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)");
2346 display_lang (uint64_t uvalue
)
2350 /* Ordered by the numeric value of these constants. */
2351 case DW_LANG_C89
: printf ("ANSI C"); break;
2352 case DW_LANG_C
: printf ("non-ANSI C"); break;
2353 case DW_LANG_Ada83
: printf ("Ada"); break;
2354 case DW_LANG_C_plus_plus
: printf ("C++"); break;
2355 case DW_LANG_Cobol74
: printf ("Cobol 74"); break;
2356 case DW_LANG_Cobol85
: printf ("Cobol 85"); break;
2357 case DW_LANG_Fortran77
: printf ("FORTRAN 77"); break;
2358 case DW_LANG_Fortran90
: printf ("Fortran 90"); break;
2359 case DW_LANG_Pascal83
: printf ("ANSI Pascal"); break;
2360 case DW_LANG_Modula2
: printf ("Modula 2"); break;
2362 /* DWARF 2.1 values. */
2363 case DW_LANG_Java
: printf ("Java"); break;
2364 case DW_LANG_C99
: printf ("ANSI C99"); break;
2365 case DW_LANG_Ada95
: printf ("ADA 95"); break;
2366 case DW_LANG_Fortran95
: printf ("Fortran 95"); break;
2368 /* DWARF 3 values. */
2369 case DW_LANG_PLI
: printf ("PLI"); break;
2370 case DW_LANG_ObjC
: printf ("Objective C"); break;
2371 case DW_LANG_ObjC_plus_plus
: printf ("Objective C++"); break;
2372 case DW_LANG_UPC
: printf ("Unified Parallel C"); break;
2373 case DW_LANG_D
: printf ("D"); break;
2375 /* DWARF 4 values. */
2376 case DW_LANG_Python
: printf ("Python"); break;
2378 /* DWARF 5 values. */
2379 case DW_LANG_OpenCL
: printf ("OpenCL"); break;
2380 case DW_LANG_Go
: printf ("Go"); break;
2381 case DW_LANG_Modula3
: printf ("Modula 3"); break;
2382 case DW_LANG_Haskell
: printf ("Haskell"); break;
2383 case DW_LANG_C_plus_plus_03
: printf ("C++03"); break;
2384 case DW_LANG_C_plus_plus_11
: printf ("C++11"); break;
2385 case DW_LANG_OCaml
: printf ("OCaml"); break;
2386 case DW_LANG_Rust
: printf ("Rust"); break;
2387 case DW_LANG_C11
: printf ("C11"); break;
2388 case DW_LANG_Swift
: printf ("Swift"); break;
2389 case DW_LANG_Julia
: printf ("Julia"); break;
2390 case DW_LANG_Dylan
: printf ("Dylan"); break;
2391 case DW_LANG_C_plus_plus_14
: printf ("C++14"); break;
2392 case DW_LANG_Fortran03
: printf ("Fortran 03"); break;
2393 case DW_LANG_Fortran08
: printf ("Fortran 08"); break;
2394 case DW_LANG_RenderScript
: printf ("RenderScript"); break;
2396 /* MIPS extension. */
2397 case DW_LANG_Mips_Assembler
: printf ("MIPS assembler"); break;
2399 /* UPC extension. */
2400 case DW_LANG_Upc
: printf ("Unified Parallel C"); break;
2403 if (uvalue
>= DW_LANG_lo_user
&& uvalue
<= DW_LANG_hi_user
)
2404 printf (_("implementation defined: %#" PRIx64
""), uvalue
);
2406 printf (_("unknown: %#" PRIx64
""), uvalue
);
2411 static unsigned char *
2412 read_and_display_attr_value (unsigned long attribute
,
2414 int64_t implicit_const
,
2415 unsigned char *start
,
2416 unsigned char *data
,
2419 uint64_t pointer_size
,
2420 uint64_t offset_size
,
2422 debug_info
*debug_info_p
,
2424 struct dwarf_section
*section
,
2425 struct cu_tu_set
*this_set
,
2430 uint64_t uvalue
= 0;
2431 uint64_t uvalue_hi
= 0;
2432 unsigned char *block_start
= NULL
;
2433 unsigned char *orig_data
= data
;
2435 if (data
> end
|| (data
== end
&& form
!= DW_FORM_flag_present
))
2437 warn (_("Corrupt attribute\n"));
2441 if (do_wide
&& ! do_loc
)
2443 /* PR 26847: Display the name of the form. */
2444 const char * name
= get_FORM_name (form
);
2446 /* For convenience we skip the DW_FORM_ prefix to the name. */
2448 name
+= 8; /* strlen ("DW_FORM_") */
2449 printf ("%c(%s)", delimiter
, name
);
2454 case DW_FORM_ref_addr
:
2455 if (dwarf_version
== 2)
2456 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
2457 else if (dwarf_version
> 2)
2458 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
2460 error (_("Internal error: DW_FORM_ref_addr is not supported in DWARF version 1.\n"));
2464 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
2467 case DW_FORM_strp_sup
:
2469 case DW_FORM_line_strp
:
2470 case DW_FORM_sec_offset
:
2471 case DW_FORM_GNU_ref_alt
:
2472 case DW_FORM_GNU_strp_alt
:
2473 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
2476 case DW_FORM_flag_present
:
2484 case DW_FORM_addrx1
:
2485 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
2491 case DW_FORM_addrx2
:
2492 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
2496 case DW_FORM_addrx3
:
2497 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 3, end
);
2500 case DW_FORM_ref_sup4
:
2504 case DW_FORM_addrx4
:
2505 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
2508 case DW_FORM_ref_sup8
:
2511 case DW_FORM_ref_sig8
:
2512 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 8, end
);
2515 case DW_FORM_data16
:
2516 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 8, end
);
2517 SAFE_BYTE_GET_AND_INC (uvalue_hi
, data
, 8, end
);
2518 if (byte_get
!= byte_get_little_endian
)
2520 uint64_t utmp
= uvalue
;
2527 READ_SLEB (svalue
, data
, end
);
2531 case DW_FORM_GNU_str_index
:
2533 case DW_FORM_ref_udata
:
2535 case DW_FORM_GNU_addr_index
:
2537 case DW_FORM_loclistx
:
2538 case DW_FORM_rnglistx
:
2539 READ_ULEB (uvalue
, data
, end
);
2542 case DW_FORM_indirect
:
2543 READ_ULEB (form
, data
, end
);
2545 printf ("%c%s", delimiter
, get_FORM_name (form
));
2546 if (form
== DW_FORM_implicit_const
)
2547 READ_SLEB (implicit_const
, data
, end
);
2548 return read_and_display_attr_value (attribute
, form
, implicit_const
,
2550 cu_offset
, pointer_size
,
2551 offset_size
, dwarf_version
,
2552 debug_info_p
, do_loc
,
2553 section
, this_set
, delimiter
, level
);
2555 case DW_FORM_implicit_const
:
2556 uvalue
= implicit_const
;
2565 case DW_FORM_ref_addr
:
2567 printf ("%c<%#" PRIx64
">", delimiter
, uvalue
);
2570 case DW_FORM_GNU_ref_alt
:
2574 /* We have already printed the form name. */
2575 printf ("%c<%#" PRIx64
">", delimiter
, uvalue
);
2577 printf ("%c<alt %#" PRIx64
">", delimiter
, uvalue
);
2579 /* FIXME: Follow the reference... */
2585 case DW_FORM_ref_sup4
:
2586 case DW_FORM_ref_udata
:
2588 printf ("%c<%#" PRIx64
">", delimiter
, uvalue
+ cu_offset
);
2593 case DW_FORM_sec_offset
:
2595 printf ("%c%#" PRIx64
, delimiter
, uvalue
);
2598 case DW_FORM_flag_present
:
2604 printf ("%c%" PRId64
, delimiter
, uvalue
);
2609 printf ("%c%" PRIu64
, delimiter
, uvalue
);
2612 case DW_FORM_implicit_const
:
2614 printf ("%c%" PRId64
, delimiter
, implicit_const
);
2617 case DW_FORM_ref_sup8
:
2622 uint64_t utmp
= uvalue
;
2623 if (form
== DW_FORM_ref8
)
2625 printf ("%c%#" PRIx64
, delimiter
, utmp
);
2629 case DW_FORM_data16
:
2633 printf (" %#" PRIx64
, uvalue
);
2635 printf (" %#" PRIx64
"%016" PRIx64
, uvalue_hi
, uvalue
);
2639 case DW_FORM_string
:
2641 printf ("%c%.*s", delimiter
, (int) (end
- data
), data
);
2642 data
+= strnlen ((char *) data
, end
- data
);
2648 case DW_FORM_exprloc
:
2649 READ_ULEB (uvalue
, data
, end
);
2652 if (block_start
>= end
)
2654 warn (_("Block ends prematurely\n"));
2659 uvalue
= check_uvalue (block_start
, uvalue
, end
);
2661 data
= block_start
+ uvalue
;
2666 SAFE_BYTE_GET (op
, block_start
, sizeof (op
), end
);
2667 if (op
!= DW_OP_addrx
)
2668 data
= display_block (block_start
, uvalue
, end
, delimiter
);
2672 case DW_FORM_block1
:
2673 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
2676 case DW_FORM_block2
:
2677 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
2680 case DW_FORM_block4
:
2681 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
2688 /* We have already displayed the form name. */
2689 printf (_("%c(offset: %#" PRIx64
"): %s"),
2690 delimiter
, uvalue
, fetch_indirect_string (uvalue
));
2692 printf (_("%c(indirect string, offset: %#" PRIx64
"): %s"),
2693 delimiter
, uvalue
, fetch_indirect_string (uvalue
));
2697 case DW_FORM_line_strp
:
2701 /* We have already displayed the form name. */
2702 printf (_("%c(offset: %#" PRIx64
"): %s"),
2703 delimiter
, uvalue
, fetch_indirect_line_string (uvalue
));
2705 printf (_("%c(indirect line string, offset: %#" PRIx64
"): %s"),
2706 delimiter
, uvalue
, fetch_indirect_line_string (uvalue
));
2710 case DW_FORM_GNU_str_index
:
2718 const char *suffix
= section
? strrchr (section
->name
, '.') : NULL
;
2719 bool dwo
= suffix
&& strcmp (suffix
, ".dwo") == 0;
2722 strng
= fetch_indexed_string (uvalue
, this_set
, offset_size
, dwo
,
2723 debug_info_p
? debug_info_p
->str_offsets_base
: 0);
2725 /* We have already displayed the form name. */
2726 printf (_("%c(offset: %#" PRIx64
"): %s"),
2727 delimiter
, uvalue
, strng
);
2729 printf (_("%c(indexed string: %#" PRIx64
"): %s"),
2730 delimiter
, uvalue
, strng
);
2734 case DW_FORM_GNU_strp_alt
:
2738 /* We have already displayed the form name. */
2739 printf (_("%c(offset: %#" PRIx64
") %s"),
2740 delimiter
, uvalue
, fetch_alt_indirect_string (uvalue
));
2742 printf (_("%c(alt indirect string, offset: %#" PRIx64
") %s"),
2743 delimiter
, uvalue
, fetch_alt_indirect_string (uvalue
));
2747 case DW_FORM_indirect
:
2748 /* Handled above. */
2751 case DW_FORM_ref_sig8
:
2753 printf ("%c%s: %#" PRIx64
, delimiter
, do_wide
? "" : "signature",
2757 case DW_FORM_GNU_addr_index
:
2759 case DW_FORM_addrx1
:
2760 case DW_FORM_addrx2
:
2761 case DW_FORM_addrx3
:
2762 case DW_FORM_addrx4
:
2763 case DW_FORM_loclistx
:
2764 case DW_FORM_rnglistx
:
2768 const char *suffix
= strrchr (section
->name
, '.');
2769 bool dwo
= suffix
&& strcmp (suffix
, ".dwo") == 0;
2771 if (form
== DW_FORM_loclistx
)
2775 idx
= fetch_indexed_offset (uvalue
, loclists_dwo
,
2776 debug_info_p
->loclists_base
,
2777 debug_info_p
->offset_size
);
2778 if (idx
!= (uint64_t) -1)
2779 idx
+= (offset_size
== 8) ? 20 : 12;
2781 else if (debug_info_p
== NULL
|| dwarf_version
> 4)
2783 idx
= fetch_indexed_offset (uvalue
, loclists
,
2784 debug_info_p
->loclists_base
,
2785 debug_info_p
->offset_size
);
2789 /* We want to compute:
2790 idx = fetch_indexed_value (uvalue, loclists,
2791 debug_info_p->loclists_base);
2792 idx += debug_info_p->loclists_base;
2793 Fortunately we already have that sum cached in the
2794 loc_offsets array. */
2795 if (uvalue
< debug_info_p
->num_loc_offsets
)
2796 idx
= debug_info_p
->loc_offsets
[uvalue
];
2799 warn (_("loc_offset %" PRIu64
" too big\n"), uvalue
);
2804 else if (form
== DW_FORM_rnglistx
)
2808 idx
= fetch_indexed_offset (uvalue
, rnglists
,
2809 debug_info_p
->rnglists_base
,
2810 debug_info_p
->offset_size
);
2814 if (debug_info_p
== NULL
)
2817 base
= debug_info_p
->rnglists_base
;
2818 idx
= fetch_indexed_offset (uvalue
, rnglists
, base
,
2819 debug_info_p
->offset_size
);
2824 if (debug_info_p
== NULL
)
2826 else if (debug_info_p
->addr_base
== DEBUG_INFO_UNAVAILABLE
)
2829 base
= debug_info_p
->addr_base
;
2831 base
+= uvalue
* pointer_size
;
2832 idx
= fetch_indexed_addr (base
, pointer_size
);
2835 /* We have already displayed the form name. */
2836 if (idx
!= (uint64_t) -1)
2837 printf (_("%c(index: %#" PRIx64
"): %#" PRIx64
),
2838 delimiter
, uvalue
, idx
);
2842 case DW_FORM_strp_sup
:
2844 printf ("%c<%#" PRIx64
">", delimiter
, uvalue
+ cu_offset
);
2848 warn (_("Unrecognized form: %#lx"), form
);
2849 /* What to do? Consume a byte maybe? */
2854 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
|| do_debug_info
)
2855 && num_debug_info_entries
== 0
2856 && debug_info_p
!= NULL
)
2860 case DW_AT_loclists_base
:
2861 if (debug_info_p
->loclists_base
)
2862 warn (_("CU @ %#" PRIx64
" has multiple loclists_base values "
2863 "(%#" PRIx64
" and %#" PRIx64
")"),
2864 debug_info_p
->cu_offset
,
2865 debug_info_p
->loclists_base
, uvalue
);
2869 warn (_("CU @ %#" PRIx64
" has has a negative loclists_base "
2870 "value of %#" PRIx64
" - treating as zero"),
2871 debug_info_p
->cu_offset
, svalue
);
2874 debug_info_p
->loclists_base
= uvalue
;
2877 case DW_AT_rnglists_base
:
2878 /* Assignment to debug_info_p->rnglists_base is now elsewhere. */
2881 case DW_AT_str_offsets_base
:
2882 if (debug_info_p
->str_offsets_base
)
2883 warn (_("CU @ %#" PRIx64
" has multiple str_offsets_base values "
2884 "%#" PRIx64
" and %#" PRIx64
")"),
2885 debug_info_p
->cu_offset
,
2886 debug_info_p
->str_offsets_base
, uvalue
);
2890 warn (_("CU @ %#" PRIx64
" has has a negative stroffsets_base "
2891 "value of %#" PRIx64
" - treating as zero"),
2892 debug_info_p
->cu_offset
, svalue
);
2895 debug_info_p
->str_offsets_base
= uvalue
;
2898 case DW_AT_frame_base
:
2899 have_frame_base
= 1;
2901 case DW_AT_location
:
2902 case DW_AT_GNU_locviews
:
2903 case DW_AT_string_length
:
2904 case DW_AT_return_addr
:
2905 case DW_AT_data_member_location
:
2906 case DW_AT_vtable_elem_location
:
2908 case DW_AT_static_link
:
2909 case DW_AT_use_location
:
2910 case DW_AT_call_value
:
2911 case DW_AT_GNU_call_site_value
:
2912 case DW_AT_call_data_value
:
2913 case DW_AT_GNU_call_site_data_value
:
2914 case DW_AT_call_target
:
2915 case DW_AT_GNU_call_site_target
:
2916 case DW_AT_call_target_clobbered
:
2917 case DW_AT_GNU_call_site_target_clobbered
:
2918 if ((dwarf_version
< 4
2919 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
2920 || form
== DW_FORM_sec_offset
2921 || form
== DW_FORM_loclistx
)
2923 /* Process location list. */
2924 unsigned int lmax
= debug_info_p
->max_loc_offsets
;
2925 unsigned int num
= debug_info_p
->num_loc_offsets
;
2927 if (lmax
== 0 || num
>= lmax
)
2930 debug_info_p
->loc_offsets
= (uint64_t *)
2931 xcrealloc (debug_info_p
->loc_offsets
,
2932 lmax
, sizeof (*debug_info_p
->loc_offsets
));
2933 debug_info_p
->loc_views
= (uint64_t *)
2934 xcrealloc (debug_info_p
->loc_views
,
2935 lmax
, sizeof (*debug_info_p
->loc_views
));
2936 debug_info_p
->have_frame_base
= (int *)
2937 xcrealloc (debug_info_p
->have_frame_base
,
2938 lmax
, sizeof (*debug_info_p
->have_frame_base
));
2939 debug_info_p
->max_loc_offsets
= lmax
;
2941 if (form
== DW_FORM_loclistx
)
2942 uvalue
= fetch_indexed_offset (num
, loclists
,
2943 debug_info_p
->loclists_base
,
2944 debug_info_p
->offset_size
);
2945 else if (this_set
!= NULL
)
2946 uvalue
+= this_set
->section_offsets
[DW_SECT_LOC
];
2948 debug_info_p
->have_frame_base
[num
] = have_frame_base
;
2949 if (attribute
!= DW_AT_GNU_locviews
)
2951 uvalue
+= debug_info_p
->loclists_base
;
2953 /* Corrupt DWARF info can produce more offsets than views.
2954 See PR 23062 for an example. */
2955 if (debug_info_p
->num_loc_offsets
2956 > debug_info_p
->num_loc_views
)
2957 warn (_("More location offset attributes than DW_AT_GNU_locview attributes\n"));
2960 debug_info_p
->loc_offsets
[num
] = uvalue
;
2961 debug_info_p
->num_loc_offsets
++;
2966 if (debug_info_p
->num_loc_views
> num
)
2968 warn (_("The number of views (%u) is greater than the number of locations (%u)\n"),
2969 debug_info_p
->num_loc_views
, num
);
2970 debug_info_p
->num_loc_views
= num
;
2973 num
= debug_info_p
->num_loc_views
;
2974 if (num
> debug_info_p
->num_loc_offsets
)
2975 warn (_("More DW_AT_GNU_locview attributes than location offset attributes\n"));
2978 debug_info_p
->loc_views
[num
] = uvalue
;
2979 debug_info_p
->num_loc_views
++;
2986 if (need_base_address
)
2988 if (form
== DW_FORM_addrx
)
2989 uvalue
= fetch_indexed_addr (debug_info_p
->addr_base
2990 + uvalue
* pointer_size
,
2993 debug_info_p
->base_address
= uvalue
;
2997 case DW_AT_GNU_addr_base
:
2998 case DW_AT_addr_base
:
2999 debug_info_p
->addr_base
= uvalue
;
3000 /* Retrieved elsewhere so that it is in
3001 place by the time we read low_pc. */
3004 case DW_AT_GNU_ranges_base
:
3005 debug_info_p
->ranges_base
= uvalue
;
3009 if ((dwarf_version
< 4
3010 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
3011 || form
== DW_FORM_sec_offset
3012 || form
== DW_FORM_rnglistx
)
3014 /* Process range list. */
3015 unsigned int lmax
= debug_info_p
->max_range_lists
;
3016 unsigned int num
= debug_info_p
->num_range_lists
;
3018 if (lmax
== 0 || num
>= lmax
)
3021 debug_info_p
->range_lists
= (uint64_t *)
3022 xcrealloc (debug_info_p
->range_lists
,
3023 lmax
, sizeof (*debug_info_p
->range_lists
));
3024 debug_info_p
->max_range_lists
= lmax
;
3027 if (form
== DW_FORM_rnglistx
)
3028 uvalue
= fetch_indexed_offset (uvalue
, rnglists
,
3029 debug_info_p
->rnglists_base
,
3030 debug_info_p
->offset_size
);
3032 debug_info_p
->range_lists
[num
] = uvalue
;
3033 debug_info_p
->num_range_lists
++;
3037 case DW_AT_GNU_dwo_name
:
3038 case DW_AT_dwo_name
:
3043 add_dwo_name ((const char *) fetch_indirect_string (uvalue
),
3046 case DW_FORM_GNU_strp_alt
:
3047 add_dwo_name ((const char *) fetch_alt_indirect_string (uvalue
), cu_offset
);
3049 case DW_FORM_GNU_str_index
:
3055 add_dwo_name (fetch_indexed_string (uvalue
, this_set
,
3057 debug_info_p
->str_offsets_base
),
3060 case DW_FORM_string
:
3061 add_dwo_name ((const char *) orig_data
, cu_offset
);
3064 warn (_("Unsupported form (%s) for attribute %s\n"),
3065 get_FORM_name (form
), get_AT_name (attribute
));
3070 case DW_AT_comp_dir
:
3071 /* FIXME: Also extract a build-id in a CU/TU. */
3076 add_dwo_dir ((const char *) fetch_indirect_string (uvalue
), cu_offset
);
3078 case DW_FORM_GNU_strp_alt
:
3079 add_dwo_dir (fetch_alt_indirect_string (uvalue
), cu_offset
);
3081 case DW_FORM_line_strp
:
3082 add_dwo_dir ((const char *) fetch_indirect_line_string (uvalue
), cu_offset
);
3084 case DW_FORM_GNU_str_index
:
3090 add_dwo_dir (fetch_indexed_string (uvalue
, this_set
, offset_size
, false,
3091 debug_info_p
->str_offsets_base
),
3094 case DW_FORM_string
:
3095 add_dwo_dir ((const char *) orig_data
, cu_offset
);
3098 warn (_("Unsupported form (%s) for attribute %s\n"),
3099 get_FORM_name (form
), get_AT_name (attribute
));
3104 case DW_AT_GNU_dwo_id
:
3109 /* FIXME: Record the length of the ID as well ? */
3110 add_dwo_id ((const char *) (data
- 8), cu_offset
);
3113 warn (_("Unsupported form (%s) for attribute %s\n"),
3114 get_FORM_name (form
), get_AT_name (attribute
));
3124 if (do_loc
|| attribute
== 0)
3127 /* For some attributes we can display further information. */
3131 if (level
>= 0 && level
< MAX_CU_NESTING
3132 && uvalue
< (size_t) (end
- start
))
3134 bool is_signed
= false;
3135 abbrev_entry
*type_abbrev
;
3136 unsigned char *type_data
;
3139 type_abbrev
= get_type_abbrev_from_form (form
, uvalue
,
3143 if (type_abbrev
!= NULL
)
3145 get_type_signedness (type_abbrev
, section
, type_data
,
3146 map
? section
->start
+ map
->end
: end
,
3147 map
? map
->start
: cu_offset
,
3148 pointer_size
, offset_size
, dwarf_version
,
3151 level_type_signed
[level
] = is_signed
;
3159 case DW_INL_not_inlined
:
3160 printf (_("(not inlined)"));
3162 case DW_INL_inlined
:
3163 printf (_("(inlined)"));
3165 case DW_INL_declared_not_inlined
:
3166 printf (_("(declared as inline but ignored)"));
3168 case DW_INL_declared_inlined
:
3169 printf (_("(declared as inline and inlined)"));
3172 printf (_(" (Unknown inline attribute value: %#" PRIx64
")"),
3178 case DW_AT_language
:
3180 display_lang (uvalue
);
3184 case DW_AT_encoding
:
3188 case DW_ATE_void
: printf ("(void)"); break;
3189 case DW_ATE_address
: printf ("(machine address)"); break;
3190 case DW_ATE_boolean
: printf ("(boolean)"); break;
3191 case DW_ATE_complex_float
: printf ("(complex float)"); break;
3192 case DW_ATE_float
: printf ("(float)"); break;
3193 case DW_ATE_signed
: printf ("(signed)"); break;
3194 case DW_ATE_signed_char
: printf ("(signed char)"); break;
3195 case DW_ATE_unsigned
: printf ("(unsigned)"); break;
3196 case DW_ATE_unsigned_char
: printf ("(unsigned char)"); break;
3197 /* DWARF 2.1 values: */
3198 case DW_ATE_imaginary_float
: printf ("(imaginary float)"); break;
3199 case DW_ATE_decimal_float
: printf ("(decimal float)"); break;
3200 /* DWARF 3 values: */
3201 case DW_ATE_packed_decimal
: printf ("(packed_decimal)"); break;
3202 case DW_ATE_numeric_string
: printf ("(numeric_string)"); break;
3203 case DW_ATE_edited
: printf ("(edited)"); break;
3204 case DW_ATE_signed_fixed
: printf ("(signed_fixed)"); break;
3205 case DW_ATE_unsigned_fixed
: printf ("(unsigned_fixed)"); break;
3206 /* DWARF 4 values: */
3207 case DW_ATE_UTF
: printf ("(unicode string)"); break;
3208 /* DWARF 5 values: */
3209 case DW_ATE_UCS
: printf ("(UCS)"); break;
3210 case DW_ATE_ASCII
: printf ("(ASCII)"); break;
3212 /* HP extensions: */
3213 case DW_ATE_HP_float80
: printf ("(HP_float80)"); break;
3214 case DW_ATE_HP_complex_float80
: printf ("(HP_complex_float80)"); break;
3215 case DW_ATE_HP_float128
: printf ("(HP_float128)"); break;
3216 case DW_ATE_HP_complex_float128
:printf ("(HP_complex_float128)"); break;
3217 case DW_ATE_HP_floathpintel
: printf ("(HP_floathpintel)"); break;
3218 case DW_ATE_HP_imaginary_float80
: printf ("(HP_imaginary_float80)"); break;
3219 case DW_ATE_HP_imaginary_float128
: printf ("(HP_imaginary_float128)"); break;
3222 if (uvalue
>= DW_ATE_lo_user
3223 && uvalue
<= DW_ATE_hi_user
)
3224 printf (_("(user defined type)"));
3226 printf (_("(unknown type)"));
3231 case DW_AT_accessibility
:
3235 case DW_ACCESS_public
: printf ("(public)"); break;
3236 case DW_ACCESS_protected
: printf ("(protected)"); break;
3237 case DW_ACCESS_private
: printf ("(private)"); break;
3239 printf (_("(unknown accessibility)"));
3244 case DW_AT_visibility
:
3248 case DW_VIS_local
: printf ("(local)"); break;
3249 case DW_VIS_exported
: printf ("(exported)"); break;
3250 case DW_VIS_qualified
: printf ("(qualified)"); break;
3251 default: printf (_("(unknown visibility)")); break;
3255 case DW_AT_endianity
:
3259 case DW_END_default
: printf ("(default)"); break;
3260 case DW_END_big
: printf ("(big)"); break;
3261 case DW_END_little
: printf ("(little)"); break;
3263 if (uvalue
>= DW_END_lo_user
&& uvalue
<= DW_END_hi_user
)
3264 printf (_("(user specified)"));
3266 printf (_("(unknown endianity)"));
3271 case DW_AT_virtuality
:
3275 case DW_VIRTUALITY_none
: printf ("(none)"); break;
3276 case DW_VIRTUALITY_virtual
: printf ("(virtual)"); break;
3277 case DW_VIRTUALITY_pure_virtual
:printf ("(pure_virtual)"); break;
3278 default: printf (_("(unknown virtuality)")); break;
3282 case DW_AT_identifier_case
:
3286 case DW_ID_case_sensitive
: printf ("(case_sensitive)"); break;
3287 case DW_ID_up_case
: printf ("(up_case)"); break;
3288 case DW_ID_down_case
: printf ("(down_case)"); break;
3289 case DW_ID_case_insensitive
: printf ("(case_insensitive)"); break;
3290 default: printf (_("(unknown case)")); break;
3294 case DW_AT_calling_convention
:
3298 case DW_CC_normal
: printf ("(normal)"); break;
3299 case DW_CC_program
: printf ("(program)"); break;
3300 case DW_CC_nocall
: printf ("(nocall)"); break;
3301 case DW_CC_pass_by_reference
: printf ("(pass by ref)"); break;
3302 case DW_CC_pass_by_value
: printf ("(pass by value)"); break;
3303 case DW_CC_GNU_renesas_sh
: printf ("(Rensas SH)"); break;
3304 case DW_CC_GNU_borland_fastcall_i386
: printf ("(Borland fastcall i386)"); break;
3306 if (uvalue
>= DW_CC_lo_user
3307 && uvalue
<= DW_CC_hi_user
)
3308 printf (_("(user defined)"));
3310 printf (_("(unknown convention)"));
3314 case DW_AT_ordering
:
3319 case -1: printf (_("(undefined)")); break;
3320 case 0: printf ("(row major)"); break;
3321 case 1: printf ("(column major)"); break;
3325 case DW_AT_decimal_sign
:
3329 case DW_DS_unsigned
: printf (_("(unsigned)")); break;
3330 case DW_DS_leading_overpunch
: printf (_("(leading overpunch)")); break;
3331 case DW_DS_trailing_overpunch
: printf (_("(trailing overpunch)")); break;
3332 case DW_DS_leading_separate
: printf (_("(leading separate)")); break;
3333 case DW_DS_trailing_separate
: printf (_("(trailing separate)")); break;
3334 default: printf (_("(unrecognised)")); break;
3338 case DW_AT_defaulted
:
3342 case DW_DEFAULTED_no
: printf (_("(no)")); break;
3343 case DW_DEFAULTED_in_class
: printf (_("(in class)")); break;
3344 case DW_DEFAULTED_out_of_class
: printf (_("(out of class)")); break;
3345 default: printf (_("(unrecognised)")); break;
3349 case DW_AT_discr_list
:
3351 display_discr_list (form
, uvalue
, data
, level
);
3354 case DW_AT_frame_base
:
3355 have_frame_base
= 1;
3357 case DW_AT_location
:
3358 case DW_AT_loclists_base
:
3359 case DW_AT_rnglists_base
:
3360 case DW_AT_str_offsets_base
:
3361 case DW_AT_string_length
:
3362 case DW_AT_return_addr
:
3363 case DW_AT_data_member_location
:
3364 case DW_AT_vtable_elem_location
:
3366 case DW_AT_static_link
:
3367 case DW_AT_use_location
:
3368 case DW_AT_call_value
:
3369 case DW_AT_GNU_call_site_value
:
3370 case DW_AT_call_data_value
:
3371 case DW_AT_GNU_call_site_data_value
:
3372 case DW_AT_call_target
:
3373 case DW_AT_GNU_call_site_target
:
3374 case DW_AT_call_target_clobbered
:
3375 case DW_AT_GNU_call_site_target_clobbered
:
3376 if ((dwarf_version
< 4
3377 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
3378 || form
== DW_FORM_sec_offset
3379 || form
== DW_FORM_loclistx
)
3381 if (attribute
!= DW_AT_rnglists_base
3382 && attribute
!= DW_AT_str_offsets_base
)
3383 printf (_(" (location list)"));
3386 case DW_AT_allocated
:
3387 case DW_AT_associated
:
3388 case DW_AT_data_location
:
3390 case DW_AT_upper_bound
:
3391 case DW_AT_lower_bound
:
3395 int need_frame_base
;
3398 need_frame_base
= decode_location_expression (block_start
,
3403 cu_offset
, section
);
3405 if (need_frame_base
&& !have_frame_base
)
3406 printf (_(" [without DW_AT_frame_base]"));
3410 case DW_AT_data_bit_offset
:
3411 case DW_AT_byte_size
:
3412 case DW_AT_bit_size
:
3413 case DW_AT_string_length_byte_size
:
3414 case DW_AT_string_length_bit_size
:
3415 case DW_AT_bit_stride
:
3416 if (form
== DW_FORM_exprloc
)
3419 (void) decode_location_expression (block_start
, pointer_size
,
3420 offset_size
, dwarf_version
,
3421 uvalue
, cu_offset
, section
);
3428 unsigned long abbrev_number
;
3429 abbrev_entry
*entry
;
3431 entry
= get_type_abbrev_from_form (form
, uvalue
, cu_offset
, end
,
3432 section
, & abbrev_number
, NULL
, NULL
);
3435 if (form
!= DW_FORM_GNU_ref_alt
)
3436 warn (_("Offset %#" PRIx64
" used as value for DW_AT_import attribute of DIE at offset %#tx is too big.\n"),
3438 orig_data
- section
->start
);
3442 printf (_("\t[Abbrev Number: %ld"), abbrev_number
);
3443 printf (" (%s)", get_TAG_name (entry
->tag
));
3456 static unsigned char *
3457 read_and_display_attr (unsigned long attribute
,
3459 int64_t implicit_const
,
3460 unsigned char *start
,
3461 unsigned char *data
,
3464 uint64_t pointer_size
,
3465 uint64_t offset_size
,
3467 debug_info
*debug_info_p
,
3469 struct dwarf_section
*section
,
3470 struct cu_tu_set
*this_set
,
3474 printf (" %-18s:", get_AT_name (attribute
));
3475 data
= read_and_display_attr_value (attribute
, form
, implicit_const
,
3477 cu_offset
, pointer_size
, offset_size
,
3478 dwarf_version
, debug_info_p
,
3479 do_loc
, section
, this_set
, ' ', level
);
3485 /* Like load_debug_section, but if the ordinary call fails, and we are
3486 following debug links, then attempt to load the requested section
3487 from one of the separate debug info files. */
3490 load_debug_section_with_follow (enum dwarf_section_display_enum sec_enum
,
3493 if (load_debug_section (sec_enum
, handle
))
3495 if (debug_displays
[sec_enum
].section
.filename
== NULL
)
3497 /* See if we can associate a filename with this section. */
3500 for (i
= first_separate_info
; i
!= NULL
; i
= i
->next
)
3501 if (i
->handle
== handle
)
3503 debug_displays
[sec_enum
].section
.filename
= i
->filename
;
3511 if (do_follow_links
)
3515 for (i
= first_separate_info
; i
!= NULL
; i
= i
->next
)
3517 if (load_debug_section (sec_enum
, i
->handle
))
3519 debug_displays
[sec_enum
].section
.filename
= i
->filename
;
3521 /* FIXME: We should check to see if any of the remaining debug info
3522 files also contain this section, and, umm, do something about it. */
3532 introduce (struct dwarf_section
* section
, bool raw
)
3536 if (do_follow_links
&& section
->filename
)
3537 printf (_("Raw dump of debug contents of section %s (loaded from %s):\n\n"),
3538 section
->name
, section
->filename
);
3540 printf (_("Raw dump of debug contents of section %s:\n\n"), section
->name
);
3544 if (do_follow_links
&& section
->filename
)
3545 printf (_("Contents of the %s section (loaded from %s):\n\n"),
3546 section
->name
, section
->filename
);
3548 printf (_("Contents of the %s section:\n\n"), section
->name
);
3552 /* Free memory allocated for one unit in debug_information. */
3555 free_debug_information (debug_info
*ent
)
3557 if (ent
->max_loc_offsets
)
3559 free (ent
->loc_offsets
);
3560 free (ent
->loc_views
);
3561 free (ent
->have_frame_base
);
3563 if (ent
->max_range_lists
)
3565 free (ent
->range_lists
);
3569 /* For look-ahead in attributes. When you want to scan a DIE for one specific
3570 attribute and ignore the rest. */
3572 static unsigned char *
3573 skip_attribute (unsigned long form
,
3574 unsigned char * data
,
3575 unsigned char * end
,
3576 uint64_t pointer_size
,
3577 uint64_t offset_size
,
3585 case DW_FORM_ref_addr
:
3586 data
+= dwarf_version
== 2 ? pointer_size
: offset_size
;
3589 data
+= pointer_size
;
3591 case DW_FORM_strp_sup
:
3593 case DW_FORM_line_strp
:
3594 case DW_FORM_sec_offset
:
3595 case DW_FORM_GNU_ref_alt
:
3596 case DW_FORM_GNU_strp_alt
:
3597 data
+= offset_size
;
3603 case DW_FORM_addrx1
:
3609 case DW_FORM_addrx2
:
3613 case DW_FORM_addrx3
:
3616 case DW_FORM_ref_sup4
:
3620 case DW_FORM_addrx4
:
3623 case DW_FORM_ref_sup8
:
3626 case DW_FORM_ref_sig8
:
3629 case DW_FORM_data16
:
3633 READ_SLEB (stemp
, data
, end
);
3635 case DW_FORM_GNU_str_index
:
3637 case DW_FORM_ref_udata
:
3639 case DW_FORM_GNU_addr_index
:
3641 case DW_FORM_loclistx
:
3642 case DW_FORM_rnglistx
:
3643 READ_ULEB (temp
, data
, end
);
3646 case DW_FORM_indirect
:
3647 while (form
== DW_FORM_indirect
)
3648 READ_ULEB (form
, data
, end
);
3649 return skip_attribute (form
, data
, end
, pointer_size
, offset_size
, dwarf_version
);
3651 case DW_FORM_string
:
3652 data
+= strnlen ((char *) data
, end
- data
);
3655 case DW_FORM_exprloc
:
3656 READ_ULEB (temp
, data
, end
);
3659 case DW_FORM_block1
:
3660 SAFE_BYTE_GET_AND_INC (temp
, data
, 1, end
);
3663 case DW_FORM_block2
:
3664 SAFE_BYTE_GET_AND_INC (temp
, data
, 2, end
);
3667 case DW_FORM_block4
:
3668 SAFE_BYTE_GET_AND_INC (temp
, data
, 4, end
);
3671 case DW_FORM_implicit_const
:
3672 case DW_FORM_flag_present
:
3675 warn (_("Unexpected form in top DIE\n"));
3682 read_bases (abbrev_entry
* entry
,
3683 unsigned char * data
,
3684 unsigned char * end
,
3685 int64_t pointer_size
,
3686 uint64_t offset_size
,
3688 debug_info
* debug_info_p
)
3692 for (attr
= entry
->first_attr
;
3693 attr
&& attr
->attribute
;
3698 if (attr
->attribute
== DW_AT_rnglists_base
)
3700 if (attr
->form
== DW_FORM_sec_offset
)
3702 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
3703 debug_info_p
->rnglists_base
= uvalue
;
3706 warn (_("Unexpected form of DW_AT_rnglists_base in the top DIE\n"));
3708 else if(attr
->attribute
== DW_AT_addr_base
|| attr
->attribute
== DW_AT_GNU_addr_base
)
3710 if (attr
->form
== DW_FORM_sec_offset
)
3712 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
3713 debug_info_p
->addr_base
= uvalue
;
3716 warn (_("Unexpected form of DW_AT_addr_base in the top DIE\n"));
3719 data
= skip_attribute(attr
->form
, data
, end
, pointer_size
, offset_size
, dwarf_version
);
3723 /* Process the contents of a .debug_info section.
3724 If do_loc is TRUE then we are scanning for location lists and dwo tags
3725 and we do not want to display anything to the user.
3726 If do_types is TRUE, we are processing a .debug_types section instead of
3727 a .debug_info section.
3728 The information displayed is restricted by the values in DWARF_START_DIE
3729 and DWARF_CUTOFF_LEVEL.
3730 Returns TRUE upon success. Otherwise an error or warning message is
3731 printed and FALSE is returned. */
3734 process_debug_info (struct dwarf_section
* section
,
3736 enum dwarf_section_display_enum abbrev_sec
,
3740 unsigned char *start
= section
->start
;
3741 unsigned char *end
= start
+ section
->size
;
3742 unsigned char *section_begin
;
3744 unsigned int num_units
= 0;
3746 /* First scan the section to get the number of comp units.
3747 Length sanity checks are done here. */
3748 for (section_begin
= start
, num_units
= 0; section_begin
< end
;
3753 /* Read the first 4 bytes. For a 32-bit DWARF section, this
3754 will be the length. For a 64-bit DWARF section, it'll be
3755 the escape code 0xffffffff followed by an 8 byte length. */
3756 SAFE_BYTE_GET_AND_INC (length
, section_begin
, 4, end
);
3758 if (length
== 0xffffffff)
3759 SAFE_BYTE_GET_AND_INC (length
, section_begin
, 8, end
);
3760 else if (length
>= 0xfffffff0 && length
< 0xffffffff)
3762 warn (_("Reserved length value (%#" PRIx64
") found in section %s\n"),
3763 length
, section
->name
);
3767 /* Negative values are illegal, they may even cause infinite
3768 looping. This can happen if we can't accurately apply
3769 relocations to an object file, or if the file is corrupt. */
3770 if (length
> (size_t) (end
- section_begin
))
3772 warn (_("Corrupt unit length (got %#" PRIx64
3773 " expected at most %#tx) in section %s\n"),
3774 length
, end
- section_begin
, section
->name
);
3777 section_begin
+= length
;
3782 error (_("No comp units in %s section ?\n"), section
->name
);
3786 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
|| do_debug_info
)
3787 && num_debug_info_entries
== 0
3791 /* Then allocate an array to hold the information. */
3792 debug_information
= (debug_info
*) cmalloc (num_units
,
3793 sizeof (* debug_information
));
3794 if (debug_information
== NULL
)
3796 error (_("Not enough memory for a debug info array of %u entries\n"),
3798 alloc_num_debug_info_entries
= num_debug_info_entries
= 0;
3802 /* PR 17531: file: 92ca3797.
3803 We cannot rely upon the debug_information array being initialised
3804 before it is used. A corrupt file could easily contain references
3805 to a unit for which information has not been made available. So
3806 we ensure that the array is zeroed here. */
3807 memset (debug_information
, 0, num_units
* sizeof (*debug_information
));
3809 alloc_num_debug_info_entries
= num_units
;
3814 load_debug_section_with_follow (str
, file
);
3815 load_debug_section_with_follow (line_str
, file
);
3816 load_debug_section_with_follow (str_dwo
, file
);
3817 load_debug_section_with_follow (str_index
, file
);
3818 load_debug_section_with_follow (str_index_dwo
, file
);
3819 load_debug_section_with_follow (debug_addr
, file
);
3822 load_debug_section_with_follow (abbrev_sec
, file
);
3823 load_debug_section_with_follow (loclists
, file
);
3824 load_debug_section_with_follow (rnglists
, file
);
3825 load_debug_section_with_follow (loclists_dwo
, file
);
3826 load_debug_section_with_follow (rnglists_dwo
, file
);
3828 if (debug_displays
[abbrev_sec
].section
.start
== NULL
)
3830 warn (_("Unable to locate %s section!\n"),
3831 debug_displays
[abbrev_sec
].section
.uncompressed_name
);
3835 if (!do_loc
&& dwarf_start_die
== 0)
3836 introduce (section
, false);
3838 free_all_abbrevs ();
3840 /* In order to be able to resolve DW_FORM_ref_addr forms we need
3841 to load *all* of the abbrevs for all CUs in this .debug_info
3842 section. This does effectively mean that we (partially) read
3843 every CU header twice. */
3844 for (section_begin
= start
; start
< end
;)
3846 DWARF2_Internal_CompUnit compunit
;
3847 unsigned char *hdrptr
;
3848 uint64_t abbrev_base
;
3851 unsigned int offset_size
;
3852 struct cu_tu_set
*this_set
;
3853 unsigned char *end_cu
;
3856 cu_offset
= start
- section_begin
;
3858 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 4, end
);
3860 if (compunit
.cu_length
== 0xffffffff)
3862 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 8, end
);
3867 end_cu
= hdrptr
+ compunit
.cu_length
;
3869 SAFE_BYTE_GET_AND_INC (compunit
.cu_version
, hdrptr
, 2, end_cu
);
3871 this_set
= find_cu_tu_set_v2 (cu_offset
, do_types
);
3873 if (compunit
.cu_version
< 5)
3875 compunit
.cu_unit_type
= DW_UT_compile
;
3876 /* Initialize it due to a false compiler warning. */
3877 compunit
.cu_pointer_size
= -1;
3881 SAFE_BYTE_GET_AND_INC (compunit
.cu_unit_type
, hdrptr
, 1, end_cu
);
3882 do_types
= (compunit
.cu_unit_type
== DW_UT_type
);
3884 SAFE_BYTE_GET_AND_INC (compunit
.cu_pointer_size
, hdrptr
, 1, end_cu
);
3887 SAFE_BYTE_GET_AND_INC (compunit
.cu_abbrev_offset
, hdrptr
, offset_size
,
3890 if (compunit
.cu_unit_type
== DW_UT_split_compile
3891 || compunit
.cu_unit_type
== DW_UT_skeleton
)
3894 SAFE_BYTE_GET_AND_INC (dwo_id
, hdrptr
, 8, end_cu
);
3897 if (this_set
== NULL
)
3900 abbrev_size
= debug_displays
[abbrev_sec
].section
.size
;
3904 abbrev_base
= this_set
->section_offsets
[DW_SECT_ABBREV
];
3905 abbrev_size
= this_set
->section_sizes
[DW_SECT_ABBREV
];
3909 abbrev_list
*free_list
;
3910 list
= find_and_process_abbrev_set (&debug_displays
[abbrev_sec
].section
,
3911 abbrev_base
, abbrev_size
,
3912 compunit
.cu_abbrev_offset
,
3915 if (list
!= NULL
&& list
->first_abbrev
!= NULL
)
3916 record_abbrev_list_for_cu (cu_offset
, start
- section_begin
,
3918 else if (free_list
!= NULL
)
3919 free_abbrev_list (free_list
);
3922 for (start
= section_begin
, unit
= 0; start
< end
; unit
++)
3924 DWARF2_Internal_CompUnit compunit
;
3925 unsigned char *hdrptr
;
3926 unsigned char *tags
;
3927 int level
, last_level
, saved_level
;
3929 unsigned int offset_size
;
3930 uint64_t signature
= 0;
3931 uint64_t type_offset
= 0;
3932 struct cu_tu_set
*this_set
;
3933 uint64_t abbrev_base
;
3935 unsigned char *end_cu
;
3938 cu_offset
= start
- section_begin
;
3940 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 4, end
);
3942 if (compunit
.cu_length
== 0xffffffff)
3944 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 8, end
);
3949 end_cu
= hdrptr
+ compunit
.cu_length
;
3951 SAFE_BYTE_GET_AND_INC (compunit
.cu_version
, hdrptr
, 2, end_cu
);
3953 this_set
= find_cu_tu_set_v2 (cu_offset
, do_types
);
3955 if (compunit
.cu_version
< 5)
3957 compunit
.cu_unit_type
= DW_UT_compile
;
3958 /* Initialize it due to a false compiler warning. */
3959 compunit
.cu_pointer_size
= -1;
3963 SAFE_BYTE_GET_AND_INC (compunit
.cu_unit_type
, hdrptr
, 1, end_cu
);
3964 do_types
= (compunit
.cu_unit_type
== DW_UT_type
);
3966 SAFE_BYTE_GET_AND_INC (compunit
.cu_pointer_size
, hdrptr
, 1, end_cu
);
3969 SAFE_BYTE_GET_AND_INC (compunit
.cu_abbrev_offset
, hdrptr
, offset_size
, end_cu
);
3971 if (this_set
== NULL
)
3974 abbrev_size
= debug_displays
[abbrev_sec
].section
.size
;
3978 abbrev_base
= this_set
->section_offsets
[DW_SECT_ABBREV
];
3979 abbrev_size
= this_set
->section_sizes
[DW_SECT_ABBREV
];
3982 if (compunit
.cu_version
< 5)
3983 SAFE_BYTE_GET_AND_INC (compunit
.cu_pointer_size
, hdrptr
, 1, end_cu
);
3985 bool do_dwo_id
= false;
3986 uint64_t dwo_id
= 0;
3987 if (compunit
.cu_unit_type
== DW_UT_split_compile
3988 || compunit
.cu_unit_type
== DW_UT_skeleton
)
3990 SAFE_BYTE_GET_AND_INC (dwo_id
, hdrptr
, 8, end_cu
);
3994 /* PR 17512: file: 001-108546-0.001:0.1. */
3995 if (compunit
.cu_pointer_size
< 2 || compunit
.cu_pointer_size
> 8)
3997 warn (_("Invalid pointer size (%d) in compunit header, using %d instead\n"),
3998 compunit
.cu_pointer_size
, offset_size
);
3999 compunit
.cu_pointer_size
= offset_size
;
4004 SAFE_BYTE_GET_AND_INC (signature
, hdrptr
, 8, end_cu
);
4005 SAFE_BYTE_GET_AND_INC (type_offset
, hdrptr
, offset_size
, end_cu
);
4008 if (dwarf_start_die
>= (size_t) (end_cu
- section_begin
))
4014 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
|| do_debug_info
)
4015 && num_debug_info_entries
== 0
4016 && alloc_num_debug_info_entries
> unit
4019 free_debug_information (&debug_information
[unit
]);
4020 memset (&debug_information
[unit
], 0, sizeof (*debug_information
));
4021 debug_information
[unit
].pointer_size
= compunit
.cu_pointer_size
;
4022 debug_information
[unit
].offset_size
= offset_size
;
4023 debug_information
[unit
].dwarf_version
= compunit
.cu_version
;
4024 debug_information
[unit
].cu_offset
= cu_offset
;
4025 debug_information
[unit
].addr_base
= DEBUG_INFO_UNAVAILABLE
;
4026 debug_information
[unit
].ranges_base
= DEBUG_INFO_UNAVAILABLE
;
4029 if (!do_loc
&& dwarf_start_die
== 0)
4031 printf (_(" Compilation Unit @ offset %#" PRIx64
":\n"),
4033 printf (_(" Length: %#" PRIx64
" (%s)\n"),
4035 offset_size
== 8 ? "64-bit" : "32-bit");
4036 printf (_(" Version: %d\n"), compunit
.cu_version
);
4037 if (compunit
.cu_version
>= 5)
4039 const char *name
= get_DW_UT_name (compunit
.cu_unit_type
);
4041 printf (_(" Unit Type: %s (%x)\n"),
4043 compunit
.cu_unit_type
);
4045 printf (_(" Abbrev Offset: %#" PRIx64
"\n"),
4046 compunit
.cu_abbrev_offset
);
4047 printf (_(" Pointer Size: %d\n"), compunit
.cu_pointer_size
);
4050 printf (_(" Signature: %#" PRIx64
"\n"), signature
);
4051 printf (_(" Type Offset: %#" PRIx64
"\n"), type_offset
);
4054 printf (_(" DWO ID: %#" PRIx64
"\n"), dwo_id
);
4055 if (this_set
!= NULL
)
4057 uint64_t *offsets
= this_set
->section_offsets
;
4058 size_t *sizes
= this_set
->section_sizes
;
4060 printf (_(" Section contributions:\n"));
4061 printf (_(" .debug_abbrev.dwo: %#" PRIx64
" %#zx\n"),
4062 offsets
[DW_SECT_ABBREV
], sizes
[DW_SECT_ABBREV
]);
4063 printf (_(" .debug_line.dwo: %#" PRIx64
" %#zx\n"),
4064 offsets
[DW_SECT_LINE
], sizes
[DW_SECT_LINE
]);
4065 printf (_(" .debug_loc.dwo: %#" PRIx64
" %#zx\n"),
4066 offsets
[DW_SECT_LOC
], sizes
[DW_SECT_LOC
]);
4067 printf (_(" .debug_str_offsets.dwo: %#" PRIx64
" %#zx\n"),
4068 offsets
[DW_SECT_STR_OFFSETS
], sizes
[DW_SECT_STR_OFFSETS
]);
4075 if (compunit
.cu_version
< 2 || compunit
.cu_version
> 5)
4077 warn (_("CU at offset %#" PRIx64
" contains corrupt or "
4078 "unsupported version number: %d.\n"),
4079 cu_offset
, compunit
.cu_version
);
4083 if (compunit
.cu_unit_type
!= DW_UT_compile
4084 && compunit
.cu_unit_type
!= DW_UT_partial
4085 && compunit
.cu_unit_type
!= DW_UT_type
4086 && compunit
.cu_unit_type
!= DW_UT_split_compile
4087 && compunit
.cu_unit_type
!= DW_UT_skeleton
)
4089 warn (_("CU at offset %#" PRIx64
" contains corrupt or "
4090 "unsupported unit type: %d.\n"),
4091 cu_offset
, compunit
.cu_unit_type
);
4095 /* Process the abbrevs used by this compilation unit. */
4097 list
= find_and_process_abbrev_set (&debug_displays
[abbrev_sec
].section
,
4098 abbrev_base
, abbrev_size
,
4099 compunit
.cu_abbrev_offset
, NULL
);
4103 while (tags
< start
)
4105 unsigned long abbrev_number
;
4106 unsigned long die_offset
;
4107 abbrev_entry
*entry
;
4109 int do_printing
= 1;
4111 die_offset
= tags
- section_begin
;
4113 READ_ULEB (abbrev_number
, tags
, start
);
4115 /* A null DIE marks the end of a list of siblings or it may also be
4116 a section padding. */
4117 if (abbrev_number
== 0)
4119 /* Check if it can be a section padding for the last CU. */
4120 if (level
== 0 && start
== end
)
4124 for (chk
= tags
; chk
< start
; chk
++)
4131 if (!do_loc
&& die_offset
>= dwarf_start_die
4132 && (dwarf_cutoff_level
== -1
4133 || level
< dwarf_cutoff_level
))
4134 printf (_(" <%d><%lx>: Abbrev Number: 0\n"),
4140 static unsigned num_bogus_warns
= 0;
4142 if (num_bogus_warns
< 3)
4144 warn (_("Bogus end-of-siblings marker detected at offset %lx in %s section\n"),
4145 die_offset
, section
->name
);
4147 if (num_bogus_warns
== 3)
4148 warn (_("Further warnings about bogus end-of-sibling markers suppressed\n"));
4151 if (dwarf_start_die
!= 0 && level
< saved_level
)
4154 free_abbrev_list (list
);
4162 if (dwarf_start_die
!= 0 && die_offset
< dwarf_start_die
)
4166 if (dwarf_start_die
!= 0 && die_offset
== dwarf_start_die
)
4167 saved_level
= level
;
4168 do_printing
= (dwarf_cutoff_level
== -1
4169 || level
< dwarf_cutoff_level
);
4171 printf (_(" <%d><%lx>: Abbrev Number: %lu"),
4172 level
, die_offset
, abbrev_number
);
4173 else if (dwarf_cutoff_level
== -1
4174 || last_level
< dwarf_cutoff_level
)
4175 printf (_(" <%d><%lx>: ...\n"), level
, die_offset
);
4180 /* Scan through the abbreviation list until we reach the
4184 for (entry
= list
->first_abbrev
; entry
!= NULL
; entry
= entry
->next
)
4185 if (entry
->number
== abbrev_number
)
4190 if (!do_loc
&& do_printing
)
4195 warn (_("DIE at offset %#lx refers to abbreviation number %lu which does not exist\n"),
4196 die_offset
, abbrev_number
);
4198 free_abbrev_list (list
);
4202 if (!do_loc
&& do_printing
)
4203 printf (" (%s)\n", get_TAG_name (entry
->tag
));
4208 need_base_address
= 0;
4210 case DW_TAG_compile_unit
:
4211 case DW_TAG_skeleton_unit
:
4212 need_base_address
= 1;
4213 need_dwo_info
= do_loc
;
4215 case DW_TAG_entry_point
:
4216 case DW_TAG_subprogram
:
4217 need_base_address
= 0;
4218 /* Assuming that there is no DW_AT_frame_base. */
4219 have_frame_base
= 0;
4223 debug_info
*debug_info_p
=
4224 (debug_information
&& unit
< alloc_num_debug_info_entries
)
4225 ? debug_information
+ unit
: NULL
;
4227 assert (!debug_info_p
4228 || (debug_info_p
->num_loc_offsets
4229 == debug_info_p
->num_loc_views
));
4231 /* Look ahead so that the values of DW_AT_rnglists_base, DW_AT_[GNU_]addr_base
4232 are available before attributes that reference them are parsed in the same DIE.
4233 Only needed for the top DIE on DWARFv5+.
4234 No simiar treatment for loclists_base because there should be no loclist
4235 attributes in top DIE. */
4236 if (compunit
.cu_version
>= 5 && level
== 0)
4243 compunit
.cu_pointer_size
,
4245 compunit
.cu_version
,
4248 /* This check was in place before, keep it. */
4249 stemp
= debug_info_p
->rnglists_base
;
4252 warn (_("CU @ %#" PRIx64
" has has a negative rnglists_base "
4253 "value of %#" PRIx64
" - treating as zero"),
4254 debug_info_p
->cu_offset
, stemp
);
4255 debug_info_p
->rnglists_base
= 0;
4259 for (attr
= entry
->first_attr
;
4260 attr
&& attr
->attribute
;
4263 if (! do_loc
&& do_printing
)
4264 /* Show the offset from where the tag was extracted. */
4265 printf (" <%tx>", tags
- section_begin
);
4266 tags
= read_and_display_attr (attr
->attribute
,
4268 attr
->implicit_const
,
4273 compunit
.cu_pointer_size
,
4275 compunit
.cu_version
,
4277 do_loc
|| ! do_printing
,
4283 /* If a locview attribute appears before a location one,
4284 make sure we don't associate it with an earlier
4287 switch (debug_info_p
->num_loc_offsets
- debug_info_p
->num_loc_views
)
4290 debug_info_p
->loc_views
[debug_info_p
->num_loc_views
] = -1;
4291 debug_info_p
->num_loc_views
++;
4292 assert (debug_info_p
->num_loc_views
4293 == debug_info_p
->num_loc_offsets
);
4300 warn(_("DIE has locviews without loclist\n"));
4301 debug_info_p
->num_loc_views
--;
4308 if (entry
->children
)
4312 free_abbrev_list (list
);
4315 /* Set num_debug_info_entries here so that it can be used to check if
4316 we need to process .debug_loc and .debug_ranges sections. */
4317 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
|| do_debug_info
)
4318 && num_debug_info_entries
== 0
4321 if (num_units
> alloc_num_debug_info_entries
)
4322 num_debug_info_entries
= alloc_num_debug_info_entries
;
4324 num_debug_info_entries
= num_units
;
4333 /* Locate and scan the .debug_info section in the file and record the pointer
4334 sizes and offsets for the compilation units in it. Usually an executable
4335 will have just one pointer size, but this is not guaranteed, and so we try
4336 not to make any assumptions. Returns zero upon failure, or the number of
4337 compilation units upon success. */
4340 load_debug_info (void * file
)
4342 /* If we have already tried and failed to load the .debug_info
4343 section then do not bother to repeat the task. */
4344 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
4347 /* If we already have the information there is nothing else to do. */
4348 if (num_debug_info_entries
> 0)
4349 return num_debug_info_entries
;
4351 /* If this is a DWARF package file, load the CU and TU indexes. */
4352 (void) load_cu_tu_indexes (file
);
4354 if (load_debug_section_with_follow (info
, file
)
4355 && process_debug_info (&debug_displays
[info
].section
, file
, abbrev
, true, false))
4356 return num_debug_info_entries
;
4358 if (load_debug_section_with_follow (info_dwo
, file
)
4359 && process_debug_info (&debug_displays
[info_dwo
].section
, file
,
4360 abbrev_dwo
, true, false))
4361 return num_debug_info_entries
;
4363 num_debug_info_entries
= DEBUG_INFO_UNAVAILABLE
;
4367 /* Read a DWARF .debug_line section header starting at DATA.
4368 Upon success returns an updated DATA pointer and the LINFO
4369 structure and the END_OF_SEQUENCE pointer will be filled in.
4370 Otherwise returns NULL. */
4372 static unsigned char *
4373 read_debug_line_header (struct dwarf_section
* section
,
4374 unsigned char * data
,
4375 unsigned char * end
,
4376 DWARF2_Internal_LineInfo
* linfo
,
4377 unsigned char ** end_of_sequence
)
4379 unsigned char *hdrptr
;
4381 /* Extract information from the Line Number Program Header.
4382 (section 6.2.4 in the Dwarf3 doc). */
4385 /* Get and check the length of the block. */
4386 SAFE_BYTE_GET_AND_INC (linfo
->li_length
, hdrptr
, 4, end
);
4388 if (linfo
->li_length
== 0xffffffff)
4390 /* This section is 64-bit DWARF 3. */
4391 SAFE_BYTE_GET_AND_INC (linfo
->li_length
, hdrptr
, 8, end
);
4392 linfo
->li_offset_size
= 8;
4395 linfo
->li_offset_size
= 4;
4397 if (linfo
->li_length
> (size_t) (end
- hdrptr
))
4399 /* If the length field has a relocation against it, then we should
4400 not complain if it is inaccurate (and probably negative). This
4401 happens in object files when the .debug_line section is actually
4402 comprised of several different .debug_line.* sections, (some of
4403 which may be removed by linker garbage collection), and a relocation
4404 is used to compute the correct length once that is done. */
4405 if (reloc_at (section
, (hdrptr
- section
->start
) - linfo
->li_offset_size
))
4407 linfo
->li_length
= end
- hdrptr
;
4411 warn (_("The length field (%#" PRIx64
")"
4412 " in the debug_line header is wrong"
4413 " - the section is too small\n"),
4418 end
= hdrptr
+ linfo
->li_length
;
4420 /* Get and check the version number. */
4421 SAFE_BYTE_GET_AND_INC (linfo
->li_version
, hdrptr
, 2, end
);
4423 if (linfo
->li_version
!= 2
4424 && linfo
->li_version
!= 3
4425 && linfo
->li_version
!= 4
4426 && linfo
->li_version
!= 5)
4428 warn (_("Only DWARF version 2, 3, 4 and 5 line info "
4429 "is currently supported.\n"));
4433 if (linfo
->li_version
>= 5)
4435 SAFE_BYTE_GET_AND_INC (linfo
->li_address_size
, hdrptr
, 1, end
);
4437 SAFE_BYTE_GET_AND_INC (linfo
->li_segment_size
, hdrptr
, 1, end
);
4438 if (linfo
->li_segment_size
!= 0)
4440 warn (_("The %s section contains "
4441 "unsupported segment selector size: %d.\n"),
4442 section
->name
, linfo
->li_segment_size
);
4447 SAFE_BYTE_GET_AND_INC (linfo
->li_prologue_length
, hdrptr
,
4448 linfo
->li_offset_size
, end
);
4449 SAFE_BYTE_GET_AND_INC (linfo
->li_min_insn_length
, hdrptr
, 1, end
);
4451 if (linfo
->li_version
>= 4)
4453 SAFE_BYTE_GET_AND_INC (linfo
->li_max_ops_per_insn
, hdrptr
, 1, end
);
4455 if (linfo
->li_max_ops_per_insn
== 0)
4457 warn (_("Invalid maximum operations per insn.\n"));
4462 linfo
->li_max_ops_per_insn
= 1;
4464 SAFE_BYTE_GET_AND_INC (linfo
->li_default_is_stmt
, hdrptr
, 1, end
);
4465 SAFE_SIGNED_BYTE_GET_AND_INC (linfo
->li_line_base
, hdrptr
, 1, end
);
4466 SAFE_BYTE_GET_AND_INC (linfo
->li_line_range
, hdrptr
, 1, end
);
4467 SAFE_BYTE_GET_AND_INC (linfo
->li_opcode_base
, hdrptr
, 1, end
);
4469 *end_of_sequence
= end
;
4473 static unsigned char *
4474 display_formatted_table (unsigned char *data
,
4475 unsigned char *start
,
4477 const DWARF2_Internal_LineInfo
*linfo
,
4478 struct dwarf_section
*section
,
4481 unsigned char *format_start
, format_count
, *format
, formati
;
4482 uint64_t data_count
, datai
;
4483 unsigned int namepass
, last_entry
= 0;
4484 const char * table_name
= is_dir
? N_("Directory Table") : N_("File Name Table");
4486 SAFE_BYTE_GET_AND_INC (format_count
, data
, 1, end
);
4487 if (do_checks
&& format_count
> 5)
4488 warn (_("Unexpectedly large number of columns in the %s (%u)\n"),
4489 table_name
, format_count
);
4491 format_start
= data
;
4492 for (formati
= 0; formati
< format_count
; formati
++)
4494 SKIP_ULEB (data
, end
);
4495 SKIP_ULEB (data
, end
);
4498 warn (_("%s: Corrupt format description entry\n"), table_name
);
4503 READ_ULEB (data_count
, data
, end
);
4504 if (data_count
== 0)
4506 printf (_("\n The %s is empty.\n"), table_name
);
4509 else if (data
>= end
4510 || data_count
> (size_t) (end
- data
))
4512 warn (_("%s: Corrupt entry count %#" PRIx64
"\n"), table_name
, data_count
);
4516 else if (format_count
== 0)
4518 warn (_("%s: format count is zero, but the table is not empty\n"),
4523 printf (_("\n The %s (offset %#tx, lines %" PRIu64
", columns %u):\n"),
4524 table_name
, data
- start
, data_count
, format_count
);
4526 printf (_(" Entry"));
4527 /* Delay displaying name as the last entry for better screen layout. */
4528 for (namepass
= 0; namepass
< 2; namepass
++)
4530 format
= format_start
;
4531 for (formati
= 0; formati
< format_count
; formati
++)
4533 uint64_t content_type
;
4535 READ_ULEB (content_type
, format
, end
);
4536 if ((content_type
== DW_LNCT_path
) == (namepass
== 1))
4537 switch (content_type
)
4540 printf (_("\tName"));
4542 case DW_LNCT_directory_index
:
4543 printf (_("\tDir"));
4545 case DW_LNCT_timestamp
:
4546 printf (_("\tTime"));
4549 printf (_("\tSize"));
4552 printf (_("\tMD5\t\t\t"));
4555 printf (_("\t(Unknown format content type %" PRIu64
")"),
4558 SKIP_ULEB (format
, end
);
4563 for (datai
= 0; datai
< data_count
; datai
++)
4565 unsigned char *datapass
= data
;
4567 printf (" %d", last_entry
++);
4568 /* Delay displaying name as the last entry for better screen layout. */
4569 for (namepass
= 0; namepass
< 2; namepass
++)
4571 format
= format_start
;
4573 for (formati
= 0; formati
< format_count
; formati
++)
4575 uint64_t content_type
, form
;
4577 READ_ULEB (content_type
, format
, end
);
4578 READ_ULEB (form
, format
, end
);
4579 data
= read_and_display_attr_value (0, form
, 0, start
, data
, end
,
4580 0, 0, linfo
->li_offset_size
,
4581 linfo
->li_version
, NULL
,
4582 ((content_type
== DW_LNCT_path
) != (namepass
== 1)),
4583 section
, NULL
, '\t', -1);
4587 if (data
>= end
&& (datai
< data_count
- 1))
4589 warn (_("\n%s: Corrupt entries list\n"), table_name
);
4598 display_debug_sup (struct dwarf_section
* section
,
4599 void * file ATTRIBUTE_UNUSED
)
4601 unsigned char * start
= section
->start
;
4602 unsigned char * end
= section
->start
+ section
->size
;
4603 unsigned int version
;
4604 char is_supplementary
;
4605 const unsigned char * sup_filename
;
4606 size_t sup_filename_len
;
4607 unsigned int num_read
;
4609 uint64_t checksum_len
;
4612 introduce (section
, true);
4613 if (section
->size
< 4)
4615 error (_("corrupt .debug_sup section: size is too small\n"));
4619 /* Read the data. */
4620 SAFE_BYTE_GET_AND_INC (version
, start
, 2, end
);
4622 warn (_("corrupt .debug_sup section: version < 5"));
4624 SAFE_BYTE_GET_AND_INC (is_supplementary
, start
, 1, end
);
4625 if (is_supplementary
!= 0 && is_supplementary
!= 1)
4626 warn (_("corrupt .debug_sup section: is_supplementary not 0 or 1\n"));
4628 sup_filename
= start
;
4629 if (is_supplementary
&& sup_filename
[0] != 0)
4630 warn (_("corrupt .debug_sup section: filename not empty in supplementary section\n"));
4632 sup_filename_len
= strnlen ((const char *) start
, end
- start
);
4633 if (sup_filename_len
== (size_t) (end
- start
))
4635 error (_("corrupt .debug_sup section: filename is not NUL terminated\n"));
4638 start
+= sup_filename_len
+ 1;
4640 checksum_len
= read_leb128 (start
, end
, false /* unsigned */, & num_read
, & status
);
4643 error (_("corrupt .debug_sup section: bad LEB128 field for checksum length\n"));
4647 if (checksum_len
> (size_t) (end
- start
))
4649 error (_("corrupt .debug_sup section: checksum length is longer than the remaining section length\n"));
4650 checksum_len
= end
- start
;
4652 else if (checksum_len
< (size_t) (end
- start
))
4654 warn (_("corrupt .debug_sup section: there are %#" PRIx64
4655 " extra, unused bytes at the end of the section\n"),
4656 (end
- start
) - checksum_len
);
4659 printf (_(" Version: %u\n"), version
);
4660 printf (_(" Is Supp: %u\n"), is_supplementary
);
4661 printf (_(" Filename: %s\n"), sup_filename
);
4662 printf (_(" Checksum Len: %" PRIu64
"\n"), checksum_len
);
4663 if (checksum_len
> 0)
4665 printf (_(" Checksum: "));
4666 while (checksum_len
--)
4667 printf ("0x%x ", * start
++ );
4674 display_debug_lines_raw (struct dwarf_section
* section
,
4675 unsigned char * data
,
4676 unsigned char * end
,
4679 unsigned char *start
= section
->start
;
4680 int verbose_view
= 0;
4682 introduce (section
, true);
4686 static DWARF2_Internal_LineInfo saved_linfo
;
4687 DWARF2_Internal_LineInfo linfo
;
4688 unsigned char *standard_opcodes
;
4689 unsigned char *end_of_sequence
;
4692 if (startswith (section
->name
, ".debug_line.")
4693 /* Note: the following does not apply to .debug_line.dwo sections.
4694 These are full debug_line sections. */
4695 && strcmp (section
->name
, ".debug_line.dwo") != 0)
4697 /* Sections named .debug_line.<foo> are fragments of a .debug_line
4698 section containing just the Line Number Statements. They are
4699 created by the assembler and intended to be used alongside gcc's
4700 -ffunction-sections command line option. When the linker's
4701 garbage collection decides to discard a .text.<foo> section it
4702 can then also discard the line number information in .debug_line.<foo>.
4704 Since the section is a fragment it does not have the details
4705 needed to fill out a LineInfo structure, so instead we use the
4706 details from the last full debug_line section that we processed. */
4707 end_of_sequence
= end
;
4708 standard_opcodes
= NULL
;
4709 linfo
= saved_linfo
;
4710 /* PR 17531: file: 0522b371. */
4711 if (linfo
.li_line_range
== 0)
4713 warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n"));
4716 reset_state_machine (linfo
.li_default_is_stmt
);
4720 unsigned char * hdrptr
;
4722 if ((hdrptr
= read_debug_line_header (section
, data
, end
, & linfo
,
4723 & end_of_sequence
)) == NULL
)
4726 printf (_(" Offset: %#tx\n"), data
- start
);
4727 printf (_(" Length: %" PRId64
"\n"), linfo
.li_length
);
4728 printf (_(" DWARF Version: %d\n"), linfo
.li_version
);
4729 if (linfo
.li_version
>= 5)
4731 printf (_(" Address size (bytes): %d\n"), linfo
.li_address_size
);
4732 printf (_(" Segment selector (bytes): %d\n"), linfo
.li_segment_size
);
4734 printf (_(" Prologue Length: %d\n"), (int) linfo
.li_prologue_length
);
4735 printf (_(" Minimum Instruction Length: %d\n"), linfo
.li_min_insn_length
);
4736 if (linfo
.li_version
>= 4)
4737 printf (_(" Maximum Ops per Instruction: %d\n"), linfo
.li_max_ops_per_insn
);
4738 printf (_(" Initial value of 'is_stmt': %d\n"), linfo
.li_default_is_stmt
);
4739 printf (_(" Line Base: %d\n"), linfo
.li_line_base
);
4740 printf (_(" Line Range: %d\n"), linfo
.li_line_range
);
4741 printf (_(" Opcode Base: %d\n"), linfo
.li_opcode_base
);
4743 /* PR 17512: file: 1665-6428-0.004. */
4744 if (linfo
.li_line_range
== 0)
4746 warn (_("Line range of 0 is invalid, using 1 instead\n"));
4747 linfo
.li_line_range
= 1;
4750 reset_state_machine (linfo
.li_default_is_stmt
);
4752 /* Display the contents of the Opcodes table. */
4753 standard_opcodes
= hdrptr
;
4755 /* PR 17512: file: 002-417945-0.004. */
4756 if (standard_opcodes
+ linfo
.li_opcode_base
>= end
)
4758 warn (_("Line Base extends beyond end of section\n"));
4762 printf (_("\n Opcodes:\n"));
4764 for (i
= 1; i
< linfo
.li_opcode_base
; i
++)
4765 printf (ngettext (" Opcode %d has %d arg\n",
4766 " Opcode %d has %d args\n",
4767 standard_opcodes
[i
- 1]),
4768 i
, standard_opcodes
[i
- 1]);
4770 /* Display the contents of the Directory table. */
4771 data
= standard_opcodes
+ linfo
.li_opcode_base
- 1;
4773 if (linfo
.li_version
>= 5)
4775 load_debug_section_with_follow (line_str
, file
);
4777 data
= display_formatted_table (data
, start
, end
, &linfo
, section
,
4779 data
= display_formatted_table (data
, start
, end
, &linfo
, section
,
4785 printf (_("\n The Directory Table is empty.\n"));
4788 unsigned int last_dir_entry
= 0;
4790 printf (_("\n The Directory Table (offset %#tx):\n"),
4793 while (data
< end
&& *data
!= 0)
4795 printf (" %d\t%.*s\n", ++last_dir_entry
, (int) (end
- data
), data
);
4797 data
+= strnlen ((char *) data
, end
- data
);
4802 /* PR 17512: file: 002-132094-0.004. */
4803 if (data
>= end
- 1)
4807 /* Skip the NUL at the end of the table. */
4811 /* Display the contents of the File Name table. */
4812 if (data
>= end
|| *data
== 0)
4813 printf (_("\n The File Name Table is empty.\n"));
4816 printf (_("\n The File Name Table (offset %#tx):\n"),
4818 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
4820 while (data
< end
&& *data
!= 0)
4822 unsigned char *name
;
4825 printf (" %d\t", ++state_machine_regs
.last_file_entry
);
4827 data
+= strnlen ((char *) data
, end
- data
);
4831 READ_ULEB (val
, data
, end
);
4832 printf ("%" PRIu64
"\t", val
);
4833 READ_ULEB (val
, data
, end
);
4834 printf ("%" PRIu64
"\t", val
);
4835 READ_ULEB (val
, data
, end
);
4836 printf ("%" PRIu64
"\t", val
);
4837 printf ("%.*s\n", (int)(end
- name
), name
);
4841 warn (_("Corrupt file name table entry\n"));
4847 /* Skip the NUL at the end of the table. */
4853 saved_linfo
= linfo
;
4856 /* Now display the statements. */
4857 if (data
>= end_of_sequence
)
4858 printf (_(" No Line Number Statements.\n"));
4861 printf (_(" Line Number Statements:\n"));
4863 while (data
< end_of_sequence
)
4865 unsigned char op_code
;
4869 printf (" [0x%08tx]", data
- start
);
4873 if (op_code
>= linfo
.li_opcode_base
)
4875 op_code
-= linfo
.li_opcode_base
;
4876 uladv
= (op_code
/ linfo
.li_line_range
);
4877 if (linfo
.li_max_ops_per_insn
== 1)
4879 uladv
*= linfo
.li_min_insn_length
;
4880 state_machine_regs
.address
+= uladv
;
4882 state_machine_regs
.view
= 0;
4883 printf (_(" Special opcode %d: "
4884 "advance Address by %" PRIu64
4885 " to %#" PRIx64
"%s"),
4886 op_code
, uladv
, state_machine_regs
.address
,
4887 verbose_view
&& uladv
4888 ? _(" (reset view)") : "");
4893 = ((state_machine_regs
.op_index
+ uladv
)
4894 / linfo
.li_max_ops_per_insn
)
4895 * linfo
.li_min_insn_length
;
4897 state_machine_regs
.address
+= addrdelta
;
4898 state_machine_regs
.op_index
4899 = (state_machine_regs
.op_index
+ uladv
)
4900 % linfo
.li_max_ops_per_insn
;
4902 state_machine_regs
.view
= 0;
4903 printf (_(" Special opcode %d: "
4904 "advance Address by %" PRIu64
4905 " to %#" PRIx64
"[%d]%s"),
4906 op_code
, uladv
, state_machine_regs
.address
,
4907 state_machine_regs
.op_index
,
4908 verbose_view
&& addrdelta
4909 ? _(" (reset view)") : "");
4911 adv
= (op_code
% linfo
.li_line_range
) + linfo
.li_line_base
;
4912 state_machine_regs
.line
+= adv
;
4913 printf (_(" and Line by %d to %d"),
4914 adv
, state_machine_regs
.line
);
4915 if (verbose_view
|| state_machine_regs
.view
)
4916 printf (_(" (view %u)\n"), state_machine_regs
.view
);
4919 state_machine_regs
.view
++;
4924 case DW_LNS_extended_op
:
4925 data
+= process_extended_line_op (data
,
4926 linfo
.li_default_is_stmt
,
4931 printf (_(" Copy"));
4932 if (verbose_view
|| state_machine_regs
.view
)
4933 printf (_(" (view %u)\n"), state_machine_regs
.view
);
4936 state_machine_regs
.view
++;
4939 case DW_LNS_advance_pc
:
4940 READ_ULEB (uladv
, data
, end
);
4941 if (linfo
.li_max_ops_per_insn
== 1)
4943 uladv
*= linfo
.li_min_insn_length
;
4944 state_machine_regs
.address
+= uladv
;
4946 state_machine_regs
.view
= 0;
4947 printf (_(" Advance PC by %" PRIu64
4948 " to %#" PRIx64
"%s\n"),
4949 uladv
, state_machine_regs
.address
,
4950 verbose_view
&& uladv
4951 ? _(" (reset view)") : "");
4956 = ((state_machine_regs
.op_index
+ uladv
)
4957 / linfo
.li_max_ops_per_insn
)
4958 * linfo
.li_min_insn_length
;
4959 state_machine_regs
.address
4961 state_machine_regs
.op_index
4962 = (state_machine_regs
.op_index
+ uladv
)
4963 % linfo
.li_max_ops_per_insn
;
4965 state_machine_regs
.view
= 0;
4966 printf (_(" Advance PC by %" PRIu64
4967 " to %#" PRIx64
"[%d]%s\n"),
4968 uladv
, state_machine_regs
.address
,
4969 state_machine_regs
.op_index
,
4970 verbose_view
&& addrdelta
4971 ? _(" (reset view)") : "");
4975 case DW_LNS_advance_line
:
4976 READ_SLEB (adv
, data
, end
);
4977 state_machine_regs
.line
+= adv
;
4978 printf (_(" Advance Line by %d to %d\n"),
4979 adv
, state_machine_regs
.line
);
4982 case DW_LNS_set_file
:
4983 READ_ULEB (uladv
, data
, end
);
4984 printf (_(" Set File Name to entry %" PRIu64
4985 " in the File Name Table\n"), uladv
);
4986 state_machine_regs
.file
= uladv
;
4989 case DW_LNS_set_column
:
4990 READ_ULEB (uladv
, data
, end
);
4991 printf (_(" Set column to %" PRIu64
"\n"), uladv
);
4992 state_machine_regs
.column
= uladv
;
4995 case DW_LNS_negate_stmt
:
4996 adv
= state_machine_regs
.is_stmt
;
4998 printf (_(" Set is_stmt to %d\n"), adv
);
4999 state_machine_regs
.is_stmt
= adv
;
5002 case DW_LNS_set_basic_block
:
5003 printf (_(" Set basic block\n"));
5004 state_machine_regs
.basic_block
= 1;
5007 case DW_LNS_const_add_pc
:
5008 uladv
= ((255 - linfo
.li_opcode_base
) / linfo
.li_line_range
);
5009 if (linfo
.li_max_ops_per_insn
)
5011 uladv
*= linfo
.li_min_insn_length
;
5012 state_machine_regs
.address
+= uladv
;
5014 state_machine_regs
.view
= 0;
5015 printf (_(" Advance PC by constant %" PRIu64
5016 " to %#" PRIx64
"%s\n"),
5017 uladv
, state_machine_regs
.address
,
5018 verbose_view
&& uladv
5019 ? _(" (reset view)") : "");
5024 = ((state_machine_regs
.op_index
+ uladv
)
5025 / linfo
.li_max_ops_per_insn
)
5026 * linfo
.li_min_insn_length
;
5027 state_machine_regs
.address
5029 state_machine_regs
.op_index
5030 = (state_machine_regs
.op_index
+ uladv
)
5031 % linfo
.li_max_ops_per_insn
;
5033 state_machine_regs
.view
= 0;
5034 printf (_(" Advance PC by constant %" PRIu64
5035 " to %#" PRIx64
"[%d]%s\n"),
5036 uladv
, state_machine_regs
.address
,
5037 state_machine_regs
.op_index
,
5038 verbose_view
&& addrdelta
5039 ? _(" (reset view)") : "");
5043 case DW_LNS_fixed_advance_pc
:
5044 SAFE_BYTE_GET_AND_INC (uladv
, data
, 2, end
);
5045 state_machine_regs
.address
+= uladv
;
5046 state_machine_regs
.op_index
= 0;
5047 printf (_(" Advance PC by fixed size amount %" PRIu64
5048 " to %#" PRIx64
"\n"),
5049 uladv
, state_machine_regs
.address
);
5050 /* Do NOT reset view. */
5053 case DW_LNS_set_prologue_end
:
5054 printf (_(" Set prologue_end to true\n"));
5057 case DW_LNS_set_epilogue_begin
:
5058 printf (_(" Set epilogue_begin to true\n"));
5061 case DW_LNS_set_isa
:
5062 READ_ULEB (uladv
, data
, end
);
5063 printf (_(" Set ISA to %" PRIu64
"\n"), uladv
);
5067 printf (_(" Unknown opcode %d with operands: "), op_code
);
5069 if (standard_opcodes
!= NULL
)
5070 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
5072 READ_ULEB (uladv
, data
, end
);
5073 printf ("%#" PRIx64
"%s", uladv
, i
== 1 ? "" : ", ");
5089 unsigned int directory_index
;
5090 unsigned int modification_date
;
5091 unsigned int length
;
5094 /* Output a decoded representation of the .debug_line section. */
5097 display_debug_lines_decoded (struct dwarf_section
* section
,
5098 unsigned char * start
,
5099 unsigned char * data
,
5100 unsigned char * end
,
5103 static DWARF2_Internal_LineInfo saved_linfo
;
5105 introduce (section
, false);
5109 /* This loop amounts to one iteration per compilation unit. */
5110 DWARF2_Internal_LineInfo linfo
;
5111 unsigned char *standard_opcodes
;
5112 unsigned char *end_of_sequence
;
5114 File_Entry
*file_table
= NULL
;
5115 unsigned int n_files
= 0;
5116 char **directory_table
= NULL
;
5117 unsigned int n_directories
= 0;
5119 if (startswith (section
->name
, ".debug_line.")
5120 /* Note: the following does not apply to .debug_line.dwo sections.
5121 These are full debug_line sections. */
5122 && strcmp (section
->name
, ".debug_line.dwo") != 0)
5124 /* See comment in display_debug_lines_raw(). */
5125 end_of_sequence
= end
;
5126 standard_opcodes
= NULL
;
5127 linfo
= saved_linfo
;
5128 /* PR 17531: file: 0522b371. */
5129 if (linfo
.li_line_range
== 0)
5131 warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n"));
5134 reset_state_machine (linfo
.li_default_is_stmt
);
5138 unsigned char *hdrptr
;
5140 if ((hdrptr
= read_debug_line_header (section
, data
, end
, & linfo
,
5141 & end_of_sequence
)) == NULL
)
5144 /* PR 17531: file: 0522b371. */
5145 if (linfo
.li_line_range
== 0)
5147 warn (_("Line range of 0 is invalid, using 1 instead\n"));
5148 linfo
.li_line_range
= 1;
5150 reset_state_machine (linfo
.li_default_is_stmt
);
5152 /* Save a pointer to the contents of the Opcodes table. */
5153 standard_opcodes
= hdrptr
;
5155 /* Traverse the Directory table just to count entries. */
5156 data
= standard_opcodes
+ linfo
.li_opcode_base
- 1;
5160 warn (_("opcode base of %d extends beyond end of section\n"),
5161 linfo
.li_opcode_base
);
5165 if (linfo
.li_version
>= 5)
5167 unsigned char *format_start
, *format
;
5168 unsigned int format_count
, formati
, entryi
;
5170 load_debug_section_with_follow (line_str
, fileptr
);
5172 /* Skip directories format. */
5173 SAFE_BYTE_GET_AND_INC (format_count
, data
, 1, end
);
5174 if (do_checks
&& format_count
> 1)
5175 warn (_("Unexpectedly large number of columns in the directory name table (%u)\n"),
5177 format_start
= data
;
5178 for (formati
= 0; formati
< format_count
; formati
++)
5180 SKIP_ULEB (data
, end
);
5181 SKIP_ULEB (data
, end
);
5184 READ_ULEB (n_directories
, data
, end
);
5187 warn (_("Corrupt directories list\n"));
5191 if (n_directories
== 0)
5192 directory_table
= NULL
;
5193 else if (n_directories
> section
->size
)
5195 warn (_("number of directories (0x%x) exceeds size of section %s\n"),
5196 n_directories
, section
->name
);
5200 directory_table
= (char **)
5201 xcalloc (n_directories
, sizeof (unsigned char *));
5203 for (entryi
= 0; entryi
< n_directories
; entryi
++)
5205 char **pathp
= &directory_table
[entryi
];
5207 format
= format_start
;
5208 for (formati
= 0; formati
< format_count
; formati
++)
5210 uint64_t content_type
, form
;
5213 READ_ULEB (content_type
, format
, end
);
5214 READ_ULEB (form
, format
, end
);
5217 warn (_("Corrupt directories list\n"));
5220 switch (content_type
)
5225 case DW_FORM_string
:
5226 *pathp
= (char *) data
;
5228 case DW_FORM_line_strp
:
5229 SAFE_BYTE_GET (uvalue
, data
, linfo
.li_offset_size
,
5231 /* Remove const by the cast. */
5233 fetch_indirect_line_string (uvalue
);
5238 data
= read_and_display_attr_value (0, form
, 0, start
,
5240 linfo
.li_offset_size
,
5247 warn (_("Corrupt directories list\n"));
5252 /* Skip files format. */
5253 SAFE_BYTE_GET_AND_INC (format_count
, data
, 1, end
);
5254 if (do_checks
&& format_count
> 5)
5255 warn (_("Unexpectedly large number of columns in the file name table (%u)\n"),
5258 format_start
= data
;
5259 for (formati
= 0; formati
< format_count
; formati
++)
5261 SKIP_ULEB (data
, end
);
5262 SKIP_ULEB (data
, end
);
5265 READ_ULEB (n_files
, data
, end
);
5266 if (data
>= end
&& n_files
> 0)
5268 warn (_("Corrupt file name list\n"));
5274 else if (n_files
> section
->size
)
5276 warn (_("number of files (0x%x) exceeds size of section %s\n"),
5277 n_files
, section
->name
);
5281 file_table
= (File_Entry
*) xcalloc (n_files
,
5282 sizeof (File_Entry
));
5284 for (entryi
= 0; entryi
< n_files
; entryi
++)
5286 File_Entry
*file
= &file_table
[entryi
];
5288 format
= format_start
;
5289 for (formati
= 0; formati
< format_count
; formati
++)
5291 uint64_t content_type
, form
;
5295 READ_ULEB (content_type
, format
, end
);
5296 READ_ULEB (form
, format
, end
);
5299 warn (_("Corrupt file name list\n"));
5302 switch (content_type
)
5307 case DW_FORM_string
:
5308 file
->name
= (char *) data
;
5310 case DW_FORM_line_strp
:
5311 SAFE_BYTE_GET (uvalue
, data
, linfo
.li_offset_size
,
5313 /* Remove const by the cast. */
5314 file
->name
= (char *)
5315 fetch_indirect_line_string (uvalue
);
5319 case DW_LNCT_directory_index
:
5323 SAFE_BYTE_GET (file
->directory_index
, data
, 1,
5327 SAFE_BYTE_GET (file
->directory_index
, data
, 2,
5332 READ_ULEB (file
->directory_index
, tmp
, end
);
5337 data
= read_and_display_attr_value (0, form
, 0, start
,
5339 linfo
.li_offset_size
,
5346 warn (_("Corrupt file name list\n"));
5355 char *ptr_directory_table
= (char *) data
;
5357 while (data
< end
&& *data
!= 0)
5359 data
+= strnlen ((char *) data
, end
- data
);
5368 warn (_("directory table ends unexpectedly\n"));
5373 /* Go through the directory table again to save the directories. */
5374 directory_table
= (char **)
5375 xmalloc (n_directories
* sizeof (unsigned char *));
5378 while (*ptr_directory_table
!= 0)
5380 directory_table
[i
] = ptr_directory_table
;
5381 ptr_directory_table
+= strlen (ptr_directory_table
) + 1;
5385 /* Skip the NUL at the end of the table. */
5388 /* Traverse the File Name table just to count the entries. */
5389 if (data
< end
&& *data
!= 0)
5391 unsigned char *ptr_file_name_table
= data
;
5393 while (data
< end
&& *data
!= 0)
5395 /* Skip Name, directory index, last modification
5396 time and length of file. */
5397 data
+= strnlen ((char *) data
, end
- data
);
5400 SKIP_ULEB (data
, end
);
5401 SKIP_ULEB (data
, end
);
5402 SKIP_ULEB (data
, end
);
5408 warn (_("file table ends unexpectedly\n"));
5413 /* Go through the file table again to save the strings. */
5414 file_table
= (File_Entry
*) xmalloc (n_files
* sizeof (File_Entry
));
5417 while (*ptr_file_name_table
!= 0)
5419 file_table
[i
].name
= (char *) ptr_file_name_table
;
5421 += strlen ((char *) ptr_file_name_table
) + 1;
5423 /* We are not interested in directory, time or size. */
5424 READ_ULEB (file_table
[i
].directory_index
,
5425 ptr_file_name_table
, end
);
5426 READ_ULEB (file_table
[i
].modification_date
,
5427 ptr_file_name_table
, end
);
5428 READ_ULEB (file_table
[i
].length
,
5429 ptr_file_name_table
, end
);
5435 /* Skip the NUL at the end of the table. */
5439 /* Print the Compilation Unit's name and a header. */
5440 if (file_table
== NULL
)
5441 printf (_("CU: No directory table\n"));
5442 else if (directory_table
== NULL
)
5443 printf (_("CU: %s:\n"), null_name (file_table
[0].name
));
5446 unsigned int ix
= file_table
[0].directory_index
;
5447 const char *directory
;
5449 if (ix
== 0 && linfo
.li_version
< 5)
5452 else if (n_directories
== 0)
5453 directory
= _("<unknown>");
5456 if (linfo
.li_version
< 5)
5458 if (ix
>= n_directories
)
5460 warn (_("directory index %u "
5461 ">= number of directories %u\n"),
5463 directory
= _("<corrupt>");
5466 directory
= directory_table
[ix
];
5469 printf (_("CU: %s/%s:\n"),
5470 null_name (directory
),
5471 null_name (file_table
[0].name
));
5473 printf ("%s:\n", null_name (file_table
[0].name
));
5479 printf (_("File name Line number Starting address View Stmt\n"));
5481 printf (_("File name Line number Starting address View Stmt\n"));
5484 printf (_("CU: Empty file name table\n"));
5485 saved_linfo
= linfo
;
5488 /* This loop iterates through the Dwarf Line Number Program. */
5489 while (data
< end_of_sequence
)
5491 unsigned char op_code
;
5494 unsigned long int uladv
;
5495 int is_special_opcode
= 0;
5500 if (op_code
>= linfo
.li_opcode_base
)
5502 op_code
-= linfo
.li_opcode_base
;
5503 uladv
= (op_code
/ linfo
.li_line_range
);
5504 if (linfo
.li_max_ops_per_insn
== 1)
5506 uladv
*= linfo
.li_min_insn_length
;
5507 state_machine_regs
.address
+= uladv
;
5509 state_machine_regs
.view
= 0;
5514 = ((state_machine_regs
.op_index
+ uladv
)
5515 / linfo
.li_max_ops_per_insn
)
5516 * linfo
.li_min_insn_length
;
5517 state_machine_regs
.address
5519 state_machine_regs
.op_index
5520 = (state_machine_regs
.op_index
+ uladv
)
5521 % linfo
.li_max_ops_per_insn
;
5523 state_machine_regs
.view
= 0;
5526 adv
= (op_code
% linfo
.li_line_range
) + linfo
.li_line_base
;
5527 state_machine_regs
.line
+= adv
;
5528 is_special_opcode
= 1;
5529 /* Increment view after printing this row. */
5534 case DW_LNS_extended_op
:
5536 unsigned int ext_op_code_len
;
5537 unsigned char ext_op_code
;
5538 unsigned char *op_code_end
;
5539 unsigned char *op_code_data
= data
;
5541 READ_ULEB (ext_op_code_len
, op_code_data
, end_of_sequence
);
5542 op_code_end
= op_code_data
+ ext_op_code_len
;
5543 if (ext_op_code_len
== 0 || op_code_end
> end_of_sequence
)
5545 warn (_("Badly formed extended line op encountered!\n"));
5548 ext_op_code
= *op_code_data
++;
5552 switch (ext_op_code
)
5554 case DW_LNE_end_sequence
:
5555 /* Reset stuff after printing this row. */
5557 case DW_LNE_set_address
:
5558 SAFE_BYTE_GET_AND_INC (state_machine_regs
.address
,
5560 op_code_end
- op_code_data
,
5562 state_machine_regs
.op_index
= 0;
5563 state_machine_regs
.view
= 0;
5565 case DW_LNE_define_file
:
5566 file_table
= (File_Entry
*) xrealloc
5567 (file_table
, (n_files
+ 1) * sizeof (File_Entry
));
5569 ++state_machine_regs
.last_file_entry
;
5570 /* Source file name. */
5571 file_table
[n_files
].name
= (char *) op_code_data
;
5572 op_code_data
+= strlen ((char *) op_code_data
) + 1;
5573 /* Directory index. */
5574 READ_ULEB (file_table
[n_files
].directory_index
,
5575 op_code_data
, op_code_end
);
5576 /* Last modification time. */
5577 READ_ULEB (file_table
[n_files
].modification_date
,
5578 op_code_data
, op_code_end
);
5580 READ_ULEB (file_table
[n_files
].length
,
5581 op_code_data
, op_code_end
);
5585 case DW_LNE_set_discriminator
:
5586 case DW_LNE_HP_set_sequence
:
5587 /* Simply ignored. */
5591 printf (_("UNKNOWN (%u): length %ld\n"),
5592 ext_op_code
, (long int) (op_code_data
- data
));
5599 /* Increment view after printing this row. */
5602 case DW_LNS_advance_pc
:
5603 READ_ULEB (uladv
, data
, end
);
5604 if (linfo
.li_max_ops_per_insn
== 1)
5606 uladv
*= linfo
.li_min_insn_length
;
5607 state_machine_regs
.address
+= uladv
;
5609 state_machine_regs
.view
= 0;
5614 = ((state_machine_regs
.op_index
+ uladv
)
5615 / linfo
.li_max_ops_per_insn
)
5616 * linfo
.li_min_insn_length
;
5617 state_machine_regs
.address
5619 state_machine_regs
.op_index
5620 = (state_machine_regs
.op_index
+ uladv
)
5621 % linfo
.li_max_ops_per_insn
;
5623 state_machine_regs
.view
= 0;
5627 case DW_LNS_advance_line
:
5628 READ_SLEB (adv
, data
, end
);
5629 state_machine_regs
.line
+= adv
;
5632 case DW_LNS_set_file
:
5633 READ_ULEB (uladv
, data
, end
);
5634 state_machine_regs
.file
= uladv
;
5636 unsigned file
= state_machine_regs
.file
;
5637 if (linfo
.li_version
< 5)
5640 if (file_table
== NULL
|| n_files
== 0)
5641 printf (_("\n [Use file table entry %d]\n"), file
);
5643 else if (file
>= n_files
)
5645 warn (_("file index %u >= number of files %u\n"),
5647 printf (_("\n <over large file table index %u>"), file
);
5651 unsigned dir
= file_table
[file
].directory_index
;
5652 if (dir
== 0 && linfo
.li_version
< 5)
5653 /* If directory index is 0, that means compilation
5654 current directory. bfd/dwarf2.c shows
5655 DW_AT_comp_dir here but in keeping with the
5656 readelf practice of minimal interpretation of
5657 file data, we show "./". */
5658 printf ("\n./%s:[++]\n",
5659 null_name (file_table
[file
].name
));
5660 else if (directory_table
== NULL
|| n_directories
== 0)
5661 printf (_("\n [Use file %s "
5662 "in directory table entry %d]\n"),
5663 null_name (file_table
[file
].name
), dir
);
5666 if (linfo
.li_version
< 5)
5669 if (dir
>= n_directories
)
5671 warn (_("directory index %u "
5672 ">= number of directories %u\n"),
5673 dir
, n_directories
);
5674 printf (_("\n <over large directory table entry "
5678 printf ("\n%s/%s:\n",
5679 null_name (directory_table
[dir
]),
5680 null_name (file_table
[file
].name
));
5685 case DW_LNS_set_column
:
5686 READ_ULEB (uladv
, data
, end
);
5687 state_machine_regs
.column
= uladv
;
5690 case DW_LNS_negate_stmt
:
5691 adv
= state_machine_regs
.is_stmt
;
5693 state_machine_regs
.is_stmt
= adv
;
5696 case DW_LNS_set_basic_block
:
5697 state_machine_regs
.basic_block
= 1;
5700 case DW_LNS_const_add_pc
:
5701 uladv
= ((255 - linfo
.li_opcode_base
) / linfo
.li_line_range
);
5702 if (linfo
.li_max_ops_per_insn
== 1)
5704 uladv
*= linfo
.li_min_insn_length
;
5705 state_machine_regs
.address
+= uladv
;
5707 state_machine_regs
.view
= 0;
5712 = ((state_machine_regs
.op_index
+ uladv
)
5713 / linfo
.li_max_ops_per_insn
)
5714 * linfo
.li_min_insn_length
;
5715 state_machine_regs
.address
5717 state_machine_regs
.op_index
5718 = (state_machine_regs
.op_index
+ uladv
)
5719 % linfo
.li_max_ops_per_insn
;
5721 state_machine_regs
.view
= 0;
5725 case DW_LNS_fixed_advance_pc
:
5726 SAFE_BYTE_GET_AND_INC (uladv
, data
, 2, end
);
5727 state_machine_regs
.address
+= uladv
;
5728 state_machine_regs
.op_index
= 0;
5729 /* Do NOT reset view. */
5732 case DW_LNS_set_prologue_end
:
5735 case DW_LNS_set_epilogue_begin
:
5738 case DW_LNS_set_isa
:
5739 READ_ULEB (uladv
, data
, end
);
5740 printf (_(" Set ISA to %lu\n"), uladv
);
5744 printf (_(" Unknown opcode %d with operands: "), op_code
);
5746 if (standard_opcodes
!= NULL
)
5747 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
5751 READ_ULEB (val
, data
, end
);
5752 printf ("%#" PRIx64
"%s", val
, i
== 1 ? "" : ", ");
5758 /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row
5759 to the DWARF address/line matrix. */
5760 if ((is_special_opcode
) || (xop
== -DW_LNE_end_sequence
)
5761 || (xop
== DW_LNS_copy
))
5763 const unsigned int MAX_FILENAME_LENGTH
= 35;
5764 char *fileName
= NULL
;
5765 char *newFileName
= NULL
;
5766 size_t fileNameLength
;
5770 unsigned indx
= state_machine_regs
.file
;
5772 if (linfo
.li_version
< 5)
5775 if (indx
>= n_files
)
5777 warn (_("file index %u >= number of files %u\n"),
5779 fileName
= _("<corrupt>");
5782 fileName
= (char *) file_table
[indx
].name
;
5785 fileName
= _("<unknown>");
5787 fileNameLength
= strlen (fileName
);
5788 newFileName
= fileName
;
5789 if (fileNameLength
> MAX_FILENAME_LENGTH
&& !do_wide
)
5791 newFileName
= (char *) xmalloc (MAX_FILENAME_LENGTH
+ 1);
5792 /* Truncate file name */
5793 memcpy (newFileName
,
5794 fileName
+ fileNameLength
- MAX_FILENAME_LENGTH
,
5795 MAX_FILENAME_LENGTH
);
5796 newFileName
[MAX_FILENAME_LENGTH
] = 0;
5799 /* A row with end_seq set to true has a meaningful address, but
5800 the other information in the same row is not significant.
5801 In such a row, print line as "-", and don't print
5803 if (!do_wide
|| fileNameLength
<= MAX_FILENAME_LENGTH
)
5805 if (linfo
.li_max_ops_per_insn
== 1)
5807 if (xop
== -DW_LNE_end_sequence
)
5808 printf ("%-31s %11s %#18" PRIx64
,
5810 state_machine_regs
.address
);
5812 printf ("%-31s %11d %#18" PRIx64
,
5813 newFileName
, state_machine_regs
.line
,
5814 state_machine_regs
.address
);
5818 if (xop
== -DW_LNE_end_sequence
)
5819 printf ("%-31s %11s %#18" PRIx64
"[%d]",
5821 state_machine_regs
.address
,
5822 state_machine_regs
.op_index
);
5824 printf ("%-31s %11d %#18" PRIx64
"[%d]",
5825 newFileName
, state_machine_regs
.line
,
5826 state_machine_regs
.address
,
5827 state_machine_regs
.op_index
);
5832 if (linfo
.li_max_ops_per_insn
== 1)
5834 if (xop
== -DW_LNE_end_sequence
)
5835 printf ("%s %11s %#18" PRIx64
,
5837 state_machine_regs
.address
);
5839 printf ("%s %11d %#18" PRIx64
,
5840 newFileName
, state_machine_regs
.line
,
5841 state_machine_regs
.address
);
5845 if (xop
== -DW_LNE_end_sequence
)
5846 printf ("%s %11s %#18" PRIx64
"[%d]",
5848 state_machine_regs
.address
,
5849 state_machine_regs
.op_index
);
5851 printf ("%s %11d %#18" PRIx64
"[%d]",
5852 newFileName
, state_machine_regs
.line
,
5853 state_machine_regs
.address
,
5854 state_machine_regs
.op_index
);
5858 if (xop
!= -DW_LNE_end_sequence
)
5860 if (state_machine_regs
.view
)
5861 printf (" %6u", state_machine_regs
.view
);
5865 if (state_machine_regs
.is_stmt
)
5870 state_machine_regs
.view
++;
5872 if (xop
== -DW_LNE_end_sequence
)
5874 reset_state_machine (linfo
.li_default_is_stmt
);
5878 if (newFileName
!= fileName
)
5890 if (directory_table
)
5892 free (directory_table
);
5893 directory_table
= NULL
;
5904 display_debug_lines (struct dwarf_section
*section
, void *file
)
5906 unsigned char *data
= section
->start
;
5907 unsigned char *end
= data
+ section
->size
;
5909 int retValDecoded
= 1;
5911 if (do_debug_lines
== 0)
5912 do_debug_lines
|= FLAG_DEBUG_LINES_RAW
;
5914 if (do_debug_lines
& FLAG_DEBUG_LINES_RAW
)
5915 retValRaw
= display_debug_lines_raw (section
, data
, end
, file
);
5917 if (do_debug_lines
& FLAG_DEBUG_LINES_DECODED
)
5918 retValDecoded
= display_debug_lines_decoded (section
, data
, data
, end
, file
);
5920 if (!retValRaw
|| !retValDecoded
)
5927 find_debug_info_for_offset (uint64_t offset
)
5931 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
5934 for (i
= 0; i
< num_debug_info_entries
; i
++)
5935 if (debug_information
[i
].cu_offset
== offset
)
5936 return debug_information
+ i
;
5942 get_gdb_index_symbol_kind_name (gdb_index_symbol_kind kind
)
5944 /* See gdb/gdb-index.h. */
5945 static const char * const kinds
[] =
5957 return _ (kinds
[kind
]);
5961 display_debug_pubnames_worker (struct dwarf_section
*section
,
5962 void *file ATTRIBUTE_UNUSED
,
5965 DWARF2_Internal_PubNames names
;
5966 unsigned char *start
= section
->start
;
5967 unsigned char *end
= start
+ section
->size
;
5969 /* It does not matter if this load fails,
5970 we test for that later on. */
5971 load_debug_info (file
);
5973 introduce (section
, false);
5977 unsigned char *data
;
5978 unsigned long sec_off
= start
- section
->start
;
5979 unsigned int offset_size
;
5981 SAFE_BYTE_GET_AND_INC (names
.pn_length
, start
, 4, end
);
5982 if (names
.pn_length
== 0xffffffff)
5984 SAFE_BYTE_GET_AND_INC (names
.pn_length
, start
, 8, end
);
5990 if (names
.pn_length
> (size_t) (end
- start
))
5992 warn (_("Debug info is corrupted, "
5993 "%s header at %#lx has length %#" PRIx64
"\n"),
5994 section
->name
, sec_off
, names
.pn_length
);
5999 start
+= names
.pn_length
;
6001 SAFE_BYTE_GET_AND_INC (names
.pn_version
, data
, 2, start
);
6002 SAFE_BYTE_GET_AND_INC (names
.pn_offset
, data
, offset_size
, start
);
6004 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
6005 && num_debug_info_entries
> 0
6006 && find_debug_info_for_offset (names
.pn_offset
) == NULL
)
6007 warn (_(".debug_info offset of %#" PRIx64
6008 " in %s section does not point to a CU header.\n"),
6009 names
.pn_offset
, section
->name
);
6011 SAFE_BYTE_GET_AND_INC (names
.pn_size
, data
, offset_size
, start
);
6013 printf (_(" Length: %" PRId64
"\n"),
6015 printf (_(" Version: %d\n"),
6017 printf (_(" Offset into .debug_info section: %#" PRIx64
"\n"),
6019 printf (_(" Size of area in .debug_info section: %" PRId64
"\n"),
6022 if (names
.pn_version
!= 2 && names
.pn_version
!= 3)
6024 static int warned
= 0;
6028 warn (_("Only DWARF 2 and 3 pubnames are currently supported\n"));
6036 printf (_("\n Offset Kind Name\n"));
6038 printf (_("\n Offset\tName\n"));
6045 SAFE_BYTE_GET_AND_INC (offset
, data
, offset_size
, start
);
6052 maxprint
= (start
- data
) - 1;
6056 unsigned int kind_data
;
6057 gdb_index_symbol_kind kind
;
6058 const char *kind_name
;
6061 SAFE_BYTE_GET_AND_INC (kind_data
, data
, 1, start
);
6063 /* GCC computes the kind as the upper byte in the CU index
6064 word, and then right shifts it by the CU index size.
6065 Left shift KIND to where the gdb-index.h accessor macros
6067 kind_data
<<= GDB_INDEX_CU_BITSIZE
;
6068 kind
= GDB_INDEX_SYMBOL_KIND_VALUE (kind_data
);
6069 kind_name
= get_gdb_index_symbol_kind_name (kind
);
6070 is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (kind_data
);
6071 printf (" %-6" PRIx64
" %s,%-10s %.*s\n",
6072 offset
, is_static
? _("s") : _("g"),
6073 kind_name
, (int) maxprint
, data
);
6076 printf (" %-6" PRIx64
"\t%.*s\n",
6077 offset
, (int) maxprint
, data
);
6079 data
+= strnlen ((char *) data
, maxprint
);
6092 display_debug_pubnames (struct dwarf_section
*section
, void *file
)
6094 return display_debug_pubnames_worker (section
, file
, 0);
6098 display_debug_gnu_pubnames (struct dwarf_section
*section
, void *file
)
6100 return display_debug_pubnames_worker (section
, file
, 1);
6104 display_debug_macinfo (struct dwarf_section
*section
,
6105 void *file ATTRIBUTE_UNUSED
)
6107 unsigned char *start
= section
->start
;
6108 unsigned char *end
= start
+ section
->size
;
6109 unsigned char *curr
= start
;
6110 enum dwarf_macinfo_record_type op
;
6112 introduce (section
, false);
6116 unsigned int lineno
;
6117 const unsigned char *string
;
6119 op
= (enum dwarf_macinfo_record_type
) *curr
;
6124 case DW_MACINFO_start_file
:
6126 unsigned int filenum
;
6128 READ_ULEB (lineno
, curr
, end
);
6129 READ_ULEB (filenum
, curr
, end
);
6130 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"),
6135 case DW_MACINFO_end_file
:
6136 printf (_(" DW_MACINFO_end_file\n"));
6139 case DW_MACINFO_define
:
6140 READ_ULEB (lineno
, curr
, end
);
6142 curr
+= strnlen ((char *) string
, end
- string
);
6143 printf (_(" DW_MACINFO_define - lineno : %d macro : %*s\n"),
6144 lineno
, (int) (curr
- string
), string
);
6149 case DW_MACINFO_undef
:
6150 READ_ULEB (lineno
, curr
, end
);
6152 curr
+= strnlen ((char *) string
, end
- string
);
6153 printf (_(" DW_MACINFO_undef - lineno : %d macro : %*s\n"),
6154 lineno
, (int) (curr
- string
), string
);
6159 case DW_MACINFO_vendor_ext
:
6161 unsigned int constant
;
6163 READ_ULEB (constant
, curr
, end
);
6165 curr
+= strnlen ((char *) string
, end
- string
);
6166 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %*s\n"),
6167 constant
, (int) (curr
- string
), string
);
6178 /* Given LINE_OFFSET into the .debug_line section, attempt to return
6179 filename and dirname corresponding to file name table entry with index
6180 FILEIDX. Return NULL on failure. */
6182 static unsigned char *
6183 get_line_filename_and_dirname (uint64_t line_offset
,
6185 unsigned char **dir_name
)
6187 struct dwarf_section
*section
= &debug_displays
[line
].section
;
6188 unsigned char *hdrptr
, *dirtable
, *file_name
;
6189 unsigned int offset_size
;
6190 unsigned int version
, opcode_base
;
6191 uint64_t length
, diridx
;
6192 const unsigned char * end
;
6195 if (section
->start
== NULL
6196 || line_offset
>= section
->size
6200 hdrptr
= section
->start
+ line_offset
;
6201 end
= section
->start
+ section
->size
;
6203 SAFE_BYTE_GET_AND_INC (length
, hdrptr
, 4, end
);
6204 if (length
== 0xffffffff)
6206 /* This section is 64-bit DWARF 3. */
6207 SAFE_BYTE_GET_AND_INC (length
, hdrptr
, 8, end
);
6213 if (length
> (size_t) (end
- hdrptr
)
6214 || length
< 2 + offset_size
+ 1 + 3 + 1)
6216 end
= hdrptr
+ length
;
6218 SAFE_BYTE_GET_AND_INC (version
, hdrptr
, 2, end
);
6219 if (version
!= 2 && version
!= 3 && version
!= 4)
6221 hdrptr
+= offset_size
+ 1;/* Skip prologue_length and min_insn_length. */
6223 hdrptr
++; /* Skip max_ops_per_insn. */
6224 hdrptr
+= 3; /* Skip default_is_stmt, line_base, line_range. */
6226 SAFE_BYTE_GET_AND_INC (opcode_base
, hdrptr
, 1, end
);
6227 if (opcode_base
== 0
6228 || opcode_base
- 1 >= (size_t) (end
- hdrptr
))
6231 hdrptr
+= opcode_base
- 1;
6234 /* Skip over dirname table. */
6235 while (*hdrptr
!= '\0')
6237 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
);
6243 hdrptr
++; /* Skip the NUL at the end of the table. */
6245 /* Now skip over preceding filename table entries. */
6246 for (; hdrptr
< end
&& *hdrptr
!= '\0' && fileidx
> 1; fileidx
--)
6248 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
);
6251 SKIP_ULEB (hdrptr
, end
);
6252 SKIP_ULEB (hdrptr
, end
);
6253 SKIP_ULEB (hdrptr
, end
);
6255 if (hdrptr
>= end
|| *hdrptr
== '\0')
6259 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
);
6264 READ_ULEB (diridx
, hdrptr
, end
);
6267 for (; dirtable
< end
&& *dirtable
!= '\0' && diridx
> 1; diridx
--)
6269 dirtable
+= strnlen ((char *) dirtable
, end
- dirtable
);
6273 if (dirtable
>= end
|| *dirtable
== '\0')
6275 *dir_name
= dirtable
;
6280 display_debug_macro (struct dwarf_section
*section
,
6283 unsigned char *start
= section
->start
;
6284 unsigned char *end
= start
+ section
->size
;
6285 unsigned char *curr
= start
;
6286 unsigned char *extended_op_buf
[256];
6287 bool is_dwo
= false;
6288 const char *suffix
= strrchr (section
->name
, '.');
6290 if (suffix
&& strcmp (suffix
, ".dwo") == 0)
6293 load_debug_section_with_follow (str
, file
);
6294 load_debug_section_with_follow (line
, file
);
6295 load_debug_section_with_follow (str_index
, file
);
6297 introduce (section
, false);
6301 unsigned int lineno
, version
, flags
;
6302 unsigned int offset_size
;
6303 const unsigned char *string
;
6304 uint64_t line_offset
= 0, sec_offset
= curr
- start
, offset
;
6305 unsigned char **extended_ops
= NULL
;
6307 SAFE_BYTE_GET_AND_INC (version
, curr
, 2, end
);
6308 if (version
!= 4 && version
!= 5)
6310 error (_("Expected to find a version number of 4 or 5 in section %s but found %d instead\n"),
6311 section
->name
, version
);
6315 SAFE_BYTE_GET_AND_INC (flags
, curr
, 1, end
);
6316 offset_size
= (flags
& 1) ? 8 : 4;
6317 printf (_(" Offset: %#" PRIx64
"\n"), sec_offset
);
6318 printf (_(" Version: %d\n"), version
);
6319 printf (_(" Offset size: %d\n"), offset_size
);
6322 SAFE_BYTE_GET_AND_INC (line_offset
, curr
, offset_size
, end
);
6323 printf (_(" Offset into .debug_line: %#" PRIx64
"\n"),
6328 unsigned int i
, count
, op
;
6331 SAFE_BYTE_GET_AND_INC (count
, curr
, 1, end
);
6333 memset (extended_op_buf
, 0, sizeof (extended_op_buf
));
6334 extended_ops
= extended_op_buf
;
6337 printf (_(" Extension opcode arguments:\n"));
6338 for (i
= 0; i
< count
; i
++)
6340 SAFE_BYTE_GET_AND_INC (op
, curr
, 1, end
);
6341 extended_ops
[op
] = curr
;
6342 READ_ULEB (nargs
, curr
, end
);
6344 printf (_(" DW_MACRO_%02x has no arguments\n"), op
);
6347 printf (_(" DW_MACRO_%02x arguments: "), op
);
6348 for (n
= 0; n
< nargs
; n
++)
6352 SAFE_BYTE_GET_AND_INC (form
, curr
, 1, end
);
6353 printf ("%s%s", get_FORM_name (form
),
6354 n
== nargs
- 1 ? "\n" : ", ");
6364 case DW_FORM_block1
:
6365 case DW_FORM_block2
:
6366 case DW_FORM_block4
:
6368 case DW_FORM_string
:
6370 case DW_FORM_sec_offset
:
6373 error (_("Invalid extension opcode form %s\n"),
6374 get_FORM_name (form
));
6390 error (_(".debug_macro section not zero terminated\n"));
6394 SAFE_BYTE_GET_AND_INC (op
, curr
, 1, end
);
6400 case DW_MACRO_define
:
6401 READ_ULEB (lineno
, curr
, end
);
6403 curr
+= strnlen ((char *) string
, end
- string
);
6404 printf (_(" DW_MACRO_define - lineno : %d macro : %*s\n"),
6405 lineno
, (int) (curr
- string
), string
);
6410 case DW_MACRO_undef
:
6411 READ_ULEB (lineno
, curr
, end
);
6413 curr
+= strnlen ((char *) string
, end
- string
);
6414 printf (_(" DW_MACRO_undef - lineno : %d macro : %*s\n"),
6415 lineno
, (int) (curr
- string
), string
);
6420 case DW_MACRO_start_file
:
6422 unsigned int filenum
;
6423 unsigned char *file_name
= NULL
, *dir_name
= NULL
;
6425 READ_ULEB (lineno
, curr
, end
);
6426 READ_ULEB (filenum
, curr
, end
);
6428 if ((flags
& 2) == 0)
6429 error (_("DW_MACRO_start_file used, but no .debug_line offset provided.\n"));
6432 = get_line_filename_and_dirname (line_offset
, filenum
,
6434 if (file_name
== NULL
)
6435 printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d\n"),
6438 printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d filename: %s%s%s\n"),
6440 dir_name
!= NULL
? (const char *) dir_name
: "",
6441 dir_name
!= NULL
? "/" : "", file_name
);
6445 case DW_MACRO_end_file
:
6446 printf (_(" DW_MACRO_end_file\n"));
6449 case DW_MACRO_define_strp
:
6450 READ_ULEB (lineno
, curr
, end
);
6451 if (version
== 4 && is_dwo
)
6452 READ_ULEB (offset
, curr
, end
);
6454 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6455 string
= fetch_indirect_string (offset
);
6456 printf (_(" DW_MACRO_define_strp - lineno : %d macro : %s\n"),
6460 case DW_MACRO_undef_strp
:
6461 READ_ULEB (lineno
, curr
, end
);
6462 if (version
== 4 && is_dwo
)
6463 READ_ULEB (offset
, curr
, end
);
6465 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6466 string
= fetch_indirect_string (offset
);
6467 printf (_(" DW_MACRO_undef_strp - lineno : %d macro : %s\n"),
6471 case DW_MACRO_import
:
6472 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6473 printf (_(" DW_MACRO_import - offset : %#" PRIx64
"\n"),
6477 case DW_MACRO_define_sup
:
6478 READ_ULEB (lineno
, curr
, end
);
6479 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6480 printf (_(" DW_MACRO_define_sup - lineno : %d"
6481 " macro offset : %#" PRIx64
"\n"),
6485 case DW_MACRO_undef_sup
:
6486 READ_ULEB (lineno
, curr
, end
);
6487 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6488 printf (_(" DW_MACRO_undef_sup - lineno : %d"
6489 " macro offset : %#" PRIx64
"\n"),
6493 case DW_MACRO_import_sup
:
6494 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6495 printf (_(" DW_MACRO_import_sup - offset : %#" PRIx64
"\n"),
6499 case DW_MACRO_define_strx
:
6500 case DW_MACRO_undef_strx
:
6501 READ_ULEB (lineno
, curr
, end
);
6502 READ_ULEB (offset
, curr
, end
);
6503 string
= (const unsigned char *)
6504 fetch_indexed_string (offset
, NULL
, offset_size
, false, 0);
6505 if (op
== DW_MACRO_define_strx
)
6506 printf (" DW_MACRO_define_strx ");
6508 printf (" DW_MACRO_undef_strx ");
6510 printf (_("(with offset %#" PRIx64
") "), offset
);
6511 printf (_("lineno : %d macro : %s\n"),
6516 if (op
>= DW_MACRO_lo_user
&& op
<= DW_MACRO_hi_user
)
6518 printf (_(" <Target Specific macro op: %#x - UNHANDLED"), op
);
6522 if (extended_ops
== NULL
|| extended_ops
[op
] == NULL
)
6524 error (_(" Unknown macro opcode %02x seen\n"), op
);
6529 /* Skip over unhandled opcodes. */
6531 unsigned char *desc
= extended_ops
[op
];
6532 READ_ULEB (nargs
, desc
, end
);
6535 printf (_(" DW_MACRO_%02x\n"), op
);
6538 printf (_(" DW_MACRO_%02x -"), op
);
6539 for (n
= 0; n
< nargs
; n
++)
6543 /* DW_FORM_implicit_const is not expected here. */
6544 SAFE_BYTE_GET_AND_INC (val
, desc
, 1, end
);
6546 = read_and_display_attr_value (0, val
, 0,
6547 start
, curr
, end
, 0, 0,
6548 offset_size
, version
,
6567 display_debug_abbrev (struct dwarf_section
*section
,
6568 void *file ATTRIBUTE_UNUSED
)
6570 abbrev_entry
*entry
;
6571 unsigned char *start
= section
->start
;
6573 introduce (section
, false);
6577 uint64_t offset
= start
- section
->start
;
6578 abbrev_list
*list
= find_and_process_abbrev_set (section
, 0,
6579 section
->size
, offset
,
6584 if (list
->first_abbrev
)
6585 printf (_(" Number TAG (%#" PRIx64
")\n"), offset
);
6587 for (entry
= list
->first_abbrev
; entry
; entry
= entry
->next
)
6591 printf (" %ld %s [%s]\n",
6593 get_TAG_name (entry
->tag
),
6594 entry
->children
? _("has children") : _("no children"));
6596 for (attr
= entry
->first_attr
; attr
; attr
= attr
->next
)
6598 printf (" %-18s %s",
6599 get_AT_name (attr
->attribute
),
6600 get_FORM_name (attr
->form
));
6601 if (attr
->form
== DW_FORM_implicit_const
)
6602 printf (": %" PRId64
, attr
->implicit_const
);
6606 start
= list
->start_of_next_abbrevs
;
6607 free_abbrev_list (list
);
6616 /* Return true when ADDR is the maximum address, when addresses are
6617 POINTER_SIZE bytes long. */
6620 is_max_address (uint64_t addr
, unsigned int pointer_size
)
6622 uint64_t mask
= ~(~(uint64_t) 0 << 1 << (pointer_size
* 8 - 1));
6623 return ((addr
& mask
) == mask
);
6626 /* Display a view pair list starting at *VSTART_PTR and ending at
6627 VLISTEND within SECTION. */
6630 display_view_pair_list (struct dwarf_section
*section
,
6631 unsigned char **vstart_ptr
,
6632 unsigned int debug_info_entry
,
6633 unsigned char *vlistend
)
6635 unsigned char *vstart
= *vstart_ptr
;
6636 unsigned char *section_end
= section
->start
+ section
->size
;
6637 unsigned int pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
6639 if (vlistend
< section_end
)
6640 section_end
= vlistend
;
6644 while (vstart
< section_end
)
6646 uint64_t off
= vstart
- section
->start
;
6647 uint64_t vbegin
, vend
;
6649 READ_ULEB (vbegin
, vstart
, section_end
);
6650 if (vstart
== section_end
)
6653 READ_ULEB (vend
, vstart
, section_end
);
6654 printf (" %8.8" PRIx64
" ", off
);
6656 print_view (vbegin
, pointer_size
);
6657 print_view (vend
, pointer_size
);
6658 printf (_("location view pair\n"));
6662 *vstart_ptr
= vstart
;
6665 /* Display a location list from a normal (ie, non-dwo) .debug_loc section. */
6668 display_loc_list (struct dwarf_section
*section
,
6669 unsigned char **start_ptr
,
6670 unsigned int debug_info_entry
,
6672 uint64_t base_address
,
6673 unsigned char **vstart_ptr
,
6676 unsigned char *start
= *start_ptr
, *vstart
= *vstart_ptr
;
6677 unsigned char *section_end
= section
->start
+ section
->size
;
6679 unsigned int pointer_size
;
6680 unsigned int offset_size
;
6684 unsigned short length
;
6685 int need_frame_base
;
6687 if (debug_info_entry
>= num_debug_info_entries
)
6689 warn (_("No debug information available for loc lists of entry: %u\n"),
6694 cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
6695 pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
6696 offset_size
= debug_information
[debug_info_entry
].offset_size
;
6697 dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
6699 if (pointer_size
< 2 || pointer_size
> 8)
6701 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
6702 pointer_size
, debug_info_entry
);
6708 uint64_t off
= offset
+ (start
- *start_ptr
);
6709 uint64_t vbegin
= -1, vend
= -1;
6711 if (2 * pointer_size
> (size_t) (section_end
- start
))
6713 warn (_("Location list starting at offset %#" PRIx64
6714 " is not terminated.\n"), offset
);
6721 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, section_end
);
6722 SAFE_BYTE_GET_AND_INC (end
, start
, pointer_size
, section_end
);
6724 if (begin
== 0 && end
== 0)
6726 /* PR 18374: In a object file we can have a location list that
6727 starts with a begin and end of 0 because there are relocations
6728 that need to be applied to the addresses. Actually applying
6729 the relocations now does not help as they will probably resolve
6730 to 0, since the object file has not been fully linked. Real
6731 end of list markers will not have any relocations against them. */
6732 if (! reloc_at (section
, off
)
6733 && ! reloc_at (section
, off
+ pointer_size
))
6735 printf (_("<End of list>\n"));
6740 /* Check base address specifiers. */
6741 if (is_max_address (begin
, pointer_size
)
6742 && !is_max_address (end
, pointer_size
))
6745 print_hex (begin
, pointer_size
);
6746 print_hex (end
, pointer_size
);
6747 printf (_("(base address)\n"));
6753 off
= offset
+ (vstart
- *start_ptr
);
6755 READ_ULEB (vbegin
, vstart
, section_end
);
6756 print_view (vbegin
, pointer_size
);
6758 READ_ULEB (vend
, vstart
, section_end
);
6759 print_view (vend
, pointer_size
);
6761 printf (_("views at %8.8" PRIx64
" for:\n %*s "), off
, 8, "");
6764 if (2 > (size_t) (section_end
- start
))
6766 warn (_("Location list starting at offset %#" PRIx64
6767 " is not terminated.\n"), offset
);
6771 SAFE_BYTE_GET_AND_INC (length
, start
, 2, section_end
);
6773 if (length
> (size_t) (section_end
- start
))
6775 warn (_("Location list starting at offset %#" PRIx64
6776 " is not terminated.\n"), offset
);
6780 print_hex (begin
+ base_address
, pointer_size
);
6781 print_hex (end
+ base_address
, pointer_size
);
6784 need_frame_base
= decode_location_expression (start
,
6789 cu_offset
, section
);
6792 if (need_frame_base
&& !has_frame_base
)
6793 printf (_(" [without DW_AT_frame_base]"));
6795 if (begin
== end
&& vbegin
== vend
)
6796 fputs (_(" (start == end)"), stdout
);
6797 else if (begin
> end
|| (begin
== end
&& vbegin
> vend
))
6798 fputs (_(" (start > end)"), stdout
);
6806 *vstart_ptr
= vstart
;
6809 /* Display a location list from a normal (ie, non-dwo) .debug_loclists section. */
6812 display_loclists_list (struct dwarf_section
* section
,
6813 unsigned char ** start_ptr
,
6814 unsigned int debug_info_entry
,
6816 uint64_t base_address
,
6817 unsigned char ** vstart_ptr
,
6820 unsigned char *start
= *start_ptr
;
6821 unsigned char *vstart
= *vstart_ptr
;
6822 unsigned char *section_end
= section
->start
+ section
->size
;
6824 unsigned int pointer_size
;
6825 unsigned int offset_size
;
6826 unsigned int dwarf_version
;
6828 /* Initialize it due to a false compiler warning. */
6829 uint64_t begin
= -1, vbegin
= -1;
6830 uint64_t end
= -1, vend
= -1;
6832 int need_frame_base
;
6834 if (debug_info_entry
>= num_debug_info_entries
)
6836 warn (_("No debug information available for "
6837 "loclists lists of entry: %u\n"),
6842 cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
6843 pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
6844 offset_size
= debug_information
[debug_info_entry
].offset_size
;
6845 dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
6847 if (pointer_size
< 2 || pointer_size
> 8)
6849 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
6850 pointer_size
, debug_info_entry
);
6856 uint64_t off
= offset
+ (start
- *start_ptr
);
6857 enum dwarf_location_list_entry_type llet
;
6859 if (start
+ 1 > section_end
)
6861 warn (_("Location list starting at offset %#" PRIx64
6862 " is not terminated.\n"), offset
);
6869 SAFE_BYTE_GET_AND_INC (llet
, start
, 1, section_end
);
6871 if (vstart
&& (llet
== DW_LLE_offset_pair
6872 || llet
== DW_LLE_start_end
6873 || llet
== DW_LLE_start_length
))
6875 off
= offset
+ (vstart
- *start_ptr
);
6877 READ_ULEB (vbegin
, vstart
, section_end
);
6878 print_view (vbegin
, pointer_size
);
6880 READ_ULEB (vend
, vstart
, section_end
);
6881 print_view (vend
, pointer_size
);
6883 printf (_("views at %8.8" PRIx64
" for:\n %*s "), off
, 8, "");
6888 case DW_LLE_end_of_list
:
6889 printf (_("<End of list>\n"));
6892 case DW_LLE_base_addressx
:
6893 READ_ULEB (base_address
, start
, section_end
);
6894 print_hex (base_address
, pointer_size
);
6895 printf (_("(index into .debug_addr) "));
6896 base_address
= fetch_indexed_addr (base_address
, pointer_size
);
6897 print_hex (base_address
, pointer_size
);
6898 printf (_("(base address)\n"));
6901 case DW_LLE_startx_endx
:
6902 READ_ULEB (begin
, start
, section_end
);
6903 begin
= fetch_indexed_addr (begin
, pointer_size
);
6904 READ_ULEB (end
, start
, section_end
);
6905 end
= fetch_indexed_addr (end
, pointer_size
);
6908 case DW_LLE_startx_length
:
6909 READ_ULEB (begin
, start
, section_end
);
6910 begin
= fetch_indexed_addr (begin
, pointer_size
);
6911 READ_ULEB (end
, start
, section_end
);
6915 case DW_LLE_default_location
:
6919 case DW_LLE_offset_pair
:
6920 READ_ULEB (begin
, start
, section_end
);
6921 begin
+= base_address
;
6922 READ_ULEB (end
, start
, section_end
);
6923 end
+= base_address
;
6926 case DW_LLE_base_address
:
6927 SAFE_BYTE_GET_AND_INC (base_address
, start
, pointer_size
,
6929 print_hex (base_address
, pointer_size
);
6930 printf (_("(base address)\n"));
6933 case DW_LLE_start_end
:
6934 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, section_end
);
6935 SAFE_BYTE_GET_AND_INC (end
, start
, pointer_size
, section_end
);
6938 case DW_LLE_start_length
:
6939 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, section_end
);
6940 READ_ULEB (end
, start
, section_end
);
6944 #ifdef DW_LLE_view_pair
6945 case DW_LLE_view_pair
:
6947 printf (_("View pair entry in loclist with locviews attribute\n"));
6948 READ_ULEB (vbegin
, start
, section_end
);
6949 print_view (vbegin
, pointer_size
);
6951 READ_ULEB (vend
, start
, section_end
);
6952 print_view (vend
, pointer_size
);
6954 printf (_("views for:\n"));
6959 error (_("Invalid location list entry type %d\n"), llet
);
6963 if (llet
== DW_LLE_end_of_list
)
6966 if (llet
== DW_LLE_base_address
6967 || llet
== DW_LLE_base_addressx
)
6970 if (start
== section_end
)
6972 warn (_("Location list starting at offset %#" PRIx64
6973 " is not terminated.\n"), offset
);
6976 READ_ULEB (length
, start
, section_end
);
6978 if (length
> (size_t) (section_end
- start
))
6980 warn (_("Location list starting at offset %#" PRIx64
6981 " is not terminated.\n"), offset
);
6985 print_hex (begin
, pointer_size
);
6986 print_hex (end
, pointer_size
);
6989 need_frame_base
= decode_location_expression (start
,
6994 cu_offset
, section
);
6997 if (need_frame_base
&& !has_frame_base
)
6998 printf (_(" [without DW_AT_frame_base]"));
7000 if (begin
== end
&& vbegin
== vend
)
7001 fputs (_(" (start == end)"), stdout
);
7002 else if (begin
> end
|| (begin
== end
&& vbegin
> vend
))
7003 fputs (_(" (start > end)"), stdout
);
7011 if (vbegin
!= (uint64_t) -1 || vend
!= (uint64_t) -1)
7012 printf (_("Trailing view pair not used in a range"));
7015 *vstart_ptr
= vstart
;
7018 /* Print a .debug_addr table index in decimal, surrounded by square brackets,
7019 right-adjusted in a field of length LEN, and followed by a space. */
7022 print_addr_index (unsigned int idx
, unsigned int len
)
7024 static char buf
[15];
7025 snprintf (buf
, sizeof (buf
), "[%d]", idx
);
7026 printf ("%*s ", len
, buf
);
7029 /* Display a location list from a .dwo section. It uses address indexes rather
7030 than embedded addresses. This code closely follows display_loc_list, but the
7031 two are sufficiently different that combining things is very ugly. */
7034 display_loc_list_dwo (struct dwarf_section
*section
,
7035 unsigned char **start_ptr
,
7036 unsigned int debug_info_entry
,
7038 unsigned char **vstart_ptr
,
7041 unsigned char *start
= *start_ptr
, *vstart
= *vstart_ptr
;
7042 unsigned char *section_end
= section
->start
+ section
->size
;
7044 unsigned int pointer_size
;
7045 unsigned int offset_size
;
7048 unsigned short length
;
7049 int need_frame_base
;
7052 if (debug_info_entry
>= num_debug_info_entries
)
7054 warn (_("No debug information for loc lists of entry: %u\n"),
7059 cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
7060 pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
7061 offset_size
= debug_information
[debug_info_entry
].offset_size
;
7062 dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
7064 if (pointer_size
< 2 || pointer_size
> 8)
7066 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
7067 pointer_size
, debug_info_entry
);
7074 print_hex (offset
+ (start
- *start_ptr
), 4);
7076 if (start
>= section_end
)
7078 warn (_("Location list starting at offset %#" PRIx64
7079 " is not terminated.\n"), offset
);
7083 SAFE_BYTE_GET_AND_INC (entry_type
, start
, 1, section_end
);
7096 uint64_t off
= offset
+ (vstart
- *start_ptr
);
7098 READ_ULEB (view
, vstart
, section_end
);
7099 print_view (view
, 8);
7101 READ_ULEB (view
, vstart
, section_end
);
7102 print_view (view
, 8);
7104 printf (_("views at %8.8" PRIx64
" for:\n %*s "), off
, 8, "");
7112 case 0: /* A terminating entry. */
7114 *vstart_ptr
= vstart
;
7115 printf (_("<End of list>\n"));
7117 case 1: /* A base-address entry. */
7118 READ_ULEB (idx
, start
, section_end
);
7119 print_addr_index (idx
, 8);
7120 printf ("%*s", 9 + (vstart
? 2 * 6 : 0), "");
7121 printf (_("(base address selection entry)\n"));
7123 case 2: /* A start/end entry. */
7124 READ_ULEB (idx
, start
, section_end
);
7125 print_addr_index (idx
, 8);
7126 READ_ULEB (idx
, start
, section_end
);
7127 print_addr_index (idx
, 8);
7129 case 3: /* A start/length entry. */
7130 READ_ULEB (idx
, start
, section_end
);
7131 print_addr_index (idx
, 8);
7132 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
7133 printf ("%08x ", idx
);
7135 case 4: /* An offset pair entry. */
7136 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
7137 printf ("%08x ", idx
);
7138 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
7139 printf ("%08x ", idx
);
7142 warn (_("Unknown location list entry type 0x%x.\n"), entry_type
);
7144 *vstart_ptr
= vstart
;
7148 if (2 > (size_t) (section_end
- start
))
7150 warn (_("Location list starting at offset %#" PRIx64
7151 " is not terminated.\n"), offset
);
7155 SAFE_BYTE_GET_AND_INC (length
, start
, 2, section_end
);
7156 if (length
> (size_t) (section_end
- start
))
7158 warn (_("Location list starting at offset %#" PRIx64
7159 " is not terminated.\n"), offset
);
7164 need_frame_base
= decode_location_expression (start
,
7169 cu_offset
, section
);
7172 if (need_frame_base
&& !has_frame_base
)
7173 printf (_(" [without DW_AT_frame_base]"));
7181 *vstart_ptr
= vstart
;
7184 /* Sort array of indexes in ascending order of loc_offsets[idx] and
7187 static uint64_t *loc_offsets
, *loc_views
;
7190 loc_offsets_compar (const void *ap
, const void *bp
)
7192 uint64_t a
= loc_offsets
[*(const unsigned int *) ap
];
7193 uint64_t b
= loc_offsets
[*(const unsigned int *) bp
];
7195 int ret
= (a
> b
) - (b
> a
);
7199 a
= loc_views
[*(const unsigned int *) ap
];
7200 b
= loc_views
[*(const unsigned int *) bp
];
7202 ret
= (a
> b
) - (b
> a
);
7208 display_offset_entry_loclists (struct dwarf_section
*section
)
7210 unsigned char * start
= section
->start
;
7211 unsigned char * const end
= start
+ section
->size
;
7213 introduce (section
, false);
7218 unsigned short version
;
7219 unsigned char address_size
;
7220 unsigned char segment_selector_size
;
7221 uint32_t offset_entry_count
;
7225 printf (_("Table at Offset %#tx\n"), start
- section
->start
);
7227 SAFE_BYTE_GET_AND_INC (length
, start
, 4, end
);
7228 if (length
== 0xffffffff)
7231 SAFE_BYTE_GET_AND_INC (length
, start
, 8, end
);
7236 SAFE_BYTE_GET_AND_INC (version
, start
, 2, end
);
7237 SAFE_BYTE_GET_AND_INC (address_size
, start
, 1, end
);
7238 SAFE_BYTE_GET_AND_INC (segment_selector_size
, start
, 1, end
);
7239 SAFE_BYTE_GET_AND_INC (offset_entry_count
, start
, 4, end
);
7241 printf (_(" Length: %#" PRIx64
"\n"), length
);
7242 printf (_(" DWARF version: %u\n"), version
);
7243 printf (_(" Address size: %u\n"), address_size
);
7244 printf (_(" Segment size: %u\n"), segment_selector_size
);
7245 printf (_(" Offset entries: %u\n"), offset_entry_count
);
7249 warn (_("The %s section contains a corrupt or "
7250 "unsupported version number: %d.\n"),
7251 section
->name
, version
);
7255 if (segment_selector_size
!= 0)
7257 warn (_("The %s section contains an "
7258 "unsupported segment selector size: %d.\n"),
7259 section
->name
, segment_selector_size
);
7263 if (offset_entry_count
== 0)
7265 warn (_("The %s section contains a table without offset\n"),
7270 printf (_("\n Offset Entries starting at %#tx:\n"),
7271 start
- section
->start
);
7273 for (i
= 0; i
< offset_entry_count
; i
++)
7277 SAFE_BYTE_GET_AND_INC (entry
, start
, is_64bit
? 8 : 4, end
);
7278 printf (_(" [%6u] %#" PRIx64
"\n"), i
, entry
);
7285 for (j
= 1, i
= 0; i
< offset_entry_count
;)
7288 uint64_t base_address
= 0;
7291 uint64_t off
= start
- section
->start
;
7295 printf (_(" Offset Entry %u\n"), i
);
7302 SAFE_BYTE_GET_AND_INC (lle
, start
, 1, end
);
7306 case DW_LLE_end_of_list
:
7307 printf (_("<End of list>\n\n"));
7311 case DW_LLE_base_addressx
:
7312 READ_ULEB (base_address
, start
, end
);
7313 print_hex (base_address
, address_size
);
7314 printf (_("(index into .debug_addr) "));
7315 base_address
= fetch_indexed_addr (base_address
, address_size
);
7316 print_hex (base_address
, address_size
);
7317 printf (_("(base address)\n"));
7320 case DW_LLE_startx_endx
:
7321 READ_ULEB (begin
, start
, end
);
7322 begin
= fetch_indexed_addr (begin
, address_size
);
7323 READ_ULEB (finish
, start
, end
);
7324 finish
= fetch_indexed_addr (finish
, address_size
);
7327 case DW_LLE_startx_length
:
7328 READ_ULEB (begin
, start
, end
);
7329 begin
= fetch_indexed_addr (begin
, address_size
);
7330 READ_ULEB (finish
, start
, end
);
7334 case DW_LLE_offset_pair
:
7335 READ_ULEB (begin
, start
, end
);
7336 begin
+= base_address
;
7337 READ_ULEB (finish
, start
, end
);
7338 finish
+= base_address
;
7341 case DW_LLE_default_location
:
7345 case DW_LLE_base_address
:
7346 SAFE_BYTE_GET_AND_INC (base_address
, start
, address_size
, end
);
7347 print_hex (base_address
, address_size
);
7348 printf (_("(base address)\n"));
7351 case DW_LLE_start_end
:
7352 SAFE_BYTE_GET_AND_INC (begin
, start
, address_size
, end
);
7353 SAFE_BYTE_GET_AND_INC (finish
, start
, address_size
, end
);
7356 case DW_LLE_start_length
:
7357 SAFE_BYTE_GET_AND_INC (begin
, start
, address_size
, end
);
7358 READ_ULEB (finish
, start
, end
);
7363 error (_("Invalid location list entry type %d\n"), lle
);
7369 warn (_("Location list starting at offset %#" PRIx64
7370 " is not terminated.\n"), off
);
7374 print_hex (begin
, address_size
);
7375 print_hex (finish
, address_size
);
7377 if (begin
== finish
)
7378 fputs (_("(start == end)"), stdout
);
7379 else if (begin
> finish
)
7380 fputs (_("(start > end)"), stdout
);
7382 /* Read the counted location descriptions. */
7383 READ_ULEB (length
, start
, end
);
7385 if (length
> (size_t) (end
- start
))
7387 warn (_("Location list starting at offset %#" PRIx64
7388 " is not terminated.\n"), off
);
7392 (void) decode_location_expression (start
, address_size
, address_size
,
7393 version
, length
, 0, section
);
7400 while (start
< end
);
7406 display_debug_loc (struct dwarf_section
*section
, void *file
)
7408 unsigned char *start
= section
->start
, *vstart
= NULL
;
7410 unsigned char *section_begin
= start
;
7411 unsigned int num_loc_list
= 0;
7412 uint64_t last_offset
= 0;
7413 uint64_t last_view
= 0;
7414 unsigned int first
= 0;
7417 int seen_first_offset
= 0;
7418 int locs_sorted
= 1;
7419 unsigned char *next
= start
, *vnext
= vstart
;
7420 unsigned int *array
= NULL
;
7421 const char *suffix
= strrchr (section
->name
, '.');
7422 bool is_dwo
= false;
7423 int is_loclists
= strstr (section
->name
, "debug_loclists") != NULL
;
7424 uint64_t header_size
= 0;
7426 if (suffix
&& strcmp (suffix
, ".dwo") == 0)
7429 bytes
= section
->size
;
7433 printf (_("\nThe %s section is empty.\n"), section
->name
);
7439 unsigned char *hdrptr
= section_begin
;
7441 unsigned short ll_version
;
7442 unsigned char *end
= section_begin
+ section
->size
;
7443 unsigned char address_size
, segment_selector_size
;
7444 uint32_t offset_entry_count
;
7446 SAFE_BYTE_GET_AND_INC (ll_length
, hdrptr
, 4, end
);
7447 if (ll_length
== 0xffffffff)
7448 SAFE_BYTE_GET_AND_INC (ll_length
, hdrptr
, 8, end
);
7450 SAFE_BYTE_GET_AND_INC (ll_version
, hdrptr
, 2, end
);
7451 if (ll_version
!= 5)
7453 warn (_("The %s section contains corrupt or "
7454 "unsupported version number: %d.\n"),
7455 section
->name
, ll_version
);
7459 SAFE_BYTE_GET_AND_INC (address_size
, hdrptr
, 1, end
);
7461 SAFE_BYTE_GET_AND_INC (segment_selector_size
, hdrptr
, 1, end
);
7462 if (segment_selector_size
!= 0)
7464 warn (_("The %s section contains "
7465 "unsupported segment selector size: %d.\n"),
7466 section
->name
, segment_selector_size
);
7470 SAFE_BYTE_GET_AND_INC (offset_entry_count
, hdrptr
, 4, end
);
7472 if (offset_entry_count
!= 0)
7473 return display_offset_entry_loclists (section
);
7475 header_size
= hdrptr
- section_begin
;
7478 if (load_debug_info (file
) == 0)
7480 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
7485 /* Check the order of location list in .debug_info section. If
7486 offsets of location lists are in the ascending order, we can
7487 use `debug_information' directly. */
7488 for (i
= 0; i
< num_debug_info_entries
; i
++)
7492 num
= debug_information
[i
].num_loc_offsets
;
7493 if (num
> num_loc_list
)
7496 /* Check if we can use `debug_information' directly. */
7497 if (locs_sorted
&& num
!= 0)
7499 if (!seen_first_offset
)
7501 /* This is the first location list. */
7502 last_offset
= debug_information
[i
].loc_offsets
[0];
7503 last_view
= debug_information
[i
].loc_views
[0];
7505 seen_first_offset
= 1;
7511 for (; j
< num
; j
++)
7514 debug_information
[i
].loc_offsets
[j
]
7515 || (last_offset
== debug_information
[i
].loc_offsets
[j
]
7516 && last_view
> debug_information
[i
].loc_views
[j
]))
7521 last_offset
= debug_information
[i
].loc_offsets
[j
];
7522 last_view
= debug_information
[i
].loc_views
[j
];
7527 if (!seen_first_offset
)
7528 error (_("No location lists in .debug_info section!\n"));
7530 if (debug_information
[first
].num_loc_offsets
> 0
7531 && debug_information
[first
].loc_offsets
[0] != header_size
7532 && debug_information
[first
].loc_views
[0] != header_size
)
7533 warn (_("Location lists in %s section start at %#" PRIx64
7534 " rather than %#" PRIx64
"\n"),
7535 section
->name
, debug_information
[first
].loc_offsets
[0],
7539 array
= (unsigned int *) xcmalloc (num_loc_list
, sizeof (unsigned int));
7541 introduce (section
, false);
7543 if (reloc_at (section
, 0))
7544 printf (_(" Warning: This section has relocations - addresses seen here may not be accurate.\n\n"));
7546 printf (_(" Offset Begin End Expression\n"));
7548 for (i
= first
; i
< num_debug_info_entries
; i
++)
7550 uint64_t offset
= 0, voffset
= 0;
7551 uint64_t base_address
;
7557 for (k
= 0; k
< debug_information
[i
].num_loc_offsets
; k
++)
7559 loc_offsets
= debug_information
[i
].loc_offsets
;
7560 loc_views
= debug_information
[i
].loc_views
;
7561 qsort (array
, debug_information
[i
].num_loc_offsets
,
7562 sizeof (*array
), loc_offsets_compar
);
7565 /* .debug_loclists has a per-unit header.
7566 Update start if we are detecting it. */
7567 if (debug_information
[i
].dwarf_version
== 5)
7569 j
= locs_sorted
? 0 : array
[0];
7571 if (debug_information
[i
].num_loc_offsets
)
7572 offset
= debug_information
[i
].loc_offsets
[j
];
7574 if (debug_information
[i
].num_loc_views
)
7575 voffset
= debug_information
[i
].loc_views
[j
];
7577 /* Assume that the size of the header is constant across CUs. */
7578 if (((start
- section_begin
) + header_size
== offset
)
7579 || ((start
-section_begin
) + header_size
== voffset
))
7580 start
+= header_size
;
7583 int adjacent_view_loclists
= 1;
7584 for (k
= 0; k
< debug_information
[i
].num_loc_offsets
; k
++)
7586 j
= locs_sorted
? k
: array
[k
];
7588 && (debug_information
[i
].loc_offsets
[locs_sorted
7589 ? k
- 1 : array
[k
- 1]]
7590 == debug_information
[i
].loc_offsets
[j
])
7591 && (debug_information
[i
].loc_views
[locs_sorted
7592 ? k
- 1 : array
[k
- 1]]
7593 == debug_information
[i
].loc_views
[j
]))
7595 has_frame_base
= debug_information
[i
].have_frame_base
[j
];
7596 offset
= debug_information
[i
].loc_offsets
[j
];
7597 next
= section_begin
+ offset
;
7598 voffset
= debug_information
[i
].loc_views
[j
];
7599 if (voffset
!= (uint64_t) -1)
7600 vnext
= section_begin
+ voffset
;
7603 base_address
= debug_information
[i
].base_address
;
7605 if (vnext
&& vnext
< next
)
7608 display_view_pair_list (section
, &vstart
, i
, next
);
7615 if (vnext
&& vnext
< next
)
7616 warn (_("There is a hole [%#tx - %#" PRIx64
"]"
7617 " in %s section.\n"),
7618 start
- section_begin
, voffset
, section
->name
);
7620 warn (_("There is a hole [%#tx - %#" PRIx64
"]"
7621 " in %s section.\n"),
7622 start
- section_begin
, offset
, section
->name
);
7624 else if (start
> next
)
7625 warn (_("There is an overlap [%#tx - %#" PRIx64
"]"
7626 " in %s section.\n"),
7627 start
- section_begin
, offset
, section
->name
);
7631 if (offset
>= bytes
)
7633 warn (_("Offset %#" PRIx64
" is bigger than %s section size.\n"),
7634 offset
, section
->name
);
7638 if (vnext
&& voffset
>= bytes
)
7640 warn (_("View Offset %#" PRIx64
" is bigger than %s section size.\n"),
7641 voffset
, section
->name
);
7648 display_loc_list_dwo (section
, &start
, i
, offset
,
7649 &vstart
, has_frame_base
);
7651 display_loc_list (section
, &start
, i
, offset
, base_address
,
7652 &vstart
, has_frame_base
);
7657 warn (_("DWO is not yet supported.\n"));
7659 display_loclists_list (section
, &start
, i
, offset
, base_address
,
7660 &vstart
, has_frame_base
);
7663 /* FIXME: this arrangement is quite simplistic. Nothing
7664 requires locview lists to be adjacent to corresponding
7665 loclists, and a single loclist could be augmented by
7666 different locview lists, and vice-versa, unlikely as it
7667 is that it would make sense to do so. Hopefully we'll
7668 have view pair support built into loclists before we ever
7669 need to address all these possibilities. */
7670 if (adjacent_view_loclists
&& vnext
7671 && vnext
!= start
&& vstart
!= next
)
7673 adjacent_view_loclists
= 0;
7674 warn (_("Hole and overlap detection requires adjacent view lists and loclists.\n"));
7677 if (vnext
&& vnext
== start
)
7678 display_view_pair_list (section
, &start
, i
, vstart
);
7682 if (start
< section
->start
+ section
->size
)
7683 warn (ngettext ("There is %ld unused byte at the end of section %s\n",
7684 "There are %ld unused bytes at the end of section %s\n",
7685 (long) (section
->start
+ section
->size
- start
)),
7686 (long) (section
->start
+ section
->size
- start
), section
->name
);
7693 display_debug_str (struct dwarf_section
*section
,
7694 void *file ATTRIBUTE_UNUSED
)
7696 unsigned char *start
= section
->start
;
7697 uint64_t bytes
= section
->size
;
7698 uint64_t addr
= section
->address
;
7702 printf (_("\nThe %s section is empty.\n"), section
->name
);
7706 introduce (section
, false);
7714 lbytes
= (bytes
> 16 ? 16 : bytes
);
7716 printf (" 0x%8.8" PRIx64
" ", addr
);
7718 for (j
= 0; j
< 16; j
++)
7721 printf ("%2.2x", start
[j
]);
7729 for (j
= 0; j
< lbytes
; j
++)
7732 if (k
>= ' ' && k
< 0x80)
7751 display_debug_info (struct dwarf_section
*section
, void *file
)
7753 return process_debug_info (section
, file
, section
->abbrev_sec
, false, false);
7757 display_debug_types (struct dwarf_section
*section
, void *file
)
7759 return process_debug_info (section
, file
, section
->abbrev_sec
, false, true);
7763 display_trace_info (struct dwarf_section
*section
, void *file
)
7765 return process_debug_info (section
, file
, section
->abbrev_sec
, false, true);
7769 display_debug_aranges (struct dwarf_section
*section
,
7770 void *file ATTRIBUTE_UNUSED
)
7772 unsigned char *start
= section
->start
;
7773 unsigned char *end
= start
+ section
->size
;
7775 introduce (section
, false);
7777 /* It does not matter if this load fails,
7778 we test for that later on. */
7779 load_debug_info (file
);
7783 unsigned char *hdrptr
;
7784 DWARF2_Internal_ARange arange
;
7785 unsigned char *addr_ranges
;
7789 unsigned char address_size
;
7790 unsigned int offset_size
;
7791 unsigned char *end_ranges
;
7794 sec_off
= hdrptr
- section
->start
;
7796 SAFE_BYTE_GET_AND_INC (arange
.ar_length
, hdrptr
, 4, end
);
7797 if (arange
.ar_length
== 0xffffffff)
7799 SAFE_BYTE_GET_AND_INC (arange
.ar_length
, hdrptr
, 8, end
);
7805 if (arange
.ar_length
> (size_t) (end
- hdrptr
))
7807 warn (_("Debug info is corrupted, %s header at %#" PRIx64
7808 " has length %#" PRIx64
"\n"),
7809 section
->name
, sec_off
, arange
.ar_length
);
7812 end_ranges
= hdrptr
+ arange
.ar_length
;
7814 SAFE_BYTE_GET_AND_INC (arange
.ar_version
, hdrptr
, 2, end_ranges
);
7815 SAFE_BYTE_GET_AND_INC (arange
.ar_info_offset
, hdrptr
, offset_size
,
7818 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
7819 && num_debug_info_entries
> 0
7820 && find_debug_info_for_offset (arange
.ar_info_offset
) == NULL
)
7821 warn (_(".debug_info offset of %#" PRIx64
7822 " in %s section does not point to a CU header.\n"),
7823 arange
.ar_info_offset
, section
->name
);
7825 SAFE_BYTE_GET_AND_INC (arange
.ar_pointer_size
, hdrptr
, 1, end_ranges
);
7826 SAFE_BYTE_GET_AND_INC (arange
.ar_segment_size
, hdrptr
, 1, end_ranges
);
7828 if (arange
.ar_version
!= 2 && arange
.ar_version
!= 3)
7830 /* PR 19872: A version number of 0 probably means that there is
7831 padding at the end of the .debug_aranges section. Gold puts
7832 it there when performing an incremental link, for example.
7833 So do not generate a warning in this case. */
7834 if (arange
.ar_version
)
7835 warn (_("Only DWARF 2 and 3 aranges are currently supported.\n"));
7839 printf (_(" Length: %" PRId64
"\n"), arange
.ar_length
);
7840 printf (_(" Version: %d\n"), arange
.ar_version
);
7841 printf (_(" Offset into .debug_info: %#" PRIx64
"\n"),
7842 arange
.ar_info_offset
);
7843 printf (_(" Pointer Size: %d\n"), arange
.ar_pointer_size
);
7844 printf (_(" Segment Size: %d\n"), arange
.ar_segment_size
);
7846 address_size
= arange
.ar_pointer_size
+ arange
.ar_segment_size
;
7848 /* PR 17512: file: 001-108546-0.001:0.1. */
7849 if (address_size
== 0 || address_size
> 8)
7851 error (_("Invalid address size in %s section!\n"),
7856 /* The DWARF spec does not require that the address size be a power
7857 of two, but we do. This will have to change if we ever encounter
7858 an uneven architecture. */
7859 if ((address_size
& (address_size
- 1)) != 0)
7861 warn (_("Pointer size + Segment size is not a power of two.\n"));
7865 if (address_size
> 4)
7866 printf (_("\n Address Length\n"));
7868 printf (_("\n Address Length\n"));
7870 addr_ranges
= hdrptr
;
7872 /* Must pad to an alignment boundary that is twice the address size. */
7873 addr_ranges
+= (2 * address_size
- 1
7874 - (hdrptr
- start
- 1) % (2 * address_size
));
7876 while (2 * address_size
<= end_ranges
- addr_ranges
)
7878 SAFE_BYTE_GET_AND_INC (address
, addr_ranges
, address_size
,
7880 SAFE_BYTE_GET_AND_INC (length
, addr_ranges
, address_size
,
7883 print_hex (address
, address_size
);
7884 print_hex_ns (length
, address_size
);
7896 /* Comparison function for qsort. */
7898 comp_addr_base (const void * v0
, const void * v1
)
7900 debug_info
*info0
= *(debug_info
**) v0
;
7901 debug_info
*info1
= *(debug_info
**) v1
;
7902 return info0
->addr_base
- info1
->addr_base
;
7905 /* Display the debug_addr section. */
7907 display_debug_addr (struct dwarf_section
*section
,
7910 debug_info
**debug_addr_info
;
7911 unsigned char *entry
;
7915 unsigned char * header
;
7917 if (section
->size
== 0)
7919 printf (_("\nThe %s section is empty.\n"), section
->name
);
7923 if (load_debug_info (file
) == 0)
7925 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
7930 introduce (section
, false);
7932 /* PR 17531: file: cf38d01b.
7933 We use xcalloc because a corrupt file may not have initialised all of the
7934 fields in the debug_info structure, which means that the sort below might
7935 try to move uninitialised data. */
7936 debug_addr_info
= (debug_info
**) xcalloc ((num_debug_info_entries
+ 1),
7937 sizeof (debug_info
*));
7940 for (i
= 0; i
< num_debug_info_entries
; i
++)
7941 if (debug_information
[i
].addr_base
!= DEBUG_INFO_UNAVAILABLE
)
7943 /* PR 17531: file: cf38d01b. */
7944 if (debug_information
[i
].addr_base
>= section
->size
)
7945 warn (_("Corrupt address base (%#" PRIx64
")"
7946 " found in debug section %u\n"),
7947 debug_information
[i
].addr_base
, i
);
7949 debug_addr_info
[count
++] = debug_information
+ i
;
7952 /* Add a sentinel to make iteration convenient. */
7953 debug_addr_info
[count
] = (debug_info
*) xmalloc (sizeof (debug_info
));
7954 debug_addr_info
[count
]->addr_base
= section
->size
;
7955 qsort (debug_addr_info
, count
, sizeof (debug_info
*), comp_addr_base
);
7957 header
= section
->start
;
7958 for (i
= 0; i
< count
; i
++)
7961 unsigned int address_size
= debug_addr_info
[i
]->pointer_size
;
7963 printf (_(" For compilation unit at offset %#" PRIx64
":\n"),
7964 debug_addr_info
[i
]->cu_offset
);
7966 printf (_("\tIndex\tAddress\n"));
7967 entry
= section
->start
+ debug_addr_info
[i
]->addr_base
;
7968 if (debug_addr_info
[i
]->dwarf_version
>= 5)
7970 size_t header_size
= entry
- header
;
7971 unsigned char *curr_header
= header
;
7974 int segment_selector_size
;
7976 if (header_size
!= 8 && header_size
!= 16)
7978 warn (_("Corrupt %s section: expecting header size of 8 or 16, but found %zd instead\n"),
7979 section
->name
, header_size
);
7983 SAFE_BYTE_GET_AND_INC (length
, curr_header
, 4, entry
);
7984 if (length
== 0xffffffff)
7985 SAFE_BYTE_GET_AND_INC (length
, curr_header
, 8, entry
);
7986 if (length
> (size_t) (section
->start
+ section
->size
- curr_header
)
7987 || length
< (size_t) (entry
- curr_header
))
7989 warn (_("Corrupt %s section: unit_length field of %#" PRIx64
7990 " is invalid\n"), section
->name
, length
);
7993 end
= curr_header
+ length
;
7994 SAFE_BYTE_GET_AND_INC (version
, curr_header
, 2, entry
);
7996 warn (_("Corrupt %s section: expecting version number 5 in header but found %d instead\n"),
7997 section
->name
, version
);
7999 SAFE_BYTE_GET_AND_INC (address_size
, curr_header
, 1, entry
);
8000 SAFE_BYTE_GET_AND_INC (segment_selector_size
, curr_header
, 1, entry
);
8001 address_size
+= segment_selector_size
;
8004 end
= section
->start
+ debug_addr_info
[i
+ 1]->addr_base
;
8009 if (address_size
< 1 || address_size
> sizeof (uint64_t))
8011 warn (_("Corrupt %s section: address size (%x) is wrong"),
8012 section
->name
, address_size
);
8016 while ((size_t) (end
- entry
) >= address_size
)
8018 uint64_t base
= byte_get (entry
, address_size
);
8019 printf (_("\t%d:\t"), idx
);
8020 print_hex_ns (base
, address_size
);
8022 entry
+= address_size
;
8028 free (debug_addr_info
);
8032 /* Display the .debug_str_offsets and .debug_str_offsets.dwo sections. */
8035 display_debug_str_offsets (struct dwarf_section
*section
,
8036 void *file ATTRIBUTE_UNUSED
)
8040 if (section
->size
== 0)
8042 printf (_("\nThe %s section is empty.\n"), section
->name
);
8046 unsigned char *start
= section
->start
;
8047 unsigned char *end
= start
+ section
->size
;
8048 unsigned char *curr
= start
;
8049 uint64_t debug_str_offsets_hdr_len
;
8051 const char *suffix
= strrchr (section
->name
, '.');
8052 bool dwo
= suffix
&& strcmp (suffix
, ".dwo") == 0;
8055 load_debug_section_with_follow (str_dwo
, file
);
8057 load_debug_section_with_follow (str
, file
);
8059 introduce (section
, false);
8064 uint64_t entry_length
;
8066 SAFE_BYTE_GET_AND_INC (length
, curr
, 4, end
);
8067 /* FIXME: We assume that this means 64-bit DWARF is being used. */
8068 if (length
== 0xffffffff)
8070 SAFE_BYTE_GET_AND_INC (length
, curr
, 8, end
);
8072 debug_str_offsets_hdr_len
= 16;
8077 debug_str_offsets_hdr_len
= 8;
8080 unsigned char *entries_end
;
8083 /* This is probably an old style .debug_str_offset section which
8084 just contains offsets and no header (and the first offset is 0). */
8085 length
= section
->size
;
8086 curr
= section
->start
;
8089 printf (_(" Length: %#" PRIx64
"\n"), length
);
8090 printf (_(" Index Offset [String]\n"));
8094 if (length
<= (size_t) (end
- curr
))
8095 entries_end
= curr
+ length
;
8098 warn (_("Section %s is too small %#" PRIx64
"\n"),
8099 section
->name
, section
->size
);
8104 SAFE_BYTE_GET_AND_INC (version
, curr
, 2, entries_end
);
8106 warn (_("Unexpected version number in str_offset header: %#x\n"), version
);
8109 SAFE_BYTE_GET_AND_INC (padding
, curr
, 2, entries_end
);
8111 warn (_("Unexpected value in str_offset header's padding field: %#x\n"), padding
);
8113 printf (_(" Length: %#" PRIx64
"\n"), length
);
8114 printf (_(" Version: %#x\n"), version
);
8115 printf (_(" Index Offset [String]\n"));
8118 for (idx
= 0; curr
< entries_end
; idx
++)
8121 const unsigned char * string
;
8123 if ((size_t) (entries_end
- curr
) < entry_length
)
8124 /* Not enough space to read one entry_length, give up. */
8127 SAFE_BYTE_GET_AND_INC (offset
, curr
, entry_length
, entries_end
);
8129 string
= (const unsigned char *)
8130 fetch_indexed_string (idx
, NULL
, entry_length
, dwo
, debug_str_offsets_hdr_len
);
8132 string
= fetch_indirect_string (offset
);
8134 printf (" %8lu ", idx
);
8135 print_hex (offset
, entry_length
);
8136 printf (" %s\n", string
);
8143 /* Each debug_information[x].range_lists[y] gets this representation for
8144 sorting purposes. */
8148 /* The debug_information[x].range_lists[y] value. */
8149 uint64_t ranges_offset
;
8151 /* Original debug_information to find parameters of the data. */
8152 debug_info
*debug_info_p
;
8155 /* Sort struct range_entry in ascending order of its RANGES_OFFSET. */
8158 range_entry_compar (const void *ap
, const void *bp
)
8160 const struct range_entry
*a_re
= (const struct range_entry
*) ap
;
8161 const struct range_entry
*b_re
= (const struct range_entry
*) bp
;
8162 const uint64_t a
= a_re
->ranges_offset
;
8163 const uint64_t b
= b_re
->ranges_offset
;
8165 return (a
> b
) - (b
> a
);
8169 display_debug_ranges_list (unsigned char * start
,
8170 unsigned char * finish
,
8171 unsigned int pointer_size
,
8173 uint64_t base_address
)
8175 while (start
< finish
)
8180 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
8181 if (start
>= finish
)
8183 SAFE_SIGNED_BYTE_GET_AND_INC (end
, start
, pointer_size
, finish
);
8186 print_hex (offset
, 4);
8188 if (begin
== 0 && end
== 0)
8190 printf (_("<End of list>\n"));
8194 /* Check base address specifiers. */
8195 if (is_max_address (begin
, pointer_size
)
8196 && !is_max_address (end
, pointer_size
))
8199 print_hex (begin
, pointer_size
);
8200 print_hex (end
, pointer_size
);
8201 printf ("(base address)\n");
8205 print_hex (begin
+ base_address
, pointer_size
);
8206 print_hex_ns (end
+ base_address
, pointer_size
);
8209 fputs (_(" (start == end)"), stdout
);
8210 else if (begin
> end
)
8211 fputs (_(" (start > end)"), stdout
);
8217 static unsigned char *
8218 display_debug_rnglists_list (unsigned char * start
,
8219 unsigned char * finish
,
8220 unsigned int pointer_size
,
8222 uint64_t base_address
,
8225 unsigned char *next
= start
;
8229 uint64_t off
= offset
+ (start
- next
);
8230 enum dwarf_range_list_entry rlet
;
8231 /* Initialize it due to a false compiler warning. */
8232 uint64_t begin
= -1, length
, end
= -1;
8234 if (start
>= finish
)
8236 warn (_("Range list starting at offset %#" PRIx64
8237 " is not terminated.\n"), offset
);
8244 SAFE_BYTE_GET_AND_INC (rlet
, start
, 1, finish
);
8248 case DW_RLE_end_of_list
:
8249 printf (_("<End of list>\n"));
8251 case DW_RLE_base_addressx
:
8252 READ_ULEB (base_address
, start
, finish
);
8253 print_hex (base_address
, pointer_size
);
8254 printf (_("(base address index) "));
8255 base_address
= fetch_indexed_addr ((base_address
* pointer_size
) + addr_base
,
8257 print_hex (base_address
, pointer_size
);
8258 printf (_("(base address)\n"));
8260 case DW_RLE_startx_endx
:
8261 READ_ULEB (begin
, start
, finish
);
8262 READ_ULEB (end
, start
, finish
);
8263 begin
= fetch_indexed_addr ((begin
* pointer_size
) + addr_base
,
8265 end
= fetch_indexed_addr ((begin
* pointer_size
) + addr_base
,
8268 case DW_RLE_startx_length
:
8269 READ_ULEB (begin
, start
, finish
);
8270 READ_ULEB (length
, start
, finish
);
8271 begin
= fetch_indexed_addr ((begin
* pointer_size
) + addr_base
,
8273 end
= begin
+ length
;
8275 case DW_RLE_offset_pair
:
8276 READ_ULEB (begin
, start
, finish
);
8277 READ_ULEB (end
, start
, finish
);
8279 case DW_RLE_base_address
:
8280 SAFE_BYTE_GET_AND_INC (base_address
, start
, pointer_size
, finish
);
8281 print_hex (base_address
, pointer_size
);
8282 printf (_("(base address)\n"));
8284 case DW_RLE_start_end
:
8285 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
8286 SAFE_BYTE_GET_AND_INC (end
, start
, pointer_size
, finish
);
8288 case DW_RLE_start_length
:
8289 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
8290 READ_ULEB (length
, start
, finish
);
8291 end
= begin
+ length
;
8294 error (_("Invalid range list entry type %d\n"), rlet
);
8295 rlet
= DW_RLE_end_of_list
;
8299 if (rlet
== DW_RLE_end_of_list
)
8301 if (rlet
== DW_RLE_base_address
|| rlet
== DW_RLE_base_addressx
)
8304 /* Only a DW_RLE_offset_pair needs the base address added. */
8305 if (rlet
== DW_RLE_offset_pair
)
8307 begin
+= base_address
;
8308 end
+= base_address
;
8311 print_hex (begin
, pointer_size
);
8312 print_hex (end
, pointer_size
);
8315 fputs (_(" (start == end)"), stdout
);
8316 else if (begin
> end
)
8317 fputs (_(" (start > end)"), stdout
);
8326 display_debug_rnglists_unit_header (struct dwarf_section
* section
,
8327 uint64_t * unit_offset
,
8328 unsigned char * poffset_size
)
8330 uint64_t start_offset
= *unit_offset
;
8331 unsigned char * p
= section
->start
+ start_offset
;
8332 unsigned char * finish
= section
->start
+ section
->size
;
8333 uint64_t initial_length
;
8334 unsigned char segment_selector_size
;
8335 unsigned int offset_entry_count
;
8337 unsigned short version
;
8338 unsigned char address_size
= 0;
8339 unsigned char offset_size
;
8341 /* Get and check the length of the block. */
8342 SAFE_BYTE_GET_AND_INC (initial_length
, p
, 4, finish
);
8344 if (initial_length
== 0xffffffff)
8346 /* This section is 64-bit DWARF 3. */
8347 SAFE_BYTE_GET_AND_INC (initial_length
, p
, 8, finish
);
8348 *poffset_size
= offset_size
= 8;
8351 *poffset_size
= offset_size
= 4;
8353 if (initial_length
> (size_t) (finish
- p
))
8355 /* If the length field has a relocation against it, then we should
8356 not complain if it is inaccurate (and probably negative).
8357 It is copied from .debug_line handling code. */
8358 if (reloc_at (section
, (p
- section
->start
) - offset_size
))
8359 initial_length
= finish
- p
;
8362 warn (_("The length field (%#" PRIx64
8363 ") in the debug_rnglists header is wrong"
8364 " - the section is too small\n"),
8370 /* Report the next unit offset to the caller. */
8371 *unit_offset
= (p
- section
->start
) + initial_length
;
8373 /* Get the other fields in the header. */
8374 SAFE_BYTE_GET_AND_INC (version
, p
, 2, finish
);
8375 SAFE_BYTE_GET_AND_INC (address_size
, p
, 1, finish
);
8376 SAFE_BYTE_GET_AND_INC (segment_selector_size
, p
, 1, finish
);
8377 SAFE_BYTE_GET_AND_INC (offset_entry_count
, p
, 4, finish
);
8379 printf (_(" Table at Offset: %#" PRIx64
":\n"), start_offset
);
8380 printf (_(" Length: %#" PRIx64
"\n"), initial_length
);
8381 printf (_(" DWARF version: %u\n"), version
);
8382 printf (_(" Address size: %u\n"), address_size
);
8383 printf (_(" Segment size: %u\n"), segment_selector_size
);
8384 printf (_(" Offset entries: %u\n"), offset_entry_count
);
8386 /* Check the fields. */
8387 if (segment_selector_size
!= 0)
8389 warn (_("The %s section contains "
8390 "unsupported segment selector size: %d.\n"),
8391 section
->name
, segment_selector_size
);
8397 warn (_("Only DWARF version 5+ debug_rnglists info "
8398 "is currently supported.\n"));
8402 if (offset_entry_count
!= 0)
8404 printf (_("\n Offsets starting at %#tx:\n"), p
- section
->start
);
8406 for (i
= 0; i
< offset_entry_count
; i
++)
8410 SAFE_BYTE_GET_AND_INC (entry
, p
, offset_size
, finish
);
8411 printf (_(" [%6u] %#" PRIx64
"\n"), i
, entry
);
8419 is_range_list_for_this_section (bool is_rnglists
, unsigned int version
)
8421 if (is_rnglists
&& version
> 4)
8424 if (! is_rnglists
&& version
< 5)
8431 display_debug_ranges (struct dwarf_section
*section
,
8432 void *file ATTRIBUTE_UNUSED
)
8434 unsigned char *start
= section
->start
;
8435 unsigned char *last_start
= start
;
8436 uint64_t bytes
= section
->size
;
8437 unsigned char *section_begin
= start
;
8438 unsigned char *finish
= start
+ bytes
;
8439 unsigned int num_range_list
, i
;
8440 struct range_entry
*range_entries
;
8441 struct range_entry
*range_entry_fill
;
8442 bool is_rnglists
= strstr (section
->name
, "debug_rnglists") != NULL
;
8443 uint64_t last_offset
= 0;
8444 uint64_t next_rnglists_cu_offset
= 0;
8445 unsigned char offset_size
;
8449 printf (_("\nThe %s section is empty.\n"), section
->name
);
8453 introduce (section
, false);
8455 if (load_debug_info (file
) == 0)
8457 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
8463 for (i
= 0; i
< num_debug_info_entries
; i
++)
8464 if (is_range_list_for_this_section (is_rnglists
, debug_information
[i
].dwarf_version
))
8465 num_range_list
+= debug_information
[i
].num_range_lists
;
8467 if (num_range_list
== 0)
8469 /* This can happen when the file was compiled with -gsplit-debug
8470 which removes references to range lists from the primary .o file. */
8471 printf (_("No range lists referenced by .debug_info section.\n"));
8475 range_entry_fill
= range_entries
= XNEWVEC (struct range_entry
, num_range_list
);
8477 for (i
= 0; i
< num_debug_info_entries
; i
++)
8479 debug_info
*debug_info_p
= &debug_information
[i
];
8482 for (j
= 0; j
< debug_info_p
->num_range_lists
; j
++)
8484 if (is_range_list_for_this_section (is_rnglists
, debug_info_p
->dwarf_version
))
8486 range_entry_fill
->ranges_offset
= debug_info_p
->range_lists
[j
];
8487 range_entry_fill
->debug_info_p
= debug_info_p
;
8493 assert (range_entry_fill
>= range_entries
);
8494 assert (num_range_list
>= (unsigned int)(range_entry_fill
- range_entries
));
8495 num_range_list
= range_entry_fill
- range_entries
;
8496 qsort (range_entries
, num_range_list
, sizeof (*range_entries
),
8497 range_entry_compar
);
8499 if (dwarf_check
!= 0 && range_entries
[0].ranges_offset
!= 0)
8500 warn (_("Range lists in %s section start at %#" PRIx64
"\n"),
8501 section
->name
, range_entries
[0].ranges_offset
);
8505 printf (_(" Offset Begin End\n"));
8507 for (i
= 0; i
< num_range_list
; i
++)
8509 struct range_entry
*range_entry
= &range_entries
[i
];
8510 debug_info
*debug_info_p
= range_entry
->debug_info_p
;
8511 unsigned int pointer_size
;
8513 unsigned char *next
;
8514 uint64_t base_address
;
8516 pointer_size
= debug_info_p
->pointer_size
;
8517 offset
= range_entry
->ranges_offset
;
8518 base_address
= debug_info_p
->base_address
;
8520 /* PR 17512: file: 001-101485-0.001:0.1. */
8521 if (pointer_size
< 2 || pointer_size
> 8)
8523 warn (_("Corrupt pointer size (%d) in debug entry at offset %#" PRIx64
"\n"),
8524 pointer_size
, offset
);
8528 if (offset
> (size_t) (finish
- section_begin
))
8530 warn (_("Corrupt offset (%#" PRIx64
") in range entry %u\n"),
8535 /* If we've moved on to the next compile unit in the rnglists section - dump the unit header(s). */
8536 if (is_rnglists
&& next_rnglists_cu_offset
< offset
)
8538 while (next_rnglists_cu_offset
< offset
)
8539 display_debug_rnglists_unit_header (section
, &next_rnglists_cu_offset
, &offset_size
);
8540 printf (_(" Offset Begin End\n"));
8543 next
= section_begin
+ offset
; /* Offset is from the section start, the base has already been added. */
8545 /* If multiple DWARF entities reference the same range then we will
8546 have multiple entries in the `range_entries' list for the same
8547 offset. Thanks to the sort above these will all be consecutive in
8548 the `range_entries' list, so we can easily ignore duplicates
8550 if (i
> 0 && last_offset
== offset
)
8552 last_offset
= offset
;
8554 if (dwarf_check
!= 0 && i
> 0)
8557 warn (_("There is a hole [%#tx - %#tx] in %s section.\n"),
8558 start
- section_begin
, next
- section_begin
, section
->name
);
8559 else if (start
> next
)
8561 if (next
== last_start
)
8563 warn (_("There is an overlap [%#tx - %#tx] in %s section.\n"),
8564 start
- section_begin
, next
- section_begin
, section
->name
);
8572 display_debug_rnglists_list
8573 (start
, finish
, pointer_size
, offset
, base_address
, debug_info_p
->addr_base
);
8575 display_debug_ranges_list
8576 (start
, finish
, pointer_size
, offset
, base_address
);
8579 /* Display trailing empty (or unreferenced) compile units, if any. */
8581 while (next_rnglists_cu_offset
< section
->size
)
8582 display_debug_rnglists_unit_header (section
, &next_rnglists_cu_offset
, &offset_size
);
8586 free (range_entries
);
8591 typedef struct Frame_Chunk
8593 struct Frame_Chunk
*next
;
8594 unsigned char *chunk_start
;
8596 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
8597 short int *col_type
;
8598 int64_t *col_offset
;
8600 unsigned int code_factor
;
8604 unsigned int cfa_reg
;
8605 uint64_t cfa_offset
;
8607 unsigned char fde_encoding
;
8608 unsigned char cfa_exp
;
8609 unsigned char ptr_size
;
8610 unsigned char segment_size
;
8614 typedef const char *(*dwarf_regname_lookup_ftype
) (unsigned int);
8615 static dwarf_regname_lookup_ftype dwarf_regnames_lookup_func
;
8616 static const char *const *dwarf_regnames
;
8617 static unsigned int dwarf_regnames_count
;
8618 static bool is_aarch64
;
8620 /* A marker for a col_type that means this column was never referenced
8621 in the frame info. */
8622 #define DW_CFA_unreferenced (-1)
8624 /* Return 0 if no more space is needed, 1 if more space is needed,
8625 -1 for invalid reg. */
8628 frame_need_space (Frame_Chunk
*fc
, unsigned int reg
)
8630 unsigned int prev
= fc
->ncols
;
8632 if (reg
< (unsigned int) fc
->ncols
)
8635 if (dwarf_regnames_count
> 0
8636 && reg
> dwarf_regnames_count
)
8639 fc
->ncols
= reg
+ 1;
8640 /* PR 17512: file: 10450-2643-0.004.
8641 If reg == -1 then this can happen... */
8645 /* PR 17512: file: 2844a11d. */
8646 if (fc
->ncols
> 1024 && dwarf_regnames_count
== 0)
8648 error (_("Unfeasibly large register number: %u\n"), reg
);
8650 /* FIXME: 1024 is an arbitrary limit. Increase it if
8651 we ever encounter a valid binary that exceeds it. */
8655 fc
->col_type
= xcrealloc (fc
->col_type
, fc
->ncols
,
8656 sizeof (*fc
->col_type
));
8657 fc
->col_offset
= xcrealloc (fc
->col_offset
, fc
->ncols
,
8658 sizeof (*fc
->col_offset
));
8659 /* PR 17512: file:002-10025-0.005. */
8660 if (fc
->col_type
== NULL
|| fc
->col_offset
== NULL
)
8662 error (_("Out of memory allocating %u columns in dwarf frame arrays\n"),
8668 while (prev
< fc
->ncols
)
8670 fc
->col_type
[prev
] = DW_CFA_unreferenced
;
8671 fc
->col_offset
[prev
] = 0;
8677 static const char *const dwarf_regnames_i386
[] =
8679 "eax", "ecx", "edx", "ebx", /* 0 - 3 */
8680 "esp", "ebp", "esi", "edi", /* 4 - 7 */
8681 "eip", "eflags", NULL
, /* 8 - 10 */
8682 "st0", "st1", "st2", "st3", /* 11 - 14 */
8683 "st4", "st5", "st6", "st7", /* 15 - 18 */
8684 NULL
, NULL
, /* 19 - 20 */
8685 "xmm0", "xmm1", "xmm2", "xmm3", /* 21 - 24 */
8686 "xmm4", "xmm5", "xmm6", "xmm7", /* 25 - 28 */
8687 "mm0", "mm1", "mm2", "mm3", /* 29 - 32 */
8688 "mm4", "mm5", "mm6", "mm7", /* 33 - 36 */
8689 "fcw", "fsw", "mxcsr", /* 37 - 39 */
8690 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
, /* 40 - 47 */
8691 "tr", "ldtr", /* 48 - 49 */
8692 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 50 - 57 */
8693 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 58 - 65 */
8694 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 66 - 73 */
8695 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 74 - 81 */
8696 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 82 - 89 */
8697 NULL
, NULL
, NULL
, /* 90 - 92 */
8698 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7" /* 93 - 100 */
8701 static const char *const dwarf_regnames_iamcu
[] =
8703 "eax", "ecx", "edx", "ebx", /* 0 - 3 */
8704 "esp", "ebp", "esi", "edi", /* 4 - 7 */
8705 "eip", "eflags", NULL
, /* 8 - 10 */
8706 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 11 - 18 */
8707 NULL
, NULL
, /* 19 - 20 */
8708 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 21 - 28 */
8709 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 29 - 36 */
8710 NULL
, NULL
, NULL
, /* 37 - 39 */
8711 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
, /* 40 - 47 */
8712 "tr", "ldtr", /* 48 - 49 */
8713 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 50 - 57 */
8714 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 58 - 65 */
8715 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 66 - 73 */
8716 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 74 - 81 */
8717 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 82 - 89 */
8718 NULL
, NULL
, NULL
, /* 90 - 92 */
8719 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
/* 93 - 100 */
8723 init_dwarf_regnames_i386 (void)
8725 dwarf_regnames
= dwarf_regnames_i386
;
8726 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_i386
);
8727 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8731 init_dwarf_regnames_iamcu (void)
8733 dwarf_regnames
= dwarf_regnames_iamcu
;
8734 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_iamcu
);
8735 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8738 static const char *const DW_CFA_GNU_window_save_name
[] =
8740 "DW_CFA_GNU_window_save",
8741 "DW_CFA_AARCH64_negate_ra_state"
8744 static const char *const dwarf_regnames_x86_64
[] =
8746 "rax", "rdx", "rcx", "rbx",
8747 "rsi", "rdi", "rbp", "rsp",
8748 "r8", "r9", "r10", "r11",
8749 "r12", "r13", "r14", "r15",
8751 "xmm0", "xmm1", "xmm2", "xmm3",
8752 "xmm4", "xmm5", "xmm6", "xmm7",
8753 "xmm8", "xmm9", "xmm10", "xmm11",
8754 "xmm12", "xmm13", "xmm14", "xmm15",
8755 "st0", "st1", "st2", "st3",
8756 "st4", "st5", "st6", "st7",
8757 "mm0", "mm1", "mm2", "mm3",
8758 "mm4", "mm5", "mm6", "mm7",
8760 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
,
8761 "fs.base", "gs.base", NULL
, NULL
,
8763 "mxcsr", "fcw", "fsw",
8764 "xmm16", "xmm17", "xmm18", "xmm19",
8765 "xmm20", "xmm21", "xmm22", "xmm23",
8766 "xmm24", "xmm25", "xmm26", "xmm27",
8767 "xmm28", "xmm29", "xmm30", "xmm31",
8768 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 83 - 90 */
8769 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 91 - 98 */
8770 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 99 - 106 */
8771 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 107 - 114 */
8772 NULL
, NULL
, NULL
, /* 115 - 117 */
8773 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7"
8777 init_dwarf_regnames_x86_64 (void)
8779 dwarf_regnames
= dwarf_regnames_x86_64
;
8780 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_x86_64
);
8781 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8784 static const char *const dwarf_regnames_aarch64
[] =
8786 "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7",
8787 "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15",
8788 "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23",
8789 "x24", "x25", "x26", "x27", "x28", "x29", "x30", "sp",
8790 NULL
, "elr", NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
8791 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, "vg", "ffr",
8792 "p0", "p1", "p2", "p3", "p4", "p5", "p6", "p7",
8793 "p8", "p9", "p10", "p11", "p12", "p13", "p14", "p15",
8794 "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7",
8795 "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15",
8796 "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23",
8797 "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31",
8798 "z0", "z1", "z2", "z3", "z4", "z5", "z6", "z7",
8799 "z8", "z9", "z10", "z11", "z12", "z13", "z14", "z15",
8800 "z16", "z17", "z18", "z19", "z20", "z21", "z22", "z23",
8801 "z24", "z25", "z26", "z27", "z28", "z29", "z30", "z31",
8805 init_dwarf_regnames_aarch64 (void)
8807 dwarf_regnames
= dwarf_regnames_aarch64
;
8808 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_aarch64
);
8809 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8813 static const char *const dwarf_regnames_s390
[] =
8815 /* Avoid saying "r5 (r5)", so omit the names of r0-r15. */
8816 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
8817 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
8818 "f0", "f2", "f4", "f6", "f1", "f3", "f5", "f7",
8819 "f8", "f10", "f12", "f14", "f9", "f11", "f13", "f15",
8820 "cr0", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7",
8821 "cr8", "cr9", "cr10", "cr11", "cr12", "cr13", "cr14", "cr15",
8822 "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7",
8823 "a8", "a9", "a10", "a11", "a12", "a13", "a14", "a15",
8826 "v16", "v18", "v20", "v22", "v17", "v19", "v21", "v23",
8827 "v24", "v26", "v28", "v30", "v25", "v27", "v29", "v31",
8831 init_dwarf_regnames_s390 (void)
8833 dwarf_regnames
= dwarf_regnames_s390
;
8834 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_s390
);
8835 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8838 static const char *const dwarf_regnames_riscv
[] =
8840 "zero", "ra", "sp", "gp", "tp", "t0", "t1", "t2", /* 0 - 7 */
8841 "s0", "s1", "a0", "a1", "a2", "a3", "a4", "a5", /* 8 - 15 */
8842 "a6", "a7", "s2", "s3", "s4", "s5", "s6", "s7", /* 16 - 23 */
8843 "s8", "s9", "s10", "s11", "t3", "t4", "t5", "t6", /* 24 - 31 */
8844 "ft0", "ft1", "ft2", "ft3", "ft4", "ft5", "ft6", "ft7", /* 32 - 39 */
8845 "fs0", "fs1", /* 40 - 41 */
8846 "fa0", "fa1", "fa2", "fa3", "fa4", "fa5", "fa6", "fa7", /* 42 - 49 */
8847 "fs2", "fs3", "fs4", "fs5", "fs6", "fs7", "fs8", "fs9", /* 50 - 57 */
8848 "fs10", "fs11", /* 58 - 59 */
8849 "ft8", "ft9", "ft10", "ft11", /* 60 - 63 */
8850 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 64 - 71 */
8851 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 72 - 79 */
8852 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 80 - 87 */
8853 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 88 - 95 */
8854 "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", /* 96 - 103 */
8855 "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15", /* 104 - 111 */
8856 "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23", /* 112 - 119 */
8857 "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31", /* 120 - 127 */
8860 /* A RISC-V replacement for REGNAME_INTERNAL_BY_TABLE_ONLY which handles
8861 the large number of CSRs. */
8864 regname_internal_riscv (unsigned int regno
)
8866 const char *name
= NULL
;
8868 /* Lookup in the table first, this covers GPR and FPR. */
8869 if (regno
< ARRAY_SIZE (dwarf_regnames_riscv
))
8870 name
= dwarf_regnames_riscv
[regno
];
8871 else if (regno
>= 4096 && regno
<= 8191)
8873 /* This might be a CSR, these live in a sparse number space from 4096
8874 to 8191 These numbers are defined in the RISC-V ELF ABI
8878 #define DECLARE_CSR(NAME,VALUE,CLASS,DEFINE_VER,ABORT_VER) \
8879 case VALUE + 4096: name = #NAME; break;
8880 #include "opcode/riscv-opc.h"
8885 static char csr_name
[10];
8886 snprintf (csr_name
, sizeof (csr_name
), "csr%d", (regno
- 4096));
8897 init_dwarf_regnames_riscv (void)
8899 dwarf_regnames
= NULL
;
8900 dwarf_regnames_count
= 8192;
8901 dwarf_regnames_lookup_func
= regname_internal_riscv
;
8905 init_dwarf_regnames_by_elf_machine_code (unsigned int e_machine
)
8907 dwarf_regnames_lookup_func
= NULL
;
8913 init_dwarf_regnames_i386 ();
8917 init_dwarf_regnames_iamcu ();
8923 init_dwarf_regnames_x86_64 ();
8927 init_dwarf_regnames_aarch64 ();
8931 init_dwarf_regnames_s390 ();
8935 init_dwarf_regnames_riscv ();
8943 /* Initialize the DWARF register name lookup state based on the
8944 architecture and specific machine type of a BFD. */
8947 init_dwarf_regnames_by_bfd_arch_and_mach (enum bfd_architecture arch
,
8950 dwarf_regnames_lookup_func
= NULL
;
8958 case bfd_mach_x86_64
:
8959 case bfd_mach_x86_64_intel_syntax
:
8960 case bfd_mach_x64_32
:
8961 case bfd_mach_x64_32_intel_syntax
:
8962 init_dwarf_regnames_x86_64 ();
8966 init_dwarf_regnames_i386 ();
8971 case bfd_arch_iamcu
:
8972 init_dwarf_regnames_iamcu ();
8975 case bfd_arch_aarch64
:
8976 init_dwarf_regnames_aarch64();
8980 init_dwarf_regnames_s390 ();
8983 case bfd_arch_riscv
:
8984 init_dwarf_regnames_riscv ();
8993 regname_internal_by_table_only (unsigned int regno
)
8995 if (dwarf_regnames
!= NULL
8996 && regno
< dwarf_regnames_count
8997 && dwarf_regnames
[regno
] != NULL
)
8998 return dwarf_regnames
[regno
];
9004 regname (unsigned int regno
, int name_only_p
)
9006 static char reg
[64];
9008 const char *name
= NULL
;
9010 if (dwarf_regnames_lookup_func
!= NULL
)
9011 name
= dwarf_regnames_lookup_func (regno
);
9017 snprintf (reg
, sizeof (reg
), "r%d (%s)", regno
, name
);
9020 snprintf (reg
, sizeof (reg
), "r%d", regno
);
9025 frame_display_row (Frame_Chunk
*fc
, int *need_col_headers
, unsigned int *max_regs
)
9030 if (*max_regs
!= fc
->ncols
)
9031 *max_regs
= fc
->ncols
;
9033 if (*need_col_headers
)
9035 *need_col_headers
= 0;
9037 printf ("%-*s CFA ", eh_addr_size
* 2, " LOC");
9039 for (r
= 0; r
< *max_regs
; r
++)
9040 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
9045 printf ("%-5s ", regname (r
, 1));
9051 print_hex (fc
->pc_begin
, eh_addr_size
);
9053 strcpy (tmp
, "exp");
9055 sprintf (tmp
, "%s%+d", regname (fc
->cfa_reg
, 1), (int) fc
->cfa_offset
);
9056 printf ("%-8s ", tmp
);
9058 for (r
= 0; r
< fc
->ncols
; r
++)
9060 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
9062 switch (fc
->col_type
[r
])
9064 case DW_CFA_undefined
:
9067 case DW_CFA_same_value
:
9071 sprintf (tmp
, "c%+" PRId64
, fc
->col_offset
[r
]);
9073 case DW_CFA_val_offset
:
9074 sprintf (tmp
, "v%+" PRId64
, fc
->col_offset
[r
]);
9076 case DW_CFA_register
:
9077 sprintf (tmp
, "%s", regname (fc
->col_offset
[r
], 0));
9079 case DW_CFA_expression
:
9080 strcpy (tmp
, "exp");
9082 case DW_CFA_val_expression
:
9083 strcpy (tmp
, "vexp");
9086 strcpy (tmp
, "n/a");
9089 printf ("%-5s ", tmp
);
9095 #define GET(VAR, N) SAFE_BYTE_GET_AND_INC (VAR, start, N, end)
9097 static unsigned char *
9098 read_cie (unsigned char *start
, unsigned char *end
,
9099 Frame_Chunk
**p_cie
, int *p_version
,
9100 uint64_t *p_aug_len
, unsigned char **p_aug
)
9104 unsigned char *augmentation_data
= NULL
;
9105 uint64_t augmentation_data_len
= 0;
9108 /* PR 17512: file: 001-228113-0.004. */
9112 fc
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
9113 memset (fc
, 0, sizeof (Frame_Chunk
));
9115 fc
->col_type
= xmalloc (sizeof (*fc
->col_type
));
9116 fc
->col_offset
= xmalloc (sizeof (*fc
->col_offset
));
9120 fc
->augmentation
= (char *) start
;
9121 /* PR 17512: file: 001-228113-0.004.
9122 Skip past augmentation name, but avoid running off the end of the data. */
9124 if (* start
++ == '\0')
9128 warn (_("No terminator for augmentation name\n"));
9132 if (strcmp (fc
->augmentation
, "eh") == 0)
9134 if (eh_addr_size
> (size_t) (end
- start
))
9136 start
+= eh_addr_size
;
9141 if (2 > (size_t) (end
- start
))
9143 GET (fc
->ptr_size
, 1);
9144 if (fc
->ptr_size
< 1 || fc
->ptr_size
> 8)
9146 warn (_("Invalid pointer size (%d) in CIE data\n"), fc
->ptr_size
);
9150 GET (fc
->segment_size
, 1);
9151 /* PR 17512: file: e99d2804. */
9152 if (fc
->segment_size
> 8 || fc
->segment_size
+ fc
->ptr_size
> 8)
9154 warn (_("Invalid segment size (%d) in CIE data\n"), fc
->segment_size
);
9158 eh_addr_size
= fc
->ptr_size
;
9162 fc
->ptr_size
= eh_addr_size
;
9163 fc
->segment_size
= 0;
9166 READ_ULEB (fc
->code_factor
, start
, end
);
9167 READ_SLEB (fc
->data_factor
, start
, end
);
9178 READ_ULEB (fc
->ra
, start
, end
);
9181 if (fc
->augmentation
[0] == 'z')
9185 READ_ULEB (augmentation_data_len
, start
, end
);
9186 augmentation_data
= start
;
9187 /* PR 17512: file: 11042-2589-0.004. */
9188 if (augmentation_data_len
> (size_t) (end
- start
))
9190 warn (_("Augmentation data too long: %#" PRIx64
9191 ", expected at most %#tx\n"),
9192 augmentation_data_len
, end
- start
);
9195 start
+= augmentation_data_len
;
9198 if (augmentation_data_len
)
9202 unsigned char *qend
;
9204 p
= (unsigned char *) fc
->augmentation
+ 1;
9205 q
= augmentation_data
;
9206 qend
= q
+ augmentation_data_len
;
9208 while (p
< end
&& q
< qend
)
9213 q
+= 1 + size_of_encoded_value (*q
);
9215 fc
->fde_encoding
= *q
++;
9224 /* Note - it is OK if this loop terminates with q < qend.
9225 Padding may have been inserted to align the end of the CIE. */
9230 *p_version
= version
;
9233 *p_aug_len
= augmentation_data_len
;
9234 *p_aug
= augmentation_data
;
9239 free (fc
->col_offset
);
9240 free (fc
->col_type
);
9245 /* Prints out the contents on the DATA array formatted as unsigned bytes.
9246 If do_wide is not enabled, then formats the output to fit into 80 columns.
9247 PRINTED contains the number of characters already written to the current
9251 display_data (size_t printed
, const unsigned char *data
, size_t len
)
9253 if (do_wide
|| len
< ((80 - printed
) / 3))
9254 for (printed
= 0; printed
< len
; ++printed
)
9255 printf (" %02x", data
[printed
]);
9258 for (printed
= 0; printed
< len
; ++printed
)
9260 if (printed
% (80 / 3) == 0)
9262 printf (" %02x", data
[printed
]);
9267 /* Prints out the contents on the augmentation data array.
9268 If do_wide is not enabled, then formats the output to fit into 80 columns. */
9271 display_augmentation_data (const unsigned char * data
, uint64_t len
)
9275 i
= printf (_(" Augmentation data: "));
9276 display_data (i
, data
, len
);
9280 display_debug_frames (struct dwarf_section
*section
,
9281 void *file ATTRIBUTE_UNUSED
)
9283 unsigned char *start
= section
->start
;
9284 unsigned char *end
= start
+ section
->size
;
9285 unsigned char *section_start
= start
;
9286 Frame_Chunk
*chunks
= NULL
, *forward_refs
= NULL
;
9287 Frame_Chunk
*remembered_state
= NULL
;
9289 bool is_eh
= strcmp (section
->name
, ".eh_frame") == 0;
9290 unsigned int max_regs
= 0;
9291 const char *bad_reg
= _("bad register: ");
9292 unsigned int saved_eh_addr_size
= eh_addr_size
;
9294 introduce (section
, false);
9298 unsigned char *saved_start
;
9299 unsigned char *block_end
;
9304 int need_col_headers
= 1;
9305 unsigned char *augmentation_data
= NULL
;
9306 uint64_t augmentation_data_len
= 0;
9307 unsigned int encoded_ptr_size
= saved_eh_addr_size
;
9308 unsigned int offset_size
;
9310 static Frame_Chunk fde_fc
;
9312 saved_start
= start
;
9314 SAFE_BYTE_GET_AND_INC (length
, start
, 4, end
);
9318 printf ("\n%08tx ZERO terminator\n\n",
9319 saved_start
- section_start
);
9320 /* Skip any zero terminators that directly follow.
9321 A corrupt section size could have loaded a whole
9322 slew of zero filled memory bytes. eg
9323 PR 17512: file: 070-19381-0.004. */
9324 while (start
< end
&& * start
== 0)
9329 if (length
== 0xffffffff)
9331 SAFE_BYTE_GET_AND_INC (length
, start
, 8, end
);
9337 if (length
> (size_t) (end
- start
))
9339 warn ("Invalid length %#" PRIx64
" in FDE at %#tx\n",
9340 length
, saved_start
- section_start
);
9344 block_end
= start
+ length
;
9346 SAFE_BYTE_GET_AND_INC (cie_id
, start
, offset_size
, block_end
);
9348 if (is_eh
? (cie_id
== 0) : ((offset_size
== 4 && cie_id
== DW_CIE_ID
)
9349 || (offset_size
== 8 && cie_id
== DW64_CIE_ID
)))
9354 start
= read_cie (start
, block_end
, &cie
, &version
,
9355 &augmentation_data_len
, &augmentation_data
);
9356 /* PR 17512: file: 027-135133-0.005. */
9363 fc
->chunk_start
= saved_start
;
9364 mreg
= max_regs
> 0 ? max_regs
- 1 : 0;
9367 if (frame_need_space (fc
, mreg
) < 0)
9369 if (fc
->fde_encoding
)
9370 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
9372 printf ("\n%08tx ", saved_start
- section_start
);
9373 print_hex (length
, fc
->ptr_size
);
9374 print_hex (cie_id
, offset_size
);
9376 if (do_debug_frames_interp
)
9378 printf ("CIE \"%s\" cf=%d df=%d ra=%d\n", fc
->augmentation
,
9379 fc
->code_factor
, fc
->data_factor
, fc
->ra
);
9384 printf (" Version: %d\n", version
);
9385 printf (" Augmentation: \"%s\"\n", fc
->augmentation
);
9388 printf (" Pointer Size: %u\n", fc
->ptr_size
);
9389 printf (" Segment Size: %u\n", fc
->segment_size
);
9391 printf (" Code alignment factor: %u\n", fc
->code_factor
);
9392 printf (" Data alignment factor: %d\n", fc
->data_factor
);
9393 printf (" Return address column: %d\n", fc
->ra
);
9395 if (augmentation_data_len
)
9396 display_augmentation_data (augmentation_data
, augmentation_data_len
);
9403 unsigned char *look_for
;
9404 unsigned long segment_selector
;
9410 uint64_t sign
= (uint64_t) 1 << (offset_size
* 8 - 1);
9411 cie_off
= (cie_off
^ sign
) - sign
;
9412 cie_off
= start
- 4 - section_start
- cie_off
;
9415 look_for
= section_start
+ cie_off
;
9416 if (cie_off
<= (size_t) (saved_start
- section_start
))
9418 for (cie
= chunks
; cie
; cie
= cie
->next
)
9419 if (cie
->chunk_start
== look_for
)
9422 else if (cie_off
>= section
->size
)
9426 for (cie
= forward_refs
; cie
; cie
= cie
->next
)
9427 if (cie
->chunk_start
== look_for
)
9431 unsigned int off_size
;
9432 unsigned char *cie_scan
;
9434 cie_scan
= look_for
;
9436 SAFE_BYTE_GET_AND_INC (length
, cie_scan
, 4, end
);
9437 if (length
== 0xffffffff)
9439 SAFE_BYTE_GET_AND_INC (length
, cie_scan
, 8, end
);
9442 if (length
!= 0 && length
<= (size_t) (end
- cie_scan
))
9445 unsigned char *cie_end
= cie_scan
+ length
;
9447 SAFE_BYTE_GET_AND_INC (c_id
, cie_scan
, off_size
,
9451 : ((off_size
== 4 && c_id
== DW_CIE_ID
)
9452 || (off_size
== 8 && c_id
== DW64_CIE_ID
)))
9457 read_cie (cie_scan
, cie_end
, &cie
, &version
,
9458 &augmentation_data_len
, &augmentation_data
);
9459 /* PR 17512: file: 3450-2098-0.004. */
9462 warn (_("Failed to read CIE information\n"));
9465 cie
->next
= forward_refs
;
9467 cie
->chunk_start
= look_for
;
9468 mreg
= max_regs
> 0 ? max_regs
- 1 : 0;
9471 if (frame_need_space (cie
, mreg
) < 0)
9473 warn (_("Invalid max register\n"));
9476 if (cie
->fde_encoding
)
9478 = size_of_encoded_value (cie
->fde_encoding
);
9485 memset (fc
, 0, sizeof (Frame_Chunk
));
9490 fc
->col_type
= xmalloc (sizeof (*fc
->col_type
));
9491 fc
->col_offset
= xmalloc (sizeof (*fc
->col_offset
));
9492 if (frame_need_space (fc
, max_regs
> 0 ? max_regs
- 1 : 0) < 0)
9494 warn (_("Invalid max register\n"));
9498 fc
->augmentation
= "";
9499 fc
->fde_encoding
= 0;
9500 fc
->ptr_size
= eh_addr_size
;
9501 fc
->segment_size
= 0;
9505 fc
->ncols
= cie
->ncols
;
9506 fc
->col_type
= xcmalloc (fc
->ncols
, sizeof (*fc
->col_type
));
9507 fc
->col_offset
= xcmalloc (fc
->ncols
, sizeof (*fc
->col_offset
));
9508 memcpy (fc
->col_type
, cie
->col_type
,
9509 fc
->ncols
* sizeof (*fc
->col_type
));
9510 memcpy (fc
->col_offset
, cie
->col_offset
,
9511 fc
->ncols
* sizeof (*fc
->col_offset
));
9512 fc
->augmentation
= cie
->augmentation
;
9513 fc
->ptr_size
= cie
->ptr_size
;
9514 eh_addr_size
= cie
->ptr_size
;
9515 fc
->segment_size
= cie
->segment_size
;
9516 fc
->code_factor
= cie
->code_factor
;
9517 fc
->data_factor
= cie
->data_factor
;
9518 fc
->cfa_reg
= cie
->cfa_reg
;
9519 fc
->cfa_offset
= cie
->cfa_offset
;
9521 if (frame_need_space (fc
, max_regs
> 0 ? max_regs
- 1: 0) < 0)
9523 warn (_("Invalid max register\n"));
9526 fc
->fde_encoding
= cie
->fde_encoding
;
9529 if (fc
->fde_encoding
)
9530 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
9532 segment_selector
= 0;
9533 if (fc
->segment_size
)
9535 if (fc
->segment_size
> sizeof (segment_selector
))
9537 /* PR 17512: file: 9e196b3e. */
9538 warn (_("Probably corrupt segment size: %d - using 4 instead\n"), fc
->segment_size
);
9539 fc
->segment_size
= 4;
9541 SAFE_BYTE_GET_AND_INC (segment_selector
, start
,
9542 fc
->segment_size
, block_end
);
9545 fc
->pc_begin
= get_encoded_value (&start
, fc
->fde_encoding
, section
,
9548 /* FIXME: It appears that sometimes the final pc_range value is
9549 encoded in less than encoded_ptr_size bytes. See the x86_64
9550 run of the "objcopy on compressed debug sections" test for an
9552 SAFE_BYTE_GET_AND_INC (fc
->pc_range
, start
, encoded_ptr_size
,
9555 if (cie
->augmentation
[0] == 'z')
9557 READ_ULEB (augmentation_data_len
, start
, block_end
);
9558 augmentation_data
= start
;
9559 /* PR 17512 file: 722-8446-0.004 and PR 22386. */
9560 if (augmentation_data_len
> (size_t) (block_end
- start
))
9562 warn (_("Augmentation data too long: %#" PRIx64
", "
9563 "expected at most %#tx\n"),
9564 augmentation_data_len
, block_end
- start
);
9566 augmentation_data
= NULL
;
9567 augmentation_data_len
= 0;
9569 start
+= augmentation_data_len
;
9572 printf ("\n%08tx ", saved_start
- section_start
);
9573 print_hex (length
, fc
->ptr_size
);
9574 print_hex (cie_id
, offset_size
);
9577 if (cie
->chunk_start
)
9578 printf ("cie=%08tx", cie
->chunk_start
- section_start
);
9580 /* Ideally translate "invalid " to 8 chars, trailing space
9582 printf (_("cie=invalid "));
9585 if (fc
->segment_size
)
9586 printf ("%04lx:", segment_selector
);
9588 print_hex_ns (fc
->pc_begin
, fc
->ptr_size
);
9590 print_hex_ns (fc
->pc_begin
+ fc
->pc_range
, fc
->ptr_size
);
9593 if (! do_debug_frames_interp
&& augmentation_data_len
)
9595 display_augmentation_data (augmentation_data
, augmentation_data_len
);
9600 /* At this point, fc is the current chunk, cie (if any) is set, and
9601 we're about to interpret instructions for the chunk. */
9602 /* ??? At present we need to do this always, since this sizes the
9603 fc->col_type and fc->col_offset arrays, which we write into always.
9604 We should probably split the interpreted and non-interpreted bits
9605 into two different routines, since there's so much that doesn't
9606 really overlap between them. */
9607 if (1 || do_debug_frames_interp
)
9609 /* Start by making a pass over the chunk, allocating storage
9610 and taking note of what registers are used. */
9611 unsigned char *tmp
= start
;
9613 while (start
< block_end
)
9615 unsigned int reg
, op
, opa
;
9623 /* Warning: if you add any more cases to this switch, be
9624 sure to add them to the corresponding switch below. */
9628 case DW_CFA_advance_loc
:
9631 SKIP_ULEB (start
, block_end
);
9634 case DW_CFA_restore
:
9637 case DW_CFA_set_loc
:
9638 if ((size_t) (block_end
- start
) < encoded_ptr_size
)
9641 start
+= encoded_ptr_size
;
9643 case DW_CFA_advance_loc1
:
9644 if ((size_t) (block_end
- start
) < 1)
9649 case DW_CFA_advance_loc2
:
9650 if ((size_t) (block_end
- start
) < 2)
9655 case DW_CFA_advance_loc4
:
9656 if ((size_t) (block_end
- start
) < 4)
9661 case DW_CFA_offset_extended
:
9662 case DW_CFA_val_offset
:
9663 READ_ULEB (reg
, start
, block_end
);
9664 SKIP_ULEB (start
, block_end
);
9666 case DW_CFA_restore_extended
:
9667 READ_ULEB (reg
, start
, block_end
);
9669 case DW_CFA_undefined
:
9670 READ_ULEB (reg
, start
, block_end
);
9672 case DW_CFA_same_value
:
9673 READ_ULEB (reg
, start
, block_end
);
9675 case DW_CFA_register
:
9676 READ_ULEB (reg
, start
, block_end
);
9677 SKIP_ULEB (start
, block_end
);
9679 case DW_CFA_def_cfa
:
9680 SKIP_ULEB (start
, block_end
);
9681 SKIP_ULEB (start
, block_end
);
9683 case DW_CFA_def_cfa_register
:
9684 SKIP_ULEB (start
, block_end
);
9686 case DW_CFA_def_cfa_offset
:
9687 SKIP_ULEB (start
, block_end
);
9689 case DW_CFA_def_cfa_expression
:
9690 READ_ULEB (temp
, start
, block_end
);
9691 if ((size_t) (block_end
- start
) < temp
)
9696 case DW_CFA_expression
:
9697 case DW_CFA_val_expression
:
9698 READ_ULEB (reg
, start
, block_end
);
9699 READ_ULEB (temp
, start
, block_end
);
9700 if ((size_t) (block_end
- start
) < temp
)
9705 case DW_CFA_offset_extended_sf
:
9706 case DW_CFA_val_offset_sf
:
9707 READ_ULEB (reg
, start
, block_end
);
9708 SKIP_SLEB (start
, block_end
);
9710 case DW_CFA_def_cfa_sf
:
9711 SKIP_ULEB (start
, block_end
);
9712 SKIP_SLEB (start
, block_end
);
9714 case DW_CFA_def_cfa_offset_sf
:
9715 SKIP_SLEB (start
, block_end
);
9717 case DW_CFA_MIPS_advance_loc8
:
9718 if ((size_t) (block_end
- start
) < 8)
9723 case DW_CFA_GNU_args_size
:
9724 SKIP_ULEB (start
, block_end
);
9726 case DW_CFA_GNU_negative_offset_extended
:
9727 READ_ULEB (reg
, start
, block_end
);
9728 SKIP_ULEB (start
, block_end
);
9733 if (reg
!= -1u && frame_need_space (fc
, reg
) >= 0)
9735 /* Don't leave any reg as DW_CFA_unreferenced so
9736 that frame_display_row prints name of regs in
9737 header, and all referenced regs in each line. */
9738 if (reg
>= cie
->ncols
9739 || cie
->col_type
[reg
] == DW_CFA_unreferenced
)
9740 fc
->col_type
[reg
] = DW_CFA_undefined
;
9742 fc
->col_type
[reg
] = cie
->col_type
[reg
];
9750 /* Now we know what registers are used, make a second pass over
9751 the chunk, this time actually printing out the info. */
9753 while (start
< block_end
)
9756 /* Note: It is tempting to use an unsigned long for 'reg' but there
9757 are various functions, notably frame_space_needed() that assume that
9758 reg is an unsigned int. */
9762 const char *reg_prefix
= "";
9769 /* Make a note if something other than DW_CFA_nop happens. */
9770 if (op
!= DW_CFA_nop
)
9773 /* Warning: if you add any more cases to this switch, be
9774 sure to add them to the corresponding switch above. */
9777 case DW_CFA_advance_loc
:
9778 opa
*= fc
->code_factor
;
9779 if (do_debug_frames_interp
)
9780 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9783 printf (" DW_CFA_advance_loc: %d to ", opa
);
9784 print_hex_ns (fc
->pc_begin
+ opa
, fc
->ptr_size
);
9787 fc
->pc_begin
+= opa
;
9791 READ_ULEB (ofs
, start
, block_end
);
9792 ofs
*= fc
->data_factor
;
9793 if (opa
>= fc
->ncols
)
9794 reg_prefix
= bad_reg
;
9795 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9796 printf (" DW_CFA_offset: %s%s at cfa%+" PRId64
"\n",
9797 reg_prefix
, regname (opa
, 0), ofs
);
9798 if (*reg_prefix
== '\0')
9800 fc
->col_type
[opa
] = DW_CFA_offset
;
9801 fc
->col_offset
[opa
] = ofs
;
9805 case DW_CFA_restore
:
9806 if (opa
>= fc
->ncols
)
9807 reg_prefix
= bad_reg
;
9808 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9809 printf (" DW_CFA_restore: %s%s\n",
9810 reg_prefix
, regname (opa
, 0));
9811 if (*reg_prefix
!= '\0')
9814 if (opa
>= cie
->ncols
9815 || cie
->col_type
[opa
] == DW_CFA_unreferenced
)
9817 fc
->col_type
[opa
] = DW_CFA_undefined
;
9818 fc
->col_offset
[opa
] = 0;
9822 fc
->col_type
[opa
] = cie
->col_type
[opa
];
9823 fc
->col_offset
[opa
] = cie
->col_offset
[opa
];
9827 case DW_CFA_set_loc
:
9828 ofs
= get_encoded_value (&start
, fc
->fde_encoding
, section
,
9830 if (do_debug_frames_interp
)
9831 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9834 printf (" DW_CFA_set_loc: ");
9835 print_hex_ns (ofs
, fc
->ptr_size
);
9841 case DW_CFA_advance_loc1
:
9842 SAFE_BYTE_GET_AND_INC (ofs
, start
, 1, 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_loc1: %" PRId64
" to ", ofs
);
9849 print_hex_ns (fc
->pc_begin
+ ofs
, fc
->ptr_size
);
9852 fc
->pc_begin
+= ofs
;
9855 case DW_CFA_advance_loc2
:
9856 SAFE_BYTE_GET_AND_INC (ofs
, start
, 2, 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_loc2: %" PRId64
" to ", ofs
);
9863 print_hex_ns (fc
->pc_begin
+ ofs
, fc
->ptr_size
);
9866 fc
->pc_begin
+= ofs
;
9869 case DW_CFA_advance_loc4
:
9870 SAFE_BYTE_GET_AND_INC (ofs
, start
, 4, block_end
);
9871 ofs
*= fc
->code_factor
;
9872 if (do_debug_frames_interp
)
9873 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9876 printf (" DW_CFA_advance_loc4: %" PRId64
" to ", ofs
);
9877 print_hex_ns (fc
->pc_begin
+ ofs
, fc
->ptr_size
);
9880 fc
->pc_begin
+= ofs
;
9883 case DW_CFA_offset_extended
:
9884 READ_ULEB (reg
, start
, block_end
);
9885 READ_ULEB (ofs
, start
, block_end
);
9886 ofs
*= fc
->data_factor
;
9887 if (reg
>= fc
->ncols
)
9888 reg_prefix
= bad_reg
;
9889 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9890 printf (" DW_CFA_offset_extended: %s%s at cfa%+" PRId64
"\n",
9891 reg_prefix
, regname (reg
, 0), ofs
);
9892 if (*reg_prefix
== '\0')
9894 fc
->col_type
[reg
] = DW_CFA_offset
;
9895 fc
->col_offset
[reg
] = ofs
;
9899 case DW_CFA_val_offset
:
9900 READ_ULEB (reg
, start
, block_end
);
9901 READ_ULEB (ofs
, start
, block_end
);
9902 ofs
*= fc
->data_factor
;
9903 if (reg
>= fc
->ncols
)
9904 reg_prefix
= bad_reg
;
9905 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9906 printf (" DW_CFA_val_offset: %s%s is cfa%+" PRId64
"\n",
9907 reg_prefix
, regname (reg
, 0), ofs
);
9908 if (*reg_prefix
== '\0')
9910 fc
->col_type
[reg
] = DW_CFA_val_offset
;
9911 fc
->col_offset
[reg
] = ofs
;
9915 case DW_CFA_restore_extended
:
9916 READ_ULEB (reg
, start
, block_end
);
9917 if (reg
>= fc
->ncols
)
9918 reg_prefix
= bad_reg
;
9919 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9920 printf (" DW_CFA_restore_extended: %s%s\n",
9921 reg_prefix
, regname (reg
, 0));
9922 if (*reg_prefix
!= '\0')
9925 if (reg
>= cie
->ncols
9926 || cie
->col_type
[reg
] == DW_CFA_unreferenced
)
9928 fc
->col_type
[reg
] = DW_CFA_undefined
;
9929 fc
->col_offset
[reg
] = 0;
9933 fc
->col_type
[reg
] = cie
->col_type
[reg
];
9934 fc
->col_offset
[reg
] = cie
->col_offset
[reg
];
9938 case DW_CFA_undefined
:
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_undefined: %s%s\n",
9944 reg_prefix
, regname (reg
, 0));
9945 if (*reg_prefix
== '\0')
9947 fc
->col_type
[reg
] = DW_CFA_undefined
;
9948 fc
->col_offset
[reg
] = 0;
9952 case DW_CFA_same_value
:
9953 READ_ULEB (reg
, start
, block_end
);
9954 if (reg
>= fc
->ncols
)
9955 reg_prefix
= bad_reg
;
9956 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9957 printf (" DW_CFA_same_value: %s%s\n",
9958 reg_prefix
, regname (reg
, 0));
9959 if (*reg_prefix
== '\0')
9961 fc
->col_type
[reg
] = DW_CFA_same_value
;
9962 fc
->col_offset
[reg
] = 0;
9966 case DW_CFA_register
:
9967 READ_ULEB (reg
, start
, block_end
);
9968 READ_ULEB (ofs
, start
, block_end
);
9969 if (reg
>= fc
->ncols
)
9970 reg_prefix
= bad_reg
;
9971 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9973 printf (" DW_CFA_register: %s%s in ",
9974 reg_prefix
, regname (reg
, 0));
9975 puts (regname (ofs
, 0));
9977 if (*reg_prefix
== '\0')
9979 fc
->col_type
[reg
] = DW_CFA_register
;
9980 fc
->col_offset
[reg
] = ofs
;
9984 case DW_CFA_remember_state
:
9985 if (! do_debug_frames_interp
)
9986 printf (" DW_CFA_remember_state\n");
9987 rs
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
9988 rs
->cfa_offset
= fc
->cfa_offset
;
9989 rs
->cfa_reg
= fc
->cfa_reg
;
9991 rs
->cfa_exp
= fc
->cfa_exp
;
9992 rs
->ncols
= fc
->ncols
;
9993 rs
->col_type
= xcmalloc (rs
->ncols
, sizeof (*rs
->col_type
));
9994 rs
->col_offset
= xcmalloc (rs
->ncols
, sizeof (*rs
->col_offset
));
9995 memcpy (rs
->col_type
, fc
->col_type
,
9996 rs
->ncols
* sizeof (*fc
->col_type
));
9997 memcpy (rs
->col_offset
, fc
->col_offset
,
9998 rs
->ncols
* sizeof (*fc
->col_offset
));
9999 rs
->next
= remembered_state
;
10000 remembered_state
= rs
;
10003 case DW_CFA_restore_state
:
10004 if (! do_debug_frames_interp
)
10005 printf (" DW_CFA_restore_state\n");
10006 rs
= remembered_state
;
10009 remembered_state
= rs
->next
;
10010 fc
->cfa_offset
= rs
->cfa_offset
;
10011 fc
->cfa_reg
= rs
->cfa_reg
;
10013 fc
->cfa_exp
= rs
->cfa_exp
;
10014 if (frame_need_space (fc
, rs
->ncols
- 1) < 0)
10016 warn (_("Invalid column number in saved frame state\n"));
10021 memcpy (fc
->col_type
, rs
->col_type
,
10022 rs
->ncols
* sizeof (*rs
->col_type
));
10023 memcpy (fc
->col_offset
, rs
->col_offset
,
10024 rs
->ncols
* sizeof (*rs
->col_offset
));
10026 free (rs
->col_type
);
10027 free (rs
->col_offset
);
10030 else if (do_debug_frames_interp
)
10031 printf ("Mismatched DW_CFA_restore_state\n");
10034 case DW_CFA_def_cfa
:
10035 READ_ULEB (fc
->cfa_reg
, start
, block_end
);
10036 READ_ULEB (fc
->cfa_offset
, start
, block_end
);
10038 if (! do_debug_frames_interp
)
10039 printf (" DW_CFA_def_cfa: %s ofs %d\n",
10040 regname (fc
->cfa_reg
, 0), (int) fc
->cfa_offset
);
10043 case DW_CFA_def_cfa_register
:
10044 READ_ULEB (fc
->cfa_reg
, start
, block_end
);
10046 if (! do_debug_frames_interp
)
10047 printf (" DW_CFA_def_cfa_register: %s\n",
10048 regname (fc
->cfa_reg
, 0));
10051 case DW_CFA_def_cfa_offset
:
10052 READ_ULEB (fc
->cfa_offset
, start
, block_end
);
10053 if (! do_debug_frames_interp
)
10054 printf (" DW_CFA_def_cfa_offset: %d\n", (int) fc
->cfa_offset
);
10058 if (! do_debug_frames_interp
)
10059 printf (" DW_CFA_nop\n");
10062 case DW_CFA_def_cfa_expression
:
10063 READ_ULEB (ofs
, start
, block_end
);
10064 if (ofs
> (size_t) (block_end
- start
))
10066 printf (_(" %s: <corrupt len %" PRIu64
">\n"),
10067 "DW_CFA_def_cfa_expression", ofs
);
10070 if (! do_debug_frames_interp
)
10072 printf (" DW_CFA_def_cfa_expression (");
10073 decode_location_expression (start
, eh_addr_size
, 0, -1,
10081 case DW_CFA_expression
:
10082 READ_ULEB (reg
, start
, block_end
);
10083 READ_ULEB (ofs
, start
, block_end
);
10084 if (reg
>= fc
->ncols
)
10085 reg_prefix
= bad_reg
;
10086 /* PR 17512: file: 069-133014-0.006. */
10087 /* PR 17512: file: 98c02eb4. */
10088 if (ofs
> (size_t) (block_end
- start
))
10090 printf (_(" %s: <corrupt len %" PRIu64
">\n"),
10091 "DW_CFA_expression", ofs
);
10094 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
10096 printf (" DW_CFA_expression: %s%s (",
10097 reg_prefix
, regname (reg
, 0));
10098 decode_location_expression (start
, eh_addr_size
, 0, -1,
10102 if (*reg_prefix
== '\0')
10103 fc
->col_type
[reg
] = DW_CFA_expression
;
10107 case DW_CFA_val_expression
:
10108 READ_ULEB (reg
, start
, block_end
);
10109 READ_ULEB (ofs
, start
, block_end
);
10110 if (reg
>= fc
->ncols
)
10111 reg_prefix
= bad_reg
;
10112 if (ofs
> (size_t) (block_end
- start
))
10114 printf (" %s: <corrupt len %" PRIu64
">\n",
10115 "DW_CFA_val_expression", ofs
);
10118 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
10120 printf (" DW_CFA_val_expression: %s%s (",
10121 reg_prefix
, regname (reg
, 0));
10122 decode_location_expression (start
, eh_addr_size
, 0, -1,
10126 if (*reg_prefix
== '\0')
10127 fc
->col_type
[reg
] = DW_CFA_val_expression
;
10131 case DW_CFA_offset_extended_sf
:
10132 READ_ULEB (reg
, start
, block_end
);
10133 READ_SLEB (sofs
, start
, block_end
);
10134 /* data_factor multiplicaton done here as unsigned to
10135 avoid integer overflow warnings from asan on fuzzed
10138 ofs
*= fc
->data_factor
;
10139 if (reg
>= fc
->ncols
)
10140 reg_prefix
= bad_reg
;
10141 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
10142 printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+" PRId64
"\n",
10143 reg_prefix
, regname (reg
, 0), ofs
);
10144 if (*reg_prefix
== '\0')
10146 fc
->col_type
[reg
] = DW_CFA_offset
;
10147 fc
->col_offset
[reg
] = ofs
;
10151 case DW_CFA_val_offset_sf
:
10152 READ_ULEB (reg
, start
, block_end
);
10153 READ_SLEB (sofs
, start
, block_end
);
10155 ofs
*= fc
->data_factor
;
10156 if (reg
>= fc
->ncols
)
10157 reg_prefix
= bad_reg
;
10158 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
10159 printf (" DW_CFA_val_offset_sf: %s%s is cfa%+" PRId64
"\n",
10160 reg_prefix
, regname (reg
, 0), ofs
);
10161 if (*reg_prefix
== '\0')
10163 fc
->col_type
[reg
] = DW_CFA_val_offset
;
10164 fc
->col_offset
[reg
] = ofs
;
10168 case DW_CFA_def_cfa_sf
:
10169 READ_ULEB (fc
->cfa_reg
, start
, block_end
);
10170 READ_SLEB (sofs
, start
, block_end
);
10172 ofs
*= fc
->data_factor
;
10173 fc
->cfa_offset
= ofs
;
10175 if (! do_debug_frames_interp
)
10176 printf (" DW_CFA_def_cfa_sf: %s ofs %" PRId64
"\n",
10177 regname (fc
->cfa_reg
, 0), ofs
);
10180 case DW_CFA_def_cfa_offset_sf
:
10181 READ_SLEB (sofs
, start
, block_end
);
10183 ofs
*= fc
->data_factor
;
10184 fc
->cfa_offset
= ofs
;
10185 if (! do_debug_frames_interp
)
10186 printf (" DW_CFA_def_cfa_offset_sf: %" PRId64
"\n", ofs
);
10189 case DW_CFA_MIPS_advance_loc8
:
10190 SAFE_BYTE_GET_AND_INC (ofs
, start
, 8, block_end
);
10191 ofs
*= fc
->code_factor
;
10192 if (do_debug_frames_interp
)
10193 frame_display_row (fc
, &need_col_headers
, &max_regs
);
10196 printf (" DW_CFA_MIPS_advance_loc8: %" PRId64
" to ", ofs
);
10197 print_hex_ns (fc
->pc_begin
+ ofs
, fc
->ptr_size
);
10200 fc
->pc_begin
+= ofs
;
10203 case DW_CFA_GNU_window_save
:
10204 if (! do_debug_frames_interp
)
10205 printf (" %s\n", DW_CFA_GNU_window_save_name
[is_aarch64
]);
10208 case DW_CFA_GNU_args_size
:
10209 READ_ULEB (ofs
, start
, block_end
);
10210 if (! do_debug_frames_interp
)
10211 printf (" DW_CFA_GNU_args_size: %" PRIu64
"\n", ofs
);
10214 case DW_CFA_GNU_negative_offset_extended
:
10215 READ_ULEB (reg
, start
, block_end
);
10216 READ_SLEB (sofs
, start
, block_end
);
10218 ofs
= -ofs
* fc
->data_factor
;
10219 if (reg
>= fc
->ncols
)
10220 reg_prefix
= bad_reg
;
10221 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
10222 printf (" DW_CFA_GNU_negative_offset_extended: %s%s "
10223 "at cfa%+" PRId64
"\n",
10224 reg_prefix
, regname (reg
, 0), ofs
);
10225 if (*reg_prefix
== '\0')
10227 fc
->col_type
[reg
] = DW_CFA_offset
;
10228 fc
->col_offset
[reg
] = ofs
;
10233 if (op
>= DW_CFA_lo_user
&& op
<= DW_CFA_hi_user
)
10234 printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op
);
10236 warn (_("Unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op
);
10241 /* Interpret the CFA - as long as it is not completely full of NOPs. */
10242 if (do_debug_frames_interp
&& ! all_nops
)
10243 frame_display_row (fc
, &need_col_headers
, &max_regs
);
10245 if (fde_fc
.col_type
!= NULL
)
10247 free (fde_fc
.col_type
);
10248 fde_fc
.col_type
= NULL
;
10250 if (fde_fc
.col_offset
!= NULL
)
10252 free (fde_fc
.col_offset
);
10253 fde_fc
.col_offset
= NULL
;
10257 eh_addr_size
= saved_eh_addr_size
;
10262 while (remembered_state
!= NULL
)
10264 rs
= remembered_state
;
10265 remembered_state
= rs
->next
;
10266 free (rs
->col_type
);
10267 free (rs
->col_offset
);
10268 rs
->next
= NULL
; /* Paranoia. */
10272 while (chunks
!= NULL
)
10276 free (rs
->col_type
);
10277 free (rs
->col_offset
);
10278 rs
->next
= NULL
; /* Paranoia. */
10282 while (forward_refs
!= NULL
)
10285 forward_refs
= rs
->next
;
10286 free (rs
->col_type
);
10287 free (rs
->col_offset
);
10288 rs
->next
= NULL
; /* Paranoia. */
10298 display_debug_names (struct dwarf_section
*section
, void *file
)
10300 unsigned char *hdrptr
= section
->start
;
10301 uint64_t unit_length
;
10302 unsigned char *unit_start
;
10303 const unsigned char *const section_end
= section
->start
+ section
->size
;
10304 unsigned char *unit_end
;
10306 introduce (section
, false);
10308 load_debug_section_with_follow (str
, file
);
10310 for (; hdrptr
< section_end
; hdrptr
= unit_end
)
10312 unsigned int offset_size
;
10313 uint16_t dwarf_version
, padding
;
10314 uint32_t comp_unit_count
, local_type_unit_count
, foreign_type_unit_count
;
10315 uint64_t bucket_count
, name_count
, abbrev_table_size
;
10316 uint32_t augmentation_string_size
;
10318 bool augmentation_printable
;
10319 const char *augmentation_string
;
10322 unit_start
= hdrptr
;
10324 /* Get and check the length of the block. */
10325 SAFE_BYTE_GET_AND_INC (unit_length
, hdrptr
, 4, section_end
);
10327 if (unit_length
== 0xffffffff)
10329 /* This section is 64-bit DWARF. */
10330 SAFE_BYTE_GET_AND_INC (unit_length
, hdrptr
, 8, section_end
);
10336 if (unit_length
> (size_t) (section_end
- hdrptr
)
10337 || unit_length
< 2 + 2 + 4 * 7)
10340 warn (_("Debug info is corrupted, %s header at %#tx"
10341 " has length %#" PRIx64
"\n"),
10342 section
->name
, unit_start
- section
->start
, unit_length
);
10345 unit_end
= hdrptr
+ unit_length
;
10347 /* Get and check the version number. */
10348 SAFE_BYTE_GET_AND_INC (dwarf_version
, hdrptr
, 2, unit_end
);
10349 printf (_("Version %d\n"), (int) dwarf_version
);
10351 /* Prior versions did not exist, and future versions may not be
10352 backwards compatible. */
10353 if (dwarf_version
!= 5)
10355 warn (_("Only DWARF version 5 .debug_names "
10356 "is currently supported.\n"));
10360 SAFE_BYTE_GET_AND_INC (padding
, hdrptr
, 2, unit_end
);
10362 warn (_("Padding field of .debug_names must be 0 (found 0x%x)\n"),
10365 SAFE_BYTE_GET_AND_INC (comp_unit_count
, hdrptr
, 4, unit_end
);
10366 if (comp_unit_count
== 0)
10367 warn (_("Compilation unit count must be >= 1 in .debug_names\n"));
10369 SAFE_BYTE_GET_AND_INC (local_type_unit_count
, hdrptr
, 4, unit_end
);
10370 SAFE_BYTE_GET_AND_INC (foreign_type_unit_count
, hdrptr
, 4, unit_end
);
10371 SAFE_BYTE_GET_AND_INC (bucket_count
, hdrptr
, 4, unit_end
);
10372 SAFE_BYTE_GET_AND_INC (name_count
, hdrptr
, 4, unit_end
);
10373 SAFE_BYTE_GET_AND_INC (abbrev_table_size
, hdrptr
, 4, unit_end
);
10375 SAFE_BYTE_GET_AND_INC (augmentation_string_size
, hdrptr
, 4, unit_end
);
10376 if (augmentation_string_size
% 4 != 0)
10378 warn (_("Augmentation string length %u must be rounded up "
10379 "to a multiple of 4 in .debug_names.\n"),
10380 augmentation_string_size
);
10381 augmentation_string_size
+= (-augmentation_string_size
) & 3;
10383 if (augmentation_string_size
> (size_t) (unit_end
- hdrptr
))
10386 printf (_("Augmentation string:"));
10388 augmentation_printable
= true;
10389 augmentation_string
= (const char *) hdrptr
;
10391 for (i
= 0; i
< augmentation_string_size
; i
++)
10395 SAFE_BYTE_GET_AND_INC (uc
, hdrptr
, 1, unit_end
);
10396 printf (" %02x", uc
);
10398 if (uc
!= 0 && !ISPRINT (uc
))
10399 augmentation_printable
= false;
10402 if (augmentation_printable
)
10406 i
< augmentation_string_size
&& augmentation_string
[i
];
10408 putchar (augmentation_string
[i
]);
10413 printf (_("CU table:\n"));
10414 if (_mul_overflow (comp_unit_count
, offset_size
, &total
)
10415 || total
> (size_t) (unit_end
- hdrptr
))
10417 for (i
= 0; i
< comp_unit_count
; i
++)
10419 uint64_t cu_offset
;
10421 SAFE_BYTE_GET_AND_INC (cu_offset
, hdrptr
, offset_size
, unit_end
);
10422 printf ("[%3u] %#" PRIx64
"\n", i
, cu_offset
);
10426 printf (_("TU table:\n"));
10427 if (_mul_overflow (local_type_unit_count
, offset_size
, &total
)
10428 || total
> (size_t) (unit_end
- hdrptr
))
10430 for (i
= 0; i
< local_type_unit_count
; i
++)
10432 uint64_t tu_offset
;
10434 SAFE_BYTE_GET_AND_INC (tu_offset
, hdrptr
, offset_size
, unit_end
);
10435 printf ("[%3u] %#" PRIx64
"\n", i
, tu_offset
);
10439 printf (_("Foreign TU table:\n"));
10440 if (_mul_overflow (foreign_type_unit_count
, 8, &total
)
10441 || total
> (size_t) (unit_end
- hdrptr
))
10443 for (i
= 0; i
< foreign_type_unit_count
; i
++)
10445 uint64_t signature
;
10447 SAFE_BYTE_GET_AND_INC (signature
, hdrptr
, 8, unit_end
);
10448 printf (_("[%3u] "), i
);
10449 print_hex_ns (signature
, 8);
10454 uint64_t xtra
= (bucket_count
* sizeof (uint32_t)
10455 + name_count
* (sizeof (uint32_t) + 2 * offset_size
)
10456 + abbrev_table_size
);
10457 if (xtra
> (size_t) (unit_end
- hdrptr
))
10459 warn (_("Entry pool offset (%#" PRIx64
") exceeds unit size %#tx "
10460 "for unit %#tx in the debug_names\n"),
10461 xtra
, unit_end
- unit_start
, unit_start
- section
->start
);
10464 const uint32_t *const hash_table_buckets
= (uint32_t *) hdrptr
;
10465 hdrptr
+= bucket_count
* sizeof (uint32_t);
10466 const uint32_t *const hash_table_hashes
= (uint32_t *) hdrptr
;
10467 hdrptr
+= name_count
* sizeof (uint32_t);
10468 unsigned char *const name_table_string_offsets
= hdrptr
;
10469 hdrptr
+= name_count
* offset_size
;
10470 unsigned char *const name_table_entry_offsets
= hdrptr
;
10471 hdrptr
+= name_count
* offset_size
;
10472 unsigned char *const abbrev_table
= hdrptr
;
10473 hdrptr
+= abbrev_table_size
;
10474 const unsigned char *const abbrev_table_end
= hdrptr
;
10475 unsigned char *const entry_pool
= hdrptr
;
10477 size_t buckets_filled
= 0;
10479 for (bucketi
= 0; bucketi
< bucket_count
; bucketi
++)
10481 const uint32_t bucket
= hash_table_buckets
[bucketi
];
10486 printf (ngettext ("Used %zu of %lu bucket.\n",
10487 "Used %zu of %lu buckets.\n",
10488 (unsigned long) bucket_count
),
10489 buckets_filled
, (unsigned long) bucket_count
);
10491 if (bucket_count
!= 0)
10493 uint32_t hash_prev
= 0;
10494 size_t hash_clash_count
= 0;
10495 size_t longest_clash
= 0;
10496 size_t this_length
= 0;
10498 for (hashi
= 0; hashi
< name_count
; hashi
++)
10500 const uint32_t hash_this
= hash_table_hashes
[hashi
];
10504 if (hash_prev
% bucket_count
== hash_this
% bucket_count
)
10506 ++hash_clash_count
;
10508 longest_clash
= MAX (longest_clash
, this_length
);
10513 hash_prev
= hash_this
;
10515 printf (_("Out of %" PRIu64
" items there are %zu bucket clashes"
10516 " (longest of %zu entries).\n"),
10517 name_count
, hash_clash_count
, longest_clash
);
10519 if (name_count
!= buckets_filled
+ hash_clash_count
)
10520 warn (_("The name_count (%" PRIu64
")"
10521 " is not the same as the used bucket_count"
10522 " (%zu) + the hash clash count (%zu)"),
10523 name_count
, buckets_filled
, hash_clash_count
);
10526 struct abbrev_lookup_entry
10528 uint64_t abbrev_tag
;
10529 unsigned char *abbrev_lookup_ptr
;
10531 struct abbrev_lookup_entry
*abbrev_lookup
= NULL
;
10532 size_t abbrev_lookup_used
= 0;
10533 size_t abbrev_lookup_allocated
= 0;
10535 unsigned char *abbrevptr
= abbrev_table
;
10538 uint64_t abbrev_tag
;
10540 READ_ULEB (abbrev_tag
, abbrevptr
, abbrev_table_end
);
10541 if (abbrev_tag
== 0)
10543 if (abbrev_lookup_used
== abbrev_lookup_allocated
)
10545 abbrev_lookup_allocated
= MAX (0x100,
10546 abbrev_lookup_allocated
* 2);
10547 abbrev_lookup
= xrealloc (abbrev_lookup
,
10548 (abbrev_lookup_allocated
10549 * sizeof (*abbrev_lookup
)));
10551 assert (abbrev_lookup_used
< abbrev_lookup_allocated
);
10552 struct abbrev_lookup_entry
*entry
;
10553 for (entry
= abbrev_lookup
;
10554 entry
< abbrev_lookup
+ abbrev_lookup_used
;
10556 if (entry
->abbrev_tag
== abbrev_tag
)
10558 warn (_("Duplicate abbreviation tag %" PRIu64
10559 " in unit %#tx in the debug_names section\n"),
10560 abbrev_tag
, unit_start
- section
->start
);
10563 entry
= &abbrev_lookup
[abbrev_lookup_used
++];
10564 entry
->abbrev_tag
= abbrev_tag
;
10565 entry
->abbrev_lookup_ptr
= abbrevptr
;
10567 /* Skip DWARF tag. */
10568 SKIP_ULEB (abbrevptr
, abbrev_table_end
);
10571 uint64_t xindex
, form
;
10573 READ_ULEB (xindex
, abbrevptr
, abbrev_table_end
);
10574 READ_ULEB (form
, abbrevptr
, abbrev_table_end
);
10575 if (xindex
== 0 && form
== 0)
10580 printf (_("\nSymbol table:\n"));
10582 for (namei
= 0; namei
< name_count
; ++namei
)
10584 uint64_t string_offset
, entry_offset
;
10587 p
= name_table_string_offsets
+ namei
* offset_size
;
10588 SAFE_BYTE_GET (string_offset
, p
, offset_size
, unit_end
);
10589 p
= name_table_entry_offsets
+ namei
* offset_size
;
10590 SAFE_BYTE_GET (entry_offset
, p
, offset_size
, unit_end
);
10592 printf ("[%3u] #%08x %s:", namei
, hash_table_hashes
[namei
],
10593 fetch_indirect_string (string_offset
));
10595 unsigned char *entryptr
= entry_pool
+ entry_offset
;
10597 /* We need to scan first whether there is a single or multiple
10598 entries. TAGNO is -2 for the first entry, it is -1 for the
10599 initial tag read of the second entry, then it becomes 0 for the
10600 first entry for real printing etc. */
10602 /* Initialize it due to a false compiler warning. */
10603 uint64_t second_abbrev_tag
= -1;
10606 uint64_t abbrev_tag
;
10607 uint64_t dwarf_tag
;
10608 const struct abbrev_lookup_entry
*entry
;
10610 READ_ULEB (abbrev_tag
, entryptr
, unit_end
);
10613 second_abbrev_tag
= abbrev_tag
;
10615 entryptr
= entry_pool
+ entry_offset
;
10618 if (abbrev_tag
== 0)
10621 printf ("%s<%" PRIu64
">",
10622 (tagno
== 0 && second_abbrev_tag
== 0 ? " " : "\n\t"),
10625 for (entry
= abbrev_lookup
;
10626 entry
< abbrev_lookup
+ abbrev_lookup_used
;
10628 if (entry
->abbrev_tag
== abbrev_tag
)
10630 if (entry
>= abbrev_lookup
+ abbrev_lookup_used
)
10632 warn (_("Undefined abbreviation tag %" PRId64
10633 " in unit %#tx in the debug_names section\n"),
10635 unit_start
- section
->start
);
10638 abbrevptr
= entry
->abbrev_lookup_ptr
;
10639 READ_ULEB (dwarf_tag
, abbrevptr
, abbrev_table_end
);
10641 printf (" %s", get_TAG_name (dwarf_tag
));
10644 uint64_t xindex
, form
;
10646 READ_ULEB (xindex
, abbrevptr
, abbrev_table_end
);
10647 READ_ULEB (form
, abbrevptr
, abbrev_table_end
);
10648 if (xindex
== 0 && form
== 0)
10652 printf (" %s", get_IDX_name (xindex
));
10653 entryptr
= read_and_display_attr_value (0, form
, 0,
10654 unit_start
, entryptr
, unit_end
,
10656 dwarf_version
, NULL
,
10657 (tagno
< 0), section
,
10663 printf (_(" <no entries>"));
10667 free (abbrev_lookup
);
10674 display_debug_links (struct dwarf_section
* section
,
10675 void * file ATTRIBUTE_UNUSED
)
10677 const unsigned char * filename
;
10678 unsigned int filelen
;
10680 introduce (section
, false);
10682 /* The .gnu_debuglink section is formatted as:
10683 (c-string) Filename.
10684 (padding) If needed to reach a 4 byte boundary.
10685 (uint32_t) CRC32 value.
10687 The .gun_debugaltlink section is formatted as:
10688 (c-string) Filename.
10689 (binary) Build-ID. */
10691 filename
= section
->start
;
10692 filelen
= strnlen ((const char *) filename
, section
->size
);
10693 if (filelen
== section
->size
)
10695 warn (_("The debuglink filename is corrupt/missing\n"));
10699 printf (_(" Separate debug info file: %s\n"), filename
);
10701 if (startswith (section
->name
, ".gnu_debuglink"))
10703 unsigned int crc32
;
10704 unsigned int crc_offset
;
10706 crc_offset
= filelen
+ 1;
10707 crc_offset
= (crc_offset
+ 3) & ~3;
10708 if (crc_offset
+ 4 > section
->size
)
10710 warn (_("CRC offset missing/truncated\n"));
10714 crc32
= byte_get (filename
+ crc_offset
, 4);
10716 printf (_(" CRC value: %#x\n"), crc32
);
10718 if (crc_offset
+ 4 < section
->size
)
10720 warn (_("There are %#" PRIx64
10721 " extraneous bytes at the end of the section\n"),
10722 section
->size
- (crc_offset
+ 4));
10726 else /* startswith (section->name, ".gnu_debugaltlink") */
10728 const unsigned char *build_id
= section
->start
+ filelen
+ 1;
10729 size_t build_id_len
= section
->size
- (filelen
+ 1);
10732 /* FIXME: Should we support smaller build-id notes ? */
10733 if (build_id_len
< 0x14)
10735 warn (_("Build-ID is too short (%#zx bytes)\n"), build_id_len
);
10739 printed
= printf (_(" Build-ID (%#zx bytes):"), build_id_len
);
10740 display_data (printed
, build_id
, build_id_len
);
10749 display_gdb_index (struct dwarf_section
*section
,
10750 void *file ATTRIBUTE_UNUSED
)
10752 unsigned char *start
= section
->start
;
10754 uint32_t cu_list_offset
, tu_list_offset
;
10755 uint32_t address_table_offset
, symbol_table_offset
, constant_pool_offset
,
10756 shortcut_table_offset
;
10757 unsigned int cu_list_elements
, tu_list_elements
;
10758 unsigned int address_table_elements
, symbol_table_slots
;
10759 unsigned char *cu_list
, *tu_list
;
10760 unsigned char *address_table
, *symbol_table
, *shortcut_table
, *constant_pool
;
10763 /* The documentation for the format of this file is in gdb/dwarf2read.c. */
10765 introduce (section
, false);
10767 version
= section
->size
< 4 ? 0 : byte_get_little_endian (start
, 4);
10768 size_t header_size
= (version
< 9 ? 6 : 7) * sizeof (uint32_t);
10769 if (section
->size
< header_size
)
10771 warn (_("Truncated header in the %s section.\n"), section
->name
);
10775 printf (_("Version %lu\n"), (unsigned long) version
);
10777 /* Prior versions are obsolete, and future versions may not be
10778 backwards compatible. */
10779 if (version
< 3 || version
> 9)
10781 warn (_("Unsupported version %lu.\n"), (unsigned long) version
);
10785 warn (_("The address table data in version 3 may be wrong.\n"));
10787 warn (_("Version 4 does not support case insensitive lookups.\n"));
10789 warn (_("Version 5 does not include inlined functions.\n"));
10791 warn (_("Version 6 does not include symbol attributes.\n"));
10792 /* Version 7 indices generated by Gold have bad type unit references,
10793 PR binutils/15021. But we don't know if the index was generated by
10794 Gold or not, so to avoid worrying users with gdb-generated indices
10795 we say nothing for version 7 here. */
10797 cu_list_offset
= byte_get_little_endian (start
+ 4, 4);
10798 tu_list_offset
= byte_get_little_endian (start
+ 8, 4);
10799 address_table_offset
= byte_get_little_endian (start
+ 12, 4);
10800 symbol_table_offset
= byte_get_little_endian (start
+ 16, 4);
10801 shortcut_table_offset
= byte_get_little_endian (start
+ 20, 4);
10803 constant_pool_offset
= shortcut_table_offset
;
10805 constant_pool_offset
= byte_get_little_endian (start
+ 24, 4);
10807 if (cu_list_offset
> section
->size
10808 || tu_list_offset
> section
->size
10809 || address_table_offset
> section
->size
10810 || symbol_table_offset
> section
->size
10811 || shortcut_table_offset
> section
->size
10812 || constant_pool_offset
> section
->size
10813 || tu_list_offset
< cu_list_offset
10814 || address_table_offset
< tu_list_offset
10815 || symbol_table_offset
< address_table_offset
10816 || shortcut_table_offset
< symbol_table_offset
10817 || constant_pool_offset
< shortcut_table_offset
)
10819 warn (_("Corrupt header in the %s section.\n"), section
->name
);
10823 cu_list_elements
= (tu_list_offset
- cu_list_offset
) / 16;
10824 tu_list_elements
= (address_table_offset
- tu_list_offset
) / 24;
10825 address_table_elements
= (symbol_table_offset
- address_table_offset
) / 20;
10826 symbol_table_slots
= (shortcut_table_offset
- symbol_table_offset
) / 8;
10828 cu_list
= start
+ cu_list_offset
;
10829 tu_list
= start
+ tu_list_offset
;
10830 address_table
= start
+ address_table_offset
;
10831 symbol_table
= start
+ symbol_table_offset
;
10832 shortcut_table
= start
+ shortcut_table_offset
;
10833 constant_pool
= start
+ constant_pool_offset
;
10835 printf (_("\nCU table:\n"));
10836 for (i
= 0; i
< cu_list_elements
; i
++)
10838 uint64_t cu_offset
= byte_get_little_endian (cu_list
+ i
* 16, 8);
10839 uint64_t cu_length
= byte_get_little_endian (cu_list
+ i
* 16 + 8, 8);
10841 printf ("[%3u] %#" PRIx64
" - %#" PRIx64
"\n",
10842 i
, cu_offset
, cu_offset
+ cu_length
- 1);
10845 printf (_("\nTU table:\n"));
10846 for (i
= 0; i
< tu_list_elements
; i
++)
10848 uint64_t tu_offset
= byte_get_little_endian (tu_list
+ i
* 24, 8);
10849 uint64_t type_offset
= byte_get_little_endian (tu_list
+ i
* 24 + 8, 8);
10850 uint64_t signature
= byte_get_little_endian (tu_list
+ i
* 24 + 16, 8);
10852 printf ("[%3u] %#" PRIx64
" %#" PRIx64
" ",
10853 i
, tu_offset
, type_offset
);
10854 print_hex_ns (signature
, 8);
10858 printf (_("\nAddress table:\n"));
10859 for (i
= 0; i
< address_table_elements
; i
++)
10861 uint64_t low
= byte_get_little_endian (address_table
+ i
* 20, 8);
10862 uint64_t high
= byte_get_little_endian (address_table
+ i
* 20 + 8, 8);
10863 uint32_t cu_index
= byte_get_little_endian (address_table
+ i
* 20 + 16, 4);
10865 print_hex (low
, 8);
10866 print_hex (high
, 8);
10867 printf ("%" PRIu32
"\n", cu_index
);
10870 printf (_("\nSymbol table:\n"));
10871 for (i
= 0; i
< symbol_table_slots
; ++i
)
10873 uint32_t name_offset
= byte_get_little_endian (symbol_table
+ i
* 8, 4);
10874 uint32_t cu_vector_offset
= byte_get_little_endian (symbol_table
+ i
* 8 + 4, 4);
10875 uint32_t num_cus
, cu
;
10877 if (name_offset
!= 0
10878 || cu_vector_offset
!= 0)
10882 /* PR 17531: file: 5b7b07ad. */
10883 if (name_offset
>= section
->size
- constant_pool_offset
)
10885 printf (_("[%3u] <corrupt offset: %x>"), i
, name_offset
);
10886 warn (_("Corrupt name offset of 0x%x found for symbol table slot %d\n"),
10890 printf ("[%3u] %.*s:", i
,
10891 (int) (section
->size
- (constant_pool_offset
+ name_offset
)),
10892 constant_pool
+ name_offset
);
10894 if (section
->size
- constant_pool_offset
< 4
10895 || cu_vector_offset
> section
->size
- constant_pool_offset
- 4)
10897 printf (_("<invalid CU vector offset: %x>\n"), cu_vector_offset
);
10898 warn (_("Corrupt CU vector offset of 0x%x found for symbol table slot %d\n"),
10899 cu_vector_offset
, i
);
10903 num_cus
= byte_get_little_endian (constant_pool
+ cu_vector_offset
, 4);
10905 if ((uint64_t) num_cus
* 4 > section
->size
- (constant_pool_offset
10906 + cu_vector_offset
+ 4))
10908 printf ("<invalid number of CUs: %d>\n", num_cus
);
10909 warn (_("Invalid number of CUs (0x%x) for symbol table slot %d\n"),
10917 for (j
= 0; j
< num_cus
; ++j
)
10920 gdb_index_symbol_kind kind
;
10922 cu
= byte_get_little_endian (constant_pool
+ cu_vector_offset
+ 4 + j
* 4, 4);
10923 is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu
);
10924 kind
= GDB_INDEX_SYMBOL_KIND_VALUE (cu
);
10925 cu
= GDB_INDEX_CU_VALUE (cu
);
10926 /* Convert to TU number if it's for a type unit. */
10927 if (cu
>= cu_list_elements
)
10928 printf ("%cT%lu", num_cus
> 1 ? '\t' : ' ',
10929 (unsigned long) cu
- cu_list_elements
);
10931 printf ("%c%lu", num_cus
> 1 ? '\t' : ' ', (unsigned long) cu
);
10933 printf (" [%s, %s]",
10934 is_static
? _("static") : _("global"),
10935 get_gdb_index_symbol_kind_name (kind
));
10946 printf (_("\nShortcut table:\n"));
10948 if (shortcut_table_offset
+ 8 > constant_pool_offset
)
10950 warn (_("Corrupt shortcut table in the %s section.\n"), section
->name
);
10954 uint32_t lang
= byte_get_little_endian (shortcut_table
, 4);
10955 printf (_("Language of main: "));
10956 display_lang (lang
);
10959 uint32_t name_offset
= byte_get_little_endian (shortcut_table
+ 4, 4);
10960 printf (_("Name of main: "));
10961 if (name_offset
>= section
->size
- constant_pool_offset
)
10963 printf (_("<corrupt offset: %x>\n"), name_offset
);
10964 warn (_("Corrupt name offset of 0x%x found for name of main\n"),
10968 printf ("%s\n", constant_pool
+ name_offset
);
10974 /* Pre-allocate enough space for the CU/TU sets needed. */
10977 prealloc_cu_tu_list (unsigned int nshndx
)
10980 /* Always allocate at least one entry for the end-marker. */
10983 if (shndx_pool
== NULL
)
10985 shndx_pool_size
= nshndx
;
10986 shndx_pool_used
= 0;
10987 shndx_pool
= (unsigned int *) xcmalloc (shndx_pool_size
,
10988 sizeof (unsigned int));
10992 shndx_pool_size
= shndx_pool_used
+ nshndx
;
10993 shndx_pool
= (unsigned int *) xcrealloc (shndx_pool
, shndx_pool_size
,
10994 sizeof (unsigned int));
10999 add_shndx_to_cu_tu_entry (unsigned int shndx
)
11001 shndx_pool
[shndx_pool_used
++] = shndx
;
11005 end_cu_tu_entry (void)
11007 shndx_pool
[shndx_pool_used
++] = 0;
11010 /* Return the short name of a DWARF section given by a DW_SECT enumerator. */
11012 static const char *
11013 get_DW_SECT_short_name (unsigned int dw_sect
)
11015 static char buf
[16];
11021 case DW_SECT_TYPES
:
11023 case DW_SECT_ABBREV
:
11029 case DW_SECT_STR_OFFSETS
:
11031 case DW_SECT_MACINFO
:
11033 case DW_SECT_MACRO
:
11039 snprintf (buf
, sizeof (buf
), "%d", dw_sect
);
11043 /* Process a CU or TU index. If DO_DISPLAY is true, print the contents.
11044 These sections are extensions for Fission.
11045 See http://gcc.gnu.org/wiki/DebugFissionDWP. */
11048 process_cu_tu_index (struct dwarf_section
*section
, int do_display
)
11050 unsigned char *phdr
= section
->start
;
11051 unsigned char *limit
= phdr
+ section
->size
;
11052 unsigned char *phash
;
11053 unsigned char *pindex
;
11054 unsigned char *ppool
;
11055 unsigned int version
;
11056 unsigned int ncols
= 0;
11057 unsigned int nused
;
11058 unsigned int nslots
;
11061 uint64_t signature
;
11064 /* PR 17512: file: 002-168123-0.004. */
11067 warn (_("Section %s is empty\n"), section
->name
);
11070 /* PR 17512: file: 002-376-0.004. */
11071 if (section
->size
< 24)
11073 warn (_("Section %s is too small to contain a CU/TU header\n"),
11079 SAFE_BYTE_GET_AND_INC (version
, phash
, 4, limit
);
11081 SAFE_BYTE_GET_AND_INC (ncols
, phash
, 4, limit
);
11082 SAFE_BYTE_GET_AND_INC (nused
, phash
, 4, limit
);
11083 SAFE_BYTE_GET_AND_INC (nslots
, phash
, 4, limit
);
11085 pindex
= phash
+ (size_t) nslots
* 8;
11086 ppool
= pindex
+ (size_t) nslots
* 4;
11090 introduce (section
, false);
11092 printf (_(" Version: %u\n"), version
);
11094 printf (_(" Number of columns: %u\n"), ncols
);
11095 printf (_(" Number of used entries: %u\n"), nused
);
11096 printf (_(" Number of slots: %u\n\n"), nslots
);
11099 /* PR 17531: file: 45d69832. */
11100 if (_mul_overflow ((size_t) nslots
, 12, &total
)
11101 || total
> (size_t) (limit
- phash
))
11103 warn (ngettext ("Section %s is too small for %u slot\n",
11104 "Section %s is too small for %u slots\n",
11106 section
->name
, nslots
);
11112 unsigned char *shndx_list
;
11113 unsigned int shndx
;
11117 prealloc_cu_tu_list ((limit
- ppool
) / 4);
11118 for (shndx_list
= ppool
+ 4; shndx_list
<= limit
- 4; shndx_list
+= 4)
11120 shndx
= byte_get (shndx_list
, 4);
11121 add_shndx_to_cu_tu_entry (shndx
);
11123 end_cu_tu_entry ();
11126 for (i
= 0; i
< nslots
; i
++)
11128 SAFE_BYTE_GET (signature
, phash
, 8, limit
);
11129 if (signature
!= 0)
11131 SAFE_BYTE_GET (j
, pindex
, 4, limit
);
11132 shndx_list
= ppool
+ j
* 4;
11133 /* PR 17531: file: 705e010d. */
11134 if (shndx_list
< ppool
)
11136 warn (_("Section index pool located before start of section\n"));
11140 printf (_(" [%3d] Signature: %#" PRIx64
" Sections: "),
11144 if (shndx_list
>= limit
)
11146 warn (_("Section %s too small for shndx pool\n"),
11150 SAFE_BYTE_GET (shndx
, shndx_list
, 4, limit
);
11153 printf (" %d", shndx
);
11162 else if (version
== 2)
11165 unsigned int dw_sect
;
11166 unsigned char *ph
= phash
;
11167 unsigned char *pi
= pindex
;
11168 unsigned char *poffsets
= ppool
+ (size_t) ncols
* 4;
11169 unsigned char *psizes
= poffsets
+ (size_t) nused
* ncols
* 4;
11171 struct cu_tu_set
*this_set
= NULL
;
11173 unsigned char *prow
;
11176 is_tu_index
= strcmp (section
->name
, ".debug_tu_index") == 0;
11178 /* PR 17531: file: 0dd159bf.
11179 Check for integer overflow (can occur when size_t is 32-bit)
11180 with overlarge ncols or nused values. */
11182 || _mul_overflow ((size_t) ncols
, 4, &temp
)
11183 || _mul_overflow ((size_t) nused
+ 1, temp
, &total
)
11184 || total
> (size_t) (limit
- ppool
)
11185 /* PR 30227: ncols could be 0. */
11186 || _mul_overflow ((size_t) nused
+ 1, 4, &total
)
11187 || total
> (size_t) (limit
- ppool
))
11189 warn (_("Section %s too small for offset and size tables\n"),
11196 printf (_(" Offset table\n"));
11197 printf (" slot %-16s ",
11198 is_tu_index
? _("signature") : _("dwo_id"));
11205 tu_sets
= xcalloc2 (nused
, sizeof (struct cu_tu_set
));
11206 this_set
= tu_sets
;
11211 cu_sets
= xcalloc2 (nused
, sizeof (struct cu_tu_set
));
11212 this_set
= cu_sets
;
11218 for (j
= 0; j
< ncols
; j
++)
11220 unsigned char *p
= ppool
+ j
* 4;
11221 SAFE_BYTE_GET (dw_sect
, p
, 4, limit
);
11222 printf (" %8s", get_DW_SECT_short_name (dw_sect
));
11227 for (i
= 0; i
< nslots
; i
++)
11229 SAFE_BYTE_GET (signature
, ph
, 8, limit
);
11231 SAFE_BYTE_GET (row
, pi
, 4, limit
);
11234 /* PR 17531: file: a05f6ab3. */
11237 warn (_("Row index (%u) is larger than number of used entries (%u)\n"),
11244 size_t num_copy
= sizeof (uint64_t);
11246 memcpy (&this_set
[row
- 1].signature
, ph
, num_copy
);
11249 prow
= poffsets
+ (row
- 1) * ncols
* 4;
11251 printf (" [%3d] %#" PRIx64
, i
, signature
);
11252 for (j
= 0; j
< ncols
; j
++)
11254 unsigned char *p
= prow
+ j
* 4;
11255 SAFE_BYTE_GET (val
, p
, 4, limit
);
11257 printf (" %8d", val
);
11261 SAFE_BYTE_GET (dw_sect
, p
, 4, limit
);
11263 /* PR 17531: file: 10796eb3. */
11264 if (dw_sect
>= DW_SECT_MAX
)
11265 warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect
);
11267 this_set
[row
- 1].section_offsets
[dw_sect
] = val
;
11283 printf (_(" Size table\n"));
11284 printf (" slot %-16s ",
11285 is_tu_index
? _("signature") : _("dwo_id"));
11288 for (j
= 0; j
< ncols
; j
++)
11290 unsigned char *p
= ppool
+ j
* 4;
11291 SAFE_BYTE_GET (val
, p
, 4, limit
);
11293 printf (" %8s", get_DW_SECT_short_name (val
));
11299 for (i
= 0; i
< nslots
; i
++)
11301 SAFE_BYTE_GET (signature
, ph
, 8, limit
);
11303 SAFE_BYTE_GET (row
, pi
, 4, limit
);
11306 prow
= psizes
+ (row
- 1) * ncols
* 4;
11309 printf (" [%3d] %#" PRIx64
, i
, signature
);
11311 for (j
= 0; j
< ncols
; j
++)
11313 unsigned char *p
= prow
+ j
* 4;
11315 /* PR 28645: Check for overflow. Since we do not know how
11316 many populated rows there will be, we cannot just
11317 perform a single check at the start of this function. */
11318 if (p
> (limit
- 4))
11322 warn (_("Too many rows/columns in DWARF index section %s\n"),
11327 SAFE_BYTE_GET (val
, p
, 4, limit
);
11330 printf (" %8d", val
);
11334 SAFE_BYTE_GET (dw_sect
, p
, 4, limit
);
11335 if (dw_sect
>= DW_SECT_MAX
)
11336 warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect
);
11338 this_set
[row
- 1].section_sizes
[dw_sect
] = val
;
11350 else if (do_display
)
11351 printf (_(" Unsupported version (%d)\n"), version
);
11359 static int cu_tu_indexes_read
= -1; /* Tri-state variable. */
11361 /* Load the CU and TU indexes if present. This will build a list of
11362 section sets that we can use to associate a .debug_info.dwo section
11363 with its associated .debug_abbrev.dwo section in a .dwp file. */
11366 load_cu_tu_indexes (void *file
)
11368 /* If we have already loaded (or tried to load) the CU and TU indexes
11369 then do not bother to repeat the task. */
11370 if (cu_tu_indexes_read
== -1)
11372 cu_tu_indexes_read
= true;
11374 if (load_debug_section_with_follow (dwp_cu_index
, file
))
11375 if (! process_cu_tu_index (&debug_displays
[dwp_cu_index
].section
, 0))
11376 cu_tu_indexes_read
= false;
11378 if (load_debug_section_with_follow (dwp_tu_index
, file
))
11379 if (! process_cu_tu_index (&debug_displays
[dwp_tu_index
].section
, 0))
11380 cu_tu_indexes_read
= false;
11383 return (bool) cu_tu_indexes_read
;
11386 /* Find the set of sections that includes section SHNDX. */
11389 find_cu_tu_set (void *file
, unsigned int shndx
)
11393 if (! load_cu_tu_indexes (file
))
11396 /* Find SHNDX in the shndx pool. */
11397 for (i
= 0; i
< shndx_pool_used
; i
++)
11398 if (shndx_pool
[i
] == shndx
)
11401 if (i
>= shndx_pool_used
)
11404 /* Now backup to find the first entry in the set. */
11405 while (i
> 0 && shndx_pool
[i
- 1] != 0)
11408 return shndx_pool
+ i
;
11411 /* Display a .debug_cu_index or .debug_tu_index section. */
11414 display_cu_index (struct dwarf_section
*section
, void *file ATTRIBUTE_UNUSED
)
11416 return process_cu_tu_index (section
, 1);
11420 display_debug_not_supported (struct dwarf_section
*section
,
11421 void *file ATTRIBUTE_UNUSED
)
11423 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
11429 /* Like malloc, but takes two parameters like calloc.
11430 Verifies that the first parameter is not too large.
11431 Note: does *not* initialise the allocated memory to zero. */
11434 cmalloc (uint64_t nmemb
, size_t size
)
11436 /* Check for overflow. */
11437 if (nmemb
>= ~(size_t) 0 / size
)
11440 return xmalloc (nmemb
* size
);
11443 /* Like xmalloc, but takes two parameters like calloc.
11444 Verifies that the first parameter is not too large.
11445 Note: does *not* initialise the allocated memory to zero. */
11448 xcmalloc (uint64_t nmemb
, size_t size
)
11450 /* Check for overflow. */
11451 if (nmemb
>= ~(size_t) 0 / size
)
11454 _("Attempt to allocate an array with an excessive number of elements: %#" PRIx64
"\n"),
11459 return xmalloc (nmemb
* size
);
11462 /* Like xrealloc, but takes three parameters.
11463 Verifies that the second parameter is not too large.
11464 Note: does *not* initialise any new memory to zero. */
11467 xcrealloc (void *ptr
, uint64_t nmemb
, size_t size
)
11469 /* Check for overflow. */
11470 if (nmemb
>= ~(size_t) 0 / size
)
11472 error (_("Attempt to re-allocate an array with an excessive number of elements: %#" PRIx64
"\n"),
11477 return xrealloc (ptr
, nmemb
* size
);
11480 /* Like xcalloc, but verifies that the first parameter is not too large. */
11483 xcalloc2 (uint64_t nmemb
, size_t size
)
11485 /* Check for overflow. */
11486 if (nmemb
>= ~(size_t) 0 / size
)
11488 error (_("Attempt to allocate a zero'ed array with an excessive number of elements: %#" PRIx64
"\n"),
11493 return xcalloc (nmemb
, size
);
11496 static unsigned long
11497 calc_gnu_debuglink_crc32 (unsigned long crc
,
11498 const unsigned char *buf
,
11501 static const unsigned long crc32_table
[256] =
11503 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
11504 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
11505 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
11506 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
11507 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
11508 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
11509 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
11510 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
11511 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
11512 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
11513 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
11514 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
11515 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
11516 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
11517 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
11518 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
11519 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
11520 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
11521 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
11522 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
11523 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
11524 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
11525 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
11526 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
11527 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
11528 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
11529 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
11530 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
11531 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
11532 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
11533 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
11534 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
11535 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
11536 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
11537 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
11538 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
11539 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
11540 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
11541 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
11542 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
11543 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
11544 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
11545 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
11546 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
11547 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
11548 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
11549 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
11550 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
11551 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
11552 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
11553 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
11556 const unsigned char *end
;
11558 crc
= ~crc
& 0xffffffff;
11559 for (end
= buf
+ len
; buf
< end
; ++ buf
)
11560 crc
= crc32_table
[(crc
^ *buf
) & 0xff] ^ (crc
>> 8);
11561 return ~crc
& 0xffffffff;
11564 typedef bool (*check_func_type
) (const char *, void *);
11565 typedef const char *(* parse_func_type
) (struct dwarf_section
*, void *);
11568 check_gnu_debuglink (const char * pathname
, void * crc_pointer
)
11570 static unsigned char buffer
[8 * 1024];
11573 unsigned long crc
= 0;
11576 sep_data
= open_debug_file (pathname
);
11577 if (sep_data
== NULL
)
11580 /* Yes - we are opening the file twice... */
11581 f
= fopen (pathname
, "rb");
11584 /* Paranoia: This should never happen. */
11585 close_debug_file (sep_data
);
11586 warn (_("Unable to reopen separate debug info file: %s\n"), pathname
);
11590 while ((count
= fread (buffer
, 1, sizeof (buffer
), f
)) > 0)
11591 crc
= calc_gnu_debuglink_crc32 (crc
, buffer
, count
);
11595 if (crc
!= * (unsigned long *) crc_pointer
)
11597 close_debug_file (sep_data
);
11598 warn (_("Separate debug info file %s found, but CRC does not match - ignoring\n"),
11606 static const char *
11607 parse_gnu_debuglink (struct dwarf_section
* section
, void * data
)
11610 unsigned int crc_offset
;
11611 unsigned long * crc32
= (unsigned long *) data
;
11613 /* The name is first.
11614 The CRC value is stored after the filename, aligned up to 4 bytes. */
11615 name
= (const char *) section
->start
;
11617 crc_offset
= strnlen (name
, section
->size
) + 1;
11618 if (crc_offset
== 1)
11620 crc_offset
= (crc_offset
+ 3) & ~3;
11621 if (crc_offset
+ 4 > section
->size
)
11624 * crc32
= byte_get (section
->start
+ crc_offset
, 4);
11629 check_gnu_debugaltlink (const char * filename
, void * data ATTRIBUTE_UNUSED
)
11631 void * sep_data
= open_debug_file (filename
);
11633 if (sep_data
== NULL
)
11636 /* FIXME: We should now extract the build-id in the separate file
11642 typedef struct build_id_data
11645 const unsigned char *data
;
11648 static const char *
11649 parse_gnu_debugaltlink (struct dwarf_section
* section
, void * data
)
11654 Build_id_data
*build_id_data
;
11656 /* The name is first.
11657 The build-id follows immediately, with no padding, up to the section's end. */
11659 name
= (const char *) section
->start
;
11660 namelen
= strnlen (name
, section
->size
) + 1;
11663 if (namelen
>= section
->size
)
11666 id_len
= section
->size
- namelen
;
11670 build_id_data
= (Build_id_data
*) data
;
11671 build_id_data
->len
= id_len
;
11672 build_id_data
->data
= section
->start
+ namelen
;
11678 add_separate_debug_file (const char * filename
, void * handle
)
11680 separate_info
* i
= xmalloc (sizeof * i
);
11682 i
->filename
= filename
;
11683 i
->handle
= handle
;
11684 i
->next
= first_separate_info
;
11685 first_separate_info
= i
;
11688 #if HAVE_LIBDEBUGINFOD
11689 /* Query debuginfod servers for the target debuglink or debugaltlink
11690 file. If successful, store the path of the file in filename and
11691 return TRUE, otherwise return FALSE. */
11694 debuginfod_fetch_separate_debug_info (struct dwarf_section
* section
,
11698 size_t build_id_len
;
11699 unsigned char * build_id
;
11701 if (strcmp (section
->uncompressed_name
, ".gnu_debuglink") == 0)
11703 /* Get the build-id of file. */
11704 build_id
= get_build_id (file
);
11707 else if (strcmp (section
->uncompressed_name
, ".gnu_debugaltlink") == 0)
11709 /* Get the build-id of the debugaltlink file. */
11710 unsigned int filelen
;
11712 filelen
= strnlen ((const char *)section
->start
, section
->size
);
11713 if (filelen
== section
->size
)
11714 /* Corrupt debugaltlink. */
11717 build_id
= section
->start
+ filelen
+ 1;
11718 build_id_len
= section
->size
- (filelen
+ 1);
11720 if (build_id_len
== 0)
11729 debuginfod_client
* client
;
11731 client
= debuginfod_begin ();
11732 if (client
== NULL
)
11735 /* Query debuginfod servers for the target file. If found its path
11736 will be stored in filename. */
11737 fd
= debuginfod_find_debuginfo (client
, build_id
, build_id_len
, filename
);
11738 debuginfod_end (client
);
11740 /* Only free build_id if we allocated space for a hex string
11741 in get_build_id (). */
11742 if (build_id_len
== 0)
11747 /* File successfully retrieved. Close fd since we want to
11748 use open_debug_file () on filename instead. */
11756 #endif /* HAVE_LIBDEBUGINFOD */
11759 load_separate_debug_info (const char * main_filename
,
11760 struct dwarf_section
* xlink
,
11761 parse_func_type parse_func
,
11762 check_func_type check_func
,
11764 void * file ATTRIBUTE_UNUSED
)
11766 const char * separate_filename
;
11767 char * debug_filename
;
11769 size_t canon_dirlen
;
11771 char * canon_filename
;
11772 char * canon_debug_filename
;
11775 if ((separate_filename
= parse_func (xlink
, func_data
)) == NULL
)
11777 warn (_("Corrupt debuglink section: %s\n"),
11778 xlink
->name
? xlink
->name
: xlink
->uncompressed_name
);
11782 /* Attempt to locate the separate file.
11783 This should duplicate the logic in bfd/opncls.c:find_separate_debug_file(). */
11785 canon_filename
= lrealpath (main_filename
);
11786 canon_dir
= xstrdup (canon_filename
);
11788 for (canon_dirlen
= strlen (canon_dir
); canon_dirlen
> 0; canon_dirlen
--)
11789 if (IS_DIR_SEPARATOR (canon_dir
[canon_dirlen
- 1]))
11791 canon_dir
[canon_dirlen
] = '\0';
11794 #define DEBUGDIR "/lib/debug"
11796 #ifndef EXTRA_DEBUG_ROOT1
11797 #define EXTRA_DEBUG_ROOT1 "/usr/lib/debug"
11799 #ifndef EXTRA_DEBUG_ROOT2
11800 #define EXTRA_DEBUG_ROOT2 "/usr/lib/debug/usr"
11803 debug_filename
= (char *) malloc (strlen (DEBUGDIR
) + 1
11805 + strlen (".debug/")
11806 #ifdef EXTRA_DEBUG_ROOT1
11807 + strlen (EXTRA_DEBUG_ROOT1
)
11809 #ifdef EXTRA_DEBUG_ROOT2
11810 + strlen (EXTRA_DEBUG_ROOT2
)
11812 + strlen (separate_filename
)
11814 if (debug_filename
== NULL
)
11816 warn (_("Out of memory"));
11818 free (canon_filename
);
11822 /* First try in the current directory. */
11823 sprintf (debug_filename
, "%s", separate_filename
);
11824 if (check_func (debug_filename
, func_data
))
11827 /* Then try in a subdirectory called .debug. */
11828 sprintf (debug_filename
, ".debug/%s", separate_filename
);
11829 if (check_func (debug_filename
, func_data
))
11832 /* Then try in the same directory as the original file. */
11833 sprintf (debug_filename
, "%s%s", canon_dir
, separate_filename
);
11834 if (check_func (debug_filename
, func_data
))
11837 /* And the .debug subdirectory of that directory. */
11838 sprintf (debug_filename
, "%s.debug/%s", canon_dir
, separate_filename
);
11839 if (check_func (debug_filename
, func_data
))
11842 #ifdef EXTRA_DEBUG_ROOT1
11843 /* Try the first extra debug file root. */
11844 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT1
, separate_filename
);
11845 if (check_func (debug_filename
, func_data
))
11848 /* Try the first extra debug file root. */
11849 sprintf (debug_filename
, "%s/%s/%s", EXTRA_DEBUG_ROOT1
, canon_dir
, separate_filename
);
11850 if (check_func (debug_filename
, func_data
))
11854 #ifdef EXTRA_DEBUG_ROOT2
11855 /* Try the second extra debug file root. */
11856 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT2
, separate_filename
);
11857 if (check_func (debug_filename
, func_data
))
11861 /* Then try in the global debug_filename directory. */
11862 strcpy (debug_filename
, DEBUGDIR
);
11863 dirlen
= strlen (DEBUGDIR
) - 1;
11864 if (dirlen
> 0 && DEBUGDIR
[dirlen
] != '/')
11865 strcat (debug_filename
, "/");
11866 strcat (debug_filename
, (const char *) separate_filename
);
11868 if (check_func (debug_filename
, func_data
))
11871 #if HAVE_LIBDEBUGINFOD
11873 char * tmp_filename
;
11876 && debuginfod_fetch_separate_debug_info (xlink
,
11880 /* File successfully downloaded from server, replace
11881 debug_filename with the file's path. */
11882 free (debug_filename
);
11883 debug_filename
= tmp_filename
;
11889 if (do_debug_links
)
11891 /* Failed to find the file. */
11892 warn (_("could not find separate debug file '%s'\n"),
11893 separate_filename
);
11894 warn (_("tried: %s\n"), debug_filename
);
11896 #ifdef EXTRA_DEBUG_ROOT2
11897 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT2
,
11898 separate_filename
);
11899 warn (_("tried: %s\n"), debug_filename
);
11902 #ifdef EXTRA_DEBUG_ROOT1
11903 sprintf (debug_filename
, "%s/%s/%s", EXTRA_DEBUG_ROOT1
,
11904 canon_dir
, separate_filename
);
11905 warn (_("tried: %s\n"), debug_filename
);
11907 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT1
,
11908 separate_filename
);
11909 warn (_("tried: %s\n"), debug_filename
);
11912 sprintf (debug_filename
, "%s.debug/%s", canon_dir
,
11913 separate_filename
);
11914 warn (_("tried: %s\n"), debug_filename
);
11916 sprintf (debug_filename
, "%s%s", canon_dir
, separate_filename
);
11917 warn (_("tried: %s\n"), debug_filename
);
11919 sprintf (debug_filename
, ".debug/%s", separate_filename
);
11920 warn (_("tried: %s\n"), debug_filename
);
11922 sprintf (debug_filename
, "%s", separate_filename
);
11923 warn (_("tried: %s\n"), debug_filename
);
11925 #if HAVE_LIBDEBUGINFOD
11926 if (use_debuginfod
)
11928 char *urls
= getenv (DEBUGINFOD_URLS_ENV_VAR
);
11933 warn (_("tried: DEBUGINFOD_URLS=%s\n"), urls
);
11939 free (debug_filename
);
11940 free (canon_filename
);
11946 canon_debug_filename
= lrealpath (debug_filename
);
11947 self
= strcmp (canon_debug_filename
, canon_filename
) == 0;
11948 free (canon_filename
);
11949 free (canon_debug_filename
);
11952 free (debug_filename
);
11956 void * debug_handle
;
11958 /* Now open the file.... */
11959 if ((debug_handle
= open_debug_file (debug_filename
)) == NULL
)
11961 warn (_("failed to open separate debug file: %s\n"), debug_filename
);
11962 free (debug_filename
);
11966 /* FIXME: We do not check to see if there are any other separate debug info
11967 files that would also match. */
11969 if (do_debug_links
)
11970 printf (_("\n%s: Found separate debug info file: %s\n"), main_filename
, debug_filename
);
11971 add_separate_debug_file (debug_filename
, debug_handle
);
11973 /* Do not free debug_filename - it might be referenced inside
11974 the structure returned by open_debug_file(). */
11975 return debug_handle
;
11978 /* Attempt to load a separate dwarf object file. */
11981 load_dwo_file (const char * main_filename
, const char * name
, const char * dir
, const char * id ATTRIBUTE_UNUSED
)
11983 char * separate_filename
;
11984 void * separate_handle
;
11986 if (IS_ABSOLUTE_PATH (name
))
11987 separate_filename
= strdup (name
);
11989 /* FIXME: Skip adding / if dwo_dir ends in /. */
11990 separate_filename
= concat (dir
, "/", name
, NULL
);
11991 if (separate_filename
== NULL
)
11993 warn (_("Out of memory allocating dwo filename\n"));
11997 if ((separate_handle
= open_debug_file (separate_filename
)) == NULL
)
11999 warn (_("Unable to load dwo file: %s\n"), separate_filename
);
12000 free (separate_filename
);
12004 /* FIXME: We should check the dwo_id. */
12006 printf (_("%s: Found separate debug object file: %s\n\n"), main_filename
, separate_filename
);
12008 add_separate_debug_file (separate_filename
, separate_handle
);
12009 /* Note - separate_filename will be freed in free_debug_memory(). */
12010 return separate_handle
;
12014 try_build_id_prefix (const char * prefix
, char * filename
, const unsigned char * data
, unsigned long id_len
)
12016 char * f
= filename
;
12018 f
+= sprintf (f
, "%s.build-id/%02x/", prefix
, (unsigned) *data
++);
12021 f
+= sprintf (f
, "%02x", (unsigned) *data
++);
12022 strcpy (f
, ".debug");
12024 return open_debug_file (filename
);
12027 /* Try to load a debug file based upon the build-id held in the .note.gnu.build-id section. */
12030 load_build_id_debug_file (const char * main_filename ATTRIBUTE_UNUSED
, void * main_file
)
12032 if (! load_debug_section (note_gnu_build_id
, main_file
))
12033 return; /* No .note.gnu.build-id section. */
12035 struct dwarf_section
* section
= & debug_displays
[note_gnu_build_id
].section
;
12036 if (section
== NULL
)
12038 warn (_("Unable to load the .note.gnu.build-id section\n"));
12042 if (section
->start
== NULL
|| section
->size
< 0x18)
12044 warn (_(".note.gnu.build-id section is corrupt/empty\n"));
12048 /* In theory we should extract the contents of the section into
12049 a note structure and then check the fields. For now though
12050 just use hard coded offsets instead:
12052 Field Bytes Contents
12055 Type 8..11 3 (NT_GNU_BUILD_ID)
12059 /* FIXME: Check the name size, name and type fields. */
12061 unsigned long build_id_size
;
12062 build_id_size
= byte_get (section
->start
+ 4, 4);
12063 if (build_id_size
< 8)
12065 warn (_(".note.gnu.build-id data size is too small\n"));
12069 if (build_id_size
> (section
->size
- 16))
12071 warn (_(".note.gnu.build-id data size is too big\n"));
12076 filename
= xmalloc (strlen (".build-id/")
12077 + build_id_size
* 2 + 2
12078 + strlen (".debug")
12079 /* The next string should be the same as the longest
12080 name found in the prefixes[] array below. */
12081 + strlen ("/usrlib64/debug/usr")
12085 static const char * prefixes
[] =
12090 "/usr/lib/debug/usr/",
12091 "/usr/lib64/debug/",
12092 "/usr/lib64/debug/usr"
12094 long unsigned int i
;
12096 for (i
= 0; i
< ARRAY_SIZE (prefixes
); i
++)
12098 handle
= try_build_id_prefix (prefixes
[i
], filename
,
12099 section
->start
+ 16, build_id_size
);
12100 if (handle
!= NULL
)
12103 /* FIXME: TYhe BFD library also tries a global debugfile directory prefix. */
12104 if (handle
== NULL
)
12106 /* Failed to find a debug file associated with the build-id.
12107 This is not an error however, rather it just means that
12108 the debug info has probably not been loaded on the system,
12109 or that another method is being used to link to the debug
12115 add_separate_debug_file (filename
, handle
);
12118 /* Try to load a debug file pointed to by the .debug_sup section. */
12121 load_debug_sup_file (const char * main_filename
, void * file
)
12123 if (! load_debug_section (debug_sup
, file
))
12124 return; /* No .debug_sup section. */
12126 struct dwarf_section
* section
;
12127 section
= & debug_displays
[debug_sup
].section
;
12128 assert (section
!= NULL
);
12130 if (section
->start
== NULL
|| section
->size
< 5)
12132 warn (_(".debug_sup section is corrupt/empty\n"));
12136 if (section
->start
[2] != 0)
12137 return; /* This is a supplementary file. */
12139 const char * filename
= (const char *) section
->start
+ 3;
12140 if (strnlen (filename
, section
->size
- 3) == section
->size
- 3)
12142 warn (_("filename in .debug_sup section is corrupt\n"));
12146 if (filename
[0] != '/' && strchr (main_filename
, '/'))
12151 new_len
= asprintf (& new_name
, "%.*s/%s",
12152 (int) (strrchr (main_filename
, '/') - main_filename
),
12157 warn (_("unable to construct path for supplementary debug file"));
12162 filename
= new_name
;
12166 /* PR 27796: Make sure that we pass a filename that can be free'd to
12167 add_separate_debug_file(). */
12168 filename
= strdup (filename
);
12169 if (filename
== NULL
)
12171 warn (_("out of memory constructing filename for .debug_sup link\n"));
12176 void * handle
= open_debug_file (filename
);
12177 if (handle
== NULL
)
12179 warn (_("unable to open file '%s' referenced from .debug_sup section\n"), filename
);
12180 free ((void *) filename
);
12184 printf (_("%s: Found supplementary debug file: %s\n\n"), main_filename
, filename
);
12186 /* FIXME: Compare the checksums, if present. */
12187 add_separate_debug_file (filename
, handle
);
12190 /* Load a debuglink section and/or a debugaltlink section, if either are present.
12191 Recursively check the loaded files for more of these sections.
12192 Also follow any links in .debug_sup sections.
12193 FIXME: Should also check for DWO_* entries in the newly loaded files. */
12196 check_for_and_load_links (void * file
, const char * filename
)
12198 void * handle
= NULL
;
12200 if (load_debug_section (gnu_debugaltlink
, file
))
12202 Build_id_data build_id_data
;
12204 handle
= load_separate_debug_info (filename
,
12205 & debug_displays
[gnu_debugaltlink
].section
,
12206 parse_gnu_debugaltlink
,
12207 check_gnu_debugaltlink
,
12212 assert (handle
== first_separate_info
->handle
);
12213 check_for_and_load_links (first_separate_info
->handle
,
12214 first_separate_info
->filename
);
12218 if (load_debug_section (gnu_debuglink
, file
))
12220 unsigned long crc32
;
12222 handle
= load_separate_debug_info (filename
,
12223 & debug_displays
[gnu_debuglink
].section
,
12224 parse_gnu_debuglink
,
12225 check_gnu_debuglink
,
12230 assert (handle
== first_separate_info
->handle
);
12231 check_for_and_load_links (first_separate_info
->handle
,
12232 first_separate_info
->filename
);
12236 load_debug_sup_file (filename
, file
);
12238 load_build_id_debug_file (filename
, file
);
12241 /* Load the separate debug info file(s) attached to FILE, if any exist.
12242 Returns TRUE if any were found, FALSE otherwise.
12243 If TRUE is returned then the linked list starting at first_separate_info
12244 will be populated with open file handles. */
12247 load_separate_debug_files (void * file
, const char * filename
)
12249 /* Skip this operation if we are not interested in debug links. */
12250 if (! do_follow_links
&& ! do_debug_links
)
12253 /* See if there are any dwo links. */
12254 if (load_debug_section (str
, file
)
12255 && load_debug_section (abbrev
, file
)
12256 && load_debug_section (info
, file
))
12258 /* Load the .debug_addr section, if it exists. */
12259 load_debug_section (debug_addr
, file
);
12260 /* Load the .debug_str_offsets section, if it exists. */
12261 load_debug_section (str_index
, file
);
12262 /* Load the .debug_loclists section, if it exists. */
12263 load_debug_section (loclists
, file
);
12264 /* Load the .debug_rnglists section, if it exists. */
12265 load_debug_section (rnglists
, file
);
12269 if (process_debug_info (& debug_displays
[info
].section
, file
, abbrev
,
12272 bool introduced
= false;
12274 const char *dir
= NULL
;
12275 const char *id
= NULL
;
12276 const char *name
= NULL
;
12278 for (dwinfo
= first_dwo_info
; dwinfo
!= NULL
; dwinfo
= dwinfo
->next
)
12280 /* Accumulate NAME, DIR and ID fields. */
12281 switch (dwinfo
->type
)
12285 warn (_("Multiple DWO_NAMEs encountered for the same CU\n"));
12286 name
= dwinfo
->value
;
12290 /* There can be multiple DW_AT_comp_dir entries in a CU,
12291 so do not complain. */
12292 dir
= dwinfo
->value
;
12297 warn (_("multiple DWO_IDs encountered for the same CU\n"));
12298 id
= dwinfo
->value
;
12302 error (_("Unexpected DWO INFO type"));
12306 /* If we have reached the end of our list, or we are changing
12307 CUs, then display the information that we have accumulated
12310 && (dwinfo
->next
== NULL
12311 || dwinfo
->next
->cu_offset
!= dwinfo
->cu_offset
))
12313 if (do_debug_links
)
12317 printf (_("The %s section contains link(s) to dwo file(s):\n\n"),
12318 debug_displays
[info
].section
.uncompressed_name
);
12322 printf (_(" Name: %s\n"), name
);
12323 printf (_(" Directory: %s\n"), dir
? dir
: _("<not-found>"));
12325 display_data (printf (_(" ID: ")), (unsigned char *) id
, 8);
12326 else if (debug_information
[0].dwarf_version
!= 5)
12327 printf (_(" ID: <not specified>\n"));
12331 if (do_follow_links
)
12332 load_dwo_file (filename
, name
, dir
, id
);
12334 name
= dir
= id
= NULL
;
12340 if (! do_follow_links
)
12341 /* The other debug links will be displayed by display_debug_links()
12342 so we do not need to do any further processing here. */
12345 /* FIXME: We do not check for the presence of both link sections in the same file. */
12346 /* FIXME: We do not check for the presence of multiple, same-name debuglink sections. */
12347 /* FIXME: We do not check for the presence of a dwo link as well as a debuglink. */
12349 check_for_and_load_links (file
, filename
);
12350 if (first_separate_info
!= NULL
)
12353 do_follow_links
= 0;
12358 free_debug_memory (void)
12362 free_all_abbrevs ();
12366 shndx_pool_size
= 0;
12367 shndx_pool_used
= 0;
12375 memset (level_type_signed
, 0, sizeof level_type_signed
);
12376 cu_tu_indexes_read
= -1;
12378 for (i
= 0; i
< max
; i
++)
12379 free_debug_section ((enum dwarf_section_display_enum
) i
);
12381 if (debug_information
!= NULL
)
12383 for (i
= 0; i
< alloc_num_debug_info_entries
; i
++)
12384 free_debug_information (&debug_information
[i
]);
12385 free (debug_information
);
12386 debug_information
= NULL
;
12387 alloc_num_debug_info_entries
= num_debug_info_entries
= 0;
12391 separate_info
* next
;
12393 for (d
= first_separate_info
; d
!= NULL
; d
= next
)
12395 close_debug_file (d
->handle
);
12396 free ((void *) d
->filename
);
12400 first_separate_info
= NULL
;
12408 const char *option
;
12411 } debug_dump_long_opts
;
12413 static const debug_dump_long_opts debug_option_table
[] =
12415 { 'A', "addr", &do_debug_addr
, 1 },
12416 { 'a', "abbrev", &do_debug_abbrevs
, 1 },
12417 { 'c', "cu_index", &do_debug_cu_index
, 1 },
12418 #ifdef HAVE_LIBDEBUGINFOD
12419 { 'D', "use-debuginfod", &use_debuginfod
, 1 },
12420 { 'E', "do-not-use-debuginfod", &use_debuginfod
, 0 },
12422 { 'F', "frames-interp", &do_debug_frames_interp
, 1 },
12423 { 'f', "frames", &do_debug_frames
, 1 },
12424 { 'g', "gdb_index", &do_gdb_index
, 1 },
12425 { 'i', "info", &do_debug_info
, 1 },
12426 { 'K', "follow-links", &do_follow_links
, 1 },
12427 { 'k', "links", &do_debug_links
, 1 },
12428 { 'L', "decodedline", &do_debug_lines
, FLAG_DEBUG_LINES_DECODED
},
12429 { 'l', "rawline", &do_debug_lines
, FLAG_DEBUG_LINES_RAW
},
12430 /* For compatibility with earlier versions of readelf. */
12431 { 'l', "line", &do_debug_lines
, FLAG_DEBUG_LINES_RAW
},
12432 { 'm', "macro", &do_debug_macinfo
, 1 },
12433 { 'N', "no-follow-links", &do_follow_links
, 0 },
12434 { 'O', "str-offsets", &do_debug_str_offsets
, 1 },
12435 { 'o', "loc", &do_debug_loc
, 1 },
12436 { 'p', "pubnames", &do_debug_pubnames
, 1 },
12437 { 'R', "Ranges", &do_debug_ranges
, 1 },
12438 { 'r', "aranges", &do_debug_aranges
, 1 },
12439 /* For compatibility with earlier versions of readelf. */
12440 { 'r', "ranges", &do_debug_aranges
, 1 },
12441 { 's', "str", &do_debug_str
, 1 },
12442 { 'T', "trace_aranges", &do_trace_aranges
, 1 },
12443 { 't', "pubtypes", &do_debug_pubtypes
, 1 },
12444 { 'U', "trace_info", &do_trace_info
, 1 },
12445 { 'u', "trace_abbrev", &do_trace_abbrevs
, 1 },
12446 { 0, NULL
, NULL
, 0 }
12449 /* Enable display of specific DWARF sections as determined by the comma
12450 separated strings in NAMES. Returns non-zero if any displaying was
12454 dwarf_select_sections_by_names (const char *names
)
12462 const debug_dump_long_opts
*entry
;
12464 for (entry
= debug_option_table
; entry
->option
; entry
++)
12466 size_t len
= strlen (entry
->option
);
12468 if (strncmp (p
, entry
->option
, len
) == 0
12469 && (p
[len
] == ',' || p
[len
] == '\0'))
12471 if (entry
->val
== 0)
12472 * entry
->variable
= 0;
12474 * entry
->variable
= entry
->val
;
12475 result
|= entry
->val
;
12482 if (entry
->option
== NULL
)
12484 warn (_("Unrecognized debug option '%s'\n"), p
);
12485 p
= strchr (p
, ',');
12494 /* The --debug-dump=frames-interp option also enables the
12495 --debug-dump=frames option. */
12496 if (do_debug_frames_interp
)
12497 do_debug_frames
= 1;
12502 /* Enable display of specific DWARF sections as determined by the characters
12503 in LETTERS. Returns non-zero if any displaying was enabled. */
12506 dwarf_select_sections_by_letters (const char *letters
)
12512 const debug_dump_long_opts
*entry
;
12514 for (entry
= debug_option_table
; entry
->letter
; entry
++)
12516 if (entry
->letter
== * letters
)
12518 if (entry
->val
== 0)
12519 * entry
->variable
= 0;
12521 * entry
->variable
|= entry
->val
;
12522 result
|= entry
->val
;
12527 if (entry
->letter
== 0)
12528 warn (_("Unrecognized debug letter option '%c'\n"), * letters
);
12533 /* The --debug-dump=frames-interp option also enables the
12534 --debug-dump=frames option. */
12535 if (do_debug_frames_interp
)
12536 do_debug_frames
= 1;
12542 dwarf_select_sections_all (void)
12545 do_debug_abbrevs
= 1;
12546 do_debug_lines
= FLAG_DEBUG_LINES_RAW
;
12547 do_debug_pubnames
= 1;
12548 do_debug_pubtypes
= 1;
12549 do_debug_aranges
= 1;
12550 do_debug_ranges
= 1;
12551 do_debug_frames
= 1;
12552 do_debug_macinfo
= 1;
12557 do_trace_abbrevs
= 1;
12558 do_trace_aranges
= 1;
12560 do_debug_cu_index
= 1;
12561 do_follow_links
= 1;
12562 do_debug_links
= 1;
12563 do_debug_str_offsets
= 1;
12566 #define NO_ABBREVS NULL, NULL, NULL, 0, 0, 0, NULL, 0
12567 #define ABBREV(N) NULL, NULL, NULL, 0, 0, N, NULL, 0
12569 /* N.B. The order here must match the order in section_display_enum. */
12571 struct dwarf_section_display debug_displays
[] =
12573 { { ".debug_abbrev", ".zdebug_abbrev", ".dwabrev", NO_ABBREVS
}, display_debug_abbrev
, &do_debug_abbrevs
, false },
12574 { { ".debug_aranges", ".zdebug_aranges", ".dwarnge", NO_ABBREVS
}, display_debug_aranges
, &do_debug_aranges
, true },
12575 { { ".debug_frame", ".zdebug_frame", ".dwframe", NO_ABBREVS
}, display_debug_frames
, &do_debug_frames
, true },
12576 { { ".debug_info", ".zdebug_info", ".dwinfo", ABBREV (abbrev
)}, display_debug_info
, &do_debug_info
, true },
12577 { { ".debug_line", ".zdebug_line", ".dwline", NO_ABBREVS
}, display_debug_lines
, &do_debug_lines
, true },
12578 { { ".debug_pubnames", ".zdebug_pubnames", ".dwpbnms", NO_ABBREVS
}, display_debug_pubnames
, &do_debug_pubnames
, false },
12579 { { ".debug_gnu_pubnames", ".zdebug_gnu_pubnames", "", NO_ABBREVS
}, display_debug_gnu_pubnames
, &do_debug_pubnames
, false },
12580 { { ".eh_frame", "", "", NO_ABBREVS
}, display_debug_frames
, &do_debug_frames
, true },
12581 { { ".debug_macinfo", ".zdebug_macinfo", "", NO_ABBREVS
}, display_debug_macinfo
, &do_debug_macinfo
, false },
12582 { { ".debug_macro", ".zdebug_macro", ".dwmac", NO_ABBREVS
}, display_debug_macro
, &do_debug_macinfo
, true },
12583 { { ".debug_str", ".zdebug_str", ".dwstr", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, false },
12584 { { ".debug_line_str", ".zdebug_line_str", "", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, false },
12585 { { ".debug_loc", ".zdebug_loc", ".dwloc", NO_ABBREVS
}, display_debug_loc
, &do_debug_loc
, true },
12586 { { ".debug_loclists", ".zdebug_loclists", "", NO_ABBREVS
}, display_debug_loc
, &do_debug_loc
, true },
12587 { { ".debug_loclists.dwo", ".zdebug_loclists.dwo", "", NO_ABBREVS
}, display_debug_loc
, &do_debug_loc
, true },
12588 { { ".debug_pubtypes", ".zdebug_pubtypes", ".dwpbtyp", NO_ABBREVS
}, display_debug_pubnames
, &do_debug_pubtypes
, false },
12589 { { ".debug_gnu_pubtypes", ".zdebug_gnu_pubtypes", "", NO_ABBREVS
}, display_debug_gnu_pubnames
, &do_debug_pubtypes
, false },
12590 { { ".debug_ranges", ".zdebug_ranges", ".dwrnges", NO_ABBREVS
}, display_debug_ranges
, &do_debug_ranges
, true },
12591 { { ".debug_rnglists", ".zdebug_rnglists", "", NO_ABBREVS
}, display_debug_ranges
, &do_debug_ranges
, true },
12592 { { ".debug_rnglists.dwo", ".zdebug_rnglists.dwo", "", NO_ABBREVS
}, display_debug_ranges
, &do_debug_ranges
, true },
12593 { { ".debug_static_func", ".zdebug_static_func", "", NO_ABBREVS
}, display_debug_not_supported
, NULL
, false },
12594 { { ".debug_static_vars", ".zdebug_static_vars", "", NO_ABBREVS
}, display_debug_not_supported
, NULL
, false },
12595 { { ".debug_types", ".zdebug_types", "", ABBREV (abbrev
) }, display_debug_types
, &do_debug_info
, true },
12596 { { ".debug_weaknames", ".zdebug_weaknames", "", NO_ABBREVS
}, display_debug_not_supported
, NULL
, false },
12597 { { ".gdb_index", "", "", NO_ABBREVS
}, display_gdb_index
, &do_gdb_index
, false },
12598 { { ".debug_names", "", "", NO_ABBREVS
}, display_debug_names
, &do_gdb_index
, false },
12599 { { ".trace_info", "", "", ABBREV (trace_abbrev
) }, display_trace_info
, &do_trace_info
, true },
12600 { { ".trace_abbrev", "", "", NO_ABBREVS
}, display_debug_abbrev
, &do_trace_abbrevs
, false },
12601 { { ".trace_aranges", "", "", NO_ABBREVS
}, display_debug_aranges
, &do_trace_aranges
, false },
12602 { { ".debug_info.dwo", ".zdebug_info.dwo", "", ABBREV (abbrev_dwo
) }, display_debug_info
, &do_debug_info
, true },
12603 { { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo", "", NO_ABBREVS
}, display_debug_abbrev
, &do_debug_abbrevs
, false },
12604 { { ".debug_types.dwo", ".zdebug_types.dwo", "", ABBREV (abbrev_dwo
) }, display_debug_types
, &do_debug_info
, true },
12605 { { ".debug_line.dwo", ".zdebug_line.dwo", "", NO_ABBREVS
}, display_debug_lines
, &do_debug_lines
, true },
12606 { { ".debug_loc.dwo", ".zdebug_loc.dwo", "", NO_ABBREVS
}, display_debug_loc
, &do_debug_loc
, true },
12607 { { ".debug_macro.dwo", ".zdebug_macro.dwo", "", NO_ABBREVS
}, display_debug_macro
, &do_debug_macinfo
, true },
12608 { { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo", "", NO_ABBREVS
}, display_debug_macinfo
, &do_debug_macinfo
, false },
12609 { { ".debug_str.dwo", ".zdebug_str.dwo", "", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, true },
12610 { { ".debug_str_offsets", ".zdebug_str_offsets", "", NO_ABBREVS
}, display_debug_str_offsets
, &do_debug_str_offsets
, true },
12611 { { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo", "", NO_ABBREVS
}, display_debug_str_offsets
, &do_debug_str_offsets
, true },
12612 { { ".debug_addr", ".zdebug_addr", "", NO_ABBREVS
}, display_debug_addr
, &do_debug_addr
, true },
12613 { { ".debug_cu_index", "", "", NO_ABBREVS
}, display_cu_index
, &do_debug_cu_index
, false },
12614 { { ".debug_tu_index", "", "", NO_ABBREVS
}, display_cu_index
, &do_debug_cu_index
, false },
12615 { { ".gnu_debuglink", "", "", NO_ABBREVS
}, display_debug_links
, &do_debug_links
, false },
12616 { { ".gnu_debugaltlink", "", "", NO_ABBREVS
}, display_debug_links
, &do_debug_links
, false },
12617 { { ".debug_sup", "", "", NO_ABBREVS
}, display_debug_sup
, &do_debug_links
, false },
12618 /* Separate debug info files can containt their own .debug_str section,
12619 and this might be in *addition* to a .debug_str section already present
12620 in the main file. Hence we need to have two entries for .debug_str. */
12621 { { ".debug_str", ".zdebug_str", "", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, false },
12622 { { ".note.gnu.build-id", "", "", NO_ABBREVS
}, display_debug_not_supported
, NULL
, false },
12625 /* A static assertion. */
12626 extern int debug_displays_assert
[ARRAY_SIZE (debug_displays
) == max
? 1 : -1];