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
->range_versions
= (unsigned int *)
2974 xcrealloc (debug_info_p
->range_versions
,
2975 lmax
, sizeof (*debug_info_p
->range_versions
));
2976 debug_info_p
->max_range_lists
= lmax
;
2979 if (form
== DW_FORM_rnglistx
)
2980 uvalue
= fetch_indexed_value (uvalue
, rnglists
, 0);
2982 debug_info_p
->range_lists
[num
] = uvalue
;
2983 debug_info_p
->range_versions
[num
] = dwarf_version
;
2984 debug_info_p
->num_range_lists
++;
2988 case DW_AT_GNU_dwo_name
:
2989 case DW_AT_dwo_name
:
2994 add_dwo_name ((const char *) fetch_indirect_string (uvalue
), cu_offset
);
2996 case DW_FORM_GNU_strp_alt
:
2997 add_dwo_name ((const char *) fetch_alt_indirect_string (uvalue
), cu_offset
);
2999 case DW_FORM_GNU_str_index
:
3005 add_dwo_name (fetch_indexed_string (uvalue
, this_set
, offset_size
, false,
3006 debug_info_p
->str_offsets_base
),
3009 case DW_FORM_string
:
3010 add_dwo_name ((const char *) orig_data
, cu_offset
);
3013 warn (_("Unsupported form (%s) for attribute %s\n"),
3014 get_FORM_name (form
), get_AT_name (attribute
));
3019 case DW_AT_comp_dir
:
3020 /* FIXME: Also extract a build-id in a CU/TU. */
3025 add_dwo_dir ((const char *) fetch_indirect_string (uvalue
), cu_offset
);
3027 case DW_FORM_GNU_strp_alt
:
3028 add_dwo_dir (fetch_alt_indirect_string (uvalue
), cu_offset
);
3030 case DW_FORM_line_strp
:
3031 add_dwo_dir ((const char *) fetch_indirect_line_string (uvalue
), cu_offset
);
3033 case DW_FORM_GNU_str_index
:
3039 add_dwo_dir (fetch_indexed_string (uvalue
, this_set
, offset_size
, false,
3040 debug_info_p
->str_offsets_base
),
3043 case DW_FORM_string
:
3044 add_dwo_dir ((const char *) orig_data
, cu_offset
);
3047 warn (_("Unsupported form (%s) for attribute %s\n"),
3048 get_FORM_name (form
), get_AT_name (attribute
));
3053 case DW_AT_GNU_dwo_id
:
3058 /* FIXME: Record the length of the ID as well ? */
3059 add_dwo_id ((const char *) (data
- 8), cu_offset
);
3062 warn (_("Unsupported form (%s) for attribute %s\n"),
3063 get_FORM_name (form
), get_AT_name (attribute
));
3073 if (do_loc
|| attribute
== 0)
3076 /* For some attributes we can display further information. */
3080 if (level
>= 0 && level
< MAX_CU_NESTING
3081 && uvalue
< (size_t) (end
- start
))
3083 bool is_signed
= false;
3084 abbrev_entry
*type_abbrev
;
3085 unsigned char *type_data
;
3088 type_abbrev
= get_type_abbrev_from_form (form
, uvalue
,
3092 if (type_abbrev
!= NULL
)
3094 get_type_signedness (type_abbrev
, section
, type_data
,
3095 map
? section
->start
+ map
->end
: end
,
3096 map
? map
->start
: cu_offset
,
3097 pointer_size
, offset_size
, dwarf_version
,
3100 level_type_signed
[level
] = is_signed
;
3108 case DW_INL_not_inlined
:
3109 printf (_("(not inlined)"));
3111 case DW_INL_inlined
:
3112 printf (_("(inlined)"));
3114 case DW_INL_declared_not_inlined
:
3115 printf (_("(declared as inline but ignored)"));
3117 case DW_INL_declared_inlined
:
3118 printf (_("(declared as inline and inlined)"));
3121 printf (_(" (Unknown inline attribute value: %#" PRIx64
")"),
3127 case DW_AT_language
:
3131 /* Ordered by the numeric value of these constants. */
3132 case DW_LANG_C89
: printf ("(ANSI C)"); break;
3133 case DW_LANG_C
: printf ("(non-ANSI C)"); break;
3134 case DW_LANG_Ada83
: printf ("(Ada)"); break;
3135 case DW_LANG_C_plus_plus
: printf ("(C++)"); break;
3136 case DW_LANG_Cobol74
: printf ("(Cobol 74)"); break;
3137 case DW_LANG_Cobol85
: printf ("(Cobol 85)"); break;
3138 case DW_LANG_Fortran77
: printf ("(FORTRAN 77)"); break;
3139 case DW_LANG_Fortran90
: printf ("(Fortran 90)"); break;
3140 case DW_LANG_Pascal83
: printf ("(ANSI Pascal)"); break;
3141 case DW_LANG_Modula2
: printf ("(Modula 2)"); break;
3142 /* DWARF 2.1 values. */
3143 case DW_LANG_Java
: printf ("(Java)"); break;
3144 case DW_LANG_C99
: printf ("(ANSI C99)"); break;
3145 case DW_LANG_Ada95
: printf ("(ADA 95)"); break;
3146 case DW_LANG_Fortran95
: printf ("(Fortran 95)"); break;
3147 /* DWARF 3 values. */
3148 case DW_LANG_PLI
: printf ("(PLI)"); break;
3149 case DW_LANG_ObjC
: printf ("(Objective C)"); break;
3150 case DW_LANG_ObjC_plus_plus
: printf ("(Objective C++)"); break;
3151 case DW_LANG_UPC
: printf ("(Unified Parallel C)"); break;
3152 case DW_LANG_D
: printf ("(D)"); break;
3153 /* DWARF 4 values. */
3154 case DW_LANG_Python
: printf ("(Python)"); break;
3155 /* DWARF 5 values. */
3156 case DW_LANG_OpenCL
: printf ("(OpenCL)"); break;
3157 case DW_LANG_Go
: printf ("(Go)"); break;
3158 case DW_LANG_Modula3
: printf ("(Modula 3)"); break;
3159 case DW_LANG_Haskell
: printf ("(Haskell)"); break;
3160 case DW_LANG_C_plus_plus_03
: printf ("(C++03)"); break;
3161 case DW_LANG_C_plus_plus_11
: printf ("(C++11)"); break;
3162 case DW_LANG_OCaml
: printf ("(OCaml)"); break;
3163 case DW_LANG_Rust
: printf ("(Rust)"); break;
3164 case DW_LANG_C11
: printf ("(C11)"); break;
3165 case DW_LANG_Swift
: printf ("(Swift)"); break;
3166 case DW_LANG_Julia
: printf ("(Julia)"); break;
3167 case DW_LANG_Dylan
: printf ("(Dylan)"); break;
3168 case DW_LANG_C_plus_plus_14
: printf ("(C++14)"); break;
3169 case DW_LANG_Fortran03
: printf ("(Fortran 03)"); break;
3170 case DW_LANG_Fortran08
: printf ("(Fortran 08)"); break;
3171 case DW_LANG_RenderScript
: printf ("(RenderScript)"); break;
3172 /* MIPS extension. */
3173 case DW_LANG_Mips_Assembler
: printf ("(MIPS assembler)"); break;
3174 /* UPC extension. */
3175 case DW_LANG_Upc
: printf ("(Unified Parallel C)"); break;
3177 if (uvalue
>= DW_LANG_lo_user
&& uvalue
<= DW_LANG_hi_user
)
3178 printf (_("(implementation defined: %#" PRIx64
")"), uvalue
);
3180 printf (_("(unknown: %#" PRIx64
")"), uvalue
);
3185 case DW_AT_encoding
:
3189 case DW_ATE_void
: printf ("(void)"); break;
3190 case DW_ATE_address
: printf ("(machine address)"); break;
3191 case DW_ATE_boolean
: printf ("(boolean)"); break;
3192 case DW_ATE_complex_float
: printf ("(complex float)"); break;
3193 case DW_ATE_float
: printf ("(float)"); break;
3194 case DW_ATE_signed
: printf ("(signed)"); break;
3195 case DW_ATE_signed_char
: printf ("(signed char)"); break;
3196 case DW_ATE_unsigned
: printf ("(unsigned)"); break;
3197 case DW_ATE_unsigned_char
: printf ("(unsigned char)"); break;
3198 /* DWARF 2.1 values: */
3199 case DW_ATE_imaginary_float
: printf ("(imaginary float)"); break;
3200 case DW_ATE_decimal_float
: printf ("(decimal float)"); break;
3201 /* DWARF 3 values: */
3202 case DW_ATE_packed_decimal
: printf ("(packed_decimal)"); break;
3203 case DW_ATE_numeric_string
: printf ("(numeric_string)"); break;
3204 case DW_ATE_edited
: printf ("(edited)"); break;
3205 case DW_ATE_signed_fixed
: printf ("(signed_fixed)"); break;
3206 case DW_ATE_unsigned_fixed
: printf ("(unsigned_fixed)"); break;
3207 /* DWARF 4 values: */
3208 case DW_ATE_UTF
: printf ("(unicode string)"); break;
3209 /* DWARF 5 values: */
3210 case DW_ATE_UCS
: printf ("(UCS)"); break;
3211 case DW_ATE_ASCII
: printf ("(ASCII)"); break;
3213 /* HP extensions: */
3214 case DW_ATE_HP_float80
: printf ("(HP_float80)"); break;
3215 case DW_ATE_HP_complex_float80
: printf ("(HP_complex_float80)"); break;
3216 case DW_ATE_HP_float128
: printf ("(HP_float128)"); break;
3217 case DW_ATE_HP_complex_float128
:printf ("(HP_complex_float128)"); break;
3218 case DW_ATE_HP_floathpintel
: printf ("(HP_floathpintel)"); break;
3219 case DW_ATE_HP_imaginary_float80
: printf ("(HP_imaginary_float80)"); break;
3220 case DW_ATE_HP_imaginary_float128
: printf ("(HP_imaginary_float128)"); break;
3223 if (uvalue
>= DW_ATE_lo_user
3224 && uvalue
<= DW_ATE_hi_user
)
3225 printf (_("(user defined type)"));
3227 printf (_("(unknown type)"));
3232 case DW_AT_accessibility
:
3236 case DW_ACCESS_public
: printf ("(public)"); break;
3237 case DW_ACCESS_protected
: printf ("(protected)"); break;
3238 case DW_ACCESS_private
: printf ("(private)"); break;
3240 printf (_("(unknown accessibility)"));
3245 case DW_AT_visibility
:
3249 case DW_VIS_local
: printf ("(local)"); break;
3250 case DW_VIS_exported
: printf ("(exported)"); break;
3251 case DW_VIS_qualified
: printf ("(qualified)"); break;
3252 default: printf (_("(unknown visibility)")); break;
3256 case DW_AT_endianity
:
3260 case DW_END_default
: printf ("(default)"); break;
3261 case DW_END_big
: printf ("(big)"); break;
3262 case DW_END_little
: printf ("(little)"); break;
3264 if (uvalue
>= DW_END_lo_user
&& uvalue
<= DW_END_hi_user
)
3265 printf (_("(user specified)"));
3267 printf (_("(unknown endianity)"));
3272 case DW_AT_virtuality
:
3276 case DW_VIRTUALITY_none
: printf ("(none)"); break;
3277 case DW_VIRTUALITY_virtual
: printf ("(virtual)"); break;
3278 case DW_VIRTUALITY_pure_virtual
:printf ("(pure_virtual)"); break;
3279 default: printf (_("(unknown virtuality)")); break;
3283 case DW_AT_identifier_case
:
3287 case DW_ID_case_sensitive
: printf ("(case_sensitive)"); break;
3288 case DW_ID_up_case
: printf ("(up_case)"); break;
3289 case DW_ID_down_case
: printf ("(down_case)"); break;
3290 case DW_ID_case_insensitive
: printf ("(case_insensitive)"); break;
3291 default: printf (_("(unknown case)")); break;
3295 case DW_AT_calling_convention
:
3299 case DW_CC_normal
: printf ("(normal)"); break;
3300 case DW_CC_program
: printf ("(program)"); break;
3301 case DW_CC_nocall
: printf ("(nocall)"); break;
3302 case DW_CC_pass_by_reference
: printf ("(pass by ref)"); break;
3303 case DW_CC_pass_by_value
: printf ("(pass by value)"); break;
3304 case DW_CC_GNU_renesas_sh
: printf ("(Rensas SH)"); break;
3305 case DW_CC_GNU_borland_fastcall_i386
: printf ("(Borland fastcall i386)"); break;
3307 if (uvalue
>= DW_CC_lo_user
3308 && uvalue
<= DW_CC_hi_user
)
3309 printf (_("(user defined)"));
3311 printf (_("(unknown convention)"));
3315 case DW_AT_ordering
:
3320 case -1: printf (_("(undefined)")); break;
3321 case 0: printf ("(row major)"); break;
3322 case 1: printf ("(column major)"); break;
3326 case DW_AT_decimal_sign
:
3330 case DW_DS_unsigned
: printf (_("(unsigned)")); break;
3331 case DW_DS_leading_overpunch
: printf (_("(leading overpunch)")); break;
3332 case DW_DS_trailing_overpunch
: printf (_("(trailing overpunch)")); break;
3333 case DW_DS_leading_separate
: printf (_("(leading separate)")); break;
3334 case DW_DS_trailing_separate
: printf (_("(trailing separate)")); break;
3335 default: printf (_("(unrecognised)")); break;
3339 case DW_AT_defaulted
:
3343 case DW_DEFAULTED_no
: printf (_("(no)")); break;
3344 case DW_DEFAULTED_in_class
: printf (_("(in class)")); break;
3345 case DW_DEFAULTED_out_of_class
: printf (_("(out of class)")); break;
3346 default: printf (_("(unrecognised)")); break;
3350 case DW_AT_discr_list
:
3352 display_discr_list (form
, uvalue
, data
, level
);
3355 case DW_AT_frame_base
:
3356 have_frame_base
= 1;
3358 case DW_AT_location
:
3359 case DW_AT_loclists_base
:
3360 case DW_AT_rnglists_base
:
3361 case DW_AT_str_offsets_base
:
3362 case DW_AT_string_length
:
3363 case DW_AT_return_addr
:
3364 case DW_AT_data_member_location
:
3365 case DW_AT_vtable_elem_location
:
3367 case DW_AT_static_link
:
3368 case DW_AT_use_location
:
3369 case DW_AT_call_value
:
3370 case DW_AT_GNU_call_site_value
:
3371 case DW_AT_call_data_value
:
3372 case DW_AT_GNU_call_site_data_value
:
3373 case DW_AT_call_target
:
3374 case DW_AT_GNU_call_site_target
:
3375 case DW_AT_call_target_clobbered
:
3376 case DW_AT_GNU_call_site_target_clobbered
:
3377 if ((dwarf_version
< 4
3378 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
3379 || form
== DW_FORM_sec_offset
3380 || form
== DW_FORM_loclistx
)
3382 if (attribute
!= DW_AT_rnglists_base
3383 && attribute
!= DW_AT_str_offsets_base
)
3384 printf (_(" (location list)"));
3387 case DW_AT_allocated
:
3388 case DW_AT_associated
:
3389 case DW_AT_data_location
:
3391 case DW_AT_upper_bound
:
3392 case DW_AT_lower_bound
:
3396 int need_frame_base
;
3399 need_frame_base
= decode_location_expression (block_start
,
3404 cu_offset
, section
);
3406 if (need_frame_base
&& !have_frame_base
)
3407 printf (_(" [without DW_AT_frame_base]"));
3411 case DW_AT_data_bit_offset
:
3412 case DW_AT_byte_size
:
3413 case DW_AT_bit_size
:
3414 case DW_AT_string_length_byte_size
:
3415 case DW_AT_string_length_bit_size
:
3416 case DW_AT_bit_stride
:
3417 if (form
== DW_FORM_exprloc
)
3420 (void) decode_location_expression (block_start
, pointer_size
,
3421 offset_size
, dwarf_version
,
3422 uvalue
, cu_offset
, section
);
3429 unsigned long abbrev_number
;
3430 abbrev_entry
*entry
;
3432 entry
= get_type_abbrev_from_form (form
, uvalue
, cu_offset
, end
,
3433 section
, & abbrev_number
, NULL
, NULL
);
3436 if (form
!= DW_FORM_GNU_ref_alt
)
3437 warn (_("Offset %#" PRIx64
" used as value for DW_AT_import attribute of DIE at offset %#tx is too big.\n"),
3439 orig_data
- section
->start
);
3443 printf (_("\t[Abbrev Number: %ld"), abbrev_number
);
3444 printf (" (%s)", get_TAG_name (entry
->tag
));
3457 static unsigned char *
3458 read_and_display_attr (unsigned long attribute
,
3460 int64_t implicit_const
,
3461 unsigned char *start
,
3462 unsigned char *data
,
3465 uint64_t pointer_size
,
3466 uint64_t offset_size
,
3468 debug_info
*debug_info_p
,
3470 struct dwarf_section
*section
,
3471 struct cu_tu_set
*this_set
,
3475 printf (" %-18s:", get_AT_name (attribute
));
3476 data
= read_and_display_attr_value (attribute
, form
, implicit_const
,
3478 cu_offset
, pointer_size
, offset_size
,
3479 dwarf_version
, debug_info_p
,
3480 do_loc
, section
, this_set
, ' ', level
);
3486 /* Like load_debug_section, but if the ordinary call fails, and we are
3487 following debug links, then attempt to load the requested section
3488 from one of the separate debug info files. */
3491 load_debug_section_with_follow (enum dwarf_section_display_enum sec_enum
,
3494 if (load_debug_section (sec_enum
, handle
))
3496 if (debug_displays
[sec_enum
].section
.filename
== NULL
)
3498 /* See if we can associate a filename with this section. */
3501 for (i
= first_separate_info
; i
!= NULL
; i
= i
->next
)
3502 if (i
->handle
== handle
)
3504 debug_displays
[sec_enum
].section
.filename
= i
->filename
;
3512 if (do_follow_links
)
3516 for (i
= first_separate_info
; i
!= NULL
; i
= i
->next
)
3518 if (load_debug_section (sec_enum
, i
->handle
))
3520 debug_displays
[sec_enum
].section
.filename
= i
->filename
;
3522 /* FIXME: We should check to see if any of the remaining debug info
3523 files also contain this section, and, umm, do something about it. */
3533 introduce (struct dwarf_section
* section
, bool raw
)
3537 if (do_follow_links
&& section
->filename
)
3538 printf (_("Raw dump of debug contents of section %s (loaded from %s):\n\n"),
3539 section
->name
, section
->filename
);
3541 printf (_("Raw dump of debug contents of section %s:\n\n"), section
->name
);
3545 if (do_follow_links
&& section
->filename
)
3546 printf (_("Contents of the %s section (loaded from %s):\n\n"),
3547 section
->name
, section
->filename
);
3549 printf (_("Contents of the %s section:\n\n"), section
->name
);
3553 /* Free memory allocated for one unit in debug_information. */
3556 free_debug_information (debug_info
*ent
)
3558 if (ent
->max_loc_offsets
)
3560 free (ent
->loc_offsets
);
3561 free (ent
->loc_views
);
3562 free (ent
->have_frame_base
);
3564 if (ent
->max_range_lists
)
3566 free (ent
->range_versions
);
3567 free (ent
->range_lists
);
3571 /* Process the contents of a .debug_info section.
3572 If do_loc is TRUE then we are scanning for location lists and dwo tags
3573 and we do not want to display anything to the user.
3574 If do_types is TRUE, we are processing a .debug_types section instead of
3575 a .debug_info section.
3576 The information displayed is restricted by the values in DWARF_START_DIE
3577 and DWARF_CUTOFF_LEVEL.
3578 Returns TRUE upon success. Otherwise an error or warning message is
3579 printed and FALSE is returned. */
3582 process_debug_info (struct dwarf_section
* section
,
3584 enum dwarf_section_display_enum abbrev_sec
,
3588 unsigned char *start
= section
->start
;
3589 unsigned char *end
= start
+ section
->size
;
3590 unsigned char *section_begin
;
3592 unsigned int num_units
= 0;
3594 /* First scan the section to get the number of comp units.
3595 Length sanity checks are done here. */
3596 for (section_begin
= start
, num_units
= 0; section_begin
< end
;
3601 /* Read the first 4 bytes. For a 32-bit DWARF section, this
3602 will be the length. For a 64-bit DWARF section, it'll be
3603 the escape code 0xffffffff followed by an 8 byte length. */
3604 SAFE_BYTE_GET_AND_INC (length
, section_begin
, 4, end
);
3606 if (length
== 0xffffffff)
3607 SAFE_BYTE_GET_AND_INC (length
, section_begin
, 8, end
);
3608 else if (length
>= 0xfffffff0 && length
< 0xffffffff)
3610 warn (_("Reserved length value (%#" PRIx64
") found in section %s\n"),
3611 length
, section
->name
);
3615 /* Negative values are illegal, they may even cause infinite
3616 looping. This can happen if we can't accurately apply
3617 relocations to an object file, or if the file is corrupt. */
3618 if (length
> (size_t) (end
- section_begin
))
3620 warn (_("Corrupt unit length (got %#" PRIx64
3621 " expected at most %#tx) in section %s\n"),
3622 length
, end
- section_begin
, section
->name
);
3625 section_begin
+= length
;
3630 error (_("No comp units in %s section ?\n"), section
->name
);
3634 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
|| do_debug_info
)
3635 && num_debug_info_entries
== 0
3639 /* Then allocate an array to hold the information. */
3640 debug_information
= (debug_info
*) cmalloc (num_units
,
3641 sizeof (* debug_information
));
3642 if (debug_information
== NULL
)
3644 error (_("Not enough memory for a debug info array of %u entries\n"),
3646 alloc_num_debug_info_entries
= num_debug_info_entries
= 0;
3650 /* PR 17531: file: 92ca3797.
3651 We cannot rely upon the debug_information array being initialised
3652 before it is used. A corrupt file could easily contain references
3653 to a unit for which information has not been made available. So
3654 we ensure that the array is zeroed here. */
3655 memset (debug_information
, 0, num_units
* sizeof (*debug_information
));
3657 alloc_num_debug_info_entries
= num_units
;
3662 load_debug_section_with_follow (str
, file
);
3663 load_debug_section_with_follow (line_str
, file
);
3664 load_debug_section_with_follow (str_dwo
, file
);
3665 load_debug_section_with_follow (str_index
, file
);
3666 load_debug_section_with_follow (str_index_dwo
, file
);
3667 load_debug_section_with_follow (debug_addr
, file
);
3670 load_debug_section_with_follow (abbrev_sec
, file
);
3671 load_debug_section_with_follow (loclists
, file
);
3672 load_debug_section_with_follow (rnglists
, file
);
3673 load_debug_section_with_follow (loclists_dwo
, file
);
3674 load_debug_section_with_follow (rnglists_dwo
, file
);
3676 if (debug_displays
[abbrev_sec
].section
.start
== NULL
)
3678 warn (_("Unable to locate %s section!\n"),
3679 debug_displays
[abbrev_sec
].section
.uncompressed_name
);
3683 if (!do_loc
&& dwarf_start_die
== 0)
3684 introduce (section
, false);
3686 free_all_abbrevs ();
3688 /* In order to be able to resolve DW_FORM_ref_addr forms we need
3689 to load *all* of the abbrevs for all CUs in this .debug_info
3690 section. This does effectively mean that we (partially) read
3691 every CU header twice. */
3692 for (section_begin
= start
; start
< end
;)
3694 DWARF2_Internal_CompUnit compunit
;
3695 unsigned char *hdrptr
;
3696 uint64_t abbrev_base
;
3699 unsigned int offset_size
;
3700 struct cu_tu_set
*this_set
;
3701 unsigned char *end_cu
;
3704 cu_offset
= start
- section_begin
;
3706 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 4, end
);
3708 if (compunit
.cu_length
== 0xffffffff)
3710 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 8, end
);
3715 end_cu
= hdrptr
+ compunit
.cu_length
;
3717 SAFE_BYTE_GET_AND_INC (compunit
.cu_version
, hdrptr
, 2, end_cu
);
3719 this_set
= find_cu_tu_set_v2 (cu_offset
, do_types
);
3721 if (compunit
.cu_version
< 5)
3723 compunit
.cu_unit_type
= DW_UT_compile
;
3724 /* Initialize it due to a false compiler warning. */
3725 compunit
.cu_pointer_size
= -1;
3729 SAFE_BYTE_GET_AND_INC (compunit
.cu_unit_type
, hdrptr
, 1, end_cu
);
3730 do_types
= (compunit
.cu_unit_type
== DW_UT_type
);
3732 SAFE_BYTE_GET_AND_INC (compunit
.cu_pointer_size
, hdrptr
, 1, end_cu
);
3735 SAFE_BYTE_GET_AND_INC (compunit
.cu_abbrev_offset
, hdrptr
, offset_size
,
3738 if (compunit
.cu_unit_type
== DW_UT_split_compile
3739 || compunit
.cu_unit_type
== DW_UT_skeleton
)
3742 SAFE_BYTE_GET_AND_INC (dwo_id
, hdrptr
, 8, end_cu
);
3745 if (this_set
== NULL
)
3748 abbrev_size
= debug_displays
[abbrev_sec
].section
.size
;
3752 abbrev_base
= this_set
->section_offsets
[DW_SECT_ABBREV
];
3753 abbrev_size
= this_set
->section_sizes
[DW_SECT_ABBREV
];
3757 abbrev_list
*free_list
;
3758 list
= find_and_process_abbrev_set (&debug_displays
[abbrev_sec
].section
,
3759 abbrev_base
, abbrev_size
,
3760 compunit
.cu_abbrev_offset
,
3763 if (list
!= NULL
&& list
->first_abbrev
!= NULL
)
3764 record_abbrev_list_for_cu (cu_offset
, start
- section_begin
,
3766 else if (free_list
!= NULL
)
3767 free_abbrev_list (free_list
);
3770 for (start
= section_begin
, unit
= 0; start
< end
; unit
++)
3772 DWARF2_Internal_CompUnit compunit
;
3773 unsigned char *hdrptr
;
3774 unsigned char *tags
;
3775 int level
, last_level
, saved_level
;
3777 unsigned int offset_size
;
3778 uint64_t signature
= 0;
3779 uint64_t type_offset
= 0;
3780 struct cu_tu_set
*this_set
;
3781 uint64_t abbrev_base
;
3783 unsigned char *end_cu
;
3786 cu_offset
= start
- section_begin
;
3788 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 4, end
);
3790 if (compunit
.cu_length
== 0xffffffff)
3792 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 8, end
);
3797 end_cu
= hdrptr
+ compunit
.cu_length
;
3799 SAFE_BYTE_GET_AND_INC (compunit
.cu_version
, hdrptr
, 2, end_cu
);
3801 this_set
= find_cu_tu_set_v2 (cu_offset
, do_types
);
3803 if (compunit
.cu_version
< 5)
3805 compunit
.cu_unit_type
= DW_UT_compile
;
3806 /* Initialize it due to a false compiler warning. */
3807 compunit
.cu_pointer_size
= -1;
3811 SAFE_BYTE_GET_AND_INC (compunit
.cu_unit_type
, hdrptr
, 1, end_cu
);
3812 do_types
= (compunit
.cu_unit_type
== DW_UT_type
);
3814 SAFE_BYTE_GET_AND_INC (compunit
.cu_pointer_size
, hdrptr
, 1, end_cu
);
3817 SAFE_BYTE_GET_AND_INC (compunit
.cu_abbrev_offset
, hdrptr
, offset_size
, end_cu
);
3819 if (this_set
== NULL
)
3822 abbrev_size
= debug_displays
[abbrev_sec
].section
.size
;
3826 abbrev_base
= this_set
->section_offsets
[DW_SECT_ABBREV
];
3827 abbrev_size
= this_set
->section_sizes
[DW_SECT_ABBREV
];
3830 if (compunit
.cu_version
< 5)
3831 SAFE_BYTE_GET_AND_INC (compunit
.cu_pointer_size
, hdrptr
, 1, end_cu
);
3833 bool do_dwo_id
= false;
3834 uint64_t dwo_id
= 0;
3835 if (compunit
.cu_unit_type
== DW_UT_split_compile
3836 || compunit
.cu_unit_type
== DW_UT_skeleton
)
3838 SAFE_BYTE_GET_AND_INC (dwo_id
, hdrptr
, 8, end_cu
);
3842 /* PR 17512: file: 001-108546-0.001:0.1. */
3843 if (compunit
.cu_pointer_size
< 2 || compunit
.cu_pointer_size
> 8)
3845 warn (_("Invalid pointer size (%d) in compunit header, using %d instead\n"),
3846 compunit
.cu_pointer_size
, offset_size
);
3847 compunit
.cu_pointer_size
= offset_size
;
3852 SAFE_BYTE_GET_AND_INC (signature
, hdrptr
, 8, end_cu
);
3853 SAFE_BYTE_GET_AND_INC (type_offset
, hdrptr
, offset_size
, end_cu
);
3856 if (dwarf_start_die
>= (size_t) (end_cu
- section_begin
))
3862 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
|| do_debug_info
)
3863 && num_debug_info_entries
== 0
3864 && alloc_num_debug_info_entries
> unit
3867 free_debug_information (&debug_information
[unit
]);
3868 memset (&debug_information
[unit
], 0, sizeof (*debug_information
));
3869 debug_information
[unit
].pointer_size
= compunit
.cu_pointer_size
;
3870 debug_information
[unit
].offset_size
= offset_size
;
3871 debug_information
[unit
].dwarf_version
= compunit
.cu_version
;
3872 debug_information
[unit
].cu_offset
= cu_offset
;
3873 debug_information
[unit
].addr_base
= DEBUG_INFO_UNAVAILABLE
;
3874 debug_information
[unit
].ranges_base
= DEBUG_INFO_UNAVAILABLE
;
3877 if (!do_loc
&& dwarf_start_die
== 0)
3879 printf (_(" Compilation Unit @ offset %#" PRIx64
":\n"),
3881 printf (_(" Length: %#" PRIx64
" (%s)\n"),
3883 offset_size
== 8 ? "64-bit" : "32-bit");
3884 printf (_(" Version: %d\n"), compunit
.cu_version
);
3885 if (compunit
.cu_version
>= 5)
3887 const char *name
= get_DW_UT_name (compunit
.cu_unit_type
);
3889 printf (_(" Unit Type: %s (%x)\n"),
3891 compunit
.cu_unit_type
);
3893 printf (_(" Abbrev Offset: %#" PRIx64
"\n"),
3894 compunit
.cu_abbrev_offset
);
3895 printf (_(" Pointer Size: %d\n"), compunit
.cu_pointer_size
);
3898 printf (_(" Signature: %#" PRIx64
"\n"), signature
);
3899 printf (_(" Type Offset: %#" PRIx64
"\n"), type_offset
);
3902 printf (_(" DWO ID: %#" PRIx64
"\n"), dwo_id
);
3903 if (this_set
!= NULL
)
3905 uint64_t *offsets
= this_set
->section_offsets
;
3906 size_t *sizes
= this_set
->section_sizes
;
3908 printf (_(" Section contributions:\n"));
3909 printf (_(" .debug_abbrev.dwo: %#" PRIx64
" %#zx\n"),
3910 offsets
[DW_SECT_ABBREV
], sizes
[DW_SECT_ABBREV
]);
3911 printf (_(" .debug_line.dwo: %#" PRIx64
" %#zx\n"),
3912 offsets
[DW_SECT_LINE
], sizes
[DW_SECT_LINE
]);
3913 printf (_(" .debug_loc.dwo: %#" PRIx64
" %#zx\n"),
3914 offsets
[DW_SECT_LOC
], sizes
[DW_SECT_LOC
]);
3915 printf (_(" .debug_str_offsets.dwo: %#" PRIx64
" %#zx\n"),
3916 offsets
[DW_SECT_STR_OFFSETS
], sizes
[DW_SECT_STR_OFFSETS
]);
3923 if (compunit
.cu_version
< 2 || compunit
.cu_version
> 5)
3925 warn (_("CU at offset %#" PRIx64
" contains corrupt or "
3926 "unsupported version number: %d.\n"),
3927 cu_offset
, compunit
.cu_version
);
3931 if (compunit
.cu_unit_type
!= DW_UT_compile
3932 && compunit
.cu_unit_type
!= DW_UT_partial
3933 && compunit
.cu_unit_type
!= DW_UT_type
3934 && compunit
.cu_unit_type
!= DW_UT_split_compile
3935 && compunit
.cu_unit_type
!= DW_UT_skeleton
)
3937 warn (_("CU at offset %#" PRIx64
" contains corrupt or "
3938 "unsupported unit type: %d.\n"),
3939 cu_offset
, compunit
.cu_unit_type
);
3943 /* Process the abbrevs used by this compilation unit. */
3945 list
= find_and_process_abbrev_set (&debug_displays
[abbrev_sec
].section
,
3946 abbrev_base
, abbrev_size
,
3947 compunit
.cu_abbrev_offset
, NULL
);
3951 while (tags
< start
)
3953 unsigned long abbrev_number
;
3954 unsigned long die_offset
;
3955 abbrev_entry
*entry
;
3957 int do_printing
= 1;
3959 die_offset
= tags
- section_begin
;
3961 READ_ULEB (abbrev_number
, tags
, start
);
3963 /* A null DIE marks the end of a list of siblings or it may also be
3964 a section padding. */
3965 if (abbrev_number
== 0)
3967 /* Check if it can be a section padding for the last CU. */
3968 if (level
== 0 && start
== end
)
3972 for (chk
= tags
; chk
< start
; chk
++)
3979 if (!do_loc
&& die_offset
>= dwarf_start_die
3980 && (dwarf_cutoff_level
== -1
3981 || level
< dwarf_cutoff_level
))
3982 printf (_(" <%d><%lx>: Abbrev Number: 0\n"),
3988 static unsigned num_bogus_warns
= 0;
3990 if (num_bogus_warns
< 3)
3992 warn (_("Bogus end-of-siblings marker detected at offset %lx in %s section\n"),
3993 die_offset
, section
->name
);
3995 if (num_bogus_warns
== 3)
3996 warn (_("Further warnings about bogus end-of-sibling markers suppressed\n"));
3999 if (dwarf_start_die
!= 0 && level
< saved_level
)
4002 free_abbrev_list (list
);
4010 if (dwarf_start_die
!= 0 && die_offset
< dwarf_start_die
)
4014 if (dwarf_start_die
!= 0 && die_offset
== dwarf_start_die
)
4015 saved_level
= level
;
4016 do_printing
= (dwarf_cutoff_level
== -1
4017 || level
< dwarf_cutoff_level
);
4019 printf (_(" <%d><%lx>: Abbrev Number: %lu"),
4020 level
, die_offset
, abbrev_number
);
4021 else if (dwarf_cutoff_level
== -1
4022 || last_level
< dwarf_cutoff_level
)
4023 printf (_(" <%d><%lx>: ...\n"), level
, die_offset
);
4028 /* Scan through the abbreviation list until we reach the
4032 for (entry
= list
->first_abbrev
; entry
!= NULL
; entry
= entry
->next
)
4033 if (entry
->number
== abbrev_number
)
4038 if (!do_loc
&& do_printing
)
4043 warn (_("DIE at offset %#lx refers to abbreviation number %lu which does not exist\n"),
4044 die_offset
, abbrev_number
);
4046 free_abbrev_list (list
);
4050 if (!do_loc
&& do_printing
)
4051 printf (" (%s)\n", get_TAG_name (entry
->tag
));
4056 need_base_address
= 0;
4058 case DW_TAG_compile_unit
:
4059 case DW_TAG_skeleton_unit
:
4060 need_base_address
= 1;
4061 need_dwo_info
= do_loc
;
4063 case DW_TAG_entry_point
:
4064 case DW_TAG_subprogram
:
4065 need_base_address
= 0;
4066 /* Assuming that there is no DW_AT_frame_base. */
4067 have_frame_base
= 0;
4071 debug_info
*debug_info_p
=
4072 (debug_information
&& unit
< alloc_num_debug_info_entries
)
4073 ? debug_information
+ unit
: NULL
;
4075 assert (!debug_info_p
4076 || (debug_info_p
->num_loc_offsets
4077 == debug_info_p
->num_loc_views
));
4079 for (attr
= entry
->first_attr
;
4080 attr
&& attr
->attribute
;
4083 if (! do_loc
&& do_printing
)
4084 /* Show the offset from where the tag was extracted. */
4085 printf (" <%tx>", tags
- section_begin
);
4086 tags
= read_and_display_attr (attr
->attribute
,
4088 attr
->implicit_const
,
4093 compunit
.cu_pointer_size
,
4095 compunit
.cu_version
,
4097 do_loc
|| ! do_printing
,
4103 /* If a locview attribute appears before a location one,
4104 make sure we don't associate it with an earlier
4107 switch (debug_info_p
->num_loc_offsets
- debug_info_p
->num_loc_views
)
4110 debug_info_p
->loc_views
[debug_info_p
->num_loc_views
] = -1;
4111 debug_info_p
->num_loc_views
++;
4112 assert (debug_info_p
->num_loc_views
4113 == debug_info_p
->num_loc_offsets
);
4120 warn(_("DIE has locviews without loclist\n"));
4121 debug_info_p
->num_loc_views
--;
4128 if (entry
->children
)
4132 free_abbrev_list (list
);
4135 /* Set num_debug_info_entries here so that it can be used to check if
4136 we need to process .debug_loc and .debug_ranges sections. */
4137 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
|| do_debug_info
)
4138 && num_debug_info_entries
== 0
4141 if (num_units
> alloc_num_debug_info_entries
)
4142 num_debug_info_entries
= alloc_num_debug_info_entries
;
4144 num_debug_info_entries
= num_units
;
4153 /* Locate and scan the .debug_info section in the file and record the pointer
4154 sizes and offsets for the compilation units in it. Usually an executable
4155 will have just one pointer size, but this is not guaranteed, and so we try
4156 not to make any assumptions. Returns zero upon failure, or the number of
4157 compilation units upon success. */
4160 load_debug_info (void * file
)
4162 /* If we have already tried and failed to load the .debug_info
4163 section then do not bother to repeat the task. */
4164 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
4167 /* If we already have the information there is nothing else to do. */
4168 if (num_debug_info_entries
> 0)
4169 return num_debug_info_entries
;
4171 /* If this is a DWARF package file, load the CU and TU indexes. */
4172 (void) load_cu_tu_indexes (file
);
4174 if (load_debug_section_with_follow (info
, file
)
4175 && process_debug_info (&debug_displays
[info
].section
, file
, abbrev
, true, false))
4176 return num_debug_info_entries
;
4178 if (load_debug_section_with_follow (info_dwo
, file
)
4179 && process_debug_info (&debug_displays
[info_dwo
].section
, file
,
4180 abbrev_dwo
, true, false))
4181 return num_debug_info_entries
;
4183 num_debug_info_entries
= DEBUG_INFO_UNAVAILABLE
;
4187 /* Read a DWARF .debug_line section header starting at DATA.
4188 Upon success returns an updated DATA pointer and the LINFO
4189 structure and the END_OF_SEQUENCE pointer will be filled in.
4190 Otherwise returns NULL. */
4192 static unsigned char *
4193 read_debug_line_header (struct dwarf_section
* section
,
4194 unsigned char * data
,
4195 unsigned char * end
,
4196 DWARF2_Internal_LineInfo
* linfo
,
4197 unsigned char ** end_of_sequence
)
4199 unsigned char *hdrptr
;
4201 /* Extract information from the Line Number Program Header.
4202 (section 6.2.4 in the Dwarf3 doc). */
4205 /* Get and check the length of the block. */
4206 SAFE_BYTE_GET_AND_INC (linfo
->li_length
, hdrptr
, 4, end
);
4208 if (linfo
->li_length
== 0xffffffff)
4210 /* This section is 64-bit DWARF 3. */
4211 SAFE_BYTE_GET_AND_INC (linfo
->li_length
, hdrptr
, 8, end
);
4212 linfo
->li_offset_size
= 8;
4215 linfo
->li_offset_size
= 4;
4217 if (linfo
->li_length
> (size_t) (end
- hdrptr
))
4219 /* If the length field has a relocation against it, then we should
4220 not complain if it is inaccurate (and probably negative). This
4221 happens in object files when the .debug_line section is actually
4222 comprised of several different .debug_line.* sections, (some of
4223 which may be removed by linker garbage collection), and a relocation
4224 is used to compute the correct length once that is done. */
4225 if (reloc_at (section
, (hdrptr
- section
->start
) - linfo
->li_offset_size
))
4227 linfo
->li_length
= end
- hdrptr
;
4231 warn (_("The length field (%#" PRIx64
")"
4232 " in the debug_line header is wrong"
4233 " - the section is too small\n"),
4238 end
= hdrptr
+ linfo
->li_length
;
4240 /* Get and check the version number. */
4241 SAFE_BYTE_GET_AND_INC (linfo
->li_version
, hdrptr
, 2, end
);
4243 if (linfo
->li_version
!= 2
4244 && linfo
->li_version
!= 3
4245 && linfo
->li_version
!= 4
4246 && linfo
->li_version
!= 5)
4248 warn (_("Only DWARF version 2, 3, 4 and 5 line info "
4249 "is currently supported.\n"));
4253 if (linfo
->li_version
>= 5)
4255 SAFE_BYTE_GET_AND_INC (linfo
->li_address_size
, hdrptr
, 1, end
);
4257 SAFE_BYTE_GET_AND_INC (linfo
->li_segment_size
, hdrptr
, 1, end
);
4258 if (linfo
->li_segment_size
!= 0)
4260 warn (_("The %s section contains "
4261 "unsupported segment selector size: %d.\n"),
4262 section
->name
, linfo
->li_segment_size
);
4267 SAFE_BYTE_GET_AND_INC (linfo
->li_prologue_length
, hdrptr
,
4268 linfo
->li_offset_size
, end
);
4269 SAFE_BYTE_GET_AND_INC (linfo
->li_min_insn_length
, hdrptr
, 1, end
);
4271 if (linfo
->li_version
>= 4)
4273 SAFE_BYTE_GET_AND_INC (linfo
->li_max_ops_per_insn
, hdrptr
, 1, end
);
4275 if (linfo
->li_max_ops_per_insn
== 0)
4277 warn (_("Invalid maximum operations per insn.\n"));
4282 linfo
->li_max_ops_per_insn
= 1;
4284 SAFE_BYTE_GET_AND_INC (linfo
->li_default_is_stmt
, hdrptr
, 1, end
);
4285 SAFE_SIGNED_BYTE_GET_AND_INC (linfo
->li_line_base
, hdrptr
, 1, end
);
4286 SAFE_BYTE_GET_AND_INC (linfo
->li_line_range
, hdrptr
, 1, end
);
4287 SAFE_BYTE_GET_AND_INC (linfo
->li_opcode_base
, hdrptr
, 1, end
);
4289 *end_of_sequence
= end
;
4293 static unsigned char *
4294 display_formatted_table (unsigned char *data
,
4295 unsigned char *start
,
4297 const DWARF2_Internal_LineInfo
*linfo
,
4298 struct dwarf_section
*section
,
4301 unsigned char *format_start
, format_count
, *format
, formati
;
4302 uint64_t data_count
, datai
;
4303 unsigned int namepass
, last_entry
= 0;
4304 const char * table_name
= is_dir
? N_("Directory Table") : N_("File Name Table");
4306 SAFE_BYTE_GET_AND_INC (format_count
, data
, 1, end
);
4307 if (do_checks
&& format_count
> 5)
4308 warn (_("Unexpectedly large number of columns in the %s (%u)\n"),
4309 table_name
, format_count
);
4311 format_start
= data
;
4312 for (formati
= 0; formati
< format_count
; formati
++)
4314 SKIP_ULEB (data
, end
);
4315 SKIP_ULEB (data
, end
);
4318 warn (_("%s: Corrupt format description entry\n"), table_name
);
4323 READ_ULEB (data_count
, data
, end
);
4324 if (data_count
== 0)
4326 printf (_("\n The %s is empty.\n"), table_name
);
4329 else if (data
>= end
4330 || data_count
> (size_t) (end
- data
))
4332 warn (_("%s: Corrupt entry count %#" PRIx64
"\n"), table_name
, data_count
);
4336 else if (format_count
== 0)
4338 warn (_("%s: format count is zero, but the table is not empty\n"),
4343 printf (_("\n The %s (offset %#tx, lines %" PRIu64
", columns %u):\n"),
4344 table_name
, data
- start
, data_count
, format_count
);
4346 printf (_(" Entry"));
4347 /* Delay displaying name as the last entry for better screen layout. */
4348 for (namepass
= 0; namepass
< 2; namepass
++)
4350 format
= format_start
;
4351 for (formati
= 0; formati
< format_count
; formati
++)
4353 uint64_t content_type
;
4355 READ_ULEB (content_type
, format
, end
);
4356 if ((content_type
== DW_LNCT_path
) == (namepass
== 1))
4357 switch (content_type
)
4360 printf (_("\tName"));
4362 case DW_LNCT_directory_index
:
4363 printf (_("\tDir"));
4365 case DW_LNCT_timestamp
:
4366 printf (_("\tTime"));
4369 printf (_("\tSize"));
4372 printf (_("\tMD5\t\t\t"));
4375 printf (_("\t(Unknown format content type %" PRIu64
")"),
4378 SKIP_ULEB (format
, end
);
4383 for (datai
= 0; datai
< data_count
; datai
++)
4385 unsigned char *datapass
= data
;
4387 printf (" %d", last_entry
++);
4388 /* Delay displaying name as the last entry for better screen layout. */
4389 for (namepass
= 0; namepass
< 2; namepass
++)
4391 format
= format_start
;
4393 for (formati
= 0; formati
< format_count
; formati
++)
4395 uint64_t content_type
, form
;
4397 READ_ULEB (content_type
, format
, end
);
4398 READ_ULEB (form
, format
, end
);
4399 data
= read_and_display_attr_value (0, form
, 0, start
, data
, end
,
4400 0, 0, linfo
->li_offset_size
,
4401 linfo
->li_version
, NULL
,
4402 ((content_type
== DW_LNCT_path
) != (namepass
== 1)),
4403 section
, NULL
, '\t', -1);
4407 if (data
>= end
&& (datai
< data_count
- 1))
4409 warn (_("\n%s: Corrupt entries list\n"), table_name
);
4418 display_debug_sup (struct dwarf_section
* section
,
4419 void * file ATTRIBUTE_UNUSED
)
4421 unsigned char * start
= section
->start
;
4422 unsigned char * end
= section
->start
+ section
->size
;
4423 unsigned int version
;
4424 char is_supplementary
;
4425 const unsigned char * sup_filename
;
4426 size_t sup_filename_len
;
4427 unsigned int num_read
;
4429 uint64_t checksum_len
;
4432 introduce (section
, true);
4433 if (section
->size
< 4)
4435 error (_("corrupt .debug_sup section: size is too small\n"));
4439 /* Read the data. */
4440 SAFE_BYTE_GET_AND_INC (version
, start
, 2, end
);
4442 warn (_("corrupt .debug_sup section: version < 5"));
4444 SAFE_BYTE_GET_AND_INC (is_supplementary
, start
, 1, end
);
4445 if (is_supplementary
!= 0 && is_supplementary
!= 1)
4446 warn (_("corrupt .debug_sup section: is_supplementary not 0 or 1\n"));
4448 sup_filename
= start
;
4449 if (is_supplementary
&& sup_filename
[0] != 0)
4450 warn (_("corrupt .debug_sup section: filename not empty in supplementary section\n"));
4452 sup_filename_len
= strnlen ((const char *) start
, end
- start
);
4453 if (sup_filename_len
== (size_t) (end
- start
))
4455 error (_("corrupt .debug_sup section: filename is not NUL terminated\n"));
4458 start
+= sup_filename_len
+ 1;
4460 checksum_len
= read_leb128 (start
, end
, false /* unsigned */, & num_read
, & status
);
4463 error (_("corrupt .debug_sup section: bad LEB128 field for checksum length\n"));
4467 if (checksum_len
> (size_t) (end
- start
))
4469 error (_("corrupt .debug_sup section: checksum length is longer than the remaining section length\n"));
4470 checksum_len
= end
- start
;
4472 else if (checksum_len
< (size_t) (end
- start
))
4474 warn (_("corrupt .debug_sup section: there are %#" PRIx64
4475 " extra, unused bytes at the end of the section\n"),
4476 (end
- start
) - checksum_len
);
4479 printf (_(" Version: %u\n"), version
);
4480 printf (_(" Is Supp: %u\n"), is_supplementary
);
4481 printf (_(" Filename: %s\n"), sup_filename
);
4482 printf (_(" Checksum Len: %" PRIu64
"\n"), checksum_len
);
4483 if (checksum_len
> 0)
4485 printf (_(" Checksum: "));
4486 while (checksum_len
--)
4487 printf ("0x%x ", * start
++ );
4494 display_debug_lines_raw (struct dwarf_section
* section
,
4495 unsigned char * data
,
4496 unsigned char * end
,
4499 unsigned char *start
= section
->start
;
4500 int verbose_view
= 0;
4502 introduce (section
, true);
4506 static DWARF2_Internal_LineInfo saved_linfo
;
4507 DWARF2_Internal_LineInfo linfo
;
4508 unsigned char *standard_opcodes
;
4509 unsigned char *end_of_sequence
;
4512 if (startswith (section
->name
, ".debug_line.")
4513 /* Note: the following does not apply to .debug_line.dwo sections.
4514 These are full debug_line sections. */
4515 && strcmp (section
->name
, ".debug_line.dwo") != 0)
4517 /* Sections named .debug_line.<foo> are fragments of a .debug_line
4518 section containing just the Line Number Statements. They are
4519 created by the assembler and intended to be used alongside gcc's
4520 -ffunction-sections command line option. When the linker's
4521 garbage collection decides to discard a .text.<foo> section it
4522 can then also discard the line number information in .debug_line.<foo>.
4524 Since the section is a fragment it does not have the details
4525 needed to fill out a LineInfo structure, so instead we use the
4526 details from the last full debug_line section that we processed. */
4527 end_of_sequence
= end
;
4528 standard_opcodes
= NULL
;
4529 linfo
= saved_linfo
;
4530 /* PR 17531: file: 0522b371. */
4531 if (linfo
.li_line_range
== 0)
4533 warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n"));
4536 reset_state_machine (linfo
.li_default_is_stmt
);
4540 unsigned char * hdrptr
;
4542 if ((hdrptr
= read_debug_line_header (section
, data
, end
, & linfo
,
4543 & end_of_sequence
)) == NULL
)
4546 printf (_(" Offset: %#tx\n"), data
- start
);
4547 printf (_(" Length: %" PRId64
"\n"), linfo
.li_length
);
4548 printf (_(" DWARF Version: %d\n"), linfo
.li_version
);
4549 if (linfo
.li_version
>= 5)
4551 printf (_(" Address size (bytes): %d\n"), linfo
.li_address_size
);
4552 printf (_(" Segment selector (bytes): %d\n"), linfo
.li_segment_size
);
4554 printf (_(" Prologue Length: %d\n"), (int) linfo
.li_prologue_length
);
4555 printf (_(" Minimum Instruction Length: %d\n"), linfo
.li_min_insn_length
);
4556 if (linfo
.li_version
>= 4)
4557 printf (_(" Maximum Ops per Instruction: %d\n"), linfo
.li_max_ops_per_insn
);
4558 printf (_(" Initial value of 'is_stmt': %d\n"), linfo
.li_default_is_stmt
);
4559 printf (_(" Line Base: %d\n"), linfo
.li_line_base
);
4560 printf (_(" Line Range: %d\n"), linfo
.li_line_range
);
4561 printf (_(" Opcode Base: %d\n"), linfo
.li_opcode_base
);
4563 /* PR 17512: file: 1665-6428-0.004. */
4564 if (linfo
.li_line_range
== 0)
4566 warn (_("Line range of 0 is invalid, using 1 instead\n"));
4567 linfo
.li_line_range
= 1;
4570 reset_state_machine (linfo
.li_default_is_stmt
);
4572 /* Display the contents of the Opcodes table. */
4573 standard_opcodes
= hdrptr
;
4575 /* PR 17512: file: 002-417945-0.004. */
4576 if (standard_opcodes
+ linfo
.li_opcode_base
>= end
)
4578 warn (_("Line Base extends beyond end of section\n"));
4582 printf (_("\n Opcodes:\n"));
4584 for (i
= 1; i
< linfo
.li_opcode_base
; i
++)
4585 printf (ngettext (" Opcode %d has %d arg\n",
4586 " Opcode %d has %d args\n",
4587 standard_opcodes
[i
- 1]),
4588 i
, standard_opcodes
[i
- 1]);
4590 /* Display the contents of the Directory table. */
4591 data
= standard_opcodes
+ linfo
.li_opcode_base
- 1;
4593 if (linfo
.li_version
>= 5)
4595 load_debug_section_with_follow (line_str
, file
);
4597 data
= display_formatted_table (data
, start
, end
, &linfo
, section
,
4599 data
= display_formatted_table (data
, start
, end
, &linfo
, section
,
4605 printf (_("\n The Directory Table is empty.\n"));
4608 unsigned int last_dir_entry
= 0;
4610 printf (_("\n The Directory Table (offset %#tx):\n"),
4613 while (data
< end
&& *data
!= 0)
4615 printf (" %d\t%.*s\n", ++last_dir_entry
, (int) (end
- data
), data
);
4617 data
+= strnlen ((char *) data
, end
- data
);
4622 /* PR 17512: file: 002-132094-0.004. */
4623 if (data
>= end
- 1)
4627 /* Skip the NUL at the end of the table. */
4631 /* Display the contents of the File Name table. */
4632 if (data
>= end
|| *data
== 0)
4633 printf (_("\n The File Name Table is empty.\n"));
4636 printf (_("\n The File Name Table (offset %#tx):\n"),
4638 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
4640 while (data
< end
&& *data
!= 0)
4642 unsigned char *name
;
4645 printf (" %d\t", ++state_machine_regs
.last_file_entry
);
4647 data
+= strnlen ((char *) data
, end
- data
);
4651 READ_ULEB (val
, data
, end
);
4652 printf ("%" PRIu64
"\t", val
);
4653 READ_ULEB (val
, data
, end
);
4654 printf ("%" PRIu64
"\t", val
);
4655 READ_ULEB (val
, data
, end
);
4656 printf ("%" PRIu64
"\t", val
);
4657 printf ("%.*s\n", (int)(end
- name
), name
);
4661 warn (_("Corrupt file name table entry\n"));
4667 /* Skip the NUL at the end of the table. */
4673 saved_linfo
= linfo
;
4676 /* Now display the statements. */
4677 if (data
>= end_of_sequence
)
4678 printf (_(" No Line Number Statements.\n"));
4681 printf (_(" Line Number Statements:\n"));
4683 while (data
< end_of_sequence
)
4685 unsigned char op_code
;
4689 printf (" [0x%08tx]", data
- start
);
4693 if (op_code
>= linfo
.li_opcode_base
)
4695 op_code
-= linfo
.li_opcode_base
;
4696 uladv
= (op_code
/ linfo
.li_line_range
);
4697 if (linfo
.li_max_ops_per_insn
== 1)
4699 uladv
*= linfo
.li_min_insn_length
;
4700 state_machine_regs
.address
+= uladv
;
4702 state_machine_regs
.view
= 0;
4703 printf (_(" Special opcode %d: "
4704 "advance Address by %" PRIu64
4705 " to %#" PRIx64
"%s"),
4706 op_code
, uladv
, state_machine_regs
.address
,
4707 verbose_view
&& uladv
4708 ? _(" (reset view)") : "");
4713 = ((state_machine_regs
.op_index
+ uladv
)
4714 / linfo
.li_max_ops_per_insn
)
4715 * linfo
.li_min_insn_length
;
4717 state_machine_regs
.address
+= addrdelta
;
4718 state_machine_regs
.op_index
4719 = (state_machine_regs
.op_index
+ uladv
)
4720 % linfo
.li_max_ops_per_insn
;
4722 state_machine_regs
.view
= 0;
4723 printf (_(" Special opcode %d: "
4724 "advance Address by %" PRIu64
4725 " to %#" PRIx64
"[%d]%s"),
4726 op_code
, uladv
, state_machine_regs
.address
,
4727 state_machine_regs
.op_index
,
4728 verbose_view
&& addrdelta
4729 ? _(" (reset view)") : "");
4731 adv
= (op_code
% linfo
.li_line_range
) + linfo
.li_line_base
;
4732 state_machine_regs
.line
+= adv
;
4733 printf (_(" and Line by %d to %d"),
4734 adv
, state_machine_regs
.line
);
4735 if (verbose_view
|| state_machine_regs
.view
)
4736 printf (_(" (view %u)\n"), state_machine_regs
.view
);
4739 state_machine_regs
.view
++;
4744 case DW_LNS_extended_op
:
4745 data
+= process_extended_line_op (data
,
4746 linfo
.li_default_is_stmt
,
4751 printf (_(" Copy"));
4752 if (verbose_view
|| state_machine_regs
.view
)
4753 printf (_(" (view %u)\n"), state_machine_regs
.view
);
4756 state_machine_regs
.view
++;
4759 case DW_LNS_advance_pc
:
4760 READ_ULEB (uladv
, data
, end
);
4761 if (linfo
.li_max_ops_per_insn
== 1)
4763 uladv
*= linfo
.li_min_insn_length
;
4764 state_machine_regs
.address
+= uladv
;
4766 state_machine_regs
.view
= 0;
4767 printf (_(" Advance PC by %" PRIu64
4768 " to %#" PRIx64
"%s\n"),
4769 uladv
, state_machine_regs
.address
,
4770 verbose_view
&& uladv
4771 ? _(" (reset view)") : "");
4776 = ((state_machine_regs
.op_index
+ uladv
)
4777 / linfo
.li_max_ops_per_insn
)
4778 * linfo
.li_min_insn_length
;
4779 state_machine_regs
.address
4781 state_machine_regs
.op_index
4782 = (state_machine_regs
.op_index
+ uladv
)
4783 % linfo
.li_max_ops_per_insn
;
4785 state_machine_regs
.view
= 0;
4786 printf (_(" Advance PC by %" PRIu64
4787 " to %#" PRIx64
"[%d]%s\n"),
4788 uladv
, state_machine_regs
.address
,
4789 state_machine_regs
.op_index
,
4790 verbose_view
&& addrdelta
4791 ? _(" (reset view)") : "");
4795 case DW_LNS_advance_line
:
4796 READ_SLEB (adv
, data
, end
);
4797 state_machine_regs
.line
+= adv
;
4798 printf (_(" Advance Line by %d to %d\n"),
4799 adv
, state_machine_regs
.line
);
4802 case DW_LNS_set_file
:
4803 READ_ULEB (uladv
, data
, end
);
4804 printf (_(" Set File Name to entry %" PRIu64
4805 " in the File Name Table\n"), uladv
);
4806 state_machine_regs
.file
= uladv
;
4809 case DW_LNS_set_column
:
4810 READ_ULEB (uladv
, data
, end
);
4811 printf (_(" Set column to %" PRIu64
"\n"), uladv
);
4812 state_machine_regs
.column
= uladv
;
4815 case DW_LNS_negate_stmt
:
4816 adv
= state_machine_regs
.is_stmt
;
4818 printf (_(" Set is_stmt to %d\n"), adv
);
4819 state_machine_regs
.is_stmt
= adv
;
4822 case DW_LNS_set_basic_block
:
4823 printf (_(" Set basic block\n"));
4824 state_machine_regs
.basic_block
= 1;
4827 case DW_LNS_const_add_pc
:
4828 uladv
= ((255 - linfo
.li_opcode_base
) / linfo
.li_line_range
);
4829 if (linfo
.li_max_ops_per_insn
)
4831 uladv
*= linfo
.li_min_insn_length
;
4832 state_machine_regs
.address
+= uladv
;
4834 state_machine_regs
.view
= 0;
4835 printf (_(" Advance PC by constant %" PRIu64
4836 " to %#" PRIx64
"%s\n"),
4837 uladv
, state_machine_regs
.address
,
4838 verbose_view
&& uladv
4839 ? _(" (reset view)") : "");
4844 = ((state_machine_regs
.op_index
+ uladv
)
4845 / linfo
.li_max_ops_per_insn
)
4846 * linfo
.li_min_insn_length
;
4847 state_machine_regs
.address
4849 state_machine_regs
.op_index
4850 = (state_machine_regs
.op_index
+ uladv
)
4851 % linfo
.li_max_ops_per_insn
;
4853 state_machine_regs
.view
= 0;
4854 printf (_(" Advance PC by constant %" PRIu64
4855 " to %#" PRIx64
"[%d]%s\n"),
4856 uladv
, state_machine_regs
.address
,
4857 state_machine_regs
.op_index
,
4858 verbose_view
&& addrdelta
4859 ? _(" (reset view)") : "");
4863 case DW_LNS_fixed_advance_pc
:
4864 SAFE_BYTE_GET_AND_INC (uladv
, data
, 2, end
);
4865 state_machine_regs
.address
+= uladv
;
4866 state_machine_regs
.op_index
= 0;
4867 printf (_(" Advance PC by fixed size amount %" PRIu64
4868 " to %#" PRIx64
"\n"),
4869 uladv
, state_machine_regs
.address
);
4870 /* Do NOT reset view. */
4873 case DW_LNS_set_prologue_end
:
4874 printf (_(" Set prologue_end to true\n"));
4877 case DW_LNS_set_epilogue_begin
:
4878 printf (_(" Set epilogue_begin to true\n"));
4881 case DW_LNS_set_isa
:
4882 READ_ULEB (uladv
, data
, end
);
4883 printf (_(" Set ISA to %" PRIu64
"\n"), uladv
);
4887 printf (_(" Unknown opcode %d with operands: "), op_code
);
4889 if (standard_opcodes
!= NULL
)
4890 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
4892 READ_ULEB (uladv
, data
, end
);
4893 printf ("%#" PRIx64
"%s", uladv
, i
== 1 ? "" : ", ");
4909 unsigned int directory_index
;
4910 unsigned int modification_date
;
4911 unsigned int length
;
4914 /* Output a decoded representation of the .debug_line section. */
4917 display_debug_lines_decoded (struct dwarf_section
* section
,
4918 unsigned char * start
,
4919 unsigned char * data
,
4920 unsigned char * end
,
4923 static DWARF2_Internal_LineInfo saved_linfo
;
4925 introduce (section
, false);
4929 /* This loop amounts to one iteration per compilation unit. */
4930 DWARF2_Internal_LineInfo linfo
;
4931 unsigned char *standard_opcodes
;
4932 unsigned char *end_of_sequence
;
4934 File_Entry
*file_table
= NULL
;
4935 unsigned int n_files
= 0;
4936 char **directory_table
= NULL
;
4937 unsigned int n_directories
= 0;
4939 if (startswith (section
->name
, ".debug_line.")
4940 /* Note: the following does not apply to .debug_line.dwo sections.
4941 These are full debug_line sections. */
4942 && strcmp (section
->name
, ".debug_line.dwo") != 0)
4944 /* See comment in display_debug_lines_raw(). */
4945 end_of_sequence
= end
;
4946 standard_opcodes
= NULL
;
4947 linfo
= saved_linfo
;
4948 /* PR 17531: file: 0522b371. */
4949 if (linfo
.li_line_range
== 0)
4951 warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n"));
4954 reset_state_machine (linfo
.li_default_is_stmt
);
4958 unsigned char *hdrptr
;
4960 if ((hdrptr
= read_debug_line_header (section
, data
, end
, & linfo
,
4961 & end_of_sequence
)) == NULL
)
4964 /* PR 17531: file: 0522b371. */
4965 if (linfo
.li_line_range
== 0)
4967 warn (_("Line range of 0 is invalid, using 1 instead\n"));
4968 linfo
.li_line_range
= 1;
4970 reset_state_machine (linfo
.li_default_is_stmt
);
4972 /* Save a pointer to the contents of the Opcodes table. */
4973 standard_opcodes
= hdrptr
;
4975 /* Traverse the Directory table just to count entries. */
4976 data
= standard_opcodes
+ linfo
.li_opcode_base
- 1;
4980 warn (_("opcode base of %d extends beyond end of section\n"),
4981 linfo
.li_opcode_base
);
4985 if (linfo
.li_version
>= 5)
4987 unsigned char *format_start
, *format
;
4988 unsigned int format_count
, formati
, entryi
;
4990 load_debug_section_with_follow (line_str
, fileptr
);
4992 /* Skip directories format. */
4993 SAFE_BYTE_GET_AND_INC (format_count
, data
, 1, end
);
4994 if (do_checks
&& format_count
> 1)
4995 warn (_("Unexpectedly large number of columns in the directory name table (%u)\n"),
4997 format_start
= data
;
4998 for (formati
= 0; formati
< format_count
; formati
++)
5000 SKIP_ULEB (data
, end
);
5001 SKIP_ULEB (data
, end
);
5004 READ_ULEB (n_directories
, data
, end
);
5007 warn (_("Corrupt directories list\n"));
5011 if (n_directories
== 0)
5012 directory_table
= NULL
;
5013 else if (n_directories
> section
->size
)
5015 warn (_("number of directories (0x%x) exceeds size of section %s\n"),
5016 n_directories
, section
->name
);
5020 directory_table
= (char **)
5021 xcalloc (n_directories
, sizeof (unsigned char *));
5023 for (entryi
= 0; entryi
< n_directories
; entryi
++)
5025 char **pathp
= &directory_table
[entryi
];
5027 format
= format_start
;
5028 for (formati
= 0; formati
< format_count
; formati
++)
5030 uint64_t content_type
, form
;
5033 READ_ULEB (content_type
, format
, end
);
5034 READ_ULEB (form
, format
, end
);
5037 warn (_("Corrupt directories list\n"));
5040 switch (content_type
)
5045 case DW_FORM_string
:
5046 *pathp
= (char *) data
;
5048 case DW_FORM_line_strp
:
5049 SAFE_BYTE_GET (uvalue
, data
, linfo
.li_offset_size
,
5051 /* Remove const by the cast. */
5053 fetch_indirect_line_string (uvalue
);
5058 data
= read_and_display_attr_value (0, form
, 0, start
,
5060 linfo
.li_offset_size
,
5067 warn (_("Corrupt directories list\n"));
5072 /* Skip files format. */
5073 SAFE_BYTE_GET_AND_INC (format_count
, data
, 1, end
);
5074 if (do_checks
&& format_count
> 5)
5075 warn (_("Unexpectedly large number of columns in the file name table (%u)\n"),
5078 format_start
= data
;
5079 for (formati
= 0; formati
< format_count
; formati
++)
5081 SKIP_ULEB (data
, end
);
5082 SKIP_ULEB (data
, end
);
5085 READ_ULEB (n_files
, data
, end
);
5086 if (data
>= end
&& n_files
> 0)
5088 warn (_("Corrupt file name list\n"));
5094 else if (n_files
> section
->size
)
5096 warn (_("number of files (0x%x) exceeds size of section %s\n"),
5097 n_files
, section
->name
);
5101 file_table
= (File_Entry
*) xcalloc (n_files
,
5102 sizeof (File_Entry
));
5104 for (entryi
= 0; entryi
< n_files
; entryi
++)
5106 File_Entry
*file
= &file_table
[entryi
];
5108 format
= format_start
;
5109 for (formati
= 0; formati
< format_count
; formati
++)
5111 uint64_t content_type
, form
;
5115 READ_ULEB (content_type
, format
, end
);
5116 READ_ULEB (form
, format
, end
);
5119 warn (_("Corrupt file name list\n"));
5122 switch (content_type
)
5127 case DW_FORM_string
:
5128 file
->name
= (char *) data
;
5130 case DW_FORM_line_strp
:
5131 SAFE_BYTE_GET (uvalue
, data
, linfo
.li_offset_size
,
5133 /* Remove const by the cast. */
5134 file
->name
= (char *)
5135 fetch_indirect_line_string (uvalue
);
5139 case DW_LNCT_directory_index
:
5143 SAFE_BYTE_GET (file
->directory_index
, data
, 1,
5147 SAFE_BYTE_GET (file
->directory_index
, data
, 2,
5152 READ_ULEB (file
->directory_index
, tmp
, end
);
5157 data
= read_and_display_attr_value (0, form
, 0, start
,
5159 linfo
.li_offset_size
,
5166 warn (_("Corrupt file name list\n"));
5175 char *ptr_directory_table
= (char *) data
;
5177 while (data
< end
&& *data
!= 0)
5179 data
+= strnlen ((char *) data
, end
- data
);
5188 warn (_("directory table ends unexpectedly\n"));
5193 /* Go through the directory table again to save the directories. */
5194 directory_table
= (char **)
5195 xmalloc (n_directories
* sizeof (unsigned char *));
5198 while (*ptr_directory_table
!= 0)
5200 directory_table
[i
] = ptr_directory_table
;
5201 ptr_directory_table
+= strlen (ptr_directory_table
) + 1;
5205 /* Skip the NUL at the end of the table. */
5208 /* Traverse the File Name table just to count the entries. */
5209 if (data
< end
&& *data
!= 0)
5211 unsigned char *ptr_file_name_table
= data
;
5213 while (data
< end
&& *data
!= 0)
5215 /* Skip Name, directory index, last modification
5216 time and length of file. */
5217 data
+= strnlen ((char *) data
, end
- data
);
5220 SKIP_ULEB (data
, end
);
5221 SKIP_ULEB (data
, end
);
5222 SKIP_ULEB (data
, end
);
5228 warn (_("file table ends unexpectedly\n"));
5233 /* Go through the file table again to save the strings. */
5234 file_table
= (File_Entry
*) xmalloc (n_files
* sizeof (File_Entry
));
5237 while (*ptr_file_name_table
!= 0)
5239 file_table
[i
].name
= (char *) ptr_file_name_table
;
5241 += strlen ((char *) ptr_file_name_table
) + 1;
5243 /* We are not interested in directory, time or size. */
5244 READ_ULEB (file_table
[i
].directory_index
,
5245 ptr_file_name_table
, end
);
5246 READ_ULEB (file_table
[i
].modification_date
,
5247 ptr_file_name_table
, end
);
5248 READ_ULEB (file_table
[i
].length
,
5249 ptr_file_name_table
, end
);
5255 /* Skip the NUL at the end of the table. */
5259 /* Print the Compilation Unit's name and a header. */
5260 if (file_table
== NULL
)
5261 printf (_("CU: No directory table\n"));
5262 else if (directory_table
== NULL
)
5263 printf (_("CU: %s:\n"), null_name (file_table
[0].name
));
5266 unsigned int ix
= file_table
[0].directory_index
;
5267 const char *directory
;
5269 if (ix
== 0 && linfo
.li_version
< 5)
5272 else if (n_directories
== 0)
5273 directory
= _("<unknown>");
5276 if (linfo
.li_version
< 5)
5278 if (ix
>= n_directories
)
5280 warn (_("directory index %u "
5281 ">= number of directories %u\n"),
5283 directory
= _("<corrupt>");
5286 directory
= directory_table
[ix
];
5289 printf (_("CU: %s/%s:\n"),
5290 null_name (directory
),
5291 null_name (file_table
[0].name
));
5293 printf ("%s:\n", null_name (file_table
[0].name
));
5299 printf (_("File name Line number Starting address View Stmt\n"));
5301 printf (_("File name Line number Starting address View Stmt\n"));
5304 printf (_("CU: Empty file name table\n"));
5305 saved_linfo
= linfo
;
5308 /* This loop iterates through the Dwarf Line Number Program. */
5309 while (data
< end_of_sequence
)
5311 unsigned char op_code
;
5314 unsigned long int uladv
;
5315 int is_special_opcode
= 0;
5320 if (op_code
>= linfo
.li_opcode_base
)
5322 op_code
-= linfo
.li_opcode_base
;
5323 uladv
= (op_code
/ linfo
.li_line_range
);
5324 if (linfo
.li_max_ops_per_insn
== 1)
5326 uladv
*= linfo
.li_min_insn_length
;
5327 state_machine_regs
.address
+= uladv
;
5329 state_machine_regs
.view
= 0;
5334 = ((state_machine_regs
.op_index
+ uladv
)
5335 / linfo
.li_max_ops_per_insn
)
5336 * linfo
.li_min_insn_length
;
5337 state_machine_regs
.address
5339 state_machine_regs
.op_index
5340 = (state_machine_regs
.op_index
+ uladv
)
5341 % linfo
.li_max_ops_per_insn
;
5343 state_machine_regs
.view
= 0;
5346 adv
= (op_code
% linfo
.li_line_range
) + linfo
.li_line_base
;
5347 state_machine_regs
.line
+= adv
;
5348 is_special_opcode
= 1;
5349 /* Increment view after printing this row. */
5354 case DW_LNS_extended_op
:
5356 unsigned int ext_op_code_len
;
5357 unsigned char ext_op_code
;
5358 unsigned char *op_code_end
;
5359 unsigned char *op_code_data
= data
;
5361 READ_ULEB (ext_op_code_len
, op_code_data
, end_of_sequence
);
5362 op_code_end
= op_code_data
+ ext_op_code_len
;
5363 if (ext_op_code_len
== 0 || op_code_end
> end_of_sequence
)
5365 warn (_("Badly formed extended line op encountered!\n"));
5368 ext_op_code
= *op_code_data
++;
5372 switch (ext_op_code
)
5374 case DW_LNE_end_sequence
:
5375 /* Reset stuff after printing this row. */
5377 case DW_LNE_set_address
:
5378 SAFE_BYTE_GET_AND_INC (state_machine_regs
.address
,
5380 op_code_end
- op_code_data
,
5382 state_machine_regs
.op_index
= 0;
5383 state_machine_regs
.view
= 0;
5385 case DW_LNE_define_file
:
5386 file_table
= (File_Entry
*) xrealloc
5387 (file_table
, (n_files
+ 1) * sizeof (File_Entry
));
5389 ++state_machine_regs
.last_file_entry
;
5390 /* Source file name. */
5391 file_table
[n_files
].name
= (char *) op_code_data
;
5392 op_code_data
+= strlen ((char *) op_code_data
) + 1;
5393 /* Directory index. */
5394 READ_ULEB (file_table
[n_files
].directory_index
,
5395 op_code_data
, op_code_end
);
5396 /* Last modification time. */
5397 READ_ULEB (file_table
[n_files
].modification_date
,
5398 op_code_data
, op_code_end
);
5400 READ_ULEB (file_table
[n_files
].length
,
5401 op_code_data
, op_code_end
);
5405 case DW_LNE_set_discriminator
:
5406 case DW_LNE_HP_set_sequence
:
5407 /* Simply ignored. */
5411 printf (_("UNKNOWN (%u): length %ld\n"),
5412 ext_op_code
, (long int) (op_code_data
- data
));
5419 /* Increment view after printing this row. */
5422 case DW_LNS_advance_pc
:
5423 READ_ULEB (uladv
, data
, end
);
5424 if (linfo
.li_max_ops_per_insn
== 1)
5426 uladv
*= linfo
.li_min_insn_length
;
5427 state_machine_regs
.address
+= uladv
;
5429 state_machine_regs
.view
= 0;
5434 = ((state_machine_regs
.op_index
+ uladv
)
5435 / linfo
.li_max_ops_per_insn
)
5436 * linfo
.li_min_insn_length
;
5437 state_machine_regs
.address
5439 state_machine_regs
.op_index
5440 = (state_machine_regs
.op_index
+ uladv
)
5441 % linfo
.li_max_ops_per_insn
;
5443 state_machine_regs
.view
= 0;
5447 case DW_LNS_advance_line
:
5448 READ_SLEB (adv
, data
, end
);
5449 state_machine_regs
.line
+= adv
;
5452 case DW_LNS_set_file
:
5453 READ_ULEB (uladv
, data
, end
);
5454 state_machine_regs
.file
= uladv
;
5456 unsigned file
= state_machine_regs
.file
;
5457 if (linfo
.li_version
< 5)
5460 if (file_table
== NULL
|| n_files
== 0)
5461 printf (_("\n [Use file table entry %d]\n"), file
);
5463 else if (file
>= n_files
)
5465 warn (_("file index %u >= number of files %u\n"),
5467 printf (_("\n <over large file table index %u>"), file
);
5471 unsigned dir
= file_table
[file
].directory_index
;
5472 if (dir
== 0 && linfo
.li_version
< 5)
5473 /* If directory index is 0, that means compilation
5474 current directory. bfd/dwarf2.c shows
5475 DW_AT_comp_dir here but in keeping with the
5476 readelf practice of minimal interpretation of
5477 file data, we show "./". */
5478 printf ("\n./%s:[++]\n",
5479 null_name (file_table
[file
].name
));
5480 else if (directory_table
== NULL
|| n_directories
== 0)
5481 printf (_("\n [Use file %s "
5482 "in directory table entry %d]\n"),
5483 null_name (file_table
[file
].name
), dir
);
5486 if (linfo
.li_version
< 5)
5489 if (dir
>= n_directories
)
5491 warn (_("directory index %u "
5492 ">= number of directories %u\n"),
5493 dir
, n_directories
);
5494 printf (_("\n <over large directory table entry "
5498 printf ("\n%s/%s:\n",
5499 null_name (directory_table
[dir
]),
5500 null_name (file_table
[file
].name
));
5505 case DW_LNS_set_column
:
5506 READ_ULEB (uladv
, data
, end
);
5507 state_machine_regs
.column
= uladv
;
5510 case DW_LNS_negate_stmt
:
5511 adv
= state_machine_regs
.is_stmt
;
5513 state_machine_regs
.is_stmt
= adv
;
5516 case DW_LNS_set_basic_block
:
5517 state_machine_regs
.basic_block
= 1;
5520 case DW_LNS_const_add_pc
:
5521 uladv
= ((255 - linfo
.li_opcode_base
) / linfo
.li_line_range
);
5522 if (linfo
.li_max_ops_per_insn
== 1)
5524 uladv
*= linfo
.li_min_insn_length
;
5525 state_machine_regs
.address
+= uladv
;
5527 state_machine_regs
.view
= 0;
5532 = ((state_machine_regs
.op_index
+ uladv
)
5533 / linfo
.li_max_ops_per_insn
)
5534 * linfo
.li_min_insn_length
;
5535 state_machine_regs
.address
5537 state_machine_regs
.op_index
5538 = (state_machine_regs
.op_index
+ uladv
)
5539 % linfo
.li_max_ops_per_insn
;
5541 state_machine_regs
.view
= 0;
5545 case DW_LNS_fixed_advance_pc
:
5546 SAFE_BYTE_GET_AND_INC (uladv
, data
, 2, end
);
5547 state_machine_regs
.address
+= uladv
;
5548 state_machine_regs
.op_index
= 0;
5549 /* Do NOT reset view. */
5552 case DW_LNS_set_prologue_end
:
5555 case DW_LNS_set_epilogue_begin
:
5558 case DW_LNS_set_isa
:
5559 READ_ULEB (uladv
, data
, end
);
5560 printf (_(" Set ISA to %lu\n"), uladv
);
5564 printf (_(" Unknown opcode %d with operands: "), op_code
);
5566 if (standard_opcodes
!= NULL
)
5567 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
5571 READ_ULEB (val
, data
, end
);
5572 printf ("%#" PRIx64
"%s", val
, i
== 1 ? "" : ", ");
5578 /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row
5579 to the DWARF address/line matrix. */
5580 if ((is_special_opcode
) || (xop
== -DW_LNE_end_sequence
)
5581 || (xop
== DW_LNS_copy
))
5583 const unsigned int MAX_FILENAME_LENGTH
= 35;
5584 char *fileName
= NULL
;
5585 char *newFileName
= NULL
;
5586 size_t fileNameLength
;
5590 unsigned indx
= state_machine_regs
.file
;
5592 if (linfo
.li_version
< 5)
5595 if (indx
>= n_files
)
5597 warn (_("file index %u >= number of files %u\n"),
5599 fileName
= _("<corrupt>");
5602 fileName
= (char *) file_table
[indx
].name
;
5605 fileName
= _("<unknown>");
5607 fileNameLength
= strlen (fileName
);
5608 newFileName
= fileName
;
5609 if (fileNameLength
> MAX_FILENAME_LENGTH
&& !do_wide
)
5611 newFileName
= (char *) xmalloc (MAX_FILENAME_LENGTH
+ 1);
5612 /* Truncate file name */
5613 memcpy (newFileName
,
5614 fileName
+ fileNameLength
- MAX_FILENAME_LENGTH
,
5615 MAX_FILENAME_LENGTH
);
5616 newFileName
[MAX_FILENAME_LENGTH
] = 0;
5619 /* A row with end_seq set to true has a meaningful address, but
5620 the other information in the same row is not significant.
5621 In such a row, print line as "-", and don't print
5623 if (!do_wide
|| fileNameLength
<= MAX_FILENAME_LENGTH
)
5625 if (linfo
.li_max_ops_per_insn
== 1)
5627 if (xop
== -DW_LNE_end_sequence
)
5628 printf ("%-31s %11s %#18" PRIx64
,
5630 state_machine_regs
.address
);
5632 printf ("%-31s %11d %#18" PRIx64
,
5633 newFileName
, state_machine_regs
.line
,
5634 state_machine_regs
.address
);
5638 if (xop
== -DW_LNE_end_sequence
)
5639 printf ("%-31s %11s %#18" PRIx64
"[%d]",
5641 state_machine_regs
.address
,
5642 state_machine_regs
.op_index
);
5644 printf ("%-31s %11d %#18" PRIx64
"[%d]",
5645 newFileName
, state_machine_regs
.line
,
5646 state_machine_regs
.address
,
5647 state_machine_regs
.op_index
);
5652 if (linfo
.li_max_ops_per_insn
== 1)
5654 if (xop
== -DW_LNE_end_sequence
)
5655 printf ("%s %11s %#18" PRIx64
,
5657 state_machine_regs
.address
);
5659 printf ("%s %11d %#18" PRIx64
,
5660 newFileName
, state_machine_regs
.line
,
5661 state_machine_regs
.address
);
5665 if (xop
== -DW_LNE_end_sequence
)
5666 printf ("%s %11s %#18" PRIx64
"[%d]",
5668 state_machine_regs
.address
,
5669 state_machine_regs
.op_index
);
5671 printf ("%s %11d %#18" PRIx64
"[%d]",
5672 newFileName
, state_machine_regs
.line
,
5673 state_machine_regs
.address
,
5674 state_machine_regs
.op_index
);
5678 if (xop
!= -DW_LNE_end_sequence
)
5680 if (state_machine_regs
.view
)
5681 printf (" %6u", state_machine_regs
.view
);
5685 if (state_machine_regs
.is_stmt
)
5690 state_machine_regs
.view
++;
5692 if (xop
== -DW_LNE_end_sequence
)
5694 reset_state_machine (linfo
.li_default_is_stmt
);
5698 if (newFileName
!= fileName
)
5710 if (directory_table
)
5712 free (directory_table
);
5713 directory_table
= NULL
;
5724 display_debug_lines (struct dwarf_section
*section
, void *file
)
5726 unsigned char *data
= section
->start
;
5727 unsigned char *end
= data
+ section
->size
;
5729 int retValDecoded
= 1;
5731 if (do_debug_lines
== 0)
5732 do_debug_lines
|= FLAG_DEBUG_LINES_RAW
;
5734 if (do_debug_lines
& FLAG_DEBUG_LINES_RAW
)
5735 retValRaw
= display_debug_lines_raw (section
, data
, end
, file
);
5737 if (do_debug_lines
& FLAG_DEBUG_LINES_DECODED
)
5738 retValDecoded
= display_debug_lines_decoded (section
, data
, data
, end
, file
);
5740 if (!retValRaw
|| !retValDecoded
)
5747 find_debug_info_for_offset (uint64_t offset
)
5751 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
5754 for (i
= 0; i
< num_debug_info_entries
; i
++)
5755 if (debug_information
[i
].cu_offset
== offset
)
5756 return debug_information
+ i
;
5762 get_gdb_index_symbol_kind_name (gdb_index_symbol_kind kind
)
5764 /* See gdb/gdb-index.h. */
5765 static const char * const kinds
[] =
5777 return _ (kinds
[kind
]);
5781 display_debug_pubnames_worker (struct dwarf_section
*section
,
5782 void *file ATTRIBUTE_UNUSED
,
5785 DWARF2_Internal_PubNames names
;
5786 unsigned char *start
= section
->start
;
5787 unsigned char *end
= start
+ section
->size
;
5789 /* It does not matter if this load fails,
5790 we test for that later on. */
5791 load_debug_info (file
);
5793 introduce (section
, false);
5797 unsigned char *data
;
5798 unsigned long sec_off
= start
- section
->start
;
5799 unsigned int offset_size
;
5801 SAFE_BYTE_GET_AND_INC (names
.pn_length
, start
, 4, end
);
5802 if (names
.pn_length
== 0xffffffff)
5804 SAFE_BYTE_GET_AND_INC (names
.pn_length
, start
, 8, end
);
5810 if (names
.pn_length
> (size_t) (end
- start
))
5812 warn (_("Debug info is corrupted, "
5813 "%s header at %#lx has length %#" PRIx64
"\n"),
5814 section
->name
, sec_off
, names
.pn_length
);
5819 start
+= names
.pn_length
;
5821 SAFE_BYTE_GET_AND_INC (names
.pn_version
, data
, 2, start
);
5822 SAFE_BYTE_GET_AND_INC (names
.pn_offset
, data
, offset_size
, start
);
5824 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
5825 && num_debug_info_entries
> 0
5826 && find_debug_info_for_offset (names
.pn_offset
) == NULL
)
5827 warn (_(".debug_info offset of %#" PRIx64
5828 " in %s section does not point to a CU header.\n"),
5829 names
.pn_offset
, section
->name
);
5831 SAFE_BYTE_GET_AND_INC (names
.pn_size
, data
, offset_size
, start
);
5833 printf (_(" Length: %" PRId64
"\n"),
5835 printf (_(" Version: %d\n"),
5837 printf (_(" Offset into .debug_info section: %#" PRIx64
"\n"),
5839 printf (_(" Size of area in .debug_info section: %" PRId64
"\n"),
5842 if (names
.pn_version
!= 2 && names
.pn_version
!= 3)
5844 static int warned
= 0;
5848 warn (_("Only DWARF 2 and 3 pubnames are currently supported\n"));
5856 printf (_("\n Offset Kind Name\n"));
5858 printf (_("\n Offset\tName\n"));
5865 SAFE_BYTE_GET_AND_INC (offset
, data
, offset_size
, start
);
5872 maxprint
= (start
- data
) - 1;
5876 unsigned int kind_data
;
5877 gdb_index_symbol_kind kind
;
5878 const char *kind_name
;
5881 SAFE_BYTE_GET_AND_INC (kind_data
, data
, 1, start
);
5883 /* GCC computes the kind as the upper byte in the CU index
5884 word, and then right shifts it by the CU index size.
5885 Left shift KIND to where the gdb-index.h accessor macros
5887 kind_data
<<= GDB_INDEX_CU_BITSIZE
;
5888 kind
= GDB_INDEX_SYMBOL_KIND_VALUE (kind_data
);
5889 kind_name
= get_gdb_index_symbol_kind_name (kind
);
5890 is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (kind_data
);
5891 printf (" %-6" PRIx64
" %s,%-10s %.*s\n",
5892 offset
, is_static
? _("s") : _("g"),
5893 kind_name
, (int) maxprint
, data
);
5896 printf (" %-6" PRIx64
"\t%.*s\n",
5897 offset
, (int) maxprint
, data
);
5899 data
+= strnlen ((char *) data
, maxprint
);
5912 display_debug_pubnames (struct dwarf_section
*section
, void *file
)
5914 return display_debug_pubnames_worker (section
, file
, 0);
5918 display_debug_gnu_pubnames (struct dwarf_section
*section
, void *file
)
5920 return display_debug_pubnames_worker (section
, file
, 1);
5924 display_debug_macinfo (struct dwarf_section
*section
,
5925 void *file ATTRIBUTE_UNUSED
)
5927 unsigned char *start
= section
->start
;
5928 unsigned char *end
= start
+ section
->size
;
5929 unsigned char *curr
= start
;
5930 enum dwarf_macinfo_record_type op
;
5932 introduce (section
, false);
5936 unsigned int lineno
;
5937 const unsigned char *string
;
5939 op
= (enum dwarf_macinfo_record_type
) *curr
;
5944 case DW_MACINFO_start_file
:
5946 unsigned int filenum
;
5948 READ_ULEB (lineno
, curr
, end
);
5949 READ_ULEB (filenum
, curr
, end
);
5950 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"),
5955 case DW_MACINFO_end_file
:
5956 printf (_(" DW_MACINFO_end_file\n"));
5959 case DW_MACINFO_define
:
5960 READ_ULEB (lineno
, curr
, end
);
5962 curr
+= strnlen ((char *) string
, end
- string
);
5963 printf (_(" DW_MACINFO_define - lineno : %d macro : %*s\n"),
5964 lineno
, (int) (curr
- string
), string
);
5969 case DW_MACINFO_undef
:
5970 READ_ULEB (lineno
, curr
, end
);
5972 curr
+= strnlen ((char *) string
, end
- string
);
5973 printf (_(" DW_MACINFO_undef - lineno : %d macro : %*s\n"),
5974 lineno
, (int) (curr
- string
), string
);
5979 case DW_MACINFO_vendor_ext
:
5981 unsigned int constant
;
5983 READ_ULEB (constant
, curr
, end
);
5985 curr
+= strnlen ((char *) string
, end
- string
);
5986 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %*s\n"),
5987 constant
, (int) (curr
- string
), string
);
5998 /* Given LINE_OFFSET into the .debug_line section, attempt to return
5999 filename and dirname corresponding to file name table entry with index
6000 FILEIDX. Return NULL on failure. */
6002 static unsigned char *
6003 get_line_filename_and_dirname (uint64_t line_offset
,
6005 unsigned char **dir_name
)
6007 struct dwarf_section
*section
= &debug_displays
[line
].section
;
6008 unsigned char *hdrptr
, *dirtable
, *file_name
;
6009 unsigned int offset_size
;
6010 unsigned int version
, opcode_base
;
6011 uint64_t length
, diridx
;
6012 const unsigned char * end
;
6015 if (section
->start
== NULL
6016 || line_offset
>= section
->size
6020 hdrptr
= section
->start
+ line_offset
;
6021 end
= section
->start
+ section
->size
;
6023 SAFE_BYTE_GET_AND_INC (length
, hdrptr
, 4, end
);
6024 if (length
== 0xffffffff)
6026 /* This section is 64-bit DWARF 3. */
6027 SAFE_BYTE_GET_AND_INC (length
, hdrptr
, 8, end
);
6033 if (length
> (size_t) (end
- hdrptr
)
6034 || length
< 2 + offset_size
+ 1 + 3 + 1)
6036 end
= hdrptr
+ length
;
6038 SAFE_BYTE_GET_AND_INC (version
, hdrptr
, 2, end
);
6039 if (version
!= 2 && version
!= 3 && version
!= 4)
6041 hdrptr
+= offset_size
+ 1;/* Skip prologue_length and min_insn_length. */
6043 hdrptr
++; /* Skip max_ops_per_insn. */
6044 hdrptr
+= 3; /* Skip default_is_stmt, line_base, line_range. */
6046 SAFE_BYTE_GET_AND_INC (opcode_base
, hdrptr
, 1, end
);
6047 if (opcode_base
== 0
6048 || opcode_base
- 1 >= (size_t) (end
- hdrptr
))
6051 hdrptr
+= opcode_base
- 1;
6054 /* Skip over dirname table. */
6055 while (*hdrptr
!= '\0')
6057 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
);
6063 hdrptr
++; /* Skip the NUL at the end of the table. */
6065 /* Now skip over preceding filename table entries. */
6066 for (; hdrptr
< end
&& *hdrptr
!= '\0' && fileidx
> 1; fileidx
--)
6068 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
);
6071 SKIP_ULEB (hdrptr
, end
);
6072 SKIP_ULEB (hdrptr
, end
);
6073 SKIP_ULEB (hdrptr
, end
);
6075 if (hdrptr
>= end
|| *hdrptr
== '\0')
6079 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
);
6084 READ_ULEB (diridx
, hdrptr
, end
);
6087 for (; dirtable
< end
&& *dirtable
!= '\0' && diridx
> 1; diridx
--)
6089 dirtable
+= strnlen ((char *) dirtable
, end
- dirtable
);
6093 if (dirtable
>= end
|| *dirtable
== '\0')
6095 *dir_name
= dirtable
;
6100 display_debug_macro (struct dwarf_section
*section
,
6103 unsigned char *start
= section
->start
;
6104 unsigned char *end
= start
+ section
->size
;
6105 unsigned char *curr
= start
;
6106 unsigned char *extended_op_buf
[256];
6107 bool is_dwo
= false;
6108 const char *suffix
= strrchr (section
->name
, '.');
6110 if (suffix
&& strcmp (suffix
, ".dwo") == 0)
6113 load_debug_section_with_follow (str
, file
);
6114 load_debug_section_with_follow (line
, file
);
6115 load_debug_section_with_follow (str_index
, file
);
6117 introduce (section
, false);
6121 unsigned int lineno
, version
, flags
;
6122 unsigned int offset_size
;
6123 const unsigned char *string
;
6124 uint64_t line_offset
= 0, sec_offset
= curr
- start
, offset
;
6125 unsigned char **extended_ops
= NULL
;
6127 SAFE_BYTE_GET_AND_INC (version
, curr
, 2, end
);
6128 if (version
!= 4 && version
!= 5)
6130 error (_("Expected to find a version number of 4 or 5 in section %s but found %d instead\n"),
6131 section
->name
, version
);
6135 SAFE_BYTE_GET_AND_INC (flags
, curr
, 1, end
);
6136 offset_size
= (flags
& 1) ? 8 : 4;
6137 printf (_(" Offset: %#" PRIx64
"\n"), sec_offset
);
6138 printf (_(" Version: %d\n"), version
);
6139 printf (_(" Offset size: %d\n"), offset_size
);
6142 SAFE_BYTE_GET_AND_INC (line_offset
, curr
, offset_size
, end
);
6143 printf (_(" Offset into .debug_line: %#" PRIx64
"\n"),
6148 unsigned int i
, count
, op
;
6151 SAFE_BYTE_GET_AND_INC (count
, curr
, 1, end
);
6153 memset (extended_op_buf
, 0, sizeof (extended_op_buf
));
6154 extended_ops
= extended_op_buf
;
6157 printf (_(" Extension opcode arguments:\n"));
6158 for (i
= 0; i
< count
; i
++)
6160 SAFE_BYTE_GET_AND_INC (op
, curr
, 1, end
);
6161 extended_ops
[op
] = curr
;
6162 READ_ULEB (nargs
, curr
, end
);
6164 printf (_(" DW_MACRO_%02x has no arguments\n"), op
);
6167 printf (_(" DW_MACRO_%02x arguments: "), op
);
6168 for (n
= 0; n
< nargs
; n
++)
6172 SAFE_BYTE_GET_AND_INC (form
, curr
, 1, end
);
6173 printf ("%s%s", get_FORM_name (form
),
6174 n
== nargs
- 1 ? "\n" : ", ");
6184 case DW_FORM_block1
:
6185 case DW_FORM_block2
:
6186 case DW_FORM_block4
:
6188 case DW_FORM_string
:
6190 case DW_FORM_sec_offset
:
6193 error (_("Invalid extension opcode form %s\n"),
6194 get_FORM_name (form
));
6210 error (_(".debug_macro section not zero terminated\n"));
6214 SAFE_BYTE_GET_AND_INC (op
, curr
, 1, end
);
6220 case DW_MACRO_define
:
6221 READ_ULEB (lineno
, curr
, end
);
6223 curr
+= strnlen ((char *) string
, end
- string
);
6224 printf (_(" DW_MACRO_define - lineno : %d macro : %*s\n"),
6225 lineno
, (int) (curr
- string
), string
);
6230 case DW_MACRO_undef
:
6231 READ_ULEB (lineno
, curr
, end
);
6233 curr
+= strnlen ((char *) string
, end
- string
);
6234 printf (_(" DW_MACRO_undef - lineno : %d macro : %*s\n"),
6235 lineno
, (int) (curr
- string
), string
);
6240 case DW_MACRO_start_file
:
6242 unsigned int filenum
;
6243 unsigned char *file_name
= NULL
, *dir_name
= NULL
;
6245 READ_ULEB (lineno
, curr
, end
);
6246 READ_ULEB (filenum
, curr
, end
);
6248 if ((flags
& 2) == 0)
6249 error (_("DW_MACRO_start_file used, but no .debug_line offset provided.\n"));
6252 = get_line_filename_and_dirname (line_offset
, filenum
,
6254 if (file_name
== NULL
)
6255 printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d\n"),
6258 printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d filename: %s%s%s\n"),
6260 dir_name
!= NULL
? (const char *) dir_name
: "",
6261 dir_name
!= NULL
? "/" : "", file_name
);
6265 case DW_MACRO_end_file
:
6266 printf (_(" DW_MACRO_end_file\n"));
6269 case DW_MACRO_define_strp
:
6270 READ_ULEB (lineno
, curr
, end
);
6271 if (version
== 4 && is_dwo
)
6272 READ_ULEB (offset
, curr
, end
);
6274 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6275 string
= fetch_indirect_string (offset
);
6276 printf (_(" DW_MACRO_define_strp - lineno : %d macro : %s\n"),
6280 case DW_MACRO_undef_strp
:
6281 READ_ULEB (lineno
, curr
, end
);
6282 if (version
== 4 && is_dwo
)
6283 READ_ULEB (offset
, curr
, end
);
6285 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6286 string
= fetch_indirect_string (offset
);
6287 printf (_(" DW_MACRO_undef_strp - lineno : %d macro : %s\n"),
6291 case DW_MACRO_import
:
6292 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6293 printf (_(" DW_MACRO_import - offset : %#" PRIx64
"\n"),
6297 case DW_MACRO_define_sup
:
6298 READ_ULEB (lineno
, curr
, end
);
6299 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6300 printf (_(" DW_MACRO_define_sup - lineno : %d"
6301 " macro offset : %#" PRIx64
"\n"),
6305 case DW_MACRO_undef_sup
:
6306 READ_ULEB (lineno
, curr
, end
);
6307 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6308 printf (_(" DW_MACRO_undef_sup - lineno : %d"
6309 " macro offset : %#" PRIx64
"\n"),
6313 case DW_MACRO_import_sup
:
6314 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6315 printf (_(" DW_MACRO_import_sup - offset : %#" PRIx64
"\n"),
6319 case DW_MACRO_define_strx
:
6320 case DW_MACRO_undef_strx
:
6321 READ_ULEB (lineno
, curr
, end
);
6322 READ_ULEB (offset
, curr
, end
);
6323 string
= (const unsigned char *)
6324 fetch_indexed_string (offset
, NULL
, offset_size
, false, 0);
6325 if (op
== DW_MACRO_define_strx
)
6326 printf (" DW_MACRO_define_strx ");
6328 printf (" DW_MACRO_undef_strx ");
6330 printf (_("(with offset %#" PRIx64
") "), offset
);
6331 printf (_("lineno : %d macro : %s\n"),
6336 if (op
>= DW_MACRO_lo_user
&& op
<= DW_MACRO_hi_user
)
6338 printf (_(" <Target Specific macro op: %#x - UNHANDLED"), op
);
6342 if (extended_ops
== NULL
|| extended_ops
[op
] == NULL
)
6344 error (_(" Unknown macro opcode %02x seen\n"), op
);
6349 /* Skip over unhandled opcodes. */
6351 unsigned char *desc
= extended_ops
[op
];
6352 READ_ULEB (nargs
, desc
, end
);
6355 printf (_(" DW_MACRO_%02x\n"), op
);
6358 printf (_(" DW_MACRO_%02x -"), op
);
6359 for (n
= 0; n
< nargs
; n
++)
6363 /* DW_FORM_implicit_const is not expected here. */
6364 SAFE_BYTE_GET_AND_INC (val
, desc
, 1, end
);
6366 = read_and_display_attr_value (0, val
, 0,
6367 start
, curr
, end
, 0, 0,
6368 offset_size
, version
,
6387 display_debug_abbrev (struct dwarf_section
*section
,
6388 void *file ATTRIBUTE_UNUSED
)
6390 abbrev_entry
*entry
;
6391 unsigned char *start
= section
->start
;
6393 introduce (section
, false);
6397 uint64_t offset
= start
- section
->start
;
6398 abbrev_list
*list
= find_and_process_abbrev_set (section
, 0,
6399 section
->size
, offset
,
6404 if (list
->first_abbrev
)
6405 printf (_(" Number TAG (%#" PRIx64
")\n"), offset
);
6407 for (entry
= list
->first_abbrev
; entry
; entry
= entry
->next
)
6411 printf (" %ld %s [%s]\n",
6413 get_TAG_name (entry
->tag
),
6414 entry
->children
? _("has children") : _("no children"));
6416 for (attr
= entry
->first_attr
; attr
; attr
= attr
->next
)
6418 printf (" %-18s %s",
6419 get_AT_name (attr
->attribute
),
6420 get_FORM_name (attr
->form
));
6421 if (attr
->form
== DW_FORM_implicit_const
)
6422 printf (": %" PRId64
, attr
->implicit_const
);
6426 start
= list
->start_of_next_abbrevs
;
6427 free_abbrev_list (list
);
6436 /* Return true when ADDR is the maximum address, when addresses are
6437 POINTER_SIZE bytes long. */
6440 is_max_address (uint64_t addr
, unsigned int pointer_size
)
6442 uint64_t mask
= ~(~(uint64_t) 0 << 1 << (pointer_size
* 8 - 1));
6443 return ((addr
& mask
) == mask
);
6446 /* Display a view pair list starting at *VSTART_PTR and ending at
6447 VLISTEND within SECTION. */
6450 display_view_pair_list (struct dwarf_section
*section
,
6451 unsigned char **vstart_ptr
,
6452 unsigned int debug_info_entry
,
6453 unsigned char *vlistend
)
6455 unsigned char *vstart
= *vstart_ptr
;
6456 unsigned char *section_end
= section
->start
+ section
->size
;
6457 unsigned int pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
6459 if (vlistend
< section_end
)
6460 section_end
= vlistend
;
6464 while (vstart
< section_end
)
6466 uint64_t off
= vstart
- section
->start
;
6467 uint64_t vbegin
, vend
;
6469 READ_ULEB (vbegin
, vstart
, section_end
);
6470 if (vstart
== section_end
)
6473 READ_ULEB (vend
, vstart
, section_end
);
6474 printf (" %8.8" PRIx64
" ", off
);
6476 print_view (vbegin
, pointer_size
);
6477 print_view (vend
, pointer_size
);
6478 printf (_("location view pair\n"));
6482 *vstart_ptr
= vstart
;
6485 /* Display a location list from a normal (ie, non-dwo) .debug_loc section. */
6488 display_loc_list (struct dwarf_section
*section
,
6489 unsigned char **start_ptr
,
6490 unsigned int debug_info_entry
,
6492 uint64_t base_address
,
6493 unsigned char **vstart_ptr
,
6496 unsigned char *start
= *start_ptr
, *vstart
= *vstart_ptr
;
6497 unsigned char *section_end
= section
->start
+ section
->size
;
6499 unsigned int pointer_size
;
6500 unsigned int offset_size
;
6504 unsigned short length
;
6505 int need_frame_base
;
6507 if (debug_info_entry
>= num_debug_info_entries
)
6509 warn (_("No debug information available for loc lists of entry: %u\n"),
6514 cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
6515 pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
6516 offset_size
= debug_information
[debug_info_entry
].offset_size
;
6517 dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
6519 if (pointer_size
< 2 || pointer_size
> 8)
6521 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
6522 pointer_size
, debug_info_entry
);
6528 uint64_t off
= offset
+ (start
- *start_ptr
);
6529 uint64_t vbegin
= -1, vend
= -1;
6531 if (2 * pointer_size
> (size_t) (section_end
- start
))
6533 warn (_("Location list starting at offset %#" PRIx64
6534 " is not terminated.\n"), offset
);
6541 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, section_end
);
6542 SAFE_BYTE_GET_AND_INC (end
, start
, pointer_size
, section_end
);
6544 if (begin
== 0 && end
== 0)
6546 /* PR 18374: In a object file we can have a location list that
6547 starts with a begin and end of 0 because there are relocations
6548 that need to be applied to the addresses. Actually applying
6549 the relocations now does not help as they will probably resolve
6550 to 0, since the object file has not been fully linked. Real
6551 end of list markers will not have any relocations against them. */
6552 if (! reloc_at (section
, off
)
6553 && ! reloc_at (section
, off
+ pointer_size
))
6555 printf (_("<End of list>\n"));
6560 /* Check base address specifiers. */
6561 if (is_max_address (begin
, pointer_size
)
6562 && !is_max_address (end
, pointer_size
))
6565 print_hex (begin
, pointer_size
);
6566 print_hex (end
, pointer_size
);
6567 printf (_("(base address)\n"));
6573 off
= offset
+ (vstart
- *start_ptr
);
6575 READ_ULEB (vbegin
, vstart
, section_end
);
6576 print_view (vbegin
, pointer_size
);
6578 READ_ULEB (vend
, vstart
, section_end
);
6579 print_view (vend
, pointer_size
);
6581 printf (_("views at %8.8" PRIx64
" for:\n %*s "), off
, 8, "");
6584 if (2 > (size_t) (section_end
- start
))
6586 warn (_("Location list starting at offset %#" PRIx64
6587 " is not terminated.\n"), offset
);
6591 SAFE_BYTE_GET_AND_INC (length
, start
, 2, section_end
);
6593 if (length
> (size_t) (section_end
- start
))
6595 warn (_("Location list starting at offset %#" PRIx64
6596 " is not terminated.\n"), offset
);
6600 print_hex (begin
+ base_address
, pointer_size
);
6601 print_hex (end
+ base_address
, pointer_size
);
6604 need_frame_base
= decode_location_expression (start
,
6609 cu_offset
, section
);
6612 if (need_frame_base
&& !has_frame_base
)
6613 printf (_(" [without DW_AT_frame_base]"));
6615 if (begin
== end
&& vbegin
== vend
)
6616 fputs (_(" (start == end)"), stdout
);
6617 else if (begin
> end
|| (begin
== end
&& vbegin
> vend
))
6618 fputs (_(" (start > end)"), stdout
);
6626 *vstart_ptr
= vstart
;
6629 /* Display a location list from a normal (ie, non-dwo) .debug_loclists section. */
6632 display_loclists_list (struct dwarf_section
* section
,
6633 unsigned char ** start_ptr
,
6634 unsigned int debug_info_entry
,
6636 uint64_t base_address
,
6637 unsigned char ** vstart_ptr
,
6640 unsigned char *start
= *start_ptr
;
6641 unsigned char *vstart
= *vstart_ptr
;
6642 unsigned char *section_end
= section
->start
+ section
->size
;
6644 unsigned int pointer_size
;
6645 unsigned int offset_size
;
6646 unsigned int dwarf_version
;
6648 /* Initialize it due to a false compiler warning. */
6649 uint64_t begin
= -1, vbegin
= -1;
6650 uint64_t end
= -1, vend
= -1;
6652 int need_frame_base
;
6654 if (debug_info_entry
>= num_debug_info_entries
)
6656 warn (_("No debug information available for "
6657 "loclists lists of entry: %u\n"),
6662 cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
6663 pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
6664 offset_size
= debug_information
[debug_info_entry
].offset_size
;
6665 dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
6667 if (pointer_size
< 2 || pointer_size
> 8)
6669 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
6670 pointer_size
, debug_info_entry
);
6676 uint64_t off
= offset
+ (start
- *start_ptr
);
6677 enum dwarf_location_list_entry_type llet
;
6679 if (start
+ 1 > section_end
)
6681 warn (_("Location list starting at offset %#" PRIx64
6682 " is not terminated.\n"), offset
);
6689 SAFE_BYTE_GET_AND_INC (llet
, start
, 1, section_end
);
6691 if (vstart
&& (llet
== DW_LLE_offset_pair
6692 || llet
== DW_LLE_start_end
6693 || llet
== DW_LLE_start_length
))
6695 off
= offset
+ (vstart
- *start_ptr
);
6697 READ_ULEB (vbegin
, vstart
, section_end
);
6698 print_view (vbegin
, pointer_size
);
6700 READ_ULEB (vend
, vstart
, section_end
);
6701 print_view (vend
, pointer_size
);
6703 printf (_("views at %8.8" PRIx64
" for:\n %*s "), off
, 8, "");
6708 case DW_LLE_end_of_list
:
6709 printf (_("<End of list>\n"));
6712 case DW_LLE_base_addressx
:
6713 READ_ULEB (base_address
, start
, section_end
);
6714 print_hex (base_address
, pointer_size
);
6715 printf (_("(index into .debug_addr) "));
6716 base_address
= fetch_indexed_addr (base_address
, pointer_size
);
6717 print_hex (base_address
, pointer_size
);
6718 printf (_("(base address)\n"));
6721 case DW_LLE_startx_endx
:
6722 READ_ULEB (begin
, start
, section_end
);
6723 begin
= fetch_indexed_addr (begin
, pointer_size
);
6724 READ_ULEB (end
, start
, section_end
);
6725 end
= fetch_indexed_addr (end
, pointer_size
);
6728 case DW_LLE_startx_length
:
6729 READ_ULEB (begin
, start
, section_end
);
6730 begin
= fetch_indexed_addr (begin
, pointer_size
);
6731 READ_ULEB (end
, start
, section_end
);
6735 case DW_LLE_default_location
:
6739 case DW_LLE_offset_pair
:
6740 READ_ULEB (begin
, start
, section_end
);
6741 begin
+= base_address
;
6742 READ_ULEB (end
, start
, section_end
);
6743 end
+= base_address
;
6746 case DW_LLE_base_address
:
6747 SAFE_BYTE_GET_AND_INC (base_address
, start
, pointer_size
,
6749 print_hex (base_address
, pointer_size
);
6750 printf (_("(base address)\n"));
6753 case DW_LLE_start_end
:
6754 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, section_end
);
6755 SAFE_BYTE_GET_AND_INC (end
, start
, pointer_size
, section_end
);
6758 case DW_LLE_start_length
:
6759 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, section_end
);
6760 READ_ULEB (end
, start
, section_end
);
6764 #ifdef DW_LLE_view_pair
6765 case DW_LLE_view_pair
:
6767 printf (_("View pair entry in loclist with locviews attribute\n"));
6768 READ_ULEB (vbegin
, start
, section_end
);
6769 print_view (vbegin
, pointer_size
);
6771 READ_ULEB (vend
, start
, section_end
);
6772 print_view (vend
, pointer_size
);
6774 printf (_("views for:\n"));
6779 error (_("Invalid location list entry type %d\n"), llet
);
6783 if (llet
== DW_LLE_end_of_list
)
6786 if (llet
== DW_LLE_base_address
6787 || llet
== DW_LLE_base_addressx
)
6790 if (start
== section_end
)
6792 warn (_("Location list starting at offset %#" PRIx64
6793 " is not terminated.\n"), offset
);
6796 READ_ULEB (length
, start
, section_end
);
6798 if (length
> (size_t) (section_end
- start
))
6800 warn (_("Location list starting at offset %#" PRIx64
6801 " is not terminated.\n"), offset
);
6805 print_hex (begin
, pointer_size
);
6806 print_hex (end
, pointer_size
);
6809 need_frame_base
= decode_location_expression (start
,
6814 cu_offset
, section
);
6817 if (need_frame_base
&& !has_frame_base
)
6818 printf (_(" [without DW_AT_frame_base]"));
6820 if (begin
== end
&& vbegin
== vend
)
6821 fputs (_(" (start == end)"), stdout
);
6822 else if (begin
> end
|| (begin
== end
&& vbegin
> vend
))
6823 fputs (_(" (start > end)"), stdout
);
6831 if (vbegin
!= (uint64_t) -1 || vend
!= (uint64_t) -1)
6832 printf (_("Trailing view pair not used in a range"));
6835 *vstart_ptr
= vstart
;
6838 /* Print a .debug_addr table index in decimal, surrounded by square brackets,
6839 right-adjusted in a field of length LEN, and followed by a space. */
6842 print_addr_index (unsigned int idx
, unsigned int len
)
6844 static char buf
[15];
6845 snprintf (buf
, sizeof (buf
), "[%d]", idx
);
6846 printf ("%*s ", len
, buf
);
6849 /* Display a location list from a .dwo section. It uses address indexes rather
6850 than embedded addresses. This code closely follows display_loc_list, but the
6851 two are sufficiently different that combining things is very ugly. */
6854 display_loc_list_dwo (struct dwarf_section
*section
,
6855 unsigned char **start_ptr
,
6856 unsigned int debug_info_entry
,
6858 unsigned char **vstart_ptr
,
6861 unsigned char *start
= *start_ptr
, *vstart
= *vstart_ptr
;
6862 unsigned char *section_end
= section
->start
+ section
->size
;
6864 unsigned int pointer_size
;
6865 unsigned int offset_size
;
6868 unsigned short length
;
6869 int need_frame_base
;
6872 if (debug_info_entry
>= num_debug_info_entries
)
6874 warn (_("No debug information for loc lists of entry: %u\n"),
6879 cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
6880 pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
6881 offset_size
= debug_information
[debug_info_entry
].offset_size
;
6882 dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
6884 if (pointer_size
< 2 || pointer_size
> 8)
6886 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
6887 pointer_size
, debug_info_entry
);
6894 print_hex (offset
+ (start
- *start_ptr
), 4);
6896 if (start
>= section_end
)
6898 warn (_("Location list starting at offset %#" PRIx64
6899 " is not terminated.\n"), offset
);
6903 SAFE_BYTE_GET_AND_INC (entry_type
, start
, 1, section_end
);
6916 uint64_t off
= offset
+ (vstart
- *start_ptr
);
6918 READ_ULEB (view
, vstart
, section_end
);
6919 print_view (view
, 8);
6921 READ_ULEB (view
, vstart
, section_end
);
6922 print_view (view
, 8);
6924 printf (_("views at %8.8" PRIx64
" for:\n %*s "), off
, 8, "");
6932 case 0: /* A terminating entry. */
6934 *vstart_ptr
= vstart
;
6935 printf (_("<End of list>\n"));
6937 case 1: /* A base-address entry. */
6938 READ_ULEB (idx
, start
, section_end
);
6939 print_addr_index (idx
, 8);
6940 printf ("%*s", 9 + (vstart
? 2 * 6 : 0), "");
6941 printf (_("(base address selection entry)\n"));
6943 case 2: /* A start/end entry. */
6944 READ_ULEB (idx
, start
, section_end
);
6945 print_addr_index (idx
, 8);
6946 READ_ULEB (idx
, start
, section_end
);
6947 print_addr_index (idx
, 8);
6949 case 3: /* A start/length entry. */
6950 READ_ULEB (idx
, start
, section_end
);
6951 print_addr_index (idx
, 8);
6952 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
6953 printf ("%08x ", idx
);
6955 case 4: /* An offset pair entry. */
6956 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
6957 printf ("%08x ", idx
);
6958 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
6959 printf ("%08x ", idx
);
6962 warn (_("Unknown location list entry type 0x%x.\n"), entry_type
);
6964 *vstart_ptr
= vstart
;
6968 if (2 > (size_t) (section_end
- start
))
6970 warn (_("Location list starting at offset %#" PRIx64
6971 " is not terminated.\n"), offset
);
6975 SAFE_BYTE_GET_AND_INC (length
, start
, 2, section_end
);
6976 if (length
> (size_t) (section_end
- start
))
6978 warn (_("Location list starting at offset %#" PRIx64
6979 " is not terminated.\n"), offset
);
6984 need_frame_base
= decode_location_expression (start
,
6989 cu_offset
, section
);
6992 if (need_frame_base
&& !has_frame_base
)
6993 printf (_(" [without DW_AT_frame_base]"));
7001 *vstart_ptr
= vstart
;
7004 /* Sort array of indexes in ascending order of loc_offsets[idx] and
7007 static uint64_t *loc_offsets
, *loc_views
;
7010 loc_offsets_compar (const void *ap
, const void *bp
)
7012 uint64_t a
= loc_offsets
[*(const unsigned int *) ap
];
7013 uint64_t b
= loc_offsets
[*(const unsigned int *) bp
];
7015 int ret
= (a
> b
) - (b
> a
);
7019 a
= loc_views
[*(const unsigned int *) ap
];
7020 b
= loc_views
[*(const unsigned int *) bp
];
7022 ret
= (a
> b
) - (b
> a
);
7028 display_offset_entry_loclists (struct dwarf_section
*section
)
7030 unsigned char * start
= section
->start
;
7031 unsigned char * const end
= start
+ section
->size
;
7033 introduce (section
, false);
7038 unsigned short version
;
7039 unsigned char address_size
;
7040 unsigned char segment_selector_size
;
7041 uint32_t offset_entry_count
;
7045 printf (_("Table at Offset %#tx\n"), start
- section
->start
);
7047 SAFE_BYTE_GET_AND_INC (length
, start
, 4, end
);
7048 if (length
== 0xffffffff)
7051 SAFE_BYTE_GET_AND_INC (length
, start
, 8, end
);
7056 SAFE_BYTE_GET_AND_INC (version
, start
, 2, end
);
7057 SAFE_BYTE_GET_AND_INC (address_size
, start
, 1, end
);
7058 SAFE_BYTE_GET_AND_INC (segment_selector_size
, start
, 1, end
);
7059 SAFE_BYTE_GET_AND_INC (offset_entry_count
, start
, 4, end
);
7061 printf (_(" Length: %#" PRIx64
"\n"), length
);
7062 printf (_(" DWARF version: %u\n"), version
);
7063 printf (_(" Address size: %u\n"), address_size
);
7064 printf (_(" Segment size: %u\n"), segment_selector_size
);
7065 printf (_(" Offset entries: %u\n"), offset_entry_count
);
7069 warn (_("The %s section contains a corrupt or "
7070 "unsupported version number: %d.\n"),
7071 section
->name
, version
);
7075 if (segment_selector_size
!= 0)
7077 warn (_("The %s section contains an "
7078 "unsupported segment selector size: %d.\n"),
7079 section
->name
, segment_selector_size
);
7083 if (offset_entry_count
== 0)
7085 warn (_("The %s section contains a table without offset\n"),
7090 printf (_("\n Offset Entries starting at %#tx:\n"),
7091 start
- section
->start
);
7093 for (i
= 0; i
< offset_entry_count
; i
++)
7097 SAFE_BYTE_GET_AND_INC (entry
, start
, is_64bit
? 8 : 4, end
);
7098 printf (_(" [%6u] %#" PRIx64
"\n"), i
, entry
);
7105 for (j
= 1, i
= 0; i
< offset_entry_count
;)
7108 uint64_t base_address
= 0;
7111 uint64_t off
= start
- section
->start
;
7115 printf (_(" Offset Entry %u\n"), i
);
7122 SAFE_BYTE_GET_AND_INC (lle
, start
, 1, end
);
7126 case DW_LLE_end_of_list
:
7127 printf (_("<End of list>\n\n"));
7131 case DW_LLE_base_addressx
:
7132 READ_ULEB (base_address
, start
, end
);
7133 print_hex (base_address
, address_size
);
7134 printf (_("(index into .debug_addr) "));
7135 base_address
= fetch_indexed_addr (base_address
, address_size
);
7136 print_hex (base_address
, address_size
);
7137 printf (_("(base address)\n"));
7140 case DW_LLE_startx_endx
:
7141 READ_ULEB (begin
, start
, end
);
7142 begin
= fetch_indexed_addr (begin
, address_size
);
7143 READ_ULEB (finish
, start
, end
);
7144 finish
= fetch_indexed_addr (finish
, address_size
);
7147 case DW_LLE_startx_length
:
7148 READ_ULEB (begin
, start
, end
);
7149 begin
= fetch_indexed_addr (begin
, address_size
);
7150 READ_ULEB (finish
, start
, end
);
7154 case DW_LLE_offset_pair
:
7155 READ_ULEB (begin
, start
, end
);
7156 begin
+= base_address
;
7157 READ_ULEB (finish
, start
, end
);
7158 finish
+= base_address
;
7161 case DW_LLE_default_location
:
7165 case DW_LLE_base_address
:
7166 SAFE_BYTE_GET_AND_INC (base_address
, start
, address_size
, end
);
7167 print_hex (base_address
, address_size
);
7168 printf (_("(base address)\n"));
7171 case DW_LLE_start_end
:
7172 SAFE_BYTE_GET_AND_INC (begin
, start
, address_size
, end
);
7173 SAFE_BYTE_GET_AND_INC (finish
, start
, address_size
, end
);
7176 case DW_LLE_start_length
:
7177 SAFE_BYTE_GET_AND_INC (begin
, start
, address_size
, end
);
7178 READ_ULEB (finish
, start
, end
);
7183 error (_("Invalid location list entry type %d\n"), lle
);
7189 warn (_("Location list starting at offset %#" PRIx64
7190 " is not terminated.\n"), off
);
7194 print_hex (begin
, address_size
);
7195 print_hex (finish
, address_size
);
7197 if (begin
== finish
)
7198 fputs (_("(start == end)"), stdout
);
7199 else if (begin
> finish
)
7200 fputs (_("(start > end)"), stdout
);
7202 /* Read the counted location descriptions. */
7203 READ_ULEB (length
, start
, end
);
7205 if (length
> (size_t) (end
- start
))
7207 warn (_("Location list starting at offset %#" PRIx64
7208 " is not terminated.\n"), off
);
7212 (void) decode_location_expression (start
, address_size
, address_size
,
7213 version
, length
, 0, section
);
7220 while (start
< end
);
7226 display_debug_loc (struct dwarf_section
*section
, void *file
)
7228 unsigned char *start
= section
->start
, *vstart
= NULL
;
7230 unsigned char *section_begin
= start
;
7231 unsigned int num_loc_list
= 0;
7232 uint64_t last_offset
= 0;
7233 uint64_t last_view
= 0;
7234 unsigned int first
= 0;
7237 int seen_first_offset
= 0;
7238 int locs_sorted
= 1;
7239 unsigned char *next
= start
, *vnext
= vstart
;
7240 unsigned int *array
= NULL
;
7241 const char *suffix
= strrchr (section
->name
, '.');
7242 bool is_dwo
= false;
7243 int is_loclists
= strstr (section
->name
, "debug_loclists") != NULL
;
7244 uint64_t header_size
= 0;
7246 if (suffix
&& strcmp (suffix
, ".dwo") == 0)
7249 bytes
= section
->size
;
7253 printf (_("\nThe %s section is empty.\n"), section
->name
);
7259 unsigned char *hdrptr
= section_begin
;
7261 unsigned short ll_version
;
7262 unsigned char *end
= section_begin
+ section
->size
;
7263 unsigned char address_size
, segment_selector_size
;
7264 uint32_t offset_entry_count
;
7266 SAFE_BYTE_GET_AND_INC (ll_length
, hdrptr
, 4, end
);
7267 if (ll_length
== 0xffffffff)
7268 SAFE_BYTE_GET_AND_INC (ll_length
, hdrptr
, 8, end
);
7270 SAFE_BYTE_GET_AND_INC (ll_version
, hdrptr
, 2, end
);
7271 if (ll_version
!= 5)
7273 warn (_("The %s section contains corrupt or "
7274 "unsupported version number: %d.\n"),
7275 section
->name
, ll_version
);
7279 SAFE_BYTE_GET_AND_INC (address_size
, hdrptr
, 1, end
);
7281 SAFE_BYTE_GET_AND_INC (segment_selector_size
, hdrptr
, 1, end
);
7282 if (segment_selector_size
!= 0)
7284 warn (_("The %s section contains "
7285 "unsupported segment selector size: %d.\n"),
7286 section
->name
, segment_selector_size
);
7290 SAFE_BYTE_GET_AND_INC (offset_entry_count
, hdrptr
, 4, end
);
7292 if (offset_entry_count
!= 0)
7293 return display_offset_entry_loclists (section
);
7295 header_size
= hdrptr
- section_begin
;
7298 if (load_debug_info (file
) == 0)
7300 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
7305 /* Check the order of location list in .debug_info section. If
7306 offsets of location lists are in the ascending order, we can
7307 use `debug_information' directly. */
7308 for (i
= 0; i
< num_debug_info_entries
; i
++)
7312 num
= debug_information
[i
].num_loc_offsets
;
7313 if (num
> num_loc_list
)
7316 /* Check if we can use `debug_information' directly. */
7317 if (locs_sorted
&& num
!= 0)
7319 if (!seen_first_offset
)
7321 /* This is the first location list. */
7322 last_offset
= debug_information
[i
].loc_offsets
[0];
7323 last_view
= debug_information
[i
].loc_views
[0];
7325 seen_first_offset
= 1;
7331 for (; j
< num
; j
++)
7334 debug_information
[i
].loc_offsets
[j
]
7335 || (last_offset
== debug_information
[i
].loc_offsets
[j
]
7336 && last_view
> debug_information
[i
].loc_views
[j
]))
7341 last_offset
= debug_information
[i
].loc_offsets
[j
];
7342 last_view
= debug_information
[i
].loc_views
[j
];
7347 if (!seen_first_offset
)
7348 error (_("No location lists in .debug_info section!\n"));
7350 if (debug_information
[first
].num_loc_offsets
> 0
7351 && debug_information
[first
].loc_offsets
[0] != header_size
7352 && debug_information
[first
].loc_views
[0] != header_size
)
7353 warn (_("Location lists in %s section start at %#" PRIx64
7354 " rather than %#" PRIx64
"\n"),
7355 section
->name
, debug_information
[first
].loc_offsets
[0],
7359 array
= (unsigned int *) xcmalloc (num_loc_list
, sizeof (unsigned int));
7361 introduce (section
, false);
7363 if (reloc_at (section
, 0))
7364 printf (_(" Warning: This section has relocations - addresses seen here may not be accurate.\n\n"));
7366 printf (_(" Offset Begin End Expression\n"));
7368 for (i
= first
; i
< num_debug_info_entries
; i
++)
7370 uint64_t offset
= 0, voffset
= 0;
7371 uint64_t base_address
;
7377 for (k
= 0; k
< debug_information
[i
].num_loc_offsets
; k
++)
7379 loc_offsets
= debug_information
[i
].loc_offsets
;
7380 loc_views
= debug_information
[i
].loc_views
;
7381 qsort (array
, debug_information
[i
].num_loc_offsets
,
7382 sizeof (*array
), loc_offsets_compar
);
7385 /* .debug_loclists has a per-unit header.
7386 Update start if we are detecting it. */
7387 if (debug_information
[i
].dwarf_version
== 5)
7389 j
= locs_sorted
? 0 : array
[0];
7391 if (debug_information
[i
].num_loc_offsets
)
7392 offset
= debug_information
[i
].loc_offsets
[j
];
7394 if (debug_information
[i
].num_loc_views
)
7395 voffset
= debug_information
[i
].loc_views
[j
];
7397 /* Assume that the size of the header is constant across CUs. */
7398 if (((start
- section_begin
) + header_size
== offset
)
7399 || ((start
-section_begin
) + header_size
== voffset
))
7400 start
+= header_size
;
7403 int adjacent_view_loclists
= 1;
7404 for (k
= 0; k
< debug_information
[i
].num_loc_offsets
; k
++)
7406 j
= locs_sorted
? k
: array
[k
];
7408 && (debug_information
[i
].loc_offsets
[locs_sorted
7409 ? k
- 1 : array
[k
- 1]]
7410 == debug_information
[i
].loc_offsets
[j
])
7411 && (debug_information
[i
].loc_views
[locs_sorted
7412 ? k
- 1 : array
[k
- 1]]
7413 == debug_information
[i
].loc_views
[j
]))
7415 has_frame_base
= debug_information
[i
].have_frame_base
[j
];
7416 offset
= debug_information
[i
].loc_offsets
[j
];
7417 next
= section_begin
+ offset
;
7418 voffset
= debug_information
[i
].loc_views
[j
];
7419 if (voffset
!= (uint64_t) -1)
7420 vnext
= section_begin
+ voffset
;
7423 base_address
= debug_information
[i
].base_address
;
7425 if (vnext
&& vnext
< next
)
7428 display_view_pair_list (section
, &vstart
, i
, next
);
7435 if (vnext
&& vnext
< next
)
7436 warn (_("There is a hole [%#tx - %#" PRIx64
"]"
7437 " in %s section.\n"),
7438 start
- section_begin
, voffset
, section
->name
);
7440 warn (_("There is a hole [%#tx - %#" PRIx64
"]"
7441 " in %s section.\n"),
7442 start
- section_begin
, offset
, section
->name
);
7444 else if (start
> next
)
7445 warn (_("There is an overlap [%#tx - %#" PRIx64
"]"
7446 " in %s section.\n"),
7447 start
- section_begin
, offset
, section
->name
);
7451 if (offset
>= bytes
)
7453 warn (_("Offset %#" PRIx64
" is bigger than %s section size.\n"),
7454 offset
, section
->name
);
7458 if (vnext
&& voffset
>= bytes
)
7460 warn (_("View Offset %#" PRIx64
" is bigger than %s section size.\n"),
7461 voffset
, section
->name
);
7468 display_loc_list_dwo (section
, &start
, i
, offset
,
7469 &vstart
, has_frame_base
);
7471 display_loc_list (section
, &start
, i
, offset
, base_address
,
7472 &vstart
, has_frame_base
);
7477 warn (_("DWO is not yet supported.\n"));
7479 display_loclists_list (section
, &start
, i
, offset
, base_address
,
7480 &vstart
, has_frame_base
);
7483 /* FIXME: this arrangement is quite simplistic. Nothing
7484 requires locview lists to be adjacent to corresponding
7485 loclists, and a single loclist could be augmented by
7486 different locview lists, and vice-versa, unlikely as it
7487 is that it would make sense to do so. Hopefully we'll
7488 have view pair support built into loclists before we ever
7489 need to address all these possibilities. */
7490 if (adjacent_view_loclists
&& vnext
7491 && vnext
!= start
&& vstart
!= next
)
7493 adjacent_view_loclists
= 0;
7494 warn (_("Hole and overlap detection requires adjacent view lists and loclists.\n"));
7497 if (vnext
&& vnext
== start
)
7498 display_view_pair_list (section
, &start
, i
, vstart
);
7502 if (start
< section
->start
+ section
->size
)
7503 warn (ngettext ("There is %ld unused byte at the end of section %s\n",
7504 "There are %ld unused bytes at the end of section %s\n",
7505 (long) (section
->start
+ section
->size
- start
)),
7506 (long) (section
->start
+ section
->size
- start
), section
->name
);
7513 display_debug_str (struct dwarf_section
*section
,
7514 void *file ATTRIBUTE_UNUSED
)
7516 unsigned char *start
= section
->start
;
7517 uint64_t bytes
= section
->size
;
7518 uint64_t addr
= section
->address
;
7522 printf (_("\nThe %s section is empty.\n"), section
->name
);
7526 introduce (section
, false);
7534 lbytes
= (bytes
> 16 ? 16 : bytes
);
7536 printf (" 0x%8.8" PRIx64
" ", addr
);
7538 for (j
= 0; j
< 16; j
++)
7541 printf ("%2.2x", start
[j
]);
7549 for (j
= 0; j
< lbytes
; j
++)
7552 if (k
>= ' ' && k
< 0x80)
7571 display_debug_info (struct dwarf_section
*section
, void *file
)
7573 return process_debug_info (section
, file
, section
->abbrev_sec
, false, false);
7577 display_debug_types (struct dwarf_section
*section
, void *file
)
7579 return process_debug_info (section
, file
, section
->abbrev_sec
, false, true);
7583 display_trace_info (struct dwarf_section
*section
, void *file
)
7585 return process_debug_info (section
, file
, section
->abbrev_sec
, false, true);
7589 display_debug_aranges (struct dwarf_section
*section
,
7590 void *file ATTRIBUTE_UNUSED
)
7592 unsigned char *start
= section
->start
;
7593 unsigned char *end
= start
+ section
->size
;
7595 introduce (section
, false);
7597 /* It does not matter if this load fails,
7598 we test for that later on. */
7599 load_debug_info (file
);
7603 unsigned char *hdrptr
;
7604 DWARF2_Internal_ARange arange
;
7605 unsigned char *addr_ranges
;
7609 unsigned char address_size
;
7610 unsigned int offset_size
;
7611 unsigned char *end_ranges
;
7614 sec_off
= hdrptr
- section
->start
;
7616 SAFE_BYTE_GET_AND_INC (arange
.ar_length
, hdrptr
, 4, end
);
7617 if (arange
.ar_length
== 0xffffffff)
7619 SAFE_BYTE_GET_AND_INC (arange
.ar_length
, hdrptr
, 8, end
);
7625 if (arange
.ar_length
> (size_t) (end
- hdrptr
))
7627 warn (_("Debug info is corrupted, %s header at %#" PRIx64
7628 " has length %#" PRIx64
"\n"),
7629 section
->name
, sec_off
, arange
.ar_length
);
7632 end_ranges
= hdrptr
+ arange
.ar_length
;
7634 SAFE_BYTE_GET_AND_INC (arange
.ar_version
, hdrptr
, 2, end_ranges
);
7635 SAFE_BYTE_GET_AND_INC (arange
.ar_info_offset
, hdrptr
, offset_size
,
7638 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
7639 && num_debug_info_entries
> 0
7640 && find_debug_info_for_offset (arange
.ar_info_offset
) == NULL
)
7641 warn (_(".debug_info offset of %#" PRIx64
7642 " in %s section does not point to a CU header.\n"),
7643 arange
.ar_info_offset
, section
->name
);
7645 SAFE_BYTE_GET_AND_INC (arange
.ar_pointer_size
, hdrptr
, 1, end_ranges
);
7646 SAFE_BYTE_GET_AND_INC (arange
.ar_segment_size
, hdrptr
, 1, end_ranges
);
7648 if (arange
.ar_version
!= 2 && arange
.ar_version
!= 3)
7650 /* PR 19872: A version number of 0 probably means that there is
7651 padding at the end of the .debug_aranges section. Gold puts
7652 it there when performing an incremental link, for example.
7653 So do not generate a warning in this case. */
7654 if (arange
.ar_version
)
7655 warn (_("Only DWARF 2 and 3 aranges are currently supported.\n"));
7659 printf (_(" Length: %" PRId64
"\n"), arange
.ar_length
);
7660 printf (_(" Version: %d\n"), arange
.ar_version
);
7661 printf (_(" Offset into .debug_info: %#" PRIx64
"\n"),
7662 arange
.ar_info_offset
);
7663 printf (_(" Pointer Size: %d\n"), arange
.ar_pointer_size
);
7664 printf (_(" Segment Size: %d\n"), arange
.ar_segment_size
);
7666 address_size
= arange
.ar_pointer_size
+ arange
.ar_segment_size
;
7668 /* PR 17512: file: 001-108546-0.001:0.1. */
7669 if (address_size
== 0 || address_size
> 8)
7671 error (_("Invalid address size in %s section!\n"),
7676 /* The DWARF spec does not require that the address size be a power
7677 of two, but we do. This will have to change if we ever encounter
7678 an uneven architecture. */
7679 if ((address_size
& (address_size
- 1)) != 0)
7681 warn (_("Pointer size + Segment size is not a power of two.\n"));
7685 if (address_size
> 4)
7686 printf (_("\n Address Length\n"));
7688 printf (_("\n Address Length\n"));
7690 addr_ranges
= hdrptr
;
7692 /* Must pad to an alignment boundary that is twice the address size. */
7693 addr_ranges
+= (2 * address_size
- 1
7694 - (hdrptr
- start
- 1) % (2 * address_size
));
7696 while (2 * address_size
<= end_ranges
- addr_ranges
)
7698 SAFE_BYTE_GET_AND_INC (address
, addr_ranges
, address_size
,
7700 SAFE_BYTE_GET_AND_INC (length
, addr_ranges
, address_size
,
7703 print_hex (address
, address_size
);
7704 print_hex_ns (length
, address_size
);
7716 /* Comparison function for qsort. */
7718 comp_addr_base (const void * v0
, const void * v1
)
7720 debug_info
*info0
= *(debug_info
**) v0
;
7721 debug_info
*info1
= *(debug_info
**) v1
;
7722 return info0
->addr_base
- info1
->addr_base
;
7725 /* Display the debug_addr section. */
7727 display_debug_addr (struct dwarf_section
*section
,
7730 debug_info
**debug_addr_info
;
7731 unsigned char *entry
;
7735 unsigned char * header
;
7737 if (section
->size
== 0)
7739 printf (_("\nThe %s section is empty.\n"), section
->name
);
7743 if (load_debug_info (file
) == 0)
7745 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
7750 introduce (section
, false);
7752 /* PR 17531: file: cf38d01b.
7753 We use xcalloc because a corrupt file may not have initialised all of the
7754 fields in the debug_info structure, which means that the sort below might
7755 try to move uninitialised data. */
7756 debug_addr_info
= (debug_info
**) xcalloc ((num_debug_info_entries
+ 1),
7757 sizeof (debug_info
*));
7760 for (i
= 0; i
< num_debug_info_entries
; i
++)
7761 if (debug_information
[i
].addr_base
!= DEBUG_INFO_UNAVAILABLE
)
7763 /* PR 17531: file: cf38d01b. */
7764 if (debug_information
[i
].addr_base
>= section
->size
)
7765 warn (_("Corrupt address base (%#" PRIx64
")"
7766 " found in debug section %u\n"),
7767 debug_information
[i
].addr_base
, i
);
7769 debug_addr_info
[count
++] = debug_information
+ i
;
7772 /* Add a sentinel to make iteration convenient. */
7773 debug_addr_info
[count
] = (debug_info
*) xmalloc (sizeof (debug_info
));
7774 debug_addr_info
[count
]->addr_base
= section
->size
;
7775 qsort (debug_addr_info
, count
, sizeof (debug_info
*), comp_addr_base
);
7777 header
= section
->start
;
7778 for (i
= 0; i
< count
; i
++)
7781 unsigned int address_size
= debug_addr_info
[i
]->pointer_size
;
7783 printf (_(" For compilation unit at offset %#" PRIx64
":\n"),
7784 debug_addr_info
[i
]->cu_offset
);
7786 printf (_("\tIndex\tAddress\n"));
7787 entry
= section
->start
+ debug_addr_info
[i
]->addr_base
;
7788 if (debug_addr_info
[i
]->dwarf_version
>= 5)
7790 size_t header_size
= entry
- header
;
7791 unsigned char *curr_header
= header
;
7794 int segment_selector_size
;
7796 if (header_size
!= 8 && header_size
!= 16)
7798 warn (_("Corrupt %s section: expecting header size of 8 or 16, but found %zd instead\n"),
7799 section
->name
, header_size
);
7803 SAFE_BYTE_GET_AND_INC (length
, curr_header
, 4, entry
);
7804 if (length
== 0xffffffff)
7805 SAFE_BYTE_GET_AND_INC (length
, curr_header
, 8, entry
);
7806 if (length
> (size_t) (section
->start
+ section
->size
- curr_header
)
7807 || length
< (size_t) (entry
- curr_header
))
7809 warn (_("Corrupt %s section: unit_length field of %#" PRIx64
7810 " is invalid\n"), section
->name
, length
);
7813 end
= curr_header
+ length
;
7814 SAFE_BYTE_GET_AND_INC (version
, curr_header
, 2, entry
);
7816 warn (_("Corrupt %s section: expecting version number 5 in header but found %d instead\n"),
7817 section
->name
, version
);
7819 SAFE_BYTE_GET_AND_INC (address_size
, curr_header
, 1, entry
);
7820 SAFE_BYTE_GET_AND_INC (segment_selector_size
, curr_header
, 1, entry
);
7821 address_size
+= segment_selector_size
;
7824 end
= section
->start
+ debug_addr_info
[i
+ 1]->addr_base
;
7829 if (address_size
< 1 || address_size
> sizeof (uint64_t))
7831 warn (_("Corrupt %s section: address size (%x) is wrong"),
7832 section
->name
, address_size
);
7836 while ((size_t) (end
- entry
) >= address_size
)
7838 uint64_t base
= byte_get (entry
, address_size
);
7839 printf (_("\t%d:\t"), idx
);
7840 print_hex_ns (base
, address_size
);
7842 entry
+= address_size
;
7848 free (debug_addr_info
);
7852 /* Display the .debug_str_offsets and .debug_str_offsets.dwo sections. */
7855 display_debug_str_offsets (struct dwarf_section
*section
,
7856 void *file ATTRIBUTE_UNUSED
)
7860 if (section
->size
== 0)
7862 printf (_("\nThe %s section is empty.\n"), section
->name
);
7866 unsigned char *start
= section
->start
;
7867 unsigned char *end
= start
+ section
->size
;
7868 unsigned char *curr
= start
;
7869 uint64_t debug_str_offsets_hdr_len
;
7871 const char *suffix
= strrchr (section
->name
, '.');
7872 bool dwo
= suffix
&& strcmp (suffix
, ".dwo") == 0;
7875 load_debug_section_with_follow (str_dwo
, file
);
7877 load_debug_section_with_follow (str
, file
);
7879 introduce (section
, false);
7884 uint64_t entry_length
;
7886 SAFE_BYTE_GET_AND_INC (length
, curr
, 4, end
);
7887 /* FIXME: We assume that this means 64-bit DWARF is being used. */
7888 if (length
== 0xffffffff)
7890 SAFE_BYTE_GET_AND_INC (length
, curr
, 8, end
);
7892 debug_str_offsets_hdr_len
= 16;
7897 debug_str_offsets_hdr_len
= 8;
7900 unsigned char *entries_end
;
7903 /* This is probably an old style .debug_str_offset section which
7904 just contains offsets and no header (and the first offset is 0). */
7905 length
= section
->size
;
7906 curr
= section
->start
;
7909 printf (_(" Length: %#" PRIx64
"\n"), length
);
7910 printf (_(" Index Offset [String]\n"));
7914 if (length
<= (size_t) (end
- curr
))
7915 entries_end
= curr
+ length
;
7918 warn (_("Section %s is too small %#" PRIx64
"\n"),
7919 section
->name
, section
->size
);
7924 SAFE_BYTE_GET_AND_INC (version
, curr
, 2, entries_end
);
7926 warn (_("Unexpected version number in str_offset header: %#x\n"), version
);
7929 SAFE_BYTE_GET_AND_INC (padding
, curr
, 2, entries_end
);
7931 warn (_("Unexpected value in str_offset header's padding field: %#x\n"), padding
);
7933 printf (_(" Length: %#" PRIx64
"\n"), length
);
7934 printf (_(" Version: %#x\n"), version
);
7935 printf (_(" Index Offset [String]\n"));
7938 for (idx
= 0; curr
< entries_end
; idx
++)
7941 const unsigned char * string
;
7943 if ((size_t) (entries_end
- curr
) < entry_length
)
7944 /* Not enough space to read one entry_length, give up. */
7947 SAFE_BYTE_GET_AND_INC (offset
, curr
, entry_length
, entries_end
);
7949 string
= (const unsigned char *)
7950 fetch_indexed_string (idx
, NULL
, entry_length
, dwo
, debug_str_offsets_hdr_len
);
7952 string
= fetch_indirect_string (offset
);
7954 printf (" %8lu ", idx
);
7955 print_hex (offset
, entry_length
);
7956 printf (" %s\n", string
);
7963 /* Each debug_information[x].range_lists[y] gets this representation for
7964 sorting purposes. */
7968 /* The debug_information[x].range_lists[y] value. */
7969 uint64_t ranges_offset
;
7971 /* Original debug_information to find parameters of the data. */
7972 debug_info
*debug_info_p
;
7975 /* Sort struct range_entry in ascending order of its RANGES_OFFSET. */
7978 range_entry_compar (const void *ap
, const void *bp
)
7980 const struct range_entry
*a_re
= (const struct range_entry
*) ap
;
7981 const struct range_entry
*b_re
= (const struct range_entry
*) bp
;
7982 const uint64_t a
= a_re
->ranges_offset
;
7983 const uint64_t b
= b_re
->ranges_offset
;
7985 return (a
> b
) - (b
> a
);
7989 display_debug_ranges_list (unsigned char * start
,
7990 unsigned char * finish
,
7991 unsigned int pointer_size
,
7993 uint64_t base_address
)
7995 while (start
< finish
)
8000 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
8001 if (start
>= finish
)
8003 SAFE_SIGNED_BYTE_GET_AND_INC (end
, start
, pointer_size
, finish
);
8006 print_hex (offset
, 4);
8008 if (begin
== 0 && end
== 0)
8010 printf (_("<End of list>\n"));
8014 /* Check base address specifiers. */
8015 if (is_max_address (begin
, pointer_size
)
8016 && !is_max_address (end
, pointer_size
))
8019 print_hex (begin
, pointer_size
);
8020 print_hex (end
, pointer_size
);
8021 printf ("(base address)\n");
8025 print_hex (begin
+ base_address
, pointer_size
);
8026 print_hex_ns (end
+ base_address
, pointer_size
);
8029 fputs (_(" (start == end)"), stdout
);
8030 else if (begin
> end
)
8031 fputs (_(" (start > end)"), stdout
);
8037 static unsigned char *
8038 display_debug_rnglists_list (unsigned char * start
,
8039 unsigned char * finish
,
8040 unsigned int pointer_size
,
8042 uint64_t base_address
,
8043 unsigned int offset_size
)
8045 unsigned char *next
= start
;
8046 unsigned int debug_addr_section_hdr_len
;
8048 if (offset_size
== 4)
8049 debug_addr_section_hdr_len
= 8;
8051 debug_addr_section_hdr_len
= 16;
8055 uint64_t off
= offset
+ (start
- next
);
8056 enum dwarf_range_list_entry rlet
;
8057 /* Initialize it due to a false compiler warning. */
8058 uint64_t begin
= -1, length
, end
= -1;
8060 if (start
>= finish
)
8062 warn (_("Range list starting at offset %#" PRIx64
8063 " is not terminated.\n"), offset
);
8070 SAFE_BYTE_GET_AND_INC (rlet
, start
, 1, finish
);
8074 case DW_RLE_end_of_list
:
8075 printf (_("<End of list>\n"));
8077 case DW_RLE_base_addressx
:
8078 READ_ULEB (base_address
, start
, finish
);
8079 print_hex (base_address
, pointer_size
);
8080 printf (_("(base address index) "));
8081 base_address
= fetch_indexed_addr ((base_address
* pointer_size
)
8082 + debug_addr_section_hdr_len
, pointer_size
);
8083 print_hex (base_address
, pointer_size
);
8084 printf (_("(base address)\n"));
8086 case DW_RLE_startx_endx
:
8087 READ_ULEB (begin
, start
, finish
);
8088 READ_ULEB (end
, start
, finish
);
8089 begin
= fetch_indexed_addr ((begin
* pointer_size
)
8090 + debug_addr_section_hdr_len
, pointer_size
);
8091 end
= fetch_indexed_addr ((begin
* pointer_size
)
8092 + debug_addr_section_hdr_len
, pointer_size
);
8094 case DW_RLE_startx_length
:
8095 READ_ULEB (begin
, start
, finish
);
8096 READ_ULEB (length
, start
, finish
);
8097 begin
= fetch_indexed_addr ((begin
* pointer_size
)
8098 + debug_addr_section_hdr_len
, pointer_size
);
8099 end
= begin
+ length
;
8101 case DW_RLE_offset_pair
:
8102 READ_ULEB (begin
, start
, finish
);
8103 READ_ULEB (end
, start
, finish
);
8105 case DW_RLE_base_address
:
8106 SAFE_BYTE_GET_AND_INC (base_address
, start
, pointer_size
, finish
);
8107 print_hex (base_address
, pointer_size
);
8108 printf (_("(base address)\n"));
8110 case DW_RLE_start_end
:
8111 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
8112 SAFE_BYTE_GET_AND_INC (end
, start
, pointer_size
, finish
);
8114 case DW_RLE_start_length
:
8115 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
8116 READ_ULEB (length
, start
, finish
);
8117 end
= begin
+ length
;
8120 error (_("Invalid range list entry type %d\n"), rlet
);
8121 rlet
= DW_RLE_end_of_list
;
8125 if (rlet
== DW_RLE_end_of_list
)
8127 if (rlet
== DW_RLE_base_address
|| rlet
== DW_RLE_base_addressx
)
8130 /* Only a DW_RLE_offset_pair needs the base address added. */
8131 if (rlet
== DW_RLE_offset_pair
)
8133 begin
+= base_address
;
8134 end
+= base_address
;
8137 print_hex (begin
, pointer_size
);
8138 print_hex (end
, pointer_size
);
8141 fputs (_(" (start == end)"), stdout
);
8142 else if (begin
> end
)
8143 fputs (_(" (start > end)"), stdout
);
8152 display_debug_rnglists (struct dwarf_section
*section
)
8154 unsigned char *start
= section
->start
;
8155 unsigned char *finish
= start
+ section
->size
;
8157 while (start
< finish
)
8159 unsigned char *table_start
;
8160 uint64_t offset
= start
- section
->start
;
8162 uint64_t initial_length
;
8163 unsigned char segment_selector_size
;
8164 unsigned int offset_entry_count
;
8166 unsigned short version
;
8167 unsigned char address_size
= 0;
8168 unsigned char offset_size
;
8170 /* Get and check the length of the block. */
8171 SAFE_BYTE_GET_AND_INC (initial_length
, start
, 4, finish
);
8173 if (initial_length
== 0xffffffff)
8175 /* This section is 64-bit DWARF 3. */
8176 SAFE_BYTE_GET_AND_INC (initial_length
, start
, 8, finish
);
8182 if (initial_length
> (size_t) (finish
- start
))
8184 /* If the length field has a relocation against it, then we should
8185 not complain if it is inaccurate (and probably negative).
8186 It is copied from .debug_line handling code. */
8187 if (reloc_at (section
, (start
- section
->start
) - offset_size
))
8188 initial_length
= finish
- start
;
8191 warn (_("The length field (%#" PRIx64
8192 ") in the debug_rnglists header is wrong"
8193 " - the section is too small\n"),
8199 end
= start
+ initial_length
;
8201 /* Get the other fields in the header. */
8202 SAFE_BYTE_GET_AND_INC (version
, start
, 2, finish
);
8203 SAFE_BYTE_GET_AND_INC (address_size
, start
, 1, finish
);
8204 SAFE_BYTE_GET_AND_INC (segment_selector_size
, start
, 1, finish
);
8205 SAFE_BYTE_GET_AND_INC (offset_entry_count
, start
, 4, finish
);
8207 printf (_(" Table at Offset: %#" PRIx64
":\n"), offset
);
8208 printf (_(" Length: %#" PRIx64
"\n"), initial_length
);
8209 printf (_(" DWARF version: %u\n"), version
);
8210 printf (_(" Address size: %u\n"), address_size
);
8211 printf (_(" Segment size: %u\n"), segment_selector_size
);
8212 printf (_(" Offset entries: %u\n"), offset_entry_count
);
8214 /* Check the fields. */
8215 if (segment_selector_size
!= 0)
8217 warn (_("The %s section contains "
8218 "unsupported segment selector size: %d.\n"),
8219 section
->name
, segment_selector_size
);
8225 warn (_("Only DWARF version 5+ debug_rnglists info "
8226 "is currently supported.\n"));
8230 table_start
= start
;
8232 if (offset_entry_count
!= 0)
8234 printf (_("\n Offsets starting at %#tx:\n"),
8235 start
- section
->start
);
8237 for (i
= 0; i
< offset_entry_count
; i
++)
8241 SAFE_BYTE_GET_AND_INC (entry
, start
, offset_size
, finish
);
8242 printf (_(" [%6u] %#" PRIx64
"\n"), i
, entry
);
8246 offset_entry_count
= 1;
8248 for (i
= 0; i
< offset_entry_count
; i
++)
8250 uint64_t indx
= start
- table_start
;
8252 offset
= start
- section
->start
;
8253 printf (_("\n Offset: %#" PRIx64
", Index: %#" PRIx64
"\n"),
8255 printf (_(" Offset Begin End\n"));
8256 start
= display_debug_rnglists_list
8257 (start
, end
, address_size
, offset
, 0, offset_size
);
8273 is_range_list_for_this_section (bool is_rnglists
, unsigned int version
)
8275 if (is_rnglists
&& version
> 4)
8278 if (! is_rnglists
&& version
< 5)
8285 display_debug_ranges (struct dwarf_section
*section
,
8286 void *file ATTRIBUTE_UNUSED
)
8288 unsigned char *start
= section
->start
;
8289 unsigned char *last_start
= start
;
8290 uint64_t bytes
= section
->size
;
8291 unsigned char *section_begin
= start
;
8292 unsigned char *finish
= start
+ bytes
;
8293 unsigned int num_range_list
, i
;
8294 struct range_entry
*range_entries
;
8295 struct range_entry
*range_entry_fill
;
8296 bool is_rnglists
= strstr (section
->name
, "debug_rnglists") != NULL
;
8297 /* Initialize it due to a false compiler warning. */
8298 unsigned char address_size
= 0;
8299 uint64_t last_offset
= 0;
8303 printf (_("\nThe %s section is empty.\n"), section
->name
);
8307 introduce (section
, false);
8310 return display_debug_rnglists (section
);
8312 if (load_debug_info (file
) == 0)
8314 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
8320 for (i
= 0; i
< num_debug_info_entries
; i
++)
8321 num_range_list
+= debug_information
[i
].num_range_lists
;
8323 if (num_range_list
== 0)
8325 /* This can happen when the file was compiled with -gsplit-debug
8326 which removes references to range lists from the primary .o file. */
8327 printf (_("No range lists referenced by .debug_info section.\n"));
8331 range_entries
= (struct range_entry
*)
8332 xmalloc (sizeof (*range_entries
) * num_range_list
);
8333 range_entry_fill
= range_entries
;
8335 for (i
= 0; i
< num_debug_info_entries
; i
++)
8337 debug_info
*debug_info_p
= &debug_information
[i
];
8340 for (j
= 0; j
< debug_info_p
->num_range_lists
; j
++)
8342 if (is_range_list_for_this_section (is_rnglists
, debug_info_p
->range_versions
[j
]))
8344 range_entry_fill
->ranges_offset
= debug_info_p
->range_lists
[j
];
8345 range_entry_fill
->debug_info_p
= debug_info_p
;
8351 num_range_list
= range_entry_fill
- range_entries
;
8352 qsort (range_entries
, num_range_list
, sizeof (*range_entries
),
8353 range_entry_compar
);
8355 if (dwarf_check
!= 0 && range_entries
[0].ranges_offset
!= 0)
8356 warn (_("Range lists in %s section start at %#" PRIx64
"\n"),
8357 section
->name
, range_entries
[0].ranges_offset
);
8360 printf (_(" Offset Begin End\n"));
8362 for (i
= 0; i
< num_range_list
; i
++)
8364 struct range_entry
*range_entry
= &range_entries
[i
];
8365 debug_info
*debug_info_p
= range_entry
->debug_info_p
;
8366 unsigned int pointer_size
;
8368 unsigned char *next
;
8369 uint64_t base_address
;
8371 pointer_size
= (is_rnglists
? address_size
: debug_info_p
->pointer_size
);
8372 offset
= range_entry
->ranges_offset
;
8373 base_address
= debug_info_p
->base_address
;
8375 /* PR 17512: file: 001-101485-0.001:0.1. */
8376 if (pointer_size
< 2 || pointer_size
> 8)
8378 warn (_("Corrupt pointer size (%d) in debug entry at offset %#" PRIx64
"\n"),
8379 pointer_size
, offset
);
8383 if (offset
> (size_t) (finish
- section_begin
))
8385 warn (_("Corrupt offset (%#" PRIx64
") in range entry %u\n"),
8390 next
= section_begin
+ offset
+ debug_info_p
->rnglists_base
;
8392 /* If multiple DWARF entities reference the same range then we will
8393 have multiple entries in the `range_entries' list for the same
8394 offset. Thanks to the sort above these will all be consecutive in
8395 the `range_entries' list, so we can easily ignore duplicates
8397 if (i
> 0 && last_offset
== offset
)
8399 last_offset
= offset
;
8401 if (dwarf_check
!= 0 && i
> 0)
8404 warn (_("There is a hole [%#tx - %#tx] in %s section.\n"),
8405 start
- section_begin
, next
- section_begin
, section
->name
);
8406 else if (start
> next
)
8408 if (next
== last_start
)
8410 warn (_("There is an overlap [%#tx - %#tx] in %s section.\n"),
8411 start
- section_begin
, next
- section_begin
, section
->name
);
8418 display_debug_ranges_list
8419 (start
, finish
, pointer_size
, offset
, base_address
);
8423 free (range_entries
);
8428 typedef struct Frame_Chunk
8430 struct Frame_Chunk
*next
;
8431 unsigned char *chunk_start
;
8433 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
8434 short int *col_type
;
8435 int64_t *col_offset
;
8437 unsigned int code_factor
;
8441 unsigned int cfa_reg
;
8442 uint64_t cfa_offset
;
8444 unsigned char fde_encoding
;
8445 unsigned char cfa_exp
;
8446 unsigned char ptr_size
;
8447 unsigned char segment_size
;
8451 typedef const char *(*dwarf_regname_lookup_ftype
) (unsigned int);
8452 static dwarf_regname_lookup_ftype dwarf_regnames_lookup_func
;
8453 static const char *const *dwarf_regnames
;
8454 static unsigned int dwarf_regnames_count
;
8455 static bool is_aarch64
;
8457 /* A marker for a col_type that means this column was never referenced
8458 in the frame info. */
8459 #define DW_CFA_unreferenced (-1)
8461 /* Return 0 if no more space is needed, 1 if more space is needed,
8462 -1 for invalid reg. */
8465 frame_need_space (Frame_Chunk
*fc
, unsigned int reg
)
8467 unsigned int prev
= fc
->ncols
;
8469 if (reg
< (unsigned int) fc
->ncols
)
8472 if (dwarf_regnames_count
> 0
8473 && reg
> dwarf_regnames_count
)
8476 fc
->ncols
= reg
+ 1;
8477 /* PR 17512: file: 10450-2643-0.004.
8478 If reg == -1 then this can happen... */
8482 /* PR 17512: file: 2844a11d. */
8483 if (fc
->ncols
> 1024 && dwarf_regnames_count
== 0)
8485 error (_("Unfeasibly large register number: %u\n"), reg
);
8487 /* FIXME: 1024 is an arbitrary limit. Increase it if
8488 we ever encounter a valid binary that exceeds it. */
8492 fc
->col_type
= xcrealloc (fc
->col_type
, fc
->ncols
,
8493 sizeof (*fc
->col_type
));
8494 fc
->col_offset
= xcrealloc (fc
->col_offset
, fc
->ncols
,
8495 sizeof (*fc
->col_offset
));
8496 /* PR 17512: file:002-10025-0.005. */
8497 if (fc
->col_type
== NULL
|| fc
->col_offset
== NULL
)
8499 error (_("Out of memory allocating %u columns in dwarf frame arrays\n"),
8505 while (prev
< fc
->ncols
)
8507 fc
->col_type
[prev
] = DW_CFA_unreferenced
;
8508 fc
->col_offset
[prev
] = 0;
8514 static const char *const dwarf_regnames_i386
[] =
8516 "eax", "ecx", "edx", "ebx", /* 0 - 3 */
8517 "esp", "ebp", "esi", "edi", /* 4 - 7 */
8518 "eip", "eflags", NULL
, /* 8 - 10 */
8519 "st0", "st1", "st2", "st3", /* 11 - 14 */
8520 "st4", "st5", "st6", "st7", /* 15 - 18 */
8521 NULL
, NULL
, /* 19 - 20 */
8522 "xmm0", "xmm1", "xmm2", "xmm3", /* 21 - 24 */
8523 "xmm4", "xmm5", "xmm6", "xmm7", /* 25 - 28 */
8524 "mm0", "mm1", "mm2", "mm3", /* 29 - 32 */
8525 "mm4", "mm5", "mm6", "mm7", /* 33 - 36 */
8526 "fcw", "fsw", "mxcsr", /* 37 - 39 */
8527 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
, /* 40 - 47 */
8528 "tr", "ldtr", /* 48 - 49 */
8529 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 50 - 57 */
8530 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 58 - 65 */
8531 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 66 - 73 */
8532 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 74 - 81 */
8533 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 82 - 89 */
8534 NULL
, NULL
, NULL
, /* 90 - 92 */
8535 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7" /* 93 - 100 */
8538 static const char *const dwarf_regnames_iamcu
[] =
8540 "eax", "ecx", "edx", "ebx", /* 0 - 3 */
8541 "esp", "ebp", "esi", "edi", /* 4 - 7 */
8542 "eip", "eflags", NULL
, /* 8 - 10 */
8543 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 11 - 18 */
8544 NULL
, NULL
, /* 19 - 20 */
8545 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 21 - 28 */
8546 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 29 - 36 */
8547 NULL
, NULL
, NULL
, /* 37 - 39 */
8548 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
, /* 40 - 47 */
8549 "tr", "ldtr", /* 48 - 49 */
8550 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 50 - 57 */
8551 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 58 - 65 */
8552 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 66 - 73 */
8553 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 74 - 81 */
8554 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 82 - 89 */
8555 NULL
, NULL
, NULL
, /* 90 - 92 */
8556 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
/* 93 - 100 */
8560 init_dwarf_regnames_i386 (void)
8562 dwarf_regnames
= dwarf_regnames_i386
;
8563 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_i386
);
8564 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8568 init_dwarf_regnames_iamcu (void)
8570 dwarf_regnames
= dwarf_regnames_iamcu
;
8571 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_iamcu
);
8572 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8575 static const char *const DW_CFA_GNU_window_save_name
[] =
8577 "DW_CFA_GNU_window_save",
8578 "DW_CFA_AARCH64_negate_ra_state"
8581 static const char *const dwarf_regnames_x86_64
[] =
8583 "rax", "rdx", "rcx", "rbx",
8584 "rsi", "rdi", "rbp", "rsp",
8585 "r8", "r9", "r10", "r11",
8586 "r12", "r13", "r14", "r15",
8588 "xmm0", "xmm1", "xmm2", "xmm3",
8589 "xmm4", "xmm5", "xmm6", "xmm7",
8590 "xmm8", "xmm9", "xmm10", "xmm11",
8591 "xmm12", "xmm13", "xmm14", "xmm15",
8592 "st0", "st1", "st2", "st3",
8593 "st4", "st5", "st6", "st7",
8594 "mm0", "mm1", "mm2", "mm3",
8595 "mm4", "mm5", "mm6", "mm7",
8597 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
,
8598 "fs.base", "gs.base", NULL
, NULL
,
8600 "mxcsr", "fcw", "fsw",
8601 "xmm16", "xmm17", "xmm18", "xmm19",
8602 "xmm20", "xmm21", "xmm22", "xmm23",
8603 "xmm24", "xmm25", "xmm26", "xmm27",
8604 "xmm28", "xmm29", "xmm30", "xmm31",
8605 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 83 - 90 */
8606 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 91 - 98 */
8607 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 99 - 106 */
8608 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 107 - 114 */
8609 NULL
, NULL
, NULL
, /* 115 - 117 */
8610 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7"
8614 init_dwarf_regnames_x86_64 (void)
8616 dwarf_regnames
= dwarf_regnames_x86_64
;
8617 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_x86_64
);
8618 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8621 static const char *const dwarf_regnames_aarch64
[] =
8623 "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7",
8624 "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15",
8625 "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23",
8626 "x24", "x25", "x26", "x27", "x28", "x29", "x30", "sp",
8627 NULL
, "elr", NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
8628 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, "vg", "ffr",
8629 "p0", "p1", "p2", "p3", "p4", "p5", "p6", "p7",
8630 "p8", "p9", "p10", "p11", "p12", "p13", "p14", "p15",
8631 "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7",
8632 "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15",
8633 "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23",
8634 "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31",
8635 "z0", "z1", "z2", "z3", "z4", "z5", "z6", "z7",
8636 "z8", "z9", "z10", "z11", "z12", "z13", "z14", "z15",
8637 "z16", "z17", "z18", "z19", "z20", "z21", "z22", "z23",
8638 "z24", "z25", "z26", "z27", "z28", "z29", "z30", "z31",
8642 init_dwarf_regnames_aarch64 (void)
8644 dwarf_regnames
= dwarf_regnames_aarch64
;
8645 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_aarch64
);
8646 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8650 static const char *const dwarf_regnames_s390
[] =
8652 /* Avoid saying "r5 (r5)", so omit the names of r0-r15. */
8653 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
8654 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
8655 "f0", "f2", "f4", "f6", "f1", "f3", "f5", "f7",
8656 "f8", "f10", "f12", "f14", "f9", "f11", "f13", "f15",
8657 "cr0", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7",
8658 "cr8", "cr9", "cr10", "cr11", "cr12", "cr13", "cr14", "cr15",
8659 "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7",
8660 "a8", "a9", "a10", "a11", "a12", "a13", "a14", "a15",
8663 "v16", "v18", "v20", "v22", "v17", "v19", "v21", "v23",
8664 "v24", "v26", "v28", "v30", "v25", "v27", "v29", "v31",
8668 init_dwarf_regnames_s390 (void)
8670 dwarf_regnames
= dwarf_regnames_s390
;
8671 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_s390
);
8672 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8675 static const char *const dwarf_regnames_riscv
[] =
8677 "zero", "ra", "sp", "gp", "tp", "t0", "t1", "t2", /* 0 - 7 */
8678 "s0", "s1", "a0", "a1", "a2", "a3", "a4", "a5", /* 8 - 15 */
8679 "a6", "a7", "s2", "s3", "s4", "s5", "s6", "s7", /* 16 - 23 */
8680 "s8", "s9", "s10", "s11", "t3", "t4", "t5", "t6", /* 24 - 31 */
8681 "ft0", "ft1", "ft2", "ft3", "ft4", "ft5", "ft6", "ft7", /* 32 - 39 */
8682 "fs0", "fs1", /* 40 - 41 */
8683 "fa0", "fa1", "fa2", "fa3", "fa4", "fa5", "fa6", "fa7", /* 42 - 49 */
8684 "fs2", "fs3", "fs4", "fs5", "fs6", "fs7", "fs8", "fs9", /* 50 - 57 */
8685 "fs10", "fs11", /* 58 - 59 */
8686 "ft8", "ft9", "ft10", "ft11", /* 60 - 63 */
8687 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 64 - 71 */
8688 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 72 - 79 */
8689 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 80 - 87 */
8690 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 88 - 95 */
8691 "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", /* 96 - 103 */
8692 "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15", /* 104 - 111 */
8693 "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23", /* 112 - 119 */
8694 "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31", /* 120 - 127 */
8697 /* A RISC-V replacement for REGNAME_INTERNAL_BY_TABLE_ONLY which handles
8698 the large number of CSRs. */
8701 regname_internal_riscv (unsigned int regno
)
8703 const char *name
= NULL
;
8705 /* Lookup in the table first, this covers GPR and FPR. */
8706 if (regno
< ARRAY_SIZE (dwarf_regnames_riscv
))
8707 name
= dwarf_regnames_riscv
[regno
];
8708 else if (regno
>= 4096 && regno
<= 8191)
8710 /* This might be a CSR, these live in a sparse number space from 4096
8711 to 8191 These numbers are defined in the RISC-V ELF ABI
8715 #define DECLARE_CSR(NAME,VALUE,CLASS,DEFINE_VER,ABORT_VER) \
8716 case VALUE + 4096: name = #NAME; break;
8717 #include "opcode/riscv-opc.h"
8722 static char csr_name
[10];
8723 snprintf (csr_name
, sizeof (csr_name
), "csr%d", (regno
- 4096));
8734 init_dwarf_regnames_riscv (void)
8736 dwarf_regnames
= NULL
;
8737 dwarf_regnames_count
= 8192;
8738 dwarf_regnames_lookup_func
= regname_internal_riscv
;
8742 init_dwarf_regnames_by_elf_machine_code (unsigned int e_machine
)
8744 dwarf_regnames_lookup_func
= NULL
;
8750 init_dwarf_regnames_i386 ();
8754 init_dwarf_regnames_iamcu ();
8760 init_dwarf_regnames_x86_64 ();
8764 init_dwarf_regnames_aarch64 ();
8768 init_dwarf_regnames_s390 ();
8772 init_dwarf_regnames_riscv ();
8780 /* Initialize the DWARF register name lookup state based on the
8781 architecture and specific machine type of a BFD. */
8784 init_dwarf_regnames_by_bfd_arch_and_mach (enum bfd_architecture arch
,
8787 dwarf_regnames_lookup_func
= NULL
;
8795 case bfd_mach_x86_64
:
8796 case bfd_mach_x86_64_intel_syntax
:
8797 case bfd_mach_x64_32
:
8798 case bfd_mach_x64_32_intel_syntax
:
8799 init_dwarf_regnames_x86_64 ();
8803 init_dwarf_regnames_i386 ();
8808 case bfd_arch_iamcu
:
8809 init_dwarf_regnames_iamcu ();
8812 case bfd_arch_aarch64
:
8813 init_dwarf_regnames_aarch64();
8817 init_dwarf_regnames_s390 ();
8820 case bfd_arch_riscv
:
8821 init_dwarf_regnames_riscv ();
8830 regname_internal_by_table_only (unsigned int regno
)
8832 if (dwarf_regnames
!= NULL
8833 && regno
< dwarf_regnames_count
8834 && dwarf_regnames
[regno
] != NULL
)
8835 return dwarf_regnames
[regno
];
8841 regname (unsigned int regno
, int name_only_p
)
8843 static char reg
[64];
8845 const char *name
= NULL
;
8847 if (dwarf_regnames_lookup_func
!= NULL
)
8848 name
= dwarf_regnames_lookup_func (regno
);
8854 snprintf (reg
, sizeof (reg
), "r%d (%s)", regno
, name
);
8857 snprintf (reg
, sizeof (reg
), "r%d", regno
);
8862 frame_display_row (Frame_Chunk
*fc
, int *need_col_headers
, unsigned int *max_regs
)
8867 if (*max_regs
!= fc
->ncols
)
8868 *max_regs
= fc
->ncols
;
8870 if (*need_col_headers
)
8872 *need_col_headers
= 0;
8874 printf ("%-*s CFA ", eh_addr_size
* 2, " LOC");
8876 for (r
= 0; r
< *max_regs
; r
++)
8877 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
8882 printf ("%-5s ", regname (r
, 1));
8888 print_hex (fc
->pc_begin
, eh_addr_size
);
8890 strcpy (tmp
, "exp");
8892 sprintf (tmp
, "%s%+d", regname (fc
->cfa_reg
, 1), (int) fc
->cfa_offset
);
8893 printf ("%-8s ", tmp
);
8895 for (r
= 0; r
< fc
->ncols
; r
++)
8897 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
8899 switch (fc
->col_type
[r
])
8901 case DW_CFA_undefined
:
8904 case DW_CFA_same_value
:
8908 sprintf (tmp
, "c%+" PRId64
, fc
->col_offset
[r
]);
8910 case DW_CFA_val_offset
:
8911 sprintf (tmp
, "v%+" PRId64
, fc
->col_offset
[r
]);
8913 case DW_CFA_register
:
8914 sprintf (tmp
, "%s", regname (fc
->col_offset
[r
], 0));
8916 case DW_CFA_expression
:
8917 strcpy (tmp
, "exp");
8919 case DW_CFA_val_expression
:
8920 strcpy (tmp
, "vexp");
8923 strcpy (tmp
, "n/a");
8926 printf ("%-5s ", tmp
);
8932 #define GET(VAR, N) SAFE_BYTE_GET_AND_INC (VAR, start, N, end)
8934 static unsigned char *
8935 read_cie (unsigned char *start
, unsigned char *end
,
8936 Frame_Chunk
**p_cie
, int *p_version
,
8937 uint64_t *p_aug_len
, unsigned char **p_aug
)
8941 unsigned char *augmentation_data
= NULL
;
8942 uint64_t augmentation_data_len
= 0;
8945 /* PR 17512: file: 001-228113-0.004. */
8949 fc
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
8950 memset (fc
, 0, sizeof (Frame_Chunk
));
8952 fc
->col_type
= xmalloc (sizeof (*fc
->col_type
));
8953 fc
->col_offset
= xmalloc (sizeof (*fc
->col_offset
));
8957 fc
->augmentation
= (char *) start
;
8958 /* PR 17512: file: 001-228113-0.004.
8959 Skip past augmentation name, but avoid running off the end of the data. */
8961 if (* start
++ == '\0')
8965 warn (_("No terminator for augmentation name\n"));
8969 if (strcmp (fc
->augmentation
, "eh") == 0)
8971 if (eh_addr_size
> (size_t) (end
- start
))
8973 start
+= eh_addr_size
;
8978 if (2 > (size_t) (end
- start
))
8980 GET (fc
->ptr_size
, 1);
8981 if (fc
->ptr_size
< 1 || fc
->ptr_size
> 8)
8983 warn (_("Invalid pointer size (%d) in CIE data\n"), fc
->ptr_size
);
8987 GET (fc
->segment_size
, 1);
8988 /* PR 17512: file: e99d2804. */
8989 if (fc
->segment_size
> 8 || fc
->segment_size
+ fc
->ptr_size
> 8)
8991 warn (_("Invalid segment size (%d) in CIE data\n"), fc
->segment_size
);
8995 eh_addr_size
= fc
->ptr_size
;
8999 fc
->ptr_size
= eh_addr_size
;
9000 fc
->segment_size
= 0;
9003 READ_ULEB (fc
->code_factor
, start
, end
);
9004 READ_SLEB (fc
->data_factor
, start
, end
);
9015 READ_ULEB (fc
->ra
, start
, end
);
9018 if (fc
->augmentation
[0] == 'z')
9022 READ_ULEB (augmentation_data_len
, start
, end
);
9023 augmentation_data
= start
;
9024 /* PR 17512: file: 11042-2589-0.004. */
9025 if (augmentation_data_len
> (size_t) (end
- start
))
9027 warn (_("Augmentation data too long: %#" PRIx64
9028 ", expected at most %#tx\n"),
9029 augmentation_data_len
, end
- start
);
9032 start
+= augmentation_data_len
;
9035 if (augmentation_data_len
)
9039 unsigned char *qend
;
9041 p
= (unsigned char *) fc
->augmentation
+ 1;
9042 q
= augmentation_data
;
9043 qend
= q
+ augmentation_data_len
;
9045 while (p
< end
&& q
< qend
)
9050 q
+= 1 + size_of_encoded_value (*q
);
9052 fc
->fde_encoding
= *q
++;
9061 /* Note - it is OK if this loop terminates with q < qend.
9062 Padding may have been inserted to align the end of the CIE. */
9067 *p_version
= version
;
9070 *p_aug_len
= augmentation_data_len
;
9071 *p_aug
= augmentation_data
;
9076 free (fc
->col_offset
);
9077 free (fc
->col_type
);
9082 /* Prints out the contents on the DATA array formatted as unsigned bytes.
9083 If do_wide is not enabled, then formats the output to fit into 80 columns.
9084 PRINTED contains the number of characters already written to the current
9088 display_data (size_t printed
, const unsigned char *data
, size_t len
)
9090 if (do_wide
|| len
< ((80 - printed
) / 3))
9091 for (printed
= 0; printed
< len
; ++printed
)
9092 printf (" %02x", data
[printed
]);
9095 for (printed
= 0; printed
< len
; ++printed
)
9097 if (printed
% (80 / 3) == 0)
9099 printf (" %02x", data
[printed
]);
9104 /* Prints out the contents on the augmentation data array.
9105 If do_wide is not enabled, then formats the output to fit into 80 columns. */
9108 display_augmentation_data (const unsigned char * data
, uint64_t len
)
9112 i
= printf (_(" Augmentation data: "));
9113 display_data (i
, data
, len
);
9117 display_debug_frames (struct dwarf_section
*section
,
9118 void *file ATTRIBUTE_UNUSED
)
9120 unsigned char *start
= section
->start
;
9121 unsigned char *end
= start
+ section
->size
;
9122 unsigned char *section_start
= start
;
9123 Frame_Chunk
*chunks
= NULL
, *forward_refs
= NULL
;
9124 Frame_Chunk
*remembered_state
= NULL
;
9126 bool is_eh
= strcmp (section
->name
, ".eh_frame") == 0;
9127 unsigned int max_regs
= 0;
9128 const char *bad_reg
= _("bad register: ");
9129 unsigned int saved_eh_addr_size
= eh_addr_size
;
9131 introduce (section
, false);
9135 unsigned char *saved_start
;
9136 unsigned char *block_end
;
9141 int need_col_headers
= 1;
9142 unsigned char *augmentation_data
= NULL
;
9143 uint64_t augmentation_data_len
= 0;
9144 unsigned int encoded_ptr_size
= saved_eh_addr_size
;
9145 unsigned int offset_size
;
9147 static Frame_Chunk fde_fc
;
9149 saved_start
= start
;
9151 SAFE_BYTE_GET_AND_INC (length
, start
, 4, end
);
9155 printf ("\n%08tx ZERO terminator\n\n",
9156 saved_start
- section_start
);
9157 /* Skip any zero terminators that directly follow.
9158 A corrupt section size could have loaded a whole
9159 slew of zero filled memory bytes. eg
9160 PR 17512: file: 070-19381-0.004. */
9161 while (start
< end
&& * start
== 0)
9166 if (length
== 0xffffffff)
9168 SAFE_BYTE_GET_AND_INC (length
, start
, 8, end
);
9174 if (length
> (size_t) (end
- start
))
9176 warn ("Invalid length %#" PRIx64
" in FDE at %#tx\n",
9177 length
, saved_start
- section_start
);
9181 block_end
= start
+ length
;
9183 SAFE_BYTE_GET_AND_INC (cie_id
, start
, offset_size
, block_end
);
9185 if (is_eh
? (cie_id
== 0) : ((offset_size
== 4 && cie_id
== DW_CIE_ID
)
9186 || (offset_size
== 8 && cie_id
== DW64_CIE_ID
)))
9191 start
= read_cie (start
, block_end
, &cie
, &version
,
9192 &augmentation_data_len
, &augmentation_data
);
9193 /* PR 17512: file: 027-135133-0.005. */
9200 fc
->chunk_start
= saved_start
;
9201 mreg
= max_regs
> 0 ? max_regs
- 1 : 0;
9204 if (frame_need_space (fc
, mreg
) < 0)
9206 if (fc
->fde_encoding
)
9207 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
9209 printf ("\n%08tx ", saved_start
- section_start
);
9210 print_hex (length
, fc
->ptr_size
);
9211 print_hex (cie_id
, offset_size
);
9213 if (do_debug_frames_interp
)
9215 printf ("CIE \"%s\" cf=%d df=%d ra=%d\n", fc
->augmentation
,
9216 fc
->code_factor
, fc
->data_factor
, fc
->ra
);
9221 printf (" Version: %d\n", version
);
9222 printf (" Augmentation: \"%s\"\n", fc
->augmentation
);
9225 printf (" Pointer Size: %u\n", fc
->ptr_size
);
9226 printf (" Segment Size: %u\n", fc
->segment_size
);
9228 printf (" Code alignment factor: %u\n", fc
->code_factor
);
9229 printf (" Data alignment factor: %d\n", fc
->data_factor
);
9230 printf (" Return address column: %d\n", fc
->ra
);
9232 if (augmentation_data_len
)
9233 display_augmentation_data (augmentation_data
, augmentation_data_len
);
9240 unsigned char *look_for
;
9241 unsigned long segment_selector
;
9247 uint64_t sign
= (uint64_t) 1 << (offset_size
* 8 - 1);
9248 cie_off
= (cie_off
^ sign
) - sign
;
9249 cie_off
= start
- 4 - section_start
- cie_off
;
9252 look_for
= section_start
+ cie_off
;
9253 if (cie_off
<= (size_t) (saved_start
- section_start
))
9255 for (cie
= chunks
; cie
; cie
= cie
->next
)
9256 if (cie
->chunk_start
== look_for
)
9259 else if (cie_off
>= section
->size
)
9263 for (cie
= forward_refs
; cie
; cie
= cie
->next
)
9264 if (cie
->chunk_start
== look_for
)
9268 unsigned int off_size
;
9269 unsigned char *cie_scan
;
9271 cie_scan
= look_for
;
9273 SAFE_BYTE_GET_AND_INC (length
, cie_scan
, 4, end
);
9274 if (length
== 0xffffffff)
9276 SAFE_BYTE_GET_AND_INC (length
, cie_scan
, 8, end
);
9279 if (length
!= 0 && length
<= (size_t) (end
- cie_scan
))
9282 unsigned char *cie_end
= cie_scan
+ length
;
9284 SAFE_BYTE_GET_AND_INC (c_id
, cie_scan
, off_size
,
9288 : ((off_size
== 4 && c_id
== DW_CIE_ID
)
9289 || (off_size
== 8 && c_id
== DW64_CIE_ID
)))
9294 read_cie (cie_scan
, cie_end
, &cie
, &version
,
9295 &augmentation_data_len
, &augmentation_data
);
9296 /* PR 17512: file: 3450-2098-0.004. */
9299 warn (_("Failed to read CIE information\n"));
9302 cie
->next
= forward_refs
;
9304 cie
->chunk_start
= look_for
;
9305 mreg
= max_regs
> 0 ? max_regs
- 1 : 0;
9308 if (frame_need_space (cie
, mreg
) < 0)
9310 warn (_("Invalid max register\n"));
9313 if (cie
->fde_encoding
)
9315 = size_of_encoded_value (cie
->fde_encoding
);
9322 memset (fc
, 0, sizeof (Frame_Chunk
));
9327 fc
->col_type
= xmalloc (sizeof (*fc
->col_type
));
9328 fc
->col_offset
= xmalloc (sizeof (*fc
->col_offset
));
9329 if (frame_need_space (fc
, max_regs
> 0 ? max_regs
- 1 : 0) < 0)
9331 warn (_("Invalid max register\n"));
9335 fc
->augmentation
= "";
9336 fc
->fde_encoding
= 0;
9337 fc
->ptr_size
= eh_addr_size
;
9338 fc
->segment_size
= 0;
9342 fc
->ncols
= cie
->ncols
;
9343 fc
->col_type
= xcmalloc (fc
->ncols
, sizeof (*fc
->col_type
));
9344 fc
->col_offset
= xcmalloc (fc
->ncols
, sizeof (*fc
->col_offset
));
9345 memcpy (fc
->col_type
, cie
->col_type
,
9346 fc
->ncols
* sizeof (*fc
->col_type
));
9347 memcpy (fc
->col_offset
, cie
->col_offset
,
9348 fc
->ncols
* sizeof (*fc
->col_offset
));
9349 fc
->augmentation
= cie
->augmentation
;
9350 fc
->ptr_size
= cie
->ptr_size
;
9351 eh_addr_size
= cie
->ptr_size
;
9352 fc
->segment_size
= cie
->segment_size
;
9353 fc
->code_factor
= cie
->code_factor
;
9354 fc
->data_factor
= cie
->data_factor
;
9355 fc
->cfa_reg
= cie
->cfa_reg
;
9356 fc
->cfa_offset
= cie
->cfa_offset
;
9358 if (frame_need_space (fc
, max_regs
> 0 ? max_regs
- 1: 0) < 0)
9360 warn (_("Invalid max register\n"));
9363 fc
->fde_encoding
= cie
->fde_encoding
;
9366 if (fc
->fde_encoding
)
9367 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
9369 segment_selector
= 0;
9370 if (fc
->segment_size
)
9372 if (fc
->segment_size
> sizeof (segment_selector
))
9374 /* PR 17512: file: 9e196b3e. */
9375 warn (_("Probably corrupt segment size: %d - using 4 instead\n"), fc
->segment_size
);
9376 fc
->segment_size
= 4;
9378 SAFE_BYTE_GET_AND_INC (segment_selector
, start
,
9379 fc
->segment_size
, block_end
);
9382 fc
->pc_begin
= get_encoded_value (&start
, fc
->fde_encoding
, section
,
9385 /* FIXME: It appears that sometimes the final pc_range value is
9386 encoded in less than encoded_ptr_size bytes. See the x86_64
9387 run of the "objcopy on compressed debug sections" test for an
9389 SAFE_BYTE_GET_AND_INC (fc
->pc_range
, start
, encoded_ptr_size
,
9392 if (cie
->augmentation
[0] == 'z')
9394 READ_ULEB (augmentation_data_len
, start
, block_end
);
9395 augmentation_data
= start
;
9396 /* PR 17512 file: 722-8446-0.004 and PR 22386. */
9397 if (augmentation_data_len
> (size_t) (block_end
- start
))
9399 warn (_("Augmentation data too long: %#" PRIx64
", "
9400 "expected at most %#tx\n"),
9401 augmentation_data_len
, block_end
- start
);
9403 augmentation_data
= NULL
;
9404 augmentation_data_len
= 0;
9406 start
+= augmentation_data_len
;
9409 printf ("\n%08tx ", saved_start
- section_start
);
9410 print_hex (length
, fc
->ptr_size
);
9411 print_hex (cie_id
, offset_size
);
9414 if (cie
->chunk_start
)
9415 printf ("cie=%08tx", cie
->chunk_start
- section_start
);
9417 /* Ideally translate "invalid " to 8 chars, trailing space
9419 printf (_("cie=invalid "));
9422 if (fc
->segment_size
)
9423 printf ("%04lx:", segment_selector
);
9425 print_hex_ns (fc
->pc_begin
, fc
->ptr_size
);
9427 print_hex_ns (fc
->pc_begin
+ fc
->pc_range
, fc
->ptr_size
);
9430 if (! do_debug_frames_interp
&& augmentation_data_len
)
9432 display_augmentation_data (augmentation_data
, augmentation_data_len
);
9437 /* At this point, fc is the current chunk, cie (if any) is set, and
9438 we're about to interpret instructions for the chunk. */
9439 /* ??? At present we need to do this always, since this sizes the
9440 fc->col_type and fc->col_offset arrays, which we write into always.
9441 We should probably split the interpreted and non-interpreted bits
9442 into two different routines, since there's so much that doesn't
9443 really overlap between them. */
9444 if (1 || do_debug_frames_interp
)
9446 /* Start by making a pass over the chunk, allocating storage
9447 and taking note of what registers are used. */
9448 unsigned char *tmp
= start
;
9450 while (start
< block_end
)
9452 unsigned int reg
, op
, opa
;
9460 /* Warning: if you add any more cases to this switch, be
9461 sure to add them to the corresponding switch below. */
9465 case DW_CFA_advance_loc
:
9468 SKIP_ULEB (start
, block_end
);
9471 case DW_CFA_restore
:
9474 case DW_CFA_set_loc
:
9475 if ((size_t) (block_end
- start
) < encoded_ptr_size
)
9478 start
+= encoded_ptr_size
;
9480 case DW_CFA_advance_loc1
:
9481 if ((size_t) (block_end
- start
) < 1)
9486 case DW_CFA_advance_loc2
:
9487 if ((size_t) (block_end
- start
) < 2)
9492 case DW_CFA_advance_loc4
:
9493 if ((size_t) (block_end
- start
) < 4)
9498 case DW_CFA_offset_extended
:
9499 case DW_CFA_val_offset
:
9500 READ_ULEB (reg
, start
, block_end
);
9501 SKIP_ULEB (start
, block_end
);
9503 case DW_CFA_restore_extended
:
9504 READ_ULEB (reg
, start
, block_end
);
9506 case DW_CFA_undefined
:
9507 READ_ULEB (reg
, start
, block_end
);
9509 case DW_CFA_same_value
:
9510 READ_ULEB (reg
, start
, block_end
);
9512 case DW_CFA_register
:
9513 READ_ULEB (reg
, start
, block_end
);
9514 SKIP_ULEB (start
, block_end
);
9516 case DW_CFA_def_cfa
:
9517 SKIP_ULEB (start
, block_end
);
9518 SKIP_ULEB (start
, block_end
);
9520 case DW_CFA_def_cfa_register
:
9521 SKIP_ULEB (start
, block_end
);
9523 case DW_CFA_def_cfa_offset
:
9524 SKIP_ULEB (start
, block_end
);
9526 case DW_CFA_def_cfa_expression
:
9527 READ_ULEB (temp
, start
, block_end
);
9528 if ((size_t) (block_end
- start
) < temp
)
9533 case DW_CFA_expression
:
9534 case DW_CFA_val_expression
:
9535 READ_ULEB (reg
, start
, block_end
);
9536 READ_ULEB (temp
, start
, block_end
);
9537 if ((size_t) (block_end
- start
) < temp
)
9542 case DW_CFA_offset_extended_sf
:
9543 case DW_CFA_val_offset_sf
:
9544 READ_ULEB (reg
, start
, block_end
);
9545 SKIP_SLEB (start
, block_end
);
9547 case DW_CFA_def_cfa_sf
:
9548 SKIP_ULEB (start
, block_end
);
9549 SKIP_SLEB (start
, block_end
);
9551 case DW_CFA_def_cfa_offset_sf
:
9552 SKIP_SLEB (start
, block_end
);
9554 case DW_CFA_MIPS_advance_loc8
:
9555 if ((size_t) (block_end
- start
) < 8)
9560 case DW_CFA_GNU_args_size
:
9561 SKIP_ULEB (start
, block_end
);
9563 case DW_CFA_GNU_negative_offset_extended
:
9564 READ_ULEB (reg
, start
, block_end
);
9565 SKIP_ULEB (start
, block_end
);
9570 if (reg
!= -1u && frame_need_space (fc
, reg
) >= 0)
9572 /* Don't leave any reg as DW_CFA_unreferenced so
9573 that frame_display_row prints name of regs in
9574 header, and all referenced regs in each line. */
9575 if (reg
>= cie
->ncols
9576 || cie
->col_type
[reg
] == DW_CFA_unreferenced
)
9577 fc
->col_type
[reg
] = DW_CFA_undefined
;
9579 fc
->col_type
[reg
] = cie
->col_type
[reg
];
9587 /* Now we know what registers are used, make a second pass over
9588 the chunk, this time actually printing out the info. */
9590 while (start
< block_end
)
9593 /* Note: It is tempting to use an unsigned long for 'reg' but there
9594 are various functions, notably frame_space_needed() that assume that
9595 reg is an unsigned int. */
9599 const char *reg_prefix
= "";
9606 /* Make a note if something other than DW_CFA_nop happens. */
9607 if (op
!= DW_CFA_nop
)
9610 /* Warning: if you add any more cases to this switch, be
9611 sure to add them to the corresponding switch above. */
9614 case DW_CFA_advance_loc
:
9615 opa
*= fc
->code_factor
;
9616 if (do_debug_frames_interp
)
9617 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9620 printf (" DW_CFA_advance_loc: %d to ", opa
);
9621 print_hex_ns (fc
->pc_begin
+ opa
, fc
->ptr_size
);
9624 fc
->pc_begin
+= opa
;
9628 READ_ULEB (ofs
, start
, block_end
);
9629 ofs
*= fc
->data_factor
;
9630 if (opa
>= fc
->ncols
)
9631 reg_prefix
= bad_reg
;
9632 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9633 printf (" DW_CFA_offset: %s%s at cfa%+" PRId64
"\n",
9634 reg_prefix
, regname (opa
, 0), ofs
);
9635 if (*reg_prefix
== '\0')
9637 fc
->col_type
[opa
] = DW_CFA_offset
;
9638 fc
->col_offset
[opa
] = ofs
;
9642 case DW_CFA_restore
:
9643 if (opa
>= fc
->ncols
)
9644 reg_prefix
= bad_reg
;
9645 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9646 printf (" DW_CFA_restore: %s%s\n",
9647 reg_prefix
, regname (opa
, 0));
9648 if (*reg_prefix
!= '\0')
9651 if (opa
>= cie
->ncols
9652 || cie
->col_type
[opa
] == DW_CFA_unreferenced
)
9654 fc
->col_type
[opa
] = DW_CFA_undefined
;
9655 fc
->col_offset
[opa
] = 0;
9659 fc
->col_type
[opa
] = cie
->col_type
[opa
];
9660 fc
->col_offset
[opa
] = cie
->col_offset
[opa
];
9664 case DW_CFA_set_loc
:
9665 ofs
= get_encoded_value (&start
, fc
->fde_encoding
, section
,
9667 if (do_debug_frames_interp
)
9668 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9671 printf (" DW_CFA_set_loc: ");
9672 print_hex_ns (ofs
, fc
->ptr_size
);
9678 case DW_CFA_advance_loc1
:
9679 SAFE_BYTE_GET_AND_INC (ofs
, start
, 1, block_end
);
9680 ofs
*= fc
->code_factor
;
9681 if (do_debug_frames_interp
)
9682 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9685 printf (" DW_CFA_advance_loc1: %" PRId64
" to ", ofs
);
9686 print_hex_ns (fc
->pc_begin
+ ofs
, fc
->ptr_size
);
9689 fc
->pc_begin
+= ofs
;
9692 case DW_CFA_advance_loc2
:
9693 SAFE_BYTE_GET_AND_INC (ofs
, start
, 2, block_end
);
9694 ofs
*= fc
->code_factor
;
9695 if (do_debug_frames_interp
)
9696 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9699 printf (" DW_CFA_advance_loc2: %" PRId64
" to ", ofs
);
9700 print_hex_ns (fc
->pc_begin
+ ofs
, fc
->ptr_size
);
9703 fc
->pc_begin
+= ofs
;
9706 case DW_CFA_advance_loc4
:
9707 SAFE_BYTE_GET_AND_INC (ofs
, start
, 4, block_end
);
9708 ofs
*= fc
->code_factor
;
9709 if (do_debug_frames_interp
)
9710 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9713 printf (" DW_CFA_advance_loc4: %" PRId64
" to ", ofs
);
9714 print_hex_ns (fc
->pc_begin
+ ofs
, fc
->ptr_size
);
9717 fc
->pc_begin
+= ofs
;
9720 case DW_CFA_offset_extended
:
9721 READ_ULEB (reg
, start
, block_end
);
9722 READ_ULEB (ofs
, start
, block_end
);
9723 ofs
*= fc
->data_factor
;
9724 if (reg
>= fc
->ncols
)
9725 reg_prefix
= bad_reg
;
9726 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9727 printf (" DW_CFA_offset_extended: %s%s at cfa%+" PRId64
"\n",
9728 reg_prefix
, regname (reg
, 0), ofs
);
9729 if (*reg_prefix
== '\0')
9731 fc
->col_type
[reg
] = DW_CFA_offset
;
9732 fc
->col_offset
[reg
] = ofs
;
9736 case DW_CFA_val_offset
:
9737 READ_ULEB (reg
, start
, block_end
);
9738 READ_ULEB (ofs
, start
, block_end
);
9739 ofs
*= fc
->data_factor
;
9740 if (reg
>= fc
->ncols
)
9741 reg_prefix
= bad_reg
;
9742 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9743 printf (" DW_CFA_val_offset: %s%s is cfa%+" PRId64
"\n",
9744 reg_prefix
, regname (reg
, 0), ofs
);
9745 if (*reg_prefix
== '\0')
9747 fc
->col_type
[reg
] = DW_CFA_val_offset
;
9748 fc
->col_offset
[reg
] = ofs
;
9752 case DW_CFA_restore_extended
:
9753 READ_ULEB (reg
, start
, block_end
);
9754 if (reg
>= fc
->ncols
)
9755 reg_prefix
= bad_reg
;
9756 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9757 printf (" DW_CFA_restore_extended: %s%s\n",
9758 reg_prefix
, regname (reg
, 0));
9759 if (*reg_prefix
!= '\0')
9762 if (reg
>= cie
->ncols
9763 || cie
->col_type
[reg
] == DW_CFA_unreferenced
)
9765 fc
->col_type
[reg
] = DW_CFA_undefined
;
9766 fc
->col_offset
[reg
] = 0;
9770 fc
->col_type
[reg
] = cie
->col_type
[reg
];
9771 fc
->col_offset
[reg
] = cie
->col_offset
[reg
];
9775 case DW_CFA_undefined
:
9776 READ_ULEB (reg
, start
, block_end
);
9777 if (reg
>= fc
->ncols
)
9778 reg_prefix
= bad_reg
;
9779 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9780 printf (" DW_CFA_undefined: %s%s\n",
9781 reg_prefix
, regname (reg
, 0));
9782 if (*reg_prefix
== '\0')
9784 fc
->col_type
[reg
] = DW_CFA_undefined
;
9785 fc
->col_offset
[reg
] = 0;
9789 case DW_CFA_same_value
:
9790 READ_ULEB (reg
, start
, block_end
);
9791 if (reg
>= fc
->ncols
)
9792 reg_prefix
= bad_reg
;
9793 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9794 printf (" DW_CFA_same_value: %s%s\n",
9795 reg_prefix
, regname (reg
, 0));
9796 if (*reg_prefix
== '\0')
9798 fc
->col_type
[reg
] = DW_CFA_same_value
;
9799 fc
->col_offset
[reg
] = 0;
9803 case DW_CFA_register
:
9804 READ_ULEB (reg
, start
, block_end
);
9805 READ_ULEB (ofs
, start
, block_end
);
9806 if (reg
>= fc
->ncols
)
9807 reg_prefix
= bad_reg
;
9808 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9810 printf (" DW_CFA_register: %s%s in ",
9811 reg_prefix
, regname (reg
, 0));
9812 puts (regname (ofs
, 0));
9814 if (*reg_prefix
== '\0')
9816 fc
->col_type
[reg
] = DW_CFA_register
;
9817 fc
->col_offset
[reg
] = ofs
;
9821 case DW_CFA_remember_state
:
9822 if (! do_debug_frames_interp
)
9823 printf (" DW_CFA_remember_state\n");
9824 rs
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
9825 rs
->cfa_offset
= fc
->cfa_offset
;
9826 rs
->cfa_reg
= fc
->cfa_reg
;
9828 rs
->cfa_exp
= fc
->cfa_exp
;
9829 rs
->ncols
= fc
->ncols
;
9830 rs
->col_type
= xcmalloc (rs
->ncols
, sizeof (*rs
->col_type
));
9831 rs
->col_offset
= xcmalloc (rs
->ncols
, sizeof (*rs
->col_offset
));
9832 memcpy (rs
->col_type
, fc
->col_type
,
9833 rs
->ncols
* sizeof (*fc
->col_type
));
9834 memcpy (rs
->col_offset
, fc
->col_offset
,
9835 rs
->ncols
* sizeof (*fc
->col_offset
));
9836 rs
->next
= remembered_state
;
9837 remembered_state
= rs
;
9840 case DW_CFA_restore_state
:
9841 if (! do_debug_frames_interp
)
9842 printf (" DW_CFA_restore_state\n");
9843 rs
= remembered_state
;
9846 remembered_state
= rs
->next
;
9847 fc
->cfa_offset
= rs
->cfa_offset
;
9848 fc
->cfa_reg
= rs
->cfa_reg
;
9850 fc
->cfa_exp
= rs
->cfa_exp
;
9851 if (frame_need_space (fc
, rs
->ncols
- 1) < 0)
9853 warn (_("Invalid column number in saved frame state\n"));
9858 memcpy (fc
->col_type
, rs
->col_type
,
9859 rs
->ncols
* sizeof (*rs
->col_type
));
9860 memcpy (fc
->col_offset
, rs
->col_offset
,
9861 rs
->ncols
* sizeof (*rs
->col_offset
));
9863 free (rs
->col_type
);
9864 free (rs
->col_offset
);
9867 else if (do_debug_frames_interp
)
9868 printf ("Mismatched DW_CFA_restore_state\n");
9871 case DW_CFA_def_cfa
:
9872 READ_ULEB (fc
->cfa_reg
, start
, block_end
);
9873 READ_ULEB (fc
->cfa_offset
, start
, block_end
);
9875 if (! do_debug_frames_interp
)
9876 printf (" DW_CFA_def_cfa: %s ofs %d\n",
9877 regname (fc
->cfa_reg
, 0), (int) fc
->cfa_offset
);
9880 case DW_CFA_def_cfa_register
:
9881 READ_ULEB (fc
->cfa_reg
, start
, block_end
);
9883 if (! do_debug_frames_interp
)
9884 printf (" DW_CFA_def_cfa_register: %s\n",
9885 regname (fc
->cfa_reg
, 0));
9888 case DW_CFA_def_cfa_offset
:
9889 READ_ULEB (fc
->cfa_offset
, start
, block_end
);
9890 if (! do_debug_frames_interp
)
9891 printf (" DW_CFA_def_cfa_offset: %d\n", (int) fc
->cfa_offset
);
9895 if (! do_debug_frames_interp
)
9896 printf (" DW_CFA_nop\n");
9899 case DW_CFA_def_cfa_expression
:
9900 READ_ULEB (ofs
, start
, block_end
);
9901 if (ofs
> (size_t) (block_end
- start
))
9903 printf (_(" %s: <corrupt len %" PRIu64
">\n"),
9904 "DW_CFA_def_cfa_expression", ofs
);
9907 if (! do_debug_frames_interp
)
9909 printf (" DW_CFA_def_cfa_expression (");
9910 decode_location_expression (start
, eh_addr_size
, 0, -1,
9918 case DW_CFA_expression
:
9919 READ_ULEB (reg
, start
, block_end
);
9920 READ_ULEB (ofs
, start
, block_end
);
9921 if (reg
>= fc
->ncols
)
9922 reg_prefix
= bad_reg
;
9923 /* PR 17512: file: 069-133014-0.006. */
9924 /* PR 17512: file: 98c02eb4. */
9925 if (ofs
> (size_t) (block_end
- start
))
9927 printf (_(" %s: <corrupt len %" PRIu64
">\n"),
9928 "DW_CFA_expression", ofs
);
9931 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9933 printf (" DW_CFA_expression: %s%s (",
9934 reg_prefix
, regname (reg
, 0));
9935 decode_location_expression (start
, eh_addr_size
, 0, -1,
9939 if (*reg_prefix
== '\0')
9940 fc
->col_type
[reg
] = DW_CFA_expression
;
9944 case DW_CFA_val_expression
:
9945 READ_ULEB (reg
, start
, block_end
);
9946 READ_ULEB (ofs
, start
, block_end
);
9947 if (reg
>= fc
->ncols
)
9948 reg_prefix
= bad_reg
;
9949 if (ofs
> (size_t) (block_end
- start
))
9951 printf (" %s: <corrupt len %" PRIu64
">\n",
9952 "DW_CFA_val_expression", ofs
);
9955 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9957 printf (" DW_CFA_val_expression: %s%s (",
9958 reg_prefix
, regname (reg
, 0));
9959 decode_location_expression (start
, eh_addr_size
, 0, -1,
9963 if (*reg_prefix
== '\0')
9964 fc
->col_type
[reg
] = DW_CFA_val_expression
;
9968 case DW_CFA_offset_extended_sf
:
9969 READ_ULEB (reg
, start
, block_end
);
9970 READ_SLEB (sofs
, start
, block_end
);
9971 /* data_factor multiplicaton done here as unsigned to
9972 avoid integer overflow warnings from asan on fuzzed
9975 ofs
*= fc
->data_factor
;
9976 if (reg
>= fc
->ncols
)
9977 reg_prefix
= bad_reg
;
9978 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9979 printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+" PRId64
"\n",
9980 reg_prefix
, regname (reg
, 0), ofs
);
9981 if (*reg_prefix
== '\0')
9983 fc
->col_type
[reg
] = DW_CFA_offset
;
9984 fc
->col_offset
[reg
] = ofs
;
9988 case DW_CFA_val_offset_sf
:
9989 READ_ULEB (reg
, start
, block_end
);
9990 READ_SLEB (sofs
, start
, block_end
);
9992 ofs
*= fc
->data_factor
;
9993 if (reg
>= fc
->ncols
)
9994 reg_prefix
= bad_reg
;
9995 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9996 printf (" DW_CFA_val_offset_sf: %s%s is cfa%+" PRId64
"\n",
9997 reg_prefix
, regname (reg
, 0), ofs
);
9998 if (*reg_prefix
== '\0')
10000 fc
->col_type
[reg
] = DW_CFA_val_offset
;
10001 fc
->col_offset
[reg
] = ofs
;
10005 case DW_CFA_def_cfa_sf
:
10006 READ_ULEB (fc
->cfa_reg
, start
, block_end
);
10007 READ_SLEB (sofs
, start
, block_end
);
10009 ofs
*= fc
->data_factor
;
10010 fc
->cfa_offset
= ofs
;
10012 if (! do_debug_frames_interp
)
10013 printf (" DW_CFA_def_cfa_sf: %s ofs %" PRId64
"\n",
10014 regname (fc
->cfa_reg
, 0), ofs
);
10017 case DW_CFA_def_cfa_offset_sf
:
10018 READ_SLEB (sofs
, start
, block_end
);
10020 ofs
*= fc
->data_factor
;
10021 fc
->cfa_offset
= ofs
;
10022 if (! do_debug_frames_interp
)
10023 printf (" DW_CFA_def_cfa_offset_sf: %" PRId64
"\n", ofs
);
10026 case DW_CFA_MIPS_advance_loc8
:
10027 SAFE_BYTE_GET_AND_INC (ofs
, start
, 8, block_end
);
10028 ofs
*= fc
->code_factor
;
10029 if (do_debug_frames_interp
)
10030 frame_display_row (fc
, &need_col_headers
, &max_regs
);
10033 printf (" DW_CFA_MIPS_advance_loc8: %" PRId64
" to ", ofs
);
10034 print_hex_ns (fc
->pc_begin
+ ofs
, fc
->ptr_size
);
10037 fc
->pc_begin
+= ofs
;
10040 case DW_CFA_GNU_window_save
:
10041 if (! do_debug_frames_interp
)
10042 printf (" %s\n", DW_CFA_GNU_window_save_name
[is_aarch64
]);
10045 case DW_CFA_GNU_args_size
:
10046 READ_ULEB (ofs
, start
, block_end
);
10047 if (! do_debug_frames_interp
)
10048 printf (" DW_CFA_GNU_args_size: %" PRIu64
"\n", ofs
);
10051 case DW_CFA_GNU_negative_offset_extended
:
10052 READ_ULEB (reg
, start
, block_end
);
10053 READ_SLEB (sofs
, start
, block_end
);
10055 ofs
= -ofs
* fc
->data_factor
;
10056 if (reg
>= fc
->ncols
)
10057 reg_prefix
= bad_reg
;
10058 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
10059 printf (" DW_CFA_GNU_negative_offset_extended: %s%s "
10060 "at cfa%+" PRId64
"\n",
10061 reg_prefix
, regname (reg
, 0), ofs
);
10062 if (*reg_prefix
== '\0')
10064 fc
->col_type
[reg
] = DW_CFA_offset
;
10065 fc
->col_offset
[reg
] = ofs
;
10070 if (op
>= DW_CFA_lo_user
&& op
<= DW_CFA_hi_user
)
10071 printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op
);
10073 warn (_("Unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op
);
10078 /* Interpret the CFA - as long as it is not completely full of NOPs. */
10079 if (do_debug_frames_interp
&& ! all_nops
)
10080 frame_display_row (fc
, &need_col_headers
, &max_regs
);
10082 if (fde_fc
.col_type
!= NULL
)
10084 free (fde_fc
.col_type
);
10085 fde_fc
.col_type
= NULL
;
10087 if (fde_fc
.col_offset
!= NULL
)
10089 free (fde_fc
.col_offset
);
10090 fde_fc
.col_offset
= NULL
;
10094 eh_addr_size
= saved_eh_addr_size
;
10099 while (remembered_state
!= NULL
)
10101 rs
= remembered_state
;
10102 remembered_state
= rs
->next
;
10103 free (rs
->col_type
);
10104 free (rs
->col_offset
);
10105 rs
->next
= NULL
; /* Paranoia. */
10109 while (chunks
!= NULL
)
10113 free (rs
->col_type
);
10114 free (rs
->col_offset
);
10115 rs
->next
= NULL
; /* Paranoia. */
10119 while (forward_refs
!= NULL
)
10122 forward_refs
= rs
->next
;
10123 free (rs
->col_type
);
10124 free (rs
->col_offset
);
10125 rs
->next
= NULL
; /* Paranoia. */
10135 display_debug_names (struct dwarf_section
*section
, void *file
)
10137 unsigned char *hdrptr
= section
->start
;
10138 uint64_t unit_length
;
10139 unsigned char *unit_start
;
10140 const unsigned char *const section_end
= section
->start
+ section
->size
;
10141 unsigned char *unit_end
;
10143 introduce (section
, false);
10145 load_debug_section_with_follow (str
, file
);
10147 for (; hdrptr
< section_end
; hdrptr
= unit_end
)
10149 unsigned int offset_size
;
10150 uint16_t dwarf_version
, padding
;
10151 uint32_t comp_unit_count
, local_type_unit_count
, foreign_type_unit_count
;
10152 uint64_t bucket_count
, name_count
, abbrev_table_size
;
10153 uint32_t augmentation_string_size
;
10155 bool augmentation_printable
;
10156 const char *augmentation_string
;
10159 unit_start
= hdrptr
;
10161 /* Get and check the length of the block. */
10162 SAFE_BYTE_GET_AND_INC (unit_length
, hdrptr
, 4, section_end
);
10164 if (unit_length
== 0xffffffff)
10166 /* This section is 64-bit DWARF. */
10167 SAFE_BYTE_GET_AND_INC (unit_length
, hdrptr
, 8, section_end
);
10173 if (unit_length
> (size_t) (section_end
- hdrptr
)
10174 || unit_length
< 2 + 2 + 4 * 7)
10177 warn (_("Debug info is corrupted, %s header at %#tx"
10178 " has length %#" PRIx64
"\n"),
10179 section
->name
, unit_start
- section
->start
, unit_length
);
10182 unit_end
= hdrptr
+ unit_length
;
10184 /* Get and check the version number. */
10185 SAFE_BYTE_GET_AND_INC (dwarf_version
, hdrptr
, 2, unit_end
);
10186 printf (_("Version %d\n"), (int) dwarf_version
);
10188 /* Prior versions did not exist, and future versions may not be
10189 backwards compatible. */
10190 if (dwarf_version
!= 5)
10192 warn (_("Only DWARF version 5 .debug_names "
10193 "is currently supported.\n"));
10197 SAFE_BYTE_GET_AND_INC (padding
, hdrptr
, 2, unit_end
);
10199 warn (_("Padding field of .debug_names must be 0 (found 0x%x)\n"),
10202 SAFE_BYTE_GET_AND_INC (comp_unit_count
, hdrptr
, 4, unit_end
);
10203 if (comp_unit_count
== 0)
10204 warn (_("Compilation unit count must be >= 1 in .debug_names\n"));
10206 SAFE_BYTE_GET_AND_INC (local_type_unit_count
, hdrptr
, 4, unit_end
);
10207 SAFE_BYTE_GET_AND_INC (foreign_type_unit_count
, hdrptr
, 4, unit_end
);
10208 SAFE_BYTE_GET_AND_INC (bucket_count
, hdrptr
, 4, unit_end
);
10209 SAFE_BYTE_GET_AND_INC (name_count
, hdrptr
, 4, unit_end
);
10210 SAFE_BYTE_GET_AND_INC (abbrev_table_size
, hdrptr
, 4, unit_end
);
10212 SAFE_BYTE_GET_AND_INC (augmentation_string_size
, hdrptr
, 4, unit_end
);
10213 if (augmentation_string_size
% 4 != 0)
10215 warn (_("Augmentation string length %u must be rounded up "
10216 "to a multiple of 4 in .debug_names.\n"),
10217 augmentation_string_size
);
10218 augmentation_string_size
+= (-augmentation_string_size
) & 3;
10220 if (augmentation_string_size
> (size_t) (unit_end
- hdrptr
))
10223 printf (_("Augmentation string:"));
10225 augmentation_printable
= true;
10226 augmentation_string
= (const char *) hdrptr
;
10228 for (i
= 0; i
< augmentation_string_size
; i
++)
10232 SAFE_BYTE_GET_AND_INC (uc
, hdrptr
, 1, unit_end
);
10233 printf (" %02x", uc
);
10235 if (uc
!= 0 && !ISPRINT (uc
))
10236 augmentation_printable
= false;
10239 if (augmentation_printable
)
10243 i
< augmentation_string_size
&& augmentation_string
[i
];
10245 putchar (augmentation_string
[i
]);
10250 printf (_("CU table:\n"));
10251 if (_mul_overflow (comp_unit_count
, offset_size
, &total
)
10252 || total
> (size_t) (unit_end
- hdrptr
))
10254 for (i
= 0; i
< comp_unit_count
; i
++)
10256 uint64_t cu_offset
;
10258 SAFE_BYTE_GET_AND_INC (cu_offset
, hdrptr
, offset_size
, unit_end
);
10259 printf ("[%3u] %#" PRIx64
"\n", i
, cu_offset
);
10263 printf (_("TU table:\n"));
10264 if (_mul_overflow (local_type_unit_count
, offset_size
, &total
)
10265 || total
> (size_t) (unit_end
- hdrptr
))
10267 for (i
= 0; i
< local_type_unit_count
; i
++)
10269 uint64_t tu_offset
;
10271 SAFE_BYTE_GET_AND_INC (tu_offset
, hdrptr
, offset_size
, unit_end
);
10272 printf ("[%3u] %#" PRIx64
"\n", i
, tu_offset
);
10276 printf (_("Foreign TU table:\n"));
10277 if (_mul_overflow (foreign_type_unit_count
, 8, &total
)
10278 || total
> (size_t) (unit_end
- hdrptr
))
10280 for (i
= 0; i
< foreign_type_unit_count
; i
++)
10282 uint64_t signature
;
10284 SAFE_BYTE_GET_AND_INC (signature
, hdrptr
, 8, unit_end
);
10285 printf (_("[%3u] "), i
);
10286 print_hex_ns (signature
, 8);
10291 uint64_t xtra
= (bucket_count
* sizeof (uint32_t)
10292 + name_count
* (sizeof (uint32_t) + 2 * offset_size
)
10293 + abbrev_table_size
);
10294 if (xtra
> (size_t) (unit_end
- hdrptr
))
10296 warn (_("Entry pool offset (%#" PRIx64
") exceeds unit size %#tx "
10297 "for unit %#tx in the debug_names\n"),
10298 xtra
, unit_end
- unit_start
, unit_start
- section
->start
);
10301 const uint32_t *const hash_table_buckets
= (uint32_t *) hdrptr
;
10302 hdrptr
+= bucket_count
* sizeof (uint32_t);
10303 const uint32_t *const hash_table_hashes
= (uint32_t *) hdrptr
;
10304 hdrptr
+= name_count
* sizeof (uint32_t);
10305 unsigned char *const name_table_string_offsets
= hdrptr
;
10306 hdrptr
+= name_count
* offset_size
;
10307 unsigned char *const name_table_entry_offsets
= hdrptr
;
10308 hdrptr
+= name_count
* offset_size
;
10309 unsigned char *const abbrev_table
= hdrptr
;
10310 hdrptr
+= abbrev_table_size
;
10311 const unsigned char *const abbrev_table_end
= hdrptr
;
10312 unsigned char *const entry_pool
= hdrptr
;
10314 size_t buckets_filled
= 0;
10316 for (bucketi
= 0; bucketi
< bucket_count
; bucketi
++)
10318 const uint32_t bucket
= hash_table_buckets
[bucketi
];
10323 printf (ngettext ("Used %zu of %lu bucket.\n",
10324 "Used %zu of %lu buckets.\n",
10325 (unsigned long) bucket_count
),
10326 buckets_filled
, (unsigned long) bucket_count
);
10328 if (bucket_count
!= 0)
10330 uint32_t hash_prev
= 0;
10331 size_t hash_clash_count
= 0;
10332 size_t longest_clash
= 0;
10333 size_t this_length
= 0;
10335 for (hashi
= 0; hashi
< name_count
; hashi
++)
10337 const uint32_t hash_this
= hash_table_hashes
[hashi
];
10341 if (hash_prev
% bucket_count
== hash_this
% bucket_count
)
10343 ++hash_clash_count
;
10345 longest_clash
= MAX (longest_clash
, this_length
);
10350 hash_prev
= hash_this
;
10352 printf (_("Out of %" PRIu64
" items there are %zu bucket clashes"
10353 " (longest of %zu entries).\n"),
10354 name_count
, hash_clash_count
, longest_clash
);
10356 if (name_count
!= buckets_filled
+ hash_clash_count
)
10357 warn (_("The name_count (%" PRIu64
")"
10358 " is not the same as the used bucket_count"
10359 " (%zu) + the hash clash count (%zu)"),
10360 name_count
, buckets_filled
, hash_clash_count
);
10363 struct abbrev_lookup_entry
10365 uint64_t abbrev_tag
;
10366 unsigned char *abbrev_lookup_ptr
;
10368 struct abbrev_lookup_entry
*abbrev_lookup
= NULL
;
10369 size_t abbrev_lookup_used
= 0;
10370 size_t abbrev_lookup_allocated
= 0;
10372 unsigned char *abbrevptr
= abbrev_table
;
10375 uint64_t abbrev_tag
;
10377 READ_ULEB (abbrev_tag
, abbrevptr
, abbrev_table_end
);
10378 if (abbrev_tag
== 0)
10380 if (abbrev_lookup_used
== abbrev_lookup_allocated
)
10382 abbrev_lookup_allocated
= MAX (0x100,
10383 abbrev_lookup_allocated
* 2);
10384 abbrev_lookup
= xrealloc (abbrev_lookup
,
10385 (abbrev_lookup_allocated
10386 * sizeof (*abbrev_lookup
)));
10388 assert (abbrev_lookup_used
< abbrev_lookup_allocated
);
10389 struct abbrev_lookup_entry
*entry
;
10390 for (entry
= abbrev_lookup
;
10391 entry
< abbrev_lookup
+ abbrev_lookup_used
;
10393 if (entry
->abbrev_tag
== abbrev_tag
)
10395 warn (_("Duplicate abbreviation tag %" PRIu64
10396 " in unit %#tx in the debug_names section\n"),
10397 abbrev_tag
, unit_start
- section
->start
);
10400 entry
= &abbrev_lookup
[abbrev_lookup_used
++];
10401 entry
->abbrev_tag
= abbrev_tag
;
10402 entry
->abbrev_lookup_ptr
= abbrevptr
;
10404 /* Skip DWARF tag. */
10405 SKIP_ULEB (abbrevptr
, abbrev_table_end
);
10408 uint64_t xindex
, form
;
10410 READ_ULEB (xindex
, abbrevptr
, abbrev_table_end
);
10411 READ_ULEB (form
, abbrevptr
, abbrev_table_end
);
10412 if (xindex
== 0 && form
== 0)
10417 printf (_("\nSymbol table:\n"));
10419 for (namei
= 0; namei
< name_count
; ++namei
)
10421 uint64_t string_offset
, entry_offset
;
10424 p
= name_table_string_offsets
+ namei
* offset_size
;
10425 SAFE_BYTE_GET (string_offset
, p
, offset_size
, unit_end
);
10426 p
= name_table_entry_offsets
+ namei
* offset_size
;
10427 SAFE_BYTE_GET (entry_offset
, p
, offset_size
, unit_end
);
10429 printf ("[%3u] #%08x %s:", namei
, hash_table_hashes
[namei
],
10430 fetch_indirect_string (string_offset
));
10432 unsigned char *entryptr
= entry_pool
+ entry_offset
;
10434 /* We need to scan first whether there is a single or multiple
10435 entries. TAGNO is -2 for the first entry, it is -1 for the
10436 initial tag read of the second entry, then it becomes 0 for the
10437 first entry for real printing etc. */
10439 /* Initialize it due to a false compiler warning. */
10440 uint64_t second_abbrev_tag
= -1;
10443 uint64_t abbrev_tag
;
10444 uint64_t dwarf_tag
;
10445 const struct abbrev_lookup_entry
*entry
;
10447 READ_ULEB (abbrev_tag
, entryptr
, unit_end
);
10450 second_abbrev_tag
= abbrev_tag
;
10452 entryptr
= entry_pool
+ entry_offset
;
10455 if (abbrev_tag
== 0)
10458 printf ("%s<%" PRIu64
">",
10459 (tagno
== 0 && second_abbrev_tag
== 0 ? " " : "\n\t"),
10462 for (entry
= abbrev_lookup
;
10463 entry
< abbrev_lookup
+ abbrev_lookup_used
;
10465 if (entry
->abbrev_tag
== abbrev_tag
)
10467 if (entry
>= abbrev_lookup
+ abbrev_lookup_used
)
10469 warn (_("Undefined abbreviation tag %" PRId64
10470 " in unit %#tx in the debug_names section\n"),
10472 unit_start
- section
->start
);
10475 abbrevptr
= entry
->abbrev_lookup_ptr
;
10476 READ_ULEB (dwarf_tag
, abbrevptr
, abbrev_table_end
);
10478 printf (" %s", get_TAG_name (dwarf_tag
));
10481 uint64_t xindex
, form
;
10483 READ_ULEB (xindex
, abbrevptr
, abbrev_table_end
);
10484 READ_ULEB (form
, abbrevptr
, abbrev_table_end
);
10485 if (xindex
== 0 && form
== 0)
10489 printf (" %s", get_IDX_name (xindex
));
10490 entryptr
= read_and_display_attr_value (0, form
, 0,
10491 unit_start
, entryptr
, unit_end
,
10493 dwarf_version
, NULL
,
10494 (tagno
< 0), section
,
10500 printf (_(" <no entries>"));
10504 free (abbrev_lookup
);
10511 display_debug_links (struct dwarf_section
* section
,
10512 void * file ATTRIBUTE_UNUSED
)
10514 const unsigned char * filename
;
10515 unsigned int filelen
;
10517 introduce (section
, false);
10519 /* The .gnu_debuglink section is formatted as:
10520 (c-string) Filename.
10521 (padding) If needed to reach a 4 byte boundary.
10522 (uint32_t) CRC32 value.
10524 The .gun_debugaltlink section is formatted as:
10525 (c-string) Filename.
10526 (binary) Build-ID. */
10528 filename
= section
->start
;
10529 filelen
= strnlen ((const char *) filename
, section
->size
);
10530 if (filelen
== section
->size
)
10532 warn (_("The debuglink filename is corrupt/missing\n"));
10536 printf (_(" Separate debug info file: %s\n"), filename
);
10538 if (startswith (section
->name
, ".gnu_debuglink"))
10540 unsigned int crc32
;
10541 unsigned int crc_offset
;
10543 crc_offset
= filelen
+ 1;
10544 crc_offset
= (crc_offset
+ 3) & ~3;
10545 if (crc_offset
+ 4 > section
->size
)
10547 warn (_("CRC offset missing/truncated\n"));
10551 crc32
= byte_get (filename
+ crc_offset
, 4);
10553 printf (_(" CRC value: %#x\n"), crc32
);
10555 if (crc_offset
+ 4 < section
->size
)
10557 warn (_("There are %#" PRIx64
10558 " extraneous bytes at the end of the section\n"),
10559 section
->size
- (crc_offset
+ 4));
10563 else /* startswith (section->name, ".gnu_debugaltlink") */
10565 const unsigned char *build_id
= section
->start
+ filelen
+ 1;
10566 size_t build_id_len
= section
->size
- (filelen
+ 1);
10569 /* FIXME: Should we support smaller build-id notes ? */
10570 if (build_id_len
< 0x14)
10572 warn (_("Build-ID is too short (%#zx bytes)\n"), build_id_len
);
10576 printed
= printf (_(" Build-ID (%#zx bytes):"), build_id_len
);
10577 display_data (printed
, build_id
, build_id_len
);
10586 display_gdb_index (struct dwarf_section
*section
,
10587 void *file ATTRIBUTE_UNUSED
)
10589 unsigned char *start
= section
->start
;
10591 uint32_t cu_list_offset
, tu_list_offset
;
10592 uint32_t address_table_offset
, symbol_table_offset
, constant_pool_offset
;
10593 unsigned int cu_list_elements
, tu_list_elements
;
10594 unsigned int address_table_elements
, symbol_table_slots
;
10595 unsigned char *cu_list
, *tu_list
;
10596 unsigned char *address_table
, *symbol_table
, *constant_pool
;
10599 /* The documentation for the format of this file is in gdb/dwarf2read.c. */
10601 introduce (section
, false);
10603 if (section
->size
< 6 * sizeof (uint32_t))
10605 warn (_("Truncated header in the %s section.\n"), section
->name
);
10609 version
= byte_get_little_endian (start
, 4);
10610 printf (_("Version %lu\n"), (unsigned long) version
);
10612 /* Prior versions are obsolete, and future versions may not be
10613 backwards compatible. */
10614 if (version
< 3 || version
> 8)
10616 warn (_("Unsupported version %lu.\n"), (unsigned long) version
);
10620 warn (_("The address table data in version 3 may be wrong.\n"));
10622 warn (_("Version 4 does not support case insensitive lookups.\n"));
10624 warn (_("Version 5 does not include inlined functions.\n"));
10626 warn (_("Version 6 does not include symbol attributes.\n"));
10627 /* Version 7 indices generated by Gold have bad type unit references,
10628 PR binutils/15021. But we don't know if the index was generated by
10629 Gold or not, so to avoid worrying users with gdb-generated indices
10630 we say nothing for version 7 here. */
10632 cu_list_offset
= byte_get_little_endian (start
+ 4, 4);
10633 tu_list_offset
= byte_get_little_endian (start
+ 8, 4);
10634 address_table_offset
= byte_get_little_endian (start
+ 12, 4);
10635 symbol_table_offset
= byte_get_little_endian (start
+ 16, 4);
10636 constant_pool_offset
= byte_get_little_endian (start
+ 20, 4);
10638 if (cu_list_offset
> section
->size
10639 || tu_list_offset
> section
->size
10640 || address_table_offset
> section
->size
10641 || symbol_table_offset
> section
->size
10642 || constant_pool_offset
> section
->size
10643 || tu_list_offset
< cu_list_offset
10644 || address_table_offset
< tu_list_offset
10645 || symbol_table_offset
< address_table_offset
10646 || constant_pool_offset
< symbol_table_offset
)
10648 warn (_("Corrupt header in the %s section.\n"), section
->name
);
10652 cu_list_elements
= (tu_list_offset
- cu_list_offset
) / 16;
10653 tu_list_elements
= (address_table_offset
- tu_list_offset
) / 24;
10654 address_table_elements
= (symbol_table_offset
- address_table_offset
) / 20;
10655 symbol_table_slots
= (constant_pool_offset
- symbol_table_offset
) / 8;
10657 cu_list
= start
+ cu_list_offset
;
10658 tu_list
= start
+ tu_list_offset
;
10659 address_table
= start
+ address_table_offset
;
10660 symbol_table
= start
+ symbol_table_offset
;
10661 constant_pool
= start
+ constant_pool_offset
;
10663 printf (_("\nCU table:\n"));
10664 for (i
= 0; i
< cu_list_elements
; i
++)
10666 uint64_t cu_offset
= byte_get_little_endian (cu_list
+ i
* 16, 8);
10667 uint64_t cu_length
= byte_get_little_endian (cu_list
+ i
* 16 + 8, 8);
10669 printf ("[%3u] %#" PRIx64
" - %#" PRIx64
"\n",
10670 i
, cu_offset
, cu_offset
+ cu_length
- 1);
10673 printf (_("\nTU table:\n"));
10674 for (i
= 0; i
< tu_list_elements
; i
++)
10676 uint64_t tu_offset
= byte_get_little_endian (tu_list
+ i
* 24, 8);
10677 uint64_t type_offset
= byte_get_little_endian (tu_list
+ i
* 24 + 8, 8);
10678 uint64_t signature
= byte_get_little_endian (tu_list
+ i
* 24 + 16, 8);
10680 printf ("[%3u] %#" PRIx64
" %#" PRIx64
" ",
10681 i
, tu_offset
, type_offset
);
10682 print_hex_ns (signature
, 8);
10686 printf (_("\nAddress table:\n"));
10687 for (i
= 0; i
< address_table_elements
; i
++)
10689 uint64_t low
= byte_get_little_endian (address_table
+ i
* 20, 8);
10690 uint64_t high
= byte_get_little_endian (address_table
+ i
* 20 + 8, 8);
10691 uint32_t cu_index
= byte_get_little_endian (address_table
+ i
* 20 + 16, 4);
10693 print_hex (low
, 8);
10694 print_hex (high
, 8);
10695 printf ("%" PRIu32
"\n", cu_index
);
10698 printf (_("\nSymbol table:\n"));
10699 for (i
= 0; i
< symbol_table_slots
; ++i
)
10701 uint32_t name_offset
= byte_get_little_endian (symbol_table
+ i
* 8, 4);
10702 uint32_t cu_vector_offset
= byte_get_little_endian (symbol_table
+ i
* 8 + 4, 4);
10703 uint32_t num_cus
, cu
;
10705 if (name_offset
!= 0
10706 || cu_vector_offset
!= 0)
10710 /* PR 17531: file: 5b7b07ad. */
10711 if (name_offset
>= section
->size
- constant_pool_offset
)
10713 printf (_("[%3u] <corrupt offset: %x>"), i
, name_offset
);
10714 warn (_("Corrupt name offset of 0x%x found for symbol table slot %d\n"),
10718 printf ("[%3u] %.*s:", i
,
10719 (int) (section
->size
- (constant_pool_offset
+ name_offset
)),
10720 constant_pool
+ name_offset
);
10722 if (section
->size
- constant_pool_offset
< 4
10723 || cu_vector_offset
> section
->size
- constant_pool_offset
- 4)
10725 printf (_("<invalid CU vector offset: %x>\n"), cu_vector_offset
);
10726 warn (_("Corrupt CU vector offset of 0x%x found for symbol table slot %d\n"),
10727 cu_vector_offset
, i
);
10731 num_cus
= byte_get_little_endian (constant_pool
+ cu_vector_offset
, 4);
10733 if ((uint64_t) num_cus
* 4 > section
->size
- (constant_pool_offset
10734 + cu_vector_offset
+ 4))
10736 printf ("<invalid number of CUs: %d>\n", num_cus
);
10737 warn (_("Invalid number of CUs (0x%x) for symbol table slot %d\n"),
10745 for (j
= 0; j
< num_cus
; ++j
)
10748 gdb_index_symbol_kind kind
;
10750 cu
= byte_get_little_endian (constant_pool
+ cu_vector_offset
+ 4 + j
* 4, 4);
10751 is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu
);
10752 kind
= GDB_INDEX_SYMBOL_KIND_VALUE (cu
);
10753 cu
= GDB_INDEX_CU_VALUE (cu
);
10754 /* Convert to TU number if it's for a type unit. */
10755 if (cu
>= cu_list_elements
)
10756 printf ("%cT%lu", num_cus
> 1 ? '\t' : ' ',
10757 (unsigned long) cu
- cu_list_elements
);
10759 printf ("%c%lu", num_cus
> 1 ? '\t' : ' ', (unsigned long) cu
);
10761 printf (" [%s, %s]",
10762 is_static
? _("static") : _("global"),
10763 get_gdb_index_symbol_kind_name (kind
));
10775 /* Pre-allocate enough space for the CU/TU sets needed. */
10778 prealloc_cu_tu_list (unsigned int nshndx
)
10781 /* Always allocate at least one entry for the end-marker. */
10784 if (shndx_pool
== NULL
)
10786 shndx_pool_size
= nshndx
;
10787 shndx_pool_used
= 0;
10788 shndx_pool
= (unsigned int *) xcmalloc (shndx_pool_size
,
10789 sizeof (unsigned int));
10793 shndx_pool_size
= shndx_pool_used
+ nshndx
;
10794 shndx_pool
= (unsigned int *) xcrealloc (shndx_pool
, shndx_pool_size
,
10795 sizeof (unsigned int));
10800 add_shndx_to_cu_tu_entry (unsigned int shndx
)
10802 shndx_pool
[shndx_pool_used
++] = shndx
;
10806 end_cu_tu_entry (void)
10808 shndx_pool
[shndx_pool_used
++] = 0;
10811 /* Return the short name of a DWARF section given by a DW_SECT enumerator. */
10813 static const char *
10814 get_DW_SECT_short_name (unsigned int dw_sect
)
10816 static char buf
[16];
10822 case DW_SECT_TYPES
:
10824 case DW_SECT_ABBREV
:
10830 case DW_SECT_STR_OFFSETS
:
10832 case DW_SECT_MACINFO
:
10834 case DW_SECT_MACRO
:
10840 snprintf (buf
, sizeof (buf
), "%d", dw_sect
);
10844 /* Process a CU or TU index. If DO_DISPLAY is true, print the contents.
10845 These sections are extensions for Fission.
10846 See http://gcc.gnu.org/wiki/DebugFissionDWP. */
10849 process_cu_tu_index (struct dwarf_section
*section
, int do_display
)
10851 unsigned char *phdr
= section
->start
;
10852 unsigned char *limit
= phdr
+ section
->size
;
10853 unsigned char *phash
;
10854 unsigned char *pindex
;
10855 unsigned char *ppool
;
10856 unsigned int version
;
10857 unsigned int ncols
= 0;
10858 unsigned int nused
;
10859 unsigned int nslots
;
10862 uint64_t signature
;
10865 /* PR 17512: file: 002-168123-0.004. */
10868 warn (_("Section %s is empty\n"), section
->name
);
10871 /* PR 17512: file: 002-376-0.004. */
10872 if (section
->size
< 24)
10874 warn (_("Section %s is too small to contain a CU/TU header\n"),
10880 SAFE_BYTE_GET_AND_INC (version
, phash
, 4, limit
);
10882 SAFE_BYTE_GET_AND_INC (ncols
, phash
, 4, limit
);
10883 SAFE_BYTE_GET_AND_INC (nused
, phash
, 4, limit
);
10884 SAFE_BYTE_GET_AND_INC (nslots
, phash
, 4, limit
);
10886 pindex
= phash
+ (size_t) nslots
* 8;
10887 ppool
= pindex
+ (size_t) nslots
* 4;
10891 introduce (section
, false);
10893 printf (_(" Version: %u\n"), version
);
10895 printf (_(" Number of columns: %u\n"), ncols
);
10896 printf (_(" Number of used entries: %u\n"), nused
);
10897 printf (_(" Number of slots: %u\n\n"), nslots
);
10900 /* PR 17531: file: 45d69832. */
10901 if (_mul_overflow ((size_t) nslots
, 12, &total
)
10902 || total
> (size_t) (limit
- phash
))
10904 warn (ngettext ("Section %s is too small for %u slot\n",
10905 "Section %s is too small for %u slots\n",
10907 section
->name
, nslots
);
10913 unsigned char *shndx_list
;
10914 unsigned int shndx
;
10918 prealloc_cu_tu_list ((limit
- ppool
) / 4);
10919 for (shndx_list
= ppool
+ 4; shndx_list
<= limit
- 4; shndx_list
+= 4)
10921 shndx
= byte_get (shndx_list
, 4);
10922 add_shndx_to_cu_tu_entry (shndx
);
10924 end_cu_tu_entry ();
10927 for (i
= 0; i
< nslots
; i
++)
10929 SAFE_BYTE_GET (signature
, phash
, 8, limit
);
10930 if (signature
!= 0)
10932 SAFE_BYTE_GET (j
, pindex
, 4, limit
);
10933 shndx_list
= ppool
+ j
* 4;
10934 /* PR 17531: file: 705e010d. */
10935 if (shndx_list
< ppool
)
10937 warn (_("Section index pool located before start of section\n"));
10941 printf (_(" [%3d] Signature: %#" PRIx64
" Sections: "),
10945 if (shndx_list
>= limit
)
10947 warn (_("Section %s too small for shndx pool\n"),
10951 SAFE_BYTE_GET (shndx
, shndx_list
, 4, limit
);
10954 printf (" %d", shndx
);
10963 else if (version
== 2)
10966 unsigned int dw_sect
;
10967 unsigned char *ph
= phash
;
10968 unsigned char *pi
= pindex
;
10969 unsigned char *poffsets
= ppool
+ (size_t) ncols
* 4;
10970 unsigned char *psizes
= poffsets
+ (size_t) nused
* ncols
* 4;
10972 struct cu_tu_set
*this_set
= NULL
;
10974 unsigned char *prow
;
10977 is_tu_index
= strcmp (section
->name
, ".debug_tu_index") == 0;
10979 /* PR 17531: file: 0dd159bf.
10980 Check for integer overflow (can occur when size_t is 32-bit)
10981 with overlarge ncols or nused values. */
10983 || _mul_overflow ((size_t) ncols
, 4, &temp
)
10984 || _mul_overflow ((size_t) nused
+ 1, temp
, &total
)
10985 || total
> (size_t) (limit
- ppool
)
10986 /* PR 30227: ncols could be 0. */
10987 || _mul_overflow ((size_t) nused
+ 1, 4, &total
)
10988 || total
> (size_t) (limit
- ppool
))
10990 warn (_("Section %s too small for offset and size tables\n"),
10997 printf (_(" Offset table\n"));
10998 printf (" slot %-16s ",
10999 is_tu_index
? _("signature") : _("dwo_id"));
11006 tu_sets
= xcalloc2 (nused
, sizeof (struct cu_tu_set
));
11007 this_set
= tu_sets
;
11012 cu_sets
= xcalloc2 (nused
, sizeof (struct cu_tu_set
));
11013 this_set
= cu_sets
;
11019 for (j
= 0; j
< ncols
; j
++)
11021 unsigned char *p
= ppool
+ j
* 4;
11022 SAFE_BYTE_GET (dw_sect
, p
, 4, limit
);
11023 printf (" %8s", get_DW_SECT_short_name (dw_sect
));
11028 for (i
= 0; i
< nslots
; i
++)
11030 SAFE_BYTE_GET (signature
, ph
, 8, limit
);
11032 SAFE_BYTE_GET (row
, pi
, 4, limit
);
11035 /* PR 17531: file: a05f6ab3. */
11038 warn (_("Row index (%u) is larger than number of used entries (%u)\n"),
11045 size_t num_copy
= sizeof (uint64_t);
11047 memcpy (&this_set
[row
- 1].signature
, ph
, num_copy
);
11050 prow
= poffsets
+ (row
- 1) * ncols
* 4;
11052 printf (" [%3d] %#" PRIx64
, i
, signature
);
11053 for (j
= 0; j
< ncols
; j
++)
11055 unsigned char *p
= prow
+ j
* 4;
11056 SAFE_BYTE_GET (val
, p
, 4, limit
);
11058 printf (" %8d", val
);
11062 SAFE_BYTE_GET (dw_sect
, p
, 4, limit
);
11064 /* PR 17531: file: 10796eb3. */
11065 if (dw_sect
>= DW_SECT_MAX
)
11066 warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect
);
11068 this_set
[row
- 1].section_offsets
[dw_sect
] = val
;
11084 printf (_(" Size table\n"));
11085 printf (" slot %-16s ",
11086 is_tu_index
? _("signature") : _("dwo_id"));
11089 for (j
= 0; j
< ncols
; j
++)
11091 unsigned char *p
= ppool
+ j
* 4;
11092 SAFE_BYTE_GET (val
, p
, 4, limit
);
11094 printf (" %8s", get_DW_SECT_short_name (val
));
11100 for (i
= 0; i
< nslots
; i
++)
11102 SAFE_BYTE_GET (signature
, ph
, 8, limit
);
11104 SAFE_BYTE_GET (row
, pi
, 4, limit
);
11107 prow
= psizes
+ (row
- 1) * ncols
* 4;
11110 printf (" [%3d] %#" PRIx64
, i
, signature
);
11112 for (j
= 0; j
< ncols
; j
++)
11114 unsigned char *p
= prow
+ j
* 4;
11116 /* PR 28645: Check for overflow. Since we do not know how
11117 many populated rows there will be, we cannot just
11118 perform a single check at the start of this function. */
11119 if (p
> (limit
- 4))
11123 warn (_("Too many rows/columns in DWARF index section %s\n"),
11128 SAFE_BYTE_GET (val
, p
, 4, limit
);
11131 printf (" %8d", val
);
11135 SAFE_BYTE_GET (dw_sect
, p
, 4, limit
);
11136 if (dw_sect
>= DW_SECT_MAX
)
11137 warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect
);
11139 this_set
[row
- 1].section_sizes
[dw_sect
] = val
;
11151 else if (do_display
)
11152 printf (_(" Unsupported version (%d)\n"), version
);
11160 static int cu_tu_indexes_read
= -1; /* Tri-state variable. */
11162 /* Load the CU and TU indexes if present. This will build a list of
11163 section sets that we can use to associate a .debug_info.dwo section
11164 with its associated .debug_abbrev.dwo section in a .dwp file. */
11167 load_cu_tu_indexes (void *file
)
11169 /* If we have already loaded (or tried to load) the CU and TU indexes
11170 then do not bother to repeat the task. */
11171 if (cu_tu_indexes_read
== -1)
11173 cu_tu_indexes_read
= true;
11175 if (load_debug_section_with_follow (dwp_cu_index
, file
))
11176 if (! process_cu_tu_index (&debug_displays
[dwp_cu_index
].section
, 0))
11177 cu_tu_indexes_read
= false;
11179 if (load_debug_section_with_follow (dwp_tu_index
, file
))
11180 if (! process_cu_tu_index (&debug_displays
[dwp_tu_index
].section
, 0))
11181 cu_tu_indexes_read
= false;
11184 return (bool) cu_tu_indexes_read
;
11187 /* Find the set of sections that includes section SHNDX. */
11190 find_cu_tu_set (void *file
, unsigned int shndx
)
11194 if (! load_cu_tu_indexes (file
))
11197 /* Find SHNDX in the shndx pool. */
11198 for (i
= 0; i
< shndx_pool_used
; i
++)
11199 if (shndx_pool
[i
] == shndx
)
11202 if (i
>= shndx_pool_used
)
11205 /* Now backup to find the first entry in the set. */
11206 while (i
> 0 && shndx_pool
[i
- 1] != 0)
11209 return shndx_pool
+ i
;
11212 /* Display a .debug_cu_index or .debug_tu_index section. */
11215 display_cu_index (struct dwarf_section
*section
, void *file ATTRIBUTE_UNUSED
)
11217 return process_cu_tu_index (section
, 1);
11221 display_debug_not_supported (struct dwarf_section
*section
,
11222 void *file ATTRIBUTE_UNUSED
)
11224 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
11230 /* Like malloc, but takes two parameters like calloc.
11231 Verifies that the first parameter is not too large.
11232 Note: does *not* initialise the allocated memory to zero. */
11235 cmalloc (uint64_t nmemb
, size_t size
)
11237 /* Check for overflow. */
11238 if (nmemb
>= ~(size_t) 0 / size
)
11241 return xmalloc (nmemb
* size
);
11244 /* Like xmalloc, but takes two parameters like calloc.
11245 Verifies that the first parameter is not too large.
11246 Note: does *not* initialise the allocated memory to zero. */
11249 xcmalloc (uint64_t nmemb
, size_t size
)
11251 /* Check for overflow. */
11252 if (nmemb
>= ~(size_t) 0 / size
)
11255 _("Attempt to allocate an array with an excessive number of elements: %#" PRIx64
"\n"),
11260 return xmalloc (nmemb
* size
);
11263 /* Like xrealloc, but takes three parameters.
11264 Verifies that the second parameter is not too large.
11265 Note: does *not* initialise any new memory to zero. */
11268 xcrealloc (void *ptr
, uint64_t nmemb
, size_t size
)
11270 /* Check for overflow. */
11271 if (nmemb
>= ~(size_t) 0 / size
)
11273 error (_("Attempt to re-allocate an array with an excessive number of elements: %#" PRIx64
"\n"),
11278 return xrealloc (ptr
, nmemb
* size
);
11281 /* Like xcalloc, but verifies that the first parameter is not too large. */
11284 xcalloc2 (uint64_t nmemb
, size_t size
)
11286 /* Check for overflow. */
11287 if (nmemb
>= ~(size_t) 0 / size
)
11289 error (_("Attempt to allocate a zero'ed array with an excessive number of elements: %#" PRIx64
"\n"),
11294 return xcalloc (nmemb
, size
);
11297 static unsigned long
11298 calc_gnu_debuglink_crc32 (unsigned long crc
,
11299 const unsigned char *buf
,
11302 static const unsigned long crc32_table
[256] =
11304 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
11305 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
11306 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
11307 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
11308 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
11309 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
11310 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
11311 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
11312 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
11313 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
11314 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
11315 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
11316 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
11317 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
11318 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
11319 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
11320 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
11321 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
11322 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
11323 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
11324 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
11325 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
11326 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
11327 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
11328 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
11329 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
11330 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
11331 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
11332 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
11333 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
11334 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
11335 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
11336 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
11337 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
11338 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
11339 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
11340 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
11341 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
11342 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
11343 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
11344 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
11345 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
11346 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
11347 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
11348 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
11349 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
11350 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
11351 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
11352 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
11353 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
11354 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
11357 const unsigned char *end
;
11359 crc
= ~crc
& 0xffffffff;
11360 for (end
= buf
+ len
; buf
< end
; ++ buf
)
11361 crc
= crc32_table
[(crc
^ *buf
) & 0xff] ^ (crc
>> 8);
11362 return ~crc
& 0xffffffff;
11365 typedef bool (*check_func_type
) (const char *, void *);
11366 typedef const char *(* parse_func_type
) (struct dwarf_section
*, void *);
11369 check_gnu_debuglink (const char * pathname
, void * crc_pointer
)
11371 static unsigned char buffer
[8 * 1024];
11374 unsigned long crc
= 0;
11377 sep_data
= open_debug_file (pathname
);
11378 if (sep_data
== NULL
)
11381 /* Yes - we are opening the file twice... */
11382 f
= fopen (pathname
, "rb");
11385 /* Paranoia: This should never happen. */
11386 close_debug_file (sep_data
);
11387 warn (_("Unable to reopen separate debug info file: %s\n"), pathname
);
11391 while ((count
= fread (buffer
, 1, sizeof (buffer
), f
)) > 0)
11392 crc
= calc_gnu_debuglink_crc32 (crc
, buffer
, count
);
11396 if (crc
!= * (unsigned long *) crc_pointer
)
11398 close_debug_file (sep_data
);
11399 warn (_("Separate debug info file %s found, but CRC does not match - ignoring\n"),
11407 static const char *
11408 parse_gnu_debuglink (struct dwarf_section
* section
, void * data
)
11411 unsigned int crc_offset
;
11412 unsigned long * crc32
= (unsigned long *) data
;
11414 /* The name is first.
11415 The CRC value is stored after the filename, aligned up to 4 bytes. */
11416 name
= (const char *) section
->start
;
11418 crc_offset
= strnlen (name
, section
->size
) + 1;
11419 if (crc_offset
== 1)
11421 crc_offset
= (crc_offset
+ 3) & ~3;
11422 if (crc_offset
+ 4 > section
->size
)
11425 * crc32
= byte_get (section
->start
+ crc_offset
, 4);
11430 check_gnu_debugaltlink (const char * filename
, void * data ATTRIBUTE_UNUSED
)
11432 void * sep_data
= open_debug_file (filename
);
11434 if (sep_data
== NULL
)
11437 /* FIXME: We should now extract the build-id in the separate file
11443 typedef struct build_id_data
11446 const unsigned char *data
;
11449 static const char *
11450 parse_gnu_debugaltlink (struct dwarf_section
* section
, void * data
)
11455 Build_id_data
*build_id_data
;
11457 /* The name is first.
11458 The build-id follows immediately, with no padding, up to the section's end. */
11460 name
= (const char *) section
->start
;
11461 namelen
= strnlen (name
, section
->size
) + 1;
11464 if (namelen
>= section
->size
)
11467 id_len
= section
->size
- namelen
;
11471 build_id_data
= (Build_id_data
*) data
;
11472 build_id_data
->len
= id_len
;
11473 build_id_data
->data
= section
->start
+ namelen
;
11479 add_separate_debug_file (const char * filename
, void * handle
)
11481 separate_info
* i
= xmalloc (sizeof * i
);
11483 i
->filename
= filename
;
11484 i
->handle
= handle
;
11485 i
->next
= first_separate_info
;
11486 first_separate_info
= i
;
11489 #if HAVE_LIBDEBUGINFOD
11490 /* Query debuginfod servers for the target debuglink or debugaltlink
11491 file. If successful, store the path of the file in filename and
11492 return TRUE, otherwise return FALSE. */
11495 debuginfod_fetch_separate_debug_info (struct dwarf_section
* section
,
11499 size_t build_id_len
;
11500 unsigned char * build_id
;
11502 if (strcmp (section
->uncompressed_name
, ".gnu_debuglink") == 0)
11504 /* Get the build-id of file. */
11505 build_id
= get_build_id (file
);
11508 else if (strcmp (section
->uncompressed_name
, ".gnu_debugaltlink") == 0)
11510 /* Get the build-id of the debugaltlink file. */
11511 unsigned int filelen
;
11513 filelen
= strnlen ((const char *)section
->start
, section
->size
);
11514 if (filelen
== section
->size
)
11515 /* Corrupt debugaltlink. */
11518 build_id
= section
->start
+ filelen
+ 1;
11519 build_id_len
= section
->size
- (filelen
+ 1);
11521 if (build_id_len
== 0)
11530 debuginfod_client
* client
;
11532 client
= debuginfod_begin ();
11533 if (client
== NULL
)
11536 /* Query debuginfod servers for the target file. If found its path
11537 will be stored in filename. */
11538 fd
= debuginfod_find_debuginfo (client
, build_id
, build_id_len
, filename
);
11539 debuginfod_end (client
);
11541 /* Only free build_id if we allocated space for a hex string
11542 in get_build_id (). */
11543 if (build_id_len
== 0)
11548 /* File successfully retrieved. Close fd since we want to
11549 use open_debug_file () on filename instead. */
11557 #endif /* HAVE_LIBDEBUGINFOD */
11560 load_separate_debug_info (const char * main_filename
,
11561 struct dwarf_section
* xlink
,
11562 parse_func_type parse_func
,
11563 check_func_type check_func
,
11565 void * file ATTRIBUTE_UNUSED
)
11567 const char * separate_filename
;
11568 char * debug_filename
;
11570 size_t canon_dirlen
;
11572 char * canon_filename
;
11573 char * canon_debug_filename
;
11576 if ((separate_filename
= parse_func (xlink
, func_data
)) == NULL
)
11578 warn (_("Corrupt debuglink section: %s\n"),
11579 xlink
->name
? xlink
->name
: xlink
->uncompressed_name
);
11583 /* Attempt to locate the separate file.
11584 This should duplicate the logic in bfd/opncls.c:find_separate_debug_file(). */
11586 canon_filename
= lrealpath (main_filename
);
11587 canon_dir
= xstrdup (canon_filename
);
11589 for (canon_dirlen
= strlen (canon_dir
); canon_dirlen
> 0; canon_dirlen
--)
11590 if (IS_DIR_SEPARATOR (canon_dir
[canon_dirlen
- 1]))
11592 canon_dir
[canon_dirlen
] = '\0';
11595 #define DEBUGDIR "/lib/debug"
11597 #ifndef EXTRA_DEBUG_ROOT1
11598 #define EXTRA_DEBUG_ROOT1 "/usr/lib/debug"
11600 #ifndef EXTRA_DEBUG_ROOT2
11601 #define EXTRA_DEBUG_ROOT2 "/usr/lib/debug/usr"
11604 debug_filename
= (char *) malloc (strlen (DEBUGDIR
) + 1
11606 + strlen (".debug/")
11607 #ifdef EXTRA_DEBUG_ROOT1
11608 + strlen (EXTRA_DEBUG_ROOT1
)
11610 #ifdef EXTRA_DEBUG_ROOT2
11611 + strlen (EXTRA_DEBUG_ROOT2
)
11613 + strlen (separate_filename
)
11615 if (debug_filename
== NULL
)
11617 warn (_("Out of memory"));
11619 free (canon_filename
);
11623 /* First try in the current directory. */
11624 sprintf (debug_filename
, "%s", separate_filename
);
11625 if (check_func (debug_filename
, func_data
))
11628 /* Then try in a subdirectory called .debug. */
11629 sprintf (debug_filename
, ".debug/%s", separate_filename
);
11630 if (check_func (debug_filename
, func_data
))
11633 /* Then try in the same directory as the original file. */
11634 sprintf (debug_filename
, "%s%s", canon_dir
, separate_filename
);
11635 if (check_func (debug_filename
, func_data
))
11638 /* And the .debug subdirectory of that directory. */
11639 sprintf (debug_filename
, "%s.debug/%s", canon_dir
, separate_filename
);
11640 if (check_func (debug_filename
, func_data
))
11643 #ifdef EXTRA_DEBUG_ROOT1
11644 /* Try the first extra debug file root. */
11645 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT1
, separate_filename
);
11646 if (check_func (debug_filename
, func_data
))
11649 /* Try the first extra debug file root. */
11650 sprintf (debug_filename
, "%s/%s/%s", EXTRA_DEBUG_ROOT1
, canon_dir
, separate_filename
);
11651 if (check_func (debug_filename
, func_data
))
11655 #ifdef EXTRA_DEBUG_ROOT2
11656 /* Try the second extra debug file root. */
11657 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT2
, separate_filename
);
11658 if (check_func (debug_filename
, func_data
))
11662 /* Then try in the global debug_filename directory. */
11663 strcpy (debug_filename
, DEBUGDIR
);
11664 dirlen
= strlen (DEBUGDIR
) - 1;
11665 if (dirlen
> 0 && DEBUGDIR
[dirlen
] != '/')
11666 strcat (debug_filename
, "/");
11667 strcat (debug_filename
, (const char *) separate_filename
);
11669 if (check_func (debug_filename
, func_data
))
11672 #if HAVE_LIBDEBUGINFOD
11674 char * tmp_filename
;
11677 && debuginfod_fetch_separate_debug_info (xlink
,
11681 /* File successfully downloaded from server, replace
11682 debug_filename with the file's path. */
11683 free (debug_filename
);
11684 debug_filename
= tmp_filename
;
11690 if (do_debug_links
)
11692 /* Failed to find the file. */
11693 warn (_("could not find separate debug file '%s'\n"),
11694 separate_filename
);
11695 warn (_("tried: %s\n"), debug_filename
);
11697 #ifdef EXTRA_DEBUG_ROOT2
11698 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT2
,
11699 separate_filename
);
11700 warn (_("tried: %s\n"), debug_filename
);
11703 #ifdef EXTRA_DEBUG_ROOT1
11704 sprintf (debug_filename
, "%s/%s/%s", EXTRA_DEBUG_ROOT1
,
11705 canon_dir
, separate_filename
);
11706 warn (_("tried: %s\n"), debug_filename
);
11708 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT1
,
11709 separate_filename
);
11710 warn (_("tried: %s\n"), debug_filename
);
11713 sprintf (debug_filename
, "%s.debug/%s", canon_dir
,
11714 separate_filename
);
11715 warn (_("tried: %s\n"), debug_filename
);
11717 sprintf (debug_filename
, "%s%s", canon_dir
, separate_filename
);
11718 warn (_("tried: %s\n"), debug_filename
);
11720 sprintf (debug_filename
, ".debug/%s", separate_filename
);
11721 warn (_("tried: %s\n"), debug_filename
);
11723 sprintf (debug_filename
, "%s", separate_filename
);
11724 warn (_("tried: %s\n"), debug_filename
);
11726 #if HAVE_LIBDEBUGINFOD
11727 if (use_debuginfod
)
11729 char *urls
= getenv (DEBUGINFOD_URLS_ENV_VAR
);
11734 warn (_("tried: DEBUGINFOD_URLS=%s\n"), urls
);
11740 free (debug_filename
);
11741 free (canon_filename
);
11747 canon_debug_filename
= lrealpath (debug_filename
);
11748 self
= strcmp (canon_debug_filename
, canon_filename
) == 0;
11749 free (canon_filename
);
11750 free (canon_debug_filename
);
11753 free (debug_filename
);
11757 void * debug_handle
;
11759 /* Now open the file.... */
11760 if ((debug_handle
= open_debug_file (debug_filename
)) == NULL
)
11762 warn (_("failed to open separate debug file: %s\n"), debug_filename
);
11763 free (debug_filename
);
11767 /* FIXME: We do not check to see if there are any other separate debug info
11768 files that would also match. */
11770 if (do_debug_links
)
11771 printf (_("\n%s: Found separate debug info file: %s\n"), main_filename
, debug_filename
);
11772 add_separate_debug_file (debug_filename
, debug_handle
);
11774 /* Do not free debug_filename - it might be referenced inside
11775 the structure returned by open_debug_file(). */
11776 return debug_handle
;
11779 /* Attempt to load a separate dwarf object file. */
11782 load_dwo_file (const char * main_filename
, const char * name
, const char * dir
, const char * id ATTRIBUTE_UNUSED
)
11784 char * separate_filename
;
11785 void * separate_handle
;
11787 if (IS_ABSOLUTE_PATH (name
))
11788 separate_filename
= strdup (name
);
11790 /* FIXME: Skip adding / if dwo_dir ends in /. */
11791 separate_filename
= concat (dir
, "/", name
, NULL
);
11792 if (separate_filename
== NULL
)
11794 warn (_("Out of memory allocating dwo filename\n"));
11798 if ((separate_handle
= open_debug_file (separate_filename
)) == NULL
)
11800 warn (_("Unable to load dwo file: %s\n"), separate_filename
);
11801 free (separate_filename
);
11805 /* FIXME: We should check the dwo_id. */
11807 printf (_("%s: Found separate debug object file: %s\n\n"), main_filename
, separate_filename
);
11809 add_separate_debug_file (separate_filename
, separate_handle
);
11810 /* Note - separate_filename will be freed in free_debug_memory(). */
11811 return separate_handle
;
11815 try_build_id_prefix (const char * prefix
, char * filename
, const unsigned char * data
, unsigned long id_len
)
11817 char * f
= filename
;
11819 f
+= sprintf (f
, "%s.build-id/%02x/", prefix
, (unsigned) *data
++);
11822 f
+= sprintf (f
, "%02x", (unsigned) *data
++);
11823 strcpy (f
, ".debug");
11825 return open_debug_file (filename
);
11828 /* Try to load a debug file based upon the build-id held in the .note.gnu.build-id section. */
11831 load_build_id_debug_file (const char * main_filename ATTRIBUTE_UNUSED
, void * main_file
)
11833 if (! load_debug_section (note_gnu_build_id
, main_file
))
11834 return; /* No .note.gnu.build-id section. */
11836 struct dwarf_section
* section
= & debug_displays
[note_gnu_build_id
].section
;
11837 if (section
== NULL
)
11839 warn (_("Unable to load the .note.gnu.build-id section\n"));
11843 if (section
->start
== NULL
|| section
->size
< 0x18)
11845 warn (_(".note.gnu.build-id section is corrupt/empty\n"));
11849 /* In theory we should extract the contents of the section into
11850 a note structure and then check the fields. For now though
11851 just use hard coded offsets instead:
11853 Field Bytes Contents
11856 Type 8..11 3 (NT_GNU_BUILD_ID)
11860 /* FIXME: Check the name size, name and type fields. */
11862 unsigned long build_id_size
;
11863 build_id_size
= byte_get (section
->start
+ 4, 4);
11864 if (build_id_size
< 8)
11866 warn (_(".note.gnu.build-id data size is too small\n"));
11870 if (build_id_size
> (section
->size
- 16))
11872 warn (_(".note.gnu.build-id data size is too big\n"));
11877 filename
= xmalloc (strlen (".build-id/")
11878 + build_id_size
* 2 + 2
11879 + strlen (".debug")
11880 /* The next string should be the same as the longest
11881 name found in the prefixes[] array below. */
11882 + strlen ("/usrlib64/debug/usr")
11886 static const char * prefixes
[] =
11891 "/usr/lib/debug/usr/",
11892 "/usr/lib64/debug/",
11893 "/usr/lib64/debug/usr"
11895 long unsigned int i
;
11897 for (i
= 0; i
< ARRAY_SIZE (prefixes
); i
++)
11899 handle
= try_build_id_prefix (prefixes
[i
], filename
,
11900 section
->start
+ 16, build_id_size
);
11901 if (handle
!= NULL
)
11904 /* FIXME: TYhe BFD library also tries a global debugfile directory prefix. */
11905 if (handle
== NULL
)
11907 /* Failed to find a debug file associated with the build-id.
11908 This is not an error however, rather it just means that
11909 the debug info has probably not been loaded on the system,
11910 or that another method is being used to link to the debug
11916 add_separate_debug_file (filename
, handle
);
11919 /* Try to load a debug file pointed to by the .debug_sup section. */
11922 load_debug_sup_file (const char * main_filename
, void * file
)
11924 if (! load_debug_section (debug_sup
, file
))
11925 return; /* No .debug_sup section. */
11927 struct dwarf_section
* section
;
11928 section
= & debug_displays
[debug_sup
].section
;
11929 assert (section
!= NULL
);
11931 if (section
->start
== NULL
|| section
->size
< 5)
11933 warn (_(".debug_sup section is corrupt/empty\n"));
11937 if (section
->start
[2] != 0)
11938 return; /* This is a supplementary file. */
11940 const char * filename
= (const char *) section
->start
+ 3;
11941 if (strnlen (filename
, section
->size
- 3) == section
->size
- 3)
11943 warn (_("filename in .debug_sup section is corrupt\n"));
11947 if (filename
[0] != '/' && strchr (main_filename
, '/'))
11952 new_len
= asprintf (& new_name
, "%.*s/%s",
11953 (int) (strrchr (main_filename
, '/') - main_filename
),
11958 warn (_("unable to construct path for supplementary debug file"));
11963 filename
= new_name
;
11967 /* PR 27796: Make sure that we pass a filename that can be free'd to
11968 add_separate_debug_file(). */
11969 filename
= strdup (filename
);
11970 if (filename
== NULL
)
11972 warn (_("out of memory constructing filename for .debug_sup link\n"));
11977 void * handle
= open_debug_file (filename
);
11978 if (handle
== NULL
)
11980 warn (_("unable to open file '%s' referenced from .debug_sup section\n"), filename
);
11981 free ((void *) filename
);
11985 printf (_("%s: Found supplementary debug file: %s\n\n"), main_filename
, filename
);
11987 /* FIXME: Compare the checksums, if present. */
11988 add_separate_debug_file (filename
, handle
);
11991 /* Load a debuglink section and/or a debugaltlink section, if either are present.
11992 Recursively check the loaded files for more of these sections.
11993 Also follow any links in .debug_sup sections.
11994 FIXME: Should also check for DWO_* entries in the newly loaded files. */
11997 check_for_and_load_links (void * file
, const char * filename
)
11999 void * handle
= NULL
;
12001 if (load_debug_section (gnu_debugaltlink
, file
))
12003 Build_id_data build_id_data
;
12005 handle
= load_separate_debug_info (filename
,
12006 & debug_displays
[gnu_debugaltlink
].section
,
12007 parse_gnu_debugaltlink
,
12008 check_gnu_debugaltlink
,
12013 assert (handle
== first_separate_info
->handle
);
12014 check_for_and_load_links (first_separate_info
->handle
,
12015 first_separate_info
->filename
);
12019 if (load_debug_section (gnu_debuglink
, file
))
12021 unsigned long crc32
;
12023 handle
= load_separate_debug_info (filename
,
12024 & debug_displays
[gnu_debuglink
].section
,
12025 parse_gnu_debuglink
,
12026 check_gnu_debuglink
,
12031 assert (handle
== first_separate_info
->handle
);
12032 check_for_and_load_links (first_separate_info
->handle
,
12033 first_separate_info
->filename
);
12037 load_debug_sup_file (filename
, file
);
12039 load_build_id_debug_file (filename
, file
);
12042 /* Load the separate debug info file(s) attached to FILE, if any exist.
12043 Returns TRUE if any were found, FALSE otherwise.
12044 If TRUE is returned then the linked list starting at first_separate_info
12045 will be populated with open file handles. */
12048 load_separate_debug_files (void * file
, const char * filename
)
12050 /* Skip this operation if we are not interested in debug links. */
12051 if (! do_follow_links
&& ! do_debug_links
)
12054 /* See if there are any dwo links. */
12055 if (load_debug_section (str
, file
)
12056 && load_debug_section (abbrev
, file
)
12057 && load_debug_section (info
, file
))
12059 /* Load the .debug_addr section, if it exists. */
12060 load_debug_section (debug_addr
, file
);
12061 /* Load the .debug_str_offsets section, if it exists. */
12062 load_debug_section (str_index
, file
);
12063 /* Load the .debug_loclists section, if it exists. */
12064 load_debug_section (loclists
, file
);
12065 /* Load the .debug_rnglists section, if it exists. */
12066 load_debug_section (rnglists
, file
);
12070 if (process_debug_info (& debug_displays
[info
].section
, file
, abbrev
,
12073 bool introduced
= false;
12075 const char *dir
= NULL
;
12076 const char *id
= NULL
;
12077 const char *name
= NULL
;
12079 for (dwinfo
= first_dwo_info
; dwinfo
!= NULL
; dwinfo
= dwinfo
->next
)
12081 /* Accumulate NAME, DIR and ID fields. */
12082 switch (dwinfo
->type
)
12086 warn (_("Multiple DWO_NAMEs encountered for the same CU\n"));
12087 name
= dwinfo
->value
;
12091 /* There can be multiple DW_AT_comp_dir entries in a CU,
12092 so do not complain. */
12093 dir
= dwinfo
->value
;
12098 warn (_("multiple DWO_IDs encountered for the same CU\n"));
12099 id
= dwinfo
->value
;
12103 error (_("Unexpected DWO INFO type"));
12107 /* If we have reached the end of our list, or we are changing
12108 CUs, then display the information that we have accumulated
12111 && (dwinfo
->next
== NULL
12112 || dwinfo
->next
->cu_offset
!= dwinfo
->cu_offset
))
12114 if (do_debug_links
)
12118 printf (_("The %s section contains link(s) to dwo file(s):\n\n"),
12119 debug_displays
[info
].section
.uncompressed_name
);
12123 printf (_(" Name: %s\n"), name
);
12124 printf (_(" Directory: %s\n"), dir
? dir
: _("<not-found>"));
12126 display_data (printf (_(" ID: ")), (unsigned char *) id
, 8);
12127 else if (debug_information
[0].dwarf_version
!= 5)
12128 printf (_(" ID: <not specified>\n"));
12132 if (do_follow_links
)
12133 load_dwo_file (filename
, name
, dir
, id
);
12135 name
= dir
= id
= NULL
;
12141 if (! do_follow_links
)
12142 /* The other debug links will be displayed by display_debug_links()
12143 so we do not need to do any further processing here. */
12146 /* FIXME: We do not check for the presence of both link sections in the same file. */
12147 /* FIXME: We do not check for the presence of multiple, same-name debuglink sections. */
12148 /* FIXME: We do not check for the presence of a dwo link as well as a debuglink. */
12150 check_for_and_load_links (file
, filename
);
12151 if (first_separate_info
!= NULL
)
12154 do_follow_links
= 0;
12159 free_debug_memory (void)
12163 free_all_abbrevs ();
12167 shndx_pool_size
= 0;
12168 shndx_pool_used
= 0;
12176 memset (level_type_signed
, 0, sizeof level_type_signed
);
12177 cu_tu_indexes_read
= -1;
12179 for (i
= 0; i
< max
; i
++)
12180 free_debug_section ((enum dwarf_section_display_enum
) i
);
12182 if (debug_information
!= NULL
)
12184 for (i
= 0; i
< alloc_num_debug_info_entries
; i
++)
12185 free_debug_information (&debug_information
[i
]);
12186 free (debug_information
);
12187 debug_information
= NULL
;
12188 alloc_num_debug_info_entries
= num_debug_info_entries
= 0;
12192 separate_info
* next
;
12194 for (d
= first_separate_info
; d
!= NULL
; d
= next
)
12196 close_debug_file (d
->handle
);
12197 free ((void *) d
->filename
);
12201 first_separate_info
= NULL
;
12209 const char *option
;
12212 } debug_dump_long_opts
;
12214 static const debug_dump_long_opts debug_option_table
[] =
12216 { 'A', "addr", &do_debug_addr
, 1 },
12217 { 'a', "abbrev", &do_debug_abbrevs
, 1 },
12218 { 'c', "cu_index", &do_debug_cu_index
, 1 },
12219 #ifdef HAVE_LIBDEBUGINFOD
12220 { 'D', "use-debuginfod", &use_debuginfod
, 1 },
12221 { 'E', "do-not-use-debuginfod", &use_debuginfod
, 0 },
12223 { 'F', "frames-interp", &do_debug_frames_interp
, 1 },
12224 { 'f', "frames", &do_debug_frames
, 1 },
12225 { 'g', "gdb_index", &do_gdb_index
, 1 },
12226 { 'i', "info", &do_debug_info
, 1 },
12227 { 'K', "follow-links", &do_follow_links
, 1 },
12228 { 'k', "links", &do_debug_links
, 1 },
12229 { 'L', "decodedline", &do_debug_lines
, FLAG_DEBUG_LINES_DECODED
},
12230 { 'l', "rawline", &do_debug_lines
, FLAG_DEBUG_LINES_RAW
},
12231 /* For compatibility with earlier versions of readelf. */
12232 { 'l', "line", &do_debug_lines
, FLAG_DEBUG_LINES_RAW
},
12233 { 'm', "macro", &do_debug_macinfo
, 1 },
12234 { 'N', "no-follow-links", &do_follow_links
, 0 },
12235 { 'O', "str-offsets", &do_debug_str_offsets
, 1 },
12236 { 'o', "loc", &do_debug_loc
, 1 },
12237 { 'p', "pubnames", &do_debug_pubnames
, 1 },
12238 { 'R', "Ranges", &do_debug_ranges
, 1 },
12239 { 'r', "aranges", &do_debug_aranges
, 1 },
12240 /* For compatibility with earlier versions of readelf. */
12241 { 'r', "ranges", &do_debug_aranges
, 1 },
12242 { 's', "str", &do_debug_str
, 1 },
12243 { 'T', "trace_aranges", &do_trace_aranges
, 1 },
12244 { 't', "pubtypes", &do_debug_pubtypes
, 1 },
12245 { 'U', "trace_info", &do_trace_info
, 1 },
12246 { 'u', "trace_abbrev", &do_trace_abbrevs
, 1 },
12247 { 0, NULL
, NULL
, 0 }
12250 /* Enable display of specific DWARF sections as determined by the comma
12251 separated strings in NAMES. Returns non-zero if any displaying was
12255 dwarf_select_sections_by_names (const char *names
)
12263 const debug_dump_long_opts
*entry
;
12265 for (entry
= debug_option_table
; entry
->option
; entry
++)
12267 size_t len
= strlen (entry
->option
);
12269 if (strncmp (p
, entry
->option
, len
) == 0
12270 && (p
[len
] == ',' || p
[len
] == '\0'))
12272 if (entry
->val
== 0)
12273 * entry
->variable
= 0;
12275 * entry
->variable
= entry
->val
;
12276 result
|= entry
->val
;
12283 if (entry
->option
== NULL
)
12285 warn (_("Unrecognized debug option '%s'\n"), p
);
12286 p
= strchr (p
, ',');
12295 /* The --debug-dump=frames-interp option also enables the
12296 --debug-dump=frames option. */
12297 if (do_debug_frames_interp
)
12298 do_debug_frames
= 1;
12303 /* Enable display of specific DWARF sections as determined by the characters
12304 in LETTERS. Returns non-zero if any displaying was enabled. */
12307 dwarf_select_sections_by_letters (const char *letters
)
12313 const debug_dump_long_opts
*entry
;
12315 for (entry
= debug_option_table
; entry
->letter
; entry
++)
12317 if (entry
->letter
== * letters
)
12319 if (entry
->val
== 0)
12320 * entry
->variable
= 0;
12322 * entry
->variable
|= entry
->val
;
12323 result
|= entry
->val
;
12328 if (entry
->letter
== 0)
12329 warn (_("Unrecognized debug letter option '%c'\n"), * letters
);
12334 /* The --debug-dump=frames-interp option also enables the
12335 --debug-dump=frames option. */
12336 if (do_debug_frames_interp
)
12337 do_debug_frames
= 1;
12343 dwarf_select_sections_all (void)
12346 do_debug_abbrevs
= 1;
12347 do_debug_lines
= FLAG_DEBUG_LINES_RAW
;
12348 do_debug_pubnames
= 1;
12349 do_debug_pubtypes
= 1;
12350 do_debug_aranges
= 1;
12351 do_debug_ranges
= 1;
12352 do_debug_frames
= 1;
12353 do_debug_macinfo
= 1;
12358 do_trace_abbrevs
= 1;
12359 do_trace_aranges
= 1;
12361 do_debug_cu_index
= 1;
12362 do_follow_links
= 1;
12363 do_debug_links
= 1;
12364 do_debug_str_offsets
= 1;
12367 #define NO_ABBREVS NULL, NULL, NULL, 0, 0, 0, NULL, 0
12368 #define ABBREV(N) NULL, NULL, NULL, 0, 0, N, NULL, 0
12370 /* N.B. The order here must match the order in section_display_enum. */
12372 struct dwarf_section_display debug_displays
[] =
12374 { { ".debug_abbrev", ".zdebug_abbrev", ".dwabrev", NO_ABBREVS
}, display_debug_abbrev
, &do_debug_abbrevs
, false },
12375 { { ".debug_aranges", ".zdebug_aranges", ".dwarnge", NO_ABBREVS
}, display_debug_aranges
, &do_debug_aranges
, true },
12376 { { ".debug_frame", ".zdebug_frame", ".dwframe", NO_ABBREVS
}, display_debug_frames
, &do_debug_frames
, true },
12377 { { ".debug_info", ".zdebug_info", ".dwinfo", ABBREV (abbrev
)}, display_debug_info
, &do_debug_info
, true },
12378 { { ".debug_line", ".zdebug_line", ".dwline", NO_ABBREVS
}, display_debug_lines
, &do_debug_lines
, true },
12379 { { ".debug_pubnames", ".zdebug_pubnames", ".dwpbnms", NO_ABBREVS
}, display_debug_pubnames
, &do_debug_pubnames
, false },
12380 { { ".debug_gnu_pubnames", ".zdebug_gnu_pubnames", "", NO_ABBREVS
}, display_debug_gnu_pubnames
, &do_debug_pubnames
, false },
12381 { { ".eh_frame", "", "", NO_ABBREVS
}, display_debug_frames
, &do_debug_frames
, true },
12382 { { ".debug_macinfo", ".zdebug_macinfo", "", NO_ABBREVS
}, display_debug_macinfo
, &do_debug_macinfo
, false },
12383 { { ".debug_macro", ".zdebug_macro", ".dwmac", NO_ABBREVS
}, display_debug_macro
, &do_debug_macinfo
, true },
12384 { { ".debug_str", ".zdebug_str", ".dwstr", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, false },
12385 { { ".debug_line_str", ".zdebug_line_str", "", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, false },
12386 { { ".debug_loc", ".zdebug_loc", ".dwloc", NO_ABBREVS
}, display_debug_loc
, &do_debug_loc
, true },
12387 { { ".debug_loclists", ".zdebug_loclists", "", NO_ABBREVS
}, display_debug_loc
, &do_debug_loc
, true },
12388 { { ".debug_loclists.dwo", ".zdebug_loclists.dwo", "", NO_ABBREVS
}, display_debug_loc
, &do_debug_loc
, true },
12389 { { ".debug_pubtypes", ".zdebug_pubtypes", ".dwpbtyp", NO_ABBREVS
}, display_debug_pubnames
, &do_debug_pubtypes
, false },
12390 { { ".debug_gnu_pubtypes", ".zdebug_gnu_pubtypes", "", NO_ABBREVS
}, display_debug_gnu_pubnames
, &do_debug_pubtypes
, false },
12391 { { ".debug_ranges", ".zdebug_ranges", ".dwrnges", NO_ABBREVS
}, display_debug_ranges
, &do_debug_ranges
, true },
12392 { { ".debug_rnglists", ".zdebug_rnglists", "", NO_ABBREVS
}, display_debug_ranges
, &do_debug_ranges
, true },
12393 { { ".debug_rnglists.dwo", ".zdebug_rnglists.dwo", "", NO_ABBREVS
}, display_debug_ranges
, &do_debug_ranges
, true },
12394 { { ".debug_static_func", ".zdebug_static_func", "", NO_ABBREVS
}, display_debug_not_supported
, NULL
, false },
12395 { { ".debug_static_vars", ".zdebug_static_vars", "", NO_ABBREVS
}, display_debug_not_supported
, NULL
, false },
12396 { { ".debug_types", ".zdebug_types", "", ABBREV (abbrev
) }, display_debug_types
, &do_debug_info
, true },
12397 { { ".debug_weaknames", ".zdebug_weaknames", "", NO_ABBREVS
}, display_debug_not_supported
, NULL
, false },
12398 { { ".gdb_index", "", "", NO_ABBREVS
}, display_gdb_index
, &do_gdb_index
, false },
12399 { { ".debug_names", "", "", NO_ABBREVS
}, display_debug_names
, &do_gdb_index
, false },
12400 { { ".trace_info", "", "", ABBREV (trace_abbrev
) }, display_trace_info
, &do_trace_info
, true },
12401 { { ".trace_abbrev", "", "", NO_ABBREVS
}, display_debug_abbrev
, &do_trace_abbrevs
, false },
12402 { { ".trace_aranges", "", "", NO_ABBREVS
}, display_debug_aranges
, &do_trace_aranges
, false },
12403 { { ".debug_info.dwo", ".zdebug_info.dwo", "", ABBREV (abbrev_dwo
) }, display_debug_info
, &do_debug_info
, true },
12404 { { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo", "", NO_ABBREVS
}, display_debug_abbrev
, &do_debug_abbrevs
, false },
12405 { { ".debug_types.dwo", ".zdebug_types.dwo", "", ABBREV (abbrev_dwo
) }, display_debug_types
, &do_debug_info
, true },
12406 { { ".debug_line.dwo", ".zdebug_line.dwo", "", NO_ABBREVS
}, display_debug_lines
, &do_debug_lines
, true },
12407 { { ".debug_loc.dwo", ".zdebug_loc.dwo", "", NO_ABBREVS
}, display_debug_loc
, &do_debug_loc
, true },
12408 { { ".debug_macro.dwo", ".zdebug_macro.dwo", "", NO_ABBREVS
}, display_debug_macro
, &do_debug_macinfo
, true },
12409 { { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo", "", NO_ABBREVS
}, display_debug_macinfo
, &do_debug_macinfo
, false },
12410 { { ".debug_str.dwo", ".zdebug_str.dwo", "", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, true },
12411 { { ".debug_str_offsets", ".zdebug_str_offsets", "", NO_ABBREVS
}, display_debug_str_offsets
, &do_debug_str_offsets
, true },
12412 { { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo", "", NO_ABBREVS
}, display_debug_str_offsets
, &do_debug_str_offsets
, true },
12413 { { ".debug_addr", ".zdebug_addr", "", NO_ABBREVS
}, display_debug_addr
, &do_debug_addr
, true },
12414 { { ".debug_cu_index", "", "", NO_ABBREVS
}, display_cu_index
, &do_debug_cu_index
, false },
12415 { { ".debug_tu_index", "", "", NO_ABBREVS
}, display_cu_index
, &do_debug_cu_index
, false },
12416 { { ".gnu_debuglink", "", "", NO_ABBREVS
}, display_debug_links
, &do_debug_links
, false },
12417 { { ".gnu_debugaltlink", "", "", NO_ABBREVS
}, display_debug_links
, &do_debug_links
, false },
12418 { { ".debug_sup", "", "", NO_ABBREVS
}, display_debug_sup
, &do_debug_links
, false },
12419 /* Separate debug info files can containt their own .debug_str section,
12420 and this might be in *addition* to a .debug_str section already present
12421 in the main file. Hence we need to have two entries for .debug_str. */
12422 { { ".debug_str", ".zdebug_str", "", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, false },
12423 { { ".note.gnu.build-id", "", "", NO_ABBREVS
}, display_debug_not_supported
, NULL
, false },
12426 /* A static assertion. */
12427 extern int debug_displays_assert
[ARRAY_SIZE (debug_displays
) == max
? 1 : -1];