1 /* dwarf.c -- display DWARF contents of a BFD binary file
2 Copyright (C) 2005-2024 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 str_offset
-= str_section
->address
;
681 if (str_offset
>= str_section
->size
)
683 warn (_("indirect offset too big: %#" PRIx64
"\n"), str_offset
);
684 return _("<indirect index offset is too big>");
687 ret
= (const char *) str_section
->start
+ str_offset
;
689 /* Unfortunately we cannot rely upon str_section ending with a NUL byte.
690 Since our caller is expecting to receive a well formed C string we test
691 for the lack of a terminating byte here. */
692 if (strnlen (ret
, str_section
->size
- str_offset
)
693 == str_section
->size
- str_offset
)
694 return _("<no NUL byte at end of section>");
700 fetch_indexed_addr (uint64_t offset
, uint32_t num_bytes
)
702 struct dwarf_section
*section
= &debug_displays
[debug_addr
].section
;
704 if (section
->start
== NULL
)
706 warn (_("Cannot fetch indexed address: the .debug_addr section is missing\n"));
710 if (offset
+ num_bytes
> section
->size
)
712 warn (_("Offset into section %s too big: %#" PRIx64
"\n"),
713 section
->name
, offset
);
717 return byte_get (section
->start
+ offset
, num_bytes
);
720 /* This is for resolving DW_FORM_rnglistx and DW_FORM_loclistx.
722 The memory layout is: base_address (taken from the CU's top DIE) points at a table of offsets,
723 relative to the section start.
724 The table of offsets contains the offsets of objects of interest relative to the table of offsets.
725 IDX is the index of the desired object in said table of offsets.
727 This returns the offset of the desired object relative to the section start or -1 upon failure. */
730 fetch_indexed_offset (uint64_t idx
,
731 enum dwarf_section_display_enum sec_enum
,
732 uint64_t base_address
,
733 uint64_t offset_size
)
735 uint64_t offset_of_offset
= base_address
+ idx
* offset_size
;
736 struct dwarf_section
*section
= &debug_displays
[sec_enum
].section
;
738 if (section
->start
== NULL
)
740 warn (_("Unable to locate %s section\n"), section
->uncompressed_name
);
744 if (section
->size
< 4)
746 warn (_("Section %s is too small to contain an value indexed from another section!\n"),
751 if (offset_of_offset
+ offset_size
>= section
->size
)
753 warn (_("Offset of %#" PRIx64
" is too big for section %s\n"),
754 offset_of_offset
, section
->name
);
758 return base_address
+ byte_get (section
->start
+ offset_of_offset
, offset_size
);
761 /* FIXME: There are better and more efficient ways to handle
762 these structures. For now though, I just want something that
763 is simple to implement. */
764 /* Records a single attribute in an abbrev. */
765 typedef struct abbrev_attr
767 unsigned long attribute
;
769 int64_t implicit_const
;
770 struct abbrev_attr
*next
;
774 /* Records a single abbrev. */
775 typedef struct abbrev_entry
777 unsigned long number
;
780 struct abbrev_attr
* first_attr
;
781 struct abbrev_attr
* last_attr
;
782 struct abbrev_entry
* next
;
786 /* Records a set of abbreviations. */
787 typedef struct abbrev_list
789 abbrev_entry
* first_abbrev
;
790 abbrev_entry
* last_abbrev
;
792 struct abbrev_list
* next
;
793 unsigned char * start_of_next_abbrevs
;
797 /* Records all the abbrevs found so far. */
798 static struct abbrev_list
* abbrev_lists
= NULL
;
800 typedef struct abbrev_map
807 /* Maps between CU offsets and abbrev sets. */
808 static abbrev_map
* cu_abbrev_map
= NULL
;
809 static unsigned long num_abbrev_map_entries
= 0;
810 static unsigned long next_free_abbrev_map_entry
= 0;
812 #define INITIAL_NUM_ABBREV_MAP_ENTRIES 8
813 #define ABBREV_MAP_ENTRIES_INCREMENT 8
816 record_abbrev_list_for_cu (uint64_t start
, uint64_t end
,
817 abbrev_list
*list
, abbrev_list
*free_list
)
819 if (free_list
!= NULL
)
821 list
->next
= abbrev_lists
;
825 if (cu_abbrev_map
== NULL
)
827 num_abbrev_map_entries
= INITIAL_NUM_ABBREV_MAP_ENTRIES
;
828 cu_abbrev_map
= xmalloc (num_abbrev_map_entries
* sizeof (* cu_abbrev_map
));
830 else if (next_free_abbrev_map_entry
== num_abbrev_map_entries
)
832 num_abbrev_map_entries
+= ABBREV_MAP_ENTRIES_INCREMENT
;
833 cu_abbrev_map
= xrealloc (cu_abbrev_map
, num_abbrev_map_entries
* sizeof (* cu_abbrev_map
));
836 cu_abbrev_map
[next_free_abbrev_map_entry
].start
= start
;
837 cu_abbrev_map
[next_free_abbrev_map_entry
].end
= end
;
838 cu_abbrev_map
[next_free_abbrev_map_entry
].list
= list
;
839 next_free_abbrev_map_entry
++;
843 free_abbrev_list (abbrev_list
*list
)
845 abbrev_entry
*abbrv
= list
->first_abbrev
;
849 abbrev_attr
*attr
= abbrv
->first_attr
;
853 abbrev_attr
*next_attr
= attr
->next
;
858 abbrev_entry
*next_abbrev
= abbrv
->next
;
863 abbrev_list
*next
= list
->next
;
869 free_all_abbrevs (void)
872 abbrev_lists
= free_abbrev_list (abbrev_lists
);
874 free (cu_abbrev_map
);
875 cu_abbrev_map
= NULL
;
876 next_free_abbrev_map_entry
= 0;
880 find_abbrev_list_by_raw_abbrev (unsigned char *raw
)
884 for (list
= abbrev_lists
; list
!= NULL
; list
= list
->next
)
885 if (list
->raw
== raw
)
891 /* Find the abbreviation map for the CU that includes OFFSET.
892 OFFSET is an absolute offset from the start of the .debug_info section. */
893 /* FIXME: This function is going to slow down readelf & objdump.
894 Not caching abbrevs is likely the answer. */
897 find_abbrev_map_by_offset (uint64_t offset
)
901 for (i
= 0; i
< next_free_abbrev_map_entry
; i
++)
902 if (cu_abbrev_map
[i
].start
<= offset
903 && cu_abbrev_map
[i
].end
> offset
)
904 return cu_abbrev_map
+ i
;
910 add_abbrev (unsigned long number
,
915 abbrev_entry
* entry
;
917 entry
= (abbrev_entry
*) xmalloc (sizeof (*entry
));
919 entry
->number
= number
;
921 entry
->children
= children
;
922 entry
->first_attr
= NULL
;
923 entry
->last_attr
= NULL
;
926 assert (list
!= NULL
);
928 if (list
->first_abbrev
== NULL
)
929 list
->first_abbrev
= entry
;
931 list
->last_abbrev
->next
= entry
;
933 list
->last_abbrev
= entry
;
937 add_abbrev_attr (unsigned long attribute
,
939 int64_t implicit_const
,
944 attr
= (abbrev_attr
*) xmalloc (sizeof (*attr
));
946 attr
->attribute
= attribute
;
948 attr
->implicit_const
= implicit_const
;
951 assert (list
!= NULL
&& list
->last_abbrev
!= NULL
);
953 if (list
->last_abbrev
->first_attr
== NULL
)
954 list
->last_abbrev
->first_attr
= attr
;
956 list
->last_abbrev
->last_attr
->next
= attr
;
958 list
->last_abbrev
->last_attr
= attr
;
961 /* Return processed (partial) contents of a .debug_abbrev section.
962 Returns NULL on errors. */
965 process_abbrev_set (struct dwarf_section
*section
,
966 unsigned char *start
,
969 abbrev_list
*list
= xmalloc (sizeof (*list
));
970 list
->first_abbrev
= NULL
;
971 list
->last_abbrev
= NULL
;
979 unsigned long attribute
;
982 READ_ULEB (entry
, start
, end
);
984 /* A single zero is supposed to end the set according
985 to the standard. If there's more, then signal that to
987 if (start
== end
|| entry
== 0)
989 list
->start_of_next_abbrevs
= start
!= end
? start
: NULL
;
993 READ_ULEB (tag
, start
, end
);
995 return free_abbrev_list (list
);
999 add_abbrev (entry
, tag
, children
, list
);
1004 /* Initialize it due to a false compiler warning. */
1005 int64_t implicit_const
= -1;
1007 READ_ULEB (attribute
, start
, end
);
1011 READ_ULEB (form
, start
, end
);
1015 if (form
== DW_FORM_implicit_const
)
1017 READ_SLEB (implicit_const
, start
, end
);
1022 add_abbrev_attr (attribute
, form
, implicit_const
, list
);
1024 while (attribute
!= 0);
1027 /* Report the missing single zero which ends the section. */
1028 error (_("%s section not zero terminated\n"), section
->name
);
1030 return free_abbrev_list (list
);
1033 /* Return a sequence of abbrevs in SECTION starting at ABBREV_BASE
1034 plus ABBREV_OFFSET and finishing at ABBREV_BASE + ABBREV_SIZE.
1035 If FREE_LIST is non-NULL search the already decoded abbrevs on
1036 abbrev_lists first and if found set *FREE_LIST to NULL. If
1037 searching doesn't find a matching abbrev, set *FREE_LIST to the
1038 newly allocated list. If FREE_LIST is NULL, no search is done and
1039 the returned abbrev_list is always newly allocated. */
1041 static abbrev_list
*
1042 find_and_process_abbrev_set (struct dwarf_section
*section
,
1043 uint64_t abbrev_base
,
1044 uint64_t abbrev_size
,
1045 uint64_t abbrev_offset
,
1046 abbrev_list
**free_list
)
1051 if (abbrev_base
>= section
->size
1052 || abbrev_size
> section
->size
- abbrev_base
)
1054 /* PR 17531: file:4bcd9ce9. */
1055 warn (_("Debug info is corrupted, abbrev size (%#" PRIx64
")"
1056 " is larger than abbrev section size (%#" PRIx64
")\n"),
1057 abbrev_base
+ abbrev_size
, section
->size
);
1060 if (abbrev_offset
>= abbrev_size
)
1062 warn (_("Debug info is corrupted, abbrev offset (%#" PRIx64
")"
1063 " is larger than abbrev section size (%#" PRIx64
")\n"),
1064 abbrev_offset
, abbrev_size
);
1068 unsigned char *start
= section
->start
+ abbrev_base
+ abbrev_offset
;
1069 unsigned char *end
= section
->start
+ abbrev_base
+ abbrev_size
;
1070 abbrev_list
*list
= NULL
;
1072 list
= find_abbrev_list_by_raw_abbrev (start
);
1075 list
= process_abbrev_set (section
, start
, end
);
1083 get_TAG_name (uint64_t tag
)
1085 const char *name
= NULL
;
1087 if ((unsigned int) tag
== tag
)
1088 name
= get_DW_TAG_name ((unsigned int) tag
);
1091 static char buffer
[100];
1093 if (tag
>= DW_TAG_lo_user
&& tag
<= DW_TAG_hi_user
)
1094 snprintf (buffer
, sizeof (buffer
),
1095 _("User TAG value: %#" PRIx64
), tag
);
1097 snprintf (buffer
, sizeof (buffer
),
1098 _("Unknown TAG value: %#" PRIx64
), tag
);
1106 get_FORM_name (unsigned long form
)
1108 const char *name
= NULL
;
1111 return "DW_FORM value: 0";
1113 if ((unsigned int) form
== form
)
1114 name
= get_DW_FORM_name ((unsigned int) form
);
1117 static char buffer
[100];
1119 snprintf (buffer
, sizeof (buffer
), _("Unknown FORM value: %lx"), form
);
1127 get_IDX_name (unsigned long idx
)
1129 const char *name
= NULL
;
1131 if ((unsigned int) idx
== idx
)
1132 name
= get_DW_IDX_name ((unsigned int) idx
);
1135 static char buffer
[100];
1137 snprintf (buffer
, sizeof (buffer
), _("Unknown IDX value: %lx"), idx
);
1144 static unsigned char *
1145 display_block (unsigned char *data
,
1147 const unsigned char * const end
, char delimiter
)
1151 printf (_("%c%" PRIu64
" byte block: "), delimiter
, length
);
1153 return (unsigned char *) end
;
1155 maxlen
= end
- data
;
1156 length
= length
> maxlen
? maxlen
: length
;
1159 printf ("%" PRIx64
" ", byte_get (data
++, 1));
1165 decode_location_expression (unsigned char * data
,
1166 unsigned int pointer_size
,
1167 unsigned int offset_size
,
1171 struct dwarf_section
* section
)
1176 unsigned char *end
= data
+ length
;
1177 int need_frame_base
= 0;
1186 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1187 printf ("DW_OP_addr: %" PRIx64
, uvalue
);
1190 printf ("DW_OP_deref");
1193 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1194 printf ("DW_OP_const1u: %" PRIu64
, uvalue
);
1197 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 1, end
);
1198 printf ("DW_OP_const1s: %" PRId64
, svalue
);
1201 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
1202 printf ("DW_OP_const2u: %" PRIu64
, uvalue
);
1205 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1206 printf ("DW_OP_const2s: %" PRId64
, svalue
);
1209 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1210 printf ("DW_OP_const4u: %" PRIu64
, uvalue
);
1213 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
1214 printf ("DW_OP_const4s: %" PRId64
, svalue
);
1217 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 8, end
);
1218 printf ("DW_OP_const8u: %" PRIu64
, uvalue
);
1221 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 8, end
);
1222 printf ("DW_OP_const8s: %" PRId64
, svalue
);
1225 READ_ULEB (uvalue
, data
, end
);
1226 printf ("DW_OP_constu: %" PRIu64
, uvalue
);
1229 READ_SLEB (svalue
, data
, end
);
1230 printf ("DW_OP_consts: %" PRId64
, svalue
);
1233 printf ("DW_OP_dup");
1236 printf ("DW_OP_drop");
1239 printf ("DW_OP_over");
1242 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1243 printf ("DW_OP_pick: %" PRIu64
, uvalue
);
1246 printf ("DW_OP_swap");
1249 printf ("DW_OP_rot");
1252 printf ("DW_OP_xderef");
1255 printf ("DW_OP_abs");
1258 printf ("DW_OP_and");
1261 printf ("DW_OP_div");
1264 printf ("DW_OP_minus");
1267 printf ("DW_OP_mod");
1270 printf ("DW_OP_mul");
1273 printf ("DW_OP_neg");
1276 printf ("DW_OP_not");
1279 printf ("DW_OP_or");
1282 printf ("DW_OP_plus");
1284 case DW_OP_plus_uconst
:
1285 READ_ULEB (uvalue
, data
, end
);
1286 printf ("DW_OP_plus_uconst: %" PRIu64
, uvalue
);
1289 printf ("DW_OP_shl");
1292 printf ("DW_OP_shr");
1295 printf ("DW_OP_shra");
1298 printf ("DW_OP_xor");
1301 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1302 printf ("DW_OP_bra: %" PRId64
, svalue
);
1305 printf ("DW_OP_eq");
1308 printf ("DW_OP_ge");
1311 printf ("DW_OP_gt");
1314 printf ("DW_OP_le");
1317 printf ("DW_OP_lt");
1320 printf ("DW_OP_ne");
1323 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1324 printf ("DW_OP_skip: %" PRId64
, svalue
);
1359 printf ("DW_OP_lit%d", op
- DW_OP_lit0
);
1394 printf ("DW_OP_reg%d (%s)", op
- DW_OP_reg0
,
1395 regname (op
- DW_OP_reg0
, 1));
1430 READ_SLEB (svalue
, data
, end
);
1431 printf ("DW_OP_breg%d (%s): %" PRId64
,
1432 op
- DW_OP_breg0
, regname (op
- DW_OP_breg0
, 1), svalue
);
1436 READ_ULEB (uvalue
, data
, end
);
1437 printf ("DW_OP_regx: %" PRIu64
" (%s)",
1438 uvalue
, regname (uvalue
, 1));
1441 need_frame_base
= 1;
1442 READ_SLEB (svalue
, data
, end
);
1443 printf ("DW_OP_fbreg: %" PRId64
, svalue
);
1446 READ_ULEB (uvalue
, data
, end
);
1447 READ_SLEB (svalue
, data
, end
);
1448 printf ("DW_OP_bregx: %" PRIu64
" (%s) %" PRId64
,
1449 uvalue
, regname (uvalue
, 1), svalue
);
1452 READ_ULEB (uvalue
, data
, end
);
1453 printf ("DW_OP_piece: %" PRIu64
, uvalue
);
1455 case DW_OP_deref_size
:
1456 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1457 printf ("DW_OP_deref_size: %" PRIu64
, uvalue
);
1459 case DW_OP_xderef_size
:
1460 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1461 printf ("DW_OP_xderef_size: %" PRIu64
, uvalue
);
1464 printf ("DW_OP_nop");
1467 /* DWARF 3 extensions. */
1468 case DW_OP_push_object_address
:
1469 printf ("DW_OP_push_object_address");
1472 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1473 this ought to be an 8-byte wide computation. */
1474 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1475 printf ("DW_OP_call2: <%#" PRIx64
">", svalue
+ cu_offset
);
1478 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1479 this ought to be an 8-byte wide computation. */
1480 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
1481 printf ("DW_OP_call4: <%#" PRIx64
">", svalue
+ cu_offset
);
1483 case DW_OP_call_ref
:
1484 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1485 this ought to be an 8-byte wide computation. */
1486 if (dwarf_version
== -1)
1488 printf (_("(DW_OP_call_ref in frame info)"));
1489 /* No way to tell where the next op is, so just bail. */
1490 return need_frame_base
;
1492 if (dwarf_version
== 2)
1494 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1498 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1500 printf ("DW_OP_call_ref: <%#" PRIx64
">", uvalue
);
1502 case DW_OP_form_tls_address
:
1503 printf ("DW_OP_form_tls_address");
1505 case DW_OP_call_frame_cfa
:
1506 printf ("DW_OP_call_frame_cfa");
1508 case DW_OP_bit_piece
:
1509 printf ("DW_OP_bit_piece: ");
1510 READ_ULEB (uvalue
, data
, end
);
1511 printf (_("size: %" PRIu64
" "), uvalue
);
1512 READ_ULEB (uvalue
, data
, end
);
1513 printf (_("offset: %" PRIu64
" "), uvalue
);
1516 /* DWARF 4 extensions. */
1517 case DW_OP_stack_value
:
1518 printf ("DW_OP_stack_value");
1521 case DW_OP_implicit_value
:
1522 printf ("DW_OP_implicit_value");
1523 READ_ULEB (uvalue
, data
, end
);
1524 data
= display_block (data
, uvalue
, end
, ' ');
1527 /* GNU extensions. */
1528 case DW_OP_GNU_push_tls_address
:
1529 printf (_("DW_OP_GNU_push_tls_address or DW_OP_HP_unknown"));
1531 case DW_OP_GNU_uninit
:
1532 printf ("DW_OP_GNU_uninit");
1533 /* FIXME: Is there data associated with this OP ? */
1535 case DW_OP_GNU_encoded_addr
:
1542 addr
= get_encoded_value (&data
, encoding
, section
, end
);
1544 printf ("DW_OP_GNU_encoded_addr: fmt:%02x addr:", encoding
);
1545 print_hex_ns (addr
, pointer_size
);
1548 case DW_OP_implicit_pointer
:
1549 case DW_OP_GNU_implicit_pointer
:
1550 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1551 this ought to be an 8-byte wide computation. */
1552 if (dwarf_version
== -1)
1554 printf (_("(%s in frame info)"),
1555 (op
== DW_OP_implicit_pointer
1556 ? "DW_OP_implicit_pointer"
1557 : "DW_OP_GNU_implicit_pointer"));
1558 /* No way to tell where the next op is, so just bail. */
1559 return need_frame_base
;
1561 if (dwarf_version
== 2)
1563 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1567 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1569 READ_SLEB (svalue
, data
, end
);
1570 printf ("%s: <%#" PRIx64
"> %" PRId64
,
1571 (op
== DW_OP_implicit_pointer
1572 ? "DW_OP_implicit_pointer" : "DW_OP_GNU_implicit_pointer"),
1575 case DW_OP_entry_value
:
1576 case DW_OP_GNU_entry_value
:
1577 READ_ULEB (uvalue
, data
, end
);
1578 /* PR 17531: file: 0cc9cd00. */
1579 if (uvalue
> (size_t) (end
- data
))
1580 uvalue
= end
- data
;
1581 printf ("%s: (", (op
== DW_OP_entry_value
? "DW_OP_entry_value"
1582 : "DW_OP_GNU_entry_value"));
1583 if (decode_location_expression (data
, pointer_size
, offset_size
,
1584 dwarf_version
, uvalue
,
1585 cu_offset
, section
))
1586 need_frame_base
= 1;
1590 case DW_OP_const_type
:
1591 case DW_OP_GNU_const_type
:
1592 READ_ULEB (uvalue
, data
, end
);
1593 printf ("%s: <%#" PRIx64
"> ",
1594 (op
== DW_OP_const_type
? "DW_OP_const_type"
1595 : "DW_OP_GNU_const_type"),
1596 cu_offset
+ uvalue
);
1597 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1598 data
= display_block (data
, uvalue
, end
, ' ');
1600 case DW_OP_regval_type
:
1601 case DW_OP_GNU_regval_type
:
1602 READ_ULEB (uvalue
, data
, end
);
1603 printf ("%s: %" PRIu64
" (%s)",
1604 (op
== DW_OP_regval_type
? "DW_OP_regval_type"
1605 : "DW_OP_GNU_regval_type"),
1606 uvalue
, regname (uvalue
, 1));
1607 READ_ULEB (uvalue
, data
, end
);
1608 printf (" <%#" PRIx64
">", cu_offset
+ uvalue
);
1610 case DW_OP_deref_type
:
1611 case DW_OP_GNU_deref_type
:
1612 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1613 printf ("%s: %" PRId64
,
1614 (op
== DW_OP_deref_type
? "DW_OP_deref_type"
1615 : "DW_OP_GNU_deref_type"),
1617 READ_ULEB (uvalue
, data
, end
);
1618 printf (" <%#" PRIx64
">", cu_offset
+ uvalue
);
1621 case DW_OP_GNU_convert
:
1622 READ_ULEB (uvalue
, data
, end
);
1623 printf ("%s <%#" PRIx64
">",
1624 (op
== DW_OP_convert
? "DW_OP_convert" : "DW_OP_GNU_convert"),
1625 uvalue
? cu_offset
+ uvalue
: uvalue
);
1627 case DW_OP_reinterpret
:
1628 case DW_OP_GNU_reinterpret
:
1629 READ_ULEB (uvalue
, data
, end
);
1630 printf ("%s <%#" PRIx64
">",
1631 (op
== DW_OP_reinterpret
? "DW_OP_reinterpret"
1632 : "DW_OP_GNU_reinterpret"),
1633 uvalue
? cu_offset
+ uvalue
: uvalue
);
1635 case DW_OP_GNU_parameter_ref
:
1636 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1637 printf ("DW_OP_GNU_parameter_ref: <%#" PRIx64
">",
1638 cu_offset
+ uvalue
);
1641 READ_ULEB (uvalue
, data
, end
);
1642 printf ("DW_OP_addrx <%#" PRIx64
">", uvalue
);
1644 case DW_OP_GNU_addr_index
:
1645 READ_ULEB (uvalue
, data
, end
);
1646 printf ("DW_OP_GNU_addr_index <%#" PRIx64
">", uvalue
);
1648 case DW_OP_GNU_const_index
:
1649 READ_ULEB (uvalue
, data
, end
);
1650 printf ("DW_OP_GNU_const_index <%#" PRIx64
">", uvalue
);
1652 case DW_OP_GNU_variable_value
:
1653 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1654 this ought to be an 8-byte wide computation. */
1655 if (dwarf_version
== -1)
1657 printf (_("(DW_OP_GNU_variable_value in frame info)"));
1658 /* No way to tell where the next op is, so just bail. */
1659 return need_frame_base
;
1661 if (dwarf_version
== 2)
1663 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1667 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1669 printf ("DW_OP_GNU_variable_value: <%#" PRIx64
">", uvalue
);
1672 /* HP extensions. */
1673 case DW_OP_HP_is_value
:
1674 printf ("DW_OP_HP_is_value");
1675 /* FIXME: Is there data associated with this OP ? */
1677 case DW_OP_HP_fltconst4
:
1678 printf ("DW_OP_HP_fltconst4");
1679 /* FIXME: Is there data associated with this OP ? */
1681 case DW_OP_HP_fltconst8
:
1682 printf ("DW_OP_HP_fltconst8");
1683 /* FIXME: Is there data associated with this OP ? */
1685 case DW_OP_HP_mod_range
:
1686 printf ("DW_OP_HP_mod_range");
1687 /* FIXME: Is there data associated with this OP ? */
1689 case DW_OP_HP_unmod_range
:
1690 printf ("DW_OP_HP_unmod_range");
1691 /* FIXME: Is there data associated with this OP ? */
1694 printf ("DW_OP_HP_tls");
1695 /* FIXME: Is there data associated with this OP ? */
1698 /* PGI (STMicroelectronics) extensions. */
1699 case DW_OP_PGI_omp_thread_num
:
1700 /* Pushes the thread number for the current thread as it would be
1701 returned by the standard OpenMP library function:
1702 omp_get_thread_num(). The "current thread" is the thread for
1703 which the expression is being evaluated. */
1704 printf ("DW_OP_PGI_omp_thread_num");
1708 if (op
>= DW_OP_lo_user
1709 && op
<= DW_OP_hi_user
)
1710 printf (_("(User defined location op %#x)"), op
);
1712 printf (_("(Unknown location op %#x)"), op
);
1713 /* No way to tell where the next op is, so just bail. */
1714 return need_frame_base
;
1717 /* Separate the ops. */
1722 return need_frame_base
;
1725 /* Find the CU or TU set corresponding to the given CU_OFFSET.
1726 This is used for DWARF package files. */
1728 static struct cu_tu_set
*
1729 find_cu_tu_set_v2 (uint64_t cu_offset
, int do_types
)
1731 struct cu_tu_set
*p
;
1733 unsigned int dw_sect
;
1739 dw_sect
= DW_SECT_TYPES
;
1745 dw_sect
= DW_SECT_INFO
;
1749 if (p
->section_offsets
[dw_sect
] == cu_offset
)
1758 fetch_alt_indirect_string (uint64_t offset
)
1762 if (! do_follow_links
)
1765 if (first_separate_info
== NULL
)
1766 return _("<no links available>");
1768 for (i
= first_separate_info
; i
!= NULL
; i
= i
->next
)
1770 struct dwarf_section
* section
;
1773 if (! load_debug_section (separate_debug_str
, i
->handle
))
1776 section
= &debug_displays
[separate_debug_str
].section
;
1778 if (section
->start
== NULL
)
1781 if (offset
>= section
->size
)
1784 ret
= (const char *) (section
->start
+ offset
);
1785 /* Unfortunately we cannot rely upon the .debug_str section ending with a
1786 NUL byte. Since our caller is expecting to receive a well formed C
1787 string we test for the lack of a terminating byte here. */
1788 if (strnlen ((const char *) ret
, section
->size
- offset
)
1789 == section
->size
- offset
)
1790 return _("<no NUL byte at end of alt .debug_str section>");
1795 warn (_("DW_FORM_GNU_strp_alt offset (%#" PRIx64
")"
1796 " too big or no string sections available\n"), offset
);
1797 return _("<offset is too big>");
1801 get_AT_name (unsigned long attribute
)
1806 return "DW_AT value: 0";
1808 /* One value is shared by the MIPS and HP extensions: */
1809 if (attribute
== DW_AT_MIPS_fde
)
1810 return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable";
1812 name
= get_DW_AT_name (attribute
);
1816 static char buffer
[100];
1818 snprintf (buffer
, sizeof (buffer
), _("Unknown AT value: %lx"),
1827 add_dwo_info (const char * value
, uint64_t cu_offset
, dwo_type type
)
1829 dwo_info
* dwinfo
= xmalloc (sizeof * dwinfo
);
1831 dwinfo
->type
= type
;
1832 dwinfo
->value
= value
;
1833 dwinfo
->cu_offset
= cu_offset
;
1834 dwinfo
->next
= first_dwo_info
;
1835 first_dwo_info
= dwinfo
;
1839 add_dwo_name (const char * name
, uint64_t cu_offset
)
1841 add_dwo_info (name
, cu_offset
, DWO_NAME
);
1845 add_dwo_dir (const char * dir
, uint64_t cu_offset
)
1847 add_dwo_info (dir
, cu_offset
, DWO_DIR
);
1851 add_dwo_id (const char * id
, uint64_t cu_offset
)
1853 add_dwo_info (id
, cu_offset
, DWO_ID
);
1857 free_dwo_info (void)
1862 for (dwinfo
= first_dwo_info
; dwinfo
!= NULL
; dwinfo
= next
)
1864 next
= dwinfo
->next
;
1867 first_dwo_info
= NULL
;
1870 /* Ensure that START + UVALUE is less than END.
1871 Return an adjusted UVALUE if necessary to ensure this relationship. */
1873 static inline uint64_t
1874 check_uvalue (const unsigned char *start
,
1876 const unsigned char *end
)
1878 uint64_t max_uvalue
= end
- start
;
1880 /* See PR 17512: file: 008-103549-0.001:0.1.
1881 and PR 24829 for examples of where these tests are triggered. */
1882 if (uvalue
> max_uvalue
)
1884 warn (_("Corrupt attribute block length: %#" PRIx64
"\n"), uvalue
);
1885 uvalue
= max_uvalue
;
1891 static unsigned char *
1892 skip_attr_bytes (unsigned long form
,
1893 unsigned char *data
,
1895 uint64_t pointer_size
,
1896 uint64_t offset_size
,
1898 uint64_t *value_return
)
1901 uint64_t uvalue
= 0;
1908 case DW_FORM_ref_addr
:
1909 if (dwarf_version
== 2)
1910 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1911 else if (dwarf_version
> 2)
1912 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1918 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1922 case DW_FORM_line_strp
:
1923 case DW_FORM_sec_offset
:
1924 case DW_FORM_GNU_ref_alt
:
1925 case DW_FORM_GNU_strp_alt
:
1926 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1929 case DW_FORM_flag_present
:
1937 case DW_FORM_addrx1
:
1938 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1942 case DW_FORM_addrx3
:
1943 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 3, end
);
1949 case DW_FORM_addrx2
:
1950 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
1956 case DW_FORM_addrx4
:
1957 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1961 READ_SLEB (svalue
, data
, end
);
1965 case DW_FORM_ref_udata
:
1967 case DW_FORM_GNU_str_index
:
1969 case DW_FORM_GNU_addr_index
:
1971 case DW_FORM_loclistx
:
1972 case DW_FORM_rnglistx
:
1973 READ_ULEB (uvalue
, data
, end
);
1977 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 8, end
);
1981 case DW_FORM_ref_sig8
:
1985 case DW_FORM_data16
:
1989 case DW_FORM_string
:
1990 inc
= strnlen ((char *) data
, end
- data
) + 1;
1994 case DW_FORM_exprloc
:
1995 READ_ULEB (uvalue
, data
, end
);
1999 case DW_FORM_block1
:
2000 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
2004 case DW_FORM_block2
:
2005 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
2009 case DW_FORM_block4
:
2010 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
2014 case DW_FORM_indirect
:
2015 READ_ULEB (form
, data
, end
);
2016 if (form
== DW_FORM_implicit_const
)
2017 SKIP_ULEB (data
, end
);
2018 return skip_attr_bytes (form
, data
, end
, pointer_size
, offset_size
,
2019 dwarf_version
, value_return
);
2025 * value_return
= uvalue
;
2026 if (inc
<= (size_t) (end
- data
))
2033 /* Given form FORM with value UVALUE, locate and return the abbreviation
2034 associated with it. */
2036 static abbrev_entry
*
2037 get_type_abbrev_from_form (unsigned long form
,
2038 unsigned long uvalue
,
2040 unsigned char *cu_end
,
2041 const struct dwarf_section
*section
,
2042 unsigned long *abbrev_num_return
,
2043 unsigned char **data_return
,
2044 abbrev_map
**map_return
)
2046 unsigned long abbrev_number
;
2048 abbrev_entry
* entry
;
2049 unsigned char * data
;
2051 if (abbrev_num_return
!= NULL
)
2052 * abbrev_num_return
= 0;
2053 if (data_return
!= NULL
)
2054 * data_return
= NULL
;
2058 case DW_FORM_GNU_ref_alt
:
2059 case DW_FORM_ref_sig8
:
2060 /* FIXME: We are unable to handle this form at the moment. */
2063 case DW_FORM_ref_addr
:
2064 if (uvalue
>= section
->size
)
2066 warn (_("Unable to resolve ref_addr form: uvalue %lx "
2067 "> section size %" PRIx64
" (%s)\n"),
2068 uvalue
, section
->size
, section
->name
);
2073 case DW_FORM_ref_sup4
:
2074 case DW_FORM_ref_sup8
:
2081 case DW_FORM_ref_udata
:
2082 if (uvalue
+ cu_offset
< uvalue
2083 || uvalue
+ cu_offset
> (size_t) (cu_end
- section
->start
))
2085 warn (_("Unable to resolve ref form: uvalue %lx + cu_offset %" PRIx64
2086 " > CU size %tx\n"),
2087 uvalue
, cu_offset
, cu_end
- section
->start
);
2090 uvalue
+= cu_offset
;
2093 /* FIXME: Are there other DW_FORMs that can be used by types ? */
2096 warn (_("Unexpected form %lx encountered whilst finding abbreviation for type\n"), form
);
2100 data
= (unsigned char *) section
->start
+ uvalue
;
2101 map
= find_abbrev_map_by_offset (uvalue
);
2105 warn (_("Unable to find abbreviations for CU offset %#lx\n"), uvalue
);
2108 if (map
->list
== NULL
)
2110 warn (_("Empty abbreviation list encountered for CU offset %lx\n"), uvalue
);
2114 if (map_return
!= NULL
)
2116 if (form
== DW_FORM_ref_addr
)
2122 READ_ULEB (abbrev_number
, data
, section
->start
+ section
->size
);
2124 for (entry
= map
->list
->first_abbrev
; entry
!= NULL
; entry
= entry
->next
)
2125 if (entry
->number
== abbrev_number
)
2128 if (abbrev_num_return
!= NULL
)
2129 * abbrev_num_return
= abbrev_number
;
2131 if (data_return
!= NULL
)
2132 * data_return
= data
;
2135 warn (_("Unable to find entry for abbreviation %lu\n"), abbrev_number
);
2140 /* Return IS_SIGNED set to TRUE if the type using abbreviation ENTRY
2141 can be determined to be a signed type. The data for ENTRY can be
2142 found starting at DATA. */
2145 get_type_signedness (abbrev_entry
*entry
,
2146 const struct dwarf_section
*section
,
2147 unsigned char *data
,
2150 uint64_t pointer_size
,
2151 uint64_t offset_size
,
2154 unsigned int nesting
)
2158 * is_signed
= false;
2160 #define MAX_NESTING 20
2161 if (nesting
> MAX_NESTING
)
2163 /* FIXME: Warn - or is this expected ?
2164 NB/ We need to avoid infinite recursion. */
2168 for (attr
= entry
->first_attr
;
2169 attr
!= NULL
&& attr
->attribute
;
2172 unsigned char * orig_data
= data
;
2173 uint64_t uvalue
= 0;
2175 data
= skip_attr_bytes (attr
->form
, data
, end
, pointer_size
,
2176 offset_size
, dwarf_version
, & uvalue
);
2180 switch (attr
->attribute
)
2182 case DW_AT_linkage_name
:
2186 if (attr
->form
== DW_FORM_strp
)
2187 printf (", %s", fetch_indirect_string (uvalue
));
2188 else if (attr
->form
== DW_FORM_string
)
2189 printf (", %.*s", (int) (end
- orig_data
), orig_data
);
2196 abbrev_entry
*type_abbrev
;
2197 unsigned char *type_data
;
2200 type_abbrev
= get_type_abbrev_from_form (attr
->form
,
2205 NULL
/* abbrev num return */,
2208 if (type_abbrev
== NULL
)
2211 get_type_signedness (type_abbrev
, section
, type_data
,
2212 map
? section
->start
+ map
->end
: end
,
2213 map
? map
->start
: cu_offset
,
2214 pointer_size
, offset_size
, dwarf_version
,
2215 is_signed
, nesting
+ 1);
2219 case DW_AT_encoding
:
2220 /* Determine signness. */
2223 case DW_ATE_address
:
2224 /* FIXME - some architectures have signed addresses. */
2225 case DW_ATE_boolean
:
2226 case DW_ATE_unsigned
:
2227 case DW_ATE_unsigned_char
:
2228 case DW_ATE_unsigned_fixed
:
2229 * is_signed
= false;
2233 case DW_ATE_complex_float
:
2236 case DW_ATE_signed_char
:
2237 case DW_ATE_imaginary_float
:
2238 case DW_ATE_decimal_float
:
2239 case DW_ATE_signed_fixed
:
2249 read_and_print_leb128 (unsigned char *data
,
2250 unsigned int *bytes_read
,
2251 unsigned const char *end
,
2255 uint64_t val
= read_leb128 (data
, end
, is_signed
, bytes_read
, &status
);
2257 report_leb_status (status
);
2259 printf ("%" PRId64
, val
);
2261 printf ("%" PRIu64
, val
);
2265 display_discr_list (unsigned long form
,
2267 unsigned char *data
,
2270 unsigned char *end
= data
;
2274 printf ("[default]");
2281 case DW_FORM_block1
:
2282 case DW_FORM_block2
:
2283 case DW_FORM_block4
:
2284 /* Move data pointer back to the start of the byte array. */
2288 printf ("<corrupt>\n");
2289 warn (_("corrupt discr_list - not using a block form\n"));
2295 printf ("<corrupt>\n");
2296 warn (_("corrupt discr_list - block not long enough\n"));
2300 bool is_signed
= (level
> 0 && level
<= MAX_CU_NESTING
2301 ? level_type_signed
[level
- 1] : false);
2306 unsigned char discriminant
;
2307 unsigned int bytes_read
;
2309 SAFE_BYTE_GET_AND_INC (discriminant
, data
, 1, end
);
2311 switch (discriminant
)
2315 read_and_print_leb128 (data
, & bytes_read
, end
, is_signed
);
2321 read_and_print_leb128 (data
, & bytes_read
, end
, is_signed
);
2325 read_and_print_leb128 (data
, & bytes_read
, end
, is_signed
);
2330 printf ("<corrupt>\n");
2331 warn (_("corrupt discr_list - unrecognized discriminant byte %#x\n"),
2341 printf (")(signed)");
2343 printf (")(unsigned)");
2347 display_lang (uint64_t uvalue
)
2351 /* Ordered by the numeric value of these constants. */
2352 case DW_LANG_C89
: printf ("ANSI C"); break;
2353 case DW_LANG_C
: printf ("non-ANSI C"); break;
2354 case DW_LANG_Ada83
: printf ("Ada"); break;
2355 case DW_LANG_C_plus_plus
: printf ("C++"); break;
2356 case DW_LANG_Cobol74
: printf ("Cobol 74"); break;
2357 case DW_LANG_Cobol85
: printf ("Cobol 85"); break;
2358 case DW_LANG_Fortran77
: printf ("FORTRAN 77"); break;
2359 case DW_LANG_Fortran90
: printf ("Fortran 90"); break;
2360 case DW_LANG_Pascal83
: printf ("ANSI Pascal"); break;
2361 case DW_LANG_Modula2
: printf ("Modula 2"); break;
2363 /* DWARF 2.1 values. */
2364 case DW_LANG_Java
: printf ("Java"); break;
2365 case DW_LANG_C99
: printf ("ANSI C99"); break;
2366 case DW_LANG_Ada95
: printf ("ADA 95"); break;
2367 case DW_LANG_Fortran95
: printf ("Fortran 95"); break;
2369 /* DWARF 3 values. */
2370 case DW_LANG_PLI
: printf ("PLI"); break;
2371 case DW_LANG_ObjC
: printf ("Objective C"); break;
2372 case DW_LANG_ObjC_plus_plus
: printf ("Objective C++"); break;
2373 case DW_LANG_UPC
: printf ("Unified Parallel C"); break;
2374 case DW_LANG_D
: printf ("D"); break;
2376 /* DWARF 4 values. */
2377 case DW_LANG_Python
: printf ("Python"); break;
2379 /* DWARF 5 values. */
2380 case DW_LANG_OpenCL
: printf ("OpenCL"); break;
2381 case DW_LANG_Go
: printf ("Go"); break;
2382 case DW_LANG_Modula3
: printf ("Modula 3"); break;
2383 case DW_LANG_Haskell
: printf ("Haskell"); break;
2384 case DW_LANG_C_plus_plus_03
: printf ("C++03"); break;
2385 case DW_LANG_C_plus_plus_11
: printf ("C++11"); break;
2386 case DW_LANG_OCaml
: printf ("OCaml"); break;
2387 case DW_LANG_Rust
: printf ("Rust"); break;
2388 case DW_LANG_C11
: printf ("C11"); break;
2389 case DW_LANG_Swift
: printf ("Swift"); break;
2390 case DW_LANG_Julia
: printf ("Julia"); break;
2391 case DW_LANG_Dylan
: printf ("Dylan"); break;
2392 case DW_LANG_C_plus_plus_14
: printf ("C++14"); break;
2393 case DW_LANG_Fortran03
: printf ("Fortran 03"); break;
2394 case DW_LANG_Fortran08
: printf ("Fortran 08"); break;
2395 case DW_LANG_RenderScript
: printf ("RenderScript"); break;
2397 /* MIPS extension. */
2398 case DW_LANG_Mips_Assembler
: printf ("MIPS assembler"); break;
2400 /* UPC extension. */
2401 case DW_LANG_Upc
: printf ("Unified Parallel C"); break;
2404 if (uvalue
>= DW_LANG_lo_user
&& uvalue
<= DW_LANG_hi_user
)
2405 printf (_("implementation defined: %#" PRIx64
""), uvalue
);
2407 printf (_("unknown: %#" PRIx64
""), uvalue
);
2412 static unsigned char *
2413 read_and_display_attr_value (unsigned long attribute
,
2415 int64_t implicit_const
,
2416 unsigned char *start
,
2417 unsigned char *data
,
2420 uint64_t pointer_size
,
2421 uint64_t offset_size
,
2423 debug_info
*debug_info_p
,
2425 struct dwarf_section
*section
,
2426 struct cu_tu_set
*this_set
,
2431 uint64_t uvalue
= 0;
2432 uint64_t uvalue_hi
= 0;
2433 unsigned char *block_start
= NULL
;
2434 unsigned char *orig_data
= data
;
2436 if (data
> end
|| (data
== end
&& form
!= DW_FORM_flag_present
))
2438 warn (_("Corrupt attribute\n"));
2442 if (do_wide
&& ! do_loc
)
2444 /* PR 26847: Display the name of the form. */
2445 const char * name
= get_FORM_name (form
);
2447 /* For convenience we skip the DW_FORM_ prefix to the name. */
2449 name
+= 8; /* strlen ("DW_FORM_") */
2450 printf ("%c(%s)", delimiter
, name
);
2455 case DW_FORM_ref_addr
:
2456 if (dwarf_version
== 2)
2457 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
2458 else if (dwarf_version
> 2)
2459 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
2461 error (_("Internal error: DW_FORM_ref_addr is not supported in DWARF version 1.\n"));
2465 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
2468 case DW_FORM_strp_sup
:
2470 case DW_FORM_line_strp
:
2471 case DW_FORM_sec_offset
:
2472 case DW_FORM_GNU_ref_alt
:
2473 case DW_FORM_GNU_strp_alt
:
2474 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
2477 case DW_FORM_flag_present
:
2485 case DW_FORM_addrx1
:
2486 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
2492 case DW_FORM_addrx2
:
2493 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
2497 case DW_FORM_addrx3
:
2498 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 3, end
);
2501 case DW_FORM_ref_sup4
:
2505 case DW_FORM_addrx4
:
2506 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
2509 case DW_FORM_ref_sup8
:
2512 case DW_FORM_ref_sig8
:
2513 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 8, end
);
2516 case DW_FORM_data16
:
2517 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 8, end
);
2518 SAFE_BYTE_GET_AND_INC (uvalue_hi
, data
, 8, end
);
2519 if (byte_get
!= byte_get_little_endian
)
2521 uint64_t utmp
= uvalue
;
2528 READ_SLEB (svalue
, data
, end
);
2532 case DW_FORM_GNU_str_index
:
2534 case DW_FORM_ref_udata
:
2536 case DW_FORM_GNU_addr_index
:
2538 case DW_FORM_loclistx
:
2539 case DW_FORM_rnglistx
:
2540 READ_ULEB (uvalue
, data
, end
);
2543 case DW_FORM_indirect
:
2544 READ_ULEB (form
, data
, end
);
2546 printf ("%c%s", delimiter
, get_FORM_name (form
));
2547 if (form
== DW_FORM_implicit_const
)
2548 READ_SLEB (implicit_const
, data
, end
);
2549 return read_and_display_attr_value (attribute
, form
, implicit_const
,
2551 cu_offset
, pointer_size
,
2552 offset_size
, dwarf_version
,
2553 debug_info_p
, do_loc
,
2554 section
, this_set
, delimiter
, level
);
2556 case DW_FORM_implicit_const
:
2557 uvalue
= implicit_const
;
2566 case DW_FORM_ref_addr
:
2568 printf ("%c<%#" PRIx64
">", delimiter
, uvalue
);
2571 case DW_FORM_GNU_ref_alt
:
2575 /* We have already printed the form name. */
2576 printf ("%c<%#" PRIx64
">", delimiter
, uvalue
);
2578 printf ("%c<alt %#" PRIx64
">", delimiter
, uvalue
);
2580 /* FIXME: Follow the reference... */
2586 case DW_FORM_ref_sup4
:
2587 case DW_FORM_ref_udata
:
2589 printf ("%c<%#" PRIx64
">", delimiter
, uvalue
+ cu_offset
);
2594 case DW_FORM_sec_offset
:
2596 printf ("%c%#" PRIx64
, delimiter
, uvalue
);
2599 case DW_FORM_flag_present
:
2605 printf ("%c%" PRId64
, delimiter
, uvalue
);
2610 printf ("%c%" PRIu64
, delimiter
, uvalue
);
2613 case DW_FORM_implicit_const
:
2615 printf ("%c%" PRId64
, delimiter
, implicit_const
);
2618 case DW_FORM_ref_sup8
:
2623 uint64_t utmp
= uvalue
;
2624 if (form
== DW_FORM_ref8
)
2626 printf ("%c%#" PRIx64
, delimiter
, utmp
);
2630 case DW_FORM_data16
:
2634 printf (" %#" PRIx64
, uvalue
);
2636 printf (" %#" PRIx64
"%016" PRIx64
, uvalue_hi
, uvalue
);
2640 case DW_FORM_string
:
2642 printf ("%c%.*s", delimiter
, (int) (end
- data
), data
);
2643 data
+= strnlen ((char *) data
, end
- data
);
2649 case DW_FORM_exprloc
:
2650 READ_ULEB (uvalue
, data
, end
);
2653 if (block_start
>= end
)
2655 warn (_("Block ends prematurely\n"));
2660 uvalue
= check_uvalue (block_start
, uvalue
, end
);
2662 data
= block_start
+ uvalue
;
2667 SAFE_BYTE_GET (op
, block_start
, sizeof (op
), end
);
2668 if (op
!= DW_OP_addrx
)
2669 data
= display_block (block_start
, uvalue
, end
, delimiter
);
2673 case DW_FORM_block1
:
2674 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
2677 case DW_FORM_block2
:
2678 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
2681 case DW_FORM_block4
:
2682 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
2689 /* We have already displayed the form name. */
2690 printf (_("%c(offset: %#" PRIx64
"): %s"),
2691 delimiter
, uvalue
, fetch_indirect_string (uvalue
));
2693 printf (_("%c(indirect string, offset: %#" PRIx64
"): %s"),
2694 delimiter
, uvalue
, fetch_indirect_string (uvalue
));
2698 case DW_FORM_line_strp
:
2702 /* We have already displayed the form name. */
2703 printf (_("%c(offset: %#" PRIx64
"): %s"),
2704 delimiter
, uvalue
, fetch_indirect_line_string (uvalue
));
2706 printf (_("%c(indirect line string, offset: %#" PRIx64
"): %s"),
2707 delimiter
, uvalue
, fetch_indirect_line_string (uvalue
));
2711 case DW_FORM_GNU_str_index
:
2719 const char *suffix
= section
? strrchr (section
->name
, '.') : NULL
;
2720 bool dwo
= suffix
&& strcmp (suffix
, ".dwo") == 0;
2723 strng
= fetch_indexed_string (uvalue
, this_set
, offset_size
, dwo
,
2724 debug_info_p
? debug_info_p
->str_offsets_base
: 0);
2726 /* We have already displayed the form name. */
2727 printf (_("%c(offset: %#" PRIx64
"): %s"),
2728 delimiter
, uvalue
, strng
);
2730 printf (_("%c(indexed string: %#" PRIx64
"): %s"),
2731 delimiter
, uvalue
, strng
);
2735 case DW_FORM_GNU_strp_alt
:
2739 /* We have already displayed the form name. */
2740 printf (_("%c(offset: %#" PRIx64
") %s"),
2741 delimiter
, uvalue
, fetch_alt_indirect_string (uvalue
));
2743 printf (_("%c(alt indirect string, offset: %#" PRIx64
") %s"),
2744 delimiter
, uvalue
, fetch_alt_indirect_string (uvalue
));
2748 case DW_FORM_indirect
:
2749 /* Handled above. */
2752 case DW_FORM_ref_sig8
:
2754 printf ("%c%s: %#" PRIx64
, delimiter
, do_wide
? "" : "signature",
2758 case DW_FORM_GNU_addr_index
:
2760 case DW_FORM_addrx1
:
2761 case DW_FORM_addrx2
:
2762 case DW_FORM_addrx3
:
2763 case DW_FORM_addrx4
:
2764 case DW_FORM_loclistx
:
2765 case DW_FORM_rnglistx
:
2769 const char *suffix
= strrchr (section
->name
, '.');
2770 bool dwo
= suffix
&& strcmp (suffix
, ".dwo") == 0;
2772 if (form
== DW_FORM_loclistx
)
2774 if (debug_info_p
== NULL
)
2778 idx
= fetch_indexed_offset (uvalue
, loclists_dwo
,
2779 debug_info_p
->loclists_base
,
2780 debug_info_p
->offset_size
);
2781 if (idx
!= (uint64_t) -1)
2782 idx
+= (offset_size
== 8) ? 20 : 12;
2784 else if (dwarf_version
> 4)
2786 idx
= fetch_indexed_offset (uvalue
, loclists
,
2787 debug_info_p
->loclists_base
,
2788 debug_info_p
->offset_size
);
2792 /* We want to compute:
2793 idx = fetch_indexed_value (uvalue, loclists,
2794 debug_info_p->loclists_base);
2795 idx += debug_info_p->loclists_base;
2796 Fortunately we already have that sum cached in the
2797 loc_offsets array. */
2798 if (uvalue
< debug_info_p
->num_loc_offsets
)
2799 idx
= debug_info_p
->loc_offsets
[uvalue
];
2802 warn (_("loc_offset %" PRIu64
" too big\n"), uvalue
);
2807 else if (form
== DW_FORM_rnglistx
)
2809 if (debug_info_p
== NULL
)
2812 idx
= fetch_indexed_offset (uvalue
,
2813 dwo
? rnglists_dwo
: rnglists
,
2814 debug_info_p
->rnglists_base
,
2815 debug_info_p
->offset_size
);
2819 if (debug_info_p
== NULL
)
2821 else if (debug_info_p
->addr_base
== DEBUG_INFO_UNAVAILABLE
)
2824 base
= debug_info_p
->addr_base
;
2826 base
+= uvalue
* pointer_size
;
2827 idx
= fetch_indexed_addr (base
, pointer_size
);
2830 /* We have already displayed the form name. */
2831 if (idx
!= (uint64_t) -1)
2832 printf (_("%c(index: %#" PRIx64
"): %#" PRIx64
),
2833 delimiter
, uvalue
, idx
);
2837 case DW_FORM_strp_sup
:
2839 printf ("%c<%#" PRIx64
">", delimiter
, uvalue
+ cu_offset
);
2843 warn (_("Unrecognized form: %#lx\n"), form
);
2844 /* What to do? Consume a byte maybe? */
2849 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
|| do_debug_info
)
2850 && num_debug_info_entries
== 0
2851 && debug_info_p
!= NULL
)
2855 case DW_AT_loclists_base
:
2856 if (debug_info_p
->loclists_base
)
2857 warn (_("CU @ %#" PRIx64
" has multiple loclists_base values "
2858 "(%#" PRIx64
" and %#" PRIx64
")\n"),
2859 debug_info_p
->cu_offset
,
2860 debug_info_p
->loclists_base
, uvalue
);
2864 warn (_("CU @ %#" PRIx64
" has has a negative loclists_base "
2865 "value of %#" PRIx64
" - treating as zero\n"),
2866 debug_info_p
->cu_offset
, svalue
);
2869 debug_info_p
->loclists_base
= uvalue
;
2872 case DW_AT_rnglists_base
:
2873 /* Assignment to debug_info_p->rnglists_base is now elsewhere. */
2876 case DW_AT_str_offsets_base
:
2877 if (debug_info_p
->str_offsets_base
)
2878 warn (_("CU @ %#" PRIx64
" has multiple str_offsets_base values "
2879 "%#" PRIx64
" and %#" PRIx64
")\n"),
2880 debug_info_p
->cu_offset
,
2881 debug_info_p
->str_offsets_base
, uvalue
);
2885 warn (_("CU @ %#" PRIx64
" has has a negative stroffsets_base "
2886 "value of %#" PRIx64
" - treating as zero\n"),
2887 debug_info_p
->cu_offset
, svalue
);
2890 debug_info_p
->str_offsets_base
= uvalue
;
2893 case DW_AT_frame_base
:
2894 /* This is crude; the have_frame_base is reset on the next
2895 subprogram, not at the end of the current topmost one. */
2896 have_frame_base
= 1;
2897 frame_base_level
= level
;
2899 case DW_AT_location
:
2900 case DW_AT_GNU_locviews
:
2901 case DW_AT_string_length
:
2902 case DW_AT_return_addr
:
2903 case DW_AT_data_member_location
:
2904 case DW_AT_vtable_elem_location
:
2906 case DW_AT_static_link
:
2907 case DW_AT_use_location
:
2908 case DW_AT_call_value
:
2909 case DW_AT_GNU_call_site_value
:
2910 case DW_AT_call_data_value
:
2911 case DW_AT_GNU_call_site_data_value
:
2912 case DW_AT_call_target
:
2913 case DW_AT_GNU_call_site_target
:
2914 case DW_AT_call_target_clobbered
:
2915 case DW_AT_GNU_call_site_target_clobbered
:
2916 if ((dwarf_version
< 4
2917 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
2918 || form
== DW_FORM_sec_offset
2919 || form
== DW_FORM_loclistx
)
2921 /* Process location list. */
2922 unsigned int lmax
= debug_info_p
->max_loc_offsets
;
2923 unsigned int num
= debug_info_p
->num_loc_offsets
;
2925 if (lmax
== 0 || num
>= lmax
)
2928 debug_info_p
->loc_offsets
= (uint64_t *)
2929 xcrealloc (debug_info_p
->loc_offsets
,
2930 lmax
, sizeof (*debug_info_p
->loc_offsets
));
2931 debug_info_p
->loc_views
= (uint64_t *)
2932 xcrealloc (debug_info_p
->loc_views
,
2933 lmax
, sizeof (*debug_info_p
->loc_views
));
2934 debug_info_p
->have_frame_base
= (int *)
2935 xcrealloc (debug_info_p
->have_frame_base
,
2936 lmax
, sizeof (*debug_info_p
->have_frame_base
));
2937 debug_info_p
->max_loc_offsets
= lmax
;
2939 if (form
== DW_FORM_loclistx
)
2940 uvalue
= fetch_indexed_offset (num
, loclists
,
2941 debug_info_p
->loclists_base
,
2942 debug_info_p
->offset_size
);
2943 else if (this_set
!= NULL
)
2944 uvalue
+= this_set
->section_offsets
[DW_SECT_LOC
];
2946 debug_info_p
->have_frame_base
[num
] = have_frame_base
;
2947 if (attribute
!= DW_AT_GNU_locviews
)
2949 /* Corrupt DWARF info can produce more offsets than views.
2950 See PR 23062 for an example. */
2951 if (debug_info_p
->num_loc_offsets
2952 > debug_info_p
->num_loc_views
)
2953 warn (_("More location offset attributes than DW_AT_GNU_locview attributes\n"));
2956 debug_info_p
->loc_offsets
[num
] = uvalue
;
2957 debug_info_p
->num_loc_offsets
++;
2962 if (debug_info_p
->num_loc_views
> num
)
2964 warn (_("The number of views (%u) is greater than the number of locations (%u)\n"),
2965 debug_info_p
->num_loc_views
, num
);
2966 debug_info_p
->num_loc_views
= num
;
2969 num
= debug_info_p
->num_loc_views
;
2970 if (num
> debug_info_p
->num_loc_offsets
)
2971 warn (_("More DW_AT_GNU_locview attributes than location offset attributes\n"));
2974 debug_info_p
->loc_views
[num
] = uvalue
;
2975 debug_info_p
->num_loc_views
++;
2982 if (need_base_address
)
2984 if (form
== DW_FORM_addrx
)
2985 uvalue
= fetch_indexed_addr (debug_info_p
->addr_base
2986 + uvalue
* pointer_size
,
2989 debug_info_p
->base_address
= uvalue
;
2993 case DW_AT_GNU_addr_base
:
2994 case DW_AT_addr_base
:
2995 debug_info_p
->addr_base
= uvalue
;
2996 /* Retrieved elsewhere so that it is in
2997 place by the time we read low_pc. */
3000 case DW_AT_GNU_ranges_base
:
3001 debug_info_p
->ranges_base
= uvalue
;
3005 if ((dwarf_version
< 4
3006 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
3007 || form
== DW_FORM_sec_offset
3008 || form
== DW_FORM_rnglistx
)
3010 /* Process range list. */
3011 unsigned int lmax
= debug_info_p
->max_range_lists
;
3012 unsigned int num
= debug_info_p
->num_range_lists
;
3014 if (lmax
== 0 || num
>= lmax
)
3017 debug_info_p
->range_lists
= (uint64_t *)
3018 xcrealloc (debug_info_p
->range_lists
,
3019 lmax
, sizeof (*debug_info_p
->range_lists
));
3020 debug_info_p
->max_range_lists
= lmax
;
3023 if (form
== DW_FORM_rnglistx
)
3024 uvalue
= fetch_indexed_offset (uvalue
, rnglists
,
3025 debug_info_p
->rnglists_base
,
3026 debug_info_p
->offset_size
);
3028 debug_info_p
->range_lists
[num
] = uvalue
;
3029 debug_info_p
->num_range_lists
++;
3033 case DW_AT_GNU_dwo_name
:
3034 case DW_AT_dwo_name
:
3039 add_dwo_name ((const char *) fetch_indirect_string (uvalue
),
3042 case DW_FORM_GNU_strp_alt
:
3043 add_dwo_name ((const char *) fetch_alt_indirect_string (uvalue
), cu_offset
);
3045 case DW_FORM_GNU_str_index
:
3051 add_dwo_name (fetch_indexed_string (uvalue
, this_set
,
3053 debug_info_p
->str_offsets_base
),
3056 case DW_FORM_string
:
3057 add_dwo_name ((const char *) orig_data
, cu_offset
);
3060 warn (_("Unsupported form (%s) for attribute %s\n"),
3061 get_FORM_name (form
), get_AT_name (attribute
));
3066 case DW_AT_comp_dir
:
3067 /* FIXME: Also extract a build-id in a CU/TU. */
3072 add_dwo_dir ((const char *) fetch_indirect_string (uvalue
), cu_offset
);
3074 case DW_FORM_GNU_strp_alt
:
3075 add_dwo_dir (fetch_alt_indirect_string (uvalue
), cu_offset
);
3077 case DW_FORM_line_strp
:
3078 add_dwo_dir ((const char *) fetch_indirect_line_string (uvalue
), cu_offset
);
3080 case DW_FORM_GNU_str_index
:
3086 add_dwo_dir (fetch_indexed_string (uvalue
, this_set
, offset_size
, false,
3087 debug_info_p
->str_offsets_base
),
3090 case DW_FORM_string
:
3091 add_dwo_dir ((const char *) orig_data
, cu_offset
);
3094 warn (_("Unsupported form (%s) for attribute %s\n"),
3095 get_FORM_name (form
), get_AT_name (attribute
));
3100 case DW_AT_GNU_dwo_id
:
3105 /* FIXME: Record the length of the ID as well ? */
3106 add_dwo_id ((const char *) (data
- 8), cu_offset
);
3109 warn (_("Unsupported form (%s) for attribute %s\n"),
3110 get_FORM_name (form
), get_AT_name (attribute
));
3120 if (do_loc
|| attribute
== 0)
3123 /* For some attributes we can display further information. */
3127 if (level
>= 0 && level
< MAX_CU_NESTING
3128 && uvalue
< (size_t) (end
- start
))
3130 bool is_signed
= false;
3131 abbrev_entry
*type_abbrev
;
3132 unsigned char *type_data
;
3135 type_abbrev
= get_type_abbrev_from_form (form
, uvalue
,
3139 if (type_abbrev
!= NULL
)
3141 get_type_signedness (type_abbrev
, section
, type_data
,
3142 map
? section
->start
+ map
->end
: end
,
3143 map
? map
->start
: cu_offset
,
3144 pointer_size
, offset_size
, dwarf_version
,
3147 level_type_signed
[level
] = is_signed
;
3155 case DW_INL_not_inlined
:
3156 printf (_("(not inlined)"));
3158 case DW_INL_inlined
:
3159 printf (_("(inlined)"));
3161 case DW_INL_declared_not_inlined
:
3162 printf (_("(declared as inline but ignored)"));
3164 case DW_INL_declared_inlined
:
3165 printf (_("(declared as inline and inlined)"));
3168 printf (_(" (Unknown inline attribute value: %#" PRIx64
")"),
3174 case DW_AT_language
:
3176 display_lang (uvalue
);
3180 case DW_AT_encoding
:
3184 case DW_ATE_void
: printf ("(void)"); break;
3185 case DW_ATE_address
: printf ("(machine address)"); break;
3186 case DW_ATE_boolean
: printf ("(boolean)"); break;
3187 case DW_ATE_complex_float
: printf ("(complex float)"); break;
3188 case DW_ATE_float
: printf ("(float)"); break;
3189 case DW_ATE_signed
: printf ("(signed)"); break;
3190 case DW_ATE_signed_char
: printf ("(signed char)"); break;
3191 case DW_ATE_unsigned
: printf ("(unsigned)"); break;
3192 case DW_ATE_unsigned_char
: printf ("(unsigned char)"); break;
3193 /* DWARF 2.1 values: */
3194 case DW_ATE_imaginary_float
: printf ("(imaginary float)"); break;
3195 case DW_ATE_decimal_float
: printf ("(decimal float)"); break;
3196 /* DWARF 3 values: */
3197 case DW_ATE_packed_decimal
: printf ("(packed_decimal)"); break;
3198 case DW_ATE_numeric_string
: printf ("(numeric_string)"); break;
3199 case DW_ATE_edited
: printf ("(edited)"); break;
3200 case DW_ATE_signed_fixed
: printf ("(signed_fixed)"); break;
3201 case DW_ATE_unsigned_fixed
: printf ("(unsigned_fixed)"); break;
3202 /* DWARF 4 values: */
3203 case DW_ATE_UTF
: printf ("(unicode string)"); break;
3204 /* DWARF 5 values: */
3205 case DW_ATE_UCS
: printf ("(UCS)"); break;
3206 case DW_ATE_ASCII
: printf ("(ASCII)"); break;
3208 /* HP extensions: */
3209 case DW_ATE_HP_float80
: printf ("(HP_float80)"); break;
3210 case DW_ATE_HP_complex_float80
: printf ("(HP_complex_float80)"); break;
3211 case DW_ATE_HP_float128
: printf ("(HP_float128)"); break;
3212 case DW_ATE_HP_complex_float128
:printf ("(HP_complex_float128)"); break;
3213 case DW_ATE_HP_floathpintel
: printf ("(HP_floathpintel)"); break;
3214 case DW_ATE_HP_imaginary_float80
: printf ("(HP_imaginary_float80)"); break;
3215 case DW_ATE_HP_imaginary_float128
: printf ("(HP_imaginary_float128)"); break;
3218 if (uvalue
>= DW_ATE_lo_user
3219 && uvalue
<= DW_ATE_hi_user
)
3220 printf (_("(user defined type)"));
3222 printf (_("(unknown type)"));
3227 case DW_AT_accessibility
:
3231 case DW_ACCESS_public
: printf ("(public)"); break;
3232 case DW_ACCESS_protected
: printf ("(protected)"); break;
3233 case DW_ACCESS_private
: printf ("(private)"); break;
3235 printf (_("(unknown accessibility)"));
3240 case DW_AT_visibility
:
3244 case DW_VIS_local
: printf ("(local)"); break;
3245 case DW_VIS_exported
: printf ("(exported)"); break;
3246 case DW_VIS_qualified
: printf ("(qualified)"); break;
3247 default: printf (_("(unknown visibility)")); break;
3251 case DW_AT_endianity
:
3255 case DW_END_default
: printf ("(default)"); break;
3256 case DW_END_big
: printf ("(big)"); break;
3257 case DW_END_little
: printf ("(little)"); break;
3259 if (uvalue
>= DW_END_lo_user
&& uvalue
<= DW_END_hi_user
)
3260 printf (_("(user specified)"));
3262 printf (_("(unknown endianity)"));
3267 case DW_AT_virtuality
:
3271 case DW_VIRTUALITY_none
: printf ("(none)"); break;
3272 case DW_VIRTUALITY_virtual
: printf ("(virtual)"); break;
3273 case DW_VIRTUALITY_pure_virtual
:printf ("(pure_virtual)"); break;
3274 default: printf (_("(unknown virtuality)")); break;
3278 case DW_AT_identifier_case
:
3282 case DW_ID_case_sensitive
: printf ("(case_sensitive)"); break;
3283 case DW_ID_up_case
: printf ("(up_case)"); break;
3284 case DW_ID_down_case
: printf ("(down_case)"); break;
3285 case DW_ID_case_insensitive
: printf ("(case_insensitive)"); break;
3286 default: printf (_("(unknown case)")); break;
3290 case DW_AT_calling_convention
:
3294 case DW_CC_normal
: printf ("(normal)"); break;
3295 case DW_CC_program
: printf ("(program)"); break;
3296 case DW_CC_nocall
: printf ("(nocall)"); break;
3297 case DW_CC_pass_by_reference
: printf ("(pass by ref)"); break;
3298 case DW_CC_pass_by_value
: printf ("(pass by value)"); break;
3299 case DW_CC_GNU_renesas_sh
: printf ("(Rensas SH)"); break;
3300 case DW_CC_GNU_borland_fastcall_i386
: printf ("(Borland fastcall i386)"); break;
3302 if (uvalue
>= DW_CC_lo_user
3303 && uvalue
<= DW_CC_hi_user
)
3304 printf (_("(user defined)"));
3306 printf (_("(unknown convention)"));
3310 case DW_AT_ordering
:
3315 case -1: printf (_("(undefined)")); break;
3316 case 0: printf ("(row major)"); break;
3317 case 1: printf ("(column major)"); break;
3321 case DW_AT_decimal_sign
:
3325 case DW_DS_unsigned
: printf (_("(unsigned)")); break;
3326 case DW_DS_leading_overpunch
: printf (_("(leading overpunch)")); break;
3327 case DW_DS_trailing_overpunch
: printf (_("(trailing overpunch)")); break;
3328 case DW_DS_leading_separate
: printf (_("(leading separate)")); break;
3329 case DW_DS_trailing_separate
: printf (_("(trailing separate)")); break;
3330 default: printf (_("(unrecognised)")); break;
3334 case DW_AT_defaulted
:
3338 case DW_DEFAULTED_no
: printf (_("(no)")); break;
3339 case DW_DEFAULTED_in_class
: printf (_("(in class)")); break;
3340 case DW_DEFAULTED_out_of_class
: printf (_("(out of class)")); break;
3341 default: printf (_("(unrecognised)")); break;
3345 case DW_AT_discr_list
:
3347 display_discr_list (form
, uvalue
, data
, level
);
3350 case DW_AT_frame_base
:
3351 have_frame_base
= 1;
3353 case DW_AT_location
:
3354 case DW_AT_loclists_base
:
3355 case DW_AT_rnglists_base
:
3356 case DW_AT_str_offsets_base
:
3357 case DW_AT_string_length
:
3358 case DW_AT_return_addr
:
3359 case DW_AT_data_member_location
:
3360 case DW_AT_vtable_elem_location
:
3362 case DW_AT_static_link
:
3363 case DW_AT_use_location
:
3364 case DW_AT_call_value
:
3365 case DW_AT_GNU_call_site_value
:
3366 case DW_AT_call_data_value
:
3367 case DW_AT_GNU_call_site_data_value
:
3368 case DW_AT_call_target
:
3369 case DW_AT_GNU_call_site_target
:
3370 case DW_AT_call_target_clobbered
:
3371 case DW_AT_GNU_call_site_target_clobbered
:
3372 if ((dwarf_version
< 4
3373 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
3374 || form
== DW_FORM_sec_offset
3375 || form
== DW_FORM_loclistx
)
3377 if (attribute
!= DW_AT_rnglists_base
3378 && attribute
!= DW_AT_str_offsets_base
)
3379 printf (_(" (location list)"));
3382 case DW_AT_allocated
:
3383 case DW_AT_associated
:
3384 case DW_AT_data_location
:
3386 case DW_AT_upper_bound
:
3387 case DW_AT_lower_bound
:
3391 int need_frame_base
;
3394 need_frame_base
= decode_location_expression (block_start
,
3399 cu_offset
, section
);
3401 if (need_frame_base
&& !have_frame_base
)
3402 printf (_(" [without DW_AT_frame_base]"));
3406 case DW_AT_data_bit_offset
:
3407 case DW_AT_byte_size
:
3408 case DW_AT_bit_size
:
3409 case DW_AT_string_length_byte_size
:
3410 case DW_AT_string_length_bit_size
:
3411 case DW_AT_bit_stride
:
3412 if (form
== DW_FORM_exprloc
)
3415 (void) decode_location_expression (block_start
, pointer_size
,
3416 offset_size
, dwarf_version
,
3417 uvalue
, cu_offset
, section
);
3424 unsigned long abbrev_number
;
3425 abbrev_entry
*entry
;
3427 entry
= get_type_abbrev_from_form (form
, uvalue
, cu_offset
, end
,
3428 section
, & abbrev_number
, NULL
, NULL
);
3431 if (form
!= DW_FORM_GNU_ref_alt
)
3432 warn (_("Offset %#" PRIx64
" used as value for DW_AT_import attribute of DIE at offset %#tx is too big.\n"),
3434 orig_data
- section
->start
);
3438 printf (_("\t[Abbrev Number: %ld"), abbrev_number
);
3439 printf (" (%s)", get_TAG_name (entry
->tag
));
3452 static unsigned char *
3453 read_and_display_attr (unsigned long attribute
,
3455 int64_t implicit_const
,
3456 unsigned char *start
,
3457 unsigned char *data
,
3460 uint64_t pointer_size
,
3461 uint64_t offset_size
,
3463 debug_info
*debug_info_p
,
3465 struct dwarf_section
*section
,
3466 struct cu_tu_set
*this_set
,
3470 printf (" %-18s:", get_AT_name (attribute
));
3471 data
= read_and_display_attr_value (attribute
, form
, implicit_const
,
3473 cu_offset
, pointer_size
, offset_size
,
3474 dwarf_version
, debug_info_p
,
3475 do_loc
, section
, this_set
, ' ', level
);
3481 /* Like load_debug_section, but if the ordinary call fails, and we are
3482 following debug links, then attempt to load the requested section
3483 from one of the separate debug info files. */
3486 load_debug_section_with_follow (enum dwarf_section_display_enum sec_enum
,
3489 if (load_debug_section (sec_enum
, handle
))
3491 if (debug_displays
[sec_enum
].section
.filename
== NULL
)
3493 /* See if we can associate a filename with this section. */
3496 for (i
= first_separate_info
; i
!= NULL
; i
= i
->next
)
3497 if (i
->handle
== handle
)
3499 debug_displays
[sec_enum
].section
.filename
= i
->filename
;
3507 if (do_follow_links
)
3511 for (i
= first_separate_info
; i
!= NULL
; i
= i
->next
)
3513 if (load_debug_section (sec_enum
, i
->handle
))
3515 debug_displays
[sec_enum
].section
.filename
= i
->filename
;
3517 /* FIXME: We should check to see if any of the remaining debug info
3518 files also contain this section, and, umm, do something about it. */
3528 introduce (struct dwarf_section
* section
, bool raw
)
3532 if (do_follow_links
&& section
->filename
)
3533 printf (_("Raw dump of debug contents of section %s (loaded from %s):\n\n"),
3534 section
->name
, section
->filename
);
3536 printf (_("Raw dump of debug contents of section %s:\n\n"), section
->name
);
3540 if (do_follow_links
&& section
->filename
)
3541 printf (_("Contents of the %s section (loaded from %s):\n\n"),
3542 section
->name
, section
->filename
);
3544 printf (_("Contents of the %s section:\n\n"), section
->name
);
3548 /* Free memory allocated for one unit in debug_information. */
3551 free_debug_information (debug_info
*ent
)
3553 if (ent
->max_loc_offsets
)
3555 free (ent
->loc_offsets
);
3556 free (ent
->loc_views
);
3557 free (ent
->have_frame_base
);
3559 if (ent
->max_range_lists
)
3561 free (ent
->range_lists
);
3565 /* For look-ahead in attributes. When you want to scan a DIE for one specific
3566 attribute and ignore the rest. */
3568 static unsigned char *
3569 skip_attribute (unsigned long form
,
3570 unsigned char * data
,
3571 unsigned char * end
,
3572 uint64_t pointer_size
,
3573 uint64_t offset_size
,
3581 case DW_FORM_ref_addr
:
3582 data
+= dwarf_version
== 2 ? pointer_size
: offset_size
;
3585 data
+= pointer_size
;
3587 case DW_FORM_strp_sup
:
3589 case DW_FORM_line_strp
:
3590 case DW_FORM_sec_offset
:
3591 case DW_FORM_GNU_ref_alt
:
3592 case DW_FORM_GNU_strp_alt
:
3593 data
+= offset_size
;
3599 case DW_FORM_addrx1
:
3605 case DW_FORM_addrx2
:
3609 case DW_FORM_addrx3
:
3612 case DW_FORM_ref_sup4
:
3616 case DW_FORM_addrx4
:
3619 case DW_FORM_ref_sup8
:
3622 case DW_FORM_ref_sig8
:
3625 case DW_FORM_data16
:
3629 READ_SLEB (stemp
, data
, end
);
3631 case DW_FORM_GNU_str_index
:
3633 case DW_FORM_ref_udata
:
3635 case DW_FORM_GNU_addr_index
:
3637 case DW_FORM_loclistx
:
3638 case DW_FORM_rnglistx
:
3639 READ_ULEB (temp
, data
, end
);
3642 case DW_FORM_indirect
:
3643 while (form
== DW_FORM_indirect
)
3644 READ_ULEB (form
, data
, end
);
3645 return skip_attribute (form
, data
, end
, pointer_size
, offset_size
, dwarf_version
);
3647 case DW_FORM_string
:
3648 data
+= strnlen ((char *) data
, end
- data
);
3651 case DW_FORM_exprloc
:
3652 READ_ULEB (temp
, data
, end
);
3655 case DW_FORM_block1
:
3656 SAFE_BYTE_GET_AND_INC (temp
, data
, 1, end
);
3659 case DW_FORM_block2
:
3660 SAFE_BYTE_GET_AND_INC (temp
, data
, 2, end
);
3663 case DW_FORM_block4
:
3664 SAFE_BYTE_GET_AND_INC (temp
, data
, 4, end
);
3667 case DW_FORM_implicit_const
:
3668 case DW_FORM_flag_present
:
3671 warn (_("Unexpected form in top DIE\n"));
3678 read_bases (abbrev_entry
* entry
,
3679 unsigned char * data
,
3680 unsigned char * end
,
3681 int64_t pointer_size
,
3682 uint64_t offset_size
,
3684 debug_info
* debug_info_p
)
3688 for (attr
= entry
->first_attr
;
3689 attr
&& attr
->attribute
;
3694 if (attr
->attribute
== DW_AT_rnglists_base
)
3696 if (attr
->form
== DW_FORM_sec_offset
)
3698 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
3699 debug_info_p
->rnglists_base
= uvalue
;
3702 warn (_("Unexpected form of DW_AT_rnglists_base in the top DIE\n"));
3704 else if (attr
->attribute
== DW_AT_addr_base
|| attr
->attribute
== DW_AT_GNU_addr_base
)
3706 if (attr
->form
== DW_FORM_sec_offset
)
3708 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
3709 debug_info_p
->addr_base
= uvalue
;
3712 warn (_("Unexpected form of DW_AT_addr_base in the top DIE\n"));
3715 data
= skip_attribute (attr
->form
, data
, end
, pointer_size
,
3716 offset_size
, dwarf_version
);
3720 /* Process the contents of a .debug_info section.
3721 If do_loc is TRUE then we are scanning for location lists and dwo tags
3722 and we do not want to display anything to the user.
3723 If do_types is TRUE, we are processing a .debug_types section instead of
3724 a .debug_info section.
3725 The information displayed is restricted by the values in DWARF_START_DIE
3726 and DWARF_CUTOFF_LEVEL.
3727 Returns TRUE upon success. Otherwise an error or warning message is
3728 printed and FALSE is returned. */
3731 process_debug_info (struct dwarf_section
* section
,
3733 enum dwarf_section_display_enum abbrev_sec
,
3737 unsigned char *start
= section
->start
;
3738 unsigned char *end
= start
+ section
->size
;
3739 unsigned char *section_begin
;
3741 unsigned int num_units
= 0;
3743 /* First scan the section to get the number of comp units.
3744 Length sanity checks are done here. */
3745 for (section_begin
= start
, num_units
= 0; section_begin
< end
;
3750 /* Read the first 4 bytes. For a 32-bit DWARF section, this
3751 will be the length. For a 64-bit DWARF section, it'll be
3752 the escape code 0xffffffff followed by an 8 byte length. */
3753 SAFE_BYTE_GET_AND_INC (length
, section_begin
, 4, end
);
3755 if (length
== 0xffffffff)
3756 SAFE_BYTE_GET_AND_INC (length
, section_begin
, 8, end
);
3757 else if (length
>= 0xfffffff0 && length
< 0xffffffff)
3759 warn (_("Reserved length value (%#" PRIx64
") found in section %s\n"),
3760 length
, section
->name
);
3764 /* Negative values are illegal, they may even cause infinite
3765 looping. This can happen if we can't accurately apply
3766 relocations to an object file, or if the file is corrupt. */
3767 if (length
> (size_t) (end
- section_begin
))
3769 warn (_("Corrupt unit length (got %#" PRIx64
3770 " expected at most %#tx) in section %s\n"),
3771 length
, end
- section_begin
, section
->name
);
3774 section_begin
+= length
;
3779 error (_("No comp units in %s section ?\n"), section
->name
);
3783 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
|| do_debug_info
)
3784 && num_debug_info_entries
== 0
3788 /* Then allocate an array to hold the information. */
3789 debug_information
= (debug_info
*) cmalloc (num_units
,
3790 sizeof (* debug_information
));
3791 if (debug_information
== NULL
)
3793 error (_("Not enough memory for a debug info array of %u entries\n"),
3795 alloc_num_debug_info_entries
= num_debug_info_entries
= 0;
3799 /* PR 17531: file: 92ca3797.
3800 We cannot rely upon the debug_information array being initialised
3801 before it is used. A corrupt file could easily contain references
3802 to a unit for which information has not been made available. So
3803 we ensure that the array is zeroed here. */
3804 memset (debug_information
, 0, num_units
* sizeof (*debug_information
));
3806 alloc_num_debug_info_entries
= num_units
;
3811 load_debug_section_with_follow (str
, file
);
3812 load_debug_section_with_follow (line_str
, file
);
3813 load_debug_section_with_follow (str_dwo
, file
);
3814 load_debug_section_with_follow (str_index
, file
);
3815 load_debug_section_with_follow (str_index_dwo
, file
);
3816 load_debug_section_with_follow (debug_addr
, file
);
3819 load_debug_section_with_follow (abbrev_sec
, file
);
3820 load_debug_section_with_follow (loclists
, file
);
3821 load_debug_section_with_follow (rnglists
, file
);
3822 load_debug_section_with_follow (loclists_dwo
, file
);
3823 load_debug_section_with_follow (rnglists_dwo
, file
);
3825 if (debug_displays
[abbrev_sec
].section
.start
== NULL
)
3827 warn (_("Unable to locate %s section!\n"),
3828 debug_displays
[abbrev_sec
].section
.uncompressed_name
);
3832 if (!do_loc
&& dwarf_start_die
== 0)
3833 introduce (section
, false);
3835 free_all_abbrevs ();
3837 /* In order to be able to resolve DW_FORM_ref_addr forms we need
3838 to load *all* of the abbrevs for all CUs in this .debug_info
3839 section. This does effectively mean that we (partially) read
3840 every CU header twice. */
3841 for (section_begin
= start
; start
< end
;)
3843 DWARF2_Internal_CompUnit compunit
;
3844 unsigned char *hdrptr
;
3845 uint64_t abbrev_base
;
3848 unsigned int offset_size
;
3849 struct cu_tu_set
*this_set
;
3850 unsigned char *end_cu
;
3853 cu_offset
= start
- section_begin
;
3855 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 4, end
);
3857 if (compunit
.cu_length
== 0xffffffff)
3859 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 8, end
);
3864 end_cu
= hdrptr
+ compunit
.cu_length
;
3866 SAFE_BYTE_GET_AND_INC (compunit
.cu_version
, hdrptr
, 2, end_cu
);
3868 this_set
= find_cu_tu_set_v2 (cu_offset
, do_types
);
3870 if (compunit
.cu_version
< 5)
3872 compunit
.cu_unit_type
= DW_UT_compile
;
3873 /* Initialize it due to a false compiler warning. */
3874 compunit
.cu_pointer_size
= -1;
3878 SAFE_BYTE_GET_AND_INC (compunit
.cu_unit_type
, hdrptr
, 1, end_cu
);
3879 do_types
= (compunit
.cu_unit_type
== DW_UT_type
);
3881 SAFE_BYTE_GET_AND_INC (compunit
.cu_pointer_size
, hdrptr
, 1, end_cu
);
3884 SAFE_BYTE_GET_AND_INC (compunit
.cu_abbrev_offset
, hdrptr
, offset_size
,
3887 if (compunit
.cu_unit_type
== DW_UT_split_compile
3888 || compunit
.cu_unit_type
== DW_UT_skeleton
)
3891 SAFE_BYTE_GET_AND_INC (dwo_id
, hdrptr
, 8, end_cu
);
3894 if (this_set
== NULL
)
3897 abbrev_size
= debug_displays
[abbrev_sec
].section
.size
;
3901 abbrev_base
= this_set
->section_offsets
[DW_SECT_ABBREV
];
3902 abbrev_size
= this_set
->section_sizes
[DW_SECT_ABBREV
];
3906 abbrev_list
*free_list
;
3907 list
= find_and_process_abbrev_set (&debug_displays
[abbrev_sec
].section
,
3908 abbrev_base
, abbrev_size
,
3909 compunit
.cu_abbrev_offset
,
3912 if (list
!= NULL
&& list
->first_abbrev
!= NULL
)
3913 record_abbrev_list_for_cu (cu_offset
, start
- section_begin
,
3915 else if (free_list
!= NULL
)
3916 free_abbrev_list (free_list
);
3919 for (start
= section_begin
, unit
= 0; start
< end
; unit
++)
3921 DWARF2_Internal_CompUnit compunit
;
3922 unsigned char *hdrptr
;
3923 unsigned char *tags
;
3924 int level
, last_level
, saved_level
;
3926 unsigned int offset_size
;
3927 uint64_t signature
= 0;
3928 uint64_t type_offset
= 0;
3929 struct cu_tu_set
*this_set
;
3930 uint64_t abbrev_base
;
3932 unsigned char *end_cu
;
3935 cu_offset
= start
- section_begin
;
3937 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 4, end
);
3939 if (compunit
.cu_length
== 0xffffffff)
3941 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 8, end
);
3946 end_cu
= hdrptr
+ compunit
.cu_length
;
3948 SAFE_BYTE_GET_AND_INC (compunit
.cu_version
, hdrptr
, 2, end_cu
);
3950 this_set
= find_cu_tu_set_v2 (cu_offset
, do_types
);
3952 if (compunit
.cu_version
< 5)
3954 compunit
.cu_unit_type
= DW_UT_compile
;
3955 /* Initialize it due to a false compiler warning. */
3956 compunit
.cu_pointer_size
= -1;
3960 SAFE_BYTE_GET_AND_INC (compunit
.cu_unit_type
, hdrptr
, 1, end_cu
);
3961 do_types
= (compunit
.cu_unit_type
== DW_UT_type
);
3963 SAFE_BYTE_GET_AND_INC (compunit
.cu_pointer_size
, hdrptr
, 1, end_cu
);
3966 SAFE_BYTE_GET_AND_INC (compunit
.cu_abbrev_offset
, hdrptr
, offset_size
, end_cu
);
3968 if (this_set
== NULL
)
3971 abbrev_size
= debug_displays
[abbrev_sec
].section
.size
;
3975 abbrev_base
= this_set
->section_offsets
[DW_SECT_ABBREV
];
3976 abbrev_size
= this_set
->section_sizes
[DW_SECT_ABBREV
];
3979 if (compunit
.cu_version
< 5)
3980 SAFE_BYTE_GET_AND_INC (compunit
.cu_pointer_size
, hdrptr
, 1, end_cu
);
3982 bool do_dwo_id
= false;
3983 uint64_t dwo_id
= 0;
3984 if (compunit
.cu_unit_type
== DW_UT_split_compile
3985 || compunit
.cu_unit_type
== DW_UT_skeleton
)
3987 SAFE_BYTE_GET_AND_INC (dwo_id
, hdrptr
, 8, end_cu
);
3991 /* PR 17512: file: 001-108546-0.001:0.1. */
3992 if (compunit
.cu_pointer_size
< 2 || compunit
.cu_pointer_size
> 8)
3994 warn (_("Invalid pointer size (%d) in compunit header, using %d instead\n"),
3995 compunit
.cu_pointer_size
, offset_size
);
3996 compunit
.cu_pointer_size
= offset_size
;
4001 SAFE_BYTE_GET_AND_INC (signature
, hdrptr
, 8, end_cu
);
4002 SAFE_BYTE_GET_AND_INC (type_offset
, hdrptr
, offset_size
, end_cu
);
4005 if (dwarf_start_die
>= (size_t) (end_cu
- section_begin
))
4011 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
|| do_debug_info
)
4012 && num_debug_info_entries
== 0
4013 && alloc_num_debug_info_entries
> unit
4016 free_debug_information (&debug_information
[unit
]);
4017 memset (&debug_information
[unit
], 0, sizeof (*debug_information
));
4018 debug_information
[unit
].pointer_size
= compunit
.cu_pointer_size
;
4019 debug_information
[unit
].offset_size
= offset_size
;
4020 debug_information
[unit
].dwarf_version
= compunit
.cu_version
;
4021 debug_information
[unit
].cu_offset
= cu_offset
;
4022 debug_information
[unit
].addr_base
= DEBUG_INFO_UNAVAILABLE
;
4023 debug_information
[unit
].ranges_base
= DEBUG_INFO_UNAVAILABLE
;
4026 if (!do_loc
&& dwarf_start_die
== 0)
4028 printf (_(" Compilation Unit @ offset %#" PRIx64
":\n"),
4030 printf (_(" Length: %#" PRIx64
" (%s)\n"),
4032 offset_size
== 8 ? "64-bit" : "32-bit");
4033 printf (_(" Version: %d\n"), compunit
.cu_version
);
4034 if (compunit
.cu_version
>= 5)
4036 const char *name
= get_DW_UT_name (compunit
.cu_unit_type
);
4038 printf (_(" Unit Type: %s (%x)\n"),
4040 compunit
.cu_unit_type
);
4042 printf (_(" Abbrev Offset: %#" PRIx64
"\n"),
4043 compunit
.cu_abbrev_offset
);
4044 printf (_(" Pointer Size: %d\n"), compunit
.cu_pointer_size
);
4047 printf (_(" Signature: %#" PRIx64
"\n"), signature
);
4048 printf (_(" Type Offset: %#" PRIx64
"\n"), type_offset
);
4051 printf (_(" DWO ID: %#" PRIx64
"\n"), dwo_id
);
4052 if (this_set
!= NULL
)
4054 uint64_t *offsets
= this_set
->section_offsets
;
4055 size_t *sizes
= this_set
->section_sizes
;
4057 printf (_(" Section contributions:\n"));
4058 printf (_(" .debug_abbrev.dwo: %#" PRIx64
" %#zx\n"),
4059 offsets
[DW_SECT_ABBREV
], sizes
[DW_SECT_ABBREV
]);
4060 printf (_(" .debug_line.dwo: %#" PRIx64
" %#zx\n"),
4061 offsets
[DW_SECT_LINE
], sizes
[DW_SECT_LINE
]);
4062 printf (_(" .debug_loc.dwo: %#" PRIx64
" %#zx\n"),
4063 offsets
[DW_SECT_LOC
], sizes
[DW_SECT_LOC
]);
4064 printf (_(" .debug_str_offsets.dwo: %#" PRIx64
" %#zx\n"),
4065 offsets
[DW_SECT_STR_OFFSETS
], sizes
[DW_SECT_STR_OFFSETS
]);
4072 if (compunit
.cu_version
< 2 || compunit
.cu_version
> 5)
4074 warn (_("CU at offset %#" PRIx64
" contains corrupt or "
4075 "unsupported version number: %d.\n"),
4076 cu_offset
, compunit
.cu_version
);
4080 if (compunit
.cu_unit_type
!= DW_UT_compile
4081 && compunit
.cu_unit_type
!= DW_UT_partial
4082 && compunit
.cu_unit_type
!= DW_UT_type
4083 && compunit
.cu_unit_type
!= DW_UT_split_compile
4084 && compunit
.cu_unit_type
!= DW_UT_skeleton
)
4086 warn (_("CU at offset %#" PRIx64
" contains corrupt or "
4087 "unsupported unit type: %d.\n"),
4088 cu_offset
, compunit
.cu_unit_type
);
4092 /* Process the abbrevs used by this compilation unit. */
4094 list
= find_and_process_abbrev_set (&debug_displays
[abbrev_sec
].section
,
4095 abbrev_base
, abbrev_size
,
4096 compunit
.cu_abbrev_offset
, NULL
);
4100 while (tags
< start
)
4102 unsigned long abbrev_number
;
4103 unsigned long die_offset
;
4104 abbrev_entry
*entry
;
4106 int do_printing
= 1;
4108 die_offset
= tags
- section_begin
;
4110 READ_ULEB (abbrev_number
, tags
, start
);
4112 /* A null DIE marks the end of a list of siblings or it may also be
4113 a section padding. */
4114 if (abbrev_number
== 0)
4116 /* Check if it can be a section padding for the last CU. */
4117 if (level
== 0 && start
== end
)
4121 for (chk
= tags
; chk
< start
; chk
++)
4128 if (!do_loc
&& die_offset
>= dwarf_start_die
4129 && (dwarf_cutoff_level
== -1
4130 || level
< dwarf_cutoff_level
))
4131 printf (_(" <%d><%lx>: Abbrev Number: 0\n"),
4137 static unsigned num_bogus_warns
= 0;
4139 if (num_bogus_warns
< 3)
4141 warn (_("Bogus end-of-siblings marker detected at offset %lx in %s section\n"),
4142 die_offset
, section
->name
);
4144 if (num_bogus_warns
== 3)
4145 warn (_("Further warnings about bogus end-of-sibling markers suppressed\n"));
4148 if (dwarf_start_die
!= 0 && level
< saved_level
)
4151 free_abbrev_list (list
);
4159 if (dwarf_start_die
!= 0 && die_offset
< dwarf_start_die
)
4163 if (dwarf_start_die
!= 0 && die_offset
== dwarf_start_die
)
4164 saved_level
= level
;
4165 do_printing
= (dwarf_cutoff_level
== -1
4166 || level
< dwarf_cutoff_level
);
4168 printf (_(" <%d><%lx>: Abbrev Number: %lu"),
4169 level
, die_offset
, abbrev_number
);
4170 else if (dwarf_cutoff_level
== -1
4171 || last_level
< dwarf_cutoff_level
)
4172 printf (_(" <%d><%lx>: ...\n"), level
, die_offset
);
4177 /* Scan through the abbreviation list until we reach the
4181 for (entry
= list
->first_abbrev
; entry
!= NULL
; entry
= entry
->next
)
4182 if (entry
->number
== abbrev_number
)
4187 if (!do_loc
&& do_printing
)
4192 warn (_("DIE at offset %#lx refers to abbreviation number %lu which does not exist\n"),
4193 die_offset
, abbrev_number
);
4195 free_abbrev_list (list
);
4199 if (!do_loc
&& do_printing
)
4200 printf (" (%s)\n", get_TAG_name (entry
->tag
));
4205 need_base_address
= 0;
4207 case DW_TAG_compile_unit
:
4208 case DW_TAG_skeleton_unit
:
4209 need_base_address
= 1;
4210 need_dwo_info
= do_loc
;
4212 case DW_TAG_entry_point
:
4213 need_base_address
= 0;
4214 /* Assuming that there is no DW_AT_frame_base. */
4215 have_frame_base
= 0;
4217 case DW_TAG_subprogram
:
4218 need_base_address
= 0;
4219 if (level
<= frame_base_level
)
4220 /* Don't reset that for nested subprogram. */
4221 have_frame_base
= 0;
4225 debug_info
*debug_info_p
=
4226 (debug_information
&& unit
< alloc_num_debug_info_entries
)
4227 ? debug_information
+ unit
: NULL
;
4229 assert (!debug_info_p
4230 || (debug_info_p
->num_loc_offsets
4231 == debug_info_p
->num_loc_views
));
4233 /* Look ahead so that the values of DW_AT_rnglists_base,
4234 DW_AT_[GNU_]addr_base are available before attributes that
4235 reference them are parsed in the same DIE.
4236 Only needed for the top DIE on DWARFv5+.
4237 No simiar treatment for loclists_base because there should
4238 be no loclist attributes in top DIE. */
4239 if (debug_info_p
&& compunit
.cu_version
>= 5 && level
== 0)
4246 compunit
.cu_pointer_size
,
4248 compunit
.cu_version
,
4251 /* This check was in place before, keep it. */
4252 stemp
= debug_info_p
->rnglists_base
;
4255 warn (_("CU @ %#" PRIx64
" has has a negative rnglists_base "
4256 "value of %#" PRIx64
" - treating as zero\n"),
4257 debug_info_p
->cu_offset
, stemp
);
4258 debug_info_p
->rnglists_base
= 0;
4262 for (attr
= entry
->first_attr
;
4263 attr
&& attr
->attribute
;
4266 if (! do_loc
&& do_printing
)
4267 /* Show the offset from where the tag was extracted. */
4268 printf (" <%tx>", tags
- section_begin
);
4269 tags
= read_and_display_attr (attr
->attribute
,
4271 attr
->implicit_const
,
4276 compunit
.cu_pointer_size
,
4278 compunit
.cu_version
,
4280 do_loc
|| ! do_printing
,
4286 /* If a locview attribute appears before a location one,
4287 make sure we don't associate it with an earlier
4290 switch (debug_info_p
->num_loc_offsets
- debug_info_p
->num_loc_views
)
4293 debug_info_p
->loc_views
[debug_info_p
->num_loc_views
] = -1;
4294 debug_info_p
->num_loc_views
++;
4295 assert (debug_info_p
->num_loc_views
4296 == debug_info_p
->num_loc_offsets
);
4303 warn (_("DIE has locviews without loclist\n"));
4304 debug_info_p
->num_loc_views
--;
4311 if (entry
->children
)
4315 free_abbrev_list (list
);
4318 /* Set num_debug_info_entries here so that it can be used to check if
4319 we need to process .debug_loc and .debug_ranges sections. */
4320 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
|| do_debug_info
)
4321 && num_debug_info_entries
== 0
4324 if (num_units
> alloc_num_debug_info_entries
)
4325 num_debug_info_entries
= alloc_num_debug_info_entries
;
4327 num_debug_info_entries
= num_units
;
4336 /* Locate and scan the .debug_info section in the file and record the pointer
4337 sizes and offsets for the compilation units in it. Usually an executable
4338 will have just one pointer size, but this is not guaranteed, and so we try
4339 not to make any assumptions. Returns zero upon failure, or the number of
4340 compilation units upon success. */
4343 load_debug_info (void * file
)
4345 /* If we have already tried and failed to load the .debug_info
4346 section then do not bother to repeat the task. */
4347 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
4350 /* If we already have the information there is nothing else to do. */
4351 if (num_debug_info_entries
> 0)
4352 return num_debug_info_entries
;
4354 /* If this is a DWARF package file, load the CU and TU indexes. */
4355 (void) load_cu_tu_indexes (file
);
4357 if (load_debug_section_with_follow (info
, file
)
4358 && process_debug_info (&debug_displays
[info
].section
, file
, abbrev
, true, false))
4359 return num_debug_info_entries
;
4361 if (load_debug_section_with_follow (info_dwo
, file
)
4362 && process_debug_info (&debug_displays
[info_dwo
].section
, file
,
4363 abbrev_dwo
, true, false))
4364 return num_debug_info_entries
;
4366 num_debug_info_entries
= DEBUG_INFO_UNAVAILABLE
;
4370 /* Read a DWARF .debug_line section header starting at DATA.
4371 Upon success returns an updated DATA pointer and the LINFO
4372 structure and the END_OF_SEQUENCE pointer will be filled in.
4373 Otherwise returns NULL. */
4375 static unsigned char *
4376 read_debug_line_header (struct dwarf_section
* section
,
4377 unsigned char * data
,
4378 unsigned char * end
,
4379 DWARF2_Internal_LineInfo
* linfo
,
4380 unsigned char ** end_of_sequence
)
4382 unsigned char *hdrptr
;
4384 /* Extract information from the Line Number Program Header.
4385 (section 6.2.4 in the Dwarf3 doc). */
4388 /* Get and check the length of the block. */
4389 SAFE_BYTE_GET_AND_INC (linfo
->li_length
, hdrptr
, 4, end
);
4391 if (linfo
->li_length
== 0xffffffff)
4393 /* This section is 64-bit DWARF 3. */
4394 SAFE_BYTE_GET_AND_INC (linfo
->li_length
, hdrptr
, 8, end
);
4395 linfo
->li_offset_size
= 8;
4398 linfo
->li_offset_size
= 4;
4400 if (linfo
->li_length
> (size_t) (end
- hdrptr
))
4402 /* If the length field has a relocation against it, then we should
4403 not complain if it is inaccurate (and probably negative). This
4404 happens in object files when the .debug_line section is actually
4405 comprised of several different .debug_line.* sections, (some of
4406 which may be removed by linker garbage collection), and a relocation
4407 is used to compute the correct length once that is done. */
4408 if (reloc_at (section
, (hdrptr
- section
->start
) - linfo
->li_offset_size
))
4410 linfo
->li_length
= end
- hdrptr
;
4414 warn (_("The length field (%#" PRIx64
")"
4415 " in the debug_line header is wrong"
4416 " - the section is too small\n"),
4421 end
= hdrptr
+ linfo
->li_length
;
4423 /* Get and check the version number. */
4424 SAFE_BYTE_GET_AND_INC (linfo
->li_version
, hdrptr
, 2, end
);
4426 if (linfo
->li_version
!= 2
4427 && linfo
->li_version
!= 3
4428 && linfo
->li_version
!= 4
4429 && linfo
->li_version
!= 5)
4431 warn (_("Only DWARF version 2, 3, 4 and 5 line info "
4432 "is currently supported.\n"));
4436 if (linfo
->li_version
>= 5)
4438 SAFE_BYTE_GET_AND_INC (linfo
->li_address_size
, hdrptr
, 1, end
);
4440 SAFE_BYTE_GET_AND_INC (linfo
->li_segment_size
, hdrptr
, 1, end
);
4441 if (linfo
->li_segment_size
!= 0)
4443 warn (_("The %s section contains "
4444 "unsupported segment selector size: %d.\n"),
4445 section
->name
, linfo
->li_segment_size
);
4450 SAFE_BYTE_GET_AND_INC (linfo
->li_prologue_length
, hdrptr
,
4451 linfo
->li_offset_size
, end
);
4452 SAFE_BYTE_GET_AND_INC (linfo
->li_min_insn_length
, hdrptr
, 1, end
);
4454 if (linfo
->li_version
>= 4)
4456 SAFE_BYTE_GET_AND_INC (linfo
->li_max_ops_per_insn
, hdrptr
, 1, end
);
4458 if (linfo
->li_max_ops_per_insn
== 0)
4460 warn (_("Invalid maximum operations per insn.\n"));
4465 linfo
->li_max_ops_per_insn
= 1;
4467 SAFE_BYTE_GET_AND_INC (linfo
->li_default_is_stmt
, hdrptr
, 1, end
);
4468 SAFE_SIGNED_BYTE_GET_AND_INC (linfo
->li_line_base
, hdrptr
, 1, end
);
4469 SAFE_BYTE_GET_AND_INC (linfo
->li_line_range
, hdrptr
, 1, end
);
4470 SAFE_BYTE_GET_AND_INC (linfo
->li_opcode_base
, hdrptr
, 1, end
);
4472 *end_of_sequence
= end
;
4476 static unsigned char *
4477 display_formatted_table (unsigned char *data
,
4478 unsigned char *start
,
4480 const DWARF2_Internal_LineInfo
*linfo
,
4481 struct dwarf_section
*section
,
4484 unsigned char *format_start
, format_count
, *format
, formati
;
4485 uint64_t data_count
, datai
;
4486 unsigned int namepass
, last_entry
= 0;
4487 const char * table_name
= is_dir
? N_("Directory Table") : N_("File Name Table");
4489 SAFE_BYTE_GET_AND_INC (format_count
, data
, 1, end
);
4490 if (do_checks
&& format_count
> 5)
4491 warn (_("Unexpectedly large number of columns in the %s (%u)\n"),
4492 table_name
, format_count
);
4494 format_start
= data
;
4495 for (formati
= 0; formati
< format_count
; formati
++)
4497 SKIP_ULEB (data
, end
);
4498 SKIP_ULEB (data
, end
);
4501 warn (_("%s: Corrupt format description entry\n"), table_name
);
4506 READ_ULEB (data_count
, data
, end
);
4507 if (data_count
== 0)
4509 printf (_("\n The %s is empty.\n"), table_name
);
4512 else if (data
>= end
4513 || data_count
> (size_t) (end
- data
))
4515 warn (_("%s: Corrupt entry count %#" PRIx64
"\n"), table_name
, data_count
);
4519 else if (format_count
== 0)
4521 warn (_("%s: format count is zero, but the table is not empty\n"),
4526 printf (_("\n The %s (offset %#tx, lines %" PRIu64
", columns %u):\n"),
4527 table_name
, data
- start
, data_count
, format_count
);
4529 printf (_(" Entry"));
4530 /* Delay displaying name as the last entry for better screen layout. */
4531 for (namepass
= 0; namepass
< 2; namepass
++)
4533 format
= format_start
;
4534 for (formati
= 0; formati
< format_count
; formati
++)
4536 uint64_t content_type
;
4538 READ_ULEB (content_type
, format
, end
);
4539 if ((content_type
== DW_LNCT_path
) == (namepass
== 1))
4540 switch (content_type
)
4543 printf (_("\tName"));
4545 case DW_LNCT_directory_index
:
4546 printf (_("\tDir"));
4548 case DW_LNCT_timestamp
:
4549 printf (_("\tTime"));
4552 printf (_("\tSize"));
4555 printf (_("\tMD5\t\t\t"));
4558 printf (_("\t(Unknown format content type %" PRIu64
")"),
4561 SKIP_ULEB (format
, end
);
4566 for (datai
= 0; datai
< data_count
; datai
++)
4568 unsigned char *datapass
= data
;
4570 printf (" %d", last_entry
++);
4571 /* Delay displaying name as the last entry for better screen layout. */
4572 for (namepass
= 0; namepass
< 2; namepass
++)
4574 format
= format_start
;
4576 for (formati
= 0; formati
< format_count
; formati
++)
4578 uint64_t content_type
, form
;
4580 READ_ULEB (content_type
, format
, end
);
4581 READ_ULEB (form
, format
, end
);
4582 data
= read_and_display_attr_value (0, form
, 0, start
, data
, end
,
4583 0, 0, linfo
->li_offset_size
,
4584 linfo
->li_version
, NULL
,
4585 ((content_type
== DW_LNCT_path
) != (namepass
== 1)),
4586 section
, NULL
, '\t', -1);
4590 if (data
>= end
&& (datai
< data_count
- 1))
4592 warn (_("\n%s: Corrupt entries list\n"), table_name
);
4601 display_debug_sup (struct dwarf_section
* section
,
4602 void * file ATTRIBUTE_UNUSED
)
4604 unsigned char * start
= section
->start
;
4605 unsigned char * end
= section
->start
+ section
->size
;
4606 unsigned int version
;
4607 char is_supplementary
;
4608 const unsigned char * sup_filename
;
4609 size_t sup_filename_len
;
4610 unsigned int num_read
;
4612 uint64_t checksum_len
;
4615 introduce (section
, true);
4616 if (section
->size
< 4)
4618 error (_("corrupt .debug_sup section: size is too small\n"));
4622 /* Read the data. */
4623 SAFE_BYTE_GET_AND_INC (version
, start
, 2, end
);
4625 warn (_("corrupt .debug_sup section: version < 5\n"));
4627 SAFE_BYTE_GET_AND_INC (is_supplementary
, start
, 1, end
);
4628 if (is_supplementary
!= 0 && is_supplementary
!= 1)
4629 warn (_("corrupt .debug_sup section: is_supplementary not 0 or 1\n"));
4631 sup_filename
= start
;
4632 if (is_supplementary
&& sup_filename
[0] != 0)
4633 warn (_("corrupt .debug_sup section: filename not empty in supplementary section\n"));
4635 sup_filename_len
= strnlen ((const char *) start
, end
- start
);
4636 if (sup_filename_len
== (size_t) (end
- start
))
4638 error (_("corrupt .debug_sup section: filename is not NUL terminated\n"));
4641 start
+= sup_filename_len
+ 1;
4643 checksum_len
= read_leb128 (start
, end
, false /* unsigned */, & num_read
, & status
);
4646 error (_("corrupt .debug_sup section: bad LEB128 field for checksum length\n"));
4650 if (checksum_len
> (size_t) (end
- start
))
4652 error (_("corrupt .debug_sup section: checksum length is longer than the remaining section length\n"));
4653 checksum_len
= end
- start
;
4655 else if (checksum_len
< (size_t) (end
- start
))
4657 warn (_("corrupt .debug_sup section: there are %#" PRIx64
4658 " extra, unused bytes at the end of the section\n"),
4659 (end
- start
) - checksum_len
);
4662 printf (_(" Version: %u\n"), version
);
4663 printf (_(" Is Supp: %u\n"), is_supplementary
);
4664 printf (_(" Filename: %s\n"), sup_filename
);
4665 printf (_(" Checksum Len: %" PRIu64
"\n"), checksum_len
);
4666 if (checksum_len
> 0)
4668 printf (_(" Checksum: "));
4669 while (checksum_len
--)
4670 printf ("0x%x ", * start
++ );
4677 display_debug_lines_raw (struct dwarf_section
* section
,
4678 unsigned char * data
,
4679 unsigned char * end
,
4682 unsigned char *start
= section
->start
;
4683 int verbose_view
= 0;
4685 introduce (section
, true);
4689 static DWARF2_Internal_LineInfo saved_linfo
;
4690 DWARF2_Internal_LineInfo linfo
;
4691 unsigned char *standard_opcodes
;
4692 unsigned char *end_of_sequence
;
4695 if (startswith (section
->name
, ".debug_line.")
4696 /* Note: the following does not apply to .debug_line.dwo sections.
4697 These are full debug_line sections. */
4698 && strcmp (section
->name
, ".debug_line.dwo") != 0)
4700 /* Sections named .debug_line.<foo> are fragments of a .debug_line
4701 section containing just the Line Number Statements. They are
4702 created by the assembler and intended to be used alongside gcc's
4703 -ffunction-sections command line option. When the linker's
4704 garbage collection decides to discard a .text.<foo> section it
4705 can then also discard the line number information in .debug_line.<foo>.
4707 Since the section is a fragment it does not have the details
4708 needed to fill out a LineInfo structure, so instead we use the
4709 details from the last full debug_line section that we processed. */
4710 end_of_sequence
= end
;
4711 standard_opcodes
= NULL
;
4712 linfo
= saved_linfo
;
4713 /* PR 17531: file: 0522b371. */
4714 if (linfo
.li_line_range
== 0)
4716 warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n"));
4719 reset_state_machine (linfo
.li_default_is_stmt
);
4723 unsigned char * hdrptr
;
4725 if ((hdrptr
= read_debug_line_header (section
, data
, end
, & linfo
,
4726 & end_of_sequence
)) == NULL
)
4729 printf (_(" Offset: %#tx\n"), data
- start
);
4730 printf (_(" Length: %" PRId64
"\n"), linfo
.li_length
);
4731 printf (_(" DWARF Version: %d\n"), linfo
.li_version
);
4732 if (linfo
.li_version
>= 5)
4734 printf (_(" Address size (bytes): %d\n"), linfo
.li_address_size
);
4735 printf (_(" Segment selector (bytes): %d\n"), linfo
.li_segment_size
);
4737 printf (_(" Prologue Length: %d\n"), (int) linfo
.li_prologue_length
);
4738 printf (_(" Minimum Instruction Length: %d\n"), linfo
.li_min_insn_length
);
4739 if (linfo
.li_version
>= 4)
4740 printf (_(" Maximum Ops per Instruction: %d\n"), linfo
.li_max_ops_per_insn
);
4741 printf (_(" Initial value of 'is_stmt': %d\n"), linfo
.li_default_is_stmt
);
4742 printf (_(" Line Base: %d\n"), linfo
.li_line_base
);
4743 printf (_(" Line Range: %d\n"), linfo
.li_line_range
);
4744 printf (_(" Opcode Base: %d\n"), linfo
.li_opcode_base
);
4746 /* PR 17512: file: 1665-6428-0.004. */
4747 if (linfo
.li_line_range
== 0)
4749 warn (_("Line range of 0 is invalid, using 1 instead\n"));
4750 linfo
.li_line_range
= 1;
4753 reset_state_machine (linfo
.li_default_is_stmt
);
4755 /* Display the contents of the Opcodes table. */
4756 standard_opcodes
= hdrptr
;
4758 /* PR 17512: file: 002-417945-0.004. */
4759 if (standard_opcodes
+ linfo
.li_opcode_base
>= end
)
4761 warn (_("Line Base extends beyond end of section\n"));
4765 printf (_("\n Opcodes:\n"));
4767 for (i
= 1; i
< linfo
.li_opcode_base
; i
++)
4768 printf (ngettext (" Opcode %d has %d arg\n",
4769 " Opcode %d has %d args\n",
4770 standard_opcodes
[i
- 1]),
4771 i
, standard_opcodes
[i
- 1]);
4773 /* Display the contents of the Directory table. */
4774 data
= standard_opcodes
+ linfo
.li_opcode_base
- 1;
4776 if (linfo
.li_version
>= 5)
4778 load_debug_section_with_follow (line_str
, file
);
4780 data
= display_formatted_table (data
, start
, end
, &linfo
, section
,
4782 data
= display_formatted_table (data
, start
, end
, &linfo
, section
,
4788 printf (_("\n The Directory Table is empty.\n"));
4791 unsigned int last_dir_entry
= 0;
4793 printf (_("\n The Directory Table (offset %#tx):\n"),
4796 while (data
< end
&& *data
!= 0)
4798 printf (" %d\t%.*s\n", ++last_dir_entry
, (int) (end
- data
), data
);
4800 data
+= strnlen ((char *) data
, end
- data
);
4805 /* PR 17512: file: 002-132094-0.004. */
4806 if (data
>= end
- 1)
4810 /* Skip the NUL at the end of the table. */
4814 /* Display the contents of the File Name table. */
4815 if (data
>= end
|| *data
== 0)
4816 printf (_("\n The File Name Table is empty.\n"));
4819 printf (_("\n The File Name Table (offset %#tx):\n"),
4821 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
4823 while (data
< end
&& *data
!= 0)
4825 unsigned char *name
;
4828 printf (" %d\t", ++state_machine_regs
.last_file_entry
);
4830 data
+= strnlen ((char *) data
, end
- data
);
4834 READ_ULEB (val
, data
, end
);
4835 printf ("%" PRIu64
"\t", val
);
4836 READ_ULEB (val
, data
, end
);
4837 printf ("%" PRIu64
"\t", val
);
4838 READ_ULEB (val
, data
, end
);
4839 printf ("%" PRIu64
"\t", val
);
4840 printf ("%.*s\n", (int)(end
- name
), name
);
4844 warn (_("Corrupt file name table entry\n"));
4850 /* Skip the NUL at the end of the table. */
4856 saved_linfo
= linfo
;
4859 /* Now display the statements. */
4860 if (data
>= end_of_sequence
)
4861 printf (_(" No Line Number Statements.\n"));
4864 printf (_(" Line Number Statements:\n"));
4866 while (data
< end_of_sequence
)
4868 unsigned char op_code
;
4872 printf (" [0x%08tx]", data
- start
);
4876 if (op_code
>= linfo
.li_opcode_base
)
4878 op_code
-= linfo
.li_opcode_base
;
4879 uladv
= (op_code
/ linfo
.li_line_range
);
4880 if (linfo
.li_max_ops_per_insn
== 1)
4882 uladv
*= linfo
.li_min_insn_length
;
4883 state_machine_regs
.address
+= uladv
;
4885 state_machine_regs
.view
= 0;
4886 printf (_(" Special opcode %d: "
4887 "advance Address by %" PRIu64
4888 " to %#" PRIx64
"%s"),
4889 op_code
, uladv
, state_machine_regs
.address
,
4890 verbose_view
&& uladv
4891 ? _(" (reset view)") : "");
4896 = ((state_machine_regs
.op_index
+ uladv
)
4897 / linfo
.li_max_ops_per_insn
)
4898 * linfo
.li_min_insn_length
;
4900 state_machine_regs
.address
+= addrdelta
;
4901 state_machine_regs
.op_index
4902 = (state_machine_regs
.op_index
+ uladv
)
4903 % linfo
.li_max_ops_per_insn
;
4905 state_machine_regs
.view
= 0;
4906 printf (_(" Special opcode %d: "
4907 "advance Address by %" PRIu64
4908 " to %#" PRIx64
"[%d]%s"),
4909 op_code
, uladv
, state_machine_regs
.address
,
4910 state_machine_regs
.op_index
,
4911 verbose_view
&& addrdelta
4912 ? _(" (reset view)") : "");
4914 adv
= (op_code
% linfo
.li_line_range
) + linfo
.li_line_base
;
4915 state_machine_regs
.line
+= adv
;
4916 printf (_(" and Line by %d to %d"),
4917 adv
, state_machine_regs
.line
);
4918 if (verbose_view
|| state_machine_regs
.view
)
4919 printf (_(" (view %u)\n"), state_machine_regs
.view
);
4922 state_machine_regs
.view
++;
4927 case DW_LNS_extended_op
:
4928 data
+= process_extended_line_op (data
,
4929 linfo
.li_default_is_stmt
,
4934 printf (_(" Copy"));
4935 if (verbose_view
|| state_machine_regs
.view
)
4936 printf (_(" (view %u)\n"), state_machine_regs
.view
);
4939 state_machine_regs
.view
++;
4942 case DW_LNS_advance_pc
:
4943 READ_ULEB (uladv
, data
, end
);
4944 if (linfo
.li_max_ops_per_insn
== 1)
4946 uladv
*= linfo
.li_min_insn_length
;
4947 state_machine_regs
.address
+= uladv
;
4949 state_machine_regs
.view
= 0;
4950 printf (_(" Advance PC by %" PRIu64
4951 " to %#" PRIx64
"%s\n"),
4952 uladv
, state_machine_regs
.address
,
4953 verbose_view
&& uladv
4954 ? _(" (reset view)") : "");
4959 = ((state_machine_regs
.op_index
+ uladv
)
4960 / linfo
.li_max_ops_per_insn
)
4961 * linfo
.li_min_insn_length
;
4962 state_machine_regs
.address
4964 state_machine_regs
.op_index
4965 = (state_machine_regs
.op_index
+ uladv
)
4966 % linfo
.li_max_ops_per_insn
;
4968 state_machine_regs
.view
= 0;
4969 printf (_(" Advance PC by %" PRIu64
4970 " to %#" PRIx64
"[%d]%s\n"),
4971 uladv
, state_machine_regs
.address
,
4972 state_machine_regs
.op_index
,
4973 verbose_view
&& addrdelta
4974 ? _(" (reset view)") : "");
4978 case DW_LNS_advance_line
:
4979 READ_SLEB (adv
, data
, end
);
4980 state_machine_regs
.line
+= adv
;
4981 printf (_(" Advance Line by %d to %d\n"),
4982 adv
, state_machine_regs
.line
);
4985 case DW_LNS_set_file
:
4986 READ_ULEB (uladv
, data
, end
);
4987 printf (_(" Set File Name to entry %" PRIu64
4988 " in the File Name Table\n"), uladv
);
4989 state_machine_regs
.file
= uladv
;
4992 case DW_LNS_set_column
:
4993 READ_ULEB (uladv
, data
, end
);
4994 printf (_(" Set column to %" PRIu64
"\n"), uladv
);
4995 state_machine_regs
.column
= uladv
;
4998 case DW_LNS_negate_stmt
:
4999 adv
= state_machine_regs
.is_stmt
;
5001 printf (_(" Set is_stmt to %d\n"), adv
);
5002 state_machine_regs
.is_stmt
= adv
;
5005 case DW_LNS_set_basic_block
:
5006 printf (_(" Set basic block\n"));
5007 state_machine_regs
.basic_block
= 1;
5010 case DW_LNS_const_add_pc
:
5011 uladv
= ((255 - linfo
.li_opcode_base
) / linfo
.li_line_range
);
5012 if (linfo
.li_max_ops_per_insn
)
5014 uladv
*= linfo
.li_min_insn_length
;
5015 state_machine_regs
.address
+= uladv
;
5017 state_machine_regs
.view
= 0;
5018 printf (_(" Advance PC by constant %" PRIu64
5019 " to %#" PRIx64
"%s\n"),
5020 uladv
, state_machine_regs
.address
,
5021 verbose_view
&& uladv
5022 ? _(" (reset view)") : "");
5027 = ((state_machine_regs
.op_index
+ uladv
)
5028 / linfo
.li_max_ops_per_insn
)
5029 * linfo
.li_min_insn_length
;
5030 state_machine_regs
.address
5032 state_machine_regs
.op_index
5033 = (state_machine_regs
.op_index
+ uladv
)
5034 % linfo
.li_max_ops_per_insn
;
5036 state_machine_regs
.view
= 0;
5037 printf (_(" Advance PC by constant %" PRIu64
5038 " to %#" PRIx64
"[%d]%s\n"),
5039 uladv
, state_machine_regs
.address
,
5040 state_machine_regs
.op_index
,
5041 verbose_view
&& addrdelta
5042 ? _(" (reset view)") : "");
5046 case DW_LNS_fixed_advance_pc
:
5047 SAFE_BYTE_GET_AND_INC (uladv
, data
, 2, end
);
5048 state_machine_regs
.address
+= uladv
;
5049 state_machine_regs
.op_index
= 0;
5050 printf (_(" Advance PC by fixed size amount %" PRIu64
5051 " to %#" PRIx64
"\n"),
5052 uladv
, state_machine_regs
.address
);
5053 /* Do NOT reset view. */
5056 case DW_LNS_set_prologue_end
:
5057 printf (_(" Set prologue_end to true\n"));
5060 case DW_LNS_set_epilogue_begin
:
5061 printf (_(" Set epilogue_begin to true\n"));
5064 case DW_LNS_set_isa
:
5065 READ_ULEB (uladv
, data
, end
);
5066 printf (_(" Set ISA to %" PRIu64
"\n"), uladv
);
5070 printf (_(" Unknown opcode %d with operands: "), op_code
);
5072 if (standard_opcodes
!= NULL
)
5073 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
5075 READ_ULEB (uladv
, data
, end
);
5076 printf ("%#" PRIx64
"%s", uladv
, i
== 1 ? "" : ", ");
5092 unsigned int directory_index
;
5093 unsigned int modification_date
;
5094 unsigned int length
;
5097 /* Output a decoded representation of the .debug_line section. */
5100 display_debug_lines_decoded (struct dwarf_section
* section
,
5101 unsigned char * start
,
5102 unsigned char * data
,
5103 unsigned char * end
,
5106 static DWARF2_Internal_LineInfo saved_linfo
;
5108 introduce (section
, false);
5112 /* This loop amounts to one iteration per compilation unit. */
5113 DWARF2_Internal_LineInfo linfo
;
5114 unsigned char *standard_opcodes
;
5115 unsigned char *end_of_sequence
;
5117 File_Entry
*file_table
= NULL
;
5118 unsigned int n_files
= 0;
5119 char **directory_table
= NULL
;
5120 unsigned int n_directories
= 0;
5122 if (startswith (section
->name
, ".debug_line.")
5123 /* Note: the following does not apply to .debug_line.dwo sections.
5124 These are full debug_line sections. */
5125 && strcmp (section
->name
, ".debug_line.dwo") != 0)
5127 /* See comment in display_debug_lines_raw(). */
5128 end_of_sequence
= end
;
5129 standard_opcodes
= NULL
;
5130 linfo
= saved_linfo
;
5131 /* PR 17531: file: 0522b371. */
5132 if (linfo
.li_line_range
== 0)
5134 warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n"));
5137 reset_state_machine (linfo
.li_default_is_stmt
);
5141 unsigned char *hdrptr
;
5143 if ((hdrptr
= read_debug_line_header (section
, data
, end
, & linfo
,
5144 & end_of_sequence
)) == NULL
)
5147 /* PR 17531: file: 0522b371. */
5148 if (linfo
.li_line_range
== 0)
5150 warn (_("Line range of 0 is invalid, using 1 instead\n"));
5151 linfo
.li_line_range
= 1;
5153 reset_state_machine (linfo
.li_default_is_stmt
);
5155 /* Save a pointer to the contents of the Opcodes table. */
5156 standard_opcodes
= hdrptr
;
5158 /* Traverse the Directory table just to count entries. */
5159 data
= standard_opcodes
+ linfo
.li_opcode_base
- 1;
5163 warn (_("opcode base of %d extends beyond end of section\n"),
5164 linfo
.li_opcode_base
);
5168 if (linfo
.li_version
>= 5)
5170 unsigned char *format_start
, *format
;
5171 unsigned int format_count
, formati
, entryi
;
5173 load_debug_section_with_follow (line_str
, fileptr
);
5175 /* Skip directories format. */
5176 SAFE_BYTE_GET_AND_INC (format_count
, data
, 1, end
);
5177 if (do_checks
&& format_count
> 1)
5178 warn (_("Unexpectedly large number of columns in the directory name table (%u)\n"),
5180 format_start
= data
;
5181 for (formati
= 0; formati
< format_count
; formati
++)
5183 SKIP_ULEB (data
, end
);
5184 SKIP_ULEB (data
, end
);
5187 READ_ULEB (n_directories
, data
, end
);
5190 warn (_("Corrupt directories list\n"));
5194 if (n_directories
== 0)
5195 directory_table
= NULL
;
5196 else if (n_directories
> section
->size
)
5198 warn (_("number of directories (0x%x) exceeds size of section %s\n"),
5199 n_directories
, section
->name
);
5203 directory_table
= (char **)
5204 xcalloc (n_directories
, sizeof (unsigned char *));
5206 for (entryi
= 0; entryi
< n_directories
; entryi
++)
5208 char **pathp
= &directory_table
[entryi
];
5210 format
= format_start
;
5211 for (formati
= 0; formati
< format_count
; formati
++)
5213 uint64_t content_type
, form
;
5216 READ_ULEB (content_type
, format
, end
);
5217 READ_ULEB (form
, format
, end
);
5220 warn (_("Corrupt directories list\n"));
5223 switch (content_type
)
5228 case DW_FORM_string
:
5229 *pathp
= (char *) data
;
5231 case DW_FORM_line_strp
:
5232 SAFE_BYTE_GET (uvalue
, data
, linfo
.li_offset_size
,
5234 /* Remove const by the cast. */
5236 fetch_indirect_line_string (uvalue
);
5241 data
= read_and_display_attr_value (0, form
, 0, start
,
5243 linfo
.li_offset_size
,
5250 warn (_("Corrupt directories list\n"));
5255 /* Skip files format. */
5256 SAFE_BYTE_GET_AND_INC (format_count
, data
, 1, end
);
5257 if (do_checks
&& format_count
> 5)
5258 warn (_("Unexpectedly large number of columns in the file name table (%u)\n"),
5261 format_start
= data
;
5262 for (formati
= 0; formati
< format_count
; formati
++)
5264 SKIP_ULEB (data
, end
);
5265 SKIP_ULEB (data
, end
);
5268 READ_ULEB (n_files
, data
, end
);
5269 if (data
>= end
&& n_files
> 0)
5271 warn (_("Corrupt file name list\n"));
5277 else if (n_files
> section
->size
)
5279 warn (_("number of files (0x%x) exceeds size of section %s\n"),
5280 n_files
, section
->name
);
5284 file_table
= (File_Entry
*) xcalloc (n_files
,
5285 sizeof (File_Entry
));
5287 for (entryi
= 0; entryi
< n_files
; entryi
++)
5289 File_Entry
*file
= &file_table
[entryi
];
5291 format
= format_start
;
5292 for (formati
= 0; formati
< format_count
; formati
++)
5294 uint64_t content_type
, form
;
5298 READ_ULEB (content_type
, format
, end
);
5299 READ_ULEB (form
, format
, end
);
5302 warn (_("Corrupt file name list\n"));
5305 switch (content_type
)
5310 case DW_FORM_string
:
5311 file
->name
= (char *) data
;
5313 case DW_FORM_line_strp
:
5314 SAFE_BYTE_GET (uvalue
, data
, linfo
.li_offset_size
,
5316 /* Remove const by the cast. */
5317 file
->name
= (char *)
5318 fetch_indirect_line_string (uvalue
);
5322 case DW_LNCT_directory_index
:
5326 SAFE_BYTE_GET (file
->directory_index
, data
, 1,
5330 SAFE_BYTE_GET (file
->directory_index
, data
, 2,
5335 READ_ULEB (file
->directory_index
, tmp
, end
);
5340 data
= read_and_display_attr_value (0, form
, 0, start
,
5342 linfo
.li_offset_size
,
5349 warn (_("Corrupt file name list\n"));
5358 char *ptr_directory_table
= (char *) data
;
5360 while (data
< end
&& *data
!= 0)
5362 data
+= strnlen ((char *) data
, end
- data
);
5371 warn (_("directory table ends unexpectedly\n"));
5376 /* Go through the directory table again to save the directories. */
5377 directory_table
= (char **)
5378 xmalloc (n_directories
* sizeof (unsigned char *));
5381 while (*ptr_directory_table
!= 0)
5383 directory_table
[i
] = ptr_directory_table
;
5384 ptr_directory_table
+= strlen (ptr_directory_table
) + 1;
5388 /* Skip the NUL at the end of the table. */
5391 /* Traverse the File Name table just to count the entries. */
5392 if (data
< end
&& *data
!= 0)
5394 unsigned char *ptr_file_name_table
= data
;
5396 while (data
< end
&& *data
!= 0)
5398 /* Skip Name, directory index, last modification
5399 time and length of file. */
5400 data
+= strnlen ((char *) data
, end
- data
);
5403 SKIP_ULEB (data
, end
);
5404 SKIP_ULEB (data
, end
);
5405 SKIP_ULEB (data
, end
);
5411 warn (_("file table ends unexpectedly\n"));
5416 /* Go through the file table again to save the strings. */
5417 file_table
= (File_Entry
*) xmalloc (n_files
* sizeof (File_Entry
));
5420 while (*ptr_file_name_table
!= 0)
5422 file_table
[i
].name
= (char *) ptr_file_name_table
;
5424 += strlen ((char *) ptr_file_name_table
) + 1;
5426 /* We are not interested in directory, time or size. */
5427 READ_ULEB (file_table
[i
].directory_index
,
5428 ptr_file_name_table
, end
);
5429 READ_ULEB (file_table
[i
].modification_date
,
5430 ptr_file_name_table
, end
);
5431 READ_ULEB (file_table
[i
].length
,
5432 ptr_file_name_table
, end
);
5438 /* Skip the NUL at the end of the table. */
5442 /* Print the Compilation Unit's name and a header. */
5443 if (file_table
== NULL
)
5444 printf (_("CU: No directory table\n"));
5445 else if (directory_table
== NULL
)
5446 printf (_("CU: %s:\n"), null_name (file_table
[0].name
));
5449 unsigned int ix
= file_table
[0].directory_index
;
5450 const char *directory
;
5452 if (ix
== 0 && linfo
.li_version
< 5)
5455 else if (n_directories
== 0)
5456 directory
= _("<unknown>");
5459 if (linfo
.li_version
< 5)
5461 if (ix
>= n_directories
)
5463 warn (_("directory index %u "
5464 ">= number of directories %u\n"),
5466 directory
= _("<corrupt>");
5469 directory
= directory_table
[ix
];
5472 printf (_("CU: %s/%s:\n"),
5473 null_name (directory
),
5474 null_name (file_table
[0].name
));
5476 printf ("%s:\n", null_name (file_table
[0].name
));
5482 printf (_("File name Line number Starting address View Stmt\n"));
5484 printf (_("File name Line number Starting address View Stmt\n"));
5487 printf (_("CU: Empty file name table\n"));
5488 saved_linfo
= linfo
;
5491 /* This loop iterates through the Dwarf Line Number Program. */
5492 while (data
< end_of_sequence
)
5494 unsigned char op_code
;
5497 unsigned long int uladv
;
5498 int is_special_opcode
= 0;
5503 if (op_code
>= linfo
.li_opcode_base
)
5505 op_code
-= linfo
.li_opcode_base
;
5506 uladv
= (op_code
/ linfo
.li_line_range
);
5507 if (linfo
.li_max_ops_per_insn
== 1)
5509 uladv
*= linfo
.li_min_insn_length
;
5510 state_machine_regs
.address
+= uladv
;
5512 state_machine_regs
.view
= 0;
5517 = ((state_machine_regs
.op_index
+ uladv
)
5518 / linfo
.li_max_ops_per_insn
)
5519 * linfo
.li_min_insn_length
;
5520 state_machine_regs
.address
5522 state_machine_regs
.op_index
5523 = (state_machine_regs
.op_index
+ uladv
)
5524 % linfo
.li_max_ops_per_insn
;
5526 state_machine_regs
.view
= 0;
5529 adv
= (op_code
% linfo
.li_line_range
) + linfo
.li_line_base
;
5530 state_machine_regs
.line
+= adv
;
5531 is_special_opcode
= 1;
5532 /* Increment view after printing this row. */
5537 case DW_LNS_extended_op
:
5539 unsigned int ext_op_code_len
;
5540 unsigned char ext_op_code
;
5541 unsigned char *op_code_end
;
5542 unsigned char *op_code_data
= data
;
5544 READ_ULEB (ext_op_code_len
, op_code_data
, end_of_sequence
);
5545 op_code_end
= op_code_data
+ ext_op_code_len
;
5546 if (ext_op_code_len
== 0 || op_code_end
> end_of_sequence
)
5548 warn (_("Badly formed extended line op encountered!\n"));
5551 ext_op_code
= *op_code_data
++;
5555 switch (ext_op_code
)
5557 case DW_LNE_end_sequence
:
5558 /* Reset stuff after printing this row. */
5560 case DW_LNE_set_address
:
5561 SAFE_BYTE_GET_AND_INC (state_machine_regs
.address
,
5563 op_code_end
- op_code_data
,
5565 state_machine_regs
.op_index
= 0;
5566 state_machine_regs
.view
= 0;
5568 case DW_LNE_define_file
:
5569 file_table
= (File_Entry
*) xrealloc
5570 (file_table
, (n_files
+ 1) * sizeof (File_Entry
));
5572 ++state_machine_regs
.last_file_entry
;
5573 /* Source file name. */
5574 file_table
[n_files
].name
= (char *) op_code_data
;
5575 op_code_data
+= strlen ((char *) op_code_data
) + 1;
5576 /* Directory index. */
5577 READ_ULEB (file_table
[n_files
].directory_index
,
5578 op_code_data
, op_code_end
);
5579 /* Last modification time. */
5580 READ_ULEB (file_table
[n_files
].modification_date
,
5581 op_code_data
, op_code_end
);
5583 READ_ULEB (file_table
[n_files
].length
,
5584 op_code_data
, op_code_end
);
5588 case DW_LNE_set_discriminator
:
5589 case DW_LNE_HP_set_sequence
:
5590 /* Simply ignored. */
5594 printf (_("UNKNOWN (%u): length %ld\n"),
5595 ext_op_code
, (long int) (op_code_data
- data
));
5602 /* Increment view after printing this row. */
5605 case DW_LNS_advance_pc
:
5606 READ_ULEB (uladv
, data
, end
);
5607 if (linfo
.li_max_ops_per_insn
== 1)
5609 uladv
*= linfo
.li_min_insn_length
;
5610 state_machine_regs
.address
+= uladv
;
5612 state_machine_regs
.view
= 0;
5617 = ((state_machine_regs
.op_index
+ uladv
)
5618 / linfo
.li_max_ops_per_insn
)
5619 * linfo
.li_min_insn_length
;
5620 state_machine_regs
.address
5622 state_machine_regs
.op_index
5623 = (state_machine_regs
.op_index
+ uladv
)
5624 % linfo
.li_max_ops_per_insn
;
5626 state_machine_regs
.view
= 0;
5630 case DW_LNS_advance_line
:
5631 READ_SLEB (adv
, data
, end
);
5632 state_machine_regs
.line
+= adv
;
5635 case DW_LNS_set_file
:
5636 READ_ULEB (uladv
, data
, end
);
5637 state_machine_regs
.file
= uladv
;
5639 unsigned file
= state_machine_regs
.file
;
5640 if (linfo
.li_version
< 5)
5643 if (file_table
== NULL
|| n_files
== 0)
5644 printf (_("\n [Use file table entry %d]\n"), file
);
5646 else if (file
>= n_files
)
5648 warn (_("file index %u >= number of files %u\n"),
5650 printf (_("\n <over large file table index %u>"), file
);
5654 unsigned dir
= file_table
[file
].directory_index
;
5655 if (dir
== 0 && linfo
.li_version
< 5)
5656 /* If directory index is 0, that means compilation
5657 current directory. bfd/dwarf2.c shows
5658 DW_AT_comp_dir here but in keeping with the
5659 readelf practice of minimal interpretation of
5660 file data, we show "./". */
5661 printf ("\n./%s:[++]\n",
5662 null_name (file_table
[file
].name
));
5663 else if (directory_table
== NULL
|| n_directories
== 0)
5664 printf (_("\n [Use file %s "
5665 "in directory table entry %d]\n"),
5666 null_name (file_table
[file
].name
), dir
);
5669 if (linfo
.li_version
< 5)
5672 if (dir
>= n_directories
)
5674 warn (_("directory index %u "
5675 ">= number of directories %u\n"),
5676 dir
, n_directories
);
5677 printf (_("\n <over large directory table entry "
5681 printf ("\n%s/%s:\n",
5682 null_name (directory_table
[dir
]),
5683 null_name (file_table
[file
].name
));
5688 case DW_LNS_set_column
:
5689 READ_ULEB (uladv
, data
, end
);
5690 state_machine_regs
.column
= uladv
;
5693 case DW_LNS_negate_stmt
:
5694 adv
= state_machine_regs
.is_stmt
;
5696 state_machine_regs
.is_stmt
= adv
;
5699 case DW_LNS_set_basic_block
:
5700 state_machine_regs
.basic_block
= 1;
5703 case DW_LNS_const_add_pc
:
5704 uladv
= ((255 - linfo
.li_opcode_base
) / linfo
.li_line_range
);
5705 if (linfo
.li_max_ops_per_insn
== 1)
5707 uladv
*= linfo
.li_min_insn_length
;
5708 state_machine_regs
.address
+= uladv
;
5710 state_machine_regs
.view
= 0;
5715 = ((state_machine_regs
.op_index
+ uladv
)
5716 / linfo
.li_max_ops_per_insn
)
5717 * linfo
.li_min_insn_length
;
5718 state_machine_regs
.address
5720 state_machine_regs
.op_index
5721 = (state_machine_regs
.op_index
+ uladv
)
5722 % linfo
.li_max_ops_per_insn
;
5724 state_machine_regs
.view
= 0;
5728 case DW_LNS_fixed_advance_pc
:
5729 SAFE_BYTE_GET_AND_INC (uladv
, data
, 2, end
);
5730 state_machine_regs
.address
+= uladv
;
5731 state_machine_regs
.op_index
= 0;
5732 /* Do NOT reset view. */
5735 case DW_LNS_set_prologue_end
:
5738 case DW_LNS_set_epilogue_begin
:
5741 case DW_LNS_set_isa
:
5742 READ_ULEB (uladv
, data
, end
);
5743 printf (_(" Set ISA to %lu\n"), uladv
);
5747 printf (_(" Unknown opcode %d with operands: "), op_code
);
5749 if (standard_opcodes
!= NULL
)
5750 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
5754 READ_ULEB (val
, data
, end
);
5755 printf ("%#" PRIx64
"%s", val
, i
== 1 ? "" : ", ");
5761 /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row
5762 to the DWARF address/line matrix. */
5763 if ((is_special_opcode
) || (xop
== -DW_LNE_end_sequence
)
5764 || (xop
== DW_LNS_copy
))
5766 const unsigned int MAX_FILENAME_LENGTH
= 35;
5767 char *fileName
= NULL
;
5768 char *newFileName
= NULL
;
5769 size_t fileNameLength
;
5773 unsigned indx
= state_machine_regs
.file
;
5775 if (linfo
.li_version
< 5)
5778 if (indx
>= n_files
)
5780 warn (_("file index %u >= number of files %u\n"),
5782 fileName
= _("<corrupt>");
5785 fileName
= (char *) file_table
[indx
].name
;
5788 fileName
= _("<unknown>");
5790 fileNameLength
= strlen (fileName
);
5791 newFileName
= fileName
;
5792 if (fileNameLength
> MAX_FILENAME_LENGTH
&& !do_wide
)
5794 newFileName
= (char *) xmalloc (MAX_FILENAME_LENGTH
+ 1);
5795 /* Truncate file name */
5796 memcpy (newFileName
,
5797 fileName
+ fileNameLength
- MAX_FILENAME_LENGTH
,
5798 MAX_FILENAME_LENGTH
);
5799 newFileName
[MAX_FILENAME_LENGTH
] = 0;
5802 /* A row with end_seq set to true has a meaningful address, but
5803 the other information in the same row is not significant.
5804 In such a row, print line as "-", and don't print
5806 if (!do_wide
|| fileNameLength
<= MAX_FILENAME_LENGTH
)
5808 if (linfo
.li_max_ops_per_insn
== 1)
5810 if (xop
== -DW_LNE_end_sequence
)
5811 printf ("%-31s %11s %#18" PRIx64
,
5813 state_machine_regs
.address
);
5815 printf ("%-31s %11d %#18" PRIx64
,
5816 newFileName
, state_machine_regs
.line
,
5817 state_machine_regs
.address
);
5821 if (xop
== -DW_LNE_end_sequence
)
5822 printf ("%-31s %11s %#18" PRIx64
"[%d]",
5824 state_machine_regs
.address
,
5825 state_machine_regs
.op_index
);
5827 printf ("%-31s %11d %#18" PRIx64
"[%d]",
5828 newFileName
, state_machine_regs
.line
,
5829 state_machine_regs
.address
,
5830 state_machine_regs
.op_index
);
5835 if (linfo
.li_max_ops_per_insn
== 1)
5837 if (xop
== -DW_LNE_end_sequence
)
5838 printf ("%s %11s %#18" PRIx64
,
5840 state_machine_regs
.address
);
5842 printf ("%s %11d %#18" PRIx64
,
5843 newFileName
, state_machine_regs
.line
,
5844 state_machine_regs
.address
);
5848 if (xop
== -DW_LNE_end_sequence
)
5849 printf ("%s %11s %#18" PRIx64
"[%d]",
5851 state_machine_regs
.address
,
5852 state_machine_regs
.op_index
);
5854 printf ("%s %11d %#18" PRIx64
"[%d]",
5855 newFileName
, state_machine_regs
.line
,
5856 state_machine_regs
.address
,
5857 state_machine_regs
.op_index
);
5861 if (xop
!= -DW_LNE_end_sequence
)
5863 if (state_machine_regs
.view
)
5864 printf (" %6u", state_machine_regs
.view
);
5868 if (state_machine_regs
.is_stmt
)
5873 state_machine_regs
.view
++;
5875 if (xop
== -DW_LNE_end_sequence
)
5877 reset_state_machine (linfo
.li_default_is_stmt
);
5881 if (newFileName
!= fileName
)
5893 if (directory_table
)
5895 free (directory_table
);
5896 directory_table
= NULL
;
5907 display_debug_lines (struct dwarf_section
*section
, void *file
)
5909 unsigned char *data
= section
->start
;
5910 unsigned char *end
= data
+ section
->size
;
5912 int retValDecoded
= 1;
5914 if (do_debug_lines
== 0)
5915 do_debug_lines
|= FLAG_DEBUG_LINES_RAW
;
5917 if (do_debug_lines
& FLAG_DEBUG_LINES_RAW
)
5918 retValRaw
= display_debug_lines_raw (section
, data
, end
, file
);
5920 if (do_debug_lines
& FLAG_DEBUG_LINES_DECODED
)
5921 retValDecoded
= display_debug_lines_decoded (section
, data
, data
, end
, file
);
5923 if (!retValRaw
|| !retValDecoded
)
5930 find_debug_info_for_offset (uint64_t offset
)
5934 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
5937 for (i
= 0; i
< num_debug_info_entries
; i
++)
5938 if (debug_information
[i
].cu_offset
== offset
)
5939 return debug_information
+ i
;
5945 get_gdb_index_symbol_kind_name (gdb_index_symbol_kind kind
)
5947 /* See gdb/gdb-index.h. */
5948 static const char * const kinds
[] =
5960 return _ (kinds
[kind
]);
5964 display_debug_pubnames_worker (struct dwarf_section
*section
,
5965 void *file ATTRIBUTE_UNUSED
,
5968 DWARF2_Internal_PubNames names
;
5969 unsigned char *start
= section
->start
;
5970 unsigned char *end
= start
+ section
->size
;
5972 /* It does not matter if this load fails,
5973 we test for that later on. */
5974 load_debug_info (file
);
5976 introduce (section
, false);
5980 unsigned char *data
;
5981 unsigned long sec_off
= start
- section
->start
;
5982 unsigned int offset_size
;
5984 SAFE_BYTE_GET_AND_INC (names
.pn_length
, start
, 4, end
);
5985 if (names
.pn_length
== 0xffffffff)
5987 SAFE_BYTE_GET_AND_INC (names
.pn_length
, start
, 8, end
);
5993 if (names
.pn_length
> (size_t) (end
- start
))
5995 warn (_("Debug info is corrupted, "
5996 "%s header at %#lx has length %#" PRIx64
"\n"),
5997 section
->name
, sec_off
, names
.pn_length
);
6002 start
+= names
.pn_length
;
6004 SAFE_BYTE_GET_AND_INC (names
.pn_version
, data
, 2, start
);
6005 SAFE_BYTE_GET_AND_INC (names
.pn_offset
, data
, offset_size
, start
);
6007 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
6008 && num_debug_info_entries
> 0
6009 && find_debug_info_for_offset (names
.pn_offset
) == NULL
)
6010 warn (_(".debug_info offset of %#" PRIx64
6011 " in %s section does not point to a CU header.\n"),
6012 names
.pn_offset
, section
->name
);
6014 SAFE_BYTE_GET_AND_INC (names
.pn_size
, data
, offset_size
, start
);
6016 printf (_(" Length: %" PRId64
"\n"),
6018 printf (_(" Version: %d\n"),
6020 printf (_(" Offset into .debug_info section: %#" PRIx64
"\n"),
6022 printf (_(" Size of area in .debug_info section: %" PRId64
"\n"),
6025 if (names
.pn_version
!= 2 && names
.pn_version
!= 3)
6027 static int warned
= 0;
6031 warn (_("Only DWARF 2 and 3 pubnames are currently supported\n"));
6039 printf (_("\n Offset Kind Name\n"));
6041 printf (_("\n Offset\tName\n"));
6048 SAFE_BYTE_GET_AND_INC (offset
, data
, offset_size
, start
);
6055 maxprint
= (start
- data
) - 1;
6059 unsigned int kind_data
;
6060 gdb_index_symbol_kind kind
;
6061 const char *kind_name
;
6064 SAFE_BYTE_GET_AND_INC (kind_data
, data
, 1, start
);
6066 /* GCC computes the kind as the upper byte in the CU index
6067 word, and then right shifts it by the CU index size.
6068 Left shift KIND to where the gdb-index.h accessor macros
6070 kind_data
<<= GDB_INDEX_CU_BITSIZE
;
6071 kind
= GDB_INDEX_SYMBOL_KIND_VALUE (kind_data
);
6072 kind_name
= get_gdb_index_symbol_kind_name (kind
);
6073 is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (kind_data
);
6074 printf (" %-6" PRIx64
" %s,%-10s %.*s\n",
6075 offset
, is_static
? _("s") : _("g"),
6076 kind_name
, (int) maxprint
, data
);
6079 printf (" %-6" PRIx64
"\t%.*s\n",
6080 offset
, (int) maxprint
, data
);
6082 data
+= strnlen ((char *) data
, maxprint
);
6095 display_debug_pubnames (struct dwarf_section
*section
, void *file
)
6097 return display_debug_pubnames_worker (section
, file
, 0);
6101 display_debug_gnu_pubnames (struct dwarf_section
*section
, void *file
)
6103 return display_debug_pubnames_worker (section
, file
, 1);
6107 display_debug_macinfo (struct dwarf_section
*section
,
6108 void *file ATTRIBUTE_UNUSED
)
6110 unsigned char *start
= section
->start
;
6111 unsigned char *end
= start
+ section
->size
;
6112 unsigned char *curr
= start
;
6113 enum dwarf_macinfo_record_type op
;
6115 introduce (section
, false);
6119 unsigned int lineno
;
6120 const unsigned char *string
;
6122 op
= (enum dwarf_macinfo_record_type
) *curr
;
6127 case DW_MACINFO_start_file
:
6129 unsigned int filenum
;
6131 READ_ULEB (lineno
, curr
, end
);
6132 READ_ULEB (filenum
, curr
, end
);
6133 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"),
6138 case DW_MACINFO_end_file
:
6139 printf (_(" DW_MACINFO_end_file\n"));
6142 case DW_MACINFO_define
:
6143 READ_ULEB (lineno
, curr
, end
);
6145 curr
+= strnlen ((char *) string
, end
- string
);
6146 printf (_(" DW_MACINFO_define - lineno : %d macro : %*s\n"),
6147 lineno
, (int) (curr
- string
), string
);
6152 case DW_MACINFO_undef
:
6153 READ_ULEB (lineno
, curr
, end
);
6155 curr
+= strnlen ((char *) string
, end
- string
);
6156 printf (_(" DW_MACINFO_undef - lineno : %d macro : %*s\n"),
6157 lineno
, (int) (curr
- string
), string
);
6162 case DW_MACINFO_vendor_ext
:
6164 unsigned int constant
;
6166 READ_ULEB (constant
, curr
, end
);
6168 curr
+= strnlen ((char *) string
, end
- string
);
6169 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %*s\n"),
6170 constant
, (int) (curr
- string
), string
);
6181 /* Given LINE_OFFSET into the .debug_line section, attempt to return
6182 filename and dirname corresponding to file name table entry with index
6183 FILEIDX. Return NULL on failure. */
6185 static unsigned char *
6186 get_line_filename_and_dirname (uint64_t line_offset
,
6188 unsigned char **dir_name
)
6190 struct dwarf_section
*section
= &debug_displays
[line
].section
;
6191 unsigned char *hdrptr
, *dirtable
, *file_name
;
6192 unsigned int offset_size
;
6193 unsigned int version
, opcode_base
;
6194 uint64_t length
, diridx
;
6195 const unsigned char * end
;
6198 if (section
->start
== NULL
6199 || line_offset
>= section
->size
6203 hdrptr
= section
->start
+ line_offset
;
6204 end
= section
->start
+ section
->size
;
6206 SAFE_BYTE_GET_AND_INC (length
, hdrptr
, 4, end
);
6207 if (length
== 0xffffffff)
6209 /* This section is 64-bit DWARF 3. */
6210 SAFE_BYTE_GET_AND_INC (length
, hdrptr
, 8, end
);
6216 if (length
> (size_t) (end
- hdrptr
)
6217 || length
< 2 + offset_size
+ 1 + 3 + 1)
6219 end
= hdrptr
+ length
;
6221 SAFE_BYTE_GET_AND_INC (version
, hdrptr
, 2, end
);
6222 if (version
!= 2 && version
!= 3 && version
!= 4)
6224 hdrptr
+= offset_size
+ 1;/* Skip prologue_length and min_insn_length. */
6226 hdrptr
++; /* Skip max_ops_per_insn. */
6227 hdrptr
+= 3; /* Skip default_is_stmt, line_base, line_range. */
6229 SAFE_BYTE_GET_AND_INC (opcode_base
, hdrptr
, 1, end
);
6230 if (opcode_base
== 0
6231 || opcode_base
- 1 >= (size_t) (end
- hdrptr
))
6234 hdrptr
+= opcode_base
- 1;
6237 /* Skip over dirname table. */
6238 while (*hdrptr
!= '\0')
6240 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
);
6246 hdrptr
++; /* Skip the NUL at the end of the table. */
6248 /* Now skip over preceding filename table entries. */
6249 for (; hdrptr
< end
&& *hdrptr
!= '\0' && fileidx
> 1; fileidx
--)
6251 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
);
6254 SKIP_ULEB (hdrptr
, end
);
6255 SKIP_ULEB (hdrptr
, end
);
6256 SKIP_ULEB (hdrptr
, end
);
6258 if (hdrptr
>= end
|| *hdrptr
== '\0')
6262 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
);
6267 READ_ULEB (diridx
, hdrptr
, end
);
6270 for (; dirtable
< end
&& *dirtable
!= '\0' && diridx
> 1; diridx
--)
6272 dirtable
+= strnlen ((char *) dirtable
, end
- dirtable
);
6276 if (dirtable
>= end
|| *dirtable
== '\0')
6278 *dir_name
= dirtable
;
6283 display_debug_macro (struct dwarf_section
*section
,
6286 unsigned char *start
= section
->start
;
6287 unsigned char *end
= start
+ section
->size
;
6288 unsigned char *curr
= start
;
6289 unsigned char *extended_op_buf
[256];
6290 bool is_dwo
= false;
6291 const char *suffix
= strrchr (section
->name
, '.');
6293 if (suffix
&& strcmp (suffix
, ".dwo") == 0)
6298 load_debug_section_with_follow (str_dwo
, file
);
6299 load_debug_section_with_follow (str_index_dwo
, file
);
6303 load_debug_section_with_follow (str
, file
);
6304 load_debug_section_with_follow (str_index
, file
);
6306 load_debug_section_with_follow (line
, file
);
6308 introduce (section
, false);
6312 unsigned int lineno
, version
, flags
;
6313 unsigned int offset_size
;
6314 const unsigned char *string
;
6315 uint64_t line_offset
= 0, sec_offset
= curr
- start
, offset
;
6316 unsigned char **extended_ops
= NULL
;
6318 SAFE_BYTE_GET_AND_INC (version
, curr
, 2, end
);
6319 if (version
!= 4 && version
!= 5)
6321 error (_("Expected to find a version number of 4 or 5 in section %s but found %d instead\n"),
6322 section
->name
, version
);
6326 SAFE_BYTE_GET_AND_INC (flags
, curr
, 1, end
);
6327 offset_size
= (flags
& 1) ? 8 : 4;
6328 printf (_(" Offset: %#" PRIx64
"\n"), sec_offset
);
6329 printf (_(" Version: %d\n"), version
);
6330 printf (_(" Offset size: %d\n"), offset_size
);
6333 SAFE_BYTE_GET_AND_INC (line_offset
, curr
, offset_size
, end
);
6334 printf (_(" Offset into .debug_line: %#" PRIx64
"\n"),
6339 unsigned int i
, count
, op
;
6342 SAFE_BYTE_GET_AND_INC (count
, curr
, 1, end
);
6344 memset (extended_op_buf
, 0, sizeof (extended_op_buf
));
6345 extended_ops
= extended_op_buf
;
6348 printf (_(" Extension opcode arguments:\n"));
6349 for (i
= 0; i
< count
; i
++)
6351 SAFE_BYTE_GET_AND_INC (op
, curr
, 1, end
);
6352 extended_ops
[op
] = curr
;
6353 READ_ULEB (nargs
, curr
, end
);
6355 printf (_(" DW_MACRO_%02x has no arguments\n"), op
);
6358 printf (_(" DW_MACRO_%02x arguments: "), op
);
6359 for (n
= 0; n
< nargs
; n
++)
6363 SAFE_BYTE_GET_AND_INC (form
, curr
, 1, end
);
6364 printf ("%s%s", get_FORM_name (form
),
6365 n
== nargs
- 1 ? "\n" : ", ");
6375 case DW_FORM_block1
:
6376 case DW_FORM_block2
:
6377 case DW_FORM_block4
:
6379 case DW_FORM_string
:
6381 case DW_FORM_sec_offset
:
6384 error (_("Invalid extension opcode form %s\n"),
6385 get_FORM_name (form
));
6401 error (_(".debug_macro section not zero terminated\n"));
6405 SAFE_BYTE_GET_AND_INC (op
, curr
, 1, end
);
6411 case DW_MACRO_define
:
6412 READ_ULEB (lineno
, curr
, end
);
6414 curr
+= strnlen ((char *) string
, end
- string
);
6415 printf (_(" DW_MACRO_define - lineno : %d macro : %*s\n"),
6416 lineno
, (int) (curr
- string
), string
);
6421 case DW_MACRO_undef
:
6422 READ_ULEB (lineno
, curr
, end
);
6424 curr
+= strnlen ((char *) string
, end
- string
);
6425 printf (_(" DW_MACRO_undef - lineno : %d macro : %*s\n"),
6426 lineno
, (int) (curr
- string
), string
);
6431 case DW_MACRO_start_file
:
6433 unsigned int filenum
;
6434 unsigned char *file_name
= NULL
, *dir_name
= NULL
;
6436 READ_ULEB (lineno
, curr
, end
);
6437 READ_ULEB (filenum
, curr
, end
);
6439 if ((flags
& 2) == 0)
6440 error (_("DW_MACRO_start_file used, but no .debug_line offset provided.\n"));
6443 = get_line_filename_and_dirname (line_offset
, filenum
,
6445 if (file_name
== NULL
)
6446 printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d\n"),
6449 printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d filename: %s%s%s\n"),
6451 dir_name
!= NULL
? (const char *) dir_name
: "",
6452 dir_name
!= NULL
? "/" : "", file_name
);
6456 case DW_MACRO_end_file
:
6457 printf (_(" DW_MACRO_end_file\n"));
6460 case DW_MACRO_define_strp
:
6461 READ_ULEB (lineno
, curr
, end
);
6462 if (version
== 4 && is_dwo
)
6463 READ_ULEB (offset
, curr
, end
);
6465 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6466 string
= fetch_indirect_string (offset
);
6467 printf (_(" DW_MACRO_define_strp - lineno : %d macro : %s\n"),
6471 case DW_MACRO_undef_strp
:
6472 READ_ULEB (lineno
, curr
, end
);
6473 if (version
== 4 && is_dwo
)
6474 READ_ULEB (offset
, curr
, end
);
6476 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6477 string
= fetch_indirect_string (offset
);
6478 printf (_(" DW_MACRO_undef_strp - lineno : %d macro : %s\n"),
6482 case DW_MACRO_import
:
6483 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6484 printf (_(" DW_MACRO_import - offset : %#" PRIx64
"\n"),
6488 case DW_MACRO_define_sup
:
6489 READ_ULEB (lineno
, curr
, end
);
6490 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6491 printf (_(" DW_MACRO_define_sup - lineno : %d"
6492 " macro offset : %#" PRIx64
"\n"),
6496 case DW_MACRO_undef_sup
:
6497 READ_ULEB (lineno
, curr
, end
);
6498 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6499 printf (_(" DW_MACRO_undef_sup - lineno : %d"
6500 " macro offset : %#" PRIx64
"\n"),
6504 case DW_MACRO_import_sup
:
6505 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6506 printf (_(" DW_MACRO_import_sup - offset : %#" PRIx64
"\n"),
6510 case DW_MACRO_define_strx
:
6511 case DW_MACRO_undef_strx
:
6512 READ_ULEB (lineno
, curr
, end
);
6513 READ_ULEB (offset
, curr
, end
);
6514 string
= (const unsigned char *)
6515 fetch_indexed_string (offset
, NULL
, offset_size
, is_dwo
, 0);
6516 if (op
== DW_MACRO_define_strx
)
6517 printf (" DW_MACRO_define_strx ");
6519 printf (" DW_MACRO_undef_strx ");
6521 printf (_("(with offset %#" PRIx64
") "), offset
);
6522 printf (_("lineno : %d macro : %s\n"),
6527 if (op
>= DW_MACRO_lo_user
&& op
<= DW_MACRO_hi_user
)
6529 printf (_(" <Target Specific macro op: %#x - UNHANDLED"), op
);
6533 if (extended_ops
== NULL
|| extended_ops
[op
] == NULL
)
6535 error (_(" Unknown macro opcode %02x seen\n"), op
);
6540 /* Skip over unhandled opcodes. */
6542 unsigned char *desc
= extended_ops
[op
];
6543 READ_ULEB (nargs
, desc
, end
);
6546 printf (_(" DW_MACRO_%02x\n"), op
);
6549 printf (_(" DW_MACRO_%02x -"), op
);
6550 for (n
= 0; n
< nargs
; n
++)
6554 /* DW_FORM_implicit_const is not expected here. */
6555 SAFE_BYTE_GET_AND_INC (val
, desc
, 1, end
);
6557 = read_and_display_attr_value (0, val
, 0,
6558 start
, curr
, end
, 0, 0,
6559 offset_size
, version
,
6578 display_debug_abbrev (struct dwarf_section
*section
,
6579 void *file ATTRIBUTE_UNUSED
)
6581 abbrev_entry
*entry
;
6582 unsigned char *start
= section
->start
;
6584 introduce (section
, false);
6588 uint64_t offset
= start
- section
->start
;
6589 abbrev_list
*list
= find_and_process_abbrev_set (section
, 0,
6590 section
->size
, offset
,
6595 if (list
->first_abbrev
)
6596 printf (_(" Number TAG (%#" PRIx64
")\n"), offset
);
6598 for (entry
= list
->first_abbrev
; entry
; entry
= entry
->next
)
6602 printf (" %ld %s [%s]\n",
6604 get_TAG_name (entry
->tag
),
6605 entry
->children
? _("has children") : _("no children"));
6607 for (attr
= entry
->first_attr
; attr
; attr
= attr
->next
)
6609 printf (" %-18s %s",
6610 get_AT_name (attr
->attribute
),
6611 get_FORM_name (attr
->form
));
6612 if (attr
->form
== DW_FORM_implicit_const
)
6613 printf (": %" PRId64
, attr
->implicit_const
);
6617 start
= list
->start_of_next_abbrevs
;
6618 free_abbrev_list (list
);
6627 /* Return true when ADDR is the maximum address, when addresses are
6628 POINTER_SIZE bytes long. */
6631 is_max_address (uint64_t addr
, unsigned int pointer_size
)
6633 uint64_t mask
= ~(~(uint64_t) 0 << 1 << (pointer_size
* 8 - 1));
6634 return ((addr
& mask
) == mask
);
6637 /* Display a view pair list starting at *VSTART_PTR and ending at
6638 VLISTEND within SECTION. */
6641 display_view_pair_list (struct dwarf_section
*section
,
6642 unsigned char **vstart_ptr
,
6643 unsigned int debug_info_entry
,
6644 unsigned char *vlistend
)
6646 unsigned char *vstart
= *vstart_ptr
;
6647 unsigned char *section_end
= section
->start
+ section
->size
;
6648 unsigned int pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
6650 if (vlistend
< section_end
)
6651 section_end
= vlistend
;
6655 while (vstart
< section_end
)
6657 uint64_t off
= vstart
- section
->start
;
6658 uint64_t vbegin
, vend
;
6660 READ_ULEB (vbegin
, vstart
, section_end
);
6661 if (vstart
== section_end
)
6664 READ_ULEB (vend
, vstart
, section_end
);
6665 printf (" %8.8" PRIx64
" ", off
);
6667 print_view (vbegin
, pointer_size
);
6668 print_view (vend
, pointer_size
);
6669 printf (_("location view pair\n"));
6673 *vstart_ptr
= vstart
;
6676 /* Display a location list from a normal (ie, non-dwo) .debug_loc section. */
6679 display_loc_list (struct dwarf_section
*section
,
6680 unsigned char **start_ptr
,
6681 unsigned int debug_info_entry
,
6683 uint64_t base_address
,
6684 unsigned char **vstart_ptr
,
6687 unsigned char *start
= *start_ptr
, *vstart
= *vstart_ptr
;
6688 unsigned char *section_end
= section
->start
+ section
->size
;
6690 unsigned int pointer_size
;
6691 unsigned int offset_size
;
6695 unsigned short length
;
6696 int need_frame_base
;
6698 if (debug_info_entry
>= num_debug_info_entries
)
6700 warn (_("No debug information available for loc lists of entry: %u\n"),
6705 cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
6706 pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
6707 offset_size
= debug_information
[debug_info_entry
].offset_size
;
6708 dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
6710 if (pointer_size
< 2 || pointer_size
> 8)
6712 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
6713 pointer_size
, debug_info_entry
);
6719 uint64_t off
= offset
+ (start
- *start_ptr
);
6720 uint64_t vbegin
= -1, vend
= -1;
6722 if (2 * pointer_size
> (size_t) (section_end
- start
))
6724 warn (_("Location list starting at offset %#" PRIx64
6725 " is not terminated.\n"), offset
);
6732 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, section_end
);
6733 SAFE_BYTE_GET_AND_INC (end
, start
, pointer_size
, section_end
);
6735 if (begin
== 0 && end
== 0)
6737 /* PR 18374: In a object file we can have a location list that
6738 starts with a begin and end of 0 because there are relocations
6739 that need to be applied to the addresses. Actually applying
6740 the relocations now does not help as they will probably resolve
6741 to 0, since the object file has not been fully linked. Real
6742 end of list markers will not have any relocations against them. */
6743 if (! reloc_at (section
, off
)
6744 && ! reloc_at (section
, off
+ pointer_size
))
6746 printf (_("<End of list>\n"));
6751 /* Check base address specifiers. */
6752 if (is_max_address (begin
, pointer_size
)
6753 && !is_max_address (end
, pointer_size
))
6756 print_hex (begin
, pointer_size
);
6757 print_hex (end
, pointer_size
);
6758 printf (_("(base address)\n"));
6764 off
= offset
+ (vstart
- *start_ptr
);
6766 READ_ULEB (vbegin
, vstart
, section_end
);
6767 print_view (vbegin
, pointer_size
);
6769 READ_ULEB (vend
, vstart
, section_end
);
6770 print_view (vend
, pointer_size
);
6772 printf (_("views at %8.8" PRIx64
" for:\n %*s "), off
, 8, "");
6775 if (2 > (size_t) (section_end
- start
))
6777 warn (_("Location list starting at offset %#" PRIx64
6778 " is not terminated.\n"), offset
);
6782 SAFE_BYTE_GET_AND_INC (length
, start
, 2, section_end
);
6784 if (length
> (size_t) (section_end
- start
))
6786 warn (_("Location list starting at offset %#" PRIx64
6787 " is not terminated.\n"), offset
);
6791 print_hex (begin
+ base_address
, pointer_size
);
6792 print_hex (end
+ base_address
, pointer_size
);
6795 need_frame_base
= decode_location_expression (start
,
6800 cu_offset
, section
);
6803 if (need_frame_base
&& !has_frame_base
)
6804 printf (_(" [without DW_AT_frame_base]"));
6806 if (begin
== end
&& vbegin
== vend
)
6807 fputs (_(" (start == end)"), stdout
);
6808 else if (begin
> end
|| (begin
== end
&& vbegin
> vend
))
6809 fputs (_(" (start > end)"), stdout
);
6817 *vstart_ptr
= vstart
;
6820 /* Display a location list from a normal (ie, non-dwo) .debug_loclists section. */
6823 display_loclists_list (struct dwarf_section
* section
,
6824 unsigned char ** start_ptr
,
6825 debug_info
* debug_info_p
,
6827 uint64_t base_address
,
6828 unsigned char ** vstart_ptr
,
6831 unsigned char *start
= *start_ptr
;
6832 unsigned char *vstart
= *vstart_ptr
;
6833 unsigned char *section_end
= section
->start
+ section
->size
;
6835 unsigned int pointer_size
;
6836 unsigned int offset_size
;
6837 unsigned int dwarf_version
;
6840 /* Initialize it due to a false compiler warning. */
6841 uint64_t begin
= -1, vbegin
= -1;
6842 uint64_t end
= -1, vend
= -1;
6844 int need_frame_base
;
6846 cu_offset
= debug_info_p
->cu_offset
;
6847 pointer_size
= debug_info_p
->pointer_size
;
6848 offset_size
= debug_info_p
->offset_size
;
6849 dwarf_version
= debug_info_p
->dwarf_version
;
6851 if (pointer_size
< 2 || pointer_size
> 8)
6853 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
6854 pointer_size
, (int)(debug_info_p
- debug_information
));
6860 uint64_t off
= offset
+ (start
- *start_ptr
);
6861 enum dwarf_location_list_entry_type llet
;
6863 if (start
+ 1 > section_end
)
6865 warn (_("Location list starting at offset %#" PRIx64
6866 " is not terminated.\n"), offset
);
6873 SAFE_BYTE_GET_AND_INC (llet
, start
, 1, section_end
);
6875 if (vstart
&& (llet
== DW_LLE_offset_pair
6876 || llet
== DW_LLE_start_end
6877 || llet
== DW_LLE_start_length
))
6879 off
= offset
+ (vstart
- *start_ptr
);
6881 READ_ULEB (vbegin
, vstart
, section_end
);
6882 print_view (vbegin
, pointer_size
);
6884 READ_ULEB (vend
, vstart
, section_end
);
6885 print_view (vend
, pointer_size
);
6887 printf (_("views at %8.8" PRIx64
" for:\n %*s "), off
, 8, "");
6892 case DW_LLE_end_of_list
:
6893 printf (_("<End of list>\n"));
6896 case DW_LLE_base_addressx
:
6897 READ_ULEB (idx
, start
, section_end
);
6898 print_hex (idx
, pointer_size
);
6899 printf (_("(index into .debug_addr) "));
6900 base_address
= fetch_indexed_addr
6901 (debug_info_p
->addr_base
+ idx
* pointer_size
, pointer_size
);
6902 print_hex (base_address
, pointer_size
);
6903 printf (_("(base address)\n"));
6906 case DW_LLE_startx_endx
:
6907 READ_ULEB (idx
, start
, section_end
);
6908 begin
= fetch_indexed_addr
6909 (debug_info_p
->addr_base
+ idx
* pointer_size
, pointer_size
);
6910 READ_ULEB (idx
, start
, section_end
);
6911 end
= fetch_indexed_addr
6912 (debug_info_p
->addr_base
+ idx
* pointer_size
, pointer_size
);
6915 case DW_LLE_startx_length
:
6916 READ_ULEB (idx
, start
, section_end
);
6917 begin
= fetch_indexed_addr
6918 (debug_info_p
->addr_base
+ idx
* pointer_size
, pointer_size
);
6919 READ_ULEB (end
, start
, section_end
);
6923 case DW_LLE_default_location
:
6927 case DW_LLE_offset_pair
:
6928 READ_ULEB (begin
, start
, section_end
);
6929 begin
+= base_address
;
6930 READ_ULEB (end
, start
, section_end
);
6931 end
+= base_address
;
6934 case DW_LLE_base_address
:
6935 SAFE_BYTE_GET_AND_INC (base_address
, start
, pointer_size
,
6937 print_hex (base_address
, pointer_size
);
6938 printf (_("(base address)\n"));
6941 case DW_LLE_start_end
:
6942 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, section_end
);
6943 SAFE_BYTE_GET_AND_INC (end
, start
, pointer_size
, section_end
);
6946 case DW_LLE_start_length
:
6947 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, section_end
);
6948 READ_ULEB (end
, start
, section_end
);
6952 #ifdef DW_LLE_view_pair
6953 case DW_LLE_view_pair
:
6955 printf (_("View pair entry in loclist with locviews attribute\n"));
6956 READ_ULEB (vbegin
, start
, section_end
);
6957 print_view (vbegin
, pointer_size
);
6959 READ_ULEB (vend
, start
, section_end
);
6960 print_view (vend
, pointer_size
);
6962 printf (_("views for:\n"));
6967 error (_("Invalid location list entry type %d\n"), llet
);
6971 if (llet
== DW_LLE_end_of_list
)
6974 if (llet
== DW_LLE_base_address
6975 || llet
== DW_LLE_base_addressx
)
6978 if (start
== section_end
)
6980 warn (_("Location list starting at offset %#" PRIx64
6981 " is not terminated.\n"), offset
);
6984 READ_ULEB (length
, start
, section_end
);
6986 if (length
> (size_t) (section_end
- start
))
6988 warn (_("Location list starting at offset %#" PRIx64
6989 " is not terminated.\n"), offset
);
6993 print_hex (begin
, pointer_size
);
6994 print_hex (end
, pointer_size
);
6997 need_frame_base
= decode_location_expression (start
,
7002 cu_offset
, section
);
7005 if (need_frame_base
&& !has_frame_base
)
7006 printf (_(" [without DW_AT_frame_base]"));
7008 if (begin
== end
&& vbegin
== vend
)
7009 fputs (_(" (start == end)"), stdout
);
7010 else if (begin
> end
|| (begin
== end
&& vbegin
> vend
))
7011 fputs (_(" (start > end)"), stdout
);
7019 if (vbegin
!= (uint64_t) -1 || vend
!= (uint64_t) -1)
7020 printf (_("Trailing view pair not used in a range"));
7023 *vstart_ptr
= vstart
;
7026 /* Print a .debug_addr table index in decimal, surrounded by square brackets,
7027 right-adjusted in a field of length LEN, and followed by a space. */
7030 print_addr_index (unsigned int idx
, unsigned int len
)
7032 static char buf
[15];
7033 snprintf (buf
, sizeof (buf
), "[%d]", idx
);
7034 printf ("%*s ", len
, buf
);
7037 /* Display a location list from a .dwo section. It uses address indexes rather
7038 than embedded addresses. This code closely follows display_loc_list, but the
7039 two are sufficiently different that combining things is very ugly. */
7042 display_loc_list_dwo (struct dwarf_section
*section
,
7043 unsigned char **start_ptr
,
7044 unsigned int debug_info_entry
,
7046 unsigned char **vstart_ptr
,
7049 unsigned char *start
= *start_ptr
, *vstart
= *vstart_ptr
;
7050 unsigned char *section_end
= section
->start
+ section
->size
;
7052 unsigned int pointer_size
;
7053 unsigned int offset_size
;
7056 unsigned short length
;
7057 int need_frame_base
;
7060 if (debug_info_entry
>= num_debug_info_entries
)
7062 warn (_("No debug information for loc lists of entry: %u\n"),
7067 cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
7068 pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
7069 offset_size
= debug_information
[debug_info_entry
].offset_size
;
7070 dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
7072 if (pointer_size
< 2 || pointer_size
> 8)
7074 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
7075 pointer_size
, debug_info_entry
);
7082 print_hex (offset
+ (start
- *start_ptr
), 4);
7084 if (start
>= section_end
)
7086 warn (_("Location list starting at offset %#" PRIx64
7087 " is not terminated.\n"), offset
);
7091 SAFE_BYTE_GET_AND_INC (entry_type
, start
, 1, section_end
);
7104 uint64_t off
= offset
+ (vstart
- *start_ptr
);
7106 READ_ULEB (view
, vstart
, section_end
);
7107 print_view (view
, 8);
7109 READ_ULEB (view
, vstart
, section_end
);
7110 print_view (view
, 8);
7112 printf (_("views at %8.8" PRIx64
" for:\n %*s "), off
, 8, "");
7120 case 0: /* A terminating entry. */
7122 *vstart_ptr
= vstart
;
7123 printf (_("<End of list>\n"));
7125 case 1: /* A base-address entry. */
7126 READ_ULEB (idx
, start
, section_end
);
7127 print_addr_index (idx
, 8);
7128 printf ("%*s", 9 + (vstart
? 2 * 6 : 0), "");
7129 printf (_("(base address selection entry)\n"));
7131 case 2: /* A start/end entry. */
7132 READ_ULEB (idx
, start
, section_end
);
7133 print_addr_index (idx
, 8);
7134 READ_ULEB (idx
, start
, section_end
);
7135 print_addr_index (idx
, 8);
7137 case 3: /* A start/length entry. */
7138 READ_ULEB (idx
, start
, section_end
);
7139 print_addr_index (idx
, 8);
7140 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
7141 printf ("%08x ", idx
);
7143 case 4: /* An offset pair entry. */
7144 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
7145 printf ("%08x ", idx
);
7146 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
7147 printf ("%08x ", idx
);
7150 warn (_("Unknown location list entry type 0x%x.\n"), entry_type
);
7152 *vstart_ptr
= vstart
;
7156 if (2 > (size_t) (section_end
- start
))
7158 warn (_("Location list starting at offset %#" PRIx64
7159 " is not terminated.\n"), offset
);
7163 SAFE_BYTE_GET_AND_INC (length
, start
, 2, section_end
);
7164 if (length
> (size_t) (section_end
- start
))
7166 warn (_("Location list starting at offset %#" PRIx64
7167 " is not terminated.\n"), offset
);
7172 need_frame_base
= decode_location_expression (start
,
7177 cu_offset
, section
);
7180 if (need_frame_base
&& !has_frame_base
)
7181 printf (_(" [without DW_AT_frame_base]"));
7189 *vstart_ptr
= vstart
;
7192 /* Sort array of indexes in ascending order of loc_offsets[idx] and
7195 static uint64_t *loc_offsets
, *loc_views
;
7198 loc_offsets_compar (const void *ap
, const void *bp
)
7200 uint64_t a
= loc_offsets
[*(const unsigned int *) ap
];
7201 uint64_t b
= loc_offsets
[*(const unsigned int *) bp
];
7203 int ret
= (a
> b
) - (b
> a
);
7207 a
= loc_views
[*(const unsigned int *) ap
];
7208 b
= loc_views
[*(const unsigned int *) bp
];
7210 ret
= (a
> b
) - (b
> a
);
7215 /* Reads and dumps the DWARFv5 loclists compiler unit header,
7216 including the offset table.
7217 Returns the offset of the next compile unit header. */
7220 display_loclists_unit_header (struct dwarf_section
* section
,
7221 uint64_t header_offset
,
7222 uint32_t * offset_count
,
7223 unsigned char ** loclists_start
)
7226 unsigned char *start
= section
->start
+ header_offset
;
7227 unsigned char *end
= section
->start
+ section
->size
;
7228 unsigned short version
;
7229 unsigned char address_size
;
7230 unsigned char segment_selector_size
;
7234 printf (_("Table at Offset %#" PRIx64
"\n"), header_offset
);
7236 SAFE_BYTE_GET_AND_INC (length
, start
, 4, end
);
7237 if (length
== 0xffffffff)
7240 SAFE_BYTE_GET_AND_INC (length
, start
, 8, end
);
7245 SAFE_BYTE_GET_AND_INC (version
, start
, 2, end
);
7246 SAFE_BYTE_GET_AND_INC (address_size
, start
, 1, end
);
7247 SAFE_BYTE_GET_AND_INC (segment_selector_size
, start
, 1, end
);
7248 SAFE_BYTE_GET_AND_INC (*offset_count
, start
, 4, end
);
7250 printf (_(" Length: %#" PRIx64
"\n"), length
);
7251 printf (_(" DWARF version: %u\n"), version
);
7252 printf (_(" Address size: %u\n"), address_size
);
7253 printf (_(" Segment size: %u\n"), segment_selector_size
);
7254 printf (_(" Offset entries: %u\n"), *offset_count
);
7256 if (segment_selector_size
!= 0)
7258 warn (_("The %s section contains an "
7259 "unsupported segment selector size: %d.\n"),
7260 section
->name
, segment_selector_size
);
7261 return (uint64_t)-1;
7266 printf (_("\n Offset Entries starting at %#tx:\n"),
7267 start
- section
->start
);
7269 for (i
= 0; i
< *offset_count
; i
++)
7273 SAFE_BYTE_GET_AND_INC (entry
, start
, is_64bit
? 8 : 4, end
);
7274 printf (_(" [%6u] %#" PRIx64
"\n"), i
, entry
);
7279 *loclists_start
= start
;
7281 /* The length field doesn't include the length field itself. */
7282 return header_offset
+ length
+ (is_64bit
? 12 : 4);
7286 display_debug_loc (struct dwarf_section
*section
, void *file
)
7288 unsigned char *start
= section
->start
, *vstart
= NULL
;
7290 unsigned char *section_begin
= start
;
7291 unsigned int num_loc_list
= 0;
7292 uint64_t last_offset
= 0;
7293 uint64_t last_view
= 0;
7294 unsigned int first
= 0;
7297 int seen_first_offset
= 0;
7298 int locs_sorted
= 1;
7299 unsigned char *next
= start
, *vnext
= vstart
;
7300 unsigned int *array
= NULL
;
7301 const char *suffix
= strrchr (section
->name
, '.');
7302 bool is_dwo
= false;
7303 int is_loclists
= strstr (section
->name
, "debug_loclists") != NULL
;
7304 uint64_t next_header_offset
= 0;
7306 if (suffix
&& strcmp (suffix
, ".dwo") == 0)
7309 bytes
= section
->size
;
7313 printf (_("\nThe %s section is empty.\n"), section
->name
);
7319 unsigned char *hdrptr
= section_begin
;
7321 unsigned short ll_version
;
7322 unsigned char *end
= section_begin
+ section
->size
;
7323 unsigned char address_size
, segment_selector_size
;
7324 uint32_t offset_entry_count
;
7326 SAFE_BYTE_GET_AND_INC (ll_length
, hdrptr
, 4, end
);
7327 if (ll_length
== 0xffffffff)
7328 SAFE_BYTE_GET_AND_INC (ll_length
, hdrptr
, 8, end
);
7330 SAFE_BYTE_GET_AND_INC (ll_version
, hdrptr
, 2, end
);
7331 if (ll_version
!= 5)
7333 warn (_("The %s section contains corrupt or "
7334 "unsupported version number: %d.\n"),
7335 section
->name
, ll_version
);
7339 SAFE_BYTE_GET_AND_INC (address_size
, hdrptr
, 1, end
);
7341 SAFE_BYTE_GET_AND_INC (segment_selector_size
, hdrptr
, 1, end
);
7342 if (segment_selector_size
!= 0)
7344 warn (_("The %s section contains "
7345 "unsupported segment selector size: %d.\n"),
7346 section
->name
, segment_selector_size
);
7350 SAFE_BYTE_GET_AND_INC (offset_entry_count
, hdrptr
, 4, end
);
7352 /*if (offset_entry_count != 0)
7353 return display_offset_entry_loclists (section);*/
7355 //header_size = hdrptr - section_begin;
7358 if (load_debug_info (file
) == 0)
7360 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
7365 /* Check the order of location list in .debug_info section. If
7366 offsets of location lists are in the ascending order, we can
7367 use `debug_information' directly. */
7368 for (i
= 0; i
< num_debug_info_entries
; i
++)
7372 num
= debug_information
[i
].num_loc_offsets
;
7373 if (num
> num_loc_list
)
7376 /* Check if we can use `debug_information' directly. */
7377 if (locs_sorted
&& num
!= 0)
7379 if (!seen_first_offset
)
7381 /* This is the first location list. */
7382 last_offset
= debug_information
[i
].loc_offsets
[0];
7383 last_view
= debug_information
[i
].loc_views
[0];
7385 seen_first_offset
= 1;
7391 for (; j
< num
; j
++)
7394 debug_information
[i
].loc_offsets
[j
]
7395 || (last_offset
== debug_information
[i
].loc_offsets
[j
]
7396 && last_view
> debug_information
[i
].loc_views
[j
]))
7401 last_offset
= debug_information
[i
].loc_offsets
[j
];
7402 last_view
= debug_information
[i
].loc_views
[j
];
7407 if (!seen_first_offset
)
7408 error (_("No location lists in .debug_info section!\n"));
7411 array
= (unsigned int *) xcmalloc (num_loc_list
, sizeof (unsigned int));
7413 introduce (section
, false);
7415 if (reloc_at (section
, 0))
7416 printf (_(" Warning: This section has relocations - addresses seen here may not be accurate.\n\n"));
7419 printf (_(" Offset Begin End Expression\n"));
7421 for (i
= first
; i
< num_debug_info_entries
; i
++)
7423 uint64_t offset
= 0, voffset
= 0;
7424 uint64_t base_address
;
7427 debug_info
*debug_info_p
= debug_information
+ i
;
7428 uint32_t offset_count
;
7433 for (k
= 0; k
< debug_info_p
->num_loc_offsets
; k
++)
7435 loc_offsets
= debug_info_p
->loc_offsets
;
7436 loc_views
= debug_info_p
->loc_views
;
7437 qsort (array
, debug_info_p
->num_loc_offsets
,
7438 sizeof (*array
), loc_offsets_compar
);
7441 /* .debug_loclists has a per-unit header.
7442 Update start if we are detecting it. */
7443 if (debug_info_p
->dwarf_version
== 5)
7445 j
= locs_sorted
? 0 : array
[0];
7447 if (debug_info_p
->num_loc_offsets
)
7448 offset
= debug_info_p
->loc_offsets
[j
];
7450 if (debug_info_p
->num_loc_views
)
7451 voffset
= debug_info_p
->loc_views
[j
];
7453 /* Parse and dump unit headers in loclists.
7454 This will misbehave if the order of CUs in debug_info
7455 doesn't match the one in loclists. */
7456 if (next_header_offset
< offset
)
7458 while (next_header_offset
< offset
)
7460 next_header_offset
= display_loclists_unit_header
7461 (section
, next_header_offset
, &offset_count
, &start
);
7463 if (next_header_offset
== (uint64_t)-1)
7464 /* Header parsing error. */
7469 Offset Begin End Expression\n"));
7473 int adjacent_view_loclists
= 1;
7475 for (k
= 0; k
< debug_info_p
->num_loc_offsets
; k
++)
7477 j
= locs_sorted
? k
: array
[k
];
7479 && (debug_info_p
->loc_offsets
[locs_sorted
7480 ? k
- 1 : array
[k
- 1]]
7481 == debug_info_p
->loc_offsets
[j
])
7482 && (debug_info_p
->loc_views
[locs_sorted
7483 ? k
- 1 : array
[k
- 1]]
7484 == debug_info_p
->loc_views
[j
]))
7486 has_frame_base
= debug_info_p
->have_frame_base
[j
];
7487 offset
= debug_info_p
->loc_offsets
[j
];
7488 next
= section_begin
+ offset
;
7489 voffset
= debug_info_p
->loc_views
[j
];
7490 if (voffset
!= (uint64_t) -1)
7491 vnext
= section_begin
+ voffset
;
7494 base_address
= debug_info_p
->base_address
;
7496 if (vnext
&& vnext
< next
)
7499 display_view_pair_list (section
, &vstart
, i
, next
);
7506 if (vnext
&& vnext
< next
)
7507 warn (_("There is a hole [%#tx - %#" PRIx64
"]"
7508 " in %s section.\n"),
7509 start
- section_begin
, voffset
, section
->name
);
7511 warn (_("There is a hole [%#tx - %#" PRIx64
"]"
7512 " in %s section.\n"),
7513 start
- section_begin
, offset
, section
->name
);
7515 else if (start
> next
)
7516 warn (_("There is an overlap [%#tx - %#" PRIx64
"]"
7517 " in %s section.\n"),
7518 start
- section_begin
, offset
, section
->name
);
7522 if (offset
>= bytes
)
7524 warn (_("Offset %#" PRIx64
" is bigger than %s section size.\n"),
7525 offset
, section
->name
);
7529 if (vnext
&& voffset
>= bytes
)
7531 warn (_("View Offset %#" PRIx64
" is bigger than %s section size.\n"),
7532 voffset
, section
->name
);
7539 display_loc_list_dwo (section
, &start
, i
, offset
,
7540 &vstart
, has_frame_base
);
7542 display_loc_list (section
, &start
, i
, offset
, base_address
,
7543 &vstart
, has_frame_base
);
7548 warn (_("DWO is not yet supported.\n"));
7550 display_loclists_list (section
, &start
, debug_info_p
, offset
,
7551 base_address
, &vstart
, has_frame_base
);
7554 /* FIXME: this arrangement is quite simplistic. Nothing
7555 requires locview lists to be adjacent to corresponding
7556 loclists, and a single loclist could be augmented by
7557 different locview lists, and vice-versa, unlikely as it
7558 is that it would make sense to do so. Hopefully we'll
7559 have view pair support built into loclists before we ever
7560 need to address all these possibilities. */
7561 if (adjacent_view_loclists
&& vnext
7562 && vnext
!= start
&& vstart
!= next
)
7564 adjacent_view_loclists
= 0;
7565 warn (_("Hole and overlap detection requires adjacent view lists and loclists.\n"));
7568 if (vnext
&& vnext
== start
)
7569 display_view_pair_list (section
, &start
, i
, vstart
);
7573 if (start
< section
->start
+ section
->size
)
7574 warn (ngettext ("There is %ld unused byte at the end of section %s\n",
7575 "There are %ld unused bytes at the end of section %s\n",
7576 (long) (section
->start
+ section
->size
- start
)),
7577 (long) (section
->start
+ section
->size
- start
), section
->name
);
7584 display_debug_str (struct dwarf_section
*section
,
7585 void *file ATTRIBUTE_UNUSED
)
7587 unsigned char *start
= section
->start
;
7588 uint64_t bytes
= section
->size
;
7589 uint64_t addr
= section
->address
;
7593 printf (_("\nThe %s section is empty.\n"), section
->name
);
7597 introduce (section
, false);
7605 lbytes
= (bytes
> 16 ? 16 : bytes
);
7607 printf (" 0x%8.8" PRIx64
" ", addr
);
7609 for (j
= 0; j
< 16; j
++)
7612 printf ("%2.2x", start
[j
]);
7620 for (j
= 0; j
< lbytes
; j
++)
7623 if (k
>= ' ' && k
< 0x80)
7642 display_debug_info (struct dwarf_section
*section
, void *file
)
7644 return process_debug_info (section
, file
, section
->abbrev_sec
, false, false);
7648 display_debug_types (struct dwarf_section
*section
, void *file
)
7650 return process_debug_info (section
, file
, section
->abbrev_sec
, false, true);
7654 display_trace_info (struct dwarf_section
*section
, void *file
)
7656 return process_debug_info (section
, file
, section
->abbrev_sec
, false, true);
7660 display_debug_aranges (struct dwarf_section
*section
,
7661 void *file ATTRIBUTE_UNUSED
)
7663 unsigned char *start
= section
->start
;
7664 unsigned char *end
= start
+ section
->size
;
7666 introduce (section
, false);
7668 /* It does not matter if this load fails,
7669 we test for that later on. */
7670 load_debug_info (file
);
7674 unsigned char *hdrptr
;
7675 DWARF2_Internal_ARange arange
;
7676 unsigned char *addr_ranges
;
7680 unsigned char address_size
;
7681 unsigned int offset_size
;
7682 unsigned char *end_ranges
;
7685 sec_off
= hdrptr
- section
->start
;
7687 SAFE_BYTE_GET_AND_INC (arange
.ar_length
, hdrptr
, 4, end
);
7688 if (arange
.ar_length
== 0xffffffff)
7690 SAFE_BYTE_GET_AND_INC (arange
.ar_length
, hdrptr
, 8, end
);
7696 if (arange
.ar_length
> (size_t) (end
- hdrptr
))
7698 warn (_("Debug info is corrupted, %s header at %#" PRIx64
7699 " has length %#" PRIx64
"\n"),
7700 section
->name
, sec_off
, arange
.ar_length
);
7703 end_ranges
= hdrptr
+ arange
.ar_length
;
7705 SAFE_BYTE_GET_AND_INC (arange
.ar_version
, hdrptr
, 2, end_ranges
);
7706 SAFE_BYTE_GET_AND_INC (arange
.ar_info_offset
, hdrptr
, offset_size
,
7709 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
7710 && num_debug_info_entries
> 0
7711 && find_debug_info_for_offset (arange
.ar_info_offset
) == NULL
)
7712 warn (_(".debug_info offset of %#" PRIx64
7713 " in %s section does not point to a CU header.\n"),
7714 arange
.ar_info_offset
, section
->name
);
7716 SAFE_BYTE_GET_AND_INC (arange
.ar_pointer_size
, hdrptr
, 1, end_ranges
);
7717 SAFE_BYTE_GET_AND_INC (arange
.ar_segment_size
, hdrptr
, 1, end_ranges
);
7719 if (arange
.ar_version
!= 2 && arange
.ar_version
!= 3)
7721 /* PR 19872: A version number of 0 probably means that there is
7722 padding at the end of the .debug_aranges section. Gold puts
7723 it there when performing an incremental link, for example.
7724 So do not generate a warning in this case. */
7725 if (arange
.ar_version
)
7726 warn (_("Only DWARF 2 and 3 aranges are currently supported.\n"));
7730 printf (_(" Length: %" PRId64
"\n"), arange
.ar_length
);
7731 printf (_(" Version: %d\n"), arange
.ar_version
);
7732 printf (_(" Offset into .debug_info: %#" PRIx64
"\n"),
7733 arange
.ar_info_offset
);
7734 printf (_(" Pointer Size: %d\n"), arange
.ar_pointer_size
);
7735 printf (_(" Segment Size: %d\n"), arange
.ar_segment_size
);
7737 address_size
= arange
.ar_pointer_size
+ arange
.ar_segment_size
;
7739 /* PR 17512: file: 001-108546-0.001:0.1. */
7740 if (address_size
== 0 || address_size
> 8)
7742 error (_("Invalid address size in %s section!\n"),
7747 /* The DWARF spec does not require that the address size be a power
7748 of two, but we do. This will have to change if we ever encounter
7749 an uneven architecture. */
7750 if ((address_size
& (address_size
- 1)) != 0)
7752 warn (_("Pointer size + Segment size is not a power of two.\n"));
7756 if (address_size
> 4)
7757 printf (_("\n Address Length\n"));
7759 printf (_("\n Address Length\n"));
7761 addr_ranges
= hdrptr
;
7763 /* Must pad to an alignment boundary that is twice the address size. */
7764 addr_ranges
+= (2 * address_size
- 1
7765 - (hdrptr
- start
- 1) % (2 * address_size
));
7767 while (2 * address_size
<= end_ranges
- addr_ranges
)
7769 SAFE_BYTE_GET_AND_INC (address
, addr_ranges
, address_size
,
7771 SAFE_BYTE_GET_AND_INC (length
, addr_ranges
, address_size
,
7774 print_hex (address
, address_size
);
7775 print_hex_ns (length
, address_size
);
7787 /* Comparison function for qsort. */
7789 comp_addr_base (const void * v0
, const void * v1
)
7791 debug_info
*info0
= *(debug_info
**) v0
;
7792 debug_info
*info1
= *(debug_info
**) v1
;
7793 return info0
->addr_base
- info1
->addr_base
;
7796 /* Display the debug_addr section. */
7798 display_debug_addr (struct dwarf_section
*section
,
7801 debug_info
**debug_addr_info
;
7802 unsigned char *entry
;
7806 unsigned char * header
;
7808 if (section
->size
== 0)
7810 printf (_("\nThe %s section is empty.\n"), section
->name
);
7814 if (load_debug_info (file
) == 0)
7816 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
7821 introduce (section
, false);
7823 /* PR 17531: file: cf38d01b.
7824 We use xcalloc because a corrupt file may not have initialised all of the
7825 fields in the debug_info structure, which means that the sort below might
7826 try to move uninitialised data. */
7827 debug_addr_info
= (debug_info
**) xcalloc ((num_debug_info_entries
+ 1),
7828 sizeof (debug_info
*));
7831 for (i
= 0; i
< num_debug_info_entries
; i
++)
7832 if (debug_information
[i
].addr_base
!= DEBUG_INFO_UNAVAILABLE
)
7834 /* PR 17531: file: cf38d01b. */
7835 if (debug_information
[i
].addr_base
>= section
->size
)
7836 warn (_("Corrupt address base (%#" PRIx64
")"
7837 " found in debug section %u\n"),
7838 debug_information
[i
].addr_base
, i
);
7840 debug_addr_info
[count
++] = debug_information
+ i
;
7843 /* Add a sentinel to make iteration convenient. */
7844 debug_addr_info
[count
] = (debug_info
*) xmalloc (sizeof (debug_info
));
7845 debug_addr_info
[count
]->addr_base
= section
->size
;
7846 qsort (debug_addr_info
, count
, sizeof (debug_info
*), comp_addr_base
);
7848 header
= section
->start
;
7849 for (i
= 0; i
< count
; i
++)
7852 unsigned int address_size
= debug_addr_info
[i
]->pointer_size
;
7854 printf (_(" For compilation unit at offset %#" PRIx64
":\n"),
7855 debug_addr_info
[i
]->cu_offset
);
7857 printf (_("\tIndex\tAddress\n"));
7858 entry
= section
->start
+ debug_addr_info
[i
]->addr_base
;
7859 if (debug_addr_info
[i
]->dwarf_version
>= 5)
7861 size_t header_size
= entry
- header
;
7862 unsigned char *curr_header
= header
;
7865 int segment_selector_size
;
7867 if (header_size
!= 8 && header_size
!= 16)
7869 warn (_("Corrupt %s section: expecting header size of 8 or 16, but found %zd instead\n"),
7870 section
->name
, header_size
);
7874 SAFE_BYTE_GET_AND_INC (length
, curr_header
, 4, entry
);
7875 if (length
== 0xffffffff)
7876 SAFE_BYTE_GET_AND_INC (length
, curr_header
, 8, entry
);
7877 if (length
> (size_t) (section
->start
+ section
->size
- curr_header
)
7878 || length
< (size_t) (entry
- curr_header
))
7880 warn (_("Corrupt %s section: unit_length field of %#" PRIx64
7881 " is invalid\n"), section
->name
, length
);
7884 end
= curr_header
+ length
;
7885 SAFE_BYTE_GET_AND_INC (version
, curr_header
, 2, entry
);
7887 warn (_("Corrupt %s section: expecting version number 5 in header but found %d instead\n"),
7888 section
->name
, version
);
7890 SAFE_BYTE_GET_AND_INC (address_size
, curr_header
, 1, entry
);
7891 SAFE_BYTE_GET_AND_INC (segment_selector_size
, curr_header
, 1, entry
);
7892 address_size
+= segment_selector_size
;
7895 end
= section
->start
+ debug_addr_info
[i
+ 1]->addr_base
;
7900 if (address_size
< 1 || address_size
> sizeof (uint64_t))
7902 warn (_("Corrupt %s section: address size (%x) is wrong\n"),
7903 section
->name
, address_size
);
7907 while ((size_t) (end
- entry
) >= address_size
)
7909 uint64_t base
= byte_get (entry
, address_size
);
7910 printf (_("\t%d:\t"), idx
);
7911 print_hex_ns (base
, address_size
);
7913 entry
+= address_size
;
7919 free (debug_addr_info
[count
]);
7920 free (debug_addr_info
);
7924 /* Display the .debug_str_offsets and .debug_str_offsets.dwo sections. */
7927 display_debug_str_offsets (struct dwarf_section
*section
,
7928 void *file ATTRIBUTE_UNUSED
)
7932 if (section
->size
== 0)
7934 printf (_("\nThe %s section is empty.\n"), section
->name
);
7938 unsigned char *start
= section
->start
;
7939 unsigned char *end
= start
+ section
->size
;
7940 unsigned char *curr
= start
;
7941 uint64_t debug_str_offsets_hdr_len
;
7943 const char *suffix
= strrchr (section
->name
, '.');
7944 bool dwo
= suffix
&& strcmp (suffix
, ".dwo") == 0;
7947 load_debug_section_with_follow (str_dwo
, file
);
7949 load_debug_section_with_follow (str
, file
);
7951 introduce (section
, false);
7956 uint64_t entry_length
;
7958 SAFE_BYTE_GET_AND_INC (length
, curr
, 4, end
);
7959 /* FIXME: We assume that this means 64-bit DWARF is being used. */
7960 if (length
== 0xffffffff)
7962 SAFE_BYTE_GET_AND_INC (length
, curr
, 8, end
);
7964 debug_str_offsets_hdr_len
= 16;
7969 debug_str_offsets_hdr_len
= 8;
7972 unsigned char *entries_end
;
7975 /* This is probably an old style .debug_str_offset section which
7976 just contains offsets and no header (and the first offset is 0). */
7977 length
= section
->size
;
7978 curr
= section
->start
;
7980 debug_str_offsets_hdr_len
= 0;
7982 printf (_(" Length: %#" PRIx64
"\n"), length
);
7983 printf (_(" Index Offset [String]\n"));
7987 if (length
<= (size_t) (end
- curr
))
7988 entries_end
= curr
+ length
;
7991 warn (_("Section %s is too small %#" PRIx64
"\n"),
7992 section
->name
, section
->size
);
7997 SAFE_BYTE_GET_AND_INC (version
, curr
, 2, entries_end
);
7999 warn (_("Unexpected version number in str_offset header: %#x\n"), version
);
8002 SAFE_BYTE_GET_AND_INC (padding
, curr
, 2, entries_end
);
8004 warn (_("Unexpected value in str_offset header's padding field: %#x\n"), padding
);
8006 printf (_(" Length: %#" PRIx64
"\n"), length
);
8007 printf (_(" Version: %#x\n"), version
);
8008 printf (_(" Index Offset [String]\n"));
8011 for (idx
= 0; curr
< entries_end
; idx
++)
8014 const unsigned char * string
;
8016 if ((size_t) (entries_end
- curr
) < entry_length
)
8017 /* Not enough space to read one entry_length, give up. */
8020 SAFE_BYTE_GET_AND_INC (offset
, curr
, entry_length
, entries_end
);
8022 string
= (const unsigned char *)
8023 fetch_indexed_string (idx
, NULL
, entry_length
, dwo
, debug_str_offsets_hdr_len
);
8025 string
= fetch_indirect_string (offset
);
8027 printf (" %8lu ", idx
);
8028 print_hex (offset
, entry_length
);
8029 printf (" %s\n", string
);
8036 /* Each debug_information[x].range_lists[y] gets this representation for
8037 sorting purposes. */
8041 /* The debug_information[x].range_lists[y] value. */
8042 uint64_t ranges_offset
;
8044 /* Original debug_information to find parameters of the data. */
8045 debug_info
*debug_info_p
;
8048 /* Sort struct range_entry in ascending order of its RANGES_OFFSET. */
8051 range_entry_compar (const void *ap
, const void *bp
)
8053 const struct range_entry
*a_re
= (const struct range_entry
*) ap
;
8054 const struct range_entry
*b_re
= (const struct range_entry
*) bp
;
8055 const uint64_t a
= a_re
->ranges_offset
;
8056 const uint64_t b
= b_re
->ranges_offset
;
8058 return (a
> b
) - (b
> a
);
8062 display_debug_ranges_list (unsigned char * start
,
8063 unsigned char * finish
,
8064 unsigned int pointer_size
,
8066 uint64_t base_address
)
8068 while (start
< finish
)
8073 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
8074 if (start
>= finish
)
8076 SAFE_SIGNED_BYTE_GET_AND_INC (end
, start
, pointer_size
, finish
);
8079 print_hex (offset
, 4);
8081 if (begin
== 0 && end
== 0)
8083 printf (_("<End of list>\n"));
8087 /* Check base address specifiers. */
8088 if (is_max_address (begin
, pointer_size
)
8089 && !is_max_address (end
, pointer_size
))
8092 print_hex (begin
, pointer_size
);
8093 print_hex (end
, pointer_size
);
8094 printf ("(base address)\n");
8098 print_hex (begin
+ base_address
, pointer_size
);
8099 print_hex_ns (end
+ base_address
, pointer_size
);
8102 fputs (_(" (start == end)"), stdout
);
8103 else if (begin
> end
)
8104 fputs (_(" (start > end)"), stdout
);
8110 static unsigned char *
8111 display_debug_rnglists_list (unsigned char * start
,
8112 unsigned char * finish
,
8113 unsigned int pointer_size
,
8115 uint64_t base_address
,
8118 unsigned char *next
= start
;
8122 uint64_t off
= offset
+ (start
- next
);
8123 enum dwarf_range_list_entry rlet
;
8124 /* Initialize it due to a false compiler warning. */
8125 uint64_t begin
= -1, length
, end
= -1;
8127 if (start
>= finish
)
8129 warn (_("Range list starting at offset %#" PRIx64
8130 " is not terminated.\n"), offset
);
8137 SAFE_BYTE_GET_AND_INC (rlet
, start
, 1, finish
);
8141 case DW_RLE_end_of_list
:
8142 printf (_("<End of list>\n"));
8144 case DW_RLE_base_addressx
:
8145 READ_ULEB (base_address
, start
, finish
);
8146 print_hex (base_address
, pointer_size
);
8147 printf (_("(base address index) "));
8148 base_address
= fetch_indexed_addr ((base_address
* pointer_size
) + addr_base
,
8150 print_hex (base_address
, pointer_size
);
8151 printf (_("(base address)\n"));
8153 case DW_RLE_startx_endx
:
8154 READ_ULEB (begin
, start
, finish
);
8155 READ_ULEB (end
, start
, finish
);
8156 begin
= fetch_indexed_addr ((begin
* pointer_size
) + addr_base
,
8158 end
= fetch_indexed_addr ((begin
* pointer_size
) + addr_base
,
8161 case DW_RLE_startx_length
:
8162 READ_ULEB (begin
, start
, finish
);
8163 READ_ULEB (length
, start
, finish
);
8164 begin
= fetch_indexed_addr ((begin
* pointer_size
) + addr_base
,
8166 end
= begin
+ length
;
8168 case DW_RLE_offset_pair
:
8169 READ_ULEB (begin
, start
, finish
);
8170 READ_ULEB (end
, start
, finish
);
8172 case DW_RLE_base_address
:
8173 SAFE_BYTE_GET_AND_INC (base_address
, start
, pointer_size
, finish
);
8174 print_hex (base_address
, pointer_size
);
8175 printf (_("(base address)\n"));
8177 case DW_RLE_start_end
:
8178 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
8179 SAFE_BYTE_GET_AND_INC (end
, start
, pointer_size
, finish
);
8181 case DW_RLE_start_length
:
8182 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
8183 READ_ULEB (length
, start
, finish
);
8184 end
= begin
+ length
;
8187 error (_("Invalid range list entry type %d\n"), rlet
);
8188 rlet
= DW_RLE_end_of_list
;
8192 if (rlet
== DW_RLE_end_of_list
)
8194 if (rlet
== DW_RLE_base_address
|| rlet
== DW_RLE_base_addressx
)
8197 /* Only a DW_RLE_offset_pair needs the base address added. */
8198 if (rlet
== DW_RLE_offset_pair
)
8200 begin
+= base_address
;
8201 end
+= base_address
;
8204 print_hex (begin
, pointer_size
);
8205 print_hex (end
, pointer_size
);
8208 fputs (_(" (start == end)"), stdout
);
8209 else if (begin
> end
)
8210 fputs (_(" (start > end)"), stdout
);
8219 display_debug_rnglists_unit_header (struct dwarf_section
* section
,
8220 uint64_t * unit_offset
,
8221 unsigned char * poffset_size
)
8223 uint64_t start_offset
= *unit_offset
;
8224 unsigned char * p
= section
->start
+ start_offset
;
8225 unsigned char * finish
= section
->start
+ section
->size
;
8226 uint64_t initial_length
;
8227 unsigned char segment_selector_size
;
8228 unsigned int offset_entry_count
;
8230 unsigned short version
;
8231 unsigned char address_size
= 0;
8232 unsigned char offset_size
;
8234 /* Get and check the length of the block. */
8235 SAFE_BYTE_GET_AND_INC (initial_length
, p
, 4, finish
);
8237 if (initial_length
== 0xffffffff)
8239 /* This section is 64-bit DWARF 3. */
8240 SAFE_BYTE_GET_AND_INC (initial_length
, p
, 8, finish
);
8241 *poffset_size
= offset_size
= 8;
8244 *poffset_size
= offset_size
= 4;
8246 if (initial_length
> (size_t) (finish
- p
))
8248 /* If the length field has a relocation against it, then we should
8249 not complain if it is inaccurate (and probably negative).
8250 It is copied from .debug_line handling code. */
8251 if (reloc_at (section
, (p
- section
->start
) - offset_size
))
8252 initial_length
= finish
- p
;
8255 warn (_("The length field (%#" PRIx64
8256 ") in the debug_rnglists header is wrong"
8257 " - the section is too small\n"),
8263 /* Report the next unit offset to the caller. */
8264 *unit_offset
= (p
- section
->start
) + initial_length
;
8266 /* Get the other fields in the header. */
8267 SAFE_BYTE_GET_AND_INC (version
, p
, 2, finish
);
8268 SAFE_BYTE_GET_AND_INC (address_size
, p
, 1, finish
);
8269 SAFE_BYTE_GET_AND_INC (segment_selector_size
, p
, 1, finish
);
8270 SAFE_BYTE_GET_AND_INC (offset_entry_count
, p
, 4, finish
);
8272 printf (_(" Table at Offset: %#" PRIx64
":\n"), start_offset
);
8273 printf (_(" Length: %#" PRIx64
"\n"), initial_length
);
8274 printf (_(" DWARF version: %u\n"), version
);
8275 printf (_(" Address size: %u\n"), address_size
);
8276 printf (_(" Segment size: %u\n"), segment_selector_size
);
8277 printf (_(" Offset entries: %u\n"), offset_entry_count
);
8279 /* Check the fields. */
8280 if (segment_selector_size
!= 0)
8282 warn (_("The %s section contains "
8283 "unsupported segment selector size: %d.\n"),
8284 section
->name
, segment_selector_size
);
8290 warn (_("Only DWARF version 5+ debug_rnglists info "
8291 "is currently supported.\n"));
8295 if (offset_entry_count
!= 0)
8297 printf (_("\n Offsets starting at %#tx:\n"), p
- section
->start
);
8299 for (i
= 0; i
< offset_entry_count
; i
++)
8303 SAFE_BYTE_GET_AND_INC (entry
, p
, offset_size
, finish
);
8304 printf (_(" [%6u] %#" PRIx64
"\n"), i
, entry
);
8312 is_range_list_for_this_section (bool is_rnglists
, unsigned int version
)
8314 if (is_rnglists
&& version
> 4)
8317 if (! is_rnglists
&& version
< 5)
8324 display_debug_ranges (struct dwarf_section
*section
,
8325 void *file ATTRIBUTE_UNUSED
)
8327 unsigned char *start
= section
->start
;
8328 unsigned char *last_start
= start
;
8329 uint64_t bytes
= section
->size
;
8330 unsigned char *section_begin
= start
;
8331 unsigned char *finish
= start
+ bytes
;
8332 unsigned int num_range_list
, i
;
8333 struct range_entry
*range_entries
;
8334 struct range_entry
*range_entry_fill
;
8335 bool is_rnglists
= strstr (section
->name
, "debug_rnglists") != NULL
;
8336 uint64_t last_offset
= 0;
8337 uint64_t next_rnglists_cu_offset
= 0;
8338 unsigned char offset_size
;
8342 printf (_("\nThe %s section is empty.\n"), section
->name
);
8346 introduce (section
, false);
8348 if (load_debug_info (file
) == 0)
8350 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
8356 for (i
= 0; i
< num_debug_info_entries
; i
++)
8357 if (is_range_list_for_this_section (is_rnglists
, debug_information
[i
].dwarf_version
))
8358 num_range_list
+= debug_information
[i
].num_range_lists
;
8360 if (num_range_list
== 0)
8362 /* This can happen when the file was compiled with -gsplit-debug
8363 which removes references to range lists from the primary .o file. */
8364 printf (_("No range lists referenced by .debug_info section.\n"));
8368 range_entry_fill
= range_entries
= XNEWVEC (struct range_entry
, num_range_list
);
8370 for (i
= 0; i
< num_debug_info_entries
; i
++)
8372 debug_info
*debug_info_p
= &debug_information
[i
];
8375 for (j
= 0; j
< debug_info_p
->num_range_lists
; j
++)
8377 if (is_range_list_for_this_section (is_rnglists
, debug_info_p
->dwarf_version
))
8379 range_entry_fill
->ranges_offset
= debug_info_p
->range_lists
[j
];
8380 range_entry_fill
->debug_info_p
= debug_info_p
;
8386 assert (range_entry_fill
>= range_entries
);
8387 assert (num_range_list
>= (unsigned int)(range_entry_fill
- range_entries
));
8388 num_range_list
= range_entry_fill
- range_entries
;
8389 qsort (range_entries
, num_range_list
, sizeof (*range_entries
),
8390 range_entry_compar
);
8392 if (dwarf_check
!= 0 && range_entries
[0].ranges_offset
!= 0)
8393 warn (_("Range lists in %s section start at %#" PRIx64
"\n"),
8394 section
->name
, range_entries
[0].ranges_offset
);
8398 printf (_(" Offset Begin End\n"));
8400 for (i
= 0; i
< num_range_list
; i
++)
8402 struct range_entry
*range_entry
= &range_entries
[i
];
8403 debug_info
*debug_info_p
= range_entry
->debug_info_p
;
8404 unsigned int pointer_size
;
8406 unsigned char *next
;
8407 uint64_t base_address
;
8409 pointer_size
= debug_info_p
->pointer_size
;
8410 offset
= range_entry
->ranges_offset
;
8411 base_address
= debug_info_p
->base_address
;
8413 /* PR 17512: file: 001-101485-0.001:0.1. */
8414 if (pointer_size
< 2 || pointer_size
> 8)
8416 warn (_("Corrupt pointer size (%d) in debug entry at offset %#" PRIx64
"\n"),
8417 pointer_size
, offset
);
8421 if (offset
> (size_t) (finish
- section_begin
))
8423 warn (_("Corrupt offset (%#" PRIx64
") in range entry %u\n"),
8428 /* If we've moved on to the next compile unit in the rnglists section - dump the unit header(s). */
8429 if (is_rnglists
&& next_rnglists_cu_offset
< offset
)
8431 while (next_rnglists_cu_offset
< offset
)
8432 display_debug_rnglists_unit_header (section
, &next_rnglists_cu_offset
, &offset_size
);
8433 printf (_(" Offset Begin End\n"));
8436 next
= section_begin
+ offset
; /* Offset is from the section start, the base has already been added. */
8438 /* If multiple DWARF entities reference the same range then we will
8439 have multiple entries in the `range_entries' list for the same
8440 offset. Thanks to the sort above these will all be consecutive in
8441 the `range_entries' list, so we can easily ignore duplicates
8443 if (i
> 0 && last_offset
== offset
)
8445 last_offset
= offset
;
8447 if (dwarf_check
!= 0 && i
> 0)
8450 warn (_("There is a hole [%#tx - %#tx] in %s section.\n"),
8451 start
- section_begin
, next
- section_begin
, section
->name
);
8452 else if (start
> next
)
8454 if (next
== last_start
)
8456 warn (_("There is an overlap [%#tx - %#tx] in %s section.\n"),
8457 start
- section_begin
, next
- section_begin
, section
->name
);
8465 display_debug_rnglists_list
8466 (start
, finish
, pointer_size
, offset
, base_address
, debug_info_p
->addr_base
);
8468 display_debug_ranges_list
8469 (start
, finish
, pointer_size
, offset
, base_address
);
8472 /* Display trailing empty (or unreferenced) compile units, if any. */
8474 while (next_rnglists_cu_offset
< section
->size
)
8475 display_debug_rnglists_unit_header (section
, &next_rnglists_cu_offset
, &offset_size
);
8479 free (range_entries
);
8484 typedef struct Frame_Chunk
8486 struct Frame_Chunk
*next
;
8487 unsigned char *chunk_start
;
8489 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
8490 short int *col_type
;
8491 int64_t *col_offset
;
8493 unsigned int code_factor
;
8497 unsigned int cfa_reg
;
8498 uint64_t cfa_offset
;
8500 unsigned char fde_encoding
;
8501 unsigned char cfa_exp
;
8502 unsigned char ptr_size
;
8503 unsigned char segment_size
;
8507 typedef const char *(*dwarf_regname_lookup_ftype
) (unsigned int);
8508 static dwarf_regname_lookup_ftype dwarf_regnames_lookup_func
;
8509 static const char *const *dwarf_regnames
;
8510 static unsigned int dwarf_regnames_count
;
8511 static bool is_aarch64
;
8513 /* A marker for a col_type that means this column was never referenced
8514 in the frame info. */
8515 #define DW_CFA_unreferenced (-1)
8517 /* Return 0 if no more space is needed, 1 if more space is needed,
8518 -1 for invalid reg. */
8521 frame_need_space (Frame_Chunk
*fc
, unsigned int reg
)
8523 unsigned int prev
= fc
->ncols
;
8525 if (reg
< (unsigned int) fc
->ncols
)
8528 if (dwarf_regnames_count
> 0
8529 && reg
> dwarf_regnames_count
)
8532 fc
->ncols
= reg
+ 1;
8533 /* PR 17512: file: 10450-2643-0.004.
8534 If reg == -1 then this can happen... */
8538 /* PR 17512: file: 2844a11d. */
8539 if (fc
->ncols
> 1024 && dwarf_regnames_count
== 0)
8541 error (_("Unfeasibly large register number: %u\n"), reg
);
8543 /* FIXME: 1024 is an arbitrary limit. Increase it if
8544 we ever encounter a valid binary that exceeds it. */
8548 fc
->col_type
= xcrealloc (fc
->col_type
, fc
->ncols
,
8549 sizeof (*fc
->col_type
));
8550 fc
->col_offset
= xcrealloc (fc
->col_offset
, fc
->ncols
,
8551 sizeof (*fc
->col_offset
));
8552 /* PR 17512: file:002-10025-0.005. */
8553 if (fc
->col_type
== NULL
|| fc
->col_offset
== NULL
)
8555 error (_("Out of memory allocating %u columns in dwarf frame arrays\n"),
8561 while (prev
< fc
->ncols
)
8563 fc
->col_type
[prev
] = DW_CFA_unreferenced
;
8564 fc
->col_offset
[prev
] = 0;
8570 static const char *const dwarf_regnames_i386
[] =
8572 "eax", "ecx", "edx", "ebx", /* 0 - 3 */
8573 "esp", "ebp", "esi", "edi", /* 4 - 7 */
8574 "eip", "eflags", NULL
, /* 8 - 10 */
8575 "st0", "st1", "st2", "st3", /* 11 - 14 */
8576 "st4", "st5", "st6", "st7", /* 15 - 18 */
8577 NULL
, NULL
, /* 19 - 20 */
8578 "xmm0", "xmm1", "xmm2", "xmm3", /* 21 - 24 */
8579 "xmm4", "xmm5", "xmm6", "xmm7", /* 25 - 28 */
8580 "mm0", "mm1", "mm2", "mm3", /* 29 - 32 */
8581 "mm4", "mm5", "mm6", "mm7", /* 33 - 36 */
8582 "fcw", "fsw", "mxcsr", /* 37 - 39 */
8583 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
, /* 40 - 47 */
8584 "tr", "ldtr", /* 48 - 49 */
8585 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 50 - 57 */
8586 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 58 - 65 */
8587 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 66 - 73 */
8588 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 74 - 81 */
8589 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 82 - 89 */
8590 NULL
, NULL
, NULL
, /* 90 - 92 */
8591 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7" /* 93 - 100 */
8594 static const char *const dwarf_regnames_iamcu
[] =
8596 "eax", "ecx", "edx", "ebx", /* 0 - 3 */
8597 "esp", "ebp", "esi", "edi", /* 4 - 7 */
8598 "eip", "eflags", NULL
, /* 8 - 10 */
8599 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 11 - 18 */
8600 NULL
, NULL
, /* 19 - 20 */
8601 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 21 - 28 */
8602 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 29 - 36 */
8603 NULL
, NULL
, NULL
, /* 37 - 39 */
8604 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
, /* 40 - 47 */
8605 "tr", "ldtr", /* 48 - 49 */
8606 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 50 - 57 */
8607 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 58 - 65 */
8608 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 66 - 73 */
8609 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 74 - 81 */
8610 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 82 - 89 */
8611 NULL
, NULL
, NULL
, /* 90 - 92 */
8612 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
/* 93 - 100 */
8616 init_dwarf_regnames_i386 (void)
8618 dwarf_regnames
= dwarf_regnames_i386
;
8619 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_i386
);
8620 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8624 init_dwarf_regnames_iamcu (void)
8626 dwarf_regnames
= dwarf_regnames_iamcu
;
8627 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_iamcu
);
8628 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8631 static const char *const DW_CFA_GNU_window_save_name
[] =
8633 "DW_CFA_GNU_window_save",
8634 "DW_CFA_AARCH64_negate_ra_state"
8637 static const char *const dwarf_regnames_x86_64
[] =
8639 "rax", "rdx", "rcx", "rbx",
8640 "rsi", "rdi", "rbp", "rsp",
8641 "r8", "r9", "r10", "r11",
8642 "r12", "r13", "r14", "r15",
8644 "xmm0", "xmm1", "xmm2", "xmm3",
8645 "xmm4", "xmm5", "xmm6", "xmm7",
8646 "xmm8", "xmm9", "xmm10", "xmm11",
8647 "xmm12", "xmm13", "xmm14", "xmm15",
8648 "st0", "st1", "st2", "st3",
8649 "st4", "st5", "st6", "st7",
8650 "mm0", "mm1", "mm2", "mm3",
8651 "mm4", "mm5", "mm6", "mm7",
8653 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
,
8654 "fs.base", "gs.base", NULL
, NULL
,
8656 "mxcsr", "fcw", "fsw",
8657 "xmm16", "xmm17", "xmm18", "xmm19",
8658 "xmm20", "xmm21", "xmm22", "xmm23",
8659 "xmm24", "xmm25", "xmm26", "xmm27",
8660 "xmm28", "xmm29", "xmm30", "xmm31",
8661 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 83 - 90 */
8662 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 91 - 98 */
8663 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 99 - 106 */
8664 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 107 - 114 */
8665 NULL
, NULL
, NULL
, /* 115 - 117 */
8666 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7",
8667 "bnd0", "bnd1", "bnd2", "bnd3",
8671 init_dwarf_regnames_x86_64 (void)
8673 dwarf_regnames
= dwarf_regnames_x86_64
;
8674 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_x86_64
);
8675 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8678 static const char *const dwarf_regnames_aarch64
[] =
8680 "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7",
8681 "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15",
8682 "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23",
8683 "x24", "x25", "x26", "x27", "x28", "x29", "x30", "sp",
8684 NULL
, "elr", NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
8685 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, "vg", "ffr",
8686 "p0", "p1", "p2", "p3", "p4", "p5", "p6", "p7",
8687 "p8", "p9", "p10", "p11", "p12", "p13", "p14", "p15",
8688 "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7",
8689 "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15",
8690 "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23",
8691 "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31",
8692 "z0", "z1", "z2", "z3", "z4", "z5", "z6", "z7",
8693 "z8", "z9", "z10", "z11", "z12", "z13", "z14", "z15",
8694 "z16", "z17", "z18", "z19", "z20", "z21", "z22", "z23",
8695 "z24", "z25", "z26", "z27", "z28", "z29", "z30", "z31",
8699 init_dwarf_regnames_aarch64 (void)
8701 dwarf_regnames
= dwarf_regnames_aarch64
;
8702 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_aarch64
);
8703 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8707 static const char *const dwarf_regnames_s390
[] =
8709 /* Avoid saying "r5 (r5)", so omit the names of r0-r15. */
8710 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
8711 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
8712 "f0", "f2", "f4", "f6", "f1", "f3", "f5", "f7",
8713 "f8", "f10", "f12", "f14", "f9", "f11", "f13", "f15",
8714 "cr0", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7",
8715 "cr8", "cr9", "cr10", "cr11", "cr12", "cr13", "cr14", "cr15",
8716 "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7",
8717 "a8", "a9", "a10", "a11", "a12", "a13", "a14", "a15",
8720 "v16", "v18", "v20", "v22", "v17", "v19", "v21", "v23",
8721 "v24", "v26", "v28", "v30", "v25", "v27", "v29", "v31",
8725 init_dwarf_regnames_s390 (void)
8727 dwarf_regnames
= dwarf_regnames_s390
;
8728 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_s390
);
8729 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8732 static const char *const dwarf_regnames_riscv
[] =
8734 "zero", "ra", "sp", "gp", "tp", "t0", "t1", "t2", /* 0 - 7 */
8735 "s0", "s1", "a0", "a1", "a2", "a3", "a4", "a5", /* 8 - 15 */
8736 "a6", "a7", "s2", "s3", "s4", "s5", "s6", "s7", /* 16 - 23 */
8737 "s8", "s9", "s10", "s11", "t3", "t4", "t5", "t6", /* 24 - 31 */
8738 "ft0", "ft1", "ft2", "ft3", "ft4", "ft5", "ft6", "ft7", /* 32 - 39 */
8739 "fs0", "fs1", /* 40 - 41 */
8740 "fa0", "fa1", "fa2", "fa3", "fa4", "fa5", "fa6", "fa7", /* 42 - 49 */
8741 "fs2", "fs3", "fs4", "fs5", "fs6", "fs7", "fs8", "fs9", /* 50 - 57 */
8742 "fs10", "fs11", /* 58 - 59 */
8743 "ft8", "ft9", "ft10", "ft11", /* 60 - 63 */
8744 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 64 - 71 */
8745 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 72 - 79 */
8746 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 80 - 87 */
8747 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 88 - 95 */
8748 "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", /* 96 - 103 */
8749 "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15", /* 104 - 111 */
8750 "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23", /* 112 - 119 */
8751 "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31", /* 120 - 127 */
8754 /* A RISC-V replacement for REGNAME_INTERNAL_BY_TABLE_ONLY which handles
8755 the large number of CSRs. */
8758 regname_internal_riscv (unsigned int regno
)
8760 const char *name
= NULL
;
8762 /* Lookup in the table first, this covers GPR and FPR. */
8763 if (regno
< ARRAY_SIZE (dwarf_regnames_riscv
))
8764 name
= dwarf_regnames_riscv
[regno
];
8765 else if (regno
>= 4096 && regno
<= 8191)
8767 /* This might be a CSR, these live in a sparse number space from 4096
8768 to 8191 These numbers are defined in the RISC-V ELF ABI
8772 #define DECLARE_CSR(NAME,VALUE,CLASS,DEFINE_VER,ABORT_VER) \
8773 case VALUE + 4096: name = #NAME; break;
8774 #include "opcode/riscv-opc.h"
8779 static char csr_name
[10];
8780 snprintf (csr_name
, sizeof (csr_name
), "csr%d", (regno
- 4096));
8791 init_dwarf_regnames_riscv (void)
8793 dwarf_regnames
= NULL
;
8794 dwarf_regnames_count
= 8192;
8795 dwarf_regnames_lookup_func
= regname_internal_riscv
;
8799 init_dwarf_regnames_by_elf_machine_code (unsigned int e_machine
)
8801 dwarf_regnames_lookup_func
= NULL
;
8807 init_dwarf_regnames_i386 ();
8811 init_dwarf_regnames_iamcu ();
8817 init_dwarf_regnames_x86_64 ();
8821 init_dwarf_regnames_aarch64 ();
8825 init_dwarf_regnames_s390 ();
8829 init_dwarf_regnames_riscv ();
8837 /* Initialize the DWARF register name lookup state based on the
8838 architecture and specific machine type of a BFD. */
8841 init_dwarf_regnames_by_bfd_arch_and_mach (enum bfd_architecture arch
,
8844 dwarf_regnames_lookup_func
= NULL
;
8852 case bfd_mach_x86_64
:
8853 case bfd_mach_x86_64_intel_syntax
:
8854 case bfd_mach_x64_32
:
8855 case bfd_mach_x64_32_intel_syntax
:
8856 init_dwarf_regnames_x86_64 ();
8860 init_dwarf_regnames_i386 ();
8865 case bfd_arch_iamcu
:
8866 init_dwarf_regnames_iamcu ();
8869 case bfd_arch_aarch64
:
8870 init_dwarf_regnames_aarch64();
8874 init_dwarf_regnames_s390 ();
8877 case bfd_arch_riscv
:
8878 init_dwarf_regnames_riscv ();
8887 regname_internal_by_table_only (unsigned int regno
)
8889 if (dwarf_regnames
!= NULL
8890 && regno
< dwarf_regnames_count
8891 && dwarf_regnames
[regno
] != NULL
)
8892 return dwarf_regnames
[regno
];
8898 regname (unsigned int regno
, int name_only_p
)
8900 static char reg
[64];
8902 const char *name
= NULL
;
8904 if (dwarf_regnames_lookup_func
!= NULL
)
8905 name
= dwarf_regnames_lookup_func (regno
);
8911 snprintf (reg
, sizeof (reg
), "r%d (%s)", regno
, name
);
8914 snprintf (reg
, sizeof (reg
), "r%d", regno
);
8919 frame_display_row (Frame_Chunk
*fc
, int *need_col_headers
, unsigned int *max_regs
)
8924 if (*max_regs
!= fc
->ncols
)
8925 *max_regs
= fc
->ncols
;
8927 if (*need_col_headers
)
8929 *need_col_headers
= 0;
8931 printf ("%-*s CFA ", eh_addr_size
* 2, " LOC");
8933 for (r
= 0; r
< *max_regs
; r
++)
8934 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
8939 printf ("%-5s ", regname (r
, 1));
8945 print_hex (fc
->pc_begin
, eh_addr_size
);
8947 strcpy (tmp
, "exp");
8949 sprintf (tmp
, "%s%+d", regname (fc
->cfa_reg
, 1), (int) fc
->cfa_offset
);
8950 printf ("%-8s ", tmp
);
8952 for (r
= 0; r
< fc
->ncols
; r
++)
8954 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
8956 switch (fc
->col_type
[r
])
8958 case DW_CFA_undefined
:
8961 case DW_CFA_same_value
:
8965 sprintf (tmp
, "c%+" PRId64
, fc
->col_offset
[r
]);
8967 case DW_CFA_val_offset
:
8968 sprintf (tmp
, "v%+" PRId64
, fc
->col_offset
[r
]);
8970 case DW_CFA_register
:
8971 sprintf (tmp
, "%s", regname (fc
->col_offset
[r
], 0));
8973 case DW_CFA_expression
:
8974 strcpy (tmp
, "exp");
8976 case DW_CFA_val_expression
:
8977 strcpy (tmp
, "vexp");
8980 strcpy (tmp
, "n/a");
8983 printf ("%-5s ", tmp
);
8989 #define GET(VAR, N) SAFE_BYTE_GET_AND_INC (VAR, start, N, end)
8991 static unsigned char *
8992 read_cie (unsigned char *start
, unsigned char *end
,
8993 Frame_Chunk
**p_cie
, int *p_version
,
8994 uint64_t *p_aug_len
, unsigned char **p_aug
)
8998 unsigned char *augmentation_data
= NULL
;
8999 uint64_t augmentation_data_len
= 0;
9002 /* PR 17512: file: 001-228113-0.004. */
9006 fc
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
9007 memset (fc
, 0, sizeof (Frame_Chunk
));
9009 fc
->col_type
= xmalloc (sizeof (*fc
->col_type
));
9010 fc
->col_offset
= xmalloc (sizeof (*fc
->col_offset
));
9014 fc
->augmentation
= (char *) start
;
9015 /* PR 17512: file: 001-228113-0.004.
9016 Skip past augmentation name, but avoid running off the end of the data. */
9018 if (* start
++ == '\0')
9022 warn (_("No terminator for augmentation name\n"));
9026 if (strcmp (fc
->augmentation
, "eh") == 0)
9028 if (eh_addr_size
> (size_t) (end
- start
))
9030 start
+= eh_addr_size
;
9035 if (2 > (size_t) (end
- start
))
9037 GET (fc
->ptr_size
, 1);
9038 if (fc
->ptr_size
< 1 || fc
->ptr_size
> 8)
9040 warn (_("Invalid pointer size (%d) in CIE data\n"), fc
->ptr_size
);
9044 GET (fc
->segment_size
, 1);
9045 /* PR 17512: file: e99d2804. */
9046 if (fc
->segment_size
> 8 || fc
->segment_size
+ fc
->ptr_size
> 8)
9048 warn (_("Invalid segment size (%d) in CIE data\n"), fc
->segment_size
);
9052 eh_addr_size
= fc
->ptr_size
;
9056 fc
->ptr_size
= eh_addr_size
;
9057 fc
->segment_size
= 0;
9060 READ_ULEB (fc
->code_factor
, start
, end
);
9061 READ_SLEB (fc
->data_factor
, start
, end
);
9072 READ_ULEB (fc
->ra
, start
, end
);
9075 if (fc
->augmentation
[0] == 'z')
9079 READ_ULEB (augmentation_data_len
, start
, end
);
9080 augmentation_data
= start
;
9081 /* PR 17512: file: 11042-2589-0.004. */
9082 if (augmentation_data_len
> (size_t) (end
- start
))
9084 warn (_("Augmentation data too long: %#" PRIx64
9085 ", expected at most %#tx\n"),
9086 augmentation_data_len
, end
- start
);
9089 start
+= augmentation_data_len
;
9092 if (augmentation_data_len
)
9096 unsigned char *qend
;
9098 p
= (unsigned char *) fc
->augmentation
+ 1;
9099 q
= augmentation_data
;
9100 qend
= q
+ augmentation_data_len
;
9102 while (p
< end
&& q
< qend
)
9107 q
+= 1 + size_of_encoded_value (*q
);
9109 fc
->fde_encoding
= *q
++;
9118 /* Note - it is OK if this loop terminates with q < qend.
9119 Padding may have been inserted to align the end of the CIE. */
9124 *p_version
= version
;
9127 *p_aug_len
= augmentation_data_len
;
9128 *p_aug
= augmentation_data
;
9133 free (fc
->col_offset
);
9134 free (fc
->col_type
);
9139 /* Prints out the contents on the DATA array formatted as unsigned bytes.
9140 If do_wide is not enabled, then formats the output to fit into 80 columns.
9141 PRINTED contains the number of characters already written to the current
9145 display_data (size_t printed
, const unsigned char *data
, size_t len
)
9147 if (do_wide
|| len
< ((80 - printed
) / 3))
9148 for (printed
= 0; printed
< len
; ++printed
)
9149 printf (" %02x", data
[printed
]);
9152 for (printed
= 0; printed
< len
; ++printed
)
9154 if (printed
% (80 / 3) == 0)
9156 printf (" %02x", data
[printed
]);
9161 /* Prints out the contents on the augmentation data array.
9162 If do_wide is not enabled, then formats the output to fit into 80 columns. */
9165 display_augmentation_data (const unsigned char * data
, uint64_t len
)
9169 i
= printf (_(" Augmentation data: "));
9170 display_data (i
, data
, len
);
9174 decode_eh_encoding (unsigned int value
)
9176 if (value
== DW_EH_PE_omit
)
9180 switch (value
& 0x0f)
9182 case DW_EH_PE_uleb128
: format
= "uleb128"; break;
9183 case DW_EH_PE_udata2
: format
= "udata2"; break;
9184 case DW_EH_PE_udata4
: format
= "udata4"; break;
9185 case DW_EH_PE_udata8
: format
= "udata8"; break;
9186 case DW_EH_PE_sleb128
: format
= "sleb128"; break;
9187 case DW_EH_PE_sdata2
: format
= "sdata2"; break;
9188 case DW_EH_PE_sdata4
: format
= "sdata4"; break;
9189 case DW_EH_PE_sdata8
: format
= "sdata8"; break;
9191 default: format
= "<unknown format>"; break; /* FIXME: Generate a warning ? */
9195 switch (value
& 0xf0)
9197 case DW_EH_PE_absptr
: application
= "absolute"; break;
9198 case DW_EH_PE_pcrel
: application
= "pcrel"; break;
9199 case DW_EH_PE_textrel
: application
= "textrel"; break; /* FIXME: Is this allowed ? */
9200 case DW_EH_PE_datarel
: application
= "datarel"; break;
9201 case DW_EH_PE_funcrel
: application
= "funcrel"; break; /* FIXME: Is this allowed ? */
9202 case DW_EH_PE_aligned
: application
= "aligned"; break; /* FIXME: Is this allowed ? */
9203 case DW_EH_PE_indirect
: application
= "indirect"; break; /* FIXME: Is this allowed ? */
9205 default: application
= "<unknown application method>"; break; /* FIXME: Generate a warning ? */
9208 static char buffer
[128];
9209 sprintf (buffer
, "%s, %s", format
, application
);
9213 /* Reads a value stored at START encoded according to ENCODING.
9214 Does not read from, or past, END.
9215 Upon success, returns the read value and sets * RETURN_LEN to
9216 the number of bytes read.
9217 Upon failure returns zero and sets * RETURN_LEN to 0.
9219 Note: does not perform any application transformations to the value. */
9222 get_encoded_eh_value (unsigned int encoding
,
9223 unsigned char * start
,
9224 unsigned char * end
,
9225 unsigned int * return_len
)
9230 unsigned char * old_start
;
9232 switch (encoding
& 0x0f)
9234 case DW_EH_PE_uleb128
:
9235 val
= read_leb128 (start
, end
, false, & len
, & status
);
9240 case DW_EH_PE_sleb128
:
9241 val
= read_leb128 (start
, end
, true, & len
, & status
);
9246 case DW_EH_PE_udata2
:
9248 SAFE_BYTE_GET_AND_INC (val
, start
, 2, end
);
9249 len
= start
- old_start
== 2 ? 2 : 0;
9252 case DW_EH_PE_udata4
:
9254 SAFE_BYTE_GET_AND_INC (val
, start
, 4, end
);
9255 len
= start
- old_start
== 4 ? 4 : 0;
9258 case DW_EH_PE_udata8
:
9260 SAFE_BYTE_GET_AND_INC (val
, start
, 8, end
);
9261 len
= start
- old_start
== 8 ? 8 : 0;
9264 case DW_EH_PE_sdata2
:
9266 SAFE_SIGNED_BYTE_GET_AND_INC (val
, start
, 2, end
);
9267 len
= start
- old_start
== 2 ? 2 : 0;
9270 case DW_EH_PE_sdata4
:
9272 SAFE_SIGNED_BYTE_GET_AND_INC (val
, start
, 4, end
);
9273 len
= start
- old_start
== 4 ? 4 : 0;
9276 case DW_EH_PE_sdata8
:
9278 SAFE_SIGNED_BYTE_GET_AND_INC (val
, start
, 8, end
);
9279 len
= start
- old_start
== 8 ? 8 : 0;
9296 encoded_eh_offset (unsigned int encoding
,
9297 struct dwarf_section
* section
,
9298 uint64_t section_offset
,
9301 switch (encoding
& 0xf0)
9304 /* This should not happen. FIXME: warn ? */
9305 case DW_EH_PE_absptr
:
9308 case DW_EH_PE_pcrel
:
9309 return value
+ (uint64_t)(section
->address
+ section_offset
);
9311 case DW_EH_PE_datarel
:
9312 return value
+ (uint64_t)section
->address
;
9317 display_eh_frame_hdr (struct dwarf_section
*section
,
9318 void *file ATTRIBUTE_UNUSED
)
9320 unsigned char *start
= section
->start
;
9321 unsigned char *end
= start
+ section
->size
;
9323 introduce (section
, false);
9325 if (section
->size
< 6)
9327 warn (_(".eh_frame_hdr section is too small\n"));
9331 unsigned int version
= start
[0];
9334 warn (_("Unsupported .eh_frame_hdr version %u\n"), version
);
9338 printf (_(" Version: %u\n"), version
);
9340 unsigned int ptr_enc
= start
[1];
9341 /* Strictly speaking this is the encoding format of the eh_frame_ptr field below. */
9342 printf (_(" Pointer Encoding Format: %#x (%s)\n"), ptr_enc
, decode_eh_encoding (ptr_enc
));
9344 unsigned int count_enc
= start
[2];
9345 printf (_(" Count Encoding Format: %#x (%s)\n"), count_enc
, decode_eh_encoding (count_enc
));
9347 unsigned int table_enc
= start
[3];
9348 printf (_(" Table Encoding Format: %#x (%s)\n"), table_enc
, decode_eh_encoding (table_enc
));
9354 uint64_t eh_frame_ptr
= get_encoded_eh_value (ptr_enc
, start
, end
, & len
);
9357 warn (_("unable to read eh_frame_ptr field in .eh_frame_hdr section\n"));
9360 printf (_(" Start of frame section: %#" PRIx64
), eh_frame_ptr
);
9362 uint64_t offset_eh_frame_ptr
= encoded_eh_offset (ptr_enc
, section
, 4, eh_frame_ptr
);
9363 if (offset_eh_frame_ptr
!= eh_frame_ptr
)
9364 printf (_(" (offset: %#" PRIx64
")"), offset_eh_frame_ptr
);
9369 if (count_enc
== DW_EH_PE_omit
)
9371 warn (_("It is suspicious to have a .eh_frame_hdr section with an empty search table\n"));
9375 if (count_enc
& 0xf0)
9377 warn (_("The count field format should be absolute, not relative to an address\n"));
9381 uint64_t fde_count
= get_encoded_eh_value (count_enc
, start
, end
, & len
);
9384 warn (_("unable to read fde_count field in .eh_frame_hdr section\n"));
9387 printf (_(" Entries in search table: %#" PRIx64
), fde_count
);
9391 if (fde_count
!= 0 && table_enc
== DW_EH_PE_omit
)
9393 warn (_("It is suspicious to have a .eh_frame_hdr section an empty table but a non empty count field\n"));
9398 /* Read and display the search table. */
9399 for (i
= 0; i
< fde_count
; i
++)
9401 uint64_t location
, address
;
9402 unsigned char * row_start
= start
;
9404 location
= get_encoded_eh_value (table_enc
, start
, end
, & len
);
9407 warn (_("Failed to read location field for entry %#" PRIx64
" in the .eh_frame_hdr's search table\n"), i
);
9412 address
= get_encoded_eh_value (table_enc
, start
, end
, & len
);
9415 warn (_("Failed to read address field for entry %#" PRIx64
" in the .eh_frame_hdr's search table\n"), i
);
9420 /* This format is intended to be compatible with the output of eu-readelf's -e option. */
9421 printf (" %#" PRIx64
" (offset: %#" PRIx64
") -> %#" PRIx64
" fde=[ %5" PRIx64
"]\n",
9423 encoded_eh_offset (table_enc
, section
, row_start
- section
->start
, location
),
9425 encoded_eh_offset (table_enc
, section
, row_start
- section
->start
, address
) - offset_eh_frame_ptr
);
9433 display_debug_frames (struct dwarf_section
*section
,
9434 void *file ATTRIBUTE_UNUSED
)
9436 unsigned char *start
= section
->start
;
9437 unsigned char *end
= start
+ section
->size
;
9438 unsigned char *section_start
= start
;
9439 Frame_Chunk
*chunks
= NULL
, *forward_refs
= NULL
;
9440 Frame_Chunk
*remembered_state
= NULL
;
9442 bool is_eh
= strcmp (section
->name
, ".eh_frame") == 0;
9443 unsigned int max_regs
= 0;
9444 const char *bad_reg
= _("bad register: ");
9445 unsigned int saved_eh_addr_size
= eh_addr_size
;
9447 introduce (section
, false);
9451 unsigned char *saved_start
;
9452 unsigned char *block_end
;
9457 int need_col_headers
= 1;
9458 unsigned char *augmentation_data
= NULL
;
9459 uint64_t augmentation_data_len
= 0;
9460 unsigned int encoded_ptr_size
= saved_eh_addr_size
;
9461 unsigned int offset_size
;
9463 static Frame_Chunk fde_fc
;
9465 saved_start
= start
;
9467 SAFE_BYTE_GET_AND_INC (length
, start
, 4, end
);
9471 printf ("\n%08tx ZERO terminator\n\n",
9472 saved_start
- section_start
);
9473 /* Skip any zero terminators that directly follow.
9474 A corrupt section size could have loaded a whole
9475 slew of zero filled memory bytes. eg
9476 PR 17512: file: 070-19381-0.004. */
9477 while (start
< end
&& * start
== 0)
9482 if (length
== 0xffffffff)
9484 SAFE_BYTE_GET_AND_INC (length
, start
, 8, end
);
9490 if (length
> (size_t) (end
- start
))
9492 warn ("Invalid length %#" PRIx64
" in FDE at %#tx\n",
9493 length
, saved_start
- section_start
);
9497 block_end
= start
+ length
;
9499 SAFE_BYTE_GET_AND_INC (cie_id
, start
, offset_size
, block_end
);
9501 if (is_eh
? (cie_id
== 0) : ((offset_size
== 4 && cie_id
== DW_CIE_ID
)
9502 || (offset_size
== 8 && cie_id
== DW64_CIE_ID
)))
9507 start
= read_cie (start
, block_end
, &cie
, &version
,
9508 &augmentation_data_len
, &augmentation_data
);
9509 /* PR 17512: file: 027-135133-0.005. */
9516 fc
->chunk_start
= saved_start
;
9517 mreg
= max_regs
> 0 ? max_regs
- 1 : 0;
9520 if (frame_need_space (fc
, mreg
) < 0)
9522 if (fc
->fde_encoding
)
9523 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
9525 printf ("\n%08tx ", saved_start
- section_start
);
9526 print_hex (length
, fc
->ptr_size
);
9527 print_hex (cie_id
, offset_size
);
9529 if (do_debug_frames_interp
)
9531 printf ("CIE \"%s\" cf=%d df=%d ra=%d\n", fc
->augmentation
,
9532 fc
->code_factor
, fc
->data_factor
, fc
->ra
);
9537 printf (" Version: %d\n", version
);
9538 printf (" Augmentation: \"%s\"\n", fc
->augmentation
);
9541 printf (" Pointer Size: %u\n", fc
->ptr_size
);
9542 printf (" Segment Size: %u\n", fc
->segment_size
);
9544 printf (" Code alignment factor: %u\n", fc
->code_factor
);
9545 printf (" Data alignment factor: %d\n", fc
->data_factor
);
9546 printf (" Return address column: %d\n", fc
->ra
);
9548 if (augmentation_data_len
)
9549 display_augmentation_data (augmentation_data
, augmentation_data_len
);
9556 unsigned char *look_for
;
9557 unsigned long segment_selector
;
9563 uint64_t sign
= (uint64_t) 1 << (offset_size
* 8 - 1);
9564 cie_off
= (cie_off
^ sign
) - sign
;
9565 cie_off
= start
- 4 - section_start
- cie_off
;
9568 look_for
= section_start
+ cie_off
;
9569 if (cie_off
<= (size_t) (saved_start
- section_start
))
9571 for (cie
= chunks
; cie
; cie
= cie
->next
)
9572 if (cie
->chunk_start
== look_for
)
9575 else if (cie_off
>= section
->size
)
9579 for (cie
= forward_refs
; cie
; cie
= cie
->next
)
9580 if (cie
->chunk_start
== look_for
)
9584 unsigned int off_size
;
9585 unsigned char *cie_scan
;
9587 cie_scan
= look_for
;
9589 SAFE_BYTE_GET_AND_INC (length
, cie_scan
, 4, end
);
9590 if (length
== 0xffffffff)
9592 SAFE_BYTE_GET_AND_INC (length
, cie_scan
, 8, end
);
9595 if (length
!= 0 && length
<= (size_t) (end
- cie_scan
))
9598 unsigned char *cie_end
= cie_scan
+ length
;
9600 SAFE_BYTE_GET_AND_INC (c_id
, cie_scan
, off_size
,
9604 : ((off_size
== 4 && c_id
== DW_CIE_ID
)
9605 || (off_size
== 8 && c_id
== DW64_CIE_ID
)))
9610 read_cie (cie_scan
, cie_end
, &cie
, &version
,
9611 &augmentation_data_len
, &augmentation_data
);
9612 /* PR 17512: file: 3450-2098-0.004. */
9615 warn (_("Failed to read CIE information\n"));
9618 cie
->next
= forward_refs
;
9620 cie
->chunk_start
= look_for
;
9621 mreg
= max_regs
> 0 ? max_regs
- 1 : 0;
9624 if (frame_need_space (cie
, mreg
) < 0)
9626 warn (_("Invalid max register\n"));
9629 if (cie
->fde_encoding
)
9631 = size_of_encoded_value (cie
->fde_encoding
);
9638 memset (fc
, 0, sizeof (Frame_Chunk
));
9643 fc
->col_type
= xmalloc (sizeof (*fc
->col_type
));
9644 fc
->col_offset
= xmalloc (sizeof (*fc
->col_offset
));
9645 if (frame_need_space (fc
, max_regs
> 0 ? max_regs
- 1 : 0) < 0)
9647 warn (_("Invalid max register\n"));
9651 fc
->augmentation
= "";
9652 fc
->fde_encoding
= 0;
9653 fc
->ptr_size
= eh_addr_size
;
9654 fc
->segment_size
= 0;
9658 fc
->ncols
= cie
->ncols
;
9659 fc
->col_type
= xcmalloc (fc
->ncols
, sizeof (*fc
->col_type
));
9660 fc
->col_offset
= xcmalloc (fc
->ncols
, sizeof (*fc
->col_offset
));
9661 memcpy (fc
->col_type
, cie
->col_type
,
9662 fc
->ncols
* sizeof (*fc
->col_type
));
9663 memcpy (fc
->col_offset
, cie
->col_offset
,
9664 fc
->ncols
* sizeof (*fc
->col_offset
));
9665 fc
->augmentation
= cie
->augmentation
;
9666 fc
->ptr_size
= cie
->ptr_size
;
9667 eh_addr_size
= cie
->ptr_size
;
9668 fc
->segment_size
= cie
->segment_size
;
9669 fc
->code_factor
= cie
->code_factor
;
9670 fc
->data_factor
= cie
->data_factor
;
9671 fc
->cfa_reg
= cie
->cfa_reg
;
9672 fc
->cfa_offset
= cie
->cfa_offset
;
9674 if (frame_need_space (fc
, max_regs
> 0 ? max_regs
- 1: 0) < 0)
9676 warn (_("Invalid max register\n"));
9679 fc
->fde_encoding
= cie
->fde_encoding
;
9682 if (fc
->fde_encoding
)
9683 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
9685 segment_selector
= 0;
9686 if (fc
->segment_size
)
9688 if (fc
->segment_size
> sizeof (segment_selector
))
9690 /* PR 17512: file: 9e196b3e. */
9691 warn (_("Probably corrupt segment size: %d - using 4 instead\n"), fc
->segment_size
);
9692 fc
->segment_size
= 4;
9694 SAFE_BYTE_GET_AND_INC (segment_selector
, start
,
9695 fc
->segment_size
, block_end
);
9698 fc
->pc_begin
= get_encoded_value (&start
, fc
->fde_encoding
, section
,
9701 /* FIXME: It appears that sometimes the final pc_range value is
9702 encoded in less than encoded_ptr_size bytes. See the x86_64
9703 run of the "objcopy on compressed debug sections" test for an
9705 SAFE_BYTE_GET_AND_INC (fc
->pc_range
, start
, encoded_ptr_size
,
9708 if (cie
->augmentation
[0] == 'z')
9710 READ_ULEB (augmentation_data_len
, start
, block_end
);
9711 augmentation_data
= start
;
9712 /* PR 17512 file: 722-8446-0.004 and PR 22386. */
9713 if (augmentation_data_len
> (size_t) (block_end
- start
))
9715 warn (_("Augmentation data too long: %#" PRIx64
", "
9716 "expected at most %#tx\n"),
9717 augmentation_data_len
, block_end
- start
);
9719 augmentation_data
= NULL
;
9720 augmentation_data_len
= 0;
9722 start
+= augmentation_data_len
;
9725 printf ("\n%08tx ", saved_start
- section_start
);
9726 print_hex (length
, fc
->ptr_size
);
9727 print_hex (cie_id
, offset_size
);
9730 if (cie
->chunk_start
)
9731 printf ("cie=%08tx", cie
->chunk_start
- section_start
);
9733 /* Ideally translate "invalid " to 8 chars, trailing space
9735 printf (_("cie=invalid "));
9738 if (fc
->segment_size
)
9739 printf ("%04lx:", segment_selector
);
9741 print_hex_ns (fc
->pc_begin
, fc
->ptr_size
);
9743 print_hex_ns (fc
->pc_begin
+ fc
->pc_range
, fc
->ptr_size
);
9746 if (! do_debug_frames_interp
&& augmentation_data_len
)
9748 display_augmentation_data (augmentation_data
, augmentation_data_len
);
9753 /* At this point, fc is the current chunk, cie (if any) is set, and
9754 we're about to interpret instructions for the chunk. */
9755 /* ??? At present we need to do this always, since this sizes the
9756 fc->col_type and fc->col_offset arrays, which we write into always.
9757 We should probably split the interpreted and non-interpreted bits
9758 into two different routines, since there's so much that doesn't
9759 really overlap between them. */
9760 if (1 || do_debug_frames_interp
)
9762 /* Start by making a pass over the chunk, allocating storage
9763 and taking note of what registers are used. */
9764 unsigned char *tmp
= start
;
9766 while (start
< block_end
)
9768 unsigned int reg
, op
, opa
;
9776 /* Warning: if you add any more cases to this switch, be
9777 sure to add them to the corresponding switch below. */
9781 case DW_CFA_advance_loc
:
9784 SKIP_ULEB (start
, block_end
);
9787 case DW_CFA_restore
:
9790 case DW_CFA_set_loc
:
9791 if ((size_t) (block_end
- start
) < encoded_ptr_size
)
9794 start
+= encoded_ptr_size
;
9796 case DW_CFA_advance_loc1
:
9797 if ((size_t) (block_end
- start
) < 1)
9802 case DW_CFA_advance_loc2
:
9803 if ((size_t) (block_end
- start
) < 2)
9808 case DW_CFA_advance_loc4
:
9809 if ((size_t) (block_end
- start
) < 4)
9814 case DW_CFA_offset_extended
:
9815 case DW_CFA_val_offset
:
9816 READ_ULEB (reg
, start
, block_end
);
9817 SKIP_ULEB (start
, block_end
);
9819 case DW_CFA_restore_extended
:
9820 READ_ULEB (reg
, start
, block_end
);
9822 case DW_CFA_undefined
:
9823 READ_ULEB (reg
, start
, block_end
);
9825 case DW_CFA_same_value
:
9826 READ_ULEB (reg
, start
, block_end
);
9828 case DW_CFA_register
:
9829 READ_ULEB (reg
, start
, block_end
);
9830 SKIP_ULEB (start
, block_end
);
9832 case DW_CFA_def_cfa
:
9833 SKIP_ULEB (start
, block_end
);
9834 SKIP_ULEB (start
, block_end
);
9836 case DW_CFA_def_cfa_register
:
9837 SKIP_ULEB (start
, block_end
);
9839 case DW_CFA_def_cfa_offset
:
9840 SKIP_ULEB (start
, block_end
);
9842 case DW_CFA_def_cfa_expression
:
9843 READ_ULEB (temp
, start
, block_end
);
9844 if ((size_t) (block_end
- start
) < temp
)
9849 case DW_CFA_expression
:
9850 case DW_CFA_val_expression
:
9851 READ_ULEB (reg
, start
, block_end
);
9852 READ_ULEB (temp
, start
, block_end
);
9853 if ((size_t) (block_end
- start
) < temp
)
9858 case DW_CFA_offset_extended_sf
:
9859 case DW_CFA_val_offset_sf
:
9860 READ_ULEB (reg
, start
, block_end
);
9861 SKIP_SLEB (start
, block_end
);
9863 case DW_CFA_def_cfa_sf
:
9864 SKIP_ULEB (start
, block_end
);
9865 SKIP_SLEB (start
, block_end
);
9867 case DW_CFA_def_cfa_offset_sf
:
9868 SKIP_SLEB (start
, block_end
);
9870 case DW_CFA_MIPS_advance_loc8
:
9871 if ((size_t) (block_end
- start
) < 8)
9876 case DW_CFA_GNU_args_size
:
9877 SKIP_ULEB (start
, block_end
);
9879 case DW_CFA_GNU_negative_offset_extended
:
9880 READ_ULEB (reg
, start
, block_end
);
9881 SKIP_ULEB (start
, block_end
);
9886 if (reg
!= -1u && frame_need_space (fc
, reg
) >= 0)
9888 /* Don't leave any reg as DW_CFA_unreferenced so
9889 that frame_display_row prints name of regs in
9890 header, and all referenced regs in each line. */
9891 if (reg
>= cie
->ncols
9892 || cie
->col_type
[reg
] == DW_CFA_unreferenced
)
9893 fc
->col_type
[reg
] = DW_CFA_undefined
;
9895 fc
->col_type
[reg
] = cie
->col_type
[reg
];
9903 /* Now we know what registers are used, make a second pass over
9904 the chunk, this time actually printing out the info. */
9906 while (start
< block_end
)
9909 /* Note: It is tempting to use an unsigned long for 'reg' but there
9910 are various functions, notably frame_space_needed() that assume that
9911 reg is an unsigned int. */
9915 const char *reg_prefix
= "";
9922 /* Make a note if something other than DW_CFA_nop happens. */
9923 if (op
!= DW_CFA_nop
)
9926 /* Warning: if you add any more cases to this switch, be
9927 sure to add them to the corresponding switch above. */
9930 case DW_CFA_advance_loc
:
9931 opa
*= fc
->code_factor
;
9932 if (do_debug_frames_interp
)
9933 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9936 printf (" DW_CFA_advance_loc: %d to ", opa
);
9937 print_hex_ns (fc
->pc_begin
+ opa
, fc
->ptr_size
);
9940 fc
->pc_begin
+= opa
;
9944 READ_ULEB (ofs
, start
, block_end
);
9945 ofs
*= fc
->data_factor
;
9946 if (opa
>= fc
->ncols
)
9947 reg_prefix
= bad_reg
;
9948 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9949 printf (" DW_CFA_offset: %s%s at cfa%+" PRId64
"\n",
9950 reg_prefix
, regname (opa
, 0), ofs
);
9951 if (*reg_prefix
== '\0')
9953 fc
->col_type
[opa
] = DW_CFA_offset
;
9954 fc
->col_offset
[opa
] = ofs
;
9958 case DW_CFA_restore
:
9959 if (opa
>= fc
->ncols
)
9960 reg_prefix
= bad_reg
;
9961 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9962 printf (" DW_CFA_restore: %s%s\n",
9963 reg_prefix
, regname (opa
, 0));
9964 if (*reg_prefix
!= '\0')
9967 if (opa
>= cie
->ncols
9968 || cie
->col_type
[opa
] == DW_CFA_unreferenced
)
9970 fc
->col_type
[opa
] = DW_CFA_undefined
;
9971 fc
->col_offset
[opa
] = 0;
9975 fc
->col_type
[opa
] = cie
->col_type
[opa
];
9976 fc
->col_offset
[opa
] = cie
->col_offset
[opa
];
9980 case DW_CFA_set_loc
:
9981 ofs
= get_encoded_value (&start
, fc
->fde_encoding
, section
,
9983 if (do_debug_frames_interp
)
9984 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9987 printf (" DW_CFA_set_loc: ");
9988 print_hex_ns (ofs
, fc
->ptr_size
);
9994 case DW_CFA_advance_loc1
:
9995 SAFE_BYTE_GET_AND_INC (ofs
, start
, 1, block_end
);
9996 ofs
*= fc
->code_factor
;
9997 if (do_debug_frames_interp
)
9998 frame_display_row (fc
, &need_col_headers
, &max_regs
);
10001 printf (" DW_CFA_advance_loc1: %" PRId64
" to ", ofs
);
10002 print_hex_ns (fc
->pc_begin
+ ofs
, fc
->ptr_size
);
10005 fc
->pc_begin
+= ofs
;
10008 case DW_CFA_advance_loc2
:
10009 SAFE_BYTE_GET_AND_INC (ofs
, start
, 2, block_end
);
10010 ofs
*= fc
->code_factor
;
10011 if (do_debug_frames_interp
)
10012 frame_display_row (fc
, &need_col_headers
, &max_regs
);
10015 printf (" DW_CFA_advance_loc2: %" PRId64
" to ", ofs
);
10016 print_hex_ns (fc
->pc_begin
+ ofs
, fc
->ptr_size
);
10019 fc
->pc_begin
+= ofs
;
10022 case DW_CFA_advance_loc4
:
10023 SAFE_BYTE_GET_AND_INC (ofs
, start
, 4, block_end
);
10024 ofs
*= fc
->code_factor
;
10025 if (do_debug_frames_interp
)
10026 frame_display_row (fc
, &need_col_headers
, &max_regs
);
10029 printf (" DW_CFA_advance_loc4: %" PRId64
" to ", ofs
);
10030 print_hex_ns (fc
->pc_begin
+ ofs
, fc
->ptr_size
);
10033 fc
->pc_begin
+= ofs
;
10036 case DW_CFA_offset_extended
:
10037 READ_ULEB (reg
, start
, block_end
);
10038 READ_ULEB (ofs
, start
, block_end
);
10039 ofs
*= fc
->data_factor
;
10040 if (reg
>= fc
->ncols
)
10041 reg_prefix
= bad_reg
;
10042 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
10043 printf (" DW_CFA_offset_extended: %s%s at cfa%+" PRId64
"\n",
10044 reg_prefix
, regname (reg
, 0), ofs
);
10045 if (*reg_prefix
== '\0')
10047 fc
->col_type
[reg
] = DW_CFA_offset
;
10048 fc
->col_offset
[reg
] = ofs
;
10052 case DW_CFA_val_offset
:
10053 READ_ULEB (reg
, start
, block_end
);
10054 READ_ULEB (ofs
, start
, block_end
);
10055 ofs
*= fc
->data_factor
;
10056 if (reg
>= fc
->ncols
)
10057 reg_prefix
= bad_reg
;
10058 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
10059 printf (" DW_CFA_val_offset: %s%s is cfa%+" PRId64
"\n",
10060 reg_prefix
, regname (reg
, 0), ofs
);
10061 if (*reg_prefix
== '\0')
10063 fc
->col_type
[reg
] = DW_CFA_val_offset
;
10064 fc
->col_offset
[reg
] = ofs
;
10068 case DW_CFA_restore_extended
:
10069 READ_ULEB (reg
, start
, block_end
);
10070 if (reg
>= fc
->ncols
)
10071 reg_prefix
= bad_reg
;
10072 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
10073 printf (" DW_CFA_restore_extended: %s%s\n",
10074 reg_prefix
, regname (reg
, 0));
10075 if (*reg_prefix
!= '\0')
10078 if (reg
>= cie
->ncols
10079 || cie
->col_type
[reg
] == DW_CFA_unreferenced
)
10081 fc
->col_type
[reg
] = DW_CFA_undefined
;
10082 fc
->col_offset
[reg
] = 0;
10086 fc
->col_type
[reg
] = cie
->col_type
[reg
];
10087 fc
->col_offset
[reg
] = cie
->col_offset
[reg
];
10091 case DW_CFA_undefined
:
10092 READ_ULEB (reg
, start
, block_end
);
10093 if (reg
>= fc
->ncols
)
10094 reg_prefix
= bad_reg
;
10095 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
10096 printf (" DW_CFA_undefined: %s%s\n",
10097 reg_prefix
, regname (reg
, 0));
10098 if (*reg_prefix
== '\0')
10100 fc
->col_type
[reg
] = DW_CFA_undefined
;
10101 fc
->col_offset
[reg
] = 0;
10105 case DW_CFA_same_value
:
10106 READ_ULEB (reg
, start
, block_end
);
10107 if (reg
>= fc
->ncols
)
10108 reg_prefix
= bad_reg
;
10109 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
10110 printf (" DW_CFA_same_value: %s%s\n",
10111 reg_prefix
, regname (reg
, 0));
10112 if (*reg_prefix
== '\0')
10114 fc
->col_type
[reg
] = DW_CFA_same_value
;
10115 fc
->col_offset
[reg
] = 0;
10119 case DW_CFA_register
:
10120 READ_ULEB (reg
, start
, block_end
);
10121 READ_ULEB (ofs
, start
, block_end
);
10122 if (reg
>= fc
->ncols
)
10123 reg_prefix
= bad_reg
;
10124 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
10126 printf (" DW_CFA_register: %s%s in ",
10127 reg_prefix
, regname (reg
, 0));
10128 puts (regname (ofs
, 0));
10130 if (*reg_prefix
== '\0')
10132 fc
->col_type
[reg
] = DW_CFA_register
;
10133 fc
->col_offset
[reg
] = ofs
;
10137 case DW_CFA_remember_state
:
10138 if (! do_debug_frames_interp
)
10139 printf (" DW_CFA_remember_state\n");
10140 rs
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
10141 rs
->cfa_offset
= fc
->cfa_offset
;
10142 rs
->cfa_reg
= fc
->cfa_reg
;
10144 rs
->cfa_exp
= fc
->cfa_exp
;
10145 rs
->ncols
= fc
->ncols
;
10146 rs
->col_type
= xcmalloc (rs
->ncols
, sizeof (*rs
->col_type
));
10147 rs
->col_offset
= xcmalloc (rs
->ncols
, sizeof (*rs
->col_offset
));
10148 memcpy (rs
->col_type
, fc
->col_type
,
10149 rs
->ncols
* sizeof (*fc
->col_type
));
10150 memcpy (rs
->col_offset
, fc
->col_offset
,
10151 rs
->ncols
* sizeof (*fc
->col_offset
));
10152 rs
->next
= remembered_state
;
10153 remembered_state
= rs
;
10156 case DW_CFA_restore_state
:
10157 if (! do_debug_frames_interp
)
10158 printf (" DW_CFA_restore_state\n");
10159 rs
= remembered_state
;
10162 remembered_state
= rs
->next
;
10163 fc
->cfa_offset
= rs
->cfa_offset
;
10164 fc
->cfa_reg
= rs
->cfa_reg
;
10166 fc
->cfa_exp
= rs
->cfa_exp
;
10167 if (frame_need_space (fc
, rs
->ncols
- 1) < 0)
10169 warn (_("Invalid column number in saved frame state\n"));
10174 memcpy (fc
->col_type
, rs
->col_type
,
10175 rs
->ncols
* sizeof (*rs
->col_type
));
10176 memcpy (fc
->col_offset
, rs
->col_offset
,
10177 rs
->ncols
* sizeof (*rs
->col_offset
));
10179 free (rs
->col_type
);
10180 free (rs
->col_offset
);
10183 else if (do_debug_frames_interp
)
10184 printf ("Mismatched DW_CFA_restore_state\n");
10187 case DW_CFA_def_cfa
:
10188 READ_ULEB (fc
->cfa_reg
, start
, block_end
);
10189 READ_ULEB (fc
->cfa_offset
, start
, block_end
);
10191 if (! do_debug_frames_interp
)
10192 printf (" DW_CFA_def_cfa: %s ofs %d\n",
10193 regname (fc
->cfa_reg
, 0), (int) fc
->cfa_offset
);
10196 case DW_CFA_def_cfa_register
:
10197 READ_ULEB (fc
->cfa_reg
, start
, block_end
);
10199 if (! do_debug_frames_interp
)
10200 printf (" DW_CFA_def_cfa_register: %s\n",
10201 regname (fc
->cfa_reg
, 0));
10204 case DW_CFA_def_cfa_offset
:
10205 READ_ULEB (fc
->cfa_offset
, start
, block_end
);
10206 if (! do_debug_frames_interp
)
10207 printf (" DW_CFA_def_cfa_offset: %d\n", (int) fc
->cfa_offset
);
10211 if (! do_debug_frames_interp
)
10212 printf (" DW_CFA_nop\n");
10215 case DW_CFA_def_cfa_expression
:
10216 READ_ULEB (ofs
, start
, block_end
);
10217 if (ofs
> (size_t) (block_end
- start
))
10219 printf (_(" %s: <corrupt len %" PRIu64
">\n"),
10220 "DW_CFA_def_cfa_expression", ofs
);
10223 if (! do_debug_frames_interp
)
10225 printf (" DW_CFA_def_cfa_expression (");
10226 decode_location_expression (start
, eh_addr_size
, 0, -1,
10234 case DW_CFA_expression
:
10235 READ_ULEB (reg
, start
, block_end
);
10236 READ_ULEB (ofs
, start
, block_end
);
10237 if (reg
>= fc
->ncols
)
10238 reg_prefix
= bad_reg
;
10239 /* PR 17512: file: 069-133014-0.006. */
10240 /* PR 17512: file: 98c02eb4. */
10241 if (ofs
> (size_t) (block_end
- start
))
10243 printf (_(" %s: <corrupt len %" PRIu64
">\n"),
10244 "DW_CFA_expression", ofs
);
10247 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
10249 printf (" DW_CFA_expression: %s%s (",
10250 reg_prefix
, regname (reg
, 0));
10251 decode_location_expression (start
, eh_addr_size
, 0, -1,
10255 if (*reg_prefix
== '\0')
10256 fc
->col_type
[reg
] = DW_CFA_expression
;
10260 case DW_CFA_val_expression
:
10261 READ_ULEB (reg
, start
, block_end
);
10262 READ_ULEB (ofs
, start
, block_end
);
10263 if (reg
>= fc
->ncols
)
10264 reg_prefix
= bad_reg
;
10265 if (ofs
> (size_t) (block_end
- start
))
10267 printf (" %s: <corrupt len %" PRIu64
">\n",
10268 "DW_CFA_val_expression", ofs
);
10271 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
10273 printf (" DW_CFA_val_expression: %s%s (",
10274 reg_prefix
, regname (reg
, 0));
10275 decode_location_expression (start
, eh_addr_size
, 0, -1,
10279 if (*reg_prefix
== '\0')
10280 fc
->col_type
[reg
] = DW_CFA_val_expression
;
10284 case DW_CFA_offset_extended_sf
:
10285 READ_ULEB (reg
, start
, block_end
);
10286 READ_SLEB (sofs
, start
, block_end
);
10287 /* data_factor multiplicaton done here as unsigned to
10288 avoid integer overflow warnings from asan on fuzzed
10291 ofs
*= fc
->data_factor
;
10292 if (reg
>= fc
->ncols
)
10293 reg_prefix
= bad_reg
;
10294 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
10295 printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+" PRId64
"\n",
10296 reg_prefix
, regname (reg
, 0), ofs
);
10297 if (*reg_prefix
== '\0')
10299 fc
->col_type
[reg
] = DW_CFA_offset
;
10300 fc
->col_offset
[reg
] = ofs
;
10304 case DW_CFA_val_offset_sf
:
10305 READ_ULEB (reg
, start
, block_end
);
10306 READ_SLEB (sofs
, start
, block_end
);
10308 ofs
*= fc
->data_factor
;
10309 if (reg
>= fc
->ncols
)
10310 reg_prefix
= bad_reg
;
10311 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
10312 printf (" DW_CFA_val_offset_sf: %s%s is cfa%+" PRId64
"\n",
10313 reg_prefix
, regname (reg
, 0), ofs
);
10314 if (*reg_prefix
== '\0')
10316 fc
->col_type
[reg
] = DW_CFA_val_offset
;
10317 fc
->col_offset
[reg
] = ofs
;
10321 case DW_CFA_def_cfa_sf
:
10322 READ_ULEB (fc
->cfa_reg
, start
, block_end
);
10323 READ_SLEB (sofs
, start
, block_end
);
10325 ofs
*= fc
->data_factor
;
10326 fc
->cfa_offset
= ofs
;
10328 if (! do_debug_frames_interp
)
10329 printf (" DW_CFA_def_cfa_sf: %s ofs %" PRId64
"\n",
10330 regname (fc
->cfa_reg
, 0), ofs
);
10333 case DW_CFA_def_cfa_offset_sf
:
10334 READ_SLEB (sofs
, start
, block_end
);
10336 ofs
*= fc
->data_factor
;
10337 fc
->cfa_offset
= ofs
;
10338 if (! do_debug_frames_interp
)
10339 printf (" DW_CFA_def_cfa_offset_sf: %" PRId64
"\n", ofs
);
10342 case DW_CFA_MIPS_advance_loc8
:
10343 SAFE_BYTE_GET_AND_INC (ofs
, start
, 8, block_end
);
10344 ofs
*= fc
->code_factor
;
10345 if (do_debug_frames_interp
)
10346 frame_display_row (fc
, &need_col_headers
, &max_regs
);
10349 printf (" DW_CFA_MIPS_advance_loc8: %" PRId64
" to ", ofs
);
10350 print_hex_ns (fc
->pc_begin
+ ofs
, fc
->ptr_size
);
10353 fc
->pc_begin
+= ofs
;
10356 case DW_CFA_GNU_window_save
:
10357 if (! do_debug_frames_interp
)
10358 printf (" %s\n", DW_CFA_GNU_window_save_name
[is_aarch64
]);
10361 case DW_CFA_GNU_args_size
:
10362 READ_ULEB (ofs
, start
, block_end
);
10363 if (! do_debug_frames_interp
)
10364 printf (" DW_CFA_GNU_args_size: %" PRIu64
"\n", ofs
);
10367 case DW_CFA_GNU_negative_offset_extended
:
10368 READ_ULEB (reg
, start
, block_end
);
10369 READ_SLEB (sofs
, start
, block_end
);
10371 ofs
= -ofs
* fc
->data_factor
;
10372 if (reg
>= fc
->ncols
)
10373 reg_prefix
= bad_reg
;
10374 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
10375 printf (" DW_CFA_GNU_negative_offset_extended: %s%s "
10376 "at cfa%+" PRId64
"\n",
10377 reg_prefix
, regname (reg
, 0), ofs
);
10378 if (*reg_prefix
== '\0')
10380 fc
->col_type
[reg
] = DW_CFA_offset
;
10381 fc
->col_offset
[reg
] = ofs
;
10386 if (op
>= DW_CFA_lo_user
&& op
<= DW_CFA_hi_user
)
10387 printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op
);
10389 warn (_("Unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op
);
10394 /* Interpret the CFA - as long as it is not completely full of NOPs. */
10395 if (do_debug_frames_interp
&& ! all_nops
)
10396 frame_display_row (fc
, &need_col_headers
, &max_regs
);
10398 if (fde_fc
.col_type
!= NULL
)
10400 free (fde_fc
.col_type
);
10401 fde_fc
.col_type
= NULL
;
10403 if (fde_fc
.col_offset
!= NULL
)
10405 free (fde_fc
.col_offset
);
10406 fde_fc
.col_offset
= NULL
;
10410 eh_addr_size
= saved_eh_addr_size
;
10415 while (remembered_state
!= NULL
)
10417 rs
= remembered_state
;
10418 remembered_state
= rs
->next
;
10419 free (rs
->col_type
);
10420 free (rs
->col_offset
);
10421 rs
->next
= NULL
; /* Paranoia. */
10425 while (chunks
!= NULL
)
10429 free (rs
->col_type
);
10430 free (rs
->col_offset
);
10431 rs
->next
= NULL
; /* Paranoia. */
10435 while (forward_refs
!= NULL
)
10438 forward_refs
= rs
->next
;
10439 free (rs
->col_type
);
10440 free (rs
->col_offset
);
10441 rs
->next
= NULL
; /* Paranoia. */
10451 display_debug_names (struct dwarf_section
*section
, void *file
)
10453 unsigned char *hdrptr
= section
->start
;
10454 uint64_t unit_length
;
10455 unsigned char *unit_start
;
10456 const unsigned char *const section_end
= section
->start
+ section
->size
;
10457 unsigned char *unit_end
;
10459 introduce (section
, false);
10461 load_debug_section_with_follow (str
, file
);
10463 for (; hdrptr
< section_end
; hdrptr
= unit_end
)
10465 unsigned int offset_size
;
10466 uint16_t dwarf_version
, padding
;
10467 uint32_t comp_unit_count
, local_type_unit_count
, foreign_type_unit_count
;
10468 uint64_t bucket_count
, name_count
, abbrev_table_size
;
10469 uint32_t augmentation_string_size
;
10471 bool augmentation_printable
;
10472 const char *augmentation_string
;
10475 unit_start
= hdrptr
;
10477 /* Get and check the length of the block. */
10478 SAFE_BYTE_GET_AND_INC (unit_length
, hdrptr
, 4, section_end
);
10480 if (unit_length
== 0xffffffff)
10482 /* This section is 64-bit DWARF. */
10483 SAFE_BYTE_GET_AND_INC (unit_length
, hdrptr
, 8, section_end
);
10489 if (unit_length
> (size_t) (section_end
- hdrptr
)
10490 || unit_length
< 2 + 2 + 4 * 7)
10493 warn (_("Debug info is corrupted, %s header at %#tx"
10494 " has length %#" PRIx64
"\n"),
10495 section
->name
, unit_start
- section
->start
, unit_length
);
10498 unit_end
= hdrptr
+ unit_length
;
10500 /* Get and check the version number. */
10501 SAFE_BYTE_GET_AND_INC (dwarf_version
, hdrptr
, 2, unit_end
);
10502 printf (_("Version %d\n"), (int) dwarf_version
);
10504 /* Prior versions did not exist, and future versions may not be
10505 backwards compatible. */
10506 if (dwarf_version
!= 5)
10508 warn (_("Only DWARF version 5 .debug_names "
10509 "is currently supported.\n"));
10513 SAFE_BYTE_GET_AND_INC (padding
, hdrptr
, 2, unit_end
);
10515 warn (_("Padding field of .debug_names must be 0 (found 0x%x)\n"),
10518 SAFE_BYTE_GET_AND_INC (comp_unit_count
, hdrptr
, 4, unit_end
);
10519 if (comp_unit_count
== 0)
10520 warn (_("Compilation unit count must be >= 1 in .debug_names\n"));
10522 SAFE_BYTE_GET_AND_INC (local_type_unit_count
, hdrptr
, 4, unit_end
);
10523 SAFE_BYTE_GET_AND_INC (foreign_type_unit_count
, hdrptr
, 4, unit_end
);
10524 SAFE_BYTE_GET_AND_INC (bucket_count
, hdrptr
, 4, unit_end
);
10525 SAFE_BYTE_GET_AND_INC (name_count
, hdrptr
, 4, unit_end
);
10526 SAFE_BYTE_GET_AND_INC (abbrev_table_size
, hdrptr
, 4, unit_end
);
10528 SAFE_BYTE_GET_AND_INC (augmentation_string_size
, hdrptr
, 4, unit_end
);
10529 if (augmentation_string_size
% 4 != 0)
10531 warn (_("Augmentation string length %u must be rounded up "
10532 "to a multiple of 4 in .debug_names.\n"),
10533 augmentation_string_size
);
10534 augmentation_string_size
+= (-augmentation_string_size
) & 3;
10536 if (augmentation_string_size
> (size_t) (unit_end
- hdrptr
))
10539 printf (_("Augmentation string:"));
10541 augmentation_printable
= true;
10542 augmentation_string
= (const char *) hdrptr
;
10544 for (i
= 0; i
< augmentation_string_size
; i
++)
10548 SAFE_BYTE_GET_AND_INC (uc
, hdrptr
, 1, unit_end
);
10549 printf (" %02x", uc
);
10551 if (uc
!= 0 && !ISPRINT (uc
))
10552 augmentation_printable
= false;
10555 if (augmentation_printable
)
10559 i
< augmentation_string_size
&& augmentation_string
[i
];
10561 putchar (augmentation_string
[i
]);
10566 printf (_("CU table:\n"));
10567 if (_mul_overflow (comp_unit_count
, offset_size
, &total
)
10568 || total
> (size_t) (unit_end
- hdrptr
))
10570 for (i
= 0; i
< comp_unit_count
; i
++)
10572 uint64_t cu_offset
;
10574 SAFE_BYTE_GET_AND_INC (cu_offset
, hdrptr
, offset_size
, unit_end
);
10575 printf ("[%3u] %#" PRIx64
"\n", i
, cu_offset
);
10579 printf (_("TU table:\n"));
10580 if (_mul_overflow (local_type_unit_count
, offset_size
, &total
)
10581 || total
> (size_t) (unit_end
- hdrptr
))
10583 for (i
= 0; i
< local_type_unit_count
; i
++)
10585 uint64_t tu_offset
;
10587 SAFE_BYTE_GET_AND_INC (tu_offset
, hdrptr
, offset_size
, unit_end
);
10588 printf ("[%3u] %#" PRIx64
"\n", i
, tu_offset
);
10592 printf (_("Foreign TU table:\n"));
10593 if (_mul_overflow (foreign_type_unit_count
, 8, &total
)
10594 || total
> (size_t) (unit_end
- hdrptr
))
10596 for (i
= 0; i
< foreign_type_unit_count
; i
++)
10598 uint64_t signature
;
10600 SAFE_BYTE_GET_AND_INC (signature
, hdrptr
, 8, unit_end
);
10601 printf (_("[%3u] "), i
);
10602 print_hex_ns (signature
, 8);
10607 uint64_t xtra
= (bucket_count
* sizeof (uint32_t)
10608 + name_count
* (sizeof (uint32_t) + 2 * offset_size
)
10609 + abbrev_table_size
);
10610 if (xtra
> (size_t) (unit_end
- hdrptr
))
10612 warn (_("Entry pool offset (%#" PRIx64
") exceeds unit size %#tx "
10613 "for unit %#tx in the debug_names\n"),
10614 xtra
, unit_end
- unit_start
, unit_start
- section
->start
);
10617 const uint32_t *const hash_table_buckets
= (uint32_t *) hdrptr
;
10618 hdrptr
+= bucket_count
* sizeof (uint32_t);
10619 const uint32_t *const hash_table_hashes
= (uint32_t *) hdrptr
;
10620 if (bucket_count
!= 0)
10621 hdrptr
+= name_count
* sizeof (uint32_t);
10622 unsigned char *const name_table_string_offsets
= hdrptr
;
10623 hdrptr
+= name_count
* offset_size
;
10624 unsigned char *const name_table_entry_offsets
= hdrptr
;
10625 hdrptr
+= name_count
* offset_size
;
10626 unsigned char *const abbrev_table
= hdrptr
;
10627 hdrptr
+= abbrev_table_size
;
10628 const unsigned char *const abbrev_table_end
= hdrptr
;
10629 unsigned char *const entry_pool
= hdrptr
;
10631 size_t buckets_filled
= 0;
10633 for (bucketi
= 0; bucketi
< bucket_count
; bucketi
++)
10635 const uint32_t bucket
= hash_table_buckets
[bucketi
];
10640 printf (ngettext ("Used %zu of %lu bucket.\n",
10641 "Used %zu of %lu buckets.\n",
10642 (unsigned long) bucket_count
),
10643 buckets_filled
, (unsigned long) bucket_count
);
10645 if (bucket_count
!= 0)
10647 uint32_t hash_prev
= 0;
10648 size_t hash_clash_count
= 0;
10649 size_t longest_clash
= 0;
10650 size_t this_length
= 0;
10652 for (hashi
= 0; hashi
< name_count
; hashi
++)
10654 const uint32_t hash_this
= hash_table_hashes
[hashi
];
10658 if (hash_prev
% bucket_count
== hash_this
% bucket_count
)
10660 ++hash_clash_count
;
10662 longest_clash
= MAX (longest_clash
, this_length
);
10667 hash_prev
= hash_this
;
10669 printf (_("Out of %" PRIu64
" items there are %zu bucket clashes"
10670 " (longest of %zu entries).\n"),
10671 name_count
, hash_clash_count
, longest_clash
);
10673 if (name_count
!= buckets_filled
+ hash_clash_count
)
10674 warn (_("The name_count (%" PRIu64
")"
10675 " is not the same as the used bucket_count"
10676 " (%zu) + the hash clash count (%zu)\n"),
10677 name_count
, buckets_filled
, hash_clash_count
);
10680 struct abbrev_lookup_entry
10682 uint64_t abbrev_tag
;
10683 unsigned char *abbrev_lookup_ptr
;
10685 struct abbrev_lookup_entry
*abbrev_lookup
= NULL
;
10686 size_t abbrev_lookup_used
= 0;
10687 size_t abbrev_lookup_allocated
= 0;
10689 unsigned char *abbrevptr
= abbrev_table
;
10692 uint64_t abbrev_tag
;
10694 READ_ULEB (abbrev_tag
, abbrevptr
, abbrev_table_end
);
10695 if (abbrev_tag
== 0)
10697 if (abbrev_lookup_used
== abbrev_lookup_allocated
)
10699 abbrev_lookup_allocated
= MAX (0x100,
10700 abbrev_lookup_allocated
* 2);
10701 abbrev_lookup
= xrealloc (abbrev_lookup
,
10702 (abbrev_lookup_allocated
10703 * sizeof (*abbrev_lookup
)));
10705 assert (abbrev_lookup_used
< abbrev_lookup_allocated
);
10706 struct abbrev_lookup_entry
*entry
;
10707 for (entry
= abbrev_lookup
;
10708 entry
< abbrev_lookup
+ abbrev_lookup_used
;
10710 if (entry
->abbrev_tag
== abbrev_tag
)
10712 warn (_("Duplicate abbreviation tag %" PRIu64
10713 " in unit %#tx in the debug_names section\n"),
10714 abbrev_tag
, unit_start
- section
->start
);
10717 entry
= &abbrev_lookup
[abbrev_lookup_used
++];
10718 entry
->abbrev_tag
= abbrev_tag
;
10719 entry
->abbrev_lookup_ptr
= abbrevptr
;
10721 /* Skip DWARF tag. */
10722 SKIP_ULEB (abbrevptr
, abbrev_table_end
);
10725 uint64_t xindex
, form
;
10727 READ_ULEB (xindex
, abbrevptr
, abbrev_table_end
);
10728 READ_ULEB (form
, abbrevptr
, abbrev_table_end
);
10729 if (xindex
== 0 && form
== 0)
10734 printf (_("\nSymbol table:\n"));
10736 for (namei
= 0; namei
< name_count
; ++namei
)
10738 uint64_t string_offset
, entry_offset
;
10740 /* We need to scan first whether there is a single or multiple
10741 entries. TAGNO is -2 for the first entry, it is -1 for the
10742 initial tag read of the second entry, then it becomes 0 for the
10743 first entry for real printing etc. */
10745 /* Initialize it due to a false compiler warning. */
10746 uint64_t second_abbrev_tag
= -1;
10747 unsigned char *entryptr
;
10749 p
= name_table_string_offsets
+ namei
* offset_size
;
10750 SAFE_BYTE_GET (string_offset
, p
, offset_size
, unit_end
);
10752 p
= name_table_entry_offsets
+ namei
* offset_size
;
10753 SAFE_BYTE_GET (entry_offset
, p
, offset_size
, unit_end
);
10755 /* The name table is indexed starting at 1 according to
10756 DWARF, so be sure to use the DWARF numbering here. */
10757 printf ("[%3u] ", namei
+ 1);
10758 if (bucket_count
!= 0)
10759 printf ("#%08x ", hash_table_hashes
[namei
]);
10761 printf ("%s:", fetch_indirect_string (string_offset
));
10763 entryptr
= entry_pool
+ entry_offset
;
10764 /* PR 31456: Check for invalid entry offset. */
10765 if (entryptr
< entry_pool
|| entryptr
>= unit_end
)
10767 warn (_("Invalid entry offset value: %" PRIx64
"\n"), entry_offset
);
10773 uint64_t abbrev_tag
;
10774 uint64_t dwarf_tag
;
10775 const struct abbrev_lookup_entry
*entry
;
10777 READ_ULEB (abbrev_tag
, entryptr
, unit_end
);
10780 second_abbrev_tag
= abbrev_tag
;
10782 entryptr
= entry_pool
+ entry_offset
;
10785 if (abbrev_tag
== 0)
10788 printf ("%s<%" PRIu64
">",
10789 (tagno
== 0 && second_abbrev_tag
== 0 ? " " : "\n\t"),
10792 for (entry
= abbrev_lookup
;
10793 entry
< abbrev_lookup
+ abbrev_lookup_used
;
10795 if (entry
->abbrev_tag
== abbrev_tag
)
10797 if (entry
>= abbrev_lookup
+ abbrev_lookup_used
)
10799 warn (_("Undefined abbreviation tag %" PRId64
10800 " in unit %#tx in the debug_names section\n"),
10802 unit_start
- section
->start
);
10805 abbrevptr
= entry
->abbrev_lookup_ptr
;
10806 READ_ULEB (dwarf_tag
, abbrevptr
, abbrev_table_end
);
10808 printf (" %s", get_TAG_name (dwarf_tag
));
10811 uint64_t xindex
, form
;
10813 READ_ULEB (xindex
, abbrevptr
, abbrev_table_end
);
10814 READ_ULEB (form
, abbrevptr
, abbrev_table_end
);
10815 if (xindex
== 0 && form
== 0)
10819 printf (" %s", get_IDX_name (xindex
));
10820 entryptr
= read_and_display_attr_value (0, form
, 0,
10821 unit_start
, entryptr
, unit_end
,
10823 dwarf_version
, NULL
,
10824 (tagno
< 0), section
,
10830 printf (_(" <no entries>"));
10834 free (abbrev_lookup
);
10841 display_debug_links (struct dwarf_section
* section
,
10842 void * file ATTRIBUTE_UNUSED
)
10844 const unsigned char * filename
;
10845 unsigned int filelen
;
10847 introduce (section
, false);
10849 /* The .gnu_debuglink section is formatted as:
10850 (c-string) Filename.
10851 (padding) If needed to reach a 4 byte boundary.
10852 (uint32_t) CRC32 value.
10854 The .gun_debugaltlink section is formatted as:
10855 (c-string) Filename.
10856 (binary) Build-ID. */
10858 filename
= section
->start
;
10859 filelen
= strnlen ((const char *) filename
, section
->size
);
10860 if (filelen
== section
->size
)
10862 warn (_("The debuglink filename is corrupt/missing\n"));
10866 printf (_(" Separate debug info file: %s\n"), filename
);
10868 if (startswith (section
->name
, ".gnu_debuglink"))
10870 unsigned int crc32
;
10871 unsigned int crc_offset
;
10873 crc_offset
= filelen
+ 1;
10874 crc_offset
= (crc_offset
+ 3) & ~3;
10875 if (crc_offset
+ 4 > section
->size
)
10877 warn (_("CRC offset missing/truncated\n"));
10881 crc32
= byte_get (filename
+ crc_offset
, 4);
10883 printf (_(" CRC value: %#x\n"), crc32
);
10885 if (crc_offset
+ 4 < section
->size
)
10887 warn (_("There are %#" PRIx64
10888 " extraneous bytes at the end of the section\n"),
10889 section
->size
- (crc_offset
+ 4));
10893 else /* startswith (section->name, ".gnu_debugaltlink") */
10895 const unsigned char *build_id
= section
->start
+ filelen
+ 1;
10896 size_t build_id_len
= section
->size
- (filelen
+ 1);
10899 /* FIXME: Should we support smaller build-id notes ? */
10900 if (build_id_len
< 0x14)
10902 warn (_("Build-ID is too short (%#zx bytes)\n"), build_id_len
);
10906 printed
= printf (_(" Build-ID (%#zx bytes):"), build_id_len
);
10907 display_data (printed
, build_id
, build_id_len
);
10916 display_gdb_index (struct dwarf_section
*section
,
10917 void *file ATTRIBUTE_UNUSED
)
10919 unsigned char *start
= section
->start
;
10921 uint32_t cu_list_offset
, tu_list_offset
;
10922 uint32_t address_table_offset
, symbol_table_offset
, constant_pool_offset
,
10923 shortcut_table_offset
;
10924 unsigned int cu_list_elements
, tu_list_elements
;
10925 unsigned int address_table_elements
, symbol_table_slots
;
10926 unsigned char *cu_list
, *tu_list
;
10927 unsigned char *address_table
, *symbol_table
, *shortcut_table
, *constant_pool
;
10930 /* The documentation for the format of this file is in gdb/dwarf2read.c. */
10932 introduce (section
, false);
10934 version
= section
->size
< 4 ? 0 : byte_get_little_endian (start
, 4);
10935 size_t header_size
= (version
< 9 ? 6 : 7) * sizeof (uint32_t);
10936 if (section
->size
< header_size
)
10938 warn (_("Truncated header in the %s section.\n"), section
->name
);
10942 printf (_("Version %lu\n"), (unsigned long) version
);
10944 /* Prior versions are obsolete, and future versions may not be
10945 backwards compatible. */
10946 if (version
< 3 || version
> 9)
10948 warn (_("Unsupported version %lu.\n"), (unsigned long) version
);
10952 warn (_("The address table data in version 3 may be wrong.\n"));
10954 warn (_("Version 4 does not support case insensitive lookups.\n"));
10956 warn (_("Version 5 does not include inlined functions.\n"));
10958 warn (_("Version 6 does not include symbol attributes.\n"));
10959 /* Version 7 indices generated by Gold have bad type unit references,
10960 PR binutils/15021. But we don't know if the index was generated by
10961 Gold or not, so to avoid worrying users with gdb-generated indices
10962 we say nothing for version 7 here. */
10964 cu_list_offset
= byte_get_little_endian (start
+ 4, 4);
10965 tu_list_offset
= byte_get_little_endian (start
+ 8, 4);
10966 address_table_offset
= byte_get_little_endian (start
+ 12, 4);
10967 symbol_table_offset
= byte_get_little_endian (start
+ 16, 4);
10968 shortcut_table_offset
= byte_get_little_endian (start
+ 20, 4);
10970 constant_pool_offset
= shortcut_table_offset
;
10972 constant_pool_offset
= byte_get_little_endian (start
+ 24, 4);
10974 if (cu_list_offset
> section
->size
10975 || tu_list_offset
> section
->size
10976 || address_table_offset
> section
->size
10977 || symbol_table_offset
> section
->size
10978 || shortcut_table_offset
> section
->size
10979 || constant_pool_offset
> section
->size
10980 || tu_list_offset
< cu_list_offset
10981 || address_table_offset
< tu_list_offset
10982 || symbol_table_offset
< address_table_offset
10983 || shortcut_table_offset
< symbol_table_offset
10984 || constant_pool_offset
< shortcut_table_offset
)
10986 warn (_("Corrupt header in the %s section.\n"), section
->name
);
10990 cu_list_elements
= (tu_list_offset
- cu_list_offset
) / 16;
10991 tu_list_elements
= (address_table_offset
- tu_list_offset
) / 24;
10992 address_table_elements
= (symbol_table_offset
- address_table_offset
) / 20;
10993 symbol_table_slots
= (shortcut_table_offset
- symbol_table_offset
) / 8;
10995 cu_list
= start
+ cu_list_offset
;
10996 tu_list
= start
+ tu_list_offset
;
10997 address_table
= start
+ address_table_offset
;
10998 symbol_table
= start
+ symbol_table_offset
;
10999 shortcut_table
= start
+ shortcut_table_offset
;
11000 constant_pool
= start
+ constant_pool_offset
;
11002 printf (_("\nCU table:\n"));
11003 for (i
= 0; i
< cu_list_elements
; i
++)
11005 uint64_t cu_offset
= byte_get_little_endian (cu_list
+ i
* 16, 8);
11006 uint64_t cu_length
= byte_get_little_endian (cu_list
+ i
* 16 + 8, 8);
11008 printf ("[%3u] %#" PRIx64
" - %#" PRIx64
"\n",
11009 i
, cu_offset
, cu_offset
+ cu_length
- 1);
11012 printf (_("\nTU table:\n"));
11013 for (i
= 0; i
< tu_list_elements
; i
++)
11015 uint64_t tu_offset
= byte_get_little_endian (tu_list
+ i
* 24, 8);
11016 uint64_t type_offset
= byte_get_little_endian (tu_list
+ i
* 24 + 8, 8);
11017 uint64_t signature
= byte_get_little_endian (tu_list
+ i
* 24 + 16, 8);
11019 printf ("[%3u] %#" PRIx64
" %#" PRIx64
" ",
11020 i
, tu_offset
, type_offset
);
11021 print_hex_ns (signature
, 8);
11025 printf (_("\nAddress table:\n"));
11026 for (i
= 0; i
< address_table_elements
; i
++)
11028 uint64_t low
= byte_get_little_endian (address_table
+ i
* 20, 8);
11029 uint64_t high
= byte_get_little_endian (address_table
+ i
* 20 + 8, 8);
11030 uint32_t cu_index
= byte_get_little_endian (address_table
+ i
* 20 + 16, 4);
11032 print_hex (low
, 8);
11033 print_hex (high
, 8);
11034 printf ("%" PRIu32
"\n", cu_index
);
11037 printf (_("\nSymbol table:\n"));
11038 for (i
= 0; i
< symbol_table_slots
; ++i
)
11040 uint32_t name_offset
= byte_get_little_endian (symbol_table
+ i
* 8, 4);
11041 uint32_t cu_vector_offset
= byte_get_little_endian (symbol_table
+ i
* 8 + 4, 4);
11042 uint32_t num_cus
, cu
;
11044 if (name_offset
!= 0
11045 || cu_vector_offset
!= 0)
11049 /* PR 17531: file: 5b7b07ad. */
11050 if (name_offset
>= section
->size
- constant_pool_offset
)
11052 printf (_("[%3u] <corrupt offset: %x>"), i
, name_offset
);
11053 warn (_("Corrupt name offset of 0x%x found for symbol table slot %d\n"),
11057 printf ("[%3u] %.*s:", i
,
11058 (int) (section
->size
- (constant_pool_offset
+ name_offset
)),
11059 constant_pool
+ name_offset
);
11061 if (section
->size
- constant_pool_offset
< 4
11062 || cu_vector_offset
> section
->size
- constant_pool_offset
- 4)
11064 printf (_("<invalid CU vector offset: %x>\n"), cu_vector_offset
);
11065 warn (_("Corrupt CU vector offset of 0x%x found for symbol table slot %d\n"),
11066 cu_vector_offset
, i
);
11070 num_cus
= byte_get_little_endian (constant_pool
+ cu_vector_offset
, 4);
11072 if ((uint64_t) num_cus
* 4 > section
->size
- (constant_pool_offset
11073 + cu_vector_offset
+ 4))
11075 printf ("<invalid number of CUs: %d>\n", num_cus
);
11076 warn (_("Invalid number of CUs (0x%x) for symbol table slot %d\n"),
11084 for (j
= 0; j
< num_cus
; ++j
)
11087 gdb_index_symbol_kind kind
;
11089 cu
= byte_get_little_endian (constant_pool
+ cu_vector_offset
+ 4 + j
* 4, 4);
11090 is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu
);
11091 kind
= GDB_INDEX_SYMBOL_KIND_VALUE (cu
);
11092 cu
= GDB_INDEX_CU_VALUE (cu
);
11093 /* Convert to TU number if it's for a type unit. */
11094 if (cu
>= cu_list_elements
)
11095 printf ("%cT%lu", num_cus
> 1 ? '\t' : ' ',
11096 (unsigned long) cu
- cu_list_elements
);
11098 printf ("%c%lu", num_cus
> 1 ? '\t' : ' ', (unsigned long) cu
);
11100 printf (" [%s, %s]",
11101 is_static
? _("static") : _("global"),
11102 get_gdb_index_symbol_kind_name (kind
));
11113 printf (_("\nShortcut table:\n"));
11115 if (shortcut_table_offset
+ 8 > constant_pool_offset
)
11117 warn (_("Corrupt shortcut table in the %s section.\n"), section
->name
);
11121 uint32_t lang
= byte_get_little_endian (shortcut_table
, 4);
11122 printf (_("Language of main: "));
11123 display_lang (lang
);
11126 printf (_("Name of main: "));
11128 printf (_("<unknown>\n"));
11131 uint32_t name_offset
= byte_get_little_endian (shortcut_table
+ 4, 4);
11132 if (name_offset
>= section
->size
- constant_pool_offset
)
11134 printf (_("<corrupt offset: %x>\n"), name_offset
);
11135 warn (_("Corrupt name offset of 0x%x found for name of main\n"),
11139 printf ("%s\n", constant_pool
+ name_offset
);
11146 /* Pre-allocate enough space for the CU/TU sets needed. */
11149 prealloc_cu_tu_list (unsigned int nshndx
)
11152 /* Always allocate at least one entry for the end-marker. */
11155 if (shndx_pool
== NULL
)
11157 shndx_pool_size
= nshndx
;
11158 shndx_pool_used
= 0;
11159 shndx_pool
= (unsigned int *) xcmalloc (shndx_pool_size
,
11160 sizeof (unsigned int));
11164 shndx_pool_size
= shndx_pool_used
+ nshndx
;
11165 shndx_pool
= (unsigned int *) xcrealloc (shndx_pool
, shndx_pool_size
,
11166 sizeof (unsigned int));
11171 add_shndx_to_cu_tu_entry (unsigned int shndx
)
11173 shndx_pool
[shndx_pool_used
++] = shndx
;
11177 end_cu_tu_entry (void)
11179 shndx_pool
[shndx_pool_used
++] = 0;
11182 /* Return the short name of a DWARF section given by a DW_SECT enumerator. */
11184 static const char *
11185 get_DW_SECT_short_name (unsigned int dw_sect
)
11187 static char buf
[16];
11193 case DW_SECT_TYPES
:
11195 case DW_SECT_ABBREV
:
11201 case DW_SECT_STR_OFFSETS
:
11203 case DW_SECT_MACINFO
:
11205 case DW_SECT_MACRO
:
11211 snprintf (buf
, sizeof (buf
), "%d", dw_sect
);
11215 /* Process a CU or TU index. If DO_DISPLAY is true, print the contents.
11216 These sections are extensions for Fission.
11217 See http://gcc.gnu.org/wiki/DebugFissionDWP. */
11220 process_cu_tu_index (struct dwarf_section
*section
, int do_display
)
11222 unsigned char *phdr
= section
->start
;
11223 unsigned char *limit
= phdr
+ section
->size
;
11224 unsigned char *phash
;
11225 unsigned char *pindex
;
11226 unsigned char *ppool
;
11227 unsigned int version
;
11228 unsigned int ncols
= 0;
11229 unsigned int nused
;
11230 unsigned int nslots
;
11233 uint64_t signature
;
11236 /* PR 17512: file: 002-168123-0.004. */
11239 warn (_("Section %s is empty\n"), section
->name
);
11242 /* PR 17512: file: 002-376-0.004. */
11243 if (section
->size
< 24)
11245 warn (_("Section %s is too small to contain a CU/TU header\n"),
11251 SAFE_BYTE_GET_AND_INC (version
, phash
, 4, limit
);
11253 SAFE_BYTE_GET_AND_INC (ncols
, phash
, 4, limit
);
11254 SAFE_BYTE_GET_AND_INC (nused
, phash
, 4, limit
);
11255 SAFE_BYTE_GET_AND_INC (nslots
, phash
, 4, limit
);
11257 pindex
= phash
+ (size_t) nslots
* 8;
11258 ppool
= pindex
+ (size_t) nslots
* 4;
11262 introduce (section
, false);
11264 printf (_(" Version: %u\n"), version
);
11266 printf (_(" Number of columns: %u\n"), ncols
);
11267 printf (_(" Number of used entries: %u\n"), nused
);
11268 printf (_(" Number of slots: %u\n\n"), nslots
);
11271 /* PR 17531: file: 45d69832. */
11272 if (_mul_overflow ((size_t) nslots
, 12, &total
)
11273 || total
> (size_t) (limit
- phash
))
11275 warn (ngettext ("Section %s is too small for %u slot\n",
11276 "Section %s is too small for %u slots\n",
11278 section
->name
, nslots
);
11284 unsigned char *shndx_list
;
11285 unsigned int shndx
;
11289 prealloc_cu_tu_list ((limit
- ppool
) / 4);
11290 for (shndx_list
= ppool
+ 4; shndx_list
<= limit
- 4; shndx_list
+= 4)
11292 shndx
= byte_get (shndx_list
, 4);
11293 add_shndx_to_cu_tu_entry (shndx
);
11295 end_cu_tu_entry ();
11298 for (i
= 0; i
< nslots
; i
++)
11300 SAFE_BYTE_GET (signature
, phash
, 8, limit
);
11301 if (signature
!= 0)
11303 SAFE_BYTE_GET (j
, pindex
, 4, limit
);
11304 shndx_list
= ppool
+ j
* 4;
11305 /* PR 17531: file: 705e010d. */
11306 if (shndx_list
< ppool
)
11308 warn (_("Section index pool located before start of section\n"));
11312 printf (_(" [%3d] Signature: %#" PRIx64
" Sections: "),
11316 if (shndx_list
>= limit
)
11318 warn (_("Section %s too small for shndx pool\n"),
11322 SAFE_BYTE_GET (shndx
, shndx_list
, 4, limit
);
11325 printf (" %d", shndx
);
11334 else if (version
== 2)
11337 unsigned int dw_sect
;
11338 unsigned char *ph
= phash
;
11339 unsigned char *pi
= pindex
;
11340 unsigned char *poffsets
= ppool
+ (size_t) ncols
* 4;
11341 unsigned char *psizes
= poffsets
+ (size_t) nused
* ncols
* 4;
11343 struct cu_tu_set
*this_set
= NULL
;
11345 unsigned char *prow
;
11348 is_tu_index
= strcmp (section
->name
, ".debug_tu_index") == 0;
11350 /* PR 17531: file: 0dd159bf.
11351 Check for integer overflow (can occur when size_t is 32-bit)
11352 with overlarge ncols or nused values. */
11354 || _mul_overflow ((size_t) ncols
, 4, &temp
)
11355 || _mul_overflow ((size_t) nused
+ 1, temp
, &total
)
11356 || total
> (size_t) (limit
- ppool
)
11357 /* PR 30227: ncols could be 0. */
11358 || _mul_overflow ((size_t) nused
+ 1, 4, &total
)
11359 || total
> (size_t) (limit
- ppool
))
11361 warn (_("Section %s too small for offset and size tables\n"),
11368 printf (_(" Offset table\n"));
11369 printf (" slot %-16s ",
11370 is_tu_index
? _("signature") : _("dwo_id"));
11377 tu_sets
= xcalloc2 (nused
, sizeof (struct cu_tu_set
));
11378 this_set
= tu_sets
;
11383 cu_sets
= xcalloc2 (nused
, sizeof (struct cu_tu_set
));
11384 this_set
= cu_sets
;
11390 for (j
= 0; j
< ncols
; j
++)
11392 unsigned char *p
= ppool
+ j
* 4;
11393 SAFE_BYTE_GET (dw_sect
, p
, 4, limit
);
11394 printf (" %8s", get_DW_SECT_short_name (dw_sect
));
11399 for (i
= 0; i
< nslots
; i
++)
11401 SAFE_BYTE_GET (signature
, ph
, 8, limit
);
11403 SAFE_BYTE_GET (row
, pi
, 4, limit
);
11406 /* PR 17531: file: a05f6ab3. */
11409 warn (_("Row index (%u) is larger than number of used entries (%u)\n"),
11416 size_t num_copy
= sizeof (uint64_t);
11418 memcpy (&this_set
[row
- 1].signature
, ph
, num_copy
);
11421 prow
= poffsets
+ (row
- 1) * ncols
* 4;
11423 printf (" [%3d] %#" PRIx64
, i
, signature
);
11424 for (j
= 0; j
< ncols
; j
++)
11426 unsigned char *p
= prow
+ j
* 4;
11427 SAFE_BYTE_GET (val
, p
, 4, limit
);
11429 printf (" %8d", val
);
11433 SAFE_BYTE_GET (dw_sect
, p
, 4, limit
);
11435 /* PR 17531: file: 10796eb3. */
11436 if (dw_sect
>= DW_SECT_MAX
)
11437 warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect
);
11439 this_set
[row
- 1].section_offsets
[dw_sect
] = val
;
11455 printf (_(" Size table\n"));
11456 printf (" slot %-16s ",
11457 is_tu_index
? _("signature") : _("dwo_id"));
11460 for (j
= 0; j
< ncols
; j
++)
11462 unsigned char *p
= ppool
+ j
* 4;
11463 SAFE_BYTE_GET (val
, p
, 4, limit
);
11465 printf (" %8s", get_DW_SECT_short_name (val
));
11471 for (i
= 0; i
< nslots
; i
++)
11473 SAFE_BYTE_GET (signature
, ph
, 8, limit
);
11475 SAFE_BYTE_GET (row
, pi
, 4, limit
);
11478 prow
= psizes
+ (row
- 1) * ncols
* 4;
11481 printf (" [%3d] %#" PRIx64
, i
, signature
);
11483 for (j
= 0; j
< ncols
; j
++)
11485 unsigned char *p
= prow
+ j
* 4;
11487 /* PR 28645: Check for overflow. Since we do not know how
11488 many populated rows there will be, we cannot just
11489 perform a single check at the start of this function. */
11490 if (p
> (limit
- 4))
11494 warn (_("Too many rows/columns in DWARF index section %s\n"),
11499 SAFE_BYTE_GET (val
, p
, 4, limit
);
11502 printf (" %8d", val
);
11506 SAFE_BYTE_GET (dw_sect
, p
, 4, limit
);
11507 if (dw_sect
>= DW_SECT_MAX
)
11508 warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect
);
11510 this_set
[row
- 1].section_sizes
[dw_sect
] = val
;
11522 else if (do_display
)
11523 printf (_(" Unsupported version (%d)\n"), version
);
11531 static int cu_tu_indexes_read
= -1; /* Tri-state variable. */
11533 /* Load the CU and TU indexes if present. This will build a list of
11534 section sets that we can use to associate a .debug_info.dwo section
11535 with its associated .debug_abbrev.dwo section in a .dwp file. */
11538 load_cu_tu_indexes (void *file
)
11540 /* If we have already loaded (or tried to load) the CU and TU indexes
11541 then do not bother to repeat the task. */
11542 if (cu_tu_indexes_read
== -1)
11544 cu_tu_indexes_read
= true;
11546 if (load_debug_section_with_follow (dwp_cu_index
, file
))
11547 if (! process_cu_tu_index (&debug_displays
[dwp_cu_index
].section
, 0))
11548 cu_tu_indexes_read
= false;
11550 if (load_debug_section_with_follow (dwp_tu_index
, file
))
11551 if (! process_cu_tu_index (&debug_displays
[dwp_tu_index
].section
, 0))
11552 cu_tu_indexes_read
= false;
11555 return (bool) cu_tu_indexes_read
;
11558 /* Find the set of sections that includes section SHNDX. */
11561 find_cu_tu_set (void *file
, unsigned int shndx
)
11565 if (! load_cu_tu_indexes (file
))
11568 /* Find SHNDX in the shndx pool. */
11569 for (i
= 0; i
< shndx_pool_used
; i
++)
11570 if (shndx_pool
[i
] == shndx
)
11573 if (i
>= shndx_pool_used
)
11576 /* Now backup to find the first entry in the set. */
11577 while (i
> 0 && shndx_pool
[i
- 1] != 0)
11580 return shndx_pool
+ i
;
11583 /* Display a .debug_cu_index or .debug_tu_index section. */
11586 display_cu_index (struct dwarf_section
*section
, void *file ATTRIBUTE_UNUSED
)
11588 return process_cu_tu_index (section
, 1);
11592 display_debug_not_supported (struct dwarf_section
*section
,
11593 void *file ATTRIBUTE_UNUSED
)
11595 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
11601 /* Like malloc, but takes two parameters like calloc.
11602 Verifies that the first parameter is not too large.
11603 Note: does *not* initialise the allocated memory to zero. */
11606 cmalloc (uint64_t nmemb
, size_t size
)
11608 /* Check for overflow. */
11609 if (nmemb
>= ~(size_t) 0 / size
)
11612 return xmalloc (nmemb
* size
);
11615 /* Like xmalloc, but takes two parameters like calloc.
11616 Verifies that the first parameter is not too large.
11617 Note: does *not* initialise the allocated memory to zero. */
11620 xcmalloc (uint64_t nmemb
, size_t size
)
11622 /* Check for overflow. */
11623 if (nmemb
>= ~(size_t) 0 / size
)
11626 _("Attempt to allocate an array with an excessive number of elements: %#" PRIx64
"\n"),
11631 return xmalloc (nmemb
* size
);
11634 /* Like xrealloc, but takes three parameters.
11635 Verifies that the second parameter is not too large.
11636 Note: does *not* initialise any new memory to zero. */
11639 xcrealloc (void *ptr
, uint64_t nmemb
, size_t size
)
11641 /* Check for overflow. */
11642 if (nmemb
>= ~(size_t) 0 / size
)
11644 error (_("Attempt to re-allocate an array with an excessive number of elements: %#" PRIx64
"\n"),
11649 return xrealloc (ptr
, nmemb
* size
);
11652 /* Like xcalloc, but verifies that the first parameter is not too large. */
11655 xcalloc2 (uint64_t nmemb
, size_t size
)
11657 /* Check for overflow. */
11658 if (nmemb
>= ~(size_t) 0 / size
)
11660 error (_("Attempt to allocate a zero'ed array with an excessive number of elements: %#" PRIx64
"\n"),
11665 return xcalloc (nmemb
, size
);
11668 static unsigned long
11669 calc_gnu_debuglink_crc32 (unsigned long crc
,
11670 const unsigned char *buf
,
11673 static const unsigned long crc32_table
[256] =
11675 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
11676 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
11677 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
11678 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
11679 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
11680 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
11681 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
11682 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
11683 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
11684 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
11685 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
11686 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
11687 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
11688 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
11689 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
11690 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
11691 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
11692 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
11693 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
11694 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
11695 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
11696 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
11697 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
11698 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
11699 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
11700 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
11701 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
11702 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
11703 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
11704 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
11705 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
11706 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
11707 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
11708 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
11709 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
11710 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
11711 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
11712 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
11713 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
11714 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
11715 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
11716 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
11717 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
11718 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
11719 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
11720 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
11721 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
11722 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
11723 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
11724 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
11725 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
11728 const unsigned char *end
;
11730 crc
= ~crc
& 0xffffffff;
11731 for (end
= buf
+ len
; buf
< end
; ++ buf
)
11732 crc
= crc32_table
[(crc
^ *buf
) & 0xff] ^ (crc
>> 8);
11733 return ~crc
& 0xffffffff;
11736 typedef bool (*check_func_type
) (const char *, void *);
11737 typedef const char *(* parse_func_type
) (struct dwarf_section
*, void *);
11740 check_gnu_debuglink (const char * pathname
, void * crc_pointer
)
11742 static unsigned char buffer
[8 * 1024];
11745 unsigned long crc
= 0;
11748 sep_data
= open_debug_file (pathname
);
11749 if (sep_data
== NULL
)
11752 /* Yes - we are opening the file twice... */
11753 f
= fopen (pathname
, "rb");
11756 /* Paranoia: This should never happen. */
11757 close_debug_file (sep_data
);
11758 warn (_("Unable to reopen separate debug info file: %s\n"), pathname
);
11762 while ((count
= fread (buffer
, 1, sizeof (buffer
), f
)) > 0)
11763 crc
= calc_gnu_debuglink_crc32 (crc
, buffer
, count
);
11767 if (crc
!= * (unsigned long *) crc_pointer
)
11769 close_debug_file (sep_data
);
11770 warn (_("Separate debug info file %s found, but CRC does not match - ignoring\n"),
11778 static const char *
11779 parse_gnu_debuglink (struct dwarf_section
* section
, void * data
)
11782 unsigned int crc_offset
;
11783 unsigned long * crc32
= (unsigned long *) data
;
11785 /* The name is first.
11786 The CRC value is stored after the filename, aligned up to 4 bytes. */
11787 name
= (const char *) section
->start
;
11789 crc_offset
= strnlen (name
, section
->size
) + 1;
11790 if (crc_offset
== 1)
11792 crc_offset
= (crc_offset
+ 3) & ~3;
11793 if (crc_offset
+ 4 > section
->size
)
11796 * crc32
= byte_get (section
->start
+ crc_offset
, 4);
11801 check_gnu_debugaltlink (const char * filename
, void * data ATTRIBUTE_UNUSED
)
11803 void * sep_data
= open_debug_file (filename
);
11805 if (sep_data
== NULL
)
11808 /* FIXME: We should now extract the build-id in the separate file
11814 typedef struct build_id_data
11817 const unsigned char *data
;
11820 static const char *
11821 parse_gnu_debugaltlink (struct dwarf_section
* section
, void * data
)
11826 Build_id_data
*build_id_data
;
11828 /* The name is first.
11829 The build-id follows immediately, with no padding, up to the section's end. */
11831 name
= (const char *) section
->start
;
11832 namelen
= strnlen (name
, section
->size
) + 1;
11835 if (namelen
>= section
->size
)
11838 id_len
= section
->size
- namelen
;
11842 build_id_data
= (Build_id_data
*) data
;
11843 build_id_data
->len
= id_len
;
11844 build_id_data
->data
= section
->start
+ namelen
;
11850 add_separate_debug_file (const char * filename
, void * handle
)
11852 separate_info
* i
= xmalloc (sizeof * i
);
11854 i
->filename
= filename
;
11855 i
->handle
= handle
;
11856 i
->next
= first_separate_info
;
11857 first_separate_info
= i
;
11860 #if HAVE_LIBDEBUGINFOD
11861 /* Query debuginfod servers for the target debuglink or debugaltlink
11862 file. If successful, store the path of the file in filename and
11863 return TRUE, otherwise return FALSE. */
11866 debuginfod_fetch_separate_debug_info (struct dwarf_section
* section
,
11870 size_t build_id_len
;
11871 unsigned char * build_id
;
11873 if (strcmp (section
->uncompressed_name
, ".gnu_debuglink") == 0)
11875 /* Get the build-id of file. */
11876 build_id
= get_build_id (file
);
11879 else if (strcmp (section
->uncompressed_name
, ".gnu_debugaltlink") == 0)
11881 /* Get the build-id of the debugaltlink file. */
11882 unsigned int filelen
;
11884 filelen
= strnlen ((const char *)section
->start
, section
->size
);
11885 if (filelen
== section
->size
)
11886 /* Corrupt debugaltlink. */
11889 build_id
= section
->start
+ filelen
+ 1;
11890 build_id_len
= section
->size
- (filelen
+ 1);
11892 if (build_id_len
== 0)
11901 debuginfod_client
* client
;
11903 client
= debuginfod_begin ();
11904 if (client
== NULL
)
11907 /* Query debuginfod servers for the target file. If found its path
11908 will be stored in filename. */
11909 fd
= debuginfod_find_debuginfo (client
, build_id
, build_id_len
, filename
);
11910 debuginfod_end (client
);
11912 /* Only free build_id if we allocated space for a hex string
11913 in get_build_id (). */
11914 if (build_id_len
== 0)
11919 /* File successfully retrieved. Close fd since we want to
11920 use open_debug_file () on filename instead. */
11928 #endif /* HAVE_LIBDEBUGINFOD */
11931 load_separate_debug_info (const char * main_filename
,
11932 struct dwarf_section
* xlink
,
11933 parse_func_type parse_func
,
11934 check_func_type check_func
,
11936 void * file ATTRIBUTE_UNUSED
)
11938 const char * separate_filename
;
11939 char * debug_filename
;
11941 size_t canon_dirlen
;
11943 char * canon_filename
;
11944 char * canon_debug_filename
;
11947 if ((separate_filename
= parse_func (xlink
, func_data
)) == NULL
)
11949 warn (_("Corrupt debuglink section: %s\n"),
11950 xlink
->name
? xlink
->name
: xlink
->uncompressed_name
);
11954 /* Attempt to locate the separate file.
11955 This should duplicate the logic in bfd/opncls.c:find_separate_debug_file(). */
11957 canon_filename
= lrealpath (main_filename
);
11958 canon_dir
= xstrdup (canon_filename
);
11960 for (canon_dirlen
= strlen (canon_dir
); canon_dirlen
> 0; canon_dirlen
--)
11961 if (IS_DIR_SEPARATOR (canon_dir
[canon_dirlen
- 1]))
11963 canon_dir
[canon_dirlen
] = '\0';
11966 #define DEBUGDIR "/lib/debug"
11968 #ifndef EXTRA_DEBUG_ROOT1
11969 #define EXTRA_DEBUG_ROOT1 "/usr/lib/debug"
11971 #ifndef EXTRA_DEBUG_ROOT2
11972 #define EXTRA_DEBUG_ROOT2 "/usr/lib/debug/usr"
11975 debug_filename
= (char *) malloc (strlen (DEBUGDIR
) + 1
11977 + strlen (".debug/")
11978 #ifdef EXTRA_DEBUG_ROOT1
11979 + strlen (EXTRA_DEBUG_ROOT1
)
11981 #ifdef EXTRA_DEBUG_ROOT2
11982 + strlen (EXTRA_DEBUG_ROOT2
)
11984 + strlen (separate_filename
)
11986 if (debug_filename
== NULL
)
11988 warn (_("Out of memory\n"));
11990 free (canon_filename
);
11994 /* First try in the current directory. */
11995 sprintf (debug_filename
, "%s", separate_filename
);
11996 if (check_func (debug_filename
, func_data
))
11999 /* Then try in a subdirectory called .debug. */
12000 sprintf (debug_filename
, ".debug/%s", separate_filename
);
12001 if (check_func (debug_filename
, func_data
))
12004 /* Then try in the same directory as the original file. */
12005 sprintf (debug_filename
, "%s%s", canon_dir
, separate_filename
);
12006 if (check_func (debug_filename
, func_data
))
12009 /* And the .debug subdirectory of that directory. */
12010 sprintf (debug_filename
, "%s.debug/%s", canon_dir
, separate_filename
);
12011 if (check_func (debug_filename
, func_data
))
12014 #ifdef EXTRA_DEBUG_ROOT1
12015 /* Try the first extra debug file root. */
12016 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT1
, separate_filename
);
12017 if (check_func (debug_filename
, func_data
))
12020 /* Try the first extra debug file root. */
12021 sprintf (debug_filename
, "%s/%s/%s", EXTRA_DEBUG_ROOT1
, canon_dir
, separate_filename
);
12022 if (check_func (debug_filename
, func_data
))
12026 #ifdef EXTRA_DEBUG_ROOT2
12027 /* Try the second extra debug file root. */
12028 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT2
, separate_filename
);
12029 if (check_func (debug_filename
, func_data
))
12033 /* Then try in the global debug_filename directory. */
12034 strcpy (debug_filename
, DEBUGDIR
);
12035 dirlen
= strlen (DEBUGDIR
) - 1;
12036 if (dirlen
> 0 && DEBUGDIR
[dirlen
] != '/')
12037 strcat (debug_filename
, "/");
12038 strcat (debug_filename
, (const char *) separate_filename
);
12040 if (check_func (debug_filename
, func_data
))
12043 #if HAVE_LIBDEBUGINFOD
12045 char * tmp_filename
;
12048 && debuginfod_fetch_separate_debug_info (xlink
,
12052 /* File successfully downloaded from server, replace
12053 debug_filename with the file's path. */
12054 free (debug_filename
);
12055 debug_filename
= tmp_filename
;
12061 if (do_debug_links
)
12063 /* Failed to find the file. */
12064 warn (_("could not find separate debug file '%s'\n"),
12065 separate_filename
);
12066 warn (_("tried: %s\n"), debug_filename
);
12068 #ifdef EXTRA_DEBUG_ROOT2
12069 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT2
,
12070 separate_filename
);
12071 warn (_("tried: %s\n"), debug_filename
);
12074 #ifdef EXTRA_DEBUG_ROOT1
12075 sprintf (debug_filename
, "%s/%s/%s", EXTRA_DEBUG_ROOT1
,
12076 canon_dir
, separate_filename
);
12077 warn (_("tried: %s\n"), debug_filename
);
12079 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT1
,
12080 separate_filename
);
12081 warn (_("tried: %s\n"), debug_filename
);
12084 sprintf (debug_filename
, "%s.debug/%s", canon_dir
,
12085 separate_filename
);
12086 warn (_("tried: %s\n"), debug_filename
);
12088 sprintf (debug_filename
, "%s%s", canon_dir
, separate_filename
);
12089 warn (_("tried: %s\n"), debug_filename
);
12091 sprintf (debug_filename
, ".debug/%s", separate_filename
);
12092 warn (_("tried: %s\n"), debug_filename
);
12094 sprintf (debug_filename
, "%s", separate_filename
);
12095 warn (_("tried: %s\n"), debug_filename
);
12097 #if HAVE_LIBDEBUGINFOD
12098 if (use_debuginfod
)
12100 char *urls
= getenv (DEBUGINFOD_URLS_ENV_VAR
);
12105 warn (_("tried: DEBUGINFOD_URLS=%s\n"), urls
);
12111 free (debug_filename
);
12112 free (canon_filename
);
12118 canon_debug_filename
= lrealpath (debug_filename
);
12119 self
= strcmp (canon_debug_filename
, canon_filename
) == 0;
12120 free (canon_filename
);
12121 free (canon_debug_filename
);
12124 free (debug_filename
);
12128 void * debug_handle
;
12130 /* Now open the file.... */
12131 if ((debug_handle
= open_debug_file (debug_filename
)) == NULL
)
12133 warn (_("failed to open separate debug file: %s\n"), debug_filename
);
12134 free (debug_filename
);
12138 /* FIXME: We do not check to see if there are any other separate debug info
12139 files that would also match. */
12141 if (do_debug_links
)
12142 printf (_("\n%s: Found separate debug info file: %s\n"), main_filename
, debug_filename
);
12143 add_separate_debug_file (debug_filename
, debug_handle
);
12145 /* Do not free debug_filename - it might be referenced inside
12146 the structure returned by open_debug_file(). */
12147 return debug_handle
;
12150 /* Attempt to load a separate dwarf object file. */
12153 load_dwo_file (const char * main_filename
, const char * name
, const char * dir
, const char * id ATTRIBUTE_UNUSED
)
12155 char * separate_filename
;
12156 void * separate_handle
;
12158 if (IS_ABSOLUTE_PATH (name
))
12159 separate_filename
= strdup (name
);
12161 /* FIXME: Skip adding / if dwo_dir ends in /. */
12162 separate_filename
= concat (dir
, "/", name
, NULL
);
12163 if (separate_filename
== NULL
)
12165 warn (_("Out of memory allocating dwo filename\n"));
12169 if ((separate_handle
= open_debug_file (separate_filename
)) == NULL
)
12171 warn (_("Unable to load dwo file: %s\n"), separate_filename
);
12172 free (separate_filename
);
12176 /* FIXME: We should check the dwo_id. */
12178 printf (_("%s: Found separate debug object file: %s\n\n"), main_filename
, separate_filename
);
12180 add_separate_debug_file (separate_filename
, separate_handle
);
12181 /* Note - separate_filename will be freed in free_debug_memory(). */
12182 return separate_handle
;
12186 try_build_id_prefix (const char * prefix
, char * filename
, const unsigned char * data
, unsigned long id_len
)
12188 char * f
= filename
;
12190 f
+= sprintf (f
, "%s.build-id/%02x/", prefix
, (unsigned) *data
++);
12193 f
+= sprintf (f
, "%02x", (unsigned) *data
++);
12194 strcpy (f
, ".debug");
12196 return open_debug_file (filename
);
12199 /* Try to load a debug file based upon the build-id held in the .note.gnu.build-id section. */
12202 load_build_id_debug_file (const char * main_filename ATTRIBUTE_UNUSED
, void * main_file
)
12204 if (! load_debug_section (note_gnu_build_id
, main_file
))
12205 return; /* No .note.gnu.build-id section. */
12207 struct dwarf_section
* section
= & debug_displays
[note_gnu_build_id
].section
;
12208 if (section
== NULL
)
12210 warn (_("Unable to load the .note.gnu.build-id section\n"));
12214 if (section
->start
== NULL
|| section
->size
< 0x18)
12216 warn (_(".note.gnu.build-id section is corrupt/empty\n"));
12220 /* In theory we should extract the contents of the section into
12221 a note structure and then check the fields. For now though
12222 just use hard coded offsets instead:
12224 Field Bytes Contents
12227 Type 8..11 3 (NT_GNU_BUILD_ID)
12231 /* FIXME: Check the name size, name and type fields. */
12233 unsigned long build_id_size
;
12234 build_id_size
= byte_get (section
->start
+ 4, 4);
12235 if (build_id_size
< 8)
12237 warn (_(".note.gnu.build-id data size is too small\n"));
12241 if (build_id_size
> (section
->size
- 16))
12243 warn (_(".note.gnu.build-id data size is too big\n"));
12248 filename
= xmalloc (strlen (".build-id/")
12249 + build_id_size
* 2 + 2
12250 + strlen (".debug")
12251 /* The next string should be the same as the longest
12252 name found in the prefixes[] array below. */
12253 + strlen ("/usrlib64/debug/usr")
12257 static const char * prefixes
[] =
12262 "/usr/lib/debug/usr/",
12263 "/usr/lib64/debug/",
12264 "/usr/lib64/debug/usr"
12266 long unsigned int i
;
12268 for (i
= 0; i
< ARRAY_SIZE (prefixes
); i
++)
12270 handle
= try_build_id_prefix (prefixes
[i
], filename
,
12271 section
->start
+ 16, build_id_size
);
12272 if (handle
!= NULL
)
12275 /* FIXME: TYhe BFD library also tries a global debugfile directory prefix. */
12276 if (handle
== NULL
)
12278 /* Failed to find a debug file associated with the build-id.
12279 This is not an error however, rather it just means that
12280 the debug info has probably not been loaded on the system,
12281 or that another method is being used to link to the debug
12287 add_separate_debug_file (filename
, handle
);
12290 /* Try to load a debug file pointed to by the .debug_sup section. */
12293 load_debug_sup_file (const char * main_filename
, void * file
)
12295 if (! load_debug_section (debug_sup
, file
))
12296 return; /* No .debug_sup section. */
12298 struct dwarf_section
* section
;
12299 section
= & debug_displays
[debug_sup
].section
;
12300 assert (section
!= NULL
);
12302 if (section
->start
== NULL
|| section
->size
< 5)
12304 warn (_(".debug_sup section is corrupt/empty\n"));
12308 if (section
->start
[2] != 0)
12309 return; /* This is a supplementary file. */
12311 const char * filename
= (const char *) section
->start
+ 3;
12312 if (strnlen (filename
, section
->size
- 3) == section
->size
- 3)
12314 warn (_("filename in .debug_sup section is corrupt\n"));
12318 if (filename
[0] != '/' && strchr (main_filename
, '/'))
12323 new_len
= asprintf (& new_name
, "%.*s/%s",
12324 (int) (strrchr (main_filename
, '/') - main_filename
),
12329 warn (_("unable to construct path for supplementary debug file\n"));
12334 filename
= new_name
;
12338 /* PR 27796: Make sure that we pass a filename that can be free'd to
12339 add_separate_debug_file(). */
12340 filename
= strdup (filename
);
12341 if (filename
== NULL
)
12343 warn (_("out of memory constructing filename for .debug_sup link\n"));
12348 void * handle
= open_debug_file (filename
);
12349 if (handle
== NULL
)
12351 warn (_("unable to open file '%s' referenced from .debug_sup section\n"), filename
);
12352 free ((void *) filename
);
12356 printf (_("%s: Found supplementary debug file: %s\n\n"), main_filename
, filename
);
12358 /* FIXME: Compare the checksums, if present. */
12359 add_separate_debug_file (filename
, handle
);
12362 /* Load a debuglink section and/or a debugaltlink section, if either are present.
12363 Recursively check the loaded files for more of these sections.
12364 Also follow any links in .debug_sup sections.
12365 FIXME: Should also check for DWO_* entries in the newly loaded files. */
12368 check_for_and_load_links (void * file
, const char * filename
)
12370 void * handle
= NULL
;
12372 if (load_debug_section (gnu_debugaltlink
, file
))
12374 Build_id_data build_id_data
;
12376 handle
= load_separate_debug_info (filename
,
12377 & debug_displays
[gnu_debugaltlink
].section
,
12378 parse_gnu_debugaltlink
,
12379 check_gnu_debugaltlink
,
12384 assert (handle
== first_separate_info
->handle
);
12385 check_for_and_load_links (first_separate_info
->handle
,
12386 first_separate_info
->filename
);
12390 if (load_debug_section (gnu_debuglink
, file
))
12392 unsigned long crc32
;
12394 handle
= load_separate_debug_info (filename
,
12395 & debug_displays
[gnu_debuglink
].section
,
12396 parse_gnu_debuglink
,
12397 check_gnu_debuglink
,
12402 assert (handle
== first_separate_info
->handle
);
12403 check_for_and_load_links (first_separate_info
->handle
,
12404 first_separate_info
->filename
);
12408 load_debug_sup_file (filename
, file
);
12410 load_build_id_debug_file (filename
, file
);
12413 /* Load the separate debug info file(s) attached to FILE, if any exist.
12414 Returns TRUE if any were found, FALSE otherwise.
12415 If TRUE is returned then the linked list starting at first_separate_info
12416 will be populated with open file handles. */
12419 load_separate_debug_files (void * file
, const char * filename
)
12421 /* Skip this operation if we are not interested in debug links. */
12422 if (! do_follow_links
&& ! do_debug_links
)
12425 /* See if there are any dwo links. */
12426 if (load_debug_section (str
, file
)
12427 && load_debug_section (abbrev
, file
)
12428 && load_debug_section (info
, file
))
12430 /* Load the .debug_addr section, if it exists. */
12431 load_debug_section (debug_addr
, file
);
12432 /* Load the .debug_str_offsets section, if it exists. */
12433 load_debug_section (str_index
, file
);
12434 /* Load the .debug_loclists section, if it exists. */
12435 load_debug_section (loclists
, file
);
12436 /* Load the .debug_rnglists section, if it exists. */
12437 load_debug_section (rnglists
, file
);
12441 if (process_debug_info (& debug_displays
[info
].section
, file
, abbrev
,
12444 bool introduced
= false;
12446 const char *dir
= NULL
;
12447 const char *id
= NULL
;
12448 const char *name
= NULL
;
12450 for (dwinfo
= first_dwo_info
; dwinfo
!= NULL
; dwinfo
= dwinfo
->next
)
12452 /* Accumulate NAME, DIR and ID fields. */
12453 switch (dwinfo
->type
)
12457 warn (_("Multiple DWO_NAMEs encountered for the same CU\n"));
12458 name
= dwinfo
->value
;
12462 /* There can be multiple DW_AT_comp_dir entries in a CU,
12463 so do not complain. */
12464 dir
= dwinfo
->value
;
12469 warn (_("multiple DWO_IDs encountered for the same CU\n"));
12470 id
= dwinfo
->value
;
12474 error (_("Unexpected DWO INFO type"));
12478 /* If we have reached the end of our list, or we are changing
12479 CUs, then display the information that we have accumulated
12482 && (dwinfo
->next
== NULL
12483 || dwinfo
->next
->cu_offset
!= dwinfo
->cu_offset
))
12485 if (do_debug_links
)
12489 printf (_("The %s section contains link(s) to dwo file(s):\n\n"),
12490 debug_displays
[info
].section
.uncompressed_name
);
12494 printf (_(" Name: %s\n"), name
);
12495 printf (_(" Directory: %s\n"), dir
? dir
: _("<not-found>"));
12497 display_data (printf (_(" ID: ")), (unsigned char *) id
, 8);
12498 else if (debug_information
[0].dwarf_version
!= 5)
12499 printf (_(" ID: <not specified>\n"));
12503 if (do_follow_links
)
12504 load_dwo_file (filename
, name
, dir
, id
);
12506 name
= dir
= id
= NULL
;
12512 if (! do_follow_links
)
12513 /* The other debug links will be displayed by display_debug_links()
12514 so we do not need to do any further processing here. */
12517 /* FIXME: We do not check for the presence of both link sections in the same file. */
12518 /* FIXME: We do not check for the presence of multiple, same-name debuglink sections. */
12519 /* FIXME: We do not check for the presence of a dwo link as well as a debuglink. */
12521 check_for_and_load_links (file
, filename
);
12522 if (first_separate_info
!= NULL
)
12525 do_follow_links
= 0;
12530 free_debug_memory (void)
12534 free_all_abbrevs ();
12538 shndx_pool_size
= 0;
12539 shndx_pool_used
= 0;
12547 memset (level_type_signed
, 0, sizeof level_type_signed
);
12548 cu_tu_indexes_read
= -1;
12550 for (i
= 0; i
< max
; i
++)
12551 free_debug_section ((enum dwarf_section_display_enum
) i
);
12553 if (debug_information
!= NULL
)
12555 for (i
= 0; i
< alloc_num_debug_info_entries
; i
++)
12556 free_debug_information (&debug_information
[i
]);
12557 free (debug_information
);
12558 debug_information
= NULL
;
12559 alloc_num_debug_info_entries
= num_debug_info_entries
= 0;
12563 separate_info
* next
;
12565 for (d
= first_separate_info
; d
!= NULL
; d
= next
)
12567 close_debug_file (d
->handle
);
12568 free ((void *) d
->filename
);
12572 first_separate_info
= NULL
;
12580 const char *option
;
12583 } debug_dump_long_opts
;
12585 static const debug_dump_long_opts debug_option_table
[] =
12587 { 'A', "addr", &do_debug_addr
, 1 },
12588 { 'a', "abbrev", &do_debug_abbrevs
, 1 },
12589 { 'c', "cu_index", &do_debug_cu_index
, 1 },
12590 #ifdef HAVE_LIBDEBUGINFOD
12591 { 'D', "use-debuginfod", &use_debuginfod
, 1 },
12592 { 'E', "do-not-use-debuginfod", &use_debuginfod
, 0 },
12594 { 'F', "frames-interp", &do_debug_frames_interp
, 1 },
12595 { 'f', "frames", &do_debug_frames
, 1 },
12596 { 'g', "gdb_index", &do_gdb_index
, 1 },
12597 { 'i', "info", &do_debug_info
, 1 },
12598 { 'K', "follow-links", &do_follow_links
, 1 },
12599 { 'k', "links", &do_debug_links
, 1 },
12600 { 'L', "decodedline", &do_debug_lines
, FLAG_DEBUG_LINES_DECODED
},
12601 { 'l', "rawline", &do_debug_lines
, FLAG_DEBUG_LINES_RAW
},
12602 /* For compatibility with earlier versions of readelf. */
12603 { 'l', "line", &do_debug_lines
, FLAG_DEBUG_LINES_RAW
},
12604 { 'm', "macro", &do_debug_macinfo
, 1 },
12605 { 'N', "no-follow-links", &do_follow_links
, 0 },
12606 { 'O', "str-offsets", &do_debug_str_offsets
, 1 },
12607 { 'o', "loc", &do_debug_loc
, 1 },
12608 { 'p', "pubnames", &do_debug_pubnames
, 1 },
12609 { 'R', "Ranges", &do_debug_ranges
, 1 },
12610 { 'r', "aranges", &do_debug_aranges
, 1 },
12611 /* For compatibility with earlier versions of readelf. */
12612 { 'r', "ranges", &do_debug_aranges
, 1 },
12613 { 's', "str", &do_debug_str
, 1 },
12614 { 'T', "trace_aranges", &do_trace_aranges
, 1 },
12615 { 't', "pubtypes", &do_debug_pubtypes
, 1 },
12616 { 'U', "trace_info", &do_trace_info
, 1 },
12617 { 'u', "trace_abbrev", &do_trace_abbrevs
, 1 },
12618 { 0, NULL
, NULL
, 0 }
12621 /* Enable display of specific DWARF sections as determined by the comma
12622 separated strings in NAMES. Returns non-zero if any displaying was
12626 dwarf_select_sections_by_names (const char *names
)
12634 const debug_dump_long_opts
*entry
;
12636 for (entry
= debug_option_table
; entry
->option
; entry
++)
12638 size_t len
= strlen (entry
->option
);
12640 if (strncmp (p
, entry
->option
, len
) == 0
12641 && (p
[len
] == ',' || p
[len
] == '\0'))
12643 if (entry
->val
== 0)
12644 * entry
->variable
= 0;
12646 * entry
->variable
= entry
->val
;
12647 result
|= entry
->val
;
12654 if (entry
->option
== NULL
)
12656 warn (_("Unrecognized debug option '%s'\n"), p
);
12657 p
= strchr (p
, ',');
12666 /* The --debug-dump=frames-interp option also enables the
12667 --debug-dump=frames option. */
12668 if (do_debug_frames_interp
)
12669 do_debug_frames
= 1;
12674 /* Enable display of specific DWARF sections as determined by the characters
12675 in LETTERS. Returns non-zero if any displaying was enabled. */
12678 dwarf_select_sections_by_letters (const char *letters
)
12684 const debug_dump_long_opts
*entry
;
12686 for (entry
= debug_option_table
; entry
->letter
; entry
++)
12688 if (entry
->letter
== * letters
)
12690 if (entry
->val
== 0)
12691 * entry
->variable
= 0;
12693 * entry
->variable
|= entry
->val
;
12694 result
|= entry
->val
;
12699 if (entry
->letter
== 0)
12700 warn (_("Unrecognized debug letter option '%c'\n"), * letters
);
12705 /* The --debug-dump=frames-interp option also enables the
12706 --debug-dump=frames option. */
12707 if (do_debug_frames_interp
)
12708 do_debug_frames
= 1;
12714 dwarf_select_sections_all (void)
12717 do_debug_abbrevs
= 1;
12718 do_debug_lines
= FLAG_DEBUG_LINES_RAW
;
12719 do_debug_pubnames
= 1;
12720 do_debug_pubtypes
= 1;
12721 do_debug_aranges
= 1;
12722 do_debug_ranges
= 1;
12723 do_debug_frames
= 1;
12724 do_debug_macinfo
= 1;
12729 do_trace_abbrevs
= 1;
12730 do_trace_aranges
= 1;
12732 do_debug_cu_index
= 1;
12733 do_follow_links
= 1;
12734 do_debug_links
= 1;
12735 do_debug_str_offsets
= 1;
12738 #define NO_ABBREVS NULL, NULL, NULL, 0, 0, 0, NULL, 0
12739 #define ABBREV(N) NULL, NULL, NULL, 0, 0, N, NULL, 0
12741 /* N.B. The order here must match the order in section_display_enum. */
12743 struct dwarf_section_display debug_displays
[] =
12745 { { ".debug_abbrev", ".zdebug_abbrev", ".dwabrev", NO_ABBREVS
}, display_debug_abbrev
, &do_debug_abbrevs
, false },
12746 { { ".debug_aranges", ".zdebug_aranges", ".dwarnge", NO_ABBREVS
}, display_debug_aranges
, &do_debug_aranges
, true },
12747 { { ".debug_frame", ".zdebug_frame", ".dwframe", NO_ABBREVS
}, display_debug_frames
, &do_debug_frames
, true },
12748 { { ".debug_info", ".zdebug_info", ".dwinfo", ABBREV (abbrev
)}, display_debug_info
, &do_debug_info
, true },
12749 { { ".debug_line", ".zdebug_line", ".dwline", NO_ABBREVS
}, display_debug_lines
, &do_debug_lines
, true },
12750 { { ".debug_pubnames", ".zdebug_pubnames", ".dwpbnms", NO_ABBREVS
}, display_debug_pubnames
, &do_debug_pubnames
, false },
12751 { { ".debug_gnu_pubnames", ".zdebug_gnu_pubnames", "", NO_ABBREVS
}, display_debug_gnu_pubnames
, &do_debug_pubnames
, false },
12752 { { ".eh_frame", "", "", NO_ABBREVS
}, display_debug_frames
, &do_debug_frames
, true },
12753 { { ".eh_frame_hdr", "", "", NO_ABBREVS
}, display_eh_frame_hdr
, &do_debug_frames
, true },
12754 { { ".debug_macinfo", ".zdebug_macinfo", "", NO_ABBREVS
}, display_debug_macinfo
, &do_debug_macinfo
, false },
12755 { { ".debug_macro", ".zdebug_macro", ".dwmac", NO_ABBREVS
}, display_debug_macro
, &do_debug_macinfo
, true },
12756 { { ".debug_str", ".zdebug_str", ".dwstr", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, false },
12757 { { ".debug_line_str", ".zdebug_line_str", "", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, false },
12758 { { ".debug_loc", ".zdebug_loc", ".dwloc", NO_ABBREVS
}, display_debug_loc
, &do_debug_loc
, true },
12759 { { ".debug_loclists", ".zdebug_loclists", "", NO_ABBREVS
}, display_debug_loc
, &do_debug_loc
, true },
12760 { { ".debug_loclists.dwo", ".zdebug_loclists.dwo", "", NO_ABBREVS
}, display_debug_loc
, &do_debug_loc
, true },
12761 { { ".debug_pubtypes", ".zdebug_pubtypes", ".dwpbtyp", NO_ABBREVS
}, display_debug_pubnames
, &do_debug_pubtypes
, false },
12762 { { ".debug_gnu_pubtypes", ".zdebug_gnu_pubtypes", "", NO_ABBREVS
}, display_debug_gnu_pubnames
, &do_debug_pubtypes
, false },
12763 { { ".debug_ranges", ".zdebug_ranges", ".dwrnges", NO_ABBREVS
}, display_debug_ranges
, &do_debug_ranges
, true },
12764 { { ".debug_rnglists", ".zdebug_rnglists", "", NO_ABBREVS
}, display_debug_ranges
, &do_debug_ranges
, true },
12765 { { ".debug_rnglists.dwo", ".zdebug_rnglists.dwo", "", NO_ABBREVS
}, display_debug_ranges
, &do_debug_ranges
, true },
12766 { { ".debug_static_func", ".zdebug_static_func", "", NO_ABBREVS
}, display_debug_not_supported
, NULL
, false },
12767 { { ".debug_static_vars", ".zdebug_static_vars", "", NO_ABBREVS
}, display_debug_not_supported
, NULL
, false },
12768 { { ".debug_types", ".zdebug_types", "", ABBREV (abbrev
) }, display_debug_types
, &do_debug_info
, true },
12769 { { ".debug_weaknames", ".zdebug_weaknames", "", NO_ABBREVS
}, display_debug_not_supported
, NULL
, false },
12770 { { ".gdb_index", "", "", NO_ABBREVS
}, display_gdb_index
, &do_gdb_index
, false },
12771 { { ".debug_names", "", "", NO_ABBREVS
}, display_debug_names
, &do_gdb_index
, false },
12772 { { ".trace_info", "", "", ABBREV (trace_abbrev
) }, display_trace_info
, &do_trace_info
, true },
12773 { { ".trace_abbrev", "", "", NO_ABBREVS
}, display_debug_abbrev
, &do_trace_abbrevs
, false },
12774 { { ".trace_aranges", "", "", NO_ABBREVS
}, display_debug_aranges
, &do_trace_aranges
, false },
12775 { { ".debug_info.dwo", ".zdebug_info.dwo", "", ABBREV (abbrev_dwo
) }, display_debug_info
, &do_debug_info
, true },
12776 { { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo", "", NO_ABBREVS
}, display_debug_abbrev
, &do_debug_abbrevs
, false },
12777 { { ".debug_types.dwo", ".zdebug_types.dwo", "", ABBREV (abbrev_dwo
) }, display_debug_types
, &do_debug_info
, true },
12778 { { ".debug_line.dwo", ".zdebug_line.dwo", "", NO_ABBREVS
}, display_debug_lines
, &do_debug_lines
, true },
12779 { { ".debug_loc.dwo", ".zdebug_loc.dwo", "", NO_ABBREVS
}, display_debug_loc
, &do_debug_loc
, true },
12780 { { ".debug_macro.dwo", ".zdebug_macro.dwo", "", NO_ABBREVS
}, display_debug_macro
, &do_debug_macinfo
, true },
12781 { { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo", "", NO_ABBREVS
}, display_debug_macinfo
, &do_debug_macinfo
, false },
12782 { { ".debug_str.dwo", ".zdebug_str.dwo", "", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, true },
12783 { { ".debug_str_offsets", ".zdebug_str_offsets", "", NO_ABBREVS
}, display_debug_str_offsets
, &do_debug_str_offsets
, true },
12784 { { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo", "", NO_ABBREVS
}, display_debug_str_offsets
, &do_debug_str_offsets
, true },
12785 { { ".debug_addr", ".zdebug_addr", "", NO_ABBREVS
}, display_debug_addr
, &do_debug_addr
, true },
12786 { { ".debug_cu_index", "", "", NO_ABBREVS
}, display_cu_index
, &do_debug_cu_index
, false },
12787 { { ".debug_tu_index", "", "", NO_ABBREVS
}, display_cu_index
, &do_debug_cu_index
, false },
12788 { { ".gnu_debuglink", "", "", NO_ABBREVS
}, display_debug_links
, &do_debug_links
, false },
12789 { { ".gnu_debugaltlink", "", "", NO_ABBREVS
}, display_debug_links
, &do_debug_links
, false },
12790 { { ".debug_sup", "", "", NO_ABBREVS
}, display_debug_sup
, &do_debug_links
, false },
12791 /* Separate debug info files can containt their own .debug_str section,
12792 and this might be in *addition* to a .debug_str section already present
12793 in the main file. Hence we need to have two entries for .debug_str. */
12794 { { ".debug_str", ".zdebug_str", "", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, false },
12795 { { ".note.gnu.build-id", "", "", NO_ABBREVS
}, display_debug_not_supported
, NULL
, false },
12798 /* A static assertion. */
12799 extern int debug_displays_assert
[ARRAY_SIZE (debug_displays
) == max
? 1 : -1];