1 /* dwarf.c -- display DWARF contents of a BFD binary file
2 Copyright (C) 2005-2022 Free Software Foundation, Inc.
4 This file is part of GNU Binutils.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
22 #include "libiberty.h"
27 #include "elf/common.h"
30 #include "gdb/gdb-index.h"
31 #include "filenames.h"
32 #include "safe-ctype.h"
35 #ifdef HAVE_LIBDEBUGINFOD
36 #include <elfutils/debuginfod.h>
44 #ifndef ENABLE_CHECKING
45 #define ENABLE_CHECKING 0
50 #define MAX(a, b) ((a) > (b) ? (a) : (b))
51 #define MIN(a, b) ((a) < (b) ? (a) : (b))
53 static const char *regname (unsigned int regno
, int row
);
54 static const char *regname_internal_by_table_only (unsigned int regno
);
56 static int have_frame_base
;
57 static int need_base_address
;
59 static unsigned int num_debug_info_entries
= 0;
60 static unsigned int alloc_num_debug_info_entries
= 0;
61 static debug_info
*debug_information
= NULL
;
62 /* Special value for num_debug_info_entries to indicate
63 that the .debug_info section could not be loaded/parsed. */
64 #define DEBUG_INFO_UNAVAILABLE (unsigned int) -1
66 /* A .debug_info section can contain multiple links to separate
67 DWO object files. We use these structures to record these links. */
75 typedef struct dwo_info
80 struct dwo_info
* next
;
83 static dwo_info
*first_dwo_info
= NULL
;
84 static bool need_dwo_info
;
86 separate_info
* first_separate_info
= NULL
;
88 unsigned int eh_addr_size
;
93 int do_debug_pubnames
;
94 int do_debug_pubtypes
;
98 int do_debug_frames_interp
;
101 int do_debug_str_offsets
;
105 int do_trace_abbrevs
;
106 int do_trace_aranges
;
108 int do_debug_cu_index
;
111 int do_follow_links
= DEFAULT_FOR_FOLLOW_LINKS
;
112 #ifdef HAVE_LIBDEBUGINFOD
113 int use_debuginfod
= 1;
117 int dwarf_cutoff_level
= -1;
118 unsigned long dwarf_start_die
;
122 /* Collection of CU/TU section sets from .debug_cu_index and .debug_tu_index
123 sections. For version 1 package files, each set is stored in SHNDX_POOL
124 as a zero-terminated list of section indexes comprising one set of debug
125 sections from a .dwo file. */
127 static unsigned int *shndx_pool
= NULL
;
128 static unsigned int shndx_pool_size
= 0;
129 static unsigned int shndx_pool_used
= 0;
131 /* For version 2 package files, each set contains an array of section offsets
132 and an array of section sizes, giving the offset and size of the
133 contribution from a CU or TU within one of the debug sections.
134 When displaying debug info from a package file, we need to use these
135 tables to locate the corresponding contributions to each section. */
140 uint64_t section_offsets
[DW_SECT_MAX
];
141 size_t section_sizes
[DW_SECT_MAX
];
144 static int cu_count
= 0;
145 static int tu_count
= 0;
146 static struct cu_tu_set
*cu_sets
= NULL
;
147 static struct cu_tu_set
*tu_sets
= NULL
;
149 static bool load_cu_tu_indexes (void *);
151 /* An array that indicates for a given level of CU nesting whether
152 the latest DW_AT_type seen for that level was a signed type or
154 #define MAX_CU_NESTING (1 << 8)
155 static bool level_type_signed
[MAX_CU_NESTING
];
157 /* Values for do_debug_lines. */
158 #define FLAG_DEBUG_LINES_RAW 1
159 #define FLAG_DEBUG_LINES_DECODED 2
162 size_of_encoded_value (int encoding
)
164 switch (encoding
& 0x7)
167 case 0: return eh_addr_size
;
175 get_encoded_value (unsigned char **pdata
,
177 struct dwarf_section
*section
,
180 unsigned char * data
= * pdata
;
181 unsigned int size
= size_of_encoded_value (encoding
);
184 if (data
>= end
|| size
> (size_t) (end
- data
))
186 warn (_("Encoded value extends past end of section\n"));
191 /* PR 17512: file: 002-829853-0.004. */
194 warn (_("Encoded size of %d is too large to read\n"), size
);
199 /* PR 17512: file: 1085-5603-0.004. */
202 warn (_("Encoded size of 0 is too small to read\n"));
207 if (encoding
& DW_EH_PE_signed
)
208 val
= byte_get_signed (data
, size
);
210 val
= byte_get (data
, size
);
212 if ((encoding
& 0x70) == DW_EH_PE_pcrel
)
213 val
+= section
->address
+ (data
- section
->start
);
215 * pdata
= data
+ size
;
219 /* Print a uint64_t value (typically an address, offset or length) in
220 hexadecimal format, followed by a space. The precision displayed is
221 determined by the NUM_BYTES parameter. */
224 print_hex (uint64_t value
, unsigned num_bytes
)
229 printf ("%0*" PRIx64
" ", num_bytes
* 2,
230 value
& ~(~(uint64_t) 0 << num_bytes
* 4 << num_bytes
* 4));
233 /* Like print_hex, but no trailing space. */
236 print_hex_ns (uint64_t value
, unsigned num_bytes
)
241 printf ("%0*" PRIx64
, num_bytes
* 2,
242 value
& ~(~(uint64_t) 0 << num_bytes
* 4 << num_bytes
* 4));
245 /* Print a view number in hexadecimal value, with the same width as
246 print_hex would have printed it. */
249 print_view (uint64_t value
, unsigned num_bytes
)
254 printf ("v%0*" PRIx64
" ", num_bytes
* 2 - 1,
255 value
& ~(~(uint64_t) 0 << num_bytes
* 4 << num_bytes
* 4));
258 /* Read in a LEB128 encoded value starting at address DATA.
259 If SIGN is true, return a signed LEB128 value.
260 If LENGTH_RETURN is not NULL, return in it the number of bytes read.
261 If STATUS_RETURN is not NULL, return with bit 0 (LSB) set if the
262 terminating byte was not found and with bit 1 set if the value
263 overflows a uint64_t.
264 No bytes will be read at address END or beyond. */
267 read_leb128 (unsigned char *data
,
268 const unsigned char *const end
,
270 unsigned int *length_return
,
274 unsigned int num_read
= 0;
275 unsigned int shift
= 0;
280 unsigned char byte
= *data
++;
281 unsigned char lost
, mask
;
285 if (shift
< CHAR_BIT
* sizeof (result
))
287 result
|= ((uint64_t) (byte
& 0x7f)) << shift
;
288 /* These bits overflowed. */
289 lost
= byte
^ (result
>> shift
);
290 /* And this is the mask of possible overflow bits. */
291 mask
= 0x7f ^ ((uint64_t) 0x7f << shift
>> shift
);
299 if ((lost
& mask
) != (sign
&& (int64_t) result
< 0 ? mask
: 0))
302 if ((byte
& 0x80) == 0)
305 if (sign
&& shift
< CHAR_BIT
* sizeof (result
) && (byte
& 0x40))
306 result
|= -((uint64_t) 1 << shift
);
311 if (length_return
!= NULL
)
312 *length_return
= num_read
;
313 if (status_return
!= NULL
)
314 *status_return
= status
;
319 /* Read AMOUNT bytes from PTR and store them in VAL.
320 Checks to make sure that the read will not reach or pass END.
321 FUNC chooses whether the value read is unsigned or signed, and may
322 be either byte_get or byte_get_signed. If INC is true, PTR is
323 incremented after reading the value.
324 This macro cannot protect against PTR values derived from user input.
325 The C standard sections 6.5.6 and 6.5.8 say attempts to do so using
326 pointers is undefined behaviour. */
327 #define SAFE_BYTE_GET_INTERNAL(VAL, PTR, AMOUNT, END, FUNC, INC) \
330 size_t amount = (AMOUNT); \
331 if (sizeof (VAL) < amount) \
333 error (ngettext ("internal error: attempt to read %d byte " \
334 "of data in to %d sized variable", \
335 "internal error: attempt to read %d bytes " \
336 "of data in to %d sized variable", \
338 (int) amount, (int) sizeof (VAL)); \
339 amount = sizeof (VAL); \
341 if (ENABLE_CHECKING) \
342 assert ((PTR) <= (END)); \
343 size_t avail = (END) - (PTR); \
346 if (amount > avail) \
351 (VAL) = (FUNC) ((PTR), amount); \
357 #define SAFE_BYTE_GET(VAL, PTR, AMOUNT, END) \
358 SAFE_BYTE_GET_INTERNAL (VAL, PTR, AMOUNT, END, byte_get, false)
360 #define SAFE_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \
361 SAFE_BYTE_GET_INTERNAL (VAL, PTR, AMOUNT, END, byte_get, true)
363 #define SAFE_SIGNED_BYTE_GET(VAL, PTR, AMOUNT, END) \
364 SAFE_BYTE_GET_INTERNAL (VAL, PTR, AMOUNT, END, byte_get_signed, false)
366 #define SAFE_SIGNED_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \
367 SAFE_BYTE_GET_INTERNAL (VAL, PTR, AMOUNT, END, byte_get_signed, true)
369 typedef struct State_Machine_Registers
378 unsigned char op_index
;
379 unsigned char end_sequence
;
380 /* This variable hold the number of the last entry seen
381 in the File Table. */
382 unsigned int last_file_entry
;
385 static SMR state_machine_regs
;
388 reset_state_machine (int is_stmt
)
390 state_machine_regs
.address
= 0;
391 state_machine_regs
.view
= 0;
392 state_machine_regs
.op_index
= 0;
393 state_machine_regs
.file
= 1;
394 state_machine_regs
.line
= 1;
395 state_machine_regs
.column
= 0;
396 state_machine_regs
.is_stmt
= is_stmt
;
397 state_machine_regs
.basic_block
= 0;
398 state_machine_regs
.end_sequence
= 0;
399 state_machine_regs
.last_file_entry
= 0;
402 /* Handled an extend line op.
403 Returns the number of bytes read. */
406 process_extended_line_op (unsigned char * data
,
410 unsigned char op_code
;
411 size_t len
, header_len
;
413 unsigned char *orig_data
= data
;
416 READ_ULEB (len
, data
, end
);
417 header_len
= data
- orig_data
;
419 if (len
== 0 || data
>= end
|| len
> (size_t) (end
- data
))
421 warn (_("Badly formed extended line op encountered!\n"));
427 printf (_(" Extended opcode %d: "), op_code
);
431 case DW_LNE_end_sequence
:
432 printf (_("End of Sequence\n\n"));
433 reset_state_machine (is_stmt
);
436 case DW_LNE_set_address
:
437 /* PR 17512: file: 002-100480-0.004. */
440 warn (_("Length (%zu) of DW_LNE_set_address op is too long\n"),
445 SAFE_BYTE_GET (adr
, data
, len
- 1, end
);
446 printf (_("set Address to %#" PRIx64
"\n"), adr
);
447 state_machine_regs
.address
= adr
;
448 state_machine_regs
.view
= 0;
449 state_machine_regs
.op_index
= 0;
452 case DW_LNE_define_file
:
453 printf (_("define new File Table entry\n"));
454 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
455 printf (" %d\t", ++state_machine_regs
.last_file_entry
);
461 l
= strnlen ((char *) data
, end
- data
);
465 READ_ULEB (val
, data
, end
);
466 printf ("%" PRIu64
"\t", val
);
467 READ_ULEB (val
, data
, end
);
468 printf ("%" PRIu64
"\t", val
);
469 READ_ULEB (val
, data
, end
);
470 printf ("%" PRIu64
"\t", val
);
471 printf ("%.*s\n\n", (int) l
, name
);
474 if (((size_t) (data
- orig_data
) != len
+ header_len
) || data
>= end
)
475 warn (_("DW_LNE_define_file: Bad opcode length\n"));
478 case DW_LNE_set_discriminator
:
479 READ_ULEB (val
, data
, end
);
480 printf (_("set Discriminator to %" PRIu64
"\n"), val
);
484 case DW_LNE_HP_negate_is_UV_update
:
485 printf ("DW_LNE_HP_negate_is_UV_update\n");
487 case DW_LNE_HP_push_context
:
488 printf ("DW_LNE_HP_push_context\n");
490 case DW_LNE_HP_pop_context
:
491 printf ("DW_LNE_HP_pop_context\n");
493 case DW_LNE_HP_set_file_line_column
:
494 printf ("DW_LNE_HP_set_file_line_column\n");
496 case DW_LNE_HP_set_routine_name
:
497 printf ("DW_LNE_HP_set_routine_name\n");
499 case DW_LNE_HP_set_sequence
:
500 printf ("DW_LNE_HP_set_sequence\n");
502 case DW_LNE_HP_negate_post_semantics
:
503 printf ("DW_LNE_HP_negate_post_semantics\n");
505 case DW_LNE_HP_negate_function_exit
:
506 printf ("DW_LNE_HP_negate_function_exit\n");
508 case DW_LNE_HP_negate_front_end_logical
:
509 printf ("DW_LNE_HP_negate_front_end_logical\n");
511 case DW_LNE_HP_define_proc
:
512 printf ("DW_LNE_HP_define_proc\n");
514 case DW_LNE_HP_source_file_correlation
:
516 unsigned char *edata
= data
+ len
- 1;
518 printf ("DW_LNE_HP_source_file_correlation\n");
524 READ_ULEB (opc
, data
, edata
);
528 case DW_LNE_HP_SFC_formfeed
:
529 printf (" DW_LNE_HP_SFC_formfeed\n");
531 case DW_LNE_HP_SFC_set_listing_line
:
532 READ_ULEB (val
, data
, edata
);
533 printf (" DW_LNE_HP_SFC_set_listing_line (%" PRIu64
")\n",
536 case DW_LNE_HP_SFC_associate
:
537 printf (" DW_LNE_HP_SFC_associate ");
538 READ_ULEB (val
, data
, edata
);
539 printf ("(%" PRIu64
, val
);
540 READ_ULEB (val
, data
, edata
);
541 printf (",%" PRIu64
, val
);
542 READ_ULEB (val
, data
, edata
);
543 printf (",%" PRIu64
")\n", val
);
546 printf (_(" UNKNOWN DW_LNE_HP_SFC opcode (%u)\n"), opc
);
556 unsigned int rlen
= len
- 1;
558 if (op_code
>= DW_LNE_lo_user
559 /* The test against DW_LNW_hi_user is redundant due to
560 the limited range of the unsigned char data type used
562 /*&& op_code <= DW_LNE_hi_user*/)
563 printf (_("user defined: "));
565 printf (_("UNKNOWN: "));
566 printf (_("length %d ["), rlen
);
568 printf (" %02x", *data
++);
574 return len
+ header_len
;
577 static const unsigned char *
578 fetch_indirect_string (uint64_t offset
)
580 struct dwarf_section
*section
= &debug_displays
[str
].section
;
581 const unsigned char * ret
;
583 if (section
->start
== NULL
)
584 return (const unsigned char *) _("<no .debug_str section>");
586 if (offset
>= section
->size
)
588 warn (_("DW_FORM_strp offset too big: %#" PRIx64
"\n"), offset
);
589 return (const unsigned char *) _("<offset is too big>");
592 ret
= section
->start
+ offset
;
593 /* Unfortunately we cannot rely upon the .debug_str section ending with a
594 NUL byte. Since our caller is expecting to receive a well formed C
595 string we test for the lack of a terminating byte here. */
596 if (strnlen ((const char *) ret
, section
->size
- offset
)
597 == section
->size
- offset
)
598 ret
= (const unsigned char *)
599 _("<no NUL byte at end of .debug_str section>");
604 static const unsigned char *
605 fetch_indirect_line_string (uint64_t offset
)
607 struct dwarf_section
*section
= &debug_displays
[line_str
].section
;
608 const unsigned char * ret
;
610 if (section
->start
== NULL
)
611 return (const unsigned char *) _("<no .debug_line_str section>");
613 if (offset
>= section
->size
)
615 warn (_("DW_FORM_line_strp offset too big: %#" PRIx64
"\n"), offset
);
616 return (const unsigned char *) _("<offset is too big>");
619 ret
= section
->start
+ offset
;
620 /* Unfortunately we cannot rely upon the .debug_line_str section ending
621 with a NUL byte. Since our caller is expecting to receive a well formed
622 C string we test for the lack of a terminating byte here. */
623 if (strnlen ((const char *) ret
, section
->size
- offset
)
624 == section
->size
- offset
)
625 ret
= (const unsigned char *)
626 _("<no NUL byte at end of .debug_line_str section>");
632 fetch_indexed_string (uint64_t idx
,
633 struct cu_tu_set
*this_set
,
634 uint64_t offset_size
,
636 uint64_t str_offsets_base
)
638 enum dwarf_section_display_enum str_sec_idx
= dwo
? str_dwo
: str
;
639 enum dwarf_section_display_enum idx_sec_idx
= dwo
? str_index_dwo
: str_index
;
640 struct dwarf_section
*index_section
= &debug_displays
[idx_sec_idx
].section
;
641 struct dwarf_section
*str_section
= &debug_displays
[str_sec_idx
].section
;
642 uint64_t index_offset
;
646 if (index_section
->start
== NULL
)
647 return (dwo
? _("<no .debug_str_offsets.dwo section>")
648 : _("<no .debug_str_offsets section>"));
650 if (str_section
->start
== NULL
)
651 return (dwo
? _("<no .debug_str.dwo section>")
652 : _("<no .debug_str section>"));
654 index_offset
= idx
* offset_size
;
656 if (this_set
!= NULL
)
657 index_offset
+= this_set
->section_offsets
[DW_SECT_STR_OFFSETS
];
659 index_offset
+= str_offsets_base
;
661 if (index_offset
+ offset_size
> index_section
->size
)
663 warn (_("string index of %" PRIu64
" converts to an offset of %#" PRIx64
664 " which is too big for section %s"),
665 idx
, index_offset
, str_section
->name
);
667 return _("<string index too big>");
670 /* FIXME: If we are being paranoid then we should also check to see if
671 IDX references an entry beyond the end of the string table pointed to
672 by STR_OFFSETS_BASE. (Since there can be more than one string table
673 in a DWARF string section). */
675 str_offset
= byte_get (index_section
->start
+ index_offset
, offset_size
);
677 str_offset
-= str_section
->address
;
678 if (str_offset
>= str_section
->size
)
680 warn (_("indirect offset too big: %#" PRIx64
"\n"), str_offset
);
681 return _("<indirect index offset is too big>");
684 ret
= (const char *) str_section
->start
+ str_offset
;
686 /* Unfortunately we cannot rely upon str_section ending with a NUL byte.
687 Since our caller is expecting to receive a well formed C string we test
688 for the lack of a terminating byte here. */
689 if (strnlen (ret
, str_section
->size
- str_offset
)
690 == str_section
->size
- str_offset
)
691 return _("<no NUL byte at end of section>");
697 fetch_indexed_addr (uint64_t offset
, uint32_t num_bytes
)
699 struct dwarf_section
*section
= &debug_displays
[debug_addr
].section
;
701 if (section
->start
== NULL
)
703 warn (_("Cannot fetch indexed address: the .debug_addr section is missing\n"));
707 if (offset
+ num_bytes
> section
->size
)
709 warn (_("Offset into section %s too big: %#" PRIx64
"\n"),
710 section
->name
, offset
);
714 return byte_get (section
->start
+ offset
, num_bytes
);
717 /* Fetch a value from a debug section that has been indexed by
718 something in another section (eg DW_FORM_loclistx or DW_FORM_rnglistx).
719 Returns -1 if the value could not be found. */
722 fetch_indexed_value (uint64_t idx
,
723 enum dwarf_section_display_enum sec_enum
,
724 uint64_t base_address
)
726 struct dwarf_section
*section
= &debug_displays
[sec_enum
].section
;
728 if (section
->start
== NULL
)
730 warn (_("Unable to locate %s section\n"), section
->uncompressed_name
);
734 uint32_t pointer_size
, bias
;
736 if (byte_get (section
->start
, 4) == 0xffffffff)
747 uint64_t offset
= idx
* pointer_size
;
749 /* Offsets are biased by the size of the section header
752 offset
+= base_address
;
756 if (offset
+ pointer_size
> section
->size
)
758 warn (_("Offset into section %s too big: %#" PRIx64
"\n"),
759 section
->name
, offset
);
763 return byte_get (section
->start
+ offset
, pointer_size
);
766 /* FIXME: There are better and more efficient ways to handle
767 these structures. For now though, I just want something that
768 is simple to implement. */
769 /* Records a single attribute in an abbrev. */
770 typedef struct abbrev_attr
772 unsigned long attribute
;
774 int64_t implicit_const
;
775 struct abbrev_attr
*next
;
779 /* Records a single abbrev. */
780 typedef struct abbrev_entry
782 unsigned long number
;
785 struct abbrev_attr
* first_attr
;
786 struct abbrev_attr
* last_attr
;
787 struct abbrev_entry
* next
;
791 /* Records a set of abbreviations. */
792 typedef struct abbrev_list
794 abbrev_entry
* first_abbrev
;
795 abbrev_entry
* last_abbrev
;
797 struct abbrev_list
* next
;
798 unsigned char * start_of_next_abbrevs
;
802 /* Records all the abbrevs found so far. */
803 static struct abbrev_list
* abbrev_lists
= NULL
;
805 typedef struct abbrev_map
812 /* Maps between CU offsets and abbrev sets. */
813 static abbrev_map
* cu_abbrev_map
= NULL
;
814 static unsigned long num_abbrev_map_entries
= 0;
815 static unsigned long next_free_abbrev_map_entry
= 0;
817 #define INITIAL_NUM_ABBREV_MAP_ENTRIES 8
818 #define ABBREV_MAP_ENTRIES_INCREMENT 8
821 record_abbrev_list_for_cu (uint64_t start
, uint64_t end
,
822 abbrev_list
*list
, abbrev_list
*free_list
)
824 if (free_list
!= NULL
)
826 list
->next
= abbrev_lists
;
830 if (cu_abbrev_map
== NULL
)
832 num_abbrev_map_entries
= INITIAL_NUM_ABBREV_MAP_ENTRIES
;
833 cu_abbrev_map
= xmalloc (num_abbrev_map_entries
* sizeof (* cu_abbrev_map
));
835 else if (next_free_abbrev_map_entry
== num_abbrev_map_entries
)
837 num_abbrev_map_entries
+= ABBREV_MAP_ENTRIES_INCREMENT
;
838 cu_abbrev_map
= xrealloc (cu_abbrev_map
, num_abbrev_map_entries
* sizeof (* cu_abbrev_map
));
841 cu_abbrev_map
[next_free_abbrev_map_entry
].start
= start
;
842 cu_abbrev_map
[next_free_abbrev_map_entry
].end
= end
;
843 cu_abbrev_map
[next_free_abbrev_map_entry
].list
= list
;
844 next_free_abbrev_map_entry
++;
848 free_abbrev_list (abbrev_list
*list
)
850 abbrev_entry
*abbrv
= list
->first_abbrev
;
854 abbrev_attr
*attr
= abbrv
->first_attr
;
858 abbrev_attr
*next_attr
= attr
->next
;
863 abbrev_entry
*next_abbrev
= abbrv
->next
;
868 abbrev_list
*next
= list
->next
;
874 free_all_abbrevs (void)
877 abbrev_lists
= free_abbrev_list (abbrev_lists
);
879 free (cu_abbrev_map
);
880 cu_abbrev_map
= NULL
;
881 next_free_abbrev_map_entry
= 0;
885 find_abbrev_list_by_raw_abbrev (unsigned char *raw
)
889 for (list
= abbrev_lists
; list
!= NULL
; list
= list
->next
)
890 if (list
->raw
== raw
)
896 /* Find the abbreviation map for the CU that includes OFFSET.
897 OFFSET is an absolute offset from the start of the .debug_info section. */
898 /* FIXME: This function is going to slow down readelf & objdump.
899 Not caching abbrevs is likely the answer. */
902 find_abbrev_map_by_offset (uint64_t offset
)
906 for (i
= 0; i
< next_free_abbrev_map_entry
; i
++)
907 if (cu_abbrev_map
[i
].start
<= offset
908 && cu_abbrev_map
[i
].end
> offset
)
909 return cu_abbrev_map
+ i
;
915 add_abbrev (unsigned long number
,
920 abbrev_entry
* entry
;
922 entry
= (abbrev_entry
*) xmalloc (sizeof (*entry
));
924 entry
->number
= number
;
926 entry
->children
= children
;
927 entry
->first_attr
= NULL
;
928 entry
->last_attr
= NULL
;
931 assert (list
!= NULL
);
933 if (list
->first_abbrev
== NULL
)
934 list
->first_abbrev
= entry
;
936 list
->last_abbrev
->next
= entry
;
938 list
->last_abbrev
= entry
;
942 add_abbrev_attr (unsigned long attribute
,
944 int64_t implicit_const
,
949 attr
= (abbrev_attr
*) xmalloc (sizeof (*attr
));
951 attr
->attribute
= attribute
;
953 attr
->implicit_const
= implicit_const
;
956 assert (list
!= NULL
&& list
->last_abbrev
!= NULL
);
958 if (list
->last_abbrev
->first_attr
== NULL
)
959 list
->last_abbrev
->first_attr
= attr
;
961 list
->last_abbrev
->last_attr
->next
= attr
;
963 list
->last_abbrev
->last_attr
= attr
;
966 /* Return processed (partial) contents of a .debug_abbrev section.
967 Returns NULL on errors. */
970 process_abbrev_set (struct dwarf_section
*section
,
971 unsigned char *start
,
974 abbrev_list
*list
= xmalloc (sizeof (*list
));
975 list
->first_abbrev
= NULL
;
976 list
->last_abbrev
= NULL
;
983 unsigned long attribute
;
986 READ_ULEB (entry
, start
, end
);
988 /* A single zero is supposed to end the set according
989 to the standard. If there's more, then signal that to
991 if (start
== end
|| entry
== 0)
994 list
->start_of_next_abbrevs
= start
!= end
? start
: NULL
;
998 READ_ULEB (tag
, start
, end
);
1005 children
= *start
++;
1007 add_abbrev (entry
, tag
, children
, list
);
1012 /* Initialize it due to a false compiler warning. */
1013 int64_t implicit_const
= -1;
1015 READ_ULEB (attribute
, start
, end
);
1019 READ_ULEB (form
, start
, end
);
1023 if (form
== DW_FORM_implicit_const
)
1025 READ_SLEB (implicit_const
, start
, end
);
1030 add_abbrev_attr (attribute
, form
, implicit_const
, list
);
1032 while (attribute
!= 0);
1035 /* Report the missing single zero which ends the section. */
1036 error (_("%s section not zero terminated\n"), section
->name
);
1042 /* Return a sequence of abbrevs in SECTION starting at ABBREV_BASE
1043 plus ABBREV_OFFSET and finishing at ABBREV_BASE + ABBREV_SIZE.
1044 If FREE_LIST is non-NULL search the already decoded abbrevs on
1045 abbrev_lists first and if found set *FREE_LIST to NULL. If
1046 searching doesn't find a matching abbrev, set *FREE_LIST to the
1047 newly allocated list. If FREE_LIST is NULL, no search is done and
1048 the returned abbrev_list is always newly allocated. */
1050 static abbrev_list
*
1051 find_and_process_abbrev_set (struct dwarf_section
*section
,
1052 uint64_t abbrev_base
,
1053 uint64_t abbrev_size
,
1054 uint64_t abbrev_offset
,
1055 abbrev_list
**free_list
)
1060 if (abbrev_base
>= section
->size
1061 || abbrev_size
> section
->size
- abbrev_base
)
1063 /* PR 17531: file:4bcd9ce9. */
1064 warn (_("Debug info is corrupted, abbrev size (%#" PRIx64
")"
1065 " is larger than abbrev section size (%#" PRIx64
")\n"),
1066 abbrev_base
+ abbrev_size
, section
->size
);
1069 if (abbrev_offset
>= abbrev_size
)
1071 warn (_("Debug info is corrupted, abbrev offset (%#" PRIx64
")"
1072 " is larger than abbrev section size (%#" PRIx64
")\n"),
1073 abbrev_offset
, abbrev_size
);
1077 unsigned char *start
= section
->start
+ abbrev_base
+ abbrev_offset
;
1078 unsigned char *end
= section
->start
+ abbrev_base
+ abbrev_size
;
1079 abbrev_list
*list
= NULL
;
1081 list
= find_abbrev_list_by_raw_abbrev (start
);
1084 list
= process_abbrev_set (section
, start
, end
);
1092 get_TAG_name (uint64_t tag
)
1094 const char *name
= NULL
;
1096 if ((unsigned int) tag
== tag
)
1097 name
= get_DW_TAG_name ((unsigned int) tag
);
1100 static char buffer
[100];
1102 if (tag
>= DW_TAG_lo_user
&& tag
<= DW_TAG_hi_user
)
1103 snprintf (buffer
, sizeof (buffer
),
1104 _("User TAG value: %#" PRIx64
), tag
);
1106 snprintf (buffer
, sizeof (buffer
),
1107 _("Unknown TAG value: %#" PRIx64
), tag
);
1115 get_FORM_name (unsigned long form
)
1117 const char *name
= NULL
;
1120 return "DW_FORM value: 0";
1122 if ((unsigned int) form
== form
)
1123 name
= get_DW_FORM_name ((unsigned int) form
);
1126 static char buffer
[100];
1128 snprintf (buffer
, sizeof (buffer
), _("Unknown FORM value: %lx"), form
);
1136 get_IDX_name (unsigned long idx
)
1138 const char *name
= NULL
;
1140 if ((unsigned int) idx
== idx
)
1141 name
= get_DW_IDX_name ((unsigned int) idx
);
1144 static char buffer
[100];
1146 snprintf (buffer
, sizeof (buffer
), _("Unknown IDX value: %lx"), idx
);
1153 static unsigned char *
1154 display_block (unsigned char *data
,
1156 const unsigned char * const end
, char delimiter
)
1160 printf (_("%c%" PRIu64
" byte block: "), delimiter
, length
);
1162 return (unsigned char *) end
;
1164 maxlen
= end
- data
;
1165 length
= length
> maxlen
? maxlen
: length
;
1168 printf ("%" PRIx64
" ", byte_get (data
++, 1));
1174 decode_location_expression (unsigned char * data
,
1175 unsigned int pointer_size
,
1176 unsigned int offset_size
,
1180 struct dwarf_section
* section
)
1185 unsigned char *end
= data
+ length
;
1186 int need_frame_base
= 0;
1195 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1196 printf ("DW_OP_addr: %" PRIx64
, uvalue
);
1199 printf ("DW_OP_deref");
1202 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1203 printf ("DW_OP_const1u: %" PRIu64
, uvalue
);
1206 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 1, end
);
1207 printf ("DW_OP_const1s: %" PRId64
, svalue
);
1210 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
1211 printf ("DW_OP_const2u: %" PRIu64
, uvalue
);
1214 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1215 printf ("DW_OP_const2s: %" PRId64
, svalue
);
1218 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1219 printf ("DW_OP_const4u: %" PRIu64
, uvalue
);
1222 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
1223 printf ("DW_OP_const4s: %" PRId64
, svalue
);
1226 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 8, end
);
1227 printf ("DW_OP_const8u: %" PRIu64
, uvalue
);
1230 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 8, end
);
1231 printf ("DW_OP_const8s: %" PRId64
, svalue
);
1234 READ_ULEB (uvalue
, data
, end
);
1235 printf ("DW_OP_constu: %" PRIu64
, uvalue
);
1238 READ_SLEB (svalue
, data
, end
);
1239 printf ("DW_OP_consts: %" PRId64
, svalue
);
1242 printf ("DW_OP_dup");
1245 printf ("DW_OP_drop");
1248 printf ("DW_OP_over");
1251 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1252 printf ("DW_OP_pick: %" PRIu64
, uvalue
);
1255 printf ("DW_OP_swap");
1258 printf ("DW_OP_rot");
1261 printf ("DW_OP_xderef");
1264 printf ("DW_OP_abs");
1267 printf ("DW_OP_and");
1270 printf ("DW_OP_div");
1273 printf ("DW_OP_minus");
1276 printf ("DW_OP_mod");
1279 printf ("DW_OP_mul");
1282 printf ("DW_OP_neg");
1285 printf ("DW_OP_not");
1288 printf ("DW_OP_or");
1291 printf ("DW_OP_plus");
1293 case DW_OP_plus_uconst
:
1294 READ_ULEB (uvalue
, data
, end
);
1295 printf ("DW_OP_plus_uconst: %" PRIu64
, uvalue
);
1298 printf ("DW_OP_shl");
1301 printf ("DW_OP_shr");
1304 printf ("DW_OP_shra");
1307 printf ("DW_OP_xor");
1310 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1311 printf ("DW_OP_bra: %" PRId64
, svalue
);
1314 printf ("DW_OP_eq");
1317 printf ("DW_OP_ge");
1320 printf ("DW_OP_gt");
1323 printf ("DW_OP_le");
1326 printf ("DW_OP_lt");
1329 printf ("DW_OP_ne");
1332 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1333 printf ("DW_OP_skip: %" PRId64
, svalue
);
1368 printf ("DW_OP_lit%d", op
- DW_OP_lit0
);
1403 printf ("DW_OP_reg%d (%s)", op
- DW_OP_reg0
,
1404 regname (op
- DW_OP_reg0
, 1));
1439 READ_SLEB (svalue
, data
, end
);
1440 printf ("DW_OP_breg%d (%s): %" PRId64
,
1441 op
- DW_OP_breg0
, regname (op
- DW_OP_breg0
, 1), svalue
);
1445 READ_ULEB (uvalue
, data
, end
);
1446 printf ("DW_OP_regx: %" PRIu64
" (%s)",
1447 uvalue
, regname (uvalue
, 1));
1450 need_frame_base
= 1;
1451 READ_SLEB (svalue
, data
, end
);
1452 printf ("DW_OP_fbreg: %" PRId64
, svalue
);
1455 READ_ULEB (uvalue
, data
, end
);
1456 READ_SLEB (svalue
, data
, end
);
1457 printf ("DW_OP_bregx: %" PRIu64
" (%s) %" PRId64
,
1458 uvalue
, regname (uvalue
, 1), svalue
);
1461 READ_ULEB (uvalue
, data
, end
);
1462 printf ("DW_OP_piece: %" PRIu64
, uvalue
);
1464 case DW_OP_deref_size
:
1465 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1466 printf ("DW_OP_deref_size: %" PRIu64
, uvalue
);
1468 case DW_OP_xderef_size
:
1469 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1470 printf ("DW_OP_xderef_size: %" PRIu64
, uvalue
);
1473 printf ("DW_OP_nop");
1476 /* DWARF 3 extensions. */
1477 case DW_OP_push_object_address
:
1478 printf ("DW_OP_push_object_address");
1481 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1482 this ought to be an 8-byte wide computation. */
1483 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1484 printf ("DW_OP_call2: <%#" PRIx64
">", svalue
+ cu_offset
);
1487 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1488 this ought to be an 8-byte wide computation. */
1489 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
1490 printf ("DW_OP_call4: <%#" PRIx64
">", svalue
+ cu_offset
);
1492 case DW_OP_call_ref
:
1493 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1494 this ought to be an 8-byte wide computation. */
1495 if (dwarf_version
== -1)
1497 printf (_("(DW_OP_call_ref in frame info)"));
1498 /* No way to tell where the next op is, so just bail. */
1499 return need_frame_base
;
1501 if (dwarf_version
== 2)
1503 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1507 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1509 printf ("DW_OP_call_ref: <%#" PRIx64
">", uvalue
);
1511 case DW_OP_form_tls_address
:
1512 printf ("DW_OP_form_tls_address");
1514 case DW_OP_call_frame_cfa
:
1515 printf ("DW_OP_call_frame_cfa");
1517 case DW_OP_bit_piece
:
1518 printf ("DW_OP_bit_piece: ");
1519 READ_ULEB (uvalue
, data
, end
);
1520 printf (_("size: %" PRIu64
" "), uvalue
);
1521 READ_ULEB (uvalue
, data
, end
);
1522 printf (_("offset: %" PRIu64
" "), uvalue
);
1525 /* DWARF 4 extensions. */
1526 case DW_OP_stack_value
:
1527 printf ("DW_OP_stack_value");
1530 case DW_OP_implicit_value
:
1531 printf ("DW_OP_implicit_value");
1532 READ_ULEB (uvalue
, data
, end
);
1533 data
= display_block (data
, uvalue
, end
, ' ');
1536 /* GNU extensions. */
1537 case DW_OP_GNU_push_tls_address
:
1538 printf (_("DW_OP_GNU_push_tls_address or DW_OP_HP_unknown"));
1540 case DW_OP_GNU_uninit
:
1541 printf ("DW_OP_GNU_uninit");
1542 /* FIXME: Is there data associated with this OP ? */
1544 case DW_OP_GNU_encoded_addr
:
1551 addr
= get_encoded_value (&data
, encoding
, section
, end
);
1553 printf ("DW_OP_GNU_encoded_addr: fmt:%02x addr:", encoding
);
1554 print_hex_ns (addr
, pointer_size
);
1557 case DW_OP_implicit_pointer
:
1558 case DW_OP_GNU_implicit_pointer
:
1559 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1560 this ought to be an 8-byte wide computation. */
1561 if (dwarf_version
== -1)
1563 printf (_("(%s in frame info)"),
1564 (op
== DW_OP_implicit_pointer
1565 ? "DW_OP_implicit_pointer"
1566 : "DW_OP_GNU_implicit_pointer"));
1567 /* No way to tell where the next op is, so just bail. */
1568 return need_frame_base
;
1570 if (dwarf_version
== 2)
1572 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1576 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1578 READ_SLEB (svalue
, data
, end
);
1579 printf ("%s: <%#" PRIx64
"> %" PRId64
,
1580 (op
== DW_OP_implicit_pointer
1581 ? "DW_OP_implicit_pointer" : "DW_OP_GNU_implicit_pointer"),
1584 case DW_OP_entry_value
:
1585 case DW_OP_GNU_entry_value
:
1586 READ_ULEB (uvalue
, data
, end
);
1587 /* PR 17531: file: 0cc9cd00. */
1588 if (uvalue
> (size_t) (end
- data
))
1589 uvalue
= end
- data
;
1590 printf ("%s: (", (op
== DW_OP_entry_value
? "DW_OP_entry_value"
1591 : "DW_OP_GNU_entry_value"));
1592 if (decode_location_expression (data
, pointer_size
, offset_size
,
1593 dwarf_version
, uvalue
,
1594 cu_offset
, section
))
1595 need_frame_base
= 1;
1599 case DW_OP_const_type
:
1600 case DW_OP_GNU_const_type
:
1601 READ_ULEB (uvalue
, data
, end
);
1602 printf ("%s: <%#" PRIx64
"> ",
1603 (op
== DW_OP_const_type
? "DW_OP_const_type"
1604 : "DW_OP_GNU_const_type"),
1605 cu_offset
+ uvalue
);
1606 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1607 data
= display_block (data
, uvalue
, end
, ' ');
1609 case DW_OP_regval_type
:
1610 case DW_OP_GNU_regval_type
:
1611 READ_ULEB (uvalue
, data
, end
);
1612 printf ("%s: %" PRIu64
" (%s)",
1613 (op
== DW_OP_regval_type
? "DW_OP_regval_type"
1614 : "DW_OP_GNU_regval_type"),
1615 uvalue
, regname (uvalue
, 1));
1616 READ_ULEB (uvalue
, data
, end
);
1617 printf (" <%#" PRIx64
">", cu_offset
+ uvalue
);
1619 case DW_OP_deref_type
:
1620 case DW_OP_GNU_deref_type
:
1621 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1622 printf ("%s: %" PRId64
,
1623 (op
== DW_OP_deref_type
? "DW_OP_deref_type"
1624 : "DW_OP_GNU_deref_type"),
1626 READ_ULEB (uvalue
, data
, end
);
1627 printf (" <%#" PRIx64
">", cu_offset
+ uvalue
);
1630 case DW_OP_GNU_convert
:
1631 READ_ULEB (uvalue
, data
, end
);
1632 printf ("%s <%#" PRIx64
">",
1633 (op
== DW_OP_convert
? "DW_OP_convert" : "DW_OP_GNU_convert"),
1634 uvalue
? cu_offset
+ uvalue
: uvalue
);
1636 case DW_OP_reinterpret
:
1637 case DW_OP_GNU_reinterpret
:
1638 READ_ULEB (uvalue
, data
, end
);
1639 printf ("%s <%#" PRIx64
">",
1640 (op
== DW_OP_reinterpret
? "DW_OP_reinterpret"
1641 : "DW_OP_GNU_reinterpret"),
1642 uvalue
? cu_offset
+ uvalue
: uvalue
);
1644 case DW_OP_GNU_parameter_ref
:
1645 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1646 printf ("DW_OP_GNU_parameter_ref: <%#" PRIx64
">",
1647 cu_offset
+ uvalue
);
1650 READ_ULEB (uvalue
, data
, end
);
1651 printf ("DW_OP_addrx <%#" PRIx64
">", uvalue
);
1653 case DW_OP_GNU_addr_index
:
1654 READ_ULEB (uvalue
, data
, end
);
1655 printf ("DW_OP_GNU_addr_index <%#" PRIx64
">", uvalue
);
1657 case DW_OP_GNU_const_index
:
1658 READ_ULEB (uvalue
, data
, end
);
1659 printf ("DW_OP_GNU_const_index <%#" PRIx64
">", uvalue
);
1661 case DW_OP_GNU_variable_value
:
1662 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1663 this ought to be an 8-byte wide computation. */
1664 if (dwarf_version
== -1)
1666 printf (_("(DW_OP_GNU_variable_value in frame info)"));
1667 /* No way to tell where the next op is, so just bail. */
1668 return need_frame_base
;
1670 if (dwarf_version
== 2)
1672 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1676 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1678 printf ("DW_OP_GNU_variable_value: <%#" PRIx64
">", uvalue
);
1681 /* HP extensions. */
1682 case DW_OP_HP_is_value
:
1683 printf ("DW_OP_HP_is_value");
1684 /* FIXME: Is there data associated with this OP ? */
1686 case DW_OP_HP_fltconst4
:
1687 printf ("DW_OP_HP_fltconst4");
1688 /* FIXME: Is there data associated with this OP ? */
1690 case DW_OP_HP_fltconst8
:
1691 printf ("DW_OP_HP_fltconst8");
1692 /* FIXME: Is there data associated with this OP ? */
1694 case DW_OP_HP_mod_range
:
1695 printf ("DW_OP_HP_mod_range");
1696 /* FIXME: Is there data associated with this OP ? */
1698 case DW_OP_HP_unmod_range
:
1699 printf ("DW_OP_HP_unmod_range");
1700 /* FIXME: Is there data associated with this OP ? */
1703 printf ("DW_OP_HP_tls");
1704 /* FIXME: Is there data associated with this OP ? */
1707 /* PGI (STMicroelectronics) extensions. */
1708 case DW_OP_PGI_omp_thread_num
:
1709 /* Pushes the thread number for the current thread as it would be
1710 returned by the standard OpenMP library function:
1711 omp_get_thread_num(). The "current thread" is the thread for
1712 which the expression is being evaluated. */
1713 printf ("DW_OP_PGI_omp_thread_num");
1717 if (op
>= DW_OP_lo_user
1718 && op
<= DW_OP_hi_user
)
1719 printf (_("(User defined location op %#x)"), op
);
1721 printf (_("(Unknown location op %#x)"), op
);
1722 /* No way to tell where the next op is, so just bail. */
1723 return need_frame_base
;
1726 /* Separate the ops. */
1731 return need_frame_base
;
1734 /* Find the CU or TU set corresponding to the given CU_OFFSET.
1735 This is used for DWARF package files. */
1737 static struct cu_tu_set
*
1738 find_cu_tu_set_v2 (uint64_t cu_offset
, int do_types
)
1740 struct cu_tu_set
*p
;
1742 unsigned int dw_sect
;
1748 dw_sect
= DW_SECT_TYPES
;
1754 dw_sect
= DW_SECT_INFO
;
1758 if (p
->section_offsets
[dw_sect
] == cu_offset
)
1767 fetch_alt_indirect_string (uint64_t offset
)
1771 if (! do_follow_links
)
1774 if (first_separate_info
== NULL
)
1775 return _("<no links available>");
1777 for (i
= first_separate_info
; i
!= NULL
; i
= i
->next
)
1779 struct dwarf_section
* section
;
1782 if (! load_debug_section (separate_debug_str
, i
->handle
))
1785 section
= &debug_displays
[separate_debug_str
].section
;
1787 if (section
->start
== NULL
)
1790 if (offset
>= section
->size
)
1793 ret
= (const char *) (section
->start
+ offset
);
1794 /* Unfortunately we cannot rely upon the .debug_str section ending with a
1795 NUL byte. Since our caller is expecting to receive a well formed C
1796 string we test for the lack of a terminating byte here. */
1797 if (strnlen ((const char *) ret
, section
->size
- offset
)
1798 == section
->size
- offset
)
1799 return _("<no NUL byte at end of alt .debug_str section>");
1804 warn (_("DW_FORM_GNU_strp_alt offset (%#" PRIx64
")"
1805 " too big or no string sections available\n"), offset
);
1806 return _("<offset is too big>");
1810 get_AT_name (unsigned long attribute
)
1815 return "DW_AT value: 0";
1817 /* One value is shared by the MIPS and HP extensions: */
1818 if (attribute
== DW_AT_MIPS_fde
)
1819 return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable";
1821 name
= get_DW_AT_name (attribute
);
1825 static char buffer
[100];
1827 snprintf (buffer
, sizeof (buffer
), _("Unknown AT value: %lx"),
1836 add_dwo_info (const char * value
, uint64_t cu_offset
, dwo_type type
)
1838 dwo_info
* dwinfo
= xmalloc (sizeof * dwinfo
);
1840 dwinfo
->type
= type
;
1841 dwinfo
->value
= value
;
1842 dwinfo
->cu_offset
= cu_offset
;
1843 dwinfo
->next
= first_dwo_info
;
1844 first_dwo_info
= dwinfo
;
1848 add_dwo_name (const char * name
, uint64_t cu_offset
)
1850 add_dwo_info (name
, cu_offset
, DWO_NAME
);
1854 add_dwo_dir (const char * dir
, uint64_t cu_offset
)
1856 add_dwo_info (dir
, cu_offset
, DWO_DIR
);
1860 add_dwo_id (const char * id
, uint64_t cu_offset
)
1862 add_dwo_info (id
, cu_offset
, DWO_ID
);
1866 free_dwo_info (void)
1871 for (dwinfo
= first_dwo_info
; dwinfo
!= NULL
; dwinfo
= next
)
1873 next
= dwinfo
->next
;
1876 first_dwo_info
= NULL
;
1879 /* Ensure that START + UVALUE is less than END.
1880 Return an adjusted UVALUE if necessary to ensure this relationship. */
1882 static inline uint64_t
1883 check_uvalue (const unsigned char *start
,
1885 const unsigned char *end
)
1887 uint64_t max_uvalue
= end
- start
;
1889 /* See PR 17512: file: 008-103549-0.001:0.1.
1890 and PR 24829 for examples of where these tests are triggered. */
1891 if (uvalue
> max_uvalue
)
1893 warn (_("Corrupt attribute block length: %#" PRIx64
"\n"), uvalue
);
1894 uvalue
= max_uvalue
;
1900 static unsigned char *
1901 skip_attr_bytes (unsigned long form
,
1902 unsigned char *data
,
1904 uint64_t pointer_size
,
1905 uint64_t offset_size
,
1907 uint64_t *value_return
)
1910 uint64_t uvalue
= 0;
1917 case DW_FORM_ref_addr
:
1918 if (dwarf_version
== 2)
1919 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1920 else if (dwarf_version
> 2)
1921 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1927 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1931 case DW_FORM_line_strp
:
1932 case DW_FORM_sec_offset
:
1933 case DW_FORM_GNU_ref_alt
:
1934 case DW_FORM_GNU_strp_alt
:
1935 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1938 case DW_FORM_flag_present
:
1946 case DW_FORM_addrx1
:
1947 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1951 case DW_FORM_addrx3
:
1952 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 3, end
);
1958 case DW_FORM_addrx2
:
1959 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
1965 case DW_FORM_addrx4
:
1966 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1970 READ_SLEB (svalue
, data
, end
);
1974 case DW_FORM_ref_udata
:
1976 case DW_FORM_GNU_str_index
:
1978 case DW_FORM_GNU_addr_index
:
1980 case DW_FORM_loclistx
:
1981 case DW_FORM_rnglistx
:
1982 READ_ULEB (uvalue
, data
, end
);
1986 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 8, end
);
1990 case DW_FORM_ref_sig8
:
1994 case DW_FORM_data16
:
1998 case DW_FORM_string
:
1999 inc
= strnlen ((char *) data
, end
- data
) + 1;
2003 case DW_FORM_exprloc
:
2004 READ_ULEB (uvalue
, data
, end
);
2008 case DW_FORM_block1
:
2009 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
2013 case DW_FORM_block2
:
2014 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
2018 case DW_FORM_block4
:
2019 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
2023 case DW_FORM_indirect
:
2024 READ_ULEB (form
, data
, end
);
2025 if (form
== DW_FORM_implicit_const
)
2026 SKIP_ULEB (data
, end
);
2027 return skip_attr_bytes (form
, data
, end
, pointer_size
, offset_size
,
2028 dwarf_version
, value_return
);
2034 * value_return
= uvalue
;
2035 if (inc
<= (size_t) (end
- data
))
2042 /* Given form FORM with value UVALUE, locate and return the abbreviation
2043 associated with it. */
2045 static abbrev_entry
*
2046 get_type_abbrev_from_form (unsigned long form
,
2047 unsigned long uvalue
,
2049 unsigned char *cu_end
,
2050 const struct dwarf_section
*section
,
2051 unsigned long *abbrev_num_return
,
2052 unsigned char **data_return
,
2053 abbrev_map
**map_return
)
2055 unsigned long abbrev_number
;
2057 abbrev_entry
* entry
;
2058 unsigned char * data
;
2060 if (abbrev_num_return
!= NULL
)
2061 * abbrev_num_return
= 0;
2062 if (data_return
!= NULL
)
2063 * data_return
= NULL
;
2067 case DW_FORM_GNU_ref_alt
:
2068 case DW_FORM_ref_sig8
:
2069 /* FIXME: We are unable to handle this form at the moment. */
2072 case DW_FORM_ref_addr
:
2073 if (uvalue
>= section
->size
)
2075 warn (_("Unable to resolve ref_addr form: uvalue %lx "
2076 "> section size %" PRIx64
" (%s)\n"),
2077 uvalue
, section
->size
, section
->name
);
2082 case DW_FORM_ref_sup4
:
2083 case DW_FORM_ref_sup8
:
2090 case DW_FORM_ref_udata
:
2091 if (uvalue
+ cu_offset
< uvalue
2092 || uvalue
+ cu_offset
> (size_t) (cu_end
- section
->start
))
2094 warn (_("Unable to resolve ref form: uvalue %lx + cu_offset %" PRIx64
2095 " > CU size %tx\n"),
2096 uvalue
, cu_offset
, cu_end
- section
->start
);
2099 uvalue
+= cu_offset
;
2102 /* FIXME: Are there other DW_FORMs that can be used by types ? */
2105 warn (_("Unexpected form %lx encountered whilst finding abbreviation for type\n"), form
);
2109 data
= (unsigned char *) section
->start
+ uvalue
;
2110 map
= find_abbrev_map_by_offset (uvalue
);
2114 warn (_("Unable to find abbreviations for CU offset %#lx\n"), uvalue
);
2117 if (map
->list
== NULL
)
2119 warn (_("Empty abbreviation list encountered for CU offset %lx\n"), uvalue
);
2123 if (map_return
!= NULL
)
2125 if (form
== DW_FORM_ref_addr
)
2131 READ_ULEB (abbrev_number
, data
, section
->start
+ section
->size
);
2133 for (entry
= map
->list
->first_abbrev
; entry
!= NULL
; entry
= entry
->next
)
2134 if (entry
->number
== abbrev_number
)
2137 if (abbrev_num_return
!= NULL
)
2138 * abbrev_num_return
= abbrev_number
;
2140 if (data_return
!= NULL
)
2141 * data_return
= data
;
2144 warn (_("Unable to find entry for abbreviation %lu\n"), abbrev_number
);
2149 /* Return IS_SIGNED set to TRUE if the type using abbreviation ENTRY
2150 can be determined to be a signed type. The data for ENTRY can be
2151 found starting at DATA. */
2154 get_type_signedness (abbrev_entry
*entry
,
2155 const struct dwarf_section
*section
,
2156 unsigned char *data
,
2159 uint64_t pointer_size
,
2160 uint64_t offset_size
,
2163 unsigned int nesting
)
2167 * is_signed
= false;
2169 #define MAX_NESTING 20
2170 if (nesting
> MAX_NESTING
)
2172 /* FIXME: Warn - or is this expected ?
2173 NB/ We need to avoid infinite recursion. */
2177 for (attr
= entry
->first_attr
;
2178 attr
!= NULL
&& attr
->attribute
;
2181 unsigned char * orig_data
= data
;
2182 uint64_t uvalue
= 0;
2184 data
= skip_attr_bytes (attr
->form
, data
, end
, pointer_size
,
2185 offset_size
, dwarf_version
, & uvalue
);
2189 switch (attr
->attribute
)
2191 case DW_AT_linkage_name
:
2195 if (attr
->form
== DW_FORM_strp
)
2196 printf (", %s", fetch_indirect_string (uvalue
));
2197 else if (attr
->form
== DW_FORM_string
)
2198 printf (", %.*s", (int) (end
- orig_data
), orig_data
);
2205 abbrev_entry
*type_abbrev
;
2206 unsigned char *type_data
;
2209 type_abbrev
= get_type_abbrev_from_form (attr
->form
,
2214 NULL
/* abbrev num return */,
2217 if (type_abbrev
== NULL
)
2220 get_type_signedness (type_abbrev
, section
, type_data
,
2221 map
? section
->start
+ map
->end
: end
,
2222 map
? map
->start
: cu_offset
,
2223 pointer_size
, offset_size
, dwarf_version
,
2224 is_signed
, nesting
+ 1);
2228 case DW_AT_encoding
:
2229 /* Determine signness. */
2232 case DW_ATE_address
:
2233 /* FIXME - some architectures have signed addresses. */
2234 case DW_ATE_boolean
:
2235 case DW_ATE_unsigned
:
2236 case DW_ATE_unsigned_char
:
2237 case DW_ATE_unsigned_fixed
:
2238 * is_signed
= false;
2242 case DW_ATE_complex_float
:
2245 case DW_ATE_signed_char
:
2246 case DW_ATE_imaginary_float
:
2247 case DW_ATE_decimal_float
:
2248 case DW_ATE_signed_fixed
:
2258 read_and_print_leb128 (unsigned char *data
,
2259 unsigned int *bytes_read
,
2260 unsigned const char *end
,
2264 uint64_t val
= read_leb128 (data
, end
, is_signed
, bytes_read
, &status
);
2266 report_leb_status (status
);
2268 printf ("%" PRId64
, val
);
2270 printf ("%" PRIu64
, val
);
2274 display_discr_list (unsigned long form
,
2276 unsigned char *data
,
2279 unsigned char *end
= data
;
2283 printf ("[default]");
2290 case DW_FORM_block1
:
2291 case DW_FORM_block2
:
2292 case DW_FORM_block4
:
2293 /* Move data pointer back to the start of the byte array. */
2297 printf ("<corrupt>\n");
2298 warn (_("corrupt discr_list - not using a block form\n"));
2304 printf ("<corrupt>\n");
2305 warn (_("corrupt discr_list - block not long enough\n"));
2309 bool is_signed
= (level
> 0 && level
<= MAX_CU_NESTING
2310 ? level_type_signed
[level
- 1] : false);
2315 unsigned char discriminant
;
2316 unsigned int bytes_read
;
2318 SAFE_BYTE_GET_AND_INC (discriminant
, data
, 1, end
);
2320 switch (discriminant
)
2324 read_and_print_leb128 (data
, & bytes_read
, end
, is_signed
);
2330 read_and_print_leb128 (data
, & bytes_read
, end
, is_signed
);
2334 read_and_print_leb128 (data
, & bytes_read
, end
, is_signed
);
2339 printf ("<corrupt>\n");
2340 warn (_("corrupt discr_list - unrecognized discriminant byte %#x\n"),
2350 printf (")(signed)");
2352 printf (")(unsigned)");
2355 static unsigned char *
2356 read_and_display_attr_value (unsigned long attribute
,
2358 int64_t implicit_const
,
2359 unsigned char *start
,
2360 unsigned char *data
,
2363 uint64_t pointer_size
,
2364 uint64_t offset_size
,
2366 debug_info
*debug_info_p
,
2368 struct dwarf_section
*section
,
2369 struct cu_tu_set
*this_set
,
2374 uint64_t uvalue
= 0;
2375 uint64_t uvalue_hi
= 0;
2376 unsigned char *block_start
= NULL
;
2377 unsigned char *orig_data
= data
;
2379 if (data
> end
|| (data
== end
&& form
!= DW_FORM_flag_present
))
2381 warn (_("Corrupt attribute\n"));
2385 if (do_wide
&& ! do_loc
)
2387 /* PR 26847: Display the name of the form. */
2388 const char * name
= get_FORM_name (form
);
2390 /* For convenience we skip the DW_FORM_ prefix to the name. */
2392 name
+= 8; /* strlen ("DW_FORM_") */
2393 printf ("%c(%s)", delimiter
, name
);
2398 case DW_FORM_ref_addr
:
2399 if (dwarf_version
== 2)
2400 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
2401 else if (dwarf_version
> 2)
2402 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
2404 error (_("Internal error: DW_FORM_ref_addr is not supported in DWARF version 1.\n"));
2408 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
2411 case DW_FORM_strp_sup
:
2413 case DW_FORM_line_strp
:
2414 case DW_FORM_sec_offset
:
2415 case DW_FORM_GNU_ref_alt
:
2416 case DW_FORM_GNU_strp_alt
:
2417 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
2420 case DW_FORM_flag_present
:
2428 case DW_FORM_addrx1
:
2429 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
2435 case DW_FORM_addrx2
:
2436 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
2440 case DW_FORM_addrx3
:
2441 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 3, end
);
2444 case DW_FORM_ref_sup4
:
2448 case DW_FORM_addrx4
:
2449 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
2452 case DW_FORM_ref_sup8
:
2455 case DW_FORM_ref_sig8
:
2456 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 8, end
);
2459 case DW_FORM_data16
:
2460 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 8, end
);
2461 SAFE_BYTE_GET_AND_INC (uvalue_hi
, data
, 8, end
);
2462 if (byte_get
!= byte_get_little_endian
)
2464 uint64_t utmp
= uvalue
;
2471 READ_SLEB (svalue
, data
, end
);
2475 case DW_FORM_GNU_str_index
:
2477 case DW_FORM_ref_udata
:
2479 case DW_FORM_GNU_addr_index
:
2481 case DW_FORM_loclistx
:
2482 case DW_FORM_rnglistx
:
2483 READ_ULEB (uvalue
, data
, end
);
2486 case DW_FORM_indirect
:
2487 READ_ULEB (form
, data
, end
);
2489 printf ("%c%s", delimiter
, get_FORM_name (form
));
2490 if (form
== DW_FORM_implicit_const
)
2491 READ_SLEB (implicit_const
, data
, end
);
2492 return read_and_display_attr_value (attribute
, form
, implicit_const
,
2494 cu_offset
, pointer_size
,
2495 offset_size
, dwarf_version
,
2496 debug_info_p
, do_loc
,
2497 section
, this_set
, delimiter
, level
);
2499 case DW_FORM_implicit_const
:
2500 uvalue
= implicit_const
;
2509 case DW_FORM_ref_addr
:
2511 printf ("%c<%#" PRIx64
">", delimiter
, uvalue
);
2514 case DW_FORM_GNU_ref_alt
:
2518 /* We have already printed the form name. */
2519 printf ("%c<%#" PRIx64
">", delimiter
, uvalue
);
2521 printf ("%c<alt %#" PRIx64
">", delimiter
, uvalue
);
2523 /* FIXME: Follow the reference... */
2529 case DW_FORM_ref_sup4
:
2530 case DW_FORM_ref_udata
:
2532 printf ("%c<%#" PRIx64
">", delimiter
, uvalue
+ cu_offset
);
2537 case DW_FORM_sec_offset
:
2539 printf ("%c%#" PRIx64
, delimiter
, uvalue
);
2542 case DW_FORM_flag_present
:
2548 printf ("%c%" PRId64
, delimiter
, uvalue
);
2553 printf ("%c%" PRIu64
, delimiter
, uvalue
);
2556 case DW_FORM_implicit_const
:
2558 printf ("%c%" PRId64
, delimiter
, implicit_const
);
2561 case DW_FORM_ref_sup8
:
2566 uint64_t utmp
= uvalue
;
2567 if (form
== DW_FORM_ref8
)
2569 printf ("%c%#" PRIx64
, delimiter
, utmp
);
2573 case DW_FORM_data16
:
2577 printf (" %#" PRIx64
, uvalue
);
2579 printf (" %#" PRIx64
"%016" PRIx64
, uvalue_hi
, uvalue
);
2583 case DW_FORM_string
:
2585 printf ("%c%.*s", delimiter
, (int) (end
- data
), data
);
2586 data
+= strnlen ((char *) data
, end
- data
);
2592 case DW_FORM_exprloc
:
2593 READ_ULEB (uvalue
, data
, end
);
2596 if (block_start
>= end
)
2598 warn (_("Block ends prematurely\n"));
2603 uvalue
= check_uvalue (block_start
, uvalue
, end
);
2605 data
= block_start
+ uvalue
;
2610 SAFE_BYTE_GET (op
, block_start
, sizeof (op
), end
);
2611 if (op
!= DW_OP_addrx
)
2612 data
= display_block (block_start
, uvalue
, end
, delimiter
);
2616 case DW_FORM_block1
:
2617 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
2620 case DW_FORM_block2
:
2621 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
2624 case DW_FORM_block4
:
2625 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
2632 /* We have already displayed the form name. */
2633 printf (_("%c(offset: %#" PRIx64
"): %s"),
2634 delimiter
, uvalue
, fetch_indirect_string (uvalue
));
2636 printf (_("%c(indirect string, offset: %#" PRIx64
"): %s"),
2637 delimiter
, uvalue
, fetch_indirect_string (uvalue
));
2641 case DW_FORM_line_strp
:
2645 /* We have already displayed the form name. */
2646 printf (_("%c(offset: %#" PRIx64
"): %s"),
2647 delimiter
, uvalue
, fetch_indirect_line_string (uvalue
));
2649 printf (_("%c(indirect line string, offset: %#" PRIx64
"): %s"),
2650 delimiter
, uvalue
, fetch_indirect_line_string (uvalue
));
2654 case DW_FORM_GNU_str_index
:
2662 const char *suffix
= section
? strrchr (section
->name
, '.') : NULL
;
2663 bool dwo
= suffix
&& strcmp (suffix
, ".dwo") == 0;
2666 strng
= fetch_indexed_string (uvalue
, this_set
, offset_size
, dwo
,
2667 debug_info_p
? debug_info_p
->str_offsets_base
: 0);
2669 /* We have already displayed the form name. */
2670 printf (_("%c(offset: %#" PRIx64
"): %s"),
2671 delimiter
, uvalue
, strng
);
2673 printf (_("%c(indexed string: %#" PRIx64
"): %s"),
2674 delimiter
, uvalue
, strng
);
2678 case DW_FORM_GNU_strp_alt
:
2682 /* We have already displayed the form name. */
2683 printf (_("%c(offset: %#" PRIx64
") %s"),
2684 delimiter
, uvalue
, fetch_alt_indirect_string (uvalue
));
2686 printf (_("%c(alt indirect string, offset: %#" PRIx64
") %s"),
2687 delimiter
, uvalue
, fetch_alt_indirect_string (uvalue
));
2691 case DW_FORM_indirect
:
2692 /* Handled above. */
2695 case DW_FORM_ref_sig8
:
2697 printf ("%c%s: %#" PRIx64
, delimiter
, do_wide
? "" : "signature",
2701 case DW_FORM_GNU_addr_index
:
2703 case DW_FORM_addrx1
:
2704 case DW_FORM_addrx2
:
2705 case DW_FORM_addrx3
:
2706 case DW_FORM_addrx4
:
2707 case DW_FORM_loclistx
:
2708 case DW_FORM_rnglistx
:
2712 const char *suffix
= strrchr (section
->name
, '.');
2713 bool dwo
= suffix
&& strcmp (suffix
, ".dwo") == 0;
2715 if (form
== DW_FORM_loclistx
)
2719 idx
= fetch_indexed_value (uvalue
, loclists_dwo
, 0);
2720 if (idx
!= (uint64_t) -1)
2721 idx
+= (offset_size
== 8) ? 20 : 12;
2723 else if (debug_info_p
== NULL
)
2725 idx
= fetch_indexed_value (uvalue
, loclists
, 0);
2729 /* We want to compute:
2730 idx = fetch_indexed_value (uvalue, loclists, debug_info_p->loclists_base);
2731 idx += debug_info_p->loclists_base;
2732 Fortunately we already have that sum cached in the
2733 loc_offsets array. */
2734 if (uvalue
< debug_info_p
->num_loc_offsets
)
2735 idx
= debug_info_p
->loc_offsets
[uvalue
];
2738 warn (_("loc_offset %" PRIu64
" too big\n"), uvalue
);
2743 else if (form
== DW_FORM_rnglistx
)
2747 idx
= fetch_indexed_value (uvalue
, rnglists_dwo
, 0);
2748 if (idx
!= (uint64_t) -1)
2749 idx
+= (offset_size
== 8) ? 20 : 12;
2753 if (debug_info_p
== NULL
)
2756 base
= debug_info_p
->rnglists_base
;
2757 /* We do not have a cached value this time, so we perform the
2758 computation manually. */
2759 idx
= fetch_indexed_value (uvalue
, rnglists
, base
);
2760 if (idx
!= (uint64_t) -1)
2766 if (debug_info_p
== NULL
)
2768 else if (debug_info_p
->addr_base
== DEBUG_INFO_UNAVAILABLE
)
2771 base
= debug_info_p
->addr_base
;
2773 base
+= uvalue
* pointer_size
;
2774 idx
= fetch_indexed_addr (base
, pointer_size
);
2777 /* We have already displayed the form name. */
2778 if (idx
!= (uint64_t) -1)
2779 printf (_("%c(index: %#" PRIx64
"): %#" PRIx64
),
2780 delimiter
, uvalue
, idx
);
2784 case DW_FORM_strp_sup
:
2786 printf ("%c<%#" PRIx64
">", delimiter
, uvalue
+ cu_offset
);
2790 warn (_("Unrecognized form: %#lx\n"), form
);
2791 /* What to do? Consume a byte maybe? */
2796 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
|| do_debug_info
)
2797 && num_debug_info_entries
== 0
2798 && debug_info_p
!= NULL
)
2802 case DW_AT_loclists_base
:
2803 if (debug_info_p
->loclists_base
)
2804 warn (_("CU @ %#" PRIx64
" has multiple loclists_base values "
2805 "(%#" PRIx64
" and %#" PRIx64
")"),
2806 debug_info_p
->cu_offset
,
2807 debug_info_p
->loclists_base
, uvalue
);
2808 debug_info_p
->loclists_base
= uvalue
;
2810 case DW_AT_rnglists_base
:
2811 if (debug_info_p
->rnglists_base
)
2812 warn (_("CU @ %#" PRIx64
" has multiple rnglists_base values "
2813 "(%#" PRIx64
" and %#" PRIx64
")"),
2814 debug_info_p
->cu_offset
,
2815 debug_info_p
->rnglists_base
, uvalue
);
2816 debug_info_p
->rnglists_base
= uvalue
;
2818 case DW_AT_str_offsets_base
:
2819 if (debug_info_p
->str_offsets_base
)
2820 warn (_("CU @ %#" PRIx64
" has multiple str_offsets_base values "
2821 "%#" PRIx64
" and %#" PRIx64
")"),
2822 debug_info_p
->cu_offset
,
2823 debug_info_p
->str_offsets_base
, uvalue
);
2824 debug_info_p
->str_offsets_base
= uvalue
;
2827 case DW_AT_frame_base
:
2828 have_frame_base
= 1;
2830 case DW_AT_location
:
2831 case DW_AT_GNU_locviews
:
2832 case DW_AT_string_length
:
2833 case DW_AT_return_addr
:
2834 case DW_AT_data_member_location
:
2835 case DW_AT_vtable_elem_location
:
2837 case DW_AT_static_link
:
2838 case DW_AT_use_location
:
2839 case DW_AT_call_value
:
2840 case DW_AT_GNU_call_site_value
:
2841 case DW_AT_call_data_value
:
2842 case DW_AT_GNU_call_site_data_value
:
2843 case DW_AT_call_target
:
2844 case DW_AT_GNU_call_site_target
:
2845 case DW_AT_call_target_clobbered
:
2846 case DW_AT_GNU_call_site_target_clobbered
:
2847 if ((dwarf_version
< 4
2848 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
2849 || form
== DW_FORM_sec_offset
2850 || form
== DW_FORM_loclistx
)
2852 /* Process location list. */
2853 unsigned int lmax
= debug_info_p
->max_loc_offsets
;
2854 unsigned int num
= debug_info_p
->num_loc_offsets
;
2856 if (lmax
== 0 || num
>= lmax
)
2859 debug_info_p
->loc_offsets
= (uint64_t *)
2860 xcrealloc (debug_info_p
->loc_offsets
,
2861 lmax
, sizeof (*debug_info_p
->loc_offsets
));
2862 debug_info_p
->loc_views
= (uint64_t *)
2863 xcrealloc (debug_info_p
->loc_views
,
2864 lmax
, sizeof (*debug_info_p
->loc_views
));
2865 debug_info_p
->have_frame_base
= (int *)
2866 xcrealloc (debug_info_p
->have_frame_base
,
2867 lmax
, sizeof (*debug_info_p
->have_frame_base
));
2868 debug_info_p
->max_loc_offsets
= lmax
;
2870 if (form
== DW_FORM_loclistx
)
2871 uvalue
= fetch_indexed_value (num
, loclists
, debug_info_p
->loclists_base
);
2872 else if (this_set
!= NULL
)
2873 uvalue
+= this_set
->section_offsets
[DW_SECT_LOC
];
2875 debug_info_p
->have_frame_base
[num
] = have_frame_base
;
2876 if (attribute
!= DW_AT_GNU_locviews
)
2878 uvalue
+= debug_info_p
->loclists_base
;
2880 /* Corrupt DWARF info can produce more offsets than views.
2881 See PR 23062 for an example. */
2882 if (debug_info_p
->num_loc_offsets
2883 > debug_info_p
->num_loc_views
)
2884 warn (_("More location offset attributes than DW_AT_GNU_locview attributes\n"));
2887 debug_info_p
->loc_offsets
[num
] = uvalue
;
2888 debug_info_p
->num_loc_offsets
++;
2893 assert (debug_info_p
->num_loc_views
<= num
);
2894 num
= debug_info_p
->num_loc_views
;
2895 if (num
> debug_info_p
->num_loc_offsets
)
2896 warn (_("More DW_AT_GNU_locview attributes than location offset attributes\n"));
2899 debug_info_p
->loc_views
[num
] = uvalue
;
2900 debug_info_p
->num_loc_views
++;
2907 if (need_base_address
)
2908 debug_info_p
->base_address
= uvalue
;
2911 case DW_AT_GNU_addr_base
:
2912 case DW_AT_addr_base
:
2913 debug_info_p
->addr_base
= uvalue
;
2916 case DW_AT_GNU_ranges_base
:
2917 debug_info_p
->ranges_base
= uvalue
;
2921 if ((dwarf_version
< 4
2922 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
2923 || form
== DW_FORM_sec_offset
2924 || form
== DW_FORM_rnglistx
)
2926 /* Process range list. */
2927 unsigned int lmax
= debug_info_p
->max_range_lists
;
2928 unsigned int num
= debug_info_p
->num_range_lists
;
2930 if (lmax
== 0 || num
>= lmax
)
2933 debug_info_p
->range_lists
= (uint64_t *)
2934 xcrealloc (debug_info_p
->range_lists
,
2935 lmax
, sizeof (*debug_info_p
->range_lists
));
2936 debug_info_p
->max_range_lists
= lmax
;
2939 if (form
== DW_FORM_rnglistx
)
2940 uvalue
= fetch_indexed_value (uvalue
, rnglists
, 0);
2942 debug_info_p
->range_lists
[num
] = uvalue
;
2943 debug_info_p
->num_range_lists
++;
2947 case DW_AT_GNU_dwo_name
:
2948 case DW_AT_dwo_name
:
2953 add_dwo_name ((const char *) fetch_indirect_string (uvalue
), cu_offset
);
2955 case DW_FORM_GNU_strp_alt
:
2956 add_dwo_name ((const char *) fetch_alt_indirect_string (uvalue
), cu_offset
);
2958 case DW_FORM_GNU_str_index
:
2964 add_dwo_name (fetch_indexed_string (uvalue
, this_set
, offset_size
, false,
2965 debug_info_p
->str_offsets_base
),
2968 case DW_FORM_string
:
2969 add_dwo_name ((const char *) orig_data
, cu_offset
);
2972 warn (_("Unsupported form (%s) for attribute %s\n"),
2973 get_FORM_name (form
), get_AT_name (attribute
));
2978 case DW_AT_comp_dir
:
2979 /* FIXME: Also extract a build-id in a CU/TU. */
2984 add_dwo_dir ((const char *) fetch_indirect_string (uvalue
), cu_offset
);
2986 case DW_FORM_GNU_strp_alt
:
2987 add_dwo_dir (fetch_alt_indirect_string (uvalue
), cu_offset
);
2989 case DW_FORM_line_strp
:
2990 add_dwo_dir ((const char *) fetch_indirect_line_string (uvalue
), cu_offset
);
2992 case DW_FORM_GNU_str_index
:
2998 add_dwo_dir (fetch_indexed_string (uvalue
, this_set
, offset_size
, false,
2999 debug_info_p
->str_offsets_base
),
3002 case DW_FORM_string
:
3003 add_dwo_dir ((const char *) orig_data
, cu_offset
);
3006 warn (_("Unsupported form (%s) for attribute %s\n"),
3007 get_FORM_name (form
), get_AT_name (attribute
));
3012 case DW_AT_GNU_dwo_id
:
3017 /* FIXME: Record the length of the ID as well ? */
3018 add_dwo_id ((const char *) (data
- 8), cu_offset
);
3021 warn (_("Unsupported form (%s) for attribute %s\n"),
3022 get_FORM_name (form
), get_AT_name (attribute
));
3032 if (do_loc
|| attribute
== 0)
3035 /* For some attributes we can display further information. */
3039 if (level
>= 0 && level
< MAX_CU_NESTING
3040 && uvalue
< (size_t) (end
- start
))
3042 bool is_signed
= false;
3043 abbrev_entry
*type_abbrev
;
3044 unsigned char *type_data
;
3047 type_abbrev
= get_type_abbrev_from_form (form
, uvalue
,
3051 if (type_abbrev
!= NULL
)
3053 get_type_signedness (type_abbrev
, section
, type_data
,
3054 map
? section
->start
+ map
->end
: end
,
3055 map
? map
->start
: cu_offset
,
3056 pointer_size
, offset_size
, dwarf_version
,
3059 level_type_signed
[level
] = is_signed
;
3067 case DW_INL_not_inlined
:
3068 printf (_("(not inlined)"));
3070 case DW_INL_inlined
:
3071 printf (_("(inlined)"));
3073 case DW_INL_declared_not_inlined
:
3074 printf (_("(declared as inline but ignored)"));
3076 case DW_INL_declared_inlined
:
3077 printf (_("(declared as inline and inlined)"));
3080 printf (_(" (Unknown inline attribute value: %#" PRIx64
")"),
3086 case DW_AT_language
:
3090 /* Ordered by the numeric value of these constants. */
3091 case DW_LANG_C89
: printf ("(ANSI C)"); break;
3092 case DW_LANG_C
: printf ("(non-ANSI C)"); break;
3093 case DW_LANG_Ada83
: printf ("(Ada)"); break;
3094 case DW_LANG_C_plus_plus
: printf ("(C++)"); break;
3095 case DW_LANG_Cobol74
: printf ("(Cobol 74)"); break;
3096 case DW_LANG_Cobol85
: printf ("(Cobol 85)"); break;
3097 case DW_LANG_Fortran77
: printf ("(FORTRAN 77)"); break;
3098 case DW_LANG_Fortran90
: printf ("(Fortran 90)"); break;
3099 case DW_LANG_Pascal83
: printf ("(ANSI Pascal)"); break;
3100 case DW_LANG_Modula2
: printf ("(Modula 2)"); break;
3101 /* DWARF 2.1 values. */
3102 case DW_LANG_Java
: printf ("(Java)"); break;
3103 case DW_LANG_C99
: printf ("(ANSI C99)"); break;
3104 case DW_LANG_Ada95
: printf ("(ADA 95)"); break;
3105 case DW_LANG_Fortran95
: printf ("(Fortran 95)"); break;
3106 /* DWARF 3 values. */
3107 case DW_LANG_PLI
: printf ("(PLI)"); break;
3108 case DW_LANG_ObjC
: printf ("(Objective C)"); break;
3109 case DW_LANG_ObjC_plus_plus
: printf ("(Objective C++)"); break;
3110 case DW_LANG_UPC
: printf ("(Unified Parallel C)"); break;
3111 case DW_LANG_D
: printf ("(D)"); break;
3112 /* DWARF 4 values. */
3113 case DW_LANG_Python
: printf ("(Python)"); break;
3114 /* DWARF 5 values. */
3115 case DW_LANG_OpenCL
: printf ("(OpenCL)"); break;
3116 case DW_LANG_Go
: printf ("(Go)"); break;
3117 case DW_LANG_Modula3
: printf ("(Modula 3)"); break;
3118 case DW_LANG_Haskell
: printf ("(Haskell)"); break;
3119 case DW_LANG_C_plus_plus_03
: printf ("(C++03)"); break;
3120 case DW_LANG_C_plus_plus_11
: printf ("(C++11)"); break;
3121 case DW_LANG_OCaml
: printf ("(OCaml)"); break;
3122 case DW_LANG_Rust
: printf ("(Rust)"); break;
3123 case DW_LANG_C11
: printf ("(C11)"); break;
3124 case DW_LANG_Swift
: printf ("(Swift)"); break;
3125 case DW_LANG_Julia
: printf ("(Julia)"); break;
3126 case DW_LANG_Dylan
: printf ("(Dylan)"); break;
3127 case DW_LANG_C_plus_plus_14
: printf ("(C++14)"); break;
3128 case DW_LANG_Fortran03
: printf ("(Fortran 03)"); break;
3129 case DW_LANG_Fortran08
: printf ("(Fortran 08)"); break;
3130 case DW_LANG_RenderScript
: printf ("(RenderScript)"); break;
3131 /* MIPS extension. */
3132 case DW_LANG_Mips_Assembler
: printf ("(MIPS assembler)"); break;
3133 /* UPC extension. */
3134 case DW_LANG_Upc
: printf ("(Unified Parallel C)"); break;
3136 if (uvalue
>= DW_LANG_lo_user
&& uvalue
<= DW_LANG_hi_user
)
3137 printf (_("(implementation defined: %#" PRIx64
")"), uvalue
);
3139 printf (_("(unknown: %#" PRIx64
")"), uvalue
);
3144 case DW_AT_encoding
:
3148 case DW_ATE_void
: printf ("(void)"); break;
3149 case DW_ATE_address
: printf ("(machine address)"); break;
3150 case DW_ATE_boolean
: printf ("(boolean)"); break;
3151 case DW_ATE_complex_float
: printf ("(complex float)"); break;
3152 case DW_ATE_float
: printf ("(float)"); break;
3153 case DW_ATE_signed
: printf ("(signed)"); break;
3154 case DW_ATE_signed_char
: printf ("(signed char)"); break;
3155 case DW_ATE_unsigned
: printf ("(unsigned)"); break;
3156 case DW_ATE_unsigned_char
: printf ("(unsigned char)"); break;
3157 /* DWARF 2.1 values: */
3158 case DW_ATE_imaginary_float
: printf ("(imaginary float)"); break;
3159 case DW_ATE_decimal_float
: printf ("(decimal float)"); break;
3160 /* DWARF 3 values: */
3161 case DW_ATE_packed_decimal
: printf ("(packed_decimal)"); break;
3162 case DW_ATE_numeric_string
: printf ("(numeric_string)"); break;
3163 case DW_ATE_edited
: printf ("(edited)"); break;
3164 case DW_ATE_signed_fixed
: printf ("(signed_fixed)"); break;
3165 case DW_ATE_unsigned_fixed
: printf ("(unsigned_fixed)"); break;
3166 /* DWARF 4 values: */
3167 case DW_ATE_UTF
: printf ("(unicode string)"); break;
3168 /* DWARF 5 values: */
3169 case DW_ATE_UCS
: printf ("(UCS)"); break;
3170 case DW_ATE_ASCII
: printf ("(ASCII)"); break;
3172 /* HP extensions: */
3173 case DW_ATE_HP_float80
: printf ("(HP_float80)"); break;
3174 case DW_ATE_HP_complex_float80
: printf ("(HP_complex_float80)"); break;
3175 case DW_ATE_HP_float128
: printf ("(HP_float128)"); break;
3176 case DW_ATE_HP_complex_float128
:printf ("(HP_complex_float128)"); break;
3177 case DW_ATE_HP_floathpintel
: printf ("(HP_floathpintel)"); break;
3178 case DW_ATE_HP_imaginary_float80
: printf ("(HP_imaginary_float80)"); break;
3179 case DW_ATE_HP_imaginary_float128
: printf ("(HP_imaginary_float128)"); break;
3182 if (uvalue
>= DW_ATE_lo_user
3183 && uvalue
<= DW_ATE_hi_user
)
3184 printf (_("(user defined type)"));
3186 printf (_("(unknown type)"));
3191 case DW_AT_accessibility
:
3195 case DW_ACCESS_public
: printf ("(public)"); break;
3196 case DW_ACCESS_protected
: printf ("(protected)"); break;
3197 case DW_ACCESS_private
: printf ("(private)"); break;
3199 printf (_("(unknown accessibility)"));
3204 case DW_AT_visibility
:
3208 case DW_VIS_local
: printf ("(local)"); break;
3209 case DW_VIS_exported
: printf ("(exported)"); break;
3210 case DW_VIS_qualified
: printf ("(qualified)"); break;
3211 default: printf (_("(unknown visibility)")); break;
3215 case DW_AT_endianity
:
3219 case DW_END_default
: printf ("(default)"); break;
3220 case DW_END_big
: printf ("(big)"); break;
3221 case DW_END_little
: printf ("(little)"); break;
3223 if (uvalue
>= DW_END_lo_user
&& uvalue
<= DW_END_hi_user
)
3224 printf (_("(user specified)"));
3226 printf (_("(unknown endianity)"));
3231 case DW_AT_virtuality
:
3235 case DW_VIRTUALITY_none
: printf ("(none)"); break;
3236 case DW_VIRTUALITY_virtual
: printf ("(virtual)"); break;
3237 case DW_VIRTUALITY_pure_virtual
:printf ("(pure_virtual)"); break;
3238 default: printf (_("(unknown virtuality)")); break;
3242 case DW_AT_identifier_case
:
3246 case DW_ID_case_sensitive
: printf ("(case_sensitive)"); break;
3247 case DW_ID_up_case
: printf ("(up_case)"); break;
3248 case DW_ID_down_case
: printf ("(down_case)"); break;
3249 case DW_ID_case_insensitive
: printf ("(case_insensitive)"); break;
3250 default: printf (_("(unknown case)")); break;
3254 case DW_AT_calling_convention
:
3258 case DW_CC_normal
: printf ("(normal)"); break;
3259 case DW_CC_program
: printf ("(program)"); break;
3260 case DW_CC_nocall
: printf ("(nocall)"); break;
3261 case DW_CC_pass_by_reference
: printf ("(pass by ref)"); break;
3262 case DW_CC_pass_by_value
: printf ("(pass by value)"); break;
3263 case DW_CC_GNU_renesas_sh
: printf ("(Rensas SH)"); break;
3264 case DW_CC_GNU_borland_fastcall_i386
: printf ("(Borland fastcall i386)"); break;
3266 if (uvalue
>= DW_CC_lo_user
3267 && uvalue
<= DW_CC_hi_user
)
3268 printf (_("(user defined)"));
3270 printf (_("(unknown convention)"));
3274 case DW_AT_ordering
:
3279 case -1: printf (_("(undefined)")); break;
3280 case 0: printf ("(row major)"); break;
3281 case 1: printf ("(column major)"); break;
3285 case DW_AT_decimal_sign
:
3289 case DW_DS_unsigned
: printf (_("(unsigned)")); break;
3290 case DW_DS_leading_overpunch
: printf (_("(leading overpunch)")); break;
3291 case DW_DS_trailing_overpunch
: printf (_("(trailing overpunch)")); break;
3292 case DW_DS_leading_separate
: printf (_("(leading separate)")); break;
3293 case DW_DS_trailing_separate
: printf (_("(trailing separate)")); break;
3294 default: printf (_("(unrecognised)")); break;
3298 case DW_AT_defaulted
:
3302 case DW_DEFAULTED_no
: printf (_("(no)")); break;
3303 case DW_DEFAULTED_in_class
: printf (_("(in class)")); break;
3304 case DW_DEFAULTED_out_of_class
: printf (_("(out of class)")); break;
3305 default: printf (_("(unrecognised)")); break;
3309 case DW_AT_discr_list
:
3311 display_discr_list (form
, uvalue
, data
, level
);
3314 case DW_AT_frame_base
:
3315 have_frame_base
= 1;
3317 case DW_AT_location
:
3318 case DW_AT_loclists_base
:
3319 case DW_AT_rnglists_base
:
3320 case DW_AT_str_offsets_base
:
3321 case DW_AT_string_length
:
3322 case DW_AT_return_addr
:
3323 case DW_AT_data_member_location
:
3324 case DW_AT_vtable_elem_location
:
3326 case DW_AT_static_link
:
3327 case DW_AT_use_location
:
3328 case DW_AT_call_value
:
3329 case DW_AT_GNU_call_site_value
:
3330 case DW_AT_call_data_value
:
3331 case DW_AT_GNU_call_site_data_value
:
3332 case DW_AT_call_target
:
3333 case DW_AT_GNU_call_site_target
:
3334 case DW_AT_call_target_clobbered
:
3335 case DW_AT_GNU_call_site_target_clobbered
:
3336 if ((dwarf_version
< 4
3337 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
3338 || form
== DW_FORM_sec_offset
3339 || form
== DW_FORM_loclistx
)
3341 if (attribute
!= DW_AT_rnglists_base
3342 && attribute
!= DW_AT_str_offsets_base
)
3343 printf (_(" (location list)"));
3346 case DW_AT_allocated
:
3347 case DW_AT_associated
:
3348 case DW_AT_data_location
:
3350 case DW_AT_upper_bound
:
3351 case DW_AT_lower_bound
:
3355 int need_frame_base
;
3358 need_frame_base
= decode_location_expression (block_start
,
3363 cu_offset
, section
);
3365 if (need_frame_base
&& !have_frame_base
)
3366 printf (_(" [without DW_AT_frame_base]"));
3370 case DW_AT_data_bit_offset
:
3371 case DW_AT_byte_size
:
3372 case DW_AT_bit_size
:
3373 case DW_AT_string_length_byte_size
:
3374 case DW_AT_string_length_bit_size
:
3375 case DW_AT_bit_stride
:
3376 if (form
== DW_FORM_exprloc
)
3379 (void) decode_location_expression (block_start
, pointer_size
,
3380 offset_size
, dwarf_version
,
3381 uvalue
, cu_offset
, section
);
3388 unsigned long abbrev_number
;
3389 abbrev_entry
*entry
;
3391 entry
= get_type_abbrev_from_form (form
, uvalue
, cu_offset
, end
,
3392 section
, & abbrev_number
, NULL
, NULL
);
3395 if (form
!= DW_FORM_GNU_ref_alt
)
3396 warn (_("Offset %#" PRIx64
" used as value for DW_AT_import attribute of DIE at offset %#tx is too big.\n"),
3398 orig_data
- section
->start
);
3402 printf (_("\t[Abbrev Number: %ld"), abbrev_number
);
3403 printf (" (%s)", get_TAG_name (entry
->tag
));
3416 static unsigned char *
3417 read_and_display_attr (unsigned long attribute
,
3419 int64_t implicit_const
,
3420 unsigned char *start
,
3421 unsigned char *data
,
3424 uint64_t pointer_size
,
3425 uint64_t offset_size
,
3427 debug_info
*debug_info_p
,
3429 struct dwarf_section
*section
,
3430 struct cu_tu_set
*this_set
,
3434 printf (" %-18s:", get_AT_name (attribute
));
3435 data
= read_and_display_attr_value (attribute
, form
, implicit_const
,
3437 cu_offset
, pointer_size
, offset_size
,
3438 dwarf_version
, debug_info_p
,
3439 do_loc
, section
, this_set
, ' ', level
);
3445 /* Like load_debug_section, but if the ordinary call fails, and we are
3446 following debug links, then attempt to load the requested section
3447 from one of the separate debug info files. */
3450 load_debug_section_with_follow (enum dwarf_section_display_enum sec_enum
,
3453 if (load_debug_section (sec_enum
, handle
))
3455 if (debug_displays
[sec_enum
].section
.filename
== NULL
)
3457 /* See if we can associate a filename with this section. */
3460 for (i
= first_separate_info
; i
!= NULL
; i
= i
->next
)
3461 if (i
->handle
== handle
)
3463 debug_displays
[sec_enum
].section
.filename
= i
->filename
;
3471 if (do_follow_links
)
3475 for (i
= first_separate_info
; i
!= NULL
; i
= i
->next
)
3477 if (load_debug_section (sec_enum
, i
->handle
))
3479 debug_displays
[sec_enum
].section
.filename
= i
->filename
;
3481 /* FIXME: We should check to see if any of the remaining debug info
3482 files also contain this section, and, umm, do something about it. */
3492 introduce (struct dwarf_section
* section
, bool raw
)
3496 if (do_follow_links
&& section
->filename
)
3497 printf (_("Raw dump of debug contents of section %s (loaded from %s):\n\n"),
3498 section
->name
, section
->filename
);
3500 printf (_("Raw dump of debug contents of section %s:\n\n"), section
->name
);
3504 if (do_follow_links
&& section
->filename
)
3505 printf (_("Contents of the %s section (loaded from %s):\n\n"),
3506 section
->name
, section
->filename
);
3508 printf (_("Contents of the %s section:\n\n"), section
->name
);
3512 /* Free memory allocated for one unit in debug_information. */
3515 free_debug_information (debug_info
*ent
)
3517 if (ent
->max_loc_offsets
)
3519 free (ent
->loc_offsets
);
3520 free (ent
->loc_views
);
3521 free (ent
->have_frame_base
);
3523 if (ent
->max_range_lists
)
3524 free (ent
->range_lists
);
3527 /* Process the contents of a .debug_info section.
3528 If do_loc is TRUE then we are scanning for location lists and dwo tags
3529 and we do not want to display anything to the user.
3530 If do_types is TRUE, we are processing a .debug_types section instead of
3531 a .debug_info section.
3532 The information displayed is restricted by the values in DWARF_START_DIE
3533 and DWARF_CUTOFF_LEVEL.
3534 Returns TRUE upon success. Otherwise an error or warning message is
3535 printed and FALSE is returned. */
3538 process_debug_info (struct dwarf_section
* section
,
3540 enum dwarf_section_display_enum abbrev_sec
,
3544 unsigned char *start
= section
->start
;
3545 unsigned char *end
= start
+ section
->size
;
3546 unsigned char *section_begin
;
3548 unsigned int num_units
= 0;
3550 /* First scan the section to get the number of comp units.
3551 Length sanity checks are done here. */
3552 for (section_begin
= start
, num_units
= 0; section_begin
< end
;
3557 /* Read the first 4 bytes. For a 32-bit DWARF section, this
3558 will be the length. For a 64-bit DWARF section, it'll be
3559 the escape code 0xffffffff followed by an 8 byte length. */
3560 SAFE_BYTE_GET_AND_INC (length
, section_begin
, 4, end
);
3562 if (length
== 0xffffffff)
3563 SAFE_BYTE_GET_AND_INC (length
, section_begin
, 8, end
);
3564 else if (length
>= 0xfffffff0 && length
< 0xffffffff)
3566 warn (_("Reserved length value (%#" PRIx64
") found in section %s\n"),
3567 length
, section
->name
);
3571 /* Negative values are illegal, they may even cause infinite
3572 looping. This can happen if we can't accurately apply
3573 relocations to an object file, or if the file is corrupt. */
3574 if (length
> (size_t) (end
- section_begin
))
3576 warn (_("Corrupt unit length (got %#" PRIx64
3577 " expected at most %#tx) in section %s\n"),
3578 length
, end
- section_begin
, section
->name
);
3581 section_begin
+= length
;
3586 error (_("No comp units in %s section ?\n"), section
->name
);
3590 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
|| do_debug_info
)
3591 && num_debug_info_entries
== 0
3595 /* Then allocate an array to hold the information. */
3596 debug_information
= (debug_info
*) cmalloc (num_units
,
3597 sizeof (* debug_information
));
3598 if (debug_information
== NULL
)
3600 error (_("Not enough memory for a debug info array of %u entries\n"),
3602 alloc_num_debug_info_entries
= num_debug_info_entries
= 0;
3606 /* PR 17531: file: 92ca3797.
3607 We cannot rely upon the debug_information array being initialised
3608 before it is used. A corrupt file could easily contain references
3609 to a unit for which information has not been made available. So
3610 we ensure that the array is zeroed here. */
3611 memset (debug_information
, 0, num_units
* sizeof (*debug_information
));
3613 alloc_num_debug_info_entries
= num_units
;
3618 load_debug_section_with_follow (str
, file
);
3619 load_debug_section_with_follow (line_str
, file
);
3620 load_debug_section_with_follow (str_dwo
, file
);
3621 load_debug_section_with_follow (str_index
, file
);
3622 load_debug_section_with_follow (str_index_dwo
, file
);
3623 load_debug_section_with_follow (debug_addr
, file
);
3626 load_debug_section_with_follow (abbrev_sec
, file
);
3627 load_debug_section_with_follow (loclists
, file
);
3628 load_debug_section_with_follow (rnglists
, file
);
3629 load_debug_section_with_follow (loclists_dwo
, file
);
3630 load_debug_section_with_follow (rnglists_dwo
, file
);
3632 if (debug_displays
[abbrev_sec
].section
.start
== NULL
)
3634 warn (_("Unable to locate %s section!\n"),
3635 debug_displays
[abbrev_sec
].section
.uncompressed_name
);
3639 if (!do_loc
&& dwarf_start_die
== 0)
3640 introduce (section
, false);
3642 free_all_abbrevs ();
3644 /* In order to be able to resolve DW_FORM_ref_addr forms we need
3645 to load *all* of the abbrevs for all CUs in this .debug_info
3646 section. This does effectively mean that we (partially) read
3647 every CU header twice. */
3648 for (section_begin
= start
; start
< end
;)
3650 DWARF2_Internal_CompUnit compunit
;
3651 unsigned char *hdrptr
;
3652 uint64_t abbrev_base
;
3655 unsigned int offset_size
;
3656 struct cu_tu_set
*this_set
;
3657 unsigned char *end_cu
;
3660 cu_offset
= start
- section_begin
;
3662 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 4, end
);
3664 if (compunit
.cu_length
== 0xffffffff)
3666 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 8, end
);
3671 end_cu
= hdrptr
+ compunit
.cu_length
;
3673 SAFE_BYTE_GET_AND_INC (compunit
.cu_version
, hdrptr
, 2, end_cu
);
3675 this_set
= find_cu_tu_set_v2 (cu_offset
, do_types
);
3677 if (compunit
.cu_version
< 5)
3679 compunit
.cu_unit_type
= DW_UT_compile
;
3680 /* Initialize it due to a false compiler warning. */
3681 compunit
.cu_pointer_size
= -1;
3685 SAFE_BYTE_GET_AND_INC (compunit
.cu_unit_type
, hdrptr
, 1, end_cu
);
3686 do_types
= (compunit
.cu_unit_type
== DW_UT_type
);
3688 SAFE_BYTE_GET_AND_INC (compunit
.cu_pointer_size
, hdrptr
, 1, end_cu
);
3691 SAFE_BYTE_GET_AND_INC (compunit
.cu_abbrev_offset
, hdrptr
, offset_size
,
3694 if (compunit
.cu_unit_type
== DW_UT_split_compile
3695 || compunit
.cu_unit_type
== DW_UT_skeleton
)
3698 SAFE_BYTE_GET_AND_INC (dwo_id
, hdrptr
, 8, end_cu
);
3701 if (this_set
== NULL
)
3704 abbrev_size
= debug_displays
[abbrev_sec
].section
.size
;
3708 abbrev_base
= this_set
->section_offsets
[DW_SECT_ABBREV
];
3709 abbrev_size
= this_set
->section_sizes
[DW_SECT_ABBREV
];
3713 abbrev_list
*free_list
;
3714 list
= find_and_process_abbrev_set (&debug_displays
[abbrev_sec
].section
,
3715 abbrev_base
, abbrev_size
,
3716 compunit
.cu_abbrev_offset
,
3719 if (list
!= NULL
&& list
->first_abbrev
!= NULL
)
3720 record_abbrev_list_for_cu (cu_offset
, start
- section_begin
,
3722 else if (free_list
!= NULL
)
3723 free_abbrev_list (free_list
);
3726 for (start
= section_begin
, unit
= 0; start
< end
; unit
++)
3728 DWARF2_Internal_CompUnit compunit
;
3729 unsigned char *hdrptr
;
3730 unsigned char *tags
;
3731 int level
, last_level
, saved_level
;
3733 unsigned int offset_size
;
3734 uint64_t signature
= 0;
3735 uint64_t type_offset
= 0;
3736 struct cu_tu_set
*this_set
;
3737 uint64_t abbrev_base
;
3739 unsigned char *end_cu
;
3742 cu_offset
= start
- section_begin
;
3744 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 4, end
);
3746 if (compunit
.cu_length
== 0xffffffff)
3748 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 8, end
);
3753 end_cu
= hdrptr
+ compunit
.cu_length
;
3755 SAFE_BYTE_GET_AND_INC (compunit
.cu_version
, hdrptr
, 2, end_cu
);
3757 this_set
= find_cu_tu_set_v2 (cu_offset
, do_types
);
3759 if (compunit
.cu_version
< 5)
3761 compunit
.cu_unit_type
= DW_UT_compile
;
3762 /* Initialize it due to a false compiler warning. */
3763 compunit
.cu_pointer_size
= -1;
3767 SAFE_BYTE_GET_AND_INC (compunit
.cu_unit_type
, hdrptr
, 1, end_cu
);
3768 do_types
= (compunit
.cu_unit_type
== DW_UT_type
);
3770 SAFE_BYTE_GET_AND_INC (compunit
.cu_pointer_size
, hdrptr
, 1, end_cu
);
3773 SAFE_BYTE_GET_AND_INC (compunit
.cu_abbrev_offset
, hdrptr
, offset_size
, end_cu
);
3775 if (this_set
== NULL
)
3778 abbrev_size
= debug_displays
[abbrev_sec
].section
.size
;
3782 abbrev_base
= this_set
->section_offsets
[DW_SECT_ABBREV
];
3783 abbrev_size
= this_set
->section_sizes
[DW_SECT_ABBREV
];
3786 if (compunit
.cu_version
< 5)
3787 SAFE_BYTE_GET_AND_INC (compunit
.cu_pointer_size
, hdrptr
, 1, end_cu
);
3789 bool do_dwo_id
= false;
3790 uint64_t dwo_id
= 0;
3791 if (compunit
.cu_unit_type
== DW_UT_split_compile
3792 || compunit
.cu_unit_type
== DW_UT_skeleton
)
3794 SAFE_BYTE_GET_AND_INC (dwo_id
, hdrptr
, 8, end_cu
);
3798 /* PR 17512: file: 001-108546-0.001:0.1. */
3799 if (compunit
.cu_pointer_size
< 2 || compunit
.cu_pointer_size
> 8)
3801 warn (_("Invalid pointer size (%d) in compunit header, using %d instead\n"),
3802 compunit
.cu_pointer_size
, offset_size
);
3803 compunit
.cu_pointer_size
= offset_size
;
3808 SAFE_BYTE_GET_AND_INC (signature
, hdrptr
, 8, end_cu
);
3809 SAFE_BYTE_GET_AND_INC (type_offset
, hdrptr
, offset_size
, end_cu
);
3812 if (dwarf_start_die
>= (size_t) (end_cu
- section_begin
))
3818 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
|| do_debug_info
)
3819 && num_debug_info_entries
== 0
3820 && alloc_num_debug_info_entries
> unit
3823 free_debug_information (&debug_information
[unit
]);
3824 memset (&debug_information
[unit
], 0, sizeof (*debug_information
));
3825 debug_information
[unit
].pointer_size
= compunit
.cu_pointer_size
;
3826 debug_information
[unit
].offset_size
= offset_size
;
3827 debug_information
[unit
].dwarf_version
= compunit
.cu_version
;
3828 debug_information
[unit
].cu_offset
= cu_offset
;
3829 debug_information
[unit
].addr_base
= DEBUG_INFO_UNAVAILABLE
;
3830 debug_information
[unit
].ranges_base
= DEBUG_INFO_UNAVAILABLE
;
3833 if (!do_loc
&& dwarf_start_die
== 0)
3835 printf (_(" Compilation Unit @ offset %#" PRIx64
":\n"),
3837 printf (_(" Length: %#" PRIx64
" (%s)\n"),
3839 offset_size
== 8 ? "64-bit" : "32-bit");
3840 printf (_(" Version: %d\n"), compunit
.cu_version
);
3841 if (compunit
.cu_version
>= 5)
3843 const char *name
= get_DW_UT_name (compunit
.cu_unit_type
);
3845 printf (_(" Unit Type: %s (%x)\n"),
3846 name
? name
: "???",
3847 compunit
.cu_unit_type
);
3849 printf (_(" Abbrev Offset: %#" PRIx64
"\n"),
3850 compunit
.cu_abbrev_offset
);
3851 printf (_(" Pointer Size: %d\n"), compunit
.cu_pointer_size
);
3854 printf (_(" Signature: %#" PRIx64
"\n"), signature
);
3855 printf (_(" Type Offset: %#" PRIx64
"\n"), type_offset
);
3858 printf (_(" DWO ID: %#" PRIx64
"\n"), dwo_id
);
3859 if (this_set
!= NULL
)
3861 uint64_t *offsets
= this_set
->section_offsets
;
3862 size_t *sizes
= this_set
->section_sizes
;
3864 printf (_(" Section contributions:\n"));
3865 printf (_(" .debug_abbrev.dwo: %#" PRIx64
" %#zx\n"),
3866 offsets
[DW_SECT_ABBREV
], sizes
[DW_SECT_ABBREV
]);
3867 printf (_(" .debug_line.dwo: %#" PRIx64
" %#zx\n"),
3868 offsets
[DW_SECT_LINE
], sizes
[DW_SECT_LINE
]);
3869 printf (_(" .debug_loc.dwo: %#" PRIx64
" %#zx\n"),
3870 offsets
[DW_SECT_LOC
], sizes
[DW_SECT_LOC
]);
3871 printf (_(" .debug_str_offsets.dwo: %#" PRIx64
" %#zx\n"),
3872 offsets
[DW_SECT_STR_OFFSETS
], sizes
[DW_SECT_STR_OFFSETS
]);
3879 if (compunit
.cu_version
< 2 || compunit
.cu_version
> 5)
3881 warn (_("CU at offset %#" PRIx64
" contains corrupt or "
3882 "unsupported version number: %d.\n"),
3883 cu_offset
, compunit
.cu_version
);
3887 if (compunit
.cu_unit_type
!= DW_UT_compile
3888 && compunit
.cu_unit_type
!= DW_UT_partial
3889 && compunit
.cu_unit_type
!= DW_UT_type
3890 && compunit
.cu_unit_type
!= DW_UT_split_compile
3891 && compunit
.cu_unit_type
!= DW_UT_skeleton
)
3893 warn (_("CU at offset %#" PRIx64
" contains corrupt or "
3894 "unsupported unit type: %d.\n"),
3895 cu_offset
, compunit
.cu_unit_type
);
3899 /* Process the abbrevs used by this compilation unit. */
3901 list
= find_and_process_abbrev_set (&debug_displays
[abbrev_sec
].section
,
3902 abbrev_base
, abbrev_size
,
3903 compunit
.cu_abbrev_offset
, NULL
);
3907 while (tags
< start
)
3909 unsigned long abbrev_number
;
3910 unsigned long die_offset
;
3911 abbrev_entry
*entry
;
3913 int do_printing
= 1;
3915 die_offset
= tags
- section_begin
;
3917 READ_ULEB (abbrev_number
, tags
, start
);
3919 /* A null DIE marks the end of a list of siblings or it may also be
3920 a section padding. */
3921 if (abbrev_number
== 0)
3923 /* Check if it can be a section padding for the last CU. */
3924 if (level
== 0 && start
== end
)
3928 for (chk
= tags
; chk
< start
; chk
++)
3935 if (!do_loc
&& die_offset
>= dwarf_start_die
3936 && (dwarf_cutoff_level
== -1
3937 || level
< dwarf_cutoff_level
))
3938 printf (_(" <%d><%lx>: Abbrev Number: 0\n"),
3944 static unsigned num_bogus_warns
= 0;
3946 if (num_bogus_warns
< 3)
3948 warn (_("Bogus end-of-siblings marker detected at offset %lx in %s section\n"),
3949 die_offset
, section
->name
);
3951 if (num_bogus_warns
== 3)
3952 warn (_("Further warnings about bogus end-of-sibling markers suppressed\n"));
3955 if (dwarf_start_die
!= 0 && level
< saved_level
)
3962 if (dwarf_start_die
!= 0 && die_offset
< dwarf_start_die
)
3966 if (dwarf_start_die
!= 0 && die_offset
== dwarf_start_die
)
3967 saved_level
= level
;
3968 do_printing
= (dwarf_cutoff_level
== -1
3969 || level
< dwarf_cutoff_level
);
3971 printf (_(" <%d><%lx>: Abbrev Number: %lu"),
3972 level
, die_offset
, abbrev_number
);
3973 else if (dwarf_cutoff_level
== -1
3974 || last_level
< dwarf_cutoff_level
)
3975 printf (_(" <%d><%lx>: ...\n"), level
, die_offset
);
3980 /* Scan through the abbreviation list until we reach the
3984 for (entry
= list
->first_abbrev
; entry
!= NULL
; entry
= entry
->next
)
3985 if (entry
->number
== abbrev_number
)
3990 if (!do_loc
&& do_printing
)
3995 warn (_("DIE at offset %#lx refers to abbreviation number %lu which does not exist\n"),
3996 die_offset
, abbrev_number
);
4000 if (!do_loc
&& do_printing
)
4001 printf (" (%s)\n", get_TAG_name (entry
->tag
));
4006 need_base_address
= 0;
4008 case DW_TAG_compile_unit
:
4009 case DW_TAG_skeleton_unit
:
4010 need_base_address
= 1;
4011 need_dwo_info
= do_loc
;
4013 case DW_TAG_entry_point
:
4014 case DW_TAG_subprogram
:
4015 need_base_address
= 0;
4016 /* Assuming that there is no DW_AT_frame_base. */
4017 have_frame_base
= 0;
4021 debug_info
*debug_info_p
=
4022 (debug_information
&& unit
< alloc_num_debug_info_entries
)
4023 ? debug_information
+ unit
: NULL
;
4025 assert (!debug_info_p
4026 || (debug_info_p
->num_loc_offsets
4027 == debug_info_p
->num_loc_views
));
4029 for (attr
= entry
->first_attr
;
4030 attr
&& attr
->attribute
;
4033 if (! do_loc
&& do_printing
)
4034 /* Show the offset from where the tag was extracted. */
4035 printf (" <%tx>", tags
- section_begin
);
4036 tags
= read_and_display_attr (attr
->attribute
,
4038 attr
->implicit_const
,
4043 compunit
.cu_pointer_size
,
4045 compunit
.cu_version
,
4047 do_loc
|| ! do_printing
,
4053 /* If a locview attribute appears before a location one,
4054 make sure we don't associate it with an earlier
4057 switch (debug_info_p
->num_loc_offsets
- debug_info_p
->num_loc_views
)
4060 debug_info_p
->loc_views
[debug_info_p
->num_loc_views
] = -1;
4061 debug_info_p
->num_loc_views
++;
4062 assert (debug_info_p
->num_loc_views
4063 == debug_info_p
->num_loc_offsets
);
4070 warn(_("DIE has locviews without loclist\n"));
4071 debug_info_p
->num_loc_views
--;
4078 if (entry
->children
)
4082 free_abbrev_list (list
);
4085 /* Set num_debug_info_entries here so that it can be used to check if
4086 we need to process .debug_loc and .debug_ranges sections. */
4087 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
|| do_debug_info
)
4088 && num_debug_info_entries
== 0
4091 if (num_units
> alloc_num_debug_info_entries
)
4092 num_debug_info_entries
= alloc_num_debug_info_entries
;
4094 num_debug_info_entries
= num_units
;
4103 /* Locate and scan the .debug_info section in the file and record the pointer
4104 sizes and offsets for the compilation units in it. Usually an executable
4105 will have just one pointer size, but this is not guaranteed, and so we try
4106 not to make any assumptions. Returns zero upon failure, or the number of
4107 compilation units upon success. */
4110 load_debug_info (void * file
)
4112 /* If we have already tried and failed to load the .debug_info
4113 section then do not bother to repeat the task. */
4114 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
4117 /* If we already have the information there is nothing else to do. */
4118 if (num_debug_info_entries
> 0)
4119 return num_debug_info_entries
;
4121 /* If this is a DWARF package file, load the CU and TU indexes. */
4122 (void) load_cu_tu_indexes (file
);
4124 if (load_debug_section_with_follow (info
, file
)
4125 && process_debug_info (&debug_displays
[info
].section
, file
, abbrev
, true, false))
4126 return num_debug_info_entries
;
4128 if (load_debug_section_with_follow (info_dwo
, file
)
4129 && process_debug_info (&debug_displays
[info_dwo
].section
, file
,
4130 abbrev_dwo
, true, false))
4131 return num_debug_info_entries
;
4133 num_debug_info_entries
= DEBUG_INFO_UNAVAILABLE
;
4137 /* Read a DWARF .debug_line section header starting at DATA.
4138 Upon success returns an updated DATA pointer and the LINFO
4139 structure and the END_OF_SEQUENCE pointer will be filled in.
4140 Otherwise returns NULL. */
4142 static unsigned char *
4143 read_debug_line_header (struct dwarf_section
* section
,
4144 unsigned char * data
,
4145 unsigned char * end
,
4146 DWARF2_Internal_LineInfo
* linfo
,
4147 unsigned char ** end_of_sequence
)
4149 unsigned char *hdrptr
;
4151 /* Extract information from the Line Number Program Header.
4152 (section 6.2.4 in the Dwarf3 doc). */
4155 /* Get and check the length of the block. */
4156 SAFE_BYTE_GET_AND_INC (linfo
->li_length
, hdrptr
, 4, end
);
4158 if (linfo
->li_length
== 0xffffffff)
4160 /* This section is 64-bit DWARF 3. */
4161 SAFE_BYTE_GET_AND_INC (linfo
->li_length
, hdrptr
, 8, end
);
4162 linfo
->li_offset_size
= 8;
4165 linfo
->li_offset_size
= 4;
4167 if (linfo
->li_length
> (size_t) (end
- hdrptr
))
4169 /* If the length field has a relocation against it, then we should
4170 not complain if it is inaccurate (and probably negative). This
4171 happens in object files when the .debug_line section is actually
4172 comprised of several different .debug_line.* sections, (some of
4173 which may be removed by linker garbage collection), and a relocation
4174 is used to compute the correct length once that is done. */
4175 if (reloc_at (section
, (hdrptr
- section
->start
) - linfo
->li_offset_size
))
4177 linfo
->li_length
= end
- hdrptr
;
4181 warn (_("The length field (%#" PRIx64
")"
4182 " in the debug_line header is wrong"
4183 " - the section is too small\n"),
4188 end
= hdrptr
+ linfo
->li_length
;
4190 /* Get and check the version number. */
4191 SAFE_BYTE_GET_AND_INC (linfo
->li_version
, hdrptr
, 2, end
);
4193 if (linfo
->li_version
!= 2
4194 && linfo
->li_version
!= 3
4195 && linfo
->li_version
!= 4
4196 && linfo
->li_version
!= 5)
4198 warn (_("Only DWARF version 2, 3, 4 and 5 line info "
4199 "is currently supported.\n"));
4203 if (linfo
->li_version
>= 5)
4205 SAFE_BYTE_GET_AND_INC (linfo
->li_address_size
, hdrptr
, 1, end
);
4207 SAFE_BYTE_GET_AND_INC (linfo
->li_segment_size
, hdrptr
, 1, end
);
4208 if (linfo
->li_segment_size
!= 0)
4210 warn (_("The %s section contains "
4211 "unsupported segment selector size: %d.\n"),
4212 section
->name
, linfo
->li_segment_size
);
4217 SAFE_BYTE_GET_AND_INC (linfo
->li_prologue_length
, hdrptr
,
4218 linfo
->li_offset_size
, end
);
4219 SAFE_BYTE_GET_AND_INC (linfo
->li_min_insn_length
, hdrptr
, 1, end
);
4221 if (linfo
->li_version
>= 4)
4223 SAFE_BYTE_GET_AND_INC (linfo
->li_max_ops_per_insn
, hdrptr
, 1, end
);
4225 if (linfo
->li_max_ops_per_insn
== 0)
4227 warn (_("Invalid maximum operations per insn.\n"));
4232 linfo
->li_max_ops_per_insn
= 1;
4234 SAFE_BYTE_GET_AND_INC (linfo
->li_default_is_stmt
, hdrptr
, 1, end
);
4235 SAFE_SIGNED_BYTE_GET_AND_INC (linfo
->li_line_base
, hdrptr
, 1, end
);
4236 SAFE_BYTE_GET_AND_INC (linfo
->li_line_range
, hdrptr
, 1, end
);
4237 SAFE_BYTE_GET_AND_INC (linfo
->li_opcode_base
, hdrptr
, 1, end
);
4239 *end_of_sequence
= end
;
4243 static unsigned char *
4244 display_formatted_table (unsigned char *data
,
4245 unsigned char *start
,
4247 const DWARF2_Internal_LineInfo
*linfo
,
4248 struct dwarf_section
*section
,
4251 unsigned char *format_start
, format_count
, *format
, formati
;
4252 uint64_t data_count
, datai
;
4253 unsigned int namepass
, last_entry
= 0;
4254 const char * table_name
= is_dir
? N_("Directory Table") : N_("File Name Table");
4256 SAFE_BYTE_GET_AND_INC (format_count
, data
, 1, end
);
4257 if (do_checks
&& format_count
> 5)
4258 warn (_("Unexpectedly large number of columns in the %s (%u)\n"),
4259 table_name
, format_count
);
4261 format_start
= data
;
4262 for (formati
= 0; formati
< format_count
; formati
++)
4264 SKIP_ULEB (data
, end
);
4265 SKIP_ULEB (data
, end
);
4268 warn (_("%s: Corrupt format description entry\n"), table_name
);
4273 READ_ULEB (data_count
, data
, end
);
4274 if (data_count
== 0)
4276 printf (_("\n The %s is empty.\n"), table_name
);
4279 else if (data
>= end
)
4281 warn (_("%s: Corrupt entry count - expected %#" PRIx64
4282 " but none found\n"), table_name
, data_count
);
4286 else if (format_count
== 0)
4288 warn (_("%s: format count is zero, but the table is not empty\n"),
4293 printf (_("\n The %s (offset %#tx, lines %" PRIu64
", columns %u):\n"),
4294 table_name
, data
- start
, data_count
, format_count
);
4296 printf (_(" Entry"));
4297 /* Delay displaying name as the last entry for better screen layout. */
4298 for (namepass
= 0; namepass
< 2; namepass
++)
4300 format
= format_start
;
4301 for (formati
= 0; formati
< format_count
; formati
++)
4303 uint64_t content_type
;
4305 READ_ULEB (content_type
, format
, end
);
4306 if ((content_type
== DW_LNCT_path
) == (namepass
== 1))
4307 switch (content_type
)
4310 printf (_("\tName"));
4312 case DW_LNCT_directory_index
:
4313 printf (_("\tDir"));
4315 case DW_LNCT_timestamp
:
4316 printf (_("\tTime"));
4319 printf (_("\tSize"));
4322 printf (_("\tMD5\t\t\t"));
4325 printf (_("\t(Unknown format content type %" PRIu64
")"),
4328 SKIP_ULEB (format
, end
);
4333 for (datai
= 0; datai
< data_count
; datai
++)
4335 unsigned char *datapass
= data
;
4337 printf (" %d", last_entry
++);
4338 /* Delay displaying name as the last entry for better screen layout. */
4339 for (namepass
= 0; namepass
< 2; namepass
++)
4341 format
= format_start
;
4343 for (formati
= 0; formati
< format_count
; formati
++)
4345 uint64_t content_type
, form
;
4347 READ_ULEB (content_type
, format
, end
);
4348 READ_ULEB (form
, format
, end
);
4349 data
= read_and_display_attr_value (0, form
, 0, start
, data
, end
,
4350 0, 0, linfo
->li_offset_size
,
4351 linfo
->li_version
, NULL
,
4352 ((content_type
== DW_LNCT_path
) != (namepass
== 1)),
4353 section
, NULL
, '\t', -1);
4357 if (data
>= end
&& (datai
< data_count
- 1))
4359 warn (_("\n%s: Corrupt entries list\n"), table_name
);
4368 display_debug_sup (struct dwarf_section
* section
,
4369 void * file ATTRIBUTE_UNUSED
)
4371 unsigned char * start
= section
->start
;
4372 unsigned char * end
= section
->start
+ section
->size
;
4373 unsigned int version
;
4374 char is_supplementary
;
4375 const unsigned char * sup_filename
;
4376 size_t sup_filename_len
;
4377 unsigned int num_read
;
4379 uint64_t checksum_len
;
4382 introduce (section
, true);
4383 if (section
->size
< 4)
4385 error (_("corrupt .debug_sup section: size is too small\n"));
4389 /* Read the data. */
4390 SAFE_BYTE_GET_AND_INC (version
, start
, 2, end
);
4392 warn (_("corrupt .debug_sup section: version < 5"));
4394 SAFE_BYTE_GET_AND_INC (is_supplementary
, start
, 1, end
);
4395 if (is_supplementary
!= 0 && is_supplementary
!= 1)
4396 warn (_("corrupt .debug_sup section: is_supplementary not 0 or 1\n"));
4398 sup_filename
= start
;
4399 if (is_supplementary
&& sup_filename
[0] != 0)
4400 warn (_("corrupt .debug_sup section: filename not empty in supplementary section\n"));
4402 sup_filename_len
= strnlen ((const char *) start
, end
- start
);
4403 if (sup_filename_len
== (size_t) (end
- start
))
4405 error (_("corrupt .debug_sup section: filename is not NUL terminated\n"));
4408 start
+= sup_filename_len
+ 1;
4410 checksum_len
= read_leb128 (start
, end
, false /* unsigned */, & num_read
, & status
);
4413 error (_("corrupt .debug_sup section: bad LEB128 field for checksum length\n"));
4417 if (checksum_len
> (size_t) (end
- start
))
4419 error (_("corrupt .debug_sup section: checksum length is longer than the remaining section length\n"));
4420 checksum_len
= end
- start
;
4422 else if (checksum_len
< (size_t) (end
- start
))
4424 warn (_("corrupt .debug_sup section: there are %#" PRIx64
4425 " extra, unused bytes at the end of the section\n"),
4426 (end
- start
) - checksum_len
);
4429 printf (_(" Version: %u\n"), version
);
4430 printf (_(" Is Supp: %u\n"), is_supplementary
);
4431 printf (_(" Filename: %s\n"), sup_filename
);
4432 printf (_(" Checksum Len: %" PRIu64
"\n"), checksum_len
);
4433 if (checksum_len
> 0)
4435 printf (_(" Checksum: "));
4436 while (checksum_len
--)
4437 printf ("0x%x ", * start
++ );
4444 display_debug_lines_raw (struct dwarf_section
* section
,
4445 unsigned char * data
,
4446 unsigned char * end
,
4449 unsigned char *start
= section
->start
;
4450 int verbose_view
= 0;
4452 introduce (section
, true);
4456 static DWARF2_Internal_LineInfo saved_linfo
;
4457 DWARF2_Internal_LineInfo linfo
;
4458 unsigned char *standard_opcodes
;
4459 unsigned char *end_of_sequence
;
4462 if (startswith (section
->name
, ".debug_line.")
4463 /* Note: the following does not apply to .debug_line.dwo sections.
4464 These are full debug_line sections. */
4465 && strcmp (section
->name
, ".debug_line.dwo") != 0)
4467 /* Sections named .debug_line.<foo> are fragments of a .debug_line
4468 section containing just the Line Number Statements. They are
4469 created by the assembler and intended to be used alongside gcc's
4470 -ffunction-sections command line option. When the linker's
4471 garbage collection decides to discard a .text.<foo> section it
4472 can then also discard the line number information in .debug_line.<foo>.
4474 Since the section is a fragment it does not have the details
4475 needed to fill out a LineInfo structure, so instead we use the
4476 details from the last full debug_line section that we processed. */
4477 end_of_sequence
= end
;
4478 standard_opcodes
= NULL
;
4479 linfo
= saved_linfo
;
4480 /* PR 17531: file: 0522b371. */
4481 if (linfo
.li_line_range
== 0)
4483 warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n"));
4486 reset_state_machine (linfo
.li_default_is_stmt
);
4490 unsigned char * hdrptr
;
4492 if ((hdrptr
= read_debug_line_header (section
, data
, end
, & linfo
,
4493 & end_of_sequence
)) == NULL
)
4496 printf (_(" Offset: %#tx\n"), data
- start
);
4497 printf (_(" Length: %" PRId64
"\n"), linfo
.li_length
);
4498 printf (_(" DWARF Version: %d\n"), linfo
.li_version
);
4499 if (linfo
.li_version
>= 5)
4501 printf (_(" Address size (bytes): %d\n"), linfo
.li_address_size
);
4502 printf (_(" Segment selector (bytes): %d\n"), linfo
.li_segment_size
);
4504 printf (_(" Prologue Length: %d\n"), (int) linfo
.li_prologue_length
);
4505 printf (_(" Minimum Instruction Length: %d\n"), linfo
.li_min_insn_length
);
4506 if (linfo
.li_version
>= 4)
4507 printf (_(" Maximum Ops per Instruction: %d\n"), linfo
.li_max_ops_per_insn
);
4508 printf (_(" Initial value of 'is_stmt': %d\n"), linfo
.li_default_is_stmt
);
4509 printf (_(" Line Base: %d\n"), linfo
.li_line_base
);
4510 printf (_(" Line Range: %d\n"), linfo
.li_line_range
);
4511 printf (_(" Opcode Base: %d\n"), linfo
.li_opcode_base
);
4513 /* PR 17512: file: 1665-6428-0.004. */
4514 if (linfo
.li_line_range
== 0)
4516 warn (_("Line range of 0 is invalid, using 1 instead\n"));
4517 linfo
.li_line_range
= 1;
4520 reset_state_machine (linfo
.li_default_is_stmt
);
4522 /* Display the contents of the Opcodes table. */
4523 standard_opcodes
= hdrptr
;
4525 /* PR 17512: file: 002-417945-0.004. */
4526 if (standard_opcodes
+ linfo
.li_opcode_base
>= end
)
4528 warn (_("Line Base extends beyond end of section\n"));
4532 printf (_("\n Opcodes:\n"));
4534 for (i
= 1; i
< linfo
.li_opcode_base
; i
++)
4535 printf (ngettext (" Opcode %d has %d arg\n",
4536 " Opcode %d has %d args\n",
4537 standard_opcodes
[i
- 1]),
4538 i
, standard_opcodes
[i
- 1]);
4540 /* Display the contents of the Directory table. */
4541 data
= standard_opcodes
+ linfo
.li_opcode_base
- 1;
4543 if (linfo
.li_version
>= 5)
4545 load_debug_section_with_follow (line_str
, file
);
4547 data
= display_formatted_table (data
, start
, end
, &linfo
, section
,
4549 data
= display_formatted_table (data
, start
, end
, &linfo
, section
,
4555 printf (_("\n The Directory Table is empty.\n"));
4558 unsigned int last_dir_entry
= 0;
4560 printf (_("\n The Directory Table (offset %#tx):\n"),
4563 while (data
< end
&& *data
!= 0)
4565 printf (" %d\t%.*s\n", ++last_dir_entry
, (int) (end
- data
), data
);
4567 data
+= strnlen ((char *) data
, end
- data
);
4572 /* PR 17512: file: 002-132094-0.004. */
4573 if (data
>= end
- 1)
4577 /* Skip the NUL at the end of the table. */
4581 /* Display the contents of the File Name table. */
4582 if (data
>= end
|| *data
== 0)
4583 printf (_("\n The File Name Table is empty.\n"));
4586 printf (_("\n The File Name Table (offset %#tx):\n"),
4588 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
4590 while (data
< end
&& *data
!= 0)
4592 unsigned char *name
;
4595 printf (" %d\t", ++state_machine_regs
.last_file_entry
);
4597 data
+= strnlen ((char *) data
, end
- data
);
4601 READ_ULEB (val
, data
, end
);
4602 printf ("%" PRIu64
"\t", val
);
4603 READ_ULEB (val
, data
, end
);
4604 printf ("%" PRIu64
"\t", val
);
4605 READ_ULEB (val
, data
, end
);
4606 printf ("%" PRIu64
"\t", val
);
4607 printf ("%.*s\n", (int)(end
- name
), name
);
4611 warn (_("Corrupt file name table entry\n"));
4617 /* Skip the NUL at the end of the table. */
4623 saved_linfo
= linfo
;
4626 /* Now display the statements. */
4627 if (data
>= end_of_sequence
)
4628 printf (_(" No Line Number Statements.\n"));
4631 printf (_(" Line Number Statements:\n"));
4633 while (data
< end_of_sequence
)
4635 unsigned char op_code
;
4639 printf (" [0x%08tx]", data
- start
);
4643 if (op_code
>= linfo
.li_opcode_base
)
4645 op_code
-= linfo
.li_opcode_base
;
4646 uladv
= (op_code
/ linfo
.li_line_range
);
4647 if (linfo
.li_max_ops_per_insn
== 1)
4649 uladv
*= linfo
.li_min_insn_length
;
4650 state_machine_regs
.address
+= uladv
;
4652 state_machine_regs
.view
= 0;
4653 printf (_(" Special opcode %d: "
4654 "advance Address by %" PRIu64
4655 " to %#" PRIx64
"%s"),
4656 op_code
, uladv
, state_machine_regs
.address
,
4657 verbose_view
&& uladv
4658 ? _(" (reset view)") : "");
4663 = ((state_machine_regs
.op_index
+ uladv
)
4664 / linfo
.li_max_ops_per_insn
)
4665 * linfo
.li_min_insn_length
;
4667 state_machine_regs
.address
+= addrdelta
;
4668 state_machine_regs
.op_index
4669 = (state_machine_regs
.op_index
+ uladv
)
4670 % linfo
.li_max_ops_per_insn
;
4672 state_machine_regs
.view
= 0;
4673 printf (_(" Special opcode %d: "
4674 "advance Address by %" PRIu64
4675 " to %#" PRIx64
"[%d]%s"),
4676 op_code
, uladv
, state_machine_regs
.address
,
4677 state_machine_regs
.op_index
,
4678 verbose_view
&& addrdelta
4679 ? _(" (reset view)") : "");
4681 adv
= (op_code
% linfo
.li_line_range
) + linfo
.li_line_base
;
4682 state_machine_regs
.line
+= adv
;
4683 printf (_(" and Line by %" PRId64
" to %d"),
4684 adv
, state_machine_regs
.line
);
4685 if (verbose_view
|| state_machine_regs
.view
)
4686 printf (_(" (view %u)\n"), state_machine_regs
.view
);
4689 state_machine_regs
.view
++;
4694 case DW_LNS_extended_op
:
4695 data
+= process_extended_line_op (data
,
4696 linfo
.li_default_is_stmt
,
4701 printf (_(" Copy"));
4702 if (verbose_view
|| state_machine_regs
.view
)
4703 printf (_(" (view %u)\n"), state_machine_regs
.view
);
4706 state_machine_regs
.view
++;
4709 case DW_LNS_advance_pc
:
4710 READ_ULEB (uladv
, data
, end
);
4711 if (linfo
.li_max_ops_per_insn
== 1)
4713 uladv
*= linfo
.li_min_insn_length
;
4714 state_machine_regs
.address
+= uladv
;
4716 state_machine_regs
.view
= 0;
4717 printf (_(" Advance PC by %" PRIu64
4718 " to %#" PRIx64
"%s\n"),
4719 uladv
, state_machine_regs
.address
,
4720 verbose_view
&& uladv
4721 ? _(" (reset view)") : "");
4726 = ((state_machine_regs
.op_index
+ uladv
)
4727 / linfo
.li_max_ops_per_insn
)
4728 * linfo
.li_min_insn_length
;
4729 state_machine_regs
.address
4731 state_machine_regs
.op_index
4732 = (state_machine_regs
.op_index
+ uladv
)
4733 % linfo
.li_max_ops_per_insn
;
4735 state_machine_regs
.view
= 0;
4736 printf (_(" Advance PC by %" PRIu64
4737 " to %#" PRIx64
"[%d]%s\n"),
4738 uladv
, state_machine_regs
.address
,
4739 state_machine_regs
.op_index
,
4740 verbose_view
&& addrdelta
4741 ? _(" (reset view)") : "");
4745 case DW_LNS_advance_line
:
4746 READ_SLEB (adv
, data
, end
);
4747 state_machine_regs
.line
+= adv
;
4748 printf (_(" Advance Line by %" PRId64
" to %d\n"),
4749 adv
, state_machine_regs
.line
);
4752 case DW_LNS_set_file
:
4753 READ_ULEB (uladv
, data
, end
);
4754 printf (_(" Set File Name to entry %" PRIu64
4755 " in the File Name Table\n"), uladv
);
4756 state_machine_regs
.file
= uladv
;
4759 case DW_LNS_set_column
:
4760 READ_ULEB (uladv
, data
, end
);
4761 printf (_(" Set column to %" PRIu64
"\n"), uladv
);
4762 state_machine_regs
.column
= uladv
;
4765 case DW_LNS_negate_stmt
:
4766 adv
= state_machine_regs
.is_stmt
;
4768 printf (_(" Set is_stmt to %" PRId64
"\n"), adv
);
4769 state_machine_regs
.is_stmt
= adv
;
4772 case DW_LNS_set_basic_block
:
4773 printf (_(" Set basic block\n"));
4774 state_machine_regs
.basic_block
= 1;
4777 case DW_LNS_const_add_pc
:
4778 uladv
= ((255 - linfo
.li_opcode_base
) / linfo
.li_line_range
);
4779 if (linfo
.li_max_ops_per_insn
)
4781 uladv
*= linfo
.li_min_insn_length
;
4782 state_machine_regs
.address
+= uladv
;
4784 state_machine_regs
.view
= 0;
4785 printf (_(" Advance PC by constant %" PRIu64
4786 " to %#" PRIx64
"%s\n"),
4787 uladv
, state_machine_regs
.address
,
4788 verbose_view
&& uladv
4789 ? _(" (reset view)") : "");
4794 = ((state_machine_regs
.op_index
+ uladv
)
4795 / linfo
.li_max_ops_per_insn
)
4796 * linfo
.li_min_insn_length
;
4797 state_machine_regs
.address
4799 state_machine_regs
.op_index
4800 = (state_machine_regs
.op_index
+ uladv
)
4801 % linfo
.li_max_ops_per_insn
;
4803 state_machine_regs
.view
= 0;
4804 printf (_(" Advance PC by constant %" PRIu64
4805 " to %#" PRIx64
"[%d]%s\n"),
4806 uladv
, state_machine_regs
.address
,
4807 state_machine_regs
.op_index
,
4808 verbose_view
&& addrdelta
4809 ? _(" (reset view)") : "");
4813 case DW_LNS_fixed_advance_pc
:
4814 SAFE_BYTE_GET_AND_INC (uladv
, data
, 2, end
);
4815 state_machine_regs
.address
+= uladv
;
4816 state_machine_regs
.op_index
= 0;
4817 printf (_(" Advance PC by fixed size amount %" PRIu64
4818 " to %#" PRIx64
"\n"),
4819 uladv
, state_machine_regs
.address
);
4820 /* Do NOT reset view. */
4823 case DW_LNS_set_prologue_end
:
4824 printf (_(" Set prologue_end to true\n"));
4827 case DW_LNS_set_epilogue_begin
:
4828 printf (_(" Set epilogue_begin to true\n"));
4831 case DW_LNS_set_isa
:
4832 READ_ULEB (uladv
, data
, end
);
4833 printf (_(" Set ISA to %" PRIu64
"\n"), uladv
);
4837 printf (_(" Unknown opcode %d with operands: "), op_code
);
4839 if (standard_opcodes
!= NULL
)
4840 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
4842 READ_ULEB (uladv
, data
, end
);
4843 printf ("%#" PRIx64
"%s", uladv
, i
== 1 ? "" : ", ");
4858 unsigned char *name
;
4859 unsigned int directory_index
;
4860 unsigned int modification_date
;
4861 unsigned int length
;
4864 /* Output a decoded representation of the .debug_line section. */
4867 display_debug_lines_decoded (struct dwarf_section
* section
,
4868 unsigned char * start
,
4869 unsigned char * data
,
4870 unsigned char * end
,
4873 static DWARF2_Internal_LineInfo saved_linfo
;
4875 introduce (section
, false);
4879 /* This loop amounts to one iteration per compilation unit. */
4880 DWARF2_Internal_LineInfo linfo
;
4881 unsigned char *standard_opcodes
;
4882 unsigned char *end_of_sequence
;
4884 File_Entry
*file_table
= NULL
;
4885 unsigned int n_files
= 0;
4886 unsigned char **directory_table
= NULL
;
4887 uint64_t n_directories
= 0;
4889 if (startswith (section
->name
, ".debug_line.")
4890 /* Note: the following does not apply to .debug_line.dwo sections.
4891 These are full debug_line sections. */
4892 && strcmp (section
->name
, ".debug_line.dwo") != 0)
4894 /* See comment in display_debug_lines_raw(). */
4895 end_of_sequence
= end
;
4896 standard_opcodes
= NULL
;
4897 linfo
= saved_linfo
;
4898 /* PR 17531: file: 0522b371. */
4899 if (linfo
.li_line_range
== 0)
4901 warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n"));
4904 reset_state_machine (linfo
.li_default_is_stmt
);
4908 unsigned char *hdrptr
;
4910 if ((hdrptr
= read_debug_line_header (section
, data
, end
, & linfo
,
4911 & end_of_sequence
)) == NULL
)
4914 /* PR 17531: file: 0522b371. */
4915 if (linfo
.li_line_range
== 0)
4917 warn (_("Line range of 0 is invalid, using 1 instead\n"));
4918 linfo
.li_line_range
= 1;
4920 reset_state_machine (linfo
.li_default_is_stmt
);
4922 /* Save a pointer to the contents of the Opcodes table. */
4923 standard_opcodes
= hdrptr
;
4925 /* Traverse the Directory table just to count entries. */
4926 data
= standard_opcodes
+ linfo
.li_opcode_base
- 1;
4930 warn (_("opcode base of %d extends beyond end of section\n"),
4931 linfo
.li_opcode_base
);
4935 if (linfo
.li_version
>= 5)
4937 unsigned char *format_start
, format_count
, *format
;
4938 uint64_t formati
, entryi
;
4940 load_debug_section_with_follow (line_str
, fileptr
);
4942 /* Skip directories format. */
4943 SAFE_BYTE_GET_AND_INC (format_count
, data
, 1, end
);
4944 if (do_checks
&& format_count
> 1)
4945 warn (_("Unexpectedly large number of columns in the directory name table (%u)\n"),
4947 format_start
= data
;
4948 for (formati
= 0; formati
< format_count
; formati
++)
4950 SKIP_ULEB (data
, end
);
4951 SKIP_ULEB (data
, end
);
4954 READ_ULEB (n_directories
, data
, end
);
4957 warn (_("Corrupt directories list\n"));
4961 if (n_directories
== 0)
4962 directory_table
= NULL
;
4964 directory_table
= (unsigned char **)
4965 xmalloc (n_directories
* sizeof (unsigned char *));
4967 for (entryi
= 0; entryi
< n_directories
; entryi
++)
4969 unsigned char **pathp
= &directory_table
[entryi
];
4971 format
= format_start
;
4972 for (formati
= 0; formati
< format_count
; formati
++)
4974 uint64_t content_type
, form
;
4977 READ_ULEB (content_type
, format
, end
);
4978 READ_ULEB (form
, format
, end
);
4981 warn (_("Corrupt directories list\n"));
4984 switch (content_type
)
4989 case DW_FORM_string
:
4992 case DW_FORM_line_strp
:
4993 SAFE_BYTE_GET (uvalue
, data
, linfo
.li_offset_size
,
4995 /* Remove const by the cast. */
4996 *pathp
= (unsigned char *)
4997 fetch_indirect_line_string (uvalue
);
5002 data
= read_and_display_attr_value (0, form
, 0, start
,
5004 linfo
.li_offset_size
,
5011 warn (_("Corrupt directories list\n"));
5016 /* Skip files format. */
5017 SAFE_BYTE_GET_AND_INC (format_count
, data
, 1, end
);
5018 if (do_checks
&& format_count
> 5)
5019 warn (_("Unexpectedly large number of columns in the file name table (%u)\n"),
5021 format_start
= data
;
5022 for (formati
= 0; formati
< format_count
; formati
++)
5024 SKIP_ULEB (data
, end
);
5025 SKIP_ULEB (data
, end
);
5028 READ_ULEB (n_files
, data
, end
);
5029 if (data
>= end
&& n_files
> 0)
5031 warn (_("Corrupt file name list\n"));
5038 file_table
= (File_Entry
*) xcalloc (1, n_files
5039 * sizeof (File_Entry
));
5041 for (entryi
= 0; entryi
< n_files
; entryi
++)
5043 File_Entry
*file
= &file_table
[entryi
];
5045 format
= format_start
;
5046 for (formati
= 0; formati
< format_count
; formati
++)
5048 uint64_t content_type
, form
;
5052 READ_ULEB (content_type
, format
, end
);
5053 READ_ULEB (form
, format
, end
);
5056 warn (_("Corrupt file name list\n"));
5059 switch (content_type
)
5064 case DW_FORM_string
:
5067 case DW_FORM_line_strp
:
5068 SAFE_BYTE_GET (uvalue
, data
, linfo
.li_offset_size
,
5070 /* Remove const by the cast. */
5071 file
->name
= (unsigned char *)
5072 fetch_indirect_line_string (uvalue
);
5076 case DW_LNCT_directory_index
:
5080 SAFE_BYTE_GET (file
->directory_index
, data
, 1,
5084 SAFE_BYTE_GET (file
->directory_index
, data
, 2,
5089 READ_ULEB (file
->directory_index
, tmp
, end
);
5094 data
= read_and_display_attr_value (0, form
, 0, start
,
5096 linfo
.li_offset_size
,
5103 warn (_("Corrupt file name list\n"));
5112 unsigned char *ptr_directory_table
= data
;
5114 while (data
< end
&& *data
!= 0)
5116 data
+= strnlen ((char *) data
, end
- data
);
5125 warn (_("directory table ends unexpectedly\n"));
5130 /* Go through the directory table again to save the directories. */
5131 directory_table
= (unsigned char **)
5132 xmalloc (n_directories
* sizeof (unsigned char *));
5135 while (*ptr_directory_table
!= 0)
5137 directory_table
[i
] = ptr_directory_table
;
5139 += strlen ((char *) ptr_directory_table
) + 1;
5143 /* Skip the NUL at the end of the table. */
5146 /* Traverse the File Name table just to count the entries. */
5147 if (data
< end
&& *data
!= 0)
5149 unsigned char *ptr_file_name_table
= data
;
5151 while (data
< end
&& *data
!= 0)
5153 /* Skip Name, directory index, last modification
5154 time and length of file. */
5155 data
+= strnlen ((char *) data
, end
- data
);
5158 SKIP_ULEB (data
, end
);
5159 SKIP_ULEB (data
, end
);
5160 SKIP_ULEB (data
, end
);
5166 warn (_("file table ends unexpectedly\n"));
5171 /* Go through the file table again to save the strings. */
5172 file_table
= (File_Entry
*) xmalloc (n_files
* sizeof (File_Entry
));
5175 while (*ptr_file_name_table
!= 0)
5177 file_table
[i
].name
= ptr_file_name_table
;
5179 += strlen ((char *) ptr_file_name_table
) + 1;
5181 /* We are not interested in directory, time or size. */
5182 READ_ULEB (file_table
[i
].directory_index
,
5183 ptr_file_name_table
, end
);
5184 READ_ULEB (file_table
[i
].modification_date
,
5185 ptr_file_name_table
, end
);
5186 READ_ULEB (file_table
[i
].length
,
5187 ptr_file_name_table
, end
);
5193 /* Skip the NUL at the end of the table. */
5197 /* Print the Compilation Unit's name and a header. */
5198 if (file_table
== NULL
)
5199 printf (_("CU: No directory table\n"));
5200 else if (directory_table
== NULL
)
5201 printf (_("CU: %s:\n"), file_table
[0].name
);
5204 unsigned int ix
= file_table
[0].directory_index
;
5205 const char *directory
;
5210 else if (n_directories
== 0)
5211 directory
= _("<unknown>");
5212 else if (ix
> n_directories
)
5214 warn (_("directory index %u > number of directories %" PRIu64
"\n"),
5216 directory
= _("<corrupt>");
5218 else if (linfo
.li_version
>= 5)
5219 directory
= (char *) directory_table
[ix
];
5221 directory
= (char *) directory_table
[ix
- 1];
5224 printf (_("CU: %s/%s:\n"), directory
, file_table
[0].name
);
5226 printf ("%s:\n", file_table
[0].name
);
5230 printf (_("File name Line number Starting address View Stmt\n"));
5232 printf (_("CU: Empty file name table\n"));
5233 saved_linfo
= linfo
;
5236 /* This loop iterates through the Dwarf Line Number Program. */
5237 while (data
< end_of_sequence
)
5239 unsigned char op_code
;
5242 unsigned long int uladv
;
5243 int is_special_opcode
= 0;
5248 if (op_code
>= linfo
.li_opcode_base
)
5250 op_code
-= linfo
.li_opcode_base
;
5251 uladv
= (op_code
/ linfo
.li_line_range
);
5252 if (linfo
.li_max_ops_per_insn
== 1)
5254 uladv
*= linfo
.li_min_insn_length
;
5255 state_machine_regs
.address
+= uladv
;
5257 state_machine_regs
.view
= 0;
5262 = ((state_machine_regs
.op_index
+ uladv
)
5263 / linfo
.li_max_ops_per_insn
)
5264 * linfo
.li_min_insn_length
;
5265 state_machine_regs
.address
5267 state_machine_regs
.op_index
5268 = (state_machine_regs
.op_index
+ uladv
)
5269 % linfo
.li_max_ops_per_insn
;
5271 state_machine_regs
.view
= 0;
5274 adv
= (op_code
% linfo
.li_line_range
) + linfo
.li_line_base
;
5275 state_machine_regs
.line
+= adv
;
5276 is_special_opcode
= 1;
5277 /* Increment view after printing this row. */
5282 case DW_LNS_extended_op
:
5284 unsigned int ext_op_code_len
;
5285 unsigned char ext_op_code
;
5286 unsigned char *op_code_end
;
5287 unsigned char *op_code_data
= data
;
5289 READ_ULEB (ext_op_code_len
, op_code_data
, end_of_sequence
);
5290 op_code_end
= op_code_data
+ ext_op_code_len
;
5291 if (ext_op_code_len
== 0 || op_code_end
> end_of_sequence
)
5293 warn (_("Badly formed extended line op encountered!\n"));
5296 ext_op_code
= *op_code_data
++;
5300 switch (ext_op_code
)
5302 case DW_LNE_end_sequence
:
5303 /* Reset stuff after printing this row. */
5305 case DW_LNE_set_address
:
5306 SAFE_BYTE_GET_AND_INC (state_machine_regs
.address
,
5308 op_code_end
- op_code_data
,
5310 state_machine_regs
.op_index
= 0;
5311 state_machine_regs
.view
= 0;
5313 case DW_LNE_define_file
:
5314 file_table
= (File_Entry
*) xrealloc
5315 (file_table
, (n_files
+ 1) * sizeof (File_Entry
));
5317 ++state_machine_regs
.last_file_entry
;
5318 /* Source file name. */
5319 file_table
[n_files
].name
= op_code_data
;
5320 op_code_data
+= strlen ((char *) op_code_data
) + 1;
5321 /* Directory index. */
5322 READ_ULEB (file_table
[n_files
].directory_index
,
5323 op_code_data
, op_code_end
);
5324 /* Last modification time. */
5325 READ_ULEB (file_table
[n_files
].modification_date
,
5326 op_code_data
, op_code_end
);
5328 READ_ULEB (file_table
[n_files
].length
,
5329 op_code_data
, op_code_end
);
5333 case DW_LNE_set_discriminator
:
5334 case DW_LNE_HP_set_sequence
:
5335 /* Simply ignored. */
5339 printf (_("UNKNOWN (%u): length %ld\n"),
5340 ext_op_code
, (long int) (op_code_data
- data
));
5347 /* Increment view after printing this row. */
5350 case DW_LNS_advance_pc
:
5351 READ_ULEB (uladv
, data
, end
);
5352 if (linfo
.li_max_ops_per_insn
== 1)
5354 uladv
*= linfo
.li_min_insn_length
;
5355 state_machine_regs
.address
+= uladv
;
5357 state_machine_regs
.view
= 0;
5362 = ((state_machine_regs
.op_index
+ uladv
)
5363 / linfo
.li_max_ops_per_insn
)
5364 * linfo
.li_min_insn_length
;
5365 state_machine_regs
.address
5367 state_machine_regs
.op_index
5368 = (state_machine_regs
.op_index
+ uladv
)
5369 % linfo
.li_max_ops_per_insn
;
5371 state_machine_regs
.view
= 0;
5375 case DW_LNS_advance_line
:
5376 READ_SLEB (adv
, data
, end
);
5377 state_machine_regs
.line
+= adv
;
5380 case DW_LNS_set_file
:
5381 READ_ULEB (uladv
, data
, end
);
5382 state_machine_regs
.file
= uladv
;
5385 unsigned file
= state_machine_regs
.file
;
5388 if (linfo
.li_version
< 5)
5391 if (file_table
== NULL
|| n_files
== 0)
5392 printf (_("\n [Use file table entry %d]\n"), file
);
5394 else if (file
>= n_files
)
5396 warn (_("file index %u > number of files %u\n"), file
, n_files
);
5397 printf (_("\n <over large file table index %u>"), file
);
5399 else if ((dir
= file_table
[file
].directory_index
) == 0)
5400 /* If directory index is 0, that means current directory. */
5401 printf ("\n./%s:[++]\n", file_table
[file
].name
);
5402 else if (directory_table
== NULL
|| n_directories
== 0)
5403 printf (_("\n [Use file %s in directory table entry %d]\n"),
5404 file_table
[file
].name
, dir
);
5406 else if (dir
> n_directories
)
5408 warn (_("directory index %u > number of directories %" PRIu64
"\n"),
5409 dir
, n_directories
);
5410 printf (_("\n <over large directory table entry %u>\n"), dir
);
5412 else if (linfo
.li_version
>= 5)
5413 printf ("\n%s/%s:\n",
5414 /* The directory index starts counting at 0. */
5415 directory_table
[dir
], file_table
[file
].name
);
5417 printf ("\n%s/%s:\n",
5418 /* The directory index starts counting at 1. */
5419 directory_table
[dir
- 1], file_table
[file
].name
);
5423 case DW_LNS_set_column
:
5424 READ_ULEB (uladv
, data
, end
);
5425 state_machine_regs
.column
= uladv
;
5428 case DW_LNS_negate_stmt
:
5429 adv
= state_machine_regs
.is_stmt
;
5431 state_machine_regs
.is_stmt
= adv
;
5434 case DW_LNS_set_basic_block
:
5435 state_machine_regs
.basic_block
= 1;
5438 case DW_LNS_const_add_pc
:
5439 uladv
= ((255 - linfo
.li_opcode_base
) / linfo
.li_line_range
);
5440 if (linfo
.li_max_ops_per_insn
== 1)
5442 uladv
*= linfo
.li_min_insn_length
;
5443 state_machine_regs
.address
+= uladv
;
5445 state_machine_regs
.view
= 0;
5450 = ((state_machine_regs
.op_index
+ uladv
)
5451 / linfo
.li_max_ops_per_insn
)
5452 * linfo
.li_min_insn_length
;
5453 state_machine_regs
.address
5455 state_machine_regs
.op_index
5456 = (state_machine_regs
.op_index
+ uladv
)
5457 % linfo
.li_max_ops_per_insn
;
5459 state_machine_regs
.view
= 0;
5463 case DW_LNS_fixed_advance_pc
:
5464 SAFE_BYTE_GET_AND_INC (uladv
, data
, 2, end
);
5465 state_machine_regs
.address
+= uladv
;
5466 state_machine_regs
.op_index
= 0;
5467 /* Do NOT reset view. */
5470 case DW_LNS_set_prologue_end
:
5473 case DW_LNS_set_epilogue_begin
:
5476 case DW_LNS_set_isa
:
5477 READ_ULEB (uladv
, data
, end
);
5478 printf (_(" Set ISA to %lu\n"), uladv
);
5482 printf (_(" Unknown opcode %d with operands: "), op_code
);
5484 if (standard_opcodes
!= NULL
)
5485 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
5489 READ_ULEB (val
, data
, end
);
5490 printf ("%#" PRIx64
"%s", val
, i
== 1 ? "" : ", ");
5496 /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row
5497 to the DWARF address/line matrix. */
5498 if ((is_special_opcode
) || (xop
== -DW_LNE_end_sequence
)
5499 || (xop
== DW_LNS_copy
))
5501 const unsigned int MAX_FILENAME_LENGTH
= 35;
5503 char *newFileName
= NULL
;
5504 size_t fileNameLength
;
5508 unsigned indx
= state_machine_regs
.file
;
5510 if (linfo
.li_version
< 5)
5513 if (indx
>= n_files
)
5515 warn (_("corrupt file index %u encountered\n"), indx
);
5516 fileName
= _("<corrupt>");
5519 fileName
= (char *) file_table
[indx
].name
;
5522 fileName
= _("<unknown>");
5524 fileNameLength
= strlen (fileName
);
5525 newFileName
= fileName
;
5526 if (fileNameLength
> MAX_FILENAME_LENGTH
&& !do_wide
)
5528 newFileName
= (char *) xmalloc (MAX_FILENAME_LENGTH
+ 1);
5529 /* Truncate file name */
5530 memcpy (newFileName
,
5531 fileName
+ fileNameLength
- MAX_FILENAME_LENGTH
,
5532 MAX_FILENAME_LENGTH
);
5533 newFileName
[MAX_FILENAME_LENGTH
] = 0;
5536 /* A row with end_seq set to true has a meaningful address, but
5537 the other information in the same row is not significant.
5538 In such a row, print line as "-", and don't print
5540 if (!do_wide
|| fileNameLength
<= MAX_FILENAME_LENGTH
)
5542 if (linfo
.li_max_ops_per_insn
== 1)
5544 if (xop
== -DW_LNE_end_sequence
)
5545 printf ("%-35s %11s %#18" PRIx64
,
5547 state_machine_regs
.address
);
5549 printf ("%-35s %11d %#18" PRIx64
,
5550 newFileName
, state_machine_regs
.line
,
5551 state_machine_regs
.address
);
5555 if (xop
== -DW_LNE_end_sequence
)
5556 printf ("%-35s %11s %#18" PRIx64
"[%d]",
5558 state_machine_regs
.address
,
5559 state_machine_regs
.op_index
);
5561 printf ("%-35s %11d %#18" PRIx64
"[%d]",
5562 newFileName
, state_machine_regs
.line
,
5563 state_machine_regs
.address
,
5564 state_machine_regs
.op_index
);
5569 if (linfo
.li_max_ops_per_insn
== 1)
5571 if (xop
== -DW_LNE_end_sequence
)
5572 printf ("%s %11s %#18" PRIx64
,
5574 state_machine_regs
.address
);
5576 printf ("%s %11d %#18" PRIx64
,
5577 newFileName
, state_machine_regs
.line
,
5578 state_machine_regs
.address
);
5582 if (xop
== -DW_LNE_end_sequence
)
5583 printf ("%s %11s %#18" PRIx64
"[%d]",
5585 state_machine_regs
.address
,
5586 state_machine_regs
.op_index
);
5588 printf ("%s %11d %#18" PRIx64
"[%d]",
5589 newFileName
, state_machine_regs
.line
,
5590 state_machine_regs
.address
,
5591 state_machine_regs
.op_index
);
5595 if (xop
!= -DW_LNE_end_sequence
)
5597 if (state_machine_regs
.view
)
5598 printf (" %6u", state_machine_regs
.view
);
5602 if (state_machine_regs
.is_stmt
)
5607 state_machine_regs
.view
++;
5609 if (xop
== -DW_LNE_end_sequence
)
5611 reset_state_machine (linfo
.li_default_is_stmt
);
5615 if (newFileName
!= fileName
)
5627 if (directory_table
)
5629 free (directory_table
);
5630 directory_table
= NULL
;
5641 display_debug_lines (struct dwarf_section
*section
, void *file
)
5643 unsigned char *data
= section
->start
;
5644 unsigned char *end
= data
+ section
->size
;
5646 int retValDecoded
= 1;
5648 if (do_debug_lines
== 0)
5649 do_debug_lines
|= FLAG_DEBUG_LINES_RAW
;
5651 if (do_debug_lines
& FLAG_DEBUG_LINES_RAW
)
5652 retValRaw
= display_debug_lines_raw (section
, data
, end
, file
);
5654 if (do_debug_lines
& FLAG_DEBUG_LINES_DECODED
)
5655 retValDecoded
= display_debug_lines_decoded (section
, data
, data
, end
, file
);
5657 if (!retValRaw
|| !retValDecoded
)
5664 find_debug_info_for_offset (uint64_t offset
)
5668 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
5671 for (i
= 0; i
< num_debug_info_entries
; i
++)
5672 if (debug_information
[i
].cu_offset
== offset
)
5673 return debug_information
+ i
;
5679 get_gdb_index_symbol_kind_name (gdb_index_symbol_kind kind
)
5681 /* See gdb/gdb-index.h. */
5682 static const char * const kinds
[] =
5694 return _ (kinds
[kind
]);
5698 display_debug_pubnames_worker (struct dwarf_section
*section
,
5699 void *file ATTRIBUTE_UNUSED
,
5702 DWARF2_Internal_PubNames names
;
5703 unsigned char *start
= section
->start
;
5704 unsigned char *end
= start
+ section
->size
;
5706 /* It does not matter if this load fails,
5707 we test for that later on. */
5708 load_debug_info (file
);
5710 introduce (section
, false);
5714 unsigned char *data
;
5715 unsigned long sec_off
= start
- section
->start
;
5716 unsigned int offset_size
;
5718 SAFE_BYTE_GET_AND_INC (names
.pn_length
, start
, 4, end
);
5719 if (names
.pn_length
== 0xffffffff)
5721 SAFE_BYTE_GET_AND_INC (names
.pn_length
, start
, 8, end
);
5727 if (names
.pn_length
> (size_t) (end
- start
))
5729 warn (_("Debug info is corrupted, "
5730 "%s header at %#lx has length %#" PRIx64
"\n"),
5731 section
->name
, sec_off
, names
.pn_length
);
5736 start
+= names
.pn_length
;
5738 SAFE_BYTE_GET_AND_INC (names
.pn_version
, data
, 2, start
);
5739 SAFE_BYTE_GET_AND_INC (names
.pn_offset
, data
, offset_size
, start
);
5741 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
5742 && num_debug_info_entries
> 0
5743 && find_debug_info_for_offset (names
.pn_offset
) == NULL
)
5744 warn (_(".debug_info offset of %#" PRIx64
5745 " in %s section does not point to a CU header.\n"),
5746 names
.pn_offset
, section
->name
);
5748 SAFE_BYTE_GET_AND_INC (names
.pn_size
, data
, offset_size
, start
);
5750 printf (_(" Length: %" PRId64
"\n"),
5752 printf (_(" Version: %d\n"),
5754 printf (_(" Offset into .debug_info section: %#" PRIx64
"\n"),
5756 printf (_(" Size of area in .debug_info section: %" PRId64
"\n"),
5759 if (names
.pn_version
!= 2 && names
.pn_version
!= 3)
5761 static int warned
= 0;
5765 warn (_("Only DWARF 2 and 3 pubnames are currently supported\n"));
5773 printf (_("\n Offset Kind Name\n"));
5775 printf (_("\n Offset\tName\n"));
5782 SAFE_BYTE_GET_AND_INC (offset
, data
, offset_size
, start
);
5789 maxprint
= (start
- data
) - 1;
5793 unsigned int kind_data
;
5794 gdb_index_symbol_kind kind
;
5795 const char *kind_name
;
5798 SAFE_BYTE_GET_AND_INC (kind_data
, data
, 1, start
);
5800 /* GCC computes the kind as the upper byte in the CU index
5801 word, and then right shifts it by the CU index size.
5802 Left shift KIND to where the gdb-index.h accessor macros
5804 kind_data
<<= GDB_INDEX_CU_BITSIZE
;
5805 kind
= GDB_INDEX_SYMBOL_KIND_VALUE (kind_data
);
5806 kind_name
= get_gdb_index_symbol_kind_name (kind
);
5807 is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (kind_data
);
5808 printf (" %-6" PRIx64
" %s,%-10s %.*s\n",
5809 offset
, is_static
? _("s") : _("g"),
5810 kind_name
, (int) maxprint
, data
);
5813 printf (" %-6" PRIx64
"\t%.*s\n",
5814 offset
, (int) maxprint
, data
);
5816 data
+= strnlen ((char *) data
, maxprint
);
5829 display_debug_pubnames (struct dwarf_section
*section
, void *file
)
5831 return display_debug_pubnames_worker (section
, file
, 0);
5835 display_debug_gnu_pubnames (struct dwarf_section
*section
, void *file
)
5837 return display_debug_pubnames_worker (section
, file
, 1);
5841 display_debug_macinfo (struct dwarf_section
*section
,
5842 void *file ATTRIBUTE_UNUSED
)
5844 unsigned char *start
= section
->start
;
5845 unsigned char *end
= start
+ section
->size
;
5846 unsigned char *curr
= start
;
5847 enum dwarf_macinfo_record_type op
;
5849 introduce (section
, false);
5853 unsigned int lineno
;
5854 const unsigned char *string
;
5856 op
= (enum dwarf_macinfo_record_type
) *curr
;
5861 case DW_MACINFO_start_file
:
5863 unsigned int filenum
;
5865 READ_ULEB (lineno
, curr
, end
);
5866 READ_ULEB (filenum
, curr
, end
);
5867 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"),
5872 case DW_MACINFO_end_file
:
5873 printf (_(" DW_MACINFO_end_file\n"));
5876 case DW_MACINFO_define
:
5877 READ_ULEB (lineno
, curr
, end
);
5879 curr
+= strnlen ((char *) string
, end
- string
);
5880 printf (_(" DW_MACINFO_define - lineno : %d macro : %*s\n"),
5881 lineno
, (int) (curr
- string
), string
);
5886 case DW_MACINFO_undef
:
5887 READ_ULEB (lineno
, curr
, end
);
5889 curr
+= strnlen ((char *) string
, end
- string
);
5890 printf (_(" DW_MACINFO_undef - lineno : %d macro : %*s\n"),
5891 lineno
, (int) (curr
- string
), string
);
5896 case DW_MACINFO_vendor_ext
:
5898 unsigned int constant
;
5900 READ_ULEB (constant
, curr
, end
);
5902 curr
+= strnlen ((char *) string
, end
- string
);
5903 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %*s\n"),
5904 constant
, (int) (curr
- string
), string
);
5915 /* Given LINE_OFFSET into the .debug_line section, attempt to return
5916 filename and dirname corresponding to file name table entry with index
5917 FILEIDX. Return NULL on failure. */
5919 static unsigned char *
5920 get_line_filename_and_dirname (uint64_t line_offset
,
5922 unsigned char **dir_name
)
5924 struct dwarf_section
*section
= &debug_displays
[line
].section
;
5925 unsigned char *hdrptr
, *dirtable
, *file_name
;
5926 unsigned int offset_size
;
5927 unsigned int version
, opcode_base
;
5928 uint64_t length
, diridx
;
5929 const unsigned char * end
;
5932 if (section
->start
== NULL
5933 || line_offset
>= section
->size
5937 hdrptr
= section
->start
+ line_offset
;
5938 end
= section
->start
+ section
->size
;
5940 SAFE_BYTE_GET_AND_INC (length
, hdrptr
, 4, end
);
5941 if (length
== 0xffffffff)
5943 /* This section is 64-bit DWARF 3. */
5944 SAFE_BYTE_GET_AND_INC (length
, hdrptr
, 8, end
);
5950 if (length
> (size_t) (end
- hdrptr
)
5951 || length
< 2 + offset_size
+ 1 + 3 + 1)
5953 end
= hdrptr
+ length
;
5955 SAFE_BYTE_GET_AND_INC (version
, hdrptr
, 2, end
);
5956 if (version
!= 2 && version
!= 3 && version
!= 4)
5958 hdrptr
+= offset_size
+ 1;/* Skip prologue_length and min_insn_length. */
5960 hdrptr
++; /* Skip max_ops_per_insn. */
5961 hdrptr
+= 3; /* Skip default_is_stmt, line_base, line_range. */
5963 SAFE_BYTE_GET_AND_INC (opcode_base
, hdrptr
, 1, end
);
5964 if (opcode_base
== 0
5965 || opcode_base
- 1 >= (size_t) (end
- hdrptr
))
5968 hdrptr
+= opcode_base
- 1;
5971 /* Skip over dirname table. */
5972 while (*hdrptr
!= '\0')
5974 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
);
5980 hdrptr
++; /* Skip the NUL at the end of the table. */
5982 /* Now skip over preceding filename table entries. */
5983 for (; hdrptr
< end
&& *hdrptr
!= '\0' && fileidx
> 1; fileidx
--)
5985 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
);
5988 SKIP_ULEB (hdrptr
, end
);
5989 SKIP_ULEB (hdrptr
, end
);
5990 SKIP_ULEB (hdrptr
, end
);
5992 if (hdrptr
>= end
|| *hdrptr
== '\0')
5996 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
);
6001 READ_ULEB (diridx
, hdrptr
, end
);
6004 for (; dirtable
< end
&& *dirtable
!= '\0' && diridx
> 1; diridx
--)
6006 dirtable
+= strnlen ((char *) dirtable
, end
- dirtable
);
6010 if (dirtable
>= end
|| *dirtable
== '\0')
6012 *dir_name
= dirtable
;
6017 display_debug_macro (struct dwarf_section
*section
,
6020 unsigned char *start
= section
->start
;
6021 unsigned char *end
= start
+ section
->size
;
6022 unsigned char *curr
= start
;
6023 unsigned char *extended_op_buf
[256];
6024 bool is_dwo
= false;
6025 const char *suffix
= strrchr (section
->name
, '.');
6027 if (suffix
&& strcmp (suffix
, ".dwo") == 0)
6030 load_debug_section_with_follow (str
, file
);
6031 load_debug_section_with_follow (line
, file
);
6032 load_debug_section_with_follow (str_index
, file
);
6034 introduce (section
, false);
6038 unsigned int lineno
, version
, flags
;
6039 unsigned int offset_size
;
6040 const unsigned char *string
;
6041 uint64_t line_offset
= 0, sec_offset
= curr
- start
, offset
;
6042 unsigned char **extended_ops
= NULL
;
6044 SAFE_BYTE_GET_AND_INC (version
, curr
, 2, end
);
6045 if (version
!= 4 && version
!= 5)
6047 error (_("Expected to find a version number of 4 or 5 in section %s but found %d instead\n"),
6048 section
->name
, version
);
6052 SAFE_BYTE_GET_AND_INC (flags
, curr
, 1, end
);
6053 offset_size
= (flags
& 1) ? 8 : 4;
6054 printf (_(" Offset: %#" PRIx64
"\n"), sec_offset
);
6055 printf (_(" Version: %d\n"), version
);
6056 printf (_(" Offset size: %d\n"), offset_size
);
6059 SAFE_BYTE_GET_AND_INC (line_offset
, curr
, offset_size
, end
);
6060 printf (_(" Offset into .debug_line: %#" PRIx64
"\n"),
6065 unsigned int i
, count
, op
;
6068 SAFE_BYTE_GET_AND_INC (count
, curr
, 1, end
);
6070 memset (extended_op_buf
, 0, sizeof (extended_op_buf
));
6071 extended_ops
= extended_op_buf
;
6074 printf (_(" Extension opcode arguments:\n"));
6075 for (i
= 0; i
< count
; i
++)
6077 SAFE_BYTE_GET_AND_INC (op
, curr
, 1, end
);
6078 extended_ops
[op
] = curr
;
6079 READ_ULEB (nargs
, curr
, end
);
6081 printf (_(" DW_MACRO_%02x has no arguments\n"), op
);
6084 printf (_(" DW_MACRO_%02x arguments: "), op
);
6085 for (n
= 0; n
< nargs
; n
++)
6089 SAFE_BYTE_GET_AND_INC (form
, curr
, 1, end
);
6090 printf ("%s%s", get_FORM_name (form
),
6091 n
== nargs
- 1 ? "\n" : ", ");
6101 case DW_FORM_block1
:
6102 case DW_FORM_block2
:
6103 case DW_FORM_block4
:
6105 case DW_FORM_string
:
6107 case DW_FORM_sec_offset
:
6110 error (_("Invalid extension opcode form %s\n"),
6111 get_FORM_name (form
));
6127 error (_(".debug_macro section not zero terminated\n"));
6131 SAFE_BYTE_GET_AND_INC (op
, curr
, 1, end
);
6137 case DW_MACRO_define
:
6138 READ_ULEB (lineno
, curr
, end
);
6140 curr
+= strnlen ((char *) string
, end
- string
);
6141 printf (_(" DW_MACRO_define - lineno : %d macro : %*s\n"),
6142 lineno
, (int) (curr
- string
), string
);
6147 case DW_MACRO_undef
:
6148 READ_ULEB (lineno
, curr
, end
);
6150 curr
+= strnlen ((char *) string
, end
- string
);
6151 printf (_(" DW_MACRO_undef - lineno : %d macro : %*s\n"),
6152 lineno
, (int) (curr
- string
), string
);
6157 case DW_MACRO_start_file
:
6159 unsigned int filenum
;
6160 unsigned char *file_name
= NULL
, *dir_name
= NULL
;
6162 READ_ULEB (lineno
, curr
, end
);
6163 READ_ULEB (filenum
, curr
, end
);
6165 if ((flags
& 2) == 0)
6166 error (_("DW_MACRO_start_file used, but no .debug_line offset provided.\n"));
6169 = get_line_filename_and_dirname (line_offset
, filenum
,
6171 if (file_name
== NULL
)
6172 printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d\n"),
6175 printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d filename: %s%s%s\n"),
6177 dir_name
!= NULL
? (const char *) dir_name
: "",
6178 dir_name
!= NULL
? "/" : "", file_name
);
6182 case DW_MACRO_end_file
:
6183 printf (_(" DW_MACRO_end_file\n"));
6186 case DW_MACRO_define_strp
:
6187 READ_ULEB (lineno
, curr
, end
);
6188 if (version
== 4 && is_dwo
)
6189 READ_ULEB (offset
, curr
, end
);
6191 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6192 string
= fetch_indirect_string (offset
);
6193 printf (_(" DW_MACRO_define_strp - lineno : %d macro : %s\n"),
6197 case DW_MACRO_undef_strp
:
6198 READ_ULEB (lineno
, curr
, end
);
6199 if (version
== 4 && is_dwo
)
6200 READ_ULEB (offset
, curr
, end
);
6202 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6203 string
= fetch_indirect_string (offset
);
6204 printf (_(" DW_MACRO_undef_strp - lineno : %d macro : %s\n"),
6208 case DW_MACRO_import
:
6209 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6210 printf (_(" DW_MACRO_import - offset : %#" PRIx64
"\n"),
6214 case DW_MACRO_define_sup
:
6215 READ_ULEB (lineno
, curr
, end
);
6216 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6217 printf (_(" DW_MACRO_define_sup - lineno : %d"
6218 " macro offset : %#" PRIx64
"\n"),
6222 case DW_MACRO_undef_sup
:
6223 READ_ULEB (lineno
, curr
, end
);
6224 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6225 printf (_(" DW_MACRO_undef_sup - lineno : %d"
6226 " macro offset : %#" PRIx64
"\n"),
6230 case DW_MACRO_import_sup
:
6231 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6232 printf (_(" DW_MACRO_import_sup - offset : %#" PRIx64
"\n"),
6236 case DW_MACRO_define_strx
:
6237 case DW_MACRO_undef_strx
:
6238 READ_ULEB (lineno
, curr
, end
);
6239 READ_ULEB (offset
, curr
, end
);
6240 string
= (const unsigned char *)
6241 fetch_indexed_string (offset
, NULL
, offset_size
, false, 0);
6242 if (op
== DW_MACRO_define_strx
)
6243 printf (" DW_MACRO_define_strx ");
6245 printf (" DW_MACRO_undef_strx ");
6247 printf (_("(with offset %#" PRIx64
") "), offset
);
6248 printf (_("lineno : %d macro : %s\n"),
6253 if (op
>= DW_MACRO_lo_user
&& op
<= DW_MACRO_hi_user
)
6255 printf (_(" <Target Specific macro op: %#x - UNHANDLED"), op
);
6259 if (extended_ops
== NULL
|| extended_ops
[op
] == NULL
)
6261 error (_(" Unknown macro opcode %02x seen\n"), op
);
6266 /* Skip over unhandled opcodes. */
6268 unsigned char *desc
= extended_ops
[op
];
6269 READ_ULEB (nargs
, desc
, end
);
6272 printf (_(" DW_MACRO_%02x\n"), op
);
6275 printf (_(" DW_MACRO_%02x -"), op
);
6276 for (n
= 0; n
< nargs
; n
++)
6280 /* DW_FORM_implicit_const is not expected here. */
6281 SAFE_BYTE_GET_AND_INC (val
, desc
, 1, end
);
6283 = read_and_display_attr_value (0, val
, 0,
6284 start
, curr
, end
, 0, 0,
6285 offset_size
, version
,
6304 display_debug_abbrev (struct dwarf_section
*section
,
6305 void *file ATTRIBUTE_UNUSED
)
6307 abbrev_entry
*entry
;
6308 unsigned char *start
= section
->start
;
6310 introduce (section
, false);
6314 uint64_t offset
= start
- section
->start
;
6315 abbrev_list
*list
= find_and_process_abbrev_set (section
, 0,
6316 section
->size
, offset
,
6321 if (list
->first_abbrev
)
6322 printf (_(" Number TAG (%#" PRIx64
")\n"), offset
);
6324 for (entry
= list
->first_abbrev
; entry
; entry
= entry
->next
)
6328 printf (" %ld %s [%s]\n",
6330 get_TAG_name (entry
->tag
),
6331 entry
->children
? _("has children") : _("no children"));
6333 for (attr
= entry
->first_attr
; attr
; attr
= attr
->next
)
6335 printf (" %-18s %s",
6336 get_AT_name (attr
->attribute
),
6337 get_FORM_name (attr
->form
));
6338 if (attr
->form
== DW_FORM_implicit_const
)
6339 printf (": %" PRId64
, attr
->implicit_const
);
6343 start
= list
->start_of_next_abbrevs
;
6344 free_abbrev_list (list
);
6353 /* Return true when ADDR is the maximum address, when addresses are
6354 POINTER_SIZE bytes long. */
6357 is_max_address (uint64_t addr
, unsigned int pointer_size
)
6359 uint64_t mask
= ~(~(uint64_t) 0 << 1 << (pointer_size
* 8 - 1));
6360 return ((addr
& mask
) == mask
);
6363 /* Display a view pair list starting at *VSTART_PTR and ending at
6364 VLISTEND within SECTION. */
6367 display_view_pair_list (struct dwarf_section
*section
,
6368 unsigned char **vstart_ptr
,
6369 unsigned int debug_info_entry
,
6370 unsigned char *vlistend
)
6372 unsigned char *vstart
= *vstart_ptr
;
6373 unsigned char *section_end
= section
->start
+ section
->size
;
6374 unsigned int pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
6376 if (vlistend
< section_end
)
6377 section_end
= vlistend
;
6381 while (vstart
< section_end
)
6383 uint64_t off
= vstart
- section
->start
;
6384 uint64_t vbegin
, vend
;
6386 READ_ULEB (vbegin
, vstart
, section_end
);
6387 if (vstart
== section_end
)
6390 READ_ULEB (vend
, vstart
, section_end
);
6391 printf (" %8.8" PRIx64
" ", off
);
6393 print_view (vbegin
, pointer_size
);
6394 print_view (vend
, pointer_size
);
6395 printf (_("location view pair\n"));
6399 *vstart_ptr
= vstart
;
6402 /* Display a location list from a normal (ie, non-dwo) .debug_loc section. */
6405 display_loc_list (struct dwarf_section
*section
,
6406 unsigned char **start_ptr
,
6407 unsigned int debug_info_entry
,
6409 uint64_t base_address
,
6410 unsigned char **vstart_ptr
,
6413 unsigned char *start
= *start_ptr
, *vstart
= *vstart_ptr
;
6414 unsigned char *section_end
= section
->start
+ section
->size
;
6416 unsigned int pointer_size
;
6417 unsigned int offset_size
;
6421 unsigned short length
;
6422 int need_frame_base
;
6424 if (debug_info_entry
>= num_debug_info_entries
)
6426 warn (_("No debug information available for loc lists of entry: %u\n"),
6431 cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
6432 pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
6433 offset_size
= debug_information
[debug_info_entry
].offset_size
;
6434 dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
6436 if (pointer_size
< 2 || pointer_size
> 8)
6438 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
6439 pointer_size
, debug_info_entry
);
6445 uint64_t off
= offset
+ (start
- *start_ptr
);
6446 uint64_t vbegin
= -1, vend
= -1;
6448 if (2 * pointer_size
> (size_t) (section_end
- start
))
6450 warn (_("Location list starting at offset %#" PRIx64
6451 " is not terminated.\n"), offset
);
6458 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, section_end
);
6459 SAFE_BYTE_GET_AND_INC (end
, start
, pointer_size
, section_end
);
6461 if (begin
== 0 && end
== 0)
6463 /* PR 18374: In a object file we can have a location list that
6464 starts with a begin and end of 0 because there are relocations
6465 that need to be applied to the addresses. Actually applying
6466 the relocations now does not help as they will probably resolve
6467 to 0, since the object file has not been fully linked. Real
6468 end of list markers will not have any relocations against them. */
6469 if (! reloc_at (section
, off
)
6470 && ! reloc_at (section
, off
+ pointer_size
))
6472 printf (_("<End of list>\n"));
6477 /* Check base address specifiers. */
6478 if (is_max_address (begin
, pointer_size
)
6479 && !is_max_address (end
, pointer_size
))
6482 print_hex (begin
, pointer_size
);
6483 print_hex (end
, pointer_size
);
6484 printf (_("(base address)\n"));
6490 off
= offset
+ (vstart
- *start_ptr
);
6492 READ_ULEB (vbegin
, vstart
, section_end
);
6493 print_view (vbegin
, pointer_size
);
6495 READ_ULEB (vend
, vstart
, section_end
);
6496 print_view (vend
, pointer_size
);
6498 printf (_("views at %8.8" PRIx64
" for:\n %*s "), off
, 8, "");
6501 if (2 > (size_t) (section_end
- start
))
6503 warn (_("Location list starting at offset %#" PRIx64
6504 " is not terminated.\n"), offset
);
6508 SAFE_BYTE_GET_AND_INC (length
, start
, 2, section_end
);
6510 if (length
> (size_t) (section_end
- start
))
6512 warn (_("Location list starting at offset %#" PRIx64
6513 " is not terminated.\n"), offset
);
6517 print_hex (begin
+ base_address
, pointer_size
);
6518 print_hex (end
+ base_address
, pointer_size
);
6521 need_frame_base
= decode_location_expression (start
,
6526 cu_offset
, section
);
6529 if (need_frame_base
&& !has_frame_base
)
6530 printf (_(" [without DW_AT_frame_base]"));
6532 if (begin
== end
&& vbegin
== vend
)
6533 fputs (_(" (start == end)"), stdout
);
6534 else if (begin
> end
|| (begin
== end
&& vbegin
> vend
))
6535 fputs (_(" (start > end)"), stdout
);
6543 *vstart_ptr
= vstart
;
6546 /* Display a location list from a normal (ie, non-dwo) .debug_loclists section. */
6549 display_loclists_list (struct dwarf_section
* section
,
6550 unsigned char ** start_ptr
,
6551 unsigned int debug_info_entry
,
6553 uint64_t base_address
,
6554 unsigned char ** vstart_ptr
,
6557 unsigned char *start
= *start_ptr
;
6558 unsigned char *vstart
= *vstart_ptr
;
6559 unsigned char *section_end
= section
->start
+ section
->size
;
6561 unsigned int pointer_size
;
6562 unsigned int offset_size
;
6563 unsigned int dwarf_version
;
6565 /* Initialize it due to a false compiler warning. */
6566 uint64_t begin
= -1, vbegin
= -1;
6567 uint64_t end
= -1, vend
= -1;
6569 int need_frame_base
;
6571 if (debug_info_entry
>= num_debug_info_entries
)
6573 warn (_("No debug information available for "
6574 "loclists lists of entry: %u\n"),
6579 cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
6580 pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
6581 offset_size
= debug_information
[debug_info_entry
].offset_size
;
6582 dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
6584 if (pointer_size
< 2 || pointer_size
> 8)
6586 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
6587 pointer_size
, debug_info_entry
);
6593 uint64_t off
= offset
+ (start
- *start_ptr
);
6594 enum dwarf_location_list_entry_type llet
;
6596 if (start
+ 1 > section_end
)
6598 warn (_("Location list starting at offset %#" PRIx64
6599 " is not terminated.\n"), offset
);
6606 SAFE_BYTE_GET_AND_INC (llet
, start
, 1, section_end
);
6608 if (vstart
&& (llet
== DW_LLE_offset_pair
6609 || llet
== DW_LLE_start_end
6610 || llet
== DW_LLE_start_length
))
6612 off
= offset
+ (vstart
- *start_ptr
);
6614 READ_ULEB (vbegin
, vstart
, section_end
);
6615 print_view (vbegin
, pointer_size
);
6617 READ_ULEB (vend
, vstart
, section_end
);
6618 print_view (vend
, pointer_size
);
6620 printf (_("views at %8.8" PRIx64
" for:\n %*s "), off
, 8, "");
6625 case DW_LLE_end_of_list
:
6626 printf (_("<End of list>\n"));
6629 case DW_LLE_base_addressx
:
6630 READ_ULEB (base_address
, start
, section_end
);
6631 print_hex (base_address
, pointer_size
);
6632 printf (_("(index into .debug_addr) "));
6633 base_address
= fetch_indexed_addr (base_address
, pointer_size
);
6634 print_hex (base_address
, pointer_size
);
6635 printf (_("(base address)\n"));
6638 case DW_LLE_startx_endx
:
6639 READ_ULEB (begin
, start
, section_end
);
6640 begin
= fetch_indexed_addr (begin
, pointer_size
);
6641 READ_ULEB (end
, start
, section_end
);
6642 end
= fetch_indexed_addr (end
, pointer_size
);
6645 case DW_LLE_startx_length
:
6646 READ_ULEB (begin
, start
, section_end
);
6647 begin
= fetch_indexed_addr (begin
, pointer_size
);
6648 READ_ULEB (end
, start
, section_end
);
6652 case DW_LLE_default_location
:
6656 case DW_LLE_offset_pair
:
6657 READ_ULEB (begin
, start
, section_end
);
6658 begin
+= base_address
;
6659 READ_ULEB (end
, start
, section_end
);
6660 end
+= base_address
;
6663 case DW_LLE_base_address
:
6664 SAFE_BYTE_GET_AND_INC (base_address
, start
, pointer_size
,
6666 print_hex (base_address
, pointer_size
);
6667 printf (_("(base address)\n"));
6670 case DW_LLE_start_end
:
6671 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, section_end
);
6672 SAFE_BYTE_GET_AND_INC (end
, start
, pointer_size
, section_end
);
6675 case DW_LLE_start_length
:
6676 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, section_end
);
6677 READ_ULEB (end
, start
, section_end
);
6681 #ifdef DW_LLE_view_pair
6682 case DW_LLE_view_pair
:
6684 printf (_("View pair entry in loclist with locviews attribute\n"));
6685 READ_ULEB (vbegin
, start
, section_end
);
6686 print_view (vbegin
, pointer_size
);
6688 READ_ULEB (vend
, start
, section_end
);
6689 print_view (vend
, pointer_size
);
6691 printf (_("views for:\n"));
6696 error (_("Invalid location list entry type %d\n"), llet
);
6700 if (llet
== DW_LLE_end_of_list
)
6703 if (llet
== DW_LLE_base_address
6704 || llet
== DW_LLE_base_addressx
)
6707 if (start
== section_end
)
6709 warn (_("Location list starting at offset %#" PRIx64
6710 " is not terminated.\n"), offset
);
6713 READ_ULEB (length
, start
, section_end
);
6715 if (length
> (size_t) (section_end
- start
))
6717 warn (_("Location list starting at offset %#" PRIx64
6718 " is not terminated.\n"), offset
);
6722 print_hex (begin
, pointer_size
);
6723 print_hex (end
, pointer_size
);
6726 need_frame_base
= decode_location_expression (start
,
6731 cu_offset
, section
);
6734 if (need_frame_base
&& !has_frame_base
)
6735 printf (_(" [without DW_AT_frame_base]"));
6737 if (begin
== end
&& vbegin
== vend
)
6738 fputs (_(" (start == end)"), stdout
);
6739 else if (begin
> end
|| (begin
== end
&& vbegin
> vend
))
6740 fputs (_(" (start > end)"), stdout
);
6748 if (vbegin
!= (uint64_t) -1 || vend
!= (uint64_t) -1)
6749 printf (_("Trailing view pair not used in a range"));
6752 *vstart_ptr
= vstart
;
6755 /* Print a .debug_addr table index in decimal, surrounded by square brackets,
6756 right-adjusted in a field of length LEN, and followed by a space. */
6759 print_addr_index (unsigned int idx
, unsigned int len
)
6761 static char buf
[15];
6762 snprintf (buf
, sizeof (buf
), "[%d]", idx
);
6763 printf ("%*s ", len
, buf
);
6766 /* Display a location list from a .dwo section. It uses address indexes rather
6767 than embedded addresses. This code closely follows display_loc_list, but the
6768 two are sufficiently different that combining things is very ugly. */
6771 display_loc_list_dwo (struct dwarf_section
*section
,
6772 unsigned char **start_ptr
,
6773 unsigned int debug_info_entry
,
6775 unsigned char **vstart_ptr
,
6778 unsigned char *start
= *start_ptr
, *vstart
= *vstart_ptr
;
6779 unsigned char *section_end
= section
->start
+ section
->size
;
6781 unsigned int pointer_size
;
6782 unsigned int offset_size
;
6785 unsigned short length
;
6786 int need_frame_base
;
6789 if (debug_info_entry
>= num_debug_info_entries
)
6791 warn (_("No debug information for loc lists of entry: %u\n"),
6796 cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
6797 pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
6798 offset_size
= debug_information
[debug_info_entry
].offset_size
;
6799 dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
6801 if (pointer_size
< 2 || pointer_size
> 8)
6803 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
6804 pointer_size
, debug_info_entry
);
6811 print_hex (offset
+ (start
- *start_ptr
), 4);
6813 if (start
>= section_end
)
6815 warn (_("Location list starting at offset %#" PRIx64
6816 " is not terminated.\n"), offset
);
6820 SAFE_BYTE_GET_AND_INC (entry_type
, start
, 1, section_end
);
6833 uint64_t off
= offset
+ (vstart
- *start_ptr
);
6835 READ_ULEB (view
, vstart
, section_end
);
6836 print_view (view
, 8);
6838 READ_ULEB (view
, vstart
, section_end
);
6839 print_view (view
, 8);
6841 printf (_("views at %8.8" PRIx64
" for:\n %*s "), off
, 8, "");
6849 case 0: /* A terminating entry. */
6851 *vstart_ptr
= vstart
;
6852 printf (_("<End of list>\n"));
6854 case 1: /* A base-address entry. */
6855 READ_ULEB (idx
, start
, section_end
);
6856 print_addr_index (idx
, 8);
6857 printf ("%*s", 9 + (vstart
? 2 * 6 : 0), "");
6858 printf (_("(base address selection entry)\n"));
6860 case 2: /* A start/end entry. */
6861 READ_ULEB (idx
, start
, section_end
);
6862 print_addr_index (idx
, 8);
6863 READ_ULEB (idx
, start
, section_end
);
6864 print_addr_index (idx
, 8);
6866 case 3: /* A start/length entry. */
6867 READ_ULEB (idx
, start
, section_end
);
6868 print_addr_index (idx
, 8);
6869 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
6870 printf ("%08x ", idx
);
6872 case 4: /* An offset pair entry. */
6873 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
6874 printf ("%08x ", idx
);
6875 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
6876 printf ("%08x ", idx
);
6879 warn (_("Unknown location list entry type 0x%x.\n"), entry_type
);
6881 *vstart_ptr
= vstart
;
6885 if (2 > (size_t) (section_end
- start
))
6887 warn (_("Location list starting at offset %#" PRIx64
6888 " is not terminated.\n"), offset
);
6892 SAFE_BYTE_GET_AND_INC (length
, start
, 2, section_end
);
6893 if (length
> (size_t) (section_end
- start
))
6895 warn (_("Location list starting at offset %#" PRIx64
6896 " is not terminated.\n"), offset
);
6901 need_frame_base
= decode_location_expression (start
,
6906 cu_offset
, section
);
6909 if (need_frame_base
&& !has_frame_base
)
6910 printf (_(" [without DW_AT_frame_base]"));
6918 *vstart_ptr
= vstart
;
6921 /* Sort array of indexes in ascending order of loc_offsets[idx] and
6924 static uint64_t *loc_offsets
, *loc_views
;
6927 loc_offsets_compar (const void *ap
, const void *bp
)
6929 uint64_t a
= loc_offsets
[*(const unsigned int *) ap
];
6930 uint64_t b
= loc_offsets
[*(const unsigned int *) bp
];
6932 int ret
= (a
> b
) - (b
> a
);
6936 a
= loc_views
[*(const unsigned int *) ap
];
6937 b
= loc_views
[*(const unsigned int *) bp
];
6939 ret
= (a
> b
) - (b
> a
);
6945 display_offset_entry_loclists (struct dwarf_section
*section
)
6947 unsigned char * start
= section
->start
;
6948 unsigned char * const end
= start
+ section
->size
;
6950 introduce (section
, false);
6955 unsigned short version
;
6956 unsigned char address_size
;
6957 unsigned char segment_selector_size
;
6958 uint32_t offset_entry_count
;
6962 printf (_("Table at Offset %#tx\n"), start
- section
->start
);
6964 SAFE_BYTE_GET_AND_INC (length
, start
, 4, end
);
6965 if (length
== 0xffffffff)
6968 SAFE_BYTE_GET_AND_INC (length
, start
, 8, end
);
6973 SAFE_BYTE_GET_AND_INC (version
, start
, 2, end
);
6974 SAFE_BYTE_GET_AND_INC (address_size
, start
, 1, end
);
6975 SAFE_BYTE_GET_AND_INC (segment_selector_size
, start
, 1, end
);
6976 SAFE_BYTE_GET_AND_INC (offset_entry_count
, start
, 4, end
);
6978 printf (_(" Length: %#" PRIx64
"\n"), length
);
6979 printf (_(" DWARF version: %u\n"), version
);
6980 printf (_(" Address size: %u\n"), address_size
);
6981 printf (_(" Segment size: %u\n"), segment_selector_size
);
6982 printf (_(" Offset entries: %u\n"), offset_entry_count
);
6986 warn (_("The %s section contains a corrupt or "
6987 "unsupported version number: %d.\n"),
6988 section
->name
, version
);
6992 if (segment_selector_size
!= 0)
6994 warn (_("The %s section contains an "
6995 "unsupported segment selector size: %d.\n"),
6996 section
->name
, segment_selector_size
);
7000 if (offset_entry_count
== 0)
7002 warn (_("The %s section contains a table without offset\n"),
7007 printf (_("\n Offset Entries starting at %#tx:\n"),
7008 start
- section
->start
);
7010 for (i
= 0; i
< offset_entry_count
; i
++)
7014 SAFE_BYTE_GET_AND_INC (entry
, start
, is_64bit
? 8 : 4, end
);
7015 printf (_(" [%6u] %#" PRIx64
"\n"), i
, entry
);
7022 for (j
= 1, i
= 0; i
< offset_entry_count
;)
7025 uint64_t base_address
= 0;
7028 uint64_t off
= start
- section
->start
;
7032 printf (_(" Offset Entry %u\n"), i
);
7039 SAFE_BYTE_GET_AND_INC (lle
, start
, 1, end
);
7043 case DW_LLE_end_of_list
:
7044 printf (_("<End of list>\n\n"));
7048 case DW_LLE_base_addressx
:
7049 READ_ULEB (base_address
, start
, end
);
7050 print_hex (base_address
, address_size
);
7051 printf (_("(index into .debug_addr) "));
7052 base_address
= fetch_indexed_addr (base_address
, address_size
);
7053 print_hex (base_address
, address_size
);
7054 printf (_("(base address)\n"));
7057 case DW_LLE_startx_endx
:
7058 READ_ULEB (begin
, start
, end
);
7059 begin
= fetch_indexed_addr (begin
, address_size
);
7060 READ_ULEB (finish
, start
, end
);
7061 finish
= fetch_indexed_addr (finish
, address_size
);
7064 case DW_LLE_startx_length
:
7065 READ_ULEB (begin
, start
, end
);
7066 begin
= fetch_indexed_addr (begin
, address_size
);
7067 READ_ULEB (finish
, start
, end
);
7071 case DW_LLE_offset_pair
:
7072 READ_ULEB (begin
, start
, end
);
7073 begin
+= base_address
;
7074 READ_ULEB (finish
, start
, end
);
7075 finish
+= base_address
;
7078 case DW_LLE_default_location
:
7082 case DW_LLE_base_address
:
7083 SAFE_BYTE_GET_AND_INC (base_address
, start
, address_size
, end
);
7084 print_hex (base_address
, address_size
);
7085 printf (_("(base address)\n"));
7088 case DW_LLE_start_end
:
7089 SAFE_BYTE_GET_AND_INC (begin
, start
, address_size
, end
);
7090 SAFE_BYTE_GET_AND_INC (finish
, start
, address_size
, end
);
7093 case DW_LLE_start_length
:
7094 SAFE_BYTE_GET_AND_INC (begin
, start
, address_size
, end
);
7095 READ_ULEB (finish
, start
, end
);
7100 error (_("Invalid location list entry type %d\n"), lle
);
7106 warn (_("Location list starting at offset %#" PRIx64
7107 " is not terminated.\n"), off
);
7111 print_hex (begin
, address_size
);
7112 print_hex (finish
, address_size
);
7114 if (begin
== finish
)
7115 fputs (_("(start == end)"), stdout
);
7116 else if (begin
> finish
)
7117 fputs (_("(start > end)"), stdout
);
7119 /* Read the counted location descriptions. */
7120 READ_ULEB (length
, start
, end
);
7122 if (length
> (size_t) (end
- start
))
7124 warn (_("Location list starting at offset %#" PRIx64
7125 " is not terminated.\n"), off
);
7129 (void) decode_location_expression (start
, address_size
, address_size
,
7130 version
, length
, 0, section
);
7137 while (start
< end
);
7143 display_debug_loc (struct dwarf_section
*section
, void *file
)
7145 unsigned char *start
= section
->start
, *vstart
= NULL
;
7147 unsigned char *section_begin
= start
;
7148 unsigned int num_loc_list
= 0;
7149 uint64_t last_offset
= 0;
7150 uint64_t last_view
= 0;
7151 unsigned int first
= 0;
7154 int seen_first_offset
= 0;
7155 int locs_sorted
= 1;
7156 unsigned char *next
= start
, *vnext
= vstart
;
7157 unsigned int *array
= NULL
;
7158 const char *suffix
= strrchr (section
->name
, '.');
7159 bool is_dwo
= false;
7160 int is_loclists
= strstr (section
->name
, "debug_loclists") != NULL
;
7161 uint64_t expected_start
= 0;
7163 if (suffix
&& strcmp (suffix
, ".dwo") == 0)
7166 bytes
= section
->size
;
7170 printf (_("\nThe %s section is empty.\n"), section
->name
);
7176 unsigned char *hdrptr
= section_begin
;
7178 unsigned short ll_version
;
7179 unsigned char *end
= section_begin
+ section
->size
;
7180 unsigned char address_size
, segment_selector_size
;
7181 uint32_t offset_entry_count
;
7183 SAFE_BYTE_GET_AND_INC (ll_length
, hdrptr
, 4, end
);
7184 if (ll_length
== 0xffffffff)
7185 SAFE_BYTE_GET_AND_INC (ll_length
, hdrptr
, 8, end
);
7187 SAFE_BYTE_GET_AND_INC (ll_version
, hdrptr
, 2, end
);
7188 if (ll_version
!= 5)
7190 warn (_("The %s section contains corrupt or "
7191 "unsupported version number: %d.\n"),
7192 section
->name
, ll_version
);
7196 SAFE_BYTE_GET_AND_INC (address_size
, hdrptr
, 1, end
);
7198 SAFE_BYTE_GET_AND_INC (segment_selector_size
, hdrptr
, 1, end
);
7199 if (segment_selector_size
!= 0)
7201 warn (_("The %s section contains "
7202 "unsupported segment selector size: %d.\n"),
7203 section
->name
, segment_selector_size
);
7207 SAFE_BYTE_GET_AND_INC (offset_entry_count
, hdrptr
, 4, end
);
7209 if (offset_entry_count
!= 0)
7210 return display_offset_entry_loclists (section
);
7212 expected_start
= hdrptr
- section_begin
;
7215 if (load_debug_info (file
) == 0)
7217 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
7222 /* Check the order of location list in .debug_info section. If
7223 offsets of location lists are in the ascending order, we can
7224 use `debug_information' directly. */
7225 for (i
= 0; i
< num_debug_info_entries
; i
++)
7229 num
= debug_information
[i
].num_loc_offsets
;
7230 if (num
> num_loc_list
)
7233 /* Check if we can use `debug_information' directly. */
7234 if (locs_sorted
&& num
!= 0)
7236 if (!seen_first_offset
)
7238 /* This is the first location list. */
7239 last_offset
= debug_information
[i
].loc_offsets
[0];
7240 last_view
= debug_information
[i
].loc_views
[0];
7242 seen_first_offset
= 1;
7248 for (; j
< num
; j
++)
7251 debug_information
[i
].loc_offsets
[j
]
7252 || (last_offset
== debug_information
[i
].loc_offsets
[j
]
7253 && last_view
> debug_information
[i
].loc_views
[j
]))
7258 last_offset
= debug_information
[i
].loc_offsets
[j
];
7259 last_view
= debug_information
[i
].loc_views
[j
];
7264 if (!seen_first_offset
)
7265 error (_("No location lists in .debug_info section!\n"));
7267 if (debug_information
[first
].num_loc_offsets
> 0
7268 && debug_information
[first
].loc_offsets
[0] != expected_start
7269 && debug_information
[first
].loc_views
[0] != expected_start
)
7270 warn (_("Location lists in %s section start at %#" PRIx64
7271 " rather than %#" PRIx64
"\n"),
7272 section
->name
, debug_information
[first
].loc_offsets
[0],
7276 array
= (unsigned int *) xcmalloc (num_loc_list
, sizeof (unsigned int));
7278 introduce (section
, false);
7280 if (reloc_at (section
, 0))
7281 printf (_(" Warning: This section has relocations - addresses seen here may not be accurate.\n\n"));
7283 printf (_(" Offset Begin End Expression\n"));
7285 seen_first_offset
= 0;
7286 for (i
= first
; i
< num_debug_info_entries
; i
++)
7288 uint64_t offset
, voffset
;
7289 uint64_t base_address
;
7295 for (k
= 0; k
< debug_information
[i
].num_loc_offsets
; k
++)
7297 loc_offsets
= debug_information
[i
].loc_offsets
;
7298 loc_views
= debug_information
[i
].loc_views
;
7299 qsort (array
, debug_information
[i
].num_loc_offsets
,
7300 sizeof (*array
), loc_offsets_compar
);
7303 int adjacent_view_loclists
= 1;
7304 for (k
= 0; k
< debug_information
[i
].num_loc_offsets
; k
++)
7306 j
= locs_sorted
? k
: array
[k
];
7308 && (debug_information
[i
].loc_offsets
[locs_sorted
7309 ? k
- 1 : array
[k
- 1]]
7310 == debug_information
[i
].loc_offsets
[j
])
7311 && (debug_information
[i
].loc_views
[locs_sorted
7312 ? k
- 1 : array
[k
- 1]]
7313 == debug_information
[i
].loc_views
[j
]))
7315 has_frame_base
= debug_information
[i
].have_frame_base
[j
];
7316 offset
= debug_information
[i
].loc_offsets
[j
];
7317 next
= section_begin
+ offset
;
7318 voffset
= debug_information
[i
].loc_views
[j
];
7319 if (voffset
!= (uint64_t) -1)
7320 vnext
= section_begin
+ voffset
;
7323 base_address
= debug_information
[i
].base_address
;
7325 if (vnext
&& vnext
< next
)
7328 display_view_pair_list (section
, &vstart
, i
, next
);
7333 if (!seen_first_offset
|| !adjacent_view_loclists
)
7334 seen_first_offset
= 1;
7338 warn (_("There is a hole [%#tx - %#" PRIx64
"]"
7339 " in %s section.\n"),
7340 start
- section_begin
, offset
, section
->name
);
7341 else if (start
> next
)
7342 warn (_("There is an overlap [%#tx - %#" PRIx64
"]"
7343 " in %s section.\n"),
7344 start
- section_begin
, offset
, section
->name
);
7349 if (offset
>= bytes
)
7351 warn (_("Offset %#" PRIx64
" is bigger than %s section size.\n"),
7352 offset
, section
->name
);
7356 if (vnext
&& voffset
>= bytes
)
7358 warn (_("View Offset %#" PRIx64
" is bigger than %s section size.\n"),
7359 voffset
, section
->name
);
7366 display_loc_list_dwo (section
, &start
, i
, offset
,
7367 &vstart
, has_frame_base
);
7369 display_loc_list (section
, &start
, i
, offset
, base_address
,
7370 &vstart
, has_frame_base
);
7375 warn (_("DWO is not yet supported.\n"));
7377 display_loclists_list (section
, &start
, i
, offset
, base_address
,
7378 &vstart
, has_frame_base
);
7381 /* FIXME: this arrangement is quite simplistic. Nothing
7382 requires locview lists to be adjacent to corresponding
7383 loclists, and a single loclist could be augmented by
7384 different locview lists, and vice-versa, unlikely as it
7385 is that it would make sense to do so. Hopefully we'll
7386 have view pair support built into loclists before we ever
7387 need to address all these possibilities. */
7388 if (adjacent_view_loclists
&& vnext
7389 && vnext
!= start
&& vstart
!= next
)
7391 adjacent_view_loclists
= 0;
7392 warn (_("Hole and overlap detection requires adjacent view lists and loclists.\n"));
7395 if (vnext
&& vnext
== start
)
7396 display_view_pair_list (section
, &start
, i
, vstart
);
7400 if (start
< section
->start
+ section
->size
)
7401 warn (ngettext ("There is %ld unused byte at the end of section %s\n",
7402 "There are %ld unused bytes at the end of section %s\n",
7403 (long) (section
->start
+ section
->size
- start
)),
7404 (long) (section
->start
+ section
->size
- start
), section
->name
);
7411 display_debug_str (struct dwarf_section
*section
,
7412 void *file ATTRIBUTE_UNUSED
)
7414 unsigned char *start
= section
->start
;
7415 uint64_t bytes
= section
->size
;
7416 uint64_t addr
= section
->address
;
7420 printf (_("\nThe %s section is empty.\n"), section
->name
);
7424 introduce (section
, false);
7432 lbytes
= (bytes
> 16 ? 16 : bytes
);
7434 printf (" 0x%8.8" PRIx64
" ", addr
);
7436 for (j
= 0; j
< 16; j
++)
7439 printf ("%2.2x", start
[j
]);
7447 for (j
= 0; j
< lbytes
; j
++)
7450 if (k
>= ' ' && k
< 0x80)
7469 display_debug_info (struct dwarf_section
*section
, void *file
)
7471 return process_debug_info (section
, file
, section
->abbrev_sec
, false, false);
7475 display_debug_types (struct dwarf_section
*section
, void *file
)
7477 return process_debug_info (section
, file
, section
->abbrev_sec
, false, true);
7481 display_trace_info (struct dwarf_section
*section
, void *file
)
7483 return process_debug_info (section
, file
, section
->abbrev_sec
, false, true);
7487 display_debug_aranges (struct dwarf_section
*section
,
7488 void *file ATTRIBUTE_UNUSED
)
7490 unsigned char *start
= section
->start
;
7491 unsigned char *end
= start
+ section
->size
;
7493 introduce (section
, false);
7495 /* It does not matter if this load fails,
7496 we test for that later on. */
7497 load_debug_info (file
);
7501 unsigned char *hdrptr
;
7502 DWARF2_Internal_ARange arange
;
7503 unsigned char *addr_ranges
;
7507 unsigned char address_size
;
7508 unsigned int offset_size
;
7509 unsigned char *end_ranges
;
7512 sec_off
= hdrptr
- section
->start
;
7514 SAFE_BYTE_GET_AND_INC (arange
.ar_length
, hdrptr
, 4, end
);
7515 if (arange
.ar_length
== 0xffffffff)
7517 SAFE_BYTE_GET_AND_INC (arange
.ar_length
, hdrptr
, 8, end
);
7523 if (arange
.ar_length
> (size_t) (end
- hdrptr
))
7525 warn (_("Debug info is corrupted, %s header at %#" PRIx64
7526 " has length %#" PRIx64
"\n"),
7527 section
->name
, sec_off
, arange
.ar_length
);
7530 end_ranges
= hdrptr
+ arange
.ar_length
;
7532 SAFE_BYTE_GET_AND_INC (arange
.ar_version
, hdrptr
, 2, end_ranges
);
7533 SAFE_BYTE_GET_AND_INC (arange
.ar_info_offset
, hdrptr
, offset_size
,
7536 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
7537 && num_debug_info_entries
> 0
7538 && find_debug_info_for_offset (arange
.ar_info_offset
) == NULL
)
7539 warn (_(".debug_info offset of %#" PRIx64
7540 " in %s section does not point to a CU header.\n"),
7541 arange
.ar_info_offset
, section
->name
);
7543 SAFE_BYTE_GET_AND_INC (arange
.ar_pointer_size
, hdrptr
, 1, end_ranges
);
7544 SAFE_BYTE_GET_AND_INC (arange
.ar_segment_size
, hdrptr
, 1, end_ranges
);
7546 if (arange
.ar_version
!= 2 && arange
.ar_version
!= 3)
7548 /* PR 19872: A version number of 0 probably means that there is
7549 padding at the end of the .debug_aranges section. Gold puts
7550 it there when performing an incremental link, for example.
7551 So do not generate a warning in this case. */
7552 if (arange
.ar_version
)
7553 warn (_("Only DWARF 2 and 3 aranges are currently supported.\n"));
7557 printf (_(" Length: %" PRId64
"\n"), arange
.ar_length
);
7558 printf (_(" Version: %d\n"), arange
.ar_version
);
7559 printf (_(" Offset into .debug_info: %#" PRIx64
"\n"),
7560 arange
.ar_info_offset
);
7561 printf (_(" Pointer Size: %d\n"), arange
.ar_pointer_size
);
7562 printf (_(" Segment Size: %d\n"), arange
.ar_segment_size
);
7564 address_size
= arange
.ar_pointer_size
+ arange
.ar_segment_size
;
7566 /* PR 17512: file: 001-108546-0.001:0.1. */
7567 if (address_size
== 0 || address_size
> 8)
7569 error (_("Invalid address size in %s section!\n"),
7574 /* The DWARF spec does not require that the address size be a power
7575 of two, but we do. This will have to change if we ever encounter
7576 an uneven architecture. */
7577 if ((address_size
& (address_size
- 1)) != 0)
7579 warn (_("Pointer size + Segment size is not a power of two.\n"));
7583 if (address_size
> 4)
7584 printf (_("\n Address Length\n"));
7586 printf (_("\n Address Length\n"));
7588 addr_ranges
= hdrptr
;
7590 /* Must pad to an alignment boundary that is twice the address size. */
7591 addr_ranges
+= (2 * address_size
- 1
7592 - (hdrptr
- start
- 1) % (2 * address_size
));
7594 while (2 * address_size
<= end_ranges
- addr_ranges
)
7596 SAFE_BYTE_GET_AND_INC (address
, addr_ranges
, address_size
,
7598 SAFE_BYTE_GET_AND_INC (length
, addr_ranges
, address_size
,
7601 print_hex (address
, address_size
);
7602 print_hex_ns (length
, address_size
);
7614 /* Comparison function for qsort. */
7616 comp_addr_base (const void * v0
, const void * v1
)
7618 debug_info
*info0
= *(debug_info
**) v0
;
7619 debug_info
*info1
= *(debug_info
**) v1
;
7620 return info0
->addr_base
- info1
->addr_base
;
7623 /* Display the debug_addr section. */
7625 display_debug_addr (struct dwarf_section
*section
,
7628 debug_info
**debug_addr_info
;
7629 unsigned char *entry
;
7633 unsigned char * header
;
7635 if (section
->size
== 0)
7637 printf (_("\nThe %s section is empty.\n"), section
->name
);
7641 if (load_debug_info (file
) == 0)
7643 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
7648 introduce (section
, false);
7650 /* PR 17531: file: cf38d01b.
7651 We use xcalloc because a corrupt file may not have initialised all of the
7652 fields in the debug_info structure, which means that the sort below might
7653 try to move uninitialised data. */
7654 debug_addr_info
= (debug_info
**) xcalloc ((num_debug_info_entries
+ 1),
7655 sizeof (debug_info
*));
7658 for (i
= 0; i
< num_debug_info_entries
; i
++)
7659 if (debug_information
[i
].addr_base
!= DEBUG_INFO_UNAVAILABLE
)
7661 /* PR 17531: file: cf38d01b. */
7662 if (debug_information
[i
].addr_base
>= section
->size
)
7663 warn (_("Corrupt address base (%#" PRIx64
")"
7664 " found in debug section %u\n"),
7665 debug_information
[i
].addr_base
, i
);
7667 debug_addr_info
[count
++] = debug_information
+ i
;
7670 /* Add a sentinel to make iteration convenient. */
7671 debug_addr_info
[count
] = (debug_info
*) xmalloc (sizeof (debug_info
));
7672 debug_addr_info
[count
]->addr_base
= section
->size
;
7673 qsort (debug_addr_info
, count
, sizeof (debug_info
*), comp_addr_base
);
7675 header
= section
->start
;
7676 for (i
= 0; i
< count
; i
++)
7679 unsigned int address_size
= debug_addr_info
[i
]->pointer_size
;
7681 printf (_(" For compilation unit at offset %#" PRIx64
":\n"),
7682 debug_addr_info
[i
]->cu_offset
);
7684 printf (_("\tIndex\tAddress\n"));
7685 entry
= section
->start
+ debug_addr_info
[i
]->addr_base
;
7686 if (debug_addr_info
[i
]->dwarf_version
>= 5)
7688 size_t header_size
= entry
- header
;
7689 unsigned char *curr_header
= header
;
7692 int segment_selector_size
;
7694 if (header_size
!= 8 && header_size
!= 16)
7696 warn (_("Corrupt %s section: expecting header size of 8 or 16, but found %zd instead\n"),
7697 section
->name
, header_size
);
7701 SAFE_BYTE_GET_AND_INC (length
, curr_header
, 4, entry
);
7702 if (length
== 0xffffffff)
7703 SAFE_BYTE_GET_AND_INC (length
, curr_header
, 8, entry
);
7704 end
= curr_header
+ length
;
7706 SAFE_BYTE_GET_AND_INC (version
, curr_header
, 2, entry
);
7708 warn (_("Corrupt %s section: expecting version number 5 in header but found %d instead\n"),
7709 section
->name
, version
);
7711 SAFE_BYTE_GET_AND_INC (address_size
, curr_header
, 1, entry
);
7712 SAFE_BYTE_GET_AND_INC (segment_selector_size
, curr_header
, 1, entry
);
7713 address_size
+= segment_selector_size
;
7716 end
= section
->start
+ debug_addr_info
[i
+ 1]->addr_base
;
7721 uint64_t base
= byte_get (entry
, address_size
);
7722 printf (_("\t%d:\t"), idx
);
7723 print_hex_ns (base
, address_size
);
7725 entry
+= address_size
;
7731 free (debug_addr_info
);
7735 /* Display the .debug_str_offsets and .debug_str_offsets.dwo sections. */
7738 display_debug_str_offsets (struct dwarf_section
*section
,
7739 void *file ATTRIBUTE_UNUSED
)
7743 if (section
->size
== 0)
7745 printf (_("\nThe %s section is empty.\n"), section
->name
);
7749 unsigned char *start
= section
->start
;
7750 unsigned char *end
= start
+ section
->size
;
7751 unsigned char *curr
= start
;
7752 uint64_t debug_str_offsets_hdr_len
;
7754 const char *suffix
= strrchr (section
->name
, '.');
7755 bool dwo
= suffix
&& strcmp (suffix
, ".dwo") == 0;
7758 load_debug_section_with_follow (str_dwo
, file
);
7760 load_debug_section_with_follow (str
, file
);
7762 introduce (section
, false);
7767 uint64_t entry_length
;
7769 SAFE_BYTE_GET_AND_INC (length
, curr
, 4, end
);
7770 /* FIXME: We assume that this means 64-bit DWARF is being used. */
7771 if (length
== 0xffffffff)
7773 SAFE_BYTE_GET_AND_INC (length
, curr
, 8, end
);
7775 debug_str_offsets_hdr_len
= 16;
7780 debug_str_offsets_hdr_len
= 8;
7783 unsigned char *entries_end
;
7786 /* This is probably an old style .debug_str_offset section which
7787 just contains offsets and no header (and the first offset is 0). */
7788 length
= section
->size
;
7789 curr
= section
->start
;
7792 printf (_(" Length: %#" PRIx64
"\n"), length
);
7793 printf (_(" Index Offset [String]\n"));
7797 if (length
<= (size_t) (end
- curr
))
7798 entries_end
= curr
+ length
;
7801 warn (_("Section %s is too small %#" PRIx64
"\n"),
7802 section
->name
, section
->size
);
7807 SAFE_BYTE_GET_AND_INC (version
, curr
, 2, entries_end
);
7809 warn (_("Unexpected version number in str_offset header: %#x\n"), version
);
7812 SAFE_BYTE_GET_AND_INC (padding
, curr
, 2, entries_end
);
7814 warn (_("Unexpected value in str_offset header's padding field: %#x\n"), padding
);
7816 printf (_(" Length: %#" PRIx64
"\n"), length
);
7817 printf (_(" Version: %#x\n"), version
);
7818 printf (_(" Index Offset [String]\n"));
7821 for (idx
= 0; curr
< entries_end
; idx
++)
7824 const unsigned char * string
;
7826 if ((size_t) (entries_end
- curr
) < entry_length
)
7827 /* Not enough space to read one entry_length, give up. */
7830 SAFE_BYTE_GET_AND_INC (offset
, curr
, entry_length
, entries_end
);
7832 string
= (const unsigned char *)
7833 fetch_indexed_string (idx
, NULL
, entry_length
, dwo
, debug_str_offsets_hdr_len
);
7835 string
= fetch_indirect_string (offset
);
7837 printf (" %8lu ", idx
);
7838 print_hex (offset
, entry_length
);
7839 printf (" %s\n", string
);
7846 /* Each debug_information[x].range_lists[y] gets this representation for
7847 sorting purposes. */
7851 /* The debug_information[x].range_lists[y] value. */
7852 uint64_t ranges_offset
;
7854 /* Original debug_information to find parameters of the data. */
7855 debug_info
*debug_info_p
;
7858 /* Sort struct range_entry in ascending order of its RANGES_OFFSET. */
7861 range_entry_compar (const void *ap
, const void *bp
)
7863 const struct range_entry
*a_re
= (const struct range_entry
*) ap
;
7864 const struct range_entry
*b_re
= (const struct range_entry
*) bp
;
7865 const uint64_t a
= a_re
->ranges_offset
;
7866 const uint64_t b
= b_re
->ranges_offset
;
7868 return (a
> b
) - (b
> a
);
7872 display_debug_ranges_list (unsigned char * start
,
7873 unsigned char * finish
,
7874 unsigned int pointer_size
,
7876 uint64_t base_address
)
7878 while (start
< finish
)
7883 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
7884 if (start
>= finish
)
7886 SAFE_SIGNED_BYTE_GET_AND_INC (end
, start
, pointer_size
, finish
);
7889 print_hex (offset
, 4);
7891 if (begin
== 0 && end
== 0)
7893 printf (_("<End of list>\n"));
7897 /* Check base address specifiers. */
7898 if (is_max_address (begin
, pointer_size
)
7899 && !is_max_address (end
, pointer_size
))
7902 print_hex (begin
, pointer_size
);
7903 print_hex (end
, pointer_size
);
7904 printf ("(base address)\n");
7908 print_hex (begin
+ base_address
, pointer_size
);
7909 print_hex_ns (end
+ base_address
, pointer_size
);
7912 fputs (_(" (start == end)"), stdout
);
7913 else if (begin
> end
)
7914 fputs (_(" (start > end)"), stdout
);
7920 static unsigned char *
7921 display_debug_rnglists_list (unsigned char * start
,
7922 unsigned char * finish
,
7923 unsigned int pointer_size
,
7925 uint64_t base_address
,
7926 unsigned int offset_size
)
7928 unsigned char *next
= start
;
7929 unsigned int debug_addr_section_hdr_len
;
7931 if (offset_size
== 4)
7932 debug_addr_section_hdr_len
= 8;
7934 debug_addr_section_hdr_len
= 16;
7938 uint64_t off
= offset
+ (start
- next
);
7939 enum dwarf_range_list_entry rlet
;
7940 /* Initialize it due to a false compiler warning. */
7941 uint64_t begin
= -1, length
, end
= -1;
7943 if (start
>= finish
)
7945 warn (_("Range list starting at offset %#" PRIx64
7946 " is not terminated.\n"), offset
);
7953 SAFE_BYTE_GET_AND_INC (rlet
, start
, 1, finish
);
7957 case DW_RLE_end_of_list
:
7958 printf (_("<End of list>\n"));
7960 case DW_RLE_base_addressx
:
7961 READ_ULEB (base_address
, start
, finish
);
7962 print_hex (base_address
, pointer_size
);
7963 printf (_("(base address index) "));
7964 base_address
= fetch_indexed_addr ((base_address
* pointer_size
)
7965 + debug_addr_section_hdr_len
, pointer_size
);
7966 print_hex (base_address
, pointer_size
);
7967 printf (_("(base address)\n"));
7969 case DW_RLE_startx_endx
:
7970 READ_ULEB (begin
, start
, finish
);
7971 READ_ULEB (end
, start
, finish
);
7972 begin
= fetch_indexed_addr ((begin
* pointer_size
)
7973 + debug_addr_section_hdr_len
, pointer_size
);
7974 end
= fetch_indexed_addr ((begin
* pointer_size
)
7975 + debug_addr_section_hdr_len
, pointer_size
);
7977 case DW_RLE_startx_length
:
7978 READ_ULEB (begin
, start
, finish
);
7979 READ_ULEB (length
, start
, finish
);
7980 begin
= fetch_indexed_addr ((begin
* pointer_size
)
7981 + debug_addr_section_hdr_len
, pointer_size
);
7982 end
= begin
+ length
;
7984 case DW_RLE_offset_pair
:
7985 READ_ULEB (begin
, start
, finish
);
7986 READ_ULEB (end
, start
, finish
);
7988 case DW_RLE_base_address
:
7989 SAFE_BYTE_GET_AND_INC (base_address
, start
, pointer_size
, finish
);
7990 print_hex (base_address
, pointer_size
);
7991 printf (_("(base address)\n"));
7993 case DW_RLE_start_end
:
7994 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
7995 SAFE_BYTE_GET_AND_INC (end
, start
, pointer_size
, finish
);
7997 case DW_RLE_start_length
:
7998 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
7999 READ_ULEB (length
, start
, finish
);
8000 end
= begin
+ length
;
8003 error (_("Invalid range list entry type %d\n"), rlet
);
8004 rlet
= DW_RLE_end_of_list
;
8008 if (rlet
== DW_RLE_end_of_list
)
8010 if (rlet
== DW_RLE_base_address
|| rlet
== DW_RLE_base_addressx
)
8013 /* Only a DW_RLE_offset_pair needs the base address added. */
8014 if (rlet
== DW_RLE_offset_pair
)
8016 begin
+= base_address
;
8017 end
+= base_address
;
8020 print_hex (begin
, pointer_size
);
8021 print_hex (end
, pointer_size
);
8024 fputs (_(" (start == end)"), stdout
);
8025 else if (begin
> end
)
8026 fputs (_(" (start > end)"), stdout
);
8035 display_debug_rnglists (struct dwarf_section
*section
)
8037 unsigned char *start
= section
->start
;
8038 unsigned char *finish
= start
+ section
->size
;
8040 while (start
< finish
)
8042 unsigned char *table_start
;
8043 uint64_t offset
= start
- section
->start
;
8045 uint64_t initial_length
;
8046 unsigned char segment_selector_size
;
8047 unsigned int offset_entry_count
;
8049 unsigned short version
;
8050 unsigned char address_size
= 0;
8051 unsigned char offset_size
;
8053 /* Get and check the length of the block. */
8054 SAFE_BYTE_GET_AND_INC (initial_length
, start
, 4, finish
);
8056 if (initial_length
== 0xffffffff)
8058 /* This section is 64-bit DWARF 3. */
8059 SAFE_BYTE_GET_AND_INC (initial_length
, start
, 8, finish
);
8065 if (initial_length
> (size_t) (finish
- start
))
8067 /* If the length field has a relocation against it, then we should
8068 not complain if it is inaccurate (and probably negative).
8069 It is copied from .debug_line handling code. */
8070 if (reloc_at (section
, (start
- section
->start
) - offset_size
))
8071 initial_length
= finish
- start
;
8074 warn (_("The length field (%#" PRIx64
8075 ") in the debug_rnglists header is wrong"
8076 " - the section is too small\n"),
8082 end
= start
+ initial_length
;
8084 /* Get the other fields in the header. */
8085 SAFE_BYTE_GET_AND_INC (version
, start
, 2, finish
);
8086 SAFE_BYTE_GET_AND_INC (address_size
, start
, 1, finish
);
8087 SAFE_BYTE_GET_AND_INC (segment_selector_size
, start
, 1, finish
);
8088 SAFE_BYTE_GET_AND_INC (offset_entry_count
, start
, 4, finish
);
8090 printf (_(" Table at Offset: %#" PRIx64
":\n"), offset
);
8091 printf (_(" Length: %#" PRIx64
"\n"), initial_length
);
8092 printf (_(" DWARF version: %u\n"), version
);
8093 printf (_(" Address size: %u\n"), address_size
);
8094 printf (_(" Segment size: %u\n"), segment_selector_size
);
8095 printf (_(" Offset entries: %u\n"), offset_entry_count
);
8097 /* Check the fields. */
8098 if (segment_selector_size
!= 0)
8100 warn (_("The %s section contains "
8101 "unsupported segment selector size: %d.\n"),
8102 section
->name
, segment_selector_size
);
8108 warn (_("Only DWARF version 5+ debug_rnglists info "
8109 "is currently supported.\n"));
8113 table_start
= start
;
8115 if (offset_entry_count
!= 0)
8117 printf (_("\n Offsets starting at %#tx:\n"),
8118 start
- section
->start
);
8120 for (i
= 0; i
< offset_entry_count
; i
++)
8124 SAFE_BYTE_GET_AND_INC (entry
, start
, offset_size
, finish
);
8125 printf (_(" [%6u] %#" PRIx64
"\n"), i
, entry
);
8129 offset_entry_count
= 1;
8131 for (i
= 0; i
< offset_entry_count
; i
++)
8133 uint64_t indx
= start
- table_start
;
8135 offset
= start
- section
->start
;
8136 printf (_("\n Offset: %#" PRIx64
", Index: %#" PRIx64
"\n"),
8138 printf (_(" Offset Begin End\n"));
8139 start
= display_debug_rnglists_list
8140 (start
, end
, address_size
, offset
, 0, offset_size
);
8156 display_debug_ranges (struct dwarf_section
*section
,
8157 void *file ATTRIBUTE_UNUSED
)
8159 unsigned char *start
= section
->start
;
8160 unsigned char *last_start
= start
;
8161 uint64_t bytes
= section
->size
;
8162 unsigned char *section_begin
= start
;
8163 unsigned char *finish
= start
+ bytes
;
8164 unsigned int num_range_list
, i
;
8165 struct range_entry
*range_entries
;
8166 struct range_entry
*range_entry_fill
;
8167 int is_rnglists
= strstr (section
->name
, "debug_rnglists") != NULL
;
8168 /* Initialize it due to a false compiler warning. */
8169 unsigned char address_size
= 0;
8170 uint64_t last_offset
= 0;
8174 printf (_("\nThe %s section is empty.\n"), section
->name
);
8178 introduce (section
, false);
8181 return display_debug_rnglists (section
);
8183 if (load_debug_info (file
) == 0)
8185 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
8191 for (i
= 0; i
< num_debug_info_entries
; i
++)
8192 num_range_list
+= debug_information
[i
].num_range_lists
;
8194 if (num_range_list
== 0)
8196 /* This can happen when the file was compiled with -gsplit-debug
8197 which removes references to range lists from the primary .o file. */
8198 printf (_("No range lists in .debug_info section.\n"));
8202 range_entries
= (struct range_entry
*)
8203 xmalloc (sizeof (*range_entries
) * num_range_list
);
8204 range_entry_fill
= range_entries
;
8206 for (i
= 0; i
< num_debug_info_entries
; i
++)
8208 debug_info
*debug_info_p
= &debug_information
[i
];
8211 for (j
= 0; j
< debug_info_p
->num_range_lists
; j
++)
8213 range_entry_fill
->ranges_offset
= debug_info_p
->range_lists
[j
];
8214 range_entry_fill
->debug_info_p
= debug_info_p
;
8219 qsort (range_entries
, num_range_list
, sizeof (*range_entries
),
8220 range_entry_compar
);
8222 if (dwarf_check
!= 0 && range_entries
[0].ranges_offset
!= 0)
8223 warn (_("Range lists in %s section start at %#" PRIx64
"\n"),
8224 section
->name
, range_entries
[0].ranges_offset
);
8227 printf (_(" Offset Begin End\n"));
8229 for (i
= 0; i
< num_range_list
; i
++)
8231 struct range_entry
*range_entry
= &range_entries
[i
];
8232 debug_info
*debug_info_p
= range_entry
->debug_info_p
;
8233 unsigned int pointer_size
;
8235 unsigned char *next
;
8236 uint64_t base_address
;
8238 pointer_size
= (is_rnglists
? address_size
: debug_info_p
->pointer_size
);
8239 offset
= range_entry
->ranges_offset
;
8240 base_address
= debug_info_p
->base_address
;
8242 /* PR 17512: file: 001-101485-0.001:0.1. */
8243 if (pointer_size
< 2 || pointer_size
> 8)
8245 warn (_("Corrupt pointer size (%d) in debug entry at offset %#" PRIx64
"\n"),
8246 pointer_size
, offset
);
8250 if (offset
> (size_t) (finish
- section_begin
))
8252 warn (_("Corrupt offset (%#" PRIx64
") in range entry %u\n"),
8257 next
= section_begin
+ offset
+ debug_info_p
->rnglists_base
;
8259 /* If multiple DWARF entities reference the same range then we will
8260 have multiple entries in the `range_entries' list for the same
8261 offset. Thanks to the sort above these will all be consecutive in
8262 the `range_entries' list, so we can easily ignore duplicates
8264 if (i
> 0 && last_offset
== offset
)
8266 last_offset
= offset
;
8268 if (dwarf_check
!= 0 && i
> 0)
8271 warn (_("There is a hole [%#tx - %#tx] in %s section.\n"),
8272 start
- section_begin
, next
- section_begin
, section
->name
);
8273 else if (start
> next
)
8275 if (next
== last_start
)
8277 warn (_("There is an overlap [%#tx - %#tx] in %s section.\n"),
8278 start
- section_begin
, next
- section_begin
, section
->name
);
8285 display_debug_ranges_list
8286 (start
, finish
, pointer_size
, offset
, base_address
);
8290 free (range_entries
);
8295 typedef struct Frame_Chunk
8297 struct Frame_Chunk
*next
;
8298 unsigned char *chunk_start
;
8300 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
8301 short int *col_type
;
8304 unsigned int code_factor
;
8308 unsigned int cfa_reg
;
8309 uint64_t cfa_offset
;
8311 unsigned char fde_encoding
;
8312 unsigned char cfa_exp
;
8313 unsigned char ptr_size
;
8314 unsigned char segment_size
;
8318 typedef const char *(*dwarf_regname_lookup_ftype
) (unsigned int);
8319 static dwarf_regname_lookup_ftype dwarf_regnames_lookup_func
;
8320 static const char *const *dwarf_regnames
;
8321 static unsigned int dwarf_regnames_count
;
8322 static bool is_aarch64
;
8324 /* A marker for a col_type that means this column was never referenced
8325 in the frame info. */
8326 #define DW_CFA_unreferenced (-1)
8328 /* Return 0 if no more space is needed, 1 if more space is needed,
8329 -1 for invalid reg. */
8332 frame_need_space (Frame_Chunk
*fc
, unsigned int reg
)
8334 unsigned int prev
= fc
->ncols
;
8336 if (reg
< (unsigned int) fc
->ncols
)
8339 if (dwarf_regnames_count
> 0
8340 && reg
> dwarf_regnames_count
)
8343 fc
->ncols
= reg
+ 1;
8344 /* PR 17512: file: 10450-2643-0.004.
8345 If reg == -1 then this can happen... */
8349 /* PR 17512: file: 2844a11d. */
8350 if (fc
->ncols
> 1024 && dwarf_regnames_count
== 0)
8352 error (_("Unfeasibly large register number: %u\n"), reg
);
8354 /* FIXME: 1024 is an arbitrary limit. Increase it if
8355 we ever encounter a valid binary that exceeds it. */
8359 fc
->col_type
= (short int *) xcrealloc (fc
->col_type
, fc
->ncols
,
8360 sizeof (short int));
8361 fc
->col_offset
= (int *) xcrealloc (fc
->col_offset
, fc
->ncols
, sizeof (int));
8362 /* PR 17512: file:002-10025-0.005. */
8363 if (fc
->col_type
== NULL
|| fc
->col_offset
== NULL
)
8365 error (_("Out of memory allocating %u columns in dwarf frame arrays\n"),
8371 while (prev
< fc
->ncols
)
8373 fc
->col_type
[prev
] = DW_CFA_unreferenced
;
8374 fc
->col_offset
[prev
] = 0;
8380 static const char *const dwarf_regnames_i386
[] =
8382 "eax", "ecx", "edx", "ebx", /* 0 - 3 */
8383 "esp", "ebp", "esi", "edi", /* 4 - 7 */
8384 "eip", "eflags", NULL
, /* 8 - 10 */
8385 "st0", "st1", "st2", "st3", /* 11 - 14 */
8386 "st4", "st5", "st6", "st7", /* 15 - 18 */
8387 NULL
, NULL
, /* 19 - 20 */
8388 "xmm0", "xmm1", "xmm2", "xmm3", /* 21 - 24 */
8389 "xmm4", "xmm5", "xmm6", "xmm7", /* 25 - 28 */
8390 "mm0", "mm1", "mm2", "mm3", /* 29 - 32 */
8391 "mm4", "mm5", "mm6", "mm7", /* 33 - 36 */
8392 "fcw", "fsw", "mxcsr", /* 37 - 39 */
8393 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
, /* 40 - 47 */
8394 "tr", "ldtr", /* 48 - 49 */
8395 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 50 - 57 */
8396 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 58 - 65 */
8397 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 66 - 73 */
8398 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 74 - 81 */
8399 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 82 - 89 */
8400 NULL
, NULL
, NULL
, /* 90 - 92 */
8401 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7" /* 93 - 100 */
8404 static const char *const dwarf_regnames_iamcu
[] =
8406 "eax", "ecx", "edx", "ebx", /* 0 - 3 */
8407 "esp", "ebp", "esi", "edi", /* 4 - 7 */
8408 "eip", "eflags", NULL
, /* 8 - 10 */
8409 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 11 - 18 */
8410 NULL
, NULL
, /* 19 - 20 */
8411 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 21 - 28 */
8412 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 29 - 36 */
8413 NULL
, NULL
, NULL
, /* 37 - 39 */
8414 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
, /* 40 - 47 */
8415 "tr", "ldtr", /* 48 - 49 */
8416 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 50 - 57 */
8417 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 58 - 65 */
8418 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 66 - 73 */
8419 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 74 - 81 */
8420 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 82 - 89 */
8421 NULL
, NULL
, NULL
, /* 90 - 92 */
8422 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
/* 93 - 100 */
8426 init_dwarf_regnames_i386 (void)
8428 dwarf_regnames
= dwarf_regnames_i386
;
8429 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_i386
);
8430 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8434 init_dwarf_regnames_iamcu (void)
8436 dwarf_regnames
= dwarf_regnames_iamcu
;
8437 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_iamcu
);
8438 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8441 static const char *const DW_CFA_GNU_window_save_name
[] =
8443 "DW_CFA_GNU_window_save",
8444 "DW_CFA_AARCH64_negate_ra_state"
8447 static const char *const dwarf_regnames_x86_64
[] =
8449 "rax", "rdx", "rcx", "rbx",
8450 "rsi", "rdi", "rbp", "rsp",
8451 "r8", "r9", "r10", "r11",
8452 "r12", "r13", "r14", "r15",
8454 "xmm0", "xmm1", "xmm2", "xmm3",
8455 "xmm4", "xmm5", "xmm6", "xmm7",
8456 "xmm8", "xmm9", "xmm10", "xmm11",
8457 "xmm12", "xmm13", "xmm14", "xmm15",
8458 "st0", "st1", "st2", "st3",
8459 "st4", "st5", "st6", "st7",
8460 "mm0", "mm1", "mm2", "mm3",
8461 "mm4", "mm5", "mm6", "mm7",
8463 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
,
8464 "fs.base", "gs.base", NULL
, NULL
,
8466 "mxcsr", "fcw", "fsw",
8467 "xmm16", "xmm17", "xmm18", "xmm19",
8468 "xmm20", "xmm21", "xmm22", "xmm23",
8469 "xmm24", "xmm25", "xmm26", "xmm27",
8470 "xmm28", "xmm29", "xmm30", "xmm31",
8471 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 83 - 90 */
8472 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 91 - 98 */
8473 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 99 - 106 */
8474 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 107 - 114 */
8475 NULL
, NULL
, NULL
, /* 115 - 117 */
8476 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7"
8480 init_dwarf_regnames_x86_64 (void)
8482 dwarf_regnames
= dwarf_regnames_x86_64
;
8483 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_x86_64
);
8484 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8487 static const char *const dwarf_regnames_aarch64
[] =
8489 "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7",
8490 "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15",
8491 "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23",
8492 "x24", "x25", "x26", "x27", "x28", "x29", "x30", "sp",
8493 NULL
, "elr", NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
8494 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, "vg", "ffr",
8495 "p0", "p1", "p2", "p3", "p4", "p5", "p6", "p7",
8496 "p8", "p9", "p10", "p11", "p12", "p13", "p14", "p15",
8497 "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7",
8498 "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15",
8499 "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23",
8500 "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31",
8501 "z0", "z1", "z2", "z3", "z4", "z5", "z6", "z7",
8502 "z8", "z9", "z10", "z11", "z12", "z13", "z14", "z15",
8503 "z16", "z17", "z18", "z19", "z20", "z21", "z22", "z23",
8504 "z24", "z25", "z26", "z27", "z28", "z29", "z30", "z31",
8508 init_dwarf_regnames_aarch64 (void)
8510 dwarf_regnames
= dwarf_regnames_aarch64
;
8511 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_aarch64
);
8512 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8516 static const char *const dwarf_regnames_s390
[] =
8518 /* Avoid saying "r5 (r5)", so omit the names of r0-r15. */
8519 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
8520 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
8521 "f0", "f2", "f4", "f6", "f1", "f3", "f5", "f7",
8522 "f8", "f10", "f12", "f14", "f9", "f11", "f13", "f15",
8523 "cr0", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7",
8524 "cr8", "cr9", "cr10", "cr11", "cr12", "cr13", "cr14", "cr15",
8525 "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7",
8526 "a8", "a9", "a10", "a11", "a12", "a13", "a14", "a15",
8529 "v16", "v18", "v20", "v22", "v17", "v19", "v21", "v23",
8530 "v24", "v26", "v28", "v30", "v25", "v27", "v29", "v31",
8534 init_dwarf_regnames_s390 (void)
8536 dwarf_regnames
= dwarf_regnames_s390
;
8537 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_s390
);
8538 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8541 static const char *const dwarf_regnames_riscv
[] =
8543 "zero", "ra", "sp", "gp", "tp", "t0", "t1", "t2", /* 0 - 7 */
8544 "s0", "s1", "a0", "a1", "a2", "a3", "a4", "a5", /* 8 - 15 */
8545 "a6", "a7", "s2", "s3", "s4", "s5", "s6", "s7", /* 16 - 23 */
8546 "s8", "s9", "s10", "s11", "t3", "t4", "t5", "t6", /* 24 - 31 */
8547 "ft0", "ft1", "ft2", "ft3", "ft4", "ft5", "ft6", "ft7", /* 32 - 39 */
8548 "fs0", "fs1", /* 40 - 41 */
8549 "fa0", "fa1", "fa2", "fa3", "fa4", "fa5", "fa6", "fa7", /* 42 - 49 */
8550 "fs2", "fs3", "fs4", "fs5", "fs6", "fs7", "fs8", "fs9", /* 50 - 57 */
8551 "fs10", "fs11", /* 58 - 59 */
8552 "ft8", "ft9", "ft10", "ft11", /* 60 - 63 */
8553 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 64 - 71 */
8554 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 72 - 79 */
8555 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 80 - 87 */
8556 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 88 - 95 */
8557 "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", /* 96 - 103 */
8558 "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15", /* 104 - 111 */
8559 "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23", /* 112 - 119 */
8560 "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31", /* 120 - 127 */
8563 /* A RISC-V replacement for REGNAME_INTERNAL_BY_TABLE_ONLY which handles
8564 the large number of CSRs. */
8567 regname_internal_riscv (unsigned int regno
)
8569 const char *name
= NULL
;
8571 /* Lookup in the table first, this covers GPR and FPR. */
8572 if (regno
< ARRAY_SIZE (dwarf_regnames_riscv
))
8573 name
= dwarf_regnames_riscv
[regno
];
8574 else if (regno
>= 4096 && regno
<= 8191)
8576 /* This might be a CSR, these live in a sparse number space from 4096
8577 to 8191 These numbers are defined in the RISC-V ELF ABI
8581 #define DECLARE_CSR(NAME,VALUE,CLASS,DEFINE_VER,ABORT_VER) \
8582 case VALUE + 4096: name = #NAME; break;
8583 #include "opcode/riscv-opc.h"
8588 static char csr_name
[10];
8589 snprintf (csr_name
, sizeof (csr_name
), "csr%d", (regno
- 4096));
8600 init_dwarf_regnames_riscv (void)
8602 dwarf_regnames
= NULL
;
8603 dwarf_regnames_count
= 8192;
8604 dwarf_regnames_lookup_func
= regname_internal_riscv
;
8608 init_dwarf_regnames_by_elf_machine_code (unsigned int e_machine
)
8610 dwarf_regnames_lookup_func
= NULL
;
8616 init_dwarf_regnames_i386 ();
8620 init_dwarf_regnames_iamcu ();
8626 init_dwarf_regnames_x86_64 ();
8630 init_dwarf_regnames_aarch64 ();
8634 init_dwarf_regnames_s390 ();
8638 init_dwarf_regnames_riscv ();
8646 /* Initialize the DWARF register name lookup state based on the
8647 architecture and specific machine type of a BFD. */
8650 init_dwarf_regnames_by_bfd_arch_and_mach (enum bfd_architecture arch
,
8653 dwarf_regnames_lookup_func
= NULL
;
8661 case bfd_mach_x86_64
:
8662 case bfd_mach_x86_64_intel_syntax
:
8663 case bfd_mach_x64_32
:
8664 case bfd_mach_x64_32_intel_syntax
:
8665 init_dwarf_regnames_x86_64 ();
8669 init_dwarf_regnames_i386 ();
8674 case bfd_arch_iamcu
:
8675 init_dwarf_regnames_iamcu ();
8678 case bfd_arch_aarch64
:
8679 init_dwarf_regnames_aarch64();
8683 init_dwarf_regnames_s390 ();
8686 case bfd_arch_riscv
:
8687 init_dwarf_regnames_riscv ();
8696 regname_internal_by_table_only (unsigned int regno
)
8698 if (dwarf_regnames
!= NULL
8699 && regno
< dwarf_regnames_count
8700 && dwarf_regnames
[regno
] != NULL
)
8701 return dwarf_regnames
[regno
];
8707 regname (unsigned int regno
, int name_only_p
)
8709 static char reg
[64];
8711 const char *name
= NULL
;
8713 if (dwarf_regnames_lookup_func
!= NULL
)
8714 name
= dwarf_regnames_lookup_func (regno
);
8720 snprintf (reg
, sizeof (reg
), "r%d (%s)", regno
, name
);
8723 snprintf (reg
, sizeof (reg
), "r%d", regno
);
8728 frame_display_row (Frame_Chunk
*fc
, int *need_col_headers
, unsigned int *max_regs
)
8733 if (*max_regs
!= fc
->ncols
)
8734 *max_regs
= fc
->ncols
;
8736 if (*need_col_headers
)
8738 *need_col_headers
= 0;
8740 printf ("%-*s CFA ", eh_addr_size
* 2, " LOC");
8742 for (r
= 0; r
< *max_regs
; r
++)
8743 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
8748 printf ("%-5s ", regname (r
, 1));
8754 print_hex (fc
->pc_begin
, eh_addr_size
);
8756 strcpy (tmp
, "exp");
8758 sprintf (tmp
, "%s%+d", regname (fc
->cfa_reg
, 1), (int) fc
->cfa_offset
);
8759 printf ("%-8s ", tmp
);
8761 for (r
= 0; r
< fc
->ncols
; r
++)
8763 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
8765 switch (fc
->col_type
[r
])
8767 case DW_CFA_undefined
:
8770 case DW_CFA_same_value
:
8774 sprintf (tmp
, "c%+d", fc
->col_offset
[r
]);
8776 case DW_CFA_val_offset
:
8777 sprintf (tmp
, "v%+d", fc
->col_offset
[r
]);
8779 case DW_CFA_register
:
8780 sprintf (tmp
, "%s", regname (fc
->col_offset
[r
], 0));
8782 case DW_CFA_expression
:
8783 strcpy (tmp
, "exp");
8785 case DW_CFA_val_expression
:
8786 strcpy (tmp
, "vexp");
8789 strcpy (tmp
, "n/a");
8792 printf ("%-5s ", tmp
);
8798 #define GET(VAR, N) SAFE_BYTE_GET_AND_INC (VAR, start, N, end)
8800 static unsigned char *
8801 read_cie (unsigned char *start
, unsigned char *end
,
8802 Frame_Chunk
**p_cie
, int *p_version
,
8803 uint64_t *p_aug_len
, unsigned char **p_aug
)
8807 unsigned char *augmentation_data
= NULL
;
8808 uint64_t augmentation_data_len
= 0;
8811 /* PR 17512: file: 001-228113-0.004. */
8815 fc
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
8816 memset (fc
, 0, sizeof (Frame_Chunk
));
8818 fc
->col_type
= (short int *) xmalloc (sizeof (short int));
8819 fc
->col_offset
= (int *) xmalloc (sizeof (int));
8823 fc
->augmentation
= (char *) start
;
8824 /* PR 17512: file: 001-228113-0.004.
8825 Skip past augmentation name, but avoid running off the end of the data. */
8827 if (* start
++ == '\0')
8831 warn (_("No terminator for augmentation name\n"));
8835 if (strcmp (fc
->augmentation
, "eh") == 0)
8837 if (eh_addr_size
> (size_t) (end
- start
))
8839 start
+= eh_addr_size
;
8844 if (2 > (size_t) (end
- start
))
8846 GET (fc
->ptr_size
, 1);
8847 if (fc
->ptr_size
< 1 || fc
->ptr_size
> 8)
8849 warn (_("Invalid pointer size (%d) in CIE data\n"), fc
->ptr_size
);
8853 GET (fc
->segment_size
, 1);
8854 /* PR 17512: file: e99d2804. */
8855 if (fc
->segment_size
> 8 || fc
->segment_size
+ fc
->ptr_size
> 8)
8857 warn (_("Invalid segment size (%d) in CIE data\n"), fc
->segment_size
);
8861 eh_addr_size
= fc
->ptr_size
;
8865 fc
->ptr_size
= eh_addr_size
;
8866 fc
->segment_size
= 0;
8869 READ_ULEB (fc
->code_factor
, start
, end
);
8870 READ_SLEB (fc
->data_factor
, start
, end
);
8881 READ_ULEB (fc
->ra
, start
, end
);
8884 if (fc
->augmentation
[0] == 'z')
8888 READ_ULEB (augmentation_data_len
, start
, end
);
8889 augmentation_data
= start
;
8890 /* PR 17512: file: 11042-2589-0.004. */
8891 if (augmentation_data_len
> (size_t) (end
- start
))
8893 warn (_("Augmentation data too long: %#" PRIx64
8894 ", expected at most %#tx\n"),
8895 augmentation_data_len
, end
- start
);
8898 start
+= augmentation_data_len
;
8901 if (augmentation_data_len
)
8905 unsigned char *qend
;
8907 p
= (unsigned char *) fc
->augmentation
+ 1;
8908 q
= augmentation_data
;
8909 qend
= q
+ augmentation_data_len
;
8911 while (p
< end
&& q
< qend
)
8916 q
+= 1 + size_of_encoded_value (*q
);
8918 fc
->fde_encoding
= *q
++;
8927 /* Note - it is OK if this loop terminates with q < qend.
8928 Padding may have been inserted to align the end of the CIE. */
8933 *p_version
= version
;
8936 *p_aug_len
= augmentation_data_len
;
8937 *p_aug
= augmentation_data
;
8942 free (fc
->col_offset
);
8943 free (fc
->col_type
);
8948 /* Prints out the contents on the DATA array formatted as unsigned bytes.
8949 If do_wide is not enabled, then formats the output to fit into 80 columns.
8950 PRINTED contains the number of characters already written to the current
8954 display_data (size_t printed
, const unsigned char *data
, size_t len
)
8956 if (do_wide
|| len
< ((80 - printed
) / 3))
8957 for (printed
= 0; printed
< len
; ++printed
)
8958 printf (" %02x", data
[printed
]);
8961 for (printed
= 0; printed
< len
; ++printed
)
8963 if (printed
% (80 / 3) == 0)
8965 printf (" %02x", data
[printed
]);
8970 /* Prints out the contents on the augmentation data array.
8971 If do_wide is not enabled, then formats the output to fit into 80 columns. */
8974 display_augmentation_data (const unsigned char * data
, uint64_t len
)
8978 i
= printf (_(" Augmentation data: "));
8979 display_data (i
, data
, len
);
8983 display_debug_frames (struct dwarf_section
*section
,
8984 void *file ATTRIBUTE_UNUSED
)
8986 unsigned char *start
= section
->start
;
8987 unsigned char *end
= start
+ section
->size
;
8988 unsigned char *section_start
= start
;
8989 Frame_Chunk
*chunks
= NULL
, *forward_refs
= NULL
;
8990 Frame_Chunk
*remembered_state
= NULL
;
8992 bool is_eh
= strcmp (section
->name
, ".eh_frame") == 0;
8993 unsigned int max_regs
= 0;
8994 const char *bad_reg
= _("bad register: ");
8995 unsigned int saved_eh_addr_size
= eh_addr_size
;
8997 introduce (section
, false);
9001 unsigned char *saved_start
;
9002 unsigned char *block_end
;
9007 int need_col_headers
= 1;
9008 unsigned char *augmentation_data
= NULL
;
9009 uint64_t augmentation_data_len
= 0;
9010 unsigned int encoded_ptr_size
= saved_eh_addr_size
;
9011 unsigned int offset_size
;
9013 static Frame_Chunk fde_fc
;
9015 saved_start
= start
;
9017 SAFE_BYTE_GET_AND_INC (length
, start
, 4, end
);
9021 printf ("\n%08tx ZERO terminator\n\n",
9022 saved_start
- section_start
);
9023 /* Skip any zero terminators that directly follow.
9024 A corrupt section size could have loaded a whole
9025 slew of zero filled memory bytes. eg
9026 PR 17512: file: 070-19381-0.004. */
9027 while (start
< end
&& * start
== 0)
9032 if (length
== 0xffffffff)
9034 SAFE_BYTE_GET_AND_INC (length
, start
, 8, end
);
9040 if (length
> (size_t) (end
- start
))
9042 warn ("Invalid length %#" PRIx64
" in FDE at %#tx\n",
9043 length
, saved_start
- section_start
);
9047 block_end
= start
+ length
;
9049 SAFE_BYTE_GET_AND_INC (cie_id
, start
, offset_size
, block_end
);
9051 if (is_eh
? (cie_id
== 0) : ((offset_size
== 4 && cie_id
== DW_CIE_ID
)
9052 || (offset_size
== 8 && cie_id
== DW64_CIE_ID
)))
9057 start
= read_cie (start
, block_end
, &cie
, &version
,
9058 &augmentation_data_len
, &augmentation_data
);
9059 /* PR 17512: file: 027-135133-0.005. */
9066 fc
->chunk_start
= saved_start
;
9067 mreg
= max_regs
> 0 ? max_regs
- 1 : 0;
9070 if (frame_need_space (fc
, mreg
) < 0)
9072 if (fc
->fde_encoding
)
9073 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
9075 printf ("\n%08tx ", saved_start
- section_start
);
9076 print_hex (length
, fc
->ptr_size
);
9077 print_hex (cie_id
, offset_size
);
9079 if (do_debug_frames_interp
)
9081 printf ("CIE \"%s\" cf=%d df=%d ra=%d\n", fc
->augmentation
,
9082 fc
->code_factor
, fc
->data_factor
, fc
->ra
);
9087 printf (" Version: %d\n", version
);
9088 printf (" Augmentation: \"%s\"\n", fc
->augmentation
);
9091 printf (" Pointer Size: %u\n", fc
->ptr_size
);
9092 printf (" Segment Size: %u\n", fc
->segment_size
);
9094 printf (" Code alignment factor: %u\n", fc
->code_factor
);
9095 printf (" Data alignment factor: %d\n", fc
->data_factor
);
9096 printf (" Return address column: %d\n", fc
->ra
);
9098 if (augmentation_data_len
)
9099 display_augmentation_data (augmentation_data
, augmentation_data_len
);
9106 unsigned char *look_for
;
9107 unsigned long segment_selector
;
9113 uint64_t sign
= (uint64_t) 1 << (offset_size
* 8 - 1);
9114 cie_off
= (cie_off
^ sign
) - sign
;
9115 cie_off
= start
- 4 - section_start
- cie_off
;
9118 look_for
= section_start
+ cie_off
;
9119 if (cie_off
<= (size_t) (saved_start
- section_start
))
9121 for (cie
= chunks
; cie
; cie
= cie
->next
)
9122 if (cie
->chunk_start
== look_for
)
9125 else if (cie_off
>= section
->size
)
9129 for (cie
= forward_refs
; cie
; cie
= cie
->next
)
9130 if (cie
->chunk_start
== look_for
)
9134 unsigned int off_size
;
9135 unsigned char *cie_scan
;
9137 cie_scan
= look_for
;
9139 SAFE_BYTE_GET_AND_INC (length
, cie_scan
, 4, end
);
9140 if (length
== 0xffffffff)
9142 SAFE_BYTE_GET_AND_INC (length
, cie_scan
, 8, end
);
9145 if (length
!= 0 && length
<= (size_t) (end
- cie_scan
))
9148 unsigned char *cie_end
= cie_scan
+ length
;
9150 SAFE_BYTE_GET_AND_INC (c_id
, cie_scan
, off_size
,
9154 : ((off_size
== 4 && c_id
== DW_CIE_ID
)
9155 || (off_size
== 8 && c_id
== DW64_CIE_ID
)))
9160 read_cie (cie_scan
, cie_end
, &cie
, &version
,
9161 &augmentation_data_len
, &augmentation_data
);
9162 /* PR 17512: file: 3450-2098-0.004. */
9165 warn (_("Failed to read CIE information\n"));
9168 cie
->next
= forward_refs
;
9170 cie
->chunk_start
= look_for
;
9171 mreg
= max_regs
> 0 ? max_regs
- 1 : 0;
9174 if (frame_need_space (cie
, mreg
) < 0)
9176 warn (_("Invalid max register\n"));
9179 if (cie
->fde_encoding
)
9181 = size_of_encoded_value (cie
->fde_encoding
);
9188 memset (fc
, 0, sizeof (Frame_Chunk
));
9193 fc
->col_type
= (short int *) xmalloc (sizeof (short int));
9194 fc
->col_offset
= (int *) xmalloc (sizeof (int));
9195 if (frame_need_space (fc
, max_regs
> 0 ? max_regs
- 1 : 0) < 0)
9197 warn (_("Invalid max register\n"));
9201 fc
->augmentation
= "";
9202 fc
->fde_encoding
= 0;
9203 fc
->ptr_size
= eh_addr_size
;
9204 fc
->segment_size
= 0;
9208 fc
->ncols
= cie
->ncols
;
9209 fc
->col_type
= (short int *) xcmalloc (fc
->ncols
, sizeof (short int));
9210 fc
->col_offset
= (int *) xcmalloc (fc
->ncols
, sizeof (int));
9211 memcpy (fc
->col_type
, cie
->col_type
, fc
->ncols
* sizeof (short int));
9212 memcpy (fc
->col_offset
, cie
->col_offset
, fc
->ncols
* sizeof (int));
9213 fc
->augmentation
= cie
->augmentation
;
9214 fc
->ptr_size
= cie
->ptr_size
;
9215 eh_addr_size
= cie
->ptr_size
;
9216 fc
->segment_size
= cie
->segment_size
;
9217 fc
->code_factor
= cie
->code_factor
;
9218 fc
->data_factor
= cie
->data_factor
;
9219 fc
->cfa_reg
= cie
->cfa_reg
;
9220 fc
->cfa_offset
= cie
->cfa_offset
;
9222 if (frame_need_space (fc
, max_regs
> 0 ? max_regs
- 1: 0) < 0)
9224 warn (_("Invalid max register\n"));
9227 fc
->fde_encoding
= cie
->fde_encoding
;
9230 if (fc
->fde_encoding
)
9231 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
9233 segment_selector
= 0;
9234 if (fc
->segment_size
)
9236 if (fc
->segment_size
> sizeof (segment_selector
))
9238 /* PR 17512: file: 9e196b3e. */
9239 warn (_("Probably corrupt segment size: %d - using 4 instead\n"), fc
->segment_size
);
9240 fc
->segment_size
= 4;
9242 SAFE_BYTE_GET_AND_INC (segment_selector
, start
,
9243 fc
->segment_size
, block_end
);
9246 fc
->pc_begin
= get_encoded_value (&start
, fc
->fde_encoding
, section
,
9249 /* FIXME: It appears that sometimes the final pc_range value is
9250 encoded in less than encoded_ptr_size bytes. See the x86_64
9251 run of the "objcopy on compressed debug sections" test for an
9253 SAFE_BYTE_GET_AND_INC (fc
->pc_range
, start
, encoded_ptr_size
,
9256 if (cie
->augmentation
[0] == 'z')
9258 READ_ULEB (augmentation_data_len
, start
, block_end
);
9259 augmentation_data
= start
;
9260 /* PR 17512 file: 722-8446-0.004 and PR 22386. */
9261 if (augmentation_data_len
> (size_t) (block_end
- start
))
9263 warn (_("Augmentation data too long: %#" PRIx64
", "
9264 "expected at most %#tx\n"),
9265 augmentation_data_len
, block_end
- start
);
9267 augmentation_data
= NULL
;
9268 augmentation_data_len
= 0;
9270 start
+= augmentation_data_len
;
9273 printf ("\n%08tx ", saved_start
- section_start
);
9274 print_hex (length
, fc
->ptr_size
);
9275 print_hex (cie_id
, offset_size
);
9278 if (cie
->chunk_start
)
9279 printf ("cie=%08tx", cie
->chunk_start
- section_start
);
9281 /* Ideally translate "invalid " to 8 chars, trailing space
9283 printf (_("cie=invalid "));
9286 if (fc
->segment_size
)
9287 printf ("%04lx:", segment_selector
);
9289 print_hex_ns (fc
->pc_begin
, fc
->ptr_size
);
9291 print_hex_ns (fc
->pc_begin
+ fc
->pc_range
, fc
->ptr_size
);
9294 if (! do_debug_frames_interp
&& augmentation_data_len
)
9296 display_augmentation_data (augmentation_data
, augmentation_data_len
);
9301 /* At this point, fc is the current chunk, cie (if any) is set, and
9302 we're about to interpret instructions for the chunk. */
9303 /* ??? At present we need to do this always, since this sizes the
9304 fc->col_type and fc->col_offset arrays, which we write into always.
9305 We should probably split the interpreted and non-interpreted bits
9306 into two different routines, since there's so much that doesn't
9307 really overlap between them. */
9308 if (1 || do_debug_frames_interp
)
9310 /* Start by making a pass over the chunk, allocating storage
9311 and taking note of what registers are used. */
9312 unsigned char *tmp
= start
;
9314 while (start
< block_end
)
9316 unsigned int reg
, op
, opa
;
9324 /* Warning: if you add any more cases to this switch, be
9325 sure to add them to the corresponding switch below. */
9329 case DW_CFA_advance_loc
:
9332 SKIP_ULEB (start
, block_end
);
9335 case DW_CFA_restore
:
9338 case DW_CFA_set_loc
:
9339 if ((size_t) (block_end
- start
) < encoded_ptr_size
)
9342 start
+= encoded_ptr_size
;
9344 case DW_CFA_advance_loc1
:
9345 if ((size_t) (block_end
- start
) < 1)
9350 case DW_CFA_advance_loc2
:
9351 if ((size_t) (block_end
- start
) < 2)
9356 case DW_CFA_advance_loc4
:
9357 if ((size_t) (block_end
- start
) < 4)
9362 case DW_CFA_offset_extended
:
9363 case DW_CFA_val_offset
:
9364 READ_ULEB (reg
, start
, block_end
);
9365 SKIP_ULEB (start
, block_end
);
9367 case DW_CFA_restore_extended
:
9368 READ_ULEB (reg
, start
, block_end
);
9370 case DW_CFA_undefined
:
9371 READ_ULEB (reg
, start
, block_end
);
9373 case DW_CFA_same_value
:
9374 READ_ULEB (reg
, start
, block_end
);
9376 case DW_CFA_register
:
9377 READ_ULEB (reg
, start
, block_end
);
9378 SKIP_ULEB (start
, block_end
);
9380 case DW_CFA_def_cfa
:
9381 SKIP_ULEB (start
, block_end
);
9382 SKIP_ULEB (start
, block_end
);
9384 case DW_CFA_def_cfa_register
:
9385 SKIP_ULEB (start
, block_end
);
9387 case DW_CFA_def_cfa_offset
:
9388 SKIP_ULEB (start
, block_end
);
9390 case DW_CFA_def_cfa_expression
:
9391 READ_ULEB (temp
, start
, block_end
);
9392 if ((size_t) (block_end
- start
) < temp
)
9397 case DW_CFA_expression
:
9398 case DW_CFA_val_expression
:
9399 READ_ULEB (reg
, start
, block_end
);
9400 READ_ULEB (temp
, start
, block_end
);
9401 if ((size_t) (block_end
- start
) < temp
)
9406 case DW_CFA_offset_extended_sf
:
9407 case DW_CFA_val_offset_sf
:
9408 READ_ULEB (reg
, start
, block_end
);
9409 SKIP_SLEB (start
, block_end
);
9411 case DW_CFA_def_cfa_sf
:
9412 SKIP_ULEB (start
, block_end
);
9413 SKIP_SLEB (start
, block_end
);
9415 case DW_CFA_def_cfa_offset_sf
:
9416 SKIP_SLEB (start
, block_end
);
9418 case DW_CFA_MIPS_advance_loc8
:
9419 if ((size_t) (block_end
- start
) < 8)
9424 case DW_CFA_GNU_args_size
:
9425 SKIP_ULEB (start
, block_end
);
9427 case DW_CFA_GNU_negative_offset_extended
:
9428 READ_ULEB (reg
, start
, block_end
);
9429 SKIP_ULEB (start
, block_end
);
9434 if (reg
!= -1u && frame_need_space (fc
, reg
) >= 0)
9436 /* Don't leave any reg as DW_CFA_unreferenced so
9437 that frame_display_row prints name of regs in
9438 header, and all referenced regs in each line. */
9439 if (reg
>= cie
->ncols
9440 || cie
->col_type
[reg
] == DW_CFA_unreferenced
)
9441 fc
->col_type
[reg
] = DW_CFA_undefined
;
9443 fc
->col_type
[reg
] = cie
->col_type
[reg
];
9451 /* Now we know what registers are used, make a second pass over
9452 the chunk, this time actually printing out the info. */
9454 while (start
< block_end
)
9457 unsigned long ul
, roffs
;
9458 /* Note: It is tempting to use an unsigned long for 'reg' but there
9459 are various functions, notably frame_space_needed() that assume that
9460 reg is an unsigned int. */
9465 const char *reg_prefix
= "";
9472 /* Make a note if something other than DW_CFA_nop happens. */
9473 if (op
!= DW_CFA_nop
)
9476 /* Warning: if you add any more cases to this switch, be
9477 sure to add them to the corresponding switch above. */
9480 case DW_CFA_advance_loc
:
9481 if (do_debug_frames_interp
)
9482 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9485 printf (" DW_CFA_advance_loc: %d to ",
9486 opa
* fc
->code_factor
);
9487 print_hex_ns (fc
->pc_begin
+ opa
* fc
->code_factor
,
9491 fc
->pc_begin
+= opa
* fc
->code_factor
;
9495 READ_ULEB (roffs
, start
, block_end
);
9496 if (opa
>= fc
->ncols
)
9497 reg_prefix
= bad_reg
;
9498 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9499 printf (" DW_CFA_offset: %s%s at cfa%+ld\n",
9500 reg_prefix
, regname (opa
, 0),
9501 roffs
* fc
->data_factor
);
9502 if (*reg_prefix
== '\0')
9504 fc
->col_type
[opa
] = DW_CFA_offset
;
9505 fc
->col_offset
[opa
] = roffs
* fc
->data_factor
;
9509 case DW_CFA_restore
:
9510 if (opa
>= fc
->ncols
)
9511 reg_prefix
= bad_reg
;
9512 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9513 printf (" DW_CFA_restore: %s%s\n",
9514 reg_prefix
, regname (opa
, 0));
9515 if (*reg_prefix
!= '\0')
9518 if (opa
>= cie
->ncols
9519 || cie
->col_type
[opa
] == DW_CFA_unreferenced
)
9521 fc
->col_type
[opa
] = DW_CFA_undefined
;
9522 fc
->col_offset
[opa
] = 0;
9526 fc
->col_type
[opa
] = cie
->col_type
[opa
];
9527 fc
->col_offset
[opa
] = cie
->col_offset
[opa
];
9531 case DW_CFA_set_loc
:
9532 vma
= get_encoded_value (&start
, fc
->fde_encoding
, section
,
9534 if (do_debug_frames_interp
)
9535 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9538 printf (" DW_CFA_set_loc: ");
9539 print_hex_ns (vma
, fc
->ptr_size
);
9545 case DW_CFA_advance_loc1
:
9546 SAFE_BYTE_GET_AND_INC (ofs
, start
, 1, block_end
);
9547 if (do_debug_frames_interp
)
9548 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9551 printf (" DW_CFA_advance_loc1: %" PRId64
" to ",
9552 ofs
* fc
->code_factor
);
9553 print_hex_ns (fc
->pc_begin
+ ofs
* fc
->code_factor
,
9557 fc
->pc_begin
+= ofs
* fc
->code_factor
;
9560 case DW_CFA_advance_loc2
:
9561 SAFE_BYTE_GET_AND_INC (ofs
, start
, 2, block_end
);
9562 if (do_debug_frames_interp
)
9563 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9566 printf (" DW_CFA_advance_loc2: %" PRId64
" to ",
9567 ofs
* fc
->code_factor
);
9568 print_hex_ns (fc
->pc_begin
+ ofs
* fc
->code_factor
,
9572 fc
->pc_begin
+= ofs
* fc
->code_factor
;
9575 case DW_CFA_advance_loc4
:
9576 SAFE_BYTE_GET_AND_INC (ofs
, start
, 4, block_end
);
9577 if (do_debug_frames_interp
)
9578 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9581 printf (" DW_CFA_advance_loc4: %" PRId64
" to ",
9582 ofs
* fc
->code_factor
);
9583 print_hex_ns (fc
->pc_begin
+ ofs
* fc
->code_factor
,
9587 fc
->pc_begin
+= ofs
* fc
->code_factor
;
9590 case DW_CFA_offset_extended
:
9591 READ_ULEB (reg
, start
, block_end
);
9592 READ_ULEB (roffs
, start
, block_end
);
9593 if (reg
>= fc
->ncols
)
9594 reg_prefix
= bad_reg
;
9595 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9596 printf (" DW_CFA_offset_extended: %s%s at cfa%+ld\n",
9597 reg_prefix
, regname (reg
, 0),
9598 roffs
* fc
->data_factor
);
9599 if (*reg_prefix
== '\0')
9601 fc
->col_type
[reg
] = DW_CFA_offset
;
9602 fc
->col_offset
[reg
] = roffs
* fc
->data_factor
;
9606 case DW_CFA_val_offset
:
9607 READ_ULEB (reg
, start
, block_end
);
9608 READ_ULEB (roffs
, start
, block_end
);
9609 if (reg
>= fc
->ncols
)
9610 reg_prefix
= bad_reg
;
9611 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9612 printf (" DW_CFA_val_offset: %s%s is cfa%+ld\n",
9613 reg_prefix
, regname (reg
, 0),
9614 roffs
* fc
->data_factor
);
9615 if (*reg_prefix
== '\0')
9617 fc
->col_type
[reg
] = DW_CFA_val_offset
;
9618 fc
->col_offset
[reg
] = roffs
* fc
->data_factor
;
9622 case DW_CFA_restore_extended
:
9623 READ_ULEB (reg
, start
, block_end
);
9624 if (reg
>= fc
->ncols
)
9625 reg_prefix
= bad_reg
;
9626 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9627 printf (" DW_CFA_restore_extended: %s%s\n",
9628 reg_prefix
, regname (reg
, 0));
9629 if (*reg_prefix
!= '\0')
9632 if (reg
>= cie
->ncols
9633 || cie
->col_type
[reg
] == DW_CFA_unreferenced
)
9635 fc
->col_type
[reg
] = DW_CFA_undefined
;
9636 fc
->col_offset
[reg
] = 0;
9640 fc
->col_type
[reg
] = cie
->col_type
[reg
];
9641 fc
->col_offset
[reg
] = cie
->col_offset
[reg
];
9645 case DW_CFA_undefined
:
9646 READ_ULEB (reg
, start
, block_end
);
9647 if (reg
>= fc
->ncols
)
9648 reg_prefix
= bad_reg
;
9649 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9650 printf (" DW_CFA_undefined: %s%s\n",
9651 reg_prefix
, regname (reg
, 0));
9652 if (*reg_prefix
== '\0')
9654 fc
->col_type
[reg
] = DW_CFA_undefined
;
9655 fc
->col_offset
[reg
] = 0;
9659 case DW_CFA_same_value
:
9660 READ_ULEB (reg
, start
, block_end
);
9661 if (reg
>= fc
->ncols
)
9662 reg_prefix
= bad_reg
;
9663 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9664 printf (" DW_CFA_same_value: %s%s\n",
9665 reg_prefix
, regname (reg
, 0));
9666 if (*reg_prefix
== '\0')
9668 fc
->col_type
[reg
] = DW_CFA_same_value
;
9669 fc
->col_offset
[reg
] = 0;
9673 case DW_CFA_register
:
9674 READ_ULEB (reg
, start
, block_end
);
9675 READ_ULEB (roffs
, start
, block_end
);
9676 if (reg
>= fc
->ncols
)
9677 reg_prefix
= bad_reg
;
9678 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9680 printf (" DW_CFA_register: %s%s in ",
9681 reg_prefix
, regname (reg
, 0));
9682 puts (regname (roffs
, 0));
9684 if (*reg_prefix
== '\0')
9686 fc
->col_type
[reg
] = DW_CFA_register
;
9687 fc
->col_offset
[reg
] = roffs
;
9691 case DW_CFA_remember_state
:
9692 if (! do_debug_frames_interp
)
9693 printf (" DW_CFA_remember_state\n");
9694 rs
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
9695 rs
->cfa_offset
= fc
->cfa_offset
;
9696 rs
->cfa_reg
= fc
->cfa_reg
;
9698 rs
->cfa_exp
= fc
->cfa_exp
;
9699 rs
->ncols
= fc
->ncols
;
9700 rs
->col_type
= (short int *) xcmalloc (rs
->ncols
,
9701 sizeof (* rs
->col_type
));
9702 rs
->col_offset
= (int *) xcmalloc (rs
->ncols
, sizeof (* rs
->col_offset
));
9703 memcpy (rs
->col_type
, fc
->col_type
, rs
->ncols
* sizeof (* fc
->col_type
));
9704 memcpy (rs
->col_offset
, fc
->col_offset
, rs
->ncols
* sizeof (* fc
->col_offset
));
9705 rs
->next
= remembered_state
;
9706 remembered_state
= rs
;
9709 case DW_CFA_restore_state
:
9710 if (! do_debug_frames_interp
)
9711 printf (" DW_CFA_restore_state\n");
9712 rs
= remembered_state
;
9715 remembered_state
= rs
->next
;
9716 fc
->cfa_offset
= rs
->cfa_offset
;
9717 fc
->cfa_reg
= rs
->cfa_reg
;
9719 fc
->cfa_exp
= rs
->cfa_exp
;
9720 if (frame_need_space (fc
, rs
->ncols
- 1) < 0)
9722 warn (_("Invalid column number in saved frame state\n"));
9726 memcpy (fc
->col_type
, rs
->col_type
, rs
->ncols
* sizeof (* rs
->col_type
));
9727 memcpy (fc
->col_offset
, rs
->col_offset
,
9728 rs
->ncols
* sizeof (* rs
->col_offset
));
9729 free (rs
->col_type
);
9730 free (rs
->col_offset
);
9733 else if (do_debug_frames_interp
)
9734 printf ("Mismatched DW_CFA_restore_state\n");
9737 case DW_CFA_def_cfa
:
9738 READ_ULEB (fc
->cfa_reg
, start
, block_end
);
9739 READ_ULEB (fc
->cfa_offset
, start
, block_end
);
9741 if (! do_debug_frames_interp
)
9742 printf (" DW_CFA_def_cfa: %s ofs %d\n",
9743 regname (fc
->cfa_reg
, 0), (int) fc
->cfa_offset
);
9746 case DW_CFA_def_cfa_register
:
9747 READ_ULEB (fc
->cfa_reg
, start
, block_end
);
9749 if (! do_debug_frames_interp
)
9750 printf (" DW_CFA_def_cfa_register: %s\n",
9751 regname (fc
->cfa_reg
, 0));
9754 case DW_CFA_def_cfa_offset
:
9755 READ_ULEB (fc
->cfa_offset
, start
, block_end
);
9756 if (! do_debug_frames_interp
)
9757 printf (" DW_CFA_def_cfa_offset: %d\n", (int) fc
->cfa_offset
);
9761 if (! do_debug_frames_interp
)
9762 printf (" DW_CFA_nop\n");
9765 case DW_CFA_def_cfa_expression
:
9766 READ_ULEB (ul
, start
, block_end
);
9767 if (ul
> (size_t) (block_end
- start
))
9769 printf (_(" DW_CFA_def_cfa_expression: <corrupt len %lu>\n"), ul
);
9772 if (! do_debug_frames_interp
)
9774 printf (" DW_CFA_def_cfa_expression (");
9775 decode_location_expression (start
, eh_addr_size
, 0, -1,
9783 case DW_CFA_expression
:
9784 READ_ULEB (reg
, start
, block_end
);
9785 READ_ULEB (ul
, start
, block_end
);
9786 if (reg
>= fc
->ncols
)
9787 reg_prefix
= bad_reg
;
9788 /* PR 17512: file: 069-133014-0.006. */
9789 /* PR 17512: file: 98c02eb4. */
9790 if (ul
> (size_t) (block_end
- start
))
9792 printf (_(" DW_CFA_expression: <corrupt len %lu>\n"), ul
);
9795 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9797 printf (" DW_CFA_expression: %s%s (",
9798 reg_prefix
, regname (reg
, 0));
9799 decode_location_expression (start
, eh_addr_size
, 0, -1,
9803 if (*reg_prefix
== '\0')
9804 fc
->col_type
[reg
] = DW_CFA_expression
;
9808 case DW_CFA_val_expression
:
9809 READ_ULEB (reg
, start
, block_end
);
9810 READ_ULEB (ul
, start
, block_end
);
9811 if (reg
>= fc
->ncols
)
9812 reg_prefix
= bad_reg
;
9813 if (ul
> (size_t) (block_end
- start
))
9815 printf (" DW_CFA_val_expression: <corrupt len %lu>\n", ul
);
9818 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9820 printf (" DW_CFA_val_expression: %s%s (",
9821 reg_prefix
, regname (reg
, 0));
9822 decode_location_expression (start
, eh_addr_size
, 0, -1,
9826 if (*reg_prefix
== '\0')
9827 fc
->col_type
[reg
] = DW_CFA_val_expression
;
9831 case DW_CFA_offset_extended_sf
:
9832 READ_ULEB (reg
, start
, block_end
);
9833 READ_SLEB (l
, start
, block_end
);
9834 if (reg
>= fc
->ncols
)
9835 reg_prefix
= bad_reg
;
9836 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9837 printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+" PRId64
"\n",
9838 reg_prefix
, regname (reg
, 0),
9839 l
* fc
->data_factor
);
9840 if (*reg_prefix
== '\0')
9842 fc
->col_type
[reg
] = DW_CFA_offset
;
9843 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
9847 case DW_CFA_val_offset_sf
:
9848 READ_ULEB (reg
, start
, block_end
);
9849 READ_SLEB (l
, start
, block_end
);
9850 if (reg
>= fc
->ncols
)
9851 reg_prefix
= bad_reg
;
9852 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9853 printf (" DW_CFA_val_offset_sf: %s%s is cfa%+" PRId64
"\n",
9854 reg_prefix
, regname (reg
, 0),
9855 l
* fc
->data_factor
);
9856 if (*reg_prefix
== '\0')
9858 fc
->col_type
[reg
] = DW_CFA_val_offset
;
9859 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
9863 case DW_CFA_def_cfa_sf
:
9864 READ_ULEB (fc
->cfa_reg
, start
, block_end
);
9865 READ_SLEB (l
, start
, block_end
);
9866 l
*= fc
->data_factor
;
9869 if (! do_debug_frames_interp
)
9870 printf (" DW_CFA_def_cfa_sf: %s ofs %" PRId64
"\n",
9871 regname (fc
->cfa_reg
, 0), l
);
9874 case DW_CFA_def_cfa_offset_sf
:
9875 READ_SLEB (l
, start
, block_end
);
9876 l
*= fc
->data_factor
;
9878 if (! do_debug_frames_interp
)
9879 printf (" DW_CFA_def_cfa_offset_sf: %" PRId64
"\n", l
);
9882 case DW_CFA_MIPS_advance_loc8
:
9883 SAFE_BYTE_GET_AND_INC (ofs
, start
, 8, block_end
);
9884 if (do_debug_frames_interp
)
9885 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9888 printf (" DW_CFA_MIPS_advance_loc8: %" PRId64
" to ",
9889 ofs
* fc
->code_factor
);
9890 print_hex_ns (fc
->pc_begin
+ ofs
* fc
->code_factor
,
9894 fc
->pc_begin
+= ofs
* fc
->code_factor
;
9897 case DW_CFA_GNU_window_save
:
9898 if (! do_debug_frames_interp
)
9899 printf (" %s\n", DW_CFA_GNU_window_save_name
[is_aarch64
]);
9902 case DW_CFA_GNU_args_size
:
9903 READ_ULEB (ul
, start
, block_end
);
9904 if (! do_debug_frames_interp
)
9905 printf (" DW_CFA_GNU_args_size: %ld\n", ul
);
9908 case DW_CFA_GNU_negative_offset_extended
:
9909 READ_ULEB (reg
, start
, block_end
);
9910 READ_SLEB (l
, start
, block_end
);
9912 if (reg
>= fc
->ncols
)
9913 reg_prefix
= bad_reg
;
9914 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9915 printf (" DW_CFA_GNU_negative_offset_extended: %s%s "
9916 "at cfa%+" PRId64
"\n",
9917 reg_prefix
, regname (reg
, 0),
9918 l
* fc
->data_factor
);
9919 if (*reg_prefix
== '\0')
9921 fc
->col_type
[reg
] = DW_CFA_offset
;
9922 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
9927 if (op
>= DW_CFA_lo_user
&& op
<= DW_CFA_hi_user
)
9928 printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op
);
9930 warn (_("Unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op
);
9935 /* Interpret the CFA - as long as it is not completely full of NOPs. */
9936 if (do_debug_frames_interp
&& ! all_nops
)
9937 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9939 if (fde_fc
.col_type
!= NULL
)
9941 free (fde_fc
.col_type
);
9942 fde_fc
.col_type
= NULL
;
9944 if (fde_fc
.col_offset
!= NULL
)
9946 free (fde_fc
.col_offset
);
9947 fde_fc
.col_offset
= NULL
;
9951 eh_addr_size
= saved_eh_addr_size
;
9956 while (remembered_state
!= NULL
)
9958 rs
= remembered_state
;
9959 remembered_state
= rs
->next
;
9960 free (rs
->col_type
);
9961 free (rs
->col_offset
);
9962 rs
->next
= NULL
; /* Paranoia. */
9966 while (chunks
!= NULL
)
9970 free (rs
->col_type
);
9971 free (rs
->col_offset
);
9972 rs
->next
= NULL
; /* Paranoia. */
9976 while (forward_refs
!= NULL
)
9979 forward_refs
= rs
->next
;
9980 free (rs
->col_type
);
9981 free (rs
->col_offset
);
9982 rs
->next
= NULL
; /* Paranoia. */
9992 display_debug_names (struct dwarf_section
*section
, void *file
)
9994 unsigned char *hdrptr
= section
->start
;
9995 uint64_t unit_length
;
9996 unsigned char *unit_start
;
9997 const unsigned char *const section_end
= section
->start
+ section
->size
;
9998 unsigned char *unit_end
;
10000 introduce (section
, false);
10002 load_debug_section_with_follow (str
, file
);
10004 for (; hdrptr
< section_end
; hdrptr
= unit_end
)
10006 unsigned int offset_size
;
10007 uint16_t dwarf_version
, padding
;
10008 uint32_t comp_unit_count
, local_type_unit_count
, foreign_type_unit_count
;
10009 uint64_t bucket_count
, name_count
, abbrev_table_size
;
10010 uint32_t augmentation_string_size
;
10012 bool augmentation_printable
;
10013 const char *augmentation_string
;
10016 unit_start
= hdrptr
;
10018 /* Get and check the length of the block. */
10019 SAFE_BYTE_GET_AND_INC (unit_length
, hdrptr
, 4, section_end
);
10021 if (unit_length
== 0xffffffff)
10023 /* This section is 64-bit DWARF. */
10024 SAFE_BYTE_GET_AND_INC (unit_length
, hdrptr
, 8, section_end
);
10030 if (unit_length
> (size_t) (section_end
- hdrptr
)
10031 || unit_length
< 2 + 2 + 4 * 7)
10034 warn (_("Debug info is corrupted, %s header at %#tx"
10035 " has length %#" PRIx64
"\n"),
10036 section
->name
, unit_start
- section
->start
, unit_length
);
10039 unit_end
= hdrptr
+ unit_length
;
10041 /* Get and check the version number. */
10042 SAFE_BYTE_GET_AND_INC (dwarf_version
, hdrptr
, 2, unit_end
);
10043 printf (_("Version %d\n"), (int) dwarf_version
);
10045 /* Prior versions did not exist, and future versions may not be
10046 backwards compatible. */
10047 if (dwarf_version
!= 5)
10049 warn (_("Only DWARF version 5 .debug_names "
10050 "is currently supported.\n"));
10054 SAFE_BYTE_GET_AND_INC (padding
, hdrptr
, 2, unit_end
);
10056 warn (_("Padding field of .debug_names must be 0 (found 0x%x)\n"),
10059 SAFE_BYTE_GET_AND_INC (comp_unit_count
, hdrptr
, 4, unit_end
);
10060 if (comp_unit_count
== 0)
10061 warn (_("Compilation unit count must be >= 1 in .debug_names\n"));
10063 SAFE_BYTE_GET_AND_INC (local_type_unit_count
, hdrptr
, 4, unit_end
);
10064 SAFE_BYTE_GET_AND_INC (foreign_type_unit_count
, hdrptr
, 4, unit_end
);
10065 SAFE_BYTE_GET_AND_INC (bucket_count
, hdrptr
, 4, unit_end
);
10066 SAFE_BYTE_GET_AND_INC (name_count
, hdrptr
, 4, unit_end
);
10067 SAFE_BYTE_GET_AND_INC (abbrev_table_size
, hdrptr
, 4, unit_end
);
10069 SAFE_BYTE_GET_AND_INC (augmentation_string_size
, hdrptr
, 4, unit_end
);
10070 if (augmentation_string_size
% 4 != 0)
10072 warn (_("Augmentation string length %u must be rounded up "
10073 "to a multiple of 4 in .debug_names.\n"),
10074 augmentation_string_size
);
10075 augmentation_string_size
+= (-augmentation_string_size
) & 3;
10077 if (augmentation_string_size
> (size_t) (unit_end
- hdrptr
))
10080 printf (_("Augmentation string:"));
10082 augmentation_printable
= true;
10083 augmentation_string
= (const char *) hdrptr
;
10085 for (i
= 0; i
< augmentation_string_size
; i
++)
10089 SAFE_BYTE_GET_AND_INC (uc
, hdrptr
, 1, unit_end
);
10090 printf (" %02x", uc
);
10092 if (uc
!= 0 && !ISPRINT (uc
))
10093 augmentation_printable
= false;
10096 if (augmentation_printable
)
10100 i
< augmentation_string_size
&& augmentation_string
[i
];
10102 putchar (augmentation_string
[i
]);
10107 printf (_("CU table:\n"));
10108 if (_mul_overflow (comp_unit_count
, offset_size
, &total
)
10109 || total
> (size_t) (unit_end
- hdrptr
))
10111 for (i
= 0; i
< comp_unit_count
; i
++)
10113 uint64_t cu_offset
;
10115 SAFE_BYTE_GET_AND_INC (cu_offset
, hdrptr
, offset_size
, unit_end
);
10116 printf ("[%3u] %#" PRIx64
"\n", i
, cu_offset
);
10120 printf (_("TU table:\n"));
10121 if (_mul_overflow (local_type_unit_count
, offset_size
, &total
)
10122 || total
> (size_t) (unit_end
- hdrptr
))
10124 for (i
= 0; i
< local_type_unit_count
; i
++)
10126 uint64_t tu_offset
;
10128 SAFE_BYTE_GET_AND_INC (tu_offset
, hdrptr
, offset_size
, unit_end
);
10129 printf ("[%3u] %#" PRIx64
"\n", i
, tu_offset
);
10133 printf (_("Foreign TU table:\n"));
10134 if (_mul_overflow (foreign_type_unit_count
, 8, &total
)
10135 || total
> (size_t) (unit_end
- hdrptr
))
10137 for (i
= 0; i
< foreign_type_unit_count
; i
++)
10139 uint64_t signature
;
10141 SAFE_BYTE_GET_AND_INC (signature
, hdrptr
, 8, unit_end
);
10142 printf (_("[%3u] "), i
);
10143 print_hex_ns (signature
, 8);
10148 uint64_t xtra
= (bucket_count
* sizeof (uint32_t)
10149 + name_count
* (sizeof (uint32_t) + 2 * offset_size
)
10150 + abbrev_table_size
);
10151 if (xtra
> (size_t) (unit_end
- hdrptr
))
10153 warn (_("Entry pool offset (%#" PRIx64
") exceeds unit size %#tx "
10154 "for unit %#tx in the debug_names\n"),
10155 xtra
, unit_end
- unit_start
, unit_start
- section
->start
);
10158 const uint32_t *const hash_table_buckets
= (uint32_t *) hdrptr
;
10159 hdrptr
+= bucket_count
* sizeof (uint32_t);
10160 const uint32_t *const hash_table_hashes
= (uint32_t *) hdrptr
;
10161 hdrptr
+= name_count
* sizeof (uint32_t);
10162 unsigned char *const name_table_string_offsets
= hdrptr
;
10163 hdrptr
+= name_count
* offset_size
;
10164 unsigned char *const name_table_entry_offsets
= hdrptr
;
10165 hdrptr
+= name_count
* offset_size
;
10166 unsigned char *const abbrev_table
= hdrptr
;
10167 hdrptr
+= abbrev_table_size
;
10168 const unsigned char *const abbrev_table_end
= hdrptr
;
10169 unsigned char *const entry_pool
= hdrptr
;
10171 size_t buckets_filled
= 0;
10173 for (bucketi
= 0; bucketi
< bucket_count
; bucketi
++)
10175 const uint32_t bucket
= hash_table_buckets
[bucketi
];
10180 printf (ngettext ("Used %zu of %lu bucket.\n",
10181 "Used %zu of %lu buckets.\n",
10182 (unsigned long) bucket_count
),
10183 buckets_filled
, (unsigned long) bucket_count
);
10185 if (bucket_count
!= 0)
10187 uint32_t hash_prev
= 0;
10188 size_t hash_clash_count
= 0;
10189 size_t longest_clash
= 0;
10190 size_t this_length
= 0;
10192 for (hashi
= 0; hashi
< name_count
; hashi
++)
10194 const uint32_t hash_this
= hash_table_hashes
[hashi
];
10198 if (hash_prev
% bucket_count
== hash_this
% bucket_count
)
10200 ++hash_clash_count
;
10202 longest_clash
= MAX (longest_clash
, this_length
);
10207 hash_prev
= hash_this
;
10209 printf (_("Out of %" PRIu64
" items there are %zu bucket clashes"
10210 " (longest of %zu entries).\n"),
10211 name_count
, hash_clash_count
, longest_clash
);
10213 if (name_count
!= buckets_filled
+ hash_clash_count
)
10214 warn (_("The name_count (%" PRIu64
")"
10215 " is not the same as the used bucket_count"
10216 " (%zu) + the hash clash count (%zu)"),
10217 name_count
, buckets_filled
, hash_clash_count
);
10220 struct abbrev_lookup_entry
10222 uint64_t abbrev_tag
;
10223 unsigned char *abbrev_lookup_ptr
;
10225 struct abbrev_lookup_entry
*abbrev_lookup
= NULL
;
10226 size_t abbrev_lookup_used
= 0;
10227 size_t abbrev_lookup_allocated
= 0;
10229 unsigned char *abbrevptr
= abbrev_table
;
10232 uint64_t abbrev_tag
;
10234 READ_ULEB (abbrev_tag
, abbrevptr
, abbrev_table_end
);
10235 if (abbrev_tag
== 0)
10237 if (abbrev_lookup_used
== abbrev_lookup_allocated
)
10239 abbrev_lookup_allocated
= MAX (0x100,
10240 abbrev_lookup_allocated
* 2);
10241 abbrev_lookup
= xrealloc (abbrev_lookup
,
10242 (abbrev_lookup_allocated
10243 * sizeof (*abbrev_lookup
)));
10245 assert (abbrev_lookup_used
< abbrev_lookup_allocated
);
10246 struct abbrev_lookup_entry
*entry
;
10247 for (entry
= abbrev_lookup
;
10248 entry
< abbrev_lookup
+ abbrev_lookup_used
;
10250 if (entry
->abbrev_tag
== abbrev_tag
)
10252 warn (_("Duplicate abbreviation tag %" PRIu64
10253 " in unit %#tx in the debug_names section\n"),
10254 abbrev_tag
, unit_start
- section
->start
);
10257 entry
= &abbrev_lookup
[abbrev_lookup_used
++];
10258 entry
->abbrev_tag
= abbrev_tag
;
10259 entry
->abbrev_lookup_ptr
= abbrevptr
;
10261 /* Skip DWARF tag. */
10262 SKIP_ULEB (abbrevptr
, abbrev_table_end
);
10265 uint64_t xindex
, form
;
10267 READ_ULEB (xindex
, abbrevptr
, abbrev_table_end
);
10268 READ_ULEB (form
, abbrevptr
, abbrev_table_end
);
10269 if (xindex
== 0 && form
== 0)
10274 printf (_("\nSymbol table:\n"));
10276 for (namei
= 0; namei
< name_count
; ++namei
)
10278 uint64_t string_offset
, entry_offset
;
10281 p
= name_table_string_offsets
+ namei
* offset_size
;
10282 SAFE_BYTE_GET (string_offset
, p
, offset_size
, unit_end
);
10283 p
= name_table_entry_offsets
+ namei
* offset_size
;
10284 SAFE_BYTE_GET (entry_offset
, p
, offset_size
, unit_end
);
10286 printf ("[%3u] #%08x %s:", namei
, hash_table_hashes
[namei
],
10287 fetch_indirect_string (string_offset
));
10289 unsigned char *entryptr
= entry_pool
+ entry_offset
;
10291 /* We need to scan first whether there is a single or multiple
10292 entries. TAGNO is -2 for the first entry, it is -1 for the
10293 initial tag read of the second entry, then it becomes 0 for the
10294 first entry for real printing etc. */
10296 /* Initialize it due to a false compiler warning. */
10297 uint64_t second_abbrev_tag
= -1;
10300 uint64_t abbrev_tag
;
10301 uint64_t dwarf_tag
;
10302 const struct abbrev_lookup_entry
*entry
;
10304 READ_ULEB (abbrev_tag
, entryptr
, unit_end
);
10307 second_abbrev_tag
= abbrev_tag
;
10309 entryptr
= entry_pool
+ entry_offset
;
10312 if (abbrev_tag
== 0)
10315 printf ("%s<%" PRIu64
">",
10316 (tagno
== 0 && second_abbrev_tag
== 0 ? " " : "\n\t"),
10319 for (entry
= abbrev_lookup
;
10320 entry
< abbrev_lookup
+ abbrev_lookup_used
;
10322 if (entry
->abbrev_tag
== abbrev_tag
)
10324 if (entry
>= abbrev_lookup
+ abbrev_lookup_used
)
10326 warn (_("Undefined abbreviation tag %" PRId64
10327 " in unit %#tx in the debug_names section\n"),
10329 unit_start
- section
->start
);
10332 abbrevptr
= entry
->abbrev_lookup_ptr
;
10333 READ_ULEB (dwarf_tag
, abbrevptr
, abbrev_table_end
);
10335 printf (" %s", get_TAG_name (dwarf_tag
));
10338 uint64_t xindex
, form
;
10340 READ_ULEB (xindex
, abbrevptr
, abbrev_table_end
);
10341 READ_ULEB (form
, abbrevptr
, abbrev_table_end
);
10342 if (xindex
== 0 && form
== 0)
10346 printf (" %s", get_IDX_name (xindex
));
10347 entryptr
= read_and_display_attr_value (0, form
, 0,
10348 unit_start
, entryptr
, unit_end
,
10350 dwarf_version
, NULL
,
10351 (tagno
< 0), section
,
10357 printf (_(" <no entries>"));
10361 free (abbrev_lookup
);
10368 display_debug_links (struct dwarf_section
* section
,
10369 void * file ATTRIBUTE_UNUSED
)
10371 const unsigned char * filename
;
10372 unsigned int filelen
;
10374 introduce (section
, false);
10376 /* The .gnu_debuglink section is formatted as:
10377 (c-string) Filename.
10378 (padding) If needed to reach a 4 byte boundary.
10379 (uint32_t) CRC32 value.
10381 The .gun_debugaltlink section is formatted as:
10382 (c-string) Filename.
10383 (binary) Build-ID. */
10385 filename
= section
->start
;
10386 filelen
= strnlen ((const char *) filename
, section
->size
);
10387 if (filelen
== section
->size
)
10389 warn (_("The debuglink filename is corrupt/missing\n"));
10393 printf (_(" Separate debug info file: %s\n"), filename
);
10395 if (startswith (section
->name
, ".gnu_debuglink"))
10397 unsigned int crc32
;
10398 unsigned int crc_offset
;
10400 crc_offset
= filelen
+ 1;
10401 crc_offset
= (crc_offset
+ 3) & ~3;
10402 if (crc_offset
+ 4 > section
->size
)
10404 warn (_("CRC offset missing/truncated\n"));
10408 crc32
= byte_get (filename
+ crc_offset
, 4);
10410 printf (_(" CRC value: %#x\n"), crc32
);
10412 if (crc_offset
+ 4 < section
->size
)
10414 warn (_("There are %#" PRIx64
10415 " extraneous bytes at the end of the section\n"),
10416 section
->size
- (crc_offset
+ 4));
10420 else /* startswith (section->name, ".gnu_debugaltlink") */
10422 const unsigned char *build_id
= section
->start
+ filelen
+ 1;
10423 size_t build_id_len
= section
->size
- (filelen
+ 1);
10426 /* FIXME: Should we support smaller build-id notes ? */
10427 if (build_id_len
< 0x14)
10429 warn (_("Build-ID is too short (%#zx bytes)\n"), build_id_len
);
10433 printed
= printf (_(" Build-ID (%#zx bytes):"), build_id_len
);
10434 display_data (printed
, build_id
, build_id_len
);
10443 display_gdb_index (struct dwarf_section
*section
,
10444 void *file ATTRIBUTE_UNUSED
)
10446 unsigned char *start
= section
->start
;
10448 uint32_t cu_list_offset
, tu_list_offset
;
10449 uint32_t address_table_offset
, symbol_table_offset
, constant_pool_offset
;
10450 unsigned int cu_list_elements
, tu_list_elements
;
10451 unsigned int address_table_elements
, symbol_table_slots
;
10452 unsigned char *cu_list
, *tu_list
;
10453 unsigned char *address_table
, *symbol_table
, *constant_pool
;
10456 /* The documentation for the format of this file is in gdb/dwarf2read.c. */
10458 introduce (section
, false);
10460 if (section
->size
< 6 * sizeof (uint32_t))
10462 warn (_("Truncated header in the %s section.\n"), section
->name
);
10466 version
= byte_get_little_endian (start
, 4);
10467 printf (_("Version %lu\n"), (unsigned long) version
);
10469 /* Prior versions are obsolete, and future versions may not be
10470 backwards compatible. */
10471 if (version
< 3 || version
> 8)
10473 warn (_("Unsupported version %lu.\n"), (unsigned long) version
);
10477 warn (_("The address table data in version 3 may be wrong.\n"));
10479 warn (_("Version 4 does not support case insensitive lookups.\n"));
10481 warn (_("Version 5 does not include inlined functions.\n"));
10483 warn (_("Version 6 does not include symbol attributes.\n"));
10484 /* Version 7 indices generated by Gold have bad type unit references,
10485 PR binutils/15021. But we don't know if the index was generated by
10486 Gold or not, so to avoid worrying users with gdb-generated indices
10487 we say nothing for version 7 here. */
10489 cu_list_offset
= byte_get_little_endian (start
+ 4, 4);
10490 tu_list_offset
= byte_get_little_endian (start
+ 8, 4);
10491 address_table_offset
= byte_get_little_endian (start
+ 12, 4);
10492 symbol_table_offset
= byte_get_little_endian (start
+ 16, 4);
10493 constant_pool_offset
= byte_get_little_endian (start
+ 20, 4);
10495 if (cu_list_offset
> section
->size
10496 || tu_list_offset
> section
->size
10497 || address_table_offset
> section
->size
10498 || symbol_table_offset
> section
->size
10499 || constant_pool_offset
> section
->size
10500 || tu_list_offset
< cu_list_offset
10501 || address_table_offset
< tu_list_offset
10502 || symbol_table_offset
< address_table_offset
10503 || constant_pool_offset
< symbol_table_offset
)
10505 warn (_("Corrupt header in the %s section.\n"), section
->name
);
10509 cu_list_elements
= (tu_list_offset
- cu_list_offset
) / 16;
10510 tu_list_elements
= (address_table_offset
- tu_list_offset
) / 24;
10511 address_table_elements
= (symbol_table_offset
- address_table_offset
) / 20;
10512 symbol_table_slots
= (constant_pool_offset
- symbol_table_offset
) / 8;
10514 cu_list
= start
+ cu_list_offset
;
10515 tu_list
= start
+ tu_list_offset
;
10516 address_table
= start
+ address_table_offset
;
10517 symbol_table
= start
+ symbol_table_offset
;
10518 constant_pool
= start
+ constant_pool_offset
;
10520 printf (_("\nCU table:\n"));
10521 for (i
= 0; i
< cu_list_elements
; i
++)
10523 uint64_t cu_offset
= byte_get_little_endian (cu_list
+ i
* 16, 8);
10524 uint64_t cu_length
= byte_get_little_endian (cu_list
+ i
* 16 + 8, 8);
10526 printf ("[%3u] %#" PRIx64
" - %#" PRIx64
"\n",
10527 i
, cu_offset
, cu_offset
+ cu_length
- 1);
10530 printf (_("\nTU table:\n"));
10531 for (i
= 0; i
< tu_list_elements
; i
++)
10533 uint64_t tu_offset
= byte_get_little_endian (tu_list
+ i
* 24, 8);
10534 uint64_t type_offset
= byte_get_little_endian (tu_list
+ i
* 24 + 8, 8);
10535 uint64_t signature
= byte_get_little_endian (tu_list
+ i
* 24 + 16, 8);
10537 printf ("[%3u] %#" PRIx64
" %#" PRIx64
" ",
10538 i
, tu_offset
, type_offset
);
10539 print_hex_ns (signature
, 8);
10543 printf (_("\nAddress table:\n"));
10544 for (i
= 0; i
< address_table_elements
; i
++)
10546 uint64_t low
= byte_get_little_endian (address_table
+ i
* 20, 8);
10547 uint64_t high
= byte_get_little_endian (address_table
+ i
* 20 + 8, 8);
10548 uint32_t cu_index
= byte_get_little_endian (address_table
+ i
+ 20 + 16, 4);
10550 print_hex (low
, 8);
10551 print_hex (high
, 8);
10552 printf ("%" PRIu32
"\n", cu_index
);
10555 printf (_("\nSymbol table:\n"));
10556 for (i
= 0; i
< symbol_table_slots
; ++i
)
10558 uint32_t name_offset
= byte_get_little_endian (symbol_table
+ i
* 8, 4);
10559 uint32_t cu_vector_offset
= byte_get_little_endian (symbol_table
+ i
* 8 + 4, 4);
10560 uint32_t num_cus
, cu
;
10562 if (name_offset
!= 0
10563 || cu_vector_offset
!= 0)
10567 /* PR 17531: file: 5b7b07ad. */
10568 if (name_offset
>= section
->size
- constant_pool_offset
)
10570 printf (_("[%3u] <corrupt offset: %x>"), i
, name_offset
);
10571 warn (_("Corrupt name offset of 0x%x found for symbol table slot %d\n"),
10575 printf ("[%3u] %.*s:", i
,
10576 (int) (section
->size
- (constant_pool_offset
+ name_offset
)),
10577 constant_pool
+ name_offset
);
10579 if (section
->size
- constant_pool_offset
< 4
10580 || cu_vector_offset
> section
->size
- constant_pool_offset
- 4)
10582 printf (_("<invalid CU vector offset: %x>\n"), cu_vector_offset
);
10583 warn (_("Corrupt CU vector offset of 0x%x found for symbol table slot %d\n"),
10584 cu_vector_offset
, i
);
10588 num_cus
= byte_get_little_endian (constant_pool
+ cu_vector_offset
, 4);
10590 if ((uint64_t) num_cus
* 4 > section
->size
- (constant_pool_offset
10591 + cu_vector_offset
+ 4))
10593 printf ("<invalid number of CUs: %d>\n", num_cus
);
10594 warn (_("Invalid number of CUs (0x%x) for symbol table slot %d\n"),
10602 for (j
= 0; j
< num_cus
; ++j
)
10605 gdb_index_symbol_kind kind
;
10607 cu
= byte_get_little_endian (constant_pool
+ cu_vector_offset
+ 4 + j
* 4, 4);
10608 is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu
);
10609 kind
= GDB_INDEX_SYMBOL_KIND_VALUE (cu
);
10610 cu
= GDB_INDEX_CU_VALUE (cu
);
10611 /* Convert to TU number if it's for a type unit. */
10612 if (cu
>= cu_list_elements
)
10613 printf ("%cT%lu", num_cus
> 1 ? '\t' : ' ',
10614 (unsigned long) cu
- cu_list_elements
);
10616 printf ("%c%lu", num_cus
> 1 ? '\t' : ' ', (unsigned long) cu
);
10618 printf (" [%s, %s]",
10619 is_static
? _("static") : _("global"),
10620 get_gdb_index_symbol_kind_name (kind
));
10632 /* Pre-allocate enough space for the CU/TU sets needed. */
10635 prealloc_cu_tu_list (unsigned int nshndx
)
10637 if (shndx_pool
== NULL
)
10639 shndx_pool_size
= nshndx
;
10640 shndx_pool_used
= 0;
10641 shndx_pool
= (unsigned int *) xcmalloc (shndx_pool_size
,
10642 sizeof (unsigned int));
10646 shndx_pool_size
= shndx_pool_used
+ nshndx
;
10647 shndx_pool
= (unsigned int *) xcrealloc (shndx_pool
, shndx_pool_size
,
10648 sizeof (unsigned int));
10653 add_shndx_to_cu_tu_entry (unsigned int shndx
)
10655 if (shndx_pool_used
>= shndx_pool_size
)
10657 error (_("Internal error: out of space in the shndx pool.\n"));
10660 shndx_pool
[shndx_pool_used
++] = shndx
;
10664 end_cu_tu_entry (void)
10666 if (shndx_pool_used
>= shndx_pool_size
)
10668 error (_("Internal error: out of space in the shndx pool.\n"));
10671 shndx_pool
[shndx_pool_used
++] = 0;
10674 /* Return the short name of a DWARF section given by a DW_SECT enumerator. */
10676 static const char *
10677 get_DW_SECT_short_name (unsigned int dw_sect
)
10679 static char buf
[16];
10685 case DW_SECT_TYPES
:
10687 case DW_SECT_ABBREV
:
10693 case DW_SECT_STR_OFFSETS
:
10695 case DW_SECT_MACINFO
:
10697 case DW_SECT_MACRO
:
10703 snprintf (buf
, sizeof (buf
), "%d", dw_sect
);
10707 /* Process a CU or TU index. If DO_DISPLAY is true, print the contents.
10708 These sections are extensions for Fission.
10709 See http://gcc.gnu.org/wiki/DebugFissionDWP. */
10712 process_cu_tu_index (struct dwarf_section
*section
, int do_display
)
10714 unsigned char *phdr
= section
->start
;
10715 unsigned char *limit
= phdr
+ section
->size
;
10716 unsigned char *phash
;
10717 unsigned char *pindex
;
10718 unsigned char *ppool
;
10719 unsigned int version
;
10720 unsigned int ncols
= 0;
10721 unsigned int nused
;
10722 unsigned int nslots
;
10725 uint64_t signature
;
10728 /* PR 17512: file: 002-168123-0.004. */
10731 warn (_("Section %s is empty\n"), section
->name
);
10734 /* PR 17512: file: 002-376-0.004. */
10735 if (section
->size
< 24)
10737 warn (_("Section %s is too small to contain a CU/TU header\n"),
10743 SAFE_BYTE_GET_AND_INC (version
, phash
, 4, limit
);
10745 SAFE_BYTE_GET_AND_INC (ncols
, phash
, 4, limit
);
10746 SAFE_BYTE_GET_AND_INC (nused
, phash
, 4, limit
);
10747 SAFE_BYTE_GET_AND_INC (nslots
, phash
, 4, limit
);
10749 pindex
= phash
+ (size_t) nslots
* 8;
10750 ppool
= pindex
+ (size_t) nslots
* 4;
10754 introduce (section
, false);
10756 printf (_(" Version: %u\n"), version
);
10758 printf (_(" Number of columns: %u\n"), ncols
);
10759 printf (_(" Number of used entries: %u\n"), nused
);
10760 printf (_(" Number of slots: %u\n\n"), nslots
);
10763 /* PR 17531: file: 45d69832. */
10764 if (_mul_overflow ((size_t) nslots
, 12, &total
)
10765 || total
> (size_t) (limit
- phash
))
10767 warn (ngettext ("Section %s is too small for %u slot\n",
10768 "Section %s is too small for %u slots\n",
10770 section
->name
, nslots
);
10777 prealloc_cu_tu_list ((limit
- ppool
) / 4);
10778 for (i
= 0; i
< nslots
; i
++)
10780 unsigned char *shndx_list
;
10781 unsigned int shndx
;
10783 SAFE_BYTE_GET (signature
, phash
, 8, limit
);
10784 if (signature
!= 0)
10786 SAFE_BYTE_GET (j
, pindex
, 4, limit
);
10787 shndx_list
= ppool
+ j
* 4;
10788 /* PR 17531: file: 705e010d. */
10789 if (shndx_list
< ppool
)
10791 warn (_("Section index pool located before start of section\n"));
10796 printf (_(" [%3d] Signature: %#" PRIx64
" Sections: "),
10800 if (shndx_list
>= limit
)
10802 warn (_("Section %s too small for shndx pool\n"),
10806 SAFE_BYTE_GET (shndx
, shndx_list
, 4, limit
);
10810 printf (" %d", shndx
);
10812 add_shndx_to_cu_tu_entry (shndx
);
10818 end_cu_tu_entry ();
10824 else if (version
== 2)
10827 unsigned int dw_sect
;
10828 unsigned char *ph
= phash
;
10829 unsigned char *pi
= pindex
;
10830 unsigned char *poffsets
= ppool
+ (size_t) ncols
* 4;
10831 unsigned char *psizes
= poffsets
+ (size_t) nused
* ncols
* 4;
10833 struct cu_tu_set
*this_set
= NULL
;
10835 unsigned char *prow
;
10838 is_tu_index
= strcmp (section
->name
, ".debug_tu_index") == 0;
10840 /* PR 17531: file: 0dd159bf.
10841 Check for integer overflow (can occur when size_t is 32-bit)
10842 with overlarge ncols or nused values. */
10844 || _mul_overflow ((size_t) ncols
, 4, &temp
)
10845 || _mul_overflow ((size_t) nused
+ 1, temp
, &total
)
10846 || total
> (size_t) (limit
- ppool
))
10848 warn (_("Section %s too small for offset and size tables\n"),
10855 printf (_(" Offset table\n"));
10856 printf (" slot %-16s ",
10857 is_tu_index
? _("signature") : _("dwo_id"));
10864 tu_sets
= xcalloc2 (nused
, sizeof (struct cu_tu_set
));
10865 this_set
= tu_sets
;
10870 cu_sets
= xcalloc2 (nused
, sizeof (struct cu_tu_set
));
10871 this_set
= cu_sets
;
10877 for (j
= 0; j
< ncols
; j
++)
10879 unsigned char *p
= ppool
+ j
* 4;
10880 SAFE_BYTE_GET (dw_sect
, p
, 4, limit
);
10881 printf (" %8s", get_DW_SECT_short_name (dw_sect
));
10886 for (i
= 0; i
< nslots
; i
++)
10888 SAFE_BYTE_GET (signature
, ph
, 8, limit
);
10890 SAFE_BYTE_GET (row
, pi
, 4, limit
);
10893 /* PR 17531: file: a05f6ab3. */
10896 warn (_("Row index (%u) is larger than number of used entries (%u)\n"),
10903 size_t num_copy
= sizeof (uint64_t);
10905 memcpy (&this_set
[row
- 1].signature
, ph
, num_copy
);
10908 prow
= poffsets
+ (row
- 1) * ncols
* 4;
10910 printf (" [%3d] %#" PRIx64
, i
, signature
);
10911 for (j
= 0; j
< ncols
; j
++)
10913 unsigned char *p
= prow
+ j
* 4;
10914 SAFE_BYTE_GET (val
, p
, 4, limit
);
10916 printf (" %8d", val
);
10920 SAFE_BYTE_GET (dw_sect
, p
, 4, limit
);
10922 /* PR 17531: file: 10796eb3. */
10923 if (dw_sect
>= DW_SECT_MAX
)
10924 warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect
);
10926 this_set
[row
- 1].section_offsets
[dw_sect
] = val
;
10942 printf (_(" Size table\n"));
10943 printf (" slot %-16s ",
10944 is_tu_index
? _("signature") : _("dwo_id"));
10947 for (j
= 0; j
< ncols
; j
++)
10949 unsigned char *p
= ppool
+ j
* 4;
10950 SAFE_BYTE_GET (val
, p
, 4, limit
);
10952 printf (" %8s", get_DW_SECT_short_name (val
));
10958 for (i
= 0; i
< nslots
; i
++)
10960 SAFE_BYTE_GET (signature
, ph
, 8, limit
);
10962 SAFE_BYTE_GET (row
, pi
, 4, limit
);
10965 prow
= psizes
+ (row
- 1) * ncols
* 4;
10968 printf (" [%3d] %#" PRIx64
, i
, signature
);
10970 for (j
= 0; j
< ncols
; j
++)
10972 unsigned char *p
= prow
+ j
* 4;
10974 /* PR 28645: Check for overflow. Since we do not know how
10975 many populated rows there will be, we cannot just
10976 perform a single check at the start of this function. */
10977 if (p
> (limit
- 4))
10981 warn (_("Too many rows/columns in DWARF index section %s\n"),
10986 SAFE_BYTE_GET (val
, p
, 4, limit
);
10989 printf (" %8d", val
);
10993 SAFE_BYTE_GET (dw_sect
, p
, 4, limit
);
10994 if (dw_sect
>= DW_SECT_MAX
)
10995 warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect
);
10997 this_set
[row
- 1].section_sizes
[dw_sect
] = val
;
11009 else if (do_display
)
11010 printf (_(" Unsupported version (%d)\n"), version
);
11018 static int cu_tu_indexes_read
= -1; /* Tri-state variable. */
11020 /* Load the CU and TU indexes if present. This will build a list of
11021 section sets that we can use to associate a .debug_info.dwo section
11022 with its associated .debug_abbrev.dwo section in a .dwp file. */
11025 load_cu_tu_indexes (void *file
)
11027 /* If we have already loaded (or tried to load) the CU and TU indexes
11028 then do not bother to repeat the task. */
11029 if (cu_tu_indexes_read
== -1)
11031 cu_tu_indexes_read
= true;
11033 if (load_debug_section_with_follow (dwp_cu_index
, file
))
11034 if (! process_cu_tu_index (&debug_displays
[dwp_cu_index
].section
, 0))
11035 cu_tu_indexes_read
= false;
11037 if (load_debug_section_with_follow (dwp_tu_index
, file
))
11038 if (! process_cu_tu_index (&debug_displays
[dwp_tu_index
].section
, 0))
11039 cu_tu_indexes_read
= false;
11042 return (bool) cu_tu_indexes_read
;
11045 /* Find the set of sections that includes section SHNDX. */
11048 find_cu_tu_set (void *file
, unsigned int shndx
)
11052 if (! load_cu_tu_indexes (file
))
11055 /* Find SHNDX in the shndx pool. */
11056 for (i
= 0; i
< shndx_pool_used
; i
++)
11057 if (shndx_pool
[i
] == shndx
)
11060 if (i
>= shndx_pool_used
)
11063 /* Now backup to find the first entry in the set. */
11064 while (i
> 0 && shndx_pool
[i
- 1] != 0)
11067 return shndx_pool
+ i
;
11070 /* Display a .debug_cu_index or .debug_tu_index section. */
11073 display_cu_index (struct dwarf_section
*section
, void *file ATTRIBUTE_UNUSED
)
11075 return process_cu_tu_index (section
, 1);
11079 display_debug_not_supported (struct dwarf_section
*section
,
11080 void *file ATTRIBUTE_UNUSED
)
11082 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
11088 /* Like malloc, but takes two parameters like calloc.
11089 Verifies that the first parameter is not too large.
11090 Note: does *not* initialise the allocated memory to zero. */
11093 cmalloc (size_t nmemb
, size_t size
)
11095 /* Check for overflow. */
11096 if (nmemb
>= ~(size_t) 0 / size
)
11099 return xmalloc (nmemb
* size
);
11102 /* Like xmalloc, but takes two parameters like calloc.
11103 Verifies that the first parameter is not too large.
11104 Note: does *not* initialise the allocated memory to zero. */
11107 xcmalloc (size_t nmemb
, size_t size
)
11109 /* Check for overflow. */
11110 if (nmemb
>= ~(size_t) 0 / size
)
11113 _("Attempt to allocate an array with an excessive number of elements: %#zx\n"),
11118 return xmalloc (nmemb
* size
);
11121 /* Like xrealloc, but takes three parameters.
11122 Verifies that the second parameter is not too large.
11123 Note: does *not* initialise any new memory to zero. */
11126 xcrealloc (void *ptr
, size_t nmemb
, size_t size
)
11128 /* Check for overflow. */
11129 if (nmemb
>= ~(size_t) 0 / size
)
11131 error (_("Attempt to re-allocate an array with an excessive number of elements: %#zx\n"),
11136 return xrealloc (ptr
, nmemb
* size
);
11139 /* Like xcalloc, but verifies that the first parameter is not too large. */
11142 xcalloc2 (size_t nmemb
, size_t size
)
11144 /* Check for overflow. */
11145 if (nmemb
>= ~(size_t) 0 / size
)
11147 error (_("Attempt to allocate a zero'ed array with an excessive number of elements: %#zx\n"),
11152 return xcalloc (nmemb
, size
);
11155 static unsigned long
11156 calc_gnu_debuglink_crc32 (unsigned long crc
,
11157 const unsigned char *buf
,
11160 static const unsigned long crc32_table
[256] =
11162 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
11163 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
11164 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
11165 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
11166 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
11167 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
11168 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
11169 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
11170 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
11171 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
11172 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
11173 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
11174 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
11175 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
11176 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
11177 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
11178 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
11179 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
11180 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
11181 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
11182 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
11183 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
11184 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
11185 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
11186 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
11187 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
11188 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
11189 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
11190 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
11191 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
11192 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
11193 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
11194 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
11195 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
11196 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
11197 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
11198 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
11199 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
11200 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
11201 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
11202 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
11203 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
11204 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
11205 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
11206 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
11207 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
11208 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
11209 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
11210 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
11211 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
11212 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
11215 const unsigned char *end
;
11217 crc
= ~crc
& 0xffffffff;
11218 for (end
= buf
+ len
; buf
< end
; ++ buf
)
11219 crc
= crc32_table
[(crc
^ *buf
) & 0xff] ^ (crc
>> 8);
11220 return ~crc
& 0xffffffff;
11223 typedef bool (*check_func_type
) (const char *, void *);
11224 typedef const char *(* parse_func_type
) (struct dwarf_section
*, void *);
11227 check_gnu_debuglink (const char * pathname
, void * crc_pointer
)
11229 static unsigned char buffer
[8 * 1024];
11232 unsigned long crc
= 0;
11235 sep_data
= open_debug_file (pathname
);
11236 if (sep_data
== NULL
)
11239 /* Yes - we are opening the file twice... */
11240 f
= fopen (pathname
, "rb");
11243 /* Paranoia: This should never happen. */
11244 close_debug_file (sep_data
);
11245 warn (_("Unable to reopen separate debug info file: %s\n"), pathname
);
11249 while ((count
= fread (buffer
, 1, sizeof (buffer
), f
)) > 0)
11250 crc
= calc_gnu_debuglink_crc32 (crc
, buffer
, count
);
11254 if (crc
!= * (unsigned long *) crc_pointer
)
11256 close_debug_file (sep_data
);
11257 warn (_("Separate debug info file %s found, but CRC does not match - ignoring\n"),
11265 static const char *
11266 parse_gnu_debuglink (struct dwarf_section
* section
, void * data
)
11269 unsigned int crc_offset
;
11270 unsigned long * crc32
= (unsigned long *) data
;
11272 /* The name is first.
11273 The CRC value is stored after the filename, aligned up to 4 bytes. */
11274 name
= (const char *) section
->start
;
11276 crc_offset
= strnlen (name
, section
->size
) + 1;
11277 if (crc_offset
== 1)
11279 crc_offset
= (crc_offset
+ 3) & ~3;
11280 if (crc_offset
+ 4 > section
->size
)
11283 * crc32
= byte_get (section
->start
+ crc_offset
, 4);
11288 check_gnu_debugaltlink (const char * filename
, void * data ATTRIBUTE_UNUSED
)
11290 void * sep_data
= open_debug_file (filename
);
11292 if (sep_data
== NULL
)
11295 /* FIXME: We should now extract the build-id in the separate file
11301 typedef struct build_id_data
11304 const unsigned char *data
;
11307 static const char *
11308 parse_gnu_debugaltlink (struct dwarf_section
* section
, void * data
)
11313 Build_id_data
*build_id_data
;
11315 /* The name is first.
11316 The build-id follows immediately, with no padding, up to the section's end. */
11318 name
= (const char *) section
->start
;
11319 namelen
= strnlen (name
, section
->size
) + 1;
11322 if (namelen
>= section
->size
)
11325 id_len
= section
->size
- namelen
;
11329 build_id_data
= (Build_id_data
*) data
;
11330 build_id_data
->len
= id_len
;
11331 build_id_data
->data
= section
->start
+ namelen
;
11337 add_separate_debug_file (const char * filename
, void * handle
)
11339 separate_info
* i
= xmalloc (sizeof * i
);
11341 i
->filename
= filename
;
11342 i
->handle
= handle
;
11343 i
->next
= first_separate_info
;
11344 first_separate_info
= i
;
11347 #if HAVE_LIBDEBUGINFOD
11348 /* Query debuginfod servers for the target debuglink or debugaltlink
11349 file. If successful, store the path of the file in filename and
11350 return TRUE, otherwise return FALSE. */
11353 debuginfod_fetch_separate_debug_info (struct dwarf_section
* section
,
11357 size_t build_id_len
;
11358 unsigned char * build_id
;
11360 if (strcmp (section
->uncompressed_name
, ".gnu_debuglink") == 0)
11362 /* Get the build-id of file. */
11363 build_id
= get_build_id (file
);
11366 else if (strcmp (section
->uncompressed_name
, ".gnu_debugaltlink") == 0)
11368 /* Get the build-id of the debugaltlink file. */
11369 unsigned int filelen
;
11371 filelen
= strnlen ((const char *)section
->start
, section
->size
);
11372 if (filelen
== section
->size
)
11373 /* Corrupt debugaltlink. */
11376 build_id
= section
->start
+ filelen
+ 1;
11377 build_id_len
= section
->size
- (filelen
+ 1);
11379 if (build_id_len
== 0)
11388 debuginfod_client
* client
;
11390 client
= debuginfod_begin ();
11391 if (client
== NULL
)
11394 /* Query debuginfod servers for the target file. If found its path
11395 will be stored in filename. */
11396 fd
= debuginfod_find_debuginfo (client
, build_id
, build_id_len
, filename
);
11397 debuginfod_end (client
);
11399 /* Only free build_id if we allocated space for a hex string
11400 in get_build_id (). */
11401 if (build_id_len
== 0)
11406 /* File successfully retrieved. Close fd since we want to
11407 use open_debug_file () on filename instead. */
11415 #endif /* HAVE_LIBDEBUGINFOD */
11418 load_separate_debug_info (const char * main_filename
,
11419 struct dwarf_section
* xlink
,
11420 parse_func_type parse_func
,
11421 check_func_type check_func
,
11423 void * file ATTRIBUTE_UNUSED
)
11425 const char * separate_filename
;
11426 char * debug_filename
;
11428 size_t canon_dirlen
;
11430 char * canon_filename
;
11431 char * canon_debug_filename
;
11434 if ((separate_filename
= parse_func (xlink
, func_data
)) == NULL
)
11436 warn (_("Corrupt debuglink section: %s\n"),
11437 xlink
->name
? xlink
->name
: xlink
->uncompressed_name
);
11441 /* Attempt to locate the separate file.
11442 This should duplicate the logic in bfd/opncls.c:find_separate_debug_file(). */
11444 canon_filename
= lrealpath (main_filename
);
11445 canon_dir
= xstrdup (canon_filename
);
11447 for (canon_dirlen
= strlen (canon_dir
); canon_dirlen
> 0; canon_dirlen
--)
11448 if (IS_DIR_SEPARATOR (canon_dir
[canon_dirlen
- 1]))
11450 canon_dir
[canon_dirlen
] = '\0';
11453 #define DEBUGDIR "/lib/debug"
11455 #ifndef EXTRA_DEBUG_ROOT1
11456 #define EXTRA_DEBUG_ROOT1 "/usr/lib/debug"
11458 #ifndef EXTRA_DEBUG_ROOT2
11459 #define EXTRA_DEBUG_ROOT2 "/usr/lib/debug/usr"
11462 debug_filename
= (char *) malloc (strlen (DEBUGDIR
) + 1
11464 + strlen (".debug/")
11465 #ifdef EXTRA_DEBUG_ROOT1
11466 + strlen (EXTRA_DEBUG_ROOT1
)
11468 #ifdef EXTRA_DEBUG_ROOT2
11469 + strlen (EXTRA_DEBUG_ROOT2
)
11471 + strlen (separate_filename
)
11473 if (debug_filename
== NULL
)
11475 warn (_("Out of memory"));
11477 free (canon_filename
);
11481 /* First try in the current directory. */
11482 sprintf (debug_filename
, "%s", separate_filename
);
11483 if (check_func (debug_filename
, func_data
))
11486 /* Then try in a subdirectory called .debug. */
11487 sprintf (debug_filename
, ".debug/%s", separate_filename
);
11488 if (check_func (debug_filename
, func_data
))
11491 /* Then try in the same directory as the original file. */
11492 sprintf (debug_filename
, "%s%s", canon_dir
, separate_filename
);
11493 if (check_func (debug_filename
, func_data
))
11496 /* And the .debug subdirectory of that directory. */
11497 sprintf (debug_filename
, "%s.debug/%s", canon_dir
, separate_filename
);
11498 if (check_func (debug_filename
, func_data
))
11501 #ifdef EXTRA_DEBUG_ROOT1
11502 /* Try the first extra debug file root. */
11503 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT1
, separate_filename
);
11504 if (check_func (debug_filename
, func_data
))
11507 /* Try the first extra debug file root. */
11508 sprintf (debug_filename
, "%s/%s/%s", EXTRA_DEBUG_ROOT1
, canon_dir
, separate_filename
);
11509 if (check_func (debug_filename
, func_data
))
11513 #ifdef EXTRA_DEBUG_ROOT2
11514 /* Try the second extra debug file root. */
11515 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT2
, separate_filename
);
11516 if (check_func (debug_filename
, func_data
))
11520 /* Then try in the global debug_filename directory. */
11521 strcpy (debug_filename
, DEBUGDIR
);
11522 dirlen
= strlen (DEBUGDIR
) - 1;
11523 if (dirlen
> 0 && DEBUGDIR
[dirlen
] != '/')
11524 strcat (debug_filename
, "/");
11525 strcat (debug_filename
, (const char *) separate_filename
);
11527 if (check_func (debug_filename
, func_data
))
11530 #if HAVE_LIBDEBUGINFOD
11532 char * tmp_filename
;
11535 && debuginfod_fetch_separate_debug_info (xlink
,
11539 /* File successfully downloaded from server, replace
11540 debug_filename with the file's path. */
11541 free (debug_filename
);
11542 debug_filename
= tmp_filename
;
11548 if (do_debug_links
)
11550 /* Failed to find the file. */
11551 warn (_("could not find separate debug file '%s'\n"),
11552 separate_filename
);
11553 warn (_("tried: %s\n"), debug_filename
);
11555 #ifdef EXTRA_DEBUG_ROOT2
11556 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT2
,
11557 separate_filename
);
11558 warn (_("tried: %s\n"), debug_filename
);
11561 #ifdef EXTRA_DEBUG_ROOT1
11562 sprintf (debug_filename
, "%s/%s/%s", EXTRA_DEBUG_ROOT1
,
11563 canon_dir
, separate_filename
);
11564 warn (_("tried: %s\n"), debug_filename
);
11566 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT1
,
11567 separate_filename
);
11568 warn (_("tried: %s\n"), debug_filename
);
11571 sprintf (debug_filename
, "%s.debug/%s", canon_dir
,
11572 separate_filename
);
11573 warn (_("tried: %s\n"), debug_filename
);
11575 sprintf (debug_filename
, "%s%s", canon_dir
, separate_filename
);
11576 warn (_("tried: %s\n"), debug_filename
);
11578 sprintf (debug_filename
, ".debug/%s", separate_filename
);
11579 warn (_("tried: %s\n"), debug_filename
);
11581 sprintf (debug_filename
, "%s", separate_filename
);
11582 warn (_("tried: %s\n"), debug_filename
);
11584 #if HAVE_LIBDEBUGINFOD
11585 if (use_debuginfod
)
11587 char *urls
= getenv (DEBUGINFOD_URLS_ENV_VAR
);
11592 warn (_("tried: DEBUGINFOD_URLS=%s\n"), urls
);
11598 free (debug_filename
);
11599 free (canon_filename
);
11605 canon_debug_filename
= lrealpath (debug_filename
);
11606 self
= strcmp (canon_debug_filename
, canon_filename
) == 0;
11607 free (canon_filename
);
11608 free (canon_debug_filename
);
11611 free (debug_filename
);
11615 void * debug_handle
;
11617 /* Now open the file.... */
11618 if ((debug_handle
= open_debug_file (debug_filename
)) == NULL
)
11620 warn (_("failed to open separate debug file: %s\n"), debug_filename
);
11621 free (debug_filename
);
11625 /* FIXME: We do not check to see if there are any other separate debug info
11626 files that would also match. */
11628 if (do_debug_links
)
11629 printf (_("\n%s: Found separate debug info file: %s\n"), main_filename
, debug_filename
);
11630 add_separate_debug_file (debug_filename
, debug_handle
);
11632 /* Do not free debug_filename - it might be referenced inside
11633 the structure returned by open_debug_file(). */
11634 return debug_handle
;
11637 /* Attempt to load a separate dwarf object file. */
11640 load_dwo_file (const char * main_filename
, const char * name
, const char * dir
, const char * id ATTRIBUTE_UNUSED
)
11642 char * separate_filename
;
11643 void * separate_handle
;
11645 if (IS_ABSOLUTE_PATH (name
))
11646 separate_filename
= strdup (name
);
11648 /* FIXME: Skip adding / if dwo_dir ends in /. */
11649 separate_filename
= concat (dir
, "/", name
, NULL
);
11650 if (separate_filename
== NULL
)
11652 warn (_("Out of memory allocating dwo filename\n"));
11656 if ((separate_handle
= open_debug_file (separate_filename
)) == NULL
)
11658 warn (_("Unable to load dwo file: %s\n"), separate_filename
);
11659 free (separate_filename
);
11663 /* FIXME: We should check the dwo_id. */
11665 printf (_("%s: Found separate debug object file: %s\n\n"), main_filename
, separate_filename
);
11667 add_separate_debug_file (separate_filename
, separate_handle
);
11668 /* Note - separate_filename will be freed in free_debug_memory(). */
11669 return separate_handle
;
11673 try_build_id_prefix (const char * prefix
, char * filename
, const unsigned char * data
, unsigned long id_len
)
11675 char * f
= filename
;
11677 f
+= sprintf (f
, "%s.build-id/%02x/", prefix
, (unsigned) *data
++);
11680 f
+= sprintf (f
, "%02x", (unsigned) *data
++);
11681 strcpy (f
, ".debug");
11683 return open_debug_file (filename
);
11686 /* Try to load a debug file based upon the build-id held in the .note.gnu.build-id section. */
11689 load_build_id_debug_file (const char * main_filename ATTRIBUTE_UNUSED
, void * main_file
)
11691 if (! load_debug_section (note_gnu_build_id
, main_file
))
11692 return; /* No .note.gnu.build-id section. */
11694 struct dwarf_section
* section
= & debug_displays
[note_gnu_build_id
].section
;
11695 if (section
== NULL
)
11697 warn (_("Unable to load the .note.gnu.build-id section\n"));
11701 if (section
->start
== NULL
|| section
->size
< 0x18)
11703 warn (_(".note.gnu.build-id section is corrupt/empty\n"));
11707 /* In theory we should extract the contents of the section into
11708 a note structure and then check the fields. For now though
11709 just use hard coded offsets instead:
11711 Field Bytes Contents
11714 Type 8..11 3 (NT_GNU_BUILD_ID)
11718 /* FIXME: Check the name size, name and type fields. */
11720 unsigned long build_id_size
;
11721 build_id_size
= byte_get (section
->start
+ 4, 4);
11722 if (build_id_size
< 8)
11724 warn (_(".note.gnu.build-id data size is too small\n"));
11728 if (build_id_size
> (section
->size
- 16))
11730 warn (_(".note.gnu.build-id data size is too big\n"));
11735 filename
= xmalloc (strlen (".build-id/")
11736 + build_id_size
* 2 + 2
11737 + strlen (".debug")
11738 /* The next string should be the same as the longest
11739 name found in the prefixes[] array below. */
11740 + strlen ("/usrlib64/debug/usr")
11744 static const char * prefixes
[] =
11749 "/usr/lib/debug/usr/",
11750 "/usr/lib64/debug/",
11751 "/usr/lib64/debug/usr"
11753 long unsigned int i
;
11755 for (i
= 0; i
< ARRAY_SIZE (prefixes
); i
++)
11757 handle
= try_build_id_prefix (prefixes
[i
], filename
,
11758 section
->start
+ 16, build_id_size
);
11759 if (handle
!= NULL
)
11762 /* FIXME: TYhe BFD library also tries a global debugfile directory prefix. */
11763 if (handle
== NULL
)
11765 /* Failed to find a debug file associated with the build-id.
11766 This is not an error however, rather it just means that
11767 the debug info has probably not been loaded on the system,
11768 or that another method is being used to link to the debug
11774 add_separate_debug_file (filename
, handle
);
11777 /* Try to load a debug file pointed to by the .debug_sup section. */
11780 load_debug_sup_file (const char * main_filename
, void * file
)
11782 if (! load_debug_section (debug_sup
, file
))
11783 return; /* No .debug_sup section. */
11785 struct dwarf_section
* section
;
11786 section
= & debug_displays
[debug_sup
].section
;
11787 assert (section
!= NULL
);
11789 if (section
->start
== NULL
|| section
->size
< 5)
11791 warn (_(".debug_sup section is corrupt/empty\n"));
11795 if (section
->start
[2] != 0)
11796 return; /* This is a supplementary file. */
11798 const char * filename
= (const char *) section
->start
+ 3;
11799 if (strnlen (filename
, section
->size
- 3) == section
->size
- 3)
11801 warn (_("filename in .debug_sup section is corrupt\n"));
11805 if (filename
[0] != '/' && strchr (main_filename
, '/'))
11810 new_len
= asprintf (& new_name
, "%.*s/%s",
11811 (int) (strrchr (main_filename
, '/') - main_filename
),
11816 warn (_("unable to construct path for supplementary debug file"));
11821 filename
= new_name
;
11825 /* PR 27796: Make sure that we pass a filename that can be free'd to
11826 add_separate_debug_file(). */
11827 filename
= strdup (filename
);
11828 if (filename
== NULL
)
11830 warn (_("out of memory constructing filename for .debug_sup link\n"));
11835 void * handle
= open_debug_file (filename
);
11836 if (handle
== NULL
)
11838 warn (_("unable to open file '%s' referenced from .debug_sup section\n"), filename
);
11839 free ((void *) filename
);
11843 printf (_("%s: Found supplementary debug file: %s\n\n"), main_filename
, filename
);
11845 /* FIXME: Compare the checksums, if present. */
11846 add_separate_debug_file (filename
, handle
);
11849 /* Load a debuglink section and/or a debugaltlink section, if either are present.
11850 Recursively check the loaded files for more of these sections.
11851 Also follow any links in .debug_sup sections.
11852 FIXME: Should also check for DWO_* entries in the newly loaded files. */
11855 check_for_and_load_links (void * file
, const char * filename
)
11857 void * handle
= NULL
;
11859 if (load_debug_section (gnu_debugaltlink
, file
))
11861 Build_id_data build_id_data
;
11863 handle
= load_separate_debug_info (filename
,
11864 & debug_displays
[gnu_debugaltlink
].section
,
11865 parse_gnu_debugaltlink
,
11866 check_gnu_debugaltlink
,
11871 assert (handle
== first_separate_info
->handle
);
11872 check_for_and_load_links (first_separate_info
->handle
,
11873 first_separate_info
->filename
);
11877 if (load_debug_section (gnu_debuglink
, file
))
11879 unsigned long crc32
;
11881 handle
= load_separate_debug_info (filename
,
11882 & debug_displays
[gnu_debuglink
].section
,
11883 parse_gnu_debuglink
,
11884 check_gnu_debuglink
,
11889 assert (handle
== first_separate_info
->handle
);
11890 check_for_and_load_links (first_separate_info
->handle
,
11891 first_separate_info
->filename
);
11895 load_debug_sup_file (filename
, file
);
11897 load_build_id_debug_file (filename
, file
);
11900 /* Load the separate debug info file(s) attached to FILE, if any exist.
11901 Returns TRUE if any were found, FALSE otherwise.
11902 If TRUE is returned then the linked list starting at first_separate_info
11903 will be populated with open file handles. */
11906 load_separate_debug_files (void * file
, const char * filename
)
11908 /* Skip this operation if we are not interested in debug links. */
11909 if (! do_follow_links
&& ! do_debug_links
)
11912 /* See if there are any dwo links. */
11913 if (load_debug_section (str
, file
)
11914 && load_debug_section (abbrev
, file
)
11915 && load_debug_section (info
, file
))
11917 /* Load the .debug_addr section, if it exists. */
11918 load_debug_section (debug_addr
, file
);
11919 /* Load the .debug_str_offsets section, if it exists. */
11920 load_debug_section (str_index
, file
);
11921 /* Load the .debug_loclists section, if it exists. */
11922 load_debug_section (loclists
, file
);
11923 /* Load the .debug_rnglists section, if it exists. */
11924 load_debug_section (rnglists
, file
);
11928 if (process_debug_info (& debug_displays
[info
].section
, file
, abbrev
,
11931 bool introduced
= false;
11933 const char *dir
= NULL
;
11934 const char *id
= NULL
;
11935 const char *name
= NULL
;
11937 for (dwinfo
= first_dwo_info
; dwinfo
!= NULL
; dwinfo
= dwinfo
->next
)
11939 /* Accumulate NAME, DIR and ID fields. */
11940 switch (dwinfo
->type
)
11944 warn (_("Multiple DWO_NAMEs encountered for the same CU\n"));
11945 name
= dwinfo
->value
;
11949 /* There can be multiple DW_AT_comp_dir entries in a CU,
11950 so do not complain. */
11951 dir
= dwinfo
->value
;
11956 warn (_("multiple DWO_IDs encountered for the same CU\n"));
11957 id
= dwinfo
->value
;
11961 error (_("Unexpected DWO INFO type"));
11965 /* If we have reached the end of our list, or we are changing
11966 CUs, then display the information that we have accumulated
11969 && (dwinfo
->next
== NULL
11970 || dwinfo
->next
->cu_offset
!= dwinfo
->cu_offset
))
11972 if (do_debug_links
)
11976 printf (_("The %s section contains link(s) to dwo file(s):\n\n"),
11977 debug_displays
[info
].section
.uncompressed_name
);
11981 printf (_(" Name: %s\n"), name
);
11982 printf (_(" Directory: %s\n"), dir
? dir
: _("<not-found>"));
11984 display_data (printf (_(" ID: ")), (unsigned char *) id
, 8);
11985 else if (debug_information
[0].dwarf_version
!= 5)
11986 printf (_(" ID: <not specified>\n"));
11990 if (do_follow_links
)
11991 load_dwo_file (filename
, name
, dir
, id
);
11993 name
= dir
= id
= NULL
;
11999 if (! do_follow_links
)
12000 /* The other debug links will be displayed by display_debug_links()
12001 so we do not need to do any further processing here. */
12004 /* FIXME: We do not check for the presence of both link sections in the same file. */
12005 /* FIXME: We do not check for the presence of multiple, same-name debuglink sections. */
12006 /* FIXME: We do not check for the presence of a dwo link as well as a debuglink. */
12008 check_for_and_load_links (file
, filename
);
12009 if (first_separate_info
!= NULL
)
12012 do_follow_links
= 0;
12017 free_debug_memory (void)
12021 free_all_abbrevs ();
12025 shndx_pool_size
= 0;
12026 shndx_pool_used
= 0;
12034 memset (level_type_signed
, 0, sizeof level_type_signed
);
12035 cu_tu_indexes_read
= -1;
12037 for (i
= 0; i
< max
; i
++)
12038 free_debug_section ((enum dwarf_section_display_enum
) i
);
12040 if (debug_information
!= NULL
)
12042 for (i
= 0; i
< alloc_num_debug_info_entries
; i
++)
12043 free_debug_information (&debug_information
[i
]);
12044 free (debug_information
);
12045 debug_information
= NULL
;
12046 alloc_num_debug_info_entries
= num_debug_info_entries
= 0;
12050 separate_info
* next
;
12052 for (d
= first_separate_info
; d
!= NULL
; d
= next
)
12054 close_debug_file (d
->handle
);
12055 free ((void *) d
->filename
);
12059 first_separate_info
= NULL
;
12067 const char *option
;
12070 } debug_dump_long_opts
;
12072 static const debug_dump_long_opts debug_option_table
[] =
12074 { 'A', "addr", &do_debug_addr
, 1 },
12075 { 'a', "abbrev", &do_debug_abbrevs
, 1 },
12076 { 'c', "cu_index", &do_debug_cu_index
, 1 },
12077 #ifdef HAVE_LIBDEBUGINFOD
12078 { 'D', "use-debuginfod", &use_debuginfod
, 1 },
12079 { 'E', "do-not-use-debuginfod", &use_debuginfod
, 0 },
12081 { 'F', "frames-interp", &do_debug_frames_interp
, 1 },
12082 { 'f', "frames", &do_debug_frames
, 1 },
12083 { 'g', "gdb_index", &do_gdb_index
, 1 },
12084 { 'i', "info", &do_debug_info
, 1 },
12085 { 'K', "follow-links", &do_follow_links
, 1 },
12086 { 'k', "links", &do_debug_links
, 1 },
12087 { 'L', "decodedline", &do_debug_lines
, FLAG_DEBUG_LINES_DECODED
},
12088 { 'l', "rawline", &do_debug_lines
, FLAG_DEBUG_LINES_RAW
},
12089 /* For compatibility with earlier versions of readelf. */
12090 { 'l', "line", &do_debug_lines
, FLAG_DEBUG_LINES_RAW
},
12091 { 'm', "macro", &do_debug_macinfo
, 1 },
12092 { 'N', "no-follow-links", &do_follow_links
, 0 },
12093 { 'O', "str-offsets", &do_debug_str_offsets
, 1 },
12094 { 'o', "loc", &do_debug_loc
, 1 },
12095 { 'p', "pubnames", &do_debug_pubnames
, 1 },
12096 { 'R', "Ranges", &do_debug_ranges
, 1 },
12097 { 'r', "aranges", &do_debug_aranges
, 1 },
12098 /* For compatibility with earlier versions of readelf. */
12099 { 'r', "ranges", &do_debug_aranges
, 1 },
12100 { 's', "str", &do_debug_str
, 1 },
12101 { 'T', "trace_aranges", &do_trace_aranges
, 1 },
12102 { 't', "pubtypes", &do_debug_pubtypes
, 1 },
12103 { 'U', "trace_info", &do_trace_info
, 1 },
12104 { 'u', "trace_abbrev", &do_trace_abbrevs
, 1 },
12105 { 0, NULL
, NULL
, 0 }
12108 /* Enable display of specific DWARF sections as determined by the comma
12109 separated strings in NAMES. Returns non-zero if any displaying was
12113 dwarf_select_sections_by_names (const char *names
)
12121 const debug_dump_long_opts
*entry
;
12123 for (entry
= debug_option_table
; entry
->option
; entry
++)
12125 size_t len
= strlen (entry
->option
);
12127 if (strncmp (p
, entry
->option
, len
) == 0
12128 && (p
[len
] == ',' || p
[len
] == '\0'))
12130 if (entry
->val
== 0)
12131 * entry
->variable
= 0;
12133 * entry
->variable
= entry
->val
;
12134 result
|= entry
->val
;
12141 if (entry
->option
== NULL
)
12143 warn (_("Unrecognized debug option '%s'\n"), p
);
12144 p
= strchr (p
, ',');
12153 /* The --debug-dump=frames-interp option also enables the
12154 --debug-dump=frames option. */
12155 if (do_debug_frames_interp
)
12156 do_debug_frames
= 1;
12161 /* Enable display of specific DWARF sections as determined by the characters
12162 in LETTERS. Returns non-zero if any displaying was enabled. */
12165 dwarf_select_sections_by_letters (const char *letters
)
12171 const debug_dump_long_opts
*entry
;
12173 for (entry
= debug_option_table
; entry
->letter
; entry
++)
12175 if (entry
->letter
== * letters
)
12177 if (entry
->val
== 0)
12178 * entry
->variable
= 0;
12180 * entry
->variable
|= entry
->val
;
12181 result
|= entry
->val
;
12186 if (entry
->letter
== 0)
12187 warn (_("Unrecognized debug letter option '%c'\n"), * letters
);
12192 /* The --debug-dump=frames-interp option also enables the
12193 --debug-dump=frames option. */
12194 if (do_debug_frames_interp
)
12195 do_debug_frames
= 1;
12201 dwarf_select_sections_all (void)
12204 do_debug_abbrevs
= 1;
12205 do_debug_lines
= FLAG_DEBUG_LINES_RAW
;
12206 do_debug_pubnames
= 1;
12207 do_debug_pubtypes
= 1;
12208 do_debug_aranges
= 1;
12209 do_debug_ranges
= 1;
12210 do_debug_frames
= 1;
12211 do_debug_macinfo
= 1;
12216 do_trace_abbrevs
= 1;
12217 do_trace_aranges
= 1;
12219 do_debug_cu_index
= 1;
12220 do_follow_links
= 1;
12221 do_debug_links
= 1;
12222 do_debug_str_offsets
= 1;
12225 #define NO_ABBREVS NULL, NULL, NULL, 0, 0, 0, NULL, 0
12226 #define ABBREV(N) NULL, NULL, NULL, 0, 0, N, NULL, 0
12228 /* N.B. The order here must match the order in section_display_enum. */
12230 struct dwarf_section_display debug_displays
[] =
12232 { { ".debug_abbrev", ".zdebug_abbrev", ".dwabrev", NO_ABBREVS
}, display_debug_abbrev
, &do_debug_abbrevs
, false },
12233 { { ".debug_aranges", ".zdebug_aranges", ".dwarnge", NO_ABBREVS
}, display_debug_aranges
, &do_debug_aranges
, true },
12234 { { ".debug_frame", ".zdebug_frame", ".dwframe", NO_ABBREVS
}, display_debug_frames
, &do_debug_frames
, true },
12235 { { ".debug_info", ".zdebug_info", ".dwinfo", ABBREV (abbrev
)}, display_debug_info
, &do_debug_info
, true },
12236 { { ".debug_line", ".zdebug_line", ".dwline", NO_ABBREVS
}, display_debug_lines
, &do_debug_lines
, true },
12237 { { ".debug_pubnames", ".zdebug_pubnames", ".dwpbnms", NO_ABBREVS
}, display_debug_pubnames
, &do_debug_pubnames
, false },
12238 { { ".debug_gnu_pubnames", ".zdebug_gnu_pubnames", "", NO_ABBREVS
}, display_debug_gnu_pubnames
, &do_debug_pubnames
, false },
12239 { { ".eh_frame", "", "", NO_ABBREVS
}, display_debug_frames
, &do_debug_frames
, true },
12240 { { ".debug_macinfo", ".zdebug_macinfo", "", NO_ABBREVS
}, display_debug_macinfo
, &do_debug_macinfo
, false },
12241 { { ".debug_macro", ".zdebug_macro", ".dwmac", NO_ABBREVS
}, display_debug_macro
, &do_debug_macinfo
, true },
12242 { { ".debug_str", ".zdebug_str", ".dwstr", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, false },
12243 { { ".debug_line_str", ".zdebug_line_str", "", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, false },
12244 { { ".debug_loc", ".zdebug_loc", ".dwloc", NO_ABBREVS
}, display_debug_loc
, &do_debug_loc
, true },
12245 { { ".debug_loclists", ".zdebug_loclists", "", NO_ABBREVS
}, display_debug_loc
, &do_debug_loc
, true },
12246 { { ".debug_loclists.dwo", ".zdebug_loclists.dwo", "", NO_ABBREVS
}, display_debug_loc
, &do_debug_loc
, true },
12247 { { ".debug_pubtypes", ".zdebug_pubtypes", ".dwpbtyp", NO_ABBREVS
}, display_debug_pubnames
, &do_debug_pubtypes
, false },
12248 { { ".debug_gnu_pubtypes", ".zdebug_gnu_pubtypes", "", NO_ABBREVS
}, display_debug_gnu_pubnames
, &do_debug_pubtypes
, false },
12249 { { ".debug_ranges", ".zdebug_ranges", ".dwrnges", NO_ABBREVS
}, display_debug_ranges
, &do_debug_ranges
, true },
12250 { { ".debug_rnglists", ".zdebug_rnglists", "", NO_ABBREVS
}, display_debug_ranges
, &do_debug_ranges
, true },
12251 { { ".debug_rnglists.dwo", ".zdebug_rnglists.dwo", "", NO_ABBREVS
}, display_debug_ranges
, &do_debug_ranges
, true },
12252 { { ".debug_static_func", ".zdebug_static_func", "", NO_ABBREVS
}, display_debug_not_supported
, NULL
, false },
12253 { { ".debug_static_vars", ".zdebug_static_vars", "", NO_ABBREVS
}, display_debug_not_supported
, NULL
, false },
12254 { { ".debug_types", ".zdebug_types", "", ABBREV (abbrev
) }, display_debug_types
, &do_debug_info
, true },
12255 { { ".debug_weaknames", ".zdebug_weaknames", "", NO_ABBREVS
}, display_debug_not_supported
, NULL
, false },
12256 { { ".gdb_index", "", "", NO_ABBREVS
}, display_gdb_index
, &do_gdb_index
, false },
12257 { { ".debug_names", "", "", NO_ABBREVS
}, display_debug_names
, &do_gdb_index
, false },
12258 { { ".trace_info", "", "", ABBREV (trace_abbrev
) }, display_trace_info
, &do_trace_info
, true },
12259 { { ".trace_abbrev", "", "", NO_ABBREVS
}, display_debug_abbrev
, &do_trace_abbrevs
, false },
12260 { { ".trace_aranges", "", "", NO_ABBREVS
}, display_debug_aranges
, &do_trace_aranges
, false },
12261 { { ".debug_info.dwo", ".zdebug_info.dwo", "", ABBREV (abbrev_dwo
) }, display_debug_info
, &do_debug_info
, true },
12262 { { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo", "", NO_ABBREVS
}, display_debug_abbrev
, &do_debug_abbrevs
, false },
12263 { { ".debug_types.dwo", ".zdebug_types.dwo", "", ABBREV (abbrev_dwo
) }, display_debug_types
, &do_debug_info
, true },
12264 { { ".debug_line.dwo", ".zdebug_line.dwo", "", NO_ABBREVS
}, display_debug_lines
, &do_debug_lines
, true },
12265 { { ".debug_loc.dwo", ".zdebug_loc.dwo", "", NO_ABBREVS
}, display_debug_loc
, &do_debug_loc
, true },
12266 { { ".debug_macro.dwo", ".zdebug_macro.dwo", "", NO_ABBREVS
}, display_debug_macro
, &do_debug_macinfo
, true },
12267 { { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo", "", NO_ABBREVS
}, display_debug_macinfo
, &do_debug_macinfo
, false },
12268 { { ".debug_str.dwo", ".zdebug_str.dwo", "", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, true },
12269 { { ".debug_str_offsets", ".zdebug_str_offsets", "", NO_ABBREVS
}, display_debug_str_offsets
, &do_debug_str_offsets
, true },
12270 { { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo", "", NO_ABBREVS
}, display_debug_str_offsets
, &do_debug_str_offsets
, true },
12271 { { ".debug_addr", ".zdebug_addr", "", NO_ABBREVS
}, display_debug_addr
, &do_debug_addr
, true },
12272 { { ".debug_cu_index", "", "", NO_ABBREVS
}, display_cu_index
, &do_debug_cu_index
, false },
12273 { { ".debug_tu_index", "", "", NO_ABBREVS
}, display_cu_index
, &do_debug_cu_index
, false },
12274 { { ".gnu_debuglink", "", "", NO_ABBREVS
}, display_debug_links
, &do_debug_links
, false },
12275 { { ".gnu_debugaltlink", "", "", NO_ABBREVS
}, display_debug_links
, &do_debug_links
, false },
12276 { { ".debug_sup", "", "", NO_ABBREVS
}, display_debug_sup
, &do_debug_links
, false },
12277 /* Separate debug info files can containt their own .debug_str section,
12278 and this might be in *addition* to a .debug_str section already present
12279 in the main file. Hence we need to have two entries for .debug_str. */
12280 { { ".debug_str", ".zdebug_str", "", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, false },
12281 { { ".note.gnu.build-id", "", "", NO_ABBREVS
}, display_debug_not_supported
, NULL
, false },
12284 /* A static assertion. */
12285 extern int debug_displays_assert
[ARRAY_SIZE (debug_displays
) == max
? 1 : -1];