1 /* dwarf.c -- display DWARF contents of a BFD binary file
2 Copyright (C) 2005-2022 Free Software Foundation, Inc.
4 This file is part of GNU Binutils.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
22 #include "libiberty.h"
27 #include "elf/common.h"
30 #include "gdb/gdb-index.h"
31 #include "filenames.h"
32 #include "safe-ctype.h"
35 #ifdef HAVE_LIBDEBUGINFOD
36 #include <elfutils/debuginfod.h>
44 #ifndef ENABLE_CHECKING
45 #define ENABLE_CHECKING 0
50 #define MAX(a, b) ((a) > (b) ? (a) : (b))
51 #define MIN(a, b) ((a) < (b) ? (a) : (b))
53 static const char *regname (unsigned int regno
, int row
);
54 static const char *regname_internal_by_table_only (unsigned int regno
);
56 static int have_frame_base
;
57 static int need_base_address
;
59 static unsigned int num_debug_info_entries
= 0;
60 static unsigned int alloc_num_debug_info_entries
= 0;
61 static debug_info
*debug_information
= NULL
;
62 /* Special value for num_debug_info_entries to indicate
63 that the .debug_info section could not be loaded/parsed. */
64 #define DEBUG_INFO_UNAVAILABLE (unsigned int) -1
66 /* A .debug_info section can contain multiple links to separate
67 DWO object files. We use these structures to record these links. */
75 typedef struct dwo_info
80 struct dwo_info
* next
;
83 static dwo_info
*first_dwo_info
= NULL
;
84 static bool need_dwo_info
;
86 separate_info
* first_separate_info
= NULL
;
88 unsigned int eh_addr_size
;
93 int do_debug_pubnames
;
94 int do_debug_pubtypes
;
98 int do_debug_frames_interp
;
101 int do_debug_str_offsets
;
105 int do_trace_abbrevs
;
106 int do_trace_aranges
;
108 int do_debug_cu_index
;
111 int do_follow_links
= DEFAULT_FOR_FOLLOW_LINKS
;
112 #ifdef HAVE_LIBDEBUGINFOD
113 int use_debuginfod
= 1;
117 int dwarf_cutoff_level
= -1;
118 unsigned long dwarf_start_die
;
122 /* Convenient constant, to avoid having to cast -1 to dwarf_vma when
123 testing whether e.g. a locview list is present. */
124 static const dwarf_vma vm1
= -1;
126 /* Collection of CU/TU section sets from .debug_cu_index and .debug_tu_index
127 sections. For version 1 package files, each set is stored in SHNDX_POOL
128 as a zero-terminated list of section indexes comprising one set of debug
129 sections from a .dwo file. */
131 static unsigned int *shndx_pool
= NULL
;
132 static unsigned int shndx_pool_size
= 0;
133 static unsigned int shndx_pool_used
= 0;
135 /* For version 2 package files, each set contains an array of section offsets
136 and an array of section sizes, giving the offset and size of the
137 contribution from a CU or TU within one of the debug sections.
138 When displaying debug info from a package file, we need to use these
139 tables to locate the corresponding contributions to each section. */
144 dwarf_vma section_offsets
[DW_SECT_MAX
];
145 size_t section_sizes
[DW_SECT_MAX
];
148 static int cu_count
= 0;
149 static int tu_count
= 0;
150 static struct cu_tu_set
*cu_sets
= NULL
;
151 static struct cu_tu_set
*tu_sets
= NULL
;
153 static bool load_cu_tu_indexes (void *);
155 /* An array that indicates for a given level of CU nesting whether
156 the latest DW_AT_type seen for that level was a signed type or
158 #define MAX_CU_NESTING (1 << 8)
159 static bool level_type_signed
[MAX_CU_NESTING
];
161 /* Values for do_debug_lines. */
162 #define FLAG_DEBUG_LINES_RAW 1
163 #define FLAG_DEBUG_LINES_DECODED 2
166 size_of_encoded_value (int encoding
)
168 switch (encoding
& 0x7)
171 case 0: return eh_addr_size
;
179 get_encoded_value (unsigned char **pdata
,
181 struct dwarf_section
*section
,
184 unsigned char * data
= * pdata
;
185 unsigned int size
= size_of_encoded_value (encoding
);
188 if (data
>= end
|| size
> (size_t) (end
- data
))
190 warn (_("Encoded value extends past end of section\n"));
195 /* PR 17512: file: 002-829853-0.004. */
198 warn (_("Encoded size of %d is too large to read\n"), size
);
203 /* PR 17512: file: 1085-5603-0.004. */
206 warn (_("Encoded size of 0 is too small to read\n"));
211 if (encoding
& DW_EH_PE_signed
)
212 val
= byte_get_signed (data
, size
);
214 val
= byte_get (data
, size
);
216 if ((encoding
& 0x70) == DW_EH_PE_pcrel
)
217 val
+= section
->address
+ (data
- section
->start
);
219 * pdata
= data
+ size
;
223 #if SIZEOF_LONG_LONG > SIZEOF_LONG
225 # define DWARF_VMA_FMT "ll"
226 # define DWARF_VMA_FMT_LONG "%16.16llx"
228 # define DWARF_VMA_FMT "I64"
229 # define DWARF_VMA_FMT_LONG "%016I64x"
232 # define DWARF_VMA_FMT "l"
233 # define DWARF_VMA_FMT_LONG "%16.16lx"
236 /* Convert a dwarf vma value into a string. Returns a pointer to a static
237 buffer containing the converted VALUE. The value is converted according
238 to the printf formating character FMTCH. If NUM_BYTES is non-zero then
239 it specifies the maximum number of bytes to be displayed in the converted
240 value and FMTCH is ignored - hex is always used. */
243 dwarf_vmatoa_1 (const char *fmtch
, dwarf_vma value
, unsigned num_bytes
)
245 /* As dwarf_vmatoa is used more then once in a printf call
246 for output, we are cycling through an fixed array of pointers
247 for return address. */
248 static int buf_pos
= 0;
249 static struct dwarf_vmatoa_buf
255 ret
= buf
[buf_pos
++].place
;
256 buf_pos
%= ARRAY_SIZE (buf
);
260 /* Printf does not have a way of specifying a maximum field width for an
261 integer value, so we print the full value into a buffer and then select
262 the precision we need. */
263 snprintf (ret
, sizeof (buf
[0].place
), DWARF_VMA_FMT_LONG
, value
);
266 return ret
+ (16 - 2 * num_bytes
);
273 sprintf (fmt
, "%%%s%s", DWARF_VMA_FMT
, fmtch
);
275 sprintf (fmt
, "%%%s", DWARF_VMA_FMT
);
276 snprintf (ret
, sizeof (buf
[0].place
), fmt
, value
);
281 static inline const char *
282 dwarf_vmatoa (const char * fmtch
, dwarf_vma value
)
284 return dwarf_vmatoa_1 (fmtch
, value
, 0);
287 /* Print a dwarf_vma value (typically an address, offset or length) in
288 hexadecimal format, followed by a space. The length of the VALUE (and
289 hence the precision displayed) is determined by the NUM_BYTES parameter. */
292 print_dwarf_vma (dwarf_vma value
, unsigned num_bytes
)
294 printf ("%s ", dwarf_vmatoa_1 (NULL
, value
, num_bytes
));
297 /* Print a view number in hexadecimal value, with the same width
298 print_dwarf_vma would have printed it with the same num_bytes.
299 Print blanks for zero view, unless force is nonzero. */
302 print_dwarf_view (dwarf_vma value
, unsigned num_bytes
, int force
)
310 assert (value
== (unsigned long) value
);
312 printf ("v%0*lx ", len
- 1, (unsigned long) value
);
314 printf ("%*s", len
+ 1, "");
317 /* Read in a LEB128 encoded value starting at address DATA.
318 If SIGN is true, return a signed LEB128 value.
319 If LENGTH_RETURN is not NULL, return in it the number of bytes read.
320 If STATUS_RETURN is not NULL, return with bit 0 (LSB) set if the
321 terminating byte was not found and with bit 1 set if the value
322 overflows a dwarf_vma.
323 No bytes will be read at address END or beyond. */
326 read_leb128 (unsigned char *data
,
327 const unsigned char *const end
,
329 unsigned int *length_return
,
332 dwarf_vma result
= 0;
333 unsigned int num_read
= 0;
334 unsigned int shift
= 0;
339 unsigned char byte
= *data
++;
340 unsigned char lost
, mask
;
344 if (shift
< CHAR_BIT
* sizeof (result
))
346 result
|= ((dwarf_vma
) (byte
& 0x7f)) << shift
;
347 /* These bits overflowed. */
348 lost
= byte
^ (result
>> shift
);
349 /* And this is the mask of possible overflow bits. */
350 mask
= 0x7f ^ ((dwarf_vma
) 0x7f << shift
>> shift
);
358 if ((lost
& mask
) != (sign
&& (dwarf_signed_vma
) result
< 0 ? mask
: 0))
361 if ((byte
& 0x80) == 0)
364 if (sign
&& shift
< CHAR_BIT
* sizeof (result
) && (byte
& 0x40))
365 result
|= -((dwarf_vma
) 1 << shift
);
370 if (length_return
!= NULL
)
371 *length_return
= num_read
;
372 if (status_return
!= NULL
)
373 *status_return
= status
;
378 /* Read AMOUNT bytes from PTR and store them in VAL.
379 Checks to make sure that the read will not reach or pass END.
380 FUNC chooses whether the value read is unsigned or signed, and may
381 be either byte_get or byte_get_signed. If INC is true, PTR is
382 incremented after reading the value.
383 This macro cannot protect against PTR values derived from user input.
384 The C standard sections 6.5.6 and 6.5.8 say attempts to do so using
385 pointers is undefined behaviour. */
386 #define SAFE_BYTE_GET_INTERNAL(VAL, PTR, AMOUNT, END, FUNC, INC) \
389 size_t amount = (AMOUNT); \
390 if (sizeof (VAL) < amount) \
392 error (ngettext ("internal error: attempt to read %d byte " \
393 "of data in to %d sized variable", \
394 "internal error: attempt to read %d bytes " \
395 "of data in to %d sized variable", \
397 (int) amount, (int) sizeof (VAL)); \
398 amount = sizeof (VAL); \
400 if (ENABLE_CHECKING) \
401 assert ((PTR) <= (END)); \
402 size_t avail = (END) - (PTR); \
405 if (amount > avail) \
410 (VAL) = (FUNC) ((PTR), amount); \
416 #define SAFE_BYTE_GET(VAL, PTR, AMOUNT, END) \
417 SAFE_BYTE_GET_INTERNAL (VAL, PTR, AMOUNT, END, byte_get, false)
419 #define SAFE_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \
420 SAFE_BYTE_GET_INTERNAL (VAL, PTR, AMOUNT, END, byte_get, true)
422 #define SAFE_SIGNED_BYTE_GET(VAL, PTR, AMOUNT, END) \
423 SAFE_BYTE_GET_INTERNAL (VAL, PTR, AMOUNT, END, byte_get_signed, false)
425 #define SAFE_SIGNED_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \
426 SAFE_BYTE_GET_INTERNAL (VAL, PTR, AMOUNT, END, byte_get_signed, true)
428 typedef struct State_Machine_Registers
437 unsigned char op_index
;
438 unsigned char end_sequence
;
439 /* This variable hold the number of the last entry seen
440 in the File Table. */
441 unsigned int last_file_entry
;
444 static SMR state_machine_regs
;
447 reset_state_machine (int is_stmt
)
449 state_machine_regs
.address
= 0;
450 state_machine_regs
.view
= 0;
451 state_machine_regs
.op_index
= 0;
452 state_machine_regs
.file
= 1;
453 state_machine_regs
.line
= 1;
454 state_machine_regs
.column
= 0;
455 state_machine_regs
.is_stmt
= is_stmt
;
456 state_machine_regs
.basic_block
= 0;
457 state_machine_regs
.end_sequence
= 0;
458 state_machine_regs
.last_file_entry
= 0;
461 /* Handled an extend line op.
462 Returns the number of bytes read. */
465 process_extended_line_op (unsigned char * data
,
469 unsigned char op_code
;
470 size_t len
, header_len
;
472 unsigned char *orig_data
= data
;
475 READ_ULEB (len
, data
, end
);
476 header_len
= data
- orig_data
;
478 if (len
== 0 || data
>= end
|| len
> (size_t) (end
- data
))
480 warn (_("Badly formed extended line op encountered!\n"));
486 printf (_(" Extended opcode %d: "), op_code
);
490 case DW_LNE_end_sequence
:
491 printf (_("End of Sequence\n\n"));
492 reset_state_machine (is_stmt
);
495 case DW_LNE_set_address
:
496 /* PR 17512: file: 002-100480-0.004. */
499 warn (_("Length (%lu) of DW_LNE_set_address op is too long\n"),
500 (unsigned long) len
- 1);
504 SAFE_BYTE_GET (adr
, data
, len
- 1, end
);
505 printf (_("set Address to 0x%s\n"), dwarf_vmatoa ("x", adr
));
506 state_machine_regs
.address
= adr
;
507 state_machine_regs
.view
= 0;
508 state_machine_regs
.op_index
= 0;
511 case DW_LNE_define_file
:
512 printf (_("define new File Table entry\n"));
513 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
514 printf (" %d\t", ++state_machine_regs
.last_file_entry
);
520 l
= strnlen ((char *) data
, end
- data
);
524 READ_ULEB (val
, data
, end
);
525 printf ("%s\t", dwarf_vmatoa ("u", val
));
526 READ_ULEB (val
, data
, end
);
527 printf ("%s\t", dwarf_vmatoa ("u", val
));
528 READ_ULEB (val
, data
, end
);
529 printf ("%s\t", dwarf_vmatoa ("u", val
));
530 printf ("%.*s\n\n", (int) l
, name
);
533 if (((size_t) (data
- orig_data
) != len
+ header_len
) || data
>= end
)
534 warn (_("DW_LNE_define_file: Bad opcode length\n"));
537 case DW_LNE_set_discriminator
:
538 READ_ULEB (val
, data
, end
);
539 printf (_("set Discriminator to %s\n"), dwarf_vmatoa ("u", val
));
543 case DW_LNE_HP_negate_is_UV_update
:
544 printf ("DW_LNE_HP_negate_is_UV_update\n");
546 case DW_LNE_HP_push_context
:
547 printf ("DW_LNE_HP_push_context\n");
549 case DW_LNE_HP_pop_context
:
550 printf ("DW_LNE_HP_pop_context\n");
552 case DW_LNE_HP_set_file_line_column
:
553 printf ("DW_LNE_HP_set_file_line_column\n");
555 case DW_LNE_HP_set_routine_name
:
556 printf ("DW_LNE_HP_set_routine_name\n");
558 case DW_LNE_HP_set_sequence
:
559 printf ("DW_LNE_HP_set_sequence\n");
561 case DW_LNE_HP_negate_post_semantics
:
562 printf ("DW_LNE_HP_negate_post_semantics\n");
564 case DW_LNE_HP_negate_function_exit
:
565 printf ("DW_LNE_HP_negate_function_exit\n");
567 case DW_LNE_HP_negate_front_end_logical
:
568 printf ("DW_LNE_HP_negate_front_end_logical\n");
570 case DW_LNE_HP_define_proc
:
571 printf ("DW_LNE_HP_define_proc\n");
573 case DW_LNE_HP_source_file_correlation
:
575 unsigned char *edata
= data
+ len
- 1;
577 printf ("DW_LNE_HP_source_file_correlation\n");
583 READ_ULEB (opc
, data
, edata
);
587 case DW_LNE_HP_SFC_formfeed
:
588 printf (" DW_LNE_HP_SFC_formfeed\n");
590 case DW_LNE_HP_SFC_set_listing_line
:
591 READ_ULEB (val
, data
, edata
);
592 printf (" DW_LNE_HP_SFC_set_listing_line (%s)\n",
593 dwarf_vmatoa ("u", val
));
595 case DW_LNE_HP_SFC_associate
:
596 printf (" DW_LNE_HP_SFC_associate ");
597 READ_ULEB (val
, data
, edata
);
598 printf ("(%s", dwarf_vmatoa ("u", val
));
599 READ_ULEB (val
, data
, edata
);
600 printf (",%s", dwarf_vmatoa ("u", val
));
601 READ_ULEB (val
, data
, edata
);
602 printf (",%s)\n", dwarf_vmatoa ("u", val
));
605 printf (_(" UNKNOWN DW_LNE_HP_SFC opcode (%u)\n"), opc
);
615 unsigned int rlen
= len
- 1;
617 if (op_code
>= DW_LNE_lo_user
618 /* The test against DW_LNW_hi_user is redundant due to
619 the limited range of the unsigned char data type used
621 /*&& op_code <= DW_LNE_hi_user*/)
622 printf (_("user defined: "));
624 printf (_("UNKNOWN: "));
625 printf (_("length %d ["), rlen
);
627 printf (" %02x", *data
++);
633 return len
+ header_len
;
636 static const unsigned char *
637 fetch_indirect_string (dwarf_vma offset
)
639 struct dwarf_section
*section
= &debug_displays
[str
].section
;
640 const unsigned char * ret
;
642 if (section
->start
== NULL
)
643 return (const unsigned char *) _("<no .debug_str section>");
645 if (offset
>= section
->size
)
647 warn (_("DW_FORM_strp offset too big: 0x%s\n"),
648 dwarf_vmatoa ("x", offset
));
649 return (const unsigned char *) _("<offset is too big>");
652 ret
= section
->start
+ offset
;
653 /* Unfortunately we cannot rely upon the .debug_str section ending with a
654 NUL byte. Since our caller is expecting to receive a well formed C
655 string we test for the lack of a terminating byte here. */
656 if (strnlen ((const char *) ret
, section
->size
- offset
)
657 == section
->size
- offset
)
658 ret
= (const unsigned char *)
659 _("<no NUL byte at end of .debug_str section>");
664 static const unsigned char *
665 fetch_indirect_line_string (dwarf_vma offset
)
667 struct dwarf_section
*section
= &debug_displays
[line_str
].section
;
668 const unsigned char * ret
;
670 if (section
->start
== NULL
)
671 return (const unsigned char *) _("<no .debug_line_str section>");
673 if (offset
>= section
->size
)
675 warn (_("DW_FORM_line_strp offset too big: 0x%s\n"),
676 dwarf_vmatoa ("x", offset
));
677 return (const unsigned char *) _("<offset is too big>");
680 ret
= section
->start
+ offset
;
681 /* Unfortunately we cannot rely upon the .debug_line_str section ending
682 with a NUL byte. Since our caller is expecting to receive a well formed
683 C string we test for the lack of a terminating byte here. */
684 if (strnlen ((const char *) ret
, section
->size
- offset
)
685 == section
->size
- offset
)
686 ret
= (const unsigned char *)
687 _("<no NUL byte at end of .debug_line_str section>");
693 fetch_indexed_string (dwarf_vma idx
, struct cu_tu_set
*this_set
,
694 dwarf_vma offset_size
, bool dwo
)
696 enum dwarf_section_display_enum str_sec_idx
= dwo
? str_dwo
: str
;
697 enum dwarf_section_display_enum idx_sec_idx
= dwo
? str_index_dwo
: str_index
;
698 struct dwarf_section
*index_section
= &debug_displays
[idx_sec_idx
].section
;
699 struct dwarf_section
*str_section
= &debug_displays
[str_sec_idx
].section
;
700 dwarf_vma index_offset
;
701 dwarf_vma str_offset
;
703 unsigned char *curr
= index_section
->start
;
704 unsigned char *end
= curr
+ index_section
->size
;
707 if (index_section
->start
== NULL
)
708 return (dwo
? _("<no .debug_str_offsets.dwo section>")
709 : _("<no .debug_str_offsets section>"));
711 if (str_section
->start
== NULL
)
712 return (dwo
? _("<no .debug_str.dwo section>")
713 : _("<no .debug_str section>"));
715 /* FIXME: We should cache the length... */
716 SAFE_BYTE_GET_AND_INC (length
, curr
, 4, end
);
717 if (length
== 0xffffffff)
719 if (offset_size
!= 8)
720 warn (_("Expected offset size of 8 but given %s"), dwarf_vmatoa ("x", offset_size
));
721 SAFE_BYTE_GET_AND_INC (length
, curr
, 8, end
);
723 else if (offset_size
!= 4)
725 warn (_("Expected offset size of 4 but given %s"), dwarf_vmatoa ("x", offset_size
));
730 /* This is probably an old style .debug_str_offset section which
731 just contains offsets and no header (and the first offset is 0). */
732 curr
= index_section
->start
;
733 length
= index_section
->size
;
737 /* Skip the version and padding bytes.
738 We assume that they are correct. */
749 && this_set
->section_sizes
[DW_SECT_STR_OFFSETS
] < length
)
750 length
= this_set
->section_sizes
[DW_SECT_STR_OFFSETS
];
752 if (length
> (dwarf_vma
) (end
- curr
))
754 warn (_("index table size too large for section %s vs %s\n"),
755 dwarf_vmatoa ("x", length
),
756 dwarf_vmatoa ("x", index_section
->size
));
760 if (length
< offset_size
)
762 warn (_("index table size %s is too small\n"),
763 dwarf_vmatoa ("x", length
));
764 return _("<table too small>");
768 index_offset
= idx
* offset_size
;
770 if (this_set
!= NULL
)
771 index_offset
+= this_set
->section_offsets
[DW_SECT_STR_OFFSETS
];
773 if (index_offset
>= length
774 || length
- index_offset
< offset_size
)
776 warn (_("DW_FORM_GNU_str_index offset too big: 0x%s vs 0x%s\n"),
777 dwarf_vmatoa ("x", index_offset
),
778 dwarf_vmatoa ("x", length
));
779 return _("<index offset is too big>");
782 str_offset
= byte_get (curr
+ index_offset
, offset_size
);
783 str_offset
-= str_section
->address
;
784 if (str_offset
>= str_section
->size
)
786 warn (_("DW_FORM_GNU_str_index indirect offset too big: 0x%s\n"),
787 dwarf_vmatoa ("x", str_offset
));
788 return _("<indirect index offset is too big>");
791 ret
= (const char *) str_section
->start
+ str_offset
;
792 /* Unfortunately we cannot rely upon str_section ending with a NUL byte.
793 Since our caller is expecting to receive a well formed C string we test
794 for the lack of a terminating byte here. */
795 if (strnlen (ret
, str_section
->size
- str_offset
)
796 == str_section
->size
- str_offset
)
797 ret
= (const char *) _("<no NUL byte at end of section>");
803 fetch_indexed_value (dwarf_vma offset
, dwarf_vma bytes
)
805 struct dwarf_section
*section
= &debug_displays
[debug_addr
].section
;
807 if (section
->start
== NULL
)
808 return (_("<no .debug_addr section>"));
810 if (offset
+ bytes
> section
->size
)
812 warn (_("Offset into section %s too big: 0x%s\n"),
813 section
->name
, dwarf_vmatoa ("x", offset
));
814 return "<offset too big>";
817 return dwarf_vmatoa ("x", byte_get (section
->start
+ offset
, bytes
));
821 /* FIXME: There are better and more efficient ways to handle
822 these structures. For now though, I just want something that
823 is simple to implement. */
824 /* Records a single attribute in an abbrev. */
825 typedef struct abbrev_attr
827 unsigned long attribute
;
829 dwarf_signed_vma implicit_const
;
830 struct abbrev_attr
* next
;
834 /* Records a single abbrev. */
835 typedef struct abbrev_entry
837 unsigned long number
;
840 struct abbrev_attr
* first_attr
;
841 struct abbrev_attr
* last_attr
;
842 struct abbrev_entry
* next
;
846 /* Records a set of abbreviations. */
847 typedef struct abbrev_list
849 abbrev_entry
* first_abbrev
;
850 abbrev_entry
* last_abbrev
;
851 dwarf_vma abbrev_base
;
852 dwarf_vma abbrev_offset
;
853 struct abbrev_list
* next
;
854 unsigned char * start_of_next_abbrevs
;
858 /* Records all the abbrevs found so far. */
859 static struct abbrev_list
* abbrev_lists
= NULL
;
861 typedef struct abbrev_map
868 /* Maps between CU offsets and abbrev sets. */
869 static abbrev_map
* cu_abbrev_map
= NULL
;
870 static unsigned long num_abbrev_map_entries
= 0;
871 static unsigned long next_free_abbrev_map_entry
= 0;
873 #define INITIAL_NUM_ABBREV_MAP_ENTRIES 8
874 #define ABBREV_MAP_ENTRIES_INCREMENT 8
877 record_abbrev_list_for_cu (dwarf_vma start
, dwarf_vma end
, abbrev_list
* list
)
879 if (cu_abbrev_map
== NULL
)
881 num_abbrev_map_entries
= INITIAL_NUM_ABBREV_MAP_ENTRIES
;
882 cu_abbrev_map
= xmalloc (num_abbrev_map_entries
* sizeof (* cu_abbrev_map
));
884 else if (next_free_abbrev_map_entry
== num_abbrev_map_entries
)
886 num_abbrev_map_entries
+= ABBREV_MAP_ENTRIES_INCREMENT
;
887 cu_abbrev_map
= xrealloc (cu_abbrev_map
, num_abbrev_map_entries
* sizeof (* cu_abbrev_map
));
890 cu_abbrev_map
[next_free_abbrev_map_entry
].start
= start
;
891 cu_abbrev_map
[next_free_abbrev_map_entry
].end
= end
;
892 cu_abbrev_map
[next_free_abbrev_map_entry
].list
= list
;
893 next_free_abbrev_map_entry
++;
897 free_all_abbrevs (void)
901 for (list
= abbrev_lists
; list
!= NULL
;)
903 abbrev_list
* next
= list
->next
;
904 abbrev_entry
* abbrv
;
906 for (abbrv
= list
->first_abbrev
; abbrv
!= NULL
;)
908 abbrev_entry
* next_abbrev
= abbrv
->next
;
911 for (attr
= abbrv
->first_attr
; attr
;)
913 abbrev_attr
*next_attr
= attr
->next
;
931 new_abbrev_list (dwarf_vma abbrev_base
, dwarf_vma abbrev_offset
)
933 abbrev_list
* list
= (abbrev_list
*) xcalloc (sizeof * list
, 1);
935 list
->abbrev_base
= abbrev_base
;
936 list
->abbrev_offset
= abbrev_offset
;
938 list
->next
= abbrev_lists
;
945 find_abbrev_list_by_abbrev_offset (dwarf_vma abbrev_base
,
946 dwarf_vma abbrev_offset
)
950 for (list
= abbrev_lists
; list
!= NULL
; list
= list
->next
)
951 if (list
->abbrev_base
== abbrev_base
952 && list
->abbrev_offset
== abbrev_offset
)
958 /* Find the abbreviation map for the CU that includes OFFSET.
959 OFFSET is an absolute offset from the start of the .debug_info section. */
960 /* FIXME: This function is going to slow down readelf & objdump.
961 Consider using a better algorithm to mitigate this effect. */
964 find_abbrev_map_by_offset (dwarf_vma offset
)
968 for (i
= 0; i
< next_free_abbrev_map_entry
; i
++)
969 if (cu_abbrev_map
[i
].start
<= offset
970 && cu_abbrev_map
[i
].end
> offset
)
971 return cu_abbrev_map
+ i
;
977 add_abbrev (unsigned long number
,
982 abbrev_entry
* entry
;
984 entry
= (abbrev_entry
*) xmalloc (sizeof (*entry
));
986 entry
->number
= number
;
988 entry
->children
= children
;
989 entry
->first_attr
= NULL
;
990 entry
->last_attr
= NULL
;
993 assert (list
!= NULL
);
995 if (list
->first_abbrev
== NULL
)
996 list
->first_abbrev
= entry
;
998 list
->last_abbrev
->next
= entry
;
1000 list
->last_abbrev
= entry
;
1004 add_abbrev_attr (unsigned long attribute
,
1006 dwarf_signed_vma implicit_const
,
1011 attr
= (abbrev_attr
*) xmalloc (sizeof (*attr
));
1013 attr
->attribute
= attribute
;
1015 attr
->implicit_const
= implicit_const
;
1018 assert (list
!= NULL
&& list
->last_abbrev
!= NULL
);
1020 if (list
->last_abbrev
->first_attr
== NULL
)
1021 list
->last_abbrev
->first_attr
= attr
;
1023 list
->last_abbrev
->last_attr
->next
= attr
;
1025 list
->last_abbrev
->last_attr
= attr
;
1028 /* Processes the (partial) contents of a .debug_abbrev section.
1029 Returns NULL if the end of the section was encountered.
1030 Returns the address after the last byte read if the end of
1031 an abbreviation set was found. */
1033 static unsigned char *
1034 process_abbrev_set (struct dwarf_section
*section
,
1035 dwarf_vma abbrev_base
,
1036 dwarf_vma abbrev_size
,
1037 dwarf_vma abbrev_offset
,
1040 if (abbrev_base
>= section
->size
1041 || abbrev_size
> section
->size
- abbrev_base
)
1043 /* PR 17531: file:4bcd9ce9. */
1044 warn (_("Debug info is corrupted, abbrev size (%lx) is larger than "
1045 "abbrev section size (%lx)\n"),
1046 (unsigned long) (abbrev_base
+ abbrev_size
),
1047 (unsigned long) section
->size
);
1050 if (abbrev_offset
>= abbrev_size
)
1052 warn (_("Debug info is corrupted, abbrev offset (%lx) is larger than "
1053 "abbrev section size (%lx)\n"),
1054 (unsigned long) abbrev_offset
,
1055 (unsigned long) abbrev_size
);
1059 unsigned char *start
= section
->start
+ abbrev_base
;
1060 unsigned char *end
= start
+ abbrev_size
;
1061 start
+= abbrev_offset
;
1064 unsigned long entry
;
1066 unsigned long attribute
;
1069 READ_ULEB (entry
, start
, end
);
1071 /* A single zero is supposed to end the set according
1072 to the standard. If there's more, then signal that to
1079 READ_ULEB (tag
, start
, end
);
1083 children
= *start
++;
1085 add_abbrev (entry
, tag
, children
, list
);
1090 /* Initialize it due to a false compiler warning. */
1091 dwarf_signed_vma implicit_const
= -1;
1093 READ_ULEB (attribute
, start
, end
);
1097 READ_ULEB (form
, start
, end
);
1101 if (form
== DW_FORM_implicit_const
)
1103 READ_SLEB (implicit_const
, start
, end
);
1108 add_abbrev_attr (attribute
, form
, implicit_const
, list
);
1110 while (attribute
!= 0);
1113 /* Report the missing single zero which ends the section. */
1114 error (_(".debug_abbrev section not zero terminated\n"));
1120 get_TAG_name (unsigned long tag
)
1122 const char *name
= get_DW_TAG_name ((unsigned int) tag
);
1126 static char buffer
[100];
1128 if (tag
>= DW_TAG_lo_user
&& tag
<= DW_TAG_hi_user
)
1129 snprintf (buffer
, sizeof (buffer
), _("User TAG value: %#lx"), tag
);
1131 snprintf (buffer
, sizeof (buffer
), _("Unknown TAG value: %#lx"), tag
);
1139 get_FORM_name (unsigned long form
)
1144 return "DW_FORM value: 0";
1146 name
= get_DW_FORM_name (form
);
1149 static char buffer
[100];
1151 snprintf (buffer
, sizeof (buffer
), _("Unknown FORM value: %lx"), form
);
1159 get_IDX_name (unsigned long idx
)
1161 const char *name
= get_DW_IDX_name ((unsigned int) idx
);
1165 static char buffer
[100];
1167 snprintf (buffer
, sizeof (buffer
), _("Unknown IDX value: %lx"), idx
);
1174 static unsigned char *
1175 display_block (unsigned char *data
,
1177 const unsigned char * const end
, char delimiter
)
1181 printf (_("%c%s byte block: "), delimiter
, dwarf_vmatoa ("u", length
));
1183 return (unsigned char *) end
;
1185 maxlen
= (dwarf_vma
) (end
- data
);
1186 length
= length
> maxlen
? maxlen
: length
;
1189 printf ("%lx ", (unsigned long) byte_get (data
++, 1));
1195 decode_location_expression (unsigned char * data
,
1196 unsigned int pointer_size
,
1197 unsigned int offset_size
,
1200 dwarf_vma cu_offset
,
1201 struct dwarf_section
* section
)
1205 dwarf_signed_vma svalue
;
1206 unsigned char *end
= data
+ length
;
1207 int need_frame_base
= 0;
1216 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1217 printf ("DW_OP_addr: %s", dwarf_vmatoa ("x", uvalue
));
1220 printf ("DW_OP_deref");
1223 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1224 printf ("DW_OP_const1u: %lu", (unsigned long) uvalue
);
1227 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 1, end
);
1228 printf ("DW_OP_const1s: %ld", (long) svalue
);
1231 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
1232 printf ("DW_OP_const2u: %lu", (unsigned long) uvalue
);
1235 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1236 printf ("DW_OP_const2s: %ld", (long) svalue
);
1239 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1240 printf ("DW_OP_const4u: %lu", (unsigned long) uvalue
);
1243 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
1244 printf ("DW_OP_const4s: %ld", (long) svalue
);
1247 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1248 printf ("DW_OP_const8u: %lu ", (unsigned long) uvalue
);
1249 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1250 printf ("%lu", (unsigned long) uvalue
);
1253 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
1254 printf ("DW_OP_const8s: %ld ", (long) svalue
);
1255 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
1256 printf ("%ld", (long) svalue
);
1259 READ_ULEB (uvalue
, data
, end
);
1260 printf ("DW_OP_constu: %s", dwarf_vmatoa ("u", uvalue
));
1263 READ_SLEB (svalue
, data
, end
);
1264 printf ("DW_OP_consts: %s", dwarf_vmatoa ("d", svalue
));
1267 printf ("DW_OP_dup");
1270 printf ("DW_OP_drop");
1273 printf ("DW_OP_over");
1276 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1277 printf ("DW_OP_pick: %ld", (unsigned long) uvalue
);
1280 printf ("DW_OP_swap");
1283 printf ("DW_OP_rot");
1286 printf ("DW_OP_xderef");
1289 printf ("DW_OP_abs");
1292 printf ("DW_OP_and");
1295 printf ("DW_OP_div");
1298 printf ("DW_OP_minus");
1301 printf ("DW_OP_mod");
1304 printf ("DW_OP_mul");
1307 printf ("DW_OP_neg");
1310 printf ("DW_OP_not");
1313 printf ("DW_OP_or");
1316 printf ("DW_OP_plus");
1318 case DW_OP_plus_uconst
:
1319 READ_ULEB (uvalue
, data
, end
);
1320 printf ("DW_OP_plus_uconst: %s", dwarf_vmatoa ("u", uvalue
));
1323 printf ("DW_OP_shl");
1326 printf ("DW_OP_shr");
1329 printf ("DW_OP_shra");
1332 printf ("DW_OP_xor");
1335 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1336 printf ("DW_OP_bra: %ld", (long) svalue
);
1339 printf ("DW_OP_eq");
1342 printf ("DW_OP_ge");
1345 printf ("DW_OP_gt");
1348 printf ("DW_OP_le");
1351 printf ("DW_OP_lt");
1354 printf ("DW_OP_ne");
1357 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1358 printf ("DW_OP_skip: %ld", (long) svalue
);
1393 printf ("DW_OP_lit%d", op
- DW_OP_lit0
);
1428 printf ("DW_OP_reg%d (%s)", op
- DW_OP_reg0
,
1429 regname (op
- DW_OP_reg0
, 1));
1464 READ_SLEB (svalue
, data
, end
);
1465 printf ("DW_OP_breg%d (%s): %s", op
- DW_OP_breg0
,
1466 regname (op
- DW_OP_breg0
, 1), dwarf_vmatoa ("d", svalue
));
1470 READ_ULEB (uvalue
, data
, end
);
1471 printf ("DW_OP_regx: %s (%s)",
1472 dwarf_vmatoa ("u", uvalue
), regname (uvalue
, 1));
1475 need_frame_base
= 1;
1476 READ_SLEB (svalue
, data
, end
);
1477 printf ("DW_OP_fbreg: %s", dwarf_vmatoa ("d", svalue
));
1480 READ_ULEB (uvalue
, data
, end
);
1481 READ_SLEB (svalue
, data
, end
);
1482 printf ("DW_OP_bregx: %s (%s) %s",
1483 dwarf_vmatoa ("u", uvalue
), regname (uvalue
, 1),
1484 dwarf_vmatoa ("d", svalue
));
1487 READ_ULEB (uvalue
, data
, end
);
1488 printf ("DW_OP_piece: %s", dwarf_vmatoa ("u", uvalue
));
1490 case DW_OP_deref_size
:
1491 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1492 printf ("DW_OP_deref_size: %ld", (long) uvalue
);
1494 case DW_OP_xderef_size
:
1495 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1496 printf ("DW_OP_xderef_size: %ld", (long) uvalue
);
1499 printf ("DW_OP_nop");
1502 /* DWARF 3 extensions. */
1503 case DW_OP_push_object_address
:
1504 printf ("DW_OP_push_object_address");
1507 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1508 this ought to be an 8-byte wide computation. */
1509 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1510 printf ("DW_OP_call2: <0x%s>",
1511 dwarf_vmatoa ("x", svalue
+ cu_offset
));
1514 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1515 this ought to be an 8-byte wide computation. */
1516 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
1517 printf ("DW_OP_call4: <0x%s>",
1518 dwarf_vmatoa ("x", svalue
+ cu_offset
));
1520 case DW_OP_call_ref
:
1521 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1522 this ought to be an 8-byte wide computation. */
1523 if (dwarf_version
== -1)
1525 printf (_("(DW_OP_call_ref in frame info)"));
1526 /* No way to tell where the next op is, so just bail. */
1527 return need_frame_base
;
1529 if (dwarf_version
== 2)
1531 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1535 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1537 printf ("DW_OP_call_ref: <0x%s>", dwarf_vmatoa ("x", uvalue
));
1539 case DW_OP_form_tls_address
:
1540 printf ("DW_OP_form_tls_address");
1542 case DW_OP_call_frame_cfa
:
1543 printf ("DW_OP_call_frame_cfa");
1545 case DW_OP_bit_piece
:
1546 printf ("DW_OP_bit_piece: ");
1547 READ_ULEB (uvalue
, data
, end
);
1548 printf (_("size: %s "), dwarf_vmatoa ("u", uvalue
));
1549 READ_ULEB (uvalue
, data
, end
);
1550 printf (_("offset: %s "), dwarf_vmatoa ("u", uvalue
));
1553 /* DWARF 4 extensions. */
1554 case DW_OP_stack_value
:
1555 printf ("DW_OP_stack_value");
1558 case DW_OP_implicit_value
:
1559 printf ("DW_OP_implicit_value");
1560 READ_ULEB (uvalue
, data
, end
);
1561 data
= display_block (data
, uvalue
, end
, ' ');
1564 /* GNU extensions. */
1565 case DW_OP_GNU_push_tls_address
:
1566 printf (_("DW_OP_GNU_push_tls_address or DW_OP_HP_unknown"));
1568 case DW_OP_GNU_uninit
:
1569 printf ("DW_OP_GNU_uninit");
1570 /* FIXME: Is there data associated with this OP ? */
1572 case DW_OP_GNU_encoded_addr
:
1579 addr
= get_encoded_value (&data
, encoding
, section
, end
);
1581 printf ("DW_OP_GNU_encoded_addr: fmt:%02x addr:", encoding
);
1582 print_dwarf_vma (addr
, pointer_size
);
1585 case DW_OP_implicit_pointer
:
1586 case DW_OP_GNU_implicit_pointer
:
1587 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1588 this ought to be an 8-byte wide computation. */
1589 if (dwarf_version
== -1)
1591 printf (_("(%s in frame info)"),
1592 (op
== DW_OP_implicit_pointer
1593 ? "DW_OP_implicit_pointer"
1594 : "DW_OP_GNU_implicit_pointer"));
1595 /* No way to tell where the next op is, so just bail. */
1596 return need_frame_base
;
1598 if (dwarf_version
== 2)
1600 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1604 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1606 READ_SLEB (svalue
, data
, end
);
1607 printf ("%s: <0x%s> %s",
1608 (op
== DW_OP_implicit_pointer
1609 ? "DW_OP_implicit_pointer" : "DW_OP_GNU_implicit_pointer"),
1610 dwarf_vmatoa ("x", uvalue
),
1611 dwarf_vmatoa ("d", svalue
));
1613 case DW_OP_entry_value
:
1614 case DW_OP_GNU_entry_value
:
1615 READ_ULEB (uvalue
, data
, end
);
1616 /* PR 17531: file: 0cc9cd00. */
1617 if (uvalue
> (dwarf_vma
) (end
- data
))
1618 uvalue
= end
- data
;
1619 printf ("%s: (", (op
== DW_OP_entry_value
? "DW_OP_entry_value"
1620 : "DW_OP_GNU_entry_value"));
1621 if (decode_location_expression (data
, pointer_size
, offset_size
,
1622 dwarf_version
, uvalue
,
1623 cu_offset
, section
))
1624 need_frame_base
= 1;
1628 case DW_OP_const_type
:
1629 case DW_OP_GNU_const_type
:
1630 READ_ULEB (uvalue
, data
, end
);
1631 printf ("%s: <0x%s> ",
1632 (op
== DW_OP_const_type
? "DW_OP_const_type"
1633 : "DW_OP_GNU_const_type"),
1634 dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1635 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1636 data
= display_block (data
, uvalue
, end
, ' ');
1638 case DW_OP_regval_type
:
1639 case DW_OP_GNU_regval_type
:
1640 READ_ULEB (uvalue
, data
, end
);
1641 printf ("%s: %s (%s)",
1642 (op
== DW_OP_regval_type
? "DW_OP_regval_type"
1643 : "DW_OP_GNU_regval_type"),
1644 dwarf_vmatoa ("u", uvalue
), regname (uvalue
, 1));
1645 READ_ULEB (uvalue
, data
, end
);
1646 printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1648 case DW_OP_deref_type
:
1649 case DW_OP_GNU_deref_type
:
1650 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1652 (op
== DW_OP_deref_type
? "DW_OP_deref_type"
1653 : "DW_OP_GNU_deref_type"),
1655 READ_ULEB (uvalue
, data
, end
);
1656 printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1659 case DW_OP_GNU_convert
:
1660 READ_ULEB (uvalue
, data
, end
);
1661 printf ("%s <0x%s>",
1662 (op
== DW_OP_convert
? "DW_OP_convert" : "DW_OP_GNU_convert"),
1663 dwarf_vmatoa ("x", uvalue
? cu_offset
+ uvalue
: 0));
1665 case DW_OP_reinterpret
:
1666 case DW_OP_GNU_reinterpret
:
1667 READ_ULEB (uvalue
, data
, end
);
1668 printf ("%s <0x%s>",
1669 (op
== DW_OP_reinterpret
? "DW_OP_reinterpret"
1670 : "DW_OP_GNU_reinterpret"),
1671 dwarf_vmatoa ("x", uvalue
? cu_offset
+ uvalue
: 0));
1673 case DW_OP_GNU_parameter_ref
:
1674 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1675 printf ("DW_OP_GNU_parameter_ref: <0x%s>",
1676 dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1678 case DW_OP_GNU_addr_index
:
1679 READ_ULEB (uvalue
, data
, end
);
1680 printf ("DW_OP_GNU_addr_index <0x%s>", dwarf_vmatoa ("x", uvalue
));
1682 case DW_OP_GNU_const_index
:
1683 READ_ULEB (uvalue
, data
, end
);
1684 printf ("DW_OP_GNU_const_index <0x%s>", dwarf_vmatoa ("x", uvalue
));
1686 case DW_OP_GNU_variable_value
:
1687 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1688 this ought to be an 8-byte wide computation. */
1689 if (dwarf_version
== -1)
1691 printf (_("(DW_OP_GNU_variable_value in frame info)"));
1692 /* No way to tell where the next op is, so just bail. */
1693 return need_frame_base
;
1695 if (dwarf_version
== 2)
1697 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1701 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1703 printf ("DW_OP_GNU_variable_value: <0x%s>", dwarf_vmatoa ("x", uvalue
));
1706 /* HP extensions. */
1707 case DW_OP_HP_is_value
:
1708 printf ("DW_OP_HP_is_value");
1709 /* FIXME: Is there data associated with this OP ? */
1711 case DW_OP_HP_fltconst4
:
1712 printf ("DW_OP_HP_fltconst4");
1713 /* FIXME: Is there data associated with this OP ? */
1715 case DW_OP_HP_fltconst8
:
1716 printf ("DW_OP_HP_fltconst8");
1717 /* FIXME: Is there data associated with this OP ? */
1719 case DW_OP_HP_mod_range
:
1720 printf ("DW_OP_HP_mod_range");
1721 /* FIXME: Is there data associated with this OP ? */
1723 case DW_OP_HP_unmod_range
:
1724 printf ("DW_OP_HP_unmod_range");
1725 /* FIXME: Is there data associated with this OP ? */
1728 printf ("DW_OP_HP_tls");
1729 /* FIXME: Is there data associated with this OP ? */
1732 /* PGI (STMicroelectronics) extensions. */
1733 case DW_OP_PGI_omp_thread_num
:
1734 /* Pushes the thread number for the current thread as it would be
1735 returned by the standard OpenMP library function:
1736 omp_get_thread_num(). The "current thread" is the thread for
1737 which the expression is being evaluated. */
1738 printf ("DW_OP_PGI_omp_thread_num");
1742 if (op
>= DW_OP_lo_user
1743 && op
<= DW_OP_hi_user
)
1744 printf (_("(User defined location op 0x%x)"), op
);
1746 printf (_("(Unknown location op 0x%x)"), op
);
1747 /* No way to tell where the next op is, so just bail. */
1748 return need_frame_base
;
1751 /* Separate the ops. */
1756 return need_frame_base
;
1759 /* Find the CU or TU set corresponding to the given CU_OFFSET.
1760 This is used for DWARF package files. */
1762 static struct cu_tu_set
*
1763 find_cu_tu_set_v2 (dwarf_vma cu_offset
, int do_types
)
1765 struct cu_tu_set
*p
;
1767 unsigned int dw_sect
;
1773 dw_sect
= DW_SECT_TYPES
;
1779 dw_sect
= DW_SECT_INFO
;
1783 if (p
->section_offsets
[dw_sect
] == cu_offset
)
1792 fetch_alt_indirect_string (dwarf_vma offset
)
1796 if (! do_follow_links
)
1799 if (first_separate_info
== NULL
)
1800 return _("<no links available>");
1802 for (i
= first_separate_info
; i
!= NULL
; i
= i
->next
)
1804 struct dwarf_section
* section
;
1807 if (! load_debug_section (separate_debug_str
, i
->handle
))
1810 section
= &debug_displays
[separate_debug_str
].section
;
1812 if (section
->start
== NULL
)
1815 if (offset
>= section
->size
)
1818 ret
= (const char *) (section
->start
+ offset
);
1819 /* Unfortunately we cannot rely upon the .debug_str section ending with a
1820 NUL byte. Since our caller is expecting to receive a well formed C
1821 string we test for the lack of a terminating byte here. */
1822 if (strnlen ((const char *) ret
, section
->size
- offset
)
1823 == section
->size
- offset
)
1824 return _("<no NUL byte at end of alt .debug_str section>");
1829 warn (_("DW_FORM_GNU_strp_alt offset (%s) too big or no string sections available\n"),
1830 dwarf_vmatoa ("x", offset
));
1831 return _("<offset is too big>");
1835 get_AT_name (unsigned long attribute
)
1840 return "DW_AT value: 0";
1842 /* One value is shared by the MIPS and HP extensions: */
1843 if (attribute
== DW_AT_MIPS_fde
)
1844 return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable";
1846 name
= get_DW_AT_name (attribute
);
1850 static char buffer
[100];
1852 snprintf (buffer
, sizeof (buffer
), _("Unknown AT value: %lx"),
1861 add_dwo_info (const char * value
, dwarf_vma cu_offset
, dwo_type type
)
1863 dwo_info
* dwinfo
= xmalloc (sizeof * dwinfo
);
1865 dwinfo
->type
= type
;
1866 dwinfo
->value
= value
;
1867 dwinfo
->cu_offset
= cu_offset
;
1868 dwinfo
->next
= first_dwo_info
;
1869 first_dwo_info
= dwinfo
;
1873 add_dwo_name (const char * name
, dwarf_vma cu_offset
)
1875 add_dwo_info (name
, cu_offset
, DWO_NAME
);
1879 add_dwo_dir (const char * dir
, dwarf_vma cu_offset
)
1881 add_dwo_info (dir
, cu_offset
, DWO_DIR
);
1885 add_dwo_id (const char * id
, dwarf_vma cu_offset
)
1887 add_dwo_info (id
, cu_offset
, DWO_ID
);
1891 free_dwo_info (void)
1896 for (dwinfo
= first_dwo_info
; dwinfo
!= NULL
; dwinfo
= next
)
1898 next
= dwinfo
->next
;
1901 first_dwo_info
= NULL
;
1904 /* Ensure that START + UVALUE is less than END.
1905 Return an adjusted UVALUE if necessary to ensure this relationship. */
1907 static inline dwarf_vma
1908 check_uvalue (const unsigned char * start
,
1910 const unsigned char * end
)
1912 dwarf_vma max_uvalue
= end
- start
;
1914 /* See PR 17512: file: 008-103549-0.001:0.1.
1915 and PR 24829 for examples of where these tests are triggered. */
1916 if (uvalue
> max_uvalue
)
1918 warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue
);
1919 uvalue
= max_uvalue
;
1925 static unsigned char *
1926 skip_attr_bytes (unsigned long form
,
1927 unsigned char *data
,
1929 dwarf_vma pointer_size
,
1930 dwarf_vma offset_size
,
1932 dwarf_vma
*value_return
)
1934 dwarf_signed_vma svalue
;
1935 dwarf_vma uvalue
= 0;
1942 case DW_FORM_ref_addr
:
1943 if (dwarf_version
== 2)
1944 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1945 else if (dwarf_version
> 2)
1946 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1952 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1956 case DW_FORM_line_strp
:
1957 case DW_FORM_sec_offset
:
1958 case DW_FORM_GNU_ref_alt
:
1959 case DW_FORM_GNU_strp_alt
:
1960 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1963 case DW_FORM_flag_present
:
1971 case DW_FORM_addrx1
:
1972 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1976 case DW_FORM_addrx3
:
1977 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 3, end
);
1983 case DW_FORM_addrx2
:
1984 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
1990 case DW_FORM_addrx4
:
1991 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1995 READ_SLEB (svalue
, data
, end
);
1999 case DW_FORM_ref_udata
:
2001 case DW_FORM_GNU_str_index
:
2003 case DW_FORM_GNU_addr_index
:
2005 READ_ULEB (uvalue
, data
, end
);
2009 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 8, end
);
2013 case DW_FORM_ref_sig8
:
2017 case DW_FORM_data16
:
2021 case DW_FORM_string
:
2022 inc
= strnlen ((char *) data
, end
- data
) + 1;
2026 case DW_FORM_exprloc
:
2027 READ_ULEB (uvalue
, data
, end
);
2031 case DW_FORM_block1
:
2032 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
2036 case DW_FORM_block2
:
2037 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
2041 case DW_FORM_block4
:
2042 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
2046 case DW_FORM_indirect
:
2047 READ_ULEB (form
, data
, end
);
2048 if (form
== DW_FORM_implicit_const
)
2049 SKIP_ULEB (data
, end
);
2050 return skip_attr_bytes (form
, data
, end
, pointer_size
, offset_size
,
2051 dwarf_version
, value_return
);
2057 * value_return
= uvalue
;
2058 if (inc
<= (dwarf_vma
) (end
- data
))
2065 /* Given form FORM with value UVALUE, locate and return the abbreviation
2066 associated with it. */
2068 static abbrev_entry
*
2069 get_type_abbrev_from_form (unsigned long form
,
2070 unsigned long uvalue
,
2071 dwarf_vma cu_offset
,
2072 unsigned char *cu_end
,
2073 const struct dwarf_section
*section
,
2074 unsigned long *abbrev_num_return
,
2075 unsigned char **data_return
,
2076 abbrev_map
**map_return
)
2078 unsigned long abbrev_number
;
2080 abbrev_entry
* entry
;
2081 unsigned char * data
;
2083 if (abbrev_num_return
!= NULL
)
2084 * abbrev_num_return
= 0;
2085 if (data_return
!= NULL
)
2086 * data_return
= NULL
;
2090 case DW_FORM_GNU_ref_alt
:
2091 case DW_FORM_ref_sig8
:
2092 /* FIXME: We are unable to handle this form at the moment. */
2095 case DW_FORM_ref_addr
:
2096 if (uvalue
>= section
->size
)
2098 warn (_("Unable to resolve ref_addr form: uvalue %lx > section size %lx (%s)\n"),
2099 uvalue
, (long) section
->size
, section
->name
);
2104 case DW_FORM_ref_sup4
:
2105 case DW_FORM_ref_sup8
:
2112 case DW_FORM_ref_udata
:
2113 if (uvalue
+ cu_offset
> (size_t) (cu_end
- section
->start
))
2115 warn (_("Unable to resolve ref form: uvalue %lx + cu_offset %lx > CU size %lx\n"),
2116 uvalue
, (long) cu_offset
, (long) (cu_end
- section
->start
));
2119 uvalue
+= cu_offset
;
2122 /* FIXME: Are there other DW_FORMs that can be used by types ? */
2125 warn (_("Unexpected form %lx encountered whilst finding abbreviation for type\n"), form
);
2129 data
= (unsigned char *) section
->start
+ uvalue
;
2130 map
= find_abbrev_map_by_offset (uvalue
);
2134 warn (_("Unable to find abbreviations for CU offset %#lx\n"), uvalue
);
2137 if (map
->list
== NULL
)
2139 warn (_("Empty abbreviation list encountered for CU offset %lx\n"), uvalue
);
2143 if (map_return
!= NULL
)
2145 if (form
== DW_FORM_ref_addr
)
2151 READ_ULEB (abbrev_number
, data
, section
->start
+ section
->size
);
2153 for (entry
= map
->list
->first_abbrev
; entry
!= NULL
; entry
= entry
->next
)
2154 if (entry
->number
== abbrev_number
)
2157 if (abbrev_num_return
!= NULL
)
2158 * abbrev_num_return
= abbrev_number
;
2160 if (data_return
!= NULL
)
2161 * data_return
= data
;
2164 warn (_("Unable to find entry for abbreviation %lu\n"), abbrev_number
);
2169 /* Return IS_SIGNED set to TRUE if the type using abbreviation ENTRY
2170 can be determined to be a signed type. The data for ENTRY can be
2171 found starting at DATA. */
2174 get_type_signedness (abbrev_entry
*entry
,
2175 const struct dwarf_section
*section
,
2176 unsigned char *data
,
2178 dwarf_vma cu_offset
,
2179 dwarf_vma pointer_size
,
2180 dwarf_vma offset_size
,
2183 unsigned int nesting
)
2187 * is_signed
= false;
2189 #define MAX_NESTING 20
2190 if (nesting
> MAX_NESTING
)
2192 /* FIXME: Warn - or is this expected ?
2193 NB/ We need to avoid infinite recursion. */
2197 for (attr
= entry
->first_attr
;
2198 attr
!= NULL
&& attr
->attribute
;
2201 unsigned char * orig_data
= data
;
2202 dwarf_vma uvalue
= 0;
2204 data
= skip_attr_bytes (attr
->form
, data
, end
, pointer_size
,
2205 offset_size
, dwarf_version
, & uvalue
);
2209 switch (attr
->attribute
)
2211 case DW_AT_linkage_name
:
2215 if (attr
->form
== DW_FORM_strp
)
2216 printf (", %s", fetch_indirect_string (uvalue
));
2217 else if (attr
->form
== DW_FORM_string
)
2218 printf (", %.*s", (int) (end
- orig_data
), orig_data
);
2225 abbrev_entry
*type_abbrev
;
2226 unsigned char *type_data
;
2229 type_abbrev
= get_type_abbrev_from_form (attr
->form
,
2234 NULL
/* abbrev num return */,
2237 if (type_abbrev
== NULL
)
2240 get_type_signedness (type_abbrev
, section
, type_data
,
2241 map
? section
->start
+ map
->end
: end
,
2242 map
? map
->start
: cu_offset
,
2243 pointer_size
, offset_size
, dwarf_version
,
2244 is_signed
, nesting
+ 1);
2248 case DW_AT_encoding
:
2249 /* Determine signness. */
2252 case DW_ATE_address
:
2253 /* FIXME - some architectures have signed addresses. */
2254 case DW_ATE_boolean
:
2255 case DW_ATE_unsigned
:
2256 case DW_ATE_unsigned_char
:
2257 case DW_ATE_unsigned_fixed
:
2258 * is_signed
= false;
2262 case DW_ATE_complex_float
:
2265 case DW_ATE_signed_char
:
2266 case DW_ATE_imaginary_float
:
2267 case DW_ATE_decimal_float
:
2268 case DW_ATE_signed_fixed
:
2278 read_and_print_leb128 (unsigned char *data
,
2279 unsigned int *bytes_read
,
2280 unsigned const char *end
,
2284 dwarf_vma val
= read_leb128 (data
, end
, is_signed
, bytes_read
, &status
);
2286 report_leb_status (status
);
2288 printf ("%s", dwarf_vmatoa (is_signed
? "d" : "u", val
));
2292 display_discr_list (unsigned long form
,
2294 unsigned char * data
,
2297 unsigned char *end
= data
;
2301 printf ("[default]");
2308 case DW_FORM_block1
:
2309 case DW_FORM_block2
:
2310 case DW_FORM_block4
:
2311 /* Move data pointer back to the start of the byte array. */
2315 printf ("<corrupt>\n");
2316 warn (_("corrupt discr_list - not using a block form\n"));
2322 printf ("<corrupt>\n");
2323 warn (_("corrupt discr_list - block not long enough\n"));
2327 bool is_signed
= (level
> 0 && level
<= MAX_CU_NESTING
2328 ? level_type_signed
[level
- 1] : false);
2333 unsigned char discriminant
;
2334 unsigned int bytes_read
;
2336 SAFE_BYTE_GET_AND_INC (discriminant
, data
, 1, end
);
2338 switch (discriminant
)
2342 read_and_print_leb128 (data
, & bytes_read
, end
, is_signed
);
2348 read_and_print_leb128 (data
, & bytes_read
, end
, is_signed
);
2352 read_and_print_leb128 (data
, & bytes_read
, end
, is_signed
);
2357 printf ("<corrupt>\n");
2358 warn (_("corrupt discr_list - unrecognized discriminant byte %#x\n"),
2368 printf (")(signed)");
2370 printf (")(unsigned)");
2373 static unsigned char *
2374 read_and_display_attr_value (unsigned long attribute
,
2376 dwarf_signed_vma implicit_const
,
2377 unsigned char * start
,
2378 unsigned char * data
,
2379 unsigned char * end
,
2380 dwarf_vma cu_offset
,
2381 dwarf_vma pointer_size
,
2382 dwarf_vma offset_size
,
2384 debug_info
* debug_info_p
,
2386 struct dwarf_section
* section
,
2387 struct cu_tu_set
* this_set
,
2391 dwarf_signed_vma svalue
;
2392 dwarf_vma uvalue
= 0;
2393 dwarf_vma uvalue_hi
= 0;
2394 unsigned char *block_start
= NULL
;
2395 unsigned char *orig_data
= data
;
2397 if (data
> end
|| (data
== end
&& form
!= DW_FORM_flag_present
))
2399 warn (_("Corrupt attribute\n"));
2403 if (do_wide
&& ! do_loc
)
2405 /* PR 26847: Display the name of the form. */
2406 const char * name
= get_FORM_name (form
);
2408 /* For convenience we skip the DW_FORM_ prefix to the name. */
2410 name
+= 8; /* strlen ("DW_FORM_") */
2411 printf ("%c(%s)", delimiter
, name
);
2419 case DW_FORM_ref_addr
:
2420 if (dwarf_version
== 2)
2421 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
2422 else if (dwarf_version
> 2)
2423 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
2425 error (_("Internal error: DW_FORM_ref_addr is not supported in DWARF version 1.\n"));
2429 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
2432 case DW_FORM_strp_sup
:
2434 case DW_FORM_line_strp
:
2435 case DW_FORM_sec_offset
:
2436 case DW_FORM_GNU_ref_alt
:
2437 case DW_FORM_GNU_strp_alt
:
2438 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
2441 case DW_FORM_flag_present
:
2449 case DW_FORM_addrx1
:
2450 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
2456 case DW_FORM_addrx2
:
2457 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
2461 case DW_FORM_addrx3
:
2462 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 3, end
);
2465 case DW_FORM_ref_sup4
:
2469 case DW_FORM_addrx4
:
2470 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
2473 case DW_FORM_ref_sup8
:
2476 case DW_FORM_ref_sig8
:
2477 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 8, end
);
2480 case DW_FORM_data16
:
2481 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 8, end
);
2482 SAFE_BYTE_GET_AND_INC (uvalue_hi
, data
, 8, end
);
2483 if (byte_get
!= byte_get_little_endian
)
2485 dwarf_vma utmp
= uvalue
;
2492 READ_SLEB (svalue
, data
, end
);
2496 case DW_FORM_GNU_str_index
:
2498 case DW_FORM_ref_udata
:
2500 case DW_FORM_GNU_addr_index
:
2502 READ_ULEB (uvalue
, data
, end
);
2505 case DW_FORM_indirect
:
2506 READ_ULEB (form
, data
, end
);
2508 printf ("%c%s", delimiter
, get_FORM_name (form
));
2509 if (form
== DW_FORM_implicit_const
)
2510 READ_SLEB (implicit_const
, data
, end
);
2511 return read_and_display_attr_value (attribute
, form
, implicit_const
,
2513 cu_offset
, pointer_size
,
2514 offset_size
, dwarf_version
,
2515 debug_info_p
, do_loc
,
2516 section
, this_set
, delimiter
, level
);
2518 case DW_FORM_implicit_const
:
2519 uvalue
= implicit_const
;
2525 case DW_FORM_ref_addr
:
2527 printf ("%c<0x%s>", delimiter
, dwarf_vmatoa ("x", uvalue
));
2530 case DW_FORM_GNU_ref_alt
:
2534 /* We have already printed the form name. */
2535 printf ("%c<0x%s>", delimiter
, dwarf_vmatoa ("x", uvalue
));
2537 printf ("%c<alt 0x%s>", delimiter
, dwarf_vmatoa ("x", uvalue
));
2539 /* FIXME: Follow the reference... */
2545 case DW_FORM_ref_sup4
:
2546 case DW_FORM_ref_udata
:
2548 printf ("%c<0x%s>", delimiter
, dwarf_vmatoa ("x", uvalue
+ cu_offset
));
2553 case DW_FORM_sec_offset
:
2555 printf ("%c0x%s", delimiter
, dwarf_vmatoa ("x", uvalue
));
2558 case DW_FORM_flag_present
:
2565 printf ("%c%s", delimiter
, dwarf_vmatoa ("d", uvalue
));
2568 case DW_FORM_implicit_const
:
2570 printf ("%c%s", delimiter
, dwarf_vmatoa ("d", implicit_const
));
2573 case DW_FORM_ref_sup8
:
2578 dwarf_vma utmp
= uvalue
;
2579 if (form
== DW_FORM_ref8
)
2581 printf ("%c0x%s", delimiter
, dwarf_vmatoa ("x", utmp
));
2585 case DW_FORM_data16
:
2588 uvalue_hi
== 0 ? "" : dwarf_vmatoa ("x", uvalue_hi
),
2589 dwarf_vmatoa_1 ("x", uvalue
, uvalue_hi
== 0 ? 0 : 8));
2592 case DW_FORM_string
:
2594 printf ("%c%.*s", delimiter
, (int) (end
- data
), data
);
2595 data
+= strnlen ((char *) data
, end
- data
);
2601 case DW_FORM_exprloc
:
2602 READ_ULEB (uvalue
, data
, end
);
2605 if (block_start
>= end
)
2607 warn (_("Block ends prematurely\n"));
2612 uvalue
= check_uvalue (block_start
, uvalue
, end
);
2615 data
= block_start
+ uvalue
;
2617 data
= display_block (block_start
, uvalue
, end
, delimiter
);
2620 case DW_FORM_block1
:
2621 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
2624 case DW_FORM_block2
:
2625 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
2628 case DW_FORM_block4
:
2629 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
2636 /* We have already displayed the form name. */
2637 printf (_("%c(offset: 0x%s): %s"), delimiter
,
2638 dwarf_vmatoa ("x", uvalue
),
2639 fetch_indirect_string (uvalue
));
2641 printf (_("%c(indirect string, offset: 0x%s): %s"), delimiter
,
2642 dwarf_vmatoa ("x", uvalue
),
2643 fetch_indirect_string (uvalue
));
2647 case DW_FORM_line_strp
:
2651 /* We have already displayed the form name. */
2652 printf (_("%c(offset: 0x%s): %s"), delimiter
,
2653 dwarf_vmatoa ("x", uvalue
),
2654 fetch_indirect_line_string (uvalue
));
2656 printf (_("%c(indirect line string, offset: 0x%s): %s"), delimiter
,
2657 dwarf_vmatoa ("x", uvalue
),
2658 fetch_indirect_line_string (uvalue
));
2662 case DW_FORM_GNU_str_index
:
2670 const char *suffix
= strrchr (section
->name
, '.');
2671 bool dwo
= suffix
&& strcmp (suffix
, ".dwo") == 0;
2674 /* We have already displayed the form name. */
2675 printf (_("%c(offset: 0x%s): %s"), delimiter
,
2676 dwarf_vmatoa ("x", uvalue
),
2677 fetch_indexed_string (uvalue
, this_set
, offset_size
, dwo
));
2679 printf (_("%c(indexed string: 0x%s): %s"), delimiter
,
2680 dwarf_vmatoa ("x", uvalue
),
2681 fetch_indexed_string (uvalue
, this_set
, offset_size
, dwo
));
2685 case DW_FORM_GNU_strp_alt
:
2689 /* We have already displayed the form name. */
2690 printf (_("%c(offset: 0x%s) %s"), delimiter
,
2691 dwarf_vmatoa ("x", uvalue
),
2692 fetch_alt_indirect_string (uvalue
));
2694 printf (_("%c(alt indirect string, offset: 0x%s) %s"), delimiter
,
2695 dwarf_vmatoa ("x", uvalue
),
2696 fetch_alt_indirect_string (uvalue
));
2700 case DW_FORM_indirect
:
2701 /* Handled above. */
2704 case DW_FORM_ref_sig8
:
2706 printf ("%c%s: 0x%s", delimiter
, do_wide
? "" : "signature",
2707 dwarf_vmatoa ("x", uvalue
));
2710 case DW_FORM_GNU_addr_index
:
2712 case DW_FORM_addrx1
:
2713 case DW_FORM_addrx2
:
2714 case DW_FORM_addrx3
:
2715 case DW_FORM_addrx4
:
2721 if (debug_info_p
== NULL
)
2723 else if (debug_info_p
->addr_base
== DEBUG_INFO_UNAVAILABLE
)
2726 base
= debug_info_p
->addr_base
;
2728 offset
= base
+ uvalue
* pointer_size
;
2731 /* We have already displayed the form name. */
2732 printf (_("%c(index: 0x%s): %s"), delimiter
,
2733 dwarf_vmatoa ("x", uvalue
),
2734 fetch_indexed_value (offset
, pointer_size
));
2736 printf (_("%c(addr_index: 0x%s): %s"), delimiter
,
2737 dwarf_vmatoa ("x", uvalue
),
2738 fetch_indexed_value (offset
, pointer_size
));
2742 case DW_FORM_strp_sup
:
2744 printf ("%c<0x%s>", delimiter
, dwarf_vmatoa ("x", uvalue
+ cu_offset
));
2748 warn (_("Unrecognized form: 0x%lx\n"), form
);
2749 /* What to do? Consume a byte maybe? */
2754 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
2755 && num_debug_info_entries
== 0
2756 && debug_info_p
!= NULL
)
2760 case DW_AT_frame_base
:
2761 have_frame_base
= 1;
2763 case DW_AT_location
:
2764 case DW_AT_GNU_locviews
:
2765 case DW_AT_string_length
:
2766 case DW_AT_return_addr
:
2767 case DW_AT_data_member_location
:
2768 case DW_AT_vtable_elem_location
:
2770 case DW_AT_static_link
:
2771 case DW_AT_use_location
:
2772 case DW_AT_call_value
:
2773 case DW_AT_GNU_call_site_value
:
2774 case DW_AT_call_data_value
:
2775 case DW_AT_GNU_call_site_data_value
:
2776 case DW_AT_call_target
:
2777 case DW_AT_GNU_call_site_target
:
2778 case DW_AT_call_target_clobbered
:
2779 case DW_AT_GNU_call_site_target_clobbered
:
2780 if ((dwarf_version
< 4
2781 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
2782 || form
== DW_FORM_sec_offset
)
2784 /* Process location list. */
2785 unsigned int lmax
= debug_info_p
->max_loc_offsets
;
2786 unsigned int num
= debug_info_p
->num_loc_offsets
;
2788 if (lmax
== 0 || num
>= lmax
)
2791 debug_info_p
->loc_offsets
= (dwarf_vma
*)
2792 xcrealloc (debug_info_p
->loc_offsets
,
2793 lmax
, sizeof (*debug_info_p
->loc_offsets
));
2794 debug_info_p
->loc_views
= (dwarf_vma
*)
2795 xcrealloc (debug_info_p
->loc_views
,
2796 lmax
, sizeof (*debug_info_p
->loc_views
));
2797 debug_info_p
->have_frame_base
= (int *)
2798 xcrealloc (debug_info_p
->have_frame_base
,
2799 lmax
, sizeof (*debug_info_p
->have_frame_base
));
2800 debug_info_p
->max_loc_offsets
= lmax
;
2802 if (this_set
!= NULL
)
2803 uvalue
+= this_set
->section_offsets
[DW_SECT_LOC
];
2804 debug_info_p
->have_frame_base
[num
] = have_frame_base
;
2805 if (attribute
!= DW_AT_GNU_locviews
)
2807 /* Corrupt DWARF info can produce more offsets than views.
2808 See PR 23062 for an example. */
2809 if (debug_info_p
->num_loc_offsets
2810 > debug_info_p
->num_loc_views
)
2811 warn (_("More location offset attributes than DW_AT_GNU_locview attributes\n"));
2814 debug_info_p
->loc_offsets
[num
] = uvalue
;
2815 debug_info_p
->num_loc_offsets
++;
2820 assert (debug_info_p
->num_loc_views
<= num
);
2821 num
= debug_info_p
->num_loc_views
;
2822 if (num
> debug_info_p
->num_loc_offsets
)
2823 warn (_("More DW_AT_GNU_locview attributes than location offset attributes\n"));
2826 debug_info_p
->loc_views
[num
] = uvalue
;
2827 debug_info_p
->num_loc_views
++;
2834 if (need_base_address
)
2835 debug_info_p
->base_address
= uvalue
;
2838 case DW_AT_GNU_addr_base
:
2839 case DW_AT_addr_base
:
2840 debug_info_p
->addr_base
= uvalue
;
2843 case DW_AT_GNU_ranges_base
:
2844 debug_info_p
->ranges_base
= uvalue
;
2848 if ((dwarf_version
< 4
2849 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
2850 || form
== DW_FORM_sec_offset
)
2852 /* Process range list. */
2853 unsigned int lmax
= debug_info_p
->max_range_lists
;
2854 unsigned int num
= debug_info_p
->num_range_lists
;
2856 if (lmax
== 0 || num
>= lmax
)
2859 debug_info_p
->range_lists
= (dwarf_vma
*)
2860 xcrealloc (debug_info_p
->range_lists
,
2861 lmax
, sizeof (*debug_info_p
->range_lists
));
2862 debug_info_p
->max_range_lists
= lmax
;
2864 debug_info_p
->range_lists
[num
] = uvalue
;
2865 debug_info_p
->num_range_lists
++;
2869 case DW_AT_GNU_dwo_name
:
2870 case DW_AT_dwo_name
:
2875 add_dwo_name ((const char *) fetch_indirect_string (uvalue
), cu_offset
);
2877 case DW_FORM_GNU_strp_alt
:
2878 add_dwo_name ((const char *) fetch_alt_indirect_string (uvalue
), cu_offset
);
2880 case DW_FORM_GNU_str_index
:
2886 add_dwo_name (fetch_indexed_string (uvalue
, this_set
, offset_size
, false), cu_offset
);
2888 case DW_FORM_string
:
2889 add_dwo_name ((const char *) orig_data
, cu_offset
);
2892 warn (_("Unsupported form (%s) for attribute %s\n"),
2893 get_FORM_name (form
), get_AT_name (attribute
));
2898 case DW_AT_comp_dir
:
2899 /* FIXME: Also extract a build-id in a CU/TU. */
2904 add_dwo_dir ((const char *) fetch_indirect_string (uvalue
), cu_offset
);
2906 case DW_FORM_GNU_strp_alt
:
2907 add_dwo_dir (fetch_alt_indirect_string (uvalue
), cu_offset
);
2909 case DW_FORM_line_strp
:
2910 add_dwo_dir ((const char *) fetch_indirect_line_string (uvalue
), cu_offset
);
2912 case DW_FORM_GNU_str_index
:
2918 add_dwo_dir (fetch_indexed_string (uvalue
, this_set
, offset_size
, false), cu_offset
);
2920 case DW_FORM_string
:
2921 add_dwo_dir ((const char *) orig_data
, cu_offset
);
2924 warn (_("Unsupported form (%s) for attribute %s\n"),
2925 get_FORM_name (form
), get_AT_name (attribute
));
2930 case DW_AT_GNU_dwo_id
:
2935 /* FIXME: Record the length of the ID as well ? */
2936 add_dwo_id ((const char *) (data
- 8), cu_offset
);
2939 warn (_("Unsupported form (%s) for attribute %s\n"),
2940 get_FORM_name (form
), get_AT_name (attribute
));
2950 if (do_loc
|| attribute
== 0)
2953 /* For some attributes we can display further information. */
2957 if (level
>= 0 && level
< MAX_CU_NESTING
2958 && uvalue
< (size_t) (end
- start
))
2960 bool is_signed
= false;
2961 abbrev_entry
*type_abbrev
;
2962 unsigned char *type_data
;
2965 type_abbrev
= get_type_abbrev_from_form (form
, uvalue
,
2969 if (type_abbrev
!= NULL
)
2971 get_type_signedness (type_abbrev
, section
, type_data
,
2972 map
? section
->start
+ map
->end
: end
,
2973 map
? map
->start
: 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
, 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
, end
,
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 /* First scan the section to get the number of comp units.
3446 Length sanity checks are done here. */
3447 for (section_begin
= start
, num_units
= 0; section_begin
< end
;
3452 /* Read the first 4 bytes. For a 32-bit DWARF section, this
3453 will be the length. For a 64-bit DWARF section, it'll be
3454 the escape code 0xffffffff followed by an 8 byte length. */
3455 SAFE_BYTE_GET_AND_INC (length
, section_begin
, 4, end
);
3457 if (length
== 0xffffffff)
3458 SAFE_BYTE_GET_AND_INC (length
, section_begin
, 8, end
);
3459 else if (length
>= 0xfffffff0 && length
< 0xffffffff)
3461 warn (_("Reserved length value (0x%s) found in section %s\n"),
3462 dwarf_vmatoa ("x", length
), section
->name
);
3466 /* Negative values are illegal, they may even cause infinite
3467 looping. This can happen if we can't accurately apply
3468 relocations to an object file, or if the file is corrupt. */
3469 if (length
> (size_t) (end
- section_begin
))
3471 warn (_("Corrupt unit length (got 0x%s expected at most 0x%s) in section %s\n"),
3472 dwarf_vmatoa ("x", length
),
3473 dwarf_vmatoa ("x", end
- section_begin
),
3477 section_begin
+= length
;
3482 error (_("No comp units in %s section ?\n"), section
->name
);
3486 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
3487 && num_debug_info_entries
== 0
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 struct cu_tu_set
* this_set
;
3552 unsigned char *end_cu
;
3555 cu_offset
= start
- section_begin
;
3557 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 4, end
);
3559 if (compunit
.cu_length
== 0xffffffff)
3561 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 8, end
);
3566 end_cu
= hdrptr
+ compunit
.cu_length
;
3568 SAFE_BYTE_GET_AND_INC (compunit
.cu_version
, hdrptr
, 2, end_cu
);
3570 this_set
= find_cu_tu_set_v2 (cu_offset
, do_types
);
3572 if (compunit
.cu_version
< 5)
3574 compunit
.cu_unit_type
= DW_UT_compile
;
3575 /* Initialize it due to a false compiler warning. */
3576 compunit
.cu_pointer_size
= -1;
3580 SAFE_BYTE_GET_AND_INC (compunit
.cu_unit_type
, hdrptr
, 1, end_cu
);
3581 do_types
= (compunit
.cu_unit_type
== DW_UT_type
);
3583 SAFE_BYTE_GET_AND_INC (compunit
.cu_pointer_size
, hdrptr
, 1, end_cu
);
3586 SAFE_BYTE_GET_AND_INC (compunit
.cu_abbrev_offset
, hdrptr
, offset_size
,
3589 if (compunit
.cu_unit_type
== DW_UT_split_compile
3590 || compunit
.cu_unit_type
== DW_UT_skeleton
)
3593 SAFE_BYTE_GET_AND_INC (dwo_id
, hdrptr
, 8, end_cu
);
3596 if (this_set
== NULL
)
3599 abbrev_size
= debug_displays
[abbrev_sec
].section
.size
;
3603 abbrev_base
= this_set
->section_offsets
[DW_SECT_ABBREV
];
3604 abbrev_size
= this_set
->section_sizes
[DW_SECT_ABBREV
];
3607 list
= find_abbrev_list_by_abbrev_offset (abbrev_base
,
3608 compunit
.cu_abbrev_offset
);
3611 unsigned char * next
;
3613 list
= new_abbrev_list (abbrev_base
,
3614 compunit
.cu_abbrev_offset
);
3615 next
= process_abbrev_set (&debug_displays
[abbrev_sec
].section
,
3616 abbrev_base
, abbrev_size
,
3617 compunit
.cu_abbrev_offset
, list
);
3618 list
->start_of_next_abbrevs
= next
;
3622 record_abbrev_list_for_cu (cu_offset
, start
- section_begin
, list
);
3625 for (start
= section_begin
, unit
= 0; start
< end
; unit
++)
3627 DWARF2_Internal_CompUnit compunit
;
3628 unsigned char *hdrptr
;
3629 unsigned char *tags
;
3630 int level
, last_level
, saved_level
;
3631 dwarf_vma cu_offset
;
3632 unsigned int offset_size
;
3633 dwarf_vma signature
= 0;
3634 dwarf_vma type_offset
= 0;
3635 struct cu_tu_set
*this_set
;
3636 dwarf_vma abbrev_base
;
3638 abbrev_list
* list
= NULL
;
3639 unsigned char *end_cu
;
3642 cu_offset
= start
- section_begin
;
3644 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 4, end
);
3646 if (compunit
.cu_length
== 0xffffffff)
3648 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 8, end
);
3653 end_cu
= hdrptr
+ compunit
.cu_length
;
3655 SAFE_BYTE_GET_AND_INC (compunit
.cu_version
, hdrptr
, 2, end_cu
);
3657 this_set
= find_cu_tu_set_v2 (cu_offset
, do_types
);
3659 if (compunit
.cu_version
< 5)
3661 compunit
.cu_unit_type
= DW_UT_compile
;
3662 /* Initialize it due to a false compiler warning. */
3663 compunit
.cu_pointer_size
= -1;
3667 SAFE_BYTE_GET_AND_INC (compunit
.cu_unit_type
, hdrptr
, 1, end_cu
);
3668 do_types
= (compunit
.cu_unit_type
== DW_UT_type
);
3670 SAFE_BYTE_GET_AND_INC (compunit
.cu_pointer_size
, hdrptr
, 1, end_cu
);
3673 SAFE_BYTE_GET_AND_INC (compunit
.cu_abbrev_offset
, hdrptr
, offset_size
, end_cu
);
3675 if (this_set
== NULL
)
3678 abbrev_size
= debug_displays
[abbrev_sec
].section
.size
;
3682 abbrev_base
= this_set
->section_offsets
[DW_SECT_ABBREV
];
3683 abbrev_size
= this_set
->section_sizes
[DW_SECT_ABBREV
];
3686 if (compunit
.cu_version
< 5)
3687 SAFE_BYTE_GET_AND_INC (compunit
.cu_pointer_size
, hdrptr
, 1, end_cu
);
3689 bool do_dwo_id
= false;
3690 uint64_t dwo_id
= 0;
3691 if (compunit
.cu_unit_type
== DW_UT_split_compile
3692 || compunit
.cu_unit_type
== DW_UT_skeleton
)
3694 SAFE_BYTE_GET_AND_INC (dwo_id
, hdrptr
, 8, end_cu
);
3698 /* PR 17512: file: 001-108546-0.001:0.1. */
3699 if (compunit
.cu_pointer_size
< 2 || compunit
.cu_pointer_size
> 8)
3701 warn (_("Invalid pointer size (%d) in compunit header, using %d instead\n"),
3702 compunit
.cu_pointer_size
, offset_size
);
3703 compunit
.cu_pointer_size
= offset_size
;
3708 SAFE_BYTE_GET_AND_INC (signature
, hdrptr
, 8, end_cu
);
3709 SAFE_BYTE_GET_AND_INC (type_offset
, hdrptr
, offset_size
, end_cu
);
3712 if (dwarf_start_die
>= (size_t) (end_cu
- section_begin
))
3718 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
3719 && num_debug_info_entries
== 0
3720 && alloc_num_debug_info_entries
> unit
3723 debug_information
[unit
].cu_offset
= cu_offset
;
3724 debug_information
[unit
].pointer_size
3725 = compunit
.cu_pointer_size
;
3726 debug_information
[unit
].offset_size
= offset_size
;
3727 debug_information
[unit
].dwarf_version
= compunit
.cu_version
;
3728 debug_information
[unit
].base_address
= 0;
3729 debug_information
[unit
].addr_base
= DEBUG_INFO_UNAVAILABLE
;
3730 debug_information
[unit
].ranges_base
= DEBUG_INFO_UNAVAILABLE
;
3731 debug_information
[unit
].loc_offsets
= NULL
;
3732 debug_information
[unit
].have_frame_base
= NULL
;
3733 debug_information
[unit
].max_loc_offsets
= 0;
3734 debug_information
[unit
].num_loc_offsets
= 0;
3735 debug_information
[unit
].range_lists
= NULL
;
3736 debug_information
[unit
].max_range_lists
= 0;
3737 debug_information
[unit
].num_range_lists
= 0;
3740 if (!do_loc
&& dwarf_start_die
== 0)
3742 printf (_(" Compilation Unit @ offset 0x%s:\n"),
3743 dwarf_vmatoa ("x", cu_offset
));
3744 printf (_(" Length: 0x%s (%s)\n"),
3745 dwarf_vmatoa ("x", compunit
.cu_length
),
3746 offset_size
== 8 ? "64-bit" : "32-bit");
3747 printf (_(" Version: %d\n"), compunit
.cu_version
);
3748 if (compunit
.cu_version
>= 5)
3750 const char *name
= get_DW_UT_name (compunit
.cu_unit_type
);
3752 printf (_(" Unit Type: %s (%x)\n"),
3753 name
? name
: "???",
3754 compunit
.cu_unit_type
);
3756 printf (_(" Abbrev Offset: 0x%s\n"),
3757 dwarf_vmatoa ("x", compunit
.cu_abbrev_offset
));
3758 printf (_(" Pointer Size: %d\n"), compunit
.cu_pointer_size
);
3761 printf (_(" Signature: 0x%s\n"),
3762 dwarf_vmatoa ("x", signature
));
3763 printf (_(" Type Offset: 0x%s\n"),
3764 dwarf_vmatoa ("x", type_offset
));
3767 printf (_(" DWO ID: 0x%s\n"), dwarf_vmatoa ("x", dwo_id
));
3768 if (this_set
!= NULL
)
3770 dwarf_vma
*offsets
= this_set
->section_offsets
;
3771 size_t *sizes
= this_set
->section_sizes
;
3773 printf (_(" Section contributions:\n"));
3774 printf (_(" .debug_abbrev.dwo: 0x%s 0x%s\n"),
3775 dwarf_vmatoa ("x", offsets
[DW_SECT_ABBREV
]),
3776 dwarf_vmatoa ("x", sizes
[DW_SECT_ABBREV
]));
3777 printf (_(" .debug_line.dwo: 0x%s 0x%s\n"),
3778 dwarf_vmatoa ("x", offsets
[DW_SECT_LINE
]),
3779 dwarf_vmatoa ("x", sizes
[DW_SECT_LINE
]));
3780 printf (_(" .debug_loc.dwo: 0x%s 0x%s\n"),
3781 dwarf_vmatoa ("x", offsets
[DW_SECT_LOC
]),
3782 dwarf_vmatoa ("x", sizes
[DW_SECT_LOC
]));
3783 printf (_(" .debug_str_offsets.dwo: 0x%s 0x%s\n"),
3784 dwarf_vmatoa ("x", offsets
[DW_SECT_STR_OFFSETS
]),
3785 dwarf_vmatoa ("x", sizes
[DW_SECT_STR_OFFSETS
]));
3792 if (compunit
.cu_version
< 2 || compunit
.cu_version
> 5)
3794 warn (_("CU at offset %s contains corrupt or "
3795 "unsupported version number: %d.\n"),
3796 dwarf_vmatoa ("x", cu_offset
), compunit
.cu_version
);
3800 if (compunit
.cu_unit_type
!= DW_UT_compile
3801 && compunit
.cu_unit_type
!= DW_UT_partial
3802 && compunit
.cu_unit_type
!= DW_UT_type
3803 && compunit
.cu_unit_type
!= DW_UT_split_compile
3804 && compunit
.cu_unit_type
!= DW_UT_skeleton
)
3806 warn (_("CU at offset %s contains corrupt or "
3807 "unsupported unit type: %d.\n"),
3808 dwarf_vmatoa ("x", cu_offset
), compunit
.cu_unit_type
);
3812 /* Process the abbrevs used by this compilation unit. */
3813 list
= find_abbrev_list_by_abbrev_offset (abbrev_base
,
3814 compunit
.cu_abbrev_offset
);
3817 unsigned char *next
;
3819 list
= new_abbrev_list (abbrev_base
,
3820 compunit
.cu_abbrev_offset
);
3821 next
= process_abbrev_set (&debug_displays
[abbrev_sec
].section
,
3822 abbrev_base
, abbrev_size
,
3823 compunit
.cu_abbrev_offset
, list
);
3824 list
->start_of_next_abbrevs
= next
;
3830 while (tags
< start
)
3832 unsigned long abbrev_number
;
3833 unsigned long die_offset
;
3834 abbrev_entry
*entry
;
3836 int do_printing
= 1;
3838 die_offset
= tags
- section_begin
;
3840 READ_ULEB (abbrev_number
, tags
, start
);
3842 /* A null DIE marks the end of a list of siblings or it may also be
3843 a section padding. */
3844 if (abbrev_number
== 0)
3846 /* Check if it can be a section padding for the last CU. */
3847 if (level
== 0 && start
== end
)
3851 for (chk
= tags
; chk
< start
; chk
++)
3858 if (!do_loc
&& die_offset
>= dwarf_start_die
3859 && (dwarf_cutoff_level
== -1
3860 || level
< dwarf_cutoff_level
))
3861 printf (_(" <%d><%lx>: Abbrev Number: 0\n"),
3867 static unsigned num_bogus_warns
= 0;
3869 if (num_bogus_warns
< 3)
3871 warn (_("Bogus end-of-siblings marker detected at offset %lx in %s section\n"),
3872 die_offset
, section
->name
);
3874 if (num_bogus_warns
== 3)
3875 warn (_("Further warnings about bogus end-of-sibling markers suppressed\n"));
3878 if (dwarf_start_die
!= 0 && level
< saved_level
)
3885 if (dwarf_start_die
!= 0 && die_offset
< dwarf_start_die
)
3889 if (dwarf_start_die
!= 0 && die_offset
== dwarf_start_die
)
3890 saved_level
= level
;
3891 do_printing
= (dwarf_cutoff_level
== -1
3892 || level
< dwarf_cutoff_level
);
3894 printf (_(" <%d><%lx>: Abbrev Number: %lu"),
3895 level
, die_offset
, abbrev_number
);
3896 else if (dwarf_cutoff_level
== -1
3897 || last_level
< dwarf_cutoff_level
)
3898 printf (_(" <%d><%lx>: ...\n"), level
, die_offset
);
3903 /* Scan through the abbreviation list until we reach the
3908 for (entry
= list
->first_abbrev
; entry
!= NULL
; entry
= entry
->next
)
3909 if (entry
->number
== abbrev_number
)
3914 if (!do_loc
&& do_printing
)
3919 warn (_("DIE at offset 0x%lx refers to abbreviation number %lu which does not exist\n"),
3920 die_offset
, abbrev_number
);
3924 if (!do_loc
&& do_printing
)
3925 printf (" (%s)\n", get_TAG_name (entry
->tag
));
3930 need_base_address
= 0;
3932 case DW_TAG_compile_unit
:
3933 need_base_address
= 1;
3934 need_dwo_info
= do_loc
;
3936 case DW_TAG_entry_point
:
3937 case DW_TAG_subprogram
:
3938 need_base_address
= 0;
3939 /* Assuming that there is no DW_AT_frame_base. */
3940 have_frame_base
= 0;
3944 debug_info
*debug_info_p
=
3945 (debug_information
&& unit
< alloc_num_debug_info_entries
)
3946 ? debug_information
+ unit
: NULL
;
3948 assert (!debug_info_p
3949 || (debug_info_p
->num_loc_offsets
3950 == debug_info_p
->num_loc_views
));
3952 for (attr
= entry
->first_attr
;
3953 attr
&& attr
->attribute
;
3956 if (! do_loc
&& do_printing
)
3957 /* Show the offset from where the tag was extracted. */
3958 printf (" <%lx>", (unsigned long)(tags
- section_begin
));
3959 tags
= read_and_display_attr (attr
->attribute
,
3961 attr
->implicit_const
,
3966 compunit
.cu_pointer_size
,
3968 compunit
.cu_version
,
3970 do_loc
|| ! do_printing
,
3976 /* If a locview attribute appears before a location one,
3977 make sure we don't associate it with an earlier
3980 switch (debug_info_p
->num_loc_offsets
- debug_info_p
->num_loc_views
)
3983 debug_info_p
->loc_views
[debug_info_p
->num_loc_views
] = vm1
;
3984 debug_info_p
->num_loc_views
++;
3985 assert (debug_info_p
->num_loc_views
3986 == debug_info_p
->num_loc_offsets
);
3993 warn(_("DIE has locviews without loclist\n"));
3994 debug_info_p
->num_loc_views
--;
4001 if (entry
->children
)
4006 /* Set num_debug_info_entries here so that it can be used to check if
4007 we need to process .debug_loc and .debug_ranges sections. */
4008 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
4009 && num_debug_info_entries
== 0
4012 if (num_units
> alloc_num_debug_info_entries
)
4013 num_debug_info_entries
= alloc_num_debug_info_entries
;
4015 num_debug_info_entries
= num_units
;
4024 /* Locate and scan the .debug_info section in the file and record the pointer
4025 sizes and offsets for the compilation units in it. Usually an executable
4026 will have just one pointer size, but this is not guaranteed, and so we try
4027 not to make any assumptions. Returns zero upon failure, or the number of
4028 compilation units upon success. */
4031 load_debug_info (void * file
)
4033 /* If we have already tried and failed to load the .debug_info
4034 section then do not bother to repeat the task. */
4035 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
4038 /* If we already have the information there is nothing else to do. */
4039 if (num_debug_info_entries
> 0)
4040 return num_debug_info_entries
;
4042 /* If this is a DWARF package file, load the CU and TU indexes. */
4043 (void) load_cu_tu_indexes (file
);
4045 if (load_debug_section_with_follow (info
, file
)
4046 && process_debug_info (&debug_displays
[info
].section
, file
, abbrev
, true, false))
4047 return num_debug_info_entries
;
4049 if (load_debug_section_with_follow (info_dwo
, file
)
4050 && process_debug_info (&debug_displays
[info_dwo
].section
, file
,
4051 abbrev_dwo
, true, false))
4052 return num_debug_info_entries
;
4054 num_debug_info_entries
= DEBUG_INFO_UNAVAILABLE
;
4058 /* Read a DWARF .debug_line section header starting at DATA.
4059 Upon success returns an updated DATA pointer and the LINFO
4060 structure and the END_OF_SEQUENCE pointer will be filled in.
4061 Otherwise returns NULL. */
4063 static unsigned char *
4064 read_debug_line_header (struct dwarf_section
* section
,
4065 unsigned char * data
,
4066 unsigned char * end
,
4067 DWARF2_Internal_LineInfo
* linfo
,
4068 unsigned char ** end_of_sequence
)
4070 unsigned char *hdrptr
;
4072 /* Extract information from the Line Number Program Header.
4073 (section 6.2.4 in the Dwarf3 doc). */
4076 /* Get and check the length of the block. */
4077 SAFE_BYTE_GET_AND_INC (linfo
->li_length
, hdrptr
, 4, end
);
4079 if (linfo
->li_length
== 0xffffffff)
4081 /* This section is 64-bit DWARF 3. */
4082 SAFE_BYTE_GET_AND_INC (linfo
->li_length
, hdrptr
, 8, end
);
4083 linfo
->li_offset_size
= 8;
4086 linfo
->li_offset_size
= 4;
4088 if (linfo
->li_length
> (size_t) (end
- hdrptr
))
4090 /* If the length field has a relocation against it, then we should
4091 not complain if it is inaccurate (and probably negative). This
4092 happens in object files when the .debug_line section is actually
4093 comprised of several different .debug_line.* sections, (some of
4094 which may be removed by linker garbage collection), and a relocation
4095 is used to compute the correct length once that is done. */
4096 if (reloc_at (section
, (hdrptr
- section
->start
) - linfo
->li_offset_size
))
4098 linfo
->li_length
= end
- hdrptr
;
4102 warn (_("The length field (0x%lx) in the debug_line header is wrong - the section is too small\n"),
4103 (long) linfo
->li_length
);
4107 end
= hdrptr
+ linfo
->li_length
;
4109 /* Get and check the version number. */
4110 SAFE_BYTE_GET_AND_INC (linfo
->li_version
, hdrptr
, 2, end
);
4112 if (linfo
->li_version
!= 2
4113 && linfo
->li_version
!= 3
4114 && linfo
->li_version
!= 4
4115 && linfo
->li_version
!= 5)
4117 warn (_("Only DWARF version 2, 3, 4 and 5 line info "
4118 "is currently supported.\n"));
4122 if (linfo
->li_version
>= 5)
4124 SAFE_BYTE_GET_AND_INC (linfo
->li_address_size
, hdrptr
, 1, end
);
4126 SAFE_BYTE_GET_AND_INC (linfo
->li_segment_size
, hdrptr
, 1, end
);
4127 if (linfo
->li_segment_size
!= 0)
4129 warn (_("The %s section contains "
4130 "unsupported segment selector size: %d.\n"),
4131 section
->name
, linfo
->li_segment_size
);
4136 SAFE_BYTE_GET_AND_INC (linfo
->li_prologue_length
, hdrptr
,
4137 linfo
->li_offset_size
, end
);
4138 SAFE_BYTE_GET_AND_INC (linfo
->li_min_insn_length
, hdrptr
, 1, end
);
4140 if (linfo
->li_version
>= 4)
4142 SAFE_BYTE_GET_AND_INC (linfo
->li_max_ops_per_insn
, hdrptr
, 1, end
);
4144 if (linfo
->li_max_ops_per_insn
== 0)
4146 warn (_("Invalid maximum operations per insn.\n"));
4151 linfo
->li_max_ops_per_insn
= 1;
4153 SAFE_BYTE_GET_AND_INC (linfo
->li_default_is_stmt
, hdrptr
, 1, end
);
4154 SAFE_SIGNED_BYTE_GET_AND_INC (linfo
->li_line_base
, hdrptr
, 1, end
);
4155 SAFE_BYTE_GET_AND_INC (linfo
->li_line_range
, hdrptr
, 1, end
);
4156 SAFE_BYTE_GET_AND_INC (linfo
->li_opcode_base
, hdrptr
, 1, end
);
4158 *end_of_sequence
= end
;
4162 static unsigned char *
4163 display_formatted_table (unsigned char *data
,
4164 unsigned char *start
,
4166 const DWARF2_Internal_LineInfo
*linfo
,
4167 struct dwarf_section
*section
,
4170 unsigned char *format_start
, format_count
, *format
, formati
;
4171 dwarf_vma data_count
, datai
;
4172 unsigned int namepass
, last_entry
= 0;
4173 const char * table_name
= is_dir
? N_("Directory Table") : N_("File Name Table");
4175 SAFE_BYTE_GET_AND_INC (format_count
, data
, 1, end
);
4176 if (do_checks
&& format_count
> 5)
4177 warn (_("Unexpectedly large number of columns in the %s (%u)\n"),
4178 table_name
, format_count
);
4180 format_start
= data
;
4181 for (formati
= 0; formati
< format_count
; formati
++)
4183 SKIP_ULEB (data
, end
);
4184 SKIP_ULEB (data
, end
);
4187 warn (_("%s: Corrupt format description entry\n"), table_name
);
4192 READ_ULEB (data_count
, data
, end
);
4193 if (data_count
== 0)
4195 printf (_("\n The %s is empty.\n"), table_name
);
4198 else if (data
>= end
)
4200 warn (_("%s: Corrupt entry count - expected %s but none found\n"),
4201 table_name
, dwarf_vmatoa ("x", data_count
));
4205 else if (format_count
== 0)
4207 warn (_("%s: format count is zero, but the table is not empty\n"),
4212 printf (_("\n The %s (offset 0x%lx, lines %s, columns %u):\n"),
4213 table_name
, (long) (data
- start
), dwarf_vmatoa ("u", data_count
),
4216 printf (_(" Entry"));
4217 /* Delay displaying name as the last entry for better screen layout. */
4218 for (namepass
= 0; namepass
< 2; namepass
++)
4220 format
= format_start
;
4221 for (formati
= 0; formati
< format_count
; formati
++)
4223 dwarf_vma content_type
;
4225 READ_ULEB (content_type
, format
, end
);
4226 if ((content_type
== DW_LNCT_path
) == (namepass
== 1))
4227 switch (content_type
)
4230 printf (_("\tName"));
4232 case DW_LNCT_directory_index
:
4233 printf (_("\tDir"));
4235 case DW_LNCT_timestamp
:
4236 printf (_("\tTime"));
4239 printf (_("\tSize"));
4242 printf (_("\tMD5\t\t\t"));
4245 printf (_("\t(Unknown format content type %s)"),
4246 dwarf_vmatoa ("u", content_type
));
4248 SKIP_ULEB (format
, end
);
4253 for (datai
= 0; datai
< data_count
; datai
++)
4255 unsigned char *datapass
= data
;
4257 printf (" %d", last_entry
++);
4258 /* Delay displaying name as the last entry for better screen layout. */
4259 for (namepass
= 0; namepass
< 2; namepass
++)
4261 format
= format_start
;
4263 for (formati
= 0; formati
< format_count
; formati
++)
4265 dwarf_vma content_type
, form
;
4267 READ_ULEB (content_type
, format
, end
);
4268 READ_ULEB (form
, format
, end
);
4269 data
= read_and_display_attr_value (0, form
, 0, start
, data
, end
,
4270 0, 0, linfo
->li_offset_size
,
4271 linfo
->li_version
, NULL
,
4272 ((content_type
== DW_LNCT_path
) != (namepass
== 1)),
4273 section
, NULL
, '\t', -1);
4277 if (data
>= end
&& (datai
< data_count
- 1))
4279 warn (_("\n%s: Corrupt entries list\n"), table_name
);
4288 display_debug_sup (struct dwarf_section
* section
,
4289 void * file ATTRIBUTE_UNUSED
)
4291 unsigned char * start
= section
->start
;
4292 unsigned char * end
= section
->start
+ section
->size
;
4293 unsigned int version
;
4294 char is_supplementary
;
4295 const unsigned char * sup_filename
;
4296 size_t sup_filename_len
;
4297 unsigned int num_read
;
4299 dwarf_vma checksum_len
;
4302 introduce (section
, true);
4303 if (section
->size
< 4)
4305 error (_("corrupt .debug_sup section: size is too small\n"));
4309 /* Read the data. */
4310 SAFE_BYTE_GET_AND_INC (version
, start
, 2, end
);
4312 warn (_("corrupt .debug_sup section: version < 5"));
4314 SAFE_BYTE_GET_AND_INC (is_supplementary
, start
, 1, end
);
4315 if (is_supplementary
!= 0 && is_supplementary
!= 1)
4316 warn (_("corrupt .debug_sup section: is_supplementary not 0 or 1\n"));
4318 sup_filename
= start
;
4319 if (is_supplementary
&& sup_filename
[0] != 0)
4320 warn (_("corrupt .debug_sup section: filename not empty in supplementary section\n"));
4322 sup_filename_len
= strnlen ((const char *) start
, end
- start
);
4323 if (sup_filename_len
== (size_t) (end
- start
))
4325 error (_("corrupt .debug_sup section: filename is not NUL terminated\n"));
4328 start
+= sup_filename_len
+ 1;
4330 checksum_len
= read_leb128 (start
, end
, false /* unsigned */, & num_read
, & status
);
4333 error (_("corrupt .debug_sup section: bad LEB128 field for checksum length\n"));
4337 if (checksum_len
> (dwarf_vma
) (end
- start
))
4339 error (_("corrupt .debug_sup section: checksum length is longer than the remaining section length\n"));
4340 checksum_len
= end
- start
;
4342 else if (checksum_len
< (dwarf_vma
) (end
- start
))
4344 warn (_("corrupt .debug_sup section: there are 0x%lx extra, unused bytes at the end of the section\n"),
4345 (long) ((end
- start
) - checksum_len
));
4348 printf (_(" Version: %u\n"), version
);
4349 printf (_(" Is Supp: %u\n"), is_supplementary
);
4350 printf (_(" Filename: %s\n"), sup_filename
);
4351 printf (_(" Checksum Len: %lu\n"), (long) checksum_len
);
4352 if (checksum_len
> 0)
4354 printf (_(" Checksum: "));
4355 while (checksum_len
--)
4356 printf ("0x%x ", * start
++ );
4363 display_debug_lines_raw (struct dwarf_section
* section
,
4364 unsigned char * data
,
4365 unsigned char * end
,
4368 unsigned char *start
= section
->start
;
4369 int verbose_view
= 0;
4371 introduce (section
, true);
4375 static DWARF2_Internal_LineInfo saved_linfo
;
4376 DWARF2_Internal_LineInfo linfo
;
4377 unsigned char *standard_opcodes
;
4378 unsigned char *end_of_sequence
;
4381 if (startswith (section
->name
, ".debug_line.")
4382 /* Note: the following does not apply to .debug_line.dwo sections.
4383 These are full debug_line sections. */
4384 && strcmp (section
->name
, ".debug_line.dwo") != 0)
4386 /* Sections named .debug_line.<foo> are fragments of a .debug_line
4387 section containing just the Line Number Statements. They are
4388 created by the assembler and intended to be used alongside gcc's
4389 -ffunction-sections command line option. When the linker's
4390 garbage collection decides to discard a .text.<foo> section it
4391 can then also discard the line number information in .debug_line.<foo>.
4393 Since the section is a fragment it does not have the details
4394 needed to fill out a LineInfo structure, so instead we use the
4395 details from the last full debug_line section that we processed. */
4396 end_of_sequence
= end
;
4397 standard_opcodes
= NULL
;
4398 linfo
= saved_linfo
;
4399 /* PR 17531: file: 0522b371. */
4400 if (linfo
.li_line_range
== 0)
4402 warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n"));
4405 reset_state_machine (linfo
.li_default_is_stmt
);
4409 unsigned char * hdrptr
;
4411 if ((hdrptr
= read_debug_line_header (section
, data
, end
, & linfo
,
4412 & end_of_sequence
)) == NULL
)
4415 printf (_(" Offset: 0x%lx\n"), (long)(data
- start
));
4416 printf (_(" Length: %ld\n"), (long) linfo
.li_length
);
4417 printf (_(" DWARF Version: %d\n"), linfo
.li_version
);
4418 if (linfo
.li_version
>= 5)
4420 printf (_(" Address size (bytes): %d\n"), linfo
.li_address_size
);
4421 printf (_(" Segment selector (bytes): %d\n"), linfo
.li_segment_size
);
4423 printf (_(" Prologue Length: %d\n"), (int) linfo
.li_prologue_length
);
4424 printf (_(" Minimum Instruction Length: %d\n"), linfo
.li_min_insn_length
);
4425 if (linfo
.li_version
>= 4)
4426 printf (_(" Maximum Ops per Instruction: %d\n"), linfo
.li_max_ops_per_insn
);
4427 printf (_(" Initial value of 'is_stmt': %d\n"), linfo
.li_default_is_stmt
);
4428 printf (_(" Line Base: %d\n"), linfo
.li_line_base
);
4429 printf (_(" Line Range: %d\n"), linfo
.li_line_range
);
4430 printf (_(" Opcode Base: %d\n"), linfo
.li_opcode_base
);
4432 /* PR 17512: file: 1665-6428-0.004. */
4433 if (linfo
.li_line_range
== 0)
4435 warn (_("Line range of 0 is invalid, using 1 instead\n"));
4436 linfo
.li_line_range
= 1;
4439 reset_state_machine (linfo
.li_default_is_stmt
);
4441 /* Display the contents of the Opcodes table. */
4442 standard_opcodes
= hdrptr
;
4444 /* PR 17512: file: 002-417945-0.004. */
4445 if (standard_opcodes
+ linfo
.li_opcode_base
>= end
)
4447 warn (_("Line Base extends beyond end of section\n"));
4451 printf (_("\n Opcodes:\n"));
4453 for (i
= 1; i
< linfo
.li_opcode_base
; i
++)
4454 printf (ngettext (" Opcode %d has %d arg\n",
4455 " Opcode %d has %d args\n",
4456 standard_opcodes
[i
- 1]),
4457 i
, standard_opcodes
[i
- 1]);
4459 /* Display the contents of the Directory table. */
4460 data
= standard_opcodes
+ linfo
.li_opcode_base
- 1;
4462 if (linfo
.li_version
>= 5)
4464 load_debug_section_with_follow (line_str
, file
);
4466 data
= display_formatted_table (data
, start
, end
, &linfo
, section
,
4468 data
= display_formatted_table (data
, start
, end
, &linfo
, section
,
4474 printf (_("\n The Directory Table is empty.\n"));
4477 unsigned int last_dir_entry
= 0;
4479 printf (_("\n The Directory Table (offset 0x%lx):\n"),
4480 (long)(data
- start
));
4482 while (data
< end
&& *data
!= 0)
4484 printf (" %d\t%.*s\n", ++last_dir_entry
, (int) (end
- data
), data
);
4486 data
+= strnlen ((char *) data
, end
- data
);
4491 /* PR 17512: file: 002-132094-0.004. */
4492 if (data
>= end
- 1)
4496 /* Skip the NUL at the end of the table. */
4500 /* Display the contents of the File Name table. */
4501 if (data
>= end
|| *data
== 0)
4502 printf (_("\n The File Name Table is empty.\n"));
4505 printf (_("\n The File Name Table (offset 0x%lx):\n"),
4506 (long)(data
- start
));
4507 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
4509 while (data
< end
&& *data
!= 0)
4511 unsigned char *name
;
4514 printf (" %d\t", ++state_machine_regs
.last_file_entry
);
4516 data
+= strnlen ((char *) data
, end
- data
);
4520 READ_ULEB (val
, data
, end
);
4521 printf ("%s\t", dwarf_vmatoa ("u", val
));
4522 READ_ULEB (val
, data
, end
);
4523 printf ("%s\t", dwarf_vmatoa ("u", val
));
4524 READ_ULEB (val
, data
, end
);
4525 printf ("%s\t", dwarf_vmatoa ("u", val
));
4526 printf ("%.*s\n", (int)(end
- name
), name
);
4530 warn (_("Corrupt file name table entry\n"));
4536 /* Skip the NUL at the end of the table. */
4542 saved_linfo
= linfo
;
4545 /* Now display the statements. */
4546 if (data
>= end_of_sequence
)
4547 printf (_(" No Line Number Statements.\n"));
4550 printf (_(" Line Number Statements:\n"));
4552 while (data
< end_of_sequence
)
4554 unsigned char op_code
;
4555 dwarf_signed_vma adv
;
4558 printf (" [0x%08lx]", (long)(data
- start
));
4562 if (op_code
>= linfo
.li_opcode_base
)
4564 op_code
-= linfo
.li_opcode_base
;
4565 uladv
= (op_code
/ linfo
.li_line_range
);
4566 if (linfo
.li_max_ops_per_insn
== 1)
4568 uladv
*= linfo
.li_min_insn_length
;
4569 state_machine_regs
.address
+= uladv
;
4571 state_machine_regs
.view
= 0;
4572 printf (_(" Special opcode %d: "
4573 "advance Address by %s to 0x%s%s"),
4574 op_code
, dwarf_vmatoa ("u", uladv
),
4575 dwarf_vmatoa ("x", state_machine_regs
.address
),
4576 verbose_view
&& uladv
4577 ? _(" (reset view)") : "");
4582 = ((state_machine_regs
.op_index
+ uladv
)
4583 / linfo
.li_max_ops_per_insn
)
4584 * linfo
.li_min_insn_length
;
4586 state_machine_regs
.address
+= addrdelta
;
4587 state_machine_regs
.op_index
4588 = (state_machine_regs
.op_index
+ uladv
)
4589 % linfo
.li_max_ops_per_insn
;
4591 state_machine_regs
.view
= 0;
4592 printf (_(" Special opcode %d: "
4593 "advance Address by %s to 0x%s[%d]%s"),
4594 op_code
, dwarf_vmatoa ("u", uladv
),
4595 dwarf_vmatoa ("x", state_machine_regs
.address
),
4596 state_machine_regs
.op_index
,
4597 verbose_view
&& addrdelta
4598 ? _(" (reset view)") : "");
4600 adv
= (op_code
% linfo
.li_line_range
) + linfo
.li_line_base
;
4601 state_machine_regs
.line
+= adv
;
4602 printf (_(" and Line by %s to %d"),
4603 dwarf_vmatoa ("d", adv
), state_machine_regs
.line
);
4604 if (verbose_view
|| state_machine_regs
.view
)
4605 printf (_(" (view %u)\n"), state_machine_regs
.view
);
4608 state_machine_regs
.view
++;
4613 case DW_LNS_extended_op
:
4614 data
+= process_extended_line_op (data
,
4615 linfo
.li_default_is_stmt
,
4620 printf (_(" Copy"));
4621 if (verbose_view
|| state_machine_regs
.view
)
4622 printf (_(" (view %u)\n"), state_machine_regs
.view
);
4625 state_machine_regs
.view
++;
4628 case DW_LNS_advance_pc
:
4629 READ_ULEB (uladv
, data
, end
);
4630 if (linfo
.li_max_ops_per_insn
== 1)
4632 uladv
*= linfo
.li_min_insn_length
;
4633 state_machine_regs
.address
+= uladv
;
4635 state_machine_regs
.view
= 0;
4636 printf (_(" Advance PC by %s to 0x%s%s\n"),
4637 dwarf_vmatoa ("u", uladv
),
4638 dwarf_vmatoa ("x", state_machine_regs
.address
),
4639 verbose_view
&& uladv
4640 ? _(" (reset view)") : "");
4645 = ((state_machine_regs
.op_index
+ uladv
)
4646 / linfo
.li_max_ops_per_insn
)
4647 * linfo
.li_min_insn_length
;
4648 state_machine_regs
.address
4650 state_machine_regs
.op_index
4651 = (state_machine_regs
.op_index
+ uladv
)
4652 % linfo
.li_max_ops_per_insn
;
4654 state_machine_regs
.view
= 0;
4655 printf (_(" Advance PC by %s to 0x%s[%d]%s\n"),
4656 dwarf_vmatoa ("u", uladv
),
4657 dwarf_vmatoa ("x", state_machine_regs
.address
),
4658 state_machine_regs
.op_index
,
4659 verbose_view
&& addrdelta
4660 ? _(" (reset view)") : "");
4664 case DW_LNS_advance_line
:
4665 READ_SLEB (adv
, data
, end
);
4666 state_machine_regs
.line
+= adv
;
4667 printf (_(" Advance Line by %s to %d\n"),
4668 dwarf_vmatoa ("d", adv
),
4669 state_machine_regs
.line
);
4672 case DW_LNS_set_file
:
4673 READ_ULEB (uladv
, data
, end
);
4674 printf (_(" Set File Name to entry %s in the File Name Table\n"),
4675 dwarf_vmatoa ("u", uladv
));
4676 state_machine_regs
.file
= uladv
;
4679 case DW_LNS_set_column
:
4680 READ_ULEB (uladv
, data
, end
);
4681 printf (_(" Set column to %s\n"),
4682 dwarf_vmatoa ("u", uladv
));
4683 state_machine_regs
.column
= uladv
;
4686 case DW_LNS_negate_stmt
:
4687 adv
= state_machine_regs
.is_stmt
;
4689 printf (_(" Set is_stmt to %s\n"), dwarf_vmatoa ("d", adv
));
4690 state_machine_regs
.is_stmt
= adv
;
4693 case DW_LNS_set_basic_block
:
4694 printf (_(" Set basic block\n"));
4695 state_machine_regs
.basic_block
= 1;
4698 case DW_LNS_const_add_pc
:
4699 uladv
= ((255 - linfo
.li_opcode_base
) / linfo
.li_line_range
);
4700 if (linfo
.li_max_ops_per_insn
)
4702 uladv
*= linfo
.li_min_insn_length
;
4703 state_machine_regs
.address
+= uladv
;
4705 state_machine_regs
.view
= 0;
4706 printf (_(" Advance PC by constant %s to 0x%s%s\n"),
4707 dwarf_vmatoa ("u", uladv
),
4708 dwarf_vmatoa ("x", state_machine_regs
.address
),
4709 verbose_view
&& uladv
4710 ? _(" (reset view)") : "");
4715 = ((state_machine_regs
.op_index
+ uladv
)
4716 / linfo
.li_max_ops_per_insn
)
4717 * linfo
.li_min_insn_length
;
4718 state_machine_regs
.address
4720 state_machine_regs
.op_index
4721 = (state_machine_regs
.op_index
+ uladv
)
4722 % linfo
.li_max_ops_per_insn
;
4724 state_machine_regs
.view
= 0;
4725 printf (_(" Advance PC by constant %s to 0x%s[%d]%s\n"),
4726 dwarf_vmatoa ("u", uladv
),
4727 dwarf_vmatoa ("x", state_machine_regs
.address
),
4728 state_machine_regs
.op_index
,
4729 verbose_view
&& addrdelta
4730 ? _(" (reset view)") : "");
4734 case DW_LNS_fixed_advance_pc
:
4735 SAFE_BYTE_GET_AND_INC (uladv
, data
, 2, end
);
4736 state_machine_regs
.address
+= uladv
;
4737 state_machine_regs
.op_index
= 0;
4738 printf (_(" Advance PC by fixed size amount %s to 0x%s\n"),
4739 dwarf_vmatoa ("u", uladv
),
4740 dwarf_vmatoa ("x", state_machine_regs
.address
));
4741 /* Do NOT reset view. */
4744 case DW_LNS_set_prologue_end
:
4745 printf (_(" Set prologue_end to true\n"));
4748 case DW_LNS_set_epilogue_begin
:
4749 printf (_(" Set epilogue_begin to true\n"));
4752 case DW_LNS_set_isa
:
4753 READ_ULEB (uladv
, data
, end
);
4754 printf (_(" Set ISA to %s\n"), dwarf_vmatoa ("u", uladv
));
4758 printf (_(" Unknown opcode %d with operands: "), op_code
);
4760 if (standard_opcodes
!= NULL
)
4761 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
4763 READ_ULEB (uladv
, data
, end
);
4764 printf ("0x%s%s", dwarf_vmatoa ("x", uladv
),
4765 i
== 1 ? "" : ", ");
4780 unsigned char *name
;
4781 unsigned int directory_index
;
4782 unsigned int modification_date
;
4783 unsigned int length
;
4786 /* Output a decoded representation of the .debug_line section. */
4789 display_debug_lines_decoded (struct dwarf_section
* section
,
4790 unsigned char * start
,
4791 unsigned char * data
,
4792 unsigned char * end
,
4795 static DWARF2_Internal_LineInfo saved_linfo
;
4797 introduce (section
, false);
4801 /* This loop amounts to one iteration per compilation unit. */
4802 DWARF2_Internal_LineInfo linfo
;
4803 unsigned char *standard_opcodes
;
4804 unsigned char *end_of_sequence
;
4806 File_Entry
*file_table
= NULL
;
4807 unsigned int n_files
= 0;
4808 unsigned char **directory_table
= NULL
;
4809 dwarf_vma n_directories
= 0;
4811 if (startswith (section
->name
, ".debug_line.")
4812 /* Note: the following does not apply to .debug_line.dwo sections.
4813 These are full debug_line sections. */
4814 && strcmp (section
->name
, ".debug_line.dwo") != 0)
4816 /* See comment in display_debug_lines_raw(). */
4817 end_of_sequence
= end
;
4818 standard_opcodes
= NULL
;
4819 linfo
= saved_linfo
;
4820 /* PR 17531: file: 0522b371. */
4821 if (linfo
.li_line_range
== 0)
4823 warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n"));
4826 reset_state_machine (linfo
.li_default_is_stmt
);
4830 unsigned char *hdrptr
;
4832 if ((hdrptr
= read_debug_line_header (section
, data
, end
, & linfo
,
4833 & end_of_sequence
)) == NULL
)
4836 /* PR 17531: file: 0522b371. */
4837 if (linfo
.li_line_range
== 0)
4839 warn (_("Line range of 0 is invalid, using 1 instead\n"));
4840 linfo
.li_line_range
= 1;
4842 reset_state_machine (linfo
.li_default_is_stmt
);
4844 /* Save a pointer to the contents of the Opcodes table. */
4845 standard_opcodes
= hdrptr
;
4847 /* Traverse the Directory table just to count entries. */
4848 data
= standard_opcodes
+ linfo
.li_opcode_base
- 1;
4852 warn (_("opcode base of %d extends beyond end of section\n"),
4853 linfo
.li_opcode_base
);
4857 if (linfo
.li_version
>= 5)
4859 unsigned char *format_start
, format_count
, *format
;
4860 dwarf_vma formati
, entryi
;
4862 load_debug_section_with_follow (line_str
, fileptr
);
4864 /* Skip directories format. */
4865 SAFE_BYTE_GET_AND_INC (format_count
, data
, 1, end
);
4866 if (do_checks
&& format_count
> 1)
4867 warn (_("Unexpectedly large number of columns in the directory name table (%u)\n"),
4869 format_start
= data
;
4870 for (formati
= 0; formati
< format_count
; formati
++)
4872 SKIP_ULEB (data
, end
);
4873 SKIP_ULEB (data
, end
);
4876 READ_ULEB (n_directories
, data
, end
);
4879 warn (_("Corrupt directories list\n"));
4883 if (n_directories
== 0)
4884 directory_table
= NULL
;
4886 directory_table
= (unsigned char **)
4887 xmalloc (n_directories
* sizeof (unsigned char *));
4889 for (entryi
= 0; entryi
< n_directories
; entryi
++)
4891 unsigned char **pathp
= &directory_table
[entryi
];
4893 format
= format_start
;
4894 for (formati
= 0; formati
< format_count
; formati
++)
4896 dwarf_vma content_type
, form
;
4899 READ_ULEB (content_type
, format
, end
);
4900 READ_ULEB (form
, format
, end
);
4903 warn (_("Corrupt directories list\n"));
4906 switch (content_type
)
4911 case DW_FORM_string
:
4914 case DW_FORM_line_strp
:
4915 SAFE_BYTE_GET (uvalue
, data
, linfo
.li_offset_size
,
4917 /* Remove const by the cast. */
4918 *pathp
= (unsigned char *)
4919 fetch_indirect_line_string (uvalue
);
4924 data
= read_and_display_attr_value (0, form
, 0, start
,
4926 linfo
.li_offset_size
,
4933 warn (_("Corrupt directories list\n"));
4938 /* Skip files format. */
4939 SAFE_BYTE_GET_AND_INC (format_count
, data
, 1, end
);
4940 if (do_checks
&& format_count
> 5)
4941 warn (_("Unexpectedly large number of columns in the file name table (%u)\n"),
4943 format_start
= data
;
4944 for (formati
= 0; formati
< format_count
; formati
++)
4946 SKIP_ULEB (data
, end
);
4947 SKIP_ULEB (data
, end
);
4950 READ_ULEB (n_files
, data
, end
);
4951 if (data
>= end
&& n_files
> 0)
4953 warn (_("Corrupt file name list\n"));
4960 file_table
= (File_Entry
*) xcalloc (1, n_files
4961 * sizeof (File_Entry
));
4963 for (entryi
= 0; entryi
< n_files
; entryi
++)
4965 File_Entry
*file
= &file_table
[entryi
];
4967 format
= format_start
;
4968 for (formati
= 0; formati
< format_count
; formati
++)
4970 dwarf_vma content_type
, form
;
4974 READ_ULEB (content_type
, format
, end
);
4975 READ_ULEB (form
, format
, end
);
4978 warn (_("Corrupt file name list\n"));
4981 switch (content_type
)
4986 case DW_FORM_string
:
4989 case DW_FORM_line_strp
:
4990 SAFE_BYTE_GET (uvalue
, data
, linfo
.li_offset_size
,
4992 /* Remove const by the cast. */
4993 file
->name
= (unsigned char *)
4994 fetch_indirect_line_string (uvalue
);
4998 case DW_LNCT_directory_index
:
5002 SAFE_BYTE_GET (file
->directory_index
, data
, 1,
5006 SAFE_BYTE_GET (file
->directory_index
, data
, 2,
5011 READ_ULEB (file
->directory_index
, tmp
, end
);
5016 data
= read_and_display_attr_value (0, form
, 0, start
,
5018 linfo
.li_offset_size
,
5025 warn (_("Corrupt file name list\n"));
5034 unsigned char *ptr_directory_table
= data
;
5036 while (data
< end
&& *data
!= 0)
5038 data
+= strnlen ((char *) data
, end
- data
);
5047 warn (_("directory table ends unexpectedly\n"));
5052 /* Go through the directory table again to save the directories. */
5053 directory_table
= (unsigned char **)
5054 xmalloc (n_directories
* sizeof (unsigned char *));
5057 while (*ptr_directory_table
!= 0)
5059 directory_table
[i
] = ptr_directory_table
;
5061 += strlen ((char *) ptr_directory_table
) + 1;
5065 /* Skip the NUL at the end of the table. */
5068 /* Traverse the File Name table just to count the entries. */
5069 if (data
< end
&& *data
!= 0)
5071 unsigned char *ptr_file_name_table
= data
;
5073 while (data
< end
&& *data
!= 0)
5075 /* Skip Name, directory index, last modification
5076 time and length of file. */
5077 data
+= strnlen ((char *) data
, end
- data
);
5080 SKIP_ULEB (data
, end
);
5081 SKIP_ULEB (data
, end
);
5082 SKIP_ULEB (data
, end
);
5088 warn (_("file table ends unexpectedly\n"));
5093 /* Go through the file table again to save the strings. */
5094 file_table
= (File_Entry
*) xmalloc (n_files
* sizeof (File_Entry
));
5097 while (*ptr_file_name_table
!= 0)
5099 file_table
[i
].name
= ptr_file_name_table
;
5101 += strlen ((char *) ptr_file_name_table
) + 1;
5103 /* We are not interested in directory, time or size. */
5104 READ_ULEB (file_table
[i
].directory_index
,
5105 ptr_file_name_table
, end
);
5106 READ_ULEB (file_table
[i
].modification_date
,
5107 ptr_file_name_table
, end
);
5108 READ_ULEB (file_table
[i
].length
,
5109 ptr_file_name_table
, end
);
5115 /* Skip the NUL at the end of the table. */
5119 /* Print the Compilation Unit's name and a header. */
5120 if (file_table
== NULL
)
5121 printf (_("CU: No directory table\n"));
5122 else if (directory_table
== NULL
)
5123 printf (_("CU: %s:\n"), file_table
[0].name
);
5126 unsigned int ix
= file_table
[0].directory_index
;
5127 const char *directory
;
5132 else if (n_directories
== 0)
5133 directory
= _("<unknown>");
5134 else if (ix
> n_directories
)
5136 warn (_("directory index %u > number of directories %s\n"),
5137 ix
, dwarf_vmatoa ("u", n_directories
));
5138 directory
= _("<corrupt>");
5141 directory
= (char *) directory_table
[ix
- 1];
5144 printf (_("CU: %s/%s:\n"), directory
, file_table
[0].name
);
5146 printf ("%s:\n", file_table
[0].name
);
5150 printf (_("File name Line number Starting address View Stmt\n"));
5152 printf (_("CU: Empty file name table\n"));
5153 saved_linfo
= linfo
;
5156 /* This loop iterates through the Dwarf Line Number Program. */
5157 while (data
< end_of_sequence
)
5159 unsigned char op_code
;
5162 unsigned long int uladv
;
5163 int is_special_opcode
= 0;
5168 if (op_code
>= linfo
.li_opcode_base
)
5170 op_code
-= linfo
.li_opcode_base
;
5171 uladv
= (op_code
/ linfo
.li_line_range
);
5172 if (linfo
.li_max_ops_per_insn
== 1)
5174 uladv
*= linfo
.li_min_insn_length
;
5175 state_machine_regs
.address
+= uladv
;
5177 state_machine_regs
.view
= 0;
5182 = ((state_machine_regs
.op_index
+ uladv
)
5183 / linfo
.li_max_ops_per_insn
)
5184 * linfo
.li_min_insn_length
;
5185 state_machine_regs
.address
5187 state_machine_regs
.op_index
5188 = (state_machine_regs
.op_index
+ uladv
)
5189 % linfo
.li_max_ops_per_insn
;
5191 state_machine_regs
.view
= 0;
5194 adv
= (op_code
% linfo
.li_line_range
) + linfo
.li_line_base
;
5195 state_machine_regs
.line
+= adv
;
5196 is_special_opcode
= 1;
5197 /* Increment view after printing this row. */
5202 case DW_LNS_extended_op
:
5204 unsigned int ext_op_code_len
;
5205 unsigned char ext_op_code
;
5206 unsigned char *op_code_end
;
5207 unsigned char *op_code_data
= data
;
5209 READ_ULEB (ext_op_code_len
, op_code_data
, end_of_sequence
);
5210 op_code_end
= op_code_data
+ ext_op_code_len
;
5211 if (ext_op_code_len
== 0 || op_code_end
> end_of_sequence
)
5213 warn (_("Badly formed extended line op encountered!\n"));
5216 ext_op_code
= *op_code_data
++;
5220 switch (ext_op_code
)
5222 case DW_LNE_end_sequence
:
5223 /* Reset stuff after printing this row. */
5225 case DW_LNE_set_address
:
5226 SAFE_BYTE_GET_AND_INC (state_machine_regs
.address
,
5228 op_code_end
- op_code_data
,
5230 state_machine_regs
.op_index
= 0;
5231 state_machine_regs
.view
= 0;
5233 case DW_LNE_define_file
:
5234 file_table
= (File_Entry
*) xrealloc
5235 (file_table
, (n_files
+ 1) * sizeof (File_Entry
));
5237 ++state_machine_regs
.last_file_entry
;
5238 /* Source file name. */
5239 file_table
[n_files
].name
= op_code_data
;
5240 op_code_data
+= strlen ((char *) op_code_data
) + 1;
5241 /* Directory index. */
5242 READ_ULEB (file_table
[n_files
].directory_index
,
5243 op_code_data
, op_code_end
);
5244 /* Last modification time. */
5245 READ_ULEB (file_table
[n_files
].modification_date
,
5246 op_code_data
, op_code_end
);
5248 READ_ULEB (file_table
[n_files
].length
,
5249 op_code_data
, op_code_end
);
5253 case DW_LNE_set_discriminator
:
5254 case DW_LNE_HP_set_sequence
:
5255 /* Simply ignored. */
5259 printf (_("UNKNOWN (%u): length %ld\n"),
5260 ext_op_code
, (long int) (op_code_data
- data
));
5267 /* Increment view after printing this row. */
5270 case DW_LNS_advance_pc
:
5271 READ_ULEB (uladv
, data
, end
);
5272 if (linfo
.li_max_ops_per_insn
== 1)
5274 uladv
*= linfo
.li_min_insn_length
;
5275 state_machine_regs
.address
+= uladv
;
5277 state_machine_regs
.view
= 0;
5282 = ((state_machine_regs
.op_index
+ uladv
)
5283 / linfo
.li_max_ops_per_insn
)
5284 * linfo
.li_min_insn_length
;
5285 state_machine_regs
.address
5287 state_machine_regs
.op_index
5288 = (state_machine_regs
.op_index
+ uladv
)
5289 % linfo
.li_max_ops_per_insn
;
5291 state_machine_regs
.view
= 0;
5295 case DW_LNS_advance_line
:
5296 READ_SLEB (adv
, data
, end
);
5297 state_machine_regs
.line
+= adv
;
5300 case DW_LNS_set_file
:
5301 READ_ULEB (uladv
, data
, end
);
5302 state_machine_regs
.file
= uladv
;
5305 unsigned file
= state_machine_regs
.file
;
5308 if (linfo
.li_version
< 5)
5310 if (file_table
== NULL
|| n_files
== 0)
5311 printf (_("\n [Use file table entry %d]\n"), file
);
5313 else if (file
>= n_files
)
5315 warn (_("file index %u > number of files %u\n"), file
, n_files
);
5316 printf (_("\n <over large file table index %u>"), file
);
5318 else if ((dir
= file_table
[file
].directory_index
) == 0)
5319 /* If directory index is 0, that means current directory. */
5320 printf ("\n./%s:[++]\n", file_table
[file
].name
);
5321 else if (directory_table
== NULL
|| n_directories
== 0)
5322 printf (_("\n [Use file %s in directory table entry %d]\n"),
5323 file_table
[file
].name
, dir
);
5325 else if (dir
> n_directories
)
5327 warn (_("directory index %u > number of directories %s\n"),
5328 dir
, dwarf_vmatoa ("u", n_directories
));
5329 printf (_("\n <over large directory table entry %u>\n"), dir
);
5332 printf ("\n%s/%s:\n",
5333 /* The directory index starts counting at 1. */
5334 directory_table
[dir
- 1], file_table
[file
].name
);
5338 case DW_LNS_set_column
:
5339 READ_ULEB (uladv
, data
, end
);
5340 state_machine_regs
.column
= uladv
;
5343 case DW_LNS_negate_stmt
:
5344 adv
= state_machine_regs
.is_stmt
;
5346 state_machine_regs
.is_stmt
= adv
;
5349 case DW_LNS_set_basic_block
:
5350 state_machine_regs
.basic_block
= 1;
5353 case DW_LNS_const_add_pc
:
5354 uladv
= ((255 - linfo
.li_opcode_base
) / linfo
.li_line_range
);
5355 if (linfo
.li_max_ops_per_insn
== 1)
5357 uladv
*= linfo
.li_min_insn_length
;
5358 state_machine_regs
.address
+= uladv
;
5360 state_machine_regs
.view
= 0;
5365 = ((state_machine_regs
.op_index
+ uladv
)
5366 / linfo
.li_max_ops_per_insn
)
5367 * linfo
.li_min_insn_length
;
5368 state_machine_regs
.address
5370 state_machine_regs
.op_index
5371 = (state_machine_regs
.op_index
+ uladv
)
5372 % linfo
.li_max_ops_per_insn
;
5374 state_machine_regs
.view
= 0;
5378 case DW_LNS_fixed_advance_pc
:
5379 SAFE_BYTE_GET_AND_INC (uladv
, data
, 2, end
);
5380 state_machine_regs
.address
+= uladv
;
5381 state_machine_regs
.op_index
= 0;
5382 /* Do NOT reset view. */
5385 case DW_LNS_set_prologue_end
:
5388 case DW_LNS_set_epilogue_begin
:
5391 case DW_LNS_set_isa
:
5392 READ_ULEB (uladv
, data
, end
);
5393 printf (_(" Set ISA to %lu\n"), uladv
);
5397 printf (_(" Unknown opcode %d with operands: "), op_code
);
5399 if (standard_opcodes
!= NULL
)
5400 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
5404 READ_ULEB (val
, data
, end
);
5405 printf ("0x%s%s", dwarf_vmatoa ("x", val
),
5406 i
== 1 ? "" : ", ");
5412 /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row
5413 to the DWARF address/line matrix. */
5414 if ((is_special_opcode
) || (xop
== -DW_LNE_end_sequence
)
5415 || (xop
== DW_LNS_copy
))
5417 const unsigned int MAX_FILENAME_LENGTH
= 35;
5419 char *newFileName
= NULL
;
5420 size_t fileNameLength
;
5424 unsigned indx
= state_machine_regs
.file
;
5426 if (linfo
.li_version
< 5)
5429 if (indx
>= n_files
)
5431 warn (_("corrupt file index %u encountered\n"), indx
);
5432 fileName
= _("<corrupt>");
5435 fileName
= (char *) file_table
[indx
].name
;
5438 fileName
= _("<unknown>");
5440 fileNameLength
= strlen (fileName
);
5441 newFileName
= fileName
;
5442 if (fileNameLength
> MAX_FILENAME_LENGTH
&& !do_wide
)
5444 newFileName
= (char *) xmalloc (MAX_FILENAME_LENGTH
+ 1);
5445 /* Truncate file name */
5446 memcpy (newFileName
,
5447 fileName
+ fileNameLength
- MAX_FILENAME_LENGTH
,
5448 MAX_FILENAME_LENGTH
);
5449 newFileName
[MAX_FILENAME_LENGTH
] = 0;
5452 /* A row with end_seq set to true has a meaningful address, but
5453 the other information in the same row is not significant.
5454 In such a row, print line as "-", and don't print
5456 if (!do_wide
|| fileNameLength
<= MAX_FILENAME_LENGTH
)
5458 if (linfo
.li_max_ops_per_insn
== 1)
5460 if (xop
== -DW_LNE_end_sequence
)
5461 printf ("%-35s %11s %#18" DWARF_VMA_FMT
"x",
5463 state_machine_regs
.address
);
5465 printf ("%-35s %11d %#18" DWARF_VMA_FMT
"x",
5466 newFileName
, state_machine_regs
.line
,
5467 state_machine_regs
.address
);
5471 if (xop
== -DW_LNE_end_sequence
)
5472 printf ("%-35s %11s %#18" DWARF_VMA_FMT
"x[%d]",
5474 state_machine_regs
.address
,
5475 state_machine_regs
.op_index
);
5477 printf ("%-35s %11d %#18" DWARF_VMA_FMT
"x[%d]",
5478 newFileName
, state_machine_regs
.line
,
5479 state_machine_regs
.address
,
5480 state_machine_regs
.op_index
);
5485 if (linfo
.li_max_ops_per_insn
== 1)
5487 if (xop
== -DW_LNE_end_sequence
)
5488 printf ("%s %11s %#18" DWARF_VMA_FMT
"x",
5490 state_machine_regs
.address
);
5492 printf ("%s %11d %#18" DWARF_VMA_FMT
"x",
5493 newFileName
, state_machine_regs
.line
,
5494 state_machine_regs
.address
);
5498 if (xop
== -DW_LNE_end_sequence
)
5499 printf ("%s %11s %#18" DWARF_VMA_FMT
"x[%d]",
5501 state_machine_regs
.address
,
5502 state_machine_regs
.op_index
);
5504 printf ("%s %11d %#18" DWARF_VMA_FMT
"x[%d]",
5505 newFileName
, state_machine_regs
.line
,
5506 state_machine_regs
.address
,
5507 state_machine_regs
.op_index
);
5511 if (xop
!= -DW_LNE_end_sequence
)
5513 if (state_machine_regs
.view
)
5514 printf (" %6u", state_machine_regs
.view
);
5518 if (state_machine_regs
.is_stmt
)
5523 state_machine_regs
.view
++;
5525 if (xop
== -DW_LNE_end_sequence
)
5527 reset_state_machine (linfo
.li_default_is_stmt
);
5531 if (newFileName
!= fileName
)
5543 if (directory_table
)
5545 free (directory_table
);
5546 directory_table
= NULL
;
5557 display_debug_lines (struct dwarf_section
*section
, void *file
)
5559 unsigned char *data
= section
->start
;
5560 unsigned char *end
= data
+ section
->size
;
5562 int retValDecoded
= 1;
5564 if (do_debug_lines
== 0)
5565 do_debug_lines
|= FLAG_DEBUG_LINES_RAW
;
5567 if (do_debug_lines
& FLAG_DEBUG_LINES_RAW
)
5568 retValRaw
= display_debug_lines_raw (section
, data
, end
, file
);
5570 if (do_debug_lines
& FLAG_DEBUG_LINES_DECODED
)
5571 retValDecoded
= display_debug_lines_decoded (section
, data
, data
, end
, file
);
5573 if (!retValRaw
|| !retValDecoded
)
5580 find_debug_info_for_offset (dwarf_vma offset
)
5584 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
5587 for (i
= 0; i
< num_debug_info_entries
; i
++)
5588 if (debug_information
[i
].cu_offset
== offset
)
5589 return debug_information
+ i
;
5595 get_gdb_index_symbol_kind_name (gdb_index_symbol_kind kind
)
5597 /* See gdb/gdb-index.h. */
5598 static const char * const kinds
[] =
5610 return _ (kinds
[kind
]);
5614 display_debug_pubnames_worker (struct dwarf_section
*section
,
5615 void *file ATTRIBUTE_UNUSED
,
5618 DWARF2_Internal_PubNames names
;
5619 unsigned char *start
= section
->start
;
5620 unsigned char *end
= start
+ section
->size
;
5622 /* It does not matter if this load fails,
5623 we test for that later on. */
5624 load_debug_info (file
);
5626 introduce (section
, false);
5630 unsigned char *data
;
5631 unsigned long sec_off
= start
- section
->start
;
5632 unsigned int offset_size
;
5634 SAFE_BYTE_GET_AND_INC (names
.pn_length
, start
, 4, end
);
5635 if (names
.pn_length
== 0xffffffff)
5637 SAFE_BYTE_GET_AND_INC (names
.pn_length
, start
, 8, end
);
5643 if (names
.pn_length
> (size_t) (end
- start
))
5645 warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"),
5648 dwarf_vmatoa ("x", names
.pn_length
));
5653 start
+= names
.pn_length
;
5655 SAFE_BYTE_GET_AND_INC (names
.pn_version
, data
, 2, start
);
5656 SAFE_BYTE_GET_AND_INC (names
.pn_offset
, data
, offset_size
, start
);
5658 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
5659 && num_debug_info_entries
> 0
5660 && find_debug_info_for_offset (names
.pn_offset
) == NULL
)
5661 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
5662 (unsigned long) names
.pn_offset
, section
->name
);
5664 SAFE_BYTE_GET_AND_INC (names
.pn_size
, data
, offset_size
, start
);
5666 printf (_(" Length: %ld\n"),
5667 (long) names
.pn_length
);
5668 printf (_(" Version: %d\n"),
5670 printf (_(" Offset into .debug_info section: 0x%lx\n"),
5671 (unsigned long) names
.pn_offset
);
5672 printf (_(" Size of area in .debug_info section: %ld\n"),
5673 (long) names
.pn_size
);
5675 if (names
.pn_version
!= 2 && names
.pn_version
!= 3)
5677 static int warned
= 0;
5681 warn (_("Only DWARF 2 and 3 pubnames are currently supported\n"));
5689 printf (_("\n Offset Kind Name\n"));
5691 printf (_("\n Offset\tName\n"));
5695 bfd_size_type maxprint
;
5698 SAFE_BYTE_GET_AND_INC (offset
, data
, offset_size
, start
);
5705 maxprint
= (start
- data
) - 1;
5709 unsigned int kind_data
;
5710 gdb_index_symbol_kind kind
;
5711 const char *kind_name
;
5714 SAFE_BYTE_GET_AND_INC (kind_data
, data
, 1, start
);
5716 /* GCC computes the kind as the upper byte in the CU index
5717 word, and then right shifts it by the CU index size.
5718 Left shift KIND to where the gdb-index.h accessor macros
5720 kind_data
<<= GDB_INDEX_CU_BITSIZE
;
5721 kind
= GDB_INDEX_SYMBOL_KIND_VALUE (kind_data
);
5722 kind_name
= get_gdb_index_symbol_kind_name (kind
);
5723 is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (kind_data
);
5724 printf (" %-6lx %s,%-10s %.*s\n",
5725 (unsigned long) offset
, is_static
? _("s") : _("g"),
5726 kind_name
, (int) maxprint
, data
);
5729 printf (" %-6lx\t%.*s\n",
5730 (unsigned long) offset
, (int) maxprint
, data
);
5732 data
+= strnlen ((char *) data
, maxprint
);
5745 display_debug_pubnames (struct dwarf_section
*section
, void *file
)
5747 return display_debug_pubnames_worker (section
, file
, 0);
5751 display_debug_gnu_pubnames (struct dwarf_section
*section
, void *file
)
5753 return display_debug_pubnames_worker (section
, file
, 1);
5757 display_debug_macinfo (struct dwarf_section
*section
,
5758 void *file ATTRIBUTE_UNUSED
)
5760 unsigned char *start
= section
->start
;
5761 unsigned char *end
= start
+ section
->size
;
5762 unsigned char *curr
= start
;
5763 enum dwarf_macinfo_record_type op
;
5765 introduce (section
, false);
5769 unsigned int lineno
;
5770 const unsigned char *string
;
5772 op
= (enum dwarf_macinfo_record_type
) *curr
;
5777 case DW_MACINFO_start_file
:
5779 unsigned int filenum
;
5781 READ_ULEB (lineno
, curr
, end
);
5782 READ_ULEB (filenum
, curr
, end
);
5783 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"),
5788 case DW_MACINFO_end_file
:
5789 printf (_(" DW_MACINFO_end_file\n"));
5792 case DW_MACINFO_define
:
5793 READ_ULEB (lineno
, curr
, end
);
5795 curr
+= strnlen ((char *) string
, end
- string
);
5796 printf (_(" DW_MACINFO_define - lineno : %d macro : %*s\n"),
5797 lineno
, (int) (curr
- string
), string
);
5802 case DW_MACINFO_undef
:
5803 READ_ULEB (lineno
, curr
, end
);
5805 curr
+= strnlen ((char *) string
, end
- string
);
5806 printf (_(" DW_MACINFO_undef - lineno : %d macro : %*s\n"),
5807 lineno
, (int) (curr
- string
), string
);
5812 case DW_MACINFO_vendor_ext
:
5814 unsigned int constant
;
5816 READ_ULEB (constant
, curr
, end
);
5818 curr
+= strnlen ((char *) string
, end
- string
);
5819 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %*s\n"),
5820 constant
, (int) (curr
- string
), string
);
5831 /* Given LINE_OFFSET into the .debug_line section, attempt to return
5832 filename and dirname corresponding to file name table entry with index
5833 FILEIDX. Return NULL on failure. */
5835 static unsigned char *
5836 get_line_filename_and_dirname (dwarf_vma line_offset
,
5838 unsigned char **dir_name
)
5840 struct dwarf_section
*section
= &debug_displays
[line
].section
;
5841 unsigned char *hdrptr
, *dirtable
, *file_name
;
5842 unsigned int offset_size
;
5843 unsigned int version
, opcode_base
;
5844 dwarf_vma length
, diridx
;
5845 const unsigned char * end
;
5848 if (section
->start
== NULL
5849 || line_offset
>= section
->size
5853 hdrptr
= section
->start
+ line_offset
;
5854 end
= section
->start
+ section
->size
;
5856 SAFE_BYTE_GET_AND_INC (length
, hdrptr
, 4, end
);
5857 if (length
== 0xffffffff)
5859 /* This section is 64-bit DWARF 3. */
5860 SAFE_BYTE_GET_AND_INC (length
, hdrptr
, 8, end
);
5866 if (length
> (size_t) (end
- hdrptr
)
5867 || length
< 2 + offset_size
+ 1 + 3 + 1)
5869 end
= hdrptr
+ length
;
5871 SAFE_BYTE_GET_AND_INC (version
, hdrptr
, 2, end
);
5872 if (version
!= 2 && version
!= 3 && version
!= 4)
5874 hdrptr
+= offset_size
+ 1;/* Skip prologue_length and min_insn_length. */
5876 hdrptr
++; /* Skip max_ops_per_insn. */
5877 hdrptr
+= 3; /* Skip default_is_stmt, line_base, line_range. */
5879 SAFE_BYTE_GET_AND_INC (opcode_base
, hdrptr
, 1, end
);
5880 if (opcode_base
== 0
5881 || opcode_base
- 1 >= (size_t) (end
- hdrptr
))
5884 hdrptr
+= opcode_base
- 1;
5887 /* Skip over dirname table. */
5888 while (*hdrptr
!= '\0')
5890 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
);
5896 hdrptr
++; /* Skip the NUL at the end of the table. */
5898 /* Now skip over preceding filename table entries. */
5899 for (; hdrptr
< end
&& *hdrptr
!= '\0' && fileidx
> 1; fileidx
--)
5901 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
);
5904 SKIP_ULEB (hdrptr
, end
);
5905 SKIP_ULEB (hdrptr
, end
);
5906 SKIP_ULEB (hdrptr
, end
);
5908 if (hdrptr
>= end
|| *hdrptr
== '\0')
5912 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
);
5917 READ_ULEB (diridx
, hdrptr
, end
);
5920 for (; dirtable
< end
&& *dirtable
!= '\0' && diridx
> 1; diridx
--)
5922 dirtable
+= strnlen ((char *) dirtable
, end
- dirtable
);
5926 if (dirtable
>= end
|| *dirtable
== '\0')
5928 *dir_name
= dirtable
;
5933 display_debug_macro (struct dwarf_section
*section
,
5936 unsigned char *start
= section
->start
;
5937 unsigned char *end
= start
+ section
->size
;
5938 unsigned char *curr
= start
;
5939 unsigned char *extended_op_buf
[256];
5940 bool is_dwo
= false;
5941 const char *suffix
= strrchr (section
->name
, '.');
5943 if (suffix
&& strcmp (suffix
, ".dwo") == 0)
5946 load_debug_section_with_follow (str
, file
);
5947 load_debug_section_with_follow (line
, file
);
5948 load_debug_section_with_follow (str_index
, file
);
5950 introduce (section
, false);
5954 unsigned int lineno
, version
, flags
;
5955 unsigned int offset_size
;
5956 const unsigned char *string
;
5957 dwarf_vma line_offset
= 0, sec_offset
= curr
- start
, offset
;
5958 unsigned char **extended_ops
= NULL
;
5960 SAFE_BYTE_GET_AND_INC (version
, curr
, 2, end
);
5961 if (version
!= 4 && version
!= 5)
5963 error (_("Expected to find a version number of 4 or 5 in section %s but found %d instead\n"),
5964 section
->name
, version
);
5968 SAFE_BYTE_GET_AND_INC (flags
, curr
, 1, end
);
5969 offset_size
= (flags
& 1) ? 8 : 4;
5970 printf (_(" Offset: 0x%lx\n"),
5971 (unsigned long) sec_offset
);
5972 printf (_(" Version: %d\n"), version
);
5973 printf (_(" Offset size: %d\n"), offset_size
);
5976 SAFE_BYTE_GET_AND_INC (line_offset
, curr
, offset_size
, end
);
5977 printf (_(" Offset into .debug_line: 0x%lx\n"),
5978 (unsigned long) line_offset
);
5982 unsigned int i
, count
, op
;
5985 SAFE_BYTE_GET_AND_INC (count
, curr
, 1, end
);
5987 memset (extended_op_buf
, 0, sizeof (extended_op_buf
));
5988 extended_ops
= extended_op_buf
;
5991 printf (_(" Extension opcode arguments:\n"));
5992 for (i
= 0; i
< count
; i
++)
5994 SAFE_BYTE_GET_AND_INC (op
, curr
, 1, end
);
5995 extended_ops
[op
] = curr
;
5996 READ_ULEB (nargs
, curr
, end
);
5998 printf (_(" DW_MACRO_%02x has no arguments\n"), op
);
6001 printf (_(" DW_MACRO_%02x arguments: "), op
);
6002 for (n
= 0; n
< nargs
; n
++)
6006 SAFE_BYTE_GET_AND_INC (form
, curr
, 1, end
);
6007 printf ("%s%s", get_FORM_name (form
),
6008 n
== nargs
- 1 ? "\n" : ", ");
6018 case DW_FORM_block1
:
6019 case DW_FORM_block2
:
6020 case DW_FORM_block4
:
6022 case DW_FORM_string
:
6024 case DW_FORM_sec_offset
:
6027 error (_("Invalid extension opcode form %s\n"),
6028 get_FORM_name (form
));
6044 error (_(".debug_macro section not zero terminated\n"));
6048 SAFE_BYTE_GET_AND_INC (op
, curr
, 1, end
);
6054 case DW_MACRO_define
:
6055 READ_ULEB (lineno
, curr
, end
);
6057 curr
+= strnlen ((char *) string
, end
- string
);
6058 printf (_(" DW_MACRO_define - lineno : %d macro : %*s\n"),
6059 lineno
, (int) (curr
- string
), string
);
6064 case DW_MACRO_undef
:
6065 READ_ULEB (lineno
, curr
, end
);
6067 curr
+= strnlen ((char *) string
, end
- string
);
6068 printf (_(" DW_MACRO_undef - lineno : %d macro : %*s\n"),
6069 lineno
, (int) (curr
- string
), string
);
6074 case DW_MACRO_start_file
:
6076 unsigned int filenum
;
6077 unsigned char *file_name
= NULL
, *dir_name
= NULL
;
6079 READ_ULEB (lineno
, curr
, end
);
6080 READ_ULEB (filenum
, curr
, end
);
6082 if ((flags
& 2) == 0)
6083 error (_("DW_MACRO_start_file used, but no .debug_line offset provided.\n"));
6086 = get_line_filename_and_dirname (line_offset
, filenum
,
6088 if (file_name
== NULL
)
6089 printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d\n"),
6092 printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d filename: %s%s%s\n"),
6094 dir_name
!= NULL
? (const char *) dir_name
: "",
6095 dir_name
!= NULL
? "/" : "", file_name
);
6099 case DW_MACRO_end_file
:
6100 printf (_(" DW_MACRO_end_file\n"));
6103 case DW_MACRO_define_strp
:
6104 READ_ULEB (lineno
, curr
, end
);
6105 if (version
== 4 && is_dwo
)
6106 READ_ULEB (offset
, curr
, end
);
6108 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6109 string
= fetch_indirect_string (offset
);
6110 printf (_(" DW_MACRO_define_strp - lineno : %d macro : %s\n"),
6114 case DW_MACRO_undef_strp
:
6115 READ_ULEB (lineno
, curr
, end
);
6116 if (version
== 4 && is_dwo
)
6117 READ_ULEB (offset
, curr
, end
);
6119 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6120 string
= fetch_indirect_string (offset
);
6121 printf (_(" DW_MACRO_undef_strp - lineno : %d macro : %s\n"),
6125 case DW_MACRO_import
:
6126 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6127 printf (_(" DW_MACRO_import - offset : 0x%lx\n"),
6128 (unsigned long) offset
);
6131 case DW_MACRO_define_sup
:
6132 READ_ULEB (lineno
, curr
, end
);
6133 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6134 printf (_(" DW_MACRO_define_sup - lineno : %d macro offset : 0x%lx\n"),
6135 lineno
, (unsigned long) offset
);
6138 case DW_MACRO_undef_sup
:
6139 READ_ULEB (lineno
, curr
, end
);
6140 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6141 printf (_(" DW_MACRO_undef_sup - lineno : %d macro offset : 0x%lx\n"),
6142 lineno
, (unsigned long) offset
);
6145 case DW_MACRO_import_sup
:
6146 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6147 printf (_(" DW_MACRO_import_sup - offset : 0x%lx\n"),
6148 (unsigned long) offset
);
6151 case DW_MACRO_define_strx
:
6152 case DW_MACRO_undef_strx
:
6153 READ_ULEB (lineno
, curr
, end
);
6154 READ_ULEB (offset
, curr
, end
);
6155 string
= (const unsigned char *)
6156 fetch_indexed_string (offset
, NULL
, offset_size
, false);
6157 if (op
== DW_MACRO_define_strx
)
6158 printf (" DW_MACRO_define_strx ");
6160 printf (" DW_MACRO_undef_strx ");
6162 printf (_("(with offset %s) "), dwarf_vmatoa ("x", offset
));
6163 printf (_("lineno : %d macro : %s\n"),
6168 if (op
>= DW_MACRO_lo_user
&& op
<= DW_MACRO_hi_user
)
6170 printf (_(" <Target Specific macro op: %#x - UNHANDLED"), op
);
6174 if (extended_ops
== NULL
|| extended_ops
[op
] == NULL
)
6176 error (_(" Unknown macro opcode %02x seen\n"), op
);
6181 /* Skip over unhandled opcodes. */
6183 unsigned char *desc
= extended_ops
[op
];
6184 READ_ULEB (nargs
, desc
, end
);
6187 printf (_(" DW_MACRO_%02x\n"), op
);
6190 printf (_(" DW_MACRO_%02x -"), op
);
6191 for (n
= 0; n
< nargs
; n
++)
6195 /* DW_FORM_implicit_const is not expected here. */
6196 SAFE_BYTE_GET_AND_INC (val
, desc
, 1, end
);
6198 = read_and_display_attr_value (0, val
, 0,
6199 start
, curr
, end
, 0, 0, offset_size
,
6200 version
, NULL
, 0, NULL
,
6218 display_debug_abbrev (struct dwarf_section
*section
,
6219 void *file ATTRIBUTE_UNUSED
)
6221 abbrev_entry
*entry
;
6222 unsigned char *start
= section
->start
;
6224 introduce (section
, false);
6231 offset
= start
- section
->start
;
6232 list
= find_abbrev_list_by_abbrev_offset (0, offset
);
6235 list
= new_abbrev_list (0, offset
);
6236 start
= process_abbrev_set (section
, 0, section
->size
, offset
, list
);
6237 list
->start_of_next_abbrevs
= start
;
6240 start
= list
->start_of_next_abbrevs
;
6242 if (list
->first_abbrev
== NULL
)
6245 printf (_(" Number TAG (0x%lx)\n"), (long) offset
);
6247 for (entry
= list
->first_abbrev
; entry
; entry
= entry
->next
)
6251 printf (" %ld %s [%s]\n",
6253 get_TAG_name (entry
->tag
),
6254 entry
->children
? _("has children") : _("no children"));
6256 for (attr
= entry
->first_attr
; attr
; attr
= attr
->next
)
6258 printf (" %-18s %s",
6259 get_AT_name (attr
->attribute
),
6260 get_FORM_name (attr
->form
));
6261 if (attr
->form
== DW_FORM_implicit_const
)
6262 printf (": %s", dwarf_vmatoa ("d", attr
->implicit_const
));
6274 /* Return true when ADDR is the maximum address, when addresses are
6275 POINTER_SIZE bytes long. */
6278 is_max_address (dwarf_vma addr
, unsigned int pointer_size
)
6280 dwarf_vma mask
= ~(~(dwarf_vma
) 1 << (pointer_size
* 8 - 1));
6281 return ((addr
& mask
) == mask
);
6284 /* Display a view pair list starting at *VSTART_PTR and ending at
6285 VLISTEND within SECTION. */
6288 display_view_pair_list (struct dwarf_section
*section
,
6289 unsigned char **vstart_ptr
,
6290 unsigned int debug_info_entry
,
6291 unsigned char *vlistend
)
6293 unsigned char *vstart
= *vstart_ptr
;
6294 unsigned char *section_end
= section
->start
+ section
->size
;
6295 unsigned int pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
6297 if (vlistend
< section_end
)
6298 section_end
= vlistend
;
6302 while (vstart
< section_end
)
6304 dwarf_vma off
= vstart
- section
->start
;
6305 dwarf_vma vbegin
, vend
;
6307 READ_ULEB (vbegin
, vstart
, section_end
);
6308 if (vstart
== section_end
)
6311 READ_ULEB (vend
, vstart
, section_end
);
6312 printf (" %8.8lx ", (unsigned long) off
);
6314 print_dwarf_view (vbegin
, pointer_size
, 1);
6315 print_dwarf_view (vend
, pointer_size
, 1);
6316 printf (_("location view pair\n"));
6320 *vstart_ptr
= vstart
;
6323 /* Display a location list from a normal (ie, non-dwo) .debug_loc section. */
6326 display_loc_list (struct dwarf_section
*section
,
6327 unsigned char **start_ptr
,
6328 unsigned int debug_info_entry
,
6330 dwarf_vma base_address
,
6331 unsigned char **vstart_ptr
,
6334 unsigned char *start
= *start_ptr
, *vstart
= *vstart_ptr
;
6335 unsigned char *section_end
= section
->start
+ section
->size
;
6336 dwarf_vma cu_offset
;
6337 unsigned int pointer_size
;
6338 unsigned int offset_size
;
6342 unsigned short length
;
6343 int need_frame_base
;
6345 if (debug_info_entry
>= num_debug_info_entries
)
6347 warn (_("No debug information available for loc lists of entry: %u\n"),
6352 cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
6353 pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
6354 offset_size
= debug_information
[debug_info_entry
].offset_size
;
6355 dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
6357 if (pointer_size
< 2 || pointer_size
> 8)
6359 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
6360 pointer_size
, debug_info_entry
);
6366 dwarf_vma off
= offset
+ (start
- *start_ptr
);
6367 dwarf_vma vbegin
= vm1
, vend
= vm1
;
6369 if (2 * pointer_size
> (size_t) (section_end
- start
))
6371 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6372 (unsigned long) offset
);
6377 print_dwarf_vma (off
, 4);
6379 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, section_end
);
6380 SAFE_BYTE_GET_AND_INC (end
, start
, pointer_size
, section_end
);
6382 if (begin
== 0 && end
== 0)
6384 /* PR 18374: In a object file we can have a location list that
6385 starts with a begin and end of 0 because there are relocations
6386 that need to be applied to the addresses. Actually applying
6387 the relocations now does not help as they will probably resolve
6388 to 0, since the object file has not been fully linked. Real
6389 end of list markers will not have any relocations against them. */
6390 if (! reloc_at (section
, off
)
6391 && ! reloc_at (section
, off
+ pointer_size
))
6393 printf (_("<End of list>\n"));
6398 /* Check base address specifiers. */
6399 if (is_max_address (begin
, pointer_size
)
6400 && !is_max_address (end
, pointer_size
))
6403 print_dwarf_vma (begin
, pointer_size
);
6404 print_dwarf_vma (end
, pointer_size
);
6405 printf (_("(base address)\n"));
6411 off
= offset
+ (vstart
- *start_ptr
);
6413 READ_ULEB (vbegin
, vstart
, section_end
);
6414 print_dwarf_view (vbegin
, pointer_size
, 1);
6416 READ_ULEB (vend
, vstart
, section_end
);
6417 print_dwarf_view (vend
, pointer_size
, 1);
6419 printf (_("views at %8.8lx for:\n %*s "),
6420 (unsigned long) off
, 8, "");
6423 if (2 > (size_t) (section_end
- start
))
6425 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6426 (unsigned long) offset
);
6430 SAFE_BYTE_GET_AND_INC (length
, start
, 2, section_end
);
6432 if (length
> (size_t) (section_end
- start
))
6434 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6435 (unsigned long) offset
);
6439 print_dwarf_vma (begin
+ base_address
, pointer_size
);
6440 print_dwarf_vma (end
+ base_address
, pointer_size
);
6443 need_frame_base
= decode_location_expression (start
,
6448 cu_offset
, section
);
6451 if (need_frame_base
&& !has_frame_base
)
6452 printf (_(" [without DW_AT_frame_base]"));
6454 if (begin
== end
&& vbegin
== vend
)
6455 fputs (_(" (start == end)"), stdout
);
6456 else if (begin
> end
|| (begin
== end
&& vbegin
> vend
))
6457 fputs (_(" (start > end)"), stdout
);
6465 *vstart_ptr
= vstart
;
6468 /* Display a location list from a normal (ie, non-dwo) .debug_loclists section. */
6471 display_loclists_list (struct dwarf_section
*section
,
6472 unsigned char **start_ptr
,
6473 unsigned int debug_info_entry
,
6475 dwarf_vma base_address
,
6476 unsigned char **vstart_ptr
,
6479 unsigned char *start
= *start_ptr
, *vstart
= *vstart_ptr
;
6480 unsigned char *section_end
= section
->start
+ section
->size
;
6481 dwarf_vma cu_offset
;
6482 unsigned int pointer_size
;
6483 unsigned int offset_size
;
6486 /* Initialize it due to a false compiler warning. */
6487 dwarf_vma begin
= -1, vbegin
= -1;
6488 dwarf_vma end
= -1, vend
= -1;
6490 int need_frame_base
;
6492 if (debug_info_entry
>= num_debug_info_entries
)
6494 warn (_("No debug information available for "
6495 "loclists lists of entry: %u\n"),
6500 cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
6501 pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
6502 offset_size
= debug_information
[debug_info_entry
].offset_size
;
6503 dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
6505 if (pointer_size
< 2 || pointer_size
> 8)
6507 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
6508 pointer_size
, debug_info_entry
);
6514 dwarf_vma off
= offset
+ (start
- *start_ptr
);
6515 enum dwarf_location_list_entry_type llet
;
6517 if (start
+ 1 > section_end
)
6519 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6520 (unsigned long) offset
);
6525 print_dwarf_vma (off
, 4);
6527 SAFE_BYTE_GET_AND_INC (llet
, start
, 1, section_end
);
6529 if (vstart
&& (llet
== DW_LLE_offset_pair
6530 || llet
== DW_LLE_start_end
6531 || llet
== DW_LLE_start_length
))
6533 off
= offset
+ (vstart
- *start_ptr
);
6535 READ_ULEB (vbegin
, vstart
, section_end
);
6536 print_dwarf_view (vbegin
, pointer_size
, 1);
6538 READ_ULEB (vend
, vstart
, section_end
);
6539 print_dwarf_view (vend
, pointer_size
, 1);
6541 printf (_("views at %8.8lx for:\n %*s "),
6542 (unsigned long) off
, 8, "");
6547 case DW_LLE_end_of_list
:
6548 printf (_("<End of list>\n"));
6550 case DW_LLE_offset_pair
:
6551 READ_ULEB (begin
, start
, section_end
);
6552 begin
+= base_address
;
6553 READ_ULEB (end
, start
, section_end
);
6554 end
+= base_address
;
6556 case DW_LLE_start_end
:
6557 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, section_end
);
6558 SAFE_BYTE_GET_AND_INC (end
, start
, pointer_size
, section_end
);
6560 case DW_LLE_start_length
:
6561 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, section_end
);
6562 READ_ULEB (end
, start
, section_end
);
6565 case DW_LLE_base_address
:
6566 SAFE_BYTE_GET_AND_INC (base_address
, start
, pointer_size
,
6568 print_dwarf_vma (base_address
, pointer_size
);
6569 printf (_("(base address)\n"));
6571 #ifdef DW_LLE_view_pair
6572 case DW_LLE_view_pair
:
6574 printf (_("View pair entry in loclist with locviews attribute\n"));
6575 READ_ULEB (vbegin
, start
, section_end
);
6576 print_dwarf_view (vbegin
, pointer_size
, 1);
6578 READ_ULEB (vend
, start
, section_end
);
6579 print_dwarf_view (vend
, pointer_size
, 1);
6581 printf (_("views for:\n"));
6585 error (_("Invalid location list entry type %d\n"), llet
);
6588 if (llet
== DW_LLE_end_of_list
)
6590 if (llet
!= DW_LLE_offset_pair
6591 && llet
!= DW_LLE_start_end
6592 && llet
!= DW_LLE_start_length
)
6595 if (start
== section_end
)
6597 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6598 (unsigned long) offset
);
6601 READ_ULEB (length
, start
, section_end
);
6603 if (length
> (size_t) (section_end
- start
))
6605 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6606 (unsigned long) offset
);
6610 print_dwarf_vma (begin
, pointer_size
);
6611 print_dwarf_vma (end
, pointer_size
);
6614 need_frame_base
= decode_location_expression (start
,
6619 cu_offset
, section
);
6622 if (need_frame_base
&& !has_frame_base
)
6623 printf (_(" [without DW_AT_frame_base]"));
6625 if (begin
== end
&& vbegin
== vend
)
6626 fputs (_(" (start == end)"), stdout
);
6627 else if (begin
> end
|| (begin
== end
&& vbegin
> vend
))
6628 fputs (_(" (start > end)"), stdout
);
6636 if (vbegin
!= vm1
|| vend
!= vm1
)
6637 printf (_("Trailing view pair not used in a range"));
6640 *vstart_ptr
= vstart
;
6643 /* Print a .debug_addr table index in decimal, surrounded by square brackets,
6644 right-adjusted in a field of length LEN, and followed by a space. */
6647 print_addr_index (unsigned int idx
, unsigned int len
)
6649 static char buf
[15];
6650 snprintf (buf
, sizeof (buf
), "[%d]", idx
);
6651 printf ("%*s ", len
, buf
);
6654 /* Display a location list from a .dwo section. It uses address indexes rather
6655 than embedded addresses. This code closely follows display_loc_list, but the
6656 two are sufficiently different that combining things is very ugly. */
6659 display_loc_list_dwo (struct dwarf_section
*section
,
6660 unsigned char **start_ptr
,
6661 unsigned int debug_info_entry
,
6663 unsigned char **vstart_ptr
,
6666 unsigned char *start
= *start_ptr
, *vstart
= *vstart_ptr
;
6667 unsigned char *section_end
= section
->start
+ section
->size
;
6668 dwarf_vma cu_offset
;
6669 unsigned int pointer_size
;
6670 unsigned int offset_size
;
6673 unsigned short length
;
6674 int need_frame_base
;
6677 if (debug_info_entry
>= num_debug_info_entries
)
6679 warn (_("No debug information for loc lists of entry: %u\n"),
6684 cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
6685 pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
6686 offset_size
= debug_information
[debug_info_entry
].offset_size
;
6687 dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
6689 if (pointer_size
< 2 || pointer_size
> 8)
6691 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
6692 pointer_size
, debug_info_entry
);
6699 print_dwarf_vma (offset
+ (start
- *start_ptr
), 4);
6701 if (start
>= section_end
)
6703 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6704 (unsigned long) offset
);
6708 SAFE_BYTE_GET_AND_INC (entry_type
, start
, 1, section_end
);
6721 dwarf_vma off
= offset
+ (vstart
- *start_ptr
);
6723 READ_ULEB (view
, vstart
, section_end
);
6724 print_dwarf_view (view
, 8, 1);
6726 READ_ULEB (view
, vstart
, section_end
);
6727 print_dwarf_view (view
, 8, 1);
6729 printf (_("views at %8.8lx for:\n %*s "),
6730 (unsigned long) off
, 8, "");
6738 case 0: /* A terminating entry. */
6740 *vstart_ptr
= vstart
;
6741 printf (_("<End of list>\n"));
6743 case 1: /* A base-address entry. */
6744 READ_ULEB (idx
, start
, section_end
);
6745 print_addr_index (idx
, 8);
6746 printf ("%*s", 9 + (vstart
? 2 * 6 : 0), "");
6747 printf (_("(base address selection entry)\n"));
6749 case 2: /* A start/end entry. */
6750 READ_ULEB (idx
, start
, section_end
);
6751 print_addr_index (idx
, 8);
6752 READ_ULEB (idx
, start
, section_end
);
6753 print_addr_index (idx
, 8);
6755 case 3: /* A start/length entry. */
6756 READ_ULEB (idx
, start
, section_end
);
6757 print_addr_index (idx
, 8);
6758 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
6759 printf ("%08x ", idx
);
6761 case 4: /* An offset pair entry. */
6762 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
6763 printf ("%08x ", idx
);
6764 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
6765 printf ("%08x ", idx
);
6768 warn (_("Unknown location list entry type 0x%x.\n"), entry_type
);
6770 *vstart_ptr
= vstart
;
6774 if (2 > (size_t) (section_end
- start
))
6776 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6777 (unsigned long) offset
);
6781 SAFE_BYTE_GET_AND_INC (length
, start
, 2, section_end
);
6782 if (length
> (size_t) (section_end
- start
))
6784 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6785 (unsigned long) offset
);
6790 need_frame_base
= decode_location_expression (start
,
6795 cu_offset
, section
);
6798 if (need_frame_base
&& !has_frame_base
)
6799 printf (_(" [without DW_AT_frame_base]"));
6807 *vstart_ptr
= vstart
;
6810 /* Sort array of indexes in ascending order of loc_offsets[idx] and
6813 static dwarf_vma
*loc_offsets
, *loc_views
;
6816 loc_offsets_compar (const void *ap
, const void *bp
)
6818 dwarf_vma a
= loc_offsets
[*(const unsigned int *) ap
];
6819 dwarf_vma b
= loc_offsets
[*(const unsigned int *) bp
];
6821 int ret
= (a
> b
) - (b
> a
);
6825 a
= loc_views
[*(const unsigned int *) ap
];
6826 b
= loc_views
[*(const unsigned int *) bp
];
6828 ret
= (a
> b
) - (b
> a
);
6834 display_debug_loc (struct dwarf_section
*section
, void *file
)
6836 unsigned char *start
= section
->start
, *vstart
= NULL
;
6838 unsigned char *section_begin
= start
;
6839 unsigned int num_loc_list
= 0;
6840 dwarf_vma last_offset
= 0;
6841 dwarf_vma last_view
= 0;
6842 unsigned int first
= 0;
6845 int seen_first_offset
= 0;
6846 int locs_sorted
= 1;
6847 unsigned char *next
= start
, *vnext
= vstart
;
6848 unsigned int *array
= NULL
;
6849 const char *suffix
= strrchr (section
->name
, '.');
6850 bool is_dwo
= false;
6851 int is_loclists
= strstr (section
->name
, "debug_loclists") != NULL
;
6852 dwarf_vma expected_start
= 0;
6854 if (suffix
&& strcmp (suffix
, ".dwo") == 0)
6857 bytes
= section
->size
;
6861 printf (_("\nThe %s section is empty.\n"), section
->name
);
6867 unsigned char *hdrptr
= section_begin
;
6868 dwarf_vma ll_length
;
6869 unsigned short ll_version
;
6870 unsigned char *end
= section_begin
+ section
->size
;
6871 unsigned char address_size
, segment_selector_size
;
6872 uint32_t offset_entry_count
;
6874 SAFE_BYTE_GET_AND_INC (ll_length
, hdrptr
, 4, end
);
6875 if (ll_length
== 0xffffffff)
6876 SAFE_BYTE_GET_AND_INC (ll_length
, hdrptr
, 8, end
);
6878 SAFE_BYTE_GET_AND_INC (ll_version
, hdrptr
, 2, end
);
6879 if (ll_version
!= 5)
6881 warn (_("The %s section contains corrupt or "
6882 "unsupported version number: %d.\n"),
6883 section
->name
, ll_version
);
6887 SAFE_BYTE_GET_AND_INC (address_size
, hdrptr
, 1, end
);
6889 SAFE_BYTE_GET_AND_INC (segment_selector_size
, hdrptr
, 1, end
);
6890 if (segment_selector_size
!= 0)
6892 warn (_("The %s section contains "
6893 "unsupported segment selector size: %d.\n"),
6894 section
->name
, segment_selector_size
);
6898 SAFE_BYTE_GET_AND_INC (offset_entry_count
, hdrptr
, 4, end
);
6899 if (offset_entry_count
!= 0)
6901 warn (_("The %s section contains "
6902 "unsupported offset entry count: %d.\n"),
6903 section
->name
, offset_entry_count
);
6907 expected_start
= hdrptr
- section_begin
;
6910 if (load_debug_info (file
) == 0)
6912 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
6917 /* Check the order of location list in .debug_info section. If
6918 offsets of location lists are in the ascending order, we can
6919 use `debug_information' directly. */
6920 for (i
= 0; i
< num_debug_info_entries
; i
++)
6924 num
= debug_information
[i
].num_loc_offsets
;
6925 if (num
> num_loc_list
)
6928 /* Check if we can use `debug_information' directly. */
6929 if (locs_sorted
&& num
!= 0)
6931 if (!seen_first_offset
)
6933 /* This is the first location list. */
6934 last_offset
= debug_information
[i
].loc_offsets
[0];
6935 last_view
= debug_information
[i
].loc_views
[0];
6937 seen_first_offset
= 1;
6943 for (; j
< num
; j
++)
6946 debug_information
[i
].loc_offsets
[j
]
6947 || (last_offset
== debug_information
[i
].loc_offsets
[j
]
6948 && last_view
> debug_information
[i
].loc_views
[j
]))
6953 last_offset
= debug_information
[i
].loc_offsets
[j
];
6954 last_view
= debug_information
[i
].loc_views
[j
];
6959 if (!seen_first_offset
)
6960 error (_("No location lists in .debug_info section!\n"));
6962 if (debug_information
[first
].num_loc_offsets
> 0
6963 && debug_information
[first
].loc_offsets
[0] != expected_start
6964 && debug_information
[first
].loc_views
[0] != expected_start
)
6965 warn (_("Location lists in %s section start at 0x%s\n"),
6967 dwarf_vmatoa ("x", debug_information
[first
].loc_offsets
[0]));
6970 array
= (unsigned int *) xcmalloc (num_loc_list
, sizeof (unsigned int));
6972 introduce (section
, false);
6974 if (reloc_at (section
, 0))
6975 printf (_(" Warning: This section has relocations - addresses seen here may not be accurate.\n\n"));
6977 printf (_(" Offset Begin End Expression\n"));
6979 seen_first_offset
= 0;
6980 for (i
= first
; i
< num_debug_info_entries
; i
++)
6982 dwarf_vma offset
, voffset
;
6983 dwarf_vma base_address
;
6989 for (k
= 0; k
< debug_information
[i
].num_loc_offsets
; k
++)
6991 loc_offsets
= debug_information
[i
].loc_offsets
;
6992 loc_views
= debug_information
[i
].loc_views
;
6993 qsort (array
, debug_information
[i
].num_loc_offsets
,
6994 sizeof (*array
), loc_offsets_compar
);
6997 int adjacent_view_loclists
= 1;
6998 for (k
= 0; k
< debug_information
[i
].num_loc_offsets
; k
++)
7000 j
= locs_sorted
? k
: array
[k
];
7002 && (debug_information
[i
].loc_offsets
[locs_sorted
7003 ? k
- 1 : array
[k
- 1]]
7004 == debug_information
[i
].loc_offsets
[j
])
7005 && (debug_information
[i
].loc_views
[locs_sorted
7006 ? k
- 1 : array
[k
- 1]]
7007 == debug_information
[i
].loc_views
[j
]))
7009 has_frame_base
= debug_information
[i
].have_frame_base
[j
];
7010 offset
= debug_information
[i
].loc_offsets
[j
];
7011 next
= section_begin
+ offset
;
7012 voffset
= debug_information
[i
].loc_views
[j
];
7014 vnext
= section_begin
+ voffset
;
7017 base_address
= debug_information
[i
].base_address
;
7019 if (vnext
&& vnext
< next
)
7022 display_view_pair_list (section
, &vstart
, i
, next
);
7027 if (!seen_first_offset
|| !adjacent_view_loclists
)
7028 seen_first_offset
= 1;
7032 warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"),
7033 (unsigned long) (start
- section_begin
),
7034 (unsigned long) offset
,
7036 else if (start
> next
)
7037 warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"),
7038 (unsigned long) (start
- section_begin
),
7039 (unsigned long) offset
,
7045 if (offset
>= bytes
)
7047 warn (_("Offset 0x%lx is bigger than %s section size.\n"),
7048 (unsigned long) offset
,
7053 if (vnext
&& voffset
>= bytes
)
7055 warn (_("View Offset 0x%lx is bigger than %s section size.\n"),
7056 (unsigned long) voffset
,
7064 display_loc_list_dwo (section
, &start
, i
, offset
,
7065 &vstart
, has_frame_base
);
7067 display_loc_list (section
, &start
, i
, offset
, base_address
,
7068 &vstart
, has_frame_base
);
7073 warn (_("DWO is not yet supported.\n"));
7075 display_loclists_list (section
, &start
, i
, offset
, base_address
,
7076 &vstart
, has_frame_base
);
7079 /* FIXME: this arrangement is quite simplistic. Nothing
7080 requires locview lists to be adjacent to corresponding
7081 loclists, and a single loclist could be augmented by
7082 different locview lists, and vice-versa, unlikely as it
7083 is that it would make sense to do so. Hopefully we'll
7084 have view pair support built into loclists before we ever
7085 need to address all these possibilities. */
7086 if (adjacent_view_loclists
&& vnext
7087 && vnext
!= start
&& vstart
!= next
)
7089 adjacent_view_loclists
= 0;
7090 warn (_("Hole and overlap detection requires adjacent view lists and loclists.\n"));
7093 if (vnext
&& vnext
== start
)
7094 display_view_pair_list (section
, &start
, i
, vstart
);
7098 if (start
< section
->start
+ section
->size
)
7099 warn (ngettext ("There is %ld unused byte at the end of section %s\n",
7100 "There are %ld unused bytes at the end of section %s\n",
7101 (long) (section
->start
+ section
->size
- start
)),
7102 (long) (section
->start
+ section
->size
- start
), section
->name
);
7109 display_debug_str (struct dwarf_section
*section
,
7110 void *file ATTRIBUTE_UNUSED
)
7112 unsigned char *start
= section
->start
;
7113 dwarf_vma bytes
= section
->size
;
7114 dwarf_vma addr
= section
->address
;
7118 printf (_("\nThe %s section is empty.\n"), section
->name
);
7122 introduce (section
, false);
7130 lbytes
= (bytes
> 16 ? 16 : bytes
);
7132 printf (" 0x%8.8lx ", (unsigned long) addr
);
7134 for (j
= 0; j
< 16; j
++)
7137 printf ("%2.2x", start
[j
]);
7145 for (j
= 0; j
< lbytes
; j
++)
7148 if (k
>= ' ' && k
< 0x80)
7167 display_debug_info (struct dwarf_section
*section
, void *file
)
7169 return process_debug_info (section
, file
, section
->abbrev_sec
, false, false);
7173 display_debug_types (struct dwarf_section
*section
, void *file
)
7175 return process_debug_info (section
, file
, section
->abbrev_sec
, false, true);
7179 display_trace_info (struct dwarf_section
*section
, void *file
)
7181 return process_debug_info (section
, file
, section
->abbrev_sec
, false, true);
7185 display_debug_aranges (struct dwarf_section
*section
,
7186 void *file ATTRIBUTE_UNUSED
)
7188 unsigned char *start
= section
->start
;
7189 unsigned char *end
= start
+ section
->size
;
7191 introduce (section
, false);
7193 /* It does not matter if this load fails,
7194 we test for that later on. */
7195 load_debug_info (file
);
7199 unsigned char *hdrptr
;
7200 DWARF2_Internal_ARange arange
;
7201 unsigned char *addr_ranges
;
7205 unsigned char address_size
;
7206 unsigned int offset_size
;
7207 unsigned char *end_ranges
;
7210 sec_off
= hdrptr
- section
->start
;
7212 SAFE_BYTE_GET_AND_INC (arange
.ar_length
, hdrptr
, 4, end
);
7213 if (arange
.ar_length
== 0xffffffff)
7215 SAFE_BYTE_GET_AND_INC (arange
.ar_length
, hdrptr
, 8, end
);
7221 if (arange
.ar_length
> (size_t) (end
- hdrptr
))
7223 warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"),
7225 (unsigned long) sec_off
,
7226 dwarf_vmatoa ("x", arange
.ar_length
));
7229 end_ranges
= hdrptr
+ arange
.ar_length
;
7231 SAFE_BYTE_GET_AND_INC (arange
.ar_version
, hdrptr
, 2, end_ranges
);
7232 SAFE_BYTE_GET_AND_INC (arange
.ar_info_offset
, hdrptr
, offset_size
,
7235 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
7236 && num_debug_info_entries
> 0
7237 && find_debug_info_for_offset (arange
.ar_info_offset
) == NULL
)
7238 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
7239 (unsigned long) arange
.ar_info_offset
, section
->name
);
7241 SAFE_BYTE_GET_AND_INC (arange
.ar_pointer_size
, hdrptr
, 1, end_ranges
);
7242 SAFE_BYTE_GET_AND_INC (arange
.ar_segment_size
, hdrptr
, 1, end_ranges
);
7244 if (arange
.ar_version
!= 2 && arange
.ar_version
!= 3)
7246 /* PR 19872: A version number of 0 probably means that there is
7247 padding at the end of the .debug_aranges section. Gold puts
7248 it there when performing an incremental link, for example.
7249 So do not generate a warning in this case. */
7250 if (arange
.ar_version
)
7251 warn (_("Only DWARF 2 and 3 aranges are currently supported.\n"));
7255 printf (_(" Length: %ld\n"),
7256 (long) arange
.ar_length
);
7257 printf (_(" Version: %d\n"), arange
.ar_version
);
7258 printf (_(" Offset into .debug_info: 0x%lx\n"),
7259 (unsigned long) arange
.ar_info_offset
);
7260 printf (_(" Pointer Size: %d\n"), arange
.ar_pointer_size
);
7261 printf (_(" Segment Size: %d\n"), arange
.ar_segment_size
);
7263 address_size
= arange
.ar_pointer_size
+ arange
.ar_segment_size
;
7265 /* PR 17512: file: 001-108546-0.001:0.1. */
7266 if (address_size
== 0 || address_size
> 8)
7268 error (_("Invalid address size in %s section!\n"),
7273 /* The DWARF spec does not require that the address size be a power
7274 of two, but we do. This will have to change if we ever encounter
7275 an uneven architecture. */
7276 if ((address_size
& (address_size
- 1)) != 0)
7278 warn (_("Pointer size + Segment size is not a power of two.\n"));
7282 if (address_size
> 4)
7283 printf (_("\n Address Length\n"));
7285 printf (_("\n Address Length\n"));
7287 addr_ranges
= hdrptr
;
7289 /* Must pad to an alignment boundary that is twice the address size. */
7290 addr_ranges
+= (2 * address_size
- 1
7291 - (hdrptr
- start
- 1) % (2 * address_size
));
7293 while (2 * address_size
<= end_ranges
- addr_ranges
)
7295 SAFE_BYTE_GET_AND_INC (address
, addr_ranges
, address_size
,
7297 SAFE_BYTE_GET_AND_INC (length
, addr_ranges
, address_size
,
7300 print_dwarf_vma (address
, address_size
);
7301 print_dwarf_vma (length
, address_size
);
7313 /* Comparison function for qsort. */
7315 comp_addr_base (const void * v0
, const void * v1
)
7317 debug_info
*info0
= *(debug_info
**) v0
;
7318 debug_info
*info1
= *(debug_info
**) v1
;
7319 return info0
->addr_base
- info1
->addr_base
;
7322 /* Display the debug_addr section. */
7324 display_debug_addr (struct dwarf_section
*section
,
7327 debug_info
**debug_addr_info
;
7328 unsigned char *entry
;
7332 unsigned char * header
;
7334 if (section
->size
== 0)
7336 printf (_("\nThe %s section is empty.\n"), section
->name
);
7340 if (load_debug_info (file
) == 0)
7342 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
7347 introduce (section
, false);
7349 /* PR 17531: file: cf38d01b.
7350 We use xcalloc because a corrupt file may not have initialised all of the
7351 fields in the debug_info structure, which means that the sort below might
7352 try to move uninitialised data. */
7353 debug_addr_info
= (debug_info
**) xcalloc ((num_debug_info_entries
+ 1),
7354 sizeof (debug_info
*));
7357 for (i
= 0; i
< num_debug_info_entries
; i
++)
7358 if (debug_information
[i
].addr_base
!= DEBUG_INFO_UNAVAILABLE
)
7360 /* PR 17531: file: cf38d01b. */
7361 if (debug_information
[i
].addr_base
>= section
->size
)
7362 warn (_("Corrupt address base (%lx) found in debug section %u\n"),
7363 (unsigned long) debug_information
[i
].addr_base
, i
);
7365 debug_addr_info
[count
++] = debug_information
+ i
;
7368 /* Add a sentinel to make iteration convenient. */
7369 debug_addr_info
[count
] = (debug_info
*) xmalloc (sizeof (debug_info
));
7370 debug_addr_info
[count
]->addr_base
= section
->size
;
7371 qsort (debug_addr_info
, count
, sizeof (debug_info
*), comp_addr_base
);
7373 header
= section
->start
;
7374 for (i
= 0; i
< count
; i
++)
7377 unsigned int address_size
= debug_addr_info
[i
]->pointer_size
;
7379 printf (_(" For compilation unit at offset 0x%s:\n"),
7380 dwarf_vmatoa ("x", debug_addr_info
[i
]->cu_offset
));
7382 printf (_("\tIndex\tAddress\n"));
7383 entry
= section
->start
+ debug_addr_info
[i
]->addr_base
;
7384 if (debug_addr_info
[i
]->dwarf_version
>= 5)
7386 size_t header_size
= entry
- header
;
7387 unsigned char * curr_header
= header
;
7390 int segment_selector_size
;
7392 if (header_size
!= 8 && header_size
!= 16)
7394 warn (_("Corrupt %s section: expecting header size of 8 or 16, but found %ld instead\n"),
7395 section
->name
, (long) header_size
);
7399 SAFE_BYTE_GET_AND_INC (length
, curr_header
, 4, entry
);
7400 if (length
== 0xffffffff)
7401 SAFE_BYTE_GET_AND_INC (length
, curr_header
, 8, entry
);
7402 end
= curr_header
+ length
;
7404 SAFE_BYTE_GET_AND_INC (version
, curr_header
, 2, entry
);
7406 warn (_("Corrupt %s section: expecting version number 5 in header but found %d instead\n"),
7407 section
->name
, version
);
7409 SAFE_BYTE_GET_AND_INC (address_size
, curr_header
, 1, entry
);
7410 SAFE_BYTE_GET_AND_INC (segment_selector_size
, curr_header
, 1, entry
);
7411 address_size
+= segment_selector_size
;
7414 end
= section
->start
+ debug_addr_info
[i
+ 1]->addr_base
;
7419 dwarf_vma base
= byte_get (entry
, address_size
);
7420 printf (_("\t%d:\t"), idx
);
7421 print_dwarf_vma (base
, address_size
);
7423 entry
+= address_size
;
7429 free (debug_addr_info
);
7433 /* Display the .debug_str_offsets and .debug_str_offsets.dwo sections. */
7436 display_debug_str_offsets (struct dwarf_section
*section
,
7437 void *file ATTRIBUTE_UNUSED
)
7441 if (section
->size
== 0)
7443 printf (_("\nThe %s section is empty.\n"), section
->name
);
7447 unsigned char *start
= section
->start
;
7448 unsigned char *end
= start
+ section
->size
;
7449 unsigned char *curr
= start
;
7451 const char *suffix
= strrchr (section
->name
, '.');
7452 bool dwo
= suffix
&& strcmp (suffix
, ".dwo") == 0;
7455 load_debug_section_with_follow (str_dwo
, file
);
7457 load_debug_section_with_follow (str
, file
);
7459 introduce (section
, false);
7464 dwarf_vma entry_length
;
7466 SAFE_BYTE_GET_AND_INC (length
, curr
, 4, end
);
7467 /* FIXME: We assume that this means 64-bit DWARF is being used. */
7468 if (length
== 0xffffffff)
7470 SAFE_BYTE_GET_AND_INC (length
, curr
, 8, end
);
7476 unsigned char *entries_end
;
7479 /* This is probably an old style .debug_str_offset section which
7480 just contains offsets and no header (and the first offset is 0). */
7481 length
= section
->size
;
7482 curr
= section
->start
;
7485 printf (_(" Length: %#lx\n"), (unsigned long) length
);
7486 printf (_(" Index Offset [String]\n"));
7490 if (length
<= (dwarf_vma
) (end
- curr
))
7491 entries_end
= curr
+ length
;
7494 warn (_("Section %s is too small %#lx\n"),
7495 section
->name
, (unsigned long) section
->size
);
7500 SAFE_BYTE_GET_AND_INC (version
, curr
, 2, entries_end
);
7502 warn (_("Unexpected version number in str_offset header: %#x\n"), version
);
7505 SAFE_BYTE_GET_AND_INC (padding
, curr
, 2, entries_end
);
7507 warn (_("Unexpected value in str_offset header's padding field: %#x\n"), padding
);
7509 printf (_(" Length: %#lx\n"), (unsigned long) length
);
7510 printf (_(" Version: %#lx\n"), (unsigned long) version
);
7511 printf (_(" Index Offset [String]\n"));
7514 for (idx
= 0; curr
< entries_end
; idx
++)
7517 const unsigned char * string
;
7519 if ((dwarf_vma
) (entries_end
- curr
) < entry_length
)
7520 /* Not enough space to read one entry_length, give up. */
7523 SAFE_BYTE_GET_AND_INC (offset
, curr
, entry_length
, entries_end
);
7525 string
= (const unsigned char *)
7526 fetch_indexed_string (idx
, NULL
, entry_length
, dwo
);
7528 string
= fetch_indirect_string (offset
);
7530 printf (" %8lu %8s %s\n", idx
, dwarf_vmatoa ("x", offset
),
7538 /* Each debug_information[x].range_lists[y] gets this representation for
7539 sorting purposes. */
7543 /* The debug_information[x].range_lists[y] value. */
7544 dwarf_vma ranges_offset
;
7546 /* Original debug_information to find parameters of the data. */
7547 debug_info
*debug_info_p
;
7550 /* Sort struct range_entry in ascending order of its RANGES_OFFSET. */
7553 range_entry_compar (const void *ap
, const void *bp
)
7555 const struct range_entry
*a_re
= (const struct range_entry
*) ap
;
7556 const struct range_entry
*b_re
= (const struct range_entry
*) bp
;
7557 const dwarf_vma a
= a_re
->ranges_offset
;
7558 const dwarf_vma b
= b_re
->ranges_offset
;
7560 return (a
> b
) - (b
> a
);
7564 display_debug_ranges_list (unsigned char * start
,
7565 unsigned char * finish
,
7566 unsigned int pointer_size
,
7568 dwarf_vma base_address
)
7570 while (start
< finish
)
7575 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
7576 if (start
>= finish
)
7578 SAFE_SIGNED_BYTE_GET_AND_INC (end
, start
, pointer_size
, finish
);
7581 print_dwarf_vma (offset
, 4);
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
,
7614 unsigned char * finish
,
7615 unsigned int pointer_size
,
7617 dwarf_vma base_address
)
7619 unsigned char *next
= start
;
7623 dwarf_vma off
= offset
+ (start
- next
);
7624 enum dwarf_range_list_entry rlet
;
7625 /* Initialize it due to a false compiler warning. */
7626 dwarf_vma begin
= -1, length
, end
= -1;
7628 if (start
>= finish
)
7630 warn (_("Range list starting at offset 0x%s is not terminated.\n"),
7631 dwarf_vmatoa ("x", offset
));
7636 print_dwarf_vma (off
, 4);
7638 SAFE_BYTE_GET_AND_INC (rlet
, start
, 1, finish
);
7642 case DW_RLE_end_of_list
:
7643 printf (_("<End of list>\n"));
7645 case DW_RLE_base_address
:
7646 SAFE_BYTE_GET_AND_INC (base_address
, start
, pointer_size
, finish
);
7647 print_dwarf_vma (base_address
, pointer_size
);
7648 printf (_("(base address)\n"));
7650 case DW_RLE_start_length
:
7651 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
7652 READ_ULEB (length
, start
, finish
);
7653 end
= begin
+ length
;
7655 case DW_RLE_offset_pair
:
7656 READ_ULEB (begin
, start
, finish
);
7657 READ_ULEB (end
, start
, finish
);
7659 case DW_RLE_start_end
:
7660 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
7661 SAFE_BYTE_GET_AND_INC (end
, start
, pointer_size
, finish
);
7664 error (_("Invalid range list entry type %d\n"), rlet
);
7665 rlet
= DW_RLE_end_of_list
;
7668 if (rlet
== DW_RLE_end_of_list
)
7670 if (rlet
== DW_RLE_base_address
)
7673 /* Only a DW_RLE_offset_pair needs the base address added. */
7674 if (rlet
== DW_RLE_offset_pair
)
7676 begin
+= base_address
;
7677 end
+= base_address
;
7680 print_dwarf_vma (begin
, pointer_size
);
7681 print_dwarf_vma (end
, pointer_size
);
7684 fputs (_("(start == end)"), stdout
);
7685 else if (begin
> end
)
7686 fputs (_("(start > end)"), stdout
);
7693 display_debug_ranges (struct dwarf_section
*section
,
7694 void *file ATTRIBUTE_UNUSED
)
7696 unsigned char * start
= section
->start
;
7697 unsigned char * last_start
= start
;
7698 dwarf_vma bytes
= section
->size
;
7699 unsigned char * section_begin
= start
;
7700 unsigned char * finish
= start
+ bytes
;
7701 unsigned int num_range_list
, i
;
7702 struct range_entry
* range_entries
;
7703 struct range_entry
* range_entry_fill
;
7704 int is_rnglists
= strstr (section
->name
, "debug_rnglists") != NULL
;
7705 /* Initialize it due to a false compiler warning. */
7706 unsigned char address_size
= 0;
7707 dwarf_vma last_offset
= 0;
7711 printf (_("\nThe %s section is empty.\n"), section
->name
);
7717 dwarf_vma initial_length
;
7718 unsigned char segment_selector_size
;
7719 unsigned int offset_size
, offset_entry_count
;
7720 unsigned short version
;
7722 /* Get and check the length of the block. */
7723 SAFE_BYTE_GET_AND_INC (initial_length
, start
, 4, finish
);
7725 if (initial_length
== 0xffffffff)
7727 /* This section is 64-bit DWARF 3. */
7728 SAFE_BYTE_GET_AND_INC (initial_length
, start
, 8, finish
);
7734 if (initial_length
> (size_t) (finish
- start
))
7736 /* If the length field has a relocation against it, then we should
7737 not complain if it is inaccurate (and probably negative).
7738 It is copied from .debug_line handling code. */
7739 if (reloc_at (section
, (start
- section
->start
) - offset_size
))
7741 initial_length
= finish
- start
;
7745 warn (_("The length field (0x%lx) in the debug_rnglists header is wrong - the section is too small\n"),
7746 (long) initial_length
);
7751 /* Get and check the version number. */
7752 SAFE_BYTE_GET_AND_INC (version
, start
, 2, finish
);
7756 warn (_("Only DWARF version 5 debug_rnglists info "
7757 "is currently supported.\n"));
7761 SAFE_BYTE_GET_AND_INC (address_size
, start
, 1, finish
);
7763 SAFE_BYTE_GET_AND_INC (segment_selector_size
, start
, 1, finish
);
7764 if (segment_selector_size
!= 0)
7766 warn (_("The %s section contains "
7767 "unsupported segment selector size: %d.\n"),
7768 section
->name
, segment_selector_size
);
7772 SAFE_BYTE_GET_AND_INC (offset_entry_count
, start
, 4, finish
);
7773 if (offset_entry_count
!= 0)
7775 warn (_("The %s section contains "
7776 "unsupported offset entry count: %u.\n"),
7777 section
->name
, offset_entry_count
);
7782 if (load_debug_info (file
) == 0)
7784 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
7790 for (i
= 0; i
< num_debug_info_entries
; i
++)
7792 if (debug_information
[i
].dwarf_version
< 5 && is_rnglists
)
7793 /* Skip .debug_rnglists reference. */
7795 if (debug_information
[i
].dwarf_version
>= 5 && !is_rnglists
)
7796 /* Skip .debug_range reference. */
7798 num_range_list
+= debug_information
[i
].num_range_lists
;
7801 if (num_range_list
== 0)
7803 /* This can happen when the file was compiled with -gsplit-debug
7804 which removes references to range lists from the primary .o file. */
7805 printf (_("No range lists in .debug_info section.\n"));
7809 range_entries
= (struct range_entry
*)
7810 xmalloc (sizeof (*range_entries
) * num_range_list
);
7811 range_entry_fill
= range_entries
;
7813 for (i
= 0; i
< num_debug_info_entries
; i
++)
7815 debug_info
*debug_info_p
= &debug_information
[i
];
7818 if (debug_information
[i
].dwarf_version
< 5 && is_rnglists
)
7819 /* Skip .debug_rnglists reference. */
7821 if (debug_information
[i
].dwarf_version
>= 5 && !is_rnglists
)
7822 /* Skip .debug_range reference. */
7825 for (j
= 0; j
< debug_info_p
->num_range_lists
; j
++)
7827 range_entry_fill
->ranges_offset
= debug_info_p
->range_lists
[j
];
7828 range_entry_fill
->debug_info_p
= debug_info_p
;
7833 qsort (range_entries
, num_range_list
, sizeof (*range_entries
),
7834 range_entry_compar
);
7836 if (dwarf_check
!= 0 && range_entries
[0].ranges_offset
!= 0)
7837 warn (_("Range lists in %s section start at 0x%lx\n"),
7838 section
->name
, (unsigned long) range_entries
[0].ranges_offset
);
7840 introduce (section
, false);
7842 printf (_(" Offset Begin End\n"));
7844 for (i
= 0; i
< num_range_list
; i
++)
7846 struct range_entry
*range_entry
= &range_entries
[i
];
7847 debug_info
*debug_info_p
= range_entry
->debug_info_p
;
7848 unsigned int pointer_size
;
7850 unsigned char *next
;
7851 dwarf_vma base_address
;
7853 pointer_size
= (is_rnglists
? address_size
: debug_info_p
->pointer_size
);
7854 offset
= range_entry
->ranges_offset
;
7855 base_address
= debug_info_p
->base_address
;
7857 /* PR 17512: file: 001-101485-0.001:0.1. */
7858 if (pointer_size
< 2 || pointer_size
> 8)
7860 warn (_("Corrupt pointer size (%d) in debug entry at offset %8.8lx\n"),
7861 pointer_size
, (unsigned long) offset
);
7865 if (offset
> (size_t) (finish
- section_begin
))
7867 warn (_("Corrupt offset (%#8.8lx) in range entry %u\n"),
7868 (unsigned long) offset
, i
);
7871 next
= section_begin
+ offset
;
7873 /* If multiple DWARF entities reference the same range then we will
7874 have multiple entries in the `range_entries' list for the same
7875 offset. Thanks to the sort above these will all be consecutive in
7876 the `range_entries' list, so we can easily ignore duplicates
7878 if (i
> 0 && last_offset
== offset
)
7880 last_offset
= offset
;
7882 if (dwarf_check
!= 0 && i
> 0)
7885 warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"),
7886 (unsigned long) (start
- section_begin
),
7887 (unsigned long) (next
- section_begin
), section
->name
);
7888 else if (start
> next
)
7890 if (next
== last_start
)
7892 warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"),
7893 (unsigned long) (start
- section_begin
),
7894 (unsigned long) (next
- section_begin
), section
->name
);
7901 (is_rnglists
? display_debug_rnglists_list
: display_debug_ranges_list
)
7902 (start
, finish
, pointer_size
, offset
, base_address
);
7906 free (range_entries
);
7911 typedef struct Frame_Chunk
7913 struct Frame_Chunk
*next
;
7914 unsigned char *chunk_start
;
7916 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
7917 short int *col_type
;
7920 unsigned int code_factor
;
7924 unsigned int cfa_reg
;
7925 dwarf_vma cfa_offset
;
7927 unsigned char fde_encoding
;
7928 unsigned char cfa_exp
;
7929 unsigned char ptr_size
;
7930 unsigned char segment_size
;
7934 typedef const char *(*dwarf_regname_lookup_ftype
) (unsigned int);
7935 static dwarf_regname_lookup_ftype dwarf_regnames_lookup_func
;
7936 static const char *const *dwarf_regnames
;
7937 static unsigned int dwarf_regnames_count
;
7940 /* A marker for a col_type that means this column was never referenced
7941 in the frame info. */
7942 #define DW_CFA_unreferenced (-1)
7944 /* Return 0 if no more space is needed, 1 if more space is needed,
7945 -1 for invalid reg. */
7948 frame_need_space (Frame_Chunk
*fc
, unsigned int reg
)
7950 unsigned int prev
= fc
->ncols
;
7952 if (reg
< (unsigned int) fc
->ncols
)
7955 if (dwarf_regnames_count
> 0
7956 && reg
> dwarf_regnames_count
)
7959 fc
->ncols
= reg
+ 1;
7960 /* PR 17512: file: 10450-2643-0.004.
7961 If reg == -1 then this can happen... */
7965 /* PR 17512: file: 2844a11d. */
7966 if (fc
->ncols
> 1024 && dwarf_regnames_count
== 0)
7968 error (_("Unfeasibly large register number: %u\n"), reg
);
7970 /* FIXME: 1024 is an arbitrary limit. Increase it if
7971 we ever encounter a valid binary that exceeds it. */
7975 fc
->col_type
= (short int *) xcrealloc (fc
->col_type
, fc
->ncols
,
7976 sizeof (short int));
7977 fc
->col_offset
= (int *) xcrealloc (fc
->col_offset
, fc
->ncols
, sizeof (int));
7978 /* PR 17512: file:002-10025-0.005. */
7979 if (fc
->col_type
== NULL
|| fc
->col_offset
== NULL
)
7981 error (_("Out of memory allocating %u columns in dwarf frame arrays\n"),
7987 while (prev
< fc
->ncols
)
7989 fc
->col_type
[prev
] = DW_CFA_unreferenced
;
7990 fc
->col_offset
[prev
] = 0;
7996 static const char *const dwarf_regnames_i386
[] =
7998 "eax", "ecx", "edx", "ebx", /* 0 - 3 */
7999 "esp", "ebp", "esi", "edi", /* 4 - 7 */
8000 "eip", "eflags", NULL
, /* 8 - 10 */
8001 "st0", "st1", "st2", "st3", /* 11 - 14 */
8002 "st4", "st5", "st6", "st7", /* 15 - 18 */
8003 NULL
, NULL
, /* 19 - 20 */
8004 "xmm0", "xmm1", "xmm2", "xmm3", /* 21 - 24 */
8005 "xmm4", "xmm5", "xmm6", "xmm7", /* 25 - 28 */
8006 "mm0", "mm1", "mm2", "mm3", /* 29 - 32 */
8007 "mm4", "mm5", "mm6", "mm7", /* 33 - 36 */
8008 "fcw", "fsw", "mxcsr", /* 37 - 39 */
8009 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
, /* 40 - 47 */
8010 "tr", "ldtr", /* 48 - 49 */
8011 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 50 - 57 */
8012 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 58 - 65 */
8013 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 66 - 73 */
8014 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 74 - 81 */
8015 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 82 - 89 */
8016 NULL
, NULL
, NULL
, /* 90 - 92 */
8017 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7" /* 93 - 100 */
8020 static const char *const dwarf_regnames_iamcu
[] =
8022 "eax", "ecx", "edx", "ebx", /* 0 - 3 */
8023 "esp", "ebp", "esi", "edi", /* 4 - 7 */
8024 "eip", "eflags", NULL
, /* 8 - 10 */
8025 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 11 - 18 */
8026 NULL
, NULL
, /* 19 - 20 */
8027 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 21 - 28 */
8028 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 29 - 36 */
8029 NULL
, NULL
, NULL
, /* 37 - 39 */
8030 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
, /* 40 - 47 */
8031 "tr", "ldtr", /* 48 - 49 */
8032 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 50 - 57 */
8033 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 58 - 65 */
8034 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 66 - 73 */
8035 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 74 - 81 */
8036 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 82 - 89 */
8037 NULL
, NULL
, NULL
, /* 90 - 92 */
8038 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
/* 93 - 100 */
8042 init_dwarf_regnames_i386 (void)
8044 dwarf_regnames
= dwarf_regnames_i386
;
8045 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_i386
);
8046 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8050 init_dwarf_regnames_iamcu (void)
8052 dwarf_regnames
= dwarf_regnames_iamcu
;
8053 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_iamcu
);
8054 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8057 static const char *const dwarf_regnames_x86_64
[] =
8059 "rax", "rdx", "rcx", "rbx",
8060 "rsi", "rdi", "rbp", "rsp",
8061 "r8", "r9", "r10", "r11",
8062 "r12", "r13", "r14", "r15",
8064 "xmm0", "xmm1", "xmm2", "xmm3",
8065 "xmm4", "xmm5", "xmm6", "xmm7",
8066 "xmm8", "xmm9", "xmm10", "xmm11",
8067 "xmm12", "xmm13", "xmm14", "xmm15",
8068 "st0", "st1", "st2", "st3",
8069 "st4", "st5", "st6", "st7",
8070 "mm0", "mm1", "mm2", "mm3",
8071 "mm4", "mm5", "mm6", "mm7",
8073 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
,
8074 "fs.base", "gs.base", NULL
, NULL
,
8076 "mxcsr", "fcw", "fsw",
8077 "xmm16", "xmm17", "xmm18", "xmm19",
8078 "xmm20", "xmm21", "xmm22", "xmm23",
8079 "xmm24", "xmm25", "xmm26", "xmm27",
8080 "xmm28", "xmm29", "xmm30", "xmm31",
8081 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 83 - 90 */
8082 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 91 - 98 */
8083 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 99 - 106 */
8084 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 107 - 114 */
8085 NULL
, NULL
, NULL
, /* 115 - 117 */
8086 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7"
8090 init_dwarf_regnames_x86_64 (void)
8092 dwarf_regnames
= dwarf_regnames_x86_64
;
8093 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_x86_64
);
8094 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8097 static const char *const dwarf_regnames_aarch64
[] =
8099 "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7",
8100 "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15",
8101 "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23",
8102 "x24", "x25", "x26", "x27", "x28", "x29", "x30", "sp",
8103 NULL
, "elr", NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
8104 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, "vg", "ffr",
8105 "p0", "p1", "p2", "p3", "p4", "p5", "p6", "p7",
8106 "p8", "p9", "p10", "p11", "p12", "p13", "p14", "p15",
8107 "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7",
8108 "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15",
8109 "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23",
8110 "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31",
8111 "z0", "z1", "z2", "z3", "z4", "z5", "z6", "z7",
8112 "z8", "z9", "z10", "z11", "z12", "z13", "z14", "z15",
8113 "z16", "z17", "z18", "z19", "z20", "z21", "z22", "z23",
8114 "z24", "z25", "z26", "z27", "z28", "z29", "z30", "z31",
8118 init_dwarf_regnames_aarch64 (void)
8120 dwarf_regnames
= dwarf_regnames_aarch64
;
8121 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_aarch64
);
8122 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8125 static const char *const dwarf_regnames_s390
[] =
8127 /* Avoid saying "r5 (r5)", so omit the names of r0-r15. */
8128 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
8129 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
8130 "f0", "f2", "f4", "f6", "f1", "f3", "f5", "f7",
8131 "f8", "f10", "f12", "f14", "f9", "f11", "f13", "f15",
8132 "cr0", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7",
8133 "cr8", "cr9", "cr10", "cr11", "cr12", "cr13", "cr14", "cr15",
8134 "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7",
8135 "a8", "a9", "a10", "a11", "a12", "a13", "a14", "a15",
8138 "v16", "v18", "v20", "v22", "v17", "v19", "v21", "v23",
8139 "v24", "v26", "v28", "v30", "v25", "v27", "v29", "v31",
8143 init_dwarf_regnames_s390 (void)
8145 dwarf_regnames
= dwarf_regnames_s390
;
8146 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_s390
);
8147 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8150 static const char *const dwarf_regnames_riscv
[] =
8152 "zero", "ra", "sp", "gp", "tp", "t0", "t1", "t2", /* 0 - 7 */
8153 "s0", "s1", "a0", "a1", "a2", "a3", "a4", "a5", /* 8 - 15 */
8154 "a6", "a7", "s2", "s3", "s4", "s5", "s6", "s7", /* 16 - 23 */
8155 "s8", "s9", "s10", "s11", "t3", "t4", "t5", "t6", /* 24 - 31 */
8156 "ft0", "ft1", "ft2", "ft3", "ft4", "ft5", "ft6", "ft7", /* 32 - 39 */
8157 "fs0", "fs1", /* 40 - 41 */
8158 "fa0", "fa1", "fa2", "fa3", "fa4", "fa5", "fa6", "fa7", /* 42 - 49 */
8159 "fs2", "fs3", "fs4", "fs5", "fs6", "fs7", "fs8", "fs9", /* 50 - 57 */
8160 "fs10", "fs11", /* 58 - 59 */
8161 "ft8", "ft9", "ft10", "ft11" /* 60 - 63 */
8164 /* A RISC-V replacement for REGNAME_INTERNAL_BY_TABLE_ONLY which handles
8165 the large number of CSRs. */
8168 regname_internal_riscv (unsigned int regno
)
8170 const char *name
= NULL
;
8172 /* Lookup in the table first, this covers GPR and FPR. */
8173 if (regno
< ARRAY_SIZE (dwarf_regnames_riscv
))
8174 name
= dwarf_regnames_riscv
[regno
];
8175 else if (regno
>= 4096 && regno
<= 8191)
8177 /* This might be a CSR, these live in a sparse number space from 4096
8178 to 8191 These numbers are defined in the RISC-V ELF ABI
8182 #define DECLARE_CSR(NAME,VALUE,CLASS,DEFINE_VER,ABORT_VER) \
8183 case VALUE + 4096: name = #NAME; break;
8184 #include "opcode/riscv-opc.h"
8189 static char csr_name
[10];
8190 snprintf (csr_name
, sizeof (csr_name
), "csr%d", (regno
- 4096));
8201 init_dwarf_regnames_riscv (void)
8203 dwarf_regnames
= NULL
;
8204 dwarf_regnames_count
= 8192;
8205 dwarf_regnames_lookup_func
= regname_internal_riscv
;
8209 init_dwarf_regnames_by_elf_machine_code (unsigned int e_machine
)
8211 dwarf_regnames_lookup_func
= NULL
;
8216 init_dwarf_regnames_i386 ();
8220 init_dwarf_regnames_iamcu ();
8226 init_dwarf_regnames_x86_64 ();
8230 init_dwarf_regnames_aarch64 ();
8234 init_dwarf_regnames_s390 ();
8238 init_dwarf_regnames_riscv ();
8246 /* Initialize the DWARF register name lookup state based on the
8247 architecture and specific machine type of a BFD. */
8250 init_dwarf_regnames_by_bfd_arch_and_mach (enum bfd_architecture arch
,
8253 dwarf_regnames_lookup_func
= NULL
;
8260 case bfd_mach_x86_64
:
8261 case bfd_mach_x86_64_intel_syntax
:
8262 case bfd_mach_x64_32
:
8263 case bfd_mach_x64_32_intel_syntax
:
8264 init_dwarf_regnames_x86_64 ();
8268 init_dwarf_regnames_i386 ();
8273 case bfd_arch_iamcu
:
8274 init_dwarf_regnames_iamcu ();
8277 case bfd_arch_aarch64
:
8278 init_dwarf_regnames_aarch64();
8282 init_dwarf_regnames_s390 ();
8285 case bfd_arch_riscv
:
8286 init_dwarf_regnames_riscv ();
8295 regname_internal_by_table_only (unsigned int regno
)
8297 if (dwarf_regnames
!= NULL
8298 && regno
< dwarf_regnames_count
8299 && dwarf_regnames
[regno
] != NULL
)
8300 return dwarf_regnames
[regno
];
8306 regname (unsigned int regno
, int name_only_p
)
8308 static char reg
[64];
8310 const char *name
= NULL
;
8312 if (dwarf_regnames_lookup_func
!= NULL
)
8313 name
= dwarf_regnames_lookup_func (regno
);
8319 snprintf (reg
, sizeof (reg
), "r%d (%s)", regno
, name
);
8322 snprintf (reg
, sizeof (reg
), "r%d", regno
);
8327 frame_display_row (Frame_Chunk
*fc
, int *need_col_headers
, unsigned int *max_regs
)
8332 if (*max_regs
!= fc
->ncols
)
8333 *max_regs
= fc
->ncols
;
8335 if (*need_col_headers
)
8337 *need_col_headers
= 0;
8339 printf ("%-*s CFA ", eh_addr_size
* 2, " LOC");
8341 for (r
= 0; r
< *max_regs
; r
++)
8342 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
8347 printf ("%-5s ", regname (r
, 1));
8353 print_dwarf_vma (fc
->pc_begin
, eh_addr_size
);
8355 strcpy (tmp
, "exp");
8357 sprintf (tmp
, "%s%+d", regname (fc
->cfa_reg
, 1), (int) fc
->cfa_offset
);
8358 printf ("%-8s ", tmp
);
8360 for (r
= 0; r
< fc
->ncols
; r
++)
8362 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
8364 switch (fc
->col_type
[r
])
8366 case DW_CFA_undefined
:
8369 case DW_CFA_same_value
:
8373 sprintf (tmp
, "c%+d", fc
->col_offset
[r
]);
8375 case DW_CFA_val_offset
:
8376 sprintf (tmp
, "v%+d", fc
->col_offset
[r
]);
8378 case DW_CFA_register
:
8379 sprintf (tmp
, "%s", regname (fc
->col_offset
[r
], 0));
8381 case DW_CFA_expression
:
8382 strcpy (tmp
, "exp");
8384 case DW_CFA_val_expression
:
8385 strcpy (tmp
, "vexp");
8388 strcpy (tmp
, "n/a");
8391 printf ("%-5s ", tmp
);
8397 #define GET(VAR, N) SAFE_BYTE_GET_AND_INC (VAR, start, N, end)
8399 static unsigned char *
8400 read_cie (unsigned char *start
, unsigned char *end
,
8401 Frame_Chunk
**p_cie
, int *p_version
,
8402 bfd_size_type
*p_aug_len
, unsigned char **p_aug
)
8406 unsigned char *augmentation_data
= NULL
;
8407 bfd_size_type augmentation_data_len
= 0;
8410 /* PR 17512: file: 001-228113-0.004. */
8414 fc
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
8415 memset (fc
, 0, sizeof (Frame_Chunk
));
8417 fc
->col_type
= (short int *) xmalloc (sizeof (short int));
8418 fc
->col_offset
= (int *) xmalloc (sizeof (int));
8422 fc
->augmentation
= (char *) start
;
8423 /* PR 17512: file: 001-228113-0.004.
8424 Skip past augmentation name, but avoid running off the end of the data. */
8426 if (* start
++ == '\0')
8430 warn (_("No terminator for augmentation name\n"));
8434 if (strcmp (fc
->augmentation
, "eh") == 0)
8436 if (eh_addr_size
> (size_t) (end
- start
))
8438 start
+= eh_addr_size
;
8443 if (2 > (size_t) (end
- start
))
8445 GET (fc
->ptr_size
, 1);
8446 if (fc
->ptr_size
< 1 || fc
->ptr_size
> 8)
8448 warn (_("Invalid pointer size (%d) in CIE data\n"), fc
->ptr_size
);
8452 GET (fc
->segment_size
, 1);
8453 /* PR 17512: file: e99d2804. */
8454 if (fc
->segment_size
> 8 || fc
->segment_size
+ fc
->ptr_size
> 8)
8456 warn (_("Invalid segment size (%d) in CIE data\n"), fc
->segment_size
);
8460 eh_addr_size
= fc
->ptr_size
;
8464 fc
->ptr_size
= eh_addr_size
;
8465 fc
->segment_size
= 0;
8468 READ_ULEB (fc
->code_factor
, start
, end
);
8469 READ_SLEB (fc
->data_factor
, start
, end
);
8480 READ_ULEB (fc
->ra
, start
, end
);
8483 if (fc
->augmentation
[0] == 'z')
8487 READ_ULEB (augmentation_data_len
, start
, end
);
8488 augmentation_data
= start
;
8489 /* PR 17512: file: 11042-2589-0.004. */
8490 if (augmentation_data_len
> (bfd_size_type
) (end
- start
))
8492 warn (_("Augmentation data too long: 0x%s, expected at most %#lx\n"),
8493 dwarf_vmatoa ("x", augmentation_data_len
),
8494 (unsigned long) (end
- start
));
8497 start
+= augmentation_data_len
;
8500 if (augmentation_data_len
)
8504 unsigned char *qend
;
8506 p
= (unsigned char *) fc
->augmentation
+ 1;
8507 q
= augmentation_data
;
8508 qend
= q
+ augmentation_data_len
;
8510 while (p
< end
&& q
< qend
)
8515 q
+= 1 + size_of_encoded_value (*q
);
8517 fc
->fde_encoding
= *q
++;
8526 /* Note - it is OK if this loop terminates with q < qend.
8527 Padding may have been inserted to align the end of the CIE. */
8532 *p_version
= version
;
8535 *p_aug_len
= augmentation_data_len
;
8536 *p_aug
= augmentation_data
;
8541 free (fc
->col_offset
);
8542 free (fc
->col_type
);
8547 /* Prints out the contents on the DATA array formatted as unsigned bytes.
8548 If do_wide is not enabled, then formats the output to fit into 80 columns.
8549 PRINTED contains the number of characters already written to the current
8553 display_data (bfd_size_type printed
,
8554 const unsigned char * data
,
8555 const bfd_size_type len
)
8557 if (do_wide
|| len
< ((80 - printed
) / 3))
8558 for (printed
= 0; printed
< len
; ++printed
)
8559 printf (" %02x", data
[printed
]);
8562 for (printed
= 0; printed
< len
; ++printed
)
8564 if (printed
% (80 / 3) == 0)
8566 printf (" %02x", data
[printed
]);
8571 /* Prints out the contents on the augmentation data array.
8572 If do_wide is not enabled, then formats the output to fit into 80 columns. */
8575 display_augmentation_data (const unsigned char * data
, const bfd_size_type len
)
8579 i
= printf (_(" Augmentation data: "));
8580 display_data (i
, data
, len
);
8584 display_debug_frames (struct dwarf_section
*section
,
8585 void *file ATTRIBUTE_UNUSED
)
8587 unsigned char *start
= section
->start
;
8588 unsigned char *end
= start
+ section
->size
;
8589 unsigned char *section_start
= start
;
8590 Frame_Chunk
*chunks
= NULL
, *forward_refs
= NULL
;
8591 Frame_Chunk
*remembered_state
= NULL
;
8593 bool is_eh
= strcmp (section
->name
, ".eh_frame") == 0;
8594 unsigned int max_regs
= 0;
8595 const char *bad_reg
= _("bad register: ");
8596 unsigned int saved_eh_addr_size
= eh_addr_size
;
8598 introduce (section
, false);
8602 unsigned char *saved_start
;
8603 unsigned char *block_end
;
8608 int need_col_headers
= 1;
8609 unsigned char *augmentation_data
= NULL
;
8610 bfd_size_type augmentation_data_len
= 0;
8611 unsigned int encoded_ptr_size
= saved_eh_addr_size
;
8612 unsigned int offset_size
;
8614 static Frame_Chunk fde_fc
;
8616 saved_start
= start
;
8618 SAFE_BYTE_GET_AND_INC (length
, start
, 4, end
);
8622 printf ("\n%08lx ZERO terminator\n\n",
8623 (unsigned long)(saved_start
- section_start
));
8624 /* Skip any zero terminators that directly follow.
8625 A corrupt section size could have loaded a whole
8626 slew of zero filled memory bytes. eg
8627 PR 17512: file: 070-19381-0.004. */
8628 while (start
< end
&& * start
== 0)
8633 if (length
== 0xffffffff)
8635 SAFE_BYTE_GET_AND_INC (length
, start
, 8, end
);
8641 if (length
> (size_t) (end
- start
))
8643 warn ("Invalid length 0x%s in FDE at %#08lx\n",
8644 dwarf_vmatoa_1 (NULL
, length
, offset_size
),
8645 (unsigned long) (saved_start
- section_start
));
8649 block_end
= start
+ length
;
8651 SAFE_BYTE_GET_AND_INC (cie_id
, start
, offset_size
, block_end
);
8653 if (is_eh
? (cie_id
== 0) : ((offset_size
== 4 && cie_id
== DW_CIE_ID
)
8654 || (offset_size
== 8 && cie_id
== DW64_CIE_ID
)))
8659 start
= read_cie (start
, block_end
, &cie
, &version
,
8660 &augmentation_data_len
, &augmentation_data
);
8661 /* PR 17512: file: 027-135133-0.005. */
8668 fc
->chunk_start
= saved_start
;
8669 mreg
= max_regs
> 0 ? max_regs
- 1 : 0;
8672 if (frame_need_space (fc
, mreg
) < 0)
8674 if (fc
->fde_encoding
)
8675 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
8677 printf ("\n%08lx ", (unsigned long) (saved_start
- section_start
));
8678 print_dwarf_vma (length
, fc
->ptr_size
);
8679 print_dwarf_vma (cie_id
, offset_size
);
8681 if (do_debug_frames_interp
)
8683 printf ("CIE \"%s\" cf=%d df=%d ra=%d\n", fc
->augmentation
,
8684 fc
->code_factor
, fc
->data_factor
, fc
->ra
);
8689 printf (" Version: %d\n", version
);
8690 printf (" Augmentation: \"%s\"\n", fc
->augmentation
);
8693 printf (" Pointer Size: %u\n", fc
->ptr_size
);
8694 printf (" Segment Size: %u\n", fc
->segment_size
);
8696 printf (" Code alignment factor: %u\n", fc
->code_factor
);
8697 printf (" Data alignment factor: %d\n", fc
->data_factor
);
8698 printf (" Return address column: %d\n", fc
->ra
);
8700 if (augmentation_data_len
)
8701 display_augmentation_data (augmentation_data
, augmentation_data_len
);
8708 unsigned char *look_for
;
8709 unsigned long segment_selector
;
8715 dwarf_vma sign
= (dwarf_vma
) 1 << (offset_size
* 8 - 1);
8716 cie_off
= (cie_off
^ sign
) - sign
;
8717 cie_off
= start
- 4 - section_start
- cie_off
;
8720 look_for
= section_start
+ cie_off
;
8721 if (cie_off
<= (dwarf_vma
) (saved_start
- section_start
))
8723 for (cie
= chunks
; cie
; cie
= cie
->next
)
8724 if (cie
->chunk_start
== look_for
)
8727 else if (cie_off
>= section
->size
)
8731 for (cie
= forward_refs
; cie
; cie
= cie
->next
)
8732 if (cie
->chunk_start
== look_for
)
8736 unsigned int off_size
;
8737 unsigned char *cie_scan
;
8739 cie_scan
= look_for
;
8741 SAFE_BYTE_GET_AND_INC (length
, cie_scan
, 4, end
);
8742 if (length
== 0xffffffff)
8744 SAFE_BYTE_GET_AND_INC (length
, cie_scan
, 8, end
);
8747 if (length
!= 0 && length
<= (size_t) (end
- cie_scan
))
8750 unsigned char *cie_end
= cie_scan
+ length
;
8752 SAFE_BYTE_GET_AND_INC (c_id
, cie_scan
, off_size
,
8756 : ((off_size
== 4 && c_id
== DW_CIE_ID
)
8757 || (off_size
== 8 && c_id
== DW64_CIE_ID
)))
8762 read_cie (cie_scan
, cie_end
, &cie
, &version
,
8763 &augmentation_data_len
, &augmentation_data
);
8764 /* PR 17512: file: 3450-2098-0.004. */
8767 warn (_("Failed to read CIE information\n"));
8770 cie
->next
= forward_refs
;
8772 cie
->chunk_start
= look_for
;
8773 mreg
= max_regs
> 0 ? max_regs
- 1 : 0;
8776 if (frame_need_space (cie
, mreg
) < 0)
8778 warn (_("Invalid max register\n"));
8781 if (cie
->fde_encoding
)
8783 = size_of_encoded_value (cie
->fde_encoding
);
8790 memset (fc
, 0, sizeof (Frame_Chunk
));
8795 fc
->col_type
= (short int *) xmalloc (sizeof (short int));
8796 fc
->col_offset
= (int *) xmalloc (sizeof (int));
8797 if (frame_need_space (fc
, max_regs
> 0 ? max_regs
- 1 : 0) < 0)
8799 warn (_("Invalid max register\n"));
8803 fc
->augmentation
= "";
8804 fc
->fde_encoding
= 0;
8805 fc
->ptr_size
= eh_addr_size
;
8806 fc
->segment_size
= 0;
8810 fc
->ncols
= cie
->ncols
;
8811 fc
->col_type
= (short int *) xcmalloc (fc
->ncols
, sizeof (short int));
8812 fc
->col_offset
= (int *) xcmalloc (fc
->ncols
, sizeof (int));
8813 memcpy (fc
->col_type
, cie
->col_type
, fc
->ncols
* sizeof (short int));
8814 memcpy (fc
->col_offset
, cie
->col_offset
, fc
->ncols
* sizeof (int));
8815 fc
->augmentation
= cie
->augmentation
;
8816 fc
->ptr_size
= cie
->ptr_size
;
8817 eh_addr_size
= cie
->ptr_size
;
8818 fc
->segment_size
= cie
->segment_size
;
8819 fc
->code_factor
= cie
->code_factor
;
8820 fc
->data_factor
= cie
->data_factor
;
8821 fc
->cfa_reg
= cie
->cfa_reg
;
8822 fc
->cfa_offset
= cie
->cfa_offset
;
8824 if (frame_need_space (fc
, max_regs
> 0 ? max_regs
- 1: 0) < 0)
8826 warn (_("Invalid max register\n"));
8829 fc
->fde_encoding
= cie
->fde_encoding
;
8832 if (fc
->fde_encoding
)
8833 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
8835 segment_selector
= 0;
8836 if (fc
->segment_size
)
8838 if (fc
->segment_size
> sizeof (segment_selector
))
8840 /* PR 17512: file: 9e196b3e. */
8841 warn (_("Probably corrupt segment size: %d - using 4 instead\n"), fc
->segment_size
);
8842 fc
->segment_size
= 4;
8844 SAFE_BYTE_GET_AND_INC (segment_selector
, start
,
8845 fc
->segment_size
, block_end
);
8848 fc
->pc_begin
= get_encoded_value (&start
, fc
->fde_encoding
, section
,
8851 /* FIXME: It appears that sometimes the final pc_range value is
8852 encoded in less than encoded_ptr_size bytes. See the x86_64
8853 run of the "objcopy on compressed debug sections" test for an
8855 SAFE_BYTE_GET_AND_INC (fc
->pc_range
, start
, encoded_ptr_size
,
8858 if (cie
->augmentation
[0] == 'z')
8860 READ_ULEB (augmentation_data_len
, start
, block_end
);
8861 augmentation_data
= start
;
8862 /* PR 17512 file: 722-8446-0.004 and PR 22386. */
8863 if (augmentation_data_len
> (bfd_size_type
) (block_end
- start
))
8865 warn (_("Augmentation data too long: 0x%s, "
8866 "expected at most %#lx\n"),
8867 dwarf_vmatoa ("x", augmentation_data_len
),
8868 (unsigned long) (block_end
- start
));
8870 augmentation_data
= NULL
;
8871 augmentation_data_len
= 0;
8873 start
+= augmentation_data_len
;
8876 printf ("\n%08lx %s %s FDE ",
8877 (unsigned long)(saved_start
- section_start
),
8878 dwarf_vmatoa_1 (NULL
, length
, fc
->ptr_size
),
8879 dwarf_vmatoa_1 (NULL
, cie_id
, offset_size
));
8881 if (cie
->chunk_start
)
8882 printf ("cie=%08lx",
8883 (unsigned long) (cie
->chunk_start
- section_start
));
8885 /* Ideally translate "invalid " to 8 chars, trailing space
8887 printf (_("cie=invalid "));
8890 if (fc
->segment_size
)
8891 printf ("%04lx:", segment_selector
);
8894 dwarf_vmatoa_1 (NULL
, fc
->pc_begin
, fc
->ptr_size
),
8895 dwarf_vmatoa_1 (NULL
, fc
->pc_begin
+ fc
->pc_range
, fc
->ptr_size
));
8897 if (! do_debug_frames_interp
&& augmentation_data_len
)
8899 display_augmentation_data (augmentation_data
, augmentation_data_len
);
8904 /* At this point, fc is the current chunk, cie (if any) is set, and
8905 we're about to interpret instructions for the chunk. */
8906 /* ??? At present we need to do this always, since this sizes the
8907 fc->col_type and fc->col_offset arrays, which we write into always.
8908 We should probably split the interpreted and non-interpreted bits
8909 into two different routines, since there's so much that doesn't
8910 really overlap between them. */
8911 if (1 || do_debug_frames_interp
)
8913 /* Start by making a pass over the chunk, allocating storage
8914 and taking note of what registers are used. */
8915 unsigned char *tmp
= start
;
8917 while (start
< block_end
)
8919 unsigned int reg
, op
, opa
;
8927 /* Warning: if you add any more cases to this switch, be
8928 sure to add them to the corresponding switch below. */
8931 case DW_CFA_advance_loc
:
8934 SKIP_ULEB (start
, block_end
);
8935 if (frame_need_space (fc
, opa
) >= 0)
8936 fc
->col_type
[opa
] = DW_CFA_undefined
;
8938 case DW_CFA_restore
:
8939 if (frame_need_space (fc
, opa
) >= 0)
8940 fc
->col_type
[opa
] = DW_CFA_undefined
;
8942 case DW_CFA_set_loc
:
8943 if ((size_t) (block_end
- start
) < encoded_ptr_size
)
8946 start
+= encoded_ptr_size
;
8948 case DW_CFA_advance_loc1
:
8949 if ((size_t) (block_end
- start
) < 1)
8954 case DW_CFA_advance_loc2
:
8955 if ((size_t) (block_end
- start
) < 2)
8960 case DW_CFA_advance_loc4
:
8961 if ((size_t) (block_end
- start
) < 4)
8966 case DW_CFA_offset_extended
:
8967 case DW_CFA_val_offset
:
8968 READ_ULEB (reg
, start
, block_end
);
8969 SKIP_ULEB (start
, block_end
);
8970 if (frame_need_space (fc
, reg
) >= 0)
8971 fc
->col_type
[reg
] = DW_CFA_undefined
;
8973 case DW_CFA_restore_extended
:
8974 READ_ULEB (reg
, start
, block_end
);
8975 if (frame_need_space (fc
, reg
) >= 0)
8976 fc
->col_type
[reg
] = DW_CFA_undefined
;
8978 case DW_CFA_undefined
:
8979 READ_ULEB (reg
, start
, block_end
);
8980 if (frame_need_space (fc
, reg
) >= 0)
8981 fc
->col_type
[reg
] = DW_CFA_undefined
;
8983 case DW_CFA_same_value
:
8984 READ_ULEB (reg
, start
, block_end
);
8985 if (frame_need_space (fc
, reg
) >= 0)
8986 fc
->col_type
[reg
] = DW_CFA_undefined
;
8988 case DW_CFA_register
:
8989 READ_ULEB (reg
, start
, block_end
);
8990 SKIP_ULEB (start
, block_end
);
8991 if (frame_need_space (fc
, reg
) >= 0)
8992 fc
->col_type
[reg
] = DW_CFA_undefined
;
8994 case DW_CFA_def_cfa
:
8995 SKIP_ULEB (start
, block_end
);
8996 SKIP_ULEB (start
, block_end
);
8998 case DW_CFA_def_cfa_register
:
8999 SKIP_ULEB (start
, block_end
);
9001 case DW_CFA_def_cfa_offset
:
9002 SKIP_ULEB (start
, block_end
);
9004 case DW_CFA_def_cfa_expression
:
9005 READ_ULEB (temp
, start
, block_end
);
9006 if ((size_t) (block_end
- start
) < temp
)
9011 case DW_CFA_expression
:
9012 case DW_CFA_val_expression
:
9013 READ_ULEB (reg
, start
, block_end
);
9014 READ_ULEB (temp
, start
, block_end
);
9015 if ((size_t) (block_end
- start
) < temp
)
9019 if (frame_need_space (fc
, reg
) >= 0)
9020 fc
->col_type
[reg
] = DW_CFA_undefined
;
9022 case DW_CFA_offset_extended_sf
:
9023 case DW_CFA_val_offset_sf
:
9024 READ_ULEB (reg
, start
, block_end
);
9025 SKIP_SLEB (start
, block_end
);
9026 if (frame_need_space (fc
, reg
) >= 0)
9027 fc
->col_type
[reg
] = DW_CFA_undefined
;
9029 case DW_CFA_def_cfa_sf
:
9030 SKIP_ULEB (start
, block_end
);
9031 SKIP_SLEB (start
, block_end
);
9033 case DW_CFA_def_cfa_offset_sf
:
9034 SKIP_SLEB (start
, block_end
);
9036 case DW_CFA_MIPS_advance_loc8
:
9037 if ((size_t) (block_end
- start
) < 8)
9042 case DW_CFA_GNU_args_size
:
9043 SKIP_ULEB (start
, block_end
);
9045 case DW_CFA_GNU_negative_offset_extended
:
9046 READ_ULEB (reg
, start
, block_end
);
9047 SKIP_ULEB (start
, block_end
);
9048 if (frame_need_space (fc
, reg
) >= 0)
9049 fc
->col_type
[reg
] = DW_CFA_undefined
;
9060 /* Now we know what registers are used, make a second pass over
9061 the chunk, this time actually printing out the info. */
9063 while (start
< block_end
)
9066 unsigned long ul
, roffs
;
9067 /* Note: It is tempting to use an unsigned long for 'reg' but there
9068 are various functions, notably frame_space_needed() that assume that
9069 reg is an unsigned int. */
9074 const char *reg_prefix
= "";
9081 /* Make a note if something other than DW_CFA_nop happens. */
9082 if (op
!= DW_CFA_nop
)
9085 /* Warning: if you add any more cases to this switch, be
9086 sure to add them to the corresponding switch above. */
9089 case DW_CFA_advance_loc
:
9090 if (do_debug_frames_interp
)
9091 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9093 printf (" DW_CFA_advance_loc: %d to %s\n",
9094 opa
* fc
->code_factor
,
9095 dwarf_vmatoa_1 (NULL
,
9096 fc
->pc_begin
+ opa
* fc
->code_factor
,
9098 fc
->pc_begin
+= opa
* fc
->code_factor
;
9102 READ_ULEB (roffs
, start
, block_end
);
9103 if (opa
>= (unsigned int) fc
->ncols
)
9104 reg_prefix
= bad_reg
;
9105 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9106 printf (" DW_CFA_offset: %s%s at cfa%+ld\n",
9107 reg_prefix
, regname (opa
, 0),
9108 roffs
* fc
->data_factor
);
9109 if (*reg_prefix
== '\0')
9111 fc
->col_type
[opa
] = DW_CFA_offset
;
9112 fc
->col_offset
[opa
] = roffs
* fc
->data_factor
;
9116 case DW_CFA_restore
:
9117 if (opa
>= (unsigned int) fc
->ncols
)
9118 reg_prefix
= bad_reg
;
9119 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9120 printf (" DW_CFA_restore: %s%s\n",
9121 reg_prefix
, regname (opa
, 0));
9122 if (*reg_prefix
!= '\0')
9125 if (opa
>= (unsigned int) cie
->ncols
9126 || (do_debug_frames_interp
9127 && cie
->col_type
[opa
] == DW_CFA_unreferenced
))
9129 fc
->col_type
[opa
] = DW_CFA_undefined
;
9130 fc
->col_offset
[opa
] = 0;
9134 fc
->col_type
[opa
] = cie
->col_type
[opa
];
9135 fc
->col_offset
[opa
] = cie
->col_offset
[opa
];
9139 case DW_CFA_set_loc
:
9140 vma
= get_encoded_value (&start
, fc
->fde_encoding
, section
,
9142 if (do_debug_frames_interp
)
9143 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9145 printf (" DW_CFA_set_loc: %s\n",
9146 dwarf_vmatoa_1 (NULL
, vma
, fc
->ptr_size
));
9150 case DW_CFA_advance_loc1
:
9151 SAFE_BYTE_GET_AND_INC (ofs
, start
, 1, block_end
);
9152 if (do_debug_frames_interp
)
9153 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9155 printf (" DW_CFA_advance_loc1: %ld to %s\n",
9156 (unsigned long) (ofs
* fc
->code_factor
),
9157 dwarf_vmatoa_1 (NULL
,
9158 fc
->pc_begin
+ ofs
* fc
->code_factor
,
9160 fc
->pc_begin
+= ofs
* fc
->code_factor
;
9163 case DW_CFA_advance_loc2
:
9164 SAFE_BYTE_GET_AND_INC (ofs
, start
, 2, block_end
);
9165 if (do_debug_frames_interp
)
9166 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9168 printf (" DW_CFA_advance_loc2: %ld to %s\n",
9169 (unsigned long) (ofs
* fc
->code_factor
),
9170 dwarf_vmatoa_1 (NULL
,
9171 fc
->pc_begin
+ ofs
* fc
->code_factor
,
9173 fc
->pc_begin
+= ofs
* fc
->code_factor
;
9176 case DW_CFA_advance_loc4
:
9177 SAFE_BYTE_GET_AND_INC (ofs
, start
, 4, block_end
);
9178 if (do_debug_frames_interp
)
9179 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9181 printf (" DW_CFA_advance_loc4: %ld to %s\n",
9182 (unsigned long) (ofs
* fc
->code_factor
),
9183 dwarf_vmatoa_1 (NULL
,
9184 fc
->pc_begin
+ ofs
* fc
->code_factor
,
9186 fc
->pc_begin
+= ofs
* fc
->code_factor
;
9189 case DW_CFA_offset_extended
:
9190 READ_ULEB (reg
, start
, block_end
);
9191 READ_ULEB (roffs
, start
, block_end
);
9192 if (reg
>= (unsigned int) fc
->ncols
)
9193 reg_prefix
= bad_reg
;
9194 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9195 printf (" DW_CFA_offset_extended: %s%s at cfa%+ld\n",
9196 reg_prefix
, regname (reg
, 0),
9197 roffs
* fc
->data_factor
);
9198 if (*reg_prefix
== '\0')
9200 fc
->col_type
[reg
] = DW_CFA_offset
;
9201 fc
->col_offset
[reg
] = roffs
* fc
->data_factor
;
9205 case DW_CFA_val_offset
:
9206 READ_ULEB (reg
, start
, block_end
);
9207 READ_ULEB (roffs
, start
, block_end
);
9208 if (reg
>= (unsigned int) fc
->ncols
)
9209 reg_prefix
= bad_reg
;
9210 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9211 printf (" DW_CFA_val_offset: %s%s is cfa%+ld\n",
9212 reg_prefix
, regname (reg
, 0),
9213 roffs
* fc
->data_factor
);
9214 if (*reg_prefix
== '\0')
9216 fc
->col_type
[reg
] = DW_CFA_val_offset
;
9217 fc
->col_offset
[reg
] = roffs
* fc
->data_factor
;
9221 case DW_CFA_restore_extended
:
9222 READ_ULEB (reg
, start
, block_end
);
9223 if (reg
>= (unsigned int) fc
->ncols
)
9224 reg_prefix
= bad_reg
;
9225 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9226 printf (" DW_CFA_restore_extended: %s%s\n",
9227 reg_prefix
, regname (reg
, 0));
9228 if (*reg_prefix
!= '\0')
9231 if (reg
>= (unsigned int) cie
->ncols
)
9233 fc
->col_type
[reg
] = DW_CFA_undefined
;
9234 fc
->col_offset
[reg
] = 0;
9238 fc
->col_type
[reg
] = cie
->col_type
[reg
];
9239 fc
->col_offset
[reg
] = cie
->col_offset
[reg
];
9243 case DW_CFA_undefined
:
9244 READ_ULEB (reg
, start
, block_end
);
9245 if (reg
>= (unsigned int) fc
->ncols
)
9246 reg_prefix
= bad_reg
;
9247 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9248 printf (" DW_CFA_undefined: %s%s\n",
9249 reg_prefix
, regname (reg
, 0));
9250 if (*reg_prefix
== '\0')
9252 fc
->col_type
[reg
] = DW_CFA_undefined
;
9253 fc
->col_offset
[reg
] = 0;
9257 case DW_CFA_same_value
:
9258 READ_ULEB (reg
, start
, block_end
);
9259 if (reg
>= (unsigned int) fc
->ncols
)
9260 reg_prefix
= bad_reg
;
9261 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9262 printf (" DW_CFA_same_value: %s%s\n",
9263 reg_prefix
, regname (reg
, 0));
9264 if (*reg_prefix
== '\0')
9266 fc
->col_type
[reg
] = DW_CFA_same_value
;
9267 fc
->col_offset
[reg
] = 0;
9271 case DW_CFA_register
:
9272 READ_ULEB (reg
, start
, block_end
);
9273 READ_ULEB (roffs
, start
, block_end
);
9274 if (reg
>= (unsigned int) fc
->ncols
)
9275 reg_prefix
= bad_reg
;
9276 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9278 printf (" DW_CFA_register: %s%s in ",
9279 reg_prefix
, regname (reg
, 0));
9280 puts (regname (roffs
, 0));
9282 if (*reg_prefix
== '\0')
9284 fc
->col_type
[reg
] = DW_CFA_register
;
9285 fc
->col_offset
[reg
] = roffs
;
9289 case DW_CFA_remember_state
:
9290 if (! do_debug_frames_interp
)
9291 printf (" DW_CFA_remember_state\n");
9292 rs
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
9293 rs
->cfa_offset
= fc
->cfa_offset
;
9294 rs
->cfa_reg
= fc
->cfa_reg
;
9296 rs
->cfa_exp
= fc
->cfa_exp
;
9297 rs
->ncols
= fc
->ncols
;
9298 rs
->col_type
= (short int *) xcmalloc (rs
->ncols
,
9299 sizeof (* rs
->col_type
));
9300 rs
->col_offset
= (int *) xcmalloc (rs
->ncols
, sizeof (* rs
->col_offset
));
9301 memcpy (rs
->col_type
, fc
->col_type
, rs
->ncols
* sizeof (* fc
->col_type
));
9302 memcpy (rs
->col_offset
, fc
->col_offset
, rs
->ncols
* sizeof (* fc
->col_offset
));
9303 rs
->next
= remembered_state
;
9304 remembered_state
= rs
;
9307 case DW_CFA_restore_state
:
9308 if (! do_debug_frames_interp
)
9309 printf (" DW_CFA_restore_state\n");
9310 rs
= remembered_state
;
9313 remembered_state
= rs
->next
;
9314 fc
->cfa_offset
= rs
->cfa_offset
;
9315 fc
->cfa_reg
= rs
->cfa_reg
;
9317 fc
->cfa_exp
= rs
->cfa_exp
;
9318 if (frame_need_space (fc
, rs
->ncols
- 1) < 0)
9320 warn (_("Invalid column number in saved frame state\n"));
9324 memcpy (fc
->col_type
, rs
->col_type
, rs
->ncols
* sizeof (* rs
->col_type
));
9325 memcpy (fc
->col_offset
, rs
->col_offset
,
9326 rs
->ncols
* sizeof (* rs
->col_offset
));
9327 free (rs
->col_type
);
9328 free (rs
->col_offset
);
9331 else if (do_debug_frames_interp
)
9332 printf ("Mismatched DW_CFA_restore_state\n");
9335 case DW_CFA_def_cfa
:
9336 READ_ULEB (fc
->cfa_reg
, start
, block_end
);
9337 READ_ULEB (fc
->cfa_offset
, start
, block_end
);
9339 if (! do_debug_frames_interp
)
9340 printf (" DW_CFA_def_cfa: %s ofs %d\n",
9341 regname (fc
->cfa_reg
, 0), (int) fc
->cfa_offset
);
9344 case DW_CFA_def_cfa_register
:
9345 READ_ULEB (fc
->cfa_reg
, start
, block_end
);
9347 if (! do_debug_frames_interp
)
9348 printf (" DW_CFA_def_cfa_register: %s\n",
9349 regname (fc
->cfa_reg
, 0));
9352 case DW_CFA_def_cfa_offset
:
9353 READ_ULEB (fc
->cfa_offset
, start
, block_end
);
9354 if (! do_debug_frames_interp
)
9355 printf (" DW_CFA_def_cfa_offset: %d\n", (int) fc
->cfa_offset
);
9359 if (! do_debug_frames_interp
)
9360 printf (" DW_CFA_nop\n");
9363 case DW_CFA_def_cfa_expression
:
9364 READ_ULEB (ul
, start
, block_end
);
9365 if (ul
> (size_t) (block_end
- start
))
9367 printf (_(" DW_CFA_def_cfa_expression: <corrupt len %lu>\n"), ul
);
9370 if (! do_debug_frames_interp
)
9372 printf (" DW_CFA_def_cfa_expression (");
9373 decode_location_expression (start
, eh_addr_size
, 0, -1,
9381 case DW_CFA_expression
:
9382 READ_ULEB (reg
, start
, block_end
);
9383 READ_ULEB (ul
, start
, block_end
);
9384 if (reg
>= (unsigned int) fc
->ncols
)
9385 reg_prefix
= bad_reg
;
9386 /* PR 17512: file: 069-133014-0.006. */
9387 /* PR 17512: file: 98c02eb4. */
9388 if (ul
> (size_t) (block_end
- start
))
9390 printf (_(" DW_CFA_expression: <corrupt len %lu>\n"), ul
);
9393 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9395 printf (" DW_CFA_expression: %s%s (",
9396 reg_prefix
, regname (reg
, 0));
9397 decode_location_expression (start
, eh_addr_size
, 0, -1,
9401 if (*reg_prefix
== '\0')
9402 fc
->col_type
[reg
] = DW_CFA_expression
;
9406 case DW_CFA_val_expression
:
9407 READ_ULEB (reg
, start
, block_end
);
9408 READ_ULEB (ul
, start
, block_end
);
9409 if (reg
>= (unsigned int) fc
->ncols
)
9410 reg_prefix
= bad_reg
;
9411 if (ul
> (size_t) (block_end
- start
))
9413 printf (" DW_CFA_val_expression: <corrupt len %lu>\n", ul
);
9416 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9418 printf (" DW_CFA_val_expression: %s%s (",
9419 reg_prefix
, regname (reg
, 0));
9420 decode_location_expression (start
, eh_addr_size
, 0, -1,
9424 if (*reg_prefix
== '\0')
9425 fc
->col_type
[reg
] = DW_CFA_val_expression
;
9429 case DW_CFA_offset_extended_sf
:
9430 READ_ULEB (reg
, start
, block_end
);
9431 READ_SLEB (l
, start
, block_end
);
9432 if (frame_need_space (fc
, reg
) < 0)
9433 reg_prefix
= bad_reg
;
9434 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9435 printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+ld\n",
9436 reg_prefix
, regname (reg
, 0),
9437 (long)(l
* fc
->data_factor
));
9438 if (*reg_prefix
== '\0')
9440 fc
->col_type
[reg
] = DW_CFA_offset
;
9441 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
9445 case DW_CFA_val_offset_sf
:
9446 READ_ULEB (reg
, start
, block_end
);
9447 READ_SLEB (l
, start
, block_end
);
9448 if (frame_need_space (fc
, reg
) < 0)
9449 reg_prefix
= bad_reg
;
9450 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9451 printf (" DW_CFA_val_offset_sf: %s%s is cfa%+ld\n",
9452 reg_prefix
, regname (reg
, 0),
9453 (long)(l
* fc
->data_factor
));
9454 if (*reg_prefix
== '\0')
9456 fc
->col_type
[reg
] = DW_CFA_val_offset
;
9457 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
9461 case DW_CFA_def_cfa_sf
:
9462 READ_ULEB (fc
->cfa_reg
, start
, block_end
);
9463 READ_SLEB (l
, start
, block_end
);
9464 l
*= fc
->data_factor
;
9467 if (! do_debug_frames_interp
)
9468 printf (" DW_CFA_def_cfa_sf: %s ofs %ld\n",
9469 regname (fc
->cfa_reg
, 0), (long) l
);
9472 case DW_CFA_def_cfa_offset_sf
:
9473 READ_SLEB (l
, start
, block_end
);
9474 l
*= fc
->data_factor
;
9476 if (! do_debug_frames_interp
)
9477 printf (" DW_CFA_def_cfa_offset_sf: %ld\n", (long) l
);
9480 case DW_CFA_MIPS_advance_loc8
:
9481 SAFE_BYTE_GET_AND_INC (ofs
, start
, 8, block_end
);
9482 if (do_debug_frames_interp
)
9483 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9485 printf (" DW_CFA_MIPS_advance_loc8: %ld to %s\n",
9486 (unsigned long) (ofs
* fc
->code_factor
),
9487 dwarf_vmatoa_1 (NULL
,
9488 fc
->pc_begin
+ ofs
* fc
->code_factor
,
9490 fc
->pc_begin
+= ofs
* fc
->code_factor
;
9493 case DW_CFA_GNU_window_save
:
9494 if (! do_debug_frames_interp
)
9495 printf (" DW_CFA_GNU_window_save\n");
9498 case DW_CFA_GNU_args_size
:
9499 READ_ULEB (ul
, start
, block_end
);
9500 if (! do_debug_frames_interp
)
9501 printf (" DW_CFA_GNU_args_size: %ld\n", ul
);
9504 case DW_CFA_GNU_negative_offset_extended
:
9505 READ_ULEB (reg
, start
, block_end
);
9506 READ_SLEB (l
, start
, block_end
);
9508 if (frame_need_space (fc
, reg
) < 0)
9509 reg_prefix
= bad_reg
;
9510 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9511 printf (" DW_CFA_GNU_negative_offset_extended: %s%s at cfa%+ld\n",
9512 reg_prefix
, regname (reg
, 0),
9513 (long)(l
* fc
->data_factor
));
9514 if (*reg_prefix
== '\0')
9516 fc
->col_type
[reg
] = DW_CFA_offset
;
9517 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
9522 if (op
>= DW_CFA_lo_user
&& op
<= DW_CFA_hi_user
)
9523 printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op
);
9525 warn (_("Unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op
);
9530 /* Interpret the CFA - as long as it is not completely full of NOPs. */
9531 if (do_debug_frames_interp
&& ! all_nops
)
9532 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9534 if (fde_fc
.col_type
!= NULL
)
9536 free (fde_fc
.col_type
);
9537 fde_fc
.col_type
= NULL
;
9539 if (fde_fc
.col_offset
!= NULL
)
9541 free (fde_fc
.col_offset
);
9542 fde_fc
.col_offset
= NULL
;
9546 eh_addr_size
= saved_eh_addr_size
;
9551 while (remembered_state
!= NULL
)
9553 rs
= remembered_state
;
9554 remembered_state
= rs
->next
;
9555 free (rs
->col_type
);
9556 free (rs
->col_offset
);
9557 rs
->next
= NULL
; /* Paranoia. */
9561 while (chunks
!= NULL
)
9565 free (rs
->col_type
);
9566 free (rs
->col_offset
);
9567 rs
->next
= NULL
; /* Paranoia. */
9571 while (forward_refs
!= NULL
)
9574 forward_refs
= rs
->next
;
9575 free (rs
->col_type
);
9576 free (rs
->col_offset
);
9577 rs
->next
= NULL
; /* Paranoia. */
9587 display_debug_names (struct dwarf_section
*section
, void *file
)
9589 unsigned char *hdrptr
= section
->start
;
9590 dwarf_vma unit_length
;
9591 unsigned char *unit_start
;
9592 const unsigned char *const section_end
= section
->start
+ section
->size
;
9593 unsigned char *unit_end
;
9595 introduce (section
, false);
9597 load_debug_section_with_follow (str
, file
);
9599 for (; hdrptr
< section_end
; hdrptr
= unit_end
)
9601 unsigned int offset_size
;
9602 uint16_t dwarf_version
, padding
;
9603 uint32_t comp_unit_count
, local_type_unit_count
, foreign_type_unit_count
;
9604 uint64_t bucket_count
, name_count
, abbrev_table_size
;
9605 uint32_t augmentation_string_size
;
9607 bool augmentation_printable
;
9608 const char *augmentation_string
;
9611 unit_start
= hdrptr
;
9613 /* Get and check the length of the block. */
9614 SAFE_BYTE_GET_AND_INC (unit_length
, hdrptr
, 4, section_end
);
9616 if (unit_length
== 0xffffffff)
9618 /* This section is 64-bit DWARF. */
9619 SAFE_BYTE_GET_AND_INC (unit_length
, hdrptr
, 8, section_end
);
9625 if (unit_length
> (size_t) (section_end
- hdrptr
)
9626 || unit_length
< 2 + 2 + 4 * 7)
9629 warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"),
9631 (unsigned long) (unit_start
- section
->start
),
9632 dwarf_vmatoa ("x", unit_length
));
9635 unit_end
= hdrptr
+ unit_length
;
9637 /* Get and check the version number. */
9638 SAFE_BYTE_GET_AND_INC (dwarf_version
, hdrptr
, 2, unit_end
);
9639 printf (_("Version %ld\n"), (long) dwarf_version
);
9641 /* Prior versions did not exist, and future versions may not be
9642 backwards compatible. */
9643 if (dwarf_version
!= 5)
9645 warn (_("Only DWARF version 5 .debug_names "
9646 "is currently supported.\n"));
9650 SAFE_BYTE_GET_AND_INC (padding
, hdrptr
, 2, unit_end
);
9652 warn (_("Padding field of .debug_names must be 0 (found 0x%x)\n"),
9655 SAFE_BYTE_GET_AND_INC (comp_unit_count
, hdrptr
, 4, unit_end
);
9656 if (comp_unit_count
== 0)
9657 warn (_("Compilation unit count must be >= 1 in .debug_names\n"));
9659 SAFE_BYTE_GET_AND_INC (local_type_unit_count
, hdrptr
, 4, unit_end
);
9660 SAFE_BYTE_GET_AND_INC (foreign_type_unit_count
, hdrptr
, 4, unit_end
);
9661 SAFE_BYTE_GET_AND_INC (bucket_count
, hdrptr
, 4, unit_end
);
9662 SAFE_BYTE_GET_AND_INC (name_count
, hdrptr
, 4, unit_end
);
9663 SAFE_BYTE_GET_AND_INC (abbrev_table_size
, hdrptr
, 4, unit_end
);
9665 SAFE_BYTE_GET_AND_INC (augmentation_string_size
, hdrptr
, 4, unit_end
);
9666 if (augmentation_string_size
% 4 != 0)
9668 warn (_("Augmentation string length %u must be rounded up "
9669 "to a multiple of 4 in .debug_names.\n"),
9670 augmentation_string_size
);
9671 augmentation_string_size
+= (-augmentation_string_size
) & 3;
9673 if (augmentation_string_size
> (size_t) (unit_end
- hdrptr
))
9676 printf (_("Augmentation string:"));
9678 augmentation_printable
= true;
9679 augmentation_string
= (const char *) hdrptr
;
9681 for (i
= 0; i
< augmentation_string_size
; i
++)
9685 SAFE_BYTE_GET_AND_INC (uc
, hdrptr
, 1, unit_end
);
9686 printf (" %02x", uc
);
9688 if (uc
!= 0 && !ISPRINT (uc
))
9689 augmentation_printable
= false;
9692 if (augmentation_printable
)
9696 i
< augmentation_string_size
&& augmentation_string
[i
];
9698 putchar (augmentation_string
[i
]);
9703 printf (_("CU table:\n"));
9704 if (_mul_overflow (comp_unit_count
, offset_size
, &total
)
9705 || total
> (size_t) (unit_end
- hdrptr
))
9707 for (i
= 0; i
< comp_unit_count
; i
++)
9711 SAFE_BYTE_GET_AND_INC (cu_offset
, hdrptr
, offset_size
, unit_end
);
9712 printf (_("[%3u] 0x%lx\n"), i
, (unsigned long) cu_offset
);
9716 printf (_("TU table:\n"));
9717 if (_mul_overflow (local_type_unit_count
, offset_size
, &total
)
9718 || total
> (size_t) (unit_end
- hdrptr
))
9720 for (i
= 0; i
< local_type_unit_count
; i
++)
9724 SAFE_BYTE_GET_AND_INC (tu_offset
, hdrptr
, offset_size
, unit_end
);
9725 printf (_("[%3u] 0x%lx\n"), i
, (unsigned long) tu_offset
);
9729 printf (_("Foreign TU table:\n"));
9730 if (_mul_overflow (foreign_type_unit_count
, 8, &total
)
9731 || total
> (size_t) (unit_end
- hdrptr
))
9733 for (i
= 0; i
< foreign_type_unit_count
; i
++)
9737 SAFE_BYTE_GET_AND_INC (signature
, hdrptr
, 8, unit_end
);
9738 printf (_("[%3u] "), i
);
9739 print_dwarf_vma (signature
, 8);
9744 uint64_t xtra
= (bucket_count
* sizeof (uint32_t)
9745 + name_count
* (sizeof (uint32_t) + 2 * offset_size
)
9746 + abbrev_table_size
);
9747 if (xtra
> (size_t) (unit_end
- hdrptr
))
9749 warn (_("Entry pool offset (0x%lx) exceeds unit size 0x%lx "
9750 "for unit 0x%lx in the debug_names\n"),
9752 (long) (unit_end
- unit_start
),
9753 (long) (unit_start
- section
->start
));
9756 const uint32_t *const hash_table_buckets
= (uint32_t *) hdrptr
;
9757 hdrptr
+= bucket_count
* sizeof (uint32_t);
9758 const uint32_t *const hash_table_hashes
= (uint32_t *) hdrptr
;
9759 hdrptr
+= name_count
* sizeof (uint32_t);
9760 unsigned char *const name_table_string_offsets
= hdrptr
;
9761 hdrptr
+= name_count
* offset_size
;
9762 unsigned char *const name_table_entry_offsets
= hdrptr
;
9763 hdrptr
+= name_count
* offset_size
;
9764 unsigned char *const abbrev_table
= hdrptr
;
9765 hdrptr
+= abbrev_table_size
;
9766 const unsigned char *const abbrev_table_end
= hdrptr
;
9767 unsigned char *const entry_pool
= hdrptr
;
9769 size_t buckets_filled
= 0;
9771 for (bucketi
= 0; bucketi
< bucket_count
; bucketi
++)
9773 const uint32_t bucket
= hash_table_buckets
[bucketi
];
9778 printf (ngettext ("Used %zu of %lu bucket.\n",
9779 "Used %zu of %lu buckets.\n",
9781 buckets_filled
, (unsigned long) bucket_count
);
9783 uint32_t hash_prev
= 0;
9784 size_t hash_clash_count
= 0;
9785 size_t longest_clash
= 0;
9786 size_t this_length
= 0;
9788 for (hashi
= 0; hashi
< name_count
; hashi
++)
9790 const uint32_t hash_this
= hash_table_hashes
[hashi
];
9794 if (hash_prev
% bucket_count
== hash_this
% bucket_count
)
9798 longest_clash
= MAX (longest_clash
, this_length
);
9803 hash_prev
= hash_this
;
9805 printf (_("Out of %lu items there are %zu bucket clashes"
9806 " (longest of %zu entries).\n"),
9807 (unsigned long) name_count
, hash_clash_count
, longest_clash
);
9808 assert (name_count
== buckets_filled
+ hash_clash_count
);
9810 struct abbrev_lookup_entry
9812 dwarf_vma abbrev_tag
;
9813 unsigned char *abbrev_lookup_ptr
;
9815 struct abbrev_lookup_entry
*abbrev_lookup
= NULL
;
9816 size_t abbrev_lookup_used
= 0;
9817 size_t abbrev_lookup_allocated
= 0;
9819 unsigned char *abbrevptr
= abbrev_table
;
9822 dwarf_vma abbrev_tag
;
9824 READ_ULEB (abbrev_tag
, abbrevptr
, abbrev_table_end
);
9825 if (abbrev_tag
== 0)
9827 if (abbrev_lookup_used
== abbrev_lookup_allocated
)
9829 abbrev_lookup_allocated
= MAX (0x100,
9830 abbrev_lookup_allocated
* 2);
9831 abbrev_lookup
= xrealloc (abbrev_lookup
,
9832 (abbrev_lookup_allocated
9833 * sizeof (*abbrev_lookup
)));
9835 assert (abbrev_lookup_used
< abbrev_lookup_allocated
);
9836 struct abbrev_lookup_entry
*entry
;
9837 for (entry
= abbrev_lookup
;
9838 entry
< abbrev_lookup
+ abbrev_lookup_used
;
9840 if (entry
->abbrev_tag
== abbrev_tag
)
9842 warn (_("Duplicate abbreviation tag %lu "
9843 "in unit 0x%lx in the debug_names\n"),
9844 (long) abbrev_tag
, (long) (unit_start
- section
->start
));
9847 entry
= &abbrev_lookup
[abbrev_lookup_used
++];
9848 entry
->abbrev_tag
= abbrev_tag
;
9849 entry
->abbrev_lookup_ptr
= abbrevptr
;
9851 /* Skip DWARF tag. */
9852 SKIP_ULEB (abbrevptr
, abbrev_table_end
);
9855 dwarf_vma xindex
, form
;
9857 READ_ULEB (xindex
, abbrevptr
, abbrev_table_end
);
9858 READ_ULEB (form
, abbrevptr
, abbrev_table_end
);
9859 if (xindex
== 0 && form
== 0)
9864 printf (_("\nSymbol table:\n"));
9866 for (namei
= 0; namei
< name_count
; ++namei
)
9868 uint64_t string_offset
, entry_offset
;
9871 p
= name_table_string_offsets
+ namei
* offset_size
;
9872 SAFE_BYTE_GET (string_offset
, p
, offset_size
, unit_end
);
9873 p
= name_table_entry_offsets
+ namei
* offset_size
;
9874 SAFE_BYTE_GET (entry_offset
, p
, offset_size
, unit_end
);
9876 printf ("[%3u] #%08x %s:", namei
, hash_table_hashes
[namei
],
9877 fetch_indirect_string (string_offset
));
9879 unsigned char *entryptr
= entry_pool
+ entry_offset
;
9881 /* We need to scan first whether there is a single or multiple
9882 entries. TAGNO is -2 for the first entry, it is -1 for the
9883 initial tag read of the second entry, then it becomes 0 for the
9884 first entry for real printing etc. */
9886 /* Initialize it due to a false compiler warning. */
9887 dwarf_vma second_abbrev_tag
= -1;
9890 dwarf_vma abbrev_tag
;
9891 dwarf_vma dwarf_tag
;
9892 const struct abbrev_lookup_entry
*entry
;
9894 READ_ULEB (abbrev_tag
, entryptr
, unit_end
);
9897 second_abbrev_tag
= abbrev_tag
;
9899 entryptr
= entry_pool
+ entry_offset
;
9902 if (abbrev_tag
== 0)
9906 (tagno
== 0 && second_abbrev_tag
== 0 ? " " : "\n\t"),
9907 (unsigned long) abbrev_tag
);
9909 for (entry
= abbrev_lookup
;
9910 entry
< abbrev_lookup
+ abbrev_lookup_used
;
9912 if (entry
->abbrev_tag
== abbrev_tag
)
9914 if (entry
>= abbrev_lookup
+ abbrev_lookup_used
)
9916 warn (_("Undefined abbreviation tag %lu "
9917 "in unit 0x%lx in the debug_names\n"),
9919 (long) (unit_start
- section
->start
));
9922 abbrevptr
= entry
->abbrev_lookup_ptr
;
9923 READ_ULEB (dwarf_tag
, abbrevptr
, abbrev_table_end
);
9925 printf (" %s", get_TAG_name (dwarf_tag
));
9928 dwarf_vma xindex
, form
;
9930 READ_ULEB (xindex
, abbrevptr
, abbrev_table_end
);
9931 READ_ULEB (form
, abbrevptr
, abbrev_table_end
);
9932 if (xindex
== 0 && form
== 0)
9936 printf (" %s", get_IDX_name (xindex
));
9937 entryptr
= read_and_display_attr_value (0, form
, 0,
9938 unit_start
, entryptr
, unit_end
,
9940 dwarf_version
, NULL
,
9947 printf (_(" <no entries>"));
9951 free (abbrev_lookup
);
9958 display_debug_links (struct dwarf_section
* section
,
9959 void * file ATTRIBUTE_UNUSED
)
9961 const unsigned char * filename
;
9962 unsigned int filelen
;
9964 introduce (section
, false);
9966 /* The .gnu_debuglink section is formatted as:
9967 (c-string) Filename.
9968 (padding) If needed to reach a 4 byte boundary.
9969 (uint32_t) CRC32 value.
9971 The .gun_debugaltlink section is formatted as:
9972 (c-string) Filename.
9973 (binary) Build-ID. */
9975 filename
= section
->start
;
9976 filelen
= strnlen ((const char *) filename
, section
->size
);
9977 if (filelen
== section
->size
)
9979 warn (_("The debuglink filename is corrupt/missing\n"));
9983 printf (_(" Separate debug info file: %s\n"), filename
);
9985 if (startswith (section
->name
, ".gnu_debuglink"))
9988 unsigned int crc_offset
;
9990 crc_offset
= filelen
+ 1;
9991 crc_offset
= (crc_offset
+ 3) & ~3;
9992 if (crc_offset
+ 4 > section
->size
)
9994 warn (_("CRC offset missing/truncated\n"));
9998 crc32
= byte_get (filename
+ crc_offset
, 4);
10000 printf (_(" CRC value: %#x\n"), crc32
);
10002 if (crc_offset
+ 4 < section
->size
)
10004 warn (_("There are %#lx extraneous bytes at the end of the section\n"),
10005 (long)(section
->size
- (crc_offset
+ 4)));
10009 else /* startswith (section->name, ".gnu_debugaltlink") */
10011 const unsigned char * build_id
= section
->start
+ filelen
+ 1;
10012 bfd_size_type build_id_len
= section
->size
- (filelen
+ 1);
10013 bfd_size_type printed
;
10015 /* FIXME: Should we support smaller build-id notes ? */
10016 if (build_id_len
< 0x14)
10018 warn (_("Build-ID is too short (%#lx bytes)\n"), (long) build_id_len
);
10022 printed
= printf (_(" Build-ID (%#lx bytes):"), (long) build_id_len
);
10023 display_data (printed
, build_id
, build_id_len
);
10032 display_gdb_index (struct dwarf_section
*section
,
10033 void *file ATTRIBUTE_UNUSED
)
10035 unsigned char *start
= section
->start
;
10037 uint32_t cu_list_offset
, tu_list_offset
;
10038 uint32_t address_table_offset
, symbol_table_offset
, constant_pool_offset
;
10039 unsigned int cu_list_elements
, tu_list_elements
;
10040 unsigned int address_table_size
, symbol_table_slots
;
10041 unsigned char *cu_list
, *tu_list
;
10042 unsigned char *address_table
, *symbol_table
, *constant_pool
;
10045 /* The documentation for the format of this file is in gdb/dwarf2read.c. */
10047 introduce (section
, false);
10049 if (section
->size
< 6 * sizeof (uint32_t))
10051 warn (_("Truncated header in the %s section.\n"), section
->name
);
10055 version
= byte_get_little_endian (start
, 4);
10056 printf (_("Version %ld\n"), (long) version
);
10058 /* Prior versions are obsolete, and future versions may not be
10059 backwards compatible. */
10060 if (version
< 3 || version
> 8)
10062 warn (_("Unsupported version %lu.\n"), (unsigned long) version
);
10066 warn (_("The address table data in version 3 may be wrong.\n"));
10068 warn (_("Version 4 does not support case insensitive lookups.\n"));
10070 warn (_("Version 5 does not include inlined functions.\n"));
10072 warn (_("Version 6 does not include symbol attributes.\n"));
10073 /* Version 7 indices generated by Gold have bad type unit references,
10074 PR binutils/15021. But we don't know if the index was generated by
10075 Gold or not, so to avoid worrying users with gdb-generated indices
10076 we say nothing for version 7 here. */
10078 cu_list_offset
= byte_get_little_endian (start
+ 4, 4);
10079 tu_list_offset
= byte_get_little_endian (start
+ 8, 4);
10080 address_table_offset
= byte_get_little_endian (start
+ 12, 4);
10081 symbol_table_offset
= byte_get_little_endian (start
+ 16, 4);
10082 constant_pool_offset
= byte_get_little_endian (start
+ 20, 4);
10084 if (cu_list_offset
> section
->size
10085 || tu_list_offset
> section
->size
10086 || address_table_offset
> section
->size
10087 || symbol_table_offset
> section
->size
10088 || constant_pool_offset
> section
->size
)
10090 warn (_("Corrupt header in the %s section.\n"), section
->name
);
10094 /* PR 17531: file: 418d0a8a. */
10095 if (tu_list_offset
< cu_list_offset
)
10097 warn (_("TU offset (%x) is less than CU offset (%x)\n"),
10098 tu_list_offset
, cu_list_offset
);
10102 cu_list_elements
= (tu_list_offset
- cu_list_offset
) / 8;
10104 if (address_table_offset
< tu_list_offset
)
10106 warn (_("Address table offset (%x) is less than TU offset (%x)\n"),
10107 address_table_offset
, tu_list_offset
);
10111 tu_list_elements
= (address_table_offset
- tu_list_offset
) / 8;
10113 /* PR 17531: file: 18a47d3d. */
10114 if (symbol_table_offset
< address_table_offset
)
10116 warn (_("Symbol table offset (%x) is less then Address table offset (%x)\n"),
10117 symbol_table_offset
, address_table_offset
);
10121 address_table_size
= symbol_table_offset
- address_table_offset
;
10123 if (constant_pool_offset
< symbol_table_offset
)
10125 warn (_("Constant pool offset (%x) is less than symbol table offset (%x)\n"),
10126 constant_pool_offset
, symbol_table_offset
);
10130 symbol_table_slots
= (constant_pool_offset
- symbol_table_offset
) / 8;
10132 cu_list
= start
+ cu_list_offset
;
10133 tu_list
= start
+ tu_list_offset
;
10134 address_table
= start
+ address_table_offset
;
10135 symbol_table
= start
+ symbol_table_offset
;
10136 constant_pool
= start
+ constant_pool_offset
;
10138 if (address_table_offset
+ address_table_size
> section
->size
)
10140 warn (_("Address table extends beyond end of section.\n"));
10144 printf (_("\nCU table:\n"));
10145 for (i
= 0; i
< cu_list_elements
; i
+= 2)
10147 uint64_t cu_offset
= byte_get_little_endian (cu_list
+ i
* 8, 8);
10148 uint64_t cu_length
= byte_get_little_endian (cu_list
+ i
* 8 + 8, 8);
10150 printf (_("[%3u] 0x%lx - 0x%lx\n"), i
/ 2,
10151 (unsigned long) cu_offset
,
10152 (unsigned long) (cu_offset
+ cu_length
- 1));
10155 printf (_("\nTU table:\n"));
10156 for (i
= 0; i
< tu_list_elements
; i
+= 3)
10158 uint64_t tu_offset
= byte_get_little_endian (tu_list
+ i
* 8, 8);
10159 uint64_t type_offset
= byte_get_little_endian (tu_list
+ i
* 8 + 8, 8);
10160 uint64_t signature
= byte_get_little_endian (tu_list
+ i
* 8 + 16, 8);
10162 printf (_("[%3u] 0x%lx 0x%lx "), i
/ 3,
10163 (unsigned long) tu_offset
,
10164 (unsigned long) type_offset
);
10165 print_dwarf_vma (signature
, 8);
10169 printf (_("\nAddress table:\n"));
10170 for (i
= 0; i
< address_table_size
&& i
<= address_table_size
- (2 * 8 + 4);
10173 uint64_t low
= byte_get_little_endian (address_table
+ i
, 8);
10174 uint64_t high
= byte_get_little_endian (address_table
+ i
+ 8, 8);
10175 uint32_t cu_index
= byte_get_little_endian (address_table
+ i
+ 16, 4);
10177 print_dwarf_vma (low
, 8);
10178 print_dwarf_vma (high
, 8);
10179 printf (_("%lu\n"), (unsigned long) cu_index
);
10182 printf (_("\nSymbol table:\n"));
10183 for (i
= 0; i
< symbol_table_slots
; ++i
)
10185 uint32_t name_offset
= byte_get_little_endian (symbol_table
+ i
* 8, 4);
10186 uint32_t cu_vector_offset
= byte_get_little_endian (symbol_table
+ i
* 8 + 4, 4);
10187 uint32_t num_cus
, cu
;
10189 if (name_offset
!= 0
10190 || cu_vector_offset
!= 0)
10194 /* PR 17531: file: 5b7b07ad. */
10195 if (name_offset
>= section
->size
- constant_pool_offset
)
10197 printf (_("[%3u] <corrupt offset: %x>"), i
, name_offset
);
10198 warn (_("Corrupt name offset of 0x%x found for symbol table slot %d\n"),
10202 printf ("[%3u] %.*s:", i
,
10203 (int) (section
->size
- (constant_pool_offset
+ name_offset
)),
10204 constant_pool
+ name_offset
);
10206 if (section
->size
- constant_pool_offset
< 4
10207 || cu_vector_offset
> section
->size
- constant_pool_offset
- 4)
10209 printf (_("<invalid CU vector offset: %x>\n"), cu_vector_offset
);
10210 warn (_("Corrupt CU vector offset of 0x%x found for symbol table slot %d\n"),
10211 cu_vector_offset
, i
);
10215 num_cus
= byte_get_little_endian (constant_pool
+ cu_vector_offset
, 4);
10217 if ((uint64_t) num_cus
* 4 > section
->size
- (constant_pool_offset
10218 + cu_vector_offset
+ 4))
10220 printf ("<invalid number of CUs: %d>\n", num_cus
);
10221 warn (_("Invalid number of CUs (0x%x) for symbol table slot %d\n"),
10229 for (j
= 0; j
< num_cus
; ++j
)
10232 gdb_index_symbol_kind kind
;
10234 cu
= byte_get_little_endian (constant_pool
+ cu_vector_offset
+ 4 + j
* 4, 4);
10235 is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu
);
10236 kind
= GDB_INDEX_SYMBOL_KIND_VALUE (cu
);
10237 cu
= GDB_INDEX_CU_VALUE (cu
);
10238 /* Convert to TU number if it's for a type unit. */
10239 if (cu
>= cu_list_elements
/ 2)
10240 printf ("%cT%lu", num_cus
> 1 ? '\t' : ' ',
10241 (unsigned long) (cu
- cu_list_elements
/ 2));
10243 printf ("%c%lu", num_cus
> 1 ? '\t' : ' ', (unsigned long) cu
);
10245 printf (" [%s, %s]",
10246 is_static
? _("static") : _("global"),
10247 get_gdb_index_symbol_kind_name (kind
));
10259 /* Pre-allocate enough space for the CU/TU sets needed. */
10262 prealloc_cu_tu_list (unsigned int nshndx
)
10264 if (shndx_pool
== NULL
)
10266 shndx_pool_size
= nshndx
;
10267 shndx_pool_used
= 0;
10268 shndx_pool
= (unsigned int *) xcmalloc (shndx_pool_size
,
10269 sizeof (unsigned int));
10273 shndx_pool_size
= shndx_pool_used
+ nshndx
;
10274 shndx_pool
= (unsigned int *) xcrealloc (shndx_pool
, shndx_pool_size
,
10275 sizeof (unsigned int));
10280 add_shndx_to_cu_tu_entry (unsigned int shndx
)
10282 if (shndx_pool_used
>= shndx_pool_size
)
10284 error (_("Internal error: out of space in the shndx pool.\n"));
10287 shndx_pool
[shndx_pool_used
++] = shndx
;
10291 end_cu_tu_entry (void)
10293 if (shndx_pool_used
>= shndx_pool_size
)
10295 error (_("Internal error: out of space in the shndx pool.\n"));
10298 shndx_pool
[shndx_pool_used
++] = 0;
10301 /* Return the short name of a DWARF section given by a DW_SECT enumerator. */
10303 static const char *
10304 get_DW_SECT_short_name (unsigned int dw_sect
)
10306 static char buf
[16];
10312 case DW_SECT_TYPES
:
10314 case DW_SECT_ABBREV
:
10320 case DW_SECT_STR_OFFSETS
:
10322 case DW_SECT_MACINFO
:
10324 case DW_SECT_MACRO
:
10330 snprintf (buf
, sizeof (buf
), "%d", dw_sect
);
10334 /* Process a CU or TU index. If DO_DISPLAY is true, print the contents.
10335 These sections are extensions for Fission.
10336 See http://gcc.gnu.org/wiki/DebugFissionDWP. */
10339 process_cu_tu_index (struct dwarf_section
*section
, int do_display
)
10341 unsigned char *phdr
= section
->start
;
10342 unsigned char *limit
= phdr
+ section
->size
;
10343 unsigned char *phash
;
10344 unsigned char *pindex
;
10345 unsigned char *ppool
;
10346 unsigned int version
;
10347 unsigned int ncols
= 0;
10348 unsigned int nused
;
10349 unsigned int nslots
;
10352 dwarf_vma signature
;
10355 /* PR 17512: file: 002-168123-0.004. */
10358 warn (_("Section %s is empty\n"), section
->name
);
10361 /* PR 17512: file: 002-376-0.004. */
10362 if (section
->size
< 24)
10364 warn (_("Section %s is too small to contain a CU/TU header\n"),
10370 SAFE_BYTE_GET_AND_INC (version
, phash
, 4, limit
);
10372 SAFE_BYTE_GET_AND_INC (ncols
, phash
, 4, limit
);
10373 SAFE_BYTE_GET_AND_INC (nused
, phash
, 4, limit
);
10374 SAFE_BYTE_GET_AND_INC (nslots
, phash
, 4, limit
);
10376 pindex
= phash
+ (size_t) nslots
* 8;
10377 ppool
= pindex
+ (size_t) nslots
* 4;
10381 introduce (section
, false);
10383 printf (_(" Version: %u\n"), version
);
10385 printf (_(" Number of columns: %u\n"), ncols
);
10386 printf (_(" Number of used entries: %u\n"), nused
);
10387 printf (_(" Number of slots: %u\n\n"), nslots
);
10390 /* PR 17531: file: 45d69832. */
10391 if (_mul_overflow ((size_t) nslots
, 12, &total
)
10392 || total
> (size_t) (limit
- phash
))
10394 warn (ngettext ("Section %s is too small for %u slot\n",
10395 "Section %s is too small for %u slots\n",
10397 section
->name
, nslots
);
10404 prealloc_cu_tu_list ((limit
- ppool
) / 4);
10405 for (i
= 0; i
< nslots
; i
++)
10407 unsigned char *shndx_list
;
10408 unsigned int shndx
;
10410 SAFE_BYTE_GET (signature
, phash
, 8, limit
);
10411 if (signature
!= 0)
10413 SAFE_BYTE_GET (j
, pindex
, 4, limit
);
10414 shndx_list
= ppool
+ j
* 4;
10415 /* PR 17531: file: 705e010d. */
10416 if (shndx_list
< ppool
)
10418 warn (_("Section index pool located before start of section\n"));
10423 printf (_(" [%3d] Signature: 0x%s Sections: "),
10424 i
, dwarf_vmatoa ("x", signature
));
10427 if (shndx_list
>= limit
)
10429 warn (_("Section %s too small for shndx pool\n"),
10433 SAFE_BYTE_GET (shndx
, shndx_list
, 4, limit
);
10437 printf (" %d", shndx
);
10439 add_shndx_to_cu_tu_entry (shndx
);
10445 end_cu_tu_entry ();
10451 else if (version
== 2)
10454 unsigned int dw_sect
;
10455 unsigned char *ph
= phash
;
10456 unsigned char *pi
= pindex
;
10457 unsigned char *poffsets
= ppool
+ (size_t) ncols
* 4;
10458 unsigned char *psizes
= poffsets
+ (size_t) nused
* ncols
* 4;
10460 struct cu_tu_set
*this_set
= NULL
;
10462 unsigned char *prow
;
10465 is_tu_index
= strcmp (section
->name
, ".debug_tu_index") == 0;
10467 /* PR 17531: file: 0dd159bf.
10468 Check for integer overflow (can occur when size_t is 32-bit)
10469 with overlarge ncols or nused values. */
10471 || _mul_overflow ((size_t) ncols
, 4, &temp
)
10472 || _mul_overflow ((size_t) nused
+ 1, temp
, &total
)
10473 || total
> (size_t) (limit
- ppool
))
10475 warn (_("Section %s too small for offset and size tables\n"),
10482 printf (_(" Offset table\n"));
10483 printf (" slot %-16s ",
10484 is_tu_index
? _("signature") : _("dwo_id"));
10491 tu_sets
= xcalloc2 (nused
, sizeof (struct cu_tu_set
));
10492 this_set
= tu_sets
;
10497 cu_sets
= xcalloc2 (nused
, sizeof (struct cu_tu_set
));
10498 this_set
= cu_sets
;
10504 for (j
= 0; j
< ncols
; j
++)
10506 unsigned char *p
= ppool
+ j
* 4;
10507 SAFE_BYTE_GET (dw_sect
, p
, 4, limit
);
10508 printf (" %8s", get_DW_SECT_short_name (dw_sect
));
10513 for (i
= 0; i
< nslots
; i
++)
10515 SAFE_BYTE_GET (signature
, ph
, 8, limit
);
10517 SAFE_BYTE_GET (row
, pi
, 4, limit
);
10520 /* PR 17531: file: a05f6ab3. */
10523 warn (_("Row index (%u) is larger than number of used entries (%u)\n"),
10530 size_t num_copy
= sizeof (uint64_t);
10532 memcpy (&this_set
[row
- 1].signature
, ph
, num_copy
);
10535 prow
= poffsets
+ (row
- 1) * ncols
* 4;
10537 printf (_(" [%3d] 0x%s"),
10538 i
, dwarf_vmatoa ("x", signature
));
10539 for (j
= 0; j
< ncols
; j
++)
10541 unsigned char *p
= prow
+ j
* 4;
10542 SAFE_BYTE_GET (val
, p
, 4, limit
);
10544 printf (" %8d", val
);
10548 SAFE_BYTE_GET (dw_sect
, p
, 4, limit
);
10550 /* PR 17531: file: 10796eb3. */
10551 if (dw_sect
>= DW_SECT_MAX
)
10552 warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect
);
10554 this_set
[row
- 1].section_offsets
[dw_sect
] = val
;
10570 printf (_(" Size table\n"));
10571 printf (" slot %-16s ",
10572 is_tu_index
? _("signature") : _("dwo_id"));
10575 for (j
= 0; j
< ncols
; j
++)
10577 unsigned char *p
= ppool
+ j
* 4;
10578 SAFE_BYTE_GET (val
, p
, 4, limit
);
10580 printf (" %8s", get_DW_SECT_short_name (val
));
10586 for (i
= 0; i
< nslots
; i
++)
10588 SAFE_BYTE_GET (signature
, ph
, 8, limit
);
10590 SAFE_BYTE_GET (row
, pi
, 4, limit
);
10593 prow
= psizes
+ (row
- 1) * ncols
* 4;
10596 printf (_(" [%3d] 0x%s"),
10597 i
, dwarf_vmatoa ("x", signature
));
10599 for (j
= 0; j
< ncols
; j
++)
10601 unsigned char *p
= prow
+ j
* 4;
10603 /* PR 28645: Check for overflow. Since we do not know how
10604 many populated rows there will be, we cannot just
10605 perform a single check at the start of this function. */
10606 if (p
> (limit
- 4))
10610 warn (_("Too many rows/columns in DWARF index section %s\n"),
10615 SAFE_BYTE_GET (val
, p
, 4, limit
);
10618 printf (" %8d", val
);
10622 SAFE_BYTE_GET (dw_sect
, p
, 4, limit
);
10623 if (dw_sect
>= DW_SECT_MAX
)
10624 warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect
);
10626 this_set
[row
- 1].section_sizes
[dw_sect
] = val
;
10638 else if (do_display
)
10639 printf (_(" Unsupported version (%d)\n"), version
);
10647 static int cu_tu_indexes_read
= -1; /* Tri-state variable. */
10649 /* Load the CU and TU indexes if present. This will build a list of
10650 section sets that we can use to associate a .debug_info.dwo section
10651 with its associated .debug_abbrev.dwo section in a .dwp file. */
10654 load_cu_tu_indexes (void *file
)
10656 /* If we have already loaded (or tried to load) the CU and TU indexes
10657 then do not bother to repeat the task. */
10658 if (cu_tu_indexes_read
== -1)
10660 cu_tu_indexes_read
= true;
10662 if (load_debug_section_with_follow (dwp_cu_index
, file
))
10663 if (! process_cu_tu_index (&debug_displays
[dwp_cu_index
].section
, 0))
10664 cu_tu_indexes_read
= false;
10666 if (load_debug_section_with_follow (dwp_tu_index
, file
))
10667 if (! process_cu_tu_index (&debug_displays
[dwp_tu_index
].section
, 0))
10668 cu_tu_indexes_read
= false;
10671 return (bool) cu_tu_indexes_read
;
10674 /* Find the set of sections that includes section SHNDX. */
10677 find_cu_tu_set (void *file
, unsigned int shndx
)
10681 if (! load_cu_tu_indexes (file
))
10684 /* Find SHNDX in the shndx pool. */
10685 for (i
= 0; i
< shndx_pool_used
; i
++)
10686 if (shndx_pool
[i
] == shndx
)
10689 if (i
>= shndx_pool_used
)
10692 /* Now backup to find the first entry in the set. */
10693 while (i
> 0 && shndx_pool
[i
- 1] != 0)
10696 return shndx_pool
+ i
;
10699 /* Display a .debug_cu_index or .debug_tu_index section. */
10702 display_cu_index (struct dwarf_section
*section
, void *file ATTRIBUTE_UNUSED
)
10704 return process_cu_tu_index (section
, 1);
10708 display_debug_not_supported (struct dwarf_section
*section
,
10709 void *file ATTRIBUTE_UNUSED
)
10711 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
10717 /* Like malloc, but takes two parameters like calloc.
10718 Verifies that the first parameter is not too large.
10719 Note: does *not* initialise the allocated memory to zero. */
10722 cmalloc (size_t nmemb
, size_t size
)
10724 /* Check for overflow. */
10725 if (nmemb
>= ~(size_t) 0 / size
)
10728 return xmalloc (nmemb
* size
);
10731 /* Like xmalloc, but takes two parameters like calloc.
10732 Verifies that the first parameter is not too large.
10733 Note: does *not* initialise the allocated memory to zero. */
10736 xcmalloc (size_t nmemb
, size_t size
)
10738 /* Check for overflow. */
10739 if (nmemb
>= ~(size_t) 0 / size
)
10742 _("Attempt to allocate an array with an excessive number of elements: 0x%lx\n"),
10747 return xmalloc (nmemb
* size
);
10750 /* Like xrealloc, but takes three parameters.
10751 Verifies that the second parameter is not too large.
10752 Note: does *not* initialise any new memory to zero. */
10755 xcrealloc (void *ptr
, size_t nmemb
, size_t size
)
10757 /* Check for overflow. */
10758 if (nmemb
>= ~(size_t) 0 / size
)
10760 error (_("Attempt to re-allocate an array with an excessive number of elements: 0x%lx\n"),
10765 return xrealloc (ptr
, nmemb
* size
);
10768 /* Like xcalloc, but verifies that the first parameter is not too large. */
10771 xcalloc2 (size_t nmemb
, size_t size
)
10773 /* Check for overflow. */
10774 if (nmemb
>= ~(size_t) 0 / size
)
10776 error (_("Attempt to allocate a zero'ed array with an excessive number of elements: 0x%lx\n"),
10781 return xcalloc (nmemb
, size
);
10784 static unsigned long
10785 calc_gnu_debuglink_crc32 (unsigned long crc
,
10786 const unsigned char * buf
,
10789 static const unsigned long crc32_table
[256] =
10791 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
10792 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
10793 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
10794 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
10795 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
10796 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
10797 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
10798 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
10799 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
10800 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
10801 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
10802 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
10803 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
10804 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
10805 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
10806 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
10807 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
10808 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
10809 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
10810 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
10811 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
10812 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
10813 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
10814 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
10815 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
10816 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
10817 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
10818 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
10819 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
10820 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
10821 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
10822 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
10823 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
10824 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
10825 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
10826 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
10827 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
10828 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
10829 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
10830 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
10831 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
10832 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
10833 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
10834 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
10835 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
10836 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
10837 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
10838 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
10839 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
10840 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
10841 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
10844 const unsigned char *end
;
10846 crc
= ~crc
& 0xffffffff;
10847 for (end
= buf
+ len
; buf
< end
; ++ buf
)
10848 crc
= crc32_table
[(crc
^ *buf
) & 0xff] ^ (crc
>> 8);
10849 return ~crc
& 0xffffffff;
10852 typedef bool (*check_func_type
) (const char *, void *);
10853 typedef const char *(* parse_func_type
) (struct dwarf_section
*, void *);
10856 check_gnu_debuglink (const char * pathname
, void * crc_pointer
)
10858 static unsigned char buffer
[8 * 1024];
10860 bfd_size_type count
;
10861 unsigned long crc
= 0;
10864 sep_data
= open_debug_file (pathname
);
10865 if (sep_data
== NULL
)
10868 /* Yes - we are opening the file twice... */
10869 f
= fopen (pathname
, "rb");
10872 /* Paranoia: This should never happen. */
10873 close_debug_file (sep_data
);
10874 warn (_("Unable to reopen separate debug info file: %s\n"), pathname
);
10878 while ((count
= fread (buffer
, 1, sizeof (buffer
), f
)) > 0)
10879 crc
= calc_gnu_debuglink_crc32 (crc
, buffer
, count
);
10883 if (crc
!= * (unsigned long *) crc_pointer
)
10885 close_debug_file (sep_data
);
10886 warn (_("Separate debug info file %s found, but CRC does not match - ignoring\n"),
10894 static const char *
10895 parse_gnu_debuglink (struct dwarf_section
* section
, void * data
)
10898 unsigned int crc_offset
;
10899 unsigned long * crc32
= (unsigned long *) data
;
10901 /* The name is first.
10902 The CRC value is stored after the filename, aligned up to 4 bytes. */
10903 name
= (const char *) section
->start
;
10905 crc_offset
= strnlen (name
, section
->size
) + 1;
10906 if (crc_offset
== 1)
10908 crc_offset
= (crc_offset
+ 3) & ~3;
10909 if (crc_offset
+ 4 > section
->size
)
10912 * crc32
= byte_get (section
->start
+ crc_offset
, 4);
10917 check_gnu_debugaltlink (const char * filename
, void * data ATTRIBUTE_UNUSED
)
10919 void * sep_data
= open_debug_file (filename
);
10921 if (sep_data
== NULL
)
10924 /* FIXME: We should now extract the build-id in the separate file
10930 typedef struct build_id_data
10933 const unsigned char * data
;
10936 static const char *
10937 parse_gnu_debugaltlink (struct dwarf_section
* section
, void * data
)
10940 bfd_size_type namelen
;
10941 bfd_size_type id_len
;
10942 Build_id_data
* build_id_data
;
10944 /* The name is first.
10945 The build-id follows immediately, with no padding, up to the section's end. */
10947 name
= (const char *) section
->start
;
10948 namelen
= strnlen (name
, section
->size
) + 1;
10951 if (namelen
>= section
->size
)
10954 id_len
= section
->size
- namelen
;
10958 build_id_data
= (Build_id_data
*) data
;
10959 build_id_data
->len
= id_len
;
10960 build_id_data
->data
= section
->start
+ namelen
;
10966 add_separate_debug_file (const char * filename
, void * handle
)
10968 separate_info
* i
= xmalloc (sizeof * i
);
10970 i
->filename
= filename
;
10971 i
->handle
= handle
;
10972 i
->next
= first_separate_info
;
10973 first_separate_info
= i
;
10976 #if HAVE_LIBDEBUGINFOD
10977 /* Query debuginfod servers for the target debuglink or debugaltlink
10978 file. If successful, store the path of the file in filename and
10979 return TRUE, otherwise return FALSE. */
10982 debuginfod_fetch_separate_debug_info (struct dwarf_section
* section
,
10986 size_t build_id_len
;
10987 unsigned char * build_id
;
10989 if (strcmp (section
->uncompressed_name
, ".gnu_debuglink") == 0)
10991 /* Get the build-id of file. */
10992 build_id
= get_build_id (file
);
10995 else if (strcmp (section
->uncompressed_name
, ".gnu_debugaltlink") == 0)
10997 /* Get the build-id of the debugaltlink file. */
10998 unsigned int filelen
;
11000 filelen
= strnlen ((const char *)section
->start
, section
->size
);
11001 if (filelen
== section
->size
)
11002 /* Corrupt debugaltlink. */
11005 build_id
= section
->start
+ filelen
+ 1;
11006 build_id_len
= section
->size
- (filelen
+ 1);
11008 if (build_id_len
== 0)
11017 debuginfod_client
* client
;
11019 client
= debuginfod_begin ();
11020 if (client
== NULL
)
11023 /* Query debuginfod servers for the target file. If found its path
11024 will be stored in filename. */
11025 fd
= debuginfod_find_debuginfo (client
, build_id
, build_id_len
, filename
);
11026 debuginfod_end (client
);
11028 /* Only free build_id if we allocated space for a hex string
11029 in get_build_id (). */
11030 if (build_id_len
== 0)
11035 /* File successfully retrieved. Close fd since we want to
11036 use open_debug_file () on filename instead. */
11044 #endif /* HAVE_LIBDEBUGINFOD */
11047 load_separate_debug_info (const char * main_filename
,
11048 struct dwarf_section
* xlink
,
11049 parse_func_type parse_func
,
11050 check_func_type check_func
,
11052 void * file ATTRIBUTE_UNUSED
)
11054 const char * separate_filename
;
11055 char * debug_filename
;
11057 size_t canon_dirlen
;
11059 char * canon_filename
;
11060 char * canon_debug_filename
;
11063 if ((separate_filename
= parse_func (xlink
, func_data
)) == NULL
)
11065 warn (_("Corrupt debuglink section: %s\n"),
11066 xlink
->name
? xlink
->name
: xlink
->uncompressed_name
);
11070 /* Attempt to locate the separate file.
11071 This should duplicate the logic in bfd/opncls.c:find_separate_debug_file(). */
11073 canon_filename
= lrealpath (main_filename
);
11074 canon_dir
= xstrdup (canon_filename
);
11076 for (canon_dirlen
= strlen (canon_dir
); canon_dirlen
> 0; canon_dirlen
--)
11077 if (IS_DIR_SEPARATOR (canon_dir
[canon_dirlen
- 1]))
11079 canon_dir
[canon_dirlen
] = '\0';
11082 #define DEBUGDIR "/lib/debug"
11084 #ifndef EXTRA_DEBUG_ROOT1
11085 #define EXTRA_DEBUG_ROOT1 "/usr/lib/debug"
11087 #ifndef EXTRA_DEBUG_ROOT2
11088 #define EXTRA_DEBUG_ROOT2 "/usr/lib/debug/usr"
11091 debug_filename
= (char *) malloc (strlen (DEBUGDIR
) + 1
11093 + strlen (".debug/")
11094 #ifdef EXTRA_DEBUG_ROOT1
11095 + strlen (EXTRA_DEBUG_ROOT1
)
11097 #ifdef EXTRA_DEBUG_ROOT2
11098 + strlen (EXTRA_DEBUG_ROOT2
)
11100 + strlen (separate_filename
)
11102 if (debug_filename
== NULL
)
11104 warn (_("Out of memory"));
11106 free (canon_filename
);
11110 /* First try in the current directory. */
11111 sprintf (debug_filename
, "%s", separate_filename
);
11112 if (check_func (debug_filename
, func_data
))
11115 /* Then try in a subdirectory called .debug. */
11116 sprintf (debug_filename
, ".debug/%s", separate_filename
);
11117 if (check_func (debug_filename
, func_data
))
11120 /* Then try in the same directory as the original file. */
11121 sprintf (debug_filename
, "%s%s", canon_dir
, separate_filename
);
11122 if (check_func (debug_filename
, func_data
))
11125 /* And the .debug subdirectory of that directory. */
11126 sprintf (debug_filename
, "%s.debug/%s", canon_dir
, separate_filename
);
11127 if (check_func (debug_filename
, func_data
))
11130 #ifdef EXTRA_DEBUG_ROOT1
11131 /* Try the first extra debug file root. */
11132 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT1
, separate_filename
);
11133 if (check_func (debug_filename
, func_data
))
11136 /* Try the first extra debug file root. */
11137 sprintf (debug_filename
, "%s/%s/%s", EXTRA_DEBUG_ROOT1
, canon_dir
, separate_filename
);
11138 if (check_func (debug_filename
, func_data
))
11142 #ifdef EXTRA_DEBUG_ROOT2
11143 /* Try the second extra debug file root. */
11144 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT2
, separate_filename
);
11145 if (check_func (debug_filename
, func_data
))
11149 /* Then try in the global debug_filename directory. */
11150 strcpy (debug_filename
, DEBUGDIR
);
11151 dirlen
= strlen (DEBUGDIR
) - 1;
11152 if (dirlen
> 0 && DEBUGDIR
[dirlen
] != '/')
11153 strcat (debug_filename
, "/");
11154 strcat (debug_filename
, (const char *) separate_filename
);
11156 if (check_func (debug_filename
, func_data
))
11159 #if HAVE_LIBDEBUGINFOD
11161 char * tmp_filename
;
11164 && debuginfod_fetch_separate_debug_info (xlink
,
11168 /* File successfully downloaded from server, replace
11169 debug_filename with the file's path. */
11170 free (debug_filename
);
11171 debug_filename
= tmp_filename
;
11177 if (do_debug_links
)
11179 /* Failed to find the file. */
11180 warn (_("could not find separate debug file '%s'\n"),
11181 separate_filename
);
11182 warn (_("tried: %s\n"), debug_filename
);
11184 #ifdef EXTRA_DEBUG_ROOT2
11185 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT2
,
11186 separate_filename
);
11187 warn (_("tried: %s\n"), debug_filename
);
11190 #ifdef EXTRA_DEBUG_ROOT1
11191 sprintf (debug_filename
, "%s/%s/%s", EXTRA_DEBUG_ROOT1
,
11192 canon_dir
, separate_filename
);
11193 warn (_("tried: %s\n"), debug_filename
);
11195 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT1
,
11196 separate_filename
);
11197 warn (_("tried: %s\n"), debug_filename
);
11200 sprintf (debug_filename
, "%s.debug/%s", canon_dir
,
11201 separate_filename
);
11202 warn (_("tried: %s\n"), debug_filename
);
11204 sprintf (debug_filename
, "%s%s", canon_dir
, separate_filename
);
11205 warn (_("tried: %s\n"), debug_filename
);
11207 sprintf (debug_filename
, ".debug/%s", separate_filename
);
11208 warn (_("tried: %s\n"), debug_filename
);
11210 sprintf (debug_filename
, "%s", separate_filename
);
11211 warn (_("tried: %s\n"), debug_filename
);
11213 #if HAVE_LIBDEBUGINFOD
11214 if (use_debuginfod
)
11216 char *urls
= getenv (DEBUGINFOD_URLS_ENV_VAR
);
11221 warn (_("tried: DEBUGINFOD_URLS=%s\n"), urls
);
11227 free (debug_filename
);
11228 free (canon_filename
);
11234 canon_debug_filename
= lrealpath (debug_filename
);
11235 self
= strcmp (canon_debug_filename
, canon_filename
) == 0;
11236 free (canon_filename
);
11237 free (canon_debug_filename
);
11240 free (debug_filename
);
11244 void * debug_handle
;
11246 /* Now open the file.... */
11247 if ((debug_handle
= open_debug_file (debug_filename
)) == NULL
)
11249 warn (_("failed to open separate debug file: %s\n"), debug_filename
);
11250 free (debug_filename
);
11254 /* FIXME: We do not check to see if there are any other separate debug info
11255 files that would also match. */
11257 if (do_debug_links
)
11258 printf (_("\n%s: Found separate debug info file: %s\n"), main_filename
, debug_filename
);
11259 add_separate_debug_file (debug_filename
, debug_handle
);
11261 /* Do not free debug_filename - it might be referenced inside
11262 the structure returned by open_debug_file(). */
11263 return debug_handle
;
11266 /* Attempt to load a separate dwarf object file. */
11269 load_dwo_file (const char * main_filename
, const char * name
, const char * dir
, const char * id ATTRIBUTE_UNUSED
)
11271 char * separate_filename
;
11272 void * separate_handle
;
11274 if (IS_ABSOLUTE_PATH (name
))
11275 separate_filename
= strdup (name
);
11277 /* FIXME: Skip adding / if dwo_dir ends in /. */
11278 separate_filename
= concat (dir
, "/", name
, NULL
);
11279 if (separate_filename
== NULL
)
11281 warn (_("Out of memory allocating dwo filename\n"));
11285 if ((separate_handle
= open_debug_file (separate_filename
)) == NULL
)
11287 warn (_("Unable to load dwo file: %s\n"), separate_filename
);
11288 free (separate_filename
);
11292 /* FIXME: We should check the dwo_id. */
11294 printf (_("%s: Found separate debug object file: %s\n\n"), main_filename
, separate_filename
);
11296 add_separate_debug_file (separate_filename
, separate_handle
);
11297 /* Note - separate_filename will be freed in free_debug_memory(). */
11298 return separate_handle
;
11302 try_build_id_prefix (const char * prefix
, char * filename
, const unsigned char * data
, unsigned long id_len
)
11304 char * f
= filename
;
11306 f
+= sprintf (f
, "%s.build-id/%02x/", prefix
, (unsigned) *data
++);
11309 f
+= sprintf (f
, "%02x", (unsigned) *data
++);
11310 strcpy (f
, ".debug");
11312 return open_debug_file (filename
);
11315 /* Try to load a debug file based upon the build-id held in the .note.gnu.build-id section. */
11318 load_build_id_debug_file (const char * main_filename ATTRIBUTE_UNUSED
, void * main_file
)
11320 if (! load_debug_section (note_gnu_build_id
, main_file
))
11321 return; /* No .note.gnu.build-id section. */
11323 struct dwarf_section
* section
= & debug_displays
[note_gnu_build_id
].section
;
11324 if (section
== NULL
)
11326 warn (_("Unable to load the .note.gnu.build-id section\n"));
11330 if (section
->start
== NULL
|| section
->size
< 0x18)
11332 warn (_(".note.gnu.build-id section is corrupt/empty\n"));
11336 /* In theory we should extract the contents of the section into
11337 a note structure and then check the fields. For now though
11338 just use hard coded offsets instead:
11340 Field Bytes Contents
11343 Type 8..11 3 (NT_GNU_BUILD_ID)
11347 /* FIXME: Check the name size, name and type fields. */
11349 unsigned long build_id_size
;
11350 build_id_size
= byte_get (section
->start
+ 4, 4);
11351 if (build_id_size
< 8)
11353 warn (_(".note.gnu.build-id data size is too small\n"));
11357 if (build_id_size
> (section
->size
- 16))
11359 warn (_(".note.gnu.build-id data size is too bug\n"));
11364 filename
= xmalloc (strlen (".build-id/")
11365 + build_id_size
* 2 + 2
11366 + strlen (".debug")
11367 /* The next string should be the same as the longest
11368 name found in the prefixes[] array below. */
11369 + strlen ("/usrlib64/debug/usr")
11373 static const char * prefixes
[] =
11378 "/usr/lib/debug/usr/",
11379 "/usr/lib64/debug/",
11380 "/usr/lib64/debug/usr"
11382 long unsigned int i
;
11384 for (i
= 0; i
< ARRAY_SIZE (prefixes
); i
++)
11386 handle
= try_build_id_prefix (prefixes
[i
], filename
,
11387 section
->start
+ 16, build_id_size
);
11388 if (handle
!= NULL
)
11391 /* FIXME: TYhe BFD library also tries a global debugfile directory prefix. */
11392 if (handle
== NULL
)
11394 /* Failed to find a debug file associated with the build-id.
11395 This is not an error however, rather it just means that
11396 the debug info has probably not been loaded on the system,
11397 or that another method is being used to link to the debug
11403 add_separate_debug_file (filename
, handle
);
11406 /* Try to load a debug file pointed to by the .debug_sup section. */
11409 load_debug_sup_file (const char * main_filename
, void * file
)
11411 if (! load_debug_section (debug_sup
, file
))
11412 return; /* No .debug_sup section. */
11414 struct dwarf_section
* section
;
11415 section
= & debug_displays
[debug_sup
].section
;
11416 assert (section
!= NULL
);
11418 if (section
->start
== NULL
|| section
->size
< 5)
11420 warn (_(".debug_sup section is corrupt/empty\n"));
11424 if (section
->start
[2] != 0)
11425 return; /* This is a supplementary file. */
11427 const char * filename
= (const char *) section
->start
+ 3;
11428 if (strnlen (filename
, section
->size
- 3) == section
->size
- 3)
11430 warn (_("filename in .debug_sup section is corrupt\n"));
11434 if (filename
[0] != '/' && strchr (main_filename
, '/'))
11439 new_len
= asprintf (& new_name
, "%.*s/%s",
11440 (int) (strrchr (main_filename
, '/') - main_filename
),
11445 warn (_("unable to construct path for supplementary debug file"));
11450 filename
= new_name
;
11454 /* PR 27796: Make sure that we pass a filename that can be free'd to
11455 add_separate_debug_file(). */
11456 filename
= strdup (filename
);
11457 if (filename
== NULL
)
11459 warn (_("out of memory constructing filename for .debug_sup link\n"));
11464 void * handle
= open_debug_file (filename
);
11465 if (handle
== NULL
)
11467 warn (_("unable to open file '%s' referenced from .debug_sup section\n"), filename
);
11468 free ((void *) filename
);
11472 printf (_("%s: Found supplementary debug file: %s\n\n"), main_filename
, filename
);
11474 /* FIXME: Compare the checksums, if present. */
11475 add_separate_debug_file (filename
, handle
);
11478 /* Load a debuglink section and/or a debugaltlink section, if either are present.
11479 Recursively check the loaded files for more of these sections.
11480 Also follow any links in .debug_sup sections.
11481 FIXME: Should also check for DWO_* entries in the newly loaded files. */
11484 check_for_and_load_links (void * file
, const char * filename
)
11486 void * handle
= NULL
;
11488 if (load_debug_section (gnu_debugaltlink
, file
))
11490 Build_id_data build_id_data
;
11492 handle
= load_separate_debug_info (filename
,
11493 & debug_displays
[gnu_debugaltlink
].section
,
11494 parse_gnu_debugaltlink
,
11495 check_gnu_debugaltlink
,
11500 assert (handle
== first_separate_info
->handle
);
11501 check_for_and_load_links (first_separate_info
->handle
,
11502 first_separate_info
->filename
);
11506 if (load_debug_section (gnu_debuglink
, file
))
11508 unsigned long crc32
;
11510 handle
= load_separate_debug_info (filename
,
11511 & debug_displays
[gnu_debuglink
].section
,
11512 parse_gnu_debuglink
,
11513 check_gnu_debuglink
,
11518 assert (handle
== first_separate_info
->handle
);
11519 check_for_and_load_links (first_separate_info
->handle
,
11520 first_separate_info
->filename
);
11524 load_debug_sup_file (filename
, file
);
11526 load_build_id_debug_file (filename
, file
);
11529 /* Load the separate debug info file(s) attached to FILE, if any exist.
11530 Returns TRUE if any were found, FALSE otherwise.
11531 If TRUE is returned then the linked list starting at first_separate_info
11532 will be populated with open file handles. */
11535 load_separate_debug_files (void * file
, const char * filename
)
11537 /* Skip this operation if we are not interested in debug links. */
11538 if (! do_follow_links
&& ! do_debug_links
)
11541 /* See if there are any dwo links. */
11542 if (load_debug_section (str
, file
)
11543 && load_debug_section (abbrev
, file
)
11544 && load_debug_section (info
, file
))
11548 if (process_debug_info (& debug_displays
[info
].section
, file
, abbrev
,
11551 bool introduced
= false;
11553 const char *dir
= NULL
;
11554 const char *id
= NULL
;
11555 const char *name
= NULL
;
11557 for (dwinfo
= first_dwo_info
; dwinfo
!= NULL
; dwinfo
= dwinfo
->next
)
11559 /* Accumulate NAME, DIR and ID fields. */
11560 switch (dwinfo
->type
)
11564 warn (_("Multiple DWO_NAMEs encountered for the same CU\n"));
11565 name
= dwinfo
->value
;
11569 /* There can be multiple DW_AT_comp_dir entries in a CU,
11570 so do not complain. */
11571 dir
= dwinfo
->value
;
11576 warn (_("multiple DWO_IDs encountered for the same CU\n"));
11577 id
= dwinfo
->value
;
11581 error (_("Unexpected DWO INFO type"));
11585 /* If we have reached the end of our list, or we are changing
11586 CUs, then display the information that we have accumulated
11589 && (dwinfo
->next
== NULL
11590 || dwinfo
->next
->cu_offset
!= dwinfo
->cu_offset
))
11592 if (do_debug_links
)
11596 printf (_("The %s section contains link(s) to dwo file(s):\n\n"),
11597 debug_displays
[info
].section
.uncompressed_name
);
11601 printf (_(" Name: %s\n"), name
);
11602 printf (_(" Directory: %s\n"), dir
? dir
: _("<not-found>"));
11604 display_data (printf (_(" ID: ")), (unsigned char *) id
, 8);
11606 printf (_(" ID: <not specified>\n"));
11610 if (do_follow_links
)
11611 load_dwo_file (filename
, name
, dir
, id
);
11613 name
= dir
= id
= NULL
;
11619 if (! do_follow_links
)
11620 /* The other debug links will be displayed by display_debug_links()
11621 so we do not need to do any further processing here. */
11624 /* FIXME: We do not check for the presence of both link sections in the same file. */
11625 /* FIXME: We do not check for the presence of multiple, same-name debuglink sections. */
11626 /* FIXME: We do not check for the presence of a dwo link as well as a debuglink. */
11628 check_for_and_load_links (file
, filename
);
11629 if (first_separate_info
!= NULL
)
11632 do_follow_links
= 0;
11637 free_debug_memory (void)
11641 free_all_abbrevs ();
11643 free (cu_abbrev_map
);
11644 cu_abbrev_map
= NULL
;
11645 next_free_abbrev_map_entry
= 0;
11649 shndx_pool_size
= 0;
11650 shndx_pool_used
= 0;
11658 memset (level_type_signed
, 0, sizeof level_type_signed
);
11659 cu_tu_indexes_read
= -1;
11661 for (i
= 0; i
< max
; i
++)
11662 free_debug_section ((enum dwarf_section_display_enum
) i
);
11664 if (debug_information
!= NULL
)
11666 for (i
= 0; i
< alloc_num_debug_info_entries
; i
++)
11668 if (debug_information
[i
].max_loc_offsets
)
11670 free (debug_information
[i
].loc_offsets
);
11671 free (debug_information
[i
].have_frame_base
);
11673 if (debug_information
[i
].max_range_lists
)
11674 free (debug_information
[i
].range_lists
);
11676 free (debug_information
);
11677 debug_information
= NULL
;
11678 alloc_num_debug_info_entries
= num_debug_info_entries
= 0;
11682 separate_info
* next
;
11684 for (d
= first_separate_info
; d
!= NULL
; d
= next
)
11686 close_debug_file (d
->handle
);
11687 free ((void *) d
->filename
);
11691 first_separate_info
= NULL
;
11697 dwarf_select_sections_by_names (const char *names
)
11701 const char * option
;
11705 debug_dump_long_opts
;
11707 static const debug_dump_long_opts opts_table
[] =
11709 /* Please keep this table alpha- sorted. */
11710 { "Ranges", & do_debug_ranges
, 1 },
11711 { "abbrev", & do_debug_abbrevs
, 1 },
11712 { "addr", & do_debug_addr
, 1 },
11713 { "aranges", & do_debug_aranges
, 1 },
11714 { "cu_index", & do_debug_cu_index
, 1 },
11715 { "decodedline", & do_debug_lines
, FLAG_DEBUG_LINES_DECODED
},
11716 #ifdef HAVE_LIBDEBUGINFOD
11717 { "do-not-use-debuginfod", & use_debuginfod
, 0 },
11719 { "follow-links", & do_follow_links
, 1 },
11720 { "frames", & do_debug_frames
, 1 },
11721 { "frames-interp", & do_debug_frames_interp
, 1 },
11722 /* The special .gdb_index section. */
11723 { "gdb_index", & do_gdb_index
, 1 },
11724 { "info", & do_debug_info
, 1 },
11725 { "line", & do_debug_lines
, FLAG_DEBUG_LINES_RAW
}, /* For backwards compatibility. */
11726 { "links", & do_debug_links
, 1 },
11727 { "loc", & do_debug_loc
, 1 },
11728 { "macro", & do_debug_macinfo
, 1 },
11729 { "no-follow-links", & do_follow_links
, 0 },
11730 { "pubnames", & do_debug_pubnames
, 1 },
11731 { "pubtypes", & do_debug_pubtypes
, 1 },
11732 /* This entry is for compatibility
11733 with earlier versions of readelf. */
11734 { "ranges", & do_debug_aranges
, 1 },
11735 { "rawline", & do_debug_lines
, FLAG_DEBUG_LINES_RAW
},
11736 { "str", & do_debug_str
, 1 },
11737 { "str-offsets", & do_debug_str_offsets
, 1 },
11738 /* These trace_* sections are used by Itanium VMS. */
11739 { "trace_abbrev", & do_trace_abbrevs
, 1 },
11740 { "trace_aranges", & do_trace_aranges
, 1 },
11741 { "trace_info", & do_trace_info
, 1 },
11742 #ifdef HAVE_LIBDEBUGINFOD
11743 { "use-debuginfod", & use_debuginfod
, 1 },
11753 const debug_dump_long_opts
* entry
;
11755 for (entry
= opts_table
; entry
->option
; entry
++)
11757 size_t len
= strlen (entry
->option
);
11759 if (strncmp (p
, entry
->option
, len
) == 0
11760 && (p
[len
] == ',' || p
[len
] == '\0'))
11762 * entry
->variable
= entry
->val
;
11764 /* The --debug-dump=frames-interp option also
11765 enables the --debug-dump=frames option. */
11766 if (do_debug_frames_interp
)
11767 do_debug_frames
= 1;
11774 if (entry
->option
== NULL
)
11776 warn (_("Unrecognized debug option '%s'\n"), p
);
11777 p
= strchr (p
, ',');
11788 dwarf_select_sections_by_letters (const char *letters
)
11790 unsigned int lindex
= 0;
11792 while (letters
[lindex
])
11793 switch (letters
[lindex
++])
11795 case 'A': do_debug_addr
= 1; break;
11796 case 'a': do_debug_abbrevs
= 1; break;
11797 case 'c': do_debug_cu_index
= 1; break;
11798 #ifdef HAVE_LIBDEBUGINFOD
11799 case 'D': use_debuginfod
= 1; break;
11800 case 'E': use_debuginfod
= 0; break;
11802 case 'F': do_debug_frames_interp
= 1; /* Fall through. */
11803 case 'f': do_debug_frames
= 1; break;
11804 case 'g': do_gdb_index
= 1; break;
11805 case 'i': do_debug_info
= 1; break;
11806 case 'K': do_follow_links
= 1; break;
11807 case 'N': do_follow_links
= 0; break;
11808 case 'k': do_debug_links
= 1; break;
11809 case 'l': do_debug_lines
|= FLAG_DEBUG_LINES_RAW
; break;
11810 case 'L': do_debug_lines
|= FLAG_DEBUG_LINES_DECODED
; break;
11811 case 'm': do_debug_macinfo
= 1; break;
11812 case 'O': do_debug_str_offsets
= 1; break;
11813 case 'o': do_debug_loc
= 1; break;
11814 case 'p': do_debug_pubnames
= 1; break;
11815 case 'R': do_debug_ranges
= 1; break;
11816 case 'r': do_debug_aranges
= 1; break;
11817 case 's': do_debug_str
= 1; break;
11818 case 'T': do_trace_aranges
= 1; break;
11819 case 't': do_debug_pubtypes
= 1; break;
11820 case 'U': do_trace_info
= 1; break;
11821 case 'u': do_trace_abbrevs
= 1; break;
11824 warn (_("Unrecognized debug option '%s'\n"), letters
);
11830 dwarf_select_sections_all (void)
11833 do_debug_abbrevs
= 1;
11834 do_debug_lines
= FLAG_DEBUG_LINES_RAW
;
11835 do_debug_pubnames
= 1;
11836 do_debug_pubtypes
= 1;
11837 do_debug_aranges
= 1;
11838 do_debug_ranges
= 1;
11839 do_debug_frames
= 1;
11840 do_debug_macinfo
= 1;
11845 do_trace_abbrevs
= 1;
11846 do_trace_aranges
= 1;
11848 do_debug_cu_index
= 1;
11849 do_follow_links
= 1;
11850 do_debug_links
= 1;
11851 do_debug_str_offsets
= 1;
11854 #define NO_ABBREVS NULL, NULL, NULL, 0, 0, 0, NULL, 0
11855 #define ABBREV(N) NULL, NULL, NULL, 0, 0, N, NULL, 0
11857 /* N.B. The order here must match the order in section_display_enum. */
11859 struct dwarf_section_display debug_displays
[] =
11861 { { ".debug_abbrev", ".zdebug_abbrev", ".dwabrev", NO_ABBREVS
}, display_debug_abbrev
, &do_debug_abbrevs
, false },
11862 { { ".debug_aranges", ".zdebug_aranges", ".dwarnge", NO_ABBREVS
}, display_debug_aranges
, &do_debug_aranges
, true },
11863 { { ".debug_frame", ".zdebug_frame", ".dwframe", NO_ABBREVS
}, display_debug_frames
, &do_debug_frames
, true },
11864 { { ".debug_info", ".zdebug_info", ".dwinfo", ABBREV (abbrev
)}, display_debug_info
, &do_debug_info
, true },
11865 { { ".debug_line", ".zdebug_line", ".dwline", NO_ABBREVS
}, display_debug_lines
, &do_debug_lines
, true },
11866 { { ".debug_pubnames", ".zdebug_pubnames", ".dwpbnms", NO_ABBREVS
}, display_debug_pubnames
, &do_debug_pubnames
, false },
11867 { { ".debug_gnu_pubnames", ".zdebug_gnu_pubnames", "", NO_ABBREVS
}, display_debug_gnu_pubnames
, &do_debug_pubnames
, false },
11868 { { ".eh_frame", "", "", NO_ABBREVS
}, display_debug_frames
, &do_debug_frames
, true },
11869 { { ".debug_macinfo", ".zdebug_macinfo", "", NO_ABBREVS
}, display_debug_macinfo
, &do_debug_macinfo
, false },
11870 { { ".debug_macro", ".zdebug_macro", ".dwmac", NO_ABBREVS
}, display_debug_macro
, &do_debug_macinfo
, true },
11871 { { ".debug_str", ".zdebug_str", ".dwstr", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, false },
11872 { { ".debug_line_str", ".zdebug_line_str", "", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, false },
11873 { { ".debug_loc", ".zdebug_loc", ".dwloc", NO_ABBREVS
}, display_debug_loc
, &do_debug_loc
, true },
11874 { { ".debug_loclists", ".zdebug_loclists", "", NO_ABBREVS
}, display_debug_loc
, &do_debug_loc
, true },
11875 { { ".debug_pubtypes", ".zdebug_pubtypes", ".dwpbtyp", NO_ABBREVS
}, display_debug_pubnames
, &do_debug_pubtypes
, false },
11876 { { ".debug_gnu_pubtypes", ".zdebug_gnu_pubtypes", "", NO_ABBREVS
}, display_debug_gnu_pubnames
, &do_debug_pubtypes
, false },
11877 { { ".debug_ranges", ".zdebug_ranges", ".dwrnges", NO_ABBREVS
}, display_debug_ranges
, &do_debug_ranges
, true },
11878 { { ".debug_rnglists", ".zdebug_rnglists", "", NO_ABBREVS
}, display_debug_ranges
, &do_debug_ranges
, true },
11879 { { ".debug_static_func", ".zdebug_static_func", "", NO_ABBREVS
}, display_debug_not_supported
, NULL
, false },
11880 { { ".debug_static_vars", ".zdebug_static_vars", "", NO_ABBREVS
}, display_debug_not_supported
, NULL
, false },
11881 { { ".debug_types", ".zdebug_types", "", ABBREV (abbrev
) }, display_debug_types
, &do_debug_info
, true },
11882 { { ".debug_weaknames", ".zdebug_weaknames", "", NO_ABBREVS
}, display_debug_not_supported
, NULL
, false },
11883 { { ".gdb_index", "", "", NO_ABBREVS
}, display_gdb_index
, &do_gdb_index
, false },
11884 { { ".debug_names", "", "", NO_ABBREVS
}, display_debug_names
, &do_gdb_index
, false },
11885 { { ".trace_info", "", "", ABBREV (trace_abbrev
) }, display_trace_info
, &do_trace_info
, true },
11886 { { ".trace_abbrev", "", "", NO_ABBREVS
}, display_debug_abbrev
, &do_trace_abbrevs
, false },
11887 { { ".trace_aranges", "", "", NO_ABBREVS
}, display_debug_aranges
, &do_trace_aranges
, false },
11888 { { ".debug_info.dwo", ".zdebug_info.dwo", "", ABBREV (abbrev_dwo
) }, display_debug_info
, &do_debug_info
, true },
11889 { { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo", "", NO_ABBREVS
}, display_debug_abbrev
, &do_debug_abbrevs
, false },
11890 { { ".debug_types.dwo", ".zdebug_types.dwo", "", ABBREV (abbrev_dwo
) }, display_debug_types
, &do_debug_info
, true },
11891 { { ".debug_line.dwo", ".zdebug_line.dwo", "", NO_ABBREVS
}, display_debug_lines
, &do_debug_lines
, true },
11892 { { ".debug_loc.dwo", ".zdebug_loc.dwo", "", NO_ABBREVS
}, display_debug_loc
, &do_debug_loc
, true },
11893 { { ".debug_macro.dwo", ".zdebug_macro.dwo", "", NO_ABBREVS
}, display_debug_macro
, &do_debug_macinfo
, true },
11894 { { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo", "", NO_ABBREVS
}, display_debug_macinfo
, &do_debug_macinfo
, false },
11895 { { ".debug_str.dwo", ".zdebug_str.dwo", "", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, true },
11896 { { ".debug_str_offsets", ".zdebug_str_offsets", "", NO_ABBREVS
}, display_debug_str_offsets
, &do_debug_str_offsets
, true },
11897 { { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo", "", NO_ABBREVS
}, display_debug_str_offsets
, &do_debug_str_offsets
, true },
11898 { { ".debug_addr", ".zdebug_addr", "", NO_ABBREVS
}, display_debug_addr
, &do_debug_addr
, true },
11899 { { ".debug_cu_index", "", "", NO_ABBREVS
}, display_cu_index
, &do_debug_cu_index
, false },
11900 { { ".debug_tu_index", "", "", NO_ABBREVS
}, display_cu_index
, &do_debug_cu_index
, false },
11901 { { ".gnu_debuglink", "", "", NO_ABBREVS
}, display_debug_links
, &do_debug_links
, false },
11902 { { ".gnu_debugaltlink", "", "", NO_ABBREVS
}, display_debug_links
, &do_debug_links
, false },
11903 { { ".debug_sup", "", "", NO_ABBREVS
}, display_debug_sup
, &do_debug_links
, false },
11904 /* Separate debug info files can containt their own .debug_str section,
11905 and this might be in *addition* to a .debug_str section already present
11906 in the main file. Hence we need to have two entries for .debug_str. */
11907 { { ".debug_str", ".zdebug_str", "", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, false },
11908 { { ".note.gnu.build-id", "", "", NO_ABBREVS
}, display_debug_not_supported
, NULL
, false },
11911 /* A static assertion. */
11912 extern int debug_displays_assert
[ARRAY_SIZE (debug_displays
) == max
? 1 : -1];