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 if (_mul_overflow (idx
, offset_size
, &index_offset
)
664 && ((index_offset
+= this_set
->section_offsets
[DW_SECT_STR_OFFSETS
])
665 < this_set
->section_offsets
[DW_SECT_STR_OFFSETS
]))
666 || (index_offset
+= str_offsets_base
) < str_offsets_base
667 || index_offset
+ offset_size
< offset_size
668 || index_offset
+ offset_size
> index_section
->size
)
670 warn (_("string index of %" PRIu64
" converts to an offset of %#" PRIx64
671 " which is too big for section %s"),
672 idx
, index_offset
, str_section
->name
);
674 return _("<string index too big>");
677 str_offset
= byte_get (index_section
->start
+ index_offset
, offset_size
);
679 str_offset
-= str_section
->address
;
680 if (str_offset
>= str_section
->size
)
682 warn (_("indirect offset too big: %#" PRIx64
"\n"), str_offset
);
683 return _("<indirect index offset is too big>");
686 ret
= (const char *) str_section
->start
+ str_offset
;
688 /* Unfortunately we cannot rely upon str_section ending with a NUL byte.
689 Since our caller is expecting to receive a well formed C string we test
690 for the lack of a terminating byte here. */
691 if (strnlen (ret
, str_section
->size
- str_offset
)
692 == str_section
->size
- str_offset
)
693 return _("<no NUL byte at end of section>");
699 fetch_indexed_addr (uint64_t offset
, uint32_t num_bytes
)
701 struct dwarf_section
*section
= &debug_displays
[debug_addr
].section
;
703 if (section
->start
== NULL
)
705 warn (_("Cannot fetch indexed address: the .debug_addr section is missing\n"));
709 if (offset
+ num_bytes
> section
->size
)
711 warn (_("Offset into section %s too big: %#" PRIx64
"\n"),
712 section
->name
, offset
);
716 return byte_get (section
->start
+ offset
, num_bytes
);
719 /* This is for resolving DW_FORM_rnglistx and DW_FORM_loclistx.
721 The memory layout is: base_address (taken from the CU's top DIE) points at a table of offsets,
722 relative to the section start.
723 The table of offsets contains the offsets of objects of interest relative to the table of offsets.
724 IDX is the index of the desired object in said table of offsets.
726 This returns the offset of the desired object relative to the section start or -1 upon failure. */
729 fetch_indexed_offset (uint64_t idx
,
730 enum dwarf_section_display_enum sec_enum
,
731 uint64_t base_address
,
732 uint64_t offset_size
)
734 uint64_t offset_of_offset
= base_address
+ idx
* offset_size
;
735 struct dwarf_section
*section
= &debug_displays
[sec_enum
].section
;
737 if (section
->start
== NULL
)
739 warn (_("Unable to locate %s section\n"), section
->uncompressed_name
);
743 if (section
->size
< 4)
745 warn (_("Section %s is too small to contain an value indexed from another section!\n"),
750 if (offset_of_offset
+ offset_size
>= section
->size
)
752 warn (_("Offset of %#" PRIx64
" is too big for section %s\n"),
753 offset_of_offset
, section
->name
);
757 return base_address
+ byte_get (section
->start
+ offset_of_offset
, offset_size
);
760 /* FIXME: There are better and more efficient ways to handle
761 these structures. For now though, I just want something that
762 is simple to implement. */
763 /* Records a single attribute in an abbrev. */
764 typedef struct abbrev_attr
766 unsigned long attribute
;
768 int64_t implicit_const
;
769 struct abbrev_attr
*next
;
773 /* Records a single abbrev. */
774 typedef struct abbrev_entry
776 unsigned long number
;
779 struct abbrev_attr
* first_attr
;
780 struct abbrev_attr
* last_attr
;
781 struct abbrev_entry
* next
;
785 /* Records a set of abbreviations. */
786 typedef struct abbrev_list
788 abbrev_entry
* first_abbrev
;
789 abbrev_entry
* last_abbrev
;
791 struct abbrev_list
* next
;
792 unsigned char * start_of_next_abbrevs
;
796 /* Records all the abbrevs found so far. */
797 static struct abbrev_list
* abbrev_lists
= NULL
;
799 typedef struct abbrev_map
806 /* Maps between CU offsets and abbrev sets. */
807 static abbrev_map
* cu_abbrev_map
= NULL
;
808 static unsigned long num_abbrev_map_entries
= 0;
809 static unsigned long next_free_abbrev_map_entry
= 0;
811 #define INITIAL_NUM_ABBREV_MAP_ENTRIES 8
812 #define ABBREV_MAP_ENTRIES_INCREMENT 8
815 record_abbrev_list_for_cu (uint64_t start
, uint64_t end
,
816 abbrev_list
*list
, abbrev_list
*free_list
)
818 if (free_list
!= NULL
)
820 list
->next
= abbrev_lists
;
824 if (cu_abbrev_map
== NULL
)
826 num_abbrev_map_entries
= INITIAL_NUM_ABBREV_MAP_ENTRIES
;
827 cu_abbrev_map
= xmalloc (num_abbrev_map_entries
* sizeof (* cu_abbrev_map
));
829 else if (next_free_abbrev_map_entry
== num_abbrev_map_entries
)
831 num_abbrev_map_entries
+= ABBREV_MAP_ENTRIES_INCREMENT
;
832 cu_abbrev_map
= xrealloc (cu_abbrev_map
, num_abbrev_map_entries
* sizeof (* cu_abbrev_map
));
835 cu_abbrev_map
[next_free_abbrev_map_entry
].start
= start
;
836 cu_abbrev_map
[next_free_abbrev_map_entry
].end
= end
;
837 cu_abbrev_map
[next_free_abbrev_map_entry
].list
= list
;
838 next_free_abbrev_map_entry
++;
842 free_abbrev_list (abbrev_list
*list
)
844 abbrev_entry
*abbrv
= list
->first_abbrev
;
848 abbrev_attr
*attr
= abbrv
->first_attr
;
852 abbrev_attr
*next_attr
= attr
->next
;
857 abbrev_entry
*next_abbrev
= abbrv
->next
;
862 abbrev_list
*next
= list
->next
;
868 free_all_abbrevs (void)
871 abbrev_lists
= free_abbrev_list (abbrev_lists
);
873 free (cu_abbrev_map
);
874 cu_abbrev_map
= NULL
;
875 next_free_abbrev_map_entry
= 0;
879 find_abbrev_list_by_raw_abbrev (unsigned char *raw
)
883 for (list
= abbrev_lists
; list
!= NULL
; list
= list
->next
)
884 if (list
->raw
== raw
)
890 /* Find the abbreviation map for the CU that includes OFFSET.
891 OFFSET is an absolute offset from the start of the .debug_info section. */
892 /* FIXME: This function is going to slow down readelf & objdump.
893 Not caching abbrevs is likely the answer. */
896 find_abbrev_map_by_offset (uint64_t offset
)
900 for (i
= 0; i
< next_free_abbrev_map_entry
; i
++)
901 if (cu_abbrev_map
[i
].start
<= offset
902 && cu_abbrev_map
[i
].end
> offset
)
903 return cu_abbrev_map
+ i
;
909 add_abbrev (unsigned long number
,
914 abbrev_entry
* entry
;
916 entry
= (abbrev_entry
*) xmalloc (sizeof (*entry
));
918 entry
->number
= number
;
920 entry
->children
= children
;
921 entry
->first_attr
= NULL
;
922 entry
->last_attr
= NULL
;
925 assert (list
!= NULL
);
927 if (list
->first_abbrev
== NULL
)
928 list
->first_abbrev
= entry
;
930 list
->last_abbrev
->next
= entry
;
932 list
->last_abbrev
= entry
;
936 add_abbrev_attr (unsigned long attribute
,
938 int64_t implicit_const
,
943 attr
= (abbrev_attr
*) xmalloc (sizeof (*attr
));
945 attr
->attribute
= attribute
;
947 attr
->implicit_const
= implicit_const
;
950 assert (list
!= NULL
&& list
->last_abbrev
!= NULL
);
952 if (list
->last_abbrev
->first_attr
== NULL
)
953 list
->last_abbrev
->first_attr
= attr
;
955 list
->last_abbrev
->last_attr
->next
= attr
;
957 list
->last_abbrev
->last_attr
= attr
;
960 /* Return processed (partial) contents of a .debug_abbrev section.
961 Returns NULL on errors. */
964 process_abbrev_set (struct dwarf_section
*section
,
965 unsigned char *start
,
968 abbrev_list
*list
= xmalloc (sizeof (*list
));
969 list
->first_abbrev
= NULL
;
970 list
->last_abbrev
= NULL
;
978 unsigned long attribute
;
981 READ_ULEB (entry
, start
, end
);
983 /* A single zero is supposed to end the set according
984 to the standard. If there's more, then signal that to
986 if (start
== end
|| entry
== 0)
988 list
->start_of_next_abbrevs
= start
!= end
? start
: NULL
;
992 READ_ULEB (tag
, start
, end
);
994 return free_abbrev_list (list
);
998 add_abbrev (entry
, tag
, children
, list
);
1003 /* Initialize it due to a false compiler warning. */
1004 int64_t implicit_const
= -1;
1006 READ_ULEB (attribute
, start
, end
);
1010 READ_ULEB (form
, start
, end
);
1014 if (form
== DW_FORM_implicit_const
)
1016 READ_SLEB (implicit_const
, start
, end
);
1021 add_abbrev_attr (attribute
, form
, implicit_const
, list
);
1023 while (attribute
!= 0);
1026 /* Report the missing single zero which ends the section. */
1027 error (_("%s section not zero terminated\n"), section
->name
);
1029 return free_abbrev_list (list
);
1032 /* Return a sequence of abbrevs in SECTION starting at ABBREV_BASE
1033 plus ABBREV_OFFSET and finishing at ABBREV_BASE + ABBREV_SIZE.
1034 If FREE_LIST is non-NULL search the already decoded abbrevs on
1035 abbrev_lists first and if found set *FREE_LIST to NULL. If
1036 searching doesn't find a matching abbrev, set *FREE_LIST to the
1037 newly allocated list. If FREE_LIST is NULL, no search is done and
1038 the returned abbrev_list is always newly allocated. */
1040 static abbrev_list
*
1041 find_and_process_abbrev_set (struct dwarf_section
*section
,
1042 uint64_t abbrev_base
,
1043 uint64_t abbrev_size
,
1044 uint64_t abbrev_offset
,
1045 abbrev_list
**free_list
)
1050 if (abbrev_base
>= section
->size
1051 || abbrev_size
> section
->size
- abbrev_base
)
1053 /* PR 17531: file:4bcd9ce9. */
1054 warn (_("Debug info is corrupted, abbrev size (%#" PRIx64
")"
1055 " is larger than abbrev section size (%#" PRIx64
")\n"),
1056 abbrev_base
+ abbrev_size
, section
->size
);
1059 if (abbrev_offset
>= abbrev_size
)
1061 warn (_("Debug info is corrupted, abbrev offset (%#" PRIx64
")"
1062 " is larger than abbrev section size (%#" PRIx64
")\n"),
1063 abbrev_offset
, abbrev_size
);
1067 unsigned char *start
= section
->start
+ abbrev_base
+ abbrev_offset
;
1068 unsigned char *end
= section
->start
+ abbrev_base
+ abbrev_size
;
1069 abbrev_list
*list
= NULL
;
1071 list
= find_abbrev_list_by_raw_abbrev (start
);
1074 list
= process_abbrev_set (section
, start
, end
);
1082 get_TAG_name (uint64_t tag
)
1084 const char *name
= NULL
;
1086 if ((unsigned int) tag
== tag
)
1087 name
= get_DW_TAG_name ((unsigned int) tag
);
1090 static char buffer
[100];
1092 if (tag
>= DW_TAG_lo_user
&& tag
<= DW_TAG_hi_user
)
1093 snprintf (buffer
, sizeof (buffer
),
1094 _("User TAG value: %#" PRIx64
), tag
);
1096 snprintf (buffer
, sizeof (buffer
),
1097 _("Unknown TAG value: %#" PRIx64
), tag
);
1105 get_FORM_name (unsigned long form
)
1107 const char *name
= NULL
;
1110 return "DW_FORM value: 0";
1112 if ((unsigned int) form
== form
)
1113 name
= get_DW_FORM_name ((unsigned int) form
);
1116 static char buffer
[100];
1118 snprintf (buffer
, sizeof (buffer
), _("Unknown FORM value: %lx"), form
);
1126 get_IDX_name (unsigned long idx
)
1128 const char *name
= NULL
;
1130 if ((unsigned int) idx
== idx
)
1131 name
= get_DW_IDX_name ((unsigned int) idx
);
1134 static char buffer
[100];
1136 snprintf (buffer
, sizeof (buffer
), _("Unknown IDX value: %lx"), idx
);
1143 static unsigned char *
1144 display_block (unsigned char *data
,
1146 const unsigned char * const end
, char delimiter
)
1150 printf (_("%c%" PRIu64
" byte block: "), delimiter
, length
);
1152 return (unsigned char *) end
;
1154 maxlen
= end
- data
;
1155 length
= length
> maxlen
? maxlen
: length
;
1158 printf ("%" PRIx64
" ", byte_get (data
++, 1));
1164 decode_location_expression (unsigned char * data
,
1165 unsigned int pointer_size
,
1166 unsigned int offset_size
,
1170 struct dwarf_section
* section
)
1175 unsigned char *end
= data
+ length
;
1176 int need_frame_base
= 0;
1185 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1186 printf ("DW_OP_addr: %" PRIx64
, uvalue
);
1189 printf ("DW_OP_deref");
1192 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1193 printf ("DW_OP_const1u: %" PRIu64
, uvalue
);
1196 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 1, end
);
1197 printf ("DW_OP_const1s: %" PRId64
, svalue
);
1200 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
1201 printf ("DW_OP_const2u: %" PRIu64
, uvalue
);
1204 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1205 printf ("DW_OP_const2s: %" PRId64
, svalue
);
1208 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1209 printf ("DW_OP_const4u: %" PRIu64
, uvalue
);
1212 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
1213 printf ("DW_OP_const4s: %" PRId64
, svalue
);
1216 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 8, end
);
1217 printf ("DW_OP_const8u: %" PRIu64
, uvalue
);
1220 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 8, end
);
1221 printf ("DW_OP_const8s: %" PRId64
, svalue
);
1224 READ_ULEB (uvalue
, data
, end
);
1225 printf ("DW_OP_constu: %" PRIu64
, uvalue
);
1228 READ_SLEB (svalue
, data
, end
);
1229 printf ("DW_OP_consts: %" PRId64
, svalue
);
1232 printf ("DW_OP_dup");
1235 printf ("DW_OP_drop");
1238 printf ("DW_OP_over");
1241 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1242 printf ("DW_OP_pick: %" PRIu64
, uvalue
);
1245 printf ("DW_OP_swap");
1248 printf ("DW_OP_rot");
1251 printf ("DW_OP_xderef");
1254 printf ("DW_OP_abs");
1257 printf ("DW_OP_and");
1260 printf ("DW_OP_div");
1263 printf ("DW_OP_minus");
1266 printf ("DW_OP_mod");
1269 printf ("DW_OP_mul");
1272 printf ("DW_OP_neg");
1275 printf ("DW_OP_not");
1278 printf ("DW_OP_or");
1281 printf ("DW_OP_plus");
1283 case DW_OP_plus_uconst
:
1284 READ_ULEB (uvalue
, data
, end
);
1285 printf ("DW_OP_plus_uconst: %" PRIu64
, uvalue
);
1288 printf ("DW_OP_shl");
1291 printf ("DW_OP_shr");
1294 printf ("DW_OP_shra");
1297 printf ("DW_OP_xor");
1300 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1301 printf ("DW_OP_bra: %" PRId64
, svalue
);
1304 printf ("DW_OP_eq");
1307 printf ("DW_OP_ge");
1310 printf ("DW_OP_gt");
1313 printf ("DW_OP_le");
1316 printf ("DW_OP_lt");
1319 printf ("DW_OP_ne");
1322 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1323 printf ("DW_OP_skip: %" PRId64
, svalue
);
1358 printf ("DW_OP_lit%d", op
- DW_OP_lit0
);
1393 printf ("DW_OP_reg%d (%s)", op
- DW_OP_reg0
,
1394 regname (op
- DW_OP_reg0
, 1));
1429 READ_SLEB (svalue
, data
, end
);
1430 printf ("DW_OP_breg%d (%s): %" PRId64
,
1431 op
- DW_OP_breg0
, regname (op
- DW_OP_breg0
, 1), svalue
);
1435 READ_ULEB (uvalue
, data
, end
);
1436 printf ("DW_OP_regx: %" PRIu64
" (%s)",
1437 uvalue
, regname (uvalue
, 1));
1440 need_frame_base
= 1;
1441 READ_SLEB (svalue
, data
, end
);
1442 printf ("DW_OP_fbreg: %" PRId64
, svalue
);
1445 READ_ULEB (uvalue
, data
, end
);
1446 READ_SLEB (svalue
, data
, end
);
1447 printf ("DW_OP_bregx: %" PRIu64
" (%s) %" PRId64
,
1448 uvalue
, regname (uvalue
, 1), svalue
);
1451 READ_ULEB (uvalue
, data
, end
);
1452 printf ("DW_OP_piece: %" PRIu64
, uvalue
);
1454 case DW_OP_deref_size
:
1455 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1456 printf ("DW_OP_deref_size: %" PRIu64
, uvalue
);
1458 case DW_OP_xderef_size
:
1459 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1460 printf ("DW_OP_xderef_size: %" PRIu64
, uvalue
);
1463 printf ("DW_OP_nop");
1466 /* DWARF 3 extensions. */
1467 case DW_OP_push_object_address
:
1468 printf ("DW_OP_push_object_address");
1471 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1472 this ought to be an 8-byte wide computation. */
1473 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1474 printf ("DW_OP_call2: <%#" PRIx64
">", svalue
+ cu_offset
);
1477 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1478 this ought to be an 8-byte wide computation. */
1479 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
1480 printf ("DW_OP_call4: <%#" PRIx64
">", svalue
+ cu_offset
);
1482 case DW_OP_call_ref
:
1483 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1484 this ought to be an 8-byte wide computation. */
1485 if (dwarf_version
== -1)
1487 printf (_("(DW_OP_call_ref in frame info)"));
1488 /* No way to tell where the next op is, so just bail. */
1489 return need_frame_base
;
1491 if (dwarf_version
== 2)
1493 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1497 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1499 printf ("DW_OP_call_ref: <%#" PRIx64
">", uvalue
);
1501 case DW_OP_form_tls_address
:
1502 printf ("DW_OP_form_tls_address");
1504 case DW_OP_call_frame_cfa
:
1505 printf ("DW_OP_call_frame_cfa");
1507 case DW_OP_bit_piece
:
1508 printf ("DW_OP_bit_piece: ");
1509 READ_ULEB (uvalue
, data
, end
);
1510 printf (_("size: %" PRIu64
" "), uvalue
);
1511 READ_ULEB (uvalue
, data
, end
);
1512 printf (_("offset: %" PRIu64
" "), uvalue
);
1515 /* DWARF 4 extensions. */
1516 case DW_OP_stack_value
:
1517 printf ("DW_OP_stack_value");
1520 case DW_OP_implicit_value
:
1521 printf ("DW_OP_implicit_value");
1522 READ_ULEB (uvalue
, data
, end
);
1523 data
= display_block (data
, uvalue
, end
, ' ');
1526 /* GNU extensions. */
1527 case DW_OP_GNU_push_tls_address
:
1528 printf (_("DW_OP_GNU_push_tls_address or DW_OP_HP_unknown"));
1530 case DW_OP_GNU_uninit
:
1531 printf ("DW_OP_GNU_uninit");
1532 /* FIXME: Is there data associated with this OP ? */
1534 case DW_OP_GNU_encoded_addr
:
1541 addr
= get_encoded_value (&data
, encoding
, section
, end
);
1543 printf ("DW_OP_GNU_encoded_addr: fmt:%02x addr:", encoding
);
1544 print_hex_ns (addr
, pointer_size
);
1547 case DW_OP_implicit_pointer
:
1548 case DW_OP_GNU_implicit_pointer
:
1549 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1550 this ought to be an 8-byte wide computation. */
1551 if (dwarf_version
== -1)
1553 printf (_("(%s in frame info)"),
1554 (op
== DW_OP_implicit_pointer
1555 ? "DW_OP_implicit_pointer"
1556 : "DW_OP_GNU_implicit_pointer"));
1557 /* No way to tell where the next op is, so just bail. */
1558 return need_frame_base
;
1560 if (dwarf_version
== 2)
1562 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1566 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1568 READ_SLEB (svalue
, data
, end
);
1569 printf ("%s: <%#" PRIx64
"> %" PRId64
,
1570 (op
== DW_OP_implicit_pointer
1571 ? "DW_OP_implicit_pointer" : "DW_OP_GNU_implicit_pointer"),
1574 case DW_OP_entry_value
:
1575 case DW_OP_GNU_entry_value
:
1576 READ_ULEB (uvalue
, data
, end
);
1577 /* PR 17531: file: 0cc9cd00. */
1578 if (uvalue
> (size_t) (end
- data
))
1579 uvalue
= end
- data
;
1580 printf ("%s: (", (op
== DW_OP_entry_value
? "DW_OP_entry_value"
1581 : "DW_OP_GNU_entry_value"));
1582 if (decode_location_expression (data
, pointer_size
, offset_size
,
1583 dwarf_version
, uvalue
,
1584 cu_offset
, section
))
1585 need_frame_base
= 1;
1589 case DW_OP_const_type
:
1590 case DW_OP_GNU_const_type
:
1591 READ_ULEB (uvalue
, data
, end
);
1592 printf ("%s: <%#" PRIx64
"> ",
1593 (op
== DW_OP_const_type
? "DW_OP_const_type"
1594 : "DW_OP_GNU_const_type"),
1595 cu_offset
+ uvalue
);
1596 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1597 data
= display_block (data
, uvalue
, end
, ' ');
1599 case DW_OP_regval_type
:
1600 case DW_OP_GNU_regval_type
:
1601 READ_ULEB (uvalue
, data
, end
);
1602 printf ("%s: %" PRIu64
" (%s)",
1603 (op
== DW_OP_regval_type
? "DW_OP_regval_type"
1604 : "DW_OP_GNU_regval_type"),
1605 uvalue
, regname (uvalue
, 1));
1606 READ_ULEB (uvalue
, data
, end
);
1607 printf (" <%#" PRIx64
">", cu_offset
+ uvalue
);
1609 case DW_OP_deref_type
:
1610 case DW_OP_GNU_deref_type
:
1611 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1612 printf ("%s: %" PRId64
,
1613 (op
== DW_OP_deref_type
? "DW_OP_deref_type"
1614 : "DW_OP_GNU_deref_type"),
1616 READ_ULEB (uvalue
, data
, end
);
1617 printf (" <%#" PRIx64
">", cu_offset
+ uvalue
);
1620 case DW_OP_GNU_convert
:
1621 READ_ULEB (uvalue
, data
, end
);
1622 printf ("%s <%#" PRIx64
">",
1623 (op
== DW_OP_convert
? "DW_OP_convert" : "DW_OP_GNU_convert"),
1624 uvalue
? cu_offset
+ uvalue
: uvalue
);
1626 case DW_OP_reinterpret
:
1627 case DW_OP_GNU_reinterpret
:
1628 READ_ULEB (uvalue
, data
, end
);
1629 printf ("%s <%#" PRIx64
">",
1630 (op
== DW_OP_reinterpret
? "DW_OP_reinterpret"
1631 : "DW_OP_GNU_reinterpret"),
1632 uvalue
? cu_offset
+ uvalue
: uvalue
);
1634 case DW_OP_GNU_parameter_ref
:
1635 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1636 printf ("DW_OP_GNU_parameter_ref: <%#" PRIx64
">",
1637 cu_offset
+ uvalue
);
1640 READ_ULEB (uvalue
, data
, end
);
1641 printf ("DW_OP_addrx <%#" PRIx64
">", uvalue
);
1643 case DW_OP_GNU_addr_index
:
1644 READ_ULEB (uvalue
, data
, end
);
1645 printf ("DW_OP_GNU_addr_index <%#" PRIx64
">", uvalue
);
1647 case DW_OP_GNU_const_index
:
1648 READ_ULEB (uvalue
, data
, end
);
1649 printf ("DW_OP_GNU_const_index <%#" PRIx64
">", uvalue
);
1651 case DW_OP_GNU_variable_value
:
1652 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1653 this ought to be an 8-byte wide computation. */
1654 if (dwarf_version
== -1)
1656 printf (_("(DW_OP_GNU_variable_value in frame info)"));
1657 /* No way to tell where the next op is, so just bail. */
1658 return need_frame_base
;
1660 if (dwarf_version
== 2)
1662 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1666 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1668 printf ("DW_OP_GNU_variable_value: <%#" PRIx64
">", uvalue
);
1671 /* HP extensions. */
1672 case DW_OP_HP_is_value
:
1673 printf ("DW_OP_HP_is_value");
1674 /* FIXME: Is there data associated with this OP ? */
1676 case DW_OP_HP_fltconst4
:
1677 printf ("DW_OP_HP_fltconst4");
1678 /* FIXME: Is there data associated with this OP ? */
1680 case DW_OP_HP_fltconst8
:
1681 printf ("DW_OP_HP_fltconst8");
1682 /* FIXME: Is there data associated with this OP ? */
1684 case DW_OP_HP_mod_range
:
1685 printf ("DW_OP_HP_mod_range");
1686 /* FIXME: Is there data associated with this OP ? */
1688 case DW_OP_HP_unmod_range
:
1689 printf ("DW_OP_HP_unmod_range");
1690 /* FIXME: Is there data associated with this OP ? */
1693 printf ("DW_OP_HP_tls");
1694 /* FIXME: Is there data associated with this OP ? */
1697 /* PGI (STMicroelectronics) extensions. */
1698 case DW_OP_PGI_omp_thread_num
:
1699 /* Pushes the thread number for the current thread as it would be
1700 returned by the standard OpenMP library function:
1701 omp_get_thread_num(). The "current thread" is the thread for
1702 which the expression is being evaluated. */
1703 printf ("DW_OP_PGI_omp_thread_num");
1707 if (op
>= DW_OP_lo_user
1708 && op
<= DW_OP_hi_user
)
1709 printf (_("(User defined location op %#x)"), op
);
1711 printf (_("(Unknown location op %#x)"), op
);
1712 /* No way to tell where the next op is, so just bail. */
1713 return need_frame_base
;
1716 /* Separate the ops. */
1721 return need_frame_base
;
1724 /* Find the CU or TU set corresponding to the given CU_OFFSET.
1725 This is used for DWARF package files. */
1727 static struct cu_tu_set
*
1728 find_cu_tu_set_v2 (uint64_t cu_offset
, int do_types
)
1730 struct cu_tu_set
*p
;
1732 unsigned int dw_sect
;
1738 dw_sect
= DW_SECT_TYPES
;
1744 dw_sect
= DW_SECT_INFO
;
1748 if (p
->section_offsets
[dw_sect
] == cu_offset
)
1757 fetch_alt_indirect_string (uint64_t offset
)
1761 if (! do_follow_links
)
1764 if (first_separate_info
== NULL
)
1765 return _("<no links available>");
1767 for (i
= first_separate_info
; i
!= NULL
; i
= i
->next
)
1769 struct dwarf_section
* section
;
1772 if (! load_debug_section (separate_debug_str
, i
->handle
))
1775 section
= &debug_displays
[separate_debug_str
].section
;
1777 if (section
->start
== NULL
)
1780 if (offset
>= section
->size
)
1783 ret
= (const char *) (section
->start
+ offset
);
1784 /* Unfortunately we cannot rely upon the .debug_str section ending with a
1785 NUL byte. Since our caller is expecting to receive a well formed C
1786 string we test for the lack of a terminating byte here. */
1787 if (strnlen ((const char *) ret
, section
->size
- offset
)
1788 == section
->size
- offset
)
1789 return _("<no NUL byte at end of alt .debug_str section>");
1794 warn (_("DW_FORM_GNU_strp_alt offset (%#" PRIx64
")"
1795 " too big or no string sections available\n"), offset
);
1796 return _("<offset is too big>");
1800 get_AT_name (unsigned long attribute
)
1805 return "DW_AT value: 0";
1807 /* One value is shared by the MIPS and HP extensions: */
1808 if (attribute
== DW_AT_MIPS_fde
)
1809 return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable";
1811 name
= get_DW_AT_name (attribute
);
1815 static char buffer
[100];
1817 snprintf (buffer
, sizeof (buffer
), _("Unknown AT value: %lx"),
1826 add_dwo_info (const char * value
, uint64_t cu_offset
, dwo_type type
)
1828 dwo_info
* dwinfo
= xmalloc (sizeof * dwinfo
);
1830 dwinfo
->type
= type
;
1831 dwinfo
->value
= value
;
1832 dwinfo
->cu_offset
= cu_offset
;
1833 dwinfo
->next
= first_dwo_info
;
1834 first_dwo_info
= dwinfo
;
1838 add_dwo_name (const char * name
, uint64_t cu_offset
)
1840 add_dwo_info (name
, cu_offset
, DWO_NAME
);
1844 add_dwo_dir (const char * dir
, uint64_t cu_offset
)
1846 add_dwo_info (dir
, cu_offset
, DWO_DIR
);
1850 add_dwo_id (const char * id
, uint64_t cu_offset
)
1852 add_dwo_info (id
, cu_offset
, DWO_ID
);
1856 free_dwo_info (void)
1861 for (dwinfo
= first_dwo_info
; dwinfo
!= NULL
; dwinfo
= next
)
1863 next
= dwinfo
->next
;
1866 first_dwo_info
= NULL
;
1869 /* Ensure that START + UVALUE is less than END.
1870 Return an adjusted UVALUE if necessary to ensure this relationship. */
1872 static inline uint64_t
1873 check_uvalue (const unsigned char *start
,
1875 const unsigned char *end
)
1877 uint64_t max_uvalue
= end
- start
;
1879 /* See PR 17512: file: 008-103549-0.001:0.1.
1880 and PR 24829 for examples of where these tests are triggered. */
1881 if (uvalue
> max_uvalue
)
1883 warn (_("Corrupt attribute block length: %#" PRIx64
"\n"), uvalue
);
1884 uvalue
= max_uvalue
;
1890 static unsigned char *
1891 skip_attr_bytes (unsigned long form
,
1892 unsigned char *data
,
1894 uint64_t pointer_size
,
1895 uint64_t offset_size
,
1897 uint64_t *value_return
)
1900 uint64_t uvalue
= 0;
1907 case DW_FORM_ref_addr
:
1908 if (dwarf_version
== 2)
1909 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1910 else if (dwarf_version
> 2)
1911 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1917 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1921 case DW_FORM_line_strp
:
1922 case DW_FORM_sec_offset
:
1923 case DW_FORM_GNU_ref_alt
:
1924 case DW_FORM_GNU_strp_alt
:
1925 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1928 case DW_FORM_flag_present
:
1936 case DW_FORM_addrx1
:
1937 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1941 case DW_FORM_addrx3
:
1942 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 3, end
);
1948 case DW_FORM_addrx2
:
1949 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
1955 case DW_FORM_addrx4
:
1956 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1960 READ_SLEB (svalue
, data
, end
);
1964 case DW_FORM_ref_udata
:
1966 case DW_FORM_GNU_str_index
:
1968 case DW_FORM_GNU_addr_index
:
1970 case DW_FORM_loclistx
:
1971 case DW_FORM_rnglistx
:
1972 READ_ULEB (uvalue
, data
, end
);
1976 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 8, end
);
1980 case DW_FORM_ref_sig8
:
1984 case DW_FORM_data16
:
1988 case DW_FORM_string
:
1989 inc
= strnlen ((char *) data
, end
- data
) + 1;
1993 case DW_FORM_exprloc
:
1994 READ_ULEB (uvalue
, data
, end
);
1998 case DW_FORM_block1
:
1999 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
2003 case DW_FORM_block2
:
2004 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
2008 case DW_FORM_block4
:
2009 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
2013 case DW_FORM_indirect
:
2014 READ_ULEB (form
, data
, end
);
2015 if (form
== DW_FORM_implicit_const
)
2016 SKIP_ULEB (data
, end
);
2017 return skip_attr_bytes (form
, data
, end
, pointer_size
, offset_size
,
2018 dwarf_version
, value_return
);
2024 * value_return
= uvalue
;
2025 if (inc
<= (size_t) (end
- data
))
2032 /* Given form FORM with value UVALUE, locate and return the abbreviation
2033 associated with it. */
2035 static abbrev_entry
*
2036 get_type_abbrev_from_form (unsigned long form
,
2037 unsigned long uvalue
,
2039 unsigned char *cu_end
,
2040 const struct dwarf_section
*section
,
2041 unsigned long *abbrev_num_return
,
2042 unsigned char **data_return
,
2043 abbrev_map
**map_return
)
2045 unsigned long abbrev_number
;
2047 abbrev_entry
* entry
;
2048 unsigned char * data
;
2050 if (abbrev_num_return
!= NULL
)
2051 * abbrev_num_return
= 0;
2052 if (data_return
!= NULL
)
2053 * data_return
= NULL
;
2057 case DW_FORM_GNU_ref_alt
:
2058 case DW_FORM_ref_sig8
:
2059 /* FIXME: We are unable to handle this form at the moment. */
2062 case DW_FORM_ref_addr
:
2063 if (uvalue
>= section
->size
)
2065 warn (_("Unable to resolve ref_addr form: uvalue %lx "
2066 "> section size %" PRIx64
" (%s)\n"),
2067 uvalue
, section
->size
, section
->name
);
2072 case DW_FORM_ref_sup4
:
2073 case DW_FORM_ref_sup8
:
2080 case DW_FORM_ref_udata
:
2081 if (uvalue
+ cu_offset
< uvalue
2082 || uvalue
+ cu_offset
> (size_t) (cu_end
- section
->start
))
2084 warn (_("Unable to resolve ref form: uvalue %lx + cu_offset %" PRIx64
2085 " > CU size %tx\n"),
2086 uvalue
, cu_offset
, cu_end
- section
->start
);
2089 uvalue
+= cu_offset
;
2092 /* FIXME: Are there other DW_FORMs that can be used by types ? */
2095 warn (_("Unexpected form %lx encountered whilst finding abbreviation for type\n"), form
);
2099 data
= (unsigned char *) section
->start
+ uvalue
;
2100 map
= find_abbrev_map_by_offset (uvalue
);
2104 warn (_("Unable to find abbreviations for CU offset %#lx\n"), uvalue
);
2107 if (map
->list
== NULL
)
2109 warn (_("Empty abbreviation list encountered for CU offset %lx\n"), uvalue
);
2113 if (map_return
!= NULL
)
2115 if (form
== DW_FORM_ref_addr
)
2121 READ_ULEB (abbrev_number
, data
, section
->start
+ section
->size
);
2123 for (entry
= map
->list
->first_abbrev
; entry
!= NULL
; entry
= entry
->next
)
2124 if (entry
->number
== abbrev_number
)
2127 if (abbrev_num_return
!= NULL
)
2128 * abbrev_num_return
= abbrev_number
;
2130 if (data_return
!= NULL
)
2131 * data_return
= data
;
2134 warn (_("Unable to find entry for abbreviation %lu\n"), abbrev_number
);
2139 /* Return IS_SIGNED set to TRUE if the type using abbreviation ENTRY
2140 can be determined to be a signed type. The data for ENTRY can be
2141 found starting at DATA. */
2144 get_type_signedness (abbrev_entry
*entry
,
2145 const struct dwarf_section
*section
,
2146 unsigned char *data
,
2149 uint64_t pointer_size
,
2150 uint64_t offset_size
,
2153 unsigned int nesting
)
2157 * is_signed
= false;
2159 #define MAX_NESTING 20
2160 if (nesting
> MAX_NESTING
)
2162 /* FIXME: Warn - or is this expected ?
2163 NB/ We need to avoid infinite recursion. */
2167 for (attr
= entry
->first_attr
;
2168 attr
!= NULL
&& attr
->attribute
;
2171 unsigned char * orig_data
= data
;
2172 uint64_t uvalue
= 0;
2174 data
= skip_attr_bytes (attr
->form
, data
, end
, pointer_size
,
2175 offset_size
, dwarf_version
, & uvalue
);
2179 switch (attr
->attribute
)
2181 case DW_AT_linkage_name
:
2185 if (attr
->form
== DW_FORM_strp
)
2186 printf (", %s", fetch_indirect_string (uvalue
));
2187 else if (attr
->form
== DW_FORM_string
)
2188 printf (", %.*s", (int) (end
- orig_data
), orig_data
);
2195 abbrev_entry
*type_abbrev
;
2196 unsigned char *type_data
;
2199 type_abbrev
= get_type_abbrev_from_form (attr
->form
,
2204 NULL
/* abbrev num return */,
2207 if (type_abbrev
== NULL
)
2210 get_type_signedness (type_abbrev
, section
, type_data
,
2211 map
? section
->start
+ map
->end
: end
,
2212 map
? map
->start
: cu_offset
,
2213 pointer_size
, offset_size
, dwarf_version
,
2214 is_signed
, nesting
+ 1);
2218 case DW_AT_encoding
:
2219 /* Determine signness. */
2222 case DW_ATE_address
:
2223 /* FIXME - some architectures have signed addresses. */
2224 case DW_ATE_boolean
:
2225 case DW_ATE_unsigned
:
2226 case DW_ATE_unsigned_char
:
2227 case DW_ATE_unsigned_fixed
:
2228 * is_signed
= false;
2232 case DW_ATE_complex_float
:
2235 case DW_ATE_signed_char
:
2236 case DW_ATE_imaginary_float
:
2237 case DW_ATE_decimal_float
:
2238 case DW_ATE_signed_fixed
:
2248 read_and_print_leb128 (unsigned char *data
,
2249 unsigned int *bytes_read
,
2250 unsigned const char *end
,
2254 uint64_t val
= read_leb128 (data
, end
, is_signed
, bytes_read
, &status
);
2256 report_leb_status (status
);
2258 printf ("%" PRId64
, val
);
2260 printf ("%" PRIu64
, val
);
2264 display_discr_list (unsigned long form
,
2266 unsigned char *data
,
2269 unsigned char *end
= data
;
2273 printf ("[default]");
2280 case DW_FORM_block1
:
2281 case DW_FORM_block2
:
2282 case DW_FORM_block4
:
2283 /* Move data pointer back to the start of the byte array. */
2287 printf ("<corrupt>\n");
2288 warn (_("corrupt discr_list - not using a block form\n"));
2294 printf ("<corrupt>\n");
2295 warn (_("corrupt discr_list - block not long enough\n"));
2299 bool is_signed
= (level
> 0 && level
<= MAX_CU_NESTING
2300 ? level_type_signed
[level
- 1] : false);
2305 unsigned char discriminant
;
2306 unsigned int bytes_read
;
2308 SAFE_BYTE_GET_AND_INC (discriminant
, data
, 1, end
);
2310 switch (discriminant
)
2314 read_and_print_leb128 (data
, & bytes_read
, end
, is_signed
);
2320 read_and_print_leb128 (data
, & bytes_read
, end
, is_signed
);
2324 read_and_print_leb128 (data
, & bytes_read
, end
, is_signed
);
2329 printf ("<corrupt>\n");
2330 warn (_("corrupt discr_list - unrecognized discriminant byte %#x\n"),
2340 printf (")(signed)");
2342 printf (")(unsigned)");
2345 static unsigned char *
2346 read_and_display_attr_value (unsigned long attribute
,
2348 int64_t implicit_const
,
2349 unsigned char *start
,
2350 unsigned char *data
,
2353 uint64_t pointer_size
,
2354 uint64_t offset_size
,
2356 debug_info
*debug_info_p
,
2358 struct dwarf_section
*section
,
2359 struct cu_tu_set
*this_set
,
2364 uint64_t uvalue
= 0;
2365 uint64_t uvalue_hi
= 0;
2366 unsigned char *block_start
= NULL
;
2367 unsigned char *orig_data
= data
;
2369 if (data
> end
|| (data
== end
&& form
!= DW_FORM_flag_present
))
2371 warn (_("Corrupt attribute\n"));
2375 if (do_wide
&& ! do_loc
)
2377 /* PR 26847: Display the name of the form. */
2378 const char * name
= get_FORM_name (form
);
2380 /* For convenience we skip the DW_FORM_ prefix to the name. */
2382 name
+= 8; /* strlen ("DW_FORM_") */
2383 printf ("%c(%s)", delimiter
, name
);
2388 case DW_FORM_ref_addr
:
2389 if (dwarf_version
== 2)
2390 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
2391 else if (dwarf_version
> 2)
2392 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
2394 error (_("Internal error: DW_FORM_ref_addr is not supported in DWARF version 1.\n"));
2398 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
2401 case DW_FORM_strp_sup
:
2403 case DW_FORM_line_strp
:
2404 case DW_FORM_sec_offset
:
2405 case DW_FORM_GNU_ref_alt
:
2406 case DW_FORM_GNU_strp_alt
:
2407 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
2410 case DW_FORM_flag_present
:
2418 case DW_FORM_addrx1
:
2419 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
2425 case DW_FORM_addrx2
:
2426 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
2430 case DW_FORM_addrx3
:
2431 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 3, end
);
2434 case DW_FORM_ref_sup4
:
2438 case DW_FORM_addrx4
:
2439 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
2442 case DW_FORM_ref_sup8
:
2445 case DW_FORM_ref_sig8
:
2446 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 8, end
);
2449 case DW_FORM_data16
:
2450 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 8, end
);
2451 SAFE_BYTE_GET_AND_INC (uvalue_hi
, data
, 8, end
);
2452 if (byte_get
!= byte_get_little_endian
)
2454 uint64_t utmp
= uvalue
;
2461 READ_SLEB (svalue
, data
, end
);
2465 case DW_FORM_GNU_str_index
:
2467 case DW_FORM_ref_udata
:
2469 case DW_FORM_GNU_addr_index
:
2471 case DW_FORM_loclistx
:
2472 case DW_FORM_rnglistx
:
2473 READ_ULEB (uvalue
, data
, end
);
2476 case DW_FORM_indirect
:
2477 READ_ULEB (form
, data
, end
);
2479 printf ("%c%s", delimiter
, get_FORM_name (form
));
2480 if (form
== DW_FORM_implicit_const
)
2481 READ_SLEB (implicit_const
, data
, end
);
2482 return read_and_display_attr_value (attribute
, form
, implicit_const
,
2484 cu_offset
, pointer_size
,
2485 offset_size
, dwarf_version
,
2486 debug_info_p
, do_loc
,
2487 section
, this_set
, delimiter
, level
);
2489 case DW_FORM_implicit_const
:
2490 uvalue
= implicit_const
;
2499 case DW_FORM_ref_addr
:
2501 printf ("%c<%#" PRIx64
">", delimiter
, uvalue
);
2504 case DW_FORM_GNU_ref_alt
:
2508 /* We have already printed the form name. */
2509 printf ("%c<%#" PRIx64
">", delimiter
, uvalue
);
2511 printf ("%c<alt %#" PRIx64
">", delimiter
, uvalue
);
2513 /* FIXME: Follow the reference... */
2519 case DW_FORM_ref_sup4
:
2520 case DW_FORM_ref_udata
:
2522 printf ("%c<%#" PRIx64
">", delimiter
, uvalue
+ cu_offset
);
2527 case DW_FORM_sec_offset
:
2529 printf ("%c%#" PRIx64
, delimiter
, uvalue
);
2532 case DW_FORM_flag_present
:
2538 printf ("%c%" PRId64
, delimiter
, uvalue
);
2543 printf ("%c%" PRIu64
, delimiter
, uvalue
);
2546 case DW_FORM_implicit_const
:
2548 printf ("%c%" PRId64
, delimiter
, implicit_const
);
2551 case DW_FORM_ref_sup8
:
2556 uint64_t utmp
= uvalue
;
2557 if (form
== DW_FORM_ref8
)
2559 printf ("%c%#" PRIx64
, delimiter
, utmp
);
2563 case DW_FORM_data16
:
2567 printf (" %#" PRIx64
, uvalue
);
2569 printf (" %#" PRIx64
"%016" PRIx64
, uvalue_hi
, uvalue
);
2573 case DW_FORM_string
:
2575 printf ("%c%.*s", delimiter
, (int) (end
- data
), data
);
2576 data
+= strnlen ((char *) data
, end
- data
);
2582 case DW_FORM_exprloc
:
2583 READ_ULEB (uvalue
, data
, end
);
2586 if (block_start
>= end
)
2588 warn (_("Block ends prematurely\n"));
2593 uvalue
= check_uvalue (block_start
, uvalue
, end
);
2595 data
= block_start
+ uvalue
;
2600 SAFE_BYTE_GET (op
, block_start
, sizeof (op
), end
);
2601 if (op
!= DW_OP_addrx
)
2602 data
= display_block (block_start
, uvalue
, end
, delimiter
);
2606 case DW_FORM_block1
:
2607 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
2610 case DW_FORM_block2
:
2611 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
2614 case DW_FORM_block4
:
2615 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
2622 /* We have already displayed the form name. */
2623 printf (_("%c(offset: %#" PRIx64
"): %s"),
2624 delimiter
, uvalue
, fetch_indirect_string (uvalue
));
2626 printf (_("%c(indirect string, offset: %#" PRIx64
"): %s"),
2627 delimiter
, uvalue
, fetch_indirect_string (uvalue
));
2631 case DW_FORM_line_strp
:
2635 /* We have already displayed the form name. */
2636 printf (_("%c(offset: %#" PRIx64
"): %s"),
2637 delimiter
, uvalue
, fetch_indirect_line_string (uvalue
));
2639 printf (_("%c(indirect line string, offset: %#" PRIx64
"): %s"),
2640 delimiter
, uvalue
, fetch_indirect_line_string (uvalue
));
2644 case DW_FORM_GNU_str_index
:
2652 const char *suffix
= section
? strrchr (section
->name
, '.') : NULL
;
2653 bool dwo
= suffix
&& strcmp (suffix
, ".dwo") == 0;
2656 strng
= fetch_indexed_string (uvalue
, this_set
, offset_size
, dwo
,
2657 debug_info_p
? debug_info_p
->str_offsets_base
: 0);
2659 /* We have already displayed the form name. */
2660 printf (_("%c(offset: %#" PRIx64
"): %s"),
2661 delimiter
, uvalue
, strng
);
2663 printf (_("%c(indexed string: %#" PRIx64
"): %s"),
2664 delimiter
, uvalue
, strng
);
2668 case DW_FORM_GNU_strp_alt
:
2672 /* We have already displayed the form name. */
2673 printf (_("%c(offset: %#" PRIx64
") %s"),
2674 delimiter
, uvalue
, fetch_alt_indirect_string (uvalue
));
2676 printf (_("%c(alt indirect string, offset: %#" PRIx64
") %s"),
2677 delimiter
, uvalue
, fetch_alt_indirect_string (uvalue
));
2681 case DW_FORM_indirect
:
2682 /* Handled above. */
2685 case DW_FORM_ref_sig8
:
2687 printf ("%c%s: %#" PRIx64
, delimiter
, do_wide
? "" : "signature",
2691 case DW_FORM_GNU_addr_index
:
2693 case DW_FORM_addrx1
:
2694 case DW_FORM_addrx2
:
2695 case DW_FORM_addrx3
:
2696 case DW_FORM_addrx4
:
2697 case DW_FORM_loclistx
:
2698 case DW_FORM_rnglistx
:
2702 const char *suffix
= strrchr (section
->name
, '.');
2703 bool dwo
= suffix
&& strcmp (suffix
, ".dwo") == 0;
2705 if (form
== DW_FORM_loclistx
)
2709 idx
= fetch_indexed_offset (uvalue
, loclists_dwo
,
2710 debug_info_p
->loclists_base
,
2711 debug_info_p
->offset_size
);
2712 if (idx
!= (uint64_t) -1)
2713 idx
+= (offset_size
== 8) ? 20 : 12;
2715 else if (debug_info_p
== NULL
|| dwarf_version
> 4)
2717 idx
= fetch_indexed_offset (uvalue
, loclists
,
2718 debug_info_p
->loclists_base
,
2719 debug_info_p
->offset_size
);
2723 /* We want to compute:
2724 idx = fetch_indexed_value (uvalue, loclists,
2725 debug_info_p->loclists_base);
2726 idx += debug_info_p->loclists_base;
2727 Fortunately we already have that sum cached in the
2728 loc_offsets array. */
2729 if (uvalue
< debug_info_p
->num_loc_offsets
)
2730 idx
= debug_info_p
->loc_offsets
[uvalue
];
2733 warn (_("loc_offset %" PRIu64
" too big\n"), uvalue
);
2738 else if (form
== DW_FORM_rnglistx
)
2742 idx
= fetch_indexed_offset (uvalue
, rnglists
,
2743 debug_info_p
->rnglists_base
,
2744 debug_info_p
->offset_size
);
2748 if (debug_info_p
== NULL
)
2751 base
= debug_info_p
->rnglists_base
;
2752 idx
= fetch_indexed_offset (uvalue
, rnglists
, base
,
2753 debug_info_p
->offset_size
);
2758 if (debug_info_p
== NULL
)
2760 else if (debug_info_p
->addr_base
== DEBUG_INFO_UNAVAILABLE
)
2763 base
= debug_info_p
->addr_base
;
2765 base
+= uvalue
* pointer_size
;
2766 idx
= fetch_indexed_addr (base
, pointer_size
);
2769 /* We have already displayed the form name. */
2770 if (idx
!= (uint64_t) -1)
2771 printf (_("%c(index: %#" PRIx64
"): %#" PRIx64
),
2772 delimiter
, uvalue
, idx
);
2776 case DW_FORM_strp_sup
:
2778 printf ("%c<%#" PRIx64
">", delimiter
, uvalue
+ cu_offset
);
2782 warn (_("Unrecognized form: %#lx"), form
);
2783 /* What to do? Consume a byte maybe? */
2788 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
|| do_debug_info
)
2789 && num_debug_info_entries
== 0
2790 && debug_info_p
!= NULL
)
2794 case DW_AT_loclists_base
:
2795 if (debug_info_p
->loclists_base
)
2796 warn (_("CU @ %#" PRIx64
" has multiple loclists_base values "
2797 "(%#" PRIx64
" and %#" PRIx64
")"),
2798 debug_info_p
->cu_offset
,
2799 debug_info_p
->loclists_base
, uvalue
);
2803 warn (_("CU @ %#" PRIx64
" has has a negative loclists_base "
2804 "value of %#" PRIx64
" - treating as zero"),
2805 debug_info_p
->cu_offset
, svalue
);
2808 debug_info_p
->loclists_base
= uvalue
;
2811 case DW_AT_rnglists_base
:
2812 /* Assignment to debug_info_p->rnglists_base is now elsewhere. */
2815 case DW_AT_str_offsets_base
:
2816 if (debug_info_p
->str_offsets_base
)
2817 warn (_("CU @ %#" PRIx64
" has multiple str_offsets_base values "
2818 "%#" PRIx64
" and %#" PRIx64
")"),
2819 debug_info_p
->cu_offset
,
2820 debug_info_p
->str_offsets_base
, uvalue
);
2824 warn (_("CU @ %#" PRIx64
" has has a negative stroffsets_base "
2825 "value of %#" PRIx64
" - treating as zero"),
2826 debug_info_p
->cu_offset
, svalue
);
2829 debug_info_p
->str_offsets_base
= uvalue
;
2832 case DW_AT_frame_base
:
2833 have_frame_base
= 1;
2835 case DW_AT_location
:
2836 case DW_AT_GNU_locviews
:
2837 case DW_AT_string_length
:
2838 case DW_AT_return_addr
:
2839 case DW_AT_data_member_location
:
2840 case DW_AT_vtable_elem_location
:
2842 case DW_AT_static_link
:
2843 case DW_AT_use_location
:
2844 case DW_AT_call_value
:
2845 case DW_AT_GNU_call_site_value
:
2846 case DW_AT_call_data_value
:
2847 case DW_AT_GNU_call_site_data_value
:
2848 case DW_AT_call_target
:
2849 case DW_AT_GNU_call_site_target
:
2850 case DW_AT_call_target_clobbered
:
2851 case DW_AT_GNU_call_site_target_clobbered
:
2852 if ((dwarf_version
< 4
2853 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
2854 || form
== DW_FORM_sec_offset
2855 || form
== DW_FORM_loclistx
)
2857 /* Process location list. */
2858 unsigned int lmax
= debug_info_p
->max_loc_offsets
;
2859 unsigned int num
= debug_info_p
->num_loc_offsets
;
2861 if (lmax
== 0 || num
>= lmax
)
2864 debug_info_p
->loc_offsets
= (uint64_t *)
2865 xcrealloc (debug_info_p
->loc_offsets
,
2866 lmax
, sizeof (*debug_info_p
->loc_offsets
));
2867 debug_info_p
->loc_views
= (uint64_t *)
2868 xcrealloc (debug_info_p
->loc_views
,
2869 lmax
, sizeof (*debug_info_p
->loc_views
));
2870 debug_info_p
->have_frame_base
= (int *)
2871 xcrealloc (debug_info_p
->have_frame_base
,
2872 lmax
, sizeof (*debug_info_p
->have_frame_base
));
2873 debug_info_p
->max_loc_offsets
= lmax
;
2875 if (form
== DW_FORM_loclistx
)
2876 uvalue
= fetch_indexed_offset (num
, loclists
,
2877 debug_info_p
->loclists_base
,
2878 debug_info_p
->offset_size
);
2879 else if (this_set
!= NULL
)
2880 uvalue
+= this_set
->section_offsets
[DW_SECT_LOC
];
2882 debug_info_p
->have_frame_base
[num
] = have_frame_base
;
2883 if (attribute
!= DW_AT_GNU_locviews
)
2885 uvalue
+= debug_info_p
->loclists_base
;
2887 /* Corrupt DWARF info can produce more offsets than views.
2888 See PR 23062 for an example. */
2889 if (debug_info_p
->num_loc_offsets
2890 > debug_info_p
->num_loc_views
)
2891 warn (_("More location offset attributes than DW_AT_GNU_locview attributes\n"));
2894 debug_info_p
->loc_offsets
[num
] = uvalue
;
2895 debug_info_p
->num_loc_offsets
++;
2900 if (debug_info_p
->num_loc_views
> num
)
2902 warn (_("The number of views (%u) is greater than the number of locations (%u)\n"),
2903 debug_info_p
->num_loc_views
, num
);
2904 debug_info_p
->num_loc_views
= num
;
2907 num
= debug_info_p
->num_loc_views
;
2908 if (num
> debug_info_p
->num_loc_offsets
)
2909 warn (_("More DW_AT_GNU_locview attributes than location offset attributes\n"));
2912 debug_info_p
->loc_views
[num
] = uvalue
;
2913 debug_info_p
->num_loc_views
++;
2920 if (need_base_address
)
2922 if (form
== DW_FORM_addrx
)
2923 uvalue
= fetch_indexed_addr (debug_info_p
->addr_base
2924 + uvalue
* pointer_size
,
2927 debug_info_p
->base_address
= uvalue
;
2931 case DW_AT_GNU_addr_base
:
2932 case DW_AT_addr_base
:
2933 debug_info_p
->addr_base
= uvalue
;
2934 /* Retrieved elsewhere so that it is in
2935 place by the time we read low_pc. */
2938 case DW_AT_GNU_ranges_base
:
2939 debug_info_p
->ranges_base
= uvalue
;
2943 if ((dwarf_version
< 4
2944 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
2945 || form
== DW_FORM_sec_offset
2946 || form
== DW_FORM_rnglistx
)
2948 /* Process range list. */
2949 unsigned int lmax
= debug_info_p
->max_range_lists
;
2950 unsigned int num
= debug_info_p
->num_range_lists
;
2952 if (lmax
== 0 || num
>= lmax
)
2955 debug_info_p
->range_lists
= (uint64_t *)
2956 xcrealloc (debug_info_p
->range_lists
,
2957 lmax
, sizeof (*debug_info_p
->range_lists
));
2958 debug_info_p
->max_range_lists
= lmax
;
2961 if (form
== DW_FORM_rnglistx
)
2962 uvalue
= fetch_indexed_offset (uvalue
, rnglists
,
2963 debug_info_p
->rnglists_base
,
2964 debug_info_p
->offset_size
);
2966 debug_info_p
->range_lists
[num
] = uvalue
;
2967 debug_info_p
->num_range_lists
++;
2971 case DW_AT_GNU_dwo_name
:
2972 case DW_AT_dwo_name
:
2977 add_dwo_name ((const char *) fetch_indirect_string (uvalue
),
2980 case DW_FORM_GNU_strp_alt
:
2981 add_dwo_name ((const char *) fetch_alt_indirect_string (uvalue
), cu_offset
);
2983 case DW_FORM_GNU_str_index
:
2989 add_dwo_name (fetch_indexed_string (uvalue
, this_set
,
2991 debug_info_p
->str_offsets_base
),
2994 case DW_FORM_string
:
2995 add_dwo_name ((const char *) orig_data
, cu_offset
);
2998 warn (_("Unsupported form (%s) for attribute %s\n"),
2999 get_FORM_name (form
), get_AT_name (attribute
));
3004 case DW_AT_comp_dir
:
3005 /* FIXME: Also extract a build-id in a CU/TU. */
3010 add_dwo_dir ((const char *) fetch_indirect_string (uvalue
), cu_offset
);
3012 case DW_FORM_GNU_strp_alt
:
3013 add_dwo_dir (fetch_alt_indirect_string (uvalue
), cu_offset
);
3015 case DW_FORM_line_strp
:
3016 add_dwo_dir ((const char *) fetch_indirect_line_string (uvalue
), cu_offset
);
3018 case DW_FORM_GNU_str_index
:
3024 add_dwo_dir (fetch_indexed_string (uvalue
, this_set
, offset_size
, false,
3025 debug_info_p
->str_offsets_base
),
3028 case DW_FORM_string
:
3029 add_dwo_dir ((const char *) orig_data
, cu_offset
);
3032 warn (_("Unsupported form (%s) for attribute %s\n"),
3033 get_FORM_name (form
), get_AT_name (attribute
));
3038 case DW_AT_GNU_dwo_id
:
3043 /* FIXME: Record the length of the ID as well ? */
3044 add_dwo_id ((const char *) (data
- 8), cu_offset
);
3047 warn (_("Unsupported form (%s) for attribute %s\n"),
3048 get_FORM_name (form
), get_AT_name (attribute
));
3058 if (do_loc
|| attribute
== 0)
3061 /* For some attributes we can display further information. */
3065 if (level
>= 0 && level
< MAX_CU_NESTING
3066 && uvalue
< (size_t) (end
- start
))
3068 bool is_signed
= false;
3069 abbrev_entry
*type_abbrev
;
3070 unsigned char *type_data
;
3073 type_abbrev
= get_type_abbrev_from_form (form
, uvalue
,
3077 if (type_abbrev
!= NULL
)
3079 get_type_signedness (type_abbrev
, section
, type_data
,
3080 map
? section
->start
+ map
->end
: end
,
3081 map
? map
->start
: cu_offset
,
3082 pointer_size
, offset_size
, dwarf_version
,
3085 level_type_signed
[level
] = is_signed
;
3093 case DW_INL_not_inlined
:
3094 printf (_("(not inlined)"));
3096 case DW_INL_inlined
:
3097 printf (_("(inlined)"));
3099 case DW_INL_declared_not_inlined
:
3100 printf (_("(declared as inline but ignored)"));
3102 case DW_INL_declared_inlined
:
3103 printf (_("(declared as inline and inlined)"));
3106 printf (_(" (Unknown inline attribute value: %#" PRIx64
")"),
3112 case DW_AT_language
:
3116 /* Ordered by the numeric value of these constants. */
3117 case DW_LANG_C89
: printf ("(ANSI C)"); break;
3118 case DW_LANG_C
: printf ("(non-ANSI C)"); break;
3119 case DW_LANG_Ada83
: printf ("(Ada)"); break;
3120 case DW_LANG_C_plus_plus
: printf ("(C++)"); break;
3121 case DW_LANG_Cobol74
: printf ("(Cobol 74)"); break;
3122 case DW_LANG_Cobol85
: printf ("(Cobol 85)"); break;
3123 case DW_LANG_Fortran77
: printf ("(FORTRAN 77)"); break;
3124 case DW_LANG_Fortran90
: printf ("(Fortran 90)"); break;
3125 case DW_LANG_Pascal83
: printf ("(ANSI Pascal)"); break;
3126 case DW_LANG_Modula2
: printf ("(Modula 2)"); break;
3127 /* DWARF 2.1 values. */
3128 case DW_LANG_Java
: printf ("(Java)"); break;
3129 case DW_LANG_C99
: printf ("(ANSI C99)"); break;
3130 case DW_LANG_Ada95
: printf ("(ADA 95)"); break;
3131 case DW_LANG_Fortran95
: printf ("(Fortran 95)"); break;
3132 /* DWARF 3 values. */
3133 case DW_LANG_PLI
: printf ("(PLI)"); break;
3134 case DW_LANG_ObjC
: printf ("(Objective C)"); break;
3135 case DW_LANG_ObjC_plus_plus
: printf ("(Objective C++)"); break;
3136 case DW_LANG_UPC
: printf ("(Unified Parallel C)"); break;
3137 case DW_LANG_D
: printf ("(D)"); break;
3138 /* DWARF 4 values. */
3139 case DW_LANG_Python
: printf ("(Python)"); break;
3140 /* DWARF 5 values. */
3141 case DW_LANG_OpenCL
: printf ("(OpenCL)"); break;
3142 case DW_LANG_Go
: printf ("(Go)"); break;
3143 case DW_LANG_Modula3
: printf ("(Modula 3)"); break;
3144 case DW_LANG_Haskell
: printf ("(Haskell)"); break;
3145 case DW_LANG_C_plus_plus_03
: printf ("(C++03)"); break;
3146 case DW_LANG_C_plus_plus_11
: printf ("(C++11)"); break;
3147 case DW_LANG_OCaml
: printf ("(OCaml)"); break;
3148 case DW_LANG_Rust
: printf ("(Rust)"); break;
3149 case DW_LANG_C11
: printf ("(C11)"); break;
3150 case DW_LANG_Swift
: printf ("(Swift)"); break;
3151 case DW_LANG_Julia
: printf ("(Julia)"); break;
3152 case DW_LANG_Dylan
: printf ("(Dylan)"); break;
3153 case DW_LANG_C_plus_plus_14
: printf ("(C++14)"); break;
3154 case DW_LANG_Fortran03
: printf ("(Fortran 03)"); break;
3155 case DW_LANG_Fortran08
: printf ("(Fortran 08)"); break;
3156 case DW_LANG_RenderScript
: printf ("(RenderScript)"); break;
3157 /* MIPS extension. */
3158 case DW_LANG_Mips_Assembler
: printf ("(MIPS assembler)"); break;
3159 /* UPC extension. */
3160 case DW_LANG_Upc
: printf ("(Unified Parallel C)"); break;
3162 if (uvalue
>= DW_LANG_lo_user
&& uvalue
<= DW_LANG_hi_user
)
3163 printf (_("(implementation defined: %#" PRIx64
")"), uvalue
);
3165 printf (_("(unknown: %#" PRIx64
")"), uvalue
);
3170 case DW_AT_encoding
:
3174 case DW_ATE_void
: printf ("(void)"); break;
3175 case DW_ATE_address
: printf ("(machine address)"); break;
3176 case DW_ATE_boolean
: printf ("(boolean)"); break;
3177 case DW_ATE_complex_float
: printf ("(complex float)"); break;
3178 case DW_ATE_float
: printf ("(float)"); break;
3179 case DW_ATE_signed
: printf ("(signed)"); break;
3180 case DW_ATE_signed_char
: printf ("(signed char)"); break;
3181 case DW_ATE_unsigned
: printf ("(unsigned)"); break;
3182 case DW_ATE_unsigned_char
: printf ("(unsigned char)"); break;
3183 /* DWARF 2.1 values: */
3184 case DW_ATE_imaginary_float
: printf ("(imaginary float)"); break;
3185 case DW_ATE_decimal_float
: printf ("(decimal float)"); break;
3186 /* DWARF 3 values: */
3187 case DW_ATE_packed_decimal
: printf ("(packed_decimal)"); break;
3188 case DW_ATE_numeric_string
: printf ("(numeric_string)"); break;
3189 case DW_ATE_edited
: printf ("(edited)"); break;
3190 case DW_ATE_signed_fixed
: printf ("(signed_fixed)"); break;
3191 case DW_ATE_unsigned_fixed
: printf ("(unsigned_fixed)"); break;
3192 /* DWARF 4 values: */
3193 case DW_ATE_UTF
: printf ("(unicode string)"); break;
3194 /* DWARF 5 values: */
3195 case DW_ATE_UCS
: printf ("(UCS)"); break;
3196 case DW_ATE_ASCII
: printf ("(ASCII)"); break;
3198 /* HP extensions: */
3199 case DW_ATE_HP_float80
: printf ("(HP_float80)"); break;
3200 case DW_ATE_HP_complex_float80
: printf ("(HP_complex_float80)"); break;
3201 case DW_ATE_HP_float128
: printf ("(HP_float128)"); break;
3202 case DW_ATE_HP_complex_float128
:printf ("(HP_complex_float128)"); break;
3203 case DW_ATE_HP_floathpintel
: printf ("(HP_floathpintel)"); break;
3204 case DW_ATE_HP_imaginary_float80
: printf ("(HP_imaginary_float80)"); break;
3205 case DW_ATE_HP_imaginary_float128
: printf ("(HP_imaginary_float128)"); break;
3208 if (uvalue
>= DW_ATE_lo_user
3209 && uvalue
<= DW_ATE_hi_user
)
3210 printf (_("(user defined type)"));
3212 printf (_("(unknown type)"));
3217 case DW_AT_accessibility
:
3221 case DW_ACCESS_public
: printf ("(public)"); break;
3222 case DW_ACCESS_protected
: printf ("(protected)"); break;
3223 case DW_ACCESS_private
: printf ("(private)"); break;
3225 printf (_("(unknown accessibility)"));
3230 case DW_AT_visibility
:
3234 case DW_VIS_local
: printf ("(local)"); break;
3235 case DW_VIS_exported
: printf ("(exported)"); break;
3236 case DW_VIS_qualified
: printf ("(qualified)"); break;
3237 default: printf (_("(unknown visibility)")); break;
3241 case DW_AT_endianity
:
3245 case DW_END_default
: printf ("(default)"); break;
3246 case DW_END_big
: printf ("(big)"); break;
3247 case DW_END_little
: printf ("(little)"); break;
3249 if (uvalue
>= DW_END_lo_user
&& uvalue
<= DW_END_hi_user
)
3250 printf (_("(user specified)"));
3252 printf (_("(unknown endianity)"));
3257 case DW_AT_virtuality
:
3261 case DW_VIRTUALITY_none
: printf ("(none)"); break;
3262 case DW_VIRTUALITY_virtual
: printf ("(virtual)"); break;
3263 case DW_VIRTUALITY_pure_virtual
:printf ("(pure_virtual)"); break;
3264 default: printf (_("(unknown virtuality)")); break;
3268 case DW_AT_identifier_case
:
3272 case DW_ID_case_sensitive
: printf ("(case_sensitive)"); break;
3273 case DW_ID_up_case
: printf ("(up_case)"); break;
3274 case DW_ID_down_case
: printf ("(down_case)"); break;
3275 case DW_ID_case_insensitive
: printf ("(case_insensitive)"); break;
3276 default: printf (_("(unknown case)")); break;
3280 case DW_AT_calling_convention
:
3284 case DW_CC_normal
: printf ("(normal)"); break;
3285 case DW_CC_program
: printf ("(program)"); break;
3286 case DW_CC_nocall
: printf ("(nocall)"); break;
3287 case DW_CC_pass_by_reference
: printf ("(pass by ref)"); break;
3288 case DW_CC_pass_by_value
: printf ("(pass by value)"); break;
3289 case DW_CC_GNU_renesas_sh
: printf ("(Rensas SH)"); break;
3290 case DW_CC_GNU_borland_fastcall_i386
: printf ("(Borland fastcall i386)"); break;
3292 if (uvalue
>= DW_CC_lo_user
3293 && uvalue
<= DW_CC_hi_user
)
3294 printf (_("(user defined)"));
3296 printf (_("(unknown convention)"));
3300 case DW_AT_ordering
:
3305 case -1: printf (_("(undefined)")); break;
3306 case 0: printf ("(row major)"); break;
3307 case 1: printf ("(column major)"); break;
3311 case DW_AT_decimal_sign
:
3315 case DW_DS_unsigned
: printf (_("(unsigned)")); break;
3316 case DW_DS_leading_overpunch
: printf (_("(leading overpunch)")); break;
3317 case DW_DS_trailing_overpunch
: printf (_("(trailing overpunch)")); break;
3318 case DW_DS_leading_separate
: printf (_("(leading separate)")); break;
3319 case DW_DS_trailing_separate
: printf (_("(trailing separate)")); break;
3320 default: printf (_("(unrecognised)")); break;
3324 case DW_AT_defaulted
:
3328 case DW_DEFAULTED_no
: printf (_("(no)")); break;
3329 case DW_DEFAULTED_in_class
: printf (_("(in class)")); break;
3330 case DW_DEFAULTED_out_of_class
: printf (_("(out of class)")); break;
3331 default: printf (_("(unrecognised)")); break;
3335 case DW_AT_discr_list
:
3337 display_discr_list (form
, uvalue
, data
, level
);
3340 case DW_AT_frame_base
:
3341 have_frame_base
= 1;
3343 case DW_AT_location
:
3344 case DW_AT_loclists_base
:
3345 case DW_AT_rnglists_base
:
3346 case DW_AT_str_offsets_base
:
3347 case DW_AT_string_length
:
3348 case DW_AT_return_addr
:
3349 case DW_AT_data_member_location
:
3350 case DW_AT_vtable_elem_location
:
3352 case DW_AT_static_link
:
3353 case DW_AT_use_location
:
3354 case DW_AT_call_value
:
3355 case DW_AT_GNU_call_site_value
:
3356 case DW_AT_call_data_value
:
3357 case DW_AT_GNU_call_site_data_value
:
3358 case DW_AT_call_target
:
3359 case DW_AT_GNU_call_site_target
:
3360 case DW_AT_call_target_clobbered
:
3361 case DW_AT_GNU_call_site_target_clobbered
:
3362 if ((dwarf_version
< 4
3363 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
3364 || form
== DW_FORM_sec_offset
3365 || form
== DW_FORM_loclistx
)
3367 if (attribute
!= DW_AT_rnglists_base
3368 && attribute
!= DW_AT_str_offsets_base
)
3369 printf (_(" (location list)"));
3372 case DW_AT_allocated
:
3373 case DW_AT_associated
:
3374 case DW_AT_data_location
:
3376 case DW_AT_upper_bound
:
3377 case DW_AT_lower_bound
:
3381 int need_frame_base
;
3384 need_frame_base
= decode_location_expression (block_start
,
3389 cu_offset
, section
);
3391 if (need_frame_base
&& !have_frame_base
)
3392 printf (_(" [without DW_AT_frame_base]"));
3396 case DW_AT_data_bit_offset
:
3397 case DW_AT_byte_size
:
3398 case DW_AT_bit_size
:
3399 case DW_AT_string_length_byte_size
:
3400 case DW_AT_string_length_bit_size
:
3401 case DW_AT_bit_stride
:
3402 if (form
== DW_FORM_exprloc
)
3405 (void) decode_location_expression (block_start
, pointer_size
,
3406 offset_size
, dwarf_version
,
3407 uvalue
, cu_offset
, section
);
3414 unsigned long abbrev_number
;
3415 abbrev_entry
*entry
;
3417 entry
= get_type_abbrev_from_form (form
, uvalue
, cu_offset
, end
,
3418 section
, & abbrev_number
, NULL
, NULL
);
3421 if (form
!= DW_FORM_GNU_ref_alt
)
3422 warn (_("Offset %#" PRIx64
" used as value for DW_AT_import attribute of DIE at offset %#tx is too big.\n"),
3424 orig_data
- section
->start
);
3428 printf (_("\t[Abbrev Number: %ld"), abbrev_number
);
3429 printf (" (%s)", get_TAG_name (entry
->tag
));
3442 static unsigned char *
3443 read_and_display_attr (unsigned long attribute
,
3445 int64_t implicit_const
,
3446 unsigned char *start
,
3447 unsigned char *data
,
3450 uint64_t pointer_size
,
3451 uint64_t offset_size
,
3453 debug_info
*debug_info_p
,
3455 struct dwarf_section
*section
,
3456 struct cu_tu_set
*this_set
,
3460 printf (" %-18s:", get_AT_name (attribute
));
3461 data
= read_and_display_attr_value (attribute
, form
, implicit_const
,
3463 cu_offset
, pointer_size
, offset_size
,
3464 dwarf_version
, debug_info_p
,
3465 do_loc
, section
, this_set
, ' ', level
);
3471 /* Like load_debug_section, but if the ordinary call fails, and we are
3472 following debug links, then attempt to load the requested section
3473 from one of the separate debug info files. */
3476 load_debug_section_with_follow (enum dwarf_section_display_enum sec_enum
,
3479 if (load_debug_section (sec_enum
, handle
))
3481 if (debug_displays
[sec_enum
].section
.filename
== NULL
)
3483 /* See if we can associate a filename with this section. */
3486 for (i
= first_separate_info
; i
!= NULL
; i
= i
->next
)
3487 if (i
->handle
== handle
)
3489 debug_displays
[sec_enum
].section
.filename
= i
->filename
;
3497 if (do_follow_links
)
3501 for (i
= first_separate_info
; i
!= NULL
; i
= i
->next
)
3503 if (load_debug_section (sec_enum
, i
->handle
))
3505 debug_displays
[sec_enum
].section
.filename
= i
->filename
;
3507 /* FIXME: We should check to see if any of the remaining debug info
3508 files also contain this section, and, umm, do something about it. */
3518 introduce (struct dwarf_section
* section
, bool raw
)
3522 if (do_follow_links
&& section
->filename
)
3523 printf (_("Raw dump of debug contents of section %s (loaded from %s):\n\n"),
3524 section
->name
, section
->filename
);
3526 printf (_("Raw dump of debug contents of section %s:\n\n"), section
->name
);
3530 if (do_follow_links
&& section
->filename
)
3531 printf (_("Contents of the %s section (loaded from %s):\n\n"),
3532 section
->name
, section
->filename
);
3534 printf (_("Contents of the %s section:\n\n"), section
->name
);
3538 /* Free memory allocated for one unit in debug_information. */
3541 free_debug_information (debug_info
*ent
)
3543 if (ent
->max_loc_offsets
)
3545 free (ent
->loc_offsets
);
3546 free (ent
->loc_views
);
3547 free (ent
->have_frame_base
);
3549 if (ent
->max_range_lists
)
3551 free (ent
->range_lists
);
3555 /* For look-ahead in attributes. When you want to scan a DIE for one specific
3556 attribute and ignore the rest. */
3558 static unsigned char *
3559 skip_attribute (unsigned long form
,
3560 unsigned char * data
,
3561 unsigned char * end
,
3562 uint64_t pointer_size
,
3563 uint64_t offset_size
,
3571 case DW_FORM_ref_addr
:
3572 data
+= dwarf_version
== 2 ? pointer_size
: offset_size
;
3575 data
+= pointer_size
;
3577 case DW_FORM_strp_sup
:
3579 case DW_FORM_line_strp
:
3580 case DW_FORM_sec_offset
:
3581 case DW_FORM_GNU_ref_alt
:
3582 case DW_FORM_GNU_strp_alt
:
3583 data
+= offset_size
;
3589 case DW_FORM_addrx1
:
3595 case DW_FORM_addrx2
:
3599 case DW_FORM_addrx3
:
3602 case DW_FORM_ref_sup4
:
3606 case DW_FORM_addrx4
:
3609 case DW_FORM_ref_sup8
:
3612 case DW_FORM_ref_sig8
:
3615 case DW_FORM_data16
:
3619 READ_SLEB (stemp
, data
, end
);
3621 case DW_FORM_GNU_str_index
:
3623 case DW_FORM_ref_udata
:
3625 case DW_FORM_GNU_addr_index
:
3627 case DW_FORM_loclistx
:
3628 case DW_FORM_rnglistx
:
3629 READ_ULEB (temp
, data
, end
);
3632 case DW_FORM_indirect
:
3633 while (form
== DW_FORM_indirect
)
3634 READ_ULEB (form
, data
, end
);
3635 return skip_attribute (form
, data
, end
, pointer_size
, offset_size
, dwarf_version
);
3637 case DW_FORM_string
:
3638 data
+= strnlen ((char *) data
, end
- data
);
3641 case DW_FORM_exprloc
:
3642 READ_ULEB (temp
, data
, end
);
3645 case DW_FORM_block1
:
3646 SAFE_BYTE_GET_AND_INC (temp
, data
, 1, end
);
3649 case DW_FORM_block2
:
3650 SAFE_BYTE_GET_AND_INC (temp
, data
, 2, end
);
3653 case DW_FORM_block4
:
3654 SAFE_BYTE_GET_AND_INC (temp
, data
, 4, end
);
3657 case DW_FORM_implicit_const
:
3658 case DW_FORM_flag_present
:
3661 warn (_("Unexpected form in top DIE\n"));
3668 read_bases (abbrev_entry
* entry
,
3669 unsigned char * data
,
3670 unsigned char * end
,
3671 int64_t pointer_size
,
3672 uint64_t offset_size
,
3674 debug_info
* debug_info_p
)
3678 for (attr
= entry
->first_attr
;
3679 attr
&& attr
->attribute
;
3684 if (attr
->attribute
== DW_AT_rnglists_base
)
3686 if (attr
->form
== DW_FORM_sec_offset
)
3688 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
3689 debug_info_p
->rnglists_base
= uvalue
;
3692 warn (_("Unexpected form of DW_AT_rnglists_base in the top DIE\n"));
3694 else if(attr
->attribute
== DW_AT_addr_base
|| attr
->attribute
== DW_AT_GNU_addr_base
)
3696 if (attr
->form
== DW_FORM_sec_offset
)
3698 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
3699 debug_info_p
->addr_base
= uvalue
;
3702 warn (_("Unexpected form of DW_AT_addr_base in the top DIE\n"));
3705 data
= skip_attribute(attr
->form
, data
, end
, pointer_size
, offset_size
, dwarf_version
);
3709 /* Process the contents of a .debug_info section.
3710 If do_loc is TRUE then we are scanning for location lists and dwo tags
3711 and we do not want to display anything to the user.
3712 If do_types is TRUE, we are processing a .debug_types section instead of
3713 a .debug_info section.
3714 The information displayed is restricted by the values in DWARF_START_DIE
3715 and DWARF_CUTOFF_LEVEL.
3716 Returns TRUE upon success. Otherwise an error or warning message is
3717 printed and FALSE is returned. */
3720 process_debug_info (struct dwarf_section
* section
,
3722 enum dwarf_section_display_enum abbrev_sec
,
3726 unsigned char *start
= section
->start
;
3727 unsigned char *end
= start
+ section
->size
;
3728 unsigned char *section_begin
;
3730 unsigned int num_units
= 0;
3732 /* First scan the section to get the number of comp units.
3733 Length sanity checks are done here. */
3734 for (section_begin
= start
, num_units
= 0; section_begin
< end
;
3739 /* Read the first 4 bytes. For a 32-bit DWARF section, this
3740 will be the length. For a 64-bit DWARF section, it'll be
3741 the escape code 0xffffffff followed by an 8 byte length. */
3742 SAFE_BYTE_GET_AND_INC (length
, section_begin
, 4, end
);
3744 if (length
== 0xffffffff)
3745 SAFE_BYTE_GET_AND_INC (length
, section_begin
, 8, end
);
3746 else if (length
>= 0xfffffff0 && length
< 0xffffffff)
3748 warn (_("Reserved length value (%#" PRIx64
") found in section %s\n"),
3749 length
, section
->name
);
3753 /* Negative values are illegal, they may even cause infinite
3754 looping. This can happen if we can't accurately apply
3755 relocations to an object file, or if the file is corrupt. */
3756 if (length
> (size_t) (end
- section_begin
))
3758 warn (_("Corrupt unit length (got %#" PRIx64
3759 " expected at most %#tx) in section %s\n"),
3760 length
, end
- section_begin
, section
->name
);
3763 section_begin
+= length
;
3768 error (_("No comp units in %s section ?\n"), section
->name
);
3772 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
|| do_debug_info
)
3773 && num_debug_info_entries
== 0
3777 /* Then allocate an array to hold the information. */
3778 debug_information
= (debug_info
*) cmalloc (num_units
,
3779 sizeof (* debug_information
));
3780 if (debug_information
== NULL
)
3782 error (_("Not enough memory for a debug info array of %u entries\n"),
3784 alloc_num_debug_info_entries
= num_debug_info_entries
= 0;
3788 /* PR 17531: file: 92ca3797.
3789 We cannot rely upon the debug_information array being initialised
3790 before it is used. A corrupt file could easily contain references
3791 to a unit for which information has not been made available. So
3792 we ensure that the array is zeroed here. */
3793 memset (debug_information
, 0, num_units
* sizeof (*debug_information
));
3795 alloc_num_debug_info_entries
= num_units
;
3800 load_debug_section_with_follow (str
, file
);
3801 load_debug_section_with_follow (line_str
, file
);
3802 load_debug_section_with_follow (str_dwo
, file
);
3803 load_debug_section_with_follow (str_index
, file
);
3804 load_debug_section_with_follow (str_index_dwo
, file
);
3805 load_debug_section_with_follow (debug_addr
, file
);
3808 load_debug_section_with_follow (abbrev_sec
, file
);
3809 load_debug_section_with_follow (loclists
, file
);
3810 load_debug_section_with_follow (rnglists
, file
);
3811 load_debug_section_with_follow (loclists_dwo
, file
);
3812 load_debug_section_with_follow (rnglists_dwo
, file
);
3814 if (debug_displays
[abbrev_sec
].section
.start
== NULL
)
3816 warn (_("Unable to locate %s section!\n"),
3817 debug_displays
[abbrev_sec
].section
.uncompressed_name
);
3821 if (!do_loc
&& dwarf_start_die
== 0)
3822 introduce (section
, false);
3824 free_all_abbrevs ();
3826 /* In order to be able to resolve DW_FORM_ref_addr forms we need
3827 to load *all* of the abbrevs for all CUs in this .debug_info
3828 section. This does effectively mean that we (partially) read
3829 every CU header twice. */
3830 for (section_begin
= start
; start
< end
;)
3832 DWARF2_Internal_CompUnit compunit
;
3833 unsigned char *hdrptr
;
3834 uint64_t abbrev_base
;
3837 unsigned int offset_size
;
3838 struct cu_tu_set
*this_set
;
3839 unsigned char *end_cu
;
3842 cu_offset
= start
- section_begin
;
3844 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 4, end
);
3846 if (compunit
.cu_length
== 0xffffffff)
3848 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 8, end
);
3853 end_cu
= hdrptr
+ compunit
.cu_length
;
3855 SAFE_BYTE_GET_AND_INC (compunit
.cu_version
, hdrptr
, 2, end_cu
);
3857 this_set
= find_cu_tu_set_v2 (cu_offset
, do_types
);
3859 if (compunit
.cu_version
< 5)
3861 compunit
.cu_unit_type
= DW_UT_compile
;
3862 /* Initialize it due to a false compiler warning. */
3863 compunit
.cu_pointer_size
= -1;
3867 SAFE_BYTE_GET_AND_INC (compunit
.cu_unit_type
, hdrptr
, 1, end_cu
);
3868 do_types
= (compunit
.cu_unit_type
== DW_UT_type
);
3870 SAFE_BYTE_GET_AND_INC (compunit
.cu_pointer_size
, hdrptr
, 1, end_cu
);
3873 SAFE_BYTE_GET_AND_INC (compunit
.cu_abbrev_offset
, hdrptr
, offset_size
,
3876 if (compunit
.cu_unit_type
== DW_UT_split_compile
3877 || compunit
.cu_unit_type
== DW_UT_skeleton
)
3880 SAFE_BYTE_GET_AND_INC (dwo_id
, hdrptr
, 8, end_cu
);
3883 if (this_set
== NULL
)
3886 abbrev_size
= debug_displays
[abbrev_sec
].section
.size
;
3890 abbrev_base
= this_set
->section_offsets
[DW_SECT_ABBREV
];
3891 abbrev_size
= this_set
->section_sizes
[DW_SECT_ABBREV
];
3895 abbrev_list
*free_list
;
3896 list
= find_and_process_abbrev_set (&debug_displays
[abbrev_sec
].section
,
3897 abbrev_base
, abbrev_size
,
3898 compunit
.cu_abbrev_offset
,
3901 if (list
!= NULL
&& list
->first_abbrev
!= NULL
)
3902 record_abbrev_list_for_cu (cu_offset
, start
- section_begin
,
3904 else if (free_list
!= NULL
)
3905 free_abbrev_list (free_list
);
3908 for (start
= section_begin
, unit
= 0; start
< end
; unit
++)
3910 DWARF2_Internal_CompUnit compunit
;
3911 unsigned char *hdrptr
;
3912 unsigned char *tags
;
3913 int level
, last_level
, saved_level
;
3915 unsigned int offset_size
;
3916 uint64_t signature
= 0;
3917 uint64_t type_offset
= 0;
3918 struct cu_tu_set
*this_set
;
3919 uint64_t abbrev_base
;
3921 unsigned char *end_cu
;
3924 cu_offset
= start
- section_begin
;
3926 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 4, end
);
3928 if (compunit
.cu_length
== 0xffffffff)
3930 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 8, end
);
3935 end_cu
= hdrptr
+ compunit
.cu_length
;
3937 SAFE_BYTE_GET_AND_INC (compunit
.cu_version
, hdrptr
, 2, end_cu
);
3939 this_set
= find_cu_tu_set_v2 (cu_offset
, do_types
);
3941 if (compunit
.cu_version
< 5)
3943 compunit
.cu_unit_type
= DW_UT_compile
;
3944 /* Initialize it due to a false compiler warning. */
3945 compunit
.cu_pointer_size
= -1;
3949 SAFE_BYTE_GET_AND_INC (compunit
.cu_unit_type
, hdrptr
, 1, end_cu
);
3950 do_types
= (compunit
.cu_unit_type
== DW_UT_type
);
3952 SAFE_BYTE_GET_AND_INC (compunit
.cu_pointer_size
, hdrptr
, 1, end_cu
);
3955 SAFE_BYTE_GET_AND_INC (compunit
.cu_abbrev_offset
, hdrptr
, offset_size
, end_cu
);
3957 if (this_set
== NULL
)
3960 abbrev_size
= debug_displays
[abbrev_sec
].section
.size
;
3964 abbrev_base
= this_set
->section_offsets
[DW_SECT_ABBREV
];
3965 abbrev_size
= this_set
->section_sizes
[DW_SECT_ABBREV
];
3968 if (compunit
.cu_version
< 5)
3969 SAFE_BYTE_GET_AND_INC (compunit
.cu_pointer_size
, hdrptr
, 1, end_cu
);
3971 bool do_dwo_id
= false;
3972 uint64_t dwo_id
= 0;
3973 if (compunit
.cu_unit_type
== DW_UT_split_compile
3974 || compunit
.cu_unit_type
== DW_UT_skeleton
)
3976 SAFE_BYTE_GET_AND_INC (dwo_id
, hdrptr
, 8, end_cu
);
3980 /* PR 17512: file: 001-108546-0.001:0.1. */
3981 if (compunit
.cu_pointer_size
< 2 || compunit
.cu_pointer_size
> 8)
3983 warn (_("Invalid pointer size (%d) in compunit header, using %d instead\n"),
3984 compunit
.cu_pointer_size
, offset_size
);
3985 compunit
.cu_pointer_size
= offset_size
;
3990 SAFE_BYTE_GET_AND_INC (signature
, hdrptr
, 8, end_cu
);
3991 SAFE_BYTE_GET_AND_INC (type_offset
, hdrptr
, offset_size
, end_cu
);
3994 if (dwarf_start_die
>= (size_t) (end_cu
- section_begin
))
4000 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
|| do_debug_info
)
4001 && num_debug_info_entries
== 0
4002 && alloc_num_debug_info_entries
> unit
4005 free_debug_information (&debug_information
[unit
]);
4006 memset (&debug_information
[unit
], 0, sizeof (*debug_information
));
4007 debug_information
[unit
].pointer_size
= compunit
.cu_pointer_size
;
4008 debug_information
[unit
].offset_size
= offset_size
;
4009 debug_information
[unit
].dwarf_version
= compunit
.cu_version
;
4010 debug_information
[unit
].cu_offset
= cu_offset
;
4011 debug_information
[unit
].addr_base
= DEBUG_INFO_UNAVAILABLE
;
4012 debug_information
[unit
].ranges_base
= DEBUG_INFO_UNAVAILABLE
;
4015 if (!do_loc
&& dwarf_start_die
== 0)
4017 printf (_(" Compilation Unit @ offset %#" PRIx64
":\n"),
4019 printf (_(" Length: %#" PRIx64
" (%s)\n"),
4021 offset_size
== 8 ? "64-bit" : "32-bit");
4022 printf (_(" Version: %d\n"), compunit
.cu_version
);
4023 if (compunit
.cu_version
>= 5)
4025 const char *name
= get_DW_UT_name (compunit
.cu_unit_type
);
4027 printf (_(" Unit Type: %s (%x)\n"),
4029 compunit
.cu_unit_type
);
4031 printf (_(" Abbrev Offset: %#" PRIx64
"\n"),
4032 compunit
.cu_abbrev_offset
);
4033 printf (_(" Pointer Size: %d\n"), compunit
.cu_pointer_size
);
4036 printf (_(" Signature: %#" PRIx64
"\n"), signature
);
4037 printf (_(" Type Offset: %#" PRIx64
"\n"), type_offset
);
4040 printf (_(" DWO ID: %#" PRIx64
"\n"), dwo_id
);
4041 if (this_set
!= NULL
)
4043 uint64_t *offsets
= this_set
->section_offsets
;
4044 size_t *sizes
= this_set
->section_sizes
;
4046 printf (_(" Section contributions:\n"));
4047 printf (_(" .debug_abbrev.dwo: %#" PRIx64
" %#zx\n"),
4048 offsets
[DW_SECT_ABBREV
], sizes
[DW_SECT_ABBREV
]);
4049 printf (_(" .debug_line.dwo: %#" PRIx64
" %#zx\n"),
4050 offsets
[DW_SECT_LINE
], sizes
[DW_SECT_LINE
]);
4051 printf (_(" .debug_loc.dwo: %#" PRIx64
" %#zx\n"),
4052 offsets
[DW_SECT_LOC
], sizes
[DW_SECT_LOC
]);
4053 printf (_(" .debug_str_offsets.dwo: %#" PRIx64
" %#zx\n"),
4054 offsets
[DW_SECT_STR_OFFSETS
], sizes
[DW_SECT_STR_OFFSETS
]);
4061 if (compunit
.cu_version
< 2 || compunit
.cu_version
> 5)
4063 warn (_("CU at offset %#" PRIx64
" contains corrupt or "
4064 "unsupported version number: %d.\n"),
4065 cu_offset
, compunit
.cu_version
);
4069 if (compunit
.cu_unit_type
!= DW_UT_compile
4070 && compunit
.cu_unit_type
!= DW_UT_partial
4071 && compunit
.cu_unit_type
!= DW_UT_type
4072 && compunit
.cu_unit_type
!= DW_UT_split_compile
4073 && compunit
.cu_unit_type
!= DW_UT_skeleton
)
4075 warn (_("CU at offset %#" PRIx64
" contains corrupt or "
4076 "unsupported unit type: %d.\n"),
4077 cu_offset
, compunit
.cu_unit_type
);
4081 /* Process the abbrevs used by this compilation unit. */
4083 list
= find_and_process_abbrev_set (&debug_displays
[abbrev_sec
].section
,
4084 abbrev_base
, abbrev_size
,
4085 compunit
.cu_abbrev_offset
, NULL
);
4089 while (tags
< start
)
4091 unsigned long abbrev_number
;
4092 unsigned long die_offset
;
4093 abbrev_entry
*entry
;
4095 int do_printing
= 1;
4097 die_offset
= tags
- section_begin
;
4099 READ_ULEB (abbrev_number
, tags
, start
);
4101 /* A null DIE marks the end of a list of siblings or it may also be
4102 a section padding. */
4103 if (abbrev_number
== 0)
4105 /* Check if it can be a section padding for the last CU. */
4106 if (level
== 0 && start
== end
)
4110 for (chk
= tags
; chk
< start
; chk
++)
4117 if (!do_loc
&& die_offset
>= dwarf_start_die
4118 && (dwarf_cutoff_level
== -1
4119 || level
< dwarf_cutoff_level
))
4120 printf (_(" <%d><%lx>: Abbrev Number: 0\n"),
4126 static unsigned num_bogus_warns
= 0;
4128 if (num_bogus_warns
< 3)
4130 warn (_("Bogus end-of-siblings marker detected at offset %lx in %s section\n"),
4131 die_offset
, section
->name
);
4133 if (num_bogus_warns
== 3)
4134 warn (_("Further warnings about bogus end-of-sibling markers suppressed\n"));
4137 if (dwarf_start_die
!= 0 && level
< saved_level
)
4140 free_abbrev_list (list
);
4148 if (dwarf_start_die
!= 0 && die_offset
< dwarf_start_die
)
4152 if (dwarf_start_die
!= 0 && die_offset
== dwarf_start_die
)
4153 saved_level
= level
;
4154 do_printing
= (dwarf_cutoff_level
== -1
4155 || level
< dwarf_cutoff_level
);
4157 printf (_(" <%d><%lx>: Abbrev Number: %lu"),
4158 level
, die_offset
, abbrev_number
);
4159 else if (dwarf_cutoff_level
== -1
4160 || last_level
< dwarf_cutoff_level
)
4161 printf (_(" <%d><%lx>: ...\n"), level
, die_offset
);
4166 /* Scan through the abbreviation list until we reach the
4170 for (entry
= list
->first_abbrev
; entry
!= NULL
; entry
= entry
->next
)
4171 if (entry
->number
== abbrev_number
)
4176 if (!do_loc
&& do_printing
)
4181 warn (_("DIE at offset %#lx refers to abbreviation number %lu which does not exist\n"),
4182 die_offset
, abbrev_number
);
4184 free_abbrev_list (list
);
4188 if (!do_loc
&& do_printing
)
4189 printf (" (%s)\n", get_TAG_name (entry
->tag
));
4194 need_base_address
= 0;
4196 case DW_TAG_compile_unit
:
4197 case DW_TAG_skeleton_unit
:
4198 need_base_address
= 1;
4199 need_dwo_info
= do_loc
;
4201 case DW_TAG_entry_point
:
4202 case DW_TAG_subprogram
:
4203 need_base_address
= 0;
4204 /* Assuming that there is no DW_AT_frame_base. */
4205 have_frame_base
= 0;
4209 debug_info
*debug_info_p
=
4210 (debug_information
&& unit
< alloc_num_debug_info_entries
)
4211 ? debug_information
+ unit
: NULL
;
4213 assert (!debug_info_p
4214 || (debug_info_p
->num_loc_offsets
4215 == debug_info_p
->num_loc_views
));
4217 /* Look ahead so that the values of DW_AT_rnglists_base, DW_AT_[GNU_]addr_base
4218 are available before attributes that reference them are parsed in the same DIE.
4219 Only needed for the top DIE on DWARFv5+.
4220 No simiar treatment for loclists_base because there should be no loclist
4221 attributes in top DIE. */
4222 if (compunit
.cu_version
>= 5 && level
== 0)
4229 compunit
.cu_pointer_size
,
4231 compunit
.cu_version
,
4234 /* This check was in place before, keep it. */
4235 stemp
= debug_info_p
->rnglists_base
;
4238 warn (_("CU @ %#" PRIx64
" has has a negative rnglists_base "
4239 "value of %#" PRIx64
" - treating as zero"),
4240 debug_info_p
->cu_offset
, stemp
);
4241 debug_info_p
->rnglists_base
= 0;
4245 for (attr
= entry
->first_attr
;
4246 attr
&& attr
->attribute
;
4249 if (! do_loc
&& do_printing
)
4250 /* Show the offset from where the tag was extracted. */
4251 printf (" <%tx>", tags
- section_begin
);
4252 tags
= read_and_display_attr (attr
->attribute
,
4254 attr
->implicit_const
,
4259 compunit
.cu_pointer_size
,
4261 compunit
.cu_version
,
4263 do_loc
|| ! do_printing
,
4269 /* If a locview attribute appears before a location one,
4270 make sure we don't associate it with an earlier
4273 switch (debug_info_p
->num_loc_offsets
- debug_info_p
->num_loc_views
)
4276 debug_info_p
->loc_views
[debug_info_p
->num_loc_views
] = -1;
4277 debug_info_p
->num_loc_views
++;
4278 assert (debug_info_p
->num_loc_views
4279 == debug_info_p
->num_loc_offsets
);
4286 warn(_("DIE has locviews without loclist\n"));
4287 debug_info_p
->num_loc_views
--;
4294 if (entry
->children
)
4298 free_abbrev_list (list
);
4301 /* Set num_debug_info_entries here so that it can be used to check if
4302 we need to process .debug_loc and .debug_ranges sections. */
4303 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
|| do_debug_info
)
4304 && num_debug_info_entries
== 0
4307 if (num_units
> alloc_num_debug_info_entries
)
4308 num_debug_info_entries
= alloc_num_debug_info_entries
;
4310 num_debug_info_entries
= num_units
;
4319 /* Locate and scan the .debug_info section in the file and record the pointer
4320 sizes and offsets for the compilation units in it. Usually an executable
4321 will have just one pointer size, but this is not guaranteed, and so we try
4322 not to make any assumptions. Returns zero upon failure, or the number of
4323 compilation units upon success. */
4326 load_debug_info (void * file
)
4328 /* If we have already tried and failed to load the .debug_info
4329 section then do not bother to repeat the task. */
4330 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
4333 /* If we already have the information there is nothing else to do. */
4334 if (num_debug_info_entries
> 0)
4335 return num_debug_info_entries
;
4337 /* If this is a DWARF package file, load the CU and TU indexes. */
4338 (void) load_cu_tu_indexes (file
);
4340 if (load_debug_section_with_follow (info
, file
)
4341 && process_debug_info (&debug_displays
[info
].section
, file
, abbrev
, true, false))
4342 return num_debug_info_entries
;
4344 if (load_debug_section_with_follow (info_dwo
, file
)
4345 && process_debug_info (&debug_displays
[info_dwo
].section
, file
,
4346 abbrev_dwo
, true, false))
4347 return num_debug_info_entries
;
4349 num_debug_info_entries
= DEBUG_INFO_UNAVAILABLE
;
4353 /* Read a DWARF .debug_line section header starting at DATA.
4354 Upon success returns an updated DATA pointer and the LINFO
4355 structure and the END_OF_SEQUENCE pointer will be filled in.
4356 Otherwise returns NULL. */
4358 static unsigned char *
4359 read_debug_line_header (struct dwarf_section
* section
,
4360 unsigned char * data
,
4361 unsigned char * end
,
4362 DWARF2_Internal_LineInfo
* linfo
,
4363 unsigned char ** end_of_sequence
)
4365 unsigned char *hdrptr
;
4367 /* Extract information from the Line Number Program Header.
4368 (section 6.2.4 in the Dwarf3 doc). */
4371 /* Get and check the length of the block. */
4372 SAFE_BYTE_GET_AND_INC (linfo
->li_length
, hdrptr
, 4, end
);
4374 if (linfo
->li_length
== 0xffffffff)
4376 /* This section is 64-bit DWARF 3. */
4377 SAFE_BYTE_GET_AND_INC (linfo
->li_length
, hdrptr
, 8, end
);
4378 linfo
->li_offset_size
= 8;
4381 linfo
->li_offset_size
= 4;
4383 if (linfo
->li_length
> (size_t) (end
- hdrptr
))
4385 /* If the length field has a relocation against it, then we should
4386 not complain if it is inaccurate (and probably negative). This
4387 happens in object files when the .debug_line section is actually
4388 comprised of several different .debug_line.* sections, (some of
4389 which may be removed by linker garbage collection), and a relocation
4390 is used to compute the correct length once that is done. */
4391 if (reloc_at (section
, (hdrptr
- section
->start
) - linfo
->li_offset_size
))
4393 linfo
->li_length
= end
- hdrptr
;
4397 warn (_("The length field (%#" PRIx64
")"
4398 " in the debug_line header is wrong"
4399 " - the section is too small\n"),
4404 end
= hdrptr
+ linfo
->li_length
;
4406 /* Get and check the version number. */
4407 SAFE_BYTE_GET_AND_INC (linfo
->li_version
, hdrptr
, 2, end
);
4409 if (linfo
->li_version
!= 2
4410 && linfo
->li_version
!= 3
4411 && linfo
->li_version
!= 4
4412 && linfo
->li_version
!= 5)
4414 warn (_("Only DWARF version 2, 3, 4 and 5 line info "
4415 "is currently supported.\n"));
4419 if (linfo
->li_version
>= 5)
4421 SAFE_BYTE_GET_AND_INC (linfo
->li_address_size
, hdrptr
, 1, end
);
4423 SAFE_BYTE_GET_AND_INC (linfo
->li_segment_size
, hdrptr
, 1, end
);
4424 if (linfo
->li_segment_size
!= 0)
4426 warn (_("The %s section contains "
4427 "unsupported segment selector size: %d.\n"),
4428 section
->name
, linfo
->li_segment_size
);
4433 SAFE_BYTE_GET_AND_INC (linfo
->li_prologue_length
, hdrptr
,
4434 linfo
->li_offset_size
, end
);
4435 SAFE_BYTE_GET_AND_INC (linfo
->li_min_insn_length
, hdrptr
, 1, end
);
4437 if (linfo
->li_version
>= 4)
4439 SAFE_BYTE_GET_AND_INC (linfo
->li_max_ops_per_insn
, hdrptr
, 1, end
);
4441 if (linfo
->li_max_ops_per_insn
== 0)
4443 warn (_("Invalid maximum operations per insn.\n"));
4448 linfo
->li_max_ops_per_insn
= 1;
4450 SAFE_BYTE_GET_AND_INC (linfo
->li_default_is_stmt
, hdrptr
, 1, end
);
4451 SAFE_SIGNED_BYTE_GET_AND_INC (linfo
->li_line_base
, hdrptr
, 1, end
);
4452 SAFE_BYTE_GET_AND_INC (linfo
->li_line_range
, hdrptr
, 1, end
);
4453 SAFE_BYTE_GET_AND_INC (linfo
->li_opcode_base
, hdrptr
, 1, end
);
4455 *end_of_sequence
= end
;
4459 static unsigned char *
4460 display_formatted_table (unsigned char *data
,
4461 unsigned char *start
,
4463 const DWARF2_Internal_LineInfo
*linfo
,
4464 struct dwarf_section
*section
,
4467 unsigned char *format_start
, format_count
, *format
, formati
;
4468 uint64_t data_count
, datai
;
4469 unsigned int namepass
, last_entry
= 0;
4470 const char * table_name
= is_dir
? N_("Directory Table") : N_("File Name Table");
4472 SAFE_BYTE_GET_AND_INC (format_count
, data
, 1, end
);
4473 if (do_checks
&& format_count
> 5)
4474 warn (_("Unexpectedly large number of columns in the %s (%u)\n"),
4475 table_name
, format_count
);
4477 format_start
= data
;
4478 for (formati
= 0; formati
< format_count
; formati
++)
4480 SKIP_ULEB (data
, end
);
4481 SKIP_ULEB (data
, end
);
4484 warn (_("%s: Corrupt format description entry\n"), table_name
);
4489 READ_ULEB (data_count
, data
, end
);
4490 if (data_count
== 0)
4492 printf (_("\n The %s is empty.\n"), table_name
);
4495 else if (data
>= end
4496 || data_count
> (size_t) (end
- data
))
4498 warn (_("%s: Corrupt entry count %#" PRIx64
"\n"), table_name
, data_count
);
4502 else if (format_count
== 0)
4504 warn (_("%s: format count is zero, but the table is not empty\n"),
4509 printf (_("\n The %s (offset %#tx, lines %" PRIu64
", columns %u):\n"),
4510 table_name
, data
- start
, data_count
, format_count
);
4512 printf (_(" Entry"));
4513 /* Delay displaying name as the last entry for better screen layout. */
4514 for (namepass
= 0; namepass
< 2; namepass
++)
4516 format
= format_start
;
4517 for (formati
= 0; formati
< format_count
; formati
++)
4519 uint64_t content_type
;
4521 READ_ULEB (content_type
, format
, end
);
4522 if ((content_type
== DW_LNCT_path
) == (namepass
== 1))
4523 switch (content_type
)
4526 printf (_("\tName"));
4528 case DW_LNCT_directory_index
:
4529 printf (_("\tDir"));
4531 case DW_LNCT_timestamp
:
4532 printf (_("\tTime"));
4535 printf (_("\tSize"));
4538 printf (_("\tMD5\t\t\t"));
4541 printf (_("\t(Unknown format content type %" PRIu64
")"),
4544 SKIP_ULEB (format
, end
);
4549 for (datai
= 0; datai
< data_count
; datai
++)
4551 unsigned char *datapass
= data
;
4553 printf (" %d", last_entry
++);
4554 /* Delay displaying name as the last entry for better screen layout. */
4555 for (namepass
= 0; namepass
< 2; namepass
++)
4557 format
= format_start
;
4559 for (formati
= 0; formati
< format_count
; formati
++)
4561 uint64_t content_type
, form
;
4563 READ_ULEB (content_type
, format
, end
);
4564 READ_ULEB (form
, format
, end
);
4565 data
= read_and_display_attr_value (0, form
, 0, start
, data
, end
,
4566 0, 0, linfo
->li_offset_size
,
4567 linfo
->li_version
, NULL
,
4568 ((content_type
== DW_LNCT_path
) != (namepass
== 1)),
4569 section
, NULL
, '\t', -1);
4573 if (data
>= end
&& (datai
< data_count
- 1))
4575 warn (_("\n%s: Corrupt entries list\n"), table_name
);
4584 display_debug_sup (struct dwarf_section
* section
,
4585 void * file ATTRIBUTE_UNUSED
)
4587 unsigned char * start
= section
->start
;
4588 unsigned char * end
= section
->start
+ section
->size
;
4589 unsigned int version
;
4590 char is_supplementary
;
4591 const unsigned char * sup_filename
;
4592 size_t sup_filename_len
;
4593 unsigned int num_read
;
4595 uint64_t checksum_len
;
4598 introduce (section
, true);
4599 if (section
->size
< 4)
4601 error (_("corrupt .debug_sup section: size is too small\n"));
4605 /* Read the data. */
4606 SAFE_BYTE_GET_AND_INC (version
, start
, 2, end
);
4608 warn (_("corrupt .debug_sup section: version < 5"));
4610 SAFE_BYTE_GET_AND_INC (is_supplementary
, start
, 1, end
);
4611 if (is_supplementary
!= 0 && is_supplementary
!= 1)
4612 warn (_("corrupt .debug_sup section: is_supplementary not 0 or 1\n"));
4614 sup_filename
= start
;
4615 if (is_supplementary
&& sup_filename
[0] != 0)
4616 warn (_("corrupt .debug_sup section: filename not empty in supplementary section\n"));
4618 sup_filename_len
= strnlen ((const char *) start
, end
- start
);
4619 if (sup_filename_len
== (size_t) (end
- start
))
4621 error (_("corrupt .debug_sup section: filename is not NUL terminated\n"));
4624 start
+= sup_filename_len
+ 1;
4626 checksum_len
= read_leb128 (start
, end
, false /* unsigned */, & num_read
, & status
);
4629 error (_("corrupt .debug_sup section: bad LEB128 field for checksum length\n"));
4633 if (checksum_len
> (size_t) (end
- start
))
4635 error (_("corrupt .debug_sup section: checksum length is longer than the remaining section length\n"));
4636 checksum_len
= end
- start
;
4638 else if (checksum_len
< (size_t) (end
- start
))
4640 warn (_("corrupt .debug_sup section: there are %#" PRIx64
4641 " extra, unused bytes at the end of the section\n"),
4642 (end
- start
) - checksum_len
);
4645 printf (_(" Version: %u\n"), version
);
4646 printf (_(" Is Supp: %u\n"), is_supplementary
);
4647 printf (_(" Filename: %s\n"), sup_filename
);
4648 printf (_(" Checksum Len: %" PRIu64
"\n"), checksum_len
);
4649 if (checksum_len
> 0)
4651 printf (_(" Checksum: "));
4652 while (checksum_len
--)
4653 printf ("0x%x ", * start
++ );
4660 display_debug_lines_raw (struct dwarf_section
* section
,
4661 unsigned char * data
,
4662 unsigned char * end
,
4665 unsigned char *start
= section
->start
;
4666 int verbose_view
= 0;
4668 introduce (section
, true);
4672 static DWARF2_Internal_LineInfo saved_linfo
;
4673 DWARF2_Internal_LineInfo linfo
;
4674 unsigned char *standard_opcodes
;
4675 unsigned char *end_of_sequence
;
4678 if (startswith (section
->name
, ".debug_line.")
4679 /* Note: the following does not apply to .debug_line.dwo sections.
4680 These are full debug_line sections. */
4681 && strcmp (section
->name
, ".debug_line.dwo") != 0)
4683 /* Sections named .debug_line.<foo> are fragments of a .debug_line
4684 section containing just the Line Number Statements. They are
4685 created by the assembler and intended to be used alongside gcc's
4686 -ffunction-sections command line option. When the linker's
4687 garbage collection decides to discard a .text.<foo> section it
4688 can then also discard the line number information in .debug_line.<foo>.
4690 Since the section is a fragment it does not have the details
4691 needed to fill out a LineInfo structure, so instead we use the
4692 details from the last full debug_line section that we processed. */
4693 end_of_sequence
= end
;
4694 standard_opcodes
= NULL
;
4695 linfo
= saved_linfo
;
4696 /* PR 17531: file: 0522b371. */
4697 if (linfo
.li_line_range
== 0)
4699 warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n"));
4702 reset_state_machine (linfo
.li_default_is_stmt
);
4706 unsigned char * hdrptr
;
4708 if ((hdrptr
= read_debug_line_header (section
, data
, end
, & linfo
,
4709 & end_of_sequence
)) == NULL
)
4712 printf (_(" Offset: %#tx\n"), data
- start
);
4713 printf (_(" Length: %" PRId64
"\n"), linfo
.li_length
);
4714 printf (_(" DWARF Version: %d\n"), linfo
.li_version
);
4715 if (linfo
.li_version
>= 5)
4717 printf (_(" Address size (bytes): %d\n"), linfo
.li_address_size
);
4718 printf (_(" Segment selector (bytes): %d\n"), linfo
.li_segment_size
);
4720 printf (_(" Prologue Length: %d\n"), (int) linfo
.li_prologue_length
);
4721 printf (_(" Minimum Instruction Length: %d\n"), linfo
.li_min_insn_length
);
4722 if (linfo
.li_version
>= 4)
4723 printf (_(" Maximum Ops per Instruction: %d\n"), linfo
.li_max_ops_per_insn
);
4724 printf (_(" Initial value of 'is_stmt': %d\n"), linfo
.li_default_is_stmt
);
4725 printf (_(" Line Base: %d\n"), linfo
.li_line_base
);
4726 printf (_(" Line Range: %d\n"), linfo
.li_line_range
);
4727 printf (_(" Opcode Base: %d\n"), linfo
.li_opcode_base
);
4729 /* PR 17512: file: 1665-6428-0.004. */
4730 if (linfo
.li_line_range
== 0)
4732 warn (_("Line range of 0 is invalid, using 1 instead\n"));
4733 linfo
.li_line_range
= 1;
4736 reset_state_machine (linfo
.li_default_is_stmt
);
4738 /* Display the contents of the Opcodes table. */
4739 standard_opcodes
= hdrptr
;
4741 /* PR 17512: file: 002-417945-0.004. */
4742 if (standard_opcodes
+ linfo
.li_opcode_base
>= end
)
4744 warn (_("Line Base extends beyond end of section\n"));
4748 printf (_("\n Opcodes:\n"));
4750 for (i
= 1; i
< linfo
.li_opcode_base
; i
++)
4751 printf (ngettext (" Opcode %d has %d arg\n",
4752 " Opcode %d has %d args\n",
4753 standard_opcodes
[i
- 1]),
4754 i
, standard_opcodes
[i
- 1]);
4756 /* Display the contents of the Directory table. */
4757 data
= standard_opcodes
+ linfo
.li_opcode_base
- 1;
4759 if (linfo
.li_version
>= 5)
4761 load_debug_section_with_follow (line_str
, file
);
4763 data
= display_formatted_table (data
, start
, end
, &linfo
, section
,
4765 data
= display_formatted_table (data
, start
, end
, &linfo
, section
,
4771 printf (_("\n The Directory Table is empty.\n"));
4774 unsigned int last_dir_entry
= 0;
4776 printf (_("\n The Directory Table (offset %#tx):\n"),
4779 while (data
< end
&& *data
!= 0)
4781 printf (" %d\t%.*s\n", ++last_dir_entry
, (int) (end
- data
), data
);
4783 data
+= strnlen ((char *) data
, end
- data
);
4788 /* PR 17512: file: 002-132094-0.004. */
4789 if (data
>= end
- 1)
4793 /* Skip the NUL at the end of the table. */
4797 /* Display the contents of the File Name table. */
4798 if (data
>= end
|| *data
== 0)
4799 printf (_("\n The File Name Table is empty.\n"));
4802 printf (_("\n The File Name Table (offset %#tx):\n"),
4804 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
4806 while (data
< end
&& *data
!= 0)
4808 unsigned char *name
;
4811 printf (" %d\t", ++state_machine_regs
.last_file_entry
);
4813 data
+= strnlen ((char *) data
, end
- data
);
4817 READ_ULEB (val
, data
, end
);
4818 printf ("%" PRIu64
"\t", val
);
4819 READ_ULEB (val
, data
, end
);
4820 printf ("%" PRIu64
"\t", val
);
4821 READ_ULEB (val
, data
, end
);
4822 printf ("%" PRIu64
"\t", val
);
4823 printf ("%.*s\n", (int)(end
- name
), name
);
4827 warn (_("Corrupt file name table entry\n"));
4833 /* Skip the NUL at the end of the table. */
4839 saved_linfo
= linfo
;
4842 /* Now display the statements. */
4843 if (data
>= end_of_sequence
)
4844 printf (_(" No Line Number Statements.\n"));
4847 printf (_(" Line Number Statements:\n"));
4849 while (data
< end_of_sequence
)
4851 unsigned char op_code
;
4855 printf (" [0x%08tx]", data
- start
);
4859 if (op_code
>= linfo
.li_opcode_base
)
4861 op_code
-= linfo
.li_opcode_base
;
4862 uladv
= (op_code
/ linfo
.li_line_range
);
4863 if (linfo
.li_max_ops_per_insn
== 1)
4865 uladv
*= linfo
.li_min_insn_length
;
4866 state_machine_regs
.address
+= uladv
;
4868 state_machine_regs
.view
= 0;
4869 printf (_(" Special opcode %d: "
4870 "advance Address by %" PRIu64
4871 " to %#" PRIx64
"%s"),
4872 op_code
, uladv
, state_machine_regs
.address
,
4873 verbose_view
&& uladv
4874 ? _(" (reset view)") : "");
4879 = ((state_machine_regs
.op_index
+ uladv
)
4880 / linfo
.li_max_ops_per_insn
)
4881 * linfo
.li_min_insn_length
;
4883 state_machine_regs
.address
+= addrdelta
;
4884 state_machine_regs
.op_index
4885 = (state_machine_regs
.op_index
+ uladv
)
4886 % linfo
.li_max_ops_per_insn
;
4888 state_machine_regs
.view
= 0;
4889 printf (_(" Special opcode %d: "
4890 "advance Address by %" PRIu64
4891 " to %#" PRIx64
"[%d]%s"),
4892 op_code
, uladv
, state_machine_regs
.address
,
4893 state_machine_regs
.op_index
,
4894 verbose_view
&& addrdelta
4895 ? _(" (reset view)") : "");
4897 adv
= (op_code
% linfo
.li_line_range
) + linfo
.li_line_base
;
4898 state_machine_regs
.line
+= adv
;
4899 printf (_(" and Line by %d to %d"),
4900 adv
, state_machine_regs
.line
);
4901 if (verbose_view
|| state_machine_regs
.view
)
4902 printf (_(" (view %u)\n"), state_machine_regs
.view
);
4905 state_machine_regs
.view
++;
4910 case DW_LNS_extended_op
:
4911 data
+= process_extended_line_op (data
,
4912 linfo
.li_default_is_stmt
,
4917 printf (_(" Copy"));
4918 if (verbose_view
|| state_machine_regs
.view
)
4919 printf (_(" (view %u)\n"), state_machine_regs
.view
);
4922 state_machine_regs
.view
++;
4925 case DW_LNS_advance_pc
:
4926 READ_ULEB (uladv
, data
, end
);
4927 if (linfo
.li_max_ops_per_insn
== 1)
4929 uladv
*= linfo
.li_min_insn_length
;
4930 state_machine_regs
.address
+= uladv
;
4932 state_machine_regs
.view
= 0;
4933 printf (_(" Advance PC by %" PRIu64
4934 " to %#" PRIx64
"%s\n"),
4935 uladv
, state_machine_regs
.address
,
4936 verbose_view
&& uladv
4937 ? _(" (reset view)") : "");
4942 = ((state_machine_regs
.op_index
+ uladv
)
4943 / linfo
.li_max_ops_per_insn
)
4944 * linfo
.li_min_insn_length
;
4945 state_machine_regs
.address
4947 state_machine_regs
.op_index
4948 = (state_machine_regs
.op_index
+ uladv
)
4949 % linfo
.li_max_ops_per_insn
;
4951 state_machine_regs
.view
= 0;
4952 printf (_(" Advance PC by %" PRIu64
4953 " to %#" PRIx64
"[%d]%s\n"),
4954 uladv
, state_machine_regs
.address
,
4955 state_machine_regs
.op_index
,
4956 verbose_view
&& addrdelta
4957 ? _(" (reset view)") : "");
4961 case DW_LNS_advance_line
:
4962 READ_SLEB (adv
, data
, end
);
4963 state_machine_regs
.line
+= adv
;
4964 printf (_(" Advance Line by %d to %d\n"),
4965 adv
, state_machine_regs
.line
);
4968 case DW_LNS_set_file
:
4969 READ_ULEB (uladv
, data
, end
);
4970 printf (_(" Set File Name to entry %" PRIu64
4971 " in the File Name Table\n"), uladv
);
4972 state_machine_regs
.file
= uladv
;
4975 case DW_LNS_set_column
:
4976 READ_ULEB (uladv
, data
, end
);
4977 printf (_(" Set column to %" PRIu64
"\n"), uladv
);
4978 state_machine_regs
.column
= uladv
;
4981 case DW_LNS_negate_stmt
:
4982 adv
= state_machine_regs
.is_stmt
;
4984 printf (_(" Set is_stmt to %d\n"), adv
);
4985 state_machine_regs
.is_stmt
= adv
;
4988 case DW_LNS_set_basic_block
:
4989 printf (_(" Set basic block\n"));
4990 state_machine_regs
.basic_block
= 1;
4993 case DW_LNS_const_add_pc
:
4994 uladv
= ((255 - linfo
.li_opcode_base
) / linfo
.li_line_range
);
4995 if (linfo
.li_max_ops_per_insn
)
4997 uladv
*= linfo
.li_min_insn_length
;
4998 state_machine_regs
.address
+= uladv
;
5000 state_machine_regs
.view
= 0;
5001 printf (_(" Advance PC by constant %" PRIu64
5002 " to %#" PRIx64
"%s\n"),
5003 uladv
, state_machine_regs
.address
,
5004 verbose_view
&& uladv
5005 ? _(" (reset view)") : "");
5010 = ((state_machine_regs
.op_index
+ uladv
)
5011 / linfo
.li_max_ops_per_insn
)
5012 * linfo
.li_min_insn_length
;
5013 state_machine_regs
.address
5015 state_machine_regs
.op_index
5016 = (state_machine_regs
.op_index
+ uladv
)
5017 % linfo
.li_max_ops_per_insn
;
5019 state_machine_regs
.view
= 0;
5020 printf (_(" Advance PC by constant %" PRIu64
5021 " to %#" PRIx64
"[%d]%s\n"),
5022 uladv
, state_machine_regs
.address
,
5023 state_machine_regs
.op_index
,
5024 verbose_view
&& addrdelta
5025 ? _(" (reset view)") : "");
5029 case DW_LNS_fixed_advance_pc
:
5030 SAFE_BYTE_GET_AND_INC (uladv
, data
, 2, end
);
5031 state_machine_regs
.address
+= uladv
;
5032 state_machine_regs
.op_index
= 0;
5033 printf (_(" Advance PC by fixed size amount %" PRIu64
5034 " to %#" PRIx64
"\n"),
5035 uladv
, state_machine_regs
.address
);
5036 /* Do NOT reset view. */
5039 case DW_LNS_set_prologue_end
:
5040 printf (_(" Set prologue_end to true\n"));
5043 case DW_LNS_set_epilogue_begin
:
5044 printf (_(" Set epilogue_begin to true\n"));
5047 case DW_LNS_set_isa
:
5048 READ_ULEB (uladv
, data
, end
);
5049 printf (_(" Set ISA to %" PRIu64
"\n"), uladv
);
5053 printf (_(" Unknown opcode %d with operands: "), op_code
);
5055 if (standard_opcodes
!= NULL
)
5056 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
5058 READ_ULEB (uladv
, data
, end
);
5059 printf ("%#" PRIx64
"%s", uladv
, i
== 1 ? "" : ", ");
5075 unsigned int directory_index
;
5076 unsigned int modification_date
;
5077 unsigned int length
;
5080 /* Output a decoded representation of the .debug_line section. */
5083 display_debug_lines_decoded (struct dwarf_section
* section
,
5084 unsigned char * start
,
5085 unsigned char * data
,
5086 unsigned char * end
,
5089 static DWARF2_Internal_LineInfo saved_linfo
;
5091 introduce (section
, false);
5095 /* This loop amounts to one iteration per compilation unit. */
5096 DWARF2_Internal_LineInfo linfo
;
5097 unsigned char *standard_opcodes
;
5098 unsigned char *end_of_sequence
;
5100 File_Entry
*file_table
= NULL
;
5101 unsigned int n_files
= 0;
5102 char **directory_table
= NULL
;
5103 unsigned int n_directories
= 0;
5105 if (startswith (section
->name
, ".debug_line.")
5106 /* Note: the following does not apply to .debug_line.dwo sections.
5107 These are full debug_line sections. */
5108 && strcmp (section
->name
, ".debug_line.dwo") != 0)
5110 /* See comment in display_debug_lines_raw(). */
5111 end_of_sequence
= end
;
5112 standard_opcodes
= NULL
;
5113 linfo
= saved_linfo
;
5114 /* PR 17531: file: 0522b371. */
5115 if (linfo
.li_line_range
== 0)
5117 warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n"));
5120 reset_state_machine (linfo
.li_default_is_stmt
);
5124 unsigned char *hdrptr
;
5126 if ((hdrptr
= read_debug_line_header (section
, data
, end
, & linfo
,
5127 & end_of_sequence
)) == NULL
)
5130 /* PR 17531: file: 0522b371. */
5131 if (linfo
.li_line_range
== 0)
5133 warn (_("Line range of 0 is invalid, using 1 instead\n"));
5134 linfo
.li_line_range
= 1;
5136 reset_state_machine (linfo
.li_default_is_stmt
);
5138 /* Save a pointer to the contents of the Opcodes table. */
5139 standard_opcodes
= hdrptr
;
5141 /* Traverse the Directory table just to count entries. */
5142 data
= standard_opcodes
+ linfo
.li_opcode_base
- 1;
5146 warn (_("opcode base of %d extends beyond end of section\n"),
5147 linfo
.li_opcode_base
);
5151 if (linfo
.li_version
>= 5)
5153 unsigned char *format_start
, *format
;
5154 unsigned int format_count
, formati
, entryi
;
5156 load_debug_section_with_follow (line_str
, fileptr
);
5158 /* Skip directories format. */
5159 SAFE_BYTE_GET_AND_INC (format_count
, data
, 1, end
);
5160 if (do_checks
&& format_count
> 1)
5161 warn (_("Unexpectedly large number of columns in the directory name table (%u)\n"),
5163 format_start
= data
;
5164 for (formati
= 0; formati
< format_count
; formati
++)
5166 SKIP_ULEB (data
, end
);
5167 SKIP_ULEB (data
, end
);
5170 READ_ULEB (n_directories
, data
, end
);
5173 warn (_("Corrupt directories list\n"));
5177 if (n_directories
== 0)
5178 directory_table
= NULL
;
5179 else if (n_directories
> section
->size
)
5181 warn (_("number of directories (0x%x) exceeds size of section %s\n"),
5182 n_directories
, section
->name
);
5186 directory_table
= (char **)
5187 xcalloc (n_directories
, sizeof (unsigned char *));
5189 for (entryi
= 0; entryi
< n_directories
; entryi
++)
5191 char **pathp
= &directory_table
[entryi
];
5193 format
= format_start
;
5194 for (formati
= 0; formati
< format_count
; formati
++)
5196 uint64_t content_type
, form
;
5199 READ_ULEB (content_type
, format
, end
);
5200 READ_ULEB (form
, format
, end
);
5203 warn (_("Corrupt directories list\n"));
5206 switch (content_type
)
5211 case DW_FORM_string
:
5212 *pathp
= (char *) data
;
5214 case DW_FORM_line_strp
:
5215 SAFE_BYTE_GET (uvalue
, data
, linfo
.li_offset_size
,
5217 /* Remove const by the cast. */
5219 fetch_indirect_line_string (uvalue
);
5224 data
= read_and_display_attr_value (0, form
, 0, start
,
5226 linfo
.li_offset_size
,
5233 warn (_("Corrupt directories list\n"));
5238 /* Skip files format. */
5239 SAFE_BYTE_GET_AND_INC (format_count
, data
, 1, end
);
5240 if (do_checks
&& format_count
> 5)
5241 warn (_("Unexpectedly large number of columns in the file name table (%u)\n"),
5244 format_start
= data
;
5245 for (formati
= 0; formati
< format_count
; formati
++)
5247 SKIP_ULEB (data
, end
);
5248 SKIP_ULEB (data
, end
);
5251 READ_ULEB (n_files
, data
, end
);
5252 if (data
>= end
&& n_files
> 0)
5254 warn (_("Corrupt file name list\n"));
5260 else if (n_files
> section
->size
)
5262 warn (_("number of files (0x%x) exceeds size of section %s\n"),
5263 n_files
, section
->name
);
5267 file_table
= (File_Entry
*) xcalloc (n_files
,
5268 sizeof (File_Entry
));
5270 for (entryi
= 0; entryi
< n_files
; entryi
++)
5272 File_Entry
*file
= &file_table
[entryi
];
5274 format
= format_start
;
5275 for (formati
= 0; formati
< format_count
; formati
++)
5277 uint64_t content_type
, form
;
5281 READ_ULEB (content_type
, format
, end
);
5282 READ_ULEB (form
, format
, end
);
5285 warn (_("Corrupt file name list\n"));
5288 switch (content_type
)
5293 case DW_FORM_string
:
5294 file
->name
= (char *) data
;
5296 case DW_FORM_line_strp
:
5297 SAFE_BYTE_GET (uvalue
, data
, linfo
.li_offset_size
,
5299 /* Remove const by the cast. */
5300 file
->name
= (char *)
5301 fetch_indirect_line_string (uvalue
);
5305 case DW_LNCT_directory_index
:
5309 SAFE_BYTE_GET (file
->directory_index
, data
, 1,
5313 SAFE_BYTE_GET (file
->directory_index
, data
, 2,
5318 READ_ULEB (file
->directory_index
, tmp
, end
);
5323 data
= read_and_display_attr_value (0, form
, 0, start
,
5325 linfo
.li_offset_size
,
5332 warn (_("Corrupt file name list\n"));
5341 char *ptr_directory_table
= (char *) data
;
5343 while (data
< end
&& *data
!= 0)
5345 data
+= strnlen ((char *) data
, end
- data
);
5354 warn (_("directory table ends unexpectedly\n"));
5359 /* Go through the directory table again to save the directories. */
5360 directory_table
= (char **)
5361 xmalloc (n_directories
* sizeof (unsigned char *));
5364 while (*ptr_directory_table
!= 0)
5366 directory_table
[i
] = ptr_directory_table
;
5367 ptr_directory_table
+= strlen (ptr_directory_table
) + 1;
5371 /* Skip the NUL at the end of the table. */
5374 /* Traverse the File Name table just to count the entries. */
5375 if (data
< end
&& *data
!= 0)
5377 unsigned char *ptr_file_name_table
= data
;
5379 while (data
< end
&& *data
!= 0)
5381 /* Skip Name, directory index, last modification
5382 time and length of file. */
5383 data
+= strnlen ((char *) data
, end
- data
);
5386 SKIP_ULEB (data
, end
);
5387 SKIP_ULEB (data
, end
);
5388 SKIP_ULEB (data
, end
);
5394 warn (_("file table ends unexpectedly\n"));
5399 /* Go through the file table again to save the strings. */
5400 file_table
= (File_Entry
*) xmalloc (n_files
* sizeof (File_Entry
));
5403 while (*ptr_file_name_table
!= 0)
5405 file_table
[i
].name
= (char *) ptr_file_name_table
;
5407 += strlen ((char *) ptr_file_name_table
) + 1;
5409 /* We are not interested in directory, time or size. */
5410 READ_ULEB (file_table
[i
].directory_index
,
5411 ptr_file_name_table
, end
);
5412 READ_ULEB (file_table
[i
].modification_date
,
5413 ptr_file_name_table
, end
);
5414 READ_ULEB (file_table
[i
].length
,
5415 ptr_file_name_table
, end
);
5421 /* Skip the NUL at the end of the table. */
5425 /* Print the Compilation Unit's name and a header. */
5426 if (file_table
== NULL
)
5427 printf (_("CU: No directory table\n"));
5428 else if (directory_table
== NULL
)
5429 printf (_("CU: %s:\n"), null_name (file_table
[0].name
));
5432 unsigned int ix
= file_table
[0].directory_index
;
5433 const char *directory
;
5435 if (ix
== 0 && linfo
.li_version
< 5)
5438 else if (n_directories
== 0)
5439 directory
= _("<unknown>");
5442 if (linfo
.li_version
< 5)
5444 if (ix
>= n_directories
)
5446 warn (_("directory index %u "
5447 ">= number of directories %u\n"),
5449 directory
= _("<corrupt>");
5452 directory
= directory_table
[ix
];
5455 printf (_("CU: %s/%s:\n"),
5456 null_name (directory
),
5457 null_name (file_table
[0].name
));
5459 printf ("%s:\n", null_name (file_table
[0].name
));
5465 printf (_("File name Line number Starting address View Stmt\n"));
5467 printf (_("File name Line number Starting address View Stmt\n"));
5470 printf (_("CU: Empty file name table\n"));
5471 saved_linfo
= linfo
;
5474 /* This loop iterates through the Dwarf Line Number Program. */
5475 while (data
< end_of_sequence
)
5477 unsigned char op_code
;
5480 unsigned long int uladv
;
5481 int is_special_opcode
= 0;
5486 if (op_code
>= linfo
.li_opcode_base
)
5488 op_code
-= linfo
.li_opcode_base
;
5489 uladv
= (op_code
/ linfo
.li_line_range
);
5490 if (linfo
.li_max_ops_per_insn
== 1)
5492 uladv
*= linfo
.li_min_insn_length
;
5493 state_machine_regs
.address
+= uladv
;
5495 state_machine_regs
.view
= 0;
5500 = ((state_machine_regs
.op_index
+ uladv
)
5501 / linfo
.li_max_ops_per_insn
)
5502 * linfo
.li_min_insn_length
;
5503 state_machine_regs
.address
5505 state_machine_regs
.op_index
5506 = (state_machine_regs
.op_index
+ uladv
)
5507 % linfo
.li_max_ops_per_insn
;
5509 state_machine_regs
.view
= 0;
5512 adv
= (op_code
% linfo
.li_line_range
) + linfo
.li_line_base
;
5513 state_machine_regs
.line
+= adv
;
5514 is_special_opcode
= 1;
5515 /* Increment view after printing this row. */
5520 case DW_LNS_extended_op
:
5522 unsigned int ext_op_code_len
;
5523 unsigned char ext_op_code
;
5524 unsigned char *op_code_end
;
5525 unsigned char *op_code_data
= data
;
5527 READ_ULEB (ext_op_code_len
, op_code_data
, end_of_sequence
);
5528 op_code_end
= op_code_data
+ ext_op_code_len
;
5529 if (ext_op_code_len
== 0 || op_code_end
> end_of_sequence
)
5531 warn (_("Badly formed extended line op encountered!\n"));
5534 ext_op_code
= *op_code_data
++;
5538 switch (ext_op_code
)
5540 case DW_LNE_end_sequence
:
5541 /* Reset stuff after printing this row. */
5543 case DW_LNE_set_address
:
5544 SAFE_BYTE_GET_AND_INC (state_machine_regs
.address
,
5546 op_code_end
- op_code_data
,
5548 state_machine_regs
.op_index
= 0;
5549 state_machine_regs
.view
= 0;
5551 case DW_LNE_define_file
:
5552 file_table
= (File_Entry
*) xrealloc
5553 (file_table
, (n_files
+ 1) * sizeof (File_Entry
));
5555 ++state_machine_regs
.last_file_entry
;
5556 /* Source file name. */
5557 file_table
[n_files
].name
= (char *) op_code_data
;
5558 op_code_data
+= strlen ((char *) op_code_data
) + 1;
5559 /* Directory index. */
5560 READ_ULEB (file_table
[n_files
].directory_index
,
5561 op_code_data
, op_code_end
);
5562 /* Last modification time. */
5563 READ_ULEB (file_table
[n_files
].modification_date
,
5564 op_code_data
, op_code_end
);
5566 READ_ULEB (file_table
[n_files
].length
,
5567 op_code_data
, op_code_end
);
5571 case DW_LNE_set_discriminator
:
5572 case DW_LNE_HP_set_sequence
:
5573 /* Simply ignored. */
5577 printf (_("UNKNOWN (%u): length %ld\n"),
5578 ext_op_code
, (long int) (op_code_data
- data
));
5585 /* Increment view after printing this row. */
5588 case DW_LNS_advance_pc
:
5589 READ_ULEB (uladv
, data
, end
);
5590 if (linfo
.li_max_ops_per_insn
== 1)
5592 uladv
*= linfo
.li_min_insn_length
;
5593 state_machine_regs
.address
+= uladv
;
5595 state_machine_regs
.view
= 0;
5600 = ((state_machine_regs
.op_index
+ uladv
)
5601 / linfo
.li_max_ops_per_insn
)
5602 * linfo
.li_min_insn_length
;
5603 state_machine_regs
.address
5605 state_machine_regs
.op_index
5606 = (state_machine_regs
.op_index
+ uladv
)
5607 % linfo
.li_max_ops_per_insn
;
5609 state_machine_regs
.view
= 0;
5613 case DW_LNS_advance_line
:
5614 READ_SLEB (adv
, data
, end
);
5615 state_machine_regs
.line
+= adv
;
5618 case DW_LNS_set_file
:
5619 READ_ULEB (uladv
, data
, end
);
5620 state_machine_regs
.file
= uladv
;
5622 unsigned file
= state_machine_regs
.file
;
5623 if (linfo
.li_version
< 5)
5626 if (file_table
== NULL
|| n_files
== 0)
5627 printf (_("\n [Use file table entry %d]\n"), file
);
5629 else if (file
>= n_files
)
5631 warn (_("file index %u >= number of files %u\n"),
5633 printf (_("\n <over large file table index %u>"), file
);
5637 unsigned dir
= file_table
[file
].directory_index
;
5638 if (dir
== 0 && linfo
.li_version
< 5)
5639 /* If directory index is 0, that means compilation
5640 current directory. bfd/dwarf2.c shows
5641 DW_AT_comp_dir here but in keeping with the
5642 readelf practice of minimal interpretation of
5643 file data, we show "./". */
5644 printf ("\n./%s:[++]\n",
5645 null_name (file_table
[file
].name
));
5646 else if (directory_table
== NULL
|| n_directories
== 0)
5647 printf (_("\n [Use file %s "
5648 "in directory table entry %d]\n"),
5649 null_name (file_table
[file
].name
), dir
);
5652 if (linfo
.li_version
< 5)
5655 if (dir
>= n_directories
)
5657 warn (_("directory index %u "
5658 ">= number of directories %u\n"),
5659 dir
, n_directories
);
5660 printf (_("\n <over large directory table entry "
5664 printf ("\n%s/%s:\n",
5665 null_name (directory_table
[dir
]),
5666 null_name (file_table
[file
].name
));
5671 case DW_LNS_set_column
:
5672 READ_ULEB (uladv
, data
, end
);
5673 state_machine_regs
.column
= uladv
;
5676 case DW_LNS_negate_stmt
:
5677 adv
= state_machine_regs
.is_stmt
;
5679 state_machine_regs
.is_stmt
= adv
;
5682 case DW_LNS_set_basic_block
:
5683 state_machine_regs
.basic_block
= 1;
5686 case DW_LNS_const_add_pc
:
5687 uladv
= ((255 - linfo
.li_opcode_base
) / linfo
.li_line_range
);
5688 if (linfo
.li_max_ops_per_insn
== 1)
5690 uladv
*= linfo
.li_min_insn_length
;
5691 state_machine_regs
.address
+= uladv
;
5693 state_machine_regs
.view
= 0;
5698 = ((state_machine_regs
.op_index
+ uladv
)
5699 / linfo
.li_max_ops_per_insn
)
5700 * linfo
.li_min_insn_length
;
5701 state_machine_regs
.address
5703 state_machine_regs
.op_index
5704 = (state_machine_regs
.op_index
+ uladv
)
5705 % linfo
.li_max_ops_per_insn
;
5707 state_machine_regs
.view
= 0;
5711 case DW_LNS_fixed_advance_pc
:
5712 SAFE_BYTE_GET_AND_INC (uladv
, data
, 2, end
);
5713 state_machine_regs
.address
+= uladv
;
5714 state_machine_regs
.op_index
= 0;
5715 /* Do NOT reset view. */
5718 case DW_LNS_set_prologue_end
:
5721 case DW_LNS_set_epilogue_begin
:
5724 case DW_LNS_set_isa
:
5725 READ_ULEB (uladv
, data
, end
);
5726 printf (_(" Set ISA to %lu\n"), uladv
);
5730 printf (_(" Unknown opcode %d with operands: "), op_code
);
5732 if (standard_opcodes
!= NULL
)
5733 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
5737 READ_ULEB (val
, data
, end
);
5738 printf ("%#" PRIx64
"%s", val
, i
== 1 ? "" : ", ");
5744 /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row
5745 to the DWARF address/line matrix. */
5746 if ((is_special_opcode
) || (xop
== -DW_LNE_end_sequence
)
5747 || (xop
== DW_LNS_copy
))
5749 const unsigned int MAX_FILENAME_LENGTH
= 35;
5750 char *fileName
= NULL
;
5751 char *newFileName
= NULL
;
5752 size_t fileNameLength
;
5756 unsigned indx
= state_machine_regs
.file
;
5758 if (linfo
.li_version
< 5)
5761 if (indx
>= n_files
)
5763 warn (_("file index %u >= number of files %u\n"),
5765 fileName
= _("<corrupt>");
5768 fileName
= (char *) file_table
[indx
].name
;
5771 fileName
= _("<unknown>");
5773 fileNameLength
= strlen (fileName
);
5774 newFileName
= fileName
;
5775 if (fileNameLength
> MAX_FILENAME_LENGTH
&& !do_wide
)
5777 newFileName
= (char *) xmalloc (MAX_FILENAME_LENGTH
+ 1);
5778 /* Truncate file name */
5779 memcpy (newFileName
,
5780 fileName
+ fileNameLength
- MAX_FILENAME_LENGTH
,
5781 MAX_FILENAME_LENGTH
);
5782 newFileName
[MAX_FILENAME_LENGTH
] = 0;
5785 /* A row with end_seq set to true has a meaningful address, but
5786 the other information in the same row is not significant.
5787 In such a row, print line as "-", and don't print
5789 if (!do_wide
|| fileNameLength
<= MAX_FILENAME_LENGTH
)
5791 if (linfo
.li_max_ops_per_insn
== 1)
5793 if (xop
== -DW_LNE_end_sequence
)
5794 printf ("%-31s %11s %#18" PRIx64
,
5796 state_machine_regs
.address
);
5798 printf ("%-31s %11d %#18" PRIx64
,
5799 newFileName
, state_machine_regs
.line
,
5800 state_machine_regs
.address
);
5804 if (xop
== -DW_LNE_end_sequence
)
5805 printf ("%-31s %11s %#18" PRIx64
"[%d]",
5807 state_machine_regs
.address
,
5808 state_machine_regs
.op_index
);
5810 printf ("%-31s %11d %#18" PRIx64
"[%d]",
5811 newFileName
, state_machine_regs
.line
,
5812 state_machine_regs
.address
,
5813 state_machine_regs
.op_index
);
5818 if (linfo
.li_max_ops_per_insn
== 1)
5820 if (xop
== -DW_LNE_end_sequence
)
5821 printf ("%s %11s %#18" PRIx64
,
5823 state_machine_regs
.address
);
5825 printf ("%s %11d %#18" PRIx64
,
5826 newFileName
, state_machine_regs
.line
,
5827 state_machine_regs
.address
);
5831 if (xop
== -DW_LNE_end_sequence
)
5832 printf ("%s %11s %#18" PRIx64
"[%d]",
5834 state_machine_regs
.address
,
5835 state_machine_regs
.op_index
);
5837 printf ("%s %11d %#18" PRIx64
"[%d]",
5838 newFileName
, state_machine_regs
.line
,
5839 state_machine_regs
.address
,
5840 state_machine_regs
.op_index
);
5844 if (xop
!= -DW_LNE_end_sequence
)
5846 if (state_machine_regs
.view
)
5847 printf (" %6u", state_machine_regs
.view
);
5851 if (state_machine_regs
.is_stmt
)
5856 state_machine_regs
.view
++;
5858 if (xop
== -DW_LNE_end_sequence
)
5860 reset_state_machine (linfo
.li_default_is_stmt
);
5864 if (newFileName
!= fileName
)
5876 if (directory_table
)
5878 free (directory_table
);
5879 directory_table
= NULL
;
5890 display_debug_lines (struct dwarf_section
*section
, void *file
)
5892 unsigned char *data
= section
->start
;
5893 unsigned char *end
= data
+ section
->size
;
5895 int retValDecoded
= 1;
5897 if (do_debug_lines
== 0)
5898 do_debug_lines
|= FLAG_DEBUG_LINES_RAW
;
5900 if (do_debug_lines
& FLAG_DEBUG_LINES_RAW
)
5901 retValRaw
= display_debug_lines_raw (section
, data
, end
, file
);
5903 if (do_debug_lines
& FLAG_DEBUG_LINES_DECODED
)
5904 retValDecoded
= display_debug_lines_decoded (section
, data
, data
, end
, file
);
5906 if (!retValRaw
|| !retValDecoded
)
5913 find_debug_info_for_offset (uint64_t offset
)
5917 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
5920 for (i
= 0; i
< num_debug_info_entries
; i
++)
5921 if (debug_information
[i
].cu_offset
== offset
)
5922 return debug_information
+ i
;
5928 get_gdb_index_symbol_kind_name (gdb_index_symbol_kind kind
)
5930 /* See gdb/gdb-index.h. */
5931 static const char * const kinds
[] =
5943 return _ (kinds
[kind
]);
5947 display_debug_pubnames_worker (struct dwarf_section
*section
,
5948 void *file ATTRIBUTE_UNUSED
,
5951 DWARF2_Internal_PubNames names
;
5952 unsigned char *start
= section
->start
;
5953 unsigned char *end
= start
+ section
->size
;
5955 /* It does not matter if this load fails,
5956 we test for that later on. */
5957 load_debug_info (file
);
5959 introduce (section
, false);
5963 unsigned char *data
;
5964 unsigned long sec_off
= start
- section
->start
;
5965 unsigned int offset_size
;
5967 SAFE_BYTE_GET_AND_INC (names
.pn_length
, start
, 4, end
);
5968 if (names
.pn_length
== 0xffffffff)
5970 SAFE_BYTE_GET_AND_INC (names
.pn_length
, start
, 8, end
);
5976 if (names
.pn_length
> (size_t) (end
- start
))
5978 warn (_("Debug info is corrupted, "
5979 "%s header at %#lx has length %#" PRIx64
"\n"),
5980 section
->name
, sec_off
, names
.pn_length
);
5985 start
+= names
.pn_length
;
5987 SAFE_BYTE_GET_AND_INC (names
.pn_version
, data
, 2, start
);
5988 SAFE_BYTE_GET_AND_INC (names
.pn_offset
, data
, offset_size
, start
);
5990 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
5991 && num_debug_info_entries
> 0
5992 && find_debug_info_for_offset (names
.pn_offset
) == NULL
)
5993 warn (_(".debug_info offset of %#" PRIx64
5994 " in %s section does not point to a CU header.\n"),
5995 names
.pn_offset
, section
->name
);
5997 SAFE_BYTE_GET_AND_INC (names
.pn_size
, data
, offset_size
, start
);
5999 printf (_(" Length: %" PRId64
"\n"),
6001 printf (_(" Version: %d\n"),
6003 printf (_(" Offset into .debug_info section: %#" PRIx64
"\n"),
6005 printf (_(" Size of area in .debug_info section: %" PRId64
"\n"),
6008 if (names
.pn_version
!= 2 && names
.pn_version
!= 3)
6010 static int warned
= 0;
6014 warn (_("Only DWARF 2 and 3 pubnames are currently supported\n"));
6022 printf (_("\n Offset Kind Name\n"));
6024 printf (_("\n Offset\tName\n"));
6031 SAFE_BYTE_GET_AND_INC (offset
, data
, offset_size
, start
);
6038 maxprint
= (start
- data
) - 1;
6042 unsigned int kind_data
;
6043 gdb_index_symbol_kind kind
;
6044 const char *kind_name
;
6047 SAFE_BYTE_GET_AND_INC (kind_data
, data
, 1, start
);
6049 /* GCC computes the kind as the upper byte in the CU index
6050 word, and then right shifts it by the CU index size.
6051 Left shift KIND to where the gdb-index.h accessor macros
6053 kind_data
<<= GDB_INDEX_CU_BITSIZE
;
6054 kind
= GDB_INDEX_SYMBOL_KIND_VALUE (kind_data
);
6055 kind_name
= get_gdb_index_symbol_kind_name (kind
);
6056 is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (kind_data
);
6057 printf (" %-6" PRIx64
" %s,%-10s %.*s\n",
6058 offset
, is_static
? _("s") : _("g"),
6059 kind_name
, (int) maxprint
, data
);
6062 printf (" %-6" PRIx64
"\t%.*s\n",
6063 offset
, (int) maxprint
, data
);
6065 data
+= strnlen ((char *) data
, maxprint
);
6078 display_debug_pubnames (struct dwarf_section
*section
, void *file
)
6080 return display_debug_pubnames_worker (section
, file
, 0);
6084 display_debug_gnu_pubnames (struct dwarf_section
*section
, void *file
)
6086 return display_debug_pubnames_worker (section
, file
, 1);
6090 display_debug_macinfo (struct dwarf_section
*section
,
6091 void *file ATTRIBUTE_UNUSED
)
6093 unsigned char *start
= section
->start
;
6094 unsigned char *end
= start
+ section
->size
;
6095 unsigned char *curr
= start
;
6096 enum dwarf_macinfo_record_type op
;
6098 introduce (section
, false);
6102 unsigned int lineno
;
6103 const unsigned char *string
;
6105 op
= (enum dwarf_macinfo_record_type
) *curr
;
6110 case DW_MACINFO_start_file
:
6112 unsigned int filenum
;
6114 READ_ULEB (lineno
, curr
, end
);
6115 READ_ULEB (filenum
, curr
, end
);
6116 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"),
6121 case DW_MACINFO_end_file
:
6122 printf (_(" DW_MACINFO_end_file\n"));
6125 case DW_MACINFO_define
:
6126 READ_ULEB (lineno
, curr
, end
);
6128 curr
+= strnlen ((char *) string
, end
- string
);
6129 printf (_(" DW_MACINFO_define - lineno : %d macro : %*s\n"),
6130 lineno
, (int) (curr
- string
), string
);
6135 case DW_MACINFO_undef
:
6136 READ_ULEB (lineno
, curr
, end
);
6138 curr
+= strnlen ((char *) string
, end
- string
);
6139 printf (_(" DW_MACINFO_undef - lineno : %d macro : %*s\n"),
6140 lineno
, (int) (curr
- string
), string
);
6145 case DW_MACINFO_vendor_ext
:
6147 unsigned int constant
;
6149 READ_ULEB (constant
, curr
, end
);
6151 curr
+= strnlen ((char *) string
, end
- string
);
6152 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %*s\n"),
6153 constant
, (int) (curr
- string
), string
);
6164 /* Given LINE_OFFSET into the .debug_line section, attempt to return
6165 filename and dirname corresponding to file name table entry with index
6166 FILEIDX. Return NULL on failure. */
6168 static unsigned char *
6169 get_line_filename_and_dirname (uint64_t line_offset
,
6171 unsigned char **dir_name
)
6173 struct dwarf_section
*section
= &debug_displays
[line
].section
;
6174 unsigned char *hdrptr
, *dirtable
, *file_name
;
6175 unsigned int offset_size
;
6176 unsigned int version
, opcode_base
;
6177 uint64_t length
, diridx
;
6178 const unsigned char * end
;
6181 if (section
->start
== NULL
6182 || line_offset
>= section
->size
6186 hdrptr
= section
->start
+ line_offset
;
6187 end
= section
->start
+ section
->size
;
6189 SAFE_BYTE_GET_AND_INC (length
, hdrptr
, 4, end
);
6190 if (length
== 0xffffffff)
6192 /* This section is 64-bit DWARF 3. */
6193 SAFE_BYTE_GET_AND_INC (length
, hdrptr
, 8, end
);
6199 if (length
> (size_t) (end
- hdrptr
)
6200 || length
< 2 + offset_size
+ 1 + 3 + 1)
6202 end
= hdrptr
+ length
;
6204 SAFE_BYTE_GET_AND_INC (version
, hdrptr
, 2, end
);
6205 if (version
!= 2 && version
!= 3 && version
!= 4)
6207 hdrptr
+= offset_size
+ 1;/* Skip prologue_length and min_insn_length. */
6209 hdrptr
++; /* Skip max_ops_per_insn. */
6210 hdrptr
+= 3; /* Skip default_is_stmt, line_base, line_range. */
6212 SAFE_BYTE_GET_AND_INC (opcode_base
, hdrptr
, 1, end
);
6213 if (opcode_base
== 0
6214 || opcode_base
- 1 >= (size_t) (end
- hdrptr
))
6217 hdrptr
+= opcode_base
- 1;
6220 /* Skip over dirname table. */
6221 while (*hdrptr
!= '\0')
6223 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
);
6229 hdrptr
++; /* Skip the NUL at the end of the table. */
6231 /* Now skip over preceding filename table entries. */
6232 for (; hdrptr
< end
&& *hdrptr
!= '\0' && fileidx
> 1; fileidx
--)
6234 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
);
6237 SKIP_ULEB (hdrptr
, end
);
6238 SKIP_ULEB (hdrptr
, end
);
6239 SKIP_ULEB (hdrptr
, end
);
6241 if (hdrptr
>= end
|| *hdrptr
== '\0')
6245 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
);
6250 READ_ULEB (diridx
, hdrptr
, end
);
6253 for (; dirtable
< end
&& *dirtable
!= '\0' && diridx
> 1; diridx
--)
6255 dirtable
+= strnlen ((char *) dirtable
, end
- dirtable
);
6259 if (dirtable
>= end
|| *dirtable
== '\0')
6261 *dir_name
= dirtable
;
6266 display_debug_macro (struct dwarf_section
*section
,
6269 unsigned char *start
= section
->start
;
6270 unsigned char *end
= start
+ section
->size
;
6271 unsigned char *curr
= start
;
6272 unsigned char *extended_op_buf
[256];
6273 bool is_dwo
= false;
6274 const char *suffix
= strrchr (section
->name
, '.');
6276 if (suffix
&& strcmp (suffix
, ".dwo") == 0)
6279 load_debug_section_with_follow (str
, file
);
6280 load_debug_section_with_follow (line
, file
);
6281 load_debug_section_with_follow (str_index
, file
);
6283 introduce (section
, false);
6287 unsigned int lineno
, version
, flags
;
6288 unsigned int offset_size
;
6289 const unsigned char *string
;
6290 uint64_t line_offset
= 0, sec_offset
= curr
- start
, offset
;
6291 unsigned char **extended_ops
= NULL
;
6293 SAFE_BYTE_GET_AND_INC (version
, curr
, 2, end
);
6294 if (version
!= 4 && version
!= 5)
6296 error (_("Expected to find a version number of 4 or 5 in section %s but found %d instead\n"),
6297 section
->name
, version
);
6301 SAFE_BYTE_GET_AND_INC (flags
, curr
, 1, end
);
6302 offset_size
= (flags
& 1) ? 8 : 4;
6303 printf (_(" Offset: %#" PRIx64
"\n"), sec_offset
);
6304 printf (_(" Version: %d\n"), version
);
6305 printf (_(" Offset size: %d\n"), offset_size
);
6308 SAFE_BYTE_GET_AND_INC (line_offset
, curr
, offset_size
, end
);
6309 printf (_(" Offset into .debug_line: %#" PRIx64
"\n"),
6314 unsigned int i
, count
, op
;
6317 SAFE_BYTE_GET_AND_INC (count
, curr
, 1, end
);
6319 memset (extended_op_buf
, 0, sizeof (extended_op_buf
));
6320 extended_ops
= extended_op_buf
;
6323 printf (_(" Extension opcode arguments:\n"));
6324 for (i
= 0; i
< count
; i
++)
6326 SAFE_BYTE_GET_AND_INC (op
, curr
, 1, end
);
6327 extended_ops
[op
] = curr
;
6328 READ_ULEB (nargs
, curr
, end
);
6330 printf (_(" DW_MACRO_%02x has no arguments\n"), op
);
6333 printf (_(" DW_MACRO_%02x arguments: "), op
);
6334 for (n
= 0; n
< nargs
; n
++)
6338 SAFE_BYTE_GET_AND_INC (form
, curr
, 1, end
);
6339 printf ("%s%s", get_FORM_name (form
),
6340 n
== nargs
- 1 ? "\n" : ", ");
6350 case DW_FORM_block1
:
6351 case DW_FORM_block2
:
6352 case DW_FORM_block4
:
6354 case DW_FORM_string
:
6356 case DW_FORM_sec_offset
:
6359 error (_("Invalid extension opcode form %s\n"),
6360 get_FORM_name (form
));
6376 error (_(".debug_macro section not zero terminated\n"));
6380 SAFE_BYTE_GET_AND_INC (op
, curr
, 1, end
);
6386 case DW_MACRO_define
:
6387 READ_ULEB (lineno
, curr
, end
);
6389 curr
+= strnlen ((char *) string
, end
- string
);
6390 printf (_(" DW_MACRO_define - lineno : %d macro : %*s\n"),
6391 lineno
, (int) (curr
- string
), string
);
6396 case DW_MACRO_undef
:
6397 READ_ULEB (lineno
, curr
, end
);
6399 curr
+= strnlen ((char *) string
, end
- string
);
6400 printf (_(" DW_MACRO_undef - lineno : %d macro : %*s\n"),
6401 lineno
, (int) (curr
- string
), string
);
6406 case DW_MACRO_start_file
:
6408 unsigned int filenum
;
6409 unsigned char *file_name
= NULL
, *dir_name
= NULL
;
6411 READ_ULEB (lineno
, curr
, end
);
6412 READ_ULEB (filenum
, curr
, end
);
6414 if ((flags
& 2) == 0)
6415 error (_("DW_MACRO_start_file used, but no .debug_line offset provided.\n"));
6418 = get_line_filename_and_dirname (line_offset
, filenum
,
6420 if (file_name
== NULL
)
6421 printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d\n"),
6424 printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d filename: %s%s%s\n"),
6426 dir_name
!= NULL
? (const char *) dir_name
: "",
6427 dir_name
!= NULL
? "/" : "", file_name
);
6431 case DW_MACRO_end_file
:
6432 printf (_(" DW_MACRO_end_file\n"));
6435 case DW_MACRO_define_strp
:
6436 READ_ULEB (lineno
, curr
, end
);
6437 if (version
== 4 && is_dwo
)
6438 READ_ULEB (offset
, curr
, end
);
6440 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6441 string
= fetch_indirect_string (offset
);
6442 printf (_(" DW_MACRO_define_strp - lineno : %d macro : %s\n"),
6446 case DW_MACRO_undef_strp
:
6447 READ_ULEB (lineno
, curr
, end
);
6448 if (version
== 4 && is_dwo
)
6449 READ_ULEB (offset
, curr
, end
);
6451 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6452 string
= fetch_indirect_string (offset
);
6453 printf (_(" DW_MACRO_undef_strp - lineno : %d macro : %s\n"),
6457 case DW_MACRO_import
:
6458 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6459 printf (_(" DW_MACRO_import - offset : %#" PRIx64
"\n"),
6463 case DW_MACRO_define_sup
:
6464 READ_ULEB (lineno
, curr
, end
);
6465 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6466 printf (_(" DW_MACRO_define_sup - lineno : %d"
6467 " macro offset : %#" PRIx64
"\n"),
6471 case DW_MACRO_undef_sup
:
6472 READ_ULEB (lineno
, curr
, end
);
6473 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6474 printf (_(" DW_MACRO_undef_sup - lineno : %d"
6475 " macro offset : %#" PRIx64
"\n"),
6479 case DW_MACRO_import_sup
:
6480 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6481 printf (_(" DW_MACRO_import_sup - offset : %#" PRIx64
"\n"),
6485 case DW_MACRO_define_strx
:
6486 case DW_MACRO_undef_strx
:
6487 READ_ULEB (lineno
, curr
, end
);
6488 READ_ULEB (offset
, curr
, end
);
6489 string
= (const unsigned char *)
6490 fetch_indexed_string (offset
, NULL
, offset_size
, false, 0);
6491 if (op
== DW_MACRO_define_strx
)
6492 printf (" DW_MACRO_define_strx ");
6494 printf (" DW_MACRO_undef_strx ");
6496 printf (_("(with offset %#" PRIx64
") "), offset
);
6497 printf (_("lineno : %d macro : %s\n"),
6502 if (op
>= DW_MACRO_lo_user
&& op
<= DW_MACRO_hi_user
)
6504 printf (_(" <Target Specific macro op: %#x - UNHANDLED"), op
);
6508 if (extended_ops
== NULL
|| extended_ops
[op
] == NULL
)
6510 error (_(" Unknown macro opcode %02x seen\n"), op
);
6515 /* Skip over unhandled opcodes. */
6517 unsigned char *desc
= extended_ops
[op
];
6518 READ_ULEB (nargs
, desc
, end
);
6521 printf (_(" DW_MACRO_%02x\n"), op
);
6524 printf (_(" DW_MACRO_%02x -"), op
);
6525 for (n
= 0; n
< nargs
; n
++)
6529 /* DW_FORM_implicit_const is not expected here. */
6530 SAFE_BYTE_GET_AND_INC (val
, desc
, 1, end
);
6532 = read_and_display_attr_value (0, val
, 0,
6533 start
, curr
, end
, 0, 0,
6534 offset_size
, version
,
6553 display_debug_abbrev (struct dwarf_section
*section
,
6554 void *file ATTRIBUTE_UNUSED
)
6556 abbrev_entry
*entry
;
6557 unsigned char *start
= section
->start
;
6559 introduce (section
, false);
6563 uint64_t offset
= start
- section
->start
;
6564 abbrev_list
*list
= find_and_process_abbrev_set (section
, 0,
6565 section
->size
, offset
,
6570 if (list
->first_abbrev
)
6571 printf (_(" Number TAG (%#" PRIx64
")\n"), offset
);
6573 for (entry
= list
->first_abbrev
; entry
; entry
= entry
->next
)
6577 printf (" %ld %s [%s]\n",
6579 get_TAG_name (entry
->tag
),
6580 entry
->children
? _("has children") : _("no children"));
6582 for (attr
= entry
->first_attr
; attr
; attr
= attr
->next
)
6584 printf (" %-18s %s",
6585 get_AT_name (attr
->attribute
),
6586 get_FORM_name (attr
->form
));
6587 if (attr
->form
== DW_FORM_implicit_const
)
6588 printf (": %" PRId64
, attr
->implicit_const
);
6592 start
= list
->start_of_next_abbrevs
;
6593 free_abbrev_list (list
);
6602 /* Return true when ADDR is the maximum address, when addresses are
6603 POINTER_SIZE bytes long. */
6606 is_max_address (uint64_t addr
, unsigned int pointer_size
)
6608 uint64_t mask
= ~(~(uint64_t) 0 << 1 << (pointer_size
* 8 - 1));
6609 return ((addr
& mask
) == mask
);
6612 /* Display a view pair list starting at *VSTART_PTR and ending at
6613 VLISTEND within SECTION. */
6616 display_view_pair_list (struct dwarf_section
*section
,
6617 unsigned char **vstart_ptr
,
6618 unsigned int debug_info_entry
,
6619 unsigned char *vlistend
)
6621 unsigned char *vstart
= *vstart_ptr
;
6622 unsigned char *section_end
= section
->start
+ section
->size
;
6623 unsigned int pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
6625 if (vlistend
< section_end
)
6626 section_end
= vlistend
;
6630 while (vstart
< section_end
)
6632 uint64_t off
= vstart
- section
->start
;
6633 uint64_t vbegin
, vend
;
6635 READ_ULEB (vbegin
, vstart
, section_end
);
6636 if (vstart
== section_end
)
6639 READ_ULEB (vend
, vstart
, section_end
);
6640 printf (" %8.8" PRIx64
" ", off
);
6642 print_view (vbegin
, pointer_size
);
6643 print_view (vend
, pointer_size
);
6644 printf (_("location view pair\n"));
6648 *vstart_ptr
= vstart
;
6651 /* Display a location list from a normal (ie, non-dwo) .debug_loc section. */
6654 display_loc_list (struct dwarf_section
*section
,
6655 unsigned char **start_ptr
,
6656 unsigned int debug_info_entry
,
6658 uint64_t base_address
,
6659 unsigned char **vstart_ptr
,
6662 unsigned char *start
= *start_ptr
, *vstart
= *vstart_ptr
;
6663 unsigned char *section_end
= section
->start
+ section
->size
;
6665 unsigned int pointer_size
;
6666 unsigned int offset_size
;
6670 unsigned short length
;
6671 int need_frame_base
;
6673 if (debug_info_entry
>= num_debug_info_entries
)
6675 warn (_("No debug information available for loc lists of entry: %u\n"),
6680 cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
6681 pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
6682 offset_size
= debug_information
[debug_info_entry
].offset_size
;
6683 dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
6685 if (pointer_size
< 2 || pointer_size
> 8)
6687 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
6688 pointer_size
, debug_info_entry
);
6694 uint64_t off
= offset
+ (start
- *start_ptr
);
6695 uint64_t vbegin
= -1, vend
= -1;
6697 if (2 * pointer_size
> (size_t) (section_end
- start
))
6699 warn (_("Location list starting at offset %#" PRIx64
6700 " is not terminated.\n"), offset
);
6707 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, section_end
);
6708 SAFE_BYTE_GET_AND_INC (end
, start
, pointer_size
, section_end
);
6710 if (begin
== 0 && end
== 0)
6712 /* PR 18374: In a object file we can have a location list that
6713 starts with a begin and end of 0 because there are relocations
6714 that need to be applied to the addresses. Actually applying
6715 the relocations now does not help as they will probably resolve
6716 to 0, since the object file has not been fully linked. Real
6717 end of list markers will not have any relocations against them. */
6718 if (! reloc_at (section
, off
)
6719 && ! reloc_at (section
, off
+ pointer_size
))
6721 printf (_("<End of list>\n"));
6726 /* Check base address specifiers. */
6727 if (is_max_address (begin
, pointer_size
)
6728 && !is_max_address (end
, pointer_size
))
6731 print_hex (begin
, pointer_size
);
6732 print_hex (end
, pointer_size
);
6733 printf (_("(base address)\n"));
6739 off
= offset
+ (vstart
- *start_ptr
);
6741 READ_ULEB (vbegin
, vstart
, section_end
);
6742 print_view (vbegin
, pointer_size
);
6744 READ_ULEB (vend
, vstart
, section_end
);
6745 print_view (vend
, pointer_size
);
6747 printf (_("views at %8.8" PRIx64
" for:\n %*s "), off
, 8, "");
6750 if (2 > (size_t) (section_end
- start
))
6752 warn (_("Location list starting at offset %#" PRIx64
6753 " is not terminated.\n"), offset
);
6757 SAFE_BYTE_GET_AND_INC (length
, start
, 2, section_end
);
6759 if (length
> (size_t) (section_end
- start
))
6761 warn (_("Location list starting at offset %#" PRIx64
6762 " is not terminated.\n"), offset
);
6766 print_hex (begin
+ base_address
, pointer_size
);
6767 print_hex (end
+ base_address
, pointer_size
);
6770 need_frame_base
= decode_location_expression (start
,
6775 cu_offset
, section
);
6778 if (need_frame_base
&& !has_frame_base
)
6779 printf (_(" [without DW_AT_frame_base]"));
6781 if (begin
== end
&& vbegin
== vend
)
6782 fputs (_(" (start == end)"), stdout
);
6783 else if (begin
> end
|| (begin
== end
&& vbegin
> vend
))
6784 fputs (_(" (start > end)"), stdout
);
6792 *vstart_ptr
= vstart
;
6795 /* Display a location list from a normal (ie, non-dwo) .debug_loclists section. */
6798 display_loclists_list (struct dwarf_section
* section
,
6799 unsigned char ** start_ptr
,
6800 unsigned int debug_info_entry
,
6802 uint64_t base_address
,
6803 unsigned char ** vstart_ptr
,
6806 unsigned char *start
= *start_ptr
;
6807 unsigned char *vstart
= *vstart_ptr
;
6808 unsigned char *section_end
= section
->start
+ section
->size
;
6810 unsigned int pointer_size
;
6811 unsigned int offset_size
;
6812 unsigned int dwarf_version
;
6814 /* Initialize it due to a false compiler warning. */
6815 uint64_t begin
= -1, vbegin
= -1;
6816 uint64_t end
= -1, vend
= -1;
6818 int need_frame_base
;
6820 if (debug_info_entry
>= num_debug_info_entries
)
6822 warn (_("No debug information available for "
6823 "loclists lists of entry: %u\n"),
6828 cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
6829 pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
6830 offset_size
= debug_information
[debug_info_entry
].offset_size
;
6831 dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
6833 if (pointer_size
< 2 || pointer_size
> 8)
6835 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
6836 pointer_size
, debug_info_entry
);
6842 uint64_t off
= offset
+ (start
- *start_ptr
);
6843 enum dwarf_location_list_entry_type llet
;
6845 if (start
+ 1 > section_end
)
6847 warn (_("Location list starting at offset %#" PRIx64
6848 " is not terminated.\n"), offset
);
6855 SAFE_BYTE_GET_AND_INC (llet
, start
, 1, section_end
);
6857 if (vstart
&& (llet
== DW_LLE_offset_pair
6858 || llet
== DW_LLE_start_end
6859 || llet
== DW_LLE_start_length
))
6861 off
= offset
+ (vstart
- *start_ptr
);
6863 READ_ULEB (vbegin
, vstart
, section_end
);
6864 print_view (vbegin
, pointer_size
);
6866 READ_ULEB (vend
, vstart
, section_end
);
6867 print_view (vend
, pointer_size
);
6869 printf (_("views at %8.8" PRIx64
" for:\n %*s "), off
, 8, "");
6874 case DW_LLE_end_of_list
:
6875 printf (_("<End of list>\n"));
6878 case DW_LLE_base_addressx
:
6879 READ_ULEB (base_address
, start
, section_end
);
6880 print_hex (base_address
, pointer_size
);
6881 printf (_("(index into .debug_addr) "));
6882 base_address
= fetch_indexed_addr (base_address
, pointer_size
);
6883 print_hex (base_address
, pointer_size
);
6884 printf (_("(base address)\n"));
6887 case DW_LLE_startx_endx
:
6888 READ_ULEB (begin
, start
, section_end
);
6889 begin
= fetch_indexed_addr (begin
, pointer_size
);
6890 READ_ULEB (end
, start
, section_end
);
6891 end
= fetch_indexed_addr (end
, pointer_size
);
6894 case DW_LLE_startx_length
:
6895 READ_ULEB (begin
, start
, section_end
);
6896 begin
= fetch_indexed_addr (begin
, pointer_size
);
6897 READ_ULEB (end
, start
, section_end
);
6901 case DW_LLE_default_location
:
6905 case DW_LLE_offset_pair
:
6906 READ_ULEB (begin
, start
, section_end
);
6907 begin
+= base_address
;
6908 READ_ULEB (end
, start
, section_end
);
6909 end
+= base_address
;
6912 case DW_LLE_base_address
:
6913 SAFE_BYTE_GET_AND_INC (base_address
, start
, pointer_size
,
6915 print_hex (base_address
, pointer_size
);
6916 printf (_("(base address)\n"));
6919 case DW_LLE_start_end
:
6920 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, section_end
);
6921 SAFE_BYTE_GET_AND_INC (end
, start
, pointer_size
, section_end
);
6924 case DW_LLE_start_length
:
6925 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, section_end
);
6926 READ_ULEB (end
, start
, section_end
);
6930 #ifdef DW_LLE_view_pair
6931 case DW_LLE_view_pair
:
6933 printf (_("View pair entry in loclist with locviews attribute\n"));
6934 READ_ULEB (vbegin
, start
, section_end
);
6935 print_view (vbegin
, pointer_size
);
6937 READ_ULEB (vend
, start
, section_end
);
6938 print_view (vend
, pointer_size
);
6940 printf (_("views for:\n"));
6945 error (_("Invalid location list entry type %d\n"), llet
);
6949 if (llet
== DW_LLE_end_of_list
)
6952 if (llet
== DW_LLE_base_address
6953 || llet
== DW_LLE_base_addressx
)
6956 if (start
== section_end
)
6958 warn (_("Location list starting at offset %#" PRIx64
6959 " is not terminated.\n"), offset
);
6962 READ_ULEB (length
, start
, section_end
);
6964 if (length
> (size_t) (section_end
- start
))
6966 warn (_("Location list starting at offset %#" PRIx64
6967 " is not terminated.\n"), offset
);
6971 print_hex (begin
, pointer_size
);
6972 print_hex (end
, pointer_size
);
6975 need_frame_base
= decode_location_expression (start
,
6980 cu_offset
, section
);
6983 if (need_frame_base
&& !has_frame_base
)
6984 printf (_(" [without DW_AT_frame_base]"));
6986 if (begin
== end
&& vbegin
== vend
)
6987 fputs (_(" (start == end)"), stdout
);
6988 else if (begin
> end
|| (begin
== end
&& vbegin
> vend
))
6989 fputs (_(" (start > end)"), stdout
);
6997 if (vbegin
!= (uint64_t) -1 || vend
!= (uint64_t) -1)
6998 printf (_("Trailing view pair not used in a range"));
7001 *vstart_ptr
= vstart
;
7004 /* Print a .debug_addr table index in decimal, surrounded by square brackets,
7005 right-adjusted in a field of length LEN, and followed by a space. */
7008 print_addr_index (unsigned int idx
, unsigned int len
)
7010 static char buf
[15];
7011 snprintf (buf
, sizeof (buf
), "[%d]", idx
);
7012 printf ("%*s ", len
, buf
);
7015 /* Display a location list from a .dwo section. It uses address indexes rather
7016 than embedded addresses. This code closely follows display_loc_list, but the
7017 two are sufficiently different that combining things is very ugly. */
7020 display_loc_list_dwo (struct dwarf_section
*section
,
7021 unsigned char **start_ptr
,
7022 unsigned int debug_info_entry
,
7024 unsigned char **vstart_ptr
,
7027 unsigned char *start
= *start_ptr
, *vstart
= *vstart_ptr
;
7028 unsigned char *section_end
= section
->start
+ section
->size
;
7030 unsigned int pointer_size
;
7031 unsigned int offset_size
;
7034 unsigned short length
;
7035 int need_frame_base
;
7038 if (debug_info_entry
>= num_debug_info_entries
)
7040 warn (_("No debug information for loc lists of entry: %u\n"),
7045 cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
7046 pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
7047 offset_size
= debug_information
[debug_info_entry
].offset_size
;
7048 dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
7050 if (pointer_size
< 2 || pointer_size
> 8)
7052 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
7053 pointer_size
, debug_info_entry
);
7060 print_hex (offset
+ (start
- *start_ptr
), 4);
7062 if (start
>= section_end
)
7064 warn (_("Location list starting at offset %#" PRIx64
7065 " is not terminated.\n"), offset
);
7069 SAFE_BYTE_GET_AND_INC (entry_type
, start
, 1, section_end
);
7082 uint64_t off
= offset
+ (vstart
- *start_ptr
);
7084 READ_ULEB (view
, vstart
, section_end
);
7085 print_view (view
, 8);
7087 READ_ULEB (view
, vstart
, section_end
);
7088 print_view (view
, 8);
7090 printf (_("views at %8.8" PRIx64
" for:\n %*s "), off
, 8, "");
7098 case 0: /* A terminating entry. */
7100 *vstart_ptr
= vstart
;
7101 printf (_("<End of list>\n"));
7103 case 1: /* A base-address entry. */
7104 READ_ULEB (idx
, start
, section_end
);
7105 print_addr_index (idx
, 8);
7106 printf ("%*s", 9 + (vstart
? 2 * 6 : 0), "");
7107 printf (_("(base address selection entry)\n"));
7109 case 2: /* A start/end entry. */
7110 READ_ULEB (idx
, start
, section_end
);
7111 print_addr_index (idx
, 8);
7112 READ_ULEB (idx
, start
, section_end
);
7113 print_addr_index (idx
, 8);
7115 case 3: /* A start/length entry. */
7116 READ_ULEB (idx
, start
, section_end
);
7117 print_addr_index (idx
, 8);
7118 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
7119 printf ("%08x ", idx
);
7121 case 4: /* An offset pair entry. */
7122 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
7123 printf ("%08x ", idx
);
7124 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
7125 printf ("%08x ", idx
);
7128 warn (_("Unknown location list entry type 0x%x.\n"), entry_type
);
7130 *vstart_ptr
= vstart
;
7134 if (2 > (size_t) (section_end
- start
))
7136 warn (_("Location list starting at offset %#" PRIx64
7137 " is not terminated.\n"), offset
);
7141 SAFE_BYTE_GET_AND_INC (length
, start
, 2, section_end
);
7142 if (length
> (size_t) (section_end
- start
))
7144 warn (_("Location list starting at offset %#" PRIx64
7145 " is not terminated.\n"), offset
);
7150 need_frame_base
= decode_location_expression (start
,
7155 cu_offset
, section
);
7158 if (need_frame_base
&& !has_frame_base
)
7159 printf (_(" [without DW_AT_frame_base]"));
7167 *vstart_ptr
= vstart
;
7170 /* Sort array of indexes in ascending order of loc_offsets[idx] and
7173 static uint64_t *loc_offsets
, *loc_views
;
7176 loc_offsets_compar (const void *ap
, const void *bp
)
7178 uint64_t a
= loc_offsets
[*(const unsigned int *) ap
];
7179 uint64_t b
= loc_offsets
[*(const unsigned int *) bp
];
7181 int ret
= (a
> b
) - (b
> a
);
7185 a
= loc_views
[*(const unsigned int *) ap
];
7186 b
= loc_views
[*(const unsigned int *) bp
];
7188 ret
= (a
> b
) - (b
> a
);
7194 display_offset_entry_loclists (struct dwarf_section
*section
)
7196 unsigned char * start
= section
->start
;
7197 unsigned char * const end
= start
+ section
->size
;
7199 introduce (section
, false);
7204 unsigned short version
;
7205 unsigned char address_size
;
7206 unsigned char segment_selector_size
;
7207 uint32_t offset_entry_count
;
7211 printf (_("Table at Offset %#tx\n"), start
- section
->start
);
7213 SAFE_BYTE_GET_AND_INC (length
, start
, 4, end
);
7214 if (length
== 0xffffffff)
7217 SAFE_BYTE_GET_AND_INC (length
, start
, 8, end
);
7222 SAFE_BYTE_GET_AND_INC (version
, start
, 2, end
);
7223 SAFE_BYTE_GET_AND_INC (address_size
, start
, 1, end
);
7224 SAFE_BYTE_GET_AND_INC (segment_selector_size
, start
, 1, end
);
7225 SAFE_BYTE_GET_AND_INC (offset_entry_count
, start
, 4, end
);
7227 printf (_(" Length: %#" PRIx64
"\n"), length
);
7228 printf (_(" DWARF version: %u\n"), version
);
7229 printf (_(" Address size: %u\n"), address_size
);
7230 printf (_(" Segment size: %u\n"), segment_selector_size
);
7231 printf (_(" Offset entries: %u\n"), offset_entry_count
);
7235 warn (_("The %s section contains a corrupt or "
7236 "unsupported version number: %d.\n"),
7237 section
->name
, version
);
7241 if (segment_selector_size
!= 0)
7243 warn (_("The %s section contains an "
7244 "unsupported segment selector size: %d.\n"),
7245 section
->name
, segment_selector_size
);
7249 if (offset_entry_count
== 0)
7251 warn (_("The %s section contains a table without offset\n"),
7256 printf (_("\n Offset Entries starting at %#tx:\n"),
7257 start
- section
->start
);
7259 for (i
= 0; i
< offset_entry_count
; i
++)
7263 SAFE_BYTE_GET_AND_INC (entry
, start
, is_64bit
? 8 : 4, end
);
7264 printf (_(" [%6u] %#" PRIx64
"\n"), i
, entry
);
7271 for (j
= 1, i
= 0; i
< offset_entry_count
;)
7274 uint64_t base_address
= 0;
7277 uint64_t off
= start
- section
->start
;
7281 printf (_(" Offset Entry %u\n"), i
);
7288 SAFE_BYTE_GET_AND_INC (lle
, start
, 1, end
);
7292 case DW_LLE_end_of_list
:
7293 printf (_("<End of list>\n\n"));
7297 case DW_LLE_base_addressx
:
7298 READ_ULEB (base_address
, start
, end
);
7299 print_hex (base_address
, address_size
);
7300 printf (_("(index into .debug_addr) "));
7301 base_address
= fetch_indexed_addr (base_address
, address_size
);
7302 print_hex (base_address
, address_size
);
7303 printf (_("(base address)\n"));
7306 case DW_LLE_startx_endx
:
7307 READ_ULEB (begin
, start
, end
);
7308 begin
= fetch_indexed_addr (begin
, address_size
);
7309 READ_ULEB (finish
, start
, end
);
7310 finish
= fetch_indexed_addr (finish
, address_size
);
7313 case DW_LLE_startx_length
:
7314 READ_ULEB (begin
, start
, end
);
7315 begin
= fetch_indexed_addr (begin
, address_size
);
7316 READ_ULEB (finish
, start
, end
);
7320 case DW_LLE_offset_pair
:
7321 READ_ULEB (begin
, start
, end
);
7322 begin
+= base_address
;
7323 READ_ULEB (finish
, start
, end
);
7324 finish
+= base_address
;
7327 case DW_LLE_default_location
:
7331 case DW_LLE_base_address
:
7332 SAFE_BYTE_GET_AND_INC (base_address
, start
, address_size
, end
);
7333 print_hex (base_address
, address_size
);
7334 printf (_("(base address)\n"));
7337 case DW_LLE_start_end
:
7338 SAFE_BYTE_GET_AND_INC (begin
, start
, address_size
, end
);
7339 SAFE_BYTE_GET_AND_INC (finish
, start
, address_size
, end
);
7342 case DW_LLE_start_length
:
7343 SAFE_BYTE_GET_AND_INC (begin
, start
, address_size
, end
);
7344 READ_ULEB (finish
, start
, end
);
7349 error (_("Invalid location list entry type %d\n"), lle
);
7355 warn (_("Location list starting at offset %#" PRIx64
7356 " is not terminated.\n"), off
);
7360 print_hex (begin
, address_size
);
7361 print_hex (finish
, address_size
);
7363 if (begin
== finish
)
7364 fputs (_("(start == end)"), stdout
);
7365 else if (begin
> finish
)
7366 fputs (_("(start > end)"), stdout
);
7368 /* Read the counted location descriptions. */
7369 READ_ULEB (length
, start
, end
);
7371 if (length
> (size_t) (end
- start
))
7373 warn (_("Location list starting at offset %#" PRIx64
7374 " is not terminated.\n"), off
);
7378 (void) decode_location_expression (start
, address_size
, address_size
,
7379 version
, length
, 0, section
);
7386 while (start
< end
);
7392 display_debug_loc (struct dwarf_section
*section
, void *file
)
7394 unsigned char *start
= section
->start
, *vstart
= NULL
;
7396 unsigned char *section_begin
= start
;
7397 unsigned int num_loc_list
= 0;
7398 uint64_t last_offset
= 0;
7399 uint64_t last_view
= 0;
7400 unsigned int first
= 0;
7403 int seen_first_offset
= 0;
7404 int locs_sorted
= 1;
7405 unsigned char *next
= start
, *vnext
= vstart
;
7406 unsigned int *array
= NULL
;
7407 const char *suffix
= strrchr (section
->name
, '.');
7408 bool is_dwo
= false;
7409 int is_loclists
= strstr (section
->name
, "debug_loclists") != NULL
;
7410 uint64_t header_size
= 0;
7412 if (suffix
&& strcmp (suffix
, ".dwo") == 0)
7415 bytes
= section
->size
;
7419 printf (_("\nThe %s section is empty.\n"), section
->name
);
7425 unsigned char *hdrptr
= section_begin
;
7427 unsigned short ll_version
;
7428 unsigned char *end
= section_begin
+ section
->size
;
7429 unsigned char address_size
, segment_selector_size
;
7430 uint32_t offset_entry_count
;
7432 SAFE_BYTE_GET_AND_INC (ll_length
, hdrptr
, 4, end
);
7433 if (ll_length
== 0xffffffff)
7434 SAFE_BYTE_GET_AND_INC (ll_length
, hdrptr
, 8, end
);
7436 SAFE_BYTE_GET_AND_INC (ll_version
, hdrptr
, 2, end
);
7437 if (ll_version
!= 5)
7439 warn (_("The %s section contains corrupt or "
7440 "unsupported version number: %d.\n"),
7441 section
->name
, ll_version
);
7445 SAFE_BYTE_GET_AND_INC (address_size
, hdrptr
, 1, end
);
7447 SAFE_BYTE_GET_AND_INC (segment_selector_size
, hdrptr
, 1, end
);
7448 if (segment_selector_size
!= 0)
7450 warn (_("The %s section contains "
7451 "unsupported segment selector size: %d.\n"),
7452 section
->name
, segment_selector_size
);
7456 SAFE_BYTE_GET_AND_INC (offset_entry_count
, hdrptr
, 4, end
);
7458 if (offset_entry_count
!= 0)
7459 return display_offset_entry_loclists (section
);
7461 header_size
= hdrptr
- section_begin
;
7464 if (load_debug_info (file
) == 0)
7466 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
7471 /* Check the order of location list in .debug_info section. If
7472 offsets of location lists are in the ascending order, we can
7473 use `debug_information' directly. */
7474 for (i
= 0; i
< num_debug_info_entries
; i
++)
7478 num
= debug_information
[i
].num_loc_offsets
;
7479 if (num
> num_loc_list
)
7482 /* Check if we can use `debug_information' directly. */
7483 if (locs_sorted
&& num
!= 0)
7485 if (!seen_first_offset
)
7487 /* This is the first location list. */
7488 last_offset
= debug_information
[i
].loc_offsets
[0];
7489 last_view
= debug_information
[i
].loc_views
[0];
7491 seen_first_offset
= 1;
7497 for (; j
< num
; j
++)
7500 debug_information
[i
].loc_offsets
[j
]
7501 || (last_offset
== debug_information
[i
].loc_offsets
[j
]
7502 && last_view
> debug_information
[i
].loc_views
[j
]))
7507 last_offset
= debug_information
[i
].loc_offsets
[j
];
7508 last_view
= debug_information
[i
].loc_views
[j
];
7513 if (!seen_first_offset
)
7514 error (_("No location lists in .debug_info section!\n"));
7516 if (debug_information
[first
].num_loc_offsets
> 0
7517 && debug_information
[first
].loc_offsets
[0] != header_size
7518 && debug_information
[first
].loc_views
[0] != header_size
)
7519 warn (_("Location lists in %s section start at %#" PRIx64
7520 " rather than %#" PRIx64
"\n"),
7521 section
->name
, debug_information
[first
].loc_offsets
[0],
7525 array
= (unsigned int *) xcmalloc (num_loc_list
, sizeof (unsigned int));
7527 introduce (section
, false);
7529 if (reloc_at (section
, 0))
7530 printf (_(" Warning: This section has relocations - addresses seen here may not be accurate.\n\n"));
7532 printf (_(" Offset Begin End Expression\n"));
7534 for (i
= first
; i
< num_debug_info_entries
; i
++)
7536 uint64_t offset
= 0, voffset
= 0;
7537 uint64_t base_address
;
7543 for (k
= 0; k
< debug_information
[i
].num_loc_offsets
; k
++)
7545 loc_offsets
= debug_information
[i
].loc_offsets
;
7546 loc_views
= debug_information
[i
].loc_views
;
7547 qsort (array
, debug_information
[i
].num_loc_offsets
,
7548 sizeof (*array
), loc_offsets_compar
);
7551 /* .debug_loclists has a per-unit header.
7552 Update start if we are detecting it. */
7553 if (debug_information
[i
].dwarf_version
== 5)
7555 j
= locs_sorted
? 0 : array
[0];
7557 if (debug_information
[i
].num_loc_offsets
)
7558 offset
= debug_information
[i
].loc_offsets
[j
];
7560 if (debug_information
[i
].num_loc_views
)
7561 voffset
= debug_information
[i
].loc_views
[j
];
7563 /* Assume that the size of the header is constant across CUs. */
7564 if (((start
- section_begin
) + header_size
== offset
)
7565 || ((start
-section_begin
) + header_size
== voffset
))
7566 start
+= header_size
;
7569 int adjacent_view_loclists
= 1;
7570 for (k
= 0; k
< debug_information
[i
].num_loc_offsets
; k
++)
7572 j
= locs_sorted
? k
: array
[k
];
7574 && (debug_information
[i
].loc_offsets
[locs_sorted
7575 ? k
- 1 : array
[k
- 1]]
7576 == debug_information
[i
].loc_offsets
[j
])
7577 && (debug_information
[i
].loc_views
[locs_sorted
7578 ? k
- 1 : array
[k
- 1]]
7579 == debug_information
[i
].loc_views
[j
]))
7581 has_frame_base
= debug_information
[i
].have_frame_base
[j
];
7582 offset
= debug_information
[i
].loc_offsets
[j
];
7583 next
= section_begin
+ offset
;
7584 voffset
= debug_information
[i
].loc_views
[j
];
7585 if (voffset
!= (uint64_t) -1)
7586 vnext
= section_begin
+ voffset
;
7589 base_address
= debug_information
[i
].base_address
;
7591 if (vnext
&& vnext
< next
)
7594 display_view_pair_list (section
, &vstart
, i
, next
);
7601 if (vnext
&& vnext
< next
)
7602 warn (_("There is a hole [%#tx - %#" PRIx64
"]"
7603 " in %s section.\n"),
7604 start
- section_begin
, voffset
, section
->name
);
7606 warn (_("There is a hole [%#tx - %#" PRIx64
"]"
7607 " in %s section.\n"),
7608 start
- section_begin
, offset
, section
->name
);
7610 else if (start
> next
)
7611 warn (_("There is an overlap [%#tx - %#" PRIx64
"]"
7612 " in %s section.\n"),
7613 start
- section_begin
, offset
, section
->name
);
7617 if (offset
>= bytes
)
7619 warn (_("Offset %#" PRIx64
" is bigger than %s section size.\n"),
7620 offset
, section
->name
);
7624 if (vnext
&& voffset
>= bytes
)
7626 warn (_("View Offset %#" PRIx64
" is bigger than %s section size.\n"),
7627 voffset
, section
->name
);
7634 display_loc_list_dwo (section
, &start
, i
, offset
,
7635 &vstart
, has_frame_base
);
7637 display_loc_list (section
, &start
, i
, offset
, base_address
,
7638 &vstart
, has_frame_base
);
7643 warn (_("DWO is not yet supported.\n"));
7645 display_loclists_list (section
, &start
, i
, offset
, base_address
,
7646 &vstart
, has_frame_base
);
7649 /* FIXME: this arrangement is quite simplistic. Nothing
7650 requires locview lists to be adjacent to corresponding
7651 loclists, and a single loclist could be augmented by
7652 different locview lists, and vice-versa, unlikely as it
7653 is that it would make sense to do so. Hopefully we'll
7654 have view pair support built into loclists before we ever
7655 need to address all these possibilities. */
7656 if (adjacent_view_loclists
&& vnext
7657 && vnext
!= start
&& vstart
!= next
)
7659 adjacent_view_loclists
= 0;
7660 warn (_("Hole and overlap detection requires adjacent view lists and loclists.\n"));
7663 if (vnext
&& vnext
== start
)
7664 display_view_pair_list (section
, &start
, i
, vstart
);
7668 if (start
< section
->start
+ section
->size
)
7669 warn (ngettext ("There is %ld unused byte at the end of section %s\n",
7670 "There are %ld unused bytes at the end of section %s\n",
7671 (long) (section
->start
+ section
->size
- start
)),
7672 (long) (section
->start
+ section
->size
- start
), section
->name
);
7679 display_debug_str (struct dwarf_section
*section
,
7680 void *file ATTRIBUTE_UNUSED
)
7682 unsigned char *start
= section
->start
;
7683 uint64_t bytes
= section
->size
;
7684 uint64_t addr
= section
->address
;
7688 printf (_("\nThe %s section is empty.\n"), section
->name
);
7692 introduce (section
, false);
7700 lbytes
= (bytes
> 16 ? 16 : bytes
);
7702 printf (" 0x%8.8" PRIx64
" ", addr
);
7704 for (j
= 0; j
< 16; j
++)
7707 printf ("%2.2x", start
[j
]);
7715 for (j
= 0; j
< lbytes
; j
++)
7718 if (k
>= ' ' && k
< 0x80)
7737 display_debug_info (struct dwarf_section
*section
, void *file
)
7739 return process_debug_info (section
, file
, section
->abbrev_sec
, false, false);
7743 display_debug_types (struct dwarf_section
*section
, void *file
)
7745 return process_debug_info (section
, file
, section
->abbrev_sec
, false, true);
7749 display_trace_info (struct dwarf_section
*section
, void *file
)
7751 return process_debug_info (section
, file
, section
->abbrev_sec
, false, true);
7755 display_debug_aranges (struct dwarf_section
*section
,
7756 void *file ATTRIBUTE_UNUSED
)
7758 unsigned char *start
= section
->start
;
7759 unsigned char *end
= start
+ section
->size
;
7761 introduce (section
, false);
7763 /* It does not matter if this load fails,
7764 we test for that later on. */
7765 load_debug_info (file
);
7769 unsigned char *hdrptr
;
7770 DWARF2_Internal_ARange arange
;
7771 unsigned char *addr_ranges
;
7775 unsigned char address_size
;
7776 unsigned int offset_size
;
7777 unsigned char *end_ranges
;
7780 sec_off
= hdrptr
- section
->start
;
7782 SAFE_BYTE_GET_AND_INC (arange
.ar_length
, hdrptr
, 4, end
);
7783 if (arange
.ar_length
== 0xffffffff)
7785 SAFE_BYTE_GET_AND_INC (arange
.ar_length
, hdrptr
, 8, end
);
7791 if (arange
.ar_length
> (size_t) (end
- hdrptr
))
7793 warn (_("Debug info is corrupted, %s header at %#" PRIx64
7794 " has length %#" PRIx64
"\n"),
7795 section
->name
, sec_off
, arange
.ar_length
);
7798 end_ranges
= hdrptr
+ arange
.ar_length
;
7800 SAFE_BYTE_GET_AND_INC (arange
.ar_version
, hdrptr
, 2, end_ranges
);
7801 SAFE_BYTE_GET_AND_INC (arange
.ar_info_offset
, hdrptr
, offset_size
,
7804 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
7805 && num_debug_info_entries
> 0
7806 && find_debug_info_for_offset (arange
.ar_info_offset
) == NULL
)
7807 warn (_(".debug_info offset of %#" PRIx64
7808 " in %s section does not point to a CU header.\n"),
7809 arange
.ar_info_offset
, section
->name
);
7811 SAFE_BYTE_GET_AND_INC (arange
.ar_pointer_size
, hdrptr
, 1, end_ranges
);
7812 SAFE_BYTE_GET_AND_INC (arange
.ar_segment_size
, hdrptr
, 1, end_ranges
);
7814 if (arange
.ar_version
!= 2 && arange
.ar_version
!= 3)
7816 /* PR 19872: A version number of 0 probably means that there is
7817 padding at the end of the .debug_aranges section. Gold puts
7818 it there when performing an incremental link, for example.
7819 So do not generate a warning in this case. */
7820 if (arange
.ar_version
)
7821 warn (_("Only DWARF 2 and 3 aranges are currently supported.\n"));
7825 printf (_(" Length: %" PRId64
"\n"), arange
.ar_length
);
7826 printf (_(" Version: %d\n"), arange
.ar_version
);
7827 printf (_(" Offset into .debug_info: %#" PRIx64
"\n"),
7828 arange
.ar_info_offset
);
7829 printf (_(" Pointer Size: %d\n"), arange
.ar_pointer_size
);
7830 printf (_(" Segment Size: %d\n"), arange
.ar_segment_size
);
7832 address_size
= arange
.ar_pointer_size
+ arange
.ar_segment_size
;
7834 /* PR 17512: file: 001-108546-0.001:0.1. */
7835 if (address_size
== 0 || address_size
> 8)
7837 error (_("Invalid address size in %s section!\n"),
7842 /* The DWARF spec does not require that the address size be a power
7843 of two, but we do. This will have to change if we ever encounter
7844 an uneven architecture. */
7845 if ((address_size
& (address_size
- 1)) != 0)
7847 warn (_("Pointer size + Segment size is not a power of two.\n"));
7851 if (address_size
> 4)
7852 printf (_("\n Address Length\n"));
7854 printf (_("\n Address Length\n"));
7856 addr_ranges
= hdrptr
;
7858 /* Must pad to an alignment boundary that is twice the address size. */
7859 addr_ranges
+= (2 * address_size
- 1
7860 - (hdrptr
- start
- 1) % (2 * address_size
));
7862 while (2 * address_size
<= end_ranges
- addr_ranges
)
7864 SAFE_BYTE_GET_AND_INC (address
, addr_ranges
, address_size
,
7866 SAFE_BYTE_GET_AND_INC (length
, addr_ranges
, address_size
,
7869 print_hex (address
, address_size
);
7870 print_hex_ns (length
, address_size
);
7882 /* Comparison function for qsort. */
7884 comp_addr_base (const void * v0
, const void * v1
)
7886 debug_info
*info0
= *(debug_info
**) v0
;
7887 debug_info
*info1
= *(debug_info
**) v1
;
7888 return info0
->addr_base
- info1
->addr_base
;
7891 /* Display the debug_addr section. */
7893 display_debug_addr (struct dwarf_section
*section
,
7896 debug_info
**debug_addr_info
;
7897 unsigned char *entry
;
7901 unsigned char * header
;
7903 if (section
->size
== 0)
7905 printf (_("\nThe %s section is empty.\n"), section
->name
);
7909 if (load_debug_info (file
) == 0)
7911 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
7916 introduce (section
, false);
7918 /* PR 17531: file: cf38d01b.
7919 We use xcalloc because a corrupt file may not have initialised all of the
7920 fields in the debug_info structure, which means that the sort below might
7921 try to move uninitialised data. */
7922 debug_addr_info
= (debug_info
**) xcalloc ((num_debug_info_entries
+ 1),
7923 sizeof (debug_info
*));
7926 for (i
= 0; i
< num_debug_info_entries
; i
++)
7927 if (debug_information
[i
].addr_base
!= DEBUG_INFO_UNAVAILABLE
)
7929 /* PR 17531: file: cf38d01b. */
7930 if (debug_information
[i
].addr_base
>= section
->size
)
7931 warn (_("Corrupt address base (%#" PRIx64
")"
7932 " found in debug section %u\n"),
7933 debug_information
[i
].addr_base
, i
);
7935 debug_addr_info
[count
++] = debug_information
+ i
;
7938 /* Add a sentinel to make iteration convenient. */
7939 debug_addr_info
[count
] = (debug_info
*) xmalloc (sizeof (debug_info
));
7940 debug_addr_info
[count
]->addr_base
= section
->size
;
7941 qsort (debug_addr_info
, count
, sizeof (debug_info
*), comp_addr_base
);
7943 header
= section
->start
;
7944 for (i
= 0; i
< count
; i
++)
7947 unsigned int address_size
= debug_addr_info
[i
]->pointer_size
;
7949 printf (_(" For compilation unit at offset %#" PRIx64
":\n"),
7950 debug_addr_info
[i
]->cu_offset
);
7952 printf (_("\tIndex\tAddress\n"));
7953 entry
= section
->start
+ debug_addr_info
[i
]->addr_base
;
7954 if (debug_addr_info
[i
]->dwarf_version
>= 5)
7956 size_t header_size
= entry
- header
;
7957 unsigned char *curr_header
= header
;
7960 int segment_selector_size
;
7962 if (header_size
!= 8 && header_size
!= 16)
7964 warn (_("Corrupt %s section: expecting header size of 8 or 16, but found %zd instead\n"),
7965 section
->name
, header_size
);
7969 SAFE_BYTE_GET_AND_INC (length
, curr_header
, 4, entry
);
7970 if (length
== 0xffffffff)
7971 SAFE_BYTE_GET_AND_INC (length
, curr_header
, 8, entry
);
7972 if (length
> (size_t) (section
->start
+ section
->size
- curr_header
)
7973 || length
< (size_t) (entry
- curr_header
))
7975 warn (_("Corrupt %s section: unit_length field of %#" PRIx64
7976 " is invalid\n"), section
->name
, length
);
7979 end
= curr_header
+ length
;
7980 SAFE_BYTE_GET_AND_INC (version
, curr_header
, 2, entry
);
7982 warn (_("Corrupt %s section: expecting version number 5 in header but found %d instead\n"),
7983 section
->name
, version
);
7985 SAFE_BYTE_GET_AND_INC (address_size
, curr_header
, 1, entry
);
7986 SAFE_BYTE_GET_AND_INC (segment_selector_size
, curr_header
, 1, entry
);
7987 address_size
+= segment_selector_size
;
7990 end
= section
->start
+ debug_addr_info
[i
+ 1]->addr_base
;
7995 if (address_size
< 1 || address_size
> sizeof (uint64_t))
7997 warn (_("Corrupt %s section: address size (%x) is wrong"),
7998 section
->name
, address_size
);
8002 while ((size_t) (end
- entry
) >= address_size
)
8004 uint64_t base
= byte_get (entry
, address_size
);
8005 printf (_("\t%d:\t"), idx
);
8006 print_hex_ns (base
, address_size
);
8008 entry
+= address_size
;
8014 free (debug_addr_info
);
8018 /* Display the .debug_str_offsets and .debug_str_offsets.dwo sections. */
8021 display_debug_str_offsets (struct dwarf_section
*section
,
8022 void *file ATTRIBUTE_UNUSED
)
8026 if (section
->size
== 0)
8028 printf (_("\nThe %s section is empty.\n"), section
->name
);
8032 unsigned char *start
= section
->start
;
8033 unsigned char *end
= start
+ section
->size
;
8034 unsigned char *curr
= start
;
8035 uint64_t debug_str_offsets_hdr_len
;
8037 const char *suffix
= strrchr (section
->name
, '.');
8038 bool dwo
= suffix
&& strcmp (suffix
, ".dwo") == 0;
8041 load_debug_section_with_follow (str_dwo
, file
);
8043 load_debug_section_with_follow (str
, file
);
8045 introduce (section
, false);
8050 uint64_t entry_length
;
8052 SAFE_BYTE_GET_AND_INC (length
, curr
, 4, end
);
8053 /* FIXME: We assume that this means 64-bit DWARF is being used. */
8054 if (length
== 0xffffffff)
8056 SAFE_BYTE_GET_AND_INC (length
, curr
, 8, end
);
8058 debug_str_offsets_hdr_len
= 16;
8063 debug_str_offsets_hdr_len
= 8;
8066 unsigned char *entries_end
;
8069 /* This is probably an old style .debug_str_offset section which
8070 just contains offsets and no header (and the first offset is 0). */
8071 length
= section
->size
;
8072 curr
= section
->start
;
8075 printf (_(" Length: %#" PRIx64
"\n"), length
);
8076 printf (_(" Index Offset [String]\n"));
8080 if (length
<= (size_t) (end
- curr
))
8081 entries_end
= curr
+ length
;
8084 warn (_("Section %s is too small %#" PRIx64
"\n"),
8085 section
->name
, section
->size
);
8090 SAFE_BYTE_GET_AND_INC (version
, curr
, 2, entries_end
);
8092 warn (_("Unexpected version number in str_offset header: %#x\n"), version
);
8095 SAFE_BYTE_GET_AND_INC (padding
, curr
, 2, entries_end
);
8097 warn (_("Unexpected value in str_offset header's padding field: %#x\n"), padding
);
8099 printf (_(" Length: %#" PRIx64
"\n"), length
);
8100 printf (_(" Version: %#x\n"), version
);
8101 printf (_(" Index Offset [String]\n"));
8104 for (idx
= 0; curr
< entries_end
; idx
++)
8107 const unsigned char * string
;
8109 if ((size_t) (entries_end
- curr
) < entry_length
)
8110 /* Not enough space to read one entry_length, give up. */
8113 SAFE_BYTE_GET_AND_INC (offset
, curr
, entry_length
, entries_end
);
8115 string
= (const unsigned char *)
8116 fetch_indexed_string (idx
, NULL
, entry_length
, dwo
, debug_str_offsets_hdr_len
);
8118 string
= fetch_indirect_string (offset
);
8120 printf (" %8lu ", idx
);
8121 print_hex (offset
, entry_length
);
8122 printf (" %s\n", string
);
8129 /* Each debug_information[x].range_lists[y] gets this representation for
8130 sorting purposes. */
8134 /* The debug_information[x].range_lists[y] value. */
8135 uint64_t ranges_offset
;
8137 /* Original debug_information to find parameters of the data. */
8138 debug_info
*debug_info_p
;
8141 /* Sort struct range_entry in ascending order of its RANGES_OFFSET. */
8144 range_entry_compar (const void *ap
, const void *bp
)
8146 const struct range_entry
*a_re
= (const struct range_entry
*) ap
;
8147 const struct range_entry
*b_re
= (const struct range_entry
*) bp
;
8148 const uint64_t a
= a_re
->ranges_offset
;
8149 const uint64_t b
= b_re
->ranges_offset
;
8151 return (a
> b
) - (b
> a
);
8155 display_debug_ranges_list (unsigned char * start
,
8156 unsigned char * finish
,
8157 unsigned int pointer_size
,
8159 uint64_t base_address
)
8161 while (start
< finish
)
8166 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
8167 if (start
>= finish
)
8169 SAFE_SIGNED_BYTE_GET_AND_INC (end
, start
, pointer_size
, finish
);
8172 print_hex (offset
, 4);
8174 if (begin
== 0 && end
== 0)
8176 printf (_("<End of list>\n"));
8180 /* Check base address specifiers. */
8181 if (is_max_address (begin
, pointer_size
)
8182 && !is_max_address (end
, pointer_size
))
8185 print_hex (begin
, pointer_size
);
8186 print_hex (end
, pointer_size
);
8187 printf ("(base address)\n");
8191 print_hex (begin
+ base_address
, pointer_size
);
8192 print_hex_ns (end
+ base_address
, pointer_size
);
8195 fputs (_(" (start == end)"), stdout
);
8196 else if (begin
> end
)
8197 fputs (_(" (start > end)"), stdout
);
8203 static unsigned char *
8204 display_debug_rnglists_list (unsigned char * start
,
8205 unsigned char * finish
,
8206 unsigned int pointer_size
,
8208 uint64_t base_address
,
8211 unsigned char *next
= start
;
8215 uint64_t off
= offset
+ (start
- next
);
8216 enum dwarf_range_list_entry rlet
;
8217 /* Initialize it due to a false compiler warning. */
8218 uint64_t begin
= -1, length
, end
= -1;
8220 if (start
>= finish
)
8222 warn (_("Range list starting at offset %#" PRIx64
8223 " is not terminated.\n"), offset
);
8230 SAFE_BYTE_GET_AND_INC (rlet
, start
, 1, finish
);
8234 case DW_RLE_end_of_list
:
8235 printf (_("<End of list>\n"));
8237 case DW_RLE_base_addressx
:
8238 READ_ULEB (base_address
, start
, finish
);
8239 print_hex (base_address
, pointer_size
);
8240 printf (_("(base address index) "));
8241 base_address
= fetch_indexed_addr ((base_address
* pointer_size
) + addr_base
,
8243 print_hex (base_address
, pointer_size
);
8244 printf (_("(base address)\n"));
8246 case DW_RLE_startx_endx
:
8247 READ_ULEB (begin
, start
, finish
);
8248 READ_ULEB (end
, start
, finish
);
8249 begin
= fetch_indexed_addr ((begin
* pointer_size
) + addr_base
,
8251 end
= fetch_indexed_addr ((begin
* pointer_size
) + addr_base
,
8254 case DW_RLE_startx_length
:
8255 READ_ULEB (begin
, start
, finish
);
8256 READ_ULEB (length
, start
, finish
);
8257 begin
= fetch_indexed_addr ((begin
* pointer_size
) + addr_base
,
8259 end
= begin
+ length
;
8261 case DW_RLE_offset_pair
:
8262 READ_ULEB (begin
, start
, finish
);
8263 READ_ULEB (end
, start
, finish
);
8265 case DW_RLE_base_address
:
8266 SAFE_BYTE_GET_AND_INC (base_address
, start
, pointer_size
, finish
);
8267 print_hex (base_address
, pointer_size
);
8268 printf (_("(base address)\n"));
8270 case DW_RLE_start_end
:
8271 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
8272 SAFE_BYTE_GET_AND_INC (end
, start
, pointer_size
, finish
);
8274 case DW_RLE_start_length
:
8275 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
8276 READ_ULEB (length
, start
, finish
);
8277 end
= begin
+ length
;
8280 error (_("Invalid range list entry type %d\n"), rlet
);
8281 rlet
= DW_RLE_end_of_list
;
8285 if (rlet
== DW_RLE_end_of_list
)
8287 if (rlet
== DW_RLE_base_address
|| rlet
== DW_RLE_base_addressx
)
8290 /* Only a DW_RLE_offset_pair needs the base address added. */
8291 if (rlet
== DW_RLE_offset_pair
)
8293 begin
+= base_address
;
8294 end
+= base_address
;
8297 print_hex (begin
, pointer_size
);
8298 print_hex (end
, pointer_size
);
8301 fputs (_(" (start == end)"), stdout
);
8302 else if (begin
> end
)
8303 fputs (_(" (start > end)"), stdout
);
8312 display_debug_rnglists_unit_header (struct dwarf_section
* section
,
8313 uint64_t * unit_offset
,
8314 unsigned char * poffset_size
)
8316 uint64_t start_offset
= *unit_offset
;
8317 unsigned char * p
= section
->start
+ start_offset
;
8318 unsigned char * finish
= section
->start
+ section
->size
;
8319 uint64_t initial_length
;
8320 unsigned char segment_selector_size
;
8321 unsigned int offset_entry_count
;
8323 unsigned short version
;
8324 unsigned char address_size
= 0;
8325 unsigned char offset_size
;
8327 /* Get and check the length of the block. */
8328 SAFE_BYTE_GET_AND_INC (initial_length
, p
, 4, finish
);
8330 if (initial_length
== 0xffffffff)
8332 /* This section is 64-bit DWARF 3. */
8333 SAFE_BYTE_GET_AND_INC (initial_length
, p
, 8, finish
);
8334 *poffset_size
= offset_size
= 8;
8337 *poffset_size
= offset_size
= 4;
8339 if (initial_length
> (size_t) (finish
- p
))
8341 /* If the length field has a relocation against it, then we should
8342 not complain if it is inaccurate (and probably negative).
8343 It is copied from .debug_line handling code. */
8344 if (reloc_at (section
, (p
- section
->start
) - offset_size
))
8345 initial_length
= finish
- p
;
8348 warn (_("The length field (%#" PRIx64
8349 ") in the debug_rnglists header is wrong"
8350 " - the section is too small\n"),
8356 /* Report the next unit offset to the caller. */
8357 *unit_offset
= (p
- section
->start
) + initial_length
;
8359 /* Get the other fields in the header. */
8360 SAFE_BYTE_GET_AND_INC (version
, p
, 2, finish
);
8361 SAFE_BYTE_GET_AND_INC (address_size
, p
, 1, finish
);
8362 SAFE_BYTE_GET_AND_INC (segment_selector_size
, p
, 1, finish
);
8363 SAFE_BYTE_GET_AND_INC (offset_entry_count
, p
, 4, finish
);
8365 printf (_(" Table at Offset: %#" PRIx64
":\n"), start_offset
);
8366 printf (_(" Length: %#" PRIx64
"\n"), initial_length
);
8367 printf (_(" DWARF version: %u\n"), version
);
8368 printf (_(" Address size: %u\n"), address_size
);
8369 printf (_(" Segment size: %u\n"), segment_selector_size
);
8370 printf (_(" Offset entries: %u\n"), offset_entry_count
);
8372 /* Check the fields. */
8373 if (segment_selector_size
!= 0)
8375 warn (_("The %s section contains "
8376 "unsupported segment selector size: %d.\n"),
8377 section
->name
, segment_selector_size
);
8383 warn (_("Only DWARF version 5+ debug_rnglists info "
8384 "is currently supported.\n"));
8388 if (offset_entry_count
!= 0)
8390 printf (_("\n Offsets starting at %#tx:\n"), p
- section
->start
);
8392 for (i
= 0; i
< offset_entry_count
; i
++)
8396 SAFE_BYTE_GET_AND_INC (entry
, p
, offset_size
, finish
);
8397 printf (_(" [%6u] %#" PRIx64
"\n"), i
, entry
);
8405 is_range_list_for_this_section (bool is_rnglists
, unsigned int version
)
8407 if (is_rnglists
&& version
> 4)
8410 if (! is_rnglists
&& version
< 5)
8417 display_debug_ranges (struct dwarf_section
*section
,
8418 void *file ATTRIBUTE_UNUSED
)
8420 unsigned char *start
= section
->start
;
8421 unsigned char *last_start
= start
;
8422 uint64_t bytes
= section
->size
;
8423 unsigned char *section_begin
= start
;
8424 unsigned char *finish
= start
+ bytes
;
8425 unsigned int num_range_list
, i
;
8426 struct range_entry
*range_entries
;
8427 struct range_entry
*range_entry_fill
;
8428 bool is_rnglists
= strstr (section
->name
, "debug_rnglists") != NULL
;
8429 uint64_t last_offset
= 0;
8430 uint64_t next_rnglists_cu_offset
= 0;
8431 unsigned char offset_size
;
8435 printf (_("\nThe %s section is empty.\n"), section
->name
);
8439 introduce (section
, false);
8441 if (load_debug_info (file
) == 0)
8443 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
8449 for (i
= 0; i
< num_debug_info_entries
; i
++)
8450 if (is_range_list_for_this_section (is_rnglists
, debug_information
[i
].dwarf_version
))
8451 num_range_list
+= debug_information
[i
].num_range_lists
;
8453 if (num_range_list
== 0)
8455 /* This can happen when the file was compiled with -gsplit-debug
8456 which removes references to range lists from the primary .o file. */
8457 printf (_("No range lists referenced by .debug_info section.\n"));
8461 range_entry_fill
= range_entries
= XNEWVEC (struct range_entry
, num_range_list
);
8463 for (i
= 0; i
< num_debug_info_entries
; i
++)
8465 debug_info
*debug_info_p
= &debug_information
[i
];
8468 for (j
= 0; j
< debug_info_p
->num_range_lists
; j
++)
8470 if (is_range_list_for_this_section (is_rnglists
, debug_info_p
->dwarf_version
))
8472 range_entry_fill
->ranges_offset
= debug_info_p
->range_lists
[j
];
8473 range_entry_fill
->debug_info_p
= debug_info_p
;
8479 assert (range_entry_fill
>= range_entries
);
8480 assert (num_range_list
>= (unsigned int)(range_entry_fill
- range_entries
));
8481 num_range_list
= range_entry_fill
- range_entries
;
8482 qsort (range_entries
, num_range_list
, sizeof (*range_entries
),
8483 range_entry_compar
);
8485 if (dwarf_check
!= 0 && range_entries
[0].ranges_offset
!= 0)
8486 warn (_("Range lists in %s section start at %#" PRIx64
"\n"),
8487 section
->name
, range_entries
[0].ranges_offset
);
8491 printf (_(" Offset Begin End\n"));
8493 for (i
= 0; i
< num_range_list
; i
++)
8495 struct range_entry
*range_entry
= &range_entries
[i
];
8496 debug_info
*debug_info_p
= range_entry
->debug_info_p
;
8497 unsigned int pointer_size
;
8499 unsigned char *next
;
8500 uint64_t base_address
;
8502 pointer_size
= debug_info_p
->pointer_size
;
8503 offset
= range_entry
->ranges_offset
;
8504 base_address
= debug_info_p
->base_address
;
8506 /* PR 17512: file: 001-101485-0.001:0.1. */
8507 if (pointer_size
< 2 || pointer_size
> 8)
8509 warn (_("Corrupt pointer size (%d) in debug entry at offset %#" PRIx64
"\n"),
8510 pointer_size
, offset
);
8514 if (offset
> (size_t) (finish
- section_begin
))
8516 warn (_("Corrupt offset (%#" PRIx64
") in range entry %u\n"),
8521 /* If we've moved on to the next compile unit in the rnglists section - dump the unit header(s). */
8522 if (is_rnglists
&& next_rnglists_cu_offset
< offset
)
8524 while (next_rnglists_cu_offset
< offset
)
8525 display_debug_rnglists_unit_header (section
, &next_rnglists_cu_offset
, &offset_size
);
8526 printf (_(" Offset Begin End\n"));
8529 next
= section_begin
+ offset
; /* Offset is from the section start, the base has already been added. */
8531 /* If multiple DWARF entities reference the same range then we will
8532 have multiple entries in the `range_entries' list for the same
8533 offset. Thanks to the sort above these will all be consecutive in
8534 the `range_entries' list, so we can easily ignore duplicates
8536 if (i
> 0 && last_offset
== offset
)
8538 last_offset
= offset
;
8540 if (dwarf_check
!= 0 && i
> 0)
8543 warn (_("There is a hole [%#tx - %#tx] in %s section.\n"),
8544 start
- section_begin
, next
- section_begin
, section
->name
);
8545 else if (start
> next
)
8547 if (next
== last_start
)
8549 warn (_("There is an overlap [%#tx - %#tx] in %s section.\n"),
8550 start
- section_begin
, next
- section_begin
, section
->name
);
8558 display_debug_rnglists_list
8559 (start
, finish
, pointer_size
, offset
, base_address
, debug_info_p
->addr_base
);
8561 display_debug_ranges_list
8562 (start
, finish
, pointer_size
, offset
, base_address
);
8565 /* Display trailing empty (or unreferenced) compile units, if any. */
8567 while (next_rnglists_cu_offset
< section
->size
)
8568 display_debug_rnglists_unit_header (section
, &next_rnglists_cu_offset
, &offset_size
);
8572 free (range_entries
);
8577 typedef struct Frame_Chunk
8579 struct Frame_Chunk
*next
;
8580 unsigned char *chunk_start
;
8582 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
8583 short int *col_type
;
8584 int64_t *col_offset
;
8586 unsigned int code_factor
;
8590 unsigned int cfa_reg
;
8591 uint64_t cfa_offset
;
8593 unsigned char fde_encoding
;
8594 unsigned char cfa_exp
;
8595 unsigned char ptr_size
;
8596 unsigned char segment_size
;
8600 typedef const char *(*dwarf_regname_lookup_ftype
) (unsigned int);
8601 static dwarf_regname_lookup_ftype dwarf_regnames_lookup_func
;
8602 static const char *const *dwarf_regnames
;
8603 static unsigned int dwarf_regnames_count
;
8604 static bool is_aarch64
;
8606 /* A marker for a col_type that means this column was never referenced
8607 in the frame info. */
8608 #define DW_CFA_unreferenced (-1)
8610 /* Return 0 if no more space is needed, 1 if more space is needed,
8611 -1 for invalid reg. */
8614 frame_need_space (Frame_Chunk
*fc
, unsigned int reg
)
8616 unsigned int prev
= fc
->ncols
;
8618 if (reg
< (unsigned int) fc
->ncols
)
8621 if (dwarf_regnames_count
> 0
8622 && reg
> dwarf_regnames_count
)
8625 fc
->ncols
= reg
+ 1;
8626 /* PR 17512: file: 10450-2643-0.004.
8627 If reg == -1 then this can happen... */
8631 /* PR 17512: file: 2844a11d. */
8632 if (fc
->ncols
> 1024 && dwarf_regnames_count
== 0)
8634 error (_("Unfeasibly large register number: %u\n"), reg
);
8636 /* FIXME: 1024 is an arbitrary limit. Increase it if
8637 we ever encounter a valid binary that exceeds it. */
8641 fc
->col_type
= xcrealloc (fc
->col_type
, fc
->ncols
,
8642 sizeof (*fc
->col_type
));
8643 fc
->col_offset
= xcrealloc (fc
->col_offset
, fc
->ncols
,
8644 sizeof (*fc
->col_offset
));
8645 /* PR 17512: file:002-10025-0.005. */
8646 if (fc
->col_type
== NULL
|| fc
->col_offset
== NULL
)
8648 error (_("Out of memory allocating %u columns in dwarf frame arrays\n"),
8654 while (prev
< fc
->ncols
)
8656 fc
->col_type
[prev
] = DW_CFA_unreferenced
;
8657 fc
->col_offset
[prev
] = 0;
8663 static const char *const dwarf_regnames_i386
[] =
8665 "eax", "ecx", "edx", "ebx", /* 0 - 3 */
8666 "esp", "ebp", "esi", "edi", /* 4 - 7 */
8667 "eip", "eflags", NULL
, /* 8 - 10 */
8668 "st0", "st1", "st2", "st3", /* 11 - 14 */
8669 "st4", "st5", "st6", "st7", /* 15 - 18 */
8670 NULL
, NULL
, /* 19 - 20 */
8671 "xmm0", "xmm1", "xmm2", "xmm3", /* 21 - 24 */
8672 "xmm4", "xmm5", "xmm6", "xmm7", /* 25 - 28 */
8673 "mm0", "mm1", "mm2", "mm3", /* 29 - 32 */
8674 "mm4", "mm5", "mm6", "mm7", /* 33 - 36 */
8675 "fcw", "fsw", "mxcsr", /* 37 - 39 */
8676 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
, /* 40 - 47 */
8677 "tr", "ldtr", /* 48 - 49 */
8678 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 50 - 57 */
8679 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 58 - 65 */
8680 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 66 - 73 */
8681 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 74 - 81 */
8682 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 82 - 89 */
8683 NULL
, NULL
, NULL
, /* 90 - 92 */
8684 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7" /* 93 - 100 */
8687 static const char *const dwarf_regnames_iamcu
[] =
8689 "eax", "ecx", "edx", "ebx", /* 0 - 3 */
8690 "esp", "ebp", "esi", "edi", /* 4 - 7 */
8691 "eip", "eflags", NULL
, /* 8 - 10 */
8692 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 11 - 18 */
8693 NULL
, NULL
, /* 19 - 20 */
8694 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 21 - 28 */
8695 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 29 - 36 */
8696 NULL
, NULL
, NULL
, /* 37 - 39 */
8697 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
, /* 40 - 47 */
8698 "tr", "ldtr", /* 48 - 49 */
8699 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 50 - 57 */
8700 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 58 - 65 */
8701 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 66 - 73 */
8702 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 74 - 81 */
8703 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 82 - 89 */
8704 NULL
, NULL
, NULL
, /* 90 - 92 */
8705 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
/* 93 - 100 */
8709 init_dwarf_regnames_i386 (void)
8711 dwarf_regnames
= dwarf_regnames_i386
;
8712 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_i386
);
8713 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8717 init_dwarf_regnames_iamcu (void)
8719 dwarf_regnames
= dwarf_regnames_iamcu
;
8720 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_iamcu
);
8721 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8724 static const char *const DW_CFA_GNU_window_save_name
[] =
8726 "DW_CFA_GNU_window_save",
8727 "DW_CFA_AARCH64_negate_ra_state"
8730 static const char *const dwarf_regnames_x86_64
[] =
8732 "rax", "rdx", "rcx", "rbx",
8733 "rsi", "rdi", "rbp", "rsp",
8734 "r8", "r9", "r10", "r11",
8735 "r12", "r13", "r14", "r15",
8737 "xmm0", "xmm1", "xmm2", "xmm3",
8738 "xmm4", "xmm5", "xmm6", "xmm7",
8739 "xmm8", "xmm9", "xmm10", "xmm11",
8740 "xmm12", "xmm13", "xmm14", "xmm15",
8741 "st0", "st1", "st2", "st3",
8742 "st4", "st5", "st6", "st7",
8743 "mm0", "mm1", "mm2", "mm3",
8744 "mm4", "mm5", "mm6", "mm7",
8746 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
,
8747 "fs.base", "gs.base", NULL
, NULL
,
8749 "mxcsr", "fcw", "fsw",
8750 "xmm16", "xmm17", "xmm18", "xmm19",
8751 "xmm20", "xmm21", "xmm22", "xmm23",
8752 "xmm24", "xmm25", "xmm26", "xmm27",
8753 "xmm28", "xmm29", "xmm30", "xmm31",
8754 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 83 - 90 */
8755 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 91 - 98 */
8756 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 99 - 106 */
8757 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 107 - 114 */
8758 NULL
, NULL
, NULL
, /* 115 - 117 */
8759 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7"
8763 init_dwarf_regnames_x86_64 (void)
8765 dwarf_regnames
= dwarf_regnames_x86_64
;
8766 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_x86_64
);
8767 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8770 static const char *const dwarf_regnames_aarch64
[] =
8772 "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7",
8773 "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15",
8774 "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23",
8775 "x24", "x25", "x26", "x27", "x28", "x29", "x30", "sp",
8776 NULL
, "elr", NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
8777 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, "vg", "ffr",
8778 "p0", "p1", "p2", "p3", "p4", "p5", "p6", "p7",
8779 "p8", "p9", "p10", "p11", "p12", "p13", "p14", "p15",
8780 "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7",
8781 "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15",
8782 "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23",
8783 "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31",
8784 "z0", "z1", "z2", "z3", "z4", "z5", "z6", "z7",
8785 "z8", "z9", "z10", "z11", "z12", "z13", "z14", "z15",
8786 "z16", "z17", "z18", "z19", "z20", "z21", "z22", "z23",
8787 "z24", "z25", "z26", "z27", "z28", "z29", "z30", "z31",
8791 init_dwarf_regnames_aarch64 (void)
8793 dwarf_regnames
= dwarf_regnames_aarch64
;
8794 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_aarch64
);
8795 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8799 static const char *const dwarf_regnames_s390
[] =
8801 /* Avoid saying "r5 (r5)", so omit the names of r0-r15. */
8802 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
8803 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
8804 "f0", "f2", "f4", "f6", "f1", "f3", "f5", "f7",
8805 "f8", "f10", "f12", "f14", "f9", "f11", "f13", "f15",
8806 "cr0", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7",
8807 "cr8", "cr9", "cr10", "cr11", "cr12", "cr13", "cr14", "cr15",
8808 "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7",
8809 "a8", "a9", "a10", "a11", "a12", "a13", "a14", "a15",
8812 "v16", "v18", "v20", "v22", "v17", "v19", "v21", "v23",
8813 "v24", "v26", "v28", "v30", "v25", "v27", "v29", "v31",
8817 init_dwarf_regnames_s390 (void)
8819 dwarf_regnames
= dwarf_regnames_s390
;
8820 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_s390
);
8821 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8824 static const char *const dwarf_regnames_riscv
[] =
8826 "zero", "ra", "sp", "gp", "tp", "t0", "t1", "t2", /* 0 - 7 */
8827 "s0", "s1", "a0", "a1", "a2", "a3", "a4", "a5", /* 8 - 15 */
8828 "a6", "a7", "s2", "s3", "s4", "s5", "s6", "s7", /* 16 - 23 */
8829 "s8", "s9", "s10", "s11", "t3", "t4", "t5", "t6", /* 24 - 31 */
8830 "ft0", "ft1", "ft2", "ft3", "ft4", "ft5", "ft6", "ft7", /* 32 - 39 */
8831 "fs0", "fs1", /* 40 - 41 */
8832 "fa0", "fa1", "fa2", "fa3", "fa4", "fa5", "fa6", "fa7", /* 42 - 49 */
8833 "fs2", "fs3", "fs4", "fs5", "fs6", "fs7", "fs8", "fs9", /* 50 - 57 */
8834 "fs10", "fs11", /* 58 - 59 */
8835 "ft8", "ft9", "ft10", "ft11", /* 60 - 63 */
8836 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 64 - 71 */
8837 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 72 - 79 */
8838 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 80 - 87 */
8839 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 88 - 95 */
8840 "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", /* 96 - 103 */
8841 "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15", /* 104 - 111 */
8842 "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23", /* 112 - 119 */
8843 "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31", /* 120 - 127 */
8846 /* A RISC-V replacement for REGNAME_INTERNAL_BY_TABLE_ONLY which handles
8847 the large number of CSRs. */
8850 regname_internal_riscv (unsigned int regno
)
8852 const char *name
= NULL
;
8854 /* Lookup in the table first, this covers GPR and FPR. */
8855 if (regno
< ARRAY_SIZE (dwarf_regnames_riscv
))
8856 name
= dwarf_regnames_riscv
[regno
];
8857 else if (regno
>= 4096 && regno
<= 8191)
8859 /* This might be a CSR, these live in a sparse number space from 4096
8860 to 8191 These numbers are defined in the RISC-V ELF ABI
8864 #define DECLARE_CSR(NAME,VALUE,CLASS,DEFINE_VER,ABORT_VER) \
8865 case VALUE + 4096: name = #NAME; break;
8866 #include "opcode/riscv-opc.h"
8871 static char csr_name
[10];
8872 snprintf (csr_name
, sizeof (csr_name
), "csr%d", (regno
- 4096));
8883 init_dwarf_regnames_riscv (void)
8885 dwarf_regnames
= NULL
;
8886 dwarf_regnames_count
= 8192;
8887 dwarf_regnames_lookup_func
= regname_internal_riscv
;
8891 init_dwarf_regnames_by_elf_machine_code (unsigned int e_machine
)
8893 dwarf_regnames_lookup_func
= NULL
;
8899 init_dwarf_regnames_i386 ();
8903 init_dwarf_regnames_iamcu ();
8909 init_dwarf_regnames_x86_64 ();
8913 init_dwarf_regnames_aarch64 ();
8917 init_dwarf_regnames_s390 ();
8921 init_dwarf_regnames_riscv ();
8929 /* Initialize the DWARF register name lookup state based on the
8930 architecture and specific machine type of a BFD. */
8933 init_dwarf_regnames_by_bfd_arch_and_mach (enum bfd_architecture arch
,
8936 dwarf_regnames_lookup_func
= NULL
;
8944 case bfd_mach_x86_64
:
8945 case bfd_mach_x86_64_intel_syntax
:
8946 case bfd_mach_x64_32
:
8947 case bfd_mach_x64_32_intel_syntax
:
8948 init_dwarf_regnames_x86_64 ();
8952 init_dwarf_regnames_i386 ();
8957 case bfd_arch_iamcu
:
8958 init_dwarf_regnames_iamcu ();
8961 case bfd_arch_aarch64
:
8962 init_dwarf_regnames_aarch64();
8966 init_dwarf_regnames_s390 ();
8969 case bfd_arch_riscv
:
8970 init_dwarf_regnames_riscv ();
8979 regname_internal_by_table_only (unsigned int regno
)
8981 if (dwarf_regnames
!= NULL
8982 && regno
< dwarf_regnames_count
8983 && dwarf_regnames
[regno
] != NULL
)
8984 return dwarf_regnames
[regno
];
8990 regname (unsigned int regno
, int name_only_p
)
8992 static char reg
[64];
8994 const char *name
= NULL
;
8996 if (dwarf_regnames_lookup_func
!= NULL
)
8997 name
= dwarf_regnames_lookup_func (regno
);
9003 snprintf (reg
, sizeof (reg
), "r%d (%s)", regno
, name
);
9006 snprintf (reg
, sizeof (reg
), "r%d", regno
);
9011 frame_display_row (Frame_Chunk
*fc
, int *need_col_headers
, unsigned int *max_regs
)
9016 if (*max_regs
!= fc
->ncols
)
9017 *max_regs
= fc
->ncols
;
9019 if (*need_col_headers
)
9021 *need_col_headers
= 0;
9023 printf ("%-*s CFA ", eh_addr_size
* 2, " LOC");
9025 for (r
= 0; r
< *max_regs
; r
++)
9026 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
9031 printf ("%-5s ", regname (r
, 1));
9037 print_hex (fc
->pc_begin
, eh_addr_size
);
9039 strcpy (tmp
, "exp");
9041 sprintf (tmp
, "%s%+d", regname (fc
->cfa_reg
, 1), (int) fc
->cfa_offset
);
9042 printf ("%-8s ", tmp
);
9044 for (r
= 0; r
< fc
->ncols
; r
++)
9046 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
9048 switch (fc
->col_type
[r
])
9050 case DW_CFA_undefined
:
9053 case DW_CFA_same_value
:
9057 sprintf (tmp
, "c%+" PRId64
, fc
->col_offset
[r
]);
9059 case DW_CFA_val_offset
:
9060 sprintf (tmp
, "v%+" PRId64
, fc
->col_offset
[r
]);
9062 case DW_CFA_register
:
9063 sprintf (tmp
, "%s", regname (fc
->col_offset
[r
], 0));
9065 case DW_CFA_expression
:
9066 strcpy (tmp
, "exp");
9068 case DW_CFA_val_expression
:
9069 strcpy (tmp
, "vexp");
9072 strcpy (tmp
, "n/a");
9075 printf ("%-5s ", tmp
);
9081 #define GET(VAR, N) SAFE_BYTE_GET_AND_INC (VAR, start, N, end)
9083 static unsigned char *
9084 read_cie (unsigned char *start
, unsigned char *end
,
9085 Frame_Chunk
**p_cie
, int *p_version
,
9086 uint64_t *p_aug_len
, unsigned char **p_aug
)
9090 unsigned char *augmentation_data
= NULL
;
9091 uint64_t augmentation_data_len
= 0;
9094 /* PR 17512: file: 001-228113-0.004. */
9098 fc
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
9099 memset (fc
, 0, sizeof (Frame_Chunk
));
9101 fc
->col_type
= xmalloc (sizeof (*fc
->col_type
));
9102 fc
->col_offset
= xmalloc (sizeof (*fc
->col_offset
));
9106 fc
->augmentation
= (char *) start
;
9107 /* PR 17512: file: 001-228113-0.004.
9108 Skip past augmentation name, but avoid running off the end of the data. */
9110 if (* start
++ == '\0')
9114 warn (_("No terminator for augmentation name\n"));
9118 if (strcmp (fc
->augmentation
, "eh") == 0)
9120 if (eh_addr_size
> (size_t) (end
- start
))
9122 start
+= eh_addr_size
;
9127 if (2 > (size_t) (end
- start
))
9129 GET (fc
->ptr_size
, 1);
9130 if (fc
->ptr_size
< 1 || fc
->ptr_size
> 8)
9132 warn (_("Invalid pointer size (%d) in CIE data\n"), fc
->ptr_size
);
9136 GET (fc
->segment_size
, 1);
9137 /* PR 17512: file: e99d2804. */
9138 if (fc
->segment_size
> 8 || fc
->segment_size
+ fc
->ptr_size
> 8)
9140 warn (_("Invalid segment size (%d) in CIE data\n"), fc
->segment_size
);
9144 eh_addr_size
= fc
->ptr_size
;
9148 fc
->ptr_size
= eh_addr_size
;
9149 fc
->segment_size
= 0;
9152 READ_ULEB (fc
->code_factor
, start
, end
);
9153 READ_SLEB (fc
->data_factor
, start
, end
);
9164 READ_ULEB (fc
->ra
, start
, end
);
9167 if (fc
->augmentation
[0] == 'z')
9171 READ_ULEB (augmentation_data_len
, start
, end
);
9172 augmentation_data
= start
;
9173 /* PR 17512: file: 11042-2589-0.004. */
9174 if (augmentation_data_len
> (size_t) (end
- start
))
9176 warn (_("Augmentation data too long: %#" PRIx64
9177 ", expected at most %#tx\n"),
9178 augmentation_data_len
, end
- start
);
9181 start
+= augmentation_data_len
;
9184 if (augmentation_data_len
)
9188 unsigned char *qend
;
9190 p
= (unsigned char *) fc
->augmentation
+ 1;
9191 q
= augmentation_data
;
9192 qend
= q
+ augmentation_data_len
;
9194 while (p
< end
&& q
< qend
)
9199 q
+= 1 + size_of_encoded_value (*q
);
9201 fc
->fde_encoding
= *q
++;
9210 /* Note - it is OK if this loop terminates with q < qend.
9211 Padding may have been inserted to align the end of the CIE. */
9216 *p_version
= version
;
9219 *p_aug_len
= augmentation_data_len
;
9220 *p_aug
= augmentation_data
;
9225 free (fc
->col_offset
);
9226 free (fc
->col_type
);
9231 /* Prints out the contents on the DATA array formatted as unsigned bytes.
9232 If do_wide is not enabled, then formats the output to fit into 80 columns.
9233 PRINTED contains the number of characters already written to the current
9237 display_data (size_t printed
, const unsigned char *data
, size_t len
)
9239 if (do_wide
|| len
< ((80 - printed
) / 3))
9240 for (printed
= 0; printed
< len
; ++printed
)
9241 printf (" %02x", data
[printed
]);
9244 for (printed
= 0; printed
< len
; ++printed
)
9246 if (printed
% (80 / 3) == 0)
9248 printf (" %02x", data
[printed
]);
9253 /* Prints out the contents on the augmentation data array.
9254 If do_wide is not enabled, then formats the output to fit into 80 columns. */
9257 display_augmentation_data (const unsigned char * data
, uint64_t len
)
9261 i
= printf (_(" Augmentation data: "));
9262 display_data (i
, data
, len
);
9266 display_debug_frames (struct dwarf_section
*section
,
9267 void *file ATTRIBUTE_UNUSED
)
9269 unsigned char *start
= section
->start
;
9270 unsigned char *end
= start
+ section
->size
;
9271 unsigned char *section_start
= start
;
9272 Frame_Chunk
*chunks
= NULL
, *forward_refs
= NULL
;
9273 Frame_Chunk
*remembered_state
= NULL
;
9275 bool is_eh
= strcmp (section
->name
, ".eh_frame") == 0;
9276 unsigned int max_regs
= 0;
9277 const char *bad_reg
= _("bad register: ");
9278 unsigned int saved_eh_addr_size
= eh_addr_size
;
9280 introduce (section
, false);
9284 unsigned char *saved_start
;
9285 unsigned char *block_end
;
9290 int need_col_headers
= 1;
9291 unsigned char *augmentation_data
= NULL
;
9292 uint64_t augmentation_data_len
= 0;
9293 unsigned int encoded_ptr_size
= saved_eh_addr_size
;
9294 unsigned int offset_size
;
9296 static Frame_Chunk fde_fc
;
9298 saved_start
= start
;
9300 SAFE_BYTE_GET_AND_INC (length
, start
, 4, end
);
9304 printf ("\n%08tx ZERO terminator\n\n",
9305 saved_start
- section_start
);
9306 /* Skip any zero terminators that directly follow.
9307 A corrupt section size could have loaded a whole
9308 slew of zero filled memory bytes. eg
9309 PR 17512: file: 070-19381-0.004. */
9310 while (start
< end
&& * start
== 0)
9315 if (length
== 0xffffffff)
9317 SAFE_BYTE_GET_AND_INC (length
, start
, 8, end
);
9323 if (length
> (size_t) (end
- start
))
9325 warn ("Invalid length %#" PRIx64
" in FDE at %#tx\n",
9326 length
, saved_start
- section_start
);
9330 block_end
= start
+ length
;
9332 SAFE_BYTE_GET_AND_INC (cie_id
, start
, offset_size
, block_end
);
9334 if (is_eh
? (cie_id
== 0) : ((offset_size
== 4 && cie_id
== DW_CIE_ID
)
9335 || (offset_size
== 8 && cie_id
== DW64_CIE_ID
)))
9340 start
= read_cie (start
, block_end
, &cie
, &version
,
9341 &augmentation_data_len
, &augmentation_data
);
9342 /* PR 17512: file: 027-135133-0.005. */
9349 fc
->chunk_start
= saved_start
;
9350 mreg
= max_regs
> 0 ? max_regs
- 1 : 0;
9353 if (frame_need_space (fc
, mreg
) < 0)
9355 if (fc
->fde_encoding
)
9356 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
9358 printf ("\n%08tx ", saved_start
- section_start
);
9359 print_hex (length
, fc
->ptr_size
);
9360 print_hex (cie_id
, offset_size
);
9362 if (do_debug_frames_interp
)
9364 printf ("CIE \"%s\" cf=%d df=%d ra=%d\n", fc
->augmentation
,
9365 fc
->code_factor
, fc
->data_factor
, fc
->ra
);
9370 printf (" Version: %d\n", version
);
9371 printf (" Augmentation: \"%s\"\n", fc
->augmentation
);
9374 printf (" Pointer Size: %u\n", fc
->ptr_size
);
9375 printf (" Segment Size: %u\n", fc
->segment_size
);
9377 printf (" Code alignment factor: %u\n", fc
->code_factor
);
9378 printf (" Data alignment factor: %d\n", fc
->data_factor
);
9379 printf (" Return address column: %d\n", fc
->ra
);
9381 if (augmentation_data_len
)
9382 display_augmentation_data (augmentation_data
, augmentation_data_len
);
9389 unsigned char *look_for
;
9390 unsigned long segment_selector
;
9396 uint64_t sign
= (uint64_t) 1 << (offset_size
* 8 - 1);
9397 cie_off
= (cie_off
^ sign
) - sign
;
9398 cie_off
= start
- 4 - section_start
- cie_off
;
9401 look_for
= section_start
+ cie_off
;
9402 if (cie_off
<= (size_t) (saved_start
- section_start
))
9404 for (cie
= chunks
; cie
; cie
= cie
->next
)
9405 if (cie
->chunk_start
== look_for
)
9408 else if (cie_off
>= section
->size
)
9412 for (cie
= forward_refs
; cie
; cie
= cie
->next
)
9413 if (cie
->chunk_start
== look_for
)
9417 unsigned int off_size
;
9418 unsigned char *cie_scan
;
9420 cie_scan
= look_for
;
9422 SAFE_BYTE_GET_AND_INC (length
, cie_scan
, 4, end
);
9423 if (length
== 0xffffffff)
9425 SAFE_BYTE_GET_AND_INC (length
, cie_scan
, 8, end
);
9428 if (length
!= 0 && length
<= (size_t) (end
- cie_scan
))
9431 unsigned char *cie_end
= cie_scan
+ length
;
9433 SAFE_BYTE_GET_AND_INC (c_id
, cie_scan
, off_size
,
9437 : ((off_size
== 4 && c_id
== DW_CIE_ID
)
9438 || (off_size
== 8 && c_id
== DW64_CIE_ID
)))
9443 read_cie (cie_scan
, cie_end
, &cie
, &version
,
9444 &augmentation_data_len
, &augmentation_data
);
9445 /* PR 17512: file: 3450-2098-0.004. */
9448 warn (_("Failed to read CIE information\n"));
9451 cie
->next
= forward_refs
;
9453 cie
->chunk_start
= look_for
;
9454 mreg
= max_regs
> 0 ? max_regs
- 1 : 0;
9457 if (frame_need_space (cie
, mreg
) < 0)
9459 warn (_("Invalid max register\n"));
9462 if (cie
->fde_encoding
)
9464 = size_of_encoded_value (cie
->fde_encoding
);
9471 memset (fc
, 0, sizeof (Frame_Chunk
));
9476 fc
->col_type
= xmalloc (sizeof (*fc
->col_type
));
9477 fc
->col_offset
= xmalloc (sizeof (*fc
->col_offset
));
9478 if (frame_need_space (fc
, max_regs
> 0 ? max_regs
- 1 : 0) < 0)
9480 warn (_("Invalid max register\n"));
9484 fc
->augmentation
= "";
9485 fc
->fde_encoding
= 0;
9486 fc
->ptr_size
= eh_addr_size
;
9487 fc
->segment_size
= 0;
9491 fc
->ncols
= cie
->ncols
;
9492 fc
->col_type
= xcmalloc (fc
->ncols
, sizeof (*fc
->col_type
));
9493 fc
->col_offset
= xcmalloc (fc
->ncols
, sizeof (*fc
->col_offset
));
9494 memcpy (fc
->col_type
, cie
->col_type
,
9495 fc
->ncols
* sizeof (*fc
->col_type
));
9496 memcpy (fc
->col_offset
, cie
->col_offset
,
9497 fc
->ncols
* sizeof (*fc
->col_offset
));
9498 fc
->augmentation
= cie
->augmentation
;
9499 fc
->ptr_size
= cie
->ptr_size
;
9500 eh_addr_size
= cie
->ptr_size
;
9501 fc
->segment_size
= cie
->segment_size
;
9502 fc
->code_factor
= cie
->code_factor
;
9503 fc
->data_factor
= cie
->data_factor
;
9504 fc
->cfa_reg
= cie
->cfa_reg
;
9505 fc
->cfa_offset
= cie
->cfa_offset
;
9507 if (frame_need_space (fc
, max_regs
> 0 ? max_regs
- 1: 0) < 0)
9509 warn (_("Invalid max register\n"));
9512 fc
->fde_encoding
= cie
->fde_encoding
;
9515 if (fc
->fde_encoding
)
9516 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
9518 segment_selector
= 0;
9519 if (fc
->segment_size
)
9521 if (fc
->segment_size
> sizeof (segment_selector
))
9523 /* PR 17512: file: 9e196b3e. */
9524 warn (_("Probably corrupt segment size: %d - using 4 instead\n"), fc
->segment_size
);
9525 fc
->segment_size
= 4;
9527 SAFE_BYTE_GET_AND_INC (segment_selector
, start
,
9528 fc
->segment_size
, block_end
);
9531 fc
->pc_begin
= get_encoded_value (&start
, fc
->fde_encoding
, section
,
9534 /* FIXME: It appears that sometimes the final pc_range value is
9535 encoded in less than encoded_ptr_size bytes. See the x86_64
9536 run of the "objcopy on compressed debug sections" test for an
9538 SAFE_BYTE_GET_AND_INC (fc
->pc_range
, start
, encoded_ptr_size
,
9541 if (cie
->augmentation
[0] == 'z')
9543 READ_ULEB (augmentation_data_len
, start
, block_end
);
9544 augmentation_data
= start
;
9545 /* PR 17512 file: 722-8446-0.004 and PR 22386. */
9546 if (augmentation_data_len
> (size_t) (block_end
- start
))
9548 warn (_("Augmentation data too long: %#" PRIx64
", "
9549 "expected at most %#tx\n"),
9550 augmentation_data_len
, block_end
- start
);
9552 augmentation_data
= NULL
;
9553 augmentation_data_len
= 0;
9555 start
+= augmentation_data_len
;
9558 printf ("\n%08tx ", saved_start
- section_start
);
9559 print_hex (length
, fc
->ptr_size
);
9560 print_hex (cie_id
, offset_size
);
9563 if (cie
->chunk_start
)
9564 printf ("cie=%08tx", cie
->chunk_start
- section_start
);
9566 /* Ideally translate "invalid " to 8 chars, trailing space
9568 printf (_("cie=invalid "));
9571 if (fc
->segment_size
)
9572 printf ("%04lx:", segment_selector
);
9574 print_hex_ns (fc
->pc_begin
, fc
->ptr_size
);
9576 print_hex_ns (fc
->pc_begin
+ fc
->pc_range
, fc
->ptr_size
);
9579 if (! do_debug_frames_interp
&& augmentation_data_len
)
9581 display_augmentation_data (augmentation_data
, augmentation_data_len
);
9586 /* At this point, fc is the current chunk, cie (if any) is set, and
9587 we're about to interpret instructions for the chunk. */
9588 /* ??? At present we need to do this always, since this sizes the
9589 fc->col_type and fc->col_offset arrays, which we write into always.
9590 We should probably split the interpreted and non-interpreted bits
9591 into two different routines, since there's so much that doesn't
9592 really overlap between them. */
9593 if (1 || do_debug_frames_interp
)
9595 /* Start by making a pass over the chunk, allocating storage
9596 and taking note of what registers are used. */
9597 unsigned char *tmp
= start
;
9599 while (start
< block_end
)
9601 unsigned int reg
, op
, opa
;
9609 /* Warning: if you add any more cases to this switch, be
9610 sure to add them to the corresponding switch below. */
9614 case DW_CFA_advance_loc
:
9617 SKIP_ULEB (start
, block_end
);
9620 case DW_CFA_restore
:
9623 case DW_CFA_set_loc
:
9624 if ((size_t) (block_end
- start
) < encoded_ptr_size
)
9627 start
+= encoded_ptr_size
;
9629 case DW_CFA_advance_loc1
:
9630 if ((size_t) (block_end
- start
) < 1)
9635 case DW_CFA_advance_loc2
:
9636 if ((size_t) (block_end
- start
) < 2)
9641 case DW_CFA_advance_loc4
:
9642 if ((size_t) (block_end
- start
) < 4)
9647 case DW_CFA_offset_extended
:
9648 case DW_CFA_val_offset
:
9649 READ_ULEB (reg
, start
, block_end
);
9650 SKIP_ULEB (start
, block_end
);
9652 case DW_CFA_restore_extended
:
9653 READ_ULEB (reg
, start
, block_end
);
9655 case DW_CFA_undefined
:
9656 READ_ULEB (reg
, start
, block_end
);
9658 case DW_CFA_same_value
:
9659 READ_ULEB (reg
, start
, block_end
);
9661 case DW_CFA_register
:
9662 READ_ULEB (reg
, start
, block_end
);
9663 SKIP_ULEB (start
, block_end
);
9665 case DW_CFA_def_cfa
:
9666 SKIP_ULEB (start
, block_end
);
9667 SKIP_ULEB (start
, block_end
);
9669 case DW_CFA_def_cfa_register
:
9670 SKIP_ULEB (start
, block_end
);
9672 case DW_CFA_def_cfa_offset
:
9673 SKIP_ULEB (start
, block_end
);
9675 case DW_CFA_def_cfa_expression
:
9676 READ_ULEB (temp
, start
, block_end
);
9677 if ((size_t) (block_end
- start
) < temp
)
9682 case DW_CFA_expression
:
9683 case DW_CFA_val_expression
:
9684 READ_ULEB (reg
, start
, block_end
);
9685 READ_ULEB (temp
, start
, block_end
);
9686 if ((size_t) (block_end
- start
) < temp
)
9691 case DW_CFA_offset_extended_sf
:
9692 case DW_CFA_val_offset_sf
:
9693 READ_ULEB (reg
, start
, block_end
);
9694 SKIP_SLEB (start
, block_end
);
9696 case DW_CFA_def_cfa_sf
:
9697 SKIP_ULEB (start
, block_end
);
9698 SKIP_SLEB (start
, block_end
);
9700 case DW_CFA_def_cfa_offset_sf
:
9701 SKIP_SLEB (start
, block_end
);
9703 case DW_CFA_MIPS_advance_loc8
:
9704 if ((size_t) (block_end
- start
) < 8)
9709 case DW_CFA_GNU_args_size
:
9710 SKIP_ULEB (start
, block_end
);
9712 case DW_CFA_GNU_negative_offset_extended
:
9713 READ_ULEB (reg
, start
, block_end
);
9714 SKIP_ULEB (start
, block_end
);
9719 if (reg
!= -1u && frame_need_space (fc
, reg
) >= 0)
9721 /* Don't leave any reg as DW_CFA_unreferenced so
9722 that frame_display_row prints name of regs in
9723 header, and all referenced regs in each line. */
9724 if (reg
>= cie
->ncols
9725 || cie
->col_type
[reg
] == DW_CFA_unreferenced
)
9726 fc
->col_type
[reg
] = DW_CFA_undefined
;
9728 fc
->col_type
[reg
] = cie
->col_type
[reg
];
9736 /* Now we know what registers are used, make a second pass over
9737 the chunk, this time actually printing out the info. */
9739 while (start
< block_end
)
9742 /* Note: It is tempting to use an unsigned long for 'reg' but there
9743 are various functions, notably frame_space_needed() that assume that
9744 reg is an unsigned int. */
9748 const char *reg_prefix
= "";
9755 /* Make a note if something other than DW_CFA_nop happens. */
9756 if (op
!= DW_CFA_nop
)
9759 /* Warning: if you add any more cases to this switch, be
9760 sure to add them to the corresponding switch above. */
9763 case DW_CFA_advance_loc
:
9764 opa
*= fc
->code_factor
;
9765 if (do_debug_frames_interp
)
9766 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9769 printf (" DW_CFA_advance_loc: %d to ", opa
);
9770 print_hex_ns (fc
->pc_begin
+ opa
, fc
->ptr_size
);
9773 fc
->pc_begin
+= opa
;
9777 READ_ULEB (ofs
, start
, block_end
);
9778 ofs
*= fc
->data_factor
;
9779 if (opa
>= fc
->ncols
)
9780 reg_prefix
= bad_reg
;
9781 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9782 printf (" DW_CFA_offset: %s%s at cfa%+" PRId64
"\n",
9783 reg_prefix
, regname (opa
, 0), ofs
);
9784 if (*reg_prefix
== '\0')
9786 fc
->col_type
[opa
] = DW_CFA_offset
;
9787 fc
->col_offset
[opa
] = ofs
;
9791 case DW_CFA_restore
:
9792 if (opa
>= fc
->ncols
)
9793 reg_prefix
= bad_reg
;
9794 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9795 printf (" DW_CFA_restore: %s%s\n",
9796 reg_prefix
, regname (opa
, 0));
9797 if (*reg_prefix
!= '\0')
9800 if (opa
>= cie
->ncols
9801 || cie
->col_type
[opa
] == DW_CFA_unreferenced
)
9803 fc
->col_type
[opa
] = DW_CFA_undefined
;
9804 fc
->col_offset
[opa
] = 0;
9808 fc
->col_type
[opa
] = cie
->col_type
[opa
];
9809 fc
->col_offset
[opa
] = cie
->col_offset
[opa
];
9813 case DW_CFA_set_loc
:
9814 ofs
= get_encoded_value (&start
, fc
->fde_encoding
, section
,
9816 if (do_debug_frames_interp
)
9817 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9820 printf (" DW_CFA_set_loc: ");
9821 print_hex_ns (ofs
, fc
->ptr_size
);
9827 case DW_CFA_advance_loc1
:
9828 SAFE_BYTE_GET_AND_INC (ofs
, start
, 1, block_end
);
9829 ofs
*= fc
->code_factor
;
9830 if (do_debug_frames_interp
)
9831 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9834 printf (" DW_CFA_advance_loc1: %" PRId64
" to ", ofs
);
9835 print_hex_ns (fc
->pc_begin
+ ofs
, fc
->ptr_size
);
9838 fc
->pc_begin
+= ofs
;
9841 case DW_CFA_advance_loc2
:
9842 SAFE_BYTE_GET_AND_INC (ofs
, start
, 2, block_end
);
9843 ofs
*= fc
->code_factor
;
9844 if (do_debug_frames_interp
)
9845 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9848 printf (" DW_CFA_advance_loc2: %" PRId64
" to ", ofs
);
9849 print_hex_ns (fc
->pc_begin
+ ofs
, fc
->ptr_size
);
9852 fc
->pc_begin
+= ofs
;
9855 case DW_CFA_advance_loc4
:
9856 SAFE_BYTE_GET_AND_INC (ofs
, start
, 4, block_end
);
9857 ofs
*= fc
->code_factor
;
9858 if (do_debug_frames_interp
)
9859 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9862 printf (" DW_CFA_advance_loc4: %" PRId64
" to ", ofs
);
9863 print_hex_ns (fc
->pc_begin
+ ofs
, fc
->ptr_size
);
9866 fc
->pc_begin
+= ofs
;
9869 case DW_CFA_offset_extended
:
9870 READ_ULEB (reg
, start
, block_end
);
9871 READ_ULEB (ofs
, start
, block_end
);
9872 ofs
*= fc
->data_factor
;
9873 if (reg
>= fc
->ncols
)
9874 reg_prefix
= bad_reg
;
9875 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9876 printf (" DW_CFA_offset_extended: %s%s at cfa%+" PRId64
"\n",
9877 reg_prefix
, regname (reg
, 0), ofs
);
9878 if (*reg_prefix
== '\0')
9880 fc
->col_type
[reg
] = DW_CFA_offset
;
9881 fc
->col_offset
[reg
] = ofs
;
9885 case DW_CFA_val_offset
:
9886 READ_ULEB (reg
, start
, block_end
);
9887 READ_ULEB (ofs
, start
, block_end
);
9888 ofs
*= fc
->data_factor
;
9889 if (reg
>= fc
->ncols
)
9890 reg_prefix
= bad_reg
;
9891 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9892 printf (" DW_CFA_val_offset: %s%s is cfa%+" PRId64
"\n",
9893 reg_prefix
, regname (reg
, 0), ofs
);
9894 if (*reg_prefix
== '\0')
9896 fc
->col_type
[reg
] = DW_CFA_val_offset
;
9897 fc
->col_offset
[reg
] = ofs
;
9901 case DW_CFA_restore_extended
:
9902 READ_ULEB (reg
, start
, block_end
);
9903 if (reg
>= fc
->ncols
)
9904 reg_prefix
= bad_reg
;
9905 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9906 printf (" DW_CFA_restore_extended: %s%s\n",
9907 reg_prefix
, regname (reg
, 0));
9908 if (*reg_prefix
!= '\0')
9911 if (reg
>= cie
->ncols
9912 || cie
->col_type
[reg
] == DW_CFA_unreferenced
)
9914 fc
->col_type
[reg
] = DW_CFA_undefined
;
9915 fc
->col_offset
[reg
] = 0;
9919 fc
->col_type
[reg
] = cie
->col_type
[reg
];
9920 fc
->col_offset
[reg
] = cie
->col_offset
[reg
];
9924 case DW_CFA_undefined
:
9925 READ_ULEB (reg
, start
, block_end
);
9926 if (reg
>= fc
->ncols
)
9927 reg_prefix
= bad_reg
;
9928 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9929 printf (" DW_CFA_undefined: %s%s\n",
9930 reg_prefix
, regname (reg
, 0));
9931 if (*reg_prefix
== '\0')
9933 fc
->col_type
[reg
] = DW_CFA_undefined
;
9934 fc
->col_offset
[reg
] = 0;
9938 case DW_CFA_same_value
:
9939 READ_ULEB (reg
, start
, block_end
);
9940 if (reg
>= fc
->ncols
)
9941 reg_prefix
= bad_reg
;
9942 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9943 printf (" DW_CFA_same_value: %s%s\n",
9944 reg_prefix
, regname (reg
, 0));
9945 if (*reg_prefix
== '\0')
9947 fc
->col_type
[reg
] = DW_CFA_same_value
;
9948 fc
->col_offset
[reg
] = 0;
9952 case DW_CFA_register
:
9953 READ_ULEB (reg
, start
, block_end
);
9954 READ_ULEB (ofs
, start
, block_end
);
9955 if (reg
>= fc
->ncols
)
9956 reg_prefix
= bad_reg
;
9957 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9959 printf (" DW_CFA_register: %s%s in ",
9960 reg_prefix
, regname (reg
, 0));
9961 puts (regname (ofs
, 0));
9963 if (*reg_prefix
== '\0')
9965 fc
->col_type
[reg
] = DW_CFA_register
;
9966 fc
->col_offset
[reg
] = ofs
;
9970 case DW_CFA_remember_state
:
9971 if (! do_debug_frames_interp
)
9972 printf (" DW_CFA_remember_state\n");
9973 rs
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
9974 rs
->cfa_offset
= fc
->cfa_offset
;
9975 rs
->cfa_reg
= fc
->cfa_reg
;
9977 rs
->cfa_exp
= fc
->cfa_exp
;
9978 rs
->ncols
= fc
->ncols
;
9979 rs
->col_type
= xcmalloc (rs
->ncols
, sizeof (*rs
->col_type
));
9980 rs
->col_offset
= xcmalloc (rs
->ncols
, sizeof (*rs
->col_offset
));
9981 memcpy (rs
->col_type
, fc
->col_type
,
9982 rs
->ncols
* sizeof (*fc
->col_type
));
9983 memcpy (rs
->col_offset
, fc
->col_offset
,
9984 rs
->ncols
* sizeof (*fc
->col_offset
));
9985 rs
->next
= remembered_state
;
9986 remembered_state
= rs
;
9989 case DW_CFA_restore_state
:
9990 if (! do_debug_frames_interp
)
9991 printf (" DW_CFA_restore_state\n");
9992 rs
= remembered_state
;
9995 remembered_state
= rs
->next
;
9996 fc
->cfa_offset
= rs
->cfa_offset
;
9997 fc
->cfa_reg
= rs
->cfa_reg
;
9999 fc
->cfa_exp
= rs
->cfa_exp
;
10000 if (frame_need_space (fc
, rs
->ncols
- 1) < 0)
10002 warn (_("Invalid column number in saved frame state\n"));
10007 memcpy (fc
->col_type
, rs
->col_type
,
10008 rs
->ncols
* sizeof (*rs
->col_type
));
10009 memcpy (fc
->col_offset
, rs
->col_offset
,
10010 rs
->ncols
* sizeof (*rs
->col_offset
));
10012 free (rs
->col_type
);
10013 free (rs
->col_offset
);
10016 else if (do_debug_frames_interp
)
10017 printf ("Mismatched DW_CFA_restore_state\n");
10020 case DW_CFA_def_cfa
:
10021 READ_ULEB (fc
->cfa_reg
, start
, block_end
);
10022 READ_ULEB (fc
->cfa_offset
, start
, block_end
);
10024 if (! do_debug_frames_interp
)
10025 printf (" DW_CFA_def_cfa: %s ofs %d\n",
10026 regname (fc
->cfa_reg
, 0), (int) fc
->cfa_offset
);
10029 case DW_CFA_def_cfa_register
:
10030 READ_ULEB (fc
->cfa_reg
, start
, block_end
);
10032 if (! do_debug_frames_interp
)
10033 printf (" DW_CFA_def_cfa_register: %s\n",
10034 regname (fc
->cfa_reg
, 0));
10037 case DW_CFA_def_cfa_offset
:
10038 READ_ULEB (fc
->cfa_offset
, start
, block_end
);
10039 if (! do_debug_frames_interp
)
10040 printf (" DW_CFA_def_cfa_offset: %d\n", (int) fc
->cfa_offset
);
10044 if (! do_debug_frames_interp
)
10045 printf (" DW_CFA_nop\n");
10048 case DW_CFA_def_cfa_expression
:
10049 READ_ULEB (ofs
, start
, block_end
);
10050 if (ofs
> (size_t) (block_end
- start
))
10052 printf (_(" %s: <corrupt len %" PRIu64
">\n"),
10053 "DW_CFA_def_cfa_expression", ofs
);
10056 if (! do_debug_frames_interp
)
10058 printf (" DW_CFA_def_cfa_expression (");
10059 decode_location_expression (start
, eh_addr_size
, 0, -1,
10067 case DW_CFA_expression
:
10068 READ_ULEB (reg
, start
, block_end
);
10069 READ_ULEB (ofs
, start
, block_end
);
10070 if (reg
>= fc
->ncols
)
10071 reg_prefix
= bad_reg
;
10072 /* PR 17512: file: 069-133014-0.006. */
10073 /* PR 17512: file: 98c02eb4. */
10074 if (ofs
> (size_t) (block_end
- start
))
10076 printf (_(" %s: <corrupt len %" PRIu64
">\n"),
10077 "DW_CFA_expression", ofs
);
10080 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
10082 printf (" DW_CFA_expression: %s%s (",
10083 reg_prefix
, regname (reg
, 0));
10084 decode_location_expression (start
, eh_addr_size
, 0, -1,
10088 if (*reg_prefix
== '\0')
10089 fc
->col_type
[reg
] = DW_CFA_expression
;
10093 case DW_CFA_val_expression
:
10094 READ_ULEB (reg
, start
, block_end
);
10095 READ_ULEB (ofs
, start
, block_end
);
10096 if (reg
>= fc
->ncols
)
10097 reg_prefix
= bad_reg
;
10098 if (ofs
> (size_t) (block_end
- start
))
10100 printf (" %s: <corrupt len %" PRIu64
">\n",
10101 "DW_CFA_val_expression", ofs
);
10104 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
10106 printf (" DW_CFA_val_expression: %s%s (",
10107 reg_prefix
, regname (reg
, 0));
10108 decode_location_expression (start
, eh_addr_size
, 0, -1,
10112 if (*reg_prefix
== '\0')
10113 fc
->col_type
[reg
] = DW_CFA_val_expression
;
10117 case DW_CFA_offset_extended_sf
:
10118 READ_ULEB (reg
, start
, block_end
);
10119 READ_SLEB (sofs
, start
, block_end
);
10120 /* data_factor multiplicaton done here as unsigned to
10121 avoid integer overflow warnings from asan on fuzzed
10124 ofs
*= fc
->data_factor
;
10125 if (reg
>= fc
->ncols
)
10126 reg_prefix
= bad_reg
;
10127 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
10128 printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+" PRId64
"\n",
10129 reg_prefix
, regname (reg
, 0), ofs
);
10130 if (*reg_prefix
== '\0')
10132 fc
->col_type
[reg
] = DW_CFA_offset
;
10133 fc
->col_offset
[reg
] = ofs
;
10137 case DW_CFA_val_offset_sf
:
10138 READ_ULEB (reg
, start
, block_end
);
10139 READ_SLEB (sofs
, start
, block_end
);
10141 ofs
*= fc
->data_factor
;
10142 if (reg
>= fc
->ncols
)
10143 reg_prefix
= bad_reg
;
10144 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
10145 printf (" DW_CFA_val_offset_sf: %s%s is cfa%+" PRId64
"\n",
10146 reg_prefix
, regname (reg
, 0), ofs
);
10147 if (*reg_prefix
== '\0')
10149 fc
->col_type
[reg
] = DW_CFA_val_offset
;
10150 fc
->col_offset
[reg
] = ofs
;
10154 case DW_CFA_def_cfa_sf
:
10155 READ_ULEB (fc
->cfa_reg
, start
, block_end
);
10156 READ_SLEB (sofs
, start
, block_end
);
10158 ofs
*= fc
->data_factor
;
10159 fc
->cfa_offset
= ofs
;
10161 if (! do_debug_frames_interp
)
10162 printf (" DW_CFA_def_cfa_sf: %s ofs %" PRId64
"\n",
10163 regname (fc
->cfa_reg
, 0), ofs
);
10166 case DW_CFA_def_cfa_offset_sf
:
10167 READ_SLEB (sofs
, start
, block_end
);
10169 ofs
*= fc
->data_factor
;
10170 fc
->cfa_offset
= ofs
;
10171 if (! do_debug_frames_interp
)
10172 printf (" DW_CFA_def_cfa_offset_sf: %" PRId64
"\n", ofs
);
10175 case DW_CFA_MIPS_advance_loc8
:
10176 SAFE_BYTE_GET_AND_INC (ofs
, start
, 8, block_end
);
10177 ofs
*= fc
->code_factor
;
10178 if (do_debug_frames_interp
)
10179 frame_display_row (fc
, &need_col_headers
, &max_regs
);
10182 printf (" DW_CFA_MIPS_advance_loc8: %" PRId64
" to ", ofs
);
10183 print_hex_ns (fc
->pc_begin
+ ofs
, fc
->ptr_size
);
10186 fc
->pc_begin
+= ofs
;
10189 case DW_CFA_GNU_window_save
:
10190 if (! do_debug_frames_interp
)
10191 printf (" %s\n", DW_CFA_GNU_window_save_name
[is_aarch64
]);
10194 case DW_CFA_GNU_args_size
:
10195 READ_ULEB (ofs
, start
, block_end
);
10196 if (! do_debug_frames_interp
)
10197 printf (" DW_CFA_GNU_args_size: %" PRIu64
"\n", ofs
);
10200 case DW_CFA_GNU_negative_offset_extended
:
10201 READ_ULEB (reg
, start
, block_end
);
10202 READ_SLEB (sofs
, start
, block_end
);
10204 ofs
= -ofs
* fc
->data_factor
;
10205 if (reg
>= fc
->ncols
)
10206 reg_prefix
= bad_reg
;
10207 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
10208 printf (" DW_CFA_GNU_negative_offset_extended: %s%s "
10209 "at cfa%+" PRId64
"\n",
10210 reg_prefix
, regname (reg
, 0), ofs
);
10211 if (*reg_prefix
== '\0')
10213 fc
->col_type
[reg
] = DW_CFA_offset
;
10214 fc
->col_offset
[reg
] = ofs
;
10219 if (op
>= DW_CFA_lo_user
&& op
<= DW_CFA_hi_user
)
10220 printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op
);
10222 warn (_("Unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op
);
10227 /* Interpret the CFA - as long as it is not completely full of NOPs. */
10228 if (do_debug_frames_interp
&& ! all_nops
)
10229 frame_display_row (fc
, &need_col_headers
, &max_regs
);
10231 if (fde_fc
.col_type
!= NULL
)
10233 free (fde_fc
.col_type
);
10234 fde_fc
.col_type
= NULL
;
10236 if (fde_fc
.col_offset
!= NULL
)
10238 free (fde_fc
.col_offset
);
10239 fde_fc
.col_offset
= NULL
;
10243 eh_addr_size
= saved_eh_addr_size
;
10248 while (remembered_state
!= NULL
)
10250 rs
= remembered_state
;
10251 remembered_state
= rs
->next
;
10252 free (rs
->col_type
);
10253 free (rs
->col_offset
);
10254 rs
->next
= NULL
; /* Paranoia. */
10258 while (chunks
!= NULL
)
10262 free (rs
->col_type
);
10263 free (rs
->col_offset
);
10264 rs
->next
= NULL
; /* Paranoia. */
10268 while (forward_refs
!= NULL
)
10271 forward_refs
= rs
->next
;
10272 free (rs
->col_type
);
10273 free (rs
->col_offset
);
10274 rs
->next
= NULL
; /* Paranoia. */
10284 display_debug_names (struct dwarf_section
*section
, void *file
)
10286 unsigned char *hdrptr
= section
->start
;
10287 uint64_t unit_length
;
10288 unsigned char *unit_start
;
10289 const unsigned char *const section_end
= section
->start
+ section
->size
;
10290 unsigned char *unit_end
;
10292 introduce (section
, false);
10294 load_debug_section_with_follow (str
, file
);
10296 for (; hdrptr
< section_end
; hdrptr
= unit_end
)
10298 unsigned int offset_size
;
10299 uint16_t dwarf_version
, padding
;
10300 uint32_t comp_unit_count
, local_type_unit_count
, foreign_type_unit_count
;
10301 uint64_t bucket_count
, name_count
, abbrev_table_size
;
10302 uint32_t augmentation_string_size
;
10304 bool augmentation_printable
;
10305 const char *augmentation_string
;
10308 unit_start
= hdrptr
;
10310 /* Get and check the length of the block. */
10311 SAFE_BYTE_GET_AND_INC (unit_length
, hdrptr
, 4, section_end
);
10313 if (unit_length
== 0xffffffff)
10315 /* This section is 64-bit DWARF. */
10316 SAFE_BYTE_GET_AND_INC (unit_length
, hdrptr
, 8, section_end
);
10322 if (unit_length
> (size_t) (section_end
- hdrptr
)
10323 || unit_length
< 2 + 2 + 4 * 7)
10326 warn (_("Debug info is corrupted, %s header at %#tx"
10327 " has length %#" PRIx64
"\n"),
10328 section
->name
, unit_start
- section
->start
, unit_length
);
10331 unit_end
= hdrptr
+ unit_length
;
10333 /* Get and check the version number. */
10334 SAFE_BYTE_GET_AND_INC (dwarf_version
, hdrptr
, 2, unit_end
);
10335 printf (_("Version %d\n"), (int) dwarf_version
);
10337 /* Prior versions did not exist, and future versions may not be
10338 backwards compatible. */
10339 if (dwarf_version
!= 5)
10341 warn (_("Only DWARF version 5 .debug_names "
10342 "is currently supported.\n"));
10346 SAFE_BYTE_GET_AND_INC (padding
, hdrptr
, 2, unit_end
);
10348 warn (_("Padding field of .debug_names must be 0 (found 0x%x)\n"),
10351 SAFE_BYTE_GET_AND_INC (comp_unit_count
, hdrptr
, 4, unit_end
);
10352 if (comp_unit_count
== 0)
10353 warn (_("Compilation unit count must be >= 1 in .debug_names\n"));
10355 SAFE_BYTE_GET_AND_INC (local_type_unit_count
, hdrptr
, 4, unit_end
);
10356 SAFE_BYTE_GET_AND_INC (foreign_type_unit_count
, hdrptr
, 4, unit_end
);
10357 SAFE_BYTE_GET_AND_INC (bucket_count
, hdrptr
, 4, unit_end
);
10358 SAFE_BYTE_GET_AND_INC (name_count
, hdrptr
, 4, unit_end
);
10359 SAFE_BYTE_GET_AND_INC (abbrev_table_size
, hdrptr
, 4, unit_end
);
10361 SAFE_BYTE_GET_AND_INC (augmentation_string_size
, hdrptr
, 4, unit_end
);
10362 if (augmentation_string_size
% 4 != 0)
10364 warn (_("Augmentation string length %u must be rounded up "
10365 "to a multiple of 4 in .debug_names.\n"),
10366 augmentation_string_size
);
10367 augmentation_string_size
+= (-augmentation_string_size
) & 3;
10369 if (augmentation_string_size
> (size_t) (unit_end
- hdrptr
))
10372 printf (_("Augmentation string:"));
10374 augmentation_printable
= true;
10375 augmentation_string
= (const char *) hdrptr
;
10377 for (i
= 0; i
< augmentation_string_size
; i
++)
10381 SAFE_BYTE_GET_AND_INC (uc
, hdrptr
, 1, unit_end
);
10382 printf (" %02x", uc
);
10384 if (uc
!= 0 && !ISPRINT (uc
))
10385 augmentation_printable
= false;
10388 if (augmentation_printable
)
10392 i
< augmentation_string_size
&& augmentation_string
[i
];
10394 putchar (augmentation_string
[i
]);
10399 printf (_("CU table:\n"));
10400 if (_mul_overflow (comp_unit_count
, offset_size
, &total
)
10401 || total
> (size_t) (unit_end
- hdrptr
))
10403 for (i
= 0; i
< comp_unit_count
; i
++)
10405 uint64_t cu_offset
;
10407 SAFE_BYTE_GET_AND_INC (cu_offset
, hdrptr
, offset_size
, unit_end
);
10408 printf ("[%3u] %#" PRIx64
"\n", i
, cu_offset
);
10412 printf (_("TU table:\n"));
10413 if (_mul_overflow (local_type_unit_count
, offset_size
, &total
)
10414 || total
> (size_t) (unit_end
- hdrptr
))
10416 for (i
= 0; i
< local_type_unit_count
; i
++)
10418 uint64_t tu_offset
;
10420 SAFE_BYTE_GET_AND_INC (tu_offset
, hdrptr
, offset_size
, unit_end
);
10421 printf ("[%3u] %#" PRIx64
"\n", i
, tu_offset
);
10425 printf (_("Foreign TU table:\n"));
10426 if (_mul_overflow (foreign_type_unit_count
, 8, &total
)
10427 || total
> (size_t) (unit_end
- hdrptr
))
10429 for (i
= 0; i
< foreign_type_unit_count
; i
++)
10431 uint64_t signature
;
10433 SAFE_BYTE_GET_AND_INC (signature
, hdrptr
, 8, unit_end
);
10434 printf (_("[%3u] "), i
);
10435 print_hex_ns (signature
, 8);
10440 uint64_t xtra
= (bucket_count
* sizeof (uint32_t)
10441 + name_count
* (sizeof (uint32_t) + 2 * offset_size
)
10442 + abbrev_table_size
);
10443 if (xtra
> (size_t) (unit_end
- hdrptr
))
10445 warn (_("Entry pool offset (%#" PRIx64
") exceeds unit size %#tx "
10446 "for unit %#tx in the debug_names\n"),
10447 xtra
, unit_end
- unit_start
, unit_start
- section
->start
);
10450 const uint32_t *const hash_table_buckets
= (uint32_t *) hdrptr
;
10451 hdrptr
+= bucket_count
* sizeof (uint32_t);
10452 const uint32_t *const hash_table_hashes
= (uint32_t *) hdrptr
;
10453 hdrptr
+= name_count
* sizeof (uint32_t);
10454 unsigned char *const name_table_string_offsets
= hdrptr
;
10455 hdrptr
+= name_count
* offset_size
;
10456 unsigned char *const name_table_entry_offsets
= hdrptr
;
10457 hdrptr
+= name_count
* offset_size
;
10458 unsigned char *const abbrev_table
= hdrptr
;
10459 hdrptr
+= abbrev_table_size
;
10460 const unsigned char *const abbrev_table_end
= hdrptr
;
10461 unsigned char *const entry_pool
= hdrptr
;
10463 size_t buckets_filled
= 0;
10465 for (bucketi
= 0; bucketi
< bucket_count
; bucketi
++)
10467 const uint32_t bucket
= hash_table_buckets
[bucketi
];
10472 printf (ngettext ("Used %zu of %lu bucket.\n",
10473 "Used %zu of %lu buckets.\n",
10474 (unsigned long) bucket_count
),
10475 buckets_filled
, (unsigned long) bucket_count
);
10477 if (bucket_count
!= 0)
10479 uint32_t hash_prev
= 0;
10480 size_t hash_clash_count
= 0;
10481 size_t longest_clash
= 0;
10482 size_t this_length
= 0;
10484 for (hashi
= 0; hashi
< name_count
; hashi
++)
10486 const uint32_t hash_this
= hash_table_hashes
[hashi
];
10490 if (hash_prev
% bucket_count
== hash_this
% bucket_count
)
10492 ++hash_clash_count
;
10494 longest_clash
= MAX (longest_clash
, this_length
);
10499 hash_prev
= hash_this
;
10501 printf (_("Out of %" PRIu64
" items there are %zu bucket clashes"
10502 " (longest of %zu entries).\n"),
10503 name_count
, hash_clash_count
, longest_clash
);
10505 if (name_count
!= buckets_filled
+ hash_clash_count
)
10506 warn (_("The name_count (%" PRIu64
")"
10507 " is not the same as the used bucket_count"
10508 " (%zu) + the hash clash count (%zu)"),
10509 name_count
, buckets_filled
, hash_clash_count
);
10512 struct abbrev_lookup_entry
10514 uint64_t abbrev_tag
;
10515 unsigned char *abbrev_lookup_ptr
;
10517 struct abbrev_lookup_entry
*abbrev_lookup
= NULL
;
10518 size_t abbrev_lookup_used
= 0;
10519 size_t abbrev_lookup_allocated
= 0;
10521 unsigned char *abbrevptr
= abbrev_table
;
10524 uint64_t abbrev_tag
;
10526 READ_ULEB (abbrev_tag
, abbrevptr
, abbrev_table_end
);
10527 if (abbrev_tag
== 0)
10529 if (abbrev_lookup_used
== abbrev_lookup_allocated
)
10531 abbrev_lookup_allocated
= MAX (0x100,
10532 abbrev_lookup_allocated
* 2);
10533 abbrev_lookup
= xrealloc (abbrev_lookup
,
10534 (abbrev_lookup_allocated
10535 * sizeof (*abbrev_lookup
)));
10537 assert (abbrev_lookup_used
< abbrev_lookup_allocated
);
10538 struct abbrev_lookup_entry
*entry
;
10539 for (entry
= abbrev_lookup
;
10540 entry
< abbrev_lookup
+ abbrev_lookup_used
;
10542 if (entry
->abbrev_tag
== abbrev_tag
)
10544 warn (_("Duplicate abbreviation tag %" PRIu64
10545 " in unit %#tx in the debug_names section\n"),
10546 abbrev_tag
, unit_start
- section
->start
);
10549 entry
= &abbrev_lookup
[abbrev_lookup_used
++];
10550 entry
->abbrev_tag
= abbrev_tag
;
10551 entry
->abbrev_lookup_ptr
= abbrevptr
;
10553 /* Skip DWARF tag. */
10554 SKIP_ULEB (abbrevptr
, abbrev_table_end
);
10557 uint64_t xindex
, form
;
10559 READ_ULEB (xindex
, abbrevptr
, abbrev_table_end
);
10560 READ_ULEB (form
, abbrevptr
, abbrev_table_end
);
10561 if (xindex
== 0 && form
== 0)
10566 printf (_("\nSymbol table:\n"));
10568 for (namei
= 0; namei
< name_count
; ++namei
)
10570 uint64_t string_offset
, entry_offset
;
10573 p
= name_table_string_offsets
+ namei
* offset_size
;
10574 SAFE_BYTE_GET (string_offset
, p
, offset_size
, unit_end
);
10575 p
= name_table_entry_offsets
+ namei
* offset_size
;
10576 SAFE_BYTE_GET (entry_offset
, p
, offset_size
, unit_end
);
10578 printf ("[%3u] #%08x %s:", namei
, hash_table_hashes
[namei
],
10579 fetch_indirect_string (string_offset
));
10581 unsigned char *entryptr
= entry_pool
+ entry_offset
;
10583 /* We need to scan first whether there is a single or multiple
10584 entries. TAGNO is -2 for the first entry, it is -1 for the
10585 initial tag read of the second entry, then it becomes 0 for the
10586 first entry for real printing etc. */
10588 /* Initialize it due to a false compiler warning. */
10589 uint64_t second_abbrev_tag
= -1;
10592 uint64_t abbrev_tag
;
10593 uint64_t dwarf_tag
;
10594 const struct abbrev_lookup_entry
*entry
;
10596 READ_ULEB (abbrev_tag
, entryptr
, unit_end
);
10599 second_abbrev_tag
= abbrev_tag
;
10601 entryptr
= entry_pool
+ entry_offset
;
10604 if (abbrev_tag
== 0)
10607 printf ("%s<%" PRIu64
">",
10608 (tagno
== 0 && second_abbrev_tag
== 0 ? " " : "\n\t"),
10611 for (entry
= abbrev_lookup
;
10612 entry
< abbrev_lookup
+ abbrev_lookup_used
;
10614 if (entry
->abbrev_tag
== abbrev_tag
)
10616 if (entry
>= abbrev_lookup
+ abbrev_lookup_used
)
10618 warn (_("Undefined abbreviation tag %" PRId64
10619 " in unit %#tx in the debug_names section\n"),
10621 unit_start
- section
->start
);
10624 abbrevptr
= entry
->abbrev_lookup_ptr
;
10625 READ_ULEB (dwarf_tag
, abbrevptr
, abbrev_table_end
);
10627 printf (" %s", get_TAG_name (dwarf_tag
));
10630 uint64_t xindex
, form
;
10632 READ_ULEB (xindex
, abbrevptr
, abbrev_table_end
);
10633 READ_ULEB (form
, abbrevptr
, abbrev_table_end
);
10634 if (xindex
== 0 && form
== 0)
10638 printf (" %s", get_IDX_name (xindex
));
10639 entryptr
= read_and_display_attr_value (0, form
, 0,
10640 unit_start
, entryptr
, unit_end
,
10642 dwarf_version
, NULL
,
10643 (tagno
< 0), section
,
10649 printf (_(" <no entries>"));
10653 free (abbrev_lookup
);
10660 display_debug_links (struct dwarf_section
* section
,
10661 void * file ATTRIBUTE_UNUSED
)
10663 const unsigned char * filename
;
10664 unsigned int filelen
;
10666 introduce (section
, false);
10668 /* The .gnu_debuglink section is formatted as:
10669 (c-string) Filename.
10670 (padding) If needed to reach a 4 byte boundary.
10671 (uint32_t) CRC32 value.
10673 The .gun_debugaltlink section is formatted as:
10674 (c-string) Filename.
10675 (binary) Build-ID. */
10677 filename
= section
->start
;
10678 filelen
= strnlen ((const char *) filename
, section
->size
);
10679 if (filelen
== section
->size
)
10681 warn (_("The debuglink filename is corrupt/missing\n"));
10685 printf (_(" Separate debug info file: %s\n"), filename
);
10687 if (startswith (section
->name
, ".gnu_debuglink"))
10689 unsigned int crc32
;
10690 unsigned int crc_offset
;
10692 crc_offset
= filelen
+ 1;
10693 crc_offset
= (crc_offset
+ 3) & ~3;
10694 if (crc_offset
+ 4 > section
->size
)
10696 warn (_("CRC offset missing/truncated\n"));
10700 crc32
= byte_get (filename
+ crc_offset
, 4);
10702 printf (_(" CRC value: %#x\n"), crc32
);
10704 if (crc_offset
+ 4 < section
->size
)
10706 warn (_("There are %#" PRIx64
10707 " extraneous bytes at the end of the section\n"),
10708 section
->size
- (crc_offset
+ 4));
10712 else /* startswith (section->name, ".gnu_debugaltlink") */
10714 const unsigned char *build_id
= section
->start
+ filelen
+ 1;
10715 size_t build_id_len
= section
->size
- (filelen
+ 1);
10718 /* FIXME: Should we support smaller build-id notes ? */
10719 if (build_id_len
< 0x14)
10721 warn (_("Build-ID is too short (%#zx bytes)\n"), build_id_len
);
10725 printed
= printf (_(" Build-ID (%#zx bytes):"), build_id_len
);
10726 display_data (printed
, build_id
, build_id_len
);
10735 display_gdb_index (struct dwarf_section
*section
,
10736 void *file ATTRIBUTE_UNUSED
)
10738 unsigned char *start
= section
->start
;
10740 uint32_t cu_list_offset
, tu_list_offset
;
10741 uint32_t address_table_offset
, symbol_table_offset
, constant_pool_offset
;
10742 unsigned int cu_list_elements
, tu_list_elements
;
10743 unsigned int address_table_elements
, symbol_table_slots
;
10744 unsigned char *cu_list
, *tu_list
;
10745 unsigned char *address_table
, *symbol_table
, *constant_pool
;
10748 /* The documentation for the format of this file is in gdb/dwarf2read.c. */
10750 introduce (section
, false);
10752 if (section
->size
< 6 * sizeof (uint32_t))
10754 warn (_("Truncated header in the %s section.\n"), section
->name
);
10758 version
= byte_get_little_endian (start
, 4);
10759 printf (_("Version %lu\n"), (unsigned long) version
);
10761 /* Prior versions are obsolete, and future versions may not be
10762 backwards compatible. */
10763 if (version
< 3 || version
> 8)
10765 warn (_("Unsupported version %lu.\n"), (unsigned long) version
);
10769 warn (_("The address table data in version 3 may be wrong.\n"));
10771 warn (_("Version 4 does not support case insensitive lookups.\n"));
10773 warn (_("Version 5 does not include inlined functions.\n"));
10775 warn (_("Version 6 does not include symbol attributes.\n"));
10776 /* Version 7 indices generated by Gold have bad type unit references,
10777 PR binutils/15021. But we don't know if the index was generated by
10778 Gold or not, so to avoid worrying users with gdb-generated indices
10779 we say nothing for version 7 here. */
10781 cu_list_offset
= byte_get_little_endian (start
+ 4, 4);
10782 tu_list_offset
= byte_get_little_endian (start
+ 8, 4);
10783 address_table_offset
= byte_get_little_endian (start
+ 12, 4);
10784 symbol_table_offset
= byte_get_little_endian (start
+ 16, 4);
10785 constant_pool_offset
= byte_get_little_endian (start
+ 20, 4);
10787 if (cu_list_offset
> section
->size
10788 || tu_list_offset
> section
->size
10789 || address_table_offset
> section
->size
10790 || symbol_table_offset
> section
->size
10791 || constant_pool_offset
> section
->size
10792 || tu_list_offset
< cu_list_offset
10793 || address_table_offset
< tu_list_offset
10794 || symbol_table_offset
< address_table_offset
10795 || constant_pool_offset
< symbol_table_offset
)
10797 warn (_("Corrupt header in the %s section.\n"), section
->name
);
10801 cu_list_elements
= (tu_list_offset
- cu_list_offset
) / 16;
10802 tu_list_elements
= (address_table_offset
- tu_list_offset
) / 24;
10803 address_table_elements
= (symbol_table_offset
- address_table_offset
) / 20;
10804 symbol_table_slots
= (constant_pool_offset
- symbol_table_offset
) / 8;
10806 cu_list
= start
+ cu_list_offset
;
10807 tu_list
= start
+ tu_list_offset
;
10808 address_table
= start
+ address_table_offset
;
10809 symbol_table
= start
+ symbol_table_offset
;
10810 constant_pool
= start
+ constant_pool_offset
;
10812 printf (_("\nCU table:\n"));
10813 for (i
= 0; i
< cu_list_elements
; i
++)
10815 uint64_t cu_offset
= byte_get_little_endian (cu_list
+ i
* 16, 8);
10816 uint64_t cu_length
= byte_get_little_endian (cu_list
+ i
* 16 + 8, 8);
10818 printf ("[%3u] %#" PRIx64
" - %#" PRIx64
"\n",
10819 i
, cu_offset
, cu_offset
+ cu_length
- 1);
10822 printf (_("\nTU table:\n"));
10823 for (i
= 0; i
< tu_list_elements
; i
++)
10825 uint64_t tu_offset
= byte_get_little_endian (tu_list
+ i
* 24, 8);
10826 uint64_t type_offset
= byte_get_little_endian (tu_list
+ i
* 24 + 8, 8);
10827 uint64_t signature
= byte_get_little_endian (tu_list
+ i
* 24 + 16, 8);
10829 printf ("[%3u] %#" PRIx64
" %#" PRIx64
" ",
10830 i
, tu_offset
, type_offset
);
10831 print_hex_ns (signature
, 8);
10835 printf (_("\nAddress table:\n"));
10836 for (i
= 0; i
< address_table_elements
; i
++)
10838 uint64_t low
= byte_get_little_endian (address_table
+ i
* 20, 8);
10839 uint64_t high
= byte_get_little_endian (address_table
+ i
* 20 + 8, 8);
10840 uint32_t cu_index
= byte_get_little_endian (address_table
+ i
* 20 + 16, 4);
10842 print_hex (low
, 8);
10843 print_hex (high
, 8);
10844 printf ("%" PRIu32
"\n", cu_index
);
10847 printf (_("\nSymbol table:\n"));
10848 for (i
= 0; i
< symbol_table_slots
; ++i
)
10850 uint32_t name_offset
= byte_get_little_endian (symbol_table
+ i
* 8, 4);
10851 uint32_t cu_vector_offset
= byte_get_little_endian (symbol_table
+ i
* 8 + 4, 4);
10852 uint32_t num_cus
, cu
;
10854 if (name_offset
!= 0
10855 || cu_vector_offset
!= 0)
10859 /* PR 17531: file: 5b7b07ad. */
10860 if (name_offset
>= section
->size
- constant_pool_offset
)
10862 printf (_("[%3u] <corrupt offset: %x>"), i
, name_offset
);
10863 warn (_("Corrupt name offset of 0x%x found for symbol table slot %d\n"),
10867 printf ("[%3u] %.*s:", i
,
10868 (int) (section
->size
- (constant_pool_offset
+ name_offset
)),
10869 constant_pool
+ name_offset
);
10871 if (section
->size
- constant_pool_offset
< 4
10872 || cu_vector_offset
> section
->size
- constant_pool_offset
- 4)
10874 printf (_("<invalid CU vector offset: %x>\n"), cu_vector_offset
);
10875 warn (_("Corrupt CU vector offset of 0x%x found for symbol table slot %d\n"),
10876 cu_vector_offset
, i
);
10880 num_cus
= byte_get_little_endian (constant_pool
+ cu_vector_offset
, 4);
10882 if ((uint64_t) num_cus
* 4 > section
->size
- (constant_pool_offset
10883 + cu_vector_offset
+ 4))
10885 printf ("<invalid number of CUs: %d>\n", num_cus
);
10886 warn (_("Invalid number of CUs (0x%x) for symbol table slot %d\n"),
10894 for (j
= 0; j
< num_cus
; ++j
)
10897 gdb_index_symbol_kind kind
;
10899 cu
= byte_get_little_endian (constant_pool
+ cu_vector_offset
+ 4 + j
* 4, 4);
10900 is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu
);
10901 kind
= GDB_INDEX_SYMBOL_KIND_VALUE (cu
);
10902 cu
= GDB_INDEX_CU_VALUE (cu
);
10903 /* Convert to TU number if it's for a type unit. */
10904 if (cu
>= cu_list_elements
)
10905 printf ("%cT%lu", num_cus
> 1 ? '\t' : ' ',
10906 (unsigned long) cu
- cu_list_elements
);
10908 printf ("%c%lu", num_cus
> 1 ? '\t' : ' ', (unsigned long) cu
);
10910 printf (" [%s, %s]",
10911 is_static
? _("static") : _("global"),
10912 get_gdb_index_symbol_kind_name (kind
));
10924 /* Pre-allocate enough space for the CU/TU sets needed. */
10927 prealloc_cu_tu_list (unsigned int nshndx
)
10930 /* Always allocate at least one entry for the end-marker. */
10933 if (shndx_pool
== NULL
)
10935 shndx_pool_size
= nshndx
;
10936 shndx_pool_used
= 0;
10937 shndx_pool
= (unsigned int *) xcmalloc (shndx_pool_size
,
10938 sizeof (unsigned int));
10942 shndx_pool_size
= shndx_pool_used
+ nshndx
;
10943 shndx_pool
= (unsigned int *) xcrealloc (shndx_pool
, shndx_pool_size
,
10944 sizeof (unsigned int));
10949 add_shndx_to_cu_tu_entry (unsigned int shndx
)
10951 shndx_pool
[shndx_pool_used
++] = shndx
;
10955 end_cu_tu_entry (void)
10957 shndx_pool
[shndx_pool_used
++] = 0;
10960 /* Return the short name of a DWARF section given by a DW_SECT enumerator. */
10962 static const char *
10963 get_DW_SECT_short_name (unsigned int dw_sect
)
10965 static char buf
[16];
10971 case DW_SECT_TYPES
:
10973 case DW_SECT_ABBREV
:
10979 case DW_SECT_STR_OFFSETS
:
10981 case DW_SECT_MACINFO
:
10983 case DW_SECT_MACRO
:
10989 snprintf (buf
, sizeof (buf
), "%d", dw_sect
);
10993 /* Process a CU or TU index. If DO_DISPLAY is true, print the contents.
10994 These sections are extensions for Fission.
10995 See http://gcc.gnu.org/wiki/DebugFissionDWP. */
10998 process_cu_tu_index (struct dwarf_section
*section
, int do_display
)
11000 unsigned char *phdr
= section
->start
;
11001 unsigned char *limit
= phdr
+ section
->size
;
11002 unsigned char *phash
;
11003 unsigned char *pindex
;
11004 unsigned char *ppool
;
11005 unsigned int version
;
11006 unsigned int ncols
= 0;
11007 unsigned int nused
;
11008 unsigned int nslots
;
11011 uint64_t signature
;
11014 /* PR 17512: file: 002-168123-0.004. */
11017 warn (_("Section %s is empty\n"), section
->name
);
11020 /* PR 17512: file: 002-376-0.004. */
11021 if (section
->size
< 24)
11023 warn (_("Section %s is too small to contain a CU/TU header\n"),
11029 SAFE_BYTE_GET_AND_INC (version
, phash
, 4, limit
);
11031 SAFE_BYTE_GET_AND_INC (ncols
, phash
, 4, limit
);
11032 SAFE_BYTE_GET_AND_INC (nused
, phash
, 4, limit
);
11033 SAFE_BYTE_GET_AND_INC (nslots
, phash
, 4, limit
);
11035 pindex
= phash
+ (size_t) nslots
* 8;
11036 ppool
= pindex
+ (size_t) nslots
* 4;
11040 introduce (section
, false);
11042 printf (_(" Version: %u\n"), version
);
11044 printf (_(" Number of columns: %u\n"), ncols
);
11045 printf (_(" Number of used entries: %u\n"), nused
);
11046 printf (_(" Number of slots: %u\n\n"), nslots
);
11049 /* PR 17531: file: 45d69832. */
11050 if (_mul_overflow ((size_t) nslots
, 12, &total
)
11051 || total
> (size_t) (limit
- phash
))
11053 warn (ngettext ("Section %s is too small for %u slot\n",
11054 "Section %s is too small for %u slots\n",
11056 section
->name
, nslots
);
11062 unsigned char *shndx_list
;
11063 unsigned int shndx
;
11067 prealloc_cu_tu_list ((limit
- ppool
) / 4);
11068 for (shndx_list
= ppool
+ 4; shndx_list
<= limit
- 4; shndx_list
+= 4)
11070 shndx
= byte_get (shndx_list
, 4);
11071 add_shndx_to_cu_tu_entry (shndx
);
11073 end_cu_tu_entry ();
11076 for (i
= 0; i
< nslots
; i
++)
11078 SAFE_BYTE_GET (signature
, phash
, 8, limit
);
11079 if (signature
!= 0)
11081 SAFE_BYTE_GET (j
, pindex
, 4, limit
);
11082 shndx_list
= ppool
+ j
* 4;
11083 /* PR 17531: file: 705e010d. */
11084 if (shndx_list
< ppool
)
11086 warn (_("Section index pool located before start of section\n"));
11090 printf (_(" [%3d] Signature: %#" PRIx64
" Sections: "),
11094 if (shndx_list
>= limit
)
11096 warn (_("Section %s too small for shndx pool\n"),
11100 SAFE_BYTE_GET (shndx
, shndx_list
, 4, limit
);
11103 printf (" %d", shndx
);
11112 else if (version
== 2)
11115 unsigned int dw_sect
;
11116 unsigned char *ph
= phash
;
11117 unsigned char *pi
= pindex
;
11118 unsigned char *poffsets
= ppool
+ (size_t) ncols
* 4;
11119 unsigned char *psizes
= poffsets
+ (size_t) nused
* ncols
* 4;
11121 struct cu_tu_set
*this_set
= NULL
;
11123 unsigned char *prow
;
11126 is_tu_index
= strcmp (section
->name
, ".debug_tu_index") == 0;
11128 /* PR 17531: file: 0dd159bf.
11129 Check for integer overflow (can occur when size_t is 32-bit)
11130 with overlarge ncols or nused values. */
11132 || _mul_overflow ((size_t) ncols
, 4, &temp
)
11133 || _mul_overflow ((size_t) nused
+ 1, temp
, &total
)
11134 || total
> (size_t) (limit
- ppool
)
11135 /* PR 30227: ncols could be 0. */
11136 || _mul_overflow ((size_t) nused
+ 1, 4, &total
)
11137 || total
> (size_t) (limit
- ppool
))
11139 warn (_("Section %s too small for offset and size tables\n"),
11146 printf (_(" Offset table\n"));
11147 printf (" slot %-16s ",
11148 is_tu_index
? _("signature") : _("dwo_id"));
11155 tu_sets
= xcalloc2 (nused
, sizeof (struct cu_tu_set
));
11156 this_set
= tu_sets
;
11161 cu_sets
= xcalloc2 (nused
, sizeof (struct cu_tu_set
));
11162 this_set
= cu_sets
;
11168 for (j
= 0; j
< ncols
; j
++)
11170 unsigned char *p
= ppool
+ j
* 4;
11171 SAFE_BYTE_GET (dw_sect
, p
, 4, limit
);
11172 printf (" %8s", get_DW_SECT_short_name (dw_sect
));
11177 for (i
= 0; i
< nslots
; i
++)
11179 SAFE_BYTE_GET (signature
, ph
, 8, limit
);
11181 SAFE_BYTE_GET (row
, pi
, 4, limit
);
11184 /* PR 17531: file: a05f6ab3. */
11187 warn (_("Row index (%u) is larger than number of used entries (%u)\n"),
11194 size_t num_copy
= sizeof (uint64_t);
11196 memcpy (&this_set
[row
- 1].signature
, ph
, num_copy
);
11199 prow
= poffsets
+ (row
- 1) * ncols
* 4;
11201 printf (" [%3d] %#" PRIx64
, i
, signature
);
11202 for (j
= 0; j
< ncols
; j
++)
11204 unsigned char *p
= prow
+ j
* 4;
11205 SAFE_BYTE_GET (val
, p
, 4, limit
);
11207 printf (" %8d", val
);
11211 SAFE_BYTE_GET (dw_sect
, p
, 4, limit
);
11213 /* PR 17531: file: 10796eb3. */
11214 if (dw_sect
>= DW_SECT_MAX
)
11215 warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect
);
11217 this_set
[row
- 1].section_offsets
[dw_sect
] = val
;
11233 printf (_(" Size table\n"));
11234 printf (" slot %-16s ",
11235 is_tu_index
? _("signature") : _("dwo_id"));
11238 for (j
= 0; j
< ncols
; j
++)
11240 unsigned char *p
= ppool
+ j
* 4;
11241 SAFE_BYTE_GET (val
, p
, 4, limit
);
11243 printf (" %8s", get_DW_SECT_short_name (val
));
11249 for (i
= 0; i
< nslots
; i
++)
11251 SAFE_BYTE_GET (signature
, ph
, 8, limit
);
11253 SAFE_BYTE_GET (row
, pi
, 4, limit
);
11256 prow
= psizes
+ (row
- 1) * ncols
* 4;
11259 printf (" [%3d] %#" PRIx64
, i
, signature
);
11261 for (j
= 0; j
< ncols
; j
++)
11263 unsigned char *p
= prow
+ j
* 4;
11265 /* PR 28645: Check for overflow. Since we do not know how
11266 many populated rows there will be, we cannot just
11267 perform a single check at the start of this function. */
11268 if (p
> (limit
- 4))
11272 warn (_("Too many rows/columns in DWARF index section %s\n"),
11277 SAFE_BYTE_GET (val
, p
, 4, limit
);
11280 printf (" %8d", val
);
11284 SAFE_BYTE_GET (dw_sect
, p
, 4, limit
);
11285 if (dw_sect
>= DW_SECT_MAX
)
11286 warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect
);
11288 this_set
[row
- 1].section_sizes
[dw_sect
] = val
;
11300 else if (do_display
)
11301 printf (_(" Unsupported version (%d)\n"), version
);
11309 static int cu_tu_indexes_read
= -1; /* Tri-state variable. */
11311 /* Load the CU and TU indexes if present. This will build a list of
11312 section sets that we can use to associate a .debug_info.dwo section
11313 with its associated .debug_abbrev.dwo section in a .dwp file. */
11316 load_cu_tu_indexes (void *file
)
11318 /* If we have already loaded (or tried to load) the CU and TU indexes
11319 then do not bother to repeat the task. */
11320 if (cu_tu_indexes_read
== -1)
11322 cu_tu_indexes_read
= true;
11324 if (load_debug_section_with_follow (dwp_cu_index
, file
))
11325 if (! process_cu_tu_index (&debug_displays
[dwp_cu_index
].section
, 0))
11326 cu_tu_indexes_read
= false;
11328 if (load_debug_section_with_follow (dwp_tu_index
, file
))
11329 if (! process_cu_tu_index (&debug_displays
[dwp_tu_index
].section
, 0))
11330 cu_tu_indexes_read
= false;
11333 return (bool) cu_tu_indexes_read
;
11336 /* Find the set of sections that includes section SHNDX. */
11339 find_cu_tu_set (void *file
, unsigned int shndx
)
11343 if (! load_cu_tu_indexes (file
))
11346 /* Find SHNDX in the shndx pool. */
11347 for (i
= 0; i
< shndx_pool_used
; i
++)
11348 if (shndx_pool
[i
] == shndx
)
11351 if (i
>= shndx_pool_used
)
11354 /* Now backup to find the first entry in the set. */
11355 while (i
> 0 && shndx_pool
[i
- 1] != 0)
11358 return shndx_pool
+ i
;
11361 /* Display a .debug_cu_index or .debug_tu_index section. */
11364 display_cu_index (struct dwarf_section
*section
, void *file ATTRIBUTE_UNUSED
)
11366 return process_cu_tu_index (section
, 1);
11370 display_debug_not_supported (struct dwarf_section
*section
,
11371 void *file ATTRIBUTE_UNUSED
)
11373 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
11379 /* Like malloc, but takes two parameters like calloc.
11380 Verifies that the first parameter is not too large.
11381 Note: does *not* initialise the allocated memory to zero. */
11384 cmalloc (uint64_t nmemb
, size_t size
)
11386 /* Check for overflow. */
11387 if (nmemb
>= ~(size_t) 0 / size
)
11390 return xmalloc (nmemb
* size
);
11393 /* Like xmalloc, but takes two parameters like calloc.
11394 Verifies that the first parameter is not too large.
11395 Note: does *not* initialise the allocated memory to zero. */
11398 xcmalloc (uint64_t nmemb
, size_t size
)
11400 /* Check for overflow. */
11401 if (nmemb
>= ~(size_t) 0 / size
)
11404 _("Attempt to allocate an array with an excessive number of elements: %#" PRIx64
"\n"),
11409 return xmalloc (nmemb
* size
);
11412 /* Like xrealloc, but takes three parameters.
11413 Verifies that the second parameter is not too large.
11414 Note: does *not* initialise any new memory to zero. */
11417 xcrealloc (void *ptr
, uint64_t nmemb
, size_t size
)
11419 /* Check for overflow. */
11420 if (nmemb
>= ~(size_t) 0 / size
)
11422 error (_("Attempt to re-allocate an array with an excessive number of elements: %#" PRIx64
"\n"),
11427 return xrealloc (ptr
, nmemb
* size
);
11430 /* Like xcalloc, but verifies that the first parameter is not too large. */
11433 xcalloc2 (uint64_t nmemb
, size_t size
)
11435 /* Check for overflow. */
11436 if (nmemb
>= ~(size_t) 0 / size
)
11438 error (_("Attempt to allocate a zero'ed array with an excessive number of elements: %#" PRIx64
"\n"),
11443 return xcalloc (nmemb
, size
);
11446 static unsigned long
11447 calc_gnu_debuglink_crc32 (unsigned long crc
,
11448 const unsigned char *buf
,
11451 static const unsigned long crc32_table
[256] =
11453 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
11454 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
11455 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
11456 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
11457 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
11458 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
11459 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
11460 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
11461 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
11462 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
11463 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
11464 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
11465 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
11466 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
11467 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
11468 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
11469 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
11470 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
11471 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
11472 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
11473 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
11474 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
11475 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
11476 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
11477 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
11478 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
11479 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
11480 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
11481 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
11482 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
11483 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
11484 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
11485 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
11486 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
11487 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
11488 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
11489 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
11490 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
11491 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
11492 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
11493 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
11494 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
11495 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
11496 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
11497 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
11498 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
11499 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
11500 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
11501 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
11502 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
11503 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
11506 const unsigned char *end
;
11508 crc
= ~crc
& 0xffffffff;
11509 for (end
= buf
+ len
; buf
< end
; ++ buf
)
11510 crc
= crc32_table
[(crc
^ *buf
) & 0xff] ^ (crc
>> 8);
11511 return ~crc
& 0xffffffff;
11514 typedef bool (*check_func_type
) (const char *, void *);
11515 typedef const char *(* parse_func_type
) (struct dwarf_section
*, void *);
11518 check_gnu_debuglink (const char * pathname
, void * crc_pointer
)
11520 static unsigned char buffer
[8 * 1024];
11523 unsigned long crc
= 0;
11526 sep_data
= open_debug_file (pathname
);
11527 if (sep_data
== NULL
)
11530 /* Yes - we are opening the file twice... */
11531 f
= fopen (pathname
, "rb");
11534 /* Paranoia: This should never happen. */
11535 close_debug_file (sep_data
);
11536 warn (_("Unable to reopen separate debug info file: %s\n"), pathname
);
11540 while ((count
= fread (buffer
, 1, sizeof (buffer
), f
)) > 0)
11541 crc
= calc_gnu_debuglink_crc32 (crc
, buffer
, count
);
11545 if (crc
!= * (unsigned long *) crc_pointer
)
11547 close_debug_file (sep_data
);
11548 warn (_("Separate debug info file %s found, but CRC does not match - ignoring\n"),
11556 static const char *
11557 parse_gnu_debuglink (struct dwarf_section
* section
, void * data
)
11560 unsigned int crc_offset
;
11561 unsigned long * crc32
= (unsigned long *) data
;
11563 /* The name is first.
11564 The CRC value is stored after the filename, aligned up to 4 bytes. */
11565 name
= (const char *) section
->start
;
11567 crc_offset
= strnlen (name
, section
->size
) + 1;
11568 if (crc_offset
== 1)
11570 crc_offset
= (crc_offset
+ 3) & ~3;
11571 if (crc_offset
+ 4 > section
->size
)
11574 * crc32
= byte_get (section
->start
+ crc_offset
, 4);
11579 check_gnu_debugaltlink (const char * filename
, void * data ATTRIBUTE_UNUSED
)
11581 void * sep_data
= open_debug_file (filename
);
11583 if (sep_data
== NULL
)
11586 /* FIXME: We should now extract the build-id in the separate file
11592 typedef struct build_id_data
11595 const unsigned char *data
;
11598 static const char *
11599 parse_gnu_debugaltlink (struct dwarf_section
* section
, void * data
)
11604 Build_id_data
*build_id_data
;
11606 /* The name is first.
11607 The build-id follows immediately, with no padding, up to the section's end. */
11609 name
= (const char *) section
->start
;
11610 namelen
= strnlen (name
, section
->size
) + 1;
11613 if (namelen
>= section
->size
)
11616 id_len
= section
->size
- namelen
;
11620 build_id_data
= (Build_id_data
*) data
;
11621 build_id_data
->len
= id_len
;
11622 build_id_data
->data
= section
->start
+ namelen
;
11628 add_separate_debug_file (const char * filename
, void * handle
)
11630 separate_info
* i
= xmalloc (sizeof * i
);
11632 i
->filename
= filename
;
11633 i
->handle
= handle
;
11634 i
->next
= first_separate_info
;
11635 first_separate_info
= i
;
11638 #if HAVE_LIBDEBUGINFOD
11639 /* Query debuginfod servers for the target debuglink or debugaltlink
11640 file. If successful, store the path of the file in filename and
11641 return TRUE, otherwise return FALSE. */
11644 debuginfod_fetch_separate_debug_info (struct dwarf_section
* section
,
11648 size_t build_id_len
;
11649 unsigned char * build_id
;
11651 if (strcmp (section
->uncompressed_name
, ".gnu_debuglink") == 0)
11653 /* Get the build-id of file. */
11654 build_id
= get_build_id (file
);
11657 else if (strcmp (section
->uncompressed_name
, ".gnu_debugaltlink") == 0)
11659 /* Get the build-id of the debugaltlink file. */
11660 unsigned int filelen
;
11662 filelen
= strnlen ((const char *)section
->start
, section
->size
);
11663 if (filelen
== section
->size
)
11664 /* Corrupt debugaltlink. */
11667 build_id
= section
->start
+ filelen
+ 1;
11668 build_id_len
= section
->size
- (filelen
+ 1);
11670 if (build_id_len
== 0)
11679 debuginfod_client
* client
;
11681 client
= debuginfod_begin ();
11682 if (client
== NULL
)
11685 /* Query debuginfod servers for the target file. If found its path
11686 will be stored in filename. */
11687 fd
= debuginfod_find_debuginfo (client
, build_id
, build_id_len
, filename
);
11688 debuginfod_end (client
);
11690 /* Only free build_id if we allocated space for a hex string
11691 in get_build_id (). */
11692 if (build_id_len
== 0)
11697 /* File successfully retrieved. Close fd since we want to
11698 use open_debug_file () on filename instead. */
11706 #endif /* HAVE_LIBDEBUGINFOD */
11709 load_separate_debug_info (const char * main_filename
,
11710 struct dwarf_section
* xlink
,
11711 parse_func_type parse_func
,
11712 check_func_type check_func
,
11714 void * file ATTRIBUTE_UNUSED
)
11716 const char * separate_filename
;
11717 char * debug_filename
;
11719 size_t canon_dirlen
;
11721 char * canon_filename
;
11722 char * canon_debug_filename
;
11725 if ((separate_filename
= parse_func (xlink
, func_data
)) == NULL
)
11727 warn (_("Corrupt debuglink section: %s\n"),
11728 xlink
->name
? xlink
->name
: xlink
->uncompressed_name
);
11732 /* Attempt to locate the separate file.
11733 This should duplicate the logic in bfd/opncls.c:find_separate_debug_file(). */
11735 canon_filename
= lrealpath (main_filename
);
11736 canon_dir
= xstrdup (canon_filename
);
11738 for (canon_dirlen
= strlen (canon_dir
); canon_dirlen
> 0; canon_dirlen
--)
11739 if (IS_DIR_SEPARATOR (canon_dir
[canon_dirlen
- 1]))
11741 canon_dir
[canon_dirlen
] = '\0';
11744 #define DEBUGDIR "/lib/debug"
11746 #ifndef EXTRA_DEBUG_ROOT1
11747 #define EXTRA_DEBUG_ROOT1 "/usr/lib/debug"
11749 #ifndef EXTRA_DEBUG_ROOT2
11750 #define EXTRA_DEBUG_ROOT2 "/usr/lib/debug/usr"
11753 debug_filename
= (char *) malloc (strlen (DEBUGDIR
) + 1
11755 + strlen (".debug/")
11756 #ifdef EXTRA_DEBUG_ROOT1
11757 + strlen (EXTRA_DEBUG_ROOT1
)
11759 #ifdef EXTRA_DEBUG_ROOT2
11760 + strlen (EXTRA_DEBUG_ROOT2
)
11762 + strlen (separate_filename
)
11764 if (debug_filename
== NULL
)
11766 warn (_("Out of memory"));
11768 free (canon_filename
);
11772 /* First try in the current directory. */
11773 sprintf (debug_filename
, "%s", separate_filename
);
11774 if (check_func (debug_filename
, func_data
))
11777 /* Then try in a subdirectory called .debug. */
11778 sprintf (debug_filename
, ".debug/%s", separate_filename
);
11779 if (check_func (debug_filename
, func_data
))
11782 /* Then try in the same directory as the original file. */
11783 sprintf (debug_filename
, "%s%s", canon_dir
, separate_filename
);
11784 if (check_func (debug_filename
, func_data
))
11787 /* And the .debug subdirectory of that directory. */
11788 sprintf (debug_filename
, "%s.debug/%s", canon_dir
, separate_filename
);
11789 if (check_func (debug_filename
, func_data
))
11792 #ifdef EXTRA_DEBUG_ROOT1
11793 /* Try the first extra debug file root. */
11794 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT1
, separate_filename
);
11795 if (check_func (debug_filename
, func_data
))
11798 /* Try the first extra debug file root. */
11799 sprintf (debug_filename
, "%s/%s/%s", EXTRA_DEBUG_ROOT1
, canon_dir
, separate_filename
);
11800 if (check_func (debug_filename
, func_data
))
11804 #ifdef EXTRA_DEBUG_ROOT2
11805 /* Try the second extra debug file root. */
11806 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT2
, separate_filename
);
11807 if (check_func (debug_filename
, func_data
))
11811 /* Then try in the global debug_filename directory. */
11812 strcpy (debug_filename
, DEBUGDIR
);
11813 dirlen
= strlen (DEBUGDIR
) - 1;
11814 if (dirlen
> 0 && DEBUGDIR
[dirlen
] != '/')
11815 strcat (debug_filename
, "/");
11816 strcat (debug_filename
, (const char *) separate_filename
);
11818 if (check_func (debug_filename
, func_data
))
11821 #if HAVE_LIBDEBUGINFOD
11823 char * tmp_filename
;
11826 && debuginfod_fetch_separate_debug_info (xlink
,
11830 /* File successfully downloaded from server, replace
11831 debug_filename with the file's path. */
11832 free (debug_filename
);
11833 debug_filename
= tmp_filename
;
11839 if (do_debug_links
)
11841 /* Failed to find the file. */
11842 warn (_("could not find separate debug file '%s'\n"),
11843 separate_filename
);
11844 warn (_("tried: %s\n"), debug_filename
);
11846 #ifdef EXTRA_DEBUG_ROOT2
11847 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT2
,
11848 separate_filename
);
11849 warn (_("tried: %s\n"), debug_filename
);
11852 #ifdef EXTRA_DEBUG_ROOT1
11853 sprintf (debug_filename
, "%s/%s/%s", EXTRA_DEBUG_ROOT1
,
11854 canon_dir
, separate_filename
);
11855 warn (_("tried: %s\n"), debug_filename
);
11857 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT1
,
11858 separate_filename
);
11859 warn (_("tried: %s\n"), debug_filename
);
11862 sprintf (debug_filename
, "%s.debug/%s", canon_dir
,
11863 separate_filename
);
11864 warn (_("tried: %s\n"), debug_filename
);
11866 sprintf (debug_filename
, "%s%s", canon_dir
, separate_filename
);
11867 warn (_("tried: %s\n"), debug_filename
);
11869 sprintf (debug_filename
, ".debug/%s", separate_filename
);
11870 warn (_("tried: %s\n"), debug_filename
);
11872 sprintf (debug_filename
, "%s", separate_filename
);
11873 warn (_("tried: %s\n"), debug_filename
);
11875 #if HAVE_LIBDEBUGINFOD
11876 if (use_debuginfod
)
11878 char *urls
= getenv (DEBUGINFOD_URLS_ENV_VAR
);
11883 warn (_("tried: DEBUGINFOD_URLS=%s\n"), urls
);
11889 free (debug_filename
);
11890 free (canon_filename
);
11896 canon_debug_filename
= lrealpath (debug_filename
);
11897 self
= strcmp (canon_debug_filename
, canon_filename
) == 0;
11898 free (canon_filename
);
11899 free (canon_debug_filename
);
11902 free (debug_filename
);
11906 void * debug_handle
;
11908 /* Now open the file.... */
11909 if ((debug_handle
= open_debug_file (debug_filename
)) == NULL
)
11911 warn (_("failed to open separate debug file: %s\n"), debug_filename
);
11912 free (debug_filename
);
11916 /* FIXME: We do not check to see if there are any other separate debug info
11917 files that would also match. */
11919 if (do_debug_links
)
11920 printf (_("\n%s: Found separate debug info file: %s\n"), main_filename
, debug_filename
);
11921 add_separate_debug_file (debug_filename
, debug_handle
);
11923 /* Do not free debug_filename - it might be referenced inside
11924 the structure returned by open_debug_file(). */
11925 return debug_handle
;
11928 /* Attempt to load a separate dwarf object file. */
11931 load_dwo_file (const char * main_filename
, const char * name
, const char * dir
, const char * id ATTRIBUTE_UNUSED
)
11933 char * separate_filename
;
11934 void * separate_handle
;
11936 if (IS_ABSOLUTE_PATH (name
))
11937 separate_filename
= strdup (name
);
11939 /* FIXME: Skip adding / if dwo_dir ends in /. */
11940 separate_filename
= concat (dir
, "/", name
, NULL
);
11941 if (separate_filename
== NULL
)
11943 warn (_("Out of memory allocating dwo filename\n"));
11947 if ((separate_handle
= open_debug_file (separate_filename
)) == NULL
)
11949 warn (_("Unable to load dwo file: %s\n"), separate_filename
);
11950 free (separate_filename
);
11954 /* FIXME: We should check the dwo_id. */
11956 printf (_("%s: Found separate debug object file: %s\n\n"), main_filename
, separate_filename
);
11958 add_separate_debug_file (separate_filename
, separate_handle
);
11959 /* Note - separate_filename will be freed in free_debug_memory(). */
11960 return separate_handle
;
11964 try_build_id_prefix (const char * prefix
, char * filename
, const unsigned char * data
, unsigned long id_len
)
11966 char * f
= filename
;
11968 f
+= sprintf (f
, "%s.build-id/%02x/", prefix
, (unsigned) *data
++);
11971 f
+= sprintf (f
, "%02x", (unsigned) *data
++);
11972 strcpy (f
, ".debug");
11974 return open_debug_file (filename
);
11977 /* Try to load a debug file based upon the build-id held in the .note.gnu.build-id section. */
11980 load_build_id_debug_file (const char * main_filename ATTRIBUTE_UNUSED
, void * main_file
)
11982 if (! load_debug_section (note_gnu_build_id
, main_file
))
11983 return; /* No .note.gnu.build-id section. */
11985 struct dwarf_section
* section
= & debug_displays
[note_gnu_build_id
].section
;
11986 if (section
== NULL
)
11988 warn (_("Unable to load the .note.gnu.build-id section\n"));
11992 if (section
->start
== NULL
|| section
->size
< 0x18)
11994 warn (_(".note.gnu.build-id section is corrupt/empty\n"));
11998 /* In theory we should extract the contents of the section into
11999 a note structure and then check the fields. For now though
12000 just use hard coded offsets instead:
12002 Field Bytes Contents
12005 Type 8..11 3 (NT_GNU_BUILD_ID)
12009 /* FIXME: Check the name size, name and type fields. */
12011 unsigned long build_id_size
;
12012 build_id_size
= byte_get (section
->start
+ 4, 4);
12013 if (build_id_size
< 8)
12015 warn (_(".note.gnu.build-id data size is too small\n"));
12019 if (build_id_size
> (section
->size
- 16))
12021 warn (_(".note.gnu.build-id data size is too big\n"));
12026 filename
= xmalloc (strlen (".build-id/")
12027 + build_id_size
* 2 + 2
12028 + strlen (".debug")
12029 /* The next string should be the same as the longest
12030 name found in the prefixes[] array below. */
12031 + strlen ("/usrlib64/debug/usr")
12035 static const char * prefixes
[] =
12040 "/usr/lib/debug/usr/",
12041 "/usr/lib64/debug/",
12042 "/usr/lib64/debug/usr"
12044 long unsigned int i
;
12046 for (i
= 0; i
< ARRAY_SIZE (prefixes
); i
++)
12048 handle
= try_build_id_prefix (prefixes
[i
], filename
,
12049 section
->start
+ 16, build_id_size
);
12050 if (handle
!= NULL
)
12053 /* FIXME: TYhe BFD library also tries a global debugfile directory prefix. */
12054 if (handle
== NULL
)
12056 /* Failed to find a debug file associated with the build-id.
12057 This is not an error however, rather it just means that
12058 the debug info has probably not been loaded on the system,
12059 or that another method is being used to link to the debug
12065 add_separate_debug_file (filename
, handle
);
12068 /* Try to load a debug file pointed to by the .debug_sup section. */
12071 load_debug_sup_file (const char * main_filename
, void * file
)
12073 if (! load_debug_section (debug_sup
, file
))
12074 return; /* No .debug_sup section. */
12076 struct dwarf_section
* section
;
12077 section
= & debug_displays
[debug_sup
].section
;
12078 assert (section
!= NULL
);
12080 if (section
->start
== NULL
|| section
->size
< 5)
12082 warn (_(".debug_sup section is corrupt/empty\n"));
12086 if (section
->start
[2] != 0)
12087 return; /* This is a supplementary file. */
12089 const char * filename
= (const char *) section
->start
+ 3;
12090 if (strnlen (filename
, section
->size
- 3) == section
->size
- 3)
12092 warn (_("filename in .debug_sup section is corrupt\n"));
12096 if (filename
[0] != '/' && strchr (main_filename
, '/'))
12101 new_len
= asprintf (& new_name
, "%.*s/%s",
12102 (int) (strrchr (main_filename
, '/') - main_filename
),
12107 warn (_("unable to construct path for supplementary debug file"));
12112 filename
= new_name
;
12116 /* PR 27796: Make sure that we pass a filename that can be free'd to
12117 add_separate_debug_file(). */
12118 filename
= strdup (filename
);
12119 if (filename
== NULL
)
12121 warn (_("out of memory constructing filename for .debug_sup link\n"));
12126 void * handle
= open_debug_file (filename
);
12127 if (handle
== NULL
)
12129 warn (_("unable to open file '%s' referenced from .debug_sup section\n"), filename
);
12130 free ((void *) filename
);
12134 printf (_("%s: Found supplementary debug file: %s\n\n"), main_filename
, filename
);
12136 /* FIXME: Compare the checksums, if present. */
12137 add_separate_debug_file (filename
, handle
);
12140 /* Load a debuglink section and/or a debugaltlink section, if either are present.
12141 Recursively check the loaded files for more of these sections.
12142 Also follow any links in .debug_sup sections.
12143 FIXME: Should also check for DWO_* entries in the newly loaded files. */
12146 check_for_and_load_links (void * file
, const char * filename
)
12148 void * handle
= NULL
;
12150 if (load_debug_section (gnu_debugaltlink
, file
))
12152 Build_id_data build_id_data
;
12154 handle
= load_separate_debug_info (filename
,
12155 & debug_displays
[gnu_debugaltlink
].section
,
12156 parse_gnu_debugaltlink
,
12157 check_gnu_debugaltlink
,
12162 assert (handle
== first_separate_info
->handle
);
12163 check_for_and_load_links (first_separate_info
->handle
,
12164 first_separate_info
->filename
);
12168 if (load_debug_section (gnu_debuglink
, file
))
12170 unsigned long crc32
;
12172 handle
= load_separate_debug_info (filename
,
12173 & debug_displays
[gnu_debuglink
].section
,
12174 parse_gnu_debuglink
,
12175 check_gnu_debuglink
,
12180 assert (handle
== first_separate_info
->handle
);
12181 check_for_and_load_links (first_separate_info
->handle
,
12182 first_separate_info
->filename
);
12186 load_debug_sup_file (filename
, file
);
12188 load_build_id_debug_file (filename
, file
);
12191 /* Load the separate debug info file(s) attached to FILE, if any exist.
12192 Returns TRUE if any were found, FALSE otherwise.
12193 If TRUE is returned then the linked list starting at first_separate_info
12194 will be populated with open file handles. */
12197 load_separate_debug_files (void * file
, const char * filename
)
12199 /* Skip this operation if we are not interested in debug links. */
12200 if (! do_follow_links
&& ! do_debug_links
)
12203 /* See if there are any dwo links. */
12204 if (load_debug_section (str
, file
)
12205 && load_debug_section (abbrev
, file
)
12206 && load_debug_section (info
, file
))
12208 /* Load the .debug_addr section, if it exists. */
12209 load_debug_section (debug_addr
, file
);
12210 /* Load the .debug_str_offsets section, if it exists. */
12211 load_debug_section (str_index
, file
);
12212 /* Load the .debug_loclists section, if it exists. */
12213 load_debug_section (loclists
, file
);
12214 /* Load the .debug_rnglists section, if it exists. */
12215 load_debug_section (rnglists
, file
);
12219 if (process_debug_info (& debug_displays
[info
].section
, file
, abbrev
,
12222 bool introduced
= false;
12224 const char *dir
= NULL
;
12225 const char *id
= NULL
;
12226 const char *name
= NULL
;
12228 for (dwinfo
= first_dwo_info
; dwinfo
!= NULL
; dwinfo
= dwinfo
->next
)
12230 /* Accumulate NAME, DIR and ID fields. */
12231 switch (dwinfo
->type
)
12235 warn (_("Multiple DWO_NAMEs encountered for the same CU\n"));
12236 name
= dwinfo
->value
;
12240 /* There can be multiple DW_AT_comp_dir entries in a CU,
12241 so do not complain. */
12242 dir
= dwinfo
->value
;
12247 warn (_("multiple DWO_IDs encountered for the same CU\n"));
12248 id
= dwinfo
->value
;
12252 error (_("Unexpected DWO INFO type"));
12256 /* If we have reached the end of our list, or we are changing
12257 CUs, then display the information that we have accumulated
12260 && (dwinfo
->next
== NULL
12261 || dwinfo
->next
->cu_offset
!= dwinfo
->cu_offset
))
12263 if (do_debug_links
)
12267 printf (_("The %s section contains link(s) to dwo file(s):\n\n"),
12268 debug_displays
[info
].section
.uncompressed_name
);
12272 printf (_(" Name: %s\n"), name
);
12273 printf (_(" Directory: %s\n"), dir
? dir
: _("<not-found>"));
12275 display_data (printf (_(" ID: ")), (unsigned char *) id
, 8);
12276 else if (debug_information
[0].dwarf_version
!= 5)
12277 printf (_(" ID: <not specified>\n"));
12281 if (do_follow_links
)
12282 load_dwo_file (filename
, name
, dir
, id
);
12284 name
= dir
= id
= NULL
;
12290 if (! do_follow_links
)
12291 /* The other debug links will be displayed by display_debug_links()
12292 so we do not need to do any further processing here. */
12295 /* FIXME: We do not check for the presence of both link sections in the same file. */
12296 /* FIXME: We do not check for the presence of multiple, same-name debuglink sections. */
12297 /* FIXME: We do not check for the presence of a dwo link as well as a debuglink. */
12299 check_for_and_load_links (file
, filename
);
12300 if (first_separate_info
!= NULL
)
12303 do_follow_links
= 0;
12308 free_debug_memory (void)
12312 free_all_abbrevs ();
12316 shndx_pool_size
= 0;
12317 shndx_pool_used
= 0;
12325 memset (level_type_signed
, 0, sizeof level_type_signed
);
12326 cu_tu_indexes_read
= -1;
12328 for (i
= 0; i
< max
; i
++)
12329 free_debug_section ((enum dwarf_section_display_enum
) i
);
12331 if (debug_information
!= NULL
)
12333 for (i
= 0; i
< alloc_num_debug_info_entries
; i
++)
12334 free_debug_information (&debug_information
[i
]);
12335 free (debug_information
);
12336 debug_information
= NULL
;
12337 alloc_num_debug_info_entries
= num_debug_info_entries
= 0;
12341 separate_info
* next
;
12343 for (d
= first_separate_info
; d
!= NULL
; d
= next
)
12345 close_debug_file (d
->handle
);
12346 free ((void *) d
->filename
);
12350 first_separate_info
= NULL
;
12358 const char *option
;
12361 } debug_dump_long_opts
;
12363 static const debug_dump_long_opts debug_option_table
[] =
12365 { 'A', "addr", &do_debug_addr
, 1 },
12366 { 'a', "abbrev", &do_debug_abbrevs
, 1 },
12367 { 'c', "cu_index", &do_debug_cu_index
, 1 },
12368 #ifdef HAVE_LIBDEBUGINFOD
12369 { 'D', "use-debuginfod", &use_debuginfod
, 1 },
12370 { 'E', "do-not-use-debuginfod", &use_debuginfod
, 0 },
12372 { 'F', "frames-interp", &do_debug_frames_interp
, 1 },
12373 { 'f', "frames", &do_debug_frames
, 1 },
12374 { 'g', "gdb_index", &do_gdb_index
, 1 },
12375 { 'i', "info", &do_debug_info
, 1 },
12376 { 'K', "follow-links", &do_follow_links
, 1 },
12377 { 'k', "links", &do_debug_links
, 1 },
12378 { 'L', "decodedline", &do_debug_lines
, FLAG_DEBUG_LINES_DECODED
},
12379 { 'l', "rawline", &do_debug_lines
, FLAG_DEBUG_LINES_RAW
},
12380 /* For compatibility with earlier versions of readelf. */
12381 { 'l', "line", &do_debug_lines
, FLAG_DEBUG_LINES_RAW
},
12382 { 'm', "macro", &do_debug_macinfo
, 1 },
12383 { 'N', "no-follow-links", &do_follow_links
, 0 },
12384 { 'O', "str-offsets", &do_debug_str_offsets
, 1 },
12385 { 'o', "loc", &do_debug_loc
, 1 },
12386 { 'p', "pubnames", &do_debug_pubnames
, 1 },
12387 { 'R', "Ranges", &do_debug_ranges
, 1 },
12388 { 'r', "aranges", &do_debug_aranges
, 1 },
12389 /* For compatibility with earlier versions of readelf. */
12390 { 'r', "ranges", &do_debug_aranges
, 1 },
12391 { 's', "str", &do_debug_str
, 1 },
12392 { 'T', "trace_aranges", &do_trace_aranges
, 1 },
12393 { 't', "pubtypes", &do_debug_pubtypes
, 1 },
12394 { 'U', "trace_info", &do_trace_info
, 1 },
12395 { 'u', "trace_abbrev", &do_trace_abbrevs
, 1 },
12396 { 0, NULL
, NULL
, 0 }
12399 /* Enable display of specific DWARF sections as determined by the comma
12400 separated strings in NAMES. Returns non-zero if any displaying was
12404 dwarf_select_sections_by_names (const char *names
)
12412 const debug_dump_long_opts
*entry
;
12414 for (entry
= debug_option_table
; entry
->option
; entry
++)
12416 size_t len
= strlen (entry
->option
);
12418 if (strncmp (p
, entry
->option
, len
) == 0
12419 && (p
[len
] == ',' || p
[len
] == '\0'))
12421 if (entry
->val
== 0)
12422 * entry
->variable
= 0;
12424 * entry
->variable
= entry
->val
;
12425 result
|= entry
->val
;
12432 if (entry
->option
== NULL
)
12434 warn (_("Unrecognized debug option '%s'\n"), p
);
12435 p
= strchr (p
, ',');
12444 /* The --debug-dump=frames-interp option also enables the
12445 --debug-dump=frames option. */
12446 if (do_debug_frames_interp
)
12447 do_debug_frames
= 1;
12452 /* Enable display of specific DWARF sections as determined by the characters
12453 in LETTERS. Returns non-zero if any displaying was enabled. */
12456 dwarf_select_sections_by_letters (const char *letters
)
12462 const debug_dump_long_opts
*entry
;
12464 for (entry
= debug_option_table
; entry
->letter
; entry
++)
12466 if (entry
->letter
== * letters
)
12468 if (entry
->val
== 0)
12469 * entry
->variable
= 0;
12471 * entry
->variable
|= entry
->val
;
12472 result
|= entry
->val
;
12477 if (entry
->letter
== 0)
12478 warn (_("Unrecognized debug letter option '%c'\n"), * letters
);
12483 /* The --debug-dump=frames-interp option also enables the
12484 --debug-dump=frames option. */
12485 if (do_debug_frames_interp
)
12486 do_debug_frames
= 1;
12492 dwarf_select_sections_all (void)
12495 do_debug_abbrevs
= 1;
12496 do_debug_lines
= FLAG_DEBUG_LINES_RAW
;
12497 do_debug_pubnames
= 1;
12498 do_debug_pubtypes
= 1;
12499 do_debug_aranges
= 1;
12500 do_debug_ranges
= 1;
12501 do_debug_frames
= 1;
12502 do_debug_macinfo
= 1;
12507 do_trace_abbrevs
= 1;
12508 do_trace_aranges
= 1;
12510 do_debug_cu_index
= 1;
12511 do_follow_links
= 1;
12512 do_debug_links
= 1;
12513 do_debug_str_offsets
= 1;
12516 #define NO_ABBREVS NULL, NULL, NULL, 0, 0, 0, NULL, 0
12517 #define ABBREV(N) NULL, NULL, NULL, 0, 0, N, NULL, 0
12519 /* N.B. The order here must match the order in section_display_enum. */
12521 struct dwarf_section_display debug_displays
[] =
12523 { { ".debug_abbrev", ".zdebug_abbrev", ".dwabrev", NO_ABBREVS
}, display_debug_abbrev
, &do_debug_abbrevs
, false },
12524 { { ".debug_aranges", ".zdebug_aranges", ".dwarnge", NO_ABBREVS
}, display_debug_aranges
, &do_debug_aranges
, true },
12525 { { ".debug_frame", ".zdebug_frame", ".dwframe", NO_ABBREVS
}, display_debug_frames
, &do_debug_frames
, true },
12526 { { ".debug_info", ".zdebug_info", ".dwinfo", ABBREV (abbrev
)}, display_debug_info
, &do_debug_info
, true },
12527 { { ".debug_line", ".zdebug_line", ".dwline", NO_ABBREVS
}, display_debug_lines
, &do_debug_lines
, true },
12528 { { ".debug_pubnames", ".zdebug_pubnames", ".dwpbnms", NO_ABBREVS
}, display_debug_pubnames
, &do_debug_pubnames
, false },
12529 { { ".debug_gnu_pubnames", ".zdebug_gnu_pubnames", "", NO_ABBREVS
}, display_debug_gnu_pubnames
, &do_debug_pubnames
, false },
12530 { { ".eh_frame", "", "", NO_ABBREVS
}, display_debug_frames
, &do_debug_frames
, true },
12531 { { ".debug_macinfo", ".zdebug_macinfo", "", NO_ABBREVS
}, display_debug_macinfo
, &do_debug_macinfo
, false },
12532 { { ".debug_macro", ".zdebug_macro", ".dwmac", NO_ABBREVS
}, display_debug_macro
, &do_debug_macinfo
, true },
12533 { { ".debug_str", ".zdebug_str", ".dwstr", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, false },
12534 { { ".debug_line_str", ".zdebug_line_str", "", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, false },
12535 { { ".debug_loc", ".zdebug_loc", ".dwloc", NO_ABBREVS
}, display_debug_loc
, &do_debug_loc
, true },
12536 { { ".debug_loclists", ".zdebug_loclists", "", NO_ABBREVS
}, display_debug_loc
, &do_debug_loc
, true },
12537 { { ".debug_loclists.dwo", ".zdebug_loclists.dwo", "", NO_ABBREVS
}, display_debug_loc
, &do_debug_loc
, true },
12538 { { ".debug_pubtypes", ".zdebug_pubtypes", ".dwpbtyp", NO_ABBREVS
}, display_debug_pubnames
, &do_debug_pubtypes
, false },
12539 { { ".debug_gnu_pubtypes", ".zdebug_gnu_pubtypes", "", NO_ABBREVS
}, display_debug_gnu_pubnames
, &do_debug_pubtypes
, false },
12540 { { ".debug_ranges", ".zdebug_ranges", ".dwrnges", NO_ABBREVS
}, display_debug_ranges
, &do_debug_ranges
, true },
12541 { { ".debug_rnglists", ".zdebug_rnglists", "", NO_ABBREVS
}, display_debug_ranges
, &do_debug_ranges
, true },
12542 { { ".debug_rnglists.dwo", ".zdebug_rnglists.dwo", "", NO_ABBREVS
}, display_debug_ranges
, &do_debug_ranges
, true },
12543 { { ".debug_static_func", ".zdebug_static_func", "", NO_ABBREVS
}, display_debug_not_supported
, NULL
, false },
12544 { { ".debug_static_vars", ".zdebug_static_vars", "", NO_ABBREVS
}, display_debug_not_supported
, NULL
, false },
12545 { { ".debug_types", ".zdebug_types", "", ABBREV (abbrev
) }, display_debug_types
, &do_debug_info
, true },
12546 { { ".debug_weaknames", ".zdebug_weaknames", "", NO_ABBREVS
}, display_debug_not_supported
, NULL
, false },
12547 { { ".gdb_index", "", "", NO_ABBREVS
}, display_gdb_index
, &do_gdb_index
, false },
12548 { { ".debug_names", "", "", NO_ABBREVS
}, display_debug_names
, &do_gdb_index
, false },
12549 { { ".trace_info", "", "", ABBREV (trace_abbrev
) }, display_trace_info
, &do_trace_info
, true },
12550 { { ".trace_abbrev", "", "", NO_ABBREVS
}, display_debug_abbrev
, &do_trace_abbrevs
, false },
12551 { { ".trace_aranges", "", "", NO_ABBREVS
}, display_debug_aranges
, &do_trace_aranges
, false },
12552 { { ".debug_info.dwo", ".zdebug_info.dwo", "", ABBREV (abbrev_dwo
) }, display_debug_info
, &do_debug_info
, true },
12553 { { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo", "", NO_ABBREVS
}, display_debug_abbrev
, &do_debug_abbrevs
, false },
12554 { { ".debug_types.dwo", ".zdebug_types.dwo", "", ABBREV (abbrev_dwo
) }, display_debug_types
, &do_debug_info
, true },
12555 { { ".debug_line.dwo", ".zdebug_line.dwo", "", NO_ABBREVS
}, display_debug_lines
, &do_debug_lines
, true },
12556 { { ".debug_loc.dwo", ".zdebug_loc.dwo", "", NO_ABBREVS
}, display_debug_loc
, &do_debug_loc
, true },
12557 { { ".debug_macro.dwo", ".zdebug_macro.dwo", "", NO_ABBREVS
}, display_debug_macro
, &do_debug_macinfo
, true },
12558 { { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo", "", NO_ABBREVS
}, display_debug_macinfo
, &do_debug_macinfo
, false },
12559 { { ".debug_str.dwo", ".zdebug_str.dwo", "", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, true },
12560 { { ".debug_str_offsets", ".zdebug_str_offsets", "", NO_ABBREVS
}, display_debug_str_offsets
, &do_debug_str_offsets
, true },
12561 { { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo", "", NO_ABBREVS
}, display_debug_str_offsets
, &do_debug_str_offsets
, true },
12562 { { ".debug_addr", ".zdebug_addr", "", NO_ABBREVS
}, display_debug_addr
, &do_debug_addr
, true },
12563 { { ".debug_cu_index", "", "", NO_ABBREVS
}, display_cu_index
, &do_debug_cu_index
, false },
12564 { { ".debug_tu_index", "", "", NO_ABBREVS
}, display_cu_index
, &do_debug_cu_index
, false },
12565 { { ".gnu_debuglink", "", "", NO_ABBREVS
}, display_debug_links
, &do_debug_links
, false },
12566 { { ".gnu_debugaltlink", "", "", NO_ABBREVS
}, display_debug_links
, &do_debug_links
, false },
12567 { { ".debug_sup", "", "", NO_ABBREVS
}, display_debug_sup
, &do_debug_links
, false },
12568 /* Separate debug info files can containt their own .debug_str section,
12569 and this might be in *addition* to a .debug_str section already present
12570 in the main file. Hence we need to have two entries for .debug_str. */
12571 { { ".debug_str", ".zdebug_str", "", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, false },
12572 { { ".note.gnu.build-id", "", "", NO_ABBREVS
}, display_debug_not_supported
, NULL
, false },
12575 /* A static assertion. */
12576 extern int debug_displays_assert
[ARRAY_SIZE (debug_displays
) == max
? 1 : -1];