1 /* dwarf.c -- display DWARF contents of a BFD binary file
2 Copyright (C) 2005-2021 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>
46 #define MAX(a, b) ((a) > (b) ? (a) : (b))
47 #define MIN(a, b) ((a) < (b) ? (a) : (b))
49 static const char *regname (unsigned int regno
, int row
);
50 static const char *regname_internal_by_table_only (unsigned int regno
);
52 static int have_frame_base
;
53 static int need_base_address
;
55 static unsigned int num_debug_info_entries
= 0;
56 static unsigned int alloc_num_debug_info_entries
= 0;
57 static debug_info
*debug_information
= NULL
;
58 /* Special value for num_debug_info_entries to indicate
59 that the .debug_info section could not be loaded/parsed. */
60 #define DEBUG_INFO_UNAVAILABLE (unsigned int) -1
62 /* A .debug_info section can contain multiple links to separate
63 DWO object files. We use these structures to record these links. */
71 typedef struct dwo_info
76 struct dwo_info
* next
;
79 static dwo_info
*first_dwo_info
= NULL
;
80 static bool need_dwo_info
;
82 separate_info
* first_separate_info
= NULL
;
84 unsigned int eh_addr_size
;
89 int do_debug_pubnames
;
90 int do_debug_pubtypes
;
94 int do_debug_frames_interp
;
97 int do_debug_str_offsets
;
101 int do_trace_abbrevs
;
102 int do_trace_aranges
;
104 int do_debug_cu_index
;
107 int do_follow_links
= DEFAULT_FOR_FOLLOW_LINKS
;
110 int dwarf_cutoff_level
= -1;
111 unsigned long dwarf_start_die
;
115 /* Convenient constant, to avoid having to cast -1 to dwarf_vma when
116 testing whether e.g. a locview list is present. */
117 static const dwarf_vma vm1
= -1;
119 /* Collection of CU/TU section sets from .debug_cu_index and .debug_tu_index
120 sections. For version 1 package files, each set is stored in SHNDX_POOL
121 as a zero-terminated list of section indexes comprising one set of debug
122 sections from a .dwo file. */
124 static unsigned int *shndx_pool
= NULL
;
125 static unsigned int shndx_pool_size
= 0;
126 static unsigned int shndx_pool_used
= 0;
128 /* For version 2 package files, each set contains an array of section offsets
129 and an array of section sizes, giving the offset and size of the
130 contribution from a CU or TU within one of the debug sections.
131 When displaying debug info from a package file, we need to use these
132 tables to locate the corresponding contributions to each section. */
137 dwarf_vma section_offsets
[DW_SECT_MAX
];
138 size_t section_sizes
[DW_SECT_MAX
];
141 static int cu_count
= 0;
142 static int tu_count
= 0;
143 static struct cu_tu_set
*cu_sets
= NULL
;
144 static struct cu_tu_set
*tu_sets
= NULL
;
146 static bool load_cu_tu_indexes (void *);
148 /* An array that indicates for a given level of CU nesting whether
149 the latest DW_AT_type seen for that level was a signed type or
151 #define MAX_CU_NESTING (1 << 8)
152 static bool level_type_signed
[MAX_CU_NESTING
];
154 /* Values for do_debug_lines. */
155 #define FLAG_DEBUG_LINES_RAW 1
156 #define FLAG_DEBUG_LINES_DECODED 2
159 size_of_encoded_value (int encoding
)
161 switch (encoding
& 0x7)
164 case 0: return eh_addr_size
;
172 get_encoded_value (unsigned char **pdata
,
174 struct dwarf_section
*section
,
177 unsigned char * data
= * pdata
;
178 unsigned int size
= size_of_encoded_value (encoding
);
181 if (data
+ size
>= end
)
183 warn (_("Encoded value extends past end of section\n"));
188 /* PR 17512: file: 002-829853-0.004. */
191 warn (_("Encoded size of %d is too large to read\n"), size
);
196 /* PR 17512: file: 1085-5603-0.004. */
199 warn (_("Encoded size of 0 is too small to read\n"));
204 if (encoding
& DW_EH_PE_signed
)
205 val
= byte_get_signed (data
, size
);
207 val
= byte_get (data
, size
);
209 if ((encoding
& 0x70) == DW_EH_PE_pcrel
)
210 val
+= section
->address
+ (data
- section
->start
);
212 * pdata
= data
+ size
;
216 #if SIZEOF_LONG_LONG > SIZEOF_LONG
218 # define DWARF_VMA_FMT "ll"
219 # define DWARF_VMA_FMT_LONG "%16.16llx"
221 # define DWARF_VMA_FMT "I64"
222 # define DWARF_VMA_FMT_LONG "%016I64x"
225 # define DWARF_VMA_FMT "l"
226 # define DWARF_VMA_FMT_LONG "%16.16lx"
229 /* Convert a dwarf vma value into a string. Returns a pointer to a static
230 buffer containing the converted VALUE. The value is converted according
231 to the printf formating character FMTCH. If NUM_BYTES is non-zero then
232 it specifies the maximum number of bytes to be displayed in the converted
233 value and FMTCH is ignored - hex is always used. */
236 dwarf_vmatoa_1 (const char *fmtch
, dwarf_vma value
, unsigned num_bytes
)
238 /* As dwarf_vmatoa is used more then once in a printf call
239 for output, we are cycling through an fixed array of pointers
240 for return address. */
241 static int buf_pos
= 0;
242 static struct dwarf_vmatoa_buf
248 ret
= buf
[buf_pos
++].place
;
249 buf_pos
%= ARRAY_SIZE (buf
);
253 /* Printf does not have a way of specifying a maximum field width for an
254 integer value, so we print the full value into a buffer and then select
255 the precision we need. */
256 snprintf (ret
, sizeof (buf
[0].place
), DWARF_VMA_FMT_LONG
, value
);
259 return ret
+ (16 - 2 * num_bytes
);
266 sprintf (fmt
, "%%%s%s", DWARF_VMA_FMT
, fmtch
);
268 sprintf (fmt
, "%%%s", DWARF_VMA_FMT
);
269 snprintf (ret
, sizeof (buf
[0].place
), fmt
, value
);
274 static inline const char *
275 dwarf_vmatoa (const char * fmtch
, dwarf_vma value
)
277 return dwarf_vmatoa_1 (fmtch
, value
, 0);
280 /* Print a dwarf_vma value (typically an address, offset or length) in
281 hexadecimal format, followed by a space. The length of the VALUE (and
282 hence the precision displayed) is determined by the NUM_BYTES parameter. */
285 print_dwarf_vma (dwarf_vma value
, unsigned num_bytes
)
287 printf ("%s ", dwarf_vmatoa_1 (NULL
, value
, num_bytes
));
290 /* Print a view number in hexadecimal value, with the same width
291 print_dwarf_vma would have printed it with the same num_bytes.
292 Print blanks for zero view, unless force is nonzero. */
295 print_dwarf_view (dwarf_vma value
, unsigned num_bytes
, int force
)
303 assert (value
== (unsigned long) value
);
305 printf ("v%0*lx ", len
- 1, (unsigned long) value
);
307 printf ("%*s", len
+ 1, "");
310 /* Read in a LEB128 encoded value starting at address DATA.
311 If SIGN is true, return a signed LEB128 value.
312 If LENGTH_RETURN is not NULL, return in it the number of bytes read.
313 If STATUS_RETURN is not NULL, return with bit 0 (LSB) set if the
314 terminating byte was not found and with bit 1 set if the value
315 overflows a dwarf_vma.
316 No bytes will be read at address END or beyond. */
319 read_leb128 (unsigned char *data
,
320 const unsigned char *const end
,
322 unsigned int *length_return
,
325 dwarf_vma result
= 0;
326 unsigned int num_read
= 0;
327 unsigned int shift
= 0;
332 unsigned char byte
= *data
++;
333 unsigned char lost
, mask
;
337 if (shift
< CHAR_BIT
* sizeof (result
))
339 result
|= ((dwarf_vma
) (byte
& 0x7f)) << shift
;
340 /* These bits overflowed. */
341 lost
= byte
^ (result
>> shift
);
342 /* And this is the mask of possible overflow bits. */
343 mask
= 0x7f ^ ((dwarf_vma
) 0x7f << shift
>> shift
);
351 if ((lost
& mask
) != (sign
&& (dwarf_signed_vma
) result
< 0 ? mask
: 0))
354 if ((byte
& 0x80) == 0)
357 if (sign
&& shift
< CHAR_BIT
* sizeof (result
) && (byte
& 0x40))
358 result
|= -((dwarf_vma
) 1 << shift
);
363 if (length_return
!= NULL
)
364 *length_return
= num_read
;
365 if (status_return
!= NULL
)
366 *status_return
= status
;
371 /* Read AMOUNT bytes from PTR and store them in VAL as an unsigned value.
372 Checks to make sure that the read will not reach or pass END
373 and that VAL is big enough to hold AMOUNT bytes. */
374 #define SAFE_BYTE_GET(VAL, PTR, AMOUNT, END) \
377 unsigned int amount = (AMOUNT); \
378 if (sizeof (VAL) < amount) \
380 error (ngettext ("internal error: attempt to read %d byte " \
381 "of data in to %d sized variable", \
382 "internal error: attempt to read %d bytes " \
383 "of data in to %d sized variable", \
385 amount, (int) sizeof (VAL)); \
386 amount = sizeof (VAL); \
388 if ((PTR) >= (END) - amount) \
391 amount = (END) - (PTR); \
395 if (amount == 0 || amount > 8) \
398 VAL = byte_get ((PTR), amount); \
402 /* Like SAFE_BYTE_GET, but also increments PTR by AMOUNT. */
403 #define SAFE_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \
406 SAFE_BYTE_GET (VAL, PTR, AMOUNT, END); \
411 /* Like SAFE_BYTE_GET, but reads a signed value. */
412 #define SAFE_SIGNED_BYTE_GET(VAL, PTR, AMOUNT, END) \
415 unsigned int amount = (AMOUNT); \
416 if ((PTR) >= (END) - amount) \
419 amount = (END) - (PTR); \
424 VAL = byte_get_signed ((PTR), amount); \
430 /* Like SAFE_SIGNED_BYTE_GET, but also increments PTR by AMOUNT. */
431 #define SAFE_SIGNED_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \
434 SAFE_SIGNED_BYTE_GET (VAL, PTR, AMOUNT, END); \
439 typedef struct State_Machine_Registers
448 unsigned char op_index
;
449 unsigned char end_sequence
;
450 /* This variable hold the number of the last entry seen
451 in the File Table. */
452 unsigned int last_file_entry
;
455 static SMR state_machine_regs
;
458 reset_state_machine (int is_stmt
)
460 state_machine_regs
.address
= 0;
461 state_machine_regs
.view
= 0;
462 state_machine_regs
.op_index
= 0;
463 state_machine_regs
.file
= 1;
464 state_machine_regs
.line
= 1;
465 state_machine_regs
.column
= 0;
466 state_machine_regs
.is_stmt
= is_stmt
;
467 state_machine_regs
.basic_block
= 0;
468 state_machine_regs
.end_sequence
= 0;
469 state_machine_regs
.last_file_entry
= 0;
472 /* Handled an extend line op.
473 Returns the number of bytes read. */
476 process_extended_line_op (unsigned char * data
,
480 unsigned char op_code
;
481 size_t len
, header_len
;
483 unsigned char *orig_data
= data
;
486 READ_ULEB (len
, data
, end
);
487 header_len
= data
- orig_data
;
489 if (len
== 0 || data
>= end
|| len
> (size_t) (end
- data
))
491 warn (_("Badly formed extended line op encountered!\n"));
497 printf (_(" Extended opcode %d: "), op_code
);
501 case DW_LNE_end_sequence
:
502 printf (_("End of Sequence\n\n"));
503 reset_state_machine (is_stmt
);
506 case DW_LNE_set_address
:
507 /* PR 17512: file: 002-100480-0.004. */
510 warn (_("Length (%lu) of DW_LNE_set_address op is too long\n"),
511 (unsigned long) len
- 1);
515 SAFE_BYTE_GET (adr
, data
, len
- 1, end
);
516 printf (_("set Address to 0x%s\n"), dwarf_vmatoa ("x", adr
));
517 state_machine_regs
.address
= adr
;
518 state_machine_regs
.view
= 0;
519 state_machine_regs
.op_index
= 0;
522 case DW_LNE_define_file
:
523 printf (_("define new File Table entry\n"));
524 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
525 printf (" %d\t", ++state_machine_regs
.last_file_entry
);
531 l
= strnlen ((char *) data
, end
- data
);
533 READ_ULEB (val
, data
, end
);
534 printf ("%s\t", dwarf_vmatoa ("u", val
));
535 READ_ULEB (val
, data
, end
);
536 printf ("%s\t", dwarf_vmatoa ("u", val
));
537 READ_ULEB (val
, data
, end
);
538 printf ("%s\t", dwarf_vmatoa ("u", val
));
539 printf ("%.*s\n\n", (int) l
, name
);
542 if (((size_t) (data
- orig_data
) != len
+ header_len
) || data
>= end
)
543 warn (_("DW_LNE_define_file: Bad opcode length\n"));
546 case DW_LNE_set_discriminator
:
547 READ_ULEB (val
, data
, end
);
548 printf (_("set Discriminator to %s\n"), dwarf_vmatoa ("u", val
));
552 case DW_LNE_HP_negate_is_UV_update
:
553 printf ("DW_LNE_HP_negate_is_UV_update\n");
555 case DW_LNE_HP_push_context
:
556 printf ("DW_LNE_HP_push_context\n");
558 case DW_LNE_HP_pop_context
:
559 printf ("DW_LNE_HP_pop_context\n");
561 case DW_LNE_HP_set_file_line_column
:
562 printf ("DW_LNE_HP_set_file_line_column\n");
564 case DW_LNE_HP_set_routine_name
:
565 printf ("DW_LNE_HP_set_routine_name\n");
567 case DW_LNE_HP_set_sequence
:
568 printf ("DW_LNE_HP_set_sequence\n");
570 case DW_LNE_HP_negate_post_semantics
:
571 printf ("DW_LNE_HP_negate_post_semantics\n");
573 case DW_LNE_HP_negate_function_exit
:
574 printf ("DW_LNE_HP_negate_function_exit\n");
576 case DW_LNE_HP_negate_front_end_logical
:
577 printf ("DW_LNE_HP_negate_front_end_logical\n");
579 case DW_LNE_HP_define_proc
:
580 printf ("DW_LNE_HP_define_proc\n");
582 case DW_LNE_HP_source_file_correlation
:
584 unsigned char *edata
= data
+ len
- 1;
586 printf ("DW_LNE_HP_source_file_correlation\n");
592 READ_ULEB (opc
, data
, edata
);
596 case DW_LNE_HP_SFC_formfeed
:
597 printf (" DW_LNE_HP_SFC_formfeed\n");
599 case DW_LNE_HP_SFC_set_listing_line
:
600 READ_ULEB (val
, data
, edata
);
601 printf (" DW_LNE_HP_SFC_set_listing_line (%s)\n",
602 dwarf_vmatoa ("u", val
));
604 case DW_LNE_HP_SFC_associate
:
605 printf (" DW_LNE_HP_SFC_associate ");
606 READ_ULEB (val
, data
, edata
);
607 printf ("(%s", dwarf_vmatoa ("u", val
));
608 READ_ULEB (val
, data
, edata
);
609 printf (",%s", dwarf_vmatoa ("u", val
));
610 READ_ULEB (val
, data
, edata
);
611 printf (",%s)\n", dwarf_vmatoa ("u", val
));
614 printf (_(" UNKNOWN DW_LNE_HP_SFC opcode (%u)\n"), opc
);
624 unsigned int rlen
= len
- 1;
626 if (op_code
>= DW_LNE_lo_user
627 /* The test against DW_LNW_hi_user is redundant due to
628 the limited range of the unsigned char data type used
630 /*&& op_code <= DW_LNE_hi_user*/)
631 printf (_("user defined: "));
633 printf (_("UNKNOWN: "));
634 printf (_("length %d ["), rlen
);
636 printf (" %02x", *data
++);
642 return len
+ header_len
;
645 static const unsigned char *
646 fetch_indirect_string (dwarf_vma offset
)
648 struct dwarf_section
*section
= &debug_displays
[str
].section
;
649 const unsigned char * ret
;
651 if (section
->start
== NULL
)
652 return (const unsigned char *) _("<no .debug_str section>");
654 if (offset
>= section
->size
)
656 warn (_("DW_FORM_strp offset too big: 0x%s\n"),
657 dwarf_vmatoa ("x", offset
));
658 return (const unsigned char *) _("<offset is too big>");
661 ret
= section
->start
+ offset
;
662 /* Unfortunately we cannot rely upon the .debug_str section ending with a
663 NUL byte. Since our caller is expecting to receive a well formed C
664 string we test for the lack of a terminating byte here. */
665 if (strnlen ((const char *) ret
, section
->size
- offset
)
666 == section
->size
- offset
)
667 ret
= (const unsigned char *)
668 _("<no NUL byte at end of .debug_str section>");
673 static const unsigned char *
674 fetch_indirect_line_string (dwarf_vma offset
)
676 struct dwarf_section
*section
= &debug_displays
[line_str
].section
;
677 const unsigned char * ret
;
679 if (section
->start
== NULL
)
680 return (const unsigned char *) _("<no .debug_line_str section>");
682 if (offset
>= section
->size
)
684 warn (_("DW_FORM_line_strp offset too big: 0x%s\n"),
685 dwarf_vmatoa ("x", offset
));
686 return (const unsigned char *) _("<offset is too big>");
689 ret
= section
->start
+ offset
;
690 /* Unfortunately we cannot rely upon the .debug_line_str section ending
691 with a NUL byte. Since our caller is expecting to receive a well formed
692 C string we test for the lack of a terminating byte here. */
693 if (strnlen ((const char *) ret
, section
->size
- offset
)
694 == section
->size
- offset
)
695 ret
= (const unsigned char *)
696 _("<no NUL byte at end of .debug_line_str section>");
702 fetch_indexed_string (dwarf_vma idx
, struct cu_tu_set
*this_set
,
703 dwarf_vma offset_size
, bool dwo
)
705 enum dwarf_section_display_enum str_sec_idx
= dwo
? str_dwo
: str
;
706 enum dwarf_section_display_enum idx_sec_idx
= dwo
? str_index_dwo
: str_index
;
707 struct dwarf_section
*index_section
= &debug_displays
[idx_sec_idx
].section
;
708 struct dwarf_section
*str_section
= &debug_displays
[str_sec_idx
].section
;
709 dwarf_vma index_offset
;
710 dwarf_vma str_offset
;
712 unsigned char *curr
= index_section
->start
;
713 unsigned char *end
= curr
+ index_section
->size
;
716 if (index_section
->start
== NULL
)
717 return (dwo
? _("<no .debug_str_offsets.dwo section>")
718 : _("<no .debug_str_offsets section>"));
720 if (str_section
->start
== NULL
)
721 return (dwo
? _("<no .debug_str.dwo section>")
722 : _("<no .debug_str section>"));
724 /* FIXME: We should cache the length... */
725 SAFE_BYTE_GET_AND_INC (length
, curr
, 4, end
);
726 if (length
== 0xffffffff)
728 if (offset_size
!= 8)
729 warn (_("Expected offset size of 8 but given %s"), dwarf_vmatoa ("x", offset_size
));
730 SAFE_BYTE_GET_AND_INC (length
, curr
, 8, end
);
732 else if (offset_size
!= 4)
734 warn (_("Expected offset size of 4 but given %s"), dwarf_vmatoa ("x", offset_size
));
739 /* This is probably an old style .debug_str_offset section which
740 just contains offsets and no header (and the first offset is 0). */
741 curr
= index_section
->start
;
742 length
= index_section
->size
;
746 /* Skip the version and padding bytes.
747 We assume that they are correct. */
758 && this_set
->section_sizes
[DW_SECT_STR_OFFSETS
] < length
)
759 length
= this_set
->section_sizes
[DW_SECT_STR_OFFSETS
];
761 if (length
> (dwarf_vma
) (end
- curr
))
763 warn (_("index table size too large for section %s vs %s\n"),
764 dwarf_vmatoa ("x", length
),
765 dwarf_vmatoa ("x", index_section
->size
));
769 if (length
< offset_size
)
771 warn (_("index table size %s is too small\n"),
772 dwarf_vmatoa ("x", length
));
773 return _("<table too small>");
777 index_offset
= idx
* offset_size
;
779 if (this_set
!= NULL
)
780 index_offset
+= this_set
->section_offsets
[DW_SECT_STR_OFFSETS
];
782 if (index_offset
>= length
783 || length
- index_offset
< offset_size
)
785 warn (_("DW_FORM_GNU_str_index offset too big: 0x%s vs 0x%s\n"),
786 dwarf_vmatoa ("x", index_offset
),
787 dwarf_vmatoa ("x", length
));
788 return _("<index offset is too big>");
791 str_offset
= byte_get (curr
+ index_offset
, offset_size
);
792 str_offset
-= str_section
->address
;
793 if (str_offset
>= str_section
->size
)
795 warn (_("DW_FORM_GNU_str_index indirect offset too big: 0x%s\n"),
796 dwarf_vmatoa ("x", str_offset
));
797 return _("<indirect index offset is too big>");
800 ret
= (const char *) str_section
->start
+ str_offset
;
801 /* Unfortunately we cannot rely upon str_section ending with a NUL byte.
802 Since our caller is expecting to receive a well formed C string we test
803 for the lack of a terminating byte here. */
804 if (strnlen (ret
, str_section
->size
- str_offset
)
805 == str_section
->size
- str_offset
)
806 ret
= (const char *) _("<no NUL byte at end of section>");
812 fetch_indexed_value (dwarf_vma offset
, dwarf_vma bytes
)
814 struct dwarf_section
*section
= &debug_displays
[debug_addr
].section
;
816 if (section
->start
== NULL
)
817 return (_("<no .debug_addr section>"));
819 if (offset
+ bytes
> section
->size
)
821 warn (_("Offset into section %s too big: 0x%s\n"),
822 section
->name
, dwarf_vmatoa ("x", offset
));
823 return "<offset too big>";
826 return dwarf_vmatoa ("x", byte_get (section
->start
+ offset
, bytes
));
830 /* FIXME: There are better and more efficient ways to handle
831 these structures. For now though, I just want something that
832 is simple to implement. */
833 /* Records a single attribute in an abbrev. */
834 typedef struct abbrev_attr
836 unsigned long attribute
;
838 bfd_signed_vma implicit_const
;
839 struct abbrev_attr
* next
;
843 /* Records a single abbrev. */
844 typedef struct abbrev_entry
846 unsigned long number
;
849 struct abbrev_attr
* first_attr
;
850 struct abbrev_attr
* last_attr
;
851 struct abbrev_entry
* next
;
855 /* Records a set of abbreviations. */
856 typedef struct abbrev_list
858 abbrev_entry
* first_abbrev
;
859 abbrev_entry
* last_abbrev
;
860 dwarf_vma abbrev_base
;
861 dwarf_vma abbrev_offset
;
862 struct abbrev_list
* next
;
863 unsigned char * start_of_next_abbrevs
;
867 /* Records all the abbrevs found so far. */
868 static struct abbrev_list
* abbrev_lists
= NULL
;
870 typedef struct abbrev_map
877 /* Maps between CU offsets and abbrev sets. */
878 static abbrev_map
* cu_abbrev_map
= NULL
;
879 static unsigned long num_abbrev_map_entries
= 0;
880 static unsigned long next_free_abbrev_map_entry
= 0;
882 #define INITIAL_NUM_ABBREV_MAP_ENTRIES 8
883 #define ABBREV_MAP_ENTRIES_INCREMENT 8
886 record_abbrev_list_for_cu (dwarf_vma start
, dwarf_vma end
, abbrev_list
* list
)
888 if (cu_abbrev_map
== NULL
)
890 num_abbrev_map_entries
= INITIAL_NUM_ABBREV_MAP_ENTRIES
;
891 cu_abbrev_map
= xmalloc (num_abbrev_map_entries
* sizeof (* cu_abbrev_map
));
893 else if (next_free_abbrev_map_entry
== num_abbrev_map_entries
)
895 num_abbrev_map_entries
+= ABBREV_MAP_ENTRIES_INCREMENT
;
896 cu_abbrev_map
= xrealloc (cu_abbrev_map
, num_abbrev_map_entries
* sizeof (* cu_abbrev_map
));
899 cu_abbrev_map
[next_free_abbrev_map_entry
].start
= start
;
900 cu_abbrev_map
[next_free_abbrev_map_entry
].end
= end
;
901 cu_abbrev_map
[next_free_abbrev_map_entry
].list
= list
;
902 next_free_abbrev_map_entry
++;
906 free_all_abbrevs (void)
910 for (list
= abbrev_lists
; list
!= NULL
;)
912 abbrev_list
* next
= list
->next
;
913 abbrev_entry
* abbrv
;
915 for (abbrv
= list
->first_abbrev
; abbrv
!= NULL
;)
917 abbrev_entry
* next_abbrev
= abbrv
->next
;
920 for (attr
= abbrv
->first_attr
; attr
;)
922 abbrev_attr
*next_attr
= attr
->next
;
940 new_abbrev_list (dwarf_vma abbrev_base
, dwarf_vma abbrev_offset
)
942 abbrev_list
* list
= (abbrev_list
*) xcalloc (sizeof * list
, 1);
944 list
->abbrev_base
= abbrev_base
;
945 list
->abbrev_offset
= abbrev_offset
;
947 list
->next
= abbrev_lists
;
954 find_abbrev_list_by_abbrev_offset (dwarf_vma abbrev_base
,
955 dwarf_vma abbrev_offset
)
959 for (list
= abbrev_lists
; list
!= NULL
; list
= list
->next
)
960 if (list
->abbrev_base
== abbrev_base
961 && list
->abbrev_offset
== abbrev_offset
)
967 /* Find the abbreviation map for the CU that includes OFFSET.
968 OFFSET is an absolute offset from the start of the .debug_info section. */
969 /* FIXME: This function is going to slow down readelf & objdump.
970 Consider using a better algorithm to mitigate this effect. */
973 find_abbrev_map_by_offset (dwarf_vma offset
)
977 for (i
= 0; i
< next_free_abbrev_map_entry
; i
++)
978 if (cu_abbrev_map
[i
].start
<= offset
979 && cu_abbrev_map
[i
].end
> offset
)
980 return cu_abbrev_map
+ i
;
986 add_abbrev (unsigned long number
,
991 abbrev_entry
* entry
;
993 entry
= (abbrev_entry
*) xmalloc (sizeof (*entry
));
995 entry
->number
= number
;
997 entry
->children
= children
;
998 entry
->first_attr
= NULL
;
999 entry
->last_attr
= NULL
;
1002 assert (list
!= NULL
);
1004 if (list
->first_abbrev
== NULL
)
1005 list
->first_abbrev
= entry
;
1007 list
->last_abbrev
->next
= entry
;
1009 list
->last_abbrev
= entry
;
1013 add_abbrev_attr (unsigned long attribute
,
1015 bfd_signed_vma implicit_const
,
1020 attr
= (abbrev_attr
*) xmalloc (sizeof (*attr
));
1022 attr
->attribute
= attribute
;
1024 attr
->implicit_const
= implicit_const
;
1027 assert (list
!= NULL
&& list
->last_abbrev
!= NULL
);
1029 if (list
->last_abbrev
->first_attr
== NULL
)
1030 list
->last_abbrev
->first_attr
= attr
;
1032 list
->last_abbrev
->last_attr
->next
= attr
;
1034 list
->last_abbrev
->last_attr
= attr
;
1037 /* Processes the (partial) contents of a .debug_abbrev section.
1038 Returns NULL if the end of the section was encountered.
1039 Returns the address after the last byte read if the end of
1040 an abbreviation set was found. */
1042 static unsigned char *
1043 process_abbrev_set (struct dwarf_section
*section
,
1044 dwarf_vma abbrev_base
,
1045 dwarf_vma abbrev_size
,
1046 dwarf_vma abbrev_offset
,
1049 if (abbrev_base
>= section
->size
1050 || abbrev_size
> section
->size
- abbrev_base
)
1052 /* PR 17531: file:4bcd9ce9. */
1053 warn (_("Debug info is corrupted, abbrev size (%lx) is larger than "
1054 "abbrev section size (%lx)\n"),
1055 (unsigned long) (abbrev_base
+ abbrev_size
),
1056 (unsigned long) section
->size
);
1059 if (abbrev_offset
>= abbrev_size
)
1061 warn (_("Debug info is corrupted, abbrev offset (%lx) is larger than "
1062 "abbrev section size (%lx)\n"),
1063 (unsigned long) abbrev_offset
,
1064 (unsigned long) abbrev_size
);
1068 unsigned char *start
= section
->start
+ abbrev_base
;
1069 unsigned char *end
= start
+ abbrev_size
;
1070 start
+= abbrev_offset
;
1073 unsigned long entry
;
1075 unsigned long attribute
;
1078 READ_ULEB (entry
, start
, end
);
1080 /* A single zero is supposed to end the set according
1081 to the standard. If there's more, then signal that to
1088 READ_ULEB (tag
, start
, end
);
1092 children
= *start
++;
1094 add_abbrev (entry
, tag
, children
, list
);
1099 /* Initialize it due to a false compiler warning. */
1100 bfd_signed_vma implicit_const
= -1;
1102 READ_ULEB (attribute
, start
, end
);
1106 READ_ULEB (form
, start
, end
);
1110 if (form
== DW_FORM_implicit_const
)
1112 READ_SLEB (implicit_const
, start
, end
);
1117 add_abbrev_attr (attribute
, form
, implicit_const
, list
);
1119 while (attribute
!= 0);
1122 /* Report the missing single zero which ends the section. */
1123 error (_(".debug_abbrev section not zero terminated\n"));
1129 get_TAG_name (unsigned long tag
)
1131 const char *name
= get_DW_TAG_name ((unsigned int) tag
);
1135 static char buffer
[100];
1137 if (tag
>= DW_TAG_lo_user
&& tag
<= DW_TAG_hi_user
)
1138 snprintf (buffer
, sizeof (buffer
), _("User TAG value: %#lx"), tag
);
1140 snprintf (buffer
, sizeof (buffer
), _("Unknown TAG value: %#lx"), tag
);
1148 get_FORM_name (unsigned long form
)
1153 return "DW_FORM value: 0";
1155 name
= get_DW_FORM_name (form
);
1158 static char buffer
[100];
1160 snprintf (buffer
, sizeof (buffer
), _("Unknown FORM value: %lx"), form
);
1168 get_IDX_name (unsigned long idx
)
1170 const char *name
= get_DW_IDX_name ((unsigned int) idx
);
1174 static char buffer
[100];
1176 snprintf (buffer
, sizeof (buffer
), _("Unknown IDX value: %lx"), idx
);
1183 static unsigned char *
1184 display_block (unsigned char *data
,
1186 const unsigned char * const end
, char delimiter
)
1190 printf (_("%c%s byte block: "), delimiter
, dwarf_vmatoa ("u", length
));
1192 return (unsigned char *) end
;
1194 maxlen
= (dwarf_vma
) (end
- data
);
1195 length
= length
> maxlen
? maxlen
: length
;
1198 printf ("%lx ", (unsigned long) byte_get (data
++, 1));
1204 decode_location_expression (unsigned char * data
,
1205 unsigned int pointer_size
,
1206 unsigned int offset_size
,
1209 dwarf_vma cu_offset
,
1210 struct dwarf_section
* section
)
1214 dwarf_signed_vma svalue
;
1215 unsigned char *end
= data
+ length
;
1216 int need_frame_base
= 0;
1225 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1226 printf ("DW_OP_addr: %s", dwarf_vmatoa ("x", uvalue
));
1229 printf ("DW_OP_deref");
1232 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1233 printf ("DW_OP_const1u: %lu", (unsigned long) uvalue
);
1236 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 1, end
);
1237 printf ("DW_OP_const1s: %ld", (long) svalue
);
1240 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
1241 printf ("DW_OP_const2u: %lu", (unsigned long) uvalue
);
1244 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1245 printf ("DW_OP_const2s: %ld", (long) svalue
);
1248 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1249 printf ("DW_OP_const4u: %lu", (unsigned long) uvalue
);
1252 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
1253 printf ("DW_OP_const4s: %ld", (long) svalue
);
1256 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1257 printf ("DW_OP_const8u: %lu ", (unsigned long) uvalue
);
1258 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1259 printf ("%lu", (unsigned long) uvalue
);
1262 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
1263 printf ("DW_OP_const8s: %ld ", (long) svalue
);
1264 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
1265 printf ("%ld", (long) svalue
);
1268 READ_ULEB (uvalue
, data
, end
);
1269 printf ("DW_OP_constu: %s", dwarf_vmatoa ("u", uvalue
));
1272 READ_SLEB (svalue
, data
, end
);
1273 printf ("DW_OP_consts: %s", dwarf_vmatoa ("d", svalue
));
1276 printf ("DW_OP_dup");
1279 printf ("DW_OP_drop");
1282 printf ("DW_OP_over");
1285 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1286 printf ("DW_OP_pick: %ld", (unsigned long) uvalue
);
1289 printf ("DW_OP_swap");
1292 printf ("DW_OP_rot");
1295 printf ("DW_OP_xderef");
1298 printf ("DW_OP_abs");
1301 printf ("DW_OP_and");
1304 printf ("DW_OP_div");
1307 printf ("DW_OP_minus");
1310 printf ("DW_OP_mod");
1313 printf ("DW_OP_mul");
1316 printf ("DW_OP_neg");
1319 printf ("DW_OP_not");
1322 printf ("DW_OP_or");
1325 printf ("DW_OP_plus");
1327 case DW_OP_plus_uconst
:
1328 READ_ULEB (uvalue
, data
, end
);
1329 printf ("DW_OP_plus_uconst: %s", dwarf_vmatoa ("u", uvalue
));
1332 printf ("DW_OP_shl");
1335 printf ("DW_OP_shr");
1338 printf ("DW_OP_shra");
1341 printf ("DW_OP_xor");
1344 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1345 printf ("DW_OP_bra: %ld", (long) svalue
);
1348 printf ("DW_OP_eq");
1351 printf ("DW_OP_ge");
1354 printf ("DW_OP_gt");
1357 printf ("DW_OP_le");
1360 printf ("DW_OP_lt");
1363 printf ("DW_OP_ne");
1366 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1367 printf ("DW_OP_skip: %ld", (long) svalue
);
1402 printf ("DW_OP_lit%d", op
- DW_OP_lit0
);
1437 printf ("DW_OP_reg%d (%s)", op
- DW_OP_reg0
,
1438 regname (op
- DW_OP_reg0
, 1));
1473 READ_SLEB (svalue
, data
, end
);
1474 printf ("DW_OP_breg%d (%s): %s", op
- DW_OP_breg0
,
1475 regname (op
- DW_OP_breg0
, 1), dwarf_vmatoa ("d", svalue
));
1479 READ_ULEB (uvalue
, data
, end
);
1480 printf ("DW_OP_regx: %s (%s)",
1481 dwarf_vmatoa ("u", uvalue
), regname (uvalue
, 1));
1484 need_frame_base
= 1;
1485 READ_SLEB (svalue
, data
, end
);
1486 printf ("DW_OP_fbreg: %s", dwarf_vmatoa ("d", svalue
));
1489 READ_ULEB (uvalue
, data
, end
);
1490 READ_SLEB (svalue
, data
, end
);
1491 printf ("DW_OP_bregx: %s (%s) %s",
1492 dwarf_vmatoa ("u", uvalue
), regname (uvalue
, 1),
1493 dwarf_vmatoa ("d", svalue
));
1496 READ_ULEB (uvalue
, data
, end
);
1497 printf ("DW_OP_piece: %s", dwarf_vmatoa ("u", uvalue
));
1499 case DW_OP_deref_size
:
1500 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1501 printf ("DW_OP_deref_size: %ld", (long) uvalue
);
1503 case DW_OP_xderef_size
:
1504 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1505 printf ("DW_OP_xderef_size: %ld", (long) uvalue
);
1508 printf ("DW_OP_nop");
1511 /* DWARF 3 extensions. */
1512 case DW_OP_push_object_address
:
1513 printf ("DW_OP_push_object_address");
1516 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1517 this ought to be an 8-byte wide computation. */
1518 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1519 printf ("DW_OP_call2: <0x%s>",
1520 dwarf_vmatoa ("x", svalue
+ cu_offset
));
1523 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1524 this ought to be an 8-byte wide computation. */
1525 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
1526 printf ("DW_OP_call4: <0x%s>",
1527 dwarf_vmatoa ("x", svalue
+ cu_offset
));
1529 case DW_OP_call_ref
:
1530 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1531 this ought to be an 8-byte wide computation. */
1532 if (dwarf_version
== -1)
1534 printf (_("(DW_OP_call_ref in frame info)"));
1535 /* No way to tell where the next op is, so just bail. */
1536 return need_frame_base
;
1538 if (dwarf_version
== 2)
1540 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1544 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1546 printf ("DW_OP_call_ref: <0x%s>", dwarf_vmatoa ("x", uvalue
));
1548 case DW_OP_form_tls_address
:
1549 printf ("DW_OP_form_tls_address");
1551 case DW_OP_call_frame_cfa
:
1552 printf ("DW_OP_call_frame_cfa");
1554 case DW_OP_bit_piece
:
1555 printf ("DW_OP_bit_piece: ");
1556 READ_ULEB (uvalue
, data
, end
);
1557 printf (_("size: %s "), dwarf_vmatoa ("u", uvalue
));
1558 READ_ULEB (uvalue
, data
, end
);
1559 printf (_("offset: %s "), dwarf_vmatoa ("u", uvalue
));
1562 /* DWARF 4 extensions. */
1563 case DW_OP_stack_value
:
1564 printf ("DW_OP_stack_value");
1567 case DW_OP_implicit_value
:
1568 printf ("DW_OP_implicit_value");
1569 READ_ULEB (uvalue
, data
, end
);
1570 data
= display_block (data
, uvalue
, end
, ' ');
1573 /* GNU extensions. */
1574 case DW_OP_GNU_push_tls_address
:
1575 printf (_("DW_OP_GNU_push_tls_address or DW_OP_HP_unknown"));
1577 case DW_OP_GNU_uninit
:
1578 printf ("DW_OP_GNU_uninit");
1579 /* FIXME: Is there data associated with this OP ? */
1581 case DW_OP_GNU_encoded_addr
:
1588 addr
= get_encoded_value (&data
, encoding
, section
, end
);
1590 printf ("DW_OP_GNU_encoded_addr: fmt:%02x addr:", encoding
);
1591 print_dwarf_vma (addr
, pointer_size
);
1594 case DW_OP_implicit_pointer
:
1595 case DW_OP_GNU_implicit_pointer
:
1596 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1597 this ought to be an 8-byte wide computation. */
1598 if (dwarf_version
== -1)
1600 printf (_("(%s in frame info)"),
1601 (op
== DW_OP_implicit_pointer
1602 ? "DW_OP_implicit_pointer"
1603 : "DW_OP_GNU_implicit_pointer"));
1604 /* No way to tell where the next op is, so just bail. */
1605 return need_frame_base
;
1607 if (dwarf_version
== 2)
1609 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1613 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1615 READ_SLEB (svalue
, data
, end
);
1616 printf ("%s: <0x%s> %s",
1617 (op
== DW_OP_implicit_pointer
1618 ? "DW_OP_implicit_pointer" : "DW_OP_GNU_implicit_pointer"),
1619 dwarf_vmatoa ("x", uvalue
),
1620 dwarf_vmatoa ("d", svalue
));
1622 case DW_OP_entry_value
:
1623 case DW_OP_GNU_entry_value
:
1624 READ_ULEB (uvalue
, data
, end
);
1625 /* PR 17531: file: 0cc9cd00. */
1626 if (uvalue
> (dwarf_vma
) (end
- data
))
1627 uvalue
= end
- data
;
1628 printf ("%s: (", (op
== DW_OP_entry_value
? "DW_OP_entry_value"
1629 : "DW_OP_GNU_entry_value"));
1630 if (decode_location_expression (data
, pointer_size
, offset_size
,
1631 dwarf_version
, uvalue
,
1632 cu_offset
, section
))
1633 need_frame_base
= 1;
1639 case DW_OP_const_type
:
1640 case DW_OP_GNU_const_type
:
1641 READ_ULEB (uvalue
, data
, end
);
1642 printf ("%s: <0x%s> ",
1643 (op
== DW_OP_const_type
? "DW_OP_const_type"
1644 : "DW_OP_GNU_const_type"),
1645 dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1646 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1647 data
= display_block (data
, uvalue
, end
, ' ');
1649 case DW_OP_regval_type
:
1650 case DW_OP_GNU_regval_type
:
1651 READ_ULEB (uvalue
, data
, end
);
1652 printf ("%s: %s (%s)",
1653 (op
== DW_OP_regval_type
? "DW_OP_regval_type"
1654 : "DW_OP_GNU_regval_type"),
1655 dwarf_vmatoa ("u", uvalue
), regname (uvalue
, 1));
1656 READ_ULEB (uvalue
, data
, end
);
1657 printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1659 case DW_OP_deref_type
:
1660 case DW_OP_GNU_deref_type
:
1661 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1663 (op
== DW_OP_deref_type
? "DW_OP_deref_type"
1664 : "DW_OP_GNU_deref_type"),
1666 READ_ULEB (uvalue
, data
, end
);
1667 printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1670 case DW_OP_GNU_convert
:
1671 READ_ULEB (uvalue
, data
, end
);
1672 printf ("%s <0x%s>",
1673 (op
== DW_OP_convert
? "DW_OP_convert" : "DW_OP_GNU_convert"),
1674 dwarf_vmatoa ("x", uvalue
? cu_offset
+ uvalue
: 0));
1676 case DW_OP_reinterpret
:
1677 case DW_OP_GNU_reinterpret
:
1678 READ_ULEB (uvalue
, data
, end
);
1679 printf ("%s <0x%s>",
1680 (op
== DW_OP_reinterpret
? "DW_OP_reinterpret"
1681 : "DW_OP_GNU_reinterpret"),
1682 dwarf_vmatoa ("x", uvalue
? cu_offset
+ uvalue
: 0));
1684 case DW_OP_GNU_parameter_ref
:
1685 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1686 printf ("DW_OP_GNU_parameter_ref: <0x%s>",
1687 dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1689 case DW_OP_GNU_addr_index
:
1690 READ_ULEB (uvalue
, data
, end
);
1691 printf ("DW_OP_GNU_addr_index <0x%s>", dwarf_vmatoa ("x", uvalue
));
1693 case DW_OP_GNU_const_index
:
1694 READ_ULEB (uvalue
, data
, end
);
1695 printf ("DW_OP_GNU_const_index <0x%s>", dwarf_vmatoa ("x", uvalue
));
1697 case DW_OP_GNU_variable_value
:
1698 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1699 this ought to be an 8-byte wide computation. */
1700 if (dwarf_version
== -1)
1702 printf (_("(DW_OP_GNU_variable_value in frame info)"));
1703 /* No way to tell where the next op is, so just bail. */
1704 return need_frame_base
;
1706 if (dwarf_version
== 2)
1708 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1712 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1714 printf ("DW_OP_GNU_variable_value: <0x%s>", dwarf_vmatoa ("x", uvalue
));
1717 /* HP extensions. */
1718 case DW_OP_HP_is_value
:
1719 printf ("DW_OP_HP_is_value");
1720 /* FIXME: Is there data associated with this OP ? */
1722 case DW_OP_HP_fltconst4
:
1723 printf ("DW_OP_HP_fltconst4");
1724 /* FIXME: Is there data associated with this OP ? */
1726 case DW_OP_HP_fltconst8
:
1727 printf ("DW_OP_HP_fltconst8");
1728 /* FIXME: Is there data associated with this OP ? */
1730 case DW_OP_HP_mod_range
:
1731 printf ("DW_OP_HP_mod_range");
1732 /* FIXME: Is there data associated with this OP ? */
1734 case DW_OP_HP_unmod_range
:
1735 printf ("DW_OP_HP_unmod_range");
1736 /* FIXME: Is there data associated with this OP ? */
1739 printf ("DW_OP_HP_tls");
1740 /* FIXME: Is there data associated with this OP ? */
1743 /* PGI (STMicroelectronics) extensions. */
1744 case DW_OP_PGI_omp_thread_num
:
1745 /* Pushes the thread number for the current thread as it would be
1746 returned by the standard OpenMP library function:
1747 omp_get_thread_num(). The "current thread" is the thread for
1748 which the expression is being evaluated. */
1749 printf ("DW_OP_PGI_omp_thread_num");
1753 if (op
>= DW_OP_lo_user
1754 && op
<= DW_OP_hi_user
)
1755 printf (_("(User defined location op 0x%x)"), op
);
1757 printf (_("(Unknown location op 0x%x)"), op
);
1758 /* No way to tell where the next op is, so just bail. */
1759 return need_frame_base
;
1762 /* Separate the ops. */
1767 return need_frame_base
;
1770 /* Find the CU or TU set corresponding to the given CU_OFFSET.
1771 This is used for DWARF package files. */
1773 static struct cu_tu_set
*
1774 find_cu_tu_set_v2 (dwarf_vma cu_offset
, int do_types
)
1776 struct cu_tu_set
*p
;
1778 unsigned int dw_sect
;
1784 dw_sect
= DW_SECT_TYPES
;
1790 dw_sect
= DW_SECT_INFO
;
1794 if (p
->section_offsets
[dw_sect
] == cu_offset
)
1803 fetch_alt_indirect_string (dwarf_vma offset
)
1807 if (! do_follow_links
)
1810 if (first_separate_info
== NULL
)
1811 return _("<no links available>");
1813 for (i
= first_separate_info
; i
!= NULL
; i
= i
->next
)
1815 struct dwarf_section
* section
;
1818 if (! load_debug_section (separate_debug_str
, i
->handle
))
1821 section
= &debug_displays
[separate_debug_str
].section
;
1823 if (section
->start
== NULL
)
1826 if (offset
>= section
->size
)
1829 ret
= (const char *) (section
->start
+ offset
);
1830 /* Unfortunately we cannot rely upon the .debug_str section ending with a
1831 NUL byte. Since our caller is expecting to receive a well formed C
1832 string we test for the lack of a terminating byte here. */
1833 if (strnlen ((const char *) ret
, section
->size
- offset
)
1834 == section
->size
- offset
)
1835 return _("<no NUL byte at end of alt .debug_str section>");
1840 warn (_("DW_FORM_GNU_strp_alt offset (%s) too big or no string sections available\n"),
1841 dwarf_vmatoa ("x", offset
));
1842 return _("<offset is too big>");
1846 get_AT_name (unsigned long attribute
)
1851 return "DW_AT value: 0";
1853 /* One value is shared by the MIPS and HP extensions: */
1854 if (attribute
== DW_AT_MIPS_fde
)
1855 return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable";
1857 name
= get_DW_AT_name (attribute
);
1861 static char buffer
[100];
1863 snprintf (buffer
, sizeof (buffer
), _("Unknown AT value: %lx"),
1872 add_dwo_info (const char * value
, dwarf_vma cu_offset
, dwo_type type
)
1874 dwo_info
* dwinfo
= xmalloc (sizeof * dwinfo
);
1876 dwinfo
->type
= type
;
1877 dwinfo
->value
= value
;
1878 dwinfo
->cu_offset
= cu_offset
;
1879 dwinfo
->next
= first_dwo_info
;
1880 first_dwo_info
= dwinfo
;
1884 add_dwo_name (const char * name
, dwarf_vma cu_offset
)
1886 add_dwo_info (name
, cu_offset
, DWO_NAME
);
1890 add_dwo_dir (const char * dir
, dwarf_vma cu_offset
)
1892 add_dwo_info (dir
, cu_offset
, DWO_DIR
);
1896 add_dwo_id (const char * id
, dwarf_vma cu_offset
)
1898 add_dwo_info (id
, cu_offset
, DWO_ID
);
1902 free_dwo_info (void)
1907 for (dwinfo
= first_dwo_info
; dwinfo
!= NULL
; dwinfo
= next
)
1909 next
= dwinfo
->next
;
1912 first_dwo_info
= NULL
;
1915 /* Ensure that START + UVALUE is less than END.
1916 Return an adjusted UVALUE if necessary to ensure this relationship. */
1918 static inline dwarf_vma
1919 check_uvalue (const unsigned char * start
,
1921 const unsigned char * end
)
1923 dwarf_vma max_uvalue
= end
- start
;
1925 /* See PR 17512: file: 008-103549-0.001:0.1.
1926 and PR 24829 for examples of where these tests are triggered. */
1927 if (uvalue
> max_uvalue
)
1929 warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue
);
1930 uvalue
= max_uvalue
;
1936 static unsigned char *
1937 skip_attr_bytes (unsigned long form
,
1938 unsigned char * data
,
1939 unsigned const char * end
,
1940 dwarf_vma pointer_size
,
1941 dwarf_vma offset_size
,
1943 dwarf_vma
* value_return
)
1945 dwarf_signed_vma svalue
;
1946 dwarf_vma uvalue
= 0;
1952 case DW_FORM_ref_addr
:
1953 if (dwarf_version
== 2)
1954 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1955 else if (dwarf_version
> 2)
1956 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1962 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1966 case DW_FORM_line_strp
:
1967 case DW_FORM_sec_offset
:
1968 case DW_FORM_GNU_ref_alt
:
1969 case DW_FORM_GNU_strp_alt
:
1970 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1973 case DW_FORM_flag_present
:
1981 case DW_FORM_addrx1
:
1982 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1986 case DW_FORM_addrx3
:
1987 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 3, end
);
1993 case DW_FORM_addrx2
:
1994 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
2000 case DW_FORM_addrx4
:
2001 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
2005 READ_SLEB (svalue
, data
, end
);
2009 case DW_FORM_ref_udata
:
2011 case DW_FORM_GNU_str_index
:
2013 case DW_FORM_GNU_addr_index
:
2015 READ_ULEB (uvalue
, data
, end
);
2019 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 8, end
);
2023 case DW_FORM_ref_sig8
:
2027 case DW_FORM_data16
:
2031 case DW_FORM_string
:
2032 data
+= strnlen ((char *) data
, end
- data
) + 1;
2036 case DW_FORM_exprloc
:
2037 READ_ULEB (uvalue
, data
, end
);
2041 case DW_FORM_block1
:
2042 SAFE_BYTE_GET (uvalue
, data
, 1, end
);
2046 case DW_FORM_block2
:
2047 SAFE_BYTE_GET (uvalue
, data
, 2, end
);
2051 case DW_FORM_block4
:
2052 SAFE_BYTE_GET (uvalue
, data
, 4, end
);
2056 case DW_FORM_indirect
:
2057 READ_ULEB (form
, data
, end
);
2058 if (form
== DW_FORM_implicit_const
)
2059 SKIP_ULEB (data
, end
);
2060 return skip_attr_bytes (form
, data
, end
, pointer_size
, offset_size
, dwarf_version
, value_return
);
2066 * value_return
= uvalue
;
2068 data
= (unsigned char *) end
;
2072 /* Given form FORM with value UVALUE, locate and return the abbreviation
2073 associated with it. */
2075 static abbrev_entry
*
2076 get_type_abbrev_from_form (unsigned long form
,
2077 unsigned long uvalue
,
2078 dwarf_vma cu_offset
,
2079 const struct dwarf_section
* section
,
2080 unsigned long * abbrev_num_return
,
2081 unsigned char ** data_return
,
2082 unsigned long * cu_offset_return
)
2084 unsigned long abbrev_number
;
2086 abbrev_entry
* entry
;
2087 unsigned char * data
;
2089 if (abbrev_num_return
!= NULL
)
2090 * abbrev_num_return
= 0;
2091 if (data_return
!= NULL
)
2092 * data_return
= NULL
;
2096 case DW_FORM_GNU_ref_alt
:
2097 case DW_FORM_ref_sig8
:
2098 /* FIXME: We are unable to handle this form at the moment. */
2101 case DW_FORM_ref_addr
:
2102 if (uvalue
>= section
->size
)
2104 warn (_("Unable to resolve ref_addr form: uvalue %lx > section size %lx (%s)\n"),
2105 uvalue
, (long) section
->size
, section
->name
);
2110 case DW_FORM_ref_sup4
:
2111 case DW_FORM_ref_sup8
:
2118 case DW_FORM_ref_udata
:
2119 if (uvalue
+ cu_offset
> section
->size
)
2121 warn (_("Unable to resolve ref form: uvalue %lx + cu_offset %lx > section size %lx\n"),
2122 uvalue
, (long) cu_offset
, (long) section
->size
);
2125 uvalue
+= cu_offset
;
2128 /* FIXME: Are there other DW_FORMs that can be used by types ? */
2131 warn (_("Unexpected form %lx encountered whilst finding abbreviation for type\n"), form
);
2135 data
= (unsigned char *) section
->start
+ uvalue
;
2136 map
= find_abbrev_map_by_offset (uvalue
);
2140 warn (_("Unable to find abbreviations for CU offset %#lx\n"), uvalue
);
2143 if (map
->list
== NULL
)
2145 warn (_("Empty abbreviation list encountered for CU offset %lx\n"), uvalue
);
2149 if (cu_offset_return
!= NULL
)
2151 if (form
== DW_FORM_ref_addr
)
2152 * cu_offset_return
= map
->start
;
2154 * cu_offset_return
= cu_offset
;
2157 READ_ULEB (abbrev_number
, data
, section
->start
+ section
->size
);
2159 for (entry
= map
->list
->first_abbrev
; entry
!= NULL
; entry
= entry
->next
)
2160 if (entry
->number
== abbrev_number
)
2163 if (abbrev_num_return
!= NULL
)
2164 * abbrev_num_return
= abbrev_number
;
2166 if (data_return
!= NULL
)
2167 * data_return
= data
;
2170 warn (_("Unable to find entry for abbreviation %lu\n"), abbrev_number
);
2175 /* Return IS_SIGNED set to TRUE if the type using abbreviation ENTRY
2176 can be determined to be a signed type. The data for ENTRY can be
2177 found starting at DATA. */
2180 get_type_signedness (abbrev_entry
*entry
,
2181 const struct dwarf_section
*section
,
2182 unsigned char *data
,
2183 unsigned const char *end
,
2184 dwarf_vma cu_offset
,
2185 dwarf_vma pointer_size
,
2186 dwarf_vma offset_size
,
2189 unsigned int nesting
)
2193 * is_signed
= false;
2195 #define MAX_NESTING 20
2196 if (nesting
> MAX_NESTING
)
2198 /* FIXME: Warn - or is this expected ?
2199 NB/ We need to avoid infinite recursion. */
2203 for (attr
= entry
->first_attr
;
2204 attr
!= NULL
&& attr
->attribute
;
2207 unsigned char * orig_data
= data
;
2208 dwarf_vma uvalue
= 0;
2210 data
= skip_attr_bytes (attr
->form
, data
, end
, pointer_size
,
2211 offset_size
, dwarf_version
, & uvalue
);
2215 switch (attr
->attribute
)
2217 case DW_AT_linkage_name
:
2221 if (attr
->form
== DW_FORM_strp
)
2222 printf (", %s", fetch_indirect_string (uvalue
));
2223 else if (attr
->form
== DW_FORM_string
)
2224 printf (", %s", orig_data
);
2231 abbrev_entry
* type_abbrev
;
2232 unsigned char * type_data
;
2233 unsigned long type_cu_offset
;
2235 type_abbrev
= get_type_abbrev_from_form (attr
->form
,
2239 NULL
/* abbrev num return */,
2242 if (type_abbrev
== NULL
)
2245 get_type_signedness (type_abbrev
, section
, type_data
, end
, type_cu_offset
,
2246 pointer_size
, offset_size
, dwarf_version
,
2247 is_signed
, nesting
+ 1);
2251 case DW_AT_encoding
:
2252 /* Determine signness. */
2255 case DW_ATE_address
:
2256 /* FIXME - some architectures have signed addresses. */
2257 case DW_ATE_boolean
:
2258 case DW_ATE_unsigned
:
2259 case DW_ATE_unsigned_char
:
2260 case DW_ATE_unsigned_fixed
:
2261 * is_signed
= false;
2265 case DW_ATE_complex_float
:
2268 case DW_ATE_signed_char
:
2269 case DW_ATE_imaginary_float
:
2270 case DW_ATE_decimal_float
:
2271 case DW_ATE_signed_fixed
:
2281 read_and_print_leb128 (unsigned char *data
,
2282 unsigned int *bytes_read
,
2283 unsigned const char *end
,
2287 dwarf_vma val
= read_leb128 (data
, end
, is_signed
, bytes_read
, &status
);
2289 report_leb_status (status
, __FILE__
, __LINE__
);
2291 printf ("%s", dwarf_vmatoa (is_signed
? "d" : "u", val
));
2295 display_discr_list (unsigned long form
,
2297 unsigned char * data
,
2298 unsigned const char * end
,
2303 printf ("[default]");
2310 case DW_FORM_block1
:
2311 case DW_FORM_block2
:
2312 case DW_FORM_block4
:
2313 /* Move data pointer back to the start of the byte array. */
2317 printf ("<corrupt>\n");
2318 warn (_("corrupt discr_list - not using a block form\n"));
2324 printf ("<corrupt>\n");
2325 warn (_("corrupt discr_list - block not long enough\n"));
2330 (level
> 0 && level
<= MAX_CU_NESTING
)
2331 ? level_type_signed
[level
- 1] : false;
2336 unsigned char discriminant
;
2337 unsigned int bytes_read
;
2339 SAFE_BYTE_GET (discriminant
, data
, 1, end
);
2343 assert (uvalue
> 0);
2344 switch (discriminant
)
2348 read_and_print_leb128 (data
, & bytes_read
, end
, is_signed
);
2349 assert (bytes_read
<= uvalue
&& bytes_read
> 0);
2350 uvalue
-= bytes_read
;
2356 read_and_print_leb128 (data
, & bytes_read
, end
, is_signed
);
2357 assert (bytes_read
<= uvalue
&& bytes_read
> 0);
2358 uvalue
-= bytes_read
;
2362 read_and_print_leb128 (data
, & bytes_read
, end
, is_signed
);
2363 assert (bytes_read
<= uvalue
&& bytes_read
> 0);
2364 uvalue
-= bytes_read
;
2369 printf ("<corrupt>\n");
2370 warn (_("corrupt discr_list - unrecognized discriminant byte %#x\n"),
2380 printf (")(signed)");
2382 printf (")(unsigned)");
2385 static unsigned char *
2386 read_and_display_attr_value (unsigned long attribute
,
2388 dwarf_signed_vma implicit_const
,
2389 unsigned char * start
,
2390 unsigned char * data
,
2391 unsigned char * end
,
2392 dwarf_vma cu_offset
,
2393 dwarf_vma pointer_size
,
2394 dwarf_vma offset_size
,
2396 debug_info
* debug_info_p
,
2398 struct dwarf_section
* section
,
2399 struct cu_tu_set
* this_set
,
2403 dwarf_signed_vma svalue
;
2404 dwarf_vma uvalue
= 0;
2405 dwarf_vma uvalue_hi
= 0;
2406 unsigned char *block_start
= NULL
;
2407 unsigned char *orig_data
= data
;
2409 if (data
> end
|| (data
== end
&& form
!= DW_FORM_flag_present
))
2411 warn (_("Corrupt attribute\n"));
2415 if (do_wide
&& ! do_loc
)
2417 /* PR 26847: Display the name of the form. */
2418 const char * name
= get_FORM_name (form
);
2420 /* For convenience we skip the DW_FORM_ prefix to the name. */
2422 name
+= 8; /* strlen ("DW_FORM_") */
2423 printf ("%c(%s)", delimiter
, name
);
2431 case DW_FORM_ref_addr
:
2432 if (dwarf_version
== 2)
2433 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
2434 else if (dwarf_version
> 2)
2435 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
2437 error (_("Internal error: DW_FORM_ref_addr is not supported in DWARF version 1.\n"));
2441 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
2444 case DW_FORM_strp_sup
:
2446 case DW_FORM_line_strp
:
2447 case DW_FORM_sec_offset
:
2448 case DW_FORM_GNU_ref_alt
:
2449 case DW_FORM_GNU_strp_alt
:
2450 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
2453 case DW_FORM_flag_present
:
2461 case DW_FORM_addrx1
:
2462 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
2468 case DW_FORM_addrx2
:
2469 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
2473 case DW_FORM_addrx3
:
2474 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 3, end
);
2477 case DW_FORM_ref_sup4
:
2481 case DW_FORM_addrx4
:
2482 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
2485 case DW_FORM_ref_sup8
:
2488 case DW_FORM_ref_sig8
:
2489 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 8, end
);
2492 case DW_FORM_data16
:
2493 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 8, end
);
2494 SAFE_BYTE_GET_AND_INC (uvalue_hi
, data
, 8, end
);
2495 if (byte_get
!= byte_get_little_endian
)
2497 dwarf_vma utmp
= uvalue
;
2504 READ_SLEB (svalue
, data
, end
);
2508 case DW_FORM_GNU_str_index
:
2510 case DW_FORM_ref_udata
:
2512 case DW_FORM_GNU_addr_index
:
2514 READ_ULEB (uvalue
, data
, end
);
2517 case DW_FORM_indirect
:
2518 READ_ULEB (form
, data
, end
);
2520 printf ("%c%s", delimiter
, get_FORM_name (form
));
2521 if (form
== DW_FORM_implicit_const
)
2522 READ_SLEB (implicit_const
, data
, end
);
2523 return read_and_display_attr_value (attribute
, form
, implicit_const
,
2525 cu_offset
, pointer_size
,
2526 offset_size
, dwarf_version
,
2527 debug_info_p
, do_loc
,
2528 section
, this_set
, delimiter
, level
);
2533 case DW_FORM_ref_addr
:
2535 printf ("%c<0x%s>", delimiter
, dwarf_vmatoa ("x", uvalue
));
2538 case DW_FORM_GNU_ref_alt
:
2542 /* We have already printed the form name. */
2543 printf ("%c<0x%s>", delimiter
, dwarf_vmatoa ("x", uvalue
));
2545 printf ("%c<alt 0x%s>", delimiter
, dwarf_vmatoa ("x", uvalue
));
2547 /* FIXME: Follow the reference... */
2553 case DW_FORM_ref_sup4
:
2554 case DW_FORM_ref_udata
:
2556 printf ("%c<0x%s>", delimiter
, dwarf_vmatoa ("x", uvalue
+ cu_offset
));
2561 case DW_FORM_sec_offset
:
2563 printf ("%c0x%s", delimiter
, dwarf_vmatoa ("x", uvalue
));
2566 case DW_FORM_flag_present
:
2573 printf ("%c%s", delimiter
, dwarf_vmatoa ("d", uvalue
));
2576 case DW_FORM_implicit_const
:
2578 printf ("%c%s", delimiter
, dwarf_vmatoa ("d", implicit_const
));
2581 case DW_FORM_ref_sup8
:
2586 dwarf_vma utmp
= uvalue
;
2587 if (form
== DW_FORM_ref8
)
2589 printf ("%c0x%s", delimiter
, dwarf_vmatoa ("x", utmp
));
2593 case DW_FORM_data16
:
2596 uvalue_hi
== 0 ? "" : dwarf_vmatoa ("x", uvalue_hi
),
2597 dwarf_vmatoa_1 ("x", uvalue
, uvalue_hi
== 0 ? 0 : 8));
2600 case DW_FORM_string
:
2602 printf ("%c%.*s", delimiter
, (int) (end
- data
), data
);
2603 data
+= strnlen ((char *) data
, end
- data
) + 1;
2607 case DW_FORM_exprloc
:
2608 READ_ULEB (uvalue
, data
, end
);
2611 if (block_start
>= end
)
2613 warn (_("Block ends prematurely\n"));
2618 uvalue
= check_uvalue (block_start
, uvalue
, end
);
2621 data
= block_start
+ uvalue
;
2623 data
= display_block (block_start
, uvalue
, end
, delimiter
);
2626 case DW_FORM_block1
:
2627 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
2630 case DW_FORM_block2
:
2631 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
2634 case DW_FORM_block4
:
2635 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
2642 /* We have already displayed the form name. */
2643 printf (_("%c(offset: 0x%s): %s"), delimiter
,
2644 dwarf_vmatoa ("x", uvalue
),
2645 fetch_indirect_string (uvalue
));
2647 printf (_("%c(indirect string, offset: 0x%s): %s"), delimiter
,
2648 dwarf_vmatoa ("x", uvalue
),
2649 fetch_indirect_string (uvalue
));
2653 case DW_FORM_line_strp
:
2657 /* We have already displayed the form name. */
2658 printf (_("%c(offset: 0x%s): %s"), delimiter
,
2659 dwarf_vmatoa ("x", uvalue
),
2660 fetch_indirect_line_string (uvalue
));
2662 printf (_("%c(indirect line string, offset: 0x%s): %s"), delimiter
,
2663 dwarf_vmatoa ("x", uvalue
),
2664 fetch_indirect_line_string (uvalue
));
2668 case DW_FORM_GNU_str_index
:
2676 const char *suffix
= strrchr (section
->name
, '.');
2677 bool dwo
= suffix
&& strcmp (suffix
, ".dwo") == 0;
2680 /* We have already displayed the form name. */
2681 printf (_("%c(offset: 0x%s): %s"), delimiter
,
2682 dwarf_vmatoa ("x", uvalue
),
2683 fetch_indexed_string (uvalue
, this_set
, offset_size
, dwo
));
2685 printf (_("%c(indexed string: 0x%s): %s"), delimiter
,
2686 dwarf_vmatoa ("x", uvalue
),
2687 fetch_indexed_string (uvalue
, this_set
, offset_size
, dwo
));
2691 case DW_FORM_GNU_strp_alt
:
2695 /* We have already displayed the form name. */
2696 printf (_("%c(offset: 0x%s) %s"), delimiter
,
2697 dwarf_vmatoa ("x", uvalue
),
2698 fetch_alt_indirect_string (uvalue
));
2700 printf (_("%c(alt indirect string, offset: 0x%s) %s"), delimiter
,
2701 dwarf_vmatoa ("x", uvalue
),
2702 fetch_alt_indirect_string (uvalue
));
2706 case DW_FORM_indirect
:
2707 /* Handled above. */
2710 case DW_FORM_ref_sig8
:
2712 printf ("%c%s: 0x%s", delimiter
, do_wide
? "" : "signature",
2713 dwarf_vmatoa ("x", uvalue
));
2716 case DW_FORM_GNU_addr_index
:
2718 case DW_FORM_addrx1
:
2719 case DW_FORM_addrx2
:
2720 case DW_FORM_addrx3
:
2721 case DW_FORM_addrx4
:
2727 if (debug_info_p
== NULL
)
2729 else if (debug_info_p
->addr_base
== DEBUG_INFO_UNAVAILABLE
)
2732 base
= debug_info_p
->addr_base
;
2734 offset
= base
+ uvalue
* pointer_size
;
2737 /* We have already displayed the form name. */
2738 printf (_("%c(index: 0x%s): %s"), delimiter
,
2739 dwarf_vmatoa ("x", uvalue
),
2740 fetch_indexed_value (offset
, pointer_size
));
2742 printf (_("%c(addr_index: 0x%s): %s"), delimiter
,
2743 dwarf_vmatoa ("x", uvalue
),
2744 fetch_indexed_value (offset
, pointer_size
));
2748 case DW_FORM_strp_sup
:
2750 printf ("%c<0x%s>", delimiter
, dwarf_vmatoa ("x", uvalue
+ cu_offset
));
2754 warn (_("Unrecognized form: 0x%lx\n"), form
);
2758 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
2759 && num_debug_info_entries
== 0
2760 && debug_info_p
!= NULL
)
2764 case DW_AT_frame_base
:
2765 have_frame_base
= 1;
2767 case DW_AT_location
:
2768 case DW_AT_GNU_locviews
:
2769 case DW_AT_string_length
:
2770 case DW_AT_return_addr
:
2771 case DW_AT_data_member_location
:
2772 case DW_AT_vtable_elem_location
:
2774 case DW_AT_static_link
:
2775 case DW_AT_use_location
:
2776 case DW_AT_call_value
:
2777 case DW_AT_GNU_call_site_value
:
2778 case DW_AT_call_data_value
:
2779 case DW_AT_GNU_call_site_data_value
:
2780 case DW_AT_call_target
:
2781 case DW_AT_GNU_call_site_target
:
2782 case DW_AT_call_target_clobbered
:
2783 case DW_AT_GNU_call_site_target_clobbered
:
2784 if ((dwarf_version
< 4
2785 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
2786 || form
== DW_FORM_sec_offset
)
2788 /* Process location list. */
2789 unsigned int lmax
= debug_info_p
->max_loc_offsets
;
2790 unsigned int num
= debug_info_p
->num_loc_offsets
;
2792 if (lmax
== 0 || num
>= lmax
)
2795 debug_info_p
->loc_offsets
= (dwarf_vma
*)
2796 xcrealloc (debug_info_p
->loc_offsets
,
2797 lmax
, sizeof (*debug_info_p
->loc_offsets
));
2798 debug_info_p
->loc_views
= (dwarf_vma
*)
2799 xcrealloc (debug_info_p
->loc_views
,
2800 lmax
, sizeof (*debug_info_p
->loc_views
));
2801 debug_info_p
->have_frame_base
= (int *)
2802 xcrealloc (debug_info_p
->have_frame_base
,
2803 lmax
, sizeof (*debug_info_p
->have_frame_base
));
2804 debug_info_p
->max_loc_offsets
= lmax
;
2806 if (this_set
!= NULL
)
2807 uvalue
+= this_set
->section_offsets
[DW_SECT_LOC
];
2808 debug_info_p
->have_frame_base
[num
] = have_frame_base
;
2809 if (attribute
!= DW_AT_GNU_locviews
)
2811 /* Corrupt DWARF info can produce more offsets than views.
2812 See PR 23062 for an example. */
2813 if (debug_info_p
->num_loc_offsets
2814 > debug_info_p
->num_loc_views
)
2815 warn (_("More location offset attributes than DW_AT_GNU_locview attributes\n"));
2818 debug_info_p
->loc_offsets
[num
] = uvalue
;
2819 debug_info_p
->num_loc_offsets
++;
2824 assert (debug_info_p
->num_loc_views
<= num
);
2825 num
= debug_info_p
->num_loc_views
;
2826 if (num
> debug_info_p
->num_loc_offsets
)
2827 warn (_("More DW_AT_GNU_locview attributes than location offset attributes\n"));
2830 debug_info_p
->loc_views
[num
] = uvalue
;
2831 debug_info_p
->num_loc_views
++;
2838 if (need_base_address
)
2839 debug_info_p
->base_address
= uvalue
;
2842 case DW_AT_GNU_addr_base
:
2843 case DW_AT_addr_base
:
2844 debug_info_p
->addr_base
= uvalue
;
2847 case DW_AT_GNU_ranges_base
:
2848 debug_info_p
->ranges_base
= uvalue
;
2852 if ((dwarf_version
< 4
2853 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
2854 || form
== DW_FORM_sec_offset
)
2856 /* Process range list. */
2857 unsigned int lmax
= debug_info_p
->max_range_lists
;
2858 unsigned int num
= debug_info_p
->num_range_lists
;
2860 if (lmax
== 0 || num
>= lmax
)
2863 debug_info_p
->range_lists
= (dwarf_vma
*)
2864 xcrealloc (debug_info_p
->range_lists
,
2865 lmax
, sizeof (*debug_info_p
->range_lists
));
2866 debug_info_p
->max_range_lists
= lmax
;
2868 debug_info_p
->range_lists
[num
] = uvalue
;
2869 debug_info_p
->num_range_lists
++;
2873 case DW_AT_GNU_dwo_name
:
2874 case DW_AT_dwo_name
:
2879 add_dwo_name ((const char *) fetch_indirect_string (uvalue
), cu_offset
);
2881 case DW_FORM_GNU_strp_alt
:
2882 add_dwo_name ((const char *) fetch_alt_indirect_string (uvalue
), cu_offset
);
2884 case DW_FORM_GNU_str_index
:
2890 add_dwo_name (fetch_indexed_string (uvalue
, this_set
, offset_size
, false), cu_offset
);
2892 case DW_FORM_string
:
2893 add_dwo_name ((const char *) orig_data
, cu_offset
);
2896 warn (_("Unsupported form (%s) for attribute %s\n"),
2897 get_FORM_name (form
), get_AT_name (attribute
));
2902 case DW_AT_comp_dir
:
2903 /* FIXME: Also extract a build-id in a CU/TU. */
2908 add_dwo_dir ((const char *) fetch_indirect_string (uvalue
), cu_offset
);
2910 case DW_FORM_GNU_strp_alt
:
2911 add_dwo_dir (fetch_alt_indirect_string (uvalue
), cu_offset
);
2913 case DW_FORM_line_strp
:
2914 add_dwo_dir ((const char *) fetch_indirect_line_string (uvalue
), cu_offset
);
2916 case DW_FORM_GNU_str_index
:
2922 add_dwo_dir (fetch_indexed_string (uvalue
, this_set
, offset_size
, false), cu_offset
);
2924 case DW_FORM_string
:
2925 add_dwo_dir ((const char *) orig_data
, cu_offset
);
2928 warn (_("Unsupported form (%s) for attribute %s\n"),
2929 get_FORM_name (form
), get_AT_name (attribute
));
2934 case DW_AT_GNU_dwo_id
:
2939 /* FIXME: Record the length of the ID as well ? */
2940 add_dwo_id ((const char *) (data
- 8), cu_offset
);
2943 warn (_("Unsupported form (%s) for attribute %s\n"),
2944 get_FORM_name (form
), get_AT_name (attribute
));
2954 if (do_loc
|| attribute
== 0)
2957 /* For some attributes we can display further information. */
2961 if (level
>= 0 && level
< MAX_CU_NESTING
2962 && uvalue
< (size_t) (end
- start
))
2964 bool is_signed
= false;
2965 abbrev_entry
*type_abbrev
;
2966 unsigned char *type_data
;
2967 unsigned long type_cu_offset
;
2969 type_abbrev
= get_type_abbrev_from_form (form
, uvalue
, cu_offset
,
2970 section
, NULL
, & type_data
, & type_cu_offset
);
2971 if (type_abbrev
!= NULL
)
2973 get_type_signedness (type_abbrev
, section
, type_data
, end
, type_cu_offset
,
2974 pointer_size
, offset_size
, dwarf_version
,
2977 level_type_signed
[level
] = is_signed
;
2985 case DW_INL_not_inlined
:
2986 printf (_("(not inlined)"));
2988 case DW_INL_inlined
:
2989 printf (_("(inlined)"));
2991 case DW_INL_declared_not_inlined
:
2992 printf (_("(declared as inline but ignored)"));
2994 case DW_INL_declared_inlined
:
2995 printf (_("(declared as inline and inlined)"));
2998 printf (_(" (Unknown inline attribute value: %s)"),
2999 dwarf_vmatoa ("x", uvalue
));
3004 case DW_AT_language
:
3008 /* Ordered by the numeric value of these constants. */
3009 case DW_LANG_C89
: printf ("(ANSI C)"); break;
3010 case DW_LANG_C
: printf ("(non-ANSI C)"); break;
3011 case DW_LANG_Ada83
: printf ("(Ada)"); break;
3012 case DW_LANG_C_plus_plus
: printf ("(C++)"); break;
3013 case DW_LANG_Cobol74
: printf ("(Cobol 74)"); break;
3014 case DW_LANG_Cobol85
: printf ("(Cobol 85)"); break;
3015 case DW_LANG_Fortran77
: printf ("(FORTRAN 77)"); break;
3016 case DW_LANG_Fortran90
: printf ("(Fortran 90)"); break;
3017 case DW_LANG_Pascal83
: printf ("(ANSI Pascal)"); break;
3018 case DW_LANG_Modula2
: printf ("(Modula 2)"); break;
3019 /* DWARF 2.1 values. */
3020 case DW_LANG_Java
: printf ("(Java)"); break;
3021 case DW_LANG_C99
: printf ("(ANSI C99)"); break;
3022 case DW_LANG_Ada95
: printf ("(ADA 95)"); break;
3023 case DW_LANG_Fortran95
: printf ("(Fortran 95)"); break;
3024 /* DWARF 3 values. */
3025 case DW_LANG_PLI
: printf ("(PLI)"); break;
3026 case DW_LANG_ObjC
: printf ("(Objective C)"); break;
3027 case DW_LANG_ObjC_plus_plus
: printf ("(Objective C++)"); break;
3028 case DW_LANG_UPC
: printf ("(Unified Parallel C)"); break;
3029 case DW_LANG_D
: printf ("(D)"); break;
3030 /* DWARF 4 values. */
3031 case DW_LANG_Python
: printf ("(Python)"); break;
3032 /* DWARF 5 values. */
3033 case DW_LANG_OpenCL
: printf ("(OpenCL)"); break;
3034 case DW_LANG_Go
: printf ("(Go)"); break;
3035 case DW_LANG_Modula3
: printf ("(Modula 3)"); break;
3036 case DW_LANG_Haskell
: printf ("(Haskell)"); break;
3037 case DW_LANG_C_plus_plus_03
: printf ("(C++03)"); break;
3038 case DW_LANG_C_plus_plus_11
: printf ("(C++11)"); break;
3039 case DW_LANG_OCaml
: printf ("(OCaml)"); break;
3040 case DW_LANG_Rust
: printf ("(Rust)"); break;
3041 case DW_LANG_C11
: printf ("(C11)"); break;
3042 case DW_LANG_Swift
: printf ("(Swift)"); break;
3043 case DW_LANG_Julia
: printf ("(Julia)"); break;
3044 case DW_LANG_Dylan
: printf ("(Dylan)"); break;
3045 case DW_LANG_C_plus_plus_14
: printf ("(C++14)"); break;
3046 case DW_LANG_Fortran03
: printf ("(Fortran 03)"); break;
3047 case DW_LANG_Fortran08
: printf ("(Fortran 08)"); break;
3048 case DW_LANG_RenderScript
: printf ("(RenderScript)"); break;
3049 /* MIPS extension. */
3050 case DW_LANG_Mips_Assembler
: printf ("(MIPS assembler)"); break;
3051 /* UPC extension. */
3052 case DW_LANG_Upc
: printf ("(Unified Parallel C)"); break;
3054 if (uvalue
>= DW_LANG_lo_user
&& uvalue
<= DW_LANG_hi_user
)
3055 printf (_("(implementation defined: %s)"),
3056 dwarf_vmatoa ("x", uvalue
));
3058 printf (_("(Unknown: %s)"), dwarf_vmatoa ("x", uvalue
));
3063 case DW_AT_encoding
:
3067 case DW_ATE_void
: printf ("(void)"); break;
3068 case DW_ATE_address
: printf ("(machine address)"); break;
3069 case DW_ATE_boolean
: printf ("(boolean)"); break;
3070 case DW_ATE_complex_float
: printf ("(complex float)"); break;
3071 case DW_ATE_float
: printf ("(float)"); break;
3072 case DW_ATE_signed
: printf ("(signed)"); break;
3073 case DW_ATE_signed_char
: printf ("(signed char)"); break;
3074 case DW_ATE_unsigned
: printf ("(unsigned)"); break;
3075 case DW_ATE_unsigned_char
: printf ("(unsigned char)"); break;
3076 /* DWARF 2.1 values: */
3077 case DW_ATE_imaginary_float
: printf ("(imaginary float)"); break;
3078 case DW_ATE_decimal_float
: printf ("(decimal float)"); break;
3079 /* DWARF 3 values: */
3080 case DW_ATE_packed_decimal
: printf ("(packed_decimal)"); break;
3081 case DW_ATE_numeric_string
: printf ("(numeric_string)"); break;
3082 case DW_ATE_edited
: printf ("(edited)"); break;
3083 case DW_ATE_signed_fixed
: printf ("(signed_fixed)"); break;
3084 case DW_ATE_unsigned_fixed
: printf ("(unsigned_fixed)"); break;
3085 /* DWARF 4 values: */
3086 case DW_ATE_UTF
: printf ("(unicode string)"); break;
3087 /* DWARF 5 values: */
3088 case DW_ATE_UCS
: printf ("(UCS)"); break;
3089 case DW_ATE_ASCII
: printf ("(ASCII)"); break;
3091 /* HP extensions: */
3092 case DW_ATE_HP_float80
: printf ("(HP_float80)"); break;
3093 case DW_ATE_HP_complex_float80
: printf ("(HP_complex_float80)"); break;
3094 case DW_ATE_HP_float128
: printf ("(HP_float128)"); break;
3095 case DW_ATE_HP_complex_float128
:printf ("(HP_complex_float128)"); break;
3096 case DW_ATE_HP_floathpintel
: printf ("(HP_floathpintel)"); break;
3097 case DW_ATE_HP_imaginary_float80
: printf ("(HP_imaginary_float80)"); break;
3098 case DW_ATE_HP_imaginary_float128
: printf ("(HP_imaginary_float128)"); break;
3101 if (uvalue
>= DW_ATE_lo_user
3102 && uvalue
<= DW_ATE_hi_user
)
3103 printf (_("(user defined type)"));
3105 printf (_("(unknown type)"));
3110 case DW_AT_accessibility
:
3114 case DW_ACCESS_public
: printf ("(public)"); break;
3115 case DW_ACCESS_protected
: printf ("(protected)"); break;
3116 case DW_ACCESS_private
: printf ("(private)"); break;
3118 printf (_("(unknown accessibility)"));
3123 case DW_AT_visibility
:
3127 case DW_VIS_local
: printf ("(local)"); break;
3128 case DW_VIS_exported
: printf ("(exported)"); break;
3129 case DW_VIS_qualified
: printf ("(qualified)"); break;
3130 default: printf (_("(unknown visibility)")); break;
3134 case DW_AT_endianity
:
3138 case DW_END_default
: printf ("(default)"); break;
3139 case DW_END_big
: printf ("(big)"); break;
3140 case DW_END_little
: printf ("(little)"); break;
3142 if (uvalue
>= DW_END_lo_user
&& uvalue
<= DW_END_hi_user
)
3143 printf (_("(user specified)"));
3145 printf (_("(unknown endianity)"));
3150 case DW_AT_virtuality
:
3154 case DW_VIRTUALITY_none
: printf ("(none)"); break;
3155 case DW_VIRTUALITY_virtual
: printf ("(virtual)"); break;
3156 case DW_VIRTUALITY_pure_virtual
:printf ("(pure_virtual)"); break;
3157 default: printf (_("(unknown virtuality)")); break;
3161 case DW_AT_identifier_case
:
3165 case DW_ID_case_sensitive
: printf ("(case_sensitive)"); break;
3166 case DW_ID_up_case
: printf ("(up_case)"); break;
3167 case DW_ID_down_case
: printf ("(down_case)"); break;
3168 case DW_ID_case_insensitive
: printf ("(case_insensitive)"); break;
3169 default: printf (_("(unknown case)")); break;
3173 case DW_AT_calling_convention
:
3177 case DW_CC_normal
: printf ("(normal)"); break;
3178 case DW_CC_program
: printf ("(program)"); break;
3179 case DW_CC_nocall
: printf ("(nocall)"); break;
3180 case DW_CC_pass_by_reference
: printf ("(pass by ref)"); break;
3181 case DW_CC_pass_by_value
: printf ("(pass by value)"); break;
3182 case DW_CC_GNU_renesas_sh
: printf ("(Rensas SH)"); break;
3183 case DW_CC_GNU_borland_fastcall_i386
: printf ("(Borland fastcall i386)"); break;
3185 if (uvalue
>= DW_CC_lo_user
3186 && uvalue
<= DW_CC_hi_user
)
3187 printf (_("(user defined)"));
3189 printf (_("(unknown convention)"));
3193 case DW_AT_ordering
:
3198 case -1: printf (_("(undefined)")); break;
3199 case 0: printf ("(row major)"); break;
3200 case 1: printf ("(column major)"); break;
3204 case DW_AT_decimal_sign
:
3208 case DW_DS_unsigned
: printf (_("(unsigned)")); break;
3209 case DW_DS_leading_overpunch
: printf (_("(leading overpunch)")); break;
3210 case DW_DS_trailing_overpunch
: printf (_("(trailing overpunch)")); break;
3211 case DW_DS_leading_separate
: printf (_("(leading separate)")); break;
3212 case DW_DS_trailing_separate
: printf (_("(trailing separate)")); break;
3213 default: printf (_("(unrecognised)")); break;
3217 case DW_AT_defaulted
:
3221 case DW_DEFAULTED_no
: printf (_("(no)")); break;
3222 case DW_DEFAULTED_in_class
: printf (_("(in class)")); break;
3223 case DW_DEFAULTED_out_of_class
: printf (_("(out of class)")); break;
3224 default: printf (_("(unrecognised)")); break;
3228 case DW_AT_discr_list
:
3230 display_discr_list (form
, uvalue
, data
, end
, level
);
3233 case DW_AT_frame_base
:
3234 have_frame_base
= 1;
3236 case DW_AT_location
:
3237 case DW_AT_string_length
:
3238 case DW_AT_return_addr
:
3239 case DW_AT_data_member_location
:
3240 case DW_AT_vtable_elem_location
:
3242 case DW_AT_static_link
:
3243 case DW_AT_use_location
:
3244 case DW_AT_call_value
:
3245 case DW_AT_GNU_call_site_value
:
3246 case DW_AT_call_data_value
:
3247 case DW_AT_GNU_call_site_data_value
:
3248 case DW_AT_call_target
:
3249 case DW_AT_GNU_call_site_target
:
3250 case DW_AT_call_target_clobbered
:
3251 case DW_AT_GNU_call_site_target_clobbered
:
3252 if ((dwarf_version
< 4
3253 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
3254 || form
== DW_FORM_sec_offset
)
3255 printf (_(" (location list)"));
3257 case DW_AT_allocated
:
3258 case DW_AT_associated
:
3259 case DW_AT_data_location
:
3261 case DW_AT_upper_bound
:
3262 case DW_AT_lower_bound
:
3265 int need_frame_base
;
3268 need_frame_base
= decode_location_expression (block_start
,
3273 cu_offset
, section
);
3275 if (need_frame_base
&& !have_frame_base
)
3276 printf (_(" [without DW_AT_frame_base]"));
3280 case DW_AT_data_bit_offset
:
3281 case DW_AT_byte_size
:
3282 case DW_AT_bit_size
:
3283 case DW_AT_string_length_byte_size
:
3284 case DW_AT_string_length_bit_size
:
3285 case DW_AT_bit_stride
:
3286 if (form
== DW_FORM_exprloc
)
3289 (void) decode_location_expression (block_start
, pointer_size
,
3290 offset_size
, dwarf_version
,
3291 uvalue
, cu_offset
, section
);
3298 unsigned long abbrev_number
;
3299 abbrev_entry
*entry
;
3301 entry
= get_type_abbrev_from_form (form
, uvalue
, cu_offset
,
3302 section
, & abbrev_number
, NULL
, NULL
);
3305 if (form
!= DW_FORM_GNU_ref_alt
)
3306 warn (_("Offset %s used as value for DW_AT_import attribute of DIE at offset 0x%lx is too big.\n"),
3307 dwarf_vmatoa ("x", uvalue
),
3308 (unsigned long) (orig_data
- section
->start
));
3312 printf (_("\t[Abbrev Number: %ld"), abbrev_number
);
3313 printf (" (%s)", get_TAG_name (entry
->tag
));
3326 static unsigned char *
3327 read_and_display_attr (unsigned long attribute
,
3329 dwarf_signed_vma implicit_const
,
3330 unsigned char * start
,
3331 unsigned char * data
,
3332 unsigned char * end
,
3333 dwarf_vma cu_offset
,
3334 dwarf_vma pointer_size
,
3335 dwarf_vma offset_size
,
3337 debug_info
* debug_info_p
,
3339 struct dwarf_section
* section
,
3340 struct cu_tu_set
* this_set
,
3344 printf (" %-18s:", get_AT_name (attribute
));
3345 data
= read_and_display_attr_value (attribute
, form
, implicit_const
,
3347 cu_offset
, pointer_size
, offset_size
,
3348 dwarf_version
, debug_info_p
,
3349 do_loc
, section
, this_set
, ' ', level
);
3355 /* Like load_debug_section, but if the ordinary call fails, and we are
3356 following debug links, then attempt to load the requested section
3357 from one of the separate debug info files. */
3360 load_debug_section_with_follow (enum dwarf_section_display_enum sec_enum
,
3363 if (load_debug_section (sec_enum
, handle
))
3365 if (debug_displays
[sec_enum
].section
.filename
== NULL
)
3367 /* See if we can associate a filename with this section. */
3370 for (i
= first_separate_info
; i
!= NULL
; i
= i
->next
)
3371 if (i
->handle
== handle
)
3373 debug_displays
[sec_enum
].section
.filename
= i
->filename
;
3381 if (do_follow_links
)
3385 for (i
= first_separate_info
; i
!= NULL
; i
= i
->next
)
3387 if (load_debug_section (sec_enum
, i
->handle
))
3389 debug_displays
[sec_enum
].section
.filename
= i
->filename
;
3391 /* FIXME: We should check to see if any of the remaining debug info
3392 files also contain this section, and, umm, do something about it. */
3402 introduce (struct dwarf_section
* section
, bool raw
)
3406 if (do_follow_links
&& section
->filename
)
3407 printf (_("Raw dump of debug contents of section %s (loaded from %s):\n\n"),
3408 section
->name
, section
->filename
);
3410 printf (_("Raw dump of debug contents of section %s:\n\n"), section
->name
);
3414 if (do_follow_links
&& section
->filename
)
3415 printf (_("Contents of the %s section (loaded from %s):\n\n"),
3416 section
->name
, section
->filename
);
3418 printf (_("Contents of the %s section:\n\n"), section
->name
);
3422 /* Process the contents of a .debug_info section.
3423 If do_loc is TRUE then we are scanning for location lists and dwo tags
3424 and we do not want to display anything to the user.
3425 If do_types is TRUE, we are processing a .debug_types section instead of
3426 a .debug_info section.
3427 The information displayed is restricted by the values in DWARF_START_DIE
3428 and DWARF_CUTOFF_LEVEL.
3429 Returns TRUE upon success. Otherwise an error or warning message is
3430 printed and FALSE is returned. */
3433 process_debug_info (struct dwarf_section
* section
,
3435 enum dwarf_section_display_enum abbrev_sec
,
3439 unsigned char *start
= section
->start
;
3440 unsigned char *end
= start
+ section
->size
;
3441 unsigned char *section_begin
;
3443 unsigned int num_units
= 0;
3445 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
3446 && num_debug_info_entries
== 0
3451 /* First scan the section to get the number of comp units. */
3452 for (section_begin
= start
, num_units
= 0; section_begin
< end
;
3455 /* Read the first 4 bytes. For a 32-bit DWARF section, this
3456 will be the length. For a 64-bit DWARF section, it'll be
3457 the escape code 0xffffffff followed by an 8 byte length. */
3458 SAFE_BYTE_GET (length
, section_begin
, 4, end
);
3460 if (length
== 0xffffffff)
3462 SAFE_BYTE_GET (length
, section_begin
+ 4, 8, end
);
3463 section_begin
+= length
+ 12;
3465 else if (length
>= 0xfffffff0 && length
< 0xffffffff)
3467 warn (_("Reserved length value (0x%s) found in section %s\n"),
3468 dwarf_vmatoa ("x", length
), section
->name
);
3472 section_begin
+= length
+ 4;
3474 /* Negative values are illegal, they may even cause infinite
3475 looping. This can happen if we can't accurately apply
3476 relocations to an object file, or if the file is corrupt. */
3477 if ((signed long) length
<= 0 || section_begin
< start
)
3479 warn (_("Corrupt unit length (0x%s) found in section %s\n"),
3480 dwarf_vmatoa ("x", length
), section
->name
);
3487 error (_("No comp units in %s section ?\n"), section
->name
);
3491 /* Then allocate an array to hold the information. */
3492 debug_information
= (debug_info
*) cmalloc (num_units
,
3493 sizeof (* debug_information
));
3494 if (debug_information
== NULL
)
3496 error (_("Not enough memory for a debug info array of %u entries\n"),
3498 alloc_num_debug_info_entries
= num_debug_info_entries
= 0;
3502 /* PR 17531: file: 92ca3797.
3503 We cannot rely upon the debug_information array being initialised
3504 before it is used. A corrupt file could easily contain references
3505 to a unit for which information has not been made available. So
3506 we ensure that the array is zeroed here. */
3507 memset (debug_information
, 0, num_units
* sizeof (*debug_information
));
3509 alloc_num_debug_info_entries
= num_units
;
3514 load_debug_section_with_follow (str
, file
);
3515 load_debug_section_with_follow (line_str
, file
);
3516 load_debug_section_with_follow (str_dwo
, file
);
3517 load_debug_section_with_follow (str_index
, file
);
3518 load_debug_section_with_follow (str_index_dwo
, file
);
3519 load_debug_section_with_follow (debug_addr
, file
);
3522 load_debug_section_with_follow (abbrev_sec
, file
);
3523 if (debug_displays
[abbrev_sec
].section
.start
== NULL
)
3525 warn (_("Unable to locate %s section!\n"),
3526 debug_displays
[abbrev_sec
].section
.uncompressed_name
);
3530 if (!do_loc
&& dwarf_start_die
== 0)
3531 introduce (section
, false);
3533 free_all_abbrevs ();
3534 free (cu_abbrev_map
);
3535 cu_abbrev_map
= NULL
;
3536 next_free_abbrev_map_entry
= 0;
3538 /* In order to be able to resolve DW_FORM_ref_attr forms we need
3539 to load *all* of the abbrevs for all CUs in this .debug_info
3540 section. This does effectively mean that we (partially) read
3541 every CU header twice. */
3542 for (section_begin
= start
; start
< end
;)
3544 DWARF2_Internal_CompUnit compunit
;
3545 unsigned char * hdrptr
;
3546 dwarf_vma abbrev_base
;
3548 dwarf_vma cu_offset
;
3549 unsigned int offset_size
;
3550 unsigned int initial_length_size
;
3551 struct cu_tu_set
* this_set
;
3556 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 4, end
);
3558 if (compunit
.cu_length
== 0xffffffff)
3560 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 8, end
);
3562 initial_length_size
= 12;
3567 initial_length_size
= 4;
3570 SAFE_BYTE_GET_AND_INC (compunit
.cu_version
, hdrptr
, 2, end
);
3572 cu_offset
= start
- section_begin
;
3574 this_set
= find_cu_tu_set_v2 (cu_offset
, do_types
);
3576 if (compunit
.cu_version
< 5)
3578 compunit
.cu_unit_type
= DW_UT_compile
;
3579 /* Initialize it due to a false compiler warning. */
3580 compunit
.cu_pointer_size
= -1;
3584 SAFE_BYTE_GET_AND_INC (compunit
.cu_unit_type
, hdrptr
, 1, end
);
3585 do_types
= (compunit
.cu_unit_type
== DW_UT_type
);
3587 SAFE_BYTE_GET_AND_INC (compunit
.cu_pointer_size
, hdrptr
, 1, end
);
3590 SAFE_BYTE_GET_AND_INC (compunit
.cu_abbrev_offset
, hdrptr
, offset_size
, end
);
3592 if (compunit
.cu_unit_type
== DW_UT_split_compile
3593 || compunit
.cu_unit_type
== DW_UT_skeleton
)
3596 SAFE_BYTE_GET_AND_INC (dwo_id
, hdrptr
, 8, end
);
3599 if (this_set
== NULL
)
3602 abbrev_size
= debug_displays
[abbrev_sec
].section
.size
;
3606 abbrev_base
= this_set
->section_offsets
[DW_SECT_ABBREV
];
3607 abbrev_size
= this_set
->section_sizes
[DW_SECT_ABBREV
];
3610 list
= find_abbrev_list_by_abbrev_offset (abbrev_base
,
3611 compunit
.cu_abbrev_offset
);
3614 unsigned char * next
;
3616 list
= new_abbrev_list (abbrev_base
,
3617 compunit
.cu_abbrev_offset
);
3618 next
= process_abbrev_set (&debug_displays
[abbrev_sec
].section
,
3619 abbrev_base
, abbrev_size
,
3620 compunit
.cu_abbrev_offset
, list
);
3621 list
->start_of_next_abbrevs
= next
;
3624 start
= section_begin
+ cu_offset
+ compunit
.cu_length
3625 + initial_length_size
;
3626 record_abbrev_list_for_cu (cu_offset
, start
- section_begin
, list
);
3629 for (start
= section_begin
, unit
= 0; start
< end
; unit
++)
3631 DWARF2_Internal_CompUnit compunit
;
3632 unsigned char *hdrptr
;
3633 unsigned char *tags
;
3634 int level
, last_level
, saved_level
;
3635 dwarf_vma cu_offset
;
3636 unsigned long sec_off
;
3637 unsigned int offset_size
;
3638 unsigned int initial_length_size
;
3639 dwarf_vma signature
= 0;
3640 dwarf_vma type_offset
= 0;
3641 struct cu_tu_set
*this_set
;
3642 dwarf_vma abbrev_base
;
3644 abbrev_list
* list
= NULL
;
3648 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 4, end
);
3650 if (compunit
.cu_length
== 0xffffffff)
3652 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 8, end
);
3654 initial_length_size
= 12;
3659 initial_length_size
= 4;
3662 SAFE_BYTE_GET_AND_INC (compunit
.cu_version
, hdrptr
, 2, end
);
3664 cu_offset
= start
- section_begin
;
3666 this_set
= find_cu_tu_set_v2 (cu_offset
, do_types
);
3668 if (compunit
.cu_version
< 5)
3670 compunit
.cu_unit_type
= DW_UT_compile
;
3671 /* Initialize it due to a false compiler warning. */
3672 compunit
.cu_pointer_size
= -1;
3676 SAFE_BYTE_GET_AND_INC (compunit
.cu_unit_type
, hdrptr
, 1, end
);
3677 do_types
= (compunit
.cu_unit_type
== DW_UT_type
);
3679 SAFE_BYTE_GET_AND_INC (compunit
.cu_pointer_size
, hdrptr
, 1, end
);
3682 SAFE_BYTE_GET_AND_INC (compunit
.cu_abbrev_offset
, hdrptr
, offset_size
, end
);
3684 if (this_set
== NULL
)
3687 abbrev_size
= debug_displays
[abbrev_sec
].section
.size
;
3691 abbrev_base
= this_set
->section_offsets
[DW_SECT_ABBREV
];
3692 abbrev_size
= this_set
->section_sizes
[DW_SECT_ABBREV
];
3695 if (compunit
.cu_version
< 5)
3696 SAFE_BYTE_GET_AND_INC (compunit
.cu_pointer_size
, hdrptr
, 1, end
);
3698 bool do_dwo_id
= false;
3699 uint64_t dwo_id
= 0;
3700 if (compunit
.cu_unit_type
== DW_UT_split_compile
3701 || compunit
.cu_unit_type
== DW_UT_skeleton
)
3703 SAFE_BYTE_GET_AND_INC (dwo_id
, hdrptr
, 8, end
);
3707 /* PR 17512: file: 001-108546-0.001:0.1. */
3708 if (compunit
.cu_pointer_size
< 2 || compunit
.cu_pointer_size
> 8)
3710 warn (_("Invalid pointer size (%d) in compunit header, using %d instead\n"),
3711 compunit
.cu_pointer_size
, offset_size
);
3712 compunit
.cu_pointer_size
= offset_size
;
3717 SAFE_BYTE_GET_AND_INC (signature
, hdrptr
, 8, end
);
3718 SAFE_BYTE_GET_AND_INC (type_offset
, hdrptr
, offset_size
, end
);
3721 if (dwarf_start_die
> (cu_offset
+ compunit
.cu_length
3722 + initial_length_size
))
3724 start
= section_begin
+ cu_offset
+ compunit
.cu_length
3725 + initial_length_size
;
3729 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
3730 && num_debug_info_entries
== 0
3731 && alloc_num_debug_info_entries
> unit
3734 debug_information
[unit
].cu_offset
= cu_offset
;
3735 debug_information
[unit
].pointer_size
3736 = compunit
.cu_pointer_size
;
3737 debug_information
[unit
].offset_size
= offset_size
;
3738 debug_information
[unit
].dwarf_version
= compunit
.cu_version
;
3739 debug_information
[unit
].base_address
= 0;
3740 debug_information
[unit
].addr_base
= DEBUG_INFO_UNAVAILABLE
;
3741 debug_information
[unit
].ranges_base
= DEBUG_INFO_UNAVAILABLE
;
3742 debug_information
[unit
].loc_offsets
= NULL
;
3743 debug_information
[unit
].have_frame_base
= NULL
;
3744 debug_information
[unit
].max_loc_offsets
= 0;
3745 debug_information
[unit
].num_loc_offsets
= 0;
3746 debug_information
[unit
].range_lists
= NULL
;
3747 debug_information
[unit
].max_range_lists
= 0;
3748 debug_information
[unit
].num_range_lists
= 0;
3751 if (!do_loc
&& dwarf_start_die
== 0)
3753 printf (_(" Compilation Unit @ offset 0x%s:\n"),
3754 dwarf_vmatoa ("x", cu_offset
));
3755 printf (_(" Length: 0x%s (%s)\n"),
3756 dwarf_vmatoa ("x", compunit
.cu_length
),
3757 offset_size
== 8 ? "64-bit" : "32-bit");
3758 printf (_(" Version: %d\n"), compunit
.cu_version
);
3759 if (compunit
.cu_version
>= 5)
3761 const char *name
= get_DW_UT_name (compunit
.cu_unit_type
);
3763 printf (_(" Unit Type: %s (%x)\n"),
3764 name
? name
: "???",
3765 compunit
.cu_unit_type
);
3767 printf (_(" Abbrev Offset: 0x%s\n"),
3768 dwarf_vmatoa ("x", compunit
.cu_abbrev_offset
));
3769 printf (_(" Pointer Size: %d\n"), compunit
.cu_pointer_size
);
3772 printf (_(" Signature: 0x%s\n"),
3773 dwarf_vmatoa ("x", signature
));
3774 printf (_(" Type Offset: 0x%s\n"),
3775 dwarf_vmatoa ("x", type_offset
));
3778 printf (_(" DWO ID: 0x%s\n"), dwarf_vmatoa ("x", dwo_id
));
3779 if (this_set
!= NULL
)
3781 dwarf_vma
*offsets
= this_set
->section_offsets
;
3782 size_t *sizes
= this_set
->section_sizes
;
3784 printf (_(" Section contributions:\n"));
3785 printf (_(" .debug_abbrev.dwo: 0x%s 0x%s\n"),
3786 dwarf_vmatoa ("x", offsets
[DW_SECT_ABBREV
]),
3787 dwarf_vmatoa ("x", sizes
[DW_SECT_ABBREV
]));
3788 printf (_(" .debug_line.dwo: 0x%s 0x%s\n"),
3789 dwarf_vmatoa ("x", offsets
[DW_SECT_LINE
]),
3790 dwarf_vmatoa ("x", sizes
[DW_SECT_LINE
]));
3791 printf (_(" .debug_loc.dwo: 0x%s 0x%s\n"),
3792 dwarf_vmatoa ("x", offsets
[DW_SECT_LOC
]),
3793 dwarf_vmatoa ("x", sizes
[DW_SECT_LOC
]));
3794 printf (_(" .debug_str_offsets.dwo: 0x%s 0x%s\n"),
3795 dwarf_vmatoa ("x", offsets
[DW_SECT_STR_OFFSETS
]),
3796 dwarf_vmatoa ("x", sizes
[DW_SECT_STR_OFFSETS
]));
3800 sec_off
= cu_offset
+ initial_length_size
;
3801 if (sec_off
+ compunit
.cu_length
< sec_off
3802 || sec_off
+ compunit
.cu_length
> section
->size
)
3804 warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"),
3806 (unsigned long) cu_offset
,
3807 dwarf_vmatoa ("x", compunit
.cu_length
));
3813 start
+= compunit
.cu_length
+ initial_length_size
;
3815 if (compunit
.cu_version
< 2 || compunit
.cu_version
> 5)
3817 warn (_("CU at offset %s contains corrupt or "
3818 "unsupported version number: %d.\n"),
3819 dwarf_vmatoa ("x", cu_offset
), compunit
.cu_version
);
3823 if (compunit
.cu_unit_type
!= DW_UT_compile
3824 && compunit
.cu_unit_type
!= DW_UT_partial
3825 && compunit
.cu_unit_type
!= DW_UT_type
3826 && compunit
.cu_unit_type
!= DW_UT_split_compile
3827 && compunit
.cu_unit_type
!= DW_UT_skeleton
)
3829 warn (_("CU at offset %s contains corrupt or "
3830 "unsupported unit type: %d.\n"),
3831 dwarf_vmatoa ("x", cu_offset
), compunit
.cu_unit_type
);
3835 /* Process the abbrevs used by this compilation unit. */
3836 list
= find_abbrev_list_by_abbrev_offset (abbrev_base
,
3837 compunit
.cu_abbrev_offset
);
3840 unsigned char *next
;
3842 list
= new_abbrev_list (abbrev_base
,
3843 compunit
.cu_abbrev_offset
);
3844 next
= process_abbrev_set (&debug_displays
[abbrev_sec
].section
,
3845 abbrev_base
, abbrev_size
,
3846 compunit
.cu_abbrev_offset
, list
);
3847 list
->start_of_next_abbrevs
= next
;
3853 while (tags
< start
)
3855 unsigned long abbrev_number
;
3856 unsigned long die_offset
;
3857 abbrev_entry
*entry
;
3859 int do_printing
= 1;
3861 die_offset
= tags
- section_begin
;
3863 READ_ULEB (abbrev_number
, tags
, start
);
3865 /* A null DIE marks the end of a list of siblings or it may also be
3866 a section padding. */
3867 if (abbrev_number
== 0)
3869 /* Check if it can be a section padding for the last CU. */
3870 if (level
== 0 && start
== end
)
3874 for (chk
= tags
; chk
< start
; chk
++)
3881 if (!do_loc
&& die_offset
>= dwarf_start_die
3882 && (dwarf_cutoff_level
== -1
3883 || level
< dwarf_cutoff_level
))
3884 printf (_(" <%d><%lx>: Abbrev Number: 0\n"),
3890 static unsigned num_bogus_warns
= 0;
3892 if (num_bogus_warns
< 3)
3894 warn (_("Bogus end-of-siblings marker detected at offset %lx in %s section\n"),
3895 die_offset
, section
->name
);
3897 if (num_bogus_warns
== 3)
3898 warn (_("Further warnings about bogus end-of-sibling markers suppressed\n"));
3901 if (dwarf_start_die
!= 0 && level
< saved_level
)
3908 if (dwarf_start_die
!= 0 && die_offset
< dwarf_start_die
)
3912 if (dwarf_start_die
!= 0 && die_offset
== dwarf_start_die
)
3913 saved_level
= level
;
3914 do_printing
= (dwarf_cutoff_level
== -1
3915 || level
< dwarf_cutoff_level
);
3917 printf (_(" <%d><%lx>: Abbrev Number: %lu"),
3918 level
, die_offset
, abbrev_number
);
3919 else if (dwarf_cutoff_level
== -1
3920 || last_level
< dwarf_cutoff_level
)
3921 printf (_(" <%d><%lx>: ...\n"), level
, die_offset
);
3926 /* Scan through the abbreviation list until we reach the
3931 for (entry
= list
->first_abbrev
; entry
!= NULL
; entry
= entry
->next
)
3932 if (entry
->number
== abbrev_number
)
3937 if (!do_loc
&& do_printing
)
3942 warn (_("DIE at offset 0x%lx refers to abbreviation number %lu which does not exist\n"),
3943 die_offset
, abbrev_number
);
3947 if (!do_loc
&& do_printing
)
3948 printf (" (%s)\n", get_TAG_name (entry
->tag
));
3953 need_base_address
= 0;
3955 case DW_TAG_compile_unit
:
3956 need_base_address
= 1;
3957 need_dwo_info
= do_loc
;
3959 case DW_TAG_entry_point
:
3960 case DW_TAG_subprogram
:
3961 need_base_address
= 0;
3962 /* Assuming that there is no DW_AT_frame_base. */
3963 have_frame_base
= 0;
3967 debug_info
*debug_info_p
=
3968 (debug_information
&& unit
< alloc_num_debug_info_entries
)
3969 ? debug_information
+ unit
: NULL
;
3971 assert (!debug_info_p
3972 || (debug_info_p
->num_loc_offsets
3973 == debug_info_p
->num_loc_views
));
3975 for (attr
= entry
->first_attr
;
3976 attr
&& attr
->attribute
;
3979 if (! do_loc
&& do_printing
)
3980 /* Show the offset from where the tag was extracted. */
3981 printf (" <%lx>", (unsigned long)(tags
- section_begin
));
3982 tags
= read_and_display_attr (attr
->attribute
,
3984 attr
->implicit_const
,
3989 compunit
.cu_pointer_size
,
3991 compunit
.cu_version
,
3993 do_loc
|| ! do_printing
,
3999 /* If a locview attribute appears before a location one,
4000 make sure we don't associate it with an earlier
4003 switch (debug_info_p
->num_loc_offsets
- debug_info_p
->num_loc_views
)
4006 debug_info_p
->loc_views
[debug_info_p
->num_loc_views
] = vm1
;
4007 debug_info_p
->num_loc_views
++;
4008 assert (debug_info_p
->num_loc_views
4009 == debug_info_p
->num_loc_offsets
);
4016 warn(_("DIE has locviews without loclist\n"));
4017 debug_info_p
->num_loc_views
--;
4024 if (entry
->children
)
4029 /* Set num_debug_info_entries here so that it can be used to check if
4030 we need to process .debug_loc and .debug_ranges sections. */
4031 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
4032 && num_debug_info_entries
== 0
4035 if (num_units
> alloc_num_debug_info_entries
)
4036 num_debug_info_entries
= alloc_num_debug_info_entries
;
4038 num_debug_info_entries
= num_units
;
4047 /* Locate and scan the .debug_info section in the file and record the pointer
4048 sizes and offsets for the compilation units in it. Usually an executable
4049 will have just one pointer size, but this is not guaranteed, and so we try
4050 not to make any assumptions. Returns zero upon failure, or the number of
4051 compilation units upon success. */
4054 load_debug_info (void * file
)
4056 /* If we have already tried and failed to load the .debug_info
4057 section then do not bother to repeat the task. */
4058 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
4061 /* If we already have the information there is nothing else to do. */
4062 if (num_debug_info_entries
> 0)
4063 return num_debug_info_entries
;
4065 /* If this is a DWARF package file, load the CU and TU indexes. */
4066 (void) load_cu_tu_indexes (file
);
4068 if (load_debug_section_with_follow (info
, file
)
4069 && process_debug_info (&debug_displays
[info
].section
, file
, abbrev
, true, false))
4070 return num_debug_info_entries
;
4072 if (load_debug_section_with_follow (info_dwo
, file
)
4073 && process_debug_info (&debug_displays
[info_dwo
].section
, file
,
4074 abbrev_dwo
, true, false))
4075 return num_debug_info_entries
;
4077 num_debug_info_entries
= DEBUG_INFO_UNAVAILABLE
;
4081 /* Read a DWARF .debug_line section header starting at DATA.
4082 Upon success returns an updated DATA pointer and the LINFO
4083 structure and the END_OF_SEQUENCE pointer will be filled in.
4084 Otherwise returns NULL. */
4086 static unsigned char *
4087 read_debug_line_header (struct dwarf_section
* section
,
4088 unsigned char * data
,
4089 unsigned char * end
,
4090 DWARF2_Internal_LineInfo
* linfo
,
4091 unsigned char ** end_of_sequence
)
4093 unsigned char *hdrptr
;
4094 unsigned int initial_length_size
;
4096 /* Extract information from the Line Number Program Header.
4097 (section 6.2.4 in the Dwarf3 doc). */
4100 /* Get and check the length of the block. */
4101 SAFE_BYTE_GET_AND_INC (linfo
->li_length
, hdrptr
, 4, end
);
4103 if (linfo
->li_length
== 0xffffffff)
4105 /* This section is 64-bit DWARF 3. */
4106 SAFE_BYTE_GET_AND_INC (linfo
->li_length
, hdrptr
, 8, end
);
4107 linfo
->li_offset_size
= 8;
4108 initial_length_size
= 12;
4112 linfo
->li_offset_size
= 4;
4113 initial_length_size
= 4;
4116 if (linfo
->li_length
+ initial_length_size
> section
->size
)
4118 /* If the length field has a relocation against it, then we should
4119 not complain if it is inaccurate (and probably negative). This
4120 happens in object files when the .debug_line section is actually
4121 comprised of several different .debug_line.* sections, (some of
4122 which may be removed by linker garbage collection), and a relocation
4123 is used to compute the correct length once that is done. */
4124 if (reloc_at (section
, (hdrptr
- section
->start
) - linfo
->li_offset_size
))
4126 linfo
->li_length
= (end
- data
) - initial_length_size
;
4130 warn (_("The length field (0x%lx) in the debug_line header is wrong - the section is too small\n"),
4131 (long) linfo
->li_length
);
4136 /* Get and check the version number. */
4137 SAFE_BYTE_GET_AND_INC (linfo
->li_version
, hdrptr
, 2, end
);
4139 if (linfo
->li_version
!= 2
4140 && linfo
->li_version
!= 3
4141 && linfo
->li_version
!= 4
4142 && linfo
->li_version
!= 5)
4144 warn (_("Only DWARF version 2, 3, 4 and 5 line info "
4145 "is currently supported.\n"));
4149 if (linfo
->li_version
>= 5)
4151 SAFE_BYTE_GET_AND_INC (linfo
->li_address_size
, hdrptr
, 1, end
);
4153 SAFE_BYTE_GET_AND_INC (linfo
->li_segment_size
, hdrptr
, 1, end
);
4154 if (linfo
->li_segment_size
!= 0)
4156 warn (_("The %s section contains "
4157 "unsupported segment selector size: %d.\n"),
4158 section
->name
, linfo
->li_segment_size
);
4163 SAFE_BYTE_GET_AND_INC (linfo
->li_prologue_length
, hdrptr
,
4164 linfo
->li_offset_size
, end
);
4165 SAFE_BYTE_GET_AND_INC (linfo
->li_min_insn_length
, hdrptr
, 1, end
);
4167 if (linfo
->li_version
>= 4)
4169 SAFE_BYTE_GET_AND_INC (linfo
->li_max_ops_per_insn
, hdrptr
, 1, end
);
4171 if (linfo
->li_max_ops_per_insn
== 0)
4173 warn (_("Invalid maximum operations per insn.\n"));
4178 linfo
->li_max_ops_per_insn
= 1;
4180 SAFE_BYTE_GET_AND_INC (linfo
->li_default_is_stmt
, hdrptr
, 1, end
);
4181 SAFE_SIGNED_BYTE_GET_AND_INC (linfo
->li_line_base
, hdrptr
, 1, end
);
4182 SAFE_BYTE_GET_AND_INC (linfo
->li_line_range
, hdrptr
, 1, end
);
4183 SAFE_BYTE_GET_AND_INC (linfo
->li_opcode_base
, hdrptr
, 1, end
);
4185 * end_of_sequence
= data
+ linfo
->li_length
+ initial_length_size
;
4186 /* PR 17512: file:002-117414-0.004. */
4187 if (* end_of_sequence
> end
)
4189 warn (_("Line length %s extends beyond end of section\n"),
4190 dwarf_vmatoa ("u", linfo
->li_length
));
4191 * end_of_sequence
= end
;
4198 static unsigned char *
4199 display_formatted_table (unsigned char *data
,
4200 unsigned char *start
,
4202 const DWARF2_Internal_LineInfo
*linfo
,
4203 struct dwarf_section
*section
,
4206 unsigned char *format_start
, format_count
, *format
, formati
;
4207 dwarf_vma data_count
, datai
;
4208 unsigned int namepass
, last_entry
= 0;
4209 const char * table_name
= is_dir
? N_("Directory Table") : N_("File Name Table");
4211 SAFE_BYTE_GET_AND_INC (format_count
, data
, 1, end
);
4212 if (do_checks
&& format_count
> 5)
4213 warn (_("Unexpectedly large number of columns in the %s (%u)\n"),
4214 table_name
, format_count
);
4216 format_start
= data
;
4217 for (formati
= 0; formati
< format_count
; formati
++)
4219 SKIP_ULEB (data
, end
);
4220 SKIP_ULEB (data
, end
);
4223 warn (_("%s: Corrupt format description entry\n"), table_name
);
4228 READ_ULEB (data_count
, data
, end
);
4229 if (data_count
== 0)
4231 printf (_("\n The %s is empty.\n"), table_name
);
4234 else if (data
>= end
)
4236 warn (_("%s: Corrupt entry count - expected %s but none found\n"),
4237 table_name
, dwarf_vmatoa ("x", data_count
));
4241 else if (format_count
== 0)
4243 warn (_("%s: format count is zero, but the table is not empty\n"),
4248 printf (_("\n The %s (offset 0x%lx, lines %s, columns %u):\n"),
4249 table_name
, (long) (data
- start
), dwarf_vmatoa ("u", data_count
),
4252 printf (_(" Entry"));
4253 /* Delay displaying name as the last entry for better screen layout. */
4254 for (namepass
= 0; namepass
< 2; namepass
++)
4256 format
= format_start
;
4257 for (formati
= 0; formati
< format_count
; formati
++)
4259 dwarf_vma content_type
;
4261 READ_ULEB (content_type
, format
, end
);
4262 if ((content_type
== DW_LNCT_path
) == (namepass
== 1))
4263 switch (content_type
)
4266 printf (_("\tName"));
4268 case DW_LNCT_directory_index
:
4269 printf (_("\tDir"));
4271 case DW_LNCT_timestamp
:
4272 printf (_("\tTime"));
4275 printf (_("\tSize"));
4278 printf (_("\tMD5\t\t\t"));
4281 printf (_("\t(Unknown format content type %s)"),
4282 dwarf_vmatoa ("u", content_type
));
4284 SKIP_ULEB (format
, end
);
4289 for (datai
= 0; datai
< data_count
; datai
++)
4291 unsigned char *datapass
= data
;
4293 printf (" %d", last_entry
++);
4294 /* Delay displaying name as the last entry for better screen layout. */
4295 for (namepass
= 0; namepass
< 2; namepass
++)
4297 format
= format_start
;
4299 for (formati
= 0; formati
< format_count
; formati
++)
4301 dwarf_vma content_type
, form
;
4303 READ_ULEB (content_type
, format
, end
);
4304 READ_ULEB (form
, format
, end
);
4305 data
= read_and_display_attr_value (0, form
, 0, start
, data
, end
,
4306 0, 0, linfo
->li_offset_size
,
4307 linfo
->li_version
, NULL
,
4308 ((content_type
== DW_LNCT_path
) != (namepass
== 1)),
4309 section
, NULL
, '\t', -1);
4313 if (data
>= end
&& (datai
< data_count
- 1))
4315 warn (_("\n%s: Corrupt entries list\n"), table_name
);
4324 display_debug_sup (struct dwarf_section
* section
,
4325 void * file ATTRIBUTE_UNUSED
)
4327 unsigned char * start
= section
->start
;
4328 unsigned char * end
= section
->start
+ section
->size
;
4329 unsigned int version
;
4330 char is_supplementary
;
4331 const unsigned char * sup_filename
;
4332 size_t sup_filename_len
;
4333 unsigned int num_read
;
4335 dwarf_vma checksum_len
;
4338 introduce (section
, true);
4339 if (section
->size
< 4)
4341 error (_("corrupt .debug_sup section: size is too small\n"));
4345 /* Read the data. */
4346 SAFE_BYTE_GET_AND_INC (version
, start
, 2, end
);
4348 warn (_("corrupt .debug_sup section: version < 5"));
4350 SAFE_BYTE_GET_AND_INC (is_supplementary
, start
, 1, end
);
4351 if (is_supplementary
!= 0 && is_supplementary
!= 1)
4352 warn (_("corrupt .debug_sup section: is_supplementary not 0 or 1\n"));
4354 sup_filename
= start
;
4355 if (is_supplementary
&& sup_filename
[0] != 0)
4356 warn (_("corrupt .debug_sup section: filename not empty in supplementary section\n"));
4358 sup_filename_len
= strnlen ((const char *) start
, end
- start
);
4359 if (sup_filename_len
== (size_t) (end
- start
))
4361 error (_("corrupt .debug_sup section: filename is not NUL terminated\n"));
4364 start
+= sup_filename_len
+ 1;
4366 checksum_len
= read_leb128 (start
, end
, false /* unsigned */, & num_read
, & status
);
4369 error (_("corrupt .debug_sup section: bad LEB128 field for checksum length\n"));
4373 if (checksum_len
> (dwarf_vma
) (end
- start
))
4375 error (_("corrupt .debug_sup section: checksum length is longer than the remaining section length\n"));
4376 checksum_len
= end
- start
;
4378 else if (checksum_len
< (dwarf_vma
) (end
- start
))
4380 warn (_("corrupt .debug_sup section: there are 0x%lx extra, unused bytes at the end of the section\n"),
4381 (long) ((end
- start
) - checksum_len
));
4384 printf (_(" Version: %u\n"), version
);
4385 printf (_(" Is Supp: %u\n"), is_supplementary
);
4386 printf (_(" Filename: %s\n"), sup_filename
);
4387 printf (_(" Checksum Len: %lu\n"), (long) checksum_len
);
4388 if (checksum_len
> 0)
4390 printf (_(" Checksum: "));
4391 while (checksum_len
--)
4392 printf ("0x%x ", * start
++ );
4399 display_debug_lines_raw (struct dwarf_section
* section
,
4400 unsigned char * data
,
4401 unsigned char * end
,
4404 unsigned char *start
= section
->start
;
4405 int verbose_view
= 0;
4407 introduce (section
, true);
4411 static DWARF2_Internal_LineInfo saved_linfo
;
4412 DWARF2_Internal_LineInfo linfo
;
4413 unsigned char *standard_opcodes
;
4414 unsigned char *end_of_sequence
;
4417 if (startswith (section
->name
, ".debug_line.")
4418 /* Note: the following does not apply to .debug_line.dwo sections.
4419 These are full debug_line sections. */
4420 && strcmp (section
->name
, ".debug_line.dwo") != 0)
4422 /* Sections named .debug_line.<foo> are fragments of a .debug_line
4423 section containing just the Line Number Statements. They are
4424 created by the assembler and intended to be used alongside gcc's
4425 -ffunction-sections command line option. When the linker's
4426 garbage collection decides to discard a .text.<foo> section it
4427 can then also discard the line number information in .debug_line.<foo>.
4429 Since the section is a fragment it does not have the details
4430 needed to fill out a LineInfo structure, so instead we use the
4431 details from the last full debug_line section that we processed. */
4432 end_of_sequence
= end
;
4433 standard_opcodes
= NULL
;
4434 linfo
= saved_linfo
;
4435 /* PR 17531: file: 0522b371. */
4436 if (linfo
.li_line_range
== 0)
4438 warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n"));
4441 reset_state_machine (linfo
.li_default_is_stmt
);
4445 unsigned char * hdrptr
;
4447 if ((hdrptr
= read_debug_line_header (section
, data
, end
, & linfo
,
4448 & end_of_sequence
)) == NULL
)
4451 printf (_(" Offset: 0x%lx\n"), (long)(data
- start
));
4452 printf (_(" Length: %ld\n"), (long) linfo
.li_length
);
4453 printf (_(" DWARF Version: %d\n"), linfo
.li_version
);
4454 if (linfo
.li_version
>= 5)
4456 printf (_(" Address size (bytes): %d\n"), linfo
.li_address_size
);
4457 printf (_(" Segment selector (bytes): %d\n"), linfo
.li_segment_size
);
4459 printf (_(" Prologue Length: %d\n"), (int) linfo
.li_prologue_length
);
4460 printf (_(" Minimum Instruction Length: %d\n"), linfo
.li_min_insn_length
);
4461 if (linfo
.li_version
>= 4)
4462 printf (_(" Maximum Ops per Instruction: %d\n"), linfo
.li_max_ops_per_insn
);
4463 printf (_(" Initial value of 'is_stmt': %d\n"), linfo
.li_default_is_stmt
);
4464 printf (_(" Line Base: %d\n"), linfo
.li_line_base
);
4465 printf (_(" Line Range: %d\n"), linfo
.li_line_range
);
4466 printf (_(" Opcode Base: %d\n"), linfo
.li_opcode_base
);
4468 /* PR 17512: file: 1665-6428-0.004. */
4469 if (linfo
.li_line_range
== 0)
4471 warn (_("Line range of 0 is invalid, using 1 instead\n"));
4472 linfo
.li_line_range
= 1;
4475 reset_state_machine (linfo
.li_default_is_stmt
);
4477 /* Display the contents of the Opcodes table. */
4478 standard_opcodes
= hdrptr
;
4480 /* PR 17512: file: 002-417945-0.004. */
4481 if (standard_opcodes
+ linfo
.li_opcode_base
>= end
)
4483 warn (_("Line Base extends beyond end of section\n"));
4487 printf (_("\n Opcodes:\n"));
4489 for (i
= 1; i
< linfo
.li_opcode_base
; i
++)
4490 printf (ngettext (" Opcode %d has %d arg\n",
4491 " Opcode %d has %d args\n",
4492 standard_opcodes
[i
- 1]),
4493 i
, standard_opcodes
[i
- 1]);
4495 /* Display the contents of the Directory table. */
4496 data
= standard_opcodes
+ linfo
.li_opcode_base
- 1;
4498 if (linfo
.li_version
>= 5)
4500 load_debug_section_with_follow (line_str
, file
);
4502 data
= display_formatted_table (data
, start
, end
, &linfo
, section
,
4504 data
= display_formatted_table (data
, start
, end
, &linfo
, section
,
4510 printf (_("\n The Directory Table is empty.\n"));
4513 unsigned int last_dir_entry
= 0;
4515 printf (_("\n The Directory Table (offset 0x%lx):\n"),
4516 (long)(data
- start
));
4518 while (data
< end
&& *data
!= 0)
4520 printf (" %d\t%.*s\n", ++last_dir_entry
, (int) (end
- data
), data
);
4522 data
+= strnlen ((char *) data
, end
- data
) + 1;
4525 /* PR 17512: file: 002-132094-0.004. */
4526 if (data
>= end
- 1)
4530 /* Skip the NUL at the end of the table. */
4533 /* Display the contents of the File Name table. */
4535 printf (_("\n The File Name Table is empty.\n"));
4538 printf (_("\n The File Name Table (offset 0x%lx):\n"),
4539 (long)(data
- start
));
4540 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
4542 while (data
< end
&& *data
!= 0)
4544 unsigned char *name
;
4547 printf (" %d\t", ++state_machine_regs
.last_file_entry
);
4549 data
+= strnlen ((char *) data
, end
- data
) + 1;
4551 READ_ULEB (val
, data
, end
);
4552 printf ("%s\t", dwarf_vmatoa ("u", val
));
4553 READ_ULEB (val
, data
, end
);
4554 printf ("%s\t", dwarf_vmatoa ("u", val
));
4555 READ_ULEB (val
, data
, end
);
4556 printf ("%s\t", dwarf_vmatoa ("u", val
));
4557 printf ("%.*s\n", (int)(end
- name
), name
);
4561 warn (_("Corrupt file name table entry\n"));
4567 /* Skip the NUL at the end of the table. */
4572 saved_linfo
= linfo
;
4575 /* Now display the statements. */
4576 if (data
>= end_of_sequence
)
4577 printf (_(" No Line Number Statements.\n"));
4580 printf (_(" Line Number Statements:\n"));
4582 while (data
< end_of_sequence
)
4584 unsigned char op_code
;
4585 dwarf_signed_vma adv
;
4588 printf (" [0x%08lx]", (long)(data
- start
));
4592 if (op_code
>= linfo
.li_opcode_base
)
4594 op_code
-= linfo
.li_opcode_base
;
4595 uladv
= (op_code
/ linfo
.li_line_range
);
4596 if (linfo
.li_max_ops_per_insn
== 1)
4598 uladv
*= linfo
.li_min_insn_length
;
4599 state_machine_regs
.address
+= uladv
;
4601 state_machine_regs
.view
= 0;
4602 printf (_(" Special opcode %d: "
4603 "advance Address by %s to 0x%s%s"),
4604 op_code
, dwarf_vmatoa ("u", uladv
),
4605 dwarf_vmatoa ("x", state_machine_regs
.address
),
4606 verbose_view
&& uladv
4607 ? _(" (reset view)") : "");
4612 = ((state_machine_regs
.op_index
+ uladv
)
4613 / linfo
.li_max_ops_per_insn
)
4614 * linfo
.li_min_insn_length
;
4616 state_machine_regs
.address
+= addrdelta
;
4617 state_machine_regs
.op_index
4618 = (state_machine_regs
.op_index
+ uladv
)
4619 % linfo
.li_max_ops_per_insn
;
4621 state_machine_regs
.view
= 0;
4622 printf (_(" Special opcode %d: "
4623 "advance Address by %s to 0x%s[%d]%s"),
4624 op_code
, dwarf_vmatoa ("u", uladv
),
4625 dwarf_vmatoa ("x", state_machine_regs
.address
),
4626 state_machine_regs
.op_index
,
4627 verbose_view
&& addrdelta
4628 ? _(" (reset view)") : "");
4630 adv
= (op_code
% linfo
.li_line_range
) + linfo
.li_line_base
;
4631 state_machine_regs
.line
+= adv
;
4632 printf (_(" and Line by %s to %d"),
4633 dwarf_vmatoa ("d", adv
), state_machine_regs
.line
);
4634 if (verbose_view
|| state_machine_regs
.view
)
4635 printf (_(" (view %u)\n"), state_machine_regs
.view
);
4638 state_machine_regs
.view
++;
4643 case DW_LNS_extended_op
:
4644 data
+= process_extended_line_op (data
,
4645 linfo
.li_default_is_stmt
,
4650 printf (_(" Copy"));
4651 if (verbose_view
|| state_machine_regs
.view
)
4652 printf (_(" (view %u)\n"), state_machine_regs
.view
);
4655 state_machine_regs
.view
++;
4658 case DW_LNS_advance_pc
:
4659 READ_ULEB (uladv
, data
, end
);
4660 if (linfo
.li_max_ops_per_insn
== 1)
4662 uladv
*= linfo
.li_min_insn_length
;
4663 state_machine_regs
.address
+= uladv
;
4665 state_machine_regs
.view
= 0;
4666 printf (_(" Advance PC by %s to 0x%s%s\n"),
4667 dwarf_vmatoa ("u", uladv
),
4668 dwarf_vmatoa ("x", state_machine_regs
.address
),
4669 verbose_view
&& uladv
4670 ? _(" (reset view)") : "");
4675 = ((state_machine_regs
.op_index
+ uladv
)
4676 / linfo
.li_max_ops_per_insn
)
4677 * linfo
.li_min_insn_length
;
4678 state_machine_regs
.address
4680 state_machine_regs
.op_index
4681 = (state_machine_regs
.op_index
+ uladv
)
4682 % linfo
.li_max_ops_per_insn
;
4684 state_machine_regs
.view
= 0;
4685 printf (_(" Advance PC by %s to 0x%s[%d]%s\n"),
4686 dwarf_vmatoa ("u", uladv
),
4687 dwarf_vmatoa ("x", state_machine_regs
.address
),
4688 state_machine_regs
.op_index
,
4689 verbose_view
&& addrdelta
4690 ? _(" (reset view)") : "");
4694 case DW_LNS_advance_line
:
4695 READ_SLEB (adv
, data
, end
);
4696 state_machine_regs
.line
+= adv
;
4697 printf (_(" Advance Line by %s to %d\n"),
4698 dwarf_vmatoa ("d", adv
),
4699 state_machine_regs
.line
);
4702 case DW_LNS_set_file
:
4703 READ_ULEB (uladv
, data
, end
);
4704 printf (_(" Set File Name to entry %s in the File Name Table\n"),
4705 dwarf_vmatoa ("u", uladv
));
4706 state_machine_regs
.file
= uladv
;
4709 case DW_LNS_set_column
:
4710 READ_ULEB (uladv
, data
, end
);
4711 printf (_(" Set column to %s\n"),
4712 dwarf_vmatoa ("u", uladv
));
4713 state_machine_regs
.column
= uladv
;
4716 case DW_LNS_negate_stmt
:
4717 adv
= state_machine_regs
.is_stmt
;
4719 printf (_(" Set is_stmt to %s\n"), dwarf_vmatoa ("d", adv
));
4720 state_machine_regs
.is_stmt
= adv
;
4723 case DW_LNS_set_basic_block
:
4724 printf (_(" Set basic block\n"));
4725 state_machine_regs
.basic_block
= 1;
4728 case DW_LNS_const_add_pc
:
4729 uladv
= ((255 - linfo
.li_opcode_base
) / linfo
.li_line_range
);
4730 if (linfo
.li_max_ops_per_insn
)
4732 uladv
*= linfo
.li_min_insn_length
;
4733 state_machine_regs
.address
+= uladv
;
4735 state_machine_regs
.view
= 0;
4736 printf (_(" Advance PC by constant %s to 0x%s%s\n"),
4737 dwarf_vmatoa ("u", uladv
),
4738 dwarf_vmatoa ("x", state_machine_regs
.address
),
4739 verbose_view
&& uladv
4740 ? _(" (reset view)") : "");
4745 = ((state_machine_regs
.op_index
+ uladv
)
4746 / linfo
.li_max_ops_per_insn
)
4747 * linfo
.li_min_insn_length
;
4748 state_machine_regs
.address
4750 state_machine_regs
.op_index
4751 = (state_machine_regs
.op_index
+ uladv
)
4752 % linfo
.li_max_ops_per_insn
;
4754 state_machine_regs
.view
= 0;
4755 printf (_(" Advance PC by constant %s to 0x%s[%d]%s\n"),
4756 dwarf_vmatoa ("u", uladv
),
4757 dwarf_vmatoa ("x", state_machine_regs
.address
),
4758 state_machine_regs
.op_index
,
4759 verbose_view
&& addrdelta
4760 ? _(" (reset view)") : "");
4764 case DW_LNS_fixed_advance_pc
:
4765 SAFE_BYTE_GET_AND_INC (uladv
, data
, 2, end
);
4766 state_machine_regs
.address
+= uladv
;
4767 state_machine_regs
.op_index
= 0;
4768 printf (_(" Advance PC by fixed size amount %s to 0x%s\n"),
4769 dwarf_vmatoa ("u", uladv
),
4770 dwarf_vmatoa ("x", state_machine_regs
.address
));
4771 /* Do NOT reset view. */
4774 case DW_LNS_set_prologue_end
:
4775 printf (_(" Set prologue_end to true\n"));
4778 case DW_LNS_set_epilogue_begin
:
4779 printf (_(" Set epilogue_begin to true\n"));
4782 case DW_LNS_set_isa
:
4783 READ_ULEB (uladv
, data
, end
);
4784 printf (_(" Set ISA to %s\n"), dwarf_vmatoa ("u", uladv
));
4788 printf (_(" Unknown opcode %d with operands: "), op_code
);
4790 if (standard_opcodes
!= NULL
)
4791 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
4793 READ_ULEB (uladv
, data
, end
);
4794 printf ("0x%s%s", dwarf_vmatoa ("x", uladv
),
4795 i
== 1 ? "" : ", ");
4810 unsigned char *name
;
4811 unsigned int directory_index
;
4812 unsigned int modification_date
;
4813 unsigned int length
;
4816 /* Output a decoded representation of the .debug_line section. */
4819 display_debug_lines_decoded (struct dwarf_section
* section
,
4820 unsigned char * start
,
4821 unsigned char * data
,
4822 unsigned char * end
,
4825 static DWARF2_Internal_LineInfo saved_linfo
;
4827 introduce (section
, false);
4831 /* This loop amounts to one iteration per compilation unit. */
4832 DWARF2_Internal_LineInfo linfo
;
4833 unsigned char *standard_opcodes
;
4834 unsigned char *end_of_sequence
;
4836 File_Entry
*file_table
= NULL
;
4837 unsigned int n_files
= 0;
4838 unsigned char **directory_table
= NULL
;
4839 dwarf_vma n_directories
= 0;
4841 if (startswith (section
->name
, ".debug_line.")
4842 /* Note: the following does not apply to .debug_line.dwo sections.
4843 These are full debug_line sections. */
4844 && strcmp (section
->name
, ".debug_line.dwo") != 0)
4846 /* See comment in display_debug_lines_raw(). */
4847 end_of_sequence
= end
;
4848 standard_opcodes
= NULL
;
4849 linfo
= saved_linfo
;
4850 /* PR 17531: file: 0522b371. */
4851 if (linfo
.li_line_range
== 0)
4853 warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n"));
4856 reset_state_machine (linfo
.li_default_is_stmt
);
4860 unsigned char *hdrptr
;
4862 if ((hdrptr
= read_debug_line_header (section
, data
, end
, & linfo
,
4863 & end_of_sequence
)) == NULL
)
4866 /* PR 17531: file: 0522b371. */
4867 if (linfo
.li_line_range
== 0)
4869 warn (_("Line range of 0 is invalid, using 1 instead\n"));
4870 linfo
.li_line_range
= 1;
4872 reset_state_machine (linfo
.li_default_is_stmt
);
4874 /* Save a pointer to the contents of the Opcodes table. */
4875 standard_opcodes
= hdrptr
;
4877 /* Traverse the Directory table just to count entries. */
4878 data
= standard_opcodes
+ linfo
.li_opcode_base
- 1;
4882 warn (_("opcode base of %d extends beyond end of section\n"),
4883 linfo
.li_opcode_base
);
4887 if (linfo
.li_version
>= 5)
4889 unsigned char *format_start
, format_count
, *format
;
4890 dwarf_vma formati
, entryi
;
4892 load_debug_section_with_follow (line_str
, fileptr
);
4894 /* Skip directories format. */
4895 SAFE_BYTE_GET_AND_INC (format_count
, data
, 1, end
);
4896 if (do_checks
&& format_count
> 1)
4897 warn (_("Unexpectedly large number of columns in the directory name table (%u)\n"),
4899 format_start
= data
;
4900 for (formati
= 0; formati
< format_count
; formati
++)
4902 SKIP_ULEB (data
, end
);
4903 SKIP_ULEB (data
, end
);
4906 READ_ULEB (n_directories
, data
, end
);
4909 warn (_("Corrupt directories list\n"));
4913 if (n_directories
== 0)
4914 directory_table
= NULL
;
4916 directory_table
= (unsigned char **)
4917 xmalloc (n_directories
* sizeof (unsigned char *));
4919 for (entryi
= 0; entryi
< n_directories
; entryi
++)
4921 unsigned char **pathp
= &directory_table
[entryi
];
4923 format
= format_start
;
4924 for (formati
= 0; formati
< format_count
; formati
++)
4926 dwarf_vma content_type
, form
;
4929 READ_ULEB (content_type
, format
, end
);
4930 READ_ULEB (form
, format
, end
);
4933 warn (_("Corrupt directories list\n"));
4936 switch (content_type
)
4941 case DW_FORM_string
:
4944 case DW_FORM_line_strp
:
4945 SAFE_BYTE_GET (uvalue
, data
, linfo
.li_offset_size
,
4947 /* Remove const by the cast. */
4948 *pathp
= (unsigned char *)
4949 fetch_indirect_line_string (uvalue
);
4954 data
= read_and_display_attr_value (0, form
, 0, start
,
4956 linfo
.li_offset_size
,
4963 warn (_("Corrupt directories list\n"));
4968 /* Skip files format. */
4969 SAFE_BYTE_GET_AND_INC (format_count
, data
, 1, end
);
4970 if (do_checks
&& format_count
> 5)
4971 warn (_("Unexpectedly large number of columns in the file name table (%u)\n"),
4973 format_start
= data
;
4974 for (formati
= 0; formati
< format_count
; formati
++)
4976 SKIP_ULEB (data
, end
);
4977 SKIP_ULEB (data
, end
);
4980 READ_ULEB (n_files
, data
, end
);
4981 if (data
>= end
&& n_files
> 0)
4983 warn (_("Corrupt file name list\n"));
4990 file_table
= (File_Entry
*) xcalloc (1, n_files
4991 * sizeof (File_Entry
));
4993 for (entryi
= 0; entryi
< n_files
; entryi
++)
4995 File_Entry
*file
= &file_table
[entryi
];
4997 format
= format_start
;
4998 for (formati
= 0; formati
< format_count
; formati
++)
5000 dwarf_vma content_type
, form
;
5004 READ_ULEB (content_type
, format
, end
);
5005 READ_ULEB (form
, format
, end
);
5008 warn (_("Corrupt file name list\n"));
5011 switch (content_type
)
5016 case DW_FORM_string
:
5019 case DW_FORM_line_strp
:
5020 SAFE_BYTE_GET (uvalue
, data
, linfo
.li_offset_size
,
5022 /* Remove const by the cast. */
5023 file
->name
= (unsigned char *)
5024 fetch_indirect_line_string (uvalue
);
5028 case DW_LNCT_directory_index
:
5032 SAFE_BYTE_GET (file
->directory_index
, data
, 1,
5036 SAFE_BYTE_GET (file
->directory_index
, data
, 2,
5041 READ_ULEB (file
->directory_index
, tmp
, end
);
5046 data
= read_and_display_attr_value (0, form
, 0, start
,
5048 linfo
.li_offset_size
,
5055 warn (_("Corrupt file name list\n"));
5064 unsigned char *ptr_directory_table
= data
;
5066 while (data
< end
&& *data
!= 0)
5068 data
+= strnlen ((char *) data
, end
- data
) + 1;
5075 warn (_("directory table ends unexpectedly\n"));
5080 /* Go through the directory table again to save the directories. */
5081 directory_table
= (unsigned char **)
5082 xmalloc (n_directories
* sizeof (unsigned char *));
5085 while (*ptr_directory_table
!= 0)
5087 directory_table
[i
] = ptr_directory_table
;
5088 ptr_directory_table
+= strnlen ((char *) ptr_directory_table
,
5089 ptr_directory_table
- end
) + 1;
5093 /* Skip the NUL at the end of the table. */
5096 /* Traverse the File Name table just to count the entries. */
5097 if (data
< end
&& *data
!= 0)
5099 unsigned char *ptr_file_name_table
= data
;
5101 while (data
< end
&& *data
!= 0)
5103 /* Skip Name, directory index, last modification
5104 time and length of file. */
5105 data
+= strnlen ((char *) data
, end
- data
) + 1;
5106 SKIP_ULEB (data
, end
);
5107 SKIP_ULEB (data
, end
);
5108 SKIP_ULEB (data
, end
);
5114 warn (_("file table ends unexpectedly\n"));
5119 /* Go through the file table again to save the strings. */
5120 file_table
= (File_Entry
*) xmalloc (n_files
* sizeof (File_Entry
));
5123 while (*ptr_file_name_table
!= 0)
5125 file_table
[i
].name
= ptr_file_name_table
;
5126 ptr_file_name_table
+= strnlen ((char *) ptr_file_name_table
,
5127 end
- ptr_file_name_table
) + 1;
5129 /* We are not interested in directory, time or size. */
5130 READ_ULEB (file_table
[i
].directory_index
,
5131 ptr_file_name_table
, end
);
5132 READ_ULEB (file_table
[i
].modification_date
,
5133 ptr_file_name_table
, end
);
5134 READ_ULEB (file_table
[i
].length
,
5135 ptr_file_name_table
, end
);
5141 /* Skip the NUL at the end of the table. */
5145 /* Print the Compilation Unit's name and a header. */
5146 if (file_table
== NULL
)
5147 printf (_("CU: No directory table\n"));
5148 else if (directory_table
== NULL
)
5149 printf (_("CU: %s:\n"), file_table
[0].name
);
5152 unsigned int ix
= file_table
[0].directory_index
;
5153 const char *directory
;
5158 else if (n_directories
== 0)
5159 directory
= _("<unknown>");
5160 else if (ix
> n_directories
)
5162 warn (_("directory index %u > number of directories %s\n"),
5163 ix
, dwarf_vmatoa ("u", n_directories
));
5164 directory
= _("<corrupt>");
5167 directory
= (char *) directory_table
[ix
- 1];
5169 if (do_wide
|| strlen (directory
) < 76)
5170 printf (_("CU: %s/%s:\n"), directory
, file_table
[0].name
);
5172 printf ("%s:\n", file_table
[0].name
);
5176 printf (_("File name Line number Starting address View Stmt\n"));
5178 printf (_("CU: Empty file name table\n"));
5179 saved_linfo
= linfo
;
5182 /* This loop iterates through the Dwarf Line Number Program. */
5183 while (data
< end_of_sequence
)
5185 unsigned char op_code
;
5188 unsigned long int uladv
;
5189 int is_special_opcode
= 0;
5194 if (op_code
>= linfo
.li_opcode_base
)
5196 op_code
-= linfo
.li_opcode_base
;
5197 uladv
= (op_code
/ linfo
.li_line_range
);
5198 if (linfo
.li_max_ops_per_insn
== 1)
5200 uladv
*= linfo
.li_min_insn_length
;
5201 state_machine_regs
.address
+= uladv
;
5203 state_machine_regs
.view
= 0;
5208 = ((state_machine_regs
.op_index
+ uladv
)
5209 / linfo
.li_max_ops_per_insn
)
5210 * linfo
.li_min_insn_length
;
5211 state_machine_regs
.address
5213 state_machine_regs
.op_index
5214 = (state_machine_regs
.op_index
+ uladv
)
5215 % linfo
.li_max_ops_per_insn
;
5217 state_machine_regs
.view
= 0;
5220 adv
= (op_code
% linfo
.li_line_range
) + linfo
.li_line_base
;
5221 state_machine_regs
.line
+= adv
;
5222 is_special_opcode
= 1;
5223 /* Increment view after printing this row. */
5228 case DW_LNS_extended_op
:
5230 unsigned int ext_op_code_len
;
5231 unsigned char ext_op_code
;
5232 unsigned char *op_code_end
;
5233 unsigned char *op_code_data
= data
;
5235 READ_ULEB (ext_op_code_len
, op_code_data
, end_of_sequence
);
5236 op_code_end
= op_code_data
+ ext_op_code_len
;
5237 if (ext_op_code_len
== 0 || op_code_end
> end_of_sequence
)
5239 warn (_("Badly formed extended line op encountered!\n"));
5242 ext_op_code
= *op_code_data
++;
5246 switch (ext_op_code
)
5248 case DW_LNE_end_sequence
:
5249 /* Reset stuff after printing this row. */
5251 case DW_LNE_set_address
:
5252 SAFE_BYTE_GET_AND_INC (state_machine_regs
.address
,
5254 op_code_end
- op_code_data
,
5256 state_machine_regs
.op_index
= 0;
5257 state_machine_regs
.view
= 0;
5259 case DW_LNE_define_file
:
5260 file_table
= (File_Entry
*) xrealloc
5261 (file_table
, (n_files
+ 1) * sizeof (File_Entry
));
5263 ++state_machine_regs
.last_file_entry
;
5264 /* Source file name. */
5265 file_table
[n_files
].name
= op_code_data
;
5266 op_code_data
+= strlen ((char *) op_code_data
) + 1;
5267 /* Directory index. */
5268 READ_ULEB (file_table
[n_files
].directory_index
,
5269 op_code_data
, op_code_end
);
5270 /* Last modification time. */
5271 READ_ULEB (file_table
[n_files
].modification_date
,
5272 op_code_data
, op_code_end
);
5274 READ_ULEB (file_table
[n_files
].length
,
5275 op_code_data
, op_code_end
);
5279 case DW_LNE_set_discriminator
:
5280 case DW_LNE_HP_set_sequence
:
5281 /* Simply ignored. */
5285 printf (_("UNKNOWN (%u): length %ld\n"),
5286 ext_op_code
, (long int) (op_code_data
- data
));
5293 /* Increment view after printing this row. */
5296 case DW_LNS_advance_pc
:
5297 READ_ULEB (uladv
, data
, end
);
5298 if (linfo
.li_max_ops_per_insn
== 1)
5300 uladv
*= linfo
.li_min_insn_length
;
5301 state_machine_regs
.address
+= uladv
;
5303 state_machine_regs
.view
= 0;
5308 = ((state_machine_regs
.op_index
+ uladv
)
5309 / linfo
.li_max_ops_per_insn
)
5310 * linfo
.li_min_insn_length
;
5311 state_machine_regs
.address
5313 state_machine_regs
.op_index
5314 = (state_machine_regs
.op_index
+ uladv
)
5315 % linfo
.li_max_ops_per_insn
;
5317 state_machine_regs
.view
= 0;
5321 case DW_LNS_advance_line
:
5322 READ_SLEB (adv
, data
, end
);
5323 state_machine_regs
.line
+= adv
;
5326 case DW_LNS_set_file
:
5327 READ_ULEB (uladv
, data
, end
);
5328 state_machine_regs
.file
= uladv
;
5331 unsigned file
= state_machine_regs
.file
- 1;
5334 if (file_table
== NULL
|| n_files
== 0)
5335 printf (_("\n [Use file table entry %d]\n"), file
);
5337 else if (file
>= n_files
)
5339 warn (_("file index %u > number of files %u\n"), file
+ 1, n_files
);
5340 printf (_("\n <over large file table index %u>"), file
);
5342 else if ((dir
= file_table
[file
].directory_index
) == 0)
5343 /* If directory index is 0, that means current directory. */
5344 printf ("\n./%s:[++]\n", file_table
[file
].name
);
5345 else if (directory_table
== NULL
|| n_directories
== 0)
5346 printf (_("\n [Use file %s in directory table entry %d]\n"),
5347 file_table
[file
].name
, dir
);
5349 else if (dir
> n_directories
)
5351 warn (_("directory index %u > number of directories %s\n"),
5352 dir
, dwarf_vmatoa ("u", n_directories
));
5353 printf (_("\n <over large directory table entry %u>\n"), dir
);
5356 printf ("\n%s/%s:\n",
5357 /* The directory index starts counting at 1. */
5358 directory_table
[dir
- 1], file_table
[file
].name
);
5362 case DW_LNS_set_column
:
5363 READ_ULEB (uladv
, data
, end
);
5364 state_machine_regs
.column
= uladv
;
5367 case DW_LNS_negate_stmt
:
5368 adv
= state_machine_regs
.is_stmt
;
5370 state_machine_regs
.is_stmt
= adv
;
5373 case DW_LNS_set_basic_block
:
5374 state_machine_regs
.basic_block
= 1;
5377 case DW_LNS_const_add_pc
:
5378 uladv
= ((255 - linfo
.li_opcode_base
) / linfo
.li_line_range
);
5379 if (linfo
.li_max_ops_per_insn
== 1)
5381 uladv
*= linfo
.li_min_insn_length
;
5382 state_machine_regs
.address
+= uladv
;
5384 state_machine_regs
.view
= 0;
5389 = ((state_machine_regs
.op_index
+ uladv
)
5390 / linfo
.li_max_ops_per_insn
)
5391 * linfo
.li_min_insn_length
;
5392 state_machine_regs
.address
5394 state_machine_regs
.op_index
5395 = (state_machine_regs
.op_index
+ uladv
)
5396 % linfo
.li_max_ops_per_insn
;
5398 state_machine_regs
.view
= 0;
5402 case DW_LNS_fixed_advance_pc
:
5403 SAFE_BYTE_GET_AND_INC (uladv
, data
, 2, end
);
5404 state_machine_regs
.address
+= uladv
;
5405 state_machine_regs
.op_index
= 0;
5406 /* Do NOT reset view. */
5409 case DW_LNS_set_prologue_end
:
5412 case DW_LNS_set_epilogue_begin
:
5415 case DW_LNS_set_isa
:
5416 READ_ULEB (uladv
, data
, end
);
5417 printf (_(" Set ISA to %lu\n"), uladv
);
5421 printf (_(" Unknown opcode %d with operands: "), op_code
);
5423 if (standard_opcodes
!= NULL
)
5424 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
5428 READ_ULEB (val
, data
, end
);
5429 printf ("0x%s%s", dwarf_vmatoa ("x", val
),
5430 i
== 1 ? "" : ", ");
5436 /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row
5437 to the DWARF address/line matrix. */
5438 if ((is_special_opcode
) || (xop
== -DW_LNE_end_sequence
)
5439 || (xop
== DW_LNS_copy
))
5441 const unsigned int MAX_FILENAME_LENGTH
= 35;
5443 char *newFileName
= NULL
;
5444 size_t fileNameLength
;
5448 unsigned indx
= state_machine_regs
.file
- 1;
5450 if (indx
>= n_files
)
5452 warn (_("corrupt file index %u encountered\n"), indx
);
5453 fileName
= _("<corrupt>");
5456 fileName
= (char *) file_table
[indx
].name
;
5459 fileName
= _("<unknown>");
5461 fileNameLength
= strlen (fileName
);
5463 if ((fileNameLength
> MAX_FILENAME_LENGTH
) && (!do_wide
))
5465 newFileName
= (char *) xmalloc (MAX_FILENAME_LENGTH
+ 1);
5466 /* Truncate file name */
5467 strncpy (newFileName
,
5468 fileName
+ fileNameLength
- MAX_FILENAME_LENGTH
,
5469 MAX_FILENAME_LENGTH
+ 1);
5470 /* FIXME: This is to pacify gcc-10 which can warn that the
5471 strncpy above might leave a non-NUL terminated string
5472 in newFileName. It won't, but gcc's analysis doesn't
5473 quite go far enough to discover this. */
5474 newFileName
[MAX_FILENAME_LENGTH
] = 0;
5478 newFileName
= (char *) xmalloc (fileNameLength
+ 1);
5479 strncpy (newFileName
, fileName
, fileNameLength
+ 1);
5482 /* A row with end_seq set to true has a meaningful address, but
5483 the other information in the same row is not significant.
5484 In such a row, print line as "-", and don't print
5486 if (!do_wide
|| (fileNameLength
<= MAX_FILENAME_LENGTH
))
5488 if (linfo
.li_max_ops_per_insn
== 1)
5490 if (xop
== -DW_LNE_end_sequence
)
5491 printf ("%-35s %11s %#18" DWARF_VMA_FMT
"x",
5493 state_machine_regs
.address
);
5495 printf ("%-35s %11d %#18" DWARF_VMA_FMT
"x",
5496 newFileName
, state_machine_regs
.line
,
5497 state_machine_regs
.address
);
5501 if (xop
== -DW_LNE_end_sequence
)
5502 printf ("%-35s %11s %#18" DWARF_VMA_FMT
"x[%d]",
5504 state_machine_regs
.address
,
5505 state_machine_regs
.op_index
);
5507 printf ("%-35s %11d %#18" DWARF_VMA_FMT
"x[%d]",
5508 newFileName
, state_machine_regs
.line
,
5509 state_machine_regs
.address
,
5510 state_machine_regs
.op_index
);
5515 if (linfo
.li_max_ops_per_insn
== 1)
5517 if (xop
== -DW_LNE_end_sequence
)
5518 printf ("%s %11s %#18" DWARF_VMA_FMT
"x",
5520 state_machine_regs
.address
);
5522 printf ("%s %11d %#18" DWARF_VMA_FMT
"x",
5523 newFileName
, state_machine_regs
.line
,
5524 state_machine_regs
.address
);
5528 if (xop
== -DW_LNE_end_sequence
)
5529 printf ("%s %11s %#18" DWARF_VMA_FMT
"x[%d]",
5531 state_machine_regs
.address
,
5532 state_machine_regs
.op_index
);
5534 printf ("%s %11d %#18" DWARF_VMA_FMT
"x[%d]",
5535 newFileName
, state_machine_regs
.line
,
5536 state_machine_regs
.address
,
5537 state_machine_regs
.op_index
);
5541 if (xop
!= -DW_LNE_end_sequence
)
5543 if (state_machine_regs
.view
)
5544 printf (" %6u", state_machine_regs
.view
);
5548 if (state_machine_regs
.is_stmt
)
5553 state_machine_regs
.view
++;
5555 if (xop
== -DW_LNE_end_sequence
)
5557 reset_state_machine (linfo
.li_default_is_stmt
);
5572 if (directory_table
)
5574 free (directory_table
);
5575 directory_table
= NULL
;
5586 display_debug_lines (struct dwarf_section
*section
, void *file
)
5588 unsigned char *data
= section
->start
;
5589 unsigned char *end
= data
+ section
->size
;
5591 int retValDecoded
= 1;
5593 if (do_debug_lines
== 0)
5594 do_debug_lines
|= FLAG_DEBUG_LINES_RAW
;
5596 if (do_debug_lines
& FLAG_DEBUG_LINES_RAW
)
5597 retValRaw
= display_debug_lines_raw (section
, data
, end
, file
);
5599 if (do_debug_lines
& FLAG_DEBUG_LINES_DECODED
)
5600 retValDecoded
= display_debug_lines_decoded (section
, data
, data
, end
, file
);
5602 if (!retValRaw
|| !retValDecoded
)
5609 find_debug_info_for_offset (unsigned long offset
)
5613 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
5616 for (i
= 0; i
< num_debug_info_entries
; i
++)
5617 if (debug_information
[i
].cu_offset
== offset
)
5618 return debug_information
+ i
;
5624 get_gdb_index_symbol_kind_name (gdb_index_symbol_kind kind
)
5626 /* See gdb/gdb-index.h. */
5627 static const char * const kinds
[] =
5639 return _ (kinds
[kind
]);
5643 display_debug_pubnames_worker (struct dwarf_section
*section
,
5644 void *file ATTRIBUTE_UNUSED
,
5647 DWARF2_Internal_PubNames names
;
5648 unsigned char *start
= section
->start
;
5649 unsigned char *end
= start
+ section
->size
;
5651 /* It does not matter if this load fails,
5652 we test for that later on. */
5653 load_debug_info (file
);
5655 introduce (section
, false);
5659 unsigned char *data
;
5660 unsigned long sec_off
;
5661 unsigned int offset_size
, initial_length_size
;
5663 SAFE_BYTE_GET_AND_INC (names
.pn_length
, start
, 4, end
);
5664 if (names
.pn_length
== 0xffffffff)
5666 SAFE_BYTE_GET_AND_INC (names
.pn_length
, start
, 8, end
);
5668 initial_length_size
= 12;
5673 initial_length_size
= 4;
5676 sec_off
= start
- section
->start
;
5677 if (sec_off
+ names
.pn_length
< sec_off
5678 || sec_off
+ names
.pn_length
> section
->size
)
5680 warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"),
5682 sec_off
- initial_length_size
,
5683 dwarf_vmatoa ("x", names
.pn_length
));
5688 start
+= names
.pn_length
;
5690 SAFE_BYTE_GET_AND_INC (names
.pn_version
, data
, 2, end
);
5691 SAFE_BYTE_GET_AND_INC (names
.pn_offset
, data
, offset_size
, end
);
5693 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
5694 && num_debug_info_entries
> 0
5695 && find_debug_info_for_offset (names
.pn_offset
) == NULL
)
5696 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
5697 (unsigned long) names
.pn_offset
, section
->name
);
5699 SAFE_BYTE_GET_AND_INC (names
.pn_size
, data
, offset_size
, end
);
5701 printf (_(" Length: %ld\n"),
5702 (long) names
.pn_length
);
5703 printf (_(" Version: %d\n"),
5705 printf (_(" Offset into .debug_info section: 0x%lx\n"),
5706 (unsigned long) names
.pn_offset
);
5707 printf (_(" Size of area in .debug_info section: %ld\n"),
5708 (long) names
.pn_size
);
5710 if (names
.pn_version
!= 2 && names
.pn_version
!= 3)
5712 static int warned
= 0;
5716 warn (_("Only DWARF 2 and 3 pubnames are currently supported\n"));
5724 printf (_("\n Offset Kind Name\n"));
5726 printf (_("\n Offset\tName\n"));
5730 bfd_size_type maxprint
;
5733 SAFE_BYTE_GET (offset
, data
, offset_size
, end
);
5738 data
+= offset_size
;
5741 maxprint
= (end
- data
) - 1;
5745 unsigned int kind_data
;
5746 gdb_index_symbol_kind kind
;
5747 const char *kind_name
;
5750 SAFE_BYTE_GET (kind_data
, data
, 1, end
);
5753 /* GCC computes the kind as the upper byte in the CU index
5754 word, and then right shifts it by the CU index size.
5755 Left shift KIND to where the gdb-index.h accessor macros
5757 kind_data
<<= GDB_INDEX_CU_BITSIZE
;
5758 kind
= GDB_INDEX_SYMBOL_KIND_VALUE (kind_data
);
5759 kind_name
= get_gdb_index_symbol_kind_name (kind
);
5760 is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (kind_data
);
5761 printf (" %-6lx %s,%-10s %.*s\n",
5762 (unsigned long) offset
, is_static
? _("s") : _("g"),
5763 kind_name
, (int) maxprint
, data
);
5766 printf (" %-6lx\t%.*s\n",
5767 (unsigned long) offset
, (int) maxprint
, data
);
5769 data
+= strnlen ((char *) data
, maxprint
) + 1;
5780 display_debug_pubnames (struct dwarf_section
*section
, void *file
)
5782 return display_debug_pubnames_worker (section
, file
, 0);
5786 display_debug_gnu_pubnames (struct dwarf_section
*section
, void *file
)
5788 return display_debug_pubnames_worker (section
, file
, 1);
5792 display_debug_macinfo (struct dwarf_section
*section
,
5793 void *file ATTRIBUTE_UNUSED
)
5795 unsigned char *start
= section
->start
;
5796 unsigned char *end
= start
+ section
->size
;
5797 unsigned char *curr
= start
;
5798 enum dwarf_macinfo_record_type op
;
5800 introduce (section
, false);
5804 unsigned int lineno
;
5805 const unsigned char *string
;
5807 op
= (enum dwarf_macinfo_record_type
) *curr
;
5812 case DW_MACINFO_start_file
:
5814 unsigned int filenum
;
5816 READ_ULEB (lineno
, curr
, end
);
5817 READ_ULEB (filenum
, curr
, end
);
5818 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"),
5823 case DW_MACINFO_end_file
:
5824 printf (_(" DW_MACINFO_end_file\n"));
5827 case DW_MACINFO_define
:
5828 READ_ULEB (lineno
, curr
, end
);
5830 curr
+= strnlen ((char *) string
, end
- string
) + 1;
5831 printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"),
5835 case DW_MACINFO_undef
:
5836 READ_ULEB (lineno
, curr
, end
);
5838 curr
+= strnlen ((char *) string
, end
- string
) + 1;
5839 printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"),
5843 case DW_MACINFO_vendor_ext
:
5845 unsigned int constant
;
5847 READ_ULEB (constant
, curr
, end
);
5849 curr
+= strnlen ((char *) string
, end
- string
) + 1;
5850 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"),
5860 /* Given LINE_OFFSET into the .debug_line section, attempt to return
5861 filename and dirname corresponding to file name table entry with index
5862 FILEIDX. Return NULL on failure. */
5864 static unsigned char *
5865 get_line_filename_and_dirname (dwarf_vma line_offset
,
5867 unsigned char **dir_name
)
5869 struct dwarf_section
*section
= &debug_displays
[line
].section
;
5870 unsigned char *hdrptr
, *dirtable
, *file_name
;
5871 unsigned int offset_size
, initial_length_size
;
5872 unsigned int version
, opcode_base
;
5873 dwarf_vma length
, diridx
;
5874 const unsigned char * end
;
5877 if (section
->start
== NULL
5878 || line_offset
>= section
->size
5882 hdrptr
= section
->start
+ line_offset
;
5883 end
= section
->start
+ section
->size
;
5885 SAFE_BYTE_GET_AND_INC (length
, hdrptr
, 4, end
);
5886 if (length
== 0xffffffff)
5888 /* This section is 64-bit DWARF 3. */
5889 SAFE_BYTE_GET_AND_INC (length
, hdrptr
, 8, end
);
5891 initial_length_size
= 12;
5896 initial_length_size
= 4;
5898 if (length
+ initial_length_size
< length
5899 || length
+ initial_length_size
> section
->size
)
5902 SAFE_BYTE_GET_AND_INC (version
, hdrptr
, 2, end
);
5903 if (version
!= 2 && version
!= 3 && version
!= 4)
5905 hdrptr
+= offset_size
+ 1;/* Skip prologue_length and min_insn_length. */
5907 hdrptr
++; /* Skip max_ops_per_insn. */
5908 hdrptr
+= 3; /* Skip default_is_stmt, line_base, line_range. */
5910 SAFE_BYTE_GET_AND_INC (opcode_base
, hdrptr
, 1, end
);
5911 if (opcode_base
== 0)
5914 hdrptr
+= opcode_base
- 1;
5919 /* Skip over dirname table. */
5920 while (*hdrptr
!= '\0')
5922 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
) + 1;
5926 hdrptr
++; /* Skip the NUL at the end of the table. */
5928 /* Now skip over preceding filename table entries. */
5929 for (; hdrptr
< end
&& *hdrptr
!= '\0' && fileidx
> 1; fileidx
--)
5931 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
) + 1;
5932 SKIP_ULEB (hdrptr
, end
);
5933 SKIP_ULEB (hdrptr
, end
);
5934 SKIP_ULEB (hdrptr
, end
);
5936 if (hdrptr
>= end
|| *hdrptr
== '\0')
5940 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
) + 1;
5943 READ_ULEB (diridx
, hdrptr
, end
);
5946 for (; dirtable
< end
&& *dirtable
!= '\0' && diridx
> 1; diridx
--)
5947 dirtable
+= strnlen ((char *) dirtable
, end
- dirtable
) + 1;
5948 if (dirtable
>= end
|| *dirtable
== '\0')
5950 *dir_name
= dirtable
;
5955 display_debug_macro (struct dwarf_section
*section
,
5958 unsigned char *start
= section
->start
;
5959 unsigned char *end
= start
+ section
->size
;
5960 unsigned char *curr
= start
;
5961 unsigned char *extended_op_buf
[256];
5962 bool is_dwo
= false;
5963 const char *suffix
= strrchr (section
->name
, '.');
5965 if (suffix
&& strcmp (suffix
, ".dwo") == 0)
5968 load_debug_section_with_follow (str
, file
);
5969 load_debug_section_with_follow (line
, file
);
5970 load_debug_section_with_follow (str_index
, file
);
5972 introduce (section
, false);
5976 unsigned int lineno
, version
, flags
;
5977 unsigned int offset_size
;
5978 const unsigned char *string
;
5979 dwarf_vma line_offset
= 0, sec_offset
= curr
- start
, offset
;
5980 unsigned char **extended_ops
= NULL
;
5982 SAFE_BYTE_GET_AND_INC (version
, curr
, 2, end
);
5983 if (version
!= 4 && version
!= 5)
5985 error (_("Expected to find a version number of 4 or 5 in section %s but found %d instead\n"),
5986 section
->name
, version
);
5990 SAFE_BYTE_GET_AND_INC (flags
, curr
, 1, end
);
5991 offset_size
= (flags
& 1) ? 8 : 4;
5992 printf (_(" Offset: 0x%lx\n"),
5993 (unsigned long) sec_offset
);
5994 printf (_(" Version: %d\n"), version
);
5995 printf (_(" Offset size: %d\n"), offset_size
);
5998 SAFE_BYTE_GET_AND_INC (line_offset
, curr
, offset_size
, end
);
5999 printf (_(" Offset into .debug_line: 0x%lx\n"),
6000 (unsigned long) line_offset
);
6004 unsigned int i
, count
, op
;
6007 SAFE_BYTE_GET_AND_INC (count
, curr
, 1, end
);
6009 memset (extended_op_buf
, 0, sizeof (extended_op_buf
));
6010 extended_ops
= extended_op_buf
;
6013 printf (_(" Extension opcode arguments:\n"));
6014 for (i
= 0; i
< count
; i
++)
6016 SAFE_BYTE_GET_AND_INC (op
, curr
, 1, end
);
6017 extended_ops
[op
] = curr
;
6018 READ_ULEB (nargs
, curr
, end
);
6020 printf (_(" DW_MACRO_%02x has no arguments\n"), op
);
6023 printf (_(" DW_MACRO_%02x arguments: "), op
);
6024 for (n
= 0; n
< nargs
; n
++)
6028 SAFE_BYTE_GET_AND_INC (form
, curr
, 1, end
);
6029 printf ("%s%s", get_FORM_name (form
),
6030 n
== nargs
- 1 ? "\n" : ", ");
6040 case DW_FORM_block1
:
6041 case DW_FORM_block2
:
6042 case DW_FORM_block4
:
6044 case DW_FORM_string
:
6046 case DW_FORM_sec_offset
:
6049 error (_("Invalid extension opcode form %s\n"),
6050 get_FORM_name (form
));
6066 error (_(".debug_macro section not zero terminated\n"));
6070 SAFE_BYTE_GET_AND_INC (op
, curr
, 1, end
);
6076 case DW_MACRO_define
:
6077 READ_ULEB (lineno
, curr
, end
);
6079 curr
+= strnlen ((char *) string
, end
- string
) + 1;
6080 printf (_(" DW_MACRO_define - lineno : %d macro : %s\n"),
6084 case DW_MACRO_undef
:
6085 READ_ULEB (lineno
, curr
, end
);
6087 curr
+= strnlen ((char *) string
, end
- string
) + 1;
6088 printf (_(" DW_MACRO_undef - lineno : %d macro : %s\n"),
6092 case DW_MACRO_start_file
:
6094 unsigned int filenum
;
6095 unsigned char *file_name
= NULL
, *dir_name
= NULL
;
6097 READ_ULEB (lineno
, curr
, end
);
6098 READ_ULEB (filenum
, curr
, end
);
6100 if ((flags
& 2) == 0)
6101 error (_("DW_MACRO_start_file used, but no .debug_line offset provided.\n"));
6104 = get_line_filename_and_dirname (line_offset
, filenum
,
6106 if (file_name
== NULL
)
6107 printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d\n"),
6110 printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d filename: %s%s%s\n"),
6112 dir_name
!= NULL
? (const char *) dir_name
: "",
6113 dir_name
!= NULL
? "/" : "", file_name
);
6117 case DW_MACRO_end_file
:
6118 printf (_(" DW_MACRO_end_file\n"));
6121 case DW_MACRO_define_strp
:
6122 READ_ULEB (lineno
, curr
, end
);
6123 if (version
== 4 && is_dwo
)
6124 READ_ULEB (offset
, curr
, end
);
6126 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6127 string
= fetch_indirect_string (offset
);
6128 printf (_(" DW_MACRO_define_strp - lineno : %d macro : %s\n"),
6132 case DW_MACRO_undef_strp
:
6133 READ_ULEB (lineno
, curr
, end
);
6134 if (version
== 4 && is_dwo
)
6135 READ_ULEB (offset
, curr
, end
);
6137 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6138 string
= fetch_indirect_string (offset
);
6139 printf (_(" DW_MACRO_undef_strp - lineno : %d macro : %s\n"),
6143 case DW_MACRO_import
:
6144 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6145 printf (_(" DW_MACRO_import - offset : 0x%lx\n"),
6146 (unsigned long) offset
);
6149 case DW_MACRO_define_sup
:
6150 READ_ULEB (lineno
, curr
, end
);
6151 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6152 printf (_(" DW_MACRO_define_sup - lineno : %d macro offset : 0x%lx\n"),
6153 lineno
, (unsigned long) offset
);
6156 case DW_MACRO_undef_sup
:
6157 READ_ULEB (lineno
, curr
, end
);
6158 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6159 printf (_(" DW_MACRO_undef_sup - lineno : %d macro offset : 0x%lx\n"),
6160 lineno
, (unsigned long) offset
);
6163 case DW_MACRO_import_sup
:
6164 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6165 printf (_(" DW_MACRO_import_sup - offset : 0x%lx\n"),
6166 (unsigned long) offset
);
6169 case DW_MACRO_define_strx
:
6170 case DW_MACRO_undef_strx
:
6171 READ_ULEB (lineno
, curr
, end
);
6172 READ_ULEB (offset
, curr
, end
);
6173 string
= (const unsigned char *)
6174 fetch_indexed_string (offset
, NULL
, offset_size
, false);
6175 if (op
== DW_MACRO_define_strx
)
6176 printf (" DW_MACRO_define_strx ");
6178 printf (" DW_MACRO_undef_strx ");
6180 printf (_("(with offset %s) "), dwarf_vmatoa ("x", offset
));
6181 printf (_("lineno : %d macro : %s\n"),
6186 if (op
>= DW_MACRO_lo_user
&& op
<= DW_MACRO_hi_user
)
6188 printf (_(" <Target Specific macro op: %#x - UNHANDLED"), op
);
6192 if (extended_ops
== NULL
|| extended_ops
[op
] == NULL
)
6194 error (_(" Unknown macro opcode %02x seen\n"), op
);
6199 /* Skip over unhandled opcodes. */
6201 unsigned char *desc
= extended_ops
[op
];
6202 READ_ULEB (nargs
, desc
, end
);
6205 printf (_(" DW_MACRO_%02x\n"), op
);
6208 printf (_(" DW_MACRO_%02x -"), op
);
6209 for (n
= 0; n
< nargs
; n
++)
6213 /* DW_FORM_implicit_const is not expected here. */
6214 SAFE_BYTE_GET_AND_INC (val
, desc
, 1, end
);
6216 = read_and_display_attr_value (0, val
, 0,
6217 start
, curr
, end
, 0, 0, offset_size
,
6218 version
, NULL
, 0, NULL
,
6236 display_debug_abbrev (struct dwarf_section
*section
,
6237 void *file ATTRIBUTE_UNUSED
)
6239 abbrev_entry
*entry
;
6240 unsigned char *start
= section
->start
;
6242 introduce (section
, false);
6249 offset
= start
- section
->start
;
6250 list
= find_abbrev_list_by_abbrev_offset (0, offset
);
6253 list
= new_abbrev_list (0, offset
);
6254 start
= process_abbrev_set (section
, 0, section
->size
, offset
, list
);
6255 list
->start_of_next_abbrevs
= start
;
6258 start
= list
->start_of_next_abbrevs
;
6260 if (list
->first_abbrev
== NULL
)
6263 printf (_(" Number TAG (0x%lx)\n"), (long) offset
);
6265 for (entry
= list
->first_abbrev
; entry
; entry
= entry
->next
)
6269 printf (" %ld %s [%s]\n",
6271 get_TAG_name (entry
->tag
),
6272 entry
->children
? _("has children") : _("no children"));
6274 for (attr
= entry
->first_attr
; attr
; attr
= attr
->next
)
6276 printf (" %-18s %s",
6277 get_AT_name (attr
->attribute
),
6278 get_FORM_name (attr
->form
));
6279 if (attr
->form
== DW_FORM_implicit_const
)
6280 printf (": %" BFD_VMA_FMT
"d", attr
->implicit_const
);
6292 /* Return true when ADDR is the maximum address, when addresses are
6293 POINTER_SIZE bytes long. */
6296 is_max_address (dwarf_vma addr
, unsigned int pointer_size
)
6298 dwarf_vma mask
= ~(~(dwarf_vma
) 1 << (pointer_size
* 8 - 1));
6299 return ((addr
& mask
) == mask
);
6302 /* Display a view pair list starting at *VSTART_PTR and ending at
6303 VLISTEND within SECTION. */
6306 display_view_pair_list (struct dwarf_section
*section
,
6307 unsigned char **vstart_ptr
,
6308 unsigned int debug_info_entry
,
6309 unsigned char *vlistend
)
6311 unsigned char *vstart
= *vstart_ptr
;
6312 unsigned char *section_end
= section
->start
+ section
->size
;
6313 unsigned int pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
6315 if (vlistend
< section_end
)
6316 section_end
= vlistend
;
6320 while (vstart
< section_end
)
6322 dwarf_vma off
= vstart
- section
->start
;
6323 dwarf_vma vbegin
, vend
;
6325 READ_ULEB (vbegin
, vstart
, section_end
);
6326 if (vstart
== section_end
)
6329 READ_ULEB (vend
, vstart
, section_end
);
6330 printf (" %8.8lx ", (unsigned long) off
);
6332 print_dwarf_view (vbegin
, pointer_size
, 1);
6333 print_dwarf_view (vend
, pointer_size
, 1);
6334 printf (_("location view pair\n"));
6338 *vstart_ptr
= vstart
;
6341 /* Display a location list from a normal (ie, non-dwo) .debug_loc section. */
6344 display_loc_list (struct dwarf_section
*section
,
6345 unsigned char **start_ptr
,
6346 unsigned int debug_info_entry
,
6348 dwarf_vma base_address
,
6349 unsigned char **vstart_ptr
,
6352 unsigned char *start
= *start_ptr
, *vstart
= *vstart_ptr
;
6353 unsigned char *section_end
= section
->start
+ section
->size
;
6354 unsigned long cu_offset
;
6355 unsigned int pointer_size
;
6356 unsigned int offset_size
;
6361 unsigned short length
;
6362 int need_frame_base
;
6364 if (debug_info_entry
>= num_debug_info_entries
)
6366 warn (_("No debug information available for loc lists of entry: %u\n"),
6371 cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
6372 pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
6373 offset_size
= debug_information
[debug_info_entry
].offset_size
;
6374 dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
6376 if (pointer_size
< 2 || pointer_size
> 8)
6378 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
6379 pointer_size
, debug_info_entry
);
6385 dwarf_vma off
= offset
+ (start
- *start_ptr
);
6386 dwarf_vma vbegin
= vm1
, vend
= vm1
;
6388 if (start
+ 2 * pointer_size
> section_end
)
6390 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6391 (unsigned long) offset
);
6395 printf (" %8.8lx ", (unsigned long) off
);
6397 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, section_end
);
6398 SAFE_BYTE_GET_AND_INC (end
, start
, pointer_size
, section_end
);
6400 if (begin
== 0 && end
== 0)
6402 /* PR 18374: In a object file we can have a location list that
6403 starts with a begin and end of 0 because there are relocations
6404 that need to be applied to the addresses. Actually applying
6405 the relocations now does not help as they will probably resolve
6406 to 0, since the object file has not been fully linked. Real
6407 end of list markers will not have any relocations against them. */
6408 if (! reloc_at (section
, off
)
6409 && ! reloc_at (section
, off
+ pointer_size
))
6411 printf (_("<End of list>\n"));
6416 /* Check base address specifiers. */
6417 if (is_max_address (begin
, pointer_size
)
6418 && !is_max_address (end
, pointer_size
))
6421 print_dwarf_vma (begin
, pointer_size
);
6422 print_dwarf_vma (end
, pointer_size
);
6423 printf (_("(base address)\n"));
6429 off
= offset
+ (vstart
- *start_ptr
);
6431 READ_ULEB (vbegin
, vstart
, section_end
);
6432 print_dwarf_view (vbegin
, pointer_size
, 1);
6434 READ_ULEB (vend
, vstart
, section_end
);
6435 print_dwarf_view (vend
, pointer_size
, 1);
6437 printf (_("views at %8.8lx for:\n %*s "),
6438 (unsigned long) off
, 8, "");
6441 if (start
+ 2 > section_end
)
6443 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6444 (unsigned long) offset
);
6448 SAFE_BYTE_GET_AND_INC (length
, start
, 2, section_end
);
6450 if (start
+ length
> section_end
)
6452 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6453 (unsigned long) offset
);
6457 print_dwarf_vma (begin
+ base_address
, pointer_size
);
6458 print_dwarf_vma (end
+ base_address
, pointer_size
);
6461 need_frame_base
= decode_location_expression (start
,
6466 cu_offset
, section
);
6469 if (need_frame_base
&& !has_frame_base
)
6470 printf (_(" [without DW_AT_frame_base]"));
6472 if (begin
== end
&& vbegin
== vend
)
6473 fputs (_(" (start == end)"), stdout
);
6474 else if (begin
> end
|| (begin
== end
&& vbegin
> vend
))
6475 fputs (_(" (start > end)"), stdout
);
6483 *vstart_ptr
= vstart
;
6486 /* Display a location list from a normal (ie, non-dwo) .debug_loclists section. */
6489 display_loclists_list (struct dwarf_section
*section
,
6490 unsigned char **start_ptr
,
6491 unsigned int debug_info_entry
,
6493 dwarf_vma base_address
,
6494 unsigned char **vstart_ptr
,
6497 unsigned char *start
= *start_ptr
, *vstart
= *vstart_ptr
;
6498 unsigned char *section_end
= section
->start
+ section
->size
;
6499 unsigned long cu_offset
;
6500 unsigned int pointer_size
;
6501 unsigned int offset_size
;
6504 /* Initialize it due to a false compiler warning. */
6505 dwarf_vma begin
= -1, vbegin
= -1;
6506 dwarf_vma end
= -1, vend
= -1;
6508 int need_frame_base
;
6510 if (debug_info_entry
>= num_debug_info_entries
)
6512 warn (_("No debug information available for "
6513 "loclists lists of entry: %u\n"),
6518 cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
6519 pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
6520 offset_size
= debug_information
[debug_info_entry
].offset_size
;
6521 dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
6523 if (pointer_size
< 2 || pointer_size
> 8)
6525 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
6526 pointer_size
, debug_info_entry
);
6532 dwarf_vma off
= offset
+ (start
- *start_ptr
);
6533 enum dwarf_location_list_entry_type llet
;
6535 if (start
+ 1 > section_end
)
6537 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6538 (unsigned long) offset
);
6542 printf (" %8.8lx ", (unsigned long) off
);
6544 SAFE_BYTE_GET_AND_INC (llet
, start
, 1, section_end
);
6546 if (vstart
&& (llet
== DW_LLE_offset_pair
6547 || llet
== DW_LLE_start_end
6548 || llet
== DW_LLE_start_length
))
6550 off
= offset
+ (vstart
- *start_ptr
);
6552 READ_ULEB (vbegin
, vstart
, section_end
);
6553 print_dwarf_view (vbegin
, pointer_size
, 1);
6555 READ_ULEB (vend
, vstart
, section_end
);
6556 print_dwarf_view (vend
, pointer_size
, 1);
6558 printf (_("views at %8.8lx for:\n %*s "),
6559 (unsigned long) off
, 8, "");
6564 case DW_LLE_end_of_list
:
6565 printf (_("<End of list>\n"));
6567 case DW_LLE_offset_pair
:
6568 READ_ULEB (begin
, start
, section_end
);
6569 begin
+= base_address
;
6570 READ_ULEB (end
, start
, section_end
);
6571 end
+= base_address
;
6573 case DW_LLE_start_end
:
6574 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, section_end
);
6575 SAFE_BYTE_GET_AND_INC (end
, start
, pointer_size
, section_end
);
6577 case DW_LLE_start_length
:
6578 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, section_end
);
6579 READ_ULEB (end
, start
, section_end
);
6582 case DW_LLE_base_address
:
6583 SAFE_BYTE_GET_AND_INC (base_address
, start
, pointer_size
,
6585 print_dwarf_vma (base_address
, pointer_size
);
6586 printf (_("(base address)\n"));
6588 #ifdef DW_LLE_view_pair
6589 case DW_LLE_view_pair
:
6591 printf (_("View pair entry in loclist with locviews attribute\n"));
6592 READ_ULEB (vbegin
, start
, section_end
);
6593 print_dwarf_view (vbegin
, pointer_size
, 1);
6595 READ_ULEB (vend
, start
, section_end
);
6596 print_dwarf_view (vend
, pointer_size
, 1);
6598 printf (_("views for:\n"));
6602 error (_("Invalid location list entry type %d\n"), llet
);
6605 if (llet
== DW_LLE_end_of_list
)
6607 if (llet
!= DW_LLE_offset_pair
6608 && llet
!= DW_LLE_start_end
6609 && llet
!= DW_LLE_start_length
)
6612 if (start
+ 2 > section_end
)
6614 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6615 (unsigned long) offset
);
6619 READ_ULEB (length
, start
, section_end
);
6621 print_dwarf_vma (begin
, pointer_size
);
6622 print_dwarf_vma (end
, pointer_size
);
6625 need_frame_base
= decode_location_expression (start
,
6630 cu_offset
, section
);
6633 if (need_frame_base
&& !has_frame_base
)
6634 printf (_(" [without DW_AT_frame_base]"));
6636 if (begin
== end
&& vbegin
== vend
)
6637 fputs (_(" (start == end)"), stdout
);
6638 else if (begin
> end
|| (begin
== end
&& vbegin
> vend
))
6639 fputs (_(" (start > end)"), stdout
);
6647 if (vbegin
!= vm1
|| vend
!= vm1
)
6648 printf (_("Trailing view pair not used in a range"));
6651 *vstart_ptr
= vstart
;
6654 /* Print a .debug_addr table index in decimal, surrounded by square brackets,
6655 right-adjusted in a field of length LEN, and followed by a space. */
6658 print_addr_index (unsigned int idx
, unsigned int len
)
6660 static char buf
[15];
6661 snprintf (buf
, sizeof (buf
), "[%d]", idx
);
6662 printf ("%*s ", len
, buf
);
6665 /* Display a location list from a .dwo section. It uses address indexes rather
6666 than embedded addresses. This code closely follows display_loc_list, but the
6667 two are sufficiently different that combining things is very ugly. */
6670 display_loc_list_dwo (struct dwarf_section
*section
,
6671 unsigned char **start_ptr
,
6672 unsigned int debug_info_entry
,
6674 unsigned char **vstart_ptr
,
6677 unsigned char *start
= *start_ptr
, *vstart
= *vstart_ptr
;
6678 unsigned char *section_end
= section
->start
+ section
->size
;
6679 unsigned long cu_offset
;
6680 unsigned int pointer_size
;
6681 unsigned int offset_size
;
6684 unsigned short length
;
6685 int need_frame_base
;
6688 if (debug_info_entry
>= num_debug_info_entries
)
6690 warn (_("No debug information for loc lists of entry: %u\n"),
6695 cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
6696 pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
6697 offset_size
= debug_information
[debug_info_entry
].offset_size
;
6698 dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
6700 if (pointer_size
< 2 || pointer_size
> 8)
6702 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
6703 pointer_size
, debug_info_entry
);
6709 printf (" %8.8lx ", (unsigned long) (offset
+ (start
- *start_ptr
)));
6711 if (start
>= section_end
)
6713 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6714 (unsigned long) offset
);
6718 SAFE_BYTE_GET_AND_INC (entry_type
, start
, 1, section_end
);
6731 dwarf_vma off
= offset
+ (vstart
- *start_ptr
);
6733 READ_ULEB (view
, vstart
, section_end
);
6734 print_dwarf_view (view
, 8, 1);
6736 READ_ULEB (view
, vstart
, section_end
);
6737 print_dwarf_view (view
, 8, 1);
6739 printf (_("views at %8.8lx for:\n %*s "),
6740 (unsigned long) off
, 8, "");
6748 case 0: /* A terminating entry. */
6750 *vstart_ptr
= vstart
;
6751 printf (_("<End of list>\n"));
6753 case 1: /* A base-address entry. */
6754 READ_ULEB (idx
, start
, section_end
);
6755 print_addr_index (idx
, 8);
6756 printf ("%*s", 9 + (vstart
? 2 * 6 : 0), "");
6757 printf (_("(base address selection entry)\n"));
6759 case 2: /* A start/end entry. */
6760 READ_ULEB (idx
, start
, section_end
);
6761 print_addr_index (idx
, 8);
6762 READ_ULEB (idx
, start
, section_end
);
6763 print_addr_index (idx
, 8);
6765 case 3: /* A start/length entry. */
6766 READ_ULEB (idx
, start
, section_end
);
6767 print_addr_index (idx
, 8);
6768 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
6769 printf ("%08x ", idx
);
6771 case 4: /* An offset pair entry. */
6772 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
6773 printf ("%08x ", idx
);
6774 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
6775 printf ("%08x ", idx
);
6778 warn (_("Unknown location list entry type 0x%x.\n"), entry_type
);
6780 *vstart_ptr
= vstart
;
6784 if (start
+ 2 > section_end
)
6786 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6787 (unsigned long) offset
);
6791 SAFE_BYTE_GET_AND_INC (length
, start
, 2, section_end
);
6792 if (start
+ length
> section_end
)
6794 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6795 (unsigned long) offset
);
6800 need_frame_base
= decode_location_expression (start
,
6805 cu_offset
, section
);
6808 if (need_frame_base
&& !has_frame_base
)
6809 printf (_(" [without DW_AT_frame_base]"));
6817 *vstart_ptr
= vstart
;
6820 /* Sort array of indexes in ascending order of loc_offsets[idx] and
6823 static dwarf_vma
*loc_offsets
, *loc_views
;
6826 loc_offsets_compar (const void *ap
, const void *bp
)
6828 dwarf_vma a
= loc_offsets
[*(const unsigned int *) ap
];
6829 dwarf_vma b
= loc_offsets
[*(const unsigned int *) bp
];
6831 int ret
= (a
> b
) - (b
> a
);
6835 a
= loc_views
[*(const unsigned int *) ap
];
6836 b
= loc_views
[*(const unsigned int *) bp
];
6838 ret
= (a
> b
) - (b
> a
);
6844 display_debug_loc (struct dwarf_section
*section
, void *file
)
6846 unsigned char *start
= section
->start
, *vstart
= NULL
;
6847 unsigned long bytes
;
6848 unsigned char *section_begin
= start
;
6849 unsigned int num_loc_list
= 0;
6850 unsigned long last_offset
= 0;
6851 unsigned long last_view
= 0;
6852 unsigned int first
= 0;
6855 int seen_first_offset
= 0;
6856 int locs_sorted
= 1;
6857 unsigned char *next
= start
, *vnext
= vstart
;
6858 unsigned int *array
= NULL
;
6859 const char *suffix
= strrchr (section
->name
, '.');
6860 bool is_dwo
= false;
6861 int is_loclists
= strstr (section
->name
, "debug_loclists") != NULL
;
6862 dwarf_vma expected_start
= 0;
6864 if (suffix
&& strcmp (suffix
, ".dwo") == 0)
6867 bytes
= section
->size
;
6871 printf (_("\nThe %s section is empty.\n"), section
->name
);
6877 unsigned char *hdrptr
= section_begin
;
6878 dwarf_vma ll_length
;
6879 unsigned short ll_version
;
6880 unsigned char *end
= section_begin
+ section
->size
;
6881 unsigned char address_size
, segment_selector_size
;
6882 uint32_t offset_entry_count
;
6884 SAFE_BYTE_GET_AND_INC (ll_length
, hdrptr
, 4, end
);
6885 if (ll_length
== 0xffffffff)
6886 SAFE_BYTE_GET_AND_INC (ll_length
, hdrptr
, 8, end
);
6888 SAFE_BYTE_GET_AND_INC (ll_version
, hdrptr
, 2, end
);
6889 if (ll_version
!= 5)
6891 warn (_("The %s section contains corrupt or "
6892 "unsupported version number: %d.\n"),
6893 section
->name
, ll_version
);
6897 SAFE_BYTE_GET_AND_INC (address_size
, hdrptr
, 1, end
);
6899 SAFE_BYTE_GET_AND_INC (segment_selector_size
, hdrptr
, 1, end
);
6900 if (segment_selector_size
!= 0)
6902 warn (_("The %s section contains "
6903 "unsupported segment selector size: %d.\n"),
6904 section
->name
, segment_selector_size
);
6908 SAFE_BYTE_GET_AND_INC (offset_entry_count
, hdrptr
, 4, end
);
6909 if (offset_entry_count
!= 0)
6911 warn (_("The %s section contains "
6912 "unsupported offset entry count: %d.\n"),
6913 section
->name
, offset_entry_count
);
6917 expected_start
= hdrptr
- section_begin
;
6920 if (load_debug_info (file
) == 0)
6922 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
6927 /* Check the order of location list in .debug_info section. If
6928 offsets of location lists are in the ascending order, we can
6929 use `debug_information' directly. */
6930 for (i
= 0; i
< num_debug_info_entries
; i
++)
6934 num
= debug_information
[i
].num_loc_offsets
;
6935 if (num
> num_loc_list
)
6938 /* Check if we can use `debug_information' directly. */
6939 if (locs_sorted
&& num
!= 0)
6941 if (!seen_first_offset
)
6943 /* This is the first location list. */
6944 last_offset
= debug_information
[i
].loc_offsets
[0];
6945 last_view
= debug_information
[i
].loc_views
[0];
6947 seen_first_offset
= 1;
6953 for (; j
< num
; j
++)
6956 debug_information
[i
].loc_offsets
[j
]
6957 || (last_offset
== debug_information
[i
].loc_offsets
[j
]
6958 && last_view
> debug_information
[i
].loc_views
[j
]))
6963 last_offset
= debug_information
[i
].loc_offsets
[j
];
6964 last_view
= debug_information
[i
].loc_views
[j
];
6969 if (!seen_first_offset
)
6970 error (_("No location lists in .debug_info section!\n"));
6972 if (debug_information
[first
].num_loc_offsets
> 0
6973 && debug_information
[first
].loc_offsets
[0] != expected_start
6974 && debug_information
[first
].loc_views
[0] != expected_start
)
6975 warn (_("Location lists in %s section start at 0x%s\n"),
6977 dwarf_vmatoa ("x", debug_information
[first
].loc_offsets
[0]));
6980 array
= (unsigned int *) xcmalloc (num_loc_list
, sizeof (unsigned int));
6982 introduce (section
, false);
6984 if (reloc_at (section
, 0))
6985 printf (_(" Warning: This section has relocations - addresses seen here may not be accurate.\n\n"));
6987 printf (_(" Offset Begin End Expression\n"));
6989 seen_first_offset
= 0;
6990 for (i
= first
; i
< num_debug_info_entries
; i
++)
6992 dwarf_vma offset
, voffset
;
6993 dwarf_vma base_address
;
6999 for (k
= 0; k
< debug_information
[i
].num_loc_offsets
; k
++)
7001 loc_offsets
= debug_information
[i
].loc_offsets
;
7002 loc_views
= debug_information
[i
].loc_views
;
7003 qsort (array
, debug_information
[i
].num_loc_offsets
,
7004 sizeof (*array
), loc_offsets_compar
);
7007 int adjacent_view_loclists
= 1;
7008 for (k
= 0; k
< debug_information
[i
].num_loc_offsets
; k
++)
7010 j
= locs_sorted
? k
: array
[k
];
7012 && (debug_information
[i
].loc_offsets
[locs_sorted
7013 ? k
- 1 : array
[k
- 1]]
7014 == debug_information
[i
].loc_offsets
[j
])
7015 && (debug_information
[i
].loc_views
[locs_sorted
7016 ? k
- 1 : array
[k
- 1]]
7017 == debug_information
[i
].loc_views
[j
]))
7019 has_frame_base
= debug_information
[i
].have_frame_base
[j
];
7020 offset
= debug_information
[i
].loc_offsets
[j
];
7021 next
= section_begin
+ offset
;
7022 voffset
= debug_information
[i
].loc_views
[j
];
7024 vnext
= section_begin
+ voffset
;
7027 base_address
= debug_information
[i
].base_address
;
7029 if (vnext
&& vnext
< next
)
7032 display_view_pair_list (section
, &vstart
, i
, next
);
7037 if (!seen_first_offset
|| !adjacent_view_loclists
)
7038 seen_first_offset
= 1;
7042 warn (_("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n"),
7043 (unsigned long) (start
- section_begin
),
7044 (unsigned long) offset
);
7045 else if (start
> next
)
7046 warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n"),
7047 (unsigned long) (start
- section_begin
),
7048 (unsigned long) offset
);
7053 if (offset
>= bytes
)
7055 warn (_("Offset 0x%lx is bigger than .debug_loc section size.\n"),
7056 (unsigned long) offset
);
7060 if (vnext
&& voffset
>= bytes
)
7062 warn (_("View Offset 0x%lx is bigger than .debug_loc section size.\n"),
7063 (unsigned long) voffset
);
7070 display_loc_list_dwo (section
, &start
, i
, offset
,
7071 &vstart
, has_frame_base
);
7073 display_loc_list (section
, &start
, i
, offset
, base_address
,
7074 &vstart
, has_frame_base
);
7079 warn (_("DWO is not yet supported.\n"));
7081 display_loclists_list (section
, &start
, i
, offset
, base_address
,
7082 &vstart
, has_frame_base
);
7085 /* FIXME: this arrangement is quite simplistic. Nothing
7086 requires locview lists to be adjacent to corresponding
7087 loclists, and a single loclist could be augmented by
7088 different locview lists, and vice-versa, unlikely as it
7089 is that it would make sense to do so. Hopefully we'll
7090 have view pair support built into loclists before we ever
7091 need to address all these possibilities. */
7092 if (adjacent_view_loclists
&& vnext
7093 && vnext
!= start
&& vstart
!= next
)
7095 adjacent_view_loclists
= 0;
7096 warn (_("Hole and overlap detection requires adjacent view lists and loclists.\n"));
7099 if (vnext
&& vnext
== start
)
7100 display_view_pair_list (section
, &start
, i
, vstart
);
7104 if (start
< section
->start
+ section
->size
)
7105 warn (ngettext ("There is %ld unused byte at the end of section %s\n",
7106 "There are %ld unused bytes at the end of section %s\n",
7107 (long) (section
->start
+ section
->size
- start
)),
7108 (long) (section
->start
+ section
->size
- start
), section
->name
);
7115 display_debug_str (struct dwarf_section
*section
,
7116 void *file ATTRIBUTE_UNUSED
)
7118 unsigned char *start
= section
->start
;
7119 unsigned long bytes
= section
->size
;
7120 dwarf_vma addr
= section
->address
;
7124 printf (_("\nThe %s section is empty.\n"), section
->name
);
7128 introduce (section
, false);
7136 lbytes
= (bytes
> 16 ? 16 : bytes
);
7138 printf (" 0x%8.8lx ", (unsigned long) addr
);
7140 for (j
= 0; j
< 16; j
++)
7143 printf ("%2.2x", start
[j
]);
7151 for (j
= 0; j
< lbytes
; j
++)
7154 if (k
>= ' ' && k
< 0x80)
7173 display_debug_info (struct dwarf_section
*section
, void *file
)
7175 return process_debug_info (section
, file
, section
->abbrev_sec
, false, false);
7179 display_debug_types (struct dwarf_section
*section
, void *file
)
7181 return process_debug_info (section
, file
, section
->abbrev_sec
, false, true);
7185 display_trace_info (struct dwarf_section
*section
, void *file
)
7187 return process_debug_info (section
, file
, section
->abbrev_sec
, false, true);
7191 display_debug_aranges (struct dwarf_section
*section
,
7192 void *file ATTRIBUTE_UNUSED
)
7194 unsigned char *start
= section
->start
;
7195 unsigned char *end
= start
+ section
->size
;
7197 introduce (section
, false);
7199 /* It does not matter if this load fails,
7200 we test for that later on. */
7201 load_debug_info (file
);
7205 unsigned char *hdrptr
;
7206 DWARF2_Internal_ARange arange
;
7207 unsigned char *addr_ranges
;
7210 unsigned long sec_off
;
7211 unsigned char address_size
;
7213 unsigned int offset_size
;
7214 unsigned int initial_length_size
;
7218 SAFE_BYTE_GET_AND_INC (arange
.ar_length
, hdrptr
, 4, end
);
7219 if (arange
.ar_length
== 0xffffffff)
7221 SAFE_BYTE_GET_AND_INC (arange
.ar_length
, hdrptr
, 8, end
);
7223 initial_length_size
= 12;
7228 initial_length_size
= 4;
7231 sec_off
= hdrptr
- section
->start
;
7232 if (sec_off
+ arange
.ar_length
< sec_off
7233 || sec_off
+ arange
.ar_length
> section
->size
)
7235 warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"),
7237 sec_off
- initial_length_size
,
7238 dwarf_vmatoa ("x", arange
.ar_length
));
7242 SAFE_BYTE_GET_AND_INC (arange
.ar_version
, hdrptr
, 2, end
);
7243 SAFE_BYTE_GET_AND_INC (arange
.ar_info_offset
, hdrptr
, offset_size
, end
);
7245 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
7246 && num_debug_info_entries
> 0
7247 && find_debug_info_for_offset (arange
.ar_info_offset
) == NULL
)
7248 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
7249 (unsigned long) arange
.ar_info_offset
, section
->name
);
7251 SAFE_BYTE_GET_AND_INC (arange
.ar_pointer_size
, hdrptr
, 1, end
);
7252 SAFE_BYTE_GET_AND_INC (arange
.ar_segment_size
, hdrptr
, 1, end
);
7254 if (arange
.ar_version
!= 2 && arange
.ar_version
!= 3)
7256 /* PR 19872: A version number of 0 probably means that there is
7257 padding at the end of the .debug_aranges section. Gold puts
7258 it there when performing an incremental link, for example.
7259 So do not generate a warning in this case. */
7260 if (arange
.ar_version
)
7261 warn (_("Only DWARF 2 and 3 aranges are currently supported.\n"));
7265 printf (_(" Length: %ld\n"),
7266 (long) arange
.ar_length
);
7267 printf (_(" Version: %d\n"), arange
.ar_version
);
7268 printf (_(" Offset into .debug_info: 0x%lx\n"),
7269 (unsigned long) arange
.ar_info_offset
);
7270 printf (_(" Pointer Size: %d\n"), arange
.ar_pointer_size
);
7271 printf (_(" Segment Size: %d\n"), arange
.ar_segment_size
);
7273 address_size
= arange
.ar_pointer_size
+ arange
.ar_segment_size
;
7275 /* PR 17512: file: 001-108546-0.001:0.1. */
7276 if (address_size
== 0 || address_size
> 8)
7278 error (_("Invalid address size in %s section!\n"),
7283 /* The DWARF spec does not require that the address size be a power
7284 of two, but we do. This will have to change if we ever encounter
7285 an uneven architecture. */
7286 if ((address_size
& (address_size
- 1)) != 0)
7288 warn (_("Pointer size + Segment size is not a power of two.\n"));
7292 if (address_size
> 4)
7293 printf (_("\n Address Length\n"));
7295 printf (_("\n Address Length\n"));
7297 addr_ranges
= hdrptr
;
7299 /* Must pad to an alignment boundary that is twice the address size. */
7300 excess
= (hdrptr
- start
) % (2 * address_size
);
7302 addr_ranges
+= (2 * address_size
) - excess
;
7304 start
+= arange
.ar_length
+ initial_length_size
;
7306 while (addr_ranges
+ 2 * address_size
<= start
)
7308 SAFE_BYTE_GET_AND_INC (address
, addr_ranges
, address_size
, end
);
7309 SAFE_BYTE_GET_AND_INC (length
, addr_ranges
, address_size
, end
);
7312 print_dwarf_vma (address
, address_size
);
7313 print_dwarf_vma (length
, address_size
);
7323 /* Comparison function for qsort. */
7325 comp_addr_base (const void * v0
, const void * v1
)
7327 debug_info
*info0
= *(debug_info
**) v0
;
7328 debug_info
*info1
= *(debug_info
**) v1
;
7329 return info0
->addr_base
- info1
->addr_base
;
7332 /* Display the debug_addr section. */
7334 display_debug_addr (struct dwarf_section
*section
,
7337 debug_info
**debug_addr_info
;
7338 unsigned char *entry
;
7342 unsigned char * header
;
7344 if (section
->size
== 0)
7346 printf (_("\nThe %s section is empty.\n"), section
->name
);
7350 if (load_debug_info (file
) == 0)
7352 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
7357 introduce (section
, false);
7359 /* PR 17531: file: cf38d01b.
7360 We use xcalloc because a corrupt file may not have initialised all of the
7361 fields in the debug_info structure, which means that the sort below might
7362 try to move uninitialised data. */
7363 debug_addr_info
= (debug_info
**) xcalloc ((num_debug_info_entries
+ 1),
7364 sizeof (debug_info
*));
7367 for (i
= 0; i
< num_debug_info_entries
; i
++)
7368 if (debug_information
[i
].addr_base
!= DEBUG_INFO_UNAVAILABLE
)
7370 /* PR 17531: file: cf38d01b. */
7371 if (debug_information
[i
].addr_base
>= section
->size
)
7372 warn (_("Corrupt address base (%lx) found in debug section %u\n"),
7373 (unsigned long) debug_information
[i
].addr_base
, i
);
7375 debug_addr_info
[count
++] = debug_information
+ i
;
7378 /* Add a sentinel to make iteration convenient. */
7379 debug_addr_info
[count
] = (debug_info
*) xmalloc (sizeof (debug_info
));
7380 debug_addr_info
[count
]->addr_base
= section
->size
;
7381 qsort (debug_addr_info
, count
, sizeof (debug_info
*), comp_addr_base
);
7383 header
= section
->start
;
7384 for (i
= 0; i
< count
; i
++)
7387 unsigned int address_size
= debug_addr_info
[i
]->pointer_size
;
7389 printf (_(" For compilation unit at offset 0x%s:\n"),
7390 dwarf_vmatoa ("x", debug_addr_info
[i
]->cu_offset
));
7392 printf (_("\tIndex\tAddress\n"));
7393 entry
= section
->start
+ debug_addr_info
[i
]->addr_base
;
7394 if (debug_addr_info
[i
]->dwarf_version
>= 5)
7396 size_t header_size
= entry
- header
;
7397 unsigned char * curr_header
= header
;
7400 int segment_selector_size
;
7402 if (header_size
!= 8 && header_size
!= 16)
7404 warn (_("Corrupt %s section: expecting header size of 8 or 16, but found %ld instead\n"),
7405 section
->name
, (long) header_size
);
7409 SAFE_BYTE_GET_AND_INC (length
, curr_header
, 4, entry
);
7410 if (length
== 0xffffffff)
7411 SAFE_BYTE_GET (length
, curr_header
, 8, entry
);
7412 end
= curr_header
+ length
;
7414 SAFE_BYTE_GET_AND_INC (version
, curr_header
, 2, entry
);
7416 warn (_("Corrupt %s section: expecting version number 5 in header but found %d instead\n"),
7417 section
->name
, version
);
7419 SAFE_BYTE_GET_AND_INC (address_size
, curr_header
, 1, entry
);
7420 SAFE_BYTE_GET_AND_INC (segment_selector_size
, curr_header
, 1, entry
);
7421 address_size
+= segment_selector_size
;
7424 end
= section
->start
+ debug_addr_info
[i
+ 1]->addr_base
;
7429 dwarf_vma base
= byte_get (entry
, address_size
);
7430 printf (_("\t%d:\t"), idx
);
7431 print_dwarf_vma (base
, address_size
);
7433 entry
+= address_size
;
7439 free (debug_addr_info
);
7443 /* Display the .debug_str_offsets and .debug_str_offsets.dwo sections. */
7446 display_debug_str_offsets (struct dwarf_section
*section
,
7447 void *file ATTRIBUTE_UNUSED
)
7451 if (section
->size
== 0)
7453 printf (_("\nThe %s section is empty.\n"), section
->name
);
7457 unsigned char *start
= section
->start
;
7458 unsigned char *end
= start
+ section
->size
;
7459 unsigned char *curr
= start
;
7461 const char *suffix
= strrchr (section
->name
, '.');
7462 bool dwo
= suffix
&& strcmp (suffix
, ".dwo") == 0;
7465 load_debug_section_with_follow (str_dwo
, file
);
7467 load_debug_section_with_follow (str
, file
);
7469 introduce (section
, false);
7474 dwarf_vma entry_length
;
7476 SAFE_BYTE_GET_AND_INC (length
, curr
, 4, end
);
7477 /* FIXME: We assume that this means 64-bit DWARF is being used. */
7478 if (length
== 0xffffffff)
7480 SAFE_BYTE_GET (length
, curr
, 8, end
);
7486 unsigned char *entries_end
;
7489 /* This is probably an old style .debug_str_offset section which
7490 just contains offsets and no header (and the first offset is 0). */
7491 length
= section
->size
;
7492 curr
= section
->start
;
7495 printf (_(" Length: %#lx\n"), (unsigned long) length
);
7496 printf (_(" Index Offset [String]\n"));
7500 entries_end
= curr
+ length
;
7503 SAFE_BYTE_GET_AND_INC (version
, curr
, 2, end
);
7505 warn (_("Unexpected version number in str_offset header: %#x\n"), version
);
7508 SAFE_BYTE_GET_AND_INC (padding
, curr
, 2, end
);
7510 warn (_("Unexpected value in str_offset header's padding field: %#x\n"), padding
);
7512 printf (_(" Length: %#lx\n"), (unsigned long) length
);
7513 printf (_(" Version: %#lx\n"), (unsigned long) version
);
7514 printf (_(" Index Offset [String]\n"));
7517 for (idx
= 0; curr
< entries_end
; idx
++)
7520 const unsigned char * string
;
7522 if (curr
+ entry_length
> entries_end
)
7523 /* Not enough space to read one entry_length, give up. */
7526 SAFE_BYTE_GET_AND_INC (offset
, curr
, entry_length
, end
);
7528 string
= (const unsigned char *)
7529 fetch_indexed_string (idx
, NULL
, entry_length
, dwo
);
7531 string
= fetch_indirect_string (offset
);
7533 printf (" %8lu %8s %s\n", idx
, dwarf_vmatoa ("x", offset
),
7541 /* Each debug_information[x].range_lists[y] gets this representation for
7542 sorting purposes. */
7546 /* The debug_information[x].range_lists[y] value. */
7547 dwarf_vma ranges_offset
;
7549 /* Original debug_information to find parameters of the data. */
7550 debug_info
*debug_info_p
;
7553 /* Sort struct range_entry in ascending order of its RANGES_OFFSET. */
7556 range_entry_compar (const void *ap
, const void *bp
)
7558 const struct range_entry
*a_re
= (const struct range_entry
*) ap
;
7559 const struct range_entry
*b_re
= (const struct range_entry
*) bp
;
7560 const dwarf_vma a
= a_re
->ranges_offset
;
7561 const dwarf_vma b
= b_re
->ranges_offset
;
7563 return (a
> b
) - (b
> a
);
7567 display_debug_ranges_list (unsigned char *start
, unsigned char *finish
,
7568 unsigned int pointer_size
, unsigned long offset
,
7569 unsigned long base_address
)
7571 while (start
< finish
)
7576 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
7577 if (start
>= finish
)
7579 SAFE_SIGNED_BYTE_GET_AND_INC (end
, start
, pointer_size
, finish
);
7581 printf (" %8.8lx ", offset
);
7583 if (begin
== 0 && end
== 0)
7585 printf (_("<End of list>\n"));
7589 /* Check base address specifiers. */
7590 if (is_max_address (begin
, pointer_size
)
7591 && !is_max_address (end
, pointer_size
))
7594 print_dwarf_vma (begin
, pointer_size
);
7595 print_dwarf_vma (end
, pointer_size
);
7596 printf ("(base address)\n");
7600 print_dwarf_vma (begin
+ base_address
, pointer_size
);
7601 print_dwarf_vma (end
+ base_address
, pointer_size
);
7604 fputs (_("(start == end)"), stdout
);
7605 else if (begin
> end
)
7606 fputs (_("(start > end)"), stdout
);
7613 display_debug_rnglists_list (unsigned char *start
, unsigned char *finish
,
7614 unsigned int pointer_size
, unsigned long offset
,
7615 unsigned long base_address
)
7617 unsigned char *next
= start
;
7621 unsigned long off
= offset
+ (start
- next
);
7622 enum dwarf_range_list_entry rlet
;
7623 /* Initialize it due to a false compiler warning. */
7624 dwarf_vma begin
= -1, length
, end
= -1;
7626 if (start
+ 1 > finish
)
7628 warn (_("Range list starting at offset 0x%lx is not terminated.\n"),
7633 printf (" %8.8lx ", off
);
7635 SAFE_BYTE_GET_AND_INC (rlet
, start
, 1, finish
);
7639 case DW_RLE_end_of_list
:
7640 printf (_("<End of list>\n"));
7642 case DW_RLE_base_address
:
7643 SAFE_BYTE_GET_AND_INC (base_address
, start
, pointer_size
, finish
);
7644 print_dwarf_vma (base_address
, pointer_size
);
7645 printf (_("(base address)\n"));
7647 case DW_RLE_start_length
:
7648 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
7649 READ_ULEB (length
, start
, finish
);
7650 end
= begin
+ length
;
7652 case DW_RLE_offset_pair
:
7653 READ_ULEB (begin
, start
, finish
);
7654 READ_ULEB (end
, start
, finish
);
7656 case DW_RLE_start_end
:
7657 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
7658 SAFE_BYTE_GET_AND_INC (end
, start
, pointer_size
, finish
);
7661 error (_("Invalid range list entry type %d\n"), rlet
);
7662 rlet
= DW_RLE_end_of_list
;
7665 if (rlet
== DW_RLE_end_of_list
)
7667 if (rlet
== DW_RLE_base_address
)
7670 /* Only a DW_RLE_offset_pair needs the base address added. */
7671 if (rlet
== DW_RLE_offset_pair
)
7673 begin
+= base_address
;
7674 end
+= base_address
;
7677 print_dwarf_vma (begin
, pointer_size
);
7678 print_dwarf_vma (end
, pointer_size
);
7681 fputs (_("(start == end)"), stdout
);
7682 else if (begin
> end
)
7683 fputs (_("(start > end)"), stdout
);
7690 display_debug_ranges (struct dwarf_section
*section
,
7691 void *file ATTRIBUTE_UNUSED
)
7693 unsigned char *start
= section
->start
;
7694 unsigned char *last_start
= start
;
7695 unsigned long bytes
= section
->size
;
7696 unsigned char *section_begin
= start
;
7697 unsigned char *finish
= start
+ bytes
;
7698 unsigned int num_range_list
, i
;
7699 struct range_entry
*range_entries
, *range_entry_fill
;
7700 int is_rnglists
= strstr (section
->name
, "debug_rnglists") != NULL
;
7701 /* Initialize it due to a false compiler warning. */
7702 unsigned char address_size
= 0;
7703 dwarf_vma last_offset
= 0;
7707 printf (_("\nThe %s section is empty.\n"), section
->name
);
7713 dwarf_vma initial_length
;
7714 unsigned int initial_length_size
;
7715 unsigned char segment_selector_size
;
7716 unsigned int offset_size
, offset_entry_count
;
7717 unsigned short version
;
7719 /* Get and check the length of the block. */
7720 SAFE_BYTE_GET_AND_INC (initial_length
, start
, 4, finish
);
7722 if (initial_length
== 0xffffffff)
7724 /* This section is 64-bit DWARF 3. */
7725 SAFE_BYTE_GET_AND_INC (initial_length
, start
, 8, finish
);
7727 initial_length_size
= 12;
7732 initial_length_size
= 4;
7735 if (initial_length
+ initial_length_size
> section
->size
)
7737 /* If the length field has a relocation against it, then we should
7738 not complain if it is inaccurate (and probably negative).
7739 It is copied from .debug_line handling code. */
7740 if (reloc_at (section
, (start
- section
->start
) - offset_size
))
7742 initial_length
= (finish
- start
) - initial_length_size
;
7746 warn (_("The length field (0x%lx) in the debug_rnglists header is wrong - the section is too small\n"),
7747 (long) initial_length
);
7752 /* Get and check the version number. */
7753 SAFE_BYTE_GET_AND_INC (version
, start
, 2, finish
);
7757 warn (_("Only DWARF version 5 debug_rnglists info "
7758 "is currently supported.\n"));
7762 SAFE_BYTE_GET_AND_INC (address_size
, start
, 1, finish
);
7764 SAFE_BYTE_GET_AND_INC (segment_selector_size
, start
, 1, finish
);
7765 if (segment_selector_size
!= 0)
7767 warn (_("The %s section contains "
7768 "unsupported segment selector size: %d.\n"),
7769 section
->name
, segment_selector_size
);
7773 SAFE_BYTE_GET_AND_INC (offset_entry_count
, start
, 4, finish
);
7774 if (offset_entry_count
!= 0)
7776 warn (_("The %s section contains "
7777 "unsupported offset entry count: %u.\n"),
7778 section
->name
, offset_entry_count
);
7783 if (load_debug_info (file
) == 0)
7785 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
7791 for (i
= 0; i
< num_debug_info_entries
; i
++)
7793 if (debug_information
[i
].dwarf_version
< 5 && is_rnglists
)
7794 /* Skip .debug_rnglists reference. */
7796 if (debug_information
[i
].dwarf_version
>= 5 && !is_rnglists
)
7797 /* Skip .debug_range reference. */
7799 num_range_list
+= debug_information
[i
].num_range_lists
;
7802 if (num_range_list
== 0)
7804 /* This can happen when the file was compiled with -gsplit-debug
7805 which removes references to range lists from the primary .o file. */
7806 printf (_("No range lists in .debug_info section.\n"));
7810 range_entries
= (struct range_entry
*)
7811 xmalloc (sizeof (*range_entries
) * num_range_list
);
7812 range_entry_fill
= range_entries
;
7814 for (i
= 0; i
< num_debug_info_entries
; i
++)
7816 debug_info
*debug_info_p
= &debug_information
[i
];
7819 if (debug_information
[i
].dwarf_version
< 5 && is_rnglists
)
7820 /* Skip .debug_rnglists reference. */
7822 if (debug_information
[i
].dwarf_version
>= 5 && !is_rnglists
)
7823 /* Skip .debug_range reference. */
7826 for (j
= 0; j
< debug_info_p
->num_range_lists
; j
++)
7828 range_entry_fill
->ranges_offset
= debug_info_p
->range_lists
[j
];
7829 range_entry_fill
->debug_info_p
= debug_info_p
;
7834 qsort (range_entries
, num_range_list
, sizeof (*range_entries
),
7835 range_entry_compar
);
7837 if (dwarf_check
!= 0 && range_entries
[0].ranges_offset
!= 0)
7838 warn (_("Range lists in %s section start at 0x%lx\n"),
7839 section
->name
, (unsigned long) range_entries
[0].ranges_offset
);
7841 introduce (section
, false);
7843 printf (_(" Offset Begin End\n"));
7845 for (i
= 0; i
< num_range_list
; i
++)
7847 struct range_entry
*range_entry
= &range_entries
[i
];
7848 debug_info
*debug_info_p
= range_entry
->debug_info_p
;
7849 unsigned int pointer_size
;
7851 unsigned char *next
;
7852 dwarf_vma base_address
;
7854 pointer_size
= (is_rnglists
? address_size
: debug_info_p
->pointer_size
);
7855 offset
= range_entry
->ranges_offset
;
7856 next
= section_begin
+ offset
;
7857 base_address
= debug_info_p
->base_address
;
7859 /* PR 17512: file: 001-101485-0.001:0.1. */
7860 if (pointer_size
< 2 || pointer_size
> 8)
7862 warn (_("Corrupt pointer size (%d) in debug entry at offset %8.8lx\n"),
7863 pointer_size
, (unsigned long) offset
);
7867 if (next
< section_begin
|| next
>= finish
)
7869 warn (_("Corrupt offset (%#8.8lx) in range entry %u\n"),
7870 (unsigned long) offset
, i
);
7874 /* If multiple DWARF entities reference the same range then we will
7875 have multiple entries in the `range_entries' list for the same
7876 offset. Thanks to the sort above these will all be consecutive in
7877 the `range_entries' list, so we can easily ignore duplicates
7879 if (i
> 0 && last_offset
== offset
)
7881 last_offset
= offset
;
7883 if (dwarf_check
!= 0 && i
> 0)
7886 warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"),
7887 (unsigned long) (start
- section_begin
),
7888 (unsigned long) (next
- section_begin
), section
->name
);
7889 else if (start
> next
)
7891 if (next
== last_start
)
7893 warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"),
7894 (unsigned long) (start
- section_begin
),
7895 (unsigned long) (next
- section_begin
), section
->name
);
7902 (is_rnglists
? display_debug_rnglists_list
: display_debug_ranges_list
)
7903 (start
, finish
, pointer_size
, offset
, base_address
);
7907 free (range_entries
);
7912 typedef struct Frame_Chunk
7914 struct Frame_Chunk
*next
;
7915 unsigned char *chunk_start
;
7917 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
7918 short int *col_type
;
7921 unsigned int code_factor
;
7925 unsigned int cfa_reg
;
7926 dwarf_vma cfa_offset
;
7928 unsigned char fde_encoding
;
7929 unsigned char cfa_exp
;
7930 unsigned char ptr_size
;
7931 unsigned char segment_size
;
7935 typedef const char *(*dwarf_regname_lookup_ftype
) (unsigned int);
7936 static dwarf_regname_lookup_ftype dwarf_regnames_lookup_func
;
7937 static const char *const *dwarf_regnames
;
7938 static unsigned int dwarf_regnames_count
;
7941 /* A marker for a col_type that means this column was never referenced
7942 in the frame info. */
7943 #define DW_CFA_unreferenced (-1)
7945 /* Return 0 if no more space is needed, 1 if more space is needed,
7946 -1 for invalid reg. */
7949 frame_need_space (Frame_Chunk
*fc
, unsigned int reg
)
7951 unsigned int prev
= fc
->ncols
;
7953 if (reg
< (unsigned int) fc
->ncols
)
7956 if (dwarf_regnames_count
> 0
7957 && reg
> dwarf_regnames_count
)
7960 fc
->ncols
= reg
+ 1;
7961 /* PR 17512: file: 10450-2643-0.004.
7962 If reg == -1 then this can happen... */
7966 /* PR 17512: file: 2844a11d. */
7967 if (fc
->ncols
> 1024 && dwarf_regnames_count
== 0)
7969 error (_("Unfeasibly large register number: %u\n"), reg
);
7971 /* FIXME: 1024 is an arbitrary limit. Increase it if
7972 we ever encounter a valid binary that exceeds it. */
7976 fc
->col_type
= (short int *) xcrealloc (fc
->col_type
, fc
->ncols
,
7977 sizeof (short int));
7978 fc
->col_offset
= (int *) xcrealloc (fc
->col_offset
, fc
->ncols
, sizeof (int));
7979 /* PR 17512: file:002-10025-0.005. */
7980 if (fc
->col_type
== NULL
|| fc
->col_offset
== NULL
)
7982 error (_("Out of memory allocating %u columns in dwarf frame arrays\n"),
7988 while (prev
< fc
->ncols
)
7990 fc
->col_type
[prev
] = DW_CFA_unreferenced
;
7991 fc
->col_offset
[prev
] = 0;
7997 static const char *const dwarf_regnames_i386
[] =
7999 "eax", "ecx", "edx", "ebx", /* 0 - 3 */
8000 "esp", "ebp", "esi", "edi", /* 4 - 7 */
8001 "eip", "eflags", NULL
, /* 8 - 10 */
8002 "st0", "st1", "st2", "st3", /* 11 - 14 */
8003 "st4", "st5", "st6", "st7", /* 15 - 18 */
8004 NULL
, NULL
, /* 19 - 20 */
8005 "xmm0", "xmm1", "xmm2", "xmm3", /* 21 - 24 */
8006 "xmm4", "xmm5", "xmm6", "xmm7", /* 25 - 28 */
8007 "mm0", "mm1", "mm2", "mm3", /* 29 - 32 */
8008 "mm4", "mm5", "mm6", "mm7", /* 33 - 36 */
8009 "fcw", "fsw", "mxcsr", /* 37 - 39 */
8010 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
, /* 40 - 47 */
8011 "tr", "ldtr", /* 48 - 49 */
8012 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 50 - 57 */
8013 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 58 - 65 */
8014 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 66 - 73 */
8015 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 74 - 81 */
8016 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 82 - 89 */
8017 NULL
, NULL
, NULL
, /* 90 - 92 */
8018 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7" /* 93 - 100 */
8021 static const char *const dwarf_regnames_iamcu
[] =
8023 "eax", "ecx", "edx", "ebx", /* 0 - 3 */
8024 "esp", "ebp", "esi", "edi", /* 4 - 7 */
8025 "eip", "eflags", NULL
, /* 8 - 10 */
8026 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 11 - 18 */
8027 NULL
, NULL
, /* 19 - 20 */
8028 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 21 - 28 */
8029 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 29 - 36 */
8030 NULL
, NULL
, NULL
, /* 37 - 39 */
8031 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
, /* 40 - 47 */
8032 "tr", "ldtr", /* 48 - 49 */
8033 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 50 - 57 */
8034 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 58 - 65 */
8035 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 66 - 73 */
8036 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 74 - 81 */
8037 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 82 - 89 */
8038 NULL
, NULL
, NULL
, /* 90 - 92 */
8039 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
/* 93 - 100 */
8043 init_dwarf_regnames_i386 (void)
8045 dwarf_regnames
= dwarf_regnames_i386
;
8046 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_i386
);
8047 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8051 init_dwarf_regnames_iamcu (void)
8053 dwarf_regnames
= dwarf_regnames_iamcu
;
8054 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_iamcu
);
8055 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8058 static const char *const dwarf_regnames_x86_64
[] =
8060 "rax", "rdx", "rcx", "rbx",
8061 "rsi", "rdi", "rbp", "rsp",
8062 "r8", "r9", "r10", "r11",
8063 "r12", "r13", "r14", "r15",
8065 "xmm0", "xmm1", "xmm2", "xmm3",
8066 "xmm4", "xmm5", "xmm6", "xmm7",
8067 "xmm8", "xmm9", "xmm10", "xmm11",
8068 "xmm12", "xmm13", "xmm14", "xmm15",
8069 "st0", "st1", "st2", "st3",
8070 "st4", "st5", "st6", "st7",
8071 "mm0", "mm1", "mm2", "mm3",
8072 "mm4", "mm5", "mm6", "mm7",
8074 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
,
8075 "fs.base", "gs.base", NULL
, NULL
,
8077 "mxcsr", "fcw", "fsw",
8078 "xmm16", "xmm17", "xmm18", "xmm19",
8079 "xmm20", "xmm21", "xmm22", "xmm23",
8080 "xmm24", "xmm25", "xmm26", "xmm27",
8081 "xmm28", "xmm29", "xmm30", "xmm31",
8082 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 83 - 90 */
8083 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 91 - 98 */
8084 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 99 - 106 */
8085 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 107 - 114 */
8086 NULL
, NULL
, NULL
, /* 115 - 117 */
8087 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7"
8091 init_dwarf_regnames_x86_64 (void)
8093 dwarf_regnames
= dwarf_regnames_x86_64
;
8094 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_x86_64
);
8095 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8098 static const char *const dwarf_regnames_aarch64
[] =
8100 "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7",
8101 "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15",
8102 "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23",
8103 "x24", "x25", "x26", "x27", "x28", "x29", "x30", "sp",
8104 NULL
, "elr", NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
8105 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, "vg", "ffr",
8106 "p0", "p1", "p2", "p3", "p4", "p5", "p6", "p7",
8107 "p8", "p9", "p10", "p11", "p12", "p13", "p14", "p15",
8108 "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7",
8109 "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15",
8110 "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23",
8111 "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31",
8112 "z0", "z1", "z2", "z3", "z4", "z5", "z6", "z7",
8113 "z8", "z9", "z10", "z11", "z12", "z13", "z14", "z15",
8114 "z16", "z17", "z18", "z19", "z20", "z21", "z22", "z23",
8115 "z24", "z25", "z26", "z27", "z28", "z29", "z30", "z31",
8119 init_dwarf_regnames_aarch64 (void)
8121 dwarf_regnames
= dwarf_regnames_aarch64
;
8122 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_aarch64
);
8123 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8126 static const char *const dwarf_regnames_s390
[] =
8128 /* Avoid saying "r5 (r5)", so omit the names of r0-r15. */
8129 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
8130 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
8131 "f0", "f2", "f4", "f6", "f1", "f3", "f5", "f7",
8132 "f8", "f10", "f12", "f14", "f9", "f11", "f13", "f15",
8133 "cr0", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7",
8134 "cr8", "cr9", "cr10", "cr11", "cr12", "cr13", "cr14", "cr15",
8135 "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7",
8136 "a8", "a9", "a10", "a11", "a12", "a13", "a14", "a15",
8139 "v16", "v18", "v20", "v22", "v17", "v19", "v21", "v23",
8140 "v24", "v26", "v28", "v30", "v25", "v27", "v29", "v31",
8144 init_dwarf_regnames_s390 (void)
8146 dwarf_regnames
= dwarf_regnames_s390
;
8147 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_s390
);
8148 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8151 static const char *const dwarf_regnames_riscv
[] =
8153 "zero", "ra", "sp", "gp", "tp", "t0", "t1", "t2", /* 0 - 7 */
8154 "s0", "s1", "a0", "a1", "a2", "a3", "a4", "a5", /* 8 - 15 */
8155 "a6", "a7", "s2", "s3", "s4", "s5", "s6", "s7", /* 16 - 23 */
8156 "s8", "s9", "s10", "s11", "t3", "t4", "t5", "t6", /* 24 - 31 */
8157 "ft0", "ft1", "ft2", "ft3", "ft4", "ft5", "ft6", "ft7", /* 32 - 39 */
8158 "fs0", "fs1", /* 40 - 41 */
8159 "fa0", "fa1", "fa2", "fa3", "fa4", "fa5", "fa6", "fa7", /* 42 - 49 */
8160 "fs2", "fs3", "fs4", "fs5", "fs6", "fs7", "fs8", "fs9", /* 50 - 57 */
8161 "fs10", "fs11", /* 58 - 59 */
8162 "ft8", "ft9", "ft10", "ft11" /* 60 - 63 */
8165 /* A RISC-V replacement for REGNAME_INTERNAL_BY_TABLE_ONLY which handles
8166 the large number of CSRs. */
8169 regname_internal_riscv (unsigned int regno
)
8171 const char *name
= NULL
;
8173 /* Lookup in the table first, this covers GPR and FPR. */
8174 if (regno
< ARRAY_SIZE (dwarf_regnames_riscv
))
8175 name
= dwarf_regnames_riscv
[regno
];
8176 else if (regno
>= 4096 && regno
<= 8191)
8178 /* This might be a CSR, these live in a sparse number space from 4096
8179 to 8191 These numbers are defined in the RISC-V ELF ABI
8183 #define DECLARE_CSR(NAME,VALUE,CLASS,DEFINE_VER,ABORT_VER) \
8184 case VALUE + 4096: name = #NAME; break;
8185 #include "opcode/riscv-opc.h"
8190 static char csr_name
[10];
8191 snprintf (csr_name
, sizeof (csr_name
), "csr%d", (regno
- 4096));
8202 init_dwarf_regnames_riscv (void)
8204 dwarf_regnames
= NULL
;
8205 dwarf_regnames_count
= 8192;
8206 dwarf_regnames_lookup_func
= regname_internal_riscv
;
8210 init_dwarf_regnames_by_elf_machine_code (unsigned int e_machine
)
8212 dwarf_regnames_lookup_func
= NULL
;
8217 init_dwarf_regnames_i386 ();
8221 init_dwarf_regnames_iamcu ();
8227 init_dwarf_regnames_x86_64 ();
8231 init_dwarf_regnames_aarch64 ();
8235 init_dwarf_regnames_s390 ();
8239 init_dwarf_regnames_riscv ();
8247 /* Initialize the DWARF register name lookup state based on the
8248 architecture and specific machine type of a BFD. */
8251 init_dwarf_regnames_by_bfd_arch_and_mach (enum bfd_architecture arch
,
8254 dwarf_regnames_lookup_func
= NULL
;
8261 case bfd_mach_x86_64
:
8262 case bfd_mach_x86_64_intel_syntax
:
8263 case bfd_mach_x64_32
:
8264 case bfd_mach_x64_32_intel_syntax
:
8265 init_dwarf_regnames_x86_64 ();
8269 init_dwarf_regnames_i386 ();
8274 case bfd_arch_iamcu
:
8275 init_dwarf_regnames_iamcu ();
8278 case bfd_arch_aarch64
:
8279 init_dwarf_regnames_aarch64();
8283 init_dwarf_regnames_s390 ();
8286 case bfd_arch_riscv
:
8287 init_dwarf_regnames_riscv ();
8296 regname_internal_by_table_only (unsigned int regno
)
8298 if (dwarf_regnames
!= NULL
8299 && regno
< dwarf_regnames_count
8300 && dwarf_regnames
[regno
] != NULL
)
8301 return dwarf_regnames
[regno
];
8307 regname (unsigned int regno
, int name_only_p
)
8309 static char reg
[64];
8311 const char *name
= NULL
;
8313 if (dwarf_regnames_lookup_func
!= NULL
)
8314 name
= dwarf_regnames_lookup_func (regno
);
8320 snprintf (reg
, sizeof (reg
), "r%d (%s)", regno
, name
);
8323 snprintf (reg
, sizeof (reg
), "r%d", regno
);
8328 frame_display_row (Frame_Chunk
*fc
, int *need_col_headers
, unsigned int *max_regs
)
8333 if (*max_regs
!= fc
->ncols
)
8334 *max_regs
= fc
->ncols
;
8336 if (*need_col_headers
)
8338 *need_col_headers
= 0;
8340 printf ("%-*s CFA ", eh_addr_size
* 2, " LOC");
8342 for (r
= 0; r
< *max_regs
; r
++)
8343 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
8348 printf ("%-5s ", regname (r
, 1));
8354 print_dwarf_vma (fc
->pc_begin
, eh_addr_size
);
8356 strcpy (tmp
, "exp");
8358 sprintf (tmp
, "%s%+d", regname (fc
->cfa_reg
, 1), (int) fc
->cfa_offset
);
8359 printf ("%-8s ", tmp
);
8361 for (r
= 0; r
< fc
->ncols
; r
++)
8363 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
8365 switch (fc
->col_type
[r
])
8367 case DW_CFA_undefined
:
8370 case DW_CFA_same_value
:
8374 sprintf (tmp
, "c%+d", fc
->col_offset
[r
]);
8376 case DW_CFA_val_offset
:
8377 sprintf (tmp
, "v%+d", fc
->col_offset
[r
]);
8379 case DW_CFA_register
:
8380 sprintf (tmp
, "%s", regname (fc
->col_offset
[r
], 0));
8382 case DW_CFA_expression
:
8383 strcpy (tmp
, "exp");
8385 case DW_CFA_val_expression
:
8386 strcpy (tmp
, "vexp");
8389 strcpy (tmp
, "n/a");
8392 printf ("%-5s ", tmp
);
8398 #define GET(VAR, N) SAFE_BYTE_GET_AND_INC (VAR, start, N, end)
8400 static unsigned char *
8401 read_cie (unsigned char *start
, unsigned char *end
,
8402 Frame_Chunk
**p_cie
, int *p_version
,
8403 bfd_size_type
*p_aug_len
, unsigned char **p_aug
)
8407 unsigned char *augmentation_data
= NULL
;
8408 bfd_size_type augmentation_data_len
= 0;
8411 /* PR 17512: file: 001-228113-0.004. */
8415 fc
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
8416 memset (fc
, 0, sizeof (Frame_Chunk
));
8418 fc
->col_type
= (short int *) xmalloc (sizeof (short int));
8419 fc
->col_offset
= (int *) xmalloc (sizeof (int));
8423 fc
->augmentation
= (char *) start
;
8424 /* PR 17512: file: 001-228113-0.004.
8425 Skip past augmentation name, but avoid running off the end of the data. */
8427 if (* start
++ == '\0')
8431 warn (_("No terminator for augmentation name\n"));
8435 if (strcmp (fc
->augmentation
, "eh") == 0)
8436 start
+= eh_addr_size
;
8440 GET (fc
->ptr_size
, 1);
8441 if (fc
->ptr_size
< 1 || fc
->ptr_size
> 8)
8443 warn (_("Invalid pointer size (%d) in CIE data\n"), fc
->ptr_size
);
8447 GET (fc
->segment_size
, 1);
8448 /* PR 17512: file: e99d2804. */
8449 if (fc
->segment_size
> 8 || fc
->segment_size
+ fc
->ptr_size
> 8)
8451 warn (_("Invalid segment size (%d) in CIE data\n"), fc
->segment_size
);
8455 eh_addr_size
= fc
->ptr_size
;
8459 fc
->ptr_size
= eh_addr_size
;
8460 fc
->segment_size
= 0;
8463 READ_ULEB (fc
->code_factor
, start
, end
);
8464 READ_SLEB (fc
->data_factor
, start
, end
);
8472 READ_ULEB (fc
->ra
, start
, end
);
8475 if (fc
->augmentation
[0] == 'z')
8477 READ_ULEB (augmentation_data_len
, start
, end
);
8478 augmentation_data
= start
;
8479 /* PR 17512: file: 11042-2589-0.004. */
8480 if (augmentation_data_len
> (bfd_size_type
) (end
- start
))
8482 warn (_("Augmentation data too long: 0x%s, expected at most %#lx\n"),
8483 dwarf_vmatoa ("x", augmentation_data_len
),
8484 (unsigned long) (end
- start
));
8487 start
+= augmentation_data_len
;
8490 if (augmentation_data_len
)
8494 unsigned char *qend
;
8496 p
= (unsigned char *) fc
->augmentation
+ 1;
8497 q
= augmentation_data
;
8498 qend
= q
+ augmentation_data_len
;
8500 while (p
< end
&& q
< qend
)
8505 q
+= 1 + size_of_encoded_value (*q
);
8507 fc
->fde_encoding
= *q
++;
8516 /* Note - it is OK if this loop terminates with q < qend.
8517 Padding may have been inserted to align the end of the CIE. */
8522 *p_version
= version
;
8525 *p_aug_len
= augmentation_data_len
;
8526 *p_aug
= augmentation_data
;
8531 free (fc
->col_offset
);
8532 free (fc
->col_type
);
8537 /* Prints out the contents on the DATA array formatted as unsigned bytes.
8538 If do_wide is not enabled, then formats the output to fit into 80 columns.
8539 PRINTED contains the number of characters already written to the current
8543 display_data (bfd_size_type printed
,
8544 const unsigned char * data
,
8545 const bfd_size_type len
)
8547 if (do_wide
|| len
< ((80 - printed
) / 3))
8548 for (printed
= 0; printed
< len
; ++printed
)
8549 printf (" %02x", data
[printed
]);
8552 for (printed
= 0; printed
< len
; ++printed
)
8554 if (printed
% (80 / 3) == 0)
8556 printf (" %02x", data
[printed
]);
8561 /* Prints out the contents on the augmentation data array.
8562 If do_wide is not enabled, then formats the output to fit into 80 columns. */
8565 display_augmentation_data (const unsigned char * data
, const bfd_size_type len
)
8569 i
= printf (_(" Augmentation data: "));
8570 display_data (i
, data
, len
);
8574 display_debug_frames (struct dwarf_section
*section
,
8575 void *file ATTRIBUTE_UNUSED
)
8577 unsigned char *start
= section
->start
;
8578 unsigned char *end
= start
+ section
->size
;
8579 unsigned char *section_start
= start
;
8580 Frame_Chunk
*chunks
= NULL
, *forward_refs
= NULL
;
8581 Frame_Chunk
*remembered_state
= NULL
;
8583 bool is_eh
= strcmp (section
->name
, ".eh_frame") == 0;
8584 unsigned int max_regs
= 0;
8585 const char *bad_reg
= _("bad register: ");
8586 unsigned int saved_eh_addr_size
= eh_addr_size
;
8588 introduce (section
, false);
8592 unsigned char *saved_start
;
8593 unsigned char *block_end
;
8598 int need_col_headers
= 1;
8599 unsigned char *augmentation_data
= NULL
;
8600 bfd_size_type augmentation_data_len
= 0;
8601 unsigned int encoded_ptr_size
= saved_eh_addr_size
;
8602 unsigned int offset_size
;
8603 unsigned int initial_length_size
;
8605 static Frame_Chunk fde_fc
;
8607 saved_start
= start
;
8609 SAFE_BYTE_GET_AND_INC (length
, start
, 4, end
);
8613 printf ("\n%08lx ZERO terminator\n\n",
8614 (unsigned long)(saved_start
- section_start
));
8615 /* Skip any zero terminators that directly follow.
8616 A corrupt section size could have loaded a whole
8617 slew of zero filled memory bytes. eg
8618 PR 17512: file: 070-19381-0.004. */
8619 while (start
< end
&& * start
== 0)
8624 if (length
== 0xffffffff)
8626 SAFE_BYTE_GET_AND_INC (length
, start
, 8, end
);
8628 initial_length_size
= 12;
8633 initial_length_size
= 4;
8636 block_end
= saved_start
+ length
+ initial_length_size
;
8637 if (block_end
> end
|| block_end
< start
)
8639 warn ("Invalid length 0x%s in FDE at %#08lx\n",
8640 dwarf_vmatoa_1 (NULL
, length
, offset_size
),
8641 (unsigned long) (saved_start
- section_start
));
8645 SAFE_BYTE_GET_AND_INC (cie_id
, start
, offset_size
, end
);
8647 if (is_eh
? (cie_id
== 0) : ((offset_size
== 4 && cie_id
== DW_CIE_ID
)
8648 || (offset_size
== 8 && cie_id
== DW64_CIE_ID
)))
8653 start
= read_cie (start
, end
, &cie
, &version
,
8654 &augmentation_data_len
, &augmentation_data
);
8655 /* PR 17512: file: 027-135133-0.005. */
8662 fc
->chunk_start
= saved_start
;
8663 mreg
= max_regs
> 0 ? max_regs
- 1 : 0;
8666 if (frame_need_space (fc
, mreg
) < 0)
8668 if (fc
->fde_encoding
)
8669 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
8671 printf ("\n%08lx ", (unsigned long) (saved_start
- section_start
));
8672 print_dwarf_vma (length
, fc
->ptr_size
);
8673 print_dwarf_vma (cie_id
, offset_size
);
8675 if (do_debug_frames_interp
)
8677 printf ("CIE \"%s\" cf=%d df=%d ra=%d\n", fc
->augmentation
,
8678 fc
->code_factor
, fc
->data_factor
, fc
->ra
);
8683 printf (" Version: %d\n", version
);
8684 printf (" Augmentation: \"%s\"\n", fc
->augmentation
);
8687 printf (" Pointer Size: %u\n", fc
->ptr_size
);
8688 printf (" Segment Size: %u\n", fc
->segment_size
);
8690 printf (" Code alignment factor: %u\n", fc
->code_factor
);
8691 printf (" Data alignment factor: %d\n", fc
->data_factor
);
8692 printf (" Return address column: %d\n", fc
->ra
);
8694 if (augmentation_data_len
)
8695 display_augmentation_data (augmentation_data
, augmentation_data_len
);
8702 unsigned char *look_for
;
8703 unsigned long segment_selector
;
8709 dwarf_vma sign
= (dwarf_vma
) 1 << (offset_size
* 8 - 1);
8710 cie_off
= (cie_off
^ sign
) - sign
;
8711 cie_off
= start
- 4 - section_start
- cie_off
;
8714 look_for
= section_start
+ cie_off
;
8715 if (cie_off
<= (dwarf_vma
) (saved_start
- section_start
))
8717 for (cie
= chunks
; cie
; cie
= cie
->next
)
8718 if (cie
->chunk_start
== look_for
)
8723 for (cie
= forward_refs
; cie
; cie
= cie
->next
)
8724 if (cie
->chunk_start
== look_for
)
8728 unsigned int off_size
;
8729 unsigned char *cie_scan
;
8731 cie_scan
= look_for
;
8733 SAFE_BYTE_GET_AND_INC (length
, cie_scan
, 4, end
);
8734 if (length
== 0xffffffff)
8736 SAFE_BYTE_GET_AND_INC (length
, cie_scan
, 8, end
);
8743 SAFE_BYTE_GET_AND_INC (c_id
, cie_scan
, off_size
, end
);
8746 : ((off_size
== 4 && c_id
== DW_CIE_ID
)
8747 || (off_size
== 8 && c_id
== DW64_CIE_ID
)))
8752 read_cie (cie_scan
, end
, &cie
, &version
,
8753 &augmentation_data_len
, &augmentation_data
);
8754 /* PR 17512: file: 3450-2098-0.004. */
8757 warn (_("Failed to read CIE information\n"));
8760 cie
->next
= forward_refs
;
8762 cie
->chunk_start
= look_for
;
8763 mreg
= max_regs
> 0 ? max_regs
- 1 : 0;
8766 if (frame_need_space (cie
, mreg
) < 0)
8768 warn (_("Invalid max register\n"));
8771 if (cie
->fde_encoding
)
8773 = size_of_encoded_value (cie
->fde_encoding
);
8780 memset (fc
, 0, sizeof (Frame_Chunk
));
8784 warn ("Invalid CIE pointer 0x%s in FDE at %#08lx\n",
8785 dwarf_vmatoa_1 (NULL
, cie_id
, offset_size
),
8786 (unsigned long) (saved_start
- section_start
));
8788 fc
->col_type
= (short int *) xmalloc (sizeof (short int));
8789 fc
->col_offset
= (int *) xmalloc (sizeof (int));
8790 if (frame_need_space (fc
, max_regs
> 0 ? max_regs
- 1 : 0) < 0)
8792 warn (_("Invalid max register\n"));
8796 fc
->augmentation
= "";
8797 fc
->fde_encoding
= 0;
8798 fc
->ptr_size
= eh_addr_size
;
8799 fc
->segment_size
= 0;
8803 fc
->ncols
= cie
->ncols
;
8804 fc
->col_type
= (short int *) xcmalloc (fc
->ncols
, sizeof (short int));
8805 fc
->col_offset
= (int *) xcmalloc (fc
->ncols
, sizeof (int));
8806 memcpy (fc
->col_type
, cie
->col_type
, fc
->ncols
* sizeof (short int));
8807 memcpy (fc
->col_offset
, cie
->col_offset
, fc
->ncols
* sizeof (int));
8808 fc
->augmentation
= cie
->augmentation
;
8809 fc
->ptr_size
= cie
->ptr_size
;
8810 eh_addr_size
= cie
->ptr_size
;
8811 fc
->segment_size
= cie
->segment_size
;
8812 fc
->code_factor
= cie
->code_factor
;
8813 fc
->data_factor
= cie
->data_factor
;
8814 fc
->cfa_reg
= cie
->cfa_reg
;
8815 fc
->cfa_offset
= cie
->cfa_offset
;
8817 if (frame_need_space (fc
, max_regs
> 0 ? max_regs
- 1: 0) < 0)
8819 warn (_("Invalid max register\n"));
8822 fc
->fde_encoding
= cie
->fde_encoding
;
8825 if (fc
->fde_encoding
)
8826 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
8828 segment_selector
= 0;
8829 if (fc
->segment_size
)
8831 if (fc
->segment_size
> sizeof (segment_selector
))
8833 /* PR 17512: file: 9e196b3e. */
8834 warn (_("Probably corrupt segment size: %d - using 4 instead\n"), fc
->segment_size
);
8835 fc
->segment_size
= 4;
8837 SAFE_BYTE_GET_AND_INC (segment_selector
, start
, fc
->segment_size
, end
);
8840 fc
->pc_begin
= get_encoded_value (&start
, fc
->fde_encoding
, section
, end
);
8842 /* FIXME: It appears that sometimes the final pc_range value is
8843 encoded in less than encoded_ptr_size bytes. See the x86_64
8844 run of the "objcopy on compressed debug sections" test for an
8846 SAFE_BYTE_GET_AND_INC (fc
->pc_range
, start
, encoded_ptr_size
, end
);
8848 if (cie
->augmentation
[0] == 'z')
8850 READ_ULEB (augmentation_data_len
, start
, end
);
8851 augmentation_data
= start
;
8852 /* PR 17512 file: 722-8446-0.004 and PR 22386. */
8853 if (augmentation_data_len
> (bfd_size_type
) (end
- start
))
8855 warn (_("Augmentation data too long: 0x%s, "
8856 "expected at most %#lx\n"),
8857 dwarf_vmatoa ("x", augmentation_data_len
),
8858 (unsigned long) (end
- start
));
8860 augmentation_data
= NULL
;
8861 augmentation_data_len
= 0;
8863 start
+= augmentation_data_len
;
8866 printf ("\n%08lx %s %s FDE cie=%08lx pc=",
8867 (unsigned long)(saved_start
- section_start
),
8868 dwarf_vmatoa_1 (NULL
, length
, fc
->ptr_size
),
8869 dwarf_vmatoa_1 (NULL
, cie_id
, offset_size
),
8870 (unsigned long)(cie
->chunk_start
- section_start
));
8872 if (fc
->segment_size
)
8873 printf ("%04lx:", segment_selector
);
8876 dwarf_vmatoa_1 (NULL
, fc
->pc_begin
, fc
->ptr_size
),
8877 dwarf_vmatoa_1 (NULL
, fc
->pc_begin
+ fc
->pc_range
, fc
->ptr_size
));
8879 if (! do_debug_frames_interp
&& augmentation_data_len
)
8881 display_augmentation_data (augmentation_data
, augmentation_data_len
);
8886 /* At this point, fc is the current chunk, cie (if any) is set, and
8887 we're about to interpret instructions for the chunk. */
8888 /* ??? At present we need to do this always, since this sizes the
8889 fc->col_type and fc->col_offset arrays, which we write into always.
8890 We should probably split the interpreted and non-interpreted bits
8891 into two different routines, since there's so much that doesn't
8892 really overlap between them. */
8893 if (1 || do_debug_frames_interp
)
8895 /* Start by making a pass over the chunk, allocating storage
8896 and taking note of what registers are used. */
8897 unsigned char *tmp
= start
;
8899 while (start
< block_end
)
8901 unsigned int reg
, op
, opa
;
8903 unsigned char * new_start
;
8910 /* Warning: if you add any more cases to this switch, be
8911 sure to add them to the corresponding switch below. */
8914 case DW_CFA_advance_loc
:
8917 SKIP_ULEB (start
, end
);
8918 if (frame_need_space (fc
, opa
) >= 0)
8919 fc
->col_type
[opa
] = DW_CFA_undefined
;
8921 case DW_CFA_restore
:
8922 if (frame_need_space (fc
, opa
) >= 0)
8923 fc
->col_type
[opa
] = DW_CFA_undefined
;
8925 case DW_CFA_set_loc
:
8926 start
+= encoded_ptr_size
;
8928 case DW_CFA_advance_loc1
:
8931 case DW_CFA_advance_loc2
:
8934 case DW_CFA_advance_loc4
:
8937 case DW_CFA_offset_extended
:
8938 case DW_CFA_val_offset
:
8939 READ_ULEB (reg
, start
, end
);
8940 SKIP_ULEB (start
, end
);
8941 if (frame_need_space (fc
, reg
) >= 0)
8942 fc
->col_type
[reg
] = DW_CFA_undefined
;
8944 case DW_CFA_restore_extended
:
8945 READ_ULEB (reg
, start
, end
);
8946 if (frame_need_space (fc
, reg
) >= 0)
8947 fc
->col_type
[reg
] = DW_CFA_undefined
;
8949 case DW_CFA_undefined
:
8950 READ_ULEB (reg
, start
, end
);
8951 if (frame_need_space (fc
, reg
) >= 0)
8952 fc
->col_type
[reg
] = DW_CFA_undefined
;
8954 case DW_CFA_same_value
:
8955 READ_ULEB (reg
, start
, end
);
8956 if (frame_need_space (fc
, reg
) >= 0)
8957 fc
->col_type
[reg
] = DW_CFA_undefined
;
8959 case DW_CFA_register
:
8960 READ_ULEB (reg
, start
, end
);
8961 SKIP_ULEB (start
, end
);
8962 if (frame_need_space (fc
, reg
) >= 0)
8963 fc
->col_type
[reg
] = DW_CFA_undefined
;
8965 case DW_CFA_def_cfa
:
8966 SKIP_ULEB (start
, end
);
8967 SKIP_ULEB (start
, end
);
8969 case DW_CFA_def_cfa_register
:
8970 SKIP_ULEB (start
, end
);
8972 case DW_CFA_def_cfa_offset
:
8973 SKIP_ULEB (start
, end
);
8975 case DW_CFA_def_cfa_expression
:
8976 READ_ULEB (temp
, start
, end
);
8977 new_start
= start
+ temp
;
8978 if (new_start
< start
)
8980 warn (_("Corrupt CFA_def expression value: %lu\n"), temp
);
8986 case DW_CFA_expression
:
8987 case DW_CFA_val_expression
:
8988 READ_ULEB (reg
, start
, end
);
8989 READ_ULEB (temp
, start
, end
);
8990 new_start
= start
+ temp
;
8991 if (new_start
< start
)
8993 /* PR 17512: file:306-192417-0.005. */
8994 warn (_("Corrupt CFA expression value: %lu\n"), temp
);
8999 if (frame_need_space (fc
, reg
) >= 0)
9000 fc
->col_type
[reg
] = DW_CFA_undefined
;
9002 case DW_CFA_offset_extended_sf
:
9003 case DW_CFA_val_offset_sf
:
9004 READ_ULEB (reg
, start
, end
);
9005 SKIP_SLEB (start
, end
);
9006 if (frame_need_space (fc
, reg
) >= 0)
9007 fc
->col_type
[reg
] = DW_CFA_undefined
;
9009 case DW_CFA_def_cfa_sf
:
9010 SKIP_ULEB (start
, end
);
9011 SKIP_SLEB (start
, end
);
9013 case DW_CFA_def_cfa_offset_sf
:
9014 SKIP_SLEB (start
, end
);
9016 case DW_CFA_MIPS_advance_loc8
:
9019 case DW_CFA_GNU_args_size
:
9020 SKIP_ULEB (start
, end
);
9022 case DW_CFA_GNU_negative_offset_extended
:
9023 READ_ULEB (reg
, start
, end
);
9024 SKIP_ULEB (start
, end
);
9025 if (frame_need_space (fc
, reg
) >= 0)
9026 fc
->col_type
[reg
] = DW_CFA_undefined
;
9037 /* Now we know what registers are used, make a second pass over
9038 the chunk, this time actually printing out the info. */
9040 while (start
< block_end
)
9042 unsigned char * tmp
;
9044 unsigned long ul
, roffs
;
9045 /* Note: It is tempting to use an unsigned long for 'reg' but there
9046 are various functions, notably frame_space_needed() that assume that
9047 reg is an unsigned int. */
9052 const char *reg_prefix
= "";
9059 /* Make a note if something other than DW_CFA_nop happens. */
9060 if (op
!= DW_CFA_nop
)
9063 /* Warning: if you add any more cases to this switch, be
9064 sure to add them to the corresponding switch above. */
9067 case DW_CFA_advance_loc
:
9068 if (do_debug_frames_interp
)
9069 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9071 printf (" DW_CFA_advance_loc: %d to %s\n",
9072 opa
* fc
->code_factor
,
9073 dwarf_vmatoa_1 (NULL
,
9074 fc
->pc_begin
+ opa
* fc
->code_factor
,
9076 fc
->pc_begin
+= opa
* fc
->code_factor
;
9080 READ_ULEB (roffs
, start
, end
);
9081 if (opa
>= (unsigned int) fc
->ncols
)
9082 reg_prefix
= bad_reg
;
9083 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9084 printf (" DW_CFA_offset: %s%s at cfa%+ld\n",
9085 reg_prefix
, regname (opa
, 0),
9086 roffs
* fc
->data_factor
);
9087 if (*reg_prefix
== '\0')
9089 fc
->col_type
[opa
] = DW_CFA_offset
;
9090 fc
->col_offset
[opa
] = roffs
* fc
->data_factor
;
9094 case DW_CFA_restore
:
9095 if (opa
>= (unsigned int) fc
->ncols
)
9096 reg_prefix
= bad_reg
;
9097 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9098 printf (" DW_CFA_restore: %s%s\n",
9099 reg_prefix
, regname (opa
, 0));
9100 if (*reg_prefix
!= '\0')
9103 if (opa
>= (unsigned int) cie
->ncols
9104 || (do_debug_frames_interp
9105 && cie
->col_type
[opa
] == DW_CFA_unreferenced
))
9107 fc
->col_type
[opa
] = DW_CFA_undefined
;
9108 fc
->col_offset
[opa
] = 0;
9112 fc
->col_type
[opa
] = cie
->col_type
[opa
];
9113 fc
->col_offset
[opa
] = cie
->col_offset
[opa
];
9117 case DW_CFA_set_loc
:
9118 vma
= get_encoded_value (&start
, fc
->fde_encoding
, section
, block_end
);
9119 if (do_debug_frames_interp
)
9120 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9122 printf (" DW_CFA_set_loc: %s\n",
9123 dwarf_vmatoa_1 (NULL
, vma
, fc
->ptr_size
));
9127 case DW_CFA_advance_loc1
:
9128 SAFE_BYTE_GET_AND_INC (ofs
, start
, 1, end
);
9129 if (do_debug_frames_interp
)
9130 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9132 printf (" DW_CFA_advance_loc1: %ld to %s\n",
9133 (unsigned long) (ofs
* fc
->code_factor
),
9134 dwarf_vmatoa_1 (NULL
,
9135 fc
->pc_begin
+ ofs
* fc
->code_factor
,
9137 fc
->pc_begin
+= ofs
* fc
->code_factor
;
9140 case DW_CFA_advance_loc2
:
9141 SAFE_BYTE_GET_AND_INC (ofs
, start
, 2, block_end
);
9142 if (do_debug_frames_interp
)
9143 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9145 printf (" DW_CFA_advance_loc2: %ld to %s\n",
9146 (unsigned long) (ofs
* fc
->code_factor
),
9147 dwarf_vmatoa_1 (NULL
,
9148 fc
->pc_begin
+ ofs
* fc
->code_factor
,
9150 fc
->pc_begin
+= ofs
* fc
->code_factor
;
9153 case DW_CFA_advance_loc4
:
9154 SAFE_BYTE_GET_AND_INC (ofs
, start
, 4, block_end
);
9155 if (do_debug_frames_interp
)
9156 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9158 printf (" DW_CFA_advance_loc4: %ld to %s\n",
9159 (unsigned long) (ofs
* fc
->code_factor
),
9160 dwarf_vmatoa_1 (NULL
,
9161 fc
->pc_begin
+ ofs
* fc
->code_factor
,
9163 fc
->pc_begin
+= ofs
* fc
->code_factor
;
9166 case DW_CFA_offset_extended
:
9167 READ_ULEB (reg
, start
, end
);
9168 READ_ULEB (roffs
, start
, end
);
9169 if (reg
>= (unsigned int) fc
->ncols
)
9170 reg_prefix
= bad_reg
;
9171 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9172 printf (" DW_CFA_offset_extended: %s%s at cfa%+ld\n",
9173 reg_prefix
, regname (reg
, 0),
9174 roffs
* fc
->data_factor
);
9175 if (*reg_prefix
== '\0')
9177 fc
->col_type
[reg
] = DW_CFA_offset
;
9178 fc
->col_offset
[reg
] = roffs
* fc
->data_factor
;
9182 case DW_CFA_val_offset
:
9183 READ_ULEB (reg
, start
, end
);
9184 READ_ULEB (roffs
, start
, end
);
9185 if (reg
>= (unsigned int) fc
->ncols
)
9186 reg_prefix
= bad_reg
;
9187 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9188 printf (" DW_CFA_val_offset: %s%s is cfa%+ld\n",
9189 reg_prefix
, regname (reg
, 0),
9190 roffs
* fc
->data_factor
);
9191 if (*reg_prefix
== '\0')
9193 fc
->col_type
[reg
] = DW_CFA_val_offset
;
9194 fc
->col_offset
[reg
] = roffs
* fc
->data_factor
;
9198 case DW_CFA_restore_extended
:
9199 READ_ULEB (reg
, start
, end
);
9200 if (reg
>= (unsigned int) fc
->ncols
)
9201 reg_prefix
= bad_reg
;
9202 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9203 printf (" DW_CFA_restore_extended: %s%s\n",
9204 reg_prefix
, regname (reg
, 0));
9205 if (*reg_prefix
!= '\0')
9208 if (reg
>= (unsigned int) cie
->ncols
)
9210 fc
->col_type
[reg
] = DW_CFA_undefined
;
9211 fc
->col_offset
[reg
] = 0;
9215 fc
->col_type
[reg
] = cie
->col_type
[reg
];
9216 fc
->col_offset
[reg
] = cie
->col_offset
[reg
];
9220 case DW_CFA_undefined
:
9221 READ_ULEB (reg
, start
, end
);
9222 if (reg
>= (unsigned int) fc
->ncols
)
9223 reg_prefix
= bad_reg
;
9224 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9225 printf (" DW_CFA_undefined: %s%s\n",
9226 reg_prefix
, regname (reg
, 0));
9227 if (*reg_prefix
== '\0')
9229 fc
->col_type
[reg
] = DW_CFA_undefined
;
9230 fc
->col_offset
[reg
] = 0;
9234 case DW_CFA_same_value
:
9235 READ_ULEB (reg
, start
, end
);
9236 if (reg
>= (unsigned int) fc
->ncols
)
9237 reg_prefix
= bad_reg
;
9238 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9239 printf (" DW_CFA_same_value: %s%s\n",
9240 reg_prefix
, regname (reg
, 0));
9241 if (*reg_prefix
== '\0')
9243 fc
->col_type
[reg
] = DW_CFA_same_value
;
9244 fc
->col_offset
[reg
] = 0;
9248 case DW_CFA_register
:
9249 READ_ULEB (reg
, start
, end
);
9250 READ_ULEB (roffs
, start
, end
);
9251 if (reg
>= (unsigned int) fc
->ncols
)
9252 reg_prefix
= bad_reg
;
9253 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9255 printf (" DW_CFA_register: %s%s in ",
9256 reg_prefix
, regname (reg
, 0));
9257 puts (regname (roffs
, 0));
9259 if (*reg_prefix
== '\0')
9261 fc
->col_type
[reg
] = DW_CFA_register
;
9262 fc
->col_offset
[reg
] = roffs
;
9266 case DW_CFA_remember_state
:
9267 if (! do_debug_frames_interp
)
9268 printf (" DW_CFA_remember_state\n");
9269 rs
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
9270 rs
->cfa_offset
= fc
->cfa_offset
;
9271 rs
->cfa_reg
= fc
->cfa_reg
;
9273 rs
->cfa_exp
= fc
->cfa_exp
;
9274 rs
->ncols
= fc
->ncols
;
9275 rs
->col_type
= (short int *) xcmalloc (rs
->ncols
,
9276 sizeof (* rs
->col_type
));
9277 rs
->col_offset
= (int *) xcmalloc (rs
->ncols
, sizeof (* rs
->col_offset
));
9278 memcpy (rs
->col_type
, fc
->col_type
, rs
->ncols
* sizeof (* fc
->col_type
));
9279 memcpy (rs
->col_offset
, fc
->col_offset
, rs
->ncols
* sizeof (* fc
->col_offset
));
9280 rs
->next
= remembered_state
;
9281 remembered_state
= rs
;
9284 case DW_CFA_restore_state
:
9285 if (! do_debug_frames_interp
)
9286 printf (" DW_CFA_restore_state\n");
9287 rs
= remembered_state
;
9290 remembered_state
= rs
->next
;
9291 fc
->cfa_offset
= rs
->cfa_offset
;
9292 fc
->cfa_reg
= rs
->cfa_reg
;
9294 fc
->cfa_exp
= rs
->cfa_exp
;
9295 if (frame_need_space (fc
, rs
->ncols
- 1) < 0)
9297 warn (_("Invalid column number in saved frame state\n"));
9301 memcpy (fc
->col_type
, rs
->col_type
, rs
->ncols
* sizeof (* rs
->col_type
));
9302 memcpy (fc
->col_offset
, rs
->col_offset
,
9303 rs
->ncols
* sizeof (* rs
->col_offset
));
9304 free (rs
->col_type
);
9305 free (rs
->col_offset
);
9308 else if (do_debug_frames_interp
)
9309 printf ("Mismatched DW_CFA_restore_state\n");
9312 case DW_CFA_def_cfa
:
9313 READ_ULEB (fc
->cfa_reg
, start
, end
);
9314 READ_ULEB (fc
->cfa_offset
, start
, end
);
9316 if (! do_debug_frames_interp
)
9317 printf (" DW_CFA_def_cfa: %s ofs %d\n",
9318 regname (fc
->cfa_reg
, 0), (int) fc
->cfa_offset
);
9321 case DW_CFA_def_cfa_register
:
9322 READ_ULEB (fc
->cfa_reg
, start
, end
);
9324 if (! do_debug_frames_interp
)
9325 printf (" DW_CFA_def_cfa_register: %s\n",
9326 regname (fc
->cfa_reg
, 0));
9329 case DW_CFA_def_cfa_offset
:
9330 READ_ULEB (fc
->cfa_offset
, start
, end
);
9331 if (! do_debug_frames_interp
)
9332 printf (" DW_CFA_def_cfa_offset: %d\n", (int) fc
->cfa_offset
);
9336 if (! do_debug_frames_interp
)
9337 printf (" DW_CFA_nop\n");
9340 case DW_CFA_def_cfa_expression
:
9341 READ_ULEB (ul
, start
, end
);
9342 if (start
>= block_end
|| ul
> (unsigned long) (block_end
- start
))
9344 printf (_(" DW_CFA_def_cfa_expression: <corrupt len %lu>\n"), ul
);
9347 if (! do_debug_frames_interp
)
9349 printf (" DW_CFA_def_cfa_expression (");
9350 decode_location_expression (start
, eh_addr_size
, 0, -1,
9358 case DW_CFA_expression
:
9359 READ_ULEB (reg
, start
, end
);
9360 READ_ULEB (ul
, start
, end
);
9361 if (reg
>= (unsigned int) fc
->ncols
)
9362 reg_prefix
= bad_reg
;
9363 /* PR 17512: file: 069-133014-0.006. */
9364 /* PR 17512: file: 98c02eb4. */
9366 if (start
>= block_end
|| tmp
> block_end
|| tmp
< start
)
9368 printf (_(" DW_CFA_expression: <corrupt len %lu>\n"), ul
);
9371 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9373 printf (" DW_CFA_expression: %s%s (",
9374 reg_prefix
, regname (reg
, 0));
9375 decode_location_expression (start
, eh_addr_size
, 0, -1,
9379 if (*reg_prefix
== '\0')
9380 fc
->col_type
[reg
] = DW_CFA_expression
;
9384 case DW_CFA_val_expression
:
9385 READ_ULEB (reg
, start
, end
);
9386 READ_ULEB (ul
, start
, end
);
9387 if (reg
>= (unsigned int) fc
->ncols
)
9388 reg_prefix
= bad_reg
;
9390 if (start
>= block_end
|| tmp
> block_end
|| tmp
< start
)
9392 printf (" DW_CFA_val_expression: <corrupt len %lu>\n", ul
);
9395 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9397 printf (" DW_CFA_val_expression: %s%s (",
9398 reg_prefix
, regname (reg
, 0));
9399 decode_location_expression (start
, eh_addr_size
, 0, -1,
9403 if (*reg_prefix
== '\0')
9404 fc
->col_type
[reg
] = DW_CFA_val_expression
;
9408 case DW_CFA_offset_extended_sf
:
9409 READ_ULEB (reg
, start
, end
);
9410 READ_SLEB (l
, start
, end
);
9411 if (frame_need_space (fc
, reg
) < 0)
9412 reg_prefix
= bad_reg
;
9413 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9414 printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+ld\n",
9415 reg_prefix
, regname (reg
, 0),
9416 (long)(l
* fc
->data_factor
));
9417 if (*reg_prefix
== '\0')
9419 fc
->col_type
[reg
] = DW_CFA_offset
;
9420 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
9424 case DW_CFA_val_offset_sf
:
9425 READ_ULEB (reg
, start
, end
);
9426 READ_SLEB (l
, start
, end
);
9427 if (frame_need_space (fc
, reg
) < 0)
9428 reg_prefix
= bad_reg
;
9429 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9430 printf (" DW_CFA_val_offset_sf: %s%s is cfa%+ld\n",
9431 reg_prefix
, regname (reg
, 0),
9432 (long)(l
* fc
->data_factor
));
9433 if (*reg_prefix
== '\0')
9435 fc
->col_type
[reg
] = DW_CFA_val_offset
;
9436 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
9440 case DW_CFA_def_cfa_sf
:
9441 READ_ULEB (fc
->cfa_reg
, start
, end
);
9442 READ_ULEB (fc
->cfa_offset
, start
, end
);
9443 fc
->cfa_offset
= fc
->cfa_offset
* fc
->data_factor
;
9445 if (! do_debug_frames_interp
)
9446 printf (" DW_CFA_def_cfa_sf: %s ofs %d\n",
9447 regname (fc
->cfa_reg
, 0), (int) fc
->cfa_offset
);
9450 case DW_CFA_def_cfa_offset_sf
:
9451 READ_ULEB (fc
->cfa_offset
, start
, end
);
9452 fc
->cfa_offset
*= fc
->data_factor
;
9453 if (! do_debug_frames_interp
)
9454 printf (" DW_CFA_def_cfa_offset_sf: %d\n", (int) fc
->cfa_offset
);
9457 case DW_CFA_MIPS_advance_loc8
:
9458 SAFE_BYTE_GET_AND_INC (ofs
, start
, 8, block_end
);
9459 if (do_debug_frames_interp
)
9460 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9462 printf (" DW_CFA_MIPS_advance_loc8: %ld to %s\n",
9463 (unsigned long) (ofs
* fc
->code_factor
),
9464 dwarf_vmatoa_1 (NULL
,
9465 fc
->pc_begin
+ ofs
* fc
->code_factor
,
9467 fc
->pc_begin
+= ofs
* fc
->code_factor
;
9470 case DW_CFA_GNU_window_save
:
9471 if (! do_debug_frames_interp
)
9472 printf (" DW_CFA_GNU_window_save\n");
9475 case DW_CFA_GNU_args_size
:
9476 READ_ULEB (ul
, start
, end
);
9477 if (! do_debug_frames_interp
)
9478 printf (" DW_CFA_GNU_args_size: %ld\n", ul
);
9481 case DW_CFA_GNU_negative_offset_extended
:
9482 READ_ULEB (reg
, start
, end
);
9483 READ_SLEB (l
, start
, end
);
9485 if (frame_need_space (fc
, reg
) < 0)
9486 reg_prefix
= bad_reg
;
9487 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9488 printf (" DW_CFA_GNU_negative_offset_extended: %s%s at cfa%+ld\n",
9489 reg_prefix
, regname (reg
, 0),
9490 (long)(l
* fc
->data_factor
));
9491 if (*reg_prefix
== '\0')
9493 fc
->col_type
[reg
] = DW_CFA_offset
;
9494 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
9499 if (op
>= DW_CFA_lo_user
&& op
<= DW_CFA_hi_user
)
9500 printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op
);
9502 warn (_("Unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op
);
9507 /* Interpret the CFA - as long as it is not completely full of NOPs. */
9508 if (do_debug_frames_interp
&& ! all_nops
)
9509 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9511 if (fde_fc
.col_type
!= NULL
)
9513 free (fde_fc
.col_type
);
9514 fde_fc
.col_type
= NULL
;
9516 if (fde_fc
.col_offset
!= NULL
)
9518 free (fde_fc
.col_offset
);
9519 fde_fc
.col_offset
= NULL
;
9523 eh_addr_size
= saved_eh_addr_size
;
9528 while (remembered_state
!= NULL
)
9530 rs
= remembered_state
;
9531 remembered_state
= rs
->next
;
9532 free (rs
->col_type
);
9533 free (rs
->col_offset
);
9534 rs
->next
= NULL
; /* Paranoia. */
9538 while (chunks
!= NULL
)
9542 free (rs
->col_type
);
9543 free (rs
->col_offset
);
9544 rs
->next
= NULL
; /* Paranoia. */
9548 while (forward_refs
!= NULL
)
9551 forward_refs
= rs
->next
;
9552 free (rs
->col_type
);
9553 free (rs
->col_offset
);
9554 rs
->next
= NULL
; /* Paranoia. */
9564 display_debug_names (struct dwarf_section
*section
, void *file
)
9566 unsigned char *hdrptr
= section
->start
;
9567 dwarf_vma unit_length
;
9568 unsigned char *unit_start
;
9569 const unsigned char *const section_end
= section
->start
+ section
->size
;
9570 unsigned char *unit_end
;
9572 introduce (section
, false);
9574 load_debug_section_with_follow (str
, file
);
9576 for (; hdrptr
< section_end
; hdrptr
= unit_end
)
9578 unsigned int offset_size
;
9579 uint16_t dwarf_version
, padding
;
9580 uint32_t comp_unit_count
, local_type_unit_count
, foreign_type_unit_count
;
9581 uint32_t bucket_count
, name_count
, abbrev_table_size
;
9582 uint32_t augmentation_string_size
;
9584 unsigned long sec_off
;
9585 bool augmentation_printable
;
9586 const char *augmentation_string
;
9588 unit_start
= hdrptr
;
9590 /* Get and check the length of the block. */
9591 SAFE_BYTE_GET_AND_INC (unit_length
, hdrptr
, 4, section_end
);
9593 if (unit_length
== 0xffffffff)
9595 /* This section is 64-bit DWARF. */
9596 SAFE_BYTE_GET_AND_INC (unit_length
, hdrptr
, 8, section_end
);
9601 unit_end
= hdrptr
+ unit_length
;
9603 sec_off
= hdrptr
- section
->start
;
9604 if (sec_off
+ unit_length
< sec_off
9605 || sec_off
+ unit_length
> section
->size
)
9607 warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"),
9609 (unsigned long) (unit_start
- section
->start
),
9610 dwarf_vmatoa ("x", unit_length
));
9614 /* Get and check the version number. */
9615 SAFE_BYTE_GET_AND_INC (dwarf_version
, hdrptr
, 2, unit_end
);
9616 printf (_("Version %ld\n"), (long) dwarf_version
);
9618 /* Prior versions did not exist, and future versions may not be
9619 backwards compatible. */
9620 if (dwarf_version
!= 5)
9622 warn (_("Only DWARF version 5 .debug_names "
9623 "is currently supported.\n"));
9627 SAFE_BYTE_GET_AND_INC (padding
, hdrptr
, 2, unit_end
);
9629 warn (_("Padding field of .debug_names must be 0 (found 0x%x)\n"),
9632 SAFE_BYTE_GET_AND_INC (comp_unit_count
, hdrptr
, 4, unit_end
);
9633 if (comp_unit_count
== 0)
9634 warn (_("Compilation unit count must be >= 1 in .debug_names\n"));
9636 SAFE_BYTE_GET_AND_INC (local_type_unit_count
, hdrptr
, 4, unit_end
);
9637 SAFE_BYTE_GET_AND_INC (foreign_type_unit_count
, hdrptr
, 4, unit_end
);
9638 SAFE_BYTE_GET_AND_INC (bucket_count
, hdrptr
, 4, unit_end
);
9639 SAFE_BYTE_GET_AND_INC (name_count
, hdrptr
, 4, unit_end
);
9640 SAFE_BYTE_GET_AND_INC (abbrev_table_size
, hdrptr
, 4, unit_end
);
9642 SAFE_BYTE_GET_AND_INC (augmentation_string_size
, hdrptr
, 4, unit_end
);
9643 if (augmentation_string_size
% 4 != 0)
9645 warn (_("Augmentation string length %u must be rounded up "
9646 "to a multiple of 4 in .debug_names.\n"),
9647 augmentation_string_size
);
9648 augmentation_string_size
+= (-augmentation_string_size
) & 3;
9651 printf (_("Augmentation string:"));
9653 augmentation_printable
= true;
9654 augmentation_string
= (const char *) hdrptr
;
9656 for (i
= 0; i
< augmentation_string_size
; i
++)
9660 SAFE_BYTE_GET_AND_INC (uc
, hdrptr
, 1, unit_end
);
9661 printf (" %02x", uc
);
9663 if (uc
!= 0 && !ISPRINT (uc
))
9664 augmentation_printable
= false;
9667 if (augmentation_printable
)
9671 i
< augmentation_string_size
&& augmentation_string
[i
];
9673 putchar (augmentation_string
[i
]);
9678 printf (_("CU table:\n"));
9679 for (i
= 0; i
< comp_unit_count
; i
++)
9683 SAFE_BYTE_GET_AND_INC (cu_offset
, hdrptr
, offset_size
, unit_end
);
9684 printf (_("[%3u] 0x%lx\n"), i
, (unsigned long) cu_offset
);
9688 printf (_("TU table:\n"));
9689 for (i
= 0; i
< local_type_unit_count
; i
++)
9693 SAFE_BYTE_GET_AND_INC (tu_offset
, hdrptr
, offset_size
, unit_end
);
9694 printf (_("[%3u] 0x%lx\n"), i
, (unsigned long) tu_offset
);
9698 printf (_("Foreign TU table:\n"));
9699 for (i
= 0; i
< foreign_type_unit_count
; i
++)
9703 SAFE_BYTE_GET_AND_INC (signature
, hdrptr
, 8, unit_end
);
9704 printf (_("[%3u] "), i
);
9705 print_dwarf_vma (signature
, 8);
9710 const uint32_t *const hash_table_buckets
= (uint32_t *) hdrptr
;
9711 hdrptr
+= bucket_count
* sizeof (uint32_t);
9712 const uint32_t *const hash_table_hashes
= (uint32_t *) hdrptr
;
9713 hdrptr
+= name_count
* sizeof (uint32_t);
9714 unsigned char *const name_table_string_offsets
= hdrptr
;
9715 hdrptr
+= name_count
* offset_size
;
9716 unsigned char *const name_table_entry_offsets
= hdrptr
;
9717 hdrptr
+= name_count
* offset_size
;
9718 unsigned char *const abbrev_table
= hdrptr
;
9719 hdrptr
+= abbrev_table_size
;
9720 const unsigned char *const abbrev_table_end
= hdrptr
;
9721 unsigned char *const entry_pool
= hdrptr
;
9722 if (hdrptr
> unit_end
)
9724 warn (_("Entry pool offset (0x%lx) exceeds unit size 0x%lx "
9725 "for unit 0x%lx in the debug_names\n"),
9726 (long) (hdrptr
- section
->start
),
9727 (long) (unit_end
- section
->start
),
9728 (long) (unit_start
- section
->start
));
9732 size_t buckets_filled
= 0;
9734 for (bucketi
= 0; bucketi
< bucket_count
; bucketi
++)
9736 const uint32_t bucket
= hash_table_buckets
[bucketi
];
9741 printf (ngettext ("Used %zu of %lu bucket.\n",
9742 "Used %zu of %lu buckets.\n",
9744 buckets_filled
, (unsigned long) bucket_count
);
9746 uint32_t hash_prev
= 0;
9747 size_t hash_clash_count
= 0;
9748 size_t longest_clash
= 0;
9749 size_t this_length
= 0;
9751 for (hashi
= 0; hashi
< name_count
; hashi
++)
9753 const uint32_t hash_this
= hash_table_hashes
[hashi
];
9757 if (hash_prev
% bucket_count
== hash_this
% bucket_count
)
9761 longest_clash
= MAX (longest_clash
, this_length
);
9766 hash_prev
= hash_this
;
9768 printf (_("Out of %lu items there are %zu bucket clashes"
9769 " (longest of %zu entries).\n"),
9770 (unsigned long) name_count
, hash_clash_count
, longest_clash
);
9771 assert (name_count
== buckets_filled
+ hash_clash_count
);
9773 struct abbrev_lookup_entry
9775 dwarf_vma abbrev_tag
;
9776 unsigned char *abbrev_lookup_ptr
;
9778 struct abbrev_lookup_entry
*abbrev_lookup
= NULL
;
9779 size_t abbrev_lookup_used
= 0;
9780 size_t abbrev_lookup_allocated
= 0;
9782 unsigned char *abbrevptr
= abbrev_table
;
9785 dwarf_vma abbrev_tag
;
9787 READ_ULEB (abbrev_tag
, abbrevptr
, abbrev_table_end
);
9788 if (abbrev_tag
== 0)
9790 if (abbrev_lookup_used
== abbrev_lookup_allocated
)
9792 abbrev_lookup_allocated
= MAX (0x100,
9793 abbrev_lookup_allocated
* 2);
9794 abbrev_lookup
= xrealloc (abbrev_lookup
,
9795 (abbrev_lookup_allocated
9796 * sizeof (*abbrev_lookup
)));
9798 assert (abbrev_lookup_used
< abbrev_lookup_allocated
);
9799 struct abbrev_lookup_entry
*entry
;
9800 for (entry
= abbrev_lookup
;
9801 entry
< abbrev_lookup
+ abbrev_lookup_used
;
9803 if (entry
->abbrev_tag
== abbrev_tag
)
9805 warn (_("Duplicate abbreviation tag %lu "
9806 "in unit 0x%lx in the debug_names\n"),
9807 (long) abbrev_tag
, (long) (unit_start
- section
->start
));
9810 entry
= &abbrev_lookup
[abbrev_lookup_used
++];
9811 entry
->abbrev_tag
= abbrev_tag
;
9812 entry
->abbrev_lookup_ptr
= abbrevptr
;
9814 /* Skip DWARF tag. */
9815 SKIP_ULEB (abbrevptr
, abbrev_table_end
);
9818 dwarf_vma xindex
, form
;
9820 READ_ULEB (xindex
, abbrevptr
, abbrev_table_end
);
9821 READ_ULEB (form
, abbrevptr
, abbrev_table_end
);
9822 if (xindex
== 0 && form
== 0)
9827 printf (_("\nSymbol table:\n"));
9829 for (namei
= 0; namei
< name_count
; ++namei
)
9831 uint64_t string_offset
, entry_offset
;
9833 SAFE_BYTE_GET (string_offset
,
9834 name_table_string_offsets
+ namei
* offset_size
,
9835 offset_size
, unit_end
);
9836 SAFE_BYTE_GET (entry_offset
,
9837 name_table_entry_offsets
+ namei
* offset_size
,
9838 offset_size
, unit_end
);
9840 printf ("[%3u] #%08x %s:", namei
, hash_table_hashes
[namei
],
9841 fetch_indirect_string (string_offset
));
9843 unsigned char *entryptr
= entry_pool
+ entry_offset
;
9845 /* We need to scan first whether there is a single or multiple
9846 entries. TAGNO is -2 for the first entry, it is -1 for the
9847 initial tag read of the second entry, then it becomes 0 for the
9848 first entry for real printing etc. */
9850 /* Initialize it due to a false compiler warning. */
9851 dwarf_vma second_abbrev_tag
= -1;
9854 dwarf_vma abbrev_tag
;
9855 dwarf_vma dwarf_tag
;
9856 const struct abbrev_lookup_entry
*entry
;
9858 READ_ULEB (abbrev_tag
, entryptr
, unit_end
);
9861 second_abbrev_tag
= abbrev_tag
;
9863 entryptr
= entry_pool
+ entry_offset
;
9866 if (abbrev_tag
== 0)
9870 (tagno
== 0 && second_abbrev_tag
== 0 ? " " : "\n\t"),
9871 (unsigned long) abbrev_tag
);
9873 for (entry
= abbrev_lookup
;
9874 entry
< abbrev_lookup
+ abbrev_lookup_used
;
9876 if (entry
->abbrev_tag
== abbrev_tag
)
9878 if (entry
>= abbrev_lookup
+ abbrev_lookup_used
)
9880 warn (_("Undefined abbreviation tag %lu "
9881 "in unit 0x%lx in the debug_names\n"),
9883 (long) (unit_start
- section
->start
));
9886 abbrevptr
= entry
->abbrev_lookup_ptr
;
9887 READ_ULEB (dwarf_tag
, abbrevptr
, abbrev_table_end
);
9889 printf (" %s", get_TAG_name (dwarf_tag
));
9892 dwarf_vma xindex
, form
;
9894 READ_ULEB (xindex
, abbrevptr
, abbrev_table_end
);
9895 READ_ULEB (form
, abbrevptr
, abbrev_table_end
);
9896 if (xindex
== 0 && form
== 0)
9900 printf (" %s", get_IDX_name (xindex
));
9901 entryptr
= read_and_display_attr_value (0, form
, 0,
9902 unit_start
, entryptr
, unit_end
,
9904 dwarf_version
, NULL
,
9911 printf (_(" <no entries>"));
9915 free (abbrev_lookup
);
9922 display_debug_links (struct dwarf_section
* section
,
9923 void * file ATTRIBUTE_UNUSED
)
9925 const unsigned char * filename
;
9926 unsigned int filelen
;
9928 introduce (section
, false);
9930 /* The .gnu_debuglink section is formatted as:
9931 (c-string) Filename.
9932 (padding) If needed to reach a 4 byte boundary.
9933 (uint32_t) CRC32 value.
9935 The .gun_debugaltlink section is formatted as:
9936 (c-string) Filename.
9937 (binary) Build-ID. */
9939 filename
= section
->start
;
9940 filelen
= strnlen ((const char *) filename
, section
->size
);
9941 if (filelen
== section
->size
)
9943 warn (_("The debuglink filename is corrupt/missing\n"));
9947 printf (_(" Separate debug info file: %s\n"), filename
);
9949 if (startswith (section
->name
, ".gnu_debuglink"))
9952 unsigned int crc_offset
;
9954 crc_offset
= filelen
+ 1;
9955 crc_offset
= (crc_offset
+ 3) & ~3;
9956 if (crc_offset
+ 4 > section
->size
)
9958 warn (_("CRC offset missing/truncated\n"));
9962 crc32
= byte_get (filename
+ crc_offset
, 4);
9964 printf (_(" CRC value: %#x\n"), crc32
);
9966 if (crc_offset
+ 4 < section
->size
)
9968 warn (_("There are %#lx extraneous bytes at the end of the section\n"),
9969 (long)(section
->size
- (crc_offset
+ 4)));
9973 else /* startswith (section->name, ".gnu_debugaltlink") */
9975 const unsigned char * build_id
= section
->start
+ filelen
+ 1;
9976 bfd_size_type build_id_len
= section
->size
- (filelen
+ 1);
9977 bfd_size_type printed
;
9979 /* FIXME: Should we support smaller build-id notes ? */
9980 if (build_id_len
< 0x14)
9982 warn (_("Build-ID is too short (%#lx bytes)\n"), (long) build_id_len
);
9986 printed
= printf (_(" Build-ID (%#lx bytes):"), (long) build_id_len
);
9987 display_data (printed
, build_id
, build_id_len
);
9996 display_gdb_index (struct dwarf_section
*section
,
9997 void *file ATTRIBUTE_UNUSED
)
9999 unsigned char *start
= section
->start
;
10001 uint32_t cu_list_offset
, tu_list_offset
;
10002 uint32_t address_table_offset
, symbol_table_offset
, constant_pool_offset
;
10003 unsigned int cu_list_elements
, tu_list_elements
;
10004 unsigned int address_table_size
, symbol_table_slots
;
10005 unsigned char *cu_list
, *tu_list
;
10006 unsigned char *address_table
, *symbol_table
, *constant_pool
;
10009 /* The documentation for the format of this file is in gdb/dwarf2read.c. */
10011 introduce (section
, false);
10013 if (section
->size
< 6 * sizeof (uint32_t))
10015 warn (_("Truncated header in the %s section.\n"), section
->name
);
10019 version
= byte_get_little_endian (start
, 4);
10020 printf (_("Version %ld\n"), (long) version
);
10022 /* Prior versions are obsolete, and future versions may not be
10023 backwards compatible. */
10024 if (version
< 3 || version
> 8)
10026 warn (_("Unsupported version %lu.\n"), (unsigned long) version
);
10030 warn (_("The address table data in version 3 may be wrong.\n"));
10032 warn (_("Version 4 does not support case insensitive lookups.\n"));
10034 warn (_("Version 5 does not include inlined functions.\n"));
10036 warn (_("Version 6 does not include symbol attributes.\n"));
10037 /* Version 7 indices generated by Gold have bad type unit references,
10038 PR binutils/15021. But we don't know if the index was generated by
10039 Gold or not, so to avoid worrying users with gdb-generated indices
10040 we say nothing for version 7 here. */
10042 cu_list_offset
= byte_get_little_endian (start
+ 4, 4);
10043 tu_list_offset
= byte_get_little_endian (start
+ 8, 4);
10044 address_table_offset
= byte_get_little_endian (start
+ 12, 4);
10045 symbol_table_offset
= byte_get_little_endian (start
+ 16, 4);
10046 constant_pool_offset
= byte_get_little_endian (start
+ 20, 4);
10048 if (cu_list_offset
> section
->size
10049 || tu_list_offset
> section
->size
10050 || address_table_offset
> section
->size
10051 || symbol_table_offset
> section
->size
10052 || constant_pool_offset
> section
->size
)
10054 warn (_("Corrupt header in the %s section.\n"), section
->name
);
10058 /* PR 17531: file: 418d0a8a. */
10059 if (tu_list_offset
< cu_list_offset
)
10061 warn (_("TU offset (%x) is less than CU offset (%x)\n"),
10062 tu_list_offset
, cu_list_offset
);
10066 cu_list_elements
= (tu_list_offset
- cu_list_offset
) / 8;
10068 if (address_table_offset
< tu_list_offset
)
10070 warn (_("Address table offset (%x) is less than TU offset (%x)\n"),
10071 address_table_offset
, tu_list_offset
);
10075 tu_list_elements
= (address_table_offset
- tu_list_offset
) / 8;
10077 /* PR 17531: file: 18a47d3d. */
10078 if (symbol_table_offset
< address_table_offset
)
10080 warn (_("Symbol table offset (%x) is less then Address table offset (%x)\n"),
10081 symbol_table_offset
, address_table_offset
);
10085 address_table_size
= symbol_table_offset
- address_table_offset
;
10087 if (constant_pool_offset
< symbol_table_offset
)
10089 warn (_("Constant pool offset (%x) is less than symbol table offset (%x)\n"),
10090 constant_pool_offset
, symbol_table_offset
);
10094 symbol_table_slots
= (constant_pool_offset
- symbol_table_offset
) / 8;
10096 cu_list
= start
+ cu_list_offset
;
10097 tu_list
= start
+ tu_list_offset
;
10098 address_table
= start
+ address_table_offset
;
10099 symbol_table
= start
+ symbol_table_offset
;
10100 constant_pool
= start
+ constant_pool_offset
;
10102 if (address_table
+ address_table_size
> section
->start
+ section
->size
)
10104 warn (_("Address table extends beyond end of section.\n"));
10108 printf (_("\nCU table:\n"));
10109 for (i
= 0; i
< cu_list_elements
; i
+= 2)
10111 uint64_t cu_offset
= byte_get_little_endian (cu_list
+ i
* 8, 8);
10112 uint64_t cu_length
= byte_get_little_endian (cu_list
+ i
* 8 + 8, 8);
10114 printf (_("[%3u] 0x%lx - 0x%lx\n"), i
/ 2,
10115 (unsigned long) cu_offset
,
10116 (unsigned long) (cu_offset
+ cu_length
- 1));
10119 printf (_("\nTU table:\n"));
10120 for (i
= 0; i
< tu_list_elements
; i
+= 3)
10122 uint64_t tu_offset
= byte_get_little_endian (tu_list
+ i
* 8, 8);
10123 uint64_t type_offset
= byte_get_little_endian (tu_list
+ i
* 8 + 8, 8);
10124 uint64_t signature
= byte_get_little_endian (tu_list
+ i
* 8 + 16, 8);
10126 printf (_("[%3u] 0x%lx 0x%lx "), i
/ 3,
10127 (unsigned long) tu_offset
,
10128 (unsigned long) type_offset
);
10129 print_dwarf_vma (signature
, 8);
10133 printf (_("\nAddress table:\n"));
10134 for (i
= 0; i
< address_table_size
&& i
<= address_table_size
- (2 * 8 + 4);
10137 uint64_t low
= byte_get_little_endian (address_table
+ i
, 8);
10138 uint64_t high
= byte_get_little_endian (address_table
+ i
+ 8, 8);
10139 uint32_t cu_index
= byte_get_little_endian (address_table
+ i
+ 16, 4);
10141 print_dwarf_vma (low
, 8);
10142 print_dwarf_vma (high
, 8);
10143 printf (_("%lu\n"), (unsigned long) cu_index
);
10146 printf (_("\nSymbol table:\n"));
10147 for (i
= 0; i
< symbol_table_slots
; ++i
)
10149 uint32_t name_offset
= byte_get_little_endian (symbol_table
+ i
* 8, 4);
10150 uint32_t cu_vector_offset
= byte_get_little_endian (symbol_table
+ i
* 8 + 4, 4);
10151 uint32_t num_cus
, cu
;
10153 if (name_offset
!= 0
10154 || cu_vector_offset
!= 0)
10157 unsigned char * adr
;
10159 adr
= constant_pool
+ name_offset
;
10160 /* PR 17531: file: 5b7b07ad. */
10161 if (adr
< constant_pool
|| adr
>= section
->start
+ section
->size
)
10163 printf (_("[%3u] <corrupt offset: %x>"), i
, name_offset
);
10164 warn (_("Corrupt name offset of 0x%x found for symbol table slot %d\n"),
10168 printf ("[%3u] %.*s:", i
,
10169 (int) (section
->size
- (constant_pool_offset
+ name_offset
)),
10170 constant_pool
+ name_offset
);
10172 adr
= constant_pool
+ cu_vector_offset
;
10173 if (adr
< constant_pool
|| adr
>= section
->start
+ section
->size
- 3)
10175 printf (_("<invalid CU vector offset: %x>\n"), cu_vector_offset
);
10176 warn (_("Corrupt CU vector offset of 0x%x found for symbol table slot %d\n"),
10177 cu_vector_offset
, i
);
10181 num_cus
= byte_get_little_endian (adr
, 4);
10183 adr
= constant_pool
+ cu_vector_offset
+ 4 + num_cus
* 4;
10184 if (num_cus
* 4 < num_cus
10185 || adr
>= section
->start
+ section
->size
10186 || adr
< constant_pool
)
10188 printf ("<invalid number of CUs: %d>\n", num_cus
);
10189 warn (_("Invalid number of CUs (0x%x) for symbol table slot %d\n"),
10197 for (j
= 0; j
< num_cus
; ++j
)
10200 gdb_index_symbol_kind kind
;
10202 cu
= byte_get_little_endian (constant_pool
+ cu_vector_offset
+ 4 + j
* 4, 4);
10203 is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu
);
10204 kind
= GDB_INDEX_SYMBOL_KIND_VALUE (cu
);
10205 cu
= GDB_INDEX_CU_VALUE (cu
);
10206 /* Convert to TU number if it's for a type unit. */
10207 if (cu
>= cu_list_elements
/ 2)
10208 printf ("%cT%lu", num_cus
> 1 ? '\t' : ' ',
10209 (unsigned long) (cu
- cu_list_elements
/ 2));
10211 printf ("%c%lu", num_cus
> 1 ? '\t' : ' ', (unsigned long) cu
);
10213 printf (" [%s, %s]",
10214 is_static
? _("static") : _("global"),
10215 get_gdb_index_symbol_kind_name (kind
));
10227 /* Pre-allocate enough space for the CU/TU sets needed. */
10230 prealloc_cu_tu_list (unsigned int nshndx
)
10232 if (shndx_pool
== NULL
)
10234 shndx_pool_size
= nshndx
;
10235 shndx_pool_used
= 0;
10236 shndx_pool
= (unsigned int *) xcmalloc (shndx_pool_size
,
10237 sizeof (unsigned int));
10241 shndx_pool_size
= shndx_pool_used
+ nshndx
;
10242 shndx_pool
= (unsigned int *) xcrealloc (shndx_pool
, shndx_pool_size
,
10243 sizeof (unsigned int));
10248 add_shndx_to_cu_tu_entry (unsigned int shndx
)
10250 if (shndx_pool_used
>= shndx_pool_size
)
10252 error (_("Internal error: out of space in the shndx pool.\n"));
10255 shndx_pool
[shndx_pool_used
++] = shndx
;
10259 end_cu_tu_entry (void)
10261 if (shndx_pool_used
>= shndx_pool_size
)
10263 error (_("Internal error: out of space in the shndx pool.\n"));
10266 shndx_pool
[shndx_pool_used
++] = 0;
10269 /* Return the short name of a DWARF section given by a DW_SECT enumerator. */
10271 static const char *
10272 get_DW_SECT_short_name (unsigned int dw_sect
)
10274 static char buf
[16];
10280 case DW_SECT_TYPES
:
10282 case DW_SECT_ABBREV
:
10288 case DW_SECT_STR_OFFSETS
:
10290 case DW_SECT_MACINFO
:
10292 case DW_SECT_MACRO
:
10298 snprintf (buf
, sizeof (buf
), "%d", dw_sect
);
10302 /* Process a CU or TU index. If DO_DISPLAY is true, print the contents.
10303 These sections are extensions for Fission.
10304 See http://gcc.gnu.org/wiki/DebugFissionDWP. */
10307 process_cu_tu_index (struct dwarf_section
*section
, int do_display
)
10309 unsigned char *phdr
= section
->start
;
10310 unsigned char *limit
= phdr
+ section
->size
;
10311 unsigned char *phash
;
10312 unsigned char *pindex
;
10313 unsigned char *ppool
;
10314 unsigned int version
;
10315 unsigned int ncols
= 0;
10316 unsigned int nused
;
10317 unsigned int nslots
;
10320 dwarf_vma signature
;
10322 /* PR 17512: file: 002-168123-0.004. */
10325 warn (_("Section %s is empty\n"), section
->name
);
10328 /* PR 17512: file: 002-376-0.004. */
10329 if (section
->size
< 24)
10331 warn (_("Section %s is too small to contain a CU/TU header\n"),
10336 SAFE_BYTE_GET (version
, phdr
, 4, limit
);
10338 SAFE_BYTE_GET (ncols
, phdr
+ 4, 4, limit
);
10339 SAFE_BYTE_GET (nused
, phdr
+ 8, 4, limit
);
10340 SAFE_BYTE_GET (nslots
, phdr
+ 12, 4, limit
);
10343 pindex
= phash
+ (size_t) nslots
* 8;
10344 ppool
= pindex
+ (size_t) nslots
* 4;
10348 introduce (section
, false);
10350 printf (_(" Version: %u\n"), version
);
10352 printf (_(" Number of columns: %u\n"), ncols
);
10353 printf (_(" Number of used entries: %u\n"), nused
);
10354 printf (_(" Number of slots: %u\n\n"), nslots
);
10357 /* PR 17531: file: 45d69832. */
10358 if ((size_t) nslots
* 8 / 8 != nslots
10359 || phash
< phdr
|| phash
> limit
10360 || pindex
< phash
|| pindex
> limit
10361 || ppool
< pindex
|| ppool
> limit
)
10363 warn (ngettext ("Section %s is too small for %u slot\n",
10364 "Section %s is too small for %u slots\n",
10366 section
->name
, nslots
);
10373 prealloc_cu_tu_list ((limit
- ppool
) / 4);
10374 for (i
= 0; i
< nslots
; i
++)
10376 unsigned char *shndx_list
;
10377 unsigned int shndx
;
10379 SAFE_BYTE_GET (signature
, phash
, 8, limit
);
10380 if (signature
!= 0)
10382 SAFE_BYTE_GET (j
, pindex
, 4, limit
);
10383 shndx_list
= ppool
+ j
* 4;
10384 /* PR 17531: file: 705e010d. */
10385 if (shndx_list
< ppool
)
10387 warn (_("Section index pool located before start of section\n"));
10392 printf (_(" [%3d] Signature: 0x%s Sections: "),
10393 i
, dwarf_vmatoa ("x", signature
));
10396 if (shndx_list
>= limit
)
10398 warn (_("Section %s too small for shndx pool\n"),
10402 SAFE_BYTE_GET (shndx
, shndx_list
, 4, limit
);
10406 printf (" %d", shndx
);
10408 add_shndx_to_cu_tu_entry (shndx
);
10414 end_cu_tu_entry ();
10420 else if (version
== 2)
10423 unsigned int dw_sect
;
10424 unsigned char *ph
= phash
;
10425 unsigned char *pi
= pindex
;
10426 unsigned char *poffsets
= ppool
+ (size_t) ncols
* 4;
10427 unsigned char *psizes
= poffsets
+ (size_t) nused
* ncols
* 4;
10428 unsigned char *pend
= psizes
+ (size_t) nused
* ncols
* 4;
10430 struct cu_tu_set
*this_set
= NULL
;
10432 unsigned char *prow
;
10434 is_tu_index
= strcmp (section
->name
, ".debug_tu_index") == 0;
10436 /* PR 17531: file: 0dd159bf.
10437 Check for integer overflow (can occur when size_t is 32-bit)
10438 with overlarge ncols or nused values. */
10440 && ((size_t) ncols
* 4 / 4 != ncols
10441 || (size_t) nused
* ncols
* 4 / ((size_t) ncols
* 4) != nused
10442 || poffsets
< ppool
|| poffsets
> limit
10443 || psizes
< poffsets
|| psizes
> limit
10444 || pend
< psizes
|| pend
> limit
))
10446 warn (_("Section %s too small for offset and size tables\n"),
10453 printf (_(" Offset table\n"));
10454 printf (" slot %-16s ",
10455 is_tu_index
? _("signature") : _("dwo_id"));
10462 tu_sets
= xcalloc2 (nused
, sizeof (struct cu_tu_set
));
10463 this_set
= tu_sets
;
10468 cu_sets
= xcalloc2 (nused
, sizeof (struct cu_tu_set
));
10469 this_set
= cu_sets
;
10475 for (j
= 0; j
< ncols
; j
++)
10477 SAFE_BYTE_GET (dw_sect
, ppool
+ j
* 4, 4, limit
);
10478 printf (" %8s", get_DW_SECT_short_name (dw_sect
));
10483 for (i
= 0; i
< nslots
; i
++)
10485 SAFE_BYTE_GET (signature
, ph
, 8, limit
);
10487 SAFE_BYTE_GET (row
, pi
, 4, limit
);
10490 /* PR 17531: file: a05f6ab3. */
10493 warn (_("Row index (%u) is larger than number of used entries (%u)\n"),
10500 size_t num_copy
= sizeof (uint64_t);
10502 /* PR 23064: Beware of buffer overflow. */
10503 if (ph
+ num_copy
< limit
)
10504 memcpy (&this_set
[row
- 1].signature
, ph
, num_copy
);
10507 warn (_("Signature (%p) extends beyond end of space in section\n"), ph
);
10512 prow
= poffsets
+ (row
- 1) * ncols
* 4;
10513 /* PR 17531: file: b8ce60a8. */
10514 if (prow
< poffsets
|| prow
> limit
)
10516 warn (_("Row index (%u) * num columns (%u) > space remaining in section\n"),
10522 printf (_(" [%3d] 0x%s"),
10523 i
, dwarf_vmatoa ("x", signature
));
10524 for (j
= 0; j
< ncols
; j
++)
10526 SAFE_BYTE_GET (val
, prow
+ j
* 4, 4, limit
);
10528 printf (" %8d", val
);
10531 SAFE_BYTE_GET (dw_sect
, ppool
+ j
* 4, 4, limit
);
10533 /* PR 17531: file: 10796eb3. */
10534 if (dw_sect
>= DW_SECT_MAX
)
10535 warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect
);
10537 this_set
[row
- 1].section_offsets
[dw_sect
] = val
;
10553 printf (_(" Size table\n"));
10554 printf (" slot %-16s ",
10555 is_tu_index
? _("signature") : _("dwo_id"));
10558 for (j
= 0; j
< ncols
; j
++)
10560 SAFE_BYTE_GET (val
, ppool
+ j
* 4, 4, limit
);
10562 printf (" %8s", get_DW_SECT_short_name (val
));
10568 for (i
= 0; i
< nslots
; i
++)
10570 SAFE_BYTE_GET (signature
, ph
, 8, limit
);
10572 SAFE_BYTE_GET (row
, pi
, 4, limit
);
10575 prow
= psizes
+ (row
- 1) * ncols
* 4;
10578 printf (_(" [%3d] 0x%s"),
10579 i
, dwarf_vmatoa ("x", signature
));
10581 for (j
= 0; j
< ncols
; j
++)
10583 SAFE_BYTE_GET (val
, prow
+ j
* 4, 4, limit
);
10585 printf (" %8d", val
);
10588 SAFE_BYTE_GET (dw_sect
, ppool
+ j
* 4, 4, limit
);
10589 if (dw_sect
>= DW_SECT_MAX
)
10590 warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect
);
10592 this_set
[row
- 1].section_sizes
[dw_sect
] = val
;
10604 else if (do_display
)
10605 printf (_(" Unsupported version (%d)\n"), version
);
10613 static int cu_tu_indexes_read
= -1; /* Tri-state variable. */
10615 /* Load the CU and TU indexes if present. This will build a list of
10616 section sets that we can use to associate a .debug_info.dwo section
10617 with its associated .debug_abbrev.dwo section in a .dwp file. */
10620 load_cu_tu_indexes (void *file
)
10622 /* If we have already loaded (or tried to load) the CU and TU indexes
10623 then do not bother to repeat the task. */
10624 if (cu_tu_indexes_read
== -1)
10626 cu_tu_indexes_read
= true;
10628 if (load_debug_section_with_follow (dwp_cu_index
, file
))
10629 if (! process_cu_tu_index (&debug_displays
[dwp_cu_index
].section
, 0))
10630 cu_tu_indexes_read
= false;
10632 if (load_debug_section_with_follow (dwp_tu_index
, file
))
10633 if (! process_cu_tu_index (&debug_displays
[dwp_tu_index
].section
, 0))
10634 cu_tu_indexes_read
= false;
10637 return (bool) cu_tu_indexes_read
;
10640 /* Find the set of sections that includes section SHNDX. */
10643 find_cu_tu_set (void *file
, unsigned int shndx
)
10647 if (! load_cu_tu_indexes (file
))
10650 /* Find SHNDX in the shndx pool. */
10651 for (i
= 0; i
< shndx_pool_used
; i
++)
10652 if (shndx_pool
[i
] == shndx
)
10655 if (i
>= shndx_pool_used
)
10658 /* Now backup to find the first entry in the set. */
10659 while (i
> 0 && shndx_pool
[i
- 1] != 0)
10662 return shndx_pool
+ i
;
10665 /* Display a .debug_cu_index or .debug_tu_index section. */
10668 display_cu_index (struct dwarf_section
*section
, void *file ATTRIBUTE_UNUSED
)
10670 return process_cu_tu_index (section
, 1);
10674 display_debug_not_supported (struct dwarf_section
*section
,
10675 void *file ATTRIBUTE_UNUSED
)
10677 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
10683 /* Like malloc, but takes two parameters like calloc.
10684 Verifies that the first parameter is not too large.
10685 Note: does *not* initialise the allocated memory to zero. */
10688 cmalloc (size_t nmemb
, size_t size
)
10690 /* Check for overflow. */
10691 if (nmemb
>= ~(size_t) 0 / size
)
10694 return xmalloc (nmemb
* size
);
10697 /* Like xmalloc, but takes two parameters like calloc.
10698 Verifies that the first parameter is not too large.
10699 Note: does *not* initialise the allocated memory to zero. */
10702 xcmalloc (size_t nmemb
, size_t size
)
10704 /* Check for overflow. */
10705 if (nmemb
>= ~(size_t) 0 / size
)
10708 _("Attempt to allocate an array with an excessive number of elements: 0x%lx\n"),
10713 return xmalloc (nmemb
* size
);
10716 /* Like xrealloc, but takes three parameters.
10717 Verifies that the second parameter is not too large.
10718 Note: does *not* initialise any new memory to zero. */
10721 xcrealloc (void *ptr
, size_t nmemb
, size_t size
)
10723 /* Check for overflow. */
10724 if (nmemb
>= ~(size_t) 0 / size
)
10726 error (_("Attempt to re-allocate an array with an excessive number of elements: 0x%lx\n"),
10731 return xrealloc (ptr
, nmemb
* size
);
10734 /* Like xcalloc, but verifies that the first parameter is not too large. */
10737 xcalloc2 (size_t nmemb
, size_t size
)
10739 /* Check for overflow. */
10740 if (nmemb
>= ~(size_t) 0 / size
)
10742 error (_("Attempt to allocate a zero'ed array with an excessive number of elements: 0x%lx\n"),
10747 return xcalloc (nmemb
, size
);
10750 static unsigned long
10751 calc_gnu_debuglink_crc32 (unsigned long crc
,
10752 const unsigned char * buf
,
10755 static const unsigned long crc32_table
[256] =
10757 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
10758 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
10759 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
10760 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
10761 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
10762 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
10763 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
10764 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
10765 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
10766 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
10767 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
10768 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
10769 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
10770 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
10771 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
10772 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
10773 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
10774 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
10775 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
10776 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
10777 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
10778 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
10779 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
10780 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
10781 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
10782 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
10783 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
10784 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
10785 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
10786 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
10787 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
10788 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
10789 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
10790 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
10791 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
10792 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
10793 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
10794 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
10795 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
10796 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
10797 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
10798 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
10799 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
10800 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
10801 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
10802 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
10803 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
10804 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
10805 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
10806 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
10807 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
10810 const unsigned char *end
;
10812 crc
= ~crc
& 0xffffffff;
10813 for (end
= buf
+ len
; buf
< end
; ++ buf
)
10814 crc
= crc32_table
[(crc
^ *buf
) & 0xff] ^ (crc
>> 8);
10815 return ~crc
& 0xffffffff;
10818 typedef bool (*check_func_type
) (const char *, void *);
10819 typedef const char *(* parse_func_type
) (struct dwarf_section
*, void *);
10822 check_gnu_debuglink (const char * pathname
, void * crc_pointer
)
10824 static unsigned char buffer
[8 * 1024];
10826 bfd_size_type count
;
10827 unsigned long crc
= 0;
10830 sep_data
= open_debug_file (pathname
);
10831 if (sep_data
== NULL
)
10834 /* Yes - we are opening the file twice... */
10835 f
= fopen (pathname
, "rb");
10838 /* Paranoia: This should never happen. */
10839 close_debug_file (sep_data
);
10840 warn (_("Unable to reopen separate debug info file: %s\n"), pathname
);
10844 while ((count
= fread (buffer
, 1, sizeof (buffer
), f
)) > 0)
10845 crc
= calc_gnu_debuglink_crc32 (crc
, buffer
, count
);
10849 if (crc
!= * (unsigned long *) crc_pointer
)
10851 close_debug_file (sep_data
);
10852 warn (_("Separate debug info file %s found, but CRC does not match - ignoring\n"),
10860 static const char *
10861 parse_gnu_debuglink (struct dwarf_section
* section
, void * data
)
10864 unsigned int crc_offset
;
10865 unsigned long * crc32
= (unsigned long *) data
;
10867 /* The name is first.
10868 The CRC value is stored after the filename, aligned up to 4 bytes. */
10869 name
= (const char *) section
->start
;
10871 crc_offset
= strnlen (name
, section
->size
) + 1;
10872 if (crc_offset
== 1)
10874 crc_offset
= (crc_offset
+ 3) & ~3;
10875 if (crc_offset
+ 4 > section
->size
)
10878 * crc32
= byte_get (section
->start
+ crc_offset
, 4);
10883 check_gnu_debugaltlink (const char * filename
, void * data ATTRIBUTE_UNUSED
)
10885 void * sep_data
= open_debug_file (filename
);
10887 if (sep_data
== NULL
)
10890 /* FIXME: We should now extract the build-id in the separate file
10896 typedef struct build_id_data
10899 const unsigned char * data
;
10902 static const char *
10903 parse_gnu_debugaltlink (struct dwarf_section
* section
, void * data
)
10906 bfd_size_type namelen
;
10907 bfd_size_type id_len
;
10908 Build_id_data
* build_id_data
;
10910 /* The name is first.
10911 The build-id follows immediately, with no padding, up to the section's end. */
10913 name
= (const char *) section
->start
;
10914 namelen
= strnlen (name
, section
->size
) + 1;
10917 if (namelen
>= section
->size
)
10920 id_len
= section
->size
- namelen
;
10924 build_id_data
= (Build_id_data
*) data
;
10925 build_id_data
->len
= id_len
;
10926 build_id_data
->data
= section
->start
+ namelen
;
10932 add_separate_debug_file (const char * filename
, void * handle
)
10934 separate_info
* i
= xmalloc (sizeof * i
);
10936 i
->filename
= filename
;
10937 i
->handle
= handle
;
10938 i
->next
= first_separate_info
;
10939 first_separate_info
= i
;
10942 #if HAVE_LIBDEBUGINFOD
10943 /* Query debuginfod servers for the target debuglink or debugaltlink
10944 file. If successful, store the path of the file in filename and
10945 return TRUE, otherwise return FALSE. */
10948 debuginfod_fetch_separate_debug_info (struct dwarf_section
* section
,
10952 size_t build_id_len
;
10953 unsigned char * build_id
;
10955 if (strcmp (section
->uncompressed_name
, ".gnu_debuglink") == 0)
10957 /* Get the build-id of file. */
10958 build_id
= get_build_id (file
);
10961 else if (strcmp (section
->uncompressed_name
, ".gnu_debugaltlink") == 0)
10963 /* Get the build-id of the debugaltlink file. */
10964 unsigned int filelen
;
10966 filelen
= strnlen ((const char *)section
->start
, section
->size
);
10967 if (filelen
== section
->size
)
10968 /* Corrupt debugaltlink. */
10971 build_id
= section
->start
+ filelen
+ 1;
10972 build_id_len
= section
->size
- (filelen
+ 1);
10974 if (build_id_len
== 0)
10983 debuginfod_client
* client
;
10985 client
= debuginfod_begin ();
10986 if (client
== NULL
)
10989 /* Query debuginfod servers for the target file. If found its path
10990 will be stored in filename. */
10991 fd
= debuginfod_find_debuginfo (client
, build_id
, build_id_len
, filename
);
10992 debuginfod_end (client
);
10994 /* Only free build_id if we allocated space for a hex string
10995 in get_build_id (). */
10996 if (build_id_len
== 0)
11001 /* File successfully retrieved. Close fd since we want to
11002 use open_debug_file () on filename instead. */
11013 load_separate_debug_info (const char * main_filename
,
11014 struct dwarf_section
* xlink
,
11015 parse_func_type parse_func
,
11016 check_func_type check_func
,
11018 void * file ATTRIBUTE_UNUSED
)
11020 const char * separate_filename
;
11021 char * debug_filename
;
11023 size_t canon_dirlen
;
11026 if ((separate_filename
= parse_func (xlink
, func_data
)) == NULL
)
11028 warn (_("Corrupt debuglink section: %s\n"),
11029 xlink
->name
? xlink
->name
: xlink
->uncompressed_name
);
11033 /* Attempt to locate the separate file.
11034 This should duplicate the logic in bfd/opncls.c:find_separate_debug_file(). */
11036 canon_dir
= lrealpath (main_filename
);
11038 for (canon_dirlen
= strlen (canon_dir
); canon_dirlen
> 0; canon_dirlen
--)
11039 if (IS_DIR_SEPARATOR (canon_dir
[canon_dirlen
- 1]))
11041 canon_dir
[canon_dirlen
] = '\0';
11044 #define DEBUGDIR "/lib/debug"
11046 #ifndef EXTRA_DEBUG_ROOT1
11047 #define EXTRA_DEBUG_ROOT1 "/usr/lib/debug"
11049 #ifndef EXTRA_DEBUG_ROOT2
11050 #define EXTRA_DEBUG_ROOT2 "/usr/lib/debug/usr"
11053 debug_filename
= (char *) malloc (strlen (DEBUGDIR
) + 1
11055 + strlen (".debug/")
11056 #ifdef EXTRA_DEBUG_ROOT1
11057 + strlen (EXTRA_DEBUG_ROOT1
)
11059 #ifdef EXTRA_DEBUG_ROOT2
11060 + strlen (EXTRA_DEBUG_ROOT2
)
11062 + strlen (separate_filename
)
11064 if (debug_filename
== NULL
)
11066 warn (_("Out of memory"));
11071 /* First try in the current directory. */
11072 sprintf (debug_filename
, "%s", separate_filename
);
11073 if (check_func (debug_filename
, func_data
))
11076 /* Then try in a subdirectory called .debug. */
11077 sprintf (debug_filename
, ".debug/%s", separate_filename
);
11078 if (check_func (debug_filename
, func_data
))
11081 /* Then try in the same directory as the original file. */
11082 sprintf (debug_filename
, "%s%s", canon_dir
, separate_filename
);
11083 if (check_func (debug_filename
, func_data
))
11086 /* And the .debug subdirectory of that directory. */
11087 sprintf (debug_filename
, "%s.debug/%s", canon_dir
, separate_filename
);
11088 if (check_func (debug_filename
, func_data
))
11091 #ifdef EXTRA_DEBUG_ROOT1
11092 /* Try the first extra debug file root. */
11093 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT1
, separate_filename
);
11094 if (check_func (debug_filename
, func_data
))
11097 /* Try the first extra debug file root. */
11098 sprintf (debug_filename
, "%s/%s/%s", EXTRA_DEBUG_ROOT1
, canon_dir
, separate_filename
);
11099 if (check_func (debug_filename
, func_data
))
11103 #ifdef EXTRA_DEBUG_ROOT2
11104 /* Try the second extra debug file root. */
11105 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT2
, separate_filename
);
11106 if (check_func (debug_filename
, func_data
))
11110 /* Then try in the global debug_filename directory. */
11111 strcpy (debug_filename
, DEBUGDIR
);
11112 dirlen
= strlen (DEBUGDIR
) - 1;
11113 if (dirlen
> 0 && DEBUGDIR
[dirlen
] != '/')
11114 strcat (debug_filename
, "/");
11115 strcat (debug_filename
, (const char *) separate_filename
);
11117 if (check_func (debug_filename
, func_data
))
11120 #if HAVE_LIBDEBUGINFOD
11122 char * tmp_filename
;
11124 if (debuginfod_fetch_separate_debug_info (xlink
,
11128 /* File successfully downloaded from server, replace
11129 debug_filename with the file's path. */
11130 free (debug_filename
);
11131 debug_filename
= tmp_filename
;
11137 if (do_debug_links
)
11139 /* Failed to find the file. */
11140 warn (_("could not find separate debug file '%s'\n"),
11141 separate_filename
);
11142 warn (_("tried: %s\n"), debug_filename
);
11144 #ifdef EXTRA_DEBUG_ROOT2
11145 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT2
,
11146 separate_filename
);
11147 warn (_("tried: %s\n"), debug_filename
);
11150 #ifdef EXTRA_DEBUG_ROOT1
11151 sprintf (debug_filename
, "%s/%s/%s", EXTRA_DEBUG_ROOT1
,
11152 canon_dir
, separate_filename
);
11153 warn (_("tried: %s\n"), debug_filename
);
11155 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT1
,
11156 separate_filename
);
11157 warn (_("tried: %s\n"), debug_filename
);
11160 sprintf (debug_filename
, "%s.debug/%s", canon_dir
,
11161 separate_filename
);
11162 warn (_("tried: %s\n"), debug_filename
);
11164 sprintf (debug_filename
, "%s%s", canon_dir
, separate_filename
);
11165 warn (_("tried: %s\n"), debug_filename
);
11167 sprintf (debug_filename
, ".debug/%s", separate_filename
);
11168 warn (_("tried: %s\n"), debug_filename
);
11170 sprintf (debug_filename
, "%s", separate_filename
);
11171 warn (_("tried: %s\n"), debug_filename
);
11173 #if HAVE_LIBDEBUGINFOD
11175 char *urls
= getenv (DEBUGINFOD_URLS_ENV_VAR
);
11179 warn (_("tried: DEBUGINFOD_URLS=%s\n"), urls
);
11185 free (debug_filename
);
11191 void * debug_handle
;
11193 /* Now open the file.... */
11194 if ((debug_handle
= open_debug_file (debug_filename
)) == NULL
)
11196 warn (_("failed to open separate debug file: %s\n"), debug_filename
);
11197 free (debug_filename
);
11201 /* FIXME: We do not check to see if there are any other separate debug info
11202 files that would also match. */
11204 if (do_debug_links
)
11205 printf (_("\n%s: Found separate debug info file: %s\n"), main_filename
, debug_filename
);
11206 add_separate_debug_file (debug_filename
, debug_handle
);
11208 /* Do not free debug_filename - it might be referenced inside
11209 the structure returned by open_debug_file(). */
11210 return debug_handle
;
11213 /* Attempt to load a separate dwarf object file. */
11216 load_dwo_file (const char * main_filename
, const char * name
, const char * dir
, const char * id ATTRIBUTE_UNUSED
)
11218 char * separate_filename
;
11219 void * separate_handle
;
11221 if (IS_ABSOLUTE_PATH (name
))
11222 separate_filename
= strdup (name
);
11224 /* FIXME: Skip adding / if dwo_dir ends in /. */
11225 separate_filename
= concat (dir
, "/", name
, NULL
);
11226 if (separate_filename
== NULL
)
11228 warn (_("Out of memory allocating dwo filename\n"));
11232 if ((separate_handle
= open_debug_file (separate_filename
)) == NULL
)
11234 warn (_("Unable to load dwo file: %s\n"), separate_filename
);
11235 free (separate_filename
);
11239 /* FIXME: We should check the dwo_id. */
11241 printf (_("%s: Found separate debug object file: %s\n\n"), main_filename
, separate_filename
);
11243 add_separate_debug_file (separate_filename
, separate_handle
);
11244 /* Note - separate_filename will be freed in free_debug_memory(). */
11245 return separate_handle
;
11249 load_debug_sup_file (const char * main_filename
, void * file
)
11251 if (! load_debug_section (debug_sup
, file
))
11252 return; /* No .debug_sup section. */
11254 struct dwarf_section
* section
;
11255 section
= & debug_displays
[debug_sup
].section
;
11256 assert (section
!= NULL
);
11258 if (section
->start
== NULL
|| section
->size
< 5)
11260 warn (_(".debug_sup section is corrupt/empty\n"));
11264 if (section
->start
[2] != 0)
11265 return; /* This is a supplementary file. */
11267 const char * filename
= (const char *) section
->start
+ 3;
11268 if (strnlen (filename
, section
->size
- 3) == section
->size
- 3)
11270 warn (_("filename in .debug_sup section is corrupt\n"));
11274 if (filename
[0] != '/' && strchr (main_filename
, '/'))
11279 new_len
= asprintf (& new_name
, "%.*s/%s",
11280 (int) (strrchr (main_filename
, '/') - main_filename
),
11285 warn (_("unable to construct path for supplementary debug file"));
11290 filename
= new_name
;
11294 /* PR 27796: Make sure that we pass a filename that can be free'd to
11295 add_separate_debug_file(). */
11296 filename
= strdup (filename
);
11297 if (filename
== NULL
)
11299 warn (_("out of memory constructing filename for .debug_sup link\n"));
11304 void * handle
= open_debug_file (filename
);
11305 if (handle
== NULL
)
11307 warn (_("unable to open file '%s' referenced from .debug_sup section\n"), filename
);
11308 free ((void *) filename
);
11312 printf (_("%s: Found supplementary debug file: %s\n\n"), main_filename
, filename
);
11314 /* FIXME: Compare the checksums, if present. */
11315 add_separate_debug_file (filename
, handle
);
11318 /* Load a debuglink section and/or a debugaltlink section, if either are present.
11319 Recursively check the loaded files for more of these sections.
11320 Also follow any links in .debug_sup sections.
11321 FIXME: Should also check for DWO_* entries in the newly loaded files. */
11324 check_for_and_load_links (void * file
, const char * filename
)
11326 void * handle
= NULL
;
11328 if (load_debug_section (gnu_debugaltlink
, file
))
11330 Build_id_data build_id_data
;
11332 handle
= load_separate_debug_info (filename
,
11333 & debug_displays
[gnu_debugaltlink
].section
,
11334 parse_gnu_debugaltlink
,
11335 check_gnu_debugaltlink
,
11340 assert (handle
== first_separate_info
->handle
);
11341 check_for_and_load_links (first_separate_info
->handle
,
11342 first_separate_info
->filename
);
11346 if (load_debug_section (gnu_debuglink
, file
))
11348 unsigned long crc32
;
11350 handle
= load_separate_debug_info (filename
,
11351 & debug_displays
[gnu_debuglink
].section
,
11352 parse_gnu_debuglink
,
11353 check_gnu_debuglink
,
11358 assert (handle
== first_separate_info
->handle
);
11359 check_for_and_load_links (first_separate_info
->handle
,
11360 first_separate_info
->filename
);
11364 load_debug_sup_file (filename
, file
);
11367 /* Load the separate debug info file(s) attached to FILE, if any exist.
11368 Returns TRUE if any were found, FALSE otherwise.
11369 If TRUE is returned then the linked list starting at first_separate_info
11370 will be populated with open file handles. */
11373 load_separate_debug_files (void * file
, const char * filename
)
11375 /* Skip this operation if we are not interested in debug links. */
11376 if (! do_follow_links
&& ! do_debug_links
)
11379 /* See if there are any dwo links. */
11380 if (load_debug_section (str
, file
)
11381 && load_debug_section (abbrev
, file
)
11382 && load_debug_section (info
, file
))
11386 if (process_debug_info (& debug_displays
[info
].section
, file
, abbrev
,
11389 bool introduced
= false;
11391 const char *dir
= NULL
;
11392 const char *id
= NULL
;
11393 const char *name
= NULL
;
11395 for (dwinfo
= first_dwo_info
; dwinfo
!= NULL
; dwinfo
= dwinfo
->next
)
11397 /* Accumulate NAME, DIR and ID fields. */
11398 switch (dwinfo
->type
)
11402 warn (_("Multiple DWO_NAMEs encountered for the same CU\n"));
11403 name
= dwinfo
->value
;
11407 /* There can be multiple DW_AT_comp_dir entries in a CU,
11408 so do not complain. */
11409 dir
= dwinfo
->value
;
11414 warn (_("multiple DWO_IDs encountered for the same CU\n"));
11415 id
= dwinfo
->value
;
11419 error (_("Unexpected DWO INFO type"));
11423 /* If we have reached the end of our list, or we are changing
11424 CUs, then display the information that we have accumulated
11427 && (dwinfo
->next
== NULL
11428 || dwinfo
->next
->cu_offset
!= dwinfo
->cu_offset
))
11430 if (do_debug_links
)
11434 printf (_("The %s section contains link(s) to dwo file(s):\n\n"),
11435 debug_displays
[info
].section
.uncompressed_name
);
11439 printf (_(" Name: %s\n"), name
);
11440 printf (_(" Directory: %s\n"), dir
? dir
: _("<not-found>"));
11442 display_data (printf (_(" ID: ")), (unsigned char *) id
, 8);
11444 printf (_(" ID: <not specified>\n"));
11448 if (do_follow_links
)
11449 load_dwo_file (filename
, name
, dir
, id
);
11451 name
= dir
= id
= NULL
;
11457 if (! do_follow_links
)
11458 /* The other debug links will be displayed by display_debug_links()
11459 so we do not need to do any further processing here. */
11462 /* FIXME: We do not check for the presence of both link sections in the same file. */
11463 /* FIXME: We do not check for the presence of multiple, same-name debuglink sections. */
11464 /* FIXME: We do not check for the presence of a dwo link as well as a debuglink. */
11466 check_for_and_load_links (file
, filename
);
11467 if (first_separate_info
!= NULL
)
11470 do_follow_links
= 0;
11475 free_debug_memory (void)
11479 free_all_abbrevs ();
11481 free (cu_abbrev_map
);
11482 cu_abbrev_map
= NULL
;
11483 next_free_abbrev_map_entry
= 0;
11487 shndx_pool_size
= 0;
11488 shndx_pool_used
= 0;
11496 memset (level_type_signed
, 0, sizeof level_type_signed
);
11497 cu_tu_indexes_read
= -1;
11499 for (i
= 0; i
< max
; i
++)
11500 free_debug_section ((enum dwarf_section_display_enum
) i
);
11502 if (debug_information
!= NULL
)
11504 for (i
= 0; i
< alloc_num_debug_info_entries
; i
++)
11506 if (debug_information
[i
].max_loc_offsets
)
11508 free (debug_information
[i
].loc_offsets
);
11509 free (debug_information
[i
].have_frame_base
);
11511 if (debug_information
[i
].max_range_lists
)
11512 free (debug_information
[i
].range_lists
);
11514 free (debug_information
);
11515 debug_information
= NULL
;
11516 alloc_num_debug_info_entries
= num_debug_info_entries
= 0;
11520 separate_info
* next
;
11522 for (d
= first_separate_info
; d
!= NULL
; d
= next
)
11524 close_debug_file (d
->handle
);
11525 free ((void *) d
->filename
);
11529 first_separate_info
= NULL
;
11535 dwarf_select_sections_by_names (const char *names
)
11539 const char * option
;
11543 debug_dump_long_opts
;
11545 static const debug_dump_long_opts opts_table
[] =
11547 /* Please keep this table alpha- sorted. */
11548 { "Ranges", & do_debug_ranges
, 1 },
11549 { "abbrev", & do_debug_abbrevs
, 1 },
11550 { "addr", & do_debug_addr
, 1 },
11551 { "aranges", & do_debug_aranges
, 1 },
11552 { "cu_index", & do_debug_cu_index
, 1 },
11553 { "decodedline", & do_debug_lines
, FLAG_DEBUG_LINES_DECODED
},
11554 { "follow-links", & do_follow_links
, 1 },
11555 { "frames", & do_debug_frames
, 1 },
11556 { "frames-interp", & do_debug_frames_interp
, 1 },
11557 /* The special .gdb_index section. */
11558 { "gdb_index", & do_gdb_index
, 1 },
11559 { "info", & do_debug_info
, 1 },
11560 { "line", & do_debug_lines
, FLAG_DEBUG_LINES_RAW
}, /* For backwards compatibility. */
11561 { "links", & do_debug_links
, 1 },
11562 { "loc", & do_debug_loc
, 1 },
11563 { "macro", & do_debug_macinfo
, 1 },
11564 { "no-follow-links", & do_follow_links
, 0 },
11565 { "pubnames", & do_debug_pubnames
, 1 },
11566 { "pubtypes", & do_debug_pubtypes
, 1 },
11567 /* This entry is for compatibility
11568 with earlier versions of readelf. */
11569 { "ranges", & do_debug_aranges
, 1 },
11570 { "rawline", & do_debug_lines
, FLAG_DEBUG_LINES_RAW
},
11571 { "str", & do_debug_str
, 1 },
11572 { "str-offsets", & do_debug_str_offsets
, 1 },
11573 /* These trace_* sections are used by Itanium VMS. */
11574 { "trace_abbrev", & do_trace_abbrevs
, 1 },
11575 { "trace_aranges", & do_trace_aranges
, 1 },
11576 { "trace_info", & do_trace_info
, 1 },
11585 const debug_dump_long_opts
* entry
;
11587 for (entry
= opts_table
; entry
->option
; entry
++)
11589 size_t len
= strlen (entry
->option
);
11591 if (strncmp (p
, entry
->option
, len
) == 0
11592 && (p
[len
] == ',' || p
[len
] == '\0'))
11594 * entry
->variable
= entry
->val
;
11596 /* The --debug-dump=frames-interp option also
11597 enables the --debug-dump=frames option. */
11598 if (do_debug_frames_interp
)
11599 do_debug_frames
= 1;
11606 if (entry
->option
== NULL
)
11608 warn (_("Unrecognized debug option '%s'\n"), p
);
11609 p
= strchr (p
, ',');
11620 dwarf_select_sections_by_letters (const char *letters
)
11622 unsigned int lindex
= 0;
11624 while (letters
[lindex
])
11625 switch (letters
[lindex
++])
11627 case 'A': do_debug_addr
= 1; break;
11628 case 'a': do_debug_abbrevs
= 1; break;
11629 case 'c': do_debug_cu_index
= 1; break;
11630 case 'F': do_debug_frames_interp
= 1; /* Fall through. */
11631 case 'f': do_debug_frames
= 1; break;
11632 case 'g': do_gdb_index
= 1; break;
11633 case 'i': do_debug_info
= 1; break;
11634 case 'K': do_follow_links
= 1; break;
11635 case 'N': do_follow_links
= 0; break;
11636 case 'k': do_debug_links
= 1; break;
11637 case 'l': do_debug_lines
|= FLAG_DEBUG_LINES_RAW
; break;
11638 case 'L': do_debug_lines
|= FLAG_DEBUG_LINES_DECODED
; break;
11639 case 'm': do_debug_macinfo
= 1; break;
11640 case 'O': do_debug_str_offsets
= 1; break;
11641 case 'o': do_debug_loc
= 1; break;
11642 case 'p': do_debug_pubnames
= 1; break;
11643 case 'R': do_debug_ranges
= 1; break;
11644 case 'r': do_debug_aranges
= 1; break;
11645 case 's': do_debug_str
= 1; break;
11646 case 'T': do_trace_aranges
= 1; break;
11647 case 't': do_debug_pubtypes
= 1; break;
11648 case 'U': do_trace_info
= 1; break;
11649 case 'u': do_trace_abbrevs
= 1; break;
11652 warn (_("Unrecognized debug option '%s'\n"), letters
);
11658 dwarf_select_sections_all (void)
11661 do_debug_abbrevs
= 1;
11662 do_debug_lines
= FLAG_DEBUG_LINES_RAW
;
11663 do_debug_pubnames
= 1;
11664 do_debug_pubtypes
= 1;
11665 do_debug_aranges
= 1;
11666 do_debug_ranges
= 1;
11667 do_debug_frames
= 1;
11668 do_debug_macinfo
= 1;
11673 do_trace_abbrevs
= 1;
11674 do_trace_aranges
= 1;
11676 do_debug_cu_index
= 1;
11677 do_follow_links
= 1;
11678 do_debug_links
= 1;
11679 do_debug_str_offsets
= 1;
11682 #define NO_ABBREVS NULL, NULL, NULL, 0, 0, 0, NULL, 0
11683 #define ABBREV(N) NULL, NULL, NULL, 0, 0, N, NULL, 0
11685 /* N.B. The order here must match the order in section_display_enum. */
11687 struct dwarf_section_display debug_displays
[] =
11689 { { ".debug_abbrev", ".zdebug_abbrev", NO_ABBREVS
}, display_debug_abbrev
, &do_debug_abbrevs
, false },
11690 { { ".debug_aranges", ".zdebug_aranges", NO_ABBREVS
}, display_debug_aranges
, &do_debug_aranges
, true },
11691 { { ".debug_frame", ".zdebug_frame", NO_ABBREVS
}, display_debug_frames
, &do_debug_frames
, true },
11692 { { ".debug_info", ".zdebug_info", ABBREV (abbrev
)}, display_debug_info
, &do_debug_info
, true },
11693 { { ".debug_line", ".zdebug_line", NO_ABBREVS
}, display_debug_lines
, &do_debug_lines
, true },
11694 { { ".debug_pubnames", ".zdebug_pubnames", NO_ABBREVS
}, display_debug_pubnames
, &do_debug_pubnames
, false },
11695 { { ".debug_gnu_pubnames", ".zdebug_gnu_pubnames", NO_ABBREVS
}, display_debug_gnu_pubnames
, &do_debug_pubnames
, false },
11696 { { ".eh_frame", "", NO_ABBREVS
}, display_debug_frames
, &do_debug_frames
, true },
11697 { { ".debug_macinfo", ".zdebug_macinfo", NO_ABBREVS
}, display_debug_macinfo
, &do_debug_macinfo
, false },
11698 { { ".debug_macro", ".zdebug_macro", NO_ABBREVS
}, display_debug_macro
, &do_debug_macinfo
, true },
11699 { { ".debug_str", ".zdebug_str", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, false },
11700 { { ".debug_line_str", ".zdebug_line_str", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, false },
11701 { { ".debug_loc", ".zdebug_loc", NO_ABBREVS
}, display_debug_loc
, &do_debug_loc
, true },
11702 { { ".debug_loclists", ".zdebug_loclists", NO_ABBREVS
}, display_debug_loc
, &do_debug_loc
, true },
11703 { { ".debug_pubtypes", ".zdebug_pubtypes", NO_ABBREVS
}, display_debug_pubnames
, &do_debug_pubtypes
, false },
11704 { { ".debug_gnu_pubtypes", ".zdebug_gnu_pubtypes", NO_ABBREVS
}, display_debug_gnu_pubnames
, &do_debug_pubtypes
, false },
11705 { { ".debug_ranges", ".zdebug_ranges", NO_ABBREVS
}, display_debug_ranges
, &do_debug_ranges
, true },
11706 { { ".debug_rnglists", ".zdebug_rnglists", NO_ABBREVS
}, display_debug_ranges
, &do_debug_ranges
, true },
11707 { { ".debug_static_func", ".zdebug_static_func", NO_ABBREVS
}, display_debug_not_supported
, NULL
, false },
11708 { { ".debug_static_vars", ".zdebug_static_vars", NO_ABBREVS
}, display_debug_not_supported
, NULL
, false },
11709 { { ".debug_types", ".zdebug_types", ABBREV (abbrev
) }, display_debug_types
, &do_debug_info
, true },
11710 { { ".debug_weaknames", ".zdebug_weaknames", NO_ABBREVS
}, display_debug_not_supported
, NULL
, false },
11711 { { ".gdb_index", "", NO_ABBREVS
}, display_gdb_index
, &do_gdb_index
, false },
11712 { { ".debug_names", "", NO_ABBREVS
}, display_debug_names
, &do_gdb_index
, false },
11713 { { ".trace_info", "", ABBREV (trace_abbrev
) }, display_trace_info
, &do_trace_info
, true },
11714 { { ".trace_abbrev", "", NO_ABBREVS
}, display_debug_abbrev
, &do_trace_abbrevs
, false },
11715 { { ".trace_aranges", "", NO_ABBREVS
}, display_debug_aranges
, &do_trace_aranges
, false },
11716 { { ".debug_info.dwo", ".zdebug_info.dwo", ABBREV (abbrev_dwo
) }, display_debug_info
, &do_debug_info
, true },
11717 { { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo", NO_ABBREVS
}, display_debug_abbrev
, &do_debug_abbrevs
, false },
11718 { { ".debug_types.dwo", ".zdebug_types.dwo", ABBREV (abbrev_dwo
) }, display_debug_types
, &do_debug_info
, true },
11719 { { ".debug_line.dwo", ".zdebug_line.dwo", NO_ABBREVS
}, display_debug_lines
, &do_debug_lines
, true },
11720 { { ".debug_loc.dwo", ".zdebug_loc.dwo", NO_ABBREVS
}, display_debug_loc
, &do_debug_loc
, true },
11721 { { ".debug_macro.dwo", ".zdebug_macro.dwo", NO_ABBREVS
}, display_debug_macro
, &do_debug_macinfo
, true },
11722 { { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo", NO_ABBREVS
}, display_debug_macinfo
, &do_debug_macinfo
, false },
11723 { { ".debug_str.dwo", ".zdebug_str.dwo", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, true },
11724 { { ".debug_str_offsets", ".zdebug_str_offsets", NO_ABBREVS
}, display_debug_str_offsets
, &do_debug_str_offsets
, true },
11725 { { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo", NO_ABBREVS
}, display_debug_str_offsets
, &do_debug_str_offsets
, true },
11726 { { ".debug_addr", ".zdebug_addr", NO_ABBREVS
}, display_debug_addr
, &do_debug_addr
, true },
11727 { { ".debug_cu_index", "", NO_ABBREVS
}, display_cu_index
, &do_debug_cu_index
, false },
11728 { { ".debug_tu_index", "", NO_ABBREVS
}, display_cu_index
, &do_debug_cu_index
, false },
11729 { { ".gnu_debuglink", "", NO_ABBREVS
}, display_debug_links
, &do_debug_links
, false },
11730 { { ".gnu_debugaltlink", "", NO_ABBREVS
}, display_debug_links
, &do_debug_links
, false },
11731 { { ".debug_sup", "", NO_ABBREVS
}, display_debug_sup
, &do_debug_links
, false },
11732 /* Separate debug info files can containt their own .debug_str section,
11733 and this might be in *addition* to a .debug_str section already present
11734 in the main file. Hence we need to have two entries for .debug_str. */
11735 { { ".debug_str", ".zdebug_str", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, false },
11738 /* A static assertion. */
11739 extern int debug_displays_assert
[ARRAY_SIZE (debug_displays
) == max
? 1 : -1];