1 /* dwarf.c -- display DWARF contents of a BFD binary file
2 Copyright (C) 2005-2025 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 frame_base_level
= -1; /* To support nested DW_TAG_subprogram's. */
58 static int need_base_address
;
60 static unsigned int num_debug_info_entries
= 0;
61 static unsigned int alloc_num_debug_info_entries
= 0;
62 static debug_info
*debug_information
= NULL
;
63 /* Special value for num_debug_info_entries to indicate
64 that the .debug_info section could not be loaded/parsed. */
65 #define DEBUG_INFO_UNAVAILABLE (unsigned int) -1
67 /* A .debug_info section can contain multiple links to separate
68 DWO object files. We use these structures to record these links. */
76 typedef struct dwo_info
81 struct dwo_info
* next
;
84 static dwo_info
*first_dwo_info
= NULL
;
85 static bool need_dwo_info
;
87 separate_info
* first_separate_info
= NULL
;
89 unsigned int eh_addr_size
;
94 int do_debug_pubnames
;
95 int do_debug_pubtypes
;
99 int do_debug_frames_interp
;
100 int do_debug_macinfo
;
102 int do_debug_str_offsets
;
106 int do_trace_abbrevs
;
107 int do_trace_aranges
;
109 int do_debug_cu_index
;
112 int do_follow_links
= DEFAULT_FOR_FOLLOW_LINKS
;
113 #ifdef HAVE_LIBDEBUGINFOD
114 int use_debuginfod
= 1;
118 int dwarf_cutoff_level
= -1;
119 unsigned long dwarf_start_die
;
123 /* Collection of CU/TU section sets from .debug_cu_index and .debug_tu_index
124 sections. For version 1 package files, each set is stored in SHNDX_POOL
125 as a zero-terminated list of section indexes comprising one set of debug
126 sections from a .dwo file. */
128 static unsigned int *shndx_pool
= NULL
;
129 static unsigned int shndx_pool_size
= 0;
130 static unsigned int shndx_pool_used
= 0;
132 /* For version 2 package files, each set contains an array of section offsets
133 and an array of section sizes, giving the offset and size of the
134 contribution from a CU or TU within one of the debug sections.
135 When displaying debug info from a package file, we need to use these
136 tables to locate the corresponding contributions to each section. */
141 uint64_t section_offsets
[DW_SECT_MAX
];
142 size_t section_sizes
[DW_SECT_MAX
];
145 static int cu_count
= 0;
146 static int tu_count
= 0;
147 static struct cu_tu_set
*cu_sets
= NULL
;
148 static struct cu_tu_set
*tu_sets
= NULL
;
150 static bool load_cu_tu_indexes (void *);
152 /* An array that indicates for a given level of CU nesting whether
153 the latest DW_AT_type seen for that level was a signed type or
155 #define MAX_CU_NESTING (1 << 8)
156 static bool level_type_signed
[MAX_CU_NESTING
];
158 /* Values for do_debug_lines. */
159 #define FLAG_DEBUG_LINES_RAW 1
160 #define FLAG_DEBUG_LINES_DECODED 2
163 size_of_encoded_value (int encoding
)
165 switch (encoding
& 0x7)
168 case 0: return eh_addr_size
;
176 get_encoded_value (unsigned char **pdata
,
178 struct dwarf_section
*section
,
181 unsigned char * data
= * pdata
;
182 unsigned int size
= size_of_encoded_value (encoding
);
185 if (data
>= end
|| size
> (size_t) (end
- data
))
187 warn (_("Encoded value extends past end of section\n"));
192 /* PR 17512: file: 002-829853-0.004. */
195 warn (_("Encoded size of %d is too large to read\n"), size
);
200 /* PR 17512: file: 1085-5603-0.004. */
203 warn (_("Encoded size of 0 is too small to read\n"));
208 if (encoding
& DW_EH_PE_signed
)
209 val
= byte_get_signed (data
, size
);
211 val
= byte_get (data
, size
);
213 if ((encoding
& 0x70) == DW_EH_PE_pcrel
)
214 val
+= section
->address
+ (data
- section
->start
);
216 * pdata
= data
+ size
;
220 /* Print a uint64_t value (typically an address, offset or length) in
221 hexadecimal format, followed by a space. The precision displayed is
222 determined by the NUM_BYTES parameter. */
225 print_hex (uint64_t value
, unsigned num_bytes
)
230 printf ("%0*" PRIx64
" ", num_bytes
* 2,
231 value
& ~(~(uint64_t) 0 << num_bytes
* 4 << num_bytes
* 4));
234 /* Like print_hex, but no trailing space. */
237 print_hex_ns (uint64_t value
, unsigned num_bytes
)
242 printf ("%0*" PRIx64
, num_bytes
* 2,
243 value
& ~(~(uint64_t) 0 << num_bytes
* 4 << num_bytes
* 4));
246 /* Print a view number in hexadecimal value, with the same width as
247 print_hex would have printed it. */
250 print_view (uint64_t value
, unsigned num_bytes
)
255 printf ("v%0*" PRIx64
" ", num_bytes
* 2 - 1,
256 value
& ~(~(uint64_t) 0 << num_bytes
* 4 << num_bytes
* 4));
260 null_name (const char *p
)
267 /* Read in a LEB128 encoded value starting at address DATA.
268 If SIGN is true, return a signed LEB128 value.
269 If LENGTH_RETURN is not NULL, return in it the number of bytes read.
270 If STATUS_RETURN is not NULL, return with bit 0 (LSB) set if the
271 terminating byte was not found and with bit 1 set if the value
272 overflows a uint64_t.
273 No bytes will be read at address END or beyond. */
276 read_leb128 (unsigned char *data
,
277 const unsigned char *const end
,
279 unsigned int *length_return
,
283 unsigned int num_read
= 0;
284 unsigned int shift
= 0;
289 unsigned char byte
= *data
++;
290 unsigned char lost
, mask
;
294 if (shift
< CHAR_BIT
* sizeof (result
))
296 result
|= ((uint64_t) (byte
& 0x7f)) << shift
;
297 /* These bits overflowed. */
298 lost
= byte
^ (result
>> shift
);
299 /* And this is the mask of possible overflow bits. */
300 mask
= 0x7f ^ ((uint64_t) 0x7f << shift
>> shift
);
308 if ((lost
& mask
) != (sign
&& (int64_t) result
< 0 ? mask
: 0))
311 if ((byte
& 0x80) == 0)
314 if (sign
&& shift
< CHAR_BIT
* sizeof (result
) && (byte
& 0x40))
315 result
|= -((uint64_t) 1 << shift
);
320 if (length_return
!= NULL
)
321 *length_return
= num_read
;
322 if (status_return
!= NULL
)
323 *status_return
= status
;
328 /* Read AMOUNT bytes from PTR and store them in VAL.
329 Checks to make sure that the read will not reach or pass END.
330 FUNC chooses whether the value read is unsigned or signed, and may
331 be either byte_get or byte_get_signed. If INC is true, PTR is
332 incremented after reading the value.
333 This macro cannot protect against PTR values derived from user input.
334 The C standard sections 6.5.6 and 6.5.8 say attempts to do so using
335 pointers is undefined behaviour. */
336 #define SAFE_BYTE_GET_INTERNAL(VAL, PTR, AMOUNT, END, FUNC, INC) \
339 size_t amount = (AMOUNT); \
340 if (sizeof (VAL) < amount) \
342 error (ngettext ("internal error: attempt to read %d byte " \
343 "of data in to %d sized variable", \
344 "internal error: attempt to read %d bytes " \
345 "of data in to %d sized variable", \
347 (int) amount, (int) sizeof (VAL)); \
348 amount = sizeof (VAL); \
350 if (ENABLE_CHECKING) \
351 assert ((PTR) <= (END)); \
352 size_t avail = (END) - (PTR); \
355 if (amount > avail) \
360 (VAL) = (FUNC) ((PTR), amount); \
366 #define SAFE_BYTE_GET(VAL, PTR, AMOUNT, END) \
367 SAFE_BYTE_GET_INTERNAL (VAL, PTR, AMOUNT, END, byte_get, false)
369 #define SAFE_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \
370 SAFE_BYTE_GET_INTERNAL (VAL, PTR, AMOUNT, END, byte_get, true)
372 #define SAFE_SIGNED_BYTE_GET(VAL, PTR, AMOUNT, END) \
373 SAFE_BYTE_GET_INTERNAL (VAL, PTR, AMOUNT, END, byte_get_signed, false)
375 #define SAFE_SIGNED_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \
376 SAFE_BYTE_GET_INTERNAL (VAL, PTR, AMOUNT, END, byte_get_signed, true)
378 typedef struct State_Machine_Registers
387 unsigned char op_index
;
388 unsigned char end_sequence
;
389 /* This variable hold the number of the last entry seen
390 in the File Table. */
391 unsigned int last_file_entry
;
394 static SMR state_machine_regs
;
397 reset_state_machine (int is_stmt
)
399 state_machine_regs
.address
= 0;
400 state_machine_regs
.view
= 0;
401 state_machine_regs
.op_index
= 0;
402 state_machine_regs
.file
= 1;
403 state_machine_regs
.line
= 1;
404 state_machine_regs
.column
= 0;
405 state_machine_regs
.is_stmt
= is_stmt
;
406 state_machine_regs
.basic_block
= 0;
407 state_machine_regs
.end_sequence
= 0;
408 state_machine_regs
.last_file_entry
= 0;
411 /* Handled an extend line op.
412 Returns the number of bytes read. */
415 process_extended_line_op (unsigned char * data
,
419 unsigned char op_code
;
420 size_t len
, header_len
;
422 unsigned char *orig_data
= data
;
425 READ_ULEB (len
, data
, end
);
426 header_len
= data
- orig_data
;
428 if (len
== 0 || data
>= end
|| len
> (size_t) (end
- data
))
430 warn (_("Badly formed extended line op encountered!\n"));
436 printf (_(" Extended opcode %d: "), op_code
);
440 case DW_LNE_end_sequence
:
441 printf (_("End of Sequence\n\n"));
442 reset_state_machine (is_stmt
);
445 case DW_LNE_set_address
:
446 /* PR 17512: file: 002-100480-0.004. */
449 warn (_("Length (%zu) of DW_LNE_set_address op is too long\n"),
454 SAFE_BYTE_GET (adr
, data
, len
- 1, end
);
455 printf (_("set Address to %#" PRIx64
"\n"), adr
);
456 state_machine_regs
.address
= adr
;
457 state_machine_regs
.view
= 0;
458 state_machine_regs
.op_index
= 0;
461 case DW_LNE_define_file
:
462 printf (_("define new File Table entry\n"));
463 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
464 printf (" %d\t", ++state_machine_regs
.last_file_entry
);
470 l
= strnlen ((char *) data
, end
- data
);
474 READ_ULEB (val
, data
, end
);
475 printf ("%" PRIu64
"\t", val
);
476 READ_ULEB (val
, data
, end
);
477 printf ("%" PRIu64
"\t", val
);
478 READ_ULEB (val
, data
, end
);
479 printf ("%" PRIu64
"\t", val
);
480 printf ("%.*s\n\n", (int) l
, name
);
483 if (((size_t) (data
- orig_data
) != len
+ header_len
) || data
>= end
)
484 warn (_("DW_LNE_define_file: Bad opcode length\n"));
487 case DW_LNE_set_discriminator
:
488 READ_ULEB (val
, data
, end
);
489 printf (_("set Discriminator to %" PRIu64
"\n"), val
);
493 case DW_LNE_HP_negate_is_UV_update
:
494 printf ("DW_LNE_HP_negate_is_UV_update\n");
496 case DW_LNE_HP_push_context
:
497 printf ("DW_LNE_HP_push_context\n");
499 case DW_LNE_HP_pop_context
:
500 printf ("DW_LNE_HP_pop_context\n");
502 case DW_LNE_HP_set_file_line_column
:
503 printf ("DW_LNE_HP_set_file_line_column\n");
505 case DW_LNE_HP_set_routine_name
:
506 printf ("DW_LNE_HP_set_routine_name\n");
508 case DW_LNE_HP_set_sequence
:
509 printf ("DW_LNE_HP_set_sequence\n");
511 case DW_LNE_HP_negate_post_semantics
:
512 printf ("DW_LNE_HP_negate_post_semantics\n");
514 case DW_LNE_HP_negate_function_exit
:
515 printf ("DW_LNE_HP_negate_function_exit\n");
517 case DW_LNE_HP_negate_front_end_logical
:
518 printf ("DW_LNE_HP_negate_front_end_logical\n");
520 case DW_LNE_HP_define_proc
:
521 printf ("DW_LNE_HP_define_proc\n");
523 case DW_LNE_HP_source_file_correlation
:
525 unsigned char *edata
= data
+ len
- 1;
527 printf ("DW_LNE_HP_source_file_correlation\n");
533 READ_ULEB (opc
, data
, edata
);
537 case DW_LNE_HP_SFC_formfeed
:
538 printf (" DW_LNE_HP_SFC_formfeed\n");
540 case DW_LNE_HP_SFC_set_listing_line
:
541 READ_ULEB (val
, data
, edata
);
542 printf (" DW_LNE_HP_SFC_set_listing_line (%" PRIu64
")\n",
545 case DW_LNE_HP_SFC_associate
:
546 printf (" DW_LNE_HP_SFC_associate ");
547 READ_ULEB (val
, data
, edata
);
548 printf ("(%" PRIu64
, val
);
549 READ_ULEB (val
, data
, edata
);
550 printf (",%" PRIu64
, val
);
551 READ_ULEB (val
, data
, edata
);
552 printf (",%" PRIu64
")\n", val
);
555 printf (_(" UNKNOWN DW_LNE_HP_SFC opcode (%u)\n"), opc
);
565 unsigned int rlen
= len
- 1;
567 if (op_code
>= DW_LNE_lo_user
568 /* The test against DW_LNW_hi_user is redundant due to
569 the limited range of the unsigned char data type used
571 /*&& op_code <= DW_LNE_hi_user*/)
572 printf (_("user defined: "));
574 printf (_("UNKNOWN: "));
575 printf (_("length %d ["), rlen
);
577 printf (" %02x", *data
++);
583 return len
+ header_len
;
586 static const unsigned char *
587 fetch_indirect_string (uint64_t offset
)
589 struct dwarf_section
*section
= &debug_displays
[str
].section
;
590 const unsigned char * ret
;
592 if (section
->start
== NULL
)
593 return (const unsigned char *) _("<no .debug_str section>");
595 if (offset
>= section
->size
)
597 warn (_("DW_FORM_strp offset too big: %#" PRIx64
"\n"), offset
);
598 return (const unsigned char *) _("<offset is too big>");
601 ret
= section
->start
+ offset
;
602 /* Unfortunately we cannot rely upon the .debug_str section ending with a
603 NUL byte. Since our caller is expecting to receive a well formed C
604 string we test for the lack of a terminating byte here. */
605 if (strnlen ((const char *) ret
, section
->size
- offset
)
606 == section
->size
- offset
)
607 ret
= (const unsigned char *)
608 _("<no NUL byte at end of .debug_str section>");
613 static const unsigned char *
614 fetch_indirect_line_string (uint64_t offset
)
616 struct dwarf_section
*section
= &debug_displays
[line_str
].section
;
617 const unsigned char * ret
;
619 if (section
->start
== NULL
)
620 return (const unsigned char *) _("<no .debug_line_str section>");
622 if (offset
>= section
->size
)
624 warn (_("DW_FORM_line_strp offset too big: %#" PRIx64
"\n"), offset
);
625 return (const unsigned char *) _("<offset is too big>");
628 ret
= section
->start
+ offset
;
629 /* Unfortunately we cannot rely upon the .debug_line_str section ending
630 with a NUL byte. Since our caller is expecting to receive a well formed
631 C string we test for the lack of a terminating byte here. */
632 if (strnlen ((const char *) ret
, section
->size
- offset
)
633 == section
->size
- offset
)
634 ret
= (const unsigned char *)
635 _("<no NUL byte at end of .debug_line_str section>");
641 fetch_indexed_string (uint64_t idx
,
642 struct cu_tu_set
*this_set
,
643 uint64_t offset_size
,
645 uint64_t str_offsets_base
)
647 enum dwarf_section_display_enum str_sec_idx
= dwo
? str_dwo
: str
;
648 enum dwarf_section_display_enum idx_sec_idx
= dwo
? str_index_dwo
: str_index
;
649 struct dwarf_section
*index_section
= &debug_displays
[idx_sec_idx
].section
;
650 struct dwarf_section
*str_section
= &debug_displays
[str_sec_idx
].section
;
651 uint64_t index_offset
;
655 if (index_section
->start
== NULL
)
656 return (dwo
? _("<no .debug_str_offsets.dwo section>")
657 : _("<no .debug_str_offsets section>"));
659 if (str_section
->start
== NULL
)
660 return (dwo
? _("<no .debug_str.dwo section>")
661 : _("<no .debug_str section>"));
663 if (_mul_overflow (idx
, offset_size
, &index_offset
)
665 && ((index_offset
+= this_set
->section_offsets
[DW_SECT_STR_OFFSETS
])
666 < this_set
->section_offsets
[DW_SECT_STR_OFFSETS
]))
667 || (index_offset
+= str_offsets_base
) < str_offsets_base
668 || index_offset
+ offset_size
< offset_size
669 || 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\n"),
673 idx
, index_offset
, str_section
->name
);
675 return _("<string index too big>");
678 str_offset
= byte_get (index_section
->start
+ index_offset
, offset_size
);
680 if (str_offset
>= str_section
->size
)
682 warn (_("indirect offset too big: %#" PRIx64
"\n"), str_offset
);
683 return _("<indirect index offset is too big>");
686 ret
= (const char *) str_section
->start
+ str_offset
;
688 /* Unfortunately we cannot rely upon str_section ending with a NUL byte.
689 Since our caller is expecting to receive a well formed C string we test
690 for the lack of a terminating byte here. */
691 if (strnlen (ret
, str_section
->size
- str_offset
)
692 == str_section
->size
- str_offset
)
693 return _("<no NUL byte at end of section>");
699 fetch_indexed_addr (uint64_t offset
, uint32_t num_bytes
)
701 struct dwarf_section
*section
= &debug_displays
[debug_addr
].section
;
703 if (section
->start
== NULL
)
705 warn (_("Cannot fetch indexed address: the .debug_addr section is missing\n"));
709 if (offset
+ num_bytes
> section
->size
)
711 warn (_("Offset into section %s too big: %#" PRIx64
"\n"),
712 section
->name
, offset
);
716 return byte_get (section
->start
+ offset
, num_bytes
);
719 /* This is for resolving DW_FORM_rnglistx and DW_FORM_loclistx.
721 The memory layout is: base_address (taken from the CU's top DIE) points at a table of offsets,
722 relative to the section start.
723 The table of offsets contains the offsets of objects of interest relative to the table of offsets.
724 IDX is the index of the desired object in said table of offsets.
726 This returns the offset of the desired object relative to the section start or -1 upon failure. */
729 fetch_indexed_offset (uint64_t idx
,
730 enum dwarf_section_display_enum sec_enum
,
731 uint64_t base_address
,
732 uint64_t offset_size
)
734 uint64_t offset_of_offset
= base_address
+ idx
* offset_size
;
735 struct dwarf_section
*section
= &debug_displays
[sec_enum
].section
;
737 if (section
->start
== NULL
)
739 warn (_("Unable to locate %s section\n"), section
->uncompressed_name
);
743 if (section
->size
< 4)
745 warn (_("Section %s is too small to contain an value indexed from another section!\n"),
750 if (offset_of_offset
+ offset_size
>= section
->size
)
752 warn (_("Offset of %#" PRIx64
" is too big for section %s\n"),
753 offset_of_offset
, section
->name
);
757 return base_address
+ byte_get (section
->start
+ offset_of_offset
, offset_size
);
760 /* FIXME: There are better and more efficient ways to handle
761 these structures. For now though, I just want something that
762 is simple to implement. */
763 /* Records a single attribute in an abbrev. */
764 typedef struct abbrev_attr
766 unsigned long attribute
;
768 int64_t implicit_const
;
769 struct abbrev_attr
*next
;
773 /* Records a single abbrev. */
774 typedef struct abbrev_entry
776 unsigned long number
;
779 struct abbrev_attr
* first_attr
;
780 struct abbrev_attr
* last_attr
;
781 struct abbrev_entry
* next
;
785 /* Records a set of abbreviations. */
786 typedef struct abbrev_list
788 abbrev_entry
* first_abbrev
;
789 abbrev_entry
* last_abbrev
;
791 struct abbrev_list
* next
;
792 unsigned char * start_of_next_abbrevs
;
796 /* Records all the abbrevs found so far. */
797 static struct abbrev_list
* abbrev_lists
= NULL
;
799 typedef struct abbrev_map
806 /* Maps between CU offsets and abbrev sets. */
807 static abbrev_map
* cu_abbrev_map
= NULL
;
808 static unsigned long num_abbrev_map_entries
= 0;
809 static unsigned long next_free_abbrev_map_entry
= 0;
811 #define INITIAL_NUM_ABBREV_MAP_ENTRIES 8
812 #define ABBREV_MAP_ENTRIES_INCREMENT 8
815 record_abbrev_list_for_cu (uint64_t start
, uint64_t end
,
816 abbrev_list
*list
, abbrev_list
*free_list
)
818 if (free_list
!= NULL
)
820 list
->next
= abbrev_lists
;
824 if (cu_abbrev_map
== NULL
)
826 num_abbrev_map_entries
= INITIAL_NUM_ABBREV_MAP_ENTRIES
;
827 cu_abbrev_map
= xmalloc (num_abbrev_map_entries
* sizeof (* cu_abbrev_map
));
829 else if (next_free_abbrev_map_entry
== num_abbrev_map_entries
)
831 num_abbrev_map_entries
+= ABBREV_MAP_ENTRIES_INCREMENT
;
832 cu_abbrev_map
= xrealloc (cu_abbrev_map
, num_abbrev_map_entries
* sizeof (* cu_abbrev_map
));
835 cu_abbrev_map
[next_free_abbrev_map_entry
].start
= start
;
836 cu_abbrev_map
[next_free_abbrev_map_entry
].end
= end
;
837 cu_abbrev_map
[next_free_abbrev_map_entry
].list
= list
;
838 next_free_abbrev_map_entry
++;
842 free_abbrev_list (abbrev_list
*list
)
844 abbrev_entry
*abbrv
= list
->first_abbrev
;
848 abbrev_attr
*attr
= abbrv
->first_attr
;
852 abbrev_attr
*next_attr
= attr
->next
;
857 abbrev_entry
*next_abbrev
= abbrv
->next
;
862 abbrev_list
*next
= list
->next
;
868 free_all_abbrevs (void)
871 abbrev_lists
= free_abbrev_list (abbrev_lists
);
873 free (cu_abbrev_map
);
874 cu_abbrev_map
= NULL
;
875 next_free_abbrev_map_entry
= 0;
879 find_abbrev_list_by_raw_abbrev (unsigned char *raw
)
883 for (list
= abbrev_lists
; list
!= NULL
; list
= list
->next
)
884 if (list
->raw
== raw
)
890 /* Find the abbreviation map for the CU that includes OFFSET.
891 OFFSET is an absolute offset from the start of the .debug_info section. */
892 /* FIXME: This function is going to slow down readelf & objdump.
893 Not caching abbrevs is likely the answer. */
896 find_abbrev_map_by_offset (uint64_t offset
)
900 for (i
= 0; i
< next_free_abbrev_map_entry
; i
++)
901 if (cu_abbrev_map
[i
].start
<= offset
902 && cu_abbrev_map
[i
].end
> offset
)
903 return cu_abbrev_map
+ i
;
909 add_abbrev (unsigned long number
,
914 abbrev_entry
* entry
;
916 entry
= (abbrev_entry
*) xmalloc (sizeof (*entry
));
918 entry
->number
= number
;
920 entry
->children
= children
;
921 entry
->first_attr
= NULL
;
922 entry
->last_attr
= NULL
;
925 assert (list
!= NULL
);
927 if (list
->first_abbrev
== NULL
)
928 list
->first_abbrev
= entry
;
930 list
->last_abbrev
->next
= entry
;
932 list
->last_abbrev
= entry
;
936 add_abbrev_attr (unsigned long attribute
,
938 int64_t implicit_const
,
943 attr
= (abbrev_attr
*) xmalloc (sizeof (*attr
));
945 attr
->attribute
= attribute
;
947 attr
->implicit_const
= implicit_const
;
950 assert (list
!= NULL
&& list
->last_abbrev
!= NULL
);
952 if (list
->last_abbrev
->first_attr
== NULL
)
953 list
->last_abbrev
->first_attr
= attr
;
955 list
->last_abbrev
->last_attr
->next
= attr
;
957 list
->last_abbrev
->last_attr
= attr
;
960 /* Return processed (partial) contents of a .debug_abbrev section.
961 Returns NULL on errors. */
964 process_abbrev_set (struct dwarf_section
*section
,
965 unsigned char *start
,
968 abbrev_list
*list
= xmalloc (sizeof (*list
));
969 list
->first_abbrev
= NULL
;
970 list
->last_abbrev
= NULL
;
978 unsigned long attribute
;
981 READ_ULEB (entry
, start
, end
);
983 /* A single zero is supposed to end the set according
984 to the standard. If there's more, then signal that to
986 if (start
== end
|| entry
== 0)
988 list
->start_of_next_abbrevs
= start
!= end
? start
: NULL
;
992 READ_ULEB (tag
, start
, end
);
994 return free_abbrev_list (list
);
998 add_abbrev (entry
, tag
, children
, list
);
1003 /* Initialize it due to a false compiler warning. */
1004 int64_t implicit_const
= -1;
1006 READ_ULEB (attribute
, start
, end
);
1010 READ_ULEB (form
, start
, end
);
1014 if (form
== DW_FORM_implicit_const
)
1016 READ_SLEB (implicit_const
, start
, end
);
1021 add_abbrev_attr (attribute
, form
, implicit_const
, list
);
1023 while (attribute
!= 0);
1026 /* Report the missing single zero which ends the section. */
1027 error (_("%s section not zero terminated\n"), section
->name
);
1029 return free_abbrev_list (list
);
1032 /* Return a sequence of abbrevs in SECTION starting at ABBREV_BASE
1033 plus ABBREV_OFFSET and finishing at ABBREV_BASE + ABBREV_SIZE.
1034 If FREE_LIST is non-NULL search the already decoded abbrevs on
1035 abbrev_lists first and if found set *FREE_LIST to NULL. If
1036 searching doesn't find a matching abbrev, set *FREE_LIST to the
1037 newly allocated list. If FREE_LIST is NULL, no search is done and
1038 the returned abbrev_list is always newly allocated. */
1040 static abbrev_list
*
1041 find_and_process_abbrev_set (struct dwarf_section
*section
,
1042 uint64_t abbrev_base
,
1043 uint64_t abbrev_size
,
1044 uint64_t abbrev_offset
,
1045 abbrev_list
**free_list
)
1050 if (abbrev_base
>= section
->size
1051 || abbrev_size
> section
->size
- abbrev_base
)
1053 /* PR 17531: file:4bcd9ce9. */
1054 warn (_("Debug info is corrupted, abbrev size (%#" PRIx64
")"
1055 " is larger than abbrev section size (%#" PRIx64
")\n"),
1056 abbrev_base
+ abbrev_size
, section
->size
);
1059 if (abbrev_offset
>= abbrev_size
)
1061 warn (_("Debug info is corrupted, abbrev offset (%#" PRIx64
")"
1062 " is larger than abbrev section size (%#" PRIx64
")\n"),
1063 abbrev_offset
, abbrev_size
);
1067 unsigned char *start
= section
->start
+ abbrev_base
+ abbrev_offset
;
1068 unsigned char *end
= section
->start
+ abbrev_base
+ abbrev_size
;
1069 abbrev_list
*list
= NULL
;
1071 list
= find_abbrev_list_by_raw_abbrev (start
);
1074 list
= process_abbrev_set (section
, start
, end
);
1082 get_TAG_name (uint64_t tag
)
1084 const char *name
= NULL
;
1086 if ((unsigned int) tag
== tag
)
1087 name
= get_DW_TAG_name ((unsigned int) tag
);
1090 static char buffer
[100];
1092 if (tag
>= DW_TAG_lo_user
&& tag
<= DW_TAG_hi_user
)
1093 snprintf (buffer
, sizeof (buffer
),
1094 _("User TAG value: %#" PRIx64
), tag
);
1096 snprintf (buffer
, sizeof (buffer
),
1097 _("Unknown TAG value: %#" PRIx64
), tag
);
1105 get_FORM_name (unsigned long form
)
1107 const char *name
= NULL
;
1110 return "DW_FORM value: 0";
1112 if ((unsigned int) form
== form
)
1113 name
= get_DW_FORM_name ((unsigned int) form
);
1116 static char buffer
[100];
1118 snprintf (buffer
, sizeof (buffer
), _("Unknown FORM value: %lx"), form
);
1126 get_IDX_name (unsigned long idx
)
1128 const char *name
= NULL
;
1130 if ((unsigned int) idx
== idx
)
1131 name
= get_DW_IDX_name ((unsigned int) idx
);
1134 static char buffer
[100];
1136 snprintf (buffer
, sizeof (buffer
), _("Unknown IDX value: %lx"), idx
);
1143 static unsigned char *
1144 display_block (unsigned char *data
,
1146 const unsigned char * const end
, char delimiter
)
1150 printf (_("%c%" PRIu64
" byte block: "), delimiter
, length
);
1152 return (unsigned char *) end
;
1154 maxlen
= end
- data
;
1155 length
= length
> maxlen
? maxlen
: length
;
1158 printf ("%" PRIx64
" ", byte_get (data
++, 1));
1164 decode_location_expression (unsigned char * data
,
1165 unsigned int pointer_size
,
1166 unsigned int offset_size
,
1170 struct dwarf_section
* section
)
1175 unsigned char *end
= data
+ length
;
1176 int need_frame_base
= 0;
1185 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1186 printf ("DW_OP_addr: %" PRIx64
, uvalue
);
1189 printf ("DW_OP_deref");
1192 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1193 printf ("DW_OP_const1u: %" PRIu64
, uvalue
);
1196 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 1, end
);
1197 printf ("DW_OP_const1s: %" PRId64
, svalue
);
1200 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
1201 printf ("DW_OP_const2u: %" PRIu64
, uvalue
);
1204 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1205 printf ("DW_OP_const2s: %" PRId64
, svalue
);
1208 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1209 printf ("DW_OP_const4u: %" PRIu64
, uvalue
);
1212 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
1213 printf ("DW_OP_const4s: %" PRId64
, svalue
);
1216 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 8, end
);
1217 printf ("DW_OP_const8u: %" PRIu64
, uvalue
);
1220 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 8, end
);
1221 printf ("DW_OP_const8s: %" PRId64
, svalue
);
1224 READ_ULEB (uvalue
, data
, end
);
1225 printf ("DW_OP_constu: %" PRIu64
, uvalue
);
1228 READ_SLEB (svalue
, data
, end
);
1229 printf ("DW_OP_consts: %" PRId64
, svalue
);
1232 printf ("DW_OP_dup");
1235 printf ("DW_OP_drop");
1238 printf ("DW_OP_over");
1241 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1242 printf ("DW_OP_pick: %" PRIu64
, uvalue
);
1245 printf ("DW_OP_swap");
1248 printf ("DW_OP_rot");
1251 printf ("DW_OP_xderef");
1254 printf ("DW_OP_abs");
1257 printf ("DW_OP_and");
1260 printf ("DW_OP_div");
1263 printf ("DW_OP_minus");
1266 printf ("DW_OP_mod");
1269 printf ("DW_OP_mul");
1272 printf ("DW_OP_neg");
1275 printf ("DW_OP_not");
1278 printf ("DW_OP_or");
1281 printf ("DW_OP_plus");
1283 case DW_OP_plus_uconst
:
1284 READ_ULEB (uvalue
, data
, end
);
1285 printf ("DW_OP_plus_uconst: %" PRIu64
, uvalue
);
1288 printf ("DW_OP_shl");
1291 printf ("DW_OP_shr");
1294 printf ("DW_OP_shra");
1297 printf ("DW_OP_xor");
1300 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1301 printf ("DW_OP_bra: %" PRId64
, svalue
);
1304 printf ("DW_OP_eq");
1307 printf ("DW_OP_ge");
1310 printf ("DW_OP_gt");
1313 printf ("DW_OP_le");
1316 printf ("DW_OP_lt");
1319 printf ("DW_OP_ne");
1322 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1323 printf ("DW_OP_skip: %" PRId64
, svalue
);
1358 printf ("DW_OP_lit%d", op
- DW_OP_lit0
);
1393 printf ("DW_OP_reg%d (%s)", op
- DW_OP_reg0
,
1394 regname (op
- DW_OP_reg0
, 1));
1429 READ_SLEB (svalue
, data
, end
);
1430 printf ("DW_OP_breg%d (%s): %" PRId64
,
1431 op
- DW_OP_breg0
, regname (op
- DW_OP_breg0
, 1), svalue
);
1435 READ_ULEB (uvalue
, data
, end
);
1436 printf ("DW_OP_regx: %" PRIu64
" (%s)",
1437 uvalue
, regname (uvalue
, 1));
1440 need_frame_base
= 1;
1441 READ_SLEB (svalue
, data
, end
);
1442 printf ("DW_OP_fbreg: %" PRId64
, svalue
);
1445 READ_ULEB (uvalue
, data
, end
);
1446 READ_SLEB (svalue
, data
, end
);
1447 printf ("DW_OP_bregx: %" PRIu64
" (%s) %" PRId64
,
1448 uvalue
, regname (uvalue
, 1), svalue
);
1451 READ_ULEB (uvalue
, data
, end
);
1452 printf ("DW_OP_piece: %" PRIu64
, uvalue
);
1454 case DW_OP_deref_size
:
1455 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1456 printf ("DW_OP_deref_size: %" PRIu64
, uvalue
);
1458 case DW_OP_xderef_size
:
1459 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1460 printf ("DW_OP_xderef_size: %" PRIu64
, uvalue
);
1463 printf ("DW_OP_nop");
1466 /* DWARF 3 extensions. */
1467 case DW_OP_push_object_address
:
1468 printf ("DW_OP_push_object_address");
1471 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1472 this ought to be an 8-byte wide computation. */
1473 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1474 printf ("DW_OP_call2: <%#" PRIx64
">", svalue
+ cu_offset
);
1477 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1478 this ought to be an 8-byte wide computation. */
1479 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
1480 printf ("DW_OP_call4: <%#" PRIx64
">", svalue
+ cu_offset
);
1482 case DW_OP_call_ref
:
1483 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1484 this ought to be an 8-byte wide computation. */
1485 if (dwarf_version
== -1)
1487 printf (_("(DW_OP_call_ref in frame info)"));
1488 /* No way to tell where the next op is, so just bail. */
1489 return need_frame_base
;
1491 if (dwarf_version
== 2)
1493 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1497 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1499 printf ("DW_OP_call_ref: <%#" PRIx64
">", uvalue
);
1501 case DW_OP_form_tls_address
:
1502 printf ("DW_OP_form_tls_address");
1504 case DW_OP_call_frame_cfa
:
1505 printf ("DW_OP_call_frame_cfa");
1507 case DW_OP_bit_piece
:
1508 printf ("DW_OP_bit_piece: ");
1509 READ_ULEB (uvalue
, data
, end
);
1510 printf (_("size: %" PRIu64
" "), uvalue
);
1511 READ_ULEB (uvalue
, data
, end
);
1512 printf (_("offset: %" PRIu64
" "), uvalue
);
1515 /* DWARF 4 extensions. */
1516 case DW_OP_stack_value
:
1517 printf ("DW_OP_stack_value");
1520 case DW_OP_implicit_value
:
1521 printf ("DW_OP_implicit_value");
1522 READ_ULEB (uvalue
, data
, end
);
1523 data
= display_block (data
, uvalue
, end
, ' ');
1526 /* GNU extensions. */
1527 case DW_OP_GNU_push_tls_address
:
1528 printf (_("DW_OP_GNU_push_tls_address or DW_OP_HP_unknown"));
1530 case DW_OP_GNU_uninit
:
1531 printf ("DW_OP_GNU_uninit");
1532 /* FIXME: Is there data associated with this OP ? */
1534 case DW_OP_GNU_encoded_addr
:
1541 addr
= get_encoded_value (&data
, encoding
, section
, end
);
1543 printf ("DW_OP_GNU_encoded_addr: fmt:%02x addr:", encoding
);
1544 print_hex_ns (addr
, pointer_size
);
1547 case DW_OP_implicit_pointer
:
1548 case DW_OP_GNU_implicit_pointer
:
1549 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1550 this ought to be an 8-byte wide computation. */
1551 if (dwarf_version
== -1)
1553 printf (_("(%s in frame info)"),
1554 (op
== DW_OP_implicit_pointer
1555 ? "DW_OP_implicit_pointer"
1556 : "DW_OP_GNU_implicit_pointer"));
1557 /* No way to tell where the next op is, so just bail. */
1558 return need_frame_base
;
1560 if (dwarf_version
== 2)
1562 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1566 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1568 READ_SLEB (svalue
, data
, end
);
1569 printf ("%s: <%#" PRIx64
"> %" PRId64
,
1570 (op
== DW_OP_implicit_pointer
1571 ? "DW_OP_implicit_pointer" : "DW_OP_GNU_implicit_pointer"),
1574 case DW_OP_entry_value
:
1575 case DW_OP_GNU_entry_value
:
1576 READ_ULEB (uvalue
, data
, end
);
1577 /* PR 17531: file: 0cc9cd00. */
1578 if (uvalue
> (size_t) (end
- data
))
1579 uvalue
= end
- data
;
1580 printf ("%s: (", (op
== DW_OP_entry_value
1581 ? "DW_OP_entry_value" : "DW_OP_GNU_entry_value"));
1582 if (decode_location_expression (data
, pointer_size
, offset_size
,
1583 dwarf_version
, uvalue
,
1584 cu_offset
, section
))
1585 need_frame_base
= 1;
1589 case DW_OP_const_type
:
1590 case DW_OP_GNU_const_type
:
1591 READ_ULEB (uvalue
, data
, end
);
1592 printf ("%s: <%#" PRIx64
"> ",
1593 (op
== DW_OP_const_type
1594 ? "DW_OP_const_type" : "DW_OP_GNU_const_type"),
1595 cu_offset
+ uvalue
);
1596 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1597 data
= display_block (data
, uvalue
, end
, ' ');
1599 case DW_OP_regval_type
:
1600 case DW_OP_GNU_regval_type
:
1601 READ_ULEB (uvalue
, data
, end
);
1602 printf ("%s: %" PRIu64
" (%s)",
1603 (op
== DW_OP_regval_type
1604 ? "DW_OP_regval_type" : "DW_OP_GNU_regval_type"),
1605 uvalue
, regname (uvalue
, 1));
1606 READ_ULEB (uvalue
, data
, end
);
1607 printf (" <%#" PRIx64
">", cu_offset
+ uvalue
);
1609 case DW_OP_deref_type
:
1610 case DW_OP_GNU_deref_type
:
1611 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1612 printf ("%s: %" PRId64
,
1613 (op
== DW_OP_deref_type
1614 ? "DW_OP_deref_type" : "DW_OP_GNU_deref_type"),
1616 READ_ULEB (uvalue
, data
, end
);
1617 printf (" <%#" PRIx64
">", cu_offset
+ uvalue
);
1620 case DW_OP_GNU_convert
:
1621 READ_ULEB (uvalue
, data
, end
);
1622 printf ("%s <%#" PRIx64
">",
1623 (op
== DW_OP_convert
? "DW_OP_convert" : "DW_OP_GNU_convert"),
1624 uvalue
? cu_offset
+ uvalue
: uvalue
);
1626 case DW_OP_reinterpret
:
1627 case DW_OP_GNU_reinterpret
:
1628 READ_ULEB (uvalue
, data
, end
);
1629 printf ("%s <%#" PRIx64
">",
1630 (op
== DW_OP_reinterpret
1631 ? "DW_OP_reinterpret" : "DW_OP_GNU_reinterpret"),
1632 uvalue
? cu_offset
+ uvalue
: uvalue
);
1634 case DW_OP_GNU_parameter_ref
:
1635 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1636 printf ("DW_OP_GNU_parameter_ref: <%#" PRIx64
">",
1637 cu_offset
+ uvalue
);
1640 READ_ULEB (uvalue
, data
, end
);
1641 printf ("DW_OP_addrx <%#" PRIx64
">", uvalue
);
1643 case DW_OP_GNU_addr_index
:
1644 READ_ULEB (uvalue
, data
, end
);
1645 printf ("DW_OP_GNU_addr_index <%#" PRIx64
">", uvalue
);
1647 case DW_OP_GNU_const_index
:
1648 READ_ULEB (uvalue
, data
, end
);
1649 printf ("DW_OP_GNU_const_index <%#" PRIx64
">", uvalue
);
1651 case DW_OP_GNU_variable_value
:
1652 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1653 this ought to be an 8-byte wide computation. */
1654 if (dwarf_version
== -1)
1656 printf (_("(DW_OP_GNU_variable_value in frame info)"));
1657 /* No way to tell where the next op is, so just bail. */
1658 return need_frame_base
;
1660 if (dwarf_version
== 2)
1662 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1666 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1668 printf ("DW_OP_GNU_variable_value: <%#" PRIx64
">", uvalue
);
1671 /* HP extensions. */
1672 case DW_OP_HP_is_value
:
1673 printf ("DW_OP_HP_is_value");
1674 /* FIXME: Is there data associated with this OP ? */
1676 case DW_OP_HP_fltconst4
:
1677 printf ("DW_OP_HP_fltconst4");
1678 /* FIXME: Is there data associated with this OP ? */
1680 case DW_OP_HP_fltconst8
:
1681 printf ("DW_OP_HP_fltconst8");
1682 /* FIXME: Is there data associated with this OP ? */
1684 case DW_OP_HP_mod_range
:
1685 printf ("DW_OP_HP_mod_range");
1686 /* FIXME: Is there data associated with this OP ? */
1688 case DW_OP_HP_unmod_range
:
1689 printf ("DW_OP_HP_unmod_range");
1690 /* FIXME: Is there data associated with this OP ? */
1693 printf ("DW_OP_HP_tls");
1694 /* FIXME: Is there data associated with this OP ? */
1697 /* PGI (STMicroelectronics) extensions. */
1698 case DW_OP_PGI_omp_thread_num
:
1699 /* Pushes the thread number for the current thread as it would be
1700 returned by the standard OpenMP library function:
1701 omp_get_thread_num(). The "current thread" is the thread for
1702 which the expression is being evaluated. */
1703 printf ("DW_OP_PGI_omp_thread_num");
1707 if (op
>= DW_OP_lo_user
1708 && op
<= DW_OP_hi_user
)
1709 printf (_("(User defined location op %#x)"), op
);
1711 printf (_("(Unknown location op %#x)"), op
);
1712 /* No way to tell where the next op is, so just bail. */
1713 return need_frame_base
;
1716 /* Separate the ops. */
1721 return need_frame_base
;
1724 /* Find the CU or TU set corresponding to the given CU_OFFSET.
1725 This is used for DWARF package files. */
1727 static struct cu_tu_set
*
1728 find_cu_tu_set_v2 (uint64_t cu_offset
, int do_types
)
1730 struct cu_tu_set
*p
;
1732 unsigned int dw_sect
;
1738 dw_sect
= DW_SECT_TYPES
;
1744 dw_sect
= DW_SECT_INFO
;
1748 if (p
->section_offsets
[dw_sect
] == cu_offset
)
1757 fetch_alt_indirect_string (uint64_t offset
)
1761 if (! do_follow_links
)
1764 if (first_separate_info
== NULL
)
1765 return _("<no links available>");
1767 for (i
= first_separate_info
; i
!= NULL
; i
= i
->next
)
1769 struct dwarf_section
* section
;
1772 if (! load_debug_section (separate_debug_str
, i
->handle
))
1775 section
= &debug_displays
[separate_debug_str
].section
;
1777 if (section
->start
== NULL
)
1780 if (offset
>= section
->size
)
1783 ret
= (const char *) (section
->start
+ offset
);
1784 /* Unfortunately we cannot rely upon the .debug_str section ending with a
1785 NUL byte. Since our caller is expecting to receive a well formed C
1786 string we test for the lack of a terminating byte here. */
1787 if (strnlen ((const char *) ret
, section
->size
- offset
)
1788 == section
->size
- offset
)
1789 return _("<no NUL byte at end of alt .debug_str section>");
1794 warn (_("DW_FORM_GNU_strp_alt offset (%#" PRIx64
")"
1795 " too big or no string sections available\n"), offset
);
1796 return _("<offset is too big>");
1800 get_AT_name (unsigned long attribute
)
1805 return "DW_AT value: 0";
1807 /* One value is shared by the MIPS and HP extensions: */
1808 if (attribute
== DW_AT_MIPS_fde
)
1809 return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable";
1811 name
= get_DW_AT_name (attribute
);
1815 static char buffer
[100];
1817 snprintf (buffer
, sizeof (buffer
), _("Unknown AT value: %lx"),
1826 add_dwo_info (const char * value
, uint64_t cu_offset
, dwo_type type
)
1828 dwo_info
* dwinfo
= xmalloc (sizeof * dwinfo
);
1830 dwinfo
->type
= type
;
1831 dwinfo
->value
= value
;
1832 dwinfo
->cu_offset
= cu_offset
;
1833 dwinfo
->next
= first_dwo_info
;
1834 first_dwo_info
= dwinfo
;
1838 add_dwo_name (const char * name
, uint64_t cu_offset
)
1840 add_dwo_info (name
, cu_offset
, DWO_NAME
);
1844 add_dwo_dir (const char * dir
, uint64_t cu_offset
)
1846 add_dwo_info (dir
, cu_offset
, DWO_DIR
);
1850 add_dwo_id (const char * id
, uint64_t cu_offset
)
1852 add_dwo_info (id
, cu_offset
, DWO_ID
);
1856 free_dwo_info (void)
1861 for (dwinfo
= first_dwo_info
; dwinfo
!= NULL
; dwinfo
= next
)
1863 next
= dwinfo
->next
;
1866 first_dwo_info
= NULL
;
1869 /* Ensure that START + UVALUE is less than END.
1870 Return an adjusted UVALUE if necessary to ensure this relationship. */
1872 static inline uint64_t
1873 check_uvalue (const unsigned char *start
,
1875 const unsigned char *end
)
1877 uint64_t max_uvalue
= end
- start
;
1879 /* See PR 17512: file: 008-103549-0.001:0.1.
1880 and PR 24829 for examples of where these tests are triggered. */
1881 if (uvalue
> max_uvalue
)
1883 warn (_("Corrupt attribute block length: %#" PRIx64
"\n"), uvalue
);
1884 uvalue
= max_uvalue
;
1890 static unsigned char *
1891 skip_attr_bytes (unsigned long form
,
1892 unsigned char *data
,
1894 uint64_t pointer_size
,
1895 uint64_t offset_size
,
1897 uint64_t *value_return
)
1900 uint64_t uvalue
= 0;
1907 case DW_FORM_ref_addr
:
1908 if (dwarf_version
== 2)
1909 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1910 else if (dwarf_version
> 2)
1911 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1917 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1921 case DW_FORM_line_strp
:
1922 case DW_FORM_sec_offset
:
1923 case DW_FORM_GNU_ref_alt
:
1924 case DW_FORM_GNU_strp_alt
:
1925 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1928 case DW_FORM_flag_present
:
1936 case DW_FORM_addrx1
:
1937 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1941 case DW_FORM_addrx3
:
1942 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 3, end
);
1948 case DW_FORM_addrx2
:
1949 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
1955 case DW_FORM_addrx4
:
1956 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1960 READ_SLEB (svalue
, data
, end
);
1964 case DW_FORM_ref_udata
:
1966 case DW_FORM_GNU_str_index
:
1968 case DW_FORM_GNU_addr_index
:
1970 case DW_FORM_loclistx
:
1971 case DW_FORM_rnglistx
:
1972 READ_ULEB (uvalue
, data
, end
);
1976 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 8, end
);
1980 case DW_FORM_ref_sig8
:
1984 case DW_FORM_data16
:
1988 case DW_FORM_string
:
1989 inc
= strnlen ((char *) data
, end
- data
) + 1;
1993 case DW_FORM_exprloc
:
1994 READ_ULEB (uvalue
, data
, end
);
1998 case DW_FORM_block1
:
1999 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
2003 case DW_FORM_block2
:
2004 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
2008 case DW_FORM_block4
:
2009 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
2013 case DW_FORM_indirect
:
2014 READ_ULEB (form
, data
, end
);
2015 if (form
== DW_FORM_implicit_const
)
2016 SKIP_ULEB (data
, end
);
2017 return skip_attr_bytes (form
, data
, end
, pointer_size
, offset_size
,
2018 dwarf_version
, value_return
);
2024 * value_return
= uvalue
;
2025 if (inc
<= (size_t) (end
- data
))
2032 /* Given form FORM with value UVALUE, locate and return the abbreviation
2033 associated with it. */
2035 static abbrev_entry
*
2036 get_type_abbrev_from_form (unsigned long form
,
2039 unsigned char *cu_end
,
2040 const struct dwarf_section
*section
,
2041 unsigned long *abbrev_num_return
,
2042 unsigned char **data_return
,
2043 abbrev_map
**map_return
)
2047 case DW_FORM_GNU_ref_alt
:
2048 case DW_FORM_ref_sig8
:
2049 /* FIXME: We are unable to handle this form at the moment. */
2052 case DW_FORM_ref_addr
:
2053 if (uvalue
>= section
->size
)
2055 warn (_("Unable to resolve ref_addr form: uvalue %" PRIx64
2056 " >= section size %" PRIx64
" (%s)\n"),
2057 uvalue
, section
->size
, section
->name
);
2062 case DW_FORM_ref_sup4
:
2063 case DW_FORM_ref_sup8
:
2070 case DW_FORM_ref_udata
:
2071 if (uvalue
+ cu_offset
< uvalue
2072 || uvalue
+ cu_offset
> (size_t) (cu_end
- section
->start
))
2074 warn (_("Unable to resolve ref form: uvalue %" PRIx64
2075 " + cu_offset %" PRIx64
" > CU size %tx\n"),
2076 uvalue
, cu_offset
, cu_end
- section
->start
);
2079 uvalue
+= cu_offset
;
2082 /* FIXME: Are there other DW_FORMs that can be used by types ? */
2085 warn (_("Unexpected form %lx encountered whilst finding abbreviation for type\n"), form
);
2089 abbrev_map
*map
= find_abbrev_map_by_offset (uvalue
);
2093 warn (_("Unable to find abbreviations for CU offset %" PRIx64
"\n"),
2097 if (map
->list
== NULL
)
2099 warn (_("Empty abbreviation list encountered for CU offset %" PRIx64
"\n"),
2104 if (map_return
!= NULL
)
2106 if (form
== DW_FORM_ref_addr
)
2112 unsigned char *data
= section
->start
+ uvalue
;
2113 if (form
== DW_FORM_ref_addr
)
2114 cu_end
= section
->start
+ map
->end
;
2116 unsigned long abbrev_number
;
2117 READ_ULEB (abbrev_number
, data
, cu_end
);
2119 if (abbrev_num_return
!= NULL
)
2120 *abbrev_num_return
= abbrev_number
;
2122 if (data_return
!= NULL
)
2123 *data_return
= data
;
2125 abbrev_entry
*entry
;
2126 for (entry
= map
->list
->first_abbrev
; entry
!= NULL
; entry
= entry
->next
)
2127 if (entry
->number
== abbrev_number
)
2131 warn (_("Unable to find entry for abbreviation %lu\n"), abbrev_number
);
2136 /* Return IS_SIGNED set to TRUE if the type using abbreviation ENTRY
2137 can be determined to be a signed type. The data for ENTRY can be
2138 found starting at DATA. */
2141 get_type_signedness (abbrev_entry
*entry
,
2142 const struct dwarf_section
*section
,
2143 unsigned char *data
,
2146 uint64_t pointer_size
,
2147 uint64_t offset_size
,
2150 unsigned int nesting
)
2154 * is_signed
= false;
2156 #define MAX_NESTING 20
2157 if (nesting
> MAX_NESTING
)
2159 /* FIXME: Warn - or is this expected ?
2160 NB/ We need to avoid infinite recursion. */
2164 for (attr
= entry
->first_attr
;
2165 attr
!= NULL
&& attr
->attribute
;
2168 unsigned char * orig_data
= data
;
2169 uint64_t uvalue
= 0;
2171 data
= skip_attr_bytes (attr
->form
, data
, end
, pointer_size
,
2172 offset_size
, dwarf_version
, & uvalue
);
2176 switch (attr
->attribute
)
2178 case DW_AT_linkage_name
:
2182 if (attr
->form
== DW_FORM_strp
)
2183 printf (", %s", fetch_indirect_string (uvalue
));
2184 else if (attr
->form
== DW_FORM_string
)
2185 printf (", %.*s", (int) (end
- orig_data
), orig_data
);
2192 abbrev_entry
*type_abbrev
;
2193 unsigned char *type_data
;
2196 type_abbrev
= get_type_abbrev_from_form (attr
->form
,
2201 NULL
/* abbrev num return */,
2204 if (type_abbrev
== NULL
)
2207 get_type_signedness (type_abbrev
, section
, type_data
,
2208 map
? section
->start
+ map
->end
: end
,
2209 map
? map
->start
: cu_offset
,
2210 pointer_size
, offset_size
, dwarf_version
,
2211 is_signed
, nesting
+ 1);
2215 case DW_AT_encoding
:
2216 /* Determine signness. */
2219 case DW_ATE_address
:
2220 /* FIXME - some architectures have signed addresses. */
2221 case DW_ATE_boolean
:
2222 case DW_ATE_unsigned
:
2223 case DW_ATE_unsigned_char
:
2224 case DW_ATE_unsigned_fixed
:
2225 * is_signed
= false;
2229 case DW_ATE_complex_float
:
2232 case DW_ATE_signed_char
:
2233 case DW_ATE_imaginary_float
:
2234 case DW_ATE_decimal_float
:
2235 case DW_ATE_signed_fixed
:
2245 read_and_print_leb128 (unsigned char *data
,
2246 unsigned int *bytes_read
,
2247 unsigned const char *end
,
2251 uint64_t val
= read_leb128 (data
, end
, is_signed
, bytes_read
, &status
);
2253 report_leb_status (status
);
2255 printf ("%" PRId64
, val
);
2257 printf ("%" PRIu64
, val
);
2261 display_discr_list (unsigned long form
,
2263 unsigned char *data
,
2266 unsigned char *end
= data
;
2270 printf ("[default]");
2277 case DW_FORM_block1
:
2278 case DW_FORM_block2
:
2279 case DW_FORM_block4
:
2280 /* Move data pointer back to the start of the byte array. */
2284 printf ("<corrupt>\n");
2285 warn (_("corrupt discr_list - not using a block form\n"));
2291 printf ("<corrupt>\n");
2292 warn (_("corrupt discr_list - block not long enough\n"));
2296 bool is_signed
= (level
> 0 && level
<= MAX_CU_NESTING
2297 ? level_type_signed
[level
- 1] : false);
2302 unsigned char discriminant
;
2303 unsigned int bytes_read
;
2305 SAFE_BYTE_GET_AND_INC (discriminant
, data
, 1, end
);
2307 switch (discriminant
)
2311 read_and_print_leb128 (data
, & bytes_read
, end
, is_signed
);
2317 read_and_print_leb128 (data
, & bytes_read
, end
, is_signed
);
2321 read_and_print_leb128 (data
, & bytes_read
, end
, is_signed
);
2326 printf ("<corrupt>\n");
2327 warn (_("corrupt discr_list - unrecognized discriminant byte %#x\n"),
2337 printf (")(signed)");
2339 printf (")(unsigned)");
2343 display_lang (uint64_t uvalue
)
2347 /* Ordered by the numeric value of these constants. */
2348 case DW_LANG_C89
: printf ("ANSI C"); break;
2349 case DW_LANG_C
: printf ("non-ANSI C"); break;
2350 case DW_LANG_Ada83
: printf ("Ada"); break;
2351 case DW_LANG_C_plus_plus
: printf ("C++"); break;
2352 case DW_LANG_Cobol74
: printf ("Cobol 74"); break;
2353 case DW_LANG_Cobol85
: printf ("Cobol 85"); break;
2354 case DW_LANG_Fortran77
: printf ("FORTRAN 77"); break;
2355 case DW_LANG_Fortran90
: printf ("Fortran 90"); break;
2356 case DW_LANG_Pascal83
: printf ("ANSI Pascal"); break;
2357 case DW_LANG_Modula2
: printf ("Modula 2"); break;
2359 /* DWARF 2.1 values. */
2360 case DW_LANG_Java
: printf ("Java"); break;
2361 case DW_LANG_C99
: printf ("ANSI C99"); break;
2362 case DW_LANG_Ada95
: printf ("ADA 95"); break;
2363 case DW_LANG_Fortran95
: printf ("Fortran 95"); break;
2365 /* DWARF 3 values. */
2366 case DW_LANG_PLI
: printf ("PLI"); break;
2367 case DW_LANG_ObjC
: printf ("Objective C"); break;
2368 case DW_LANG_ObjC_plus_plus
: printf ("Objective C++"); break;
2369 case DW_LANG_UPC
: printf ("Unified Parallel C"); break;
2370 case DW_LANG_D
: printf ("D"); break;
2372 /* DWARF 4 values. */
2373 case DW_LANG_Python
: printf ("Python"); break;
2375 /* DWARF 5 values. */
2376 case DW_LANG_OpenCL
: printf ("OpenCL"); break;
2377 case DW_LANG_Go
: printf ("Go"); break;
2378 case DW_LANG_Modula3
: printf ("Modula 3"); break;
2379 case DW_LANG_Haskell
: printf ("Haskell"); break;
2380 case DW_LANG_C_plus_plus_03
: printf ("C++03"); break;
2381 case DW_LANG_C_plus_plus_11
: printf ("C++11"); break;
2382 case DW_LANG_OCaml
: printf ("OCaml"); break;
2383 case DW_LANG_Rust
: printf ("Rust"); break;
2384 case DW_LANG_C11
: printf ("C11"); break;
2385 case DW_LANG_Swift
: printf ("Swift"); break;
2386 case DW_LANG_Julia
: printf ("Julia"); break;
2387 case DW_LANG_Dylan
: printf ("Dylan"); break;
2388 case DW_LANG_C_plus_plus_14
: printf ("C++14"); break;
2389 case DW_LANG_Fortran03
: printf ("Fortran 03"); break;
2390 case DW_LANG_Fortran08
: printf ("Fortran 08"); break;
2391 case DW_LANG_RenderScript
: printf ("RenderScript"); break;
2392 case DW_LANG_C17
: printf ("C17"); break;
2393 case DW_LANG_Fortran18
: printf ("Fortran 18"); break;
2394 case DW_LANG_Ada2005
: printf ("Ada 2005"); break;
2395 case DW_LANG_Ada2012
: printf ("Ada 2012"); break;
2396 case DW_LANG_HIP
: printf ("Hip"); break;
2397 case DW_LANG_Assembly
: printf ("Assembler"); break;
2398 case DW_LANG_C_sharp
: printf ("C Sharp"); break;
2399 case DW_LANG_Mojo
: printf ("Mojo"); break;
2400 case DW_LANG_GLSL
: printf ("GLSL"); break;
2401 case DW_LANG_GLSL_ES
: printf ("GLSL_ES"); break;
2402 case DW_LANG_HLSL
: printf ("HLSL"); break;
2403 case DW_LANG_OpenCL_CPP
: printf ("OpenCL C++"); break;
2404 case DW_LANG_CPP_for_OpenCL
: printf ("C++ for OpenCL"); break;
2405 case DW_LANG_SYCL
: printf ("SYCL"); break;
2406 case DW_LANG_C_plus_plus_17
: printf ("C++17"); break;
2407 case DW_LANG_C_plus_plus_20
: printf ("C++20"); break;
2408 case DW_LANG_C_plus_plus_23
: printf ("C++23"); break;
2409 case DW_LANG_Odin
: printf ("Odin"); break;
2410 case DW_LANG_P4
: printf ("P4"); break;
2411 case DW_LANG_Metal
: printf ("C23"); break;
2412 case DW_LANG_C23
: printf ("C23"); break;
2413 case DW_LANG_Fortran23
: printf ("Fortran 23"); break;
2414 case DW_LANG_Ruby
: printf ("Ruby"); break;
2415 case DW_LANG_Move
: printf ("Move"); break;
2416 case DW_LANG_Hylo
: printf ("Hylo"); break;
2418 /* MIPS extension. */
2419 case DW_LANG_Mips_Assembler
: printf ("MIPS assembler"); break;
2421 /* UPC extension. */
2422 case DW_LANG_Upc
: printf ("Unified Parallel C"); break;
2425 if (uvalue
>= DW_LANG_lo_user
&& uvalue
<= DW_LANG_hi_user
)
2426 printf (_("implementation defined: %#" PRIx64
""), uvalue
);
2428 printf (_("unknown: %#" PRIx64
""), uvalue
);
2433 static unsigned char *
2434 read_and_display_attr_value (unsigned long attribute
,
2436 int64_t implicit_const
,
2437 unsigned char *start
,
2438 unsigned char *data
,
2441 uint64_t pointer_size
,
2442 uint64_t offset_size
,
2444 debug_info
*debug_info_p
,
2446 struct dwarf_section
*section
,
2447 struct cu_tu_set
*this_set
,
2452 uint64_t uvalue
= 0;
2453 uint64_t uvalue_hi
= 0;
2454 unsigned char *block_start
= NULL
;
2455 unsigned char *orig_data
= data
;
2457 if (data
> end
|| (data
== end
&& form
!= DW_FORM_flag_present
))
2459 warn (_("Corrupt attribute\n"));
2463 if (do_wide
&& ! do_loc
)
2465 /* PR 26847: Display the name of the form. */
2466 const char * name
= get_FORM_name (form
);
2468 /* For convenience we skip the DW_FORM_ prefix to the name. */
2470 name
+= 8; /* strlen ("DW_FORM_") */
2471 printf ("%c(%s)", delimiter
, name
);
2476 case DW_FORM_ref_addr
:
2477 if (dwarf_version
== 2)
2478 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
2479 else if (dwarf_version
> 2)
2480 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
2482 error (_("Internal error: DW_FORM_ref_addr is not supported in DWARF version 1.\n"));
2486 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
2489 case DW_FORM_strp_sup
:
2491 case DW_FORM_line_strp
:
2492 case DW_FORM_sec_offset
:
2493 case DW_FORM_GNU_ref_alt
:
2494 case DW_FORM_GNU_strp_alt
:
2495 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
2498 case DW_FORM_flag_present
:
2506 case DW_FORM_addrx1
:
2507 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
2513 case DW_FORM_addrx2
:
2514 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
2518 case DW_FORM_addrx3
:
2519 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 3, end
);
2522 case DW_FORM_ref_sup4
:
2526 case DW_FORM_addrx4
:
2527 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
2530 case DW_FORM_ref_sup8
:
2533 case DW_FORM_ref_sig8
:
2534 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 8, end
);
2537 case DW_FORM_data16
:
2538 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 8, end
);
2539 SAFE_BYTE_GET_AND_INC (uvalue_hi
, data
, 8, end
);
2540 if (byte_get
!= byte_get_little_endian
)
2542 uint64_t utmp
= uvalue
;
2549 READ_SLEB (svalue
, data
, end
);
2553 case DW_FORM_GNU_str_index
:
2555 case DW_FORM_ref_udata
:
2557 case DW_FORM_GNU_addr_index
:
2559 case DW_FORM_loclistx
:
2560 case DW_FORM_rnglistx
:
2561 READ_ULEB (uvalue
, data
, end
);
2564 case DW_FORM_indirect
:
2565 READ_ULEB (form
, data
, end
);
2567 printf ("%c%s", delimiter
, get_FORM_name (form
));
2568 if (form
== DW_FORM_implicit_const
)
2569 READ_SLEB (implicit_const
, data
, end
);
2570 return read_and_display_attr_value (attribute
, form
, implicit_const
,
2572 cu_offset
, pointer_size
,
2573 offset_size
, dwarf_version
,
2574 debug_info_p
, do_loc
,
2575 section
, this_set
, delimiter
, level
);
2577 case DW_FORM_implicit_const
:
2578 uvalue
= implicit_const
;
2587 case DW_FORM_ref_addr
:
2589 printf ("%c<%#" PRIx64
">", delimiter
, uvalue
);
2592 case DW_FORM_GNU_ref_alt
:
2596 /* We have already printed the form name. */
2597 printf ("%c<%#" PRIx64
">", delimiter
, uvalue
);
2599 printf ("%c<alt %#" PRIx64
">", delimiter
, uvalue
);
2601 /* FIXME: Follow the reference... */
2607 case DW_FORM_ref_sup4
:
2608 case DW_FORM_ref_udata
:
2610 printf ("%c<%#" PRIx64
">", delimiter
, uvalue
+ cu_offset
);
2615 case DW_FORM_sec_offset
:
2617 printf ("%c%#" PRIx64
, delimiter
, uvalue
);
2620 case DW_FORM_flag_present
:
2626 printf ("%c%" PRId64
, delimiter
, uvalue
);
2631 printf ("%c%" PRIu64
, delimiter
, uvalue
);
2634 case DW_FORM_implicit_const
:
2636 printf ("%c%" PRId64
, delimiter
, implicit_const
);
2639 case DW_FORM_ref_sup8
:
2644 uint64_t utmp
= uvalue
;
2645 if (form
== DW_FORM_ref8
)
2647 printf ("%c%#" PRIx64
, delimiter
, utmp
);
2651 case DW_FORM_data16
:
2655 printf (" %#" PRIx64
, uvalue
);
2657 printf (" %#" PRIx64
"%016" PRIx64
, uvalue_hi
, uvalue
);
2661 case DW_FORM_string
:
2663 printf ("%c%.*s", delimiter
, (int) (end
- data
), data
);
2664 data
+= strnlen ((char *) data
, end
- data
);
2670 case DW_FORM_exprloc
:
2671 READ_ULEB (uvalue
, data
, end
);
2674 if (block_start
>= end
)
2676 warn (_("Block ends prematurely\n"));
2681 uvalue
= check_uvalue (block_start
, uvalue
, end
);
2683 data
= block_start
+ uvalue
;
2688 SAFE_BYTE_GET (op
, block_start
, sizeof (op
), end
);
2689 if (op
!= DW_OP_addrx
)
2690 data
= display_block (block_start
, uvalue
, end
, delimiter
);
2694 case DW_FORM_block1
:
2695 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
2698 case DW_FORM_block2
:
2699 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
2702 case DW_FORM_block4
:
2703 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
2710 /* We have already displayed the form name. */
2711 printf (_("%c(offset: %#" PRIx64
"): %s"),
2712 delimiter
, uvalue
, fetch_indirect_string (uvalue
));
2714 printf (_("%c(indirect string, offset: %#" PRIx64
"): %s"),
2715 delimiter
, uvalue
, fetch_indirect_string (uvalue
));
2719 case DW_FORM_line_strp
:
2723 /* We have already displayed the form name. */
2724 printf (_("%c(offset: %#" PRIx64
"): %s"),
2725 delimiter
, uvalue
, fetch_indirect_line_string (uvalue
));
2727 printf (_("%c(indirect line string, offset: %#" PRIx64
"): %s"),
2728 delimiter
, uvalue
, fetch_indirect_line_string (uvalue
));
2732 case DW_FORM_GNU_str_index
:
2740 const char *suffix
= section
? strrchr (section
->name
, '.') : NULL
;
2741 bool dwo
= suffix
&& strcmp (suffix
, ".dwo") == 0;
2744 strng
= fetch_indexed_string (uvalue
, this_set
, offset_size
, dwo
,
2745 debug_info_p
? debug_info_p
->str_offsets_base
: 0);
2747 /* We have already displayed the form name. */
2748 printf (_("%c(offset: %#" PRIx64
"): %s"),
2749 delimiter
, uvalue
, strng
);
2751 printf (_("%c(indexed string: %#" PRIx64
"): %s"),
2752 delimiter
, uvalue
, strng
);
2756 case DW_FORM_GNU_strp_alt
:
2760 /* We have already displayed the form name. */
2761 printf (_("%c(offset: %#" PRIx64
") %s"),
2762 delimiter
, uvalue
, fetch_alt_indirect_string (uvalue
));
2764 printf (_("%c(alt indirect string, offset: %#" PRIx64
") %s"),
2765 delimiter
, uvalue
, fetch_alt_indirect_string (uvalue
));
2769 case DW_FORM_indirect
:
2770 /* Handled above. */
2773 case DW_FORM_ref_sig8
:
2775 printf ("%c%s: %#" PRIx64
, delimiter
, do_wide
? "" : "signature",
2779 case DW_FORM_GNU_addr_index
:
2781 case DW_FORM_addrx1
:
2782 case DW_FORM_addrx2
:
2783 case DW_FORM_addrx3
:
2784 case DW_FORM_addrx4
:
2785 case DW_FORM_loclistx
:
2786 case DW_FORM_rnglistx
:
2790 const char *suffix
= strrchr (section
->name
, '.');
2791 bool dwo
= suffix
&& strcmp (suffix
, ".dwo") == 0;
2793 if (form
== DW_FORM_loclistx
)
2795 if (debug_info_p
== NULL
)
2799 idx
= fetch_indexed_offset (uvalue
, loclists_dwo
,
2800 debug_info_p
->loclists_base
,
2801 debug_info_p
->offset_size
);
2802 if (idx
!= (uint64_t) -1)
2803 idx
+= (offset_size
== 8) ? 20 : 12;
2805 else if (dwarf_version
> 4)
2807 idx
= fetch_indexed_offset (uvalue
, loclists
,
2808 debug_info_p
->loclists_base
,
2809 debug_info_p
->offset_size
);
2813 /* We want to compute:
2814 idx = fetch_indexed_value (uvalue, loclists,
2815 debug_info_p->loclists_base);
2816 idx += debug_info_p->loclists_base;
2817 Fortunately we already have that sum cached in the
2818 loc_offsets array. */
2819 if (uvalue
< debug_info_p
->num_loc_offsets
)
2820 idx
= debug_info_p
->loc_offsets
[uvalue
];
2823 warn (_("loc_offset %" PRIu64
" too big\n"), uvalue
);
2828 else if (form
== DW_FORM_rnglistx
)
2830 if (debug_info_p
== NULL
)
2833 idx
= fetch_indexed_offset (uvalue
,
2834 dwo
? rnglists_dwo
: rnglists
,
2835 debug_info_p
->rnglists_base
,
2836 debug_info_p
->offset_size
);
2840 if (debug_info_p
== NULL
)
2842 else if (debug_info_p
->addr_base
== DEBUG_INFO_UNAVAILABLE
)
2845 base
= debug_info_p
->addr_base
;
2847 base
+= uvalue
* pointer_size
;
2848 idx
= fetch_indexed_addr (base
, pointer_size
);
2851 /* We have already displayed the form name. */
2852 if (idx
!= (uint64_t) -1)
2853 printf (_("%c(index: %#" PRIx64
"): %#" PRIx64
),
2854 delimiter
, uvalue
, idx
);
2858 case DW_FORM_strp_sup
:
2860 printf ("%c<%#" PRIx64
">", delimiter
, uvalue
+ cu_offset
);
2864 warn (_("Unrecognized form: %#lx\n"), form
);
2865 /* What to do? Consume a byte maybe? */
2870 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
|| do_debug_info
)
2871 && num_debug_info_entries
== 0
2872 && debug_info_p
!= NULL
)
2876 case DW_AT_loclists_base
:
2877 if (debug_info_p
->loclists_base
)
2878 warn (_("CU @ %#" PRIx64
" has multiple loclists_base values "
2879 "(%#" PRIx64
" and %#" PRIx64
")\n"),
2880 debug_info_p
->cu_offset
,
2881 debug_info_p
->loclists_base
, uvalue
);
2885 warn (_("CU @ %#" PRIx64
" has has a negative loclists_base "
2886 "value of %#" PRIx64
" - treating as zero\n"),
2887 debug_info_p
->cu_offset
, svalue
);
2890 debug_info_p
->loclists_base
= uvalue
;
2893 case DW_AT_rnglists_base
:
2894 /* Assignment to debug_info_p->rnglists_base is now elsewhere. */
2897 case DW_AT_str_offsets_base
:
2898 if (debug_info_p
->str_offsets_base
)
2899 warn (_("CU @ %#" PRIx64
" has multiple str_offsets_base values "
2900 "%#" PRIx64
" and %#" PRIx64
")\n"),
2901 debug_info_p
->cu_offset
,
2902 debug_info_p
->str_offsets_base
, uvalue
);
2906 warn (_("CU @ %#" PRIx64
" has has a negative stroffsets_base "
2907 "value of %#" PRIx64
" - treating as zero\n"),
2908 debug_info_p
->cu_offset
, svalue
);
2911 debug_info_p
->str_offsets_base
= uvalue
;
2914 case DW_AT_frame_base
:
2915 /* This is crude; the have_frame_base is reset on the next
2916 subprogram, not at the end of the current topmost one. */
2917 have_frame_base
= 1;
2918 frame_base_level
= level
;
2920 case DW_AT_location
:
2921 case DW_AT_GNU_locviews
:
2922 case DW_AT_string_length
:
2923 case DW_AT_return_addr
:
2924 case DW_AT_data_member_location
:
2925 case DW_AT_vtable_elem_location
:
2927 case DW_AT_static_link
:
2928 case DW_AT_use_location
:
2929 case DW_AT_call_value
:
2930 case DW_AT_GNU_call_site_value
:
2931 case DW_AT_call_data_value
:
2932 case DW_AT_GNU_call_site_data_value
:
2933 case DW_AT_call_target
:
2934 case DW_AT_GNU_call_site_target
:
2935 case DW_AT_call_target_clobbered
:
2936 case DW_AT_GNU_call_site_target_clobbered
:
2937 if ((dwarf_version
< 4
2938 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
2939 || form
== DW_FORM_sec_offset
2940 || form
== DW_FORM_loclistx
)
2942 /* Process location list. */
2943 unsigned int lmax
= debug_info_p
->max_loc_offsets
;
2944 unsigned int num
= debug_info_p
->num_loc_offsets
;
2946 if (lmax
== 0 || num
>= lmax
)
2949 debug_info_p
->loc_offsets
= (uint64_t *)
2950 xcrealloc (debug_info_p
->loc_offsets
,
2951 lmax
, sizeof (*debug_info_p
->loc_offsets
));
2952 debug_info_p
->loc_views
= (uint64_t *)
2953 xcrealloc (debug_info_p
->loc_views
,
2954 lmax
, sizeof (*debug_info_p
->loc_views
));
2955 debug_info_p
->have_frame_base
= (int *)
2956 xcrealloc (debug_info_p
->have_frame_base
,
2957 lmax
, sizeof (*debug_info_p
->have_frame_base
));
2958 debug_info_p
->max_loc_offsets
= lmax
;
2960 if (form
== DW_FORM_loclistx
)
2961 uvalue
= fetch_indexed_offset (num
, loclists
,
2962 debug_info_p
->loclists_base
,
2963 debug_info_p
->offset_size
);
2964 else if (this_set
!= NULL
)
2965 uvalue
+= this_set
->section_offsets
[DW_SECT_LOC
];
2967 debug_info_p
->have_frame_base
[num
] = have_frame_base
;
2968 if (attribute
!= DW_AT_GNU_locviews
)
2970 /* Corrupt DWARF info can produce more offsets than views.
2971 See PR 23062 for an example. */
2972 if (debug_info_p
->num_loc_offsets
2973 > debug_info_p
->num_loc_views
)
2974 warn (_("More location offset attributes than DW_AT_GNU_locview attributes\n"));
2977 debug_info_p
->loc_offsets
[num
] = uvalue
;
2978 debug_info_p
->num_loc_offsets
++;
2983 if (debug_info_p
->num_loc_views
> num
)
2985 warn (_("The number of views (%u) is greater than the number of locations (%u)\n"),
2986 debug_info_p
->num_loc_views
, num
);
2987 debug_info_p
->num_loc_views
= num
;
2990 num
= debug_info_p
->num_loc_views
;
2991 if (num
> debug_info_p
->num_loc_offsets
)
2992 warn (_("More DW_AT_GNU_locview attributes than location offset attributes\n"));
2995 debug_info_p
->loc_views
[num
] = uvalue
;
2996 debug_info_p
->num_loc_views
++;
3003 if (need_base_address
)
3005 if (form
== DW_FORM_addrx
)
3006 uvalue
= fetch_indexed_addr (debug_info_p
->addr_base
3007 + uvalue
* pointer_size
,
3010 debug_info_p
->base_address
= uvalue
;
3014 case DW_AT_GNU_addr_base
:
3015 case DW_AT_addr_base
:
3016 debug_info_p
->addr_base
= uvalue
;
3017 /* Retrieved elsewhere so that it is in
3018 place by the time we read low_pc. */
3021 case DW_AT_GNU_ranges_base
:
3022 debug_info_p
->ranges_base
= uvalue
;
3026 if ((dwarf_version
< 4
3027 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
3028 || form
== DW_FORM_sec_offset
3029 || form
== DW_FORM_rnglistx
)
3031 /* Process range list. */
3032 unsigned int lmax
= debug_info_p
->max_range_lists
;
3033 unsigned int num
= debug_info_p
->num_range_lists
;
3035 if (lmax
== 0 || num
>= lmax
)
3038 debug_info_p
->range_lists
= (uint64_t *)
3039 xcrealloc (debug_info_p
->range_lists
,
3040 lmax
, sizeof (*debug_info_p
->range_lists
));
3041 debug_info_p
->max_range_lists
= lmax
;
3044 if (form
== DW_FORM_rnglistx
)
3045 uvalue
= fetch_indexed_offset (uvalue
, rnglists
,
3046 debug_info_p
->rnglists_base
,
3047 debug_info_p
->offset_size
);
3049 debug_info_p
->range_lists
[num
] = uvalue
;
3050 debug_info_p
->num_range_lists
++;
3054 case DW_AT_GNU_dwo_name
:
3055 case DW_AT_dwo_name
:
3060 add_dwo_name ((const char *) fetch_indirect_string (uvalue
),
3063 case DW_FORM_GNU_strp_alt
:
3064 add_dwo_name ((const char *) fetch_alt_indirect_string (uvalue
), cu_offset
);
3066 case DW_FORM_GNU_str_index
:
3072 add_dwo_name (fetch_indexed_string (uvalue
, this_set
,
3074 debug_info_p
->str_offsets_base
),
3077 case DW_FORM_string
:
3078 add_dwo_name ((const char *) orig_data
, cu_offset
);
3081 warn (_("Unsupported form (%s) for attribute %s\n"),
3082 get_FORM_name (form
), get_AT_name (attribute
));
3087 case DW_AT_comp_dir
:
3088 /* FIXME: Also extract a build-id in a CU/TU. */
3093 add_dwo_dir ((const char *) fetch_indirect_string (uvalue
), cu_offset
);
3095 case DW_FORM_GNU_strp_alt
:
3096 add_dwo_dir (fetch_alt_indirect_string (uvalue
), cu_offset
);
3098 case DW_FORM_line_strp
:
3099 add_dwo_dir ((const char *) fetch_indirect_line_string (uvalue
), cu_offset
);
3101 case DW_FORM_GNU_str_index
:
3107 add_dwo_dir (fetch_indexed_string (uvalue
, this_set
, offset_size
, false,
3108 debug_info_p
->str_offsets_base
),
3111 case DW_FORM_string
:
3112 add_dwo_dir ((const char *) orig_data
, cu_offset
);
3115 warn (_("Unsupported form (%s) for attribute %s\n"),
3116 get_FORM_name (form
), get_AT_name (attribute
));
3121 case DW_AT_GNU_dwo_id
:
3126 /* FIXME: Record the length of the ID as well ? */
3127 add_dwo_id ((const char *) (data
- 8), cu_offset
);
3130 warn (_("Unsupported form (%s) for attribute %s\n"),
3131 get_FORM_name (form
), get_AT_name (attribute
));
3141 if (do_loc
|| attribute
== 0)
3144 /* For some attributes we can display further information. */
3148 if (level
>= 0 && level
< MAX_CU_NESTING
3149 && uvalue
< (size_t) (end
- start
))
3151 bool is_signed
= false;
3152 abbrev_entry
*type_abbrev
;
3153 unsigned char *type_data
;
3156 type_abbrev
= get_type_abbrev_from_form (form
, uvalue
,
3160 if (type_abbrev
!= NULL
)
3162 get_type_signedness (type_abbrev
, section
, type_data
,
3163 map
? section
->start
+ map
->end
: end
,
3164 map
? map
->start
: cu_offset
,
3165 pointer_size
, offset_size
, dwarf_version
,
3168 level_type_signed
[level
] = is_signed
;
3176 case DW_INL_not_inlined
:
3177 printf (_("(not inlined)"));
3179 case DW_INL_inlined
:
3180 printf (_("(inlined)"));
3182 case DW_INL_declared_not_inlined
:
3183 printf (_("(declared as inline but ignored)"));
3185 case DW_INL_declared_inlined
:
3186 printf (_("(declared as inline and inlined)"));
3189 printf (_(" (Unknown inline attribute value: %#" PRIx64
")"),
3195 case DW_AT_language
:
3197 display_lang (uvalue
);
3201 case DW_AT_encoding
:
3205 case DW_ATE_void
: printf ("(void)"); break;
3206 case DW_ATE_address
: printf ("(machine address)"); break;
3207 case DW_ATE_boolean
: printf ("(boolean)"); break;
3208 case DW_ATE_complex_float
: printf ("(complex float)"); break;
3209 case DW_ATE_float
: printf ("(float)"); break;
3210 case DW_ATE_signed
: printf ("(signed)"); break;
3211 case DW_ATE_signed_char
: printf ("(signed char)"); break;
3212 case DW_ATE_unsigned
: printf ("(unsigned)"); break;
3213 case DW_ATE_unsigned_char
: printf ("(unsigned char)"); break;
3214 /* DWARF 2.1 values: */
3215 case DW_ATE_imaginary_float
: printf ("(imaginary float)"); break;
3216 case DW_ATE_decimal_float
: printf ("(decimal float)"); break;
3217 /* DWARF 3 values: */
3218 case DW_ATE_packed_decimal
: printf ("(packed_decimal)"); break;
3219 case DW_ATE_numeric_string
: printf ("(numeric_string)"); break;
3220 case DW_ATE_edited
: printf ("(edited)"); break;
3221 case DW_ATE_signed_fixed
: printf ("(signed_fixed)"); break;
3222 case DW_ATE_unsigned_fixed
: printf ("(unsigned_fixed)"); break;
3223 /* DWARF 4 values: */
3224 case DW_ATE_UTF
: printf ("(unicode string)"); break;
3225 /* DWARF 5 values: */
3226 case DW_ATE_UCS
: printf ("(UCS)"); break;
3227 case DW_ATE_ASCII
: printf ("(ASCII)"); break;
3229 /* HP extensions: */
3230 case DW_ATE_HP_float80
: printf ("(HP_float80)"); break;
3231 case DW_ATE_HP_complex_float80
: printf ("(HP_complex_float80)"); break;
3232 case DW_ATE_HP_float128
: printf ("(HP_float128)"); break;
3233 case DW_ATE_HP_complex_float128
:printf ("(HP_complex_float128)"); break;
3234 case DW_ATE_HP_floathpintel
: printf ("(HP_floathpintel)"); break;
3235 case DW_ATE_HP_imaginary_float80
: printf ("(HP_imaginary_float80)"); break;
3236 case DW_ATE_HP_imaginary_float128
: printf ("(HP_imaginary_float128)"); break;
3239 if (uvalue
>= DW_ATE_lo_user
3240 && uvalue
<= DW_ATE_hi_user
)
3241 printf (_("(user defined type)"));
3243 printf (_("(unknown type)"));
3248 case DW_AT_accessibility
:
3252 case DW_ACCESS_public
: printf ("(public)"); break;
3253 case DW_ACCESS_protected
: printf ("(protected)"); break;
3254 case DW_ACCESS_private
: printf ("(private)"); break;
3256 printf (_("(unknown accessibility)"));
3261 case DW_AT_visibility
:
3265 case DW_VIS_local
: printf ("(local)"); break;
3266 case DW_VIS_exported
: printf ("(exported)"); break;
3267 case DW_VIS_qualified
: printf ("(qualified)"); break;
3268 default: printf (_("(unknown visibility)")); break;
3272 case DW_AT_endianity
:
3276 case DW_END_default
: printf ("(default)"); break;
3277 case DW_END_big
: printf ("(big)"); break;
3278 case DW_END_little
: printf ("(little)"); break;
3280 if (uvalue
>= DW_END_lo_user
&& uvalue
<= DW_END_hi_user
)
3281 printf (_("(user specified)"));
3283 printf (_("(unknown endianity)"));
3288 case DW_AT_virtuality
:
3292 case DW_VIRTUALITY_none
: printf ("(none)"); break;
3293 case DW_VIRTUALITY_virtual
: printf ("(virtual)"); break;
3294 case DW_VIRTUALITY_pure_virtual
:printf ("(pure_virtual)"); break;
3295 default: printf (_("(unknown virtuality)")); break;
3299 case DW_AT_identifier_case
:
3303 case DW_ID_case_sensitive
: printf ("(case_sensitive)"); break;
3304 case DW_ID_up_case
: printf ("(up_case)"); break;
3305 case DW_ID_down_case
: printf ("(down_case)"); break;
3306 case DW_ID_case_insensitive
: printf ("(case_insensitive)"); break;
3307 default: printf (_("(unknown case)")); break;
3311 case DW_AT_calling_convention
:
3315 case DW_CC_normal
: printf ("(normal)"); break;
3316 case DW_CC_program
: printf ("(program)"); break;
3317 case DW_CC_nocall
: printf ("(nocall)"); break;
3318 case DW_CC_pass_by_reference
: printf ("(pass by ref)"); break;
3319 case DW_CC_pass_by_value
: printf ("(pass by value)"); break;
3320 case DW_CC_GNU_renesas_sh
: printf ("(Rensas SH)"); break;
3321 case DW_CC_GNU_borland_fastcall_i386
: printf ("(Borland fastcall i386)"); break;
3323 if (uvalue
>= DW_CC_lo_user
3324 && uvalue
<= DW_CC_hi_user
)
3325 printf (_("(user defined)"));
3327 printf (_("(unknown convention)"));
3331 case DW_AT_ordering
:
3336 case -1: printf (_("(undefined)")); break;
3337 case 0: printf ("(row major)"); break;
3338 case 1: printf ("(column major)"); break;
3342 case DW_AT_decimal_sign
:
3346 case DW_DS_unsigned
: printf (_("(unsigned)")); break;
3347 case DW_DS_leading_overpunch
: printf (_("(leading overpunch)")); break;
3348 case DW_DS_trailing_overpunch
: printf (_("(trailing overpunch)")); break;
3349 case DW_DS_leading_separate
: printf (_("(leading separate)")); break;
3350 case DW_DS_trailing_separate
: printf (_("(trailing separate)")); break;
3351 default: printf (_("(unrecognised)")); break;
3355 case DW_AT_defaulted
:
3359 case DW_DEFAULTED_no
: printf (_("(no)")); break;
3360 case DW_DEFAULTED_in_class
: printf (_("(in class)")); break;
3361 case DW_DEFAULTED_out_of_class
: printf (_("(out of class)")); break;
3362 default: printf (_("(unrecognised)")); break;
3366 case DW_AT_discr_list
:
3368 display_discr_list (form
, uvalue
, data
, level
);
3371 case DW_AT_frame_base
:
3372 have_frame_base
= 1;
3374 case DW_AT_location
:
3375 case DW_AT_loclists_base
:
3376 case DW_AT_rnglists_base
:
3377 case DW_AT_str_offsets_base
:
3378 case DW_AT_string_length
:
3379 case DW_AT_return_addr
:
3380 case DW_AT_data_member_location
:
3381 case DW_AT_vtable_elem_location
:
3383 case DW_AT_static_link
:
3384 case DW_AT_use_location
:
3385 case DW_AT_call_value
:
3386 case DW_AT_GNU_call_site_value
:
3387 case DW_AT_call_data_value
:
3388 case DW_AT_GNU_call_site_data_value
:
3389 case DW_AT_call_target
:
3390 case DW_AT_GNU_call_site_target
:
3391 case DW_AT_call_target_clobbered
:
3392 case DW_AT_GNU_call_site_target_clobbered
:
3393 if ((dwarf_version
< 4
3394 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
3395 || form
== DW_FORM_sec_offset
3396 || form
== DW_FORM_loclistx
)
3398 if (attribute
!= DW_AT_rnglists_base
3399 && attribute
!= DW_AT_str_offsets_base
)
3400 printf (_(" (location list)"));
3403 case DW_AT_allocated
:
3404 case DW_AT_associated
:
3405 case DW_AT_data_location
:
3407 case DW_AT_upper_bound
:
3408 case DW_AT_lower_bound
:
3412 int need_frame_base
;
3415 need_frame_base
= decode_location_expression (block_start
,
3420 cu_offset
, section
);
3422 if (need_frame_base
&& !have_frame_base
)
3423 printf (_(" [without DW_AT_frame_base]"));
3427 case DW_AT_data_bit_offset
:
3428 case DW_AT_byte_size
:
3429 case DW_AT_bit_size
:
3430 case DW_AT_string_length_byte_size
:
3431 case DW_AT_string_length_bit_size
:
3432 case DW_AT_bit_stride
:
3433 if (form
== DW_FORM_exprloc
)
3436 (void) decode_location_expression (block_start
, pointer_size
,
3437 offset_size
, dwarf_version
,
3438 uvalue
, cu_offset
, section
);
3445 unsigned long abbrev_number
;
3446 abbrev_entry
*entry
;
3448 entry
= get_type_abbrev_from_form (form
, uvalue
, cu_offset
, end
,
3449 section
, & abbrev_number
, NULL
, NULL
);
3452 if (form
!= DW_FORM_GNU_ref_alt
)
3453 warn (_("Offset %#" PRIx64
" used as value for DW_AT_import attribute of DIE at offset %#tx is too big.\n"),
3455 orig_data
- section
->start
);
3459 printf (_("\t[Abbrev Number: %ld"), abbrev_number
);
3460 printf (" (%s)", get_TAG_name (entry
->tag
));
3473 static unsigned char *
3474 read_and_display_attr (unsigned long attribute
,
3476 int64_t implicit_const
,
3477 unsigned char *start
,
3478 unsigned char *data
,
3481 uint64_t pointer_size
,
3482 uint64_t offset_size
,
3484 debug_info
*debug_info_p
,
3486 struct dwarf_section
*section
,
3487 struct cu_tu_set
*this_set
,
3491 printf (" %-18s:", get_AT_name (attribute
));
3492 data
= read_and_display_attr_value (attribute
, form
, implicit_const
,
3494 cu_offset
, pointer_size
, offset_size
,
3495 dwarf_version
, debug_info_p
,
3496 do_loc
, section
, this_set
, ' ', level
);
3502 /* Like load_debug_section, but if the ordinary call fails, and we are
3503 following debug links, then attempt to load the requested section
3504 from one of the separate debug info files. */
3507 load_debug_section_with_follow (enum dwarf_section_display_enum sec_enum
,
3510 if (load_debug_section (sec_enum
, handle
))
3512 if (debug_displays
[sec_enum
].section
.filename
== NULL
)
3514 /* See if we can associate a filename with this section. */
3517 for (i
= first_separate_info
; i
!= NULL
; i
= i
->next
)
3518 if (i
->handle
== handle
)
3520 debug_displays
[sec_enum
].section
.filename
= i
->filename
;
3528 if (do_follow_links
)
3532 for (i
= first_separate_info
; i
!= NULL
; i
= i
->next
)
3534 if (load_debug_section (sec_enum
, i
->handle
))
3536 debug_displays
[sec_enum
].section
.filename
= i
->filename
;
3538 /* FIXME: We should check to see if any of the remaining debug info
3539 files also contain this section, and, umm, do something about it. */
3549 introduce (struct dwarf_section
* section
, bool raw
)
3553 if (do_follow_links
&& section
->filename
)
3554 printf (_("Raw dump of debug contents of section %s (loaded from %s):\n\n"),
3555 section
->name
, section
->filename
);
3557 printf (_("Raw dump of debug contents of section %s:\n\n"), section
->name
);
3561 if (do_follow_links
&& section
->filename
)
3562 printf (_("Contents of the %s section (loaded from %s):\n\n"),
3563 section
->name
, section
->filename
);
3565 printf (_("Contents of the %s section:\n\n"), section
->name
);
3569 /* Free memory allocated for one unit in debug_information. */
3572 free_debug_information (debug_info
*ent
)
3574 if (ent
->max_loc_offsets
)
3576 free (ent
->loc_offsets
);
3577 free (ent
->loc_views
);
3578 free (ent
->have_frame_base
);
3580 if (ent
->max_range_lists
)
3582 free (ent
->range_lists
);
3586 /* For look-ahead in attributes. When you want to scan a DIE for one specific
3587 attribute and ignore the rest. */
3589 static unsigned char *
3590 skip_attribute (unsigned long form
,
3591 unsigned char * data
,
3592 unsigned char * end
,
3593 uint64_t pointer_size
,
3594 uint64_t offset_size
,
3602 case DW_FORM_ref_addr
:
3603 inc
= dwarf_version
== 2 ? pointer_size
: offset_size
;
3608 case DW_FORM_strp_sup
:
3610 case DW_FORM_line_strp
:
3611 case DW_FORM_sec_offset
:
3612 case DW_FORM_GNU_ref_alt
:
3613 case DW_FORM_GNU_strp_alt
:
3620 case DW_FORM_addrx1
:
3626 case DW_FORM_addrx2
:
3630 case DW_FORM_addrx3
:
3633 case DW_FORM_ref_sup4
:
3637 case DW_FORM_addrx4
:
3640 case DW_FORM_ref_sup8
:
3643 case DW_FORM_ref_sig8
:
3646 case DW_FORM_data16
:
3650 SKIP_SLEB (data
, end
);
3652 case DW_FORM_GNU_str_index
:
3654 case DW_FORM_ref_udata
:
3656 case DW_FORM_GNU_addr_index
:
3658 case DW_FORM_loclistx
:
3659 case DW_FORM_rnglistx
:
3660 SKIP_ULEB (data
, end
);
3662 case DW_FORM_indirect
:
3663 while (form
== DW_FORM_indirect
)
3664 READ_ULEB (form
, data
, end
);
3665 return skip_attribute (form
, data
, end
, pointer_size
, offset_size
,
3668 case DW_FORM_string
:
3669 inc
= strnlen ((char *) data
, end
- data
);
3672 case DW_FORM_exprloc
:
3673 READ_ULEB (temp
, data
, end
);
3676 case DW_FORM_block1
:
3677 SAFE_BYTE_GET_AND_INC (temp
, data
, 1, end
);
3680 case DW_FORM_block2
:
3681 SAFE_BYTE_GET_AND_INC (temp
, data
, 2, end
);
3684 case DW_FORM_block4
:
3685 SAFE_BYTE_GET_AND_INC (temp
, data
, 4, end
);
3688 case DW_FORM_implicit_const
:
3689 case DW_FORM_flag_present
:
3692 warn (_("Unexpected form in top DIE\n"));
3695 if (inc
<= (size_t) (end
- data
))
3703 read_bases (abbrev_entry
* entry
,
3704 unsigned char * data
,
3705 unsigned char * end
,
3706 int64_t pointer_size
,
3707 uint64_t offset_size
,
3709 debug_info
* debug_info_p
)
3713 for (attr
= entry
->first_attr
;
3714 attr
&& attr
->attribute
;
3719 if (attr
->attribute
== DW_AT_rnglists_base
)
3721 if (attr
->form
== DW_FORM_sec_offset
)
3723 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
3724 debug_info_p
->rnglists_base
= uvalue
;
3727 warn (_("Unexpected form of DW_AT_rnglists_base in the top DIE\n"));
3729 else if (attr
->attribute
== DW_AT_addr_base
3730 || attr
->attribute
== DW_AT_GNU_addr_base
)
3732 if (attr
->form
== DW_FORM_sec_offset
)
3734 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
3735 debug_info_p
->addr_base
= uvalue
;
3738 warn (_("Unexpected form of DW_AT_addr_base in the top DIE\n"));
3741 data
= skip_attribute (attr
->form
, data
, end
, pointer_size
,
3742 offset_size
, dwarf_version
);
3746 /* Process the contents of a .debug_info section.
3747 If do_loc is TRUE then we are scanning for location lists and dwo tags
3748 and we do not want to display anything to the user.
3749 If do_types is TRUE, we are processing a .debug_types section instead of
3750 a .debug_info section.
3751 The information displayed is restricted by the values in DWARF_START_DIE
3752 and DWARF_CUTOFF_LEVEL.
3753 Returns TRUE upon success. Otherwise an error or warning message is
3754 printed and FALSE is returned. */
3757 process_debug_info (struct dwarf_section
* section
,
3759 enum dwarf_section_display_enum abbrev_sec
,
3763 unsigned char *start
= section
->start
;
3764 unsigned char *end
= start
+ section
->size
;
3765 unsigned char *section_begin
;
3767 unsigned int num_units
= 0;
3769 /* First scan the section to get the number of comp units.
3770 Length sanity checks are done here. */
3771 for (section_begin
= start
, num_units
= 0; section_begin
< end
;
3776 /* Read the first 4 bytes. For a 32-bit DWARF section, this
3777 will be the length. For a 64-bit DWARF section, it'll be
3778 the escape code 0xffffffff followed by an 8 byte length. */
3779 SAFE_BYTE_GET_AND_INC (length
, section_begin
, 4, end
);
3781 if (length
== 0xffffffff)
3782 SAFE_BYTE_GET_AND_INC (length
, section_begin
, 8, end
);
3783 else if (length
>= 0xfffffff0 && length
< 0xffffffff)
3785 warn (_("Reserved length value (%#" PRIx64
") found in section %s\n"),
3786 length
, section
->name
);
3790 /* Negative values are illegal, they may even cause infinite
3791 looping. This can happen if we can't accurately apply
3792 relocations to an object file, or if the file is corrupt. */
3793 if (length
> (size_t) (end
- section_begin
))
3795 warn (_("Corrupt unit length (got %#" PRIx64
3796 " expected at most %#tx) in section %s\n"),
3797 length
, end
- section_begin
, section
->name
);
3800 section_begin
+= length
;
3805 error (_("No comp units in %s section ?\n"), section
->name
);
3809 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
|| do_debug_info
)
3810 && alloc_num_debug_info_entries
== 0
3813 /* Then allocate an array to hold the information. */
3814 debug_information
= cmalloc (num_units
, sizeof (*debug_information
));
3815 if (debug_information
== NULL
)
3817 error (_("Not enough memory for a debug info array of %u entries\n"),
3819 alloc_num_debug_info_entries
= num_debug_info_entries
= 0;
3823 /* PR 17531: file: 92ca3797.
3824 We cannot rely upon the debug_information array being initialised
3825 before it is used. A corrupt file could easily contain references
3826 to a unit for which information has not been made available. So
3827 we ensure that the array is zeroed here. */
3828 memset (debug_information
, 0, num_units
* sizeof (*debug_information
));
3830 alloc_num_debug_info_entries
= num_units
;
3835 load_debug_section_with_follow (str
, file
);
3836 load_debug_section_with_follow (line_str
, file
);
3837 load_debug_section_with_follow (str_dwo
, file
);
3838 load_debug_section_with_follow (str_index
, file
);
3839 load_debug_section_with_follow (str_index_dwo
, file
);
3840 load_debug_section_with_follow (debug_addr
, file
);
3843 load_debug_section_with_follow (abbrev_sec
, file
);
3844 load_debug_section_with_follow (loclists
, file
);
3845 load_debug_section_with_follow (rnglists
, file
);
3846 load_debug_section_with_follow (loclists_dwo
, file
);
3847 load_debug_section_with_follow (rnglists_dwo
, file
);
3849 if (debug_displays
[abbrev_sec
].section
.start
== NULL
)
3851 warn (_("Unable to locate %s section!\n"),
3852 debug_displays
[abbrev_sec
].section
.uncompressed_name
);
3856 if (!do_loc
&& dwarf_start_die
== 0)
3857 introduce (section
, false);
3859 free_all_abbrevs ();
3861 /* In order to be able to resolve DW_FORM_ref_addr forms we need
3862 to load *all* of the abbrevs for all CUs in this .debug_info
3863 section. This does effectively mean that we (partially) read
3864 every CU header twice. */
3865 for (section_begin
= start
; start
< end
;)
3867 DWARF2_Internal_CompUnit compunit
;
3868 unsigned char *hdrptr
;
3869 uint64_t abbrev_base
;
3872 unsigned int offset_size
;
3873 struct cu_tu_set
*this_set
;
3874 unsigned char *end_cu
;
3877 cu_offset
= start
- section_begin
;
3879 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 4, end
);
3881 if (compunit
.cu_length
== 0xffffffff)
3883 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 8, end
);
3888 end_cu
= hdrptr
+ compunit
.cu_length
;
3890 SAFE_BYTE_GET_AND_INC (compunit
.cu_version
, hdrptr
, 2, end_cu
);
3892 this_set
= find_cu_tu_set_v2 (cu_offset
, do_types
);
3894 if (compunit
.cu_version
< 5)
3896 compunit
.cu_unit_type
= DW_UT_compile
;
3897 /* Initialize it due to a false compiler warning. */
3898 compunit
.cu_pointer_size
= -1;
3902 SAFE_BYTE_GET_AND_INC (compunit
.cu_unit_type
, hdrptr
, 1, end_cu
);
3903 do_types
= (compunit
.cu_unit_type
== DW_UT_type
);
3905 SAFE_BYTE_GET_AND_INC (compunit
.cu_pointer_size
, hdrptr
, 1, end_cu
);
3908 SAFE_BYTE_GET_AND_INC (compunit
.cu_abbrev_offset
, hdrptr
, offset_size
,
3911 if (compunit
.cu_unit_type
== DW_UT_split_compile
3912 || compunit
.cu_unit_type
== DW_UT_skeleton
)
3915 SAFE_BYTE_GET_AND_INC (dwo_id
, hdrptr
, 8, end_cu
);
3918 if (this_set
== NULL
)
3921 abbrev_size
= debug_displays
[abbrev_sec
].section
.size
;
3925 abbrev_base
= this_set
->section_offsets
[DW_SECT_ABBREV
];
3926 abbrev_size
= this_set
->section_sizes
[DW_SECT_ABBREV
];
3930 abbrev_list
*free_list
;
3931 list
= find_and_process_abbrev_set (&debug_displays
[abbrev_sec
].section
,
3932 abbrev_base
, abbrev_size
,
3933 compunit
.cu_abbrev_offset
,
3936 if (list
!= NULL
&& list
->first_abbrev
!= NULL
)
3937 record_abbrev_list_for_cu (cu_offset
, start
- section_begin
,
3939 else if (free_list
!= NULL
)
3940 free_abbrev_list (free_list
);
3943 for (start
= section_begin
, unit
= 0; start
< end
; unit
++)
3945 DWARF2_Internal_CompUnit compunit
;
3946 unsigned char *hdrptr
;
3947 unsigned char *tags
;
3948 int level
, last_level
, saved_level
;
3950 unsigned int offset_size
;
3951 uint64_t signature
= 0;
3952 uint64_t type_offset
= 0;
3953 struct cu_tu_set
*this_set
;
3954 uint64_t abbrev_base
;
3956 unsigned char *end_cu
;
3959 cu_offset
= start
- section_begin
;
3961 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 4, end
);
3963 if (compunit
.cu_length
== 0xffffffff)
3965 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 8, end
);
3970 end_cu
= hdrptr
+ compunit
.cu_length
;
3972 SAFE_BYTE_GET_AND_INC (compunit
.cu_version
, hdrptr
, 2, end_cu
);
3974 this_set
= find_cu_tu_set_v2 (cu_offset
, do_types
);
3976 if (compunit
.cu_version
< 5)
3978 compunit
.cu_unit_type
= DW_UT_compile
;
3979 /* Initialize it due to a false compiler warning. */
3980 compunit
.cu_pointer_size
= -1;
3984 SAFE_BYTE_GET_AND_INC (compunit
.cu_unit_type
, hdrptr
, 1, end_cu
);
3985 do_types
= (compunit
.cu_unit_type
== DW_UT_type
);
3987 SAFE_BYTE_GET_AND_INC (compunit
.cu_pointer_size
, hdrptr
, 1, end_cu
);
3990 SAFE_BYTE_GET_AND_INC (compunit
.cu_abbrev_offset
, hdrptr
, offset_size
, end_cu
);
3992 if (this_set
== NULL
)
3995 abbrev_size
= debug_displays
[abbrev_sec
].section
.size
;
3999 abbrev_base
= this_set
->section_offsets
[DW_SECT_ABBREV
];
4000 abbrev_size
= this_set
->section_sizes
[DW_SECT_ABBREV
];
4003 if (compunit
.cu_version
< 5)
4004 SAFE_BYTE_GET_AND_INC (compunit
.cu_pointer_size
, hdrptr
, 1, end_cu
);
4006 bool do_dwo_id
= false;
4007 uint64_t dwo_id
= 0;
4008 if (compunit
.cu_unit_type
== DW_UT_split_compile
4009 || compunit
.cu_unit_type
== DW_UT_skeleton
)
4011 SAFE_BYTE_GET_AND_INC (dwo_id
, hdrptr
, 8, end_cu
);
4015 /* PR 17512: file: 001-108546-0.001:0.1. */
4016 if (compunit
.cu_pointer_size
< 2 || compunit
.cu_pointer_size
> 8)
4018 warn (_("Invalid pointer size (%d) in compunit header, using %d instead\n"),
4019 compunit
.cu_pointer_size
, offset_size
);
4020 compunit
.cu_pointer_size
= offset_size
;
4025 SAFE_BYTE_GET_AND_INC (signature
, hdrptr
, 8, end_cu
);
4026 SAFE_BYTE_GET_AND_INC (type_offset
, hdrptr
, offset_size
, end_cu
);
4029 if (dwarf_start_die
>= (size_t) (end_cu
- section_begin
))
4035 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
|| do_debug_info
)
4036 && num_debug_info_entries
== 0
4037 && alloc_num_debug_info_entries
> unit
4040 free_debug_information (&debug_information
[unit
]);
4041 memset (&debug_information
[unit
], 0, sizeof (*debug_information
));
4042 debug_information
[unit
].pointer_size
= compunit
.cu_pointer_size
;
4043 debug_information
[unit
].offset_size
= offset_size
;
4044 debug_information
[unit
].dwarf_version
= compunit
.cu_version
;
4045 debug_information
[unit
].cu_offset
= cu_offset
;
4046 debug_information
[unit
].addr_base
= DEBUG_INFO_UNAVAILABLE
;
4047 debug_information
[unit
].ranges_base
= DEBUG_INFO_UNAVAILABLE
;
4050 if (!do_loc
&& dwarf_start_die
== 0)
4052 printf (_(" Compilation Unit @ offset %#" PRIx64
":\n"),
4054 printf (_(" Length: %#" PRIx64
" (%s)\n"),
4056 offset_size
== 8 ? "64-bit" : "32-bit");
4057 printf (_(" Version: %d\n"), compunit
.cu_version
);
4058 if (compunit
.cu_version
>= 5)
4060 const char *name
= get_DW_UT_name (compunit
.cu_unit_type
);
4062 printf (_(" Unit Type: %s (%x)\n"),
4064 compunit
.cu_unit_type
);
4066 printf (_(" Abbrev Offset: %#" PRIx64
"\n"),
4067 compunit
.cu_abbrev_offset
);
4068 printf (_(" Pointer Size: %d\n"), compunit
.cu_pointer_size
);
4071 printf (_(" Signature: %#" PRIx64
"\n"), signature
);
4072 printf (_(" Type Offset: %#" PRIx64
"\n"), type_offset
);
4075 printf (_(" DWO ID: %#" PRIx64
"\n"), dwo_id
);
4076 if (this_set
!= NULL
)
4078 uint64_t *offsets
= this_set
->section_offsets
;
4079 size_t *sizes
= this_set
->section_sizes
;
4081 printf (_(" Section contributions:\n"));
4082 printf (_(" .debug_abbrev.dwo: %#" PRIx64
" %#zx\n"),
4083 offsets
[DW_SECT_ABBREV
], sizes
[DW_SECT_ABBREV
]);
4084 printf (_(" .debug_line.dwo: %#" PRIx64
" %#zx\n"),
4085 offsets
[DW_SECT_LINE
], sizes
[DW_SECT_LINE
]);
4086 printf (_(" .debug_loc.dwo: %#" PRIx64
" %#zx\n"),
4087 offsets
[DW_SECT_LOC
], sizes
[DW_SECT_LOC
]);
4088 printf (_(" .debug_str_offsets.dwo: %#" PRIx64
" %#zx\n"),
4089 offsets
[DW_SECT_STR_OFFSETS
], sizes
[DW_SECT_STR_OFFSETS
]);
4096 if (compunit
.cu_version
< 2 || compunit
.cu_version
> 5)
4098 warn (_("CU at offset %#" PRIx64
" contains corrupt or "
4099 "unsupported version number: %d.\n"),
4100 cu_offset
, compunit
.cu_version
);
4104 if (compunit
.cu_unit_type
!= DW_UT_compile
4105 && compunit
.cu_unit_type
!= DW_UT_partial
4106 && compunit
.cu_unit_type
!= DW_UT_type
4107 && compunit
.cu_unit_type
!= DW_UT_split_compile
4108 && compunit
.cu_unit_type
!= DW_UT_skeleton
)
4110 warn (_("CU at offset %#" PRIx64
" contains corrupt or "
4111 "unsupported unit type: %d.\n"),
4112 cu_offset
, compunit
.cu_unit_type
);
4116 /* Process the abbrevs used by this compilation unit. */
4118 list
= find_and_process_abbrev_set (&debug_displays
[abbrev_sec
].section
,
4119 abbrev_base
, abbrev_size
,
4120 compunit
.cu_abbrev_offset
, NULL
);
4124 while (tags
< start
)
4126 unsigned long abbrev_number
;
4127 unsigned long die_offset
;
4128 abbrev_entry
*entry
;
4130 int do_printing
= 1;
4132 die_offset
= tags
- section_begin
;
4134 READ_ULEB (abbrev_number
, tags
, start
);
4136 /* A null DIE marks the end of a list of siblings or it may also be
4137 a section padding. */
4138 if (abbrev_number
== 0)
4140 /* Check if it can be a section padding for the last CU. */
4141 if (level
== 0 && start
== end
)
4145 for (chk
= tags
; chk
< start
; chk
++)
4152 if (!do_loc
&& die_offset
>= dwarf_start_die
4153 && (dwarf_cutoff_level
== -1
4154 || level
< dwarf_cutoff_level
))
4155 printf (_(" <%d><%lx>: Abbrev Number: 0\n"),
4161 static unsigned num_bogus_warns
= 0;
4163 if (num_bogus_warns
< 3)
4165 warn (_("Bogus end-of-siblings marker detected at offset %lx in %s section\n"),
4166 die_offset
, section
->name
);
4168 if (num_bogus_warns
== 3)
4169 warn (_("Further warnings about bogus end-of-sibling markers suppressed\n"));
4172 if (dwarf_start_die
!= 0 && level
< saved_level
)
4175 free_abbrev_list (list
);
4183 if (dwarf_start_die
!= 0 && die_offset
< dwarf_start_die
)
4187 if (dwarf_start_die
!= 0 && die_offset
== dwarf_start_die
)
4188 saved_level
= level
;
4189 do_printing
= (dwarf_cutoff_level
== -1
4190 || level
< dwarf_cutoff_level
);
4192 printf (_(" <%d><%lx>: Abbrev Number: %lu"),
4193 level
, die_offset
, abbrev_number
);
4194 else if (dwarf_cutoff_level
== -1
4195 || last_level
< dwarf_cutoff_level
)
4196 printf (_(" <%d><%lx>: ...\n"), level
, die_offset
);
4201 /* Scan through the abbreviation list until we reach the
4205 for (entry
= list
->first_abbrev
; entry
!= NULL
; entry
= entry
->next
)
4206 if (entry
->number
== abbrev_number
)
4211 if (!do_loc
&& do_printing
)
4216 warn (_("DIE at offset %#lx refers to abbreviation number %lu which does not exist\n"),
4217 die_offset
, abbrev_number
);
4219 free_abbrev_list (list
);
4223 if (!do_loc
&& do_printing
)
4224 printf (" (%s)\n", get_TAG_name (entry
->tag
));
4229 need_base_address
= 0;
4231 case DW_TAG_compile_unit
:
4232 case DW_TAG_skeleton_unit
:
4233 need_base_address
= 1;
4234 need_dwo_info
= do_loc
;
4236 case DW_TAG_entry_point
:
4237 need_base_address
= 0;
4238 /* Assuming that there is no DW_AT_frame_base. */
4239 have_frame_base
= 0;
4241 case DW_TAG_subprogram
:
4242 need_base_address
= 0;
4243 if (level
<= frame_base_level
)
4244 /* Don't reset that for nested subprogram. */
4245 have_frame_base
= 0;
4249 debug_info
*debug_info_p
= ((debug_information
4250 && unit
< alloc_num_debug_info_entries
)
4251 ? debug_information
+ unit
: NULL
);
4253 assert (!debug_info_p
4254 || (debug_info_p
->num_loc_offsets
4255 == debug_info_p
->num_loc_views
));
4257 /* Look ahead so that the values of DW_AT_rnglists_base,
4258 DW_AT_[GNU_]addr_base are available before attributes that
4259 reference them are parsed in the same DIE.
4260 Only needed for the top DIE on DWARFv5+.
4261 No simiar treatment for loclists_base because there should
4262 be no loclist attributes in top DIE. */
4263 if (debug_info_p
&& compunit
.cu_version
>= 5 && level
== 0)
4270 compunit
.cu_pointer_size
,
4272 compunit
.cu_version
,
4275 /* This check was in place before, keep it. */
4276 stemp
= debug_info_p
->rnglists_base
;
4279 warn (_("CU @ %#" PRIx64
" has has a negative rnglists_base "
4280 "value of %#" PRIx64
" - treating as zero\n"),
4281 debug_info_p
->cu_offset
, stemp
);
4282 debug_info_p
->rnglists_base
= 0;
4286 for (attr
= entry
->first_attr
;
4287 attr
&& attr
->attribute
;
4290 if (! do_loc
&& do_printing
)
4291 /* Show the offset from where the tag was extracted. */
4292 printf (" <%tx>", tags
- section_begin
);
4293 tags
= read_and_display_attr (attr
->attribute
,
4295 attr
->implicit_const
,
4300 compunit
.cu_pointer_size
,
4302 compunit
.cu_version
,
4304 do_loc
|| ! do_printing
,
4310 /* If a locview attribute appears before a location one,
4311 make sure we don't associate it with an earlier
4314 switch (debug_info_p
->num_loc_offsets
- debug_info_p
->num_loc_views
)
4317 debug_info_p
->loc_views
[debug_info_p
->num_loc_views
] = -1;
4318 debug_info_p
->num_loc_views
++;
4319 assert (debug_info_p
->num_loc_views
4320 == debug_info_p
->num_loc_offsets
);
4327 warn (_("DIE has locviews without loclist\n"));
4328 debug_info_p
->num_loc_views
--;
4335 if (entry
->children
)
4339 free_abbrev_list (list
);
4342 /* Set num_debug_info_entries here so that it can be used to check if
4343 we need to process .debug_loc and .debug_ranges sections. */
4344 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
|| do_debug_info
)
4345 && num_debug_info_entries
== 0
4348 if (num_units
> alloc_num_debug_info_entries
)
4349 num_debug_info_entries
= alloc_num_debug_info_entries
;
4351 num_debug_info_entries
= num_units
;
4360 /* Locate and scan the .debug_info section in the file and record the pointer
4361 sizes and offsets for the compilation units in it. Usually an executable
4362 will have just one pointer size, but this is not guaranteed, and so we try
4363 not to make any assumptions. Returns zero upon failure, or the number of
4364 compilation units upon success. */
4367 load_debug_info (void * file
)
4369 /* If we have already tried and failed to load the .debug_info
4370 section then do not bother to repeat the task. */
4371 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
4374 /* If we already have the information there is nothing else to do. */
4375 if (num_debug_info_entries
> 0)
4376 return num_debug_info_entries
;
4378 /* If this is a DWARF package file, load the CU and TU indexes. */
4379 (void) load_cu_tu_indexes (file
);
4381 if (load_debug_section_with_follow (info
, file
)
4382 && process_debug_info (&debug_displays
[info
].section
, file
, abbrev
, true, false))
4383 return num_debug_info_entries
;
4385 if (load_debug_section_with_follow (info_dwo
, file
)
4386 && process_debug_info (&debug_displays
[info_dwo
].section
, file
,
4387 abbrev_dwo
, true, false))
4388 return num_debug_info_entries
;
4390 num_debug_info_entries
= DEBUG_INFO_UNAVAILABLE
;
4394 /* Read a DWARF .debug_line section header starting at DATA.
4395 Upon success returns an updated DATA pointer and the LINFO
4396 structure and the END_OF_SEQUENCE pointer will be filled in.
4397 Otherwise returns NULL. */
4399 static unsigned char *
4400 read_debug_line_header (struct dwarf_section
* section
,
4401 unsigned char * data
,
4402 unsigned char * end
,
4403 DWARF2_Internal_LineInfo
* linfo
,
4404 unsigned char ** end_of_sequence
)
4406 unsigned char *hdrptr
;
4408 /* Extract information from the Line Number Program Header.
4409 (section 6.2.4 in the Dwarf3 doc). */
4412 /* Get and check the length of the block. */
4413 SAFE_BYTE_GET_AND_INC (linfo
->li_length
, hdrptr
, 4, end
);
4415 if (linfo
->li_length
== 0xffffffff)
4417 /* This section is 64-bit DWARF 3. */
4418 SAFE_BYTE_GET_AND_INC (linfo
->li_length
, hdrptr
, 8, end
);
4419 linfo
->li_offset_size
= 8;
4422 linfo
->li_offset_size
= 4;
4424 if (linfo
->li_length
> (size_t) (end
- hdrptr
))
4426 /* If the length field has a relocation against it, then we should
4427 not complain if it is inaccurate (and probably negative). This
4428 happens in object files when the .debug_line section is actually
4429 comprised of several different .debug_line.* sections, (some of
4430 which may be removed by linker garbage collection), and a relocation
4431 is used to compute the correct length once that is done. */
4432 if (reloc_at (section
, (hdrptr
- section
->start
) - linfo
->li_offset_size
))
4434 linfo
->li_length
= end
- hdrptr
;
4438 warn (_("The length field (%#" PRIx64
")"
4439 " in the debug_line header is wrong"
4440 " - the section is too small\n"),
4445 end
= hdrptr
+ linfo
->li_length
;
4447 /* Get and check the version number. */
4448 SAFE_BYTE_GET_AND_INC (linfo
->li_version
, hdrptr
, 2, end
);
4450 if (linfo
->li_version
!= 2
4451 && linfo
->li_version
!= 3
4452 && linfo
->li_version
!= 4
4453 && linfo
->li_version
!= 5)
4455 warn (_("Only DWARF version 2, 3, 4 and 5 line info "
4456 "is currently supported.\n"));
4460 if (linfo
->li_version
>= 5)
4462 SAFE_BYTE_GET_AND_INC (linfo
->li_address_size
, hdrptr
, 1, end
);
4464 SAFE_BYTE_GET_AND_INC (linfo
->li_segment_size
, hdrptr
, 1, end
);
4465 if (linfo
->li_segment_size
!= 0)
4467 warn (_("The %s section contains "
4468 "unsupported segment selector size: %d.\n"),
4469 section
->name
, linfo
->li_segment_size
);
4474 SAFE_BYTE_GET_AND_INC (linfo
->li_prologue_length
, hdrptr
,
4475 linfo
->li_offset_size
, end
);
4476 SAFE_BYTE_GET_AND_INC (linfo
->li_min_insn_length
, hdrptr
, 1, end
);
4478 if (linfo
->li_version
>= 4)
4480 SAFE_BYTE_GET_AND_INC (linfo
->li_max_ops_per_insn
, hdrptr
, 1, end
);
4482 if (linfo
->li_max_ops_per_insn
== 0)
4484 warn (_("Invalid maximum operations per insn.\n"));
4489 linfo
->li_max_ops_per_insn
= 1;
4491 SAFE_BYTE_GET_AND_INC (linfo
->li_default_is_stmt
, hdrptr
, 1, end
);
4492 SAFE_SIGNED_BYTE_GET_AND_INC (linfo
->li_line_base
, hdrptr
, 1, end
);
4493 SAFE_BYTE_GET_AND_INC (linfo
->li_line_range
, hdrptr
, 1, end
);
4494 SAFE_BYTE_GET_AND_INC (linfo
->li_opcode_base
, hdrptr
, 1, end
);
4496 *end_of_sequence
= end
;
4500 static unsigned char *
4501 display_formatted_table (unsigned char *data
,
4502 unsigned char *start
,
4504 const DWARF2_Internal_LineInfo
*linfo
,
4505 struct dwarf_section
*section
,
4508 unsigned char *format_start
, format_count
, *format
, formati
;
4509 uint64_t data_count
, datai
;
4510 unsigned int namepass
, last_entry
= 0;
4511 const char * table_name
= is_dir
? N_("Directory Table") : N_("File Name Table");
4513 SAFE_BYTE_GET_AND_INC (format_count
, data
, 1, end
);
4514 if (do_checks
&& format_count
> 5)
4515 warn (_("Unexpectedly large number of columns in the %s (%u)\n"),
4516 table_name
, format_count
);
4518 format_start
= data
;
4519 for (formati
= 0; formati
< format_count
; formati
++)
4521 SKIP_ULEB (data
, end
);
4522 SKIP_ULEB (data
, end
);
4525 warn (_("%s: Corrupt format description entry\n"), table_name
);
4530 READ_ULEB (data_count
, data
, end
);
4531 if (data_count
== 0)
4533 printf (_("\n The %s is empty.\n"), table_name
);
4536 else if (data
>= end
4537 || data_count
> (size_t) (end
- data
))
4539 warn (_("%s: Corrupt entry count %#" PRIx64
"\n"), table_name
, data_count
);
4543 else if (format_count
== 0)
4545 warn (_("%s: format count is zero, but the table is not empty\n"),
4550 printf (_("\n The %s (offset %#tx, lines %" PRIu64
", columns %u):\n"),
4551 table_name
, data
- start
, data_count
, format_count
);
4553 printf (_(" Entry"));
4554 /* Delay displaying name as the last entry for better screen layout. */
4555 for (namepass
= 0; namepass
< 2; namepass
++)
4557 format
= format_start
;
4558 for (formati
= 0; formati
< format_count
; formati
++)
4560 uint64_t content_type
;
4562 READ_ULEB (content_type
, format
, end
);
4563 if ((content_type
== DW_LNCT_path
) == (namepass
== 1))
4564 switch (content_type
)
4567 printf (_("\tName"));
4569 case DW_LNCT_directory_index
:
4570 printf (_("\tDir"));
4572 case DW_LNCT_timestamp
:
4573 printf (_("\tTime"));
4576 printf (_("\tSize"));
4579 printf (_("\tMD5\t\t\t"));
4582 printf (_("\t(Unknown format content type %" PRIu64
")"),
4585 SKIP_ULEB (format
, end
);
4590 for (datai
= 0; datai
< data_count
; datai
++)
4592 unsigned char *datapass
= data
;
4594 printf (" %d", last_entry
++);
4595 /* Delay displaying name as the last entry for better screen layout. */
4596 for (namepass
= 0; namepass
< 2; namepass
++)
4598 format
= format_start
;
4600 for (formati
= 0; formati
< format_count
; formati
++)
4602 uint64_t content_type
, form
;
4604 READ_ULEB (content_type
, format
, end
);
4605 READ_ULEB (form
, format
, end
);
4606 data
= read_and_display_attr_value (0, form
, 0, start
, data
, end
,
4607 0, 0, linfo
->li_offset_size
,
4608 linfo
->li_version
, NULL
,
4609 ((content_type
== DW_LNCT_path
) != (namepass
== 1)),
4610 section
, NULL
, '\t', -1);
4614 if (data
>= end
&& (datai
< data_count
- 1))
4616 warn (_("\n%s: Corrupt entries list\n"), table_name
);
4625 display_debug_sup (struct dwarf_section
* section
,
4626 void * file ATTRIBUTE_UNUSED
)
4628 unsigned char * start
= section
->start
;
4629 unsigned char * end
= section
->start
+ section
->size
;
4630 unsigned int version
;
4631 char is_supplementary
;
4632 const unsigned char * sup_filename
;
4633 size_t sup_filename_len
;
4634 unsigned int num_read
;
4636 uint64_t checksum_len
;
4639 introduce (section
, true);
4640 if (section
->size
< 4)
4642 error (_("corrupt .debug_sup section: size is too small\n"));
4646 /* Read the data. */
4647 SAFE_BYTE_GET_AND_INC (version
, start
, 2, end
);
4649 warn (_("corrupt .debug_sup section: version < 5\n"));
4651 SAFE_BYTE_GET_AND_INC (is_supplementary
, start
, 1, end
);
4652 if (is_supplementary
!= 0 && is_supplementary
!= 1)
4653 warn (_("corrupt .debug_sup section: is_supplementary not 0 or 1\n"));
4655 sup_filename
= start
;
4656 if (is_supplementary
&& sup_filename
[0] != 0)
4657 warn (_("corrupt .debug_sup section: filename not empty in supplementary section\n"));
4659 sup_filename_len
= strnlen ((const char *) start
, end
- start
);
4660 if (sup_filename_len
== (size_t) (end
- start
))
4662 error (_("corrupt .debug_sup section: filename is not NUL terminated\n"));
4665 start
+= sup_filename_len
+ 1;
4667 checksum_len
= read_leb128 (start
, end
, false /* unsigned */, & num_read
, & status
);
4670 error (_("corrupt .debug_sup section: bad LEB128 field for checksum length\n"));
4674 if (checksum_len
> (size_t) (end
- start
))
4676 error (_("corrupt .debug_sup section: checksum length is longer than the remaining section length\n"));
4677 checksum_len
= end
- start
;
4679 else if (checksum_len
< (size_t) (end
- start
))
4681 warn (_("corrupt .debug_sup section: there are %#" PRIx64
4682 " extra, unused bytes at the end of the section\n"),
4683 (end
- start
) - checksum_len
);
4686 printf (_(" Version: %u\n"), version
);
4687 printf (_(" Is Supp: %u\n"), is_supplementary
);
4688 printf (_(" Filename: %s\n"), sup_filename
);
4689 printf (_(" Checksum Len: %" PRIu64
"\n"), checksum_len
);
4690 if (checksum_len
> 0)
4692 printf (_(" Checksum: "));
4693 while (checksum_len
--)
4694 printf ("0x%x ", * start
++ );
4701 display_debug_lines_raw (struct dwarf_section
* section
,
4702 unsigned char * data
,
4703 unsigned char * end
,
4706 unsigned char *start
= section
->start
;
4707 int verbose_view
= 0;
4709 introduce (section
, true);
4713 static DWARF2_Internal_LineInfo saved_linfo
;
4714 DWARF2_Internal_LineInfo linfo
;
4715 unsigned char *standard_opcodes
;
4716 unsigned char *end_of_sequence
;
4719 if (startswith (section
->name
, ".debug_line.")
4720 /* Note: the following does not apply to .debug_line.dwo sections.
4721 These are full debug_line sections. */
4722 && strcmp (section
->name
, ".debug_line.dwo") != 0)
4724 /* Sections named .debug_line.<foo> are fragments of a .debug_line
4725 section containing just the Line Number Statements. They are
4726 created by the assembler and intended to be used alongside gcc's
4727 -ffunction-sections command line option. When the linker's
4728 garbage collection decides to discard a .text.<foo> section it
4729 can then also discard the line number information in .debug_line.<foo>.
4731 Since the section is a fragment it does not have the details
4732 needed to fill out a LineInfo structure, so instead we use the
4733 details from the last full debug_line section that we processed. */
4734 end_of_sequence
= end
;
4735 standard_opcodes
= NULL
;
4736 linfo
= saved_linfo
;
4737 /* PR 17531: file: 0522b371. */
4738 if (linfo
.li_line_range
== 0)
4740 warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n"));
4743 reset_state_machine (linfo
.li_default_is_stmt
);
4747 unsigned char * hdrptr
;
4749 if ((hdrptr
= read_debug_line_header (section
, data
, end
, & linfo
,
4750 & end_of_sequence
)) == NULL
)
4753 printf (_(" Offset: %#tx\n"), data
- start
);
4754 printf (_(" Length: %" PRId64
"\n"), linfo
.li_length
);
4755 printf (_(" DWARF Version: %d\n"), linfo
.li_version
);
4756 if (linfo
.li_version
>= 5)
4758 printf (_(" Address size (bytes): %d\n"), linfo
.li_address_size
);
4759 printf (_(" Segment selector (bytes): %d\n"), linfo
.li_segment_size
);
4761 printf (_(" Prologue Length: %d\n"), (int) linfo
.li_prologue_length
);
4762 printf (_(" Minimum Instruction Length: %d\n"), linfo
.li_min_insn_length
);
4763 if (linfo
.li_version
>= 4)
4764 printf (_(" Maximum Ops per Instruction: %d\n"), linfo
.li_max_ops_per_insn
);
4765 printf (_(" Initial value of 'is_stmt': %d\n"), linfo
.li_default_is_stmt
);
4766 printf (_(" Line Base: %d\n"), linfo
.li_line_base
);
4767 printf (_(" Line Range: %d\n"), linfo
.li_line_range
);
4768 printf (_(" Opcode Base: %d\n"), linfo
.li_opcode_base
);
4770 /* PR 17512: file: 1665-6428-0.004. */
4771 if (linfo
.li_line_range
== 0)
4773 warn (_("Line range of 0 is invalid, using 1 instead\n"));
4774 linfo
.li_line_range
= 1;
4777 reset_state_machine (linfo
.li_default_is_stmt
);
4779 /* Display the contents of the Opcodes table. */
4780 standard_opcodes
= hdrptr
;
4782 /* PR 17512: file: 002-417945-0.004. */
4783 if (standard_opcodes
+ linfo
.li_opcode_base
>= end
)
4785 warn (_("Line Base extends beyond end of section\n"));
4789 printf (_("\n Opcodes:\n"));
4791 for (i
= 1; i
< linfo
.li_opcode_base
; i
++)
4792 printf (ngettext (" Opcode %d has %d arg\n",
4793 " Opcode %d has %d args\n",
4794 standard_opcodes
[i
- 1]),
4795 i
, standard_opcodes
[i
- 1]);
4797 /* Display the contents of the Directory table. */
4798 data
= standard_opcodes
+ linfo
.li_opcode_base
- 1;
4800 if (linfo
.li_version
>= 5)
4802 load_debug_section_with_follow (line_str
, file
);
4804 data
= display_formatted_table (data
, start
, end
, &linfo
, section
,
4806 data
= display_formatted_table (data
, start
, end
, &linfo
, section
,
4812 printf (_("\n The Directory Table is empty.\n"));
4815 unsigned int last_dir_entry
= 0;
4817 printf (_("\n The Directory Table (offset %#tx):\n"),
4820 while (data
< end
&& *data
!= 0)
4822 printf (" %d\t%.*s\n", ++last_dir_entry
, (int) (end
- data
), data
);
4824 data
+= strnlen ((char *) data
, end
- data
);
4829 /* PR 17512: file: 002-132094-0.004. */
4830 if (data
>= end
- 1)
4834 /* Skip the NUL at the end of the table. */
4838 /* Display the contents of the File Name table. */
4839 if (data
>= end
|| *data
== 0)
4840 printf (_("\n The File Name Table is empty.\n"));
4843 printf (_("\n The File Name Table (offset %#tx):\n"),
4845 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
4847 while (data
< end
&& *data
!= 0)
4849 unsigned char *name
;
4852 printf (" %d\t", ++state_machine_regs
.last_file_entry
);
4854 data
+= strnlen ((char *) data
, end
- data
);
4858 READ_ULEB (val
, data
, end
);
4859 printf ("%" PRIu64
"\t", val
);
4860 READ_ULEB (val
, data
, end
);
4861 printf ("%" PRIu64
"\t", val
);
4862 READ_ULEB (val
, data
, end
);
4863 printf ("%" PRIu64
"\t", val
);
4864 printf ("%.*s\n", (int)(end
- name
), name
);
4868 warn (_("Corrupt file name table entry\n"));
4874 /* Skip the NUL at the end of the table. */
4880 saved_linfo
= linfo
;
4883 /* Now display the statements. */
4884 if (data
>= end_of_sequence
)
4885 printf (_(" No Line Number Statements.\n"));
4888 printf (_(" Line Number Statements:\n"));
4890 while (data
< end_of_sequence
)
4892 unsigned char op_code
;
4896 printf (" [0x%08tx]", data
- start
);
4900 if (op_code
>= linfo
.li_opcode_base
)
4902 op_code
-= linfo
.li_opcode_base
;
4903 uladv
= (op_code
/ linfo
.li_line_range
);
4904 if (linfo
.li_max_ops_per_insn
== 1)
4906 uladv
*= linfo
.li_min_insn_length
;
4907 state_machine_regs
.address
+= uladv
;
4909 state_machine_regs
.view
= 0;
4910 printf (_(" Special opcode %d: "
4911 "advance Address by %" PRIu64
4912 " to %#" PRIx64
"%s"),
4913 op_code
, uladv
, state_machine_regs
.address
,
4914 verbose_view
&& uladv
4915 ? _(" (reset view)") : "");
4920 = ((state_machine_regs
.op_index
+ uladv
)
4921 / linfo
.li_max_ops_per_insn
)
4922 * linfo
.li_min_insn_length
;
4924 state_machine_regs
.address
+= addrdelta
;
4925 state_machine_regs
.op_index
4926 = (state_machine_regs
.op_index
+ uladv
)
4927 % linfo
.li_max_ops_per_insn
;
4929 state_machine_regs
.view
= 0;
4930 printf (_(" Special opcode %d: "
4931 "advance Address by %" PRIu64
4932 " to %#" PRIx64
"[%d]%s"),
4933 op_code
, uladv
, state_machine_regs
.address
,
4934 state_machine_regs
.op_index
,
4935 verbose_view
&& addrdelta
4936 ? _(" (reset view)") : "");
4938 adv
= (op_code
% linfo
.li_line_range
) + linfo
.li_line_base
;
4939 state_machine_regs
.line
+= adv
;
4940 printf (_(" and Line by %d to %d"),
4941 adv
, state_machine_regs
.line
);
4942 if (verbose_view
|| state_machine_regs
.view
)
4943 printf (_(" (view %u)\n"), state_machine_regs
.view
);
4946 state_machine_regs
.view
++;
4951 case DW_LNS_extended_op
:
4952 data
+= process_extended_line_op (data
,
4953 linfo
.li_default_is_stmt
,
4958 printf (_(" Copy"));
4959 if (verbose_view
|| state_machine_regs
.view
)
4960 printf (_(" (view %u)\n"), state_machine_regs
.view
);
4963 state_machine_regs
.view
++;
4966 case DW_LNS_advance_pc
:
4967 READ_ULEB (uladv
, data
, end
);
4968 if (linfo
.li_max_ops_per_insn
== 1)
4970 uladv
*= linfo
.li_min_insn_length
;
4971 state_machine_regs
.address
+= uladv
;
4973 state_machine_regs
.view
= 0;
4974 printf (_(" Advance PC by %" PRIu64
4975 " to %#" PRIx64
"%s\n"),
4976 uladv
, state_machine_regs
.address
,
4977 verbose_view
&& uladv
4978 ? _(" (reset view)") : "");
4983 = ((state_machine_regs
.op_index
+ uladv
)
4984 / linfo
.li_max_ops_per_insn
)
4985 * linfo
.li_min_insn_length
;
4986 state_machine_regs
.address
4988 state_machine_regs
.op_index
4989 = (state_machine_regs
.op_index
+ uladv
)
4990 % linfo
.li_max_ops_per_insn
;
4992 state_machine_regs
.view
= 0;
4993 printf (_(" Advance PC by %" PRIu64
4994 " to %#" PRIx64
"[%d]%s\n"),
4995 uladv
, state_machine_regs
.address
,
4996 state_machine_regs
.op_index
,
4997 verbose_view
&& addrdelta
4998 ? _(" (reset view)") : "");
5002 case DW_LNS_advance_line
:
5003 READ_SLEB (adv
, data
, end
);
5004 state_machine_regs
.line
+= adv
;
5005 printf (_(" Advance Line by %d to %d\n"),
5006 adv
, state_machine_regs
.line
);
5009 case DW_LNS_set_file
:
5010 READ_ULEB (uladv
, data
, end
);
5011 printf (_(" Set File Name to entry %" PRIu64
5012 " in the File Name Table\n"), uladv
);
5013 state_machine_regs
.file
= uladv
;
5016 case DW_LNS_set_column
:
5017 READ_ULEB (uladv
, data
, end
);
5018 printf (_(" Set column to %" PRIu64
"\n"), uladv
);
5019 state_machine_regs
.column
= uladv
;
5022 case DW_LNS_negate_stmt
:
5023 adv
= state_machine_regs
.is_stmt
;
5025 printf (_(" Set is_stmt to %d\n"), adv
);
5026 state_machine_regs
.is_stmt
= adv
;
5029 case DW_LNS_set_basic_block
:
5030 printf (_(" Set basic block\n"));
5031 state_machine_regs
.basic_block
= 1;
5034 case DW_LNS_const_add_pc
:
5035 uladv
= ((255 - linfo
.li_opcode_base
) / linfo
.li_line_range
);
5036 if (linfo
.li_max_ops_per_insn
)
5038 uladv
*= linfo
.li_min_insn_length
;
5039 state_machine_regs
.address
+= uladv
;
5041 state_machine_regs
.view
= 0;
5042 printf (_(" Advance PC by constant %" PRIu64
5043 " to %#" PRIx64
"%s\n"),
5044 uladv
, state_machine_regs
.address
,
5045 verbose_view
&& uladv
5046 ? _(" (reset view)") : "");
5051 = ((state_machine_regs
.op_index
+ uladv
)
5052 / linfo
.li_max_ops_per_insn
)
5053 * linfo
.li_min_insn_length
;
5054 state_machine_regs
.address
5056 state_machine_regs
.op_index
5057 = (state_machine_regs
.op_index
+ uladv
)
5058 % linfo
.li_max_ops_per_insn
;
5060 state_machine_regs
.view
= 0;
5061 printf (_(" Advance PC by constant %" PRIu64
5062 " to %#" PRIx64
"[%d]%s\n"),
5063 uladv
, state_machine_regs
.address
,
5064 state_machine_regs
.op_index
,
5065 verbose_view
&& addrdelta
5066 ? _(" (reset view)") : "");
5070 case DW_LNS_fixed_advance_pc
:
5071 SAFE_BYTE_GET_AND_INC (uladv
, data
, 2, end
);
5072 state_machine_regs
.address
+= uladv
;
5073 state_machine_regs
.op_index
= 0;
5074 printf (_(" Advance PC by fixed size amount %" PRIu64
5075 " to %#" PRIx64
"\n"),
5076 uladv
, state_machine_regs
.address
);
5077 /* Do NOT reset view. */
5080 case DW_LNS_set_prologue_end
:
5081 printf (_(" Set prologue_end to true\n"));
5084 case DW_LNS_set_epilogue_begin
:
5085 printf (_(" Set epilogue_begin to true\n"));
5088 case DW_LNS_set_isa
:
5089 READ_ULEB (uladv
, data
, end
);
5090 printf (_(" Set ISA to %" PRIu64
"\n"), uladv
);
5094 printf (_(" Unknown opcode %d with operands: "), op_code
);
5096 if (standard_opcodes
!= NULL
)
5097 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
5099 READ_ULEB (uladv
, data
, end
);
5100 printf ("%#" PRIx64
"%s", uladv
, i
== 1 ? "" : ", ");
5116 unsigned int directory_index
;
5117 unsigned int modification_date
;
5118 unsigned int length
;
5121 /* Output a decoded representation of the .debug_line section. */
5124 display_debug_lines_decoded (struct dwarf_section
* section
,
5125 unsigned char * start
,
5126 unsigned char * data
,
5127 unsigned char * end
,
5130 static DWARF2_Internal_LineInfo saved_linfo
;
5132 introduce (section
, false);
5136 /* This loop amounts to one iteration per compilation unit. */
5137 DWARF2_Internal_LineInfo linfo
;
5138 unsigned char *standard_opcodes
;
5139 unsigned char *end_of_sequence
;
5141 File_Entry
*file_table
= NULL
;
5142 unsigned int n_files
= 0;
5143 char **directory_table
= NULL
;
5144 unsigned int n_directories
= 0;
5146 if (startswith (section
->name
, ".debug_line.")
5147 /* Note: the following does not apply to .debug_line.dwo sections.
5148 These are full debug_line sections. */
5149 && strcmp (section
->name
, ".debug_line.dwo") != 0)
5151 /* See comment in display_debug_lines_raw(). */
5152 end_of_sequence
= end
;
5153 standard_opcodes
= NULL
;
5154 linfo
= saved_linfo
;
5155 /* PR 17531: file: 0522b371. */
5156 if (linfo
.li_line_range
== 0)
5158 warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n"));
5161 reset_state_machine (linfo
.li_default_is_stmt
);
5165 unsigned char *hdrptr
;
5167 if ((hdrptr
= read_debug_line_header (section
, data
, end
, & linfo
,
5168 & end_of_sequence
)) == NULL
)
5171 /* PR 17531: file: 0522b371. */
5172 if (linfo
.li_line_range
== 0)
5174 warn (_("Line range of 0 is invalid, using 1 instead\n"));
5175 linfo
.li_line_range
= 1;
5177 reset_state_machine (linfo
.li_default_is_stmt
);
5179 /* Save a pointer to the contents of the Opcodes table. */
5180 standard_opcodes
= hdrptr
;
5182 /* Traverse the Directory table just to count entries. */
5183 data
= standard_opcodes
+ linfo
.li_opcode_base
- 1;
5187 warn (_("opcode base of %d extends beyond end of section\n"),
5188 linfo
.li_opcode_base
);
5192 if (linfo
.li_version
>= 5)
5194 unsigned char *format_start
, *format
;
5195 unsigned int format_count
, formati
, entryi
;
5197 load_debug_section_with_follow (line_str
, fileptr
);
5199 /* Skip directories format. */
5200 SAFE_BYTE_GET_AND_INC (format_count
, data
, 1, end
);
5201 if (do_checks
&& format_count
> 1)
5202 warn (_("Unexpectedly large number of columns in the directory name table (%u)\n"),
5204 format_start
= data
;
5205 for (formati
= 0; formati
< format_count
; formati
++)
5207 SKIP_ULEB (data
, end
);
5208 SKIP_ULEB (data
, end
);
5211 READ_ULEB (n_directories
, data
, end
);
5214 warn (_("Corrupt directories list\n"));
5218 if (n_directories
== 0)
5219 directory_table
= NULL
;
5220 else if (n_directories
> section
->size
)
5222 warn (_("number of directories (0x%x) exceeds size of section %s\n"),
5223 n_directories
, section
->name
);
5227 directory_table
= (char **)
5228 xcalloc (n_directories
, sizeof (unsigned char *));
5230 for (entryi
= 0; entryi
< n_directories
; entryi
++)
5232 char **pathp
= &directory_table
[entryi
];
5234 format
= format_start
;
5235 for (formati
= 0; formati
< format_count
; formati
++)
5237 uint64_t content_type
, form
;
5240 READ_ULEB (content_type
, format
, end
);
5241 READ_ULEB (form
, format
, end
);
5244 warn (_("Corrupt directories list\n"));
5247 switch (content_type
)
5252 case DW_FORM_string
:
5253 *pathp
= (char *) data
;
5255 case DW_FORM_line_strp
:
5256 SAFE_BYTE_GET (uvalue
, data
, linfo
.li_offset_size
,
5258 /* Remove const by the cast. */
5260 fetch_indirect_line_string (uvalue
);
5265 data
= read_and_display_attr_value (0, form
, 0, start
,
5267 linfo
.li_offset_size
,
5274 warn (_("Corrupt directories list\n"));
5279 /* Skip files format. */
5280 SAFE_BYTE_GET_AND_INC (format_count
, data
, 1, end
);
5281 if (do_checks
&& format_count
> 5)
5282 warn (_("Unexpectedly large number of columns in the file name table (%u)\n"),
5285 format_start
= data
;
5286 for (formati
= 0; formati
< format_count
; formati
++)
5288 SKIP_ULEB (data
, end
);
5289 SKIP_ULEB (data
, end
);
5292 READ_ULEB (n_files
, data
, end
);
5293 if (data
>= end
&& n_files
> 0)
5295 warn (_("Corrupt file name list\n"));
5301 else if (n_files
> section
->size
)
5303 warn (_("number of files (0x%x) exceeds size of section %s\n"),
5304 n_files
, section
->name
);
5308 file_table
= (File_Entry
*) xcalloc (n_files
,
5309 sizeof (File_Entry
));
5311 for (entryi
= 0; entryi
< n_files
; entryi
++)
5313 File_Entry
*file
= &file_table
[entryi
];
5315 format
= format_start
;
5316 for (formati
= 0; formati
< format_count
; formati
++)
5318 uint64_t content_type
, form
;
5322 READ_ULEB (content_type
, format
, end
);
5323 READ_ULEB (form
, format
, end
);
5326 warn (_("Corrupt file name list\n"));
5329 switch (content_type
)
5334 case DW_FORM_string
:
5335 file
->name
= (char *) data
;
5337 case DW_FORM_line_strp
:
5338 SAFE_BYTE_GET (uvalue
, data
, linfo
.li_offset_size
,
5340 /* Remove const by the cast. */
5341 file
->name
= (char *)
5342 fetch_indirect_line_string (uvalue
);
5346 case DW_LNCT_directory_index
:
5350 SAFE_BYTE_GET (file
->directory_index
, data
, 1,
5354 SAFE_BYTE_GET (file
->directory_index
, data
, 2,
5359 READ_ULEB (file
->directory_index
, tmp
, end
);
5364 data
= read_and_display_attr_value (0, form
, 0, start
,
5366 linfo
.li_offset_size
,
5373 warn (_("Corrupt file name list\n"));
5382 char *ptr_directory_table
= (char *) data
;
5384 while (data
< end
&& *data
!= 0)
5386 data
+= strnlen ((char *) data
, end
- data
);
5395 warn (_("directory table ends unexpectedly\n"));
5400 /* Go through the directory table again to save the directories. */
5401 directory_table
= (char **)
5402 xmalloc (n_directories
* sizeof (unsigned char *));
5405 while (*ptr_directory_table
!= 0)
5407 directory_table
[i
] = ptr_directory_table
;
5408 ptr_directory_table
+= strlen (ptr_directory_table
) + 1;
5412 /* Skip the NUL at the end of the table. */
5415 /* Traverse the File Name table just to count the entries. */
5416 if (data
< end
&& *data
!= 0)
5418 unsigned char *ptr_file_name_table
= data
;
5420 while (data
< end
&& *data
!= 0)
5422 /* Skip Name, directory index, last modification
5423 time and length of file. */
5424 data
+= strnlen ((char *) data
, end
- data
);
5427 SKIP_ULEB (data
, end
);
5428 SKIP_ULEB (data
, end
);
5429 SKIP_ULEB (data
, end
);
5435 warn (_("file table ends unexpectedly\n"));
5440 /* Go through the file table again to save the strings. */
5441 file_table
= (File_Entry
*) xmalloc (n_files
* sizeof (File_Entry
));
5444 while (*ptr_file_name_table
!= 0)
5446 file_table
[i
].name
= (char *) ptr_file_name_table
;
5448 += strlen ((char *) ptr_file_name_table
) + 1;
5450 /* We are not interested in directory, time or size. */
5451 READ_ULEB (file_table
[i
].directory_index
,
5452 ptr_file_name_table
, end
);
5453 READ_ULEB (file_table
[i
].modification_date
,
5454 ptr_file_name_table
, end
);
5455 READ_ULEB (file_table
[i
].length
,
5456 ptr_file_name_table
, end
);
5462 /* Skip the NUL at the end of the table. */
5466 /* Print the Compilation Unit's name and a header. */
5467 if (file_table
== NULL
)
5468 printf (_("CU: No directory table\n"));
5469 else if (directory_table
== NULL
)
5470 printf (_("CU: %s:\n"), null_name (file_table
[0].name
));
5473 unsigned int ix
= file_table
[0].directory_index
;
5474 const char *directory
;
5476 if (ix
== 0 && linfo
.li_version
< 5)
5479 else if (n_directories
== 0)
5480 directory
= _("<unknown>");
5483 if (linfo
.li_version
< 5)
5485 if (ix
>= n_directories
)
5487 warn (_("directory index %u "
5488 ">= number of directories %u\n"),
5490 directory
= _("<corrupt>");
5493 directory
= directory_table
[ix
];
5496 printf (_("CU: %s/%s:\n"),
5497 null_name (directory
),
5498 null_name (file_table
[0].name
));
5500 printf ("%s:\n", null_name (file_table
[0].name
));
5506 printf (_("File name Line number Starting address View Stmt\n"));
5508 printf (_("File name Line number Starting address View Stmt\n"));
5511 printf (_("CU: Empty file name table\n"));
5512 saved_linfo
= linfo
;
5515 /* This loop iterates through the Dwarf Line Number Program. */
5516 while (data
< end_of_sequence
)
5518 unsigned char op_code
;
5521 unsigned long int uladv
;
5522 int is_special_opcode
= 0;
5527 if (op_code
>= linfo
.li_opcode_base
)
5529 op_code
-= linfo
.li_opcode_base
;
5530 uladv
= (op_code
/ linfo
.li_line_range
);
5531 if (linfo
.li_max_ops_per_insn
== 1)
5533 uladv
*= linfo
.li_min_insn_length
;
5534 state_machine_regs
.address
+= uladv
;
5536 state_machine_regs
.view
= 0;
5541 = ((state_machine_regs
.op_index
+ uladv
)
5542 / linfo
.li_max_ops_per_insn
)
5543 * linfo
.li_min_insn_length
;
5544 state_machine_regs
.address
5546 state_machine_regs
.op_index
5547 = (state_machine_regs
.op_index
+ uladv
)
5548 % linfo
.li_max_ops_per_insn
;
5550 state_machine_regs
.view
= 0;
5553 adv
= (op_code
% linfo
.li_line_range
) + linfo
.li_line_base
;
5554 state_machine_regs
.line
+= adv
;
5555 is_special_opcode
= 1;
5556 /* Increment view after printing this row. */
5561 case DW_LNS_extended_op
:
5563 unsigned int ext_op_code_len
;
5564 unsigned char ext_op_code
;
5565 unsigned char *op_code_end
;
5566 unsigned char *op_code_data
= data
;
5568 READ_ULEB (ext_op_code_len
, op_code_data
, end_of_sequence
);
5569 op_code_end
= op_code_data
+ ext_op_code_len
;
5570 if (ext_op_code_len
== 0 || op_code_end
> end_of_sequence
)
5572 warn (_("Badly formed extended line op encountered!\n"));
5575 ext_op_code
= *op_code_data
++;
5579 switch (ext_op_code
)
5581 case DW_LNE_end_sequence
:
5582 /* Reset stuff after printing this row. */
5584 case DW_LNE_set_address
:
5585 SAFE_BYTE_GET_AND_INC (state_machine_regs
.address
,
5587 op_code_end
- op_code_data
,
5589 state_machine_regs
.op_index
= 0;
5590 state_machine_regs
.view
= 0;
5592 case DW_LNE_define_file
:
5593 file_table
= (File_Entry
*) xrealloc
5594 (file_table
, (n_files
+ 1) * sizeof (File_Entry
));
5596 ++state_machine_regs
.last_file_entry
;
5597 /* Source file name. */
5598 file_table
[n_files
].name
= (char *) op_code_data
;
5599 op_code_data
+= strlen ((char *) op_code_data
) + 1;
5600 /* Directory index. */
5601 READ_ULEB (file_table
[n_files
].directory_index
,
5602 op_code_data
, op_code_end
);
5603 /* Last modification time. */
5604 READ_ULEB (file_table
[n_files
].modification_date
,
5605 op_code_data
, op_code_end
);
5607 READ_ULEB (file_table
[n_files
].length
,
5608 op_code_data
, op_code_end
);
5612 case DW_LNE_set_discriminator
:
5613 case DW_LNE_HP_set_sequence
:
5614 /* Simply ignored. */
5618 printf (_("UNKNOWN (%u): length %ld\n"),
5619 ext_op_code
, (long int) (op_code_data
- data
));
5626 /* Increment view after printing this row. */
5629 case DW_LNS_advance_pc
:
5630 READ_ULEB (uladv
, data
, end
);
5631 if (linfo
.li_max_ops_per_insn
== 1)
5633 uladv
*= linfo
.li_min_insn_length
;
5634 state_machine_regs
.address
+= uladv
;
5636 state_machine_regs
.view
= 0;
5641 = ((state_machine_regs
.op_index
+ uladv
)
5642 / linfo
.li_max_ops_per_insn
)
5643 * linfo
.li_min_insn_length
;
5644 state_machine_regs
.address
5646 state_machine_regs
.op_index
5647 = (state_machine_regs
.op_index
+ uladv
)
5648 % linfo
.li_max_ops_per_insn
;
5650 state_machine_regs
.view
= 0;
5654 case DW_LNS_advance_line
:
5655 READ_SLEB (adv
, data
, end
);
5656 state_machine_regs
.line
+= adv
;
5659 case DW_LNS_set_file
:
5660 READ_ULEB (uladv
, data
, end
);
5661 state_machine_regs
.file
= uladv
;
5663 unsigned file
= state_machine_regs
.file
;
5664 if (linfo
.li_version
< 5)
5667 if (file_table
== NULL
|| n_files
== 0)
5668 printf (_("\n [Use file table entry %d]\n"), file
);
5670 else if (file
>= n_files
)
5672 warn (_("file index %u >= number of files %u\n"),
5674 printf (_("\n <over large file table index %u>"), file
);
5678 unsigned dir
= file_table
[file
].directory_index
;
5679 if (dir
== 0 && linfo
.li_version
< 5)
5680 /* If directory index is 0, that means compilation
5681 current directory. bfd/dwarf2.c shows
5682 DW_AT_comp_dir here but in keeping with the
5683 readelf practice of minimal interpretation of
5684 file data, we show "./". */
5685 printf ("\n./%s:[++]\n",
5686 null_name (file_table
[file
].name
));
5687 else if (directory_table
== NULL
|| n_directories
== 0)
5688 printf (_("\n [Use file %s "
5689 "in directory table entry %d]\n"),
5690 null_name (file_table
[file
].name
), dir
);
5693 if (linfo
.li_version
< 5)
5696 if (dir
>= n_directories
)
5698 warn (_("directory index %u "
5699 ">= number of directories %u\n"),
5700 dir
, n_directories
);
5701 printf (_("\n <over large directory table entry "
5705 printf ("\n%s/%s:\n",
5706 null_name (directory_table
[dir
]),
5707 null_name (file_table
[file
].name
));
5712 case DW_LNS_set_column
:
5713 READ_ULEB (uladv
, data
, end
);
5714 state_machine_regs
.column
= uladv
;
5717 case DW_LNS_negate_stmt
:
5718 adv
= state_machine_regs
.is_stmt
;
5720 state_machine_regs
.is_stmt
= adv
;
5723 case DW_LNS_set_basic_block
:
5724 state_machine_regs
.basic_block
= 1;
5727 case DW_LNS_const_add_pc
:
5728 uladv
= ((255 - linfo
.li_opcode_base
) / linfo
.li_line_range
);
5729 if (linfo
.li_max_ops_per_insn
== 1)
5731 uladv
*= linfo
.li_min_insn_length
;
5732 state_machine_regs
.address
+= uladv
;
5734 state_machine_regs
.view
= 0;
5739 = ((state_machine_regs
.op_index
+ uladv
)
5740 / linfo
.li_max_ops_per_insn
)
5741 * linfo
.li_min_insn_length
;
5742 state_machine_regs
.address
5744 state_machine_regs
.op_index
5745 = (state_machine_regs
.op_index
+ uladv
)
5746 % linfo
.li_max_ops_per_insn
;
5748 state_machine_regs
.view
= 0;
5752 case DW_LNS_fixed_advance_pc
:
5753 SAFE_BYTE_GET_AND_INC (uladv
, data
, 2, end
);
5754 state_machine_regs
.address
+= uladv
;
5755 state_machine_regs
.op_index
= 0;
5756 /* Do NOT reset view. */
5759 case DW_LNS_set_prologue_end
:
5762 case DW_LNS_set_epilogue_begin
:
5765 case DW_LNS_set_isa
:
5766 READ_ULEB (uladv
, data
, end
);
5767 printf (_(" Set ISA to %lu\n"), uladv
);
5771 printf (_(" Unknown opcode %d with operands: "), op_code
);
5773 if (standard_opcodes
!= NULL
)
5774 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
5778 READ_ULEB (val
, data
, end
);
5779 printf ("%#" PRIx64
"%s", val
, i
== 1 ? "" : ", ");
5785 /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row
5786 to the DWARF address/line matrix. */
5787 if ((is_special_opcode
) || (xop
== -DW_LNE_end_sequence
)
5788 || (xop
== DW_LNS_copy
))
5790 const unsigned int MAX_FILENAME_LENGTH
= 35;
5791 char *fileName
= NULL
;
5792 char *newFileName
= NULL
;
5793 size_t fileNameLength
;
5797 unsigned indx
= state_machine_regs
.file
;
5799 if (linfo
.li_version
< 5)
5802 if (indx
>= n_files
)
5804 warn (_("file index %u >= number of files %u\n"),
5806 fileName
= _("<corrupt>");
5809 fileName
= (char *) file_table
[indx
].name
;
5812 fileName
= _("<unknown>");
5814 fileNameLength
= strlen (fileName
);
5815 newFileName
= fileName
;
5816 if (fileNameLength
> MAX_FILENAME_LENGTH
&& !do_wide
)
5818 newFileName
= (char *) xmalloc (MAX_FILENAME_LENGTH
+ 1);
5819 /* Truncate file name */
5820 memcpy (newFileName
,
5821 fileName
+ fileNameLength
- MAX_FILENAME_LENGTH
,
5822 MAX_FILENAME_LENGTH
);
5823 newFileName
[MAX_FILENAME_LENGTH
] = 0;
5826 /* A row with end_seq set to true has a meaningful address, but
5827 the other information in the same row is not significant.
5828 In such a row, print line as "-", and don't print
5830 if (!do_wide
|| fileNameLength
<= MAX_FILENAME_LENGTH
)
5832 if (linfo
.li_max_ops_per_insn
== 1)
5834 if (xop
== -DW_LNE_end_sequence
)
5835 printf ("%-31s %11s %#18" PRIx64
,
5837 state_machine_regs
.address
);
5839 printf ("%-31s %11d %#18" PRIx64
,
5840 newFileName
, state_machine_regs
.line
,
5841 state_machine_regs
.address
);
5845 if (xop
== -DW_LNE_end_sequence
)
5846 printf ("%-31s %11s %#18" PRIx64
"[%d]",
5848 state_machine_regs
.address
,
5849 state_machine_regs
.op_index
);
5851 printf ("%-31s %11d %#18" PRIx64
"[%d]",
5852 newFileName
, state_machine_regs
.line
,
5853 state_machine_regs
.address
,
5854 state_machine_regs
.op_index
);
5859 if (linfo
.li_max_ops_per_insn
== 1)
5861 if (xop
== -DW_LNE_end_sequence
)
5862 printf ("%s %11s %#18" PRIx64
,
5864 state_machine_regs
.address
);
5866 printf ("%s %11d %#18" PRIx64
,
5867 newFileName
, state_machine_regs
.line
,
5868 state_machine_regs
.address
);
5872 if (xop
== -DW_LNE_end_sequence
)
5873 printf ("%s %11s %#18" PRIx64
"[%d]",
5875 state_machine_regs
.address
,
5876 state_machine_regs
.op_index
);
5878 printf ("%s %11d %#18" PRIx64
"[%d]",
5879 newFileName
, state_machine_regs
.line
,
5880 state_machine_regs
.address
,
5881 state_machine_regs
.op_index
);
5885 if (xop
!= -DW_LNE_end_sequence
)
5887 if (state_machine_regs
.view
)
5888 printf (" %6u", state_machine_regs
.view
);
5892 if (state_machine_regs
.is_stmt
)
5897 state_machine_regs
.view
++;
5899 if (xop
== -DW_LNE_end_sequence
)
5901 reset_state_machine (linfo
.li_default_is_stmt
);
5905 if (newFileName
!= fileName
)
5917 if (directory_table
)
5919 free (directory_table
);
5920 directory_table
= NULL
;
5931 display_debug_lines (struct dwarf_section
*section
, void *file
)
5933 unsigned char *data
= section
->start
;
5934 unsigned char *end
= data
+ section
->size
;
5936 int retValDecoded
= 1;
5938 if (do_debug_lines
== 0)
5939 do_debug_lines
|= FLAG_DEBUG_LINES_RAW
;
5941 if (do_debug_lines
& FLAG_DEBUG_LINES_RAW
)
5942 retValRaw
= display_debug_lines_raw (section
, data
, end
, file
);
5944 if (do_debug_lines
& FLAG_DEBUG_LINES_DECODED
)
5945 retValDecoded
= display_debug_lines_decoded (section
, data
, data
, end
, file
);
5947 if (!retValRaw
|| !retValDecoded
)
5954 find_debug_info_for_offset (uint64_t offset
)
5958 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
5961 for (i
= 0; i
< num_debug_info_entries
; i
++)
5962 if (debug_information
[i
].cu_offset
== offset
)
5963 return debug_information
+ i
;
5969 get_gdb_index_symbol_kind_name (gdb_index_symbol_kind kind
)
5971 /* See gdb/gdb-index.h. */
5972 static const char * const kinds
[] =
5984 return _ (kinds
[kind
]);
5988 display_debug_pubnames_worker (struct dwarf_section
*section
,
5989 void *file ATTRIBUTE_UNUSED
,
5992 DWARF2_Internal_PubNames names
;
5993 unsigned char *start
= section
->start
;
5994 unsigned char *end
= start
+ section
->size
;
5996 /* It does not matter if this load fails,
5997 we test for that later on. */
5998 load_debug_info (file
);
6000 introduce (section
, false);
6004 unsigned char *data
;
6005 unsigned long sec_off
= start
- section
->start
;
6006 unsigned int offset_size
;
6008 SAFE_BYTE_GET_AND_INC (names
.pn_length
, start
, 4, end
);
6009 if (names
.pn_length
== 0xffffffff)
6011 SAFE_BYTE_GET_AND_INC (names
.pn_length
, start
, 8, end
);
6017 if (names
.pn_length
> (size_t) (end
- start
))
6019 warn (_("Debug info is corrupted, "
6020 "%s header at %#lx has length %#" PRIx64
"\n"),
6021 section
->name
, sec_off
, names
.pn_length
);
6026 start
+= names
.pn_length
;
6028 SAFE_BYTE_GET_AND_INC (names
.pn_version
, data
, 2, start
);
6029 SAFE_BYTE_GET_AND_INC (names
.pn_offset
, data
, offset_size
, start
);
6031 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
6032 && num_debug_info_entries
> 0
6033 && find_debug_info_for_offset (names
.pn_offset
) == NULL
)
6034 warn (_(".debug_info offset of %#" PRIx64
6035 " in %s section does not point to a CU header.\n"),
6036 names
.pn_offset
, section
->name
);
6038 SAFE_BYTE_GET_AND_INC (names
.pn_size
, data
, offset_size
, start
);
6040 printf (_(" Length: %" PRId64
"\n"),
6042 printf (_(" Version: %d\n"),
6044 printf (_(" Offset into .debug_info section: %#" PRIx64
"\n"),
6046 printf (_(" Size of area in .debug_info section: %" PRId64
"\n"),
6049 if (names
.pn_version
!= 2 && names
.pn_version
!= 3)
6051 static int warned
= 0;
6055 warn (_("Only DWARF 2 and 3 pubnames are currently supported\n"));
6063 printf (_("\n Offset Kind Name\n"));
6065 printf (_("\n Offset\tName\n"));
6072 SAFE_BYTE_GET_AND_INC (offset
, data
, offset_size
, start
);
6079 maxprint
= (start
- data
) - 1;
6083 unsigned int kind_data
;
6084 gdb_index_symbol_kind kind
;
6085 const char *kind_name
;
6088 SAFE_BYTE_GET_AND_INC (kind_data
, data
, 1, start
);
6090 /* GCC computes the kind as the upper byte in the CU index
6091 word, and then right shifts it by the CU index size.
6092 Left shift KIND to where the gdb-index.h accessor macros
6094 kind_data
<<= GDB_INDEX_CU_BITSIZE
;
6095 kind
= GDB_INDEX_SYMBOL_KIND_VALUE (kind_data
);
6096 kind_name
= get_gdb_index_symbol_kind_name (kind
);
6097 is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (kind_data
);
6098 printf (" %-6" PRIx64
" %s,%-10s %.*s\n",
6099 offset
, is_static
? _("s") : _("g"),
6100 kind_name
, (int) maxprint
, data
);
6103 printf (" %-6" PRIx64
"\t%.*s\n",
6104 offset
, (int) maxprint
, data
);
6106 data
+= strnlen ((char *) data
, maxprint
);
6119 display_debug_pubnames (struct dwarf_section
*section
, void *file
)
6121 return display_debug_pubnames_worker (section
, file
, 0);
6125 display_debug_gnu_pubnames (struct dwarf_section
*section
, void *file
)
6127 return display_debug_pubnames_worker (section
, file
, 1);
6131 display_debug_macinfo (struct dwarf_section
*section
,
6132 void *file ATTRIBUTE_UNUSED
)
6134 unsigned char *start
= section
->start
;
6135 unsigned char *end
= start
+ section
->size
;
6136 unsigned char *curr
= start
;
6137 enum dwarf_macinfo_record_type op
;
6139 introduce (section
, false);
6143 unsigned int lineno
;
6144 const unsigned char *string
;
6146 op
= (enum dwarf_macinfo_record_type
) *curr
;
6151 case DW_MACINFO_start_file
:
6153 unsigned int filenum
;
6155 READ_ULEB (lineno
, curr
, end
);
6156 READ_ULEB (filenum
, curr
, end
);
6157 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"),
6162 case DW_MACINFO_end_file
:
6163 printf (_(" DW_MACINFO_end_file\n"));
6166 case DW_MACINFO_define
:
6167 READ_ULEB (lineno
, curr
, end
);
6169 curr
+= strnlen ((char *) string
, end
- string
);
6170 printf (_(" DW_MACINFO_define - lineno : %d macro : %*s\n"),
6171 lineno
, (int) (curr
- string
), string
);
6176 case DW_MACINFO_undef
:
6177 READ_ULEB (lineno
, curr
, end
);
6179 curr
+= strnlen ((char *) string
, end
- string
);
6180 printf (_(" DW_MACINFO_undef - lineno : %d macro : %*s\n"),
6181 lineno
, (int) (curr
- string
), string
);
6186 case DW_MACINFO_vendor_ext
:
6188 unsigned int constant
;
6190 READ_ULEB (constant
, curr
, end
);
6192 curr
+= strnlen ((char *) string
, end
- string
);
6193 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %*s\n"),
6194 constant
, (int) (curr
- string
), string
);
6205 /* Given LINE_OFFSET into the .debug_line section, attempt to return
6206 filename and dirname corresponding to file name table entry with index
6207 FILEIDX. Return NULL on failure. */
6209 static unsigned char *
6210 get_line_filename_and_dirname (uint64_t line_offset
,
6212 unsigned char **dir_name
)
6214 struct dwarf_section
*section
= &debug_displays
[line
].section
;
6215 unsigned char *hdrptr
, *dirtable
, *file_name
;
6216 unsigned int offset_size
;
6217 unsigned int version
, opcode_base
;
6218 uint64_t length
, diridx
;
6219 const unsigned char * end
;
6222 if (section
->start
== NULL
6223 || line_offset
>= section
->size
6227 hdrptr
= section
->start
+ line_offset
;
6228 end
= section
->start
+ section
->size
;
6230 SAFE_BYTE_GET_AND_INC (length
, hdrptr
, 4, end
);
6231 if (length
== 0xffffffff)
6233 /* This section is 64-bit DWARF 3. */
6234 SAFE_BYTE_GET_AND_INC (length
, hdrptr
, 8, end
);
6240 if (length
> (size_t) (end
- hdrptr
)
6241 || length
< 2 + offset_size
+ 1 + 3 + 1)
6243 end
= hdrptr
+ length
;
6245 SAFE_BYTE_GET_AND_INC (version
, hdrptr
, 2, end
);
6246 if (version
!= 2 && version
!= 3 && version
!= 4)
6248 hdrptr
+= offset_size
+ 1;/* Skip prologue_length and min_insn_length. */
6250 hdrptr
++; /* Skip max_ops_per_insn. */
6251 hdrptr
+= 3; /* Skip default_is_stmt, line_base, line_range. */
6253 SAFE_BYTE_GET_AND_INC (opcode_base
, hdrptr
, 1, end
);
6254 if (opcode_base
== 0
6255 || opcode_base
- 1 >= (size_t) (end
- hdrptr
))
6258 hdrptr
+= opcode_base
- 1;
6261 /* Skip over dirname table. */
6262 while (*hdrptr
!= '\0')
6264 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
);
6270 hdrptr
++; /* Skip the NUL at the end of the table. */
6272 /* Now skip over preceding filename table entries. */
6273 for (; hdrptr
< end
&& *hdrptr
!= '\0' && fileidx
> 1; fileidx
--)
6275 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
);
6278 SKIP_ULEB (hdrptr
, end
);
6279 SKIP_ULEB (hdrptr
, end
);
6280 SKIP_ULEB (hdrptr
, end
);
6282 if (hdrptr
>= end
|| *hdrptr
== '\0')
6286 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
);
6291 READ_ULEB (diridx
, hdrptr
, end
);
6294 for (; dirtable
< end
&& *dirtable
!= '\0' && diridx
> 1; diridx
--)
6296 dirtable
+= strnlen ((char *) dirtable
, end
- dirtable
);
6300 if (dirtable
>= end
|| *dirtable
== '\0')
6302 *dir_name
= dirtable
;
6307 display_debug_macro (struct dwarf_section
*section
,
6310 unsigned char *start
= section
->start
;
6311 unsigned char *end
= start
+ section
->size
;
6312 unsigned char *curr
= start
;
6313 unsigned char *extended_op_buf
[256];
6314 bool is_dwo
= false;
6315 const char *suffix
= strrchr (section
->name
, '.');
6317 if (suffix
&& strcmp (suffix
, ".dwo") == 0)
6322 load_debug_section_with_follow (str_dwo
, file
);
6323 load_debug_section_with_follow (str_index_dwo
, file
);
6327 load_debug_section_with_follow (str
, file
);
6328 load_debug_section_with_follow (str_index
, file
);
6330 load_debug_section_with_follow (line
, file
);
6332 introduce (section
, false);
6336 unsigned int lineno
, version
, flags
;
6337 unsigned int offset_size
;
6338 const unsigned char *string
;
6339 uint64_t line_offset
= 0, sec_offset
= curr
- start
, offset
;
6340 unsigned char **extended_ops
= NULL
;
6342 SAFE_BYTE_GET_AND_INC (version
, curr
, 2, end
);
6343 if (version
!= 4 && version
!= 5)
6345 error (_("Expected to find a version number of 4 or 5 in section %s but found %d instead\n"),
6346 section
->name
, version
);
6350 SAFE_BYTE_GET_AND_INC (flags
, curr
, 1, end
);
6351 offset_size
= (flags
& 1) ? 8 : 4;
6352 printf (_(" Offset: %#" PRIx64
"\n"), sec_offset
);
6353 printf (_(" Version: %d\n"), version
);
6354 printf (_(" Offset size: %d\n"), offset_size
);
6357 SAFE_BYTE_GET_AND_INC (line_offset
, curr
, offset_size
, end
);
6358 printf (_(" Offset into .debug_line: %#" PRIx64
"\n"),
6363 unsigned int i
, count
, op
;
6366 SAFE_BYTE_GET_AND_INC (count
, curr
, 1, end
);
6368 memset (extended_op_buf
, 0, sizeof (extended_op_buf
));
6369 extended_ops
= extended_op_buf
;
6372 printf (_(" Extension opcode arguments:\n"));
6373 for (i
= 0; i
< count
; i
++)
6375 SAFE_BYTE_GET_AND_INC (op
, curr
, 1, end
);
6376 extended_ops
[op
] = curr
;
6377 READ_ULEB (nargs
, curr
, end
);
6379 printf (_(" DW_MACRO_%02x has no arguments\n"), op
);
6382 printf (_(" DW_MACRO_%02x arguments: "), op
);
6383 for (n
= 0; n
< nargs
; n
++)
6387 SAFE_BYTE_GET_AND_INC (form
, curr
, 1, end
);
6388 printf ("%s%s", get_FORM_name (form
),
6389 n
== nargs
- 1 ? "\n" : ", ");
6399 case DW_FORM_block1
:
6400 case DW_FORM_block2
:
6401 case DW_FORM_block4
:
6403 case DW_FORM_string
:
6405 case DW_FORM_sec_offset
:
6408 error (_("Invalid extension opcode form %s\n"),
6409 get_FORM_name (form
));
6425 error (_(".debug_macro section not zero terminated\n"));
6429 SAFE_BYTE_GET_AND_INC (op
, curr
, 1, end
);
6435 case DW_MACRO_define
:
6436 READ_ULEB (lineno
, curr
, end
);
6438 curr
+= strnlen ((char *) string
, end
- string
);
6439 printf (_(" DW_MACRO_define - lineno : %d macro : %*s\n"),
6440 lineno
, (int) (curr
- string
), string
);
6445 case DW_MACRO_undef
:
6446 READ_ULEB (lineno
, curr
, end
);
6448 curr
+= strnlen ((char *) string
, end
- string
);
6449 printf (_(" DW_MACRO_undef - lineno : %d macro : %*s\n"),
6450 lineno
, (int) (curr
- string
), string
);
6455 case DW_MACRO_start_file
:
6457 unsigned int filenum
;
6458 unsigned char *file_name
= NULL
, *dir_name
= NULL
;
6460 READ_ULEB (lineno
, curr
, end
);
6461 READ_ULEB (filenum
, curr
, end
);
6463 if ((flags
& 2) == 0)
6464 error (_("DW_MACRO_start_file used, but no .debug_line offset provided.\n"));
6467 = get_line_filename_and_dirname (line_offset
, filenum
,
6469 if (file_name
== NULL
)
6470 printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d\n"),
6473 printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d filename: %s%s%s\n"),
6475 dir_name
!= NULL
? (const char *) dir_name
: "",
6476 dir_name
!= NULL
? "/" : "", file_name
);
6480 case DW_MACRO_end_file
:
6481 printf (_(" DW_MACRO_end_file\n"));
6484 case DW_MACRO_define_strp
:
6485 READ_ULEB (lineno
, curr
, end
);
6486 if (version
== 4 && is_dwo
)
6487 READ_ULEB (offset
, curr
, end
);
6489 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6490 string
= fetch_indirect_string (offset
);
6491 printf (_(" DW_MACRO_define_strp - lineno : %d macro : %s\n"),
6495 case DW_MACRO_undef_strp
:
6496 READ_ULEB (lineno
, curr
, end
);
6497 if (version
== 4 && is_dwo
)
6498 READ_ULEB (offset
, curr
, end
);
6500 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6501 string
= fetch_indirect_string (offset
);
6502 printf (_(" DW_MACRO_undef_strp - lineno : %d macro : %s\n"),
6506 case DW_MACRO_import
:
6507 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6508 printf (_(" DW_MACRO_import - offset : %#" PRIx64
"\n"),
6512 case DW_MACRO_define_sup
:
6513 READ_ULEB (lineno
, curr
, end
);
6514 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6515 printf (_(" DW_MACRO_define_sup - lineno : %d"
6516 " macro offset : %#" PRIx64
"\n"),
6520 case DW_MACRO_undef_sup
:
6521 READ_ULEB (lineno
, curr
, end
);
6522 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6523 printf (_(" DW_MACRO_undef_sup - lineno : %d"
6524 " macro offset : %#" PRIx64
"\n"),
6528 case DW_MACRO_import_sup
:
6529 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6530 printf (_(" DW_MACRO_import_sup - offset : %#" PRIx64
"\n"),
6534 case DW_MACRO_define_strx
:
6535 case DW_MACRO_undef_strx
:
6536 READ_ULEB (lineno
, curr
, end
);
6537 READ_ULEB (offset
, curr
, end
);
6538 string
= (const unsigned char *)
6539 fetch_indexed_string (offset
, NULL
, offset_size
, is_dwo
, 0);
6540 if (op
== DW_MACRO_define_strx
)
6541 printf (" DW_MACRO_define_strx ");
6543 printf (" DW_MACRO_undef_strx ");
6545 printf (_("(with offset %#" PRIx64
") "), offset
);
6546 printf (_("lineno : %d macro : %s\n"),
6551 if (op
>= DW_MACRO_lo_user
&& op
<= DW_MACRO_hi_user
)
6553 printf (_(" <Target Specific macro op: %#x - UNHANDLED"), op
);
6557 if (extended_ops
== NULL
|| extended_ops
[op
] == NULL
)
6559 error (_(" Unknown macro opcode %02x seen\n"), op
);
6564 /* Skip over unhandled opcodes. */
6566 unsigned char *desc
= extended_ops
[op
];
6567 READ_ULEB (nargs
, desc
, end
);
6570 printf (_(" DW_MACRO_%02x\n"), op
);
6573 printf (_(" DW_MACRO_%02x -"), op
);
6574 for (n
= 0; n
< nargs
; n
++)
6578 /* DW_FORM_implicit_const is not expected here. */
6579 SAFE_BYTE_GET_AND_INC (val
, desc
, 1, end
);
6581 = read_and_display_attr_value (0, val
, 0,
6582 start
, curr
, end
, 0, 0,
6583 offset_size
, version
,
6602 display_debug_abbrev (struct dwarf_section
*section
,
6603 void *file ATTRIBUTE_UNUSED
)
6605 abbrev_entry
*entry
;
6606 unsigned char *start
= section
->start
;
6608 introduce (section
, false);
6612 uint64_t offset
= start
- section
->start
;
6613 abbrev_list
*list
= find_and_process_abbrev_set (section
, 0,
6614 section
->size
, offset
,
6619 if (list
->first_abbrev
)
6620 printf (_(" Number TAG (%#" PRIx64
")\n"), offset
);
6622 for (entry
= list
->first_abbrev
; entry
; entry
= entry
->next
)
6626 printf (" %ld %s [%s]\n",
6628 get_TAG_name (entry
->tag
),
6629 entry
->children
? _("has children") : _("no children"));
6631 for (attr
= entry
->first_attr
; attr
; attr
= attr
->next
)
6633 printf (" %-18s %s",
6634 get_AT_name (attr
->attribute
),
6635 get_FORM_name (attr
->form
));
6636 if (attr
->form
== DW_FORM_implicit_const
)
6637 printf (": %" PRId64
, attr
->implicit_const
);
6641 start
= list
->start_of_next_abbrevs
;
6642 free_abbrev_list (list
);
6651 /* Return true when ADDR is the maximum address, when addresses are
6652 POINTER_SIZE bytes long. */
6655 is_max_address (uint64_t addr
, unsigned int pointer_size
)
6657 uint64_t mask
= ~(~(uint64_t) 0 << 1 << (pointer_size
* 8 - 1));
6658 return ((addr
& mask
) == mask
);
6661 /* Display a view pair list starting at *VSTART_PTR and ending at
6662 VLISTEND within SECTION. */
6665 display_view_pair_list (struct dwarf_section
*section
,
6666 unsigned char **vstart_ptr
,
6667 unsigned int debug_info_entry
,
6668 unsigned char *vlistend
)
6670 unsigned char *vstart
= *vstart_ptr
;
6671 unsigned char *section_end
= section
->start
+ section
->size
;
6672 unsigned int pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
6674 if (vlistend
< section_end
)
6675 section_end
= vlistend
;
6679 while (vstart
< section_end
)
6681 uint64_t off
= vstart
- section
->start
;
6682 uint64_t vbegin
, vend
;
6684 READ_ULEB (vbegin
, vstart
, section_end
);
6685 if (vstart
== section_end
)
6688 READ_ULEB (vend
, vstart
, section_end
);
6689 printf (" %8.8" PRIx64
" ", off
);
6691 print_view (vbegin
, pointer_size
);
6692 print_view (vend
, pointer_size
);
6693 printf (_("location view pair\n"));
6697 *vstart_ptr
= vstart
;
6700 /* Display a location list from a normal (ie, non-dwo) .debug_loc section. */
6703 display_loc_list (struct dwarf_section
*section
,
6704 unsigned char **start_ptr
,
6705 unsigned int debug_info_entry
,
6707 uint64_t base_address
,
6708 unsigned char **vstart_ptr
,
6711 unsigned char *start
= *start_ptr
, *vstart
= *vstart_ptr
;
6712 unsigned char *section_end
= section
->start
+ section
->size
;
6714 unsigned int pointer_size
;
6715 unsigned int offset_size
;
6719 unsigned short length
;
6720 int need_frame_base
;
6722 if (debug_info_entry
>= num_debug_info_entries
)
6724 warn (_("No debug information available for loc lists of entry: %u\n"),
6729 cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
6730 pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
6731 offset_size
= debug_information
[debug_info_entry
].offset_size
;
6732 dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
6734 if (pointer_size
< 2 || pointer_size
> 8)
6736 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
6737 pointer_size
, debug_info_entry
);
6743 uint64_t off
= offset
+ (start
- *start_ptr
);
6744 uint64_t vbegin
= -1, vend
= -1;
6746 if (2 * pointer_size
> (size_t) (section_end
- start
))
6748 warn (_("Location list starting at offset %#" PRIx64
6749 " is not terminated.\n"), offset
);
6756 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, section_end
);
6757 SAFE_BYTE_GET_AND_INC (end
, start
, pointer_size
, section_end
);
6759 if (begin
== 0 && end
== 0)
6761 /* PR 18374: In a object file we can have a location list that
6762 starts with a begin and end of 0 because there are relocations
6763 that need to be applied to the addresses. Actually applying
6764 the relocations now does not help as they will probably resolve
6765 to 0, since the object file has not been fully linked. Real
6766 end of list markers will not have any relocations against them. */
6767 if (! reloc_at (section
, off
)
6768 && ! reloc_at (section
, off
+ pointer_size
))
6770 printf (_("<End of list>\n"));
6775 /* Check base address specifiers. */
6776 if (is_max_address (begin
, pointer_size
)
6777 && !is_max_address (end
, pointer_size
))
6780 print_hex (begin
, pointer_size
);
6781 print_hex (end
, pointer_size
);
6782 printf (_("(base address)\n"));
6788 off
= offset
+ (vstart
- *start_ptr
);
6790 READ_ULEB (vbegin
, vstart
, section_end
);
6791 print_view (vbegin
, pointer_size
);
6793 READ_ULEB (vend
, vstart
, section_end
);
6794 print_view (vend
, pointer_size
);
6796 printf (_("views at %8.8" PRIx64
" for:\n %*s "), off
, 8, "");
6799 if (2 > (size_t) (section_end
- start
))
6801 warn (_("Location list starting at offset %#" PRIx64
6802 " is not terminated.\n"), offset
);
6806 SAFE_BYTE_GET_AND_INC (length
, start
, 2, section_end
);
6808 if (length
> (size_t) (section_end
- start
))
6810 warn (_("Location list starting at offset %#" PRIx64
6811 " is not terminated.\n"), offset
);
6815 print_hex (begin
+ base_address
, pointer_size
);
6816 print_hex (end
+ base_address
, pointer_size
);
6819 need_frame_base
= decode_location_expression (start
,
6824 cu_offset
, section
);
6827 if (need_frame_base
&& !has_frame_base
)
6828 printf (_(" [without DW_AT_frame_base]"));
6830 if (begin
== end
&& vbegin
== vend
)
6831 fputs (_(" (start == end)"), stdout
);
6832 else if (begin
> end
|| (begin
== end
&& vbegin
> vend
))
6833 fputs (_(" (start > end)"), stdout
);
6841 *vstart_ptr
= vstart
;
6844 /* Display a location list from a normal (ie, non-dwo) .debug_loclists section. */
6847 display_loclists_list (struct dwarf_section
* section
,
6848 unsigned char ** start_ptr
,
6849 debug_info
* debug_info_p
,
6851 uint64_t base_address
,
6852 unsigned char ** vstart_ptr
,
6855 unsigned char *start
= *start_ptr
;
6856 unsigned char *vstart
= *vstart_ptr
;
6857 unsigned char *section_end
= section
->start
+ section
->size
;
6859 unsigned int pointer_size
;
6860 unsigned int offset_size
;
6861 unsigned int dwarf_version
;
6864 /* Initialize it due to a false compiler warning. */
6865 uint64_t begin
= -1, vbegin
= -1;
6866 uint64_t end
= -1, vend
= -1;
6868 int need_frame_base
;
6870 cu_offset
= debug_info_p
->cu_offset
;
6871 pointer_size
= debug_info_p
->pointer_size
;
6872 offset_size
= debug_info_p
->offset_size
;
6873 dwarf_version
= debug_info_p
->dwarf_version
;
6875 if (pointer_size
< 2 || pointer_size
> 8)
6877 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
6878 pointer_size
, (int)(debug_info_p
- debug_information
));
6884 uint64_t off
= offset
+ (start
- *start_ptr
);
6885 enum dwarf_location_list_entry_type llet
;
6887 if (start
+ 1 > section_end
)
6889 warn (_("Location list starting at offset %#" PRIx64
6890 " is not terminated.\n"), offset
);
6897 SAFE_BYTE_GET_AND_INC (llet
, start
, 1, section_end
);
6899 if (vstart
&& (llet
== DW_LLE_offset_pair
6900 || llet
== DW_LLE_start_end
6901 || llet
== DW_LLE_start_length
))
6903 off
= offset
+ (vstart
- *start_ptr
);
6905 READ_ULEB (vbegin
, vstart
, section_end
);
6906 print_view (vbegin
, pointer_size
);
6908 READ_ULEB (vend
, vstart
, section_end
);
6909 print_view (vend
, pointer_size
);
6911 printf (_("views at %8.8" PRIx64
" for:\n %*s "), off
, 8, "");
6916 case DW_LLE_end_of_list
:
6917 printf (_("<End of list>\n"));
6920 case DW_LLE_base_addressx
:
6921 READ_ULEB (idx
, start
, section_end
);
6922 print_hex (idx
, pointer_size
);
6923 printf (_("(index into .debug_addr) "));
6924 base_address
= fetch_indexed_addr
6925 (debug_info_p
->addr_base
+ idx
* pointer_size
, pointer_size
);
6926 print_hex (base_address
, pointer_size
);
6927 printf (_("(base address)\n"));
6930 case DW_LLE_startx_endx
:
6931 READ_ULEB (idx
, start
, section_end
);
6932 begin
= fetch_indexed_addr
6933 (debug_info_p
->addr_base
+ idx
* pointer_size
, pointer_size
);
6934 READ_ULEB (idx
, start
, section_end
);
6935 end
= fetch_indexed_addr
6936 (debug_info_p
->addr_base
+ idx
* pointer_size
, pointer_size
);
6939 case DW_LLE_startx_length
:
6940 READ_ULEB (idx
, start
, section_end
);
6941 begin
= fetch_indexed_addr
6942 (debug_info_p
->addr_base
+ idx
* pointer_size
, pointer_size
);
6943 READ_ULEB (end
, start
, section_end
);
6947 case DW_LLE_default_location
:
6951 case DW_LLE_offset_pair
:
6952 READ_ULEB (begin
, start
, section_end
);
6953 begin
+= base_address
;
6954 READ_ULEB (end
, start
, section_end
);
6955 end
+= base_address
;
6958 case DW_LLE_base_address
:
6959 SAFE_BYTE_GET_AND_INC (base_address
, start
, pointer_size
,
6961 print_hex (base_address
, pointer_size
);
6962 printf (_("(base address)\n"));
6965 case DW_LLE_start_end
:
6966 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, section_end
);
6967 SAFE_BYTE_GET_AND_INC (end
, start
, pointer_size
, section_end
);
6970 case DW_LLE_start_length
:
6971 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, section_end
);
6972 READ_ULEB (end
, start
, section_end
);
6976 #ifdef DW_LLE_view_pair
6977 case DW_LLE_view_pair
:
6979 printf (_("View pair entry in loclist with locviews attribute\n"));
6980 READ_ULEB (vbegin
, start
, section_end
);
6981 print_view (vbegin
, pointer_size
);
6983 READ_ULEB (vend
, start
, section_end
);
6984 print_view (vend
, pointer_size
);
6986 printf (_("views for:\n"));
6991 error (_("Invalid location list entry type %d\n"), llet
);
6995 if (llet
== DW_LLE_end_of_list
)
6998 if (llet
== DW_LLE_base_address
6999 || llet
== DW_LLE_base_addressx
)
7002 if (start
== section_end
)
7004 warn (_("Location list starting at offset %#" PRIx64
7005 " is not terminated.\n"), offset
);
7008 READ_ULEB (length
, start
, section_end
);
7010 if (length
> (size_t) (section_end
- start
))
7012 warn (_("Location list starting at offset %#" PRIx64
7013 " is not terminated.\n"), offset
);
7017 print_hex (begin
, pointer_size
);
7018 print_hex (end
, pointer_size
);
7021 need_frame_base
= decode_location_expression (start
,
7026 cu_offset
, section
);
7029 if (need_frame_base
&& !has_frame_base
)
7030 printf (_(" [without DW_AT_frame_base]"));
7032 if (begin
== end
&& vbegin
== vend
)
7033 fputs (_(" (start == end)"), stdout
);
7034 else if (begin
> end
|| (begin
== end
&& vbegin
> vend
))
7035 fputs (_(" (start > end)"), stdout
);
7043 if (vbegin
!= (uint64_t) -1 || vend
!= (uint64_t) -1)
7044 printf (_("Trailing view pair not used in a range"));
7047 *vstart_ptr
= vstart
;
7050 /* Print a .debug_addr table index in decimal, surrounded by square brackets,
7051 right-adjusted in a field of length LEN, and followed by a space. */
7054 print_addr_index (unsigned int idx
, unsigned int len
)
7056 static char buf
[15];
7057 snprintf (buf
, sizeof (buf
), "[%d]", idx
);
7058 printf ("%*s ", len
, buf
);
7061 /* Display a location list from a .dwo section. It uses address indexes rather
7062 than embedded addresses. This code closely follows display_loc_list, but the
7063 two are sufficiently different that combining things is very ugly. */
7066 display_loc_list_dwo (struct dwarf_section
*section
,
7067 unsigned char **start_ptr
,
7068 unsigned int debug_info_entry
,
7070 unsigned char **vstart_ptr
,
7073 unsigned char *start
= *start_ptr
, *vstart
= *vstart_ptr
;
7074 unsigned char *section_end
= section
->start
+ section
->size
;
7076 unsigned int pointer_size
;
7077 unsigned int offset_size
;
7080 unsigned short length
;
7081 int need_frame_base
;
7084 if (debug_info_entry
>= num_debug_info_entries
)
7086 warn (_("No debug information for loc lists of entry: %u\n"),
7091 cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
7092 pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
7093 offset_size
= debug_information
[debug_info_entry
].offset_size
;
7094 dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
7096 if (pointer_size
< 2 || pointer_size
> 8)
7098 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
7099 pointer_size
, debug_info_entry
);
7106 print_hex (offset
+ (start
- *start_ptr
), 4);
7108 if (start
>= section_end
)
7110 warn (_("Location list starting at offset %#" PRIx64
7111 " is not terminated.\n"), offset
);
7115 SAFE_BYTE_GET_AND_INC (entry_type
, start
, 1, section_end
);
7128 uint64_t off
= offset
+ (vstart
- *start_ptr
);
7130 READ_ULEB (view
, vstart
, section_end
);
7131 print_view (view
, 8);
7133 READ_ULEB (view
, vstart
, section_end
);
7134 print_view (view
, 8);
7136 printf (_("views at %8.8" PRIx64
" for:\n %*s "), off
, 8, "");
7144 case 0: /* A terminating entry. */
7146 *vstart_ptr
= vstart
;
7147 printf (_("<End of list>\n"));
7149 case 1: /* A base-address entry. */
7150 READ_ULEB (idx
, start
, section_end
);
7151 print_addr_index (idx
, 8);
7152 printf ("%*s", 9 + (vstart
? 2 * 6 : 0), "");
7153 printf (_("(base address selection entry)\n"));
7155 case 2: /* A start/end entry. */
7156 READ_ULEB (idx
, start
, section_end
);
7157 print_addr_index (idx
, 8);
7158 READ_ULEB (idx
, start
, section_end
);
7159 print_addr_index (idx
, 8);
7161 case 3: /* A start/length entry. */
7162 READ_ULEB (idx
, start
, section_end
);
7163 print_addr_index (idx
, 8);
7164 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
7165 printf ("%08x ", idx
);
7167 case 4: /* An offset pair entry. */
7168 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
7169 printf ("%08x ", idx
);
7170 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
7171 printf ("%08x ", idx
);
7174 warn (_("Unknown location list entry type 0x%x.\n"), entry_type
);
7176 *vstart_ptr
= vstart
;
7180 if (2 > (size_t) (section_end
- start
))
7182 warn (_("Location list starting at offset %#" PRIx64
7183 " is not terminated.\n"), offset
);
7187 SAFE_BYTE_GET_AND_INC (length
, start
, 2, section_end
);
7188 if (length
> (size_t) (section_end
- start
))
7190 warn (_("Location list starting at offset %#" PRIx64
7191 " is not terminated.\n"), offset
);
7196 need_frame_base
= decode_location_expression (start
,
7201 cu_offset
, section
);
7204 if (need_frame_base
&& !has_frame_base
)
7205 printf (_(" [without DW_AT_frame_base]"));
7213 *vstart_ptr
= vstart
;
7216 /* Sort array of indexes in ascending order of loc_offsets[idx] and
7219 static uint64_t *loc_offsets
, *loc_views
;
7222 loc_offsets_compar (const void *ap
, const void *bp
)
7224 uint64_t a
= loc_offsets
[*(const unsigned int *) ap
];
7225 uint64_t b
= loc_offsets
[*(const unsigned int *) bp
];
7227 int ret
= (a
> b
) - (b
> a
);
7231 a
= loc_views
[*(const unsigned int *) ap
];
7232 b
= loc_views
[*(const unsigned int *) bp
];
7234 ret
= (a
> b
) - (b
> a
);
7239 /* Reads and dumps the DWARFv5 loclists compiler unit header,
7240 including the offset table.
7241 Returns the offset of the next compile unit header. */
7244 display_loclists_unit_header (struct dwarf_section
* section
,
7245 uint64_t header_offset
,
7246 uint32_t * offset_count
,
7247 unsigned char ** loclists_start
)
7250 unsigned char *start
= section
->start
+ header_offset
;
7251 unsigned char *end
= section
->start
+ section
->size
;
7252 unsigned short version
;
7253 unsigned char address_size
;
7254 unsigned char segment_selector_size
;
7258 printf (_("Table at Offset %#" PRIx64
"\n"), header_offset
);
7260 SAFE_BYTE_GET_AND_INC (length
, start
, 4, end
);
7261 if (length
== 0xffffffff)
7264 SAFE_BYTE_GET_AND_INC (length
, start
, 8, end
);
7269 SAFE_BYTE_GET_AND_INC (version
, start
, 2, end
);
7270 SAFE_BYTE_GET_AND_INC (address_size
, start
, 1, end
);
7271 SAFE_BYTE_GET_AND_INC (segment_selector_size
, start
, 1, end
);
7272 SAFE_BYTE_GET_AND_INC (*offset_count
, start
, 4, end
);
7274 printf (_(" Length: %#" PRIx64
"\n"), length
);
7275 printf (_(" DWARF version: %u\n"), version
);
7276 printf (_(" Address size: %u\n"), address_size
);
7277 printf (_(" Segment size: %u\n"), segment_selector_size
);
7278 printf (_(" Offset entries: %u\n"), *offset_count
);
7280 if (segment_selector_size
!= 0)
7282 warn (_("The %s section contains an "
7283 "unsupported segment selector size: %d.\n"),
7284 section
->name
, segment_selector_size
);
7285 return (uint64_t)-1;
7290 printf (_("\n Offset Entries starting at %#tx:\n"),
7291 start
- section
->start
);
7293 for (i
= 0; i
< *offset_count
; i
++)
7297 SAFE_BYTE_GET_AND_INC (entry
, start
, is_64bit
? 8 : 4, end
);
7298 printf (_(" [%6u] %#" PRIx64
"\n"), i
, entry
);
7303 *loclists_start
= start
;
7305 /* The length field doesn't include the length field itself. */
7306 return header_offset
+ length
+ (is_64bit
? 12 : 4);
7310 display_debug_loc (struct dwarf_section
*section
, void *file
)
7312 unsigned char *start
= section
->start
, *vstart
= NULL
;
7314 unsigned char *section_begin
= start
;
7315 unsigned int num_loc_list
= 0;
7316 uint64_t last_offset
= 0;
7317 uint64_t last_view
= 0;
7318 unsigned int first
= 0;
7321 int seen_first_offset
= 0;
7322 int locs_sorted
= 1;
7323 unsigned char *next
= start
, *vnext
= vstart
;
7324 unsigned int *array
= NULL
;
7325 const char *suffix
= strrchr (section
->name
, '.');
7326 bool is_dwo
= false;
7327 bool is_loclists
= strstr (section
->name
, "debug_loclists") != NULL
;
7328 uint64_t next_header_offset
= 0;
7330 if (suffix
&& strcmp (suffix
, ".dwo") == 0)
7333 bytes
= section
->size
;
7337 printf (_("\nThe %s section is empty.\n"), section
->name
);
7343 unsigned char *hdrptr
= section_begin
;
7345 unsigned short ll_version
;
7346 unsigned char *end
= section_begin
+ section
->size
;
7347 unsigned char address_size
, segment_selector_size
;
7348 uint32_t offset_entry_count
;
7350 SAFE_BYTE_GET_AND_INC (ll_length
, hdrptr
, 4, end
);
7351 if (ll_length
== 0xffffffff)
7352 SAFE_BYTE_GET_AND_INC (ll_length
, hdrptr
, 8, end
);
7354 SAFE_BYTE_GET_AND_INC (ll_version
, hdrptr
, 2, end
);
7355 if (ll_version
!= 5)
7357 warn (_("The %s section contains corrupt or "
7358 "unsupported version number: %d.\n"),
7359 section
->name
, ll_version
);
7363 SAFE_BYTE_GET_AND_INC (address_size
, hdrptr
, 1, end
);
7365 SAFE_BYTE_GET_AND_INC (segment_selector_size
, hdrptr
, 1, end
);
7366 if (segment_selector_size
!= 0)
7368 warn (_("The %s section contains "
7369 "unsupported segment selector size: %d.\n"),
7370 section
->name
, segment_selector_size
);
7374 SAFE_BYTE_GET_AND_INC (offset_entry_count
, hdrptr
, 4, end
);
7376 /*if (offset_entry_count != 0)
7377 return display_offset_entry_loclists (section);*/
7379 //header_size = hdrptr - section_begin;
7382 if (load_debug_info (file
) == 0)
7384 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
7389 /* Check the order of location list in .debug_info section. If
7390 offsets of location lists are in the ascending order, we can
7391 use `debug_information' directly. */
7392 for (i
= 0; i
< num_debug_info_entries
; i
++)
7396 num
= debug_information
[i
].num_loc_offsets
;
7397 if (num
> num_loc_list
)
7400 /* Check if we can use `debug_information' directly. */
7401 if (locs_sorted
&& num
!= 0)
7403 if (!seen_first_offset
)
7405 /* This is the first location list. */
7406 last_offset
= debug_information
[i
].loc_offsets
[0];
7407 last_view
= debug_information
[i
].loc_views
[0];
7409 seen_first_offset
= 1;
7415 for (; j
< num
; j
++)
7417 if (last_offset
> debug_information
[i
].loc_offsets
[j
]
7418 || (last_offset
== debug_information
[i
].loc_offsets
[j
]
7419 && last_view
> debug_information
[i
].loc_views
[j
]))
7424 last_offset
= debug_information
[i
].loc_offsets
[j
];
7425 last_view
= debug_information
[i
].loc_views
[j
];
7430 if (!seen_first_offset
)
7431 error (_("No location lists in .debug_info section!\n"));
7434 array
= (unsigned int *) xcmalloc (num_loc_list
, sizeof (unsigned int));
7436 introduce (section
, false);
7438 if (reloc_at (section
, 0))
7439 printf (_(" Warning: This section has relocations - addresses seen here may not be accurate.\n\n"));
7442 printf (_(" Offset Begin End Expression\n"));
7444 for (i
= first
; i
< num_debug_info_entries
; i
++)
7446 uint64_t offset
= 0, voffset
= 0;
7447 uint64_t base_address
;
7450 debug_info
*debug_info_p
= debug_information
+ i
;
7451 uint32_t offset_count
;
7453 /* .debug_loclists section is loaded into debug_information as
7454 DWARF-5 debug info and .debug_loc section is loaded into
7455 debug_information as pre-DWARF-5 debug info. When dumping
7456 .debug_loc section, we should only process pre-DWARF-5 debug
7457 info in debug_information. When dumping .debug_loclists
7458 section, we should only process DWARF-5 info in
7459 debug_information. */
7460 if ((debug_info_p
->dwarf_version
>= 5) != is_loclists
)
7465 for (k
= 0; k
< debug_info_p
->num_loc_offsets
; k
++)
7467 loc_offsets
= debug_info_p
->loc_offsets
;
7468 loc_views
= debug_info_p
->loc_views
;
7469 qsort (array
, debug_info_p
->num_loc_offsets
,
7470 sizeof (*array
), loc_offsets_compar
);
7473 /* .debug_loclists has a per-unit header.
7474 Update start if we are detecting it. */
7475 if (debug_info_p
->dwarf_version
>= 5)
7477 j
= locs_sorted
? 0 : array
[0];
7479 if (debug_info_p
->num_loc_offsets
)
7480 offset
= debug_info_p
->loc_offsets
[j
];
7482 if (debug_info_p
->num_loc_views
)
7483 voffset
= debug_info_p
->loc_views
[j
];
7485 /* Parse and dump unit headers in loclists.
7486 This will misbehave if the order of CUs in debug_info
7487 doesn't match the one in loclists. */
7488 if (next_header_offset
< offset
)
7490 while (next_header_offset
< offset
)
7492 next_header_offset
= display_loclists_unit_header
7493 (section
, next_header_offset
, &offset_count
, &start
);
7495 if (next_header_offset
== (uint64_t)-1)
7496 /* Header parsing error. */
7501 Offset Begin End Expression\n"));
7505 int adjacent_view_loclists
= 1;
7507 for (k
= 0; k
< debug_info_p
->num_loc_offsets
; k
++)
7509 j
= locs_sorted
? k
: array
[k
];
7511 && (debug_info_p
->loc_offsets
[locs_sorted
7512 ? k
- 1 : array
[k
- 1]]
7513 == debug_info_p
->loc_offsets
[j
])
7514 && (debug_info_p
->loc_views
[locs_sorted
7515 ? k
- 1 : array
[k
- 1]]
7516 == debug_info_p
->loc_views
[j
]))
7518 has_frame_base
= debug_info_p
->have_frame_base
[j
];
7519 offset
= debug_info_p
->loc_offsets
[j
];
7520 next
= section_begin
+ offset
;
7521 voffset
= debug_info_p
->loc_views
[j
];
7522 if (voffset
!= (uint64_t) -1)
7523 vnext
= section_begin
+ voffset
;
7526 base_address
= debug_info_p
->base_address
;
7528 if (vnext
&& vnext
< next
)
7531 display_view_pair_list (section
, &vstart
, i
, next
);
7538 if (vnext
&& vnext
< next
)
7539 warn (_("There is a hole [%#tx - %#" PRIx64
"]"
7540 " in %s section.\n"),
7541 start
- section_begin
, voffset
, section
->name
);
7543 warn (_("There is a hole [%#tx - %#" PRIx64
"]"
7544 " in %s section.\n"),
7545 start
- section_begin
, offset
, section
->name
);
7547 else if (start
> next
)
7548 warn (_("There is an overlap [%#tx - %#" PRIx64
"]"
7549 " in %s section.\n"),
7550 start
- section_begin
, offset
, section
->name
);
7554 if (offset
>= bytes
)
7556 warn (_("Offset %#" PRIx64
" is bigger than %s section size.\n"),
7557 offset
, section
->name
);
7561 if (vnext
&& voffset
>= bytes
)
7563 warn (_("View Offset %#" PRIx64
" is bigger than %s section size.\n"),
7564 voffset
, section
->name
);
7571 display_loc_list_dwo (section
, &start
, i
, offset
,
7572 &vstart
, has_frame_base
);
7574 display_loc_list (section
, &start
, i
, offset
, base_address
,
7575 &vstart
, has_frame_base
);
7580 warn (_("DWO is not yet supported.\n"));
7582 display_loclists_list (section
, &start
, debug_info_p
, offset
,
7583 base_address
, &vstart
, has_frame_base
);
7586 /* FIXME: this arrangement is quite simplistic. Nothing
7587 requires locview lists to be adjacent to corresponding
7588 loclists, and a single loclist could be augmented by
7589 different locview lists, and vice-versa, unlikely as it
7590 is that it would make sense to do so. Hopefully we'll
7591 have view pair support built into loclists before we ever
7592 need to address all these possibilities. */
7593 if (adjacent_view_loclists
&& vnext
7594 && vnext
!= start
&& vstart
!= next
)
7596 adjacent_view_loclists
= 0;
7597 warn (_("Hole and overlap detection requires adjacent view lists and loclists.\n"));
7600 if (vnext
&& vnext
== start
)
7601 display_view_pair_list (section
, &start
, i
, vstart
);
7605 if (start
< section
->start
+ section
->size
)
7606 warn (ngettext ("There is %ld unused byte at the end of section %s\n",
7607 "There are %ld unused bytes at the end of section %s\n",
7608 (long) (section
->start
+ section
->size
- start
)),
7609 (long) (section
->start
+ section
->size
- start
), section
->name
);
7616 display_debug_str (struct dwarf_section
*section
,
7617 void *file ATTRIBUTE_UNUSED
)
7619 unsigned char *start
= section
->start
;
7620 uint64_t bytes
= section
->size
;
7621 uint64_t addr
= section
->address
;
7625 printf (_("\nThe %s section is empty.\n"), section
->name
);
7629 introduce (section
, false);
7637 lbytes
= (bytes
> 16 ? 16 : bytes
);
7639 printf (" 0x%8.8" PRIx64
" ", addr
);
7641 for (j
= 0; j
< 16; j
++)
7644 printf ("%2.2x", start
[j
]);
7652 for (j
= 0; j
< lbytes
; j
++)
7655 if (k
>= ' ' && k
< 0x80)
7674 display_debug_info (struct dwarf_section
*section
, void *file
)
7676 return process_debug_info (section
, file
, section
->abbrev_sec
, false, false);
7680 display_debug_types (struct dwarf_section
*section
, void *file
)
7682 return process_debug_info (section
, file
, section
->abbrev_sec
, false, true);
7686 display_trace_info (struct dwarf_section
*section
, void *file
)
7688 return process_debug_info (section
, file
, section
->abbrev_sec
, false, true);
7692 display_debug_aranges (struct dwarf_section
*section
,
7693 void *file ATTRIBUTE_UNUSED
)
7695 unsigned char *start
= section
->start
;
7696 unsigned char *end
= start
+ section
->size
;
7698 introduce (section
, false);
7700 /* It does not matter if this load fails,
7701 we test for that later on. */
7702 load_debug_info (file
);
7706 unsigned char *hdrptr
;
7707 DWARF2_Internal_ARange arange
;
7708 unsigned char *addr_ranges
;
7712 unsigned char address_size
;
7713 unsigned int offset_size
;
7714 unsigned char *end_ranges
;
7717 sec_off
= hdrptr
- section
->start
;
7719 SAFE_BYTE_GET_AND_INC (arange
.ar_length
, hdrptr
, 4, end
);
7720 if (arange
.ar_length
== 0xffffffff)
7722 SAFE_BYTE_GET_AND_INC (arange
.ar_length
, hdrptr
, 8, end
);
7728 if (arange
.ar_length
> (size_t) (end
- hdrptr
))
7730 warn (_("Debug info is corrupted, %s header at %#" PRIx64
7731 " has length %#" PRIx64
"\n"),
7732 section
->name
, sec_off
, arange
.ar_length
);
7735 end_ranges
= hdrptr
+ arange
.ar_length
;
7737 SAFE_BYTE_GET_AND_INC (arange
.ar_version
, hdrptr
, 2, end_ranges
);
7738 SAFE_BYTE_GET_AND_INC (arange
.ar_info_offset
, hdrptr
, offset_size
,
7741 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
7742 && num_debug_info_entries
> 0
7743 && find_debug_info_for_offset (arange
.ar_info_offset
) == NULL
)
7744 warn (_(".debug_info offset of %#" PRIx64
7745 " in %s section does not point to a CU header.\n"),
7746 arange
.ar_info_offset
, section
->name
);
7748 SAFE_BYTE_GET_AND_INC (arange
.ar_pointer_size
, hdrptr
, 1, end_ranges
);
7749 SAFE_BYTE_GET_AND_INC (arange
.ar_segment_size
, hdrptr
, 1, end_ranges
);
7751 if (arange
.ar_version
!= 2 && arange
.ar_version
!= 3)
7753 /* PR 19872: A version number of 0 probably means that there is
7754 padding at the end of the .debug_aranges section. Gold puts
7755 it there when performing an incremental link, for example.
7756 So do not generate a warning in this case. */
7757 if (arange
.ar_version
)
7758 warn (_("Only DWARF 2 and 3 aranges are currently supported.\n"));
7762 printf (_(" Length: %" PRId64
"\n"), arange
.ar_length
);
7763 printf (_(" Version: %d\n"), arange
.ar_version
);
7764 printf (_(" Offset into .debug_info: %#" PRIx64
"\n"),
7765 arange
.ar_info_offset
);
7766 printf (_(" Pointer Size: %d\n"), arange
.ar_pointer_size
);
7767 printf (_(" Segment Size: %d\n"), arange
.ar_segment_size
);
7769 address_size
= arange
.ar_pointer_size
+ arange
.ar_segment_size
;
7771 /* PR 17512: file: 001-108546-0.001:0.1. */
7772 if (address_size
== 0 || address_size
> 8)
7774 error (_("Invalid address size in %s section!\n"),
7779 /* The DWARF spec does not require that the address size be a power
7780 of two, but we do. This will have to change if we ever encounter
7781 an uneven architecture. */
7782 if ((address_size
& (address_size
- 1)) != 0)
7784 warn (_("Pointer size + Segment size is not a power of two.\n"));
7788 if (address_size
> 4)
7789 printf (_("\n Address Length\n"));
7791 printf (_("\n Address Length\n"));
7793 addr_ranges
= hdrptr
;
7795 /* Must pad to an alignment boundary that is twice the address size. */
7796 addr_ranges
+= (2 * address_size
- 1
7797 - (hdrptr
- start
- 1) % (2 * address_size
));
7799 while (2 * address_size
<= end_ranges
- addr_ranges
)
7801 SAFE_BYTE_GET_AND_INC (address
, addr_ranges
, address_size
,
7803 SAFE_BYTE_GET_AND_INC (length
, addr_ranges
, address_size
,
7806 print_hex (address
, address_size
);
7807 print_hex_ns (length
, address_size
);
7819 /* Comparison function for qsort. */
7821 comp_addr_base (const void * v0
, const void * v1
)
7823 debug_info
*info0
= *(debug_info
**) v0
;
7824 debug_info
*info1
= *(debug_info
**) v1
;
7825 return info0
->addr_base
- info1
->addr_base
;
7828 /* Display the debug_addr section. */
7830 display_debug_addr (struct dwarf_section
*section
,
7833 debug_info
**debug_addr_info
;
7834 unsigned char *entry
;
7838 unsigned char * header
;
7840 if (section
->size
== 0)
7842 printf (_("\nThe %s section is empty.\n"), section
->name
);
7846 if (load_debug_info (file
) == 0)
7848 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
7853 introduce (section
, false);
7855 /* PR 17531: file: cf38d01b.
7856 We use xcalloc because a corrupt file may not have initialised all of the
7857 fields in the debug_info structure, which means that the sort below might
7858 try to move uninitialised data. */
7859 debug_addr_info
= (debug_info
**) xcalloc ((num_debug_info_entries
+ 1),
7860 sizeof (debug_info
*));
7863 for (i
= 0; i
< num_debug_info_entries
; i
++)
7864 if (debug_information
[i
].addr_base
!= DEBUG_INFO_UNAVAILABLE
)
7866 /* PR 17531: file: cf38d01b. */
7867 if (debug_information
[i
].addr_base
>= section
->size
)
7868 warn (_("Corrupt address base (%#" PRIx64
")"
7869 " found in debug section %u\n"),
7870 debug_information
[i
].addr_base
, i
);
7872 debug_addr_info
[count
++] = debug_information
+ i
;
7875 /* Add a sentinel to make iteration convenient. */
7876 debug_addr_info
[count
] = (debug_info
*) xmalloc (sizeof (debug_info
));
7877 debug_addr_info
[count
]->addr_base
= section
->size
;
7878 qsort (debug_addr_info
, count
, sizeof (debug_info
*), comp_addr_base
);
7880 header
= section
->start
;
7881 for (i
= 0; i
< count
; i
++)
7884 unsigned int address_size
= debug_addr_info
[i
]->pointer_size
;
7886 printf (_(" For compilation unit at offset %#" PRIx64
":\n"),
7887 debug_addr_info
[i
]->cu_offset
);
7889 printf (_("\tIndex\tAddress\n"));
7890 entry
= section
->start
+ debug_addr_info
[i
]->addr_base
;
7891 if (debug_addr_info
[i
]->dwarf_version
>= 5)
7893 size_t header_size
= entry
- header
;
7894 unsigned char *curr_header
= header
;
7897 int segment_selector_size
;
7899 if (header_size
!= 8 && header_size
!= 16)
7901 warn (_("Corrupt %s section: expecting header size of 8 or 16, but found %zd instead\n"),
7902 section
->name
, header_size
);
7906 SAFE_BYTE_GET_AND_INC (length
, curr_header
, 4, entry
);
7907 if (length
== 0xffffffff)
7908 SAFE_BYTE_GET_AND_INC (length
, curr_header
, 8, entry
);
7909 if (length
> (size_t) (section
->start
+ section
->size
- curr_header
)
7910 || length
< (size_t) (entry
- curr_header
))
7912 warn (_("Corrupt %s section: unit_length field of %#" PRIx64
7913 " is invalid\n"), section
->name
, length
);
7916 end
= curr_header
+ length
;
7917 SAFE_BYTE_GET_AND_INC (version
, curr_header
, 2, entry
);
7919 warn (_("Corrupt %s section: expecting version number 5 in header but found %d instead\n"),
7920 section
->name
, version
);
7922 SAFE_BYTE_GET_AND_INC (address_size
, curr_header
, 1, entry
);
7923 SAFE_BYTE_GET_AND_INC (segment_selector_size
, curr_header
, 1, entry
);
7924 address_size
+= segment_selector_size
;
7927 end
= section
->start
+ debug_addr_info
[i
+ 1]->addr_base
;
7932 if (address_size
< 1 || address_size
> sizeof (uint64_t))
7934 warn (_("Corrupt %s section: address size (%x) is wrong\n"),
7935 section
->name
, address_size
);
7939 while ((size_t) (end
- entry
) >= address_size
)
7941 uint64_t base
= byte_get (entry
, address_size
);
7942 printf (_("\t%d:\t"), idx
);
7943 print_hex_ns (base
, address_size
);
7945 entry
+= address_size
;
7951 free (debug_addr_info
[count
]);
7952 free (debug_addr_info
);
7956 /* Display the .debug_str_offsets and .debug_str_offsets.dwo sections. */
7959 display_debug_str_offsets (struct dwarf_section
*section
,
7960 void *file ATTRIBUTE_UNUSED
)
7964 if (section
->size
== 0)
7966 printf (_("\nThe %s section is empty.\n"), section
->name
);
7970 unsigned char *start
= section
->start
;
7971 unsigned char *end
= start
+ section
->size
;
7972 unsigned char *curr
= start
;
7973 uint64_t debug_str_offsets_hdr_len
;
7975 const char *suffix
= strrchr (section
->name
, '.');
7976 bool dwo
= suffix
&& strcmp (suffix
, ".dwo") == 0;
7979 load_debug_section_with_follow (str_dwo
, file
);
7981 load_debug_section_with_follow (str
, file
);
7983 introduce (section
, false);
7988 uint64_t entry_length
;
7990 SAFE_BYTE_GET_AND_INC (length
, curr
, 4, end
);
7991 /* FIXME: We assume that this means 64-bit DWARF is being used. */
7992 if (length
== 0xffffffff)
7994 SAFE_BYTE_GET_AND_INC (length
, curr
, 8, end
);
7996 debug_str_offsets_hdr_len
= 16;
8001 debug_str_offsets_hdr_len
= 8;
8004 unsigned char *entries_end
;
8007 /* This is probably an old style .debug_str_offset section which
8008 just contains offsets and no header (and the first offset is 0). */
8009 length
= section
->size
;
8010 curr
= section
->start
;
8012 debug_str_offsets_hdr_len
= 0;
8014 printf (_(" Length: %#" PRIx64
"\n"), length
);
8015 printf (_(" Index Offset [String]\n"));
8019 if (length
<= (size_t) (end
- curr
))
8020 entries_end
= curr
+ length
;
8023 warn (_("Section %s is too small %#" PRIx64
"\n"),
8024 section
->name
, section
->size
);
8029 SAFE_BYTE_GET_AND_INC (version
, curr
, 2, entries_end
);
8031 warn (_("Unexpected version number in str_offset header: %#x\n"), version
);
8034 SAFE_BYTE_GET_AND_INC (padding
, curr
, 2, entries_end
);
8036 warn (_("Unexpected value in str_offset header's padding field: %#x\n"), padding
);
8038 printf (_(" Length: %#" PRIx64
"\n"), length
);
8039 printf (_(" Version: %#x\n"), version
);
8040 printf (_(" Index Offset [String]\n"));
8043 for (idx
= 0; curr
< entries_end
; idx
++)
8046 const unsigned char * string
;
8048 if ((size_t) (entries_end
- curr
) < entry_length
)
8049 /* Not enough space to read one entry_length, give up. */
8052 SAFE_BYTE_GET_AND_INC (offset
, curr
, entry_length
, entries_end
);
8054 string
= (const unsigned char *)
8055 fetch_indexed_string (idx
, NULL
, entry_length
, dwo
, debug_str_offsets_hdr_len
);
8057 string
= fetch_indirect_string (offset
);
8059 printf (" %8lu ", idx
);
8060 print_hex (offset
, entry_length
);
8061 printf (" %s\n", string
);
8068 /* Each debug_information[x].range_lists[y] gets this representation for
8069 sorting purposes. */
8073 /* The debug_information[x].range_lists[y] value. */
8074 uint64_t ranges_offset
;
8076 /* Original debug_information to find parameters of the data. */
8077 debug_info
*debug_info_p
;
8080 /* Sort struct range_entry in ascending order of its RANGES_OFFSET. */
8083 range_entry_compar (const void *ap
, const void *bp
)
8085 const struct range_entry
*a_re
= (const struct range_entry
*) ap
;
8086 const struct range_entry
*b_re
= (const struct range_entry
*) bp
;
8087 const uint64_t a
= a_re
->ranges_offset
;
8088 const uint64_t b
= b_re
->ranges_offset
;
8090 return (a
> b
) - (b
> a
);
8093 static unsigned char *
8094 display_debug_ranges_list (unsigned char * start
,
8095 unsigned char * finish
,
8096 unsigned int pointer_size
,
8098 uint64_t base_address
)
8100 while (start
< finish
)
8105 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
8106 if (start
>= finish
)
8108 SAFE_SIGNED_BYTE_GET_AND_INC (end
, start
, pointer_size
, finish
);
8111 print_hex (offset
, 4);
8113 if (begin
== 0 && end
== 0)
8115 printf (_("<End of list>\n"));
8119 /* Check base address specifiers. */
8120 if (is_max_address (begin
, pointer_size
)
8121 && !is_max_address (end
, pointer_size
))
8124 print_hex (begin
, pointer_size
);
8125 print_hex (end
, pointer_size
);
8126 printf ("(base address)\n");
8130 print_hex (begin
+ base_address
, pointer_size
);
8131 print_hex_ns (end
+ base_address
, pointer_size
);
8134 fputs (_(" (start == end)"), stdout
);
8135 else if (begin
> end
)
8136 fputs (_(" (start > end)"), stdout
);
8144 static unsigned char *
8145 display_debug_rnglists_list (unsigned char * start
,
8146 unsigned char * finish
,
8147 unsigned int pointer_size
,
8149 uint64_t base_address
,
8152 unsigned char *next
= start
;
8156 uint64_t off
= offset
+ (start
- next
);
8157 enum dwarf_range_list_entry rlet
;
8158 /* Initialize it due to a false compiler warning. */
8159 uint64_t begin
= -1, length
, end
= -1;
8161 if (start
>= finish
)
8163 warn (_("Range list starting at offset %#" PRIx64
8164 " is not terminated.\n"), offset
);
8171 SAFE_BYTE_GET_AND_INC (rlet
, start
, 1, finish
);
8175 case DW_RLE_end_of_list
:
8176 printf (_("<End of list>\n"));
8178 case DW_RLE_base_addressx
:
8179 READ_ULEB (base_address
, start
, finish
);
8180 print_hex (base_address
, pointer_size
);
8181 printf (_("(base address index) "));
8182 base_address
= fetch_indexed_addr (base_address
* pointer_size
+ addr_base
,
8184 print_hex (base_address
, pointer_size
);
8185 printf (_("(base address)\n"));
8187 case DW_RLE_startx_endx
:
8188 READ_ULEB (begin
, start
, finish
);
8189 READ_ULEB (end
, start
, finish
);
8190 begin
= fetch_indexed_addr (begin
* pointer_size
+ addr_base
,
8192 end
= fetch_indexed_addr (end
* pointer_size
+ addr_base
,
8195 case DW_RLE_startx_length
:
8196 READ_ULEB (begin
, start
, finish
);
8197 READ_ULEB (length
, start
, finish
);
8198 begin
= fetch_indexed_addr (begin
* pointer_size
+ addr_base
,
8200 end
= begin
+ length
;
8202 case DW_RLE_offset_pair
:
8203 READ_ULEB (begin
, start
, finish
);
8204 READ_ULEB (end
, start
, finish
);
8206 case DW_RLE_base_address
:
8207 SAFE_BYTE_GET_AND_INC (base_address
, start
, pointer_size
, finish
);
8208 print_hex (base_address
, pointer_size
);
8209 printf (_("(base address)\n"));
8211 case DW_RLE_start_end
:
8212 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
8213 SAFE_BYTE_GET_AND_INC (end
, start
, pointer_size
, finish
);
8215 case DW_RLE_start_length
:
8216 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
8217 READ_ULEB (length
, start
, finish
);
8218 end
= begin
+ length
;
8221 error (_("Invalid range list entry type %d\n"), rlet
);
8222 rlet
= DW_RLE_end_of_list
;
8226 if (rlet
== DW_RLE_end_of_list
)
8228 if (rlet
== DW_RLE_base_address
|| rlet
== DW_RLE_base_addressx
)
8231 /* Only a DW_RLE_offset_pair needs the base address added. */
8232 if (rlet
== DW_RLE_offset_pair
)
8234 begin
+= base_address
;
8235 end
+= base_address
;
8238 print_hex (begin
, pointer_size
);
8239 print_hex (end
, pointer_size
);
8242 fputs (_(" (start == end)"), stdout
);
8243 else if (begin
> end
)
8244 fputs (_(" (start > end)"), stdout
);
8253 display_debug_rnglists_unit_header (struct dwarf_section
* section
,
8254 uint64_t * unit_offset
,
8255 unsigned char * poffset_size
)
8257 uint64_t start_offset
= *unit_offset
;
8258 unsigned char * p
= section
->start
+ start_offset
;
8259 unsigned char * finish
= section
->start
+ section
->size
;
8260 uint64_t initial_length
;
8261 unsigned char segment_selector_size
;
8262 unsigned int offset_entry_count
;
8264 unsigned short version
;
8265 unsigned char address_size
= 0;
8266 unsigned char offset_size
;
8268 /* Get and check the length of the block. */
8269 SAFE_BYTE_GET_AND_INC (initial_length
, p
, 4, finish
);
8271 if (initial_length
== 0xffffffff)
8273 /* This section is 64-bit DWARF 3. */
8274 SAFE_BYTE_GET_AND_INC (initial_length
, p
, 8, finish
);
8275 *poffset_size
= offset_size
= 8;
8278 *poffset_size
= offset_size
= 4;
8280 if (initial_length
> (size_t) (finish
- p
))
8282 /* If the length field has a relocation against it, then we should
8283 not complain if it is inaccurate (and probably negative).
8284 It is copied from .debug_line handling code. */
8285 if (reloc_at (section
, (p
- section
->start
) - offset_size
))
8286 initial_length
= finish
- p
;
8289 warn (_("The length field (%#" PRIx64
8290 ") in the debug_rnglists header is wrong"
8291 " - the section is too small\n"),
8297 /* Report the next unit offset to the caller. */
8298 *unit_offset
= (p
- section
->start
) + initial_length
;
8300 /* Get the other fields in the header. */
8301 SAFE_BYTE_GET_AND_INC (version
, p
, 2, finish
);
8302 SAFE_BYTE_GET_AND_INC (address_size
, p
, 1, finish
);
8303 SAFE_BYTE_GET_AND_INC (segment_selector_size
, p
, 1, finish
);
8304 SAFE_BYTE_GET_AND_INC (offset_entry_count
, p
, 4, finish
);
8306 printf (_(" Table at Offset: %#" PRIx64
":\n"), start_offset
);
8307 printf (_(" Length: %#" PRIx64
"\n"), initial_length
);
8308 printf (_(" DWARF version: %u\n"), version
);
8309 printf (_(" Address size: %u\n"), address_size
);
8310 printf (_(" Segment size: %u\n"), segment_selector_size
);
8311 printf (_(" Offset entries: %u\n"), offset_entry_count
);
8313 /* Check the fields. */
8314 if (segment_selector_size
!= 0)
8316 warn (_("The %s section contains "
8317 "unsupported segment selector size: %d.\n"),
8318 section
->name
, segment_selector_size
);
8324 warn (_("Only DWARF version 5+ debug_rnglists info "
8325 "is currently supported.\n"));
8329 if (offset_entry_count
!= 0)
8331 printf (_("\n Offsets starting at %#tx:\n"), p
- section
->start
);
8333 for (i
= 0; i
< offset_entry_count
; i
++)
8337 SAFE_BYTE_GET_AND_INC (entry
, p
, offset_size
, finish
);
8338 printf (_(" [%6u] %#" PRIx64
"\n"), i
, entry
);
8346 is_range_list_for_this_section (bool is_rnglists
, unsigned int version
)
8348 if (is_rnglists
&& version
> 4)
8351 if (! is_rnglists
&& version
< 5)
8358 display_debug_ranges (struct dwarf_section
*section
,
8359 void *file ATTRIBUTE_UNUSED
)
8361 unsigned char *start
= section
->start
;
8362 unsigned char *last_start
= start
;
8363 unsigned char *last_end
;
8364 uint64_t bytes
= section
->size
;
8365 unsigned char *section_begin
= start
;
8366 unsigned char *finish
= start
+ bytes
;
8367 unsigned int num_range_list
, i
;
8368 struct range_entry
*range_entries
;
8369 struct range_entry
*range_entry_fill
;
8370 bool is_rnglists
= strstr (section
->name
, "debug_rnglists") != NULL
;
8371 uint64_t last_offset
= 0;
8372 uint64_t next_rnglists_cu_offset
= 0;
8373 unsigned char offset_size
;
8377 printf (_("\nThe %s section is empty.\n"), section
->name
);
8381 introduce (section
, false);
8383 if (load_debug_info (file
) == 0)
8385 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
8391 for (i
= 0; i
< num_debug_info_entries
; i
++)
8392 if (is_range_list_for_this_section (is_rnglists
, debug_information
[i
].dwarf_version
))
8393 num_range_list
+= debug_information
[i
].num_range_lists
;
8395 if (num_range_list
== 0)
8397 /* This can happen when the file was compiled with -gsplit-debug
8398 which removes references to range lists from the primary .o file. */
8399 printf (_("No range lists referenced by .debug_info section.\n"));
8403 range_entry_fill
= range_entries
= XNEWVEC (struct range_entry
, num_range_list
);
8405 for (i
= 0; i
< num_debug_info_entries
; i
++)
8407 debug_info
*debug_info_p
= &debug_information
[i
];
8410 for (j
= 0; j
< debug_info_p
->num_range_lists
; j
++)
8412 if (is_range_list_for_this_section (is_rnglists
, debug_info_p
->dwarf_version
))
8414 range_entry_fill
->ranges_offset
= debug_info_p
->range_lists
[j
];
8415 range_entry_fill
->debug_info_p
= debug_info_p
;
8421 assert (range_entry_fill
>= range_entries
);
8422 assert (num_range_list
>= (unsigned int)(range_entry_fill
- range_entries
));
8423 num_range_list
= range_entry_fill
- range_entries
;
8424 qsort (range_entries
, num_range_list
, sizeof (*range_entries
),
8425 range_entry_compar
);
8429 printf (_(" Offset Begin End\n"));
8432 for (i
= 0; i
< num_range_list
; i
++)
8434 struct range_entry
*range_entry
= &range_entries
[i
];
8435 debug_info
*debug_info_p
= range_entry
->debug_info_p
;
8436 unsigned int pointer_size
;
8438 unsigned char *next
;
8439 uint64_t base_address
;
8441 pointer_size
= debug_info_p
->pointer_size
;
8442 offset
= range_entry
->ranges_offset
;
8443 base_address
= debug_info_p
->base_address
;
8445 /* PR 17512: file: 001-101485-0.001:0.1. */
8446 if (pointer_size
< 2 || pointer_size
> 8)
8448 warn (_("Corrupt pointer size (%d) in debug entry at offset %#" PRIx64
"\n"),
8449 pointer_size
, offset
);
8453 if (offset
> (size_t) (finish
- section_begin
))
8455 warn (_("Corrupt offset (%#" PRIx64
") in range entry %u\n"),
8460 /* If we've moved on to the next compile unit in the rnglists section - dump the unit header(s). */
8461 if (is_rnglists
&& next_rnglists_cu_offset
< offset
)
8463 while (next_rnglists_cu_offset
< offset
)
8464 display_debug_rnglists_unit_header (section
, &next_rnglists_cu_offset
, &offset_size
);
8465 printf (_(" Offset Begin End\n"));
8468 next
= section_begin
+ offset
; /* Offset is from the section start, the base has already been added. */
8472 last_end
= section_begin
;
8474 last_end
+= 2 * offset_size
- 4 + 2 + 1 + 1 + 4;
8476 /* If multiple DWARF entities reference the same range then we will
8477 have multiple entries in the `range_entries' list for the same
8478 offset. Thanks to the sort above these will all be consecutive in
8479 the `range_entries' list, so we can easily ignore duplicates
8481 if (i
> 0 && last_offset
== offset
)
8483 last_offset
= offset
;
8485 if (dwarf_check
!= 0)
8489 if (last_end
!= next
)
8490 warn (_("There is a hole [%#tx - %#tx] in %s section.\n"),
8491 last_end
- section_begin
, next
- section_begin
,
8494 else if (start
> next
)
8496 if (next
== last_start
)
8498 warn (_("There is an overlap [%#tx - %#tx] in %s section.\n"),
8499 start
- section_begin
, next
- section_begin
, section
->name
);
8508 = display_debug_rnglists_list
8509 (start
, finish
, pointer_size
, offset
, base_address
,
8510 debug_info_p
->addr_base
);
8513 = display_debug_ranges_list
8514 (start
, finish
, pointer_size
, offset
, base_address
);
8517 /* Display trailing empty (or unreferenced) compile units, if any. */
8519 while (next_rnglists_cu_offset
< section
->size
)
8520 display_debug_rnglists_unit_header (section
, &next_rnglists_cu_offset
, &offset_size
);
8524 free (range_entries
);
8529 typedef struct Frame_Chunk
8531 struct Frame_Chunk
*next
;
8532 unsigned char *chunk_start
;
8534 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
8535 short int *col_type
;
8536 int64_t *col_offset
;
8538 unsigned int code_factor
;
8542 unsigned int cfa_reg
;
8543 uint64_t cfa_offset
;
8545 unsigned char fde_encoding
;
8546 unsigned char cfa_exp
;
8547 unsigned char ptr_size
;
8548 unsigned char segment_size
;
8552 typedef const char *(*dwarf_regname_lookup_ftype
) (unsigned int);
8553 static dwarf_regname_lookup_ftype dwarf_regnames_lookup_func
;
8554 static const char *const *dwarf_regnames
;
8555 static unsigned int dwarf_regnames_count
;
8556 static bool is_aarch64
;
8558 /* A marker for a col_type that means this column was never referenced
8559 in the frame info. */
8560 #define DW_CFA_unreferenced (-1)
8562 /* Return 0 if no more space is needed, 1 if more space is needed,
8563 -1 for invalid reg. */
8566 frame_need_space (Frame_Chunk
*fc
, unsigned int reg
)
8568 unsigned int prev
= fc
->ncols
;
8570 if (reg
< (unsigned int) fc
->ncols
)
8573 if (dwarf_regnames_count
> 0
8574 && reg
> dwarf_regnames_count
)
8577 fc
->ncols
= reg
+ 1;
8578 /* PR 17512: file: 10450-2643-0.004.
8579 If reg == -1 then this can happen... */
8583 /* PR 17512: file: 2844a11d. */
8584 if (fc
->ncols
> 1024 && dwarf_regnames_count
== 0)
8586 error (_("Unfeasibly large register number: %u\n"), reg
);
8588 /* FIXME: 1024 is an arbitrary limit. Increase it if
8589 we ever encounter a valid binary that exceeds it. */
8593 fc
->col_type
= xcrealloc (fc
->col_type
, fc
->ncols
,
8594 sizeof (*fc
->col_type
));
8595 fc
->col_offset
= xcrealloc (fc
->col_offset
, fc
->ncols
,
8596 sizeof (*fc
->col_offset
));
8597 /* PR 17512: file:002-10025-0.005. */
8598 if (fc
->col_type
== NULL
|| fc
->col_offset
== NULL
)
8600 error (_("Out of memory allocating %u columns in dwarf frame arrays\n"),
8606 while (prev
< fc
->ncols
)
8608 fc
->col_type
[prev
] = DW_CFA_unreferenced
;
8609 fc
->col_offset
[prev
] = 0;
8615 static const char *const dwarf_regnames_i386
[] =
8617 "eax", "ecx", "edx", "ebx", /* 0 - 3 */
8618 "esp", "ebp", "esi", "edi", /* 4 - 7 */
8619 "eip", "eflags", NULL
, /* 8 - 10 */
8620 "st0", "st1", "st2", "st3", /* 11 - 14 */
8621 "st4", "st5", "st6", "st7", /* 15 - 18 */
8622 NULL
, NULL
, /* 19 - 20 */
8623 "xmm0", "xmm1", "xmm2", "xmm3", /* 21 - 24 */
8624 "xmm4", "xmm5", "xmm6", "xmm7", /* 25 - 28 */
8625 "mm0", "mm1", "mm2", "mm3", /* 29 - 32 */
8626 "mm4", "mm5", "mm6", "mm7", /* 33 - 36 */
8627 "fcw", "fsw", "mxcsr", /* 37 - 39 */
8628 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
, /* 40 - 47 */
8629 "tr", "ldtr", /* 48 - 49 */
8630 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 50 - 57 */
8631 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 58 - 65 */
8632 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 66 - 73 */
8633 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 74 - 81 */
8634 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 82 - 89 */
8635 NULL
, NULL
, NULL
, /* 90 - 92 */
8636 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7" /* 93 - 100 */
8639 static const char *const dwarf_regnames_iamcu
[] =
8641 "eax", "ecx", "edx", "ebx", /* 0 - 3 */
8642 "esp", "ebp", "esi", "edi", /* 4 - 7 */
8643 "eip", "eflags", NULL
, /* 8 - 10 */
8644 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 11 - 18 */
8645 NULL
, NULL
, /* 19 - 20 */
8646 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 21 - 28 */
8647 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 29 - 36 */
8648 NULL
, NULL
, NULL
, /* 37 - 39 */
8649 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
, /* 40 - 47 */
8650 "tr", "ldtr", /* 48 - 49 */
8651 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 50 - 57 */
8652 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 58 - 65 */
8653 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 66 - 73 */
8654 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 74 - 81 */
8655 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 82 - 89 */
8656 NULL
, NULL
, NULL
, /* 90 - 92 */
8657 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
/* 93 - 100 */
8661 init_dwarf_regnames_i386 (void)
8663 dwarf_regnames
= dwarf_regnames_i386
;
8664 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_i386
);
8665 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8669 init_dwarf_regnames_iamcu (void)
8671 dwarf_regnames
= dwarf_regnames_iamcu
;
8672 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_iamcu
);
8673 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8676 static const char *const DW_CFA_GNU_window_save_name
[] =
8678 "DW_CFA_GNU_window_save",
8679 "DW_CFA_AARCH64_negate_ra_state"
8682 static const char *const dwarf_regnames_x86_64
[] =
8684 "rax", "rdx", "rcx", "rbx",
8685 "rsi", "rdi", "rbp", "rsp",
8686 "r8", "r9", "r10", "r11",
8687 "r12", "r13", "r14", "r15",
8689 "xmm0", "xmm1", "xmm2", "xmm3",
8690 "xmm4", "xmm5", "xmm6", "xmm7",
8691 "xmm8", "xmm9", "xmm10", "xmm11",
8692 "xmm12", "xmm13", "xmm14", "xmm15",
8693 "st0", "st1", "st2", "st3",
8694 "st4", "st5", "st6", "st7",
8695 "mm0", "mm1", "mm2", "mm3",
8696 "mm4", "mm5", "mm6", "mm7",
8698 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
,
8699 "fs.base", "gs.base", NULL
, NULL
,
8701 "mxcsr", "fcw", "fsw",
8702 "xmm16", "xmm17", "xmm18", "xmm19",
8703 "xmm20", "xmm21", "xmm22", "xmm23",
8704 "xmm24", "xmm25", "xmm26", "xmm27",
8705 "xmm28", "xmm29", "xmm30", "xmm31",
8706 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 83 - 90 */
8707 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 91 - 98 */
8708 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 99 - 106 */
8709 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 107 - 114 */
8710 NULL
, NULL
, NULL
, /* 115 - 117 */
8711 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7",
8712 "bnd0", "bnd1", "bnd2", "bnd3",
8716 init_dwarf_regnames_x86_64 (void)
8718 dwarf_regnames
= dwarf_regnames_x86_64
;
8719 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_x86_64
);
8720 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8723 static const char *const dwarf_regnames_aarch64
[] =
8725 "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7",
8726 "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15",
8727 "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23",
8728 "x24", "x25", "x26", "x27", "x28", "x29", "x30", "sp",
8729 NULL
, "elr", NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
8730 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, "vg", "ffr",
8731 "p0", "p1", "p2", "p3", "p4", "p5", "p6", "p7",
8732 "p8", "p9", "p10", "p11", "p12", "p13", "p14", "p15",
8733 "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7",
8734 "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15",
8735 "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23",
8736 "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31",
8737 "z0", "z1", "z2", "z3", "z4", "z5", "z6", "z7",
8738 "z8", "z9", "z10", "z11", "z12", "z13", "z14", "z15",
8739 "z16", "z17", "z18", "z19", "z20", "z21", "z22", "z23",
8740 "z24", "z25", "z26", "z27", "z28", "z29", "z30", "z31",
8744 init_dwarf_regnames_aarch64 (void)
8746 dwarf_regnames
= dwarf_regnames_aarch64
;
8747 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_aarch64
);
8748 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8752 static const char *const dwarf_regnames_s390
[] =
8754 /* Avoid saying "r5 (r5)", so omit the names of r0-r15. */
8755 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
8756 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
8757 "f0", "f2", "f4", "f6", "f1", "f3", "f5", "f7",
8758 "f8", "f10", "f12", "f14", "f9", "f11", "f13", "f15",
8759 "cr0", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7",
8760 "cr8", "cr9", "cr10", "cr11", "cr12", "cr13", "cr14", "cr15",
8761 "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7",
8762 "a8", "a9", "a10", "a11", "a12", "a13", "a14", "a15",
8765 "v16", "v18", "v20", "v22", "v17", "v19", "v21", "v23",
8766 "v24", "v26", "v28", "v30", "v25", "v27", "v29", "v31",
8770 init_dwarf_regnames_s390 (void)
8772 dwarf_regnames
= dwarf_regnames_s390
;
8773 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_s390
);
8774 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8777 static const char *const dwarf_regnames_riscv
[] =
8779 "zero", "ra", "sp", "gp", "tp", "t0", "t1", "t2", /* 0 - 7 */
8780 "s0", "s1", "a0", "a1", "a2", "a3", "a4", "a5", /* 8 - 15 */
8781 "a6", "a7", "s2", "s3", "s4", "s5", "s6", "s7", /* 16 - 23 */
8782 "s8", "s9", "s10", "s11", "t3", "t4", "t5", "t6", /* 24 - 31 */
8783 "ft0", "ft1", "ft2", "ft3", "ft4", "ft5", "ft6", "ft7", /* 32 - 39 */
8784 "fs0", "fs1", /* 40 - 41 */
8785 "fa0", "fa1", "fa2", "fa3", "fa4", "fa5", "fa6", "fa7", /* 42 - 49 */
8786 "fs2", "fs3", "fs4", "fs5", "fs6", "fs7", "fs8", "fs9", /* 50 - 57 */
8787 "fs10", "fs11", /* 58 - 59 */
8788 "ft8", "ft9", "ft10", "ft11", /* 60 - 63 */
8789 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 64 - 71 */
8790 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 72 - 79 */
8791 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 80 - 87 */
8792 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 88 - 95 */
8793 "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", /* 96 - 103 */
8794 "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15", /* 104 - 111 */
8795 "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23", /* 112 - 119 */
8796 "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31", /* 120 - 127 */
8799 /* A RISC-V replacement for REGNAME_INTERNAL_BY_TABLE_ONLY which handles
8800 the large number of CSRs. */
8803 regname_internal_riscv (unsigned int regno
)
8805 const char *name
= NULL
;
8807 /* Lookup in the table first, this covers GPR and FPR. */
8808 if (regno
< ARRAY_SIZE (dwarf_regnames_riscv
))
8809 name
= dwarf_regnames_riscv
[regno
];
8810 else if (regno
>= 4096 && regno
<= 8191)
8812 /* This might be a CSR, these live in a sparse number space from 4096
8813 to 8191 These numbers are defined in the RISC-V ELF ABI
8817 #define DECLARE_CSR(NAME,VALUE,CLASS,DEFINE_VER,ABORT_VER) \
8818 case VALUE + 4096: name = #NAME; break;
8819 #include "opcode/riscv-opc.h"
8824 static char csr_name
[10];
8825 snprintf (csr_name
, sizeof (csr_name
), "csr%d", (regno
- 4096));
8836 init_dwarf_regnames_riscv (void)
8838 dwarf_regnames
= NULL
;
8839 dwarf_regnames_count
= 8192;
8840 dwarf_regnames_lookup_func
= regname_internal_riscv
;
8843 static const char *const dwarf_regnames_loongarch
[] =
8845 "$zero", "$ra", "$tp", "$sp", "$a0", "$a1", "$a2", "$a3", /* 0-7 */
8846 "$a4", "$a5", "$a6", "$a7", "$t0", "$t1", "$t2", "$t3", /* 8-15 */
8847 "$t4", "$t5", "$t6", "$t7", "$t8", "$r21","$fp", "$s0", /* 16-23 */
8848 "$s1", "$s2", "$s3", "$s4", "$s5", "$s6", "$s7", "$s8", /* 24-31 */
8849 "$fa0", "$fa1", "$fa2", "$fa3", "$fa4", "$fa5", "$fa6", /* 32-38 */
8850 "$fa7", "$ft0", "$ft1", "$ft2", "$ft3", "$ft4", "$ft5", /* 39-45 */
8851 "$ft6", "$ft7", "$ft8", "$ft9", "$ft10", "$ft11", "$ft12", /* 46-52 */
8852 "$ft13", "$ft14", "$ft15", "$fs0", "$fs1", "$fs2", "$fs3", /* 53-59 */
8853 "$fs4", "$fs5", "$fs6", "$fs7", /* 60-63 */
8857 init_dwarf_regnames_loongarch (void)
8859 dwarf_regnames
= dwarf_regnames_loongarch
;
8860 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_loongarch
);
8861 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8865 init_dwarf_regnames_by_elf_machine_code (unsigned int e_machine
)
8867 dwarf_regnames_lookup_func
= NULL
;
8873 init_dwarf_regnames_i386 ();
8877 init_dwarf_regnames_iamcu ();
8883 init_dwarf_regnames_x86_64 ();
8887 init_dwarf_regnames_aarch64 ();
8891 init_dwarf_regnames_s390 ();
8895 init_dwarf_regnames_riscv ();
8899 init_dwarf_regnames_loongarch ();
8907 /* Initialize the DWARF register name lookup state based on the
8908 architecture and specific machine type of a BFD. */
8911 init_dwarf_regnames_by_bfd_arch_and_mach (enum bfd_architecture arch
,
8914 dwarf_regnames_lookup_func
= NULL
;
8922 case bfd_mach_x86_64
:
8923 case bfd_mach_x86_64_intel_syntax
:
8924 case bfd_mach_x64_32
:
8925 case bfd_mach_x64_32_intel_syntax
:
8926 init_dwarf_regnames_x86_64 ();
8930 init_dwarf_regnames_i386 ();
8935 case bfd_arch_iamcu
:
8936 init_dwarf_regnames_iamcu ();
8939 case bfd_arch_aarch64
:
8940 init_dwarf_regnames_aarch64();
8944 init_dwarf_regnames_s390 ();
8947 case bfd_arch_riscv
:
8948 init_dwarf_regnames_riscv ();
8951 case bfd_arch_loongarch
:
8952 init_dwarf_regnames_loongarch ();
8961 regname_internal_by_table_only (unsigned int regno
)
8963 if (dwarf_regnames
!= NULL
8964 && regno
< dwarf_regnames_count
8965 && dwarf_regnames
[regno
] != NULL
)
8966 return dwarf_regnames
[regno
];
8972 regname (unsigned int regno
, int name_only_p
)
8974 static char reg
[64];
8976 const char *name
= NULL
;
8978 if (dwarf_regnames_lookup_func
!= NULL
)
8979 name
= dwarf_regnames_lookup_func (regno
);
8985 snprintf (reg
, sizeof (reg
), "r%d (%s)", regno
, name
);
8988 snprintf (reg
, sizeof (reg
), "r%d", regno
);
8993 frame_display_row (Frame_Chunk
*fc
, int *need_col_headers
, unsigned int *max_regs
)
8998 if (*max_regs
!= fc
->ncols
)
8999 *max_regs
= fc
->ncols
;
9001 if (*need_col_headers
)
9003 *need_col_headers
= 0;
9005 printf ("%-*s CFA ", eh_addr_size
* 2, " LOC");
9007 for (r
= 0; r
< *max_regs
; r
++)
9008 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
9013 printf ("%-5s ", regname (r
, 1));
9019 print_hex (fc
->pc_begin
, eh_addr_size
);
9021 strcpy (tmp
, "exp");
9023 sprintf (tmp
, "%s%+d", regname (fc
->cfa_reg
, 1), (int) fc
->cfa_offset
);
9024 printf ("%-8s ", tmp
);
9026 for (r
= 0; r
< fc
->ncols
; r
++)
9028 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
9030 switch (fc
->col_type
[r
])
9032 case DW_CFA_undefined
:
9035 case DW_CFA_same_value
:
9039 sprintf (tmp
, "c%+" PRId64
, fc
->col_offset
[r
]);
9041 case DW_CFA_val_offset
:
9042 sprintf (tmp
, "v%+" PRId64
, fc
->col_offset
[r
]);
9044 case DW_CFA_register
:
9045 sprintf (tmp
, "%s", regname (fc
->col_offset
[r
], 0));
9047 case DW_CFA_expression
:
9048 strcpy (tmp
, "exp");
9050 case DW_CFA_val_expression
:
9051 strcpy (tmp
, "vexp");
9054 strcpy (tmp
, "n/a");
9057 printf ("%-5s ", tmp
);
9063 #define GET(VAR, N) SAFE_BYTE_GET_AND_INC (VAR, start, N, end)
9065 static unsigned char *
9066 read_cie (unsigned char *start
, unsigned char *end
,
9067 Frame_Chunk
**p_cie
, int *p_version
,
9068 uint64_t *p_aug_len
, unsigned char **p_aug
)
9072 unsigned char *augmentation_data
= NULL
;
9073 uint64_t augmentation_data_len
= 0;
9076 /* PR 17512: file: 001-228113-0.004. */
9080 fc
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
9081 memset (fc
, 0, sizeof (Frame_Chunk
));
9083 fc
->col_type
= xmalloc (sizeof (*fc
->col_type
));
9084 fc
->col_offset
= xmalloc (sizeof (*fc
->col_offset
));
9088 fc
->augmentation
= (char *) start
;
9089 /* PR 17512: file: 001-228113-0.004.
9090 Skip past augmentation name, but avoid running off the end of the data. */
9092 if (* start
++ == '\0')
9096 warn (_("No terminator for augmentation name\n"));
9100 if (strcmp (fc
->augmentation
, "eh") == 0)
9102 if (eh_addr_size
> (size_t) (end
- start
))
9104 start
+= eh_addr_size
;
9109 if (2 > (size_t) (end
- start
))
9111 GET (fc
->ptr_size
, 1);
9112 if (fc
->ptr_size
< 1 || fc
->ptr_size
> 8)
9114 warn (_("Invalid pointer size (%d) in CIE data\n"), fc
->ptr_size
);
9118 GET (fc
->segment_size
, 1);
9119 /* PR 17512: file: e99d2804. */
9120 if (fc
->segment_size
> 8 || fc
->segment_size
+ fc
->ptr_size
> 8)
9122 warn (_("Invalid segment size (%d) in CIE data\n"), fc
->segment_size
);
9126 eh_addr_size
= fc
->ptr_size
;
9130 fc
->ptr_size
= eh_addr_size
;
9131 fc
->segment_size
= 0;
9134 READ_ULEB (fc
->code_factor
, start
, end
);
9135 READ_SLEB (fc
->data_factor
, start
, end
);
9146 READ_ULEB (fc
->ra
, start
, end
);
9149 if (fc
->augmentation
[0] == 'z')
9153 READ_ULEB (augmentation_data_len
, start
, end
);
9154 augmentation_data
= start
;
9155 /* PR 17512: file: 11042-2589-0.004. */
9156 if (augmentation_data_len
> (size_t) (end
- start
))
9158 warn (_("Augmentation data too long: %#" PRIx64
9159 ", expected at most %#tx\n"),
9160 augmentation_data_len
, end
- start
);
9163 start
+= augmentation_data_len
;
9166 if (augmentation_data_len
)
9170 unsigned char *qend
;
9172 p
= (unsigned char *) fc
->augmentation
+ 1;
9173 q
= augmentation_data
;
9174 qend
= q
+ augmentation_data_len
;
9176 while (p
< end
&& q
< qend
)
9181 q
+= 1 + size_of_encoded_value (*q
);
9183 fc
->fde_encoding
= *q
++;
9192 /* Note - it is OK if this loop terminates with q < qend.
9193 Padding may have been inserted to align the end of the CIE. */
9198 *p_version
= version
;
9201 *p_aug_len
= augmentation_data_len
;
9202 *p_aug
= augmentation_data
;
9207 free (fc
->col_offset
);
9208 free (fc
->col_type
);
9213 /* Prints out the contents on the DATA array formatted as unsigned bytes.
9214 If do_wide is not enabled, then formats the output to fit into 80 columns.
9215 PRINTED contains the number of characters already written to the current
9219 display_data (size_t printed
, const unsigned char *data
, size_t len
)
9221 if (do_wide
|| len
< ((80 - printed
) / 3))
9222 for (printed
= 0; printed
< len
; ++printed
)
9223 printf (" %02x", data
[printed
]);
9226 for (printed
= 0; printed
< len
; ++printed
)
9228 if (printed
% (80 / 3) == 0)
9230 printf (" %02x", data
[printed
]);
9235 /* Prints out the contents on the augmentation data array.
9236 If do_wide is not enabled, then formats the output to fit into 80 columns. */
9239 display_augmentation_data (const unsigned char * data
, uint64_t len
)
9243 i
= printf (_(" Augmentation data: "));
9244 display_data (i
, data
, len
);
9248 decode_eh_encoding (unsigned int value
)
9250 if (value
== DW_EH_PE_omit
)
9254 switch (value
& 0x0f)
9256 case DW_EH_PE_uleb128
: format
= "uleb128"; break;
9257 case DW_EH_PE_udata2
: format
= "udata2"; break;
9258 case DW_EH_PE_udata4
: format
= "udata4"; break;
9259 case DW_EH_PE_udata8
: format
= "udata8"; break;
9260 case DW_EH_PE_sleb128
: format
= "sleb128"; break;
9261 case DW_EH_PE_sdata2
: format
= "sdata2"; break;
9262 case DW_EH_PE_sdata4
: format
= "sdata4"; break;
9263 case DW_EH_PE_sdata8
: format
= "sdata8"; break;
9265 default: format
= "<unknown format>"; break; /* FIXME: Generate a warning ? */
9269 switch (value
& 0xf0)
9271 case DW_EH_PE_absptr
: application
= "absolute"; break;
9272 case DW_EH_PE_pcrel
: application
= "pcrel"; break;
9273 case DW_EH_PE_textrel
: application
= "textrel"; break; /* FIXME: Is this allowed ? */
9274 case DW_EH_PE_datarel
: application
= "datarel"; break;
9275 case DW_EH_PE_funcrel
: application
= "funcrel"; break; /* FIXME: Is this allowed ? */
9276 case DW_EH_PE_aligned
: application
= "aligned"; break; /* FIXME: Is this allowed ? */
9277 case DW_EH_PE_indirect
: application
= "indirect"; break; /* FIXME: Is this allowed ? */
9279 default: application
= "<unknown application method>"; break; /* FIXME: Generate a warning ? */
9282 static char buffer
[128];
9283 sprintf (buffer
, "%s, %s", format
, application
);
9287 /* Reads a value stored at START encoded according to ENCODING.
9288 Does not read from, or past, END.
9289 Upon success, returns the read value and sets * RETURN_LEN to
9290 the number of bytes read.
9291 Upon failure returns zero and sets * RETURN_LEN to 0.
9293 Note: does not perform any application transformations to the value. */
9296 get_encoded_eh_value (unsigned int encoding
,
9297 unsigned char * start
,
9298 unsigned char * end
,
9299 unsigned int * return_len
)
9304 unsigned char * old_start
;
9306 switch (encoding
& 0x0f)
9308 case DW_EH_PE_uleb128
:
9309 val
= read_leb128 (start
, end
, false, & len
, & status
);
9314 case DW_EH_PE_sleb128
:
9315 val
= read_leb128 (start
, end
, true, & len
, & status
);
9320 case DW_EH_PE_udata2
:
9322 SAFE_BYTE_GET_AND_INC (val
, start
, 2, end
);
9323 len
= start
- old_start
== 2 ? 2 : 0;
9326 case DW_EH_PE_udata4
:
9328 SAFE_BYTE_GET_AND_INC (val
, start
, 4, end
);
9329 len
= start
- old_start
== 4 ? 4 : 0;
9332 case DW_EH_PE_udata8
:
9334 SAFE_BYTE_GET_AND_INC (val
, start
, 8, end
);
9335 len
= start
- old_start
== 8 ? 8 : 0;
9338 case DW_EH_PE_sdata2
:
9340 SAFE_SIGNED_BYTE_GET_AND_INC (val
, start
, 2, end
);
9341 len
= start
- old_start
== 2 ? 2 : 0;
9344 case DW_EH_PE_sdata4
:
9346 SAFE_SIGNED_BYTE_GET_AND_INC (val
, start
, 4, end
);
9347 len
= start
- old_start
== 4 ? 4 : 0;
9350 case DW_EH_PE_sdata8
:
9352 SAFE_SIGNED_BYTE_GET_AND_INC (val
, start
, 8, end
);
9353 len
= start
- old_start
== 8 ? 8 : 0;
9369 encoded_eh_offset (unsigned int encoding
,
9370 struct dwarf_section
* section
,
9371 uint64_t section_offset
,
9374 switch (encoding
& 0xf0)
9377 /* This should not happen. FIXME: warn ? */
9378 case DW_EH_PE_absptr
:
9381 case DW_EH_PE_pcrel
:
9382 return value
+ (uint64_t)(section
->address
+ section_offset
);
9384 case DW_EH_PE_datarel
:
9385 return value
+ (uint64_t)section
->address
;
9390 display_eh_frame_hdr (struct dwarf_section
*section
,
9391 void *file ATTRIBUTE_UNUSED
)
9393 unsigned char *start
= section
->start
;
9394 unsigned char *end
= start
+ section
->size
;
9396 introduce (section
, false);
9398 if (section
->size
< 6)
9400 warn (_(".eh_frame_hdr section is too small\n"));
9404 unsigned int version
= start
[0];
9407 warn (_("Unsupported .eh_frame_hdr version %u\n"), version
);
9411 printf (_(" Version: %u\n"), version
);
9413 unsigned int ptr_enc
= start
[1];
9414 /* Strictly speaking this is the encoding format of the eh_frame_ptr field below. */
9415 printf (_(" Pointer Encoding Format: %#x (%s)\n"), ptr_enc
, decode_eh_encoding (ptr_enc
));
9417 unsigned int count_enc
= start
[2];
9418 printf (_(" Count Encoding Format: %#x (%s)\n"), count_enc
, decode_eh_encoding (count_enc
));
9420 unsigned int table_enc
= start
[3];
9421 printf (_(" Table Encoding Format: %#x (%s)\n"), table_enc
, decode_eh_encoding (table_enc
));
9427 uint64_t eh_frame_ptr
= get_encoded_eh_value (ptr_enc
, start
, end
, & len
);
9430 warn (_("unable to read eh_frame_ptr field in .eh_frame_hdr section\n"));
9433 printf (_(" Start of frame section: %#" PRIx64
), eh_frame_ptr
);
9435 uint64_t offset_eh_frame_ptr
= encoded_eh_offset (ptr_enc
, section
, 4, eh_frame_ptr
);
9436 if (offset_eh_frame_ptr
!= eh_frame_ptr
)
9437 printf (_(" (offset: %#" PRIx64
")"), offset_eh_frame_ptr
);
9442 if (count_enc
== DW_EH_PE_omit
)
9444 warn (_("It is suspicious to have a .eh_frame_hdr section with an empty search table\n"));
9448 if (count_enc
& 0xf0)
9450 warn (_("The count field format should be absolute, not relative to an address\n"));
9454 uint64_t fde_count
= get_encoded_eh_value (count_enc
, start
, end
, & len
);
9457 warn (_("unable to read fde_count field in .eh_frame_hdr section\n"));
9460 printf (_(" Entries in search table: %#" PRIx64
), fde_count
);
9464 if (fde_count
!= 0 && table_enc
== DW_EH_PE_omit
)
9466 warn (_("It is suspicious to have a .eh_frame_hdr section an empty table but a non empty count field\n"));
9471 /* Read and display the search table. */
9472 for (i
= 0; i
< fde_count
; i
++)
9474 uint64_t location
, address
;
9475 unsigned char * row_start
= start
;
9477 location
= get_encoded_eh_value (table_enc
, start
, end
, & len
);
9480 warn (_("Failed to read location field for entry %#" PRIx64
" in the .eh_frame_hdr's search table\n"), i
);
9485 address
= get_encoded_eh_value (table_enc
, start
, end
, & len
);
9488 warn (_("Failed to read address field for entry %#" PRIx64
" in the .eh_frame_hdr's search table\n"), i
);
9493 /* This format is intended to be compatible with the output of eu-readelf's -e option. */
9494 printf (" %#" PRIx64
" (offset: %#" PRIx64
") -> %#" PRIx64
" fde=[ %5" PRIx64
"]\n",
9496 encoded_eh_offset (table_enc
, section
, row_start
- section
->start
, location
),
9498 encoded_eh_offset (table_enc
, section
, row_start
- section
->start
, address
) - offset_eh_frame_ptr
);
9506 display_debug_frames (struct dwarf_section
*section
,
9507 void *file ATTRIBUTE_UNUSED
)
9509 unsigned char *start
= section
->start
;
9510 unsigned char *end
= start
+ section
->size
;
9511 unsigned char *section_start
= start
;
9512 Frame_Chunk
*chunks
= NULL
, *forward_refs
= NULL
;
9513 Frame_Chunk
*remembered_state
= NULL
;
9515 bool is_eh
= strcmp (section
->name
, ".eh_frame") == 0;
9516 unsigned int max_regs
= 0;
9517 const char *bad_reg
= _("bad register: ");
9518 unsigned int saved_eh_addr_size
= eh_addr_size
;
9520 introduce (section
, false);
9524 unsigned char *saved_start
;
9525 unsigned char *block_end
;
9530 int need_col_headers
= 1;
9531 unsigned char *augmentation_data
= NULL
;
9532 uint64_t augmentation_data_len
= 0;
9533 unsigned int encoded_ptr_size
= saved_eh_addr_size
;
9534 unsigned int offset_size
;
9536 static Frame_Chunk fde_fc
;
9538 saved_start
= start
;
9540 SAFE_BYTE_GET_AND_INC (length
, start
, 4, end
);
9544 printf ("\n%08tx ZERO terminator\n\n",
9545 saved_start
- section_start
);
9546 /* Skip any zero terminators that directly follow.
9547 A corrupt section size could have loaded a whole
9548 slew of zero filled memory bytes. eg
9549 PR 17512: file: 070-19381-0.004. */
9550 while (start
< end
&& * start
== 0)
9555 if (length
== 0xffffffff)
9557 SAFE_BYTE_GET_AND_INC (length
, start
, 8, end
);
9563 if (length
> (size_t) (end
- start
))
9565 warn ("Invalid length %#" PRIx64
" in FDE at %#tx\n",
9566 length
, saved_start
- section_start
);
9570 block_end
= start
+ length
;
9572 SAFE_BYTE_GET_AND_INC (cie_id
, start
, offset_size
, block_end
);
9574 if (is_eh
? (cie_id
== 0) : ((offset_size
== 4 && cie_id
== DW_CIE_ID
)
9575 || (offset_size
== 8 && cie_id
== DW64_CIE_ID
)))
9580 start
= read_cie (start
, block_end
, &cie
, &version
,
9581 &augmentation_data_len
, &augmentation_data
);
9582 /* PR 17512: file: 027-135133-0.005. */
9589 fc
->chunk_start
= saved_start
;
9590 mreg
= max_regs
> 0 ? max_regs
- 1 : 0;
9593 if (frame_need_space (fc
, mreg
) < 0)
9595 if (fc
->fde_encoding
)
9596 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
9598 printf ("\n%08tx ", saved_start
- section_start
);
9599 print_hex (length
, fc
->ptr_size
);
9600 print_hex (cie_id
, offset_size
);
9602 if (do_debug_frames_interp
)
9604 printf ("CIE \"%s\" cf=%d df=%d ra=%d\n", fc
->augmentation
,
9605 fc
->code_factor
, fc
->data_factor
, fc
->ra
);
9610 printf (" Version: %d\n", version
);
9611 printf (" Augmentation: \"%s\"\n", fc
->augmentation
);
9614 printf (" Pointer Size: %u\n", fc
->ptr_size
);
9615 printf (" Segment Size: %u\n", fc
->segment_size
);
9617 printf (" Code alignment factor: %u\n", fc
->code_factor
);
9618 printf (" Data alignment factor: %d\n", fc
->data_factor
);
9619 printf (" Return address column: %d\n", fc
->ra
);
9621 if (augmentation_data_len
)
9622 display_augmentation_data (augmentation_data
, augmentation_data_len
);
9629 unsigned char *look_for
;
9630 unsigned long segment_selector
;
9636 uint64_t sign
= (uint64_t) 1 << (offset_size
* 8 - 1);
9637 cie_off
= (cie_off
^ sign
) - sign
;
9638 cie_off
= start
- 4 - section_start
- cie_off
;
9641 look_for
= section_start
+ cie_off
;
9642 if (cie_off
<= (size_t) (saved_start
- section_start
))
9644 for (cie
= chunks
; cie
; cie
= cie
->next
)
9645 if (cie
->chunk_start
== look_for
)
9648 else if (cie_off
>= section
->size
)
9652 for (cie
= forward_refs
; cie
; cie
= cie
->next
)
9653 if (cie
->chunk_start
== look_for
)
9657 unsigned int off_size
;
9658 unsigned char *cie_scan
;
9660 cie_scan
= look_for
;
9662 SAFE_BYTE_GET_AND_INC (length
, cie_scan
, 4, end
);
9663 if (length
== 0xffffffff)
9665 SAFE_BYTE_GET_AND_INC (length
, cie_scan
, 8, end
);
9668 if (length
!= 0 && length
<= (size_t) (end
- cie_scan
))
9671 unsigned char *cie_end
= cie_scan
+ length
;
9673 SAFE_BYTE_GET_AND_INC (c_id
, cie_scan
, off_size
,
9677 : ((off_size
== 4 && c_id
== DW_CIE_ID
)
9678 || (off_size
== 8 && c_id
== DW64_CIE_ID
)))
9683 read_cie (cie_scan
, cie_end
, &cie
, &version
,
9684 &augmentation_data_len
, &augmentation_data
);
9685 /* PR 17512: file: 3450-2098-0.004. */
9688 warn (_("Failed to read CIE information\n"));
9691 cie
->next
= forward_refs
;
9693 cie
->chunk_start
= look_for
;
9694 mreg
= max_regs
> 0 ? max_regs
- 1 : 0;
9697 if (frame_need_space (cie
, mreg
) < 0)
9699 warn (_("Invalid max register\n"));
9702 if (cie
->fde_encoding
)
9704 = size_of_encoded_value (cie
->fde_encoding
);
9711 memset (fc
, 0, sizeof (Frame_Chunk
));
9716 fc
->col_type
= xmalloc (sizeof (*fc
->col_type
));
9717 fc
->col_offset
= xmalloc (sizeof (*fc
->col_offset
));
9718 if (frame_need_space (fc
, max_regs
> 0 ? max_regs
- 1 : 0) < 0)
9720 warn (_("Invalid max register\n"));
9724 fc
->augmentation
= "";
9725 fc
->fde_encoding
= 0;
9726 fc
->ptr_size
= eh_addr_size
;
9727 fc
->segment_size
= 0;
9731 fc
->ncols
= cie
->ncols
;
9732 fc
->col_type
= xcmalloc (fc
->ncols
, sizeof (*fc
->col_type
));
9733 fc
->col_offset
= xcmalloc (fc
->ncols
, sizeof (*fc
->col_offset
));
9734 memcpy (fc
->col_type
, cie
->col_type
,
9735 fc
->ncols
* sizeof (*fc
->col_type
));
9736 memcpy (fc
->col_offset
, cie
->col_offset
,
9737 fc
->ncols
* sizeof (*fc
->col_offset
));
9738 fc
->augmentation
= cie
->augmentation
;
9739 fc
->ptr_size
= cie
->ptr_size
;
9740 eh_addr_size
= cie
->ptr_size
;
9741 fc
->segment_size
= cie
->segment_size
;
9742 fc
->code_factor
= cie
->code_factor
;
9743 fc
->data_factor
= cie
->data_factor
;
9744 fc
->cfa_reg
= cie
->cfa_reg
;
9745 fc
->cfa_offset
= cie
->cfa_offset
;
9747 if (frame_need_space (fc
, max_regs
> 0 ? max_regs
- 1: 0) < 0)
9749 warn (_("Invalid max register\n"));
9752 fc
->fde_encoding
= cie
->fde_encoding
;
9755 if (fc
->fde_encoding
)
9756 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
9758 segment_selector
= 0;
9759 if (fc
->segment_size
)
9761 if (fc
->segment_size
> sizeof (segment_selector
))
9763 /* PR 17512: file: 9e196b3e. */
9764 warn (_("Probably corrupt segment size: %d - using 4 instead\n"), fc
->segment_size
);
9765 fc
->segment_size
= 4;
9767 SAFE_BYTE_GET_AND_INC (segment_selector
, start
,
9768 fc
->segment_size
, block_end
);
9771 fc
->pc_begin
= get_encoded_value (&start
, fc
->fde_encoding
, section
,
9774 /* FIXME: It appears that sometimes the final pc_range value is
9775 encoded in less than encoded_ptr_size bytes. See the x86_64
9776 run of the "objcopy on compressed debug sections" test for an
9778 SAFE_BYTE_GET_AND_INC (fc
->pc_range
, start
, encoded_ptr_size
,
9781 if (cie
->augmentation
[0] == 'z')
9783 READ_ULEB (augmentation_data_len
, start
, block_end
);
9784 augmentation_data
= start
;
9785 /* PR 17512 file: 722-8446-0.004 and PR 22386. */
9786 if (augmentation_data_len
> (size_t) (block_end
- start
))
9788 warn (_("Augmentation data too long: %#" PRIx64
", "
9789 "expected at most %#tx\n"),
9790 augmentation_data_len
, block_end
- start
);
9792 augmentation_data
= NULL
;
9793 augmentation_data_len
= 0;
9795 start
+= augmentation_data_len
;
9798 printf ("\n%08tx ", saved_start
- section_start
);
9799 print_hex (length
, fc
->ptr_size
);
9800 print_hex (cie_id
, offset_size
);
9803 if (cie
->chunk_start
)
9804 printf ("cie=%08tx", cie
->chunk_start
- section_start
);
9806 /* Ideally translate "invalid " to 8 chars, trailing space
9808 printf (_("cie=invalid "));
9811 if (fc
->segment_size
)
9812 printf ("%04lx:", segment_selector
);
9814 print_hex_ns (fc
->pc_begin
, fc
->ptr_size
);
9816 print_hex_ns (fc
->pc_begin
+ fc
->pc_range
, fc
->ptr_size
);
9819 if (! do_debug_frames_interp
&& augmentation_data_len
)
9821 display_augmentation_data (augmentation_data
, augmentation_data_len
);
9826 /* At this point, fc is the current chunk, cie (if any) is set, and
9827 we're about to interpret instructions for the chunk. */
9828 /* ??? At present we need to do this always, since this sizes the
9829 fc->col_type and fc->col_offset arrays, which we write into always.
9830 We should probably split the interpreted and non-interpreted bits
9831 into two different routines, since there's so much that doesn't
9832 really overlap between them. */
9833 if (1 || do_debug_frames_interp
)
9835 /* Start by making a pass over the chunk, allocating storage
9836 and taking note of what registers are used. */
9837 unsigned char *tmp
= start
;
9839 while (start
< block_end
)
9841 unsigned int reg
, op
, opa
;
9849 /* Warning: if you add any more cases to this switch, be
9850 sure to add them to the corresponding switch below. */
9854 case DW_CFA_advance_loc
:
9857 SKIP_ULEB (start
, block_end
);
9860 case DW_CFA_restore
:
9863 case DW_CFA_set_loc
:
9864 if ((size_t) (block_end
- start
) < encoded_ptr_size
)
9867 start
+= encoded_ptr_size
;
9869 case DW_CFA_advance_loc1
:
9870 if ((size_t) (block_end
- start
) < 1)
9875 case DW_CFA_advance_loc2
:
9876 if ((size_t) (block_end
- start
) < 2)
9881 case DW_CFA_advance_loc4
:
9882 if ((size_t) (block_end
- start
) < 4)
9887 case DW_CFA_offset_extended
:
9888 case DW_CFA_val_offset
:
9889 READ_ULEB (reg
, start
, block_end
);
9890 SKIP_ULEB (start
, block_end
);
9892 case DW_CFA_restore_extended
:
9893 READ_ULEB (reg
, start
, block_end
);
9895 case DW_CFA_undefined
:
9896 READ_ULEB (reg
, start
, block_end
);
9898 case DW_CFA_same_value
:
9899 READ_ULEB (reg
, start
, block_end
);
9901 case DW_CFA_register
:
9902 READ_ULEB (reg
, start
, block_end
);
9903 SKIP_ULEB (start
, block_end
);
9905 case DW_CFA_def_cfa
:
9906 SKIP_ULEB (start
, block_end
);
9907 SKIP_ULEB (start
, block_end
);
9909 case DW_CFA_def_cfa_register
:
9910 SKIP_ULEB (start
, block_end
);
9912 case DW_CFA_def_cfa_offset
:
9913 SKIP_ULEB (start
, block_end
);
9915 case DW_CFA_def_cfa_expression
:
9916 READ_ULEB (temp
, start
, block_end
);
9917 if ((size_t) (block_end
- start
) < temp
)
9922 case DW_CFA_expression
:
9923 case DW_CFA_val_expression
:
9924 READ_ULEB (reg
, start
, block_end
);
9925 READ_ULEB (temp
, start
, block_end
);
9926 if ((size_t) (block_end
- start
) < temp
)
9931 case DW_CFA_offset_extended_sf
:
9932 case DW_CFA_val_offset_sf
:
9933 READ_ULEB (reg
, start
, block_end
);
9934 SKIP_SLEB (start
, block_end
);
9936 case DW_CFA_def_cfa_sf
:
9937 SKIP_ULEB (start
, block_end
);
9938 SKIP_SLEB (start
, block_end
);
9940 case DW_CFA_def_cfa_offset_sf
:
9941 SKIP_SLEB (start
, block_end
);
9943 case DW_CFA_MIPS_advance_loc8
:
9944 if ((size_t) (block_end
- start
) < 8)
9949 case DW_CFA_GNU_args_size
:
9950 SKIP_ULEB (start
, block_end
);
9952 case DW_CFA_GNU_negative_offset_extended
:
9953 READ_ULEB (reg
, start
, block_end
);
9954 SKIP_ULEB (start
, block_end
);
9959 if (reg
!= -1u && frame_need_space (fc
, reg
) >= 0)
9961 /* Don't leave any reg as DW_CFA_unreferenced so
9962 that frame_display_row prints name of regs in
9963 header, and all referenced regs in each line. */
9964 if (reg
>= cie
->ncols
9965 || cie
->col_type
[reg
] == DW_CFA_unreferenced
)
9966 fc
->col_type
[reg
] = DW_CFA_undefined
;
9968 fc
->col_type
[reg
] = cie
->col_type
[reg
];
9976 /* Now we know what registers are used, make a second pass over
9977 the chunk, this time actually printing out the info. */
9979 while (start
< block_end
)
9982 /* Note: It is tempting to use an unsigned long for 'reg' but there
9983 are various functions, notably frame_space_needed() that assume that
9984 reg is an unsigned int. */
9988 const char *reg_prefix
= "";
9995 /* Make a note if something other than DW_CFA_nop happens. */
9996 if (op
!= DW_CFA_nop
)
9999 /* Warning: if you add any more cases to this switch, be
10000 sure to add them to the corresponding switch above. */
10003 case DW_CFA_advance_loc
:
10004 opa
*= fc
->code_factor
;
10005 if (do_debug_frames_interp
)
10006 frame_display_row (fc
, &need_col_headers
, &max_regs
);
10009 printf (" DW_CFA_advance_loc: %d to ", opa
);
10010 print_hex_ns (fc
->pc_begin
+ opa
, fc
->ptr_size
);
10013 fc
->pc_begin
+= opa
;
10016 case DW_CFA_offset
:
10017 READ_ULEB (ofs
, start
, block_end
);
10018 ofs
*= fc
->data_factor
;
10019 if (opa
>= fc
->ncols
)
10020 reg_prefix
= bad_reg
;
10021 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
10022 printf (" DW_CFA_offset: %s%s at cfa%+" PRId64
"\n",
10023 reg_prefix
, regname (opa
, 0), ofs
);
10024 if (*reg_prefix
== '\0')
10026 fc
->col_type
[opa
] = DW_CFA_offset
;
10027 fc
->col_offset
[opa
] = ofs
;
10031 case DW_CFA_restore
:
10032 if (opa
>= fc
->ncols
)
10033 reg_prefix
= bad_reg
;
10034 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
10035 printf (" DW_CFA_restore: %s%s\n",
10036 reg_prefix
, regname (opa
, 0));
10037 if (*reg_prefix
!= '\0')
10040 if (opa
>= cie
->ncols
10041 || cie
->col_type
[opa
] == DW_CFA_unreferenced
)
10043 fc
->col_type
[opa
] = DW_CFA_undefined
;
10044 fc
->col_offset
[opa
] = 0;
10048 fc
->col_type
[opa
] = cie
->col_type
[opa
];
10049 fc
->col_offset
[opa
] = cie
->col_offset
[opa
];
10053 case DW_CFA_set_loc
:
10054 ofs
= get_encoded_value (&start
, fc
->fde_encoding
, section
,
10056 if (do_debug_frames_interp
)
10057 frame_display_row (fc
, &need_col_headers
, &max_regs
);
10060 printf (" DW_CFA_set_loc: ");
10061 print_hex_ns (ofs
, fc
->ptr_size
);
10064 fc
->pc_begin
= ofs
;
10067 case DW_CFA_advance_loc1
:
10068 SAFE_BYTE_GET_AND_INC (ofs
, start
, 1, block_end
);
10069 ofs
*= fc
->code_factor
;
10070 if (do_debug_frames_interp
)
10071 frame_display_row (fc
, &need_col_headers
, &max_regs
);
10074 printf (" DW_CFA_advance_loc1: %" PRId64
" to ", ofs
);
10075 print_hex_ns (fc
->pc_begin
+ ofs
, fc
->ptr_size
);
10078 fc
->pc_begin
+= ofs
;
10081 case DW_CFA_advance_loc2
:
10082 SAFE_BYTE_GET_AND_INC (ofs
, start
, 2, block_end
);
10083 ofs
*= fc
->code_factor
;
10084 if (do_debug_frames_interp
)
10085 frame_display_row (fc
, &need_col_headers
, &max_regs
);
10088 printf (" DW_CFA_advance_loc2: %" PRId64
" to ", ofs
);
10089 print_hex_ns (fc
->pc_begin
+ ofs
, fc
->ptr_size
);
10092 fc
->pc_begin
+= ofs
;
10095 case DW_CFA_advance_loc4
:
10096 SAFE_BYTE_GET_AND_INC (ofs
, start
, 4, block_end
);
10097 ofs
*= fc
->code_factor
;
10098 if (do_debug_frames_interp
)
10099 frame_display_row (fc
, &need_col_headers
, &max_regs
);
10102 printf (" DW_CFA_advance_loc4: %" PRId64
" to ", ofs
);
10103 print_hex_ns (fc
->pc_begin
+ ofs
, fc
->ptr_size
);
10106 fc
->pc_begin
+= ofs
;
10109 case DW_CFA_offset_extended
:
10110 READ_ULEB (reg
, start
, block_end
);
10111 READ_ULEB (ofs
, start
, block_end
);
10112 ofs
*= fc
->data_factor
;
10113 if (reg
>= fc
->ncols
)
10114 reg_prefix
= bad_reg
;
10115 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
10116 printf (" DW_CFA_offset_extended: %s%s at cfa%+" PRId64
"\n",
10117 reg_prefix
, regname (reg
, 0), ofs
);
10118 if (*reg_prefix
== '\0')
10120 fc
->col_type
[reg
] = DW_CFA_offset
;
10121 fc
->col_offset
[reg
] = ofs
;
10125 case DW_CFA_val_offset
:
10126 READ_ULEB (reg
, start
, block_end
);
10127 READ_ULEB (ofs
, start
, block_end
);
10128 ofs
*= fc
->data_factor
;
10129 if (reg
>= fc
->ncols
)
10130 reg_prefix
= bad_reg
;
10131 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
10132 printf (" DW_CFA_val_offset: %s%s is cfa%+" PRId64
"\n",
10133 reg_prefix
, regname (reg
, 0), ofs
);
10134 if (*reg_prefix
== '\0')
10136 fc
->col_type
[reg
] = DW_CFA_val_offset
;
10137 fc
->col_offset
[reg
] = ofs
;
10141 case DW_CFA_restore_extended
:
10142 READ_ULEB (reg
, start
, block_end
);
10143 if (reg
>= fc
->ncols
)
10144 reg_prefix
= bad_reg
;
10145 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
10146 printf (" DW_CFA_restore_extended: %s%s\n",
10147 reg_prefix
, regname (reg
, 0));
10148 if (*reg_prefix
!= '\0')
10151 if (reg
>= cie
->ncols
10152 || cie
->col_type
[reg
] == DW_CFA_unreferenced
)
10154 fc
->col_type
[reg
] = DW_CFA_undefined
;
10155 fc
->col_offset
[reg
] = 0;
10159 fc
->col_type
[reg
] = cie
->col_type
[reg
];
10160 fc
->col_offset
[reg
] = cie
->col_offset
[reg
];
10164 case DW_CFA_undefined
:
10165 READ_ULEB (reg
, start
, block_end
);
10166 if (reg
>= fc
->ncols
)
10167 reg_prefix
= bad_reg
;
10168 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
10169 printf (" DW_CFA_undefined: %s%s\n",
10170 reg_prefix
, regname (reg
, 0));
10171 if (*reg_prefix
== '\0')
10173 fc
->col_type
[reg
] = DW_CFA_undefined
;
10174 fc
->col_offset
[reg
] = 0;
10178 case DW_CFA_same_value
:
10179 READ_ULEB (reg
, start
, block_end
);
10180 if (reg
>= fc
->ncols
)
10181 reg_prefix
= bad_reg
;
10182 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
10183 printf (" DW_CFA_same_value: %s%s\n",
10184 reg_prefix
, regname (reg
, 0));
10185 if (*reg_prefix
== '\0')
10187 fc
->col_type
[reg
] = DW_CFA_same_value
;
10188 fc
->col_offset
[reg
] = 0;
10192 case DW_CFA_register
:
10193 READ_ULEB (reg
, start
, block_end
);
10194 READ_ULEB (ofs
, start
, block_end
);
10195 if (reg
>= fc
->ncols
)
10196 reg_prefix
= bad_reg
;
10197 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
10199 printf (" DW_CFA_register: %s%s in ",
10200 reg_prefix
, regname (reg
, 0));
10201 puts (regname (ofs
, 0));
10203 if (*reg_prefix
== '\0')
10205 fc
->col_type
[reg
] = DW_CFA_register
;
10206 fc
->col_offset
[reg
] = ofs
;
10210 case DW_CFA_remember_state
:
10211 if (! do_debug_frames_interp
)
10212 printf (" DW_CFA_remember_state\n");
10213 rs
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
10214 rs
->cfa_offset
= fc
->cfa_offset
;
10215 rs
->cfa_reg
= fc
->cfa_reg
;
10217 rs
->cfa_exp
= fc
->cfa_exp
;
10218 rs
->ncols
= fc
->ncols
;
10219 rs
->col_type
= xcmalloc (rs
->ncols
, sizeof (*rs
->col_type
));
10220 rs
->col_offset
= xcmalloc (rs
->ncols
, sizeof (*rs
->col_offset
));
10221 memcpy (rs
->col_type
, fc
->col_type
,
10222 rs
->ncols
* sizeof (*fc
->col_type
));
10223 memcpy (rs
->col_offset
, fc
->col_offset
,
10224 rs
->ncols
* sizeof (*fc
->col_offset
));
10225 rs
->next
= remembered_state
;
10226 remembered_state
= rs
;
10229 case DW_CFA_restore_state
:
10230 if (! do_debug_frames_interp
)
10231 printf (" DW_CFA_restore_state\n");
10232 rs
= remembered_state
;
10235 remembered_state
= rs
->next
;
10236 fc
->cfa_offset
= rs
->cfa_offset
;
10237 fc
->cfa_reg
= rs
->cfa_reg
;
10239 fc
->cfa_exp
= rs
->cfa_exp
;
10240 if (frame_need_space (fc
, rs
->ncols
- 1) < 0)
10242 warn (_("Invalid column number in saved frame state\n"));
10247 memcpy (fc
->col_type
, rs
->col_type
,
10248 rs
->ncols
* sizeof (*rs
->col_type
));
10249 memcpy (fc
->col_offset
, rs
->col_offset
,
10250 rs
->ncols
* sizeof (*rs
->col_offset
));
10252 free (rs
->col_type
);
10253 free (rs
->col_offset
);
10256 else if (do_debug_frames_interp
)
10257 printf ("Mismatched DW_CFA_restore_state\n");
10260 case DW_CFA_def_cfa
:
10261 READ_ULEB (fc
->cfa_reg
, start
, block_end
);
10262 READ_ULEB (fc
->cfa_offset
, start
, block_end
);
10264 if (! do_debug_frames_interp
)
10265 printf (" DW_CFA_def_cfa: %s ofs %d\n",
10266 regname (fc
->cfa_reg
, 0), (int) fc
->cfa_offset
);
10269 case DW_CFA_def_cfa_register
:
10270 READ_ULEB (fc
->cfa_reg
, start
, block_end
);
10272 if (! do_debug_frames_interp
)
10273 printf (" DW_CFA_def_cfa_register: %s\n",
10274 regname (fc
->cfa_reg
, 0));
10277 case DW_CFA_def_cfa_offset
:
10278 READ_ULEB (fc
->cfa_offset
, start
, block_end
);
10279 if (! do_debug_frames_interp
)
10280 printf (" DW_CFA_def_cfa_offset: %d\n", (int) fc
->cfa_offset
);
10284 if (! do_debug_frames_interp
)
10285 printf (" DW_CFA_nop\n");
10288 case DW_CFA_def_cfa_expression
:
10289 READ_ULEB (ofs
, start
, block_end
);
10290 if (ofs
> (size_t) (block_end
- start
))
10292 printf (_(" %s: <corrupt len %" PRIu64
">\n"),
10293 "DW_CFA_def_cfa_expression", ofs
);
10296 if (! do_debug_frames_interp
)
10298 printf (" DW_CFA_def_cfa_expression (");
10299 decode_location_expression (start
, eh_addr_size
, 0, -1,
10307 case DW_CFA_expression
:
10308 READ_ULEB (reg
, start
, block_end
);
10309 READ_ULEB (ofs
, start
, block_end
);
10310 if (reg
>= fc
->ncols
)
10311 reg_prefix
= bad_reg
;
10312 /* PR 17512: file: 069-133014-0.006. */
10313 /* PR 17512: file: 98c02eb4. */
10314 if (ofs
> (size_t) (block_end
- start
))
10316 printf (_(" %s: <corrupt len %" PRIu64
">\n"),
10317 "DW_CFA_expression", ofs
);
10320 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
10322 printf (" DW_CFA_expression: %s%s (",
10323 reg_prefix
, regname (reg
, 0));
10324 decode_location_expression (start
, eh_addr_size
, 0, -1,
10328 if (*reg_prefix
== '\0')
10329 fc
->col_type
[reg
] = DW_CFA_expression
;
10333 case DW_CFA_val_expression
:
10334 READ_ULEB (reg
, start
, block_end
);
10335 READ_ULEB (ofs
, start
, block_end
);
10336 if (reg
>= fc
->ncols
)
10337 reg_prefix
= bad_reg
;
10338 if (ofs
> (size_t) (block_end
- start
))
10340 printf (" %s: <corrupt len %" PRIu64
">\n",
10341 "DW_CFA_val_expression", ofs
);
10344 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
10346 printf (" DW_CFA_val_expression: %s%s (",
10347 reg_prefix
, regname (reg
, 0));
10348 decode_location_expression (start
, eh_addr_size
, 0, -1,
10352 if (*reg_prefix
== '\0')
10353 fc
->col_type
[reg
] = DW_CFA_val_expression
;
10357 case DW_CFA_offset_extended_sf
:
10358 READ_ULEB (reg
, start
, block_end
);
10359 READ_SLEB (sofs
, start
, block_end
);
10360 /* data_factor multiplicaton done here as unsigned to
10361 avoid integer overflow warnings from asan on fuzzed
10364 ofs
*= fc
->data_factor
;
10365 if (reg
>= fc
->ncols
)
10366 reg_prefix
= bad_reg
;
10367 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
10368 printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+" PRId64
"\n",
10369 reg_prefix
, regname (reg
, 0), ofs
);
10370 if (*reg_prefix
== '\0')
10372 fc
->col_type
[reg
] = DW_CFA_offset
;
10373 fc
->col_offset
[reg
] = ofs
;
10377 case DW_CFA_val_offset_sf
:
10378 READ_ULEB (reg
, start
, block_end
);
10379 READ_SLEB (sofs
, start
, block_end
);
10381 ofs
*= fc
->data_factor
;
10382 if (reg
>= fc
->ncols
)
10383 reg_prefix
= bad_reg
;
10384 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
10385 printf (" DW_CFA_val_offset_sf: %s%s is cfa%+" PRId64
"\n",
10386 reg_prefix
, regname (reg
, 0), ofs
);
10387 if (*reg_prefix
== '\0')
10389 fc
->col_type
[reg
] = DW_CFA_val_offset
;
10390 fc
->col_offset
[reg
] = ofs
;
10394 case DW_CFA_def_cfa_sf
:
10395 READ_ULEB (fc
->cfa_reg
, start
, block_end
);
10396 READ_SLEB (sofs
, start
, block_end
);
10398 ofs
*= fc
->data_factor
;
10399 fc
->cfa_offset
= ofs
;
10401 if (! do_debug_frames_interp
)
10402 printf (" DW_CFA_def_cfa_sf: %s ofs %" PRId64
"\n",
10403 regname (fc
->cfa_reg
, 0), ofs
);
10406 case DW_CFA_def_cfa_offset_sf
:
10407 READ_SLEB (sofs
, start
, block_end
);
10409 ofs
*= fc
->data_factor
;
10410 fc
->cfa_offset
= ofs
;
10411 if (! do_debug_frames_interp
)
10412 printf (" DW_CFA_def_cfa_offset_sf: %" PRId64
"\n", ofs
);
10415 case DW_CFA_MIPS_advance_loc8
:
10416 SAFE_BYTE_GET_AND_INC (ofs
, start
, 8, block_end
);
10417 ofs
*= fc
->code_factor
;
10418 if (do_debug_frames_interp
)
10419 frame_display_row (fc
, &need_col_headers
, &max_regs
);
10422 printf (" DW_CFA_MIPS_advance_loc8: %" PRId64
" to ", ofs
);
10423 print_hex_ns (fc
->pc_begin
+ ofs
, fc
->ptr_size
);
10426 fc
->pc_begin
+= ofs
;
10429 case DW_CFA_AARCH64_negate_ra_state_with_pc
:
10430 if (! do_debug_frames_interp
)
10431 printf (" DW_CFA_AARCH64_negate_ra_state_with_pc\n");
10434 case DW_CFA_GNU_window_save
:
10435 if (! do_debug_frames_interp
)
10436 printf (" %s\n", DW_CFA_GNU_window_save_name
[is_aarch64
]);
10439 case DW_CFA_GNU_args_size
:
10440 READ_ULEB (ofs
, start
, block_end
);
10441 if (! do_debug_frames_interp
)
10442 printf (" DW_CFA_GNU_args_size: %" PRIu64
"\n", ofs
);
10445 case DW_CFA_GNU_negative_offset_extended
:
10446 READ_ULEB (reg
, start
, block_end
);
10447 READ_SLEB (sofs
, start
, block_end
);
10449 ofs
= -ofs
* fc
->data_factor
;
10450 if (reg
>= fc
->ncols
)
10451 reg_prefix
= bad_reg
;
10452 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
10453 printf (" DW_CFA_GNU_negative_offset_extended: %s%s "
10454 "at cfa%+" PRId64
"\n",
10455 reg_prefix
, regname (reg
, 0), ofs
);
10456 if (*reg_prefix
== '\0')
10458 fc
->col_type
[reg
] = DW_CFA_offset
;
10459 fc
->col_offset
[reg
] = ofs
;
10464 if (op
>= DW_CFA_lo_user
&& op
<= DW_CFA_hi_user
)
10465 printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op
);
10467 warn (_("Unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op
);
10472 /* Interpret the CFA - as long as it is not completely full of NOPs. */
10473 if (do_debug_frames_interp
&& ! all_nops
)
10474 frame_display_row (fc
, &need_col_headers
, &max_regs
);
10476 if (fde_fc
.col_type
!= NULL
)
10478 free (fde_fc
.col_type
);
10479 fde_fc
.col_type
= NULL
;
10481 if (fde_fc
.col_offset
!= NULL
)
10483 free (fde_fc
.col_offset
);
10484 fde_fc
.col_offset
= NULL
;
10488 eh_addr_size
= saved_eh_addr_size
;
10493 while (remembered_state
!= NULL
)
10495 rs
= remembered_state
;
10496 remembered_state
= rs
->next
;
10497 free (rs
->col_type
);
10498 free (rs
->col_offset
);
10499 rs
->next
= NULL
; /* Paranoia. */
10503 while (chunks
!= NULL
)
10507 free (rs
->col_type
);
10508 free (rs
->col_offset
);
10509 rs
->next
= NULL
; /* Paranoia. */
10513 while (forward_refs
!= NULL
)
10516 forward_refs
= rs
->next
;
10517 free (rs
->col_type
);
10518 free (rs
->col_offset
);
10519 rs
->next
= NULL
; /* Paranoia. */
10529 display_debug_names (struct dwarf_section
*section
, void *file
)
10531 unsigned char *hdrptr
= section
->start
;
10532 uint64_t unit_length
;
10533 unsigned char *unit_start
;
10534 const unsigned char *const section_end
= section
->start
+ section
->size
;
10535 unsigned char *unit_end
;
10537 introduce (section
, false);
10539 load_debug_section_with_follow (str
, file
);
10541 for (; hdrptr
< section_end
; hdrptr
= unit_end
)
10543 unsigned int offset_size
;
10544 uint16_t dwarf_version
, padding
;
10545 uint32_t comp_unit_count
, local_type_unit_count
, foreign_type_unit_count
;
10546 uint64_t bucket_count
, name_count
, abbrev_table_size
;
10547 uint32_t augmentation_string_size
;
10549 bool augmentation_printable
;
10550 const char *augmentation_string
;
10553 unit_start
= hdrptr
;
10555 /* Get and check the length of the block. */
10556 SAFE_BYTE_GET_AND_INC (unit_length
, hdrptr
, 4, section_end
);
10558 if (unit_length
== 0xffffffff)
10560 /* This section is 64-bit DWARF. */
10561 SAFE_BYTE_GET_AND_INC (unit_length
, hdrptr
, 8, section_end
);
10567 if (unit_length
> (size_t) (section_end
- hdrptr
)
10568 || unit_length
< 2 + 2 + 4 * 7)
10571 warn (_("Debug info is corrupted, %s header at %#tx"
10572 " has length %#" PRIx64
"\n"),
10573 section
->name
, unit_start
- section
->start
, unit_length
);
10576 unit_end
= hdrptr
+ unit_length
;
10578 /* Get and check the version number. */
10579 SAFE_BYTE_GET_AND_INC (dwarf_version
, hdrptr
, 2, unit_end
);
10580 printf (_("Version %d\n"), (int) dwarf_version
);
10582 /* Prior versions did not exist, and future versions may not be
10583 backwards compatible. */
10584 if (dwarf_version
!= 5)
10586 warn (_("Only DWARF version 5 .debug_names "
10587 "is currently supported.\n"));
10591 SAFE_BYTE_GET_AND_INC (padding
, hdrptr
, 2, unit_end
);
10593 warn (_("Padding field of .debug_names must be 0 (found 0x%x)\n"),
10596 SAFE_BYTE_GET_AND_INC (comp_unit_count
, hdrptr
, 4, unit_end
);
10597 if (comp_unit_count
== 0)
10598 warn (_("Compilation unit count must be >= 1 in .debug_names\n"));
10600 SAFE_BYTE_GET_AND_INC (local_type_unit_count
, hdrptr
, 4, unit_end
);
10601 SAFE_BYTE_GET_AND_INC (foreign_type_unit_count
, hdrptr
, 4, unit_end
);
10602 SAFE_BYTE_GET_AND_INC (bucket_count
, hdrptr
, 4, unit_end
);
10603 SAFE_BYTE_GET_AND_INC (name_count
, hdrptr
, 4, unit_end
);
10604 SAFE_BYTE_GET_AND_INC (abbrev_table_size
, hdrptr
, 4, unit_end
);
10606 SAFE_BYTE_GET_AND_INC (augmentation_string_size
, hdrptr
, 4, unit_end
);
10607 if (augmentation_string_size
% 4 != 0)
10609 warn (_("Augmentation string length %u must be rounded up "
10610 "to a multiple of 4 in .debug_names.\n"),
10611 augmentation_string_size
);
10612 augmentation_string_size
+= (-augmentation_string_size
) & 3;
10614 if (augmentation_string_size
> (size_t) (unit_end
- hdrptr
))
10617 printf (_("Augmentation string:"));
10619 augmentation_printable
= true;
10620 augmentation_string
= (const char *) hdrptr
;
10622 for (i
= 0; i
< augmentation_string_size
; i
++)
10626 SAFE_BYTE_GET_AND_INC (uc
, hdrptr
, 1, unit_end
);
10627 printf (" %02x", uc
);
10629 if (uc
!= 0 && !ISPRINT (uc
))
10630 augmentation_printable
= false;
10633 if (augmentation_printable
)
10637 i
< augmentation_string_size
&& augmentation_string
[i
];
10639 putchar (augmentation_string
[i
]);
10644 printf (_("CU table:\n"));
10645 if (_mul_overflow (comp_unit_count
, offset_size
, &total
)
10646 || total
> (size_t) (unit_end
- hdrptr
))
10648 for (i
= 0; i
< comp_unit_count
; i
++)
10650 uint64_t cu_offset
;
10652 SAFE_BYTE_GET_AND_INC (cu_offset
, hdrptr
, offset_size
, unit_end
);
10653 printf ("[%3u] %#" PRIx64
"\n", i
, cu_offset
);
10657 printf (_("TU table:\n"));
10658 if (_mul_overflow (local_type_unit_count
, offset_size
, &total
)
10659 || total
> (size_t) (unit_end
- hdrptr
))
10661 for (i
= 0; i
< local_type_unit_count
; i
++)
10663 uint64_t tu_offset
;
10665 SAFE_BYTE_GET_AND_INC (tu_offset
, hdrptr
, offset_size
, unit_end
);
10666 printf ("[%3u] %#" PRIx64
"\n", i
, tu_offset
);
10670 printf (_("Foreign TU table:\n"));
10671 if (_mul_overflow (foreign_type_unit_count
, 8, &total
)
10672 || total
> (size_t) (unit_end
- hdrptr
))
10674 for (i
= 0; i
< foreign_type_unit_count
; i
++)
10676 uint64_t signature
;
10678 SAFE_BYTE_GET_AND_INC (signature
, hdrptr
, 8, unit_end
);
10679 printf (_("[%3u] "), i
);
10680 print_hex_ns (signature
, 8);
10685 uint64_t xtra
= (bucket_count
* sizeof (uint32_t)
10686 + name_count
* (sizeof (uint32_t) + 2 * offset_size
)
10687 + abbrev_table_size
);
10688 if (xtra
> (size_t) (unit_end
- hdrptr
))
10690 warn (_("Entry pool offset (%#" PRIx64
") exceeds unit size %#tx "
10691 "for unit %#tx in the debug_names\n"),
10692 xtra
, unit_end
- unit_start
, unit_start
- section
->start
);
10695 const uint32_t *const hash_table_buckets
= (uint32_t *) hdrptr
;
10696 hdrptr
+= bucket_count
* sizeof (uint32_t);
10697 const uint32_t *const hash_table_hashes
= (uint32_t *) hdrptr
;
10698 if (bucket_count
!= 0)
10699 hdrptr
+= name_count
* sizeof (uint32_t);
10700 unsigned char *const name_table_string_offsets
= hdrptr
;
10701 hdrptr
+= name_count
* offset_size
;
10702 unsigned char *const name_table_entry_offsets
= hdrptr
;
10703 hdrptr
+= name_count
* offset_size
;
10704 unsigned char *const abbrev_table
= hdrptr
;
10705 hdrptr
+= abbrev_table_size
;
10706 const unsigned char *const abbrev_table_end
= hdrptr
;
10707 unsigned char *const entry_pool
= hdrptr
;
10709 size_t buckets_filled
= 0;
10711 for (bucketi
= 0; bucketi
< bucket_count
; bucketi
++)
10713 const uint32_t bucket
= hash_table_buckets
[bucketi
];
10718 printf (ngettext ("Used %zu of %lu bucket.\n",
10719 "Used %zu of %lu buckets.\n",
10720 (unsigned long) bucket_count
),
10721 buckets_filled
, (unsigned long) bucket_count
);
10723 if (bucket_count
!= 0)
10725 uint32_t hash_prev
= 0;
10726 size_t hash_clash_count
= 0;
10727 size_t longest_clash
= 0;
10728 size_t this_length
= 0;
10730 for (hashi
= 0; hashi
< name_count
; hashi
++)
10732 const uint32_t hash_this
= hash_table_hashes
[hashi
];
10736 if (hash_prev
% bucket_count
== hash_this
% bucket_count
)
10738 ++hash_clash_count
;
10740 longest_clash
= MAX (longest_clash
, this_length
);
10745 hash_prev
= hash_this
;
10747 printf (_("Out of %" PRIu64
" items there are %zu bucket clashes"
10748 " (longest of %zu entries).\n"),
10749 name_count
, hash_clash_count
, longest_clash
);
10751 if (name_count
!= buckets_filled
+ hash_clash_count
)
10752 warn (_("The name_count (%" PRIu64
")"
10753 " is not the same as the used bucket_count"
10754 " (%zu) + the hash clash count (%zu)\n"),
10755 name_count
, buckets_filled
, hash_clash_count
);
10758 struct abbrev_lookup_entry
10760 uint64_t abbrev_tag
;
10761 unsigned char *abbrev_lookup_ptr
;
10763 struct abbrev_lookup_entry
*abbrev_lookup
= NULL
;
10764 size_t abbrev_lookup_used
= 0;
10765 size_t abbrev_lookup_allocated
= 0;
10767 unsigned char *abbrevptr
= abbrev_table
;
10770 uint64_t abbrev_tag
;
10772 READ_ULEB (abbrev_tag
, abbrevptr
, abbrev_table_end
);
10773 if (abbrev_tag
== 0)
10775 if (abbrev_lookup_used
== abbrev_lookup_allocated
)
10777 abbrev_lookup_allocated
= MAX (0x100,
10778 abbrev_lookup_allocated
* 2);
10779 abbrev_lookup
= xrealloc (abbrev_lookup
,
10780 (abbrev_lookup_allocated
10781 * sizeof (*abbrev_lookup
)));
10783 assert (abbrev_lookup_used
< abbrev_lookup_allocated
);
10784 struct abbrev_lookup_entry
*entry
;
10785 for (entry
= abbrev_lookup
;
10786 entry
< abbrev_lookup
+ abbrev_lookup_used
;
10788 if (entry
->abbrev_tag
== abbrev_tag
)
10790 warn (_("Duplicate abbreviation tag %" PRIu64
10791 " in unit %#tx in the debug_names section\n"),
10792 abbrev_tag
, unit_start
- section
->start
);
10795 entry
= &abbrev_lookup
[abbrev_lookup_used
++];
10796 entry
->abbrev_tag
= abbrev_tag
;
10797 entry
->abbrev_lookup_ptr
= abbrevptr
;
10799 /* Skip DWARF tag. */
10800 SKIP_ULEB (abbrevptr
, abbrev_table_end
);
10803 uint64_t xindex
, form
;
10805 READ_ULEB (xindex
, abbrevptr
, abbrev_table_end
);
10806 READ_ULEB (form
, abbrevptr
, abbrev_table_end
);
10807 if (xindex
== 0 && form
== 0)
10812 printf (_("\nSymbol table:\n"));
10814 for (namei
= 0; namei
< name_count
; ++namei
)
10816 uint64_t string_offset
, entry_offset
;
10818 /* We need to scan first whether there is a single or multiple
10819 entries. TAGNO is -2 for the first entry, it is -1 for the
10820 initial tag read of the second entry, then it becomes 0 for the
10821 first entry for real printing etc. */
10823 /* Initialize it due to a false compiler warning. */
10824 uint64_t second_abbrev_tag
= -1;
10825 unsigned char *entryptr
;
10827 p
= name_table_string_offsets
+ namei
* offset_size
;
10828 SAFE_BYTE_GET (string_offset
, p
, offset_size
, unit_end
);
10830 p
= name_table_entry_offsets
+ namei
* offset_size
;
10831 SAFE_BYTE_GET (entry_offset
, p
, offset_size
, unit_end
);
10833 /* The name table is indexed starting at 1 according to
10834 DWARF, so be sure to use the DWARF numbering here. */
10835 printf ("[%3u] ", namei
+ 1);
10836 if (bucket_count
!= 0)
10837 printf ("#%08x ", hash_table_hashes
[namei
]);
10839 printf ("%s:", fetch_indirect_string (string_offset
));
10841 entryptr
= entry_pool
+ entry_offset
;
10842 /* PR 31456: Check for invalid entry offset. */
10843 if (entryptr
< entry_pool
|| entryptr
>= unit_end
)
10845 warn (_("Invalid entry offset value: %" PRIx64
"\n"), entry_offset
);
10851 uint64_t abbrev_tag
;
10852 uint64_t dwarf_tag
;
10853 const struct abbrev_lookup_entry
*entry
;
10854 uint64_t this_entry
= entryptr
- entry_pool
;
10856 READ_ULEB (abbrev_tag
, entryptr
, unit_end
);
10859 second_abbrev_tag
= abbrev_tag
;
10861 entryptr
= entry_pool
+ entry_offset
;
10864 if (abbrev_tag
== 0)
10867 printf ("%s<%#" PRIx64
"><%" PRIu64
">",
10868 (tagno
== 0 && second_abbrev_tag
== 0 ? " " : "\n\t"),
10869 this_entry
, abbrev_tag
);
10871 for (entry
= abbrev_lookup
;
10872 entry
< abbrev_lookup
+ abbrev_lookup_used
;
10874 if (entry
->abbrev_tag
== abbrev_tag
)
10876 if (entry
>= abbrev_lookup
+ abbrev_lookup_used
)
10878 warn (_("Undefined abbreviation tag %" PRId64
10879 " in unit %#tx in the debug_names section\n"),
10881 unit_start
- section
->start
);
10884 abbrevptr
= entry
->abbrev_lookup_ptr
;
10885 READ_ULEB (dwarf_tag
, abbrevptr
, abbrev_table_end
);
10887 printf (" %s", get_TAG_name (dwarf_tag
));
10890 uint64_t xindex
, form
;
10892 READ_ULEB (xindex
, abbrevptr
, abbrev_table_end
);
10893 READ_ULEB (form
, abbrevptr
, abbrev_table_end
);
10894 if (xindex
== 0 && form
== 0)
10898 printf (" %s", get_IDX_name (xindex
));
10899 entryptr
= read_and_display_attr_value (0, form
, 0,
10900 unit_start
, entryptr
, unit_end
,
10902 dwarf_version
, NULL
,
10903 (tagno
< 0), section
,
10909 printf (_(" <no entries>"));
10913 free (abbrev_lookup
);
10920 display_debug_links (struct dwarf_section
* section
,
10921 void * file ATTRIBUTE_UNUSED
)
10923 const unsigned char * filename
;
10924 unsigned int filelen
;
10926 introduce (section
, false);
10928 /* The .gnu_debuglink section is formatted as:
10929 (c-string) Filename.
10930 (padding) If needed to reach a 4 byte boundary.
10931 (uint32_t) CRC32 value.
10933 The .gnu_debugaltlink section is formatted as:
10934 (c-string) Filename.
10935 (binary) Build-ID. */
10937 filename
= section
->start
;
10938 filelen
= strnlen ((const char *) filename
, section
->size
);
10939 if (filelen
== section
->size
)
10941 warn (_("The debuglink filename is corrupt/missing\n"));
10945 printf (_(" Separate debug info file: %s\n"), filename
);
10947 if (startswith (section
->name
, ".gnu_debuglink"))
10949 unsigned int crc32
;
10950 unsigned int crc_offset
;
10952 crc_offset
= filelen
+ 1;
10953 crc_offset
= (crc_offset
+ 3) & ~3;
10954 if (crc_offset
+ 4 > section
->size
)
10956 warn (_("CRC offset missing/truncated\n"));
10960 crc32
= byte_get (filename
+ crc_offset
, 4);
10962 printf (_(" CRC value: %#x\n"), crc32
);
10964 if (crc_offset
+ 4 < section
->size
)
10966 warn (_("There are %#" PRIx64
10967 " extraneous bytes at the end of the section\n"),
10968 section
->size
- (crc_offset
+ 4));
10972 else /* startswith (section->name, ".gnu_debugaltlink") */
10974 const unsigned char *build_id
= section
->start
+ filelen
+ 1;
10975 size_t build_id_len
= section
->size
- (filelen
+ 1);
10978 /* FIXME: Should we support smaller build-id notes ? */
10979 if (build_id_len
< 0x14)
10981 warn (_("Build-ID is too short (%#zx bytes)\n"), build_id_len
);
10985 printed
= printf (_(" Build-ID (%#zx bytes):"), build_id_len
);
10986 display_data (printed
, build_id
, build_id_len
);
10995 display_gdb_index (struct dwarf_section
*section
,
10996 void *file ATTRIBUTE_UNUSED
)
10998 unsigned char *start
= section
->start
;
11000 uint32_t cu_list_offset
, tu_list_offset
;
11001 uint32_t address_table_offset
, symbol_table_offset
, constant_pool_offset
,
11002 shortcut_table_offset
;
11003 unsigned int cu_list_elements
, tu_list_elements
;
11004 unsigned int address_table_elements
, symbol_table_slots
;
11005 unsigned char *cu_list
, *tu_list
;
11006 unsigned char *address_table
, *symbol_table
, *shortcut_table
, *constant_pool
;
11009 /* The documentation for the format of this file is in gdb/dwarf2read.c. */
11011 introduce (section
, false);
11013 version
= section
->size
< 4 ? 0 : byte_get_little_endian (start
, 4);
11014 size_t header_size
= (version
< 9 ? 6 : 7) * sizeof (uint32_t);
11015 if (section
->size
< header_size
)
11017 warn (_("Truncated header in the %s section.\n"), section
->name
);
11021 printf (_("Version %lu\n"), (unsigned long) version
);
11023 /* Prior versions are obsolete, and future versions may not be
11024 backwards compatible. */
11025 if (version
< 3 || version
> 9)
11027 warn (_("Unsupported version %lu.\n"), (unsigned long) version
);
11031 warn (_("The address table data in version 3 may be wrong.\n"));
11033 warn (_("Version 4 does not support case insensitive lookups.\n"));
11035 warn (_("Version 5 does not include inlined functions.\n"));
11037 warn (_("Version 6 does not include symbol attributes.\n"));
11038 /* Version 7 indices generated by Gold have bad type unit references,
11039 PR binutils/15021. But we don't know if the index was generated by
11040 Gold or not, so to avoid worrying users with gdb-generated indices
11041 we say nothing for version 7 here. */
11043 cu_list_offset
= byte_get_little_endian (start
+ 4, 4);
11044 tu_list_offset
= byte_get_little_endian (start
+ 8, 4);
11045 address_table_offset
= byte_get_little_endian (start
+ 12, 4);
11046 symbol_table_offset
= byte_get_little_endian (start
+ 16, 4);
11047 shortcut_table_offset
= byte_get_little_endian (start
+ 20, 4);
11049 constant_pool_offset
= shortcut_table_offset
;
11051 constant_pool_offset
= byte_get_little_endian (start
+ 24, 4);
11053 if (cu_list_offset
> section
->size
11054 || tu_list_offset
> section
->size
11055 || address_table_offset
> section
->size
11056 || symbol_table_offset
> section
->size
11057 || shortcut_table_offset
> section
->size
11058 || constant_pool_offset
> section
->size
11059 || tu_list_offset
< cu_list_offset
11060 || address_table_offset
< tu_list_offset
11061 || symbol_table_offset
< address_table_offset
11062 || shortcut_table_offset
< symbol_table_offset
11063 || constant_pool_offset
< shortcut_table_offset
)
11065 warn (_("Corrupt header in the %s section.\n"), section
->name
);
11069 cu_list_elements
= (tu_list_offset
- cu_list_offset
) / 16;
11070 tu_list_elements
= (address_table_offset
- tu_list_offset
) / 24;
11071 address_table_elements
= (symbol_table_offset
- address_table_offset
) / 20;
11072 symbol_table_slots
= (shortcut_table_offset
- symbol_table_offset
) / 8;
11074 cu_list
= start
+ cu_list_offset
;
11075 tu_list
= start
+ tu_list_offset
;
11076 address_table
= start
+ address_table_offset
;
11077 symbol_table
= start
+ symbol_table_offset
;
11078 shortcut_table
= start
+ shortcut_table_offset
;
11079 constant_pool
= start
+ constant_pool_offset
;
11081 printf (_("\nCU table:\n"));
11082 for (i
= 0; i
< cu_list_elements
; i
++)
11084 uint64_t cu_offset
= byte_get_little_endian (cu_list
+ i
* 16, 8);
11085 uint64_t cu_length
= byte_get_little_endian (cu_list
+ i
* 16 + 8, 8);
11087 printf ("[%3u] %#" PRIx64
" - %#" PRIx64
"\n",
11088 i
, cu_offset
, cu_offset
+ cu_length
- 1);
11091 printf (_("\nTU table:\n"));
11092 for (i
= 0; i
< tu_list_elements
; i
++)
11094 uint64_t tu_offset
= byte_get_little_endian (tu_list
+ i
* 24, 8);
11095 uint64_t type_offset
= byte_get_little_endian (tu_list
+ i
* 24 + 8, 8);
11096 uint64_t signature
= byte_get_little_endian (tu_list
+ i
* 24 + 16, 8);
11098 printf ("[%3u] %#" PRIx64
" %#" PRIx64
" ",
11099 i
, tu_offset
, type_offset
);
11100 print_hex_ns (signature
, 8);
11104 printf (_("\nAddress table:\n"));
11105 for (i
= 0; i
< address_table_elements
; i
++)
11107 uint64_t low
= byte_get_little_endian (address_table
+ i
* 20, 8);
11108 uint64_t high
= byte_get_little_endian (address_table
+ i
* 20 + 8, 8);
11109 uint32_t cu_index
= byte_get_little_endian (address_table
+ i
* 20 + 16, 4);
11111 print_hex (low
, 8);
11112 print_hex (high
, 8);
11113 printf ("%" PRIu32
"\n", cu_index
);
11116 printf (_("\nSymbol table:\n"));
11117 for (i
= 0; i
< symbol_table_slots
; ++i
)
11119 uint32_t name_offset
= byte_get_little_endian (symbol_table
+ i
* 8, 4);
11120 uint32_t cu_vector_offset
= byte_get_little_endian (symbol_table
+ i
* 8 + 4, 4);
11121 uint32_t num_cus
, cu
;
11123 if (name_offset
!= 0
11124 || cu_vector_offset
!= 0)
11128 /* PR 17531: file: 5b7b07ad. */
11129 if (name_offset
>= section
->size
- constant_pool_offset
)
11131 printf (_("[%3u] <corrupt offset: %x>"), i
, name_offset
);
11132 warn (_("Corrupt name offset of 0x%x found for symbol table slot %d\n"),
11136 printf ("[%3u] %.*s:", i
,
11137 (int) (section
->size
- (constant_pool_offset
+ name_offset
)),
11138 constant_pool
+ name_offset
);
11140 if (section
->size
- constant_pool_offset
< 4
11141 || cu_vector_offset
> section
->size
- constant_pool_offset
- 4)
11143 printf (_("<invalid CU vector offset: %x>\n"), cu_vector_offset
);
11144 warn (_("Corrupt CU vector offset of 0x%x found for symbol table slot %d\n"),
11145 cu_vector_offset
, i
);
11149 num_cus
= byte_get_little_endian (constant_pool
+ cu_vector_offset
, 4);
11151 if ((uint64_t) num_cus
* 4 > section
->size
- (constant_pool_offset
11152 + cu_vector_offset
+ 4))
11154 printf ("<invalid number of CUs: %d>\n", num_cus
);
11155 warn (_("Invalid number of CUs (0x%x) for symbol table slot %d\n"),
11163 for (j
= 0; j
< num_cus
; ++j
)
11166 gdb_index_symbol_kind kind
;
11168 cu
= byte_get_little_endian (constant_pool
+ cu_vector_offset
+ 4 + j
* 4, 4);
11169 is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu
);
11170 kind
= GDB_INDEX_SYMBOL_KIND_VALUE (cu
);
11171 cu
= GDB_INDEX_CU_VALUE (cu
);
11172 /* Convert to TU number if it's for a type unit. */
11173 if (cu
>= cu_list_elements
)
11174 printf ("%cT%lu", num_cus
> 1 ? '\t' : ' ',
11175 (unsigned long) cu
- cu_list_elements
);
11177 printf ("%c%lu", num_cus
> 1 ? '\t' : ' ', (unsigned long) cu
);
11179 printf (" [%s, %s]",
11180 is_static
? _("static") : _("global"),
11181 get_gdb_index_symbol_kind_name (kind
));
11192 printf (_("\nShortcut table:\n"));
11194 if (shortcut_table_offset
+ 8 > constant_pool_offset
)
11196 warn (_("Corrupt shortcut table in the %s section.\n"), section
->name
);
11200 uint32_t lang
= byte_get_little_endian (shortcut_table
, 4);
11201 printf (_("Language of main: "));
11202 display_lang (lang
);
11205 printf (_("Name of main: "));
11207 printf (_("<unknown>\n"));
11210 uint32_t name_offset
= byte_get_little_endian (shortcut_table
+ 4, 4);
11211 if (name_offset
>= section
->size
- constant_pool_offset
)
11213 printf (_("<corrupt offset: %x>\n"), name_offset
);
11214 warn (_("Corrupt name offset of 0x%x found for name of main\n"),
11218 printf ("%s\n", constant_pool
+ name_offset
);
11225 /* Pre-allocate enough space for the CU/TU sets needed. */
11228 prealloc_cu_tu_list (unsigned int nshndx
)
11231 /* Always allocate at least one entry for the end-marker. */
11234 if (shndx_pool
== NULL
)
11236 shndx_pool_size
= nshndx
;
11237 shndx_pool_used
= 0;
11238 shndx_pool
= (unsigned int *) xcmalloc (shndx_pool_size
,
11239 sizeof (unsigned int));
11243 shndx_pool_size
= shndx_pool_used
+ nshndx
;
11244 shndx_pool
= (unsigned int *) xcrealloc (shndx_pool
, shndx_pool_size
,
11245 sizeof (unsigned int));
11250 add_shndx_to_cu_tu_entry (unsigned int shndx
)
11252 shndx_pool
[shndx_pool_used
++] = shndx
;
11256 end_cu_tu_entry (void)
11258 shndx_pool
[shndx_pool_used
++] = 0;
11261 /* Return the short name of a DWARF section given by a DW_SECT enumerator. */
11263 static const char *
11264 get_DW_SECT_short_name (unsigned int dw_sect
)
11266 static char buf
[16];
11272 case DW_SECT_TYPES
:
11274 case DW_SECT_ABBREV
:
11280 case DW_SECT_STR_OFFSETS
:
11282 case DW_SECT_MACINFO
:
11284 case DW_SECT_MACRO
:
11290 snprintf (buf
, sizeof (buf
), "%d", dw_sect
);
11294 /* Process a CU or TU index. If DO_DISPLAY is true, print the contents.
11295 These sections are extensions for Fission.
11296 See http://gcc.gnu.org/wiki/DebugFissionDWP. */
11299 process_cu_tu_index (struct dwarf_section
*section
, int do_display
)
11301 unsigned char *phdr
= section
->start
;
11302 unsigned char *limit
= phdr
+ section
->size
;
11303 unsigned char *phash
;
11304 unsigned char *pindex
;
11305 unsigned char *ppool
;
11306 unsigned int version
;
11307 unsigned int ncols
= 0;
11308 unsigned int nused
;
11309 unsigned int nslots
;
11312 uint64_t signature
;
11315 /* PR 17512: file: 002-168123-0.004. */
11318 warn (_("Section %s is empty\n"), section
->name
);
11321 /* PR 17512: file: 002-376-0.004. */
11322 if (section
->size
< 24)
11324 warn (_("Section %s is too small to contain a CU/TU header\n"),
11330 SAFE_BYTE_GET_AND_INC (version
, phash
, 4, limit
);
11332 SAFE_BYTE_GET_AND_INC (ncols
, phash
, 4, limit
);
11333 SAFE_BYTE_GET_AND_INC (nused
, phash
, 4, limit
);
11334 SAFE_BYTE_GET_AND_INC (nslots
, phash
, 4, limit
);
11336 pindex
= phash
+ (size_t) nslots
* 8;
11337 ppool
= pindex
+ (size_t) nslots
* 4;
11341 introduce (section
, false);
11343 printf (_(" Version: %u\n"), version
);
11345 printf (_(" Number of columns: %u\n"), ncols
);
11346 printf (_(" Number of used entries: %u\n"), nused
);
11347 printf (_(" Number of slots: %u\n\n"), nslots
);
11350 /* PR 17531: file: 45d69832. */
11351 if (_mul_overflow ((size_t) nslots
, 12, &total
)
11352 || total
> (size_t) (limit
- phash
))
11354 warn (ngettext ("Section %s is too small for %u slot\n",
11355 "Section %s is too small for %u slots\n",
11357 section
->name
, nslots
);
11363 unsigned char *shndx_list
;
11364 unsigned int shndx
;
11368 prealloc_cu_tu_list ((limit
- ppool
) / 4);
11369 for (shndx_list
= ppool
+ 4; shndx_list
<= limit
- 4; shndx_list
+= 4)
11371 shndx
= byte_get (shndx_list
, 4);
11372 add_shndx_to_cu_tu_entry (shndx
);
11374 end_cu_tu_entry ();
11377 for (i
= 0; i
< nslots
; i
++)
11379 SAFE_BYTE_GET (signature
, phash
, 8, limit
);
11380 if (signature
!= 0)
11382 SAFE_BYTE_GET (j
, pindex
, 4, limit
);
11383 shndx_list
= ppool
+ j
* 4;
11384 /* PR 17531: file: 705e010d. */
11385 if (shndx_list
< ppool
)
11387 warn (_("Section index pool located before start of section\n"));
11391 printf (_(" [%3d] Signature: %#" PRIx64
" Sections: "),
11395 if (shndx_list
>= limit
)
11397 warn (_("Section %s too small for shndx pool\n"),
11401 SAFE_BYTE_GET (shndx
, shndx_list
, 4, limit
);
11404 printf (" %d", shndx
);
11413 else if (version
== 2)
11416 unsigned int dw_sect
;
11417 unsigned char *ph
= phash
;
11418 unsigned char *pi
= pindex
;
11419 unsigned char *poffsets
= ppool
+ (size_t) ncols
* 4;
11420 unsigned char *psizes
= poffsets
+ (size_t) nused
* ncols
* 4;
11422 struct cu_tu_set
*this_set
= NULL
;
11424 unsigned char *prow
;
11427 is_tu_index
= strcmp (section
->name
, ".debug_tu_index") == 0;
11429 /* PR 17531: file: 0dd159bf.
11430 Check for integer overflow (can occur when size_t is 32-bit)
11431 with overlarge ncols or nused values. */
11433 || _mul_overflow ((size_t) ncols
, 4, &temp
)
11434 || _mul_overflow ((size_t) nused
+ 1, temp
, &total
)
11435 || total
> (size_t) (limit
- ppool
)
11436 /* PR 30227: ncols could be 0. */
11437 || _mul_overflow ((size_t) nused
+ 1, 4, &total
)
11438 || total
> (size_t) (limit
- ppool
))
11440 warn (_("Section %s too small for offset and size tables\n"),
11447 printf (_(" Offset table\n"));
11448 printf (" slot %-16s ",
11449 is_tu_index
? _("signature") : _("dwo_id"));
11456 tu_sets
= xcalloc2 (nused
, sizeof (struct cu_tu_set
));
11457 this_set
= tu_sets
;
11462 cu_sets
= xcalloc2 (nused
, sizeof (struct cu_tu_set
));
11463 this_set
= cu_sets
;
11469 for (j
= 0; j
< ncols
; j
++)
11471 unsigned char *p
= ppool
+ j
* 4;
11472 SAFE_BYTE_GET (dw_sect
, p
, 4, limit
);
11473 printf (" %8s", get_DW_SECT_short_name (dw_sect
));
11478 for (i
= 0; i
< nslots
; i
++)
11480 SAFE_BYTE_GET (signature
, ph
, 8, limit
);
11482 SAFE_BYTE_GET (row
, pi
, 4, limit
);
11485 /* PR 17531: file: a05f6ab3. */
11488 warn (_("Row index (%u) is larger than number of used entries (%u)\n"),
11495 size_t num_copy
= sizeof (uint64_t);
11497 memcpy (&this_set
[row
- 1].signature
, ph
, num_copy
);
11500 prow
= poffsets
+ (row
- 1) * ncols
* 4;
11502 printf (" [%3d] %#" PRIx64
, i
, signature
);
11503 for (j
= 0; j
< ncols
; j
++)
11505 unsigned char *p
= prow
+ j
* 4;
11506 SAFE_BYTE_GET (val
, p
, 4, limit
);
11508 printf (" %8d", val
);
11512 SAFE_BYTE_GET (dw_sect
, p
, 4, limit
);
11514 /* PR 17531: file: 10796eb3. */
11515 if (dw_sect
>= DW_SECT_MAX
)
11516 warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect
);
11518 this_set
[row
- 1].section_offsets
[dw_sect
] = val
;
11534 printf (_(" Size table\n"));
11535 printf (" slot %-16s ",
11536 is_tu_index
? _("signature") : _("dwo_id"));
11539 for (j
= 0; j
< ncols
; j
++)
11541 unsigned char *p
= ppool
+ j
* 4;
11542 SAFE_BYTE_GET (val
, p
, 4, limit
);
11544 printf (" %8s", get_DW_SECT_short_name (val
));
11550 for (i
= 0; i
< nslots
; i
++)
11552 SAFE_BYTE_GET (signature
, ph
, 8, limit
);
11554 SAFE_BYTE_GET (row
, pi
, 4, limit
);
11557 prow
= psizes
+ (row
- 1) * ncols
* 4;
11560 printf (" [%3d] %#" PRIx64
, i
, signature
);
11562 for (j
= 0; j
< ncols
; j
++)
11564 unsigned char *p
= prow
+ j
* 4;
11566 /* PR 28645: Check for overflow. Since we do not know how
11567 many populated rows there will be, we cannot just
11568 perform a single check at the start of this function. */
11569 if (p
> (limit
- 4))
11573 warn (_("Too many rows/columns in DWARF index section %s\n"),
11578 SAFE_BYTE_GET (val
, p
, 4, limit
);
11581 printf (" %8d", val
);
11585 SAFE_BYTE_GET (dw_sect
, p
, 4, limit
);
11586 if (dw_sect
>= DW_SECT_MAX
)
11587 warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect
);
11589 this_set
[row
- 1].section_sizes
[dw_sect
] = val
;
11601 else if (do_display
)
11602 printf (_(" Unsupported version (%d)\n"), version
);
11610 static int cu_tu_indexes_read
= -1; /* Tri-state variable. */
11612 /* Load the CU and TU indexes if present. This will build a list of
11613 section sets that we can use to associate a .debug_info.dwo section
11614 with its associated .debug_abbrev.dwo section in a .dwp file. */
11617 load_cu_tu_indexes (void *file
)
11619 /* If we have already loaded (or tried to load) the CU and TU indexes
11620 then do not bother to repeat the task. */
11621 if (cu_tu_indexes_read
== -1)
11623 cu_tu_indexes_read
= true;
11625 if (load_debug_section_with_follow (dwp_cu_index
, file
))
11626 if (! process_cu_tu_index (&debug_displays
[dwp_cu_index
].section
, 0))
11627 cu_tu_indexes_read
= false;
11629 if (load_debug_section_with_follow (dwp_tu_index
, file
))
11630 if (! process_cu_tu_index (&debug_displays
[dwp_tu_index
].section
, 0))
11631 cu_tu_indexes_read
= false;
11634 return (bool) cu_tu_indexes_read
;
11637 /* Find the set of sections that includes section SHNDX. */
11640 find_cu_tu_set (void *file
, unsigned int shndx
)
11644 if (! load_cu_tu_indexes (file
))
11647 /* Find SHNDX in the shndx pool. */
11648 for (i
= 0; i
< shndx_pool_used
; i
++)
11649 if (shndx_pool
[i
] == shndx
)
11652 if (i
>= shndx_pool_used
)
11655 /* Now backup to find the first entry in the set. */
11656 while (i
> 0 && shndx_pool
[i
- 1] != 0)
11659 return shndx_pool
+ i
;
11662 /* Display a .debug_cu_index or .debug_tu_index section. */
11665 display_cu_index (struct dwarf_section
*section
, void *file ATTRIBUTE_UNUSED
)
11667 return process_cu_tu_index (section
, 1);
11671 display_debug_not_supported (struct dwarf_section
*section
,
11672 void *file ATTRIBUTE_UNUSED
)
11674 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
11680 /* Like malloc, but takes two parameters like calloc.
11681 Verifies that the first parameter is not too large.
11682 Note: does *not* initialise the allocated memory to zero. */
11685 cmalloc (uint64_t nmemb
, size_t size
)
11687 /* Check for overflow. */
11688 if (nmemb
>= ~(size_t) 0 / size
)
11691 return xmalloc (nmemb
* size
);
11694 /* Like xmalloc, but takes two parameters like calloc.
11695 Verifies that the first parameter is not too large.
11696 Note: does *not* initialise the allocated memory to zero. */
11699 xcmalloc (uint64_t nmemb
, size_t size
)
11701 /* Check for overflow. */
11702 if (nmemb
>= ~(size_t) 0 / size
)
11705 _("Attempt to allocate an array with an excessive number of elements: %#" PRIx64
"\n"),
11710 return xmalloc (nmemb
* size
);
11713 /* Like xrealloc, but takes three parameters.
11714 Verifies that the second parameter is not too large.
11715 Note: does *not* initialise any new memory to zero. */
11718 xcrealloc (void *ptr
, uint64_t nmemb
, size_t size
)
11720 /* Check for overflow. */
11721 if (nmemb
>= ~(size_t) 0 / size
)
11723 error (_("Attempt to re-allocate an array with an excessive number of elements: %#" PRIx64
"\n"),
11728 return xrealloc (ptr
, nmemb
* size
);
11731 /* Like xcalloc, but verifies that the first parameter is not too large. */
11734 xcalloc2 (uint64_t nmemb
, size_t size
)
11736 /* Check for overflow. */
11737 if (nmemb
>= ~(size_t) 0 / size
)
11739 error (_("Attempt to allocate a zero'ed array with an excessive number of elements: %#" PRIx64
"\n"),
11744 return xcalloc (nmemb
, size
);
11747 static unsigned long
11748 calc_gnu_debuglink_crc32 (unsigned long crc
,
11749 const unsigned char *buf
,
11752 static const unsigned long crc32_table
[256] =
11754 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
11755 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
11756 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
11757 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
11758 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
11759 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
11760 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
11761 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
11762 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
11763 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
11764 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
11765 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
11766 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
11767 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
11768 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
11769 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
11770 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
11771 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
11772 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
11773 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
11774 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
11775 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
11776 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
11777 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
11778 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
11779 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
11780 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
11781 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
11782 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
11783 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
11784 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
11785 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
11786 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
11787 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
11788 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
11789 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
11790 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
11791 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
11792 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
11793 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
11794 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
11795 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
11796 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
11797 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
11798 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
11799 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
11800 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
11801 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
11802 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
11803 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
11804 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
11807 const unsigned char *end
;
11809 crc
= ~crc
& 0xffffffff;
11810 for (end
= buf
+ len
; buf
< end
; ++ buf
)
11811 crc
= crc32_table
[(crc
^ *buf
) & 0xff] ^ (crc
>> 8);
11812 return ~crc
& 0xffffffff;
11815 typedef bool (*check_func_type
) (const char *, void *);
11816 typedef const char *(* parse_func_type
) (struct dwarf_section
*, void *);
11819 check_gnu_debuglink (const char * pathname
, void * crc_pointer
)
11821 static unsigned char buffer
[8 * 1024];
11824 unsigned long crc
= 0;
11827 sep_data
= open_debug_file (pathname
);
11828 if (sep_data
== NULL
)
11831 /* Yes - we are opening the file twice... */
11832 f
= fopen (pathname
, "rb");
11835 /* Paranoia: This should never happen. */
11836 close_debug_file (sep_data
);
11837 warn (_("Unable to reopen separate debug info file: %s\n"), pathname
);
11841 while ((count
= fread (buffer
, 1, sizeof (buffer
), f
)) > 0)
11842 crc
= calc_gnu_debuglink_crc32 (crc
, buffer
, count
);
11845 close_debug_file (sep_data
);
11847 if (crc
!= * (unsigned long *) crc_pointer
)
11849 warn (_("Separate debug info file %s found, but CRC does not match - ignoring\n"),
11857 static const char *
11858 parse_gnu_debuglink (struct dwarf_section
* section
, void * data
)
11861 unsigned int crc_offset
;
11862 unsigned long * crc32
= (unsigned long *) data
;
11864 /* The name is first.
11865 The CRC value is stored after the filename, aligned up to 4 bytes. */
11866 name
= (const char *) section
->start
;
11868 crc_offset
= strnlen (name
, section
->size
) + 1;
11869 if (crc_offset
== 1)
11871 crc_offset
= (crc_offset
+ 3) & ~3;
11872 if (crc_offset
+ 4 > section
->size
)
11875 * crc32
= byte_get (section
->start
+ crc_offset
, 4);
11880 check_gnu_debugaltlink (const char * filename
, void * data ATTRIBUTE_UNUSED
)
11882 void * sep_data
= open_debug_file (filename
);
11884 if (sep_data
== NULL
)
11887 /* FIXME: We should now extract the build-id in the separate file
11890 close_debug_file (sep_data
);
11894 typedef struct build_id_data
11897 const unsigned char *data
;
11900 static const char *
11901 parse_gnu_debugaltlink (struct dwarf_section
* section
, void * data
)
11906 Build_id_data
*build_id_data
;
11908 /* The name is first.
11909 The build-id follows immediately, with no padding, up to the section's end. */
11911 name
= (const char *) section
->start
;
11912 namelen
= strnlen (name
, section
->size
) + 1;
11915 if (namelen
>= section
->size
)
11918 id_len
= section
->size
- namelen
;
11922 build_id_data
= (Build_id_data
*) data
;
11923 build_id_data
->len
= id_len
;
11924 build_id_data
->data
= section
->start
+ namelen
;
11930 add_separate_debug_file (const char * filename
, void * handle
)
11932 separate_info
* i
= xmalloc (sizeof * i
);
11934 i
->filename
= filename
;
11935 i
->handle
= handle
;
11936 i
->next
= first_separate_info
;
11937 first_separate_info
= i
;
11940 #if HAVE_LIBDEBUGINFOD
11941 /* Query debuginfod servers for the target debuglink or debugaltlink
11942 file. If successful, store the path of the file in filename and
11943 return TRUE, otherwise return FALSE. */
11946 debuginfod_fetch_separate_debug_info (struct dwarf_section
* section
,
11950 size_t build_id_len
;
11951 unsigned char * build_id
;
11953 if (strcmp (section
->uncompressed_name
, ".gnu_debuglink") == 0)
11955 /* Get the build-id of file. */
11956 build_id
= get_build_id (file
);
11959 else if (strcmp (section
->uncompressed_name
, ".gnu_debugaltlink") == 0)
11961 /* Get the build-id of the debugaltlink file. */
11962 unsigned int filelen
;
11964 filelen
= strnlen ((const char *)section
->start
, section
->size
);
11965 if (filelen
== section
->size
)
11966 /* Corrupt debugaltlink. */
11969 build_id
= section
->start
+ filelen
+ 1;
11970 build_id_len
= section
->size
- (filelen
+ 1);
11972 if (build_id_len
== 0)
11981 debuginfod_client
* client
;
11983 client
= debuginfod_begin ();
11984 if (client
== NULL
)
11987 /* Query debuginfod servers for the target file. If found its path
11988 will be stored in filename. */
11989 fd
= debuginfod_find_debuginfo (client
, build_id
, build_id_len
, filename
);
11990 debuginfod_end (client
);
11992 /* Only free build_id if we allocated space for a hex string
11993 in get_build_id (). */
11994 if (build_id_len
== 0)
11999 /* File successfully retrieved. Close fd since we want to
12000 use open_debug_file () on filename instead. */
12008 #endif /* HAVE_LIBDEBUGINFOD */
12011 load_separate_debug_info (const char * main_filename
,
12012 struct dwarf_section
* xlink
,
12013 parse_func_type parse_func
,
12014 check_func_type check_func
,
12016 void * file ATTRIBUTE_UNUSED
)
12018 const char * separate_filename
;
12019 char * debug_filename
;
12021 size_t canon_dirlen
;
12023 char * canon_filename
;
12024 char * canon_debug_filename
;
12027 if ((separate_filename
= parse_func (xlink
, func_data
)) == NULL
)
12029 warn (_("Corrupt debuglink section: %s\n"),
12030 xlink
->name
? xlink
->name
: xlink
->uncompressed_name
);
12034 /* Attempt to locate the separate file.
12035 This should duplicate the logic in bfd/opncls.c:find_separate_debug_file(). */
12037 canon_filename
= lrealpath (main_filename
);
12038 canon_dir
= xstrdup (canon_filename
);
12040 for (canon_dirlen
= strlen (canon_dir
); canon_dirlen
> 0; canon_dirlen
--)
12041 if (IS_DIR_SEPARATOR (canon_dir
[canon_dirlen
- 1]))
12043 canon_dir
[canon_dirlen
] = '\0';
12046 #define DEBUGDIR "/lib/debug"
12048 #ifndef EXTRA_DEBUG_ROOT1
12049 #define EXTRA_DEBUG_ROOT1 "/usr/lib/debug"
12051 #ifndef EXTRA_DEBUG_ROOT2
12052 #define EXTRA_DEBUG_ROOT2 "/usr/lib/debug/usr"
12055 debug_filename
= (char *) malloc (strlen (DEBUGDIR
) + 1
12057 + strlen (".debug/")
12058 #ifdef EXTRA_DEBUG_ROOT1
12059 + strlen (EXTRA_DEBUG_ROOT1
)
12061 #ifdef EXTRA_DEBUG_ROOT2
12062 + strlen (EXTRA_DEBUG_ROOT2
)
12064 + strlen (separate_filename
)
12066 if (debug_filename
== NULL
)
12068 warn (_("Out of memory\n"));
12070 free (canon_filename
);
12074 /* First try in the current directory. */
12075 sprintf (debug_filename
, "%s", separate_filename
);
12076 if (check_func (debug_filename
, func_data
))
12079 /* Then try in a subdirectory called .debug. */
12080 sprintf (debug_filename
, ".debug/%s", separate_filename
);
12081 if (check_func (debug_filename
, func_data
))
12084 /* Then try in the same directory as the original file. */
12085 sprintf (debug_filename
, "%s%s", canon_dir
, separate_filename
);
12086 if (check_func (debug_filename
, func_data
))
12089 /* And the .debug subdirectory of that directory. */
12090 sprintf (debug_filename
, "%s.debug/%s", canon_dir
, separate_filename
);
12091 if (check_func (debug_filename
, func_data
))
12094 #ifdef EXTRA_DEBUG_ROOT1
12095 /* Try the first extra debug file root. */
12096 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT1
, separate_filename
);
12097 if (check_func (debug_filename
, func_data
))
12100 /* Try the first extra debug file root. */
12101 sprintf (debug_filename
, "%s/%s/%s", EXTRA_DEBUG_ROOT1
, canon_dir
, separate_filename
);
12102 if (check_func (debug_filename
, func_data
))
12106 #ifdef EXTRA_DEBUG_ROOT2
12107 /* Try the second extra debug file root. */
12108 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT2
, separate_filename
);
12109 if (check_func (debug_filename
, func_data
))
12113 /* Then try in the global debug_filename directory. */
12114 strcpy (debug_filename
, DEBUGDIR
);
12115 dirlen
= strlen (DEBUGDIR
) - 1;
12116 if (dirlen
> 0 && DEBUGDIR
[dirlen
] != '/')
12117 strcat (debug_filename
, "/");
12118 strcat (debug_filename
, (const char *) separate_filename
);
12120 if (check_func (debug_filename
, func_data
))
12123 #if HAVE_LIBDEBUGINFOD
12125 char * tmp_filename
;
12128 && debuginfod_fetch_separate_debug_info (xlink
,
12132 /* File successfully downloaded from server, replace
12133 debug_filename with the file's path. */
12134 free (debug_filename
);
12135 debug_filename
= tmp_filename
;
12141 if (do_debug_links
)
12143 /* Failed to find the file. */
12144 warn (_("could not find separate debug file '%s'\n"),
12145 separate_filename
);
12146 warn (_("tried: %s\n"), debug_filename
);
12148 #ifdef EXTRA_DEBUG_ROOT2
12149 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT2
,
12150 separate_filename
);
12151 warn (_("tried: %s\n"), debug_filename
);
12154 #ifdef EXTRA_DEBUG_ROOT1
12155 sprintf (debug_filename
, "%s/%s/%s", EXTRA_DEBUG_ROOT1
,
12156 canon_dir
, separate_filename
);
12157 warn (_("tried: %s\n"), debug_filename
);
12159 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT1
,
12160 separate_filename
);
12161 warn (_("tried: %s\n"), debug_filename
);
12164 sprintf (debug_filename
, "%s.debug/%s", canon_dir
,
12165 separate_filename
);
12166 warn (_("tried: %s\n"), debug_filename
);
12168 sprintf (debug_filename
, "%s%s", canon_dir
, separate_filename
);
12169 warn (_("tried: %s\n"), debug_filename
);
12171 sprintf (debug_filename
, ".debug/%s", separate_filename
);
12172 warn (_("tried: %s\n"), debug_filename
);
12174 sprintf (debug_filename
, "%s", separate_filename
);
12175 warn (_("tried: %s\n"), debug_filename
);
12177 #if HAVE_LIBDEBUGINFOD
12178 if (use_debuginfod
)
12180 char *urls
= getenv (DEBUGINFOD_URLS_ENV_VAR
);
12185 warn (_("tried: DEBUGINFOD_URLS=%s\n"), urls
);
12191 free (debug_filename
);
12192 free (canon_filename
);
12198 canon_debug_filename
= lrealpath (debug_filename
);
12199 self
= strcmp (canon_debug_filename
, canon_filename
) == 0;
12200 free (canon_filename
);
12201 free (canon_debug_filename
);
12204 free (debug_filename
);
12208 void * debug_handle
;
12210 /* Now open the file.... */
12211 if ((debug_handle
= open_debug_file (debug_filename
)) == NULL
)
12213 warn (_("failed to open separate debug file: %s\n"), debug_filename
);
12214 free (debug_filename
);
12218 /* FIXME: We do not check to see if there are any other separate debug info
12219 files that would also match. */
12221 if (do_debug_links
)
12222 printf (_("\n%s: Found separate debug info file: %s\n"), main_filename
, debug_filename
);
12223 add_separate_debug_file (debug_filename
, debug_handle
);
12225 /* Do not free debug_filename - it might be referenced inside
12226 the structure returned by open_debug_file(). */
12227 return debug_handle
;
12230 /* Attempt to load a separate dwarf object file. */
12233 load_dwo_file (const char * main_filename
, const char * name
, const char * dir
, const char * id ATTRIBUTE_UNUSED
)
12235 char * separate_filename
;
12236 void * separate_handle
;
12238 if (IS_ABSOLUTE_PATH (name
))
12239 separate_filename
= strdup (name
);
12241 /* FIXME: Skip adding / if dwo_dir ends in /. */
12242 separate_filename
= concat (dir
, "/", name
, NULL
);
12243 if (separate_filename
== NULL
)
12245 warn (_("Out of memory allocating dwo filename\n"));
12249 if ((separate_handle
= open_debug_file (separate_filename
)) == NULL
)
12251 warn (_("Unable to load dwo file: %s\n"), separate_filename
);
12252 free (separate_filename
);
12256 /* FIXME: We should check the dwo_id. */
12258 printf (_("%s: Found separate debug object file: %s\n\n"), main_filename
, separate_filename
);
12260 add_separate_debug_file (separate_filename
, separate_handle
);
12261 /* Note - separate_filename will be freed in free_debug_memory(). */
12262 return separate_handle
;
12266 try_build_id_prefix (const char * prefix
, char * filename
, const unsigned char * data
, unsigned long id_len
)
12268 char * f
= filename
;
12270 f
+= sprintf (f
, "%s.build-id/%02x/", prefix
, (unsigned) *data
++);
12273 f
+= sprintf (f
, "%02x", (unsigned) *data
++);
12274 strcpy (f
, ".debug");
12276 return open_debug_file (filename
);
12279 /* Try to load a debug file based upon the build-id held in the .note.gnu.build-id section. */
12282 load_build_id_debug_file (const char * main_filename ATTRIBUTE_UNUSED
, void * main_file
)
12284 if (! load_debug_section (note_gnu_build_id
, main_file
))
12285 return; /* No .note.gnu.build-id section. */
12287 struct dwarf_section
* section
= & debug_displays
[note_gnu_build_id
].section
;
12288 if (section
== NULL
)
12290 warn (_("Unable to load the .note.gnu.build-id section\n"));
12294 if (section
->start
== NULL
|| section
->size
< 0x18)
12296 warn (_(".note.gnu.build-id section is corrupt/empty\n"));
12300 /* In theory we should extract the contents of the section into
12301 a note structure and then check the fields. For now though
12302 just use hard coded offsets instead:
12304 Field Bytes Contents
12307 Type 8..11 3 (NT_GNU_BUILD_ID)
12311 /* FIXME: Check the name size, name and type fields. */
12313 unsigned long build_id_size
;
12314 build_id_size
= byte_get (section
->start
+ 4, 4);
12315 if (build_id_size
< 8)
12317 warn (_(".note.gnu.build-id data size is too small\n"));
12321 if (build_id_size
> (section
->size
- 16))
12323 warn (_(".note.gnu.build-id data size is too big\n"));
12328 filename
= xmalloc (strlen (".build-id/")
12329 + build_id_size
* 2 + 2
12330 + strlen (".debug")
12331 /* The next string should be the same as the longest
12332 name found in the prefixes[] array below. */
12333 + strlen ("/usr/lib64/debug/usr/")
12337 static const char * prefixes
[] =
12342 "/usr/lib/debug/usr/",
12343 "/usr/lib64/debug/",
12344 "/usr/lib64/debug/usr/"
12346 long unsigned int i
;
12348 for (i
= 0; i
< ARRAY_SIZE (prefixes
); i
++)
12350 handle
= try_build_id_prefix (prefixes
[i
], filename
,
12351 section
->start
+ 16, build_id_size
);
12352 if (handle
!= NULL
)
12355 /* FIXME: TYhe BFD library also tries a global debugfile directory prefix. */
12356 if (handle
== NULL
)
12358 /* Failed to find a debug file associated with the build-id.
12359 This is not an error however, rather it just means that
12360 the debug info has probably not been loaded on the system,
12361 or that another method is being used to link to the debug
12367 add_separate_debug_file (filename
, handle
);
12370 /* Try to load a debug file pointed to by the .debug_sup section. */
12373 load_debug_sup_file (const char * main_filename
, void * file
)
12375 if (! load_debug_section (debug_sup
, file
))
12376 return; /* No .debug_sup section. */
12378 struct dwarf_section
* section
;
12379 section
= & debug_displays
[debug_sup
].section
;
12380 assert (section
!= NULL
);
12382 if (section
->start
== NULL
|| section
->size
< 5)
12384 warn (_(".debug_sup section is corrupt/empty\n"));
12388 if (section
->start
[2] != 0)
12389 return; /* This is a supplementary file. */
12391 const char * filename
= (const char *) section
->start
+ 3;
12392 if (strnlen (filename
, section
->size
- 3) == section
->size
- 3)
12394 warn (_("filename in .debug_sup section is corrupt\n"));
12398 if (filename
[0] != '/' && strchr (main_filename
, '/'))
12399 filename
= xasprintf ("%.*s/%s",
12400 (int) (strrchr (main_filename
, '/') - main_filename
),
12404 /* PR 27796: Make sure that we pass a filename that can be free'd to
12405 add_separate_debug_file(). */
12406 filename
= xstrdup (filename
);
12408 void * handle
= open_debug_file (filename
);
12409 if (handle
== NULL
)
12411 warn (_("unable to open file '%s' referenced from .debug_sup section\n"), filename
);
12412 free ((void *) filename
);
12416 printf (_("%s: Found supplementary debug file: %s\n\n"), main_filename
, filename
);
12418 /* FIXME: Compare the checksums, if present. */
12419 add_separate_debug_file (filename
, handle
);
12422 /* Load a debuglink section and/or a debugaltlink section, if either are present.
12423 Recursively check the loaded files for more of these sections.
12424 Also follow any links in .debug_sup sections.
12425 FIXME: Should also check for DWO_* entries in the newly loaded files. */
12428 check_for_and_load_links (void * file
, const char * filename
)
12430 void * handle
= NULL
;
12432 if (load_debug_section (gnu_debugaltlink
, file
))
12434 Build_id_data build_id_data
;
12436 handle
= load_separate_debug_info (filename
,
12437 & debug_displays
[gnu_debugaltlink
].section
,
12438 parse_gnu_debugaltlink
,
12439 check_gnu_debugaltlink
,
12444 assert (handle
== first_separate_info
->handle
);
12445 check_for_and_load_links (first_separate_info
->handle
,
12446 first_separate_info
->filename
);
12450 if (load_debug_section (gnu_debuglink
, file
))
12452 unsigned long crc32
;
12454 handle
= load_separate_debug_info (filename
,
12455 & debug_displays
[gnu_debuglink
].section
,
12456 parse_gnu_debuglink
,
12457 check_gnu_debuglink
,
12462 assert (handle
== first_separate_info
->handle
);
12463 check_for_and_load_links (first_separate_info
->handle
,
12464 first_separate_info
->filename
);
12468 load_debug_sup_file (filename
, file
);
12470 load_build_id_debug_file (filename
, file
);
12473 /* Load the separate debug info file(s) attached to FILE, if any exist.
12474 Returns TRUE if any were found, FALSE otherwise.
12475 If TRUE is returned then the linked list starting at first_separate_info
12476 will be populated with open file handles. */
12479 load_separate_debug_files (void * file
, const char * filename
)
12481 /* Skip this operation if we are not interested in debug links. */
12482 if (! do_follow_links
&& ! do_debug_links
)
12485 /* See if there are any dwo links. */
12486 if (load_debug_section (str
, file
)
12487 && load_debug_section (abbrev
, file
)
12488 && load_debug_section (info
, file
))
12490 /* Load the .debug_addr section, if it exists. */
12491 load_debug_section (debug_addr
, file
);
12492 /* Load the .debug_str_offsets section, if it exists. */
12493 load_debug_section (str_index
, file
);
12494 /* Load the .debug_loclists section, if it exists. */
12495 load_debug_section (loclists
, file
);
12496 /* Load the .debug_rnglists section, if it exists. */
12497 load_debug_section (rnglists
, file
);
12501 if (process_debug_info (& debug_displays
[info
].section
, file
, abbrev
,
12504 bool introduced
= false;
12506 const char *dir
= NULL
;
12507 const char *id
= NULL
;
12508 const char *name
= NULL
;
12510 for (dwinfo
= first_dwo_info
; dwinfo
!= NULL
; dwinfo
= dwinfo
->next
)
12512 /* Accumulate NAME, DIR and ID fields. */
12513 switch (dwinfo
->type
)
12517 warn (_("Multiple DWO_NAMEs encountered for the same CU\n"));
12518 name
= dwinfo
->value
;
12522 /* There can be multiple DW_AT_comp_dir entries in a CU,
12523 so do not complain. */
12524 dir
= dwinfo
->value
;
12529 warn (_("multiple DWO_IDs encountered for the same CU\n"));
12530 id
= dwinfo
->value
;
12534 error (_("Unexpected DWO INFO type"));
12538 /* If we have reached the end of our list, or we are changing
12539 CUs, then display the information that we have accumulated
12542 && (dwinfo
->next
== NULL
12543 || dwinfo
->next
->cu_offset
!= dwinfo
->cu_offset
))
12545 if (do_debug_links
)
12549 printf (_("The %s section contains link(s) to dwo file(s):\n\n"),
12550 debug_displays
[info
].section
.uncompressed_name
);
12554 printf (_(" Name: %s\n"), name
);
12555 printf (_(" Directory: %s\n"), dir
? dir
: _("<not-found>"));
12557 display_data (printf (_(" ID: ")), (unsigned char *) id
, 8);
12558 else if (debug_information
[0].dwarf_version
!= 5)
12559 printf (_(" ID: <not specified>\n"));
12563 if (do_follow_links
)
12564 load_dwo_file (filename
, name
, dir
, id
);
12566 name
= dir
= id
= NULL
;
12572 if (! do_follow_links
)
12573 /* The other debug links will be displayed by display_debug_links()
12574 so we do not need to do any further processing here. */
12577 /* FIXME: We do not check for the presence of both link sections in the same file. */
12578 /* FIXME: We do not check for the presence of multiple, same-name debuglink sections. */
12579 /* FIXME: We do not check for the presence of a dwo link as well as a debuglink. */
12581 check_for_and_load_links (file
, filename
);
12582 if (first_separate_info
!= NULL
)
12585 do_follow_links
= 0;
12590 free_debug_memory (void)
12594 free_all_abbrevs ();
12598 shndx_pool_size
= 0;
12599 shndx_pool_used
= 0;
12607 memset (level_type_signed
, 0, sizeof level_type_signed
);
12608 cu_tu_indexes_read
= -1;
12610 for (i
= 0; i
< max
; i
++)
12611 free_debug_section ((enum dwarf_section_display_enum
) i
);
12613 if (debug_information
!= NULL
)
12615 for (i
= 0; i
< alloc_num_debug_info_entries
; i
++)
12616 free_debug_information (&debug_information
[i
]);
12617 free (debug_information
);
12618 debug_information
= NULL
;
12619 alloc_num_debug_info_entries
= num_debug_info_entries
= 0;
12623 separate_info
* next
;
12625 for (d
= first_separate_info
; d
!= NULL
; d
= next
)
12627 close_debug_file (d
->handle
);
12628 free ((void *) d
->filename
);
12632 first_separate_info
= NULL
;
12640 const char *option
;
12643 } debug_dump_long_opts
;
12645 static const debug_dump_long_opts debug_option_table
[] =
12647 { 'A', "addr", &do_debug_addr
, 1 },
12648 { 'a', "abbrev", &do_debug_abbrevs
, 1 },
12649 { 'c', "cu_index", &do_debug_cu_index
, 1 },
12650 #ifdef HAVE_LIBDEBUGINFOD
12651 { 'D', "use-debuginfod", &use_debuginfod
, 1 },
12652 { 'E', "do-not-use-debuginfod", &use_debuginfod
, 0 },
12654 { 'F', "frames-interp", &do_debug_frames_interp
, 1 },
12655 { 'f', "frames", &do_debug_frames
, 1 },
12656 { 'g', "gdb_index", &do_gdb_index
, 1 },
12657 { 'i', "info", &do_debug_info
, 1 },
12658 { 'K', "follow-links", &do_follow_links
, 1 },
12659 { 'k', "links", &do_debug_links
, 1 },
12660 { 'L', "decodedline", &do_debug_lines
, FLAG_DEBUG_LINES_DECODED
},
12661 { 'l', "rawline", &do_debug_lines
, FLAG_DEBUG_LINES_RAW
},
12662 /* For compatibility with earlier versions of readelf. */
12663 { 'l', "line", &do_debug_lines
, FLAG_DEBUG_LINES_RAW
},
12664 { 'm', "macro", &do_debug_macinfo
, 1 },
12665 { 'N', "no-follow-links", &do_follow_links
, 0 },
12666 { 'O', "str-offsets", &do_debug_str_offsets
, 1 },
12667 { 'o', "loc", &do_debug_loc
, 1 },
12668 { 'p', "pubnames", &do_debug_pubnames
, 1 },
12669 { 'R', "Ranges", &do_debug_ranges
, 1 },
12670 { 'r', "aranges", &do_debug_aranges
, 1 },
12671 /* For compatibility with earlier versions of readelf. */
12672 { 'r', "ranges", &do_debug_aranges
, 1 },
12673 { 's', "str", &do_debug_str
, 1 },
12674 { 'T', "trace_aranges", &do_trace_aranges
, 1 },
12675 { 't', "pubtypes", &do_debug_pubtypes
, 1 },
12676 { 'U', "trace_info", &do_trace_info
, 1 },
12677 { 'u', "trace_abbrev", &do_trace_abbrevs
, 1 },
12678 { 0, NULL
, NULL
, 0 }
12681 /* Enable display of specific DWARF sections as determined by the comma
12682 separated strings in NAMES. Returns non-zero if any displaying was
12686 dwarf_select_sections_by_names (const char *names
)
12694 const debug_dump_long_opts
*entry
;
12696 for (entry
= debug_option_table
; entry
->option
; entry
++)
12698 size_t len
= strlen (entry
->option
);
12700 if (strncmp (p
, entry
->option
, len
) == 0
12701 && (p
[len
] == ',' || p
[len
] == '\0'))
12703 if (entry
->val
== 0)
12704 * entry
->variable
= 0;
12706 * entry
->variable
= entry
->val
;
12707 result
|= entry
->val
;
12714 if (entry
->option
== NULL
)
12716 warn (_("Unrecognized debug option '%s'\n"), p
);
12717 p
= strchr (p
, ',');
12726 /* The --debug-dump=frames-interp option also enables the
12727 --debug-dump=frames option. */
12728 if (do_debug_frames_interp
)
12729 do_debug_frames
= 1;
12734 /* Enable display of specific DWARF sections as determined by the characters
12735 in LETTERS. Returns non-zero if any displaying was enabled. */
12738 dwarf_select_sections_by_letters (const char *letters
)
12744 const debug_dump_long_opts
*entry
;
12746 for (entry
= debug_option_table
; entry
->letter
; entry
++)
12748 if (entry
->letter
== * letters
)
12750 if (entry
->val
== 0)
12751 * entry
->variable
= 0;
12753 * entry
->variable
|= entry
->val
;
12754 result
|= entry
->val
;
12759 if (entry
->letter
== 0)
12760 warn (_("Unrecognized debug letter option '%c'\n"), * letters
);
12765 /* The --debug-dump=frames-interp option also enables the
12766 --debug-dump=frames option. */
12767 if (do_debug_frames_interp
)
12768 do_debug_frames
= 1;
12774 dwarf_select_sections_all (void)
12777 do_debug_abbrevs
= 1;
12778 do_debug_lines
= FLAG_DEBUG_LINES_RAW
;
12779 do_debug_pubnames
= 1;
12780 do_debug_pubtypes
= 1;
12781 do_debug_aranges
= 1;
12782 do_debug_ranges
= 1;
12783 do_debug_frames
= 1;
12784 do_debug_macinfo
= 1;
12789 do_trace_abbrevs
= 1;
12790 do_trace_aranges
= 1;
12792 do_debug_cu_index
= 1;
12793 do_follow_links
= 1;
12794 do_debug_links
= 1;
12795 do_debug_str_offsets
= 1;
12798 #define NO_ABBREVS NULL, NULL, NULL, 0, 0, 0, NULL, 0
12799 #define ABBREV(N) NULL, NULL, NULL, 0, 0, N, NULL, 0
12801 /* N.B. The order here must match the order in section_display_enum. */
12803 struct dwarf_section_display debug_displays
[] =
12805 { { ".debug_abbrev", ".zdebug_abbrev", ".dwabrev", NO_ABBREVS
}, display_debug_abbrev
, &do_debug_abbrevs
, false },
12806 { { ".debug_aranges", ".zdebug_aranges", ".dwarnge", NO_ABBREVS
}, display_debug_aranges
, &do_debug_aranges
, true },
12807 { { ".debug_frame", ".zdebug_frame", ".dwframe", NO_ABBREVS
}, display_debug_frames
, &do_debug_frames
, true },
12808 { { ".debug_info", ".zdebug_info", ".dwinfo", ABBREV (abbrev
)}, display_debug_info
, &do_debug_info
, true },
12809 { { ".debug_line", ".zdebug_line", ".dwline", NO_ABBREVS
}, display_debug_lines
, &do_debug_lines
, true },
12810 { { ".debug_pubnames", ".zdebug_pubnames", ".dwpbnms", NO_ABBREVS
}, display_debug_pubnames
, &do_debug_pubnames
, false },
12811 { { ".debug_gnu_pubnames", ".zdebug_gnu_pubnames", "", NO_ABBREVS
}, display_debug_gnu_pubnames
, &do_debug_pubnames
, false },
12812 { { ".eh_frame", "", "", NO_ABBREVS
}, display_debug_frames
, &do_debug_frames
, true },
12813 { { ".eh_frame_hdr", "", "", NO_ABBREVS
}, display_eh_frame_hdr
, &do_debug_frames
, true },
12814 { { ".debug_macinfo", ".zdebug_macinfo", "", NO_ABBREVS
}, display_debug_macinfo
, &do_debug_macinfo
, false },
12815 { { ".debug_macro", ".zdebug_macro", ".dwmac", NO_ABBREVS
}, display_debug_macro
, &do_debug_macinfo
, true },
12816 { { ".debug_str", ".zdebug_str", ".dwstr", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, false },
12817 { { ".debug_line_str", ".zdebug_line_str", "", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, false },
12818 { { ".debug_loc", ".zdebug_loc", ".dwloc", NO_ABBREVS
}, display_debug_loc
, &do_debug_loc
, true },
12819 { { ".debug_loclists", ".zdebug_loclists", "", NO_ABBREVS
}, display_debug_loc
, &do_debug_loc
, true },
12820 { { ".debug_loclists.dwo", ".zdebug_loclists.dwo", "", NO_ABBREVS
}, display_debug_loc
, &do_debug_loc
, true },
12821 { { ".debug_pubtypes", ".zdebug_pubtypes", ".dwpbtyp", NO_ABBREVS
}, display_debug_pubnames
, &do_debug_pubtypes
, false },
12822 { { ".debug_gnu_pubtypes", ".zdebug_gnu_pubtypes", "", NO_ABBREVS
}, display_debug_gnu_pubnames
, &do_debug_pubtypes
, false },
12823 { { ".debug_ranges", ".zdebug_ranges", ".dwrnges", NO_ABBREVS
}, display_debug_ranges
, &do_debug_ranges
, true },
12824 { { ".debug_rnglists", ".zdebug_rnglists", "", NO_ABBREVS
}, display_debug_ranges
, &do_debug_ranges
, true },
12825 { { ".debug_rnglists.dwo", ".zdebug_rnglists.dwo", "", NO_ABBREVS
}, display_debug_ranges
, &do_debug_ranges
, true },
12826 { { ".debug_static_func", ".zdebug_static_func", "", NO_ABBREVS
}, display_debug_not_supported
, NULL
, false },
12827 { { ".debug_static_vars", ".zdebug_static_vars", "", NO_ABBREVS
}, display_debug_not_supported
, NULL
, false },
12828 { { ".debug_types", ".zdebug_types", "", ABBREV (abbrev
) }, display_debug_types
, &do_debug_info
, true },
12829 { { ".debug_weaknames", ".zdebug_weaknames", "", NO_ABBREVS
}, display_debug_not_supported
, NULL
, false },
12830 { { ".gdb_index", "", "", NO_ABBREVS
}, display_gdb_index
, &do_gdb_index
, false },
12831 { { ".debug_names", "", "", NO_ABBREVS
}, display_debug_names
, &do_gdb_index
, false },
12832 { { ".trace_info", "", "", ABBREV (trace_abbrev
) }, display_trace_info
, &do_trace_info
, true },
12833 { { ".trace_abbrev", "", "", NO_ABBREVS
}, display_debug_abbrev
, &do_trace_abbrevs
, false },
12834 { { ".trace_aranges", "", "", NO_ABBREVS
}, display_debug_aranges
, &do_trace_aranges
, false },
12835 { { ".debug_info.dwo", ".zdebug_info.dwo", "", ABBREV (abbrev_dwo
) }, display_debug_info
, &do_debug_info
, true },
12836 { { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo", "", NO_ABBREVS
}, display_debug_abbrev
, &do_debug_abbrevs
, false },
12837 { { ".debug_types.dwo", ".zdebug_types.dwo", "", ABBREV (abbrev_dwo
) }, display_debug_types
, &do_debug_info
, true },
12838 { { ".debug_line.dwo", ".zdebug_line.dwo", "", NO_ABBREVS
}, display_debug_lines
, &do_debug_lines
, true },
12839 { { ".debug_loc.dwo", ".zdebug_loc.dwo", "", NO_ABBREVS
}, display_debug_loc
, &do_debug_loc
, true },
12840 { { ".debug_macro.dwo", ".zdebug_macro.dwo", "", NO_ABBREVS
}, display_debug_macro
, &do_debug_macinfo
, true },
12841 { { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo", "", NO_ABBREVS
}, display_debug_macinfo
, &do_debug_macinfo
, false },
12842 { { ".debug_str.dwo", ".zdebug_str.dwo", "", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, true },
12843 { { ".debug_str_offsets", ".zdebug_str_offsets", "", NO_ABBREVS
}, display_debug_str_offsets
, &do_debug_str_offsets
, true },
12844 { { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo", "", NO_ABBREVS
}, display_debug_str_offsets
, &do_debug_str_offsets
, true },
12845 { { ".debug_addr", ".zdebug_addr", "", NO_ABBREVS
}, display_debug_addr
, &do_debug_addr
, true },
12846 { { ".debug_cu_index", "", "", NO_ABBREVS
}, display_cu_index
, &do_debug_cu_index
, false },
12847 { { ".debug_tu_index", "", "", NO_ABBREVS
}, display_cu_index
, &do_debug_cu_index
, false },
12848 { { ".gnu_debuglink", "", "", NO_ABBREVS
}, display_debug_links
, &do_debug_links
, false },
12849 { { ".gnu_debugaltlink", "", "", NO_ABBREVS
}, display_debug_links
, &do_debug_links
, false },
12850 { { ".debug_sup", "", "", NO_ABBREVS
}, display_debug_sup
, &do_debug_links
, false },
12851 /* Separate debug info files can containt their own .debug_str section,
12852 and this might be in *addition* to a .debug_str section already present
12853 in the main file. Hence we need to have two entries for .debug_str. */
12854 { { ".debug_str", ".zdebug_str", "", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, false },
12855 { { ".note.gnu.build-id", "", "", NO_ABBREVS
}, display_debug_not_supported
, NULL
, false },
12858 /* A static assertion. */
12859 extern int debug_displays_assert
[ARRAY_SIZE (debug_displays
) == max
? 1 : -1];