1 /* dwarf.c -- display DWARF contents of a BFD binary file
2 Copyright (C) 2005-2023 Free Software Foundation, Inc.
4 This file is part of GNU Binutils.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
22 #include "libiberty.h"
27 #include "elf/common.h"
30 #include "gdb/gdb-index.h"
31 #include "filenames.h"
32 #include "safe-ctype.h"
35 #ifdef HAVE_LIBDEBUGINFOD
36 #include <elfutils/debuginfod.h>
44 #ifndef ENABLE_CHECKING
45 #define ENABLE_CHECKING 0
50 #define MAX(a, b) ((a) > (b) ? (a) : (b))
51 #define MIN(a, b) ((a) < (b) ? (a) : (b))
53 static const char *regname (unsigned int regno
, int row
);
54 static const char *regname_internal_by_table_only (unsigned int regno
);
56 static int have_frame_base
;
57 static int need_base_address
;
59 static unsigned int num_debug_info_entries
= 0;
60 static unsigned int alloc_num_debug_info_entries
= 0;
61 static debug_info
*debug_information
= NULL
;
62 /* Special value for num_debug_info_entries to indicate
63 that the .debug_info section could not be loaded/parsed. */
64 #define DEBUG_INFO_UNAVAILABLE (unsigned int) -1
66 /* A .debug_info section can contain multiple links to separate
67 DWO object files. We use these structures to record these links. */
75 typedef struct dwo_info
80 struct dwo_info
* next
;
83 static dwo_info
*first_dwo_info
= NULL
;
84 static bool need_dwo_info
;
86 separate_info
* first_separate_info
= NULL
;
88 unsigned int eh_addr_size
;
93 int do_debug_pubnames
;
94 int do_debug_pubtypes
;
98 int do_debug_frames_interp
;
101 int do_debug_str_offsets
;
105 int do_trace_abbrevs
;
106 int do_trace_aranges
;
108 int do_debug_cu_index
;
111 int do_follow_links
= DEFAULT_FOR_FOLLOW_LINKS
;
112 #ifdef HAVE_LIBDEBUGINFOD
113 int use_debuginfod
= 1;
117 int dwarf_cutoff_level
= -1;
118 unsigned long dwarf_start_die
;
122 /* Collection of CU/TU section sets from .debug_cu_index and .debug_tu_index
123 sections. For version 1 package files, each set is stored in SHNDX_POOL
124 as a zero-terminated list of section indexes comprising one set of debug
125 sections from a .dwo file. */
127 static unsigned int *shndx_pool
= NULL
;
128 static unsigned int shndx_pool_size
= 0;
129 static unsigned int shndx_pool_used
= 0;
131 /* For version 2 package files, each set contains an array of section offsets
132 and an array of section sizes, giving the offset and size of the
133 contribution from a CU or TU within one of the debug sections.
134 When displaying debug info from a package file, we need to use these
135 tables to locate the corresponding contributions to each section. */
140 uint64_t section_offsets
[DW_SECT_MAX
];
141 size_t section_sizes
[DW_SECT_MAX
];
144 static int cu_count
= 0;
145 static int tu_count
= 0;
146 static struct cu_tu_set
*cu_sets
= NULL
;
147 static struct cu_tu_set
*tu_sets
= NULL
;
149 static bool load_cu_tu_indexes (void *);
151 /* An array that indicates for a given level of CU nesting whether
152 the latest DW_AT_type seen for that level was a signed type or
154 #define MAX_CU_NESTING (1 << 8)
155 static bool level_type_signed
[MAX_CU_NESTING
];
157 /* Values for do_debug_lines. */
158 #define FLAG_DEBUG_LINES_RAW 1
159 #define FLAG_DEBUG_LINES_DECODED 2
162 size_of_encoded_value (int encoding
)
164 switch (encoding
& 0x7)
167 case 0: return eh_addr_size
;
175 get_encoded_value (unsigned char **pdata
,
177 struct dwarf_section
*section
,
180 unsigned char * data
= * pdata
;
181 unsigned int size
= size_of_encoded_value (encoding
);
184 if (data
>= end
|| size
> (size_t) (end
- data
))
186 warn (_("Encoded value extends past end of section\n"));
191 /* PR 17512: file: 002-829853-0.004. */
194 warn (_("Encoded size of %d is too large to read\n"), size
);
199 /* PR 17512: file: 1085-5603-0.004. */
202 warn (_("Encoded size of 0 is too small to read\n"));
207 if (encoding
& DW_EH_PE_signed
)
208 val
= byte_get_signed (data
, size
);
210 val
= byte_get (data
, size
);
212 if ((encoding
& 0x70) == DW_EH_PE_pcrel
)
213 val
+= section
->address
+ (data
- section
->start
);
215 * pdata
= data
+ size
;
219 /* Print a uint64_t value (typically an address, offset or length) in
220 hexadecimal format, followed by a space. The precision displayed is
221 determined by the NUM_BYTES parameter. */
224 print_hex (uint64_t value
, unsigned num_bytes
)
229 printf ("%0*" PRIx64
" ", num_bytes
* 2,
230 value
& ~(~(uint64_t) 0 << num_bytes
* 4 << num_bytes
* 4));
233 /* Like print_hex, but no trailing space. */
236 print_hex_ns (uint64_t value
, unsigned num_bytes
)
241 printf ("%0*" PRIx64
, num_bytes
* 2,
242 value
& ~(~(uint64_t) 0 << num_bytes
* 4 << num_bytes
* 4));
245 /* Print a view number in hexadecimal value, with the same width as
246 print_hex would have printed it. */
249 print_view (uint64_t value
, unsigned num_bytes
)
254 printf ("v%0*" PRIx64
" ", num_bytes
* 2 - 1,
255 value
& ~(~(uint64_t) 0 << num_bytes
* 4 << num_bytes
* 4));
259 null_name (const char *p
)
266 /* Read in a LEB128 encoded value starting at address DATA.
267 If SIGN is true, return a signed LEB128 value.
268 If LENGTH_RETURN is not NULL, return in it the number of bytes read.
269 If STATUS_RETURN is not NULL, return with bit 0 (LSB) set if the
270 terminating byte was not found and with bit 1 set if the value
271 overflows a uint64_t.
272 No bytes will be read at address END or beyond. */
275 read_leb128 (unsigned char *data
,
276 const unsigned char *const end
,
278 unsigned int *length_return
,
282 unsigned int num_read
= 0;
283 unsigned int shift
= 0;
288 unsigned char byte
= *data
++;
289 unsigned char lost
, mask
;
293 if (shift
< CHAR_BIT
* sizeof (result
))
295 result
|= ((uint64_t) (byte
& 0x7f)) << shift
;
296 /* These bits overflowed. */
297 lost
= byte
^ (result
>> shift
);
298 /* And this is the mask of possible overflow bits. */
299 mask
= 0x7f ^ ((uint64_t) 0x7f << shift
>> shift
);
307 if ((lost
& mask
) != (sign
&& (int64_t) result
< 0 ? mask
: 0))
310 if ((byte
& 0x80) == 0)
313 if (sign
&& shift
< CHAR_BIT
* sizeof (result
) && (byte
& 0x40))
314 result
|= -((uint64_t) 1 << shift
);
319 if (length_return
!= NULL
)
320 *length_return
= num_read
;
321 if (status_return
!= NULL
)
322 *status_return
= status
;
327 /* Read AMOUNT bytes from PTR and store them in VAL.
328 Checks to make sure that the read will not reach or pass END.
329 FUNC chooses whether the value read is unsigned or signed, and may
330 be either byte_get or byte_get_signed. If INC is true, PTR is
331 incremented after reading the value.
332 This macro cannot protect against PTR values derived from user input.
333 The C standard sections 6.5.6 and 6.5.8 say attempts to do so using
334 pointers is undefined behaviour. */
335 #define SAFE_BYTE_GET_INTERNAL(VAL, PTR, AMOUNT, END, FUNC, INC) \
338 size_t amount = (AMOUNT); \
339 if (sizeof (VAL) < amount) \
341 error (ngettext ("internal error: attempt to read %d byte " \
342 "of data in to %d sized variable", \
343 "internal error: attempt to read %d bytes " \
344 "of data in to %d sized variable", \
346 (int) amount, (int) sizeof (VAL)); \
347 amount = sizeof (VAL); \
349 if (ENABLE_CHECKING) \
350 assert ((PTR) <= (END)); \
351 size_t avail = (END) - (PTR); \
354 if (amount > avail) \
359 (VAL) = (FUNC) ((PTR), amount); \
365 #define SAFE_BYTE_GET(VAL, PTR, AMOUNT, END) \
366 SAFE_BYTE_GET_INTERNAL (VAL, PTR, AMOUNT, END, byte_get, false)
368 #define SAFE_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \
369 SAFE_BYTE_GET_INTERNAL (VAL, PTR, AMOUNT, END, byte_get, true)
371 #define SAFE_SIGNED_BYTE_GET(VAL, PTR, AMOUNT, END) \
372 SAFE_BYTE_GET_INTERNAL (VAL, PTR, AMOUNT, END, byte_get_signed, false)
374 #define SAFE_SIGNED_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \
375 SAFE_BYTE_GET_INTERNAL (VAL, PTR, AMOUNT, END, byte_get_signed, true)
377 typedef struct State_Machine_Registers
386 unsigned char op_index
;
387 unsigned char end_sequence
;
388 /* This variable hold the number of the last entry seen
389 in the File Table. */
390 unsigned int last_file_entry
;
393 static SMR state_machine_regs
;
396 reset_state_machine (int is_stmt
)
398 state_machine_regs
.address
= 0;
399 state_machine_regs
.view
= 0;
400 state_machine_regs
.op_index
= 0;
401 state_machine_regs
.file
= 1;
402 state_machine_regs
.line
= 1;
403 state_machine_regs
.column
= 0;
404 state_machine_regs
.is_stmt
= is_stmt
;
405 state_machine_regs
.basic_block
= 0;
406 state_machine_regs
.end_sequence
= 0;
407 state_machine_regs
.last_file_entry
= 0;
410 /* Handled an extend line op.
411 Returns the number of bytes read. */
414 process_extended_line_op (unsigned char * data
,
418 unsigned char op_code
;
419 size_t len
, header_len
;
421 unsigned char *orig_data
= data
;
424 READ_ULEB (len
, data
, end
);
425 header_len
= data
- orig_data
;
427 if (len
== 0 || data
>= end
|| len
> (size_t) (end
- data
))
429 warn (_("Badly formed extended line op encountered!\n"));
435 printf (_(" Extended opcode %d: "), op_code
);
439 case DW_LNE_end_sequence
:
440 printf (_("End of Sequence\n\n"));
441 reset_state_machine (is_stmt
);
444 case DW_LNE_set_address
:
445 /* PR 17512: file: 002-100480-0.004. */
448 warn (_("Length (%zu) of DW_LNE_set_address op is too long\n"),
453 SAFE_BYTE_GET (adr
, data
, len
- 1, end
);
454 printf (_("set Address to %#" PRIx64
"\n"), adr
);
455 state_machine_regs
.address
= adr
;
456 state_machine_regs
.view
= 0;
457 state_machine_regs
.op_index
= 0;
460 case DW_LNE_define_file
:
461 printf (_("define new File Table entry\n"));
462 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
463 printf (" %d\t", ++state_machine_regs
.last_file_entry
);
469 l
= strnlen ((char *) data
, end
- data
);
473 READ_ULEB (val
, data
, end
);
474 printf ("%" PRIu64
"\t", val
);
475 READ_ULEB (val
, data
, end
);
476 printf ("%" PRIu64
"\t", val
);
477 READ_ULEB (val
, data
, end
);
478 printf ("%" PRIu64
"\t", val
);
479 printf ("%.*s\n\n", (int) l
, name
);
482 if (((size_t) (data
- orig_data
) != len
+ header_len
) || data
>= end
)
483 warn (_("DW_LNE_define_file: Bad opcode length\n"));
486 case DW_LNE_set_discriminator
:
487 READ_ULEB (val
, data
, end
);
488 printf (_("set Discriminator to %" PRIu64
"\n"), val
);
492 case DW_LNE_HP_negate_is_UV_update
:
493 printf ("DW_LNE_HP_negate_is_UV_update\n");
495 case DW_LNE_HP_push_context
:
496 printf ("DW_LNE_HP_push_context\n");
498 case DW_LNE_HP_pop_context
:
499 printf ("DW_LNE_HP_pop_context\n");
501 case DW_LNE_HP_set_file_line_column
:
502 printf ("DW_LNE_HP_set_file_line_column\n");
504 case DW_LNE_HP_set_routine_name
:
505 printf ("DW_LNE_HP_set_routine_name\n");
507 case DW_LNE_HP_set_sequence
:
508 printf ("DW_LNE_HP_set_sequence\n");
510 case DW_LNE_HP_negate_post_semantics
:
511 printf ("DW_LNE_HP_negate_post_semantics\n");
513 case DW_LNE_HP_negate_function_exit
:
514 printf ("DW_LNE_HP_negate_function_exit\n");
516 case DW_LNE_HP_negate_front_end_logical
:
517 printf ("DW_LNE_HP_negate_front_end_logical\n");
519 case DW_LNE_HP_define_proc
:
520 printf ("DW_LNE_HP_define_proc\n");
522 case DW_LNE_HP_source_file_correlation
:
524 unsigned char *edata
= data
+ len
- 1;
526 printf ("DW_LNE_HP_source_file_correlation\n");
532 READ_ULEB (opc
, data
, edata
);
536 case DW_LNE_HP_SFC_formfeed
:
537 printf (" DW_LNE_HP_SFC_formfeed\n");
539 case DW_LNE_HP_SFC_set_listing_line
:
540 READ_ULEB (val
, data
, edata
);
541 printf (" DW_LNE_HP_SFC_set_listing_line (%" PRIu64
")\n",
544 case DW_LNE_HP_SFC_associate
:
545 printf (" DW_LNE_HP_SFC_associate ");
546 READ_ULEB (val
, data
, edata
);
547 printf ("(%" PRIu64
, val
);
548 READ_ULEB (val
, data
, edata
);
549 printf (",%" PRIu64
, val
);
550 READ_ULEB (val
, data
, edata
);
551 printf (",%" PRIu64
")\n", val
);
554 printf (_(" UNKNOWN DW_LNE_HP_SFC opcode (%u)\n"), opc
);
564 unsigned int rlen
= len
- 1;
566 if (op_code
>= DW_LNE_lo_user
567 /* The test against DW_LNW_hi_user is redundant due to
568 the limited range of the unsigned char data type used
570 /*&& op_code <= DW_LNE_hi_user*/)
571 printf (_("user defined: "));
573 printf (_("UNKNOWN: "));
574 printf (_("length %d ["), rlen
);
576 printf (" %02x", *data
++);
582 return len
+ header_len
;
585 static const unsigned char *
586 fetch_indirect_string (uint64_t offset
)
588 struct dwarf_section
*section
= &debug_displays
[str
].section
;
589 const unsigned char * ret
;
591 if (section
->start
== NULL
)
592 return (const unsigned char *) _("<no .debug_str section>");
594 if (offset
>= section
->size
)
596 warn (_("DW_FORM_strp offset too big: %#" PRIx64
"\n"), offset
);
597 return (const unsigned char *) _("<offset is too big>");
600 ret
= section
->start
+ offset
;
601 /* Unfortunately we cannot rely upon the .debug_str section ending with a
602 NUL byte. Since our caller is expecting to receive a well formed C
603 string we test for the lack of a terminating byte here. */
604 if (strnlen ((const char *) ret
, section
->size
- offset
)
605 == section
->size
- offset
)
606 ret
= (const unsigned char *)
607 _("<no NUL byte at end of .debug_str section>");
612 static const unsigned char *
613 fetch_indirect_line_string (uint64_t offset
)
615 struct dwarf_section
*section
= &debug_displays
[line_str
].section
;
616 const unsigned char * ret
;
618 if (section
->start
== NULL
)
619 return (const unsigned char *) _("<no .debug_line_str section>");
621 if (offset
>= section
->size
)
623 warn (_("DW_FORM_line_strp offset too big: %#" PRIx64
"\n"), offset
);
624 return (const unsigned char *) _("<offset is too big>");
627 ret
= section
->start
+ offset
;
628 /* Unfortunately we cannot rely upon the .debug_line_str section ending
629 with a NUL byte. Since our caller is expecting to receive a well formed
630 C string we test for the lack of a terminating byte here. */
631 if (strnlen ((const char *) ret
, section
->size
- offset
)
632 == section
->size
- offset
)
633 ret
= (const unsigned char *)
634 _("<no NUL byte at end of .debug_line_str section>");
640 fetch_indexed_string (uint64_t idx
,
641 struct cu_tu_set
*this_set
,
642 uint64_t offset_size
,
644 uint64_t str_offsets_base
)
646 enum dwarf_section_display_enum str_sec_idx
= dwo
? str_dwo
: str
;
647 enum dwarf_section_display_enum idx_sec_idx
= dwo
? str_index_dwo
: str_index
;
648 struct dwarf_section
*index_section
= &debug_displays
[idx_sec_idx
].section
;
649 struct dwarf_section
*str_section
= &debug_displays
[str_sec_idx
].section
;
650 uint64_t index_offset
;
654 if (index_section
->start
== NULL
)
655 return (dwo
? _("<no .debug_str_offsets.dwo section>")
656 : _("<no .debug_str_offsets section>"));
658 if (str_section
->start
== NULL
)
659 return (dwo
? _("<no .debug_str.dwo section>")
660 : _("<no .debug_str section>"));
662 index_offset
= idx
* offset_size
;
664 if (this_set
!= NULL
)
665 index_offset
+= this_set
->section_offsets
[DW_SECT_STR_OFFSETS
];
667 index_offset
+= str_offsets_base
;
669 if (index_offset
+ offset_size
> index_section
->size
)
671 warn (_("string index of %" PRIu64
" converts to an offset of %#" PRIx64
672 " which is too big for section %s"),
673 idx
, index_offset
, str_section
->name
);
675 return _("<string index too big>");
678 /* FIXME: If we are being paranoid then we should also check to see if
679 IDX references an entry beyond the end of the string table pointed to
680 by STR_OFFSETS_BASE. (Since there can be more than one string table
681 in a DWARF string section). */
683 str_offset
= byte_get (index_section
->start
+ index_offset
, offset_size
);
685 str_offset
-= str_section
->address
;
686 if (str_offset
>= str_section
->size
)
688 warn (_("indirect offset too big: %#" PRIx64
"\n"), str_offset
);
689 return _("<indirect index offset is too big>");
692 ret
= (const char *) str_section
->start
+ str_offset
;
694 /* Unfortunately we cannot rely upon str_section ending with a NUL byte.
695 Since our caller is expecting to receive a well formed C string we test
696 for the lack of a terminating byte here. */
697 if (strnlen (ret
, str_section
->size
- str_offset
)
698 == str_section
->size
- str_offset
)
699 return _("<no NUL byte at end of section>");
705 fetch_indexed_addr (uint64_t offset
, uint32_t num_bytes
)
707 struct dwarf_section
*section
= &debug_displays
[debug_addr
].section
;
709 if (section
->start
== NULL
)
711 warn (_("Cannot fetch indexed address: the .debug_addr section is missing\n"));
715 if (offset
+ num_bytes
> section
->size
)
717 warn (_("Offset into section %s too big: %#" PRIx64
"\n"),
718 section
->name
, offset
);
722 return byte_get (section
->start
+ offset
, num_bytes
);
725 /* Fetch a value from a debug section that has been indexed by
726 something in another section (eg DW_FORM_loclistx or DW_FORM_rnglistx).
727 Returns -1 if the value could not be found. */
730 fetch_indexed_value (uint64_t idx
,
731 enum dwarf_section_display_enum sec_enum
,
732 uint64_t base_address
)
734 struct dwarf_section
*section
= &debug_displays
[sec_enum
].section
;
736 if (section
->start
== NULL
)
738 warn (_("Unable to locate %s section\n"), section
->uncompressed_name
);
742 if (section
->size
< 4)
744 warn (_("Section %s is too small to contain an value indexed from another section!\n"),
749 uint32_t pointer_size
, bias
;
751 if (byte_get (section
->start
, 4) == 0xffffffff)
762 uint64_t offset
= idx
* pointer_size
;
764 /* Offsets are biased by the size of the section header
767 offset
+= base_address
;
771 if (offset
+ pointer_size
> section
->size
)
773 warn (_("Offset into section %s too big: %#" PRIx64
"\n"),
774 section
->name
, offset
);
778 return byte_get (section
->start
+ offset
, pointer_size
);
781 /* FIXME: There are better and more efficient ways to handle
782 these structures. For now though, I just want something that
783 is simple to implement. */
784 /* Records a single attribute in an abbrev. */
785 typedef struct abbrev_attr
787 unsigned long attribute
;
789 int64_t implicit_const
;
790 struct abbrev_attr
*next
;
794 /* Records a single abbrev. */
795 typedef struct abbrev_entry
797 unsigned long number
;
800 struct abbrev_attr
* first_attr
;
801 struct abbrev_attr
* last_attr
;
802 struct abbrev_entry
* next
;
806 /* Records a set of abbreviations. */
807 typedef struct abbrev_list
809 abbrev_entry
* first_abbrev
;
810 abbrev_entry
* last_abbrev
;
812 struct abbrev_list
* next
;
813 unsigned char * start_of_next_abbrevs
;
817 /* Records all the abbrevs found so far. */
818 static struct abbrev_list
* abbrev_lists
= NULL
;
820 typedef struct abbrev_map
827 /* Maps between CU offsets and abbrev sets. */
828 static abbrev_map
* cu_abbrev_map
= NULL
;
829 static unsigned long num_abbrev_map_entries
= 0;
830 static unsigned long next_free_abbrev_map_entry
= 0;
832 #define INITIAL_NUM_ABBREV_MAP_ENTRIES 8
833 #define ABBREV_MAP_ENTRIES_INCREMENT 8
836 record_abbrev_list_for_cu (uint64_t start
, uint64_t end
,
837 abbrev_list
*list
, abbrev_list
*free_list
)
839 if (free_list
!= NULL
)
841 list
->next
= abbrev_lists
;
845 if (cu_abbrev_map
== NULL
)
847 num_abbrev_map_entries
= INITIAL_NUM_ABBREV_MAP_ENTRIES
;
848 cu_abbrev_map
= xmalloc (num_abbrev_map_entries
* sizeof (* cu_abbrev_map
));
850 else if (next_free_abbrev_map_entry
== num_abbrev_map_entries
)
852 num_abbrev_map_entries
+= ABBREV_MAP_ENTRIES_INCREMENT
;
853 cu_abbrev_map
= xrealloc (cu_abbrev_map
, num_abbrev_map_entries
* sizeof (* cu_abbrev_map
));
856 cu_abbrev_map
[next_free_abbrev_map_entry
].start
= start
;
857 cu_abbrev_map
[next_free_abbrev_map_entry
].end
= end
;
858 cu_abbrev_map
[next_free_abbrev_map_entry
].list
= list
;
859 next_free_abbrev_map_entry
++;
863 free_abbrev_list (abbrev_list
*list
)
865 abbrev_entry
*abbrv
= list
->first_abbrev
;
869 abbrev_attr
*attr
= abbrv
->first_attr
;
873 abbrev_attr
*next_attr
= attr
->next
;
878 abbrev_entry
*next_abbrev
= abbrv
->next
;
883 abbrev_list
*next
= list
->next
;
889 free_all_abbrevs (void)
892 abbrev_lists
= free_abbrev_list (abbrev_lists
);
894 free (cu_abbrev_map
);
895 cu_abbrev_map
= NULL
;
896 next_free_abbrev_map_entry
= 0;
900 find_abbrev_list_by_raw_abbrev (unsigned char *raw
)
904 for (list
= abbrev_lists
; list
!= NULL
; list
= list
->next
)
905 if (list
->raw
== raw
)
911 /* Find the abbreviation map for the CU that includes OFFSET.
912 OFFSET is an absolute offset from the start of the .debug_info section. */
913 /* FIXME: This function is going to slow down readelf & objdump.
914 Not caching abbrevs is likely the answer. */
917 find_abbrev_map_by_offset (uint64_t offset
)
921 for (i
= 0; i
< next_free_abbrev_map_entry
; i
++)
922 if (cu_abbrev_map
[i
].start
<= offset
923 && cu_abbrev_map
[i
].end
> offset
)
924 return cu_abbrev_map
+ i
;
930 add_abbrev (unsigned long number
,
935 abbrev_entry
* entry
;
937 entry
= (abbrev_entry
*) xmalloc (sizeof (*entry
));
939 entry
->number
= number
;
941 entry
->children
= children
;
942 entry
->first_attr
= NULL
;
943 entry
->last_attr
= NULL
;
946 assert (list
!= NULL
);
948 if (list
->first_abbrev
== NULL
)
949 list
->first_abbrev
= entry
;
951 list
->last_abbrev
->next
= entry
;
953 list
->last_abbrev
= entry
;
957 add_abbrev_attr (unsigned long attribute
,
959 int64_t implicit_const
,
964 attr
= (abbrev_attr
*) xmalloc (sizeof (*attr
));
966 attr
->attribute
= attribute
;
968 attr
->implicit_const
= implicit_const
;
971 assert (list
!= NULL
&& list
->last_abbrev
!= NULL
);
973 if (list
->last_abbrev
->first_attr
== NULL
)
974 list
->last_abbrev
->first_attr
= attr
;
976 list
->last_abbrev
->last_attr
->next
= attr
;
978 list
->last_abbrev
->last_attr
= attr
;
981 /* Return processed (partial) contents of a .debug_abbrev section.
982 Returns NULL on errors. */
985 process_abbrev_set (struct dwarf_section
*section
,
986 unsigned char *start
,
989 abbrev_list
*list
= xmalloc (sizeof (*list
));
990 list
->first_abbrev
= NULL
;
991 list
->last_abbrev
= NULL
;
999 unsigned long attribute
;
1002 READ_ULEB (entry
, start
, end
);
1004 /* A single zero is supposed to end the set according
1005 to the standard. If there's more, then signal that to
1007 if (start
== end
|| entry
== 0)
1009 list
->start_of_next_abbrevs
= start
!= end
? start
: NULL
;
1013 READ_ULEB (tag
, start
, end
);
1015 return free_abbrev_list (list
);
1017 children
= *start
++;
1019 add_abbrev (entry
, tag
, children
, list
);
1024 /* Initialize it due to a false compiler warning. */
1025 int64_t implicit_const
= -1;
1027 READ_ULEB (attribute
, start
, end
);
1031 READ_ULEB (form
, start
, end
);
1035 if (form
== DW_FORM_implicit_const
)
1037 READ_SLEB (implicit_const
, start
, end
);
1042 add_abbrev_attr (attribute
, form
, implicit_const
, list
);
1044 while (attribute
!= 0);
1047 /* Report the missing single zero which ends the section. */
1048 error (_("%s section not zero terminated\n"), section
->name
);
1050 return free_abbrev_list (list
);
1053 /* Return a sequence of abbrevs in SECTION starting at ABBREV_BASE
1054 plus ABBREV_OFFSET and finishing at ABBREV_BASE + ABBREV_SIZE.
1055 If FREE_LIST is non-NULL search the already decoded abbrevs on
1056 abbrev_lists first and if found set *FREE_LIST to NULL. If
1057 searching doesn't find a matching abbrev, set *FREE_LIST to the
1058 newly allocated list. If FREE_LIST is NULL, no search is done and
1059 the returned abbrev_list is always newly allocated. */
1061 static abbrev_list
*
1062 find_and_process_abbrev_set (struct dwarf_section
*section
,
1063 uint64_t abbrev_base
,
1064 uint64_t abbrev_size
,
1065 uint64_t abbrev_offset
,
1066 abbrev_list
**free_list
)
1071 if (abbrev_base
>= section
->size
1072 || abbrev_size
> section
->size
- abbrev_base
)
1074 /* PR 17531: file:4bcd9ce9. */
1075 warn (_("Debug info is corrupted, abbrev size (%#" PRIx64
")"
1076 " is larger than abbrev section size (%#" PRIx64
")\n"),
1077 abbrev_base
+ abbrev_size
, section
->size
);
1080 if (abbrev_offset
>= abbrev_size
)
1082 warn (_("Debug info is corrupted, abbrev offset (%#" PRIx64
")"
1083 " is larger than abbrev section size (%#" PRIx64
")\n"),
1084 abbrev_offset
, abbrev_size
);
1088 unsigned char *start
= section
->start
+ abbrev_base
+ abbrev_offset
;
1089 unsigned char *end
= section
->start
+ abbrev_base
+ abbrev_size
;
1090 abbrev_list
*list
= NULL
;
1092 list
= find_abbrev_list_by_raw_abbrev (start
);
1095 list
= process_abbrev_set (section
, start
, end
);
1103 get_TAG_name (uint64_t tag
)
1105 const char *name
= NULL
;
1107 if ((unsigned int) tag
== tag
)
1108 name
= get_DW_TAG_name ((unsigned int) tag
);
1111 static char buffer
[100];
1113 if (tag
>= DW_TAG_lo_user
&& tag
<= DW_TAG_hi_user
)
1114 snprintf (buffer
, sizeof (buffer
),
1115 _("User TAG value: %#" PRIx64
), tag
);
1117 snprintf (buffer
, sizeof (buffer
),
1118 _("Unknown TAG value: %#" PRIx64
), tag
);
1126 get_FORM_name (unsigned long form
)
1128 const char *name
= NULL
;
1131 return "DW_FORM value: 0";
1133 if ((unsigned int) form
== form
)
1134 name
= get_DW_FORM_name ((unsigned int) form
);
1137 static char buffer
[100];
1139 snprintf (buffer
, sizeof (buffer
), _("Unknown FORM value: %lx"), form
);
1147 get_IDX_name (unsigned long idx
)
1149 const char *name
= NULL
;
1151 if ((unsigned int) idx
== idx
)
1152 name
= get_DW_IDX_name ((unsigned int) idx
);
1155 static char buffer
[100];
1157 snprintf (buffer
, sizeof (buffer
), _("Unknown IDX value: %lx"), idx
);
1164 static unsigned char *
1165 display_block (unsigned char *data
,
1167 const unsigned char * const end
, char delimiter
)
1171 printf (_("%c%" PRIu64
" byte block: "), delimiter
, length
);
1173 return (unsigned char *) end
;
1175 maxlen
= end
- data
;
1176 length
= length
> maxlen
? maxlen
: length
;
1179 printf ("%" PRIx64
" ", byte_get (data
++, 1));
1185 decode_location_expression (unsigned char * data
,
1186 unsigned int pointer_size
,
1187 unsigned int offset_size
,
1191 struct dwarf_section
* section
)
1196 unsigned char *end
= data
+ length
;
1197 int need_frame_base
= 0;
1206 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1207 printf ("DW_OP_addr: %" PRIx64
, uvalue
);
1210 printf ("DW_OP_deref");
1213 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1214 printf ("DW_OP_const1u: %" PRIu64
, uvalue
);
1217 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 1, end
);
1218 printf ("DW_OP_const1s: %" PRId64
, svalue
);
1221 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
1222 printf ("DW_OP_const2u: %" PRIu64
, uvalue
);
1225 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1226 printf ("DW_OP_const2s: %" PRId64
, svalue
);
1229 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1230 printf ("DW_OP_const4u: %" PRIu64
, uvalue
);
1233 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
1234 printf ("DW_OP_const4s: %" PRId64
, svalue
);
1237 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 8, end
);
1238 printf ("DW_OP_const8u: %" PRIu64
, uvalue
);
1241 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 8, end
);
1242 printf ("DW_OP_const8s: %" PRId64
, svalue
);
1245 READ_ULEB (uvalue
, data
, end
);
1246 printf ("DW_OP_constu: %" PRIu64
, uvalue
);
1249 READ_SLEB (svalue
, data
, end
);
1250 printf ("DW_OP_consts: %" PRId64
, svalue
);
1253 printf ("DW_OP_dup");
1256 printf ("DW_OP_drop");
1259 printf ("DW_OP_over");
1262 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1263 printf ("DW_OP_pick: %" PRIu64
, uvalue
);
1266 printf ("DW_OP_swap");
1269 printf ("DW_OP_rot");
1272 printf ("DW_OP_xderef");
1275 printf ("DW_OP_abs");
1278 printf ("DW_OP_and");
1281 printf ("DW_OP_div");
1284 printf ("DW_OP_minus");
1287 printf ("DW_OP_mod");
1290 printf ("DW_OP_mul");
1293 printf ("DW_OP_neg");
1296 printf ("DW_OP_not");
1299 printf ("DW_OP_or");
1302 printf ("DW_OP_plus");
1304 case DW_OP_plus_uconst
:
1305 READ_ULEB (uvalue
, data
, end
);
1306 printf ("DW_OP_plus_uconst: %" PRIu64
, uvalue
);
1309 printf ("DW_OP_shl");
1312 printf ("DW_OP_shr");
1315 printf ("DW_OP_shra");
1318 printf ("DW_OP_xor");
1321 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1322 printf ("DW_OP_bra: %" PRId64
, svalue
);
1325 printf ("DW_OP_eq");
1328 printf ("DW_OP_ge");
1331 printf ("DW_OP_gt");
1334 printf ("DW_OP_le");
1337 printf ("DW_OP_lt");
1340 printf ("DW_OP_ne");
1343 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1344 printf ("DW_OP_skip: %" PRId64
, svalue
);
1379 printf ("DW_OP_lit%d", op
- DW_OP_lit0
);
1414 printf ("DW_OP_reg%d (%s)", op
- DW_OP_reg0
,
1415 regname (op
- DW_OP_reg0
, 1));
1450 READ_SLEB (svalue
, data
, end
);
1451 printf ("DW_OP_breg%d (%s): %" PRId64
,
1452 op
- DW_OP_breg0
, regname (op
- DW_OP_breg0
, 1), svalue
);
1456 READ_ULEB (uvalue
, data
, end
);
1457 printf ("DW_OP_regx: %" PRIu64
" (%s)",
1458 uvalue
, regname (uvalue
, 1));
1461 need_frame_base
= 1;
1462 READ_SLEB (svalue
, data
, end
);
1463 printf ("DW_OP_fbreg: %" PRId64
, svalue
);
1466 READ_ULEB (uvalue
, data
, end
);
1467 READ_SLEB (svalue
, data
, end
);
1468 printf ("DW_OP_bregx: %" PRIu64
" (%s) %" PRId64
,
1469 uvalue
, regname (uvalue
, 1), svalue
);
1472 READ_ULEB (uvalue
, data
, end
);
1473 printf ("DW_OP_piece: %" PRIu64
, uvalue
);
1475 case DW_OP_deref_size
:
1476 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1477 printf ("DW_OP_deref_size: %" PRIu64
, uvalue
);
1479 case DW_OP_xderef_size
:
1480 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1481 printf ("DW_OP_xderef_size: %" PRIu64
, uvalue
);
1484 printf ("DW_OP_nop");
1487 /* DWARF 3 extensions. */
1488 case DW_OP_push_object_address
:
1489 printf ("DW_OP_push_object_address");
1492 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1493 this ought to be an 8-byte wide computation. */
1494 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1495 printf ("DW_OP_call2: <%#" PRIx64
">", svalue
+ cu_offset
);
1498 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1499 this ought to be an 8-byte wide computation. */
1500 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
1501 printf ("DW_OP_call4: <%#" PRIx64
">", svalue
+ cu_offset
);
1503 case DW_OP_call_ref
:
1504 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1505 this ought to be an 8-byte wide computation. */
1506 if (dwarf_version
== -1)
1508 printf (_("(DW_OP_call_ref in frame info)"));
1509 /* No way to tell where the next op is, so just bail. */
1510 return need_frame_base
;
1512 if (dwarf_version
== 2)
1514 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1518 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1520 printf ("DW_OP_call_ref: <%#" PRIx64
">", uvalue
);
1522 case DW_OP_form_tls_address
:
1523 printf ("DW_OP_form_tls_address");
1525 case DW_OP_call_frame_cfa
:
1526 printf ("DW_OP_call_frame_cfa");
1528 case DW_OP_bit_piece
:
1529 printf ("DW_OP_bit_piece: ");
1530 READ_ULEB (uvalue
, data
, end
);
1531 printf (_("size: %" PRIu64
" "), uvalue
);
1532 READ_ULEB (uvalue
, data
, end
);
1533 printf (_("offset: %" PRIu64
" "), uvalue
);
1536 /* DWARF 4 extensions. */
1537 case DW_OP_stack_value
:
1538 printf ("DW_OP_stack_value");
1541 case DW_OP_implicit_value
:
1542 printf ("DW_OP_implicit_value");
1543 READ_ULEB (uvalue
, data
, end
);
1544 data
= display_block (data
, uvalue
, end
, ' ');
1547 /* GNU extensions. */
1548 case DW_OP_GNU_push_tls_address
:
1549 printf (_("DW_OP_GNU_push_tls_address or DW_OP_HP_unknown"));
1551 case DW_OP_GNU_uninit
:
1552 printf ("DW_OP_GNU_uninit");
1553 /* FIXME: Is there data associated with this OP ? */
1555 case DW_OP_GNU_encoded_addr
:
1562 addr
= get_encoded_value (&data
, encoding
, section
, end
);
1564 printf ("DW_OP_GNU_encoded_addr: fmt:%02x addr:", encoding
);
1565 print_hex_ns (addr
, pointer_size
);
1568 case DW_OP_implicit_pointer
:
1569 case DW_OP_GNU_implicit_pointer
:
1570 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1571 this ought to be an 8-byte wide computation. */
1572 if (dwarf_version
== -1)
1574 printf (_("(%s in frame info)"),
1575 (op
== DW_OP_implicit_pointer
1576 ? "DW_OP_implicit_pointer"
1577 : "DW_OP_GNU_implicit_pointer"));
1578 /* No way to tell where the next op is, so just bail. */
1579 return need_frame_base
;
1581 if (dwarf_version
== 2)
1583 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1587 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1589 READ_SLEB (svalue
, data
, end
);
1590 printf ("%s: <%#" PRIx64
"> %" PRId64
,
1591 (op
== DW_OP_implicit_pointer
1592 ? "DW_OP_implicit_pointer" : "DW_OP_GNU_implicit_pointer"),
1595 case DW_OP_entry_value
:
1596 case DW_OP_GNU_entry_value
:
1597 READ_ULEB (uvalue
, data
, end
);
1598 /* PR 17531: file: 0cc9cd00. */
1599 if (uvalue
> (size_t) (end
- data
))
1600 uvalue
= end
- data
;
1601 printf ("%s: (", (op
== DW_OP_entry_value
? "DW_OP_entry_value"
1602 : "DW_OP_GNU_entry_value"));
1603 if (decode_location_expression (data
, pointer_size
, offset_size
,
1604 dwarf_version
, uvalue
,
1605 cu_offset
, section
))
1606 need_frame_base
= 1;
1610 case DW_OP_const_type
:
1611 case DW_OP_GNU_const_type
:
1612 READ_ULEB (uvalue
, data
, end
);
1613 printf ("%s: <%#" PRIx64
"> ",
1614 (op
== DW_OP_const_type
? "DW_OP_const_type"
1615 : "DW_OP_GNU_const_type"),
1616 cu_offset
+ uvalue
);
1617 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1618 data
= display_block (data
, uvalue
, end
, ' ');
1620 case DW_OP_regval_type
:
1621 case DW_OP_GNU_regval_type
:
1622 READ_ULEB (uvalue
, data
, end
);
1623 printf ("%s: %" PRIu64
" (%s)",
1624 (op
== DW_OP_regval_type
? "DW_OP_regval_type"
1625 : "DW_OP_GNU_regval_type"),
1626 uvalue
, regname (uvalue
, 1));
1627 READ_ULEB (uvalue
, data
, end
);
1628 printf (" <%#" PRIx64
">", cu_offset
+ uvalue
);
1630 case DW_OP_deref_type
:
1631 case DW_OP_GNU_deref_type
:
1632 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1633 printf ("%s: %" PRId64
,
1634 (op
== DW_OP_deref_type
? "DW_OP_deref_type"
1635 : "DW_OP_GNU_deref_type"),
1637 READ_ULEB (uvalue
, data
, end
);
1638 printf (" <%#" PRIx64
">", cu_offset
+ uvalue
);
1641 case DW_OP_GNU_convert
:
1642 READ_ULEB (uvalue
, data
, end
);
1643 printf ("%s <%#" PRIx64
">",
1644 (op
== DW_OP_convert
? "DW_OP_convert" : "DW_OP_GNU_convert"),
1645 uvalue
? cu_offset
+ uvalue
: uvalue
);
1647 case DW_OP_reinterpret
:
1648 case DW_OP_GNU_reinterpret
:
1649 READ_ULEB (uvalue
, data
, end
);
1650 printf ("%s <%#" PRIx64
">",
1651 (op
== DW_OP_reinterpret
? "DW_OP_reinterpret"
1652 : "DW_OP_GNU_reinterpret"),
1653 uvalue
? cu_offset
+ uvalue
: uvalue
);
1655 case DW_OP_GNU_parameter_ref
:
1656 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1657 printf ("DW_OP_GNU_parameter_ref: <%#" PRIx64
">",
1658 cu_offset
+ uvalue
);
1661 READ_ULEB (uvalue
, data
, end
);
1662 printf ("DW_OP_addrx <%#" PRIx64
">", uvalue
);
1664 case DW_OP_GNU_addr_index
:
1665 READ_ULEB (uvalue
, data
, end
);
1666 printf ("DW_OP_GNU_addr_index <%#" PRIx64
">", uvalue
);
1668 case DW_OP_GNU_const_index
:
1669 READ_ULEB (uvalue
, data
, end
);
1670 printf ("DW_OP_GNU_const_index <%#" PRIx64
">", uvalue
);
1672 case DW_OP_GNU_variable_value
:
1673 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1674 this ought to be an 8-byte wide computation. */
1675 if (dwarf_version
== -1)
1677 printf (_("(DW_OP_GNU_variable_value in frame info)"));
1678 /* No way to tell where the next op is, so just bail. */
1679 return need_frame_base
;
1681 if (dwarf_version
== 2)
1683 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1687 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1689 printf ("DW_OP_GNU_variable_value: <%#" PRIx64
">", uvalue
);
1692 /* HP extensions. */
1693 case DW_OP_HP_is_value
:
1694 printf ("DW_OP_HP_is_value");
1695 /* FIXME: Is there data associated with this OP ? */
1697 case DW_OP_HP_fltconst4
:
1698 printf ("DW_OP_HP_fltconst4");
1699 /* FIXME: Is there data associated with this OP ? */
1701 case DW_OP_HP_fltconst8
:
1702 printf ("DW_OP_HP_fltconst8");
1703 /* FIXME: Is there data associated with this OP ? */
1705 case DW_OP_HP_mod_range
:
1706 printf ("DW_OP_HP_mod_range");
1707 /* FIXME: Is there data associated with this OP ? */
1709 case DW_OP_HP_unmod_range
:
1710 printf ("DW_OP_HP_unmod_range");
1711 /* FIXME: Is there data associated with this OP ? */
1714 printf ("DW_OP_HP_tls");
1715 /* FIXME: Is there data associated with this OP ? */
1718 /* PGI (STMicroelectronics) extensions. */
1719 case DW_OP_PGI_omp_thread_num
:
1720 /* Pushes the thread number for the current thread as it would be
1721 returned by the standard OpenMP library function:
1722 omp_get_thread_num(). The "current thread" is the thread for
1723 which the expression is being evaluated. */
1724 printf ("DW_OP_PGI_omp_thread_num");
1728 if (op
>= DW_OP_lo_user
1729 && op
<= DW_OP_hi_user
)
1730 printf (_("(User defined location op %#x)"), op
);
1732 printf (_("(Unknown location op %#x)"), op
);
1733 /* No way to tell where the next op is, so just bail. */
1734 return need_frame_base
;
1737 /* Separate the ops. */
1742 return need_frame_base
;
1745 /* Find the CU or TU set corresponding to the given CU_OFFSET.
1746 This is used for DWARF package files. */
1748 static struct cu_tu_set
*
1749 find_cu_tu_set_v2 (uint64_t cu_offset
, int do_types
)
1751 struct cu_tu_set
*p
;
1753 unsigned int dw_sect
;
1759 dw_sect
= DW_SECT_TYPES
;
1765 dw_sect
= DW_SECT_INFO
;
1769 if (p
->section_offsets
[dw_sect
] == cu_offset
)
1778 fetch_alt_indirect_string (uint64_t offset
)
1782 if (! do_follow_links
)
1785 if (first_separate_info
== NULL
)
1786 return _("<no links available>");
1788 for (i
= first_separate_info
; i
!= NULL
; i
= i
->next
)
1790 struct dwarf_section
* section
;
1793 if (! load_debug_section (separate_debug_str
, i
->handle
))
1796 section
= &debug_displays
[separate_debug_str
].section
;
1798 if (section
->start
== NULL
)
1801 if (offset
>= section
->size
)
1804 ret
= (const char *) (section
->start
+ offset
);
1805 /* Unfortunately we cannot rely upon the .debug_str section ending with a
1806 NUL byte. Since our caller is expecting to receive a well formed C
1807 string we test for the lack of a terminating byte here. */
1808 if (strnlen ((const char *) ret
, section
->size
- offset
)
1809 == section
->size
- offset
)
1810 return _("<no NUL byte at end of alt .debug_str section>");
1815 warn (_("DW_FORM_GNU_strp_alt offset (%#" PRIx64
")"
1816 " too big or no string sections available\n"), offset
);
1817 return _("<offset is too big>");
1821 get_AT_name (unsigned long attribute
)
1826 return "DW_AT value: 0";
1828 /* One value is shared by the MIPS and HP extensions: */
1829 if (attribute
== DW_AT_MIPS_fde
)
1830 return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable";
1832 name
= get_DW_AT_name (attribute
);
1836 static char buffer
[100];
1838 snprintf (buffer
, sizeof (buffer
), _("Unknown AT value: %lx"),
1847 add_dwo_info (const char * value
, uint64_t cu_offset
, dwo_type type
)
1849 dwo_info
* dwinfo
= xmalloc (sizeof * dwinfo
);
1851 dwinfo
->type
= type
;
1852 dwinfo
->value
= value
;
1853 dwinfo
->cu_offset
= cu_offset
;
1854 dwinfo
->next
= first_dwo_info
;
1855 first_dwo_info
= dwinfo
;
1859 add_dwo_name (const char * name
, uint64_t cu_offset
)
1861 add_dwo_info (name
, cu_offset
, DWO_NAME
);
1865 add_dwo_dir (const char * dir
, uint64_t cu_offset
)
1867 add_dwo_info (dir
, cu_offset
, DWO_DIR
);
1871 add_dwo_id (const char * id
, uint64_t cu_offset
)
1873 add_dwo_info (id
, cu_offset
, DWO_ID
);
1877 free_dwo_info (void)
1882 for (dwinfo
= first_dwo_info
; dwinfo
!= NULL
; dwinfo
= next
)
1884 next
= dwinfo
->next
;
1887 first_dwo_info
= NULL
;
1890 /* Ensure that START + UVALUE is less than END.
1891 Return an adjusted UVALUE if necessary to ensure this relationship. */
1893 static inline uint64_t
1894 check_uvalue (const unsigned char *start
,
1896 const unsigned char *end
)
1898 uint64_t max_uvalue
= end
- start
;
1900 /* See PR 17512: file: 008-103549-0.001:0.1.
1901 and PR 24829 for examples of where these tests are triggered. */
1902 if (uvalue
> max_uvalue
)
1904 warn (_("Corrupt attribute block length: %#" PRIx64
"\n"), uvalue
);
1905 uvalue
= max_uvalue
;
1911 static unsigned char *
1912 skip_attr_bytes (unsigned long form
,
1913 unsigned char *data
,
1915 uint64_t pointer_size
,
1916 uint64_t offset_size
,
1918 uint64_t *value_return
)
1921 uint64_t uvalue
= 0;
1928 case DW_FORM_ref_addr
:
1929 if (dwarf_version
== 2)
1930 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1931 else if (dwarf_version
> 2)
1932 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1938 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1942 case DW_FORM_line_strp
:
1943 case DW_FORM_sec_offset
:
1944 case DW_FORM_GNU_ref_alt
:
1945 case DW_FORM_GNU_strp_alt
:
1946 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1949 case DW_FORM_flag_present
:
1957 case DW_FORM_addrx1
:
1958 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1962 case DW_FORM_addrx3
:
1963 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 3, end
);
1969 case DW_FORM_addrx2
:
1970 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
1976 case DW_FORM_addrx4
:
1977 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1981 READ_SLEB (svalue
, data
, end
);
1985 case DW_FORM_ref_udata
:
1987 case DW_FORM_GNU_str_index
:
1989 case DW_FORM_GNU_addr_index
:
1991 case DW_FORM_loclistx
:
1992 case DW_FORM_rnglistx
:
1993 READ_ULEB (uvalue
, data
, end
);
1997 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 8, end
);
2001 case DW_FORM_ref_sig8
:
2005 case DW_FORM_data16
:
2009 case DW_FORM_string
:
2010 inc
= strnlen ((char *) data
, end
- data
) + 1;
2014 case DW_FORM_exprloc
:
2015 READ_ULEB (uvalue
, data
, end
);
2019 case DW_FORM_block1
:
2020 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
2024 case DW_FORM_block2
:
2025 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
2029 case DW_FORM_block4
:
2030 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
2034 case DW_FORM_indirect
:
2035 READ_ULEB (form
, data
, end
);
2036 if (form
== DW_FORM_implicit_const
)
2037 SKIP_ULEB (data
, end
);
2038 return skip_attr_bytes (form
, data
, end
, pointer_size
, offset_size
,
2039 dwarf_version
, value_return
);
2045 * value_return
= uvalue
;
2046 if (inc
<= (size_t) (end
- data
))
2053 /* Given form FORM with value UVALUE, locate and return the abbreviation
2054 associated with it. */
2056 static abbrev_entry
*
2057 get_type_abbrev_from_form (unsigned long form
,
2058 unsigned long uvalue
,
2060 unsigned char *cu_end
,
2061 const struct dwarf_section
*section
,
2062 unsigned long *abbrev_num_return
,
2063 unsigned char **data_return
,
2064 abbrev_map
**map_return
)
2066 unsigned long abbrev_number
;
2068 abbrev_entry
* entry
;
2069 unsigned char * data
;
2071 if (abbrev_num_return
!= NULL
)
2072 * abbrev_num_return
= 0;
2073 if (data_return
!= NULL
)
2074 * data_return
= NULL
;
2078 case DW_FORM_GNU_ref_alt
:
2079 case DW_FORM_ref_sig8
:
2080 /* FIXME: We are unable to handle this form at the moment. */
2083 case DW_FORM_ref_addr
:
2084 if (uvalue
>= section
->size
)
2086 warn (_("Unable to resolve ref_addr form: uvalue %lx "
2087 "> section size %" PRIx64
" (%s)\n"),
2088 uvalue
, section
->size
, section
->name
);
2093 case DW_FORM_ref_sup4
:
2094 case DW_FORM_ref_sup8
:
2101 case DW_FORM_ref_udata
:
2102 if (uvalue
+ cu_offset
< uvalue
2103 || uvalue
+ cu_offset
> (size_t) (cu_end
- section
->start
))
2105 warn (_("Unable to resolve ref form: uvalue %lx + cu_offset %" PRIx64
2106 " > CU size %tx\n"),
2107 uvalue
, cu_offset
, cu_end
- section
->start
);
2110 uvalue
+= cu_offset
;
2113 /* FIXME: Are there other DW_FORMs that can be used by types ? */
2116 warn (_("Unexpected form %lx encountered whilst finding abbreviation for type\n"), form
);
2120 data
= (unsigned char *) section
->start
+ uvalue
;
2121 map
= find_abbrev_map_by_offset (uvalue
);
2125 warn (_("Unable to find abbreviations for CU offset %#lx\n"), uvalue
);
2128 if (map
->list
== NULL
)
2130 warn (_("Empty abbreviation list encountered for CU offset %lx\n"), uvalue
);
2134 if (map_return
!= NULL
)
2136 if (form
== DW_FORM_ref_addr
)
2142 READ_ULEB (abbrev_number
, data
, section
->start
+ section
->size
);
2144 for (entry
= map
->list
->first_abbrev
; entry
!= NULL
; entry
= entry
->next
)
2145 if (entry
->number
== abbrev_number
)
2148 if (abbrev_num_return
!= NULL
)
2149 * abbrev_num_return
= abbrev_number
;
2151 if (data_return
!= NULL
)
2152 * data_return
= data
;
2155 warn (_("Unable to find entry for abbreviation %lu\n"), abbrev_number
);
2160 /* Return IS_SIGNED set to TRUE if the type using abbreviation ENTRY
2161 can be determined to be a signed type. The data for ENTRY can be
2162 found starting at DATA. */
2165 get_type_signedness (abbrev_entry
*entry
,
2166 const struct dwarf_section
*section
,
2167 unsigned char *data
,
2170 uint64_t pointer_size
,
2171 uint64_t offset_size
,
2174 unsigned int nesting
)
2178 * is_signed
= false;
2180 #define MAX_NESTING 20
2181 if (nesting
> MAX_NESTING
)
2183 /* FIXME: Warn - or is this expected ?
2184 NB/ We need to avoid infinite recursion. */
2188 for (attr
= entry
->first_attr
;
2189 attr
!= NULL
&& attr
->attribute
;
2192 unsigned char * orig_data
= data
;
2193 uint64_t uvalue
= 0;
2195 data
= skip_attr_bytes (attr
->form
, data
, end
, pointer_size
,
2196 offset_size
, dwarf_version
, & uvalue
);
2200 switch (attr
->attribute
)
2202 case DW_AT_linkage_name
:
2206 if (attr
->form
== DW_FORM_strp
)
2207 printf (", %s", fetch_indirect_string (uvalue
));
2208 else if (attr
->form
== DW_FORM_string
)
2209 printf (", %.*s", (int) (end
- orig_data
), orig_data
);
2216 abbrev_entry
*type_abbrev
;
2217 unsigned char *type_data
;
2220 type_abbrev
= get_type_abbrev_from_form (attr
->form
,
2225 NULL
/* abbrev num return */,
2228 if (type_abbrev
== NULL
)
2231 get_type_signedness (type_abbrev
, section
, type_data
,
2232 map
? section
->start
+ map
->end
: end
,
2233 map
? map
->start
: cu_offset
,
2234 pointer_size
, offset_size
, dwarf_version
,
2235 is_signed
, nesting
+ 1);
2239 case DW_AT_encoding
:
2240 /* Determine signness. */
2243 case DW_ATE_address
:
2244 /* FIXME - some architectures have signed addresses. */
2245 case DW_ATE_boolean
:
2246 case DW_ATE_unsigned
:
2247 case DW_ATE_unsigned_char
:
2248 case DW_ATE_unsigned_fixed
:
2249 * is_signed
= false;
2253 case DW_ATE_complex_float
:
2256 case DW_ATE_signed_char
:
2257 case DW_ATE_imaginary_float
:
2258 case DW_ATE_decimal_float
:
2259 case DW_ATE_signed_fixed
:
2269 read_and_print_leb128 (unsigned char *data
,
2270 unsigned int *bytes_read
,
2271 unsigned const char *end
,
2275 uint64_t val
= read_leb128 (data
, end
, is_signed
, bytes_read
, &status
);
2277 report_leb_status (status
);
2279 printf ("%" PRId64
, val
);
2281 printf ("%" PRIu64
, val
);
2285 display_discr_list (unsigned long form
,
2287 unsigned char *data
,
2290 unsigned char *end
= data
;
2294 printf ("[default]");
2301 case DW_FORM_block1
:
2302 case DW_FORM_block2
:
2303 case DW_FORM_block4
:
2304 /* Move data pointer back to the start of the byte array. */
2308 printf ("<corrupt>\n");
2309 warn (_("corrupt discr_list - not using a block form\n"));
2315 printf ("<corrupt>\n");
2316 warn (_("corrupt discr_list - block not long enough\n"));
2320 bool is_signed
= (level
> 0 && level
<= MAX_CU_NESTING
2321 ? level_type_signed
[level
- 1] : false);
2326 unsigned char discriminant
;
2327 unsigned int bytes_read
;
2329 SAFE_BYTE_GET_AND_INC (discriminant
, data
, 1, end
);
2331 switch (discriminant
)
2335 read_and_print_leb128 (data
, & bytes_read
, end
, is_signed
);
2341 read_and_print_leb128 (data
, & bytes_read
, end
, is_signed
);
2345 read_and_print_leb128 (data
, & bytes_read
, end
, is_signed
);
2350 printf ("<corrupt>\n");
2351 warn (_("corrupt discr_list - unrecognized discriminant byte %#x\n"),
2361 printf (")(signed)");
2363 printf (")(unsigned)");
2366 static unsigned char *
2367 read_and_display_attr_value (unsigned long attribute
,
2369 int64_t implicit_const
,
2370 unsigned char *start
,
2371 unsigned char *data
,
2374 uint64_t pointer_size
,
2375 uint64_t offset_size
,
2377 debug_info
*debug_info_p
,
2379 struct dwarf_section
*section
,
2380 struct cu_tu_set
*this_set
,
2385 uint64_t uvalue
= 0;
2386 uint64_t uvalue_hi
= 0;
2387 unsigned char *block_start
= NULL
;
2388 unsigned char *orig_data
= data
;
2390 if (data
> end
|| (data
== end
&& form
!= DW_FORM_flag_present
))
2392 warn (_("Corrupt attribute\n"));
2396 if (do_wide
&& ! do_loc
)
2398 /* PR 26847: Display the name of the form. */
2399 const char * name
= get_FORM_name (form
);
2401 /* For convenience we skip the DW_FORM_ prefix to the name. */
2403 name
+= 8; /* strlen ("DW_FORM_") */
2404 printf ("%c(%s)", delimiter
, name
);
2409 case DW_FORM_ref_addr
:
2410 if (dwarf_version
== 2)
2411 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
2412 else if (dwarf_version
> 2)
2413 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
2415 error (_("Internal error: DW_FORM_ref_addr is not supported in DWARF version 1.\n"));
2419 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
2422 case DW_FORM_strp_sup
:
2424 case DW_FORM_line_strp
:
2425 case DW_FORM_sec_offset
:
2426 case DW_FORM_GNU_ref_alt
:
2427 case DW_FORM_GNU_strp_alt
:
2428 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
2431 case DW_FORM_flag_present
:
2439 case DW_FORM_addrx1
:
2440 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
2446 case DW_FORM_addrx2
:
2447 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
2451 case DW_FORM_addrx3
:
2452 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 3, end
);
2455 case DW_FORM_ref_sup4
:
2459 case DW_FORM_addrx4
:
2460 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
2463 case DW_FORM_ref_sup8
:
2466 case DW_FORM_ref_sig8
:
2467 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 8, end
);
2470 case DW_FORM_data16
:
2471 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 8, end
);
2472 SAFE_BYTE_GET_AND_INC (uvalue_hi
, data
, 8, end
);
2473 if (byte_get
!= byte_get_little_endian
)
2475 uint64_t utmp
= uvalue
;
2482 READ_SLEB (svalue
, data
, end
);
2486 case DW_FORM_GNU_str_index
:
2488 case DW_FORM_ref_udata
:
2490 case DW_FORM_GNU_addr_index
:
2492 case DW_FORM_loclistx
:
2493 case DW_FORM_rnglistx
:
2494 READ_ULEB (uvalue
, data
, end
);
2497 case DW_FORM_indirect
:
2498 READ_ULEB (form
, data
, end
);
2500 printf ("%c%s", delimiter
, get_FORM_name (form
));
2501 if (form
== DW_FORM_implicit_const
)
2502 READ_SLEB (implicit_const
, data
, end
);
2503 return read_and_display_attr_value (attribute
, form
, implicit_const
,
2505 cu_offset
, pointer_size
,
2506 offset_size
, dwarf_version
,
2507 debug_info_p
, do_loc
,
2508 section
, this_set
, delimiter
, level
);
2510 case DW_FORM_implicit_const
:
2511 uvalue
= implicit_const
;
2520 case DW_FORM_ref_addr
:
2522 printf ("%c<%#" PRIx64
">", delimiter
, uvalue
);
2525 case DW_FORM_GNU_ref_alt
:
2529 /* We have already printed the form name. */
2530 printf ("%c<%#" PRIx64
">", delimiter
, uvalue
);
2532 printf ("%c<alt %#" PRIx64
">", delimiter
, uvalue
);
2534 /* FIXME: Follow the reference... */
2540 case DW_FORM_ref_sup4
:
2541 case DW_FORM_ref_udata
:
2543 printf ("%c<%#" PRIx64
">", delimiter
, uvalue
+ cu_offset
);
2548 case DW_FORM_sec_offset
:
2550 printf ("%c%#" PRIx64
, delimiter
, uvalue
);
2553 case DW_FORM_flag_present
:
2559 printf ("%c%" PRId64
, delimiter
, uvalue
);
2564 printf ("%c%" PRIu64
, delimiter
, uvalue
);
2567 case DW_FORM_implicit_const
:
2569 printf ("%c%" PRId64
, delimiter
, implicit_const
);
2572 case DW_FORM_ref_sup8
:
2577 uint64_t utmp
= uvalue
;
2578 if (form
== DW_FORM_ref8
)
2580 printf ("%c%#" PRIx64
, delimiter
, utmp
);
2584 case DW_FORM_data16
:
2588 printf (" %#" PRIx64
, uvalue
);
2590 printf (" %#" PRIx64
"%016" PRIx64
, uvalue_hi
, uvalue
);
2594 case DW_FORM_string
:
2596 printf ("%c%.*s", delimiter
, (int) (end
- data
), data
);
2597 data
+= strnlen ((char *) data
, end
- data
);
2603 case DW_FORM_exprloc
:
2604 READ_ULEB (uvalue
, data
, end
);
2607 if (block_start
>= end
)
2609 warn (_("Block ends prematurely\n"));
2614 uvalue
= check_uvalue (block_start
, uvalue
, end
);
2616 data
= block_start
+ uvalue
;
2621 SAFE_BYTE_GET (op
, block_start
, sizeof (op
), end
);
2622 if (op
!= DW_OP_addrx
)
2623 data
= display_block (block_start
, uvalue
, end
, delimiter
);
2627 case DW_FORM_block1
:
2628 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
2631 case DW_FORM_block2
:
2632 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
2635 case DW_FORM_block4
:
2636 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
2643 /* We have already displayed the form name. */
2644 printf (_("%c(offset: %#" PRIx64
"): %s"),
2645 delimiter
, uvalue
, fetch_indirect_string (uvalue
));
2647 printf (_("%c(indirect string, offset: %#" PRIx64
"): %s"),
2648 delimiter
, uvalue
, fetch_indirect_string (uvalue
));
2652 case DW_FORM_line_strp
:
2656 /* We have already displayed the form name. */
2657 printf (_("%c(offset: %#" PRIx64
"): %s"),
2658 delimiter
, uvalue
, fetch_indirect_line_string (uvalue
));
2660 printf (_("%c(indirect line string, offset: %#" PRIx64
"): %s"),
2661 delimiter
, uvalue
, fetch_indirect_line_string (uvalue
));
2665 case DW_FORM_GNU_str_index
:
2673 const char *suffix
= section
? strrchr (section
->name
, '.') : NULL
;
2674 bool dwo
= suffix
&& strcmp (suffix
, ".dwo") == 0;
2677 strng
= fetch_indexed_string (uvalue
, this_set
, offset_size
, dwo
,
2678 debug_info_p
? debug_info_p
->str_offsets_base
: 0);
2680 /* We have already displayed the form name. */
2681 printf (_("%c(offset: %#" PRIx64
"): %s"),
2682 delimiter
, uvalue
, strng
);
2684 printf (_("%c(indexed string: %#" PRIx64
"): %s"),
2685 delimiter
, uvalue
, strng
);
2689 case DW_FORM_GNU_strp_alt
:
2693 /* We have already displayed the form name. */
2694 printf (_("%c(offset: %#" PRIx64
") %s"),
2695 delimiter
, uvalue
, fetch_alt_indirect_string (uvalue
));
2697 printf (_("%c(alt indirect string, offset: %#" PRIx64
") %s"),
2698 delimiter
, uvalue
, fetch_alt_indirect_string (uvalue
));
2702 case DW_FORM_indirect
:
2703 /* Handled above. */
2706 case DW_FORM_ref_sig8
:
2708 printf ("%c%s: %#" PRIx64
, delimiter
, do_wide
? "" : "signature",
2712 case DW_FORM_GNU_addr_index
:
2714 case DW_FORM_addrx1
:
2715 case DW_FORM_addrx2
:
2716 case DW_FORM_addrx3
:
2717 case DW_FORM_addrx4
:
2718 case DW_FORM_loclistx
:
2719 case DW_FORM_rnglistx
:
2723 const char *suffix
= strrchr (section
->name
, '.');
2724 bool dwo
= suffix
&& strcmp (suffix
, ".dwo") == 0;
2726 if (form
== DW_FORM_loclistx
)
2730 idx
= fetch_indexed_value (uvalue
, loclists_dwo
, 0);
2731 if (idx
!= (uint64_t) -1)
2732 idx
+= (offset_size
== 8) ? 20 : 12;
2734 else if (debug_info_p
== NULL
)
2736 idx
= fetch_indexed_value (uvalue
, loclists
, 0);
2740 /* We want to compute:
2741 idx = fetch_indexed_value (uvalue, loclists, debug_info_p->loclists_base);
2742 idx += debug_info_p->loclists_base;
2743 Fortunately we already have that sum cached in the
2744 loc_offsets array. */
2745 if (uvalue
< debug_info_p
->num_loc_offsets
)
2746 idx
= debug_info_p
->loc_offsets
[uvalue
];
2749 warn (_("loc_offset %" PRIu64
" too big\n"), uvalue
);
2754 else if (form
== DW_FORM_rnglistx
)
2758 idx
= fetch_indexed_value (uvalue
, rnglists_dwo
, 0);
2759 if (idx
!= (uint64_t) -1)
2760 idx
+= (offset_size
== 8) ? 20 : 12;
2764 if (debug_info_p
== NULL
)
2767 base
= debug_info_p
->rnglists_base
;
2768 /* We do not have a cached value this time, so we perform the
2769 computation manually. */
2770 idx
= fetch_indexed_value (uvalue
, rnglists
, base
);
2771 if (idx
!= (uint64_t) -1)
2777 if (debug_info_p
== NULL
)
2779 else if (debug_info_p
->addr_base
== DEBUG_INFO_UNAVAILABLE
)
2782 base
= debug_info_p
->addr_base
;
2784 base
+= uvalue
* pointer_size
;
2785 idx
= fetch_indexed_addr (base
, pointer_size
);
2788 /* We have already displayed the form name. */
2789 if (idx
!= (uint64_t) -1)
2790 printf (_("%c(index: %#" PRIx64
"): %#" PRIx64
),
2791 delimiter
, uvalue
, idx
);
2795 case DW_FORM_strp_sup
:
2797 printf ("%c<%#" PRIx64
">", delimiter
, uvalue
+ cu_offset
);
2801 warn (_("Unrecognized form: %#lx"), form
);
2802 /* What to do? Consume a byte maybe? */
2807 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
|| do_debug_info
)
2808 && num_debug_info_entries
== 0
2809 && debug_info_p
!= NULL
)
2813 case DW_AT_loclists_base
:
2814 if (debug_info_p
->loclists_base
)
2815 warn (_("CU @ %#" PRIx64
" has multiple loclists_base values "
2816 "(%#" PRIx64
" and %#" PRIx64
")"),
2817 debug_info_p
->cu_offset
,
2818 debug_info_p
->loclists_base
, uvalue
);
2822 warn (_("CU @ %#" PRIx64
" has has a negative loclists_base "
2823 "value of %#" PRIx64
" - treating as zero"),
2824 debug_info_p
->cu_offset
, svalue
);
2827 debug_info_p
->loclists_base
= uvalue
;
2830 case DW_AT_rnglists_base
:
2831 if (debug_info_p
->rnglists_base
)
2832 warn (_("CU @ %#" PRIx64
" has multiple rnglists_base values "
2833 "(%#" PRIx64
" and %#" PRIx64
")"),
2834 debug_info_p
->cu_offset
,
2835 debug_info_p
->rnglists_base
, uvalue
);
2839 warn (_("CU @ %#" PRIx64
" has has a negative rnglists_base "
2840 "value of %#" PRIx64
" - treating as zero"),
2841 debug_info_p
->cu_offset
, svalue
);
2844 debug_info_p
->rnglists_base
= uvalue
;
2847 case DW_AT_str_offsets_base
:
2848 if (debug_info_p
->str_offsets_base
)
2849 warn (_("CU @ %#" PRIx64
" has multiple str_offsets_base values "
2850 "%#" PRIx64
" and %#" PRIx64
")"),
2851 debug_info_p
->cu_offset
,
2852 debug_info_p
->str_offsets_base
, uvalue
);
2856 warn (_("CU @ %#" PRIx64
" has has a negative stroffsets_base "
2857 "value of %#" PRIx64
" - treating as zero"),
2858 debug_info_p
->cu_offset
, svalue
);
2861 debug_info_p
->str_offsets_base
= uvalue
;
2864 case DW_AT_frame_base
:
2865 have_frame_base
= 1;
2867 case DW_AT_location
:
2868 case DW_AT_GNU_locviews
:
2869 case DW_AT_string_length
:
2870 case DW_AT_return_addr
:
2871 case DW_AT_data_member_location
:
2872 case DW_AT_vtable_elem_location
:
2874 case DW_AT_static_link
:
2875 case DW_AT_use_location
:
2876 case DW_AT_call_value
:
2877 case DW_AT_GNU_call_site_value
:
2878 case DW_AT_call_data_value
:
2879 case DW_AT_GNU_call_site_data_value
:
2880 case DW_AT_call_target
:
2881 case DW_AT_GNU_call_site_target
:
2882 case DW_AT_call_target_clobbered
:
2883 case DW_AT_GNU_call_site_target_clobbered
:
2884 if ((dwarf_version
< 4
2885 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
2886 || form
== DW_FORM_sec_offset
2887 || form
== DW_FORM_loclistx
)
2889 /* Process location list. */
2890 unsigned int lmax
= debug_info_p
->max_loc_offsets
;
2891 unsigned int num
= debug_info_p
->num_loc_offsets
;
2893 if (lmax
== 0 || num
>= lmax
)
2896 debug_info_p
->loc_offsets
= (uint64_t *)
2897 xcrealloc (debug_info_p
->loc_offsets
,
2898 lmax
, sizeof (*debug_info_p
->loc_offsets
));
2899 debug_info_p
->loc_views
= (uint64_t *)
2900 xcrealloc (debug_info_p
->loc_views
,
2901 lmax
, sizeof (*debug_info_p
->loc_views
));
2902 debug_info_p
->have_frame_base
= (int *)
2903 xcrealloc (debug_info_p
->have_frame_base
,
2904 lmax
, sizeof (*debug_info_p
->have_frame_base
));
2905 debug_info_p
->max_loc_offsets
= lmax
;
2907 if (form
== DW_FORM_loclistx
)
2908 uvalue
= fetch_indexed_value (num
, loclists
, debug_info_p
->loclists_base
);
2909 else if (this_set
!= NULL
)
2910 uvalue
+= this_set
->section_offsets
[DW_SECT_LOC
];
2912 debug_info_p
->have_frame_base
[num
] = have_frame_base
;
2913 if (attribute
!= DW_AT_GNU_locviews
)
2915 uvalue
+= debug_info_p
->loclists_base
;
2917 /* Corrupt DWARF info can produce more offsets than views.
2918 See PR 23062 for an example. */
2919 if (debug_info_p
->num_loc_offsets
2920 > debug_info_p
->num_loc_views
)
2921 warn (_("More location offset attributes than DW_AT_GNU_locview attributes\n"));
2924 debug_info_p
->loc_offsets
[num
] = uvalue
;
2925 debug_info_p
->num_loc_offsets
++;
2930 assert (debug_info_p
->num_loc_views
<= num
);
2931 num
= debug_info_p
->num_loc_views
;
2932 if (num
> debug_info_p
->num_loc_offsets
)
2933 warn (_("More DW_AT_GNU_locview attributes than location offset attributes\n"));
2936 debug_info_p
->loc_views
[num
] = uvalue
;
2937 debug_info_p
->num_loc_views
++;
2944 if (need_base_address
)
2945 debug_info_p
->base_address
= uvalue
;
2948 case DW_AT_GNU_addr_base
:
2949 case DW_AT_addr_base
:
2950 debug_info_p
->addr_base
= uvalue
;
2953 case DW_AT_GNU_ranges_base
:
2954 debug_info_p
->ranges_base
= uvalue
;
2958 if ((dwarf_version
< 4
2959 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
2960 || form
== DW_FORM_sec_offset
2961 || form
== DW_FORM_rnglistx
)
2963 /* Process range list. */
2964 unsigned int lmax
= debug_info_p
->max_range_lists
;
2965 unsigned int num
= debug_info_p
->num_range_lists
;
2967 if (lmax
== 0 || num
>= lmax
)
2970 debug_info_p
->range_lists
= (uint64_t *)
2971 xcrealloc (debug_info_p
->range_lists
,
2972 lmax
, sizeof (*debug_info_p
->range_lists
));
2973 debug_info_p
->max_range_lists
= lmax
;
2976 if (form
== DW_FORM_rnglistx
)
2977 uvalue
= fetch_indexed_value (uvalue
, rnglists
, 0);
2979 debug_info_p
->range_lists
[num
] = uvalue
;
2980 debug_info_p
->num_range_lists
++;
2984 case DW_AT_GNU_dwo_name
:
2985 case DW_AT_dwo_name
:
2990 add_dwo_name ((const char *) fetch_indirect_string (uvalue
), cu_offset
);
2992 case DW_FORM_GNU_strp_alt
:
2993 add_dwo_name ((const char *) fetch_alt_indirect_string (uvalue
), cu_offset
);
2995 case DW_FORM_GNU_str_index
:
3001 add_dwo_name (fetch_indexed_string (uvalue
, this_set
, offset_size
, false,
3002 debug_info_p
->str_offsets_base
),
3005 case DW_FORM_string
:
3006 add_dwo_name ((const char *) orig_data
, cu_offset
);
3009 warn (_("Unsupported form (%s) for attribute %s\n"),
3010 get_FORM_name (form
), get_AT_name (attribute
));
3015 case DW_AT_comp_dir
:
3016 /* FIXME: Also extract a build-id in a CU/TU. */
3021 add_dwo_dir ((const char *) fetch_indirect_string (uvalue
), cu_offset
);
3023 case DW_FORM_GNU_strp_alt
:
3024 add_dwo_dir (fetch_alt_indirect_string (uvalue
), cu_offset
);
3026 case DW_FORM_line_strp
:
3027 add_dwo_dir ((const char *) fetch_indirect_line_string (uvalue
), cu_offset
);
3029 case DW_FORM_GNU_str_index
:
3035 add_dwo_dir (fetch_indexed_string (uvalue
, this_set
, offset_size
, false,
3036 debug_info_p
->str_offsets_base
),
3039 case DW_FORM_string
:
3040 add_dwo_dir ((const char *) orig_data
, cu_offset
);
3043 warn (_("Unsupported form (%s) for attribute %s\n"),
3044 get_FORM_name (form
), get_AT_name (attribute
));
3049 case DW_AT_GNU_dwo_id
:
3054 /* FIXME: Record the length of the ID as well ? */
3055 add_dwo_id ((const char *) (data
- 8), cu_offset
);
3058 warn (_("Unsupported form (%s) for attribute %s\n"),
3059 get_FORM_name (form
), get_AT_name (attribute
));
3069 if (do_loc
|| attribute
== 0)
3072 /* For some attributes we can display further information. */
3076 if (level
>= 0 && level
< MAX_CU_NESTING
3077 && uvalue
< (size_t) (end
- start
))
3079 bool is_signed
= false;
3080 abbrev_entry
*type_abbrev
;
3081 unsigned char *type_data
;
3084 type_abbrev
= get_type_abbrev_from_form (form
, uvalue
,
3088 if (type_abbrev
!= NULL
)
3090 get_type_signedness (type_abbrev
, section
, type_data
,
3091 map
? section
->start
+ map
->end
: end
,
3092 map
? map
->start
: cu_offset
,
3093 pointer_size
, offset_size
, dwarf_version
,
3096 level_type_signed
[level
] = is_signed
;
3104 case DW_INL_not_inlined
:
3105 printf (_("(not inlined)"));
3107 case DW_INL_inlined
:
3108 printf (_("(inlined)"));
3110 case DW_INL_declared_not_inlined
:
3111 printf (_("(declared as inline but ignored)"));
3113 case DW_INL_declared_inlined
:
3114 printf (_("(declared as inline and inlined)"));
3117 printf (_(" (Unknown inline attribute value: %#" PRIx64
")"),
3123 case DW_AT_language
:
3127 /* Ordered by the numeric value of these constants. */
3128 case DW_LANG_C89
: printf ("(ANSI C)"); break;
3129 case DW_LANG_C
: printf ("(non-ANSI C)"); break;
3130 case DW_LANG_Ada83
: printf ("(Ada)"); break;
3131 case DW_LANG_C_plus_plus
: printf ("(C++)"); break;
3132 case DW_LANG_Cobol74
: printf ("(Cobol 74)"); break;
3133 case DW_LANG_Cobol85
: printf ("(Cobol 85)"); break;
3134 case DW_LANG_Fortran77
: printf ("(FORTRAN 77)"); break;
3135 case DW_LANG_Fortran90
: printf ("(Fortran 90)"); break;
3136 case DW_LANG_Pascal83
: printf ("(ANSI Pascal)"); break;
3137 case DW_LANG_Modula2
: printf ("(Modula 2)"); break;
3138 /* DWARF 2.1 values. */
3139 case DW_LANG_Java
: printf ("(Java)"); break;
3140 case DW_LANG_C99
: printf ("(ANSI C99)"); break;
3141 case DW_LANG_Ada95
: printf ("(ADA 95)"); break;
3142 case DW_LANG_Fortran95
: printf ("(Fortran 95)"); break;
3143 /* DWARF 3 values. */
3144 case DW_LANG_PLI
: printf ("(PLI)"); break;
3145 case DW_LANG_ObjC
: printf ("(Objective C)"); break;
3146 case DW_LANG_ObjC_plus_plus
: printf ("(Objective C++)"); break;
3147 case DW_LANG_UPC
: printf ("(Unified Parallel C)"); break;
3148 case DW_LANG_D
: printf ("(D)"); break;
3149 /* DWARF 4 values. */
3150 case DW_LANG_Python
: printf ("(Python)"); break;
3151 /* DWARF 5 values. */
3152 case DW_LANG_OpenCL
: printf ("(OpenCL)"); break;
3153 case DW_LANG_Go
: printf ("(Go)"); break;
3154 case DW_LANG_Modula3
: printf ("(Modula 3)"); break;
3155 case DW_LANG_Haskell
: printf ("(Haskell)"); break;
3156 case DW_LANG_C_plus_plus_03
: printf ("(C++03)"); break;
3157 case DW_LANG_C_plus_plus_11
: printf ("(C++11)"); break;
3158 case DW_LANG_OCaml
: printf ("(OCaml)"); break;
3159 case DW_LANG_Rust
: printf ("(Rust)"); break;
3160 case DW_LANG_C11
: printf ("(C11)"); break;
3161 case DW_LANG_Swift
: printf ("(Swift)"); break;
3162 case DW_LANG_Julia
: printf ("(Julia)"); break;
3163 case DW_LANG_Dylan
: printf ("(Dylan)"); break;
3164 case DW_LANG_C_plus_plus_14
: printf ("(C++14)"); break;
3165 case DW_LANG_Fortran03
: printf ("(Fortran 03)"); break;
3166 case DW_LANG_Fortran08
: printf ("(Fortran 08)"); break;
3167 case DW_LANG_RenderScript
: printf ("(RenderScript)"); break;
3168 /* MIPS extension. */
3169 case DW_LANG_Mips_Assembler
: printf ("(MIPS assembler)"); break;
3170 /* UPC extension. */
3171 case DW_LANG_Upc
: printf ("(Unified Parallel C)"); break;
3173 if (uvalue
>= DW_LANG_lo_user
&& uvalue
<= DW_LANG_hi_user
)
3174 printf (_("(implementation defined: %#" PRIx64
")"), uvalue
);
3176 printf (_("(unknown: %#" PRIx64
")"), uvalue
);
3181 case DW_AT_encoding
:
3185 case DW_ATE_void
: printf ("(void)"); break;
3186 case DW_ATE_address
: printf ("(machine address)"); break;
3187 case DW_ATE_boolean
: printf ("(boolean)"); break;
3188 case DW_ATE_complex_float
: printf ("(complex float)"); break;
3189 case DW_ATE_float
: printf ("(float)"); break;
3190 case DW_ATE_signed
: printf ("(signed)"); break;
3191 case DW_ATE_signed_char
: printf ("(signed char)"); break;
3192 case DW_ATE_unsigned
: printf ("(unsigned)"); break;
3193 case DW_ATE_unsigned_char
: printf ("(unsigned char)"); break;
3194 /* DWARF 2.1 values: */
3195 case DW_ATE_imaginary_float
: printf ("(imaginary float)"); break;
3196 case DW_ATE_decimal_float
: printf ("(decimal float)"); break;
3197 /* DWARF 3 values: */
3198 case DW_ATE_packed_decimal
: printf ("(packed_decimal)"); break;
3199 case DW_ATE_numeric_string
: printf ("(numeric_string)"); break;
3200 case DW_ATE_edited
: printf ("(edited)"); break;
3201 case DW_ATE_signed_fixed
: printf ("(signed_fixed)"); break;
3202 case DW_ATE_unsigned_fixed
: printf ("(unsigned_fixed)"); break;
3203 /* DWARF 4 values: */
3204 case DW_ATE_UTF
: printf ("(unicode string)"); break;
3205 /* DWARF 5 values: */
3206 case DW_ATE_UCS
: printf ("(UCS)"); break;
3207 case DW_ATE_ASCII
: printf ("(ASCII)"); break;
3209 /* HP extensions: */
3210 case DW_ATE_HP_float80
: printf ("(HP_float80)"); break;
3211 case DW_ATE_HP_complex_float80
: printf ("(HP_complex_float80)"); break;
3212 case DW_ATE_HP_float128
: printf ("(HP_float128)"); break;
3213 case DW_ATE_HP_complex_float128
:printf ("(HP_complex_float128)"); break;
3214 case DW_ATE_HP_floathpintel
: printf ("(HP_floathpintel)"); break;
3215 case DW_ATE_HP_imaginary_float80
: printf ("(HP_imaginary_float80)"); break;
3216 case DW_ATE_HP_imaginary_float128
: printf ("(HP_imaginary_float128)"); break;
3219 if (uvalue
>= DW_ATE_lo_user
3220 && uvalue
<= DW_ATE_hi_user
)
3221 printf (_("(user defined type)"));
3223 printf (_("(unknown type)"));
3228 case DW_AT_accessibility
:
3232 case DW_ACCESS_public
: printf ("(public)"); break;
3233 case DW_ACCESS_protected
: printf ("(protected)"); break;
3234 case DW_ACCESS_private
: printf ("(private)"); break;
3236 printf (_("(unknown accessibility)"));
3241 case DW_AT_visibility
:
3245 case DW_VIS_local
: printf ("(local)"); break;
3246 case DW_VIS_exported
: printf ("(exported)"); break;
3247 case DW_VIS_qualified
: printf ("(qualified)"); break;
3248 default: printf (_("(unknown visibility)")); break;
3252 case DW_AT_endianity
:
3256 case DW_END_default
: printf ("(default)"); break;
3257 case DW_END_big
: printf ("(big)"); break;
3258 case DW_END_little
: printf ("(little)"); break;
3260 if (uvalue
>= DW_END_lo_user
&& uvalue
<= DW_END_hi_user
)
3261 printf (_("(user specified)"));
3263 printf (_("(unknown endianity)"));
3268 case DW_AT_virtuality
:
3272 case DW_VIRTUALITY_none
: printf ("(none)"); break;
3273 case DW_VIRTUALITY_virtual
: printf ("(virtual)"); break;
3274 case DW_VIRTUALITY_pure_virtual
:printf ("(pure_virtual)"); break;
3275 default: printf (_("(unknown virtuality)")); break;
3279 case DW_AT_identifier_case
:
3283 case DW_ID_case_sensitive
: printf ("(case_sensitive)"); break;
3284 case DW_ID_up_case
: printf ("(up_case)"); break;
3285 case DW_ID_down_case
: printf ("(down_case)"); break;
3286 case DW_ID_case_insensitive
: printf ("(case_insensitive)"); break;
3287 default: printf (_("(unknown case)")); break;
3291 case DW_AT_calling_convention
:
3295 case DW_CC_normal
: printf ("(normal)"); break;
3296 case DW_CC_program
: printf ("(program)"); break;
3297 case DW_CC_nocall
: printf ("(nocall)"); break;
3298 case DW_CC_pass_by_reference
: printf ("(pass by ref)"); break;
3299 case DW_CC_pass_by_value
: printf ("(pass by value)"); break;
3300 case DW_CC_GNU_renesas_sh
: printf ("(Rensas SH)"); break;
3301 case DW_CC_GNU_borland_fastcall_i386
: printf ("(Borland fastcall i386)"); break;
3303 if (uvalue
>= DW_CC_lo_user
3304 && uvalue
<= DW_CC_hi_user
)
3305 printf (_("(user defined)"));
3307 printf (_("(unknown convention)"));
3311 case DW_AT_ordering
:
3316 case -1: printf (_("(undefined)")); break;
3317 case 0: printf ("(row major)"); break;
3318 case 1: printf ("(column major)"); break;
3322 case DW_AT_decimal_sign
:
3326 case DW_DS_unsigned
: printf (_("(unsigned)")); break;
3327 case DW_DS_leading_overpunch
: printf (_("(leading overpunch)")); break;
3328 case DW_DS_trailing_overpunch
: printf (_("(trailing overpunch)")); break;
3329 case DW_DS_leading_separate
: printf (_("(leading separate)")); break;
3330 case DW_DS_trailing_separate
: printf (_("(trailing separate)")); break;
3331 default: printf (_("(unrecognised)")); break;
3335 case DW_AT_defaulted
:
3339 case DW_DEFAULTED_no
: printf (_("(no)")); break;
3340 case DW_DEFAULTED_in_class
: printf (_("(in class)")); break;
3341 case DW_DEFAULTED_out_of_class
: printf (_("(out of class)")); break;
3342 default: printf (_("(unrecognised)")); break;
3346 case DW_AT_discr_list
:
3348 display_discr_list (form
, uvalue
, data
, level
);
3351 case DW_AT_frame_base
:
3352 have_frame_base
= 1;
3354 case DW_AT_location
:
3355 case DW_AT_loclists_base
:
3356 case DW_AT_rnglists_base
:
3357 case DW_AT_str_offsets_base
:
3358 case DW_AT_string_length
:
3359 case DW_AT_return_addr
:
3360 case DW_AT_data_member_location
:
3361 case DW_AT_vtable_elem_location
:
3363 case DW_AT_static_link
:
3364 case DW_AT_use_location
:
3365 case DW_AT_call_value
:
3366 case DW_AT_GNU_call_site_value
:
3367 case DW_AT_call_data_value
:
3368 case DW_AT_GNU_call_site_data_value
:
3369 case DW_AT_call_target
:
3370 case DW_AT_GNU_call_site_target
:
3371 case DW_AT_call_target_clobbered
:
3372 case DW_AT_GNU_call_site_target_clobbered
:
3373 if ((dwarf_version
< 4
3374 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
3375 || form
== DW_FORM_sec_offset
3376 || form
== DW_FORM_loclistx
)
3378 if (attribute
!= DW_AT_rnglists_base
3379 && attribute
!= DW_AT_str_offsets_base
)
3380 printf (_(" (location list)"));
3383 case DW_AT_allocated
:
3384 case DW_AT_associated
:
3385 case DW_AT_data_location
:
3387 case DW_AT_upper_bound
:
3388 case DW_AT_lower_bound
:
3392 int need_frame_base
;
3395 need_frame_base
= decode_location_expression (block_start
,
3400 cu_offset
, section
);
3402 if (need_frame_base
&& !have_frame_base
)
3403 printf (_(" [without DW_AT_frame_base]"));
3407 case DW_AT_data_bit_offset
:
3408 case DW_AT_byte_size
:
3409 case DW_AT_bit_size
:
3410 case DW_AT_string_length_byte_size
:
3411 case DW_AT_string_length_bit_size
:
3412 case DW_AT_bit_stride
:
3413 if (form
== DW_FORM_exprloc
)
3416 (void) decode_location_expression (block_start
, pointer_size
,
3417 offset_size
, dwarf_version
,
3418 uvalue
, cu_offset
, section
);
3425 unsigned long abbrev_number
;
3426 abbrev_entry
*entry
;
3428 entry
= get_type_abbrev_from_form (form
, uvalue
, cu_offset
, end
,
3429 section
, & abbrev_number
, NULL
, NULL
);
3432 if (form
!= DW_FORM_GNU_ref_alt
)
3433 warn (_("Offset %#" PRIx64
" used as value for DW_AT_import attribute of DIE at offset %#tx is too big.\n"),
3435 orig_data
- section
->start
);
3439 printf (_("\t[Abbrev Number: %ld"), abbrev_number
);
3440 printf (" (%s)", get_TAG_name (entry
->tag
));
3453 static unsigned char *
3454 read_and_display_attr (unsigned long attribute
,
3456 int64_t implicit_const
,
3457 unsigned char *start
,
3458 unsigned char *data
,
3461 uint64_t pointer_size
,
3462 uint64_t offset_size
,
3464 debug_info
*debug_info_p
,
3466 struct dwarf_section
*section
,
3467 struct cu_tu_set
*this_set
,
3471 printf (" %-18s:", get_AT_name (attribute
));
3472 data
= read_and_display_attr_value (attribute
, form
, implicit_const
,
3474 cu_offset
, pointer_size
, offset_size
,
3475 dwarf_version
, debug_info_p
,
3476 do_loc
, section
, this_set
, ' ', level
);
3482 /* Like load_debug_section, but if the ordinary call fails, and we are
3483 following debug links, then attempt to load the requested section
3484 from one of the separate debug info files. */
3487 load_debug_section_with_follow (enum dwarf_section_display_enum sec_enum
,
3490 if (load_debug_section (sec_enum
, handle
))
3492 if (debug_displays
[sec_enum
].section
.filename
== NULL
)
3494 /* See if we can associate a filename with this section. */
3497 for (i
= first_separate_info
; i
!= NULL
; i
= i
->next
)
3498 if (i
->handle
== handle
)
3500 debug_displays
[sec_enum
].section
.filename
= i
->filename
;
3508 if (do_follow_links
)
3512 for (i
= first_separate_info
; i
!= NULL
; i
= i
->next
)
3514 if (load_debug_section (sec_enum
, i
->handle
))
3516 debug_displays
[sec_enum
].section
.filename
= i
->filename
;
3518 /* FIXME: We should check to see if any of the remaining debug info
3519 files also contain this section, and, umm, do something about it. */
3529 introduce (struct dwarf_section
* section
, bool raw
)
3533 if (do_follow_links
&& section
->filename
)
3534 printf (_("Raw dump of debug contents of section %s (loaded from %s):\n\n"),
3535 section
->name
, section
->filename
);
3537 printf (_("Raw dump of debug contents of section %s:\n\n"), section
->name
);
3541 if (do_follow_links
&& section
->filename
)
3542 printf (_("Contents of the %s section (loaded from %s):\n\n"),
3543 section
->name
, section
->filename
);
3545 printf (_("Contents of the %s section:\n\n"), section
->name
);
3549 /* Free memory allocated for one unit in debug_information. */
3552 free_debug_information (debug_info
*ent
)
3554 if (ent
->max_loc_offsets
)
3556 free (ent
->loc_offsets
);
3557 free (ent
->loc_views
);
3558 free (ent
->have_frame_base
);
3560 if (ent
->max_range_lists
)
3561 free (ent
->range_lists
);
3564 /* Process the contents of a .debug_info section.
3565 If do_loc is TRUE then we are scanning for location lists and dwo tags
3566 and we do not want to display anything to the user.
3567 If do_types is TRUE, we are processing a .debug_types section instead of
3568 a .debug_info section.
3569 The information displayed is restricted by the values in DWARF_START_DIE
3570 and DWARF_CUTOFF_LEVEL.
3571 Returns TRUE upon success. Otherwise an error or warning message is
3572 printed and FALSE is returned. */
3575 process_debug_info (struct dwarf_section
* section
,
3577 enum dwarf_section_display_enum abbrev_sec
,
3581 unsigned char *start
= section
->start
;
3582 unsigned char *end
= start
+ section
->size
;
3583 unsigned char *section_begin
;
3585 unsigned int num_units
= 0;
3587 /* First scan the section to get the number of comp units.
3588 Length sanity checks are done here. */
3589 for (section_begin
= start
, num_units
= 0; section_begin
< end
;
3594 /* Read the first 4 bytes. For a 32-bit DWARF section, this
3595 will be the length. For a 64-bit DWARF section, it'll be
3596 the escape code 0xffffffff followed by an 8 byte length. */
3597 SAFE_BYTE_GET_AND_INC (length
, section_begin
, 4, end
);
3599 if (length
== 0xffffffff)
3600 SAFE_BYTE_GET_AND_INC (length
, section_begin
, 8, end
);
3601 else if (length
>= 0xfffffff0 && length
< 0xffffffff)
3603 warn (_("Reserved length value (%#" PRIx64
") found in section %s\n"),
3604 length
, section
->name
);
3608 /* Negative values are illegal, they may even cause infinite
3609 looping. This can happen if we can't accurately apply
3610 relocations to an object file, or if the file is corrupt. */
3611 if (length
> (size_t) (end
- section_begin
))
3613 warn (_("Corrupt unit length (got %#" PRIx64
3614 " expected at most %#tx) in section %s\n"),
3615 length
, end
- section_begin
, section
->name
);
3618 section_begin
+= length
;
3623 error (_("No comp units in %s section ?\n"), section
->name
);
3627 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
|| do_debug_info
)
3628 && num_debug_info_entries
== 0
3632 /* Then allocate an array to hold the information. */
3633 debug_information
= (debug_info
*) cmalloc (num_units
,
3634 sizeof (* debug_information
));
3635 if (debug_information
== NULL
)
3637 error (_("Not enough memory for a debug info array of %u entries\n"),
3639 alloc_num_debug_info_entries
= num_debug_info_entries
= 0;
3643 /* PR 17531: file: 92ca3797.
3644 We cannot rely upon the debug_information array being initialised
3645 before it is used. A corrupt file could easily contain references
3646 to a unit for which information has not been made available. So
3647 we ensure that the array is zeroed here. */
3648 memset (debug_information
, 0, num_units
* sizeof (*debug_information
));
3650 alloc_num_debug_info_entries
= num_units
;
3655 load_debug_section_with_follow (str
, file
);
3656 load_debug_section_with_follow (line_str
, file
);
3657 load_debug_section_with_follow (str_dwo
, file
);
3658 load_debug_section_with_follow (str_index
, file
);
3659 load_debug_section_with_follow (str_index_dwo
, file
);
3660 load_debug_section_with_follow (debug_addr
, file
);
3663 load_debug_section_with_follow (abbrev_sec
, file
);
3664 load_debug_section_with_follow (loclists
, file
);
3665 load_debug_section_with_follow (rnglists
, file
);
3666 load_debug_section_with_follow (loclists_dwo
, file
);
3667 load_debug_section_with_follow (rnglists_dwo
, file
);
3669 if (debug_displays
[abbrev_sec
].section
.start
== NULL
)
3671 warn (_("Unable to locate %s section!\n"),
3672 debug_displays
[abbrev_sec
].section
.uncompressed_name
);
3676 if (!do_loc
&& dwarf_start_die
== 0)
3677 introduce (section
, false);
3679 free_all_abbrevs ();
3681 /* In order to be able to resolve DW_FORM_ref_addr forms we need
3682 to load *all* of the abbrevs for all CUs in this .debug_info
3683 section. This does effectively mean that we (partially) read
3684 every CU header twice. */
3685 for (section_begin
= start
; start
< end
;)
3687 DWARF2_Internal_CompUnit compunit
;
3688 unsigned char *hdrptr
;
3689 uint64_t abbrev_base
;
3692 unsigned int offset_size
;
3693 struct cu_tu_set
*this_set
;
3694 unsigned char *end_cu
;
3697 cu_offset
= start
- section_begin
;
3699 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 4, end
);
3701 if (compunit
.cu_length
== 0xffffffff)
3703 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 8, end
);
3708 end_cu
= hdrptr
+ compunit
.cu_length
;
3710 SAFE_BYTE_GET_AND_INC (compunit
.cu_version
, hdrptr
, 2, end_cu
);
3712 this_set
= find_cu_tu_set_v2 (cu_offset
, do_types
);
3714 if (compunit
.cu_version
< 5)
3716 compunit
.cu_unit_type
= DW_UT_compile
;
3717 /* Initialize it due to a false compiler warning. */
3718 compunit
.cu_pointer_size
= -1;
3722 SAFE_BYTE_GET_AND_INC (compunit
.cu_unit_type
, hdrptr
, 1, end_cu
);
3723 do_types
= (compunit
.cu_unit_type
== DW_UT_type
);
3725 SAFE_BYTE_GET_AND_INC (compunit
.cu_pointer_size
, hdrptr
, 1, end_cu
);
3728 SAFE_BYTE_GET_AND_INC (compunit
.cu_abbrev_offset
, hdrptr
, offset_size
,
3731 if (compunit
.cu_unit_type
== DW_UT_split_compile
3732 || compunit
.cu_unit_type
== DW_UT_skeleton
)
3735 SAFE_BYTE_GET_AND_INC (dwo_id
, hdrptr
, 8, end_cu
);
3738 if (this_set
== NULL
)
3741 abbrev_size
= debug_displays
[abbrev_sec
].section
.size
;
3745 abbrev_base
= this_set
->section_offsets
[DW_SECT_ABBREV
];
3746 abbrev_size
= this_set
->section_sizes
[DW_SECT_ABBREV
];
3750 abbrev_list
*free_list
;
3751 list
= find_and_process_abbrev_set (&debug_displays
[abbrev_sec
].section
,
3752 abbrev_base
, abbrev_size
,
3753 compunit
.cu_abbrev_offset
,
3756 if (list
!= NULL
&& list
->first_abbrev
!= NULL
)
3757 record_abbrev_list_for_cu (cu_offset
, start
- section_begin
,
3759 else if (free_list
!= NULL
)
3760 free_abbrev_list (free_list
);
3763 for (start
= section_begin
, unit
= 0; start
< end
; unit
++)
3765 DWARF2_Internal_CompUnit compunit
;
3766 unsigned char *hdrptr
;
3767 unsigned char *tags
;
3768 int level
, last_level
, saved_level
;
3770 unsigned int offset_size
;
3771 uint64_t signature
= 0;
3772 uint64_t type_offset
= 0;
3773 struct cu_tu_set
*this_set
;
3774 uint64_t abbrev_base
;
3776 unsigned char *end_cu
;
3779 cu_offset
= start
- section_begin
;
3781 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 4, end
);
3783 if (compunit
.cu_length
== 0xffffffff)
3785 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 8, end
);
3790 end_cu
= hdrptr
+ compunit
.cu_length
;
3792 SAFE_BYTE_GET_AND_INC (compunit
.cu_version
, hdrptr
, 2, end_cu
);
3794 this_set
= find_cu_tu_set_v2 (cu_offset
, do_types
);
3796 if (compunit
.cu_version
< 5)
3798 compunit
.cu_unit_type
= DW_UT_compile
;
3799 /* Initialize it due to a false compiler warning. */
3800 compunit
.cu_pointer_size
= -1;
3804 SAFE_BYTE_GET_AND_INC (compunit
.cu_unit_type
, hdrptr
, 1, end_cu
);
3805 do_types
= (compunit
.cu_unit_type
== DW_UT_type
);
3807 SAFE_BYTE_GET_AND_INC (compunit
.cu_pointer_size
, hdrptr
, 1, end_cu
);
3810 SAFE_BYTE_GET_AND_INC (compunit
.cu_abbrev_offset
, hdrptr
, offset_size
, end_cu
);
3812 if (this_set
== NULL
)
3815 abbrev_size
= debug_displays
[abbrev_sec
].section
.size
;
3819 abbrev_base
= this_set
->section_offsets
[DW_SECT_ABBREV
];
3820 abbrev_size
= this_set
->section_sizes
[DW_SECT_ABBREV
];
3823 if (compunit
.cu_version
< 5)
3824 SAFE_BYTE_GET_AND_INC (compunit
.cu_pointer_size
, hdrptr
, 1, end_cu
);
3826 bool do_dwo_id
= false;
3827 uint64_t dwo_id
= 0;
3828 if (compunit
.cu_unit_type
== DW_UT_split_compile
3829 || compunit
.cu_unit_type
== DW_UT_skeleton
)
3831 SAFE_BYTE_GET_AND_INC (dwo_id
, hdrptr
, 8, end_cu
);
3835 /* PR 17512: file: 001-108546-0.001:0.1. */
3836 if (compunit
.cu_pointer_size
< 2 || compunit
.cu_pointer_size
> 8)
3838 warn (_("Invalid pointer size (%d) in compunit header, using %d instead\n"),
3839 compunit
.cu_pointer_size
, offset_size
);
3840 compunit
.cu_pointer_size
= offset_size
;
3845 SAFE_BYTE_GET_AND_INC (signature
, hdrptr
, 8, end_cu
);
3846 SAFE_BYTE_GET_AND_INC (type_offset
, hdrptr
, offset_size
, end_cu
);
3849 if (dwarf_start_die
>= (size_t) (end_cu
- section_begin
))
3855 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
|| do_debug_info
)
3856 && num_debug_info_entries
== 0
3857 && alloc_num_debug_info_entries
> unit
3860 free_debug_information (&debug_information
[unit
]);
3861 memset (&debug_information
[unit
], 0, sizeof (*debug_information
));
3862 debug_information
[unit
].pointer_size
= compunit
.cu_pointer_size
;
3863 debug_information
[unit
].offset_size
= offset_size
;
3864 debug_information
[unit
].dwarf_version
= compunit
.cu_version
;
3865 debug_information
[unit
].cu_offset
= cu_offset
;
3866 debug_information
[unit
].addr_base
= DEBUG_INFO_UNAVAILABLE
;
3867 debug_information
[unit
].ranges_base
= DEBUG_INFO_UNAVAILABLE
;
3870 if (!do_loc
&& dwarf_start_die
== 0)
3872 printf (_(" Compilation Unit @ offset %#" PRIx64
":\n"),
3874 printf (_(" Length: %#" PRIx64
" (%s)\n"),
3876 offset_size
== 8 ? "64-bit" : "32-bit");
3877 printf (_(" Version: %d\n"), compunit
.cu_version
);
3878 if (compunit
.cu_version
>= 5)
3880 const char *name
= get_DW_UT_name (compunit
.cu_unit_type
);
3882 printf (_(" Unit Type: %s (%x)\n"),
3884 compunit
.cu_unit_type
);
3886 printf (_(" Abbrev Offset: %#" PRIx64
"\n"),
3887 compunit
.cu_abbrev_offset
);
3888 printf (_(" Pointer Size: %d\n"), compunit
.cu_pointer_size
);
3891 printf (_(" Signature: %#" PRIx64
"\n"), signature
);
3892 printf (_(" Type Offset: %#" PRIx64
"\n"), type_offset
);
3895 printf (_(" DWO ID: %#" PRIx64
"\n"), dwo_id
);
3896 if (this_set
!= NULL
)
3898 uint64_t *offsets
= this_set
->section_offsets
;
3899 size_t *sizes
= this_set
->section_sizes
;
3901 printf (_(" Section contributions:\n"));
3902 printf (_(" .debug_abbrev.dwo: %#" PRIx64
" %#zx\n"),
3903 offsets
[DW_SECT_ABBREV
], sizes
[DW_SECT_ABBREV
]);
3904 printf (_(" .debug_line.dwo: %#" PRIx64
" %#zx\n"),
3905 offsets
[DW_SECT_LINE
], sizes
[DW_SECT_LINE
]);
3906 printf (_(" .debug_loc.dwo: %#" PRIx64
" %#zx\n"),
3907 offsets
[DW_SECT_LOC
], sizes
[DW_SECT_LOC
]);
3908 printf (_(" .debug_str_offsets.dwo: %#" PRIx64
" %#zx\n"),
3909 offsets
[DW_SECT_STR_OFFSETS
], sizes
[DW_SECT_STR_OFFSETS
]);
3916 if (compunit
.cu_version
< 2 || compunit
.cu_version
> 5)
3918 warn (_("CU at offset %#" PRIx64
" contains corrupt or "
3919 "unsupported version number: %d.\n"),
3920 cu_offset
, compunit
.cu_version
);
3924 if (compunit
.cu_unit_type
!= DW_UT_compile
3925 && compunit
.cu_unit_type
!= DW_UT_partial
3926 && compunit
.cu_unit_type
!= DW_UT_type
3927 && compunit
.cu_unit_type
!= DW_UT_split_compile
3928 && compunit
.cu_unit_type
!= DW_UT_skeleton
)
3930 warn (_("CU at offset %#" PRIx64
" contains corrupt or "
3931 "unsupported unit type: %d.\n"),
3932 cu_offset
, compunit
.cu_unit_type
);
3936 /* Process the abbrevs used by this compilation unit. */
3938 list
= find_and_process_abbrev_set (&debug_displays
[abbrev_sec
].section
,
3939 abbrev_base
, abbrev_size
,
3940 compunit
.cu_abbrev_offset
, NULL
);
3944 while (tags
< start
)
3946 unsigned long abbrev_number
;
3947 unsigned long die_offset
;
3948 abbrev_entry
*entry
;
3950 int do_printing
= 1;
3952 die_offset
= tags
- section_begin
;
3954 READ_ULEB (abbrev_number
, tags
, start
);
3956 /* A null DIE marks the end of a list of siblings or it may also be
3957 a section padding. */
3958 if (abbrev_number
== 0)
3960 /* Check if it can be a section padding for the last CU. */
3961 if (level
== 0 && start
== end
)
3965 for (chk
= tags
; chk
< start
; chk
++)
3972 if (!do_loc
&& die_offset
>= dwarf_start_die
3973 && (dwarf_cutoff_level
== -1
3974 || level
< dwarf_cutoff_level
))
3975 printf (_(" <%d><%lx>: Abbrev Number: 0\n"),
3981 static unsigned num_bogus_warns
= 0;
3983 if (num_bogus_warns
< 3)
3985 warn (_("Bogus end-of-siblings marker detected at offset %lx in %s section\n"),
3986 die_offset
, section
->name
);
3988 if (num_bogus_warns
== 3)
3989 warn (_("Further warnings about bogus end-of-sibling markers suppressed\n"));
3992 if (dwarf_start_die
!= 0 && level
< saved_level
)
3999 if (dwarf_start_die
!= 0 && die_offset
< dwarf_start_die
)
4003 if (dwarf_start_die
!= 0 && die_offset
== dwarf_start_die
)
4004 saved_level
= level
;
4005 do_printing
= (dwarf_cutoff_level
== -1
4006 || level
< dwarf_cutoff_level
);
4008 printf (_(" <%d><%lx>: Abbrev Number: %lu"),
4009 level
, die_offset
, abbrev_number
);
4010 else if (dwarf_cutoff_level
== -1
4011 || last_level
< dwarf_cutoff_level
)
4012 printf (_(" <%d><%lx>: ...\n"), level
, die_offset
);
4017 /* Scan through the abbreviation list until we reach the
4021 for (entry
= list
->first_abbrev
; entry
!= NULL
; entry
= entry
->next
)
4022 if (entry
->number
== abbrev_number
)
4027 if (!do_loc
&& do_printing
)
4032 warn (_("DIE at offset %#lx refers to abbreviation number %lu which does not exist\n"),
4033 die_offset
, abbrev_number
);
4037 if (!do_loc
&& do_printing
)
4038 printf (" (%s)\n", get_TAG_name (entry
->tag
));
4043 need_base_address
= 0;
4045 case DW_TAG_compile_unit
:
4046 case DW_TAG_skeleton_unit
:
4047 need_base_address
= 1;
4048 need_dwo_info
= do_loc
;
4050 case DW_TAG_entry_point
:
4051 case DW_TAG_subprogram
:
4052 need_base_address
= 0;
4053 /* Assuming that there is no DW_AT_frame_base. */
4054 have_frame_base
= 0;
4058 debug_info
*debug_info_p
=
4059 (debug_information
&& unit
< alloc_num_debug_info_entries
)
4060 ? debug_information
+ unit
: NULL
;
4062 assert (!debug_info_p
4063 || (debug_info_p
->num_loc_offsets
4064 == debug_info_p
->num_loc_views
));
4066 for (attr
= entry
->first_attr
;
4067 attr
&& attr
->attribute
;
4070 if (! do_loc
&& do_printing
)
4071 /* Show the offset from where the tag was extracted. */
4072 printf (" <%tx>", tags
- section_begin
);
4073 tags
= read_and_display_attr (attr
->attribute
,
4075 attr
->implicit_const
,
4080 compunit
.cu_pointer_size
,
4082 compunit
.cu_version
,
4084 do_loc
|| ! do_printing
,
4090 /* If a locview attribute appears before a location one,
4091 make sure we don't associate it with an earlier
4094 switch (debug_info_p
->num_loc_offsets
- debug_info_p
->num_loc_views
)
4097 debug_info_p
->loc_views
[debug_info_p
->num_loc_views
] = -1;
4098 debug_info_p
->num_loc_views
++;
4099 assert (debug_info_p
->num_loc_views
4100 == debug_info_p
->num_loc_offsets
);
4107 warn(_("DIE has locviews without loclist\n"));
4108 debug_info_p
->num_loc_views
--;
4115 if (entry
->children
)
4119 free_abbrev_list (list
);
4122 /* Set num_debug_info_entries here so that it can be used to check if
4123 we need to process .debug_loc and .debug_ranges sections. */
4124 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
|| do_debug_info
)
4125 && num_debug_info_entries
== 0
4128 if (num_units
> alloc_num_debug_info_entries
)
4129 num_debug_info_entries
= alloc_num_debug_info_entries
;
4131 num_debug_info_entries
= num_units
;
4140 /* Locate and scan the .debug_info section in the file and record the pointer
4141 sizes and offsets for the compilation units in it. Usually an executable
4142 will have just one pointer size, but this is not guaranteed, and so we try
4143 not to make any assumptions. Returns zero upon failure, or the number of
4144 compilation units upon success. */
4147 load_debug_info (void * file
)
4149 /* If we have already tried and failed to load the .debug_info
4150 section then do not bother to repeat the task. */
4151 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
4154 /* If we already have the information there is nothing else to do. */
4155 if (num_debug_info_entries
> 0)
4156 return num_debug_info_entries
;
4158 /* If this is a DWARF package file, load the CU and TU indexes. */
4159 (void) load_cu_tu_indexes (file
);
4161 if (load_debug_section_with_follow (info
, file
)
4162 && process_debug_info (&debug_displays
[info
].section
, file
, abbrev
, true, false))
4163 return num_debug_info_entries
;
4165 if (load_debug_section_with_follow (info_dwo
, file
)
4166 && process_debug_info (&debug_displays
[info_dwo
].section
, file
,
4167 abbrev_dwo
, true, false))
4168 return num_debug_info_entries
;
4170 num_debug_info_entries
= DEBUG_INFO_UNAVAILABLE
;
4174 /* Read a DWARF .debug_line section header starting at DATA.
4175 Upon success returns an updated DATA pointer and the LINFO
4176 structure and the END_OF_SEQUENCE pointer will be filled in.
4177 Otherwise returns NULL. */
4179 static unsigned char *
4180 read_debug_line_header (struct dwarf_section
* section
,
4181 unsigned char * data
,
4182 unsigned char * end
,
4183 DWARF2_Internal_LineInfo
* linfo
,
4184 unsigned char ** end_of_sequence
)
4186 unsigned char *hdrptr
;
4188 /* Extract information from the Line Number Program Header.
4189 (section 6.2.4 in the Dwarf3 doc). */
4192 /* Get and check the length of the block. */
4193 SAFE_BYTE_GET_AND_INC (linfo
->li_length
, hdrptr
, 4, end
);
4195 if (linfo
->li_length
== 0xffffffff)
4197 /* This section is 64-bit DWARF 3. */
4198 SAFE_BYTE_GET_AND_INC (linfo
->li_length
, hdrptr
, 8, end
);
4199 linfo
->li_offset_size
= 8;
4202 linfo
->li_offset_size
= 4;
4204 if (linfo
->li_length
> (size_t) (end
- hdrptr
))
4206 /* If the length field has a relocation against it, then we should
4207 not complain if it is inaccurate (and probably negative). This
4208 happens in object files when the .debug_line section is actually
4209 comprised of several different .debug_line.* sections, (some of
4210 which may be removed by linker garbage collection), and a relocation
4211 is used to compute the correct length once that is done. */
4212 if (reloc_at (section
, (hdrptr
- section
->start
) - linfo
->li_offset_size
))
4214 linfo
->li_length
= end
- hdrptr
;
4218 warn (_("The length field (%#" PRIx64
")"
4219 " in the debug_line header is wrong"
4220 " - the section is too small\n"),
4225 end
= hdrptr
+ linfo
->li_length
;
4227 /* Get and check the version number. */
4228 SAFE_BYTE_GET_AND_INC (linfo
->li_version
, hdrptr
, 2, end
);
4230 if (linfo
->li_version
!= 2
4231 && linfo
->li_version
!= 3
4232 && linfo
->li_version
!= 4
4233 && linfo
->li_version
!= 5)
4235 warn (_("Only DWARF version 2, 3, 4 and 5 line info "
4236 "is currently supported.\n"));
4240 if (linfo
->li_version
>= 5)
4242 SAFE_BYTE_GET_AND_INC (linfo
->li_address_size
, hdrptr
, 1, end
);
4244 SAFE_BYTE_GET_AND_INC (linfo
->li_segment_size
, hdrptr
, 1, end
);
4245 if (linfo
->li_segment_size
!= 0)
4247 warn (_("The %s section contains "
4248 "unsupported segment selector size: %d.\n"),
4249 section
->name
, linfo
->li_segment_size
);
4254 SAFE_BYTE_GET_AND_INC (linfo
->li_prologue_length
, hdrptr
,
4255 linfo
->li_offset_size
, end
);
4256 SAFE_BYTE_GET_AND_INC (linfo
->li_min_insn_length
, hdrptr
, 1, end
);
4258 if (linfo
->li_version
>= 4)
4260 SAFE_BYTE_GET_AND_INC (linfo
->li_max_ops_per_insn
, hdrptr
, 1, end
);
4262 if (linfo
->li_max_ops_per_insn
== 0)
4264 warn (_("Invalid maximum operations per insn.\n"));
4269 linfo
->li_max_ops_per_insn
= 1;
4271 SAFE_BYTE_GET_AND_INC (linfo
->li_default_is_stmt
, hdrptr
, 1, end
);
4272 SAFE_SIGNED_BYTE_GET_AND_INC (linfo
->li_line_base
, hdrptr
, 1, end
);
4273 SAFE_BYTE_GET_AND_INC (linfo
->li_line_range
, hdrptr
, 1, end
);
4274 SAFE_BYTE_GET_AND_INC (linfo
->li_opcode_base
, hdrptr
, 1, end
);
4276 *end_of_sequence
= end
;
4280 static unsigned char *
4281 display_formatted_table (unsigned char *data
,
4282 unsigned char *start
,
4284 const DWARF2_Internal_LineInfo
*linfo
,
4285 struct dwarf_section
*section
,
4288 unsigned char *format_start
, format_count
, *format
, formati
;
4289 uint64_t data_count
, datai
;
4290 unsigned int namepass
, last_entry
= 0;
4291 const char * table_name
= is_dir
? N_("Directory Table") : N_("File Name Table");
4293 SAFE_BYTE_GET_AND_INC (format_count
, data
, 1, end
);
4294 if (do_checks
&& format_count
> 5)
4295 warn (_("Unexpectedly large number of columns in the %s (%u)\n"),
4296 table_name
, format_count
);
4298 format_start
= data
;
4299 for (formati
= 0; formati
< format_count
; formati
++)
4301 SKIP_ULEB (data
, end
);
4302 SKIP_ULEB (data
, end
);
4305 warn (_("%s: Corrupt format description entry\n"), table_name
);
4310 READ_ULEB (data_count
, data
, end
);
4311 if (data_count
== 0)
4313 printf (_("\n The %s is empty.\n"), table_name
);
4316 else if (data
>= end
)
4318 warn (_("%s: Corrupt entry count - expected %#" PRIx64
4319 " but none found\n"), table_name
, data_count
);
4323 else if (format_count
== 0)
4325 warn (_("%s: format count is zero, but the table is not empty\n"),
4330 printf (_("\n The %s (offset %#tx, lines %" PRIu64
", columns %u):\n"),
4331 table_name
, data
- start
, data_count
, format_count
);
4333 printf (_(" Entry"));
4334 /* Delay displaying name as the last entry for better screen layout. */
4335 for (namepass
= 0; namepass
< 2; namepass
++)
4337 format
= format_start
;
4338 for (formati
= 0; formati
< format_count
; formati
++)
4340 uint64_t content_type
;
4342 READ_ULEB (content_type
, format
, end
);
4343 if ((content_type
== DW_LNCT_path
) == (namepass
== 1))
4344 switch (content_type
)
4347 printf (_("\tName"));
4349 case DW_LNCT_directory_index
:
4350 printf (_("\tDir"));
4352 case DW_LNCT_timestamp
:
4353 printf (_("\tTime"));
4356 printf (_("\tSize"));
4359 printf (_("\tMD5\t\t\t"));
4362 printf (_("\t(Unknown format content type %" PRIu64
")"),
4365 SKIP_ULEB (format
, end
);
4370 for (datai
= 0; datai
< data_count
; datai
++)
4372 unsigned char *datapass
= data
;
4374 printf (" %d", last_entry
++);
4375 /* Delay displaying name as the last entry for better screen layout. */
4376 for (namepass
= 0; namepass
< 2; namepass
++)
4378 format
= format_start
;
4380 for (formati
= 0; formati
< format_count
; formati
++)
4382 uint64_t content_type
, form
;
4384 READ_ULEB (content_type
, format
, end
);
4385 READ_ULEB (form
, format
, end
);
4386 data
= read_and_display_attr_value (0, form
, 0, start
, data
, end
,
4387 0, 0, linfo
->li_offset_size
,
4388 linfo
->li_version
, NULL
,
4389 ((content_type
== DW_LNCT_path
) != (namepass
== 1)),
4390 section
, NULL
, '\t', -1);
4394 if (data
>= end
&& (datai
< data_count
- 1))
4396 warn (_("\n%s: Corrupt entries list\n"), table_name
);
4405 display_debug_sup (struct dwarf_section
* section
,
4406 void * file ATTRIBUTE_UNUSED
)
4408 unsigned char * start
= section
->start
;
4409 unsigned char * end
= section
->start
+ section
->size
;
4410 unsigned int version
;
4411 char is_supplementary
;
4412 const unsigned char * sup_filename
;
4413 size_t sup_filename_len
;
4414 unsigned int num_read
;
4416 uint64_t checksum_len
;
4419 introduce (section
, true);
4420 if (section
->size
< 4)
4422 error (_("corrupt .debug_sup section: size is too small\n"));
4426 /* Read the data. */
4427 SAFE_BYTE_GET_AND_INC (version
, start
, 2, end
);
4429 warn (_("corrupt .debug_sup section: version < 5"));
4431 SAFE_BYTE_GET_AND_INC (is_supplementary
, start
, 1, end
);
4432 if (is_supplementary
!= 0 && is_supplementary
!= 1)
4433 warn (_("corrupt .debug_sup section: is_supplementary not 0 or 1\n"));
4435 sup_filename
= start
;
4436 if (is_supplementary
&& sup_filename
[0] != 0)
4437 warn (_("corrupt .debug_sup section: filename not empty in supplementary section\n"));
4439 sup_filename_len
= strnlen ((const char *) start
, end
- start
);
4440 if (sup_filename_len
== (size_t) (end
- start
))
4442 error (_("corrupt .debug_sup section: filename is not NUL terminated\n"));
4445 start
+= sup_filename_len
+ 1;
4447 checksum_len
= read_leb128 (start
, end
, false /* unsigned */, & num_read
, & status
);
4450 error (_("corrupt .debug_sup section: bad LEB128 field for checksum length\n"));
4454 if (checksum_len
> (size_t) (end
- start
))
4456 error (_("corrupt .debug_sup section: checksum length is longer than the remaining section length\n"));
4457 checksum_len
= end
- start
;
4459 else if (checksum_len
< (size_t) (end
- start
))
4461 warn (_("corrupt .debug_sup section: there are %#" PRIx64
4462 " extra, unused bytes at the end of the section\n"),
4463 (end
- start
) - checksum_len
);
4466 printf (_(" Version: %u\n"), version
);
4467 printf (_(" Is Supp: %u\n"), is_supplementary
);
4468 printf (_(" Filename: %s\n"), sup_filename
);
4469 printf (_(" Checksum Len: %" PRIu64
"\n"), checksum_len
);
4470 if (checksum_len
> 0)
4472 printf (_(" Checksum: "));
4473 while (checksum_len
--)
4474 printf ("0x%x ", * start
++ );
4481 display_debug_lines_raw (struct dwarf_section
* section
,
4482 unsigned char * data
,
4483 unsigned char * end
,
4486 unsigned char *start
= section
->start
;
4487 int verbose_view
= 0;
4489 introduce (section
, true);
4493 static DWARF2_Internal_LineInfo saved_linfo
;
4494 DWARF2_Internal_LineInfo linfo
;
4495 unsigned char *standard_opcodes
;
4496 unsigned char *end_of_sequence
;
4499 if (startswith (section
->name
, ".debug_line.")
4500 /* Note: the following does not apply to .debug_line.dwo sections.
4501 These are full debug_line sections. */
4502 && strcmp (section
->name
, ".debug_line.dwo") != 0)
4504 /* Sections named .debug_line.<foo> are fragments of a .debug_line
4505 section containing just the Line Number Statements. They are
4506 created by the assembler and intended to be used alongside gcc's
4507 -ffunction-sections command line option. When the linker's
4508 garbage collection decides to discard a .text.<foo> section it
4509 can then also discard the line number information in .debug_line.<foo>.
4511 Since the section is a fragment it does not have the details
4512 needed to fill out a LineInfo structure, so instead we use the
4513 details from the last full debug_line section that we processed. */
4514 end_of_sequence
= end
;
4515 standard_opcodes
= NULL
;
4516 linfo
= saved_linfo
;
4517 /* PR 17531: file: 0522b371. */
4518 if (linfo
.li_line_range
== 0)
4520 warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n"));
4523 reset_state_machine (linfo
.li_default_is_stmt
);
4527 unsigned char * hdrptr
;
4529 if ((hdrptr
= read_debug_line_header (section
, data
, end
, & linfo
,
4530 & end_of_sequence
)) == NULL
)
4533 printf (_(" Offset: %#tx\n"), data
- start
);
4534 printf (_(" Length: %" PRId64
"\n"), linfo
.li_length
);
4535 printf (_(" DWARF Version: %d\n"), linfo
.li_version
);
4536 if (linfo
.li_version
>= 5)
4538 printf (_(" Address size (bytes): %d\n"), linfo
.li_address_size
);
4539 printf (_(" Segment selector (bytes): %d\n"), linfo
.li_segment_size
);
4541 printf (_(" Prologue Length: %d\n"), (int) linfo
.li_prologue_length
);
4542 printf (_(" Minimum Instruction Length: %d\n"), linfo
.li_min_insn_length
);
4543 if (linfo
.li_version
>= 4)
4544 printf (_(" Maximum Ops per Instruction: %d\n"), linfo
.li_max_ops_per_insn
);
4545 printf (_(" Initial value of 'is_stmt': %d\n"), linfo
.li_default_is_stmt
);
4546 printf (_(" Line Base: %d\n"), linfo
.li_line_base
);
4547 printf (_(" Line Range: %d\n"), linfo
.li_line_range
);
4548 printf (_(" Opcode Base: %d\n"), linfo
.li_opcode_base
);
4550 /* PR 17512: file: 1665-6428-0.004. */
4551 if (linfo
.li_line_range
== 0)
4553 warn (_("Line range of 0 is invalid, using 1 instead\n"));
4554 linfo
.li_line_range
= 1;
4557 reset_state_machine (linfo
.li_default_is_stmt
);
4559 /* Display the contents of the Opcodes table. */
4560 standard_opcodes
= hdrptr
;
4562 /* PR 17512: file: 002-417945-0.004. */
4563 if (standard_opcodes
+ linfo
.li_opcode_base
>= end
)
4565 warn (_("Line Base extends beyond end of section\n"));
4569 printf (_("\n Opcodes:\n"));
4571 for (i
= 1; i
< linfo
.li_opcode_base
; i
++)
4572 printf (ngettext (" Opcode %d has %d arg\n",
4573 " Opcode %d has %d args\n",
4574 standard_opcodes
[i
- 1]),
4575 i
, standard_opcodes
[i
- 1]);
4577 /* Display the contents of the Directory table. */
4578 data
= standard_opcodes
+ linfo
.li_opcode_base
- 1;
4580 if (linfo
.li_version
>= 5)
4582 load_debug_section_with_follow (line_str
, file
);
4584 data
= display_formatted_table (data
, start
, end
, &linfo
, section
,
4586 data
= display_formatted_table (data
, start
, end
, &linfo
, section
,
4592 printf (_("\n The Directory Table is empty.\n"));
4595 unsigned int last_dir_entry
= 0;
4597 printf (_("\n The Directory Table (offset %#tx):\n"),
4600 while (data
< end
&& *data
!= 0)
4602 printf (" %d\t%.*s\n", ++last_dir_entry
, (int) (end
- data
), data
);
4604 data
+= strnlen ((char *) data
, end
- data
);
4609 /* PR 17512: file: 002-132094-0.004. */
4610 if (data
>= end
- 1)
4614 /* Skip the NUL at the end of the table. */
4618 /* Display the contents of the File Name table. */
4619 if (data
>= end
|| *data
== 0)
4620 printf (_("\n The File Name Table is empty.\n"));
4623 printf (_("\n The File Name Table (offset %#tx):\n"),
4625 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
4627 while (data
< end
&& *data
!= 0)
4629 unsigned char *name
;
4632 printf (" %d\t", ++state_machine_regs
.last_file_entry
);
4634 data
+= strnlen ((char *) data
, end
- data
);
4638 READ_ULEB (val
, data
, end
);
4639 printf ("%" PRIu64
"\t", val
);
4640 READ_ULEB (val
, data
, end
);
4641 printf ("%" PRIu64
"\t", val
);
4642 READ_ULEB (val
, data
, end
);
4643 printf ("%" PRIu64
"\t", val
);
4644 printf ("%.*s\n", (int)(end
- name
), name
);
4648 warn (_("Corrupt file name table entry\n"));
4654 /* Skip the NUL at the end of the table. */
4660 saved_linfo
= linfo
;
4663 /* Now display the statements. */
4664 if (data
>= end_of_sequence
)
4665 printf (_(" No Line Number Statements.\n"));
4668 printf (_(" Line Number Statements:\n"));
4670 while (data
< end_of_sequence
)
4672 unsigned char op_code
;
4676 printf (" [0x%08tx]", data
- start
);
4680 if (op_code
>= linfo
.li_opcode_base
)
4682 op_code
-= linfo
.li_opcode_base
;
4683 uladv
= (op_code
/ linfo
.li_line_range
);
4684 if (linfo
.li_max_ops_per_insn
== 1)
4686 uladv
*= linfo
.li_min_insn_length
;
4687 state_machine_regs
.address
+= uladv
;
4689 state_machine_regs
.view
= 0;
4690 printf (_(" Special opcode %d: "
4691 "advance Address by %" PRIu64
4692 " to %#" PRIx64
"%s"),
4693 op_code
, uladv
, state_machine_regs
.address
,
4694 verbose_view
&& uladv
4695 ? _(" (reset view)") : "");
4700 = ((state_machine_regs
.op_index
+ uladv
)
4701 / linfo
.li_max_ops_per_insn
)
4702 * linfo
.li_min_insn_length
;
4704 state_machine_regs
.address
+= addrdelta
;
4705 state_machine_regs
.op_index
4706 = (state_machine_regs
.op_index
+ uladv
)
4707 % linfo
.li_max_ops_per_insn
;
4709 state_machine_regs
.view
= 0;
4710 printf (_(" Special opcode %d: "
4711 "advance Address by %" PRIu64
4712 " to %#" PRIx64
"[%d]%s"),
4713 op_code
, uladv
, state_machine_regs
.address
,
4714 state_machine_regs
.op_index
,
4715 verbose_view
&& addrdelta
4716 ? _(" (reset view)") : "");
4718 adv
= (op_code
% linfo
.li_line_range
) + linfo
.li_line_base
;
4719 state_machine_regs
.line
+= adv
;
4720 printf (_(" and Line by %" PRId64
" to %d"),
4721 adv
, state_machine_regs
.line
);
4722 if (verbose_view
|| state_machine_regs
.view
)
4723 printf (_(" (view %u)\n"), state_machine_regs
.view
);
4726 state_machine_regs
.view
++;
4731 case DW_LNS_extended_op
:
4732 data
+= process_extended_line_op (data
,
4733 linfo
.li_default_is_stmt
,
4738 printf (_(" Copy"));
4739 if (verbose_view
|| state_machine_regs
.view
)
4740 printf (_(" (view %u)\n"), state_machine_regs
.view
);
4743 state_machine_regs
.view
++;
4746 case DW_LNS_advance_pc
:
4747 READ_ULEB (uladv
, data
, end
);
4748 if (linfo
.li_max_ops_per_insn
== 1)
4750 uladv
*= linfo
.li_min_insn_length
;
4751 state_machine_regs
.address
+= uladv
;
4753 state_machine_regs
.view
= 0;
4754 printf (_(" Advance PC by %" PRIu64
4755 " to %#" PRIx64
"%s\n"),
4756 uladv
, state_machine_regs
.address
,
4757 verbose_view
&& uladv
4758 ? _(" (reset view)") : "");
4763 = ((state_machine_regs
.op_index
+ uladv
)
4764 / linfo
.li_max_ops_per_insn
)
4765 * linfo
.li_min_insn_length
;
4766 state_machine_regs
.address
4768 state_machine_regs
.op_index
4769 = (state_machine_regs
.op_index
+ uladv
)
4770 % linfo
.li_max_ops_per_insn
;
4772 state_machine_regs
.view
= 0;
4773 printf (_(" Advance PC by %" PRIu64
4774 " to %#" PRIx64
"[%d]%s\n"),
4775 uladv
, state_machine_regs
.address
,
4776 state_machine_regs
.op_index
,
4777 verbose_view
&& addrdelta
4778 ? _(" (reset view)") : "");
4782 case DW_LNS_advance_line
:
4783 READ_SLEB (adv
, data
, end
);
4784 state_machine_regs
.line
+= adv
;
4785 printf (_(" Advance Line by %" PRId64
" to %d\n"),
4786 adv
, state_machine_regs
.line
);
4789 case DW_LNS_set_file
:
4790 READ_ULEB (uladv
, data
, end
);
4791 printf (_(" Set File Name to entry %" PRIu64
4792 " in the File Name Table\n"), uladv
);
4793 state_machine_regs
.file
= uladv
;
4796 case DW_LNS_set_column
:
4797 READ_ULEB (uladv
, data
, end
);
4798 printf (_(" Set column to %" PRIu64
"\n"), uladv
);
4799 state_machine_regs
.column
= uladv
;
4802 case DW_LNS_negate_stmt
:
4803 adv
= state_machine_regs
.is_stmt
;
4805 printf (_(" Set is_stmt to %" PRId64
"\n"), adv
);
4806 state_machine_regs
.is_stmt
= adv
;
4809 case DW_LNS_set_basic_block
:
4810 printf (_(" Set basic block\n"));
4811 state_machine_regs
.basic_block
= 1;
4814 case DW_LNS_const_add_pc
:
4815 uladv
= ((255 - linfo
.li_opcode_base
) / linfo
.li_line_range
);
4816 if (linfo
.li_max_ops_per_insn
)
4818 uladv
*= linfo
.li_min_insn_length
;
4819 state_machine_regs
.address
+= uladv
;
4821 state_machine_regs
.view
= 0;
4822 printf (_(" Advance PC by constant %" PRIu64
4823 " to %#" PRIx64
"%s\n"),
4824 uladv
, state_machine_regs
.address
,
4825 verbose_view
&& uladv
4826 ? _(" (reset view)") : "");
4831 = ((state_machine_regs
.op_index
+ uladv
)
4832 / linfo
.li_max_ops_per_insn
)
4833 * linfo
.li_min_insn_length
;
4834 state_machine_regs
.address
4836 state_machine_regs
.op_index
4837 = (state_machine_regs
.op_index
+ uladv
)
4838 % linfo
.li_max_ops_per_insn
;
4840 state_machine_regs
.view
= 0;
4841 printf (_(" Advance PC by constant %" PRIu64
4842 " to %#" PRIx64
"[%d]%s\n"),
4843 uladv
, state_machine_regs
.address
,
4844 state_machine_regs
.op_index
,
4845 verbose_view
&& addrdelta
4846 ? _(" (reset view)") : "");
4850 case DW_LNS_fixed_advance_pc
:
4851 SAFE_BYTE_GET_AND_INC (uladv
, data
, 2, end
);
4852 state_machine_regs
.address
+= uladv
;
4853 state_machine_regs
.op_index
= 0;
4854 printf (_(" Advance PC by fixed size amount %" PRIu64
4855 " to %#" PRIx64
"\n"),
4856 uladv
, state_machine_regs
.address
);
4857 /* Do NOT reset view. */
4860 case DW_LNS_set_prologue_end
:
4861 printf (_(" Set prologue_end to true\n"));
4864 case DW_LNS_set_epilogue_begin
:
4865 printf (_(" Set epilogue_begin to true\n"));
4868 case DW_LNS_set_isa
:
4869 READ_ULEB (uladv
, data
, end
);
4870 printf (_(" Set ISA to %" PRIu64
"\n"), uladv
);
4874 printf (_(" Unknown opcode %d with operands: "), op_code
);
4876 if (standard_opcodes
!= NULL
)
4877 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
4879 READ_ULEB (uladv
, data
, end
);
4880 printf ("%#" PRIx64
"%s", uladv
, i
== 1 ? "" : ", ");
4896 unsigned int directory_index
;
4897 unsigned int modification_date
;
4898 unsigned int length
;
4901 /* Output a decoded representation of the .debug_line section. */
4904 display_debug_lines_decoded (struct dwarf_section
* section
,
4905 unsigned char * start
,
4906 unsigned char * data
,
4907 unsigned char * end
,
4910 static DWARF2_Internal_LineInfo saved_linfo
;
4912 introduce (section
, false);
4916 /* This loop amounts to one iteration per compilation unit. */
4917 DWARF2_Internal_LineInfo linfo
;
4918 unsigned char *standard_opcodes
;
4919 unsigned char *end_of_sequence
;
4921 File_Entry
*file_table
= NULL
;
4922 unsigned int n_files
= 0;
4923 char **directory_table
= NULL
;
4924 unsigned int n_directories
= 0;
4926 if (startswith (section
->name
, ".debug_line.")
4927 /* Note: the following does not apply to .debug_line.dwo sections.
4928 These are full debug_line sections. */
4929 && strcmp (section
->name
, ".debug_line.dwo") != 0)
4931 /* See comment in display_debug_lines_raw(). */
4932 end_of_sequence
= end
;
4933 standard_opcodes
= NULL
;
4934 linfo
= saved_linfo
;
4935 /* PR 17531: file: 0522b371. */
4936 if (linfo
.li_line_range
== 0)
4938 warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n"));
4941 reset_state_machine (linfo
.li_default_is_stmt
);
4945 unsigned char *hdrptr
;
4947 if ((hdrptr
= read_debug_line_header (section
, data
, end
, & linfo
,
4948 & end_of_sequence
)) == NULL
)
4951 /* PR 17531: file: 0522b371. */
4952 if (linfo
.li_line_range
== 0)
4954 warn (_("Line range of 0 is invalid, using 1 instead\n"));
4955 linfo
.li_line_range
= 1;
4957 reset_state_machine (linfo
.li_default_is_stmt
);
4959 /* Save a pointer to the contents of the Opcodes table. */
4960 standard_opcodes
= hdrptr
;
4962 /* Traverse the Directory table just to count entries. */
4963 data
= standard_opcodes
+ linfo
.li_opcode_base
- 1;
4967 warn (_("opcode base of %d extends beyond end of section\n"),
4968 linfo
.li_opcode_base
);
4972 if (linfo
.li_version
>= 5)
4974 unsigned char *format_start
, *format
;
4975 unsigned int format_count
, formati
, entryi
;
4977 load_debug_section_with_follow (line_str
, fileptr
);
4979 /* Skip directories format. */
4980 SAFE_BYTE_GET_AND_INC (format_count
, data
, 1, end
);
4981 if (do_checks
&& format_count
> 1)
4982 warn (_("Unexpectedly large number of columns in the directory name table (%u)\n"),
4984 format_start
= data
;
4985 for (formati
= 0; formati
< format_count
; formati
++)
4987 SKIP_ULEB (data
, end
);
4988 SKIP_ULEB (data
, end
);
4991 READ_ULEB (n_directories
, data
, end
);
4994 warn (_("Corrupt directories list\n"));
4998 if (n_directories
== 0)
4999 directory_table
= NULL
;
5001 directory_table
= (char **)
5002 xcalloc (n_directories
, sizeof (unsigned char *));
5004 for (entryi
= 0; entryi
< n_directories
; entryi
++)
5006 char **pathp
= &directory_table
[entryi
];
5008 format
= format_start
;
5009 for (formati
= 0; formati
< format_count
; formati
++)
5011 uint64_t content_type
, form
;
5014 READ_ULEB (content_type
, format
, end
);
5015 READ_ULEB (form
, format
, end
);
5018 warn (_("Corrupt directories list\n"));
5021 switch (content_type
)
5026 case DW_FORM_string
:
5027 *pathp
= (char *) data
;
5029 case DW_FORM_line_strp
:
5030 SAFE_BYTE_GET (uvalue
, data
, linfo
.li_offset_size
,
5032 /* Remove const by the cast. */
5034 fetch_indirect_line_string (uvalue
);
5039 data
= read_and_display_attr_value (0, form
, 0, start
,
5041 linfo
.li_offset_size
,
5048 warn (_("Corrupt directories list\n"));
5053 /* Skip files format. */
5054 SAFE_BYTE_GET_AND_INC (format_count
, data
, 1, end
);
5055 if (do_checks
&& format_count
> 5)
5056 warn (_("Unexpectedly large number of columns in the file name table (%u)\n"),
5058 format_start
= data
;
5059 for (formati
= 0; formati
< format_count
; formati
++)
5061 SKIP_ULEB (data
, end
);
5062 SKIP_ULEB (data
, end
);
5065 READ_ULEB (n_files
, data
, end
);
5066 if (data
>= end
&& n_files
> 0)
5068 warn (_("Corrupt file name list\n"));
5075 file_table
= (File_Entry
*) xcalloc (n_files
,
5076 sizeof (File_Entry
));
5078 for (entryi
= 0; entryi
< n_files
; entryi
++)
5080 File_Entry
*file
= &file_table
[entryi
];
5082 format
= format_start
;
5083 for (formati
= 0; formati
< format_count
; formati
++)
5085 uint64_t content_type
, form
;
5089 READ_ULEB (content_type
, format
, end
);
5090 READ_ULEB (form
, format
, end
);
5093 warn (_("Corrupt file name list\n"));
5096 switch (content_type
)
5101 case DW_FORM_string
:
5102 file
->name
= (char *) data
;
5104 case DW_FORM_line_strp
:
5105 SAFE_BYTE_GET (uvalue
, data
, linfo
.li_offset_size
,
5107 /* Remove const by the cast. */
5108 file
->name
= (char *)
5109 fetch_indirect_line_string (uvalue
);
5113 case DW_LNCT_directory_index
:
5117 SAFE_BYTE_GET (file
->directory_index
, data
, 1,
5121 SAFE_BYTE_GET (file
->directory_index
, data
, 2,
5126 READ_ULEB (file
->directory_index
, tmp
, end
);
5131 data
= read_and_display_attr_value (0, form
, 0, start
,
5133 linfo
.li_offset_size
,
5140 warn (_("Corrupt file name list\n"));
5149 char *ptr_directory_table
= (char *) data
;
5151 while (data
< end
&& *data
!= 0)
5153 data
+= strnlen ((char *) data
, end
- data
);
5162 warn (_("directory table ends unexpectedly\n"));
5167 /* Go through the directory table again to save the directories. */
5168 directory_table
= (char **)
5169 xmalloc (n_directories
* sizeof (unsigned char *));
5172 while (*ptr_directory_table
!= 0)
5174 directory_table
[i
] = ptr_directory_table
;
5175 ptr_directory_table
+= strlen (ptr_directory_table
) + 1;
5179 /* Skip the NUL at the end of the table. */
5182 /* Traverse the File Name table just to count the entries. */
5183 if (data
< end
&& *data
!= 0)
5185 unsigned char *ptr_file_name_table
= data
;
5187 while (data
< end
&& *data
!= 0)
5189 /* Skip Name, directory index, last modification
5190 time and length of file. */
5191 data
+= strnlen ((char *) data
, end
- data
);
5194 SKIP_ULEB (data
, end
);
5195 SKIP_ULEB (data
, end
);
5196 SKIP_ULEB (data
, end
);
5202 warn (_("file table ends unexpectedly\n"));
5207 /* Go through the file table again to save the strings. */
5208 file_table
= (File_Entry
*) xmalloc (n_files
* sizeof (File_Entry
));
5211 while (*ptr_file_name_table
!= 0)
5213 file_table
[i
].name
= (char *) ptr_file_name_table
;
5215 += strlen ((char *) ptr_file_name_table
) + 1;
5217 /* We are not interested in directory, time or size. */
5218 READ_ULEB (file_table
[i
].directory_index
,
5219 ptr_file_name_table
, end
);
5220 READ_ULEB (file_table
[i
].modification_date
,
5221 ptr_file_name_table
, end
);
5222 READ_ULEB (file_table
[i
].length
,
5223 ptr_file_name_table
, end
);
5229 /* Skip the NUL at the end of the table. */
5233 /* Print the Compilation Unit's name and a header. */
5234 if (file_table
== NULL
)
5235 printf (_("CU: No directory table\n"));
5236 else if (directory_table
== NULL
)
5237 printf (_("CU: %s:\n"), null_name (file_table
[0].name
));
5240 unsigned int ix
= file_table
[0].directory_index
;
5241 const char *directory
;
5243 if (ix
== 0 && linfo
.li_version
< 5)
5246 else if (n_directories
== 0)
5247 directory
= _("<unknown>");
5250 if (linfo
.li_version
< 5)
5252 if (ix
>= n_directories
)
5254 warn (_("directory index %u "
5255 ">= number of directories %u\n"),
5257 directory
= _("<corrupt>");
5260 directory
= directory_table
[ix
];
5263 printf (_("CU: %s/%s:\n"),
5264 null_name (directory
),
5265 null_name (file_table
[0].name
));
5267 printf ("%s:\n", null_name (file_table
[0].name
));
5273 printf (_("File name Line number Starting address View Stmt\n"));
5275 printf (_("File name Line number Starting address View Stmt\n"));
5278 printf (_("CU: Empty file name table\n"));
5279 saved_linfo
= linfo
;
5282 /* This loop iterates through the Dwarf Line Number Program. */
5283 while (data
< end_of_sequence
)
5285 unsigned char op_code
;
5288 unsigned long int uladv
;
5289 int is_special_opcode
= 0;
5294 if (op_code
>= linfo
.li_opcode_base
)
5296 op_code
-= linfo
.li_opcode_base
;
5297 uladv
= (op_code
/ linfo
.li_line_range
);
5298 if (linfo
.li_max_ops_per_insn
== 1)
5300 uladv
*= linfo
.li_min_insn_length
;
5301 state_machine_regs
.address
+= uladv
;
5303 state_machine_regs
.view
= 0;
5308 = ((state_machine_regs
.op_index
+ uladv
)
5309 / linfo
.li_max_ops_per_insn
)
5310 * linfo
.li_min_insn_length
;
5311 state_machine_regs
.address
5313 state_machine_regs
.op_index
5314 = (state_machine_regs
.op_index
+ uladv
)
5315 % linfo
.li_max_ops_per_insn
;
5317 state_machine_regs
.view
= 0;
5320 adv
= (op_code
% linfo
.li_line_range
) + linfo
.li_line_base
;
5321 state_machine_regs
.line
+= adv
;
5322 is_special_opcode
= 1;
5323 /* Increment view after printing this row. */
5328 case DW_LNS_extended_op
:
5330 unsigned int ext_op_code_len
;
5331 unsigned char ext_op_code
;
5332 unsigned char *op_code_end
;
5333 unsigned char *op_code_data
= data
;
5335 READ_ULEB (ext_op_code_len
, op_code_data
, end_of_sequence
);
5336 op_code_end
= op_code_data
+ ext_op_code_len
;
5337 if (ext_op_code_len
== 0 || op_code_end
> end_of_sequence
)
5339 warn (_("Badly formed extended line op encountered!\n"));
5342 ext_op_code
= *op_code_data
++;
5346 switch (ext_op_code
)
5348 case DW_LNE_end_sequence
:
5349 /* Reset stuff after printing this row. */
5351 case DW_LNE_set_address
:
5352 SAFE_BYTE_GET_AND_INC (state_machine_regs
.address
,
5354 op_code_end
- op_code_data
,
5356 state_machine_regs
.op_index
= 0;
5357 state_machine_regs
.view
= 0;
5359 case DW_LNE_define_file
:
5360 file_table
= (File_Entry
*) xrealloc
5361 (file_table
, (n_files
+ 1) * sizeof (File_Entry
));
5363 ++state_machine_regs
.last_file_entry
;
5364 /* Source file name. */
5365 file_table
[n_files
].name
= (char *) op_code_data
;
5366 op_code_data
+= strlen ((char *) op_code_data
) + 1;
5367 /* Directory index. */
5368 READ_ULEB (file_table
[n_files
].directory_index
,
5369 op_code_data
, op_code_end
);
5370 /* Last modification time. */
5371 READ_ULEB (file_table
[n_files
].modification_date
,
5372 op_code_data
, op_code_end
);
5374 READ_ULEB (file_table
[n_files
].length
,
5375 op_code_data
, op_code_end
);
5379 case DW_LNE_set_discriminator
:
5380 case DW_LNE_HP_set_sequence
:
5381 /* Simply ignored. */
5385 printf (_("UNKNOWN (%u): length %ld\n"),
5386 ext_op_code
, (long int) (op_code_data
- data
));
5393 /* Increment view after printing this row. */
5396 case DW_LNS_advance_pc
:
5397 READ_ULEB (uladv
, data
, end
);
5398 if (linfo
.li_max_ops_per_insn
== 1)
5400 uladv
*= linfo
.li_min_insn_length
;
5401 state_machine_regs
.address
+= uladv
;
5403 state_machine_regs
.view
= 0;
5408 = ((state_machine_regs
.op_index
+ uladv
)
5409 / linfo
.li_max_ops_per_insn
)
5410 * linfo
.li_min_insn_length
;
5411 state_machine_regs
.address
5413 state_machine_regs
.op_index
5414 = (state_machine_regs
.op_index
+ uladv
)
5415 % linfo
.li_max_ops_per_insn
;
5417 state_machine_regs
.view
= 0;
5421 case DW_LNS_advance_line
:
5422 READ_SLEB (adv
, data
, end
);
5423 state_machine_regs
.line
+= adv
;
5426 case DW_LNS_set_file
:
5427 READ_ULEB (uladv
, data
, end
);
5428 state_machine_regs
.file
= uladv
;
5430 unsigned file
= state_machine_regs
.file
;
5431 if (linfo
.li_version
< 5)
5434 if (file_table
== NULL
|| n_files
== 0)
5435 printf (_("\n [Use file table entry %d]\n"), file
);
5437 else if (file
>= n_files
)
5439 warn (_("file index %u >= number of files %u\n"),
5441 printf (_("\n <over large file table index %u>"), file
);
5445 unsigned dir
= file_table
[file
].directory_index
;
5446 if (dir
== 0 && linfo
.li_version
< 5)
5447 /* If directory index is 0, that means compilation
5448 current directory. bfd/dwarf2.c shows
5449 DW_AT_comp_dir here but in keeping with the
5450 readelf practice of minimal interpretation of
5451 file data, we show "./". */
5452 printf ("\n./%s:[++]\n",
5453 null_name (file_table
[file
].name
));
5454 else if (directory_table
== NULL
|| n_directories
== 0)
5455 printf (_("\n [Use file %s "
5456 "in directory table entry %d]\n"),
5457 null_name (file_table
[file
].name
), dir
);
5460 if (linfo
.li_version
< 5)
5463 if (dir
>= n_directories
)
5465 warn (_("directory index %u "
5466 ">= number of directories %u\n"),
5467 dir
, n_directories
);
5468 printf (_("\n <over large directory table entry "
5472 printf ("\n%s/%s:\n",
5473 null_name (directory_table
[dir
]),
5474 null_name (file_table
[file
].name
));
5479 case DW_LNS_set_column
:
5480 READ_ULEB (uladv
, data
, end
);
5481 state_machine_regs
.column
= uladv
;
5484 case DW_LNS_negate_stmt
:
5485 adv
= state_machine_regs
.is_stmt
;
5487 state_machine_regs
.is_stmt
= adv
;
5490 case DW_LNS_set_basic_block
:
5491 state_machine_regs
.basic_block
= 1;
5494 case DW_LNS_const_add_pc
:
5495 uladv
= ((255 - linfo
.li_opcode_base
) / linfo
.li_line_range
);
5496 if (linfo
.li_max_ops_per_insn
== 1)
5498 uladv
*= linfo
.li_min_insn_length
;
5499 state_machine_regs
.address
+= uladv
;
5501 state_machine_regs
.view
= 0;
5506 = ((state_machine_regs
.op_index
+ uladv
)
5507 / linfo
.li_max_ops_per_insn
)
5508 * linfo
.li_min_insn_length
;
5509 state_machine_regs
.address
5511 state_machine_regs
.op_index
5512 = (state_machine_regs
.op_index
+ uladv
)
5513 % linfo
.li_max_ops_per_insn
;
5515 state_machine_regs
.view
= 0;
5519 case DW_LNS_fixed_advance_pc
:
5520 SAFE_BYTE_GET_AND_INC (uladv
, data
, 2, end
);
5521 state_machine_regs
.address
+= uladv
;
5522 state_machine_regs
.op_index
= 0;
5523 /* Do NOT reset view. */
5526 case DW_LNS_set_prologue_end
:
5529 case DW_LNS_set_epilogue_begin
:
5532 case DW_LNS_set_isa
:
5533 READ_ULEB (uladv
, data
, end
);
5534 printf (_(" Set ISA to %lu\n"), uladv
);
5538 printf (_(" Unknown opcode %d with operands: "), op_code
);
5540 if (standard_opcodes
!= NULL
)
5541 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
5545 READ_ULEB (val
, data
, end
);
5546 printf ("%#" PRIx64
"%s", val
, i
== 1 ? "" : ", ");
5552 /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row
5553 to the DWARF address/line matrix. */
5554 if ((is_special_opcode
) || (xop
== -DW_LNE_end_sequence
)
5555 || (xop
== DW_LNS_copy
))
5557 const unsigned int MAX_FILENAME_LENGTH
= 35;
5558 char *fileName
= NULL
;
5559 char *newFileName
= NULL
;
5560 size_t fileNameLength
;
5564 unsigned indx
= state_machine_regs
.file
;
5566 if (linfo
.li_version
< 5)
5569 if (indx
>= n_files
)
5571 warn (_("file index %u >= number of files %u\n"),
5573 fileName
= _("<corrupt>");
5576 fileName
= (char *) file_table
[indx
].name
;
5579 fileName
= _("<unknown>");
5581 fileNameLength
= strlen (fileName
);
5582 newFileName
= fileName
;
5583 if (fileNameLength
> MAX_FILENAME_LENGTH
&& !do_wide
)
5585 newFileName
= (char *) xmalloc (MAX_FILENAME_LENGTH
+ 1);
5586 /* Truncate file name */
5587 memcpy (newFileName
,
5588 fileName
+ fileNameLength
- MAX_FILENAME_LENGTH
,
5589 MAX_FILENAME_LENGTH
);
5590 newFileName
[MAX_FILENAME_LENGTH
] = 0;
5593 /* A row with end_seq set to true has a meaningful address, but
5594 the other information in the same row is not significant.
5595 In such a row, print line as "-", and don't print
5597 if (!do_wide
|| fileNameLength
<= MAX_FILENAME_LENGTH
)
5599 if (linfo
.li_max_ops_per_insn
== 1)
5601 if (xop
== -DW_LNE_end_sequence
)
5602 printf ("%-31s %11s %#18" PRIx64
,
5604 state_machine_regs
.address
);
5606 printf ("%-31s %11d %#18" PRIx64
,
5607 newFileName
, state_machine_regs
.line
,
5608 state_machine_regs
.address
);
5612 if (xop
== -DW_LNE_end_sequence
)
5613 printf ("%-31s %11s %#18" PRIx64
"[%d]",
5615 state_machine_regs
.address
,
5616 state_machine_regs
.op_index
);
5618 printf ("%-31s %11d %#18" PRIx64
"[%d]",
5619 newFileName
, state_machine_regs
.line
,
5620 state_machine_regs
.address
,
5621 state_machine_regs
.op_index
);
5626 if (linfo
.li_max_ops_per_insn
== 1)
5628 if (xop
== -DW_LNE_end_sequence
)
5629 printf ("%s %11s %#18" PRIx64
,
5631 state_machine_regs
.address
);
5633 printf ("%s %11d %#18" PRIx64
,
5634 newFileName
, state_machine_regs
.line
,
5635 state_machine_regs
.address
);
5639 if (xop
== -DW_LNE_end_sequence
)
5640 printf ("%s %11s %#18" PRIx64
"[%d]",
5642 state_machine_regs
.address
,
5643 state_machine_regs
.op_index
);
5645 printf ("%s %11d %#18" PRIx64
"[%d]",
5646 newFileName
, state_machine_regs
.line
,
5647 state_machine_regs
.address
,
5648 state_machine_regs
.op_index
);
5652 if (xop
!= -DW_LNE_end_sequence
)
5654 if (state_machine_regs
.view
)
5655 printf (" %6u", state_machine_regs
.view
);
5659 if (state_machine_regs
.is_stmt
)
5664 state_machine_regs
.view
++;
5666 if (xop
== -DW_LNE_end_sequence
)
5668 reset_state_machine (linfo
.li_default_is_stmt
);
5672 if (newFileName
!= fileName
)
5684 if (directory_table
)
5686 free (directory_table
);
5687 directory_table
= NULL
;
5698 display_debug_lines (struct dwarf_section
*section
, void *file
)
5700 unsigned char *data
= section
->start
;
5701 unsigned char *end
= data
+ section
->size
;
5703 int retValDecoded
= 1;
5705 if (do_debug_lines
== 0)
5706 do_debug_lines
|= FLAG_DEBUG_LINES_RAW
;
5708 if (do_debug_lines
& FLAG_DEBUG_LINES_RAW
)
5709 retValRaw
= display_debug_lines_raw (section
, data
, end
, file
);
5711 if (do_debug_lines
& FLAG_DEBUG_LINES_DECODED
)
5712 retValDecoded
= display_debug_lines_decoded (section
, data
, data
, end
, file
);
5714 if (!retValRaw
|| !retValDecoded
)
5721 find_debug_info_for_offset (uint64_t offset
)
5725 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
5728 for (i
= 0; i
< num_debug_info_entries
; i
++)
5729 if (debug_information
[i
].cu_offset
== offset
)
5730 return debug_information
+ i
;
5736 get_gdb_index_symbol_kind_name (gdb_index_symbol_kind kind
)
5738 /* See gdb/gdb-index.h. */
5739 static const char * const kinds
[] =
5751 return _ (kinds
[kind
]);
5755 display_debug_pubnames_worker (struct dwarf_section
*section
,
5756 void *file ATTRIBUTE_UNUSED
,
5759 DWARF2_Internal_PubNames names
;
5760 unsigned char *start
= section
->start
;
5761 unsigned char *end
= start
+ section
->size
;
5763 /* It does not matter if this load fails,
5764 we test for that later on. */
5765 load_debug_info (file
);
5767 introduce (section
, false);
5771 unsigned char *data
;
5772 unsigned long sec_off
= start
- section
->start
;
5773 unsigned int offset_size
;
5775 SAFE_BYTE_GET_AND_INC (names
.pn_length
, start
, 4, end
);
5776 if (names
.pn_length
== 0xffffffff)
5778 SAFE_BYTE_GET_AND_INC (names
.pn_length
, start
, 8, end
);
5784 if (names
.pn_length
> (size_t) (end
- start
))
5786 warn (_("Debug info is corrupted, "
5787 "%s header at %#lx has length %#" PRIx64
"\n"),
5788 section
->name
, sec_off
, names
.pn_length
);
5793 start
+= names
.pn_length
;
5795 SAFE_BYTE_GET_AND_INC (names
.pn_version
, data
, 2, start
);
5796 SAFE_BYTE_GET_AND_INC (names
.pn_offset
, data
, offset_size
, start
);
5798 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
5799 && num_debug_info_entries
> 0
5800 && find_debug_info_for_offset (names
.pn_offset
) == NULL
)
5801 warn (_(".debug_info offset of %#" PRIx64
5802 " in %s section does not point to a CU header.\n"),
5803 names
.pn_offset
, section
->name
);
5805 SAFE_BYTE_GET_AND_INC (names
.pn_size
, data
, offset_size
, start
);
5807 printf (_(" Length: %" PRId64
"\n"),
5809 printf (_(" Version: %d\n"),
5811 printf (_(" Offset into .debug_info section: %#" PRIx64
"\n"),
5813 printf (_(" Size of area in .debug_info section: %" PRId64
"\n"),
5816 if (names
.pn_version
!= 2 && names
.pn_version
!= 3)
5818 static int warned
= 0;
5822 warn (_("Only DWARF 2 and 3 pubnames are currently supported\n"));
5830 printf (_("\n Offset Kind Name\n"));
5832 printf (_("\n Offset\tName\n"));
5839 SAFE_BYTE_GET_AND_INC (offset
, data
, offset_size
, start
);
5846 maxprint
= (start
- data
) - 1;
5850 unsigned int kind_data
;
5851 gdb_index_symbol_kind kind
;
5852 const char *kind_name
;
5855 SAFE_BYTE_GET_AND_INC (kind_data
, data
, 1, start
);
5857 /* GCC computes the kind as the upper byte in the CU index
5858 word, and then right shifts it by the CU index size.
5859 Left shift KIND to where the gdb-index.h accessor macros
5861 kind_data
<<= GDB_INDEX_CU_BITSIZE
;
5862 kind
= GDB_INDEX_SYMBOL_KIND_VALUE (kind_data
);
5863 kind_name
= get_gdb_index_symbol_kind_name (kind
);
5864 is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (kind_data
);
5865 printf (" %-6" PRIx64
" %s,%-10s %.*s\n",
5866 offset
, is_static
? _("s") : _("g"),
5867 kind_name
, (int) maxprint
, data
);
5870 printf (" %-6" PRIx64
"\t%.*s\n",
5871 offset
, (int) maxprint
, data
);
5873 data
+= strnlen ((char *) data
, maxprint
);
5886 display_debug_pubnames (struct dwarf_section
*section
, void *file
)
5888 return display_debug_pubnames_worker (section
, file
, 0);
5892 display_debug_gnu_pubnames (struct dwarf_section
*section
, void *file
)
5894 return display_debug_pubnames_worker (section
, file
, 1);
5898 display_debug_macinfo (struct dwarf_section
*section
,
5899 void *file ATTRIBUTE_UNUSED
)
5901 unsigned char *start
= section
->start
;
5902 unsigned char *end
= start
+ section
->size
;
5903 unsigned char *curr
= start
;
5904 enum dwarf_macinfo_record_type op
;
5906 introduce (section
, false);
5910 unsigned int lineno
;
5911 const unsigned char *string
;
5913 op
= (enum dwarf_macinfo_record_type
) *curr
;
5918 case DW_MACINFO_start_file
:
5920 unsigned int filenum
;
5922 READ_ULEB (lineno
, curr
, end
);
5923 READ_ULEB (filenum
, curr
, end
);
5924 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"),
5929 case DW_MACINFO_end_file
:
5930 printf (_(" DW_MACINFO_end_file\n"));
5933 case DW_MACINFO_define
:
5934 READ_ULEB (lineno
, curr
, end
);
5936 curr
+= strnlen ((char *) string
, end
- string
);
5937 printf (_(" DW_MACINFO_define - lineno : %d macro : %*s\n"),
5938 lineno
, (int) (curr
- string
), string
);
5943 case DW_MACINFO_undef
:
5944 READ_ULEB (lineno
, curr
, end
);
5946 curr
+= strnlen ((char *) string
, end
- string
);
5947 printf (_(" DW_MACINFO_undef - lineno : %d macro : %*s\n"),
5948 lineno
, (int) (curr
- string
), string
);
5953 case DW_MACINFO_vendor_ext
:
5955 unsigned int constant
;
5957 READ_ULEB (constant
, curr
, end
);
5959 curr
+= strnlen ((char *) string
, end
- string
);
5960 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %*s\n"),
5961 constant
, (int) (curr
- string
), string
);
5972 /* Given LINE_OFFSET into the .debug_line section, attempt to return
5973 filename and dirname corresponding to file name table entry with index
5974 FILEIDX. Return NULL on failure. */
5976 static unsigned char *
5977 get_line_filename_and_dirname (uint64_t line_offset
,
5979 unsigned char **dir_name
)
5981 struct dwarf_section
*section
= &debug_displays
[line
].section
;
5982 unsigned char *hdrptr
, *dirtable
, *file_name
;
5983 unsigned int offset_size
;
5984 unsigned int version
, opcode_base
;
5985 uint64_t length
, diridx
;
5986 const unsigned char * end
;
5989 if (section
->start
== NULL
5990 || line_offset
>= section
->size
5994 hdrptr
= section
->start
+ line_offset
;
5995 end
= section
->start
+ section
->size
;
5997 SAFE_BYTE_GET_AND_INC (length
, hdrptr
, 4, end
);
5998 if (length
== 0xffffffff)
6000 /* This section is 64-bit DWARF 3. */
6001 SAFE_BYTE_GET_AND_INC (length
, hdrptr
, 8, end
);
6007 if (length
> (size_t) (end
- hdrptr
)
6008 || length
< 2 + offset_size
+ 1 + 3 + 1)
6010 end
= hdrptr
+ length
;
6012 SAFE_BYTE_GET_AND_INC (version
, hdrptr
, 2, end
);
6013 if (version
!= 2 && version
!= 3 && version
!= 4)
6015 hdrptr
+= offset_size
+ 1;/* Skip prologue_length and min_insn_length. */
6017 hdrptr
++; /* Skip max_ops_per_insn. */
6018 hdrptr
+= 3; /* Skip default_is_stmt, line_base, line_range. */
6020 SAFE_BYTE_GET_AND_INC (opcode_base
, hdrptr
, 1, end
);
6021 if (opcode_base
== 0
6022 || opcode_base
- 1 >= (size_t) (end
- hdrptr
))
6025 hdrptr
+= opcode_base
- 1;
6028 /* Skip over dirname table. */
6029 while (*hdrptr
!= '\0')
6031 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
);
6037 hdrptr
++; /* Skip the NUL at the end of the table. */
6039 /* Now skip over preceding filename table entries. */
6040 for (; hdrptr
< end
&& *hdrptr
!= '\0' && fileidx
> 1; fileidx
--)
6042 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
);
6045 SKIP_ULEB (hdrptr
, end
);
6046 SKIP_ULEB (hdrptr
, end
);
6047 SKIP_ULEB (hdrptr
, end
);
6049 if (hdrptr
>= end
|| *hdrptr
== '\0')
6053 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
);
6058 READ_ULEB (diridx
, hdrptr
, end
);
6061 for (; dirtable
< end
&& *dirtable
!= '\0' && diridx
> 1; diridx
--)
6063 dirtable
+= strnlen ((char *) dirtable
, end
- dirtable
);
6067 if (dirtable
>= end
|| *dirtable
== '\0')
6069 *dir_name
= dirtable
;
6074 display_debug_macro (struct dwarf_section
*section
,
6077 unsigned char *start
= section
->start
;
6078 unsigned char *end
= start
+ section
->size
;
6079 unsigned char *curr
= start
;
6080 unsigned char *extended_op_buf
[256];
6081 bool is_dwo
= false;
6082 const char *suffix
= strrchr (section
->name
, '.');
6084 if (suffix
&& strcmp (suffix
, ".dwo") == 0)
6087 load_debug_section_with_follow (str
, file
);
6088 load_debug_section_with_follow (line
, file
);
6089 load_debug_section_with_follow (str_index
, file
);
6091 introduce (section
, false);
6095 unsigned int lineno
, version
, flags
;
6096 unsigned int offset_size
;
6097 const unsigned char *string
;
6098 uint64_t line_offset
= 0, sec_offset
= curr
- start
, offset
;
6099 unsigned char **extended_ops
= NULL
;
6101 SAFE_BYTE_GET_AND_INC (version
, curr
, 2, end
);
6102 if (version
!= 4 && version
!= 5)
6104 error (_("Expected to find a version number of 4 or 5 in section %s but found %d instead\n"),
6105 section
->name
, version
);
6109 SAFE_BYTE_GET_AND_INC (flags
, curr
, 1, end
);
6110 offset_size
= (flags
& 1) ? 8 : 4;
6111 printf (_(" Offset: %#" PRIx64
"\n"), sec_offset
);
6112 printf (_(" Version: %d\n"), version
);
6113 printf (_(" Offset size: %d\n"), offset_size
);
6116 SAFE_BYTE_GET_AND_INC (line_offset
, curr
, offset_size
, end
);
6117 printf (_(" Offset into .debug_line: %#" PRIx64
"\n"),
6122 unsigned int i
, count
, op
;
6125 SAFE_BYTE_GET_AND_INC (count
, curr
, 1, end
);
6127 memset (extended_op_buf
, 0, sizeof (extended_op_buf
));
6128 extended_ops
= extended_op_buf
;
6131 printf (_(" Extension opcode arguments:\n"));
6132 for (i
= 0; i
< count
; i
++)
6134 SAFE_BYTE_GET_AND_INC (op
, curr
, 1, end
);
6135 extended_ops
[op
] = curr
;
6136 READ_ULEB (nargs
, curr
, end
);
6138 printf (_(" DW_MACRO_%02x has no arguments\n"), op
);
6141 printf (_(" DW_MACRO_%02x arguments: "), op
);
6142 for (n
= 0; n
< nargs
; n
++)
6146 SAFE_BYTE_GET_AND_INC (form
, curr
, 1, end
);
6147 printf ("%s%s", get_FORM_name (form
),
6148 n
== nargs
- 1 ? "\n" : ", ");
6158 case DW_FORM_block1
:
6159 case DW_FORM_block2
:
6160 case DW_FORM_block4
:
6162 case DW_FORM_string
:
6164 case DW_FORM_sec_offset
:
6167 error (_("Invalid extension opcode form %s\n"),
6168 get_FORM_name (form
));
6184 error (_(".debug_macro section not zero terminated\n"));
6188 SAFE_BYTE_GET_AND_INC (op
, curr
, 1, end
);
6194 case DW_MACRO_define
:
6195 READ_ULEB (lineno
, curr
, end
);
6197 curr
+= strnlen ((char *) string
, end
- string
);
6198 printf (_(" DW_MACRO_define - lineno : %d macro : %*s\n"),
6199 lineno
, (int) (curr
- string
), string
);
6204 case DW_MACRO_undef
:
6205 READ_ULEB (lineno
, curr
, end
);
6207 curr
+= strnlen ((char *) string
, end
- string
);
6208 printf (_(" DW_MACRO_undef - lineno : %d macro : %*s\n"),
6209 lineno
, (int) (curr
- string
), string
);
6214 case DW_MACRO_start_file
:
6216 unsigned int filenum
;
6217 unsigned char *file_name
= NULL
, *dir_name
= NULL
;
6219 READ_ULEB (lineno
, curr
, end
);
6220 READ_ULEB (filenum
, curr
, end
);
6222 if ((flags
& 2) == 0)
6223 error (_("DW_MACRO_start_file used, but no .debug_line offset provided.\n"));
6226 = get_line_filename_and_dirname (line_offset
, filenum
,
6228 if (file_name
== NULL
)
6229 printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d\n"),
6232 printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d filename: %s%s%s\n"),
6234 dir_name
!= NULL
? (const char *) dir_name
: "",
6235 dir_name
!= NULL
? "/" : "", file_name
);
6239 case DW_MACRO_end_file
:
6240 printf (_(" DW_MACRO_end_file\n"));
6243 case DW_MACRO_define_strp
:
6244 READ_ULEB (lineno
, curr
, end
);
6245 if (version
== 4 && is_dwo
)
6246 READ_ULEB (offset
, curr
, end
);
6248 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6249 string
= fetch_indirect_string (offset
);
6250 printf (_(" DW_MACRO_define_strp - lineno : %d macro : %s\n"),
6254 case DW_MACRO_undef_strp
:
6255 READ_ULEB (lineno
, curr
, end
);
6256 if (version
== 4 && is_dwo
)
6257 READ_ULEB (offset
, curr
, end
);
6259 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6260 string
= fetch_indirect_string (offset
);
6261 printf (_(" DW_MACRO_undef_strp - lineno : %d macro : %s\n"),
6265 case DW_MACRO_import
:
6266 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6267 printf (_(" DW_MACRO_import - offset : %#" PRIx64
"\n"),
6271 case DW_MACRO_define_sup
:
6272 READ_ULEB (lineno
, curr
, end
);
6273 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6274 printf (_(" DW_MACRO_define_sup - lineno : %d"
6275 " macro offset : %#" PRIx64
"\n"),
6279 case DW_MACRO_undef_sup
:
6280 READ_ULEB (lineno
, curr
, end
);
6281 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6282 printf (_(" DW_MACRO_undef_sup - lineno : %d"
6283 " macro offset : %#" PRIx64
"\n"),
6287 case DW_MACRO_import_sup
:
6288 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6289 printf (_(" DW_MACRO_import_sup - offset : %#" PRIx64
"\n"),
6293 case DW_MACRO_define_strx
:
6294 case DW_MACRO_undef_strx
:
6295 READ_ULEB (lineno
, curr
, end
);
6296 READ_ULEB (offset
, curr
, end
);
6297 string
= (const unsigned char *)
6298 fetch_indexed_string (offset
, NULL
, offset_size
, false, 0);
6299 if (op
== DW_MACRO_define_strx
)
6300 printf (" DW_MACRO_define_strx ");
6302 printf (" DW_MACRO_undef_strx ");
6304 printf (_("(with offset %#" PRIx64
") "), offset
);
6305 printf (_("lineno : %d macro : %s\n"),
6310 if (op
>= DW_MACRO_lo_user
&& op
<= DW_MACRO_hi_user
)
6312 printf (_(" <Target Specific macro op: %#x - UNHANDLED"), op
);
6316 if (extended_ops
== NULL
|| extended_ops
[op
] == NULL
)
6318 error (_(" Unknown macro opcode %02x seen\n"), op
);
6323 /* Skip over unhandled opcodes. */
6325 unsigned char *desc
= extended_ops
[op
];
6326 READ_ULEB (nargs
, desc
, end
);
6329 printf (_(" DW_MACRO_%02x\n"), op
);
6332 printf (_(" DW_MACRO_%02x -"), op
);
6333 for (n
= 0; n
< nargs
; n
++)
6337 /* DW_FORM_implicit_const is not expected here. */
6338 SAFE_BYTE_GET_AND_INC (val
, desc
, 1, end
);
6340 = read_and_display_attr_value (0, val
, 0,
6341 start
, curr
, end
, 0, 0,
6342 offset_size
, version
,
6361 display_debug_abbrev (struct dwarf_section
*section
,
6362 void *file ATTRIBUTE_UNUSED
)
6364 abbrev_entry
*entry
;
6365 unsigned char *start
= section
->start
;
6367 introduce (section
, false);
6371 uint64_t offset
= start
- section
->start
;
6372 abbrev_list
*list
= find_and_process_abbrev_set (section
, 0,
6373 section
->size
, offset
,
6378 if (list
->first_abbrev
)
6379 printf (_(" Number TAG (%#" PRIx64
")\n"), offset
);
6381 for (entry
= list
->first_abbrev
; entry
; entry
= entry
->next
)
6385 printf (" %ld %s [%s]\n",
6387 get_TAG_name (entry
->tag
),
6388 entry
->children
? _("has children") : _("no children"));
6390 for (attr
= entry
->first_attr
; attr
; attr
= attr
->next
)
6392 printf (" %-18s %s",
6393 get_AT_name (attr
->attribute
),
6394 get_FORM_name (attr
->form
));
6395 if (attr
->form
== DW_FORM_implicit_const
)
6396 printf (": %" PRId64
, attr
->implicit_const
);
6400 start
= list
->start_of_next_abbrevs
;
6401 free_abbrev_list (list
);
6410 /* Return true when ADDR is the maximum address, when addresses are
6411 POINTER_SIZE bytes long. */
6414 is_max_address (uint64_t addr
, unsigned int pointer_size
)
6416 uint64_t mask
= ~(~(uint64_t) 0 << 1 << (pointer_size
* 8 - 1));
6417 return ((addr
& mask
) == mask
);
6420 /* Display a view pair list starting at *VSTART_PTR and ending at
6421 VLISTEND within SECTION. */
6424 display_view_pair_list (struct dwarf_section
*section
,
6425 unsigned char **vstart_ptr
,
6426 unsigned int debug_info_entry
,
6427 unsigned char *vlistend
)
6429 unsigned char *vstart
= *vstart_ptr
;
6430 unsigned char *section_end
= section
->start
+ section
->size
;
6431 unsigned int pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
6433 if (vlistend
< section_end
)
6434 section_end
= vlistend
;
6438 while (vstart
< section_end
)
6440 uint64_t off
= vstart
- section
->start
;
6441 uint64_t vbegin
, vend
;
6443 READ_ULEB (vbegin
, vstart
, section_end
);
6444 if (vstart
== section_end
)
6447 READ_ULEB (vend
, vstart
, section_end
);
6448 printf (" %8.8" PRIx64
" ", off
);
6450 print_view (vbegin
, pointer_size
);
6451 print_view (vend
, pointer_size
);
6452 printf (_("location view pair\n"));
6456 *vstart_ptr
= vstart
;
6459 /* Display a location list from a normal (ie, non-dwo) .debug_loc section. */
6462 display_loc_list (struct dwarf_section
*section
,
6463 unsigned char **start_ptr
,
6464 unsigned int debug_info_entry
,
6466 uint64_t base_address
,
6467 unsigned char **vstart_ptr
,
6470 unsigned char *start
= *start_ptr
, *vstart
= *vstart_ptr
;
6471 unsigned char *section_end
= section
->start
+ section
->size
;
6473 unsigned int pointer_size
;
6474 unsigned int offset_size
;
6478 unsigned short length
;
6479 int need_frame_base
;
6481 if (debug_info_entry
>= num_debug_info_entries
)
6483 warn (_("No debug information available for loc lists of entry: %u\n"),
6488 cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
6489 pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
6490 offset_size
= debug_information
[debug_info_entry
].offset_size
;
6491 dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
6493 if (pointer_size
< 2 || pointer_size
> 8)
6495 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
6496 pointer_size
, debug_info_entry
);
6502 uint64_t off
= offset
+ (start
- *start_ptr
);
6503 uint64_t vbegin
= -1, vend
= -1;
6505 if (2 * pointer_size
> (size_t) (section_end
- start
))
6507 warn (_("Location list starting at offset %#" PRIx64
6508 " is not terminated.\n"), offset
);
6515 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, section_end
);
6516 SAFE_BYTE_GET_AND_INC (end
, start
, pointer_size
, section_end
);
6518 if (begin
== 0 && end
== 0)
6520 /* PR 18374: In a object file we can have a location list that
6521 starts with a begin and end of 0 because there are relocations
6522 that need to be applied to the addresses. Actually applying
6523 the relocations now does not help as they will probably resolve
6524 to 0, since the object file has not been fully linked. Real
6525 end of list markers will not have any relocations against them. */
6526 if (! reloc_at (section
, off
)
6527 && ! reloc_at (section
, off
+ pointer_size
))
6529 printf (_("<End of list>\n"));
6534 /* Check base address specifiers. */
6535 if (is_max_address (begin
, pointer_size
)
6536 && !is_max_address (end
, pointer_size
))
6539 print_hex (begin
, pointer_size
);
6540 print_hex (end
, pointer_size
);
6541 printf (_("(base address)\n"));
6547 off
= offset
+ (vstart
- *start_ptr
);
6549 READ_ULEB (vbegin
, vstart
, section_end
);
6550 print_view (vbegin
, pointer_size
);
6552 READ_ULEB (vend
, vstart
, section_end
);
6553 print_view (vend
, pointer_size
);
6555 printf (_("views at %8.8" PRIx64
" for:\n %*s "), off
, 8, "");
6558 if (2 > (size_t) (section_end
- start
))
6560 warn (_("Location list starting at offset %#" PRIx64
6561 " is not terminated.\n"), offset
);
6565 SAFE_BYTE_GET_AND_INC (length
, start
, 2, section_end
);
6567 if (length
> (size_t) (section_end
- start
))
6569 warn (_("Location list starting at offset %#" PRIx64
6570 " is not terminated.\n"), offset
);
6574 print_hex (begin
+ base_address
, pointer_size
);
6575 print_hex (end
+ base_address
, pointer_size
);
6578 need_frame_base
= decode_location_expression (start
,
6583 cu_offset
, section
);
6586 if (need_frame_base
&& !has_frame_base
)
6587 printf (_(" [without DW_AT_frame_base]"));
6589 if (begin
== end
&& vbegin
== vend
)
6590 fputs (_(" (start == end)"), stdout
);
6591 else if (begin
> end
|| (begin
== end
&& vbegin
> vend
))
6592 fputs (_(" (start > end)"), stdout
);
6600 *vstart_ptr
= vstart
;
6603 /* Display a location list from a normal (ie, non-dwo) .debug_loclists section. */
6606 display_loclists_list (struct dwarf_section
* section
,
6607 unsigned char ** start_ptr
,
6608 unsigned int debug_info_entry
,
6610 uint64_t base_address
,
6611 unsigned char ** vstart_ptr
,
6614 unsigned char *start
= *start_ptr
;
6615 unsigned char *vstart
= *vstart_ptr
;
6616 unsigned char *section_end
= section
->start
+ section
->size
;
6618 unsigned int pointer_size
;
6619 unsigned int offset_size
;
6620 unsigned int dwarf_version
;
6622 /* Initialize it due to a false compiler warning. */
6623 uint64_t begin
= -1, vbegin
= -1;
6624 uint64_t end
= -1, vend
= -1;
6626 int need_frame_base
;
6628 if (debug_info_entry
>= num_debug_info_entries
)
6630 warn (_("No debug information available for "
6631 "loclists lists of entry: %u\n"),
6636 cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
6637 pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
6638 offset_size
= debug_information
[debug_info_entry
].offset_size
;
6639 dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
6641 if (pointer_size
< 2 || pointer_size
> 8)
6643 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
6644 pointer_size
, debug_info_entry
);
6650 uint64_t off
= offset
+ (start
- *start_ptr
);
6651 enum dwarf_location_list_entry_type llet
;
6653 if (start
+ 1 > section_end
)
6655 warn (_("Location list starting at offset %#" PRIx64
6656 " is not terminated.\n"), offset
);
6663 SAFE_BYTE_GET_AND_INC (llet
, start
, 1, section_end
);
6665 if (vstart
&& (llet
== DW_LLE_offset_pair
6666 || llet
== DW_LLE_start_end
6667 || llet
== DW_LLE_start_length
))
6669 off
= offset
+ (vstart
- *start_ptr
);
6671 READ_ULEB (vbegin
, vstart
, section_end
);
6672 print_view (vbegin
, pointer_size
);
6674 READ_ULEB (vend
, vstart
, section_end
);
6675 print_view (vend
, pointer_size
);
6677 printf (_("views at %8.8" PRIx64
" for:\n %*s "), off
, 8, "");
6682 case DW_LLE_end_of_list
:
6683 printf (_("<End of list>\n"));
6686 case DW_LLE_base_addressx
:
6687 READ_ULEB (base_address
, start
, section_end
);
6688 print_hex (base_address
, pointer_size
);
6689 printf (_("(index into .debug_addr) "));
6690 base_address
= fetch_indexed_addr (base_address
, pointer_size
);
6691 print_hex (base_address
, pointer_size
);
6692 printf (_("(base address)\n"));
6695 case DW_LLE_startx_endx
:
6696 READ_ULEB (begin
, start
, section_end
);
6697 begin
= fetch_indexed_addr (begin
, pointer_size
);
6698 READ_ULEB (end
, start
, section_end
);
6699 end
= fetch_indexed_addr (end
, pointer_size
);
6702 case DW_LLE_startx_length
:
6703 READ_ULEB (begin
, start
, section_end
);
6704 begin
= fetch_indexed_addr (begin
, pointer_size
);
6705 READ_ULEB (end
, start
, section_end
);
6709 case DW_LLE_default_location
:
6713 case DW_LLE_offset_pair
:
6714 READ_ULEB (begin
, start
, section_end
);
6715 begin
+= base_address
;
6716 READ_ULEB (end
, start
, section_end
);
6717 end
+= base_address
;
6720 case DW_LLE_base_address
:
6721 SAFE_BYTE_GET_AND_INC (base_address
, start
, pointer_size
,
6723 print_hex (base_address
, pointer_size
);
6724 printf (_("(base address)\n"));
6727 case DW_LLE_start_end
:
6728 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, section_end
);
6729 SAFE_BYTE_GET_AND_INC (end
, start
, pointer_size
, section_end
);
6732 case DW_LLE_start_length
:
6733 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, section_end
);
6734 READ_ULEB (end
, start
, section_end
);
6738 #ifdef DW_LLE_view_pair
6739 case DW_LLE_view_pair
:
6741 printf (_("View pair entry in loclist with locviews attribute\n"));
6742 READ_ULEB (vbegin
, start
, section_end
);
6743 print_view (vbegin
, pointer_size
);
6745 READ_ULEB (vend
, start
, section_end
);
6746 print_view (vend
, pointer_size
);
6748 printf (_("views for:\n"));
6753 error (_("Invalid location list entry type %d\n"), llet
);
6757 if (llet
== DW_LLE_end_of_list
)
6760 if (llet
== DW_LLE_base_address
6761 || llet
== DW_LLE_base_addressx
)
6764 if (start
== section_end
)
6766 warn (_("Location list starting at offset %#" PRIx64
6767 " is not terminated.\n"), offset
);
6770 READ_ULEB (length
, start
, section_end
);
6772 if (length
> (size_t) (section_end
- start
))
6774 warn (_("Location list starting at offset %#" PRIx64
6775 " is not terminated.\n"), offset
);
6779 print_hex (begin
, pointer_size
);
6780 print_hex (end
, pointer_size
);
6783 need_frame_base
= decode_location_expression (start
,
6788 cu_offset
, section
);
6791 if (need_frame_base
&& !has_frame_base
)
6792 printf (_(" [without DW_AT_frame_base]"));
6794 if (begin
== end
&& vbegin
== vend
)
6795 fputs (_(" (start == end)"), stdout
);
6796 else if (begin
> end
|| (begin
== end
&& vbegin
> vend
))
6797 fputs (_(" (start > end)"), stdout
);
6805 if (vbegin
!= (uint64_t) -1 || vend
!= (uint64_t) -1)
6806 printf (_("Trailing view pair not used in a range"));
6809 *vstart_ptr
= vstart
;
6812 /* Print a .debug_addr table index in decimal, surrounded by square brackets,
6813 right-adjusted in a field of length LEN, and followed by a space. */
6816 print_addr_index (unsigned int idx
, unsigned int len
)
6818 static char buf
[15];
6819 snprintf (buf
, sizeof (buf
), "[%d]", idx
);
6820 printf ("%*s ", len
, buf
);
6823 /* Display a location list from a .dwo section. It uses address indexes rather
6824 than embedded addresses. This code closely follows display_loc_list, but the
6825 two are sufficiently different that combining things is very ugly. */
6828 display_loc_list_dwo (struct dwarf_section
*section
,
6829 unsigned char **start_ptr
,
6830 unsigned int debug_info_entry
,
6832 unsigned char **vstart_ptr
,
6835 unsigned char *start
= *start_ptr
, *vstart
= *vstart_ptr
;
6836 unsigned char *section_end
= section
->start
+ section
->size
;
6838 unsigned int pointer_size
;
6839 unsigned int offset_size
;
6842 unsigned short length
;
6843 int need_frame_base
;
6846 if (debug_info_entry
>= num_debug_info_entries
)
6848 warn (_("No debug information for loc lists of entry: %u\n"),
6853 cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
6854 pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
6855 offset_size
= debug_information
[debug_info_entry
].offset_size
;
6856 dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
6858 if (pointer_size
< 2 || pointer_size
> 8)
6860 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
6861 pointer_size
, debug_info_entry
);
6868 print_hex (offset
+ (start
- *start_ptr
), 4);
6870 if (start
>= section_end
)
6872 warn (_("Location list starting at offset %#" PRIx64
6873 " is not terminated.\n"), offset
);
6877 SAFE_BYTE_GET_AND_INC (entry_type
, start
, 1, section_end
);
6890 uint64_t off
= offset
+ (vstart
- *start_ptr
);
6892 READ_ULEB (view
, vstart
, section_end
);
6893 print_view (view
, 8);
6895 READ_ULEB (view
, vstart
, section_end
);
6896 print_view (view
, 8);
6898 printf (_("views at %8.8" PRIx64
" for:\n %*s "), off
, 8, "");
6906 case 0: /* A terminating entry. */
6908 *vstart_ptr
= vstart
;
6909 printf (_("<End of list>\n"));
6911 case 1: /* A base-address entry. */
6912 READ_ULEB (idx
, start
, section_end
);
6913 print_addr_index (idx
, 8);
6914 printf ("%*s", 9 + (vstart
? 2 * 6 : 0), "");
6915 printf (_("(base address selection entry)\n"));
6917 case 2: /* A start/end entry. */
6918 READ_ULEB (idx
, start
, section_end
);
6919 print_addr_index (idx
, 8);
6920 READ_ULEB (idx
, start
, section_end
);
6921 print_addr_index (idx
, 8);
6923 case 3: /* A start/length entry. */
6924 READ_ULEB (idx
, start
, section_end
);
6925 print_addr_index (idx
, 8);
6926 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
6927 printf ("%08x ", idx
);
6929 case 4: /* An offset pair entry. */
6930 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
6931 printf ("%08x ", idx
);
6932 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
6933 printf ("%08x ", idx
);
6936 warn (_("Unknown location list entry type 0x%x.\n"), entry_type
);
6938 *vstart_ptr
= vstart
;
6942 if (2 > (size_t) (section_end
- start
))
6944 warn (_("Location list starting at offset %#" PRIx64
6945 " is not terminated.\n"), offset
);
6949 SAFE_BYTE_GET_AND_INC (length
, start
, 2, section_end
);
6950 if (length
> (size_t) (section_end
- start
))
6952 warn (_("Location list starting at offset %#" PRIx64
6953 " is not terminated.\n"), offset
);
6958 need_frame_base
= decode_location_expression (start
,
6963 cu_offset
, section
);
6966 if (need_frame_base
&& !has_frame_base
)
6967 printf (_(" [without DW_AT_frame_base]"));
6975 *vstart_ptr
= vstart
;
6978 /* Sort array of indexes in ascending order of loc_offsets[idx] and
6981 static uint64_t *loc_offsets
, *loc_views
;
6984 loc_offsets_compar (const void *ap
, const void *bp
)
6986 uint64_t a
= loc_offsets
[*(const unsigned int *) ap
];
6987 uint64_t b
= loc_offsets
[*(const unsigned int *) bp
];
6989 int ret
= (a
> b
) - (b
> a
);
6993 a
= loc_views
[*(const unsigned int *) ap
];
6994 b
= loc_views
[*(const unsigned int *) bp
];
6996 ret
= (a
> b
) - (b
> a
);
7002 display_offset_entry_loclists (struct dwarf_section
*section
)
7004 unsigned char * start
= section
->start
;
7005 unsigned char * const end
= start
+ section
->size
;
7007 introduce (section
, false);
7012 unsigned short version
;
7013 unsigned char address_size
;
7014 unsigned char segment_selector_size
;
7015 uint32_t offset_entry_count
;
7019 printf (_("Table at Offset %#tx\n"), start
- section
->start
);
7021 SAFE_BYTE_GET_AND_INC (length
, start
, 4, end
);
7022 if (length
== 0xffffffff)
7025 SAFE_BYTE_GET_AND_INC (length
, start
, 8, end
);
7030 SAFE_BYTE_GET_AND_INC (version
, start
, 2, end
);
7031 SAFE_BYTE_GET_AND_INC (address_size
, start
, 1, end
);
7032 SAFE_BYTE_GET_AND_INC (segment_selector_size
, start
, 1, end
);
7033 SAFE_BYTE_GET_AND_INC (offset_entry_count
, start
, 4, end
);
7035 printf (_(" Length: %#" PRIx64
"\n"), length
);
7036 printf (_(" DWARF version: %u\n"), version
);
7037 printf (_(" Address size: %u\n"), address_size
);
7038 printf (_(" Segment size: %u\n"), segment_selector_size
);
7039 printf (_(" Offset entries: %u\n"), offset_entry_count
);
7043 warn (_("The %s section contains a corrupt or "
7044 "unsupported version number: %d.\n"),
7045 section
->name
, version
);
7049 if (segment_selector_size
!= 0)
7051 warn (_("The %s section contains an "
7052 "unsupported segment selector size: %d.\n"),
7053 section
->name
, segment_selector_size
);
7057 if (offset_entry_count
== 0)
7059 warn (_("The %s section contains a table without offset\n"),
7064 printf (_("\n Offset Entries starting at %#tx:\n"),
7065 start
- section
->start
);
7067 for (i
= 0; i
< offset_entry_count
; i
++)
7071 SAFE_BYTE_GET_AND_INC (entry
, start
, is_64bit
? 8 : 4, end
);
7072 printf (_(" [%6u] %#" PRIx64
"\n"), i
, entry
);
7079 for (j
= 1, i
= 0; i
< offset_entry_count
;)
7082 uint64_t base_address
= 0;
7085 uint64_t off
= start
- section
->start
;
7089 printf (_(" Offset Entry %u\n"), i
);
7096 SAFE_BYTE_GET_AND_INC (lle
, start
, 1, end
);
7100 case DW_LLE_end_of_list
:
7101 printf (_("<End of list>\n\n"));
7105 case DW_LLE_base_addressx
:
7106 READ_ULEB (base_address
, start
, end
);
7107 print_hex (base_address
, address_size
);
7108 printf (_("(index into .debug_addr) "));
7109 base_address
= fetch_indexed_addr (base_address
, address_size
);
7110 print_hex (base_address
, address_size
);
7111 printf (_("(base address)\n"));
7114 case DW_LLE_startx_endx
:
7115 READ_ULEB (begin
, start
, end
);
7116 begin
= fetch_indexed_addr (begin
, address_size
);
7117 READ_ULEB (finish
, start
, end
);
7118 finish
= fetch_indexed_addr (finish
, address_size
);
7121 case DW_LLE_startx_length
:
7122 READ_ULEB (begin
, start
, end
);
7123 begin
= fetch_indexed_addr (begin
, address_size
);
7124 READ_ULEB (finish
, start
, end
);
7128 case DW_LLE_offset_pair
:
7129 READ_ULEB (begin
, start
, end
);
7130 begin
+= base_address
;
7131 READ_ULEB (finish
, start
, end
);
7132 finish
+= base_address
;
7135 case DW_LLE_default_location
:
7139 case DW_LLE_base_address
:
7140 SAFE_BYTE_GET_AND_INC (base_address
, start
, address_size
, end
);
7141 print_hex (base_address
, address_size
);
7142 printf (_("(base address)\n"));
7145 case DW_LLE_start_end
:
7146 SAFE_BYTE_GET_AND_INC (begin
, start
, address_size
, end
);
7147 SAFE_BYTE_GET_AND_INC (finish
, start
, address_size
, end
);
7150 case DW_LLE_start_length
:
7151 SAFE_BYTE_GET_AND_INC (begin
, start
, address_size
, end
);
7152 READ_ULEB (finish
, start
, end
);
7157 error (_("Invalid location list entry type %d\n"), lle
);
7163 warn (_("Location list starting at offset %#" PRIx64
7164 " is not terminated.\n"), off
);
7168 print_hex (begin
, address_size
);
7169 print_hex (finish
, address_size
);
7171 if (begin
== finish
)
7172 fputs (_("(start == end)"), stdout
);
7173 else if (begin
> finish
)
7174 fputs (_("(start > end)"), stdout
);
7176 /* Read the counted location descriptions. */
7177 READ_ULEB (length
, start
, end
);
7179 if (length
> (size_t) (end
- start
))
7181 warn (_("Location list starting at offset %#" PRIx64
7182 " is not terminated.\n"), off
);
7186 (void) decode_location_expression (start
, address_size
, address_size
,
7187 version
, length
, 0, section
);
7194 while (start
< end
);
7200 display_debug_loc (struct dwarf_section
*section
, void *file
)
7202 unsigned char *start
= section
->start
, *vstart
= NULL
;
7204 unsigned char *section_begin
= start
;
7205 unsigned int num_loc_list
= 0;
7206 uint64_t last_offset
= 0;
7207 uint64_t last_view
= 0;
7208 unsigned int first
= 0;
7211 int seen_first_offset
= 0;
7212 int locs_sorted
= 1;
7213 unsigned char *next
= start
, *vnext
= vstart
;
7214 unsigned int *array
= NULL
;
7215 const char *suffix
= strrchr (section
->name
, '.');
7216 bool is_dwo
= false;
7217 int is_loclists
= strstr (section
->name
, "debug_loclists") != NULL
;
7218 uint64_t header_size
= 0;
7220 if (suffix
&& strcmp (suffix
, ".dwo") == 0)
7223 bytes
= section
->size
;
7227 printf (_("\nThe %s section is empty.\n"), section
->name
);
7233 unsigned char *hdrptr
= section_begin
;
7235 unsigned short ll_version
;
7236 unsigned char *end
= section_begin
+ section
->size
;
7237 unsigned char address_size
, segment_selector_size
;
7238 uint32_t offset_entry_count
;
7240 SAFE_BYTE_GET_AND_INC (ll_length
, hdrptr
, 4, end
);
7241 if (ll_length
== 0xffffffff)
7242 SAFE_BYTE_GET_AND_INC (ll_length
, hdrptr
, 8, end
);
7244 SAFE_BYTE_GET_AND_INC (ll_version
, hdrptr
, 2, end
);
7245 if (ll_version
!= 5)
7247 warn (_("The %s section contains corrupt or "
7248 "unsupported version number: %d.\n"),
7249 section
->name
, ll_version
);
7253 SAFE_BYTE_GET_AND_INC (address_size
, hdrptr
, 1, end
);
7255 SAFE_BYTE_GET_AND_INC (segment_selector_size
, hdrptr
, 1, end
);
7256 if (segment_selector_size
!= 0)
7258 warn (_("The %s section contains "
7259 "unsupported segment selector size: %d.\n"),
7260 section
->name
, segment_selector_size
);
7264 SAFE_BYTE_GET_AND_INC (offset_entry_count
, hdrptr
, 4, end
);
7266 if (offset_entry_count
!= 0)
7267 return display_offset_entry_loclists (section
);
7269 header_size
= hdrptr
- section_begin
;
7272 if (load_debug_info (file
) == 0)
7274 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
7279 /* Check the order of location list in .debug_info section. If
7280 offsets of location lists are in the ascending order, we can
7281 use `debug_information' directly. */
7282 for (i
= 0; i
< num_debug_info_entries
; i
++)
7286 num
= debug_information
[i
].num_loc_offsets
;
7287 if (num
> num_loc_list
)
7290 /* Check if we can use `debug_information' directly. */
7291 if (locs_sorted
&& num
!= 0)
7293 if (!seen_first_offset
)
7295 /* This is the first location list. */
7296 last_offset
= debug_information
[i
].loc_offsets
[0];
7297 last_view
= debug_information
[i
].loc_views
[0];
7299 seen_first_offset
= 1;
7305 for (; j
< num
; j
++)
7308 debug_information
[i
].loc_offsets
[j
]
7309 || (last_offset
== debug_information
[i
].loc_offsets
[j
]
7310 && last_view
> debug_information
[i
].loc_views
[j
]))
7315 last_offset
= debug_information
[i
].loc_offsets
[j
];
7316 last_view
= debug_information
[i
].loc_views
[j
];
7321 if (!seen_first_offset
)
7322 error (_("No location lists in .debug_info section!\n"));
7324 if (debug_information
[first
].num_loc_offsets
> 0
7325 && debug_information
[first
].loc_offsets
[0] != header_size
7326 && debug_information
[first
].loc_views
[0] != header_size
)
7327 warn (_("Location lists in %s section start at %#" PRIx64
7328 " rather than %#" PRIx64
"\n"),
7329 section
->name
, debug_information
[first
].loc_offsets
[0],
7333 array
= (unsigned int *) xcmalloc (num_loc_list
, sizeof (unsigned int));
7335 introduce (section
, false);
7337 if (reloc_at (section
, 0))
7338 printf (_(" Warning: This section has relocations - addresses seen here may not be accurate.\n\n"));
7340 printf (_(" Offset Begin End Expression\n"));
7342 for (i
= first
; i
< num_debug_info_entries
; i
++)
7344 uint64_t offset
= 0, voffset
= 0;
7345 uint64_t base_address
;
7351 for (k
= 0; k
< debug_information
[i
].num_loc_offsets
; k
++)
7353 loc_offsets
= debug_information
[i
].loc_offsets
;
7354 loc_views
= debug_information
[i
].loc_views
;
7355 qsort (array
, debug_information
[i
].num_loc_offsets
,
7356 sizeof (*array
), loc_offsets_compar
);
7359 /* .debug_loclists has a per-unit header.
7360 Update start if we are detecting it. */
7361 if (debug_information
[i
].dwarf_version
== 5)
7363 j
= locs_sorted
? 0 : array
[0];
7365 if (debug_information
[i
].num_loc_offsets
)
7366 offset
= debug_information
[i
].loc_offsets
[j
];
7368 if (debug_information
[i
].num_loc_views
)
7369 voffset
= debug_information
[i
].loc_views
[j
];
7371 /* Assume that the size of the header is constant across CUs. */
7372 if (((start
- section_begin
) + header_size
== offset
)
7373 || ((start
-section_begin
) + header_size
== voffset
))
7374 start
+= header_size
;
7377 int adjacent_view_loclists
= 1;
7378 for (k
= 0; k
< debug_information
[i
].num_loc_offsets
; k
++)
7380 j
= locs_sorted
? k
: array
[k
];
7382 && (debug_information
[i
].loc_offsets
[locs_sorted
7383 ? k
- 1 : array
[k
- 1]]
7384 == debug_information
[i
].loc_offsets
[j
])
7385 && (debug_information
[i
].loc_views
[locs_sorted
7386 ? k
- 1 : array
[k
- 1]]
7387 == debug_information
[i
].loc_views
[j
]))
7389 has_frame_base
= debug_information
[i
].have_frame_base
[j
];
7390 offset
= debug_information
[i
].loc_offsets
[j
];
7391 next
= section_begin
+ offset
;
7392 voffset
= debug_information
[i
].loc_views
[j
];
7393 if (voffset
!= (uint64_t) -1)
7394 vnext
= section_begin
+ voffset
;
7397 base_address
= debug_information
[i
].base_address
;
7399 if (vnext
&& vnext
< next
)
7402 display_view_pair_list (section
, &vstart
, i
, next
);
7409 if (vnext
&& vnext
< next
)
7410 warn (_("There is a hole [%#tx - %#" PRIx64
"]"
7411 " in %s section.\n"),
7412 start
- section_begin
, voffset
, section
->name
);
7414 warn (_("There is a hole [%#tx - %#" PRIx64
"]"
7415 " in %s section.\n"),
7416 start
- section_begin
, offset
, section
->name
);
7418 else if (start
> next
)
7419 warn (_("There is an overlap [%#tx - %#" PRIx64
"]"
7420 " in %s section.\n"),
7421 start
- section_begin
, offset
, section
->name
);
7425 if (offset
>= bytes
)
7427 warn (_("Offset %#" PRIx64
" is bigger than %s section size.\n"),
7428 offset
, section
->name
);
7432 if (vnext
&& voffset
>= bytes
)
7434 warn (_("View Offset %#" PRIx64
" is bigger than %s section size.\n"),
7435 voffset
, section
->name
);
7442 display_loc_list_dwo (section
, &start
, i
, offset
,
7443 &vstart
, has_frame_base
);
7445 display_loc_list (section
, &start
, i
, offset
, base_address
,
7446 &vstart
, has_frame_base
);
7451 warn (_("DWO is not yet supported.\n"));
7453 display_loclists_list (section
, &start
, i
, offset
, base_address
,
7454 &vstart
, has_frame_base
);
7457 /* FIXME: this arrangement is quite simplistic. Nothing
7458 requires locview lists to be adjacent to corresponding
7459 loclists, and a single loclist could be augmented by
7460 different locview lists, and vice-versa, unlikely as it
7461 is that it would make sense to do so. Hopefully we'll
7462 have view pair support built into loclists before we ever
7463 need to address all these possibilities. */
7464 if (adjacent_view_loclists
&& vnext
7465 && vnext
!= start
&& vstart
!= next
)
7467 adjacent_view_loclists
= 0;
7468 warn (_("Hole and overlap detection requires adjacent view lists and loclists.\n"));
7471 if (vnext
&& vnext
== start
)
7472 display_view_pair_list (section
, &start
, i
, vstart
);
7476 if (start
< section
->start
+ section
->size
)
7477 warn (ngettext ("There is %ld unused byte at the end of section %s\n",
7478 "There are %ld unused bytes at the end of section %s\n",
7479 (long) (section
->start
+ section
->size
- start
)),
7480 (long) (section
->start
+ section
->size
- start
), section
->name
);
7487 display_debug_str (struct dwarf_section
*section
,
7488 void *file ATTRIBUTE_UNUSED
)
7490 unsigned char *start
= section
->start
;
7491 uint64_t bytes
= section
->size
;
7492 uint64_t addr
= section
->address
;
7496 printf (_("\nThe %s section is empty.\n"), section
->name
);
7500 introduce (section
, false);
7508 lbytes
= (bytes
> 16 ? 16 : bytes
);
7510 printf (" 0x%8.8" PRIx64
" ", addr
);
7512 for (j
= 0; j
< 16; j
++)
7515 printf ("%2.2x", start
[j
]);
7523 for (j
= 0; j
< lbytes
; j
++)
7526 if (k
>= ' ' && k
< 0x80)
7545 display_debug_info (struct dwarf_section
*section
, void *file
)
7547 return process_debug_info (section
, file
, section
->abbrev_sec
, false, false);
7551 display_debug_types (struct dwarf_section
*section
, void *file
)
7553 return process_debug_info (section
, file
, section
->abbrev_sec
, false, true);
7557 display_trace_info (struct dwarf_section
*section
, void *file
)
7559 return process_debug_info (section
, file
, section
->abbrev_sec
, false, true);
7563 display_debug_aranges (struct dwarf_section
*section
,
7564 void *file ATTRIBUTE_UNUSED
)
7566 unsigned char *start
= section
->start
;
7567 unsigned char *end
= start
+ section
->size
;
7569 introduce (section
, false);
7571 /* It does not matter if this load fails,
7572 we test for that later on. */
7573 load_debug_info (file
);
7577 unsigned char *hdrptr
;
7578 DWARF2_Internal_ARange arange
;
7579 unsigned char *addr_ranges
;
7583 unsigned char address_size
;
7584 unsigned int offset_size
;
7585 unsigned char *end_ranges
;
7588 sec_off
= hdrptr
- section
->start
;
7590 SAFE_BYTE_GET_AND_INC (arange
.ar_length
, hdrptr
, 4, end
);
7591 if (arange
.ar_length
== 0xffffffff)
7593 SAFE_BYTE_GET_AND_INC (arange
.ar_length
, hdrptr
, 8, end
);
7599 if (arange
.ar_length
> (size_t) (end
- hdrptr
))
7601 warn (_("Debug info is corrupted, %s header at %#" PRIx64
7602 " has length %#" PRIx64
"\n"),
7603 section
->name
, sec_off
, arange
.ar_length
);
7606 end_ranges
= hdrptr
+ arange
.ar_length
;
7608 SAFE_BYTE_GET_AND_INC (arange
.ar_version
, hdrptr
, 2, end_ranges
);
7609 SAFE_BYTE_GET_AND_INC (arange
.ar_info_offset
, hdrptr
, offset_size
,
7612 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
7613 && num_debug_info_entries
> 0
7614 && find_debug_info_for_offset (arange
.ar_info_offset
) == NULL
)
7615 warn (_(".debug_info offset of %#" PRIx64
7616 " in %s section does not point to a CU header.\n"),
7617 arange
.ar_info_offset
, section
->name
);
7619 SAFE_BYTE_GET_AND_INC (arange
.ar_pointer_size
, hdrptr
, 1, end_ranges
);
7620 SAFE_BYTE_GET_AND_INC (arange
.ar_segment_size
, hdrptr
, 1, end_ranges
);
7622 if (arange
.ar_version
!= 2 && arange
.ar_version
!= 3)
7624 /* PR 19872: A version number of 0 probably means that there is
7625 padding at the end of the .debug_aranges section. Gold puts
7626 it there when performing an incremental link, for example.
7627 So do not generate a warning in this case. */
7628 if (arange
.ar_version
)
7629 warn (_("Only DWARF 2 and 3 aranges are currently supported.\n"));
7633 printf (_(" Length: %" PRId64
"\n"), arange
.ar_length
);
7634 printf (_(" Version: %d\n"), arange
.ar_version
);
7635 printf (_(" Offset into .debug_info: %#" PRIx64
"\n"),
7636 arange
.ar_info_offset
);
7637 printf (_(" Pointer Size: %d\n"), arange
.ar_pointer_size
);
7638 printf (_(" Segment Size: %d\n"), arange
.ar_segment_size
);
7640 address_size
= arange
.ar_pointer_size
+ arange
.ar_segment_size
;
7642 /* PR 17512: file: 001-108546-0.001:0.1. */
7643 if (address_size
== 0 || address_size
> 8)
7645 error (_("Invalid address size in %s section!\n"),
7650 /* The DWARF spec does not require that the address size be a power
7651 of two, but we do. This will have to change if we ever encounter
7652 an uneven architecture. */
7653 if ((address_size
& (address_size
- 1)) != 0)
7655 warn (_("Pointer size + Segment size is not a power of two.\n"));
7659 if (address_size
> 4)
7660 printf (_("\n Address Length\n"));
7662 printf (_("\n Address Length\n"));
7664 addr_ranges
= hdrptr
;
7666 /* Must pad to an alignment boundary that is twice the address size. */
7667 addr_ranges
+= (2 * address_size
- 1
7668 - (hdrptr
- start
- 1) % (2 * address_size
));
7670 while (2 * address_size
<= end_ranges
- addr_ranges
)
7672 SAFE_BYTE_GET_AND_INC (address
, addr_ranges
, address_size
,
7674 SAFE_BYTE_GET_AND_INC (length
, addr_ranges
, address_size
,
7677 print_hex (address
, address_size
);
7678 print_hex_ns (length
, address_size
);
7690 /* Comparison function for qsort. */
7692 comp_addr_base (const void * v0
, const void * v1
)
7694 debug_info
*info0
= *(debug_info
**) v0
;
7695 debug_info
*info1
= *(debug_info
**) v1
;
7696 return info0
->addr_base
- info1
->addr_base
;
7699 /* Display the debug_addr section. */
7701 display_debug_addr (struct dwarf_section
*section
,
7704 debug_info
**debug_addr_info
;
7705 unsigned char *entry
;
7709 unsigned char * header
;
7711 if (section
->size
== 0)
7713 printf (_("\nThe %s section is empty.\n"), section
->name
);
7717 if (load_debug_info (file
) == 0)
7719 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
7724 introduce (section
, false);
7726 /* PR 17531: file: cf38d01b.
7727 We use xcalloc because a corrupt file may not have initialised all of the
7728 fields in the debug_info structure, which means that the sort below might
7729 try to move uninitialised data. */
7730 debug_addr_info
= (debug_info
**) xcalloc ((num_debug_info_entries
+ 1),
7731 sizeof (debug_info
*));
7734 for (i
= 0; i
< num_debug_info_entries
; i
++)
7735 if (debug_information
[i
].addr_base
!= DEBUG_INFO_UNAVAILABLE
)
7737 /* PR 17531: file: cf38d01b. */
7738 if (debug_information
[i
].addr_base
>= section
->size
)
7739 warn (_("Corrupt address base (%#" PRIx64
")"
7740 " found in debug section %u\n"),
7741 debug_information
[i
].addr_base
, i
);
7743 debug_addr_info
[count
++] = debug_information
+ i
;
7746 /* Add a sentinel to make iteration convenient. */
7747 debug_addr_info
[count
] = (debug_info
*) xmalloc (sizeof (debug_info
));
7748 debug_addr_info
[count
]->addr_base
= section
->size
;
7749 qsort (debug_addr_info
, count
, sizeof (debug_info
*), comp_addr_base
);
7751 header
= section
->start
;
7752 for (i
= 0; i
< count
; i
++)
7755 unsigned int address_size
= debug_addr_info
[i
]->pointer_size
;
7757 printf (_(" For compilation unit at offset %#" PRIx64
":\n"),
7758 debug_addr_info
[i
]->cu_offset
);
7760 printf (_("\tIndex\tAddress\n"));
7761 entry
= section
->start
+ debug_addr_info
[i
]->addr_base
;
7762 if (debug_addr_info
[i
]->dwarf_version
>= 5)
7764 size_t header_size
= entry
- header
;
7765 unsigned char *curr_header
= header
;
7768 int segment_selector_size
;
7770 if (header_size
!= 8 && header_size
!= 16)
7772 warn (_("Corrupt %s section: expecting header size of 8 or 16, but found %zd instead\n"),
7773 section
->name
, header_size
);
7777 SAFE_BYTE_GET_AND_INC (length
, curr_header
, 4, entry
);
7778 if (length
== 0xffffffff)
7779 SAFE_BYTE_GET_AND_INC (length
, curr_header
, 8, entry
);
7780 if (length
> (size_t) (section
->start
+ section
->size
- curr_header
)
7781 || length
< (size_t) (entry
- curr_header
))
7783 warn (_("Corrupt %s section: unit_length field of %#" PRIx64
7784 " is invalid\n"), section
->name
, length
);
7787 end
= curr_header
+ length
;
7788 SAFE_BYTE_GET_AND_INC (version
, curr_header
, 2, entry
);
7790 warn (_("Corrupt %s section: expecting version number 5 in header but found %d instead\n"),
7791 section
->name
, version
);
7793 SAFE_BYTE_GET_AND_INC (address_size
, curr_header
, 1, entry
);
7794 SAFE_BYTE_GET_AND_INC (segment_selector_size
, curr_header
, 1, entry
);
7795 address_size
+= segment_selector_size
;
7798 end
= section
->start
+ debug_addr_info
[i
+ 1]->addr_base
;
7803 if (address_size
< 1 || address_size
> sizeof (uint64_t))
7805 warn (_("Corrupt %s section: address size (%x) is wrong"),
7806 section
->name
, address_size
);
7810 while ((size_t) (end
- entry
) >= address_size
)
7812 uint64_t base
= byte_get (entry
, address_size
);
7813 printf (_("\t%d:\t"), idx
);
7814 print_hex_ns (base
, address_size
);
7816 entry
+= address_size
;
7822 free (debug_addr_info
);
7826 /* Display the .debug_str_offsets and .debug_str_offsets.dwo sections. */
7829 display_debug_str_offsets (struct dwarf_section
*section
,
7830 void *file ATTRIBUTE_UNUSED
)
7834 if (section
->size
== 0)
7836 printf (_("\nThe %s section is empty.\n"), section
->name
);
7840 unsigned char *start
= section
->start
;
7841 unsigned char *end
= start
+ section
->size
;
7842 unsigned char *curr
= start
;
7843 uint64_t debug_str_offsets_hdr_len
;
7845 const char *suffix
= strrchr (section
->name
, '.');
7846 bool dwo
= suffix
&& strcmp (suffix
, ".dwo") == 0;
7849 load_debug_section_with_follow (str_dwo
, file
);
7851 load_debug_section_with_follow (str
, file
);
7853 introduce (section
, false);
7858 uint64_t entry_length
;
7860 SAFE_BYTE_GET_AND_INC (length
, curr
, 4, end
);
7861 /* FIXME: We assume that this means 64-bit DWARF is being used. */
7862 if (length
== 0xffffffff)
7864 SAFE_BYTE_GET_AND_INC (length
, curr
, 8, end
);
7866 debug_str_offsets_hdr_len
= 16;
7871 debug_str_offsets_hdr_len
= 8;
7874 unsigned char *entries_end
;
7877 /* This is probably an old style .debug_str_offset section which
7878 just contains offsets and no header (and the first offset is 0). */
7879 length
= section
->size
;
7880 curr
= section
->start
;
7883 printf (_(" Length: %#" PRIx64
"\n"), length
);
7884 printf (_(" Index Offset [String]\n"));
7888 if (length
<= (size_t) (end
- curr
))
7889 entries_end
= curr
+ length
;
7892 warn (_("Section %s is too small %#" PRIx64
"\n"),
7893 section
->name
, section
->size
);
7898 SAFE_BYTE_GET_AND_INC (version
, curr
, 2, entries_end
);
7900 warn (_("Unexpected version number in str_offset header: %#x\n"), version
);
7903 SAFE_BYTE_GET_AND_INC (padding
, curr
, 2, entries_end
);
7905 warn (_("Unexpected value in str_offset header's padding field: %#x\n"), padding
);
7907 printf (_(" Length: %#" PRIx64
"\n"), length
);
7908 printf (_(" Version: %#x\n"), version
);
7909 printf (_(" Index Offset [String]\n"));
7912 for (idx
= 0; curr
< entries_end
; idx
++)
7915 const unsigned char * string
;
7917 if ((size_t) (entries_end
- curr
) < entry_length
)
7918 /* Not enough space to read one entry_length, give up. */
7921 SAFE_BYTE_GET_AND_INC (offset
, curr
, entry_length
, entries_end
);
7923 string
= (const unsigned char *)
7924 fetch_indexed_string (idx
, NULL
, entry_length
, dwo
, debug_str_offsets_hdr_len
);
7926 string
= fetch_indirect_string (offset
);
7928 printf (" %8lu ", idx
);
7929 print_hex (offset
, entry_length
);
7930 printf (" %s\n", string
);
7937 /* Each debug_information[x].range_lists[y] gets this representation for
7938 sorting purposes. */
7942 /* The debug_information[x].range_lists[y] value. */
7943 uint64_t ranges_offset
;
7945 /* Original debug_information to find parameters of the data. */
7946 debug_info
*debug_info_p
;
7949 /* Sort struct range_entry in ascending order of its RANGES_OFFSET. */
7952 range_entry_compar (const void *ap
, const void *bp
)
7954 const struct range_entry
*a_re
= (const struct range_entry
*) ap
;
7955 const struct range_entry
*b_re
= (const struct range_entry
*) bp
;
7956 const uint64_t a
= a_re
->ranges_offset
;
7957 const uint64_t b
= b_re
->ranges_offset
;
7959 return (a
> b
) - (b
> a
);
7963 display_debug_ranges_list (unsigned char * start
,
7964 unsigned char * finish
,
7965 unsigned int pointer_size
,
7967 uint64_t base_address
)
7969 while (start
< finish
)
7974 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
7975 if (start
>= finish
)
7977 SAFE_SIGNED_BYTE_GET_AND_INC (end
, start
, pointer_size
, finish
);
7980 print_hex (offset
, 4);
7982 if (begin
== 0 && end
== 0)
7984 printf (_("<End of list>\n"));
7988 /* Check base address specifiers. */
7989 if (is_max_address (begin
, pointer_size
)
7990 && !is_max_address (end
, pointer_size
))
7993 print_hex (begin
, pointer_size
);
7994 print_hex (end
, pointer_size
);
7995 printf ("(base address)\n");
7999 print_hex (begin
+ base_address
, pointer_size
);
8000 print_hex_ns (end
+ base_address
, pointer_size
);
8003 fputs (_(" (start == end)"), stdout
);
8004 else if (begin
> end
)
8005 fputs (_(" (start > end)"), stdout
);
8011 static unsigned char *
8012 display_debug_rnglists_list (unsigned char * start
,
8013 unsigned char * finish
,
8014 unsigned int pointer_size
,
8016 uint64_t base_address
,
8017 unsigned int offset_size
)
8019 unsigned char *next
= start
;
8020 unsigned int debug_addr_section_hdr_len
;
8022 if (offset_size
== 4)
8023 debug_addr_section_hdr_len
= 8;
8025 debug_addr_section_hdr_len
= 16;
8029 uint64_t off
= offset
+ (start
- next
);
8030 enum dwarf_range_list_entry rlet
;
8031 /* Initialize it due to a false compiler warning. */
8032 uint64_t begin
= -1, length
, end
= -1;
8034 if (start
>= finish
)
8036 warn (_("Range list starting at offset %#" PRIx64
8037 " is not terminated.\n"), offset
);
8044 SAFE_BYTE_GET_AND_INC (rlet
, start
, 1, finish
);
8048 case DW_RLE_end_of_list
:
8049 printf (_("<End of list>\n"));
8051 case DW_RLE_base_addressx
:
8052 READ_ULEB (base_address
, start
, finish
);
8053 print_hex (base_address
, pointer_size
);
8054 printf (_("(base address index) "));
8055 base_address
= fetch_indexed_addr ((base_address
* pointer_size
)
8056 + debug_addr_section_hdr_len
, pointer_size
);
8057 print_hex (base_address
, pointer_size
);
8058 printf (_("(base address)\n"));
8060 case DW_RLE_startx_endx
:
8061 READ_ULEB (begin
, start
, finish
);
8062 READ_ULEB (end
, start
, finish
);
8063 begin
= fetch_indexed_addr ((begin
* pointer_size
)
8064 + debug_addr_section_hdr_len
, pointer_size
);
8065 end
= fetch_indexed_addr ((begin
* pointer_size
)
8066 + debug_addr_section_hdr_len
, pointer_size
);
8068 case DW_RLE_startx_length
:
8069 READ_ULEB (begin
, start
, finish
);
8070 READ_ULEB (length
, start
, finish
);
8071 begin
= fetch_indexed_addr ((begin
* pointer_size
)
8072 + debug_addr_section_hdr_len
, pointer_size
);
8073 end
= begin
+ length
;
8075 case DW_RLE_offset_pair
:
8076 READ_ULEB (begin
, start
, finish
);
8077 READ_ULEB (end
, start
, finish
);
8079 case DW_RLE_base_address
:
8080 SAFE_BYTE_GET_AND_INC (base_address
, start
, pointer_size
, finish
);
8081 print_hex (base_address
, pointer_size
);
8082 printf (_("(base address)\n"));
8084 case DW_RLE_start_end
:
8085 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
8086 SAFE_BYTE_GET_AND_INC (end
, start
, pointer_size
, finish
);
8088 case DW_RLE_start_length
:
8089 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
8090 READ_ULEB (length
, start
, finish
);
8091 end
= begin
+ length
;
8094 error (_("Invalid range list entry type %d\n"), rlet
);
8095 rlet
= DW_RLE_end_of_list
;
8099 if (rlet
== DW_RLE_end_of_list
)
8101 if (rlet
== DW_RLE_base_address
|| rlet
== DW_RLE_base_addressx
)
8104 /* Only a DW_RLE_offset_pair needs the base address added. */
8105 if (rlet
== DW_RLE_offset_pair
)
8107 begin
+= base_address
;
8108 end
+= base_address
;
8111 print_hex (begin
, pointer_size
);
8112 print_hex (end
, pointer_size
);
8115 fputs (_(" (start == end)"), stdout
);
8116 else if (begin
> end
)
8117 fputs (_(" (start > end)"), stdout
);
8126 display_debug_rnglists (struct dwarf_section
*section
)
8128 unsigned char *start
= section
->start
;
8129 unsigned char *finish
= start
+ section
->size
;
8131 while (start
< finish
)
8133 unsigned char *table_start
;
8134 uint64_t offset
= start
- section
->start
;
8136 uint64_t initial_length
;
8137 unsigned char segment_selector_size
;
8138 unsigned int offset_entry_count
;
8140 unsigned short version
;
8141 unsigned char address_size
= 0;
8142 unsigned char offset_size
;
8144 /* Get and check the length of the block. */
8145 SAFE_BYTE_GET_AND_INC (initial_length
, start
, 4, finish
);
8147 if (initial_length
== 0xffffffff)
8149 /* This section is 64-bit DWARF 3. */
8150 SAFE_BYTE_GET_AND_INC (initial_length
, start
, 8, finish
);
8156 if (initial_length
> (size_t) (finish
- start
))
8158 /* If the length field has a relocation against it, then we should
8159 not complain if it is inaccurate (and probably negative).
8160 It is copied from .debug_line handling code. */
8161 if (reloc_at (section
, (start
- section
->start
) - offset_size
))
8162 initial_length
= finish
- start
;
8165 warn (_("The length field (%#" PRIx64
8166 ") in the debug_rnglists header is wrong"
8167 " - the section is too small\n"),
8173 end
= start
+ initial_length
;
8175 /* Get the other fields in the header. */
8176 SAFE_BYTE_GET_AND_INC (version
, start
, 2, finish
);
8177 SAFE_BYTE_GET_AND_INC (address_size
, start
, 1, finish
);
8178 SAFE_BYTE_GET_AND_INC (segment_selector_size
, start
, 1, finish
);
8179 SAFE_BYTE_GET_AND_INC (offset_entry_count
, start
, 4, finish
);
8181 printf (_(" Table at Offset: %#" PRIx64
":\n"), offset
);
8182 printf (_(" Length: %#" PRIx64
"\n"), initial_length
);
8183 printf (_(" DWARF version: %u\n"), version
);
8184 printf (_(" Address size: %u\n"), address_size
);
8185 printf (_(" Segment size: %u\n"), segment_selector_size
);
8186 printf (_(" Offset entries: %u\n"), offset_entry_count
);
8188 /* Check the fields. */
8189 if (segment_selector_size
!= 0)
8191 warn (_("The %s section contains "
8192 "unsupported segment selector size: %d.\n"),
8193 section
->name
, segment_selector_size
);
8199 warn (_("Only DWARF version 5+ debug_rnglists info "
8200 "is currently supported.\n"));
8204 table_start
= start
;
8206 if (offset_entry_count
!= 0)
8208 printf (_("\n Offsets starting at %#tx:\n"),
8209 start
- section
->start
);
8211 for (i
= 0; i
< offset_entry_count
; i
++)
8215 SAFE_BYTE_GET_AND_INC (entry
, start
, offset_size
, finish
);
8216 printf (_(" [%6u] %#" PRIx64
"\n"), i
, entry
);
8220 offset_entry_count
= 1;
8222 for (i
= 0; i
< offset_entry_count
; i
++)
8224 uint64_t indx
= start
- table_start
;
8226 offset
= start
- section
->start
;
8227 printf (_("\n Offset: %#" PRIx64
", Index: %#" PRIx64
"\n"),
8229 printf (_(" Offset Begin End\n"));
8230 start
= display_debug_rnglists_list
8231 (start
, end
, address_size
, offset
, 0, offset_size
);
8247 display_debug_ranges (struct dwarf_section
*section
,
8248 void *file ATTRIBUTE_UNUSED
)
8250 unsigned char *start
= section
->start
;
8251 unsigned char *last_start
= start
;
8252 uint64_t bytes
= section
->size
;
8253 unsigned char *section_begin
= start
;
8254 unsigned char *finish
= start
+ bytes
;
8255 unsigned int num_range_list
, i
;
8256 struct range_entry
*range_entries
;
8257 struct range_entry
*range_entry_fill
;
8258 int is_rnglists
= strstr (section
->name
, "debug_rnglists") != NULL
;
8259 /* Initialize it due to a false compiler warning. */
8260 unsigned char address_size
= 0;
8261 uint64_t last_offset
= 0;
8265 printf (_("\nThe %s section is empty.\n"), section
->name
);
8269 introduce (section
, false);
8272 return display_debug_rnglists (section
);
8274 if (load_debug_info (file
) == 0)
8276 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
8282 for (i
= 0; i
< num_debug_info_entries
; i
++)
8283 num_range_list
+= debug_information
[i
].num_range_lists
;
8285 if (num_range_list
== 0)
8287 /* This can happen when the file was compiled with -gsplit-debug
8288 which removes references to range lists from the primary .o file. */
8289 printf (_("No range lists in .debug_info section.\n"));
8293 range_entries
= (struct range_entry
*)
8294 xmalloc (sizeof (*range_entries
) * num_range_list
);
8295 range_entry_fill
= range_entries
;
8297 for (i
= 0; i
< num_debug_info_entries
; i
++)
8299 debug_info
*debug_info_p
= &debug_information
[i
];
8302 for (j
= 0; j
< debug_info_p
->num_range_lists
; j
++)
8304 range_entry_fill
->ranges_offset
= debug_info_p
->range_lists
[j
];
8305 range_entry_fill
->debug_info_p
= debug_info_p
;
8310 qsort (range_entries
, num_range_list
, sizeof (*range_entries
),
8311 range_entry_compar
);
8313 if (dwarf_check
!= 0 && range_entries
[0].ranges_offset
!= 0)
8314 warn (_("Range lists in %s section start at %#" PRIx64
"\n"),
8315 section
->name
, range_entries
[0].ranges_offset
);
8318 printf (_(" Offset Begin End\n"));
8320 for (i
= 0; i
< num_range_list
; i
++)
8322 struct range_entry
*range_entry
= &range_entries
[i
];
8323 debug_info
*debug_info_p
= range_entry
->debug_info_p
;
8324 unsigned int pointer_size
;
8326 unsigned char *next
;
8327 uint64_t base_address
;
8329 pointer_size
= (is_rnglists
? address_size
: debug_info_p
->pointer_size
);
8330 offset
= range_entry
->ranges_offset
;
8331 base_address
= debug_info_p
->base_address
;
8333 /* PR 17512: file: 001-101485-0.001:0.1. */
8334 if (pointer_size
< 2 || pointer_size
> 8)
8336 warn (_("Corrupt pointer size (%d) in debug entry at offset %#" PRIx64
"\n"),
8337 pointer_size
, offset
);
8341 if (offset
> (size_t) (finish
- section_begin
))
8343 warn (_("Corrupt offset (%#" PRIx64
") in range entry %u\n"),
8348 next
= section_begin
+ offset
+ debug_info_p
->rnglists_base
;
8350 /* If multiple DWARF entities reference the same range then we will
8351 have multiple entries in the `range_entries' list for the same
8352 offset. Thanks to the sort above these will all be consecutive in
8353 the `range_entries' list, so we can easily ignore duplicates
8355 if (i
> 0 && last_offset
== offset
)
8357 last_offset
= offset
;
8359 if (dwarf_check
!= 0 && i
> 0)
8362 warn (_("There is a hole [%#tx - %#tx] in %s section.\n"),
8363 start
- section_begin
, next
- section_begin
, section
->name
);
8364 else if (start
> next
)
8366 if (next
== last_start
)
8368 warn (_("There is an overlap [%#tx - %#tx] in %s section.\n"),
8369 start
- section_begin
, next
- section_begin
, section
->name
);
8376 display_debug_ranges_list
8377 (start
, finish
, pointer_size
, offset
, base_address
);
8381 free (range_entries
);
8386 typedef struct Frame_Chunk
8388 struct Frame_Chunk
*next
;
8389 unsigned char *chunk_start
;
8391 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
8392 short int *col_type
;
8393 int64_t *col_offset
;
8395 unsigned int code_factor
;
8399 unsigned int cfa_reg
;
8400 uint64_t cfa_offset
;
8402 unsigned char fde_encoding
;
8403 unsigned char cfa_exp
;
8404 unsigned char ptr_size
;
8405 unsigned char segment_size
;
8409 typedef const char *(*dwarf_regname_lookup_ftype
) (unsigned int);
8410 static dwarf_regname_lookup_ftype dwarf_regnames_lookup_func
;
8411 static const char *const *dwarf_regnames
;
8412 static unsigned int dwarf_regnames_count
;
8413 static bool is_aarch64
;
8415 /* A marker for a col_type that means this column was never referenced
8416 in the frame info. */
8417 #define DW_CFA_unreferenced (-1)
8419 /* Return 0 if no more space is needed, 1 if more space is needed,
8420 -1 for invalid reg. */
8423 frame_need_space (Frame_Chunk
*fc
, unsigned int reg
)
8425 unsigned int prev
= fc
->ncols
;
8427 if (reg
< (unsigned int) fc
->ncols
)
8430 if (dwarf_regnames_count
> 0
8431 && reg
> dwarf_regnames_count
)
8434 fc
->ncols
= reg
+ 1;
8435 /* PR 17512: file: 10450-2643-0.004.
8436 If reg == -1 then this can happen... */
8440 /* PR 17512: file: 2844a11d. */
8441 if (fc
->ncols
> 1024 && dwarf_regnames_count
== 0)
8443 error (_("Unfeasibly large register number: %u\n"), reg
);
8445 /* FIXME: 1024 is an arbitrary limit. Increase it if
8446 we ever encounter a valid binary that exceeds it. */
8450 fc
->col_type
= xcrealloc (fc
->col_type
, fc
->ncols
,
8451 sizeof (*fc
->col_type
));
8452 fc
->col_offset
= xcrealloc (fc
->col_offset
, fc
->ncols
,
8453 sizeof (*fc
->col_offset
));
8454 /* PR 17512: file:002-10025-0.005. */
8455 if (fc
->col_type
== NULL
|| fc
->col_offset
== NULL
)
8457 error (_("Out of memory allocating %u columns in dwarf frame arrays\n"),
8463 while (prev
< fc
->ncols
)
8465 fc
->col_type
[prev
] = DW_CFA_unreferenced
;
8466 fc
->col_offset
[prev
] = 0;
8472 static const char *const dwarf_regnames_i386
[] =
8474 "eax", "ecx", "edx", "ebx", /* 0 - 3 */
8475 "esp", "ebp", "esi", "edi", /* 4 - 7 */
8476 "eip", "eflags", NULL
, /* 8 - 10 */
8477 "st0", "st1", "st2", "st3", /* 11 - 14 */
8478 "st4", "st5", "st6", "st7", /* 15 - 18 */
8479 NULL
, NULL
, /* 19 - 20 */
8480 "xmm0", "xmm1", "xmm2", "xmm3", /* 21 - 24 */
8481 "xmm4", "xmm5", "xmm6", "xmm7", /* 25 - 28 */
8482 "mm0", "mm1", "mm2", "mm3", /* 29 - 32 */
8483 "mm4", "mm5", "mm6", "mm7", /* 33 - 36 */
8484 "fcw", "fsw", "mxcsr", /* 37 - 39 */
8485 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
, /* 40 - 47 */
8486 "tr", "ldtr", /* 48 - 49 */
8487 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 50 - 57 */
8488 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 58 - 65 */
8489 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 66 - 73 */
8490 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 74 - 81 */
8491 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 82 - 89 */
8492 NULL
, NULL
, NULL
, /* 90 - 92 */
8493 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7" /* 93 - 100 */
8496 static const char *const dwarf_regnames_iamcu
[] =
8498 "eax", "ecx", "edx", "ebx", /* 0 - 3 */
8499 "esp", "ebp", "esi", "edi", /* 4 - 7 */
8500 "eip", "eflags", NULL
, /* 8 - 10 */
8501 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 11 - 18 */
8502 NULL
, NULL
, /* 19 - 20 */
8503 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 21 - 28 */
8504 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 29 - 36 */
8505 NULL
, NULL
, NULL
, /* 37 - 39 */
8506 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
, /* 40 - 47 */
8507 "tr", "ldtr", /* 48 - 49 */
8508 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 50 - 57 */
8509 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 58 - 65 */
8510 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 66 - 73 */
8511 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 74 - 81 */
8512 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 82 - 89 */
8513 NULL
, NULL
, NULL
, /* 90 - 92 */
8514 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
/* 93 - 100 */
8518 init_dwarf_regnames_i386 (void)
8520 dwarf_regnames
= dwarf_regnames_i386
;
8521 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_i386
);
8522 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8526 init_dwarf_regnames_iamcu (void)
8528 dwarf_regnames
= dwarf_regnames_iamcu
;
8529 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_iamcu
);
8530 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8533 static const char *const DW_CFA_GNU_window_save_name
[] =
8535 "DW_CFA_GNU_window_save",
8536 "DW_CFA_AARCH64_negate_ra_state"
8539 static const char *const dwarf_regnames_x86_64
[] =
8541 "rax", "rdx", "rcx", "rbx",
8542 "rsi", "rdi", "rbp", "rsp",
8543 "r8", "r9", "r10", "r11",
8544 "r12", "r13", "r14", "r15",
8546 "xmm0", "xmm1", "xmm2", "xmm3",
8547 "xmm4", "xmm5", "xmm6", "xmm7",
8548 "xmm8", "xmm9", "xmm10", "xmm11",
8549 "xmm12", "xmm13", "xmm14", "xmm15",
8550 "st0", "st1", "st2", "st3",
8551 "st4", "st5", "st6", "st7",
8552 "mm0", "mm1", "mm2", "mm3",
8553 "mm4", "mm5", "mm6", "mm7",
8555 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
,
8556 "fs.base", "gs.base", NULL
, NULL
,
8558 "mxcsr", "fcw", "fsw",
8559 "xmm16", "xmm17", "xmm18", "xmm19",
8560 "xmm20", "xmm21", "xmm22", "xmm23",
8561 "xmm24", "xmm25", "xmm26", "xmm27",
8562 "xmm28", "xmm29", "xmm30", "xmm31",
8563 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 83 - 90 */
8564 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 91 - 98 */
8565 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 99 - 106 */
8566 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 107 - 114 */
8567 NULL
, NULL
, NULL
, /* 115 - 117 */
8568 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7"
8572 init_dwarf_regnames_x86_64 (void)
8574 dwarf_regnames
= dwarf_regnames_x86_64
;
8575 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_x86_64
);
8576 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8579 static const char *const dwarf_regnames_aarch64
[] =
8581 "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7",
8582 "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15",
8583 "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23",
8584 "x24", "x25", "x26", "x27", "x28", "x29", "x30", "sp",
8585 NULL
, "elr", NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
8586 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, "vg", "ffr",
8587 "p0", "p1", "p2", "p3", "p4", "p5", "p6", "p7",
8588 "p8", "p9", "p10", "p11", "p12", "p13", "p14", "p15",
8589 "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7",
8590 "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15",
8591 "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23",
8592 "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31",
8593 "z0", "z1", "z2", "z3", "z4", "z5", "z6", "z7",
8594 "z8", "z9", "z10", "z11", "z12", "z13", "z14", "z15",
8595 "z16", "z17", "z18", "z19", "z20", "z21", "z22", "z23",
8596 "z24", "z25", "z26", "z27", "z28", "z29", "z30", "z31",
8600 init_dwarf_regnames_aarch64 (void)
8602 dwarf_regnames
= dwarf_regnames_aarch64
;
8603 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_aarch64
);
8604 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8608 static const char *const dwarf_regnames_s390
[] =
8610 /* Avoid saying "r5 (r5)", so omit the names of r0-r15. */
8611 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
8612 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
8613 "f0", "f2", "f4", "f6", "f1", "f3", "f5", "f7",
8614 "f8", "f10", "f12", "f14", "f9", "f11", "f13", "f15",
8615 "cr0", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7",
8616 "cr8", "cr9", "cr10", "cr11", "cr12", "cr13", "cr14", "cr15",
8617 "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7",
8618 "a8", "a9", "a10", "a11", "a12", "a13", "a14", "a15",
8621 "v16", "v18", "v20", "v22", "v17", "v19", "v21", "v23",
8622 "v24", "v26", "v28", "v30", "v25", "v27", "v29", "v31",
8626 init_dwarf_regnames_s390 (void)
8628 dwarf_regnames
= dwarf_regnames_s390
;
8629 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_s390
);
8630 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8633 static const char *const dwarf_regnames_riscv
[] =
8635 "zero", "ra", "sp", "gp", "tp", "t0", "t1", "t2", /* 0 - 7 */
8636 "s0", "s1", "a0", "a1", "a2", "a3", "a4", "a5", /* 8 - 15 */
8637 "a6", "a7", "s2", "s3", "s4", "s5", "s6", "s7", /* 16 - 23 */
8638 "s8", "s9", "s10", "s11", "t3", "t4", "t5", "t6", /* 24 - 31 */
8639 "ft0", "ft1", "ft2", "ft3", "ft4", "ft5", "ft6", "ft7", /* 32 - 39 */
8640 "fs0", "fs1", /* 40 - 41 */
8641 "fa0", "fa1", "fa2", "fa3", "fa4", "fa5", "fa6", "fa7", /* 42 - 49 */
8642 "fs2", "fs3", "fs4", "fs5", "fs6", "fs7", "fs8", "fs9", /* 50 - 57 */
8643 "fs10", "fs11", /* 58 - 59 */
8644 "ft8", "ft9", "ft10", "ft11", /* 60 - 63 */
8645 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 64 - 71 */
8646 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 72 - 79 */
8647 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 80 - 87 */
8648 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 88 - 95 */
8649 "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", /* 96 - 103 */
8650 "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15", /* 104 - 111 */
8651 "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23", /* 112 - 119 */
8652 "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31", /* 120 - 127 */
8655 /* A RISC-V replacement for REGNAME_INTERNAL_BY_TABLE_ONLY which handles
8656 the large number of CSRs. */
8659 regname_internal_riscv (unsigned int regno
)
8661 const char *name
= NULL
;
8663 /* Lookup in the table first, this covers GPR and FPR. */
8664 if (regno
< ARRAY_SIZE (dwarf_regnames_riscv
))
8665 name
= dwarf_regnames_riscv
[regno
];
8666 else if (regno
>= 4096 && regno
<= 8191)
8668 /* This might be a CSR, these live in a sparse number space from 4096
8669 to 8191 These numbers are defined in the RISC-V ELF ABI
8673 #define DECLARE_CSR(NAME,VALUE,CLASS,DEFINE_VER,ABORT_VER) \
8674 case VALUE + 4096: name = #NAME; break;
8675 #include "opcode/riscv-opc.h"
8680 static char csr_name
[10];
8681 snprintf (csr_name
, sizeof (csr_name
), "csr%d", (regno
- 4096));
8692 init_dwarf_regnames_riscv (void)
8694 dwarf_regnames
= NULL
;
8695 dwarf_regnames_count
= 8192;
8696 dwarf_regnames_lookup_func
= regname_internal_riscv
;
8700 init_dwarf_regnames_by_elf_machine_code (unsigned int e_machine
)
8702 dwarf_regnames_lookup_func
= NULL
;
8708 init_dwarf_regnames_i386 ();
8712 init_dwarf_regnames_iamcu ();
8718 init_dwarf_regnames_x86_64 ();
8722 init_dwarf_regnames_aarch64 ();
8726 init_dwarf_regnames_s390 ();
8730 init_dwarf_regnames_riscv ();
8738 /* Initialize the DWARF register name lookup state based on the
8739 architecture and specific machine type of a BFD. */
8742 init_dwarf_regnames_by_bfd_arch_and_mach (enum bfd_architecture arch
,
8745 dwarf_regnames_lookup_func
= NULL
;
8753 case bfd_mach_x86_64
:
8754 case bfd_mach_x86_64_intel_syntax
:
8755 case bfd_mach_x64_32
:
8756 case bfd_mach_x64_32_intel_syntax
:
8757 init_dwarf_regnames_x86_64 ();
8761 init_dwarf_regnames_i386 ();
8766 case bfd_arch_iamcu
:
8767 init_dwarf_regnames_iamcu ();
8770 case bfd_arch_aarch64
:
8771 init_dwarf_regnames_aarch64();
8775 init_dwarf_regnames_s390 ();
8778 case bfd_arch_riscv
:
8779 init_dwarf_regnames_riscv ();
8788 regname_internal_by_table_only (unsigned int regno
)
8790 if (dwarf_regnames
!= NULL
8791 && regno
< dwarf_regnames_count
8792 && dwarf_regnames
[regno
] != NULL
)
8793 return dwarf_regnames
[regno
];
8799 regname (unsigned int regno
, int name_only_p
)
8801 static char reg
[64];
8803 const char *name
= NULL
;
8805 if (dwarf_regnames_lookup_func
!= NULL
)
8806 name
= dwarf_regnames_lookup_func (regno
);
8812 snprintf (reg
, sizeof (reg
), "r%d (%s)", regno
, name
);
8815 snprintf (reg
, sizeof (reg
), "r%d", regno
);
8820 frame_display_row (Frame_Chunk
*fc
, int *need_col_headers
, unsigned int *max_regs
)
8825 if (*max_regs
!= fc
->ncols
)
8826 *max_regs
= fc
->ncols
;
8828 if (*need_col_headers
)
8830 *need_col_headers
= 0;
8832 printf ("%-*s CFA ", eh_addr_size
* 2, " LOC");
8834 for (r
= 0; r
< *max_regs
; r
++)
8835 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
8840 printf ("%-5s ", regname (r
, 1));
8846 print_hex (fc
->pc_begin
, eh_addr_size
);
8848 strcpy (tmp
, "exp");
8850 sprintf (tmp
, "%s%+d", regname (fc
->cfa_reg
, 1), (int) fc
->cfa_offset
);
8851 printf ("%-8s ", tmp
);
8853 for (r
= 0; r
< fc
->ncols
; r
++)
8855 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
8857 switch (fc
->col_type
[r
])
8859 case DW_CFA_undefined
:
8862 case DW_CFA_same_value
:
8866 sprintf (tmp
, "c%+" PRId64
, fc
->col_offset
[r
]);
8868 case DW_CFA_val_offset
:
8869 sprintf (tmp
, "v%+" PRId64
, fc
->col_offset
[r
]);
8871 case DW_CFA_register
:
8872 sprintf (tmp
, "%s", regname (fc
->col_offset
[r
], 0));
8874 case DW_CFA_expression
:
8875 strcpy (tmp
, "exp");
8877 case DW_CFA_val_expression
:
8878 strcpy (tmp
, "vexp");
8881 strcpy (tmp
, "n/a");
8884 printf ("%-5s ", tmp
);
8890 #define GET(VAR, N) SAFE_BYTE_GET_AND_INC (VAR, start, N, end)
8892 static unsigned char *
8893 read_cie (unsigned char *start
, unsigned char *end
,
8894 Frame_Chunk
**p_cie
, int *p_version
,
8895 uint64_t *p_aug_len
, unsigned char **p_aug
)
8899 unsigned char *augmentation_data
= NULL
;
8900 uint64_t augmentation_data_len
= 0;
8903 /* PR 17512: file: 001-228113-0.004. */
8907 fc
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
8908 memset (fc
, 0, sizeof (Frame_Chunk
));
8910 fc
->col_type
= xmalloc (sizeof (*fc
->col_type
));
8911 fc
->col_offset
= xmalloc (sizeof (*fc
->col_offset
));
8915 fc
->augmentation
= (char *) start
;
8916 /* PR 17512: file: 001-228113-0.004.
8917 Skip past augmentation name, but avoid running off the end of the data. */
8919 if (* start
++ == '\0')
8923 warn (_("No terminator for augmentation name\n"));
8927 if (strcmp (fc
->augmentation
, "eh") == 0)
8929 if (eh_addr_size
> (size_t) (end
- start
))
8931 start
+= eh_addr_size
;
8936 if (2 > (size_t) (end
- start
))
8938 GET (fc
->ptr_size
, 1);
8939 if (fc
->ptr_size
< 1 || fc
->ptr_size
> 8)
8941 warn (_("Invalid pointer size (%d) in CIE data\n"), fc
->ptr_size
);
8945 GET (fc
->segment_size
, 1);
8946 /* PR 17512: file: e99d2804. */
8947 if (fc
->segment_size
> 8 || fc
->segment_size
+ fc
->ptr_size
> 8)
8949 warn (_("Invalid segment size (%d) in CIE data\n"), fc
->segment_size
);
8953 eh_addr_size
= fc
->ptr_size
;
8957 fc
->ptr_size
= eh_addr_size
;
8958 fc
->segment_size
= 0;
8961 READ_ULEB (fc
->code_factor
, start
, end
);
8962 READ_SLEB (fc
->data_factor
, start
, end
);
8973 READ_ULEB (fc
->ra
, start
, end
);
8976 if (fc
->augmentation
[0] == 'z')
8980 READ_ULEB (augmentation_data_len
, start
, end
);
8981 augmentation_data
= start
;
8982 /* PR 17512: file: 11042-2589-0.004. */
8983 if (augmentation_data_len
> (size_t) (end
- start
))
8985 warn (_("Augmentation data too long: %#" PRIx64
8986 ", expected at most %#tx\n"),
8987 augmentation_data_len
, end
- start
);
8990 start
+= augmentation_data_len
;
8993 if (augmentation_data_len
)
8997 unsigned char *qend
;
8999 p
= (unsigned char *) fc
->augmentation
+ 1;
9000 q
= augmentation_data
;
9001 qend
= q
+ augmentation_data_len
;
9003 while (p
< end
&& q
< qend
)
9008 q
+= 1 + size_of_encoded_value (*q
);
9010 fc
->fde_encoding
= *q
++;
9019 /* Note - it is OK if this loop terminates with q < qend.
9020 Padding may have been inserted to align the end of the CIE. */
9025 *p_version
= version
;
9028 *p_aug_len
= augmentation_data_len
;
9029 *p_aug
= augmentation_data
;
9034 free (fc
->col_offset
);
9035 free (fc
->col_type
);
9040 /* Prints out the contents on the DATA array formatted as unsigned bytes.
9041 If do_wide is not enabled, then formats the output to fit into 80 columns.
9042 PRINTED contains the number of characters already written to the current
9046 display_data (size_t printed
, const unsigned char *data
, size_t len
)
9048 if (do_wide
|| len
< ((80 - printed
) / 3))
9049 for (printed
= 0; printed
< len
; ++printed
)
9050 printf (" %02x", data
[printed
]);
9053 for (printed
= 0; printed
< len
; ++printed
)
9055 if (printed
% (80 / 3) == 0)
9057 printf (" %02x", data
[printed
]);
9062 /* Prints out the contents on the augmentation data array.
9063 If do_wide is not enabled, then formats the output to fit into 80 columns. */
9066 display_augmentation_data (const unsigned char * data
, uint64_t len
)
9070 i
= printf (_(" Augmentation data: "));
9071 display_data (i
, data
, len
);
9075 display_debug_frames (struct dwarf_section
*section
,
9076 void *file ATTRIBUTE_UNUSED
)
9078 unsigned char *start
= section
->start
;
9079 unsigned char *end
= start
+ section
->size
;
9080 unsigned char *section_start
= start
;
9081 Frame_Chunk
*chunks
= NULL
, *forward_refs
= NULL
;
9082 Frame_Chunk
*remembered_state
= NULL
;
9084 bool is_eh
= strcmp (section
->name
, ".eh_frame") == 0;
9085 unsigned int max_regs
= 0;
9086 const char *bad_reg
= _("bad register: ");
9087 unsigned int saved_eh_addr_size
= eh_addr_size
;
9089 introduce (section
, false);
9093 unsigned char *saved_start
;
9094 unsigned char *block_end
;
9099 int need_col_headers
= 1;
9100 unsigned char *augmentation_data
= NULL
;
9101 uint64_t augmentation_data_len
= 0;
9102 unsigned int encoded_ptr_size
= saved_eh_addr_size
;
9103 unsigned int offset_size
;
9105 static Frame_Chunk fde_fc
;
9107 saved_start
= start
;
9109 SAFE_BYTE_GET_AND_INC (length
, start
, 4, end
);
9113 printf ("\n%08tx ZERO terminator\n\n",
9114 saved_start
- section_start
);
9115 /* Skip any zero terminators that directly follow.
9116 A corrupt section size could have loaded a whole
9117 slew of zero filled memory bytes. eg
9118 PR 17512: file: 070-19381-0.004. */
9119 while (start
< end
&& * start
== 0)
9124 if (length
== 0xffffffff)
9126 SAFE_BYTE_GET_AND_INC (length
, start
, 8, end
);
9132 if (length
> (size_t) (end
- start
))
9134 warn ("Invalid length %#" PRIx64
" in FDE at %#tx\n",
9135 length
, saved_start
- section_start
);
9139 block_end
= start
+ length
;
9141 SAFE_BYTE_GET_AND_INC (cie_id
, start
, offset_size
, block_end
);
9143 if (is_eh
? (cie_id
== 0) : ((offset_size
== 4 && cie_id
== DW_CIE_ID
)
9144 || (offset_size
== 8 && cie_id
== DW64_CIE_ID
)))
9149 start
= read_cie (start
, block_end
, &cie
, &version
,
9150 &augmentation_data_len
, &augmentation_data
);
9151 /* PR 17512: file: 027-135133-0.005. */
9158 fc
->chunk_start
= saved_start
;
9159 mreg
= max_regs
> 0 ? max_regs
- 1 : 0;
9162 if (frame_need_space (fc
, mreg
) < 0)
9164 if (fc
->fde_encoding
)
9165 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
9167 printf ("\n%08tx ", saved_start
- section_start
);
9168 print_hex (length
, fc
->ptr_size
);
9169 print_hex (cie_id
, offset_size
);
9171 if (do_debug_frames_interp
)
9173 printf ("CIE \"%s\" cf=%d df=%d ra=%d\n", fc
->augmentation
,
9174 fc
->code_factor
, fc
->data_factor
, fc
->ra
);
9179 printf (" Version: %d\n", version
);
9180 printf (" Augmentation: \"%s\"\n", fc
->augmentation
);
9183 printf (" Pointer Size: %u\n", fc
->ptr_size
);
9184 printf (" Segment Size: %u\n", fc
->segment_size
);
9186 printf (" Code alignment factor: %u\n", fc
->code_factor
);
9187 printf (" Data alignment factor: %d\n", fc
->data_factor
);
9188 printf (" Return address column: %d\n", fc
->ra
);
9190 if (augmentation_data_len
)
9191 display_augmentation_data (augmentation_data
, augmentation_data_len
);
9198 unsigned char *look_for
;
9199 unsigned long segment_selector
;
9205 uint64_t sign
= (uint64_t) 1 << (offset_size
* 8 - 1);
9206 cie_off
= (cie_off
^ sign
) - sign
;
9207 cie_off
= start
- 4 - section_start
- cie_off
;
9210 look_for
= section_start
+ cie_off
;
9211 if (cie_off
<= (size_t) (saved_start
- section_start
))
9213 for (cie
= chunks
; cie
; cie
= cie
->next
)
9214 if (cie
->chunk_start
== look_for
)
9217 else if (cie_off
>= section
->size
)
9221 for (cie
= forward_refs
; cie
; cie
= cie
->next
)
9222 if (cie
->chunk_start
== look_for
)
9226 unsigned int off_size
;
9227 unsigned char *cie_scan
;
9229 cie_scan
= look_for
;
9231 SAFE_BYTE_GET_AND_INC (length
, cie_scan
, 4, end
);
9232 if (length
== 0xffffffff)
9234 SAFE_BYTE_GET_AND_INC (length
, cie_scan
, 8, end
);
9237 if (length
!= 0 && length
<= (size_t) (end
- cie_scan
))
9240 unsigned char *cie_end
= cie_scan
+ length
;
9242 SAFE_BYTE_GET_AND_INC (c_id
, cie_scan
, off_size
,
9246 : ((off_size
== 4 && c_id
== DW_CIE_ID
)
9247 || (off_size
== 8 && c_id
== DW64_CIE_ID
)))
9252 read_cie (cie_scan
, cie_end
, &cie
, &version
,
9253 &augmentation_data_len
, &augmentation_data
);
9254 /* PR 17512: file: 3450-2098-0.004. */
9257 warn (_("Failed to read CIE information\n"));
9260 cie
->next
= forward_refs
;
9262 cie
->chunk_start
= look_for
;
9263 mreg
= max_regs
> 0 ? max_regs
- 1 : 0;
9266 if (frame_need_space (cie
, mreg
) < 0)
9268 warn (_("Invalid max register\n"));
9271 if (cie
->fde_encoding
)
9273 = size_of_encoded_value (cie
->fde_encoding
);
9280 memset (fc
, 0, sizeof (Frame_Chunk
));
9285 fc
->col_type
= xmalloc (sizeof (*fc
->col_type
));
9286 fc
->col_offset
= xmalloc (sizeof (*fc
->col_offset
));
9287 if (frame_need_space (fc
, max_regs
> 0 ? max_regs
- 1 : 0) < 0)
9289 warn (_("Invalid max register\n"));
9293 fc
->augmentation
= "";
9294 fc
->fde_encoding
= 0;
9295 fc
->ptr_size
= eh_addr_size
;
9296 fc
->segment_size
= 0;
9300 fc
->ncols
= cie
->ncols
;
9301 fc
->col_type
= xcmalloc (fc
->ncols
, sizeof (*fc
->col_type
));
9302 fc
->col_offset
= xcmalloc (fc
->ncols
, sizeof (*fc
->col_offset
));
9303 memcpy (fc
->col_type
, cie
->col_type
,
9304 fc
->ncols
* sizeof (*fc
->col_type
));
9305 memcpy (fc
->col_offset
, cie
->col_offset
,
9306 fc
->ncols
* sizeof (*fc
->col_offset
));
9307 fc
->augmentation
= cie
->augmentation
;
9308 fc
->ptr_size
= cie
->ptr_size
;
9309 eh_addr_size
= cie
->ptr_size
;
9310 fc
->segment_size
= cie
->segment_size
;
9311 fc
->code_factor
= cie
->code_factor
;
9312 fc
->data_factor
= cie
->data_factor
;
9313 fc
->cfa_reg
= cie
->cfa_reg
;
9314 fc
->cfa_offset
= cie
->cfa_offset
;
9316 if (frame_need_space (fc
, max_regs
> 0 ? max_regs
- 1: 0) < 0)
9318 warn (_("Invalid max register\n"));
9321 fc
->fde_encoding
= cie
->fde_encoding
;
9324 if (fc
->fde_encoding
)
9325 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
9327 segment_selector
= 0;
9328 if (fc
->segment_size
)
9330 if (fc
->segment_size
> sizeof (segment_selector
))
9332 /* PR 17512: file: 9e196b3e. */
9333 warn (_("Probably corrupt segment size: %d - using 4 instead\n"), fc
->segment_size
);
9334 fc
->segment_size
= 4;
9336 SAFE_BYTE_GET_AND_INC (segment_selector
, start
,
9337 fc
->segment_size
, block_end
);
9340 fc
->pc_begin
= get_encoded_value (&start
, fc
->fde_encoding
, section
,
9343 /* FIXME: It appears that sometimes the final pc_range value is
9344 encoded in less than encoded_ptr_size bytes. See the x86_64
9345 run of the "objcopy on compressed debug sections" test for an
9347 SAFE_BYTE_GET_AND_INC (fc
->pc_range
, start
, encoded_ptr_size
,
9350 if (cie
->augmentation
[0] == 'z')
9352 READ_ULEB (augmentation_data_len
, start
, block_end
);
9353 augmentation_data
= start
;
9354 /* PR 17512 file: 722-8446-0.004 and PR 22386. */
9355 if (augmentation_data_len
> (size_t) (block_end
- start
))
9357 warn (_("Augmentation data too long: %#" PRIx64
", "
9358 "expected at most %#tx\n"),
9359 augmentation_data_len
, block_end
- start
);
9361 augmentation_data
= NULL
;
9362 augmentation_data_len
= 0;
9364 start
+= augmentation_data_len
;
9367 printf ("\n%08tx ", saved_start
- section_start
);
9368 print_hex (length
, fc
->ptr_size
);
9369 print_hex (cie_id
, offset_size
);
9372 if (cie
->chunk_start
)
9373 printf ("cie=%08tx", cie
->chunk_start
- section_start
);
9375 /* Ideally translate "invalid " to 8 chars, trailing space
9377 printf (_("cie=invalid "));
9380 if (fc
->segment_size
)
9381 printf ("%04lx:", segment_selector
);
9383 print_hex_ns (fc
->pc_begin
, fc
->ptr_size
);
9385 print_hex_ns (fc
->pc_begin
+ fc
->pc_range
, fc
->ptr_size
);
9388 if (! do_debug_frames_interp
&& augmentation_data_len
)
9390 display_augmentation_data (augmentation_data
, augmentation_data_len
);
9395 /* At this point, fc is the current chunk, cie (if any) is set, and
9396 we're about to interpret instructions for the chunk. */
9397 /* ??? At present we need to do this always, since this sizes the
9398 fc->col_type and fc->col_offset arrays, which we write into always.
9399 We should probably split the interpreted and non-interpreted bits
9400 into two different routines, since there's so much that doesn't
9401 really overlap between them. */
9402 if (1 || do_debug_frames_interp
)
9404 /* Start by making a pass over the chunk, allocating storage
9405 and taking note of what registers are used. */
9406 unsigned char *tmp
= start
;
9408 while (start
< block_end
)
9410 unsigned int reg
, op
, opa
;
9418 /* Warning: if you add any more cases to this switch, be
9419 sure to add them to the corresponding switch below. */
9423 case DW_CFA_advance_loc
:
9426 SKIP_ULEB (start
, block_end
);
9429 case DW_CFA_restore
:
9432 case DW_CFA_set_loc
:
9433 if ((size_t) (block_end
- start
) < encoded_ptr_size
)
9436 start
+= encoded_ptr_size
;
9438 case DW_CFA_advance_loc1
:
9439 if ((size_t) (block_end
- start
) < 1)
9444 case DW_CFA_advance_loc2
:
9445 if ((size_t) (block_end
- start
) < 2)
9450 case DW_CFA_advance_loc4
:
9451 if ((size_t) (block_end
- start
) < 4)
9456 case DW_CFA_offset_extended
:
9457 case DW_CFA_val_offset
:
9458 READ_ULEB (reg
, start
, block_end
);
9459 SKIP_ULEB (start
, block_end
);
9461 case DW_CFA_restore_extended
:
9462 READ_ULEB (reg
, start
, block_end
);
9464 case DW_CFA_undefined
:
9465 READ_ULEB (reg
, start
, block_end
);
9467 case DW_CFA_same_value
:
9468 READ_ULEB (reg
, start
, block_end
);
9470 case DW_CFA_register
:
9471 READ_ULEB (reg
, start
, block_end
);
9472 SKIP_ULEB (start
, block_end
);
9474 case DW_CFA_def_cfa
:
9475 SKIP_ULEB (start
, block_end
);
9476 SKIP_ULEB (start
, block_end
);
9478 case DW_CFA_def_cfa_register
:
9479 SKIP_ULEB (start
, block_end
);
9481 case DW_CFA_def_cfa_offset
:
9482 SKIP_ULEB (start
, block_end
);
9484 case DW_CFA_def_cfa_expression
:
9485 READ_ULEB (temp
, start
, block_end
);
9486 if ((size_t) (block_end
- start
) < temp
)
9491 case DW_CFA_expression
:
9492 case DW_CFA_val_expression
:
9493 READ_ULEB (reg
, start
, block_end
);
9494 READ_ULEB (temp
, start
, block_end
);
9495 if ((size_t) (block_end
- start
) < temp
)
9500 case DW_CFA_offset_extended_sf
:
9501 case DW_CFA_val_offset_sf
:
9502 READ_ULEB (reg
, start
, block_end
);
9503 SKIP_SLEB (start
, block_end
);
9505 case DW_CFA_def_cfa_sf
:
9506 SKIP_ULEB (start
, block_end
);
9507 SKIP_SLEB (start
, block_end
);
9509 case DW_CFA_def_cfa_offset_sf
:
9510 SKIP_SLEB (start
, block_end
);
9512 case DW_CFA_MIPS_advance_loc8
:
9513 if ((size_t) (block_end
- start
) < 8)
9518 case DW_CFA_GNU_args_size
:
9519 SKIP_ULEB (start
, block_end
);
9521 case DW_CFA_GNU_negative_offset_extended
:
9522 READ_ULEB (reg
, start
, block_end
);
9523 SKIP_ULEB (start
, block_end
);
9528 if (reg
!= -1u && frame_need_space (fc
, reg
) >= 0)
9530 /* Don't leave any reg as DW_CFA_unreferenced so
9531 that frame_display_row prints name of regs in
9532 header, and all referenced regs in each line. */
9533 if (reg
>= cie
->ncols
9534 || cie
->col_type
[reg
] == DW_CFA_unreferenced
)
9535 fc
->col_type
[reg
] = DW_CFA_undefined
;
9537 fc
->col_type
[reg
] = cie
->col_type
[reg
];
9545 /* Now we know what registers are used, make a second pass over
9546 the chunk, this time actually printing out the info. */
9548 while (start
< block_end
)
9551 /* Note: It is tempting to use an unsigned long for 'reg' but there
9552 are various functions, notably frame_space_needed() that assume that
9553 reg is an unsigned int. */
9557 const char *reg_prefix
= "";
9564 /* Make a note if something other than DW_CFA_nop happens. */
9565 if (op
!= DW_CFA_nop
)
9568 /* Warning: if you add any more cases to this switch, be
9569 sure to add them to the corresponding switch above. */
9572 case DW_CFA_advance_loc
:
9573 opa
*= fc
->code_factor
;
9574 if (do_debug_frames_interp
)
9575 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9578 printf (" DW_CFA_advance_loc: %d to ", opa
);
9579 print_hex_ns (fc
->pc_begin
+ opa
, fc
->ptr_size
);
9582 fc
->pc_begin
+= opa
;
9586 READ_ULEB (ofs
, start
, block_end
);
9587 ofs
*= fc
->data_factor
;
9588 if (opa
>= fc
->ncols
)
9589 reg_prefix
= bad_reg
;
9590 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9591 printf (" DW_CFA_offset: %s%s at cfa%+" PRId64
"\n",
9592 reg_prefix
, regname (opa
, 0), ofs
);
9593 if (*reg_prefix
== '\0')
9595 fc
->col_type
[opa
] = DW_CFA_offset
;
9596 fc
->col_offset
[opa
] = ofs
;
9600 case DW_CFA_restore
:
9601 if (opa
>= fc
->ncols
)
9602 reg_prefix
= bad_reg
;
9603 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9604 printf (" DW_CFA_restore: %s%s\n",
9605 reg_prefix
, regname (opa
, 0));
9606 if (*reg_prefix
!= '\0')
9609 if (opa
>= cie
->ncols
9610 || cie
->col_type
[opa
] == DW_CFA_unreferenced
)
9612 fc
->col_type
[opa
] = DW_CFA_undefined
;
9613 fc
->col_offset
[opa
] = 0;
9617 fc
->col_type
[opa
] = cie
->col_type
[opa
];
9618 fc
->col_offset
[opa
] = cie
->col_offset
[opa
];
9622 case DW_CFA_set_loc
:
9623 ofs
= get_encoded_value (&start
, fc
->fde_encoding
, section
,
9625 if (do_debug_frames_interp
)
9626 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9629 printf (" DW_CFA_set_loc: ");
9630 print_hex_ns (ofs
, fc
->ptr_size
);
9636 case DW_CFA_advance_loc1
:
9637 SAFE_BYTE_GET_AND_INC (ofs
, start
, 1, block_end
);
9638 ofs
*= fc
->code_factor
;
9639 if (do_debug_frames_interp
)
9640 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9643 printf (" DW_CFA_advance_loc1: %" PRId64
" to ", ofs
);
9644 print_hex_ns (fc
->pc_begin
+ ofs
, fc
->ptr_size
);
9647 fc
->pc_begin
+= ofs
;
9650 case DW_CFA_advance_loc2
:
9651 SAFE_BYTE_GET_AND_INC (ofs
, start
, 2, block_end
);
9652 ofs
*= fc
->code_factor
;
9653 if (do_debug_frames_interp
)
9654 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9657 printf (" DW_CFA_advance_loc2: %" PRId64
" to ", ofs
);
9658 print_hex_ns (fc
->pc_begin
+ ofs
, fc
->ptr_size
);
9661 fc
->pc_begin
+= ofs
;
9664 case DW_CFA_advance_loc4
:
9665 SAFE_BYTE_GET_AND_INC (ofs
, start
, 4, block_end
);
9666 ofs
*= fc
->code_factor
;
9667 if (do_debug_frames_interp
)
9668 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9671 printf (" DW_CFA_advance_loc4: %" PRId64
" to ", ofs
);
9672 print_hex_ns (fc
->pc_begin
+ ofs
, fc
->ptr_size
);
9675 fc
->pc_begin
+= ofs
;
9678 case DW_CFA_offset_extended
:
9679 READ_ULEB (reg
, start
, block_end
);
9680 READ_ULEB (ofs
, start
, block_end
);
9681 ofs
*= fc
->data_factor
;
9682 if (reg
>= fc
->ncols
)
9683 reg_prefix
= bad_reg
;
9684 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9685 printf (" DW_CFA_offset_extended: %s%s at cfa%+" PRId64
"\n",
9686 reg_prefix
, regname (reg
, 0), ofs
);
9687 if (*reg_prefix
== '\0')
9689 fc
->col_type
[reg
] = DW_CFA_offset
;
9690 fc
->col_offset
[reg
] = ofs
;
9694 case DW_CFA_val_offset
:
9695 READ_ULEB (reg
, start
, block_end
);
9696 READ_ULEB (ofs
, start
, block_end
);
9697 ofs
*= fc
->data_factor
;
9698 if (reg
>= fc
->ncols
)
9699 reg_prefix
= bad_reg
;
9700 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9701 printf (" DW_CFA_val_offset: %s%s is cfa%+" PRId64
"\n",
9702 reg_prefix
, regname (reg
, 0), ofs
);
9703 if (*reg_prefix
== '\0')
9705 fc
->col_type
[reg
] = DW_CFA_val_offset
;
9706 fc
->col_offset
[reg
] = ofs
;
9710 case DW_CFA_restore_extended
:
9711 READ_ULEB (reg
, start
, block_end
);
9712 if (reg
>= fc
->ncols
)
9713 reg_prefix
= bad_reg
;
9714 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9715 printf (" DW_CFA_restore_extended: %s%s\n",
9716 reg_prefix
, regname (reg
, 0));
9717 if (*reg_prefix
!= '\0')
9720 if (reg
>= cie
->ncols
9721 || cie
->col_type
[reg
] == DW_CFA_unreferenced
)
9723 fc
->col_type
[reg
] = DW_CFA_undefined
;
9724 fc
->col_offset
[reg
] = 0;
9728 fc
->col_type
[reg
] = cie
->col_type
[reg
];
9729 fc
->col_offset
[reg
] = cie
->col_offset
[reg
];
9733 case DW_CFA_undefined
:
9734 READ_ULEB (reg
, start
, block_end
);
9735 if (reg
>= fc
->ncols
)
9736 reg_prefix
= bad_reg
;
9737 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9738 printf (" DW_CFA_undefined: %s%s\n",
9739 reg_prefix
, regname (reg
, 0));
9740 if (*reg_prefix
== '\0')
9742 fc
->col_type
[reg
] = DW_CFA_undefined
;
9743 fc
->col_offset
[reg
] = 0;
9747 case DW_CFA_same_value
:
9748 READ_ULEB (reg
, start
, block_end
);
9749 if (reg
>= fc
->ncols
)
9750 reg_prefix
= bad_reg
;
9751 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9752 printf (" DW_CFA_same_value: %s%s\n",
9753 reg_prefix
, regname (reg
, 0));
9754 if (*reg_prefix
== '\0')
9756 fc
->col_type
[reg
] = DW_CFA_same_value
;
9757 fc
->col_offset
[reg
] = 0;
9761 case DW_CFA_register
:
9762 READ_ULEB (reg
, start
, block_end
);
9763 READ_ULEB (ofs
, start
, block_end
);
9764 if (reg
>= fc
->ncols
)
9765 reg_prefix
= bad_reg
;
9766 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9768 printf (" DW_CFA_register: %s%s in ",
9769 reg_prefix
, regname (reg
, 0));
9770 puts (regname (ofs
, 0));
9772 if (*reg_prefix
== '\0')
9774 fc
->col_type
[reg
] = DW_CFA_register
;
9775 fc
->col_offset
[reg
] = ofs
;
9779 case DW_CFA_remember_state
:
9780 if (! do_debug_frames_interp
)
9781 printf (" DW_CFA_remember_state\n");
9782 rs
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
9783 rs
->cfa_offset
= fc
->cfa_offset
;
9784 rs
->cfa_reg
= fc
->cfa_reg
;
9786 rs
->cfa_exp
= fc
->cfa_exp
;
9787 rs
->ncols
= fc
->ncols
;
9788 rs
->col_type
= xcmalloc (rs
->ncols
, sizeof (*rs
->col_type
));
9789 rs
->col_offset
= xcmalloc (rs
->ncols
, sizeof (*rs
->col_offset
));
9790 memcpy (rs
->col_type
, fc
->col_type
,
9791 rs
->ncols
* sizeof (*fc
->col_type
));
9792 memcpy (rs
->col_offset
, fc
->col_offset
,
9793 rs
->ncols
* sizeof (*fc
->col_offset
));
9794 rs
->next
= remembered_state
;
9795 remembered_state
= rs
;
9798 case DW_CFA_restore_state
:
9799 if (! do_debug_frames_interp
)
9800 printf (" DW_CFA_restore_state\n");
9801 rs
= remembered_state
;
9804 remembered_state
= rs
->next
;
9805 fc
->cfa_offset
= rs
->cfa_offset
;
9806 fc
->cfa_reg
= rs
->cfa_reg
;
9808 fc
->cfa_exp
= rs
->cfa_exp
;
9809 if (frame_need_space (fc
, rs
->ncols
- 1) < 0)
9811 warn (_("Invalid column number in saved frame state\n"));
9815 memcpy (fc
->col_type
, rs
->col_type
,
9816 rs
->ncols
* sizeof (*rs
->col_type
));
9817 memcpy (fc
->col_offset
, rs
->col_offset
,
9818 rs
->ncols
* sizeof (*rs
->col_offset
));
9819 free (rs
->col_type
);
9820 free (rs
->col_offset
);
9823 else if (do_debug_frames_interp
)
9824 printf ("Mismatched DW_CFA_restore_state\n");
9827 case DW_CFA_def_cfa
:
9828 READ_ULEB (fc
->cfa_reg
, start
, block_end
);
9829 READ_ULEB (fc
->cfa_offset
, start
, block_end
);
9831 if (! do_debug_frames_interp
)
9832 printf (" DW_CFA_def_cfa: %s ofs %d\n",
9833 regname (fc
->cfa_reg
, 0), (int) fc
->cfa_offset
);
9836 case DW_CFA_def_cfa_register
:
9837 READ_ULEB (fc
->cfa_reg
, start
, block_end
);
9839 if (! do_debug_frames_interp
)
9840 printf (" DW_CFA_def_cfa_register: %s\n",
9841 regname (fc
->cfa_reg
, 0));
9844 case DW_CFA_def_cfa_offset
:
9845 READ_ULEB (fc
->cfa_offset
, start
, block_end
);
9846 if (! do_debug_frames_interp
)
9847 printf (" DW_CFA_def_cfa_offset: %d\n", (int) fc
->cfa_offset
);
9851 if (! do_debug_frames_interp
)
9852 printf (" DW_CFA_nop\n");
9855 case DW_CFA_def_cfa_expression
:
9856 READ_ULEB (ofs
, start
, block_end
);
9857 if (ofs
> (size_t) (block_end
- start
))
9859 printf (_(" %s: <corrupt len %" PRIu64
">\n"),
9860 "DW_CFA_def_cfa_expression", ofs
);
9863 if (! do_debug_frames_interp
)
9865 printf (" DW_CFA_def_cfa_expression (");
9866 decode_location_expression (start
, eh_addr_size
, 0, -1,
9874 case DW_CFA_expression
:
9875 READ_ULEB (reg
, start
, block_end
);
9876 READ_ULEB (ofs
, start
, block_end
);
9877 if (reg
>= fc
->ncols
)
9878 reg_prefix
= bad_reg
;
9879 /* PR 17512: file: 069-133014-0.006. */
9880 /* PR 17512: file: 98c02eb4. */
9881 if (ofs
> (size_t) (block_end
- start
))
9883 printf (_(" %s: <corrupt len %" PRIu64
">\n"),
9884 "DW_CFA_expression", ofs
);
9887 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9889 printf (" DW_CFA_expression: %s%s (",
9890 reg_prefix
, regname (reg
, 0));
9891 decode_location_expression (start
, eh_addr_size
, 0, -1,
9895 if (*reg_prefix
== '\0')
9896 fc
->col_type
[reg
] = DW_CFA_expression
;
9900 case DW_CFA_val_expression
:
9901 READ_ULEB (reg
, start
, block_end
);
9902 READ_ULEB (ofs
, start
, block_end
);
9903 if (reg
>= fc
->ncols
)
9904 reg_prefix
= bad_reg
;
9905 if (ofs
> (size_t) (block_end
- start
))
9907 printf (" %s: <corrupt len %" PRIu64
">\n",
9908 "DW_CFA_val_expression", ofs
);
9911 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9913 printf (" DW_CFA_val_expression: %s%s (",
9914 reg_prefix
, regname (reg
, 0));
9915 decode_location_expression (start
, eh_addr_size
, 0, -1,
9919 if (*reg_prefix
== '\0')
9920 fc
->col_type
[reg
] = DW_CFA_val_expression
;
9924 case DW_CFA_offset_extended_sf
:
9925 READ_ULEB (reg
, start
, block_end
);
9926 READ_SLEB (sofs
, start
, block_end
);
9927 /* data_factor multiplicaton done here as unsigned to
9928 avoid integer overflow warnings from asan on fuzzed
9931 ofs
*= fc
->data_factor
;
9932 if (reg
>= fc
->ncols
)
9933 reg_prefix
= bad_reg
;
9934 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9935 printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+" PRId64
"\n",
9936 reg_prefix
, regname (reg
, 0), ofs
);
9937 if (*reg_prefix
== '\0')
9939 fc
->col_type
[reg
] = DW_CFA_offset
;
9940 fc
->col_offset
[reg
] = ofs
;
9944 case DW_CFA_val_offset_sf
:
9945 READ_ULEB (reg
, start
, block_end
);
9946 READ_SLEB (sofs
, start
, block_end
);
9948 ofs
*= fc
->data_factor
;
9949 if (reg
>= fc
->ncols
)
9950 reg_prefix
= bad_reg
;
9951 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9952 printf (" DW_CFA_val_offset_sf: %s%s is cfa%+" PRId64
"\n",
9953 reg_prefix
, regname (reg
, 0), ofs
);
9954 if (*reg_prefix
== '\0')
9956 fc
->col_type
[reg
] = DW_CFA_val_offset
;
9957 fc
->col_offset
[reg
] = ofs
;
9961 case DW_CFA_def_cfa_sf
:
9962 READ_ULEB (fc
->cfa_reg
, start
, block_end
);
9963 READ_SLEB (sofs
, start
, block_end
);
9965 ofs
*= fc
->data_factor
;
9966 fc
->cfa_offset
= ofs
;
9968 if (! do_debug_frames_interp
)
9969 printf (" DW_CFA_def_cfa_sf: %s ofs %" PRId64
"\n",
9970 regname (fc
->cfa_reg
, 0), ofs
);
9973 case DW_CFA_def_cfa_offset_sf
:
9974 READ_SLEB (sofs
, start
, block_end
);
9976 ofs
*= fc
->data_factor
;
9977 fc
->cfa_offset
= ofs
;
9978 if (! do_debug_frames_interp
)
9979 printf (" DW_CFA_def_cfa_offset_sf: %" PRId64
"\n", ofs
);
9982 case DW_CFA_MIPS_advance_loc8
:
9983 SAFE_BYTE_GET_AND_INC (ofs
, start
, 8, block_end
);
9984 ofs
*= fc
->code_factor
;
9985 if (do_debug_frames_interp
)
9986 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9989 printf (" DW_CFA_MIPS_advance_loc8: %" PRId64
" to ", ofs
);
9990 print_hex_ns (fc
->pc_begin
+ ofs
, fc
->ptr_size
);
9993 fc
->pc_begin
+= ofs
;
9996 case DW_CFA_GNU_window_save
:
9997 if (! do_debug_frames_interp
)
9998 printf (" %s\n", DW_CFA_GNU_window_save_name
[is_aarch64
]);
10001 case DW_CFA_GNU_args_size
:
10002 READ_ULEB (ofs
, start
, block_end
);
10003 if (! do_debug_frames_interp
)
10004 printf (" DW_CFA_GNU_args_size: %" PRIu64
"\n", ofs
);
10007 case DW_CFA_GNU_negative_offset_extended
:
10008 READ_ULEB (reg
, start
, block_end
);
10009 READ_SLEB (sofs
, start
, block_end
);
10011 ofs
= -ofs
* fc
->data_factor
;
10012 if (reg
>= fc
->ncols
)
10013 reg_prefix
= bad_reg
;
10014 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
10015 printf (" DW_CFA_GNU_negative_offset_extended: %s%s "
10016 "at cfa%+" PRId64
"\n",
10017 reg_prefix
, regname (reg
, 0), ofs
);
10018 if (*reg_prefix
== '\0')
10020 fc
->col_type
[reg
] = DW_CFA_offset
;
10021 fc
->col_offset
[reg
] = ofs
;
10026 if (op
>= DW_CFA_lo_user
&& op
<= DW_CFA_hi_user
)
10027 printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op
);
10029 warn (_("Unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op
);
10034 /* Interpret the CFA - as long as it is not completely full of NOPs. */
10035 if (do_debug_frames_interp
&& ! all_nops
)
10036 frame_display_row (fc
, &need_col_headers
, &max_regs
);
10038 if (fde_fc
.col_type
!= NULL
)
10040 free (fde_fc
.col_type
);
10041 fde_fc
.col_type
= NULL
;
10043 if (fde_fc
.col_offset
!= NULL
)
10045 free (fde_fc
.col_offset
);
10046 fde_fc
.col_offset
= NULL
;
10050 eh_addr_size
= saved_eh_addr_size
;
10055 while (remembered_state
!= NULL
)
10057 rs
= remembered_state
;
10058 remembered_state
= rs
->next
;
10059 free (rs
->col_type
);
10060 free (rs
->col_offset
);
10061 rs
->next
= NULL
; /* Paranoia. */
10065 while (chunks
!= NULL
)
10069 free (rs
->col_type
);
10070 free (rs
->col_offset
);
10071 rs
->next
= NULL
; /* Paranoia. */
10075 while (forward_refs
!= NULL
)
10078 forward_refs
= rs
->next
;
10079 free (rs
->col_type
);
10080 free (rs
->col_offset
);
10081 rs
->next
= NULL
; /* Paranoia. */
10091 display_debug_names (struct dwarf_section
*section
, void *file
)
10093 unsigned char *hdrptr
= section
->start
;
10094 uint64_t unit_length
;
10095 unsigned char *unit_start
;
10096 const unsigned char *const section_end
= section
->start
+ section
->size
;
10097 unsigned char *unit_end
;
10099 introduce (section
, false);
10101 load_debug_section_with_follow (str
, file
);
10103 for (; hdrptr
< section_end
; hdrptr
= unit_end
)
10105 unsigned int offset_size
;
10106 uint16_t dwarf_version
, padding
;
10107 uint32_t comp_unit_count
, local_type_unit_count
, foreign_type_unit_count
;
10108 uint64_t bucket_count
, name_count
, abbrev_table_size
;
10109 uint32_t augmentation_string_size
;
10111 bool augmentation_printable
;
10112 const char *augmentation_string
;
10115 unit_start
= hdrptr
;
10117 /* Get and check the length of the block. */
10118 SAFE_BYTE_GET_AND_INC (unit_length
, hdrptr
, 4, section_end
);
10120 if (unit_length
== 0xffffffff)
10122 /* This section is 64-bit DWARF. */
10123 SAFE_BYTE_GET_AND_INC (unit_length
, hdrptr
, 8, section_end
);
10129 if (unit_length
> (size_t) (section_end
- hdrptr
)
10130 || unit_length
< 2 + 2 + 4 * 7)
10133 warn (_("Debug info is corrupted, %s header at %#tx"
10134 " has length %#" PRIx64
"\n"),
10135 section
->name
, unit_start
- section
->start
, unit_length
);
10138 unit_end
= hdrptr
+ unit_length
;
10140 /* Get and check the version number. */
10141 SAFE_BYTE_GET_AND_INC (dwarf_version
, hdrptr
, 2, unit_end
);
10142 printf (_("Version %d\n"), (int) dwarf_version
);
10144 /* Prior versions did not exist, and future versions may not be
10145 backwards compatible. */
10146 if (dwarf_version
!= 5)
10148 warn (_("Only DWARF version 5 .debug_names "
10149 "is currently supported.\n"));
10153 SAFE_BYTE_GET_AND_INC (padding
, hdrptr
, 2, unit_end
);
10155 warn (_("Padding field of .debug_names must be 0 (found 0x%x)\n"),
10158 SAFE_BYTE_GET_AND_INC (comp_unit_count
, hdrptr
, 4, unit_end
);
10159 if (comp_unit_count
== 0)
10160 warn (_("Compilation unit count must be >= 1 in .debug_names\n"));
10162 SAFE_BYTE_GET_AND_INC (local_type_unit_count
, hdrptr
, 4, unit_end
);
10163 SAFE_BYTE_GET_AND_INC (foreign_type_unit_count
, hdrptr
, 4, unit_end
);
10164 SAFE_BYTE_GET_AND_INC (bucket_count
, hdrptr
, 4, unit_end
);
10165 SAFE_BYTE_GET_AND_INC (name_count
, hdrptr
, 4, unit_end
);
10166 SAFE_BYTE_GET_AND_INC (abbrev_table_size
, hdrptr
, 4, unit_end
);
10168 SAFE_BYTE_GET_AND_INC (augmentation_string_size
, hdrptr
, 4, unit_end
);
10169 if (augmentation_string_size
% 4 != 0)
10171 warn (_("Augmentation string length %u must be rounded up "
10172 "to a multiple of 4 in .debug_names.\n"),
10173 augmentation_string_size
);
10174 augmentation_string_size
+= (-augmentation_string_size
) & 3;
10176 if (augmentation_string_size
> (size_t) (unit_end
- hdrptr
))
10179 printf (_("Augmentation string:"));
10181 augmentation_printable
= true;
10182 augmentation_string
= (const char *) hdrptr
;
10184 for (i
= 0; i
< augmentation_string_size
; i
++)
10188 SAFE_BYTE_GET_AND_INC (uc
, hdrptr
, 1, unit_end
);
10189 printf (" %02x", uc
);
10191 if (uc
!= 0 && !ISPRINT (uc
))
10192 augmentation_printable
= false;
10195 if (augmentation_printable
)
10199 i
< augmentation_string_size
&& augmentation_string
[i
];
10201 putchar (augmentation_string
[i
]);
10206 printf (_("CU table:\n"));
10207 if (_mul_overflow (comp_unit_count
, offset_size
, &total
)
10208 || total
> (size_t) (unit_end
- hdrptr
))
10210 for (i
= 0; i
< comp_unit_count
; i
++)
10212 uint64_t cu_offset
;
10214 SAFE_BYTE_GET_AND_INC (cu_offset
, hdrptr
, offset_size
, unit_end
);
10215 printf ("[%3u] %#" PRIx64
"\n", i
, cu_offset
);
10219 printf (_("TU table:\n"));
10220 if (_mul_overflow (local_type_unit_count
, offset_size
, &total
)
10221 || total
> (size_t) (unit_end
- hdrptr
))
10223 for (i
= 0; i
< local_type_unit_count
; i
++)
10225 uint64_t tu_offset
;
10227 SAFE_BYTE_GET_AND_INC (tu_offset
, hdrptr
, offset_size
, unit_end
);
10228 printf ("[%3u] %#" PRIx64
"\n", i
, tu_offset
);
10232 printf (_("Foreign TU table:\n"));
10233 if (_mul_overflow (foreign_type_unit_count
, 8, &total
)
10234 || total
> (size_t) (unit_end
- hdrptr
))
10236 for (i
= 0; i
< foreign_type_unit_count
; i
++)
10238 uint64_t signature
;
10240 SAFE_BYTE_GET_AND_INC (signature
, hdrptr
, 8, unit_end
);
10241 printf (_("[%3u] "), i
);
10242 print_hex_ns (signature
, 8);
10247 uint64_t xtra
= (bucket_count
* sizeof (uint32_t)
10248 + name_count
* (sizeof (uint32_t) + 2 * offset_size
)
10249 + abbrev_table_size
);
10250 if (xtra
> (size_t) (unit_end
- hdrptr
))
10252 warn (_("Entry pool offset (%#" PRIx64
") exceeds unit size %#tx "
10253 "for unit %#tx in the debug_names\n"),
10254 xtra
, unit_end
- unit_start
, unit_start
- section
->start
);
10257 const uint32_t *const hash_table_buckets
= (uint32_t *) hdrptr
;
10258 hdrptr
+= bucket_count
* sizeof (uint32_t);
10259 const uint32_t *const hash_table_hashes
= (uint32_t *) hdrptr
;
10260 hdrptr
+= name_count
* sizeof (uint32_t);
10261 unsigned char *const name_table_string_offsets
= hdrptr
;
10262 hdrptr
+= name_count
* offset_size
;
10263 unsigned char *const name_table_entry_offsets
= hdrptr
;
10264 hdrptr
+= name_count
* offset_size
;
10265 unsigned char *const abbrev_table
= hdrptr
;
10266 hdrptr
+= abbrev_table_size
;
10267 const unsigned char *const abbrev_table_end
= hdrptr
;
10268 unsigned char *const entry_pool
= hdrptr
;
10270 size_t buckets_filled
= 0;
10272 for (bucketi
= 0; bucketi
< bucket_count
; bucketi
++)
10274 const uint32_t bucket
= hash_table_buckets
[bucketi
];
10279 printf (ngettext ("Used %zu of %lu bucket.\n",
10280 "Used %zu of %lu buckets.\n",
10281 (unsigned long) bucket_count
),
10282 buckets_filled
, (unsigned long) bucket_count
);
10284 if (bucket_count
!= 0)
10286 uint32_t hash_prev
= 0;
10287 size_t hash_clash_count
= 0;
10288 size_t longest_clash
= 0;
10289 size_t this_length
= 0;
10291 for (hashi
= 0; hashi
< name_count
; hashi
++)
10293 const uint32_t hash_this
= hash_table_hashes
[hashi
];
10297 if (hash_prev
% bucket_count
== hash_this
% bucket_count
)
10299 ++hash_clash_count
;
10301 longest_clash
= MAX (longest_clash
, this_length
);
10306 hash_prev
= hash_this
;
10308 printf (_("Out of %" PRIu64
" items there are %zu bucket clashes"
10309 " (longest of %zu entries).\n"),
10310 name_count
, hash_clash_count
, longest_clash
);
10312 if (name_count
!= buckets_filled
+ hash_clash_count
)
10313 warn (_("The name_count (%" PRIu64
")"
10314 " is not the same as the used bucket_count"
10315 " (%zu) + the hash clash count (%zu)"),
10316 name_count
, buckets_filled
, hash_clash_count
);
10319 struct abbrev_lookup_entry
10321 uint64_t abbrev_tag
;
10322 unsigned char *abbrev_lookup_ptr
;
10324 struct abbrev_lookup_entry
*abbrev_lookup
= NULL
;
10325 size_t abbrev_lookup_used
= 0;
10326 size_t abbrev_lookup_allocated
= 0;
10328 unsigned char *abbrevptr
= abbrev_table
;
10331 uint64_t abbrev_tag
;
10333 READ_ULEB (abbrev_tag
, abbrevptr
, abbrev_table_end
);
10334 if (abbrev_tag
== 0)
10336 if (abbrev_lookup_used
== abbrev_lookup_allocated
)
10338 abbrev_lookup_allocated
= MAX (0x100,
10339 abbrev_lookup_allocated
* 2);
10340 abbrev_lookup
= xrealloc (abbrev_lookup
,
10341 (abbrev_lookup_allocated
10342 * sizeof (*abbrev_lookup
)));
10344 assert (abbrev_lookup_used
< abbrev_lookup_allocated
);
10345 struct abbrev_lookup_entry
*entry
;
10346 for (entry
= abbrev_lookup
;
10347 entry
< abbrev_lookup
+ abbrev_lookup_used
;
10349 if (entry
->abbrev_tag
== abbrev_tag
)
10351 warn (_("Duplicate abbreviation tag %" PRIu64
10352 " in unit %#tx in the debug_names section\n"),
10353 abbrev_tag
, unit_start
- section
->start
);
10356 entry
= &abbrev_lookup
[abbrev_lookup_used
++];
10357 entry
->abbrev_tag
= abbrev_tag
;
10358 entry
->abbrev_lookup_ptr
= abbrevptr
;
10360 /* Skip DWARF tag. */
10361 SKIP_ULEB (abbrevptr
, abbrev_table_end
);
10364 uint64_t xindex
, form
;
10366 READ_ULEB (xindex
, abbrevptr
, abbrev_table_end
);
10367 READ_ULEB (form
, abbrevptr
, abbrev_table_end
);
10368 if (xindex
== 0 && form
== 0)
10373 printf (_("\nSymbol table:\n"));
10375 for (namei
= 0; namei
< name_count
; ++namei
)
10377 uint64_t string_offset
, entry_offset
;
10380 p
= name_table_string_offsets
+ namei
* offset_size
;
10381 SAFE_BYTE_GET (string_offset
, p
, offset_size
, unit_end
);
10382 p
= name_table_entry_offsets
+ namei
* offset_size
;
10383 SAFE_BYTE_GET (entry_offset
, p
, offset_size
, unit_end
);
10385 printf ("[%3u] #%08x %s:", namei
, hash_table_hashes
[namei
],
10386 fetch_indirect_string (string_offset
));
10388 unsigned char *entryptr
= entry_pool
+ entry_offset
;
10390 /* We need to scan first whether there is a single or multiple
10391 entries. TAGNO is -2 for the first entry, it is -1 for the
10392 initial tag read of the second entry, then it becomes 0 for the
10393 first entry for real printing etc. */
10395 /* Initialize it due to a false compiler warning. */
10396 uint64_t second_abbrev_tag
= -1;
10399 uint64_t abbrev_tag
;
10400 uint64_t dwarf_tag
;
10401 const struct abbrev_lookup_entry
*entry
;
10403 READ_ULEB (abbrev_tag
, entryptr
, unit_end
);
10406 second_abbrev_tag
= abbrev_tag
;
10408 entryptr
= entry_pool
+ entry_offset
;
10411 if (abbrev_tag
== 0)
10414 printf ("%s<%" PRIu64
">",
10415 (tagno
== 0 && second_abbrev_tag
== 0 ? " " : "\n\t"),
10418 for (entry
= abbrev_lookup
;
10419 entry
< abbrev_lookup
+ abbrev_lookup_used
;
10421 if (entry
->abbrev_tag
== abbrev_tag
)
10423 if (entry
>= abbrev_lookup
+ abbrev_lookup_used
)
10425 warn (_("Undefined abbreviation tag %" PRId64
10426 " in unit %#tx in the debug_names section\n"),
10428 unit_start
- section
->start
);
10431 abbrevptr
= entry
->abbrev_lookup_ptr
;
10432 READ_ULEB (dwarf_tag
, abbrevptr
, abbrev_table_end
);
10434 printf (" %s", get_TAG_name (dwarf_tag
));
10437 uint64_t xindex
, form
;
10439 READ_ULEB (xindex
, abbrevptr
, abbrev_table_end
);
10440 READ_ULEB (form
, abbrevptr
, abbrev_table_end
);
10441 if (xindex
== 0 && form
== 0)
10445 printf (" %s", get_IDX_name (xindex
));
10446 entryptr
= read_and_display_attr_value (0, form
, 0,
10447 unit_start
, entryptr
, unit_end
,
10449 dwarf_version
, NULL
,
10450 (tagno
< 0), section
,
10456 printf (_(" <no entries>"));
10460 free (abbrev_lookup
);
10467 display_debug_links (struct dwarf_section
* section
,
10468 void * file ATTRIBUTE_UNUSED
)
10470 const unsigned char * filename
;
10471 unsigned int filelen
;
10473 introduce (section
, false);
10475 /* The .gnu_debuglink section is formatted as:
10476 (c-string) Filename.
10477 (padding) If needed to reach a 4 byte boundary.
10478 (uint32_t) CRC32 value.
10480 The .gun_debugaltlink section is formatted as:
10481 (c-string) Filename.
10482 (binary) Build-ID. */
10484 filename
= section
->start
;
10485 filelen
= strnlen ((const char *) filename
, section
->size
);
10486 if (filelen
== section
->size
)
10488 warn (_("The debuglink filename is corrupt/missing\n"));
10492 printf (_(" Separate debug info file: %s\n"), filename
);
10494 if (startswith (section
->name
, ".gnu_debuglink"))
10496 unsigned int crc32
;
10497 unsigned int crc_offset
;
10499 crc_offset
= filelen
+ 1;
10500 crc_offset
= (crc_offset
+ 3) & ~3;
10501 if (crc_offset
+ 4 > section
->size
)
10503 warn (_("CRC offset missing/truncated\n"));
10507 crc32
= byte_get (filename
+ crc_offset
, 4);
10509 printf (_(" CRC value: %#x\n"), crc32
);
10511 if (crc_offset
+ 4 < section
->size
)
10513 warn (_("There are %#" PRIx64
10514 " extraneous bytes at the end of the section\n"),
10515 section
->size
- (crc_offset
+ 4));
10519 else /* startswith (section->name, ".gnu_debugaltlink") */
10521 const unsigned char *build_id
= section
->start
+ filelen
+ 1;
10522 size_t build_id_len
= section
->size
- (filelen
+ 1);
10525 /* FIXME: Should we support smaller build-id notes ? */
10526 if (build_id_len
< 0x14)
10528 warn (_("Build-ID is too short (%#zx bytes)\n"), build_id_len
);
10532 printed
= printf (_(" Build-ID (%#zx bytes):"), build_id_len
);
10533 display_data (printed
, build_id
, build_id_len
);
10542 display_gdb_index (struct dwarf_section
*section
,
10543 void *file ATTRIBUTE_UNUSED
)
10545 unsigned char *start
= section
->start
;
10547 uint32_t cu_list_offset
, tu_list_offset
;
10548 uint32_t address_table_offset
, symbol_table_offset
, constant_pool_offset
;
10549 unsigned int cu_list_elements
, tu_list_elements
;
10550 unsigned int address_table_elements
, symbol_table_slots
;
10551 unsigned char *cu_list
, *tu_list
;
10552 unsigned char *address_table
, *symbol_table
, *constant_pool
;
10555 /* The documentation for the format of this file is in gdb/dwarf2read.c. */
10557 introduce (section
, false);
10559 if (section
->size
< 6 * sizeof (uint32_t))
10561 warn (_("Truncated header in the %s section.\n"), section
->name
);
10565 version
= byte_get_little_endian (start
, 4);
10566 printf (_("Version %lu\n"), (unsigned long) version
);
10568 /* Prior versions are obsolete, and future versions may not be
10569 backwards compatible. */
10570 if (version
< 3 || version
> 8)
10572 warn (_("Unsupported version %lu.\n"), (unsigned long) version
);
10576 warn (_("The address table data in version 3 may be wrong.\n"));
10578 warn (_("Version 4 does not support case insensitive lookups.\n"));
10580 warn (_("Version 5 does not include inlined functions.\n"));
10582 warn (_("Version 6 does not include symbol attributes.\n"));
10583 /* Version 7 indices generated by Gold have bad type unit references,
10584 PR binutils/15021. But we don't know if the index was generated by
10585 Gold or not, so to avoid worrying users with gdb-generated indices
10586 we say nothing for version 7 here. */
10588 cu_list_offset
= byte_get_little_endian (start
+ 4, 4);
10589 tu_list_offset
= byte_get_little_endian (start
+ 8, 4);
10590 address_table_offset
= byte_get_little_endian (start
+ 12, 4);
10591 symbol_table_offset
= byte_get_little_endian (start
+ 16, 4);
10592 constant_pool_offset
= byte_get_little_endian (start
+ 20, 4);
10594 if (cu_list_offset
> section
->size
10595 || tu_list_offset
> section
->size
10596 || address_table_offset
> section
->size
10597 || symbol_table_offset
> section
->size
10598 || constant_pool_offset
> section
->size
10599 || tu_list_offset
< cu_list_offset
10600 || address_table_offset
< tu_list_offset
10601 || symbol_table_offset
< address_table_offset
10602 || constant_pool_offset
< symbol_table_offset
)
10604 warn (_("Corrupt header in the %s section.\n"), section
->name
);
10608 cu_list_elements
= (tu_list_offset
- cu_list_offset
) / 16;
10609 tu_list_elements
= (address_table_offset
- tu_list_offset
) / 24;
10610 address_table_elements
= (symbol_table_offset
- address_table_offset
) / 20;
10611 symbol_table_slots
= (constant_pool_offset
- symbol_table_offset
) / 8;
10613 cu_list
= start
+ cu_list_offset
;
10614 tu_list
= start
+ tu_list_offset
;
10615 address_table
= start
+ address_table_offset
;
10616 symbol_table
= start
+ symbol_table_offset
;
10617 constant_pool
= start
+ constant_pool_offset
;
10619 printf (_("\nCU table:\n"));
10620 for (i
= 0; i
< cu_list_elements
; i
++)
10622 uint64_t cu_offset
= byte_get_little_endian (cu_list
+ i
* 16, 8);
10623 uint64_t cu_length
= byte_get_little_endian (cu_list
+ i
* 16 + 8, 8);
10625 printf ("[%3u] %#" PRIx64
" - %#" PRIx64
"\n",
10626 i
, cu_offset
, cu_offset
+ cu_length
- 1);
10629 printf (_("\nTU table:\n"));
10630 for (i
= 0; i
< tu_list_elements
; i
++)
10632 uint64_t tu_offset
= byte_get_little_endian (tu_list
+ i
* 24, 8);
10633 uint64_t type_offset
= byte_get_little_endian (tu_list
+ i
* 24 + 8, 8);
10634 uint64_t signature
= byte_get_little_endian (tu_list
+ i
* 24 + 16, 8);
10636 printf ("[%3u] %#" PRIx64
" %#" PRIx64
" ",
10637 i
, tu_offset
, type_offset
);
10638 print_hex_ns (signature
, 8);
10642 printf (_("\nAddress table:\n"));
10643 for (i
= 0; i
< address_table_elements
; i
++)
10645 uint64_t low
= byte_get_little_endian (address_table
+ i
* 20, 8);
10646 uint64_t high
= byte_get_little_endian (address_table
+ i
* 20 + 8, 8);
10647 uint32_t cu_index
= byte_get_little_endian (address_table
+ i
* 20 + 16, 4);
10649 print_hex (low
, 8);
10650 print_hex (high
, 8);
10651 printf ("%" PRIu32
"\n", cu_index
);
10654 printf (_("\nSymbol table:\n"));
10655 for (i
= 0; i
< symbol_table_slots
; ++i
)
10657 uint32_t name_offset
= byte_get_little_endian (symbol_table
+ i
* 8, 4);
10658 uint32_t cu_vector_offset
= byte_get_little_endian (symbol_table
+ i
* 8 + 4, 4);
10659 uint32_t num_cus
, cu
;
10661 if (name_offset
!= 0
10662 || cu_vector_offset
!= 0)
10666 /* PR 17531: file: 5b7b07ad. */
10667 if (name_offset
>= section
->size
- constant_pool_offset
)
10669 printf (_("[%3u] <corrupt offset: %x>"), i
, name_offset
);
10670 warn (_("Corrupt name offset of 0x%x found for symbol table slot %d\n"),
10674 printf ("[%3u] %.*s:", i
,
10675 (int) (section
->size
- (constant_pool_offset
+ name_offset
)),
10676 constant_pool
+ name_offset
);
10678 if (section
->size
- constant_pool_offset
< 4
10679 || cu_vector_offset
> section
->size
- constant_pool_offset
- 4)
10681 printf (_("<invalid CU vector offset: %x>\n"), cu_vector_offset
);
10682 warn (_("Corrupt CU vector offset of 0x%x found for symbol table slot %d\n"),
10683 cu_vector_offset
, i
);
10687 num_cus
= byte_get_little_endian (constant_pool
+ cu_vector_offset
, 4);
10689 if ((uint64_t) num_cus
* 4 > section
->size
- (constant_pool_offset
10690 + cu_vector_offset
+ 4))
10692 printf ("<invalid number of CUs: %d>\n", num_cus
);
10693 warn (_("Invalid number of CUs (0x%x) for symbol table slot %d\n"),
10701 for (j
= 0; j
< num_cus
; ++j
)
10704 gdb_index_symbol_kind kind
;
10706 cu
= byte_get_little_endian (constant_pool
+ cu_vector_offset
+ 4 + j
* 4, 4);
10707 is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu
);
10708 kind
= GDB_INDEX_SYMBOL_KIND_VALUE (cu
);
10709 cu
= GDB_INDEX_CU_VALUE (cu
);
10710 /* Convert to TU number if it's for a type unit. */
10711 if (cu
>= cu_list_elements
)
10712 printf ("%cT%lu", num_cus
> 1 ? '\t' : ' ',
10713 (unsigned long) cu
- cu_list_elements
);
10715 printf ("%c%lu", num_cus
> 1 ? '\t' : ' ', (unsigned long) cu
);
10717 printf (" [%s, %s]",
10718 is_static
? _("static") : _("global"),
10719 get_gdb_index_symbol_kind_name (kind
));
10731 /* Pre-allocate enough space for the CU/TU sets needed. */
10734 prealloc_cu_tu_list (unsigned int nshndx
)
10736 if (shndx_pool
== NULL
)
10738 shndx_pool_size
= nshndx
;
10739 shndx_pool_used
= 0;
10740 shndx_pool
= (unsigned int *) xcmalloc (shndx_pool_size
,
10741 sizeof (unsigned int));
10745 shndx_pool_size
= shndx_pool_used
+ nshndx
;
10746 shndx_pool
= (unsigned int *) xcrealloc (shndx_pool
, shndx_pool_size
,
10747 sizeof (unsigned int));
10752 add_shndx_to_cu_tu_entry (unsigned int shndx
)
10754 shndx_pool
[shndx_pool_used
++] = shndx
;
10758 end_cu_tu_entry (void)
10760 shndx_pool
[shndx_pool_used
++] = 0;
10763 /* Return the short name of a DWARF section given by a DW_SECT enumerator. */
10765 static const char *
10766 get_DW_SECT_short_name (unsigned int dw_sect
)
10768 static char buf
[16];
10774 case DW_SECT_TYPES
:
10776 case DW_SECT_ABBREV
:
10782 case DW_SECT_STR_OFFSETS
:
10784 case DW_SECT_MACINFO
:
10786 case DW_SECT_MACRO
:
10792 snprintf (buf
, sizeof (buf
), "%d", dw_sect
);
10796 /* Process a CU or TU index. If DO_DISPLAY is true, print the contents.
10797 These sections are extensions for Fission.
10798 See http://gcc.gnu.org/wiki/DebugFissionDWP. */
10801 process_cu_tu_index (struct dwarf_section
*section
, int do_display
)
10803 unsigned char *phdr
= section
->start
;
10804 unsigned char *limit
= phdr
+ section
->size
;
10805 unsigned char *phash
;
10806 unsigned char *pindex
;
10807 unsigned char *ppool
;
10808 unsigned int version
;
10809 unsigned int ncols
= 0;
10810 unsigned int nused
;
10811 unsigned int nslots
;
10814 uint64_t signature
;
10817 /* PR 17512: file: 002-168123-0.004. */
10820 warn (_("Section %s is empty\n"), section
->name
);
10823 /* PR 17512: file: 002-376-0.004. */
10824 if (section
->size
< 24)
10826 warn (_("Section %s is too small to contain a CU/TU header\n"),
10832 SAFE_BYTE_GET_AND_INC (version
, phash
, 4, limit
);
10834 SAFE_BYTE_GET_AND_INC (ncols
, phash
, 4, limit
);
10835 SAFE_BYTE_GET_AND_INC (nused
, phash
, 4, limit
);
10836 SAFE_BYTE_GET_AND_INC (nslots
, phash
, 4, limit
);
10838 pindex
= phash
+ (size_t) nslots
* 8;
10839 ppool
= pindex
+ (size_t) nslots
* 4;
10843 introduce (section
, false);
10845 printf (_(" Version: %u\n"), version
);
10847 printf (_(" Number of columns: %u\n"), ncols
);
10848 printf (_(" Number of used entries: %u\n"), nused
);
10849 printf (_(" Number of slots: %u\n\n"), nslots
);
10852 /* PR 17531: file: 45d69832. */
10853 if (_mul_overflow ((size_t) nslots
, 12, &total
)
10854 || total
> (size_t) (limit
- phash
))
10856 warn (ngettext ("Section %s is too small for %u slot\n",
10857 "Section %s is too small for %u slots\n",
10859 section
->name
, nslots
);
10865 unsigned char *shndx_list
;
10866 unsigned int shndx
;
10870 prealloc_cu_tu_list ((limit
- ppool
) / 4);
10871 for (shndx_list
= ppool
+ 4; shndx_list
<= limit
- 4; shndx_list
+= 4)
10873 shndx
= byte_get (shndx_list
, 4);
10874 add_shndx_to_cu_tu_entry (shndx
);
10876 end_cu_tu_entry ();
10879 for (i
= 0; i
< nslots
; i
++)
10881 SAFE_BYTE_GET (signature
, phash
, 8, limit
);
10882 if (signature
!= 0)
10884 SAFE_BYTE_GET (j
, pindex
, 4, limit
);
10885 shndx_list
= ppool
+ j
* 4;
10886 /* PR 17531: file: 705e010d. */
10887 if (shndx_list
< ppool
)
10889 warn (_("Section index pool located before start of section\n"));
10893 printf (_(" [%3d] Signature: %#" PRIx64
" Sections: "),
10897 if (shndx_list
>= limit
)
10899 warn (_("Section %s too small for shndx pool\n"),
10903 SAFE_BYTE_GET (shndx
, shndx_list
, 4, limit
);
10906 printf (" %d", shndx
);
10915 else if (version
== 2)
10918 unsigned int dw_sect
;
10919 unsigned char *ph
= phash
;
10920 unsigned char *pi
= pindex
;
10921 unsigned char *poffsets
= ppool
+ (size_t) ncols
* 4;
10922 unsigned char *psizes
= poffsets
+ (size_t) nused
* ncols
* 4;
10924 struct cu_tu_set
*this_set
= NULL
;
10926 unsigned char *prow
;
10929 is_tu_index
= strcmp (section
->name
, ".debug_tu_index") == 0;
10931 /* PR 17531: file: 0dd159bf.
10932 Check for integer overflow (can occur when size_t is 32-bit)
10933 with overlarge ncols or nused values. */
10935 || _mul_overflow ((size_t) ncols
, 4, &temp
)
10936 || _mul_overflow ((size_t) nused
+ 1, temp
, &total
)
10937 || total
> (size_t) (limit
- ppool
)
10938 /* PR 30227: ncols could be 0. */
10939 || _mul_overflow ((size_t) nused
+ 1, 4, &total
)
10940 || total
> (size_t) (limit
- ppool
))
10942 warn (_("Section %s too small for offset and size tables\n"),
10949 printf (_(" Offset table\n"));
10950 printf (" slot %-16s ",
10951 is_tu_index
? _("signature") : _("dwo_id"));
10958 tu_sets
= xcalloc2 (nused
, sizeof (struct cu_tu_set
));
10959 this_set
= tu_sets
;
10964 cu_sets
= xcalloc2 (nused
, sizeof (struct cu_tu_set
));
10965 this_set
= cu_sets
;
10971 for (j
= 0; j
< ncols
; j
++)
10973 unsigned char *p
= ppool
+ j
* 4;
10974 SAFE_BYTE_GET (dw_sect
, p
, 4, limit
);
10975 printf (" %8s", get_DW_SECT_short_name (dw_sect
));
10980 for (i
= 0; i
< nslots
; i
++)
10982 SAFE_BYTE_GET (signature
, ph
, 8, limit
);
10984 SAFE_BYTE_GET (row
, pi
, 4, limit
);
10987 /* PR 17531: file: a05f6ab3. */
10990 warn (_("Row index (%u) is larger than number of used entries (%u)\n"),
10997 size_t num_copy
= sizeof (uint64_t);
10999 memcpy (&this_set
[row
- 1].signature
, ph
, num_copy
);
11002 prow
= poffsets
+ (row
- 1) * ncols
* 4;
11004 printf (" [%3d] %#" PRIx64
, i
, signature
);
11005 for (j
= 0; j
< ncols
; j
++)
11007 unsigned char *p
= prow
+ j
* 4;
11008 SAFE_BYTE_GET (val
, p
, 4, limit
);
11010 printf (" %8d", val
);
11014 SAFE_BYTE_GET (dw_sect
, p
, 4, limit
);
11016 /* PR 17531: file: 10796eb3. */
11017 if (dw_sect
>= DW_SECT_MAX
)
11018 warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect
);
11020 this_set
[row
- 1].section_offsets
[dw_sect
] = val
;
11036 printf (_(" Size table\n"));
11037 printf (" slot %-16s ",
11038 is_tu_index
? _("signature") : _("dwo_id"));
11041 for (j
= 0; j
< ncols
; j
++)
11043 unsigned char *p
= ppool
+ j
* 4;
11044 SAFE_BYTE_GET (val
, p
, 4, limit
);
11046 printf (" %8s", get_DW_SECT_short_name (val
));
11052 for (i
= 0; i
< nslots
; i
++)
11054 SAFE_BYTE_GET (signature
, ph
, 8, limit
);
11056 SAFE_BYTE_GET (row
, pi
, 4, limit
);
11059 prow
= psizes
+ (row
- 1) * ncols
* 4;
11062 printf (" [%3d] %#" PRIx64
, i
, signature
);
11064 for (j
= 0; j
< ncols
; j
++)
11066 unsigned char *p
= prow
+ j
* 4;
11068 /* PR 28645: Check for overflow. Since we do not know how
11069 many populated rows there will be, we cannot just
11070 perform a single check at the start of this function. */
11071 if (p
> (limit
- 4))
11075 warn (_("Too many rows/columns in DWARF index section %s\n"),
11080 SAFE_BYTE_GET (val
, p
, 4, limit
);
11083 printf (" %8d", val
);
11087 SAFE_BYTE_GET (dw_sect
, p
, 4, limit
);
11088 if (dw_sect
>= DW_SECT_MAX
)
11089 warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect
);
11091 this_set
[row
- 1].section_sizes
[dw_sect
] = val
;
11103 else if (do_display
)
11104 printf (_(" Unsupported version (%d)\n"), version
);
11112 static int cu_tu_indexes_read
= -1; /* Tri-state variable. */
11114 /* Load the CU and TU indexes if present. This will build a list of
11115 section sets that we can use to associate a .debug_info.dwo section
11116 with its associated .debug_abbrev.dwo section in a .dwp file. */
11119 load_cu_tu_indexes (void *file
)
11121 /* If we have already loaded (or tried to load) the CU and TU indexes
11122 then do not bother to repeat the task. */
11123 if (cu_tu_indexes_read
== -1)
11125 cu_tu_indexes_read
= true;
11127 if (load_debug_section_with_follow (dwp_cu_index
, file
))
11128 if (! process_cu_tu_index (&debug_displays
[dwp_cu_index
].section
, 0))
11129 cu_tu_indexes_read
= false;
11131 if (load_debug_section_with_follow (dwp_tu_index
, file
))
11132 if (! process_cu_tu_index (&debug_displays
[dwp_tu_index
].section
, 0))
11133 cu_tu_indexes_read
= false;
11136 return (bool) cu_tu_indexes_read
;
11139 /* Find the set of sections that includes section SHNDX. */
11142 find_cu_tu_set (void *file
, unsigned int shndx
)
11146 if (! load_cu_tu_indexes (file
))
11149 /* Find SHNDX in the shndx pool. */
11150 for (i
= 0; i
< shndx_pool_used
; i
++)
11151 if (shndx_pool
[i
] == shndx
)
11154 if (i
>= shndx_pool_used
)
11157 /* Now backup to find the first entry in the set. */
11158 while (i
> 0 && shndx_pool
[i
- 1] != 0)
11161 return shndx_pool
+ i
;
11164 /* Display a .debug_cu_index or .debug_tu_index section. */
11167 display_cu_index (struct dwarf_section
*section
, void *file ATTRIBUTE_UNUSED
)
11169 return process_cu_tu_index (section
, 1);
11173 display_debug_not_supported (struct dwarf_section
*section
,
11174 void *file ATTRIBUTE_UNUSED
)
11176 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
11182 /* Like malloc, but takes two parameters like calloc.
11183 Verifies that the first parameter is not too large.
11184 Note: does *not* initialise the allocated memory to zero. */
11187 cmalloc (uint64_t nmemb
, size_t size
)
11189 /* Check for overflow. */
11190 if (nmemb
>= ~(size_t) 0 / size
)
11193 return xmalloc (nmemb
* size
);
11196 /* Like xmalloc, but takes two parameters like calloc.
11197 Verifies that the first parameter is not too large.
11198 Note: does *not* initialise the allocated memory to zero. */
11201 xcmalloc (uint64_t nmemb
, size_t size
)
11203 /* Check for overflow. */
11204 if (nmemb
>= ~(size_t) 0 / size
)
11207 _("Attempt to allocate an array with an excessive number of elements: %#" PRIx64
"\n"),
11212 return xmalloc (nmemb
* size
);
11215 /* Like xrealloc, but takes three parameters.
11216 Verifies that the second parameter is not too large.
11217 Note: does *not* initialise any new memory to zero. */
11220 xcrealloc (void *ptr
, uint64_t nmemb
, size_t size
)
11222 /* Check for overflow. */
11223 if (nmemb
>= ~(size_t) 0 / size
)
11225 error (_("Attempt to re-allocate an array with an excessive number of elements: %#" PRIx64
"\n"),
11230 return xrealloc (ptr
, nmemb
* size
);
11233 /* Like xcalloc, but verifies that the first parameter is not too large. */
11236 xcalloc2 (uint64_t nmemb
, size_t size
)
11238 /* Check for overflow. */
11239 if (nmemb
>= ~(size_t) 0 / size
)
11241 error (_("Attempt to allocate a zero'ed array with an excessive number of elements: %#" PRIx64
"\n"),
11246 return xcalloc (nmemb
, size
);
11249 static unsigned long
11250 calc_gnu_debuglink_crc32 (unsigned long crc
,
11251 const unsigned char *buf
,
11254 static const unsigned long crc32_table
[256] =
11256 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
11257 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
11258 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
11259 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
11260 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
11261 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
11262 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
11263 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
11264 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
11265 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
11266 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
11267 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
11268 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
11269 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
11270 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
11271 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
11272 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
11273 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
11274 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
11275 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
11276 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
11277 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
11278 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
11279 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
11280 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
11281 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
11282 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
11283 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
11284 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
11285 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
11286 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
11287 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
11288 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
11289 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
11290 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
11291 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
11292 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
11293 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
11294 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
11295 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
11296 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
11297 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
11298 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
11299 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
11300 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
11301 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
11302 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
11303 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
11304 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
11305 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
11306 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
11309 const unsigned char *end
;
11311 crc
= ~crc
& 0xffffffff;
11312 for (end
= buf
+ len
; buf
< end
; ++ buf
)
11313 crc
= crc32_table
[(crc
^ *buf
) & 0xff] ^ (crc
>> 8);
11314 return ~crc
& 0xffffffff;
11317 typedef bool (*check_func_type
) (const char *, void *);
11318 typedef const char *(* parse_func_type
) (struct dwarf_section
*, void *);
11321 check_gnu_debuglink (const char * pathname
, void * crc_pointer
)
11323 static unsigned char buffer
[8 * 1024];
11326 unsigned long crc
= 0;
11329 sep_data
= open_debug_file (pathname
);
11330 if (sep_data
== NULL
)
11333 /* Yes - we are opening the file twice... */
11334 f
= fopen (pathname
, "rb");
11337 /* Paranoia: This should never happen. */
11338 close_debug_file (sep_data
);
11339 warn (_("Unable to reopen separate debug info file: %s\n"), pathname
);
11343 while ((count
= fread (buffer
, 1, sizeof (buffer
), f
)) > 0)
11344 crc
= calc_gnu_debuglink_crc32 (crc
, buffer
, count
);
11348 if (crc
!= * (unsigned long *) crc_pointer
)
11350 close_debug_file (sep_data
);
11351 warn (_("Separate debug info file %s found, but CRC does not match - ignoring\n"),
11359 static const char *
11360 parse_gnu_debuglink (struct dwarf_section
* section
, void * data
)
11363 unsigned int crc_offset
;
11364 unsigned long * crc32
= (unsigned long *) data
;
11366 /* The name is first.
11367 The CRC value is stored after the filename, aligned up to 4 bytes. */
11368 name
= (const char *) section
->start
;
11370 crc_offset
= strnlen (name
, section
->size
) + 1;
11371 if (crc_offset
== 1)
11373 crc_offset
= (crc_offset
+ 3) & ~3;
11374 if (crc_offset
+ 4 > section
->size
)
11377 * crc32
= byte_get (section
->start
+ crc_offset
, 4);
11382 check_gnu_debugaltlink (const char * filename
, void * data ATTRIBUTE_UNUSED
)
11384 void * sep_data
= open_debug_file (filename
);
11386 if (sep_data
== NULL
)
11389 /* FIXME: We should now extract the build-id in the separate file
11395 typedef struct build_id_data
11398 const unsigned char *data
;
11401 static const char *
11402 parse_gnu_debugaltlink (struct dwarf_section
* section
, void * data
)
11407 Build_id_data
*build_id_data
;
11409 /* The name is first.
11410 The build-id follows immediately, with no padding, up to the section's end. */
11412 name
= (const char *) section
->start
;
11413 namelen
= strnlen (name
, section
->size
) + 1;
11416 if (namelen
>= section
->size
)
11419 id_len
= section
->size
- namelen
;
11423 build_id_data
= (Build_id_data
*) data
;
11424 build_id_data
->len
= id_len
;
11425 build_id_data
->data
= section
->start
+ namelen
;
11431 add_separate_debug_file (const char * filename
, void * handle
)
11433 separate_info
* i
= xmalloc (sizeof * i
);
11435 i
->filename
= filename
;
11436 i
->handle
= handle
;
11437 i
->next
= first_separate_info
;
11438 first_separate_info
= i
;
11441 #if HAVE_LIBDEBUGINFOD
11442 /* Query debuginfod servers for the target debuglink or debugaltlink
11443 file. If successful, store the path of the file in filename and
11444 return TRUE, otherwise return FALSE. */
11447 debuginfod_fetch_separate_debug_info (struct dwarf_section
* section
,
11451 size_t build_id_len
;
11452 unsigned char * build_id
;
11454 if (strcmp (section
->uncompressed_name
, ".gnu_debuglink") == 0)
11456 /* Get the build-id of file. */
11457 build_id
= get_build_id (file
);
11460 else if (strcmp (section
->uncompressed_name
, ".gnu_debugaltlink") == 0)
11462 /* Get the build-id of the debugaltlink file. */
11463 unsigned int filelen
;
11465 filelen
= strnlen ((const char *)section
->start
, section
->size
);
11466 if (filelen
== section
->size
)
11467 /* Corrupt debugaltlink. */
11470 build_id
= section
->start
+ filelen
+ 1;
11471 build_id_len
= section
->size
- (filelen
+ 1);
11473 if (build_id_len
== 0)
11482 debuginfod_client
* client
;
11484 client
= debuginfod_begin ();
11485 if (client
== NULL
)
11488 /* Query debuginfod servers for the target file. If found its path
11489 will be stored in filename. */
11490 fd
= debuginfod_find_debuginfo (client
, build_id
, build_id_len
, filename
);
11491 debuginfod_end (client
);
11493 /* Only free build_id if we allocated space for a hex string
11494 in get_build_id (). */
11495 if (build_id_len
== 0)
11500 /* File successfully retrieved. Close fd since we want to
11501 use open_debug_file () on filename instead. */
11509 #endif /* HAVE_LIBDEBUGINFOD */
11512 load_separate_debug_info (const char * main_filename
,
11513 struct dwarf_section
* xlink
,
11514 parse_func_type parse_func
,
11515 check_func_type check_func
,
11517 void * file ATTRIBUTE_UNUSED
)
11519 const char * separate_filename
;
11520 char * debug_filename
;
11522 size_t canon_dirlen
;
11524 char * canon_filename
;
11525 char * canon_debug_filename
;
11528 if ((separate_filename
= parse_func (xlink
, func_data
)) == NULL
)
11530 warn (_("Corrupt debuglink section: %s\n"),
11531 xlink
->name
? xlink
->name
: xlink
->uncompressed_name
);
11535 /* Attempt to locate the separate file.
11536 This should duplicate the logic in bfd/opncls.c:find_separate_debug_file(). */
11538 canon_filename
= lrealpath (main_filename
);
11539 canon_dir
= xstrdup (canon_filename
);
11541 for (canon_dirlen
= strlen (canon_dir
); canon_dirlen
> 0; canon_dirlen
--)
11542 if (IS_DIR_SEPARATOR (canon_dir
[canon_dirlen
- 1]))
11544 canon_dir
[canon_dirlen
] = '\0';
11547 #define DEBUGDIR "/lib/debug"
11549 #ifndef EXTRA_DEBUG_ROOT1
11550 #define EXTRA_DEBUG_ROOT1 "/usr/lib/debug"
11552 #ifndef EXTRA_DEBUG_ROOT2
11553 #define EXTRA_DEBUG_ROOT2 "/usr/lib/debug/usr"
11556 debug_filename
= (char *) malloc (strlen (DEBUGDIR
) + 1
11558 + strlen (".debug/")
11559 #ifdef EXTRA_DEBUG_ROOT1
11560 + strlen (EXTRA_DEBUG_ROOT1
)
11562 #ifdef EXTRA_DEBUG_ROOT2
11563 + strlen (EXTRA_DEBUG_ROOT2
)
11565 + strlen (separate_filename
)
11567 if (debug_filename
== NULL
)
11569 warn (_("Out of memory"));
11571 free (canon_filename
);
11575 /* First try in the current directory. */
11576 sprintf (debug_filename
, "%s", separate_filename
);
11577 if (check_func (debug_filename
, func_data
))
11580 /* Then try in a subdirectory called .debug. */
11581 sprintf (debug_filename
, ".debug/%s", separate_filename
);
11582 if (check_func (debug_filename
, func_data
))
11585 /* Then try in the same directory as the original file. */
11586 sprintf (debug_filename
, "%s%s", canon_dir
, separate_filename
);
11587 if (check_func (debug_filename
, func_data
))
11590 /* And the .debug subdirectory of that directory. */
11591 sprintf (debug_filename
, "%s.debug/%s", canon_dir
, separate_filename
);
11592 if (check_func (debug_filename
, func_data
))
11595 #ifdef EXTRA_DEBUG_ROOT1
11596 /* Try the first extra debug file root. */
11597 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT1
, separate_filename
);
11598 if (check_func (debug_filename
, func_data
))
11601 /* Try the first extra debug file root. */
11602 sprintf (debug_filename
, "%s/%s/%s", EXTRA_DEBUG_ROOT1
, canon_dir
, separate_filename
);
11603 if (check_func (debug_filename
, func_data
))
11607 #ifdef EXTRA_DEBUG_ROOT2
11608 /* Try the second extra debug file root. */
11609 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT2
, separate_filename
);
11610 if (check_func (debug_filename
, func_data
))
11614 /* Then try in the global debug_filename directory. */
11615 strcpy (debug_filename
, DEBUGDIR
);
11616 dirlen
= strlen (DEBUGDIR
) - 1;
11617 if (dirlen
> 0 && DEBUGDIR
[dirlen
] != '/')
11618 strcat (debug_filename
, "/");
11619 strcat (debug_filename
, (const char *) separate_filename
);
11621 if (check_func (debug_filename
, func_data
))
11624 #if HAVE_LIBDEBUGINFOD
11626 char * tmp_filename
;
11629 && debuginfod_fetch_separate_debug_info (xlink
,
11633 /* File successfully downloaded from server, replace
11634 debug_filename with the file's path. */
11635 free (debug_filename
);
11636 debug_filename
= tmp_filename
;
11642 if (do_debug_links
)
11644 /* Failed to find the file. */
11645 warn (_("could not find separate debug file '%s'\n"),
11646 separate_filename
);
11647 warn (_("tried: %s\n"), debug_filename
);
11649 #ifdef EXTRA_DEBUG_ROOT2
11650 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT2
,
11651 separate_filename
);
11652 warn (_("tried: %s\n"), debug_filename
);
11655 #ifdef EXTRA_DEBUG_ROOT1
11656 sprintf (debug_filename
, "%s/%s/%s", EXTRA_DEBUG_ROOT1
,
11657 canon_dir
, separate_filename
);
11658 warn (_("tried: %s\n"), debug_filename
);
11660 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT1
,
11661 separate_filename
);
11662 warn (_("tried: %s\n"), debug_filename
);
11665 sprintf (debug_filename
, "%s.debug/%s", canon_dir
,
11666 separate_filename
);
11667 warn (_("tried: %s\n"), debug_filename
);
11669 sprintf (debug_filename
, "%s%s", canon_dir
, separate_filename
);
11670 warn (_("tried: %s\n"), debug_filename
);
11672 sprintf (debug_filename
, ".debug/%s", separate_filename
);
11673 warn (_("tried: %s\n"), debug_filename
);
11675 sprintf (debug_filename
, "%s", separate_filename
);
11676 warn (_("tried: %s\n"), debug_filename
);
11678 #if HAVE_LIBDEBUGINFOD
11679 if (use_debuginfod
)
11681 char *urls
= getenv (DEBUGINFOD_URLS_ENV_VAR
);
11686 warn (_("tried: DEBUGINFOD_URLS=%s\n"), urls
);
11692 free (debug_filename
);
11693 free (canon_filename
);
11699 canon_debug_filename
= lrealpath (debug_filename
);
11700 self
= strcmp (canon_debug_filename
, canon_filename
) == 0;
11701 free (canon_filename
);
11702 free (canon_debug_filename
);
11705 free (debug_filename
);
11709 void * debug_handle
;
11711 /* Now open the file.... */
11712 if ((debug_handle
= open_debug_file (debug_filename
)) == NULL
)
11714 warn (_("failed to open separate debug file: %s\n"), debug_filename
);
11715 free (debug_filename
);
11719 /* FIXME: We do not check to see if there are any other separate debug info
11720 files that would also match. */
11722 if (do_debug_links
)
11723 printf (_("\n%s: Found separate debug info file: %s\n"), main_filename
, debug_filename
);
11724 add_separate_debug_file (debug_filename
, debug_handle
);
11726 /* Do not free debug_filename - it might be referenced inside
11727 the structure returned by open_debug_file(). */
11728 return debug_handle
;
11731 /* Attempt to load a separate dwarf object file. */
11734 load_dwo_file (const char * main_filename
, const char * name
, const char * dir
, const char * id ATTRIBUTE_UNUSED
)
11736 char * separate_filename
;
11737 void * separate_handle
;
11739 if (IS_ABSOLUTE_PATH (name
))
11740 separate_filename
= strdup (name
);
11742 /* FIXME: Skip adding / if dwo_dir ends in /. */
11743 separate_filename
= concat (dir
, "/", name
, NULL
);
11744 if (separate_filename
== NULL
)
11746 warn (_("Out of memory allocating dwo filename\n"));
11750 if ((separate_handle
= open_debug_file (separate_filename
)) == NULL
)
11752 warn (_("Unable to load dwo file: %s\n"), separate_filename
);
11753 free (separate_filename
);
11757 /* FIXME: We should check the dwo_id. */
11759 printf (_("%s: Found separate debug object file: %s\n\n"), main_filename
, separate_filename
);
11761 add_separate_debug_file (separate_filename
, separate_handle
);
11762 /* Note - separate_filename will be freed in free_debug_memory(). */
11763 return separate_handle
;
11767 try_build_id_prefix (const char * prefix
, char * filename
, const unsigned char * data
, unsigned long id_len
)
11769 char * f
= filename
;
11771 f
+= sprintf (f
, "%s.build-id/%02x/", prefix
, (unsigned) *data
++);
11774 f
+= sprintf (f
, "%02x", (unsigned) *data
++);
11775 strcpy (f
, ".debug");
11777 return open_debug_file (filename
);
11780 /* Try to load a debug file based upon the build-id held in the .note.gnu.build-id section. */
11783 load_build_id_debug_file (const char * main_filename ATTRIBUTE_UNUSED
, void * main_file
)
11785 if (! load_debug_section (note_gnu_build_id
, main_file
))
11786 return; /* No .note.gnu.build-id section. */
11788 struct dwarf_section
* section
= & debug_displays
[note_gnu_build_id
].section
;
11789 if (section
== NULL
)
11791 warn (_("Unable to load the .note.gnu.build-id section\n"));
11795 if (section
->start
== NULL
|| section
->size
< 0x18)
11797 warn (_(".note.gnu.build-id section is corrupt/empty\n"));
11801 /* In theory we should extract the contents of the section into
11802 a note structure and then check the fields. For now though
11803 just use hard coded offsets instead:
11805 Field Bytes Contents
11808 Type 8..11 3 (NT_GNU_BUILD_ID)
11812 /* FIXME: Check the name size, name and type fields. */
11814 unsigned long build_id_size
;
11815 build_id_size
= byte_get (section
->start
+ 4, 4);
11816 if (build_id_size
< 8)
11818 warn (_(".note.gnu.build-id data size is too small\n"));
11822 if (build_id_size
> (section
->size
- 16))
11824 warn (_(".note.gnu.build-id data size is too big\n"));
11829 filename
= xmalloc (strlen (".build-id/")
11830 + build_id_size
* 2 + 2
11831 + strlen (".debug")
11832 /* The next string should be the same as the longest
11833 name found in the prefixes[] array below. */
11834 + strlen ("/usrlib64/debug/usr")
11838 static const char * prefixes
[] =
11843 "/usr/lib/debug/usr/",
11844 "/usr/lib64/debug/",
11845 "/usr/lib64/debug/usr"
11847 long unsigned int i
;
11849 for (i
= 0; i
< ARRAY_SIZE (prefixes
); i
++)
11851 handle
= try_build_id_prefix (prefixes
[i
], filename
,
11852 section
->start
+ 16, build_id_size
);
11853 if (handle
!= NULL
)
11856 /* FIXME: TYhe BFD library also tries a global debugfile directory prefix. */
11857 if (handle
== NULL
)
11859 /* Failed to find a debug file associated with the build-id.
11860 This is not an error however, rather it just means that
11861 the debug info has probably not been loaded on the system,
11862 or that another method is being used to link to the debug
11868 add_separate_debug_file (filename
, handle
);
11871 /* Try to load a debug file pointed to by the .debug_sup section. */
11874 load_debug_sup_file (const char * main_filename
, void * file
)
11876 if (! load_debug_section (debug_sup
, file
))
11877 return; /* No .debug_sup section. */
11879 struct dwarf_section
* section
;
11880 section
= & debug_displays
[debug_sup
].section
;
11881 assert (section
!= NULL
);
11883 if (section
->start
== NULL
|| section
->size
< 5)
11885 warn (_(".debug_sup section is corrupt/empty\n"));
11889 if (section
->start
[2] != 0)
11890 return; /* This is a supplementary file. */
11892 const char * filename
= (const char *) section
->start
+ 3;
11893 if (strnlen (filename
, section
->size
- 3) == section
->size
- 3)
11895 warn (_("filename in .debug_sup section is corrupt\n"));
11899 if (filename
[0] != '/' && strchr (main_filename
, '/'))
11904 new_len
= asprintf (& new_name
, "%.*s/%s",
11905 (int) (strrchr (main_filename
, '/') - main_filename
),
11910 warn (_("unable to construct path for supplementary debug file"));
11915 filename
= new_name
;
11919 /* PR 27796: Make sure that we pass a filename that can be free'd to
11920 add_separate_debug_file(). */
11921 filename
= strdup (filename
);
11922 if (filename
== NULL
)
11924 warn (_("out of memory constructing filename for .debug_sup link\n"));
11929 void * handle
= open_debug_file (filename
);
11930 if (handle
== NULL
)
11932 warn (_("unable to open file '%s' referenced from .debug_sup section\n"), filename
);
11933 free ((void *) filename
);
11937 printf (_("%s: Found supplementary debug file: %s\n\n"), main_filename
, filename
);
11939 /* FIXME: Compare the checksums, if present. */
11940 add_separate_debug_file (filename
, handle
);
11943 /* Load a debuglink section and/or a debugaltlink section, if either are present.
11944 Recursively check the loaded files for more of these sections.
11945 Also follow any links in .debug_sup sections.
11946 FIXME: Should also check for DWO_* entries in the newly loaded files. */
11949 check_for_and_load_links (void * file
, const char * filename
)
11951 void * handle
= NULL
;
11953 if (load_debug_section (gnu_debugaltlink
, file
))
11955 Build_id_data build_id_data
;
11957 handle
= load_separate_debug_info (filename
,
11958 & debug_displays
[gnu_debugaltlink
].section
,
11959 parse_gnu_debugaltlink
,
11960 check_gnu_debugaltlink
,
11965 assert (handle
== first_separate_info
->handle
);
11966 check_for_and_load_links (first_separate_info
->handle
,
11967 first_separate_info
->filename
);
11971 if (load_debug_section (gnu_debuglink
, file
))
11973 unsigned long crc32
;
11975 handle
= load_separate_debug_info (filename
,
11976 & debug_displays
[gnu_debuglink
].section
,
11977 parse_gnu_debuglink
,
11978 check_gnu_debuglink
,
11983 assert (handle
== first_separate_info
->handle
);
11984 check_for_and_load_links (first_separate_info
->handle
,
11985 first_separate_info
->filename
);
11989 load_debug_sup_file (filename
, file
);
11991 load_build_id_debug_file (filename
, file
);
11994 /* Load the separate debug info file(s) attached to FILE, if any exist.
11995 Returns TRUE if any were found, FALSE otherwise.
11996 If TRUE is returned then the linked list starting at first_separate_info
11997 will be populated with open file handles. */
12000 load_separate_debug_files (void * file
, const char * filename
)
12002 /* Skip this operation if we are not interested in debug links. */
12003 if (! do_follow_links
&& ! do_debug_links
)
12006 /* See if there are any dwo links. */
12007 if (load_debug_section (str
, file
)
12008 && load_debug_section (abbrev
, file
)
12009 && load_debug_section (info
, file
))
12011 /* Load the .debug_addr section, if it exists. */
12012 load_debug_section (debug_addr
, file
);
12013 /* Load the .debug_str_offsets section, if it exists. */
12014 load_debug_section (str_index
, file
);
12015 /* Load the .debug_loclists section, if it exists. */
12016 load_debug_section (loclists
, file
);
12017 /* Load the .debug_rnglists section, if it exists. */
12018 load_debug_section (rnglists
, file
);
12022 if (process_debug_info (& debug_displays
[info
].section
, file
, abbrev
,
12025 bool introduced
= false;
12027 const char *dir
= NULL
;
12028 const char *id
= NULL
;
12029 const char *name
= NULL
;
12031 for (dwinfo
= first_dwo_info
; dwinfo
!= NULL
; dwinfo
= dwinfo
->next
)
12033 /* Accumulate NAME, DIR and ID fields. */
12034 switch (dwinfo
->type
)
12038 warn (_("Multiple DWO_NAMEs encountered for the same CU\n"));
12039 name
= dwinfo
->value
;
12043 /* There can be multiple DW_AT_comp_dir entries in a CU,
12044 so do not complain. */
12045 dir
= dwinfo
->value
;
12050 warn (_("multiple DWO_IDs encountered for the same CU\n"));
12051 id
= dwinfo
->value
;
12055 error (_("Unexpected DWO INFO type"));
12059 /* If we have reached the end of our list, or we are changing
12060 CUs, then display the information that we have accumulated
12063 && (dwinfo
->next
== NULL
12064 || dwinfo
->next
->cu_offset
!= dwinfo
->cu_offset
))
12066 if (do_debug_links
)
12070 printf (_("The %s section contains link(s) to dwo file(s):\n\n"),
12071 debug_displays
[info
].section
.uncompressed_name
);
12075 printf (_(" Name: %s\n"), name
);
12076 printf (_(" Directory: %s\n"), dir
? dir
: _("<not-found>"));
12078 display_data (printf (_(" ID: ")), (unsigned char *) id
, 8);
12079 else if (debug_information
[0].dwarf_version
!= 5)
12080 printf (_(" ID: <not specified>\n"));
12084 if (do_follow_links
)
12085 load_dwo_file (filename
, name
, dir
, id
);
12087 name
= dir
= id
= NULL
;
12093 if (! do_follow_links
)
12094 /* The other debug links will be displayed by display_debug_links()
12095 so we do not need to do any further processing here. */
12098 /* FIXME: We do not check for the presence of both link sections in the same file. */
12099 /* FIXME: We do not check for the presence of multiple, same-name debuglink sections. */
12100 /* FIXME: We do not check for the presence of a dwo link as well as a debuglink. */
12102 check_for_and_load_links (file
, filename
);
12103 if (first_separate_info
!= NULL
)
12106 do_follow_links
= 0;
12111 free_debug_memory (void)
12115 free_all_abbrevs ();
12119 shndx_pool_size
= 0;
12120 shndx_pool_used
= 0;
12128 memset (level_type_signed
, 0, sizeof level_type_signed
);
12129 cu_tu_indexes_read
= -1;
12131 for (i
= 0; i
< max
; i
++)
12132 free_debug_section ((enum dwarf_section_display_enum
) i
);
12134 if (debug_information
!= NULL
)
12136 for (i
= 0; i
< alloc_num_debug_info_entries
; i
++)
12137 free_debug_information (&debug_information
[i
]);
12138 free (debug_information
);
12139 debug_information
= NULL
;
12140 alloc_num_debug_info_entries
= num_debug_info_entries
= 0;
12144 separate_info
* next
;
12146 for (d
= first_separate_info
; d
!= NULL
; d
= next
)
12148 close_debug_file (d
->handle
);
12149 free ((void *) d
->filename
);
12153 first_separate_info
= NULL
;
12161 const char *option
;
12164 } debug_dump_long_opts
;
12166 static const debug_dump_long_opts debug_option_table
[] =
12168 { 'A', "addr", &do_debug_addr
, 1 },
12169 { 'a', "abbrev", &do_debug_abbrevs
, 1 },
12170 { 'c', "cu_index", &do_debug_cu_index
, 1 },
12171 #ifdef HAVE_LIBDEBUGINFOD
12172 { 'D', "use-debuginfod", &use_debuginfod
, 1 },
12173 { 'E', "do-not-use-debuginfod", &use_debuginfod
, 0 },
12175 { 'F', "frames-interp", &do_debug_frames_interp
, 1 },
12176 { 'f', "frames", &do_debug_frames
, 1 },
12177 { 'g', "gdb_index", &do_gdb_index
, 1 },
12178 { 'i', "info", &do_debug_info
, 1 },
12179 { 'K', "follow-links", &do_follow_links
, 1 },
12180 { 'k', "links", &do_debug_links
, 1 },
12181 { 'L', "decodedline", &do_debug_lines
, FLAG_DEBUG_LINES_DECODED
},
12182 { 'l', "rawline", &do_debug_lines
, FLAG_DEBUG_LINES_RAW
},
12183 /* For compatibility with earlier versions of readelf. */
12184 { 'l', "line", &do_debug_lines
, FLAG_DEBUG_LINES_RAW
},
12185 { 'm', "macro", &do_debug_macinfo
, 1 },
12186 { 'N', "no-follow-links", &do_follow_links
, 0 },
12187 { 'O', "str-offsets", &do_debug_str_offsets
, 1 },
12188 { 'o', "loc", &do_debug_loc
, 1 },
12189 { 'p', "pubnames", &do_debug_pubnames
, 1 },
12190 { 'R', "Ranges", &do_debug_ranges
, 1 },
12191 { 'r', "aranges", &do_debug_aranges
, 1 },
12192 /* For compatibility with earlier versions of readelf. */
12193 { 'r', "ranges", &do_debug_aranges
, 1 },
12194 { 's', "str", &do_debug_str
, 1 },
12195 { 'T', "trace_aranges", &do_trace_aranges
, 1 },
12196 { 't', "pubtypes", &do_debug_pubtypes
, 1 },
12197 { 'U', "trace_info", &do_trace_info
, 1 },
12198 { 'u', "trace_abbrev", &do_trace_abbrevs
, 1 },
12199 { 0, NULL
, NULL
, 0 }
12202 /* Enable display of specific DWARF sections as determined by the comma
12203 separated strings in NAMES. Returns non-zero if any displaying was
12207 dwarf_select_sections_by_names (const char *names
)
12215 const debug_dump_long_opts
*entry
;
12217 for (entry
= debug_option_table
; entry
->option
; entry
++)
12219 size_t len
= strlen (entry
->option
);
12221 if (strncmp (p
, entry
->option
, len
) == 0
12222 && (p
[len
] == ',' || p
[len
] == '\0'))
12224 if (entry
->val
== 0)
12225 * entry
->variable
= 0;
12227 * entry
->variable
= entry
->val
;
12228 result
|= entry
->val
;
12235 if (entry
->option
== NULL
)
12237 warn (_("Unrecognized debug option '%s'\n"), p
);
12238 p
= strchr (p
, ',');
12247 /* The --debug-dump=frames-interp option also enables the
12248 --debug-dump=frames option. */
12249 if (do_debug_frames_interp
)
12250 do_debug_frames
= 1;
12255 /* Enable display of specific DWARF sections as determined by the characters
12256 in LETTERS. Returns non-zero if any displaying was enabled. */
12259 dwarf_select_sections_by_letters (const char *letters
)
12265 const debug_dump_long_opts
*entry
;
12267 for (entry
= debug_option_table
; entry
->letter
; entry
++)
12269 if (entry
->letter
== * letters
)
12271 if (entry
->val
== 0)
12272 * entry
->variable
= 0;
12274 * entry
->variable
|= entry
->val
;
12275 result
|= entry
->val
;
12280 if (entry
->letter
== 0)
12281 warn (_("Unrecognized debug letter option '%c'\n"), * letters
);
12286 /* The --debug-dump=frames-interp option also enables the
12287 --debug-dump=frames option. */
12288 if (do_debug_frames_interp
)
12289 do_debug_frames
= 1;
12295 dwarf_select_sections_all (void)
12298 do_debug_abbrevs
= 1;
12299 do_debug_lines
= FLAG_DEBUG_LINES_RAW
;
12300 do_debug_pubnames
= 1;
12301 do_debug_pubtypes
= 1;
12302 do_debug_aranges
= 1;
12303 do_debug_ranges
= 1;
12304 do_debug_frames
= 1;
12305 do_debug_macinfo
= 1;
12310 do_trace_abbrevs
= 1;
12311 do_trace_aranges
= 1;
12313 do_debug_cu_index
= 1;
12314 do_follow_links
= 1;
12315 do_debug_links
= 1;
12316 do_debug_str_offsets
= 1;
12319 #define NO_ABBREVS NULL, NULL, NULL, 0, 0, 0, NULL, 0
12320 #define ABBREV(N) NULL, NULL, NULL, 0, 0, N, NULL, 0
12322 /* N.B. The order here must match the order in section_display_enum. */
12324 struct dwarf_section_display debug_displays
[] =
12326 { { ".debug_abbrev", ".zdebug_abbrev", ".dwabrev", NO_ABBREVS
}, display_debug_abbrev
, &do_debug_abbrevs
, false },
12327 { { ".debug_aranges", ".zdebug_aranges", ".dwarnge", NO_ABBREVS
}, display_debug_aranges
, &do_debug_aranges
, true },
12328 { { ".debug_frame", ".zdebug_frame", ".dwframe", NO_ABBREVS
}, display_debug_frames
, &do_debug_frames
, true },
12329 { { ".debug_info", ".zdebug_info", ".dwinfo", ABBREV (abbrev
)}, display_debug_info
, &do_debug_info
, true },
12330 { { ".debug_line", ".zdebug_line", ".dwline", NO_ABBREVS
}, display_debug_lines
, &do_debug_lines
, true },
12331 { { ".debug_pubnames", ".zdebug_pubnames", ".dwpbnms", NO_ABBREVS
}, display_debug_pubnames
, &do_debug_pubnames
, false },
12332 { { ".debug_gnu_pubnames", ".zdebug_gnu_pubnames", "", NO_ABBREVS
}, display_debug_gnu_pubnames
, &do_debug_pubnames
, false },
12333 { { ".eh_frame", "", "", NO_ABBREVS
}, display_debug_frames
, &do_debug_frames
, true },
12334 { { ".debug_macinfo", ".zdebug_macinfo", "", NO_ABBREVS
}, display_debug_macinfo
, &do_debug_macinfo
, false },
12335 { { ".debug_macro", ".zdebug_macro", ".dwmac", NO_ABBREVS
}, display_debug_macro
, &do_debug_macinfo
, true },
12336 { { ".debug_str", ".zdebug_str", ".dwstr", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, false },
12337 { { ".debug_line_str", ".zdebug_line_str", "", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, false },
12338 { { ".debug_loc", ".zdebug_loc", ".dwloc", NO_ABBREVS
}, display_debug_loc
, &do_debug_loc
, true },
12339 { { ".debug_loclists", ".zdebug_loclists", "", NO_ABBREVS
}, display_debug_loc
, &do_debug_loc
, true },
12340 { { ".debug_loclists.dwo", ".zdebug_loclists.dwo", "", NO_ABBREVS
}, display_debug_loc
, &do_debug_loc
, true },
12341 { { ".debug_pubtypes", ".zdebug_pubtypes", ".dwpbtyp", NO_ABBREVS
}, display_debug_pubnames
, &do_debug_pubtypes
, false },
12342 { { ".debug_gnu_pubtypes", ".zdebug_gnu_pubtypes", "", NO_ABBREVS
}, display_debug_gnu_pubnames
, &do_debug_pubtypes
, false },
12343 { { ".debug_ranges", ".zdebug_ranges", ".dwrnges", NO_ABBREVS
}, display_debug_ranges
, &do_debug_ranges
, true },
12344 { { ".debug_rnglists", ".zdebug_rnglists", "", NO_ABBREVS
}, display_debug_ranges
, &do_debug_ranges
, true },
12345 { { ".debug_rnglists.dwo", ".zdebug_rnglists.dwo", "", NO_ABBREVS
}, display_debug_ranges
, &do_debug_ranges
, true },
12346 { { ".debug_static_func", ".zdebug_static_func", "", NO_ABBREVS
}, display_debug_not_supported
, NULL
, false },
12347 { { ".debug_static_vars", ".zdebug_static_vars", "", NO_ABBREVS
}, display_debug_not_supported
, NULL
, false },
12348 { { ".debug_types", ".zdebug_types", "", ABBREV (abbrev
) }, display_debug_types
, &do_debug_info
, true },
12349 { { ".debug_weaknames", ".zdebug_weaknames", "", NO_ABBREVS
}, display_debug_not_supported
, NULL
, false },
12350 { { ".gdb_index", "", "", NO_ABBREVS
}, display_gdb_index
, &do_gdb_index
, false },
12351 { { ".debug_names", "", "", NO_ABBREVS
}, display_debug_names
, &do_gdb_index
, false },
12352 { { ".trace_info", "", "", ABBREV (trace_abbrev
) }, display_trace_info
, &do_trace_info
, true },
12353 { { ".trace_abbrev", "", "", NO_ABBREVS
}, display_debug_abbrev
, &do_trace_abbrevs
, false },
12354 { { ".trace_aranges", "", "", NO_ABBREVS
}, display_debug_aranges
, &do_trace_aranges
, false },
12355 { { ".debug_info.dwo", ".zdebug_info.dwo", "", ABBREV (abbrev_dwo
) }, display_debug_info
, &do_debug_info
, true },
12356 { { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo", "", NO_ABBREVS
}, display_debug_abbrev
, &do_debug_abbrevs
, false },
12357 { { ".debug_types.dwo", ".zdebug_types.dwo", "", ABBREV (abbrev_dwo
) }, display_debug_types
, &do_debug_info
, true },
12358 { { ".debug_line.dwo", ".zdebug_line.dwo", "", NO_ABBREVS
}, display_debug_lines
, &do_debug_lines
, true },
12359 { { ".debug_loc.dwo", ".zdebug_loc.dwo", "", NO_ABBREVS
}, display_debug_loc
, &do_debug_loc
, true },
12360 { { ".debug_macro.dwo", ".zdebug_macro.dwo", "", NO_ABBREVS
}, display_debug_macro
, &do_debug_macinfo
, true },
12361 { { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo", "", NO_ABBREVS
}, display_debug_macinfo
, &do_debug_macinfo
, false },
12362 { { ".debug_str.dwo", ".zdebug_str.dwo", "", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, true },
12363 { { ".debug_str_offsets", ".zdebug_str_offsets", "", NO_ABBREVS
}, display_debug_str_offsets
, &do_debug_str_offsets
, true },
12364 { { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo", "", NO_ABBREVS
}, display_debug_str_offsets
, &do_debug_str_offsets
, true },
12365 { { ".debug_addr", ".zdebug_addr", "", NO_ABBREVS
}, display_debug_addr
, &do_debug_addr
, true },
12366 { { ".debug_cu_index", "", "", NO_ABBREVS
}, display_cu_index
, &do_debug_cu_index
, false },
12367 { { ".debug_tu_index", "", "", NO_ABBREVS
}, display_cu_index
, &do_debug_cu_index
, false },
12368 { { ".gnu_debuglink", "", "", NO_ABBREVS
}, display_debug_links
, &do_debug_links
, false },
12369 { { ".gnu_debugaltlink", "", "", NO_ABBREVS
}, display_debug_links
, &do_debug_links
, false },
12370 { { ".debug_sup", "", "", NO_ABBREVS
}, display_debug_sup
, &do_debug_links
, false },
12371 /* Separate debug info files can containt their own .debug_str section,
12372 and this might be in *addition* to a .debug_str section already present
12373 in the main file. Hence we need to have two entries for .debug_str. */
12374 { { ".debug_str", ".zdebug_str", "", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, false },
12375 { { ".note.gnu.build-id", "", "", NO_ABBREVS
}, display_debug_not_supported
, NULL
, false },
12378 /* A static assertion. */
12379 extern int debug_displays_assert
[ARRAY_SIZE (debug_displays
) == max
? 1 : -1];