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 index_offset
= idx
* offset_size
;
664 if (this_set
!= NULL
)
665 index_offset
+= this_set
->section_offsets
[DW_SECT_STR_OFFSETS
];
667 index_offset
+= str_offsets_base
;
669 if (index_offset
+ offset_size
> index_section
->size
)
671 warn (_("string index of %" PRIu64
" converts to an offset of %#" PRIx64
672 " which is too big for section %s"),
673 idx
, index_offset
, str_section
->name
);
675 return _("<string index too big>");
678 /* FIXME: If we are being paranoid then we should also check to see if
679 IDX references an entry beyond the end of the string table pointed to
680 by STR_OFFSETS_BASE. (Since there can be more than one string table
681 in a DWARF string section). */
683 str_offset
= byte_get (index_section
->start
+ index_offset
, offset_size
);
685 str_offset
-= str_section
->address
;
686 if (str_offset
>= str_section
->size
)
688 warn (_("indirect offset too big: %#" PRIx64
"\n"), str_offset
);
689 return _("<indirect index offset is too big>");
692 ret
= (const char *) str_section
->start
+ str_offset
;
694 /* Unfortunately we cannot rely upon str_section ending with a NUL byte.
695 Since our caller is expecting to receive a well formed C string we test
696 for the lack of a terminating byte here. */
697 if (strnlen (ret
, str_section
->size
- str_offset
)
698 == str_section
->size
- str_offset
)
699 return _("<no NUL byte at end of section>");
705 fetch_indexed_addr (uint64_t offset
, uint32_t num_bytes
)
707 struct dwarf_section
*section
= &debug_displays
[debug_addr
].section
;
709 if (section
->start
== NULL
)
711 warn (_("Cannot fetch indexed address: the .debug_addr section is missing\n"));
715 if (offset
+ num_bytes
> section
->size
)
717 warn (_("Offset into section %s too big: %#" PRIx64
"\n"),
718 section
->name
, offset
);
722 return byte_get (section
->start
+ offset
, num_bytes
);
725 /* Fetch a value from a debug section that has been indexed by
726 something in another section (eg DW_FORM_loclistx or DW_FORM_rnglistx).
727 Returns -1 if the value could not be found. */
730 fetch_indexed_value (uint64_t idx
,
731 enum dwarf_section_display_enum sec_enum
,
732 uint64_t base_address
)
734 struct dwarf_section
*section
= &debug_displays
[sec_enum
].section
;
736 if (section
->start
== NULL
)
738 warn (_("Unable to locate %s section\n"), section
->uncompressed_name
);
742 if (section
->size
< 4)
744 warn (_("Section %s is too small to contain an value indexed from another section!\n"),
749 uint32_t pointer_size
, bias
;
751 if (byte_get (section
->start
, 4) == 0xffffffff)
762 uint64_t offset
= idx
* pointer_size
;
764 /* Offsets are biased by the size of the section header
767 offset
+= base_address
;
771 if (offset
+ pointer_size
> section
->size
)
773 warn (_("Offset into section %s too big: %#" PRIx64
"\n"),
774 section
->name
, offset
);
778 return byte_get (section
->start
+ offset
, pointer_size
);
781 /* FIXME: There are better and more efficient ways to handle
782 these structures. For now though, I just want something that
783 is simple to implement. */
784 /* Records a single attribute in an abbrev. */
785 typedef struct abbrev_attr
787 unsigned long attribute
;
789 int64_t implicit_const
;
790 struct abbrev_attr
*next
;
794 /* Records a single abbrev. */
795 typedef struct abbrev_entry
797 unsigned long number
;
800 struct abbrev_attr
* first_attr
;
801 struct abbrev_attr
* last_attr
;
802 struct abbrev_entry
* next
;
806 /* Records a set of abbreviations. */
807 typedef struct abbrev_list
809 abbrev_entry
* first_abbrev
;
810 abbrev_entry
* last_abbrev
;
812 struct abbrev_list
* next
;
813 unsigned char * start_of_next_abbrevs
;
817 /* Records all the abbrevs found so far. */
818 static struct abbrev_list
* abbrev_lists
= NULL
;
820 typedef struct abbrev_map
827 /* Maps between CU offsets and abbrev sets. */
828 static abbrev_map
* cu_abbrev_map
= NULL
;
829 static unsigned long num_abbrev_map_entries
= 0;
830 static unsigned long next_free_abbrev_map_entry
= 0;
832 #define INITIAL_NUM_ABBREV_MAP_ENTRIES 8
833 #define ABBREV_MAP_ENTRIES_INCREMENT 8
836 record_abbrev_list_for_cu (uint64_t start
, uint64_t end
,
837 abbrev_list
*list
, abbrev_list
*free_list
)
839 if (free_list
!= NULL
)
841 list
->next
= abbrev_lists
;
845 if (cu_abbrev_map
== NULL
)
847 num_abbrev_map_entries
= INITIAL_NUM_ABBREV_MAP_ENTRIES
;
848 cu_abbrev_map
= xmalloc (num_abbrev_map_entries
* sizeof (* cu_abbrev_map
));
850 else if (next_free_abbrev_map_entry
== num_abbrev_map_entries
)
852 num_abbrev_map_entries
+= ABBREV_MAP_ENTRIES_INCREMENT
;
853 cu_abbrev_map
= xrealloc (cu_abbrev_map
, num_abbrev_map_entries
* sizeof (* cu_abbrev_map
));
856 cu_abbrev_map
[next_free_abbrev_map_entry
].start
= start
;
857 cu_abbrev_map
[next_free_abbrev_map_entry
].end
= end
;
858 cu_abbrev_map
[next_free_abbrev_map_entry
].list
= list
;
859 next_free_abbrev_map_entry
++;
863 free_abbrev_list (abbrev_list
*list
)
865 abbrev_entry
*abbrv
= list
->first_abbrev
;
869 abbrev_attr
*attr
= abbrv
->first_attr
;
873 abbrev_attr
*next_attr
= attr
->next
;
878 abbrev_entry
*next_abbrev
= abbrv
->next
;
883 abbrev_list
*next
= list
->next
;
889 free_all_abbrevs (void)
892 abbrev_lists
= free_abbrev_list (abbrev_lists
);
894 free (cu_abbrev_map
);
895 cu_abbrev_map
= NULL
;
896 next_free_abbrev_map_entry
= 0;
900 find_abbrev_list_by_raw_abbrev (unsigned char *raw
)
904 for (list
= abbrev_lists
; list
!= NULL
; list
= list
->next
)
905 if (list
->raw
== raw
)
911 /* Find the abbreviation map for the CU that includes OFFSET.
912 OFFSET is an absolute offset from the start of the .debug_info section. */
913 /* FIXME: This function is going to slow down readelf & objdump.
914 Not caching abbrevs is likely the answer. */
917 find_abbrev_map_by_offset (uint64_t offset
)
921 for (i
= 0; i
< next_free_abbrev_map_entry
; i
++)
922 if (cu_abbrev_map
[i
].start
<= offset
923 && cu_abbrev_map
[i
].end
> offset
)
924 return cu_abbrev_map
+ i
;
930 add_abbrev (unsigned long number
,
935 abbrev_entry
* entry
;
937 entry
= (abbrev_entry
*) xmalloc (sizeof (*entry
));
939 entry
->number
= number
;
941 entry
->children
= children
;
942 entry
->first_attr
= NULL
;
943 entry
->last_attr
= NULL
;
946 assert (list
!= NULL
);
948 if (list
->first_abbrev
== NULL
)
949 list
->first_abbrev
= entry
;
951 list
->last_abbrev
->next
= entry
;
953 list
->last_abbrev
= entry
;
957 add_abbrev_attr (unsigned long attribute
,
959 int64_t implicit_const
,
964 attr
= (abbrev_attr
*) xmalloc (sizeof (*attr
));
966 attr
->attribute
= attribute
;
968 attr
->implicit_const
= implicit_const
;
971 assert (list
!= NULL
&& list
->last_abbrev
!= NULL
);
973 if (list
->last_abbrev
->first_attr
== NULL
)
974 list
->last_abbrev
->first_attr
= attr
;
976 list
->last_abbrev
->last_attr
->next
= attr
;
978 list
->last_abbrev
->last_attr
= attr
;
981 /* Return processed (partial) contents of a .debug_abbrev section.
982 Returns NULL on errors. */
985 process_abbrev_set (struct dwarf_section
*section
,
986 unsigned char *start
,
989 abbrev_list
*list
= xmalloc (sizeof (*list
));
990 list
->first_abbrev
= NULL
;
991 list
->last_abbrev
= NULL
;
998 unsigned long attribute
;
1001 READ_ULEB (entry
, start
, end
);
1003 /* A single zero is supposed to end the set according
1004 to the standard. If there's more, then signal that to
1006 if (start
== end
|| entry
== 0)
1009 list
->start_of_next_abbrevs
= start
!= end
? start
: NULL
;
1013 READ_ULEB (tag
, start
, end
);
1020 children
= *start
++;
1022 add_abbrev (entry
, tag
, children
, list
);
1027 /* Initialize it due to a false compiler warning. */
1028 int64_t implicit_const
= -1;
1030 READ_ULEB (attribute
, start
, end
);
1034 READ_ULEB (form
, start
, end
);
1038 if (form
== DW_FORM_implicit_const
)
1040 READ_SLEB (implicit_const
, start
, end
);
1045 add_abbrev_attr (attribute
, form
, implicit_const
, list
);
1047 while (attribute
!= 0);
1050 /* Report the missing single zero which ends the section. */
1051 error (_("%s section not zero terminated\n"), section
->name
);
1057 /* Return a sequence of abbrevs in SECTION starting at ABBREV_BASE
1058 plus ABBREV_OFFSET and finishing at ABBREV_BASE + ABBREV_SIZE.
1059 If FREE_LIST is non-NULL search the already decoded abbrevs on
1060 abbrev_lists first and if found set *FREE_LIST to NULL. If
1061 searching doesn't find a matching abbrev, set *FREE_LIST to the
1062 newly allocated list. If FREE_LIST is NULL, no search is done and
1063 the returned abbrev_list is always newly allocated. */
1065 static abbrev_list
*
1066 find_and_process_abbrev_set (struct dwarf_section
*section
,
1067 uint64_t abbrev_base
,
1068 uint64_t abbrev_size
,
1069 uint64_t abbrev_offset
,
1070 abbrev_list
**free_list
)
1075 if (abbrev_base
>= section
->size
1076 || abbrev_size
> section
->size
- abbrev_base
)
1078 /* PR 17531: file:4bcd9ce9. */
1079 warn (_("Debug info is corrupted, abbrev size (%#" PRIx64
")"
1080 " is larger than abbrev section size (%#" PRIx64
")\n"),
1081 abbrev_base
+ abbrev_size
, section
->size
);
1084 if (abbrev_offset
>= abbrev_size
)
1086 warn (_("Debug info is corrupted, abbrev offset (%#" PRIx64
")"
1087 " is larger than abbrev section size (%#" PRIx64
")\n"),
1088 abbrev_offset
, abbrev_size
);
1092 unsigned char *start
= section
->start
+ abbrev_base
+ abbrev_offset
;
1093 unsigned char *end
= section
->start
+ abbrev_base
+ abbrev_size
;
1094 abbrev_list
*list
= NULL
;
1096 list
= find_abbrev_list_by_raw_abbrev (start
);
1099 list
= process_abbrev_set (section
, start
, end
);
1107 get_TAG_name (uint64_t tag
)
1109 const char *name
= NULL
;
1111 if ((unsigned int) tag
== tag
)
1112 name
= get_DW_TAG_name ((unsigned int) tag
);
1115 static char buffer
[100];
1117 if (tag
>= DW_TAG_lo_user
&& tag
<= DW_TAG_hi_user
)
1118 snprintf (buffer
, sizeof (buffer
),
1119 _("User TAG value: %#" PRIx64
), tag
);
1121 snprintf (buffer
, sizeof (buffer
),
1122 _("Unknown TAG value: %#" PRIx64
), tag
);
1130 get_FORM_name (unsigned long form
)
1132 const char *name
= NULL
;
1135 return "DW_FORM value: 0";
1137 if ((unsigned int) form
== form
)
1138 name
= get_DW_FORM_name ((unsigned int) form
);
1141 static char buffer
[100];
1143 snprintf (buffer
, sizeof (buffer
), _("Unknown FORM value: %lx"), form
);
1151 get_IDX_name (unsigned long idx
)
1153 const char *name
= NULL
;
1155 if ((unsigned int) idx
== idx
)
1156 name
= get_DW_IDX_name ((unsigned int) idx
);
1159 static char buffer
[100];
1161 snprintf (buffer
, sizeof (buffer
), _("Unknown IDX value: %lx"), idx
);
1168 static unsigned char *
1169 display_block (unsigned char *data
,
1171 const unsigned char * const end
, char delimiter
)
1175 printf (_("%c%" PRIu64
" byte block: "), delimiter
, length
);
1177 return (unsigned char *) end
;
1179 maxlen
= end
- data
;
1180 length
= length
> maxlen
? maxlen
: length
;
1183 printf ("%" PRIx64
" ", byte_get (data
++, 1));
1189 decode_location_expression (unsigned char * data
,
1190 unsigned int pointer_size
,
1191 unsigned int offset_size
,
1195 struct dwarf_section
* section
)
1200 unsigned char *end
= data
+ length
;
1201 int need_frame_base
= 0;
1210 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1211 printf ("DW_OP_addr: %" PRIx64
, uvalue
);
1214 printf ("DW_OP_deref");
1217 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1218 printf ("DW_OP_const1u: %" PRIu64
, uvalue
);
1221 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 1, end
);
1222 printf ("DW_OP_const1s: %" PRId64
, svalue
);
1225 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
1226 printf ("DW_OP_const2u: %" PRIu64
, uvalue
);
1229 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1230 printf ("DW_OP_const2s: %" PRId64
, svalue
);
1233 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1234 printf ("DW_OP_const4u: %" PRIu64
, uvalue
);
1237 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
1238 printf ("DW_OP_const4s: %" PRId64
, svalue
);
1241 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 8, end
);
1242 printf ("DW_OP_const8u: %" PRIu64
, uvalue
);
1245 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 8, end
);
1246 printf ("DW_OP_const8s: %" PRId64
, svalue
);
1249 READ_ULEB (uvalue
, data
, end
);
1250 printf ("DW_OP_constu: %" PRIu64
, uvalue
);
1253 READ_SLEB (svalue
, data
, end
);
1254 printf ("DW_OP_consts: %" PRId64
, svalue
);
1257 printf ("DW_OP_dup");
1260 printf ("DW_OP_drop");
1263 printf ("DW_OP_over");
1266 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1267 printf ("DW_OP_pick: %" PRIu64
, uvalue
);
1270 printf ("DW_OP_swap");
1273 printf ("DW_OP_rot");
1276 printf ("DW_OP_xderef");
1279 printf ("DW_OP_abs");
1282 printf ("DW_OP_and");
1285 printf ("DW_OP_div");
1288 printf ("DW_OP_minus");
1291 printf ("DW_OP_mod");
1294 printf ("DW_OP_mul");
1297 printf ("DW_OP_neg");
1300 printf ("DW_OP_not");
1303 printf ("DW_OP_or");
1306 printf ("DW_OP_plus");
1308 case DW_OP_plus_uconst
:
1309 READ_ULEB (uvalue
, data
, end
);
1310 printf ("DW_OP_plus_uconst: %" PRIu64
, uvalue
);
1313 printf ("DW_OP_shl");
1316 printf ("DW_OP_shr");
1319 printf ("DW_OP_shra");
1322 printf ("DW_OP_xor");
1325 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1326 printf ("DW_OP_bra: %" PRId64
, svalue
);
1329 printf ("DW_OP_eq");
1332 printf ("DW_OP_ge");
1335 printf ("DW_OP_gt");
1338 printf ("DW_OP_le");
1341 printf ("DW_OP_lt");
1344 printf ("DW_OP_ne");
1347 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1348 printf ("DW_OP_skip: %" PRId64
, svalue
);
1383 printf ("DW_OP_lit%d", op
- DW_OP_lit0
);
1418 printf ("DW_OP_reg%d (%s)", op
- DW_OP_reg0
,
1419 regname (op
- DW_OP_reg0
, 1));
1454 READ_SLEB (svalue
, data
, end
);
1455 printf ("DW_OP_breg%d (%s): %" PRId64
,
1456 op
- DW_OP_breg0
, regname (op
- DW_OP_breg0
, 1), svalue
);
1460 READ_ULEB (uvalue
, data
, end
);
1461 printf ("DW_OP_regx: %" PRIu64
" (%s)",
1462 uvalue
, regname (uvalue
, 1));
1465 need_frame_base
= 1;
1466 READ_SLEB (svalue
, data
, end
);
1467 printf ("DW_OP_fbreg: %" PRId64
, svalue
);
1470 READ_ULEB (uvalue
, data
, end
);
1471 READ_SLEB (svalue
, data
, end
);
1472 printf ("DW_OP_bregx: %" PRIu64
" (%s) %" PRId64
,
1473 uvalue
, regname (uvalue
, 1), svalue
);
1476 READ_ULEB (uvalue
, data
, end
);
1477 printf ("DW_OP_piece: %" PRIu64
, uvalue
);
1479 case DW_OP_deref_size
:
1480 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1481 printf ("DW_OP_deref_size: %" PRIu64
, uvalue
);
1483 case DW_OP_xderef_size
:
1484 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1485 printf ("DW_OP_xderef_size: %" PRIu64
, uvalue
);
1488 printf ("DW_OP_nop");
1491 /* DWARF 3 extensions. */
1492 case DW_OP_push_object_address
:
1493 printf ("DW_OP_push_object_address");
1496 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1497 this ought to be an 8-byte wide computation. */
1498 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1499 printf ("DW_OP_call2: <%#" PRIx64
">", svalue
+ cu_offset
);
1502 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1503 this ought to be an 8-byte wide computation. */
1504 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
1505 printf ("DW_OP_call4: <%#" PRIx64
">", svalue
+ cu_offset
);
1507 case DW_OP_call_ref
:
1508 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1509 this ought to be an 8-byte wide computation. */
1510 if (dwarf_version
== -1)
1512 printf (_("(DW_OP_call_ref in frame info)"));
1513 /* No way to tell where the next op is, so just bail. */
1514 return need_frame_base
;
1516 if (dwarf_version
== 2)
1518 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1522 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1524 printf ("DW_OP_call_ref: <%#" PRIx64
">", uvalue
);
1526 case DW_OP_form_tls_address
:
1527 printf ("DW_OP_form_tls_address");
1529 case DW_OP_call_frame_cfa
:
1530 printf ("DW_OP_call_frame_cfa");
1532 case DW_OP_bit_piece
:
1533 printf ("DW_OP_bit_piece: ");
1534 READ_ULEB (uvalue
, data
, end
);
1535 printf (_("size: %" PRIu64
" "), uvalue
);
1536 READ_ULEB (uvalue
, data
, end
);
1537 printf (_("offset: %" PRIu64
" "), uvalue
);
1540 /* DWARF 4 extensions. */
1541 case DW_OP_stack_value
:
1542 printf ("DW_OP_stack_value");
1545 case DW_OP_implicit_value
:
1546 printf ("DW_OP_implicit_value");
1547 READ_ULEB (uvalue
, data
, end
);
1548 data
= display_block (data
, uvalue
, end
, ' ');
1551 /* GNU extensions. */
1552 case DW_OP_GNU_push_tls_address
:
1553 printf (_("DW_OP_GNU_push_tls_address or DW_OP_HP_unknown"));
1555 case DW_OP_GNU_uninit
:
1556 printf ("DW_OP_GNU_uninit");
1557 /* FIXME: Is there data associated with this OP ? */
1559 case DW_OP_GNU_encoded_addr
:
1566 addr
= get_encoded_value (&data
, encoding
, section
, end
);
1568 printf ("DW_OP_GNU_encoded_addr: fmt:%02x addr:", encoding
);
1569 print_hex_ns (addr
, pointer_size
);
1572 case DW_OP_implicit_pointer
:
1573 case DW_OP_GNU_implicit_pointer
:
1574 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1575 this ought to be an 8-byte wide computation. */
1576 if (dwarf_version
== -1)
1578 printf (_("(%s in frame info)"),
1579 (op
== DW_OP_implicit_pointer
1580 ? "DW_OP_implicit_pointer"
1581 : "DW_OP_GNU_implicit_pointer"));
1582 /* No way to tell where the next op is, so just bail. */
1583 return need_frame_base
;
1585 if (dwarf_version
== 2)
1587 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1591 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1593 READ_SLEB (svalue
, data
, end
);
1594 printf ("%s: <%#" PRIx64
"> %" PRId64
,
1595 (op
== DW_OP_implicit_pointer
1596 ? "DW_OP_implicit_pointer" : "DW_OP_GNU_implicit_pointer"),
1599 case DW_OP_entry_value
:
1600 case DW_OP_GNU_entry_value
:
1601 READ_ULEB (uvalue
, data
, end
);
1602 /* PR 17531: file: 0cc9cd00. */
1603 if (uvalue
> (size_t) (end
- data
))
1604 uvalue
= end
- data
;
1605 printf ("%s: (", (op
== DW_OP_entry_value
? "DW_OP_entry_value"
1606 : "DW_OP_GNU_entry_value"));
1607 if (decode_location_expression (data
, pointer_size
, offset_size
,
1608 dwarf_version
, uvalue
,
1609 cu_offset
, section
))
1610 need_frame_base
= 1;
1614 case DW_OP_const_type
:
1615 case DW_OP_GNU_const_type
:
1616 READ_ULEB (uvalue
, data
, end
);
1617 printf ("%s: <%#" PRIx64
"> ",
1618 (op
== DW_OP_const_type
? "DW_OP_const_type"
1619 : "DW_OP_GNU_const_type"),
1620 cu_offset
+ uvalue
);
1621 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1622 data
= display_block (data
, uvalue
, end
, ' ');
1624 case DW_OP_regval_type
:
1625 case DW_OP_GNU_regval_type
:
1626 READ_ULEB (uvalue
, data
, end
);
1627 printf ("%s: %" PRIu64
" (%s)",
1628 (op
== DW_OP_regval_type
? "DW_OP_regval_type"
1629 : "DW_OP_GNU_regval_type"),
1630 uvalue
, regname (uvalue
, 1));
1631 READ_ULEB (uvalue
, data
, end
);
1632 printf (" <%#" PRIx64
">", cu_offset
+ uvalue
);
1634 case DW_OP_deref_type
:
1635 case DW_OP_GNU_deref_type
:
1636 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1637 printf ("%s: %" PRId64
,
1638 (op
== DW_OP_deref_type
? "DW_OP_deref_type"
1639 : "DW_OP_GNU_deref_type"),
1641 READ_ULEB (uvalue
, data
, end
);
1642 printf (" <%#" PRIx64
">", cu_offset
+ uvalue
);
1645 case DW_OP_GNU_convert
:
1646 READ_ULEB (uvalue
, data
, end
);
1647 printf ("%s <%#" PRIx64
">",
1648 (op
== DW_OP_convert
? "DW_OP_convert" : "DW_OP_GNU_convert"),
1649 uvalue
? cu_offset
+ uvalue
: uvalue
);
1651 case DW_OP_reinterpret
:
1652 case DW_OP_GNU_reinterpret
:
1653 READ_ULEB (uvalue
, data
, end
);
1654 printf ("%s <%#" PRIx64
">",
1655 (op
== DW_OP_reinterpret
? "DW_OP_reinterpret"
1656 : "DW_OP_GNU_reinterpret"),
1657 uvalue
? cu_offset
+ uvalue
: uvalue
);
1659 case DW_OP_GNU_parameter_ref
:
1660 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1661 printf ("DW_OP_GNU_parameter_ref: <%#" PRIx64
">",
1662 cu_offset
+ uvalue
);
1665 READ_ULEB (uvalue
, data
, end
);
1666 printf ("DW_OP_addrx <%#" PRIx64
">", uvalue
);
1668 case DW_OP_GNU_addr_index
:
1669 READ_ULEB (uvalue
, data
, end
);
1670 printf ("DW_OP_GNU_addr_index <%#" PRIx64
">", uvalue
);
1672 case DW_OP_GNU_const_index
:
1673 READ_ULEB (uvalue
, data
, end
);
1674 printf ("DW_OP_GNU_const_index <%#" PRIx64
">", uvalue
);
1676 case DW_OP_GNU_variable_value
:
1677 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1678 this ought to be an 8-byte wide computation. */
1679 if (dwarf_version
== -1)
1681 printf (_("(DW_OP_GNU_variable_value in frame info)"));
1682 /* No way to tell where the next op is, so just bail. */
1683 return need_frame_base
;
1685 if (dwarf_version
== 2)
1687 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1691 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1693 printf ("DW_OP_GNU_variable_value: <%#" PRIx64
">", uvalue
);
1696 /* HP extensions. */
1697 case DW_OP_HP_is_value
:
1698 printf ("DW_OP_HP_is_value");
1699 /* FIXME: Is there data associated with this OP ? */
1701 case DW_OP_HP_fltconst4
:
1702 printf ("DW_OP_HP_fltconst4");
1703 /* FIXME: Is there data associated with this OP ? */
1705 case DW_OP_HP_fltconst8
:
1706 printf ("DW_OP_HP_fltconst8");
1707 /* FIXME: Is there data associated with this OP ? */
1709 case DW_OP_HP_mod_range
:
1710 printf ("DW_OP_HP_mod_range");
1711 /* FIXME: Is there data associated with this OP ? */
1713 case DW_OP_HP_unmod_range
:
1714 printf ("DW_OP_HP_unmod_range");
1715 /* FIXME: Is there data associated with this OP ? */
1718 printf ("DW_OP_HP_tls");
1719 /* FIXME: Is there data associated with this OP ? */
1722 /* PGI (STMicroelectronics) extensions. */
1723 case DW_OP_PGI_omp_thread_num
:
1724 /* Pushes the thread number for the current thread as it would be
1725 returned by the standard OpenMP library function:
1726 omp_get_thread_num(). The "current thread" is the thread for
1727 which the expression is being evaluated. */
1728 printf ("DW_OP_PGI_omp_thread_num");
1732 if (op
>= DW_OP_lo_user
1733 && op
<= DW_OP_hi_user
)
1734 printf (_("(User defined location op %#x)"), op
);
1736 printf (_("(Unknown location op %#x)"), op
);
1737 /* No way to tell where the next op is, so just bail. */
1738 return need_frame_base
;
1741 /* Separate the ops. */
1746 return need_frame_base
;
1749 /* Find the CU or TU set corresponding to the given CU_OFFSET.
1750 This is used for DWARF package files. */
1752 static struct cu_tu_set
*
1753 find_cu_tu_set_v2 (uint64_t cu_offset
, int do_types
)
1755 struct cu_tu_set
*p
;
1757 unsigned int dw_sect
;
1763 dw_sect
= DW_SECT_TYPES
;
1769 dw_sect
= DW_SECT_INFO
;
1773 if (p
->section_offsets
[dw_sect
] == cu_offset
)
1782 fetch_alt_indirect_string (uint64_t offset
)
1786 if (! do_follow_links
)
1789 if (first_separate_info
== NULL
)
1790 return _("<no links available>");
1792 for (i
= first_separate_info
; i
!= NULL
; i
= i
->next
)
1794 struct dwarf_section
* section
;
1797 if (! load_debug_section (separate_debug_str
, i
->handle
))
1800 section
= &debug_displays
[separate_debug_str
].section
;
1802 if (section
->start
== NULL
)
1805 if (offset
>= section
->size
)
1808 ret
= (const char *) (section
->start
+ offset
);
1809 /* Unfortunately we cannot rely upon the .debug_str section ending with a
1810 NUL byte. Since our caller is expecting to receive a well formed C
1811 string we test for the lack of a terminating byte here. */
1812 if (strnlen ((const char *) ret
, section
->size
- offset
)
1813 == section
->size
- offset
)
1814 return _("<no NUL byte at end of alt .debug_str section>");
1819 warn (_("DW_FORM_GNU_strp_alt offset (%#" PRIx64
")"
1820 " too big or no string sections available\n"), offset
);
1821 return _("<offset is too big>");
1825 get_AT_name (unsigned long attribute
)
1830 return "DW_AT value: 0";
1832 /* One value is shared by the MIPS and HP extensions: */
1833 if (attribute
== DW_AT_MIPS_fde
)
1834 return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable";
1836 name
= get_DW_AT_name (attribute
);
1840 static char buffer
[100];
1842 snprintf (buffer
, sizeof (buffer
), _("Unknown AT value: %lx"),
1851 add_dwo_info (const char * value
, uint64_t cu_offset
, dwo_type type
)
1853 dwo_info
* dwinfo
= xmalloc (sizeof * dwinfo
);
1855 dwinfo
->type
= type
;
1856 dwinfo
->value
= value
;
1857 dwinfo
->cu_offset
= cu_offset
;
1858 dwinfo
->next
= first_dwo_info
;
1859 first_dwo_info
= dwinfo
;
1863 add_dwo_name (const char * name
, uint64_t cu_offset
)
1865 add_dwo_info (name
, cu_offset
, DWO_NAME
);
1869 add_dwo_dir (const char * dir
, uint64_t cu_offset
)
1871 add_dwo_info (dir
, cu_offset
, DWO_DIR
);
1875 add_dwo_id (const char * id
, uint64_t cu_offset
)
1877 add_dwo_info (id
, cu_offset
, DWO_ID
);
1881 free_dwo_info (void)
1886 for (dwinfo
= first_dwo_info
; dwinfo
!= NULL
; dwinfo
= next
)
1888 next
= dwinfo
->next
;
1891 first_dwo_info
= NULL
;
1894 /* Ensure that START + UVALUE is less than END.
1895 Return an adjusted UVALUE if necessary to ensure this relationship. */
1897 static inline uint64_t
1898 check_uvalue (const unsigned char *start
,
1900 const unsigned char *end
)
1902 uint64_t max_uvalue
= end
- start
;
1904 /* See PR 17512: file: 008-103549-0.001:0.1.
1905 and PR 24829 for examples of where these tests are triggered. */
1906 if (uvalue
> max_uvalue
)
1908 warn (_("Corrupt attribute block length: %#" PRIx64
"\n"), uvalue
);
1909 uvalue
= max_uvalue
;
1915 static unsigned char *
1916 skip_attr_bytes (unsigned long form
,
1917 unsigned char *data
,
1919 uint64_t pointer_size
,
1920 uint64_t offset_size
,
1922 uint64_t *value_return
)
1925 uint64_t uvalue
= 0;
1932 case DW_FORM_ref_addr
:
1933 if (dwarf_version
== 2)
1934 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1935 else if (dwarf_version
> 2)
1936 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1942 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1946 case DW_FORM_line_strp
:
1947 case DW_FORM_sec_offset
:
1948 case DW_FORM_GNU_ref_alt
:
1949 case DW_FORM_GNU_strp_alt
:
1950 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1953 case DW_FORM_flag_present
:
1961 case DW_FORM_addrx1
:
1962 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1966 case DW_FORM_addrx3
:
1967 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 3, end
);
1973 case DW_FORM_addrx2
:
1974 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
1980 case DW_FORM_addrx4
:
1981 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1985 READ_SLEB (svalue
, data
, end
);
1989 case DW_FORM_ref_udata
:
1991 case DW_FORM_GNU_str_index
:
1993 case DW_FORM_GNU_addr_index
:
1995 case DW_FORM_loclistx
:
1996 case DW_FORM_rnglistx
:
1997 READ_ULEB (uvalue
, data
, end
);
2001 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 8, end
);
2005 case DW_FORM_ref_sig8
:
2009 case DW_FORM_data16
:
2013 case DW_FORM_string
:
2014 inc
= strnlen ((char *) data
, end
- data
) + 1;
2018 case DW_FORM_exprloc
:
2019 READ_ULEB (uvalue
, data
, end
);
2023 case DW_FORM_block1
:
2024 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
2028 case DW_FORM_block2
:
2029 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
2033 case DW_FORM_block4
:
2034 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
2038 case DW_FORM_indirect
:
2039 READ_ULEB (form
, data
, end
);
2040 if (form
== DW_FORM_implicit_const
)
2041 SKIP_ULEB (data
, end
);
2042 return skip_attr_bytes (form
, data
, end
, pointer_size
, offset_size
,
2043 dwarf_version
, value_return
);
2049 * value_return
= uvalue
;
2050 if (inc
<= (size_t) (end
- data
))
2057 /* Given form FORM with value UVALUE, locate and return the abbreviation
2058 associated with it. */
2060 static abbrev_entry
*
2061 get_type_abbrev_from_form (unsigned long form
,
2062 unsigned long uvalue
,
2064 unsigned char *cu_end
,
2065 const struct dwarf_section
*section
,
2066 unsigned long *abbrev_num_return
,
2067 unsigned char **data_return
,
2068 abbrev_map
**map_return
)
2070 unsigned long abbrev_number
;
2072 abbrev_entry
* entry
;
2073 unsigned char * data
;
2075 if (abbrev_num_return
!= NULL
)
2076 * abbrev_num_return
= 0;
2077 if (data_return
!= NULL
)
2078 * data_return
= NULL
;
2082 case DW_FORM_GNU_ref_alt
:
2083 case DW_FORM_ref_sig8
:
2084 /* FIXME: We are unable to handle this form at the moment. */
2087 case DW_FORM_ref_addr
:
2088 if (uvalue
>= section
->size
)
2090 warn (_("Unable to resolve ref_addr form: uvalue %lx "
2091 "> section size %" PRIx64
" (%s)\n"),
2092 uvalue
, section
->size
, section
->name
);
2097 case DW_FORM_ref_sup4
:
2098 case DW_FORM_ref_sup8
:
2105 case DW_FORM_ref_udata
:
2106 if (uvalue
+ cu_offset
< uvalue
2107 || uvalue
+ cu_offset
> (size_t) (cu_end
- section
->start
))
2109 warn (_("Unable to resolve ref form: uvalue %lx + cu_offset %" PRIx64
2110 " > CU size %tx\n"),
2111 uvalue
, cu_offset
, cu_end
- section
->start
);
2114 uvalue
+= cu_offset
;
2117 /* FIXME: Are there other DW_FORMs that can be used by types ? */
2120 warn (_("Unexpected form %lx encountered whilst finding abbreviation for type\n"), form
);
2124 data
= (unsigned char *) section
->start
+ uvalue
;
2125 map
= find_abbrev_map_by_offset (uvalue
);
2129 warn (_("Unable to find abbreviations for CU offset %#lx\n"), uvalue
);
2132 if (map
->list
== NULL
)
2134 warn (_("Empty abbreviation list encountered for CU offset %lx\n"), uvalue
);
2138 if (map_return
!= NULL
)
2140 if (form
== DW_FORM_ref_addr
)
2146 READ_ULEB (abbrev_number
, data
, section
->start
+ section
->size
);
2148 for (entry
= map
->list
->first_abbrev
; entry
!= NULL
; entry
= entry
->next
)
2149 if (entry
->number
== abbrev_number
)
2152 if (abbrev_num_return
!= NULL
)
2153 * abbrev_num_return
= abbrev_number
;
2155 if (data_return
!= NULL
)
2156 * data_return
= data
;
2159 warn (_("Unable to find entry for abbreviation %lu\n"), abbrev_number
);
2164 /* Return IS_SIGNED set to TRUE if the type using abbreviation ENTRY
2165 can be determined to be a signed type. The data for ENTRY can be
2166 found starting at DATA. */
2169 get_type_signedness (abbrev_entry
*entry
,
2170 const struct dwarf_section
*section
,
2171 unsigned char *data
,
2174 uint64_t pointer_size
,
2175 uint64_t offset_size
,
2178 unsigned int nesting
)
2182 * is_signed
= false;
2184 #define MAX_NESTING 20
2185 if (nesting
> MAX_NESTING
)
2187 /* FIXME: Warn - or is this expected ?
2188 NB/ We need to avoid infinite recursion. */
2192 for (attr
= entry
->first_attr
;
2193 attr
!= NULL
&& attr
->attribute
;
2196 unsigned char * orig_data
= data
;
2197 uint64_t uvalue
= 0;
2199 data
= skip_attr_bytes (attr
->form
, data
, end
, pointer_size
,
2200 offset_size
, dwarf_version
, & uvalue
);
2204 switch (attr
->attribute
)
2206 case DW_AT_linkage_name
:
2210 if (attr
->form
== DW_FORM_strp
)
2211 printf (", %s", fetch_indirect_string (uvalue
));
2212 else if (attr
->form
== DW_FORM_string
)
2213 printf (", %.*s", (int) (end
- orig_data
), orig_data
);
2220 abbrev_entry
*type_abbrev
;
2221 unsigned char *type_data
;
2224 type_abbrev
= get_type_abbrev_from_form (attr
->form
,
2229 NULL
/* abbrev num return */,
2232 if (type_abbrev
== NULL
)
2235 get_type_signedness (type_abbrev
, section
, type_data
,
2236 map
? section
->start
+ map
->end
: end
,
2237 map
? map
->start
: cu_offset
,
2238 pointer_size
, offset_size
, dwarf_version
,
2239 is_signed
, nesting
+ 1);
2243 case DW_AT_encoding
:
2244 /* Determine signness. */
2247 case DW_ATE_address
:
2248 /* FIXME - some architectures have signed addresses. */
2249 case DW_ATE_boolean
:
2250 case DW_ATE_unsigned
:
2251 case DW_ATE_unsigned_char
:
2252 case DW_ATE_unsigned_fixed
:
2253 * is_signed
= false;
2257 case DW_ATE_complex_float
:
2260 case DW_ATE_signed_char
:
2261 case DW_ATE_imaginary_float
:
2262 case DW_ATE_decimal_float
:
2263 case DW_ATE_signed_fixed
:
2273 read_and_print_leb128 (unsigned char *data
,
2274 unsigned int *bytes_read
,
2275 unsigned const char *end
,
2279 uint64_t val
= read_leb128 (data
, end
, is_signed
, bytes_read
, &status
);
2281 report_leb_status (status
);
2283 printf ("%" PRId64
, val
);
2285 printf ("%" PRIu64
, val
);
2289 display_discr_list (unsigned long form
,
2291 unsigned char *data
,
2294 unsigned char *end
= data
;
2298 printf ("[default]");
2305 case DW_FORM_block1
:
2306 case DW_FORM_block2
:
2307 case DW_FORM_block4
:
2308 /* Move data pointer back to the start of the byte array. */
2312 printf ("<corrupt>\n");
2313 warn (_("corrupt discr_list - not using a block form\n"));
2319 printf ("<corrupt>\n");
2320 warn (_("corrupt discr_list - block not long enough\n"));
2324 bool is_signed
= (level
> 0 && level
<= MAX_CU_NESTING
2325 ? level_type_signed
[level
- 1] : false);
2330 unsigned char discriminant
;
2331 unsigned int bytes_read
;
2333 SAFE_BYTE_GET_AND_INC (discriminant
, data
, 1, end
);
2335 switch (discriminant
)
2339 read_and_print_leb128 (data
, & bytes_read
, end
, is_signed
);
2345 read_and_print_leb128 (data
, & bytes_read
, end
, is_signed
);
2349 read_and_print_leb128 (data
, & bytes_read
, end
, is_signed
);
2354 printf ("<corrupt>\n");
2355 warn (_("corrupt discr_list - unrecognized discriminant byte %#x\n"),
2365 printf (")(signed)");
2367 printf (")(unsigned)");
2370 static unsigned char *
2371 read_and_display_attr_value (unsigned long attribute
,
2373 int64_t implicit_const
,
2374 unsigned char *start
,
2375 unsigned char *data
,
2378 uint64_t pointer_size
,
2379 uint64_t offset_size
,
2381 debug_info
*debug_info_p
,
2383 struct dwarf_section
*section
,
2384 struct cu_tu_set
*this_set
,
2389 uint64_t uvalue
= 0;
2390 uint64_t uvalue_hi
= 0;
2391 unsigned char *block_start
= NULL
;
2392 unsigned char *orig_data
= data
;
2394 if (data
> end
|| (data
== end
&& form
!= DW_FORM_flag_present
))
2396 warn (_("Corrupt attribute\n"));
2400 if (do_wide
&& ! do_loc
)
2402 /* PR 26847: Display the name of the form. */
2403 const char * name
= get_FORM_name (form
);
2405 /* For convenience we skip the DW_FORM_ prefix to the name. */
2407 name
+= 8; /* strlen ("DW_FORM_") */
2408 printf ("%c(%s)", delimiter
, name
);
2413 case DW_FORM_ref_addr
:
2414 if (dwarf_version
== 2)
2415 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
2416 else if (dwarf_version
> 2)
2417 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
2419 error (_("Internal error: DW_FORM_ref_addr is not supported in DWARF version 1.\n"));
2423 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
2426 case DW_FORM_strp_sup
:
2428 case DW_FORM_line_strp
:
2429 case DW_FORM_sec_offset
:
2430 case DW_FORM_GNU_ref_alt
:
2431 case DW_FORM_GNU_strp_alt
:
2432 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
2435 case DW_FORM_flag_present
:
2443 case DW_FORM_addrx1
:
2444 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
2450 case DW_FORM_addrx2
:
2451 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
2455 case DW_FORM_addrx3
:
2456 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 3, end
);
2459 case DW_FORM_ref_sup4
:
2463 case DW_FORM_addrx4
:
2464 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
2467 case DW_FORM_ref_sup8
:
2470 case DW_FORM_ref_sig8
:
2471 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 8, end
);
2474 case DW_FORM_data16
:
2475 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 8, end
);
2476 SAFE_BYTE_GET_AND_INC (uvalue_hi
, data
, 8, end
);
2477 if (byte_get
!= byte_get_little_endian
)
2479 uint64_t utmp
= uvalue
;
2486 READ_SLEB (svalue
, data
, end
);
2490 case DW_FORM_GNU_str_index
:
2492 case DW_FORM_ref_udata
:
2494 case DW_FORM_GNU_addr_index
:
2496 case DW_FORM_loclistx
:
2497 case DW_FORM_rnglistx
:
2498 READ_ULEB (uvalue
, data
, end
);
2501 case DW_FORM_indirect
:
2502 READ_ULEB (form
, data
, end
);
2504 printf ("%c%s", delimiter
, get_FORM_name (form
));
2505 if (form
== DW_FORM_implicit_const
)
2506 READ_SLEB (implicit_const
, data
, end
);
2507 return read_and_display_attr_value (attribute
, form
, implicit_const
,
2509 cu_offset
, pointer_size
,
2510 offset_size
, dwarf_version
,
2511 debug_info_p
, do_loc
,
2512 section
, this_set
, delimiter
, level
);
2514 case DW_FORM_implicit_const
:
2515 uvalue
= implicit_const
;
2524 case DW_FORM_ref_addr
:
2526 printf ("%c<%#" PRIx64
">", delimiter
, uvalue
);
2529 case DW_FORM_GNU_ref_alt
:
2533 /* We have already printed the form name. */
2534 printf ("%c<%#" PRIx64
">", delimiter
, uvalue
);
2536 printf ("%c<alt %#" PRIx64
">", delimiter
, uvalue
);
2538 /* FIXME: Follow the reference... */
2544 case DW_FORM_ref_sup4
:
2545 case DW_FORM_ref_udata
:
2547 printf ("%c<%#" PRIx64
">", delimiter
, uvalue
+ cu_offset
);
2552 case DW_FORM_sec_offset
:
2554 printf ("%c%#" PRIx64
, delimiter
, uvalue
);
2557 case DW_FORM_flag_present
:
2563 printf ("%c%" PRId64
, delimiter
, uvalue
);
2568 printf ("%c%" PRIu64
, delimiter
, uvalue
);
2571 case DW_FORM_implicit_const
:
2573 printf ("%c%" PRId64
, delimiter
, implicit_const
);
2576 case DW_FORM_ref_sup8
:
2581 uint64_t utmp
= uvalue
;
2582 if (form
== DW_FORM_ref8
)
2584 printf ("%c%#" PRIx64
, delimiter
, utmp
);
2588 case DW_FORM_data16
:
2592 printf (" %#" PRIx64
, uvalue
);
2594 printf (" %#" PRIx64
"%016" PRIx64
, uvalue_hi
, uvalue
);
2598 case DW_FORM_string
:
2600 printf ("%c%.*s", delimiter
, (int) (end
- data
), data
);
2601 data
+= strnlen ((char *) data
, end
- data
);
2607 case DW_FORM_exprloc
:
2608 READ_ULEB (uvalue
, data
, end
);
2611 if (block_start
>= end
)
2613 warn (_("Block ends prematurely\n"));
2618 uvalue
= check_uvalue (block_start
, uvalue
, end
);
2620 data
= block_start
+ uvalue
;
2625 SAFE_BYTE_GET (op
, block_start
, sizeof (op
), end
);
2626 if (op
!= DW_OP_addrx
)
2627 data
= display_block (block_start
, uvalue
, end
, delimiter
);
2631 case DW_FORM_block1
:
2632 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
2635 case DW_FORM_block2
:
2636 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
2639 case DW_FORM_block4
:
2640 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
2647 /* We have already displayed the form name. */
2648 printf (_("%c(offset: %#" PRIx64
"): %s"),
2649 delimiter
, uvalue
, fetch_indirect_string (uvalue
));
2651 printf (_("%c(indirect string, offset: %#" PRIx64
"): %s"),
2652 delimiter
, uvalue
, fetch_indirect_string (uvalue
));
2656 case DW_FORM_line_strp
:
2660 /* We have already displayed the form name. */
2661 printf (_("%c(offset: %#" PRIx64
"): %s"),
2662 delimiter
, uvalue
, fetch_indirect_line_string (uvalue
));
2664 printf (_("%c(indirect line string, offset: %#" PRIx64
"): %s"),
2665 delimiter
, uvalue
, fetch_indirect_line_string (uvalue
));
2669 case DW_FORM_GNU_str_index
:
2677 const char *suffix
= section
? strrchr (section
->name
, '.') : NULL
;
2678 bool dwo
= suffix
&& strcmp (suffix
, ".dwo") == 0;
2681 strng
= fetch_indexed_string (uvalue
, this_set
, offset_size
, dwo
,
2682 debug_info_p
? debug_info_p
->str_offsets_base
: 0);
2684 /* We have already displayed the form name. */
2685 printf (_("%c(offset: %#" PRIx64
"): %s"),
2686 delimiter
, uvalue
, strng
);
2688 printf (_("%c(indexed string: %#" PRIx64
"): %s"),
2689 delimiter
, uvalue
, strng
);
2693 case DW_FORM_GNU_strp_alt
:
2697 /* We have already displayed the form name. */
2698 printf (_("%c(offset: %#" PRIx64
") %s"),
2699 delimiter
, uvalue
, fetch_alt_indirect_string (uvalue
));
2701 printf (_("%c(alt indirect string, offset: %#" PRIx64
") %s"),
2702 delimiter
, uvalue
, fetch_alt_indirect_string (uvalue
));
2706 case DW_FORM_indirect
:
2707 /* Handled above. */
2710 case DW_FORM_ref_sig8
:
2712 printf ("%c%s: %#" PRIx64
, delimiter
, do_wide
? "" : "signature",
2716 case DW_FORM_GNU_addr_index
:
2718 case DW_FORM_addrx1
:
2719 case DW_FORM_addrx2
:
2720 case DW_FORM_addrx3
:
2721 case DW_FORM_addrx4
:
2722 case DW_FORM_loclistx
:
2723 case DW_FORM_rnglistx
:
2727 const char *suffix
= strrchr (section
->name
, '.');
2728 bool dwo
= suffix
&& strcmp (suffix
, ".dwo") == 0;
2730 if (form
== DW_FORM_loclistx
)
2734 idx
= fetch_indexed_value (uvalue
, loclists_dwo
, 0);
2735 if (idx
!= (uint64_t) -1)
2736 idx
+= (offset_size
== 8) ? 20 : 12;
2738 else if (debug_info_p
== NULL
)
2740 idx
= fetch_indexed_value (uvalue
, loclists
, 0);
2744 /* We want to compute:
2745 idx = fetch_indexed_value (uvalue, loclists, debug_info_p->loclists_base);
2746 idx += debug_info_p->loclists_base;
2747 Fortunately we already have that sum cached in the
2748 loc_offsets array. */
2749 if (uvalue
< debug_info_p
->num_loc_offsets
)
2750 idx
= debug_info_p
->loc_offsets
[uvalue
];
2753 warn (_("loc_offset %" PRIu64
" too big\n"), uvalue
);
2758 else if (form
== DW_FORM_rnglistx
)
2762 idx
= fetch_indexed_value (uvalue
, rnglists_dwo
, 0);
2763 if (idx
!= (uint64_t) -1)
2764 idx
+= (offset_size
== 8) ? 20 : 12;
2768 if (debug_info_p
== NULL
)
2771 base
= debug_info_p
->rnglists_base
;
2772 /* We do not have a cached value this time, so we perform the
2773 computation manually. */
2774 idx
= fetch_indexed_value (uvalue
, rnglists
, base
);
2775 if (idx
!= (uint64_t) -1)
2781 if (debug_info_p
== NULL
)
2783 else if (debug_info_p
->addr_base
== DEBUG_INFO_UNAVAILABLE
)
2786 base
= debug_info_p
->addr_base
;
2788 base
+= uvalue
* pointer_size
;
2789 idx
= fetch_indexed_addr (base
, pointer_size
);
2792 /* We have already displayed the form name. */
2793 if (idx
!= (uint64_t) -1)
2794 printf (_("%c(index: %#" PRIx64
"): %#" PRIx64
),
2795 delimiter
, uvalue
, idx
);
2799 case DW_FORM_strp_sup
:
2801 printf ("%c<%#" PRIx64
">", delimiter
, uvalue
+ cu_offset
);
2805 warn (_("Unrecognized form: %#lx\n"), form
);
2806 /* What to do? Consume a byte maybe? */
2811 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
|| do_debug_info
)
2812 && num_debug_info_entries
== 0
2813 && debug_info_p
!= NULL
)
2817 case DW_AT_loclists_base
:
2818 if (debug_info_p
->loclists_base
)
2819 warn (_("CU @ %#" PRIx64
" has multiple loclists_base values "
2820 "(%#" PRIx64
" and %#" PRIx64
")"),
2821 debug_info_p
->cu_offset
,
2822 debug_info_p
->loclists_base
, uvalue
);
2823 debug_info_p
->loclists_base
= uvalue
;
2825 case DW_AT_rnglists_base
:
2826 if (debug_info_p
->rnglists_base
)
2827 warn (_("CU @ %#" PRIx64
" has multiple rnglists_base values "
2828 "(%#" PRIx64
" and %#" PRIx64
")"),
2829 debug_info_p
->cu_offset
,
2830 debug_info_p
->rnglists_base
, uvalue
);
2831 debug_info_p
->rnglists_base
= uvalue
;
2833 case DW_AT_str_offsets_base
:
2834 if (debug_info_p
->str_offsets_base
)
2835 warn (_("CU @ %#" PRIx64
" has multiple str_offsets_base values "
2836 "%#" PRIx64
" and %#" PRIx64
")"),
2837 debug_info_p
->cu_offset
,
2838 debug_info_p
->str_offsets_base
, uvalue
);
2839 debug_info_p
->str_offsets_base
= uvalue
;
2842 case DW_AT_frame_base
:
2843 have_frame_base
= 1;
2845 case DW_AT_location
:
2846 case DW_AT_GNU_locviews
:
2847 case DW_AT_string_length
:
2848 case DW_AT_return_addr
:
2849 case DW_AT_data_member_location
:
2850 case DW_AT_vtable_elem_location
:
2852 case DW_AT_static_link
:
2853 case DW_AT_use_location
:
2854 case DW_AT_call_value
:
2855 case DW_AT_GNU_call_site_value
:
2856 case DW_AT_call_data_value
:
2857 case DW_AT_GNU_call_site_data_value
:
2858 case DW_AT_call_target
:
2859 case DW_AT_GNU_call_site_target
:
2860 case DW_AT_call_target_clobbered
:
2861 case DW_AT_GNU_call_site_target_clobbered
:
2862 if ((dwarf_version
< 4
2863 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
2864 || form
== DW_FORM_sec_offset
2865 || form
== DW_FORM_loclistx
)
2867 /* Process location list. */
2868 unsigned int lmax
= debug_info_p
->max_loc_offsets
;
2869 unsigned int num
= debug_info_p
->num_loc_offsets
;
2871 if (lmax
== 0 || num
>= lmax
)
2874 debug_info_p
->loc_offsets
= (uint64_t *)
2875 xcrealloc (debug_info_p
->loc_offsets
,
2876 lmax
, sizeof (*debug_info_p
->loc_offsets
));
2877 debug_info_p
->loc_views
= (uint64_t *)
2878 xcrealloc (debug_info_p
->loc_views
,
2879 lmax
, sizeof (*debug_info_p
->loc_views
));
2880 debug_info_p
->have_frame_base
= (int *)
2881 xcrealloc (debug_info_p
->have_frame_base
,
2882 lmax
, sizeof (*debug_info_p
->have_frame_base
));
2883 debug_info_p
->max_loc_offsets
= lmax
;
2885 if (form
== DW_FORM_loclistx
)
2886 uvalue
= fetch_indexed_value (num
, loclists
, debug_info_p
->loclists_base
);
2887 else if (this_set
!= NULL
)
2888 uvalue
+= this_set
->section_offsets
[DW_SECT_LOC
];
2890 debug_info_p
->have_frame_base
[num
] = have_frame_base
;
2891 if (attribute
!= DW_AT_GNU_locviews
)
2893 uvalue
+= debug_info_p
->loclists_base
;
2895 /* Corrupt DWARF info can produce more offsets than views.
2896 See PR 23062 for an example. */
2897 if (debug_info_p
->num_loc_offsets
2898 > debug_info_p
->num_loc_views
)
2899 warn (_("More location offset attributes than DW_AT_GNU_locview attributes\n"));
2902 debug_info_p
->loc_offsets
[num
] = uvalue
;
2903 debug_info_p
->num_loc_offsets
++;
2908 assert (debug_info_p
->num_loc_views
<= num
);
2909 num
= debug_info_p
->num_loc_views
;
2910 if (num
> debug_info_p
->num_loc_offsets
)
2911 warn (_("More DW_AT_GNU_locview attributes than location offset attributes\n"));
2914 debug_info_p
->loc_views
[num
] = uvalue
;
2915 debug_info_p
->num_loc_views
++;
2922 if (need_base_address
)
2923 debug_info_p
->base_address
= uvalue
;
2926 case DW_AT_GNU_addr_base
:
2927 case DW_AT_addr_base
:
2928 debug_info_p
->addr_base
= uvalue
;
2931 case DW_AT_GNU_ranges_base
:
2932 debug_info_p
->ranges_base
= uvalue
;
2936 if ((dwarf_version
< 4
2937 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
2938 || form
== DW_FORM_sec_offset
2939 || form
== DW_FORM_rnglistx
)
2941 /* Process range list. */
2942 unsigned int lmax
= debug_info_p
->max_range_lists
;
2943 unsigned int num
= debug_info_p
->num_range_lists
;
2945 if (lmax
== 0 || num
>= lmax
)
2948 debug_info_p
->range_lists
= (uint64_t *)
2949 xcrealloc (debug_info_p
->range_lists
,
2950 lmax
, sizeof (*debug_info_p
->range_lists
));
2951 debug_info_p
->max_range_lists
= lmax
;
2954 if (form
== DW_FORM_rnglistx
)
2955 uvalue
= fetch_indexed_value (uvalue
, rnglists
, 0);
2957 debug_info_p
->range_lists
[num
] = uvalue
;
2958 debug_info_p
->num_range_lists
++;
2962 case DW_AT_GNU_dwo_name
:
2963 case DW_AT_dwo_name
:
2968 add_dwo_name ((const char *) fetch_indirect_string (uvalue
), cu_offset
);
2970 case DW_FORM_GNU_strp_alt
:
2971 add_dwo_name ((const char *) fetch_alt_indirect_string (uvalue
), cu_offset
);
2973 case DW_FORM_GNU_str_index
:
2979 add_dwo_name (fetch_indexed_string (uvalue
, this_set
, offset_size
, false,
2980 debug_info_p
->str_offsets_base
),
2983 case DW_FORM_string
:
2984 add_dwo_name ((const char *) orig_data
, cu_offset
);
2987 warn (_("Unsupported form (%s) for attribute %s\n"),
2988 get_FORM_name (form
), get_AT_name (attribute
));
2993 case DW_AT_comp_dir
:
2994 /* FIXME: Also extract a build-id in a CU/TU. */
2999 add_dwo_dir ((const char *) fetch_indirect_string (uvalue
), cu_offset
);
3001 case DW_FORM_GNU_strp_alt
:
3002 add_dwo_dir (fetch_alt_indirect_string (uvalue
), cu_offset
);
3004 case DW_FORM_line_strp
:
3005 add_dwo_dir ((const char *) fetch_indirect_line_string (uvalue
), cu_offset
);
3007 case DW_FORM_GNU_str_index
:
3013 add_dwo_dir (fetch_indexed_string (uvalue
, this_set
, offset_size
, false,
3014 debug_info_p
->str_offsets_base
),
3017 case DW_FORM_string
:
3018 add_dwo_dir ((const char *) orig_data
, cu_offset
);
3021 warn (_("Unsupported form (%s) for attribute %s\n"),
3022 get_FORM_name (form
), get_AT_name (attribute
));
3027 case DW_AT_GNU_dwo_id
:
3032 /* FIXME: Record the length of the ID as well ? */
3033 add_dwo_id ((const char *) (data
- 8), cu_offset
);
3036 warn (_("Unsupported form (%s) for attribute %s\n"),
3037 get_FORM_name (form
), get_AT_name (attribute
));
3047 if (do_loc
|| attribute
== 0)
3050 /* For some attributes we can display further information. */
3054 if (level
>= 0 && level
< MAX_CU_NESTING
3055 && uvalue
< (size_t) (end
- start
))
3057 bool is_signed
= false;
3058 abbrev_entry
*type_abbrev
;
3059 unsigned char *type_data
;
3062 type_abbrev
= get_type_abbrev_from_form (form
, uvalue
,
3066 if (type_abbrev
!= NULL
)
3068 get_type_signedness (type_abbrev
, section
, type_data
,
3069 map
? section
->start
+ map
->end
: end
,
3070 map
? map
->start
: cu_offset
,
3071 pointer_size
, offset_size
, dwarf_version
,
3074 level_type_signed
[level
] = is_signed
;
3082 case DW_INL_not_inlined
:
3083 printf (_("(not inlined)"));
3085 case DW_INL_inlined
:
3086 printf (_("(inlined)"));
3088 case DW_INL_declared_not_inlined
:
3089 printf (_("(declared as inline but ignored)"));
3091 case DW_INL_declared_inlined
:
3092 printf (_("(declared as inline and inlined)"));
3095 printf (_(" (Unknown inline attribute value: %#" PRIx64
")"),
3101 case DW_AT_language
:
3105 /* Ordered by the numeric value of these constants. */
3106 case DW_LANG_C89
: printf ("(ANSI C)"); break;
3107 case DW_LANG_C
: printf ("(non-ANSI C)"); break;
3108 case DW_LANG_Ada83
: printf ("(Ada)"); break;
3109 case DW_LANG_C_plus_plus
: printf ("(C++)"); break;
3110 case DW_LANG_Cobol74
: printf ("(Cobol 74)"); break;
3111 case DW_LANG_Cobol85
: printf ("(Cobol 85)"); break;
3112 case DW_LANG_Fortran77
: printf ("(FORTRAN 77)"); break;
3113 case DW_LANG_Fortran90
: printf ("(Fortran 90)"); break;
3114 case DW_LANG_Pascal83
: printf ("(ANSI Pascal)"); break;
3115 case DW_LANG_Modula2
: printf ("(Modula 2)"); break;
3116 /* DWARF 2.1 values. */
3117 case DW_LANG_Java
: printf ("(Java)"); break;
3118 case DW_LANG_C99
: printf ("(ANSI C99)"); break;
3119 case DW_LANG_Ada95
: printf ("(ADA 95)"); break;
3120 case DW_LANG_Fortran95
: printf ("(Fortran 95)"); break;
3121 /* DWARF 3 values. */
3122 case DW_LANG_PLI
: printf ("(PLI)"); break;
3123 case DW_LANG_ObjC
: printf ("(Objective C)"); break;
3124 case DW_LANG_ObjC_plus_plus
: printf ("(Objective C++)"); break;
3125 case DW_LANG_UPC
: printf ("(Unified Parallel C)"); break;
3126 case DW_LANG_D
: printf ("(D)"); break;
3127 /* DWARF 4 values. */
3128 case DW_LANG_Python
: printf ("(Python)"); break;
3129 /* DWARF 5 values. */
3130 case DW_LANG_OpenCL
: printf ("(OpenCL)"); break;
3131 case DW_LANG_Go
: printf ("(Go)"); break;
3132 case DW_LANG_Modula3
: printf ("(Modula 3)"); break;
3133 case DW_LANG_Haskell
: printf ("(Haskell)"); break;
3134 case DW_LANG_C_plus_plus_03
: printf ("(C++03)"); break;
3135 case DW_LANG_C_plus_plus_11
: printf ("(C++11)"); break;
3136 case DW_LANG_OCaml
: printf ("(OCaml)"); break;
3137 case DW_LANG_Rust
: printf ("(Rust)"); break;
3138 case DW_LANG_C11
: printf ("(C11)"); break;
3139 case DW_LANG_Swift
: printf ("(Swift)"); break;
3140 case DW_LANG_Julia
: printf ("(Julia)"); break;
3141 case DW_LANG_Dylan
: printf ("(Dylan)"); break;
3142 case DW_LANG_C_plus_plus_14
: printf ("(C++14)"); break;
3143 case DW_LANG_Fortran03
: printf ("(Fortran 03)"); break;
3144 case DW_LANG_Fortran08
: printf ("(Fortran 08)"); break;
3145 case DW_LANG_RenderScript
: printf ("(RenderScript)"); break;
3146 /* MIPS extension. */
3147 case DW_LANG_Mips_Assembler
: printf ("(MIPS assembler)"); break;
3148 /* UPC extension. */
3149 case DW_LANG_Upc
: printf ("(Unified Parallel C)"); break;
3151 if (uvalue
>= DW_LANG_lo_user
&& uvalue
<= DW_LANG_hi_user
)
3152 printf (_("(implementation defined: %#" PRIx64
")"), uvalue
);
3154 printf (_("(unknown: %#" PRIx64
")"), uvalue
);
3159 case DW_AT_encoding
:
3163 case DW_ATE_void
: printf ("(void)"); break;
3164 case DW_ATE_address
: printf ("(machine address)"); break;
3165 case DW_ATE_boolean
: printf ("(boolean)"); break;
3166 case DW_ATE_complex_float
: printf ("(complex float)"); break;
3167 case DW_ATE_float
: printf ("(float)"); break;
3168 case DW_ATE_signed
: printf ("(signed)"); break;
3169 case DW_ATE_signed_char
: printf ("(signed char)"); break;
3170 case DW_ATE_unsigned
: printf ("(unsigned)"); break;
3171 case DW_ATE_unsigned_char
: printf ("(unsigned char)"); break;
3172 /* DWARF 2.1 values: */
3173 case DW_ATE_imaginary_float
: printf ("(imaginary float)"); break;
3174 case DW_ATE_decimal_float
: printf ("(decimal float)"); break;
3175 /* DWARF 3 values: */
3176 case DW_ATE_packed_decimal
: printf ("(packed_decimal)"); break;
3177 case DW_ATE_numeric_string
: printf ("(numeric_string)"); break;
3178 case DW_ATE_edited
: printf ("(edited)"); break;
3179 case DW_ATE_signed_fixed
: printf ("(signed_fixed)"); break;
3180 case DW_ATE_unsigned_fixed
: printf ("(unsigned_fixed)"); break;
3181 /* DWARF 4 values: */
3182 case DW_ATE_UTF
: printf ("(unicode string)"); break;
3183 /* DWARF 5 values: */
3184 case DW_ATE_UCS
: printf ("(UCS)"); break;
3185 case DW_ATE_ASCII
: printf ("(ASCII)"); break;
3187 /* HP extensions: */
3188 case DW_ATE_HP_float80
: printf ("(HP_float80)"); break;
3189 case DW_ATE_HP_complex_float80
: printf ("(HP_complex_float80)"); break;
3190 case DW_ATE_HP_float128
: printf ("(HP_float128)"); break;
3191 case DW_ATE_HP_complex_float128
:printf ("(HP_complex_float128)"); break;
3192 case DW_ATE_HP_floathpintel
: printf ("(HP_floathpintel)"); break;
3193 case DW_ATE_HP_imaginary_float80
: printf ("(HP_imaginary_float80)"); break;
3194 case DW_ATE_HP_imaginary_float128
: printf ("(HP_imaginary_float128)"); break;
3197 if (uvalue
>= DW_ATE_lo_user
3198 && uvalue
<= DW_ATE_hi_user
)
3199 printf (_("(user defined type)"));
3201 printf (_("(unknown type)"));
3206 case DW_AT_accessibility
:
3210 case DW_ACCESS_public
: printf ("(public)"); break;
3211 case DW_ACCESS_protected
: printf ("(protected)"); break;
3212 case DW_ACCESS_private
: printf ("(private)"); break;
3214 printf (_("(unknown accessibility)"));
3219 case DW_AT_visibility
:
3223 case DW_VIS_local
: printf ("(local)"); break;
3224 case DW_VIS_exported
: printf ("(exported)"); break;
3225 case DW_VIS_qualified
: printf ("(qualified)"); break;
3226 default: printf (_("(unknown visibility)")); break;
3230 case DW_AT_endianity
:
3234 case DW_END_default
: printf ("(default)"); break;
3235 case DW_END_big
: printf ("(big)"); break;
3236 case DW_END_little
: printf ("(little)"); break;
3238 if (uvalue
>= DW_END_lo_user
&& uvalue
<= DW_END_hi_user
)
3239 printf (_("(user specified)"));
3241 printf (_("(unknown endianity)"));
3246 case DW_AT_virtuality
:
3250 case DW_VIRTUALITY_none
: printf ("(none)"); break;
3251 case DW_VIRTUALITY_virtual
: printf ("(virtual)"); break;
3252 case DW_VIRTUALITY_pure_virtual
:printf ("(pure_virtual)"); break;
3253 default: printf (_("(unknown virtuality)")); break;
3257 case DW_AT_identifier_case
:
3261 case DW_ID_case_sensitive
: printf ("(case_sensitive)"); break;
3262 case DW_ID_up_case
: printf ("(up_case)"); break;
3263 case DW_ID_down_case
: printf ("(down_case)"); break;
3264 case DW_ID_case_insensitive
: printf ("(case_insensitive)"); break;
3265 default: printf (_("(unknown case)")); break;
3269 case DW_AT_calling_convention
:
3273 case DW_CC_normal
: printf ("(normal)"); break;
3274 case DW_CC_program
: printf ("(program)"); break;
3275 case DW_CC_nocall
: printf ("(nocall)"); break;
3276 case DW_CC_pass_by_reference
: printf ("(pass by ref)"); break;
3277 case DW_CC_pass_by_value
: printf ("(pass by value)"); break;
3278 case DW_CC_GNU_renesas_sh
: printf ("(Rensas SH)"); break;
3279 case DW_CC_GNU_borland_fastcall_i386
: printf ("(Borland fastcall i386)"); break;
3281 if (uvalue
>= DW_CC_lo_user
3282 && uvalue
<= DW_CC_hi_user
)
3283 printf (_("(user defined)"));
3285 printf (_("(unknown convention)"));
3289 case DW_AT_ordering
:
3294 case -1: printf (_("(undefined)")); break;
3295 case 0: printf ("(row major)"); break;
3296 case 1: printf ("(column major)"); break;
3300 case DW_AT_decimal_sign
:
3304 case DW_DS_unsigned
: printf (_("(unsigned)")); break;
3305 case DW_DS_leading_overpunch
: printf (_("(leading overpunch)")); break;
3306 case DW_DS_trailing_overpunch
: printf (_("(trailing overpunch)")); break;
3307 case DW_DS_leading_separate
: printf (_("(leading separate)")); break;
3308 case DW_DS_trailing_separate
: printf (_("(trailing separate)")); break;
3309 default: printf (_("(unrecognised)")); break;
3313 case DW_AT_defaulted
:
3317 case DW_DEFAULTED_no
: printf (_("(no)")); break;
3318 case DW_DEFAULTED_in_class
: printf (_("(in class)")); break;
3319 case DW_DEFAULTED_out_of_class
: printf (_("(out of class)")); break;
3320 default: printf (_("(unrecognised)")); break;
3324 case DW_AT_discr_list
:
3326 display_discr_list (form
, uvalue
, data
, level
);
3329 case DW_AT_frame_base
:
3330 have_frame_base
= 1;
3332 case DW_AT_location
:
3333 case DW_AT_loclists_base
:
3334 case DW_AT_rnglists_base
:
3335 case DW_AT_str_offsets_base
:
3336 case DW_AT_string_length
:
3337 case DW_AT_return_addr
:
3338 case DW_AT_data_member_location
:
3339 case DW_AT_vtable_elem_location
:
3341 case DW_AT_static_link
:
3342 case DW_AT_use_location
:
3343 case DW_AT_call_value
:
3344 case DW_AT_GNU_call_site_value
:
3345 case DW_AT_call_data_value
:
3346 case DW_AT_GNU_call_site_data_value
:
3347 case DW_AT_call_target
:
3348 case DW_AT_GNU_call_site_target
:
3349 case DW_AT_call_target_clobbered
:
3350 case DW_AT_GNU_call_site_target_clobbered
:
3351 if ((dwarf_version
< 4
3352 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
3353 || form
== DW_FORM_sec_offset
3354 || form
== DW_FORM_loclistx
)
3356 if (attribute
!= DW_AT_rnglists_base
3357 && attribute
!= DW_AT_str_offsets_base
)
3358 printf (_(" (location list)"));
3361 case DW_AT_allocated
:
3362 case DW_AT_associated
:
3363 case DW_AT_data_location
:
3365 case DW_AT_upper_bound
:
3366 case DW_AT_lower_bound
:
3370 int need_frame_base
;
3373 need_frame_base
= decode_location_expression (block_start
,
3378 cu_offset
, section
);
3380 if (need_frame_base
&& !have_frame_base
)
3381 printf (_(" [without DW_AT_frame_base]"));
3385 case DW_AT_data_bit_offset
:
3386 case DW_AT_byte_size
:
3387 case DW_AT_bit_size
:
3388 case DW_AT_string_length_byte_size
:
3389 case DW_AT_string_length_bit_size
:
3390 case DW_AT_bit_stride
:
3391 if (form
== DW_FORM_exprloc
)
3394 (void) decode_location_expression (block_start
, pointer_size
,
3395 offset_size
, dwarf_version
,
3396 uvalue
, cu_offset
, section
);
3403 unsigned long abbrev_number
;
3404 abbrev_entry
*entry
;
3406 entry
= get_type_abbrev_from_form (form
, uvalue
, cu_offset
, end
,
3407 section
, & abbrev_number
, NULL
, NULL
);
3410 if (form
!= DW_FORM_GNU_ref_alt
)
3411 warn (_("Offset %#" PRIx64
" used as value for DW_AT_import attribute of DIE at offset %#tx is too big.\n"),
3413 orig_data
- section
->start
);
3417 printf (_("\t[Abbrev Number: %ld"), abbrev_number
);
3418 printf (" (%s)", get_TAG_name (entry
->tag
));
3431 static unsigned char *
3432 read_and_display_attr (unsigned long attribute
,
3434 int64_t implicit_const
,
3435 unsigned char *start
,
3436 unsigned char *data
,
3439 uint64_t pointer_size
,
3440 uint64_t offset_size
,
3442 debug_info
*debug_info_p
,
3444 struct dwarf_section
*section
,
3445 struct cu_tu_set
*this_set
,
3449 printf (" %-18s:", get_AT_name (attribute
));
3450 data
= read_and_display_attr_value (attribute
, form
, implicit_const
,
3452 cu_offset
, pointer_size
, offset_size
,
3453 dwarf_version
, debug_info_p
,
3454 do_loc
, section
, this_set
, ' ', level
);
3460 /* Like load_debug_section, but if the ordinary call fails, and we are
3461 following debug links, then attempt to load the requested section
3462 from one of the separate debug info files. */
3465 load_debug_section_with_follow (enum dwarf_section_display_enum sec_enum
,
3468 if (load_debug_section (sec_enum
, handle
))
3470 if (debug_displays
[sec_enum
].section
.filename
== NULL
)
3472 /* See if we can associate a filename with this section. */
3475 for (i
= first_separate_info
; i
!= NULL
; i
= i
->next
)
3476 if (i
->handle
== handle
)
3478 debug_displays
[sec_enum
].section
.filename
= i
->filename
;
3486 if (do_follow_links
)
3490 for (i
= first_separate_info
; i
!= NULL
; i
= i
->next
)
3492 if (load_debug_section (sec_enum
, i
->handle
))
3494 debug_displays
[sec_enum
].section
.filename
= i
->filename
;
3496 /* FIXME: We should check to see if any of the remaining debug info
3497 files also contain this section, and, umm, do something about it. */
3507 introduce (struct dwarf_section
* section
, bool raw
)
3511 if (do_follow_links
&& section
->filename
)
3512 printf (_("Raw dump of debug contents of section %s (loaded from %s):\n\n"),
3513 section
->name
, section
->filename
);
3515 printf (_("Raw dump of debug contents of section %s:\n\n"), section
->name
);
3519 if (do_follow_links
&& section
->filename
)
3520 printf (_("Contents of the %s section (loaded from %s):\n\n"),
3521 section
->name
, section
->filename
);
3523 printf (_("Contents of the %s section:\n\n"), section
->name
);
3527 /* Free memory allocated for one unit in debug_information. */
3530 free_debug_information (debug_info
*ent
)
3532 if (ent
->max_loc_offsets
)
3534 free (ent
->loc_offsets
);
3535 free (ent
->loc_views
);
3536 free (ent
->have_frame_base
);
3538 if (ent
->max_range_lists
)
3539 free (ent
->range_lists
);
3542 /* Process the contents of a .debug_info section.
3543 If do_loc is TRUE then we are scanning for location lists and dwo tags
3544 and we do not want to display anything to the user.
3545 If do_types is TRUE, we are processing a .debug_types section instead of
3546 a .debug_info section.
3547 The information displayed is restricted by the values in DWARF_START_DIE
3548 and DWARF_CUTOFF_LEVEL.
3549 Returns TRUE upon success. Otherwise an error or warning message is
3550 printed and FALSE is returned. */
3553 process_debug_info (struct dwarf_section
* section
,
3555 enum dwarf_section_display_enum abbrev_sec
,
3559 unsigned char *start
= section
->start
;
3560 unsigned char *end
= start
+ section
->size
;
3561 unsigned char *section_begin
;
3563 unsigned int num_units
= 0;
3565 /* First scan the section to get the number of comp units.
3566 Length sanity checks are done here. */
3567 for (section_begin
= start
, num_units
= 0; section_begin
< end
;
3572 /* Read the first 4 bytes. For a 32-bit DWARF section, this
3573 will be the length. For a 64-bit DWARF section, it'll be
3574 the escape code 0xffffffff followed by an 8 byte length. */
3575 SAFE_BYTE_GET_AND_INC (length
, section_begin
, 4, end
);
3577 if (length
== 0xffffffff)
3578 SAFE_BYTE_GET_AND_INC (length
, section_begin
, 8, end
);
3579 else if (length
>= 0xfffffff0 && length
< 0xffffffff)
3581 warn (_("Reserved length value (%#" PRIx64
") found in section %s\n"),
3582 length
, section
->name
);
3586 /* Negative values are illegal, they may even cause infinite
3587 looping. This can happen if we can't accurately apply
3588 relocations to an object file, or if the file is corrupt. */
3589 if (length
> (size_t) (end
- section_begin
))
3591 warn (_("Corrupt unit length (got %#" PRIx64
3592 " expected at most %#tx) in section %s\n"),
3593 length
, end
- section_begin
, section
->name
);
3596 section_begin
+= length
;
3601 error (_("No comp units in %s section ?\n"), section
->name
);
3605 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
|| do_debug_info
)
3606 && num_debug_info_entries
== 0
3610 /* Then allocate an array to hold the information. */
3611 debug_information
= (debug_info
*) cmalloc (num_units
,
3612 sizeof (* debug_information
));
3613 if (debug_information
== NULL
)
3615 error (_("Not enough memory for a debug info array of %u entries\n"),
3617 alloc_num_debug_info_entries
= num_debug_info_entries
= 0;
3621 /* PR 17531: file: 92ca3797.
3622 We cannot rely upon the debug_information array being initialised
3623 before it is used. A corrupt file could easily contain references
3624 to a unit for which information has not been made available. So
3625 we ensure that the array is zeroed here. */
3626 memset (debug_information
, 0, num_units
* sizeof (*debug_information
));
3628 alloc_num_debug_info_entries
= num_units
;
3633 load_debug_section_with_follow (str
, file
);
3634 load_debug_section_with_follow (line_str
, file
);
3635 load_debug_section_with_follow (str_dwo
, file
);
3636 load_debug_section_with_follow (str_index
, file
);
3637 load_debug_section_with_follow (str_index_dwo
, file
);
3638 load_debug_section_with_follow (debug_addr
, file
);
3641 load_debug_section_with_follow (abbrev_sec
, file
);
3642 load_debug_section_with_follow (loclists
, file
);
3643 load_debug_section_with_follow (rnglists
, file
);
3644 load_debug_section_with_follow (loclists_dwo
, file
);
3645 load_debug_section_with_follow (rnglists_dwo
, file
);
3647 if (debug_displays
[abbrev_sec
].section
.start
== NULL
)
3649 warn (_("Unable to locate %s section!\n"),
3650 debug_displays
[abbrev_sec
].section
.uncompressed_name
);
3654 if (!do_loc
&& dwarf_start_die
== 0)
3655 introduce (section
, false);
3657 free_all_abbrevs ();
3659 /* In order to be able to resolve DW_FORM_ref_addr forms we need
3660 to load *all* of the abbrevs for all CUs in this .debug_info
3661 section. This does effectively mean that we (partially) read
3662 every CU header twice. */
3663 for (section_begin
= start
; start
< end
;)
3665 DWARF2_Internal_CompUnit compunit
;
3666 unsigned char *hdrptr
;
3667 uint64_t abbrev_base
;
3670 unsigned int offset_size
;
3671 struct cu_tu_set
*this_set
;
3672 unsigned char *end_cu
;
3675 cu_offset
= start
- section_begin
;
3677 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 4, end
);
3679 if (compunit
.cu_length
== 0xffffffff)
3681 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 8, end
);
3686 end_cu
= hdrptr
+ compunit
.cu_length
;
3688 SAFE_BYTE_GET_AND_INC (compunit
.cu_version
, hdrptr
, 2, end_cu
);
3690 this_set
= find_cu_tu_set_v2 (cu_offset
, do_types
);
3692 if (compunit
.cu_version
< 5)
3694 compunit
.cu_unit_type
= DW_UT_compile
;
3695 /* Initialize it due to a false compiler warning. */
3696 compunit
.cu_pointer_size
= -1;
3700 SAFE_BYTE_GET_AND_INC (compunit
.cu_unit_type
, hdrptr
, 1, end_cu
);
3701 do_types
= (compunit
.cu_unit_type
== DW_UT_type
);
3703 SAFE_BYTE_GET_AND_INC (compunit
.cu_pointer_size
, hdrptr
, 1, end_cu
);
3706 SAFE_BYTE_GET_AND_INC (compunit
.cu_abbrev_offset
, hdrptr
, offset_size
,
3709 if (compunit
.cu_unit_type
== DW_UT_split_compile
3710 || compunit
.cu_unit_type
== DW_UT_skeleton
)
3713 SAFE_BYTE_GET_AND_INC (dwo_id
, hdrptr
, 8, end_cu
);
3716 if (this_set
== NULL
)
3719 abbrev_size
= debug_displays
[abbrev_sec
].section
.size
;
3723 abbrev_base
= this_set
->section_offsets
[DW_SECT_ABBREV
];
3724 abbrev_size
= this_set
->section_sizes
[DW_SECT_ABBREV
];
3728 abbrev_list
*free_list
;
3729 list
= find_and_process_abbrev_set (&debug_displays
[abbrev_sec
].section
,
3730 abbrev_base
, abbrev_size
,
3731 compunit
.cu_abbrev_offset
,
3734 if (list
!= NULL
&& list
->first_abbrev
!= NULL
)
3735 record_abbrev_list_for_cu (cu_offset
, start
- section_begin
,
3737 else if (free_list
!= NULL
)
3738 free_abbrev_list (free_list
);
3741 for (start
= section_begin
, unit
= 0; start
< end
; unit
++)
3743 DWARF2_Internal_CompUnit compunit
;
3744 unsigned char *hdrptr
;
3745 unsigned char *tags
;
3746 int level
, last_level
, saved_level
;
3748 unsigned int offset_size
;
3749 uint64_t signature
= 0;
3750 uint64_t type_offset
= 0;
3751 struct cu_tu_set
*this_set
;
3752 uint64_t abbrev_base
;
3754 unsigned char *end_cu
;
3757 cu_offset
= start
- section_begin
;
3759 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 4, end
);
3761 if (compunit
.cu_length
== 0xffffffff)
3763 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 8, end
);
3768 end_cu
= hdrptr
+ compunit
.cu_length
;
3770 SAFE_BYTE_GET_AND_INC (compunit
.cu_version
, hdrptr
, 2, end_cu
);
3772 this_set
= find_cu_tu_set_v2 (cu_offset
, do_types
);
3774 if (compunit
.cu_version
< 5)
3776 compunit
.cu_unit_type
= DW_UT_compile
;
3777 /* Initialize it due to a false compiler warning. */
3778 compunit
.cu_pointer_size
= -1;
3782 SAFE_BYTE_GET_AND_INC (compunit
.cu_unit_type
, hdrptr
, 1, end_cu
);
3783 do_types
= (compunit
.cu_unit_type
== DW_UT_type
);
3785 SAFE_BYTE_GET_AND_INC (compunit
.cu_pointer_size
, hdrptr
, 1, end_cu
);
3788 SAFE_BYTE_GET_AND_INC (compunit
.cu_abbrev_offset
, hdrptr
, offset_size
, end_cu
);
3790 if (this_set
== NULL
)
3793 abbrev_size
= debug_displays
[abbrev_sec
].section
.size
;
3797 abbrev_base
= this_set
->section_offsets
[DW_SECT_ABBREV
];
3798 abbrev_size
= this_set
->section_sizes
[DW_SECT_ABBREV
];
3801 if (compunit
.cu_version
< 5)
3802 SAFE_BYTE_GET_AND_INC (compunit
.cu_pointer_size
, hdrptr
, 1, end_cu
);
3804 bool do_dwo_id
= false;
3805 uint64_t dwo_id
= 0;
3806 if (compunit
.cu_unit_type
== DW_UT_split_compile
3807 || compunit
.cu_unit_type
== DW_UT_skeleton
)
3809 SAFE_BYTE_GET_AND_INC (dwo_id
, hdrptr
, 8, end_cu
);
3813 /* PR 17512: file: 001-108546-0.001:0.1. */
3814 if (compunit
.cu_pointer_size
< 2 || compunit
.cu_pointer_size
> 8)
3816 warn (_("Invalid pointer size (%d) in compunit header, using %d instead\n"),
3817 compunit
.cu_pointer_size
, offset_size
);
3818 compunit
.cu_pointer_size
= offset_size
;
3823 SAFE_BYTE_GET_AND_INC (signature
, hdrptr
, 8, end_cu
);
3824 SAFE_BYTE_GET_AND_INC (type_offset
, hdrptr
, offset_size
, end_cu
);
3827 if (dwarf_start_die
>= (size_t) (end_cu
- section_begin
))
3833 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
|| do_debug_info
)
3834 && num_debug_info_entries
== 0
3835 && alloc_num_debug_info_entries
> unit
3838 free_debug_information (&debug_information
[unit
]);
3839 memset (&debug_information
[unit
], 0, sizeof (*debug_information
));
3840 debug_information
[unit
].pointer_size
= compunit
.cu_pointer_size
;
3841 debug_information
[unit
].offset_size
= offset_size
;
3842 debug_information
[unit
].dwarf_version
= compunit
.cu_version
;
3843 debug_information
[unit
].cu_offset
= cu_offset
;
3844 debug_information
[unit
].addr_base
= DEBUG_INFO_UNAVAILABLE
;
3845 debug_information
[unit
].ranges_base
= DEBUG_INFO_UNAVAILABLE
;
3848 if (!do_loc
&& dwarf_start_die
== 0)
3850 printf (_(" Compilation Unit @ offset %#" PRIx64
":\n"),
3852 printf (_(" Length: %#" PRIx64
" (%s)\n"),
3854 offset_size
== 8 ? "64-bit" : "32-bit");
3855 printf (_(" Version: %d\n"), compunit
.cu_version
);
3856 if (compunit
.cu_version
>= 5)
3858 const char *name
= get_DW_UT_name (compunit
.cu_unit_type
);
3860 printf (_(" Unit Type: %s (%x)\n"),
3862 compunit
.cu_unit_type
);
3864 printf (_(" Abbrev Offset: %#" PRIx64
"\n"),
3865 compunit
.cu_abbrev_offset
);
3866 printf (_(" Pointer Size: %d\n"), compunit
.cu_pointer_size
);
3869 printf (_(" Signature: %#" PRIx64
"\n"), signature
);
3870 printf (_(" Type Offset: %#" PRIx64
"\n"), type_offset
);
3873 printf (_(" DWO ID: %#" PRIx64
"\n"), dwo_id
);
3874 if (this_set
!= NULL
)
3876 uint64_t *offsets
= this_set
->section_offsets
;
3877 size_t *sizes
= this_set
->section_sizes
;
3879 printf (_(" Section contributions:\n"));
3880 printf (_(" .debug_abbrev.dwo: %#" PRIx64
" %#zx\n"),
3881 offsets
[DW_SECT_ABBREV
], sizes
[DW_SECT_ABBREV
]);
3882 printf (_(" .debug_line.dwo: %#" PRIx64
" %#zx\n"),
3883 offsets
[DW_SECT_LINE
], sizes
[DW_SECT_LINE
]);
3884 printf (_(" .debug_loc.dwo: %#" PRIx64
" %#zx\n"),
3885 offsets
[DW_SECT_LOC
], sizes
[DW_SECT_LOC
]);
3886 printf (_(" .debug_str_offsets.dwo: %#" PRIx64
" %#zx\n"),
3887 offsets
[DW_SECT_STR_OFFSETS
], sizes
[DW_SECT_STR_OFFSETS
]);
3894 if (compunit
.cu_version
< 2 || compunit
.cu_version
> 5)
3896 warn (_("CU at offset %#" PRIx64
" contains corrupt or "
3897 "unsupported version number: %d.\n"),
3898 cu_offset
, compunit
.cu_version
);
3902 if (compunit
.cu_unit_type
!= DW_UT_compile
3903 && compunit
.cu_unit_type
!= DW_UT_partial
3904 && compunit
.cu_unit_type
!= DW_UT_type
3905 && compunit
.cu_unit_type
!= DW_UT_split_compile
3906 && compunit
.cu_unit_type
!= DW_UT_skeleton
)
3908 warn (_("CU at offset %#" PRIx64
" contains corrupt or "
3909 "unsupported unit type: %d.\n"),
3910 cu_offset
, compunit
.cu_unit_type
);
3914 /* Process the abbrevs used by this compilation unit. */
3916 list
= find_and_process_abbrev_set (&debug_displays
[abbrev_sec
].section
,
3917 abbrev_base
, abbrev_size
,
3918 compunit
.cu_abbrev_offset
, NULL
);
3922 while (tags
< start
)
3924 unsigned long abbrev_number
;
3925 unsigned long die_offset
;
3926 abbrev_entry
*entry
;
3928 int do_printing
= 1;
3930 die_offset
= tags
- section_begin
;
3932 READ_ULEB (abbrev_number
, tags
, start
);
3934 /* A null DIE marks the end of a list of siblings or it may also be
3935 a section padding. */
3936 if (abbrev_number
== 0)
3938 /* Check if it can be a section padding for the last CU. */
3939 if (level
== 0 && start
== end
)
3943 for (chk
= tags
; chk
< start
; chk
++)
3950 if (!do_loc
&& die_offset
>= dwarf_start_die
3951 && (dwarf_cutoff_level
== -1
3952 || level
< dwarf_cutoff_level
))
3953 printf (_(" <%d><%lx>: Abbrev Number: 0\n"),
3959 static unsigned num_bogus_warns
= 0;
3961 if (num_bogus_warns
< 3)
3963 warn (_("Bogus end-of-siblings marker detected at offset %lx in %s section\n"),
3964 die_offset
, section
->name
);
3966 if (num_bogus_warns
== 3)
3967 warn (_("Further warnings about bogus end-of-sibling markers suppressed\n"));
3970 if (dwarf_start_die
!= 0 && level
< saved_level
)
3977 if (dwarf_start_die
!= 0 && die_offset
< dwarf_start_die
)
3981 if (dwarf_start_die
!= 0 && die_offset
== dwarf_start_die
)
3982 saved_level
= level
;
3983 do_printing
= (dwarf_cutoff_level
== -1
3984 || level
< dwarf_cutoff_level
);
3986 printf (_(" <%d><%lx>: Abbrev Number: %lu"),
3987 level
, die_offset
, abbrev_number
);
3988 else if (dwarf_cutoff_level
== -1
3989 || last_level
< dwarf_cutoff_level
)
3990 printf (_(" <%d><%lx>: ...\n"), level
, die_offset
);
3995 /* Scan through the abbreviation list until we reach the
3999 for (entry
= list
->first_abbrev
; entry
!= NULL
; entry
= entry
->next
)
4000 if (entry
->number
== abbrev_number
)
4005 if (!do_loc
&& do_printing
)
4010 warn (_("DIE at offset %#lx refers to abbreviation number %lu which does not exist\n"),
4011 die_offset
, abbrev_number
);
4015 if (!do_loc
&& do_printing
)
4016 printf (" (%s)\n", get_TAG_name (entry
->tag
));
4021 need_base_address
= 0;
4023 case DW_TAG_compile_unit
:
4024 case DW_TAG_skeleton_unit
:
4025 need_base_address
= 1;
4026 need_dwo_info
= do_loc
;
4028 case DW_TAG_entry_point
:
4029 case DW_TAG_subprogram
:
4030 need_base_address
= 0;
4031 /* Assuming that there is no DW_AT_frame_base. */
4032 have_frame_base
= 0;
4036 debug_info
*debug_info_p
=
4037 (debug_information
&& unit
< alloc_num_debug_info_entries
)
4038 ? debug_information
+ unit
: NULL
;
4040 assert (!debug_info_p
4041 || (debug_info_p
->num_loc_offsets
4042 == debug_info_p
->num_loc_views
));
4044 for (attr
= entry
->first_attr
;
4045 attr
&& attr
->attribute
;
4048 if (! do_loc
&& do_printing
)
4049 /* Show the offset from where the tag was extracted. */
4050 printf (" <%tx>", tags
- section_begin
);
4051 tags
= read_and_display_attr (attr
->attribute
,
4053 attr
->implicit_const
,
4058 compunit
.cu_pointer_size
,
4060 compunit
.cu_version
,
4062 do_loc
|| ! do_printing
,
4068 /* If a locview attribute appears before a location one,
4069 make sure we don't associate it with an earlier
4072 switch (debug_info_p
->num_loc_offsets
- debug_info_p
->num_loc_views
)
4075 debug_info_p
->loc_views
[debug_info_p
->num_loc_views
] = -1;
4076 debug_info_p
->num_loc_views
++;
4077 assert (debug_info_p
->num_loc_views
4078 == debug_info_p
->num_loc_offsets
);
4085 warn(_("DIE has locviews without loclist\n"));
4086 debug_info_p
->num_loc_views
--;
4093 if (entry
->children
)
4097 free_abbrev_list (list
);
4100 /* Set num_debug_info_entries here so that it can be used to check if
4101 we need to process .debug_loc and .debug_ranges sections. */
4102 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
|| do_debug_info
)
4103 && num_debug_info_entries
== 0
4106 if (num_units
> alloc_num_debug_info_entries
)
4107 num_debug_info_entries
= alloc_num_debug_info_entries
;
4109 num_debug_info_entries
= num_units
;
4118 /* Locate and scan the .debug_info section in the file and record the pointer
4119 sizes and offsets for the compilation units in it. Usually an executable
4120 will have just one pointer size, but this is not guaranteed, and so we try
4121 not to make any assumptions. Returns zero upon failure, or the number of
4122 compilation units upon success. */
4125 load_debug_info (void * file
)
4127 /* If we have already tried and failed to load the .debug_info
4128 section then do not bother to repeat the task. */
4129 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
4132 /* If we already have the information there is nothing else to do. */
4133 if (num_debug_info_entries
> 0)
4134 return num_debug_info_entries
;
4136 /* If this is a DWARF package file, load the CU and TU indexes. */
4137 (void) load_cu_tu_indexes (file
);
4139 if (load_debug_section_with_follow (info
, file
)
4140 && process_debug_info (&debug_displays
[info
].section
, file
, abbrev
, true, false))
4141 return num_debug_info_entries
;
4143 if (load_debug_section_with_follow (info_dwo
, file
)
4144 && process_debug_info (&debug_displays
[info_dwo
].section
, file
,
4145 abbrev_dwo
, true, false))
4146 return num_debug_info_entries
;
4148 num_debug_info_entries
= DEBUG_INFO_UNAVAILABLE
;
4152 /* Read a DWARF .debug_line section header starting at DATA.
4153 Upon success returns an updated DATA pointer and the LINFO
4154 structure and the END_OF_SEQUENCE pointer will be filled in.
4155 Otherwise returns NULL. */
4157 static unsigned char *
4158 read_debug_line_header (struct dwarf_section
* section
,
4159 unsigned char * data
,
4160 unsigned char * end
,
4161 DWARF2_Internal_LineInfo
* linfo
,
4162 unsigned char ** end_of_sequence
)
4164 unsigned char *hdrptr
;
4166 /* Extract information from the Line Number Program Header.
4167 (section 6.2.4 in the Dwarf3 doc). */
4170 /* Get and check the length of the block. */
4171 SAFE_BYTE_GET_AND_INC (linfo
->li_length
, hdrptr
, 4, end
);
4173 if (linfo
->li_length
== 0xffffffff)
4175 /* This section is 64-bit DWARF 3. */
4176 SAFE_BYTE_GET_AND_INC (linfo
->li_length
, hdrptr
, 8, end
);
4177 linfo
->li_offset_size
= 8;
4180 linfo
->li_offset_size
= 4;
4182 if (linfo
->li_length
> (size_t) (end
- hdrptr
))
4184 /* If the length field has a relocation against it, then we should
4185 not complain if it is inaccurate (and probably negative). This
4186 happens in object files when the .debug_line section is actually
4187 comprised of several different .debug_line.* sections, (some of
4188 which may be removed by linker garbage collection), and a relocation
4189 is used to compute the correct length once that is done. */
4190 if (reloc_at (section
, (hdrptr
- section
->start
) - linfo
->li_offset_size
))
4192 linfo
->li_length
= end
- hdrptr
;
4196 warn (_("The length field (%#" PRIx64
")"
4197 " in the debug_line header is wrong"
4198 " - the section is too small\n"),
4203 end
= hdrptr
+ linfo
->li_length
;
4205 /* Get and check the version number. */
4206 SAFE_BYTE_GET_AND_INC (linfo
->li_version
, hdrptr
, 2, end
);
4208 if (linfo
->li_version
!= 2
4209 && linfo
->li_version
!= 3
4210 && linfo
->li_version
!= 4
4211 && linfo
->li_version
!= 5)
4213 warn (_("Only DWARF version 2, 3, 4 and 5 line info "
4214 "is currently supported.\n"));
4218 if (linfo
->li_version
>= 5)
4220 SAFE_BYTE_GET_AND_INC (linfo
->li_address_size
, hdrptr
, 1, end
);
4222 SAFE_BYTE_GET_AND_INC (linfo
->li_segment_size
, hdrptr
, 1, end
);
4223 if (linfo
->li_segment_size
!= 0)
4225 warn (_("The %s section contains "
4226 "unsupported segment selector size: %d.\n"),
4227 section
->name
, linfo
->li_segment_size
);
4232 SAFE_BYTE_GET_AND_INC (linfo
->li_prologue_length
, hdrptr
,
4233 linfo
->li_offset_size
, end
);
4234 SAFE_BYTE_GET_AND_INC (linfo
->li_min_insn_length
, hdrptr
, 1, end
);
4236 if (linfo
->li_version
>= 4)
4238 SAFE_BYTE_GET_AND_INC (linfo
->li_max_ops_per_insn
, hdrptr
, 1, end
);
4240 if (linfo
->li_max_ops_per_insn
== 0)
4242 warn (_("Invalid maximum operations per insn.\n"));
4247 linfo
->li_max_ops_per_insn
= 1;
4249 SAFE_BYTE_GET_AND_INC (linfo
->li_default_is_stmt
, hdrptr
, 1, end
);
4250 SAFE_SIGNED_BYTE_GET_AND_INC (linfo
->li_line_base
, hdrptr
, 1, end
);
4251 SAFE_BYTE_GET_AND_INC (linfo
->li_line_range
, hdrptr
, 1, end
);
4252 SAFE_BYTE_GET_AND_INC (linfo
->li_opcode_base
, hdrptr
, 1, end
);
4254 *end_of_sequence
= end
;
4258 static unsigned char *
4259 display_formatted_table (unsigned char *data
,
4260 unsigned char *start
,
4262 const DWARF2_Internal_LineInfo
*linfo
,
4263 struct dwarf_section
*section
,
4266 unsigned char *format_start
, format_count
, *format
, formati
;
4267 uint64_t data_count
, datai
;
4268 unsigned int namepass
, last_entry
= 0;
4269 const char * table_name
= is_dir
? N_("Directory Table") : N_("File Name Table");
4271 SAFE_BYTE_GET_AND_INC (format_count
, data
, 1, end
);
4272 if (do_checks
&& format_count
> 5)
4273 warn (_("Unexpectedly large number of columns in the %s (%u)\n"),
4274 table_name
, format_count
);
4276 format_start
= data
;
4277 for (formati
= 0; formati
< format_count
; formati
++)
4279 SKIP_ULEB (data
, end
);
4280 SKIP_ULEB (data
, end
);
4283 warn (_("%s: Corrupt format description entry\n"), table_name
);
4288 READ_ULEB (data_count
, data
, end
);
4289 if (data_count
== 0)
4291 printf (_("\n The %s is empty.\n"), table_name
);
4294 else if (data
>= end
)
4296 warn (_("%s: Corrupt entry count - expected %#" PRIx64
4297 " but none found\n"), table_name
, data_count
);
4301 else if (format_count
== 0)
4303 warn (_("%s: format count is zero, but the table is not empty\n"),
4308 printf (_("\n The %s (offset %#tx, lines %" PRIu64
", columns %u):\n"),
4309 table_name
, data
- start
, data_count
, format_count
);
4311 printf (_(" Entry"));
4312 /* Delay displaying name as the last entry for better screen layout. */
4313 for (namepass
= 0; namepass
< 2; namepass
++)
4315 format
= format_start
;
4316 for (formati
= 0; formati
< format_count
; formati
++)
4318 uint64_t content_type
;
4320 READ_ULEB (content_type
, format
, end
);
4321 if ((content_type
== DW_LNCT_path
) == (namepass
== 1))
4322 switch (content_type
)
4325 printf (_("\tName"));
4327 case DW_LNCT_directory_index
:
4328 printf (_("\tDir"));
4330 case DW_LNCT_timestamp
:
4331 printf (_("\tTime"));
4334 printf (_("\tSize"));
4337 printf (_("\tMD5\t\t\t"));
4340 printf (_("\t(Unknown format content type %" PRIu64
")"),
4343 SKIP_ULEB (format
, end
);
4348 for (datai
= 0; datai
< data_count
; datai
++)
4350 unsigned char *datapass
= data
;
4352 printf (" %d", last_entry
++);
4353 /* Delay displaying name as the last entry for better screen layout. */
4354 for (namepass
= 0; namepass
< 2; namepass
++)
4356 format
= format_start
;
4358 for (formati
= 0; formati
< format_count
; formati
++)
4360 uint64_t content_type
, form
;
4362 READ_ULEB (content_type
, format
, end
);
4363 READ_ULEB (form
, format
, end
);
4364 data
= read_and_display_attr_value (0, form
, 0, start
, data
, end
,
4365 0, 0, linfo
->li_offset_size
,
4366 linfo
->li_version
, NULL
,
4367 ((content_type
== DW_LNCT_path
) != (namepass
== 1)),
4368 section
, NULL
, '\t', -1);
4372 if (data
>= end
&& (datai
< data_count
- 1))
4374 warn (_("\n%s: Corrupt entries list\n"), table_name
);
4383 display_debug_sup (struct dwarf_section
* section
,
4384 void * file ATTRIBUTE_UNUSED
)
4386 unsigned char * start
= section
->start
;
4387 unsigned char * end
= section
->start
+ section
->size
;
4388 unsigned int version
;
4389 char is_supplementary
;
4390 const unsigned char * sup_filename
;
4391 size_t sup_filename_len
;
4392 unsigned int num_read
;
4394 uint64_t checksum_len
;
4397 introduce (section
, true);
4398 if (section
->size
< 4)
4400 error (_("corrupt .debug_sup section: size is too small\n"));
4404 /* Read the data. */
4405 SAFE_BYTE_GET_AND_INC (version
, start
, 2, end
);
4407 warn (_("corrupt .debug_sup section: version < 5"));
4409 SAFE_BYTE_GET_AND_INC (is_supplementary
, start
, 1, end
);
4410 if (is_supplementary
!= 0 && is_supplementary
!= 1)
4411 warn (_("corrupt .debug_sup section: is_supplementary not 0 or 1\n"));
4413 sup_filename
= start
;
4414 if (is_supplementary
&& sup_filename
[0] != 0)
4415 warn (_("corrupt .debug_sup section: filename not empty in supplementary section\n"));
4417 sup_filename_len
= strnlen ((const char *) start
, end
- start
);
4418 if (sup_filename_len
== (size_t) (end
- start
))
4420 error (_("corrupt .debug_sup section: filename is not NUL terminated\n"));
4423 start
+= sup_filename_len
+ 1;
4425 checksum_len
= read_leb128 (start
, end
, false /* unsigned */, & num_read
, & status
);
4428 error (_("corrupt .debug_sup section: bad LEB128 field for checksum length\n"));
4432 if (checksum_len
> (size_t) (end
- start
))
4434 error (_("corrupt .debug_sup section: checksum length is longer than the remaining section length\n"));
4435 checksum_len
= end
- start
;
4437 else if (checksum_len
< (size_t) (end
- start
))
4439 warn (_("corrupt .debug_sup section: there are %#" PRIx64
4440 " extra, unused bytes at the end of the section\n"),
4441 (end
- start
) - checksum_len
);
4444 printf (_(" Version: %u\n"), version
);
4445 printf (_(" Is Supp: %u\n"), is_supplementary
);
4446 printf (_(" Filename: %s\n"), sup_filename
);
4447 printf (_(" Checksum Len: %" PRIu64
"\n"), checksum_len
);
4448 if (checksum_len
> 0)
4450 printf (_(" Checksum: "));
4451 while (checksum_len
--)
4452 printf ("0x%x ", * start
++ );
4459 display_debug_lines_raw (struct dwarf_section
* section
,
4460 unsigned char * data
,
4461 unsigned char * end
,
4464 unsigned char *start
= section
->start
;
4465 int verbose_view
= 0;
4467 introduce (section
, true);
4471 static DWARF2_Internal_LineInfo saved_linfo
;
4472 DWARF2_Internal_LineInfo linfo
;
4473 unsigned char *standard_opcodes
;
4474 unsigned char *end_of_sequence
;
4477 if (startswith (section
->name
, ".debug_line.")
4478 /* Note: the following does not apply to .debug_line.dwo sections.
4479 These are full debug_line sections. */
4480 && strcmp (section
->name
, ".debug_line.dwo") != 0)
4482 /* Sections named .debug_line.<foo> are fragments of a .debug_line
4483 section containing just the Line Number Statements. They are
4484 created by the assembler and intended to be used alongside gcc's
4485 -ffunction-sections command line option. When the linker's
4486 garbage collection decides to discard a .text.<foo> section it
4487 can then also discard the line number information in .debug_line.<foo>.
4489 Since the section is a fragment it does not have the details
4490 needed to fill out a LineInfo structure, so instead we use the
4491 details from the last full debug_line section that we processed. */
4492 end_of_sequence
= end
;
4493 standard_opcodes
= NULL
;
4494 linfo
= saved_linfo
;
4495 /* PR 17531: file: 0522b371. */
4496 if (linfo
.li_line_range
== 0)
4498 warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n"));
4501 reset_state_machine (linfo
.li_default_is_stmt
);
4505 unsigned char * hdrptr
;
4507 if ((hdrptr
= read_debug_line_header (section
, data
, end
, & linfo
,
4508 & end_of_sequence
)) == NULL
)
4511 printf (_(" Offset: %#tx\n"), data
- start
);
4512 printf (_(" Length: %" PRId64
"\n"), linfo
.li_length
);
4513 printf (_(" DWARF Version: %d\n"), linfo
.li_version
);
4514 if (linfo
.li_version
>= 5)
4516 printf (_(" Address size (bytes): %d\n"), linfo
.li_address_size
);
4517 printf (_(" Segment selector (bytes): %d\n"), linfo
.li_segment_size
);
4519 printf (_(" Prologue Length: %d\n"), (int) linfo
.li_prologue_length
);
4520 printf (_(" Minimum Instruction Length: %d\n"), linfo
.li_min_insn_length
);
4521 if (linfo
.li_version
>= 4)
4522 printf (_(" Maximum Ops per Instruction: %d\n"), linfo
.li_max_ops_per_insn
);
4523 printf (_(" Initial value of 'is_stmt': %d\n"), linfo
.li_default_is_stmt
);
4524 printf (_(" Line Base: %d\n"), linfo
.li_line_base
);
4525 printf (_(" Line Range: %d\n"), linfo
.li_line_range
);
4526 printf (_(" Opcode Base: %d\n"), linfo
.li_opcode_base
);
4528 /* PR 17512: file: 1665-6428-0.004. */
4529 if (linfo
.li_line_range
== 0)
4531 warn (_("Line range of 0 is invalid, using 1 instead\n"));
4532 linfo
.li_line_range
= 1;
4535 reset_state_machine (linfo
.li_default_is_stmt
);
4537 /* Display the contents of the Opcodes table. */
4538 standard_opcodes
= hdrptr
;
4540 /* PR 17512: file: 002-417945-0.004. */
4541 if (standard_opcodes
+ linfo
.li_opcode_base
>= end
)
4543 warn (_("Line Base extends beyond end of section\n"));
4547 printf (_("\n Opcodes:\n"));
4549 for (i
= 1; i
< linfo
.li_opcode_base
; i
++)
4550 printf (ngettext (" Opcode %d has %d arg\n",
4551 " Opcode %d has %d args\n",
4552 standard_opcodes
[i
- 1]),
4553 i
, standard_opcodes
[i
- 1]);
4555 /* Display the contents of the Directory table. */
4556 data
= standard_opcodes
+ linfo
.li_opcode_base
- 1;
4558 if (linfo
.li_version
>= 5)
4560 load_debug_section_with_follow (line_str
, file
);
4562 data
= display_formatted_table (data
, start
, end
, &linfo
, section
,
4564 data
= display_formatted_table (data
, start
, end
, &linfo
, section
,
4570 printf (_("\n The Directory Table is empty.\n"));
4573 unsigned int last_dir_entry
= 0;
4575 printf (_("\n The Directory Table (offset %#tx):\n"),
4578 while (data
< end
&& *data
!= 0)
4580 printf (" %d\t%.*s\n", ++last_dir_entry
, (int) (end
- data
), data
);
4582 data
+= strnlen ((char *) data
, end
- data
);
4587 /* PR 17512: file: 002-132094-0.004. */
4588 if (data
>= end
- 1)
4592 /* Skip the NUL at the end of the table. */
4596 /* Display the contents of the File Name table. */
4597 if (data
>= end
|| *data
== 0)
4598 printf (_("\n The File Name Table is empty.\n"));
4601 printf (_("\n The File Name Table (offset %#tx):\n"),
4603 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
4605 while (data
< end
&& *data
!= 0)
4607 unsigned char *name
;
4610 printf (" %d\t", ++state_machine_regs
.last_file_entry
);
4612 data
+= strnlen ((char *) data
, end
- data
);
4616 READ_ULEB (val
, data
, end
);
4617 printf ("%" PRIu64
"\t", val
);
4618 READ_ULEB (val
, data
, end
);
4619 printf ("%" PRIu64
"\t", val
);
4620 READ_ULEB (val
, data
, end
);
4621 printf ("%" PRIu64
"\t", val
);
4622 printf ("%.*s\n", (int)(end
- name
), name
);
4626 warn (_("Corrupt file name table entry\n"));
4632 /* Skip the NUL at the end of the table. */
4638 saved_linfo
= linfo
;
4641 /* Now display the statements. */
4642 if (data
>= end_of_sequence
)
4643 printf (_(" No Line Number Statements.\n"));
4646 printf (_(" Line Number Statements:\n"));
4648 while (data
< end_of_sequence
)
4650 unsigned char op_code
;
4654 printf (" [0x%08tx]", data
- start
);
4658 if (op_code
>= linfo
.li_opcode_base
)
4660 op_code
-= linfo
.li_opcode_base
;
4661 uladv
= (op_code
/ linfo
.li_line_range
);
4662 if (linfo
.li_max_ops_per_insn
== 1)
4664 uladv
*= linfo
.li_min_insn_length
;
4665 state_machine_regs
.address
+= uladv
;
4667 state_machine_regs
.view
= 0;
4668 printf (_(" Special opcode %d: "
4669 "advance Address by %" PRIu64
4670 " to %#" PRIx64
"%s"),
4671 op_code
, uladv
, state_machine_regs
.address
,
4672 verbose_view
&& uladv
4673 ? _(" (reset view)") : "");
4678 = ((state_machine_regs
.op_index
+ uladv
)
4679 / linfo
.li_max_ops_per_insn
)
4680 * linfo
.li_min_insn_length
;
4682 state_machine_regs
.address
+= addrdelta
;
4683 state_machine_regs
.op_index
4684 = (state_machine_regs
.op_index
+ uladv
)
4685 % linfo
.li_max_ops_per_insn
;
4687 state_machine_regs
.view
= 0;
4688 printf (_(" Special opcode %d: "
4689 "advance Address by %" PRIu64
4690 " to %#" PRIx64
"[%d]%s"),
4691 op_code
, uladv
, state_machine_regs
.address
,
4692 state_machine_regs
.op_index
,
4693 verbose_view
&& addrdelta
4694 ? _(" (reset view)") : "");
4696 adv
= (op_code
% linfo
.li_line_range
) + linfo
.li_line_base
;
4697 state_machine_regs
.line
+= adv
;
4698 printf (_(" and Line by %" PRId64
" to %d"),
4699 adv
, state_machine_regs
.line
);
4700 if (verbose_view
|| state_machine_regs
.view
)
4701 printf (_(" (view %u)\n"), state_machine_regs
.view
);
4704 state_machine_regs
.view
++;
4709 case DW_LNS_extended_op
:
4710 data
+= process_extended_line_op (data
,
4711 linfo
.li_default_is_stmt
,
4716 printf (_(" Copy"));
4717 if (verbose_view
|| state_machine_regs
.view
)
4718 printf (_(" (view %u)\n"), state_machine_regs
.view
);
4721 state_machine_regs
.view
++;
4724 case DW_LNS_advance_pc
:
4725 READ_ULEB (uladv
, data
, end
);
4726 if (linfo
.li_max_ops_per_insn
== 1)
4728 uladv
*= linfo
.li_min_insn_length
;
4729 state_machine_regs
.address
+= uladv
;
4731 state_machine_regs
.view
= 0;
4732 printf (_(" Advance PC by %" PRIu64
4733 " to %#" PRIx64
"%s\n"),
4734 uladv
, state_machine_regs
.address
,
4735 verbose_view
&& uladv
4736 ? _(" (reset view)") : "");
4741 = ((state_machine_regs
.op_index
+ uladv
)
4742 / linfo
.li_max_ops_per_insn
)
4743 * linfo
.li_min_insn_length
;
4744 state_machine_regs
.address
4746 state_machine_regs
.op_index
4747 = (state_machine_regs
.op_index
+ uladv
)
4748 % linfo
.li_max_ops_per_insn
;
4750 state_machine_regs
.view
= 0;
4751 printf (_(" Advance PC by %" PRIu64
4752 " to %#" PRIx64
"[%d]%s\n"),
4753 uladv
, state_machine_regs
.address
,
4754 state_machine_regs
.op_index
,
4755 verbose_view
&& addrdelta
4756 ? _(" (reset view)") : "");
4760 case DW_LNS_advance_line
:
4761 READ_SLEB (adv
, data
, end
);
4762 state_machine_regs
.line
+= adv
;
4763 printf (_(" Advance Line by %" PRId64
" to %d\n"),
4764 adv
, state_machine_regs
.line
);
4767 case DW_LNS_set_file
:
4768 READ_ULEB (uladv
, data
, end
);
4769 printf (_(" Set File Name to entry %" PRIu64
4770 " in the File Name Table\n"), uladv
);
4771 state_machine_regs
.file
= uladv
;
4774 case DW_LNS_set_column
:
4775 READ_ULEB (uladv
, data
, end
);
4776 printf (_(" Set column to %" PRIu64
"\n"), uladv
);
4777 state_machine_regs
.column
= uladv
;
4780 case DW_LNS_negate_stmt
:
4781 adv
= state_machine_regs
.is_stmt
;
4783 printf (_(" Set is_stmt to %" PRId64
"\n"), adv
);
4784 state_machine_regs
.is_stmt
= adv
;
4787 case DW_LNS_set_basic_block
:
4788 printf (_(" Set basic block\n"));
4789 state_machine_regs
.basic_block
= 1;
4792 case DW_LNS_const_add_pc
:
4793 uladv
= ((255 - linfo
.li_opcode_base
) / linfo
.li_line_range
);
4794 if (linfo
.li_max_ops_per_insn
)
4796 uladv
*= linfo
.li_min_insn_length
;
4797 state_machine_regs
.address
+= uladv
;
4799 state_machine_regs
.view
= 0;
4800 printf (_(" Advance PC by constant %" PRIu64
4801 " to %#" PRIx64
"%s\n"),
4802 uladv
, state_machine_regs
.address
,
4803 verbose_view
&& uladv
4804 ? _(" (reset view)") : "");
4809 = ((state_machine_regs
.op_index
+ uladv
)
4810 / linfo
.li_max_ops_per_insn
)
4811 * linfo
.li_min_insn_length
;
4812 state_machine_regs
.address
4814 state_machine_regs
.op_index
4815 = (state_machine_regs
.op_index
+ uladv
)
4816 % linfo
.li_max_ops_per_insn
;
4818 state_machine_regs
.view
= 0;
4819 printf (_(" Advance PC by constant %" PRIu64
4820 " to %#" PRIx64
"[%d]%s\n"),
4821 uladv
, state_machine_regs
.address
,
4822 state_machine_regs
.op_index
,
4823 verbose_view
&& addrdelta
4824 ? _(" (reset view)") : "");
4828 case DW_LNS_fixed_advance_pc
:
4829 SAFE_BYTE_GET_AND_INC (uladv
, data
, 2, end
);
4830 state_machine_regs
.address
+= uladv
;
4831 state_machine_regs
.op_index
= 0;
4832 printf (_(" Advance PC by fixed size amount %" PRIu64
4833 " to %#" PRIx64
"\n"),
4834 uladv
, state_machine_regs
.address
);
4835 /* Do NOT reset view. */
4838 case DW_LNS_set_prologue_end
:
4839 printf (_(" Set prologue_end to true\n"));
4842 case DW_LNS_set_epilogue_begin
:
4843 printf (_(" Set epilogue_begin to true\n"));
4846 case DW_LNS_set_isa
:
4847 READ_ULEB (uladv
, data
, end
);
4848 printf (_(" Set ISA to %" PRIu64
"\n"), uladv
);
4852 printf (_(" Unknown opcode %d with operands: "), op_code
);
4854 if (standard_opcodes
!= NULL
)
4855 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
4857 READ_ULEB (uladv
, data
, end
);
4858 printf ("%#" PRIx64
"%s", uladv
, i
== 1 ? "" : ", ");
4874 unsigned int directory_index
;
4875 unsigned int modification_date
;
4876 unsigned int length
;
4879 /* Output a decoded representation of the .debug_line section. */
4882 display_debug_lines_decoded (struct dwarf_section
* section
,
4883 unsigned char * start
,
4884 unsigned char * data
,
4885 unsigned char * end
,
4888 static DWARF2_Internal_LineInfo saved_linfo
;
4890 introduce (section
, false);
4894 /* This loop amounts to one iteration per compilation unit. */
4895 DWARF2_Internal_LineInfo linfo
;
4896 unsigned char *standard_opcodes
;
4897 unsigned char *end_of_sequence
;
4899 File_Entry
*file_table
= NULL
;
4900 unsigned int n_files
= 0;
4901 char **directory_table
= NULL
;
4902 unsigned int n_directories
= 0;
4904 if (startswith (section
->name
, ".debug_line.")
4905 /* Note: the following does not apply to .debug_line.dwo sections.
4906 These are full debug_line sections. */
4907 && strcmp (section
->name
, ".debug_line.dwo") != 0)
4909 /* See comment in display_debug_lines_raw(). */
4910 end_of_sequence
= end
;
4911 standard_opcodes
= NULL
;
4912 linfo
= saved_linfo
;
4913 /* PR 17531: file: 0522b371. */
4914 if (linfo
.li_line_range
== 0)
4916 warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n"));
4919 reset_state_machine (linfo
.li_default_is_stmt
);
4923 unsigned char *hdrptr
;
4925 if ((hdrptr
= read_debug_line_header (section
, data
, end
, & linfo
,
4926 & end_of_sequence
)) == NULL
)
4929 /* PR 17531: file: 0522b371. */
4930 if (linfo
.li_line_range
== 0)
4932 warn (_("Line range of 0 is invalid, using 1 instead\n"));
4933 linfo
.li_line_range
= 1;
4935 reset_state_machine (linfo
.li_default_is_stmt
);
4937 /* Save a pointer to the contents of the Opcodes table. */
4938 standard_opcodes
= hdrptr
;
4940 /* Traverse the Directory table just to count entries. */
4941 data
= standard_opcodes
+ linfo
.li_opcode_base
- 1;
4945 warn (_("opcode base of %d extends beyond end of section\n"),
4946 linfo
.li_opcode_base
);
4950 if (linfo
.li_version
>= 5)
4952 unsigned char *format_start
, *format
;
4953 unsigned int format_count
, formati
, entryi
;
4955 load_debug_section_with_follow (line_str
, fileptr
);
4957 /* Skip directories format. */
4958 SAFE_BYTE_GET_AND_INC (format_count
, data
, 1, end
);
4959 if (do_checks
&& format_count
> 1)
4960 warn (_("Unexpectedly large number of columns in the directory name table (%u)\n"),
4962 format_start
= data
;
4963 for (formati
= 0; formati
< format_count
; formati
++)
4965 SKIP_ULEB (data
, end
);
4966 SKIP_ULEB (data
, end
);
4969 READ_ULEB (n_directories
, data
, end
);
4972 warn (_("Corrupt directories list\n"));
4976 if (n_directories
== 0)
4977 directory_table
= NULL
;
4979 directory_table
= (char **)
4980 xcalloc (n_directories
, sizeof (unsigned char *));
4982 for (entryi
= 0; entryi
< n_directories
; entryi
++)
4984 char **pathp
= &directory_table
[entryi
];
4986 format
= format_start
;
4987 for (formati
= 0; formati
< format_count
; formati
++)
4989 uint64_t content_type
, form
;
4992 READ_ULEB (content_type
, format
, end
);
4993 READ_ULEB (form
, format
, end
);
4996 warn (_("Corrupt directories list\n"));
4999 switch (content_type
)
5004 case DW_FORM_string
:
5005 *pathp
= (char *) data
;
5007 case DW_FORM_line_strp
:
5008 SAFE_BYTE_GET (uvalue
, data
, linfo
.li_offset_size
,
5010 /* Remove const by the cast. */
5012 fetch_indirect_line_string (uvalue
);
5017 data
= read_and_display_attr_value (0, form
, 0, start
,
5019 linfo
.li_offset_size
,
5026 warn (_("Corrupt directories list\n"));
5031 /* Skip files format. */
5032 SAFE_BYTE_GET_AND_INC (format_count
, data
, 1, end
);
5033 if (do_checks
&& format_count
> 5)
5034 warn (_("Unexpectedly large number of columns in the file name table (%u)\n"),
5036 format_start
= data
;
5037 for (formati
= 0; formati
< format_count
; formati
++)
5039 SKIP_ULEB (data
, end
);
5040 SKIP_ULEB (data
, end
);
5043 READ_ULEB (n_files
, data
, end
);
5044 if (data
>= end
&& n_files
> 0)
5046 warn (_("Corrupt file name list\n"));
5053 file_table
= (File_Entry
*) xcalloc (n_files
,
5054 sizeof (File_Entry
));
5056 for (entryi
= 0; entryi
< n_files
; entryi
++)
5058 File_Entry
*file
= &file_table
[entryi
];
5060 format
= format_start
;
5061 for (formati
= 0; formati
< format_count
; formati
++)
5063 uint64_t content_type
, form
;
5067 READ_ULEB (content_type
, format
, end
);
5068 READ_ULEB (form
, format
, end
);
5071 warn (_("Corrupt file name list\n"));
5074 switch (content_type
)
5079 case DW_FORM_string
:
5080 file
->name
= (char *) data
;
5082 case DW_FORM_line_strp
:
5083 SAFE_BYTE_GET (uvalue
, data
, linfo
.li_offset_size
,
5085 /* Remove const by the cast. */
5086 file
->name
= (char *)
5087 fetch_indirect_line_string (uvalue
);
5091 case DW_LNCT_directory_index
:
5095 SAFE_BYTE_GET (file
->directory_index
, data
, 1,
5099 SAFE_BYTE_GET (file
->directory_index
, data
, 2,
5104 READ_ULEB (file
->directory_index
, tmp
, end
);
5109 data
= read_and_display_attr_value (0, form
, 0, start
,
5111 linfo
.li_offset_size
,
5118 warn (_("Corrupt file name list\n"));
5127 char *ptr_directory_table
= (char *) data
;
5129 while (data
< end
&& *data
!= 0)
5131 data
+= strnlen ((char *) data
, end
- data
);
5140 warn (_("directory table ends unexpectedly\n"));
5145 /* Go through the directory table again to save the directories. */
5146 directory_table
= (char **)
5147 xmalloc (n_directories
* sizeof (unsigned char *));
5150 while (*ptr_directory_table
!= 0)
5152 directory_table
[i
] = ptr_directory_table
;
5153 ptr_directory_table
+= strlen (ptr_directory_table
) + 1;
5157 /* Skip the NUL at the end of the table. */
5160 /* Traverse the File Name table just to count the entries. */
5161 if (data
< end
&& *data
!= 0)
5163 unsigned char *ptr_file_name_table
= data
;
5165 while (data
< end
&& *data
!= 0)
5167 /* Skip Name, directory index, last modification
5168 time and length of file. */
5169 data
+= strnlen ((char *) data
, end
- data
);
5172 SKIP_ULEB (data
, end
);
5173 SKIP_ULEB (data
, end
);
5174 SKIP_ULEB (data
, end
);
5180 warn (_("file table ends unexpectedly\n"));
5185 /* Go through the file table again to save the strings. */
5186 file_table
= (File_Entry
*) xmalloc (n_files
* sizeof (File_Entry
));
5189 while (*ptr_file_name_table
!= 0)
5191 file_table
[i
].name
= (char *) ptr_file_name_table
;
5193 += strlen ((char *) ptr_file_name_table
) + 1;
5195 /* We are not interested in directory, time or size. */
5196 READ_ULEB (file_table
[i
].directory_index
,
5197 ptr_file_name_table
, end
);
5198 READ_ULEB (file_table
[i
].modification_date
,
5199 ptr_file_name_table
, end
);
5200 READ_ULEB (file_table
[i
].length
,
5201 ptr_file_name_table
, end
);
5207 /* Skip the NUL at the end of the table. */
5211 /* Print the Compilation Unit's name and a header. */
5212 if (file_table
== NULL
)
5213 printf (_("CU: No directory table\n"));
5214 else if (directory_table
== NULL
)
5215 printf (_("CU: %s:\n"), null_name (file_table
[0].name
));
5218 unsigned int ix
= file_table
[0].directory_index
;
5219 const char *directory
;
5221 if (ix
== 0 && linfo
.li_version
< 5)
5224 else if (n_directories
== 0)
5225 directory
= _("<unknown>");
5228 if (linfo
.li_version
< 5)
5230 if (ix
>= n_directories
)
5232 warn (_("directory index %u "
5233 ">= number of directories %u\n"),
5235 directory
= _("<corrupt>");
5238 directory
= directory_table
[ix
];
5241 printf (_("CU: %s/%s:\n"),
5242 null_name (directory
),
5243 null_name (file_table
[0].name
));
5245 printf ("%s:\n", null_name (file_table
[0].name
));
5251 printf (_("File name Line number Starting address View Stmt\n"));
5253 printf (_("File name Line number Starting address View Stmt\n"));
5256 printf (_("CU: Empty file name table\n"));
5257 saved_linfo
= linfo
;
5260 /* This loop iterates through the Dwarf Line Number Program. */
5261 while (data
< end_of_sequence
)
5263 unsigned char op_code
;
5266 unsigned long int uladv
;
5267 int is_special_opcode
= 0;
5272 if (op_code
>= linfo
.li_opcode_base
)
5274 op_code
-= linfo
.li_opcode_base
;
5275 uladv
= (op_code
/ linfo
.li_line_range
);
5276 if (linfo
.li_max_ops_per_insn
== 1)
5278 uladv
*= linfo
.li_min_insn_length
;
5279 state_machine_regs
.address
+= uladv
;
5281 state_machine_regs
.view
= 0;
5286 = ((state_machine_regs
.op_index
+ uladv
)
5287 / linfo
.li_max_ops_per_insn
)
5288 * linfo
.li_min_insn_length
;
5289 state_machine_regs
.address
5291 state_machine_regs
.op_index
5292 = (state_machine_regs
.op_index
+ uladv
)
5293 % linfo
.li_max_ops_per_insn
;
5295 state_machine_regs
.view
= 0;
5298 adv
= (op_code
% linfo
.li_line_range
) + linfo
.li_line_base
;
5299 state_machine_regs
.line
+= adv
;
5300 is_special_opcode
= 1;
5301 /* Increment view after printing this row. */
5306 case DW_LNS_extended_op
:
5308 unsigned int ext_op_code_len
;
5309 unsigned char ext_op_code
;
5310 unsigned char *op_code_end
;
5311 unsigned char *op_code_data
= data
;
5313 READ_ULEB (ext_op_code_len
, op_code_data
, end_of_sequence
);
5314 op_code_end
= op_code_data
+ ext_op_code_len
;
5315 if (ext_op_code_len
== 0 || op_code_end
> end_of_sequence
)
5317 warn (_("Badly formed extended line op encountered!\n"));
5320 ext_op_code
= *op_code_data
++;
5324 switch (ext_op_code
)
5326 case DW_LNE_end_sequence
:
5327 /* Reset stuff after printing this row. */
5329 case DW_LNE_set_address
:
5330 SAFE_BYTE_GET_AND_INC (state_machine_regs
.address
,
5332 op_code_end
- op_code_data
,
5334 state_machine_regs
.op_index
= 0;
5335 state_machine_regs
.view
= 0;
5337 case DW_LNE_define_file
:
5338 file_table
= (File_Entry
*) xrealloc
5339 (file_table
, (n_files
+ 1) * sizeof (File_Entry
));
5341 ++state_machine_regs
.last_file_entry
;
5342 /* Source file name. */
5343 file_table
[n_files
].name
= (char *) op_code_data
;
5344 op_code_data
+= strlen ((char *) op_code_data
) + 1;
5345 /* Directory index. */
5346 READ_ULEB (file_table
[n_files
].directory_index
,
5347 op_code_data
, op_code_end
);
5348 /* Last modification time. */
5349 READ_ULEB (file_table
[n_files
].modification_date
,
5350 op_code_data
, op_code_end
);
5352 READ_ULEB (file_table
[n_files
].length
,
5353 op_code_data
, op_code_end
);
5357 case DW_LNE_set_discriminator
:
5358 case DW_LNE_HP_set_sequence
:
5359 /* Simply ignored. */
5363 printf (_("UNKNOWN (%u): length %ld\n"),
5364 ext_op_code
, (long int) (op_code_data
- data
));
5371 /* Increment view after printing this row. */
5374 case DW_LNS_advance_pc
:
5375 READ_ULEB (uladv
, data
, end
);
5376 if (linfo
.li_max_ops_per_insn
== 1)
5378 uladv
*= linfo
.li_min_insn_length
;
5379 state_machine_regs
.address
+= uladv
;
5381 state_machine_regs
.view
= 0;
5386 = ((state_machine_regs
.op_index
+ uladv
)
5387 / linfo
.li_max_ops_per_insn
)
5388 * linfo
.li_min_insn_length
;
5389 state_machine_regs
.address
5391 state_machine_regs
.op_index
5392 = (state_machine_regs
.op_index
+ uladv
)
5393 % linfo
.li_max_ops_per_insn
;
5395 state_machine_regs
.view
= 0;
5399 case DW_LNS_advance_line
:
5400 READ_SLEB (adv
, data
, end
);
5401 state_machine_regs
.line
+= adv
;
5404 case DW_LNS_set_file
:
5405 READ_ULEB (uladv
, data
, end
);
5406 state_machine_regs
.file
= uladv
;
5408 unsigned file
= state_machine_regs
.file
;
5409 if (linfo
.li_version
< 5)
5412 if (file_table
== NULL
|| n_files
== 0)
5413 printf (_("\n [Use file table entry %d]\n"), file
);
5415 else if (file
>= n_files
)
5417 warn (_("file index %u >= number of files %u\n"),
5419 printf (_("\n <over large file table index %u>"), file
);
5423 unsigned dir
= file_table
[file
].directory_index
;
5424 if (dir
== 0 && linfo
.li_version
< 5)
5425 /* If directory index is 0, that means compilation
5426 current directory. bfd/dwarf2.c shows
5427 DW_AT_comp_dir here but in keeping with the
5428 readelf practice of minimal interpretation of
5429 file data, we show "./". */
5430 printf ("\n./%s:[++]\n",
5431 null_name (file_table
[file
].name
));
5432 else if (directory_table
== NULL
|| n_directories
== 0)
5433 printf (_("\n [Use file %s "
5434 "in directory table entry %d]\n"),
5435 null_name (file_table
[file
].name
), dir
);
5438 if (linfo
.li_version
< 5)
5441 if (dir
>= n_directories
)
5443 warn (_("directory index %u "
5444 ">= number of directories %u\n"),
5445 dir
, n_directories
);
5446 printf (_("\n <over large directory table entry "
5450 printf ("\n%s/%s:\n",
5451 null_name (directory_table
[dir
]),
5452 null_name (file_table
[file
].name
));
5457 case DW_LNS_set_column
:
5458 READ_ULEB (uladv
, data
, end
);
5459 state_machine_regs
.column
= uladv
;
5462 case DW_LNS_negate_stmt
:
5463 adv
= state_machine_regs
.is_stmt
;
5465 state_machine_regs
.is_stmt
= adv
;
5468 case DW_LNS_set_basic_block
:
5469 state_machine_regs
.basic_block
= 1;
5472 case DW_LNS_const_add_pc
:
5473 uladv
= ((255 - linfo
.li_opcode_base
) / linfo
.li_line_range
);
5474 if (linfo
.li_max_ops_per_insn
== 1)
5476 uladv
*= linfo
.li_min_insn_length
;
5477 state_machine_regs
.address
+= uladv
;
5479 state_machine_regs
.view
= 0;
5484 = ((state_machine_regs
.op_index
+ uladv
)
5485 / linfo
.li_max_ops_per_insn
)
5486 * linfo
.li_min_insn_length
;
5487 state_machine_regs
.address
5489 state_machine_regs
.op_index
5490 = (state_machine_regs
.op_index
+ uladv
)
5491 % linfo
.li_max_ops_per_insn
;
5493 state_machine_regs
.view
= 0;
5497 case DW_LNS_fixed_advance_pc
:
5498 SAFE_BYTE_GET_AND_INC (uladv
, data
, 2, end
);
5499 state_machine_regs
.address
+= uladv
;
5500 state_machine_regs
.op_index
= 0;
5501 /* Do NOT reset view. */
5504 case DW_LNS_set_prologue_end
:
5507 case DW_LNS_set_epilogue_begin
:
5510 case DW_LNS_set_isa
:
5511 READ_ULEB (uladv
, data
, end
);
5512 printf (_(" Set ISA to %lu\n"), uladv
);
5516 printf (_(" Unknown opcode %d with operands: "), op_code
);
5518 if (standard_opcodes
!= NULL
)
5519 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
5523 READ_ULEB (val
, data
, end
);
5524 printf ("%#" PRIx64
"%s", val
, i
== 1 ? "" : ", ");
5530 /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row
5531 to the DWARF address/line matrix. */
5532 if ((is_special_opcode
) || (xop
== -DW_LNE_end_sequence
)
5533 || (xop
== DW_LNS_copy
))
5535 const unsigned int MAX_FILENAME_LENGTH
= 35;
5536 char *fileName
= NULL
;
5537 char *newFileName
= NULL
;
5538 size_t fileNameLength
;
5542 unsigned indx
= state_machine_regs
.file
;
5544 if (linfo
.li_version
< 5)
5547 if (indx
>= n_files
)
5549 warn (_("file index %u >= number of files %u\n"),
5551 fileName
= _("<corrupt>");
5554 fileName
= (char *) file_table
[indx
].name
;
5557 fileName
= _("<unknown>");
5559 fileNameLength
= strlen (fileName
);
5560 newFileName
= fileName
;
5561 if (fileNameLength
> MAX_FILENAME_LENGTH
&& !do_wide
)
5563 newFileName
= (char *) xmalloc (MAX_FILENAME_LENGTH
+ 1);
5564 /* Truncate file name */
5565 memcpy (newFileName
,
5566 fileName
+ fileNameLength
- MAX_FILENAME_LENGTH
,
5567 MAX_FILENAME_LENGTH
);
5568 newFileName
[MAX_FILENAME_LENGTH
] = 0;
5571 /* A row with end_seq set to true has a meaningful address, but
5572 the other information in the same row is not significant.
5573 In such a row, print line as "-", and don't print
5575 if (!do_wide
|| fileNameLength
<= MAX_FILENAME_LENGTH
)
5577 if (linfo
.li_max_ops_per_insn
== 1)
5579 if (xop
== -DW_LNE_end_sequence
)
5580 printf ("%-31s %11s %#18" PRIx64
,
5582 state_machine_regs
.address
);
5584 printf ("%-31s %11d %#18" PRIx64
,
5585 newFileName
, state_machine_regs
.line
,
5586 state_machine_regs
.address
);
5590 if (xop
== -DW_LNE_end_sequence
)
5591 printf ("%-31s %11s %#18" PRIx64
"[%d]",
5593 state_machine_regs
.address
,
5594 state_machine_regs
.op_index
);
5596 printf ("%-31s %11d %#18" PRIx64
"[%d]",
5597 newFileName
, state_machine_regs
.line
,
5598 state_machine_regs
.address
,
5599 state_machine_regs
.op_index
);
5604 if (linfo
.li_max_ops_per_insn
== 1)
5606 if (xop
== -DW_LNE_end_sequence
)
5607 printf ("%s %11s %#18" PRIx64
,
5609 state_machine_regs
.address
);
5611 printf ("%s %11d %#18" PRIx64
,
5612 newFileName
, state_machine_regs
.line
,
5613 state_machine_regs
.address
);
5617 if (xop
== -DW_LNE_end_sequence
)
5618 printf ("%s %11s %#18" PRIx64
"[%d]",
5620 state_machine_regs
.address
,
5621 state_machine_regs
.op_index
);
5623 printf ("%s %11d %#18" PRIx64
"[%d]",
5624 newFileName
, state_machine_regs
.line
,
5625 state_machine_regs
.address
,
5626 state_machine_regs
.op_index
);
5630 if (xop
!= -DW_LNE_end_sequence
)
5632 if (state_machine_regs
.view
)
5633 printf (" %6u", state_machine_regs
.view
);
5637 if (state_machine_regs
.is_stmt
)
5642 state_machine_regs
.view
++;
5644 if (xop
== -DW_LNE_end_sequence
)
5646 reset_state_machine (linfo
.li_default_is_stmt
);
5650 if (newFileName
!= fileName
)
5662 if (directory_table
)
5664 free (directory_table
);
5665 directory_table
= NULL
;
5676 display_debug_lines (struct dwarf_section
*section
, void *file
)
5678 unsigned char *data
= section
->start
;
5679 unsigned char *end
= data
+ section
->size
;
5681 int retValDecoded
= 1;
5683 if (do_debug_lines
== 0)
5684 do_debug_lines
|= FLAG_DEBUG_LINES_RAW
;
5686 if (do_debug_lines
& FLAG_DEBUG_LINES_RAW
)
5687 retValRaw
= display_debug_lines_raw (section
, data
, end
, file
);
5689 if (do_debug_lines
& FLAG_DEBUG_LINES_DECODED
)
5690 retValDecoded
= display_debug_lines_decoded (section
, data
, data
, end
, file
);
5692 if (!retValRaw
|| !retValDecoded
)
5699 find_debug_info_for_offset (uint64_t offset
)
5703 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
5706 for (i
= 0; i
< num_debug_info_entries
; i
++)
5707 if (debug_information
[i
].cu_offset
== offset
)
5708 return debug_information
+ i
;
5714 get_gdb_index_symbol_kind_name (gdb_index_symbol_kind kind
)
5716 /* See gdb/gdb-index.h. */
5717 static const char * const kinds
[] =
5729 return _ (kinds
[kind
]);
5733 display_debug_pubnames_worker (struct dwarf_section
*section
,
5734 void *file ATTRIBUTE_UNUSED
,
5737 DWARF2_Internal_PubNames names
;
5738 unsigned char *start
= section
->start
;
5739 unsigned char *end
= start
+ section
->size
;
5741 /* It does not matter if this load fails,
5742 we test for that later on. */
5743 load_debug_info (file
);
5745 introduce (section
, false);
5749 unsigned char *data
;
5750 unsigned long sec_off
= start
- section
->start
;
5751 unsigned int offset_size
;
5753 SAFE_BYTE_GET_AND_INC (names
.pn_length
, start
, 4, end
);
5754 if (names
.pn_length
== 0xffffffff)
5756 SAFE_BYTE_GET_AND_INC (names
.pn_length
, start
, 8, end
);
5762 if (names
.pn_length
> (size_t) (end
- start
))
5764 warn (_("Debug info is corrupted, "
5765 "%s header at %#lx has length %#" PRIx64
"\n"),
5766 section
->name
, sec_off
, names
.pn_length
);
5771 start
+= names
.pn_length
;
5773 SAFE_BYTE_GET_AND_INC (names
.pn_version
, data
, 2, start
);
5774 SAFE_BYTE_GET_AND_INC (names
.pn_offset
, data
, offset_size
, start
);
5776 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
5777 && num_debug_info_entries
> 0
5778 && find_debug_info_for_offset (names
.pn_offset
) == NULL
)
5779 warn (_(".debug_info offset of %#" PRIx64
5780 " in %s section does not point to a CU header.\n"),
5781 names
.pn_offset
, section
->name
);
5783 SAFE_BYTE_GET_AND_INC (names
.pn_size
, data
, offset_size
, start
);
5785 printf (_(" Length: %" PRId64
"\n"),
5787 printf (_(" Version: %d\n"),
5789 printf (_(" Offset into .debug_info section: %#" PRIx64
"\n"),
5791 printf (_(" Size of area in .debug_info section: %" PRId64
"\n"),
5794 if (names
.pn_version
!= 2 && names
.pn_version
!= 3)
5796 static int warned
= 0;
5800 warn (_("Only DWARF 2 and 3 pubnames are currently supported\n"));
5808 printf (_("\n Offset Kind Name\n"));
5810 printf (_("\n Offset\tName\n"));
5817 SAFE_BYTE_GET_AND_INC (offset
, data
, offset_size
, start
);
5824 maxprint
= (start
- data
) - 1;
5828 unsigned int kind_data
;
5829 gdb_index_symbol_kind kind
;
5830 const char *kind_name
;
5833 SAFE_BYTE_GET_AND_INC (kind_data
, data
, 1, start
);
5835 /* GCC computes the kind as the upper byte in the CU index
5836 word, and then right shifts it by the CU index size.
5837 Left shift KIND to where the gdb-index.h accessor macros
5839 kind_data
<<= GDB_INDEX_CU_BITSIZE
;
5840 kind
= GDB_INDEX_SYMBOL_KIND_VALUE (kind_data
);
5841 kind_name
= get_gdb_index_symbol_kind_name (kind
);
5842 is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (kind_data
);
5843 printf (" %-6" PRIx64
" %s,%-10s %.*s\n",
5844 offset
, is_static
? _("s") : _("g"),
5845 kind_name
, (int) maxprint
, data
);
5848 printf (" %-6" PRIx64
"\t%.*s\n",
5849 offset
, (int) maxprint
, data
);
5851 data
+= strnlen ((char *) data
, maxprint
);
5864 display_debug_pubnames (struct dwarf_section
*section
, void *file
)
5866 return display_debug_pubnames_worker (section
, file
, 0);
5870 display_debug_gnu_pubnames (struct dwarf_section
*section
, void *file
)
5872 return display_debug_pubnames_worker (section
, file
, 1);
5876 display_debug_macinfo (struct dwarf_section
*section
,
5877 void *file ATTRIBUTE_UNUSED
)
5879 unsigned char *start
= section
->start
;
5880 unsigned char *end
= start
+ section
->size
;
5881 unsigned char *curr
= start
;
5882 enum dwarf_macinfo_record_type op
;
5884 introduce (section
, false);
5888 unsigned int lineno
;
5889 const unsigned char *string
;
5891 op
= (enum dwarf_macinfo_record_type
) *curr
;
5896 case DW_MACINFO_start_file
:
5898 unsigned int filenum
;
5900 READ_ULEB (lineno
, curr
, end
);
5901 READ_ULEB (filenum
, curr
, end
);
5902 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"),
5907 case DW_MACINFO_end_file
:
5908 printf (_(" DW_MACINFO_end_file\n"));
5911 case DW_MACINFO_define
:
5912 READ_ULEB (lineno
, curr
, end
);
5914 curr
+= strnlen ((char *) string
, end
- string
);
5915 printf (_(" DW_MACINFO_define - lineno : %d macro : %*s\n"),
5916 lineno
, (int) (curr
- string
), string
);
5921 case DW_MACINFO_undef
:
5922 READ_ULEB (lineno
, curr
, end
);
5924 curr
+= strnlen ((char *) string
, end
- string
);
5925 printf (_(" DW_MACINFO_undef - lineno : %d macro : %*s\n"),
5926 lineno
, (int) (curr
- string
), string
);
5931 case DW_MACINFO_vendor_ext
:
5933 unsigned int constant
;
5935 READ_ULEB (constant
, curr
, end
);
5937 curr
+= strnlen ((char *) string
, end
- string
);
5938 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %*s\n"),
5939 constant
, (int) (curr
- string
), string
);
5950 /* Given LINE_OFFSET into the .debug_line section, attempt to return
5951 filename and dirname corresponding to file name table entry with index
5952 FILEIDX. Return NULL on failure. */
5954 static unsigned char *
5955 get_line_filename_and_dirname (uint64_t line_offset
,
5957 unsigned char **dir_name
)
5959 struct dwarf_section
*section
= &debug_displays
[line
].section
;
5960 unsigned char *hdrptr
, *dirtable
, *file_name
;
5961 unsigned int offset_size
;
5962 unsigned int version
, opcode_base
;
5963 uint64_t length
, diridx
;
5964 const unsigned char * end
;
5967 if (section
->start
== NULL
5968 || line_offset
>= section
->size
5972 hdrptr
= section
->start
+ line_offset
;
5973 end
= section
->start
+ section
->size
;
5975 SAFE_BYTE_GET_AND_INC (length
, hdrptr
, 4, end
);
5976 if (length
== 0xffffffff)
5978 /* This section is 64-bit DWARF 3. */
5979 SAFE_BYTE_GET_AND_INC (length
, hdrptr
, 8, end
);
5985 if (length
> (size_t) (end
- hdrptr
)
5986 || length
< 2 + offset_size
+ 1 + 3 + 1)
5988 end
= hdrptr
+ length
;
5990 SAFE_BYTE_GET_AND_INC (version
, hdrptr
, 2, end
);
5991 if (version
!= 2 && version
!= 3 && version
!= 4)
5993 hdrptr
+= offset_size
+ 1;/* Skip prologue_length and min_insn_length. */
5995 hdrptr
++; /* Skip max_ops_per_insn. */
5996 hdrptr
+= 3; /* Skip default_is_stmt, line_base, line_range. */
5998 SAFE_BYTE_GET_AND_INC (opcode_base
, hdrptr
, 1, end
);
5999 if (opcode_base
== 0
6000 || opcode_base
- 1 >= (size_t) (end
- hdrptr
))
6003 hdrptr
+= opcode_base
- 1;
6006 /* Skip over dirname table. */
6007 while (*hdrptr
!= '\0')
6009 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
);
6015 hdrptr
++; /* Skip the NUL at the end of the table. */
6017 /* Now skip over preceding filename table entries. */
6018 for (; hdrptr
< end
&& *hdrptr
!= '\0' && fileidx
> 1; fileidx
--)
6020 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
);
6023 SKIP_ULEB (hdrptr
, end
);
6024 SKIP_ULEB (hdrptr
, end
);
6025 SKIP_ULEB (hdrptr
, end
);
6027 if (hdrptr
>= end
|| *hdrptr
== '\0')
6031 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
);
6036 READ_ULEB (diridx
, hdrptr
, end
);
6039 for (; dirtable
< end
&& *dirtable
!= '\0' && diridx
> 1; diridx
--)
6041 dirtable
+= strnlen ((char *) dirtable
, end
- dirtable
);
6045 if (dirtable
>= end
|| *dirtable
== '\0')
6047 *dir_name
= dirtable
;
6052 display_debug_macro (struct dwarf_section
*section
,
6055 unsigned char *start
= section
->start
;
6056 unsigned char *end
= start
+ section
->size
;
6057 unsigned char *curr
= start
;
6058 unsigned char *extended_op_buf
[256];
6059 bool is_dwo
= false;
6060 const char *suffix
= strrchr (section
->name
, '.');
6062 if (suffix
&& strcmp (suffix
, ".dwo") == 0)
6065 load_debug_section_with_follow (str
, file
);
6066 load_debug_section_with_follow (line
, file
);
6067 load_debug_section_with_follow (str_index
, file
);
6069 introduce (section
, false);
6073 unsigned int lineno
, version
, flags
;
6074 unsigned int offset_size
;
6075 const unsigned char *string
;
6076 uint64_t line_offset
= 0, sec_offset
= curr
- start
, offset
;
6077 unsigned char **extended_ops
= NULL
;
6079 SAFE_BYTE_GET_AND_INC (version
, curr
, 2, end
);
6080 if (version
!= 4 && version
!= 5)
6082 error (_("Expected to find a version number of 4 or 5 in section %s but found %d instead\n"),
6083 section
->name
, version
);
6087 SAFE_BYTE_GET_AND_INC (flags
, curr
, 1, end
);
6088 offset_size
= (flags
& 1) ? 8 : 4;
6089 printf (_(" Offset: %#" PRIx64
"\n"), sec_offset
);
6090 printf (_(" Version: %d\n"), version
);
6091 printf (_(" Offset size: %d\n"), offset_size
);
6094 SAFE_BYTE_GET_AND_INC (line_offset
, curr
, offset_size
, end
);
6095 printf (_(" Offset into .debug_line: %#" PRIx64
"\n"),
6100 unsigned int i
, count
, op
;
6103 SAFE_BYTE_GET_AND_INC (count
, curr
, 1, end
);
6105 memset (extended_op_buf
, 0, sizeof (extended_op_buf
));
6106 extended_ops
= extended_op_buf
;
6109 printf (_(" Extension opcode arguments:\n"));
6110 for (i
= 0; i
< count
; i
++)
6112 SAFE_BYTE_GET_AND_INC (op
, curr
, 1, end
);
6113 extended_ops
[op
] = curr
;
6114 READ_ULEB (nargs
, curr
, end
);
6116 printf (_(" DW_MACRO_%02x has no arguments\n"), op
);
6119 printf (_(" DW_MACRO_%02x arguments: "), op
);
6120 for (n
= 0; n
< nargs
; n
++)
6124 SAFE_BYTE_GET_AND_INC (form
, curr
, 1, end
);
6125 printf ("%s%s", get_FORM_name (form
),
6126 n
== nargs
- 1 ? "\n" : ", ");
6136 case DW_FORM_block1
:
6137 case DW_FORM_block2
:
6138 case DW_FORM_block4
:
6140 case DW_FORM_string
:
6142 case DW_FORM_sec_offset
:
6145 error (_("Invalid extension opcode form %s\n"),
6146 get_FORM_name (form
));
6162 error (_(".debug_macro section not zero terminated\n"));
6166 SAFE_BYTE_GET_AND_INC (op
, curr
, 1, end
);
6172 case DW_MACRO_define
:
6173 READ_ULEB (lineno
, curr
, end
);
6175 curr
+= strnlen ((char *) string
, end
- string
);
6176 printf (_(" DW_MACRO_define - lineno : %d macro : %*s\n"),
6177 lineno
, (int) (curr
- string
), string
);
6182 case DW_MACRO_undef
:
6183 READ_ULEB (lineno
, curr
, end
);
6185 curr
+= strnlen ((char *) string
, end
- string
);
6186 printf (_(" DW_MACRO_undef - lineno : %d macro : %*s\n"),
6187 lineno
, (int) (curr
- string
), string
);
6192 case DW_MACRO_start_file
:
6194 unsigned int filenum
;
6195 unsigned char *file_name
= NULL
, *dir_name
= NULL
;
6197 READ_ULEB (lineno
, curr
, end
);
6198 READ_ULEB (filenum
, curr
, end
);
6200 if ((flags
& 2) == 0)
6201 error (_("DW_MACRO_start_file used, but no .debug_line offset provided.\n"));
6204 = get_line_filename_and_dirname (line_offset
, filenum
,
6206 if (file_name
== NULL
)
6207 printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d\n"),
6210 printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d filename: %s%s%s\n"),
6212 dir_name
!= NULL
? (const char *) dir_name
: "",
6213 dir_name
!= NULL
? "/" : "", file_name
);
6217 case DW_MACRO_end_file
:
6218 printf (_(" DW_MACRO_end_file\n"));
6221 case DW_MACRO_define_strp
:
6222 READ_ULEB (lineno
, curr
, end
);
6223 if (version
== 4 && is_dwo
)
6224 READ_ULEB (offset
, curr
, end
);
6226 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6227 string
= fetch_indirect_string (offset
);
6228 printf (_(" DW_MACRO_define_strp - lineno : %d macro : %s\n"),
6232 case DW_MACRO_undef_strp
:
6233 READ_ULEB (lineno
, curr
, end
);
6234 if (version
== 4 && is_dwo
)
6235 READ_ULEB (offset
, curr
, end
);
6237 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6238 string
= fetch_indirect_string (offset
);
6239 printf (_(" DW_MACRO_undef_strp - lineno : %d macro : %s\n"),
6243 case DW_MACRO_import
:
6244 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6245 printf (_(" DW_MACRO_import - offset : %#" PRIx64
"\n"),
6249 case DW_MACRO_define_sup
:
6250 READ_ULEB (lineno
, curr
, end
);
6251 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6252 printf (_(" DW_MACRO_define_sup - lineno : %d"
6253 " macro offset : %#" PRIx64
"\n"),
6257 case DW_MACRO_undef_sup
:
6258 READ_ULEB (lineno
, curr
, end
);
6259 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6260 printf (_(" DW_MACRO_undef_sup - lineno : %d"
6261 " macro offset : %#" PRIx64
"\n"),
6265 case DW_MACRO_import_sup
:
6266 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6267 printf (_(" DW_MACRO_import_sup - offset : %#" PRIx64
"\n"),
6271 case DW_MACRO_define_strx
:
6272 case DW_MACRO_undef_strx
:
6273 READ_ULEB (lineno
, curr
, end
);
6274 READ_ULEB (offset
, curr
, end
);
6275 string
= (const unsigned char *)
6276 fetch_indexed_string (offset
, NULL
, offset_size
, false, 0);
6277 if (op
== DW_MACRO_define_strx
)
6278 printf (" DW_MACRO_define_strx ");
6280 printf (" DW_MACRO_undef_strx ");
6282 printf (_("(with offset %#" PRIx64
") "), offset
);
6283 printf (_("lineno : %d macro : %s\n"),
6288 if (op
>= DW_MACRO_lo_user
&& op
<= DW_MACRO_hi_user
)
6290 printf (_(" <Target Specific macro op: %#x - UNHANDLED"), op
);
6294 if (extended_ops
== NULL
|| extended_ops
[op
] == NULL
)
6296 error (_(" Unknown macro opcode %02x seen\n"), op
);
6301 /* Skip over unhandled opcodes. */
6303 unsigned char *desc
= extended_ops
[op
];
6304 READ_ULEB (nargs
, desc
, end
);
6307 printf (_(" DW_MACRO_%02x\n"), op
);
6310 printf (_(" DW_MACRO_%02x -"), op
);
6311 for (n
= 0; n
< nargs
; n
++)
6315 /* DW_FORM_implicit_const is not expected here. */
6316 SAFE_BYTE_GET_AND_INC (val
, desc
, 1, end
);
6318 = read_and_display_attr_value (0, val
, 0,
6319 start
, curr
, end
, 0, 0,
6320 offset_size
, version
,
6339 display_debug_abbrev (struct dwarf_section
*section
,
6340 void *file ATTRIBUTE_UNUSED
)
6342 abbrev_entry
*entry
;
6343 unsigned char *start
= section
->start
;
6345 introduce (section
, false);
6349 uint64_t offset
= start
- section
->start
;
6350 abbrev_list
*list
= find_and_process_abbrev_set (section
, 0,
6351 section
->size
, offset
,
6356 if (list
->first_abbrev
)
6357 printf (_(" Number TAG (%#" PRIx64
")\n"), offset
);
6359 for (entry
= list
->first_abbrev
; entry
; entry
= entry
->next
)
6363 printf (" %ld %s [%s]\n",
6365 get_TAG_name (entry
->tag
),
6366 entry
->children
? _("has children") : _("no children"));
6368 for (attr
= entry
->first_attr
; attr
; attr
= attr
->next
)
6370 printf (" %-18s %s",
6371 get_AT_name (attr
->attribute
),
6372 get_FORM_name (attr
->form
));
6373 if (attr
->form
== DW_FORM_implicit_const
)
6374 printf (": %" PRId64
, attr
->implicit_const
);
6378 start
= list
->start_of_next_abbrevs
;
6379 free_abbrev_list (list
);
6388 /* Return true when ADDR is the maximum address, when addresses are
6389 POINTER_SIZE bytes long. */
6392 is_max_address (uint64_t addr
, unsigned int pointer_size
)
6394 uint64_t mask
= ~(~(uint64_t) 0 << 1 << (pointer_size
* 8 - 1));
6395 return ((addr
& mask
) == mask
);
6398 /* Display a view pair list starting at *VSTART_PTR and ending at
6399 VLISTEND within SECTION. */
6402 display_view_pair_list (struct dwarf_section
*section
,
6403 unsigned char **vstart_ptr
,
6404 unsigned int debug_info_entry
,
6405 unsigned char *vlistend
)
6407 unsigned char *vstart
= *vstart_ptr
;
6408 unsigned char *section_end
= section
->start
+ section
->size
;
6409 unsigned int pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
6411 if (vlistend
< section_end
)
6412 section_end
= vlistend
;
6416 while (vstart
< section_end
)
6418 uint64_t off
= vstart
- section
->start
;
6419 uint64_t vbegin
, vend
;
6421 READ_ULEB (vbegin
, vstart
, section_end
);
6422 if (vstart
== section_end
)
6425 READ_ULEB (vend
, vstart
, section_end
);
6426 printf (" %8.8" PRIx64
" ", off
);
6428 print_view (vbegin
, pointer_size
);
6429 print_view (vend
, pointer_size
);
6430 printf (_("location view pair\n"));
6434 *vstart_ptr
= vstart
;
6437 /* Display a location list from a normal (ie, non-dwo) .debug_loc section. */
6440 display_loc_list (struct dwarf_section
*section
,
6441 unsigned char **start_ptr
,
6442 unsigned int debug_info_entry
,
6444 uint64_t base_address
,
6445 unsigned char **vstart_ptr
,
6448 unsigned char *start
= *start_ptr
, *vstart
= *vstart_ptr
;
6449 unsigned char *section_end
= section
->start
+ section
->size
;
6451 unsigned int pointer_size
;
6452 unsigned int offset_size
;
6456 unsigned short length
;
6457 int need_frame_base
;
6459 if (debug_info_entry
>= num_debug_info_entries
)
6461 warn (_("No debug information available for loc lists of entry: %u\n"),
6466 cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
6467 pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
6468 offset_size
= debug_information
[debug_info_entry
].offset_size
;
6469 dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
6471 if (pointer_size
< 2 || pointer_size
> 8)
6473 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
6474 pointer_size
, debug_info_entry
);
6480 uint64_t off
= offset
+ (start
- *start_ptr
);
6481 uint64_t vbegin
= -1, vend
= -1;
6483 if (2 * pointer_size
> (size_t) (section_end
- start
))
6485 warn (_("Location list starting at offset %#" PRIx64
6486 " is not terminated.\n"), offset
);
6493 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, section_end
);
6494 SAFE_BYTE_GET_AND_INC (end
, start
, pointer_size
, section_end
);
6496 if (begin
== 0 && end
== 0)
6498 /* PR 18374: In a object file we can have a location list that
6499 starts with a begin and end of 0 because there are relocations
6500 that need to be applied to the addresses. Actually applying
6501 the relocations now does not help as they will probably resolve
6502 to 0, since the object file has not been fully linked. Real
6503 end of list markers will not have any relocations against them. */
6504 if (! reloc_at (section
, off
)
6505 && ! reloc_at (section
, off
+ pointer_size
))
6507 printf (_("<End of list>\n"));
6512 /* Check base address specifiers. */
6513 if (is_max_address (begin
, pointer_size
)
6514 && !is_max_address (end
, pointer_size
))
6517 print_hex (begin
, pointer_size
);
6518 print_hex (end
, pointer_size
);
6519 printf (_("(base address)\n"));
6525 off
= offset
+ (vstart
- *start_ptr
);
6527 READ_ULEB (vbegin
, vstart
, section_end
);
6528 print_view (vbegin
, pointer_size
);
6530 READ_ULEB (vend
, vstart
, section_end
);
6531 print_view (vend
, pointer_size
);
6533 printf (_("views at %8.8" PRIx64
" for:\n %*s "), off
, 8, "");
6536 if (2 > (size_t) (section_end
- start
))
6538 warn (_("Location list starting at offset %#" PRIx64
6539 " is not terminated.\n"), offset
);
6543 SAFE_BYTE_GET_AND_INC (length
, start
, 2, section_end
);
6545 if (length
> (size_t) (section_end
- start
))
6547 warn (_("Location list starting at offset %#" PRIx64
6548 " is not terminated.\n"), offset
);
6552 print_hex (begin
+ base_address
, pointer_size
);
6553 print_hex (end
+ base_address
, pointer_size
);
6556 need_frame_base
= decode_location_expression (start
,
6561 cu_offset
, section
);
6564 if (need_frame_base
&& !has_frame_base
)
6565 printf (_(" [without DW_AT_frame_base]"));
6567 if (begin
== end
&& vbegin
== vend
)
6568 fputs (_(" (start == end)"), stdout
);
6569 else if (begin
> end
|| (begin
== end
&& vbegin
> vend
))
6570 fputs (_(" (start > end)"), stdout
);
6578 *vstart_ptr
= vstart
;
6581 /* Display a location list from a normal (ie, non-dwo) .debug_loclists section. */
6584 display_loclists_list (struct dwarf_section
* section
,
6585 unsigned char ** start_ptr
,
6586 unsigned int debug_info_entry
,
6588 uint64_t base_address
,
6589 unsigned char ** vstart_ptr
,
6592 unsigned char *start
= *start_ptr
;
6593 unsigned char *vstart
= *vstart_ptr
;
6594 unsigned char *section_end
= section
->start
+ section
->size
;
6596 unsigned int pointer_size
;
6597 unsigned int offset_size
;
6598 unsigned int dwarf_version
;
6600 /* Initialize it due to a false compiler warning. */
6601 uint64_t begin
= -1, vbegin
= -1;
6602 uint64_t end
= -1, vend
= -1;
6604 int need_frame_base
;
6606 if (debug_info_entry
>= num_debug_info_entries
)
6608 warn (_("No debug information available for "
6609 "loclists lists of entry: %u\n"),
6614 cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
6615 pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
6616 offset_size
= debug_information
[debug_info_entry
].offset_size
;
6617 dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
6619 if (pointer_size
< 2 || pointer_size
> 8)
6621 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
6622 pointer_size
, debug_info_entry
);
6628 uint64_t off
= offset
+ (start
- *start_ptr
);
6629 enum dwarf_location_list_entry_type llet
;
6631 if (start
+ 1 > section_end
)
6633 warn (_("Location list starting at offset %#" PRIx64
6634 " is not terminated.\n"), offset
);
6641 SAFE_BYTE_GET_AND_INC (llet
, start
, 1, section_end
);
6643 if (vstart
&& (llet
== DW_LLE_offset_pair
6644 || llet
== DW_LLE_start_end
6645 || llet
== DW_LLE_start_length
))
6647 off
= offset
+ (vstart
- *start_ptr
);
6649 READ_ULEB (vbegin
, vstart
, section_end
);
6650 print_view (vbegin
, pointer_size
);
6652 READ_ULEB (vend
, vstart
, section_end
);
6653 print_view (vend
, pointer_size
);
6655 printf (_("views at %8.8" PRIx64
" for:\n %*s "), off
, 8, "");
6660 case DW_LLE_end_of_list
:
6661 printf (_("<End of list>\n"));
6664 case DW_LLE_base_addressx
:
6665 READ_ULEB (base_address
, start
, section_end
);
6666 print_hex (base_address
, pointer_size
);
6667 printf (_("(index into .debug_addr) "));
6668 base_address
= fetch_indexed_addr (base_address
, pointer_size
);
6669 print_hex (base_address
, pointer_size
);
6670 printf (_("(base address)\n"));
6673 case DW_LLE_startx_endx
:
6674 READ_ULEB (begin
, start
, section_end
);
6675 begin
= fetch_indexed_addr (begin
, pointer_size
);
6676 READ_ULEB (end
, start
, section_end
);
6677 end
= fetch_indexed_addr (end
, pointer_size
);
6680 case DW_LLE_startx_length
:
6681 READ_ULEB (begin
, start
, section_end
);
6682 begin
= fetch_indexed_addr (begin
, pointer_size
);
6683 READ_ULEB (end
, start
, section_end
);
6687 case DW_LLE_default_location
:
6691 case DW_LLE_offset_pair
:
6692 READ_ULEB (begin
, start
, section_end
);
6693 begin
+= base_address
;
6694 READ_ULEB (end
, start
, section_end
);
6695 end
+= base_address
;
6698 case DW_LLE_base_address
:
6699 SAFE_BYTE_GET_AND_INC (base_address
, start
, pointer_size
,
6701 print_hex (base_address
, pointer_size
);
6702 printf (_("(base address)\n"));
6705 case DW_LLE_start_end
:
6706 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, section_end
);
6707 SAFE_BYTE_GET_AND_INC (end
, start
, pointer_size
, section_end
);
6710 case DW_LLE_start_length
:
6711 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, section_end
);
6712 READ_ULEB (end
, start
, section_end
);
6716 #ifdef DW_LLE_view_pair
6717 case DW_LLE_view_pair
:
6719 printf (_("View pair entry in loclist with locviews attribute\n"));
6720 READ_ULEB (vbegin
, start
, section_end
);
6721 print_view (vbegin
, pointer_size
);
6723 READ_ULEB (vend
, start
, section_end
);
6724 print_view (vend
, pointer_size
);
6726 printf (_("views for:\n"));
6731 error (_("Invalid location list entry type %d\n"), llet
);
6735 if (llet
== DW_LLE_end_of_list
)
6738 if (llet
== DW_LLE_base_address
6739 || llet
== DW_LLE_base_addressx
)
6742 if (start
== section_end
)
6744 warn (_("Location list starting at offset %#" PRIx64
6745 " is not terminated.\n"), offset
);
6748 READ_ULEB (length
, start
, section_end
);
6750 if (length
> (size_t) (section_end
- start
))
6752 warn (_("Location list starting at offset %#" PRIx64
6753 " is not terminated.\n"), offset
);
6757 print_hex (begin
, pointer_size
);
6758 print_hex (end
, pointer_size
);
6761 need_frame_base
= decode_location_expression (start
,
6766 cu_offset
, section
);
6769 if (need_frame_base
&& !has_frame_base
)
6770 printf (_(" [without DW_AT_frame_base]"));
6772 if (begin
== end
&& vbegin
== vend
)
6773 fputs (_(" (start == end)"), stdout
);
6774 else if (begin
> end
|| (begin
== end
&& vbegin
> vend
))
6775 fputs (_(" (start > end)"), stdout
);
6783 if (vbegin
!= (uint64_t) -1 || vend
!= (uint64_t) -1)
6784 printf (_("Trailing view pair not used in a range"));
6787 *vstart_ptr
= vstart
;
6790 /* Print a .debug_addr table index in decimal, surrounded by square brackets,
6791 right-adjusted in a field of length LEN, and followed by a space. */
6794 print_addr_index (unsigned int idx
, unsigned int len
)
6796 static char buf
[15];
6797 snprintf (buf
, sizeof (buf
), "[%d]", idx
);
6798 printf ("%*s ", len
, buf
);
6801 /* Display a location list from a .dwo section. It uses address indexes rather
6802 than embedded addresses. This code closely follows display_loc_list, but the
6803 two are sufficiently different that combining things is very ugly. */
6806 display_loc_list_dwo (struct dwarf_section
*section
,
6807 unsigned char **start_ptr
,
6808 unsigned int debug_info_entry
,
6810 unsigned char **vstart_ptr
,
6813 unsigned char *start
= *start_ptr
, *vstart
= *vstart_ptr
;
6814 unsigned char *section_end
= section
->start
+ section
->size
;
6816 unsigned int pointer_size
;
6817 unsigned int offset_size
;
6820 unsigned short length
;
6821 int need_frame_base
;
6824 if (debug_info_entry
>= num_debug_info_entries
)
6826 warn (_("No debug information for loc lists of entry: %u\n"),
6831 cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
6832 pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
6833 offset_size
= debug_information
[debug_info_entry
].offset_size
;
6834 dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
6836 if (pointer_size
< 2 || pointer_size
> 8)
6838 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
6839 pointer_size
, debug_info_entry
);
6846 print_hex (offset
+ (start
- *start_ptr
), 4);
6848 if (start
>= section_end
)
6850 warn (_("Location list starting at offset %#" PRIx64
6851 " is not terminated.\n"), offset
);
6855 SAFE_BYTE_GET_AND_INC (entry_type
, start
, 1, section_end
);
6868 uint64_t off
= offset
+ (vstart
- *start_ptr
);
6870 READ_ULEB (view
, vstart
, section_end
);
6871 print_view (view
, 8);
6873 READ_ULEB (view
, vstart
, section_end
);
6874 print_view (view
, 8);
6876 printf (_("views at %8.8" PRIx64
" for:\n %*s "), off
, 8, "");
6884 case 0: /* A terminating entry. */
6886 *vstart_ptr
= vstart
;
6887 printf (_("<End of list>\n"));
6889 case 1: /* A base-address entry. */
6890 READ_ULEB (idx
, start
, section_end
);
6891 print_addr_index (idx
, 8);
6892 printf ("%*s", 9 + (vstart
? 2 * 6 : 0), "");
6893 printf (_("(base address selection entry)\n"));
6895 case 2: /* A start/end entry. */
6896 READ_ULEB (idx
, start
, section_end
);
6897 print_addr_index (idx
, 8);
6898 READ_ULEB (idx
, start
, section_end
);
6899 print_addr_index (idx
, 8);
6901 case 3: /* A start/length entry. */
6902 READ_ULEB (idx
, start
, section_end
);
6903 print_addr_index (idx
, 8);
6904 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
6905 printf ("%08x ", idx
);
6907 case 4: /* An offset pair entry. */
6908 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
6909 printf ("%08x ", idx
);
6910 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
6911 printf ("%08x ", idx
);
6914 warn (_("Unknown location list entry type 0x%x.\n"), entry_type
);
6916 *vstart_ptr
= vstart
;
6920 if (2 > (size_t) (section_end
- start
))
6922 warn (_("Location list starting at offset %#" PRIx64
6923 " is not terminated.\n"), offset
);
6927 SAFE_BYTE_GET_AND_INC (length
, start
, 2, section_end
);
6928 if (length
> (size_t) (section_end
- start
))
6930 warn (_("Location list starting at offset %#" PRIx64
6931 " is not terminated.\n"), offset
);
6936 need_frame_base
= decode_location_expression (start
,
6941 cu_offset
, section
);
6944 if (need_frame_base
&& !has_frame_base
)
6945 printf (_(" [without DW_AT_frame_base]"));
6953 *vstart_ptr
= vstart
;
6956 /* Sort array of indexes in ascending order of loc_offsets[idx] and
6959 static uint64_t *loc_offsets
, *loc_views
;
6962 loc_offsets_compar (const void *ap
, const void *bp
)
6964 uint64_t a
= loc_offsets
[*(const unsigned int *) ap
];
6965 uint64_t b
= loc_offsets
[*(const unsigned int *) bp
];
6967 int ret
= (a
> b
) - (b
> a
);
6971 a
= loc_views
[*(const unsigned int *) ap
];
6972 b
= loc_views
[*(const unsigned int *) bp
];
6974 ret
= (a
> b
) - (b
> a
);
6980 display_offset_entry_loclists (struct dwarf_section
*section
)
6982 unsigned char * start
= section
->start
;
6983 unsigned char * const end
= start
+ section
->size
;
6985 introduce (section
, false);
6990 unsigned short version
;
6991 unsigned char address_size
;
6992 unsigned char segment_selector_size
;
6993 uint32_t offset_entry_count
;
6997 printf (_("Table at Offset %#tx\n"), start
- section
->start
);
6999 SAFE_BYTE_GET_AND_INC (length
, start
, 4, end
);
7000 if (length
== 0xffffffff)
7003 SAFE_BYTE_GET_AND_INC (length
, start
, 8, end
);
7008 SAFE_BYTE_GET_AND_INC (version
, start
, 2, end
);
7009 SAFE_BYTE_GET_AND_INC (address_size
, start
, 1, end
);
7010 SAFE_BYTE_GET_AND_INC (segment_selector_size
, start
, 1, end
);
7011 SAFE_BYTE_GET_AND_INC (offset_entry_count
, start
, 4, end
);
7013 printf (_(" Length: %#" PRIx64
"\n"), length
);
7014 printf (_(" DWARF version: %u\n"), version
);
7015 printf (_(" Address size: %u\n"), address_size
);
7016 printf (_(" Segment size: %u\n"), segment_selector_size
);
7017 printf (_(" Offset entries: %u\n"), offset_entry_count
);
7021 warn (_("The %s section contains a corrupt or "
7022 "unsupported version number: %d.\n"),
7023 section
->name
, version
);
7027 if (segment_selector_size
!= 0)
7029 warn (_("The %s section contains an "
7030 "unsupported segment selector size: %d.\n"),
7031 section
->name
, segment_selector_size
);
7035 if (offset_entry_count
== 0)
7037 warn (_("The %s section contains a table without offset\n"),
7042 printf (_("\n Offset Entries starting at %#tx:\n"),
7043 start
- section
->start
);
7045 for (i
= 0; i
< offset_entry_count
; i
++)
7049 SAFE_BYTE_GET_AND_INC (entry
, start
, is_64bit
? 8 : 4, end
);
7050 printf (_(" [%6u] %#" PRIx64
"\n"), i
, entry
);
7057 for (j
= 1, i
= 0; i
< offset_entry_count
;)
7060 uint64_t base_address
= 0;
7063 uint64_t off
= start
- section
->start
;
7067 printf (_(" Offset Entry %u\n"), i
);
7074 SAFE_BYTE_GET_AND_INC (lle
, start
, 1, end
);
7078 case DW_LLE_end_of_list
:
7079 printf (_("<End of list>\n\n"));
7083 case DW_LLE_base_addressx
:
7084 READ_ULEB (base_address
, start
, end
);
7085 print_hex (base_address
, address_size
);
7086 printf (_("(index into .debug_addr) "));
7087 base_address
= fetch_indexed_addr (base_address
, address_size
);
7088 print_hex (base_address
, address_size
);
7089 printf (_("(base address)\n"));
7092 case DW_LLE_startx_endx
:
7093 READ_ULEB (begin
, start
, end
);
7094 begin
= fetch_indexed_addr (begin
, address_size
);
7095 READ_ULEB (finish
, start
, end
);
7096 finish
= fetch_indexed_addr (finish
, address_size
);
7099 case DW_LLE_startx_length
:
7100 READ_ULEB (begin
, start
, end
);
7101 begin
= fetch_indexed_addr (begin
, address_size
);
7102 READ_ULEB (finish
, start
, end
);
7106 case DW_LLE_offset_pair
:
7107 READ_ULEB (begin
, start
, end
);
7108 begin
+= base_address
;
7109 READ_ULEB (finish
, start
, end
);
7110 finish
+= base_address
;
7113 case DW_LLE_default_location
:
7117 case DW_LLE_base_address
:
7118 SAFE_BYTE_GET_AND_INC (base_address
, start
, address_size
, end
);
7119 print_hex (base_address
, address_size
);
7120 printf (_("(base address)\n"));
7123 case DW_LLE_start_end
:
7124 SAFE_BYTE_GET_AND_INC (begin
, start
, address_size
, end
);
7125 SAFE_BYTE_GET_AND_INC (finish
, start
, address_size
, end
);
7128 case DW_LLE_start_length
:
7129 SAFE_BYTE_GET_AND_INC (begin
, start
, address_size
, end
);
7130 READ_ULEB (finish
, start
, end
);
7135 error (_("Invalid location list entry type %d\n"), lle
);
7141 warn (_("Location list starting at offset %#" PRIx64
7142 " is not terminated.\n"), off
);
7146 print_hex (begin
, address_size
);
7147 print_hex (finish
, address_size
);
7149 if (begin
== finish
)
7150 fputs (_("(start == end)"), stdout
);
7151 else if (begin
> finish
)
7152 fputs (_("(start > end)"), stdout
);
7154 /* Read the counted location descriptions. */
7155 READ_ULEB (length
, start
, end
);
7157 if (length
> (size_t) (end
- start
))
7159 warn (_("Location list starting at offset %#" PRIx64
7160 " is not terminated.\n"), off
);
7164 (void) decode_location_expression (start
, address_size
, address_size
,
7165 version
, length
, 0, section
);
7172 while (start
< end
);
7178 display_debug_loc (struct dwarf_section
*section
, void *file
)
7180 unsigned char *start
= section
->start
, *vstart
= NULL
;
7182 unsigned char *section_begin
= start
;
7183 unsigned int num_loc_list
= 0;
7184 uint64_t last_offset
= 0;
7185 uint64_t last_view
= 0;
7186 unsigned int first
= 0;
7189 int seen_first_offset
= 0;
7190 int locs_sorted
= 1;
7191 unsigned char *next
= start
, *vnext
= vstart
;
7192 unsigned int *array
= NULL
;
7193 const char *suffix
= strrchr (section
->name
, '.');
7194 bool is_dwo
= false;
7195 int is_loclists
= strstr (section
->name
, "debug_loclists") != NULL
;
7196 uint64_t header_size
= 0;
7198 if (suffix
&& strcmp (suffix
, ".dwo") == 0)
7201 bytes
= section
->size
;
7205 printf (_("\nThe %s section is empty.\n"), section
->name
);
7211 unsigned char *hdrptr
= section_begin
;
7213 unsigned short ll_version
;
7214 unsigned char *end
= section_begin
+ section
->size
;
7215 unsigned char address_size
, segment_selector_size
;
7216 uint32_t offset_entry_count
;
7218 SAFE_BYTE_GET_AND_INC (ll_length
, hdrptr
, 4, end
);
7219 if (ll_length
== 0xffffffff)
7220 SAFE_BYTE_GET_AND_INC (ll_length
, hdrptr
, 8, end
);
7222 SAFE_BYTE_GET_AND_INC (ll_version
, hdrptr
, 2, end
);
7223 if (ll_version
!= 5)
7225 warn (_("The %s section contains corrupt or "
7226 "unsupported version number: %d.\n"),
7227 section
->name
, ll_version
);
7231 SAFE_BYTE_GET_AND_INC (address_size
, hdrptr
, 1, end
);
7233 SAFE_BYTE_GET_AND_INC (segment_selector_size
, hdrptr
, 1, end
);
7234 if (segment_selector_size
!= 0)
7236 warn (_("The %s section contains "
7237 "unsupported segment selector size: %d.\n"),
7238 section
->name
, segment_selector_size
);
7242 SAFE_BYTE_GET_AND_INC (offset_entry_count
, hdrptr
, 4, end
);
7244 if (offset_entry_count
!= 0)
7245 return display_offset_entry_loclists (section
);
7247 header_size
= hdrptr
- section_begin
;
7250 if (load_debug_info (file
) == 0)
7252 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
7257 /* Check the order of location list in .debug_info section. If
7258 offsets of location lists are in the ascending order, we can
7259 use `debug_information' directly. */
7260 for (i
= 0; i
< num_debug_info_entries
; i
++)
7264 num
= debug_information
[i
].num_loc_offsets
;
7265 if (num
> num_loc_list
)
7268 /* Check if we can use `debug_information' directly. */
7269 if (locs_sorted
&& num
!= 0)
7271 if (!seen_first_offset
)
7273 /* This is the first location list. */
7274 last_offset
= debug_information
[i
].loc_offsets
[0];
7275 last_view
= debug_information
[i
].loc_views
[0];
7277 seen_first_offset
= 1;
7283 for (; j
< num
; j
++)
7286 debug_information
[i
].loc_offsets
[j
]
7287 || (last_offset
== debug_information
[i
].loc_offsets
[j
]
7288 && last_view
> debug_information
[i
].loc_views
[j
]))
7293 last_offset
= debug_information
[i
].loc_offsets
[j
];
7294 last_view
= debug_information
[i
].loc_views
[j
];
7299 if (!seen_first_offset
)
7300 error (_("No location lists in .debug_info section!\n"));
7302 if (debug_information
[first
].num_loc_offsets
> 0
7303 && debug_information
[first
].loc_offsets
[0] != header_size
7304 && debug_information
[first
].loc_views
[0] != header_size
)
7305 warn (_("Location lists in %s section start at %#" PRIx64
7306 " rather than %#" PRIx64
"\n"),
7307 section
->name
, debug_information
[first
].loc_offsets
[0],
7311 array
= (unsigned int *) xcmalloc (num_loc_list
, sizeof (unsigned int));
7313 introduce (section
, false);
7315 if (reloc_at (section
, 0))
7316 printf (_(" Warning: This section has relocations - addresses seen here may not be accurate.\n\n"));
7318 printf (_(" Offset Begin End Expression\n"));
7320 for (i
= first
; i
< num_debug_info_entries
; i
++)
7322 uint64_t offset
= 0, voffset
= 0;
7323 uint64_t base_address
;
7329 for (k
= 0; k
< debug_information
[i
].num_loc_offsets
; k
++)
7331 loc_offsets
= debug_information
[i
].loc_offsets
;
7332 loc_views
= debug_information
[i
].loc_views
;
7333 qsort (array
, debug_information
[i
].num_loc_offsets
,
7334 sizeof (*array
), loc_offsets_compar
);
7337 /* .debug_loclists has a per-unit header.
7338 Update start if we are detecting it. */
7339 if (debug_information
[i
].dwarf_version
== 5)
7341 j
= locs_sorted
? 0 : array
[0];
7343 if (debug_information
[i
].num_loc_offsets
)
7344 offset
= debug_information
[i
].loc_offsets
[j
];
7346 if (debug_information
[i
].num_loc_views
)
7347 voffset
= debug_information
[i
].loc_views
[j
];
7349 /* Assume that the size of the header is constant across CUs. */
7350 if (((start
- section_begin
) + header_size
== offset
)
7351 || ((start
-section_begin
) + header_size
== voffset
))
7352 start
+= header_size
;
7355 int adjacent_view_loclists
= 1;
7356 for (k
= 0; k
< debug_information
[i
].num_loc_offsets
; k
++)
7358 j
= locs_sorted
? k
: array
[k
];
7360 && (debug_information
[i
].loc_offsets
[locs_sorted
7361 ? k
- 1 : array
[k
- 1]]
7362 == debug_information
[i
].loc_offsets
[j
])
7363 && (debug_information
[i
].loc_views
[locs_sorted
7364 ? k
- 1 : array
[k
- 1]]
7365 == debug_information
[i
].loc_views
[j
]))
7367 has_frame_base
= debug_information
[i
].have_frame_base
[j
];
7368 offset
= debug_information
[i
].loc_offsets
[j
];
7369 next
= section_begin
+ offset
;
7370 voffset
= debug_information
[i
].loc_views
[j
];
7371 if (voffset
!= (uint64_t) -1)
7372 vnext
= section_begin
+ voffset
;
7375 base_address
= debug_information
[i
].base_address
;
7377 if (vnext
&& vnext
< next
)
7380 display_view_pair_list (section
, &vstart
, i
, next
);
7387 if (vnext
&& vnext
< next
)
7388 warn (_("There is a hole [%#tx - %#" PRIx64
"]"
7389 " in %s section.\n"),
7390 start
- section_begin
, voffset
, section
->name
);
7392 warn (_("There is a hole [%#tx - %#" PRIx64
"]"
7393 " in %s section.\n"),
7394 start
- section_begin
, offset
, section
->name
);
7396 else if (start
> next
)
7397 warn (_("There is an overlap [%#tx - %#" PRIx64
"]"
7398 " in %s section.\n"),
7399 start
- section_begin
, offset
, section
->name
);
7403 if (offset
>= bytes
)
7405 warn (_("Offset %#" PRIx64
" is bigger than %s section size.\n"),
7406 offset
, section
->name
);
7410 if (vnext
&& voffset
>= bytes
)
7412 warn (_("View Offset %#" PRIx64
" is bigger than %s section size.\n"),
7413 voffset
, section
->name
);
7420 display_loc_list_dwo (section
, &start
, i
, offset
,
7421 &vstart
, has_frame_base
);
7423 display_loc_list (section
, &start
, i
, offset
, base_address
,
7424 &vstart
, has_frame_base
);
7429 warn (_("DWO is not yet supported.\n"));
7431 display_loclists_list (section
, &start
, i
, offset
, base_address
,
7432 &vstart
, has_frame_base
);
7435 /* FIXME: this arrangement is quite simplistic. Nothing
7436 requires locview lists to be adjacent to corresponding
7437 loclists, and a single loclist could be augmented by
7438 different locview lists, and vice-versa, unlikely as it
7439 is that it would make sense to do so. Hopefully we'll
7440 have view pair support built into loclists before we ever
7441 need to address all these possibilities. */
7442 if (adjacent_view_loclists
&& vnext
7443 && vnext
!= start
&& vstart
!= next
)
7445 adjacent_view_loclists
= 0;
7446 warn (_("Hole and overlap detection requires adjacent view lists and loclists.\n"));
7449 if (vnext
&& vnext
== start
)
7450 display_view_pair_list (section
, &start
, i
, vstart
);
7454 if (start
< section
->start
+ section
->size
)
7455 warn (ngettext ("There is %ld unused byte at the end of section %s\n",
7456 "There are %ld unused bytes at the end of section %s\n",
7457 (long) (section
->start
+ section
->size
- start
)),
7458 (long) (section
->start
+ section
->size
- start
), section
->name
);
7465 display_debug_str (struct dwarf_section
*section
,
7466 void *file ATTRIBUTE_UNUSED
)
7468 unsigned char *start
= section
->start
;
7469 uint64_t bytes
= section
->size
;
7470 uint64_t addr
= section
->address
;
7474 printf (_("\nThe %s section is empty.\n"), section
->name
);
7478 introduce (section
, false);
7486 lbytes
= (bytes
> 16 ? 16 : bytes
);
7488 printf (" 0x%8.8" PRIx64
" ", addr
);
7490 for (j
= 0; j
< 16; j
++)
7493 printf ("%2.2x", start
[j
]);
7501 for (j
= 0; j
< lbytes
; j
++)
7504 if (k
>= ' ' && k
< 0x80)
7523 display_debug_info (struct dwarf_section
*section
, void *file
)
7525 return process_debug_info (section
, file
, section
->abbrev_sec
, false, false);
7529 display_debug_types (struct dwarf_section
*section
, void *file
)
7531 return process_debug_info (section
, file
, section
->abbrev_sec
, false, true);
7535 display_trace_info (struct dwarf_section
*section
, void *file
)
7537 return process_debug_info (section
, file
, section
->abbrev_sec
, false, true);
7541 display_debug_aranges (struct dwarf_section
*section
,
7542 void *file ATTRIBUTE_UNUSED
)
7544 unsigned char *start
= section
->start
;
7545 unsigned char *end
= start
+ section
->size
;
7547 introduce (section
, false);
7549 /* It does not matter if this load fails,
7550 we test for that later on. */
7551 load_debug_info (file
);
7555 unsigned char *hdrptr
;
7556 DWARF2_Internal_ARange arange
;
7557 unsigned char *addr_ranges
;
7561 unsigned char address_size
;
7562 unsigned int offset_size
;
7563 unsigned char *end_ranges
;
7566 sec_off
= hdrptr
- section
->start
;
7568 SAFE_BYTE_GET_AND_INC (arange
.ar_length
, hdrptr
, 4, end
);
7569 if (arange
.ar_length
== 0xffffffff)
7571 SAFE_BYTE_GET_AND_INC (arange
.ar_length
, hdrptr
, 8, end
);
7577 if (arange
.ar_length
> (size_t) (end
- hdrptr
))
7579 warn (_("Debug info is corrupted, %s header at %#" PRIx64
7580 " has length %#" PRIx64
"\n"),
7581 section
->name
, sec_off
, arange
.ar_length
);
7584 end_ranges
= hdrptr
+ arange
.ar_length
;
7586 SAFE_BYTE_GET_AND_INC (arange
.ar_version
, hdrptr
, 2, end_ranges
);
7587 SAFE_BYTE_GET_AND_INC (arange
.ar_info_offset
, hdrptr
, offset_size
,
7590 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
7591 && num_debug_info_entries
> 0
7592 && find_debug_info_for_offset (arange
.ar_info_offset
) == NULL
)
7593 warn (_(".debug_info offset of %#" PRIx64
7594 " in %s section does not point to a CU header.\n"),
7595 arange
.ar_info_offset
, section
->name
);
7597 SAFE_BYTE_GET_AND_INC (arange
.ar_pointer_size
, hdrptr
, 1, end_ranges
);
7598 SAFE_BYTE_GET_AND_INC (arange
.ar_segment_size
, hdrptr
, 1, end_ranges
);
7600 if (arange
.ar_version
!= 2 && arange
.ar_version
!= 3)
7602 /* PR 19872: A version number of 0 probably means that there is
7603 padding at the end of the .debug_aranges section. Gold puts
7604 it there when performing an incremental link, for example.
7605 So do not generate a warning in this case. */
7606 if (arange
.ar_version
)
7607 warn (_("Only DWARF 2 and 3 aranges are currently supported.\n"));
7611 printf (_(" Length: %" PRId64
"\n"), arange
.ar_length
);
7612 printf (_(" Version: %d\n"), arange
.ar_version
);
7613 printf (_(" Offset into .debug_info: %#" PRIx64
"\n"),
7614 arange
.ar_info_offset
);
7615 printf (_(" Pointer Size: %d\n"), arange
.ar_pointer_size
);
7616 printf (_(" Segment Size: %d\n"), arange
.ar_segment_size
);
7618 address_size
= arange
.ar_pointer_size
+ arange
.ar_segment_size
;
7620 /* PR 17512: file: 001-108546-0.001:0.1. */
7621 if (address_size
== 0 || address_size
> 8)
7623 error (_("Invalid address size in %s section!\n"),
7628 /* The DWARF spec does not require that the address size be a power
7629 of two, but we do. This will have to change if we ever encounter
7630 an uneven architecture. */
7631 if ((address_size
& (address_size
- 1)) != 0)
7633 warn (_("Pointer size + Segment size is not a power of two.\n"));
7637 if (address_size
> 4)
7638 printf (_("\n Address Length\n"));
7640 printf (_("\n Address Length\n"));
7642 addr_ranges
= hdrptr
;
7644 /* Must pad to an alignment boundary that is twice the address size. */
7645 addr_ranges
+= (2 * address_size
- 1
7646 - (hdrptr
- start
- 1) % (2 * address_size
));
7648 while (2 * address_size
<= end_ranges
- addr_ranges
)
7650 SAFE_BYTE_GET_AND_INC (address
, addr_ranges
, address_size
,
7652 SAFE_BYTE_GET_AND_INC (length
, addr_ranges
, address_size
,
7655 print_hex (address
, address_size
);
7656 print_hex_ns (length
, address_size
);
7668 /* Comparison function for qsort. */
7670 comp_addr_base (const void * v0
, const void * v1
)
7672 debug_info
*info0
= *(debug_info
**) v0
;
7673 debug_info
*info1
= *(debug_info
**) v1
;
7674 return info0
->addr_base
- info1
->addr_base
;
7677 /* Display the debug_addr section. */
7679 display_debug_addr (struct dwarf_section
*section
,
7682 debug_info
**debug_addr_info
;
7683 unsigned char *entry
;
7687 unsigned char * header
;
7689 if (section
->size
== 0)
7691 printf (_("\nThe %s section is empty.\n"), section
->name
);
7695 if (load_debug_info (file
) == 0)
7697 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
7702 introduce (section
, false);
7704 /* PR 17531: file: cf38d01b.
7705 We use xcalloc because a corrupt file may not have initialised all of the
7706 fields in the debug_info structure, which means that the sort below might
7707 try to move uninitialised data. */
7708 debug_addr_info
= (debug_info
**) xcalloc ((num_debug_info_entries
+ 1),
7709 sizeof (debug_info
*));
7712 for (i
= 0; i
< num_debug_info_entries
; i
++)
7713 if (debug_information
[i
].addr_base
!= DEBUG_INFO_UNAVAILABLE
)
7715 /* PR 17531: file: cf38d01b. */
7716 if (debug_information
[i
].addr_base
>= section
->size
)
7717 warn (_("Corrupt address base (%#" PRIx64
")"
7718 " found in debug section %u\n"),
7719 debug_information
[i
].addr_base
, i
);
7721 debug_addr_info
[count
++] = debug_information
+ i
;
7724 /* Add a sentinel to make iteration convenient. */
7725 debug_addr_info
[count
] = (debug_info
*) xmalloc (sizeof (debug_info
));
7726 debug_addr_info
[count
]->addr_base
= section
->size
;
7727 qsort (debug_addr_info
, count
, sizeof (debug_info
*), comp_addr_base
);
7729 header
= section
->start
;
7730 for (i
= 0; i
< count
; i
++)
7733 unsigned int address_size
= debug_addr_info
[i
]->pointer_size
;
7735 printf (_(" For compilation unit at offset %#" PRIx64
":\n"),
7736 debug_addr_info
[i
]->cu_offset
);
7738 printf (_("\tIndex\tAddress\n"));
7739 entry
= section
->start
+ debug_addr_info
[i
]->addr_base
;
7740 if (debug_addr_info
[i
]->dwarf_version
>= 5)
7742 size_t header_size
= entry
- header
;
7743 unsigned char *curr_header
= header
;
7746 int segment_selector_size
;
7748 if (header_size
!= 8 && header_size
!= 16)
7750 warn (_("Corrupt %s section: expecting header size of 8 or 16, but found %zd instead\n"),
7751 section
->name
, header_size
);
7755 SAFE_BYTE_GET_AND_INC (length
, curr_header
, 4, entry
);
7756 if (length
== 0xffffffff)
7757 SAFE_BYTE_GET_AND_INC (length
, curr_header
, 8, entry
);
7758 if (length
> (size_t) (section
->start
+ section
->size
- curr_header
)
7759 || length
< (size_t) (entry
- curr_header
))
7761 warn (_("Corrupt %s section: unit_length field of %#" PRIx64
7762 " is invalid\n"), section
->name
, length
);
7765 end
= curr_header
+ length
;
7766 SAFE_BYTE_GET_AND_INC (version
, curr_header
, 2, entry
);
7768 warn (_("Corrupt %s section: expecting version number 5 in header but found %d instead\n"),
7769 section
->name
, version
);
7771 SAFE_BYTE_GET_AND_INC (address_size
, curr_header
, 1, entry
);
7772 SAFE_BYTE_GET_AND_INC (segment_selector_size
, curr_header
, 1, entry
);
7773 address_size
+= segment_selector_size
;
7776 end
= section
->start
+ debug_addr_info
[i
+ 1]->addr_base
;
7781 if (address_size
< 1 || address_size
> sizeof (uint64_t))
7783 warn (_("Corrupt %s section: address size (%x) is wrong"),
7784 section
->name
, address_size
);
7788 while ((size_t) (end
- entry
) >= address_size
)
7790 uint64_t base
= byte_get (entry
, address_size
);
7791 printf (_("\t%d:\t"), idx
);
7792 print_hex_ns (base
, address_size
);
7794 entry
+= address_size
;
7800 free (debug_addr_info
);
7804 /* Display the .debug_str_offsets and .debug_str_offsets.dwo sections. */
7807 display_debug_str_offsets (struct dwarf_section
*section
,
7808 void *file ATTRIBUTE_UNUSED
)
7812 if (section
->size
== 0)
7814 printf (_("\nThe %s section is empty.\n"), section
->name
);
7818 unsigned char *start
= section
->start
;
7819 unsigned char *end
= start
+ section
->size
;
7820 unsigned char *curr
= start
;
7821 uint64_t debug_str_offsets_hdr_len
;
7823 const char *suffix
= strrchr (section
->name
, '.');
7824 bool dwo
= suffix
&& strcmp (suffix
, ".dwo") == 0;
7827 load_debug_section_with_follow (str_dwo
, file
);
7829 load_debug_section_with_follow (str
, file
);
7831 introduce (section
, false);
7836 uint64_t entry_length
;
7838 SAFE_BYTE_GET_AND_INC (length
, curr
, 4, end
);
7839 /* FIXME: We assume that this means 64-bit DWARF is being used. */
7840 if (length
== 0xffffffff)
7842 SAFE_BYTE_GET_AND_INC (length
, curr
, 8, end
);
7844 debug_str_offsets_hdr_len
= 16;
7849 debug_str_offsets_hdr_len
= 8;
7852 unsigned char *entries_end
;
7855 /* This is probably an old style .debug_str_offset section which
7856 just contains offsets and no header (and the first offset is 0). */
7857 length
= section
->size
;
7858 curr
= section
->start
;
7861 printf (_(" Length: %#" PRIx64
"\n"), length
);
7862 printf (_(" Index Offset [String]\n"));
7866 if (length
<= (size_t) (end
- curr
))
7867 entries_end
= curr
+ length
;
7870 warn (_("Section %s is too small %#" PRIx64
"\n"),
7871 section
->name
, section
->size
);
7876 SAFE_BYTE_GET_AND_INC (version
, curr
, 2, entries_end
);
7878 warn (_("Unexpected version number in str_offset header: %#x\n"), version
);
7881 SAFE_BYTE_GET_AND_INC (padding
, curr
, 2, entries_end
);
7883 warn (_("Unexpected value in str_offset header's padding field: %#x\n"), padding
);
7885 printf (_(" Length: %#" PRIx64
"\n"), length
);
7886 printf (_(" Version: %#x\n"), version
);
7887 printf (_(" Index Offset [String]\n"));
7890 for (idx
= 0; curr
< entries_end
; idx
++)
7893 const unsigned char * string
;
7895 if ((size_t) (entries_end
- curr
) < entry_length
)
7896 /* Not enough space to read one entry_length, give up. */
7899 SAFE_BYTE_GET_AND_INC (offset
, curr
, entry_length
, entries_end
);
7901 string
= (const unsigned char *)
7902 fetch_indexed_string (idx
, NULL
, entry_length
, dwo
, debug_str_offsets_hdr_len
);
7904 string
= fetch_indirect_string (offset
);
7906 printf (" %8lu ", idx
);
7907 print_hex (offset
, entry_length
);
7908 printf (" %s\n", string
);
7915 /* Each debug_information[x].range_lists[y] gets this representation for
7916 sorting purposes. */
7920 /* The debug_information[x].range_lists[y] value. */
7921 uint64_t ranges_offset
;
7923 /* Original debug_information to find parameters of the data. */
7924 debug_info
*debug_info_p
;
7927 /* Sort struct range_entry in ascending order of its RANGES_OFFSET. */
7930 range_entry_compar (const void *ap
, const void *bp
)
7932 const struct range_entry
*a_re
= (const struct range_entry
*) ap
;
7933 const struct range_entry
*b_re
= (const struct range_entry
*) bp
;
7934 const uint64_t a
= a_re
->ranges_offset
;
7935 const uint64_t b
= b_re
->ranges_offset
;
7937 return (a
> b
) - (b
> a
);
7941 display_debug_ranges_list (unsigned char * start
,
7942 unsigned char * finish
,
7943 unsigned int pointer_size
,
7945 uint64_t base_address
)
7947 while (start
< finish
)
7952 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
7953 if (start
>= finish
)
7955 SAFE_SIGNED_BYTE_GET_AND_INC (end
, start
, pointer_size
, finish
);
7958 print_hex (offset
, 4);
7960 if (begin
== 0 && end
== 0)
7962 printf (_("<End of list>\n"));
7966 /* Check base address specifiers. */
7967 if (is_max_address (begin
, pointer_size
)
7968 && !is_max_address (end
, pointer_size
))
7971 print_hex (begin
, pointer_size
);
7972 print_hex (end
, pointer_size
);
7973 printf ("(base address)\n");
7977 print_hex (begin
+ base_address
, pointer_size
);
7978 print_hex_ns (end
+ base_address
, pointer_size
);
7981 fputs (_(" (start == end)"), stdout
);
7982 else if (begin
> end
)
7983 fputs (_(" (start > end)"), stdout
);
7989 static unsigned char *
7990 display_debug_rnglists_list (unsigned char * start
,
7991 unsigned char * finish
,
7992 unsigned int pointer_size
,
7994 uint64_t base_address
,
7995 unsigned int offset_size
)
7997 unsigned char *next
= start
;
7998 unsigned int debug_addr_section_hdr_len
;
8000 if (offset_size
== 4)
8001 debug_addr_section_hdr_len
= 8;
8003 debug_addr_section_hdr_len
= 16;
8007 uint64_t off
= offset
+ (start
- next
);
8008 enum dwarf_range_list_entry rlet
;
8009 /* Initialize it due to a false compiler warning. */
8010 uint64_t begin
= -1, length
, end
= -1;
8012 if (start
>= finish
)
8014 warn (_("Range list starting at offset %#" PRIx64
8015 " is not terminated.\n"), offset
);
8022 SAFE_BYTE_GET_AND_INC (rlet
, start
, 1, finish
);
8026 case DW_RLE_end_of_list
:
8027 printf (_("<End of list>\n"));
8029 case DW_RLE_base_addressx
:
8030 READ_ULEB (base_address
, start
, finish
);
8031 print_hex (base_address
, pointer_size
);
8032 printf (_("(base address index) "));
8033 base_address
= fetch_indexed_addr ((base_address
* pointer_size
)
8034 + debug_addr_section_hdr_len
, pointer_size
);
8035 print_hex (base_address
, pointer_size
);
8036 printf (_("(base address)\n"));
8038 case DW_RLE_startx_endx
:
8039 READ_ULEB (begin
, start
, finish
);
8040 READ_ULEB (end
, start
, finish
);
8041 begin
= fetch_indexed_addr ((begin
* pointer_size
)
8042 + debug_addr_section_hdr_len
, pointer_size
);
8043 end
= fetch_indexed_addr ((begin
* pointer_size
)
8044 + debug_addr_section_hdr_len
, pointer_size
);
8046 case DW_RLE_startx_length
:
8047 READ_ULEB (begin
, start
, finish
);
8048 READ_ULEB (length
, start
, finish
);
8049 begin
= fetch_indexed_addr ((begin
* pointer_size
)
8050 + debug_addr_section_hdr_len
, pointer_size
);
8051 end
= begin
+ length
;
8053 case DW_RLE_offset_pair
:
8054 READ_ULEB (begin
, start
, finish
);
8055 READ_ULEB (end
, start
, finish
);
8057 case DW_RLE_base_address
:
8058 SAFE_BYTE_GET_AND_INC (base_address
, start
, pointer_size
, finish
);
8059 print_hex (base_address
, pointer_size
);
8060 printf (_("(base address)\n"));
8062 case DW_RLE_start_end
:
8063 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
8064 SAFE_BYTE_GET_AND_INC (end
, start
, pointer_size
, finish
);
8066 case DW_RLE_start_length
:
8067 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
8068 READ_ULEB (length
, start
, finish
);
8069 end
= begin
+ length
;
8072 error (_("Invalid range list entry type %d\n"), rlet
);
8073 rlet
= DW_RLE_end_of_list
;
8077 if (rlet
== DW_RLE_end_of_list
)
8079 if (rlet
== DW_RLE_base_address
|| rlet
== DW_RLE_base_addressx
)
8082 /* Only a DW_RLE_offset_pair needs the base address added. */
8083 if (rlet
== DW_RLE_offset_pair
)
8085 begin
+= base_address
;
8086 end
+= base_address
;
8089 print_hex (begin
, pointer_size
);
8090 print_hex (end
, pointer_size
);
8093 fputs (_(" (start == end)"), stdout
);
8094 else if (begin
> end
)
8095 fputs (_(" (start > end)"), stdout
);
8104 display_debug_rnglists (struct dwarf_section
*section
)
8106 unsigned char *start
= section
->start
;
8107 unsigned char *finish
= start
+ section
->size
;
8109 while (start
< finish
)
8111 unsigned char *table_start
;
8112 uint64_t offset
= start
- section
->start
;
8114 uint64_t initial_length
;
8115 unsigned char segment_selector_size
;
8116 unsigned int offset_entry_count
;
8118 unsigned short version
;
8119 unsigned char address_size
= 0;
8120 unsigned char offset_size
;
8122 /* Get and check the length of the block. */
8123 SAFE_BYTE_GET_AND_INC (initial_length
, start
, 4, finish
);
8125 if (initial_length
== 0xffffffff)
8127 /* This section is 64-bit DWARF 3. */
8128 SAFE_BYTE_GET_AND_INC (initial_length
, start
, 8, finish
);
8134 if (initial_length
> (size_t) (finish
- start
))
8136 /* If the length field has a relocation against it, then we should
8137 not complain if it is inaccurate (and probably negative).
8138 It is copied from .debug_line handling code. */
8139 if (reloc_at (section
, (start
- section
->start
) - offset_size
))
8140 initial_length
= finish
- start
;
8143 warn (_("The length field (%#" PRIx64
8144 ") in the debug_rnglists header is wrong"
8145 " - the section is too small\n"),
8151 end
= start
+ initial_length
;
8153 /* Get the other fields in the header. */
8154 SAFE_BYTE_GET_AND_INC (version
, start
, 2, finish
);
8155 SAFE_BYTE_GET_AND_INC (address_size
, start
, 1, finish
);
8156 SAFE_BYTE_GET_AND_INC (segment_selector_size
, start
, 1, finish
);
8157 SAFE_BYTE_GET_AND_INC (offset_entry_count
, start
, 4, finish
);
8159 printf (_(" Table at Offset: %#" PRIx64
":\n"), offset
);
8160 printf (_(" Length: %#" PRIx64
"\n"), initial_length
);
8161 printf (_(" DWARF version: %u\n"), version
);
8162 printf (_(" Address size: %u\n"), address_size
);
8163 printf (_(" Segment size: %u\n"), segment_selector_size
);
8164 printf (_(" Offset entries: %u\n"), offset_entry_count
);
8166 /* Check the fields. */
8167 if (segment_selector_size
!= 0)
8169 warn (_("The %s section contains "
8170 "unsupported segment selector size: %d.\n"),
8171 section
->name
, segment_selector_size
);
8177 warn (_("Only DWARF version 5+ debug_rnglists info "
8178 "is currently supported.\n"));
8182 table_start
= start
;
8184 if (offset_entry_count
!= 0)
8186 printf (_("\n Offsets starting at %#tx:\n"),
8187 start
- section
->start
);
8189 for (i
= 0; i
< offset_entry_count
; i
++)
8193 SAFE_BYTE_GET_AND_INC (entry
, start
, offset_size
, finish
);
8194 printf (_(" [%6u] %#" PRIx64
"\n"), i
, entry
);
8198 offset_entry_count
= 1;
8200 for (i
= 0; i
< offset_entry_count
; i
++)
8202 uint64_t indx
= start
- table_start
;
8204 offset
= start
- section
->start
;
8205 printf (_("\n Offset: %#" PRIx64
", Index: %#" PRIx64
"\n"),
8207 printf (_(" Offset Begin End\n"));
8208 start
= display_debug_rnglists_list
8209 (start
, end
, address_size
, offset
, 0, offset_size
);
8225 display_debug_ranges (struct dwarf_section
*section
,
8226 void *file ATTRIBUTE_UNUSED
)
8228 unsigned char *start
= section
->start
;
8229 unsigned char *last_start
= start
;
8230 uint64_t bytes
= section
->size
;
8231 unsigned char *section_begin
= start
;
8232 unsigned char *finish
= start
+ bytes
;
8233 unsigned int num_range_list
, i
;
8234 struct range_entry
*range_entries
;
8235 struct range_entry
*range_entry_fill
;
8236 int is_rnglists
= strstr (section
->name
, "debug_rnglists") != NULL
;
8237 /* Initialize it due to a false compiler warning. */
8238 unsigned char address_size
= 0;
8239 uint64_t last_offset
= 0;
8243 printf (_("\nThe %s section is empty.\n"), section
->name
);
8247 introduce (section
, false);
8250 return display_debug_rnglists (section
);
8252 if (load_debug_info (file
) == 0)
8254 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
8260 for (i
= 0; i
< num_debug_info_entries
; i
++)
8261 num_range_list
+= debug_information
[i
].num_range_lists
;
8263 if (num_range_list
== 0)
8265 /* This can happen when the file was compiled with -gsplit-debug
8266 which removes references to range lists from the primary .o file. */
8267 printf (_("No range lists in .debug_info section.\n"));
8271 range_entries
= (struct range_entry
*)
8272 xmalloc (sizeof (*range_entries
) * num_range_list
);
8273 range_entry_fill
= range_entries
;
8275 for (i
= 0; i
< num_debug_info_entries
; i
++)
8277 debug_info
*debug_info_p
= &debug_information
[i
];
8280 for (j
= 0; j
< debug_info_p
->num_range_lists
; j
++)
8282 range_entry_fill
->ranges_offset
= debug_info_p
->range_lists
[j
];
8283 range_entry_fill
->debug_info_p
= debug_info_p
;
8288 qsort (range_entries
, num_range_list
, sizeof (*range_entries
),
8289 range_entry_compar
);
8291 if (dwarf_check
!= 0 && range_entries
[0].ranges_offset
!= 0)
8292 warn (_("Range lists in %s section start at %#" PRIx64
"\n"),
8293 section
->name
, range_entries
[0].ranges_offset
);
8296 printf (_(" Offset Begin End\n"));
8298 for (i
= 0; i
< num_range_list
; i
++)
8300 struct range_entry
*range_entry
= &range_entries
[i
];
8301 debug_info
*debug_info_p
= range_entry
->debug_info_p
;
8302 unsigned int pointer_size
;
8304 unsigned char *next
;
8305 uint64_t base_address
;
8307 pointer_size
= (is_rnglists
? address_size
: debug_info_p
->pointer_size
);
8308 offset
= range_entry
->ranges_offset
;
8309 base_address
= debug_info_p
->base_address
;
8311 /* PR 17512: file: 001-101485-0.001:0.1. */
8312 if (pointer_size
< 2 || pointer_size
> 8)
8314 warn (_("Corrupt pointer size (%d) in debug entry at offset %#" PRIx64
"\n"),
8315 pointer_size
, offset
);
8319 if (offset
> (size_t) (finish
- section_begin
))
8321 warn (_("Corrupt offset (%#" PRIx64
") in range entry %u\n"),
8326 next
= section_begin
+ offset
+ debug_info_p
->rnglists_base
;
8328 /* If multiple DWARF entities reference the same range then we will
8329 have multiple entries in the `range_entries' list for the same
8330 offset. Thanks to the sort above these will all be consecutive in
8331 the `range_entries' list, so we can easily ignore duplicates
8333 if (i
> 0 && last_offset
== offset
)
8335 last_offset
= offset
;
8337 if (dwarf_check
!= 0 && i
> 0)
8340 warn (_("There is a hole [%#tx - %#tx] in %s section.\n"),
8341 start
- section_begin
, next
- section_begin
, section
->name
);
8342 else if (start
> next
)
8344 if (next
== last_start
)
8346 warn (_("There is an overlap [%#tx - %#tx] in %s section.\n"),
8347 start
- section_begin
, next
- section_begin
, section
->name
);
8354 display_debug_ranges_list
8355 (start
, finish
, pointer_size
, offset
, base_address
);
8359 free (range_entries
);
8364 typedef struct Frame_Chunk
8366 struct Frame_Chunk
*next
;
8367 unsigned char *chunk_start
;
8369 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
8370 short int *col_type
;
8371 int64_t *col_offset
;
8373 unsigned int code_factor
;
8377 unsigned int cfa_reg
;
8378 uint64_t cfa_offset
;
8380 unsigned char fde_encoding
;
8381 unsigned char cfa_exp
;
8382 unsigned char ptr_size
;
8383 unsigned char segment_size
;
8387 typedef const char *(*dwarf_regname_lookup_ftype
) (unsigned int);
8388 static dwarf_regname_lookup_ftype dwarf_regnames_lookup_func
;
8389 static const char *const *dwarf_regnames
;
8390 static unsigned int dwarf_regnames_count
;
8391 static bool is_aarch64
;
8393 /* A marker for a col_type that means this column was never referenced
8394 in the frame info. */
8395 #define DW_CFA_unreferenced (-1)
8397 /* Return 0 if no more space is needed, 1 if more space is needed,
8398 -1 for invalid reg. */
8401 frame_need_space (Frame_Chunk
*fc
, unsigned int reg
)
8403 unsigned int prev
= fc
->ncols
;
8405 if (reg
< (unsigned int) fc
->ncols
)
8408 if (dwarf_regnames_count
> 0
8409 && reg
> dwarf_regnames_count
)
8412 fc
->ncols
= reg
+ 1;
8413 /* PR 17512: file: 10450-2643-0.004.
8414 If reg == -1 then this can happen... */
8418 /* PR 17512: file: 2844a11d. */
8419 if (fc
->ncols
> 1024 && dwarf_regnames_count
== 0)
8421 error (_("Unfeasibly large register number: %u\n"), reg
);
8423 /* FIXME: 1024 is an arbitrary limit. Increase it if
8424 we ever encounter a valid binary that exceeds it. */
8428 fc
->col_type
= xcrealloc (fc
->col_type
, fc
->ncols
,
8429 sizeof (*fc
->col_type
));
8430 fc
->col_offset
= xcrealloc (fc
->col_offset
, fc
->ncols
,
8431 sizeof (*fc
->col_offset
));
8432 /* PR 17512: file:002-10025-0.005. */
8433 if (fc
->col_type
== NULL
|| fc
->col_offset
== NULL
)
8435 error (_("Out of memory allocating %u columns in dwarf frame arrays\n"),
8441 while (prev
< fc
->ncols
)
8443 fc
->col_type
[prev
] = DW_CFA_unreferenced
;
8444 fc
->col_offset
[prev
] = 0;
8450 static const char *const dwarf_regnames_i386
[] =
8452 "eax", "ecx", "edx", "ebx", /* 0 - 3 */
8453 "esp", "ebp", "esi", "edi", /* 4 - 7 */
8454 "eip", "eflags", NULL
, /* 8 - 10 */
8455 "st0", "st1", "st2", "st3", /* 11 - 14 */
8456 "st4", "st5", "st6", "st7", /* 15 - 18 */
8457 NULL
, NULL
, /* 19 - 20 */
8458 "xmm0", "xmm1", "xmm2", "xmm3", /* 21 - 24 */
8459 "xmm4", "xmm5", "xmm6", "xmm7", /* 25 - 28 */
8460 "mm0", "mm1", "mm2", "mm3", /* 29 - 32 */
8461 "mm4", "mm5", "mm6", "mm7", /* 33 - 36 */
8462 "fcw", "fsw", "mxcsr", /* 37 - 39 */
8463 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
, /* 40 - 47 */
8464 "tr", "ldtr", /* 48 - 49 */
8465 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 50 - 57 */
8466 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 58 - 65 */
8467 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 66 - 73 */
8468 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 74 - 81 */
8469 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 82 - 89 */
8470 NULL
, NULL
, NULL
, /* 90 - 92 */
8471 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7" /* 93 - 100 */
8474 static const char *const dwarf_regnames_iamcu
[] =
8476 "eax", "ecx", "edx", "ebx", /* 0 - 3 */
8477 "esp", "ebp", "esi", "edi", /* 4 - 7 */
8478 "eip", "eflags", NULL
, /* 8 - 10 */
8479 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 11 - 18 */
8480 NULL
, NULL
, /* 19 - 20 */
8481 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 21 - 28 */
8482 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 29 - 36 */
8483 NULL
, NULL
, NULL
, /* 37 - 39 */
8484 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
, /* 40 - 47 */
8485 "tr", "ldtr", /* 48 - 49 */
8486 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 50 - 57 */
8487 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 58 - 65 */
8488 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 66 - 73 */
8489 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 74 - 81 */
8490 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 82 - 89 */
8491 NULL
, NULL
, NULL
, /* 90 - 92 */
8492 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
/* 93 - 100 */
8496 init_dwarf_regnames_i386 (void)
8498 dwarf_regnames
= dwarf_regnames_i386
;
8499 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_i386
);
8500 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8504 init_dwarf_regnames_iamcu (void)
8506 dwarf_regnames
= dwarf_regnames_iamcu
;
8507 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_iamcu
);
8508 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8511 static const char *const DW_CFA_GNU_window_save_name
[] =
8513 "DW_CFA_GNU_window_save",
8514 "DW_CFA_AARCH64_negate_ra_state"
8517 static const char *const dwarf_regnames_x86_64
[] =
8519 "rax", "rdx", "rcx", "rbx",
8520 "rsi", "rdi", "rbp", "rsp",
8521 "r8", "r9", "r10", "r11",
8522 "r12", "r13", "r14", "r15",
8524 "xmm0", "xmm1", "xmm2", "xmm3",
8525 "xmm4", "xmm5", "xmm6", "xmm7",
8526 "xmm8", "xmm9", "xmm10", "xmm11",
8527 "xmm12", "xmm13", "xmm14", "xmm15",
8528 "st0", "st1", "st2", "st3",
8529 "st4", "st5", "st6", "st7",
8530 "mm0", "mm1", "mm2", "mm3",
8531 "mm4", "mm5", "mm6", "mm7",
8533 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
,
8534 "fs.base", "gs.base", NULL
, NULL
,
8536 "mxcsr", "fcw", "fsw",
8537 "xmm16", "xmm17", "xmm18", "xmm19",
8538 "xmm20", "xmm21", "xmm22", "xmm23",
8539 "xmm24", "xmm25", "xmm26", "xmm27",
8540 "xmm28", "xmm29", "xmm30", "xmm31",
8541 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 83 - 90 */
8542 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 91 - 98 */
8543 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 99 - 106 */
8544 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 107 - 114 */
8545 NULL
, NULL
, NULL
, /* 115 - 117 */
8546 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7"
8550 init_dwarf_regnames_x86_64 (void)
8552 dwarf_regnames
= dwarf_regnames_x86_64
;
8553 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_x86_64
);
8554 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8557 static const char *const dwarf_regnames_aarch64
[] =
8559 "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7",
8560 "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15",
8561 "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23",
8562 "x24", "x25", "x26", "x27", "x28", "x29", "x30", "sp",
8563 NULL
, "elr", NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
8564 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, "vg", "ffr",
8565 "p0", "p1", "p2", "p3", "p4", "p5", "p6", "p7",
8566 "p8", "p9", "p10", "p11", "p12", "p13", "p14", "p15",
8567 "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7",
8568 "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15",
8569 "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23",
8570 "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31",
8571 "z0", "z1", "z2", "z3", "z4", "z5", "z6", "z7",
8572 "z8", "z9", "z10", "z11", "z12", "z13", "z14", "z15",
8573 "z16", "z17", "z18", "z19", "z20", "z21", "z22", "z23",
8574 "z24", "z25", "z26", "z27", "z28", "z29", "z30", "z31",
8578 init_dwarf_regnames_aarch64 (void)
8580 dwarf_regnames
= dwarf_regnames_aarch64
;
8581 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_aarch64
);
8582 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8586 static const char *const dwarf_regnames_s390
[] =
8588 /* Avoid saying "r5 (r5)", so omit the names of r0-r15. */
8589 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
8590 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
8591 "f0", "f2", "f4", "f6", "f1", "f3", "f5", "f7",
8592 "f8", "f10", "f12", "f14", "f9", "f11", "f13", "f15",
8593 "cr0", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7",
8594 "cr8", "cr9", "cr10", "cr11", "cr12", "cr13", "cr14", "cr15",
8595 "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7",
8596 "a8", "a9", "a10", "a11", "a12", "a13", "a14", "a15",
8599 "v16", "v18", "v20", "v22", "v17", "v19", "v21", "v23",
8600 "v24", "v26", "v28", "v30", "v25", "v27", "v29", "v31",
8604 init_dwarf_regnames_s390 (void)
8606 dwarf_regnames
= dwarf_regnames_s390
;
8607 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_s390
);
8608 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8611 static const char *const dwarf_regnames_riscv
[] =
8613 "zero", "ra", "sp", "gp", "tp", "t0", "t1", "t2", /* 0 - 7 */
8614 "s0", "s1", "a0", "a1", "a2", "a3", "a4", "a5", /* 8 - 15 */
8615 "a6", "a7", "s2", "s3", "s4", "s5", "s6", "s7", /* 16 - 23 */
8616 "s8", "s9", "s10", "s11", "t3", "t4", "t5", "t6", /* 24 - 31 */
8617 "ft0", "ft1", "ft2", "ft3", "ft4", "ft5", "ft6", "ft7", /* 32 - 39 */
8618 "fs0", "fs1", /* 40 - 41 */
8619 "fa0", "fa1", "fa2", "fa3", "fa4", "fa5", "fa6", "fa7", /* 42 - 49 */
8620 "fs2", "fs3", "fs4", "fs5", "fs6", "fs7", "fs8", "fs9", /* 50 - 57 */
8621 "fs10", "fs11", /* 58 - 59 */
8622 "ft8", "ft9", "ft10", "ft11", /* 60 - 63 */
8623 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 64 - 71 */
8624 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 72 - 79 */
8625 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 80 - 87 */
8626 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 88 - 95 */
8627 "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", /* 96 - 103 */
8628 "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15", /* 104 - 111 */
8629 "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23", /* 112 - 119 */
8630 "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31", /* 120 - 127 */
8633 /* A RISC-V replacement for REGNAME_INTERNAL_BY_TABLE_ONLY which handles
8634 the large number of CSRs. */
8637 regname_internal_riscv (unsigned int regno
)
8639 const char *name
= NULL
;
8641 /* Lookup in the table first, this covers GPR and FPR. */
8642 if (regno
< ARRAY_SIZE (dwarf_regnames_riscv
))
8643 name
= dwarf_regnames_riscv
[regno
];
8644 else if (regno
>= 4096 && regno
<= 8191)
8646 /* This might be a CSR, these live in a sparse number space from 4096
8647 to 8191 These numbers are defined in the RISC-V ELF ABI
8651 #define DECLARE_CSR(NAME,VALUE,CLASS,DEFINE_VER,ABORT_VER) \
8652 case VALUE + 4096: name = #NAME; break;
8653 #include "opcode/riscv-opc.h"
8658 static char csr_name
[10];
8659 snprintf (csr_name
, sizeof (csr_name
), "csr%d", (regno
- 4096));
8670 init_dwarf_regnames_riscv (void)
8672 dwarf_regnames
= NULL
;
8673 dwarf_regnames_count
= 8192;
8674 dwarf_regnames_lookup_func
= regname_internal_riscv
;
8678 init_dwarf_regnames_by_elf_machine_code (unsigned int e_machine
)
8680 dwarf_regnames_lookup_func
= NULL
;
8686 init_dwarf_regnames_i386 ();
8690 init_dwarf_regnames_iamcu ();
8696 init_dwarf_regnames_x86_64 ();
8700 init_dwarf_regnames_aarch64 ();
8704 init_dwarf_regnames_s390 ();
8708 init_dwarf_regnames_riscv ();
8716 /* Initialize the DWARF register name lookup state based on the
8717 architecture and specific machine type of a BFD. */
8720 init_dwarf_regnames_by_bfd_arch_and_mach (enum bfd_architecture arch
,
8723 dwarf_regnames_lookup_func
= NULL
;
8731 case bfd_mach_x86_64
:
8732 case bfd_mach_x86_64_intel_syntax
:
8733 case bfd_mach_x64_32
:
8734 case bfd_mach_x64_32_intel_syntax
:
8735 init_dwarf_regnames_x86_64 ();
8739 init_dwarf_regnames_i386 ();
8744 case bfd_arch_iamcu
:
8745 init_dwarf_regnames_iamcu ();
8748 case bfd_arch_aarch64
:
8749 init_dwarf_regnames_aarch64();
8753 init_dwarf_regnames_s390 ();
8756 case bfd_arch_riscv
:
8757 init_dwarf_regnames_riscv ();
8766 regname_internal_by_table_only (unsigned int regno
)
8768 if (dwarf_regnames
!= NULL
8769 && regno
< dwarf_regnames_count
8770 && dwarf_regnames
[regno
] != NULL
)
8771 return dwarf_regnames
[regno
];
8777 regname (unsigned int regno
, int name_only_p
)
8779 static char reg
[64];
8781 const char *name
= NULL
;
8783 if (dwarf_regnames_lookup_func
!= NULL
)
8784 name
= dwarf_regnames_lookup_func (regno
);
8790 snprintf (reg
, sizeof (reg
), "r%d (%s)", regno
, name
);
8793 snprintf (reg
, sizeof (reg
), "r%d", regno
);
8798 frame_display_row (Frame_Chunk
*fc
, int *need_col_headers
, unsigned int *max_regs
)
8803 if (*max_regs
!= fc
->ncols
)
8804 *max_regs
= fc
->ncols
;
8806 if (*need_col_headers
)
8808 *need_col_headers
= 0;
8810 printf ("%-*s CFA ", eh_addr_size
* 2, " LOC");
8812 for (r
= 0; r
< *max_regs
; r
++)
8813 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
8818 printf ("%-5s ", regname (r
, 1));
8824 print_hex (fc
->pc_begin
, eh_addr_size
);
8826 strcpy (tmp
, "exp");
8828 sprintf (tmp
, "%s%+d", regname (fc
->cfa_reg
, 1), (int) fc
->cfa_offset
);
8829 printf ("%-8s ", tmp
);
8831 for (r
= 0; r
< fc
->ncols
; r
++)
8833 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
8835 switch (fc
->col_type
[r
])
8837 case DW_CFA_undefined
:
8840 case DW_CFA_same_value
:
8844 sprintf (tmp
, "c%+" PRId64
, fc
->col_offset
[r
]);
8846 case DW_CFA_val_offset
:
8847 sprintf (tmp
, "v%+" PRId64
, fc
->col_offset
[r
]);
8849 case DW_CFA_register
:
8850 sprintf (tmp
, "%s", regname (fc
->col_offset
[r
], 0));
8852 case DW_CFA_expression
:
8853 strcpy (tmp
, "exp");
8855 case DW_CFA_val_expression
:
8856 strcpy (tmp
, "vexp");
8859 strcpy (tmp
, "n/a");
8862 printf ("%-5s ", tmp
);
8868 #define GET(VAR, N) SAFE_BYTE_GET_AND_INC (VAR, start, N, end)
8870 static unsigned char *
8871 read_cie (unsigned char *start
, unsigned char *end
,
8872 Frame_Chunk
**p_cie
, int *p_version
,
8873 uint64_t *p_aug_len
, unsigned char **p_aug
)
8877 unsigned char *augmentation_data
= NULL
;
8878 uint64_t augmentation_data_len
= 0;
8881 /* PR 17512: file: 001-228113-0.004. */
8885 fc
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
8886 memset (fc
, 0, sizeof (Frame_Chunk
));
8888 fc
->col_type
= xmalloc (sizeof (*fc
->col_type
));
8889 fc
->col_offset
= xmalloc (sizeof (*fc
->col_offset
));
8893 fc
->augmentation
= (char *) start
;
8894 /* PR 17512: file: 001-228113-0.004.
8895 Skip past augmentation name, but avoid running off the end of the data. */
8897 if (* start
++ == '\0')
8901 warn (_("No terminator for augmentation name\n"));
8905 if (strcmp (fc
->augmentation
, "eh") == 0)
8907 if (eh_addr_size
> (size_t) (end
- start
))
8909 start
+= eh_addr_size
;
8914 if (2 > (size_t) (end
- start
))
8916 GET (fc
->ptr_size
, 1);
8917 if (fc
->ptr_size
< 1 || fc
->ptr_size
> 8)
8919 warn (_("Invalid pointer size (%d) in CIE data\n"), fc
->ptr_size
);
8923 GET (fc
->segment_size
, 1);
8924 /* PR 17512: file: e99d2804. */
8925 if (fc
->segment_size
> 8 || fc
->segment_size
+ fc
->ptr_size
> 8)
8927 warn (_("Invalid segment size (%d) in CIE data\n"), fc
->segment_size
);
8931 eh_addr_size
= fc
->ptr_size
;
8935 fc
->ptr_size
= eh_addr_size
;
8936 fc
->segment_size
= 0;
8939 READ_ULEB (fc
->code_factor
, start
, end
);
8940 READ_SLEB (fc
->data_factor
, start
, end
);
8951 READ_ULEB (fc
->ra
, start
, end
);
8954 if (fc
->augmentation
[0] == 'z')
8958 READ_ULEB (augmentation_data_len
, start
, end
);
8959 augmentation_data
= start
;
8960 /* PR 17512: file: 11042-2589-0.004. */
8961 if (augmentation_data_len
> (size_t) (end
- start
))
8963 warn (_("Augmentation data too long: %#" PRIx64
8964 ", expected at most %#tx\n"),
8965 augmentation_data_len
, end
- start
);
8968 start
+= augmentation_data_len
;
8971 if (augmentation_data_len
)
8975 unsigned char *qend
;
8977 p
= (unsigned char *) fc
->augmentation
+ 1;
8978 q
= augmentation_data
;
8979 qend
= q
+ augmentation_data_len
;
8981 while (p
< end
&& q
< qend
)
8986 q
+= 1 + size_of_encoded_value (*q
);
8988 fc
->fde_encoding
= *q
++;
8997 /* Note - it is OK if this loop terminates with q < qend.
8998 Padding may have been inserted to align the end of the CIE. */
9003 *p_version
= version
;
9006 *p_aug_len
= augmentation_data_len
;
9007 *p_aug
= augmentation_data
;
9012 free (fc
->col_offset
);
9013 free (fc
->col_type
);
9018 /* Prints out the contents on the DATA array formatted as unsigned bytes.
9019 If do_wide is not enabled, then formats the output to fit into 80 columns.
9020 PRINTED contains the number of characters already written to the current
9024 display_data (size_t printed
, const unsigned char *data
, size_t len
)
9026 if (do_wide
|| len
< ((80 - printed
) / 3))
9027 for (printed
= 0; printed
< len
; ++printed
)
9028 printf (" %02x", data
[printed
]);
9031 for (printed
= 0; printed
< len
; ++printed
)
9033 if (printed
% (80 / 3) == 0)
9035 printf (" %02x", data
[printed
]);
9040 /* Prints out the contents on the augmentation data array.
9041 If do_wide is not enabled, then formats the output to fit into 80 columns. */
9044 display_augmentation_data (const unsigned char * data
, uint64_t len
)
9048 i
= printf (_(" Augmentation data: "));
9049 display_data (i
, data
, len
);
9053 display_debug_frames (struct dwarf_section
*section
,
9054 void *file ATTRIBUTE_UNUSED
)
9056 unsigned char *start
= section
->start
;
9057 unsigned char *end
= start
+ section
->size
;
9058 unsigned char *section_start
= start
;
9059 Frame_Chunk
*chunks
= NULL
, *forward_refs
= NULL
;
9060 Frame_Chunk
*remembered_state
= NULL
;
9062 bool is_eh
= strcmp (section
->name
, ".eh_frame") == 0;
9063 unsigned int max_regs
= 0;
9064 const char *bad_reg
= _("bad register: ");
9065 unsigned int saved_eh_addr_size
= eh_addr_size
;
9067 introduce (section
, false);
9071 unsigned char *saved_start
;
9072 unsigned char *block_end
;
9077 int need_col_headers
= 1;
9078 unsigned char *augmentation_data
= NULL
;
9079 uint64_t augmentation_data_len
= 0;
9080 unsigned int encoded_ptr_size
= saved_eh_addr_size
;
9081 unsigned int offset_size
;
9083 static Frame_Chunk fde_fc
;
9085 saved_start
= start
;
9087 SAFE_BYTE_GET_AND_INC (length
, start
, 4, end
);
9091 printf ("\n%08tx ZERO terminator\n\n",
9092 saved_start
- section_start
);
9093 /* Skip any zero terminators that directly follow.
9094 A corrupt section size could have loaded a whole
9095 slew of zero filled memory bytes. eg
9096 PR 17512: file: 070-19381-0.004. */
9097 while (start
< end
&& * start
== 0)
9102 if (length
== 0xffffffff)
9104 SAFE_BYTE_GET_AND_INC (length
, start
, 8, end
);
9110 if (length
> (size_t) (end
- start
))
9112 warn ("Invalid length %#" PRIx64
" in FDE at %#tx\n",
9113 length
, saved_start
- section_start
);
9117 block_end
= start
+ length
;
9119 SAFE_BYTE_GET_AND_INC (cie_id
, start
, offset_size
, block_end
);
9121 if (is_eh
? (cie_id
== 0) : ((offset_size
== 4 && cie_id
== DW_CIE_ID
)
9122 || (offset_size
== 8 && cie_id
== DW64_CIE_ID
)))
9127 start
= read_cie (start
, block_end
, &cie
, &version
,
9128 &augmentation_data_len
, &augmentation_data
);
9129 /* PR 17512: file: 027-135133-0.005. */
9136 fc
->chunk_start
= saved_start
;
9137 mreg
= max_regs
> 0 ? max_regs
- 1 : 0;
9140 if (frame_need_space (fc
, mreg
) < 0)
9142 if (fc
->fde_encoding
)
9143 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
9145 printf ("\n%08tx ", saved_start
- section_start
);
9146 print_hex (length
, fc
->ptr_size
);
9147 print_hex (cie_id
, offset_size
);
9149 if (do_debug_frames_interp
)
9151 printf ("CIE \"%s\" cf=%d df=%d ra=%d\n", fc
->augmentation
,
9152 fc
->code_factor
, fc
->data_factor
, fc
->ra
);
9157 printf (" Version: %d\n", version
);
9158 printf (" Augmentation: \"%s\"\n", fc
->augmentation
);
9161 printf (" Pointer Size: %u\n", fc
->ptr_size
);
9162 printf (" Segment Size: %u\n", fc
->segment_size
);
9164 printf (" Code alignment factor: %u\n", fc
->code_factor
);
9165 printf (" Data alignment factor: %d\n", fc
->data_factor
);
9166 printf (" Return address column: %d\n", fc
->ra
);
9168 if (augmentation_data_len
)
9169 display_augmentation_data (augmentation_data
, augmentation_data_len
);
9176 unsigned char *look_for
;
9177 unsigned long segment_selector
;
9183 uint64_t sign
= (uint64_t) 1 << (offset_size
* 8 - 1);
9184 cie_off
= (cie_off
^ sign
) - sign
;
9185 cie_off
= start
- 4 - section_start
- cie_off
;
9188 look_for
= section_start
+ cie_off
;
9189 if (cie_off
<= (size_t) (saved_start
- section_start
))
9191 for (cie
= chunks
; cie
; cie
= cie
->next
)
9192 if (cie
->chunk_start
== look_for
)
9195 else if (cie_off
>= section
->size
)
9199 for (cie
= forward_refs
; cie
; cie
= cie
->next
)
9200 if (cie
->chunk_start
== look_for
)
9204 unsigned int off_size
;
9205 unsigned char *cie_scan
;
9207 cie_scan
= look_for
;
9209 SAFE_BYTE_GET_AND_INC (length
, cie_scan
, 4, end
);
9210 if (length
== 0xffffffff)
9212 SAFE_BYTE_GET_AND_INC (length
, cie_scan
, 8, end
);
9215 if (length
!= 0 && length
<= (size_t) (end
- cie_scan
))
9218 unsigned char *cie_end
= cie_scan
+ length
;
9220 SAFE_BYTE_GET_AND_INC (c_id
, cie_scan
, off_size
,
9224 : ((off_size
== 4 && c_id
== DW_CIE_ID
)
9225 || (off_size
== 8 && c_id
== DW64_CIE_ID
)))
9230 read_cie (cie_scan
, cie_end
, &cie
, &version
,
9231 &augmentation_data_len
, &augmentation_data
);
9232 /* PR 17512: file: 3450-2098-0.004. */
9235 warn (_("Failed to read CIE information\n"));
9238 cie
->next
= forward_refs
;
9240 cie
->chunk_start
= look_for
;
9241 mreg
= max_regs
> 0 ? max_regs
- 1 : 0;
9244 if (frame_need_space (cie
, mreg
) < 0)
9246 warn (_("Invalid max register\n"));
9249 if (cie
->fde_encoding
)
9251 = size_of_encoded_value (cie
->fde_encoding
);
9258 memset (fc
, 0, sizeof (Frame_Chunk
));
9263 fc
->col_type
= xmalloc (sizeof (*fc
->col_type
));
9264 fc
->col_offset
= xmalloc (sizeof (*fc
->col_offset
));
9265 if (frame_need_space (fc
, max_regs
> 0 ? max_regs
- 1 : 0) < 0)
9267 warn (_("Invalid max register\n"));
9271 fc
->augmentation
= "";
9272 fc
->fde_encoding
= 0;
9273 fc
->ptr_size
= eh_addr_size
;
9274 fc
->segment_size
= 0;
9278 fc
->ncols
= cie
->ncols
;
9279 fc
->col_type
= xcmalloc (fc
->ncols
, sizeof (*fc
->col_type
));
9280 fc
->col_offset
= xcmalloc (fc
->ncols
, sizeof (*fc
->col_offset
));
9281 memcpy (fc
->col_type
, cie
->col_type
,
9282 fc
->ncols
* sizeof (*fc
->col_type
));
9283 memcpy (fc
->col_offset
, cie
->col_offset
,
9284 fc
->ncols
* sizeof (*fc
->col_offset
));
9285 fc
->augmentation
= cie
->augmentation
;
9286 fc
->ptr_size
= cie
->ptr_size
;
9287 eh_addr_size
= cie
->ptr_size
;
9288 fc
->segment_size
= cie
->segment_size
;
9289 fc
->code_factor
= cie
->code_factor
;
9290 fc
->data_factor
= cie
->data_factor
;
9291 fc
->cfa_reg
= cie
->cfa_reg
;
9292 fc
->cfa_offset
= cie
->cfa_offset
;
9294 if (frame_need_space (fc
, max_regs
> 0 ? max_regs
- 1: 0) < 0)
9296 warn (_("Invalid max register\n"));
9299 fc
->fde_encoding
= cie
->fde_encoding
;
9302 if (fc
->fde_encoding
)
9303 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
9305 segment_selector
= 0;
9306 if (fc
->segment_size
)
9308 if (fc
->segment_size
> sizeof (segment_selector
))
9310 /* PR 17512: file: 9e196b3e. */
9311 warn (_("Probably corrupt segment size: %d - using 4 instead\n"), fc
->segment_size
);
9312 fc
->segment_size
= 4;
9314 SAFE_BYTE_GET_AND_INC (segment_selector
, start
,
9315 fc
->segment_size
, block_end
);
9318 fc
->pc_begin
= get_encoded_value (&start
, fc
->fde_encoding
, section
,
9321 /* FIXME: It appears that sometimes the final pc_range value is
9322 encoded in less than encoded_ptr_size bytes. See the x86_64
9323 run of the "objcopy on compressed debug sections" test for an
9325 SAFE_BYTE_GET_AND_INC (fc
->pc_range
, start
, encoded_ptr_size
,
9328 if (cie
->augmentation
[0] == 'z')
9330 READ_ULEB (augmentation_data_len
, start
, block_end
);
9331 augmentation_data
= start
;
9332 /* PR 17512 file: 722-8446-0.004 and PR 22386. */
9333 if (augmentation_data_len
> (size_t) (block_end
- start
))
9335 warn (_("Augmentation data too long: %#" PRIx64
", "
9336 "expected at most %#tx\n"),
9337 augmentation_data_len
, block_end
- start
);
9339 augmentation_data
= NULL
;
9340 augmentation_data_len
= 0;
9342 start
+= augmentation_data_len
;
9345 printf ("\n%08tx ", saved_start
- section_start
);
9346 print_hex (length
, fc
->ptr_size
);
9347 print_hex (cie_id
, offset_size
);
9350 if (cie
->chunk_start
)
9351 printf ("cie=%08tx", cie
->chunk_start
- section_start
);
9353 /* Ideally translate "invalid " to 8 chars, trailing space
9355 printf (_("cie=invalid "));
9358 if (fc
->segment_size
)
9359 printf ("%04lx:", segment_selector
);
9361 print_hex_ns (fc
->pc_begin
, fc
->ptr_size
);
9363 print_hex_ns (fc
->pc_begin
+ fc
->pc_range
, fc
->ptr_size
);
9366 if (! do_debug_frames_interp
&& augmentation_data_len
)
9368 display_augmentation_data (augmentation_data
, augmentation_data_len
);
9373 /* At this point, fc is the current chunk, cie (if any) is set, and
9374 we're about to interpret instructions for the chunk. */
9375 /* ??? At present we need to do this always, since this sizes the
9376 fc->col_type and fc->col_offset arrays, which we write into always.
9377 We should probably split the interpreted and non-interpreted bits
9378 into two different routines, since there's so much that doesn't
9379 really overlap between them. */
9380 if (1 || do_debug_frames_interp
)
9382 /* Start by making a pass over the chunk, allocating storage
9383 and taking note of what registers are used. */
9384 unsigned char *tmp
= start
;
9386 while (start
< block_end
)
9388 unsigned int reg
, op
, opa
;
9396 /* Warning: if you add any more cases to this switch, be
9397 sure to add them to the corresponding switch below. */
9401 case DW_CFA_advance_loc
:
9404 SKIP_ULEB (start
, block_end
);
9407 case DW_CFA_restore
:
9410 case DW_CFA_set_loc
:
9411 if ((size_t) (block_end
- start
) < encoded_ptr_size
)
9414 start
+= encoded_ptr_size
;
9416 case DW_CFA_advance_loc1
:
9417 if ((size_t) (block_end
- start
) < 1)
9422 case DW_CFA_advance_loc2
:
9423 if ((size_t) (block_end
- start
) < 2)
9428 case DW_CFA_advance_loc4
:
9429 if ((size_t) (block_end
- start
) < 4)
9434 case DW_CFA_offset_extended
:
9435 case DW_CFA_val_offset
:
9436 READ_ULEB (reg
, start
, block_end
);
9437 SKIP_ULEB (start
, block_end
);
9439 case DW_CFA_restore_extended
:
9440 READ_ULEB (reg
, start
, block_end
);
9442 case DW_CFA_undefined
:
9443 READ_ULEB (reg
, start
, block_end
);
9445 case DW_CFA_same_value
:
9446 READ_ULEB (reg
, start
, block_end
);
9448 case DW_CFA_register
:
9449 READ_ULEB (reg
, start
, block_end
);
9450 SKIP_ULEB (start
, block_end
);
9452 case DW_CFA_def_cfa
:
9453 SKIP_ULEB (start
, block_end
);
9454 SKIP_ULEB (start
, block_end
);
9456 case DW_CFA_def_cfa_register
:
9457 SKIP_ULEB (start
, block_end
);
9459 case DW_CFA_def_cfa_offset
:
9460 SKIP_ULEB (start
, block_end
);
9462 case DW_CFA_def_cfa_expression
:
9463 READ_ULEB (temp
, start
, block_end
);
9464 if ((size_t) (block_end
- start
) < temp
)
9469 case DW_CFA_expression
:
9470 case DW_CFA_val_expression
:
9471 READ_ULEB (reg
, start
, block_end
);
9472 READ_ULEB (temp
, start
, block_end
);
9473 if ((size_t) (block_end
- start
) < temp
)
9478 case DW_CFA_offset_extended_sf
:
9479 case DW_CFA_val_offset_sf
:
9480 READ_ULEB (reg
, start
, block_end
);
9481 SKIP_SLEB (start
, block_end
);
9483 case DW_CFA_def_cfa_sf
:
9484 SKIP_ULEB (start
, block_end
);
9485 SKIP_SLEB (start
, block_end
);
9487 case DW_CFA_def_cfa_offset_sf
:
9488 SKIP_SLEB (start
, block_end
);
9490 case DW_CFA_MIPS_advance_loc8
:
9491 if ((size_t) (block_end
- start
) < 8)
9496 case DW_CFA_GNU_args_size
:
9497 SKIP_ULEB (start
, block_end
);
9499 case DW_CFA_GNU_negative_offset_extended
:
9500 READ_ULEB (reg
, start
, block_end
);
9501 SKIP_ULEB (start
, block_end
);
9506 if (reg
!= -1u && frame_need_space (fc
, reg
) >= 0)
9508 /* Don't leave any reg as DW_CFA_unreferenced so
9509 that frame_display_row prints name of regs in
9510 header, and all referenced regs in each line. */
9511 if (reg
>= cie
->ncols
9512 || cie
->col_type
[reg
] == DW_CFA_unreferenced
)
9513 fc
->col_type
[reg
] = DW_CFA_undefined
;
9515 fc
->col_type
[reg
] = cie
->col_type
[reg
];
9523 /* Now we know what registers are used, make a second pass over
9524 the chunk, this time actually printing out the info. */
9526 while (start
< block_end
)
9529 /* Note: It is tempting to use an unsigned long for 'reg' but there
9530 are various functions, notably frame_space_needed() that assume that
9531 reg is an unsigned int. */
9535 const char *reg_prefix
= "";
9542 /* Make a note if something other than DW_CFA_nop happens. */
9543 if (op
!= DW_CFA_nop
)
9546 /* Warning: if you add any more cases to this switch, be
9547 sure to add them to the corresponding switch above. */
9550 case DW_CFA_advance_loc
:
9551 opa
*= fc
->code_factor
;
9552 if (do_debug_frames_interp
)
9553 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9556 printf (" DW_CFA_advance_loc: %d to ", opa
);
9557 print_hex_ns (fc
->pc_begin
+ opa
, fc
->ptr_size
);
9560 fc
->pc_begin
+= opa
;
9564 READ_ULEB (ofs
, start
, block_end
);
9565 ofs
*= fc
->data_factor
;
9566 if (opa
>= fc
->ncols
)
9567 reg_prefix
= bad_reg
;
9568 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9569 printf (" DW_CFA_offset: %s%s at cfa%+" PRId64
"\n",
9570 reg_prefix
, regname (opa
, 0), ofs
);
9571 if (*reg_prefix
== '\0')
9573 fc
->col_type
[opa
] = DW_CFA_offset
;
9574 fc
->col_offset
[opa
] = ofs
;
9578 case DW_CFA_restore
:
9579 if (opa
>= fc
->ncols
)
9580 reg_prefix
= bad_reg
;
9581 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9582 printf (" DW_CFA_restore: %s%s\n",
9583 reg_prefix
, regname (opa
, 0));
9584 if (*reg_prefix
!= '\0')
9587 if (opa
>= cie
->ncols
9588 || cie
->col_type
[opa
] == DW_CFA_unreferenced
)
9590 fc
->col_type
[opa
] = DW_CFA_undefined
;
9591 fc
->col_offset
[opa
] = 0;
9595 fc
->col_type
[opa
] = cie
->col_type
[opa
];
9596 fc
->col_offset
[opa
] = cie
->col_offset
[opa
];
9600 case DW_CFA_set_loc
:
9601 ofs
= get_encoded_value (&start
, fc
->fde_encoding
, section
,
9603 if (do_debug_frames_interp
)
9604 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9607 printf (" DW_CFA_set_loc: ");
9608 print_hex_ns (ofs
, fc
->ptr_size
);
9614 case DW_CFA_advance_loc1
:
9615 SAFE_BYTE_GET_AND_INC (ofs
, start
, 1, block_end
);
9616 ofs
*= fc
->code_factor
;
9617 if (do_debug_frames_interp
)
9618 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9621 printf (" DW_CFA_advance_loc1: %" PRId64
" to ", ofs
);
9622 print_hex_ns (fc
->pc_begin
+ ofs
, fc
->ptr_size
);
9625 fc
->pc_begin
+= ofs
;
9628 case DW_CFA_advance_loc2
:
9629 SAFE_BYTE_GET_AND_INC (ofs
, start
, 2, block_end
);
9630 ofs
*= fc
->code_factor
;
9631 if (do_debug_frames_interp
)
9632 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9635 printf (" DW_CFA_advance_loc2: %" PRId64
" to ", ofs
);
9636 print_hex_ns (fc
->pc_begin
+ ofs
, fc
->ptr_size
);
9639 fc
->pc_begin
+= ofs
;
9642 case DW_CFA_advance_loc4
:
9643 SAFE_BYTE_GET_AND_INC (ofs
, start
, 4, block_end
);
9644 ofs
*= fc
->code_factor
;
9645 if (do_debug_frames_interp
)
9646 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9649 printf (" DW_CFA_advance_loc4: %" PRId64
" to ", ofs
);
9650 print_hex_ns (fc
->pc_begin
+ ofs
, fc
->ptr_size
);
9653 fc
->pc_begin
+= ofs
;
9656 case DW_CFA_offset_extended
:
9657 READ_ULEB (reg
, start
, block_end
);
9658 READ_ULEB (ofs
, start
, block_end
);
9659 ofs
*= fc
->data_factor
;
9660 if (reg
>= fc
->ncols
)
9661 reg_prefix
= bad_reg
;
9662 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9663 printf (" DW_CFA_offset_extended: %s%s at cfa%+" PRId64
"\n",
9664 reg_prefix
, regname (reg
, 0), ofs
);
9665 if (*reg_prefix
== '\0')
9667 fc
->col_type
[reg
] = DW_CFA_offset
;
9668 fc
->col_offset
[reg
] = ofs
;
9672 case DW_CFA_val_offset
:
9673 READ_ULEB (reg
, start
, block_end
);
9674 READ_ULEB (ofs
, start
, block_end
);
9675 ofs
*= fc
->data_factor
;
9676 if (reg
>= fc
->ncols
)
9677 reg_prefix
= bad_reg
;
9678 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9679 printf (" DW_CFA_val_offset: %s%s is cfa%+" PRId64
"\n",
9680 reg_prefix
, regname (reg
, 0), ofs
);
9681 if (*reg_prefix
== '\0')
9683 fc
->col_type
[reg
] = DW_CFA_val_offset
;
9684 fc
->col_offset
[reg
] = ofs
;
9688 case DW_CFA_restore_extended
:
9689 READ_ULEB (reg
, start
, block_end
);
9690 if (reg
>= fc
->ncols
)
9691 reg_prefix
= bad_reg
;
9692 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9693 printf (" DW_CFA_restore_extended: %s%s\n",
9694 reg_prefix
, regname (reg
, 0));
9695 if (*reg_prefix
!= '\0')
9698 if (reg
>= cie
->ncols
9699 || cie
->col_type
[reg
] == DW_CFA_unreferenced
)
9701 fc
->col_type
[reg
] = DW_CFA_undefined
;
9702 fc
->col_offset
[reg
] = 0;
9706 fc
->col_type
[reg
] = cie
->col_type
[reg
];
9707 fc
->col_offset
[reg
] = cie
->col_offset
[reg
];
9711 case DW_CFA_undefined
:
9712 READ_ULEB (reg
, start
, block_end
);
9713 if (reg
>= fc
->ncols
)
9714 reg_prefix
= bad_reg
;
9715 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9716 printf (" DW_CFA_undefined: %s%s\n",
9717 reg_prefix
, regname (reg
, 0));
9718 if (*reg_prefix
== '\0')
9720 fc
->col_type
[reg
] = DW_CFA_undefined
;
9721 fc
->col_offset
[reg
] = 0;
9725 case DW_CFA_same_value
:
9726 READ_ULEB (reg
, start
, block_end
);
9727 if (reg
>= fc
->ncols
)
9728 reg_prefix
= bad_reg
;
9729 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9730 printf (" DW_CFA_same_value: %s%s\n",
9731 reg_prefix
, regname (reg
, 0));
9732 if (*reg_prefix
== '\0')
9734 fc
->col_type
[reg
] = DW_CFA_same_value
;
9735 fc
->col_offset
[reg
] = 0;
9739 case DW_CFA_register
:
9740 READ_ULEB (reg
, start
, block_end
);
9741 READ_ULEB (ofs
, start
, block_end
);
9742 if (reg
>= fc
->ncols
)
9743 reg_prefix
= bad_reg
;
9744 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9746 printf (" DW_CFA_register: %s%s in ",
9747 reg_prefix
, regname (reg
, 0));
9748 puts (regname (ofs
, 0));
9750 if (*reg_prefix
== '\0')
9752 fc
->col_type
[reg
] = DW_CFA_register
;
9753 fc
->col_offset
[reg
] = ofs
;
9757 case DW_CFA_remember_state
:
9758 if (! do_debug_frames_interp
)
9759 printf (" DW_CFA_remember_state\n");
9760 rs
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
9761 rs
->cfa_offset
= fc
->cfa_offset
;
9762 rs
->cfa_reg
= fc
->cfa_reg
;
9764 rs
->cfa_exp
= fc
->cfa_exp
;
9765 rs
->ncols
= fc
->ncols
;
9766 rs
->col_type
= xcmalloc (rs
->ncols
, sizeof (*rs
->col_type
));
9767 rs
->col_offset
= xcmalloc (rs
->ncols
, sizeof (*rs
->col_offset
));
9768 memcpy (rs
->col_type
, fc
->col_type
,
9769 rs
->ncols
* sizeof (*fc
->col_type
));
9770 memcpy (rs
->col_offset
, fc
->col_offset
,
9771 rs
->ncols
* sizeof (*fc
->col_offset
));
9772 rs
->next
= remembered_state
;
9773 remembered_state
= rs
;
9776 case DW_CFA_restore_state
:
9777 if (! do_debug_frames_interp
)
9778 printf (" DW_CFA_restore_state\n");
9779 rs
= remembered_state
;
9782 remembered_state
= rs
->next
;
9783 fc
->cfa_offset
= rs
->cfa_offset
;
9784 fc
->cfa_reg
= rs
->cfa_reg
;
9786 fc
->cfa_exp
= rs
->cfa_exp
;
9787 if (frame_need_space (fc
, rs
->ncols
- 1) < 0)
9789 warn (_("Invalid column number in saved frame state\n"));
9793 memcpy (fc
->col_type
, rs
->col_type
,
9794 rs
->ncols
* sizeof (*rs
->col_type
));
9795 memcpy (fc
->col_offset
, rs
->col_offset
,
9796 rs
->ncols
* sizeof (*rs
->col_offset
));
9797 free (rs
->col_type
);
9798 free (rs
->col_offset
);
9801 else if (do_debug_frames_interp
)
9802 printf ("Mismatched DW_CFA_restore_state\n");
9805 case DW_CFA_def_cfa
:
9806 READ_ULEB (fc
->cfa_reg
, start
, block_end
);
9807 READ_ULEB (fc
->cfa_offset
, start
, block_end
);
9809 if (! do_debug_frames_interp
)
9810 printf (" DW_CFA_def_cfa: %s ofs %d\n",
9811 regname (fc
->cfa_reg
, 0), (int) fc
->cfa_offset
);
9814 case DW_CFA_def_cfa_register
:
9815 READ_ULEB (fc
->cfa_reg
, start
, block_end
);
9817 if (! do_debug_frames_interp
)
9818 printf (" DW_CFA_def_cfa_register: %s\n",
9819 regname (fc
->cfa_reg
, 0));
9822 case DW_CFA_def_cfa_offset
:
9823 READ_ULEB (fc
->cfa_offset
, start
, block_end
);
9824 if (! do_debug_frames_interp
)
9825 printf (" DW_CFA_def_cfa_offset: %d\n", (int) fc
->cfa_offset
);
9829 if (! do_debug_frames_interp
)
9830 printf (" DW_CFA_nop\n");
9833 case DW_CFA_def_cfa_expression
:
9834 READ_ULEB (ofs
, start
, block_end
);
9835 if (ofs
> (size_t) (block_end
- start
))
9837 printf (_(" %s: <corrupt len %" PRIu64
">\n"),
9838 "DW_CFA_def_cfa_expression", ofs
);
9841 if (! do_debug_frames_interp
)
9843 printf (" DW_CFA_def_cfa_expression (");
9844 decode_location_expression (start
, eh_addr_size
, 0, -1,
9852 case DW_CFA_expression
:
9853 READ_ULEB (reg
, start
, block_end
);
9854 READ_ULEB (ofs
, start
, block_end
);
9855 if (reg
>= fc
->ncols
)
9856 reg_prefix
= bad_reg
;
9857 /* PR 17512: file: 069-133014-0.006. */
9858 /* PR 17512: file: 98c02eb4. */
9859 if (ofs
> (size_t) (block_end
- start
))
9861 printf (_(" %s: <corrupt len %" PRIu64
">\n"),
9862 "DW_CFA_expression", ofs
);
9865 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9867 printf (" DW_CFA_expression: %s%s (",
9868 reg_prefix
, regname (reg
, 0));
9869 decode_location_expression (start
, eh_addr_size
, 0, -1,
9873 if (*reg_prefix
== '\0')
9874 fc
->col_type
[reg
] = DW_CFA_expression
;
9878 case DW_CFA_val_expression
:
9879 READ_ULEB (reg
, start
, block_end
);
9880 READ_ULEB (ofs
, start
, block_end
);
9881 if (reg
>= fc
->ncols
)
9882 reg_prefix
= bad_reg
;
9883 if (ofs
> (size_t) (block_end
- start
))
9885 printf (" %s: <corrupt len %" PRIu64
">\n",
9886 "DW_CFA_val_expression", ofs
);
9889 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9891 printf (" DW_CFA_val_expression: %s%s (",
9892 reg_prefix
, regname (reg
, 0));
9893 decode_location_expression (start
, eh_addr_size
, 0, -1,
9897 if (*reg_prefix
== '\0')
9898 fc
->col_type
[reg
] = DW_CFA_val_expression
;
9902 case DW_CFA_offset_extended_sf
:
9903 READ_ULEB (reg
, start
, block_end
);
9904 READ_SLEB (sofs
, start
, block_end
);
9905 /* data_factor multiplicaton done here as unsigned to
9906 avoid integer overflow warnings from asan on fuzzed
9909 ofs
*= fc
->data_factor
;
9910 if (reg
>= fc
->ncols
)
9911 reg_prefix
= bad_reg
;
9912 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9913 printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+" PRId64
"\n",
9914 reg_prefix
, regname (reg
, 0), ofs
);
9915 if (*reg_prefix
== '\0')
9917 fc
->col_type
[reg
] = DW_CFA_offset
;
9918 fc
->col_offset
[reg
] = ofs
;
9922 case DW_CFA_val_offset_sf
:
9923 READ_ULEB (reg
, start
, block_end
);
9924 READ_SLEB (sofs
, start
, block_end
);
9926 ofs
*= fc
->data_factor
;
9927 if (reg
>= fc
->ncols
)
9928 reg_prefix
= bad_reg
;
9929 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9930 printf (" DW_CFA_val_offset_sf: %s%s is cfa%+" PRId64
"\n",
9931 reg_prefix
, regname (reg
, 0), ofs
);
9932 if (*reg_prefix
== '\0')
9934 fc
->col_type
[reg
] = DW_CFA_val_offset
;
9935 fc
->col_offset
[reg
] = ofs
;
9939 case DW_CFA_def_cfa_sf
:
9940 READ_ULEB (fc
->cfa_reg
, start
, block_end
);
9941 READ_SLEB (sofs
, start
, block_end
);
9943 ofs
*= fc
->data_factor
;
9944 fc
->cfa_offset
= ofs
;
9946 if (! do_debug_frames_interp
)
9947 printf (" DW_CFA_def_cfa_sf: %s ofs %" PRId64
"\n",
9948 regname (fc
->cfa_reg
, 0), ofs
);
9951 case DW_CFA_def_cfa_offset_sf
:
9952 READ_SLEB (sofs
, start
, block_end
);
9954 ofs
*= fc
->data_factor
;
9955 fc
->cfa_offset
= ofs
;
9956 if (! do_debug_frames_interp
)
9957 printf (" DW_CFA_def_cfa_offset_sf: %" PRId64
"\n", ofs
);
9960 case DW_CFA_MIPS_advance_loc8
:
9961 SAFE_BYTE_GET_AND_INC (ofs
, start
, 8, block_end
);
9962 ofs
*= fc
->code_factor
;
9963 if (do_debug_frames_interp
)
9964 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9967 printf (" DW_CFA_MIPS_advance_loc8: %" PRId64
" to ", ofs
);
9968 print_hex_ns (fc
->pc_begin
+ ofs
, fc
->ptr_size
);
9971 fc
->pc_begin
+= ofs
;
9974 case DW_CFA_GNU_window_save
:
9975 if (! do_debug_frames_interp
)
9976 printf (" %s\n", DW_CFA_GNU_window_save_name
[is_aarch64
]);
9979 case DW_CFA_GNU_args_size
:
9980 READ_ULEB (ofs
, start
, block_end
);
9981 if (! do_debug_frames_interp
)
9982 printf (" DW_CFA_GNU_args_size: %" PRIu64
"\n", ofs
);
9985 case DW_CFA_GNU_negative_offset_extended
:
9986 READ_ULEB (reg
, start
, block_end
);
9987 READ_SLEB (sofs
, start
, block_end
);
9989 ofs
= -ofs
* fc
->data_factor
;
9990 if (reg
>= fc
->ncols
)
9991 reg_prefix
= bad_reg
;
9992 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9993 printf (" DW_CFA_GNU_negative_offset_extended: %s%s "
9994 "at cfa%+" PRId64
"\n",
9995 reg_prefix
, regname (reg
, 0), ofs
);
9996 if (*reg_prefix
== '\0')
9998 fc
->col_type
[reg
] = DW_CFA_offset
;
9999 fc
->col_offset
[reg
] = ofs
;
10004 if (op
>= DW_CFA_lo_user
&& op
<= DW_CFA_hi_user
)
10005 printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op
);
10007 warn (_("Unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op
);
10012 /* Interpret the CFA - as long as it is not completely full of NOPs. */
10013 if (do_debug_frames_interp
&& ! all_nops
)
10014 frame_display_row (fc
, &need_col_headers
, &max_regs
);
10016 if (fde_fc
.col_type
!= NULL
)
10018 free (fde_fc
.col_type
);
10019 fde_fc
.col_type
= NULL
;
10021 if (fde_fc
.col_offset
!= NULL
)
10023 free (fde_fc
.col_offset
);
10024 fde_fc
.col_offset
= NULL
;
10028 eh_addr_size
= saved_eh_addr_size
;
10033 while (remembered_state
!= NULL
)
10035 rs
= remembered_state
;
10036 remembered_state
= rs
->next
;
10037 free (rs
->col_type
);
10038 free (rs
->col_offset
);
10039 rs
->next
= NULL
; /* Paranoia. */
10043 while (chunks
!= NULL
)
10047 free (rs
->col_type
);
10048 free (rs
->col_offset
);
10049 rs
->next
= NULL
; /* Paranoia. */
10053 while (forward_refs
!= NULL
)
10056 forward_refs
= rs
->next
;
10057 free (rs
->col_type
);
10058 free (rs
->col_offset
);
10059 rs
->next
= NULL
; /* Paranoia. */
10069 display_debug_names (struct dwarf_section
*section
, void *file
)
10071 unsigned char *hdrptr
= section
->start
;
10072 uint64_t unit_length
;
10073 unsigned char *unit_start
;
10074 const unsigned char *const section_end
= section
->start
+ section
->size
;
10075 unsigned char *unit_end
;
10077 introduce (section
, false);
10079 load_debug_section_with_follow (str
, file
);
10081 for (; hdrptr
< section_end
; hdrptr
= unit_end
)
10083 unsigned int offset_size
;
10084 uint16_t dwarf_version
, padding
;
10085 uint32_t comp_unit_count
, local_type_unit_count
, foreign_type_unit_count
;
10086 uint64_t bucket_count
, name_count
, abbrev_table_size
;
10087 uint32_t augmentation_string_size
;
10089 bool augmentation_printable
;
10090 const char *augmentation_string
;
10093 unit_start
= hdrptr
;
10095 /* Get and check the length of the block. */
10096 SAFE_BYTE_GET_AND_INC (unit_length
, hdrptr
, 4, section_end
);
10098 if (unit_length
== 0xffffffff)
10100 /* This section is 64-bit DWARF. */
10101 SAFE_BYTE_GET_AND_INC (unit_length
, hdrptr
, 8, section_end
);
10107 if (unit_length
> (size_t) (section_end
- hdrptr
)
10108 || unit_length
< 2 + 2 + 4 * 7)
10111 warn (_("Debug info is corrupted, %s header at %#tx"
10112 " has length %#" PRIx64
"\n"),
10113 section
->name
, unit_start
- section
->start
, unit_length
);
10116 unit_end
= hdrptr
+ unit_length
;
10118 /* Get and check the version number. */
10119 SAFE_BYTE_GET_AND_INC (dwarf_version
, hdrptr
, 2, unit_end
);
10120 printf (_("Version %d\n"), (int) dwarf_version
);
10122 /* Prior versions did not exist, and future versions may not be
10123 backwards compatible. */
10124 if (dwarf_version
!= 5)
10126 warn (_("Only DWARF version 5 .debug_names "
10127 "is currently supported.\n"));
10131 SAFE_BYTE_GET_AND_INC (padding
, hdrptr
, 2, unit_end
);
10133 warn (_("Padding field of .debug_names must be 0 (found 0x%x)\n"),
10136 SAFE_BYTE_GET_AND_INC (comp_unit_count
, hdrptr
, 4, unit_end
);
10137 if (comp_unit_count
== 0)
10138 warn (_("Compilation unit count must be >= 1 in .debug_names\n"));
10140 SAFE_BYTE_GET_AND_INC (local_type_unit_count
, hdrptr
, 4, unit_end
);
10141 SAFE_BYTE_GET_AND_INC (foreign_type_unit_count
, hdrptr
, 4, unit_end
);
10142 SAFE_BYTE_GET_AND_INC (bucket_count
, hdrptr
, 4, unit_end
);
10143 SAFE_BYTE_GET_AND_INC (name_count
, hdrptr
, 4, unit_end
);
10144 SAFE_BYTE_GET_AND_INC (abbrev_table_size
, hdrptr
, 4, unit_end
);
10146 SAFE_BYTE_GET_AND_INC (augmentation_string_size
, hdrptr
, 4, unit_end
);
10147 if (augmentation_string_size
% 4 != 0)
10149 warn (_("Augmentation string length %u must be rounded up "
10150 "to a multiple of 4 in .debug_names.\n"),
10151 augmentation_string_size
);
10152 augmentation_string_size
+= (-augmentation_string_size
) & 3;
10154 if (augmentation_string_size
> (size_t) (unit_end
- hdrptr
))
10157 printf (_("Augmentation string:"));
10159 augmentation_printable
= true;
10160 augmentation_string
= (const char *) hdrptr
;
10162 for (i
= 0; i
< augmentation_string_size
; i
++)
10166 SAFE_BYTE_GET_AND_INC (uc
, hdrptr
, 1, unit_end
);
10167 printf (" %02x", uc
);
10169 if (uc
!= 0 && !ISPRINT (uc
))
10170 augmentation_printable
= false;
10173 if (augmentation_printable
)
10177 i
< augmentation_string_size
&& augmentation_string
[i
];
10179 putchar (augmentation_string
[i
]);
10184 printf (_("CU table:\n"));
10185 if (_mul_overflow (comp_unit_count
, offset_size
, &total
)
10186 || total
> (size_t) (unit_end
- hdrptr
))
10188 for (i
= 0; i
< comp_unit_count
; i
++)
10190 uint64_t cu_offset
;
10192 SAFE_BYTE_GET_AND_INC (cu_offset
, hdrptr
, offset_size
, unit_end
);
10193 printf ("[%3u] %#" PRIx64
"\n", i
, cu_offset
);
10197 printf (_("TU table:\n"));
10198 if (_mul_overflow (local_type_unit_count
, offset_size
, &total
)
10199 || total
> (size_t) (unit_end
- hdrptr
))
10201 for (i
= 0; i
< local_type_unit_count
; i
++)
10203 uint64_t tu_offset
;
10205 SAFE_BYTE_GET_AND_INC (tu_offset
, hdrptr
, offset_size
, unit_end
);
10206 printf ("[%3u] %#" PRIx64
"\n", i
, tu_offset
);
10210 printf (_("Foreign TU table:\n"));
10211 if (_mul_overflow (foreign_type_unit_count
, 8, &total
)
10212 || total
> (size_t) (unit_end
- hdrptr
))
10214 for (i
= 0; i
< foreign_type_unit_count
; i
++)
10216 uint64_t signature
;
10218 SAFE_BYTE_GET_AND_INC (signature
, hdrptr
, 8, unit_end
);
10219 printf (_("[%3u] "), i
);
10220 print_hex_ns (signature
, 8);
10225 uint64_t xtra
= (bucket_count
* sizeof (uint32_t)
10226 + name_count
* (sizeof (uint32_t) + 2 * offset_size
)
10227 + abbrev_table_size
);
10228 if (xtra
> (size_t) (unit_end
- hdrptr
))
10230 warn (_("Entry pool offset (%#" PRIx64
") exceeds unit size %#tx "
10231 "for unit %#tx in the debug_names\n"),
10232 xtra
, unit_end
- unit_start
, unit_start
- section
->start
);
10235 const uint32_t *const hash_table_buckets
= (uint32_t *) hdrptr
;
10236 hdrptr
+= bucket_count
* sizeof (uint32_t);
10237 const uint32_t *const hash_table_hashes
= (uint32_t *) hdrptr
;
10238 hdrptr
+= name_count
* sizeof (uint32_t);
10239 unsigned char *const name_table_string_offsets
= hdrptr
;
10240 hdrptr
+= name_count
* offset_size
;
10241 unsigned char *const name_table_entry_offsets
= hdrptr
;
10242 hdrptr
+= name_count
* offset_size
;
10243 unsigned char *const abbrev_table
= hdrptr
;
10244 hdrptr
+= abbrev_table_size
;
10245 const unsigned char *const abbrev_table_end
= hdrptr
;
10246 unsigned char *const entry_pool
= hdrptr
;
10248 size_t buckets_filled
= 0;
10250 for (bucketi
= 0; bucketi
< bucket_count
; bucketi
++)
10252 const uint32_t bucket
= hash_table_buckets
[bucketi
];
10257 printf (ngettext ("Used %zu of %lu bucket.\n",
10258 "Used %zu of %lu buckets.\n",
10259 (unsigned long) bucket_count
),
10260 buckets_filled
, (unsigned long) bucket_count
);
10262 if (bucket_count
!= 0)
10264 uint32_t hash_prev
= 0;
10265 size_t hash_clash_count
= 0;
10266 size_t longest_clash
= 0;
10267 size_t this_length
= 0;
10269 for (hashi
= 0; hashi
< name_count
; hashi
++)
10271 const uint32_t hash_this
= hash_table_hashes
[hashi
];
10275 if (hash_prev
% bucket_count
== hash_this
% bucket_count
)
10277 ++hash_clash_count
;
10279 longest_clash
= MAX (longest_clash
, this_length
);
10284 hash_prev
= hash_this
;
10286 printf (_("Out of %" PRIu64
" items there are %zu bucket clashes"
10287 " (longest of %zu entries).\n"),
10288 name_count
, hash_clash_count
, longest_clash
);
10290 if (name_count
!= buckets_filled
+ hash_clash_count
)
10291 warn (_("The name_count (%" PRIu64
")"
10292 " is not the same as the used bucket_count"
10293 " (%zu) + the hash clash count (%zu)"),
10294 name_count
, buckets_filled
, hash_clash_count
);
10297 struct abbrev_lookup_entry
10299 uint64_t abbrev_tag
;
10300 unsigned char *abbrev_lookup_ptr
;
10302 struct abbrev_lookup_entry
*abbrev_lookup
= NULL
;
10303 size_t abbrev_lookup_used
= 0;
10304 size_t abbrev_lookup_allocated
= 0;
10306 unsigned char *abbrevptr
= abbrev_table
;
10309 uint64_t abbrev_tag
;
10311 READ_ULEB (abbrev_tag
, abbrevptr
, abbrev_table_end
);
10312 if (abbrev_tag
== 0)
10314 if (abbrev_lookup_used
== abbrev_lookup_allocated
)
10316 abbrev_lookup_allocated
= MAX (0x100,
10317 abbrev_lookup_allocated
* 2);
10318 abbrev_lookup
= xrealloc (abbrev_lookup
,
10319 (abbrev_lookup_allocated
10320 * sizeof (*abbrev_lookup
)));
10322 assert (abbrev_lookup_used
< abbrev_lookup_allocated
);
10323 struct abbrev_lookup_entry
*entry
;
10324 for (entry
= abbrev_lookup
;
10325 entry
< abbrev_lookup
+ abbrev_lookup_used
;
10327 if (entry
->abbrev_tag
== abbrev_tag
)
10329 warn (_("Duplicate abbreviation tag %" PRIu64
10330 " in unit %#tx in the debug_names section\n"),
10331 abbrev_tag
, unit_start
- section
->start
);
10334 entry
= &abbrev_lookup
[abbrev_lookup_used
++];
10335 entry
->abbrev_tag
= abbrev_tag
;
10336 entry
->abbrev_lookup_ptr
= abbrevptr
;
10338 /* Skip DWARF tag. */
10339 SKIP_ULEB (abbrevptr
, abbrev_table_end
);
10342 uint64_t xindex
, form
;
10344 READ_ULEB (xindex
, abbrevptr
, abbrev_table_end
);
10345 READ_ULEB (form
, abbrevptr
, abbrev_table_end
);
10346 if (xindex
== 0 && form
== 0)
10351 printf (_("\nSymbol table:\n"));
10353 for (namei
= 0; namei
< name_count
; ++namei
)
10355 uint64_t string_offset
, entry_offset
;
10358 p
= name_table_string_offsets
+ namei
* offset_size
;
10359 SAFE_BYTE_GET (string_offset
, p
, offset_size
, unit_end
);
10360 p
= name_table_entry_offsets
+ namei
* offset_size
;
10361 SAFE_BYTE_GET (entry_offset
, p
, offset_size
, unit_end
);
10363 printf ("[%3u] #%08x %s:", namei
, hash_table_hashes
[namei
],
10364 fetch_indirect_string (string_offset
));
10366 unsigned char *entryptr
= entry_pool
+ entry_offset
;
10368 /* We need to scan first whether there is a single or multiple
10369 entries. TAGNO is -2 for the first entry, it is -1 for the
10370 initial tag read of the second entry, then it becomes 0 for the
10371 first entry for real printing etc. */
10373 /* Initialize it due to a false compiler warning. */
10374 uint64_t second_abbrev_tag
= -1;
10377 uint64_t abbrev_tag
;
10378 uint64_t dwarf_tag
;
10379 const struct abbrev_lookup_entry
*entry
;
10381 READ_ULEB (abbrev_tag
, entryptr
, unit_end
);
10384 second_abbrev_tag
= abbrev_tag
;
10386 entryptr
= entry_pool
+ entry_offset
;
10389 if (abbrev_tag
== 0)
10392 printf ("%s<%" PRIu64
">",
10393 (tagno
== 0 && second_abbrev_tag
== 0 ? " " : "\n\t"),
10396 for (entry
= abbrev_lookup
;
10397 entry
< abbrev_lookup
+ abbrev_lookup_used
;
10399 if (entry
->abbrev_tag
== abbrev_tag
)
10401 if (entry
>= abbrev_lookup
+ abbrev_lookup_used
)
10403 warn (_("Undefined abbreviation tag %" PRId64
10404 " in unit %#tx in the debug_names section\n"),
10406 unit_start
- section
->start
);
10409 abbrevptr
= entry
->abbrev_lookup_ptr
;
10410 READ_ULEB (dwarf_tag
, abbrevptr
, abbrev_table_end
);
10412 printf (" %s", get_TAG_name (dwarf_tag
));
10415 uint64_t xindex
, form
;
10417 READ_ULEB (xindex
, abbrevptr
, abbrev_table_end
);
10418 READ_ULEB (form
, abbrevptr
, abbrev_table_end
);
10419 if (xindex
== 0 && form
== 0)
10423 printf (" %s", get_IDX_name (xindex
));
10424 entryptr
= read_and_display_attr_value (0, form
, 0,
10425 unit_start
, entryptr
, unit_end
,
10427 dwarf_version
, NULL
,
10428 (tagno
< 0), section
,
10434 printf (_(" <no entries>"));
10438 free (abbrev_lookup
);
10445 display_debug_links (struct dwarf_section
* section
,
10446 void * file ATTRIBUTE_UNUSED
)
10448 const unsigned char * filename
;
10449 unsigned int filelen
;
10451 introduce (section
, false);
10453 /* The .gnu_debuglink section is formatted as:
10454 (c-string) Filename.
10455 (padding) If needed to reach a 4 byte boundary.
10456 (uint32_t) CRC32 value.
10458 The .gun_debugaltlink section is formatted as:
10459 (c-string) Filename.
10460 (binary) Build-ID. */
10462 filename
= section
->start
;
10463 filelen
= strnlen ((const char *) filename
, section
->size
);
10464 if (filelen
== section
->size
)
10466 warn (_("The debuglink filename is corrupt/missing\n"));
10470 printf (_(" Separate debug info file: %s\n"), filename
);
10472 if (startswith (section
->name
, ".gnu_debuglink"))
10474 unsigned int crc32
;
10475 unsigned int crc_offset
;
10477 crc_offset
= filelen
+ 1;
10478 crc_offset
= (crc_offset
+ 3) & ~3;
10479 if (crc_offset
+ 4 > section
->size
)
10481 warn (_("CRC offset missing/truncated\n"));
10485 crc32
= byte_get (filename
+ crc_offset
, 4);
10487 printf (_(" CRC value: %#x\n"), crc32
);
10489 if (crc_offset
+ 4 < section
->size
)
10491 warn (_("There are %#" PRIx64
10492 " extraneous bytes at the end of the section\n"),
10493 section
->size
- (crc_offset
+ 4));
10497 else /* startswith (section->name, ".gnu_debugaltlink") */
10499 const unsigned char *build_id
= section
->start
+ filelen
+ 1;
10500 size_t build_id_len
= section
->size
- (filelen
+ 1);
10503 /* FIXME: Should we support smaller build-id notes ? */
10504 if (build_id_len
< 0x14)
10506 warn (_("Build-ID is too short (%#zx bytes)\n"), build_id_len
);
10510 printed
= printf (_(" Build-ID (%#zx bytes):"), build_id_len
);
10511 display_data (printed
, build_id
, build_id_len
);
10520 display_gdb_index (struct dwarf_section
*section
,
10521 void *file ATTRIBUTE_UNUSED
)
10523 unsigned char *start
= section
->start
;
10525 uint32_t cu_list_offset
, tu_list_offset
;
10526 uint32_t address_table_offset
, symbol_table_offset
, constant_pool_offset
;
10527 unsigned int cu_list_elements
, tu_list_elements
;
10528 unsigned int address_table_elements
, symbol_table_slots
;
10529 unsigned char *cu_list
, *tu_list
;
10530 unsigned char *address_table
, *symbol_table
, *constant_pool
;
10533 /* The documentation for the format of this file is in gdb/dwarf2read.c. */
10535 introduce (section
, false);
10537 if (section
->size
< 6 * sizeof (uint32_t))
10539 warn (_("Truncated header in the %s section.\n"), section
->name
);
10543 version
= byte_get_little_endian (start
, 4);
10544 printf (_("Version %lu\n"), (unsigned long) version
);
10546 /* Prior versions are obsolete, and future versions may not be
10547 backwards compatible. */
10548 if (version
< 3 || version
> 8)
10550 warn (_("Unsupported version %lu.\n"), (unsigned long) version
);
10554 warn (_("The address table data in version 3 may be wrong.\n"));
10556 warn (_("Version 4 does not support case insensitive lookups.\n"));
10558 warn (_("Version 5 does not include inlined functions.\n"));
10560 warn (_("Version 6 does not include symbol attributes.\n"));
10561 /* Version 7 indices generated by Gold have bad type unit references,
10562 PR binutils/15021. But we don't know if the index was generated by
10563 Gold or not, so to avoid worrying users with gdb-generated indices
10564 we say nothing for version 7 here. */
10566 cu_list_offset
= byte_get_little_endian (start
+ 4, 4);
10567 tu_list_offset
= byte_get_little_endian (start
+ 8, 4);
10568 address_table_offset
= byte_get_little_endian (start
+ 12, 4);
10569 symbol_table_offset
= byte_get_little_endian (start
+ 16, 4);
10570 constant_pool_offset
= byte_get_little_endian (start
+ 20, 4);
10572 if (cu_list_offset
> section
->size
10573 || tu_list_offset
> section
->size
10574 || address_table_offset
> section
->size
10575 || symbol_table_offset
> section
->size
10576 || constant_pool_offset
> section
->size
10577 || tu_list_offset
< cu_list_offset
10578 || address_table_offset
< tu_list_offset
10579 || symbol_table_offset
< address_table_offset
10580 || constant_pool_offset
< symbol_table_offset
)
10582 warn (_("Corrupt header in the %s section.\n"), section
->name
);
10586 cu_list_elements
= (tu_list_offset
- cu_list_offset
) / 16;
10587 tu_list_elements
= (address_table_offset
- tu_list_offset
) / 24;
10588 address_table_elements
= (symbol_table_offset
- address_table_offset
) / 20;
10589 symbol_table_slots
= (constant_pool_offset
- symbol_table_offset
) / 8;
10591 cu_list
= start
+ cu_list_offset
;
10592 tu_list
= start
+ tu_list_offset
;
10593 address_table
= start
+ address_table_offset
;
10594 symbol_table
= start
+ symbol_table_offset
;
10595 constant_pool
= start
+ constant_pool_offset
;
10597 printf (_("\nCU table:\n"));
10598 for (i
= 0; i
< cu_list_elements
; i
++)
10600 uint64_t cu_offset
= byte_get_little_endian (cu_list
+ i
* 16, 8);
10601 uint64_t cu_length
= byte_get_little_endian (cu_list
+ i
* 16 + 8, 8);
10603 printf ("[%3u] %#" PRIx64
" - %#" PRIx64
"\n",
10604 i
, cu_offset
, cu_offset
+ cu_length
- 1);
10607 printf (_("\nTU table:\n"));
10608 for (i
= 0; i
< tu_list_elements
; i
++)
10610 uint64_t tu_offset
= byte_get_little_endian (tu_list
+ i
* 24, 8);
10611 uint64_t type_offset
= byte_get_little_endian (tu_list
+ i
* 24 + 8, 8);
10612 uint64_t signature
= byte_get_little_endian (tu_list
+ i
* 24 + 16, 8);
10614 printf ("[%3u] %#" PRIx64
" %#" PRIx64
" ",
10615 i
, tu_offset
, type_offset
);
10616 print_hex_ns (signature
, 8);
10620 printf (_("\nAddress table:\n"));
10621 for (i
= 0; i
< address_table_elements
; i
++)
10623 uint64_t low
= byte_get_little_endian (address_table
+ i
* 20, 8);
10624 uint64_t high
= byte_get_little_endian (address_table
+ i
* 20 + 8, 8);
10625 uint32_t cu_index
= byte_get_little_endian (address_table
+ i
* 20 + 16, 4);
10627 print_hex (low
, 8);
10628 print_hex (high
, 8);
10629 printf ("%" PRIu32
"\n", cu_index
);
10632 printf (_("\nSymbol table:\n"));
10633 for (i
= 0; i
< symbol_table_slots
; ++i
)
10635 uint32_t name_offset
= byte_get_little_endian (symbol_table
+ i
* 8, 4);
10636 uint32_t cu_vector_offset
= byte_get_little_endian (symbol_table
+ i
* 8 + 4, 4);
10637 uint32_t num_cus
, cu
;
10639 if (name_offset
!= 0
10640 || cu_vector_offset
!= 0)
10644 /* PR 17531: file: 5b7b07ad. */
10645 if (name_offset
>= section
->size
- constant_pool_offset
)
10647 printf (_("[%3u] <corrupt offset: %x>"), i
, name_offset
);
10648 warn (_("Corrupt name offset of 0x%x found for symbol table slot %d\n"),
10652 printf ("[%3u] %.*s:", i
,
10653 (int) (section
->size
- (constant_pool_offset
+ name_offset
)),
10654 constant_pool
+ name_offset
);
10656 if (section
->size
- constant_pool_offset
< 4
10657 || cu_vector_offset
> section
->size
- constant_pool_offset
- 4)
10659 printf (_("<invalid CU vector offset: %x>\n"), cu_vector_offset
);
10660 warn (_("Corrupt CU vector offset of 0x%x found for symbol table slot %d\n"),
10661 cu_vector_offset
, i
);
10665 num_cus
= byte_get_little_endian (constant_pool
+ cu_vector_offset
, 4);
10667 if ((uint64_t) num_cus
* 4 > section
->size
- (constant_pool_offset
10668 + cu_vector_offset
+ 4))
10670 printf ("<invalid number of CUs: %d>\n", num_cus
);
10671 warn (_("Invalid number of CUs (0x%x) for symbol table slot %d\n"),
10679 for (j
= 0; j
< num_cus
; ++j
)
10682 gdb_index_symbol_kind kind
;
10684 cu
= byte_get_little_endian (constant_pool
+ cu_vector_offset
+ 4 + j
* 4, 4);
10685 is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu
);
10686 kind
= GDB_INDEX_SYMBOL_KIND_VALUE (cu
);
10687 cu
= GDB_INDEX_CU_VALUE (cu
);
10688 /* Convert to TU number if it's for a type unit. */
10689 if (cu
>= cu_list_elements
)
10690 printf ("%cT%lu", num_cus
> 1 ? '\t' : ' ',
10691 (unsigned long) cu
- cu_list_elements
);
10693 printf ("%c%lu", num_cus
> 1 ? '\t' : ' ', (unsigned long) cu
);
10695 printf (" [%s, %s]",
10696 is_static
? _("static") : _("global"),
10697 get_gdb_index_symbol_kind_name (kind
));
10709 /* Pre-allocate enough space for the CU/TU sets needed. */
10712 prealloc_cu_tu_list (unsigned int nshndx
)
10714 if (shndx_pool
== NULL
)
10716 shndx_pool_size
= nshndx
;
10717 shndx_pool_used
= 0;
10718 shndx_pool
= (unsigned int *) xcmalloc (shndx_pool_size
,
10719 sizeof (unsigned int));
10723 shndx_pool_size
= shndx_pool_used
+ nshndx
;
10724 shndx_pool
= (unsigned int *) xcrealloc (shndx_pool
, shndx_pool_size
,
10725 sizeof (unsigned int));
10730 add_shndx_to_cu_tu_entry (unsigned int shndx
)
10732 shndx_pool
[shndx_pool_used
++] = shndx
;
10736 end_cu_tu_entry (void)
10738 shndx_pool
[shndx_pool_used
++] = 0;
10741 /* Return the short name of a DWARF section given by a DW_SECT enumerator. */
10743 static const char *
10744 get_DW_SECT_short_name (unsigned int dw_sect
)
10746 static char buf
[16];
10752 case DW_SECT_TYPES
:
10754 case DW_SECT_ABBREV
:
10760 case DW_SECT_STR_OFFSETS
:
10762 case DW_SECT_MACINFO
:
10764 case DW_SECT_MACRO
:
10770 snprintf (buf
, sizeof (buf
), "%d", dw_sect
);
10774 /* Process a CU or TU index. If DO_DISPLAY is true, print the contents.
10775 These sections are extensions for Fission.
10776 See http://gcc.gnu.org/wiki/DebugFissionDWP. */
10779 process_cu_tu_index (struct dwarf_section
*section
, int do_display
)
10781 unsigned char *phdr
= section
->start
;
10782 unsigned char *limit
= phdr
+ section
->size
;
10783 unsigned char *phash
;
10784 unsigned char *pindex
;
10785 unsigned char *ppool
;
10786 unsigned int version
;
10787 unsigned int ncols
= 0;
10788 unsigned int nused
;
10789 unsigned int nslots
;
10792 uint64_t signature
;
10795 /* PR 17512: file: 002-168123-0.004. */
10798 warn (_("Section %s is empty\n"), section
->name
);
10801 /* PR 17512: file: 002-376-0.004. */
10802 if (section
->size
< 24)
10804 warn (_("Section %s is too small to contain a CU/TU header\n"),
10810 SAFE_BYTE_GET_AND_INC (version
, phash
, 4, limit
);
10812 SAFE_BYTE_GET_AND_INC (ncols
, phash
, 4, limit
);
10813 SAFE_BYTE_GET_AND_INC (nused
, phash
, 4, limit
);
10814 SAFE_BYTE_GET_AND_INC (nslots
, phash
, 4, limit
);
10816 pindex
= phash
+ (size_t) nslots
* 8;
10817 ppool
= pindex
+ (size_t) nslots
* 4;
10821 introduce (section
, false);
10823 printf (_(" Version: %u\n"), version
);
10825 printf (_(" Number of columns: %u\n"), ncols
);
10826 printf (_(" Number of used entries: %u\n"), nused
);
10827 printf (_(" Number of slots: %u\n\n"), nslots
);
10830 /* PR 17531: file: 45d69832. */
10831 if (_mul_overflow ((size_t) nslots
, 12, &total
)
10832 || total
> (size_t) (limit
- phash
))
10834 warn (ngettext ("Section %s is too small for %u slot\n",
10835 "Section %s is too small for %u slots\n",
10837 section
->name
, nslots
);
10843 unsigned char *shndx_list
;
10844 unsigned int shndx
;
10848 prealloc_cu_tu_list ((limit
- ppool
) / 4);
10849 for (shndx_list
= ppool
+ 4; shndx_list
<= limit
- 4; shndx_list
+= 4)
10851 shndx
= byte_get (shndx_list
, 4);
10852 add_shndx_to_cu_tu_entry (shndx
);
10854 end_cu_tu_entry ();
10857 for (i
= 0; i
< nslots
; i
++)
10859 SAFE_BYTE_GET (signature
, phash
, 8, limit
);
10860 if (signature
!= 0)
10862 SAFE_BYTE_GET (j
, pindex
, 4, limit
);
10863 shndx_list
= ppool
+ j
* 4;
10864 /* PR 17531: file: 705e010d. */
10865 if (shndx_list
< ppool
)
10867 warn (_("Section index pool located before start of section\n"));
10871 printf (_(" [%3d] Signature: %#" PRIx64
" Sections: "),
10875 if (shndx_list
>= limit
)
10877 warn (_("Section %s too small for shndx pool\n"),
10881 SAFE_BYTE_GET (shndx
, shndx_list
, 4, limit
);
10884 printf (" %d", shndx
);
10893 else if (version
== 2)
10896 unsigned int dw_sect
;
10897 unsigned char *ph
= phash
;
10898 unsigned char *pi
= pindex
;
10899 unsigned char *poffsets
= ppool
+ (size_t) ncols
* 4;
10900 unsigned char *psizes
= poffsets
+ (size_t) nused
* ncols
* 4;
10902 struct cu_tu_set
*this_set
= NULL
;
10904 unsigned char *prow
;
10907 is_tu_index
= strcmp (section
->name
, ".debug_tu_index") == 0;
10909 /* PR 17531: file: 0dd159bf.
10910 Check for integer overflow (can occur when size_t is 32-bit)
10911 with overlarge ncols or nused values. */
10913 || _mul_overflow ((size_t) ncols
, 4, &temp
)
10914 || _mul_overflow ((size_t) nused
+ 1, temp
, &total
)
10915 || total
> (size_t) (limit
- ppool
))
10917 warn (_("Section %s too small for offset and size tables\n"),
10924 printf (_(" Offset table\n"));
10925 printf (" slot %-16s ",
10926 is_tu_index
? _("signature") : _("dwo_id"));
10933 tu_sets
= xcalloc2 (nused
, sizeof (struct cu_tu_set
));
10934 this_set
= tu_sets
;
10939 cu_sets
= xcalloc2 (nused
, sizeof (struct cu_tu_set
));
10940 this_set
= cu_sets
;
10946 for (j
= 0; j
< ncols
; j
++)
10948 unsigned char *p
= ppool
+ j
* 4;
10949 SAFE_BYTE_GET (dw_sect
, p
, 4, limit
);
10950 printf (" %8s", get_DW_SECT_short_name (dw_sect
));
10955 for (i
= 0; i
< nslots
; i
++)
10957 SAFE_BYTE_GET (signature
, ph
, 8, limit
);
10959 SAFE_BYTE_GET (row
, pi
, 4, limit
);
10962 /* PR 17531: file: a05f6ab3. */
10965 warn (_("Row index (%u) is larger than number of used entries (%u)\n"),
10972 size_t num_copy
= sizeof (uint64_t);
10974 memcpy (&this_set
[row
- 1].signature
, ph
, num_copy
);
10977 prow
= poffsets
+ (row
- 1) * ncols
* 4;
10979 printf (" [%3d] %#" PRIx64
, i
, signature
);
10980 for (j
= 0; j
< ncols
; j
++)
10982 unsigned char *p
= prow
+ j
* 4;
10983 SAFE_BYTE_GET (val
, p
, 4, limit
);
10985 printf (" %8d", val
);
10989 SAFE_BYTE_GET (dw_sect
, p
, 4, limit
);
10991 /* PR 17531: file: 10796eb3. */
10992 if (dw_sect
>= DW_SECT_MAX
)
10993 warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect
);
10995 this_set
[row
- 1].section_offsets
[dw_sect
] = val
;
11011 printf (_(" Size table\n"));
11012 printf (" slot %-16s ",
11013 is_tu_index
? _("signature") : _("dwo_id"));
11016 for (j
= 0; j
< ncols
; j
++)
11018 unsigned char *p
= ppool
+ j
* 4;
11019 SAFE_BYTE_GET (val
, p
, 4, limit
);
11021 printf (" %8s", get_DW_SECT_short_name (val
));
11027 for (i
= 0; i
< nslots
; i
++)
11029 SAFE_BYTE_GET (signature
, ph
, 8, limit
);
11031 SAFE_BYTE_GET (row
, pi
, 4, limit
);
11034 prow
= psizes
+ (row
- 1) * ncols
* 4;
11037 printf (" [%3d] %#" PRIx64
, i
, signature
);
11039 for (j
= 0; j
< ncols
; j
++)
11041 unsigned char *p
= prow
+ j
* 4;
11043 /* PR 28645: Check for overflow. Since we do not know how
11044 many populated rows there will be, we cannot just
11045 perform a single check at the start of this function. */
11046 if (p
> (limit
- 4))
11050 warn (_("Too many rows/columns in DWARF index section %s\n"),
11055 SAFE_BYTE_GET (val
, p
, 4, limit
);
11058 printf (" %8d", val
);
11062 SAFE_BYTE_GET (dw_sect
, p
, 4, limit
);
11063 if (dw_sect
>= DW_SECT_MAX
)
11064 warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect
);
11066 this_set
[row
- 1].section_sizes
[dw_sect
] = val
;
11078 else if (do_display
)
11079 printf (_(" Unsupported version (%d)\n"), version
);
11087 static int cu_tu_indexes_read
= -1; /* Tri-state variable. */
11089 /* Load the CU and TU indexes if present. This will build a list of
11090 section sets that we can use to associate a .debug_info.dwo section
11091 with its associated .debug_abbrev.dwo section in a .dwp file. */
11094 load_cu_tu_indexes (void *file
)
11096 /* If we have already loaded (or tried to load) the CU and TU indexes
11097 then do not bother to repeat the task. */
11098 if (cu_tu_indexes_read
== -1)
11100 cu_tu_indexes_read
= true;
11102 if (load_debug_section_with_follow (dwp_cu_index
, file
))
11103 if (! process_cu_tu_index (&debug_displays
[dwp_cu_index
].section
, 0))
11104 cu_tu_indexes_read
= false;
11106 if (load_debug_section_with_follow (dwp_tu_index
, file
))
11107 if (! process_cu_tu_index (&debug_displays
[dwp_tu_index
].section
, 0))
11108 cu_tu_indexes_read
= false;
11111 return (bool) cu_tu_indexes_read
;
11114 /* Find the set of sections that includes section SHNDX. */
11117 find_cu_tu_set (void *file
, unsigned int shndx
)
11121 if (! load_cu_tu_indexes (file
))
11124 /* Find SHNDX in the shndx pool. */
11125 for (i
= 0; i
< shndx_pool_used
; i
++)
11126 if (shndx_pool
[i
] == shndx
)
11129 if (i
>= shndx_pool_used
)
11132 /* Now backup to find the first entry in the set. */
11133 while (i
> 0 && shndx_pool
[i
- 1] != 0)
11136 return shndx_pool
+ i
;
11139 /* Display a .debug_cu_index or .debug_tu_index section. */
11142 display_cu_index (struct dwarf_section
*section
, void *file ATTRIBUTE_UNUSED
)
11144 return process_cu_tu_index (section
, 1);
11148 display_debug_not_supported (struct dwarf_section
*section
,
11149 void *file ATTRIBUTE_UNUSED
)
11151 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
11157 /* Like malloc, but takes two parameters like calloc.
11158 Verifies that the first parameter is not too large.
11159 Note: does *not* initialise the allocated memory to zero. */
11162 cmalloc (uint64_t nmemb
, size_t size
)
11164 /* Check for overflow. */
11165 if (nmemb
>= ~(size_t) 0 / size
)
11168 return xmalloc (nmemb
* size
);
11171 /* Like xmalloc, but takes two parameters like calloc.
11172 Verifies that the first parameter is not too large.
11173 Note: does *not* initialise the allocated memory to zero. */
11176 xcmalloc (uint64_t nmemb
, size_t size
)
11178 /* Check for overflow. */
11179 if (nmemb
>= ~(size_t) 0 / size
)
11182 _("Attempt to allocate an array with an excessive number of elements: %#" PRIx64
"\n"),
11187 return xmalloc (nmemb
* size
);
11190 /* Like xrealloc, but takes three parameters.
11191 Verifies that the second parameter is not too large.
11192 Note: does *not* initialise any new memory to zero. */
11195 xcrealloc (void *ptr
, uint64_t nmemb
, size_t size
)
11197 /* Check for overflow. */
11198 if (nmemb
>= ~(size_t) 0 / size
)
11200 error (_("Attempt to re-allocate an array with an excessive number of elements: %#" PRIx64
"\n"),
11205 return xrealloc (ptr
, nmemb
* size
);
11208 /* Like xcalloc, but verifies that the first parameter is not too large. */
11211 xcalloc2 (uint64_t nmemb
, size_t size
)
11213 /* Check for overflow. */
11214 if (nmemb
>= ~(size_t) 0 / size
)
11216 error (_("Attempt to allocate a zero'ed array with an excessive number of elements: %#" PRIx64
"\n"),
11221 return xcalloc (nmemb
, size
);
11224 static unsigned long
11225 calc_gnu_debuglink_crc32 (unsigned long crc
,
11226 const unsigned char *buf
,
11229 static const unsigned long crc32_table
[256] =
11231 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
11232 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
11233 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
11234 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
11235 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
11236 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
11237 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
11238 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
11239 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
11240 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
11241 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
11242 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
11243 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
11244 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
11245 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
11246 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
11247 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
11248 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
11249 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
11250 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
11251 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
11252 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
11253 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
11254 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
11255 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
11256 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
11257 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
11258 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
11259 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
11260 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
11261 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
11262 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
11263 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
11264 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
11265 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
11266 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
11267 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
11268 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
11269 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
11270 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
11271 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
11272 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
11273 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
11274 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
11275 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
11276 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
11277 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
11278 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
11279 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
11280 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
11281 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
11284 const unsigned char *end
;
11286 crc
= ~crc
& 0xffffffff;
11287 for (end
= buf
+ len
; buf
< end
; ++ buf
)
11288 crc
= crc32_table
[(crc
^ *buf
) & 0xff] ^ (crc
>> 8);
11289 return ~crc
& 0xffffffff;
11292 typedef bool (*check_func_type
) (const char *, void *);
11293 typedef const char *(* parse_func_type
) (struct dwarf_section
*, void *);
11296 check_gnu_debuglink (const char * pathname
, void * crc_pointer
)
11298 static unsigned char buffer
[8 * 1024];
11301 unsigned long crc
= 0;
11304 sep_data
= open_debug_file (pathname
);
11305 if (sep_data
== NULL
)
11308 /* Yes - we are opening the file twice... */
11309 f
= fopen (pathname
, "rb");
11312 /* Paranoia: This should never happen. */
11313 close_debug_file (sep_data
);
11314 warn (_("Unable to reopen separate debug info file: %s\n"), pathname
);
11318 while ((count
= fread (buffer
, 1, sizeof (buffer
), f
)) > 0)
11319 crc
= calc_gnu_debuglink_crc32 (crc
, buffer
, count
);
11323 if (crc
!= * (unsigned long *) crc_pointer
)
11325 close_debug_file (sep_data
);
11326 warn (_("Separate debug info file %s found, but CRC does not match - ignoring\n"),
11334 static const char *
11335 parse_gnu_debuglink (struct dwarf_section
* section
, void * data
)
11338 unsigned int crc_offset
;
11339 unsigned long * crc32
= (unsigned long *) data
;
11341 /* The name is first.
11342 The CRC value is stored after the filename, aligned up to 4 bytes. */
11343 name
= (const char *) section
->start
;
11345 crc_offset
= strnlen (name
, section
->size
) + 1;
11346 if (crc_offset
== 1)
11348 crc_offset
= (crc_offset
+ 3) & ~3;
11349 if (crc_offset
+ 4 > section
->size
)
11352 * crc32
= byte_get (section
->start
+ crc_offset
, 4);
11357 check_gnu_debugaltlink (const char * filename
, void * data ATTRIBUTE_UNUSED
)
11359 void * sep_data
= open_debug_file (filename
);
11361 if (sep_data
== NULL
)
11364 /* FIXME: We should now extract the build-id in the separate file
11370 typedef struct build_id_data
11373 const unsigned char *data
;
11376 static const char *
11377 parse_gnu_debugaltlink (struct dwarf_section
* section
, void * data
)
11382 Build_id_data
*build_id_data
;
11384 /* The name is first.
11385 The build-id follows immediately, with no padding, up to the section's end. */
11387 name
= (const char *) section
->start
;
11388 namelen
= strnlen (name
, section
->size
) + 1;
11391 if (namelen
>= section
->size
)
11394 id_len
= section
->size
- namelen
;
11398 build_id_data
= (Build_id_data
*) data
;
11399 build_id_data
->len
= id_len
;
11400 build_id_data
->data
= section
->start
+ namelen
;
11406 add_separate_debug_file (const char * filename
, void * handle
)
11408 separate_info
* i
= xmalloc (sizeof * i
);
11410 i
->filename
= filename
;
11411 i
->handle
= handle
;
11412 i
->next
= first_separate_info
;
11413 first_separate_info
= i
;
11416 #if HAVE_LIBDEBUGINFOD
11417 /* Query debuginfod servers for the target debuglink or debugaltlink
11418 file. If successful, store the path of the file in filename and
11419 return TRUE, otherwise return FALSE. */
11422 debuginfod_fetch_separate_debug_info (struct dwarf_section
* section
,
11426 size_t build_id_len
;
11427 unsigned char * build_id
;
11429 if (strcmp (section
->uncompressed_name
, ".gnu_debuglink") == 0)
11431 /* Get the build-id of file. */
11432 build_id
= get_build_id (file
);
11435 else if (strcmp (section
->uncompressed_name
, ".gnu_debugaltlink") == 0)
11437 /* Get the build-id of the debugaltlink file. */
11438 unsigned int filelen
;
11440 filelen
= strnlen ((const char *)section
->start
, section
->size
);
11441 if (filelen
== section
->size
)
11442 /* Corrupt debugaltlink. */
11445 build_id
= section
->start
+ filelen
+ 1;
11446 build_id_len
= section
->size
- (filelen
+ 1);
11448 if (build_id_len
== 0)
11457 debuginfod_client
* client
;
11459 client
= debuginfod_begin ();
11460 if (client
== NULL
)
11463 /* Query debuginfod servers for the target file. If found its path
11464 will be stored in filename. */
11465 fd
= debuginfod_find_debuginfo (client
, build_id
, build_id_len
, filename
);
11466 debuginfod_end (client
);
11468 /* Only free build_id if we allocated space for a hex string
11469 in get_build_id (). */
11470 if (build_id_len
== 0)
11475 /* File successfully retrieved. Close fd since we want to
11476 use open_debug_file () on filename instead. */
11484 #endif /* HAVE_LIBDEBUGINFOD */
11487 load_separate_debug_info (const char * main_filename
,
11488 struct dwarf_section
* xlink
,
11489 parse_func_type parse_func
,
11490 check_func_type check_func
,
11492 void * file ATTRIBUTE_UNUSED
)
11494 const char * separate_filename
;
11495 char * debug_filename
;
11497 size_t canon_dirlen
;
11499 char * canon_filename
;
11500 char * canon_debug_filename
;
11503 if ((separate_filename
= parse_func (xlink
, func_data
)) == NULL
)
11505 warn (_("Corrupt debuglink section: %s\n"),
11506 xlink
->name
? xlink
->name
: xlink
->uncompressed_name
);
11510 /* Attempt to locate the separate file.
11511 This should duplicate the logic in bfd/opncls.c:find_separate_debug_file(). */
11513 canon_filename
= lrealpath (main_filename
);
11514 canon_dir
= xstrdup (canon_filename
);
11516 for (canon_dirlen
= strlen (canon_dir
); canon_dirlen
> 0; canon_dirlen
--)
11517 if (IS_DIR_SEPARATOR (canon_dir
[canon_dirlen
- 1]))
11519 canon_dir
[canon_dirlen
] = '\0';
11522 #define DEBUGDIR "/lib/debug"
11524 #ifndef EXTRA_DEBUG_ROOT1
11525 #define EXTRA_DEBUG_ROOT1 "/usr/lib/debug"
11527 #ifndef EXTRA_DEBUG_ROOT2
11528 #define EXTRA_DEBUG_ROOT2 "/usr/lib/debug/usr"
11531 debug_filename
= (char *) malloc (strlen (DEBUGDIR
) + 1
11533 + strlen (".debug/")
11534 #ifdef EXTRA_DEBUG_ROOT1
11535 + strlen (EXTRA_DEBUG_ROOT1
)
11537 #ifdef EXTRA_DEBUG_ROOT2
11538 + strlen (EXTRA_DEBUG_ROOT2
)
11540 + strlen (separate_filename
)
11542 if (debug_filename
== NULL
)
11544 warn (_("Out of memory"));
11546 free (canon_filename
);
11550 /* First try in the current directory. */
11551 sprintf (debug_filename
, "%s", separate_filename
);
11552 if (check_func (debug_filename
, func_data
))
11555 /* Then try in a subdirectory called .debug. */
11556 sprintf (debug_filename
, ".debug/%s", separate_filename
);
11557 if (check_func (debug_filename
, func_data
))
11560 /* Then try in the same directory as the original file. */
11561 sprintf (debug_filename
, "%s%s", canon_dir
, separate_filename
);
11562 if (check_func (debug_filename
, func_data
))
11565 /* And the .debug subdirectory of that directory. */
11566 sprintf (debug_filename
, "%s.debug/%s", canon_dir
, separate_filename
);
11567 if (check_func (debug_filename
, func_data
))
11570 #ifdef EXTRA_DEBUG_ROOT1
11571 /* Try the first extra debug file root. */
11572 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT1
, separate_filename
);
11573 if (check_func (debug_filename
, func_data
))
11576 /* Try the first extra debug file root. */
11577 sprintf (debug_filename
, "%s/%s/%s", EXTRA_DEBUG_ROOT1
, canon_dir
, separate_filename
);
11578 if (check_func (debug_filename
, func_data
))
11582 #ifdef EXTRA_DEBUG_ROOT2
11583 /* Try the second extra debug file root. */
11584 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT2
, separate_filename
);
11585 if (check_func (debug_filename
, func_data
))
11589 /* Then try in the global debug_filename directory. */
11590 strcpy (debug_filename
, DEBUGDIR
);
11591 dirlen
= strlen (DEBUGDIR
) - 1;
11592 if (dirlen
> 0 && DEBUGDIR
[dirlen
] != '/')
11593 strcat (debug_filename
, "/");
11594 strcat (debug_filename
, (const char *) separate_filename
);
11596 if (check_func (debug_filename
, func_data
))
11599 #if HAVE_LIBDEBUGINFOD
11601 char * tmp_filename
;
11604 && debuginfod_fetch_separate_debug_info (xlink
,
11608 /* File successfully downloaded from server, replace
11609 debug_filename with the file's path. */
11610 free (debug_filename
);
11611 debug_filename
= tmp_filename
;
11617 if (do_debug_links
)
11619 /* Failed to find the file. */
11620 warn (_("could not find separate debug file '%s'\n"),
11621 separate_filename
);
11622 warn (_("tried: %s\n"), debug_filename
);
11624 #ifdef EXTRA_DEBUG_ROOT2
11625 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT2
,
11626 separate_filename
);
11627 warn (_("tried: %s\n"), debug_filename
);
11630 #ifdef EXTRA_DEBUG_ROOT1
11631 sprintf (debug_filename
, "%s/%s/%s", EXTRA_DEBUG_ROOT1
,
11632 canon_dir
, separate_filename
);
11633 warn (_("tried: %s\n"), debug_filename
);
11635 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT1
,
11636 separate_filename
);
11637 warn (_("tried: %s\n"), debug_filename
);
11640 sprintf (debug_filename
, "%s.debug/%s", canon_dir
,
11641 separate_filename
);
11642 warn (_("tried: %s\n"), debug_filename
);
11644 sprintf (debug_filename
, "%s%s", canon_dir
, separate_filename
);
11645 warn (_("tried: %s\n"), debug_filename
);
11647 sprintf (debug_filename
, ".debug/%s", separate_filename
);
11648 warn (_("tried: %s\n"), debug_filename
);
11650 sprintf (debug_filename
, "%s", separate_filename
);
11651 warn (_("tried: %s\n"), debug_filename
);
11653 #if HAVE_LIBDEBUGINFOD
11654 if (use_debuginfod
)
11656 char *urls
= getenv (DEBUGINFOD_URLS_ENV_VAR
);
11661 warn (_("tried: DEBUGINFOD_URLS=%s\n"), urls
);
11667 free (debug_filename
);
11668 free (canon_filename
);
11674 canon_debug_filename
= lrealpath (debug_filename
);
11675 self
= strcmp (canon_debug_filename
, canon_filename
) == 0;
11676 free (canon_filename
);
11677 free (canon_debug_filename
);
11680 free (debug_filename
);
11684 void * debug_handle
;
11686 /* Now open the file.... */
11687 if ((debug_handle
= open_debug_file (debug_filename
)) == NULL
)
11689 warn (_("failed to open separate debug file: %s\n"), debug_filename
);
11690 free (debug_filename
);
11694 /* FIXME: We do not check to see if there are any other separate debug info
11695 files that would also match. */
11697 if (do_debug_links
)
11698 printf (_("\n%s: Found separate debug info file: %s\n"), main_filename
, debug_filename
);
11699 add_separate_debug_file (debug_filename
, debug_handle
);
11701 /* Do not free debug_filename - it might be referenced inside
11702 the structure returned by open_debug_file(). */
11703 return debug_handle
;
11706 /* Attempt to load a separate dwarf object file. */
11709 load_dwo_file (const char * main_filename
, const char * name
, const char * dir
, const char * id ATTRIBUTE_UNUSED
)
11711 char * separate_filename
;
11712 void * separate_handle
;
11714 if (IS_ABSOLUTE_PATH (name
))
11715 separate_filename
= strdup (name
);
11717 /* FIXME: Skip adding / if dwo_dir ends in /. */
11718 separate_filename
= concat (dir
, "/", name
, NULL
);
11719 if (separate_filename
== NULL
)
11721 warn (_("Out of memory allocating dwo filename\n"));
11725 if ((separate_handle
= open_debug_file (separate_filename
)) == NULL
)
11727 warn (_("Unable to load dwo file: %s\n"), separate_filename
);
11728 free (separate_filename
);
11732 /* FIXME: We should check the dwo_id. */
11734 printf (_("%s: Found separate debug object file: %s\n\n"), main_filename
, separate_filename
);
11736 add_separate_debug_file (separate_filename
, separate_handle
);
11737 /* Note - separate_filename will be freed in free_debug_memory(). */
11738 return separate_handle
;
11742 try_build_id_prefix (const char * prefix
, char * filename
, const unsigned char * data
, unsigned long id_len
)
11744 char * f
= filename
;
11746 f
+= sprintf (f
, "%s.build-id/%02x/", prefix
, (unsigned) *data
++);
11749 f
+= sprintf (f
, "%02x", (unsigned) *data
++);
11750 strcpy (f
, ".debug");
11752 return open_debug_file (filename
);
11755 /* Try to load a debug file based upon the build-id held in the .note.gnu.build-id section. */
11758 load_build_id_debug_file (const char * main_filename ATTRIBUTE_UNUSED
, void * main_file
)
11760 if (! load_debug_section (note_gnu_build_id
, main_file
))
11761 return; /* No .note.gnu.build-id section. */
11763 struct dwarf_section
* section
= & debug_displays
[note_gnu_build_id
].section
;
11764 if (section
== NULL
)
11766 warn (_("Unable to load the .note.gnu.build-id section\n"));
11770 if (section
->start
== NULL
|| section
->size
< 0x18)
11772 warn (_(".note.gnu.build-id section is corrupt/empty\n"));
11776 /* In theory we should extract the contents of the section into
11777 a note structure and then check the fields. For now though
11778 just use hard coded offsets instead:
11780 Field Bytes Contents
11783 Type 8..11 3 (NT_GNU_BUILD_ID)
11787 /* FIXME: Check the name size, name and type fields. */
11789 unsigned long build_id_size
;
11790 build_id_size
= byte_get (section
->start
+ 4, 4);
11791 if (build_id_size
< 8)
11793 warn (_(".note.gnu.build-id data size is too small\n"));
11797 if (build_id_size
> (section
->size
- 16))
11799 warn (_(".note.gnu.build-id data size is too big\n"));
11804 filename
= xmalloc (strlen (".build-id/")
11805 + build_id_size
* 2 + 2
11806 + strlen (".debug")
11807 /* The next string should be the same as the longest
11808 name found in the prefixes[] array below. */
11809 + strlen ("/usrlib64/debug/usr")
11813 static const char * prefixes
[] =
11818 "/usr/lib/debug/usr/",
11819 "/usr/lib64/debug/",
11820 "/usr/lib64/debug/usr"
11822 long unsigned int i
;
11824 for (i
= 0; i
< ARRAY_SIZE (prefixes
); i
++)
11826 handle
= try_build_id_prefix (prefixes
[i
], filename
,
11827 section
->start
+ 16, build_id_size
);
11828 if (handle
!= NULL
)
11831 /* FIXME: TYhe BFD library also tries a global debugfile directory prefix. */
11832 if (handle
== NULL
)
11834 /* Failed to find a debug file associated with the build-id.
11835 This is not an error however, rather it just means that
11836 the debug info has probably not been loaded on the system,
11837 or that another method is being used to link to the debug
11843 add_separate_debug_file (filename
, handle
);
11846 /* Try to load a debug file pointed to by the .debug_sup section. */
11849 load_debug_sup_file (const char * main_filename
, void * file
)
11851 if (! load_debug_section (debug_sup
, file
))
11852 return; /* No .debug_sup section. */
11854 struct dwarf_section
* section
;
11855 section
= & debug_displays
[debug_sup
].section
;
11856 assert (section
!= NULL
);
11858 if (section
->start
== NULL
|| section
->size
< 5)
11860 warn (_(".debug_sup section is corrupt/empty\n"));
11864 if (section
->start
[2] != 0)
11865 return; /* This is a supplementary file. */
11867 const char * filename
= (const char *) section
->start
+ 3;
11868 if (strnlen (filename
, section
->size
- 3) == section
->size
- 3)
11870 warn (_("filename in .debug_sup section is corrupt\n"));
11874 if (filename
[0] != '/' && strchr (main_filename
, '/'))
11879 new_len
= asprintf (& new_name
, "%.*s/%s",
11880 (int) (strrchr (main_filename
, '/') - main_filename
),
11885 warn (_("unable to construct path for supplementary debug file"));
11890 filename
= new_name
;
11894 /* PR 27796: Make sure that we pass a filename that can be free'd to
11895 add_separate_debug_file(). */
11896 filename
= strdup (filename
);
11897 if (filename
== NULL
)
11899 warn (_("out of memory constructing filename for .debug_sup link\n"));
11904 void * handle
= open_debug_file (filename
);
11905 if (handle
== NULL
)
11907 warn (_("unable to open file '%s' referenced from .debug_sup section\n"), filename
);
11908 free ((void *) filename
);
11912 printf (_("%s: Found supplementary debug file: %s\n\n"), main_filename
, filename
);
11914 /* FIXME: Compare the checksums, if present. */
11915 add_separate_debug_file (filename
, handle
);
11918 /* Load a debuglink section and/or a debugaltlink section, if either are present.
11919 Recursively check the loaded files for more of these sections.
11920 Also follow any links in .debug_sup sections.
11921 FIXME: Should also check for DWO_* entries in the newly loaded files. */
11924 check_for_and_load_links (void * file
, const char * filename
)
11926 void * handle
= NULL
;
11928 if (load_debug_section (gnu_debugaltlink
, file
))
11930 Build_id_data build_id_data
;
11932 handle
= load_separate_debug_info (filename
,
11933 & debug_displays
[gnu_debugaltlink
].section
,
11934 parse_gnu_debugaltlink
,
11935 check_gnu_debugaltlink
,
11940 assert (handle
== first_separate_info
->handle
);
11941 check_for_and_load_links (first_separate_info
->handle
,
11942 first_separate_info
->filename
);
11946 if (load_debug_section (gnu_debuglink
, file
))
11948 unsigned long crc32
;
11950 handle
= load_separate_debug_info (filename
,
11951 & debug_displays
[gnu_debuglink
].section
,
11952 parse_gnu_debuglink
,
11953 check_gnu_debuglink
,
11958 assert (handle
== first_separate_info
->handle
);
11959 check_for_and_load_links (first_separate_info
->handle
,
11960 first_separate_info
->filename
);
11964 load_debug_sup_file (filename
, file
);
11966 load_build_id_debug_file (filename
, file
);
11969 /* Load the separate debug info file(s) attached to FILE, if any exist.
11970 Returns TRUE if any were found, FALSE otherwise.
11971 If TRUE is returned then the linked list starting at first_separate_info
11972 will be populated with open file handles. */
11975 load_separate_debug_files (void * file
, const char * filename
)
11977 /* Skip this operation if we are not interested in debug links. */
11978 if (! do_follow_links
&& ! do_debug_links
)
11981 /* See if there are any dwo links. */
11982 if (load_debug_section (str
, file
)
11983 && load_debug_section (abbrev
, file
)
11984 && load_debug_section (info
, file
))
11986 /* Load the .debug_addr section, if it exists. */
11987 load_debug_section (debug_addr
, file
);
11988 /* Load the .debug_str_offsets section, if it exists. */
11989 load_debug_section (str_index
, file
);
11990 /* Load the .debug_loclists section, if it exists. */
11991 load_debug_section (loclists
, file
);
11992 /* Load the .debug_rnglists section, if it exists. */
11993 load_debug_section (rnglists
, file
);
11997 if (process_debug_info (& debug_displays
[info
].section
, file
, abbrev
,
12000 bool introduced
= false;
12002 const char *dir
= NULL
;
12003 const char *id
= NULL
;
12004 const char *name
= NULL
;
12006 for (dwinfo
= first_dwo_info
; dwinfo
!= NULL
; dwinfo
= dwinfo
->next
)
12008 /* Accumulate NAME, DIR and ID fields. */
12009 switch (dwinfo
->type
)
12013 warn (_("Multiple DWO_NAMEs encountered for the same CU\n"));
12014 name
= dwinfo
->value
;
12018 /* There can be multiple DW_AT_comp_dir entries in a CU,
12019 so do not complain. */
12020 dir
= dwinfo
->value
;
12025 warn (_("multiple DWO_IDs encountered for the same CU\n"));
12026 id
= dwinfo
->value
;
12030 error (_("Unexpected DWO INFO type"));
12034 /* If we have reached the end of our list, or we are changing
12035 CUs, then display the information that we have accumulated
12038 && (dwinfo
->next
== NULL
12039 || dwinfo
->next
->cu_offset
!= dwinfo
->cu_offset
))
12041 if (do_debug_links
)
12045 printf (_("The %s section contains link(s) to dwo file(s):\n\n"),
12046 debug_displays
[info
].section
.uncompressed_name
);
12050 printf (_(" Name: %s\n"), name
);
12051 printf (_(" Directory: %s\n"), dir
? dir
: _("<not-found>"));
12053 display_data (printf (_(" ID: ")), (unsigned char *) id
, 8);
12054 else if (debug_information
[0].dwarf_version
!= 5)
12055 printf (_(" ID: <not specified>\n"));
12059 if (do_follow_links
)
12060 load_dwo_file (filename
, name
, dir
, id
);
12062 name
= dir
= id
= NULL
;
12068 if (! do_follow_links
)
12069 /* The other debug links will be displayed by display_debug_links()
12070 so we do not need to do any further processing here. */
12073 /* FIXME: We do not check for the presence of both link sections in the same file. */
12074 /* FIXME: We do not check for the presence of multiple, same-name debuglink sections. */
12075 /* FIXME: We do not check for the presence of a dwo link as well as a debuglink. */
12077 check_for_and_load_links (file
, filename
);
12078 if (first_separate_info
!= NULL
)
12081 do_follow_links
= 0;
12086 free_debug_memory (void)
12090 free_all_abbrevs ();
12094 shndx_pool_size
= 0;
12095 shndx_pool_used
= 0;
12103 memset (level_type_signed
, 0, sizeof level_type_signed
);
12104 cu_tu_indexes_read
= -1;
12106 for (i
= 0; i
< max
; i
++)
12107 free_debug_section ((enum dwarf_section_display_enum
) i
);
12109 if (debug_information
!= NULL
)
12111 for (i
= 0; i
< alloc_num_debug_info_entries
; i
++)
12112 free_debug_information (&debug_information
[i
]);
12113 free (debug_information
);
12114 debug_information
= NULL
;
12115 alloc_num_debug_info_entries
= num_debug_info_entries
= 0;
12119 separate_info
* next
;
12121 for (d
= first_separate_info
; d
!= NULL
; d
= next
)
12123 close_debug_file (d
->handle
);
12124 free ((void *) d
->filename
);
12128 first_separate_info
= NULL
;
12136 const char *option
;
12139 } debug_dump_long_opts
;
12141 static const debug_dump_long_opts debug_option_table
[] =
12143 { 'A', "addr", &do_debug_addr
, 1 },
12144 { 'a', "abbrev", &do_debug_abbrevs
, 1 },
12145 { 'c', "cu_index", &do_debug_cu_index
, 1 },
12146 #ifdef HAVE_LIBDEBUGINFOD
12147 { 'D', "use-debuginfod", &use_debuginfod
, 1 },
12148 { 'E', "do-not-use-debuginfod", &use_debuginfod
, 0 },
12150 { 'F', "frames-interp", &do_debug_frames_interp
, 1 },
12151 { 'f', "frames", &do_debug_frames
, 1 },
12152 { 'g', "gdb_index", &do_gdb_index
, 1 },
12153 { 'i', "info", &do_debug_info
, 1 },
12154 { 'K', "follow-links", &do_follow_links
, 1 },
12155 { 'k', "links", &do_debug_links
, 1 },
12156 { 'L', "decodedline", &do_debug_lines
, FLAG_DEBUG_LINES_DECODED
},
12157 { 'l', "rawline", &do_debug_lines
, FLAG_DEBUG_LINES_RAW
},
12158 /* For compatibility with earlier versions of readelf. */
12159 { 'l', "line", &do_debug_lines
, FLAG_DEBUG_LINES_RAW
},
12160 { 'm', "macro", &do_debug_macinfo
, 1 },
12161 { 'N', "no-follow-links", &do_follow_links
, 0 },
12162 { 'O', "str-offsets", &do_debug_str_offsets
, 1 },
12163 { 'o', "loc", &do_debug_loc
, 1 },
12164 { 'p', "pubnames", &do_debug_pubnames
, 1 },
12165 { 'R', "Ranges", &do_debug_ranges
, 1 },
12166 { 'r', "aranges", &do_debug_aranges
, 1 },
12167 /* For compatibility with earlier versions of readelf. */
12168 { 'r', "ranges", &do_debug_aranges
, 1 },
12169 { 's', "str", &do_debug_str
, 1 },
12170 { 'T', "trace_aranges", &do_trace_aranges
, 1 },
12171 { 't', "pubtypes", &do_debug_pubtypes
, 1 },
12172 { 'U', "trace_info", &do_trace_info
, 1 },
12173 { 'u', "trace_abbrev", &do_trace_abbrevs
, 1 },
12174 { 0, NULL
, NULL
, 0 }
12177 /* Enable display of specific DWARF sections as determined by the comma
12178 separated strings in NAMES. Returns non-zero if any displaying was
12182 dwarf_select_sections_by_names (const char *names
)
12190 const debug_dump_long_opts
*entry
;
12192 for (entry
= debug_option_table
; entry
->option
; entry
++)
12194 size_t len
= strlen (entry
->option
);
12196 if (strncmp (p
, entry
->option
, len
) == 0
12197 && (p
[len
] == ',' || p
[len
] == '\0'))
12199 if (entry
->val
== 0)
12200 * entry
->variable
= 0;
12202 * entry
->variable
= entry
->val
;
12203 result
|= entry
->val
;
12210 if (entry
->option
== NULL
)
12212 warn (_("Unrecognized debug option '%s'\n"), p
);
12213 p
= strchr (p
, ',');
12222 /* The --debug-dump=frames-interp option also enables the
12223 --debug-dump=frames option. */
12224 if (do_debug_frames_interp
)
12225 do_debug_frames
= 1;
12230 /* Enable display of specific DWARF sections as determined by the characters
12231 in LETTERS. Returns non-zero if any displaying was enabled. */
12234 dwarf_select_sections_by_letters (const char *letters
)
12240 const debug_dump_long_opts
*entry
;
12242 for (entry
= debug_option_table
; entry
->letter
; entry
++)
12244 if (entry
->letter
== * letters
)
12246 if (entry
->val
== 0)
12247 * entry
->variable
= 0;
12249 * entry
->variable
|= entry
->val
;
12250 result
|= entry
->val
;
12255 if (entry
->letter
== 0)
12256 warn (_("Unrecognized debug letter option '%c'\n"), * letters
);
12261 /* The --debug-dump=frames-interp option also enables the
12262 --debug-dump=frames option. */
12263 if (do_debug_frames_interp
)
12264 do_debug_frames
= 1;
12270 dwarf_select_sections_all (void)
12273 do_debug_abbrevs
= 1;
12274 do_debug_lines
= FLAG_DEBUG_LINES_RAW
;
12275 do_debug_pubnames
= 1;
12276 do_debug_pubtypes
= 1;
12277 do_debug_aranges
= 1;
12278 do_debug_ranges
= 1;
12279 do_debug_frames
= 1;
12280 do_debug_macinfo
= 1;
12285 do_trace_abbrevs
= 1;
12286 do_trace_aranges
= 1;
12288 do_debug_cu_index
= 1;
12289 do_follow_links
= 1;
12290 do_debug_links
= 1;
12291 do_debug_str_offsets
= 1;
12294 #define NO_ABBREVS NULL, NULL, NULL, 0, 0, 0, NULL, 0
12295 #define ABBREV(N) NULL, NULL, NULL, 0, 0, N, NULL, 0
12297 /* N.B. The order here must match the order in section_display_enum. */
12299 struct dwarf_section_display debug_displays
[] =
12301 { { ".debug_abbrev", ".zdebug_abbrev", ".dwabrev", NO_ABBREVS
}, display_debug_abbrev
, &do_debug_abbrevs
, false },
12302 { { ".debug_aranges", ".zdebug_aranges", ".dwarnge", NO_ABBREVS
}, display_debug_aranges
, &do_debug_aranges
, true },
12303 { { ".debug_frame", ".zdebug_frame", ".dwframe", NO_ABBREVS
}, display_debug_frames
, &do_debug_frames
, true },
12304 { { ".debug_info", ".zdebug_info", ".dwinfo", ABBREV (abbrev
)}, display_debug_info
, &do_debug_info
, true },
12305 { { ".debug_line", ".zdebug_line", ".dwline", NO_ABBREVS
}, display_debug_lines
, &do_debug_lines
, true },
12306 { { ".debug_pubnames", ".zdebug_pubnames", ".dwpbnms", NO_ABBREVS
}, display_debug_pubnames
, &do_debug_pubnames
, false },
12307 { { ".debug_gnu_pubnames", ".zdebug_gnu_pubnames", "", NO_ABBREVS
}, display_debug_gnu_pubnames
, &do_debug_pubnames
, false },
12308 { { ".eh_frame", "", "", NO_ABBREVS
}, display_debug_frames
, &do_debug_frames
, true },
12309 { { ".debug_macinfo", ".zdebug_macinfo", "", NO_ABBREVS
}, display_debug_macinfo
, &do_debug_macinfo
, false },
12310 { { ".debug_macro", ".zdebug_macro", ".dwmac", NO_ABBREVS
}, display_debug_macro
, &do_debug_macinfo
, true },
12311 { { ".debug_str", ".zdebug_str", ".dwstr", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, false },
12312 { { ".debug_line_str", ".zdebug_line_str", "", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, false },
12313 { { ".debug_loc", ".zdebug_loc", ".dwloc", NO_ABBREVS
}, display_debug_loc
, &do_debug_loc
, true },
12314 { { ".debug_loclists", ".zdebug_loclists", "", NO_ABBREVS
}, display_debug_loc
, &do_debug_loc
, true },
12315 { { ".debug_loclists.dwo", ".zdebug_loclists.dwo", "", NO_ABBREVS
}, display_debug_loc
, &do_debug_loc
, true },
12316 { { ".debug_pubtypes", ".zdebug_pubtypes", ".dwpbtyp", NO_ABBREVS
}, display_debug_pubnames
, &do_debug_pubtypes
, false },
12317 { { ".debug_gnu_pubtypes", ".zdebug_gnu_pubtypes", "", NO_ABBREVS
}, display_debug_gnu_pubnames
, &do_debug_pubtypes
, false },
12318 { { ".debug_ranges", ".zdebug_ranges", ".dwrnges", NO_ABBREVS
}, display_debug_ranges
, &do_debug_ranges
, true },
12319 { { ".debug_rnglists", ".zdebug_rnglists", "", NO_ABBREVS
}, display_debug_ranges
, &do_debug_ranges
, true },
12320 { { ".debug_rnglists.dwo", ".zdebug_rnglists.dwo", "", NO_ABBREVS
}, display_debug_ranges
, &do_debug_ranges
, true },
12321 { { ".debug_static_func", ".zdebug_static_func", "", NO_ABBREVS
}, display_debug_not_supported
, NULL
, false },
12322 { { ".debug_static_vars", ".zdebug_static_vars", "", NO_ABBREVS
}, display_debug_not_supported
, NULL
, false },
12323 { { ".debug_types", ".zdebug_types", "", ABBREV (abbrev
) }, display_debug_types
, &do_debug_info
, true },
12324 { { ".debug_weaknames", ".zdebug_weaknames", "", NO_ABBREVS
}, display_debug_not_supported
, NULL
, false },
12325 { { ".gdb_index", "", "", NO_ABBREVS
}, display_gdb_index
, &do_gdb_index
, false },
12326 { { ".debug_names", "", "", NO_ABBREVS
}, display_debug_names
, &do_gdb_index
, false },
12327 { { ".trace_info", "", "", ABBREV (trace_abbrev
) }, display_trace_info
, &do_trace_info
, true },
12328 { { ".trace_abbrev", "", "", NO_ABBREVS
}, display_debug_abbrev
, &do_trace_abbrevs
, false },
12329 { { ".trace_aranges", "", "", NO_ABBREVS
}, display_debug_aranges
, &do_trace_aranges
, false },
12330 { { ".debug_info.dwo", ".zdebug_info.dwo", "", ABBREV (abbrev_dwo
) }, display_debug_info
, &do_debug_info
, true },
12331 { { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo", "", NO_ABBREVS
}, display_debug_abbrev
, &do_debug_abbrevs
, false },
12332 { { ".debug_types.dwo", ".zdebug_types.dwo", "", ABBREV (abbrev_dwo
) }, display_debug_types
, &do_debug_info
, true },
12333 { { ".debug_line.dwo", ".zdebug_line.dwo", "", NO_ABBREVS
}, display_debug_lines
, &do_debug_lines
, true },
12334 { { ".debug_loc.dwo", ".zdebug_loc.dwo", "", NO_ABBREVS
}, display_debug_loc
, &do_debug_loc
, true },
12335 { { ".debug_macro.dwo", ".zdebug_macro.dwo", "", NO_ABBREVS
}, display_debug_macro
, &do_debug_macinfo
, true },
12336 { { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo", "", NO_ABBREVS
}, display_debug_macinfo
, &do_debug_macinfo
, false },
12337 { { ".debug_str.dwo", ".zdebug_str.dwo", "", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, true },
12338 { { ".debug_str_offsets", ".zdebug_str_offsets", "", NO_ABBREVS
}, display_debug_str_offsets
, &do_debug_str_offsets
, true },
12339 { { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo", "", NO_ABBREVS
}, display_debug_str_offsets
, &do_debug_str_offsets
, true },
12340 { { ".debug_addr", ".zdebug_addr", "", NO_ABBREVS
}, display_debug_addr
, &do_debug_addr
, true },
12341 { { ".debug_cu_index", "", "", NO_ABBREVS
}, display_cu_index
, &do_debug_cu_index
, false },
12342 { { ".debug_tu_index", "", "", NO_ABBREVS
}, display_cu_index
, &do_debug_cu_index
, false },
12343 { { ".gnu_debuglink", "", "", NO_ABBREVS
}, display_debug_links
, &do_debug_links
, false },
12344 { { ".gnu_debugaltlink", "", "", NO_ABBREVS
}, display_debug_links
, &do_debug_links
, false },
12345 { { ".debug_sup", "", "", NO_ABBREVS
}, display_debug_sup
, &do_debug_links
, false },
12346 /* Separate debug info files can containt their own .debug_str section,
12347 and this might be in *addition* to a .debug_str section already present
12348 in the main file. Hence we need to have two entries for .debug_str. */
12349 { { ".debug_str", ".zdebug_str", "", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, false },
12350 { { ".note.gnu.build-id", "", "", NO_ABBREVS
}, display_debug_not_supported
, NULL
, false },
12353 /* A static assertion. */
12354 extern int debug_displays_assert
[ARRAY_SIZE (debug_displays
) == max
? 1 : -1];