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
;
998 unsigned long attribute
;
1001 READ_ULEB (entry
, start
, end
);
1003 /* A single zero is supposed to end the set according
1004 to the standard. If there's more, then signal that to
1006 if (start
== end
|| entry
== 0)
1009 list
->start_of_next_abbrevs
= start
!= end
? start
: NULL
;
1013 READ_ULEB (tag
, start
, end
);
1020 children
= *start
++;
1022 add_abbrev (entry
, tag
, children
, list
);
1027 /* Initialize it due to a false compiler warning. */
1028 int64_t implicit_const
= -1;
1030 READ_ULEB (attribute
, start
, end
);
1034 READ_ULEB (form
, start
, end
);
1038 if (form
== DW_FORM_implicit_const
)
1040 READ_SLEB (implicit_const
, start
, end
);
1045 add_abbrev_attr (attribute
, form
, implicit_const
, list
);
1047 while (attribute
!= 0);
1050 /* Report the missing single zero which ends the section. */
1051 error (_("%s section not zero terminated\n"), section
->name
);
1057 /* Return a sequence of abbrevs in SECTION starting at ABBREV_BASE
1058 plus ABBREV_OFFSET and finishing at ABBREV_BASE + ABBREV_SIZE.
1059 If FREE_LIST is non-NULL search the already decoded abbrevs on
1060 abbrev_lists first and if found set *FREE_LIST to NULL. If
1061 searching doesn't find a matching abbrev, set *FREE_LIST to the
1062 newly allocated list. If FREE_LIST is NULL, no search is done and
1063 the returned abbrev_list is always newly allocated. */
1065 static abbrev_list
*
1066 find_and_process_abbrev_set (struct dwarf_section
*section
,
1067 uint64_t abbrev_base
,
1068 uint64_t abbrev_size
,
1069 uint64_t abbrev_offset
,
1070 abbrev_list
**free_list
)
1075 if (abbrev_base
>= section
->size
1076 || abbrev_size
> section
->size
- abbrev_base
)
1078 /* PR 17531: file:4bcd9ce9. */
1079 warn (_("Debug info is corrupted, abbrev size (%#" PRIx64
")"
1080 " is larger than abbrev section size (%#" PRIx64
")\n"),
1081 abbrev_base
+ abbrev_size
, section
->size
);
1084 if (abbrev_offset
>= abbrev_size
)
1086 warn (_("Debug info is corrupted, abbrev offset (%#" PRIx64
")"
1087 " is larger than abbrev section size (%#" PRIx64
")\n"),
1088 abbrev_offset
, abbrev_size
);
1092 unsigned char *start
= section
->start
+ abbrev_base
+ abbrev_offset
;
1093 unsigned char *end
= section
->start
+ abbrev_base
+ abbrev_size
;
1094 abbrev_list
*list
= NULL
;
1096 list
= find_abbrev_list_by_raw_abbrev (start
);
1099 list
= process_abbrev_set (section
, start
, end
);
1107 get_TAG_name (uint64_t tag
)
1109 const char *name
= NULL
;
1111 if ((unsigned int) tag
== tag
)
1112 name
= get_DW_TAG_name ((unsigned int) tag
);
1115 static char buffer
[100];
1117 if (tag
>= DW_TAG_lo_user
&& tag
<= DW_TAG_hi_user
)
1118 snprintf (buffer
, sizeof (buffer
),
1119 _("User TAG value: %#" PRIx64
), tag
);
1121 snprintf (buffer
, sizeof (buffer
),
1122 _("Unknown TAG value: %#" PRIx64
), tag
);
1130 get_FORM_name (unsigned long form
)
1132 const char *name
= NULL
;
1135 return "DW_FORM value: 0";
1137 if ((unsigned int) form
== form
)
1138 name
= get_DW_FORM_name ((unsigned int) form
);
1141 static char buffer
[100];
1143 snprintf (buffer
, sizeof (buffer
), _("Unknown FORM value: %lx"), form
);
1151 get_IDX_name (unsigned long idx
)
1153 const char *name
= NULL
;
1155 if ((unsigned int) idx
== idx
)
1156 name
= get_DW_IDX_name ((unsigned int) idx
);
1159 static char buffer
[100];
1161 snprintf (buffer
, sizeof (buffer
), _("Unknown IDX value: %lx"), idx
);
1168 static unsigned char *
1169 display_block (unsigned char *data
,
1171 const unsigned char * const end
, char delimiter
)
1175 printf (_("%c%" PRIu64
" byte block: "), delimiter
, length
);
1177 return (unsigned char *) end
;
1179 maxlen
= end
- data
;
1180 length
= length
> maxlen
? maxlen
: length
;
1183 printf ("%" PRIx64
" ", byte_get (data
++, 1));
1189 decode_location_expression (unsigned char * data
,
1190 unsigned int pointer_size
,
1191 unsigned int offset_size
,
1195 struct dwarf_section
* section
)
1200 unsigned char *end
= data
+ length
;
1201 int need_frame_base
= 0;
1210 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1211 printf ("DW_OP_addr: %" PRIx64
, uvalue
);
1214 printf ("DW_OP_deref");
1217 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1218 printf ("DW_OP_const1u: %" PRIu64
, uvalue
);
1221 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 1, end
);
1222 printf ("DW_OP_const1s: %" PRId64
, svalue
);
1225 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
1226 printf ("DW_OP_const2u: %" PRIu64
, uvalue
);
1229 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1230 printf ("DW_OP_const2s: %" PRId64
, svalue
);
1233 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1234 printf ("DW_OP_const4u: %" PRIu64
, uvalue
);
1237 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
1238 printf ("DW_OP_const4s: %" PRId64
, svalue
);
1241 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 8, end
);
1242 printf ("DW_OP_const8u: %" PRIu64
, uvalue
);
1245 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 8, end
);
1246 printf ("DW_OP_const8s: %" PRId64
, svalue
);
1249 READ_ULEB (uvalue
, data
, end
);
1250 printf ("DW_OP_constu: %" PRIu64
, uvalue
);
1253 READ_SLEB (svalue
, data
, end
);
1254 printf ("DW_OP_consts: %" PRId64
, svalue
);
1257 printf ("DW_OP_dup");
1260 printf ("DW_OP_drop");
1263 printf ("DW_OP_over");
1266 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1267 printf ("DW_OP_pick: %" PRIu64
, uvalue
);
1270 printf ("DW_OP_swap");
1273 printf ("DW_OP_rot");
1276 printf ("DW_OP_xderef");
1279 printf ("DW_OP_abs");
1282 printf ("DW_OP_and");
1285 printf ("DW_OP_div");
1288 printf ("DW_OP_minus");
1291 printf ("DW_OP_mod");
1294 printf ("DW_OP_mul");
1297 printf ("DW_OP_neg");
1300 printf ("DW_OP_not");
1303 printf ("DW_OP_or");
1306 printf ("DW_OP_plus");
1308 case DW_OP_plus_uconst
:
1309 READ_ULEB (uvalue
, data
, end
);
1310 printf ("DW_OP_plus_uconst: %" PRIu64
, uvalue
);
1313 printf ("DW_OP_shl");
1316 printf ("DW_OP_shr");
1319 printf ("DW_OP_shra");
1322 printf ("DW_OP_xor");
1325 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1326 printf ("DW_OP_bra: %" PRId64
, svalue
);
1329 printf ("DW_OP_eq");
1332 printf ("DW_OP_ge");
1335 printf ("DW_OP_gt");
1338 printf ("DW_OP_le");
1341 printf ("DW_OP_lt");
1344 printf ("DW_OP_ne");
1347 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1348 printf ("DW_OP_skip: %" PRId64
, svalue
);
1383 printf ("DW_OP_lit%d", op
- DW_OP_lit0
);
1418 printf ("DW_OP_reg%d (%s)", op
- DW_OP_reg0
,
1419 regname (op
- DW_OP_reg0
, 1));
1454 READ_SLEB (svalue
, data
, end
);
1455 printf ("DW_OP_breg%d (%s): %" PRId64
,
1456 op
- DW_OP_breg0
, regname (op
- DW_OP_breg0
, 1), svalue
);
1460 READ_ULEB (uvalue
, data
, end
);
1461 printf ("DW_OP_regx: %" PRIu64
" (%s)",
1462 uvalue
, regname (uvalue
, 1));
1465 need_frame_base
= 1;
1466 READ_SLEB (svalue
, data
, end
);
1467 printf ("DW_OP_fbreg: %" PRId64
, svalue
);
1470 READ_ULEB (uvalue
, data
, end
);
1471 READ_SLEB (svalue
, data
, end
);
1472 printf ("DW_OP_bregx: %" PRIu64
" (%s) %" PRId64
,
1473 uvalue
, regname (uvalue
, 1), svalue
);
1476 READ_ULEB (uvalue
, data
, end
);
1477 printf ("DW_OP_piece: %" PRIu64
, uvalue
);
1479 case DW_OP_deref_size
:
1480 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1481 printf ("DW_OP_deref_size: %" PRIu64
, uvalue
);
1483 case DW_OP_xderef_size
:
1484 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1485 printf ("DW_OP_xderef_size: %" PRIu64
, uvalue
);
1488 printf ("DW_OP_nop");
1491 /* DWARF 3 extensions. */
1492 case DW_OP_push_object_address
:
1493 printf ("DW_OP_push_object_address");
1496 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1497 this ought to be an 8-byte wide computation. */
1498 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1499 printf ("DW_OP_call2: <%#" PRIx64
">", svalue
+ cu_offset
);
1502 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1503 this ought to be an 8-byte wide computation. */
1504 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
1505 printf ("DW_OP_call4: <%#" PRIx64
">", svalue
+ cu_offset
);
1507 case DW_OP_call_ref
:
1508 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1509 this ought to be an 8-byte wide computation. */
1510 if (dwarf_version
== -1)
1512 printf (_("(DW_OP_call_ref in frame info)"));
1513 /* No way to tell where the next op is, so just bail. */
1514 return need_frame_base
;
1516 if (dwarf_version
== 2)
1518 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1522 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1524 printf ("DW_OP_call_ref: <%#" PRIx64
">", uvalue
);
1526 case DW_OP_form_tls_address
:
1527 printf ("DW_OP_form_tls_address");
1529 case DW_OP_call_frame_cfa
:
1530 printf ("DW_OP_call_frame_cfa");
1532 case DW_OP_bit_piece
:
1533 printf ("DW_OP_bit_piece: ");
1534 READ_ULEB (uvalue
, data
, end
);
1535 printf (_("size: %" PRIu64
" "), uvalue
);
1536 READ_ULEB (uvalue
, data
, end
);
1537 printf (_("offset: %" PRIu64
" "), uvalue
);
1540 /* DWARF 4 extensions. */
1541 case DW_OP_stack_value
:
1542 printf ("DW_OP_stack_value");
1545 case DW_OP_implicit_value
:
1546 printf ("DW_OP_implicit_value");
1547 READ_ULEB (uvalue
, data
, end
);
1548 data
= display_block (data
, uvalue
, end
, ' ');
1551 /* GNU extensions. */
1552 case DW_OP_GNU_push_tls_address
:
1553 printf (_("DW_OP_GNU_push_tls_address or DW_OP_HP_unknown"));
1555 case DW_OP_GNU_uninit
:
1556 printf ("DW_OP_GNU_uninit");
1557 /* FIXME: Is there data associated with this OP ? */
1559 case DW_OP_GNU_encoded_addr
:
1566 addr
= get_encoded_value (&data
, encoding
, section
, end
);
1568 printf ("DW_OP_GNU_encoded_addr: fmt:%02x addr:", encoding
);
1569 print_hex_ns (addr
, pointer_size
);
1572 case DW_OP_implicit_pointer
:
1573 case DW_OP_GNU_implicit_pointer
:
1574 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1575 this ought to be an 8-byte wide computation. */
1576 if (dwarf_version
== -1)
1578 printf (_("(%s in frame info)"),
1579 (op
== DW_OP_implicit_pointer
1580 ? "DW_OP_implicit_pointer"
1581 : "DW_OP_GNU_implicit_pointer"));
1582 /* No way to tell where the next op is, so just bail. */
1583 return need_frame_base
;
1585 if (dwarf_version
== 2)
1587 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1591 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1593 READ_SLEB (svalue
, data
, end
);
1594 printf ("%s: <%#" PRIx64
"> %" PRId64
,
1595 (op
== DW_OP_implicit_pointer
1596 ? "DW_OP_implicit_pointer" : "DW_OP_GNU_implicit_pointer"),
1599 case DW_OP_entry_value
:
1600 case DW_OP_GNU_entry_value
:
1601 READ_ULEB (uvalue
, data
, end
);
1602 /* PR 17531: file: 0cc9cd00. */
1603 if (uvalue
> (size_t) (end
- data
))
1604 uvalue
= end
- data
;
1605 printf ("%s: (", (op
== DW_OP_entry_value
? "DW_OP_entry_value"
1606 : "DW_OP_GNU_entry_value"));
1607 if (decode_location_expression (data
, pointer_size
, offset_size
,
1608 dwarf_version
, uvalue
,
1609 cu_offset
, section
))
1610 need_frame_base
= 1;
1614 case DW_OP_const_type
:
1615 case DW_OP_GNU_const_type
:
1616 READ_ULEB (uvalue
, data
, end
);
1617 printf ("%s: <%#" PRIx64
"> ",
1618 (op
== DW_OP_const_type
? "DW_OP_const_type"
1619 : "DW_OP_GNU_const_type"),
1620 cu_offset
+ uvalue
);
1621 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1622 data
= display_block (data
, uvalue
, end
, ' ');
1624 case DW_OP_regval_type
:
1625 case DW_OP_GNU_regval_type
:
1626 READ_ULEB (uvalue
, data
, end
);
1627 printf ("%s: %" PRIu64
" (%s)",
1628 (op
== DW_OP_regval_type
? "DW_OP_regval_type"
1629 : "DW_OP_GNU_regval_type"),
1630 uvalue
, regname (uvalue
, 1));
1631 READ_ULEB (uvalue
, data
, end
);
1632 printf (" <%#" PRIx64
">", cu_offset
+ uvalue
);
1634 case DW_OP_deref_type
:
1635 case DW_OP_GNU_deref_type
:
1636 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1637 printf ("%s: %" PRId64
,
1638 (op
== DW_OP_deref_type
? "DW_OP_deref_type"
1639 : "DW_OP_GNU_deref_type"),
1641 READ_ULEB (uvalue
, data
, end
);
1642 printf (" <%#" PRIx64
">", cu_offset
+ uvalue
);
1645 case DW_OP_GNU_convert
:
1646 READ_ULEB (uvalue
, data
, end
);
1647 printf ("%s <%#" PRIx64
">",
1648 (op
== DW_OP_convert
? "DW_OP_convert" : "DW_OP_GNU_convert"),
1649 uvalue
? cu_offset
+ uvalue
: uvalue
);
1651 case DW_OP_reinterpret
:
1652 case DW_OP_GNU_reinterpret
:
1653 READ_ULEB (uvalue
, data
, end
);
1654 printf ("%s <%#" PRIx64
">",
1655 (op
== DW_OP_reinterpret
? "DW_OP_reinterpret"
1656 : "DW_OP_GNU_reinterpret"),
1657 uvalue
? cu_offset
+ uvalue
: uvalue
);
1659 case DW_OP_GNU_parameter_ref
:
1660 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1661 printf ("DW_OP_GNU_parameter_ref: <%#" PRIx64
">",
1662 cu_offset
+ uvalue
);
1665 READ_ULEB (uvalue
, data
, end
);
1666 printf ("DW_OP_addrx <%#" PRIx64
">", uvalue
);
1668 case DW_OP_GNU_addr_index
:
1669 READ_ULEB (uvalue
, data
, end
);
1670 printf ("DW_OP_GNU_addr_index <%#" PRIx64
">", uvalue
);
1672 case DW_OP_GNU_const_index
:
1673 READ_ULEB (uvalue
, data
, end
);
1674 printf ("DW_OP_GNU_const_index <%#" PRIx64
">", uvalue
);
1676 case DW_OP_GNU_variable_value
:
1677 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1678 this ought to be an 8-byte wide computation. */
1679 if (dwarf_version
== -1)
1681 printf (_("(DW_OP_GNU_variable_value in frame info)"));
1682 /* No way to tell where the next op is, so just bail. */
1683 return need_frame_base
;
1685 if (dwarf_version
== 2)
1687 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1691 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1693 printf ("DW_OP_GNU_variable_value: <%#" PRIx64
">", uvalue
);
1696 /* HP extensions. */
1697 case DW_OP_HP_is_value
:
1698 printf ("DW_OP_HP_is_value");
1699 /* FIXME: Is there data associated with this OP ? */
1701 case DW_OP_HP_fltconst4
:
1702 printf ("DW_OP_HP_fltconst4");
1703 /* FIXME: Is there data associated with this OP ? */
1705 case DW_OP_HP_fltconst8
:
1706 printf ("DW_OP_HP_fltconst8");
1707 /* FIXME: Is there data associated with this OP ? */
1709 case DW_OP_HP_mod_range
:
1710 printf ("DW_OP_HP_mod_range");
1711 /* FIXME: Is there data associated with this OP ? */
1713 case DW_OP_HP_unmod_range
:
1714 printf ("DW_OP_HP_unmod_range");
1715 /* FIXME: Is there data associated with this OP ? */
1718 printf ("DW_OP_HP_tls");
1719 /* FIXME: Is there data associated with this OP ? */
1722 /* PGI (STMicroelectronics) extensions. */
1723 case DW_OP_PGI_omp_thread_num
:
1724 /* Pushes the thread number for the current thread as it would be
1725 returned by the standard OpenMP library function:
1726 omp_get_thread_num(). The "current thread" is the thread for
1727 which the expression is being evaluated. */
1728 printf ("DW_OP_PGI_omp_thread_num");
1732 if (op
>= DW_OP_lo_user
1733 && op
<= DW_OP_hi_user
)
1734 printf (_("(User defined location op %#x)"), op
);
1736 printf (_("(Unknown location op %#x)"), op
);
1737 /* No way to tell where the next op is, so just bail. */
1738 return need_frame_base
;
1741 /* Separate the ops. */
1746 return need_frame_base
;
1749 /* Find the CU or TU set corresponding to the given CU_OFFSET.
1750 This is used for DWARF package files. */
1752 static struct cu_tu_set
*
1753 find_cu_tu_set_v2 (uint64_t cu_offset
, int do_types
)
1755 struct cu_tu_set
*p
;
1757 unsigned int dw_sect
;
1763 dw_sect
= DW_SECT_TYPES
;
1769 dw_sect
= DW_SECT_INFO
;
1773 if (p
->section_offsets
[dw_sect
] == cu_offset
)
1782 fetch_alt_indirect_string (uint64_t offset
)
1786 if (! do_follow_links
)
1789 if (first_separate_info
== NULL
)
1790 return _("<no links available>");
1792 for (i
= first_separate_info
; i
!= NULL
; i
= i
->next
)
1794 struct dwarf_section
* section
;
1797 if (! load_debug_section (separate_debug_str
, i
->handle
))
1800 section
= &debug_displays
[separate_debug_str
].section
;
1802 if (section
->start
== NULL
)
1805 if (offset
>= section
->size
)
1808 ret
= (const char *) (section
->start
+ offset
);
1809 /* Unfortunately we cannot rely upon the .debug_str section ending with a
1810 NUL byte. Since our caller is expecting to receive a well formed C
1811 string we test for the lack of a terminating byte here. */
1812 if (strnlen ((const char *) ret
, section
->size
- offset
)
1813 == section
->size
- offset
)
1814 return _("<no NUL byte at end of alt .debug_str section>");
1819 warn (_("DW_FORM_GNU_strp_alt offset (%#" PRIx64
")"
1820 " too big or no string sections available\n"), offset
);
1821 return _("<offset is too big>");
1825 get_AT_name (unsigned long attribute
)
1830 return "DW_AT value: 0";
1832 /* One value is shared by the MIPS and HP extensions: */
1833 if (attribute
== DW_AT_MIPS_fde
)
1834 return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable";
1836 name
= get_DW_AT_name (attribute
);
1840 static char buffer
[100];
1842 snprintf (buffer
, sizeof (buffer
), _("Unknown AT value: %lx"),
1851 add_dwo_info (const char * value
, uint64_t cu_offset
, dwo_type type
)
1853 dwo_info
* dwinfo
= xmalloc (sizeof * dwinfo
);
1855 dwinfo
->type
= type
;
1856 dwinfo
->value
= value
;
1857 dwinfo
->cu_offset
= cu_offset
;
1858 dwinfo
->next
= first_dwo_info
;
1859 first_dwo_info
= dwinfo
;
1863 add_dwo_name (const char * name
, uint64_t cu_offset
)
1865 add_dwo_info (name
, cu_offset
, DWO_NAME
);
1869 add_dwo_dir (const char * dir
, uint64_t cu_offset
)
1871 add_dwo_info (dir
, cu_offset
, DWO_DIR
);
1875 add_dwo_id (const char * id
, uint64_t cu_offset
)
1877 add_dwo_info (id
, cu_offset
, DWO_ID
);
1881 free_dwo_info (void)
1886 for (dwinfo
= first_dwo_info
; dwinfo
!= NULL
; dwinfo
= next
)
1888 next
= dwinfo
->next
;
1891 first_dwo_info
= NULL
;
1894 /* Ensure that START + UVALUE is less than END.
1895 Return an adjusted UVALUE if necessary to ensure this relationship. */
1897 static inline uint64_t
1898 check_uvalue (const unsigned char *start
,
1900 const unsigned char *end
)
1902 uint64_t max_uvalue
= end
- start
;
1904 /* See PR 17512: file: 008-103549-0.001:0.1.
1905 and PR 24829 for examples of where these tests are triggered. */
1906 if (uvalue
> max_uvalue
)
1908 warn (_("Corrupt attribute block length: %#" PRIx64
"\n"), uvalue
);
1909 uvalue
= max_uvalue
;
1915 static unsigned char *
1916 skip_attr_bytes (unsigned long form
,
1917 unsigned char *data
,
1919 uint64_t pointer_size
,
1920 uint64_t offset_size
,
1922 uint64_t *value_return
)
1925 uint64_t uvalue
= 0;
1932 case DW_FORM_ref_addr
:
1933 if (dwarf_version
== 2)
1934 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1935 else if (dwarf_version
> 2)
1936 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1942 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1946 case DW_FORM_line_strp
:
1947 case DW_FORM_sec_offset
:
1948 case DW_FORM_GNU_ref_alt
:
1949 case DW_FORM_GNU_strp_alt
:
1950 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1953 case DW_FORM_flag_present
:
1961 case DW_FORM_addrx1
:
1962 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1966 case DW_FORM_addrx3
:
1967 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 3, end
);
1973 case DW_FORM_addrx2
:
1974 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
1980 case DW_FORM_addrx4
:
1981 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1985 READ_SLEB (svalue
, data
, end
);
1989 case DW_FORM_ref_udata
:
1991 case DW_FORM_GNU_str_index
:
1993 case DW_FORM_GNU_addr_index
:
1995 case DW_FORM_loclistx
:
1996 case DW_FORM_rnglistx
:
1997 READ_ULEB (uvalue
, data
, end
);
2001 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 8, end
);
2005 case DW_FORM_ref_sig8
:
2009 case DW_FORM_data16
:
2013 case DW_FORM_string
:
2014 inc
= strnlen ((char *) data
, end
- data
) + 1;
2018 case DW_FORM_exprloc
:
2019 READ_ULEB (uvalue
, data
, end
);
2023 case DW_FORM_block1
:
2024 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
2028 case DW_FORM_block2
:
2029 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
2033 case DW_FORM_block4
:
2034 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
2038 case DW_FORM_indirect
:
2039 READ_ULEB (form
, data
, end
);
2040 if (form
== DW_FORM_implicit_const
)
2041 SKIP_ULEB (data
, end
);
2042 return skip_attr_bytes (form
, data
, end
, pointer_size
, offset_size
,
2043 dwarf_version
, value_return
);
2049 * value_return
= uvalue
;
2050 if (inc
<= (size_t) (end
- data
))
2057 /* Given form FORM with value UVALUE, locate and return the abbreviation
2058 associated with it. */
2060 static abbrev_entry
*
2061 get_type_abbrev_from_form (unsigned long form
,
2062 unsigned long uvalue
,
2064 unsigned char *cu_end
,
2065 const struct dwarf_section
*section
,
2066 unsigned long *abbrev_num_return
,
2067 unsigned char **data_return
,
2068 abbrev_map
**map_return
)
2070 unsigned long abbrev_number
;
2072 abbrev_entry
* entry
;
2073 unsigned char * data
;
2075 if (abbrev_num_return
!= NULL
)
2076 * abbrev_num_return
= 0;
2077 if (data_return
!= NULL
)
2078 * data_return
= NULL
;
2082 case DW_FORM_GNU_ref_alt
:
2083 case DW_FORM_ref_sig8
:
2084 /* FIXME: We are unable to handle this form at the moment. */
2087 case DW_FORM_ref_addr
:
2088 if (uvalue
>= section
->size
)
2090 warn (_("Unable to resolve ref_addr form: uvalue %lx "
2091 "> section size %" PRIx64
" (%s)\n"),
2092 uvalue
, section
->size
, section
->name
);
2097 case DW_FORM_ref_sup4
:
2098 case DW_FORM_ref_sup8
:
2105 case DW_FORM_ref_udata
:
2106 if (uvalue
+ cu_offset
< uvalue
2107 || uvalue
+ cu_offset
> (size_t) (cu_end
- section
->start
))
2109 warn (_("Unable to resolve ref form: uvalue %lx + cu_offset %" PRIx64
2110 " > CU size %tx\n"),
2111 uvalue
, cu_offset
, cu_end
- section
->start
);
2114 uvalue
+= cu_offset
;
2117 /* FIXME: Are there other DW_FORMs that can be used by types ? */
2120 warn (_("Unexpected form %lx encountered whilst finding abbreviation for type\n"), form
);
2124 data
= (unsigned char *) section
->start
+ uvalue
;
2125 map
= find_abbrev_map_by_offset (uvalue
);
2129 warn (_("Unable to find abbreviations for CU offset %#lx\n"), uvalue
);
2132 if (map
->list
== NULL
)
2134 warn (_("Empty abbreviation list encountered for CU offset %lx\n"), uvalue
);
2138 if (map_return
!= NULL
)
2140 if (form
== DW_FORM_ref_addr
)
2146 READ_ULEB (abbrev_number
, data
, section
->start
+ section
->size
);
2148 for (entry
= map
->list
->first_abbrev
; entry
!= NULL
; entry
= entry
->next
)
2149 if (entry
->number
== abbrev_number
)
2152 if (abbrev_num_return
!= NULL
)
2153 * abbrev_num_return
= abbrev_number
;
2155 if (data_return
!= NULL
)
2156 * data_return
= data
;
2159 warn (_("Unable to find entry for abbreviation %lu\n"), abbrev_number
);
2164 /* Return IS_SIGNED set to TRUE if the type using abbreviation ENTRY
2165 can be determined to be a signed type. The data for ENTRY can be
2166 found starting at DATA. */
2169 get_type_signedness (abbrev_entry
*entry
,
2170 const struct dwarf_section
*section
,
2171 unsigned char *data
,
2174 uint64_t pointer_size
,
2175 uint64_t offset_size
,
2178 unsigned int nesting
)
2182 * is_signed
= false;
2184 #define MAX_NESTING 20
2185 if (nesting
> MAX_NESTING
)
2187 /* FIXME: Warn - or is this expected ?
2188 NB/ We need to avoid infinite recursion. */
2192 for (attr
= entry
->first_attr
;
2193 attr
!= NULL
&& attr
->attribute
;
2196 unsigned char * orig_data
= data
;
2197 uint64_t uvalue
= 0;
2199 data
= skip_attr_bytes (attr
->form
, data
, end
, pointer_size
,
2200 offset_size
, dwarf_version
, & uvalue
);
2204 switch (attr
->attribute
)
2206 case DW_AT_linkage_name
:
2210 if (attr
->form
== DW_FORM_strp
)
2211 printf (", %s", fetch_indirect_string (uvalue
));
2212 else if (attr
->form
== DW_FORM_string
)
2213 printf (", %.*s", (int) (end
- orig_data
), orig_data
);
2220 abbrev_entry
*type_abbrev
;
2221 unsigned char *type_data
;
2224 type_abbrev
= get_type_abbrev_from_form (attr
->form
,
2229 NULL
/* abbrev num return */,
2232 if (type_abbrev
== NULL
)
2235 get_type_signedness (type_abbrev
, section
, type_data
,
2236 map
? section
->start
+ map
->end
: end
,
2237 map
? map
->start
: cu_offset
,
2238 pointer_size
, offset_size
, dwarf_version
,
2239 is_signed
, nesting
+ 1);
2243 case DW_AT_encoding
:
2244 /* Determine signness. */
2247 case DW_ATE_address
:
2248 /* FIXME - some architectures have signed addresses. */
2249 case DW_ATE_boolean
:
2250 case DW_ATE_unsigned
:
2251 case DW_ATE_unsigned_char
:
2252 case DW_ATE_unsigned_fixed
:
2253 * is_signed
= false;
2257 case DW_ATE_complex_float
:
2260 case DW_ATE_signed_char
:
2261 case DW_ATE_imaginary_float
:
2262 case DW_ATE_decimal_float
:
2263 case DW_ATE_signed_fixed
:
2273 read_and_print_leb128 (unsigned char *data
,
2274 unsigned int *bytes_read
,
2275 unsigned const char *end
,
2279 uint64_t val
= read_leb128 (data
, end
, is_signed
, bytes_read
, &status
);
2281 report_leb_status (status
);
2283 printf ("%" PRId64
, val
);
2285 printf ("%" PRIu64
, val
);
2289 display_discr_list (unsigned long form
,
2291 unsigned char *data
,
2294 unsigned char *end
= data
;
2298 printf ("[default]");
2305 case DW_FORM_block1
:
2306 case DW_FORM_block2
:
2307 case DW_FORM_block4
:
2308 /* Move data pointer back to the start of the byte array. */
2312 printf ("<corrupt>\n");
2313 warn (_("corrupt discr_list - not using a block form\n"));
2319 printf ("<corrupt>\n");
2320 warn (_("corrupt discr_list - block not long enough\n"));
2324 bool is_signed
= (level
> 0 && level
<= MAX_CU_NESTING
2325 ? level_type_signed
[level
- 1] : false);
2330 unsigned char discriminant
;
2331 unsigned int bytes_read
;
2333 SAFE_BYTE_GET_AND_INC (discriminant
, data
, 1, end
);
2335 switch (discriminant
)
2339 read_and_print_leb128 (data
, & bytes_read
, end
, is_signed
);
2345 read_and_print_leb128 (data
, & bytes_read
, end
, is_signed
);
2349 read_and_print_leb128 (data
, & bytes_read
, end
, is_signed
);
2354 printf ("<corrupt>\n");
2355 warn (_("corrupt discr_list - unrecognized discriminant byte %#x\n"),
2365 printf (")(signed)");
2367 printf (")(unsigned)");
2370 static unsigned char *
2371 read_and_display_attr_value (unsigned long attribute
,
2373 int64_t implicit_const
,
2374 unsigned char *start
,
2375 unsigned char *data
,
2378 uint64_t pointer_size
,
2379 uint64_t offset_size
,
2381 debug_info
*debug_info_p
,
2383 struct dwarf_section
*section
,
2384 struct cu_tu_set
*this_set
,
2389 uint64_t uvalue
= 0;
2390 uint64_t uvalue_hi
= 0;
2391 unsigned char *block_start
= NULL
;
2392 unsigned char *orig_data
= data
;
2394 if (data
> end
|| (data
== end
&& form
!= DW_FORM_flag_present
))
2396 warn (_("Corrupt attribute\n"));
2400 if (do_wide
&& ! do_loc
)
2402 /* PR 26847: Display the name of the form. */
2403 const char * name
= get_FORM_name (form
);
2405 /* For convenience we skip the DW_FORM_ prefix to the name. */
2407 name
+= 8; /* strlen ("DW_FORM_") */
2408 printf ("%c(%s)", delimiter
, name
);
2413 case DW_FORM_ref_addr
:
2414 if (dwarf_version
== 2)
2415 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
2416 else if (dwarf_version
> 2)
2417 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
2419 error (_("Internal error: DW_FORM_ref_addr is not supported in DWARF version 1.\n"));
2423 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
2426 case DW_FORM_strp_sup
:
2428 case DW_FORM_line_strp
:
2429 case DW_FORM_sec_offset
:
2430 case DW_FORM_GNU_ref_alt
:
2431 case DW_FORM_GNU_strp_alt
:
2432 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
2435 case DW_FORM_flag_present
:
2443 case DW_FORM_addrx1
:
2444 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
2450 case DW_FORM_addrx2
:
2451 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
2455 case DW_FORM_addrx3
:
2456 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 3, end
);
2459 case DW_FORM_ref_sup4
:
2463 case DW_FORM_addrx4
:
2464 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
2467 case DW_FORM_ref_sup8
:
2470 case DW_FORM_ref_sig8
:
2471 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 8, end
);
2474 case DW_FORM_data16
:
2475 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 8, end
);
2476 SAFE_BYTE_GET_AND_INC (uvalue_hi
, data
, 8, end
);
2477 if (byte_get
!= byte_get_little_endian
)
2479 uint64_t utmp
= uvalue
;
2486 READ_SLEB (svalue
, data
, end
);
2490 case DW_FORM_GNU_str_index
:
2492 case DW_FORM_ref_udata
:
2494 case DW_FORM_GNU_addr_index
:
2496 case DW_FORM_loclistx
:
2497 case DW_FORM_rnglistx
:
2498 READ_ULEB (uvalue
, data
, end
);
2501 case DW_FORM_indirect
:
2502 READ_ULEB (form
, data
, end
);
2504 printf ("%c%s", delimiter
, get_FORM_name (form
));
2505 if (form
== DW_FORM_implicit_const
)
2506 READ_SLEB (implicit_const
, data
, end
);
2507 return read_and_display_attr_value (attribute
, form
, implicit_const
,
2509 cu_offset
, pointer_size
,
2510 offset_size
, dwarf_version
,
2511 debug_info_p
, do_loc
,
2512 section
, this_set
, delimiter
, level
);
2514 case DW_FORM_implicit_const
:
2515 uvalue
= implicit_const
;
2524 case DW_FORM_ref_addr
:
2526 printf ("%c<%#" PRIx64
">", delimiter
, uvalue
);
2529 case DW_FORM_GNU_ref_alt
:
2533 /* We have already printed the form name. */
2534 printf ("%c<%#" PRIx64
">", delimiter
, uvalue
);
2536 printf ("%c<alt %#" PRIx64
">", delimiter
, uvalue
);
2538 /* FIXME: Follow the reference... */
2544 case DW_FORM_ref_sup4
:
2545 case DW_FORM_ref_udata
:
2547 printf ("%c<%#" PRIx64
">", delimiter
, uvalue
+ cu_offset
);
2552 case DW_FORM_sec_offset
:
2554 printf ("%c%#" PRIx64
, delimiter
, uvalue
);
2557 case DW_FORM_flag_present
:
2563 printf ("%c%" PRId64
, delimiter
, uvalue
);
2568 printf ("%c%" PRIu64
, delimiter
, uvalue
);
2571 case DW_FORM_implicit_const
:
2573 printf ("%c%" PRId64
, delimiter
, implicit_const
);
2576 case DW_FORM_ref_sup8
:
2581 uint64_t utmp
= uvalue
;
2582 if (form
== DW_FORM_ref8
)
2584 printf ("%c%#" PRIx64
, delimiter
, utmp
);
2588 case DW_FORM_data16
:
2592 printf (" %#" PRIx64
, uvalue
);
2594 printf (" %#" PRIx64
"%016" PRIx64
, uvalue_hi
, uvalue
);
2598 case DW_FORM_string
:
2600 printf ("%c%.*s", delimiter
, (int) (end
- data
), data
);
2601 data
+= strnlen ((char *) data
, end
- data
);
2607 case DW_FORM_exprloc
:
2608 READ_ULEB (uvalue
, data
, end
);
2611 if (block_start
>= end
)
2613 warn (_("Block ends prematurely\n"));
2618 uvalue
= check_uvalue (block_start
, uvalue
, end
);
2620 data
= block_start
+ uvalue
;
2625 SAFE_BYTE_GET (op
, block_start
, sizeof (op
), end
);
2626 if (op
!= DW_OP_addrx
)
2627 data
= display_block (block_start
, uvalue
, end
, delimiter
);
2631 case DW_FORM_block1
:
2632 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
2635 case DW_FORM_block2
:
2636 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
2639 case DW_FORM_block4
:
2640 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
2647 /* We have already displayed the form name. */
2648 printf (_("%c(offset: %#" PRIx64
"): %s"),
2649 delimiter
, uvalue
, fetch_indirect_string (uvalue
));
2651 printf (_("%c(indirect string, offset: %#" PRIx64
"): %s"),
2652 delimiter
, uvalue
, fetch_indirect_string (uvalue
));
2656 case DW_FORM_line_strp
:
2660 /* We have already displayed the form name. */
2661 printf (_("%c(offset: %#" PRIx64
"): %s"),
2662 delimiter
, uvalue
, fetch_indirect_line_string (uvalue
));
2664 printf (_("%c(indirect line string, offset: %#" PRIx64
"): %s"),
2665 delimiter
, uvalue
, fetch_indirect_line_string (uvalue
));
2669 case DW_FORM_GNU_str_index
:
2677 const char *suffix
= section
? strrchr (section
->name
, '.') : NULL
;
2678 bool dwo
= suffix
&& strcmp (suffix
, ".dwo") == 0;
2681 strng
= fetch_indexed_string (uvalue
, this_set
, offset_size
, dwo
,
2682 debug_info_p
? debug_info_p
->str_offsets_base
: 0);
2684 /* We have already displayed the form name. */
2685 printf (_("%c(offset: %#" PRIx64
"): %s"),
2686 delimiter
, uvalue
, strng
);
2688 printf (_("%c(indexed string: %#" PRIx64
"): %s"),
2689 delimiter
, uvalue
, strng
);
2693 case DW_FORM_GNU_strp_alt
:
2697 /* We have already displayed the form name. */
2698 printf (_("%c(offset: %#" PRIx64
") %s"),
2699 delimiter
, uvalue
, fetch_alt_indirect_string (uvalue
));
2701 printf (_("%c(alt indirect string, offset: %#" PRIx64
") %s"),
2702 delimiter
, uvalue
, fetch_alt_indirect_string (uvalue
));
2706 case DW_FORM_indirect
:
2707 /* Handled above. */
2710 case DW_FORM_ref_sig8
:
2712 printf ("%c%s: %#" PRIx64
, delimiter
, do_wide
? "" : "signature",
2716 case DW_FORM_GNU_addr_index
:
2718 case DW_FORM_addrx1
:
2719 case DW_FORM_addrx2
:
2720 case DW_FORM_addrx3
:
2721 case DW_FORM_addrx4
:
2722 case DW_FORM_loclistx
:
2723 case DW_FORM_rnglistx
:
2727 const char *suffix
= strrchr (section
->name
, '.');
2728 bool dwo
= suffix
&& strcmp (suffix
, ".dwo") == 0;
2730 if (form
== DW_FORM_loclistx
)
2734 idx
= fetch_indexed_value (uvalue
, loclists_dwo
, 0);
2735 if (idx
!= (uint64_t) -1)
2736 idx
+= (offset_size
== 8) ? 20 : 12;
2738 else if (debug_info_p
== NULL
)
2740 idx
= fetch_indexed_value (uvalue
, loclists
, 0);
2744 /* We want to compute:
2745 idx = fetch_indexed_value (uvalue, loclists, debug_info_p->loclists_base);
2746 idx += debug_info_p->loclists_base;
2747 Fortunately we already have that sum cached in the
2748 loc_offsets array. */
2749 if (uvalue
< debug_info_p
->num_loc_offsets
)
2750 idx
= debug_info_p
->loc_offsets
[uvalue
];
2753 warn (_("loc_offset %" PRIu64
" too big\n"), uvalue
);
2758 else if (form
== DW_FORM_rnglistx
)
2762 idx
= fetch_indexed_value (uvalue
, rnglists_dwo
, 0);
2763 if (idx
!= (uint64_t) -1)
2764 idx
+= (offset_size
== 8) ? 20 : 12;
2768 if (debug_info_p
== NULL
)
2771 base
= debug_info_p
->rnglists_base
;
2772 /* We do not have a cached value this time, so we perform the
2773 computation manually. */
2774 idx
= fetch_indexed_value (uvalue
, rnglists
, base
);
2775 if (idx
!= (uint64_t) -1)
2781 if (debug_info_p
== NULL
)
2783 else if (debug_info_p
->addr_base
== DEBUG_INFO_UNAVAILABLE
)
2786 base
= debug_info_p
->addr_base
;
2788 base
+= uvalue
* pointer_size
;
2789 idx
= fetch_indexed_addr (base
, pointer_size
);
2792 /* We have already displayed the form name. */
2793 if (idx
!= (uint64_t) -1)
2794 printf (_("%c(index: %#" PRIx64
"): %#" PRIx64
),
2795 delimiter
, uvalue
, idx
);
2799 case DW_FORM_strp_sup
:
2801 printf ("%c<%#" PRIx64
">", delimiter
, uvalue
+ cu_offset
);
2805 warn (_("Unrecognized form: %#lx\n"), form
);
2806 /* What to do? Consume a byte maybe? */
2811 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
|| do_debug_info
)
2812 && num_debug_info_entries
== 0
2813 && debug_info_p
!= NULL
)
2817 case DW_AT_loclists_base
:
2818 if (debug_info_p
->loclists_base
)
2819 warn (_("CU @ %#" PRIx64
" has multiple loclists_base values "
2820 "(%#" PRIx64
" and %#" PRIx64
")"),
2821 debug_info_p
->cu_offset
,
2822 debug_info_p
->loclists_base
, uvalue
);
2823 debug_info_p
->loclists_base
= uvalue
;
2825 case DW_AT_rnglists_base
:
2826 if (debug_info_p
->rnglists_base
)
2827 warn (_("CU @ %#" PRIx64
" has multiple rnglists_base values "
2828 "(%#" PRIx64
" and %#" PRIx64
")"),
2829 debug_info_p
->cu_offset
,
2830 debug_info_p
->rnglists_base
, uvalue
);
2831 debug_info_p
->rnglists_base
= uvalue
;
2833 case DW_AT_str_offsets_base
:
2834 if (debug_info_p
->str_offsets_base
)
2835 warn (_("CU @ %#" PRIx64
" has multiple str_offsets_base values "
2836 "%#" PRIx64
" and %#" PRIx64
")"),
2837 debug_info_p
->cu_offset
,
2838 debug_info_p
->str_offsets_base
, uvalue
);
2839 debug_info_p
->str_offsets_base
= uvalue
;
2842 case DW_AT_frame_base
:
2843 have_frame_base
= 1;
2845 case DW_AT_location
:
2846 case DW_AT_GNU_locviews
:
2847 case DW_AT_string_length
:
2848 case DW_AT_return_addr
:
2849 case DW_AT_data_member_location
:
2850 case DW_AT_vtable_elem_location
:
2852 case DW_AT_static_link
:
2853 case DW_AT_use_location
:
2854 case DW_AT_call_value
:
2855 case DW_AT_GNU_call_site_value
:
2856 case DW_AT_call_data_value
:
2857 case DW_AT_GNU_call_site_data_value
:
2858 case DW_AT_call_target
:
2859 case DW_AT_GNU_call_site_target
:
2860 case DW_AT_call_target_clobbered
:
2861 case DW_AT_GNU_call_site_target_clobbered
:
2862 if ((dwarf_version
< 4
2863 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
2864 || form
== DW_FORM_sec_offset
2865 || form
== DW_FORM_loclistx
)
2867 /* Process location list. */
2868 unsigned int lmax
= debug_info_p
->max_loc_offsets
;
2869 unsigned int num
= debug_info_p
->num_loc_offsets
;
2871 if (lmax
== 0 || num
>= lmax
)
2874 debug_info_p
->loc_offsets
= (uint64_t *)
2875 xcrealloc (debug_info_p
->loc_offsets
,
2876 lmax
, sizeof (*debug_info_p
->loc_offsets
));
2877 debug_info_p
->loc_views
= (uint64_t *)
2878 xcrealloc (debug_info_p
->loc_views
,
2879 lmax
, sizeof (*debug_info_p
->loc_views
));
2880 debug_info_p
->have_frame_base
= (int *)
2881 xcrealloc (debug_info_p
->have_frame_base
,
2882 lmax
, sizeof (*debug_info_p
->have_frame_base
));
2883 debug_info_p
->max_loc_offsets
= lmax
;
2885 if (form
== DW_FORM_loclistx
)
2886 uvalue
= fetch_indexed_value (num
, loclists
, debug_info_p
->loclists_base
);
2887 else if (this_set
!= NULL
)
2888 uvalue
+= this_set
->section_offsets
[DW_SECT_LOC
];
2890 debug_info_p
->have_frame_base
[num
] = have_frame_base
;
2891 if (attribute
!= DW_AT_GNU_locviews
)
2893 uvalue
+= debug_info_p
->loclists_base
;
2895 /* Corrupt DWARF info can produce more offsets than views.
2896 See PR 23062 for an example. */
2897 if (debug_info_p
->num_loc_offsets
2898 > debug_info_p
->num_loc_views
)
2899 warn (_("More location offset attributes than DW_AT_GNU_locview attributes\n"));
2902 debug_info_p
->loc_offsets
[num
] = uvalue
;
2903 debug_info_p
->num_loc_offsets
++;
2908 assert (debug_info_p
->num_loc_views
<= num
);
2909 num
= debug_info_p
->num_loc_views
;
2910 if (num
> debug_info_p
->num_loc_offsets
)
2911 warn (_("More DW_AT_GNU_locview attributes than location offset attributes\n"));
2914 debug_info_p
->loc_views
[num
] = uvalue
;
2915 debug_info_p
->num_loc_views
++;
2922 if (need_base_address
)
2923 debug_info_p
->base_address
= uvalue
;
2926 case DW_AT_GNU_addr_base
:
2927 case DW_AT_addr_base
:
2928 debug_info_p
->addr_base
= uvalue
;
2931 case DW_AT_GNU_ranges_base
:
2932 debug_info_p
->ranges_base
= uvalue
;
2936 if ((dwarf_version
< 4
2937 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
2938 || form
== DW_FORM_sec_offset
2939 || form
== DW_FORM_rnglistx
)
2941 /* Process range list. */
2942 unsigned int lmax
= debug_info_p
->max_range_lists
;
2943 unsigned int num
= debug_info_p
->num_range_lists
;
2945 if (lmax
== 0 || num
>= lmax
)
2948 debug_info_p
->range_lists
= (uint64_t *)
2949 xcrealloc (debug_info_p
->range_lists
,
2950 lmax
, sizeof (*debug_info_p
->range_lists
));
2951 debug_info_p
->max_range_lists
= lmax
;
2954 if (form
== DW_FORM_rnglistx
)
2955 uvalue
= fetch_indexed_value (uvalue
, rnglists
, 0);
2957 debug_info_p
->range_lists
[num
] = uvalue
;
2958 debug_info_p
->num_range_lists
++;
2962 case DW_AT_GNU_dwo_name
:
2963 case DW_AT_dwo_name
:
2968 add_dwo_name ((const char *) fetch_indirect_string (uvalue
), cu_offset
);
2970 case DW_FORM_GNU_strp_alt
:
2971 add_dwo_name ((const char *) fetch_alt_indirect_string (uvalue
), cu_offset
);
2973 case DW_FORM_GNU_str_index
:
2979 add_dwo_name (fetch_indexed_string (uvalue
, this_set
, offset_size
, false,
2980 debug_info_p
->str_offsets_base
),
2983 case DW_FORM_string
:
2984 add_dwo_name ((const char *) orig_data
, cu_offset
);
2987 warn (_("Unsupported form (%s) for attribute %s\n"),
2988 get_FORM_name (form
), get_AT_name (attribute
));
2993 case DW_AT_comp_dir
:
2994 /* FIXME: Also extract a build-id in a CU/TU. */
2999 add_dwo_dir ((const char *) fetch_indirect_string (uvalue
), cu_offset
);
3001 case DW_FORM_GNU_strp_alt
:
3002 add_dwo_dir (fetch_alt_indirect_string (uvalue
), cu_offset
);
3004 case DW_FORM_line_strp
:
3005 add_dwo_dir ((const char *) fetch_indirect_line_string (uvalue
), cu_offset
);
3007 case DW_FORM_GNU_str_index
:
3013 add_dwo_dir (fetch_indexed_string (uvalue
, this_set
, offset_size
, false,
3014 debug_info_p
->str_offsets_base
),
3017 case DW_FORM_string
:
3018 add_dwo_dir ((const char *) orig_data
, cu_offset
);
3021 warn (_("Unsupported form (%s) for attribute %s\n"),
3022 get_FORM_name (form
), get_AT_name (attribute
));
3027 case DW_AT_GNU_dwo_id
:
3032 /* FIXME: Record the length of the ID as well ? */
3033 add_dwo_id ((const char *) (data
- 8), cu_offset
);
3036 warn (_("Unsupported form (%s) for attribute %s\n"),
3037 get_FORM_name (form
), get_AT_name (attribute
));
3047 if (do_loc
|| attribute
== 0)
3050 /* For some attributes we can display further information. */
3054 if (level
>= 0 && level
< MAX_CU_NESTING
3055 && uvalue
< (size_t) (end
- start
))
3057 bool is_signed
= false;
3058 abbrev_entry
*type_abbrev
;
3059 unsigned char *type_data
;
3062 type_abbrev
= get_type_abbrev_from_form (form
, uvalue
,
3066 if (type_abbrev
!= NULL
)
3068 get_type_signedness (type_abbrev
, section
, type_data
,
3069 map
? section
->start
+ map
->end
: end
,
3070 map
? map
->start
: cu_offset
,
3071 pointer_size
, offset_size
, dwarf_version
,
3074 level_type_signed
[level
] = is_signed
;
3082 case DW_INL_not_inlined
:
3083 printf (_("(not inlined)"));
3085 case DW_INL_inlined
:
3086 printf (_("(inlined)"));
3088 case DW_INL_declared_not_inlined
:
3089 printf (_("(declared as inline but ignored)"));
3091 case DW_INL_declared_inlined
:
3092 printf (_("(declared as inline and inlined)"));
3095 printf (_(" (Unknown inline attribute value: %#" PRIx64
")"),
3101 case DW_AT_language
:
3105 /* Ordered by the numeric value of these constants. */
3106 case DW_LANG_C89
: printf ("(ANSI C)"); break;
3107 case DW_LANG_C
: printf ("(non-ANSI C)"); break;
3108 case DW_LANG_Ada83
: printf ("(Ada)"); break;
3109 case DW_LANG_C_plus_plus
: printf ("(C++)"); break;
3110 case DW_LANG_Cobol74
: printf ("(Cobol 74)"); break;
3111 case DW_LANG_Cobol85
: printf ("(Cobol 85)"); break;
3112 case DW_LANG_Fortran77
: printf ("(FORTRAN 77)"); break;
3113 case DW_LANG_Fortran90
: printf ("(Fortran 90)"); break;
3114 case DW_LANG_Pascal83
: printf ("(ANSI Pascal)"); break;
3115 case DW_LANG_Modula2
: printf ("(Modula 2)"); break;
3116 /* DWARF 2.1 values. */
3117 case DW_LANG_Java
: printf ("(Java)"); break;
3118 case DW_LANG_C99
: printf ("(ANSI C99)"); break;
3119 case DW_LANG_Ada95
: printf ("(ADA 95)"); break;
3120 case DW_LANG_Fortran95
: printf ("(Fortran 95)"); break;
3121 /* DWARF 3 values. */
3122 case DW_LANG_PLI
: printf ("(PLI)"); break;
3123 case DW_LANG_ObjC
: printf ("(Objective C)"); break;
3124 case DW_LANG_ObjC_plus_plus
: printf ("(Objective C++)"); break;
3125 case DW_LANG_UPC
: printf ("(Unified Parallel C)"); break;
3126 case DW_LANG_D
: printf ("(D)"); break;
3127 /* DWARF 4 values. */
3128 case DW_LANG_Python
: printf ("(Python)"); break;
3129 /* DWARF 5 values. */
3130 case DW_LANG_OpenCL
: printf ("(OpenCL)"); break;
3131 case DW_LANG_Go
: printf ("(Go)"); break;
3132 case DW_LANG_Modula3
: printf ("(Modula 3)"); break;
3133 case DW_LANG_Haskell
: printf ("(Haskell)"); break;
3134 case DW_LANG_C_plus_plus_03
: printf ("(C++03)"); break;
3135 case DW_LANG_C_plus_plus_11
: printf ("(C++11)"); break;
3136 case DW_LANG_OCaml
: printf ("(OCaml)"); break;
3137 case DW_LANG_Rust
: printf ("(Rust)"); break;
3138 case DW_LANG_C11
: printf ("(C11)"); break;
3139 case DW_LANG_Swift
: printf ("(Swift)"); break;
3140 case DW_LANG_Julia
: printf ("(Julia)"); break;
3141 case DW_LANG_Dylan
: printf ("(Dylan)"); break;
3142 case DW_LANG_C_plus_plus_14
: printf ("(C++14)"); break;
3143 case DW_LANG_Fortran03
: printf ("(Fortran 03)"); break;
3144 case DW_LANG_Fortran08
: printf ("(Fortran 08)"); break;
3145 case DW_LANG_RenderScript
: printf ("(RenderScript)"); break;
3146 /* MIPS extension. */
3147 case DW_LANG_Mips_Assembler
: printf ("(MIPS assembler)"); break;
3148 /* UPC extension. */
3149 case DW_LANG_Upc
: printf ("(Unified Parallel C)"); break;
3151 if (uvalue
>= DW_LANG_lo_user
&& uvalue
<= DW_LANG_hi_user
)
3152 printf (_("(implementation defined: %#" PRIx64
")"), uvalue
);
3154 printf (_("(unknown: %#" PRIx64
")"), uvalue
);
3159 case DW_AT_encoding
:
3163 case DW_ATE_void
: printf ("(void)"); break;
3164 case DW_ATE_address
: printf ("(machine address)"); break;
3165 case DW_ATE_boolean
: printf ("(boolean)"); break;
3166 case DW_ATE_complex_float
: printf ("(complex float)"); break;
3167 case DW_ATE_float
: printf ("(float)"); break;
3168 case DW_ATE_signed
: printf ("(signed)"); break;
3169 case DW_ATE_signed_char
: printf ("(signed char)"); break;
3170 case DW_ATE_unsigned
: printf ("(unsigned)"); break;
3171 case DW_ATE_unsigned_char
: printf ("(unsigned char)"); break;
3172 /* DWARF 2.1 values: */
3173 case DW_ATE_imaginary_float
: printf ("(imaginary float)"); break;
3174 case DW_ATE_decimal_float
: printf ("(decimal float)"); break;
3175 /* DWARF 3 values: */
3176 case DW_ATE_packed_decimal
: printf ("(packed_decimal)"); break;
3177 case DW_ATE_numeric_string
: printf ("(numeric_string)"); break;
3178 case DW_ATE_edited
: printf ("(edited)"); break;
3179 case DW_ATE_signed_fixed
: printf ("(signed_fixed)"); break;
3180 case DW_ATE_unsigned_fixed
: printf ("(unsigned_fixed)"); break;
3181 /* DWARF 4 values: */
3182 case DW_ATE_UTF
: printf ("(unicode string)"); break;
3183 /* DWARF 5 values: */
3184 case DW_ATE_UCS
: printf ("(UCS)"); break;
3185 case DW_ATE_ASCII
: printf ("(ASCII)"); break;
3187 /* HP extensions: */
3188 case DW_ATE_HP_float80
: printf ("(HP_float80)"); break;
3189 case DW_ATE_HP_complex_float80
: printf ("(HP_complex_float80)"); break;
3190 case DW_ATE_HP_float128
: printf ("(HP_float128)"); break;
3191 case DW_ATE_HP_complex_float128
:printf ("(HP_complex_float128)"); break;
3192 case DW_ATE_HP_floathpintel
: printf ("(HP_floathpintel)"); break;
3193 case DW_ATE_HP_imaginary_float80
: printf ("(HP_imaginary_float80)"); break;
3194 case DW_ATE_HP_imaginary_float128
: printf ("(HP_imaginary_float128)"); break;
3197 if (uvalue
>= DW_ATE_lo_user
3198 && uvalue
<= DW_ATE_hi_user
)
3199 printf (_("(user defined type)"));
3201 printf (_("(unknown type)"));
3206 case DW_AT_accessibility
:
3210 case DW_ACCESS_public
: printf ("(public)"); break;
3211 case DW_ACCESS_protected
: printf ("(protected)"); break;
3212 case DW_ACCESS_private
: printf ("(private)"); break;
3214 printf (_("(unknown accessibility)"));
3219 case DW_AT_visibility
:
3223 case DW_VIS_local
: printf ("(local)"); break;
3224 case DW_VIS_exported
: printf ("(exported)"); break;
3225 case DW_VIS_qualified
: printf ("(qualified)"); break;
3226 default: printf (_("(unknown visibility)")); break;
3230 case DW_AT_endianity
:
3234 case DW_END_default
: printf ("(default)"); break;
3235 case DW_END_big
: printf ("(big)"); break;
3236 case DW_END_little
: printf ("(little)"); break;
3238 if (uvalue
>= DW_END_lo_user
&& uvalue
<= DW_END_hi_user
)
3239 printf (_("(user specified)"));
3241 printf (_("(unknown endianity)"));
3246 case DW_AT_virtuality
:
3250 case DW_VIRTUALITY_none
: printf ("(none)"); break;
3251 case DW_VIRTUALITY_virtual
: printf ("(virtual)"); break;
3252 case DW_VIRTUALITY_pure_virtual
:printf ("(pure_virtual)"); break;
3253 default: printf (_("(unknown virtuality)")); break;
3257 case DW_AT_identifier_case
:
3261 case DW_ID_case_sensitive
: printf ("(case_sensitive)"); break;
3262 case DW_ID_up_case
: printf ("(up_case)"); break;
3263 case DW_ID_down_case
: printf ("(down_case)"); break;
3264 case DW_ID_case_insensitive
: printf ("(case_insensitive)"); break;
3265 default: printf (_("(unknown case)")); break;
3269 case DW_AT_calling_convention
:
3273 case DW_CC_normal
: printf ("(normal)"); break;
3274 case DW_CC_program
: printf ("(program)"); break;
3275 case DW_CC_nocall
: printf ("(nocall)"); break;
3276 case DW_CC_pass_by_reference
: printf ("(pass by ref)"); break;
3277 case DW_CC_pass_by_value
: printf ("(pass by value)"); break;
3278 case DW_CC_GNU_renesas_sh
: printf ("(Rensas SH)"); break;
3279 case DW_CC_GNU_borland_fastcall_i386
: printf ("(Borland fastcall i386)"); break;
3281 if (uvalue
>= DW_CC_lo_user
3282 && uvalue
<= DW_CC_hi_user
)
3283 printf (_("(user defined)"));
3285 printf (_("(unknown convention)"));
3289 case DW_AT_ordering
:
3294 case -1: printf (_("(undefined)")); break;
3295 case 0: printf ("(row major)"); break;
3296 case 1: printf ("(column major)"); break;
3300 case DW_AT_decimal_sign
:
3304 case DW_DS_unsigned
: printf (_("(unsigned)")); break;
3305 case DW_DS_leading_overpunch
: printf (_("(leading overpunch)")); break;
3306 case DW_DS_trailing_overpunch
: printf (_("(trailing overpunch)")); break;
3307 case DW_DS_leading_separate
: printf (_("(leading separate)")); break;
3308 case DW_DS_trailing_separate
: printf (_("(trailing separate)")); break;
3309 default: printf (_("(unrecognised)")); break;
3313 case DW_AT_defaulted
:
3317 case DW_DEFAULTED_no
: printf (_("(no)")); break;
3318 case DW_DEFAULTED_in_class
: printf (_("(in class)")); break;
3319 case DW_DEFAULTED_out_of_class
: printf (_("(out of class)")); break;
3320 default: printf (_("(unrecognised)")); break;
3324 case DW_AT_discr_list
:
3326 display_discr_list (form
, uvalue
, data
, level
);
3329 case DW_AT_frame_base
:
3330 have_frame_base
= 1;
3332 case DW_AT_location
:
3333 case DW_AT_loclists_base
:
3334 case DW_AT_rnglists_base
:
3335 case DW_AT_str_offsets_base
:
3336 case DW_AT_string_length
:
3337 case DW_AT_return_addr
:
3338 case DW_AT_data_member_location
:
3339 case DW_AT_vtable_elem_location
:
3341 case DW_AT_static_link
:
3342 case DW_AT_use_location
:
3343 case DW_AT_call_value
:
3344 case DW_AT_GNU_call_site_value
:
3345 case DW_AT_call_data_value
:
3346 case DW_AT_GNU_call_site_data_value
:
3347 case DW_AT_call_target
:
3348 case DW_AT_GNU_call_site_target
:
3349 case DW_AT_call_target_clobbered
:
3350 case DW_AT_GNU_call_site_target_clobbered
:
3351 if ((dwarf_version
< 4
3352 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
3353 || form
== DW_FORM_sec_offset
3354 || form
== DW_FORM_loclistx
)
3356 if (attribute
!= DW_AT_rnglists_base
3357 && attribute
!= DW_AT_str_offsets_base
)
3358 printf (_(" (location list)"));
3361 case DW_AT_allocated
:
3362 case DW_AT_associated
:
3363 case DW_AT_data_location
:
3365 case DW_AT_upper_bound
:
3366 case DW_AT_lower_bound
:
3370 int need_frame_base
;
3373 need_frame_base
= decode_location_expression (block_start
,
3378 cu_offset
, section
);
3380 if (need_frame_base
&& !have_frame_base
)
3381 printf (_(" [without DW_AT_frame_base]"));
3385 case DW_AT_data_bit_offset
:
3386 case DW_AT_byte_size
:
3387 case DW_AT_bit_size
:
3388 case DW_AT_string_length_byte_size
:
3389 case DW_AT_string_length_bit_size
:
3390 case DW_AT_bit_stride
:
3391 if (form
== DW_FORM_exprloc
)
3394 (void) decode_location_expression (block_start
, pointer_size
,
3395 offset_size
, dwarf_version
,
3396 uvalue
, cu_offset
, section
);
3403 unsigned long abbrev_number
;
3404 abbrev_entry
*entry
;
3406 entry
= get_type_abbrev_from_form (form
, uvalue
, cu_offset
, end
,
3407 section
, & abbrev_number
, NULL
, NULL
);
3410 if (form
!= DW_FORM_GNU_ref_alt
)
3411 warn (_("Offset %#" PRIx64
" used as value for DW_AT_import attribute of DIE at offset %#tx is too big.\n"),
3413 orig_data
- section
->start
);
3417 printf (_("\t[Abbrev Number: %ld"), abbrev_number
);
3418 printf (" (%s)", get_TAG_name (entry
->tag
));
3431 static unsigned char *
3432 read_and_display_attr (unsigned long attribute
,
3434 int64_t implicit_const
,
3435 unsigned char *start
,
3436 unsigned char *data
,
3439 uint64_t pointer_size
,
3440 uint64_t offset_size
,
3442 debug_info
*debug_info_p
,
3444 struct dwarf_section
*section
,
3445 struct cu_tu_set
*this_set
,
3449 printf (" %-18s:", get_AT_name (attribute
));
3450 data
= read_and_display_attr_value (attribute
, form
, implicit_const
,
3452 cu_offset
, pointer_size
, offset_size
,
3453 dwarf_version
, debug_info_p
,
3454 do_loc
, section
, this_set
, ' ', level
);
3460 /* Like load_debug_section, but if the ordinary call fails, and we are
3461 following debug links, then attempt to load the requested section
3462 from one of the separate debug info files. */
3465 load_debug_section_with_follow (enum dwarf_section_display_enum sec_enum
,
3468 if (load_debug_section (sec_enum
, handle
))
3470 if (debug_displays
[sec_enum
].section
.filename
== NULL
)
3472 /* See if we can associate a filename with this section. */
3475 for (i
= first_separate_info
; i
!= NULL
; i
= i
->next
)
3476 if (i
->handle
== handle
)
3478 debug_displays
[sec_enum
].section
.filename
= i
->filename
;
3486 if (do_follow_links
)
3490 for (i
= first_separate_info
; i
!= NULL
; i
= i
->next
)
3492 if (load_debug_section (sec_enum
, i
->handle
))
3494 debug_displays
[sec_enum
].section
.filename
= i
->filename
;
3496 /* FIXME: We should check to see if any of the remaining debug info
3497 files also contain this section, and, umm, do something about it. */
3507 introduce (struct dwarf_section
* section
, bool raw
)
3511 if (do_follow_links
&& section
->filename
)
3512 printf (_("Raw dump of debug contents of section %s (loaded from %s):\n\n"),
3513 section
->name
, section
->filename
);
3515 printf (_("Raw dump of debug contents of section %s:\n\n"), section
->name
);
3519 if (do_follow_links
&& section
->filename
)
3520 printf (_("Contents of the %s section (loaded from %s):\n\n"),
3521 section
->name
, section
->filename
);
3523 printf (_("Contents of the %s section:\n\n"), section
->name
);
3527 /* Free memory allocated for one unit in debug_information. */
3530 free_debug_information (debug_info
*ent
)
3532 if (ent
->max_loc_offsets
)
3534 free (ent
->loc_offsets
);
3535 free (ent
->loc_views
);
3536 free (ent
->have_frame_base
);
3538 if (ent
->max_range_lists
)
3539 free (ent
->range_lists
);
3542 /* Process the contents of a .debug_info section.
3543 If do_loc is TRUE then we are scanning for location lists and dwo tags
3544 and we do not want to display anything to the user.
3545 If do_types is TRUE, we are processing a .debug_types section instead of
3546 a .debug_info section.
3547 The information displayed is restricted by the values in DWARF_START_DIE
3548 and DWARF_CUTOFF_LEVEL.
3549 Returns TRUE upon success. Otherwise an error or warning message is
3550 printed and FALSE is returned. */
3553 process_debug_info (struct dwarf_section
* section
,
3555 enum dwarf_section_display_enum abbrev_sec
,
3559 unsigned char *start
= section
->start
;
3560 unsigned char *end
= start
+ section
->size
;
3561 unsigned char *section_begin
;
3563 unsigned int num_units
= 0;
3565 /* First scan the section to get the number of comp units.
3566 Length sanity checks are done here. */
3567 for (section_begin
= start
, num_units
= 0; section_begin
< end
;
3572 /* Read the first 4 bytes. For a 32-bit DWARF section, this
3573 will be the length. For a 64-bit DWARF section, it'll be
3574 the escape code 0xffffffff followed by an 8 byte length. */
3575 SAFE_BYTE_GET_AND_INC (length
, section_begin
, 4, end
);
3577 if (length
== 0xffffffff)
3578 SAFE_BYTE_GET_AND_INC (length
, section_begin
, 8, end
);
3579 else if (length
>= 0xfffffff0 && length
< 0xffffffff)
3581 warn (_("Reserved length value (%#" PRIx64
") found in section %s\n"),
3582 length
, section
->name
);
3586 /* Negative values are illegal, they may even cause infinite
3587 looping. This can happen if we can't accurately apply
3588 relocations to an object file, or if the file is corrupt. */
3589 if (length
> (size_t) (end
- section_begin
))
3591 warn (_("Corrupt unit length (got %#" PRIx64
3592 " expected at most %#tx) in section %s\n"),
3593 length
, end
- section_begin
, section
->name
);
3596 section_begin
+= length
;
3601 error (_("No comp units in %s section ?\n"), section
->name
);
3605 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
|| do_debug_info
)
3606 && num_debug_info_entries
== 0
3610 /* Then allocate an array to hold the information. */
3611 debug_information
= (debug_info
*) cmalloc (num_units
,
3612 sizeof (* debug_information
));
3613 if (debug_information
== NULL
)
3615 error (_("Not enough memory for a debug info array of %u entries\n"),
3617 alloc_num_debug_info_entries
= num_debug_info_entries
= 0;
3621 /* PR 17531: file: 92ca3797.
3622 We cannot rely upon the debug_information array being initialised
3623 before it is used. A corrupt file could easily contain references
3624 to a unit for which information has not been made available. So
3625 we ensure that the array is zeroed here. */
3626 memset (debug_information
, 0, num_units
* sizeof (*debug_information
));
3628 alloc_num_debug_info_entries
= num_units
;
3633 load_debug_section_with_follow (str
, file
);
3634 load_debug_section_with_follow (line_str
, file
);
3635 load_debug_section_with_follow (str_dwo
, file
);
3636 load_debug_section_with_follow (str_index
, file
);
3637 load_debug_section_with_follow (str_index_dwo
, file
);
3638 load_debug_section_with_follow (debug_addr
, file
);
3641 load_debug_section_with_follow (abbrev_sec
, file
);
3642 load_debug_section_with_follow (loclists
, file
);
3643 load_debug_section_with_follow (rnglists
, file
);
3644 load_debug_section_with_follow (loclists_dwo
, file
);
3645 load_debug_section_with_follow (rnglists_dwo
, file
);
3647 if (debug_displays
[abbrev_sec
].section
.start
== NULL
)
3649 warn (_("Unable to locate %s section!\n"),
3650 debug_displays
[abbrev_sec
].section
.uncompressed_name
);
3654 if (!do_loc
&& dwarf_start_die
== 0)
3655 introduce (section
, false);
3657 free_all_abbrevs ();
3659 /* In order to be able to resolve DW_FORM_ref_addr forms we need
3660 to load *all* of the abbrevs for all CUs in this .debug_info
3661 section. This does effectively mean that we (partially) read
3662 every CU header twice. */
3663 for (section_begin
= start
; start
< end
;)
3665 DWARF2_Internal_CompUnit compunit
;
3666 unsigned char *hdrptr
;
3667 uint64_t abbrev_base
;
3670 unsigned int offset_size
;
3671 struct cu_tu_set
*this_set
;
3672 unsigned char *end_cu
;
3675 cu_offset
= start
- section_begin
;
3677 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 4, end
);
3679 if (compunit
.cu_length
== 0xffffffff)
3681 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 8, end
);
3686 end_cu
= hdrptr
+ compunit
.cu_length
;
3688 SAFE_BYTE_GET_AND_INC (compunit
.cu_version
, hdrptr
, 2, end_cu
);
3690 this_set
= find_cu_tu_set_v2 (cu_offset
, do_types
);
3692 if (compunit
.cu_version
< 5)
3694 compunit
.cu_unit_type
= DW_UT_compile
;
3695 /* Initialize it due to a false compiler warning. */
3696 compunit
.cu_pointer_size
= -1;
3700 SAFE_BYTE_GET_AND_INC (compunit
.cu_unit_type
, hdrptr
, 1, end_cu
);
3701 do_types
= (compunit
.cu_unit_type
== DW_UT_type
);
3703 SAFE_BYTE_GET_AND_INC (compunit
.cu_pointer_size
, hdrptr
, 1, end_cu
);
3706 SAFE_BYTE_GET_AND_INC (compunit
.cu_abbrev_offset
, hdrptr
, offset_size
,
3709 if (compunit
.cu_unit_type
== DW_UT_split_compile
3710 || compunit
.cu_unit_type
== DW_UT_skeleton
)
3713 SAFE_BYTE_GET_AND_INC (dwo_id
, hdrptr
, 8, end_cu
);
3716 if (this_set
== NULL
)
3719 abbrev_size
= debug_displays
[abbrev_sec
].section
.size
;
3723 abbrev_base
= this_set
->section_offsets
[DW_SECT_ABBREV
];
3724 abbrev_size
= this_set
->section_sizes
[DW_SECT_ABBREV
];
3728 abbrev_list
*free_list
;
3729 list
= find_and_process_abbrev_set (&debug_displays
[abbrev_sec
].section
,
3730 abbrev_base
, abbrev_size
,
3731 compunit
.cu_abbrev_offset
,
3734 if (list
!= NULL
&& list
->first_abbrev
!= NULL
)
3735 record_abbrev_list_for_cu (cu_offset
, start
- section_begin
,
3737 else if (free_list
!= NULL
)
3738 free_abbrev_list (free_list
);
3741 for (start
= section_begin
, unit
= 0; start
< end
; unit
++)
3743 DWARF2_Internal_CompUnit compunit
;
3744 unsigned char *hdrptr
;
3745 unsigned char *tags
;
3746 int level
, last_level
, saved_level
;
3748 unsigned int offset_size
;
3749 uint64_t signature
= 0;
3750 uint64_t type_offset
= 0;
3751 struct cu_tu_set
*this_set
;
3752 uint64_t abbrev_base
;
3754 unsigned char *end_cu
;
3757 cu_offset
= start
- section_begin
;
3759 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 4, end
);
3761 if (compunit
.cu_length
== 0xffffffff)
3763 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 8, end
);
3768 end_cu
= hdrptr
+ compunit
.cu_length
;
3770 SAFE_BYTE_GET_AND_INC (compunit
.cu_version
, hdrptr
, 2, end_cu
);
3772 this_set
= find_cu_tu_set_v2 (cu_offset
, do_types
);
3774 if (compunit
.cu_version
< 5)
3776 compunit
.cu_unit_type
= DW_UT_compile
;
3777 /* Initialize it due to a false compiler warning. */
3778 compunit
.cu_pointer_size
= -1;
3782 SAFE_BYTE_GET_AND_INC (compunit
.cu_unit_type
, hdrptr
, 1, end_cu
);
3783 do_types
= (compunit
.cu_unit_type
== DW_UT_type
);
3785 SAFE_BYTE_GET_AND_INC (compunit
.cu_pointer_size
, hdrptr
, 1, end_cu
);
3788 SAFE_BYTE_GET_AND_INC (compunit
.cu_abbrev_offset
, hdrptr
, offset_size
, end_cu
);
3790 if (this_set
== NULL
)
3793 abbrev_size
= debug_displays
[abbrev_sec
].section
.size
;
3797 abbrev_base
= this_set
->section_offsets
[DW_SECT_ABBREV
];
3798 abbrev_size
= this_set
->section_sizes
[DW_SECT_ABBREV
];
3801 if (compunit
.cu_version
< 5)
3802 SAFE_BYTE_GET_AND_INC (compunit
.cu_pointer_size
, hdrptr
, 1, end_cu
);
3804 bool do_dwo_id
= false;
3805 uint64_t dwo_id
= 0;
3806 if (compunit
.cu_unit_type
== DW_UT_split_compile
3807 || compunit
.cu_unit_type
== DW_UT_skeleton
)
3809 SAFE_BYTE_GET_AND_INC (dwo_id
, hdrptr
, 8, end_cu
);
3813 /* PR 17512: file: 001-108546-0.001:0.1. */
3814 if (compunit
.cu_pointer_size
< 2 || compunit
.cu_pointer_size
> 8)
3816 warn (_("Invalid pointer size (%d) in compunit header, using %d instead\n"),
3817 compunit
.cu_pointer_size
, offset_size
);
3818 compunit
.cu_pointer_size
= offset_size
;
3823 SAFE_BYTE_GET_AND_INC (signature
, hdrptr
, 8, end_cu
);
3824 SAFE_BYTE_GET_AND_INC (type_offset
, hdrptr
, offset_size
, end_cu
);
3827 if (dwarf_start_die
>= (size_t) (end_cu
- section_begin
))
3833 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
|| do_debug_info
)
3834 && num_debug_info_entries
== 0
3835 && alloc_num_debug_info_entries
> unit
3838 free_debug_information (&debug_information
[unit
]);
3839 memset (&debug_information
[unit
], 0, sizeof (*debug_information
));
3840 debug_information
[unit
].pointer_size
= compunit
.cu_pointer_size
;
3841 debug_information
[unit
].offset_size
= offset_size
;
3842 debug_information
[unit
].dwarf_version
= compunit
.cu_version
;
3843 debug_information
[unit
].cu_offset
= cu_offset
;
3844 debug_information
[unit
].addr_base
= DEBUG_INFO_UNAVAILABLE
;
3845 debug_information
[unit
].ranges_base
= DEBUG_INFO_UNAVAILABLE
;
3848 if (!do_loc
&& dwarf_start_die
== 0)
3850 printf (_(" Compilation Unit @ offset %#" PRIx64
":\n"),
3852 printf (_(" Length: %#" PRIx64
" (%s)\n"),
3854 offset_size
== 8 ? "64-bit" : "32-bit");
3855 printf (_(" Version: %d\n"), compunit
.cu_version
);
3856 if (compunit
.cu_version
>= 5)
3858 const char *name
= get_DW_UT_name (compunit
.cu_unit_type
);
3860 printf (_(" Unit Type: %s (%x)\n"),
3862 compunit
.cu_unit_type
);
3864 printf (_(" Abbrev Offset: %#" PRIx64
"\n"),
3865 compunit
.cu_abbrev_offset
);
3866 printf (_(" Pointer Size: %d\n"), compunit
.cu_pointer_size
);
3869 printf (_(" Signature: %#" PRIx64
"\n"), signature
);
3870 printf (_(" Type Offset: %#" PRIx64
"\n"), type_offset
);
3873 printf (_(" DWO ID: %#" PRIx64
"\n"), dwo_id
);
3874 if (this_set
!= NULL
)
3876 uint64_t *offsets
= this_set
->section_offsets
;
3877 size_t *sizes
= this_set
->section_sizes
;
3879 printf (_(" Section contributions:\n"));
3880 printf (_(" .debug_abbrev.dwo: %#" PRIx64
" %#zx\n"),
3881 offsets
[DW_SECT_ABBREV
], sizes
[DW_SECT_ABBREV
]);
3882 printf (_(" .debug_line.dwo: %#" PRIx64
" %#zx\n"),
3883 offsets
[DW_SECT_LINE
], sizes
[DW_SECT_LINE
]);
3884 printf (_(" .debug_loc.dwo: %#" PRIx64
" %#zx\n"),
3885 offsets
[DW_SECT_LOC
], sizes
[DW_SECT_LOC
]);
3886 printf (_(" .debug_str_offsets.dwo: %#" PRIx64
" %#zx\n"),
3887 offsets
[DW_SECT_STR_OFFSETS
], sizes
[DW_SECT_STR_OFFSETS
]);
3894 if (compunit
.cu_version
< 2 || compunit
.cu_version
> 5)
3896 warn (_("CU at offset %#" PRIx64
" contains corrupt or "
3897 "unsupported version number: %d.\n"),
3898 cu_offset
, compunit
.cu_version
);
3902 if (compunit
.cu_unit_type
!= DW_UT_compile
3903 && compunit
.cu_unit_type
!= DW_UT_partial
3904 && compunit
.cu_unit_type
!= DW_UT_type
3905 && compunit
.cu_unit_type
!= DW_UT_split_compile
3906 && compunit
.cu_unit_type
!= DW_UT_skeleton
)
3908 warn (_("CU at offset %#" PRIx64
" contains corrupt or "
3909 "unsupported unit type: %d.\n"),
3910 cu_offset
, compunit
.cu_unit_type
);
3914 /* Process the abbrevs used by this compilation unit. */
3916 list
= find_and_process_abbrev_set (&debug_displays
[abbrev_sec
].section
,
3917 abbrev_base
, abbrev_size
,
3918 compunit
.cu_abbrev_offset
, NULL
);
3922 while (tags
< start
)
3924 unsigned long abbrev_number
;
3925 unsigned long die_offset
;
3926 abbrev_entry
*entry
;
3928 int do_printing
= 1;
3930 die_offset
= tags
- section_begin
;
3932 READ_ULEB (abbrev_number
, tags
, start
);
3934 /* A null DIE marks the end of a list of siblings or it may also be
3935 a section padding. */
3936 if (abbrev_number
== 0)
3938 /* Check if it can be a section padding for the last CU. */
3939 if (level
== 0 && start
== end
)
3943 for (chk
= tags
; chk
< start
; chk
++)
3950 if (!do_loc
&& die_offset
>= dwarf_start_die
3951 && (dwarf_cutoff_level
== -1
3952 || level
< dwarf_cutoff_level
))
3953 printf (_(" <%d><%lx>: Abbrev Number: 0\n"),
3959 static unsigned num_bogus_warns
= 0;
3961 if (num_bogus_warns
< 3)
3963 warn (_("Bogus end-of-siblings marker detected at offset %lx in %s section\n"),
3964 die_offset
, section
->name
);
3966 if (num_bogus_warns
== 3)
3967 warn (_("Further warnings about bogus end-of-sibling markers suppressed\n"));
3970 if (dwarf_start_die
!= 0 && level
< saved_level
)
3977 if (dwarf_start_die
!= 0 && die_offset
< dwarf_start_die
)
3981 if (dwarf_start_die
!= 0 && die_offset
== dwarf_start_die
)
3982 saved_level
= level
;
3983 do_printing
= (dwarf_cutoff_level
== -1
3984 || level
< dwarf_cutoff_level
);
3986 printf (_(" <%d><%lx>: Abbrev Number: %lu"),
3987 level
, die_offset
, abbrev_number
);
3988 else if (dwarf_cutoff_level
== -1
3989 || last_level
< dwarf_cutoff_level
)
3990 printf (_(" <%d><%lx>: ...\n"), level
, die_offset
);
3995 /* Scan through the abbreviation list until we reach the
3999 for (entry
= list
->first_abbrev
; entry
!= NULL
; entry
= entry
->next
)
4000 if (entry
->number
== abbrev_number
)
4005 if (!do_loc
&& do_printing
)
4010 warn (_("DIE at offset %#lx refers to abbreviation number %lu which does not exist\n"),
4011 die_offset
, abbrev_number
);
4015 if (!do_loc
&& do_printing
)
4016 printf (" (%s)\n", get_TAG_name (entry
->tag
));
4021 need_base_address
= 0;
4023 case DW_TAG_compile_unit
:
4024 case DW_TAG_skeleton_unit
:
4025 need_base_address
= 1;
4026 need_dwo_info
= do_loc
;
4028 case DW_TAG_entry_point
:
4029 case DW_TAG_subprogram
:
4030 need_base_address
= 0;
4031 /* Assuming that there is no DW_AT_frame_base. */
4032 have_frame_base
= 0;
4036 debug_info
*debug_info_p
=
4037 (debug_information
&& unit
< alloc_num_debug_info_entries
)
4038 ? debug_information
+ unit
: NULL
;
4040 assert (!debug_info_p
4041 || (debug_info_p
->num_loc_offsets
4042 == debug_info_p
->num_loc_views
));
4044 for (attr
= entry
->first_attr
;
4045 attr
&& attr
->attribute
;
4048 if (! do_loc
&& do_printing
)
4049 /* Show the offset from where the tag was extracted. */
4050 printf (" <%tx>", tags
- section_begin
);
4051 tags
= read_and_display_attr (attr
->attribute
,
4053 attr
->implicit_const
,
4058 compunit
.cu_pointer_size
,
4060 compunit
.cu_version
,
4062 do_loc
|| ! do_printing
,
4068 /* If a locview attribute appears before a location one,
4069 make sure we don't associate it with an earlier
4072 switch (debug_info_p
->num_loc_offsets
- debug_info_p
->num_loc_views
)
4075 debug_info_p
->loc_views
[debug_info_p
->num_loc_views
] = -1;
4076 debug_info_p
->num_loc_views
++;
4077 assert (debug_info_p
->num_loc_views
4078 == debug_info_p
->num_loc_offsets
);
4085 warn(_("DIE has locviews without loclist\n"));
4086 debug_info_p
->num_loc_views
--;
4093 if (entry
->children
)
4097 free_abbrev_list (list
);
4100 /* Set num_debug_info_entries here so that it can be used to check if
4101 we need to process .debug_loc and .debug_ranges sections. */
4102 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
|| do_debug_info
)
4103 && num_debug_info_entries
== 0
4106 if (num_units
> alloc_num_debug_info_entries
)
4107 num_debug_info_entries
= alloc_num_debug_info_entries
;
4109 num_debug_info_entries
= num_units
;
4118 /* Locate and scan the .debug_info section in the file and record the pointer
4119 sizes and offsets for the compilation units in it. Usually an executable
4120 will have just one pointer size, but this is not guaranteed, and so we try
4121 not to make any assumptions. Returns zero upon failure, or the number of
4122 compilation units upon success. */
4125 load_debug_info (void * file
)
4127 /* If we have already tried and failed to load the .debug_info
4128 section then do not bother to repeat the task. */
4129 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
4132 /* If we already have the information there is nothing else to do. */
4133 if (num_debug_info_entries
> 0)
4134 return num_debug_info_entries
;
4136 /* If this is a DWARF package file, load the CU and TU indexes. */
4137 (void) load_cu_tu_indexes (file
);
4139 if (load_debug_section_with_follow (info
, file
)
4140 && process_debug_info (&debug_displays
[info
].section
, file
, abbrev
, true, false))
4141 return num_debug_info_entries
;
4143 if (load_debug_section_with_follow (info_dwo
, file
)
4144 && process_debug_info (&debug_displays
[info_dwo
].section
, file
,
4145 abbrev_dwo
, true, false))
4146 return num_debug_info_entries
;
4148 num_debug_info_entries
= DEBUG_INFO_UNAVAILABLE
;
4152 /* Read a DWARF .debug_line section header starting at DATA.
4153 Upon success returns an updated DATA pointer and the LINFO
4154 structure and the END_OF_SEQUENCE pointer will be filled in.
4155 Otherwise returns NULL. */
4157 static unsigned char *
4158 read_debug_line_header (struct dwarf_section
* section
,
4159 unsigned char * data
,
4160 unsigned char * end
,
4161 DWARF2_Internal_LineInfo
* linfo
,
4162 unsigned char ** end_of_sequence
)
4164 unsigned char *hdrptr
;
4166 /* Extract information from the Line Number Program Header.
4167 (section 6.2.4 in the Dwarf3 doc). */
4170 /* Get and check the length of the block. */
4171 SAFE_BYTE_GET_AND_INC (linfo
->li_length
, hdrptr
, 4, end
);
4173 if (linfo
->li_length
== 0xffffffff)
4175 /* This section is 64-bit DWARF 3. */
4176 SAFE_BYTE_GET_AND_INC (linfo
->li_length
, hdrptr
, 8, end
);
4177 linfo
->li_offset_size
= 8;
4180 linfo
->li_offset_size
= 4;
4182 if (linfo
->li_length
> (size_t) (end
- hdrptr
))
4184 /* If the length field has a relocation against it, then we should
4185 not complain if it is inaccurate (and probably negative). This
4186 happens in object files when the .debug_line section is actually
4187 comprised of several different .debug_line.* sections, (some of
4188 which may be removed by linker garbage collection), and a relocation
4189 is used to compute the correct length once that is done. */
4190 if (reloc_at (section
, (hdrptr
- section
->start
) - linfo
->li_offset_size
))
4192 linfo
->li_length
= end
- hdrptr
;
4196 warn (_("The length field (%#" PRIx64
")"
4197 " in the debug_line header is wrong"
4198 " - the section is too small\n"),
4203 end
= hdrptr
+ linfo
->li_length
;
4205 /* Get and check the version number. */
4206 SAFE_BYTE_GET_AND_INC (linfo
->li_version
, hdrptr
, 2, end
);
4208 if (linfo
->li_version
!= 2
4209 && linfo
->li_version
!= 3
4210 && linfo
->li_version
!= 4
4211 && linfo
->li_version
!= 5)
4213 warn (_("Only DWARF version 2, 3, 4 and 5 line info "
4214 "is currently supported.\n"));
4218 if (linfo
->li_version
>= 5)
4220 SAFE_BYTE_GET_AND_INC (linfo
->li_address_size
, hdrptr
, 1, end
);
4222 SAFE_BYTE_GET_AND_INC (linfo
->li_segment_size
, hdrptr
, 1, end
);
4223 if (linfo
->li_segment_size
!= 0)
4225 warn (_("The %s section contains "
4226 "unsupported segment selector size: %d.\n"),
4227 section
->name
, linfo
->li_segment_size
);
4232 SAFE_BYTE_GET_AND_INC (linfo
->li_prologue_length
, hdrptr
,
4233 linfo
->li_offset_size
, end
);
4234 SAFE_BYTE_GET_AND_INC (linfo
->li_min_insn_length
, hdrptr
, 1, end
);
4236 if (linfo
->li_version
>= 4)
4238 SAFE_BYTE_GET_AND_INC (linfo
->li_max_ops_per_insn
, hdrptr
, 1, end
);
4240 if (linfo
->li_max_ops_per_insn
== 0)
4242 warn (_("Invalid maximum operations per insn.\n"));
4247 linfo
->li_max_ops_per_insn
= 1;
4249 SAFE_BYTE_GET_AND_INC (linfo
->li_default_is_stmt
, hdrptr
, 1, end
);
4250 SAFE_SIGNED_BYTE_GET_AND_INC (linfo
->li_line_base
, hdrptr
, 1, end
);
4251 SAFE_BYTE_GET_AND_INC (linfo
->li_line_range
, hdrptr
, 1, end
);
4252 SAFE_BYTE_GET_AND_INC (linfo
->li_opcode_base
, hdrptr
, 1, end
);
4254 *end_of_sequence
= end
;
4258 static unsigned char *
4259 display_formatted_table (unsigned char *data
,
4260 unsigned char *start
,
4262 const DWARF2_Internal_LineInfo
*linfo
,
4263 struct dwarf_section
*section
,
4266 unsigned char *format_start
, format_count
, *format
, formati
;
4267 uint64_t data_count
, datai
;
4268 unsigned int namepass
, last_entry
= 0;
4269 const char * table_name
= is_dir
? N_("Directory Table") : N_("File Name Table");
4271 SAFE_BYTE_GET_AND_INC (format_count
, data
, 1, end
);
4272 if (do_checks
&& format_count
> 5)
4273 warn (_("Unexpectedly large number of columns in the %s (%u)\n"),
4274 table_name
, format_count
);
4276 format_start
= data
;
4277 for (formati
= 0; formati
< format_count
; formati
++)
4279 SKIP_ULEB (data
, end
);
4280 SKIP_ULEB (data
, end
);
4283 warn (_("%s: Corrupt format description entry\n"), table_name
);
4288 READ_ULEB (data_count
, data
, end
);
4289 if (data_count
== 0)
4291 printf (_("\n The %s is empty.\n"), table_name
);
4294 else if (data
>= end
)
4296 warn (_("%s: Corrupt entry count - expected %#" PRIx64
4297 " but none found\n"), table_name
, data_count
);
4301 else if (format_count
== 0)
4303 warn (_("%s: format count is zero, but the table is not empty\n"),
4308 printf (_("\n The %s (offset %#tx, lines %" PRIu64
", columns %u):\n"),
4309 table_name
, data
- start
, data_count
, format_count
);
4311 printf (_(" Entry"));
4312 /* Delay displaying name as the last entry for better screen layout. */
4313 for (namepass
= 0; namepass
< 2; namepass
++)
4315 format
= format_start
;
4316 for (formati
= 0; formati
< format_count
; formati
++)
4318 uint64_t content_type
;
4320 READ_ULEB (content_type
, format
, end
);
4321 if ((content_type
== DW_LNCT_path
) == (namepass
== 1))
4322 switch (content_type
)
4325 printf (_("\tName"));
4327 case DW_LNCT_directory_index
:
4328 printf (_("\tDir"));
4330 case DW_LNCT_timestamp
:
4331 printf (_("\tTime"));
4334 printf (_("\tSize"));
4337 printf (_("\tMD5\t\t\t"));
4340 printf (_("\t(Unknown format content type %" PRIu64
")"),
4343 SKIP_ULEB (format
, end
);
4348 for (datai
= 0; datai
< data_count
; datai
++)
4350 unsigned char *datapass
= data
;
4352 printf (" %d", last_entry
++);
4353 /* Delay displaying name as the last entry for better screen layout. */
4354 for (namepass
= 0; namepass
< 2; namepass
++)
4356 format
= format_start
;
4358 for (formati
= 0; formati
< format_count
; formati
++)
4360 uint64_t content_type
, form
;
4362 READ_ULEB (content_type
, format
, end
);
4363 READ_ULEB (form
, format
, end
);
4364 data
= read_and_display_attr_value (0, form
, 0, start
, data
, end
,
4365 0, 0, linfo
->li_offset_size
,
4366 linfo
->li_version
, NULL
,
4367 ((content_type
== DW_LNCT_path
) != (namepass
== 1)),
4368 section
, NULL
, '\t', -1);
4372 if (data
>= end
&& (datai
< data_count
- 1))
4374 warn (_("\n%s: Corrupt entries list\n"), table_name
);
4383 display_debug_sup (struct dwarf_section
* section
,
4384 void * file ATTRIBUTE_UNUSED
)
4386 unsigned char * start
= section
->start
;
4387 unsigned char * end
= section
->start
+ section
->size
;
4388 unsigned int version
;
4389 char is_supplementary
;
4390 const unsigned char * sup_filename
;
4391 size_t sup_filename_len
;
4392 unsigned int num_read
;
4394 uint64_t checksum_len
;
4397 introduce (section
, true);
4398 if (section
->size
< 4)
4400 error (_("corrupt .debug_sup section: size is too small\n"));
4404 /* Read the data. */
4405 SAFE_BYTE_GET_AND_INC (version
, start
, 2, end
);
4407 warn (_("corrupt .debug_sup section: version < 5"));
4409 SAFE_BYTE_GET_AND_INC (is_supplementary
, start
, 1, end
);
4410 if (is_supplementary
!= 0 && is_supplementary
!= 1)
4411 warn (_("corrupt .debug_sup section: is_supplementary not 0 or 1\n"));
4413 sup_filename
= start
;
4414 if (is_supplementary
&& sup_filename
[0] != 0)
4415 warn (_("corrupt .debug_sup section: filename not empty in supplementary section\n"));
4417 sup_filename_len
= strnlen ((const char *) start
, end
- start
);
4418 if (sup_filename_len
== (size_t) (end
- start
))
4420 error (_("corrupt .debug_sup section: filename is not NUL terminated\n"));
4423 start
+= sup_filename_len
+ 1;
4425 checksum_len
= read_leb128 (start
, end
, false /* unsigned */, & num_read
, & status
);
4428 error (_("corrupt .debug_sup section: bad LEB128 field for checksum length\n"));
4432 if (checksum_len
> (size_t) (end
- start
))
4434 error (_("corrupt .debug_sup section: checksum length is longer than the remaining section length\n"));
4435 checksum_len
= end
- start
;
4437 else if (checksum_len
< (size_t) (end
- start
))
4439 warn (_("corrupt .debug_sup section: there are %#" PRIx64
4440 " extra, unused bytes at the end of the section\n"),
4441 (end
- start
) - checksum_len
);
4444 printf (_(" Version: %u\n"), version
);
4445 printf (_(" Is Supp: %u\n"), is_supplementary
);
4446 printf (_(" Filename: %s\n"), sup_filename
);
4447 printf (_(" Checksum Len: %" PRIu64
"\n"), checksum_len
);
4448 if (checksum_len
> 0)
4450 printf (_(" Checksum: "));
4451 while (checksum_len
--)
4452 printf ("0x%x ", * start
++ );
4459 display_debug_lines_raw (struct dwarf_section
* section
,
4460 unsigned char * data
,
4461 unsigned char * end
,
4464 unsigned char *start
= section
->start
;
4465 int verbose_view
= 0;
4467 introduce (section
, true);
4471 static DWARF2_Internal_LineInfo saved_linfo
;
4472 DWARF2_Internal_LineInfo linfo
;
4473 unsigned char *standard_opcodes
;
4474 unsigned char *end_of_sequence
;
4477 if (startswith (section
->name
, ".debug_line.")
4478 /* Note: the following does not apply to .debug_line.dwo sections.
4479 These are full debug_line sections. */
4480 && strcmp (section
->name
, ".debug_line.dwo") != 0)
4482 /* Sections named .debug_line.<foo> are fragments of a .debug_line
4483 section containing just the Line Number Statements. They are
4484 created by the assembler and intended to be used alongside gcc's
4485 -ffunction-sections command line option. When the linker's
4486 garbage collection decides to discard a .text.<foo> section it
4487 can then also discard the line number information in .debug_line.<foo>.
4489 Since the section is a fragment it does not have the details
4490 needed to fill out a LineInfo structure, so instead we use the
4491 details from the last full debug_line section that we processed. */
4492 end_of_sequence
= end
;
4493 standard_opcodes
= NULL
;
4494 linfo
= saved_linfo
;
4495 /* PR 17531: file: 0522b371. */
4496 if (linfo
.li_line_range
== 0)
4498 warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n"));
4501 reset_state_machine (linfo
.li_default_is_stmt
);
4505 unsigned char * hdrptr
;
4507 if ((hdrptr
= read_debug_line_header (section
, data
, end
, & linfo
,
4508 & end_of_sequence
)) == NULL
)
4511 printf (_(" Offset: %#tx\n"), data
- start
);
4512 printf (_(" Length: %" PRId64
"\n"), linfo
.li_length
);
4513 printf (_(" DWARF Version: %d\n"), linfo
.li_version
);
4514 if (linfo
.li_version
>= 5)
4516 printf (_(" Address size (bytes): %d\n"), linfo
.li_address_size
);
4517 printf (_(" Segment selector (bytes): %d\n"), linfo
.li_segment_size
);
4519 printf (_(" Prologue Length: %d\n"), (int) linfo
.li_prologue_length
);
4520 printf (_(" Minimum Instruction Length: %d\n"), linfo
.li_min_insn_length
);
4521 if (linfo
.li_version
>= 4)
4522 printf (_(" Maximum Ops per Instruction: %d\n"), linfo
.li_max_ops_per_insn
);
4523 printf (_(" Initial value of 'is_stmt': %d\n"), linfo
.li_default_is_stmt
);
4524 printf (_(" Line Base: %d\n"), linfo
.li_line_base
);
4525 printf (_(" Line Range: %d\n"), linfo
.li_line_range
);
4526 printf (_(" Opcode Base: %d\n"), linfo
.li_opcode_base
);
4528 /* PR 17512: file: 1665-6428-0.004. */
4529 if (linfo
.li_line_range
== 0)
4531 warn (_("Line range of 0 is invalid, using 1 instead\n"));
4532 linfo
.li_line_range
= 1;
4535 reset_state_machine (linfo
.li_default_is_stmt
);
4537 /* Display the contents of the Opcodes table. */
4538 standard_opcodes
= hdrptr
;
4540 /* PR 17512: file: 002-417945-0.004. */
4541 if (standard_opcodes
+ linfo
.li_opcode_base
>= end
)
4543 warn (_("Line Base extends beyond end of section\n"));
4547 printf (_("\n Opcodes:\n"));
4549 for (i
= 1; i
< linfo
.li_opcode_base
; i
++)
4550 printf (ngettext (" Opcode %d has %d arg\n",
4551 " Opcode %d has %d args\n",
4552 standard_opcodes
[i
- 1]),
4553 i
, standard_opcodes
[i
- 1]);
4555 /* Display the contents of the Directory table. */
4556 data
= standard_opcodes
+ linfo
.li_opcode_base
- 1;
4558 if (linfo
.li_version
>= 5)
4560 load_debug_section_with_follow (line_str
, file
);
4562 data
= display_formatted_table (data
, start
, end
, &linfo
, section
,
4564 data
= display_formatted_table (data
, start
, end
, &linfo
, section
,
4570 printf (_("\n The Directory Table is empty.\n"));
4573 unsigned int last_dir_entry
= 0;
4575 printf (_("\n The Directory Table (offset %#tx):\n"),
4578 while (data
< end
&& *data
!= 0)
4580 printf (" %d\t%.*s\n", ++last_dir_entry
, (int) (end
- data
), data
);
4582 data
+= strnlen ((char *) data
, end
- data
);
4587 /* PR 17512: file: 002-132094-0.004. */
4588 if (data
>= end
- 1)
4592 /* Skip the NUL at the end of the table. */
4596 /* Display the contents of the File Name table. */
4597 if (data
>= end
|| *data
== 0)
4598 printf (_("\n The File Name Table is empty.\n"));
4601 printf (_("\n The File Name Table (offset %#tx):\n"),
4603 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
4605 while (data
< end
&& *data
!= 0)
4607 unsigned char *name
;
4610 printf (" %d\t", ++state_machine_regs
.last_file_entry
);
4612 data
+= strnlen ((char *) data
, end
- data
);
4616 READ_ULEB (val
, data
, end
);
4617 printf ("%" PRIu64
"\t", val
);
4618 READ_ULEB (val
, data
, end
);
4619 printf ("%" PRIu64
"\t", val
);
4620 READ_ULEB (val
, data
, end
);
4621 printf ("%" PRIu64
"\t", val
);
4622 printf ("%.*s\n", (int)(end
- name
), name
);
4626 warn (_("Corrupt file name table entry\n"));
4632 /* Skip the NUL at the end of the table. */
4638 saved_linfo
= linfo
;
4641 /* Now display the statements. */
4642 if (data
>= end_of_sequence
)
4643 printf (_(" No Line Number Statements.\n"));
4646 printf (_(" Line Number Statements:\n"));
4648 while (data
< end_of_sequence
)
4650 unsigned char op_code
;
4654 printf (" [0x%08tx]", data
- start
);
4658 if (op_code
>= linfo
.li_opcode_base
)
4660 op_code
-= linfo
.li_opcode_base
;
4661 uladv
= (op_code
/ linfo
.li_line_range
);
4662 if (linfo
.li_max_ops_per_insn
== 1)
4664 uladv
*= linfo
.li_min_insn_length
;
4665 state_machine_regs
.address
+= uladv
;
4667 state_machine_regs
.view
= 0;
4668 printf (_(" Special opcode %d: "
4669 "advance Address by %" PRIu64
4670 " to %#" PRIx64
"%s"),
4671 op_code
, uladv
, state_machine_regs
.address
,
4672 verbose_view
&& uladv
4673 ? _(" (reset view)") : "");
4678 = ((state_machine_regs
.op_index
+ uladv
)
4679 / linfo
.li_max_ops_per_insn
)
4680 * linfo
.li_min_insn_length
;
4682 state_machine_regs
.address
+= addrdelta
;
4683 state_machine_regs
.op_index
4684 = (state_machine_regs
.op_index
+ uladv
)
4685 % linfo
.li_max_ops_per_insn
;
4687 state_machine_regs
.view
= 0;
4688 printf (_(" Special opcode %d: "
4689 "advance Address by %" PRIu64
4690 " to %#" PRIx64
"[%d]%s"),
4691 op_code
, uladv
, state_machine_regs
.address
,
4692 state_machine_regs
.op_index
,
4693 verbose_view
&& addrdelta
4694 ? _(" (reset view)") : "");
4696 adv
= (op_code
% linfo
.li_line_range
) + linfo
.li_line_base
;
4697 state_machine_regs
.line
+= adv
;
4698 printf (_(" and Line by %" PRId64
" to %d"),
4699 adv
, state_machine_regs
.line
);
4700 if (verbose_view
|| state_machine_regs
.view
)
4701 printf (_(" (view %u)\n"), state_machine_regs
.view
);
4704 state_machine_regs
.view
++;
4709 case DW_LNS_extended_op
:
4710 data
+= process_extended_line_op (data
,
4711 linfo
.li_default_is_stmt
,
4716 printf (_(" Copy"));
4717 if (verbose_view
|| state_machine_regs
.view
)
4718 printf (_(" (view %u)\n"), state_machine_regs
.view
);
4721 state_machine_regs
.view
++;
4724 case DW_LNS_advance_pc
:
4725 READ_ULEB (uladv
, data
, end
);
4726 if (linfo
.li_max_ops_per_insn
== 1)
4728 uladv
*= linfo
.li_min_insn_length
;
4729 state_machine_regs
.address
+= uladv
;
4731 state_machine_regs
.view
= 0;
4732 printf (_(" Advance PC by %" PRIu64
4733 " to %#" PRIx64
"%s\n"),
4734 uladv
, state_machine_regs
.address
,
4735 verbose_view
&& uladv
4736 ? _(" (reset view)") : "");
4741 = ((state_machine_regs
.op_index
+ uladv
)
4742 / linfo
.li_max_ops_per_insn
)
4743 * linfo
.li_min_insn_length
;
4744 state_machine_regs
.address
4746 state_machine_regs
.op_index
4747 = (state_machine_regs
.op_index
+ uladv
)
4748 % linfo
.li_max_ops_per_insn
;
4750 state_machine_regs
.view
= 0;
4751 printf (_(" Advance PC by %" PRIu64
4752 " to %#" PRIx64
"[%d]%s\n"),
4753 uladv
, state_machine_regs
.address
,
4754 state_machine_regs
.op_index
,
4755 verbose_view
&& addrdelta
4756 ? _(" (reset view)") : "");
4760 case DW_LNS_advance_line
:
4761 READ_SLEB (adv
, data
, end
);
4762 state_machine_regs
.line
+= adv
;
4763 printf (_(" Advance Line by %" PRId64
" to %d\n"),
4764 adv
, state_machine_regs
.line
);
4767 case DW_LNS_set_file
:
4768 READ_ULEB (uladv
, data
, end
);
4769 printf (_(" Set File Name to entry %" PRIu64
4770 " in the File Name Table\n"), uladv
);
4771 state_machine_regs
.file
= uladv
;
4774 case DW_LNS_set_column
:
4775 READ_ULEB (uladv
, data
, end
);
4776 printf (_(" Set column to %" PRIu64
"\n"), uladv
);
4777 state_machine_regs
.column
= uladv
;
4780 case DW_LNS_negate_stmt
:
4781 adv
= state_machine_regs
.is_stmt
;
4783 printf (_(" Set is_stmt to %" PRId64
"\n"), adv
);
4784 state_machine_regs
.is_stmt
= adv
;
4787 case DW_LNS_set_basic_block
:
4788 printf (_(" Set basic block\n"));
4789 state_machine_regs
.basic_block
= 1;
4792 case DW_LNS_const_add_pc
:
4793 uladv
= ((255 - linfo
.li_opcode_base
) / linfo
.li_line_range
);
4794 if (linfo
.li_max_ops_per_insn
)
4796 uladv
*= linfo
.li_min_insn_length
;
4797 state_machine_regs
.address
+= uladv
;
4799 state_machine_regs
.view
= 0;
4800 printf (_(" Advance PC by constant %" PRIu64
4801 " to %#" PRIx64
"%s\n"),
4802 uladv
, state_machine_regs
.address
,
4803 verbose_view
&& uladv
4804 ? _(" (reset view)") : "");
4809 = ((state_machine_regs
.op_index
+ uladv
)
4810 / linfo
.li_max_ops_per_insn
)
4811 * linfo
.li_min_insn_length
;
4812 state_machine_regs
.address
4814 state_machine_regs
.op_index
4815 = (state_machine_regs
.op_index
+ uladv
)
4816 % linfo
.li_max_ops_per_insn
;
4818 state_machine_regs
.view
= 0;
4819 printf (_(" Advance PC by constant %" PRIu64
4820 " to %#" PRIx64
"[%d]%s\n"),
4821 uladv
, state_machine_regs
.address
,
4822 state_machine_regs
.op_index
,
4823 verbose_view
&& addrdelta
4824 ? _(" (reset view)") : "");
4828 case DW_LNS_fixed_advance_pc
:
4829 SAFE_BYTE_GET_AND_INC (uladv
, data
, 2, end
);
4830 state_machine_regs
.address
+= uladv
;
4831 state_machine_regs
.op_index
= 0;
4832 printf (_(" Advance PC by fixed size amount %" PRIu64
4833 " to %#" PRIx64
"\n"),
4834 uladv
, state_machine_regs
.address
);
4835 /* Do NOT reset view. */
4838 case DW_LNS_set_prologue_end
:
4839 printf (_(" Set prologue_end to true\n"));
4842 case DW_LNS_set_epilogue_begin
:
4843 printf (_(" Set epilogue_begin to true\n"));
4846 case DW_LNS_set_isa
:
4847 READ_ULEB (uladv
, data
, end
);
4848 printf (_(" Set ISA to %" PRIu64
"\n"), uladv
);
4852 printf (_(" Unknown opcode %d with operands: "), op_code
);
4854 if (standard_opcodes
!= NULL
)
4855 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
4857 READ_ULEB (uladv
, data
, end
);
4858 printf ("%#" PRIx64
"%s", uladv
, i
== 1 ? "" : ", ");
4874 unsigned int directory_index
;
4875 unsigned int modification_date
;
4876 unsigned int length
;
4879 /* Output a decoded representation of the .debug_line section. */
4882 display_debug_lines_decoded (struct dwarf_section
* section
,
4883 unsigned char * start
,
4884 unsigned char * data
,
4885 unsigned char * end
,
4888 static DWARF2_Internal_LineInfo saved_linfo
;
4890 introduce (section
, false);
4894 /* This loop amounts to one iteration per compilation unit. */
4895 DWARF2_Internal_LineInfo linfo
;
4896 unsigned char *standard_opcodes
;
4897 unsigned char *end_of_sequence
;
4899 File_Entry
*file_table
= NULL
;
4900 unsigned int n_files
= 0;
4901 char **directory_table
= NULL
;
4902 unsigned int n_directories
= 0;
4904 if (startswith (section
->name
, ".debug_line.")
4905 /* Note: the following does not apply to .debug_line.dwo sections.
4906 These are full debug_line sections. */
4907 && strcmp (section
->name
, ".debug_line.dwo") != 0)
4909 /* See comment in display_debug_lines_raw(). */
4910 end_of_sequence
= end
;
4911 standard_opcodes
= NULL
;
4912 linfo
= saved_linfo
;
4913 /* PR 17531: file: 0522b371. */
4914 if (linfo
.li_line_range
== 0)
4916 warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n"));
4919 reset_state_machine (linfo
.li_default_is_stmt
);
4923 unsigned char *hdrptr
;
4925 if ((hdrptr
= read_debug_line_header (section
, data
, end
, & linfo
,
4926 & end_of_sequence
)) == NULL
)
4929 /* PR 17531: file: 0522b371. */
4930 if (linfo
.li_line_range
== 0)
4932 warn (_("Line range of 0 is invalid, using 1 instead\n"));
4933 linfo
.li_line_range
= 1;
4935 reset_state_machine (linfo
.li_default_is_stmt
);
4937 /* Save a pointer to the contents of the Opcodes table. */
4938 standard_opcodes
= hdrptr
;
4940 /* Traverse the Directory table just to count entries. */
4941 data
= standard_opcodes
+ linfo
.li_opcode_base
- 1;
4945 warn (_("opcode base of %d extends beyond end of section\n"),
4946 linfo
.li_opcode_base
);
4950 if (linfo
.li_version
>= 5)
4952 unsigned char *format_start
, *format
;
4953 unsigned int format_count
, formati
, entryi
;
4955 load_debug_section_with_follow (line_str
, fileptr
);
4957 /* Skip directories format. */
4958 SAFE_BYTE_GET_AND_INC (format_count
, data
, 1, end
);
4959 if (do_checks
&& format_count
> 1)
4960 warn (_("Unexpectedly large number of columns in the directory name table (%u)\n"),
4962 format_start
= data
;
4963 for (formati
= 0; formati
< format_count
; formati
++)
4965 SKIP_ULEB (data
, end
);
4966 SKIP_ULEB (data
, end
);
4969 READ_ULEB (n_directories
, data
, end
);
4972 warn (_("Corrupt directories list\n"));
4976 if (n_directories
== 0)
4977 directory_table
= NULL
;
4979 directory_table
= (char **)
4980 xcalloc (n_directories
, sizeof (unsigned char *));
4982 for (entryi
= 0; entryi
< n_directories
; entryi
++)
4984 char **pathp
= &directory_table
[entryi
];
4986 format
= format_start
;
4987 for (formati
= 0; formati
< format_count
; formati
++)
4989 uint64_t content_type
, form
;
4992 READ_ULEB (content_type
, format
, end
);
4993 READ_ULEB (form
, format
, end
);
4996 warn (_("Corrupt directories list\n"));
4999 switch (content_type
)
5004 case DW_FORM_string
:
5005 *pathp
= (char *) data
;
5007 case DW_FORM_line_strp
:
5008 SAFE_BYTE_GET (uvalue
, data
, linfo
.li_offset_size
,
5010 /* Remove const by the cast. */
5012 fetch_indirect_line_string (uvalue
);
5017 data
= read_and_display_attr_value (0, form
, 0, start
,
5019 linfo
.li_offset_size
,
5026 warn (_("Corrupt directories list\n"));
5031 /* Skip files format. */
5032 SAFE_BYTE_GET_AND_INC (format_count
, data
, 1, end
);
5033 if (do_checks
&& format_count
> 5)
5034 warn (_("Unexpectedly large number of columns in the file name table (%u)\n"),
5036 format_start
= data
;
5037 for (formati
= 0; formati
< format_count
; formati
++)
5039 SKIP_ULEB (data
, end
);
5040 SKIP_ULEB (data
, end
);
5043 READ_ULEB (n_files
, data
, end
);
5044 if (data
>= end
&& n_files
> 0)
5046 warn (_("Corrupt file name list\n"));
5053 file_table
= (File_Entry
*) xcalloc (n_files
,
5054 sizeof (File_Entry
));
5056 for (entryi
= 0; entryi
< n_files
; entryi
++)
5058 File_Entry
*file
= &file_table
[entryi
];
5060 format
= format_start
;
5061 for (formati
= 0; formati
< format_count
; formati
++)
5063 uint64_t content_type
, form
;
5067 READ_ULEB (content_type
, format
, end
);
5068 READ_ULEB (form
, format
, end
);
5071 warn (_("Corrupt file name list\n"));
5074 switch (content_type
)
5079 case DW_FORM_string
:
5080 file
->name
= (char *) data
;
5082 case DW_FORM_line_strp
:
5083 SAFE_BYTE_GET (uvalue
, data
, linfo
.li_offset_size
,
5085 /* Remove const by the cast. */
5086 file
->name
= (char *)
5087 fetch_indirect_line_string (uvalue
);
5091 case DW_LNCT_directory_index
:
5095 SAFE_BYTE_GET (file
->directory_index
, data
, 1,
5099 SAFE_BYTE_GET (file
->directory_index
, data
, 2,
5104 READ_ULEB (file
->directory_index
, tmp
, end
);
5109 data
= read_and_display_attr_value (0, form
, 0, start
,
5111 linfo
.li_offset_size
,
5118 warn (_("Corrupt file name list\n"));
5127 char *ptr_directory_table
= (char *) data
;
5129 while (data
< end
&& *data
!= 0)
5131 data
+= strnlen ((char *) data
, end
- data
);
5140 warn (_("directory table ends unexpectedly\n"));
5145 /* Go through the directory table again to save the directories. */
5146 directory_table
= (char **)
5147 xmalloc (n_directories
* sizeof (unsigned char *));
5150 while (*ptr_directory_table
!= 0)
5152 directory_table
[i
] = ptr_directory_table
;
5153 ptr_directory_table
+= strlen (ptr_directory_table
) + 1;
5157 /* Skip the NUL at the end of the table. */
5160 /* Traverse the File Name table just to count the entries. */
5161 if (data
< end
&& *data
!= 0)
5163 unsigned char *ptr_file_name_table
= data
;
5165 while (data
< end
&& *data
!= 0)
5167 /* Skip Name, directory index, last modification
5168 time and length of file. */
5169 data
+= strnlen ((char *) data
, end
- data
);
5172 SKIP_ULEB (data
, end
);
5173 SKIP_ULEB (data
, end
);
5174 SKIP_ULEB (data
, end
);
5180 warn (_("file table ends unexpectedly\n"));
5185 /* Go through the file table again to save the strings. */
5186 file_table
= (File_Entry
*) xmalloc (n_files
* sizeof (File_Entry
));
5189 while (*ptr_file_name_table
!= 0)
5191 file_table
[i
].name
= (char *) ptr_file_name_table
;
5193 += strlen ((char *) ptr_file_name_table
) + 1;
5195 /* We are not interested in directory, time or size. */
5196 READ_ULEB (file_table
[i
].directory_index
,
5197 ptr_file_name_table
, end
);
5198 READ_ULEB (file_table
[i
].modification_date
,
5199 ptr_file_name_table
, end
);
5200 READ_ULEB (file_table
[i
].length
,
5201 ptr_file_name_table
, end
);
5207 /* Skip the NUL at the end of the table. */
5211 /* Print the Compilation Unit's name and a header. */
5212 if (file_table
== NULL
)
5213 printf (_("CU: No directory table\n"));
5214 else if (directory_table
== NULL
)
5215 printf (_("CU: %s:\n"), null_name (file_table
[0].name
));
5218 unsigned int ix
= file_table
[0].directory_index
;
5219 const char *directory
;
5221 if (ix
== 0 && linfo
.li_version
< 5)
5224 else if (n_directories
== 0)
5225 directory
= _("<unknown>");
5228 if (linfo
.li_version
< 5)
5230 if (ix
>= n_directories
)
5232 warn (_("directory index %u "
5233 ">= number of directories %u\n"),
5235 directory
= _("<corrupt>");
5238 directory
= directory_table
[ix
];
5241 printf (_("CU: %s/%s:\n"),
5242 null_name (directory
),
5243 null_name (file_table
[0].name
));
5245 printf ("%s:\n", null_name (file_table
[0].name
));
5249 printf (_("File name Line number Starting address View Stmt\n"));
5251 printf (_("CU: Empty file name table\n"));
5252 saved_linfo
= linfo
;
5255 /* This loop iterates through the Dwarf Line Number Program. */
5256 while (data
< end_of_sequence
)
5258 unsigned char op_code
;
5261 unsigned long int uladv
;
5262 int is_special_opcode
= 0;
5267 if (op_code
>= linfo
.li_opcode_base
)
5269 op_code
-= linfo
.li_opcode_base
;
5270 uladv
= (op_code
/ linfo
.li_line_range
);
5271 if (linfo
.li_max_ops_per_insn
== 1)
5273 uladv
*= linfo
.li_min_insn_length
;
5274 state_machine_regs
.address
+= uladv
;
5276 state_machine_regs
.view
= 0;
5281 = ((state_machine_regs
.op_index
+ uladv
)
5282 / linfo
.li_max_ops_per_insn
)
5283 * linfo
.li_min_insn_length
;
5284 state_machine_regs
.address
5286 state_machine_regs
.op_index
5287 = (state_machine_regs
.op_index
+ uladv
)
5288 % linfo
.li_max_ops_per_insn
;
5290 state_machine_regs
.view
= 0;
5293 adv
= (op_code
% linfo
.li_line_range
) + linfo
.li_line_base
;
5294 state_machine_regs
.line
+= adv
;
5295 is_special_opcode
= 1;
5296 /* Increment view after printing this row. */
5301 case DW_LNS_extended_op
:
5303 unsigned int ext_op_code_len
;
5304 unsigned char ext_op_code
;
5305 unsigned char *op_code_end
;
5306 unsigned char *op_code_data
= data
;
5308 READ_ULEB (ext_op_code_len
, op_code_data
, end_of_sequence
);
5309 op_code_end
= op_code_data
+ ext_op_code_len
;
5310 if (ext_op_code_len
== 0 || op_code_end
> end_of_sequence
)
5312 warn (_("Badly formed extended line op encountered!\n"));
5315 ext_op_code
= *op_code_data
++;
5319 switch (ext_op_code
)
5321 case DW_LNE_end_sequence
:
5322 /* Reset stuff after printing this row. */
5324 case DW_LNE_set_address
:
5325 SAFE_BYTE_GET_AND_INC (state_machine_regs
.address
,
5327 op_code_end
- op_code_data
,
5329 state_machine_regs
.op_index
= 0;
5330 state_machine_regs
.view
= 0;
5332 case DW_LNE_define_file
:
5333 file_table
= (File_Entry
*) xrealloc
5334 (file_table
, (n_files
+ 1) * sizeof (File_Entry
));
5336 ++state_machine_regs
.last_file_entry
;
5337 /* Source file name. */
5338 file_table
[n_files
].name
= (char *) op_code_data
;
5339 op_code_data
+= strlen ((char *) op_code_data
) + 1;
5340 /* Directory index. */
5341 READ_ULEB (file_table
[n_files
].directory_index
,
5342 op_code_data
, op_code_end
);
5343 /* Last modification time. */
5344 READ_ULEB (file_table
[n_files
].modification_date
,
5345 op_code_data
, op_code_end
);
5347 READ_ULEB (file_table
[n_files
].length
,
5348 op_code_data
, op_code_end
);
5352 case DW_LNE_set_discriminator
:
5353 case DW_LNE_HP_set_sequence
:
5354 /* Simply ignored. */
5358 printf (_("UNKNOWN (%u): length %ld\n"),
5359 ext_op_code
, (long int) (op_code_data
- data
));
5366 /* Increment view after printing this row. */
5369 case DW_LNS_advance_pc
:
5370 READ_ULEB (uladv
, data
, end
);
5371 if (linfo
.li_max_ops_per_insn
== 1)
5373 uladv
*= linfo
.li_min_insn_length
;
5374 state_machine_regs
.address
+= uladv
;
5376 state_machine_regs
.view
= 0;
5381 = ((state_machine_regs
.op_index
+ uladv
)
5382 / linfo
.li_max_ops_per_insn
)
5383 * linfo
.li_min_insn_length
;
5384 state_machine_regs
.address
5386 state_machine_regs
.op_index
5387 = (state_machine_regs
.op_index
+ uladv
)
5388 % linfo
.li_max_ops_per_insn
;
5390 state_machine_regs
.view
= 0;
5394 case DW_LNS_advance_line
:
5395 READ_SLEB (adv
, data
, end
);
5396 state_machine_regs
.line
+= adv
;
5399 case DW_LNS_set_file
:
5400 READ_ULEB (uladv
, data
, end
);
5401 state_machine_regs
.file
= uladv
;
5403 unsigned file
= state_machine_regs
.file
;
5404 if (linfo
.li_version
< 5)
5407 if (file_table
== NULL
|| n_files
== 0)
5408 printf (_("\n [Use file table entry %d]\n"), file
);
5410 else if (file
>= n_files
)
5412 warn (_("file index %u >= number of files %u\n"),
5414 printf (_("\n <over large file table index %u>"), file
);
5418 unsigned dir
= file_table
[file
].directory_index
;
5419 if (dir
== 0 && linfo
.li_version
< 5)
5420 /* If directory index is 0, that means compilation
5421 current directory. bfd/dwarf2.c shows
5422 DW_AT_comp_dir here but in keeping with the
5423 readelf practice of minimal interpretation of
5424 file data, we show "./". */
5425 printf ("\n./%s:[++]\n",
5426 null_name (file_table
[file
].name
));
5427 else if (directory_table
== NULL
|| n_directories
== 0)
5428 printf (_("\n [Use file %s "
5429 "in directory table entry %d]\n"),
5430 null_name (file_table
[file
].name
), dir
);
5433 if (linfo
.li_version
< 5)
5436 if (dir
>= n_directories
)
5438 warn (_("directory index %u "
5439 ">= number of directories %u\n"),
5440 dir
, n_directories
);
5441 printf (_("\n <over large directory table entry "
5445 printf ("\n%s/%s:\n",
5446 null_name (directory_table
[dir
]),
5447 null_name (file_table
[file
].name
));
5452 case DW_LNS_set_column
:
5453 READ_ULEB (uladv
, data
, end
);
5454 state_machine_regs
.column
= uladv
;
5457 case DW_LNS_negate_stmt
:
5458 adv
= state_machine_regs
.is_stmt
;
5460 state_machine_regs
.is_stmt
= adv
;
5463 case DW_LNS_set_basic_block
:
5464 state_machine_regs
.basic_block
= 1;
5467 case DW_LNS_const_add_pc
:
5468 uladv
= ((255 - linfo
.li_opcode_base
) / linfo
.li_line_range
);
5469 if (linfo
.li_max_ops_per_insn
== 1)
5471 uladv
*= linfo
.li_min_insn_length
;
5472 state_machine_regs
.address
+= uladv
;
5474 state_machine_regs
.view
= 0;
5479 = ((state_machine_regs
.op_index
+ uladv
)
5480 / linfo
.li_max_ops_per_insn
)
5481 * linfo
.li_min_insn_length
;
5482 state_machine_regs
.address
5484 state_machine_regs
.op_index
5485 = (state_machine_regs
.op_index
+ uladv
)
5486 % linfo
.li_max_ops_per_insn
;
5488 state_machine_regs
.view
= 0;
5492 case DW_LNS_fixed_advance_pc
:
5493 SAFE_BYTE_GET_AND_INC (uladv
, data
, 2, end
);
5494 state_machine_regs
.address
+= uladv
;
5495 state_machine_regs
.op_index
= 0;
5496 /* Do NOT reset view. */
5499 case DW_LNS_set_prologue_end
:
5502 case DW_LNS_set_epilogue_begin
:
5505 case DW_LNS_set_isa
:
5506 READ_ULEB (uladv
, data
, end
);
5507 printf (_(" Set ISA to %lu\n"), uladv
);
5511 printf (_(" Unknown opcode %d with operands: "), op_code
);
5513 if (standard_opcodes
!= NULL
)
5514 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
5518 READ_ULEB (val
, data
, end
);
5519 printf ("%#" PRIx64
"%s", val
, i
== 1 ? "" : ", ");
5525 /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row
5526 to the DWARF address/line matrix. */
5527 if ((is_special_opcode
) || (xop
== -DW_LNE_end_sequence
)
5528 || (xop
== DW_LNS_copy
))
5530 const unsigned int MAX_FILENAME_LENGTH
= 35;
5531 char *fileName
= NULL
;
5532 char *newFileName
= NULL
;
5533 size_t fileNameLength
;
5537 unsigned indx
= state_machine_regs
.file
;
5539 if (linfo
.li_version
< 5)
5542 if (indx
>= n_files
)
5544 warn (_("file index %u >= number of files %u\n"),
5546 fileName
= _("<corrupt>");
5549 fileName
= (char *) file_table
[indx
].name
;
5552 fileName
= _("<unknown>");
5554 fileNameLength
= strlen (fileName
);
5555 newFileName
= fileName
;
5556 if (fileNameLength
> MAX_FILENAME_LENGTH
&& !do_wide
)
5558 newFileName
= (char *) xmalloc (MAX_FILENAME_LENGTH
+ 1);
5559 /* Truncate file name */
5560 memcpy (newFileName
,
5561 fileName
+ fileNameLength
- MAX_FILENAME_LENGTH
,
5562 MAX_FILENAME_LENGTH
);
5563 newFileName
[MAX_FILENAME_LENGTH
] = 0;
5566 /* A row with end_seq set to true has a meaningful address, but
5567 the other information in the same row is not significant.
5568 In such a row, print line as "-", and don't print
5570 if (!do_wide
|| fileNameLength
<= MAX_FILENAME_LENGTH
)
5572 if (linfo
.li_max_ops_per_insn
== 1)
5574 if (xop
== -DW_LNE_end_sequence
)
5575 printf ("%-35s %11s %#18" PRIx64
,
5577 state_machine_regs
.address
);
5579 printf ("%-35s %11d %#18" PRIx64
,
5580 newFileName
, state_machine_regs
.line
,
5581 state_machine_regs
.address
);
5585 if (xop
== -DW_LNE_end_sequence
)
5586 printf ("%-35s %11s %#18" PRIx64
"[%d]",
5588 state_machine_regs
.address
,
5589 state_machine_regs
.op_index
);
5591 printf ("%-35s %11d %#18" PRIx64
"[%d]",
5592 newFileName
, state_machine_regs
.line
,
5593 state_machine_regs
.address
,
5594 state_machine_regs
.op_index
);
5599 if (linfo
.li_max_ops_per_insn
== 1)
5601 if (xop
== -DW_LNE_end_sequence
)
5602 printf ("%s %11s %#18" PRIx64
,
5604 state_machine_regs
.address
);
5606 printf ("%s %11d %#18" PRIx64
,
5607 newFileName
, state_machine_regs
.line
,
5608 state_machine_regs
.address
);
5612 if (xop
== -DW_LNE_end_sequence
)
5613 printf ("%s %11s %#18" PRIx64
"[%d]",
5615 state_machine_regs
.address
,
5616 state_machine_regs
.op_index
);
5618 printf ("%s %11d %#18" PRIx64
"[%d]",
5619 newFileName
, state_machine_regs
.line
,
5620 state_machine_regs
.address
,
5621 state_machine_regs
.op_index
);
5625 if (xop
!= -DW_LNE_end_sequence
)
5627 if (state_machine_regs
.view
)
5628 printf (" %6u", state_machine_regs
.view
);
5632 if (state_machine_regs
.is_stmt
)
5637 state_machine_regs
.view
++;
5639 if (xop
== -DW_LNE_end_sequence
)
5641 reset_state_machine (linfo
.li_default_is_stmt
);
5645 if (newFileName
!= fileName
)
5657 if (directory_table
)
5659 free (directory_table
);
5660 directory_table
= NULL
;
5671 display_debug_lines (struct dwarf_section
*section
, void *file
)
5673 unsigned char *data
= section
->start
;
5674 unsigned char *end
= data
+ section
->size
;
5676 int retValDecoded
= 1;
5678 if (do_debug_lines
== 0)
5679 do_debug_lines
|= FLAG_DEBUG_LINES_RAW
;
5681 if (do_debug_lines
& FLAG_DEBUG_LINES_RAW
)
5682 retValRaw
= display_debug_lines_raw (section
, data
, end
, file
);
5684 if (do_debug_lines
& FLAG_DEBUG_LINES_DECODED
)
5685 retValDecoded
= display_debug_lines_decoded (section
, data
, data
, end
, file
);
5687 if (!retValRaw
|| !retValDecoded
)
5694 find_debug_info_for_offset (uint64_t offset
)
5698 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
5701 for (i
= 0; i
< num_debug_info_entries
; i
++)
5702 if (debug_information
[i
].cu_offset
== offset
)
5703 return debug_information
+ i
;
5709 get_gdb_index_symbol_kind_name (gdb_index_symbol_kind kind
)
5711 /* See gdb/gdb-index.h. */
5712 static const char * const kinds
[] =
5724 return _ (kinds
[kind
]);
5728 display_debug_pubnames_worker (struct dwarf_section
*section
,
5729 void *file ATTRIBUTE_UNUSED
,
5732 DWARF2_Internal_PubNames names
;
5733 unsigned char *start
= section
->start
;
5734 unsigned char *end
= start
+ section
->size
;
5736 /* It does not matter if this load fails,
5737 we test for that later on. */
5738 load_debug_info (file
);
5740 introduce (section
, false);
5744 unsigned char *data
;
5745 unsigned long sec_off
= start
- section
->start
;
5746 unsigned int offset_size
;
5748 SAFE_BYTE_GET_AND_INC (names
.pn_length
, start
, 4, end
);
5749 if (names
.pn_length
== 0xffffffff)
5751 SAFE_BYTE_GET_AND_INC (names
.pn_length
, start
, 8, end
);
5757 if (names
.pn_length
> (size_t) (end
- start
))
5759 warn (_("Debug info is corrupted, "
5760 "%s header at %#lx has length %#" PRIx64
"\n"),
5761 section
->name
, sec_off
, names
.pn_length
);
5766 start
+= names
.pn_length
;
5768 SAFE_BYTE_GET_AND_INC (names
.pn_version
, data
, 2, start
);
5769 SAFE_BYTE_GET_AND_INC (names
.pn_offset
, data
, offset_size
, start
);
5771 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
5772 && num_debug_info_entries
> 0
5773 && find_debug_info_for_offset (names
.pn_offset
) == NULL
)
5774 warn (_(".debug_info offset of %#" PRIx64
5775 " in %s section does not point to a CU header.\n"),
5776 names
.pn_offset
, section
->name
);
5778 SAFE_BYTE_GET_AND_INC (names
.pn_size
, data
, offset_size
, start
);
5780 printf (_(" Length: %" PRId64
"\n"),
5782 printf (_(" Version: %d\n"),
5784 printf (_(" Offset into .debug_info section: %#" PRIx64
"\n"),
5786 printf (_(" Size of area in .debug_info section: %" PRId64
"\n"),
5789 if (names
.pn_version
!= 2 && names
.pn_version
!= 3)
5791 static int warned
= 0;
5795 warn (_("Only DWARF 2 and 3 pubnames are currently supported\n"));
5803 printf (_("\n Offset Kind Name\n"));
5805 printf (_("\n Offset\tName\n"));
5812 SAFE_BYTE_GET_AND_INC (offset
, data
, offset_size
, start
);
5819 maxprint
= (start
- data
) - 1;
5823 unsigned int kind_data
;
5824 gdb_index_symbol_kind kind
;
5825 const char *kind_name
;
5828 SAFE_BYTE_GET_AND_INC (kind_data
, data
, 1, start
);
5830 /* GCC computes the kind as the upper byte in the CU index
5831 word, and then right shifts it by the CU index size.
5832 Left shift KIND to where the gdb-index.h accessor macros
5834 kind_data
<<= GDB_INDEX_CU_BITSIZE
;
5835 kind
= GDB_INDEX_SYMBOL_KIND_VALUE (kind_data
);
5836 kind_name
= get_gdb_index_symbol_kind_name (kind
);
5837 is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (kind_data
);
5838 printf (" %-6" PRIx64
" %s,%-10s %.*s\n",
5839 offset
, is_static
? _("s") : _("g"),
5840 kind_name
, (int) maxprint
, data
);
5843 printf (" %-6" PRIx64
"\t%.*s\n",
5844 offset
, (int) maxprint
, data
);
5846 data
+= strnlen ((char *) data
, maxprint
);
5859 display_debug_pubnames (struct dwarf_section
*section
, void *file
)
5861 return display_debug_pubnames_worker (section
, file
, 0);
5865 display_debug_gnu_pubnames (struct dwarf_section
*section
, void *file
)
5867 return display_debug_pubnames_worker (section
, file
, 1);
5871 display_debug_macinfo (struct dwarf_section
*section
,
5872 void *file ATTRIBUTE_UNUSED
)
5874 unsigned char *start
= section
->start
;
5875 unsigned char *end
= start
+ section
->size
;
5876 unsigned char *curr
= start
;
5877 enum dwarf_macinfo_record_type op
;
5879 introduce (section
, false);
5883 unsigned int lineno
;
5884 const unsigned char *string
;
5886 op
= (enum dwarf_macinfo_record_type
) *curr
;
5891 case DW_MACINFO_start_file
:
5893 unsigned int filenum
;
5895 READ_ULEB (lineno
, curr
, end
);
5896 READ_ULEB (filenum
, curr
, end
);
5897 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"),
5902 case DW_MACINFO_end_file
:
5903 printf (_(" DW_MACINFO_end_file\n"));
5906 case DW_MACINFO_define
:
5907 READ_ULEB (lineno
, curr
, end
);
5909 curr
+= strnlen ((char *) string
, end
- string
);
5910 printf (_(" DW_MACINFO_define - lineno : %d macro : %*s\n"),
5911 lineno
, (int) (curr
- string
), string
);
5916 case DW_MACINFO_undef
:
5917 READ_ULEB (lineno
, curr
, end
);
5919 curr
+= strnlen ((char *) string
, end
- string
);
5920 printf (_(" DW_MACINFO_undef - lineno : %d macro : %*s\n"),
5921 lineno
, (int) (curr
- string
), string
);
5926 case DW_MACINFO_vendor_ext
:
5928 unsigned int constant
;
5930 READ_ULEB (constant
, curr
, end
);
5932 curr
+= strnlen ((char *) string
, end
- string
);
5933 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %*s\n"),
5934 constant
, (int) (curr
- string
), string
);
5945 /* Given LINE_OFFSET into the .debug_line section, attempt to return
5946 filename and dirname corresponding to file name table entry with index
5947 FILEIDX. Return NULL on failure. */
5949 static unsigned char *
5950 get_line_filename_and_dirname (uint64_t line_offset
,
5952 unsigned char **dir_name
)
5954 struct dwarf_section
*section
= &debug_displays
[line
].section
;
5955 unsigned char *hdrptr
, *dirtable
, *file_name
;
5956 unsigned int offset_size
;
5957 unsigned int version
, opcode_base
;
5958 uint64_t length
, diridx
;
5959 const unsigned char * end
;
5962 if (section
->start
== NULL
5963 || line_offset
>= section
->size
5967 hdrptr
= section
->start
+ line_offset
;
5968 end
= section
->start
+ section
->size
;
5970 SAFE_BYTE_GET_AND_INC (length
, hdrptr
, 4, end
);
5971 if (length
== 0xffffffff)
5973 /* This section is 64-bit DWARF 3. */
5974 SAFE_BYTE_GET_AND_INC (length
, hdrptr
, 8, end
);
5980 if (length
> (size_t) (end
- hdrptr
)
5981 || length
< 2 + offset_size
+ 1 + 3 + 1)
5983 end
= hdrptr
+ length
;
5985 SAFE_BYTE_GET_AND_INC (version
, hdrptr
, 2, end
);
5986 if (version
!= 2 && version
!= 3 && version
!= 4)
5988 hdrptr
+= offset_size
+ 1;/* Skip prologue_length and min_insn_length. */
5990 hdrptr
++; /* Skip max_ops_per_insn. */
5991 hdrptr
+= 3; /* Skip default_is_stmt, line_base, line_range. */
5993 SAFE_BYTE_GET_AND_INC (opcode_base
, hdrptr
, 1, end
);
5994 if (opcode_base
== 0
5995 || opcode_base
- 1 >= (size_t) (end
- hdrptr
))
5998 hdrptr
+= opcode_base
- 1;
6001 /* Skip over dirname table. */
6002 while (*hdrptr
!= '\0')
6004 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
);
6010 hdrptr
++; /* Skip the NUL at the end of the table. */
6012 /* Now skip over preceding filename table entries. */
6013 for (; hdrptr
< end
&& *hdrptr
!= '\0' && fileidx
> 1; fileidx
--)
6015 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
);
6018 SKIP_ULEB (hdrptr
, end
);
6019 SKIP_ULEB (hdrptr
, end
);
6020 SKIP_ULEB (hdrptr
, end
);
6022 if (hdrptr
>= end
|| *hdrptr
== '\0')
6026 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
);
6031 READ_ULEB (diridx
, hdrptr
, end
);
6034 for (; dirtable
< end
&& *dirtable
!= '\0' && diridx
> 1; diridx
--)
6036 dirtable
+= strnlen ((char *) dirtable
, end
- dirtable
);
6040 if (dirtable
>= end
|| *dirtable
== '\0')
6042 *dir_name
= dirtable
;
6047 display_debug_macro (struct dwarf_section
*section
,
6050 unsigned char *start
= section
->start
;
6051 unsigned char *end
= start
+ section
->size
;
6052 unsigned char *curr
= start
;
6053 unsigned char *extended_op_buf
[256];
6054 bool is_dwo
= false;
6055 const char *suffix
= strrchr (section
->name
, '.');
6057 if (suffix
&& strcmp (suffix
, ".dwo") == 0)
6060 load_debug_section_with_follow (str
, file
);
6061 load_debug_section_with_follow (line
, file
);
6062 load_debug_section_with_follow (str_index
, file
);
6064 introduce (section
, false);
6068 unsigned int lineno
, version
, flags
;
6069 unsigned int offset_size
;
6070 const unsigned char *string
;
6071 uint64_t line_offset
= 0, sec_offset
= curr
- start
, offset
;
6072 unsigned char **extended_ops
= NULL
;
6074 SAFE_BYTE_GET_AND_INC (version
, curr
, 2, end
);
6075 if (version
!= 4 && version
!= 5)
6077 error (_("Expected to find a version number of 4 or 5 in section %s but found %d instead\n"),
6078 section
->name
, version
);
6082 SAFE_BYTE_GET_AND_INC (flags
, curr
, 1, end
);
6083 offset_size
= (flags
& 1) ? 8 : 4;
6084 printf (_(" Offset: %#" PRIx64
"\n"), sec_offset
);
6085 printf (_(" Version: %d\n"), version
);
6086 printf (_(" Offset size: %d\n"), offset_size
);
6089 SAFE_BYTE_GET_AND_INC (line_offset
, curr
, offset_size
, end
);
6090 printf (_(" Offset into .debug_line: %#" PRIx64
"\n"),
6095 unsigned int i
, count
, op
;
6098 SAFE_BYTE_GET_AND_INC (count
, curr
, 1, end
);
6100 memset (extended_op_buf
, 0, sizeof (extended_op_buf
));
6101 extended_ops
= extended_op_buf
;
6104 printf (_(" Extension opcode arguments:\n"));
6105 for (i
= 0; i
< count
; i
++)
6107 SAFE_BYTE_GET_AND_INC (op
, curr
, 1, end
);
6108 extended_ops
[op
] = curr
;
6109 READ_ULEB (nargs
, curr
, end
);
6111 printf (_(" DW_MACRO_%02x has no arguments\n"), op
);
6114 printf (_(" DW_MACRO_%02x arguments: "), op
);
6115 for (n
= 0; n
< nargs
; n
++)
6119 SAFE_BYTE_GET_AND_INC (form
, curr
, 1, end
);
6120 printf ("%s%s", get_FORM_name (form
),
6121 n
== nargs
- 1 ? "\n" : ", ");
6131 case DW_FORM_block1
:
6132 case DW_FORM_block2
:
6133 case DW_FORM_block4
:
6135 case DW_FORM_string
:
6137 case DW_FORM_sec_offset
:
6140 error (_("Invalid extension opcode form %s\n"),
6141 get_FORM_name (form
));
6157 error (_(".debug_macro section not zero terminated\n"));
6161 SAFE_BYTE_GET_AND_INC (op
, curr
, 1, end
);
6167 case DW_MACRO_define
:
6168 READ_ULEB (lineno
, curr
, end
);
6170 curr
+= strnlen ((char *) string
, end
- string
);
6171 printf (_(" DW_MACRO_define - lineno : %d macro : %*s\n"),
6172 lineno
, (int) (curr
- string
), string
);
6177 case DW_MACRO_undef
:
6178 READ_ULEB (lineno
, curr
, end
);
6180 curr
+= strnlen ((char *) string
, end
- string
);
6181 printf (_(" DW_MACRO_undef - lineno : %d macro : %*s\n"),
6182 lineno
, (int) (curr
- string
), string
);
6187 case DW_MACRO_start_file
:
6189 unsigned int filenum
;
6190 unsigned char *file_name
= NULL
, *dir_name
= NULL
;
6192 READ_ULEB (lineno
, curr
, end
);
6193 READ_ULEB (filenum
, curr
, end
);
6195 if ((flags
& 2) == 0)
6196 error (_("DW_MACRO_start_file used, but no .debug_line offset provided.\n"));
6199 = get_line_filename_and_dirname (line_offset
, filenum
,
6201 if (file_name
== NULL
)
6202 printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d\n"),
6205 printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d filename: %s%s%s\n"),
6207 dir_name
!= NULL
? (const char *) dir_name
: "",
6208 dir_name
!= NULL
? "/" : "", file_name
);
6212 case DW_MACRO_end_file
:
6213 printf (_(" DW_MACRO_end_file\n"));
6216 case DW_MACRO_define_strp
:
6217 READ_ULEB (lineno
, curr
, end
);
6218 if (version
== 4 && is_dwo
)
6219 READ_ULEB (offset
, curr
, end
);
6221 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6222 string
= fetch_indirect_string (offset
);
6223 printf (_(" DW_MACRO_define_strp - lineno : %d macro : %s\n"),
6227 case DW_MACRO_undef_strp
:
6228 READ_ULEB (lineno
, curr
, end
);
6229 if (version
== 4 && is_dwo
)
6230 READ_ULEB (offset
, curr
, end
);
6232 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6233 string
= fetch_indirect_string (offset
);
6234 printf (_(" DW_MACRO_undef_strp - lineno : %d macro : %s\n"),
6238 case DW_MACRO_import
:
6239 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6240 printf (_(" DW_MACRO_import - offset : %#" PRIx64
"\n"),
6244 case DW_MACRO_define_sup
:
6245 READ_ULEB (lineno
, curr
, end
);
6246 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6247 printf (_(" DW_MACRO_define_sup - lineno : %d"
6248 " macro offset : %#" PRIx64
"\n"),
6252 case DW_MACRO_undef_sup
:
6253 READ_ULEB (lineno
, curr
, end
);
6254 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6255 printf (_(" DW_MACRO_undef_sup - lineno : %d"
6256 " macro offset : %#" PRIx64
"\n"),
6260 case DW_MACRO_import_sup
:
6261 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6262 printf (_(" DW_MACRO_import_sup - offset : %#" PRIx64
"\n"),
6266 case DW_MACRO_define_strx
:
6267 case DW_MACRO_undef_strx
:
6268 READ_ULEB (lineno
, curr
, end
);
6269 READ_ULEB (offset
, curr
, end
);
6270 string
= (const unsigned char *)
6271 fetch_indexed_string (offset
, NULL
, offset_size
, false, 0);
6272 if (op
== DW_MACRO_define_strx
)
6273 printf (" DW_MACRO_define_strx ");
6275 printf (" DW_MACRO_undef_strx ");
6277 printf (_("(with offset %#" PRIx64
") "), offset
);
6278 printf (_("lineno : %d macro : %s\n"),
6283 if (op
>= DW_MACRO_lo_user
&& op
<= DW_MACRO_hi_user
)
6285 printf (_(" <Target Specific macro op: %#x - UNHANDLED"), op
);
6289 if (extended_ops
== NULL
|| extended_ops
[op
] == NULL
)
6291 error (_(" Unknown macro opcode %02x seen\n"), op
);
6296 /* Skip over unhandled opcodes. */
6298 unsigned char *desc
= extended_ops
[op
];
6299 READ_ULEB (nargs
, desc
, end
);
6302 printf (_(" DW_MACRO_%02x\n"), op
);
6305 printf (_(" DW_MACRO_%02x -"), op
);
6306 for (n
= 0; n
< nargs
; n
++)
6310 /* DW_FORM_implicit_const is not expected here. */
6311 SAFE_BYTE_GET_AND_INC (val
, desc
, 1, end
);
6313 = read_and_display_attr_value (0, val
, 0,
6314 start
, curr
, end
, 0, 0,
6315 offset_size
, version
,
6334 display_debug_abbrev (struct dwarf_section
*section
,
6335 void *file ATTRIBUTE_UNUSED
)
6337 abbrev_entry
*entry
;
6338 unsigned char *start
= section
->start
;
6340 introduce (section
, false);
6344 uint64_t offset
= start
- section
->start
;
6345 abbrev_list
*list
= find_and_process_abbrev_set (section
, 0,
6346 section
->size
, offset
,
6351 if (list
->first_abbrev
)
6352 printf (_(" Number TAG (%#" PRIx64
")\n"), offset
);
6354 for (entry
= list
->first_abbrev
; entry
; entry
= entry
->next
)
6358 printf (" %ld %s [%s]\n",
6360 get_TAG_name (entry
->tag
),
6361 entry
->children
? _("has children") : _("no children"));
6363 for (attr
= entry
->first_attr
; attr
; attr
= attr
->next
)
6365 printf (" %-18s %s",
6366 get_AT_name (attr
->attribute
),
6367 get_FORM_name (attr
->form
));
6368 if (attr
->form
== DW_FORM_implicit_const
)
6369 printf (": %" PRId64
, attr
->implicit_const
);
6373 start
= list
->start_of_next_abbrevs
;
6374 free_abbrev_list (list
);
6383 /* Return true when ADDR is the maximum address, when addresses are
6384 POINTER_SIZE bytes long. */
6387 is_max_address (uint64_t addr
, unsigned int pointer_size
)
6389 uint64_t mask
= ~(~(uint64_t) 0 << 1 << (pointer_size
* 8 - 1));
6390 return ((addr
& mask
) == mask
);
6393 /* Display a view pair list starting at *VSTART_PTR and ending at
6394 VLISTEND within SECTION. */
6397 display_view_pair_list (struct dwarf_section
*section
,
6398 unsigned char **vstart_ptr
,
6399 unsigned int debug_info_entry
,
6400 unsigned char *vlistend
)
6402 unsigned char *vstart
= *vstart_ptr
;
6403 unsigned char *section_end
= section
->start
+ section
->size
;
6404 unsigned int pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
6406 if (vlistend
< section_end
)
6407 section_end
= vlistend
;
6411 while (vstart
< section_end
)
6413 uint64_t off
= vstart
- section
->start
;
6414 uint64_t vbegin
, vend
;
6416 READ_ULEB (vbegin
, vstart
, section_end
);
6417 if (vstart
== section_end
)
6420 READ_ULEB (vend
, vstart
, section_end
);
6421 printf (" %8.8" PRIx64
" ", off
);
6423 print_view (vbegin
, pointer_size
);
6424 print_view (vend
, pointer_size
);
6425 printf (_("location view pair\n"));
6429 *vstart_ptr
= vstart
;
6432 /* Display a location list from a normal (ie, non-dwo) .debug_loc section. */
6435 display_loc_list (struct dwarf_section
*section
,
6436 unsigned char **start_ptr
,
6437 unsigned int debug_info_entry
,
6439 uint64_t base_address
,
6440 unsigned char **vstart_ptr
,
6443 unsigned char *start
= *start_ptr
, *vstart
= *vstart_ptr
;
6444 unsigned char *section_end
= section
->start
+ section
->size
;
6446 unsigned int pointer_size
;
6447 unsigned int offset_size
;
6451 unsigned short length
;
6452 int need_frame_base
;
6454 if (debug_info_entry
>= num_debug_info_entries
)
6456 warn (_("No debug information available for loc lists of entry: %u\n"),
6461 cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
6462 pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
6463 offset_size
= debug_information
[debug_info_entry
].offset_size
;
6464 dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
6466 if (pointer_size
< 2 || pointer_size
> 8)
6468 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
6469 pointer_size
, debug_info_entry
);
6475 uint64_t off
= offset
+ (start
- *start_ptr
);
6476 uint64_t vbegin
= -1, vend
= -1;
6478 if (2 * pointer_size
> (size_t) (section_end
- start
))
6480 warn (_("Location list starting at offset %#" PRIx64
6481 " is not terminated.\n"), offset
);
6488 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, section_end
);
6489 SAFE_BYTE_GET_AND_INC (end
, start
, pointer_size
, section_end
);
6491 if (begin
== 0 && end
== 0)
6493 /* PR 18374: In a object file we can have a location list that
6494 starts with a begin and end of 0 because there are relocations
6495 that need to be applied to the addresses. Actually applying
6496 the relocations now does not help as they will probably resolve
6497 to 0, since the object file has not been fully linked. Real
6498 end of list markers will not have any relocations against them. */
6499 if (! reloc_at (section
, off
)
6500 && ! reloc_at (section
, off
+ pointer_size
))
6502 printf (_("<End of list>\n"));
6507 /* Check base address specifiers. */
6508 if (is_max_address (begin
, pointer_size
)
6509 && !is_max_address (end
, pointer_size
))
6512 print_hex (begin
, pointer_size
);
6513 print_hex (end
, pointer_size
);
6514 printf (_("(base address)\n"));
6520 off
= offset
+ (vstart
- *start_ptr
);
6522 READ_ULEB (vbegin
, vstart
, section_end
);
6523 print_view (vbegin
, pointer_size
);
6525 READ_ULEB (vend
, vstart
, section_end
);
6526 print_view (vend
, pointer_size
);
6528 printf (_("views at %8.8" PRIx64
" for:\n %*s "), off
, 8, "");
6531 if (2 > (size_t) (section_end
- start
))
6533 warn (_("Location list starting at offset %#" PRIx64
6534 " is not terminated.\n"), offset
);
6538 SAFE_BYTE_GET_AND_INC (length
, start
, 2, section_end
);
6540 if (length
> (size_t) (section_end
- start
))
6542 warn (_("Location list starting at offset %#" PRIx64
6543 " is not terminated.\n"), offset
);
6547 print_hex (begin
+ base_address
, pointer_size
);
6548 print_hex (end
+ base_address
, pointer_size
);
6551 need_frame_base
= decode_location_expression (start
,
6556 cu_offset
, section
);
6559 if (need_frame_base
&& !has_frame_base
)
6560 printf (_(" [without DW_AT_frame_base]"));
6562 if (begin
== end
&& vbegin
== vend
)
6563 fputs (_(" (start == end)"), stdout
);
6564 else if (begin
> end
|| (begin
== end
&& vbegin
> vend
))
6565 fputs (_(" (start > end)"), stdout
);
6573 *vstart_ptr
= vstart
;
6576 /* Display a location list from a normal (ie, non-dwo) .debug_loclists section. */
6579 display_loclists_list (struct dwarf_section
* section
,
6580 unsigned char ** start_ptr
,
6581 unsigned int debug_info_entry
,
6583 uint64_t base_address
,
6584 unsigned char ** vstart_ptr
,
6587 unsigned char *start
= *start_ptr
;
6588 unsigned char *vstart
= *vstart_ptr
;
6589 unsigned char *section_end
= section
->start
+ section
->size
;
6591 unsigned int pointer_size
;
6592 unsigned int offset_size
;
6593 unsigned int dwarf_version
;
6595 /* Initialize it due to a false compiler warning. */
6596 uint64_t begin
= -1, vbegin
= -1;
6597 uint64_t end
= -1, vend
= -1;
6599 int need_frame_base
;
6601 if (debug_info_entry
>= num_debug_info_entries
)
6603 warn (_("No debug information available for "
6604 "loclists lists of entry: %u\n"),
6609 cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
6610 pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
6611 offset_size
= debug_information
[debug_info_entry
].offset_size
;
6612 dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
6614 if (pointer_size
< 2 || pointer_size
> 8)
6616 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
6617 pointer_size
, debug_info_entry
);
6623 uint64_t off
= offset
+ (start
- *start_ptr
);
6624 enum dwarf_location_list_entry_type llet
;
6626 if (start
+ 1 > section_end
)
6628 warn (_("Location list starting at offset %#" PRIx64
6629 " is not terminated.\n"), offset
);
6636 SAFE_BYTE_GET_AND_INC (llet
, start
, 1, section_end
);
6638 if (vstart
&& (llet
== DW_LLE_offset_pair
6639 || llet
== DW_LLE_start_end
6640 || llet
== DW_LLE_start_length
))
6642 off
= offset
+ (vstart
- *start_ptr
);
6644 READ_ULEB (vbegin
, vstart
, section_end
);
6645 print_view (vbegin
, pointer_size
);
6647 READ_ULEB (vend
, vstart
, section_end
);
6648 print_view (vend
, pointer_size
);
6650 printf (_("views at %8.8" PRIx64
" for:\n %*s "), off
, 8, "");
6655 case DW_LLE_end_of_list
:
6656 printf (_("<End of list>\n"));
6659 case DW_LLE_base_addressx
:
6660 READ_ULEB (base_address
, start
, section_end
);
6661 print_hex (base_address
, pointer_size
);
6662 printf (_("(index into .debug_addr) "));
6663 base_address
= fetch_indexed_addr (base_address
, pointer_size
);
6664 print_hex (base_address
, pointer_size
);
6665 printf (_("(base address)\n"));
6668 case DW_LLE_startx_endx
:
6669 READ_ULEB (begin
, start
, section_end
);
6670 begin
= fetch_indexed_addr (begin
, pointer_size
);
6671 READ_ULEB (end
, start
, section_end
);
6672 end
= fetch_indexed_addr (end
, pointer_size
);
6675 case DW_LLE_startx_length
:
6676 READ_ULEB (begin
, start
, section_end
);
6677 begin
= fetch_indexed_addr (begin
, pointer_size
);
6678 READ_ULEB (end
, start
, section_end
);
6682 case DW_LLE_default_location
:
6686 case DW_LLE_offset_pair
:
6687 READ_ULEB (begin
, start
, section_end
);
6688 begin
+= base_address
;
6689 READ_ULEB (end
, start
, section_end
);
6690 end
+= base_address
;
6693 case DW_LLE_base_address
:
6694 SAFE_BYTE_GET_AND_INC (base_address
, start
, pointer_size
,
6696 print_hex (base_address
, pointer_size
);
6697 printf (_("(base address)\n"));
6700 case DW_LLE_start_end
:
6701 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, section_end
);
6702 SAFE_BYTE_GET_AND_INC (end
, start
, pointer_size
, section_end
);
6705 case DW_LLE_start_length
:
6706 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, section_end
);
6707 READ_ULEB (end
, start
, section_end
);
6711 #ifdef DW_LLE_view_pair
6712 case DW_LLE_view_pair
:
6714 printf (_("View pair entry in loclist with locviews attribute\n"));
6715 READ_ULEB (vbegin
, start
, section_end
);
6716 print_view (vbegin
, pointer_size
);
6718 READ_ULEB (vend
, start
, section_end
);
6719 print_view (vend
, pointer_size
);
6721 printf (_("views for:\n"));
6726 error (_("Invalid location list entry type %d\n"), llet
);
6730 if (llet
== DW_LLE_end_of_list
)
6733 if (llet
== DW_LLE_base_address
6734 || llet
== DW_LLE_base_addressx
)
6737 if (start
== section_end
)
6739 warn (_("Location list starting at offset %#" PRIx64
6740 " is not terminated.\n"), offset
);
6743 READ_ULEB (length
, start
, section_end
);
6745 if (length
> (size_t) (section_end
- start
))
6747 warn (_("Location list starting at offset %#" PRIx64
6748 " is not terminated.\n"), offset
);
6752 print_hex (begin
, pointer_size
);
6753 print_hex (end
, pointer_size
);
6756 need_frame_base
= decode_location_expression (start
,
6761 cu_offset
, section
);
6764 if (need_frame_base
&& !has_frame_base
)
6765 printf (_(" [without DW_AT_frame_base]"));
6767 if (begin
== end
&& vbegin
== vend
)
6768 fputs (_(" (start == end)"), stdout
);
6769 else if (begin
> end
|| (begin
== end
&& vbegin
> vend
))
6770 fputs (_(" (start > end)"), stdout
);
6778 if (vbegin
!= (uint64_t) -1 || vend
!= (uint64_t) -1)
6779 printf (_("Trailing view pair not used in a range"));
6782 *vstart_ptr
= vstart
;
6785 /* Print a .debug_addr table index in decimal, surrounded by square brackets,
6786 right-adjusted in a field of length LEN, and followed by a space. */
6789 print_addr_index (unsigned int idx
, unsigned int len
)
6791 static char buf
[15];
6792 snprintf (buf
, sizeof (buf
), "[%d]", idx
);
6793 printf ("%*s ", len
, buf
);
6796 /* Display a location list from a .dwo section. It uses address indexes rather
6797 than embedded addresses. This code closely follows display_loc_list, but the
6798 two are sufficiently different that combining things is very ugly. */
6801 display_loc_list_dwo (struct dwarf_section
*section
,
6802 unsigned char **start_ptr
,
6803 unsigned int debug_info_entry
,
6805 unsigned char **vstart_ptr
,
6808 unsigned char *start
= *start_ptr
, *vstart
= *vstart_ptr
;
6809 unsigned char *section_end
= section
->start
+ section
->size
;
6811 unsigned int pointer_size
;
6812 unsigned int offset_size
;
6815 unsigned short length
;
6816 int need_frame_base
;
6819 if (debug_info_entry
>= num_debug_info_entries
)
6821 warn (_("No debug information for loc lists of entry: %u\n"),
6826 cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
6827 pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
6828 offset_size
= debug_information
[debug_info_entry
].offset_size
;
6829 dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
6831 if (pointer_size
< 2 || pointer_size
> 8)
6833 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
6834 pointer_size
, debug_info_entry
);
6841 print_hex (offset
+ (start
- *start_ptr
), 4);
6843 if (start
>= section_end
)
6845 warn (_("Location list starting at offset %#" PRIx64
6846 " is not terminated.\n"), offset
);
6850 SAFE_BYTE_GET_AND_INC (entry_type
, start
, 1, section_end
);
6863 uint64_t off
= offset
+ (vstart
- *start_ptr
);
6865 READ_ULEB (view
, vstart
, section_end
);
6866 print_view (view
, 8);
6868 READ_ULEB (view
, vstart
, section_end
);
6869 print_view (view
, 8);
6871 printf (_("views at %8.8" PRIx64
" for:\n %*s "), off
, 8, "");
6879 case 0: /* A terminating entry. */
6881 *vstart_ptr
= vstart
;
6882 printf (_("<End of list>\n"));
6884 case 1: /* A base-address entry. */
6885 READ_ULEB (idx
, start
, section_end
);
6886 print_addr_index (idx
, 8);
6887 printf ("%*s", 9 + (vstart
? 2 * 6 : 0), "");
6888 printf (_("(base address selection entry)\n"));
6890 case 2: /* A start/end entry. */
6891 READ_ULEB (idx
, start
, section_end
);
6892 print_addr_index (idx
, 8);
6893 READ_ULEB (idx
, start
, section_end
);
6894 print_addr_index (idx
, 8);
6896 case 3: /* A start/length entry. */
6897 READ_ULEB (idx
, start
, section_end
);
6898 print_addr_index (idx
, 8);
6899 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
6900 printf ("%08x ", idx
);
6902 case 4: /* An offset pair entry. */
6903 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
6904 printf ("%08x ", idx
);
6905 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
6906 printf ("%08x ", idx
);
6909 warn (_("Unknown location list entry type 0x%x.\n"), entry_type
);
6911 *vstart_ptr
= vstart
;
6915 if (2 > (size_t) (section_end
- start
))
6917 warn (_("Location list starting at offset %#" PRIx64
6918 " is not terminated.\n"), offset
);
6922 SAFE_BYTE_GET_AND_INC (length
, start
, 2, section_end
);
6923 if (length
> (size_t) (section_end
- start
))
6925 warn (_("Location list starting at offset %#" PRIx64
6926 " is not terminated.\n"), offset
);
6931 need_frame_base
= decode_location_expression (start
,
6936 cu_offset
, section
);
6939 if (need_frame_base
&& !has_frame_base
)
6940 printf (_(" [without DW_AT_frame_base]"));
6948 *vstart_ptr
= vstart
;
6951 /* Sort array of indexes in ascending order of loc_offsets[idx] and
6954 static uint64_t *loc_offsets
, *loc_views
;
6957 loc_offsets_compar (const void *ap
, const void *bp
)
6959 uint64_t a
= loc_offsets
[*(const unsigned int *) ap
];
6960 uint64_t b
= loc_offsets
[*(const unsigned int *) bp
];
6962 int ret
= (a
> b
) - (b
> a
);
6966 a
= loc_views
[*(const unsigned int *) ap
];
6967 b
= loc_views
[*(const unsigned int *) bp
];
6969 ret
= (a
> b
) - (b
> a
);
6975 display_offset_entry_loclists (struct dwarf_section
*section
)
6977 unsigned char * start
= section
->start
;
6978 unsigned char * const end
= start
+ section
->size
;
6980 introduce (section
, false);
6985 unsigned short version
;
6986 unsigned char address_size
;
6987 unsigned char segment_selector_size
;
6988 uint32_t offset_entry_count
;
6992 printf (_("Table at Offset %#tx\n"), start
- section
->start
);
6994 SAFE_BYTE_GET_AND_INC (length
, start
, 4, end
);
6995 if (length
== 0xffffffff)
6998 SAFE_BYTE_GET_AND_INC (length
, start
, 8, end
);
7003 SAFE_BYTE_GET_AND_INC (version
, start
, 2, end
);
7004 SAFE_BYTE_GET_AND_INC (address_size
, start
, 1, end
);
7005 SAFE_BYTE_GET_AND_INC (segment_selector_size
, start
, 1, end
);
7006 SAFE_BYTE_GET_AND_INC (offset_entry_count
, start
, 4, end
);
7008 printf (_(" Length: %#" PRIx64
"\n"), length
);
7009 printf (_(" DWARF version: %u\n"), version
);
7010 printf (_(" Address size: %u\n"), address_size
);
7011 printf (_(" Segment size: %u\n"), segment_selector_size
);
7012 printf (_(" Offset entries: %u\n"), offset_entry_count
);
7016 warn (_("The %s section contains a corrupt or "
7017 "unsupported version number: %d.\n"),
7018 section
->name
, version
);
7022 if (segment_selector_size
!= 0)
7024 warn (_("The %s section contains an "
7025 "unsupported segment selector size: %d.\n"),
7026 section
->name
, segment_selector_size
);
7030 if (offset_entry_count
== 0)
7032 warn (_("The %s section contains a table without offset\n"),
7037 printf (_("\n Offset Entries starting at %#tx:\n"),
7038 start
- section
->start
);
7040 for (i
= 0; i
< offset_entry_count
; i
++)
7044 SAFE_BYTE_GET_AND_INC (entry
, start
, is_64bit
? 8 : 4, end
);
7045 printf (_(" [%6u] %#" PRIx64
"\n"), i
, entry
);
7052 for (j
= 1, i
= 0; i
< offset_entry_count
;)
7055 uint64_t base_address
= 0;
7058 uint64_t off
= start
- section
->start
;
7062 printf (_(" Offset Entry %u\n"), i
);
7069 SAFE_BYTE_GET_AND_INC (lle
, start
, 1, end
);
7073 case DW_LLE_end_of_list
:
7074 printf (_("<End of list>\n\n"));
7078 case DW_LLE_base_addressx
:
7079 READ_ULEB (base_address
, start
, end
);
7080 print_hex (base_address
, address_size
);
7081 printf (_("(index into .debug_addr) "));
7082 base_address
= fetch_indexed_addr (base_address
, address_size
);
7083 print_hex (base_address
, address_size
);
7084 printf (_("(base address)\n"));
7087 case DW_LLE_startx_endx
:
7088 READ_ULEB (begin
, start
, end
);
7089 begin
= fetch_indexed_addr (begin
, address_size
);
7090 READ_ULEB (finish
, start
, end
);
7091 finish
= fetch_indexed_addr (finish
, address_size
);
7094 case DW_LLE_startx_length
:
7095 READ_ULEB (begin
, start
, end
);
7096 begin
= fetch_indexed_addr (begin
, address_size
);
7097 READ_ULEB (finish
, start
, end
);
7101 case DW_LLE_offset_pair
:
7102 READ_ULEB (begin
, start
, end
);
7103 begin
+= base_address
;
7104 READ_ULEB (finish
, start
, end
);
7105 finish
+= base_address
;
7108 case DW_LLE_default_location
:
7112 case DW_LLE_base_address
:
7113 SAFE_BYTE_GET_AND_INC (base_address
, start
, address_size
, end
);
7114 print_hex (base_address
, address_size
);
7115 printf (_("(base address)\n"));
7118 case DW_LLE_start_end
:
7119 SAFE_BYTE_GET_AND_INC (begin
, start
, address_size
, end
);
7120 SAFE_BYTE_GET_AND_INC (finish
, start
, address_size
, end
);
7123 case DW_LLE_start_length
:
7124 SAFE_BYTE_GET_AND_INC (begin
, start
, address_size
, end
);
7125 READ_ULEB (finish
, start
, end
);
7130 error (_("Invalid location list entry type %d\n"), lle
);
7136 warn (_("Location list starting at offset %#" PRIx64
7137 " is not terminated.\n"), off
);
7141 print_hex (begin
, address_size
);
7142 print_hex (finish
, address_size
);
7144 if (begin
== finish
)
7145 fputs (_("(start == end)"), stdout
);
7146 else if (begin
> finish
)
7147 fputs (_("(start > end)"), stdout
);
7149 /* Read the counted location descriptions. */
7150 READ_ULEB (length
, start
, end
);
7152 if (length
> (size_t) (end
- start
))
7154 warn (_("Location list starting at offset %#" PRIx64
7155 " is not terminated.\n"), off
);
7159 (void) decode_location_expression (start
, address_size
, address_size
,
7160 version
, length
, 0, section
);
7167 while (start
< end
);
7173 display_debug_loc (struct dwarf_section
*section
, void *file
)
7175 unsigned char *start
= section
->start
, *vstart
= NULL
;
7177 unsigned char *section_begin
= start
;
7178 unsigned int num_loc_list
= 0;
7179 uint64_t last_offset
= 0;
7180 uint64_t last_view
= 0;
7181 unsigned int first
= 0;
7184 int seen_first_offset
= 0;
7185 int locs_sorted
= 1;
7186 unsigned char *next
= start
, *vnext
= vstart
;
7187 unsigned int *array
= NULL
;
7188 const char *suffix
= strrchr (section
->name
, '.');
7189 bool is_dwo
= false;
7190 int is_loclists
= strstr (section
->name
, "debug_loclists") != NULL
;
7191 uint64_t header_size
= 0;
7193 if (suffix
&& strcmp (suffix
, ".dwo") == 0)
7196 bytes
= section
->size
;
7200 printf (_("\nThe %s section is empty.\n"), section
->name
);
7206 unsigned char *hdrptr
= section_begin
;
7208 unsigned short ll_version
;
7209 unsigned char *end
= section_begin
+ section
->size
;
7210 unsigned char address_size
, segment_selector_size
;
7211 uint32_t offset_entry_count
;
7213 SAFE_BYTE_GET_AND_INC (ll_length
, hdrptr
, 4, end
);
7214 if (ll_length
== 0xffffffff)
7215 SAFE_BYTE_GET_AND_INC (ll_length
, hdrptr
, 8, end
);
7217 SAFE_BYTE_GET_AND_INC (ll_version
, hdrptr
, 2, end
);
7218 if (ll_version
!= 5)
7220 warn (_("The %s section contains corrupt or "
7221 "unsupported version number: %d.\n"),
7222 section
->name
, ll_version
);
7226 SAFE_BYTE_GET_AND_INC (address_size
, hdrptr
, 1, end
);
7228 SAFE_BYTE_GET_AND_INC (segment_selector_size
, hdrptr
, 1, end
);
7229 if (segment_selector_size
!= 0)
7231 warn (_("The %s section contains "
7232 "unsupported segment selector size: %d.\n"),
7233 section
->name
, segment_selector_size
);
7237 SAFE_BYTE_GET_AND_INC (offset_entry_count
, hdrptr
, 4, end
);
7239 if (offset_entry_count
!= 0)
7240 return display_offset_entry_loclists (section
);
7242 header_size
= hdrptr
- section_begin
;
7245 if (load_debug_info (file
) == 0)
7247 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
7252 /* Check the order of location list in .debug_info section. If
7253 offsets of location lists are in the ascending order, we can
7254 use `debug_information' directly. */
7255 for (i
= 0; i
< num_debug_info_entries
; i
++)
7259 num
= debug_information
[i
].num_loc_offsets
;
7260 if (num
> num_loc_list
)
7263 /* Check if we can use `debug_information' directly. */
7264 if (locs_sorted
&& num
!= 0)
7266 if (!seen_first_offset
)
7268 /* This is the first location list. */
7269 last_offset
= debug_information
[i
].loc_offsets
[0];
7270 last_view
= debug_information
[i
].loc_views
[0];
7272 seen_first_offset
= 1;
7278 for (; j
< num
; j
++)
7281 debug_information
[i
].loc_offsets
[j
]
7282 || (last_offset
== debug_information
[i
].loc_offsets
[j
]
7283 && last_view
> debug_information
[i
].loc_views
[j
]))
7288 last_offset
= debug_information
[i
].loc_offsets
[j
];
7289 last_view
= debug_information
[i
].loc_views
[j
];
7294 if (!seen_first_offset
)
7295 error (_("No location lists in .debug_info section!\n"));
7297 if (debug_information
[first
].num_loc_offsets
> 0
7298 && debug_information
[first
].loc_offsets
[0] != header_size
7299 && debug_information
[first
].loc_views
[0] != header_size
)
7300 warn (_("Location lists in %s section start at %#" PRIx64
7301 " rather than %#" PRIx64
"\n"),
7302 section
->name
, debug_information
[first
].loc_offsets
[0],
7306 array
= (unsigned int *) xcmalloc (num_loc_list
, sizeof (unsigned int));
7308 introduce (section
, false);
7310 if (reloc_at (section
, 0))
7311 printf (_(" Warning: This section has relocations - addresses seen here may not be accurate.\n\n"));
7313 printf (_(" Offset Begin End Expression\n"));
7315 for (i
= first
; i
< num_debug_info_entries
; i
++)
7317 uint64_t offset
= 0, voffset
= 0;
7318 uint64_t base_address
;
7324 for (k
= 0; k
< debug_information
[i
].num_loc_offsets
; k
++)
7326 loc_offsets
= debug_information
[i
].loc_offsets
;
7327 loc_views
= debug_information
[i
].loc_views
;
7328 qsort (array
, debug_information
[i
].num_loc_offsets
,
7329 sizeof (*array
), loc_offsets_compar
);
7332 /* .debug_loclists has a per-unit header.
7333 Update start if we are detecting it. */
7334 if (debug_information
[i
].dwarf_version
== 5)
7336 j
= locs_sorted
? 0 : array
[0];
7338 if (debug_information
[i
].num_loc_offsets
)
7339 offset
= debug_information
[i
].loc_offsets
[j
];
7341 if (debug_information
[i
].num_loc_views
)
7342 voffset
= debug_information
[i
].loc_views
[j
];
7344 /* Assume that the size of the header is constant across CUs. */
7345 if (((start
- section_begin
) + header_size
== offset
)
7346 || ((start
-section_begin
) + header_size
== voffset
))
7347 start
+= header_size
;
7350 int adjacent_view_loclists
= 1;
7351 for (k
= 0; k
< debug_information
[i
].num_loc_offsets
; k
++)
7353 j
= locs_sorted
? k
: array
[k
];
7355 && (debug_information
[i
].loc_offsets
[locs_sorted
7356 ? k
- 1 : array
[k
- 1]]
7357 == debug_information
[i
].loc_offsets
[j
])
7358 && (debug_information
[i
].loc_views
[locs_sorted
7359 ? k
- 1 : array
[k
- 1]]
7360 == debug_information
[i
].loc_views
[j
]))
7362 has_frame_base
= debug_information
[i
].have_frame_base
[j
];
7363 offset
= debug_information
[i
].loc_offsets
[j
];
7364 next
= section_begin
+ offset
;
7365 voffset
= debug_information
[i
].loc_views
[j
];
7366 if (voffset
!= (uint64_t) -1)
7367 vnext
= section_begin
+ voffset
;
7370 base_address
= debug_information
[i
].base_address
;
7372 if (vnext
&& vnext
< next
)
7375 display_view_pair_list (section
, &vstart
, i
, next
);
7382 if (vnext
&& vnext
< next
)
7383 warn (_("There is a hole [%#tx - %#" PRIx64
"]"
7384 " in %s section.\n"),
7385 start
- section_begin
, voffset
, section
->name
);
7387 warn (_("There is a hole [%#tx - %#" PRIx64
"]"
7388 " in %s section.\n"),
7389 start
- section_begin
, offset
, section
->name
);
7391 else if (start
> next
)
7392 warn (_("There is an overlap [%#tx - %#" PRIx64
"]"
7393 " in %s section.\n"),
7394 start
- section_begin
, offset
, section
->name
);
7398 if (offset
>= bytes
)
7400 warn (_("Offset %#" PRIx64
" is bigger than %s section size.\n"),
7401 offset
, section
->name
);
7405 if (vnext
&& voffset
>= bytes
)
7407 warn (_("View Offset %#" PRIx64
" is bigger than %s section size.\n"),
7408 voffset
, section
->name
);
7415 display_loc_list_dwo (section
, &start
, i
, offset
,
7416 &vstart
, has_frame_base
);
7418 display_loc_list (section
, &start
, i
, offset
, base_address
,
7419 &vstart
, has_frame_base
);
7424 warn (_("DWO is not yet supported.\n"));
7426 display_loclists_list (section
, &start
, i
, offset
, base_address
,
7427 &vstart
, has_frame_base
);
7430 /* FIXME: this arrangement is quite simplistic. Nothing
7431 requires locview lists to be adjacent to corresponding
7432 loclists, and a single loclist could be augmented by
7433 different locview lists, and vice-versa, unlikely as it
7434 is that it would make sense to do so. Hopefully we'll
7435 have view pair support built into loclists before we ever
7436 need to address all these possibilities. */
7437 if (adjacent_view_loclists
&& vnext
7438 && vnext
!= start
&& vstart
!= next
)
7440 adjacent_view_loclists
= 0;
7441 warn (_("Hole and overlap detection requires adjacent view lists and loclists.\n"));
7444 if (vnext
&& vnext
== start
)
7445 display_view_pair_list (section
, &start
, i
, vstart
);
7449 if (start
< section
->start
+ section
->size
)
7450 warn (ngettext ("There is %ld unused byte at the end of section %s\n",
7451 "There are %ld unused bytes at the end of section %s\n",
7452 (long) (section
->start
+ section
->size
- start
)),
7453 (long) (section
->start
+ section
->size
- start
), section
->name
);
7460 display_debug_str (struct dwarf_section
*section
,
7461 void *file ATTRIBUTE_UNUSED
)
7463 unsigned char *start
= section
->start
;
7464 uint64_t bytes
= section
->size
;
7465 uint64_t addr
= section
->address
;
7469 printf (_("\nThe %s section is empty.\n"), section
->name
);
7473 introduce (section
, false);
7481 lbytes
= (bytes
> 16 ? 16 : bytes
);
7483 printf (" 0x%8.8" PRIx64
" ", addr
);
7485 for (j
= 0; j
< 16; j
++)
7488 printf ("%2.2x", start
[j
]);
7496 for (j
= 0; j
< lbytes
; j
++)
7499 if (k
>= ' ' && k
< 0x80)
7518 display_debug_info (struct dwarf_section
*section
, void *file
)
7520 return process_debug_info (section
, file
, section
->abbrev_sec
, false, false);
7524 display_debug_types (struct dwarf_section
*section
, void *file
)
7526 return process_debug_info (section
, file
, section
->abbrev_sec
, false, true);
7530 display_trace_info (struct dwarf_section
*section
, void *file
)
7532 return process_debug_info (section
, file
, section
->abbrev_sec
, false, true);
7536 display_debug_aranges (struct dwarf_section
*section
,
7537 void *file ATTRIBUTE_UNUSED
)
7539 unsigned char *start
= section
->start
;
7540 unsigned char *end
= start
+ section
->size
;
7542 introduce (section
, false);
7544 /* It does not matter if this load fails,
7545 we test for that later on. */
7546 load_debug_info (file
);
7550 unsigned char *hdrptr
;
7551 DWARF2_Internal_ARange arange
;
7552 unsigned char *addr_ranges
;
7556 unsigned char address_size
;
7557 unsigned int offset_size
;
7558 unsigned char *end_ranges
;
7561 sec_off
= hdrptr
- section
->start
;
7563 SAFE_BYTE_GET_AND_INC (arange
.ar_length
, hdrptr
, 4, end
);
7564 if (arange
.ar_length
== 0xffffffff)
7566 SAFE_BYTE_GET_AND_INC (arange
.ar_length
, hdrptr
, 8, end
);
7572 if (arange
.ar_length
> (size_t) (end
- hdrptr
))
7574 warn (_("Debug info is corrupted, %s header at %#" PRIx64
7575 " has length %#" PRIx64
"\n"),
7576 section
->name
, sec_off
, arange
.ar_length
);
7579 end_ranges
= hdrptr
+ arange
.ar_length
;
7581 SAFE_BYTE_GET_AND_INC (arange
.ar_version
, hdrptr
, 2, end_ranges
);
7582 SAFE_BYTE_GET_AND_INC (arange
.ar_info_offset
, hdrptr
, offset_size
,
7585 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
7586 && num_debug_info_entries
> 0
7587 && find_debug_info_for_offset (arange
.ar_info_offset
) == NULL
)
7588 warn (_(".debug_info offset of %#" PRIx64
7589 " in %s section does not point to a CU header.\n"),
7590 arange
.ar_info_offset
, section
->name
);
7592 SAFE_BYTE_GET_AND_INC (arange
.ar_pointer_size
, hdrptr
, 1, end_ranges
);
7593 SAFE_BYTE_GET_AND_INC (arange
.ar_segment_size
, hdrptr
, 1, end_ranges
);
7595 if (arange
.ar_version
!= 2 && arange
.ar_version
!= 3)
7597 /* PR 19872: A version number of 0 probably means that there is
7598 padding at the end of the .debug_aranges section. Gold puts
7599 it there when performing an incremental link, for example.
7600 So do not generate a warning in this case. */
7601 if (arange
.ar_version
)
7602 warn (_("Only DWARF 2 and 3 aranges are currently supported.\n"));
7606 printf (_(" Length: %" PRId64
"\n"), arange
.ar_length
);
7607 printf (_(" Version: %d\n"), arange
.ar_version
);
7608 printf (_(" Offset into .debug_info: %#" PRIx64
"\n"),
7609 arange
.ar_info_offset
);
7610 printf (_(" Pointer Size: %d\n"), arange
.ar_pointer_size
);
7611 printf (_(" Segment Size: %d\n"), arange
.ar_segment_size
);
7613 address_size
= arange
.ar_pointer_size
+ arange
.ar_segment_size
;
7615 /* PR 17512: file: 001-108546-0.001:0.1. */
7616 if (address_size
== 0 || address_size
> 8)
7618 error (_("Invalid address size in %s section!\n"),
7623 /* The DWARF spec does not require that the address size be a power
7624 of two, but we do. This will have to change if we ever encounter
7625 an uneven architecture. */
7626 if ((address_size
& (address_size
- 1)) != 0)
7628 warn (_("Pointer size + Segment size is not a power of two.\n"));
7632 if (address_size
> 4)
7633 printf (_("\n Address Length\n"));
7635 printf (_("\n Address Length\n"));
7637 addr_ranges
= hdrptr
;
7639 /* Must pad to an alignment boundary that is twice the address size. */
7640 addr_ranges
+= (2 * address_size
- 1
7641 - (hdrptr
- start
- 1) % (2 * address_size
));
7643 while (2 * address_size
<= end_ranges
- addr_ranges
)
7645 SAFE_BYTE_GET_AND_INC (address
, addr_ranges
, address_size
,
7647 SAFE_BYTE_GET_AND_INC (length
, addr_ranges
, address_size
,
7650 print_hex (address
, address_size
);
7651 print_hex_ns (length
, address_size
);
7663 /* Comparison function for qsort. */
7665 comp_addr_base (const void * v0
, const void * v1
)
7667 debug_info
*info0
= *(debug_info
**) v0
;
7668 debug_info
*info1
= *(debug_info
**) v1
;
7669 return info0
->addr_base
- info1
->addr_base
;
7672 /* Display the debug_addr section. */
7674 display_debug_addr (struct dwarf_section
*section
,
7677 debug_info
**debug_addr_info
;
7678 unsigned char *entry
;
7682 unsigned char * header
;
7684 if (section
->size
== 0)
7686 printf (_("\nThe %s section is empty.\n"), section
->name
);
7690 if (load_debug_info (file
) == 0)
7692 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
7697 introduce (section
, false);
7699 /* PR 17531: file: cf38d01b.
7700 We use xcalloc because a corrupt file may not have initialised all of the
7701 fields in the debug_info structure, which means that the sort below might
7702 try to move uninitialised data. */
7703 debug_addr_info
= (debug_info
**) xcalloc ((num_debug_info_entries
+ 1),
7704 sizeof (debug_info
*));
7707 for (i
= 0; i
< num_debug_info_entries
; i
++)
7708 if (debug_information
[i
].addr_base
!= DEBUG_INFO_UNAVAILABLE
)
7710 /* PR 17531: file: cf38d01b. */
7711 if (debug_information
[i
].addr_base
>= section
->size
)
7712 warn (_("Corrupt address base (%#" PRIx64
")"
7713 " found in debug section %u\n"),
7714 debug_information
[i
].addr_base
, i
);
7716 debug_addr_info
[count
++] = debug_information
+ i
;
7719 /* Add a sentinel to make iteration convenient. */
7720 debug_addr_info
[count
] = (debug_info
*) xmalloc (sizeof (debug_info
));
7721 debug_addr_info
[count
]->addr_base
= section
->size
;
7722 qsort (debug_addr_info
, count
, sizeof (debug_info
*), comp_addr_base
);
7724 header
= section
->start
;
7725 for (i
= 0; i
< count
; i
++)
7728 unsigned int address_size
= debug_addr_info
[i
]->pointer_size
;
7730 printf (_(" For compilation unit at offset %#" PRIx64
":\n"),
7731 debug_addr_info
[i
]->cu_offset
);
7733 printf (_("\tIndex\tAddress\n"));
7734 entry
= section
->start
+ debug_addr_info
[i
]->addr_base
;
7735 if (debug_addr_info
[i
]->dwarf_version
>= 5)
7737 size_t header_size
= entry
- header
;
7738 unsigned char *curr_header
= header
;
7741 int segment_selector_size
;
7743 if (header_size
!= 8 && header_size
!= 16)
7745 warn (_("Corrupt %s section: expecting header size of 8 or 16, but found %zd instead\n"),
7746 section
->name
, header_size
);
7750 SAFE_BYTE_GET_AND_INC (length
, curr_header
, 4, entry
);
7751 if (length
== 0xffffffff)
7752 SAFE_BYTE_GET_AND_INC (length
, curr_header
, 8, entry
);
7753 if (length
> (size_t) (section
->start
+ section
->size
- curr_header
)
7754 || length
< (size_t) (entry
- curr_header
))
7756 warn (_("Corrupt %s section: unit_length field of %#" PRIx64
7757 " is invalid\n"), section
->name
, length
);
7760 end
= curr_header
+ length
;
7761 SAFE_BYTE_GET_AND_INC (version
, curr_header
, 2, entry
);
7763 warn (_("Corrupt %s section: expecting version number 5 in header but found %d instead\n"),
7764 section
->name
, version
);
7766 SAFE_BYTE_GET_AND_INC (address_size
, curr_header
, 1, entry
);
7767 SAFE_BYTE_GET_AND_INC (segment_selector_size
, curr_header
, 1, entry
);
7768 address_size
+= segment_selector_size
;
7771 end
= section
->start
+ debug_addr_info
[i
+ 1]->addr_base
;
7776 if (address_size
< 1 || address_size
> sizeof (uint64_t))
7778 warn (_("Corrupt %s section: address size (%x) is wrong"),
7779 section
->name
, address_size
);
7783 while ((size_t) (end
- entry
) >= address_size
)
7785 uint64_t base
= byte_get (entry
, address_size
);
7786 printf (_("\t%d:\t"), idx
);
7787 print_hex_ns (base
, address_size
);
7789 entry
+= address_size
;
7795 free (debug_addr_info
);
7799 /* Display the .debug_str_offsets and .debug_str_offsets.dwo sections. */
7802 display_debug_str_offsets (struct dwarf_section
*section
,
7803 void *file ATTRIBUTE_UNUSED
)
7807 if (section
->size
== 0)
7809 printf (_("\nThe %s section is empty.\n"), section
->name
);
7813 unsigned char *start
= section
->start
;
7814 unsigned char *end
= start
+ section
->size
;
7815 unsigned char *curr
= start
;
7816 uint64_t debug_str_offsets_hdr_len
;
7818 const char *suffix
= strrchr (section
->name
, '.');
7819 bool dwo
= suffix
&& strcmp (suffix
, ".dwo") == 0;
7822 load_debug_section_with_follow (str_dwo
, file
);
7824 load_debug_section_with_follow (str
, file
);
7826 introduce (section
, false);
7831 uint64_t entry_length
;
7833 SAFE_BYTE_GET_AND_INC (length
, curr
, 4, end
);
7834 /* FIXME: We assume that this means 64-bit DWARF is being used. */
7835 if (length
== 0xffffffff)
7837 SAFE_BYTE_GET_AND_INC (length
, curr
, 8, end
);
7839 debug_str_offsets_hdr_len
= 16;
7844 debug_str_offsets_hdr_len
= 8;
7847 unsigned char *entries_end
;
7850 /* This is probably an old style .debug_str_offset section which
7851 just contains offsets and no header (and the first offset is 0). */
7852 length
= section
->size
;
7853 curr
= section
->start
;
7856 printf (_(" Length: %#" PRIx64
"\n"), length
);
7857 printf (_(" Index Offset [String]\n"));
7861 if (length
<= (size_t) (end
- curr
))
7862 entries_end
= curr
+ length
;
7865 warn (_("Section %s is too small %#" PRIx64
"\n"),
7866 section
->name
, section
->size
);
7871 SAFE_BYTE_GET_AND_INC (version
, curr
, 2, entries_end
);
7873 warn (_("Unexpected version number in str_offset header: %#x\n"), version
);
7876 SAFE_BYTE_GET_AND_INC (padding
, curr
, 2, entries_end
);
7878 warn (_("Unexpected value in str_offset header's padding field: %#x\n"), padding
);
7880 printf (_(" Length: %#" PRIx64
"\n"), length
);
7881 printf (_(" Version: %#x\n"), version
);
7882 printf (_(" Index Offset [String]\n"));
7885 for (idx
= 0; curr
< entries_end
; idx
++)
7888 const unsigned char * string
;
7890 if ((size_t) (entries_end
- curr
) < entry_length
)
7891 /* Not enough space to read one entry_length, give up. */
7894 SAFE_BYTE_GET_AND_INC (offset
, curr
, entry_length
, entries_end
);
7896 string
= (const unsigned char *)
7897 fetch_indexed_string (idx
, NULL
, entry_length
, dwo
, debug_str_offsets_hdr_len
);
7899 string
= fetch_indirect_string (offset
);
7901 printf (" %8lu ", idx
);
7902 print_hex (offset
, entry_length
);
7903 printf (" %s\n", string
);
7910 /* Each debug_information[x].range_lists[y] gets this representation for
7911 sorting purposes. */
7915 /* The debug_information[x].range_lists[y] value. */
7916 uint64_t ranges_offset
;
7918 /* Original debug_information to find parameters of the data. */
7919 debug_info
*debug_info_p
;
7922 /* Sort struct range_entry in ascending order of its RANGES_OFFSET. */
7925 range_entry_compar (const void *ap
, const void *bp
)
7927 const struct range_entry
*a_re
= (const struct range_entry
*) ap
;
7928 const struct range_entry
*b_re
= (const struct range_entry
*) bp
;
7929 const uint64_t a
= a_re
->ranges_offset
;
7930 const uint64_t b
= b_re
->ranges_offset
;
7932 return (a
> b
) - (b
> a
);
7936 display_debug_ranges_list (unsigned char * start
,
7937 unsigned char * finish
,
7938 unsigned int pointer_size
,
7940 uint64_t base_address
)
7942 while (start
< finish
)
7947 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
7948 if (start
>= finish
)
7950 SAFE_SIGNED_BYTE_GET_AND_INC (end
, start
, pointer_size
, finish
);
7953 print_hex (offset
, 4);
7955 if (begin
== 0 && end
== 0)
7957 printf (_("<End of list>\n"));
7961 /* Check base address specifiers. */
7962 if (is_max_address (begin
, pointer_size
)
7963 && !is_max_address (end
, pointer_size
))
7966 print_hex (begin
, pointer_size
);
7967 print_hex (end
, pointer_size
);
7968 printf ("(base address)\n");
7972 print_hex (begin
+ base_address
, pointer_size
);
7973 print_hex_ns (end
+ base_address
, pointer_size
);
7976 fputs (_(" (start == end)"), stdout
);
7977 else if (begin
> end
)
7978 fputs (_(" (start > end)"), stdout
);
7984 static unsigned char *
7985 display_debug_rnglists_list (unsigned char * start
,
7986 unsigned char * finish
,
7987 unsigned int pointer_size
,
7989 uint64_t base_address
,
7990 unsigned int offset_size
)
7992 unsigned char *next
= start
;
7993 unsigned int debug_addr_section_hdr_len
;
7995 if (offset_size
== 4)
7996 debug_addr_section_hdr_len
= 8;
7998 debug_addr_section_hdr_len
= 16;
8002 uint64_t off
= offset
+ (start
- next
);
8003 enum dwarf_range_list_entry rlet
;
8004 /* Initialize it due to a false compiler warning. */
8005 uint64_t begin
= -1, length
, end
= -1;
8007 if (start
>= finish
)
8009 warn (_("Range list starting at offset %#" PRIx64
8010 " is not terminated.\n"), offset
);
8017 SAFE_BYTE_GET_AND_INC (rlet
, start
, 1, finish
);
8021 case DW_RLE_end_of_list
:
8022 printf (_("<End of list>\n"));
8024 case DW_RLE_base_addressx
:
8025 READ_ULEB (base_address
, start
, finish
);
8026 print_hex (base_address
, pointer_size
);
8027 printf (_("(base address index) "));
8028 base_address
= fetch_indexed_addr ((base_address
* pointer_size
)
8029 + debug_addr_section_hdr_len
, pointer_size
);
8030 print_hex (base_address
, pointer_size
);
8031 printf (_("(base address)\n"));
8033 case DW_RLE_startx_endx
:
8034 READ_ULEB (begin
, start
, finish
);
8035 READ_ULEB (end
, start
, finish
);
8036 begin
= fetch_indexed_addr ((begin
* pointer_size
)
8037 + debug_addr_section_hdr_len
, pointer_size
);
8038 end
= fetch_indexed_addr ((begin
* pointer_size
)
8039 + debug_addr_section_hdr_len
, pointer_size
);
8041 case DW_RLE_startx_length
:
8042 READ_ULEB (begin
, start
, finish
);
8043 READ_ULEB (length
, start
, finish
);
8044 begin
= fetch_indexed_addr ((begin
* pointer_size
)
8045 + debug_addr_section_hdr_len
, pointer_size
);
8046 end
= begin
+ length
;
8048 case DW_RLE_offset_pair
:
8049 READ_ULEB (begin
, start
, finish
);
8050 READ_ULEB (end
, start
, finish
);
8052 case DW_RLE_base_address
:
8053 SAFE_BYTE_GET_AND_INC (base_address
, start
, pointer_size
, finish
);
8054 print_hex (base_address
, pointer_size
);
8055 printf (_("(base address)\n"));
8057 case DW_RLE_start_end
:
8058 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
8059 SAFE_BYTE_GET_AND_INC (end
, start
, pointer_size
, finish
);
8061 case DW_RLE_start_length
:
8062 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
8063 READ_ULEB (length
, start
, finish
);
8064 end
= begin
+ length
;
8067 error (_("Invalid range list entry type %d\n"), rlet
);
8068 rlet
= DW_RLE_end_of_list
;
8072 if (rlet
== DW_RLE_end_of_list
)
8074 if (rlet
== DW_RLE_base_address
|| rlet
== DW_RLE_base_addressx
)
8077 /* Only a DW_RLE_offset_pair needs the base address added. */
8078 if (rlet
== DW_RLE_offset_pair
)
8080 begin
+= base_address
;
8081 end
+= base_address
;
8084 print_hex (begin
, pointer_size
);
8085 print_hex (end
, pointer_size
);
8088 fputs (_(" (start == end)"), stdout
);
8089 else if (begin
> end
)
8090 fputs (_(" (start > end)"), stdout
);
8099 display_debug_rnglists (struct dwarf_section
*section
)
8101 unsigned char *start
= section
->start
;
8102 unsigned char *finish
= start
+ section
->size
;
8104 while (start
< finish
)
8106 unsigned char *table_start
;
8107 uint64_t offset
= start
- section
->start
;
8109 uint64_t initial_length
;
8110 unsigned char segment_selector_size
;
8111 unsigned int offset_entry_count
;
8113 unsigned short version
;
8114 unsigned char address_size
= 0;
8115 unsigned char offset_size
;
8117 /* Get and check the length of the block. */
8118 SAFE_BYTE_GET_AND_INC (initial_length
, start
, 4, finish
);
8120 if (initial_length
== 0xffffffff)
8122 /* This section is 64-bit DWARF 3. */
8123 SAFE_BYTE_GET_AND_INC (initial_length
, start
, 8, finish
);
8129 if (initial_length
> (size_t) (finish
- start
))
8131 /* If the length field has a relocation against it, then we should
8132 not complain if it is inaccurate (and probably negative).
8133 It is copied from .debug_line handling code. */
8134 if (reloc_at (section
, (start
- section
->start
) - offset_size
))
8135 initial_length
= finish
- start
;
8138 warn (_("The length field (%#" PRIx64
8139 ") in the debug_rnglists header is wrong"
8140 " - the section is too small\n"),
8146 end
= start
+ initial_length
;
8148 /* Get the other fields in the header. */
8149 SAFE_BYTE_GET_AND_INC (version
, start
, 2, finish
);
8150 SAFE_BYTE_GET_AND_INC (address_size
, start
, 1, finish
);
8151 SAFE_BYTE_GET_AND_INC (segment_selector_size
, start
, 1, finish
);
8152 SAFE_BYTE_GET_AND_INC (offset_entry_count
, start
, 4, finish
);
8154 printf (_(" Table at Offset: %#" PRIx64
":\n"), offset
);
8155 printf (_(" Length: %#" PRIx64
"\n"), initial_length
);
8156 printf (_(" DWARF version: %u\n"), version
);
8157 printf (_(" Address size: %u\n"), address_size
);
8158 printf (_(" Segment size: %u\n"), segment_selector_size
);
8159 printf (_(" Offset entries: %u\n"), offset_entry_count
);
8161 /* Check the fields. */
8162 if (segment_selector_size
!= 0)
8164 warn (_("The %s section contains "
8165 "unsupported segment selector size: %d.\n"),
8166 section
->name
, segment_selector_size
);
8172 warn (_("Only DWARF version 5+ debug_rnglists info "
8173 "is currently supported.\n"));
8177 table_start
= start
;
8179 if (offset_entry_count
!= 0)
8181 printf (_("\n Offsets starting at %#tx:\n"),
8182 start
- section
->start
);
8184 for (i
= 0; i
< offset_entry_count
; i
++)
8188 SAFE_BYTE_GET_AND_INC (entry
, start
, offset_size
, finish
);
8189 printf (_(" [%6u] %#" PRIx64
"\n"), i
, entry
);
8193 offset_entry_count
= 1;
8195 for (i
= 0; i
< offset_entry_count
; i
++)
8197 uint64_t indx
= start
- table_start
;
8199 offset
= start
- section
->start
;
8200 printf (_("\n Offset: %#" PRIx64
", Index: %#" PRIx64
"\n"),
8202 printf (_(" Offset Begin End\n"));
8203 start
= display_debug_rnglists_list
8204 (start
, end
, address_size
, offset
, 0, offset_size
);
8220 display_debug_ranges (struct dwarf_section
*section
,
8221 void *file ATTRIBUTE_UNUSED
)
8223 unsigned char *start
= section
->start
;
8224 unsigned char *last_start
= start
;
8225 uint64_t bytes
= section
->size
;
8226 unsigned char *section_begin
= start
;
8227 unsigned char *finish
= start
+ bytes
;
8228 unsigned int num_range_list
, i
;
8229 struct range_entry
*range_entries
;
8230 struct range_entry
*range_entry_fill
;
8231 int is_rnglists
= strstr (section
->name
, "debug_rnglists") != NULL
;
8232 /* Initialize it due to a false compiler warning. */
8233 unsigned char address_size
= 0;
8234 uint64_t last_offset
= 0;
8238 printf (_("\nThe %s section is empty.\n"), section
->name
);
8242 introduce (section
, false);
8245 return display_debug_rnglists (section
);
8247 if (load_debug_info (file
) == 0)
8249 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
8255 for (i
= 0; i
< num_debug_info_entries
; i
++)
8256 num_range_list
+= debug_information
[i
].num_range_lists
;
8258 if (num_range_list
== 0)
8260 /* This can happen when the file was compiled with -gsplit-debug
8261 which removes references to range lists from the primary .o file. */
8262 printf (_("No range lists in .debug_info section.\n"));
8266 range_entries
= (struct range_entry
*)
8267 xmalloc (sizeof (*range_entries
) * num_range_list
);
8268 range_entry_fill
= range_entries
;
8270 for (i
= 0; i
< num_debug_info_entries
; i
++)
8272 debug_info
*debug_info_p
= &debug_information
[i
];
8275 for (j
= 0; j
< debug_info_p
->num_range_lists
; j
++)
8277 range_entry_fill
->ranges_offset
= debug_info_p
->range_lists
[j
];
8278 range_entry_fill
->debug_info_p
= debug_info_p
;
8283 qsort (range_entries
, num_range_list
, sizeof (*range_entries
),
8284 range_entry_compar
);
8286 if (dwarf_check
!= 0 && range_entries
[0].ranges_offset
!= 0)
8287 warn (_("Range lists in %s section start at %#" PRIx64
"\n"),
8288 section
->name
, range_entries
[0].ranges_offset
);
8291 printf (_(" Offset Begin End\n"));
8293 for (i
= 0; i
< num_range_list
; i
++)
8295 struct range_entry
*range_entry
= &range_entries
[i
];
8296 debug_info
*debug_info_p
= range_entry
->debug_info_p
;
8297 unsigned int pointer_size
;
8299 unsigned char *next
;
8300 uint64_t base_address
;
8302 pointer_size
= (is_rnglists
? address_size
: debug_info_p
->pointer_size
);
8303 offset
= range_entry
->ranges_offset
;
8304 base_address
= debug_info_p
->base_address
;
8306 /* PR 17512: file: 001-101485-0.001:0.1. */
8307 if (pointer_size
< 2 || pointer_size
> 8)
8309 warn (_("Corrupt pointer size (%d) in debug entry at offset %#" PRIx64
"\n"),
8310 pointer_size
, offset
);
8314 if (offset
> (size_t) (finish
- section_begin
))
8316 warn (_("Corrupt offset (%#" PRIx64
") in range entry %u\n"),
8321 next
= section_begin
+ offset
+ debug_info_p
->rnglists_base
;
8323 /* If multiple DWARF entities reference the same range then we will
8324 have multiple entries in the `range_entries' list for the same
8325 offset. Thanks to the sort above these will all be consecutive in
8326 the `range_entries' list, so we can easily ignore duplicates
8328 if (i
> 0 && last_offset
== offset
)
8330 last_offset
= offset
;
8332 if (dwarf_check
!= 0 && i
> 0)
8335 warn (_("There is a hole [%#tx - %#tx] in %s section.\n"),
8336 start
- section_begin
, next
- section_begin
, section
->name
);
8337 else if (start
> next
)
8339 if (next
== last_start
)
8341 warn (_("There is an overlap [%#tx - %#tx] in %s section.\n"),
8342 start
- section_begin
, next
- section_begin
, section
->name
);
8349 display_debug_ranges_list
8350 (start
, finish
, pointer_size
, offset
, base_address
);
8354 free (range_entries
);
8359 typedef struct Frame_Chunk
8361 struct Frame_Chunk
*next
;
8362 unsigned char *chunk_start
;
8364 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
8365 short int *col_type
;
8366 int64_t *col_offset
;
8368 unsigned int code_factor
;
8372 unsigned int cfa_reg
;
8373 uint64_t cfa_offset
;
8375 unsigned char fde_encoding
;
8376 unsigned char cfa_exp
;
8377 unsigned char ptr_size
;
8378 unsigned char segment_size
;
8382 typedef const char *(*dwarf_regname_lookup_ftype
) (unsigned int);
8383 static dwarf_regname_lookup_ftype dwarf_regnames_lookup_func
;
8384 static const char *const *dwarf_regnames
;
8385 static unsigned int dwarf_regnames_count
;
8386 static bool is_aarch64
;
8388 /* A marker for a col_type that means this column was never referenced
8389 in the frame info. */
8390 #define DW_CFA_unreferenced (-1)
8392 /* Return 0 if no more space is needed, 1 if more space is needed,
8393 -1 for invalid reg. */
8396 frame_need_space (Frame_Chunk
*fc
, unsigned int reg
)
8398 unsigned int prev
= fc
->ncols
;
8400 if (reg
< (unsigned int) fc
->ncols
)
8403 if (dwarf_regnames_count
> 0
8404 && reg
> dwarf_regnames_count
)
8407 fc
->ncols
= reg
+ 1;
8408 /* PR 17512: file: 10450-2643-0.004.
8409 If reg == -1 then this can happen... */
8413 /* PR 17512: file: 2844a11d. */
8414 if (fc
->ncols
> 1024 && dwarf_regnames_count
== 0)
8416 error (_("Unfeasibly large register number: %u\n"), reg
);
8418 /* FIXME: 1024 is an arbitrary limit. Increase it if
8419 we ever encounter a valid binary that exceeds it. */
8423 fc
->col_type
= xcrealloc (fc
->col_type
, fc
->ncols
,
8424 sizeof (*fc
->col_type
));
8425 fc
->col_offset
= xcrealloc (fc
->col_offset
, fc
->ncols
,
8426 sizeof (*fc
->col_offset
));
8427 /* PR 17512: file:002-10025-0.005. */
8428 if (fc
->col_type
== NULL
|| fc
->col_offset
== NULL
)
8430 error (_("Out of memory allocating %u columns in dwarf frame arrays\n"),
8436 while (prev
< fc
->ncols
)
8438 fc
->col_type
[prev
] = DW_CFA_unreferenced
;
8439 fc
->col_offset
[prev
] = 0;
8445 static const char *const dwarf_regnames_i386
[] =
8447 "eax", "ecx", "edx", "ebx", /* 0 - 3 */
8448 "esp", "ebp", "esi", "edi", /* 4 - 7 */
8449 "eip", "eflags", NULL
, /* 8 - 10 */
8450 "st0", "st1", "st2", "st3", /* 11 - 14 */
8451 "st4", "st5", "st6", "st7", /* 15 - 18 */
8452 NULL
, NULL
, /* 19 - 20 */
8453 "xmm0", "xmm1", "xmm2", "xmm3", /* 21 - 24 */
8454 "xmm4", "xmm5", "xmm6", "xmm7", /* 25 - 28 */
8455 "mm0", "mm1", "mm2", "mm3", /* 29 - 32 */
8456 "mm4", "mm5", "mm6", "mm7", /* 33 - 36 */
8457 "fcw", "fsw", "mxcsr", /* 37 - 39 */
8458 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
, /* 40 - 47 */
8459 "tr", "ldtr", /* 48 - 49 */
8460 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 50 - 57 */
8461 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 58 - 65 */
8462 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 66 - 73 */
8463 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 74 - 81 */
8464 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 82 - 89 */
8465 NULL
, NULL
, NULL
, /* 90 - 92 */
8466 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7" /* 93 - 100 */
8469 static const char *const dwarf_regnames_iamcu
[] =
8471 "eax", "ecx", "edx", "ebx", /* 0 - 3 */
8472 "esp", "ebp", "esi", "edi", /* 4 - 7 */
8473 "eip", "eflags", NULL
, /* 8 - 10 */
8474 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 11 - 18 */
8475 NULL
, NULL
, /* 19 - 20 */
8476 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 21 - 28 */
8477 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 29 - 36 */
8478 NULL
, NULL
, NULL
, /* 37 - 39 */
8479 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
, /* 40 - 47 */
8480 "tr", "ldtr", /* 48 - 49 */
8481 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 50 - 57 */
8482 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 58 - 65 */
8483 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 66 - 73 */
8484 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 74 - 81 */
8485 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 82 - 89 */
8486 NULL
, NULL
, NULL
, /* 90 - 92 */
8487 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
/* 93 - 100 */
8491 init_dwarf_regnames_i386 (void)
8493 dwarf_regnames
= dwarf_regnames_i386
;
8494 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_i386
);
8495 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8499 init_dwarf_regnames_iamcu (void)
8501 dwarf_regnames
= dwarf_regnames_iamcu
;
8502 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_iamcu
);
8503 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8506 static const char *const DW_CFA_GNU_window_save_name
[] =
8508 "DW_CFA_GNU_window_save",
8509 "DW_CFA_AARCH64_negate_ra_state"
8512 static const char *const dwarf_regnames_x86_64
[] =
8514 "rax", "rdx", "rcx", "rbx",
8515 "rsi", "rdi", "rbp", "rsp",
8516 "r8", "r9", "r10", "r11",
8517 "r12", "r13", "r14", "r15",
8519 "xmm0", "xmm1", "xmm2", "xmm3",
8520 "xmm4", "xmm5", "xmm6", "xmm7",
8521 "xmm8", "xmm9", "xmm10", "xmm11",
8522 "xmm12", "xmm13", "xmm14", "xmm15",
8523 "st0", "st1", "st2", "st3",
8524 "st4", "st5", "st6", "st7",
8525 "mm0", "mm1", "mm2", "mm3",
8526 "mm4", "mm5", "mm6", "mm7",
8528 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
,
8529 "fs.base", "gs.base", NULL
, NULL
,
8531 "mxcsr", "fcw", "fsw",
8532 "xmm16", "xmm17", "xmm18", "xmm19",
8533 "xmm20", "xmm21", "xmm22", "xmm23",
8534 "xmm24", "xmm25", "xmm26", "xmm27",
8535 "xmm28", "xmm29", "xmm30", "xmm31",
8536 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 83 - 90 */
8537 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 91 - 98 */
8538 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 99 - 106 */
8539 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 107 - 114 */
8540 NULL
, NULL
, NULL
, /* 115 - 117 */
8541 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7"
8545 init_dwarf_regnames_x86_64 (void)
8547 dwarf_regnames
= dwarf_regnames_x86_64
;
8548 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_x86_64
);
8549 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8552 static const char *const dwarf_regnames_aarch64
[] =
8554 "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7",
8555 "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15",
8556 "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23",
8557 "x24", "x25", "x26", "x27", "x28", "x29", "x30", "sp",
8558 NULL
, "elr", NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
8559 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, "vg", "ffr",
8560 "p0", "p1", "p2", "p3", "p4", "p5", "p6", "p7",
8561 "p8", "p9", "p10", "p11", "p12", "p13", "p14", "p15",
8562 "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7",
8563 "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15",
8564 "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23",
8565 "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31",
8566 "z0", "z1", "z2", "z3", "z4", "z5", "z6", "z7",
8567 "z8", "z9", "z10", "z11", "z12", "z13", "z14", "z15",
8568 "z16", "z17", "z18", "z19", "z20", "z21", "z22", "z23",
8569 "z24", "z25", "z26", "z27", "z28", "z29", "z30", "z31",
8573 init_dwarf_regnames_aarch64 (void)
8575 dwarf_regnames
= dwarf_regnames_aarch64
;
8576 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_aarch64
);
8577 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8581 static const char *const dwarf_regnames_s390
[] =
8583 /* Avoid saying "r5 (r5)", so omit the names of r0-r15. */
8584 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
8585 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
8586 "f0", "f2", "f4", "f6", "f1", "f3", "f5", "f7",
8587 "f8", "f10", "f12", "f14", "f9", "f11", "f13", "f15",
8588 "cr0", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7",
8589 "cr8", "cr9", "cr10", "cr11", "cr12", "cr13", "cr14", "cr15",
8590 "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7",
8591 "a8", "a9", "a10", "a11", "a12", "a13", "a14", "a15",
8594 "v16", "v18", "v20", "v22", "v17", "v19", "v21", "v23",
8595 "v24", "v26", "v28", "v30", "v25", "v27", "v29", "v31",
8599 init_dwarf_regnames_s390 (void)
8601 dwarf_regnames
= dwarf_regnames_s390
;
8602 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_s390
);
8603 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8606 static const char *const dwarf_regnames_riscv
[] =
8608 "zero", "ra", "sp", "gp", "tp", "t0", "t1", "t2", /* 0 - 7 */
8609 "s0", "s1", "a0", "a1", "a2", "a3", "a4", "a5", /* 8 - 15 */
8610 "a6", "a7", "s2", "s3", "s4", "s5", "s6", "s7", /* 16 - 23 */
8611 "s8", "s9", "s10", "s11", "t3", "t4", "t5", "t6", /* 24 - 31 */
8612 "ft0", "ft1", "ft2", "ft3", "ft4", "ft5", "ft6", "ft7", /* 32 - 39 */
8613 "fs0", "fs1", /* 40 - 41 */
8614 "fa0", "fa1", "fa2", "fa3", "fa4", "fa5", "fa6", "fa7", /* 42 - 49 */
8615 "fs2", "fs3", "fs4", "fs5", "fs6", "fs7", "fs8", "fs9", /* 50 - 57 */
8616 "fs10", "fs11", /* 58 - 59 */
8617 "ft8", "ft9", "ft10", "ft11", /* 60 - 63 */
8618 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 64 - 71 */
8619 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 72 - 79 */
8620 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 80 - 87 */
8621 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 88 - 95 */
8622 "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", /* 96 - 103 */
8623 "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15", /* 104 - 111 */
8624 "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23", /* 112 - 119 */
8625 "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31", /* 120 - 127 */
8628 /* A RISC-V replacement for REGNAME_INTERNAL_BY_TABLE_ONLY which handles
8629 the large number of CSRs. */
8632 regname_internal_riscv (unsigned int regno
)
8634 const char *name
= NULL
;
8636 /* Lookup in the table first, this covers GPR and FPR. */
8637 if (regno
< ARRAY_SIZE (dwarf_regnames_riscv
))
8638 name
= dwarf_regnames_riscv
[regno
];
8639 else if (regno
>= 4096 && regno
<= 8191)
8641 /* This might be a CSR, these live in a sparse number space from 4096
8642 to 8191 These numbers are defined in the RISC-V ELF ABI
8646 #define DECLARE_CSR(NAME,VALUE,CLASS,DEFINE_VER,ABORT_VER) \
8647 case VALUE + 4096: name = #NAME; break;
8648 #include "opcode/riscv-opc.h"
8653 static char csr_name
[10];
8654 snprintf (csr_name
, sizeof (csr_name
), "csr%d", (regno
- 4096));
8665 init_dwarf_regnames_riscv (void)
8667 dwarf_regnames
= NULL
;
8668 dwarf_regnames_count
= 8192;
8669 dwarf_regnames_lookup_func
= regname_internal_riscv
;
8673 init_dwarf_regnames_by_elf_machine_code (unsigned int e_machine
)
8675 dwarf_regnames_lookup_func
= NULL
;
8681 init_dwarf_regnames_i386 ();
8685 init_dwarf_regnames_iamcu ();
8691 init_dwarf_regnames_x86_64 ();
8695 init_dwarf_regnames_aarch64 ();
8699 init_dwarf_regnames_s390 ();
8703 init_dwarf_regnames_riscv ();
8711 /* Initialize the DWARF register name lookup state based on the
8712 architecture and specific machine type of a BFD. */
8715 init_dwarf_regnames_by_bfd_arch_and_mach (enum bfd_architecture arch
,
8718 dwarf_regnames_lookup_func
= NULL
;
8726 case bfd_mach_x86_64
:
8727 case bfd_mach_x86_64_intel_syntax
:
8728 case bfd_mach_x64_32
:
8729 case bfd_mach_x64_32_intel_syntax
:
8730 init_dwarf_regnames_x86_64 ();
8734 init_dwarf_regnames_i386 ();
8739 case bfd_arch_iamcu
:
8740 init_dwarf_regnames_iamcu ();
8743 case bfd_arch_aarch64
:
8744 init_dwarf_regnames_aarch64();
8748 init_dwarf_regnames_s390 ();
8751 case bfd_arch_riscv
:
8752 init_dwarf_regnames_riscv ();
8761 regname_internal_by_table_only (unsigned int regno
)
8763 if (dwarf_regnames
!= NULL
8764 && regno
< dwarf_regnames_count
8765 && dwarf_regnames
[regno
] != NULL
)
8766 return dwarf_regnames
[regno
];
8772 regname (unsigned int regno
, int name_only_p
)
8774 static char reg
[64];
8776 const char *name
= NULL
;
8778 if (dwarf_regnames_lookup_func
!= NULL
)
8779 name
= dwarf_regnames_lookup_func (regno
);
8785 snprintf (reg
, sizeof (reg
), "r%d (%s)", regno
, name
);
8788 snprintf (reg
, sizeof (reg
), "r%d", regno
);
8793 frame_display_row (Frame_Chunk
*fc
, int *need_col_headers
, unsigned int *max_regs
)
8798 if (*max_regs
!= fc
->ncols
)
8799 *max_regs
= fc
->ncols
;
8801 if (*need_col_headers
)
8803 *need_col_headers
= 0;
8805 printf ("%-*s CFA ", eh_addr_size
* 2, " LOC");
8807 for (r
= 0; r
< *max_regs
; r
++)
8808 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
8813 printf ("%-5s ", regname (r
, 1));
8819 print_hex (fc
->pc_begin
, eh_addr_size
);
8821 strcpy (tmp
, "exp");
8823 sprintf (tmp
, "%s%+d", regname (fc
->cfa_reg
, 1), (int) fc
->cfa_offset
);
8824 printf ("%-8s ", tmp
);
8826 for (r
= 0; r
< fc
->ncols
; r
++)
8828 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
8830 switch (fc
->col_type
[r
])
8832 case DW_CFA_undefined
:
8835 case DW_CFA_same_value
:
8839 sprintf (tmp
, "c%+" PRId64
, fc
->col_offset
[r
]);
8841 case DW_CFA_val_offset
:
8842 sprintf (tmp
, "v%+" PRId64
, fc
->col_offset
[r
]);
8844 case DW_CFA_register
:
8845 sprintf (tmp
, "%s", regname (fc
->col_offset
[r
], 0));
8847 case DW_CFA_expression
:
8848 strcpy (tmp
, "exp");
8850 case DW_CFA_val_expression
:
8851 strcpy (tmp
, "vexp");
8854 strcpy (tmp
, "n/a");
8857 printf ("%-5s ", tmp
);
8863 #define GET(VAR, N) SAFE_BYTE_GET_AND_INC (VAR, start, N, end)
8865 static unsigned char *
8866 read_cie (unsigned char *start
, unsigned char *end
,
8867 Frame_Chunk
**p_cie
, int *p_version
,
8868 uint64_t *p_aug_len
, unsigned char **p_aug
)
8872 unsigned char *augmentation_data
= NULL
;
8873 uint64_t augmentation_data_len
= 0;
8876 /* PR 17512: file: 001-228113-0.004. */
8880 fc
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
8881 memset (fc
, 0, sizeof (Frame_Chunk
));
8883 fc
->col_type
= xmalloc (sizeof (*fc
->col_type
));
8884 fc
->col_offset
= xmalloc (sizeof (*fc
->col_offset
));
8888 fc
->augmentation
= (char *) start
;
8889 /* PR 17512: file: 001-228113-0.004.
8890 Skip past augmentation name, but avoid running off the end of the data. */
8892 if (* start
++ == '\0')
8896 warn (_("No terminator for augmentation name\n"));
8900 if (strcmp (fc
->augmentation
, "eh") == 0)
8902 if (eh_addr_size
> (size_t) (end
- start
))
8904 start
+= eh_addr_size
;
8909 if (2 > (size_t) (end
- start
))
8911 GET (fc
->ptr_size
, 1);
8912 if (fc
->ptr_size
< 1 || fc
->ptr_size
> 8)
8914 warn (_("Invalid pointer size (%d) in CIE data\n"), fc
->ptr_size
);
8918 GET (fc
->segment_size
, 1);
8919 /* PR 17512: file: e99d2804. */
8920 if (fc
->segment_size
> 8 || fc
->segment_size
+ fc
->ptr_size
> 8)
8922 warn (_("Invalid segment size (%d) in CIE data\n"), fc
->segment_size
);
8926 eh_addr_size
= fc
->ptr_size
;
8930 fc
->ptr_size
= eh_addr_size
;
8931 fc
->segment_size
= 0;
8934 READ_ULEB (fc
->code_factor
, start
, end
);
8935 READ_SLEB (fc
->data_factor
, start
, end
);
8946 READ_ULEB (fc
->ra
, start
, end
);
8949 if (fc
->augmentation
[0] == 'z')
8953 READ_ULEB (augmentation_data_len
, start
, end
);
8954 augmentation_data
= start
;
8955 /* PR 17512: file: 11042-2589-0.004. */
8956 if (augmentation_data_len
> (size_t) (end
- start
))
8958 warn (_("Augmentation data too long: %#" PRIx64
8959 ", expected at most %#tx\n"),
8960 augmentation_data_len
, end
- start
);
8963 start
+= augmentation_data_len
;
8966 if (augmentation_data_len
)
8970 unsigned char *qend
;
8972 p
= (unsigned char *) fc
->augmentation
+ 1;
8973 q
= augmentation_data
;
8974 qend
= q
+ augmentation_data_len
;
8976 while (p
< end
&& q
< qend
)
8981 q
+= 1 + size_of_encoded_value (*q
);
8983 fc
->fde_encoding
= *q
++;
8992 /* Note - it is OK if this loop terminates with q < qend.
8993 Padding may have been inserted to align the end of the CIE. */
8998 *p_version
= version
;
9001 *p_aug_len
= augmentation_data_len
;
9002 *p_aug
= augmentation_data
;
9007 free (fc
->col_offset
);
9008 free (fc
->col_type
);
9013 /* Prints out the contents on the DATA array formatted as unsigned bytes.
9014 If do_wide is not enabled, then formats the output to fit into 80 columns.
9015 PRINTED contains the number of characters already written to the current
9019 display_data (size_t printed
, const unsigned char *data
, size_t len
)
9021 if (do_wide
|| len
< ((80 - printed
) / 3))
9022 for (printed
= 0; printed
< len
; ++printed
)
9023 printf (" %02x", data
[printed
]);
9026 for (printed
= 0; printed
< len
; ++printed
)
9028 if (printed
% (80 / 3) == 0)
9030 printf (" %02x", data
[printed
]);
9035 /* Prints out the contents on the augmentation data array.
9036 If do_wide is not enabled, then formats the output to fit into 80 columns. */
9039 display_augmentation_data (const unsigned char * data
, uint64_t len
)
9043 i
= printf (_(" Augmentation data: "));
9044 display_data (i
, data
, len
);
9048 display_debug_frames (struct dwarf_section
*section
,
9049 void *file ATTRIBUTE_UNUSED
)
9051 unsigned char *start
= section
->start
;
9052 unsigned char *end
= start
+ section
->size
;
9053 unsigned char *section_start
= start
;
9054 Frame_Chunk
*chunks
= NULL
, *forward_refs
= NULL
;
9055 Frame_Chunk
*remembered_state
= NULL
;
9057 bool is_eh
= strcmp (section
->name
, ".eh_frame") == 0;
9058 unsigned int max_regs
= 0;
9059 const char *bad_reg
= _("bad register: ");
9060 unsigned int saved_eh_addr_size
= eh_addr_size
;
9062 introduce (section
, false);
9066 unsigned char *saved_start
;
9067 unsigned char *block_end
;
9072 int need_col_headers
= 1;
9073 unsigned char *augmentation_data
= NULL
;
9074 uint64_t augmentation_data_len
= 0;
9075 unsigned int encoded_ptr_size
= saved_eh_addr_size
;
9076 unsigned int offset_size
;
9078 static Frame_Chunk fde_fc
;
9080 saved_start
= start
;
9082 SAFE_BYTE_GET_AND_INC (length
, start
, 4, end
);
9086 printf ("\n%08tx ZERO terminator\n\n",
9087 saved_start
- section_start
);
9088 /* Skip any zero terminators that directly follow.
9089 A corrupt section size could have loaded a whole
9090 slew of zero filled memory bytes. eg
9091 PR 17512: file: 070-19381-0.004. */
9092 while (start
< end
&& * start
== 0)
9097 if (length
== 0xffffffff)
9099 SAFE_BYTE_GET_AND_INC (length
, start
, 8, end
);
9105 if (length
> (size_t) (end
- start
))
9107 warn ("Invalid length %#" PRIx64
" in FDE at %#tx\n",
9108 length
, saved_start
- section_start
);
9112 block_end
= start
+ length
;
9114 SAFE_BYTE_GET_AND_INC (cie_id
, start
, offset_size
, block_end
);
9116 if (is_eh
? (cie_id
== 0) : ((offset_size
== 4 && cie_id
== DW_CIE_ID
)
9117 || (offset_size
== 8 && cie_id
== DW64_CIE_ID
)))
9122 start
= read_cie (start
, block_end
, &cie
, &version
,
9123 &augmentation_data_len
, &augmentation_data
);
9124 /* PR 17512: file: 027-135133-0.005. */
9131 fc
->chunk_start
= saved_start
;
9132 mreg
= max_regs
> 0 ? max_regs
- 1 : 0;
9135 if (frame_need_space (fc
, mreg
) < 0)
9137 if (fc
->fde_encoding
)
9138 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
9140 printf ("\n%08tx ", saved_start
- section_start
);
9141 print_hex (length
, fc
->ptr_size
);
9142 print_hex (cie_id
, offset_size
);
9144 if (do_debug_frames_interp
)
9146 printf ("CIE \"%s\" cf=%d df=%d ra=%d\n", fc
->augmentation
,
9147 fc
->code_factor
, fc
->data_factor
, fc
->ra
);
9152 printf (" Version: %d\n", version
);
9153 printf (" Augmentation: \"%s\"\n", fc
->augmentation
);
9156 printf (" Pointer Size: %u\n", fc
->ptr_size
);
9157 printf (" Segment Size: %u\n", fc
->segment_size
);
9159 printf (" Code alignment factor: %u\n", fc
->code_factor
);
9160 printf (" Data alignment factor: %d\n", fc
->data_factor
);
9161 printf (" Return address column: %d\n", fc
->ra
);
9163 if (augmentation_data_len
)
9164 display_augmentation_data (augmentation_data
, augmentation_data_len
);
9171 unsigned char *look_for
;
9172 unsigned long segment_selector
;
9178 uint64_t sign
= (uint64_t) 1 << (offset_size
* 8 - 1);
9179 cie_off
= (cie_off
^ sign
) - sign
;
9180 cie_off
= start
- 4 - section_start
- cie_off
;
9183 look_for
= section_start
+ cie_off
;
9184 if (cie_off
<= (size_t) (saved_start
- section_start
))
9186 for (cie
= chunks
; cie
; cie
= cie
->next
)
9187 if (cie
->chunk_start
== look_for
)
9190 else if (cie_off
>= section
->size
)
9194 for (cie
= forward_refs
; cie
; cie
= cie
->next
)
9195 if (cie
->chunk_start
== look_for
)
9199 unsigned int off_size
;
9200 unsigned char *cie_scan
;
9202 cie_scan
= look_for
;
9204 SAFE_BYTE_GET_AND_INC (length
, cie_scan
, 4, end
);
9205 if (length
== 0xffffffff)
9207 SAFE_BYTE_GET_AND_INC (length
, cie_scan
, 8, end
);
9210 if (length
!= 0 && length
<= (size_t) (end
- cie_scan
))
9213 unsigned char *cie_end
= cie_scan
+ length
;
9215 SAFE_BYTE_GET_AND_INC (c_id
, cie_scan
, off_size
,
9219 : ((off_size
== 4 && c_id
== DW_CIE_ID
)
9220 || (off_size
== 8 && c_id
== DW64_CIE_ID
)))
9225 read_cie (cie_scan
, cie_end
, &cie
, &version
,
9226 &augmentation_data_len
, &augmentation_data
);
9227 /* PR 17512: file: 3450-2098-0.004. */
9230 warn (_("Failed to read CIE information\n"));
9233 cie
->next
= forward_refs
;
9235 cie
->chunk_start
= look_for
;
9236 mreg
= max_regs
> 0 ? max_regs
- 1 : 0;
9239 if (frame_need_space (cie
, mreg
) < 0)
9241 warn (_("Invalid max register\n"));
9244 if (cie
->fde_encoding
)
9246 = size_of_encoded_value (cie
->fde_encoding
);
9253 memset (fc
, 0, sizeof (Frame_Chunk
));
9258 fc
->col_type
= xmalloc (sizeof (*fc
->col_type
));
9259 fc
->col_offset
= xmalloc (sizeof (*fc
->col_offset
));
9260 if (frame_need_space (fc
, max_regs
> 0 ? max_regs
- 1 : 0) < 0)
9262 warn (_("Invalid max register\n"));
9266 fc
->augmentation
= "";
9267 fc
->fde_encoding
= 0;
9268 fc
->ptr_size
= eh_addr_size
;
9269 fc
->segment_size
= 0;
9273 fc
->ncols
= cie
->ncols
;
9274 fc
->col_type
= xcmalloc (fc
->ncols
, sizeof (*fc
->col_type
));
9275 fc
->col_offset
= xcmalloc (fc
->ncols
, sizeof (*fc
->col_offset
));
9276 memcpy (fc
->col_type
, cie
->col_type
,
9277 fc
->ncols
* sizeof (*fc
->col_type
));
9278 memcpy (fc
->col_offset
, cie
->col_offset
,
9279 fc
->ncols
* sizeof (*fc
->col_offset
));
9280 fc
->augmentation
= cie
->augmentation
;
9281 fc
->ptr_size
= cie
->ptr_size
;
9282 eh_addr_size
= cie
->ptr_size
;
9283 fc
->segment_size
= cie
->segment_size
;
9284 fc
->code_factor
= cie
->code_factor
;
9285 fc
->data_factor
= cie
->data_factor
;
9286 fc
->cfa_reg
= cie
->cfa_reg
;
9287 fc
->cfa_offset
= cie
->cfa_offset
;
9289 if (frame_need_space (fc
, max_regs
> 0 ? max_regs
- 1: 0) < 0)
9291 warn (_("Invalid max register\n"));
9294 fc
->fde_encoding
= cie
->fde_encoding
;
9297 if (fc
->fde_encoding
)
9298 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
9300 segment_selector
= 0;
9301 if (fc
->segment_size
)
9303 if (fc
->segment_size
> sizeof (segment_selector
))
9305 /* PR 17512: file: 9e196b3e. */
9306 warn (_("Probably corrupt segment size: %d - using 4 instead\n"), fc
->segment_size
);
9307 fc
->segment_size
= 4;
9309 SAFE_BYTE_GET_AND_INC (segment_selector
, start
,
9310 fc
->segment_size
, block_end
);
9313 fc
->pc_begin
= get_encoded_value (&start
, fc
->fde_encoding
, section
,
9316 /* FIXME: It appears that sometimes the final pc_range value is
9317 encoded in less than encoded_ptr_size bytes. See the x86_64
9318 run of the "objcopy on compressed debug sections" test for an
9320 SAFE_BYTE_GET_AND_INC (fc
->pc_range
, start
, encoded_ptr_size
,
9323 if (cie
->augmentation
[0] == 'z')
9325 READ_ULEB (augmentation_data_len
, start
, block_end
);
9326 augmentation_data
= start
;
9327 /* PR 17512 file: 722-8446-0.004 and PR 22386. */
9328 if (augmentation_data_len
> (size_t) (block_end
- start
))
9330 warn (_("Augmentation data too long: %#" PRIx64
", "
9331 "expected at most %#tx\n"),
9332 augmentation_data_len
, block_end
- start
);
9334 augmentation_data
= NULL
;
9335 augmentation_data_len
= 0;
9337 start
+= augmentation_data_len
;
9340 printf ("\n%08tx ", saved_start
- section_start
);
9341 print_hex (length
, fc
->ptr_size
);
9342 print_hex (cie_id
, offset_size
);
9345 if (cie
->chunk_start
)
9346 printf ("cie=%08tx", cie
->chunk_start
- section_start
);
9348 /* Ideally translate "invalid " to 8 chars, trailing space
9350 printf (_("cie=invalid "));
9353 if (fc
->segment_size
)
9354 printf ("%04lx:", segment_selector
);
9356 print_hex_ns (fc
->pc_begin
, fc
->ptr_size
);
9358 print_hex_ns (fc
->pc_begin
+ fc
->pc_range
, fc
->ptr_size
);
9361 if (! do_debug_frames_interp
&& augmentation_data_len
)
9363 display_augmentation_data (augmentation_data
, augmentation_data_len
);
9368 /* At this point, fc is the current chunk, cie (if any) is set, and
9369 we're about to interpret instructions for the chunk. */
9370 /* ??? At present we need to do this always, since this sizes the
9371 fc->col_type and fc->col_offset arrays, which we write into always.
9372 We should probably split the interpreted and non-interpreted bits
9373 into two different routines, since there's so much that doesn't
9374 really overlap between them. */
9375 if (1 || do_debug_frames_interp
)
9377 /* Start by making a pass over the chunk, allocating storage
9378 and taking note of what registers are used. */
9379 unsigned char *tmp
= start
;
9381 while (start
< block_end
)
9383 unsigned int reg
, op
, opa
;
9391 /* Warning: if you add any more cases to this switch, be
9392 sure to add them to the corresponding switch below. */
9396 case DW_CFA_advance_loc
:
9399 SKIP_ULEB (start
, block_end
);
9402 case DW_CFA_restore
:
9405 case DW_CFA_set_loc
:
9406 if ((size_t) (block_end
- start
) < encoded_ptr_size
)
9409 start
+= encoded_ptr_size
;
9411 case DW_CFA_advance_loc1
:
9412 if ((size_t) (block_end
- start
) < 1)
9417 case DW_CFA_advance_loc2
:
9418 if ((size_t) (block_end
- start
) < 2)
9423 case DW_CFA_advance_loc4
:
9424 if ((size_t) (block_end
- start
) < 4)
9429 case DW_CFA_offset_extended
:
9430 case DW_CFA_val_offset
:
9431 READ_ULEB (reg
, start
, block_end
);
9432 SKIP_ULEB (start
, block_end
);
9434 case DW_CFA_restore_extended
:
9435 READ_ULEB (reg
, start
, block_end
);
9437 case DW_CFA_undefined
:
9438 READ_ULEB (reg
, start
, block_end
);
9440 case DW_CFA_same_value
:
9441 READ_ULEB (reg
, start
, block_end
);
9443 case DW_CFA_register
:
9444 READ_ULEB (reg
, start
, block_end
);
9445 SKIP_ULEB (start
, block_end
);
9447 case DW_CFA_def_cfa
:
9448 SKIP_ULEB (start
, block_end
);
9449 SKIP_ULEB (start
, block_end
);
9451 case DW_CFA_def_cfa_register
:
9452 SKIP_ULEB (start
, block_end
);
9454 case DW_CFA_def_cfa_offset
:
9455 SKIP_ULEB (start
, block_end
);
9457 case DW_CFA_def_cfa_expression
:
9458 READ_ULEB (temp
, start
, block_end
);
9459 if ((size_t) (block_end
- start
) < temp
)
9464 case DW_CFA_expression
:
9465 case DW_CFA_val_expression
:
9466 READ_ULEB (reg
, start
, block_end
);
9467 READ_ULEB (temp
, start
, block_end
);
9468 if ((size_t) (block_end
- start
) < temp
)
9473 case DW_CFA_offset_extended_sf
:
9474 case DW_CFA_val_offset_sf
:
9475 READ_ULEB (reg
, start
, block_end
);
9476 SKIP_SLEB (start
, block_end
);
9478 case DW_CFA_def_cfa_sf
:
9479 SKIP_ULEB (start
, block_end
);
9480 SKIP_SLEB (start
, block_end
);
9482 case DW_CFA_def_cfa_offset_sf
:
9483 SKIP_SLEB (start
, block_end
);
9485 case DW_CFA_MIPS_advance_loc8
:
9486 if ((size_t) (block_end
- start
) < 8)
9491 case DW_CFA_GNU_args_size
:
9492 SKIP_ULEB (start
, block_end
);
9494 case DW_CFA_GNU_negative_offset_extended
:
9495 READ_ULEB (reg
, start
, block_end
);
9496 SKIP_ULEB (start
, block_end
);
9501 if (reg
!= -1u && frame_need_space (fc
, reg
) >= 0)
9503 /* Don't leave any reg as DW_CFA_unreferenced so
9504 that frame_display_row prints name of regs in
9505 header, and all referenced regs in each line. */
9506 if (reg
>= cie
->ncols
9507 || cie
->col_type
[reg
] == DW_CFA_unreferenced
)
9508 fc
->col_type
[reg
] = DW_CFA_undefined
;
9510 fc
->col_type
[reg
] = cie
->col_type
[reg
];
9518 /* Now we know what registers are used, make a second pass over
9519 the chunk, this time actually printing out the info. */
9521 while (start
< block_end
)
9524 /* Note: It is tempting to use an unsigned long for 'reg' but there
9525 are various functions, notably frame_space_needed() that assume that
9526 reg is an unsigned int. */
9530 const char *reg_prefix
= "";
9537 /* Make a note if something other than DW_CFA_nop happens. */
9538 if (op
!= DW_CFA_nop
)
9541 /* Warning: if you add any more cases to this switch, be
9542 sure to add them to the corresponding switch above. */
9545 case DW_CFA_advance_loc
:
9546 opa
*= fc
->code_factor
;
9547 if (do_debug_frames_interp
)
9548 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9551 printf (" DW_CFA_advance_loc: %d to ", opa
);
9552 print_hex_ns (fc
->pc_begin
+ opa
, fc
->ptr_size
);
9555 fc
->pc_begin
+= opa
;
9559 READ_ULEB (ofs
, start
, block_end
);
9560 ofs
*= fc
->data_factor
;
9561 if (opa
>= fc
->ncols
)
9562 reg_prefix
= bad_reg
;
9563 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9564 printf (" DW_CFA_offset: %s%s at cfa%+" PRId64
"\n",
9565 reg_prefix
, regname (opa
, 0), ofs
);
9566 if (*reg_prefix
== '\0')
9568 fc
->col_type
[opa
] = DW_CFA_offset
;
9569 fc
->col_offset
[opa
] = ofs
;
9573 case DW_CFA_restore
:
9574 if (opa
>= fc
->ncols
)
9575 reg_prefix
= bad_reg
;
9576 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9577 printf (" DW_CFA_restore: %s%s\n",
9578 reg_prefix
, regname (opa
, 0));
9579 if (*reg_prefix
!= '\0')
9582 if (opa
>= cie
->ncols
9583 || cie
->col_type
[opa
] == DW_CFA_unreferenced
)
9585 fc
->col_type
[opa
] = DW_CFA_undefined
;
9586 fc
->col_offset
[opa
] = 0;
9590 fc
->col_type
[opa
] = cie
->col_type
[opa
];
9591 fc
->col_offset
[opa
] = cie
->col_offset
[opa
];
9595 case DW_CFA_set_loc
:
9596 ofs
= get_encoded_value (&start
, fc
->fde_encoding
, section
,
9598 if (do_debug_frames_interp
)
9599 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9602 printf (" DW_CFA_set_loc: ");
9603 print_hex_ns (ofs
, fc
->ptr_size
);
9609 case DW_CFA_advance_loc1
:
9610 SAFE_BYTE_GET_AND_INC (ofs
, start
, 1, block_end
);
9611 ofs
*= fc
->code_factor
;
9612 if (do_debug_frames_interp
)
9613 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9616 printf (" DW_CFA_advance_loc1: %" PRId64
" to ", ofs
);
9617 print_hex_ns (fc
->pc_begin
+ ofs
, fc
->ptr_size
);
9620 fc
->pc_begin
+= ofs
;
9623 case DW_CFA_advance_loc2
:
9624 SAFE_BYTE_GET_AND_INC (ofs
, start
, 2, block_end
);
9625 ofs
*= fc
->code_factor
;
9626 if (do_debug_frames_interp
)
9627 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9630 printf (" DW_CFA_advance_loc2: %" PRId64
" to ", ofs
);
9631 print_hex_ns (fc
->pc_begin
+ ofs
, fc
->ptr_size
);
9634 fc
->pc_begin
+= ofs
;
9637 case DW_CFA_advance_loc4
:
9638 SAFE_BYTE_GET_AND_INC (ofs
, start
, 4, block_end
);
9639 ofs
*= fc
->code_factor
;
9640 if (do_debug_frames_interp
)
9641 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9644 printf (" DW_CFA_advance_loc4: %" PRId64
" to ", ofs
);
9645 print_hex_ns (fc
->pc_begin
+ ofs
, fc
->ptr_size
);
9648 fc
->pc_begin
+= ofs
;
9651 case DW_CFA_offset_extended
:
9652 READ_ULEB (reg
, start
, block_end
);
9653 READ_ULEB (ofs
, start
, block_end
);
9654 ofs
*= fc
->data_factor
;
9655 if (reg
>= fc
->ncols
)
9656 reg_prefix
= bad_reg
;
9657 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9658 printf (" DW_CFA_offset_extended: %s%s at cfa%+" PRId64
"\n",
9659 reg_prefix
, regname (reg
, 0), ofs
);
9660 if (*reg_prefix
== '\0')
9662 fc
->col_type
[reg
] = DW_CFA_offset
;
9663 fc
->col_offset
[reg
] = ofs
;
9667 case DW_CFA_val_offset
:
9668 READ_ULEB (reg
, start
, block_end
);
9669 READ_ULEB (ofs
, start
, block_end
);
9670 ofs
*= fc
->data_factor
;
9671 if (reg
>= fc
->ncols
)
9672 reg_prefix
= bad_reg
;
9673 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9674 printf (" DW_CFA_val_offset: %s%s is cfa%+" PRId64
"\n",
9675 reg_prefix
, regname (reg
, 0), ofs
);
9676 if (*reg_prefix
== '\0')
9678 fc
->col_type
[reg
] = DW_CFA_val_offset
;
9679 fc
->col_offset
[reg
] = ofs
;
9683 case DW_CFA_restore_extended
:
9684 READ_ULEB (reg
, start
, block_end
);
9685 if (reg
>= fc
->ncols
)
9686 reg_prefix
= bad_reg
;
9687 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9688 printf (" DW_CFA_restore_extended: %s%s\n",
9689 reg_prefix
, regname (reg
, 0));
9690 if (*reg_prefix
!= '\0')
9693 if (reg
>= cie
->ncols
9694 || cie
->col_type
[reg
] == DW_CFA_unreferenced
)
9696 fc
->col_type
[reg
] = DW_CFA_undefined
;
9697 fc
->col_offset
[reg
] = 0;
9701 fc
->col_type
[reg
] = cie
->col_type
[reg
];
9702 fc
->col_offset
[reg
] = cie
->col_offset
[reg
];
9706 case DW_CFA_undefined
:
9707 READ_ULEB (reg
, start
, block_end
);
9708 if (reg
>= fc
->ncols
)
9709 reg_prefix
= bad_reg
;
9710 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9711 printf (" DW_CFA_undefined: %s%s\n",
9712 reg_prefix
, regname (reg
, 0));
9713 if (*reg_prefix
== '\0')
9715 fc
->col_type
[reg
] = DW_CFA_undefined
;
9716 fc
->col_offset
[reg
] = 0;
9720 case DW_CFA_same_value
:
9721 READ_ULEB (reg
, start
, block_end
);
9722 if (reg
>= fc
->ncols
)
9723 reg_prefix
= bad_reg
;
9724 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9725 printf (" DW_CFA_same_value: %s%s\n",
9726 reg_prefix
, regname (reg
, 0));
9727 if (*reg_prefix
== '\0')
9729 fc
->col_type
[reg
] = DW_CFA_same_value
;
9730 fc
->col_offset
[reg
] = 0;
9734 case DW_CFA_register
:
9735 READ_ULEB (reg
, start
, block_end
);
9736 READ_ULEB (ofs
, start
, block_end
);
9737 if (reg
>= fc
->ncols
)
9738 reg_prefix
= bad_reg
;
9739 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9741 printf (" DW_CFA_register: %s%s in ",
9742 reg_prefix
, regname (reg
, 0));
9743 puts (regname (ofs
, 0));
9745 if (*reg_prefix
== '\0')
9747 fc
->col_type
[reg
] = DW_CFA_register
;
9748 fc
->col_offset
[reg
] = ofs
;
9752 case DW_CFA_remember_state
:
9753 if (! do_debug_frames_interp
)
9754 printf (" DW_CFA_remember_state\n");
9755 rs
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
9756 rs
->cfa_offset
= fc
->cfa_offset
;
9757 rs
->cfa_reg
= fc
->cfa_reg
;
9759 rs
->cfa_exp
= fc
->cfa_exp
;
9760 rs
->ncols
= fc
->ncols
;
9761 rs
->col_type
= xcmalloc (rs
->ncols
, sizeof (*rs
->col_type
));
9762 rs
->col_offset
= xcmalloc (rs
->ncols
, sizeof (*rs
->col_offset
));
9763 memcpy (rs
->col_type
, fc
->col_type
,
9764 rs
->ncols
* sizeof (*fc
->col_type
));
9765 memcpy (rs
->col_offset
, fc
->col_offset
,
9766 rs
->ncols
* sizeof (*fc
->col_offset
));
9767 rs
->next
= remembered_state
;
9768 remembered_state
= rs
;
9771 case DW_CFA_restore_state
:
9772 if (! do_debug_frames_interp
)
9773 printf (" DW_CFA_restore_state\n");
9774 rs
= remembered_state
;
9777 remembered_state
= rs
->next
;
9778 fc
->cfa_offset
= rs
->cfa_offset
;
9779 fc
->cfa_reg
= rs
->cfa_reg
;
9781 fc
->cfa_exp
= rs
->cfa_exp
;
9782 if (frame_need_space (fc
, rs
->ncols
- 1) < 0)
9784 warn (_("Invalid column number in saved frame state\n"));
9788 memcpy (fc
->col_type
, rs
->col_type
,
9789 rs
->ncols
* sizeof (*rs
->col_type
));
9790 memcpy (fc
->col_offset
, rs
->col_offset
,
9791 rs
->ncols
* sizeof (*rs
->col_offset
));
9792 free (rs
->col_type
);
9793 free (rs
->col_offset
);
9796 else if (do_debug_frames_interp
)
9797 printf ("Mismatched DW_CFA_restore_state\n");
9800 case DW_CFA_def_cfa
:
9801 READ_ULEB (fc
->cfa_reg
, start
, block_end
);
9802 READ_ULEB (fc
->cfa_offset
, start
, block_end
);
9804 if (! do_debug_frames_interp
)
9805 printf (" DW_CFA_def_cfa: %s ofs %d\n",
9806 regname (fc
->cfa_reg
, 0), (int) fc
->cfa_offset
);
9809 case DW_CFA_def_cfa_register
:
9810 READ_ULEB (fc
->cfa_reg
, start
, block_end
);
9812 if (! do_debug_frames_interp
)
9813 printf (" DW_CFA_def_cfa_register: %s\n",
9814 regname (fc
->cfa_reg
, 0));
9817 case DW_CFA_def_cfa_offset
:
9818 READ_ULEB (fc
->cfa_offset
, start
, block_end
);
9819 if (! do_debug_frames_interp
)
9820 printf (" DW_CFA_def_cfa_offset: %d\n", (int) fc
->cfa_offset
);
9824 if (! do_debug_frames_interp
)
9825 printf (" DW_CFA_nop\n");
9828 case DW_CFA_def_cfa_expression
:
9829 READ_ULEB (ofs
, start
, block_end
);
9830 if (ofs
> (size_t) (block_end
- start
))
9832 printf (_(" %s: <corrupt len %" PRIu64
">\n"),
9833 "DW_CFA_def_cfa_expression", ofs
);
9836 if (! do_debug_frames_interp
)
9838 printf (" DW_CFA_def_cfa_expression (");
9839 decode_location_expression (start
, eh_addr_size
, 0, -1,
9847 case DW_CFA_expression
:
9848 READ_ULEB (reg
, start
, block_end
);
9849 READ_ULEB (ofs
, start
, block_end
);
9850 if (reg
>= fc
->ncols
)
9851 reg_prefix
= bad_reg
;
9852 /* PR 17512: file: 069-133014-0.006. */
9853 /* PR 17512: file: 98c02eb4. */
9854 if (ofs
> (size_t) (block_end
- start
))
9856 printf (_(" %s: <corrupt len %" PRIu64
">\n"),
9857 "DW_CFA_expression", ofs
);
9860 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9862 printf (" DW_CFA_expression: %s%s (",
9863 reg_prefix
, regname (reg
, 0));
9864 decode_location_expression (start
, eh_addr_size
, 0, -1,
9868 if (*reg_prefix
== '\0')
9869 fc
->col_type
[reg
] = DW_CFA_expression
;
9873 case DW_CFA_val_expression
:
9874 READ_ULEB (reg
, start
, block_end
);
9875 READ_ULEB (ofs
, start
, block_end
);
9876 if (reg
>= fc
->ncols
)
9877 reg_prefix
= bad_reg
;
9878 if (ofs
> (size_t) (block_end
- start
))
9880 printf (" %s: <corrupt len %" PRIu64
">\n",
9881 "DW_CFA_val_expression", ofs
);
9884 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9886 printf (" DW_CFA_val_expression: %s%s (",
9887 reg_prefix
, regname (reg
, 0));
9888 decode_location_expression (start
, eh_addr_size
, 0, -1,
9892 if (*reg_prefix
== '\0')
9893 fc
->col_type
[reg
] = DW_CFA_val_expression
;
9897 case DW_CFA_offset_extended_sf
:
9898 READ_ULEB (reg
, start
, block_end
);
9899 READ_SLEB (sofs
, start
, block_end
);
9900 /* data_factor multiplicaton done here as unsigned to
9901 avoid integer overflow warnings from asan on fuzzed
9904 ofs
*= fc
->data_factor
;
9905 if (reg
>= fc
->ncols
)
9906 reg_prefix
= bad_reg
;
9907 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9908 printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+" PRId64
"\n",
9909 reg_prefix
, regname (reg
, 0), ofs
);
9910 if (*reg_prefix
== '\0')
9912 fc
->col_type
[reg
] = DW_CFA_offset
;
9913 fc
->col_offset
[reg
] = ofs
;
9917 case DW_CFA_val_offset_sf
:
9918 READ_ULEB (reg
, start
, block_end
);
9919 READ_SLEB (sofs
, start
, block_end
);
9921 ofs
*= fc
->data_factor
;
9922 if (reg
>= fc
->ncols
)
9923 reg_prefix
= bad_reg
;
9924 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9925 printf (" DW_CFA_val_offset_sf: %s%s is cfa%+" PRId64
"\n",
9926 reg_prefix
, regname (reg
, 0), ofs
);
9927 if (*reg_prefix
== '\0')
9929 fc
->col_type
[reg
] = DW_CFA_val_offset
;
9930 fc
->col_offset
[reg
] = ofs
;
9934 case DW_CFA_def_cfa_sf
:
9935 READ_ULEB (fc
->cfa_reg
, start
, block_end
);
9936 READ_SLEB (sofs
, start
, block_end
);
9938 ofs
*= fc
->data_factor
;
9939 fc
->cfa_offset
= ofs
;
9941 if (! do_debug_frames_interp
)
9942 printf (" DW_CFA_def_cfa_sf: %s ofs %" PRId64
"\n",
9943 regname (fc
->cfa_reg
, 0), ofs
);
9946 case DW_CFA_def_cfa_offset_sf
:
9947 READ_SLEB (sofs
, start
, block_end
);
9949 ofs
*= fc
->data_factor
;
9950 fc
->cfa_offset
= ofs
;
9951 if (! do_debug_frames_interp
)
9952 printf (" DW_CFA_def_cfa_offset_sf: %" PRId64
"\n", ofs
);
9955 case DW_CFA_MIPS_advance_loc8
:
9956 SAFE_BYTE_GET_AND_INC (ofs
, start
, 8, block_end
);
9957 ofs
*= fc
->code_factor
;
9958 if (do_debug_frames_interp
)
9959 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9962 printf (" DW_CFA_MIPS_advance_loc8: %" PRId64
" to ", ofs
);
9963 print_hex_ns (fc
->pc_begin
+ ofs
, fc
->ptr_size
);
9966 fc
->pc_begin
+= ofs
;
9969 case DW_CFA_GNU_window_save
:
9970 if (! do_debug_frames_interp
)
9971 printf (" %s\n", DW_CFA_GNU_window_save_name
[is_aarch64
]);
9974 case DW_CFA_GNU_args_size
:
9975 READ_ULEB (ofs
, start
, block_end
);
9976 if (! do_debug_frames_interp
)
9977 printf (" DW_CFA_GNU_args_size: %" PRIu64
"\n", ofs
);
9980 case DW_CFA_GNU_negative_offset_extended
:
9981 READ_ULEB (reg
, start
, block_end
);
9982 READ_SLEB (sofs
, start
, block_end
);
9984 ofs
= -ofs
* fc
->data_factor
;
9985 if (reg
>= fc
->ncols
)
9986 reg_prefix
= bad_reg
;
9987 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9988 printf (" DW_CFA_GNU_negative_offset_extended: %s%s "
9989 "at cfa%+" PRId64
"\n",
9990 reg_prefix
, regname (reg
, 0), ofs
);
9991 if (*reg_prefix
== '\0')
9993 fc
->col_type
[reg
] = DW_CFA_offset
;
9994 fc
->col_offset
[reg
] = ofs
;
9999 if (op
>= DW_CFA_lo_user
&& op
<= DW_CFA_hi_user
)
10000 printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op
);
10002 warn (_("Unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op
);
10007 /* Interpret the CFA - as long as it is not completely full of NOPs. */
10008 if (do_debug_frames_interp
&& ! all_nops
)
10009 frame_display_row (fc
, &need_col_headers
, &max_regs
);
10011 if (fde_fc
.col_type
!= NULL
)
10013 free (fde_fc
.col_type
);
10014 fde_fc
.col_type
= NULL
;
10016 if (fde_fc
.col_offset
!= NULL
)
10018 free (fde_fc
.col_offset
);
10019 fde_fc
.col_offset
= NULL
;
10023 eh_addr_size
= saved_eh_addr_size
;
10028 while (remembered_state
!= NULL
)
10030 rs
= remembered_state
;
10031 remembered_state
= rs
->next
;
10032 free (rs
->col_type
);
10033 free (rs
->col_offset
);
10034 rs
->next
= NULL
; /* Paranoia. */
10038 while (chunks
!= NULL
)
10042 free (rs
->col_type
);
10043 free (rs
->col_offset
);
10044 rs
->next
= NULL
; /* Paranoia. */
10048 while (forward_refs
!= NULL
)
10051 forward_refs
= rs
->next
;
10052 free (rs
->col_type
);
10053 free (rs
->col_offset
);
10054 rs
->next
= NULL
; /* Paranoia. */
10064 display_debug_names (struct dwarf_section
*section
, void *file
)
10066 unsigned char *hdrptr
= section
->start
;
10067 uint64_t unit_length
;
10068 unsigned char *unit_start
;
10069 const unsigned char *const section_end
= section
->start
+ section
->size
;
10070 unsigned char *unit_end
;
10072 introduce (section
, false);
10074 load_debug_section_with_follow (str
, file
);
10076 for (; hdrptr
< section_end
; hdrptr
= unit_end
)
10078 unsigned int offset_size
;
10079 uint16_t dwarf_version
, padding
;
10080 uint32_t comp_unit_count
, local_type_unit_count
, foreign_type_unit_count
;
10081 uint64_t bucket_count
, name_count
, abbrev_table_size
;
10082 uint32_t augmentation_string_size
;
10084 bool augmentation_printable
;
10085 const char *augmentation_string
;
10088 unit_start
= hdrptr
;
10090 /* Get and check the length of the block. */
10091 SAFE_BYTE_GET_AND_INC (unit_length
, hdrptr
, 4, section_end
);
10093 if (unit_length
== 0xffffffff)
10095 /* This section is 64-bit DWARF. */
10096 SAFE_BYTE_GET_AND_INC (unit_length
, hdrptr
, 8, section_end
);
10102 if (unit_length
> (size_t) (section_end
- hdrptr
)
10103 || unit_length
< 2 + 2 + 4 * 7)
10106 warn (_("Debug info is corrupted, %s header at %#tx"
10107 " has length %#" PRIx64
"\n"),
10108 section
->name
, unit_start
- section
->start
, unit_length
);
10111 unit_end
= hdrptr
+ unit_length
;
10113 /* Get and check the version number. */
10114 SAFE_BYTE_GET_AND_INC (dwarf_version
, hdrptr
, 2, unit_end
);
10115 printf (_("Version %d\n"), (int) dwarf_version
);
10117 /* Prior versions did not exist, and future versions may not be
10118 backwards compatible. */
10119 if (dwarf_version
!= 5)
10121 warn (_("Only DWARF version 5 .debug_names "
10122 "is currently supported.\n"));
10126 SAFE_BYTE_GET_AND_INC (padding
, hdrptr
, 2, unit_end
);
10128 warn (_("Padding field of .debug_names must be 0 (found 0x%x)\n"),
10131 SAFE_BYTE_GET_AND_INC (comp_unit_count
, hdrptr
, 4, unit_end
);
10132 if (comp_unit_count
== 0)
10133 warn (_("Compilation unit count must be >= 1 in .debug_names\n"));
10135 SAFE_BYTE_GET_AND_INC (local_type_unit_count
, hdrptr
, 4, unit_end
);
10136 SAFE_BYTE_GET_AND_INC (foreign_type_unit_count
, hdrptr
, 4, unit_end
);
10137 SAFE_BYTE_GET_AND_INC (bucket_count
, hdrptr
, 4, unit_end
);
10138 SAFE_BYTE_GET_AND_INC (name_count
, hdrptr
, 4, unit_end
);
10139 SAFE_BYTE_GET_AND_INC (abbrev_table_size
, hdrptr
, 4, unit_end
);
10141 SAFE_BYTE_GET_AND_INC (augmentation_string_size
, hdrptr
, 4, unit_end
);
10142 if (augmentation_string_size
% 4 != 0)
10144 warn (_("Augmentation string length %u must be rounded up "
10145 "to a multiple of 4 in .debug_names.\n"),
10146 augmentation_string_size
);
10147 augmentation_string_size
+= (-augmentation_string_size
) & 3;
10149 if (augmentation_string_size
> (size_t) (unit_end
- hdrptr
))
10152 printf (_("Augmentation string:"));
10154 augmentation_printable
= true;
10155 augmentation_string
= (const char *) hdrptr
;
10157 for (i
= 0; i
< augmentation_string_size
; i
++)
10161 SAFE_BYTE_GET_AND_INC (uc
, hdrptr
, 1, unit_end
);
10162 printf (" %02x", uc
);
10164 if (uc
!= 0 && !ISPRINT (uc
))
10165 augmentation_printable
= false;
10168 if (augmentation_printable
)
10172 i
< augmentation_string_size
&& augmentation_string
[i
];
10174 putchar (augmentation_string
[i
]);
10179 printf (_("CU table:\n"));
10180 if (_mul_overflow (comp_unit_count
, offset_size
, &total
)
10181 || total
> (size_t) (unit_end
- hdrptr
))
10183 for (i
= 0; i
< comp_unit_count
; i
++)
10185 uint64_t cu_offset
;
10187 SAFE_BYTE_GET_AND_INC (cu_offset
, hdrptr
, offset_size
, unit_end
);
10188 printf ("[%3u] %#" PRIx64
"\n", i
, cu_offset
);
10192 printf (_("TU table:\n"));
10193 if (_mul_overflow (local_type_unit_count
, offset_size
, &total
)
10194 || total
> (size_t) (unit_end
- hdrptr
))
10196 for (i
= 0; i
< local_type_unit_count
; i
++)
10198 uint64_t tu_offset
;
10200 SAFE_BYTE_GET_AND_INC (tu_offset
, hdrptr
, offset_size
, unit_end
);
10201 printf ("[%3u] %#" PRIx64
"\n", i
, tu_offset
);
10205 printf (_("Foreign TU table:\n"));
10206 if (_mul_overflow (foreign_type_unit_count
, 8, &total
)
10207 || total
> (size_t) (unit_end
- hdrptr
))
10209 for (i
= 0; i
< foreign_type_unit_count
; i
++)
10211 uint64_t signature
;
10213 SAFE_BYTE_GET_AND_INC (signature
, hdrptr
, 8, unit_end
);
10214 printf (_("[%3u] "), i
);
10215 print_hex_ns (signature
, 8);
10220 uint64_t xtra
= (bucket_count
* sizeof (uint32_t)
10221 + name_count
* (sizeof (uint32_t) + 2 * offset_size
)
10222 + abbrev_table_size
);
10223 if (xtra
> (size_t) (unit_end
- hdrptr
))
10225 warn (_("Entry pool offset (%#" PRIx64
") exceeds unit size %#tx "
10226 "for unit %#tx in the debug_names\n"),
10227 xtra
, unit_end
- unit_start
, unit_start
- section
->start
);
10230 const uint32_t *const hash_table_buckets
= (uint32_t *) hdrptr
;
10231 hdrptr
+= bucket_count
* sizeof (uint32_t);
10232 const uint32_t *const hash_table_hashes
= (uint32_t *) hdrptr
;
10233 hdrptr
+= name_count
* sizeof (uint32_t);
10234 unsigned char *const name_table_string_offsets
= hdrptr
;
10235 hdrptr
+= name_count
* offset_size
;
10236 unsigned char *const name_table_entry_offsets
= hdrptr
;
10237 hdrptr
+= name_count
* offset_size
;
10238 unsigned char *const abbrev_table
= hdrptr
;
10239 hdrptr
+= abbrev_table_size
;
10240 const unsigned char *const abbrev_table_end
= hdrptr
;
10241 unsigned char *const entry_pool
= hdrptr
;
10243 size_t buckets_filled
= 0;
10245 for (bucketi
= 0; bucketi
< bucket_count
; bucketi
++)
10247 const uint32_t bucket
= hash_table_buckets
[bucketi
];
10252 printf (ngettext ("Used %zu of %lu bucket.\n",
10253 "Used %zu of %lu buckets.\n",
10254 (unsigned long) bucket_count
),
10255 buckets_filled
, (unsigned long) bucket_count
);
10257 if (bucket_count
!= 0)
10259 uint32_t hash_prev
= 0;
10260 size_t hash_clash_count
= 0;
10261 size_t longest_clash
= 0;
10262 size_t this_length
= 0;
10264 for (hashi
= 0; hashi
< name_count
; hashi
++)
10266 const uint32_t hash_this
= hash_table_hashes
[hashi
];
10270 if (hash_prev
% bucket_count
== hash_this
% bucket_count
)
10272 ++hash_clash_count
;
10274 longest_clash
= MAX (longest_clash
, this_length
);
10279 hash_prev
= hash_this
;
10281 printf (_("Out of %" PRIu64
" items there are %zu bucket clashes"
10282 " (longest of %zu entries).\n"),
10283 name_count
, hash_clash_count
, longest_clash
);
10285 if (name_count
!= buckets_filled
+ hash_clash_count
)
10286 warn (_("The name_count (%" PRIu64
")"
10287 " is not the same as the used bucket_count"
10288 " (%zu) + the hash clash count (%zu)"),
10289 name_count
, buckets_filled
, hash_clash_count
);
10292 struct abbrev_lookup_entry
10294 uint64_t abbrev_tag
;
10295 unsigned char *abbrev_lookup_ptr
;
10297 struct abbrev_lookup_entry
*abbrev_lookup
= NULL
;
10298 size_t abbrev_lookup_used
= 0;
10299 size_t abbrev_lookup_allocated
= 0;
10301 unsigned char *abbrevptr
= abbrev_table
;
10304 uint64_t abbrev_tag
;
10306 READ_ULEB (abbrev_tag
, abbrevptr
, abbrev_table_end
);
10307 if (abbrev_tag
== 0)
10309 if (abbrev_lookup_used
== abbrev_lookup_allocated
)
10311 abbrev_lookup_allocated
= MAX (0x100,
10312 abbrev_lookup_allocated
* 2);
10313 abbrev_lookup
= xrealloc (abbrev_lookup
,
10314 (abbrev_lookup_allocated
10315 * sizeof (*abbrev_lookup
)));
10317 assert (abbrev_lookup_used
< abbrev_lookup_allocated
);
10318 struct abbrev_lookup_entry
*entry
;
10319 for (entry
= abbrev_lookup
;
10320 entry
< abbrev_lookup
+ abbrev_lookup_used
;
10322 if (entry
->abbrev_tag
== abbrev_tag
)
10324 warn (_("Duplicate abbreviation tag %" PRIu64
10325 " in unit %#tx in the debug_names section\n"),
10326 abbrev_tag
, unit_start
- section
->start
);
10329 entry
= &abbrev_lookup
[abbrev_lookup_used
++];
10330 entry
->abbrev_tag
= abbrev_tag
;
10331 entry
->abbrev_lookup_ptr
= abbrevptr
;
10333 /* Skip DWARF tag. */
10334 SKIP_ULEB (abbrevptr
, abbrev_table_end
);
10337 uint64_t xindex
, form
;
10339 READ_ULEB (xindex
, abbrevptr
, abbrev_table_end
);
10340 READ_ULEB (form
, abbrevptr
, abbrev_table_end
);
10341 if (xindex
== 0 && form
== 0)
10346 printf (_("\nSymbol table:\n"));
10348 for (namei
= 0; namei
< name_count
; ++namei
)
10350 uint64_t string_offset
, entry_offset
;
10353 p
= name_table_string_offsets
+ namei
* offset_size
;
10354 SAFE_BYTE_GET (string_offset
, p
, offset_size
, unit_end
);
10355 p
= name_table_entry_offsets
+ namei
* offset_size
;
10356 SAFE_BYTE_GET (entry_offset
, p
, offset_size
, unit_end
);
10358 printf ("[%3u] #%08x %s:", namei
, hash_table_hashes
[namei
],
10359 fetch_indirect_string (string_offset
));
10361 unsigned char *entryptr
= entry_pool
+ entry_offset
;
10363 /* We need to scan first whether there is a single or multiple
10364 entries. TAGNO is -2 for the first entry, it is -1 for the
10365 initial tag read of the second entry, then it becomes 0 for the
10366 first entry for real printing etc. */
10368 /* Initialize it due to a false compiler warning. */
10369 uint64_t second_abbrev_tag
= -1;
10372 uint64_t abbrev_tag
;
10373 uint64_t dwarf_tag
;
10374 const struct abbrev_lookup_entry
*entry
;
10376 READ_ULEB (abbrev_tag
, entryptr
, unit_end
);
10379 second_abbrev_tag
= abbrev_tag
;
10381 entryptr
= entry_pool
+ entry_offset
;
10384 if (abbrev_tag
== 0)
10387 printf ("%s<%" PRIu64
">",
10388 (tagno
== 0 && second_abbrev_tag
== 0 ? " " : "\n\t"),
10391 for (entry
= abbrev_lookup
;
10392 entry
< abbrev_lookup
+ abbrev_lookup_used
;
10394 if (entry
->abbrev_tag
== abbrev_tag
)
10396 if (entry
>= abbrev_lookup
+ abbrev_lookup_used
)
10398 warn (_("Undefined abbreviation tag %" PRId64
10399 " in unit %#tx in the debug_names section\n"),
10401 unit_start
- section
->start
);
10404 abbrevptr
= entry
->abbrev_lookup_ptr
;
10405 READ_ULEB (dwarf_tag
, abbrevptr
, abbrev_table_end
);
10407 printf (" %s", get_TAG_name (dwarf_tag
));
10410 uint64_t xindex
, form
;
10412 READ_ULEB (xindex
, abbrevptr
, abbrev_table_end
);
10413 READ_ULEB (form
, abbrevptr
, abbrev_table_end
);
10414 if (xindex
== 0 && form
== 0)
10418 printf (" %s", get_IDX_name (xindex
));
10419 entryptr
= read_and_display_attr_value (0, form
, 0,
10420 unit_start
, entryptr
, unit_end
,
10422 dwarf_version
, NULL
,
10423 (tagno
< 0), section
,
10429 printf (_(" <no entries>"));
10433 free (abbrev_lookup
);
10440 display_debug_links (struct dwarf_section
* section
,
10441 void * file ATTRIBUTE_UNUSED
)
10443 const unsigned char * filename
;
10444 unsigned int filelen
;
10446 introduce (section
, false);
10448 /* The .gnu_debuglink section is formatted as:
10449 (c-string) Filename.
10450 (padding) If needed to reach a 4 byte boundary.
10451 (uint32_t) CRC32 value.
10453 The .gun_debugaltlink section is formatted as:
10454 (c-string) Filename.
10455 (binary) Build-ID. */
10457 filename
= section
->start
;
10458 filelen
= strnlen ((const char *) filename
, section
->size
);
10459 if (filelen
== section
->size
)
10461 warn (_("The debuglink filename is corrupt/missing\n"));
10465 printf (_(" Separate debug info file: %s\n"), filename
);
10467 if (startswith (section
->name
, ".gnu_debuglink"))
10469 unsigned int crc32
;
10470 unsigned int crc_offset
;
10472 crc_offset
= filelen
+ 1;
10473 crc_offset
= (crc_offset
+ 3) & ~3;
10474 if (crc_offset
+ 4 > section
->size
)
10476 warn (_("CRC offset missing/truncated\n"));
10480 crc32
= byte_get (filename
+ crc_offset
, 4);
10482 printf (_(" CRC value: %#x\n"), crc32
);
10484 if (crc_offset
+ 4 < section
->size
)
10486 warn (_("There are %#" PRIx64
10487 " extraneous bytes at the end of the section\n"),
10488 section
->size
- (crc_offset
+ 4));
10492 else /* startswith (section->name, ".gnu_debugaltlink") */
10494 const unsigned char *build_id
= section
->start
+ filelen
+ 1;
10495 size_t build_id_len
= section
->size
- (filelen
+ 1);
10498 /* FIXME: Should we support smaller build-id notes ? */
10499 if (build_id_len
< 0x14)
10501 warn (_("Build-ID is too short (%#zx bytes)\n"), build_id_len
);
10505 printed
= printf (_(" Build-ID (%#zx bytes):"), build_id_len
);
10506 display_data (printed
, build_id
, build_id_len
);
10515 display_gdb_index (struct dwarf_section
*section
,
10516 void *file ATTRIBUTE_UNUSED
)
10518 unsigned char *start
= section
->start
;
10520 uint32_t cu_list_offset
, tu_list_offset
;
10521 uint32_t address_table_offset
, symbol_table_offset
, constant_pool_offset
;
10522 unsigned int cu_list_elements
, tu_list_elements
;
10523 unsigned int address_table_elements
, symbol_table_slots
;
10524 unsigned char *cu_list
, *tu_list
;
10525 unsigned char *address_table
, *symbol_table
, *constant_pool
;
10528 /* The documentation for the format of this file is in gdb/dwarf2read.c. */
10530 introduce (section
, false);
10532 if (section
->size
< 6 * sizeof (uint32_t))
10534 warn (_("Truncated header in the %s section.\n"), section
->name
);
10538 version
= byte_get_little_endian (start
, 4);
10539 printf (_("Version %lu\n"), (unsigned long) version
);
10541 /* Prior versions are obsolete, and future versions may not be
10542 backwards compatible. */
10543 if (version
< 3 || version
> 8)
10545 warn (_("Unsupported version %lu.\n"), (unsigned long) version
);
10549 warn (_("The address table data in version 3 may be wrong.\n"));
10551 warn (_("Version 4 does not support case insensitive lookups.\n"));
10553 warn (_("Version 5 does not include inlined functions.\n"));
10555 warn (_("Version 6 does not include symbol attributes.\n"));
10556 /* Version 7 indices generated by Gold have bad type unit references,
10557 PR binutils/15021. But we don't know if the index was generated by
10558 Gold or not, so to avoid worrying users with gdb-generated indices
10559 we say nothing for version 7 here. */
10561 cu_list_offset
= byte_get_little_endian (start
+ 4, 4);
10562 tu_list_offset
= byte_get_little_endian (start
+ 8, 4);
10563 address_table_offset
= byte_get_little_endian (start
+ 12, 4);
10564 symbol_table_offset
= byte_get_little_endian (start
+ 16, 4);
10565 constant_pool_offset
= byte_get_little_endian (start
+ 20, 4);
10567 if (cu_list_offset
> section
->size
10568 || tu_list_offset
> section
->size
10569 || address_table_offset
> section
->size
10570 || symbol_table_offset
> section
->size
10571 || constant_pool_offset
> section
->size
10572 || tu_list_offset
< cu_list_offset
10573 || address_table_offset
< tu_list_offset
10574 || symbol_table_offset
< address_table_offset
10575 || constant_pool_offset
< symbol_table_offset
)
10577 warn (_("Corrupt header in the %s section.\n"), section
->name
);
10581 cu_list_elements
= (tu_list_offset
- cu_list_offset
) / 16;
10582 tu_list_elements
= (address_table_offset
- tu_list_offset
) / 24;
10583 address_table_elements
= (symbol_table_offset
- address_table_offset
) / 20;
10584 symbol_table_slots
= (constant_pool_offset
- symbol_table_offset
) / 8;
10586 cu_list
= start
+ cu_list_offset
;
10587 tu_list
= start
+ tu_list_offset
;
10588 address_table
= start
+ address_table_offset
;
10589 symbol_table
= start
+ symbol_table_offset
;
10590 constant_pool
= start
+ constant_pool_offset
;
10592 printf (_("\nCU table:\n"));
10593 for (i
= 0; i
< cu_list_elements
; i
++)
10595 uint64_t cu_offset
= byte_get_little_endian (cu_list
+ i
* 16, 8);
10596 uint64_t cu_length
= byte_get_little_endian (cu_list
+ i
* 16 + 8, 8);
10598 printf ("[%3u] %#" PRIx64
" - %#" PRIx64
"\n",
10599 i
, cu_offset
, cu_offset
+ cu_length
- 1);
10602 printf (_("\nTU table:\n"));
10603 for (i
= 0; i
< tu_list_elements
; i
++)
10605 uint64_t tu_offset
= byte_get_little_endian (tu_list
+ i
* 24, 8);
10606 uint64_t type_offset
= byte_get_little_endian (tu_list
+ i
* 24 + 8, 8);
10607 uint64_t signature
= byte_get_little_endian (tu_list
+ i
* 24 + 16, 8);
10609 printf ("[%3u] %#" PRIx64
" %#" PRIx64
" ",
10610 i
, tu_offset
, type_offset
);
10611 print_hex_ns (signature
, 8);
10615 printf (_("\nAddress table:\n"));
10616 for (i
= 0; i
< address_table_elements
; i
++)
10618 uint64_t low
= byte_get_little_endian (address_table
+ i
* 20, 8);
10619 uint64_t high
= byte_get_little_endian (address_table
+ i
* 20 + 8, 8);
10620 uint32_t cu_index
= byte_get_little_endian (address_table
+ i
* 20 + 16, 4);
10622 print_hex (low
, 8);
10623 print_hex (high
, 8);
10624 printf ("%" PRIu32
"\n", cu_index
);
10627 printf (_("\nSymbol table:\n"));
10628 for (i
= 0; i
< symbol_table_slots
; ++i
)
10630 uint32_t name_offset
= byte_get_little_endian (symbol_table
+ i
* 8, 4);
10631 uint32_t cu_vector_offset
= byte_get_little_endian (symbol_table
+ i
* 8 + 4, 4);
10632 uint32_t num_cus
, cu
;
10634 if (name_offset
!= 0
10635 || cu_vector_offset
!= 0)
10639 /* PR 17531: file: 5b7b07ad. */
10640 if (name_offset
>= section
->size
- constant_pool_offset
)
10642 printf (_("[%3u] <corrupt offset: %x>"), i
, name_offset
);
10643 warn (_("Corrupt name offset of 0x%x found for symbol table slot %d\n"),
10647 printf ("[%3u] %.*s:", i
,
10648 (int) (section
->size
- (constant_pool_offset
+ name_offset
)),
10649 constant_pool
+ name_offset
);
10651 if (section
->size
- constant_pool_offset
< 4
10652 || cu_vector_offset
> section
->size
- constant_pool_offset
- 4)
10654 printf (_("<invalid CU vector offset: %x>\n"), cu_vector_offset
);
10655 warn (_("Corrupt CU vector offset of 0x%x found for symbol table slot %d\n"),
10656 cu_vector_offset
, i
);
10660 num_cus
= byte_get_little_endian (constant_pool
+ cu_vector_offset
, 4);
10662 if ((uint64_t) num_cus
* 4 > section
->size
- (constant_pool_offset
10663 + cu_vector_offset
+ 4))
10665 printf ("<invalid number of CUs: %d>\n", num_cus
);
10666 warn (_("Invalid number of CUs (0x%x) for symbol table slot %d\n"),
10674 for (j
= 0; j
< num_cus
; ++j
)
10677 gdb_index_symbol_kind kind
;
10679 cu
= byte_get_little_endian (constant_pool
+ cu_vector_offset
+ 4 + j
* 4, 4);
10680 is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu
);
10681 kind
= GDB_INDEX_SYMBOL_KIND_VALUE (cu
);
10682 cu
= GDB_INDEX_CU_VALUE (cu
);
10683 /* Convert to TU number if it's for a type unit. */
10684 if (cu
>= cu_list_elements
)
10685 printf ("%cT%lu", num_cus
> 1 ? '\t' : ' ',
10686 (unsigned long) cu
- cu_list_elements
);
10688 printf ("%c%lu", num_cus
> 1 ? '\t' : ' ', (unsigned long) cu
);
10690 printf (" [%s, %s]",
10691 is_static
? _("static") : _("global"),
10692 get_gdb_index_symbol_kind_name (kind
));
10704 /* Pre-allocate enough space for the CU/TU sets needed. */
10707 prealloc_cu_tu_list (unsigned int nshndx
)
10709 if (shndx_pool
== NULL
)
10711 shndx_pool_size
= nshndx
;
10712 shndx_pool_used
= 0;
10713 shndx_pool
= (unsigned int *) xcmalloc (shndx_pool_size
,
10714 sizeof (unsigned int));
10718 shndx_pool_size
= shndx_pool_used
+ nshndx
;
10719 shndx_pool
= (unsigned int *) xcrealloc (shndx_pool
, shndx_pool_size
,
10720 sizeof (unsigned int));
10725 add_shndx_to_cu_tu_entry (unsigned int shndx
)
10727 shndx_pool
[shndx_pool_used
++] = shndx
;
10731 end_cu_tu_entry (void)
10733 shndx_pool
[shndx_pool_used
++] = 0;
10736 /* Return the short name of a DWARF section given by a DW_SECT enumerator. */
10738 static const char *
10739 get_DW_SECT_short_name (unsigned int dw_sect
)
10741 static char buf
[16];
10747 case DW_SECT_TYPES
:
10749 case DW_SECT_ABBREV
:
10755 case DW_SECT_STR_OFFSETS
:
10757 case DW_SECT_MACINFO
:
10759 case DW_SECT_MACRO
:
10765 snprintf (buf
, sizeof (buf
), "%d", dw_sect
);
10769 /* Process a CU or TU index. If DO_DISPLAY is true, print the contents.
10770 These sections are extensions for Fission.
10771 See http://gcc.gnu.org/wiki/DebugFissionDWP. */
10774 process_cu_tu_index (struct dwarf_section
*section
, int do_display
)
10776 unsigned char *phdr
= section
->start
;
10777 unsigned char *limit
= phdr
+ section
->size
;
10778 unsigned char *phash
;
10779 unsigned char *pindex
;
10780 unsigned char *ppool
;
10781 unsigned int version
;
10782 unsigned int ncols
= 0;
10783 unsigned int nused
;
10784 unsigned int nslots
;
10787 uint64_t signature
;
10790 /* PR 17512: file: 002-168123-0.004. */
10793 warn (_("Section %s is empty\n"), section
->name
);
10796 /* PR 17512: file: 002-376-0.004. */
10797 if (section
->size
< 24)
10799 warn (_("Section %s is too small to contain a CU/TU header\n"),
10805 SAFE_BYTE_GET_AND_INC (version
, phash
, 4, limit
);
10807 SAFE_BYTE_GET_AND_INC (ncols
, phash
, 4, limit
);
10808 SAFE_BYTE_GET_AND_INC (nused
, phash
, 4, limit
);
10809 SAFE_BYTE_GET_AND_INC (nslots
, phash
, 4, limit
);
10811 pindex
= phash
+ (size_t) nslots
* 8;
10812 ppool
= pindex
+ (size_t) nslots
* 4;
10816 introduce (section
, false);
10818 printf (_(" Version: %u\n"), version
);
10820 printf (_(" Number of columns: %u\n"), ncols
);
10821 printf (_(" Number of used entries: %u\n"), nused
);
10822 printf (_(" Number of slots: %u\n\n"), nslots
);
10825 /* PR 17531: file: 45d69832. */
10826 if (_mul_overflow ((size_t) nslots
, 12, &total
)
10827 || total
> (size_t) (limit
- phash
))
10829 warn (ngettext ("Section %s is too small for %u slot\n",
10830 "Section %s is too small for %u slots\n",
10832 section
->name
, nslots
);
10838 unsigned char *shndx_list
;
10839 unsigned int shndx
;
10843 prealloc_cu_tu_list ((limit
- ppool
) / 4);
10844 for (shndx_list
= ppool
+ 4; shndx_list
<= limit
- 4; shndx_list
+= 4)
10846 shndx
= byte_get (shndx_list
, 4);
10847 add_shndx_to_cu_tu_entry (shndx
);
10849 end_cu_tu_entry ();
10852 for (i
= 0; i
< nslots
; i
++)
10854 SAFE_BYTE_GET (signature
, phash
, 8, limit
);
10855 if (signature
!= 0)
10857 SAFE_BYTE_GET (j
, pindex
, 4, limit
);
10858 shndx_list
= ppool
+ j
* 4;
10859 /* PR 17531: file: 705e010d. */
10860 if (shndx_list
< ppool
)
10862 warn (_("Section index pool located before start of section\n"));
10866 printf (_(" [%3d] Signature: %#" PRIx64
" Sections: "),
10870 if (shndx_list
>= limit
)
10872 warn (_("Section %s too small for shndx pool\n"),
10876 SAFE_BYTE_GET (shndx
, shndx_list
, 4, limit
);
10879 printf (" %d", shndx
);
10888 else if (version
== 2)
10891 unsigned int dw_sect
;
10892 unsigned char *ph
= phash
;
10893 unsigned char *pi
= pindex
;
10894 unsigned char *poffsets
= ppool
+ (size_t) ncols
* 4;
10895 unsigned char *psizes
= poffsets
+ (size_t) nused
* ncols
* 4;
10897 struct cu_tu_set
*this_set
= NULL
;
10899 unsigned char *prow
;
10902 is_tu_index
= strcmp (section
->name
, ".debug_tu_index") == 0;
10904 /* PR 17531: file: 0dd159bf.
10905 Check for integer overflow (can occur when size_t is 32-bit)
10906 with overlarge ncols or nused values. */
10908 || _mul_overflow ((size_t) ncols
, 4, &temp
)
10909 || _mul_overflow ((size_t) nused
+ 1, temp
, &total
)
10910 || total
> (size_t) (limit
- ppool
))
10912 warn (_("Section %s too small for offset and size tables\n"),
10919 printf (_(" Offset table\n"));
10920 printf (" slot %-16s ",
10921 is_tu_index
? _("signature") : _("dwo_id"));
10928 tu_sets
= xcalloc2 (nused
, sizeof (struct cu_tu_set
));
10929 this_set
= tu_sets
;
10934 cu_sets
= xcalloc2 (nused
, sizeof (struct cu_tu_set
));
10935 this_set
= cu_sets
;
10941 for (j
= 0; j
< ncols
; j
++)
10943 unsigned char *p
= ppool
+ j
* 4;
10944 SAFE_BYTE_GET (dw_sect
, p
, 4, limit
);
10945 printf (" %8s", get_DW_SECT_short_name (dw_sect
));
10950 for (i
= 0; i
< nslots
; i
++)
10952 SAFE_BYTE_GET (signature
, ph
, 8, limit
);
10954 SAFE_BYTE_GET (row
, pi
, 4, limit
);
10957 /* PR 17531: file: a05f6ab3. */
10960 warn (_("Row index (%u) is larger than number of used entries (%u)\n"),
10967 size_t num_copy
= sizeof (uint64_t);
10969 memcpy (&this_set
[row
- 1].signature
, ph
, num_copy
);
10972 prow
= poffsets
+ (row
- 1) * ncols
* 4;
10974 printf (" [%3d] %#" PRIx64
, i
, signature
);
10975 for (j
= 0; j
< ncols
; j
++)
10977 unsigned char *p
= prow
+ j
* 4;
10978 SAFE_BYTE_GET (val
, p
, 4, limit
);
10980 printf (" %8d", val
);
10984 SAFE_BYTE_GET (dw_sect
, p
, 4, limit
);
10986 /* PR 17531: file: 10796eb3. */
10987 if (dw_sect
>= DW_SECT_MAX
)
10988 warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect
);
10990 this_set
[row
- 1].section_offsets
[dw_sect
] = val
;
11006 printf (_(" Size table\n"));
11007 printf (" slot %-16s ",
11008 is_tu_index
? _("signature") : _("dwo_id"));
11011 for (j
= 0; j
< ncols
; j
++)
11013 unsigned char *p
= ppool
+ j
* 4;
11014 SAFE_BYTE_GET (val
, p
, 4, limit
);
11016 printf (" %8s", get_DW_SECT_short_name (val
));
11022 for (i
= 0; i
< nslots
; i
++)
11024 SAFE_BYTE_GET (signature
, ph
, 8, limit
);
11026 SAFE_BYTE_GET (row
, pi
, 4, limit
);
11029 prow
= psizes
+ (row
- 1) * ncols
* 4;
11032 printf (" [%3d] %#" PRIx64
, i
, signature
);
11034 for (j
= 0; j
< ncols
; j
++)
11036 unsigned char *p
= prow
+ j
* 4;
11038 /* PR 28645: Check for overflow. Since we do not know how
11039 many populated rows there will be, we cannot just
11040 perform a single check at the start of this function. */
11041 if (p
> (limit
- 4))
11045 warn (_("Too many rows/columns in DWARF index section %s\n"),
11050 SAFE_BYTE_GET (val
, p
, 4, limit
);
11053 printf (" %8d", val
);
11057 SAFE_BYTE_GET (dw_sect
, p
, 4, limit
);
11058 if (dw_sect
>= DW_SECT_MAX
)
11059 warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect
);
11061 this_set
[row
- 1].section_sizes
[dw_sect
] = val
;
11073 else if (do_display
)
11074 printf (_(" Unsupported version (%d)\n"), version
);
11082 static int cu_tu_indexes_read
= -1; /* Tri-state variable. */
11084 /* Load the CU and TU indexes if present. This will build a list of
11085 section sets that we can use to associate a .debug_info.dwo section
11086 with its associated .debug_abbrev.dwo section in a .dwp file. */
11089 load_cu_tu_indexes (void *file
)
11091 /* If we have already loaded (or tried to load) the CU and TU indexes
11092 then do not bother to repeat the task. */
11093 if (cu_tu_indexes_read
== -1)
11095 cu_tu_indexes_read
= true;
11097 if (load_debug_section_with_follow (dwp_cu_index
, file
))
11098 if (! process_cu_tu_index (&debug_displays
[dwp_cu_index
].section
, 0))
11099 cu_tu_indexes_read
= false;
11101 if (load_debug_section_with_follow (dwp_tu_index
, file
))
11102 if (! process_cu_tu_index (&debug_displays
[dwp_tu_index
].section
, 0))
11103 cu_tu_indexes_read
= false;
11106 return (bool) cu_tu_indexes_read
;
11109 /* Find the set of sections that includes section SHNDX. */
11112 find_cu_tu_set (void *file
, unsigned int shndx
)
11116 if (! load_cu_tu_indexes (file
))
11119 /* Find SHNDX in the shndx pool. */
11120 for (i
= 0; i
< shndx_pool_used
; i
++)
11121 if (shndx_pool
[i
] == shndx
)
11124 if (i
>= shndx_pool_used
)
11127 /* Now backup to find the first entry in the set. */
11128 while (i
> 0 && shndx_pool
[i
- 1] != 0)
11131 return shndx_pool
+ i
;
11134 /* Display a .debug_cu_index or .debug_tu_index section. */
11137 display_cu_index (struct dwarf_section
*section
, void *file ATTRIBUTE_UNUSED
)
11139 return process_cu_tu_index (section
, 1);
11143 display_debug_not_supported (struct dwarf_section
*section
,
11144 void *file ATTRIBUTE_UNUSED
)
11146 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
11152 /* Like malloc, but takes two parameters like calloc.
11153 Verifies that the first parameter is not too large.
11154 Note: does *not* initialise the allocated memory to zero. */
11157 cmalloc (uint64_t nmemb
, size_t size
)
11159 /* Check for overflow. */
11160 if (nmemb
>= ~(size_t) 0 / size
)
11163 return xmalloc (nmemb
* size
);
11166 /* Like xmalloc, but takes two parameters like calloc.
11167 Verifies that the first parameter is not too large.
11168 Note: does *not* initialise the allocated memory to zero. */
11171 xcmalloc (uint64_t nmemb
, size_t size
)
11173 /* Check for overflow. */
11174 if (nmemb
>= ~(size_t) 0 / size
)
11177 _("Attempt to allocate an array with an excessive number of elements: %#" PRIx64
"\n"),
11182 return xmalloc (nmemb
* size
);
11185 /* Like xrealloc, but takes three parameters.
11186 Verifies that the second parameter is not too large.
11187 Note: does *not* initialise any new memory to zero. */
11190 xcrealloc (void *ptr
, uint64_t nmemb
, size_t size
)
11192 /* Check for overflow. */
11193 if (nmemb
>= ~(size_t) 0 / size
)
11195 error (_("Attempt to re-allocate an array with an excessive number of elements: %#" PRIx64
"\n"),
11200 return xrealloc (ptr
, nmemb
* size
);
11203 /* Like xcalloc, but verifies that the first parameter is not too large. */
11206 xcalloc2 (uint64_t nmemb
, size_t size
)
11208 /* Check for overflow. */
11209 if (nmemb
>= ~(size_t) 0 / size
)
11211 error (_("Attempt to allocate a zero'ed array with an excessive number of elements: %#" PRIx64
"\n"),
11216 return xcalloc (nmemb
, size
);
11219 static unsigned long
11220 calc_gnu_debuglink_crc32 (unsigned long crc
,
11221 const unsigned char *buf
,
11224 static const unsigned long crc32_table
[256] =
11226 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
11227 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
11228 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
11229 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
11230 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
11231 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
11232 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
11233 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
11234 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
11235 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
11236 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
11237 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
11238 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
11239 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
11240 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
11241 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
11242 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
11243 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
11244 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
11245 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
11246 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
11247 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
11248 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
11249 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
11250 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
11251 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
11252 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
11253 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
11254 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
11255 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
11256 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
11257 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
11258 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
11259 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
11260 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
11261 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
11262 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
11263 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
11264 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
11265 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
11266 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
11267 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
11268 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
11269 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
11270 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
11271 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
11272 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
11273 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
11274 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
11275 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
11276 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
11279 const unsigned char *end
;
11281 crc
= ~crc
& 0xffffffff;
11282 for (end
= buf
+ len
; buf
< end
; ++ buf
)
11283 crc
= crc32_table
[(crc
^ *buf
) & 0xff] ^ (crc
>> 8);
11284 return ~crc
& 0xffffffff;
11287 typedef bool (*check_func_type
) (const char *, void *);
11288 typedef const char *(* parse_func_type
) (struct dwarf_section
*, void *);
11291 check_gnu_debuglink (const char * pathname
, void * crc_pointer
)
11293 static unsigned char buffer
[8 * 1024];
11296 unsigned long crc
= 0;
11299 sep_data
= open_debug_file (pathname
);
11300 if (sep_data
== NULL
)
11303 /* Yes - we are opening the file twice... */
11304 f
= fopen (pathname
, "rb");
11307 /* Paranoia: This should never happen. */
11308 close_debug_file (sep_data
);
11309 warn (_("Unable to reopen separate debug info file: %s\n"), pathname
);
11313 while ((count
= fread (buffer
, 1, sizeof (buffer
), f
)) > 0)
11314 crc
= calc_gnu_debuglink_crc32 (crc
, buffer
, count
);
11318 if (crc
!= * (unsigned long *) crc_pointer
)
11320 close_debug_file (sep_data
);
11321 warn (_("Separate debug info file %s found, but CRC does not match - ignoring\n"),
11329 static const char *
11330 parse_gnu_debuglink (struct dwarf_section
* section
, void * data
)
11333 unsigned int crc_offset
;
11334 unsigned long * crc32
= (unsigned long *) data
;
11336 /* The name is first.
11337 The CRC value is stored after the filename, aligned up to 4 bytes. */
11338 name
= (const char *) section
->start
;
11340 crc_offset
= strnlen (name
, section
->size
) + 1;
11341 if (crc_offset
== 1)
11343 crc_offset
= (crc_offset
+ 3) & ~3;
11344 if (crc_offset
+ 4 > section
->size
)
11347 * crc32
= byte_get (section
->start
+ crc_offset
, 4);
11352 check_gnu_debugaltlink (const char * filename
, void * data ATTRIBUTE_UNUSED
)
11354 void * sep_data
= open_debug_file (filename
);
11356 if (sep_data
== NULL
)
11359 /* FIXME: We should now extract the build-id in the separate file
11365 typedef struct build_id_data
11368 const unsigned char *data
;
11371 static const char *
11372 parse_gnu_debugaltlink (struct dwarf_section
* section
, void * data
)
11377 Build_id_data
*build_id_data
;
11379 /* The name is first.
11380 The build-id follows immediately, with no padding, up to the section's end. */
11382 name
= (const char *) section
->start
;
11383 namelen
= strnlen (name
, section
->size
) + 1;
11386 if (namelen
>= section
->size
)
11389 id_len
= section
->size
- namelen
;
11393 build_id_data
= (Build_id_data
*) data
;
11394 build_id_data
->len
= id_len
;
11395 build_id_data
->data
= section
->start
+ namelen
;
11401 add_separate_debug_file (const char * filename
, void * handle
)
11403 separate_info
* i
= xmalloc (sizeof * i
);
11405 i
->filename
= filename
;
11406 i
->handle
= handle
;
11407 i
->next
= first_separate_info
;
11408 first_separate_info
= i
;
11411 #if HAVE_LIBDEBUGINFOD
11412 /* Query debuginfod servers for the target debuglink or debugaltlink
11413 file. If successful, store the path of the file in filename and
11414 return TRUE, otherwise return FALSE. */
11417 debuginfod_fetch_separate_debug_info (struct dwarf_section
* section
,
11421 size_t build_id_len
;
11422 unsigned char * build_id
;
11424 if (strcmp (section
->uncompressed_name
, ".gnu_debuglink") == 0)
11426 /* Get the build-id of file. */
11427 build_id
= get_build_id (file
);
11430 else if (strcmp (section
->uncompressed_name
, ".gnu_debugaltlink") == 0)
11432 /* Get the build-id of the debugaltlink file. */
11433 unsigned int filelen
;
11435 filelen
= strnlen ((const char *)section
->start
, section
->size
);
11436 if (filelen
== section
->size
)
11437 /* Corrupt debugaltlink. */
11440 build_id
= section
->start
+ filelen
+ 1;
11441 build_id_len
= section
->size
- (filelen
+ 1);
11443 if (build_id_len
== 0)
11452 debuginfod_client
* client
;
11454 client
= debuginfod_begin ();
11455 if (client
== NULL
)
11458 /* Query debuginfod servers for the target file. If found its path
11459 will be stored in filename. */
11460 fd
= debuginfod_find_debuginfo (client
, build_id
, build_id_len
, filename
);
11461 debuginfod_end (client
);
11463 /* Only free build_id if we allocated space for a hex string
11464 in get_build_id (). */
11465 if (build_id_len
== 0)
11470 /* File successfully retrieved. Close fd since we want to
11471 use open_debug_file () on filename instead. */
11479 #endif /* HAVE_LIBDEBUGINFOD */
11482 load_separate_debug_info (const char * main_filename
,
11483 struct dwarf_section
* xlink
,
11484 parse_func_type parse_func
,
11485 check_func_type check_func
,
11487 void * file ATTRIBUTE_UNUSED
)
11489 const char * separate_filename
;
11490 char * debug_filename
;
11492 size_t canon_dirlen
;
11494 char * canon_filename
;
11495 char * canon_debug_filename
;
11498 if ((separate_filename
= parse_func (xlink
, func_data
)) == NULL
)
11500 warn (_("Corrupt debuglink section: %s\n"),
11501 xlink
->name
? xlink
->name
: xlink
->uncompressed_name
);
11505 /* Attempt to locate the separate file.
11506 This should duplicate the logic in bfd/opncls.c:find_separate_debug_file(). */
11508 canon_filename
= lrealpath (main_filename
);
11509 canon_dir
= xstrdup (canon_filename
);
11511 for (canon_dirlen
= strlen (canon_dir
); canon_dirlen
> 0; canon_dirlen
--)
11512 if (IS_DIR_SEPARATOR (canon_dir
[canon_dirlen
- 1]))
11514 canon_dir
[canon_dirlen
] = '\0';
11517 #define DEBUGDIR "/lib/debug"
11519 #ifndef EXTRA_DEBUG_ROOT1
11520 #define EXTRA_DEBUG_ROOT1 "/usr/lib/debug"
11522 #ifndef EXTRA_DEBUG_ROOT2
11523 #define EXTRA_DEBUG_ROOT2 "/usr/lib/debug/usr"
11526 debug_filename
= (char *) malloc (strlen (DEBUGDIR
) + 1
11528 + strlen (".debug/")
11529 #ifdef EXTRA_DEBUG_ROOT1
11530 + strlen (EXTRA_DEBUG_ROOT1
)
11532 #ifdef EXTRA_DEBUG_ROOT2
11533 + strlen (EXTRA_DEBUG_ROOT2
)
11535 + strlen (separate_filename
)
11537 if (debug_filename
== NULL
)
11539 warn (_("Out of memory"));
11541 free (canon_filename
);
11545 /* First try in the current directory. */
11546 sprintf (debug_filename
, "%s", separate_filename
);
11547 if (check_func (debug_filename
, func_data
))
11550 /* Then try in a subdirectory called .debug. */
11551 sprintf (debug_filename
, ".debug/%s", separate_filename
);
11552 if (check_func (debug_filename
, func_data
))
11555 /* Then try in the same directory as the original file. */
11556 sprintf (debug_filename
, "%s%s", canon_dir
, separate_filename
);
11557 if (check_func (debug_filename
, func_data
))
11560 /* And the .debug subdirectory of that directory. */
11561 sprintf (debug_filename
, "%s.debug/%s", canon_dir
, separate_filename
);
11562 if (check_func (debug_filename
, func_data
))
11565 #ifdef EXTRA_DEBUG_ROOT1
11566 /* Try the first extra debug file root. */
11567 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT1
, separate_filename
);
11568 if (check_func (debug_filename
, func_data
))
11571 /* Try the first extra debug file root. */
11572 sprintf (debug_filename
, "%s/%s/%s", EXTRA_DEBUG_ROOT1
, canon_dir
, separate_filename
);
11573 if (check_func (debug_filename
, func_data
))
11577 #ifdef EXTRA_DEBUG_ROOT2
11578 /* Try the second extra debug file root. */
11579 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT2
, separate_filename
);
11580 if (check_func (debug_filename
, func_data
))
11584 /* Then try in the global debug_filename directory. */
11585 strcpy (debug_filename
, DEBUGDIR
);
11586 dirlen
= strlen (DEBUGDIR
) - 1;
11587 if (dirlen
> 0 && DEBUGDIR
[dirlen
] != '/')
11588 strcat (debug_filename
, "/");
11589 strcat (debug_filename
, (const char *) separate_filename
);
11591 if (check_func (debug_filename
, func_data
))
11594 #if HAVE_LIBDEBUGINFOD
11596 char * tmp_filename
;
11599 && debuginfod_fetch_separate_debug_info (xlink
,
11603 /* File successfully downloaded from server, replace
11604 debug_filename with the file's path. */
11605 free (debug_filename
);
11606 debug_filename
= tmp_filename
;
11612 if (do_debug_links
)
11614 /* Failed to find the file. */
11615 warn (_("could not find separate debug file '%s'\n"),
11616 separate_filename
);
11617 warn (_("tried: %s\n"), debug_filename
);
11619 #ifdef EXTRA_DEBUG_ROOT2
11620 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT2
,
11621 separate_filename
);
11622 warn (_("tried: %s\n"), debug_filename
);
11625 #ifdef EXTRA_DEBUG_ROOT1
11626 sprintf (debug_filename
, "%s/%s/%s", EXTRA_DEBUG_ROOT1
,
11627 canon_dir
, separate_filename
);
11628 warn (_("tried: %s\n"), debug_filename
);
11630 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT1
,
11631 separate_filename
);
11632 warn (_("tried: %s\n"), debug_filename
);
11635 sprintf (debug_filename
, "%s.debug/%s", canon_dir
,
11636 separate_filename
);
11637 warn (_("tried: %s\n"), debug_filename
);
11639 sprintf (debug_filename
, "%s%s", canon_dir
, separate_filename
);
11640 warn (_("tried: %s\n"), debug_filename
);
11642 sprintf (debug_filename
, ".debug/%s", separate_filename
);
11643 warn (_("tried: %s\n"), debug_filename
);
11645 sprintf (debug_filename
, "%s", separate_filename
);
11646 warn (_("tried: %s\n"), debug_filename
);
11648 #if HAVE_LIBDEBUGINFOD
11649 if (use_debuginfod
)
11651 char *urls
= getenv (DEBUGINFOD_URLS_ENV_VAR
);
11656 warn (_("tried: DEBUGINFOD_URLS=%s\n"), urls
);
11662 free (debug_filename
);
11663 free (canon_filename
);
11669 canon_debug_filename
= lrealpath (debug_filename
);
11670 self
= strcmp (canon_debug_filename
, canon_filename
) == 0;
11671 free (canon_filename
);
11672 free (canon_debug_filename
);
11675 free (debug_filename
);
11679 void * debug_handle
;
11681 /* Now open the file.... */
11682 if ((debug_handle
= open_debug_file (debug_filename
)) == NULL
)
11684 warn (_("failed to open separate debug file: %s\n"), debug_filename
);
11685 free (debug_filename
);
11689 /* FIXME: We do not check to see if there are any other separate debug info
11690 files that would also match. */
11692 if (do_debug_links
)
11693 printf (_("\n%s: Found separate debug info file: %s\n"), main_filename
, debug_filename
);
11694 add_separate_debug_file (debug_filename
, debug_handle
);
11696 /* Do not free debug_filename - it might be referenced inside
11697 the structure returned by open_debug_file(). */
11698 return debug_handle
;
11701 /* Attempt to load a separate dwarf object file. */
11704 load_dwo_file (const char * main_filename
, const char * name
, const char * dir
, const char * id ATTRIBUTE_UNUSED
)
11706 char * separate_filename
;
11707 void * separate_handle
;
11709 if (IS_ABSOLUTE_PATH (name
))
11710 separate_filename
= strdup (name
);
11712 /* FIXME: Skip adding / if dwo_dir ends in /. */
11713 separate_filename
= concat (dir
, "/", name
, NULL
);
11714 if (separate_filename
== NULL
)
11716 warn (_("Out of memory allocating dwo filename\n"));
11720 if ((separate_handle
= open_debug_file (separate_filename
)) == NULL
)
11722 warn (_("Unable to load dwo file: %s\n"), separate_filename
);
11723 free (separate_filename
);
11727 /* FIXME: We should check the dwo_id. */
11729 printf (_("%s: Found separate debug object file: %s\n\n"), main_filename
, separate_filename
);
11731 add_separate_debug_file (separate_filename
, separate_handle
);
11732 /* Note - separate_filename will be freed in free_debug_memory(). */
11733 return separate_handle
;
11737 try_build_id_prefix (const char * prefix
, char * filename
, const unsigned char * data
, unsigned long id_len
)
11739 char * f
= filename
;
11741 f
+= sprintf (f
, "%s.build-id/%02x/", prefix
, (unsigned) *data
++);
11744 f
+= sprintf (f
, "%02x", (unsigned) *data
++);
11745 strcpy (f
, ".debug");
11747 return open_debug_file (filename
);
11750 /* Try to load a debug file based upon the build-id held in the .note.gnu.build-id section. */
11753 load_build_id_debug_file (const char * main_filename ATTRIBUTE_UNUSED
, void * main_file
)
11755 if (! load_debug_section (note_gnu_build_id
, main_file
))
11756 return; /* No .note.gnu.build-id section. */
11758 struct dwarf_section
* section
= & debug_displays
[note_gnu_build_id
].section
;
11759 if (section
== NULL
)
11761 warn (_("Unable to load the .note.gnu.build-id section\n"));
11765 if (section
->start
== NULL
|| section
->size
< 0x18)
11767 warn (_(".note.gnu.build-id section is corrupt/empty\n"));
11771 /* In theory we should extract the contents of the section into
11772 a note structure and then check the fields. For now though
11773 just use hard coded offsets instead:
11775 Field Bytes Contents
11778 Type 8..11 3 (NT_GNU_BUILD_ID)
11782 /* FIXME: Check the name size, name and type fields. */
11784 unsigned long build_id_size
;
11785 build_id_size
= byte_get (section
->start
+ 4, 4);
11786 if (build_id_size
< 8)
11788 warn (_(".note.gnu.build-id data size is too small\n"));
11792 if (build_id_size
> (section
->size
- 16))
11794 warn (_(".note.gnu.build-id data size is too big\n"));
11799 filename
= xmalloc (strlen (".build-id/")
11800 + build_id_size
* 2 + 2
11801 + strlen (".debug")
11802 /* The next string should be the same as the longest
11803 name found in the prefixes[] array below. */
11804 + strlen ("/usrlib64/debug/usr")
11808 static const char * prefixes
[] =
11813 "/usr/lib/debug/usr/",
11814 "/usr/lib64/debug/",
11815 "/usr/lib64/debug/usr"
11817 long unsigned int i
;
11819 for (i
= 0; i
< ARRAY_SIZE (prefixes
); i
++)
11821 handle
= try_build_id_prefix (prefixes
[i
], filename
,
11822 section
->start
+ 16, build_id_size
);
11823 if (handle
!= NULL
)
11826 /* FIXME: TYhe BFD library also tries a global debugfile directory prefix. */
11827 if (handle
== NULL
)
11829 /* Failed to find a debug file associated with the build-id.
11830 This is not an error however, rather it just means that
11831 the debug info has probably not been loaded on the system,
11832 or that another method is being used to link to the debug
11838 add_separate_debug_file (filename
, handle
);
11841 /* Try to load a debug file pointed to by the .debug_sup section. */
11844 load_debug_sup_file (const char * main_filename
, void * file
)
11846 if (! load_debug_section (debug_sup
, file
))
11847 return; /* No .debug_sup section. */
11849 struct dwarf_section
* section
;
11850 section
= & debug_displays
[debug_sup
].section
;
11851 assert (section
!= NULL
);
11853 if (section
->start
== NULL
|| section
->size
< 5)
11855 warn (_(".debug_sup section is corrupt/empty\n"));
11859 if (section
->start
[2] != 0)
11860 return; /* This is a supplementary file. */
11862 const char * filename
= (const char *) section
->start
+ 3;
11863 if (strnlen (filename
, section
->size
- 3) == section
->size
- 3)
11865 warn (_("filename in .debug_sup section is corrupt\n"));
11869 if (filename
[0] != '/' && strchr (main_filename
, '/'))
11874 new_len
= asprintf (& new_name
, "%.*s/%s",
11875 (int) (strrchr (main_filename
, '/') - main_filename
),
11880 warn (_("unable to construct path for supplementary debug file"));
11885 filename
= new_name
;
11889 /* PR 27796: Make sure that we pass a filename that can be free'd to
11890 add_separate_debug_file(). */
11891 filename
= strdup (filename
);
11892 if (filename
== NULL
)
11894 warn (_("out of memory constructing filename for .debug_sup link\n"));
11899 void * handle
= open_debug_file (filename
);
11900 if (handle
== NULL
)
11902 warn (_("unable to open file '%s' referenced from .debug_sup section\n"), filename
);
11903 free ((void *) filename
);
11907 printf (_("%s: Found supplementary debug file: %s\n\n"), main_filename
, filename
);
11909 /* FIXME: Compare the checksums, if present. */
11910 add_separate_debug_file (filename
, handle
);
11913 /* Load a debuglink section and/or a debugaltlink section, if either are present.
11914 Recursively check the loaded files for more of these sections.
11915 Also follow any links in .debug_sup sections.
11916 FIXME: Should also check for DWO_* entries in the newly loaded files. */
11919 check_for_and_load_links (void * file
, const char * filename
)
11921 void * handle
= NULL
;
11923 if (load_debug_section (gnu_debugaltlink
, file
))
11925 Build_id_data build_id_data
;
11927 handle
= load_separate_debug_info (filename
,
11928 & debug_displays
[gnu_debugaltlink
].section
,
11929 parse_gnu_debugaltlink
,
11930 check_gnu_debugaltlink
,
11935 assert (handle
== first_separate_info
->handle
);
11936 check_for_and_load_links (first_separate_info
->handle
,
11937 first_separate_info
->filename
);
11941 if (load_debug_section (gnu_debuglink
, file
))
11943 unsigned long crc32
;
11945 handle
= load_separate_debug_info (filename
,
11946 & debug_displays
[gnu_debuglink
].section
,
11947 parse_gnu_debuglink
,
11948 check_gnu_debuglink
,
11953 assert (handle
== first_separate_info
->handle
);
11954 check_for_and_load_links (first_separate_info
->handle
,
11955 first_separate_info
->filename
);
11959 load_debug_sup_file (filename
, file
);
11961 load_build_id_debug_file (filename
, file
);
11964 /* Load the separate debug info file(s) attached to FILE, if any exist.
11965 Returns TRUE if any were found, FALSE otherwise.
11966 If TRUE is returned then the linked list starting at first_separate_info
11967 will be populated with open file handles. */
11970 load_separate_debug_files (void * file
, const char * filename
)
11972 /* Skip this operation if we are not interested in debug links. */
11973 if (! do_follow_links
&& ! do_debug_links
)
11976 /* See if there are any dwo links. */
11977 if (load_debug_section (str
, file
)
11978 && load_debug_section (abbrev
, file
)
11979 && load_debug_section (info
, file
))
11981 /* Load the .debug_addr section, if it exists. */
11982 load_debug_section (debug_addr
, file
);
11983 /* Load the .debug_str_offsets section, if it exists. */
11984 load_debug_section (str_index
, file
);
11985 /* Load the .debug_loclists section, if it exists. */
11986 load_debug_section (loclists
, file
);
11987 /* Load the .debug_rnglists section, if it exists. */
11988 load_debug_section (rnglists
, file
);
11992 if (process_debug_info (& debug_displays
[info
].section
, file
, abbrev
,
11995 bool introduced
= false;
11997 const char *dir
= NULL
;
11998 const char *id
= NULL
;
11999 const char *name
= NULL
;
12001 for (dwinfo
= first_dwo_info
; dwinfo
!= NULL
; dwinfo
= dwinfo
->next
)
12003 /* Accumulate NAME, DIR and ID fields. */
12004 switch (dwinfo
->type
)
12008 warn (_("Multiple DWO_NAMEs encountered for the same CU\n"));
12009 name
= dwinfo
->value
;
12013 /* There can be multiple DW_AT_comp_dir entries in a CU,
12014 so do not complain. */
12015 dir
= dwinfo
->value
;
12020 warn (_("multiple DWO_IDs encountered for the same CU\n"));
12021 id
= dwinfo
->value
;
12025 error (_("Unexpected DWO INFO type"));
12029 /* If we have reached the end of our list, or we are changing
12030 CUs, then display the information that we have accumulated
12033 && (dwinfo
->next
== NULL
12034 || dwinfo
->next
->cu_offset
!= dwinfo
->cu_offset
))
12036 if (do_debug_links
)
12040 printf (_("The %s section contains link(s) to dwo file(s):\n\n"),
12041 debug_displays
[info
].section
.uncompressed_name
);
12045 printf (_(" Name: %s\n"), name
);
12046 printf (_(" Directory: %s\n"), dir
? dir
: _("<not-found>"));
12048 display_data (printf (_(" ID: ")), (unsigned char *) id
, 8);
12049 else if (debug_information
[0].dwarf_version
!= 5)
12050 printf (_(" ID: <not specified>\n"));
12054 if (do_follow_links
)
12055 load_dwo_file (filename
, name
, dir
, id
);
12057 name
= dir
= id
= NULL
;
12063 if (! do_follow_links
)
12064 /* The other debug links will be displayed by display_debug_links()
12065 so we do not need to do any further processing here. */
12068 /* FIXME: We do not check for the presence of both link sections in the same file. */
12069 /* FIXME: We do not check for the presence of multiple, same-name debuglink sections. */
12070 /* FIXME: We do not check for the presence of a dwo link as well as a debuglink. */
12072 check_for_and_load_links (file
, filename
);
12073 if (first_separate_info
!= NULL
)
12076 do_follow_links
= 0;
12081 free_debug_memory (void)
12085 free_all_abbrevs ();
12089 shndx_pool_size
= 0;
12090 shndx_pool_used
= 0;
12098 memset (level_type_signed
, 0, sizeof level_type_signed
);
12099 cu_tu_indexes_read
= -1;
12101 for (i
= 0; i
< max
; i
++)
12102 free_debug_section ((enum dwarf_section_display_enum
) i
);
12104 if (debug_information
!= NULL
)
12106 for (i
= 0; i
< alloc_num_debug_info_entries
; i
++)
12107 free_debug_information (&debug_information
[i
]);
12108 free (debug_information
);
12109 debug_information
= NULL
;
12110 alloc_num_debug_info_entries
= num_debug_info_entries
= 0;
12114 separate_info
* next
;
12116 for (d
= first_separate_info
; d
!= NULL
; d
= next
)
12118 close_debug_file (d
->handle
);
12119 free ((void *) d
->filename
);
12123 first_separate_info
= NULL
;
12131 const char *option
;
12134 } debug_dump_long_opts
;
12136 static const debug_dump_long_opts debug_option_table
[] =
12138 { 'A', "addr", &do_debug_addr
, 1 },
12139 { 'a', "abbrev", &do_debug_abbrevs
, 1 },
12140 { 'c', "cu_index", &do_debug_cu_index
, 1 },
12141 #ifdef HAVE_LIBDEBUGINFOD
12142 { 'D', "use-debuginfod", &use_debuginfod
, 1 },
12143 { 'E', "do-not-use-debuginfod", &use_debuginfod
, 0 },
12145 { 'F', "frames-interp", &do_debug_frames_interp
, 1 },
12146 { 'f', "frames", &do_debug_frames
, 1 },
12147 { 'g', "gdb_index", &do_gdb_index
, 1 },
12148 { 'i', "info", &do_debug_info
, 1 },
12149 { 'K', "follow-links", &do_follow_links
, 1 },
12150 { 'k', "links", &do_debug_links
, 1 },
12151 { 'L', "decodedline", &do_debug_lines
, FLAG_DEBUG_LINES_DECODED
},
12152 { 'l', "rawline", &do_debug_lines
, FLAG_DEBUG_LINES_RAW
},
12153 /* For compatibility with earlier versions of readelf. */
12154 { 'l', "line", &do_debug_lines
, FLAG_DEBUG_LINES_RAW
},
12155 { 'm', "macro", &do_debug_macinfo
, 1 },
12156 { 'N', "no-follow-links", &do_follow_links
, 0 },
12157 { 'O', "str-offsets", &do_debug_str_offsets
, 1 },
12158 { 'o', "loc", &do_debug_loc
, 1 },
12159 { 'p', "pubnames", &do_debug_pubnames
, 1 },
12160 { 'R', "Ranges", &do_debug_ranges
, 1 },
12161 { 'r', "aranges", &do_debug_aranges
, 1 },
12162 /* For compatibility with earlier versions of readelf. */
12163 { 'r', "ranges", &do_debug_aranges
, 1 },
12164 { 's', "str", &do_debug_str
, 1 },
12165 { 'T', "trace_aranges", &do_trace_aranges
, 1 },
12166 { 't', "pubtypes", &do_debug_pubtypes
, 1 },
12167 { 'U', "trace_info", &do_trace_info
, 1 },
12168 { 'u', "trace_abbrev", &do_trace_abbrevs
, 1 },
12169 { 0, NULL
, NULL
, 0 }
12172 /* Enable display of specific DWARF sections as determined by the comma
12173 separated strings in NAMES. Returns non-zero if any displaying was
12177 dwarf_select_sections_by_names (const char *names
)
12185 const debug_dump_long_opts
*entry
;
12187 for (entry
= debug_option_table
; entry
->option
; entry
++)
12189 size_t len
= strlen (entry
->option
);
12191 if (strncmp (p
, entry
->option
, len
) == 0
12192 && (p
[len
] == ',' || p
[len
] == '\0'))
12194 if (entry
->val
== 0)
12195 * entry
->variable
= 0;
12197 * entry
->variable
= entry
->val
;
12198 result
|= entry
->val
;
12205 if (entry
->option
== NULL
)
12207 warn (_("Unrecognized debug option '%s'\n"), p
);
12208 p
= strchr (p
, ',');
12217 /* The --debug-dump=frames-interp option also enables the
12218 --debug-dump=frames option. */
12219 if (do_debug_frames_interp
)
12220 do_debug_frames
= 1;
12225 /* Enable display of specific DWARF sections as determined by the characters
12226 in LETTERS. Returns non-zero if any displaying was enabled. */
12229 dwarf_select_sections_by_letters (const char *letters
)
12235 const debug_dump_long_opts
*entry
;
12237 for (entry
= debug_option_table
; entry
->letter
; entry
++)
12239 if (entry
->letter
== * letters
)
12241 if (entry
->val
== 0)
12242 * entry
->variable
= 0;
12244 * entry
->variable
|= entry
->val
;
12245 result
|= entry
->val
;
12250 if (entry
->letter
== 0)
12251 warn (_("Unrecognized debug letter option '%c'\n"), * letters
);
12256 /* The --debug-dump=frames-interp option also enables the
12257 --debug-dump=frames option. */
12258 if (do_debug_frames_interp
)
12259 do_debug_frames
= 1;
12265 dwarf_select_sections_all (void)
12268 do_debug_abbrevs
= 1;
12269 do_debug_lines
= FLAG_DEBUG_LINES_RAW
;
12270 do_debug_pubnames
= 1;
12271 do_debug_pubtypes
= 1;
12272 do_debug_aranges
= 1;
12273 do_debug_ranges
= 1;
12274 do_debug_frames
= 1;
12275 do_debug_macinfo
= 1;
12280 do_trace_abbrevs
= 1;
12281 do_trace_aranges
= 1;
12283 do_debug_cu_index
= 1;
12284 do_follow_links
= 1;
12285 do_debug_links
= 1;
12286 do_debug_str_offsets
= 1;
12289 #define NO_ABBREVS NULL, NULL, NULL, 0, 0, 0, NULL, 0
12290 #define ABBREV(N) NULL, NULL, NULL, 0, 0, N, NULL, 0
12292 /* N.B. The order here must match the order in section_display_enum. */
12294 struct dwarf_section_display debug_displays
[] =
12296 { { ".debug_abbrev", ".zdebug_abbrev", ".dwabrev", NO_ABBREVS
}, display_debug_abbrev
, &do_debug_abbrevs
, false },
12297 { { ".debug_aranges", ".zdebug_aranges", ".dwarnge", NO_ABBREVS
}, display_debug_aranges
, &do_debug_aranges
, true },
12298 { { ".debug_frame", ".zdebug_frame", ".dwframe", NO_ABBREVS
}, display_debug_frames
, &do_debug_frames
, true },
12299 { { ".debug_info", ".zdebug_info", ".dwinfo", ABBREV (abbrev
)}, display_debug_info
, &do_debug_info
, true },
12300 { { ".debug_line", ".zdebug_line", ".dwline", NO_ABBREVS
}, display_debug_lines
, &do_debug_lines
, true },
12301 { { ".debug_pubnames", ".zdebug_pubnames", ".dwpbnms", NO_ABBREVS
}, display_debug_pubnames
, &do_debug_pubnames
, false },
12302 { { ".debug_gnu_pubnames", ".zdebug_gnu_pubnames", "", NO_ABBREVS
}, display_debug_gnu_pubnames
, &do_debug_pubnames
, false },
12303 { { ".eh_frame", "", "", NO_ABBREVS
}, display_debug_frames
, &do_debug_frames
, true },
12304 { { ".debug_macinfo", ".zdebug_macinfo", "", NO_ABBREVS
}, display_debug_macinfo
, &do_debug_macinfo
, false },
12305 { { ".debug_macro", ".zdebug_macro", ".dwmac", NO_ABBREVS
}, display_debug_macro
, &do_debug_macinfo
, true },
12306 { { ".debug_str", ".zdebug_str", ".dwstr", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, false },
12307 { { ".debug_line_str", ".zdebug_line_str", "", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, false },
12308 { { ".debug_loc", ".zdebug_loc", ".dwloc", NO_ABBREVS
}, display_debug_loc
, &do_debug_loc
, true },
12309 { { ".debug_loclists", ".zdebug_loclists", "", NO_ABBREVS
}, display_debug_loc
, &do_debug_loc
, true },
12310 { { ".debug_loclists.dwo", ".zdebug_loclists.dwo", "", NO_ABBREVS
}, display_debug_loc
, &do_debug_loc
, true },
12311 { { ".debug_pubtypes", ".zdebug_pubtypes", ".dwpbtyp", NO_ABBREVS
}, display_debug_pubnames
, &do_debug_pubtypes
, false },
12312 { { ".debug_gnu_pubtypes", ".zdebug_gnu_pubtypes", "", NO_ABBREVS
}, display_debug_gnu_pubnames
, &do_debug_pubtypes
, false },
12313 { { ".debug_ranges", ".zdebug_ranges", ".dwrnges", NO_ABBREVS
}, display_debug_ranges
, &do_debug_ranges
, true },
12314 { { ".debug_rnglists", ".zdebug_rnglists", "", NO_ABBREVS
}, display_debug_ranges
, &do_debug_ranges
, true },
12315 { { ".debug_rnglists.dwo", ".zdebug_rnglists.dwo", "", NO_ABBREVS
}, display_debug_ranges
, &do_debug_ranges
, true },
12316 { { ".debug_static_func", ".zdebug_static_func", "", NO_ABBREVS
}, display_debug_not_supported
, NULL
, false },
12317 { { ".debug_static_vars", ".zdebug_static_vars", "", NO_ABBREVS
}, display_debug_not_supported
, NULL
, false },
12318 { { ".debug_types", ".zdebug_types", "", ABBREV (abbrev
) }, display_debug_types
, &do_debug_info
, true },
12319 { { ".debug_weaknames", ".zdebug_weaknames", "", NO_ABBREVS
}, display_debug_not_supported
, NULL
, false },
12320 { { ".gdb_index", "", "", NO_ABBREVS
}, display_gdb_index
, &do_gdb_index
, false },
12321 { { ".debug_names", "", "", NO_ABBREVS
}, display_debug_names
, &do_gdb_index
, false },
12322 { { ".trace_info", "", "", ABBREV (trace_abbrev
) }, display_trace_info
, &do_trace_info
, true },
12323 { { ".trace_abbrev", "", "", NO_ABBREVS
}, display_debug_abbrev
, &do_trace_abbrevs
, false },
12324 { { ".trace_aranges", "", "", NO_ABBREVS
}, display_debug_aranges
, &do_trace_aranges
, false },
12325 { { ".debug_info.dwo", ".zdebug_info.dwo", "", ABBREV (abbrev_dwo
) }, display_debug_info
, &do_debug_info
, true },
12326 { { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo", "", NO_ABBREVS
}, display_debug_abbrev
, &do_debug_abbrevs
, false },
12327 { { ".debug_types.dwo", ".zdebug_types.dwo", "", ABBREV (abbrev_dwo
) }, display_debug_types
, &do_debug_info
, true },
12328 { { ".debug_line.dwo", ".zdebug_line.dwo", "", NO_ABBREVS
}, display_debug_lines
, &do_debug_lines
, true },
12329 { { ".debug_loc.dwo", ".zdebug_loc.dwo", "", NO_ABBREVS
}, display_debug_loc
, &do_debug_loc
, true },
12330 { { ".debug_macro.dwo", ".zdebug_macro.dwo", "", NO_ABBREVS
}, display_debug_macro
, &do_debug_macinfo
, true },
12331 { { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo", "", NO_ABBREVS
}, display_debug_macinfo
, &do_debug_macinfo
, false },
12332 { { ".debug_str.dwo", ".zdebug_str.dwo", "", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, true },
12333 { { ".debug_str_offsets", ".zdebug_str_offsets", "", NO_ABBREVS
}, display_debug_str_offsets
, &do_debug_str_offsets
, true },
12334 { { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo", "", NO_ABBREVS
}, display_debug_str_offsets
, &do_debug_str_offsets
, true },
12335 { { ".debug_addr", ".zdebug_addr", "", NO_ABBREVS
}, display_debug_addr
, &do_debug_addr
, true },
12336 { { ".debug_cu_index", "", "", NO_ABBREVS
}, display_cu_index
, &do_debug_cu_index
, false },
12337 { { ".debug_tu_index", "", "", NO_ABBREVS
}, display_cu_index
, &do_debug_cu_index
, false },
12338 { { ".gnu_debuglink", "", "", NO_ABBREVS
}, display_debug_links
, &do_debug_links
, false },
12339 { { ".gnu_debugaltlink", "", "", NO_ABBREVS
}, display_debug_links
, &do_debug_links
, false },
12340 { { ".debug_sup", "", "", NO_ABBREVS
}, display_debug_sup
, &do_debug_links
, false },
12341 /* Separate debug info files can containt their own .debug_str section,
12342 and this might be in *addition* to a .debug_str section already present
12343 in the main file. Hence we need to have two entries for .debug_str. */
12344 { { ".debug_str", ".zdebug_str", "", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, false },
12345 { { ".note.gnu.build-id", "", "", NO_ABBREVS
}, display_debug_not_supported
, NULL
, false },
12348 /* A static assertion. */
12349 extern int debug_displays_assert
[ARRAY_SIZE (debug_displays
) == max
? 1 : -1];