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 if (str_offset
>= str_section
->size
)
682 warn (_("indirect offset too big: %#" PRIx64
"\n"), str_offset
);
683 return _("<indirect index offset is too big>");
686 ret
= (const char *) str_section
->start
+ str_offset
;
688 /* Unfortunately we cannot rely upon str_section ending with a NUL byte.
689 Since our caller is expecting to receive a well formed C string we test
690 for the lack of a terminating byte here. */
691 if (strnlen (ret
, str_section
->size
- str_offset
)
692 == str_section
->size
- str_offset
)
693 return _("<no NUL byte at end of section>");
699 fetch_indexed_addr (uint64_t offset
, uint32_t num_bytes
)
701 struct dwarf_section
*section
= &debug_displays
[debug_addr
].section
;
703 if (section
->start
== NULL
)
705 warn (_("Cannot fetch indexed address: the .debug_addr section is missing\n"));
709 if (offset
+ num_bytes
> section
->size
)
711 warn (_("Offset into section %s too big: %#" PRIx64
"\n"),
712 section
->name
, offset
);
716 return byte_get (section
->start
+ offset
, num_bytes
);
719 /* This is for resolving DW_FORM_rnglistx and DW_FORM_loclistx.
721 The memory layout is: base_address (taken from the CU's top DIE) points at a table of offsets,
722 relative to the section start.
723 The table of offsets contains the offsets of objects of interest relative to the table of offsets.
724 IDX is the index of the desired object in said table of offsets.
726 This returns the offset of the desired object relative to the section start or -1 upon failure. */
729 fetch_indexed_offset (uint64_t idx
,
730 enum dwarf_section_display_enum sec_enum
,
731 uint64_t base_address
,
732 uint64_t offset_size
)
734 uint64_t offset_of_offset
= base_address
+ idx
* offset_size
;
735 struct dwarf_section
*section
= &debug_displays
[sec_enum
].section
;
737 if (section
->start
== NULL
)
739 warn (_("Unable to locate %s section\n"), section
->uncompressed_name
);
743 if (section
->size
< 4)
745 warn (_("Section %s is too small to contain an value indexed from another section!\n"),
750 if (offset_of_offset
+ offset_size
>= section
->size
)
752 warn (_("Offset of %#" PRIx64
" is too big for section %s\n"),
753 offset_of_offset
, section
->name
);
757 return base_address
+ byte_get (section
->start
+ offset_of_offset
, offset_size
);
760 /* FIXME: There are better and more efficient ways to handle
761 these structures. For now though, I just want something that
762 is simple to implement. */
763 /* Records a single attribute in an abbrev. */
764 typedef struct abbrev_attr
766 unsigned long attribute
;
768 int64_t implicit_const
;
769 struct abbrev_attr
*next
;
773 /* Records a single abbrev. */
774 typedef struct abbrev_entry
776 unsigned long number
;
779 struct abbrev_attr
* first_attr
;
780 struct abbrev_attr
* last_attr
;
781 struct abbrev_entry
* next
;
785 /* Records a set of abbreviations. */
786 typedef struct abbrev_list
788 abbrev_entry
* first_abbrev
;
789 abbrev_entry
* last_abbrev
;
791 struct abbrev_list
* next
;
792 unsigned char * start_of_next_abbrevs
;
796 /* Records all the abbrevs found so far. */
797 static struct abbrev_list
* abbrev_lists
= NULL
;
799 typedef struct abbrev_map
806 /* Maps between CU offsets and abbrev sets. */
807 static abbrev_map
* cu_abbrev_map
= NULL
;
808 static unsigned long num_abbrev_map_entries
= 0;
809 static unsigned long next_free_abbrev_map_entry
= 0;
811 #define INITIAL_NUM_ABBREV_MAP_ENTRIES 8
812 #define ABBREV_MAP_ENTRIES_INCREMENT 8
815 record_abbrev_list_for_cu (uint64_t start
, uint64_t end
,
816 abbrev_list
*list
, abbrev_list
*free_list
)
818 if (free_list
!= NULL
)
820 list
->next
= abbrev_lists
;
824 if (cu_abbrev_map
== NULL
)
826 num_abbrev_map_entries
= INITIAL_NUM_ABBREV_MAP_ENTRIES
;
827 cu_abbrev_map
= xmalloc (num_abbrev_map_entries
* sizeof (* cu_abbrev_map
));
829 else if (next_free_abbrev_map_entry
== num_abbrev_map_entries
)
831 num_abbrev_map_entries
+= ABBREV_MAP_ENTRIES_INCREMENT
;
832 cu_abbrev_map
= xrealloc (cu_abbrev_map
, num_abbrev_map_entries
* sizeof (* cu_abbrev_map
));
835 cu_abbrev_map
[next_free_abbrev_map_entry
].start
= start
;
836 cu_abbrev_map
[next_free_abbrev_map_entry
].end
= end
;
837 cu_abbrev_map
[next_free_abbrev_map_entry
].list
= list
;
838 next_free_abbrev_map_entry
++;
842 free_abbrev_list (abbrev_list
*list
)
844 abbrev_entry
*abbrv
= list
->first_abbrev
;
848 abbrev_attr
*attr
= abbrv
->first_attr
;
852 abbrev_attr
*next_attr
= attr
->next
;
857 abbrev_entry
*next_abbrev
= abbrv
->next
;
862 abbrev_list
*next
= list
->next
;
868 free_all_abbrevs (void)
871 abbrev_lists
= free_abbrev_list (abbrev_lists
);
873 free (cu_abbrev_map
);
874 cu_abbrev_map
= NULL
;
875 next_free_abbrev_map_entry
= 0;
879 find_abbrev_list_by_raw_abbrev (unsigned char *raw
)
883 for (list
= abbrev_lists
; list
!= NULL
; list
= list
->next
)
884 if (list
->raw
== raw
)
890 /* Find the abbreviation map for the CU that includes OFFSET.
891 OFFSET is an absolute offset from the start of the .debug_info section. */
892 /* FIXME: This function is going to slow down readelf & objdump.
893 Not caching abbrevs is likely the answer. */
896 find_abbrev_map_by_offset (uint64_t offset
)
900 for (i
= 0; i
< next_free_abbrev_map_entry
; i
++)
901 if (cu_abbrev_map
[i
].start
<= offset
902 && cu_abbrev_map
[i
].end
> offset
)
903 return cu_abbrev_map
+ i
;
909 add_abbrev (unsigned long number
,
914 abbrev_entry
* entry
;
916 entry
= (abbrev_entry
*) xmalloc (sizeof (*entry
));
918 entry
->number
= number
;
920 entry
->children
= children
;
921 entry
->first_attr
= NULL
;
922 entry
->last_attr
= NULL
;
925 assert (list
!= NULL
);
927 if (list
->first_abbrev
== NULL
)
928 list
->first_abbrev
= entry
;
930 list
->last_abbrev
->next
= entry
;
932 list
->last_abbrev
= entry
;
936 add_abbrev_attr (unsigned long attribute
,
938 int64_t implicit_const
,
943 attr
= (abbrev_attr
*) xmalloc (sizeof (*attr
));
945 attr
->attribute
= attribute
;
947 attr
->implicit_const
= implicit_const
;
950 assert (list
!= NULL
&& list
->last_abbrev
!= NULL
);
952 if (list
->last_abbrev
->first_attr
== NULL
)
953 list
->last_abbrev
->first_attr
= attr
;
955 list
->last_abbrev
->last_attr
->next
= attr
;
957 list
->last_abbrev
->last_attr
= attr
;
960 /* Return processed (partial) contents of a .debug_abbrev section.
961 Returns NULL on errors. */
964 process_abbrev_set (struct dwarf_section
*section
,
965 unsigned char *start
,
968 abbrev_list
*list
= xmalloc (sizeof (*list
));
969 list
->first_abbrev
= NULL
;
970 list
->last_abbrev
= NULL
;
978 unsigned long attribute
;
981 READ_ULEB (entry
, start
, end
);
983 /* A single zero is supposed to end the set according
984 to the standard. If there's more, then signal that to
986 if (start
== end
|| entry
== 0)
988 list
->start_of_next_abbrevs
= start
!= end
? start
: NULL
;
992 READ_ULEB (tag
, start
, end
);
994 return free_abbrev_list (list
);
998 add_abbrev (entry
, tag
, children
, list
);
1003 /* Initialize it due to a false compiler warning. */
1004 int64_t implicit_const
= -1;
1006 READ_ULEB (attribute
, start
, end
);
1010 READ_ULEB (form
, start
, end
);
1014 if (form
== DW_FORM_implicit_const
)
1016 READ_SLEB (implicit_const
, start
, end
);
1021 add_abbrev_attr (attribute
, form
, implicit_const
, list
);
1023 while (attribute
!= 0);
1026 /* Report the missing single zero which ends the section. */
1027 error (_("%s section not zero terminated\n"), section
->name
);
1029 return free_abbrev_list (list
);
1032 /* Return a sequence of abbrevs in SECTION starting at ABBREV_BASE
1033 plus ABBREV_OFFSET and finishing at ABBREV_BASE + ABBREV_SIZE.
1034 If FREE_LIST is non-NULL search the already decoded abbrevs on
1035 abbrev_lists first and if found set *FREE_LIST to NULL. If
1036 searching doesn't find a matching abbrev, set *FREE_LIST to the
1037 newly allocated list. If FREE_LIST is NULL, no search is done and
1038 the returned abbrev_list is always newly allocated. */
1040 static abbrev_list
*
1041 find_and_process_abbrev_set (struct dwarf_section
*section
,
1042 uint64_t abbrev_base
,
1043 uint64_t abbrev_size
,
1044 uint64_t abbrev_offset
,
1045 abbrev_list
**free_list
)
1050 if (abbrev_base
>= section
->size
1051 || abbrev_size
> section
->size
- abbrev_base
)
1053 /* PR 17531: file:4bcd9ce9. */
1054 warn (_("Debug info is corrupted, abbrev size (%#" PRIx64
")"
1055 " is larger than abbrev section size (%#" PRIx64
")\n"),
1056 abbrev_base
+ abbrev_size
, section
->size
);
1059 if (abbrev_offset
>= abbrev_size
)
1061 warn (_("Debug info is corrupted, abbrev offset (%#" PRIx64
")"
1062 " is larger than abbrev section size (%#" PRIx64
")\n"),
1063 abbrev_offset
, abbrev_size
);
1067 unsigned char *start
= section
->start
+ abbrev_base
+ abbrev_offset
;
1068 unsigned char *end
= section
->start
+ abbrev_base
+ abbrev_size
;
1069 abbrev_list
*list
= NULL
;
1071 list
= find_abbrev_list_by_raw_abbrev (start
);
1074 list
= process_abbrev_set (section
, start
, end
);
1082 get_TAG_name (uint64_t tag
)
1084 const char *name
= NULL
;
1086 if ((unsigned int) tag
== tag
)
1087 name
= get_DW_TAG_name ((unsigned int) tag
);
1090 static char buffer
[100];
1092 if (tag
>= DW_TAG_lo_user
&& tag
<= DW_TAG_hi_user
)
1093 snprintf (buffer
, sizeof (buffer
),
1094 _("User TAG value: %#" PRIx64
), tag
);
1096 snprintf (buffer
, sizeof (buffer
),
1097 _("Unknown TAG value: %#" PRIx64
), tag
);
1105 get_FORM_name (unsigned long form
)
1107 const char *name
= NULL
;
1110 return "DW_FORM value: 0";
1112 if ((unsigned int) form
== form
)
1113 name
= get_DW_FORM_name ((unsigned int) form
);
1116 static char buffer
[100];
1118 snprintf (buffer
, sizeof (buffer
), _("Unknown FORM value: %lx"), form
);
1126 get_IDX_name (unsigned long idx
)
1128 const char *name
= NULL
;
1130 if ((unsigned int) idx
== idx
)
1131 name
= get_DW_IDX_name ((unsigned int) idx
);
1134 static char buffer
[100];
1136 snprintf (buffer
, sizeof (buffer
), _("Unknown IDX value: %lx"), idx
);
1143 static unsigned char *
1144 display_block (unsigned char *data
,
1146 const unsigned char * const end
, char delimiter
)
1150 printf (_("%c%" PRIu64
" byte block: "), delimiter
, length
);
1152 return (unsigned char *) end
;
1154 maxlen
= end
- data
;
1155 length
= length
> maxlen
? maxlen
: length
;
1158 printf ("%" PRIx64
" ", byte_get (data
++, 1));
1164 decode_location_expression (unsigned char * data
,
1165 unsigned int pointer_size
,
1166 unsigned int offset_size
,
1170 struct dwarf_section
* section
)
1175 unsigned char *end
= data
+ length
;
1176 int need_frame_base
= 0;
1185 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1186 printf ("DW_OP_addr: %" PRIx64
, uvalue
);
1189 printf ("DW_OP_deref");
1192 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1193 printf ("DW_OP_const1u: %" PRIu64
, uvalue
);
1196 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 1, end
);
1197 printf ("DW_OP_const1s: %" PRId64
, svalue
);
1200 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
1201 printf ("DW_OP_const2u: %" PRIu64
, uvalue
);
1204 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1205 printf ("DW_OP_const2s: %" PRId64
, svalue
);
1208 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1209 printf ("DW_OP_const4u: %" PRIu64
, uvalue
);
1212 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
1213 printf ("DW_OP_const4s: %" PRId64
, svalue
);
1216 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 8, end
);
1217 printf ("DW_OP_const8u: %" PRIu64
, uvalue
);
1220 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 8, end
);
1221 printf ("DW_OP_const8s: %" PRId64
, svalue
);
1224 READ_ULEB (uvalue
, data
, end
);
1225 printf ("DW_OP_constu: %" PRIu64
, uvalue
);
1228 READ_SLEB (svalue
, data
, end
);
1229 printf ("DW_OP_consts: %" PRId64
, svalue
);
1232 printf ("DW_OP_dup");
1235 printf ("DW_OP_drop");
1238 printf ("DW_OP_over");
1241 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1242 printf ("DW_OP_pick: %" PRIu64
, uvalue
);
1245 printf ("DW_OP_swap");
1248 printf ("DW_OP_rot");
1251 printf ("DW_OP_xderef");
1254 printf ("DW_OP_abs");
1257 printf ("DW_OP_and");
1260 printf ("DW_OP_div");
1263 printf ("DW_OP_minus");
1266 printf ("DW_OP_mod");
1269 printf ("DW_OP_mul");
1272 printf ("DW_OP_neg");
1275 printf ("DW_OP_not");
1278 printf ("DW_OP_or");
1281 printf ("DW_OP_plus");
1283 case DW_OP_plus_uconst
:
1284 READ_ULEB (uvalue
, data
, end
);
1285 printf ("DW_OP_plus_uconst: %" PRIu64
, uvalue
);
1288 printf ("DW_OP_shl");
1291 printf ("DW_OP_shr");
1294 printf ("DW_OP_shra");
1297 printf ("DW_OP_xor");
1300 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1301 printf ("DW_OP_bra: %" PRId64
, svalue
);
1304 printf ("DW_OP_eq");
1307 printf ("DW_OP_ge");
1310 printf ("DW_OP_gt");
1313 printf ("DW_OP_le");
1316 printf ("DW_OP_lt");
1319 printf ("DW_OP_ne");
1322 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1323 printf ("DW_OP_skip: %" PRId64
, svalue
);
1358 printf ("DW_OP_lit%d", op
- DW_OP_lit0
);
1393 printf ("DW_OP_reg%d (%s)", op
- DW_OP_reg0
,
1394 regname (op
- DW_OP_reg0
, 1));
1429 READ_SLEB (svalue
, data
, end
);
1430 printf ("DW_OP_breg%d (%s): %" PRId64
,
1431 op
- DW_OP_breg0
, regname (op
- DW_OP_breg0
, 1), svalue
);
1435 READ_ULEB (uvalue
, data
, end
);
1436 printf ("DW_OP_regx: %" PRIu64
" (%s)",
1437 uvalue
, regname (uvalue
, 1));
1440 need_frame_base
= 1;
1441 READ_SLEB (svalue
, data
, end
);
1442 printf ("DW_OP_fbreg: %" PRId64
, svalue
);
1445 READ_ULEB (uvalue
, data
, end
);
1446 READ_SLEB (svalue
, data
, end
);
1447 printf ("DW_OP_bregx: %" PRIu64
" (%s) %" PRId64
,
1448 uvalue
, regname (uvalue
, 1), svalue
);
1451 READ_ULEB (uvalue
, data
, end
);
1452 printf ("DW_OP_piece: %" PRIu64
, uvalue
);
1454 case DW_OP_deref_size
:
1455 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1456 printf ("DW_OP_deref_size: %" PRIu64
, uvalue
);
1458 case DW_OP_xderef_size
:
1459 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1460 printf ("DW_OP_xderef_size: %" PRIu64
, uvalue
);
1463 printf ("DW_OP_nop");
1466 /* DWARF 3 extensions. */
1467 case DW_OP_push_object_address
:
1468 printf ("DW_OP_push_object_address");
1471 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1472 this ought to be an 8-byte wide computation. */
1473 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1474 printf ("DW_OP_call2: <%#" PRIx64
">", svalue
+ cu_offset
);
1477 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1478 this ought to be an 8-byte wide computation. */
1479 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
1480 printf ("DW_OP_call4: <%#" PRIx64
">", svalue
+ cu_offset
);
1482 case DW_OP_call_ref
:
1483 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1484 this ought to be an 8-byte wide computation. */
1485 if (dwarf_version
== -1)
1487 printf (_("(DW_OP_call_ref in frame info)"));
1488 /* No way to tell where the next op is, so just bail. */
1489 return need_frame_base
;
1491 if (dwarf_version
== 2)
1493 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1497 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1499 printf ("DW_OP_call_ref: <%#" PRIx64
">", uvalue
);
1501 case DW_OP_form_tls_address
:
1502 printf ("DW_OP_form_tls_address");
1504 case DW_OP_call_frame_cfa
:
1505 printf ("DW_OP_call_frame_cfa");
1507 case DW_OP_bit_piece
:
1508 printf ("DW_OP_bit_piece: ");
1509 READ_ULEB (uvalue
, data
, end
);
1510 printf (_("size: %" PRIu64
" "), uvalue
);
1511 READ_ULEB (uvalue
, data
, end
);
1512 printf (_("offset: %" PRIu64
" "), uvalue
);
1515 /* DWARF 4 extensions. */
1516 case DW_OP_stack_value
:
1517 printf ("DW_OP_stack_value");
1520 case DW_OP_implicit_value
:
1521 printf ("DW_OP_implicit_value");
1522 READ_ULEB (uvalue
, data
, end
);
1523 data
= display_block (data
, uvalue
, end
, ' ');
1526 /* GNU extensions. */
1527 case DW_OP_GNU_push_tls_address
:
1528 printf (_("DW_OP_GNU_push_tls_address or DW_OP_HP_unknown"));
1530 case DW_OP_GNU_uninit
:
1531 printf ("DW_OP_GNU_uninit");
1532 /* FIXME: Is there data associated with this OP ? */
1534 case DW_OP_GNU_encoded_addr
:
1541 addr
= get_encoded_value (&data
, encoding
, section
, end
);
1543 printf ("DW_OP_GNU_encoded_addr: fmt:%02x addr:", encoding
);
1544 print_hex_ns (addr
, pointer_size
);
1547 case DW_OP_implicit_pointer
:
1548 case DW_OP_GNU_implicit_pointer
:
1549 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1550 this ought to be an 8-byte wide computation. */
1551 if (dwarf_version
== -1)
1553 printf (_("(%s in frame info)"),
1554 (op
== DW_OP_implicit_pointer
1555 ? "DW_OP_implicit_pointer"
1556 : "DW_OP_GNU_implicit_pointer"));
1557 /* No way to tell where the next op is, so just bail. */
1558 return need_frame_base
;
1560 if (dwarf_version
== 2)
1562 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1566 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1568 READ_SLEB (svalue
, data
, end
);
1569 printf ("%s: <%#" PRIx64
"> %" PRId64
,
1570 (op
== DW_OP_implicit_pointer
1571 ? "DW_OP_implicit_pointer" : "DW_OP_GNU_implicit_pointer"),
1574 case DW_OP_entry_value
:
1575 case DW_OP_GNU_entry_value
:
1576 READ_ULEB (uvalue
, data
, end
);
1577 /* PR 17531: file: 0cc9cd00. */
1578 if (uvalue
> (size_t) (end
- data
))
1579 uvalue
= end
- data
;
1580 printf ("%s: (", (op
== DW_OP_entry_value
? "DW_OP_entry_value"
1581 : "DW_OP_GNU_entry_value"));
1582 if (decode_location_expression (data
, pointer_size
, offset_size
,
1583 dwarf_version
, uvalue
,
1584 cu_offset
, section
))
1585 need_frame_base
= 1;
1589 case DW_OP_const_type
:
1590 case DW_OP_GNU_const_type
:
1591 READ_ULEB (uvalue
, data
, end
);
1592 printf ("%s: <%#" PRIx64
"> ",
1593 (op
== DW_OP_const_type
? "DW_OP_const_type"
1594 : "DW_OP_GNU_const_type"),
1595 cu_offset
+ uvalue
);
1596 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1597 data
= display_block (data
, uvalue
, end
, ' ');
1599 case DW_OP_regval_type
:
1600 case DW_OP_GNU_regval_type
:
1601 READ_ULEB (uvalue
, data
, end
);
1602 printf ("%s: %" PRIu64
" (%s)",
1603 (op
== DW_OP_regval_type
? "DW_OP_regval_type"
1604 : "DW_OP_GNU_regval_type"),
1605 uvalue
, regname (uvalue
, 1));
1606 READ_ULEB (uvalue
, data
, end
);
1607 printf (" <%#" PRIx64
">", cu_offset
+ uvalue
);
1609 case DW_OP_deref_type
:
1610 case DW_OP_GNU_deref_type
:
1611 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1612 printf ("%s: %" PRId64
,
1613 (op
== DW_OP_deref_type
? "DW_OP_deref_type"
1614 : "DW_OP_GNU_deref_type"),
1616 READ_ULEB (uvalue
, data
, end
);
1617 printf (" <%#" PRIx64
">", cu_offset
+ uvalue
);
1620 case DW_OP_GNU_convert
:
1621 READ_ULEB (uvalue
, data
, end
);
1622 printf ("%s <%#" PRIx64
">",
1623 (op
== DW_OP_convert
? "DW_OP_convert" : "DW_OP_GNU_convert"),
1624 uvalue
? cu_offset
+ uvalue
: uvalue
);
1626 case DW_OP_reinterpret
:
1627 case DW_OP_GNU_reinterpret
:
1628 READ_ULEB (uvalue
, data
, end
);
1629 printf ("%s <%#" PRIx64
">",
1630 (op
== DW_OP_reinterpret
? "DW_OP_reinterpret"
1631 : "DW_OP_GNU_reinterpret"),
1632 uvalue
? cu_offset
+ uvalue
: uvalue
);
1634 case DW_OP_GNU_parameter_ref
:
1635 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1636 printf ("DW_OP_GNU_parameter_ref: <%#" PRIx64
">",
1637 cu_offset
+ uvalue
);
1640 READ_ULEB (uvalue
, data
, end
);
1641 printf ("DW_OP_addrx <%#" PRIx64
">", uvalue
);
1643 case DW_OP_GNU_addr_index
:
1644 READ_ULEB (uvalue
, data
, end
);
1645 printf ("DW_OP_GNU_addr_index <%#" PRIx64
">", uvalue
);
1647 case DW_OP_GNU_const_index
:
1648 READ_ULEB (uvalue
, data
, end
);
1649 printf ("DW_OP_GNU_const_index <%#" PRIx64
">", uvalue
);
1651 case DW_OP_GNU_variable_value
:
1652 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1653 this ought to be an 8-byte wide computation. */
1654 if (dwarf_version
== -1)
1656 printf (_("(DW_OP_GNU_variable_value in frame info)"));
1657 /* No way to tell where the next op is, so just bail. */
1658 return need_frame_base
;
1660 if (dwarf_version
== 2)
1662 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1666 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1668 printf ("DW_OP_GNU_variable_value: <%#" PRIx64
">", uvalue
);
1671 /* HP extensions. */
1672 case DW_OP_HP_is_value
:
1673 printf ("DW_OP_HP_is_value");
1674 /* FIXME: Is there data associated with this OP ? */
1676 case DW_OP_HP_fltconst4
:
1677 printf ("DW_OP_HP_fltconst4");
1678 /* FIXME: Is there data associated with this OP ? */
1680 case DW_OP_HP_fltconst8
:
1681 printf ("DW_OP_HP_fltconst8");
1682 /* FIXME: Is there data associated with this OP ? */
1684 case DW_OP_HP_mod_range
:
1685 printf ("DW_OP_HP_mod_range");
1686 /* FIXME: Is there data associated with this OP ? */
1688 case DW_OP_HP_unmod_range
:
1689 printf ("DW_OP_HP_unmod_range");
1690 /* FIXME: Is there data associated with this OP ? */
1693 printf ("DW_OP_HP_tls");
1694 /* FIXME: Is there data associated with this OP ? */
1697 /* PGI (STMicroelectronics) extensions. */
1698 case DW_OP_PGI_omp_thread_num
:
1699 /* Pushes the thread number for the current thread as it would be
1700 returned by the standard OpenMP library function:
1701 omp_get_thread_num(). The "current thread" is the thread for
1702 which the expression is being evaluated. */
1703 printf ("DW_OP_PGI_omp_thread_num");
1707 if (op
>= DW_OP_lo_user
1708 && op
<= DW_OP_hi_user
)
1709 printf (_("(User defined location op %#x)"), op
);
1711 printf (_("(Unknown location op %#x)"), op
);
1712 /* No way to tell where the next op is, so just bail. */
1713 return need_frame_base
;
1716 /* Separate the ops. */
1721 return need_frame_base
;
1724 /* Find the CU or TU set corresponding to the given CU_OFFSET.
1725 This is used for DWARF package files. */
1727 static struct cu_tu_set
*
1728 find_cu_tu_set_v2 (uint64_t cu_offset
, int do_types
)
1730 struct cu_tu_set
*p
;
1732 unsigned int dw_sect
;
1738 dw_sect
= DW_SECT_TYPES
;
1744 dw_sect
= DW_SECT_INFO
;
1748 if (p
->section_offsets
[dw_sect
] == cu_offset
)
1757 fetch_alt_indirect_string (uint64_t offset
)
1761 if (! do_follow_links
)
1764 if (first_separate_info
== NULL
)
1765 return _("<no links available>");
1767 for (i
= first_separate_info
; i
!= NULL
; i
= i
->next
)
1769 struct dwarf_section
* section
;
1772 if (! load_debug_section (separate_debug_str
, i
->handle
))
1775 section
= &debug_displays
[separate_debug_str
].section
;
1777 if (section
->start
== NULL
)
1780 if (offset
>= section
->size
)
1783 ret
= (const char *) (section
->start
+ offset
);
1784 /* Unfortunately we cannot rely upon the .debug_str section ending with a
1785 NUL byte. Since our caller is expecting to receive a well formed C
1786 string we test for the lack of a terminating byte here. */
1787 if (strnlen ((const char *) ret
, section
->size
- offset
)
1788 == section
->size
- offset
)
1789 return _("<no NUL byte at end of alt .debug_str section>");
1794 warn (_("DW_FORM_GNU_strp_alt offset (%#" PRIx64
")"
1795 " too big or no string sections available\n"), offset
);
1796 return _("<offset is too big>");
1800 get_AT_name (unsigned long attribute
)
1805 return "DW_AT value: 0";
1807 /* One value is shared by the MIPS and HP extensions: */
1808 if (attribute
== DW_AT_MIPS_fde
)
1809 return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable";
1811 name
= get_DW_AT_name (attribute
);
1815 static char buffer
[100];
1817 snprintf (buffer
, sizeof (buffer
), _("Unknown AT value: %lx"),
1826 add_dwo_info (const char * value
, uint64_t cu_offset
, dwo_type type
)
1828 dwo_info
* dwinfo
= xmalloc (sizeof * dwinfo
);
1830 dwinfo
->type
= type
;
1831 dwinfo
->value
= value
;
1832 dwinfo
->cu_offset
= cu_offset
;
1833 dwinfo
->next
= first_dwo_info
;
1834 first_dwo_info
= dwinfo
;
1838 add_dwo_name (const char * name
, uint64_t cu_offset
)
1840 add_dwo_info (name
, cu_offset
, DWO_NAME
);
1844 add_dwo_dir (const char * dir
, uint64_t cu_offset
)
1846 add_dwo_info (dir
, cu_offset
, DWO_DIR
);
1850 add_dwo_id (const char * id
, uint64_t cu_offset
)
1852 add_dwo_info (id
, cu_offset
, DWO_ID
);
1856 free_dwo_info (void)
1861 for (dwinfo
= first_dwo_info
; dwinfo
!= NULL
; dwinfo
= next
)
1863 next
= dwinfo
->next
;
1866 first_dwo_info
= NULL
;
1869 /* Ensure that START + UVALUE is less than END.
1870 Return an adjusted UVALUE if necessary to ensure this relationship. */
1872 static inline uint64_t
1873 check_uvalue (const unsigned char *start
,
1875 const unsigned char *end
)
1877 uint64_t max_uvalue
= end
- start
;
1879 /* See PR 17512: file: 008-103549-0.001:0.1.
1880 and PR 24829 for examples of where these tests are triggered. */
1881 if (uvalue
> max_uvalue
)
1883 warn (_("Corrupt attribute block length: %#" PRIx64
"\n"), uvalue
);
1884 uvalue
= max_uvalue
;
1890 static unsigned char *
1891 skip_attr_bytes (unsigned long form
,
1892 unsigned char *data
,
1894 uint64_t pointer_size
,
1895 uint64_t offset_size
,
1897 uint64_t *value_return
)
1900 uint64_t uvalue
= 0;
1907 case DW_FORM_ref_addr
:
1908 if (dwarf_version
== 2)
1909 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1910 else if (dwarf_version
> 2)
1911 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1917 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1921 case DW_FORM_line_strp
:
1922 case DW_FORM_sec_offset
:
1923 case DW_FORM_GNU_ref_alt
:
1924 case DW_FORM_GNU_strp_alt
:
1925 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1928 case DW_FORM_flag_present
:
1936 case DW_FORM_addrx1
:
1937 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1941 case DW_FORM_addrx3
:
1942 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 3, end
);
1948 case DW_FORM_addrx2
:
1949 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
1955 case DW_FORM_addrx4
:
1956 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1960 READ_SLEB (svalue
, data
, end
);
1964 case DW_FORM_ref_udata
:
1966 case DW_FORM_GNU_str_index
:
1968 case DW_FORM_GNU_addr_index
:
1970 case DW_FORM_loclistx
:
1971 case DW_FORM_rnglistx
:
1972 READ_ULEB (uvalue
, data
, end
);
1976 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 8, end
);
1980 case DW_FORM_ref_sig8
:
1984 case DW_FORM_data16
:
1988 case DW_FORM_string
:
1989 inc
= strnlen ((char *) data
, end
- data
) + 1;
1993 case DW_FORM_exprloc
:
1994 READ_ULEB (uvalue
, data
, end
);
1998 case DW_FORM_block1
:
1999 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
2003 case DW_FORM_block2
:
2004 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
2008 case DW_FORM_block4
:
2009 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
2013 case DW_FORM_indirect
:
2014 READ_ULEB (form
, data
, end
);
2015 if (form
== DW_FORM_implicit_const
)
2016 SKIP_ULEB (data
, end
);
2017 return skip_attr_bytes (form
, data
, end
, pointer_size
, offset_size
,
2018 dwarf_version
, value_return
);
2024 * value_return
= uvalue
;
2025 if (inc
<= (size_t) (end
- data
))
2032 /* Given form FORM with value UVALUE, locate and return the abbreviation
2033 associated with it. */
2035 static abbrev_entry
*
2036 get_type_abbrev_from_form (unsigned long form
,
2039 unsigned char *cu_end
,
2040 const struct dwarf_section
*section
,
2041 unsigned long *abbrev_num_return
,
2042 unsigned char **data_return
,
2043 abbrev_map
**map_return
)
2047 case DW_FORM_GNU_ref_alt
:
2048 case DW_FORM_ref_sig8
:
2049 /* FIXME: We are unable to handle this form at the moment. */
2052 case DW_FORM_ref_addr
:
2053 if (uvalue
>= section
->size
)
2055 warn (_("Unable to resolve ref_addr form: uvalue %" PRIx64
2056 " >= section size %" PRIx64
" (%s)\n"),
2057 uvalue
, section
->size
, section
->name
);
2062 case DW_FORM_ref_sup4
:
2063 case DW_FORM_ref_sup8
:
2070 case DW_FORM_ref_udata
:
2071 if (uvalue
+ cu_offset
< uvalue
2072 || uvalue
+ cu_offset
> (size_t) (cu_end
- section
->start
))
2074 warn (_("Unable to resolve ref form: uvalue %" PRIx64
2075 " + cu_offset %" PRIx64
" > CU size %tx\n"),
2076 uvalue
, cu_offset
, cu_end
- section
->start
);
2079 uvalue
+= cu_offset
;
2082 /* FIXME: Are there other DW_FORMs that can be used by types ? */
2085 warn (_("Unexpected form %lx encountered whilst finding abbreviation for type\n"), form
);
2089 abbrev_map
*map
= find_abbrev_map_by_offset (uvalue
);
2093 warn (_("Unable to find abbreviations for CU offset %" PRIx64
"\n"),
2097 if (map
->list
== NULL
)
2099 warn (_("Empty abbreviation list encountered for CU offset %" PRIx64
"\n"),
2104 if (map_return
!= NULL
)
2106 if (form
== DW_FORM_ref_addr
)
2112 unsigned char *data
= section
->start
+ uvalue
;
2113 if (form
== DW_FORM_ref_addr
)
2114 cu_end
= section
->start
+ map
->end
;
2116 unsigned long abbrev_number
;
2117 READ_ULEB (abbrev_number
, data
, cu_end
);
2119 if (abbrev_num_return
!= NULL
)
2120 *abbrev_num_return
= abbrev_number
;
2122 if (data_return
!= NULL
)
2123 *data_return
= data
;
2125 abbrev_entry
*entry
;
2126 for (entry
= map
->list
->first_abbrev
; entry
!= NULL
; entry
= entry
->next
)
2127 if (entry
->number
== abbrev_number
)
2131 warn (_("Unable to find entry for abbreviation %lu\n"), abbrev_number
);
2136 /* Return IS_SIGNED set to TRUE if the type using abbreviation ENTRY
2137 can be determined to be a signed type. The data for ENTRY can be
2138 found starting at DATA. */
2141 get_type_signedness (abbrev_entry
*entry
,
2142 const struct dwarf_section
*section
,
2143 unsigned char *data
,
2146 uint64_t pointer_size
,
2147 uint64_t offset_size
,
2150 unsigned int nesting
)
2154 * is_signed
= false;
2156 #define MAX_NESTING 20
2157 if (nesting
> MAX_NESTING
)
2159 /* FIXME: Warn - or is this expected ?
2160 NB/ We need to avoid infinite recursion. */
2164 for (attr
= entry
->first_attr
;
2165 attr
!= NULL
&& attr
->attribute
;
2168 unsigned char * orig_data
= data
;
2169 uint64_t uvalue
= 0;
2171 data
= skip_attr_bytes (attr
->form
, data
, end
, pointer_size
,
2172 offset_size
, dwarf_version
, & uvalue
);
2176 switch (attr
->attribute
)
2178 case DW_AT_linkage_name
:
2182 if (attr
->form
== DW_FORM_strp
)
2183 printf (", %s", fetch_indirect_string (uvalue
));
2184 else if (attr
->form
== DW_FORM_string
)
2185 printf (", %.*s", (int) (end
- orig_data
), orig_data
);
2192 abbrev_entry
*type_abbrev
;
2193 unsigned char *type_data
;
2196 type_abbrev
= get_type_abbrev_from_form (attr
->form
,
2201 NULL
/* abbrev num return */,
2204 if (type_abbrev
== NULL
)
2207 get_type_signedness (type_abbrev
, section
, type_data
,
2208 map
? section
->start
+ map
->end
: end
,
2209 map
? map
->start
: cu_offset
,
2210 pointer_size
, offset_size
, dwarf_version
,
2211 is_signed
, nesting
+ 1);
2215 case DW_AT_encoding
:
2216 /* Determine signness. */
2219 case DW_ATE_address
:
2220 /* FIXME - some architectures have signed addresses. */
2221 case DW_ATE_boolean
:
2222 case DW_ATE_unsigned
:
2223 case DW_ATE_unsigned_char
:
2224 case DW_ATE_unsigned_fixed
:
2225 * is_signed
= false;
2229 case DW_ATE_complex_float
:
2232 case DW_ATE_signed_char
:
2233 case DW_ATE_imaginary_float
:
2234 case DW_ATE_decimal_float
:
2235 case DW_ATE_signed_fixed
:
2245 read_and_print_leb128 (unsigned char *data
,
2246 unsigned int *bytes_read
,
2247 unsigned const char *end
,
2251 uint64_t val
= read_leb128 (data
, end
, is_signed
, bytes_read
, &status
);
2253 report_leb_status (status
);
2255 printf ("%" PRId64
, val
);
2257 printf ("%" PRIu64
, val
);
2261 display_discr_list (unsigned long form
,
2263 unsigned char *data
,
2266 unsigned char *end
= data
;
2270 printf ("[default]");
2277 case DW_FORM_block1
:
2278 case DW_FORM_block2
:
2279 case DW_FORM_block4
:
2280 /* Move data pointer back to the start of the byte array. */
2284 printf ("<corrupt>\n");
2285 warn (_("corrupt discr_list - not using a block form\n"));
2291 printf ("<corrupt>\n");
2292 warn (_("corrupt discr_list - block not long enough\n"));
2296 bool is_signed
= (level
> 0 && level
<= MAX_CU_NESTING
2297 ? level_type_signed
[level
- 1] : false);
2302 unsigned char discriminant
;
2303 unsigned int bytes_read
;
2305 SAFE_BYTE_GET_AND_INC (discriminant
, data
, 1, end
);
2307 switch (discriminant
)
2311 read_and_print_leb128 (data
, & bytes_read
, end
, is_signed
);
2317 read_and_print_leb128 (data
, & bytes_read
, end
, is_signed
);
2321 read_and_print_leb128 (data
, & bytes_read
, end
, is_signed
);
2326 printf ("<corrupt>\n");
2327 warn (_("corrupt discr_list - unrecognized discriminant byte %#x\n"),
2337 printf (")(signed)");
2339 printf (")(unsigned)");
2343 display_lang (uint64_t uvalue
)
2347 /* Ordered by the numeric value of these constants. */
2348 case DW_LANG_C89
: printf ("ANSI C"); break;
2349 case DW_LANG_C
: printf ("non-ANSI C"); break;
2350 case DW_LANG_Ada83
: printf ("Ada"); break;
2351 case DW_LANG_C_plus_plus
: printf ("C++"); break;
2352 case DW_LANG_Cobol74
: printf ("Cobol 74"); break;
2353 case DW_LANG_Cobol85
: printf ("Cobol 85"); break;
2354 case DW_LANG_Fortran77
: printf ("FORTRAN 77"); break;
2355 case DW_LANG_Fortran90
: printf ("Fortran 90"); break;
2356 case DW_LANG_Pascal83
: printf ("ANSI Pascal"); break;
2357 case DW_LANG_Modula2
: printf ("Modula 2"); break;
2359 /* DWARF 2.1 values. */
2360 case DW_LANG_Java
: printf ("Java"); break;
2361 case DW_LANG_C99
: printf ("ANSI C99"); break;
2362 case DW_LANG_Ada95
: printf ("ADA 95"); break;
2363 case DW_LANG_Fortran95
: printf ("Fortran 95"); break;
2365 /* DWARF 3 values. */
2366 case DW_LANG_PLI
: printf ("PLI"); break;
2367 case DW_LANG_ObjC
: printf ("Objective C"); break;
2368 case DW_LANG_ObjC_plus_plus
: printf ("Objective C++"); break;
2369 case DW_LANG_UPC
: printf ("Unified Parallel C"); break;
2370 case DW_LANG_D
: printf ("D"); break;
2372 /* DWARF 4 values. */
2373 case DW_LANG_Python
: printf ("Python"); break;
2375 /* DWARF 5 values. */
2376 case DW_LANG_OpenCL
: printf ("OpenCL"); break;
2377 case DW_LANG_Go
: printf ("Go"); break;
2378 case DW_LANG_Modula3
: printf ("Modula 3"); break;
2379 case DW_LANG_Haskell
: printf ("Haskell"); break;
2380 case DW_LANG_C_plus_plus_03
: printf ("C++03"); break;
2381 case DW_LANG_C_plus_plus_11
: printf ("C++11"); break;
2382 case DW_LANG_OCaml
: printf ("OCaml"); break;
2383 case DW_LANG_Rust
: printf ("Rust"); break;
2384 case DW_LANG_C11
: printf ("C11"); break;
2385 case DW_LANG_Swift
: printf ("Swift"); break;
2386 case DW_LANG_Julia
: printf ("Julia"); break;
2387 case DW_LANG_Dylan
: printf ("Dylan"); break;
2388 case DW_LANG_C_plus_plus_14
: printf ("C++14"); break;
2389 case DW_LANG_Fortran03
: printf ("Fortran 03"); break;
2390 case DW_LANG_Fortran08
: printf ("Fortran 08"); break;
2391 case DW_LANG_RenderScript
: printf ("RenderScript"); break;
2392 case DW_LANG_C17
: printf ("C17"); break;
2393 case DW_LANG_Fortran18
: printf ("Fortran 18"); break;
2394 case DW_LANG_Ada2005
: printf ("Ada 2005"); break;
2395 case DW_LANG_Ada2012
: printf ("Ada 2012"); break;
2396 case DW_LANG_HIP
: printf ("Hip"); break;
2397 case DW_LANG_Assembly
: printf ("Assembler"); break;
2398 case DW_LANG_C_sharp
: printf ("C Sharp"); break;
2399 case DW_LANG_Mojo
: printf ("Mojo"); break;
2400 case DW_LANG_GLSL
: printf ("GLSL"); break;
2401 case DW_LANG_GLSL_ES
: printf ("GLSL_ES"); break;
2402 case DW_LANG_HLSL
: printf ("HLSL"); break;
2403 case DW_LANG_OpenCL_CPP
: printf ("OpenCL C++"); break;
2404 case DW_LANG_CPP_for_OpenCL
: printf ("C++ for OpenCL"); break;
2405 case DW_LANG_SYCL
: printf ("SYCL"); break;
2406 case DW_LANG_C_plus_plus_17
: printf ("C++17"); break;
2407 case DW_LANG_C_plus_plus_20
: printf ("C++20"); break;
2408 case DW_LANG_C_plus_plus_23
: printf ("C++23"); break;
2409 case DW_LANG_Odin
: printf ("Odin"); break;
2410 case DW_LANG_P4
: printf ("P4"); break;
2411 case DW_LANG_Metal
: printf ("C23"); break;
2412 case DW_LANG_C23
: printf ("C23"); break;
2413 case DW_LANG_Fortran23
: printf ("Fortran 23"); break;
2414 case DW_LANG_Ruby
: printf ("Ruby"); break;
2415 case DW_LANG_Move
: printf ("Move"); break;
2416 case DW_LANG_Hylo
: printf ("Hylo"); break;
2418 /* MIPS extension. */
2419 case DW_LANG_Mips_Assembler
: printf ("MIPS assembler"); break;
2421 /* UPC extension. */
2422 case DW_LANG_Upc
: printf ("Unified Parallel C"); break;
2425 if (uvalue
>= DW_LANG_lo_user
&& uvalue
<= DW_LANG_hi_user
)
2426 printf (_("implementation defined: %#" PRIx64
""), uvalue
);
2428 printf (_("unknown: %#" PRIx64
""), uvalue
);
2433 static unsigned char *
2434 read_and_display_attr_value (unsigned long attribute
,
2436 int64_t implicit_const
,
2437 unsigned char *start
,
2438 unsigned char *data
,
2441 uint64_t pointer_size
,
2442 uint64_t offset_size
,
2444 debug_info
*debug_info_p
,
2446 struct dwarf_section
*section
,
2447 struct cu_tu_set
*this_set
,
2452 uint64_t uvalue
= 0;
2453 uint64_t uvalue_hi
= 0;
2454 unsigned char *block_start
= NULL
;
2455 unsigned char *orig_data
= data
;
2457 if (data
> end
|| (data
== end
&& form
!= DW_FORM_flag_present
))
2459 warn (_("Corrupt attribute\n"));
2463 if (do_wide
&& ! do_loc
)
2465 /* PR 26847: Display the name of the form. */
2466 const char * name
= get_FORM_name (form
);
2468 /* For convenience we skip the DW_FORM_ prefix to the name. */
2470 name
+= 8; /* strlen ("DW_FORM_") */
2471 printf ("%c(%s)", delimiter
, name
);
2476 case DW_FORM_ref_addr
:
2477 if (dwarf_version
== 2)
2478 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
2479 else if (dwarf_version
> 2)
2480 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
2482 error (_("Internal error: DW_FORM_ref_addr is not supported in DWARF version 1.\n"));
2486 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
2489 case DW_FORM_strp_sup
:
2491 case DW_FORM_line_strp
:
2492 case DW_FORM_sec_offset
:
2493 case DW_FORM_GNU_ref_alt
:
2494 case DW_FORM_GNU_strp_alt
:
2495 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
2498 case DW_FORM_flag_present
:
2506 case DW_FORM_addrx1
:
2507 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
2513 case DW_FORM_addrx2
:
2514 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
2518 case DW_FORM_addrx3
:
2519 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 3, end
);
2522 case DW_FORM_ref_sup4
:
2526 case DW_FORM_addrx4
:
2527 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
2530 case DW_FORM_ref_sup8
:
2533 case DW_FORM_ref_sig8
:
2534 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 8, end
);
2537 case DW_FORM_data16
:
2538 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 8, end
);
2539 SAFE_BYTE_GET_AND_INC (uvalue_hi
, data
, 8, end
);
2540 if (byte_get
!= byte_get_little_endian
)
2542 uint64_t utmp
= uvalue
;
2549 READ_SLEB (svalue
, data
, end
);
2553 case DW_FORM_GNU_str_index
:
2555 case DW_FORM_ref_udata
:
2557 case DW_FORM_GNU_addr_index
:
2559 case DW_FORM_loclistx
:
2560 case DW_FORM_rnglistx
:
2561 READ_ULEB (uvalue
, data
, end
);
2564 case DW_FORM_indirect
:
2565 READ_ULEB (form
, data
, end
);
2567 printf ("%c%s", delimiter
, get_FORM_name (form
));
2568 if (form
== DW_FORM_implicit_const
)
2569 READ_SLEB (implicit_const
, data
, end
);
2570 return read_and_display_attr_value (attribute
, form
, implicit_const
,
2572 cu_offset
, pointer_size
,
2573 offset_size
, dwarf_version
,
2574 debug_info_p
, do_loc
,
2575 section
, this_set
, delimiter
, level
);
2577 case DW_FORM_implicit_const
:
2578 uvalue
= implicit_const
;
2587 case DW_FORM_ref_addr
:
2589 printf ("%c<%#" PRIx64
">", delimiter
, uvalue
);
2592 case DW_FORM_GNU_ref_alt
:
2596 /* We have already printed the form name. */
2597 printf ("%c<%#" PRIx64
">", delimiter
, uvalue
);
2599 printf ("%c<alt %#" PRIx64
">", delimiter
, uvalue
);
2601 /* FIXME: Follow the reference... */
2607 case DW_FORM_ref_sup4
:
2608 case DW_FORM_ref_udata
:
2610 printf ("%c<%#" PRIx64
">", delimiter
, uvalue
+ cu_offset
);
2615 case DW_FORM_sec_offset
:
2617 printf ("%c%#" PRIx64
, delimiter
, uvalue
);
2620 case DW_FORM_flag_present
:
2626 printf ("%c%" PRId64
, delimiter
, uvalue
);
2631 printf ("%c%" PRIu64
, delimiter
, uvalue
);
2634 case DW_FORM_implicit_const
:
2636 printf ("%c%" PRId64
, delimiter
, implicit_const
);
2639 case DW_FORM_ref_sup8
:
2644 uint64_t utmp
= uvalue
;
2645 if (form
== DW_FORM_ref8
)
2647 printf ("%c%#" PRIx64
, delimiter
, utmp
);
2651 case DW_FORM_data16
:
2655 printf (" %#" PRIx64
, uvalue
);
2657 printf (" %#" PRIx64
"%016" PRIx64
, uvalue_hi
, uvalue
);
2661 case DW_FORM_string
:
2663 printf ("%c%.*s", delimiter
, (int) (end
- data
), data
);
2664 data
+= strnlen ((char *) data
, end
- data
);
2670 case DW_FORM_exprloc
:
2671 READ_ULEB (uvalue
, data
, end
);
2674 if (block_start
>= end
)
2676 warn (_("Block ends prematurely\n"));
2681 uvalue
= check_uvalue (block_start
, uvalue
, end
);
2683 data
= block_start
+ uvalue
;
2688 SAFE_BYTE_GET (op
, block_start
, sizeof (op
), end
);
2689 if (op
!= DW_OP_addrx
)
2690 data
= display_block (block_start
, uvalue
, end
, delimiter
);
2694 case DW_FORM_block1
:
2695 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
2698 case DW_FORM_block2
:
2699 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
2702 case DW_FORM_block4
:
2703 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
2710 /* We have already displayed the form name. */
2711 printf (_("%c(offset: %#" PRIx64
"): %s"),
2712 delimiter
, uvalue
, fetch_indirect_string (uvalue
));
2714 printf (_("%c(indirect string, offset: %#" PRIx64
"): %s"),
2715 delimiter
, uvalue
, fetch_indirect_string (uvalue
));
2719 case DW_FORM_line_strp
:
2723 /* We have already displayed the form name. */
2724 printf (_("%c(offset: %#" PRIx64
"): %s"),
2725 delimiter
, uvalue
, fetch_indirect_line_string (uvalue
));
2727 printf (_("%c(indirect line string, offset: %#" PRIx64
"): %s"),
2728 delimiter
, uvalue
, fetch_indirect_line_string (uvalue
));
2732 case DW_FORM_GNU_str_index
:
2740 const char *suffix
= section
? strrchr (section
->name
, '.') : NULL
;
2741 bool dwo
= suffix
&& strcmp (suffix
, ".dwo") == 0;
2744 strng
= fetch_indexed_string (uvalue
, this_set
, offset_size
, dwo
,
2745 debug_info_p
? debug_info_p
->str_offsets_base
: 0);
2747 /* We have already displayed the form name. */
2748 printf (_("%c(offset: %#" PRIx64
"): %s"),
2749 delimiter
, uvalue
, strng
);
2751 printf (_("%c(indexed string: %#" PRIx64
"): %s"),
2752 delimiter
, uvalue
, strng
);
2756 case DW_FORM_GNU_strp_alt
:
2760 /* We have already displayed the form name. */
2761 printf (_("%c(offset: %#" PRIx64
") %s"),
2762 delimiter
, uvalue
, fetch_alt_indirect_string (uvalue
));
2764 printf (_("%c(alt indirect string, offset: %#" PRIx64
") %s"),
2765 delimiter
, uvalue
, fetch_alt_indirect_string (uvalue
));
2769 case DW_FORM_indirect
:
2770 /* Handled above. */
2773 case DW_FORM_ref_sig8
:
2775 printf ("%c%s: %#" PRIx64
, delimiter
, do_wide
? "" : "signature",
2779 case DW_FORM_GNU_addr_index
:
2781 case DW_FORM_addrx1
:
2782 case DW_FORM_addrx2
:
2783 case DW_FORM_addrx3
:
2784 case DW_FORM_addrx4
:
2785 case DW_FORM_loclistx
:
2786 case DW_FORM_rnglistx
:
2790 const char *suffix
= strrchr (section
->name
, '.');
2791 bool dwo
= suffix
&& strcmp (suffix
, ".dwo") == 0;
2793 if (form
== DW_FORM_loclistx
)
2795 if (debug_info_p
== NULL
)
2799 idx
= fetch_indexed_offset (uvalue
, loclists_dwo
,
2800 debug_info_p
->loclists_base
,
2801 debug_info_p
->offset_size
);
2802 if (idx
!= (uint64_t) -1)
2803 idx
+= (offset_size
== 8) ? 20 : 12;
2805 else if (dwarf_version
> 4)
2807 idx
= fetch_indexed_offset (uvalue
, loclists
,
2808 debug_info_p
->loclists_base
,
2809 debug_info_p
->offset_size
);
2813 /* We want to compute:
2814 idx = fetch_indexed_value (uvalue, loclists,
2815 debug_info_p->loclists_base);
2816 idx += debug_info_p->loclists_base;
2817 Fortunately we already have that sum cached in the
2818 loc_offsets array. */
2819 if (uvalue
< debug_info_p
->num_loc_offsets
)
2820 idx
= debug_info_p
->loc_offsets
[uvalue
];
2823 warn (_("loc_offset %" PRIu64
" too big\n"), uvalue
);
2828 else if (form
== DW_FORM_rnglistx
)
2830 if (debug_info_p
== NULL
)
2833 idx
= fetch_indexed_offset (uvalue
,
2834 dwo
? rnglists_dwo
: rnglists
,
2835 debug_info_p
->rnglists_base
,
2836 debug_info_p
->offset_size
);
2840 if (debug_info_p
== NULL
)
2842 else if (debug_info_p
->addr_base
== DEBUG_INFO_UNAVAILABLE
)
2845 base
= debug_info_p
->addr_base
;
2847 base
+= uvalue
* pointer_size
;
2848 idx
= fetch_indexed_addr (base
, pointer_size
);
2851 /* We have already displayed the form name. */
2852 if (idx
!= (uint64_t) -1)
2853 printf (_("%c(index: %#" PRIx64
"): %#" PRIx64
),
2854 delimiter
, uvalue
, idx
);
2858 case DW_FORM_strp_sup
:
2860 printf ("%c<%#" PRIx64
">", delimiter
, uvalue
+ cu_offset
);
2864 warn (_("Unrecognized form: %#lx\n"), form
);
2865 /* What to do? Consume a byte maybe? */
2870 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
|| do_debug_info
)
2871 && num_debug_info_entries
== 0
2872 && debug_info_p
!= NULL
)
2876 case DW_AT_loclists_base
:
2877 if (debug_info_p
->loclists_base
)
2878 warn (_("CU @ %#" PRIx64
" has multiple loclists_base values "
2879 "(%#" PRIx64
" and %#" PRIx64
")\n"),
2880 debug_info_p
->cu_offset
,
2881 debug_info_p
->loclists_base
, uvalue
);
2885 warn (_("CU @ %#" PRIx64
" has has a negative loclists_base "
2886 "value of %#" PRIx64
" - treating as zero\n"),
2887 debug_info_p
->cu_offset
, svalue
);
2890 debug_info_p
->loclists_base
= uvalue
;
2893 case DW_AT_rnglists_base
:
2894 /* Assignment to debug_info_p->rnglists_base is now elsewhere. */
2897 case DW_AT_str_offsets_base
:
2898 if (debug_info_p
->str_offsets_base
)
2899 warn (_("CU @ %#" PRIx64
" has multiple str_offsets_base values "
2900 "%#" PRIx64
" and %#" PRIx64
")\n"),
2901 debug_info_p
->cu_offset
,
2902 debug_info_p
->str_offsets_base
, uvalue
);
2906 warn (_("CU @ %#" PRIx64
" has has a negative stroffsets_base "
2907 "value of %#" PRIx64
" - treating as zero\n"),
2908 debug_info_p
->cu_offset
, svalue
);
2911 debug_info_p
->str_offsets_base
= uvalue
;
2914 case DW_AT_frame_base
:
2915 /* This is crude; the have_frame_base is reset on the next
2916 subprogram, not at the end of the current topmost one. */
2917 have_frame_base
= 1;
2918 frame_base_level
= level
;
2920 case DW_AT_location
:
2921 case DW_AT_GNU_locviews
:
2922 case DW_AT_string_length
:
2923 case DW_AT_return_addr
:
2924 case DW_AT_data_member_location
:
2925 case DW_AT_vtable_elem_location
:
2927 case DW_AT_static_link
:
2928 case DW_AT_use_location
:
2929 case DW_AT_call_value
:
2930 case DW_AT_GNU_call_site_value
:
2931 case DW_AT_call_data_value
:
2932 case DW_AT_GNU_call_site_data_value
:
2933 case DW_AT_call_target
:
2934 case DW_AT_GNU_call_site_target
:
2935 case DW_AT_call_target_clobbered
:
2936 case DW_AT_GNU_call_site_target_clobbered
:
2937 if ((dwarf_version
< 4
2938 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
2939 || form
== DW_FORM_sec_offset
2940 || form
== DW_FORM_loclistx
)
2942 /* Process location list. */
2943 unsigned int lmax
= debug_info_p
->max_loc_offsets
;
2944 unsigned int num
= debug_info_p
->num_loc_offsets
;
2946 if (lmax
== 0 || num
>= lmax
)
2949 debug_info_p
->loc_offsets
= (uint64_t *)
2950 xcrealloc (debug_info_p
->loc_offsets
,
2951 lmax
, sizeof (*debug_info_p
->loc_offsets
));
2952 debug_info_p
->loc_views
= (uint64_t *)
2953 xcrealloc (debug_info_p
->loc_views
,
2954 lmax
, sizeof (*debug_info_p
->loc_views
));
2955 debug_info_p
->have_frame_base
= (int *)
2956 xcrealloc (debug_info_p
->have_frame_base
,
2957 lmax
, sizeof (*debug_info_p
->have_frame_base
));
2958 debug_info_p
->max_loc_offsets
= lmax
;
2960 if (form
== DW_FORM_loclistx
)
2961 uvalue
= fetch_indexed_offset (num
, loclists
,
2962 debug_info_p
->loclists_base
,
2963 debug_info_p
->offset_size
);
2964 else if (this_set
!= NULL
)
2965 uvalue
+= this_set
->section_offsets
[DW_SECT_LOC
];
2967 debug_info_p
->have_frame_base
[num
] = have_frame_base
;
2968 if (attribute
!= DW_AT_GNU_locviews
)
2970 /* Corrupt DWARF info can produce more offsets than views.
2971 See PR 23062 for an example. */
2972 if (debug_info_p
->num_loc_offsets
2973 > debug_info_p
->num_loc_views
)
2974 warn (_("More location offset attributes than DW_AT_GNU_locview attributes\n"));
2977 debug_info_p
->loc_offsets
[num
] = uvalue
;
2978 debug_info_p
->num_loc_offsets
++;
2983 if (debug_info_p
->num_loc_views
> num
)
2985 warn (_("The number of views (%u) is greater than the number of locations (%u)\n"),
2986 debug_info_p
->num_loc_views
, num
);
2987 debug_info_p
->num_loc_views
= num
;
2990 num
= debug_info_p
->num_loc_views
;
2991 if (num
> debug_info_p
->num_loc_offsets
)
2992 warn (_("More DW_AT_GNU_locview attributes than location offset attributes\n"));
2995 debug_info_p
->loc_views
[num
] = uvalue
;
2996 debug_info_p
->num_loc_views
++;
3003 if (need_base_address
)
3005 if (form
== DW_FORM_addrx
)
3006 uvalue
= fetch_indexed_addr (debug_info_p
->addr_base
3007 + uvalue
* pointer_size
,
3010 debug_info_p
->base_address
= uvalue
;
3014 case DW_AT_GNU_addr_base
:
3015 case DW_AT_addr_base
:
3016 debug_info_p
->addr_base
= uvalue
;
3017 /* Retrieved elsewhere so that it is in
3018 place by the time we read low_pc. */
3021 case DW_AT_GNU_ranges_base
:
3022 debug_info_p
->ranges_base
= uvalue
;
3026 if ((dwarf_version
< 4
3027 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
3028 || form
== DW_FORM_sec_offset
3029 || form
== DW_FORM_rnglistx
)
3031 /* Process range list. */
3032 unsigned int lmax
= debug_info_p
->max_range_lists
;
3033 unsigned int num
= debug_info_p
->num_range_lists
;
3035 if (lmax
== 0 || num
>= lmax
)
3038 debug_info_p
->range_lists
= (uint64_t *)
3039 xcrealloc (debug_info_p
->range_lists
,
3040 lmax
, sizeof (*debug_info_p
->range_lists
));
3041 debug_info_p
->max_range_lists
= lmax
;
3044 if (form
== DW_FORM_rnglistx
)
3045 uvalue
= fetch_indexed_offset (uvalue
, rnglists
,
3046 debug_info_p
->rnglists_base
,
3047 debug_info_p
->offset_size
);
3049 debug_info_p
->range_lists
[num
] = uvalue
;
3050 debug_info_p
->num_range_lists
++;
3054 case DW_AT_GNU_dwo_name
:
3055 case DW_AT_dwo_name
:
3060 add_dwo_name ((const char *) fetch_indirect_string (uvalue
),
3063 case DW_FORM_GNU_strp_alt
:
3064 add_dwo_name ((const char *) fetch_alt_indirect_string (uvalue
), cu_offset
);
3066 case DW_FORM_GNU_str_index
:
3072 add_dwo_name (fetch_indexed_string (uvalue
, this_set
,
3074 debug_info_p
->str_offsets_base
),
3077 case DW_FORM_string
:
3078 add_dwo_name ((const char *) orig_data
, cu_offset
);
3081 warn (_("Unsupported form (%s) for attribute %s\n"),
3082 get_FORM_name (form
), get_AT_name (attribute
));
3087 case DW_AT_comp_dir
:
3088 /* FIXME: Also extract a build-id in a CU/TU. */
3093 add_dwo_dir ((const char *) fetch_indirect_string (uvalue
), cu_offset
);
3095 case DW_FORM_GNU_strp_alt
:
3096 add_dwo_dir (fetch_alt_indirect_string (uvalue
), cu_offset
);
3098 case DW_FORM_line_strp
:
3099 add_dwo_dir ((const char *) fetch_indirect_line_string (uvalue
), cu_offset
);
3101 case DW_FORM_GNU_str_index
:
3107 add_dwo_dir (fetch_indexed_string (uvalue
, this_set
, offset_size
, false,
3108 debug_info_p
->str_offsets_base
),
3111 case DW_FORM_string
:
3112 add_dwo_dir ((const char *) orig_data
, cu_offset
);
3115 warn (_("Unsupported form (%s) for attribute %s\n"),
3116 get_FORM_name (form
), get_AT_name (attribute
));
3121 case DW_AT_GNU_dwo_id
:
3126 /* FIXME: Record the length of the ID as well ? */
3127 add_dwo_id ((const char *) (data
- 8), cu_offset
);
3130 warn (_("Unsupported form (%s) for attribute %s\n"),
3131 get_FORM_name (form
), get_AT_name (attribute
));
3141 if (do_loc
|| attribute
== 0)
3144 /* For some attributes we can display further information. */
3148 if (level
>= 0 && level
< MAX_CU_NESTING
3149 && uvalue
< (size_t) (end
- start
))
3151 bool is_signed
= false;
3152 abbrev_entry
*type_abbrev
;
3153 unsigned char *type_data
;
3156 type_abbrev
= get_type_abbrev_from_form (form
, uvalue
,
3160 if (type_abbrev
!= NULL
)
3162 get_type_signedness (type_abbrev
, section
, type_data
,
3163 map
? section
->start
+ map
->end
: end
,
3164 map
? map
->start
: cu_offset
,
3165 pointer_size
, offset_size
, dwarf_version
,
3168 level_type_signed
[level
] = is_signed
;
3176 case DW_INL_not_inlined
:
3177 printf (_("(not inlined)"));
3179 case DW_INL_inlined
:
3180 printf (_("(inlined)"));
3182 case DW_INL_declared_not_inlined
:
3183 printf (_("(declared as inline but ignored)"));
3185 case DW_INL_declared_inlined
:
3186 printf (_("(declared as inline and inlined)"));
3189 printf (_(" (Unknown inline attribute value: %#" PRIx64
")"),
3195 case DW_AT_language
:
3197 display_lang (uvalue
);
3201 case DW_AT_encoding
:
3205 case DW_ATE_void
: printf ("(void)"); break;
3206 case DW_ATE_address
: printf ("(machine address)"); break;
3207 case DW_ATE_boolean
: printf ("(boolean)"); break;
3208 case DW_ATE_complex_float
: printf ("(complex float)"); break;
3209 case DW_ATE_float
: printf ("(float)"); break;
3210 case DW_ATE_signed
: printf ("(signed)"); break;
3211 case DW_ATE_signed_char
: printf ("(signed char)"); break;
3212 case DW_ATE_unsigned
: printf ("(unsigned)"); break;
3213 case DW_ATE_unsigned_char
: printf ("(unsigned char)"); break;
3214 /* DWARF 2.1 values: */
3215 case DW_ATE_imaginary_float
: printf ("(imaginary float)"); break;
3216 case DW_ATE_decimal_float
: printf ("(decimal float)"); break;
3217 /* DWARF 3 values: */
3218 case DW_ATE_packed_decimal
: printf ("(packed_decimal)"); break;
3219 case DW_ATE_numeric_string
: printf ("(numeric_string)"); break;
3220 case DW_ATE_edited
: printf ("(edited)"); break;
3221 case DW_ATE_signed_fixed
: printf ("(signed_fixed)"); break;
3222 case DW_ATE_unsigned_fixed
: printf ("(unsigned_fixed)"); break;
3223 /* DWARF 4 values: */
3224 case DW_ATE_UTF
: printf ("(unicode string)"); break;
3225 /* DWARF 5 values: */
3226 case DW_ATE_UCS
: printf ("(UCS)"); break;
3227 case DW_ATE_ASCII
: printf ("(ASCII)"); break;
3229 /* HP extensions: */
3230 case DW_ATE_HP_float80
: printf ("(HP_float80)"); break;
3231 case DW_ATE_HP_complex_float80
: printf ("(HP_complex_float80)"); break;
3232 case DW_ATE_HP_float128
: printf ("(HP_float128)"); break;
3233 case DW_ATE_HP_complex_float128
:printf ("(HP_complex_float128)"); break;
3234 case DW_ATE_HP_floathpintel
: printf ("(HP_floathpintel)"); break;
3235 case DW_ATE_HP_imaginary_float80
: printf ("(HP_imaginary_float80)"); break;
3236 case DW_ATE_HP_imaginary_float128
: printf ("(HP_imaginary_float128)"); break;
3239 if (uvalue
>= DW_ATE_lo_user
3240 && uvalue
<= DW_ATE_hi_user
)
3241 printf (_("(user defined type)"));
3243 printf (_("(unknown type)"));
3248 case DW_AT_accessibility
:
3252 case DW_ACCESS_public
: printf ("(public)"); break;
3253 case DW_ACCESS_protected
: printf ("(protected)"); break;
3254 case DW_ACCESS_private
: printf ("(private)"); break;
3256 printf (_("(unknown accessibility)"));
3261 case DW_AT_visibility
:
3265 case DW_VIS_local
: printf ("(local)"); break;
3266 case DW_VIS_exported
: printf ("(exported)"); break;
3267 case DW_VIS_qualified
: printf ("(qualified)"); break;
3268 default: printf (_("(unknown visibility)")); break;
3272 case DW_AT_endianity
:
3276 case DW_END_default
: printf ("(default)"); break;
3277 case DW_END_big
: printf ("(big)"); break;
3278 case DW_END_little
: printf ("(little)"); break;
3280 if (uvalue
>= DW_END_lo_user
&& uvalue
<= DW_END_hi_user
)
3281 printf (_("(user specified)"));
3283 printf (_("(unknown endianity)"));
3288 case DW_AT_virtuality
:
3292 case DW_VIRTUALITY_none
: printf ("(none)"); break;
3293 case DW_VIRTUALITY_virtual
: printf ("(virtual)"); break;
3294 case DW_VIRTUALITY_pure_virtual
:printf ("(pure_virtual)"); break;
3295 default: printf (_("(unknown virtuality)")); break;
3299 case DW_AT_identifier_case
:
3303 case DW_ID_case_sensitive
: printf ("(case_sensitive)"); break;
3304 case DW_ID_up_case
: printf ("(up_case)"); break;
3305 case DW_ID_down_case
: printf ("(down_case)"); break;
3306 case DW_ID_case_insensitive
: printf ("(case_insensitive)"); break;
3307 default: printf (_("(unknown case)")); break;
3311 case DW_AT_calling_convention
:
3315 case DW_CC_normal
: printf ("(normal)"); break;
3316 case DW_CC_program
: printf ("(program)"); break;
3317 case DW_CC_nocall
: printf ("(nocall)"); break;
3318 case DW_CC_pass_by_reference
: printf ("(pass by ref)"); break;
3319 case DW_CC_pass_by_value
: printf ("(pass by value)"); break;
3320 case DW_CC_GNU_renesas_sh
: printf ("(Rensas SH)"); break;
3321 case DW_CC_GNU_borland_fastcall_i386
: printf ("(Borland fastcall i386)"); break;
3323 if (uvalue
>= DW_CC_lo_user
3324 && uvalue
<= DW_CC_hi_user
)
3325 printf (_("(user defined)"));
3327 printf (_("(unknown convention)"));
3331 case DW_AT_ordering
:
3336 case -1: printf (_("(undefined)")); break;
3337 case 0: printf ("(row major)"); break;
3338 case 1: printf ("(column major)"); break;
3342 case DW_AT_decimal_sign
:
3346 case DW_DS_unsigned
: printf (_("(unsigned)")); break;
3347 case DW_DS_leading_overpunch
: printf (_("(leading overpunch)")); break;
3348 case DW_DS_trailing_overpunch
: printf (_("(trailing overpunch)")); break;
3349 case DW_DS_leading_separate
: printf (_("(leading separate)")); break;
3350 case DW_DS_trailing_separate
: printf (_("(trailing separate)")); break;
3351 default: printf (_("(unrecognised)")); break;
3355 case DW_AT_defaulted
:
3359 case DW_DEFAULTED_no
: printf (_("(no)")); break;
3360 case DW_DEFAULTED_in_class
: printf (_("(in class)")); break;
3361 case DW_DEFAULTED_out_of_class
: printf (_("(out of class)")); break;
3362 default: printf (_("(unrecognised)")); break;
3366 case DW_AT_discr_list
:
3368 display_discr_list (form
, uvalue
, data
, level
);
3371 case DW_AT_frame_base
:
3372 have_frame_base
= 1;
3374 case DW_AT_location
:
3375 case DW_AT_loclists_base
:
3376 case DW_AT_rnglists_base
:
3377 case DW_AT_str_offsets_base
:
3378 case DW_AT_string_length
:
3379 case DW_AT_return_addr
:
3380 case DW_AT_data_member_location
:
3381 case DW_AT_vtable_elem_location
:
3383 case DW_AT_static_link
:
3384 case DW_AT_use_location
:
3385 case DW_AT_call_value
:
3386 case DW_AT_GNU_call_site_value
:
3387 case DW_AT_call_data_value
:
3388 case DW_AT_GNU_call_site_data_value
:
3389 case DW_AT_call_target
:
3390 case DW_AT_GNU_call_site_target
:
3391 case DW_AT_call_target_clobbered
:
3392 case DW_AT_GNU_call_site_target_clobbered
:
3393 if ((dwarf_version
< 4
3394 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
3395 || form
== DW_FORM_sec_offset
3396 || form
== DW_FORM_loclistx
)
3398 if (attribute
!= DW_AT_rnglists_base
3399 && attribute
!= DW_AT_str_offsets_base
)
3400 printf (_(" (location list)"));
3403 case DW_AT_allocated
:
3404 case DW_AT_associated
:
3405 case DW_AT_data_location
:
3407 case DW_AT_upper_bound
:
3408 case DW_AT_lower_bound
:
3412 int need_frame_base
;
3415 need_frame_base
= decode_location_expression (block_start
,
3420 cu_offset
, section
);
3422 if (need_frame_base
&& !have_frame_base
)
3423 printf (_(" [without DW_AT_frame_base]"));
3427 case DW_AT_data_bit_offset
:
3428 case DW_AT_byte_size
:
3429 case DW_AT_bit_size
:
3430 case DW_AT_string_length_byte_size
:
3431 case DW_AT_string_length_bit_size
:
3432 case DW_AT_bit_stride
:
3433 if (form
== DW_FORM_exprloc
)
3436 (void) decode_location_expression (block_start
, pointer_size
,
3437 offset_size
, dwarf_version
,
3438 uvalue
, cu_offset
, section
);
3445 unsigned long abbrev_number
;
3446 abbrev_entry
*entry
;
3448 entry
= get_type_abbrev_from_form (form
, uvalue
, cu_offset
, end
,
3449 section
, & abbrev_number
, NULL
, NULL
);
3452 if (form
!= DW_FORM_GNU_ref_alt
)
3453 warn (_("Offset %#" PRIx64
" used as value for DW_AT_import attribute of DIE at offset %#tx is too big.\n"),
3455 orig_data
- section
->start
);
3459 printf (_("\t[Abbrev Number: %ld"), abbrev_number
);
3460 printf (" (%s)", get_TAG_name (entry
->tag
));
3473 static unsigned char *
3474 read_and_display_attr (unsigned long attribute
,
3476 int64_t implicit_const
,
3477 unsigned char *start
,
3478 unsigned char *data
,
3481 uint64_t pointer_size
,
3482 uint64_t offset_size
,
3484 debug_info
*debug_info_p
,
3486 struct dwarf_section
*section
,
3487 struct cu_tu_set
*this_set
,
3491 printf (" %-18s:", get_AT_name (attribute
));
3492 data
= read_and_display_attr_value (attribute
, form
, implicit_const
,
3494 cu_offset
, pointer_size
, offset_size
,
3495 dwarf_version
, debug_info_p
,
3496 do_loc
, section
, this_set
, ' ', level
);
3502 /* Like load_debug_section, but if the ordinary call fails, and we are
3503 following debug links, then attempt to load the requested section
3504 from one of the separate debug info files. */
3507 load_debug_section_with_follow (enum dwarf_section_display_enum sec_enum
,
3510 if (load_debug_section (sec_enum
, handle
))
3512 if (debug_displays
[sec_enum
].section
.filename
== NULL
)
3514 /* See if we can associate a filename with this section. */
3517 for (i
= first_separate_info
; i
!= NULL
; i
= i
->next
)
3518 if (i
->handle
== handle
)
3520 debug_displays
[sec_enum
].section
.filename
= i
->filename
;
3528 if (do_follow_links
)
3532 for (i
= first_separate_info
; i
!= NULL
; i
= i
->next
)
3534 if (load_debug_section (sec_enum
, i
->handle
))
3536 debug_displays
[sec_enum
].section
.filename
= i
->filename
;
3538 /* FIXME: We should check to see if any of the remaining debug info
3539 files also contain this section, and, umm, do something about it. */
3549 introduce (struct dwarf_section
* section
, bool raw
)
3553 if (do_follow_links
&& section
->filename
)
3554 printf (_("Raw dump of debug contents of section %s (loaded from %s):\n\n"),
3555 section
->name
, section
->filename
);
3557 printf (_("Raw dump of debug contents of section %s:\n\n"), section
->name
);
3561 if (do_follow_links
&& section
->filename
)
3562 printf (_("Contents of the %s section (loaded from %s):\n\n"),
3563 section
->name
, section
->filename
);
3565 printf (_("Contents of the %s section:\n\n"), section
->name
);
3569 /* Free memory allocated for one unit in debug_information. */
3572 free_debug_information (debug_info
*ent
)
3574 if (ent
->max_loc_offsets
)
3576 free (ent
->loc_offsets
);
3577 free (ent
->loc_views
);
3578 free (ent
->have_frame_base
);
3580 if (ent
->max_range_lists
)
3582 free (ent
->range_lists
);
3586 /* For look-ahead in attributes. When you want to scan a DIE for one specific
3587 attribute and ignore the rest. */
3589 static unsigned char *
3590 skip_attribute (unsigned long form
,
3591 unsigned char * data
,
3592 unsigned char * end
,
3593 uint64_t pointer_size
,
3594 uint64_t offset_size
,
3602 case DW_FORM_ref_addr
:
3603 inc
= dwarf_version
== 2 ? pointer_size
: offset_size
;
3608 case DW_FORM_strp_sup
:
3610 case DW_FORM_line_strp
:
3611 case DW_FORM_sec_offset
:
3612 case DW_FORM_GNU_ref_alt
:
3613 case DW_FORM_GNU_strp_alt
:
3620 case DW_FORM_addrx1
:
3626 case DW_FORM_addrx2
:
3630 case DW_FORM_addrx3
:
3633 case DW_FORM_ref_sup4
:
3637 case DW_FORM_addrx4
:
3640 case DW_FORM_ref_sup8
:
3643 case DW_FORM_ref_sig8
:
3646 case DW_FORM_data16
:
3650 SKIP_SLEB (data
, end
);
3652 case DW_FORM_GNU_str_index
:
3654 case DW_FORM_ref_udata
:
3656 case DW_FORM_GNU_addr_index
:
3658 case DW_FORM_loclistx
:
3659 case DW_FORM_rnglistx
:
3660 SKIP_ULEB (data
, end
);
3662 case DW_FORM_indirect
:
3663 while (form
== DW_FORM_indirect
)
3664 READ_ULEB (form
, data
, end
);
3665 return skip_attribute (form
, data
, end
, pointer_size
, offset_size
,
3668 case DW_FORM_string
:
3669 inc
= strnlen ((char *) data
, end
- data
);
3672 case DW_FORM_exprloc
:
3673 READ_ULEB (temp
, data
, end
);
3676 case DW_FORM_block1
:
3677 SAFE_BYTE_GET_AND_INC (temp
, data
, 1, end
);
3680 case DW_FORM_block2
:
3681 SAFE_BYTE_GET_AND_INC (temp
, data
, 2, end
);
3684 case DW_FORM_block4
:
3685 SAFE_BYTE_GET_AND_INC (temp
, data
, 4, end
);
3688 case DW_FORM_implicit_const
:
3689 case DW_FORM_flag_present
:
3692 warn (_("Unexpected form in top DIE\n"));
3695 if (inc
<= (size_t) (end
- data
))
3703 read_bases (abbrev_entry
* entry
,
3704 unsigned char * data
,
3705 unsigned char * end
,
3706 int64_t pointer_size
,
3707 uint64_t offset_size
,
3709 debug_info
* debug_info_p
)
3713 for (attr
= entry
->first_attr
;
3714 attr
&& attr
->attribute
;
3719 if (attr
->attribute
== DW_AT_rnglists_base
)
3721 if (attr
->form
== DW_FORM_sec_offset
)
3723 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
3724 debug_info_p
->rnglists_base
= uvalue
;
3727 warn (_("Unexpected form of DW_AT_rnglists_base in the top DIE\n"));
3729 else if (attr
->attribute
== DW_AT_addr_base
3730 || attr
->attribute
== DW_AT_GNU_addr_base
)
3732 if (attr
->form
== DW_FORM_sec_offset
)
3734 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
3735 debug_info_p
->addr_base
= uvalue
;
3738 warn (_("Unexpected form of DW_AT_addr_base in the top DIE\n"));
3741 data
= skip_attribute (attr
->form
, data
, end
, pointer_size
,
3742 offset_size
, dwarf_version
);
3746 /* Process the contents of a .debug_info section.
3747 If do_loc is TRUE then we are scanning for location lists and dwo tags
3748 and we do not want to display anything to the user.
3749 If do_types is TRUE, we are processing a .debug_types section instead of
3750 a .debug_info section.
3751 The information displayed is restricted by the values in DWARF_START_DIE
3752 and DWARF_CUTOFF_LEVEL.
3753 Returns TRUE upon success. Otherwise an error or warning message is
3754 printed and FALSE is returned. */
3757 process_debug_info (struct dwarf_section
* section
,
3759 enum dwarf_section_display_enum abbrev_sec
,
3763 unsigned char *start
= section
->start
;
3764 unsigned char *end
= start
+ section
->size
;
3765 unsigned char *section_begin
;
3767 unsigned int num_units
= 0;
3769 /* First scan the section to get the number of comp units.
3770 Length sanity checks are done here. */
3771 for (section_begin
= start
, num_units
= 0; section_begin
< end
;
3776 /* Read the first 4 bytes. For a 32-bit DWARF section, this
3777 will be the length. For a 64-bit DWARF section, it'll be
3778 the escape code 0xffffffff followed by an 8 byte length. */
3779 SAFE_BYTE_GET_AND_INC (length
, section_begin
, 4, end
);
3781 if (length
== 0xffffffff)
3782 SAFE_BYTE_GET_AND_INC (length
, section_begin
, 8, end
);
3783 else if (length
>= 0xfffffff0 && length
< 0xffffffff)
3785 warn (_("Reserved length value (%#" PRIx64
") found in section %s\n"),
3786 length
, section
->name
);
3790 /* Negative values are illegal, they may even cause infinite
3791 looping. This can happen if we can't accurately apply
3792 relocations to an object file, or if the file is corrupt. */
3793 if (length
> (size_t) (end
- section_begin
))
3795 warn (_("Corrupt unit length (got %#" PRIx64
3796 " expected at most %#tx) in section %s\n"),
3797 length
, end
- section_begin
, section
->name
);
3800 section_begin
+= length
;
3805 error (_("No comp units in %s section ?\n"), section
->name
);
3809 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
|| do_debug_info
)
3810 && num_debug_info_entries
== 0
3814 /* Then allocate an array to hold the information. */
3815 debug_information
= (debug_info
*) cmalloc (num_units
,
3816 sizeof (* debug_information
));
3817 if (debug_information
== NULL
)
3819 error (_("Not enough memory for a debug info array of %u entries\n"),
3821 alloc_num_debug_info_entries
= num_debug_info_entries
= 0;
3825 /* PR 17531: file: 92ca3797.
3826 We cannot rely upon the debug_information array being initialised
3827 before it is used. A corrupt file could easily contain references
3828 to a unit for which information has not been made available. So
3829 we ensure that the array is zeroed here. */
3830 memset (debug_information
, 0, num_units
* sizeof (*debug_information
));
3832 alloc_num_debug_info_entries
= num_units
;
3837 load_debug_section_with_follow (str
, file
);
3838 load_debug_section_with_follow (line_str
, file
);
3839 load_debug_section_with_follow (str_dwo
, file
);
3840 load_debug_section_with_follow (str_index
, file
);
3841 load_debug_section_with_follow (str_index_dwo
, file
);
3842 load_debug_section_with_follow (debug_addr
, file
);
3845 load_debug_section_with_follow (abbrev_sec
, file
);
3846 load_debug_section_with_follow (loclists
, file
);
3847 load_debug_section_with_follow (rnglists
, file
);
3848 load_debug_section_with_follow (loclists_dwo
, file
);
3849 load_debug_section_with_follow (rnglists_dwo
, file
);
3851 if (debug_displays
[abbrev_sec
].section
.start
== NULL
)
3853 warn (_("Unable to locate %s section!\n"),
3854 debug_displays
[abbrev_sec
].section
.uncompressed_name
);
3858 if (!do_loc
&& dwarf_start_die
== 0)
3859 introduce (section
, false);
3861 free_all_abbrevs ();
3863 /* In order to be able to resolve DW_FORM_ref_addr forms we need
3864 to load *all* of the abbrevs for all CUs in this .debug_info
3865 section. This does effectively mean that we (partially) read
3866 every CU header twice. */
3867 for (section_begin
= start
; start
< end
;)
3869 DWARF2_Internal_CompUnit compunit
;
3870 unsigned char *hdrptr
;
3871 uint64_t abbrev_base
;
3874 unsigned int offset_size
;
3875 struct cu_tu_set
*this_set
;
3876 unsigned char *end_cu
;
3879 cu_offset
= start
- section_begin
;
3881 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 4, end
);
3883 if (compunit
.cu_length
== 0xffffffff)
3885 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 8, end
);
3890 end_cu
= hdrptr
+ compunit
.cu_length
;
3892 SAFE_BYTE_GET_AND_INC (compunit
.cu_version
, hdrptr
, 2, end_cu
);
3894 this_set
= find_cu_tu_set_v2 (cu_offset
, do_types
);
3896 if (compunit
.cu_version
< 5)
3898 compunit
.cu_unit_type
= DW_UT_compile
;
3899 /* Initialize it due to a false compiler warning. */
3900 compunit
.cu_pointer_size
= -1;
3904 SAFE_BYTE_GET_AND_INC (compunit
.cu_unit_type
, hdrptr
, 1, end_cu
);
3905 do_types
= (compunit
.cu_unit_type
== DW_UT_type
);
3907 SAFE_BYTE_GET_AND_INC (compunit
.cu_pointer_size
, hdrptr
, 1, end_cu
);
3910 SAFE_BYTE_GET_AND_INC (compunit
.cu_abbrev_offset
, hdrptr
, offset_size
,
3913 if (compunit
.cu_unit_type
== DW_UT_split_compile
3914 || compunit
.cu_unit_type
== DW_UT_skeleton
)
3917 SAFE_BYTE_GET_AND_INC (dwo_id
, hdrptr
, 8, end_cu
);
3920 if (this_set
== NULL
)
3923 abbrev_size
= debug_displays
[abbrev_sec
].section
.size
;
3927 abbrev_base
= this_set
->section_offsets
[DW_SECT_ABBREV
];
3928 abbrev_size
= this_set
->section_sizes
[DW_SECT_ABBREV
];
3932 abbrev_list
*free_list
;
3933 list
= find_and_process_abbrev_set (&debug_displays
[abbrev_sec
].section
,
3934 abbrev_base
, abbrev_size
,
3935 compunit
.cu_abbrev_offset
,
3938 if (list
!= NULL
&& list
->first_abbrev
!= NULL
)
3939 record_abbrev_list_for_cu (cu_offset
, start
- section_begin
,
3941 else if (free_list
!= NULL
)
3942 free_abbrev_list (free_list
);
3945 for (start
= section_begin
, unit
= 0; start
< end
; unit
++)
3947 DWARF2_Internal_CompUnit compunit
;
3948 unsigned char *hdrptr
;
3949 unsigned char *tags
;
3950 int level
, last_level
, saved_level
;
3952 unsigned int offset_size
;
3953 uint64_t signature
= 0;
3954 uint64_t type_offset
= 0;
3955 struct cu_tu_set
*this_set
;
3956 uint64_t abbrev_base
;
3958 unsigned char *end_cu
;
3961 cu_offset
= start
- section_begin
;
3963 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 4, end
);
3965 if (compunit
.cu_length
== 0xffffffff)
3967 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 8, end
);
3972 end_cu
= hdrptr
+ compunit
.cu_length
;
3974 SAFE_BYTE_GET_AND_INC (compunit
.cu_version
, hdrptr
, 2, end_cu
);
3976 this_set
= find_cu_tu_set_v2 (cu_offset
, do_types
);
3978 if (compunit
.cu_version
< 5)
3980 compunit
.cu_unit_type
= DW_UT_compile
;
3981 /* Initialize it due to a false compiler warning. */
3982 compunit
.cu_pointer_size
= -1;
3986 SAFE_BYTE_GET_AND_INC (compunit
.cu_unit_type
, hdrptr
, 1, end_cu
);
3987 do_types
= (compunit
.cu_unit_type
== DW_UT_type
);
3989 SAFE_BYTE_GET_AND_INC (compunit
.cu_pointer_size
, hdrptr
, 1, end_cu
);
3992 SAFE_BYTE_GET_AND_INC (compunit
.cu_abbrev_offset
, hdrptr
, offset_size
, end_cu
);
3994 if (this_set
== NULL
)
3997 abbrev_size
= debug_displays
[abbrev_sec
].section
.size
;
4001 abbrev_base
= this_set
->section_offsets
[DW_SECT_ABBREV
];
4002 abbrev_size
= this_set
->section_sizes
[DW_SECT_ABBREV
];
4005 if (compunit
.cu_version
< 5)
4006 SAFE_BYTE_GET_AND_INC (compunit
.cu_pointer_size
, hdrptr
, 1, end_cu
);
4008 bool do_dwo_id
= false;
4009 uint64_t dwo_id
= 0;
4010 if (compunit
.cu_unit_type
== DW_UT_split_compile
4011 || compunit
.cu_unit_type
== DW_UT_skeleton
)
4013 SAFE_BYTE_GET_AND_INC (dwo_id
, hdrptr
, 8, end_cu
);
4017 /* PR 17512: file: 001-108546-0.001:0.1. */
4018 if (compunit
.cu_pointer_size
< 2 || compunit
.cu_pointer_size
> 8)
4020 warn (_("Invalid pointer size (%d) in compunit header, using %d instead\n"),
4021 compunit
.cu_pointer_size
, offset_size
);
4022 compunit
.cu_pointer_size
= offset_size
;
4027 SAFE_BYTE_GET_AND_INC (signature
, hdrptr
, 8, end_cu
);
4028 SAFE_BYTE_GET_AND_INC (type_offset
, hdrptr
, offset_size
, end_cu
);
4031 if (dwarf_start_die
>= (size_t) (end_cu
- section_begin
))
4037 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
|| do_debug_info
)
4038 && num_debug_info_entries
== 0
4039 && alloc_num_debug_info_entries
> unit
4042 free_debug_information (&debug_information
[unit
]);
4043 memset (&debug_information
[unit
], 0, sizeof (*debug_information
));
4044 debug_information
[unit
].pointer_size
= compunit
.cu_pointer_size
;
4045 debug_information
[unit
].offset_size
= offset_size
;
4046 debug_information
[unit
].dwarf_version
= compunit
.cu_version
;
4047 debug_information
[unit
].cu_offset
= cu_offset
;
4048 debug_information
[unit
].addr_base
= DEBUG_INFO_UNAVAILABLE
;
4049 debug_information
[unit
].ranges_base
= DEBUG_INFO_UNAVAILABLE
;
4052 if (!do_loc
&& dwarf_start_die
== 0)
4054 printf (_(" Compilation Unit @ offset %#" PRIx64
":\n"),
4056 printf (_(" Length: %#" PRIx64
" (%s)\n"),
4058 offset_size
== 8 ? "64-bit" : "32-bit");
4059 printf (_(" Version: %d\n"), compunit
.cu_version
);
4060 if (compunit
.cu_version
>= 5)
4062 const char *name
= get_DW_UT_name (compunit
.cu_unit_type
);
4064 printf (_(" Unit Type: %s (%x)\n"),
4066 compunit
.cu_unit_type
);
4068 printf (_(" Abbrev Offset: %#" PRIx64
"\n"),
4069 compunit
.cu_abbrev_offset
);
4070 printf (_(" Pointer Size: %d\n"), compunit
.cu_pointer_size
);
4073 printf (_(" Signature: %#" PRIx64
"\n"), signature
);
4074 printf (_(" Type Offset: %#" PRIx64
"\n"), type_offset
);
4077 printf (_(" DWO ID: %#" PRIx64
"\n"), dwo_id
);
4078 if (this_set
!= NULL
)
4080 uint64_t *offsets
= this_set
->section_offsets
;
4081 size_t *sizes
= this_set
->section_sizes
;
4083 printf (_(" Section contributions:\n"));
4084 printf (_(" .debug_abbrev.dwo: %#" PRIx64
" %#zx\n"),
4085 offsets
[DW_SECT_ABBREV
], sizes
[DW_SECT_ABBREV
]);
4086 printf (_(" .debug_line.dwo: %#" PRIx64
" %#zx\n"),
4087 offsets
[DW_SECT_LINE
], sizes
[DW_SECT_LINE
]);
4088 printf (_(" .debug_loc.dwo: %#" PRIx64
" %#zx\n"),
4089 offsets
[DW_SECT_LOC
], sizes
[DW_SECT_LOC
]);
4090 printf (_(" .debug_str_offsets.dwo: %#" PRIx64
" %#zx\n"),
4091 offsets
[DW_SECT_STR_OFFSETS
], sizes
[DW_SECT_STR_OFFSETS
]);
4098 if (compunit
.cu_version
< 2 || compunit
.cu_version
> 5)
4100 warn (_("CU at offset %#" PRIx64
" contains corrupt or "
4101 "unsupported version number: %d.\n"),
4102 cu_offset
, compunit
.cu_version
);
4106 if (compunit
.cu_unit_type
!= DW_UT_compile
4107 && compunit
.cu_unit_type
!= DW_UT_partial
4108 && compunit
.cu_unit_type
!= DW_UT_type
4109 && compunit
.cu_unit_type
!= DW_UT_split_compile
4110 && compunit
.cu_unit_type
!= DW_UT_skeleton
)
4112 warn (_("CU at offset %#" PRIx64
" contains corrupt or "
4113 "unsupported unit type: %d.\n"),
4114 cu_offset
, compunit
.cu_unit_type
);
4118 /* Process the abbrevs used by this compilation unit. */
4120 list
= find_and_process_abbrev_set (&debug_displays
[abbrev_sec
].section
,
4121 abbrev_base
, abbrev_size
,
4122 compunit
.cu_abbrev_offset
, NULL
);
4126 while (tags
< start
)
4128 unsigned long abbrev_number
;
4129 unsigned long die_offset
;
4130 abbrev_entry
*entry
;
4132 int do_printing
= 1;
4134 die_offset
= tags
- section_begin
;
4136 READ_ULEB (abbrev_number
, tags
, start
);
4138 /* A null DIE marks the end of a list of siblings or it may also be
4139 a section padding. */
4140 if (abbrev_number
== 0)
4142 /* Check if it can be a section padding for the last CU. */
4143 if (level
== 0 && start
== end
)
4147 for (chk
= tags
; chk
< start
; chk
++)
4154 if (!do_loc
&& die_offset
>= dwarf_start_die
4155 && (dwarf_cutoff_level
== -1
4156 || level
< dwarf_cutoff_level
))
4157 printf (_(" <%d><%lx>: Abbrev Number: 0\n"),
4163 static unsigned num_bogus_warns
= 0;
4165 if (num_bogus_warns
< 3)
4167 warn (_("Bogus end-of-siblings marker detected at offset %lx in %s section\n"),
4168 die_offset
, section
->name
);
4170 if (num_bogus_warns
== 3)
4171 warn (_("Further warnings about bogus end-of-sibling markers suppressed\n"));
4174 if (dwarf_start_die
!= 0 && level
< saved_level
)
4177 free_abbrev_list (list
);
4185 if (dwarf_start_die
!= 0 && die_offset
< dwarf_start_die
)
4189 if (dwarf_start_die
!= 0 && die_offset
== dwarf_start_die
)
4190 saved_level
= level
;
4191 do_printing
= (dwarf_cutoff_level
== -1
4192 || level
< dwarf_cutoff_level
);
4194 printf (_(" <%d><%lx>: Abbrev Number: %lu"),
4195 level
, die_offset
, abbrev_number
);
4196 else if (dwarf_cutoff_level
== -1
4197 || last_level
< dwarf_cutoff_level
)
4198 printf (_(" <%d><%lx>: ...\n"), level
, die_offset
);
4203 /* Scan through the abbreviation list until we reach the
4207 for (entry
= list
->first_abbrev
; entry
!= NULL
; entry
= entry
->next
)
4208 if (entry
->number
== abbrev_number
)
4213 if (!do_loc
&& do_printing
)
4218 warn (_("DIE at offset %#lx refers to abbreviation number %lu which does not exist\n"),
4219 die_offset
, abbrev_number
);
4221 free_abbrev_list (list
);
4225 if (!do_loc
&& do_printing
)
4226 printf (" (%s)\n", get_TAG_name (entry
->tag
));
4231 need_base_address
= 0;
4233 case DW_TAG_compile_unit
:
4234 case DW_TAG_skeleton_unit
:
4235 need_base_address
= 1;
4236 need_dwo_info
= do_loc
;
4238 case DW_TAG_entry_point
:
4239 need_base_address
= 0;
4240 /* Assuming that there is no DW_AT_frame_base. */
4241 have_frame_base
= 0;
4243 case DW_TAG_subprogram
:
4244 need_base_address
= 0;
4245 if (level
<= frame_base_level
)
4246 /* Don't reset that for nested subprogram. */
4247 have_frame_base
= 0;
4251 debug_info
*debug_info_p
=
4252 (debug_information
&& unit
< alloc_num_debug_info_entries
)
4253 ? debug_information
+ unit
: NULL
;
4255 assert (!debug_info_p
4256 || (debug_info_p
->num_loc_offsets
4257 == debug_info_p
->num_loc_views
));
4259 /* Look ahead so that the values of DW_AT_rnglists_base,
4260 DW_AT_[GNU_]addr_base are available before attributes that
4261 reference them are parsed in the same DIE.
4262 Only needed for the top DIE on DWARFv5+.
4263 No simiar treatment for loclists_base because there should
4264 be no loclist attributes in top DIE. */
4265 if (debug_info_p
&& compunit
.cu_version
>= 5 && level
== 0)
4272 compunit
.cu_pointer_size
,
4274 compunit
.cu_version
,
4277 /* This check was in place before, keep it. */
4278 stemp
= debug_info_p
->rnglists_base
;
4281 warn (_("CU @ %#" PRIx64
" has has a negative rnglists_base "
4282 "value of %#" PRIx64
" - treating as zero\n"),
4283 debug_info_p
->cu_offset
, stemp
);
4284 debug_info_p
->rnglists_base
= 0;
4288 for (attr
= entry
->first_attr
;
4289 attr
&& attr
->attribute
;
4292 if (! do_loc
&& do_printing
)
4293 /* Show the offset from where the tag was extracted. */
4294 printf (" <%tx>", tags
- section_begin
);
4295 tags
= read_and_display_attr (attr
->attribute
,
4297 attr
->implicit_const
,
4302 compunit
.cu_pointer_size
,
4304 compunit
.cu_version
,
4306 do_loc
|| ! do_printing
,
4312 /* If a locview attribute appears before a location one,
4313 make sure we don't associate it with an earlier
4316 switch (debug_info_p
->num_loc_offsets
- debug_info_p
->num_loc_views
)
4319 debug_info_p
->loc_views
[debug_info_p
->num_loc_views
] = -1;
4320 debug_info_p
->num_loc_views
++;
4321 assert (debug_info_p
->num_loc_views
4322 == debug_info_p
->num_loc_offsets
);
4329 warn (_("DIE has locviews without loclist\n"));
4330 debug_info_p
->num_loc_views
--;
4337 if (entry
->children
)
4341 free_abbrev_list (list
);
4344 /* Set num_debug_info_entries here so that it can be used to check if
4345 we need to process .debug_loc and .debug_ranges sections. */
4346 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
|| do_debug_info
)
4347 && num_debug_info_entries
== 0
4350 if (num_units
> alloc_num_debug_info_entries
)
4351 num_debug_info_entries
= alloc_num_debug_info_entries
;
4353 num_debug_info_entries
= num_units
;
4362 /* Locate and scan the .debug_info section in the file and record the pointer
4363 sizes and offsets for the compilation units in it. Usually an executable
4364 will have just one pointer size, but this is not guaranteed, and so we try
4365 not to make any assumptions. Returns zero upon failure, or the number of
4366 compilation units upon success. */
4369 load_debug_info (void * file
)
4371 /* If we have already tried and failed to load the .debug_info
4372 section then do not bother to repeat the task. */
4373 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
4376 /* If we already have the information there is nothing else to do. */
4377 if (num_debug_info_entries
> 0)
4378 return num_debug_info_entries
;
4380 /* If this is a DWARF package file, load the CU and TU indexes. */
4381 (void) load_cu_tu_indexes (file
);
4383 if (load_debug_section_with_follow (info
, file
)
4384 && process_debug_info (&debug_displays
[info
].section
, file
, abbrev
, true, false))
4385 return num_debug_info_entries
;
4387 if (load_debug_section_with_follow (info_dwo
, file
)
4388 && process_debug_info (&debug_displays
[info_dwo
].section
, file
,
4389 abbrev_dwo
, true, false))
4390 return num_debug_info_entries
;
4392 num_debug_info_entries
= DEBUG_INFO_UNAVAILABLE
;
4396 /* Read a DWARF .debug_line section header starting at DATA.
4397 Upon success returns an updated DATA pointer and the LINFO
4398 structure and the END_OF_SEQUENCE pointer will be filled in.
4399 Otherwise returns NULL. */
4401 static unsigned char *
4402 read_debug_line_header (struct dwarf_section
* section
,
4403 unsigned char * data
,
4404 unsigned char * end
,
4405 DWARF2_Internal_LineInfo
* linfo
,
4406 unsigned char ** end_of_sequence
)
4408 unsigned char *hdrptr
;
4410 /* Extract information from the Line Number Program Header.
4411 (section 6.2.4 in the Dwarf3 doc). */
4414 /* Get and check the length of the block. */
4415 SAFE_BYTE_GET_AND_INC (linfo
->li_length
, hdrptr
, 4, end
);
4417 if (linfo
->li_length
== 0xffffffff)
4419 /* This section is 64-bit DWARF 3. */
4420 SAFE_BYTE_GET_AND_INC (linfo
->li_length
, hdrptr
, 8, end
);
4421 linfo
->li_offset_size
= 8;
4424 linfo
->li_offset_size
= 4;
4426 if (linfo
->li_length
> (size_t) (end
- hdrptr
))
4428 /* If the length field has a relocation against it, then we should
4429 not complain if it is inaccurate (and probably negative). This
4430 happens in object files when the .debug_line section is actually
4431 comprised of several different .debug_line.* sections, (some of
4432 which may be removed by linker garbage collection), and a relocation
4433 is used to compute the correct length once that is done. */
4434 if (reloc_at (section
, (hdrptr
- section
->start
) - linfo
->li_offset_size
))
4436 linfo
->li_length
= end
- hdrptr
;
4440 warn (_("The length field (%#" PRIx64
")"
4441 " in the debug_line header is wrong"
4442 " - the section is too small\n"),
4447 end
= hdrptr
+ linfo
->li_length
;
4449 /* Get and check the version number. */
4450 SAFE_BYTE_GET_AND_INC (linfo
->li_version
, hdrptr
, 2, end
);
4452 if (linfo
->li_version
!= 2
4453 && linfo
->li_version
!= 3
4454 && linfo
->li_version
!= 4
4455 && linfo
->li_version
!= 5)
4457 warn (_("Only DWARF version 2, 3, 4 and 5 line info "
4458 "is currently supported.\n"));
4462 if (linfo
->li_version
>= 5)
4464 SAFE_BYTE_GET_AND_INC (linfo
->li_address_size
, hdrptr
, 1, end
);
4466 SAFE_BYTE_GET_AND_INC (linfo
->li_segment_size
, hdrptr
, 1, end
);
4467 if (linfo
->li_segment_size
!= 0)
4469 warn (_("The %s section contains "
4470 "unsupported segment selector size: %d.\n"),
4471 section
->name
, linfo
->li_segment_size
);
4476 SAFE_BYTE_GET_AND_INC (linfo
->li_prologue_length
, hdrptr
,
4477 linfo
->li_offset_size
, end
);
4478 SAFE_BYTE_GET_AND_INC (linfo
->li_min_insn_length
, hdrptr
, 1, end
);
4480 if (linfo
->li_version
>= 4)
4482 SAFE_BYTE_GET_AND_INC (linfo
->li_max_ops_per_insn
, hdrptr
, 1, end
);
4484 if (linfo
->li_max_ops_per_insn
== 0)
4486 warn (_("Invalid maximum operations per insn.\n"));
4491 linfo
->li_max_ops_per_insn
= 1;
4493 SAFE_BYTE_GET_AND_INC (linfo
->li_default_is_stmt
, hdrptr
, 1, end
);
4494 SAFE_SIGNED_BYTE_GET_AND_INC (linfo
->li_line_base
, hdrptr
, 1, end
);
4495 SAFE_BYTE_GET_AND_INC (linfo
->li_line_range
, hdrptr
, 1, end
);
4496 SAFE_BYTE_GET_AND_INC (linfo
->li_opcode_base
, hdrptr
, 1, end
);
4498 *end_of_sequence
= end
;
4502 static unsigned char *
4503 display_formatted_table (unsigned char *data
,
4504 unsigned char *start
,
4506 const DWARF2_Internal_LineInfo
*linfo
,
4507 struct dwarf_section
*section
,
4510 unsigned char *format_start
, format_count
, *format
, formati
;
4511 uint64_t data_count
, datai
;
4512 unsigned int namepass
, last_entry
= 0;
4513 const char * table_name
= is_dir
? N_("Directory Table") : N_("File Name Table");
4515 SAFE_BYTE_GET_AND_INC (format_count
, data
, 1, end
);
4516 if (do_checks
&& format_count
> 5)
4517 warn (_("Unexpectedly large number of columns in the %s (%u)\n"),
4518 table_name
, format_count
);
4520 format_start
= data
;
4521 for (formati
= 0; formati
< format_count
; formati
++)
4523 SKIP_ULEB (data
, end
);
4524 SKIP_ULEB (data
, end
);
4527 warn (_("%s: Corrupt format description entry\n"), table_name
);
4532 READ_ULEB (data_count
, data
, end
);
4533 if (data_count
== 0)
4535 printf (_("\n The %s is empty.\n"), table_name
);
4538 else if (data
>= end
4539 || data_count
> (size_t) (end
- data
))
4541 warn (_("%s: Corrupt entry count %#" PRIx64
"\n"), table_name
, data_count
);
4545 else if (format_count
== 0)
4547 warn (_("%s: format count is zero, but the table is not empty\n"),
4552 printf (_("\n The %s (offset %#tx, lines %" PRIu64
", columns %u):\n"),
4553 table_name
, data
- start
, data_count
, format_count
);
4555 printf (_(" Entry"));
4556 /* Delay displaying name as the last entry for better screen layout. */
4557 for (namepass
= 0; namepass
< 2; namepass
++)
4559 format
= format_start
;
4560 for (formati
= 0; formati
< format_count
; formati
++)
4562 uint64_t content_type
;
4564 READ_ULEB (content_type
, format
, end
);
4565 if ((content_type
== DW_LNCT_path
) == (namepass
== 1))
4566 switch (content_type
)
4569 printf (_("\tName"));
4571 case DW_LNCT_directory_index
:
4572 printf (_("\tDir"));
4574 case DW_LNCT_timestamp
:
4575 printf (_("\tTime"));
4578 printf (_("\tSize"));
4581 printf (_("\tMD5\t\t\t"));
4584 printf (_("\t(Unknown format content type %" PRIu64
")"),
4587 SKIP_ULEB (format
, end
);
4592 for (datai
= 0; datai
< data_count
; datai
++)
4594 unsigned char *datapass
= data
;
4596 printf (" %d", last_entry
++);
4597 /* Delay displaying name as the last entry for better screen layout. */
4598 for (namepass
= 0; namepass
< 2; namepass
++)
4600 format
= format_start
;
4602 for (formati
= 0; formati
< format_count
; formati
++)
4604 uint64_t content_type
, form
;
4606 READ_ULEB (content_type
, format
, end
);
4607 READ_ULEB (form
, format
, end
);
4608 data
= read_and_display_attr_value (0, form
, 0, start
, data
, end
,
4609 0, 0, linfo
->li_offset_size
,
4610 linfo
->li_version
, NULL
,
4611 ((content_type
== DW_LNCT_path
) != (namepass
== 1)),
4612 section
, NULL
, '\t', -1);
4616 if (data
>= end
&& (datai
< data_count
- 1))
4618 warn (_("\n%s: Corrupt entries list\n"), table_name
);
4627 display_debug_sup (struct dwarf_section
* section
,
4628 void * file ATTRIBUTE_UNUSED
)
4630 unsigned char * start
= section
->start
;
4631 unsigned char * end
= section
->start
+ section
->size
;
4632 unsigned int version
;
4633 char is_supplementary
;
4634 const unsigned char * sup_filename
;
4635 size_t sup_filename_len
;
4636 unsigned int num_read
;
4638 uint64_t checksum_len
;
4641 introduce (section
, true);
4642 if (section
->size
< 4)
4644 error (_("corrupt .debug_sup section: size is too small\n"));
4648 /* Read the data. */
4649 SAFE_BYTE_GET_AND_INC (version
, start
, 2, end
);
4651 warn (_("corrupt .debug_sup section: version < 5\n"));
4653 SAFE_BYTE_GET_AND_INC (is_supplementary
, start
, 1, end
);
4654 if (is_supplementary
!= 0 && is_supplementary
!= 1)
4655 warn (_("corrupt .debug_sup section: is_supplementary not 0 or 1\n"));
4657 sup_filename
= start
;
4658 if (is_supplementary
&& sup_filename
[0] != 0)
4659 warn (_("corrupt .debug_sup section: filename not empty in supplementary section\n"));
4661 sup_filename_len
= strnlen ((const char *) start
, end
- start
);
4662 if (sup_filename_len
== (size_t) (end
- start
))
4664 error (_("corrupt .debug_sup section: filename is not NUL terminated\n"));
4667 start
+= sup_filename_len
+ 1;
4669 checksum_len
= read_leb128 (start
, end
, false /* unsigned */, & num_read
, & status
);
4672 error (_("corrupt .debug_sup section: bad LEB128 field for checksum length\n"));
4676 if (checksum_len
> (size_t) (end
- start
))
4678 error (_("corrupt .debug_sup section: checksum length is longer than the remaining section length\n"));
4679 checksum_len
= end
- start
;
4681 else if (checksum_len
< (size_t) (end
- start
))
4683 warn (_("corrupt .debug_sup section: there are %#" PRIx64
4684 " extra, unused bytes at the end of the section\n"),
4685 (end
- start
) - checksum_len
);
4688 printf (_(" Version: %u\n"), version
);
4689 printf (_(" Is Supp: %u\n"), is_supplementary
);
4690 printf (_(" Filename: %s\n"), sup_filename
);
4691 printf (_(" Checksum Len: %" PRIu64
"\n"), checksum_len
);
4692 if (checksum_len
> 0)
4694 printf (_(" Checksum: "));
4695 while (checksum_len
--)
4696 printf ("0x%x ", * start
++ );
4703 display_debug_lines_raw (struct dwarf_section
* section
,
4704 unsigned char * data
,
4705 unsigned char * end
,
4708 unsigned char *start
= section
->start
;
4709 int verbose_view
= 0;
4711 introduce (section
, true);
4715 static DWARF2_Internal_LineInfo saved_linfo
;
4716 DWARF2_Internal_LineInfo linfo
;
4717 unsigned char *standard_opcodes
;
4718 unsigned char *end_of_sequence
;
4721 if (startswith (section
->name
, ".debug_line.")
4722 /* Note: the following does not apply to .debug_line.dwo sections.
4723 These are full debug_line sections. */
4724 && strcmp (section
->name
, ".debug_line.dwo") != 0)
4726 /* Sections named .debug_line.<foo> are fragments of a .debug_line
4727 section containing just the Line Number Statements. They are
4728 created by the assembler and intended to be used alongside gcc's
4729 -ffunction-sections command line option. When the linker's
4730 garbage collection decides to discard a .text.<foo> section it
4731 can then also discard the line number information in .debug_line.<foo>.
4733 Since the section is a fragment it does not have the details
4734 needed to fill out a LineInfo structure, so instead we use the
4735 details from the last full debug_line section that we processed. */
4736 end_of_sequence
= end
;
4737 standard_opcodes
= NULL
;
4738 linfo
= saved_linfo
;
4739 /* PR 17531: file: 0522b371. */
4740 if (linfo
.li_line_range
== 0)
4742 warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n"));
4745 reset_state_machine (linfo
.li_default_is_stmt
);
4749 unsigned char * hdrptr
;
4751 if ((hdrptr
= read_debug_line_header (section
, data
, end
, & linfo
,
4752 & end_of_sequence
)) == NULL
)
4755 printf (_(" Offset: %#tx\n"), data
- start
);
4756 printf (_(" Length: %" PRId64
"\n"), linfo
.li_length
);
4757 printf (_(" DWARF Version: %d\n"), linfo
.li_version
);
4758 if (linfo
.li_version
>= 5)
4760 printf (_(" Address size (bytes): %d\n"), linfo
.li_address_size
);
4761 printf (_(" Segment selector (bytes): %d\n"), linfo
.li_segment_size
);
4763 printf (_(" Prologue Length: %d\n"), (int) linfo
.li_prologue_length
);
4764 printf (_(" Minimum Instruction Length: %d\n"), linfo
.li_min_insn_length
);
4765 if (linfo
.li_version
>= 4)
4766 printf (_(" Maximum Ops per Instruction: %d\n"), linfo
.li_max_ops_per_insn
);
4767 printf (_(" Initial value of 'is_stmt': %d\n"), linfo
.li_default_is_stmt
);
4768 printf (_(" Line Base: %d\n"), linfo
.li_line_base
);
4769 printf (_(" Line Range: %d\n"), linfo
.li_line_range
);
4770 printf (_(" Opcode Base: %d\n"), linfo
.li_opcode_base
);
4772 /* PR 17512: file: 1665-6428-0.004. */
4773 if (linfo
.li_line_range
== 0)
4775 warn (_("Line range of 0 is invalid, using 1 instead\n"));
4776 linfo
.li_line_range
= 1;
4779 reset_state_machine (linfo
.li_default_is_stmt
);
4781 /* Display the contents of the Opcodes table. */
4782 standard_opcodes
= hdrptr
;
4784 /* PR 17512: file: 002-417945-0.004. */
4785 if (standard_opcodes
+ linfo
.li_opcode_base
>= end
)
4787 warn (_("Line Base extends beyond end of section\n"));
4791 printf (_("\n Opcodes:\n"));
4793 for (i
= 1; i
< linfo
.li_opcode_base
; i
++)
4794 printf (ngettext (" Opcode %d has %d arg\n",
4795 " Opcode %d has %d args\n",
4796 standard_opcodes
[i
- 1]),
4797 i
, standard_opcodes
[i
- 1]);
4799 /* Display the contents of the Directory table. */
4800 data
= standard_opcodes
+ linfo
.li_opcode_base
- 1;
4802 if (linfo
.li_version
>= 5)
4804 load_debug_section_with_follow (line_str
, file
);
4806 data
= display_formatted_table (data
, start
, end
, &linfo
, section
,
4808 data
= display_formatted_table (data
, start
, end
, &linfo
, section
,
4814 printf (_("\n The Directory Table is empty.\n"));
4817 unsigned int last_dir_entry
= 0;
4819 printf (_("\n The Directory Table (offset %#tx):\n"),
4822 while (data
< end
&& *data
!= 0)
4824 printf (" %d\t%.*s\n", ++last_dir_entry
, (int) (end
- data
), data
);
4826 data
+= strnlen ((char *) data
, end
- data
);
4831 /* PR 17512: file: 002-132094-0.004. */
4832 if (data
>= end
- 1)
4836 /* Skip the NUL at the end of the table. */
4840 /* Display the contents of the File Name table. */
4841 if (data
>= end
|| *data
== 0)
4842 printf (_("\n The File Name Table is empty.\n"));
4845 printf (_("\n The File Name Table (offset %#tx):\n"),
4847 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
4849 while (data
< end
&& *data
!= 0)
4851 unsigned char *name
;
4854 printf (" %d\t", ++state_machine_regs
.last_file_entry
);
4856 data
+= strnlen ((char *) data
, end
- data
);
4860 READ_ULEB (val
, data
, end
);
4861 printf ("%" PRIu64
"\t", val
);
4862 READ_ULEB (val
, data
, end
);
4863 printf ("%" PRIu64
"\t", val
);
4864 READ_ULEB (val
, data
, end
);
4865 printf ("%" PRIu64
"\t", val
);
4866 printf ("%.*s\n", (int)(end
- name
), name
);
4870 warn (_("Corrupt file name table entry\n"));
4876 /* Skip the NUL at the end of the table. */
4882 saved_linfo
= linfo
;
4885 /* Now display the statements. */
4886 if (data
>= end_of_sequence
)
4887 printf (_(" No Line Number Statements.\n"));
4890 printf (_(" Line Number Statements:\n"));
4892 while (data
< end_of_sequence
)
4894 unsigned char op_code
;
4898 printf (" [0x%08tx]", data
- start
);
4902 if (op_code
>= linfo
.li_opcode_base
)
4904 op_code
-= linfo
.li_opcode_base
;
4905 uladv
= (op_code
/ linfo
.li_line_range
);
4906 if (linfo
.li_max_ops_per_insn
== 1)
4908 uladv
*= linfo
.li_min_insn_length
;
4909 state_machine_regs
.address
+= uladv
;
4911 state_machine_regs
.view
= 0;
4912 printf (_(" Special opcode %d: "
4913 "advance Address by %" PRIu64
4914 " to %#" PRIx64
"%s"),
4915 op_code
, uladv
, state_machine_regs
.address
,
4916 verbose_view
&& uladv
4917 ? _(" (reset view)") : "");
4922 = ((state_machine_regs
.op_index
+ uladv
)
4923 / linfo
.li_max_ops_per_insn
)
4924 * linfo
.li_min_insn_length
;
4926 state_machine_regs
.address
+= addrdelta
;
4927 state_machine_regs
.op_index
4928 = (state_machine_regs
.op_index
+ uladv
)
4929 % linfo
.li_max_ops_per_insn
;
4931 state_machine_regs
.view
= 0;
4932 printf (_(" Special opcode %d: "
4933 "advance Address by %" PRIu64
4934 " to %#" PRIx64
"[%d]%s"),
4935 op_code
, uladv
, state_machine_regs
.address
,
4936 state_machine_regs
.op_index
,
4937 verbose_view
&& addrdelta
4938 ? _(" (reset view)") : "");
4940 adv
= (op_code
% linfo
.li_line_range
) + linfo
.li_line_base
;
4941 state_machine_regs
.line
+= adv
;
4942 printf (_(" and Line by %d to %d"),
4943 adv
, state_machine_regs
.line
);
4944 if (verbose_view
|| state_machine_regs
.view
)
4945 printf (_(" (view %u)\n"), state_machine_regs
.view
);
4948 state_machine_regs
.view
++;
4953 case DW_LNS_extended_op
:
4954 data
+= process_extended_line_op (data
,
4955 linfo
.li_default_is_stmt
,
4960 printf (_(" Copy"));
4961 if (verbose_view
|| state_machine_regs
.view
)
4962 printf (_(" (view %u)\n"), state_machine_regs
.view
);
4965 state_machine_regs
.view
++;
4968 case DW_LNS_advance_pc
:
4969 READ_ULEB (uladv
, data
, end
);
4970 if (linfo
.li_max_ops_per_insn
== 1)
4972 uladv
*= linfo
.li_min_insn_length
;
4973 state_machine_regs
.address
+= uladv
;
4975 state_machine_regs
.view
= 0;
4976 printf (_(" Advance PC by %" PRIu64
4977 " to %#" PRIx64
"%s\n"),
4978 uladv
, state_machine_regs
.address
,
4979 verbose_view
&& uladv
4980 ? _(" (reset view)") : "");
4985 = ((state_machine_regs
.op_index
+ uladv
)
4986 / linfo
.li_max_ops_per_insn
)
4987 * linfo
.li_min_insn_length
;
4988 state_machine_regs
.address
4990 state_machine_regs
.op_index
4991 = (state_machine_regs
.op_index
+ uladv
)
4992 % linfo
.li_max_ops_per_insn
;
4994 state_machine_regs
.view
= 0;
4995 printf (_(" Advance PC by %" PRIu64
4996 " to %#" PRIx64
"[%d]%s\n"),
4997 uladv
, state_machine_regs
.address
,
4998 state_machine_regs
.op_index
,
4999 verbose_view
&& addrdelta
5000 ? _(" (reset view)") : "");
5004 case DW_LNS_advance_line
:
5005 READ_SLEB (adv
, data
, end
);
5006 state_machine_regs
.line
+= adv
;
5007 printf (_(" Advance Line by %d to %d\n"),
5008 adv
, state_machine_regs
.line
);
5011 case DW_LNS_set_file
:
5012 READ_ULEB (uladv
, data
, end
);
5013 printf (_(" Set File Name to entry %" PRIu64
5014 " in the File Name Table\n"), uladv
);
5015 state_machine_regs
.file
= uladv
;
5018 case DW_LNS_set_column
:
5019 READ_ULEB (uladv
, data
, end
);
5020 printf (_(" Set column to %" PRIu64
"\n"), uladv
);
5021 state_machine_regs
.column
= uladv
;
5024 case DW_LNS_negate_stmt
:
5025 adv
= state_machine_regs
.is_stmt
;
5027 printf (_(" Set is_stmt to %d\n"), adv
);
5028 state_machine_regs
.is_stmt
= adv
;
5031 case DW_LNS_set_basic_block
:
5032 printf (_(" Set basic block\n"));
5033 state_machine_regs
.basic_block
= 1;
5036 case DW_LNS_const_add_pc
:
5037 uladv
= ((255 - linfo
.li_opcode_base
) / linfo
.li_line_range
);
5038 if (linfo
.li_max_ops_per_insn
)
5040 uladv
*= linfo
.li_min_insn_length
;
5041 state_machine_regs
.address
+= uladv
;
5043 state_machine_regs
.view
= 0;
5044 printf (_(" Advance PC by constant %" PRIu64
5045 " to %#" PRIx64
"%s\n"),
5046 uladv
, state_machine_regs
.address
,
5047 verbose_view
&& uladv
5048 ? _(" (reset view)") : "");
5053 = ((state_machine_regs
.op_index
+ uladv
)
5054 / linfo
.li_max_ops_per_insn
)
5055 * linfo
.li_min_insn_length
;
5056 state_machine_regs
.address
5058 state_machine_regs
.op_index
5059 = (state_machine_regs
.op_index
+ uladv
)
5060 % linfo
.li_max_ops_per_insn
;
5062 state_machine_regs
.view
= 0;
5063 printf (_(" Advance PC by constant %" PRIu64
5064 " to %#" PRIx64
"[%d]%s\n"),
5065 uladv
, state_machine_regs
.address
,
5066 state_machine_regs
.op_index
,
5067 verbose_view
&& addrdelta
5068 ? _(" (reset view)") : "");
5072 case DW_LNS_fixed_advance_pc
:
5073 SAFE_BYTE_GET_AND_INC (uladv
, data
, 2, end
);
5074 state_machine_regs
.address
+= uladv
;
5075 state_machine_regs
.op_index
= 0;
5076 printf (_(" Advance PC by fixed size amount %" PRIu64
5077 " to %#" PRIx64
"\n"),
5078 uladv
, state_machine_regs
.address
);
5079 /* Do NOT reset view. */
5082 case DW_LNS_set_prologue_end
:
5083 printf (_(" Set prologue_end to true\n"));
5086 case DW_LNS_set_epilogue_begin
:
5087 printf (_(" Set epilogue_begin to true\n"));
5090 case DW_LNS_set_isa
:
5091 READ_ULEB (uladv
, data
, end
);
5092 printf (_(" Set ISA to %" PRIu64
"\n"), uladv
);
5096 printf (_(" Unknown opcode %d with operands: "), op_code
);
5098 if (standard_opcodes
!= NULL
)
5099 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
5101 READ_ULEB (uladv
, data
, end
);
5102 printf ("%#" PRIx64
"%s", uladv
, i
== 1 ? "" : ", ");
5118 unsigned int directory_index
;
5119 unsigned int modification_date
;
5120 unsigned int length
;
5123 /* Output a decoded representation of the .debug_line section. */
5126 display_debug_lines_decoded (struct dwarf_section
* section
,
5127 unsigned char * start
,
5128 unsigned char * data
,
5129 unsigned char * end
,
5132 static DWARF2_Internal_LineInfo saved_linfo
;
5134 introduce (section
, false);
5138 /* This loop amounts to one iteration per compilation unit. */
5139 DWARF2_Internal_LineInfo linfo
;
5140 unsigned char *standard_opcodes
;
5141 unsigned char *end_of_sequence
;
5143 File_Entry
*file_table
= NULL
;
5144 unsigned int n_files
= 0;
5145 char **directory_table
= NULL
;
5146 unsigned int n_directories
= 0;
5148 if (startswith (section
->name
, ".debug_line.")
5149 /* Note: the following does not apply to .debug_line.dwo sections.
5150 These are full debug_line sections. */
5151 && strcmp (section
->name
, ".debug_line.dwo") != 0)
5153 /* See comment in display_debug_lines_raw(). */
5154 end_of_sequence
= end
;
5155 standard_opcodes
= NULL
;
5156 linfo
= saved_linfo
;
5157 /* PR 17531: file: 0522b371. */
5158 if (linfo
.li_line_range
== 0)
5160 warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n"));
5163 reset_state_machine (linfo
.li_default_is_stmt
);
5167 unsigned char *hdrptr
;
5169 if ((hdrptr
= read_debug_line_header (section
, data
, end
, & linfo
,
5170 & end_of_sequence
)) == NULL
)
5173 /* PR 17531: file: 0522b371. */
5174 if (linfo
.li_line_range
== 0)
5176 warn (_("Line range of 0 is invalid, using 1 instead\n"));
5177 linfo
.li_line_range
= 1;
5179 reset_state_machine (linfo
.li_default_is_stmt
);
5181 /* Save a pointer to the contents of the Opcodes table. */
5182 standard_opcodes
= hdrptr
;
5184 /* Traverse the Directory table just to count entries. */
5185 data
= standard_opcodes
+ linfo
.li_opcode_base
- 1;
5189 warn (_("opcode base of %d extends beyond end of section\n"),
5190 linfo
.li_opcode_base
);
5194 if (linfo
.li_version
>= 5)
5196 unsigned char *format_start
, *format
;
5197 unsigned int format_count
, formati
, entryi
;
5199 load_debug_section_with_follow (line_str
, fileptr
);
5201 /* Skip directories format. */
5202 SAFE_BYTE_GET_AND_INC (format_count
, data
, 1, end
);
5203 if (do_checks
&& format_count
> 1)
5204 warn (_("Unexpectedly large number of columns in the directory name table (%u)\n"),
5206 format_start
= data
;
5207 for (formati
= 0; formati
< format_count
; formati
++)
5209 SKIP_ULEB (data
, end
);
5210 SKIP_ULEB (data
, end
);
5213 READ_ULEB (n_directories
, data
, end
);
5216 warn (_("Corrupt directories list\n"));
5220 if (n_directories
== 0)
5221 directory_table
= NULL
;
5222 else if (n_directories
> section
->size
)
5224 warn (_("number of directories (0x%x) exceeds size of section %s\n"),
5225 n_directories
, section
->name
);
5229 directory_table
= (char **)
5230 xcalloc (n_directories
, sizeof (unsigned char *));
5232 for (entryi
= 0; entryi
< n_directories
; entryi
++)
5234 char **pathp
= &directory_table
[entryi
];
5236 format
= format_start
;
5237 for (formati
= 0; formati
< format_count
; formati
++)
5239 uint64_t content_type
, form
;
5242 READ_ULEB (content_type
, format
, end
);
5243 READ_ULEB (form
, format
, end
);
5246 warn (_("Corrupt directories list\n"));
5249 switch (content_type
)
5254 case DW_FORM_string
:
5255 *pathp
= (char *) data
;
5257 case DW_FORM_line_strp
:
5258 SAFE_BYTE_GET (uvalue
, data
, linfo
.li_offset_size
,
5260 /* Remove const by the cast. */
5262 fetch_indirect_line_string (uvalue
);
5267 data
= read_and_display_attr_value (0, form
, 0, start
,
5269 linfo
.li_offset_size
,
5276 warn (_("Corrupt directories list\n"));
5281 /* Skip files format. */
5282 SAFE_BYTE_GET_AND_INC (format_count
, data
, 1, end
);
5283 if (do_checks
&& format_count
> 5)
5284 warn (_("Unexpectedly large number of columns in the file name table (%u)\n"),
5287 format_start
= data
;
5288 for (formati
= 0; formati
< format_count
; formati
++)
5290 SKIP_ULEB (data
, end
);
5291 SKIP_ULEB (data
, end
);
5294 READ_ULEB (n_files
, data
, end
);
5295 if (data
>= end
&& n_files
> 0)
5297 warn (_("Corrupt file name list\n"));
5303 else if (n_files
> section
->size
)
5305 warn (_("number of files (0x%x) exceeds size of section %s\n"),
5306 n_files
, section
->name
);
5310 file_table
= (File_Entry
*) xcalloc (n_files
,
5311 sizeof (File_Entry
));
5313 for (entryi
= 0; entryi
< n_files
; entryi
++)
5315 File_Entry
*file
= &file_table
[entryi
];
5317 format
= format_start
;
5318 for (formati
= 0; formati
< format_count
; formati
++)
5320 uint64_t content_type
, form
;
5324 READ_ULEB (content_type
, format
, end
);
5325 READ_ULEB (form
, format
, end
);
5328 warn (_("Corrupt file name list\n"));
5331 switch (content_type
)
5336 case DW_FORM_string
:
5337 file
->name
= (char *) data
;
5339 case DW_FORM_line_strp
:
5340 SAFE_BYTE_GET (uvalue
, data
, linfo
.li_offset_size
,
5342 /* Remove const by the cast. */
5343 file
->name
= (char *)
5344 fetch_indirect_line_string (uvalue
);
5348 case DW_LNCT_directory_index
:
5352 SAFE_BYTE_GET (file
->directory_index
, data
, 1,
5356 SAFE_BYTE_GET (file
->directory_index
, data
, 2,
5361 READ_ULEB (file
->directory_index
, tmp
, end
);
5366 data
= read_and_display_attr_value (0, form
, 0, start
,
5368 linfo
.li_offset_size
,
5375 warn (_("Corrupt file name list\n"));
5384 char *ptr_directory_table
= (char *) data
;
5386 while (data
< end
&& *data
!= 0)
5388 data
+= strnlen ((char *) data
, end
- data
);
5397 warn (_("directory table ends unexpectedly\n"));
5402 /* Go through the directory table again to save the directories. */
5403 directory_table
= (char **)
5404 xmalloc (n_directories
* sizeof (unsigned char *));
5407 while (*ptr_directory_table
!= 0)
5409 directory_table
[i
] = ptr_directory_table
;
5410 ptr_directory_table
+= strlen (ptr_directory_table
) + 1;
5414 /* Skip the NUL at the end of the table. */
5417 /* Traverse the File Name table just to count the entries. */
5418 if (data
< end
&& *data
!= 0)
5420 unsigned char *ptr_file_name_table
= data
;
5422 while (data
< end
&& *data
!= 0)
5424 /* Skip Name, directory index, last modification
5425 time and length of file. */
5426 data
+= strnlen ((char *) data
, end
- data
);
5429 SKIP_ULEB (data
, end
);
5430 SKIP_ULEB (data
, end
);
5431 SKIP_ULEB (data
, end
);
5437 warn (_("file table ends unexpectedly\n"));
5442 /* Go through the file table again to save the strings. */
5443 file_table
= (File_Entry
*) xmalloc (n_files
* sizeof (File_Entry
));
5446 while (*ptr_file_name_table
!= 0)
5448 file_table
[i
].name
= (char *) ptr_file_name_table
;
5450 += strlen ((char *) ptr_file_name_table
) + 1;
5452 /* We are not interested in directory, time or size. */
5453 READ_ULEB (file_table
[i
].directory_index
,
5454 ptr_file_name_table
, end
);
5455 READ_ULEB (file_table
[i
].modification_date
,
5456 ptr_file_name_table
, end
);
5457 READ_ULEB (file_table
[i
].length
,
5458 ptr_file_name_table
, end
);
5464 /* Skip the NUL at the end of the table. */
5468 /* Print the Compilation Unit's name and a header. */
5469 if (file_table
== NULL
)
5470 printf (_("CU: No directory table\n"));
5471 else if (directory_table
== NULL
)
5472 printf (_("CU: %s:\n"), null_name (file_table
[0].name
));
5475 unsigned int ix
= file_table
[0].directory_index
;
5476 const char *directory
;
5478 if (ix
== 0 && linfo
.li_version
< 5)
5481 else if (n_directories
== 0)
5482 directory
= _("<unknown>");
5485 if (linfo
.li_version
< 5)
5487 if (ix
>= n_directories
)
5489 warn (_("directory index %u "
5490 ">= number of directories %u\n"),
5492 directory
= _("<corrupt>");
5495 directory
= directory_table
[ix
];
5498 printf (_("CU: %s/%s:\n"),
5499 null_name (directory
),
5500 null_name (file_table
[0].name
));
5502 printf ("%s:\n", null_name (file_table
[0].name
));
5508 printf (_("File name Line number Starting address View Stmt\n"));
5510 printf (_("File name Line number Starting address View Stmt\n"));
5513 printf (_("CU: Empty file name table\n"));
5514 saved_linfo
= linfo
;
5517 /* This loop iterates through the Dwarf Line Number Program. */
5518 while (data
< end_of_sequence
)
5520 unsigned char op_code
;
5523 unsigned long int uladv
;
5524 int is_special_opcode
= 0;
5529 if (op_code
>= linfo
.li_opcode_base
)
5531 op_code
-= linfo
.li_opcode_base
;
5532 uladv
= (op_code
/ linfo
.li_line_range
);
5533 if (linfo
.li_max_ops_per_insn
== 1)
5535 uladv
*= linfo
.li_min_insn_length
;
5536 state_machine_regs
.address
+= uladv
;
5538 state_machine_regs
.view
= 0;
5543 = ((state_machine_regs
.op_index
+ uladv
)
5544 / linfo
.li_max_ops_per_insn
)
5545 * linfo
.li_min_insn_length
;
5546 state_machine_regs
.address
5548 state_machine_regs
.op_index
5549 = (state_machine_regs
.op_index
+ uladv
)
5550 % linfo
.li_max_ops_per_insn
;
5552 state_machine_regs
.view
= 0;
5555 adv
= (op_code
% linfo
.li_line_range
) + linfo
.li_line_base
;
5556 state_machine_regs
.line
+= adv
;
5557 is_special_opcode
= 1;
5558 /* Increment view after printing this row. */
5563 case DW_LNS_extended_op
:
5565 unsigned int ext_op_code_len
;
5566 unsigned char ext_op_code
;
5567 unsigned char *op_code_end
;
5568 unsigned char *op_code_data
= data
;
5570 READ_ULEB (ext_op_code_len
, op_code_data
, end_of_sequence
);
5571 op_code_end
= op_code_data
+ ext_op_code_len
;
5572 if (ext_op_code_len
== 0 || op_code_end
> end_of_sequence
)
5574 warn (_("Badly formed extended line op encountered!\n"));
5577 ext_op_code
= *op_code_data
++;
5581 switch (ext_op_code
)
5583 case DW_LNE_end_sequence
:
5584 /* Reset stuff after printing this row. */
5586 case DW_LNE_set_address
:
5587 SAFE_BYTE_GET_AND_INC (state_machine_regs
.address
,
5589 op_code_end
- op_code_data
,
5591 state_machine_regs
.op_index
= 0;
5592 state_machine_regs
.view
= 0;
5594 case DW_LNE_define_file
:
5595 file_table
= (File_Entry
*) xrealloc
5596 (file_table
, (n_files
+ 1) * sizeof (File_Entry
));
5598 ++state_machine_regs
.last_file_entry
;
5599 /* Source file name. */
5600 file_table
[n_files
].name
= (char *) op_code_data
;
5601 op_code_data
+= strlen ((char *) op_code_data
) + 1;
5602 /* Directory index. */
5603 READ_ULEB (file_table
[n_files
].directory_index
,
5604 op_code_data
, op_code_end
);
5605 /* Last modification time. */
5606 READ_ULEB (file_table
[n_files
].modification_date
,
5607 op_code_data
, op_code_end
);
5609 READ_ULEB (file_table
[n_files
].length
,
5610 op_code_data
, op_code_end
);
5614 case DW_LNE_set_discriminator
:
5615 case DW_LNE_HP_set_sequence
:
5616 /* Simply ignored. */
5620 printf (_("UNKNOWN (%u): length %ld\n"),
5621 ext_op_code
, (long int) (op_code_data
- data
));
5628 /* Increment view after printing this row. */
5631 case DW_LNS_advance_pc
:
5632 READ_ULEB (uladv
, data
, end
);
5633 if (linfo
.li_max_ops_per_insn
== 1)
5635 uladv
*= linfo
.li_min_insn_length
;
5636 state_machine_regs
.address
+= uladv
;
5638 state_machine_regs
.view
= 0;
5643 = ((state_machine_regs
.op_index
+ uladv
)
5644 / linfo
.li_max_ops_per_insn
)
5645 * linfo
.li_min_insn_length
;
5646 state_machine_regs
.address
5648 state_machine_regs
.op_index
5649 = (state_machine_regs
.op_index
+ uladv
)
5650 % linfo
.li_max_ops_per_insn
;
5652 state_machine_regs
.view
= 0;
5656 case DW_LNS_advance_line
:
5657 READ_SLEB (adv
, data
, end
);
5658 state_machine_regs
.line
+= adv
;
5661 case DW_LNS_set_file
:
5662 READ_ULEB (uladv
, data
, end
);
5663 state_machine_regs
.file
= uladv
;
5665 unsigned file
= state_machine_regs
.file
;
5666 if (linfo
.li_version
< 5)
5669 if (file_table
== NULL
|| n_files
== 0)
5670 printf (_("\n [Use file table entry %d]\n"), file
);
5672 else if (file
>= n_files
)
5674 warn (_("file index %u >= number of files %u\n"),
5676 printf (_("\n <over large file table index %u>"), file
);
5680 unsigned dir
= file_table
[file
].directory_index
;
5681 if (dir
== 0 && linfo
.li_version
< 5)
5682 /* If directory index is 0, that means compilation
5683 current directory. bfd/dwarf2.c shows
5684 DW_AT_comp_dir here but in keeping with the
5685 readelf practice of minimal interpretation of
5686 file data, we show "./". */
5687 printf ("\n./%s:[++]\n",
5688 null_name (file_table
[file
].name
));
5689 else if (directory_table
== NULL
|| n_directories
== 0)
5690 printf (_("\n [Use file %s "
5691 "in directory table entry %d]\n"),
5692 null_name (file_table
[file
].name
), dir
);
5695 if (linfo
.li_version
< 5)
5698 if (dir
>= n_directories
)
5700 warn (_("directory index %u "
5701 ">= number of directories %u\n"),
5702 dir
, n_directories
);
5703 printf (_("\n <over large directory table entry "
5707 printf ("\n%s/%s:\n",
5708 null_name (directory_table
[dir
]),
5709 null_name (file_table
[file
].name
));
5714 case DW_LNS_set_column
:
5715 READ_ULEB (uladv
, data
, end
);
5716 state_machine_regs
.column
= uladv
;
5719 case DW_LNS_negate_stmt
:
5720 adv
= state_machine_regs
.is_stmt
;
5722 state_machine_regs
.is_stmt
= adv
;
5725 case DW_LNS_set_basic_block
:
5726 state_machine_regs
.basic_block
= 1;
5729 case DW_LNS_const_add_pc
:
5730 uladv
= ((255 - linfo
.li_opcode_base
) / linfo
.li_line_range
);
5731 if (linfo
.li_max_ops_per_insn
== 1)
5733 uladv
*= linfo
.li_min_insn_length
;
5734 state_machine_regs
.address
+= uladv
;
5736 state_machine_regs
.view
= 0;
5741 = ((state_machine_regs
.op_index
+ uladv
)
5742 / linfo
.li_max_ops_per_insn
)
5743 * linfo
.li_min_insn_length
;
5744 state_machine_regs
.address
5746 state_machine_regs
.op_index
5747 = (state_machine_regs
.op_index
+ uladv
)
5748 % linfo
.li_max_ops_per_insn
;
5750 state_machine_regs
.view
= 0;
5754 case DW_LNS_fixed_advance_pc
:
5755 SAFE_BYTE_GET_AND_INC (uladv
, data
, 2, end
);
5756 state_machine_regs
.address
+= uladv
;
5757 state_machine_regs
.op_index
= 0;
5758 /* Do NOT reset view. */
5761 case DW_LNS_set_prologue_end
:
5764 case DW_LNS_set_epilogue_begin
:
5767 case DW_LNS_set_isa
:
5768 READ_ULEB (uladv
, data
, end
);
5769 printf (_(" Set ISA to %lu\n"), uladv
);
5773 printf (_(" Unknown opcode %d with operands: "), op_code
);
5775 if (standard_opcodes
!= NULL
)
5776 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
5780 READ_ULEB (val
, data
, end
);
5781 printf ("%#" PRIx64
"%s", val
, i
== 1 ? "" : ", ");
5787 /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row
5788 to the DWARF address/line matrix. */
5789 if ((is_special_opcode
) || (xop
== -DW_LNE_end_sequence
)
5790 || (xop
== DW_LNS_copy
))
5792 const unsigned int MAX_FILENAME_LENGTH
= 35;
5793 char *fileName
= NULL
;
5794 char *newFileName
= NULL
;
5795 size_t fileNameLength
;
5799 unsigned indx
= state_machine_regs
.file
;
5801 if (linfo
.li_version
< 5)
5804 if (indx
>= n_files
)
5806 warn (_("file index %u >= number of files %u\n"),
5808 fileName
= _("<corrupt>");
5811 fileName
= (char *) file_table
[indx
].name
;
5814 fileName
= _("<unknown>");
5816 fileNameLength
= strlen (fileName
);
5817 newFileName
= fileName
;
5818 if (fileNameLength
> MAX_FILENAME_LENGTH
&& !do_wide
)
5820 newFileName
= (char *) xmalloc (MAX_FILENAME_LENGTH
+ 1);
5821 /* Truncate file name */
5822 memcpy (newFileName
,
5823 fileName
+ fileNameLength
- MAX_FILENAME_LENGTH
,
5824 MAX_FILENAME_LENGTH
);
5825 newFileName
[MAX_FILENAME_LENGTH
] = 0;
5828 /* A row with end_seq set to true has a meaningful address, but
5829 the other information in the same row is not significant.
5830 In such a row, print line as "-", and don't print
5832 if (!do_wide
|| fileNameLength
<= MAX_FILENAME_LENGTH
)
5834 if (linfo
.li_max_ops_per_insn
== 1)
5836 if (xop
== -DW_LNE_end_sequence
)
5837 printf ("%-31s %11s %#18" PRIx64
,
5839 state_machine_regs
.address
);
5841 printf ("%-31s %11d %#18" PRIx64
,
5842 newFileName
, state_machine_regs
.line
,
5843 state_machine_regs
.address
);
5847 if (xop
== -DW_LNE_end_sequence
)
5848 printf ("%-31s %11s %#18" PRIx64
"[%d]",
5850 state_machine_regs
.address
,
5851 state_machine_regs
.op_index
);
5853 printf ("%-31s %11d %#18" PRIx64
"[%d]",
5854 newFileName
, state_machine_regs
.line
,
5855 state_machine_regs
.address
,
5856 state_machine_regs
.op_index
);
5861 if (linfo
.li_max_ops_per_insn
== 1)
5863 if (xop
== -DW_LNE_end_sequence
)
5864 printf ("%s %11s %#18" PRIx64
,
5866 state_machine_regs
.address
);
5868 printf ("%s %11d %#18" PRIx64
,
5869 newFileName
, state_machine_regs
.line
,
5870 state_machine_regs
.address
);
5874 if (xop
== -DW_LNE_end_sequence
)
5875 printf ("%s %11s %#18" PRIx64
"[%d]",
5877 state_machine_regs
.address
,
5878 state_machine_regs
.op_index
);
5880 printf ("%s %11d %#18" PRIx64
"[%d]",
5881 newFileName
, state_machine_regs
.line
,
5882 state_machine_regs
.address
,
5883 state_machine_regs
.op_index
);
5887 if (xop
!= -DW_LNE_end_sequence
)
5889 if (state_machine_regs
.view
)
5890 printf (" %6u", state_machine_regs
.view
);
5894 if (state_machine_regs
.is_stmt
)
5899 state_machine_regs
.view
++;
5901 if (xop
== -DW_LNE_end_sequence
)
5903 reset_state_machine (linfo
.li_default_is_stmt
);
5907 if (newFileName
!= fileName
)
5919 if (directory_table
)
5921 free (directory_table
);
5922 directory_table
= NULL
;
5933 display_debug_lines (struct dwarf_section
*section
, void *file
)
5935 unsigned char *data
= section
->start
;
5936 unsigned char *end
= data
+ section
->size
;
5938 int retValDecoded
= 1;
5940 if (do_debug_lines
== 0)
5941 do_debug_lines
|= FLAG_DEBUG_LINES_RAW
;
5943 if (do_debug_lines
& FLAG_DEBUG_LINES_RAW
)
5944 retValRaw
= display_debug_lines_raw (section
, data
, end
, file
);
5946 if (do_debug_lines
& FLAG_DEBUG_LINES_DECODED
)
5947 retValDecoded
= display_debug_lines_decoded (section
, data
, data
, end
, file
);
5949 if (!retValRaw
|| !retValDecoded
)
5956 find_debug_info_for_offset (uint64_t offset
)
5960 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
5963 for (i
= 0; i
< num_debug_info_entries
; i
++)
5964 if (debug_information
[i
].cu_offset
== offset
)
5965 return debug_information
+ i
;
5971 get_gdb_index_symbol_kind_name (gdb_index_symbol_kind kind
)
5973 /* See gdb/gdb-index.h. */
5974 static const char * const kinds
[] =
5986 return _ (kinds
[kind
]);
5990 display_debug_pubnames_worker (struct dwarf_section
*section
,
5991 void *file ATTRIBUTE_UNUSED
,
5994 DWARF2_Internal_PubNames names
;
5995 unsigned char *start
= section
->start
;
5996 unsigned char *end
= start
+ section
->size
;
5998 /* It does not matter if this load fails,
5999 we test for that later on. */
6000 load_debug_info (file
);
6002 introduce (section
, false);
6006 unsigned char *data
;
6007 unsigned long sec_off
= start
- section
->start
;
6008 unsigned int offset_size
;
6010 SAFE_BYTE_GET_AND_INC (names
.pn_length
, start
, 4, end
);
6011 if (names
.pn_length
== 0xffffffff)
6013 SAFE_BYTE_GET_AND_INC (names
.pn_length
, start
, 8, end
);
6019 if (names
.pn_length
> (size_t) (end
- start
))
6021 warn (_("Debug info is corrupted, "
6022 "%s header at %#lx has length %#" PRIx64
"\n"),
6023 section
->name
, sec_off
, names
.pn_length
);
6028 start
+= names
.pn_length
;
6030 SAFE_BYTE_GET_AND_INC (names
.pn_version
, data
, 2, start
);
6031 SAFE_BYTE_GET_AND_INC (names
.pn_offset
, data
, offset_size
, start
);
6033 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
6034 && num_debug_info_entries
> 0
6035 && find_debug_info_for_offset (names
.pn_offset
) == NULL
)
6036 warn (_(".debug_info offset of %#" PRIx64
6037 " in %s section does not point to a CU header.\n"),
6038 names
.pn_offset
, section
->name
);
6040 SAFE_BYTE_GET_AND_INC (names
.pn_size
, data
, offset_size
, start
);
6042 printf (_(" Length: %" PRId64
"\n"),
6044 printf (_(" Version: %d\n"),
6046 printf (_(" Offset into .debug_info section: %#" PRIx64
"\n"),
6048 printf (_(" Size of area in .debug_info section: %" PRId64
"\n"),
6051 if (names
.pn_version
!= 2 && names
.pn_version
!= 3)
6053 static int warned
= 0;
6057 warn (_("Only DWARF 2 and 3 pubnames are currently supported\n"));
6065 printf (_("\n Offset Kind Name\n"));
6067 printf (_("\n Offset\tName\n"));
6074 SAFE_BYTE_GET_AND_INC (offset
, data
, offset_size
, start
);
6081 maxprint
= (start
- data
) - 1;
6085 unsigned int kind_data
;
6086 gdb_index_symbol_kind kind
;
6087 const char *kind_name
;
6090 SAFE_BYTE_GET_AND_INC (kind_data
, data
, 1, start
);
6092 /* GCC computes the kind as the upper byte in the CU index
6093 word, and then right shifts it by the CU index size.
6094 Left shift KIND to where the gdb-index.h accessor macros
6096 kind_data
<<= GDB_INDEX_CU_BITSIZE
;
6097 kind
= GDB_INDEX_SYMBOL_KIND_VALUE (kind_data
);
6098 kind_name
= get_gdb_index_symbol_kind_name (kind
);
6099 is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (kind_data
);
6100 printf (" %-6" PRIx64
" %s,%-10s %.*s\n",
6101 offset
, is_static
? _("s") : _("g"),
6102 kind_name
, (int) maxprint
, data
);
6105 printf (" %-6" PRIx64
"\t%.*s\n",
6106 offset
, (int) maxprint
, data
);
6108 data
+= strnlen ((char *) data
, maxprint
);
6121 display_debug_pubnames (struct dwarf_section
*section
, void *file
)
6123 return display_debug_pubnames_worker (section
, file
, 0);
6127 display_debug_gnu_pubnames (struct dwarf_section
*section
, void *file
)
6129 return display_debug_pubnames_worker (section
, file
, 1);
6133 display_debug_macinfo (struct dwarf_section
*section
,
6134 void *file ATTRIBUTE_UNUSED
)
6136 unsigned char *start
= section
->start
;
6137 unsigned char *end
= start
+ section
->size
;
6138 unsigned char *curr
= start
;
6139 enum dwarf_macinfo_record_type op
;
6141 introduce (section
, false);
6145 unsigned int lineno
;
6146 const unsigned char *string
;
6148 op
= (enum dwarf_macinfo_record_type
) *curr
;
6153 case DW_MACINFO_start_file
:
6155 unsigned int filenum
;
6157 READ_ULEB (lineno
, curr
, end
);
6158 READ_ULEB (filenum
, curr
, end
);
6159 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"),
6164 case DW_MACINFO_end_file
:
6165 printf (_(" DW_MACINFO_end_file\n"));
6168 case DW_MACINFO_define
:
6169 READ_ULEB (lineno
, curr
, end
);
6171 curr
+= strnlen ((char *) string
, end
- string
);
6172 printf (_(" DW_MACINFO_define - lineno : %d macro : %*s\n"),
6173 lineno
, (int) (curr
- string
), string
);
6178 case DW_MACINFO_undef
:
6179 READ_ULEB (lineno
, curr
, end
);
6181 curr
+= strnlen ((char *) string
, end
- string
);
6182 printf (_(" DW_MACINFO_undef - lineno : %d macro : %*s\n"),
6183 lineno
, (int) (curr
- string
), string
);
6188 case DW_MACINFO_vendor_ext
:
6190 unsigned int constant
;
6192 READ_ULEB (constant
, curr
, end
);
6194 curr
+= strnlen ((char *) string
, end
- string
);
6195 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %*s\n"),
6196 constant
, (int) (curr
- string
), string
);
6207 /* Given LINE_OFFSET into the .debug_line section, attempt to return
6208 filename and dirname corresponding to file name table entry with index
6209 FILEIDX. Return NULL on failure. */
6211 static unsigned char *
6212 get_line_filename_and_dirname (uint64_t line_offset
,
6214 unsigned char **dir_name
)
6216 struct dwarf_section
*section
= &debug_displays
[line
].section
;
6217 unsigned char *hdrptr
, *dirtable
, *file_name
;
6218 unsigned int offset_size
;
6219 unsigned int version
, opcode_base
;
6220 uint64_t length
, diridx
;
6221 const unsigned char * end
;
6224 if (section
->start
== NULL
6225 || line_offset
>= section
->size
6229 hdrptr
= section
->start
+ line_offset
;
6230 end
= section
->start
+ section
->size
;
6232 SAFE_BYTE_GET_AND_INC (length
, hdrptr
, 4, end
);
6233 if (length
== 0xffffffff)
6235 /* This section is 64-bit DWARF 3. */
6236 SAFE_BYTE_GET_AND_INC (length
, hdrptr
, 8, end
);
6242 if (length
> (size_t) (end
- hdrptr
)
6243 || length
< 2 + offset_size
+ 1 + 3 + 1)
6245 end
= hdrptr
+ length
;
6247 SAFE_BYTE_GET_AND_INC (version
, hdrptr
, 2, end
);
6248 if (version
!= 2 && version
!= 3 && version
!= 4)
6250 hdrptr
+= offset_size
+ 1;/* Skip prologue_length and min_insn_length. */
6252 hdrptr
++; /* Skip max_ops_per_insn. */
6253 hdrptr
+= 3; /* Skip default_is_stmt, line_base, line_range. */
6255 SAFE_BYTE_GET_AND_INC (opcode_base
, hdrptr
, 1, end
);
6256 if (opcode_base
== 0
6257 || opcode_base
- 1 >= (size_t) (end
- hdrptr
))
6260 hdrptr
+= opcode_base
- 1;
6263 /* Skip over dirname table. */
6264 while (*hdrptr
!= '\0')
6266 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
);
6272 hdrptr
++; /* Skip the NUL at the end of the table. */
6274 /* Now skip over preceding filename table entries. */
6275 for (; hdrptr
< end
&& *hdrptr
!= '\0' && fileidx
> 1; fileidx
--)
6277 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
);
6280 SKIP_ULEB (hdrptr
, end
);
6281 SKIP_ULEB (hdrptr
, end
);
6282 SKIP_ULEB (hdrptr
, end
);
6284 if (hdrptr
>= end
|| *hdrptr
== '\0')
6288 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
);
6293 READ_ULEB (diridx
, hdrptr
, end
);
6296 for (; dirtable
< end
&& *dirtable
!= '\0' && diridx
> 1; diridx
--)
6298 dirtable
+= strnlen ((char *) dirtable
, end
- dirtable
);
6302 if (dirtable
>= end
|| *dirtable
== '\0')
6304 *dir_name
= dirtable
;
6309 display_debug_macro (struct dwarf_section
*section
,
6312 unsigned char *start
= section
->start
;
6313 unsigned char *end
= start
+ section
->size
;
6314 unsigned char *curr
= start
;
6315 unsigned char *extended_op_buf
[256];
6316 bool is_dwo
= false;
6317 const char *suffix
= strrchr (section
->name
, '.');
6319 if (suffix
&& strcmp (suffix
, ".dwo") == 0)
6324 load_debug_section_with_follow (str_dwo
, file
);
6325 load_debug_section_with_follow (str_index_dwo
, file
);
6329 load_debug_section_with_follow (str
, file
);
6330 load_debug_section_with_follow (str_index
, file
);
6332 load_debug_section_with_follow (line
, file
);
6334 introduce (section
, false);
6338 unsigned int lineno
, version
, flags
;
6339 unsigned int offset_size
;
6340 const unsigned char *string
;
6341 uint64_t line_offset
= 0, sec_offset
= curr
- start
, offset
;
6342 unsigned char **extended_ops
= NULL
;
6344 SAFE_BYTE_GET_AND_INC (version
, curr
, 2, end
);
6345 if (version
!= 4 && version
!= 5)
6347 error (_("Expected to find a version number of 4 or 5 in section %s but found %d instead\n"),
6348 section
->name
, version
);
6352 SAFE_BYTE_GET_AND_INC (flags
, curr
, 1, end
);
6353 offset_size
= (flags
& 1) ? 8 : 4;
6354 printf (_(" Offset: %#" PRIx64
"\n"), sec_offset
);
6355 printf (_(" Version: %d\n"), version
);
6356 printf (_(" Offset size: %d\n"), offset_size
);
6359 SAFE_BYTE_GET_AND_INC (line_offset
, curr
, offset_size
, end
);
6360 printf (_(" Offset into .debug_line: %#" PRIx64
"\n"),
6365 unsigned int i
, count
, op
;
6368 SAFE_BYTE_GET_AND_INC (count
, curr
, 1, end
);
6370 memset (extended_op_buf
, 0, sizeof (extended_op_buf
));
6371 extended_ops
= extended_op_buf
;
6374 printf (_(" Extension opcode arguments:\n"));
6375 for (i
= 0; i
< count
; i
++)
6377 SAFE_BYTE_GET_AND_INC (op
, curr
, 1, end
);
6378 extended_ops
[op
] = curr
;
6379 READ_ULEB (nargs
, curr
, end
);
6381 printf (_(" DW_MACRO_%02x has no arguments\n"), op
);
6384 printf (_(" DW_MACRO_%02x arguments: "), op
);
6385 for (n
= 0; n
< nargs
; n
++)
6389 SAFE_BYTE_GET_AND_INC (form
, curr
, 1, end
);
6390 printf ("%s%s", get_FORM_name (form
),
6391 n
== nargs
- 1 ? "\n" : ", ");
6401 case DW_FORM_block1
:
6402 case DW_FORM_block2
:
6403 case DW_FORM_block4
:
6405 case DW_FORM_string
:
6407 case DW_FORM_sec_offset
:
6410 error (_("Invalid extension opcode form %s\n"),
6411 get_FORM_name (form
));
6427 error (_(".debug_macro section not zero terminated\n"));
6431 SAFE_BYTE_GET_AND_INC (op
, curr
, 1, end
);
6437 case DW_MACRO_define
:
6438 READ_ULEB (lineno
, curr
, end
);
6440 curr
+= strnlen ((char *) string
, end
- string
);
6441 printf (_(" DW_MACRO_define - lineno : %d macro : %*s\n"),
6442 lineno
, (int) (curr
- string
), string
);
6447 case DW_MACRO_undef
:
6448 READ_ULEB (lineno
, curr
, end
);
6450 curr
+= strnlen ((char *) string
, end
- string
);
6451 printf (_(" DW_MACRO_undef - lineno : %d macro : %*s\n"),
6452 lineno
, (int) (curr
- string
), string
);
6457 case DW_MACRO_start_file
:
6459 unsigned int filenum
;
6460 unsigned char *file_name
= NULL
, *dir_name
= NULL
;
6462 READ_ULEB (lineno
, curr
, end
);
6463 READ_ULEB (filenum
, curr
, end
);
6465 if ((flags
& 2) == 0)
6466 error (_("DW_MACRO_start_file used, but no .debug_line offset provided.\n"));
6469 = get_line_filename_and_dirname (line_offset
, filenum
,
6471 if (file_name
== NULL
)
6472 printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d\n"),
6475 printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d filename: %s%s%s\n"),
6477 dir_name
!= NULL
? (const char *) dir_name
: "",
6478 dir_name
!= NULL
? "/" : "", file_name
);
6482 case DW_MACRO_end_file
:
6483 printf (_(" DW_MACRO_end_file\n"));
6486 case DW_MACRO_define_strp
:
6487 READ_ULEB (lineno
, curr
, end
);
6488 if (version
== 4 && is_dwo
)
6489 READ_ULEB (offset
, curr
, end
);
6491 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6492 string
= fetch_indirect_string (offset
);
6493 printf (_(" DW_MACRO_define_strp - lineno : %d macro : %s\n"),
6497 case DW_MACRO_undef_strp
:
6498 READ_ULEB (lineno
, curr
, end
);
6499 if (version
== 4 && is_dwo
)
6500 READ_ULEB (offset
, curr
, end
);
6502 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6503 string
= fetch_indirect_string (offset
);
6504 printf (_(" DW_MACRO_undef_strp - lineno : %d macro : %s\n"),
6508 case DW_MACRO_import
:
6509 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6510 printf (_(" DW_MACRO_import - offset : %#" PRIx64
"\n"),
6514 case DW_MACRO_define_sup
:
6515 READ_ULEB (lineno
, curr
, end
);
6516 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6517 printf (_(" DW_MACRO_define_sup - lineno : %d"
6518 " macro offset : %#" PRIx64
"\n"),
6522 case DW_MACRO_undef_sup
:
6523 READ_ULEB (lineno
, curr
, end
);
6524 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6525 printf (_(" DW_MACRO_undef_sup - lineno : %d"
6526 " macro offset : %#" PRIx64
"\n"),
6530 case DW_MACRO_import_sup
:
6531 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6532 printf (_(" DW_MACRO_import_sup - offset : %#" PRIx64
"\n"),
6536 case DW_MACRO_define_strx
:
6537 case DW_MACRO_undef_strx
:
6538 READ_ULEB (lineno
, curr
, end
);
6539 READ_ULEB (offset
, curr
, end
);
6540 string
= (const unsigned char *)
6541 fetch_indexed_string (offset
, NULL
, offset_size
, is_dwo
, 0);
6542 if (op
== DW_MACRO_define_strx
)
6543 printf (" DW_MACRO_define_strx ");
6545 printf (" DW_MACRO_undef_strx ");
6547 printf (_("(with offset %#" PRIx64
") "), offset
);
6548 printf (_("lineno : %d macro : %s\n"),
6553 if (op
>= DW_MACRO_lo_user
&& op
<= DW_MACRO_hi_user
)
6555 printf (_(" <Target Specific macro op: %#x - UNHANDLED"), op
);
6559 if (extended_ops
== NULL
|| extended_ops
[op
] == NULL
)
6561 error (_(" Unknown macro opcode %02x seen\n"), op
);
6566 /* Skip over unhandled opcodes. */
6568 unsigned char *desc
= extended_ops
[op
];
6569 READ_ULEB (nargs
, desc
, end
);
6572 printf (_(" DW_MACRO_%02x\n"), op
);
6575 printf (_(" DW_MACRO_%02x -"), op
);
6576 for (n
= 0; n
< nargs
; n
++)
6580 /* DW_FORM_implicit_const is not expected here. */
6581 SAFE_BYTE_GET_AND_INC (val
, desc
, 1, end
);
6583 = read_and_display_attr_value (0, val
, 0,
6584 start
, curr
, end
, 0, 0,
6585 offset_size
, version
,
6604 display_debug_abbrev (struct dwarf_section
*section
,
6605 void *file ATTRIBUTE_UNUSED
)
6607 abbrev_entry
*entry
;
6608 unsigned char *start
= section
->start
;
6610 introduce (section
, false);
6614 uint64_t offset
= start
- section
->start
;
6615 abbrev_list
*list
= find_and_process_abbrev_set (section
, 0,
6616 section
->size
, offset
,
6621 if (list
->first_abbrev
)
6622 printf (_(" Number TAG (%#" PRIx64
")\n"), offset
);
6624 for (entry
= list
->first_abbrev
; entry
; entry
= entry
->next
)
6628 printf (" %ld %s [%s]\n",
6630 get_TAG_name (entry
->tag
),
6631 entry
->children
? _("has children") : _("no children"));
6633 for (attr
= entry
->first_attr
; attr
; attr
= attr
->next
)
6635 printf (" %-18s %s",
6636 get_AT_name (attr
->attribute
),
6637 get_FORM_name (attr
->form
));
6638 if (attr
->form
== DW_FORM_implicit_const
)
6639 printf (": %" PRId64
, attr
->implicit_const
);
6643 start
= list
->start_of_next_abbrevs
;
6644 free_abbrev_list (list
);
6653 /* Return true when ADDR is the maximum address, when addresses are
6654 POINTER_SIZE bytes long. */
6657 is_max_address (uint64_t addr
, unsigned int pointer_size
)
6659 uint64_t mask
= ~(~(uint64_t) 0 << 1 << (pointer_size
* 8 - 1));
6660 return ((addr
& mask
) == mask
);
6663 /* Display a view pair list starting at *VSTART_PTR and ending at
6664 VLISTEND within SECTION. */
6667 display_view_pair_list (struct dwarf_section
*section
,
6668 unsigned char **vstart_ptr
,
6669 unsigned int debug_info_entry
,
6670 unsigned char *vlistend
)
6672 unsigned char *vstart
= *vstart_ptr
;
6673 unsigned char *section_end
= section
->start
+ section
->size
;
6674 unsigned int pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
6676 if (vlistend
< section_end
)
6677 section_end
= vlistend
;
6681 while (vstart
< section_end
)
6683 uint64_t off
= vstart
- section
->start
;
6684 uint64_t vbegin
, vend
;
6686 READ_ULEB (vbegin
, vstart
, section_end
);
6687 if (vstart
== section_end
)
6690 READ_ULEB (vend
, vstart
, section_end
);
6691 printf (" %8.8" PRIx64
" ", off
);
6693 print_view (vbegin
, pointer_size
);
6694 print_view (vend
, pointer_size
);
6695 printf (_("location view pair\n"));
6699 *vstart_ptr
= vstart
;
6702 /* Display a location list from a normal (ie, non-dwo) .debug_loc section. */
6705 display_loc_list (struct dwarf_section
*section
,
6706 unsigned char **start_ptr
,
6707 unsigned int debug_info_entry
,
6709 uint64_t base_address
,
6710 unsigned char **vstart_ptr
,
6713 unsigned char *start
= *start_ptr
, *vstart
= *vstart_ptr
;
6714 unsigned char *section_end
= section
->start
+ section
->size
;
6716 unsigned int pointer_size
;
6717 unsigned int offset_size
;
6721 unsigned short length
;
6722 int need_frame_base
;
6724 if (debug_info_entry
>= num_debug_info_entries
)
6726 warn (_("No debug information available for loc lists of entry: %u\n"),
6731 cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
6732 pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
6733 offset_size
= debug_information
[debug_info_entry
].offset_size
;
6734 dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
6736 if (pointer_size
< 2 || pointer_size
> 8)
6738 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
6739 pointer_size
, debug_info_entry
);
6745 uint64_t off
= offset
+ (start
- *start_ptr
);
6746 uint64_t vbegin
= -1, vend
= -1;
6748 if (2 * pointer_size
> (size_t) (section_end
- start
))
6750 warn (_("Location list starting at offset %#" PRIx64
6751 " is not terminated.\n"), offset
);
6758 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, section_end
);
6759 SAFE_BYTE_GET_AND_INC (end
, start
, pointer_size
, section_end
);
6761 if (begin
== 0 && end
== 0)
6763 /* PR 18374: In a object file we can have a location list that
6764 starts with a begin and end of 0 because there are relocations
6765 that need to be applied to the addresses. Actually applying
6766 the relocations now does not help as they will probably resolve
6767 to 0, since the object file has not been fully linked. Real
6768 end of list markers will not have any relocations against them. */
6769 if (! reloc_at (section
, off
)
6770 && ! reloc_at (section
, off
+ pointer_size
))
6772 printf (_("<End of list>\n"));
6777 /* Check base address specifiers. */
6778 if (is_max_address (begin
, pointer_size
)
6779 && !is_max_address (end
, pointer_size
))
6782 print_hex (begin
, pointer_size
);
6783 print_hex (end
, pointer_size
);
6784 printf (_("(base address)\n"));
6790 off
= offset
+ (vstart
- *start_ptr
);
6792 READ_ULEB (vbegin
, vstart
, section_end
);
6793 print_view (vbegin
, pointer_size
);
6795 READ_ULEB (vend
, vstart
, section_end
);
6796 print_view (vend
, pointer_size
);
6798 printf (_("views at %8.8" PRIx64
" for:\n %*s "), off
, 8, "");
6801 if (2 > (size_t) (section_end
- start
))
6803 warn (_("Location list starting at offset %#" PRIx64
6804 " is not terminated.\n"), offset
);
6808 SAFE_BYTE_GET_AND_INC (length
, start
, 2, section_end
);
6810 if (length
> (size_t) (section_end
- start
))
6812 warn (_("Location list starting at offset %#" PRIx64
6813 " is not terminated.\n"), offset
);
6817 print_hex (begin
+ base_address
, pointer_size
);
6818 print_hex (end
+ base_address
, pointer_size
);
6821 need_frame_base
= decode_location_expression (start
,
6826 cu_offset
, section
);
6829 if (need_frame_base
&& !has_frame_base
)
6830 printf (_(" [without DW_AT_frame_base]"));
6832 if (begin
== end
&& vbegin
== vend
)
6833 fputs (_(" (start == end)"), stdout
);
6834 else if (begin
> end
|| (begin
== end
&& vbegin
> vend
))
6835 fputs (_(" (start > end)"), stdout
);
6843 *vstart_ptr
= vstart
;
6846 /* Display a location list from a normal (ie, non-dwo) .debug_loclists section. */
6849 display_loclists_list (struct dwarf_section
* section
,
6850 unsigned char ** start_ptr
,
6851 debug_info
* debug_info_p
,
6853 uint64_t base_address
,
6854 unsigned char ** vstart_ptr
,
6857 unsigned char *start
= *start_ptr
;
6858 unsigned char *vstart
= *vstart_ptr
;
6859 unsigned char *section_end
= section
->start
+ section
->size
;
6861 unsigned int pointer_size
;
6862 unsigned int offset_size
;
6863 unsigned int dwarf_version
;
6866 /* Initialize it due to a false compiler warning. */
6867 uint64_t begin
= -1, vbegin
= -1;
6868 uint64_t end
= -1, vend
= -1;
6870 int need_frame_base
;
6872 cu_offset
= debug_info_p
->cu_offset
;
6873 pointer_size
= debug_info_p
->pointer_size
;
6874 offset_size
= debug_info_p
->offset_size
;
6875 dwarf_version
= debug_info_p
->dwarf_version
;
6877 if (pointer_size
< 2 || pointer_size
> 8)
6879 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
6880 pointer_size
, (int)(debug_info_p
- debug_information
));
6886 uint64_t off
= offset
+ (start
- *start_ptr
);
6887 enum dwarf_location_list_entry_type llet
;
6889 if (start
+ 1 > section_end
)
6891 warn (_("Location list starting at offset %#" PRIx64
6892 " is not terminated.\n"), offset
);
6899 SAFE_BYTE_GET_AND_INC (llet
, start
, 1, section_end
);
6901 if (vstart
&& (llet
== DW_LLE_offset_pair
6902 || llet
== DW_LLE_start_end
6903 || llet
== DW_LLE_start_length
))
6905 off
= offset
+ (vstart
- *start_ptr
);
6907 READ_ULEB (vbegin
, vstart
, section_end
);
6908 print_view (vbegin
, pointer_size
);
6910 READ_ULEB (vend
, vstart
, section_end
);
6911 print_view (vend
, pointer_size
);
6913 printf (_("views at %8.8" PRIx64
" for:\n %*s "), off
, 8, "");
6918 case DW_LLE_end_of_list
:
6919 printf (_("<End of list>\n"));
6922 case DW_LLE_base_addressx
:
6923 READ_ULEB (idx
, start
, section_end
);
6924 print_hex (idx
, pointer_size
);
6925 printf (_("(index into .debug_addr) "));
6926 base_address
= fetch_indexed_addr
6927 (debug_info_p
->addr_base
+ idx
* pointer_size
, pointer_size
);
6928 print_hex (base_address
, pointer_size
);
6929 printf (_("(base address)\n"));
6932 case DW_LLE_startx_endx
:
6933 READ_ULEB (idx
, start
, section_end
);
6934 begin
= fetch_indexed_addr
6935 (debug_info_p
->addr_base
+ idx
* pointer_size
, pointer_size
);
6936 READ_ULEB (idx
, start
, section_end
);
6937 end
= fetch_indexed_addr
6938 (debug_info_p
->addr_base
+ idx
* pointer_size
, pointer_size
);
6941 case DW_LLE_startx_length
:
6942 READ_ULEB (idx
, start
, section_end
);
6943 begin
= fetch_indexed_addr
6944 (debug_info_p
->addr_base
+ idx
* pointer_size
, pointer_size
);
6945 READ_ULEB (end
, start
, section_end
);
6949 case DW_LLE_default_location
:
6953 case DW_LLE_offset_pair
:
6954 READ_ULEB (begin
, start
, section_end
);
6955 begin
+= base_address
;
6956 READ_ULEB (end
, start
, section_end
);
6957 end
+= base_address
;
6960 case DW_LLE_base_address
:
6961 SAFE_BYTE_GET_AND_INC (base_address
, start
, pointer_size
,
6963 print_hex (base_address
, pointer_size
);
6964 printf (_("(base address)\n"));
6967 case DW_LLE_start_end
:
6968 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, section_end
);
6969 SAFE_BYTE_GET_AND_INC (end
, start
, pointer_size
, section_end
);
6972 case DW_LLE_start_length
:
6973 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, section_end
);
6974 READ_ULEB (end
, start
, section_end
);
6978 #ifdef DW_LLE_view_pair
6979 case DW_LLE_view_pair
:
6981 printf (_("View pair entry in loclist with locviews attribute\n"));
6982 READ_ULEB (vbegin
, start
, section_end
);
6983 print_view (vbegin
, pointer_size
);
6985 READ_ULEB (vend
, start
, section_end
);
6986 print_view (vend
, pointer_size
);
6988 printf (_("views for:\n"));
6993 error (_("Invalid location list entry type %d\n"), llet
);
6997 if (llet
== DW_LLE_end_of_list
)
7000 if (llet
== DW_LLE_base_address
7001 || llet
== DW_LLE_base_addressx
)
7004 if (start
== section_end
)
7006 warn (_("Location list starting at offset %#" PRIx64
7007 " is not terminated.\n"), offset
);
7010 READ_ULEB (length
, start
, section_end
);
7012 if (length
> (size_t) (section_end
- start
))
7014 warn (_("Location list starting at offset %#" PRIx64
7015 " is not terminated.\n"), offset
);
7019 print_hex (begin
, pointer_size
);
7020 print_hex (end
, pointer_size
);
7023 need_frame_base
= decode_location_expression (start
,
7028 cu_offset
, section
);
7031 if (need_frame_base
&& !has_frame_base
)
7032 printf (_(" [without DW_AT_frame_base]"));
7034 if (begin
== end
&& vbegin
== vend
)
7035 fputs (_(" (start == end)"), stdout
);
7036 else if (begin
> end
|| (begin
== end
&& vbegin
> vend
))
7037 fputs (_(" (start > end)"), stdout
);
7045 if (vbegin
!= (uint64_t) -1 || vend
!= (uint64_t) -1)
7046 printf (_("Trailing view pair not used in a range"));
7049 *vstart_ptr
= vstart
;
7052 /* Print a .debug_addr table index in decimal, surrounded by square brackets,
7053 right-adjusted in a field of length LEN, and followed by a space. */
7056 print_addr_index (unsigned int idx
, unsigned int len
)
7058 static char buf
[15];
7059 snprintf (buf
, sizeof (buf
), "[%d]", idx
);
7060 printf ("%*s ", len
, buf
);
7063 /* Display a location list from a .dwo section. It uses address indexes rather
7064 than embedded addresses. This code closely follows display_loc_list, but the
7065 two are sufficiently different that combining things is very ugly. */
7068 display_loc_list_dwo (struct dwarf_section
*section
,
7069 unsigned char **start_ptr
,
7070 unsigned int debug_info_entry
,
7072 unsigned char **vstart_ptr
,
7075 unsigned char *start
= *start_ptr
, *vstart
= *vstart_ptr
;
7076 unsigned char *section_end
= section
->start
+ section
->size
;
7078 unsigned int pointer_size
;
7079 unsigned int offset_size
;
7082 unsigned short length
;
7083 int need_frame_base
;
7086 if (debug_info_entry
>= num_debug_info_entries
)
7088 warn (_("No debug information for loc lists of entry: %u\n"),
7093 cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
7094 pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
7095 offset_size
= debug_information
[debug_info_entry
].offset_size
;
7096 dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
7098 if (pointer_size
< 2 || pointer_size
> 8)
7100 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
7101 pointer_size
, debug_info_entry
);
7108 print_hex (offset
+ (start
- *start_ptr
), 4);
7110 if (start
>= section_end
)
7112 warn (_("Location list starting at offset %#" PRIx64
7113 " is not terminated.\n"), offset
);
7117 SAFE_BYTE_GET_AND_INC (entry_type
, start
, 1, section_end
);
7130 uint64_t off
= offset
+ (vstart
- *start_ptr
);
7132 READ_ULEB (view
, vstart
, section_end
);
7133 print_view (view
, 8);
7135 READ_ULEB (view
, vstart
, section_end
);
7136 print_view (view
, 8);
7138 printf (_("views at %8.8" PRIx64
" for:\n %*s "), off
, 8, "");
7146 case 0: /* A terminating entry. */
7148 *vstart_ptr
= vstart
;
7149 printf (_("<End of list>\n"));
7151 case 1: /* A base-address entry. */
7152 READ_ULEB (idx
, start
, section_end
);
7153 print_addr_index (idx
, 8);
7154 printf ("%*s", 9 + (vstart
? 2 * 6 : 0), "");
7155 printf (_("(base address selection entry)\n"));
7157 case 2: /* A start/end entry. */
7158 READ_ULEB (idx
, start
, section_end
);
7159 print_addr_index (idx
, 8);
7160 READ_ULEB (idx
, start
, section_end
);
7161 print_addr_index (idx
, 8);
7163 case 3: /* A start/length entry. */
7164 READ_ULEB (idx
, start
, section_end
);
7165 print_addr_index (idx
, 8);
7166 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
7167 printf ("%08x ", idx
);
7169 case 4: /* An offset pair entry. */
7170 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
7171 printf ("%08x ", idx
);
7172 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
7173 printf ("%08x ", idx
);
7176 warn (_("Unknown location list entry type 0x%x.\n"), entry_type
);
7178 *vstart_ptr
= vstart
;
7182 if (2 > (size_t) (section_end
- start
))
7184 warn (_("Location list starting at offset %#" PRIx64
7185 " is not terminated.\n"), offset
);
7189 SAFE_BYTE_GET_AND_INC (length
, start
, 2, section_end
);
7190 if (length
> (size_t) (section_end
- start
))
7192 warn (_("Location list starting at offset %#" PRIx64
7193 " is not terminated.\n"), offset
);
7198 need_frame_base
= decode_location_expression (start
,
7203 cu_offset
, section
);
7206 if (need_frame_base
&& !has_frame_base
)
7207 printf (_(" [without DW_AT_frame_base]"));
7215 *vstart_ptr
= vstart
;
7218 /* Sort array of indexes in ascending order of loc_offsets[idx] and
7221 static uint64_t *loc_offsets
, *loc_views
;
7224 loc_offsets_compar (const void *ap
, const void *bp
)
7226 uint64_t a
= loc_offsets
[*(const unsigned int *) ap
];
7227 uint64_t b
= loc_offsets
[*(const unsigned int *) bp
];
7229 int ret
= (a
> b
) - (b
> a
);
7233 a
= loc_views
[*(const unsigned int *) ap
];
7234 b
= loc_views
[*(const unsigned int *) bp
];
7236 ret
= (a
> b
) - (b
> a
);
7241 /* Reads and dumps the DWARFv5 loclists compiler unit header,
7242 including the offset table.
7243 Returns the offset of the next compile unit header. */
7246 display_loclists_unit_header (struct dwarf_section
* section
,
7247 uint64_t header_offset
,
7248 uint32_t * offset_count
,
7249 unsigned char ** loclists_start
)
7252 unsigned char *start
= section
->start
+ header_offset
;
7253 unsigned char *end
= section
->start
+ section
->size
;
7254 unsigned short version
;
7255 unsigned char address_size
;
7256 unsigned char segment_selector_size
;
7260 printf (_("Table at Offset %#" PRIx64
"\n"), header_offset
);
7262 SAFE_BYTE_GET_AND_INC (length
, start
, 4, end
);
7263 if (length
== 0xffffffff)
7266 SAFE_BYTE_GET_AND_INC (length
, start
, 8, end
);
7271 SAFE_BYTE_GET_AND_INC (version
, start
, 2, end
);
7272 SAFE_BYTE_GET_AND_INC (address_size
, start
, 1, end
);
7273 SAFE_BYTE_GET_AND_INC (segment_selector_size
, start
, 1, end
);
7274 SAFE_BYTE_GET_AND_INC (*offset_count
, start
, 4, end
);
7276 printf (_(" Length: %#" PRIx64
"\n"), length
);
7277 printf (_(" DWARF version: %u\n"), version
);
7278 printf (_(" Address size: %u\n"), address_size
);
7279 printf (_(" Segment size: %u\n"), segment_selector_size
);
7280 printf (_(" Offset entries: %u\n"), *offset_count
);
7282 if (segment_selector_size
!= 0)
7284 warn (_("The %s section contains an "
7285 "unsupported segment selector size: %d.\n"),
7286 section
->name
, segment_selector_size
);
7287 return (uint64_t)-1;
7292 printf (_("\n Offset Entries starting at %#tx:\n"),
7293 start
- section
->start
);
7295 for (i
= 0; i
< *offset_count
; i
++)
7299 SAFE_BYTE_GET_AND_INC (entry
, start
, is_64bit
? 8 : 4, end
);
7300 printf (_(" [%6u] %#" PRIx64
"\n"), i
, entry
);
7305 *loclists_start
= start
;
7307 /* The length field doesn't include the length field itself. */
7308 return header_offset
+ length
+ (is_64bit
? 12 : 4);
7312 display_debug_loc (struct dwarf_section
*section
, void *file
)
7314 unsigned char *start
= section
->start
, *vstart
= NULL
;
7316 unsigned char *section_begin
= start
;
7317 unsigned int num_loc_list
= 0;
7318 uint64_t last_offset
= 0;
7319 uint64_t last_view
= 0;
7320 unsigned int first
= 0;
7323 int seen_first_offset
= 0;
7324 int locs_sorted
= 1;
7325 unsigned char *next
= start
, *vnext
= vstart
;
7326 unsigned int *array
= NULL
;
7327 const char *suffix
= strrchr (section
->name
, '.');
7328 bool is_dwo
= false;
7329 int is_loclists
= strstr (section
->name
, "debug_loclists") != NULL
;
7330 uint64_t next_header_offset
= 0;
7332 if (suffix
&& strcmp (suffix
, ".dwo") == 0)
7335 bytes
= section
->size
;
7339 printf (_("\nThe %s section is empty.\n"), section
->name
);
7345 unsigned char *hdrptr
= section_begin
;
7347 unsigned short ll_version
;
7348 unsigned char *end
= section_begin
+ section
->size
;
7349 unsigned char address_size
, segment_selector_size
;
7350 uint32_t offset_entry_count
;
7352 SAFE_BYTE_GET_AND_INC (ll_length
, hdrptr
, 4, end
);
7353 if (ll_length
== 0xffffffff)
7354 SAFE_BYTE_GET_AND_INC (ll_length
, hdrptr
, 8, end
);
7356 SAFE_BYTE_GET_AND_INC (ll_version
, hdrptr
, 2, end
);
7357 if (ll_version
!= 5)
7359 warn (_("The %s section contains corrupt or "
7360 "unsupported version number: %d.\n"),
7361 section
->name
, ll_version
);
7365 SAFE_BYTE_GET_AND_INC (address_size
, hdrptr
, 1, end
);
7367 SAFE_BYTE_GET_AND_INC (segment_selector_size
, hdrptr
, 1, end
);
7368 if (segment_selector_size
!= 0)
7370 warn (_("The %s section contains "
7371 "unsupported segment selector size: %d.\n"),
7372 section
->name
, segment_selector_size
);
7376 SAFE_BYTE_GET_AND_INC (offset_entry_count
, hdrptr
, 4, end
);
7378 /*if (offset_entry_count != 0)
7379 return display_offset_entry_loclists (section);*/
7381 //header_size = hdrptr - section_begin;
7384 if (load_debug_info (file
) == 0)
7386 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
7391 /* Check the order of location list in .debug_info section. If
7392 offsets of location lists are in the ascending order, we can
7393 use `debug_information' directly. */
7394 for (i
= 0; i
< num_debug_info_entries
; i
++)
7398 num
= debug_information
[i
].num_loc_offsets
;
7399 if (num
> num_loc_list
)
7402 /* Check if we can use `debug_information' directly. */
7403 if (locs_sorted
&& num
!= 0)
7405 if (!seen_first_offset
)
7407 /* This is the first location list. */
7408 last_offset
= debug_information
[i
].loc_offsets
[0];
7409 last_view
= debug_information
[i
].loc_views
[0];
7411 seen_first_offset
= 1;
7417 for (; j
< num
; j
++)
7420 debug_information
[i
].loc_offsets
[j
]
7421 || (last_offset
== debug_information
[i
].loc_offsets
[j
]
7422 && last_view
> debug_information
[i
].loc_views
[j
]))
7427 last_offset
= debug_information
[i
].loc_offsets
[j
];
7428 last_view
= debug_information
[i
].loc_views
[j
];
7433 if (!seen_first_offset
)
7434 error (_("No location lists in .debug_info section!\n"));
7437 array
= (unsigned int *) xcmalloc (num_loc_list
, sizeof (unsigned int));
7439 introduce (section
, false);
7441 if (reloc_at (section
, 0))
7442 printf (_(" Warning: This section has relocations - addresses seen here may not be accurate.\n\n"));
7445 printf (_(" Offset Begin End Expression\n"));
7447 for (i
= first
; i
< num_debug_info_entries
; i
++)
7449 uint64_t offset
= 0, voffset
= 0;
7450 uint64_t base_address
;
7453 debug_info
*debug_info_p
= debug_information
+ i
;
7454 uint32_t offset_count
;
7459 for (k
= 0; k
< debug_info_p
->num_loc_offsets
; k
++)
7461 loc_offsets
= debug_info_p
->loc_offsets
;
7462 loc_views
= debug_info_p
->loc_views
;
7463 qsort (array
, debug_info_p
->num_loc_offsets
,
7464 sizeof (*array
), loc_offsets_compar
);
7467 /* .debug_loclists has a per-unit header.
7468 Update start if we are detecting it. */
7469 if (debug_info_p
->dwarf_version
== 5)
7471 j
= locs_sorted
? 0 : array
[0];
7473 if (debug_info_p
->num_loc_offsets
)
7474 offset
= debug_info_p
->loc_offsets
[j
];
7476 if (debug_info_p
->num_loc_views
)
7477 voffset
= debug_info_p
->loc_views
[j
];
7479 /* Parse and dump unit headers in loclists.
7480 This will misbehave if the order of CUs in debug_info
7481 doesn't match the one in loclists. */
7482 if (next_header_offset
< offset
)
7484 while (next_header_offset
< offset
)
7486 next_header_offset
= display_loclists_unit_header
7487 (section
, next_header_offset
, &offset_count
, &start
);
7489 if (next_header_offset
== (uint64_t)-1)
7490 /* Header parsing error. */
7495 Offset Begin End Expression\n"));
7499 int adjacent_view_loclists
= 1;
7501 for (k
= 0; k
< debug_info_p
->num_loc_offsets
; k
++)
7503 j
= locs_sorted
? k
: array
[k
];
7505 && (debug_info_p
->loc_offsets
[locs_sorted
7506 ? k
- 1 : array
[k
- 1]]
7507 == debug_info_p
->loc_offsets
[j
])
7508 && (debug_info_p
->loc_views
[locs_sorted
7509 ? k
- 1 : array
[k
- 1]]
7510 == debug_info_p
->loc_views
[j
]))
7512 has_frame_base
= debug_info_p
->have_frame_base
[j
];
7513 offset
= debug_info_p
->loc_offsets
[j
];
7514 next
= section_begin
+ offset
;
7515 voffset
= debug_info_p
->loc_views
[j
];
7516 if (voffset
!= (uint64_t) -1)
7517 vnext
= section_begin
+ voffset
;
7520 base_address
= debug_info_p
->base_address
;
7522 if (vnext
&& vnext
< next
)
7525 display_view_pair_list (section
, &vstart
, i
, next
);
7532 if (vnext
&& vnext
< next
)
7533 warn (_("There is a hole [%#tx - %#" PRIx64
"]"
7534 " in %s section.\n"),
7535 start
- section_begin
, voffset
, section
->name
);
7537 warn (_("There is a hole [%#tx - %#" PRIx64
"]"
7538 " in %s section.\n"),
7539 start
- section_begin
, offset
, section
->name
);
7541 else if (start
> next
)
7542 warn (_("There is an overlap [%#tx - %#" PRIx64
"]"
7543 " in %s section.\n"),
7544 start
- section_begin
, offset
, section
->name
);
7548 if (offset
>= bytes
)
7550 warn (_("Offset %#" PRIx64
" is bigger than %s section size.\n"),
7551 offset
, section
->name
);
7555 if (vnext
&& voffset
>= bytes
)
7557 warn (_("View Offset %#" PRIx64
" is bigger than %s section size.\n"),
7558 voffset
, section
->name
);
7565 display_loc_list_dwo (section
, &start
, i
, offset
,
7566 &vstart
, has_frame_base
);
7568 display_loc_list (section
, &start
, i
, offset
, base_address
,
7569 &vstart
, has_frame_base
);
7574 warn (_("DWO is not yet supported.\n"));
7576 display_loclists_list (section
, &start
, debug_info_p
, offset
,
7577 base_address
, &vstart
, has_frame_base
);
7580 /* FIXME: this arrangement is quite simplistic. Nothing
7581 requires locview lists to be adjacent to corresponding
7582 loclists, and a single loclist could be augmented by
7583 different locview lists, and vice-versa, unlikely as it
7584 is that it would make sense to do so. Hopefully we'll
7585 have view pair support built into loclists before we ever
7586 need to address all these possibilities. */
7587 if (adjacent_view_loclists
&& vnext
7588 && vnext
!= start
&& vstart
!= next
)
7590 adjacent_view_loclists
= 0;
7591 warn (_("Hole and overlap detection requires adjacent view lists and loclists.\n"));
7594 if (vnext
&& vnext
== start
)
7595 display_view_pair_list (section
, &start
, i
, vstart
);
7599 if (start
< section
->start
+ section
->size
)
7600 warn (ngettext ("There is %ld unused byte at the end of section %s\n",
7601 "There are %ld unused bytes at the end of section %s\n",
7602 (long) (section
->start
+ section
->size
- start
)),
7603 (long) (section
->start
+ section
->size
- start
), section
->name
);
7610 display_debug_str (struct dwarf_section
*section
,
7611 void *file ATTRIBUTE_UNUSED
)
7613 unsigned char *start
= section
->start
;
7614 uint64_t bytes
= section
->size
;
7615 uint64_t addr
= section
->address
;
7619 printf (_("\nThe %s section is empty.\n"), section
->name
);
7623 introduce (section
, false);
7631 lbytes
= (bytes
> 16 ? 16 : bytes
);
7633 printf (" 0x%8.8" PRIx64
" ", addr
);
7635 for (j
= 0; j
< 16; j
++)
7638 printf ("%2.2x", start
[j
]);
7646 for (j
= 0; j
< lbytes
; j
++)
7649 if (k
>= ' ' && k
< 0x80)
7668 display_debug_info (struct dwarf_section
*section
, void *file
)
7670 return process_debug_info (section
, file
, section
->abbrev_sec
, false, false);
7674 display_debug_types (struct dwarf_section
*section
, void *file
)
7676 return process_debug_info (section
, file
, section
->abbrev_sec
, false, true);
7680 display_trace_info (struct dwarf_section
*section
, void *file
)
7682 return process_debug_info (section
, file
, section
->abbrev_sec
, false, true);
7686 display_debug_aranges (struct dwarf_section
*section
,
7687 void *file ATTRIBUTE_UNUSED
)
7689 unsigned char *start
= section
->start
;
7690 unsigned char *end
= start
+ section
->size
;
7692 introduce (section
, false);
7694 /* It does not matter if this load fails,
7695 we test for that later on. */
7696 load_debug_info (file
);
7700 unsigned char *hdrptr
;
7701 DWARF2_Internal_ARange arange
;
7702 unsigned char *addr_ranges
;
7706 unsigned char address_size
;
7707 unsigned int offset_size
;
7708 unsigned char *end_ranges
;
7711 sec_off
= hdrptr
- section
->start
;
7713 SAFE_BYTE_GET_AND_INC (arange
.ar_length
, hdrptr
, 4, end
);
7714 if (arange
.ar_length
== 0xffffffff)
7716 SAFE_BYTE_GET_AND_INC (arange
.ar_length
, hdrptr
, 8, end
);
7722 if (arange
.ar_length
> (size_t) (end
- hdrptr
))
7724 warn (_("Debug info is corrupted, %s header at %#" PRIx64
7725 " has length %#" PRIx64
"\n"),
7726 section
->name
, sec_off
, arange
.ar_length
);
7729 end_ranges
= hdrptr
+ arange
.ar_length
;
7731 SAFE_BYTE_GET_AND_INC (arange
.ar_version
, hdrptr
, 2, end_ranges
);
7732 SAFE_BYTE_GET_AND_INC (arange
.ar_info_offset
, hdrptr
, offset_size
,
7735 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
7736 && num_debug_info_entries
> 0
7737 && find_debug_info_for_offset (arange
.ar_info_offset
) == NULL
)
7738 warn (_(".debug_info offset of %#" PRIx64
7739 " in %s section does not point to a CU header.\n"),
7740 arange
.ar_info_offset
, section
->name
);
7742 SAFE_BYTE_GET_AND_INC (arange
.ar_pointer_size
, hdrptr
, 1, end_ranges
);
7743 SAFE_BYTE_GET_AND_INC (arange
.ar_segment_size
, hdrptr
, 1, end_ranges
);
7745 if (arange
.ar_version
!= 2 && arange
.ar_version
!= 3)
7747 /* PR 19872: A version number of 0 probably means that there is
7748 padding at the end of the .debug_aranges section. Gold puts
7749 it there when performing an incremental link, for example.
7750 So do not generate a warning in this case. */
7751 if (arange
.ar_version
)
7752 warn (_("Only DWARF 2 and 3 aranges are currently supported.\n"));
7756 printf (_(" Length: %" PRId64
"\n"), arange
.ar_length
);
7757 printf (_(" Version: %d\n"), arange
.ar_version
);
7758 printf (_(" Offset into .debug_info: %#" PRIx64
"\n"),
7759 arange
.ar_info_offset
);
7760 printf (_(" Pointer Size: %d\n"), arange
.ar_pointer_size
);
7761 printf (_(" Segment Size: %d\n"), arange
.ar_segment_size
);
7763 address_size
= arange
.ar_pointer_size
+ arange
.ar_segment_size
;
7765 /* PR 17512: file: 001-108546-0.001:0.1. */
7766 if (address_size
== 0 || address_size
> 8)
7768 error (_("Invalid address size in %s section!\n"),
7773 /* The DWARF spec does not require that the address size be a power
7774 of two, but we do. This will have to change if we ever encounter
7775 an uneven architecture. */
7776 if ((address_size
& (address_size
- 1)) != 0)
7778 warn (_("Pointer size + Segment size is not a power of two.\n"));
7782 if (address_size
> 4)
7783 printf (_("\n Address Length\n"));
7785 printf (_("\n Address Length\n"));
7787 addr_ranges
= hdrptr
;
7789 /* Must pad to an alignment boundary that is twice the address size. */
7790 addr_ranges
+= (2 * address_size
- 1
7791 - (hdrptr
- start
- 1) % (2 * address_size
));
7793 while (2 * address_size
<= end_ranges
- addr_ranges
)
7795 SAFE_BYTE_GET_AND_INC (address
, addr_ranges
, address_size
,
7797 SAFE_BYTE_GET_AND_INC (length
, addr_ranges
, address_size
,
7800 print_hex (address
, address_size
);
7801 print_hex_ns (length
, address_size
);
7813 /* Comparison function for qsort. */
7815 comp_addr_base (const void * v0
, const void * v1
)
7817 debug_info
*info0
= *(debug_info
**) v0
;
7818 debug_info
*info1
= *(debug_info
**) v1
;
7819 return info0
->addr_base
- info1
->addr_base
;
7822 /* Display the debug_addr section. */
7824 display_debug_addr (struct dwarf_section
*section
,
7827 debug_info
**debug_addr_info
;
7828 unsigned char *entry
;
7832 unsigned char * header
;
7834 if (section
->size
== 0)
7836 printf (_("\nThe %s section is empty.\n"), section
->name
);
7840 if (load_debug_info (file
) == 0)
7842 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
7847 introduce (section
, false);
7849 /* PR 17531: file: cf38d01b.
7850 We use xcalloc because a corrupt file may not have initialised all of the
7851 fields in the debug_info structure, which means that the sort below might
7852 try to move uninitialised data. */
7853 debug_addr_info
= (debug_info
**) xcalloc ((num_debug_info_entries
+ 1),
7854 sizeof (debug_info
*));
7857 for (i
= 0; i
< num_debug_info_entries
; i
++)
7858 if (debug_information
[i
].addr_base
!= DEBUG_INFO_UNAVAILABLE
)
7860 /* PR 17531: file: cf38d01b. */
7861 if (debug_information
[i
].addr_base
>= section
->size
)
7862 warn (_("Corrupt address base (%#" PRIx64
")"
7863 " found in debug section %u\n"),
7864 debug_information
[i
].addr_base
, i
);
7866 debug_addr_info
[count
++] = debug_information
+ i
;
7869 /* Add a sentinel to make iteration convenient. */
7870 debug_addr_info
[count
] = (debug_info
*) xmalloc (sizeof (debug_info
));
7871 debug_addr_info
[count
]->addr_base
= section
->size
;
7872 qsort (debug_addr_info
, count
, sizeof (debug_info
*), comp_addr_base
);
7874 header
= section
->start
;
7875 for (i
= 0; i
< count
; i
++)
7878 unsigned int address_size
= debug_addr_info
[i
]->pointer_size
;
7880 printf (_(" For compilation unit at offset %#" PRIx64
":\n"),
7881 debug_addr_info
[i
]->cu_offset
);
7883 printf (_("\tIndex\tAddress\n"));
7884 entry
= section
->start
+ debug_addr_info
[i
]->addr_base
;
7885 if (debug_addr_info
[i
]->dwarf_version
>= 5)
7887 size_t header_size
= entry
- header
;
7888 unsigned char *curr_header
= header
;
7891 int segment_selector_size
;
7893 if (header_size
!= 8 && header_size
!= 16)
7895 warn (_("Corrupt %s section: expecting header size of 8 or 16, but found %zd instead\n"),
7896 section
->name
, header_size
);
7900 SAFE_BYTE_GET_AND_INC (length
, curr_header
, 4, entry
);
7901 if (length
== 0xffffffff)
7902 SAFE_BYTE_GET_AND_INC (length
, curr_header
, 8, entry
);
7903 if (length
> (size_t) (section
->start
+ section
->size
- curr_header
)
7904 || length
< (size_t) (entry
- curr_header
))
7906 warn (_("Corrupt %s section: unit_length field of %#" PRIx64
7907 " is invalid\n"), section
->name
, length
);
7910 end
= curr_header
+ length
;
7911 SAFE_BYTE_GET_AND_INC (version
, curr_header
, 2, entry
);
7913 warn (_("Corrupt %s section: expecting version number 5 in header but found %d instead\n"),
7914 section
->name
, version
);
7916 SAFE_BYTE_GET_AND_INC (address_size
, curr_header
, 1, entry
);
7917 SAFE_BYTE_GET_AND_INC (segment_selector_size
, curr_header
, 1, entry
);
7918 address_size
+= segment_selector_size
;
7921 end
= section
->start
+ debug_addr_info
[i
+ 1]->addr_base
;
7926 if (address_size
< 1 || address_size
> sizeof (uint64_t))
7928 warn (_("Corrupt %s section: address size (%x) is wrong\n"),
7929 section
->name
, address_size
);
7933 while ((size_t) (end
- entry
) >= address_size
)
7935 uint64_t base
= byte_get (entry
, address_size
);
7936 printf (_("\t%d:\t"), idx
);
7937 print_hex_ns (base
, address_size
);
7939 entry
+= address_size
;
7945 free (debug_addr_info
[count
]);
7946 free (debug_addr_info
);
7950 /* Display the .debug_str_offsets and .debug_str_offsets.dwo sections. */
7953 display_debug_str_offsets (struct dwarf_section
*section
,
7954 void *file ATTRIBUTE_UNUSED
)
7958 if (section
->size
== 0)
7960 printf (_("\nThe %s section is empty.\n"), section
->name
);
7964 unsigned char *start
= section
->start
;
7965 unsigned char *end
= start
+ section
->size
;
7966 unsigned char *curr
= start
;
7967 uint64_t debug_str_offsets_hdr_len
;
7969 const char *suffix
= strrchr (section
->name
, '.');
7970 bool dwo
= suffix
&& strcmp (suffix
, ".dwo") == 0;
7973 load_debug_section_with_follow (str_dwo
, file
);
7975 load_debug_section_with_follow (str
, file
);
7977 introduce (section
, false);
7982 uint64_t entry_length
;
7984 SAFE_BYTE_GET_AND_INC (length
, curr
, 4, end
);
7985 /* FIXME: We assume that this means 64-bit DWARF is being used. */
7986 if (length
== 0xffffffff)
7988 SAFE_BYTE_GET_AND_INC (length
, curr
, 8, end
);
7990 debug_str_offsets_hdr_len
= 16;
7995 debug_str_offsets_hdr_len
= 8;
7998 unsigned char *entries_end
;
8001 /* This is probably an old style .debug_str_offset section which
8002 just contains offsets and no header (and the first offset is 0). */
8003 length
= section
->size
;
8004 curr
= section
->start
;
8006 debug_str_offsets_hdr_len
= 0;
8008 printf (_(" Length: %#" PRIx64
"\n"), length
);
8009 printf (_(" Index Offset [String]\n"));
8013 if (length
<= (size_t) (end
- curr
))
8014 entries_end
= curr
+ length
;
8017 warn (_("Section %s is too small %#" PRIx64
"\n"),
8018 section
->name
, section
->size
);
8023 SAFE_BYTE_GET_AND_INC (version
, curr
, 2, entries_end
);
8025 warn (_("Unexpected version number in str_offset header: %#x\n"), version
);
8028 SAFE_BYTE_GET_AND_INC (padding
, curr
, 2, entries_end
);
8030 warn (_("Unexpected value in str_offset header's padding field: %#x\n"), padding
);
8032 printf (_(" Length: %#" PRIx64
"\n"), length
);
8033 printf (_(" Version: %#x\n"), version
);
8034 printf (_(" Index Offset [String]\n"));
8037 for (idx
= 0; curr
< entries_end
; idx
++)
8040 const unsigned char * string
;
8042 if ((size_t) (entries_end
- curr
) < entry_length
)
8043 /* Not enough space to read one entry_length, give up. */
8046 SAFE_BYTE_GET_AND_INC (offset
, curr
, entry_length
, entries_end
);
8048 string
= (const unsigned char *)
8049 fetch_indexed_string (idx
, NULL
, entry_length
, dwo
, debug_str_offsets_hdr_len
);
8051 string
= fetch_indirect_string (offset
);
8053 printf (" %8lu ", idx
);
8054 print_hex (offset
, entry_length
);
8055 printf (" %s\n", string
);
8062 /* Each debug_information[x].range_lists[y] gets this representation for
8063 sorting purposes. */
8067 /* The debug_information[x].range_lists[y] value. */
8068 uint64_t ranges_offset
;
8070 /* Original debug_information to find parameters of the data. */
8071 debug_info
*debug_info_p
;
8074 /* Sort struct range_entry in ascending order of its RANGES_OFFSET. */
8077 range_entry_compar (const void *ap
, const void *bp
)
8079 const struct range_entry
*a_re
= (const struct range_entry
*) ap
;
8080 const struct range_entry
*b_re
= (const struct range_entry
*) bp
;
8081 const uint64_t a
= a_re
->ranges_offset
;
8082 const uint64_t b
= b_re
->ranges_offset
;
8084 return (a
> b
) - (b
> a
);
8088 display_debug_ranges_list (unsigned char * start
,
8089 unsigned char * finish
,
8090 unsigned int pointer_size
,
8092 uint64_t base_address
)
8094 while (start
< finish
)
8099 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
8100 if (start
>= finish
)
8102 SAFE_SIGNED_BYTE_GET_AND_INC (end
, start
, pointer_size
, finish
);
8105 print_hex (offset
, 4);
8107 if (begin
== 0 && end
== 0)
8109 printf (_("<End of list>\n"));
8113 /* Check base address specifiers. */
8114 if (is_max_address (begin
, pointer_size
)
8115 && !is_max_address (end
, pointer_size
))
8118 print_hex (begin
, pointer_size
);
8119 print_hex (end
, pointer_size
);
8120 printf ("(base address)\n");
8124 print_hex (begin
+ base_address
, pointer_size
);
8125 print_hex_ns (end
+ base_address
, pointer_size
);
8128 fputs (_(" (start == end)"), stdout
);
8129 else if (begin
> end
)
8130 fputs (_(" (start > end)"), stdout
);
8136 static unsigned char *
8137 display_debug_rnglists_list (unsigned char * start
,
8138 unsigned char * finish
,
8139 unsigned int pointer_size
,
8141 uint64_t base_address
,
8144 unsigned char *next
= start
;
8148 uint64_t off
= offset
+ (start
- next
);
8149 enum dwarf_range_list_entry rlet
;
8150 /* Initialize it due to a false compiler warning. */
8151 uint64_t begin
= -1, length
, end
= -1;
8153 if (start
>= finish
)
8155 warn (_("Range list starting at offset %#" PRIx64
8156 " is not terminated.\n"), offset
);
8163 SAFE_BYTE_GET_AND_INC (rlet
, start
, 1, finish
);
8167 case DW_RLE_end_of_list
:
8168 printf (_("<End of list>\n"));
8170 case DW_RLE_base_addressx
:
8171 READ_ULEB (base_address
, start
, finish
);
8172 print_hex (base_address
, pointer_size
);
8173 printf (_("(base address index) "));
8174 base_address
= fetch_indexed_addr (base_address
* pointer_size
+ addr_base
,
8176 print_hex (base_address
, pointer_size
);
8177 printf (_("(base address)\n"));
8179 case DW_RLE_startx_endx
:
8180 READ_ULEB (begin
, start
, finish
);
8181 READ_ULEB (end
, start
, finish
);
8182 begin
= fetch_indexed_addr (begin
* pointer_size
+ addr_base
,
8184 end
= fetch_indexed_addr (end
* pointer_size
+ addr_base
,
8187 case DW_RLE_startx_length
:
8188 READ_ULEB (begin
, start
, finish
);
8189 READ_ULEB (length
, start
, finish
);
8190 begin
= fetch_indexed_addr (begin
* pointer_size
+ addr_base
,
8192 end
= begin
+ length
;
8194 case DW_RLE_offset_pair
:
8195 READ_ULEB (begin
, start
, finish
);
8196 READ_ULEB (end
, start
, finish
);
8198 case DW_RLE_base_address
:
8199 SAFE_BYTE_GET_AND_INC (base_address
, start
, pointer_size
, finish
);
8200 print_hex (base_address
, pointer_size
);
8201 printf (_("(base address)\n"));
8203 case DW_RLE_start_end
:
8204 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
8205 SAFE_BYTE_GET_AND_INC (end
, start
, pointer_size
, finish
);
8207 case DW_RLE_start_length
:
8208 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
8209 READ_ULEB (length
, start
, finish
);
8210 end
= begin
+ length
;
8213 error (_("Invalid range list entry type %d\n"), rlet
);
8214 rlet
= DW_RLE_end_of_list
;
8218 if (rlet
== DW_RLE_end_of_list
)
8220 if (rlet
== DW_RLE_base_address
|| rlet
== DW_RLE_base_addressx
)
8223 /* Only a DW_RLE_offset_pair needs the base address added. */
8224 if (rlet
== DW_RLE_offset_pair
)
8226 begin
+= base_address
;
8227 end
+= base_address
;
8230 print_hex (begin
, pointer_size
);
8231 print_hex (end
, pointer_size
);
8234 fputs (_(" (start == end)"), stdout
);
8235 else if (begin
> end
)
8236 fputs (_(" (start > end)"), stdout
);
8245 display_debug_rnglists_unit_header (struct dwarf_section
* section
,
8246 uint64_t * unit_offset
,
8247 unsigned char * poffset_size
)
8249 uint64_t start_offset
= *unit_offset
;
8250 unsigned char * p
= section
->start
+ start_offset
;
8251 unsigned char * finish
= section
->start
+ section
->size
;
8252 uint64_t initial_length
;
8253 unsigned char segment_selector_size
;
8254 unsigned int offset_entry_count
;
8256 unsigned short version
;
8257 unsigned char address_size
= 0;
8258 unsigned char offset_size
;
8260 /* Get and check the length of the block. */
8261 SAFE_BYTE_GET_AND_INC (initial_length
, p
, 4, finish
);
8263 if (initial_length
== 0xffffffff)
8265 /* This section is 64-bit DWARF 3. */
8266 SAFE_BYTE_GET_AND_INC (initial_length
, p
, 8, finish
);
8267 *poffset_size
= offset_size
= 8;
8270 *poffset_size
= offset_size
= 4;
8272 if (initial_length
> (size_t) (finish
- p
))
8274 /* If the length field has a relocation against it, then we should
8275 not complain if it is inaccurate (and probably negative).
8276 It is copied from .debug_line handling code. */
8277 if (reloc_at (section
, (p
- section
->start
) - offset_size
))
8278 initial_length
= finish
- p
;
8281 warn (_("The length field (%#" PRIx64
8282 ") in the debug_rnglists header is wrong"
8283 " - the section is too small\n"),
8289 /* Report the next unit offset to the caller. */
8290 *unit_offset
= (p
- section
->start
) + initial_length
;
8292 /* Get the other fields in the header. */
8293 SAFE_BYTE_GET_AND_INC (version
, p
, 2, finish
);
8294 SAFE_BYTE_GET_AND_INC (address_size
, p
, 1, finish
);
8295 SAFE_BYTE_GET_AND_INC (segment_selector_size
, p
, 1, finish
);
8296 SAFE_BYTE_GET_AND_INC (offset_entry_count
, p
, 4, finish
);
8298 printf (_(" Table at Offset: %#" PRIx64
":\n"), start_offset
);
8299 printf (_(" Length: %#" PRIx64
"\n"), initial_length
);
8300 printf (_(" DWARF version: %u\n"), version
);
8301 printf (_(" Address size: %u\n"), address_size
);
8302 printf (_(" Segment size: %u\n"), segment_selector_size
);
8303 printf (_(" Offset entries: %u\n"), offset_entry_count
);
8305 /* Check the fields. */
8306 if (segment_selector_size
!= 0)
8308 warn (_("The %s section contains "
8309 "unsupported segment selector size: %d.\n"),
8310 section
->name
, segment_selector_size
);
8316 warn (_("Only DWARF version 5+ debug_rnglists info "
8317 "is currently supported.\n"));
8321 if (offset_entry_count
!= 0)
8323 printf (_("\n Offsets starting at %#tx:\n"), p
- section
->start
);
8325 for (i
= 0; i
< offset_entry_count
; i
++)
8329 SAFE_BYTE_GET_AND_INC (entry
, p
, offset_size
, finish
);
8330 printf (_(" [%6u] %#" PRIx64
"\n"), i
, entry
);
8338 is_range_list_for_this_section (bool is_rnglists
, unsigned int version
)
8340 if (is_rnglists
&& version
> 4)
8343 if (! is_rnglists
&& version
< 5)
8350 display_debug_ranges (struct dwarf_section
*section
,
8351 void *file ATTRIBUTE_UNUSED
)
8353 unsigned char *start
= section
->start
;
8354 unsigned char *last_start
= start
;
8355 uint64_t bytes
= section
->size
;
8356 unsigned char *section_begin
= start
;
8357 unsigned char *finish
= start
+ bytes
;
8358 unsigned int num_range_list
, i
;
8359 struct range_entry
*range_entries
;
8360 struct range_entry
*range_entry_fill
;
8361 bool is_rnglists
= strstr (section
->name
, "debug_rnglists") != NULL
;
8362 uint64_t last_offset
= 0;
8363 uint64_t next_rnglists_cu_offset
= 0;
8364 unsigned char offset_size
;
8368 printf (_("\nThe %s section is empty.\n"), section
->name
);
8372 introduce (section
, false);
8374 if (load_debug_info (file
) == 0)
8376 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
8382 for (i
= 0; i
< num_debug_info_entries
; i
++)
8383 if (is_range_list_for_this_section (is_rnglists
, debug_information
[i
].dwarf_version
))
8384 num_range_list
+= debug_information
[i
].num_range_lists
;
8386 if (num_range_list
== 0)
8388 /* This can happen when the file was compiled with -gsplit-debug
8389 which removes references to range lists from the primary .o file. */
8390 printf (_("No range lists referenced by .debug_info section.\n"));
8394 range_entry_fill
= range_entries
= XNEWVEC (struct range_entry
, num_range_list
);
8396 for (i
= 0; i
< num_debug_info_entries
; i
++)
8398 debug_info
*debug_info_p
= &debug_information
[i
];
8401 for (j
= 0; j
< debug_info_p
->num_range_lists
; j
++)
8403 if (is_range_list_for_this_section (is_rnglists
, debug_info_p
->dwarf_version
))
8405 range_entry_fill
->ranges_offset
= debug_info_p
->range_lists
[j
];
8406 range_entry_fill
->debug_info_p
= debug_info_p
;
8412 assert (range_entry_fill
>= range_entries
);
8413 assert (num_range_list
>= (unsigned int)(range_entry_fill
- range_entries
));
8414 num_range_list
= range_entry_fill
- range_entries
;
8415 qsort (range_entries
, num_range_list
, sizeof (*range_entries
),
8416 range_entry_compar
);
8418 if (dwarf_check
!= 0 && range_entries
[0].ranges_offset
!= 0)
8419 warn (_("Range lists in %s section start at %#" PRIx64
"\n"),
8420 section
->name
, range_entries
[0].ranges_offset
);
8424 printf (_(" Offset Begin End\n"));
8426 for (i
= 0; i
< num_range_list
; i
++)
8428 struct range_entry
*range_entry
= &range_entries
[i
];
8429 debug_info
*debug_info_p
= range_entry
->debug_info_p
;
8430 unsigned int pointer_size
;
8432 unsigned char *next
;
8433 uint64_t base_address
;
8435 pointer_size
= debug_info_p
->pointer_size
;
8436 offset
= range_entry
->ranges_offset
;
8437 base_address
= debug_info_p
->base_address
;
8439 /* PR 17512: file: 001-101485-0.001:0.1. */
8440 if (pointer_size
< 2 || pointer_size
> 8)
8442 warn (_("Corrupt pointer size (%d) in debug entry at offset %#" PRIx64
"\n"),
8443 pointer_size
, offset
);
8447 if (offset
> (size_t) (finish
- section_begin
))
8449 warn (_("Corrupt offset (%#" PRIx64
") in range entry %u\n"),
8454 /* If we've moved on to the next compile unit in the rnglists section - dump the unit header(s). */
8455 if (is_rnglists
&& next_rnglists_cu_offset
< offset
)
8457 while (next_rnglists_cu_offset
< offset
)
8458 display_debug_rnglists_unit_header (section
, &next_rnglists_cu_offset
, &offset_size
);
8459 printf (_(" Offset Begin End\n"));
8462 next
= section_begin
+ offset
; /* Offset is from the section start, the base has already been added. */
8464 /* If multiple DWARF entities reference the same range then we will
8465 have multiple entries in the `range_entries' list for the same
8466 offset. Thanks to the sort above these will all be consecutive in
8467 the `range_entries' list, so we can easily ignore duplicates
8469 if (i
> 0 && last_offset
== offset
)
8471 last_offset
= offset
;
8473 if (dwarf_check
!= 0 && i
> 0)
8476 warn (_("There is a hole [%#tx - %#tx] in %s section.\n"),
8477 start
- section_begin
, next
- section_begin
, section
->name
);
8478 else if (start
> next
)
8480 if (next
== last_start
)
8482 warn (_("There is an overlap [%#tx - %#tx] in %s section.\n"),
8483 start
- section_begin
, next
- section_begin
, section
->name
);
8491 display_debug_rnglists_list
8492 (start
, finish
, pointer_size
, offset
, base_address
, debug_info_p
->addr_base
);
8494 display_debug_ranges_list
8495 (start
, finish
, pointer_size
, offset
, base_address
);
8498 /* Display trailing empty (or unreferenced) compile units, if any. */
8500 while (next_rnglists_cu_offset
< section
->size
)
8501 display_debug_rnglists_unit_header (section
, &next_rnglists_cu_offset
, &offset_size
);
8505 free (range_entries
);
8510 typedef struct Frame_Chunk
8512 struct Frame_Chunk
*next
;
8513 unsigned char *chunk_start
;
8515 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
8516 short int *col_type
;
8517 int64_t *col_offset
;
8519 unsigned int code_factor
;
8523 unsigned int cfa_reg
;
8524 uint64_t cfa_offset
;
8526 unsigned char fde_encoding
;
8527 unsigned char cfa_exp
;
8528 unsigned char ptr_size
;
8529 unsigned char segment_size
;
8533 typedef const char *(*dwarf_regname_lookup_ftype
) (unsigned int);
8534 static dwarf_regname_lookup_ftype dwarf_regnames_lookup_func
;
8535 static const char *const *dwarf_regnames
;
8536 static unsigned int dwarf_regnames_count
;
8537 static bool is_aarch64
;
8539 /* A marker for a col_type that means this column was never referenced
8540 in the frame info. */
8541 #define DW_CFA_unreferenced (-1)
8543 /* Return 0 if no more space is needed, 1 if more space is needed,
8544 -1 for invalid reg. */
8547 frame_need_space (Frame_Chunk
*fc
, unsigned int reg
)
8549 unsigned int prev
= fc
->ncols
;
8551 if (reg
< (unsigned int) fc
->ncols
)
8554 if (dwarf_regnames_count
> 0
8555 && reg
> dwarf_regnames_count
)
8558 fc
->ncols
= reg
+ 1;
8559 /* PR 17512: file: 10450-2643-0.004.
8560 If reg == -1 then this can happen... */
8564 /* PR 17512: file: 2844a11d. */
8565 if (fc
->ncols
> 1024 && dwarf_regnames_count
== 0)
8567 error (_("Unfeasibly large register number: %u\n"), reg
);
8569 /* FIXME: 1024 is an arbitrary limit. Increase it if
8570 we ever encounter a valid binary that exceeds it. */
8574 fc
->col_type
= xcrealloc (fc
->col_type
, fc
->ncols
,
8575 sizeof (*fc
->col_type
));
8576 fc
->col_offset
= xcrealloc (fc
->col_offset
, fc
->ncols
,
8577 sizeof (*fc
->col_offset
));
8578 /* PR 17512: file:002-10025-0.005. */
8579 if (fc
->col_type
== NULL
|| fc
->col_offset
== NULL
)
8581 error (_("Out of memory allocating %u columns in dwarf frame arrays\n"),
8587 while (prev
< fc
->ncols
)
8589 fc
->col_type
[prev
] = DW_CFA_unreferenced
;
8590 fc
->col_offset
[prev
] = 0;
8596 static const char *const dwarf_regnames_i386
[] =
8598 "eax", "ecx", "edx", "ebx", /* 0 - 3 */
8599 "esp", "ebp", "esi", "edi", /* 4 - 7 */
8600 "eip", "eflags", NULL
, /* 8 - 10 */
8601 "st0", "st1", "st2", "st3", /* 11 - 14 */
8602 "st4", "st5", "st6", "st7", /* 15 - 18 */
8603 NULL
, NULL
, /* 19 - 20 */
8604 "xmm0", "xmm1", "xmm2", "xmm3", /* 21 - 24 */
8605 "xmm4", "xmm5", "xmm6", "xmm7", /* 25 - 28 */
8606 "mm0", "mm1", "mm2", "mm3", /* 29 - 32 */
8607 "mm4", "mm5", "mm6", "mm7", /* 33 - 36 */
8608 "fcw", "fsw", "mxcsr", /* 37 - 39 */
8609 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
, /* 40 - 47 */
8610 "tr", "ldtr", /* 48 - 49 */
8611 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 50 - 57 */
8612 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 58 - 65 */
8613 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 66 - 73 */
8614 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 74 - 81 */
8615 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 82 - 89 */
8616 NULL
, NULL
, NULL
, /* 90 - 92 */
8617 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7" /* 93 - 100 */
8620 static const char *const dwarf_regnames_iamcu
[] =
8622 "eax", "ecx", "edx", "ebx", /* 0 - 3 */
8623 "esp", "ebp", "esi", "edi", /* 4 - 7 */
8624 "eip", "eflags", NULL
, /* 8 - 10 */
8625 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 11 - 18 */
8626 NULL
, NULL
, /* 19 - 20 */
8627 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 21 - 28 */
8628 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 29 - 36 */
8629 NULL
, NULL
, NULL
, /* 37 - 39 */
8630 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
, /* 40 - 47 */
8631 "tr", "ldtr", /* 48 - 49 */
8632 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 50 - 57 */
8633 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 58 - 65 */
8634 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 66 - 73 */
8635 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 74 - 81 */
8636 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 82 - 89 */
8637 NULL
, NULL
, NULL
, /* 90 - 92 */
8638 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
/* 93 - 100 */
8642 init_dwarf_regnames_i386 (void)
8644 dwarf_regnames
= dwarf_regnames_i386
;
8645 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_i386
);
8646 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8650 init_dwarf_regnames_iamcu (void)
8652 dwarf_regnames
= dwarf_regnames_iamcu
;
8653 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_iamcu
);
8654 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8657 static const char *const DW_CFA_GNU_window_save_name
[] =
8659 "DW_CFA_GNU_window_save",
8660 "DW_CFA_AARCH64_negate_ra_state"
8663 static const char *const dwarf_regnames_x86_64
[] =
8665 "rax", "rdx", "rcx", "rbx",
8666 "rsi", "rdi", "rbp", "rsp",
8667 "r8", "r9", "r10", "r11",
8668 "r12", "r13", "r14", "r15",
8670 "xmm0", "xmm1", "xmm2", "xmm3",
8671 "xmm4", "xmm5", "xmm6", "xmm7",
8672 "xmm8", "xmm9", "xmm10", "xmm11",
8673 "xmm12", "xmm13", "xmm14", "xmm15",
8674 "st0", "st1", "st2", "st3",
8675 "st4", "st5", "st6", "st7",
8676 "mm0", "mm1", "mm2", "mm3",
8677 "mm4", "mm5", "mm6", "mm7",
8679 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
,
8680 "fs.base", "gs.base", NULL
, NULL
,
8682 "mxcsr", "fcw", "fsw",
8683 "xmm16", "xmm17", "xmm18", "xmm19",
8684 "xmm20", "xmm21", "xmm22", "xmm23",
8685 "xmm24", "xmm25", "xmm26", "xmm27",
8686 "xmm28", "xmm29", "xmm30", "xmm31",
8687 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 83 - 90 */
8688 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 91 - 98 */
8689 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 99 - 106 */
8690 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 107 - 114 */
8691 NULL
, NULL
, NULL
, /* 115 - 117 */
8692 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7",
8693 "bnd0", "bnd1", "bnd2", "bnd3",
8697 init_dwarf_regnames_x86_64 (void)
8699 dwarf_regnames
= dwarf_regnames_x86_64
;
8700 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_x86_64
);
8701 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8704 static const char *const dwarf_regnames_aarch64
[] =
8706 "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7",
8707 "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15",
8708 "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23",
8709 "x24", "x25", "x26", "x27", "x28", "x29", "x30", "sp",
8710 NULL
, "elr", NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
8711 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, "vg", "ffr",
8712 "p0", "p1", "p2", "p3", "p4", "p5", "p6", "p7",
8713 "p8", "p9", "p10", "p11", "p12", "p13", "p14", "p15",
8714 "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7",
8715 "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15",
8716 "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23",
8717 "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31",
8718 "z0", "z1", "z2", "z3", "z4", "z5", "z6", "z7",
8719 "z8", "z9", "z10", "z11", "z12", "z13", "z14", "z15",
8720 "z16", "z17", "z18", "z19", "z20", "z21", "z22", "z23",
8721 "z24", "z25", "z26", "z27", "z28", "z29", "z30", "z31",
8725 init_dwarf_regnames_aarch64 (void)
8727 dwarf_regnames
= dwarf_regnames_aarch64
;
8728 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_aarch64
);
8729 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8733 static const char *const dwarf_regnames_s390
[] =
8735 /* Avoid saying "r5 (r5)", so omit the names of r0-r15. */
8736 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
8737 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
8738 "f0", "f2", "f4", "f6", "f1", "f3", "f5", "f7",
8739 "f8", "f10", "f12", "f14", "f9", "f11", "f13", "f15",
8740 "cr0", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7",
8741 "cr8", "cr9", "cr10", "cr11", "cr12", "cr13", "cr14", "cr15",
8742 "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7",
8743 "a8", "a9", "a10", "a11", "a12", "a13", "a14", "a15",
8746 "v16", "v18", "v20", "v22", "v17", "v19", "v21", "v23",
8747 "v24", "v26", "v28", "v30", "v25", "v27", "v29", "v31",
8751 init_dwarf_regnames_s390 (void)
8753 dwarf_regnames
= dwarf_regnames_s390
;
8754 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_s390
);
8755 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8758 static const char *const dwarf_regnames_riscv
[] =
8760 "zero", "ra", "sp", "gp", "tp", "t0", "t1", "t2", /* 0 - 7 */
8761 "s0", "s1", "a0", "a1", "a2", "a3", "a4", "a5", /* 8 - 15 */
8762 "a6", "a7", "s2", "s3", "s4", "s5", "s6", "s7", /* 16 - 23 */
8763 "s8", "s9", "s10", "s11", "t3", "t4", "t5", "t6", /* 24 - 31 */
8764 "ft0", "ft1", "ft2", "ft3", "ft4", "ft5", "ft6", "ft7", /* 32 - 39 */
8765 "fs0", "fs1", /* 40 - 41 */
8766 "fa0", "fa1", "fa2", "fa3", "fa4", "fa5", "fa6", "fa7", /* 42 - 49 */
8767 "fs2", "fs3", "fs4", "fs5", "fs6", "fs7", "fs8", "fs9", /* 50 - 57 */
8768 "fs10", "fs11", /* 58 - 59 */
8769 "ft8", "ft9", "ft10", "ft11", /* 60 - 63 */
8770 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 64 - 71 */
8771 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 72 - 79 */
8772 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 80 - 87 */
8773 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 88 - 95 */
8774 "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", /* 96 - 103 */
8775 "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15", /* 104 - 111 */
8776 "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23", /* 112 - 119 */
8777 "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31", /* 120 - 127 */
8780 /* A RISC-V replacement for REGNAME_INTERNAL_BY_TABLE_ONLY which handles
8781 the large number of CSRs. */
8784 regname_internal_riscv (unsigned int regno
)
8786 const char *name
= NULL
;
8788 /* Lookup in the table first, this covers GPR and FPR. */
8789 if (regno
< ARRAY_SIZE (dwarf_regnames_riscv
))
8790 name
= dwarf_regnames_riscv
[regno
];
8791 else if (regno
>= 4096 && regno
<= 8191)
8793 /* This might be a CSR, these live in a sparse number space from 4096
8794 to 8191 These numbers are defined in the RISC-V ELF ABI
8798 #define DECLARE_CSR(NAME,VALUE,CLASS,DEFINE_VER,ABORT_VER) \
8799 case VALUE + 4096: name = #NAME; break;
8800 #include "opcode/riscv-opc.h"
8805 static char csr_name
[10];
8806 snprintf (csr_name
, sizeof (csr_name
), "csr%d", (regno
- 4096));
8817 init_dwarf_regnames_riscv (void)
8819 dwarf_regnames
= NULL
;
8820 dwarf_regnames_count
= 8192;
8821 dwarf_regnames_lookup_func
= regname_internal_riscv
;
8824 static const char *const dwarf_regnames_loongarch
[] =
8826 "$zero", "$ra", "$tp", "$sp", "$a0", "$a1", "$a2", "$a3", /* 0-7 */
8827 "$a4", "$a5", "$a6", "$a7", "$t0", "$t1", "$t2", "$t3", /* 8-15 */
8828 "$t4", "$t5", "$t6", "$t7", "$t8", "$r21","$fp", "$s0", /* 16-23 */
8829 "$s1", "$s2", "$s3", "$s4", "$s5", "$s6", "$s7", "$s8", /* 24-31 */
8830 "$fa0", "$fa1", "$fa2", "$fa3", "$fa4", "$fa5", "$fa6", /* 32-38 */
8831 "$fa7", "$ft0", "$ft1", "$ft2", "$ft3", "$ft4", "$ft5", /* 39-45 */
8832 "$ft6", "$ft7", "$ft8", "$ft9", "$ft10", "$ft11", "$ft12", /* 46-52 */
8833 "$ft13", "$ft14", "$ft15", "$fs0", "$fs1", "$fs2", "$fs3", /* 53-59 */
8834 "$fs4", "$fs5", "$fs6", "$fs7", /* 60-63 */
8838 init_dwarf_regnames_loongarch (void)
8840 dwarf_regnames
= dwarf_regnames_loongarch
;
8841 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_loongarch
);
8842 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8846 init_dwarf_regnames_by_elf_machine_code (unsigned int e_machine
)
8848 dwarf_regnames_lookup_func
= NULL
;
8854 init_dwarf_regnames_i386 ();
8858 init_dwarf_regnames_iamcu ();
8864 init_dwarf_regnames_x86_64 ();
8868 init_dwarf_regnames_aarch64 ();
8872 init_dwarf_regnames_s390 ();
8876 init_dwarf_regnames_riscv ();
8880 init_dwarf_regnames_loongarch ();
8888 /* Initialize the DWARF register name lookup state based on the
8889 architecture and specific machine type of a BFD. */
8892 init_dwarf_regnames_by_bfd_arch_and_mach (enum bfd_architecture arch
,
8895 dwarf_regnames_lookup_func
= NULL
;
8903 case bfd_mach_x86_64
:
8904 case bfd_mach_x86_64_intel_syntax
:
8905 case bfd_mach_x64_32
:
8906 case bfd_mach_x64_32_intel_syntax
:
8907 init_dwarf_regnames_x86_64 ();
8911 init_dwarf_regnames_i386 ();
8916 case bfd_arch_iamcu
:
8917 init_dwarf_regnames_iamcu ();
8920 case bfd_arch_aarch64
:
8921 init_dwarf_regnames_aarch64();
8925 init_dwarf_regnames_s390 ();
8928 case bfd_arch_riscv
:
8929 init_dwarf_regnames_riscv ();
8932 case bfd_arch_loongarch
:
8933 init_dwarf_regnames_loongarch ();
8942 regname_internal_by_table_only (unsigned int regno
)
8944 if (dwarf_regnames
!= NULL
8945 && regno
< dwarf_regnames_count
8946 && dwarf_regnames
[regno
] != NULL
)
8947 return dwarf_regnames
[regno
];
8953 regname (unsigned int regno
, int name_only_p
)
8955 static char reg
[64];
8957 const char *name
= NULL
;
8959 if (dwarf_regnames_lookup_func
!= NULL
)
8960 name
= dwarf_regnames_lookup_func (regno
);
8966 snprintf (reg
, sizeof (reg
), "r%d (%s)", regno
, name
);
8969 snprintf (reg
, sizeof (reg
), "r%d", regno
);
8974 frame_display_row (Frame_Chunk
*fc
, int *need_col_headers
, unsigned int *max_regs
)
8979 if (*max_regs
!= fc
->ncols
)
8980 *max_regs
= fc
->ncols
;
8982 if (*need_col_headers
)
8984 *need_col_headers
= 0;
8986 printf ("%-*s CFA ", eh_addr_size
* 2, " LOC");
8988 for (r
= 0; r
< *max_regs
; r
++)
8989 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
8994 printf ("%-5s ", regname (r
, 1));
9000 print_hex (fc
->pc_begin
, eh_addr_size
);
9002 strcpy (tmp
, "exp");
9004 sprintf (tmp
, "%s%+d", regname (fc
->cfa_reg
, 1), (int) fc
->cfa_offset
);
9005 printf ("%-8s ", tmp
);
9007 for (r
= 0; r
< fc
->ncols
; r
++)
9009 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
9011 switch (fc
->col_type
[r
])
9013 case DW_CFA_undefined
:
9016 case DW_CFA_same_value
:
9020 sprintf (tmp
, "c%+" PRId64
, fc
->col_offset
[r
]);
9022 case DW_CFA_val_offset
:
9023 sprintf (tmp
, "v%+" PRId64
, fc
->col_offset
[r
]);
9025 case DW_CFA_register
:
9026 sprintf (tmp
, "%s", regname (fc
->col_offset
[r
], 0));
9028 case DW_CFA_expression
:
9029 strcpy (tmp
, "exp");
9031 case DW_CFA_val_expression
:
9032 strcpy (tmp
, "vexp");
9035 strcpy (tmp
, "n/a");
9038 printf ("%-5s ", tmp
);
9044 #define GET(VAR, N) SAFE_BYTE_GET_AND_INC (VAR, start, N, end)
9046 static unsigned char *
9047 read_cie (unsigned char *start
, unsigned char *end
,
9048 Frame_Chunk
**p_cie
, int *p_version
,
9049 uint64_t *p_aug_len
, unsigned char **p_aug
)
9053 unsigned char *augmentation_data
= NULL
;
9054 uint64_t augmentation_data_len
= 0;
9057 /* PR 17512: file: 001-228113-0.004. */
9061 fc
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
9062 memset (fc
, 0, sizeof (Frame_Chunk
));
9064 fc
->col_type
= xmalloc (sizeof (*fc
->col_type
));
9065 fc
->col_offset
= xmalloc (sizeof (*fc
->col_offset
));
9069 fc
->augmentation
= (char *) start
;
9070 /* PR 17512: file: 001-228113-0.004.
9071 Skip past augmentation name, but avoid running off the end of the data. */
9073 if (* start
++ == '\0')
9077 warn (_("No terminator for augmentation name\n"));
9081 if (strcmp (fc
->augmentation
, "eh") == 0)
9083 if (eh_addr_size
> (size_t) (end
- start
))
9085 start
+= eh_addr_size
;
9090 if (2 > (size_t) (end
- start
))
9092 GET (fc
->ptr_size
, 1);
9093 if (fc
->ptr_size
< 1 || fc
->ptr_size
> 8)
9095 warn (_("Invalid pointer size (%d) in CIE data\n"), fc
->ptr_size
);
9099 GET (fc
->segment_size
, 1);
9100 /* PR 17512: file: e99d2804. */
9101 if (fc
->segment_size
> 8 || fc
->segment_size
+ fc
->ptr_size
> 8)
9103 warn (_("Invalid segment size (%d) in CIE data\n"), fc
->segment_size
);
9107 eh_addr_size
= fc
->ptr_size
;
9111 fc
->ptr_size
= eh_addr_size
;
9112 fc
->segment_size
= 0;
9115 READ_ULEB (fc
->code_factor
, start
, end
);
9116 READ_SLEB (fc
->data_factor
, start
, end
);
9127 READ_ULEB (fc
->ra
, start
, end
);
9130 if (fc
->augmentation
[0] == 'z')
9134 READ_ULEB (augmentation_data_len
, start
, end
);
9135 augmentation_data
= start
;
9136 /* PR 17512: file: 11042-2589-0.004. */
9137 if (augmentation_data_len
> (size_t) (end
- start
))
9139 warn (_("Augmentation data too long: %#" PRIx64
9140 ", expected at most %#tx\n"),
9141 augmentation_data_len
, end
- start
);
9144 start
+= augmentation_data_len
;
9147 if (augmentation_data_len
)
9151 unsigned char *qend
;
9153 p
= (unsigned char *) fc
->augmentation
+ 1;
9154 q
= augmentation_data
;
9155 qend
= q
+ augmentation_data_len
;
9157 while (p
< end
&& q
< qend
)
9162 q
+= 1 + size_of_encoded_value (*q
);
9164 fc
->fde_encoding
= *q
++;
9173 /* Note - it is OK if this loop terminates with q < qend.
9174 Padding may have been inserted to align the end of the CIE. */
9179 *p_version
= version
;
9182 *p_aug_len
= augmentation_data_len
;
9183 *p_aug
= augmentation_data
;
9188 free (fc
->col_offset
);
9189 free (fc
->col_type
);
9194 /* Prints out the contents on the DATA array formatted as unsigned bytes.
9195 If do_wide is not enabled, then formats the output to fit into 80 columns.
9196 PRINTED contains the number of characters already written to the current
9200 display_data (size_t printed
, const unsigned char *data
, size_t len
)
9202 if (do_wide
|| len
< ((80 - printed
) / 3))
9203 for (printed
= 0; printed
< len
; ++printed
)
9204 printf (" %02x", data
[printed
]);
9207 for (printed
= 0; printed
< len
; ++printed
)
9209 if (printed
% (80 / 3) == 0)
9211 printf (" %02x", data
[printed
]);
9216 /* Prints out the contents on the augmentation data array.
9217 If do_wide is not enabled, then formats the output to fit into 80 columns. */
9220 display_augmentation_data (const unsigned char * data
, uint64_t len
)
9224 i
= printf (_(" Augmentation data: "));
9225 display_data (i
, data
, len
);
9229 decode_eh_encoding (unsigned int value
)
9231 if (value
== DW_EH_PE_omit
)
9235 switch (value
& 0x0f)
9237 case DW_EH_PE_uleb128
: format
= "uleb128"; break;
9238 case DW_EH_PE_udata2
: format
= "udata2"; break;
9239 case DW_EH_PE_udata4
: format
= "udata4"; break;
9240 case DW_EH_PE_udata8
: format
= "udata8"; break;
9241 case DW_EH_PE_sleb128
: format
= "sleb128"; break;
9242 case DW_EH_PE_sdata2
: format
= "sdata2"; break;
9243 case DW_EH_PE_sdata4
: format
= "sdata4"; break;
9244 case DW_EH_PE_sdata8
: format
= "sdata8"; break;
9246 default: format
= "<unknown format>"; break; /* FIXME: Generate a warning ? */
9250 switch (value
& 0xf0)
9252 case DW_EH_PE_absptr
: application
= "absolute"; break;
9253 case DW_EH_PE_pcrel
: application
= "pcrel"; break;
9254 case DW_EH_PE_textrel
: application
= "textrel"; break; /* FIXME: Is this allowed ? */
9255 case DW_EH_PE_datarel
: application
= "datarel"; break;
9256 case DW_EH_PE_funcrel
: application
= "funcrel"; break; /* FIXME: Is this allowed ? */
9257 case DW_EH_PE_aligned
: application
= "aligned"; break; /* FIXME: Is this allowed ? */
9258 case DW_EH_PE_indirect
: application
= "indirect"; break; /* FIXME: Is this allowed ? */
9260 default: application
= "<unknown application method>"; break; /* FIXME: Generate a warning ? */
9263 static char buffer
[128];
9264 sprintf (buffer
, "%s, %s", format
, application
);
9268 /* Reads a value stored at START encoded according to ENCODING.
9269 Does not read from, or past, END.
9270 Upon success, returns the read value and sets * RETURN_LEN to
9271 the number of bytes read.
9272 Upon failure returns zero and sets * RETURN_LEN to 0.
9274 Note: does not perform any application transformations to the value. */
9277 get_encoded_eh_value (unsigned int encoding
,
9278 unsigned char * start
,
9279 unsigned char * end
,
9280 unsigned int * return_len
)
9285 unsigned char * old_start
;
9287 switch (encoding
& 0x0f)
9289 case DW_EH_PE_uleb128
:
9290 val
= read_leb128 (start
, end
, false, & len
, & status
);
9295 case DW_EH_PE_sleb128
:
9296 val
= read_leb128 (start
, end
, true, & len
, & status
);
9301 case DW_EH_PE_udata2
:
9303 SAFE_BYTE_GET_AND_INC (val
, start
, 2, end
);
9304 len
= start
- old_start
== 2 ? 2 : 0;
9307 case DW_EH_PE_udata4
:
9309 SAFE_BYTE_GET_AND_INC (val
, start
, 4, end
);
9310 len
= start
- old_start
== 4 ? 4 : 0;
9313 case DW_EH_PE_udata8
:
9315 SAFE_BYTE_GET_AND_INC (val
, start
, 8, end
);
9316 len
= start
- old_start
== 8 ? 8 : 0;
9319 case DW_EH_PE_sdata2
:
9321 SAFE_SIGNED_BYTE_GET_AND_INC (val
, start
, 2, end
);
9322 len
= start
- old_start
== 2 ? 2 : 0;
9325 case DW_EH_PE_sdata4
:
9327 SAFE_SIGNED_BYTE_GET_AND_INC (val
, start
, 4, end
);
9328 len
= start
- old_start
== 4 ? 4 : 0;
9331 case DW_EH_PE_sdata8
:
9333 SAFE_SIGNED_BYTE_GET_AND_INC (val
, start
, 8, end
);
9334 len
= start
- old_start
== 8 ? 8 : 0;
9351 encoded_eh_offset (unsigned int encoding
,
9352 struct dwarf_section
* section
,
9353 uint64_t section_offset
,
9356 switch (encoding
& 0xf0)
9359 /* This should not happen. FIXME: warn ? */
9360 case DW_EH_PE_absptr
:
9363 case DW_EH_PE_pcrel
:
9364 return value
+ (uint64_t)(section
->address
+ section_offset
);
9366 case DW_EH_PE_datarel
:
9367 return value
+ (uint64_t)section
->address
;
9372 display_eh_frame_hdr (struct dwarf_section
*section
,
9373 void *file ATTRIBUTE_UNUSED
)
9375 unsigned char *start
= section
->start
;
9376 unsigned char *end
= start
+ section
->size
;
9378 introduce (section
, false);
9380 if (section
->size
< 6)
9382 warn (_(".eh_frame_hdr section is too small\n"));
9386 unsigned int version
= start
[0];
9389 warn (_("Unsupported .eh_frame_hdr version %u\n"), version
);
9393 printf (_(" Version: %u\n"), version
);
9395 unsigned int ptr_enc
= start
[1];
9396 /* Strictly speaking this is the encoding format of the eh_frame_ptr field below. */
9397 printf (_(" Pointer Encoding Format: %#x (%s)\n"), ptr_enc
, decode_eh_encoding (ptr_enc
));
9399 unsigned int count_enc
= start
[2];
9400 printf (_(" Count Encoding Format: %#x (%s)\n"), count_enc
, decode_eh_encoding (count_enc
));
9402 unsigned int table_enc
= start
[3];
9403 printf (_(" Table Encoding Format: %#x (%s)\n"), table_enc
, decode_eh_encoding (table_enc
));
9409 uint64_t eh_frame_ptr
= get_encoded_eh_value (ptr_enc
, start
, end
, & len
);
9412 warn (_("unable to read eh_frame_ptr field in .eh_frame_hdr section\n"));
9415 printf (_(" Start of frame section: %#" PRIx64
), eh_frame_ptr
);
9417 uint64_t offset_eh_frame_ptr
= encoded_eh_offset (ptr_enc
, section
, 4, eh_frame_ptr
);
9418 if (offset_eh_frame_ptr
!= eh_frame_ptr
)
9419 printf (_(" (offset: %#" PRIx64
")"), offset_eh_frame_ptr
);
9424 if (count_enc
== DW_EH_PE_omit
)
9426 warn (_("It is suspicious to have a .eh_frame_hdr section with an empty search table\n"));
9430 if (count_enc
& 0xf0)
9432 warn (_("The count field format should be absolute, not relative to an address\n"));
9436 uint64_t fde_count
= get_encoded_eh_value (count_enc
, start
, end
, & len
);
9439 warn (_("unable to read fde_count field in .eh_frame_hdr section\n"));
9442 printf (_(" Entries in search table: %#" PRIx64
), fde_count
);
9446 if (fde_count
!= 0 && table_enc
== DW_EH_PE_omit
)
9448 warn (_("It is suspicious to have a .eh_frame_hdr section an empty table but a non empty count field\n"));
9453 /* Read and display the search table. */
9454 for (i
= 0; i
< fde_count
; i
++)
9456 uint64_t location
, address
;
9457 unsigned char * row_start
= start
;
9459 location
= get_encoded_eh_value (table_enc
, start
, end
, & len
);
9462 warn (_("Failed to read location field for entry %#" PRIx64
" in the .eh_frame_hdr's search table\n"), i
);
9467 address
= get_encoded_eh_value (table_enc
, start
, end
, & len
);
9470 warn (_("Failed to read address field for entry %#" PRIx64
" in the .eh_frame_hdr's search table\n"), i
);
9475 /* This format is intended to be compatible with the output of eu-readelf's -e option. */
9476 printf (" %#" PRIx64
" (offset: %#" PRIx64
") -> %#" PRIx64
" fde=[ %5" PRIx64
"]\n",
9478 encoded_eh_offset (table_enc
, section
, row_start
- section
->start
, location
),
9480 encoded_eh_offset (table_enc
, section
, row_start
- section
->start
, address
) - offset_eh_frame_ptr
);
9488 display_debug_frames (struct dwarf_section
*section
,
9489 void *file ATTRIBUTE_UNUSED
)
9491 unsigned char *start
= section
->start
;
9492 unsigned char *end
= start
+ section
->size
;
9493 unsigned char *section_start
= start
;
9494 Frame_Chunk
*chunks
= NULL
, *forward_refs
= NULL
;
9495 Frame_Chunk
*remembered_state
= NULL
;
9497 bool is_eh
= strcmp (section
->name
, ".eh_frame") == 0;
9498 unsigned int max_regs
= 0;
9499 const char *bad_reg
= _("bad register: ");
9500 unsigned int saved_eh_addr_size
= eh_addr_size
;
9502 introduce (section
, false);
9506 unsigned char *saved_start
;
9507 unsigned char *block_end
;
9512 int need_col_headers
= 1;
9513 unsigned char *augmentation_data
= NULL
;
9514 uint64_t augmentation_data_len
= 0;
9515 unsigned int encoded_ptr_size
= saved_eh_addr_size
;
9516 unsigned int offset_size
;
9518 static Frame_Chunk fde_fc
;
9520 saved_start
= start
;
9522 SAFE_BYTE_GET_AND_INC (length
, start
, 4, end
);
9526 printf ("\n%08tx ZERO terminator\n\n",
9527 saved_start
- section_start
);
9528 /* Skip any zero terminators that directly follow.
9529 A corrupt section size could have loaded a whole
9530 slew of zero filled memory bytes. eg
9531 PR 17512: file: 070-19381-0.004. */
9532 while (start
< end
&& * start
== 0)
9537 if (length
== 0xffffffff)
9539 SAFE_BYTE_GET_AND_INC (length
, start
, 8, end
);
9545 if (length
> (size_t) (end
- start
))
9547 warn ("Invalid length %#" PRIx64
" in FDE at %#tx\n",
9548 length
, saved_start
- section_start
);
9552 block_end
= start
+ length
;
9554 SAFE_BYTE_GET_AND_INC (cie_id
, start
, offset_size
, block_end
);
9556 if (is_eh
? (cie_id
== 0) : ((offset_size
== 4 && cie_id
== DW_CIE_ID
)
9557 || (offset_size
== 8 && cie_id
== DW64_CIE_ID
)))
9562 start
= read_cie (start
, block_end
, &cie
, &version
,
9563 &augmentation_data_len
, &augmentation_data
);
9564 /* PR 17512: file: 027-135133-0.005. */
9571 fc
->chunk_start
= saved_start
;
9572 mreg
= max_regs
> 0 ? max_regs
- 1 : 0;
9575 if (frame_need_space (fc
, mreg
) < 0)
9577 if (fc
->fde_encoding
)
9578 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
9580 printf ("\n%08tx ", saved_start
- section_start
);
9581 print_hex (length
, fc
->ptr_size
);
9582 print_hex (cie_id
, offset_size
);
9584 if (do_debug_frames_interp
)
9586 printf ("CIE \"%s\" cf=%d df=%d ra=%d\n", fc
->augmentation
,
9587 fc
->code_factor
, fc
->data_factor
, fc
->ra
);
9592 printf (" Version: %d\n", version
);
9593 printf (" Augmentation: \"%s\"\n", fc
->augmentation
);
9596 printf (" Pointer Size: %u\n", fc
->ptr_size
);
9597 printf (" Segment Size: %u\n", fc
->segment_size
);
9599 printf (" Code alignment factor: %u\n", fc
->code_factor
);
9600 printf (" Data alignment factor: %d\n", fc
->data_factor
);
9601 printf (" Return address column: %d\n", fc
->ra
);
9603 if (augmentation_data_len
)
9604 display_augmentation_data (augmentation_data
, augmentation_data_len
);
9611 unsigned char *look_for
;
9612 unsigned long segment_selector
;
9618 uint64_t sign
= (uint64_t) 1 << (offset_size
* 8 - 1);
9619 cie_off
= (cie_off
^ sign
) - sign
;
9620 cie_off
= start
- 4 - section_start
- cie_off
;
9623 look_for
= section_start
+ cie_off
;
9624 if (cie_off
<= (size_t) (saved_start
- section_start
))
9626 for (cie
= chunks
; cie
; cie
= cie
->next
)
9627 if (cie
->chunk_start
== look_for
)
9630 else if (cie_off
>= section
->size
)
9634 for (cie
= forward_refs
; cie
; cie
= cie
->next
)
9635 if (cie
->chunk_start
== look_for
)
9639 unsigned int off_size
;
9640 unsigned char *cie_scan
;
9642 cie_scan
= look_for
;
9644 SAFE_BYTE_GET_AND_INC (length
, cie_scan
, 4, end
);
9645 if (length
== 0xffffffff)
9647 SAFE_BYTE_GET_AND_INC (length
, cie_scan
, 8, end
);
9650 if (length
!= 0 && length
<= (size_t) (end
- cie_scan
))
9653 unsigned char *cie_end
= cie_scan
+ length
;
9655 SAFE_BYTE_GET_AND_INC (c_id
, cie_scan
, off_size
,
9659 : ((off_size
== 4 && c_id
== DW_CIE_ID
)
9660 || (off_size
== 8 && c_id
== DW64_CIE_ID
)))
9665 read_cie (cie_scan
, cie_end
, &cie
, &version
,
9666 &augmentation_data_len
, &augmentation_data
);
9667 /* PR 17512: file: 3450-2098-0.004. */
9670 warn (_("Failed to read CIE information\n"));
9673 cie
->next
= forward_refs
;
9675 cie
->chunk_start
= look_for
;
9676 mreg
= max_regs
> 0 ? max_regs
- 1 : 0;
9679 if (frame_need_space (cie
, mreg
) < 0)
9681 warn (_("Invalid max register\n"));
9684 if (cie
->fde_encoding
)
9686 = size_of_encoded_value (cie
->fde_encoding
);
9693 memset (fc
, 0, sizeof (Frame_Chunk
));
9698 fc
->col_type
= xmalloc (sizeof (*fc
->col_type
));
9699 fc
->col_offset
= xmalloc (sizeof (*fc
->col_offset
));
9700 if (frame_need_space (fc
, max_regs
> 0 ? max_regs
- 1 : 0) < 0)
9702 warn (_("Invalid max register\n"));
9706 fc
->augmentation
= "";
9707 fc
->fde_encoding
= 0;
9708 fc
->ptr_size
= eh_addr_size
;
9709 fc
->segment_size
= 0;
9713 fc
->ncols
= cie
->ncols
;
9714 fc
->col_type
= xcmalloc (fc
->ncols
, sizeof (*fc
->col_type
));
9715 fc
->col_offset
= xcmalloc (fc
->ncols
, sizeof (*fc
->col_offset
));
9716 memcpy (fc
->col_type
, cie
->col_type
,
9717 fc
->ncols
* sizeof (*fc
->col_type
));
9718 memcpy (fc
->col_offset
, cie
->col_offset
,
9719 fc
->ncols
* sizeof (*fc
->col_offset
));
9720 fc
->augmentation
= cie
->augmentation
;
9721 fc
->ptr_size
= cie
->ptr_size
;
9722 eh_addr_size
= cie
->ptr_size
;
9723 fc
->segment_size
= cie
->segment_size
;
9724 fc
->code_factor
= cie
->code_factor
;
9725 fc
->data_factor
= cie
->data_factor
;
9726 fc
->cfa_reg
= cie
->cfa_reg
;
9727 fc
->cfa_offset
= cie
->cfa_offset
;
9729 if (frame_need_space (fc
, max_regs
> 0 ? max_regs
- 1: 0) < 0)
9731 warn (_("Invalid max register\n"));
9734 fc
->fde_encoding
= cie
->fde_encoding
;
9737 if (fc
->fde_encoding
)
9738 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
9740 segment_selector
= 0;
9741 if (fc
->segment_size
)
9743 if (fc
->segment_size
> sizeof (segment_selector
))
9745 /* PR 17512: file: 9e196b3e. */
9746 warn (_("Probably corrupt segment size: %d - using 4 instead\n"), fc
->segment_size
);
9747 fc
->segment_size
= 4;
9749 SAFE_BYTE_GET_AND_INC (segment_selector
, start
,
9750 fc
->segment_size
, block_end
);
9753 fc
->pc_begin
= get_encoded_value (&start
, fc
->fde_encoding
, section
,
9756 /* FIXME: It appears that sometimes the final pc_range value is
9757 encoded in less than encoded_ptr_size bytes. See the x86_64
9758 run of the "objcopy on compressed debug sections" test for an
9760 SAFE_BYTE_GET_AND_INC (fc
->pc_range
, start
, encoded_ptr_size
,
9763 if (cie
->augmentation
[0] == 'z')
9765 READ_ULEB (augmentation_data_len
, start
, block_end
);
9766 augmentation_data
= start
;
9767 /* PR 17512 file: 722-8446-0.004 and PR 22386. */
9768 if (augmentation_data_len
> (size_t) (block_end
- start
))
9770 warn (_("Augmentation data too long: %#" PRIx64
", "
9771 "expected at most %#tx\n"),
9772 augmentation_data_len
, block_end
- start
);
9774 augmentation_data
= NULL
;
9775 augmentation_data_len
= 0;
9777 start
+= augmentation_data_len
;
9780 printf ("\n%08tx ", saved_start
- section_start
);
9781 print_hex (length
, fc
->ptr_size
);
9782 print_hex (cie_id
, offset_size
);
9785 if (cie
->chunk_start
)
9786 printf ("cie=%08tx", cie
->chunk_start
- section_start
);
9788 /* Ideally translate "invalid " to 8 chars, trailing space
9790 printf (_("cie=invalid "));
9793 if (fc
->segment_size
)
9794 printf ("%04lx:", segment_selector
);
9796 print_hex_ns (fc
->pc_begin
, fc
->ptr_size
);
9798 print_hex_ns (fc
->pc_begin
+ fc
->pc_range
, fc
->ptr_size
);
9801 if (! do_debug_frames_interp
&& augmentation_data_len
)
9803 display_augmentation_data (augmentation_data
, augmentation_data_len
);
9808 /* At this point, fc is the current chunk, cie (if any) is set, and
9809 we're about to interpret instructions for the chunk. */
9810 /* ??? At present we need to do this always, since this sizes the
9811 fc->col_type and fc->col_offset arrays, which we write into always.
9812 We should probably split the interpreted and non-interpreted bits
9813 into two different routines, since there's so much that doesn't
9814 really overlap between them. */
9815 if (1 || do_debug_frames_interp
)
9817 /* Start by making a pass over the chunk, allocating storage
9818 and taking note of what registers are used. */
9819 unsigned char *tmp
= start
;
9821 while (start
< block_end
)
9823 unsigned int reg
, op
, opa
;
9831 /* Warning: if you add any more cases to this switch, be
9832 sure to add them to the corresponding switch below. */
9836 case DW_CFA_advance_loc
:
9839 SKIP_ULEB (start
, block_end
);
9842 case DW_CFA_restore
:
9845 case DW_CFA_set_loc
:
9846 if ((size_t) (block_end
- start
) < encoded_ptr_size
)
9849 start
+= encoded_ptr_size
;
9851 case DW_CFA_advance_loc1
:
9852 if ((size_t) (block_end
- start
) < 1)
9857 case DW_CFA_advance_loc2
:
9858 if ((size_t) (block_end
- start
) < 2)
9863 case DW_CFA_advance_loc4
:
9864 if ((size_t) (block_end
- start
) < 4)
9869 case DW_CFA_offset_extended
:
9870 case DW_CFA_val_offset
:
9871 READ_ULEB (reg
, start
, block_end
);
9872 SKIP_ULEB (start
, block_end
);
9874 case DW_CFA_restore_extended
:
9875 READ_ULEB (reg
, start
, block_end
);
9877 case DW_CFA_undefined
:
9878 READ_ULEB (reg
, start
, block_end
);
9880 case DW_CFA_same_value
:
9881 READ_ULEB (reg
, start
, block_end
);
9883 case DW_CFA_register
:
9884 READ_ULEB (reg
, start
, block_end
);
9885 SKIP_ULEB (start
, block_end
);
9887 case DW_CFA_def_cfa
:
9888 SKIP_ULEB (start
, block_end
);
9889 SKIP_ULEB (start
, block_end
);
9891 case DW_CFA_def_cfa_register
:
9892 SKIP_ULEB (start
, block_end
);
9894 case DW_CFA_def_cfa_offset
:
9895 SKIP_ULEB (start
, block_end
);
9897 case DW_CFA_def_cfa_expression
:
9898 READ_ULEB (temp
, start
, block_end
);
9899 if ((size_t) (block_end
- start
) < temp
)
9904 case DW_CFA_expression
:
9905 case DW_CFA_val_expression
:
9906 READ_ULEB (reg
, start
, block_end
);
9907 READ_ULEB (temp
, start
, block_end
);
9908 if ((size_t) (block_end
- start
) < temp
)
9913 case DW_CFA_offset_extended_sf
:
9914 case DW_CFA_val_offset_sf
:
9915 READ_ULEB (reg
, start
, block_end
);
9916 SKIP_SLEB (start
, block_end
);
9918 case DW_CFA_def_cfa_sf
:
9919 SKIP_ULEB (start
, block_end
);
9920 SKIP_SLEB (start
, block_end
);
9922 case DW_CFA_def_cfa_offset_sf
:
9923 SKIP_SLEB (start
, block_end
);
9925 case DW_CFA_MIPS_advance_loc8
:
9926 if ((size_t) (block_end
- start
) < 8)
9931 case DW_CFA_GNU_args_size
:
9932 SKIP_ULEB (start
, block_end
);
9934 case DW_CFA_GNU_negative_offset_extended
:
9935 READ_ULEB (reg
, start
, block_end
);
9936 SKIP_ULEB (start
, block_end
);
9941 if (reg
!= -1u && frame_need_space (fc
, reg
) >= 0)
9943 /* Don't leave any reg as DW_CFA_unreferenced so
9944 that frame_display_row prints name of regs in
9945 header, and all referenced regs in each line. */
9946 if (reg
>= cie
->ncols
9947 || cie
->col_type
[reg
] == DW_CFA_unreferenced
)
9948 fc
->col_type
[reg
] = DW_CFA_undefined
;
9950 fc
->col_type
[reg
] = cie
->col_type
[reg
];
9958 /* Now we know what registers are used, make a second pass over
9959 the chunk, this time actually printing out the info. */
9961 while (start
< block_end
)
9964 /* Note: It is tempting to use an unsigned long for 'reg' but there
9965 are various functions, notably frame_space_needed() that assume that
9966 reg is an unsigned int. */
9970 const char *reg_prefix
= "";
9977 /* Make a note if something other than DW_CFA_nop happens. */
9978 if (op
!= DW_CFA_nop
)
9981 /* Warning: if you add any more cases to this switch, be
9982 sure to add them to the corresponding switch above. */
9985 case DW_CFA_advance_loc
:
9986 opa
*= fc
->code_factor
;
9987 if (do_debug_frames_interp
)
9988 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9991 printf (" DW_CFA_advance_loc: %d to ", opa
);
9992 print_hex_ns (fc
->pc_begin
+ opa
, fc
->ptr_size
);
9995 fc
->pc_begin
+= opa
;
9999 READ_ULEB (ofs
, start
, block_end
);
10000 ofs
*= fc
->data_factor
;
10001 if (opa
>= fc
->ncols
)
10002 reg_prefix
= bad_reg
;
10003 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
10004 printf (" DW_CFA_offset: %s%s at cfa%+" PRId64
"\n",
10005 reg_prefix
, regname (opa
, 0), ofs
);
10006 if (*reg_prefix
== '\0')
10008 fc
->col_type
[opa
] = DW_CFA_offset
;
10009 fc
->col_offset
[opa
] = ofs
;
10013 case DW_CFA_restore
:
10014 if (opa
>= fc
->ncols
)
10015 reg_prefix
= bad_reg
;
10016 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
10017 printf (" DW_CFA_restore: %s%s\n",
10018 reg_prefix
, regname (opa
, 0));
10019 if (*reg_prefix
!= '\0')
10022 if (opa
>= cie
->ncols
10023 || cie
->col_type
[opa
] == DW_CFA_unreferenced
)
10025 fc
->col_type
[opa
] = DW_CFA_undefined
;
10026 fc
->col_offset
[opa
] = 0;
10030 fc
->col_type
[opa
] = cie
->col_type
[opa
];
10031 fc
->col_offset
[opa
] = cie
->col_offset
[opa
];
10035 case DW_CFA_set_loc
:
10036 ofs
= get_encoded_value (&start
, fc
->fde_encoding
, section
,
10038 if (do_debug_frames_interp
)
10039 frame_display_row (fc
, &need_col_headers
, &max_regs
);
10042 printf (" DW_CFA_set_loc: ");
10043 print_hex_ns (ofs
, fc
->ptr_size
);
10046 fc
->pc_begin
= ofs
;
10049 case DW_CFA_advance_loc1
:
10050 SAFE_BYTE_GET_AND_INC (ofs
, start
, 1, block_end
);
10051 ofs
*= fc
->code_factor
;
10052 if (do_debug_frames_interp
)
10053 frame_display_row (fc
, &need_col_headers
, &max_regs
);
10056 printf (" DW_CFA_advance_loc1: %" PRId64
" to ", ofs
);
10057 print_hex_ns (fc
->pc_begin
+ ofs
, fc
->ptr_size
);
10060 fc
->pc_begin
+= ofs
;
10063 case DW_CFA_advance_loc2
:
10064 SAFE_BYTE_GET_AND_INC (ofs
, start
, 2, block_end
);
10065 ofs
*= fc
->code_factor
;
10066 if (do_debug_frames_interp
)
10067 frame_display_row (fc
, &need_col_headers
, &max_regs
);
10070 printf (" DW_CFA_advance_loc2: %" PRId64
" to ", ofs
);
10071 print_hex_ns (fc
->pc_begin
+ ofs
, fc
->ptr_size
);
10074 fc
->pc_begin
+= ofs
;
10077 case DW_CFA_advance_loc4
:
10078 SAFE_BYTE_GET_AND_INC (ofs
, start
, 4, block_end
);
10079 ofs
*= fc
->code_factor
;
10080 if (do_debug_frames_interp
)
10081 frame_display_row (fc
, &need_col_headers
, &max_regs
);
10084 printf (" DW_CFA_advance_loc4: %" PRId64
" to ", ofs
);
10085 print_hex_ns (fc
->pc_begin
+ ofs
, fc
->ptr_size
);
10088 fc
->pc_begin
+= ofs
;
10091 case DW_CFA_offset_extended
:
10092 READ_ULEB (reg
, start
, block_end
);
10093 READ_ULEB (ofs
, start
, block_end
);
10094 ofs
*= fc
->data_factor
;
10095 if (reg
>= fc
->ncols
)
10096 reg_prefix
= bad_reg
;
10097 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
10098 printf (" DW_CFA_offset_extended: %s%s at cfa%+" PRId64
"\n",
10099 reg_prefix
, regname (reg
, 0), ofs
);
10100 if (*reg_prefix
== '\0')
10102 fc
->col_type
[reg
] = DW_CFA_offset
;
10103 fc
->col_offset
[reg
] = ofs
;
10107 case DW_CFA_val_offset
:
10108 READ_ULEB (reg
, start
, block_end
);
10109 READ_ULEB (ofs
, start
, block_end
);
10110 ofs
*= fc
->data_factor
;
10111 if (reg
>= fc
->ncols
)
10112 reg_prefix
= bad_reg
;
10113 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
10114 printf (" DW_CFA_val_offset: %s%s is cfa%+" PRId64
"\n",
10115 reg_prefix
, regname (reg
, 0), ofs
);
10116 if (*reg_prefix
== '\0')
10118 fc
->col_type
[reg
] = DW_CFA_val_offset
;
10119 fc
->col_offset
[reg
] = ofs
;
10123 case DW_CFA_restore_extended
:
10124 READ_ULEB (reg
, start
, block_end
);
10125 if (reg
>= fc
->ncols
)
10126 reg_prefix
= bad_reg
;
10127 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
10128 printf (" DW_CFA_restore_extended: %s%s\n",
10129 reg_prefix
, regname (reg
, 0));
10130 if (*reg_prefix
!= '\0')
10133 if (reg
>= cie
->ncols
10134 || cie
->col_type
[reg
] == DW_CFA_unreferenced
)
10136 fc
->col_type
[reg
] = DW_CFA_undefined
;
10137 fc
->col_offset
[reg
] = 0;
10141 fc
->col_type
[reg
] = cie
->col_type
[reg
];
10142 fc
->col_offset
[reg
] = cie
->col_offset
[reg
];
10146 case DW_CFA_undefined
:
10147 READ_ULEB (reg
, start
, block_end
);
10148 if (reg
>= fc
->ncols
)
10149 reg_prefix
= bad_reg
;
10150 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
10151 printf (" DW_CFA_undefined: %s%s\n",
10152 reg_prefix
, regname (reg
, 0));
10153 if (*reg_prefix
== '\0')
10155 fc
->col_type
[reg
] = DW_CFA_undefined
;
10156 fc
->col_offset
[reg
] = 0;
10160 case DW_CFA_same_value
:
10161 READ_ULEB (reg
, start
, block_end
);
10162 if (reg
>= fc
->ncols
)
10163 reg_prefix
= bad_reg
;
10164 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
10165 printf (" DW_CFA_same_value: %s%s\n",
10166 reg_prefix
, regname (reg
, 0));
10167 if (*reg_prefix
== '\0')
10169 fc
->col_type
[reg
] = DW_CFA_same_value
;
10170 fc
->col_offset
[reg
] = 0;
10174 case DW_CFA_register
:
10175 READ_ULEB (reg
, start
, block_end
);
10176 READ_ULEB (ofs
, start
, block_end
);
10177 if (reg
>= fc
->ncols
)
10178 reg_prefix
= bad_reg
;
10179 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
10181 printf (" DW_CFA_register: %s%s in ",
10182 reg_prefix
, regname (reg
, 0));
10183 puts (regname (ofs
, 0));
10185 if (*reg_prefix
== '\0')
10187 fc
->col_type
[reg
] = DW_CFA_register
;
10188 fc
->col_offset
[reg
] = ofs
;
10192 case DW_CFA_remember_state
:
10193 if (! do_debug_frames_interp
)
10194 printf (" DW_CFA_remember_state\n");
10195 rs
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
10196 rs
->cfa_offset
= fc
->cfa_offset
;
10197 rs
->cfa_reg
= fc
->cfa_reg
;
10199 rs
->cfa_exp
= fc
->cfa_exp
;
10200 rs
->ncols
= fc
->ncols
;
10201 rs
->col_type
= xcmalloc (rs
->ncols
, sizeof (*rs
->col_type
));
10202 rs
->col_offset
= xcmalloc (rs
->ncols
, sizeof (*rs
->col_offset
));
10203 memcpy (rs
->col_type
, fc
->col_type
,
10204 rs
->ncols
* sizeof (*fc
->col_type
));
10205 memcpy (rs
->col_offset
, fc
->col_offset
,
10206 rs
->ncols
* sizeof (*fc
->col_offset
));
10207 rs
->next
= remembered_state
;
10208 remembered_state
= rs
;
10211 case DW_CFA_restore_state
:
10212 if (! do_debug_frames_interp
)
10213 printf (" DW_CFA_restore_state\n");
10214 rs
= remembered_state
;
10217 remembered_state
= rs
->next
;
10218 fc
->cfa_offset
= rs
->cfa_offset
;
10219 fc
->cfa_reg
= rs
->cfa_reg
;
10221 fc
->cfa_exp
= rs
->cfa_exp
;
10222 if (frame_need_space (fc
, rs
->ncols
- 1) < 0)
10224 warn (_("Invalid column number in saved frame state\n"));
10229 memcpy (fc
->col_type
, rs
->col_type
,
10230 rs
->ncols
* sizeof (*rs
->col_type
));
10231 memcpy (fc
->col_offset
, rs
->col_offset
,
10232 rs
->ncols
* sizeof (*rs
->col_offset
));
10234 free (rs
->col_type
);
10235 free (rs
->col_offset
);
10238 else if (do_debug_frames_interp
)
10239 printf ("Mismatched DW_CFA_restore_state\n");
10242 case DW_CFA_def_cfa
:
10243 READ_ULEB (fc
->cfa_reg
, start
, block_end
);
10244 READ_ULEB (fc
->cfa_offset
, start
, block_end
);
10246 if (! do_debug_frames_interp
)
10247 printf (" DW_CFA_def_cfa: %s ofs %d\n",
10248 regname (fc
->cfa_reg
, 0), (int) fc
->cfa_offset
);
10251 case DW_CFA_def_cfa_register
:
10252 READ_ULEB (fc
->cfa_reg
, start
, block_end
);
10254 if (! do_debug_frames_interp
)
10255 printf (" DW_CFA_def_cfa_register: %s\n",
10256 regname (fc
->cfa_reg
, 0));
10259 case DW_CFA_def_cfa_offset
:
10260 READ_ULEB (fc
->cfa_offset
, start
, block_end
);
10261 if (! do_debug_frames_interp
)
10262 printf (" DW_CFA_def_cfa_offset: %d\n", (int) fc
->cfa_offset
);
10266 if (! do_debug_frames_interp
)
10267 printf (" DW_CFA_nop\n");
10270 case DW_CFA_def_cfa_expression
:
10271 READ_ULEB (ofs
, start
, block_end
);
10272 if (ofs
> (size_t) (block_end
- start
))
10274 printf (_(" %s: <corrupt len %" PRIu64
">\n"),
10275 "DW_CFA_def_cfa_expression", ofs
);
10278 if (! do_debug_frames_interp
)
10280 printf (" DW_CFA_def_cfa_expression (");
10281 decode_location_expression (start
, eh_addr_size
, 0, -1,
10289 case DW_CFA_expression
:
10290 READ_ULEB (reg
, start
, block_end
);
10291 READ_ULEB (ofs
, start
, block_end
);
10292 if (reg
>= fc
->ncols
)
10293 reg_prefix
= bad_reg
;
10294 /* PR 17512: file: 069-133014-0.006. */
10295 /* PR 17512: file: 98c02eb4. */
10296 if (ofs
> (size_t) (block_end
- start
))
10298 printf (_(" %s: <corrupt len %" PRIu64
">\n"),
10299 "DW_CFA_expression", ofs
);
10302 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
10304 printf (" DW_CFA_expression: %s%s (",
10305 reg_prefix
, regname (reg
, 0));
10306 decode_location_expression (start
, eh_addr_size
, 0, -1,
10310 if (*reg_prefix
== '\0')
10311 fc
->col_type
[reg
] = DW_CFA_expression
;
10315 case DW_CFA_val_expression
:
10316 READ_ULEB (reg
, start
, block_end
);
10317 READ_ULEB (ofs
, start
, block_end
);
10318 if (reg
>= fc
->ncols
)
10319 reg_prefix
= bad_reg
;
10320 if (ofs
> (size_t) (block_end
- start
))
10322 printf (" %s: <corrupt len %" PRIu64
">\n",
10323 "DW_CFA_val_expression", ofs
);
10326 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
10328 printf (" DW_CFA_val_expression: %s%s (",
10329 reg_prefix
, regname (reg
, 0));
10330 decode_location_expression (start
, eh_addr_size
, 0, -1,
10334 if (*reg_prefix
== '\0')
10335 fc
->col_type
[reg
] = DW_CFA_val_expression
;
10339 case DW_CFA_offset_extended_sf
:
10340 READ_ULEB (reg
, start
, block_end
);
10341 READ_SLEB (sofs
, start
, block_end
);
10342 /* data_factor multiplicaton done here as unsigned to
10343 avoid integer overflow warnings from asan on fuzzed
10346 ofs
*= fc
->data_factor
;
10347 if (reg
>= fc
->ncols
)
10348 reg_prefix
= bad_reg
;
10349 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
10350 printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+" PRId64
"\n",
10351 reg_prefix
, regname (reg
, 0), ofs
);
10352 if (*reg_prefix
== '\0')
10354 fc
->col_type
[reg
] = DW_CFA_offset
;
10355 fc
->col_offset
[reg
] = ofs
;
10359 case DW_CFA_val_offset_sf
:
10360 READ_ULEB (reg
, start
, block_end
);
10361 READ_SLEB (sofs
, start
, block_end
);
10363 ofs
*= fc
->data_factor
;
10364 if (reg
>= fc
->ncols
)
10365 reg_prefix
= bad_reg
;
10366 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
10367 printf (" DW_CFA_val_offset_sf: %s%s is cfa%+" PRId64
"\n",
10368 reg_prefix
, regname (reg
, 0), ofs
);
10369 if (*reg_prefix
== '\0')
10371 fc
->col_type
[reg
] = DW_CFA_val_offset
;
10372 fc
->col_offset
[reg
] = ofs
;
10376 case DW_CFA_def_cfa_sf
:
10377 READ_ULEB (fc
->cfa_reg
, start
, block_end
);
10378 READ_SLEB (sofs
, start
, block_end
);
10380 ofs
*= fc
->data_factor
;
10381 fc
->cfa_offset
= ofs
;
10383 if (! do_debug_frames_interp
)
10384 printf (" DW_CFA_def_cfa_sf: %s ofs %" PRId64
"\n",
10385 regname (fc
->cfa_reg
, 0), ofs
);
10388 case DW_CFA_def_cfa_offset_sf
:
10389 READ_SLEB (sofs
, start
, block_end
);
10391 ofs
*= fc
->data_factor
;
10392 fc
->cfa_offset
= ofs
;
10393 if (! do_debug_frames_interp
)
10394 printf (" DW_CFA_def_cfa_offset_sf: %" PRId64
"\n", ofs
);
10397 case DW_CFA_MIPS_advance_loc8
:
10398 SAFE_BYTE_GET_AND_INC (ofs
, start
, 8, block_end
);
10399 ofs
*= fc
->code_factor
;
10400 if (do_debug_frames_interp
)
10401 frame_display_row (fc
, &need_col_headers
, &max_regs
);
10404 printf (" DW_CFA_MIPS_advance_loc8: %" PRId64
" to ", ofs
);
10405 print_hex_ns (fc
->pc_begin
+ ofs
, fc
->ptr_size
);
10408 fc
->pc_begin
+= ofs
;
10411 case DW_CFA_GNU_window_save
:
10412 if (! do_debug_frames_interp
)
10413 printf (" %s\n", DW_CFA_GNU_window_save_name
[is_aarch64
]);
10416 case DW_CFA_GNU_args_size
:
10417 READ_ULEB (ofs
, start
, block_end
);
10418 if (! do_debug_frames_interp
)
10419 printf (" DW_CFA_GNU_args_size: %" PRIu64
"\n", ofs
);
10422 case DW_CFA_GNU_negative_offset_extended
:
10423 READ_ULEB (reg
, start
, block_end
);
10424 READ_SLEB (sofs
, start
, block_end
);
10426 ofs
= -ofs
* fc
->data_factor
;
10427 if (reg
>= fc
->ncols
)
10428 reg_prefix
= bad_reg
;
10429 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
10430 printf (" DW_CFA_GNU_negative_offset_extended: %s%s "
10431 "at cfa%+" PRId64
"\n",
10432 reg_prefix
, regname (reg
, 0), ofs
);
10433 if (*reg_prefix
== '\0')
10435 fc
->col_type
[reg
] = DW_CFA_offset
;
10436 fc
->col_offset
[reg
] = ofs
;
10441 if (op
>= DW_CFA_lo_user
&& op
<= DW_CFA_hi_user
)
10442 printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op
);
10444 warn (_("Unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op
);
10449 /* Interpret the CFA - as long as it is not completely full of NOPs. */
10450 if (do_debug_frames_interp
&& ! all_nops
)
10451 frame_display_row (fc
, &need_col_headers
, &max_regs
);
10453 if (fde_fc
.col_type
!= NULL
)
10455 free (fde_fc
.col_type
);
10456 fde_fc
.col_type
= NULL
;
10458 if (fde_fc
.col_offset
!= NULL
)
10460 free (fde_fc
.col_offset
);
10461 fde_fc
.col_offset
= NULL
;
10465 eh_addr_size
= saved_eh_addr_size
;
10470 while (remembered_state
!= NULL
)
10472 rs
= remembered_state
;
10473 remembered_state
= rs
->next
;
10474 free (rs
->col_type
);
10475 free (rs
->col_offset
);
10476 rs
->next
= NULL
; /* Paranoia. */
10480 while (chunks
!= NULL
)
10484 free (rs
->col_type
);
10485 free (rs
->col_offset
);
10486 rs
->next
= NULL
; /* Paranoia. */
10490 while (forward_refs
!= NULL
)
10493 forward_refs
= rs
->next
;
10494 free (rs
->col_type
);
10495 free (rs
->col_offset
);
10496 rs
->next
= NULL
; /* Paranoia. */
10506 display_debug_names (struct dwarf_section
*section
, void *file
)
10508 unsigned char *hdrptr
= section
->start
;
10509 uint64_t unit_length
;
10510 unsigned char *unit_start
;
10511 const unsigned char *const section_end
= section
->start
+ section
->size
;
10512 unsigned char *unit_end
;
10514 introduce (section
, false);
10516 load_debug_section_with_follow (str
, file
);
10518 for (; hdrptr
< section_end
; hdrptr
= unit_end
)
10520 unsigned int offset_size
;
10521 uint16_t dwarf_version
, padding
;
10522 uint32_t comp_unit_count
, local_type_unit_count
, foreign_type_unit_count
;
10523 uint64_t bucket_count
, name_count
, abbrev_table_size
;
10524 uint32_t augmentation_string_size
;
10526 bool augmentation_printable
;
10527 const char *augmentation_string
;
10530 unit_start
= hdrptr
;
10532 /* Get and check the length of the block. */
10533 SAFE_BYTE_GET_AND_INC (unit_length
, hdrptr
, 4, section_end
);
10535 if (unit_length
== 0xffffffff)
10537 /* This section is 64-bit DWARF. */
10538 SAFE_BYTE_GET_AND_INC (unit_length
, hdrptr
, 8, section_end
);
10544 if (unit_length
> (size_t) (section_end
- hdrptr
)
10545 || unit_length
< 2 + 2 + 4 * 7)
10548 warn (_("Debug info is corrupted, %s header at %#tx"
10549 " has length %#" PRIx64
"\n"),
10550 section
->name
, unit_start
- section
->start
, unit_length
);
10553 unit_end
= hdrptr
+ unit_length
;
10555 /* Get and check the version number. */
10556 SAFE_BYTE_GET_AND_INC (dwarf_version
, hdrptr
, 2, unit_end
);
10557 printf (_("Version %d\n"), (int) dwarf_version
);
10559 /* Prior versions did not exist, and future versions may not be
10560 backwards compatible. */
10561 if (dwarf_version
!= 5)
10563 warn (_("Only DWARF version 5 .debug_names "
10564 "is currently supported.\n"));
10568 SAFE_BYTE_GET_AND_INC (padding
, hdrptr
, 2, unit_end
);
10570 warn (_("Padding field of .debug_names must be 0 (found 0x%x)\n"),
10573 SAFE_BYTE_GET_AND_INC (comp_unit_count
, hdrptr
, 4, unit_end
);
10574 if (comp_unit_count
== 0)
10575 warn (_("Compilation unit count must be >= 1 in .debug_names\n"));
10577 SAFE_BYTE_GET_AND_INC (local_type_unit_count
, hdrptr
, 4, unit_end
);
10578 SAFE_BYTE_GET_AND_INC (foreign_type_unit_count
, hdrptr
, 4, unit_end
);
10579 SAFE_BYTE_GET_AND_INC (bucket_count
, hdrptr
, 4, unit_end
);
10580 SAFE_BYTE_GET_AND_INC (name_count
, hdrptr
, 4, unit_end
);
10581 SAFE_BYTE_GET_AND_INC (abbrev_table_size
, hdrptr
, 4, unit_end
);
10583 SAFE_BYTE_GET_AND_INC (augmentation_string_size
, hdrptr
, 4, unit_end
);
10584 if (augmentation_string_size
% 4 != 0)
10586 warn (_("Augmentation string length %u must be rounded up "
10587 "to a multiple of 4 in .debug_names.\n"),
10588 augmentation_string_size
);
10589 augmentation_string_size
+= (-augmentation_string_size
) & 3;
10591 if (augmentation_string_size
> (size_t) (unit_end
- hdrptr
))
10594 printf (_("Augmentation string:"));
10596 augmentation_printable
= true;
10597 augmentation_string
= (const char *) hdrptr
;
10599 for (i
= 0; i
< augmentation_string_size
; i
++)
10603 SAFE_BYTE_GET_AND_INC (uc
, hdrptr
, 1, unit_end
);
10604 printf (" %02x", uc
);
10606 if (uc
!= 0 && !ISPRINT (uc
))
10607 augmentation_printable
= false;
10610 if (augmentation_printable
)
10614 i
< augmentation_string_size
&& augmentation_string
[i
];
10616 putchar (augmentation_string
[i
]);
10621 printf (_("CU table:\n"));
10622 if (_mul_overflow (comp_unit_count
, offset_size
, &total
)
10623 || total
> (size_t) (unit_end
- hdrptr
))
10625 for (i
= 0; i
< comp_unit_count
; i
++)
10627 uint64_t cu_offset
;
10629 SAFE_BYTE_GET_AND_INC (cu_offset
, hdrptr
, offset_size
, unit_end
);
10630 printf ("[%3u] %#" PRIx64
"\n", i
, cu_offset
);
10634 printf (_("TU table:\n"));
10635 if (_mul_overflow (local_type_unit_count
, offset_size
, &total
)
10636 || total
> (size_t) (unit_end
- hdrptr
))
10638 for (i
= 0; i
< local_type_unit_count
; i
++)
10640 uint64_t tu_offset
;
10642 SAFE_BYTE_GET_AND_INC (tu_offset
, hdrptr
, offset_size
, unit_end
);
10643 printf ("[%3u] %#" PRIx64
"\n", i
, tu_offset
);
10647 printf (_("Foreign TU table:\n"));
10648 if (_mul_overflow (foreign_type_unit_count
, 8, &total
)
10649 || total
> (size_t) (unit_end
- hdrptr
))
10651 for (i
= 0; i
< foreign_type_unit_count
; i
++)
10653 uint64_t signature
;
10655 SAFE_BYTE_GET_AND_INC (signature
, hdrptr
, 8, unit_end
);
10656 printf (_("[%3u] "), i
);
10657 print_hex_ns (signature
, 8);
10662 uint64_t xtra
= (bucket_count
* sizeof (uint32_t)
10663 + name_count
* (sizeof (uint32_t) + 2 * offset_size
)
10664 + abbrev_table_size
);
10665 if (xtra
> (size_t) (unit_end
- hdrptr
))
10667 warn (_("Entry pool offset (%#" PRIx64
") exceeds unit size %#tx "
10668 "for unit %#tx in the debug_names\n"),
10669 xtra
, unit_end
- unit_start
, unit_start
- section
->start
);
10672 const uint32_t *const hash_table_buckets
= (uint32_t *) hdrptr
;
10673 hdrptr
+= bucket_count
* sizeof (uint32_t);
10674 const uint32_t *const hash_table_hashes
= (uint32_t *) hdrptr
;
10675 if (bucket_count
!= 0)
10676 hdrptr
+= name_count
* sizeof (uint32_t);
10677 unsigned char *const name_table_string_offsets
= hdrptr
;
10678 hdrptr
+= name_count
* offset_size
;
10679 unsigned char *const name_table_entry_offsets
= hdrptr
;
10680 hdrptr
+= name_count
* offset_size
;
10681 unsigned char *const abbrev_table
= hdrptr
;
10682 hdrptr
+= abbrev_table_size
;
10683 const unsigned char *const abbrev_table_end
= hdrptr
;
10684 unsigned char *const entry_pool
= hdrptr
;
10686 size_t buckets_filled
= 0;
10688 for (bucketi
= 0; bucketi
< bucket_count
; bucketi
++)
10690 const uint32_t bucket
= hash_table_buckets
[bucketi
];
10695 printf (ngettext ("Used %zu of %lu bucket.\n",
10696 "Used %zu of %lu buckets.\n",
10697 (unsigned long) bucket_count
),
10698 buckets_filled
, (unsigned long) bucket_count
);
10700 if (bucket_count
!= 0)
10702 uint32_t hash_prev
= 0;
10703 size_t hash_clash_count
= 0;
10704 size_t longest_clash
= 0;
10705 size_t this_length
= 0;
10707 for (hashi
= 0; hashi
< name_count
; hashi
++)
10709 const uint32_t hash_this
= hash_table_hashes
[hashi
];
10713 if (hash_prev
% bucket_count
== hash_this
% bucket_count
)
10715 ++hash_clash_count
;
10717 longest_clash
= MAX (longest_clash
, this_length
);
10722 hash_prev
= hash_this
;
10724 printf (_("Out of %" PRIu64
" items there are %zu bucket clashes"
10725 " (longest of %zu entries).\n"),
10726 name_count
, hash_clash_count
, longest_clash
);
10728 if (name_count
!= buckets_filled
+ hash_clash_count
)
10729 warn (_("The name_count (%" PRIu64
")"
10730 " is not the same as the used bucket_count"
10731 " (%zu) + the hash clash count (%zu)\n"),
10732 name_count
, buckets_filled
, hash_clash_count
);
10735 struct abbrev_lookup_entry
10737 uint64_t abbrev_tag
;
10738 unsigned char *abbrev_lookup_ptr
;
10740 struct abbrev_lookup_entry
*abbrev_lookup
= NULL
;
10741 size_t abbrev_lookup_used
= 0;
10742 size_t abbrev_lookup_allocated
= 0;
10744 unsigned char *abbrevptr
= abbrev_table
;
10747 uint64_t abbrev_tag
;
10749 READ_ULEB (abbrev_tag
, abbrevptr
, abbrev_table_end
);
10750 if (abbrev_tag
== 0)
10752 if (abbrev_lookup_used
== abbrev_lookup_allocated
)
10754 abbrev_lookup_allocated
= MAX (0x100,
10755 abbrev_lookup_allocated
* 2);
10756 abbrev_lookup
= xrealloc (abbrev_lookup
,
10757 (abbrev_lookup_allocated
10758 * sizeof (*abbrev_lookup
)));
10760 assert (abbrev_lookup_used
< abbrev_lookup_allocated
);
10761 struct abbrev_lookup_entry
*entry
;
10762 for (entry
= abbrev_lookup
;
10763 entry
< abbrev_lookup
+ abbrev_lookup_used
;
10765 if (entry
->abbrev_tag
== abbrev_tag
)
10767 warn (_("Duplicate abbreviation tag %" PRIu64
10768 " in unit %#tx in the debug_names section\n"),
10769 abbrev_tag
, unit_start
- section
->start
);
10772 entry
= &abbrev_lookup
[abbrev_lookup_used
++];
10773 entry
->abbrev_tag
= abbrev_tag
;
10774 entry
->abbrev_lookup_ptr
= abbrevptr
;
10776 /* Skip DWARF tag. */
10777 SKIP_ULEB (abbrevptr
, abbrev_table_end
);
10780 uint64_t xindex
, form
;
10782 READ_ULEB (xindex
, abbrevptr
, abbrev_table_end
);
10783 READ_ULEB (form
, abbrevptr
, abbrev_table_end
);
10784 if (xindex
== 0 && form
== 0)
10789 printf (_("\nSymbol table:\n"));
10791 for (namei
= 0; namei
< name_count
; ++namei
)
10793 uint64_t string_offset
, entry_offset
;
10795 /* We need to scan first whether there is a single or multiple
10796 entries. TAGNO is -2 for the first entry, it is -1 for the
10797 initial tag read of the second entry, then it becomes 0 for the
10798 first entry for real printing etc. */
10800 /* Initialize it due to a false compiler warning. */
10801 uint64_t second_abbrev_tag
= -1;
10802 unsigned char *entryptr
;
10804 p
= name_table_string_offsets
+ namei
* offset_size
;
10805 SAFE_BYTE_GET (string_offset
, p
, offset_size
, unit_end
);
10807 p
= name_table_entry_offsets
+ namei
* offset_size
;
10808 SAFE_BYTE_GET (entry_offset
, p
, offset_size
, unit_end
);
10810 /* The name table is indexed starting at 1 according to
10811 DWARF, so be sure to use the DWARF numbering here. */
10812 printf ("[%3u] ", namei
+ 1);
10813 if (bucket_count
!= 0)
10814 printf ("#%08x ", hash_table_hashes
[namei
]);
10816 printf ("%s:", fetch_indirect_string (string_offset
));
10818 entryptr
= entry_pool
+ entry_offset
;
10819 /* PR 31456: Check for invalid entry offset. */
10820 if (entryptr
< entry_pool
|| entryptr
>= unit_end
)
10822 warn (_("Invalid entry offset value: %" PRIx64
"\n"), entry_offset
);
10828 uint64_t abbrev_tag
;
10829 uint64_t dwarf_tag
;
10830 const struct abbrev_lookup_entry
*entry
;
10832 READ_ULEB (abbrev_tag
, entryptr
, unit_end
);
10835 second_abbrev_tag
= abbrev_tag
;
10837 entryptr
= entry_pool
+ entry_offset
;
10840 if (abbrev_tag
== 0)
10843 printf ("%s<%" PRIu64
">",
10844 (tagno
== 0 && second_abbrev_tag
== 0 ? " " : "\n\t"),
10847 for (entry
= abbrev_lookup
;
10848 entry
< abbrev_lookup
+ abbrev_lookup_used
;
10850 if (entry
->abbrev_tag
== abbrev_tag
)
10852 if (entry
>= abbrev_lookup
+ abbrev_lookup_used
)
10854 warn (_("Undefined abbreviation tag %" PRId64
10855 " in unit %#tx in the debug_names section\n"),
10857 unit_start
- section
->start
);
10860 abbrevptr
= entry
->abbrev_lookup_ptr
;
10861 READ_ULEB (dwarf_tag
, abbrevptr
, abbrev_table_end
);
10863 printf (" %s", get_TAG_name (dwarf_tag
));
10866 uint64_t xindex
, form
;
10868 READ_ULEB (xindex
, abbrevptr
, abbrev_table_end
);
10869 READ_ULEB (form
, abbrevptr
, abbrev_table_end
);
10870 if (xindex
== 0 && form
== 0)
10874 printf (" %s", get_IDX_name (xindex
));
10875 entryptr
= read_and_display_attr_value (0, form
, 0,
10876 unit_start
, entryptr
, unit_end
,
10878 dwarf_version
, NULL
,
10879 (tagno
< 0), section
,
10885 printf (_(" <no entries>"));
10889 free (abbrev_lookup
);
10896 display_debug_links (struct dwarf_section
* section
,
10897 void * file ATTRIBUTE_UNUSED
)
10899 const unsigned char * filename
;
10900 unsigned int filelen
;
10902 introduce (section
, false);
10904 /* The .gnu_debuglink section is formatted as:
10905 (c-string) Filename.
10906 (padding) If needed to reach a 4 byte boundary.
10907 (uint32_t) CRC32 value.
10909 The .gun_debugaltlink section is formatted as:
10910 (c-string) Filename.
10911 (binary) Build-ID. */
10913 filename
= section
->start
;
10914 filelen
= strnlen ((const char *) filename
, section
->size
);
10915 if (filelen
== section
->size
)
10917 warn (_("The debuglink filename is corrupt/missing\n"));
10921 printf (_(" Separate debug info file: %s\n"), filename
);
10923 if (startswith (section
->name
, ".gnu_debuglink"))
10925 unsigned int crc32
;
10926 unsigned int crc_offset
;
10928 crc_offset
= filelen
+ 1;
10929 crc_offset
= (crc_offset
+ 3) & ~3;
10930 if (crc_offset
+ 4 > section
->size
)
10932 warn (_("CRC offset missing/truncated\n"));
10936 crc32
= byte_get (filename
+ crc_offset
, 4);
10938 printf (_(" CRC value: %#x\n"), crc32
);
10940 if (crc_offset
+ 4 < section
->size
)
10942 warn (_("There are %#" PRIx64
10943 " extraneous bytes at the end of the section\n"),
10944 section
->size
- (crc_offset
+ 4));
10948 else /* startswith (section->name, ".gnu_debugaltlink") */
10950 const unsigned char *build_id
= section
->start
+ filelen
+ 1;
10951 size_t build_id_len
= section
->size
- (filelen
+ 1);
10954 /* FIXME: Should we support smaller build-id notes ? */
10955 if (build_id_len
< 0x14)
10957 warn (_("Build-ID is too short (%#zx bytes)\n"), build_id_len
);
10961 printed
= printf (_(" Build-ID (%#zx bytes):"), build_id_len
);
10962 display_data (printed
, build_id
, build_id_len
);
10971 display_gdb_index (struct dwarf_section
*section
,
10972 void *file ATTRIBUTE_UNUSED
)
10974 unsigned char *start
= section
->start
;
10976 uint32_t cu_list_offset
, tu_list_offset
;
10977 uint32_t address_table_offset
, symbol_table_offset
, constant_pool_offset
,
10978 shortcut_table_offset
;
10979 unsigned int cu_list_elements
, tu_list_elements
;
10980 unsigned int address_table_elements
, symbol_table_slots
;
10981 unsigned char *cu_list
, *tu_list
;
10982 unsigned char *address_table
, *symbol_table
, *shortcut_table
, *constant_pool
;
10985 /* The documentation for the format of this file is in gdb/dwarf2read.c. */
10987 introduce (section
, false);
10989 version
= section
->size
< 4 ? 0 : byte_get_little_endian (start
, 4);
10990 size_t header_size
= (version
< 9 ? 6 : 7) * sizeof (uint32_t);
10991 if (section
->size
< header_size
)
10993 warn (_("Truncated header in the %s section.\n"), section
->name
);
10997 printf (_("Version %lu\n"), (unsigned long) version
);
10999 /* Prior versions are obsolete, and future versions may not be
11000 backwards compatible. */
11001 if (version
< 3 || version
> 9)
11003 warn (_("Unsupported version %lu.\n"), (unsigned long) version
);
11007 warn (_("The address table data in version 3 may be wrong.\n"));
11009 warn (_("Version 4 does not support case insensitive lookups.\n"));
11011 warn (_("Version 5 does not include inlined functions.\n"));
11013 warn (_("Version 6 does not include symbol attributes.\n"));
11014 /* Version 7 indices generated by Gold have bad type unit references,
11015 PR binutils/15021. But we don't know if the index was generated by
11016 Gold or not, so to avoid worrying users with gdb-generated indices
11017 we say nothing for version 7 here. */
11019 cu_list_offset
= byte_get_little_endian (start
+ 4, 4);
11020 tu_list_offset
= byte_get_little_endian (start
+ 8, 4);
11021 address_table_offset
= byte_get_little_endian (start
+ 12, 4);
11022 symbol_table_offset
= byte_get_little_endian (start
+ 16, 4);
11023 shortcut_table_offset
= byte_get_little_endian (start
+ 20, 4);
11025 constant_pool_offset
= shortcut_table_offset
;
11027 constant_pool_offset
= byte_get_little_endian (start
+ 24, 4);
11029 if (cu_list_offset
> section
->size
11030 || tu_list_offset
> section
->size
11031 || address_table_offset
> section
->size
11032 || symbol_table_offset
> section
->size
11033 || shortcut_table_offset
> section
->size
11034 || constant_pool_offset
> section
->size
11035 || tu_list_offset
< cu_list_offset
11036 || address_table_offset
< tu_list_offset
11037 || symbol_table_offset
< address_table_offset
11038 || shortcut_table_offset
< symbol_table_offset
11039 || constant_pool_offset
< shortcut_table_offset
)
11041 warn (_("Corrupt header in the %s section.\n"), section
->name
);
11045 cu_list_elements
= (tu_list_offset
- cu_list_offset
) / 16;
11046 tu_list_elements
= (address_table_offset
- tu_list_offset
) / 24;
11047 address_table_elements
= (symbol_table_offset
- address_table_offset
) / 20;
11048 symbol_table_slots
= (shortcut_table_offset
- symbol_table_offset
) / 8;
11050 cu_list
= start
+ cu_list_offset
;
11051 tu_list
= start
+ tu_list_offset
;
11052 address_table
= start
+ address_table_offset
;
11053 symbol_table
= start
+ symbol_table_offset
;
11054 shortcut_table
= start
+ shortcut_table_offset
;
11055 constant_pool
= start
+ constant_pool_offset
;
11057 printf (_("\nCU table:\n"));
11058 for (i
= 0; i
< cu_list_elements
; i
++)
11060 uint64_t cu_offset
= byte_get_little_endian (cu_list
+ i
* 16, 8);
11061 uint64_t cu_length
= byte_get_little_endian (cu_list
+ i
* 16 + 8, 8);
11063 printf ("[%3u] %#" PRIx64
" - %#" PRIx64
"\n",
11064 i
, cu_offset
, cu_offset
+ cu_length
- 1);
11067 printf (_("\nTU table:\n"));
11068 for (i
= 0; i
< tu_list_elements
; i
++)
11070 uint64_t tu_offset
= byte_get_little_endian (tu_list
+ i
* 24, 8);
11071 uint64_t type_offset
= byte_get_little_endian (tu_list
+ i
* 24 + 8, 8);
11072 uint64_t signature
= byte_get_little_endian (tu_list
+ i
* 24 + 16, 8);
11074 printf ("[%3u] %#" PRIx64
" %#" PRIx64
" ",
11075 i
, tu_offset
, type_offset
);
11076 print_hex_ns (signature
, 8);
11080 printf (_("\nAddress table:\n"));
11081 for (i
= 0; i
< address_table_elements
; i
++)
11083 uint64_t low
= byte_get_little_endian (address_table
+ i
* 20, 8);
11084 uint64_t high
= byte_get_little_endian (address_table
+ i
* 20 + 8, 8);
11085 uint32_t cu_index
= byte_get_little_endian (address_table
+ i
* 20 + 16, 4);
11087 print_hex (low
, 8);
11088 print_hex (high
, 8);
11089 printf ("%" PRIu32
"\n", cu_index
);
11092 printf (_("\nSymbol table:\n"));
11093 for (i
= 0; i
< symbol_table_slots
; ++i
)
11095 uint32_t name_offset
= byte_get_little_endian (symbol_table
+ i
* 8, 4);
11096 uint32_t cu_vector_offset
= byte_get_little_endian (symbol_table
+ i
* 8 + 4, 4);
11097 uint32_t num_cus
, cu
;
11099 if (name_offset
!= 0
11100 || cu_vector_offset
!= 0)
11104 /* PR 17531: file: 5b7b07ad. */
11105 if (name_offset
>= section
->size
- constant_pool_offset
)
11107 printf (_("[%3u] <corrupt offset: %x>"), i
, name_offset
);
11108 warn (_("Corrupt name offset of 0x%x found for symbol table slot %d\n"),
11112 printf ("[%3u] %.*s:", i
,
11113 (int) (section
->size
- (constant_pool_offset
+ name_offset
)),
11114 constant_pool
+ name_offset
);
11116 if (section
->size
- constant_pool_offset
< 4
11117 || cu_vector_offset
> section
->size
- constant_pool_offset
- 4)
11119 printf (_("<invalid CU vector offset: %x>\n"), cu_vector_offset
);
11120 warn (_("Corrupt CU vector offset of 0x%x found for symbol table slot %d\n"),
11121 cu_vector_offset
, i
);
11125 num_cus
= byte_get_little_endian (constant_pool
+ cu_vector_offset
, 4);
11127 if ((uint64_t) num_cus
* 4 > section
->size
- (constant_pool_offset
11128 + cu_vector_offset
+ 4))
11130 printf ("<invalid number of CUs: %d>\n", num_cus
);
11131 warn (_("Invalid number of CUs (0x%x) for symbol table slot %d\n"),
11139 for (j
= 0; j
< num_cus
; ++j
)
11142 gdb_index_symbol_kind kind
;
11144 cu
= byte_get_little_endian (constant_pool
+ cu_vector_offset
+ 4 + j
* 4, 4);
11145 is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu
);
11146 kind
= GDB_INDEX_SYMBOL_KIND_VALUE (cu
);
11147 cu
= GDB_INDEX_CU_VALUE (cu
);
11148 /* Convert to TU number if it's for a type unit. */
11149 if (cu
>= cu_list_elements
)
11150 printf ("%cT%lu", num_cus
> 1 ? '\t' : ' ',
11151 (unsigned long) cu
- cu_list_elements
);
11153 printf ("%c%lu", num_cus
> 1 ? '\t' : ' ', (unsigned long) cu
);
11155 printf (" [%s, %s]",
11156 is_static
? _("static") : _("global"),
11157 get_gdb_index_symbol_kind_name (kind
));
11168 printf (_("\nShortcut table:\n"));
11170 if (shortcut_table_offset
+ 8 > constant_pool_offset
)
11172 warn (_("Corrupt shortcut table in the %s section.\n"), section
->name
);
11176 uint32_t lang
= byte_get_little_endian (shortcut_table
, 4);
11177 printf (_("Language of main: "));
11178 display_lang (lang
);
11181 printf (_("Name of main: "));
11183 printf (_("<unknown>\n"));
11186 uint32_t name_offset
= byte_get_little_endian (shortcut_table
+ 4, 4);
11187 if (name_offset
>= section
->size
- constant_pool_offset
)
11189 printf (_("<corrupt offset: %x>\n"), name_offset
);
11190 warn (_("Corrupt name offset of 0x%x found for name of main\n"),
11194 printf ("%s\n", constant_pool
+ name_offset
);
11201 /* Pre-allocate enough space for the CU/TU sets needed. */
11204 prealloc_cu_tu_list (unsigned int nshndx
)
11207 /* Always allocate at least one entry for the end-marker. */
11210 if (shndx_pool
== NULL
)
11212 shndx_pool_size
= nshndx
;
11213 shndx_pool_used
= 0;
11214 shndx_pool
= (unsigned int *) xcmalloc (shndx_pool_size
,
11215 sizeof (unsigned int));
11219 shndx_pool_size
= shndx_pool_used
+ nshndx
;
11220 shndx_pool
= (unsigned int *) xcrealloc (shndx_pool
, shndx_pool_size
,
11221 sizeof (unsigned int));
11226 add_shndx_to_cu_tu_entry (unsigned int shndx
)
11228 shndx_pool
[shndx_pool_used
++] = shndx
;
11232 end_cu_tu_entry (void)
11234 shndx_pool
[shndx_pool_used
++] = 0;
11237 /* Return the short name of a DWARF section given by a DW_SECT enumerator. */
11239 static const char *
11240 get_DW_SECT_short_name (unsigned int dw_sect
)
11242 static char buf
[16];
11248 case DW_SECT_TYPES
:
11250 case DW_SECT_ABBREV
:
11256 case DW_SECT_STR_OFFSETS
:
11258 case DW_SECT_MACINFO
:
11260 case DW_SECT_MACRO
:
11266 snprintf (buf
, sizeof (buf
), "%d", dw_sect
);
11270 /* Process a CU or TU index. If DO_DISPLAY is true, print the contents.
11271 These sections are extensions for Fission.
11272 See http://gcc.gnu.org/wiki/DebugFissionDWP. */
11275 process_cu_tu_index (struct dwarf_section
*section
, int do_display
)
11277 unsigned char *phdr
= section
->start
;
11278 unsigned char *limit
= phdr
+ section
->size
;
11279 unsigned char *phash
;
11280 unsigned char *pindex
;
11281 unsigned char *ppool
;
11282 unsigned int version
;
11283 unsigned int ncols
= 0;
11284 unsigned int nused
;
11285 unsigned int nslots
;
11288 uint64_t signature
;
11291 /* PR 17512: file: 002-168123-0.004. */
11294 warn (_("Section %s is empty\n"), section
->name
);
11297 /* PR 17512: file: 002-376-0.004. */
11298 if (section
->size
< 24)
11300 warn (_("Section %s is too small to contain a CU/TU header\n"),
11306 SAFE_BYTE_GET_AND_INC (version
, phash
, 4, limit
);
11308 SAFE_BYTE_GET_AND_INC (ncols
, phash
, 4, limit
);
11309 SAFE_BYTE_GET_AND_INC (nused
, phash
, 4, limit
);
11310 SAFE_BYTE_GET_AND_INC (nslots
, phash
, 4, limit
);
11312 pindex
= phash
+ (size_t) nslots
* 8;
11313 ppool
= pindex
+ (size_t) nslots
* 4;
11317 introduce (section
, false);
11319 printf (_(" Version: %u\n"), version
);
11321 printf (_(" Number of columns: %u\n"), ncols
);
11322 printf (_(" Number of used entries: %u\n"), nused
);
11323 printf (_(" Number of slots: %u\n\n"), nslots
);
11326 /* PR 17531: file: 45d69832. */
11327 if (_mul_overflow ((size_t) nslots
, 12, &total
)
11328 || total
> (size_t) (limit
- phash
))
11330 warn (ngettext ("Section %s is too small for %u slot\n",
11331 "Section %s is too small for %u slots\n",
11333 section
->name
, nslots
);
11339 unsigned char *shndx_list
;
11340 unsigned int shndx
;
11344 prealloc_cu_tu_list ((limit
- ppool
) / 4);
11345 for (shndx_list
= ppool
+ 4; shndx_list
<= limit
- 4; shndx_list
+= 4)
11347 shndx
= byte_get (shndx_list
, 4);
11348 add_shndx_to_cu_tu_entry (shndx
);
11350 end_cu_tu_entry ();
11353 for (i
= 0; i
< nslots
; i
++)
11355 SAFE_BYTE_GET (signature
, phash
, 8, limit
);
11356 if (signature
!= 0)
11358 SAFE_BYTE_GET (j
, pindex
, 4, limit
);
11359 shndx_list
= ppool
+ j
* 4;
11360 /* PR 17531: file: 705e010d. */
11361 if (shndx_list
< ppool
)
11363 warn (_("Section index pool located before start of section\n"));
11367 printf (_(" [%3d] Signature: %#" PRIx64
" Sections: "),
11371 if (shndx_list
>= limit
)
11373 warn (_("Section %s too small for shndx pool\n"),
11377 SAFE_BYTE_GET (shndx
, shndx_list
, 4, limit
);
11380 printf (" %d", shndx
);
11389 else if (version
== 2)
11392 unsigned int dw_sect
;
11393 unsigned char *ph
= phash
;
11394 unsigned char *pi
= pindex
;
11395 unsigned char *poffsets
= ppool
+ (size_t) ncols
* 4;
11396 unsigned char *psizes
= poffsets
+ (size_t) nused
* ncols
* 4;
11398 struct cu_tu_set
*this_set
= NULL
;
11400 unsigned char *prow
;
11403 is_tu_index
= strcmp (section
->name
, ".debug_tu_index") == 0;
11405 /* PR 17531: file: 0dd159bf.
11406 Check for integer overflow (can occur when size_t is 32-bit)
11407 with overlarge ncols or nused values. */
11409 || _mul_overflow ((size_t) ncols
, 4, &temp
)
11410 || _mul_overflow ((size_t) nused
+ 1, temp
, &total
)
11411 || total
> (size_t) (limit
- ppool
)
11412 /* PR 30227: ncols could be 0. */
11413 || _mul_overflow ((size_t) nused
+ 1, 4, &total
)
11414 || total
> (size_t) (limit
- ppool
))
11416 warn (_("Section %s too small for offset and size tables\n"),
11423 printf (_(" Offset table\n"));
11424 printf (" slot %-16s ",
11425 is_tu_index
? _("signature") : _("dwo_id"));
11432 tu_sets
= xcalloc2 (nused
, sizeof (struct cu_tu_set
));
11433 this_set
= tu_sets
;
11438 cu_sets
= xcalloc2 (nused
, sizeof (struct cu_tu_set
));
11439 this_set
= cu_sets
;
11445 for (j
= 0; j
< ncols
; j
++)
11447 unsigned char *p
= ppool
+ j
* 4;
11448 SAFE_BYTE_GET (dw_sect
, p
, 4, limit
);
11449 printf (" %8s", get_DW_SECT_short_name (dw_sect
));
11454 for (i
= 0; i
< nslots
; i
++)
11456 SAFE_BYTE_GET (signature
, ph
, 8, limit
);
11458 SAFE_BYTE_GET (row
, pi
, 4, limit
);
11461 /* PR 17531: file: a05f6ab3. */
11464 warn (_("Row index (%u) is larger than number of used entries (%u)\n"),
11471 size_t num_copy
= sizeof (uint64_t);
11473 memcpy (&this_set
[row
- 1].signature
, ph
, num_copy
);
11476 prow
= poffsets
+ (row
- 1) * ncols
* 4;
11478 printf (" [%3d] %#" PRIx64
, i
, signature
);
11479 for (j
= 0; j
< ncols
; j
++)
11481 unsigned char *p
= prow
+ j
* 4;
11482 SAFE_BYTE_GET (val
, p
, 4, limit
);
11484 printf (" %8d", val
);
11488 SAFE_BYTE_GET (dw_sect
, p
, 4, limit
);
11490 /* PR 17531: file: 10796eb3. */
11491 if (dw_sect
>= DW_SECT_MAX
)
11492 warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect
);
11494 this_set
[row
- 1].section_offsets
[dw_sect
] = val
;
11510 printf (_(" Size table\n"));
11511 printf (" slot %-16s ",
11512 is_tu_index
? _("signature") : _("dwo_id"));
11515 for (j
= 0; j
< ncols
; j
++)
11517 unsigned char *p
= ppool
+ j
* 4;
11518 SAFE_BYTE_GET (val
, p
, 4, limit
);
11520 printf (" %8s", get_DW_SECT_short_name (val
));
11526 for (i
= 0; i
< nslots
; i
++)
11528 SAFE_BYTE_GET (signature
, ph
, 8, limit
);
11530 SAFE_BYTE_GET (row
, pi
, 4, limit
);
11533 prow
= psizes
+ (row
- 1) * ncols
* 4;
11536 printf (" [%3d] %#" PRIx64
, i
, signature
);
11538 for (j
= 0; j
< ncols
; j
++)
11540 unsigned char *p
= prow
+ j
* 4;
11542 /* PR 28645: Check for overflow. Since we do not know how
11543 many populated rows there will be, we cannot just
11544 perform a single check at the start of this function. */
11545 if (p
> (limit
- 4))
11549 warn (_("Too many rows/columns in DWARF index section %s\n"),
11554 SAFE_BYTE_GET (val
, p
, 4, limit
);
11557 printf (" %8d", val
);
11561 SAFE_BYTE_GET (dw_sect
, p
, 4, limit
);
11562 if (dw_sect
>= DW_SECT_MAX
)
11563 warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect
);
11565 this_set
[row
- 1].section_sizes
[dw_sect
] = val
;
11577 else if (do_display
)
11578 printf (_(" Unsupported version (%d)\n"), version
);
11586 static int cu_tu_indexes_read
= -1; /* Tri-state variable. */
11588 /* Load the CU and TU indexes if present. This will build a list of
11589 section sets that we can use to associate a .debug_info.dwo section
11590 with its associated .debug_abbrev.dwo section in a .dwp file. */
11593 load_cu_tu_indexes (void *file
)
11595 /* If we have already loaded (or tried to load) the CU and TU indexes
11596 then do not bother to repeat the task. */
11597 if (cu_tu_indexes_read
== -1)
11599 cu_tu_indexes_read
= true;
11601 if (load_debug_section_with_follow (dwp_cu_index
, file
))
11602 if (! process_cu_tu_index (&debug_displays
[dwp_cu_index
].section
, 0))
11603 cu_tu_indexes_read
= false;
11605 if (load_debug_section_with_follow (dwp_tu_index
, file
))
11606 if (! process_cu_tu_index (&debug_displays
[dwp_tu_index
].section
, 0))
11607 cu_tu_indexes_read
= false;
11610 return (bool) cu_tu_indexes_read
;
11613 /* Find the set of sections that includes section SHNDX. */
11616 find_cu_tu_set (void *file
, unsigned int shndx
)
11620 if (! load_cu_tu_indexes (file
))
11623 /* Find SHNDX in the shndx pool. */
11624 for (i
= 0; i
< shndx_pool_used
; i
++)
11625 if (shndx_pool
[i
] == shndx
)
11628 if (i
>= shndx_pool_used
)
11631 /* Now backup to find the first entry in the set. */
11632 while (i
> 0 && shndx_pool
[i
- 1] != 0)
11635 return shndx_pool
+ i
;
11638 /* Display a .debug_cu_index or .debug_tu_index section. */
11641 display_cu_index (struct dwarf_section
*section
, void *file ATTRIBUTE_UNUSED
)
11643 return process_cu_tu_index (section
, 1);
11647 display_debug_not_supported (struct dwarf_section
*section
,
11648 void *file ATTRIBUTE_UNUSED
)
11650 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
11656 /* Like malloc, but takes two parameters like calloc.
11657 Verifies that the first parameter is not too large.
11658 Note: does *not* initialise the allocated memory to zero. */
11661 cmalloc (uint64_t nmemb
, size_t size
)
11663 /* Check for overflow. */
11664 if (nmemb
>= ~(size_t) 0 / size
)
11667 return xmalloc (nmemb
* size
);
11670 /* Like xmalloc, but takes two parameters like calloc.
11671 Verifies that the first parameter is not too large.
11672 Note: does *not* initialise the allocated memory to zero. */
11675 xcmalloc (uint64_t nmemb
, size_t size
)
11677 /* Check for overflow. */
11678 if (nmemb
>= ~(size_t) 0 / size
)
11681 _("Attempt to allocate an array with an excessive number of elements: %#" PRIx64
"\n"),
11686 return xmalloc (nmemb
* size
);
11689 /* Like xrealloc, but takes three parameters.
11690 Verifies that the second parameter is not too large.
11691 Note: does *not* initialise any new memory to zero. */
11694 xcrealloc (void *ptr
, uint64_t nmemb
, size_t size
)
11696 /* Check for overflow. */
11697 if (nmemb
>= ~(size_t) 0 / size
)
11699 error (_("Attempt to re-allocate an array with an excessive number of elements: %#" PRIx64
"\n"),
11704 return xrealloc (ptr
, nmemb
* size
);
11707 /* Like xcalloc, but verifies that the first parameter is not too large. */
11710 xcalloc2 (uint64_t nmemb
, size_t size
)
11712 /* Check for overflow. */
11713 if (nmemb
>= ~(size_t) 0 / size
)
11715 error (_("Attempt to allocate a zero'ed array with an excessive number of elements: %#" PRIx64
"\n"),
11720 return xcalloc (nmemb
, size
);
11723 static unsigned long
11724 calc_gnu_debuglink_crc32 (unsigned long crc
,
11725 const unsigned char *buf
,
11728 static const unsigned long crc32_table
[256] =
11730 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
11731 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
11732 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
11733 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
11734 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
11735 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
11736 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
11737 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
11738 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
11739 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
11740 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
11741 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
11742 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
11743 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
11744 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
11745 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
11746 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
11747 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
11748 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
11749 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
11750 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
11751 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
11752 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
11753 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
11754 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
11755 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
11756 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
11757 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
11758 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
11759 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
11760 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
11761 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
11762 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
11763 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
11764 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
11765 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
11766 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
11767 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
11768 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
11769 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
11770 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
11771 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
11772 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
11773 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
11774 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
11775 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
11776 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
11777 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
11778 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
11779 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
11780 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
11783 const unsigned char *end
;
11785 crc
= ~crc
& 0xffffffff;
11786 for (end
= buf
+ len
; buf
< end
; ++ buf
)
11787 crc
= crc32_table
[(crc
^ *buf
) & 0xff] ^ (crc
>> 8);
11788 return ~crc
& 0xffffffff;
11791 typedef bool (*check_func_type
) (const char *, void *);
11792 typedef const char *(* parse_func_type
) (struct dwarf_section
*, void *);
11795 check_gnu_debuglink (const char * pathname
, void * crc_pointer
)
11797 static unsigned char buffer
[8 * 1024];
11800 unsigned long crc
= 0;
11803 sep_data
= open_debug_file (pathname
);
11804 if (sep_data
== NULL
)
11807 /* Yes - we are opening the file twice... */
11808 f
= fopen (pathname
, "rb");
11811 /* Paranoia: This should never happen. */
11812 close_debug_file (sep_data
);
11813 warn (_("Unable to reopen separate debug info file: %s\n"), pathname
);
11817 while ((count
= fread (buffer
, 1, sizeof (buffer
), f
)) > 0)
11818 crc
= calc_gnu_debuglink_crc32 (crc
, buffer
, count
);
11822 if (crc
!= * (unsigned long *) crc_pointer
)
11824 close_debug_file (sep_data
);
11825 warn (_("Separate debug info file %s found, but CRC does not match - ignoring\n"),
11833 static const char *
11834 parse_gnu_debuglink (struct dwarf_section
* section
, void * data
)
11837 unsigned int crc_offset
;
11838 unsigned long * crc32
= (unsigned long *) data
;
11840 /* The name is first.
11841 The CRC value is stored after the filename, aligned up to 4 bytes. */
11842 name
= (const char *) section
->start
;
11844 crc_offset
= strnlen (name
, section
->size
) + 1;
11845 if (crc_offset
== 1)
11847 crc_offset
= (crc_offset
+ 3) & ~3;
11848 if (crc_offset
+ 4 > section
->size
)
11851 * crc32
= byte_get (section
->start
+ crc_offset
, 4);
11856 check_gnu_debugaltlink (const char * filename
, void * data ATTRIBUTE_UNUSED
)
11858 void * sep_data
= open_debug_file (filename
);
11860 if (sep_data
== NULL
)
11863 /* FIXME: We should now extract the build-id in the separate file
11869 typedef struct build_id_data
11872 const unsigned char *data
;
11875 static const char *
11876 parse_gnu_debugaltlink (struct dwarf_section
* section
, void * data
)
11881 Build_id_data
*build_id_data
;
11883 /* The name is first.
11884 The build-id follows immediately, with no padding, up to the section's end. */
11886 name
= (const char *) section
->start
;
11887 namelen
= strnlen (name
, section
->size
) + 1;
11890 if (namelen
>= section
->size
)
11893 id_len
= section
->size
- namelen
;
11897 build_id_data
= (Build_id_data
*) data
;
11898 build_id_data
->len
= id_len
;
11899 build_id_data
->data
= section
->start
+ namelen
;
11905 add_separate_debug_file (const char * filename
, void * handle
)
11907 separate_info
* i
= xmalloc (sizeof * i
);
11909 i
->filename
= filename
;
11910 i
->handle
= handle
;
11911 i
->next
= first_separate_info
;
11912 first_separate_info
= i
;
11915 #if HAVE_LIBDEBUGINFOD
11916 /* Query debuginfod servers for the target debuglink or debugaltlink
11917 file. If successful, store the path of the file in filename and
11918 return TRUE, otherwise return FALSE. */
11921 debuginfod_fetch_separate_debug_info (struct dwarf_section
* section
,
11925 size_t build_id_len
;
11926 unsigned char * build_id
;
11928 if (strcmp (section
->uncompressed_name
, ".gnu_debuglink") == 0)
11930 /* Get the build-id of file. */
11931 build_id
= get_build_id (file
);
11934 else if (strcmp (section
->uncompressed_name
, ".gnu_debugaltlink") == 0)
11936 /* Get the build-id of the debugaltlink file. */
11937 unsigned int filelen
;
11939 filelen
= strnlen ((const char *)section
->start
, section
->size
);
11940 if (filelen
== section
->size
)
11941 /* Corrupt debugaltlink. */
11944 build_id
= section
->start
+ filelen
+ 1;
11945 build_id_len
= section
->size
- (filelen
+ 1);
11947 if (build_id_len
== 0)
11956 debuginfod_client
* client
;
11958 client
= debuginfod_begin ();
11959 if (client
== NULL
)
11962 /* Query debuginfod servers for the target file. If found its path
11963 will be stored in filename. */
11964 fd
= debuginfod_find_debuginfo (client
, build_id
, build_id_len
, filename
);
11965 debuginfod_end (client
);
11967 /* Only free build_id if we allocated space for a hex string
11968 in get_build_id (). */
11969 if (build_id_len
== 0)
11974 /* File successfully retrieved. Close fd since we want to
11975 use open_debug_file () on filename instead. */
11983 #endif /* HAVE_LIBDEBUGINFOD */
11986 load_separate_debug_info (const char * main_filename
,
11987 struct dwarf_section
* xlink
,
11988 parse_func_type parse_func
,
11989 check_func_type check_func
,
11991 void * file ATTRIBUTE_UNUSED
)
11993 const char * separate_filename
;
11994 char * debug_filename
;
11996 size_t canon_dirlen
;
11998 char * canon_filename
;
11999 char * canon_debug_filename
;
12002 if ((separate_filename
= parse_func (xlink
, func_data
)) == NULL
)
12004 warn (_("Corrupt debuglink section: %s\n"),
12005 xlink
->name
? xlink
->name
: xlink
->uncompressed_name
);
12009 /* Attempt to locate the separate file.
12010 This should duplicate the logic in bfd/opncls.c:find_separate_debug_file(). */
12012 canon_filename
= lrealpath (main_filename
);
12013 canon_dir
= xstrdup (canon_filename
);
12015 for (canon_dirlen
= strlen (canon_dir
); canon_dirlen
> 0; canon_dirlen
--)
12016 if (IS_DIR_SEPARATOR (canon_dir
[canon_dirlen
- 1]))
12018 canon_dir
[canon_dirlen
] = '\0';
12021 #define DEBUGDIR "/lib/debug"
12023 #ifndef EXTRA_DEBUG_ROOT1
12024 #define EXTRA_DEBUG_ROOT1 "/usr/lib/debug"
12026 #ifndef EXTRA_DEBUG_ROOT2
12027 #define EXTRA_DEBUG_ROOT2 "/usr/lib/debug/usr"
12030 debug_filename
= (char *) malloc (strlen (DEBUGDIR
) + 1
12032 + strlen (".debug/")
12033 #ifdef EXTRA_DEBUG_ROOT1
12034 + strlen (EXTRA_DEBUG_ROOT1
)
12036 #ifdef EXTRA_DEBUG_ROOT2
12037 + strlen (EXTRA_DEBUG_ROOT2
)
12039 + strlen (separate_filename
)
12041 if (debug_filename
== NULL
)
12043 warn (_("Out of memory\n"));
12045 free (canon_filename
);
12049 /* First try in the current directory. */
12050 sprintf (debug_filename
, "%s", separate_filename
);
12051 if (check_func (debug_filename
, func_data
))
12054 /* Then try in a subdirectory called .debug. */
12055 sprintf (debug_filename
, ".debug/%s", separate_filename
);
12056 if (check_func (debug_filename
, func_data
))
12059 /* Then try in the same directory as the original file. */
12060 sprintf (debug_filename
, "%s%s", canon_dir
, separate_filename
);
12061 if (check_func (debug_filename
, func_data
))
12064 /* And the .debug subdirectory of that directory. */
12065 sprintf (debug_filename
, "%s.debug/%s", canon_dir
, separate_filename
);
12066 if (check_func (debug_filename
, func_data
))
12069 #ifdef EXTRA_DEBUG_ROOT1
12070 /* Try the first extra debug file root. */
12071 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT1
, separate_filename
);
12072 if (check_func (debug_filename
, func_data
))
12075 /* Try the first extra debug file root. */
12076 sprintf (debug_filename
, "%s/%s/%s", EXTRA_DEBUG_ROOT1
, canon_dir
, separate_filename
);
12077 if (check_func (debug_filename
, func_data
))
12081 #ifdef EXTRA_DEBUG_ROOT2
12082 /* Try the second extra debug file root. */
12083 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT2
, separate_filename
);
12084 if (check_func (debug_filename
, func_data
))
12088 /* Then try in the global debug_filename directory. */
12089 strcpy (debug_filename
, DEBUGDIR
);
12090 dirlen
= strlen (DEBUGDIR
) - 1;
12091 if (dirlen
> 0 && DEBUGDIR
[dirlen
] != '/')
12092 strcat (debug_filename
, "/");
12093 strcat (debug_filename
, (const char *) separate_filename
);
12095 if (check_func (debug_filename
, func_data
))
12098 #if HAVE_LIBDEBUGINFOD
12100 char * tmp_filename
;
12103 && debuginfod_fetch_separate_debug_info (xlink
,
12107 /* File successfully downloaded from server, replace
12108 debug_filename with the file's path. */
12109 free (debug_filename
);
12110 debug_filename
= tmp_filename
;
12116 if (do_debug_links
)
12118 /* Failed to find the file. */
12119 warn (_("could not find separate debug file '%s'\n"),
12120 separate_filename
);
12121 warn (_("tried: %s\n"), debug_filename
);
12123 #ifdef EXTRA_DEBUG_ROOT2
12124 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT2
,
12125 separate_filename
);
12126 warn (_("tried: %s\n"), debug_filename
);
12129 #ifdef EXTRA_DEBUG_ROOT1
12130 sprintf (debug_filename
, "%s/%s/%s", EXTRA_DEBUG_ROOT1
,
12131 canon_dir
, separate_filename
);
12132 warn (_("tried: %s\n"), debug_filename
);
12134 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT1
,
12135 separate_filename
);
12136 warn (_("tried: %s\n"), debug_filename
);
12139 sprintf (debug_filename
, "%s.debug/%s", canon_dir
,
12140 separate_filename
);
12141 warn (_("tried: %s\n"), debug_filename
);
12143 sprintf (debug_filename
, "%s%s", canon_dir
, separate_filename
);
12144 warn (_("tried: %s\n"), debug_filename
);
12146 sprintf (debug_filename
, ".debug/%s", separate_filename
);
12147 warn (_("tried: %s\n"), debug_filename
);
12149 sprintf (debug_filename
, "%s", separate_filename
);
12150 warn (_("tried: %s\n"), debug_filename
);
12152 #if HAVE_LIBDEBUGINFOD
12153 if (use_debuginfod
)
12155 char *urls
= getenv (DEBUGINFOD_URLS_ENV_VAR
);
12160 warn (_("tried: DEBUGINFOD_URLS=%s\n"), urls
);
12166 free (debug_filename
);
12167 free (canon_filename
);
12173 canon_debug_filename
= lrealpath (debug_filename
);
12174 self
= strcmp (canon_debug_filename
, canon_filename
) == 0;
12175 free (canon_filename
);
12176 free (canon_debug_filename
);
12179 free (debug_filename
);
12183 void * debug_handle
;
12185 /* Now open the file.... */
12186 if ((debug_handle
= open_debug_file (debug_filename
)) == NULL
)
12188 warn (_("failed to open separate debug file: %s\n"), debug_filename
);
12189 free (debug_filename
);
12193 /* FIXME: We do not check to see if there are any other separate debug info
12194 files that would also match. */
12196 if (do_debug_links
)
12197 printf (_("\n%s: Found separate debug info file: %s\n"), main_filename
, debug_filename
);
12198 add_separate_debug_file (debug_filename
, debug_handle
);
12200 /* Do not free debug_filename - it might be referenced inside
12201 the structure returned by open_debug_file(). */
12202 return debug_handle
;
12205 /* Attempt to load a separate dwarf object file. */
12208 load_dwo_file (const char * main_filename
, const char * name
, const char * dir
, const char * id ATTRIBUTE_UNUSED
)
12210 char * separate_filename
;
12211 void * separate_handle
;
12213 if (IS_ABSOLUTE_PATH (name
))
12214 separate_filename
= strdup (name
);
12216 /* FIXME: Skip adding / if dwo_dir ends in /. */
12217 separate_filename
= concat (dir
, "/", name
, NULL
);
12218 if (separate_filename
== NULL
)
12220 warn (_("Out of memory allocating dwo filename\n"));
12224 if ((separate_handle
= open_debug_file (separate_filename
)) == NULL
)
12226 warn (_("Unable to load dwo file: %s\n"), separate_filename
);
12227 free (separate_filename
);
12231 /* FIXME: We should check the dwo_id. */
12233 printf (_("%s: Found separate debug object file: %s\n\n"), main_filename
, separate_filename
);
12235 add_separate_debug_file (separate_filename
, separate_handle
);
12236 /* Note - separate_filename will be freed in free_debug_memory(). */
12237 return separate_handle
;
12241 try_build_id_prefix (const char * prefix
, char * filename
, const unsigned char * data
, unsigned long id_len
)
12243 char * f
= filename
;
12245 f
+= sprintf (f
, "%s.build-id/%02x/", prefix
, (unsigned) *data
++);
12248 f
+= sprintf (f
, "%02x", (unsigned) *data
++);
12249 strcpy (f
, ".debug");
12251 return open_debug_file (filename
);
12254 /* Try to load a debug file based upon the build-id held in the .note.gnu.build-id section. */
12257 load_build_id_debug_file (const char * main_filename ATTRIBUTE_UNUSED
, void * main_file
)
12259 if (! load_debug_section (note_gnu_build_id
, main_file
))
12260 return; /* No .note.gnu.build-id section. */
12262 struct dwarf_section
* section
= & debug_displays
[note_gnu_build_id
].section
;
12263 if (section
== NULL
)
12265 warn (_("Unable to load the .note.gnu.build-id section\n"));
12269 if (section
->start
== NULL
|| section
->size
< 0x18)
12271 warn (_(".note.gnu.build-id section is corrupt/empty\n"));
12275 /* In theory we should extract the contents of the section into
12276 a note structure and then check the fields. For now though
12277 just use hard coded offsets instead:
12279 Field Bytes Contents
12282 Type 8..11 3 (NT_GNU_BUILD_ID)
12286 /* FIXME: Check the name size, name and type fields. */
12288 unsigned long build_id_size
;
12289 build_id_size
= byte_get (section
->start
+ 4, 4);
12290 if (build_id_size
< 8)
12292 warn (_(".note.gnu.build-id data size is too small\n"));
12296 if (build_id_size
> (section
->size
- 16))
12298 warn (_(".note.gnu.build-id data size is too big\n"));
12303 filename
= xmalloc (strlen (".build-id/")
12304 + build_id_size
* 2 + 2
12305 + strlen (".debug")
12306 /* The next string should be the same as the longest
12307 name found in the prefixes[] array below. */
12308 + strlen ("/usrlib64/debug/usr")
12312 static const char * prefixes
[] =
12317 "/usr/lib/debug/usr/",
12318 "/usr/lib64/debug/",
12319 "/usr/lib64/debug/usr"
12321 long unsigned int i
;
12323 for (i
= 0; i
< ARRAY_SIZE (prefixes
); i
++)
12325 handle
= try_build_id_prefix (prefixes
[i
], filename
,
12326 section
->start
+ 16, build_id_size
);
12327 if (handle
!= NULL
)
12330 /* FIXME: TYhe BFD library also tries a global debugfile directory prefix. */
12331 if (handle
== NULL
)
12333 /* Failed to find a debug file associated with the build-id.
12334 This is not an error however, rather it just means that
12335 the debug info has probably not been loaded on the system,
12336 or that another method is being used to link to the debug
12342 add_separate_debug_file (filename
, handle
);
12345 /* Try to load a debug file pointed to by the .debug_sup section. */
12348 load_debug_sup_file (const char * main_filename
, void * file
)
12350 if (! load_debug_section (debug_sup
, file
))
12351 return; /* No .debug_sup section. */
12353 struct dwarf_section
* section
;
12354 section
= & debug_displays
[debug_sup
].section
;
12355 assert (section
!= NULL
);
12357 if (section
->start
== NULL
|| section
->size
< 5)
12359 warn (_(".debug_sup section is corrupt/empty\n"));
12363 if (section
->start
[2] != 0)
12364 return; /* This is a supplementary file. */
12366 const char * filename
= (const char *) section
->start
+ 3;
12367 if (strnlen (filename
, section
->size
- 3) == section
->size
- 3)
12369 warn (_("filename in .debug_sup section is corrupt\n"));
12373 if (filename
[0] != '/' && strchr (main_filename
, '/'))
12374 filename
= xasprintf ("%.*s/%s",
12375 (int) (strrchr (main_filename
, '/') - main_filename
),
12379 /* PR 27796: Make sure that we pass a filename that can be free'd to
12380 add_separate_debug_file(). */
12381 filename
= xstrdup (filename
);
12383 void * handle
= open_debug_file (filename
);
12384 if (handle
== NULL
)
12386 warn (_("unable to open file '%s' referenced from .debug_sup section\n"), filename
);
12387 free ((void *) filename
);
12391 printf (_("%s: Found supplementary debug file: %s\n\n"), main_filename
, filename
);
12393 /* FIXME: Compare the checksums, if present. */
12394 add_separate_debug_file (filename
, handle
);
12397 /* Load a debuglink section and/or a debugaltlink section, if either are present.
12398 Recursively check the loaded files for more of these sections.
12399 Also follow any links in .debug_sup sections.
12400 FIXME: Should also check for DWO_* entries in the newly loaded files. */
12403 check_for_and_load_links (void * file
, const char * filename
)
12405 void * handle
= NULL
;
12407 if (load_debug_section (gnu_debugaltlink
, file
))
12409 Build_id_data build_id_data
;
12411 handle
= load_separate_debug_info (filename
,
12412 & debug_displays
[gnu_debugaltlink
].section
,
12413 parse_gnu_debugaltlink
,
12414 check_gnu_debugaltlink
,
12419 assert (handle
== first_separate_info
->handle
);
12420 check_for_and_load_links (first_separate_info
->handle
,
12421 first_separate_info
->filename
);
12425 if (load_debug_section (gnu_debuglink
, file
))
12427 unsigned long crc32
;
12429 handle
= load_separate_debug_info (filename
,
12430 & debug_displays
[gnu_debuglink
].section
,
12431 parse_gnu_debuglink
,
12432 check_gnu_debuglink
,
12437 assert (handle
== first_separate_info
->handle
);
12438 check_for_and_load_links (first_separate_info
->handle
,
12439 first_separate_info
->filename
);
12443 load_debug_sup_file (filename
, file
);
12445 load_build_id_debug_file (filename
, file
);
12448 /* Load the separate debug info file(s) attached to FILE, if any exist.
12449 Returns TRUE if any were found, FALSE otherwise.
12450 If TRUE is returned then the linked list starting at first_separate_info
12451 will be populated with open file handles. */
12454 load_separate_debug_files (void * file
, const char * filename
)
12456 /* Skip this operation if we are not interested in debug links. */
12457 if (! do_follow_links
&& ! do_debug_links
)
12460 /* See if there are any dwo links. */
12461 if (load_debug_section (str
, file
)
12462 && load_debug_section (abbrev
, file
)
12463 && load_debug_section (info
, file
))
12465 /* Load the .debug_addr section, if it exists. */
12466 load_debug_section (debug_addr
, file
);
12467 /* Load the .debug_str_offsets section, if it exists. */
12468 load_debug_section (str_index
, file
);
12469 /* Load the .debug_loclists section, if it exists. */
12470 load_debug_section (loclists
, file
);
12471 /* Load the .debug_rnglists section, if it exists. */
12472 load_debug_section (rnglists
, file
);
12476 if (process_debug_info (& debug_displays
[info
].section
, file
, abbrev
,
12479 bool introduced
= false;
12481 const char *dir
= NULL
;
12482 const char *id
= NULL
;
12483 const char *name
= NULL
;
12485 for (dwinfo
= first_dwo_info
; dwinfo
!= NULL
; dwinfo
= dwinfo
->next
)
12487 /* Accumulate NAME, DIR and ID fields. */
12488 switch (dwinfo
->type
)
12492 warn (_("Multiple DWO_NAMEs encountered for the same CU\n"));
12493 name
= dwinfo
->value
;
12497 /* There can be multiple DW_AT_comp_dir entries in a CU,
12498 so do not complain. */
12499 dir
= dwinfo
->value
;
12504 warn (_("multiple DWO_IDs encountered for the same CU\n"));
12505 id
= dwinfo
->value
;
12509 error (_("Unexpected DWO INFO type"));
12513 /* If we have reached the end of our list, or we are changing
12514 CUs, then display the information that we have accumulated
12517 && (dwinfo
->next
== NULL
12518 || dwinfo
->next
->cu_offset
!= dwinfo
->cu_offset
))
12520 if (do_debug_links
)
12524 printf (_("The %s section contains link(s) to dwo file(s):\n\n"),
12525 debug_displays
[info
].section
.uncompressed_name
);
12529 printf (_(" Name: %s\n"), name
);
12530 printf (_(" Directory: %s\n"), dir
? dir
: _("<not-found>"));
12532 display_data (printf (_(" ID: ")), (unsigned char *) id
, 8);
12533 else if (debug_information
[0].dwarf_version
!= 5)
12534 printf (_(" ID: <not specified>\n"));
12538 if (do_follow_links
)
12539 load_dwo_file (filename
, name
, dir
, id
);
12541 name
= dir
= id
= NULL
;
12547 if (! do_follow_links
)
12548 /* The other debug links will be displayed by display_debug_links()
12549 so we do not need to do any further processing here. */
12552 /* FIXME: We do not check for the presence of both link sections in the same file. */
12553 /* FIXME: We do not check for the presence of multiple, same-name debuglink sections. */
12554 /* FIXME: We do not check for the presence of a dwo link as well as a debuglink. */
12556 check_for_and_load_links (file
, filename
);
12557 if (first_separate_info
!= NULL
)
12560 do_follow_links
= 0;
12565 free_debug_memory (void)
12569 free_all_abbrevs ();
12573 shndx_pool_size
= 0;
12574 shndx_pool_used
= 0;
12582 memset (level_type_signed
, 0, sizeof level_type_signed
);
12583 cu_tu_indexes_read
= -1;
12585 for (i
= 0; i
< max
; i
++)
12586 free_debug_section ((enum dwarf_section_display_enum
) i
);
12588 if (debug_information
!= NULL
)
12590 for (i
= 0; i
< alloc_num_debug_info_entries
; i
++)
12591 free_debug_information (&debug_information
[i
]);
12592 free (debug_information
);
12593 debug_information
= NULL
;
12594 alloc_num_debug_info_entries
= num_debug_info_entries
= 0;
12598 separate_info
* next
;
12600 for (d
= first_separate_info
; d
!= NULL
; d
= next
)
12602 close_debug_file (d
->handle
);
12603 free ((void *) d
->filename
);
12607 first_separate_info
= NULL
;
12615 const char *option
;
12618 } debug_dump_long_opts
;
12620 static const debug_dump_long_opts debug_option_table
[] =
12622 { 'A', "addr", &do_debug_addr
, 1 },
12623 { 'a', "abbrev", &do_debug_abbrevs
, 1 },
12624 { 'c', "cu_index", &do_debug_cu_index
, 1 },
12625 #ifdef HAVE_LIBDEBUGINFOD
12626 { 'D', "use-debuginfod", &use_debuginfod
, 1 },
12627 { 'E', "do-not-use-debuginfod", &use_debuginfod
, 0 },
12629 { 'F', "frames-interp", &do_debug_frames_interp
, 1 },
12630 { 'f', "frames", &do_debug_frames
, 1 },
12631 { 'g', "gdb_index", &do_gdb_index
, 1 },
12632 { 'i', "info", &do_debug_info
, 1 },
12633 { 'K', "follow-links", &do_follow_links
, 1 },
12634 { 'k', "links", &do_debug_links
, 1 },
12635 { 'L', "decodedline", &do_debug_lines
, FLAG_DEBUG_LINES_DECODED
},
12636 { 'l', "rawline", &do_debug_lines
, FLAG_DEBUG_LINES_RAW
},
12637 /* For compatibility with earlier versions of readelf. */
12638 { 'l', "line", &do_debug_lines
, FLAG_DEBUG_LINES_RAW
},
12639 { 'm', "macro", &do_debug_macinfo
, 1 },
12640 { 'N', "no-follow-links", &do_follow_links
, 0 },
12641 { 'O', "str-offsets", &do_debug_str_offsets
, 1 },
12642 { 'o', "loc", &do_debug_loc
, 1 },
12643 { 'p', "pubnames", &do_debug_pubnames
, 1 },
12644 { 'R', "Ranges", &do_debug_ranges
, 1 },
12645 { 'r', "aranges", &do_debug_aranges
, 1 },
12646 /* For compatibility with earlier versions of readelf. */
12647 { 'r', "ranges", &do_debug_aranges
, 1 },
12648 { 's', "str", &do_debug_str
, 1 },
12649 { 'T', "trace_aranges", &do_trace_aranges
, 1 },
12650 { 't', "pubtypes", &do_debug_pubtypes
, 1 },
12651 { 'U', "trace_info", &do_trace_info
, 1 },
12652 { 'u', "trace_abbrev", &do_trace_abbrevs
, 1 },
12653 { 0, NULL
, NULL
, 0 }
12656 /* Enable display of specific DWARF sections as determined by the comma
12657 separated strings in NAMES. Returns non-zero if any displaying was
12661 dwarf_select_sections_by_names (const char *names
)
12669 const debug_dump_long_opts
*entry
;
12671 for (entry
= debug_option_table
; entry
->option
; entry
++)
12673 size_t len
= strlen (entry
->option
);
12675 if (strncmp (p
, entry
->option
, len
) == 0
12676 && (p
[len
] == ',' || p
[len
] == '\0'))
12678 if (entry
->val
== 0)
12679 * entry
->variable
= 0;
12681 * entry
->variable
= entry
->val
;
12682 result
|= entry
->val
;
12689 if (entry
->option
== NULL
)
12691 warn (_("Unrecognized debug option '%s'\n"), p
);
12692 p
= strchr (p
, ',');
12701 /* The --debug-dump=frames-interp option also enables the
12702 --debug-dump=frames option. */
12703 if (do_debug_frames_interp
)
12704 do_debug_frames
= 1;
12709 /* Enable display of specific DWARF sections as determined by the characters
12710 in LETTERS. Returns non-zero if any displaying was enabled. */
12713 dwarf_select_sections_by_letters (const char *letters
)
12719 const debug_dump_long_opts
*entry
;
12721 for (entry
= debug_option_table
; entry
->letter
; entry
++)
12723 if (entry
->letter
== * letters
)
12725 if (entry
->val
== 0)
12726 * entry
->variable
= 0;
12728 * entry
->variable
|= entry
->val
;
12729 result
|= entry
->val
;
12734 if (entry
->letter
== 0)
12735 warn (_("Unrecognized debug letter option '%c'\n"), * letters
);
12740 /* The --debug-dump=frames-interp option also enables the
12741 --debug-dump=frames option. */
12742 if (do_debug_frames_interp
)
12743 do_debug_frames
= 1;
12749 dwarf_select_sections_all (void)
12752 do_debug_abbrevs
= 1;
12753 do_debug_lines
= FLAG_DEBUG_LINES_RAW
;
12754 do_debug_pubnames
= 1;
12755 do_debug_pubtypes
= 1;
12756 do_debug_aranges
= 1;
12757 do_debug_ranges
= 1;
12758 do_debug_frames
= 1;
12759 do_debug_macinfo
= 1;
12764 do_trace_abbrevs
= 1;
12765 do_trace_aranges
= 1;
12767 do_debug_cu_index
= 1;
12768 do_follow_links
= 1;
12769 do_debug_links
= 1;
12770 do_debug_str_offsets
= 1;
12773 #define NO_ABBREVS NULL, NULL, NULL, 0, 0, 0, NULL, 0
12774 #define ABBREV(N) NULL, NULL, NULL, 0, 0, N, NULL, 0
12776 /* N.B. The order here must match the order in section_display_enum. */
12778 struct dwarf_section_display debug_displays
[] =
12780 { { ".debug_abbrev", ".zdebug_abbrev", ".dwabrev", NO_ABBREVS
}, display_debug_abbrev
, &do_debug_abbrevs
, false },
12781 { { ".debug_aranges", ".zdebug_aranges", ".dwarnge", NO_ABBREVS
}, display_debug_aranges
, &do_debug_aranges
, true },
12782 { { ".debug_frame", ".zdebug_frame", ".dwframe", NO_ABBREVS
}, display_debug_frames
, &do_debug_frames
, true },
12783 { { ".debug_info", ".zdebug_info", ".dwinfo", ABBREV (abbrev
)}, display_debug_info
, &do_debug_info
, true },
12784 { { ".debug_line", ".zdebug_line", ".dwline", NO_ABBREVS
}, display_debug_lines
, &do_debug_lines
, true },
12785 { { ".debug_pubnames", ".zdebug_pubnames", ".dwpbnms", NO_ABBREVS
}, display_debug_pubnames
, &do_debug_pubnames
, false },
12786 { { ".debug_gnu_pubnames", ".zdebug_gnu_pubnames", "", NO_ABBREVS
}, display_debug_gnu_pubnames
, &do_debug_pubnames
, false },
12787 { { ".eh_frame", "", "", NO_ABBREVS
}, display_debug_frames
, &do_debug_frames
, true },
12788 { { ".eh_frame_hdr", "", "", NO_ABBREVS
}, display_eh_frame_hdr
, &do_debug_frames
, true },
12789 { { ".debug_macinfo", ".zdebug_macinfo", "", NO_ABBREVS
}, display_debug_macinfo
, &do_debug_macinfo
, false },
12790 { { ".debug_macro", ".zdebug_macro", ".dwmac", NO_ABBREVS
}, display_debug_macro
, &do_debug_macinfo
, true },
12791 { { ".debug_str", ".zdebug_str", ".dwstr", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, false },
12792 { { ".debug_line_str", ".zdebug_line_str", "", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, false },
12793 { { ".debug_loc", ".zdebug_loc", ".dwloc", NO_ABBREVS
}, display_debug_loc
, &do_debug_loc
, true },
12794 { { ".debug_loclists", ".zdebug_loclists", "", NO_ABBREVS
}, display_debug_loc
, &do_debug_loc
, true },
12795 { { ".debug_loclists.dwo", ".zdebug_loclists.dwo", "", NO_ABBREVS
}, display_debug_loc
, &do_debug_loc
, true },
12796 { { ".debug_pubtypes", ".zdebug_pubtypes", ".dwpbtyp", NO_ABBREVS
}, display_debug_pubnames
, &do_debug_pubtypes
, false },
12797 { { ".debug_gnu_pubtypes", ".zdebug_gnu_pubtypes", "", NO_ABBREVS
}, display_debug_gnu_pubnames
, &do_debug_pubtypes
, false },
12798 { { ".debug_ranges", ".zdebug_ranges", ".dwrnges", NO_ABBREVS
}, display_debug_ranges
, &do_debug_ranges
, true },
12799 { { ".debug_rnglists", ".zdebug_rnglists", "", NO_ABBREVS
}, display_debug_ranges
, &do_debug_ranges
, true },
12800 { { ".debug_rnglists.dwo", ".zdebug_rnglists.dwo", "", NO_ABBREVS
}, display_debug_ranges
, &do_debug_ranges
, true },
12801 { { ".debug_static_func", ".zdebug_static_func", "", NO_ABBREVS
}, display_debug_not_supported
, NULL
, false },
12802 { { ".debug_static_vars", ".zdebug_static_vars", "", NO_ABBREVS
}, display_debug_not_supported
, NULL
, false },
12803 { { ".debug_types", ".zdebug_types", "", ABBREV (abbrev
) }, display_debug_types
, &do_debug_info
, true },
12804 { { ".debug_weaknames", ".zdebug_weaknames", "", NO_ABBREVS
}, display_debug_not_supported
, NULL
, false },
12805 { { ".gdb_index", "", "", NO_ABBREVS
}, display_gdb_index
, &do_gdb_index
, false },
12806 { { ".debug_names", "", "", NO_ABBREVS
}, display_debug_names
, &do_gdb_index
, false },
12807 { { ".trace_info", "", "", ABBREV (trace_abbrev
) }, display_trace_info
, &do_trace_info
, true },
12808 { { ".trace_abbrev", "", "", NO_ABBREVS
}, display_debug_abbrev
, &do_trace_abbrevs
, false },
12809 { { ".trace_aranges", "", "", NO_ABBREVS
}, display_debug_aranges
, &do_trace_aranges
, false },
12810 { { ".debug_info.dwo", ".zdebug_info.dwo", "", ABBREV (abbrev_dwo
) }, display_debug_info
, &do_debug_info
, true },
12811 { { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo", "", NO_ABBREVS
}, display_debug_abbrev
, &do_debug_abbrevs
, false },
12812 { { ".debug_types.dwo", ".zdebug_types.dwo", "", ABBREV (abbrev_dwo
) }, display_debug_types
, &do_debug_info
, true },
12813 { { ".debug_line.dwo", ".zdebug_line.dwo", "", NO_ABBREVS
}, display_debug_lines
, &do_debug_lines
, true },
12814 { { ".debug_loc.dwo", ".zdebug_loc.dwo", "", NO_ABBREVS
}, display_debug_loc
, &do_debug_loc
, true },
12815 { { ".debug_macro.dwo", ".zdebug_macro.dwo", "", NO_ABBREVS
}, display_debug_macro
, &do_debug_macinfo
, true },
12816 { { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo", "", NO_ABBREVS
}, display_debug_macinfo
, &do_debug_macinfo
, false },
12817 { { ".debug_str.dwo", ".zdebug_str.dwo", "", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, true },
12818 { { ".debug_str_offsets", ".zdebug_str_offsets", "", NO_ABBREVS
}, display_debug_str_offsets
, &do_debug_str_offsets
, true },
12819 { { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo", "", NO_ABBREVS
}, display_debug_str_offsets
, &do_debug_str_offsets
, true },
12820 { { ".debug_addr", ".zdebug_addr", "", NO_ABBREVS
}, display_debug_addr
, &do_debug_addr
, true },
12821 { { ".debug_cu_index", "", "", NO_ABBREVS
}, display_cu_index
, &do_debug_cu_index
, false },
12822 { { ".debug_tu_index", "", "", NO_ABBREVS
}, display_cu_index
, &do_debug_cu_index
, false },
12823 { { ".gnu_debuglink", "", "", NO_ABBREVS
}, display_debug_links
, &do_debug_links
, false },
12824 { { ".gnu_debugaltlink", "", "", NO_ABBREVS
}, display_debug_links
, &do_debug_links
, false },
12825 { { ".debug_sup", "", "", NO_ABBREVS
}, display_debug_sup
, &do_debug_links
, false },
12826 /* Separate debug info files can containt their own .debug_str section,
12827 and this might be in *addition* to a .debug_str section already present
12828 in the main file. Hence we need to have two entries for .debug_str. */
12829 { { ".debug_str", ".zdebug_str", "", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, false },
12830 { { ".note.gnu.build-id", "", "", NO_ABBREVS
}, display_debug_not_supported
, NULL
, false },
12833 /* A static assertion. */
12834 extern int debug_displays_assert
[ARRAY_SIZE (debug_displays
) == max
? 1 : -1];