1 /* dwarf.c -- display DWARF contents of a BFD binary file
2 Copyright (C) 2005-2021 Free Software Foundation, Inc.
4 This file is part of GNU Binutils.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
22 #include "libiberty.h"
27 #include "elf/common.h"
30 #include "gdb/gdb-index.h"
31 #include "filenames.h"
32 #include "safe-ctype.h"
35 #ifdef HAVE_LIBDEBUGINFOD
36 #include <elfutils/debuginfod.h>
46 #define MAX(a, b) ((a) > (b) ? (a) : (b))
47 #define MIN(a, b) ((a) < (b) ? (a) : (b))
49 static const char *regname (unsigned int regno
, int row
);
50 static const char *regname_internal_by_table_only (unsigned int regno
);
52 static int have_frame_base
;
53 static int need_base_address
;
55 static unsigned int num_debug_info_entries
= 0;
56 static unsigned int alloc_num_debug_info_entries
= 0;
57 static debug_info
*debug_information
= NULL
;
58 /* Special value for num_debug_info_entries to indicate
59 that the .debug_info section could not be loaded/parsed. */
60 #define DEBUG_INFO_UNAVAILABLE (unsigned int) -1
62 /* A .debug_info section can contain multiple links to separate
63 DWO object files. We use these structures to record these links. */
71 typedef struct dwo_info
76 struct dwo_info
* next
;
79 static dwo_info
*first_dwo_info
= NULL
;
80 static bool need_dwo_info
;
82 separate_info
* first_separate_info
= NULL
;
84 unsigned int eh_addr_size
;
89 int do_debug_pubnames
;
90 int do_debug_pubtypes
;
94 int do_debug_frames_interp
;
97 int do_debug_str_offsets
;
101 int do_trace_abbrevs
;
102 int do_trace_aranges
;
104 int do_debug_cu_index
;
107 int do_follow_links
= DEFAULT_FOR_FOLLOW_LINKS
;
110 int dwarf_cutoff_level
= -1;
111 unsigned long dwarf_start_die
;
115 /* Convenient constant, to avoid having to cast -1 to dwarf_vma when
116 testing whether e.g. a locview list is present. */
117 static const dwarf_vma vm1
= -1;
119 /* Collection of CU/TU section sets from .debug_cu_index and .debug_tu_index
120 sections. For version 1 package files, each set is stored in SHNDX_POOL
121 as a zero-terminated list of section indexes comprising one set of debug
122 sections from a .dwo file. */
124 static unsigned int *shndx_pool
= NULL
;
125 static unsigned int shndx_pool_size
= 0;
126 static unsigned int shndx_pool_used
= 0;
128 /* For version 2 package files, each set contains an array of section offsets
129 and an array of section sizes, giving the offset and size of the
130 contribution from a CU or TU within one of the debug sections.
131 When displaying debug info from a package file, we need to use these
132 tables to locate the corresponding contributions to each section. */
137 dwarf_vma section_offsets
[DW_SECT_MAX
];
138 size_t section_sizes
[DW_SECT_MAX
];
141 static int cu_count
= 0;
142 static int tu_count
= 0;
143 static struct cu_tu_set
*cu_sets
= NULL
;
144 static struct cu_tu_set
*tu_sets
= NULL
;
146 static bool load_cu_tu_indexes (void *);
148 /* An array that indicates for a given level of CU nesting whether
149 the latest DW_AT_type seen for that level was a signed type or
151 #define MAX_CU_NESTING (1 << 8)
152 static bool level_type_signed
[MAX_CU_NESTING
];
154 /* Values for do_debug_lines. */
155 #define FLAG_DEBUG_LINES_RAW 1
156 #define FLAG_DEBUG_LINES_DECODED 2
159 size_of_encoded_value (int encoding
)
161 switch (encoding
& 0x7)
164 case 0: return eh_addr_size
;
172 get_encoded_value (unsigned char **pdata
,
174 struct dwarf_section
*section
,
177 unsigned char * data
= * pdata
;
178 unsigned int size
= size_of_encoded_value (encoding
);
181 if (data
+ size
>= end
)
183 warn (_("Encoded value extends past end of section\n"));
188 /* PR 17512: file: 002-829853-0.004. */
191 warn (_("Encoded size of %d is too large to read\n"), size
);
196 /* PR 17512: file: 1085-5603-0.004. */
199 warn (_("Encoded size of 0 is too small to read\n"));
204 if (encoding
& DW_EH_PE_signed
)
205 val
= byte_get_signed (data
, size
);
207 val
= byte_get (data
, size
);
209 if ((encoding
& 0x70) == DW_EH_PE_pcrel
)
210 val
+= section
->address
+ (data
- section
->start
);
212 * pdata
= data
+ size
;
216 #if SIZEOF_LONG_LONG > SIZEOF_LONG
218 # define DWARF_VMA_FMT "ll"
219 # define DWARF_VMA_FMT_LONG "%16.16llx"
221 # define DWARF_VMA_FMT "I64"
222 # define DWARF_VMA_FMT_LONG "%016I64x"
225 # define DWARF_VMA_FMT "l"
226 # define DWARF_VMA_FMT_LONG "%16.16lx"
229 /* Convert a dwarf vma value into a string. Returns a pointer to a static
230 buffer containing the converted VALUE. The value is converted according
231 to the printf formating character FMTCH. If NUM_BYTES is non-zero then
232 it specifies the maximum number of bytes to be displayed in the converted
233 value and FMTCH is ignored - hex is always used. */
236 dwarf_vmatoa_1 (const char *fmtch
, dwarf_vma value
, unsigned num_bytes
)
238 /* As dwarf_vmatoa is used more then once in a printf call
239 for output, we are cycling through an fixed array of pointers
240 for return address. */
241 static int buf_pos
= 0;
242 static struct dwarf_vmatoa_buf
248 ret
= buf
[buf_pos
++].place
;
249 buf_pos
%= ARRAY_SIZE (buf
);
253 /* Printf does not have a way of specifying a maximum field width for an
254 integer value, so we print the full value into a buffer and then select
255 the precision we need. */
256 snprintf (ret
, sizeof (buf
[0].place
), DWARF_VMA_FMT_LONG
, value
);
259 return ret
+ (16 - 2 * num_bytes
);
266 sprintf (fmt
, "%%%s%s", DWARF_VMA_FMT
, fmtch
);
268 sprintf (fmt
, "%%%s", DWARF_VMA_FMT
);
269 snprintf (ret
, sizeof (buf
[0].place
), fmt
, value
);
274 static inline const char *
275 dwarf_vmatoa (const char * fmtch
, dwarf_vma value
)
277 return dwarf_vmatoa_1 (fmtch
, value
, 0);
280 /* Print a dwarf_vma value (typically an address, offset or length) in
281 hexadecimal format, followed by a space. The length of the VALUE (and
282 hence the precision displayed) is determined by the NUM_BYTES parameter. */
285 print_dwarf_vma (dwarf_vma value
, unsigned num_bytes
)
287 printf ("%s ", dwarf_vmatoa_1 (NULL
, value
, num_bytes
));
290 /* Print a view number in hexadecimal value, with the same width
291 print_dwarf_vma would have printed it with the same num_bytes.
292 Print blanks for zero view, unless force is nonzero. */
295 print_dwarf_view (dwarf_vma value
, unsigned num_bytes
, int force
)
303 assert (value
== (unsigned long) value
);
305 printf ("v%0*lx ", len
- 1, (unsigned long) value
);
307 printf ("%*s", len
+ 1, "");
310 /* Format a 64-bit value, given as two 32-bit values, in hex.
311 For reentrancy, this uses a buffer provided by the caller. */
314 dwarf_vmatoa64 (dwarf_vma hvalue
, dwarf_vma lvalue
, char *buf
,
315 unsigned int buf_len
)
320 snprintf (buf
, buf_len
, "%" DWARF_VMA_FMT
"x", lvalue
);
323 len
= snprintf (buf
, buf_len
, "%" DWARF_VMA_FMT
"x", hvalue
);
324 snprintf (buf
+ len
, buf_len
- len
,
325 "%08" DWARF_VMA_FMT
"x", lvalue
);
331 /* Read in a LEB128 encoded value starting at address DATA.
332 If SIGN is true, return a signed LEB128 value.
333 If LENGTH_RETURN is not NULL, return in it the number of bytes read.
334 If STATUS_RETURN is not NULL, return with bit 0 (LSB) set if the
335 terminating byte was not found and with bit 1 set if the value
336 overflows a dwarf_vma.
337 No bytes will be read at address END or beyond. */
340 read_leb128 (unsigned char *data
,
341 const unsigned char *const end
,
343 unsigned int *length_return
,
346 dwarf_vma result
= 0;
347 unsigned int num_read
= 0;
348 unsigned int shift
= 0;
353 unsigned char byte
= *data
++;
354 unsigned char lost
, mask
;
358 if (shift
< CHAR_BIT
* sizeof (result
))
360 result
|= ((dwarf_vma
) (byte
& 0x7f)) << shift
;
361 /* These bits overflowed. */
362 lost
= byte
^ (result
>> shift
);
363 /* And this is the mask of possible overflow bits. */
364 mask
= 0x7f ^ ((dwarf_vma
) 0x7f << shift
>> shift
);
372 if ((lost
& mask
) != (sign
&& (dwarf_signed_vma
) result
< 0 ? mask
: 0))
375 if ((byte
& 0x80) == 0)
378 if (sign
&& shift
< CHAR_BIT
* sizeof (result
) && (byte
& 0x40))
379 result
|= -((dwarf_vma
) 1 << shift
);
384 if (length_return
!= NULL
)
385 *length_return
= num_read
;
386 if (status_return
!= NULL
)
387 *status_return
= status
;
392 /* Read AMOUNT bytes from PTR and store them in VAL as an unsigned value.
393 Checks to make sure that the read will not reach or pass END
394 and that VAL is big enough to hold AMOUNT bytes. */
395 #define SAFE_BYTE_GET(VAL, PTR, AMOUNT, END) \
398 unsigned int amount = (AMOUNT); \
399 if (sizeof (VAL) < amount) \
401 error (ngettext ("internal error: attempt to read %d byte " \
402 "of data in to %d sized variable", \
403 "internal error: attempt to read %d bytes " \
404 "of data in to %d sized variable", \
406 amount, (int) sizeof (VAL)); \
407 amount = sizeof (VAL); \
409 if ((PTR) >= (END) - amount) \
412 amount = (END) - (PTR); \
416 if (amount == 0 || amount > 8) \
419 VAL = byte_get ((PTR), amount); \
423 /* Like SAFE_BYTE_GET, but also increments PTR by AMOUNT. */
424 #define SAFE_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \
427 SAFE_BYTE_GET (VAL, PTR, AMOUNT, END); \
432 /* Like SAFE_BYTE_GET, but reads a signed value. */
433 #define SAFE_SIGNED_BYTE_GET(VAL, PTR, AMOUNT, END) \
436 unsigned int amount = (AMOUNT); \
437 if ((PTR) >= (END) - amount) \
440 amount = (END) - (PTR); \
445 VAL = byte_get_signed ((PTR), amount); \
451 /* Like SAFE_SIGNED_BYTE_GET, but also increments PTR by AMOUNT. */
452 #define SAFE_SIGNED_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \
455 SAFE_SIGNED_BYTE_GET (VAL, PTR, AMOUNT, END); \
460 #define SAFE_BYTE_GET64(PTR, HIGH, LOW, END) \
463 if ((PTR) <= (END) - 8) \
465 byte_get_64 ((PTR), (HIGH), (LOW)); \
469 * (LOW) = * (HIGH) = 0; \
474 typedef struct State_Machine_Registers
483 unsigned char op_index
;
484 unsigned char end_sequence
;
485 /* This variable hold the number of the last entry seen
486 in the File Table. */
487 unsigned int last_file_entry
;
490 static SMR state_machine_regs
;
493 reset_state_machine (int is_stmt
)
495 state_machine_regs
.address
= 0;
496 state_machine_regs
.view
= 0;
497 state_machine_regs
.op_index
= 0;
498 state_machine_regs
.file
= 1;
499 state_machine_regs
.line
= 1;
500 state_machine_regs
.column
= 0;
501 state_machine_regs
.is_stmt
= is_stmt
;
502 state_machine_regs
.basic_block
= 0;
503 state_machine_regs
.end_sequence
= 0;
504 state_machine_regs
.last_file_entry
= 0;
507 /* Handled an extend line op.
508 Returns the number of bytes read. */
511 process_extended_line_op (unsigned char * data
,
515 unsigned char op_code
;
516 size_t len
, header_len
;
518 unsigned char *orig_data
= data
;
521 READ_ULEB (len
, data
, end
);
522 header_len
= data
- orig_data
;
524 if (len
== 0 || data
>= end
|| len
> (size_t) (end
- data
))
526 warn (_("Badly formed extended line op encountered!\n"));
532 printf (_(" Extended opcode %d: "), op_code
);
536 case DW_LNE_end_sequence
:
537 printf (_("End of Sequence\n\n"));
538 reset_state_machine (is_stmt
);
541 case DW_LNE_set_address
:
542 /* PR 17512: file: 002-100480-0.004. */
545 warn (_("Length (%lu) of DW_LNE_set_address op is too long\n"),
546 (unsigned long) len
- 1);
550 SAFE_BYTE_GET (adr
, data
, len
- 1, end
);
551 printf (_("set Address to 0x%s\n"), dwarf_vmatoa ("x", adr
));
552 state_machine_regs
.address
= adr
;
553 state_machine_regs
.view
= 0;
554 state_machine_regs
.op_index
= 0;
557 case DW_LNE_define_file
:
558 printf (_("define new File Table entry\n"));
559 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
560 printf (" %d\t", ++state_machine_regs
.last_file_entry
);
566 l
= strnlen ((char *) data
, end
- data
);
568 READ_ULEB (val
, data
, end
);
569 printf ("%s\t", dwarf_vmatoa ("u", val
));
570 READ_ULEB (val
, data
, end
);
571 printf ("%s\t", dwarf_vmatoa ("u", val
));
572 READ_ULEB (val
, data
, end
);
573 printf ("%s\t", dwarf_vmatoa ("u", val
));
574 printf ("%.*s\n\n", (int) l
, name
);
577 if (((size_t) (data
- orig_data
) != len
+ header_len
) || data
>= end
)
578 warn (_("DW_LNE_define_file: Bad opcode length\n"));
581 case DW_LNE_set_discriminator
:
582 READ_ULEB (val
, data
, end
);
583 printf (_("set Discriminator to %s\n"), dwarf_vmatoa ("u", val
));
587 case DW_LNE_HP_negate_is_UV_update
:
588 printf ("DW_LNE_HP_negate_is_UV_update\n");
590 case DW_LNE_HP_push_context
:
591 printf ("DW_LNE_HP_push_context\n");
593 case DW_LNE_HP_pop_context
:
594 printf ("DW_LNE_HP_pop_context\n");
596 case DW_LNE_HP_set_file_line_column
:
597 printf ("DW_LNE_HP_set_file_line_column\n");
599 case DW_LNE_HP_set_routine_name
:
600 printf ("DW_LNE_HP_set_routine_name\n");
602 case DW_LNE_HP_set_sequence
:
603 printf ("DW_LNE_HP_set_sequence\n");
605 case DW_LNE_HP_negate_post_semantics
:
606 printf ("DW_LNE_HP_negate_post_semantics\n");
608 case DW_LNE_HP_negate_function_exit
:
609 printf ("DW_LNE_HP_negate_function_exit\n");
611 case DW_LNE_HP_negate_front_end_logical
:
612 printf ("DW_LNE_HP_negate_front_end_logical\n");
614 case DW_LNE_HP_define_proc
:
615 printf ("DW_LNE_HP_define_proc\n");
617 case DW_LNE_HP_source_file_correlation
:
619 unsigned char *edata
= data
+ len
- 1;
621 printf ("DW_LNE_HP_source_file_correlation\n");
627 READ_ULEB (opc
, data
, edata
);
631 case DW_LNE_HP_SFC_formfeed
:
632 printf (" DW_LNE_HP_SFC_formfeed\n");
634 case DW_LNE_HP_SFC_set_listing_line
:
635 READ_ULEB (val
, data
, edata
);
636 printf (" DW_LNE_HP_SFC_set_listing_line (%s)\n",
637 dwarf_vmatoa ("u", val
));
639 case DW_LNE_HP_SFC_associate
:
640 printf (" DW_LNE_HP_SFC_associate ");
641 READ_ULEB (val
, data
, edata
);
642 printf ("(%s", dwarf_vmatoa ("u", val
));
643 READ_ULEB (val
, data
, edata
);
644 printf (",%s", dwarf_vmatoa ("u", val
));
645 READ_ULEB (val
, data
, edata
);
646 printf (",%s)\n", dwarf_vmatoa ("u", val
));
649 printf (_(" UNKNOWN DW_LNE_HP_SFC opcode (%u)\n"), opc
);
659 unsigned int rlen
= len
- 1;
661 if (op_code
>= DW_LNE_lo_user
662 /* The test against DW_LNW_hi_user is redundant due to
663 the limited range of the unsigned char data type used
665 /*&& op_code <= DW_LNE_hi_user*/)
666 printf (_("user defined: "));
668 printf (_("UNKNOWN: "));
669 printf (_("length %d ["), rlen
);
671 printf (" %02x", *data
++);
677 return len
+ header_len
;
680 static const unsigned char *
681 fetch_indirect_string (dwarf_vma offset
)
683 struct dwarf_section
*section
= &debug_displays
[str
].section
;
684 const unsigned char * ret
;
686 if (section
->start
== NULL
)
687 return (const unsigned char *) _("<no .debug_str section>");
689 if (offset
>= section
->size
)
691 warn (_("DW_FORM_strp offset too big: 0x%s\n"),
692 dwarf_vmatoa ("x", offset
));
693 return (const unsigned char *) _("<offset is too big>");
696 ret
= section
->start
+ offset
;
697 /* Unfortunately we cannot rely upon the .debug_str section ending with a
698 NUL byte. Since our caller is expecting to receive a well formed C
699 string we test for the lack of a terminating byte here. */
700 if (strnlen ((const char *) ret
, section
->size
- offset
)
701 == section
->size
- offset
)
702 ret
= (const unsigned char *)
703 _("<no NUL byte at end of .debug_str section>");
708 static const unsigned char *
709 fetch_indirect_line_string (dwarf_vma offset
)
711 struct dwarf_section
*section
= &debug_displays
[line_str
].section
;
712 const unsigned char * ret
;
714 if (section
->start
== NULL
)
715 return (const unsigned char *) _("<no .debug_line_str section>");
717 if (offset
>= section
->size
)
719 warn (_("DW_FORM_line_strp offset too big: 0x%s\n"),
720 dwarf_vmatoa ("x", offset
));
721 return (const unsigned char *) _("<offset is too big>");
724 ret
= section
->start
+ offset
;
725 /* Unfortunately we cannot rely upon the .debug_line_str section ending
726 with a NUL byte. Since our caller is expecting to receive a well formed
727 C string we test for the lack of a terminating byte here. */
728 if (strnlen ((const char *) ret
, section
->size
- offset
)
729 == section
->size
- offset
)
730 ret
= (const unsigned char *)
731 _("<no NUL byte at end of .debug_line_str section>");
737 fetch_indexed_string (dwarf_vma idx
, struct cu_tu_set
*this_set
,
738 dwarf_vma offset_size
, bool dwo
)
740 enum dwarf_section_display_enum str_sec_idx
= dwo
? str_dwo
: str
;
741 enum dwarf_section_display_enum idx_sec_idx
= dwo
? str_index_dwo
: str_index
;
742 struct dwarf_section
*index_section
= &debug_displays
[idx_sec_idx
].section
;
743 struct dwarf_section
*str_section
= &debug_displays
[str_sec_idx
].section
;
744 dwarf_vma index_offset
;
745 dwarf_vma str_offset
;
747 unsigned char *curr
= index_section
->start
;
748 unsigned char *end
= curr
+ index_section
->size
;
751 if (index_section
->start
== NULL
)
752 return (dwo
? _("<no .debug_str_offsets.dwo section>")
753 : _("<no .debug_str_offsets section>"));
755 if (str_section
->start
== NULL
)
756 return (dwo
? _("<no .debug_str.dwo section>")
757 : _("<no .debug_str section>"));
759 /* FIXME: We should cache the length... */
760 SAFE_BYTE_GET_AND_INC (length
, curr
, 4, end
);
761 if (length
== 0xffffffff)
763 if (offset_size
!= 8)
764 warn (_("Expected offset size of 8 but given %s"), dwarf_vmatoa ("x", offset_size
));
765 SAFE_BYTE_GET_AND_INC (length
, curr
, 8, end
);
767 else if (offset_size
!= 4)
769 warn (_("Expected offset size of 4 but given %s"), dwarf_vmatoa ("x", offset_size
));
774 /* This is probably an old style .debug_str_offset section which
775 just contains offsets and no header (and the first offset is 0). */
776 curr
= index_section
->start
;
777 length
= index_section
->size
;
781 /* Skip the version and padding bytes.
782 We assume that they are correct. */
793 && this_set
->section_sizes
[DW_SECT_STR_OFFSETS
] < length
)
794 length
= this_set
->section_sizes
[DW_SECT_STR_OFFSETS
];
796 if (length
> (dwarf_vma
) (end
- curr
))
798 warn (_("index table size too large for section %s vs %s\n"),
799 dwarf_vmatoa ("x", length
),
800 dwarf_vmatoa ("x", index_section
->size
));
804 if (length
< offset_size
)
806 warn (_("index table size %s is too small\n"),
807 dwarf_vmatoa ("x", length
));
808 return _("<table too small>");
812 index_offset
= idx
* offset_size
;
814 if (this_set
!= NULL
)
815 index_offset
+= this_set
->section_offsets
[DW_SECT_STR_OFFSETS
];
817 if (index_offset
>= length
818 || length
- index_offset
< offset_size
)
820 warn (_("DW_FORM_GNU_str_index offset too big: 0x%s vs 0x%s\n"),
821 dwarf_vmatoa ("x", index_offset
),
822 dwarf_vmatoa ("x", length
));
823 return _("<index offset is too big>");
826 str_offset
= byte_get (curr
+ index_offset
, offset_size
);
827 str_offset
-= str_section
->address
;
828 if (str_offset
>= str_section
->size
)
830 warn (_("DW_FORM_GNU_str_index indirect offset too big: 0x%s\n"),
831 dwarf_vmatoa ("x", str_offset
));
832 return _("<indirect index offset is too big>");
835 ret
= (const char *) str_section
->start
+ str_offset
;
836 /* Unfortunately we cannot rely upon str_section ending with a NUL byte.
837 Since our caller is expecting to receive a well formed C string we test
838 for the lack of a terminating byte here. */
839 if (strnlen (ret
, str_section
->size
- str_offset
)
840 == str_section
->size
- str_offset
)
841 ret
= (const char *) _("<no NUL byte at end of section>");
847 fetch_indexed_value (dwarf_vma offset
, dwarf_vma bytes
)
849 struct dwarf_section
*section
= &debug_displays
[debug_addr
].section
;
851 if (section
->start
== NULL
)
852 return (_("<no .debug_addr section>"));
854 if (offset
+ bytes
> section
->size
)
856 warn (_("Offset into section %s too big: 0x%s\n"),
857 section
->name
, dwarf_vmatoa ("x", offset
));
858 return "<offset too big>";
861 return dwarf_vmatoa ("x", byte_get (section
->start
+ offset
, bytes
));
865 /* FIXME: There are better and more efficient ways to handle
866 these structures. For now though, I just want something that
867 is simple to implement. */
868 /* Records a single attribute in an abbrev. */
869 typedef struct abbrev_attr
871 unsigned long attribute
;
873 bfd_signed_vma implicit_const
;
874 struct abbrev_attr
* next
;
878 /* Records a single abbrev. */
879 typedef struct abbrev_entry
881 unsigned long number
;
884 struct abbrev_attr
* first_attr
;
885 struct abbrev_attr
* last_attr
;
886 struct abbrev_entry
* next
;
890 /* Records a set of abbreviations. */
891 typedef struct abbrev_list
893 abbrev_entry
* first_abbrev
;
894 abbrev_entry
* last_abbrev
;
895 dwarf_vma abbrev_base
;
896 dwarf_vma abbrev_offset
;
897 struct abbrev_list
* next
;
898 unsigned char * start_of_next_abbrevs
;
902 /* Records all the abbrevs found so far. */
903 static struct abbrev_list
* abbrev_lists
= NULL
;
905 typedef struct abbrev_map
912 /* Maps between CU offsets and abbrev sets. */
913 static abbrev_map
* cu_abbrev_map
= NULL
;
914 static unsigned long num_abbrev_map_entries
= 0;
915 static unsigned long next_free_abbrev_map_entry
= 0;
917 #define INITIAL_NUM_ABBREV_MAP_ENTRIES 8
918 #define ABBREV_MAP_ENTRIES_INCREMENT 8
921 record_abbrev_list_for_cu (dwarf_vma start
, dwarf_vma end
, abbrev_list
* list
)
923 if (cu_abbrev_map
== NULL
)
925 num_abbrev_map_entries
= INITIAL_NUM_ABBREV_MAP_ENTRIES
;
926 cu_abbrev_map
= xmalloc (num_abbrev_map_entries
* sizeof (* cu_abbrev_map
));
928 else if (next_free_abbrev_map_entry
== num_abbrev_map_entries
)
930 num_abbrev_map_entries
+= ABBREV_MAP_ENTRIES_INCREMENT
;
931 cu_abbrev_map
= xrealloc (cu_abbrev_map
, num_abbrev_map_entries
* sizeof (* cu_abbrev_map
));
934 cu_abbrev_map
[next_free_abbrev_map_entry
].start
= start
;
935 cu_abbrev_map
[next_free_abbrev_map_entry
].end
= end
;
936 cu_abbrev_map
[next_free_abbrev_map_entry
].list
= list
;
937 next_free_abbrev_map_entry
++;
941 free_all_abbrevs (void)
945 for (list
= abbrev_lists
; list
!= NULL
;)
947 abbrev_list
* next
= list
->next
;
948 abbrev_entry
* abbrv
;
950 for (abbrv
= list
->first_abbrev
; abbrv
!= NULL
;)
952 abbrev_entry
* next_abbrev
= abbrv
->next
;
955 for (attr
= abbrv
->first_attr
; attr
;)
957 abbrev_attr
*next_attr
= attr
->next
;
975 new_abbrev_list (dwarf_vma abbrev_base
, dwarf_vma abbrev_offset
)
977 abbrev_list
* list
= (abbrev_list
*) xcalloc (sizeof * list
, 1);
979 list
->abbrev_base
= abbrev_base
;
980 list
->abbrev_offset
= abbrev_offset
;
982 list
->next
= abbrev_lists
;
989 find_abbrev_list_by_abbrev_offset (dwarf_vma abbrev_base
,
990 dwarf_vma abbrev_offset
)
994 for (list
= abbrev_lists
; list
!= NULL
; list
= list
->next
)
995 if (list
->abbrev_base
== abbrev_base
996 && list
->abbrev_offset
== abbrev_offset
)
1002 /* Find the abbreviation map for the CU that includes OFFSET.
1003 OFFSET is an absolute offset from the start of the .debug_info section. */
1004 /* FIXME: This function is going to slow down readelf & objdump.
1005 Consider using a better algorithm to mitigate this effect. */
1008 find_abbrev_map_by_offset (dwarf_vma offset
)
1012 for (i
= 0; i
< next_free_abbrev_map_entry
; i
++)
1013 if (cu_abbrev_map
[i
].start
<= offset
1014 && cu_abbrev_map
[i
].end
> offset
)
1015 return cu_abbrev_map
+ i
;
1021 add_abbrev (unsigned long number
,
1026 abbrev_entry
* entry
;
1028 entry
= (abbrev_entry
*) xmalloc (sizeof (*entry
));
1030 entry
->number
= number
;
1032 entry
->children
= children
;
1033 entry
->first_attr
= NULL
;
1034 entry
->last_attr
= NULL
;
1037 assert (list
!= NULL
);
1039 if (list
->first_abbrev
== NULL
)
1040 list
->first_abbrev
= entry
;
1042 list
->last_abbrev
->next
= entry
;
1044 list
->last_abbrev
= entry
;
1048 add_abbrev_attr (unsigned long attribute
,
1050 bfd_signed_vma implicit_const
,
1055 attr
= (abbrev_attr
*) xmalloc (sizeof (*attr
));
1057 attr
->attribute
= attribute
;
1059 attr
->implicit_const
= implicit_const
;
1062 assert (list
!= NULL
&& list
->last_abbrev
!= NULL
);
1064 if (list
->last_abbrev
->first_attr
== NULL
)
1065 list
->last_abbrev
->first_attr
= attr
;
1067 list
->last_abbrev
->last_attr
->next
= attr
;
1069 list
->last_abbrev
->last_attr
= attr
;
1072 /* Processes the (partial) contents of a .debug_abbrev section.
1073 Returns NULL if the end of the section was encountered.
1074 Returns the address after the last byte read if the end of
1075 an abbreviation set was found. */
1077 static unsigned char *
1078 process_abbrev_set (struct dwarf_section
*section
,
1079 dwarf_vma abbrev_base
,
1080 dwarf_vma abbrev_size
,
1081 dwarf_vma abbrev_offset
,
1084 if (abbrev_base
>= section
->size
1085 || abbrev_size
> section
->size
- abbrev_base
)
1087 /* PR 17531: file:4bcd9ce9. */
1088 warn (_("Debug info is corrupted, abbrev size (%lx) is larger than "
1089 "abbrev section size (%lx)\n"),
1090 (unsigned long) (abbrev_base
+ abbrev_size
),
1091 (unsigned long) section
->size
);
1094 if (abbrev_offset
>= abbrev_size
)
1096 warn (_("Debug info is corrupted, abbrev offset (%lx) is larger than "
1097 "abbrev section size (%lx)\n"),
1098 (unsigned long) abbrev_offset
,
1099 (unsigned long) abbrev_size
);
1103 unsigned char *start
= section
->start
+ abbrev_base
;
1104 unsigned char *end
= start
+ abbrev_size
;
1105 start
+= abbrev_offset
;
1108 unsigned long entry
;
1110 unsigned long attribute
;
1113 READ_ULEB (entry
, start
, end
);
1115 /* A single zero is supposed to end the set according
1116 to the standard. If there's more, then signal that to
1123 READ_ULEB (tag
, start
, end
);
1127 children
= *start
++;
1129 add_abbrev (entry
, tag
, children
, list
);
1134 /* Initialize it due to a false compiler warning. */
1135 bfd_signed_vma implicit_const
= -1;
1137 READ_ULEB (attribute
, start
, end
);
1141 READ_ULEB (form
, start
, end
);
1145 if (form
== DW_FORM_implicit_const
)
1147 READ_SLEB (implicit_const
, start
, end
);
1152 add_abbrev_attr (attribute
, form
, implicit_const
, list
);
1154 while (attribute
!= 0);
1157 /* Report the missing single zero which ends the section. */
1158 error (_(".debug_abbrev section not zero terminated\n"));
1164 get_TAG_name (unsigned long tag
)
1166 const char *name
= get_DW_TAG_name ((unsigned int) tag
);
1170 static char buffer
[100];
1172 if (tag
>= DW_TAG_lo_user
&& tag
<= DW_TAG_hi_user
)
1173 snprintf (buffer
, sizeof (buffer
), _("User TAG value: %#lx"), tag
);
1175 snprintf (buffer
, sizeof (buffer
), _("Unknown TAG value: %#lx"), tag
);
1183 get_FORM_name (unsigned long form
)
1188 return "DW_FORM value: 0";
1190 name
= get_DW_FORM_name (form
);
1193 static char buffer
[100];
1195 snprintf (buffer
, sizeof (buffer
), _("Unknown FORM value: %lx"), form
);
1203 get_IDX_name (unsigned long idx
)
1205 const char *name
= get_DW_IDX_name ((unsigned int) idx
);
1209 static char buffer
[100];
1211 snprintf (buffer
, sizeof (buffer
), _("Unknown IDX value: %lx"), idx
);
1218 static unsigned char *
1219 display_block (unsigned char *data
,
1221 const unsigned char * const end
, char delimiter
)
1225 printf (_("%c%s byte block: "), delimiter
, dwarf_vmatoa ("u", length
));
1227 return (unsigned char *) end
;
1229 maxlen
= (dwarf_vma
) (end
- data
);
1230 length
= length
> maxlen
? maxlen
: length
;
1233 printf ("%lx ", (unsigned long) byte_get (data
++, 1));
1239 decode_location_expression (unsigned char * data
,
1240 unsigned int pointer_size
,
1241 unsigned int offset_size
,
1244 dwarf_vma cu_offset
,
1245 struct dwarf_section
* section
)
1249 dwarf_signed_vma svalue
;
1250 unsigned char *end
= data
+ length
;
1251 int need_frame_base
= 0;
1260 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1261 printf ("DW_OP_addr: %s", dwarf_vmatoa ("x", uvalue
));
1264 printf ("DW_OP_deref");
1267 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1268 printf ("DW_OP_const1u: %lu", (unsigned long) uvalue
);
1271 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 1, end
);
1272 printf ("DW_OP_const1s: %ld", (long) svalue
);
1275 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
1276 printf ("DW_OP_const2u: %lu", (unsigned long) uvalue
);
1279 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1280 printf ("DW_OP_const2s: %ld", (long) svalue
);
1283 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1284 printf ("DW_OP_const4u: %lu", (unsigned long) uvalue
);
1287 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
1288 printf ("DW_OP_const4s: %ld", (long) svalue
);
1291 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1292 printf ("DW_OP_const8u: %lu ", (unsigned long) uvalue
);
1293 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1294 printf ("%lu", (unsigned long) uvalue
);
1297 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
1298 printf ("DW_OP_const8s: %ld ", (long) svalue
);
1299 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
1300 printf ("%ld", (long) svalue
);
1303 READ_ULEB (uvalue
, data
, end
);
1304 printf ("DW_OP_constu: %s", dwarf_vmatoa ("u", uvalue
));
1307 READ_SLEB (svalue
, data
, end
);
1308 printf ("DW_OP_consts: %s", dwarf_vmatoa ("d", svalue
));
1311 printf ("DW_OP_dup");
1314 printf ("DW_OP_drop");
1317 printf ("DW_OP_over");
1320 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1321 printf ("DW_OP_pick: %ld", (unsigned long) uvalue
);
1324 printf ("DW_OP_swap");
1327 printf ("DW_OP_rot");
1330 printf ("DW_OP_xderef");
1333 printf ("DW_OP_abs");
1336 printf ("DW_OP_and");
1339 printf ("DW_OP_div");
1342 printf ("DW_OP_minus");
1345 printf ("DW_OP_mod");
1348 printf ("DW_OP_mul");
1351 printf ("DW_OP_neg");
1354 printf ("DW_OP_not");
1357 printf ("DW_OP_or");
1360 printf ("DW_OP_plus");
1362 case DW_OP_plus_uconst
:
1363 READ_ULEB (uvalue
, data
, end
);
1364 printf ("DW_OP_plus_uconst: %s", dwarf_vmatoa ("u", uvalue
));
1367 printf ("DW_OP_shl");
1370 printf ("DW_OP_shr");
1373 printf ("DW_OP_shra");
1376 printf ("DW_OP_xor");
1379 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1380 printf ("DW_OP_bra: %ld", (long) svalue
);
1383 printf ("DW_OP_eq");
1386 printf ("DW_OP_ge");
1389 printf ("DW_OP_gt");
1392 printf ("DW_OP_le");
1395 printf ("DW_OP_lt");
1398 printf ("DW_OP_ne");
1401 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1402 printf ("DW_OP_skip: %ld", (long) svalue
);
1437 printf ("DW_OP_lit%d", op
- DW_OP_lit0
);
1472 printf ("DW_OP_reg%d (%s)", op
- DW_OP_reg0
,
1473 regname (op
- DW_OP_reg0
, 1));
1508 READ_SLEB (svalue
, data
, end
);
1509 printf ("DW_OP_breg%d (%s): %s", op
- DW_OP_breg0
,
1510 regname (op
- DW_OP_breg0
, 1), dwarf_vmatoa ("d", svalue
));
1514 READ_ULEB (uvalue
, data
, end
);
1515 printf ("DW_OP_regx: %s (%s)",
1516 dwarf_vmatoa ("u", uvalue
), regname (uvalue
, 1));
1519 need_frame_base
= 1;
1520 READ_SLEB (svalue
, data
, end
);
1521 printf ("DW_OP_fbreg: %s", dwarf_vmatoa ("d", svalue
));
1524 READ_ULEB (uvalue
, data
, end
);
1525 READ_SLEB (svalue
, data
, end
);
1526 printf ("DW_OP_bregx: %s (%s) %s",
1527 dwarf_vmatoa ("u", uvalue
), regname (uvalue
, 1),
1528 dwarf_vmatoa ("d", svalue
));
1531 READ_ULEB (uvalue
, data
, end
);
1532 printf ("DW_OP_piece: %s", dwarf_vmatoa ("u", uvalue
));
1534 case DW_OP_deref_size
:
1535 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1536 printf ("DW_OP_deref_size: %ld", (long) uvalue
);
1538 case DW_OP_xderef_size
:
1539 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1540 printf ("DW_OP_xderef_size: %ld", (long) uvalue
);
1543 printf ("DW_OP_nop");
1546 /* DWARF 3 extensions. */
1547 case DW_OP_push_object_address
:
1548 printf ("DW_OP_push_object_address");
1551 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1552 this ought to be an 8-byte wide computation. */
1553 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1554 printf ("DW_OP_call2: <0x%s>",
1555 dwarf_vmatoa ("x", svalue
+ cu_offset
));
1558 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1559 this ought to be an 8-byte wide computation. */
1560 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
1561 printf ("DW_OP_call4: <0x%s>",
1562 dwarf_vmatoa ("x", svalue
+ cu_offset
));
1564 case DW_OP_call_ref
:
1565 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1566 this ought to be an 8-byte wide computation. */
1567 if (dwarf_version
== -1)
1569 printf (_("(DW_OP_call_ref in frame info)"));
1570 /* No way to tell where the next op is, so just bail. */
1571 return need_frame_base
;
1573 if (dwarf_version
== 2)
1575 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1579 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1581 printf ("DW_OP_call_ref: <0x%s>", dwarf_vmatoa ("x", uvalue
));
1583 case DW_OP_form_tls_address
:
1584 printf ("DW_OP_form_tls_address");
1586 case DW_OP_call_frame_cfa
:
1587 printf ("DW_OP_call_frame_cfa");
1589 case DW_OP_bit_piece
:
1590 printf ("DW_OP_bit_piece: ");
1591 READ_ULEB (uvalue
, data
, end
);
1592 printf (_("size: %s "), dwarf_vmatoa ("u", uvalue
));
1593 READ_ULEB (uvalue
, data
, end
);
1594 printf (_("offset: %s "), dwarf_vmatoa ("u", uvalue
));
1597 /* DWARF 4 extensions. */
1598 case DW_OP_stack_value
:
1599 printf ("DW_OP_stack_value");
1602 case DW_OP_implicit_value
:
1603 printf ("DW_OP_implicit_value");
1604 READ_ULEB (uvalue
, data
, end
);
1605 data
= display_block (data
, uvalue
, end
, ' ');
1608 /* GNU extensions. */
1609 case DW_OP_GNU_push_tls_address
:
1610 printf (_("DW_OP_GNU_push_tls_address or DW_OP_HP_unknown"));
1612 case DW_OP_GNU_uninit
:
1613 printf ("DW_OP_GNU_uninit");
1614 /* FIXME: Is there data associated with this OP ? */
1616 case DW_OP_GNU_encoded_addr
:
1623 addr
= get_encoded_value (&data
, encoding
, section
, end
);
1625 printf ("DW_OP_GNU_encoded_addr: fmt:%02x addr:", encoding
);
1626 print_dwarf_vma (addr
, pointer_size
);
1629 case DW_OP_implicit_pointer
:
1630 case DW_OP_GNU_implicit_pointer
:
1631 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1632 this ought to be an 8-byte wide computation. */
1633 if (dwarf_version
== -1)
1635 printf (_("(%s in frame info)"),
1636 (op
== DW_OP_implicit_pointer
1637 ? "DW_OP_implicit_pointer"
1638 : "DW_OP_GNU_implicit_pointer"));
1639 /* No way to tell where the next op is, so just bail. */
1640 return need_frame_base
;
1642 if (dwarf_version
== 2)
1644 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1648 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1650 READ_SLEB (svalue
, data
, end
);
1651 printf ("%s: <0x%s> %s",
1652 (op
== DW_OP_implicit_pointer
1653 ? "DW_OP_implicit_pointer" : "DW_OP_GNU_implicit_pointer"),
1654 dwarf_vmatoa ("x", uvalue
),
1655 dwarf_vmatoa ("d", svalue
));
1657 case DW_OP_entry_value
:
1658 case DW_OP_GNU_entry_value
:
1659 READ_ULEB (uvalue
, data
, end
);
1660 /* PR 17531: file: 0cc9cd00. */
1661 if (uvalue
> (dwarf_vma
) (end
- data
))
1662 uvalue
= end
- data
;
1663 printf ("%s: (", (op
== DW_OP_entry_value
? "DW_OP_entry_value"
1664 : "DW_OP_GNU_entry_value"));
1665 if (decode_location_expression (data
, pointer_size
, offset_size
,
1666 dwarf_version
, uvalue
,
1667 cu_offset
, section
))
1668 need_frame_base
= 1;
1674 case DW_OP_const_type
:
1675 case DW_OP_GNU_const_type
:
1676 READ_ULEB (uvalue
, data
, end
);
1677 printf ("%s: <0x%s> ",
1678 (op
== DW_OP_const_type
? "DW_OP_const_type"
1679 : "DW_OP_GNU_const_type"),
1680 dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1681 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1682 data
= display_block (data
, uvalue
, end
, ' ');
1684 case DW_OP_regval_type
:
1685 case DW_OP_GNU_regval_type
:
1686 READ_ULEB (uvalue
, data
, end
);
1687 printf ("%s: %s (%s)",
1688 (op
== DW_OP_regval_type
? "DW_OP_regval_type"
1689 : "DW_OP_GNU_regval_type"),
1690 dwarf_vmatoa ("u", uvalue
), regname (uvalue
, 1));
1691 READ_ULEB (uvalue
, data
, end
);
1692 printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1694 case DW_OP_deref_type
:
1695 case DW_OP_GNU_deref_type
:
1696 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1698 (op
== DW_OP_deref_type
? "DW_OP_deref_type"
1699 : "DW_OP_GNU_deref_type"),
1701 READ_ULEB (uvalue
, data
, end
);
1702 printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1705 case DW_OP_GNU_convert
:
1706 READ_ULEB (uvalue
, data
, end
);
1707 printf ("%s <0x%s>",
1708 (op
== DW_OP_convert
? "DW_OP_convert" : "DW_OP_GNU_convert"),
1709 dwarf_vmatoa ("x", uvalue
? cu_offset
+ uvalue
: 0));
1711 case DW_OP_reinterpret
:
1712 case DW_OP_GNU_reinterpret
:
1713 READ_ULEB (uvalue
, data
, end
);
1714 printf ("%s <0x%s>",
1715 (op
== DW_OP_reinterpret
? "DW_OP_reinterpret"
1716 : "DW_OP_GNU_reinterpret"),
1717 dwarf_vmatoa ("x", uvalue
? cu_offset
+ uvalue
: 0));
1719 case DW_OP_GNU_parameter_ref
:
1720 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1721 printf ("DW_OP_GNU_parameter_ref: <0x%s>",
1722 dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1724 case DW_OP_GNU_addr_index
:
1725 READ_ULEB (uvalue
, data
, end
);
1726 printf ("DW_OP_GNU_addr_index <0x%s>", dwarf_vmatoa ("x", uvalue
));
1728 case DW_OP_GNU_const_index
:
1729 READ_ULEB (uvalue
, data
, end
);
1730 printf ("DW_OP_GNU_const_index <0x%s>", dwarf_vmatoa ("x", uvalue
));
1732 case DW_OP_GNU_variable_value
:
1733 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1734 this ought to be an 8-byte wide computation. */
1735 if (dwarf_version
== -1)
1737 printf (_("(DW_OP_GNU_variable_value in frame info)"));
1738 /* No way to tell where the next op is, so just bail. */
1739 return need_frame_base
;
1741 if (dwarf_version
== 2)
1743 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1747 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1749 printf ("DW_OP_GNU_variable_value: <0x%s>", dwarf_vmatoa ("x", uvalue
));
1752 /* HP extensions. */
1753 case DW_OP_HP_is_value
:
1754 printf ("DW_OP_HP_is_value");
1755 /* FIXME: Is there data associated with this OP ? */
1757 case DW_OP_HP_fltconst4
:
1758 printf ("DW_OP_HP_fltconst4");
1759 /* FIXME: Is there data associated with this OP ? */
1761 case DW_OP_HP_fltconst8
:
1762 printf ("DW_OP_HP_fltconst8");
1763 /* FIXME: Is there data associated with this OP ? */
1765 case DW_OP_HP_mod_range
:
1766 printf ("DW_OP_HP_mod_range");
1767 /* FIXME: Is there data associated with this OP ? */
1769 case DW_OP_HP_unmod_range
:
1770 printf ("DW_OP_HP_unmod_range");
1771 /* FIXME: Is there data associated with this OP ? */
1774 printf ("DW_OP_HP_tls");
1775 /* FIXME: Is there data associated with this OP ? */
1778 /* PGI (STMicroelectronics) extensions. */
1779 case DW_OP_PGI_omp_thread_num
:
1780 /* Pushes the thread number for the current thread as it would be
1781 returned by the standard OpenMP library function:
1782 omp_get_thread_num(). The "current thread" is the thread for
1783 which the expression is being evaluated. */
1784 printf ("DW_OP_PGI_omp_thread_num");
1788 if (op
>= DW_OP_lo_user
1789 && op
<= DW_OP_hi_user
)
1790 printf (_("(User defined location op 0x%x)"), op
);
1792 printf (_("(Unknown location op 0x%x)"), op
);
1793 /* No way to tell where the next op is, so just bail. */
1794 return need_frame_base
;
1797 /* Separate the ops. */
1802 return need_frame_base
;
1805 /* Find the CU or TU set corresponding to the given CU_OFFSET.
1806 This is used for DWARF package files. */
1808 static struct cu_tu_set
*
1809 find_cu_tu_set_v2 (dwarf_vma cu_offset
, int do_types
)
1811 struct cu_tu_set
*p
;
1813 unsigned int dw_sect
;
1819 dw_sect
= DW_SECT_TYPES
;
1825 dw_sect
= DW_SECT_INFO
;
1829 if (p
->section_offsets
[dw_sect
] == cu_offset
)
1837 /* Add INC to HIGH_BITS:LOW_BITS. */
1839 add64 (dwarf_vma
* high_bits
, dwarf_vma
* low_bits
, dwarf_vma inc
)
1841 dwarf_vma tmp
= * low_bits
;
1845 /* FIXME: There is probably a better way of handling this:
1847 We need to cope with dwarf_vma being a 32-bit or 64-bit
1848 type. Plus regardless of its size LOW_BITS is meant to
1849 only hold 32-bits, so if there is overflow or wrap around
1850 we must propagate into HIGH_BITS. */
1851 if (tmp
< * low_bits
)
1855 else if (sizeof (tmp
) > 8
1866 fetch_alt_indirect_string (dwarf_vma offset
)
1870 if (! do_follow_links
)
1873 if (first_separate_info
== NULL
)
1874 return _("<no links available>");
1876 for (i
= first_separate_info
; i
!= NULL
; i
= i
->next
)
1878 struct dwarf_section
* section
;
1881 if (! load_debug_section (separate_debug_str
, i
->handle
))
1884 section
= &debug_displays
[separate_debug_str
].section
;
1886 if (section
->start
== NULL
)
1889 if (offset
>= section
->size
)
1892 ret
= (const char *) (section
->start
+ offset
);
1893 /* Unfortunately we cannot rely upon the .debug_str section ending with a
1894 NUL byte. Since our caller is expecting to receive a well formed C
1895 string we test for the lack of a terminating byte here. */
1896 if (strnlen ((const char *) ret
, section
->size
- offset
)
1897 == section
->size
- offset
)
1898 return _("<no NUL byte at end of alt .debug_str section>");
1903 warn (_("DW_FORM_GNU_strp_alt offset (%s) too big or no string sections available\n"),
1904 dwarf_vmatoa ("x", offset
));
1905 return _("<offset is too big>");
1909 get_AT_name (unsigned long attribute
)
1914 return "DW_AT value: 0";
1916 /* One value is shared by the MIPS and HP extensions: */
1917 if (attribute
== DW_AT_MIPS_fde
)
1918 return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable";
1920 name
= get_DW_AT_name (attribute
);
1924 static char buffer
[100];
1926 snprintf (buffer
, sizeof (buffer
), _("Unknown AT value: %lx"),
1935 add_dwo_info (const char * value
, dwarf_vma cu_offset
, dwo_type type
)
1937 dwo_info
* dwinfo
= xmalloc (sizeof * dwinfo
);
1939 dwinfo
->type
= type
;
1940 dwinfo
->value
= value
;
1941 dwinfo
->cu_offset
= cu_offset
;
1942 dwinfo
->next
= first_dwo_info
;
1943 first_dwo_info
= dwinfo
;
1947 add_dwo_name (const char * name
, dwarf_vma cu_offset
)
1949 add_dwo_info (name
, cu_offset
, DWO_NAME
);
1953 add_dwo_dir (const char * dir
, dwarf_vma cu_offset
)
1955 add_dwo_info (dir
, cu_offset
, DWO_DIR
);
1959 add_dwo_id (const char * id
, dwarf_vma cu_offset
)
1961 add_dwo_info (id
, cu_offset
, DWO_ID
);
1965 free_dwo_info (void)
1970 for (dwinfo
= first_dwo_info
; dwinfo
!= NULL
; dwinfo
= next
)
1972 next
= dwinfo
->next
;
1975 first_dwo_info
= NULL
;
1978 /* Ensure that START + UVALUE is less than END.
1979 Return an adjusted UVALUE if necessary to ensure this relationship. */
1981 static inline dwarf_vma
1982 check_uvalue (const unsigned char * start
,
1984 const unsigned char * end
)
1986 dwarf_vma max_uvalue
= end
- start
;
1988 /* See PR 17512: file: 008-103549-0.001:0.1.
1989 and PR 24829 for examples of where these tests are triggered. */
1990 if (uvalue
> max_uvalue
)
1992 warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue
);
1993 uvalue
= max_uvalue
;
1999 static unsigned char *
2000 skip_attr_bytes (unsigned long form
,
2001 unsigned char * data
,
2002 unsigned const char * end
,
2003 dwarf_vma pointer_size
,
2004 dwarf_vma offset_size
,
2006 dwarf_vma
* value_return
)
2008 dwarf_signed_vma svalue
;
2009 dwarf_vma uvalue
= 0;
2015 case DW_FORM_ref_addr
:
2016 if (dwarf_version
== 2)
2017 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
2018 else if (dwarf_version
> 2)
2019 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
2025 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
2029 case DW_FORM_line_strp
:
2030 case DW_FORM_sec_offset
:
2031 case DW_FORM_GNU_ref_alt
:
2032 case DW_FORM_GNU_strp_alt
:
2033 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
2036 case DW_FORM_flag_present
:
2044 case DW_FORM_addrx1
:
2045 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
2049 case DW_FORM_addrx3
:
2050 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 3, end
);
2056 case DW_FORM_addrx2
:
2057 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
2063 case DW_FORM_addrx4
:
2064 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
2068 READ_SLEB (svalue
, data
, end
);
2072 case DW_FORM_ref_udata
:
2074 case DW_FORM_GNU_str_index
:
2076 case DW_FORM_GNU_addr_index
:
2078 READ_ULEB (uvalue
, data
, end
);
2083 dwarf_vma high_bits
;
2085 SAFE_BYTE_GET64 (data
, &high_bits
, &uvalue
, end
);
2087 if (sizeof (uvalue
) > 4)
2088 uvalue
+= high_bits
<< 32;
2089 else if (high_bits
!= 0)
2091 /* FIXME: What to do ? */
2098 case DW_FORM_ref_sig8
:
2102 case DW_FORM_data16
:
2106 case DW_FORM_string
:
2107 data
+= strnlen ((char *) data
, end
- data
) + 1;
2111 case DW_FORM_exprloc
:
2112 READ_ULEB (uvalue
, data
, end
);
2116 case DW_FORM_block1
:
2117 SAFE_BYTE_GET (uvalue
, data
, 1, end
);
2121 case DW_FORM_block2
:
2122 SAFE_BYTE_GET (uvalue
, data
, 2, end
);
2126 case DW_FORM_block4
:
2127 SAFE_BYTE_GET (uvalue
, data
, 4, end
);
2131 case DW_FORM_indirect
:
2132 READ_ULEB (form
, data
, end
);
2133 if (form
== DW_FORM_implicit_const
)
2134 SKIP_ULEB (data
, end
);
2135 return skip_attr_bytes (form
, data
, end
, pointer_size
, offset_size
, dwarf_version
, value_return
);
2141 * value_return
= uvalue
;
2143 data
= (unsigned char *) end
;
2147 /* Given form FORM with value UVALUE, locate and return the abbreviation
2148 associated with it. */
2150 static abbrev_entry
*
2151 get_type_abbrev_from_form (unsigned long form
,
2152 unsigned long uvalue
,
2153 dwarf_vma cu_offset
,
2154 const struct dwarf_section
* section
,
2155 unsigned long * abbrev_num_return
,
2156 unsigned char ** data_return
,
2157 unsigned long * cu_offset_return
)
2159 unsigned long abbrev_number
;
2161 abbrev_entry
* entry
;
2162 unsigned char * data
;
2164 if (abbrev_num_return
!= NULL
)
2165 * abbrev_num_return
= 0;
2166 if (data_return
!= NULL
)
2167 * data_return
= NULL
;
2171 case DW_FORM_GNU_ref_alt
:
2172 case DW_FORM_ref_sig8
:
2173 /* FIXME: We are unable to handle this form at the moment. */
2176 case DW_FORM_ref_addr
:
2177 if (uvalue
>= section
->size
)
2179 warn (_("Unable to resolve ref_addr form: uvalue %lx > section size %lx (%s)\n"),
2180 uvalue
, (long) section
->size
, section
->name
);
2185 case DW_FORM_ref_sup4
:
2186 case DW_FORM_ref_sup8
:
2193 case DW_FORM_ref_udata
:
2194 if (uvalue
+ cu_offset
> section
->size
)
2196 warn (_("Unable to resolve ref form: uvalue %lx + cu_offset %lx > section size %lx\n"),
2197 uvalue
, (long) cu_offset
, (long) section
->size
);
2200 uvalue
+= cu_offset
;
2203 /* FIXME: Are there other DW_FORMs that can be used by types ? */
2206 warn (_("Unexpected form %lx encountered whilst finding abbreviation for type\n"), form
);
2210 data
= (unsigned char *) section
->start
+ uvalue
;
2211 map
= find_abbrev_map_by_offset (uvalue
);
2215 warn (_("Unable to find abbreviations for CU offset %#lx\n"), uvalue
);
2218 if (map
->list
== NULL
)
2220 warn (_("Empty abbreviation list encountered for CU offset %lx\n"), uvalue
);
2224 if (cu_offset_return
!= NULL
)
2226 if (form
== DW_FORM_ref_addr
)
2227 * cu_offset_return
= map
->start
;
2229 * cu_offset_return
= cu_offset
;
2232 READ_ULEB (abbrev_number
, data
, section
->start
+ section
->size
);
2234 for (entry
= map
->list
->first_abbrev
; entry
!= NULL
; entry
= entry
->next
)
2235 if (entry
->number
== abbrev_number
)
2238 if (abbrev_num_return
!= NULL
)
2239 * abbrev_num_return
= abbrev_number
;
2241 if (data_return
!= NULL
)
2242 * data_return
= data
;
2245 warn (_("Unable to find entry for abbreviation %lu\n"), abbrev_number
);
2250 /* Return IS_SIGNED set to TRUE if the type using abbreviation ENTRY
2251 can be determined to be a signed type. The data for ENTRY can be
2252 found starting at DATA. */
2255 get_type_signedness (abbrev_entry
*entry
,
2256 const struct dwarf_section
*section
,
2257 unsigned char *data
,
2258 unsigned const char *end
,
2259 dwarf_vma cu_offset
,
2260 dwarf_vma pointer_size
,
2261 dwarf_vma offset_size
,
2264 unsigned int nesting
)
2268 * is_signed
= false;
2270 #define MAX_NESTING 20
2271 if (nesting
> MAX_NESTING
)
2273 /* FIXME: Warn - or is this expected ?
2274 NB/ We need to avoid infinite recursion. */
2278 for (attr
= entry
->first_attr
;
2279 attr
!= NULL
&& attr
->attribute
;
2282 unsigned char * orig_data
= data
;
2283 dwarf_vma uvalue
= 0;
2285 data
= skip_attr_bytes (attr
->form
, data
, end
, pointer_size
,
2286 offset_size
, dwarf_version
, & uvalue
);
2290 switch (attr
->attribute
)
2292 case DW_AT_linkage_name
:
2296 if (attr
->form
== DW_FORM_strp
)
2297 printf (", %s", fetch_indirect_string (uvalue
));
2298 else if (attr
->form
== DW_FORM_string
)
2299 printf (", %s", orig_data
);
2306 abbrev_entry
* type_abbrev
;
2307 unsigned char * type_data
;
2308 unsigned long type_cu_offset
;
2310 type_abbrev
= get_type_abbrev_from_form (attr
->form
,
2314 NULL
/* abbrev num return */,
2317 if (type_abbrev
== NULL
)
2320 get_type_signedness (type_abbrev
, section
, type_data
, end
, type_cu_offset
,
2321 pointer_size
, offset_size
, dwarf_version
,
2322 is_signed
, nesting
+ 1);
2326 case DW_AT_encoding
:
2327 /* Determine signness. */
2330 case DW_ATE_address
:
2331 /* FIXME - some architectures have signed addresses. */
2332 case DW_ATE_boolean
:
2333 case DW_ATE_unsigned
:
2334 case DW_ATE_unsigned_char
:
2335 case DW_ATE_unsigned_fixed
:
2336 * is_signed
= false;
2340 case DW_ATE_complex_float
:
2343 case DW_ATE_signed_char
:
2344 case DW_ATE_imaginary_float
:
2345 case DW_ATE_decimal_float
:
2346 case DW_ATE_signed_fixed
:
2356 read_and_print_leb128 (unsigned char *data
,
2357 unsigned int *bytes_read
,
2358 unsigned const char *end
,
2362 dwarf_vma val
= read_leb128 (data
, end
, is_signed
, bytes_read
, &status
);
2364 report_leb_status (status
, __FILE__
, __LINE__
);
2366 printf ("%s", dwarf_vmatoa (is_signed
? "d" : "u", val
));
2370 display_discr_list (unsigned long form
,
2372 unsigned char * data
,
2373 unsigned const char * end
,
2378 printf ("[default]");
2385 case DW_FORM_block1
:
2386 case DW_FORM_block2
:
2387 case DW_FORM_block4
:
2388 /* Move data pointer back to the start of the byte array. */
2392 printf ("<corrupt>\n");
2393 warn (_("corrupt discr_list - not using a block form\n"));
2399 printf ("<corrupt>\n");
2400 warn (_("corrupt discr_list - block not long enough\n"));
2405 (level
> 0 && level
<= MAX_CU_NESTING
)
2406 ? level_type_signed
[level
- 1] : false;
2411 unsigned char discriminant
;
2412 unsigned int bytes_read
;
2414 SAFE_BYTE_GET (discriminant
, data
, 1, end
);
2418 assert (uvalue
> 0);
2419 switch (discriminant
)
2423 read_and_print_leb128 (data
, & bytes_read
, end
, is_signed
);
2424 assert (bytes_read
<= uvalue
&& bytes_read
> 0);
2425 uvalue
-= bytes_read
;
2431 read_and_print_leb128 (data
, & bytes_read
, end
, is_signed
);
2432 assert (bytes_read
<= uvalue
&& bytes_read
> 0);
2433 uvalue
-= bytes_read
;
2437 read_and_print_leb128 (data
, & bytes_read
, end
, is_signed
);
2438 assert (bytes_read
<= uvalue
&& bytes_read
> 0);
2439 uvalue
-= bytes_read
;
2444 printf ("<corrupt>\n");
2445 warn (_("corrupt discr_list - unrecognized discriminant byte %#x\n"),
2455 printf (")(signed)");
2457 printf (")(unsigned)");
2460 static unsigned char *
2461 read_and_display_attr_value (unsigned long attribute
,
2463 dwarf_signed_vma implicit_const
,
2464 unsigned char * start
,
2465 unsigned char * data
,
2466 unsigned char * end
,
2467 dwarf_vma cu_offset
,
2468 dwarf_vma pointer_size
,
2469 dwarf_vma offset_size
,
2471 debug_info
* debug_info_p
,
2473 struct dwarf_section
* section
,
2474 struct cu_tu_set
* this_set
,
2478 dwarf_signed_vma svalue
;
2479 dwarf_vma uvalue
= 0;
2480 unsigned char * block_start
= NULL
;
2481 unsigned char * orig_data
= data
;
2483 if (data
> end
|| (data
== end
&& form
!= DW_FORM_flag_present
))
2485 warn (_("Corrupt attribute\n"));
2489 if (do_wide
&& ! do_loc
)
2491 /* PR 26847: Display the name of the form. */
2492 const char * name
= get_FORM_name (form
);
2494 /* For convenience we skip the DW_FORM_ prefix to the name. */
2496 name
+= 8; /* strlen ("DW_FORM_") */
2497 printf ("%c(%s)", delimiter
, name
);
2505 case DW_FORM_ref_addr
:
2506 if (dwarf_version
== 2)
2507 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
2508 else if (dwarf_version
> 2)
2509 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
2511 error (_("Internal error: DW_FORM_ref_addr is not supported in DWARF version 1.\n"));
2515 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
2518 case DW_FORM_strp_sup
:
2520 case DW_FORM_line_strp
:
2521 case DW_FORM_sec_offset
:
2522 case DW_FORM_GNU_ref_alt
:
2523 case DW_FORM_GNU_strp_alt
:
2524 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
2527 case DW_FORM_flag_present
:
2535 case DW_FORM_addrx1
:
2536 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
2542 case DW_FORM_addrx2
:
2543 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
2547 case DW_FORM_addrx3
:
2548 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 3, end
);
2551 case DW_FORM_ref_sup4
:
2555 case DW_FORM_addrx4
:
2556 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
2560 READ_SLEB (svalue
, data
, end
);
2564 case DW_FORM_GNU_str_index
:
2566 case DW_FORM_ref_udata
:
2568 case DW_FORM_GNU_addr_index
:
2570 READ_ULEB (uvalue
, data
, end
);
2573 case DW_FORM_indirect
:
2574 READ_ULEB (form
, data
, end
);
2576 printf ("%c%s", delimiter
, get_FORM_name (form
));
2577 if (form
== DW_FORM_implicit_const
)
2578 READ_SLEB (implicit_const
, data
, end
);
2579 return read_and_display_attr_value (attribute
, form
, implicit_const
,
2581 cu_offset
, pointer_size
,
2582 offset_size
, dwarf_version
,
2583 debug_info_p
, do_loc
,
2584 section
, this_set
, delimiter
, level
);
2589 case DW_FORM_ref_addr
:
2591 printf ("%c<0x%s>", delimiter
, dwarf_vmatoa ("x", uvalue
));
2594 case DW_FORM_GNU_ref_alt
:
2598 /* We have already printed the form name. */
2599 printf ("%c<0x%s>", delimiter
, dwarf_vmatoa ("x", uvalue
));
2601 printf ("%c<alt 0x%s>", delimiter
, dwarf_vmatoa ("x", uvalue
));
2603 /* FIXME: Follow the reference... */
2609 case DW_FORM_ref_sup4
:
2610 case DW_FORM_ref_udata
:
2612 printf ("%c<0x%s>", delimiter
, dwarf_vmatoa ("x", uvalue
+ cu_offset
));
2617 case DW_FORM_sec_offset
:
2619 printf ("%c0x%s", delimiter
, dwarf_vmatoa ("x", uvalue
));
2622 case DW_FORM_flag_present
:
2629 printf ("%c%s", delimiter
, dwarf_vmatoa ("d", uvalue
));
2632 case DW_FORM_implicit_const
:
2634 printf ("%c%s", delimiter
, dwarf_vmatoa ("d", implicit_const
));
2637 case DW_FORM_ref_sup8
:
2642 dwarf_vma high_bits
;
2646 SAFE_BYTE_GET64 (data
, &high_bits
, &uvalue
, end
);
2648 if (form
== DW_FORM_ref8
)
2649 add64 (& high_bits
, & utmp
, cu_offset
);
2650 printf ("%c0x%s", delimiter
,
2651 dwarf_vmatoa64 (high_bits
, utmp
, buf
, sizeof (buf
)));
2654 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
2655 && num_debug_info_entries
== 0)
2657 if (sizeof (uvalue
) == 8)
2658 SAFE_BYTE_GET (uvalue
, data
, 8, end
);
2660 error (_("DW_FORM_data8 is unsupported when sizeof (dwarf_vma) != 8\n"));
2666 case DW_FORM_data16
:
2669 dwarf_vma left_high_bits
, left_low_bits
;
2670 dwarf_vma right_high_bits
, right_low_bits
;
2672 SAFE_BYTE_GET64 (data
, &left_high_bits
, &left_low_bits
, end
);
2673 SAFE_BYTE_GET64 (data
+ 8, &right_high_bits
, &right_low_bits
, end
);
2674 if (byte_get
== byte_get_little_endian
)
2677 left_high_bits
^= right_high_bits
;
2678 right_high_bits
^= left_high_bits
;
2679 left_high_bits
^= right_high_bits
;
2680 left_low_bits
^= right_low_bits
;
2681 right_low_bits
^= left_low_bits
;
2682 left_low_bits
^= right_low_bits
;
2684 printf (" 0x%08" DWARF_VMA_FMT
"x%08" DWARF_VMA_FMT
"x"
2685 "%08" DWARF_VMA_FMT
"x%08" DWARF_VMA_FMT
"x",
2686 left_high_bits
, left_low_bits
, right_high_bits
,
2692 case DW_FORM_string
:
2694 printf ("%c%.*s", delimiter
, (int) (end
- data
), data
);
2695 data
+= strnlen ((char *) data
, end
- data
) + 1;
2699 case DW_FORM_exprloc
:
2700 READ_ULEB (uvalue
, data
, end
);
2703 if (block_start
>= end
)
2705 warn (_("Block ends prematurely\n"));
2710 uvalue
= check_uvalue (block_start
, uvalue
, end
);
2713 data
= block_start
+ uvalue
;
2715 data
= display_block (block_start
, uvalue
, end
, delimiter
);
2718 case DW_FORM_block1
:
2719 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
2722 case DW_FORM_block2
:
2723 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
2726 case DW_FORM_block4
:
2727 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
2734 /* We have already displayed the form name. */
2735 printf (_("%c(offset: 0x%s): %s"), delimiter
,
2736 dwarf_vmatoa ("x", uvalue
),
2737 fetch_indirect_string (uvalue
));
2739 printf (_("%c(indirect string, offset: 0x%s): %s"), delimiter
,
2740 dwarf_vmatoa ("x", uvalue
),
2741 fetch_indirect_string (uvalue
));
2745 case DW_FORM_line_strp
:
2749 /* We have already displayed the form name. */
2750 printf (_("%c(offset: 0x%s): %s"), delimiter
,
2751 dwarf_vmatoa ("x", uvalue
),
2752 fetch_indirect_line_string (uvalue
));
2754 printf (_("%c(indirect line string, offset: 0x%s): %s"), delimiter
,
2755 dwarf_vmatoa ("x", uvalue
),
2756 fetch_indirect_line_string (uvalue
));
2760 case DW_FORM_GNU_str_index
:
2768 const char *suffix
= strrchr (section
->name
, '.');
2769 bool dwo
= suffix
&& strcmp (suffix
, ".dwo") == 0;
2772 /* We have already displayed the form name. */
2773 printf (_("%c(offset: 0x%s): %s"), delimiter
,
2774 dwarf_vmatoa ("x", uvalue
),
2775 fetch_indexed_string (uvalue
, this_set
, offset_size
, dwo
));
2777 printf (_("%c(indexed string: 0x%s): %s"), delimiter
,
2778 dwarf_vmatoa ("x", uvalue
),
2779 fetch_indexed_string (uvalue
, this_set
, offset_size
, dwo
));
2783 case DW_FORM_GNU_strp_alt
:
2787 /* We have already displayed the form name. */
2788 printf (_("%c(offset: 0x%s) %s"), delimiter
,
2789 dwarf_vmatoa ("x", uvalue
),
2790 fetch_alt_indirect_string (uvalue
));
2792 printf (_("%c(alt indirect string, offset: 0x%s) %s"), delimiter
,
2793 dwarf_vmatoa ("x", uvalue
),
2794 fetch_alt_indirect_string (uvalue
));
2798 case DW_FORM_indirect
:
2799 /* Handled above. */
2802 case DW_FORM_ref_sig8
:
2805 dwarf_vma high_bits
;
2808 SAFE_BYTE_GET64 (data
, &high_bits
, &uvalue
, end
);
2810 /* We have already displayed the form name. */
2811 printf ("%c: 0x%s", delimiter
,
2812 dwarf_vmatoa64 (high_bits
, uvalue
, buf
, sizeof (buf
)));
2814 printf ("%csignature: 0x%s", delimiter
,
2815 dwarf_vmatoa64 (high_bits
, uvalue
, buf
, sizeof (buf
)));
2820 case DW_FORM_GNU_addr_index
:
2822 case DW_FORM_addrx1
:
2823 case DW_FORM_addrx2
:
2824 case DW_FORM_addrx3
:
2825 case DW_FORM_addrx4
:
2831 if (debug_info_p
== NULL
)
2833 else if (debug_info_p
->addr_base
== DEBUG_INFO_UNAVAILABLE
)
2836 base
= debug_info_p
->addr_base
;
2838 offset
= base
+ uvalue
* pointer_size
;
2841 /* We have already displayed the form name. */
2842 printf (_("%c(index: 0x%s): %s"), delimiter
,
2843 dwarf_vmatoa ("x", uvalue
),
2844 fetch_indexed_value (offset
, pointer_size
));
2846 printf (_("%c(addr_index: 0x%s): %s"), delimiter
,
2847 dwarf_vmatoa ("x", uvalue
),
2848 fetch_indexed_value (offset
, pointer_size
));
2852 case DW_FORM_strp_sup
:
2854 printf ("%c<0x%s>", delimiter
, dwarf_vmatoa ("x", uvalue
+ cu_offset
));
2858 warn (_("Unrecognized form: 0x%lx\n"), form
);
2862 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
2863 && num_debug_info_entries
== 0
2864 && debug_info_p
!= NULL
)
2868 case DW_AT_frame_base
:
2869 have_frame_base
= 1;
2871 case DW_AT_location
:
2872 case DW_AT_GNU_locviews
:
2873 case DW_AT_string_length
:
2874 case DW_AT_return_addr
:
2875 case DW_AT_data_member_location
:
2876 case DW_AT_vtable_elem_location
:
2878 case DW_AT_static_link
:
2879 case DW_AT_use_location
:
2880 case DW_AT_call_value
:
2881 case DW_AT_GNU_call_site_value
:
2882 case DW_AT_call_data_value
:
2883 case DW_AT_GNU_call_site_data_value
:
2884 case DW_AT_call_target
:
2885 case DW_AT_GNU_call_site_target
:
2886 case DW_AT_call_target_clobbered
:
2887 case DW_AT_GNU_call_site_target_clobbered
:
2888 if ((dwarf_version
< 4
2889 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
2890 || form
== DW_FORM_sec_offset
)
2892 /* Process location list. */
2893 unsigned int lmax
= debug_info_p
->max_loc_offsets
;
2894 unsigned int num
= debug_info_p
->num_loc_offsets
;
2896 if (lmax
== 0 || num
>= lmax
)
2899 debug_info_p
->loc_offsets
= (dwarf_vma
*)
2900 xcrealloc (debug_info_p
->loc_offsets
,
2901 lmax
, sizeof (*debug_info_p
->loc_offsets
));
2902 debug_info_p
->loc_views
= (dwarf_vma
*)
2903 xcrealloc (debug_info_p
->loc_views
,
2904 lmax
, sizeof (*debug_info_p
->loc_views
));
2905 debug_info_p
->have_frame_base
= (int *)
2906 xcrealloc (debug_info_p
->have_frame_base
,
2907 lmax
, sizeof (*debug_info_p
->have_frame_base
));
2908 debug_info_p
->max_loc_offsets
= lmax
;
2910 if (this_set
!= NULL
)
2911 uvalue
+= this_set
->section_offsets
[DW_SECT_LOC
];
2912 debug_info_p
->have_frame_base
[num
] = have_frame_base
;
2913 if (attribute
!= DW_AT_GNU_locviews
)
2915 /* Corrupt DWARF info can produce more offsets than views.
2916 See PR 23062 for an example. */
2917 if (debug_info_p
->num_loc_offsets
2918 > debug_info_p
->num_loc_views
)
2919 warn (_("More location offset attributes than DW_AT_GNU_locview attributes\n"));
2922 debug_info_p
->loc_offsets
[num
] = uvalue
;
2923 debug_info_p
->num_loc_offsets
++;
2928 assert (debug_info_p
->num_loc_views
<= num
);
2929 num
= debug_info_p
->num_loc_views
;
2930 if (num
> debug_info_p
->num_loc_offsets
)
2931 warn (_("More DW_AT_GNU_locview attributes than location offset attributes\n"));
2934 debug_info_p
->loc_views
[num
] = uvalue
;
2935 debug_info_p
->num_loc_views
++;
2942 if (need_base_address
)
2943 debug_info_p
->base_address
= uvalue
;
2946 case DW_AT_GNU_addr_base
:
2947 case DW_AT_addr_base
:
2948 debug_info_p
->addr_base
= uvalue
;
2951 case DW_AT_GNU_ranges_base
:
2952 debug_info_p
->ranges_base
= uvalue
;
2956 if ((dwarf_version
< 4
2957 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
2958 || form
== DW_FORM_sec_offset
)
2960 /* Process range list. */
2961 unsigned int lmax
= debug_info_p
->max_range_lists
;
2962 unsigned int num
= debug_info_p
->num_range_lists
;
2964 if (lmax
== 0 || num
>= lmax
)
2967 debug_info_p
->range_lists
= (dwarf_vma
*)
2968 xcrealloc (debug_info_p
->range_lists
,
2969 lmax
, sizeof (*debug_info_p
->range_lists
));
2970 debug_info_p
->max_range_lists
= lmax
;
2972 debug_info_p
->range_lists
[num
] = uvalue
;
2973 debug_info_p
->num_range_lists
++;
2977 case DW_AT_GNU_dwo_name
:
2978 case DW_AT_dwo_name
:
2983 add_dwo_name ((const char *) fetch_indirect_string (uvalue
), cu_offset
);
2985 case DW_FORM_GNU_strp_alt
:
2986 add_dwo_name ((const char *) fetch_alt_indirect_string (uvalue
), cu_offset
);
2988 case DW_FORM_GNU_str_index
:
2994 add_dwo_name (fetch_indexed_string (uvalue
, this_set
, offset_size
, false), cu_offset
);
2996 case DW_FORM_string
:
2997 add_dwo_name ((const char *) orig_data
, cu_offset
);
3000 warn (_("Unsupported form (%s) for attribute %s\n"),
3001 get_FORM_name (form
), get_AT_name (attribute
));
3006 case DW_AT_comp_dir
:
3007 /* FIXME: Also extract a build-id in a CU/TU. */
3012 add_dwo_dir ((const char *) fetch_indirect_string (uvalue
), cu_offset
);
3014 case DW_FORM_GNU_strp_alt
:
3015 add_dwo_dir (fetch_alt_indirect_string (uvalue
), cu_offset
);
3017 case DW_FORM_line_strp
:
3018 add_dwo_dir ((const char *) fetch_indirect_line_string (uvalue
), cu_offset
);
3020 case DW_FORM_GNU_str_index
:
3026 add_dwo_dir (fetch_indexed_string (uvalue
, this_set
, offset_size
, false), cu_offset
);
3028 case DW_FORM_string
:
3029 add_dwo_dir ((const char *) orig_data
, cu_offset
);
3032 warn (_("Unsupported form (%s) for attribute %s\n"),
3033 get_FORM_name (form
), get_AT_name (attribute
));
3038 case DW_AT_GNU_dwo_id
:
3043 /* FIXME: Record the length of the ID as well ? */
3044 add_dwo_id ((const char *) (data
- 8), cu_offset
);
3047 warn (_("Unsupported form (%s) for attribute %s\n"),
3048 get_FORM_name (form
), get_AT_name (attribute
));
3058 if (do_loc
|| attribute
== 0)
3061 /* For some attributes we can display further information. */
3065 if (level
>= 0 && level
< MAX_CU_NESTING
3066 && uvalue
< (size_t) (end
- start
))
3068 bool is_signed
= false;
3069 abbrev_entry
*type_abbrev
;
3070 unsigned char *type_data
;
3071 unsigned long type_cu_offset
;
3073 type_abbrev
= get_type_abbrev_from_form (form
, uvalue
, cu_offset
,
3074 section
, NULL
, & type_data
, & type_cu_offset
);
3075 if (type_abbrev
!= NULL
)
3077 get_type_signedness (type_abbrev
, section
, type_data
, end
, type_cu_offset
,
3078 pointer_size
, offset_size
, dwarf_version
,
3081 level_type_signed
[level
] = is_signed
;
3089 case DW_INL_not_inlined
:
3090 printf (_("(not inlined)"));
3092 case DW_INL_inlined
:
3093 printf (_("(inlined)"));
3095 case DW_INL_declared_not_inlined
:
3096 printf (_("(declared as inline but ignored)"));
3098 case DW_INL_declared_inlined
:
3099 printf (_("(declared as inline and inlined)"));
3102 printf (_(" (Unknown inline attribute value: %s)"),
3103 dwarf_vmatoa ("x", uvalue
));
3108 case DW_AT_language
:
3112 /* Ordered by the numeric value of these constants. */
3113 case DW_LANG_C89
: printf ("(ANSI C)"); break;
3114 case DW_LANG_C
: printf ("(non-ANSI C)"); break;
3115 case DW_LANG_Ada83
: printf ("(Ada)"); break;
3116 case DW_LANG_C_plus_plus
: printf ("(C++)"); break;
3117 case DW_LANG_Cobol74
: printf ("(Cobol 74)"); break;
3118 case DW_LANG_Cobol85
: printf ("(Cobol 85)"); break;
3119 case DW_LANG_Fortran77
: printf ("(FORTRAN 77)"); break;
3120 case DW_LANG_Fortran90
: printf ("(Fortran 90)"); break;
3121 case DW_LANG_Pascal83
: printf ("(ANSI Pascal)"); break;
3122 case DW_LANG_Modula2
: printf ("(Modula 2)"); break;
3123 /* DWARF 2.1 values. */
3124 case DW_LANG_Java
: printf ("(Java)"); break;
3125 case DW_LANG_C99
: printf ("(ANSI C99)"); break;
3126 case DW_LANG_Ada95
: printf ("(ADA 95)"); break;
3127 case DW_LANG_Fortran95
: printf ("(Fortran 95)"); break;
3128 /* DWARF 3 values. */
3129 case DW_LANG_PLI
: printf ("(PLI)"); break;
3130 case DW_LANG_ObjC
: printf ("(Objective C)"); break;
3131 case DW_LANG_ObjC_plus_plus
: printf ("(Objective C++)"); break;
3132 case DW_LANG_UPC
: printf ("(Unified Parallel C)"); break;
3133 case DW_LANG_D
: printf ("(D)"); break;
3134 /* DWARF 4 values. */
3135 case DW_LANG_Python
: printf ("(Python)"); break;
3136 /* DWARF 5 values. */
3137 case DW_LANG_OpenCL
: printf ("(OpenCL)"); break;
3138 case DW_LANG_Go
: printf ("(Go)"); break;
3139 case DW_LANG_Modula3
: printf ("(Modula 3)"); break;
3140 case DW_LANG_Haskell
: printf ("(Haskell)"); break;
3141 case DW_LANG_C_plus_plus_03
: printf ("(C++03)"); break;
3142 case DW_LANG_C_plus_plus_11
: printf ("(C++11)"); break;
3143 case DW_LANG_OCaml
: printf ("(OCaml)"); break;
3144 case DW_LANG_Rust
: printf ("(Rust)"); break;
3145 case DW_LANG_C11
: printf ("(C11)"); break;
3146 case DW_LANG_Swift
: printf ("(Swift)"); break;
3147 case DW_LANG_Julia
: printf ("(Julia)"); break;
3148 case DW_LANG_Dylan
: printf ("(Dylan)"); break;
3149 case DW_LANG_C_plus_plus_14
: printf ("(C++14)"); break;
3150 case DW_LANG_Fortran03
: printf ("(Fortran 03)"); break;
3151 case DW_LANG_Fortran08
: printf ("(Fortran 08)"); break;
3152 case DW_LANG_RenderScript
: printf ("(RenderScript)"); break;
3153 /* MIPS extension. */
3154 case DW_LANG_Mips_Assembler
: printf ("(MIPS assembler)"); break;
3155 /* UPC extension. */
3156 case DW_LANG_Upc
: printf ("(Unified Parallel C)"); break;
3158 if (uvalue
>= DW_LANG_lo_user
&& uvalue
<= DW_LANG_hi_user
)
3159 printf (_("(implementation defined: %s)"),
3160 dwarf_vmatoa ("x", uvalue
));
3162 printf (_("(Unknown: %s)"), dwarf_vmatoa ("x", uvalue
));
3167 case DW_AT_encoding
:
3171 case DW_ATE_void
: printf ("(void)"); break;
3172 case DW_ATE_address
: printf ("(machine address)"); break;
3173 case DW_ATE_boolean
: printf ("(boolean)"); break;
3174 case DW_ATE_complex_float
: printf ("(complex float)"); break;
3175 case DW_ATE_float
: printf ("(float)"); break;
3176 case DW_ATE_signed
: printf ("(signed)"); break;
3177 case DW_ATE_signed_char
: printf ("(signed char)"); break;
3178 case DW_ATE_unsigned
: printf ("(unsigned)"); break;
3179 case DW_ATE_unsigned_char
: printf ("(unsigned char)"); break;
3180 /* DWARF 2.1 values: */
3181 case DW_ATE_imaginary_float
: printf ("(imaginary float)"); break;
3182 case DW_ATE_decimal_float
: printf ("(decimal float)"); break;
3183 /* DWARF 3 values: */
3184 case DW_ATE_packed_decimal
: printf ("(packed_decimal)"); break;
3185 case DW_ATE_numeric_string
: printf ("(numeric_string)"); break;
3186 case DW_ATE_edited
: printf ("(edited)"); break;
3187 case DW_ATE_signed_fixed
: printf ("(signed_fixed)"); break;
3188 case DW_ATE_unsigned_fixed
: printf ("(unsigned_fixed)"); break;
3189 /* DWARF 4 values: */
3190 case DW_ATE_UTF
: printf ("(unicode string)"); break;
3191 /* DWARF 5 values: */
3192 case DW_ATE_UCS
: printf ("(UCS)"); break;
3193 case DW_ATE_ASCII
: printf ("(ASCII)"); break;
3195 /* HP extensions: */
3196 case DW_ATE_HP_float80
: printf ("(HP_float80)"); break;
3197 case DW_ATE_HP_complex_float80
: printf ("(HP_complex_float80)"); break;
3198 case DW_ATE_HP_float128
: printf ("(HP_float128)"); break;
3199 case DW_ATE_HP_complex_float128
:printf ("(HP_complex_float128)"); break;
3200 case DW_ATE_HP_floathpintel
: printf ("(HP_floathpintel)"); break;
3201 case DW_ATE_HP_imaginary_float80
: printf ("(HP_imaginary_float80)"); break;
3202 case DW_ATE_HP_imaginary_float128
: printf ("(HP_imaginary_float128)"); break;
3205 if (uvalue
>= DW_ATE_lo_user
3206 && uvalue
<= DW_ATE_hi_user
)
3207 printf (_("(user defined type)"));
3209 printf (_("(unknown type)"));
3214 case DW_AT_accessibility
:
3218 case DW_ACCESS_public
: printf ("(public)"); break;
3219 case DW_ACCESS_protected
: printf ("(protected)"); break;
3220 case DW_ACCESS_private
: printf ("(private)"); break;
3222 printf (_("(unknown accessibility)"));
3227 case DW_AT_visibility
:
3231 case DW_VIS_local
: printf ("(local)"); break;
3232 case DW_VIS_exported
: printf ("(exported)"); break;
3233 case DW_VIS_qualified
: printf ("(qualified)"); break;
3234 default: printf (_("(unknown visibility)")); break;
3238 case DW_AT_endianity
:
3242 case DW_END_default
: printf ("(default)"); break;
3243 case DW_END_big
: printf ("(big)"); break;
3244 case DW_END_little
: printf ("(little)"); break;
3246 if (uvalue
>= DW_END_lo_user
&& uvalue
<= DW_END_hi_user
)
3247 printf (_("(user specified)"));
3249 printf (_("(unknown endianity)"));
3254 case DW_AT_virtuality
:
3258 case DW_VIRTUALITY_none
: printf ("(none)"); break;
3259 case DW_VIRTUALITY_virtual
: printf ("(virtual)"); break;
3260 case DW_VIRTUALITY_pure_virtual
:printf ("(pure_virtual)"); break;
3261 default: printf (_("(unknown virtuality)")); break;
3265 case DW_AT_identifier_case
:
3269 case DW_ID_case_sensitive
: printf ("(case_sensitive)"); break;
3270 case DW_ID_up_case
: printf ("(up_case)"); break;
3271 case DW_ID_down_case
: printf ("(down_case)"); break;
3272 case DW_ID_case_insensitive
: printf ("(case_insensitive)"); break;
3273 default: printf (_("(unknown case)")); break;
3277 case DW_AT_calling_convention
:
3281 case DW_CC_normal
: printf ("(normal)"); break;
3282 case DW_CC_program
: printf ("(program)"); break;
3283 case DW_CC_nocall
: printf ("(nocall)"); break;
3284 case DW_CC_pass_by_reference
: printf ("(pass by ref)"); break;
3285 case DW_CC_pass_by_value
: printf ("(pass by value)"); break;
3286 case DW_CC_GNU_renesas_sh
: printf ("(Rensas SH)"); break;
3287 case DW_CC_GNU_borland_fastcall_i386
: printf ("(Borland fastcall i386)"); break;
3289 if (uvalue
>= DW_CC_lo_user
3290 && uvalue
<= DW_CC_hi_user
)
3291 printf (_("(user defined)"));
3293 printf (_("(unknown convention)"));
3297 case DW_AT_ordering
:
3302 case -1: printf (_("(undefined)")); break;
3303 case 0: printf ("(row major)"); break;
3304 case 1: printf ("(column major)"); break;
3308 case DW_AT_decimal_sign
:
3312 case DW_DS_unsigned
: printf (_("(unsigned)")); break;
3313 case DW_DS_leading_overpunch
: printf (_("(leading overpunch)")); break;
3314 case DW_DS_trailing_overpunch
: printf (_("(trailing overpunch)")); break;
3315 case DW_DS_leading_separate
: printf (_("(leading separate)")); break;
3316 case DW_DS_trailing_separate
: printf (_("(trailing separate)")); break;
3317 default: printf (_("(unrecognised)")); break;
3321 case DW_AT_defaulted
:
3325 case DW_DEFAULTED_no
: printf (_("(no)")); break;
3326 case DW_DEFAULTED_in_class
: printf (_("(in class)")); break;
3327 case DW_DEFAULTED_out_of_class
: printf (_("(out of class)")); break;
3328 default: printf (_("(unrecognised)")); break;
3332 case DW_AT_discr_list
:
3334 display_discr_list (form
, uvalue
, data
, end
, level
);
3337 case DW_AT_frame_base
:
3338 have_frame_base
= 1;
3340 case DW_AT_location
:
3341 case DW_AT_string_length
:
3342 case DW_AT_return_addr
:
3343 case DW_AT_data_member_location
:
3344 case DW_AT_vtable_elem_location
:
3346 case DW_AT_static_link
:
3347 case DW_AT_use_location
:
3348 case DW_AT_call_value
:
3349 case DW_AT_GNU_call_site_value
:
3350 case DW_AT_call_data_value
:
3351 case DW_AT_GNU_call_site_data_value
:
3352 case DW_AT_call_target
:
3353 case DW_AT_GNU_call_site_target
:
3354 case DW_AT_call_target_clobbered
:
3355 case DW_AT_GNU_call_site_target_clobbered
:
3356 if ((dwarf_version
< 4
3357 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
3358 || form
== DW_FORM_sec_offset
)
3359 printf (_(" (location list)"));
3361 case DW_AT_allocated
:
3362 case DW_AT_associated
:
3363 case DW_AT_data_location
:
3365 case DW_AT_upper_bound
:
3366 case DW_AT_lower_bound
:
3369 int need_frame_base
;
3372 need_frame_base
= decode_location_expression (block_start
,
3377 cu_offset
, section
);
3379 if (need_frame_base
&& !have_frame_base
)
3380 printf (_(" [without DW_AT_frame_base]"));
3384 case DW_AT_data_bit_offset
:
3385 case DW_AT_byte_size
:
3386 case DW_AT_bit_size
:
3387 case DW_AT_string_length_byte_size
:
3388 case DW_AT_string_length_bit_size
:
3389 case DW_AT_bit_stride
:
3390 if (form
== DW_FORM_exprloc
)
3393 (void) decode_location_expression (block_start
, pointer_size
,
3394 offset_size
, dwarf_version
,
3395 uvalue
, cu_offset
, section
);
3402 unsigned long abbrev_number
;
3403 abbrev_entry
*entry
;
3405 entry
= get_type_abbrev_from_form (form
, uvalue
, cu_offset
,
3406 section
, & abbrev_number
, NULL
, NULL
);
3409 if (form
!= DW_FORM_GNU_ref_alt
)
3410 warn (_("Offset %s used as value for DW_AT_import attribute of DIE at offset 0x%lx is too big.\n"),
3411 dwarf_vmatoa ("x", uvalue
),
3412 (unsigned long) (orig_data
- section
->start
));
3416 printf (_("\t[Abbrev Number: %ld"), abbrev_number
);
3417 printf (" (%s)", get_TAG_name (entry
->tag
));
3430 static unsigned char *
3431 read_and_display_attr (unsigned long attribute
,
3433 dwarf_signed_vma implicit_const
,
3434 unsigned char * start
,
3435 unsigned char * data
,
3436 unsigned char * end
,
3437 dwarf_vma cu_offset
,
3438 dwarf_vma pointer_size
,
3439 dwarf_vma offset_size
,
3441 debug_info
* debug_info_p
,
3443 struct dwarf_section
* section
,
3444 struct cu_tu_set
* this_set
,
3448 printf (" %-18s:", get_AT_name (attribute
));
3449 data
= read_and_display_attr_value (attribute
, form
, implicit_const
,
3451 cu_offset
, pointer_size
, offset_size
,
3452 dwarf_version
, debug_info_p
,
3453 do_loc
, section
, this_set
, ' ', level
);
3459 /* Like load_debug_section, but if the ordinary call fails, and we are
3460 following debug links, then attempt to load the requested section
3461 from one of the separate debug info files. */
3464 load_debug_section_with_follow (enum dwarf_section_display_enum sec_enum
,
3467 if (load_debug_section (sec_enum
, handle
))
3469 if (debug_displays
[sec_enum
].section
.filename
== NULL
)
3471 /* See if we can associate a filename with this section. */
3474 for (i
= first_separate_info
; i
!= NULL
; i
= i
->next
)
3475 if (i
->handle
== handle
)
3477 debug_displays
[sec_enum
].section
.filename
= i
->filename
;
3485 if (do_follow_links
)
3489 for (i
= first_separate_info
; i
!= NULL
; i
= i
->next
)
3491 if (load_debug_section (sec_enum
, i
->handle
))
3493 debug_displays
[sec_enum
].section
.filename
= i
->filename
;
3495 /* FIXME: We should check to see if any of the remaining debug info
3496 files also contain this section, and, umm, do something about it. */
3506 introduce (struct dwarf_section
* section
, bool raw
)
3510 if (do_follow_links
&& section
->filename
)
3511 printf (_("Raw dump of debug contents of section %s (loaded from %s):\n\n"),
3512 section
->name
, section
->filename
);
3514 printf (_("Raw dump of debug contents of section %s:\n\n"), section
->name
);
3518 if (do_follow_links
&& section
->filename
)
3519 printf (_("Contents of the %s section (loaded from %s):\n\n"),
3520 section
->name
, section
->filename
);
3522 printf (_("Contents of the %s section:\n\n"), section
->name
);
3526 /* Process the contents of a .debug_info section.
3527 If do_loc is TRUE then we are scanning for location lists and dwo tags
3528 and we do not want to display anything to the user.
3529 If do_types is TRUE, we are processing a .debug_types section instead of
3530 a .debug_info section.
3531 The information displayed is restricted by the values in DWARF_START_DIE
3532 and DWARF_CUTOFF_LEVEL.
3533 Returns TRUE upon success. Otherwise an error or warning message is
3534 printed and FALSE is returned. */
3537 process_debug_info (struct dwarf_section
* section
,
3539 enum dwarf_section_display_enum abbrev_sec
,
3543 unsigned char *start
= section
->start
;
3544 unsigned char *end
= start
+ section
->size
;
3545 unsigned char *section_begin
;
3547 unsigned int num_units
= 0;
3549 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
3550 && num_debug_info_entries
== 0
3555 /* First scan the section to get the number of comp units. */
3556 for (section_begin
= start
, num_units
= 0; section_begin
< end
;
3559 /* Read the first 4 bytes. For a 32-bit DWARF section, this
3560 will be the length. For a 64-bit DWARF section, it'll be
3561 the escape code 0xffffffff followed by an 8 byte length. */
3562 SAFE_BYTE_GET (length
, section_begin
, 4, end
);
3564 if (length
== 0xffffffff)
3566 SAFE_BYTE_GET (length
, section_begin
+ 4, 8, end
);
3567 section_begin
+= length
+ 12;
3569 else if (length
>= 0xfffffff0 && length
< 0xffffffff)
3571 warn (_("Reserved length value (0x%s) found in section %s\n"),
3572 dwarf_vmatoa ("x", length
), section
->name
);
3576 section_begin
+= length
+ 4;
3578 /* Negative values are illegal, they may even cause infinite
3579 looping. This can happen if we can't accurately apply
3580 relocations to an object file, or if the file is corrupt. */
3581 if ((signed long) length
<= 0 || section_begin
< start
)
3583 warn (_("Corrupt unit length (0x%s) found in section %s\n"),
3584 dwarf_vmatoa ("x", length
), section
->name
);
3591 error (_("No comp units in %s section ?\n"), section
->name
);
3595 /* Then allocate an array to hold the information. */
3596 debug_information
= (debug_info
*) cmalloc (num_units
,
3597 sizeof (* debug_information
));
3598 if (debug_information
== NULL
)
3600 error (_("Not enough memory for a debug info array of %u entries\n"),
3602 alloc_num_debug_info_entries
= num_debug_info_entries
= 0;
3606 /* PR 17531: file: 92ca3797.
3607 We cannot rely upon the debug_information array being initialised
3608 before it is used. A corrupt file could easily contain references
3609 to a unit for which information has not been made available. So
3610 we ensure that the array is zeroed here. */
3611 memset (debug_information
, 0, num_units
* sizeof (*debug_information
));
3613 alloc_num_debug_info_entries
= num_units
;
3618 load_debug_section_with_follow (str
, file
);
3619 load_debug_section_with_follow (line_str
, file
);
3620 load_debug_section_with_follow (str_dwo
, file
);
3621 load_debug_section_with_follow (str_index
, file
);
3622 load_debug_section_with_follow (str_index_dwo
, file
);
3623 load_debug_section_with_follow (debug_addr
, file
);
3626 load_debug_section_with_follow (abbrev_sec
, file
);
3627 if (debug_displays
[abbrev_sec
].section
.start
== NULL
)
3629 warn (_("Unable to locate %s section!\n"),
3630 debug_displays
[abbrev_sec
].section
.uncompressed_name
);
3634 if (!do_loc
&& dwarf_start_die
== 0)
3635 introduce (section
, false);
3637 free_all_abbrevs ();
3638 free (cu_abbrev_map
);
3639 cu_abbrev_map
= NULL
;
3640 next_free_abbrev_map_entry
= 0;
3642 /* In order to be able to resolve DW_FORM_ref_attr forms we need
3643 to load *all* of the abbrevs for all CUs in this .debug_info
3644 section. This does effectively mean that we (partially) read
3645 every CU header twice. */
3646 for (section_begin
= start
; start
< end
;)
3648 DWARF2_Internal_CompUnit compunit
;
3649 unsigned char * hdrptr
;
3650 dwarf_vma abbrev_base
;
3652 dwarf_vma cu_offset
;
3653 unsigned int offset_size
;
3654 unsigned int initial_length_size
;
3655 struct cu_tu_set
* this_set
;
3660 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 4, end
);
3662 if (compunit
.cu_length
== 0xffffffff)
3664 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 8, end
);
3666 initial_length_size
= 12;
3671 initial_length_size
= 4;
3674 SAFE_BYTE_GET_AND_INC (compunit
.cu_version
, hdrptr
, 2, end
);
3676 cu_offset
= start
- section_begin
;
3678 this_set
= find_cu_tu_set_v2 (cu_offset
, do_types
);
3680 if (compunit
.cu_version
< 5)
3682 compunit
.cu_unit_type
= DW_UT_compile
;
3683 /* Initialize it due to a false compiler warning. */
3684 compunit
.cu_pointer_size
= -1;
3688 SAFE_BYTE_GET_AND_INC (compunit
.cu_unit_type
, hdrptr
, 1, end
);
3689 do_types
= (compunit
.cu_unit_type
== DW_UT_type
);
3691 SAFE_BYTE_GET_AND_INC (compunit
.cu_pointer_size
, hdrptr
, 1, end
);
3694 SAFE_BYTE_GET_AND_INC (compunit
.cu_abbrev_offset
, hdrptr
, offset_size
, end
);
3696 if (compunit
.cu_unit_type
== DW_UT_split_compile
3697 || compunit
.cu_unit_type
== DW_UT_skeleton
)
3700 SAFE_BYTE_GET_AND_INC (dwo_id
, hdrptr
, 8, end
);
3703 if (this_set
== NULL
)
3706 abbrev_size
= debug_displays
[abbrev_sec
].section
.size
;
3710 abbrev_base
= this_set
->section_offsets
[DW_SECT_ABBREV
];
3711 abbrev_size
= this_set
->section_sizes
[DW_SECT_ABBREV
];
3714 list
= find_abbrev_list_by_abbrev_offset (abbrev_base
,
3715 compunit
.cu_abbrev_offset
);
3718 unsigned char * next
;
3720 list
= new_abbrev_list (abbrev_base
,
3721 compunit
.cu_abbrev_offset
);
3722 next
= process_abbrev_set (&debug_displays
[abbrev_sec
].section
,
3723 abbrev_base
, abbrev_size
,
3724 compunit
.cu_abbrev_offset
, list
);
3725 list
->start_of_next_abbrevs
= next
;
3728 start
= section_begin
+ cu_offset
+ compunit
.cu_length
3729 + initial_length_size
;
3730 record_abbrev_list_for_cu (cu_offset
, start
- section_begin
, list
);
3733 for (start
= section_begin
, unit
= 0; start
< end
; unit
++)
3735 DWARF2_Internal_CompUnit compunit
;
3736 unsigned char *hdrptr
;
3737 unsigned char *tags
;
3738 int level
, last_level
, saved_level
;
3739 dwarf_vma cu_offset
;
3740 unsigned long sec_off
;
3741 unsigned int offset_size
;
3742 unsigned int initial_length_size
;
3743 dwarf_vma signature_high
= 0;
3744 dwarf_vma signature_low
= 0;
3745 dwarf_vma type_offset
= 0;
3746 struct cu_tu_set
*this_set
;
3747 dwarf_vma abbrev_base
;
3749 abbrev_list
* list
= NULL
;
3753 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 4, end
);
3755 if (compunit
.cu_length
== 0xffffffff)
3757 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 8, end
);
3759 initial_length_size
= 12;
3764 initial_length_size
= 4;
3767 SAFE_BYTE_GET_AND_INC (compunit
.cu_version
, hdrptr
, 2, end
);
3769 cu_offset
= start
- section_begin
;
3771 this_set
= find_cu_tu_set_v2 (cu_offset
, do_types
);
3773 if (compunit
.cu_version
< 5)
3775 compunit
.cu_unit_type
= DW_UT_compile
;
3776 /* Initialize it due to a false compiler warning. */
3777 compunit
.cu_pointer_size
= -1;
3781 SAFE_BYTE_GET_AND_INC (compunit
.cu_unit_type
, hdrptr
, 1, end
);
3782 do_types
= (compunit
.cu_unit_type
== DW_UT_type
);
3784 SAFE_BYTE_GET_AND_INC (compunit
.cu_pointer_size
, hdrptr
, 1, end
);
3787 SAFE_BYTE_GET_AND_INC (compunit
.cu_abbrev_offset
, hdrptr
, offset_size
, end
);
3789 if (this_set
== NULL
)
3792 abbrev_size
= debug_displays
[abbrev_sec
].section
.size
;
3796 abbrev_base
= this_set
->section_offsets
[DW_SECT_ABBREV
];
3797 abbrev_size
= this_set
->section_sizes
[DW_SECT_ABBREV
];
3800 if (compunit
.cu_version
< 5)
3801 SAFE_BYTE_GET_AND_INC (compunit
.cu_pointer_size
, hdrptr
, 1, end
);
3803 bool do_dwo_id
= false;
3804 uint64_t dwo_id
= 0;
3805 if (compunit
.cu_unit_type
== DW_UT_split_compile
3806 || compunit
.cu_unit_type
== DW_UT_skeleton
)
3808 SAFE_BYTE_GET_AND_INC (dwo_id
, hdrptr
, 8, end
);
3812 /* PR 17512: file: 001-108546-0.001:0.1. */
3813 if (compunit
.cu_pointer_size
< 2 || compunit
.cu_pointer_size
> 8)
3815 warn (_("Invalid pointer size (%d) in compunit header, using %d instead\n"),
3816 compunit
.cu_pointer_size
, offset_size
);
3817 compunit
.cu_pointer_size
= offset_size
;
3822 SAFE_BYTE_GET64 (hdrptr
, &signature_high
, &signature_low
, end
);
3824 SAFE_BYTE_GET_AND_INC (type_offset
, hdrptr
, offset_size
, end
);
3827 if (dwarf_start_die
> (cu_offset
+ compunit
.cu_length
3828 + initial_length_size
))
3830 start
= section_begin
+ cu_offset
+ compunit
.cu_length
3831 + initial_length_size
;
3835 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
3836 && num_debug_info_entries
== 0
3837 && alloc_num_debug_info_entries
> unit
3840 debug_information
[unit
].cu_offset
= cu_offset
;
3841 debug_information
[unit
].pointer_size
3842 = compunit
.cu_pointer_size
;
3843 debug_information
[unit
].offset_size
= offset_size
;
3844 debug_information
[unit
].dwarf_version
= compunit
.cu_version
;
3845 debug_information
[unit
].base_address
= 0;
3846 debug_information
[unit
].addr_base
= DEBUG_INFO_UNAVAILABLE
;
3847 debug_information
[unit
].ranges_base
= DEBUG_INFO_UNAVAILABLE
;
3848 debug_information
[unit
].loc_offsets
= NULL
;
3849 debug_information
[unit
].have_frame_base
= NULL
;
3850 debug_information
[unit
].max_loc_offsets
= 0;
3851 debug_information
[unit
].num_loc_offsets
= 0;
3852 debug_information
[unit
].range_lists
= NULL
;
3853 debug_information
[unit
].max_range_lists
= 0;
3854 debug_information
[unit
].num_range_lists
= 0;
3857 if (!do_loc
&& dwarf_start_die
== 0)
3859 printf (_(" Compilation Unit @ offset 0x%s:\n"),
3860 dwarf_vmatoa ("x", cu_offset
));
3861 printf (_(" Length: 0x%s (%s)\n"),
3862 dwarf_vmatoa ("x", compunit
.cu_length
),
3863 offset_size
== 8 ? "64-bit" : "32-bit");
3864 printf (_(" Version: %d\n"), compunit
.cu_version
);
3865 if (compunit
.cu_version
>= 5)
3867 const char *name
= get_DW_UT_name (compunit
.cu_unit_type
);
3869 printf (_(" Unit Type: %s (%x)\n"),
3870 name
? name
: "???",
3871 compunit
.cu_unit_type
);
3873 printf (_(" Abbrev Offset: 0x%s\n"),
3874 dwarf_vmatoa ("x", compunit
.cu_abbrev_offset
));
3875 printf (_(" Pointer Size: %d\n"), compunit
.cu_pointer_size
);
3880 printf (_(" Signature: 0x%s\n"),
3881 dwarf_vmatoa64 (signature_high
, signature_low
,
3882 buf
, sizeof (buf
)));
3883 printf (_(" Type Offset: 0x%s\n"),
3884 dwarf_vmatoa ("x", type_offset
));
3887 printf (_(" DWO ID: 0x%s\n"), dwarf_vmatoa ("x", dwo_id
));
3888 if (this_set
!= NULL
)
3890 dwarf_vma
*offsets
= this_set
->section_offsets
;
3891 size_t *sizes
= this_set
->section_sizes
;
3893 printf (_(" Section contributions:\n"));
3894 printf (_(" .debug_abbrev.dwo: 0x%s 0x%s\n"),
3895 dwarf_vmatoa ("x", offsets
[DW_SECT_ABBREV
]),
3896 dwarf_vmatoa ("x", sizes
[DW_SECT_ABBREV
]));
3897 printf (_(" .debug_line.dwo: 0x%s 0x%s\n"),
3898 dwarf_vmatoa ("x", offsets
[DW_SECT_LINE
]),
3899 dwarf_vmatoa ("x", sizes
[DW_SECT_LINE
]));
3900 printf (_(" .debug_loc.dwo: 0x%s 0x%s\n"),
3901 dwarf_vmatoa ("x", offsets
[DW_SECT_LOC
]),
3902 dwarf_vmatoa ("x", sizes
[DW_SECT_LOC
]));
3903 printf (_(" .debug_str_offsets.dwo: 0x%s 0x%s\n"),
3904 dwarf_vmatoa ("x", offsets
[DW_SECT_STR_OFFSETS
]),
3905 dwarf_vmatoa ("x", sizes
[DW_SECT_STR_OFFSETS
]));
3909 sec_off
= cu_offset
+ initial_length_size
;
3910 if (sec_off
+ compunit
.cu_length
< sec_off
3911 || sec_off
+ compunit
.cu_length
> section
->size
)
3913 warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"),
3915 (unsigned long) cu_offset
,
3916 dwarf_vmatoa ("x", compunit
.cu_length
));
3922 start
+= compunit
.cu_length
+ initial_length_size
;
3924 if (compunit
.cu_version
< 2 || compunit
.cu_version
> 5)
3926 warn (_("CU at offset %s contains corrupt or "
3927 "unsupported version number: %d.\n"),
3928 dwarf_vmatoa ("x", cu_offset
), compunit
.cu_version
);
3932 if (compunit
.cu_unit_type
!= DW_UT_compile
3933 && compunit
.cu_unit_type
!= DW_UT_partial
3934 && compunit
.cu_unit_type
!= DW_UT_type
3935 && compunit
.cu_unit_type
!= DW_UT_split_compile
3936 && compunit
.cu_unit_type
!= DW_UT_skeleton
)
3938 warn (_("CU at offset %s contains corrupt or "
3939 "unsupported unit type: %d.\n"),
3940 dwarf_vmatoa ("x", cu_offset
), compunit
.cu_unit_type
);
3944 /* Process the abbrevs used by this compilation unit. */
3945 list
= find_abbrev_list_by_abbrev_offset (abbrev_base
,
3946 compunit
.cu_abbrev_offset
);
3949 unsigned char *next
;
3951 list
= new_abbrev_list (abbrev_base
,
3952 compunit
.cu_abbrev_offset
);
3953 next
= process_abbrev_set (&debug_displays
[abbrev_sec
].section
,
3954 abbrev_base
, abbrev_size
,
3955 compunit
.cu_abbrev_offset
, list
);
3956 list
->start_of_next_abbrevs
= next
;
3962 while (tags
< start
)
3964 unsigned long abbrev_number
;
3965 unsigned long die_offset
;
3966 abbrev_entry
*entry
;
3968 int do_printing
= 1;
3970 die_offset
= tags
- section_begin
;
3972 READ_ULEB (abbrev_number
, tags
, start
);
3974 /* A null DIE marks the end of a list of siblings or it may also be
3975 a section padding. */
3976 if (abbrev_number
== 0)
3978 /* Check if it can be a section padding for the last CU. */
3979 if (level
== 0 && start
== end
)
3983 for (chk
= tags
; chk
< start
; chk
++)
3990 if (!do_loc
&& die_offset
>= dwarf_start_die
3991 && (dwarf_cutoff_level
== -1
3992 || level
< dwarf_cutoff_level
))
3993 printf (_(" <%d><%lx>: Abbrev Number: 0\n"),
3999 static unsigned num_bogus_warns
= 0;
4001 if (num_bogus_warns
< 3)
4003 warn (_("Bogus end-of-siblings marker detected at offset %lx in %s section\n"),
4004 die_offset
, section
->name
);
4006 if (num_bogus_warns
== 3)
4007 warn (_("Further warnings about bogus end-of-sibling markers suppressed\n"));
4010 if (dwarf_start_die
!= 0 && level
< saved_level
)
4017 if (dwarf_start_die
!= 0 && die_offset
< dwarf_start_die
)
4021 if (dwarf_start_die
!= 0 && die_offset
== dwarf_start_die
)
4022 saved_level
= level
;
4023 do_printing
= (dwarf_cutoff_level
== -1
4024 || level
< dwarf_cutoff_level
);
4026 printf (_(" <%d><%lx>: Abbrev Number: %lu"),
4027 level
, die_offset
, abbrev_number
);
4028 else if (dwarf_cutoff_level
== -1
4029 || last_level
< dwarf_cutoff_level
)
4030 printf (_(" <%d><%lx>: ...\n"), level
, die_offset
);
4035 /* Scan through the abbreviation list until we reach the
4040 for (entry
= list
->first_abbrev
; entry
!= NULL
; entry
= entry
->next
)
4041 if (entry
->number
== abbrev_number
)
4046 if (!do_loc
&& do_printing
)
4051 warn (_("DIE at offset 0x%lx refers to abbreviation number %lu which does not exist\n"),
4052 die_offset
, abbrev_number
);
4056 if (!do_loc
&& do_printing
)
4057 printf (" (%s)\n", get_TAG_name (entry
->tag
));
4062 need_base_address
= 0;
4064 case DW_TAG_compile_unit
:
4065 need_base_address
= 1;
4066 need_dwo_info
= do_loc
;
4068 case DW_TAG_entry_point
:
4069 case DW_TAG_subprogram
:
4070 need_base_address
= 0;
4071 /* Assuming that there is no DW_AT_frame_base. */
4072 have_frame_base
= 0;
4076 debug_info
*debug_info_p
=
4077 (debug_information
&& unit
< alloc_num_debug_info_entries
)
4078 ? debug_information
+ unit
: NULL
;
4080 assert (!debug_info_p
4081 || (debug_info_p
->num_loc_offsets
4082 == debug_info_p
->num_loc_views
));
4084 for (attr
= entry
->first_attr
;
4085 attr
&& attr
->attribute
;
4088 if (! do_loc
&& do_printing
)
4089 /* Show the offset from where the tag was extracted. */
4090 printf (" <%lx>", (unsigned long)(tags
- section_begin
));
4091 tags
= read_and_display_attr (attr
->attribute
,
4093 attr
->implicit_const
,
4098 compunit
.cu_pointer_size
,
4100 compunit
.cu_version
,
4102 do_loc
|| ! do_printing
,
4108 /* If a locview attribute appears before a location one,
4109 make sure we don't associate it with an earlier
4112 switch (debug_info_p
->num_loc_offsets
- debug_info_p
->num_loc_views
)
4115 debug_info_p
->loc_views
[debug_info_p
->num_loc_views
] = vm1
;
4116 debug_info_p
->num_loc_views
++;
4117 assert (debug_info_p
->num_loc_views
4118 == debug_info_p
->num_loc_offsets
);
4125 warn(_("DIE has locviews without loclist\n"));
4126 debug_info_p
->num_loc_views
--;
4133 if (entry
->children
)
4138 /* Set num_debug_info_entries here so that it can be used to check if
4139 we need to process .debug_loc and .debug_ranges sections. */
4140 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
4141 && num_debug_info_entries
== 0
4144 if (num_units
> alloc_num_debug_info_entries
)
4145 num_debug_info_entries
= alloc_num_debug_info_entries
;
4147 num_debug_info_entries
= num_units
;
4156 /* Locate and scan the .debug_info section in the file and record the pointer
4157 sizes and offsets for the compilation units in it. Usually an executable
4158 will have just one pointer size, but this is not guaranteed, and so we try
4159 not to make any assumptions. Returns zero upon failure, or the number of
4160 compilation units upon success. */
4163 load_debug_info (void * file
)
4165 /* If we have already tried and failed to load the .debug_info
4166 section then do not bother to repeat the task. */
4167 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
4170 /* If we already have the information there is nothing else to do. */
4171 if (num_debug_info_entries
> 0)
4172 return num_debug_info_entries
;
4174 /* If this is a DWARF package file, load the CU and TU indexes. */
4175 (void) load_cu_tu_indexes (file
);
4177 if (load_debug_section_with_follow (info
, file
)
4178 && process_debug_info (&debug_displays
[info
].section
, file
, abbrev
, true, false))
4179 return num_debug_info_entries
;
4181 if (load_debug_section_with_follow (info_dwo
, file
)
4182 && process_debug_info (&debug_displays
[info_dwo
].section
, file
,
4183 abbrev_dwo
, true, false))
4184 return num_debug_info_entries
;
4186 num_debug_info_entries
= DEBUG_INFO_UNAVAILABLE
;
4190 /* Read a DWARF .debug_line section header starting at DATA.
4191 Upon success returns an updated DATA pointer and the LINFO
4192 structure and the END_OF_SEQUENCE pointer will be filled in.
4193 Otherwise returns NULL. */
4195 static unsigned char *
4196 read_debug_line_header (struct dwarf_section
* section
,
4197 unsigned char * data
,
4198 unsigned char * end
,
4199 DWARF2_Internal_LineInfo
* linfo
,
4200 unsigned char ** end_of_sequence
)
4202 unsigned char *hdrptr
;
4203 unsigned int initial_length_size
;
4205 /* Extract information from the Line Number Program Header.
4206 (section 6.2.4 in the Dwarf3 doc). */
4209 /* Get and check the length of the block. */
4210 SAFE_BYTE_GET_AND_INC (linfo
->li_length
, hdrptr
, 4, end
);
4212 if (linfo
->li_length
== 0xffffffff)
4214 /* This section is 64-bit DWARF 3. */
4215 SAFE_BYTE_GET_AND_INC (linfo
->li_length
, hdrptr
, 8, end
);
4216 linfo
->li_offset_size
= 8;
4217 initial_length_size
= 12;
4221 linfo
->li_offset_size
= 4;
4222 initial_length_size
= 4;
4225 if (linfo
->li_length
+ initial_length_size
> section
->size
)
4227 /* If the length field has a relocation against it, then we should
4228 not complain if it is inaccurate (and probably negative). This
4229 happens in object files when the .debug_line section is actually
4230 comprised of several different .debug_line.* sections, (some of
4231 which may be removed by linker garbage collection), and a relocation
4232 is used to compute the correct length once that is done. */
4233 if (reloc_at (section
, (hdrptr
- section
->start
) - linfo
->li_offset_size
))
4235 linfo
->li_length
= (end
- data
) - initial_length_size
;
4239 warn (_("The length field (0x%lx) in the debug_line header is wrong - the section is too small\n"),
4240 (long) linfo
->li_length
);
4245 /* Get and check the version number. */
4246 SAFE_BYTE_GET_AND_INC (linfo
->li_version
, hdrptr
, 2, end
);
4248 if (linfo
->li_version
!= 2
4249 && linfo
->li_version
!= 3
4250 && linfo
->li_version
!= 4
4251 && linfo
->li_version
!= 5)
4253 warn (_("Only DWARF version 2, 3, 4 and 5 line info "
4254 "is currently supported.\n"));
4258 if (linfo
->li_version
>= 5)
4260 SAFE_BYTE_GET_AND_INC (linfo
->li_address_size
, hdrptr
, 1, end
);
4262 SAFE_BYTE_GET_AND_INC (linfo
->li_segment_size
, hdrptr
, 1, end
);
4263 if (linfo
->li_segment_size
!= 0)
4265 warn (_("The %s section contains "
4266 "unsupported segment selector size: %d.\n"),
4267 section
->name
, linfo
->li_segment_size
);
4272 SAFE_BYTE_GET_AND_INC (linfo
->li_prologue_length
, hdrptr
,
4273 linfo
->li_offset_size
, end
);
4274 SAFE_BYTE_GET_AND_INC (linfo
->li_min_insn_length
, hdrptr
, 1, end
);
4276 if (linfo
->li_version
>= 4)
4278 SAFE_BYTE_GET_AND_INC (linfo
->li_max_ops_per_insn
, hdrptr
, 1, end
);
4280 if (linfo
->li_max_ops_per_insn
== 0)
4282 warn (_("Invalid maximum operations per insn.\n"));
4287 linfo
->li_max_ops_per_insn
= 1;
4289 SAFE_BYTE_GET_AND_INC (linfo
->li_default_is_stmt
, hdrptr
, 1, end
);
4290 SAFE_SIGNED_BYTE_GET_AND_INC (linfo
->li_line_base
, hdrptr
, 1, end
);
4291 SAFE_BYTE_GET_AND_INC (linfo
->li_line_range
, hdrptr
, 1, end
);
4292 SAFE_BYTE_GET_AND_INC (linfo
->li_opcode_base
, hdrptr
, 1, end
);
4294 * end_of_sequence
= data
+ linfo
->li_length
+ initial_length_size
;
4295 /* PR 17512: file:002-117414-0.004. */
4296 if (* end_of_sequence
> end
)
4298 warn (_("Line length %s extends beyond end of section\n"),
4299 dwarf_vmatoa ("u", linfo
->li_length
));
4300 * end_of_sequence
= end
;
4307 static unsigned char *
4308 display_formatted_table (unsigned char *data
,
4309 unsigned char *start
,
4311 const DWARF2_Internal_LineInfo
*linfo
,
4312 struct dwarf_section
*section
,
4315 unsigned char *format_start
, format_count
, *format
, formati
;
4316 dwarf_vma data_count
, datai
;
4317 unsigned int namepass
, last_entry
= 0;
4318 const char * table_name
= is_dir
? N_("Directory Table") : N_("File Name Table");
4320 SAFE_BYTE_GET_AND_INC (format_count
, data
, 1, end
);
4321 if (do_checks
&& format_count
> 5)
4322 warn (_("Unexpectedly large number of columns in the %s (%u)\n"),
4323 table_name
, format_count
);
4325 format_start
= data
;
4326 for (formati
= 0; formati
< format_count
; formati
++)
4328 SKIP_ULEB (data
, end
);
4329 SKIP_ULEB (data
, end
);
4332 warn (_("%s: Corrupt format description entry\n"), table_name
);
4337 READ_ULEB (data_count
, data
, end
);
4338 if (data_count
== 0)
4340 printf (_("\n The %s is empty.\n"), table_name
);
4343 else if (data
>= end
)
4345 warn (_("%s: Corrupt entry count - expected %s but none found\n"),
4346 table_name
, dwarf_vmatoa ("x", data_count
));
4350 else if (format_count
== 0)
4352 warn (_("%s: format count is zero, but the table is not empty\n"),
4357 printf (_("\n The %s (offset 0x%lx, lines %s, columns %u):\n"),
4358 table_name
, (long) (data
- start
), dwarf_vmatoa ("u", data_count
),
4361 printf (_(" Entry"));
4362 /* Delay displaying name as the last entry for better screen layout. */
4363 for (namepass
= 0; namepass
< 2; namepass
++)
4365 format
= format_start
;
4366 for (formati
= 0; formati
< format_count
; formati
++)
4368 dwarf_vma content_type
;
4370 READ_ULEB (content_type
, format
, end
);
4371 if ((content_type
== DW_LNCT_path
) == (namepass
== 1))
4372 switch (content_type
)
4375 printf (_("\tName"));
4377 case DW_LNCT_directory_index
:
4378 printf (_("\tDir"));
4380 case DW_LNCT_timestamp
:
4381 printf (_("\tTime"));
4384 printf (_("\tSize"));
4387 printf (_("\tMD5\t\t\t"));
4390 printf (_("\t(Unknown format content type %s)"),
4391 dwarf_vmatoa ("u", content_type
));
4393 SKIP_ULEB (format
, end
);
4398 for (datai
= 0; datai
< data_count
; datai
++)
4400 unsigned char *datapass
= data
;
4402 printf (" %d", last_entry
++);
4403 /* Delay displaying name as the last entry for better screen layout. */
4404 for (namepass
= 0; namepass
< 2; namepass
++)
4406 format
= format_start
;
4408 for (formati
= 0; formati
< format_count
; formati
++)
4410 dwarf_vma content_type
, form
;
4412 READ_ULEB (content_type
, format
, end
);
4413 READ_ULEB (form
, format
, end
);
4414 data
= read_and_display_attr_value (0, form
, 0, start
, data
, end
,
4415 0, 0, linfo
->li_offset_size
,
4416 linfo
->li_version
, NULL
,
4417 ((content_type
== DW_LNCT_path
) != (namepass
== 1)),
4418 section
, NULL
, '\t', -1);
4422 if (data
>= end
&& (datai
< data_count
- 1))
4424 warn (_("\n%s: Corrupt entries list\n"), table_name
);
4433 display_debug_sup (struct dwarf_section
* section
,
4434 void * file ATTRIBUTE_UNUSED
)
4436 unsigned char * start
= section
->start
;
4437 unsigned char * end
= section
->start
+ section
->size
;
4438 unsigned int version
;
4439 char is_supplementary
;
4440 const unsigned char * sup_filename
;
4441 size_t sup_filename_len
;
4442 unsigned int num_read
;
4444 dwarf_vma checksum_len
;
4447 introduce (section
, true);
4448 if (section
->size
< 4)
4450 error (_("corrupt .debug_sup section: size is too small\n"));
4454 /* Read the data. */
4455 SAFE_BYTE_GET_AND_INC (version
, start
, 2, end
);
4457 warn (_("corrupt .debug_sup section: version < 5"));
4459 SAFE_BYTE_GET_AND_INC (is_supplementary
, start
, 1, end
);
4460 if (is_supplementary
!= 0 && is_supplementary
!= 1)
4461 warn (_("corrupt .debug_sup section: is_supplementary not 0 or 1\n"));
4463 sup_filename
= start
;
4464 if (is_supplementary
&& sup_filename
[0] != 0)
4465 warn (_("corrupt .debug_sup section: filename not empty in supplementary section\n"));
4467 sup_filename_len
= strnlen ((const char *) start
, end
- start
);
4468 if (sup_filename_len
== (size_t) (end
- start
))
4470 error (_("corrupt .debug_sup section: filename is not NUL terminated\n"));
4473 start
+= sup_filename_len
+ 1;
4475 checksum_len
= read_leb128 (start
, end
, false /* unsigned */, & num_read
, & status
);
4478 error (_("corrupt .debug_sup section: bad LEB128 field for checksum length\n"));
4482 if (checksum_len
> (dwarf_vma
) (end
- start
))
4484 error (_("corrupt .debug_sup section: checksum length is longer than the remaining section length\n"));
4485 checksum_len
= end
- start
;
4487 else if (checksum_len
< (dwarf_vma
) (end
- start
))
4489 warn (_("corrupt .debug_sup section: there are 0x%lx extra, unused bytes at the end of the section\n"),
4490 (long) ((end
- start
) - checksum_len
));
4493 printf (_(" Version: %u\n"), version
);
4494 printf (_(" Is Supp: %u\n"), is_supplementary
);
4495 printf (_(" Filename: %s\n"), sup_filename
);
4496 printf (_(" Checksum Len: %lu\n"), (long) checksum_len
);
4497 if (checksum_len
> 0)
4499 printf (_(" Checksum: "));
4500 while (checksum_len
--)
4501 printf ("0x%x ", * start
++ );
4508 display_debug_lines_raw (struct dwarf_section
* section
,
4509 unsigned char * data
,
4510 unsigned char * end
,
4513 unsigned char *start
= section
->start
;
4514 int verbose_view
= 0;
4516 introduce (section
, true);
4520 static DWARF2_Internal_LineInfo saved_linfo
;
4521 DWARF2_Internal_LineInfo linfo
;
4522 unsigned char *standard_opcodes
;
4523 unsigned char *end_of_sequence
;
4526 if (startswith (section
->name
, ".debug_line.")
4527 /* Note: the following does not apply to .debug_line.dwo sections.
4528 These are full debug_line sections. */
4529 && strcmp (section
->name
, ".debug_line.dwo") != 0)
4531 /* Sections named .debug_line.<foo> are fragments of a .debug_line
4532 section containing just the Line Number Statements. They are
4533 created by the assembler and intended to be used alongside gcc's
4534 -ffunction-sections command line option. When the linker's
4535 garbage collection decides to discard a .text.<foo> section it
4536 can then also discard the line number information in .debug_line.<foo>.
4538 Since the section is a fragment it does not have the details
4539 needed to fill out a LineInfo structure, so instead we use the
4540 details from the last full debug_line section that we processed. */
4541 end_of_sequence
= end
;
4542 standard_opcodes
= NULL
;
4543 linfo
= saved_linfo
;
4544 /* PR 17531: file: 0522b371. */
4545 if (linfo
.li_line_range
== 0)
4547 warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n"));
4550 reset_state_machine (linfo
.li_default_is_stmt
);
4554 unsigned char * hdrptr
;
4556 if ((hdrptr
= read_debug_line_header (section
, data
, end
, & linfo
,
4557 & end_of_sequence
)) == NULL
)
4560 printf (_(" Offset: 0x%lx\n"), (long)(data
- start
));
4561 printf (_(" Length: %ld\n"), (long) linfo
.li_length
);
4562 printf (_(" DWARF Version: %d\n"), linfo
.li_version
);
4563 if (linfo
.li_version
>= 5)
4565 printf (_(" Address size (bytes): %d\n"), linfo
.li_address_size
);
4566 printf (_(" Segment selector (bytes): %d\n"), linfo
.li_segment_size
);
4568 printf (_(" Prologue Length: %d\n"), (int) linfo
.li_prologue_length
);
4569 printf (_(" Minimum Instruction Length: %d\n"), linfo
.li_min_insn_length
);
4570 if (linfo
.li_version
>= 4)
4571 printf (_(" Maximum Ops per Instruction: %d\n"), linfo
.li_max_ops_per_insn
);
4572 printf (_(" Initial value of 'is_stmt': %d\n"), linfo
.li_default_is_stmt
);
4573 printf (_(" Line Base: %d\n"), linfo
.li_line_base
);
4574 printf (_(" Line Range: %d\n"), linfo
.li_line_range
);
4575 printf (_(" Opcode Base: %d\n"), linfo
.li_opcode_base
);
4577 /* PR 17512: file: 1665-6428-0.004. */
4578 if (linfo
.li_line_range
== 0)
4580 warn (_("Line range of 0 is invalid, using 1 instead\n"));
4581 linfo
.li_line_range
= 1;
4584 reset_state_machine (linfo
.li_default_is_stmt
);
4586 /* Display the contents of the Opcodes table. */
4587 standard_opcodes
= hdrptr
;
4589 /* PR 17512: file: 002-417945-0.004. */
4590 if (standard_opcodes
+ linfo
.li_opcode_base
>= end
)
4592 warn (_("Line Base extends beyond end of section\n"));
4596 printf (_("\n Opcodes:\n"));
4598 for (i
= 1; i
< linfo
.li_opcode_base
; i
++)
4599 printf (ngettext (" Opcode %d has %d arg\n",
4600 " Opcode %d has %d args\n",
4601 standard_opcodes
[i
- 1]),
4602 i
, standard_opcodes
[i
- 1]);
4604 /* Display the contents of the Directory table. */
4605 data
= standard_opcodes
+ linfo
.li_opcode_base
- 1;
4607 if (linfo
.li_version
>= 5)
4609 load_debug_section_with_follow (line_str
, file
);
4611 data
= display_formatted_table (data
, start
, end
, &linfo
, section
,
4613 data
= display_formatted_table (data
, start
, end
, &linfo
, section
,
4619 printf (_("\n The Directory Table is empty.\n"));
4622 unsigned int last_dir_entry
= 0;
4624 printf (_("\n The Directory Table (offset 0x%lx):\n"),
4625 (long)(data
- start
));
4627 while (data
< end
&& *data
!= 0)
4629 printf (" %d\t%.*s\n", ++last_dir_entry
, (int) (end
- data
), data
);
4631 data
+= strnlen ((char *) data
, end
- data
) + 1;
4634 /* PR 17512: file: 002-132094-0.004. */
4635 if (data
>= end
- 1)
4639 /* Skip the NUL at the end of the table. */
4642 /* Display the contents of the File Name table. */
4644 printf (_("\n The File Name Table is empty.\n"));
4647 printf (_("\n The File Name Table (offset 0x%lx):\n"),
4648 (long)(data
- start
));
4649 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
4651 while (data
< end
&& *data
!= 0)
4653 unsigned char *name
;
4656 printf (" %d\t", ++state_machine_regs
.last_file_entry
);
4658 data
+= strnlen ((char *) data
, end
- data
) + 1;
4660 READ_ULEB (val
, data
, end
);
4661 printf ("%s\t", dwarf_vmatoa ("u", val
));
4662 READ_ULEB (val
, data
, end
);
4663 printf ("%s\t", dwarf_vmatoa ("u", val
));
4664 READ_ULEB (val
, data
, end
);
4665 printf ("%s\t", dwarf_vmatoa ("u", val
));
4666 printf ("%.*s\n", (int)(end
- name
), name
);
4670 warn (_("Corrupt file name table entry\n"));
4676 /* Skip the NUL at the end of the table. */
4681 saved_linfo
= linfo
;
4684 /* Now display the statements. */
4685 if (data
>= end_of_sequence
)
4686 printf (_(" No Line Number Statements.\n"));
4689 printf (_(" Line Number Statements:\n"));
4691 while (data
< end_of_sequence
)
4693 unsigned char op_code
;
4694 dwarf_signed_vma adv
;
4697 printf (" [0x%08lx]", (long)(data
- start
));
4701 if (op_code
>= linfo
.li_opcode_base
)
4703 op_code
-= linfo
.li_opcode_base
;
4704 uladv
= (op_code
/ linfo
.li_line_range
);
4705 if (linfo
.li_max_ops_per_insn
== 1)
4707 uladv
*= linfo
.li_min_insn_length
;
4708 state_machine_regs
.address
+= uladv
;
4710 state_machine_regs
.view
= 0;
4711 printf (_(" Special opcode %d: "
4712 "advance Address by %s to 0x%s%s"),
4713 op_code
, dwarf_vmatoa ("u", uladv
),
4714 dwarf_vmatoa ("x", state_machine_regs
.address
),
4715 verbose_view
&& uladv
4716 ? _(" (reset view)") : "");
4721 = ((state_machine_regs
.op_index
+ uladv
)
4722 / linfo
.li_max_ops_per_insn
)
4723 * linfo
.li_min_insn_length
;
4725 state_machine_regs
.address
+= addrdelta
;
4726 state_machine_regs
.op_index
4727 = (state_machine_regs
.op_index
+ uladv
)
4728 % linfo
.li_max_ops_per_insn
;
4730 state_machine_regs
.view
= 0;
4731 printf (_(" Special opcode %d: "
4732 "advance Address by %s to 0x%s[%d]%s"),
4733 op_code
, dwarf_vmatoa ("u", uladv
),
4734 dwarf_vmatoa ("x", state_machine_regs
.address
),
4735 state_machine_regs
.op_index
,
4736 verbose_view
&& addrdelta
4737 ? _(" (reset view)") : "");
4739 adv
= (op_code
% linfo
.li_line_range
) + linfo
.li_line_base
;
4740 state_machine_regs
.line
+= adv
;
4741 printf (_(" and Line by %s to %d"),
4742 dwarf_vmatoa ("d", adv
), state_machine_regs
.line
);
4743 if (verbose_view
|| state_machine_regs
.view
)
4744 printf (_(" (view %u)\n"), state_machine_regs
.view
);
4747 state_machine_regs
.view
++;
4752 case DW_LNS_extended_op
:
4753 data
+= process_extended_line_op (data
,
4754 linfo
.li_default_is_stmt
,
4759 printf (_(" Copy"));
4760 if (verbose_view
|| state_machine_regs
.view
)
4761 printf (_(" (view %u)\n"), state_machine_regs
.view
);
4764 state_machine_regs
.view
++;
4767 case DW_LNS_advance_pc
:
4768 READ_ULEB (uladv
, data
, end
);
4769 if (linfo
.li_max_ops_per_insn
== 1)
4771 uladv
*= linfo
.li_min_insn_length
;
4772 state_machine_regs
.address
+= uladv
;
4774 state_machine_regs
.view
= 0;
4775 printf (_(" Advance PC by %s to 0x%s%s\n"),
4776 dwarf_vmatoa ("u", uladv
),
4777 dwarf_vmatoa ("x", state_machine_regs
.address
),
4778 verbose_view
&& uladv
4779 ? _(" (reset view)") : "");
4784 = ((state_machine_regs
.op_index
+ uladv
)
4785 / linfo
.li_max_ops_per_insn
)
4786 * linfo
.li_min_insn_length
;
4787 state_machine_regs
.address
4789 state_machine_regs
.op_index
4790 = (state_machine_regs
.op_index
+ uladv
)
4791 % linfo
.li_max_ops_per_insn
;
4793 state_machine_regs
.view
= 0;
4794 printf (_(" Advance PC by %s to 0x%s[%d]%s\n"),
4795 dwarf_vmatoa ("u", uladv
),
4796 dwarf_vmatoa ("x", state_machine_regs
.address
),
4797 state_machine_regs
.op_index
,
4798 verbose_view
&& addrdelta
4799 ? _(" (reset view)") : "");
4803 case DW_LNS_advance_line
:
4804 READ_SLEB (adv
, data
, end
);
4805 state_machine_regs
.line
+= adv
;
4806 printf (_(" Advance Line by %s to %d\n"),
4807 dwarf_vmatoa ("d", adv
),
4808 state_machine_regs
.line
);
4811 case DW_LNS_set_file
:
4812 READ_ULEB (uladv
, data
, end
);
4813 printf (_(" Set File Name to entry %s in the File Name Table\n"),
4814 dwarf_vmatoa ("u", uladv
));
4815 state_machine_regs
.file
= uladv
;
4818 case DW_LNS_set_column
:
4819 READ_ULEB (uladv
, data
, end
);
4820 printf (_(" Set column to %s\n"),
4821 dwarf_vmatoa ("u", uladv
));
4822 state_machine_regs
.column
= uladv
;
4825 case DW_LNS_negate_stmt
:
4826 adv
= state_machine_regs
.is_stmt
;
4828 printf (_(" Set is_stmt to %s\n"), dwarf_vmatoa ("d", adv
));
4829 state_machine_regs
.is_stmt
= adv
;
4832 case DW_LNS_set_basic_block
:
4833 printf (_(" Set basic block\n"));
4834 state_machine_regs
.basic_block
= 1;
4837 case DW_LNS_const_add_pc
:
4838 uladv
= ((255 - linfo
.li_opcode_base
) / linfo
.li_line_range
);
4839 if (linfo
.li_max_ops_per_insn
)
4841 uladv
*= linfo
.li_min_insn_length
;
4842 state_machine_regs
.address
+= uladv
;
4844 state_machine_regs
.view
= 0;
4845 printf (_(" Advance PC by constant %s to 0x%s%s\n"),
4846 dwarf_vmatoa ("u", uladv
),
4847 dwarf_vmatoa ("x", state_machine_regs
.address
),
4848 verbose_view
&& uladv
4849 ? _(" (reset view)") : "");
4854 = ((state_machine_regs
.op_index
+ uladv
)
4855 / linfo
.li_max_ops_per_insn
)
4856 * linfo
.li_min_insn_length
;
4857 state_machine_regs
.address
4859 state_machine_regs
.op_index
4860 = (state_machine_regs
.op_index
+ uladv
)
4861 % linfo
.li_max_ops_per_insn
;
4863 state_machine_regs
.view
= 0;
4864 printf (_(" Advance PC by constant %s to 0x%s[%d]%s\n"),
4865 dwarf_vmatoa ("u", uladv
),
4866 dwarf_vmatoa ("x", state_machine_regs
.address
),
4867 state_machine_regs
.op_index
,
4868 verbose_view
&& addrdelta
4869 ? _(" (reset view)") : "");
4873 case DW_LNS_fixed_advance_pc
:
4874 SAFE_BYTE_GET_AND_INC (uladv
, data
, 2, end
);
4875 state_machine_regs
.address
+= uladv
;
4876 state_machine_regs
.op_index
= 0;
4877 printf (_(" Advance PC by fixed size amount %s to 0x%s\n"),
4878 dwarf_vmatoa ("u", uladv
),
4879 dwarf_vmatoa ("x", state_machine_regs
.address
));
4880 /* Do NOT reset view. */
4883 case DW_LNS_set_prologue_end
:
4884 printf (_(" Set prologue_end to true\n"));
4887 case DW_LNS_set_epilogue_begin
:
4888 printf (_(" Set epilogue_begin to true\n"));
4891 case DW_LNS_set_isa
:
4892 READ_ULEB (uladv
, data
, end
);
4893 printf (_(" Set ISA to %s\n"), dwarf_vmatoa ("u", uladv
));
4897 printf (_(" Unknown opcode %d with operands: "), op_code
);
4899 if (standard_opcodes
!= NULL
)
4900 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
4902 READ_ULEB (uladv
, data
, end
);
4903 printf ("0x%s%s", dwarf_vmatoa ("x", uladv
),
4904 i
== 1 ? "" : ", ");
4919 unsigned char *name
;
4920 unsigned int directory_index
;
4921 unsigned int modification_date
;
4922 unsigned int length
;
4925 /* Output a decoded representation of the .debug_line section. */
4928 display_debug_lines_decoded (struct dwarf_section
* section
,
4929 unsigned char * start
,
4930 unsigned char * data
,
4931 unsigned char * end
,
4934 static DWARF2_Internal_LineInfo saved_linfo
;
4936 introduce (section
, false);
4940 /* This loop amounts to one iteration per compilation unit. */
4941 DWARF2_Internal_LineInfo linfo
;
4942 unsigned char *standard_opcodes
;
4943 unsigned char *end_of_sequence
;
4945 File_Entry
*file_table
= NULL
;
4946 unsigned int n_files
= 0;
4947 unsigned char **directory_table
= NULL
;
4948 dwarf_vma n_directories
= 0;
4950 if (startswith (section
->name
, ".debug_line.")
4951 /* Note: the following does not apply to .debug_line.dwo sections.
4952 These are full debug_line sections. */
4953 && strcmp (section
->name
, ".debug_line.dwo") != 0)
4955 /* See comment in display_debug_lines_raw(). */
4956 end_of_sequence
= end
;
4957 standard_opcodes
= NULL
;
4958 linfo
= saved_linfo
;
4959 /* PR 17531: file: 0522b371. */
4960 if (linfo
.li_line_range
== 0)
4962 warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n"));
4965 reset_state_machine (linfo
.li_default_is_stmt
);
4969 unsigned char *hdrptr
;
4971 if ((hdrptr
= read_debug_line_header (section
, data
, end
, & linfo
,
4972 & end_of_sequence
)) == NULL
)
4975 /* PR 17531: file: 0522b371. */
4976 if (linfo
.li_line_range
== 0)
4978 warn (_("Line range of 0 is invalid, using 1 instead\n"));
4979 linfo
.li_line_range
= 1;
4981 reset_state_machine (linfo
.li_default_is_stmt
);
4983 /* Save a pointer to the contents of the Opcodes table. */
4984 standard_opcodes
= hdrptr
;
4986 /* Traverse the Directory table just to count entries. */
4987 data
= standard_opcodes
+ linfo
.li_opcode_base
- 1;
4991 warn (_("opcode base of %d extends beyond end of section\n"),
4992 linfo
.li_opcode_base
);
4996 if (linfo
.li_version
>= 5)
4998 unsigned char *format_start
, format_count
, *format
;
4999 dwarf_vma formati
, entryi
;
5001 load_debug_section_with_follow (line_str
, fileptr
);
5003 /* Skip directories format. */
5004 SAFE_BYTE_GET_AND_INC (format_count
, data
, 1, end
);
5005 if (do_checks
&& format_count
> 1)
5006 warn (_("Unexpectedly large number of columns in the directory name table (%u)\n"),
5008 format_start
= data
;
5009 for (formati
= 0; formati
< format_count
; formati
++)
5011 SKIP_ULEB (data
, end
);
5012 SKIP_ULEB (data
, end
);
5015 READ_ULEB (n_directories
, data
, end
);
5018 warn (_("Corrupt directories list\n"));
5022 if (n_directories
== 0)
5023 directory_table
= NULL
;
5025 directory_table
= (unsigned char **)
5026 xmalloc (n_directories
* sizeof (unsigned char *));
5028 for (entryi
= 0; entryi
< n_directories
; entryi
++)
5030 unsigned char **pathp
= &directory_table
[entryi
];
5032 format
= format_start
;
5033 for (formati
= 0; formati
< format_count
; formati
++)
5035 dwarf_vma content_type
, form
;
5038 READ_ULEB (content_type
, format
, end
);
5039 READ_ULEB (form
, format
, end
);
5042 warn (_("Corrupt directories list\n"));
5045 switch (content_type
)
5050 case DW_FORM_string
:
5053 case DW_FORM_line_strp
:
5054 SAFE_BYTE_GET (uvalue
, data
, linfo
.li_offset_size
,
5056 /* Remove const by the cast. */
5057 *pathp
= (unsigned char *)
5058 fetch_indirect_line_string (uvalue
);
5063 data
= read_and_display_attr_value (0, form
, 0, start
,
5065 linfo
.li_offset_size
,
5072 warn (_("Corrupt directories list\n"));
5077 /* Skip files format. */
5078 SAFE_BYTE_GET_AND_INC (format_count
, data
, 1, end
);
5079 if (do_checks
&& format_count
> 5)
5080 warn (_("Unexpectedly large number of columns in the file name table (%u)\n"),
5082 format_start
= data
;
5083 for (formati
= 0; formati
< format_count
; formati
++)
5085 SKIP_ULEB (data
, end
);
5086 SKIP_ULEB (data
, end
);
5089 READ_ULEB (n_files
, data
, end
);
5090 if (data
>= end
&& n_files
> 0)
5092 warn (_("Corrupt file name list\n"));
5099 file_table
= (File_Entry
*) xcalloc (1, n_files
5100 * sizeof (File_Entry
));
5102 for (entryi
= 0; entryi
< n_files
; entryi
++)
5104 File_Entry
*file
= &file_table
[entryi
];
5106 format
= format_start
;
5107 for (formati
= 0; formati
< format_count
; formati
++)
5109 dwarf_vma content_type
, form
;
5113 READ_ULEB (content_type
, format
, end
);
5114 READ_ULEB (form
, format
, end
);
5117 warn (_("Corrupt file name list\n"));
5120 switch (content_type
)
5125 case DW_FORM_string
:
5128 case DW_FORM_line_strp
:
5129 SAFE_BYTE_GET (uvalue
, data
, linfo
.li_offset_size
,
5131 /* Remove const by the cast. */
5132 file
->name
= (unsigned char *)
5133 fetch_indirect_line_string (uvalue
);
5137 case DW_LNCT_directory_index
:
5141 SAFE_BYTE_GET (file
->directory_index
, data
, 1,
5145 SAFE_BYTE_GET (file
->directory_index
, data
, 2,
5150 READ_ULEB (file
->directory_index
, tmp
, end
);
5155 data
= read_and_display_attr_value (0, form
, 0, start
,
5157 linfo
.li_offset_size
,
5164 warn (_("Corrupt file name list\n"));
5173 unsigned char *ptr_directory_table
= data
;
5175 while (data
< end
&& *data
!= 0)
5177 data
+= strnlen ((char *) data
, end
- data
) + 1;
5184 warn (_("directory table ends unexpectedly\n"));
5189 /* Go through the directory table again to save the directories. */
5190 directory_table
= (unsigned char **)
5191 xmalloc (n_directories
* sizeof (unsigned char *));
5194 while (*ptr_directory_table
!= 0)
5196 directory_table
[i
] = ptr_directory_table
;
5197 ptr_directory_table
+= strnlen ((char *) ptr_directory_table
,
5198 ptr_directory_table
- end
) + 1;
5202 /* Skip the NUL at the end of the table. */
5205 /* Traverse the File Name table just to count the entries. */
5206 if (data
< end
&& *data
!= 0)
5208 unsigned char *ptr_file_name_table
= data
;
5210 while (data
< end
&& *data
!= 0)
5212 /* Skip Name, directory index, last modification
5213 time and length of file. */
5214 data
+= strnlen ((char *) data
, end
- data
) + 1;
5215 SKIP_ULEB (data
, end
);
5216 SKIP_ULEB (data
, end
);
5217 SKIP_ULEB (data
, end
);
5223 warn (_("file table ends unexpectedly\n"));
5228 /* Go through the file table again to save the strings. */
5229 file_table
= (File_Entry
*) xmalloc (n_files
* sizeof (File_Entry
));
5232 while (*ptr_file_name_table
!= 0)
5234 file_table
[i
].name
= ptr_file_name_table
;
5235 ptr_file_name_table
+= strnlen ((char *) ptr_file_name_table
,
5236 end
- ptr_file_name_table
) + 1;
5238 /* We are not interested in directory, time or size. */
5239 READ_ULEB (file_table
[i
].directory_index
,
5240 ptr_file_name_table
, end
);
5241 READ_ULEB (file_table
[i
].modification_date
,
5242 ptr_file_name_table
, end
);
5243 READ_ULEB (file_table
[i
].length
,
5244 ptr_file_name_table
, end
);
5250 /* Skip the NUL at the end of the table. */
5254 /* Print the Compilation Unit's name and a header. */
5255 if (file_table
== NULL
)
5256 printf (_("CU: No directory table\n"));
5257 else if (directory_table
== NULL
)
5258 printf (_("CU: %s:\n"), file_table
[0].name
);
5261 unsigned int ix
= file_table
[0].directory_index
;
5262 const char *directory
;
5267 else if (n_directories
== 0)
5268 directory
= _("<unknown>");
5269 else if (ix
> n_directories
)
5271 warn (_("directory index %u > number of directories %s\n"),
5272 ix
, dwarf_vmatoa ("u", n_directories
));
5273 directory
= _("<corrupt>");
5276 directory
= (char *) directory_table
[ix
- 1];
5278 if (do_wide
|| strlen (directory
) < 76)
5279 printf (_("CU: %s/%s:\n"), directory
, file_table
[0].name
);
5281 printf ("%s:\n", file_table
[0].name
);
5285 printf (_("File name Line number Starting address View Stmt\n"));
5287 printf (_("CU: Empty file name table\n"));
5288 saved_linfo
= linfo
;
5291 /* This loop iterates through the Dwarf Line Number Program. */
5292 while (data
< end_of_sequence
)
5294 unsigned char op_code
;
5297 unsigned long int uladv
;
5298 int is_special_opcode
= 0;
5303 if (op_code
>= linfo
.li_opcode_base
)
5305 op_code
-= linfo
.li_opcode_base
;
5306 uladv
= (op_code
/ linfo
.li_line_range
);
5307 if (linfo
.li_max_ops_per_insn
== 1)
5309 uladv
*= linfo
.li_min_insn_length
;
5310 state_machine_regs
.address
+= uladv
;
5312 state_machine_regs
.view
= 0;
5317 = ((state_machine_regs
.op_index
+ uladv
)
5318 / linfo
.li_max_ops_per_insn
)
5319 * linfo
.li_min_insn_length
;
5320 state_machine_regs
.address
5322 state_machine_regs
.op_index
5323 = (state_machine_regs
.op_index
+ uladv
)
5324 % linfo
.li_max_ops_per_insn
;
5326 state_machine_regs
.view
= 0;
5329 adv
= (op_code
% linfo
.li_line_range
) + linfo
.li_line_base
;
5330 state_machine_regs
.line
+= adv
;
5331 is_special_opcode
= 1;
5332 /* Increment view after printing this row. */
5337 case DW_LNS_extended_op
:
5339 unsigned int ext_op_code_len
;
5340 unsigned char ext_op_code
;
5341 unsigned char *op_code_end
;
5342 unsigned char *op_code_data
= data
;
5344 READ_ULEB (ext_op_code_len
, op_code_data
, end_of_sequence
);
5345 op_code_end
= op_code_data
+ ext_op_code_len
;
5346 if (ext_op_code_len
== 0 || op_code_end
> end_of_sequence
)
5348 warn (_("Badly formed extended line op encountered!\n"));
5351 ext_op_code
= *op_code_data
++;
5355 switch (ext_op_code
)
5357 case DW_LNE_end_sequence
:
5358 /* Reset stuff after printing this row. */
5360 case DW_LNE_set_address
:
5361 SAFE_BYTE_GET_AND_INC (state_machine_regs
.address
,
5363 op_code_end
- op_code_data
,
5365 state_machine_regs
.op_index
= 0;
5366 state_machine_regs
.view
= 0;
5368 case DW_LNE_define_file
:
5369 file_table
= (File_Entry
*) xrealloc
5370 (file_table
, (n_files
+ 1) * sizeof (File_Entry
));
5372 ++state_machine_regs
.last_file_entry
;
5373 /* Source file name. */
5374 file_table
[n_files
].name
= op_code_data
;
5375 op_code_data
+= strlen ((char *) op_code_data
) + 1;
5376 /* Directory index. */
5377 READ_ULEB (file_table
[n_files
].directory_index
,
5378 op_code_data
, op_code_end
);
5379 /* Last modification time. */
5380 READ_ULEB (file_table
[n_files
].modification_date
,
5381 op_code_data
, op_code_end
);
5383 READ_ULEB (file_table
[n_files
].length
,
5384 op_code_data
, op_code_end
);
5388 case DW_LNE_set_discriminator
:
5389 case DW_LNE_HP_set_sequence
:
5390 /* Simply ignored. */
5394 printf (_("UNKNOWN (%u): length %ld\n"),
5395 ext_op_code
, (long int) (op_code_data
- data
));
5402 /* Increment view after printing this row. */
5405 case DW_LNS_advance_pc
:
5406 READ_ULEB (uladv
, data
, end
);
5407 if (linfo
.li_max_ops_per_insn
== 1)
5409 uladv
*= linfo
.li_min_insn_length
;
5410 state_machine_regs
.address
+= uladv
;
5412 state_machine_regs
.view
= 0;
5417 = ((state_machine_regs
.op_index
+ uladv
)
5418 / linfo
.li_max_ops_per_insn
)
5419 * linfo
.li_min_insn_length
;
5420 state_machine_regs
.address
5422 state_machine_regs
.op_index
5423 = (state_machine_regs
.op_index
+ uladv
)
5424 % linfo
.li_max_ops_per_insn
;
5426 state_machine_regs
.view
= 0;
5430 case DW_LNS_advance_line
:
5431 READ_SLEB (adv
, data
, end
);
5432 state_machine_regs
.line
+= adv
;
5435 case DW_LNS_set_file
:
5436 READ_ULEB (uladv
, data
, end
);
5437 state_machine_regs
.file
= uladv
;
5440 unsigned file
= state_machine_regs
.file
- 1;
5443 if (file_table
== NULL
|| n_files
== 0)
5444 printf (_("\n [Use file table entry %d]\n"), file
);
5446 else if (file
>= n_files
)
5448 warn (_("file index %u > number of files %u\n"), file
+ 1, n_files
);
5449 printf (_("\n <over large file table index %u>"), file
);
5451 else if ((dir
= file_table
[file
].directory_index
) == 0)
5452 /* If directory index is 0, that means current directory. */
5453 printf ("\n./%s:[++]\n", file_table
[file
].name
);
5454 else if (directory_table
== NULL
|| n_directories
== 0)
5455 printf (_("\n [Use file %s in directory table entry %d]\n"),
5456 file_table
[file
].name
, dir
);
5458 else if (dir
> n_directories
)
5460 warn (_("directory index %u > number of directories %s\n"),
5461 dir
, dwarf_vmatoa ("u", n_directories
));
5462 printf (_("\n <over large directory table entry %u>\n"), dir
);
5465 printf ("\n%s/%s:\n",
5466 /* The directory index starts counting at 1. */
5467 directory_table
[dir
- 1], file_table
[file
].name
);
5471 case DW_LNS_set_column
:
5472 READ_ULEB (uladv
, data
, end
);
5473 state_machine_regs
.column
= uladv
;
5476 case DW_LNS_negate_stmt
:
5477 adv
= state_machine_regs
.is_stmt
;
5479 state_machine_regs
.is_stmt
= adv
;
5482 case DW_LNS_set_basic_block
:
5483 state_machine_regs
.basic_block
= 1;
5486 case DW_LNS_const_add_pc
:
5487 uladv
= ((255 - linfo
.li_opcode_base
) / linfo
.li_line_range
);
5488 if (linfo
.li_max_ops_per_insn
== 1)
5490 uladv
*= linfo
.li_min_insn_length
;
5491 state_machine_regs
.address
+= uladv
;
5493 state_machine_regs
.view
= 0;
5498 = ((state_machine_regs
.op_index
+ uladv
)
5499 / linfo
.li_max_ops_per_insn
)
5500 * linfo
.li_min_insn_length
;
5501 state_machine_regs
.address
5503 state_machine_regs
.op_index
5504 = (state_machine_regs
.op_index
+ uladv
)
5505 % linfo
.li_max_ops_per_insn
;
5507 state_machine_regs
.view
= 0;
5511 case DW_LNS_fixed_advance_pc
:
5512 SAFE_BYTE_GET_AND_INC (uladv
, data
, 2, end
);
5513 state_machine_regs
.address
+= uladv
;
5514 state_machine_regs
.op_index
= 0;
5515 /* Do NOT reset view. */
5518 case DW_LNS_set_prologue_end
:
5521 case DW_LNS_set_epilogue_begin
:
5524 case DW_LNS_set_isa
:
5525 READ_ULEB (uladv
, data
, end
);
5526 printf (_(" Set ISA to %lu\n"), uladv
);
5530 printf (_(" Unknown opcode %d with operands: "), op_code
);
5532 if (standard_opcodes
!= NULL
)
5533 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
5537 READ_ULEB (val
, data
, end
);
5538 printf ("0x%s%s", dwarf_vmatoa ("x", val
),
5539 i
== 1 ? "" : ", ");
5545 /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row
5546 to the DWARF address/line matrix. */
5547 if ((is_special_opcode
) || (xop
== -DW_LNE_end_sequence
)
5548 || (xop
== DW_LNS_copy
))
5550 const unsigned int MAX_FILENAME_LENGTH
= 35;
5552 char *newFileName
= NULL
;
5553 size_t fileNameLength
;
5557 unsigned indx
= state_machine_regs
.file
- 1;
5559 if (indx
>= n_files
)
5561 warn (_("corrupt file index %u encountered\n"), indx
);
5562 fileName
= _("<corrupt>");
5565 fileName
= (char *) file_table
[indx
].name
;
5568 fileName
= _("<unknown>");
5570 fileNameLength
= strlen (fileName
);
5572 if ((fileNameLength
> MAX_FILENAME_LENGTH
) && (!do_wide
))
5574 newFileName
= (char *) xmalloc (MAX_FILENAME_LENGTH
+ 1);
5575 /* Truncate file name */
5576 strncpy (newFileName
,
5577 fileName
+ fileNameLength
- MAX_FILENAME_LENGTH
,
5578 MAX_FILENAME_LENGTH
+ 1);
5579 /* FIXME: This is to pacify gcc-10 which can warn that the
5580 strncpy above might leave a non-NUL terminated string
5581 in newFileName. It won't, but gcc's analysis doesn't
5582 quite go far enough to discover this. */
5583 newFileName
[MAX_FILENAME_LENGTH
] = 0;
5587 newFileName
= (char *) xmalloc (fileNameLength
+ 1);
5588 strncpy (newFileName
, fileName
, fileNameLength
+ 1);
5591 /* A row with end_seq set to true has a meaningful address, but
5592 the other information in the same row is not significant.
5593 In such a row, print line as "-", and don't print
5595 if (!do_wide
|| (fileNameLength
<= MAX_FILENAME_LENGTH
))
5597 if (linfo
.li_max_ops_per_insn
== 1)
5599 if (xop
== -DW_LNE_end_sequence
)
5600 printf ("%-35s %11s %#18" DWARF_VMA_FMT
"x",
5602 state_machine_regs
.address
);
5604 printf ("%-35s %11d %#18" DWARF_VMA_FMT
"x",
5605 newFileName
, state_machine_regs
.line
,
5606 state_machine_regs
.address
);
5610 if (xop
== -DW_LNE_end_sequence
)
5611 printf ("%-35s %11s %#18" DWARF_VMA_FMT
"x[%d]",
5613 state_machine_regs
.address
,
5614 state_machine_regs
.op_index
);
5616 printf ("%-35s %11d %#18" DWARF_VMA_FMT
"x[%d]",
5617 newFileName
, state_machine_regs
.line
,
5618 state_machine_regs
.address
,
5619 state_machine_regs
.op_index
);
5624 if (linfo
.li_max_ops_per_insn
== 1)
5626 if (xop
== -DW_LNE_end_sequence
)
5627 printf ("%s %11s %#18" DWARF_VMA_FMT
"x",
5629 state_machine_regs
.address
);
5631 printf ("%s %11d %#18" DWARF_VMA_FMT
"x",
5632 newFileName
, state_machine_regs
.line
,
5633 state_machine_regs
.address
);
5637 if (xop
== -DW_LNE_end_sequence
)
5638 printf ("%s %11s %#18" DWARF_VMA_FMT
"x[%d]",
5640 state_machine_regs
.address
,
5641 state_machine_regs
.op_index
);
5643 printf ("%s %11d %#18" DWARF_VMA_FMT
"x[%d]",
5644 newFileName
, state_machine_regs
.line
,
5645 state_machine_regs
.address
,
5646 state_machine_regs
.op_index
);
5650 if (xop
!= -DW_LNE_end_sequence
)
5652 if (state_machine_regs
.view
)
5653 printf (" %6u", state_machine_regs
.view
);
5657 if (state_machine_regs
.is_stmt
)
5662 state_machine_regs
.view
++;
5664 if (xop
== -DW_LNE_end_sequence
)
5666 reset_state_machine (linfo
.li_default_is_stmt
);
5681 if (directory_table
)
5683 free (directory_table
);
5684 directory_table
= NULL
;
5695 display_debug_lines (struct dwarf_section
*section
, void *file
)
5697 unsigned char *data
= section
->start
;
5698 unsigned char *end
= data
+ section
->size
;
5700 int retValDecoded
= 1;
5702 if (do_debug_lines
== 0)
5703 do_debug_lines
|= FLAG_DEBUG_LINES_RAW
;
5705 if (do_debug_lines
& FLAG_DEBUG_LINES_RAW
)
5706 retValRaw
= display_debug_lines_raw (section
, data
, end
, file
);
5708 if (do_debug_lines
& FLAG_DEBUG_LINES_DECODED
)
5709 retValDecoded
= display_debug_lines_decoded (section
, data
, data
, end
, file
);
5711 if (!retValRaw
|| !retValDecoded
)
5718 find_debug_info_for_offset (unsigned long offset
)
5722 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
5725 for (i
= 0; i
< num_debug_info_entries
; i
++)
5726 if (debug_information
[i
].cu_offset
== offset
)
5727 return debug_information
+ i
;
5733 get_gdb_index_symbol_kind_name (gdb_index_symbol_kind kind
)
5735 /* See gdb/gdb-index.h. */
5736 static const char * const kinds
[] =
5748 return _ (kinds
[kind
]);
5752 display_debug_pubnames_worker (struct dwarf_section
*section
,
5753 void *file ATTRIBUTE_UNUSED
,
5756 DWARF2_Internal_PubNames names
;
5757 unsigned char *start
= section
->start
;
5758 unsigned char *end
= start
+ section
->size
;
5760 /* It does not matter if this load fails,
5761 we test for that later on. */
5762 load_debug_info (file
);
5764 introduce (section
, false);
5768 unsigned char *data
;
5769 unsigned long sec_off
;
5770 unsigned int offset_size
, initial_length_size
;
5772 SAFE_BYTE_GET_AND_INC (names
.pn_length
, start
, 4, end
);
5773 if (names
.pn_length
== 0xffffffff)
5775 SAFE_BYTE_GET_AND_INC (names
.pn_length
, start
, 8, end
);
5777 initial_length_size
= 12;
5782 initial_length_size
= 4;
5785 sec_off
= start
- section
->start
;
5786 if (sec_off
+ names
.pn_length
< sec_off
5787 || sec_off
+ names
.pn_length
> section
->size
)
5789 warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"),
5791 sec_off
- initial_length_size
,
5792 dwarf_vmatoa ("x", names
.pn_length
));
5797 start
+= names
.pn_length
;
5799 SAFE_BYTE_GET_AND_INC (names
.pn_version
, data
, 2, end
);
5800 SAFE_BYTE_GET_AND_INC (names
.pn_offset
, data
, offset_size
, end
);
5802 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
5803 && num_debug_info_entries
> 0
5804 && find_debug_info_for_offset (names
.pn_offset
) == NULL
)
5805 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
5806 (unsigned long) names
.pn_offset
, section
->name
);
5808 SAFE_BYTE_GET_AND_INC (names
.pn_size
, data
, offset_size
, end
);
5810 printf (_(" Length: %ld\n"),
5811 (long) names
.pn_length
);
5812 printf (_(" Version: %d\n"),
5814 printf (_(" Offset into .debug_info section: 0x%lx\n"),
5815 (unsigned long) names
.pn_offset
);
5816 printf (_(" Size of area in .debug_info section: %ld\n"),
5817 (long) names
.pn_size
);
5819 if (names
.pn_version
!= 2 && names
.pn_version
!= 3)
5821 static int warned
= 0;
5825 warn (_("Only DWARF 2 and 3 pubnames are currently supported\n"));
5833 printf (_("\n Offset Kind Name\n"));
5835 printf (_("\n Offset\tName\n"));
5839 bfd_size_type maxprint
;
5842 SAFE_BYTE_GET (offset
, data
, offset_size
, end
);
5847 data
+= offset_size
;
5850 maxprint
= (end
- data
) - 1;
5854 unsigned int kind_data
;
5855 gdb_index_symbol_kind kind
;
5856 const char *kind_name
;
5859 SAFE_BYTE_GET (kind_data
, data
, 1, end
);
5862 /* GCC computes the kind as the upper byte in the CU index
5863 word, and then right shifts it by the CU index size.
5864 Left shift KIND to where the gdb-index.h accessor macros
5866 kind_data
<<= GDB_INDEX_CU_BITSIZE
;
5867 kind
= GDB_INDEX_SYMBOL_KIND_VALUE (kind_data
);
5868 kind_name
= get_gdb_index_symbol_kind_name (kind
);
5869 is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (kind_data
);
5870 printf (" %-6lx %s,%-10s %.*s\n",
5871 (unsigned long) offset
, is_static
? _("s") : _("g"),
5872 kind_name
, (int) maxprint
, data
);
5875 printf (" %-6lx\t%.*s\n",
5876 (unsigned long) offset
, (int) maxprint
, data
);
5878 data
+= strnlen ((char *) data
, maxprint
) + 1;
5889 display_debug_pubnames (struct dwarf_section
*section
, void *file
)
5891 return display_debug_pubnames_worker (section
, file
, 0);
5895 display_debug_gnu_pubnames (struct dwarf_section
*section
, void *file
)
5897 return display_debug_pubnames_worker (section
, file
, 1);
5901 display_debug_macinfo (struct dwarf_section
*section
,
5902 void *file ATTRIBUTE_UNUSED
)
5904 unsigned char *start
= section
->start
;
5905 unsigned char *end
= start
+ section
->size
;
5906 unsigned char *curr
= start
;
5907 enum dwarf_macinfo_record_type op
;
5909 introduce (section
, false);
5913 unsigned int lineno
;
5914 const unsigned char *string
;
5916 op
= (enum dwarf_macinfo_record_type
) *curr
;
5921 case DW_MACINFO_start_file
:
5923 unsigned int filenum
;
5925 READ_ULEB (lineno
, curr
, end
);
5926 READ_ULEB (filenum
, curr
, end
);
5927 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"),
5932 case DW_MACINFO_end_file
:
5933 printf (_(" DW_MACINFO_end_file\n"));
5936 case DW_MACINFO_define
:
5937 READ_ULEB (lineno
, curr
, end
);
5939 curr
+= strnlen ((char *) string
, end
- string
) + 1;
5940 printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"),
5944 case DW_MACINFO_undef
:
5945 READ_ULEB (lineno
, curr
, end
);
5947 curr
+= strnlen ((char *) string
, end
- string
) + 1;
5948 printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"),
5952 case DW_MACINFO_vendor_ext
:
5954 unsigned int constant
;
5956 READ_ULEB (constant
, curr
, end
);
5958 curr
+= strnlen ((char *) string
, end
- string
) + 1;
5959 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"),
5969 /* Given LINE_OFFSET into the .debug_line section, attempt to return
5970 filename and dirname corresponding to file name table entry with index
5971 FILEIDX. Return NULL on failure. */
5973 static unsigned char *
5974 get_line_filename_and_dirname (dwarf_vma line_offset
,
5976 unsigned char **dir_name
)
5978 struct dwarf_section
*section
= &debug_displays
[line
].section
;
5979 unsigned char *hdrptr
, *dirtable
, *file_name
;
5980 unsigned int offset_size
, initial_length_size
;
5981 unsigned int version
, opcode_base
;
5982 dwarf_vma length
, diridx
;
5983 const unsigned char * end
;
5986 if (section
->start
== NULL
5987 || line_offset
>= section
->size
5991 hdrptr
= section
->start
+ line_offset
;
5992 end
= section
->start
+ section
->size
;
5994 SAFE_BYTE_GET_AND_INC (length
, hdrptr
, 4, end
);
5995 if (length
== 0xffffffff)
5997 /* This section is 64-bit DWARF 3. */
5998 SAFE_BYTE_GET_AND_INC (length
, hdrptr
, 8, end
);
6000 initial_length_size
= 12;
6005 initial_length_size
= 4;
6007 if (length
+ initial_length_size
< length
6008 || length
+ initial_length_size
> section
->size
)
6011 SAFE_BYTE_GET_AND_INC (version
, hdrptr
, 2, end
);
6012 if (version
!= 2 && version
!= 3 && version
!= 4)
6014 hdrptr
+= offset_size
+ 1;/* Skip prologue_length and min_insn_length. */
6016 hdrptr
++; /* Skip max_ops_per_insn. */
6017 hdrptr
+= 3; /* Skip default_is_stmt, line_base, line_range. */
6019 SAFE_BYTE_GET_AND_INC (opcode_base
, hdrptr
, 1, end
);
6020 if (opcode_base
== 0)
6023 hdrptr
+= opcode_base
- 1;
6028 /* Skip over dirname table. */
6029 while (*hdrptr
!= '\0')
6031 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
) + 1;
6035 hdrptr
++; /* Skip the NUL at the end of the table. */
6037 /* Now skip over preceding filename table entries. */
6038 for (; hdrptr
< end
&& *hdrptr
!= '\0' && fileidx
> 1; fileidx
--)
6040 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
) + 1;
6041 SKIP_ULEB (hdrptr
, end
);
6042 SKIP_ULEB (hdrptr
, end
);
6043 SKIP_ULEB (hdrptr
, end
);
6045 if (hdrptr
>= end
|| *hdrptr
== '\0')
6049 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
) + 1;
6052 READ_ULEB (diridx
, hdrptr
, end
);
6055 for (; dirtable
< end
&& *dirtable
!= '\0' && diridx
> 1; diridx
--)
6056 dirtable
+= strnlen ((char *) dirtable
, end
- dirtable
) + 1;
6057 if (dirtable
>= end
|| *dirtable
== '\0')
6059 *dir_name
= dirtable
;
6064 display_debug_macro (struct dwarf_section
*section
,
6067 unsigned char *start
= section
->start
;
6068 unsigned char *end
= start
+ section
->size
;
6069 unsigned char *curr
= start
;
6070 unsigned char *extended_op_buf
[256];
6071 bool is_dwo
= false;
6072 const char *suffix
= strrchr (section
->name
, '.');
6074 if (suffix
&& strcmp (suffix
, ".dwo") == 0)
6077 load_debug_section_with_follow (str
, file
);
6078 load_debug_section_with_follow (line
, file
);
6079 load_debug_section_with_follow (str_index
, file
);
6081 introduce (section
, false);
6085 unsigned int lineno
, version
, flags
;
6086 unsigned int offset_size
;
6087 const unsigned char *string
;
6088 dwarf_vma line_offset
= 0, sec_offset
= curr
- start
, offset
;
6089 unsigned char **extended_ops
= NULL
;
6091 SAFE_BYTE_GET_AND_INC (version
, curr
, 2, end
);
6092 if (version
!= 4 && version
!= 5)
6094 error (_("Expected to find a version number of 4 or 5 in section %s but found %d instead\n"),
6095 section
->name
, version
);
6099 SAFE_BYTE_GET_AND_INC (flags
, curr
, 1, end
);
6100 offset_size
= (flags
& 1) ? 8 : 4;
6101 printf (_(" Offset: 0x%lx\n"),
6102 (unsigned long) sec_offset
);
6103 printf (_(" Version: %d\n"), version
);
6104 printf (_(" Offset size: %d\n"), offset_size
);
6107 SAFE_BYTE_GET_AND_INC (line_offset
, curr
, offset_size
, end
);
6108 printf (_(" Offset into .debug_line: 0x%lx\n"),
6109 (unsigned long) line_offset
);
6113 unsigned int i
, count
, op
;
6116 SAFE_BYTE_GET_AND_INC (count
, curr
, 1, end
);
6118 memset (extended_op_buf
, 0, sizeof (extended_op_buf
));
6119 extended_ops
= extended_op_buf
;
6122 printf (_(" Extension opcode arguments:\n"));
6123 for (i
= 0; i
< count
; i
++)
6125 SAFE_BYTE_GET_AND_INC (op
, curr
, 1, end
);
6126 extended_ops
[op
] = curr
;
6127 READ_ULEB (nargs
, curr
, end
);
6129 printf (_(" DW_MACRO_%02x has no arguments\n"), op
);
6132 printf (_(" DW_MACRO_%02x arguments: "), op
);
6133 for (n
= 0; n
< nargs
; n
++)
6137 SAFE_BYTE_GET_AND_INC (form
, curr
, 1, end
);
6138 printf ("%s%s", get_FORM_name (form
),
6139 n
== nargs
- 1 ? "\n" : ", ");
6149 case DW_FORM_block1
:
6150 case DW_FORM_block2
:
6151 case DW_FORM_block4
:
6153 case DW_FORM_string
:
6155 case DW_FORM_sec_offset
:
6158 error (_("Invalid extension opcode form %s\n"),
6159 get_FORM_name (form
));
6175 error (_(".debug_macro section not zero terminated\n"));
6179 SAFE_BYTE_GET_AND_INC (op
, curr
, 1, end
);
6185 case DW_MACRO_define
:
6186 READ_ULEB (lineno
, curr
, end
);
6188 curr
+= strnlen ((char *) string
, end
- string
) + 1;
6189 printf (_(" DW_MACRO_define - lineno : %d macro : %s\n"),
6193 case DW_MACRO_undef
:
6194 READ_ULEB (lineno
, curr
, end
);
6196 curr
+= strnlen ((char *) string
, end
- string
) + 1;
6197 printf (_(" DW_MACRO_undef - lineno : %d macro : %s\n"),
6201 case DW_MACRO_start_file
:
6203 unsigned int filenum
;
6204 unsigned char *file_name
= NULL
, *dir_name
= NULL
;
6206 READ_ULEB (lineno
, curr
, end
);
6207 READ_ULEB (filenum
, curr
, end
);
6209 if ((flags
& 2) == 0)
6210 error (_("DW_MACRO_start_file used, but no .debug_line offset provided.\n"));
6213 = get_line_filename_and_dirname (line_offset
, filenum
,
6215 if (file_name
== NULL
)
6216 printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d\n"),
6219 printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d filename: %s%s%s\n"),
6221 dir_name
!= NULL
? (const char *) dir_name
: "",
6222 dir_name
!= NULL
? "/" : "", file_name
);
6226 case DW_MACRO_end_file
:
6227 printf (_(" DW_MACRO_end_file\n"));
6230 case DW_MACRO_define_strp
:
6231 READ_ULEB (lineno
, curr
, end
);
6232 if (version
== 4 && is_dwo
)
6233 READ_ULEB (offset
, curr
, end
);
6235 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6236 string
= fetch_indirect_string (offset
);
6237 printf (_(" DW_MACRO_define_strp - lineno : %d macro : %s\n"),
6241 case DW_MACRO_undef_strp
:
6242 READ_ULEB (lineno
, curr
, end
);
6243 if (version
== 4 && is_dwo
)
6244 READ_ULEB (offset
, curr
, end
);
6246 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6247 string
= fetch_indirect_string (offset
);
6248 printf (_(" DW_MACRO_undef_strp - lineno : %d macro : %s\n"),
6252 case DW_MACRO_import
:
6253 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6254 printf (_(" DW_MACRO_import - offset : 0x%lx\n"),
6255 (unsigned long) offset
);
6258 case DW_MACRO_define_sup
:
6259 READ_ULEB (lineno
, curr
, end
);
6260 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6261 printf (_(" DW_MACRO_define_sup - lineno : %d macro offset : 0x%lx\n"),
6262 lineno
, (unsigned long) offset
);
6265 case DW_MACRO_undef_sup
:
6266 READ_ULEB (lineno
, curr
, end
);
6267 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6268 printf (_(" DW_MACRO_undef_sup - lineno : %d macro offset : 0x%lx\n"),
6269 lineno
, (unsigned long) offset
);
6272 case DW_MACRO_import_sup
:
6273 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6274 printf (_(" DW_MACRO_import_sup - offset : 0x%lx\n"),
6275 (unsigned long) offset
);
6278 case DW_MACRO_define_strx
:
6279 case DW_MACRO_undef_strx
:
6280 READ_ULEB (lineno
, curr
, end
);
6281 READ_ULEB (offset
, curr
, end
);
6282 string
= (const unsigned char *)
6283 fetch_indexed_string (offset
, NULL
, offset_size
, false);
6284 if (op
== DW_MACRO_define_strx
)
6285 printf (" DW_MACRO_define_strx ");
6287 printf (" DW_MACRO_undef_strx ");
6289 printf (_("(with offset %s) "), dwarf_vmatoa ("x", offset
));
6290 printf (_("lineno : %d macro : %s\n"),
6295 if (op
>= DW_MACRO_lo_user
&& op
<= DW_MACRO_hi_user
)
6297 printf (_(" <Target Specific macro op: %#x - UNHANDLED"), op
);
6301 if (extended_ops
== NULL
|| extended_ops
[op
] == NULL
)
6303 error (_(" Unknown macro opcode %02x seen\n"), op
);
6308 /* Skip over unhandled opcodes. */
6310 unsigned char *desc
= extended_ops
[op
];
6311 READ_ULEB (nargs
, desc
, end
);
6314 printf (_(" DW_MACRO_%02x\n"), op
);
6317 printf (_(" DW_MACRO_%02x -"), op
);
6318 for (n
= 0; n
< nargs
; n
++)
6322 /* DW_FORM_implicit_const is not expected here. */
6323 SAFE_BYTE_GET_AND_INC (val
, desc
, 1, end
);
6325 = read_and_display_attr_value (0, val
, 0,
6326 start
, curr
, end
, 0, 0, offset_size
,
6327 version
, NULL
, 0, NULL
,
6345 display_debug_abbrev (struct dwarf_section
*section
,
6346 void *file ATTRIBUTE_UNUSED
)
6348 abbrev_entry
*entry
;
6349 unsigned char *start
= section
->start
;
6351 introduce (section
, false);
6358 offset
= start
- section
->start
;
6359 list
= find_abbrev_list_by_abbrev_offset (0, offset
);
6362 list
= new_abbrev_list (0, offset
);
6363 start
= process_abbrev_set (section
, 0, section
->size
, offset
, list
);
6364 list
->start_of_next_abbrevs
= start
;
6367 start
= list
->start_of_next_abbrevs
;
6369 if (list
->first_abbrev
== NULL
)
6372 printf (_(" Number TAG (0x%lx)\n"), (long) offset
);
6374 for (entry
= list
->first_abbrev
; entry
; entry
= entry
->next
)
6378 printf (" %ld %s [%s]\n",
6380 get_TAG_name (entry
->tag
),
6381 entry
->children
? _("has children") : _("no children"));
6383 for (attr
= entry
->first_attr
; attr
; attr
= attr
->next
)
6385 printf (" %-18s %s",
6386 get_AT_name (attr
->attribute
),
6387 get_FORM_name (attr
->form
));
6388 if (attr
->form
== DW_FORM_implicit_const
)
6389 printf (": %" BFD_VMA_FMT
"d", attr
->implicit_const
);
6401 /* Return true when ADDR is the maximum address, when addresses are
6402 POINTER_SIZE bytes long. */
6405 is_max_address (dwarf_vma addr
, unsigned int pointer_size
)
6407 dwarf_vma mask
= ~(~(dwarf_vma
) 1 << (pointer_size
* 8 - 1));
6408 return ((addr
& mask
) == mask
);
6411 /* Display a view pair list starting at *VSTART_PTR and ending at
6412 VLISTEND within SECTION. */
6415 display_view_pair_list (struct dwarf_section
*section
,
6416 unsigned char **vstart_ptr
,
6417 unsigned int debug_info_entry
,
6418 unsigned char *vlistend
)
6420 unsigned char *vstart
= *vstart_ptr
;
6421 unsigned char *section_end
= section
->start
+ section
->size
;
6422 unsigned int pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
6424 if (vlistend
< section_end
)
6425 section_end
= vlistend
;
6429 while (vstart
< section_end
)
6431 dwarf_vma off
= vstart
- section
->start
;
6432 dwarf_vma vbegin
, vend
;
6434 READ_ULEB (vbegin
, vstart
, section_end
);
6435 if (vstart
== section_end
)
6438 READ_ULEB (vend
, vstart
, section_end
);
6439 printf (" %8.8lx ", (unsigned long) off
);
6441 print_dwarf_view (vbegin
, pointer_size
, 1);
6442 print_dwarf_view (vend
, pointer_size
, 1);
6443 printf (_("location view pair\n"));
6447 *vstart_ptr
= vstart
;
6450 /* Display a location list from a normal (ie, non-dwo) .debug_loc section. */
6453 display_loc_list (struct dwarf_section
*section
,
6454 unsigned char **start_ptr
,
6455 unsigned int debug_info_entry
,
6457 dwarf_vma base_address
,
6458 unsigned char **vstart_ptr
,
6461 unsigned char *start
= *start_ptr
, *vstart
= *vstart_ptr
;
6462 unsigned char *section_end
= section
->start
+ section
->size
;
6463 unsigned long cu_offset
;
6464 unsigned int pointer_size
;
6465 unsigned int offset_size
;
6470 unsigned short length
;
6471 int need_frame_base
;
6473 if (debug_info_entry
>= num_debug_info_entries
)
6475 warn (_("No debug information available for loc lists of entry: %u\n"),
6480 cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
6481 pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
6482 offset_size
= debug_information
[debug_info_entry
].offset_size
;
6483 dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
6485 if (pointer_size
< 2 || pointer_size
> 8)
6487 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
6488 pointer_size
, debug_info_entry
);
6494 dwarf_vma off
= offset
+ (start
- *start_ptr
);
6495 dwarf_vma vbegin
= vm1
, vend
= vm1
;
6497 if (start
+ 2 * pointer_size
> section_end
)
6499 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6500 (unsigned long) offset
);
6504 printf (" %8.8lx ", (unsigned long) off
);
6506 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, section_end
);
6507 SAFE_BYTE_GET_AND_INC (end
, start
, pointer_size
, section_end
);
6509 if (begin
== 0 && end
== 0)
6511 /* PR 18374: In a object file we can have a location list that
6512 starts with a begin and end of 0 because there are relocations
6513 that need to be applied to the addresses. Actually applying
6514 the relocations now does not help as they will probably resolve
6515 to 0, since the object file has not been fully linked. Real
6516 end of list markers will not have any relocations against them. */
6517 if (! reloc_at (section
, off
)
6518 && ! reloc_at (section
, off
+ pointer_size
))
6520 printf (_("<End of list>\n"));
6525 /* Check base address specifiers. */
6526 if (is_max_address (begin
, pointer_size
)
6527 && !is_max_address (end
, pointer_size
))
6530 print_dwarf_vma (begin
, pointer_size
);
6531 print_dwarf_vma (end
, pointer_size
);
6532 printf (_("(base address)\n"));
6538 off
= offset
+ (vstart
- *start_ptr
);
6540 READ_ULEB (vbegin
, vstart
, section_end
);
6541 print_dwarf_view (vbegin
, pointer_size
, 1);
6543 READ_ULEB (vend
, vstart
, section_end
);
6544 print_dwarf_view (vend
, pointer_size
, 1);
6546 printf (_("views at %8.8lx for:\n %*s "),
6547 (unsigned long) off
, 8, "");
6550 if (start
+ 2 > section_end
)
6552 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6553 (unsigned long) offset
);
6557 SAFE_BYTE_GET_AND_INC (length
, start
, 2, section_end
);
6559 if (start
+ length
> section_end
)
6561 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6562 (unsigned long) offset
);
6566 print_dwarf_vma (begin
+ base_address
, pointer_size
);
6567 print_dwarf_vma (end
+ base_address
, pointer_size
);
6570 need_frame_base
= decode_location_expression (start
,
6575 cu_offset
, section
);
6578 if (need_frame_base
&& !has_frame_base
)
6579 printf (_(" [without DW_AT_frame_base]"));
6581 if (begin
== end
&& vbegin
== vend
)
6582 fputs (_(" (start == end)"), stdout
);
6583 else if (begin
> end
|| (begin
== end
&& vbegin
> vend
))
6584 fputs (_(" (start > end)"), stdout
);
6592 *vstart_ptr
= vstart
;
6595 /* Display a location list from a normal (ie, non-dwo) .debug_loclists section. */
6598 display_loclists_list (struct dwarf_section
*section
,
6599 unsigned char **start_ptr
,
6600 unsigned int debug_info_entry
,
6602 dwarf_vma base_address
,
6603 unsigned char **vstart_ptr
,
6606 unsigned char *start
= *start_ptr
, *vstart
= *vstart_ptr
;
6607 unsigned char *section_end
= section
->start
+ section
->size
;
6608 unsigned long cu_offset
;
6609 unsigned int pointer_size
;
6610 unsigned int offset_size
;
6613 /* Initialize it due to a false compiler warning. */
6614 dwarf_vma begin
= -1, vbegin
= -1;
6615 dwarf_vma end
= -1, vend
= -1;
6617 int need_frame_base
;
6619 if (debug_info_entry
>= num_debug_info_entries
)
6621 warn (_("No debug information available for "
6622 "loclists lists of entry: %u\n"),
6627 cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
6628 pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
6629 offset_size
= debug_information
[debug_info_entry
].offset_size
;
6630 dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
6632 if (pointer_size
< 2 || pointer_size
> 8)
6634 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
6635 pointer_size
, debug_info_entry
);
6641 dwarf_vma off
= offset
+ (start
- *start_ptr
);
6642 enum dwarf_location_list_entry_type llet
;
6644 if (start
+ 1 > section_end
)
6646 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6647 (unsigned long) offset
);
6651 printf (" %8.8lx ", (unsigned long) off
);
6653 SAFE_BYTE_GET_AND_INC (llet
, start
, 1, section_end
);
6655 if (vstart
&& (llet
== DW_LLE_offset_pair
6656 || llet
== DW_LLE_start_end
6657 || llet
== DW_LLE_start_length
))
6659 off
= offset
+ (vstart
- *start_ptr
);
6661 READ_ULEB (vbegin
, vstart
, section_end
);
6662 print_dwarf_view (vbegin
, pointer_size
, 1);
6664 READ_ULEB (vend
, vstart
, section_end
);
6665 print_dwarf_view (vend
, pointer_size
, 1);
6667 printf (_("views at %8.8lx for:\n %*s "),
6668 (unsigned long) off
, 8, "");
6673 case DW_LLE_end_of_list
:
6674 printf (_("<End of list>\n"));
6676 case DW_LLE_offset_pair
:
6677 READ_ULEB (begin
, start
, section_end
);
6678 begin
+= base_address
;
6679 READ_ULEB (end
, start
, section_end
);
6680 end
+= base_address
;
6682 case DW_LLE_start_end
:
6683 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, section_end
);
6684 SAFE_BYTE_GET_AND_INC (end
, start
, pointer_size
, section_end
);
6686 case DW_LLE_start_length
:
6687 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, section_end
);
6688 READ_ULEB (end
, start
, section_end
);
6691 case DW_LLE_base_address
:
6692 SAFE_BYTE_GET_AND_INC (base_address
, start
, pointer_size
,
6694 print_dwarf_vma (base_address
, pointer_size
);
6695 printf (_("(base address)\n"));
6697 #ifdef DW_LLE_view_pair
6698 case DW_LLE_view_pair
:
6700 printf (_("View pair entry in loclist with locviews attribute\n"));
6701 READ_ULEB (vbegin
, start
, section_end
);
6702 print_dwarf_view (vbegin
, pointer_size
, 1);
6704 READ_ULEB (vend
, start
, section_end
);
6705 print_dwarf_view (vend
, pointer_size
, 1);
6707 printf (_("views for:\n"));
6711 error (_("Invalid location list entry type %d\n"), llet
);
6714 if (llet
== DW_LLE_end_of_list
)
6716 if (llet
!= DW_LLE_offset_pair
6717 && llet
!= DW_LLE_start_end
6718 && llet
!= DW_LLE_start_length
)
6721 if (start
+ 2 > section_end
)
6723 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6724 (unsigned long) offset
);
6728 READ_ULEB (length
, start
, section_end
);
6730 print_dwarf_vma (begin
, pointer_size
);
6731 print_dwarf_vma (end
, pointer_size
);
6734 need_frame_base
= decode_location_expression (start
,
6739 cu_offset
, section
);
6742 if (need_frame_base
&& !has_frame_base
)
6743 printf (_(" [without DW_AT_frame_base]"));
6745 if (begin
== end
&& vbegin
== vend
)
6746 fputs (_(" (start == end)"), stdout
);
6747 else if (begin
> end
|| (begin
== end
&& vbegin
> vend
))
6748 fputs (_(" (start > end)"), stdout
);
6756 if (vbegin
!= vm1
|| vend
!= vm1
)
6757 printf (_("Trailing view pair not used in a range"));
6760 *vstart_ptr
= vstart
;
6763 /* Print a .debug_addr table index in decimal, surrounded by square brackets,
6764 right-adjusted in a field of length LEN, and followed by a space. */
6767 print_addr_index (unsigned int idx
, unsigned int len
)
6769 static char buf
[15];
6770 snprintf (buf
, sizeof (buf
), "[%d]", idx
);
6771 printf ("%*s ", len
, buf
);
6774 /* Display a location list from a .dwo section. It uses address indexes rather
6775 than embedded addresses. This code closely follows display_loc_list, but the
6776 two are sufficiently different that combining things is very ugly. */
6779 display_loc_list_dwo (struct dwarf_section
*section
,
6780 unsigned char **start_ptr
,
6781 unsigned int debug_info_entry
,
6783 unsigned char **vstart_ptr
,
6786 unsigned char *start
= *start_ptr
, *vstart
= *vstart_ptr
;
6787 unsigned char *section_end
= section
->start
+ section
->size
;
6788 unsigned long cu_offset
;
6789 unsigned int pointer_size
;
6790 unsigned int offset_size
;
6793 unsigned short length
;
6794 int need_frame_base
;
6797 if (debug_info_entry
>= num_debug_info_entries
)
6799 warn (_("No debug information for loc lists of entry: %u\n"),
6804 cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
6805 pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
6806 offset_size
= debug_information
[debug_info_entry
].offset_size
;
6807 dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
6809 if (pointer_size
< 2 || pointer_size
> 8)
6811 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
6812 pointer_size
, debug_info_entry
);
6818 printf (" %8.8lx ", (unsigned long) (offset
+ (start
- *start_ptr
)));
6820 if (start
>= section_end
)
6822 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6823 (unsigned long) offset
);
6827 SAFE_BYTE_GET_AND_INC (entry_type
, start
, 1, section_end
);
6840 dwarf_vma off
= offset
+ (vstart
- *start_ptr
);
6842 READ_ULEB (view
, vstart
, section_end
);
6843 print_dwarf_view (view
, 8, 1);
6845 READ_ULEB (view
, vstart
, section_end
);
6846 print_dwarf_view (view
, 8, 1);
6848 printf (_("views at %8.8lx for:\n %*s "),
6849 (unsigned long) off
, 8, "");
6857 case 0: /* A terminating entry. */
6859 *vstart_ptr
= vstart
;
6860 printf (_("<End of list>\n"));
6862 case 1: /* A base-address entry. */
6863 READ_ULEB (idx
, start
, section_end
);
6864 print_addr_index (idx
, 8);
6865 printf ("%*s", 9 + (vstart
? 2 * 6 : 0), "");
6866 printf (_("(base address selection entry)\n"));
6868 case 2: /* A start/end entry. */
6869 READ_ULEB (idx
, start
, section_end
);
6870 print_addr_index (idx
, 8);
6871 READ_ULEB (idx
, start
, section_end
);
6872 print_addr_index (idx
, 8);
6874 case 3: /* A start/length entry. */
6875 READ_ULEB (idx
, start
, section_end
);
6876 print_addr_index (idx
, 8);
6877 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
6878 printf ("%08x ", idx
);
6880 case 4: /* An offset pair entry. */
6881 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
6882 printf ("%08x ", idx
);
6883 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
6884 printf ("%08x ", idx
);
6887 warn (_("Unknown location list entry type 0x%x.\n"), entry_type
);
6889 *vstart_ptr
= vstart
;
6893 if (start
+ 2 > section_end
)
6895 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6896 (unsigned long) offset
);
6900 SAFE_BYTE_GET_AND_INC (length
, start
, 2, section_end
);
6901 if (start
+ length
> section_end
)
6903 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6904 (unsigned long) offset
);
6909 need_frame_base
= decode_location_expression (start
,
6914 cu_offset
, section
);
6917 if (need_frame_base
&& !has_frame_base
)
6918 printf (_(" [without DW_AT_frame_base]"));
6926 *vstart_ptr
= vstart
;
6929 /* Sort array of indexes in ascending order of loc_offsets[idx] and
6932 static dwarf_vma
*loc_offsets
, *loc_views
;
6935 loc_offsets_compar (const void *ap
, const void *bp
)
6937 dwarf_vma a
= loc_offsets
[*(const unsigned int *) ap
];
6938 dwarf_vma b
= loc_offsets
[*(const unsigned int *) bp
];
6940 int ret
= (a
> b
) - (b
> a
);
6944 a
= loc_views
[*(const unsigned int *) ap
];
6945 b
= loc_views
[*(const unsigned int *) bp
];
6947 ret
= (a
> b
) - (b
> a
);
6953 display_debug_loc (struct dwarf_section
*section
, void *file
)
6955 unsigned char *start
= section
->start
, *vstart
= NULL
;
6956 unsigned long bytes
;
6957 unsigned char *section_begin
= start
;
6958 unsigned int num_loc_list
= 0;
6959 unsigned long last_offset
= 0;
6960 unsigned long last_view
= 0;
6961 unsigned int first
= 0;
6964 int seen_first_offset
= 0;
6965 int locs_sorted
= 1;
6966 unsigned char *next
= start
, *vnext
= vstart
;
6967 unsigned int *array
= NULL
;
6968 const char *suffix
= strrchr (section
->name
, '.');
6969 bool is_dwo
= false;
6970 int is_loclists
= strstr (section
->name
, "debug_loclists") != NULL
;
6971 dwarf_vma expected_start
= 0;
6973 if (suffix
&& strcmp (suffix
, ".dwo") == 0)
6976 bytes
= section
->size
;
6980 printf (_("\nThe %s section is empty.\n"), section
->name
);
6986 unsigned char *hdrptr
= section_begin
;
6987 dwarf_vma ll_length
;
6988 unsigned short ll_version
;
6989 unsigned char *end
= section_begin
+ section
->size
;
6990 unsigned char address_size
, segment_selector_size
;
6991 uint32_t offset_entry_count
;
6993 SAFE_BYTE_GET_AND_INC (ll_length
, hdrptr
, 4, end
);
6994 if (ll_length
== 0xffffffff)
6995 SAFE_BYTE_GET_AND_INC (ll_length
, hdrptr
, 8, end
);
6997 SAFE_BYTE_GET_AND_INC (ll_version
, hdrptr
, 2, end
);
6998 if (ll_version
!= 5)
7000 warn (_("The %s section contains corrupt or "
7001 "unsupported version number: %d.\n"),
7002 section
->name
, ll_version
);
7006 SAFE_BYTE_GET_AND_INC (address_size
, hdrptr
, 1, end
);
7008 SAFE_BYTE_GET_AND_INC (segment_selector_size
, hdrptr
, 1, end
);
7009 if (segment_selector_size
!= 0)
7011 warn (_("The %s section contains "
7012 "unsupported segment selector size: %d.\n"),
7013 section
->name
, segment_selector_size
);
7017 SAFE_BYTE_GET_AND_INC (offset_entry_count
, hdrptr
, 4, end
);
7018 if (offset_entry_count
!= 0)
7020 warn (_("The %s section contains "
7021 "unsupported offset entry count: %d.\n"),
7022 section
->name
, offset_entry_count
);
7026 expected_start
= hdrptr
- section_begin
;
7029 if (load_debug_info (file
) == 0)
7031 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
7036 /* Check the order of location list in .debug_info section. If
7037 offsets of location lists are in the ascending order, we can
7038 use `debug_information' directly. */
7039 for (i
= 0; i
< num_debug_info_entries
; i
++)
7043 num
= debug_information
[i
].num_loc_offsets
;
7044 if (num
> num_loc_list
)
7047 /* Check if we can use `debug_information' directly. */
7048 if (locs_sorted
&& num
!= 0)
7050 if (!seen_first_offset
)
7052 /* This is the first location list. */
7053 last_offset
= debug_information
[i
].loc_offsets
[0];
7054 last_view
= debug_information
[i
].loc_views
[0];
7056 seen_first_offset
= 1;
7062 for (; j
< num
; j
++)
7065 debug_information
[i
].loc_offsets
[j
]
7066 || (last_offset
== debug_information
[i
].loc_offsets
[j
]
7067 && last_view
> debug_information
[i
].loc_views
[j
]))
7072 last_offset
= debug_information
[i
].loc_offsets
[j
];
7073 last_view
= debug_information
[i
].loc_views
[j
];
7078 if (!seen_first_offset
)
7079 error (_("No location lists in .debug_info section!\n"));
7081 if (debug_information
[first
].num_loc_offsets
> 0
7082 && debug_information
[first
].loc_offsets
[0] != expected_start
7083 && debug_information
[first
].loc_views
[0] != expected_start
)
7084 warn (_("Location lists in %s section start at 0x%s\n"),
7086 dwarf_vmatoa ("x", debug_information
[first
].loc_offsets
[0]));
7089 array
= (unsigned int *) xcmalloc (num_loc_list
, sizeof (unsigned int));
7091 introduce (section
, false);
7093 if (reloc_at (section
, 0))
7094 printf (_(" Warning: This section has relocations - addresses seen here may not be accurate.\n\n"));
7096 printf (_(" Offset Begin End Expression\n"));
7098 seen_first_offset
= 0;
7099 for (i
= first
; i
< num_debug_info_entries
; i
++)
7101 dwarf_vma offset
, voffset
;
7102 dwarf_vma base_address
;
7108 for (k
= 0; k
< debug_information
[i
].num_loc_offsets
; k
++)
7110 loc_offsets
= debug_information
[i
].loc_offsets
;
7111 loc_views
= debug_information
[i
].loc_views
;
7112 qsort (array
, debug_information
[i
].num_loc_offsets
,
7113 sizeof (*array
), loc_offsets_compar
);
7116 int adjacent_view_loclists
= 1;
7117 for (k
= 0; k
< debug_information
[i
].num_loc_offsets
; k
++)
7119 j
= locs_sorted
? k
: array
[k
];
7121 && (debug_information
[i
].loc_offsets
[locs_sorted
7122 ? k
- 1 : array
[k
- 1]]
7123 == debug_information
[i
].loc_offsets
[j
])
7124 && (debug_information
[i
].loc_views
[locs_sorted
7125 ? k
- 1 : array
[k
- 1]]
7126 == debug_information
[i
].loc_views
[j
]))
7128 has_frame_base
= debug_information
[i
].have_frame_base
[j
];
7129 offset
= debug_information
[i
].loc_offsets
[j
];
7130 next
= section_begin
+ offset
;
7131 voffset
= debug_information
[i
].loc_views
[j
];
7133 vnext
= section_begin
+ voffset
;
7136 base_address
= debug_information
[i
].base_address
;
7138 if (vnext
&& vnext
< next
)
7141 display_view_pair_list (section
, &vstart
, i
, next
);
7146 if (!seen_first_offset
|| !adjacent_view_loclists
)
7147 seen_first_offset
= 1;
7151 warn (_("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n"),
7152 (unsigned long) (start
- section_begin
),
7153 (unsigned long) offset
);
7154 else if (start
> next
)
7155 warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n"),
7156 (unsigned long) (start
- section_begin
),
7157 (unsigned long) offset
);
7162 if (offset
>= bytes
)
7164 warn (_("Offset 0x%lx is bigger than .debug_loc section size.\n"),
7165 (unsigned long) offset
);
7169 if (vnext
&& voffset
>= bytes
)
7171 warn (_("View Offset 0x%lx is bigger than .debug_loc section size.\n"),
7172 (unsigned long) voffset
);
7179 display_loc_list_dwo (section
, &start
, i
, offset
,
7180 &vstart
, has_frame_base
);
7182 display_loc_list (section
, &start
, i
, offset
, base_address
,
7183 &vstart
, has_frame_base
);
7188 warn (_("DWO is not yet supported.\n"));
7190 display_loclists_list (section
, &start
, i
, offset
, base_address
,
7191 &vstart
, has_frame_base
);
7194 /* FIXME: this arrangement is quite simplistic. Nothing
7195 requires locview lists to be adjacent to corresponding
7196 loclists, and a single loclist could be augmented by
7197 different locview lists, and vice-versa, unlikely as it
7198 is that it would make sense to do so. Hopefully we'll
7199 have view pair support built into loclists before we ever
7200 need to address all these possibilities. */
7201 if (adjacent_view_loclists
&& vnext
7202 && vnext
!= start
&& vstart
!= next
)
7204 adjacent_view_loclists
= 0;
7205 warn (_("Hole and overlap detection requires adjacent view lists and loclists.\n"));
7208 if (vnext
&& vnext
== start
)
7209 display_view_pair_list (section
, &start
, i
, vstart
);
7213 if (start
< section
->start
+ section
->size
)
7214 warn (ngettext ("There is %ld unused byte at the end of section %s\n",
7215 "There are %ld unused bytes at the end of section %s\n",
7216 (long) (section
->start
+ section
->size
- start
)),
7217 (long) (section
->start
+ section
->size
- start
), section
->name
);
7224 display_debug_str (struct dwarf_section
*section
,
7225 void *file ATTRIBUTE_UNUSED
)
7227 unsigned char *start
= section
->start
;
7228 unsigned long bytes
= section
->size
;
7229 dwarf_vma addr
= section
->address
;
7233 printf (_("\nThe %s section is empty.\n"), section
->name
);
7237 introduce (section
, false);
7245 lbytes
= (bytes
> 16 ? 16 : bytes
);
7247 printf (" 0x%8.8lx ", (unsigned long) addr
);
7249 for (j
= 0; j
< 16; j
++)
7252 printf ("%2.2x", start
[j
]);
7260 for (j
= 0; j
< lbytes
; j
++)
7263 if (k
>= ' ' && k
< 0x80)
7282 display_debug_info (struct dwarf_section
*section
, void *file
)
7284 return process_debug_info (section
, file
, section
->abbrev_sec
, false, false);
7288 display_debug_types (struct dwarf_section
*section
, void *file
)
7290 return process_debug_info (section
, file
, section
->abbrev_sec
, false, true);
7294 display_trace_info (struct dwarf_section
*section
, void *file
)
7296 return process_debug_info (section
, file
, section
->abbrev_sec
, false, true);
7300 display_debug_aranges (struct dwarf_section
*section
,
7301 void *file ATTRIBUTE_UNUSED
)
7303 unsigned char *start
= section
->start
;
7304 unsigned char *end
= start
+ section
->size
;
7306 introduce (section
, false);
7308 /* It does not matter if this load fails,
7309 we test for that later on. */
7310 load_debug_info (file
);
7314 unsigned char *hdrptr
;
7315 DWARF2_Internal_ARange arange
;
7316 unsigned char *addr_ranges
;
7319 unsigned long sec_off
;
7320 unsigned char address_size
;
7322 unsigned int offset_size
;
7323 unsigned int initial_length_size
;
7327 SAFE_BYTE_GET_AND_INC (arange
.ar_length
, hdrptr
, 4, end
);
7328 if (arange
.ar_length
== 0xffffffff)
7330 SAFE_BYTE_GET_AND_INC (arange
.ar_length
, hdrptr
, 8, end
);
7332 initial_length_size
= 12;
7337 initial_length_size
= 4;
7340 sec_off
= hdrptr
- section
->start
;
7341 if (sec_off
+ arange
.ar_length
< sec_off
7342 || sec_off
+ arange
.ar_length
> section
->size
)
7344 warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"),
7346 sec_off
- initial_length_size
,
7347 dwarf_vmatoa ("x", arange
.ar_length
));
7351 SAFE_BYTE_GET_AND_INC (arange
.ar_version
, hdrptr
, 2, end
);
7352 SAFE_BYTE_GET_AND_INC (arange
.ar_info_offset
, hdrptr
, offset_size
, end
);
7354 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
7355 && num_debug_info_entries
> 0
7356 && find_debug_info_for_offset (arange
.ar_info_offset
) == NULL
)
7357 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
7358 (unsigned long) arange
.ar_info_offset
, section
->name
);
7360 SAFE_BYTE_GET_AND_INC (arange
.ar_pointer_size
, hdrptr
, 1, end
);
7361 SAFE_BYTE_GET_AND_INC (arange
.ar_segment_size
, hdrptr
, 1, end
);
7363 if (arange
.ar_version
!= 2 && arange
.ar_version
!= 3)
7365 /* PR 19872: A version number of 0 probably means that there is
7366 padding at the end of the .debug_aranges section. Gold puts
7367 it there when performing an incremental link, for example.
7368 So do not generate a warning in this case. */
7369 if (arange
.ar_version
)
7370 warn (_("Only DWARF 2 and 3 aranges are currently supported.\n"));
7374 printf (_(" Length: %ld\n"),
7375 (long) arange
.ar_length
);
7376 printf (_(" Version: %d\n"), arange
.ar_version
);
7377 printf (_(" Offset into .debug_info: 0x%lx\n"),
7378 (unsigned long) arange
.ar_info_offset
);
7379 printf (_(" Pointer Size: %d\n"), arange
.ar_pointer_size
);
7380 printf (_(" Segment Size: %d\n"), arange
.ar_segment_size
);
7382 address_size
= arange
.ar_pointer_size
+ arange
.ar_segment_size
;
7384 /* PR 17512: file: 001-108546-0.001:0.1. */
7385 if (address_size
== 0 || address_size
> 8)
7387 error (_("Invalid address size in %s section!\n"),
7392 /* The DWARF spec does not require that the address size be a power
7393 of two, but we do. This will have to change if we ever encounter
7394 an uneven architecture. */
7395 if ((address_size
& (address_size
- 1)) != 0)
7397 warn (_("Pointer size + Segment size is not a power of two.\n"));
7401 if (address_size
> 4)
7402 printf (_("\n Address Length\n"));
7404 printf (_("\n Address Length\n"));
7406 addr_ranges
= hdrptr
;
7408 /* Must pad to an alignment boundary that is twice the address size. */
7409 excess
= (hdrptr
- start
) % (2 * address_size
);
7411 addr_ranges
+= (2 * address_size
) - excess
;
7413 start
+= arange
.ar_length
+ initial_length_size
;
7415 while (addr_ranges
+ 2 * address_size
<= start
)
7417 SAFE_BYTE_GET_AND_INC (address
, addr_ranges
, address_size
, end
);
7418 SAFE_BYTE_GET_AND_INC (length
, addr_ranges
, address_size
, end
);
7421 print_dwarf_vma (address
, address_size
);
7422 print_dwarf_vma (length
, address_size
);
7432 /* Comparison function for qsort. */
7434 comp_addr_base (const void * v0
, const void * v1
)
7436 debug_info
*info0
= *(debug_info
**) v0
;
7437 debug_info
*info1
= *(debug_info
**) v1
;
7438 return info0
->addr_base
- info1
->addr_base
;
7441 /* Display the debug_addr section. */
7443 display_debug_addr (struct dwarf_section
*section
,
7446 debug_info
**debug_addr_info
;
7447 unsigned char *entry
;
7451 unsigned char * header
;
7453 if (section
->size
== 0)
7455 printf (_("\nThe %s section is empty.\n"), section
->name
);
7459 if (load_debug_info (file
) == 0)
7461 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
7466 introduce (section
, false);
7468 /* PR 17531: file: cf38d01b.
7469 We use xcalloc because a corrupt file may not have initialised all of the
7470 fields in the debug_info structure, which means that the sort below might
7471 try to move uninitialised data. */
7472 debug_addr_info
= (debug_info
**) xcalloc ((num_debug_info_entries
+ 1),
7473 sizeof (debug_info
*));
7476 for (i
= 0; i
< num_debug_info_entries
; i
++)
7477 if (debug_information
[i
].addr_base
!= DEBUG_INFO_UNAVAILABLE
)
7479 /* PR 17531: file: cf38d01b. */
7480 if (debug_information
[i
].addr_base
>= section
->size
)
7481 warn (_("Corrupt address base (%lx) found in debug section %u\n"),
7482 (unsigned long) debug_information
[i
].addr_base
, i
);
7484 debug_addr_info
[count
++] = debug_information
+ i
;
7487 /* Add a sentinel to make iteration convenient. */
7488 debug_addr_info
[count
] = (debug_info
*) xmalloc (sizeof (debug_info
));
7489 debug_addr_info
[count
]->addr_base
= section
->size
;
7490 qsort (debug_addr_info
, count
, sizeof (debug_info
*), comp_addr_base
);
7492 header
= section
->start
;
7493 for (i
= 0; i
< count
; i
++)
7496 unsigned int address_size
= debug_addr_info
[i
]->pointer_size
;
7498 printf (_(" For compilation unit at offset 0x%s:\n"),
7499 dwarf_vmatoa ("x", debug_addr_info
[i
]->cu_offset
));
7501 printf (_("\tIndex\tAddress\n"));
7502 entry
= section
->start
+ debug_addr_info
[i
]->addr_base
;
7503 if (debug_addr_info
[i
]->dwarf_version
>= 5)
7505 size_t header_size
= entry
- header
;
7506 unsigned char * curr_header
= header
;
7509 int segment_selector_size
;
7511 if (header_size
!= 8 && header_size
!= 16)
7513 warn (_("Corrupt %s section: expecting header size of 8 or 16, but found %ld instead\n"),
7514 section
->name
, (long) header_size
);
7518 SAFE_BYTE_GET_AND_INC (length
, curr_header
, 4, entry
);
7519 if (length
== 0xffffffff)
7520 SAFE_BYTE_GET (length
, curr_header
, 8, entry
);
7521 end
= curr_header
+ length
;
7523 SAFE_BYTE_GET_AND_INC (version
, curr_header
, 2, entry
);
7525 warn (_("Corrupt %s section: expecting version number 5 in header but found %d instead\n"),
7526 section
->name
, version
);
7528 SAFE_BYTE_GET_AND_INC (address_size
, curr_header
, 1, entry
);
7529 SAFE_BYTE_GET_AND_INC (segment_selector_size
, curr_header
, 1, entry
);
7530 address_size
+= segment_selector_size
;
7533 end
= section
->start
+ debug_addr_info
[i
+ 1]->addr_base
;
7538 dwarf_vma base
= byte_get (entry
, address_size
);
7539 printf (_("\t%d:\t"), idx
);
7540 print_dwarf_vma (base
, address_size
);
7542 entry
+= address_size
;
7548 free (debug_addr_info
);
7552 /* Display the .debug_str_offsets and .debug_str_offsets.dwo sections. */
7555 display_debug_str_offsets (struct dwarf_section
*section
,
7556 void *file ATTRIBUTE_UNUSED
)
7560 if (section
->size
== 0)
7562 printf (_("\nThe %s section is empty.\n"), section
->name
);
7566 unsigned char *start
= section
->start
;
7567 unsigned char *end
= start
+ section
->size
;
7568 unsigned char *curr
= start
;
7570 const char *suffix
= strrchr (section
->name
, '.');
7571 bool dwo
= suffix
&& strcmp (suffix
, ".dwo") == 0;
7574 load_debug_section_with_follow (str_dwo
, file
);
7576 load_debug_section_with_follow (str
, file
);
7578 introduce (section
, false);
7583 dwarf_vma entry_length
;
7585 SAFE_BYTE_GET_AND_INC (length
, curr
, 4, end
);
7586 /* FIXME: We assume that this means 64-bit DWARF is being used. */
7587 if (length
== 0xffffffff)
7589 SAFE_BYTE_GET (length
, curr
, 8, end
);
7595 unsigned char *entries_end
;
7598 /* This is probably an old style .debug_str_offset section which
7599 just contains offsets and no header (and the first offset is 0). */
7600 length
= section
->size
;
7601 curr
= section
->start
;
7604 printf (_(" Length: %#lx\n"), (unsigned long) length
);
7605 printf (_(" Index Offset [String]\n"));
7609 entries_end
= curr
+ length
;
7612 SAFE_BYTE_GET_AND_INC (version
, curr
, 2, end
);
7614 warn (_("Unexpected version number in str_offset header: %#x\n"), version
);
7617 SAFE_BYTE_GET_AND_INC (padding
, curr
, 2, end
);
7619 warn (_("Unexpected value in str_offset header's padding field: %#x\n"), padding
);
7621 printf (_(" Length: %#lx\n"), (unsigned long) length
);
7622 printf (_(" Version: %#lx\n"), (unsigned long) version
);
7623 printf (_(" Index Offset [String]\n"));
7626 for (idx
= 0; curr
< entries_end
; idx
++)
7629 const unsigned char * string
;
7631 if (curr
+ entry_length
> entries_end
)
7632 /* Not enough space to read one entry_length, give up. */
7635 SAFE_BYTE_GET_AND_INC (offset
, curr
, entry_length
, end
);
7637 string
= (const unsigned char *)
7638 fetch_indexed_string (idx
, NULL
, entry_length
, dwo
);
7640 string
= fetch_indirect_string (offset
);
7642 printf (" %8lu %8s %s\n", idx
, dwarf_vmatoa ("x", offset
),
7650 /* Each debug_information[x].range_lists[y] gets this representation for
7651 sorting purposes. */
7655 /* The debug_information[x].range_lists[y] value. */
7656 dwarf_vma ranges_offset
;
7658 /* Original debug_information to find parameters of the data. */
7659 debug_info
*debug_info_p
;
7662 /* Sort struct range_entry in ascending order of its RANGES_OFFSET. */
7665 range_entry_compar (const void *ap
, const void *bp
)
7667 const struct range_entry
*a_re
= (const struct range_entry
*) ap
;
7668 const struct range_entry
*b_re
= (const struct range_entry
*) bp
;
7669 const dwarf_vma a
= a_re
->ranges_offset
;
7670 const dwarf_vma b
= b_re
->ranges_offset
;
7672 return (a
> b
) - (b
> a
);
7676 display_debug_ranges_list (unsigned char *start
, unsigned char *finish
,
7677 unsigned int pointer_size
, unsigned long offset
,
7678 unsigned long base_address
)
7680 while (start
< finish
)
7685 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
7686 if (start
>= finish
)
7688 SAFE_SIGNED_BYTE_GET_AND_INC (end
, start
, pointer_size
, finish
);
7690 printf (" %8.8lx ", offset
);
7692 if (begin
== 0 && end
== 0)
7694 printf (_("<End of list>\n"));
7698 /* Check base address specifiers. */
7699 if (is_max_address (begin
, pointer_size
)
7700 && !is_max_address (end
, pointer_size
))
7703 print_dwarf_vma (begin
, pointer_size
);
7704 print_dwarf_vma (end
, pointer_size
);
7705 printf ("(base address)\n");
7709 print_dwarf_vma (begin
+ base_address
, pointer_size
);
7710 print_dwarf_vma (end
+ base_address
, pointer_size
);
7713 fputs (_("(start == end)"), stdout
);
7714 else if (begin
> end
)
7715 fputs (_("(start > end)"), stdout
);
7722 display_debug_rnglists_list (unsigned char *start
, unsigned char *finish
,
7723 unsigned int pointer_size
, unsigned long offset
,
7724 unsigned long base_address
)
7726 unsigned char *next
= start
;
7730 unsigned long off
= offset
+ (start
- next
);
7731 enum dwarf_range_list_entry rlet
;
7732 /* Initialize it due to a false compiler warning. */
7733 dwarf_vma begin
= -1, length
, end
= -1;
7735 if (start
+ 1 > finish
)
7737 warn (_("Range list starting at offset 0x%lx is not terminated.\n"),
7742 printf (" %8.8lx ", off
);
7744 SAFE_BYTE_GET_AND_INC (rlet
, start
, 1, finish
);
7748 case DW_RLE_end_of_list
:
7749 printf (_("<End of list>\n"));
7751 case DW_RLE_base_address
:
7752 SAFE_BYTE_GET_AND_INC (base_address
, start
, pointer_size
, finish
);
7753 print_dwarf_vma (base_address
, pointer_size
);
7754 printf (_("(base address)\n"));
7756 case DW_RLE_start_length
:
7757 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
7758 READ_ULEB (length
, start
, finish
);
7759 end
= begin
+ length
;
7761 case DW_RLE_offset_pair
:
7762 READ_ULEB (begin
, start
, finish
);
7763 READ_ULEB (end
, start
, finish
);
7765 case DW_RLE_start_end
:
7766 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
7767 SAFE_BYTE_GET_AND_INC (end
, start
, pointer_size
, finish
);
7770 error (_("Invalid range list entry type %d\n"), rlet
);
7771 rlet
= DW_RLE_end_of_list
;
7774 if (rlet
== DW_RLE_end_of_list
)
7776 if (rlet
== DW_RLE_base_address
)
7779 /* Only a DW_RLE_offset_pair needs the base address added. */
7780 if (rlet
== DW_RLE_offset_pair
)
7782 begin
+= base_address
;
7783 end
+= base_address
;
7786 print_dwarf_vma (begin
, pointer_size
);
7787 print_dwarf_vma (end
, pointer_size
);
7790 fputs (_("(start == end)"), stdout
);
7791 else if (begin
> end
)
7792 fputs (_("(start > end)"), stdout
);
7799 display_debug_ranges (struct dwarf_section
*section
,
7800 void *file ATTRIBUTE_UNUSED
)
7802 unsigned char *start
= section
->start
;
7803 unsigned char *last_start
= start
;
7804 unsigned long bytes
= section
->size
;
7805 unsigned char *section_begin
= start
;
7806 unsigned char *finish
= start
+ bytes
;
7807 unsigned int num_range_list
, i
;
7808 struct range_entry
*range_entries
, *range_entry_fill
;
7809 int is_rnglists
= strstr (section
->name
, "debug_rnglists") != NULL
;
7810 /* Initialize it due to a false compiler warning. */
7811 unsigned char address_size
= 0;
7812 dwarf_vma last_offset
= 0;
7816 printf (_("\nThe %s section is empty.\n"), section
->name
);
7822 dwarf_vma initial_length
;
7823 unsigned int initial_length_size
;
7824 unsigned char segment_selector_size
;
7825 unsigned int offset_size
, offset_entry_count
;
7826 unsigned short version
;
7828 /* Get and check the length of the block. */
7829 SAFE_BYTE_GET_AND_INC (initial_length
, start
, 4, finish
);
7831 if (initial_length
== 0xffffffff)
7833 /* This section is 64-bit DWARF 3. */
7834 SAFE_BYTE_GET_AND_INC (initial_length
, start
, 8, finish
);
7836 initial_length_size
= 12;
7841 initial_length_size
= 4;
7844 if (initial_length
+ initial_length_size
> section
->size
)
7846 /* If the length field has a relocation against it, then we should
7847 not complain if it is inaccurate (and probably negative).
7848 It is copied from .debug_line handling code. */
7849 if (reloc_at (section
, (start
- section
->start
) - offset_size
))
7851 initial_length
= (finish
- start
) - initial_length_size
;
7855 warn (_("The length field (0x%lx) in the debug_rnglists header is wrong - the section is too small\n"),
7856 (long) initial_length
);
7861 /* Get and check the version number. */
7862 SAFE_BYTE_GET_AND_INC (version
, start
, 2, finish
);
7866 warn (_("Only DWARF version 5 debug_rnglists info "
7867 "is currently supported.\n"));
7871 SAFE_BYTE_GET_AND_INC (address_size
, start
, 1, finish
);
7873 SAFE_BYTE_GET_AND_INC (segment_selector_size
, start
, 1, finish
);
7874 if (segment_selector_size
!= 0)
7876 warn (_("The %s section contains "
7877 "unsupported segment selector size: %d.\n"),
7878 section
->name
, segment_selector_size
);
7882 SAFE_BYTE_GET_AND_INC (offset_entry_count
, start
, 4, finish
);
7883 if (offset_entry_count
!= 0)
7885 warn (_("The %s section contains "
7886 "unsupported offset entry count: %u.\n"),
7887 section
->name
, offset_entry_count
);
7892 if (load_debug_info (file
) == 0)
7894 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
7900 for (i
= 0; i
< num_debug_info_entries
; i
++)
7902 if (debug_information
[i
].dwarf_version
< 5 && is_rnglists
)
7903 /* Skip .debug_rnglists reference. */
7905 if (debug_information
[i
].dwarf_version
>= 5 && !is_rnglists
)
7906 /* Skip .debug_range reference. */
7908 num_range_list
+= debug_information
[i
].num_range_lists
;
7911 if (num_range_list
== 0)
7913 /* This can happen when the file was compiled with -gsplit-debug
7914 which removes references to range lists from the primary .o file. */
7915 printf (_("No range lists in .debug_info section.\n"));
7919 range_entries
= (struct range_entry
*)
7920 xmalloc (sizeof (*range_entries
) * num_range_list
);
7921 range_entry_fill
= range_entries
;
7923 for (i
= 0; i
< num_debug_info_entries
; i
++)
7925 debug_info
*debug_info_p
= &debug_information
[i
];
7928 if (debug_information
[i
].dwarf_version
< 5 && is_rnglists
)
7929 /* Skip .debug_rnglists reference. */
7931 if (debug_information
[i
].dwarf_version
>= 5 && !is_rnglists
)
7932 /* Skip .debug_range reference. */
7935 for (j
= 0; j
< debug_info_p
->num_range_lists
; j
++)
7937 range_entry_fill
->ranges_offset
= debug_info_p
->range_lists
[j
];
7938 range_entry_fill
->debug_info_p
= debug_info_p
;
7943 qsort (range_entries
, num_range_list
, sizeof (*range_entries
),
7944 range_entry_compar
);
7946 if (dwarf_check
!= 0 && range_entries
[0].ranges_offset
!= 0)
7947 warn (_("Range lists in %s section start at 0x%lx\n"),
7948 section
->name
, (unsigned long) range_entries
[0].ranges_offset
);
7950 introduce (section
, false);
7952 printf (_(" Offset Begin End\n"));
7954 for (i
= 0; i
< num_range_list
; i
++)
7956 struct range_entry
*range_entry
= &range_entries
[i
];
7957 debug_info
*debug_info_p
= range_entry
->debug_info_p
;
7958 unsigned int pointer_size
;
7960 unsigned char *next
;
7961 dwarf_vma base_address
;
7963 pointer_size
= (is_rnglists
? address_size
: debug_info_p
->pointer_size
);
7964 offset
= range_entry
->ranges_offset
;
7965 next
= section_begin
+ offset
;
7966 base_address
= debug_info_p
->base_address
;
7968 /* PR 17512: file: 001-101485-0.001:0.1. */
7969 if (pointer_size
< 2 || pointer_size
> 8)
7971 warn (_("Corrupt pointer size (%d) in debug entry at offset %8.8lx\n"),
7972 pointer_size
, (unsigned long) offset
);
7976 if (next
< section_begin
|| next
>= finish
)
7978 warn (_("Corrupt offset (%#8.8lx) in range entry %u\n"),
7979 (unsigned long) offset
, i
);
7983 /* If multiple DWARF entities reference the same range then we will
7984 have multiple entries in the `range_entries' list for the same
7985 offset. Thanks to the sort above these will all be consecutive in
7986 the `range_entries' list, so we can easily ignore duplicates
7988 if (i
> 0 && last_offset
== offset
)
7990 last_offset
= offset
;
7992 if (dwarf_check
!= 0 && i
> 0)
7995 warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"),
7996 (unsigned long) (start
- section_begin
),
7997 (unsigned long) (next
- section_begin
), section
->name
);
7998 else if (start
> next
)
8000 if (next
== last_start
)
8002 warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"),
8003 (unsigned long) (start
- section_begin
),
8004 (unsigned long) (next
- section_begin
), section
->name
);
8011 (is_rnglists
? display_debug_rnglists_list
: display_debug_ranges_list
)
8012 (start
, finish
, pointer_size
, offset
, base_address
);
8016 free (range_entries
);
8021 typedef struct Frame_Chunk
8023 struct Frame_Chunk
*next
;
8024 unsigned char *chunk_start
;
8026 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
8027 short int *col_type
;
8030 unsigned int code_factor
;
8034 unsigned int cfa_reg
;
8035 dwarf_vma cfa_offset
;
8037 unsigned char fde_encoding
;
8038 unsigned char cfa_exp
;
8039 unsigned char ptr_size
;
8040 unsigned char segment_size
;
8044 typedef const char *(*dwarf_regname_lookup_ftype
) (unsigned int);
8045 static dwarf_regname_lookup_ftype dwarf_regnames_lookup_func
;
8046 static const char *const *dwarf_regnames
;
8047 static unsigned int dwarf_regnames_count
;
8050 /* A marker for a col_type that means this column was never referenced
8051 in the frame info. */
8052 #define DW_CFA_unreferenced (-1)
8054 /* Return 0 if no more space is needed, 1 if more space is needed,
8055 -1 for invalid reg. */
8058 frame_need_space (Frame_Chunk
*fc
, unsigned int reg
)
8060 unsigned int prev
= fc
->ncols
;
8062 if (reg
< (unsigned int) fc
->ncols
)
8065 if (dwarf_regnames_count
> 0
8066 && reg
> dwarf_regnames_count
)
8069 fc
->ncols
= reg
+ 1;
8070 /* PR 17512: file: 10450-2643-0.004.
8071 If reg == -1 then this can happen... */
8075 /* PR 17512: file: 2844a11d. */
8076 if (fc
->ncols
> 1024 && dwarf_regnames_count
== 0)
8078 error (_("Unfeasibly large register number: %u\n"), reg
);
8080 /* FIXME: 1024 is an arbitrary limit. Increase it if
8081 we ever encounter a valid binary that exceeds it. */
8085 fc
->col_type
= (short int *) xcrealloc (fc
->col_type
, fc
->ncols
,
8086 sizeof (short int));
8087 fc
->col_offset
= (int *) xcrealloc (fc
->col_offset
, fc
->ncols
, sizeof (int));
8088 /* PR 17512: file:002-10025-0.005. */
8089 if (fc
->col_type
== NULL
|| fc
->col_offset
== NULL
)
8091 error (_("Out of memory allocating %u columns in dwarf frame arrays\n"),
8097 while (prev
< fc
->ncols
)
8099 fc
->col_type
[prev
] = DW_CFA_unreferenced
;
8100 fc
->col_offset
[prev
] = 0;
8106 static const char *const dwarf_regnames_i386
[] =
8108 "eax", "ecx", "edx", "ebx", /* 0 - 3 */
8109 "esp", "ebp", "esi", "edi", /* 4 - 7 */
8110 "eip", "eflags", NULL
, /* 8 - 10 */
8111 "st0", "st1", "st2", "st3", /* 11 - 14 */
8112 "st4", "st5", "st6", "st7", /* 15 - 18 */
8113 NULL
, NULL
, /* 19 - 20 */
8114 "xmm0", "xmm1", "xmm2", "xmm3", /* 21 - 24 */
8115 "xmm4", "xmm5", "xmm6", "xmm7", /* 25 - 28 */
8116 "mm0", "mm1", "mm2", "mm3", /* 29 - 32 */
8117 "mm4", "mm5", "mm6", "mm7", /* 33 - 36 */
8118 "fcw", "fsw", "mxcsr", /* 37 - 39 */
8119 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
, /* 40 - 47 */
8120 "tr", "ldtr", /* 48 - 49 */
8121 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 50 - 57 */
8122 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 58 - 65 */
8123 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 66 - 73 */
8124 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 74 - 81 */
8125 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 82 - 89 */
8126 NULL
, NULL
, NULL
, /* 90 - 92 */
8127 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7" /* 93 - 100 */
8130 static const char *const dwarf_regnames_iamcu
[] =
8132 "eax", "ecx", "edx", "ebx", /* 0 - 3 */
8133 "esp", "ebp", "esi", "edi", /* 4 - 7 */
8134 "eip", "eflags", NULL
, /* 8 - 10 */
8135 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 11 - 18 */
8136 NULL
, NULL
, /* 19 - 20 */
8137 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 21 - 28 */
8138 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 29 - 36 */
8139 NULL
, NULL
, NULL
, /* 37 - 39 */
8140 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
, /* 40 - 47 */
8141 "tr", "ldtr", /* 48 - 49 */
8142 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 50 - 57 */
8143 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 58 - 65 */
8144 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 66 - 73 */
8145 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 74 - 81 */
8146 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 82 - 89 */
8147 NULL
, NULL
, NULL
, /* 90 - 92 */
8148 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
/* 93 - 100 */
8152 init_dwarf_regnames_i386 (void)
8154 dwarf_regnames
= dwarf_regnames_i386
;
8155 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_i386
);
8156 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8160 init_dwarf_regnames_iamcu (void)
8162 dwarf_regnames
= dwarf_regnames_iamcu
;
8163 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_iamcu
);
8164 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8167 static const char *const dwarf_regnames_x86_64
[] =
8169 "rax", "rdx", "rcx", "rbx",
8170 "rsi", "rdi", "rbp", "rsp",
8171 "r8", "r9", "r10", "r11",
8172 "r12", "r13", "r14", "r15",
8174 "xmm0", "xmm1", "xmm2", "xmm3",
8175 "xmm4", "xmm5", "xmm6", "xmm7",
8176 "xmm8", "xmm9", "xmm10", "xmm11",
8177 "xmm12", "xmm13", "xmm14", "xmm15",
8178 "st0", "st1", "st2", "st3",
8179 "st4", "st5", "st6", "st7",
8180 "mm0", "mm1", "mm2", "mm3",
8181 "mm4", "mm5", "mm6", "mm7",
8183 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
,
8184 "fs.base", "gs.base", NULL
, NULL
,
8186 "mxcsr", "fcw", "fsw",
8187 "xmm16", "xmm17", "xmm18", "xmm19",
8188 "xmm20", "xmm21", "xmm22", "xmm23",
8189 "xmm24", "xmm25", "xmm26", "xmm27",
8190 "xmm28", "xmm29", "xmm30", "xmm31",
8191 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 83 - 90 */
8192 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 91 - 98 */
8193 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 99 - 106 */
8194 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 107 - 114 */
8195 NULL
, NULL
, NULL
, /* 115 - 117 */
8196 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7"
8200 init_dwarf_regnames_x86_64 (void)
8202 dwarf_regnames
= dwarf_regnames_x86_64
;
8203 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_x86_64
);
8204 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8207 static const char *const dwarf_regnames_aarch64
[] =
8209 "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7",
8210 "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15",
8211 "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23",
8212 "x24", "x25", "x26", "x27", "x28", "x29", "x30", "sp",
8213 NULL
, "elr", NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
8214 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, "vg", "ffr",
8215 "p0", "p1", "p2", "p3", "p4", "p5", "p6", "p7",
8216 "p8", "p9", "p10", "p11", "p12", "p13", "p14", "p15",
8217 "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7",
8218 "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15",
8219 "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23",
8220 "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31",
8221 "z0", "z1", "z2", "z3", "z4", "z5", "z6", "z7",
8222 "z8", "z9", "z10", "z11", "z12", "z13", "z14", "z15",
8223 "z16", "z17", "z18", "z19", "z20", "z21", "z22", "z23",
8224 "z24", "z25", "z26", "z27", "z28", "z29", "z30", "z31",
8228 init_dwarf_regnames_aarch64 (void)
8230 dwarf_regnames
= dwarf_regnames_aarch64
;
8231 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_aarch64
);
8232 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8235 static const char *const dwarf_regnames_s390
[] =
8237 /* Avoid saying "r5 (r5)", so omit the names of r0-r15. */
8238 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
8239 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
8240 "f0", "f2", "f4", "f6", "f1", "f3", "f5", "f7",
8241 "f8", "f10", "f12", "f14", "f9", "f11", "f13", "f15",
8242 "cr0", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7",
8243 "cr8", "cr9", "cr10", "cr11", "cr12", "cr13", "cr14", "cr15",
8244 "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7",
8245 "a8", "a9", "a10", "a11", "a12", "a13", "a14", "a15",
8248 "v16", "v18", "v20", "v22", "v17", "v19", "v21", "v23",
8249 "v24", "v26", "v28", "v30", "v25", "v27", "v29", "v31",
8253 init_dwarf_regnames_s390 (void)
8255 dwarf_regnames
= dwarf_regnames_s390
;
8256 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_s390
);
8257 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8260 static const char *const dwarf_regnames_riscv
[] =
8262 "zero", "ra", "sp", "gp", "tp", "t0", "t1", "t2", /* 0 - 7 */
8263 "s0", "s1", "a0", "a1", "a2", "a3", "a4", "a5", /* 8 - 15 */
8264 "a6", "a7", "s2", "s3", "s4", "s5", "s6", "s7", /* 16 - 23 */
8265 "s8", "s9", "s10", "s11", "t3", "t4", "t5", "t6", /* 24 - 31 */
8266 "ft0", "ft1", "ft2", "ft3", "ft4", "ft5", "ft6", "ft7", /* 32 - 39 */
8267 "fs0", "fs1", /* 40 - 41 */
8268 "fa0", "fa1", "fa2", "fa3", "fa4", "fa5", "fa6", "fa7", /* 42 - 49 */
8269 "fs2", "fs3", "fs4", "fs5", "fs6", "fs7", "fs8", "fs9", /* 50 - 57 */
8270 "fs10", "fs11", /* 58 - 59 */
8271 "ft8", "ft9", "ft10", "ft11" /* 60 - 63 */
8274 /* A RISC-V replacement for REGNAME_INTERNAL_BY_TABLE_ONLY which handles
8275 the large number of CSRs. */
8278 regname_internal_riscv (unsigned int regno
)
8280 const char *name
= NULL
;
8282 /* Lookup in the table first, this covers GPR and FPR. */
8283 if (regno
< ARRAY_SIZE (dwarf_regnames_riscv
))
8284 name
= dwarf_regnames_riscv
[regno
];
8285 else if (regno
>= 4096 && regno
<= 8191)
8287 /* This might be a CSR, these live in a sparse number space from 4096
8288 to 8191 These numbers are defined in the RISC-V ELF ABI
8292 #define DECLARE_CSR(NAME,VALUE,CLASS,DEFINE_VER,ABORT_VER) \
8293 case VALUE + 4096: name = #NAME; break;
8294 #include "opcode/riscv-opc.h"
8299 static char csr_name
[10];
8300 snprintf (csr_name
, sizeof (csr_name
), "csr%d", (regno
- 4096));
8311 init_dwarf_regnames_riscv (void)
8313 dwarf_regnames
= NULL
;
8314 dwarf_regnames_count
= 8192;
8315 dwarf_regnames_lookup_func
= regname_internal_riscv
;
8319 init_dwarf_regnames_by_elf_machine_code (unsigned int e_machine
)
8321 dwarf_regnames_lookup_func
= NULL
;
8326 init_dwarf_regnames_i386 ();
8330 init_dwarf_regnames_iamcu ();
8336 init_dwarf_regnames_x86_64 ();
8340 init_dwarf_regnames_aarch64 ();
8344 init_dwarf_regnames_s390 ();
8348 init_dwarf_regnames_riscv ();
8356 /* Initialize the DWARF register name lookup state based on the
8357 architecture and specific machine type of a BFD. */
8360 init_dwarf_regnames_by_bfd_arch_and_mach (enum bfd_architecture arch
,
8363 dwarf_regnames_lookup_func
= NULL
;
8370 case bfd_mach_x86_64
:
8371 case bfd_mach_x86_64_intel_syntax
:
8372 case bfd_mach_x64_32
:
8373 case bfd_mach_x64_32_intel_syntax
:
8374 init_dwarf_regnames_x86_64 ();
8378 init_dwarf_regnames_i386 ();
8383 case bfd_arch_iamcu
:
8384 init_dwarf_regnames_iamcu ();
8387 case bfd_arch_aarch64
:
8388 init_dwarf_regnames_aarch64();
8392 init_dwarf_regnames_s390 ();
8395 case bfd_arch_riscv
:
8396 init_dwarf_regnames_riscv ();
8405 regname_internal_by_table_only (unsigned int regno
)
8407 if (dwarf_regnames
!= NULL
8408 && regno
< dwarf_regnames_count
8409 && dwarf_regnames
[regno
] != NULL
)
8410 return dwarf_regnames
[regno
];
8416 regname (unsigned int regno
, int name_only_p
)
8418 static char reg
[64];
8420 const char *name
= NULL
;
8422 if (dwarf_regnames_lookup_func
!= NULL
)
8423 name
= dwarf_regnames_lookup_func (regno
);
8429 snprintf (reg
, sizeof (reg
), "r%d (%s)", regno
, name
);
8432 snprintf (reg
, sizeof (reg
), "r%d", regno
);
8437 frame_display_row (Frame_Chunk
*fc
, int *need_col_headers
, unsigned int *max_regs
)
8442 if (*max_regs
!= fc
->ncols
)
8443 *max_regs
= fc
->ncols
;
8445 if (*need_col_headers
)
8447 *need_col_headers
= 0;
8449 printf ("%-*s CFA ", eh_addr_size
* 2, " LOC");
8451 for (r
= 0; r
< *max_regs
; r
++)
8452 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
8457 printf ("%-5s ", regname (r
, 1));
8463 print_dwarf_vma (fc
->pc_begin
, eh_addr_size
);
8465 strcpy (tmp
, "exp");
8467 sprintf (tmp
, "%s%+d", regname (fc
->cfa_reg
, 1), (int) fc
->cfa_offset
);
8468 printf ("%-8s ", tmp
);
8470 for (r
= 0; r
< fc
->ncols
; r
++)
8472 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
8474 switch (fc
->col_type
[r
])
8476 case DW_CFA_undefined
:
8479 case DW_CFA_same_value
:
8483 sprintf (tmp
, "c%+d", fc
->col_offset
[r
]);
8485 case DW_CFA_val_offset
:
8486 sprintf (tmp
, "v%+d", fc
->col_offset
[r
]);
8488 case DW_CFA_register
:
8489 sprintf (tmp
, "%s", regname (fc
->col_offset
[r
], 0));
8491 case DW_CFA_expression
:
8492 strcpy (tmp
, "exp");
8494 case DW_CFA_val_expression
:
8495 strcpy (tmp
, "vexp");
8498 strcpy (tmp
, "n/a");
8501 printf ("%-5s ", tmp
);
8507 #define GET(VAR, N) SAFE_BYTE_GET_AND_INC (VAR, start, N, end)
8509 static unsigned char *
8510 read_cie (unsigned char *start
, unsigned char *end
,
8511 Frame_Chunk
**p_cie
, int *p_version
,
8512 bfd_size_type
*p_aug_len
, unsigned char **p_aug
)
8516 unsigned char *augmentation_data
= NULL
;
8517 bfd_size_type augmentation_data_len
= 0;
8520 /* PR 17512: file: 001-228113-0.004. */
8524 fc
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
8525 memset (fc
, 0, sizeof (Frame_Chunk
));
8527 fc
->col_type
= (short int *) xmalloc (sizeof (short int));
8528 fc
->col_offset
= (int *) xmalloc (sizeof (int));
8532 fc
->augmentation
= (char *) start
;
8533 /* PR 17512: file: 001-228113-0.004.
8534 Skip past augmentation name, but avoid running off the end of the data. */
8536 if (* start
++ == '\0')
8540 warn (_("No terminator for augmentation name\n"));
8544 if (strcmp (fc
->augmentation
, "eh") == 0)
8545 start
+= eh_addr_size
;
8549 GET (fc
->ptr_size
, 1);
8550 if (fc
->ptr_size
< 1 || fc
->ptr_size
> 8)
8552 warn (_("Invalid pointer size (%d) in CIE data\n"), fc
->ptr_size
);
8556 GET (fc
->segment_size
, 1);
8557 /* PR 17512: file: e99d2804. */
8558 if (fc
->segment_size
> 8 || fc
->segment_size
+ fc
->ptr_size
> 8)
8560 warn (_("Invalid segment size (%d) in CIE data\n"), fc
->segment_size
);
8564 eh_addr_size
= fc
->ptr_size
;
8568 fc
->ptr_size
= eh_addr_size
;
8569 fc
->segment_size
= 0;
8572 READ_ULEB (fc
->code_factor
, start
, end
);
8573 READ_SLEB (fc
->data_factor
, start
, end
);
8581 READ_ULEB (fc
->ra
, start
, end
);
8584 if (fc
->augmentation
[0] == 'z')
8586 READ_ULEB (augmentation_data_len
, start
, end
);
8587 augmentation_data
= start
;
8588 /* PR 17512: file: 11042-2589-0.004. */
8589 if (augmentation_data_len
> (bfd_size_type
) (end
- start
))
8591 warn (_("Augmentation data too long: 0x%s, expected at most %#lx\n"),
8592 dwarf_vmatoa ("x", augmentation_data_len
),
8593 (unsigned long) (end
- start
));
8596 start
+= augmentation_data_len
;
8599 if (augmentation_data_len
)
8603 unsigned char *qend
;
8605 p
= (unsigned char *) fc
->augmentation
+ 1;
8606 q
= augmentation_data
;
8607 qend
= q
+ augmentation_data_len
;
8609 while (p
< end
&& q
< qend
)
8614 q
+= 1 + size_of_encoded_value (*q
);
8616 fc
->fde_encoding
= *q
++;
8625 /* Note - it is OK if this loop terminates with q < qend.
8626 Padding may have been inserted to align the end of the CIE. */
8631 *p_version
= version
;
8634 *p_aug_len
= augmentation_data_len
;
8635 *p_aug
= augmentation_data
;
8640 free (fc
->col_offset
);
8641 free (fc
->col_type
);
8646 /* Prints out the contents on the DATA array formatted as unsigned bytes.
8647 If do_wide is not enabled, then formats the output to fit into 80 columns.
8648 PRINTED contains the number of characters already written to the current
8652 display_data (bfd_size_type printed
,
8653 const unsigned char * data
,
8654 const bfd_size_type len
)
8656 if (do_wide
|| len
< ((80 - printed
) / 3))
8657 for (printed
= 0; printed
< len
; ++printed
)
8658 printf (" %02x", data
[printed
]);
8661 for (printed
= 0; printed
< len
; ++printed
)
8663 if (printed
% (80 / 3) == 0)
8665 printf (" %02x", data
[printed
]);
8670 /* Prints out the contents on the augmentation data array.
8671 If do_wide is not enabled, then formats the output to fit into 80 columns. */
8674 display_augmentation_data (const unsigned char * data
, const bfd_size_type len
)
8678 i
= printf (_(" Augmentation data: "));
8679 display_data (i
, data
, len
);
8683 display_debug_frames (struct dwarf_section
*section
,
8684 void *file ATTRIBUTE_UNUSED
)
8686 unsigned char *start
= section
->start
;
8687 unsigned char *end
= start
+ section
->size
;
8688 unsigned char *section_start
= start
;
8689 Frame_Chunk
*chunks
= NULL
, *forward_refs
= NULL
;
8690 Frame_Chunk
*remembered_state
= NULL
;
8692 bool is_eh
= strcmp (section
->name
, ".eh_frame") == 0;
8693 unsigned int max_regs
= 0;
8694 const char *bad_reg
= _("bad register: ");
8695 unsigned int saved_eh_addr_size
= eh_addr_size
;
8697 introduce (section
, false);
8701 unsigned char *saved_start
;
8702 unsigned char *block_end
;
8707 int need_col_headers
= 1;
8708 unsigned char *augmentation_data
= NULL
;
8709 bfd_size_type augmentation_data_len
= 0;
8710 unsigned int encoded_ptr_size
= saved_eh_addr_size
;
8711 unsigned int offset_size
;
8712 unsigned int initial_length_size
;
8714 static Frame_Chunk fde_fc
;
8716 saved_start
= start
;
8718 SAFE_BYTE_GET_AND_INC (length
, start
, 4, end
);
8722 printf ("\n%08lx ZERO terminator\n\n",
8723 (unsigned long)(saved_start
- section_start
));
8724 /* Skip any zero terminators that directly follow.
8725 A corrupt section size could have loaded a whole
8726 slew of zero filled memory bytes. eg
8727 PR 17512: file: 070-19381-0.004. */
8728 while (start
< end
&& * start
== 0)
8733 if (length
== 0xffffffff)
8735 SAFE_BYTE_GET_AND_INC (length
, start
, 8, end
);
8737 initial_length_size
= 12;
8742 initial_length_size
= 4;
8745 block_end
= saved_start
+ length
+ initial_length_size
;
8746 if (block_end
> end
|| block_end
< start
)
8748 warn ("Invalid length 0x%s in FDE at %#08lx\n",
8749 dwarf_vmatoa_1 (NULL
, length
, offset_size
),
8750 (unsigned long) (saved_start
- section_start
));
8754 SAFE_BYTE_GET_AND_INC (cie_id
, start
, offset_size
, end
);
8756 if (is_eh
? (cie_id
== 0) : ((offset_size
== 4 && cie_id
== DW_CIE_ID
)
8757 || (offset_size
== 8 && cie_id
== DW64_CIE_ID
)))
8762 start
= read_cie (start
, end
, &cie
, &version
,
8763 &augmentation_data_len
, &augmentation_data
);
8764 /* PR 17512: file: 027-135133-0.005. */
8771 fc
->chunk_start
= saved_start
;
8772 mreg
= max_regs
> 0 ? max_regs
- 1 : 0;
8775 if (frame_need_space (fc
, mreg
) < 0)
8777 if (fc
->fde_encoding
)
8778 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
8780 printf ("\n%08lx ", (unsigned long) (saved_start
- section_start
));
8781 print_dwarf_vma (length
, fc
->ptr_size
);
8782 print_dwarf_vma (cie_id
, offset_size
);
8784 if (do_debug_frames_interp
)
8786 printf ("CIE \"%s\" cf=%d df=%d ra=%d\n", fc
->augmentation
,
8787 fc
->code_factor
, fc
->data_factor
, fc
->ra
);
8792 printf (" Version: %d\n", version
);
8793 printf (" Augmentation: \"%s\"\n", fc
->augmentation
);
8796 printf (" Pointer Size: %u\n", fc
->ptr_size
);
8797 printf (" Segment Size: %u\n", fc
->segment_size
);
8799 printf (" Code alignment factor: %u\n", fc
->code_factor
);
8800 printf (" Data alignment factor: %d\n", fc
->data_factor
);
8801 printf (" Return address column: %d\n", fc
->ra
);
8803 if (augmentation_data_len
)
8804 display_augmentation_data (augmentation_data
, augmentation_data_len
);
8811 unsigned char *look_for
;
8812 unsigned long segment_selector
;
8816 dwarf_vma sign
= (dwarf_vma
) 1 << (offset_size
* 8 - 1);
8817 look_for
= start
- 4 - ((cie_id
^ sign
) - sign
);
8820 look_for
= section_start
+ cie_id
;
8822 if (look_for
<= saved_start
)
8824 for (cie
= chunks
; cie
; cie
= cie
->next
)
8825 if (cie
->chunk_start
== look_for
)
8830 for (cie
= forward_refs
; cie
; cie
= cie
->next
)
8831 if (cie
->chunk_start
== look_for
)
8835 unsigned int off_size
;
8836 unsigned char *cie_scan
;
8838 cie_scan
= look_for
;
8840 SAFE_BYTE_GET_AND_INC (length
, cie_scan
, 4, end
);
8841 if (length
== 0xffffffff)
8843 SAFE_BYTE_GET_AND_INC (length
, cie_scan
, 8, end
);
8850 SAFE_BYTE_GET_AND_INC (c_id
, cie_scan
, off_size
, end
);
8853 : ((off_size
== 4 && c_id
== DW_CIE_ID
)
8854 || (off_size
== 8 && c_id
== DW64_CIE_ID
)))
8859 read_cie (cie_scan
, end
, &cie
, &version
,
8860 &augmentation_data_len
, &augmentation_data
);
8861 /* PR 17512: file: 3450-2098-0.004. */
8864 warn (_("Failed to read CIE information\n"));
8867 cie
->next
= forward_refs
;
8869 cie
->chunk_start
= look_for
;
8870 mreg
= max_regs
> 0 ? max_regs
- 1 : 0;
8873 if (frame_need_space (cie
, mreg
) < 0)
8875 warn (_("Invalid max register\n"));
8878 if (cie
->fde_encoding
)
8880 = size_of_encoded_value (cie
->fde_encoding
);
8887 memset (fc
, 0, sizeof (Frame_Chunk
));
8891 warn ("Invalid CIE pointer 0x%s in FDE at %#08lx\n",
8892 dwarf_vmatoa_1 (NULL
, cie_id
, offset_size
),
8893 (unsigned long) (saved_start
- section_start
));
8895 fc
->col_type
= (short int *) xmalloc (sizeof (short int));
8896 fc
->col_offset
= (int *) xmalloc (sizeof (int));
8897 if (frame_need_space (fc
, max_regs
> 0 ? max_regs
- 1 : 0) < 0)
8899 warn (_("Invalid max register\n"));
8903 fc
->augmentation
= "";
8904 fc
->fde_encoding
= 0;
8905 fc
->ptr_size
= eh_addr_size
;
8906 fc
->segment_size
= 0;
8910 fc
->ncols
= cie
->ncols
;
8911 fc
->col_type
= (short int *) xcmalloc (fc
->ncols
, sizeof (short int));
8912 fc
->col_offset
= (int *) xcmalloc (fc
->ncols
, sizeof (int));
8913 memcpy (fc
->col_type
, cie
->col_type
, fc
->ncols
* sizeof (short int));
8914 memcpy (fc
->col_offset
, cie
->col_offset
, fc
->ncols
* sizeof (int));
8915 fc
->augmentation
= cie
->augmentation
;
8916 fc
->ptr_size
= cie
->ptr_size
;
8917 eh_addr_size
= cie
->ptr_size
;
8918 fc
->segment_size
= cie
->segment_size
;
8919 fc
->code_factor
= cie
->code_factor
;
8920 fc
->data_factor
= cie
->data_factor
;
8921 fc
->cfa_reg
= cie
->cfa_reg
;
8922 fc
->cfa_offset
= cie
->cfa_offset
;
8924 if (frame_need_space (fc
, max_regs
> 0 ? max_regs
- 1: 0) < 0)
8926 warn (_("Invalid max register\n"));
8929 fc
->fde_encoding
= cie
->fde_encoding
;
8932 if (fc
->fde_encoding
)
8933 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
8935 segment_selector
= 0;
8936 if (fc
->segment_size
)
8938 if (fc
->segment_size
> sizeof (segment_selector
))
8940 /* PR 17512: file: 9e196b3e. */
8941 warn (_("Probably corrupt segment size: %d - using 4 instead\n"), fc
->segment_size
);
8942 fc
->segment_size
= 4;
8944 SAFE_BYTE_GET_AND_INC (segment_selector
, start
, fc
->segment_size
, end
);
8947 fc
->pc_begin
= get_encoded_value (&start
, fc
->fde_encoding
, section
, end
);
8949 /* FIXME: It appears that sometimes the final pc_range value is
8950 encoded in less than encoded_ptr_size bytes. See the x86_64
8951 run of the "objcopy on compressed debug sections" test for an
8953 SAFE_BYTE_GET_AND_INC (fc
->pc_range
, start
, encoded_ptr_size
, end
);
8955 if (cie
->augmentation
[0] == 'z')
8957 READ_ULEB (augmentation_data_len
, start
, end
);
8958 augmentation_data
= start
;
8959 /* PR 17512 file: 722-8446-0.004 and PR 22386. */
8960 if (augmentation_data_len
> (bfd_size_type
) (end
- start
))
8962 warn (_("Augmentation data too long: 0x%s, "
8963 "expected at most %#lx\n"),
8964 dwarf_vmatoa ("x", augmentation_data_len
),
8965 (unsigned long) (end
- start
));
8967 augmentation_data
= NULL
;
8968 augmentation_data_len
= 0;
8970 start
+= augmentation_data_len
;
8973 printf ("\n%08lx %s %s FDE cie=%08lx pc=",
8974 (unsigned long)(saved_start
- section_start
),
8975 dwarf_vmatoa_1 (NULL
, length
, fc
->ptr_size
),
8976 dwarf_vmatoa_1 (NULL
, cie_id
, offset_size
),
8977 (unsigned long)(cie
->chunk_start
- section_start
));
8979 if (fc
->segment_size
)
8980 printf ("%04lx:", segment_selector
);
8983 dwarf_vmatoa_1 (NULL
, fc
->pc_begin
, fc
->ptr_size
),
8984 dwarf_vmatoa_1 (NULL
, fc
->pc_begin
+ fc
->pc_range
, fc
->ptr_size
));
8986 if (! do_debug_frames_interp
&& augmentation_data_len
)
8988 display_augmentation_data (augmentation_data
, augmentation_data_len
);
8993 /* At this point, fc is the current chunk, cie (if any) is set, and
8994 we're about to interpret instructions for the chunk. */
8995 /* ??? At present we need to do this always, since this sizes the
8996 fc->col_type and fc->col_offset arrays, which we write into always.
8997 We should probably split the interpreted and non-interpreted bits
8998 into two different routines, since there's so much that doesn't
8999 really overlap between them. */
9000 if (1 || do_debug_frames_interp
)
9002 /* Start by making a pass over the chunk, allocating storage
9003 and taking note of what registers are used. */
9004 unsigned char *tmp
= start
;
9006 while (start
< block_end
)
9008 unsigned int reg
, op
, opa
;
9010 unsigned char * new_start
;
9017 /* Warning: if you add any more cases to this switch, be
9018 sure to add them to the corresponding switch below. */
9021 case DW_CFA_advance_loc
:
9024 SKIP_ULEB (start
, end
);
9025 if (frame_need_space (fc
, opa
) >= 0)
9026 fc
->col_type
[opa
] = DW_CFA_undefined
;
9028 case DW_CFA_restore
:
9029 if (frame_need_space (fc
, opa
) >= 0)
9030 fc
->col_type
[opa
] = DW_CFA_undefined
;
9032 case DW_CFA_set_loc
:
9033 start
+= encoded_ptr_size
;
9035 case DW_CFA_advance_loc1
:
9038 case DW_CFA_advance_loc2
:
9041 case DW_CFA_advance_loc4
:
9044 case DW_CFA_offset_extended
:
9045 case DW_CFA_val_offset
:
9046 READ_ULEB (reg
, start
, end
);
9047 SKIP_ULEB (start
, end
);
9048 if (frame_need_space (fc
, reg
) >= 0)
9049 fc
->col_type
[reg
] = DW_CFA_undefined
;
9051 case DW_CFA_restore_extended
:
9052 READ_ULEB (reg
, start
, end
);
9053 if (frame_need_space (fc
, reg
) >= 0)
9054 fc
->col_type
[reg
] = DW_CFA_undefined
;
9056 case DW_CFA_undefined
:
9057 READ_ULEB (reg
, start
, end
);
9058 if (frame_need_space (fc
, reg
) >= 0)
9059 fc
->col_type
[reg
] = DW_CFA_undefined
;
9061 case DW_CFA_same_value
:
9062 READ_ULEB (reg
, start
, end
);
9063 if (frame_need_space (fc
, reg
) >= 0)
9064 fc
->col_type
[reg
] = DW_CFA_undefined
;
9066 case DW_CFA_register
:
9067 READ_ULEB (reg
, start
, end
);
9068 SKIP_ULEB (start
, end
);
9069 if (frame_need_space (fc
, reg
) >= 0)
9070 fc
->col_type
[reg
] = DW_CFA_undefined
;
9072 case DW_CFA_def_cfa
:
9073 SKIP_ULEB (start
, end
);
9074 SKIP_ULEB (start
, end
);
9076 case DW_CFA_def_cfa_register
:
9077 SKIP_ULEB (start
, end
);
9079 case DW_CFA_def_cfa_offset
:
9080 SKIP_ULEB (start
, end
);
9082 case DW_CFA_def_cfa_expression
:
9083 READ_ULEB (temp
, start
, end
);
9084 new_start
= start
+ temp
;
9085 if (new_start
< start
)
9087 warn (_("Corrupt CFA_def expression value: %lu\n"), temp
);
9093 case DW_CFA_expression
:
9094 case DW_CFA_val_expression
:
9095 READ_ULEB (reg
, start
, end
);
9096 READ_ULEB (temp
, start
, end
);
9097 new_start
= start
+ temp
;
9098 if (new_start
< start
)
9100 /* PR 17512: file:306-192417-0.005. */
9101 warn (_("Corrupt CFA expression value: %lu\n"), temp
);
9106 if (frame_need_space (fc
, reg
) >= 0)
9107 fc
->col_type
[reg
] = DW_CFA_undefined
;
9109 case DW_CFA_offset_extended_sf
:
9110 case DW_CFA_val_offset_sf
:
9111 READ_ULEB (reg
, start
, end
);
9112 SKIP_SLEB (start
, end
);
9113 if (frame_need_space (fc
, reg
) >= 0)
9114 fc
->col_type
[reg
] = DW_CFA_undefined
;
9116 case DW_CFA_def_cfa_sf
:
9117 SKIP_ULEB (start
, end
);
9118 SKIP_SLEB (start
, end
);
9120 case DW_CFA_def_cfa_offset_sf
:
9121 SKIP_SLEB (start
, end
);
9123 case DW_CFA_MIPS_advance_loc8
:
9126 case DW_CFA_GNU_args_size
:
9127 SKIP_ULEB (start
, end
);
9129 case DW_CFA_GNU_negative_offset_extended
:
9130 READ_ULEB (reg
, start
, end
);
9131 SKIP_ULEB (start
, end
);
9132 if (frame_need_space (fc
, reg
) >= 0)
9133 fc
->col_type
[reg
] = DW_CFA_undefined
;
9144 /* Now we know what registers are used, make a second pass over
9145 the chunk, this time actually printing out the info. */
9147 while (start
< block_end
)
9149 unsigned char * tmp
;
9151 unsigned long ul
, roffs
;
9152 /* Note: It is tempting to use an unsigned long for 'reg' but there
9153 are various functions, notably frame_space_needed() that assume that
9154 reg is an unsigned int. */
9159 const char *reg_prefix
= "";
9166 /* Make a note if something other than DW_CFA_nop happens. */
9167 if (op
!= DW_CFA_nop
)
9170 /* Warning: if you add any more cases to this switch, be
9171 sure to add them to the corresponding switch above. */
9174 case DW_CFA_advance_loc
:
9175 if (do_debug_frames_interp
)
9176 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9178 printf (" DW_CFA_advance_loc: %d to %s\n",
9179 opa
* fc
->code_factor
,
9180 dwarf_vmatoa_1 (NULL
,
9181 fc
->pc_begin
+ opa
* fc
->code_factor
,
9183 fc
->pc_begin
+= opa
* fc
->code_factor
;
9187 READ_ULEB (roffs
, start
, end
);
9188 if (opa
>= (unsigned int) fc
->ncols
)
9189 reg_prefix
= bad_reg
;
9190 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9191 printf (" DW_CFA_offset: %s%s at cfa%+ld\n",
9192 reg_prefix
, regname (opa
, 0),
9193 roffs
* fc
->data_factor
);
9194 if (*reg_prefix
== '\0')
9196 fc
->col_type
[opa
] = DW_CFA_offset
;
9197 fc
->col_offset
[opa
] = roffs
* fc
->data_factor
;
9201 case DW_CFA_restore
:
9202 if (opa
>= (unsigned int) fc
->ncols
)
9203 reg_prefix
= bad_reg
;
9204 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9205 printf (" DW_CFA_restore: %s%s\n",
9206 reg_prefix
, regname (opa
, 0));
9207 if (*reg_prefix
!= '\0')
9210 if (opa
>= (unsigned int) cie
->ncols
9211 || (do_debug_frames_interp
9212 && cie
->col_type
[opa
] == DW_CFA_unreferenced
))
9214 fc
->col_type
[opa
] = DW_CFA_undefined
;
9215 fc
->col_offset
[opa
] = 0;
9219 fc
->col_type
[opa
] = cie
->col_type
[opa
];
9220 fc
->col_offset
[opa
] = cie
->col_offset
[opa
];
9224 case DW_CFA_set_loc
:
9225 vma
= get_encoded_value (&start
, fc
->fde_encoding
, section
, block_end
);
9226 if (do_debug_frames_interp
)
9227 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9229 printf (" DW_CFA_set_loc: %s\n",
9230 dwarf_vmatoa_1 (NULL
, vma
, fc
->ptr_size
));
9234 case DW_CFA_advance_loc1
:
9235 SAFE_BYTE_GET_AND_INC (ofs
, start
, 1, end
);
9236 if (do_debug_frames_interp
)
9237 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9239 printf (" DW_CFA_advance_loc1: %ld to %s\n",
9240 (unsigned long) (ofs
* fc
->code_factor
),
9241 dwarf_vmatoa_1 (NULL
,
9242 fc
->pc_begin
+ ofs
* fc
->code_factor
,
9244 fc
->pc_begin
+= ofs
* fc
->code_factor
;
9247 case DW_CFA_advance_loc2
:
9248 SAFE_BYTE_GET_AND_INC (ofs
, start
, 2, block_end
);
9249 if (do_debug_frames_interp
)
9250 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9252 printf (" DW_CFA_advance_loc2: %ld to %s\n",
9253 (unsigned long) (ofs
* fc
->code_factor
),
9254 dwarf_vmatoa_1 (NULL
,
9255 fc
->pc_begin
+ ofs
* fc
->code_factor
,
9257 fc
->pc_begin
+= ofs
* fc
->code_factor
;
9260 case DW_CFA_advance_loc4
:
9261 SAFE_BYTE_GET_AND_INC (ofs
, start
, 4, block_end
);
9262 if (do_debug_frames_interp
)
9263 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9265 printf (" DW_CFA_advance_loc4: %ld to %s\n",
9266 (unsigned long) (ofs
* fc
->code_factor
),
9267 dwarf_vmatoa_1 (NULL
,
9268 fc
->pc_begin
+ ofs
* fc
->code_factor
,
9270 fc
->pc_begin
+= ofs
* fc
->code_factor
;
9273 case DW_CFA_offset_extended
:
9274 READ_ULEB (reg
, start
, end
);
9275 READ_ULEB (roffs
, start
, end
);
9276 if (reg
>= (unsigned int) fc
->ncols
)
9277 reg_prefix
= bad_reg
;
9278 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9279 printf (" DW_CFA_offset_extended: %s%s at cfa%+ld\n",
9280 reg_prefix
, regname (reg
, 0),
9281 roffs
* fc
->data_factor
);
9282 if (*reg_prefix
== '\0')
9284 fc
->col_type
[reg
] = DW_CFA_offset
;
9285 fc
->col_offset
[reg
] = roffs
* fc
->data_factor
;
9289 case DW_CFA_val_offset
:
9290 READ_ULEB (reg
, start
, end
);
9291 READ_ULEB (roffs
, start
, end
);
9292 if (reg
>= (unsigned int) fc
->ncols
)
9293 reg_prefix
= bad_reg
;
9294 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9295 printf (" DW_CFA_val_offset: %s%s is cfa%+ld\n",
9296 reg_prefix
, regname (reg
, 0),
9297 roffs
* fc
->data_factor
);
9298 if (*reg_prefix
== '\0')
9300 fc
->col_type
[reg
] = DW_CFA_val_offset
;
9301 fc
->col_offset
[reg
] = roffs
* fc
->data_factor
;
9305 case DW_CFA_restore_extended
:
9306 READ_ULEB (reg
, start
, end
);
9307 if (reg
>= (unsigned int) fc
->ncols
)
9308 reg_prefix
= bad_reg
;
9309 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9310 printf (" DW_CFA_restore_extended: %s%s\n",
9311 reg_prefix
, regname (reg
, 0));
9312 if (*reg_prefix
!= '\0')
9315 if (reg
>= (unsigned int) cie
->ncols
)
9317 fc
->col_type
[reg
] = DW_CFA_undefined
;
9318 fc
->col_offset
[reg
] = 0;
9322 fc
->col_type
[reg
] = cie
->col_type
[reg
];
9323 fc
->col_offset
[reg
] = cie
->col_offset
[reg
];
9327 case DW_CFA_undefined
:
9328 READ_ULEB (reg
, start
, end
);
9329 if (reg
>= (unsigned int) fc
->ncols
)
9330 reg_prefix
= bad_reg
;
9331 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9332 printf (" DW_CFA_undefined: %s%s\n",
9333 reg_prefix
, regname (reg
, 0));
9334 if (*reg_prefix
== '\0')
9336 fc
->col_type
[reg
] = DW_CFA_undefined
;
9337 fc
->col_offset
[reg
] = 0;
9341 case DW_CFA_same_value
:
9342 READ_ULEB (reg
, start
, end
);
9343 if (reg
>= (unsigned int) fc
->ncols
)
9344 reg_prefix
= bad_reg
;
9345 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9346 printf (" DW_CFA_same_value: %s%s\n",
9347 reg_prefix
, regname (reg
, 0));
9348 if (*reg_prefix
== '\0')
9350 fc
->col_type
[reg
] = DW_CFA_same_value
;
9351 fc
->col_offset
[reg
] = 0;
9355 case DW_CFA_register
:
9356 READ_ULEB (reg
, start
, end
);
9357 READ_ULEB (roffs
, start
, end
);
9358 if (reg
>= (unsigned int) fc
->ncols
)
9359 reg_prefix
= bad_reg
;
9360 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9362 printf (" DW_CFA_register: %s%s in ",
9363 reg_prefix
, regname (reg
, 0));
9364 puts (regname (roffs
, 0));
9366 if (*reg_prefix
== '\0')
9368 fc
->col_type
[reg
] = DW_CFA_register
;
9369 fc
->col_offset
[reg
] = roffs
;
9373 case DW_CFA_remember_state
:
9374 if (! do_debug_frames_interp
)
9375 printf (" DW_CFA_remember_state\n");
9376 rs
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
9377 rs
->cfa_offset
= fc
->cfa_offset
;
9378 rs
->cfa_reg
= fc
->cfa_reg
;
9380 rs
->cfa_exp
= fc
->cfa_exp
;
9381 rs
->ncols
= fc
->ncols
;
9382 rs
->col_type
= (short int *) xcmalloc (rs
->ncols
,
9383 sizeof (* rs
->col_type
));
9384 rs
->col_offset
= (int *) xcmalloc (rs
->ncols
, sizeof (* rs
->col_offset
));
9385 memcpy (rs
->col_type
, fc
->col_type
, rs
->ncols
* sizeof (* fc
->col_type
));
9386 memcpy (rs
->col_offset
, fc
->col_offset
, rs
->ncols
* sizeof (* fc
->col_offset
));
9387 rs
->next
= remembered_state
;
9388 remembered_state
= rs
;
9391 case DW_CFA_restore_state
:
9392 if (! do_debug_frames_interp
)
9393 printf (" DW_CFA_restore_state\n");
9394 rs
= remembered_state
;
9397 remembered_state
= rs
->next
;
9398 fc
->cfa_offset
= rs
->cfa_offset
;
9399 fc
->cfa_reg
= rs
->cfa_reg
;
9401 fc
->cfa_exp
= rs
->cfa_exp
;
9402 if (frame_need_space (fc
, rs
->ncols
- 1) < 0)
9404 warn (_("Invalid column number in saved frame state\n"));
9408 memcpy (fc
->col_type
, rs
->col_type
, rs
->ncols
* sizeof (* rs
->col_type
));
9409 memcpy (fc
->col_offset
, rs
->col_offset
,
9410 rs
->ncols
* sizeof (* rs
->col_offset
));
9411 free (rs
->col_type
);
9412 free (rs
->col_offset
);
9415 else if (do_debug_frames_interp
)
9416 printf ("Mismatched DW_CFA_restore_state\n");
9419 case DW_CFA_def_cfa
:
9420 READ_ULEB (fc
->cfa_reg
, start
, end
);
9421 READ_ULEB (fc
->cfa_offset
, start
, end
);
9423 if (! do_debug_frames_interp
)
9424 printf (" DW_CFA_def_cfa: %s ofs %d\n",
9425 regname (fc
->cfa_reg
, 0), (int) fc
->cfa_offset
);
9428 case DW_CFA_def_cfa_register
:
9429 READ_ULEB (fc
->cfa_reg
, start
, end
);
9431 if (! do_debug_frames_interp
)
9432 printf (" DW_CFA_def_cfa_register: %s\n",
9433 regname (fc
->cfa_reg
, 0));
9436 case DW_CFA_def_cfa_offset
:
9437 READ_ULEB (fc
->cfa_offset
, start
, end
);
9438 if (! do_debug_frames_interp
)
9439 printf (" DW_CFA_def_cfa_offset: %d\n", (int) fc
->cfa_offset
);
9443 if (! do_debug_frames_interp
)
9444 printf (" DW_CFA_nop\n");
9447 case DW_CFA_def_cfa_expression
:
9448 READ_ULEB (ul
, start
, end
);
9449 if (start
>= block_end
|| ul
> (unsigned long) (block_end
- start
))
9451 printf (_(" DW_CFA_def_cfa_expression: <corrupt len %lu>\n"), ul
);
9454 if (! do_debug_frames_interp
)
9456 printf (" DW_CFA_def_cfa_expression (");
9457 decode_location_expression (start
, eh_addr_size
, 0, -1,
9465 case DW_CFA_expression
:
9466 READ_ULEB (reg
, start
, end
);
9467 READ_ULEB (ul
, start
, end
);
9468 if (reg
>= (unsigned int) fc
->ncols
)
9469 reg_prefix
= bad_reg
;
9470 /* PR 17512: file: 069-133014-0.006. */
9471 /* PR 17512: file: 98c02eb4. */
9473 if (start
>= block_end
|| tmp
> block_end
|| tmp
< start
)
9475 printf (_(" DW_CFA_expression: <corrupt len %lu>\n"), ul
);
9478 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9480 printf (" DW_CFA_expression: %s%s (",
9481 reg_prefix
, regname (reg
, 0));
9482 decode_location_expression (start
, eh_addr_size
, 0, -1,
9486 if (*reg_prefix
== '\0')
9487 fc
->col_type
[reg
] = DW_CFA_expression
;
9491 case DW_CFA_val_expression
:
9492 READ_ULEB (reg
, start
, end
);
9493 READ_ULEB (ul
, start
, end
);
9494 if (reg
>= (unsigned int) fc
->ncols
)
9495 reg_prefix
= bad_reg
;
9497 if (start
>= block_end
|| tmp
> block_end
|| tmp
< start
)
9499 printf (" DW_CFA_val_expression: <corrupt len %lu>\n", ul
);
9502 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9504 printf (" DW_CFA_val_expression: %s%s (",
9505 reg_prefix
, regname (reg
, 0));
9506 decode_location_expression (start
, eh_addr_size
, 0, -1,
9510 if (*reg_prefix
== '\0')
9511 fc
->col_type
[reg
] = DW_CFA_val_expression
;
9515 case DW_CFA_offset_extended_sf
:
9516 READ_ULEB (reg
, start
, end
);
9517 READ_SLEB (l
, start
, end
);
9518 if (frame_need_space (fc
, reg
) < 0)
9519 reg_prefix
= bad_reg
;
9520 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9521 printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+ld\n",
9522 reg_prefix
, regname (reg
, 0),
9523 (long)(l
* fc
->data_factor
));
9524 if (*reg_prefix
== '\0')
9526 fc
->col_type
[reg
] = DW_CFA_offset
;
9527 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
9531 case DW_CFA_val_offset_sf
:
9532 READ_ULEB (reg
, start
, end
);
9533 READ_SLEB (l
, start
, end
);
9534 if (frame_need_space (fc
, reg
) < 0)
9535 reg_prefix
= bad_reg
;
9536 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9537 printf (" DW_CFA_val_offset_sf: %s%s is cfa%+ld\n",
9538 reg_prefix
, regname (reg
, 0),
9539 (long)(l
* fc
->data_factor
));
9540 if (*reg_prefix
== '\0')
9542 fc
->col_type
[reg
] = DW_CFA_val_offset
;
9543 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
9547 case DW_CFA_def_cfa_sf
:
9548 READ_ULEB (fc
->cfa_reg
, start
, end
);
9549 READ_ULEB (fc
->cfa_offset
, start
, end
);
9550 fc
->cfa_offset
= fc
->cfa_offset
* fc
->data_factor
;
9552 if (! do_debug_frames_interp
)
9553 printf (" DW_CFA_def_cfa_sf: %s ofs %d\n",
9554 regname (fc
->cfa_reg
, 0), (int) fc
->cfa_offset
);
9557 case DW_CFA_def_cfa_offset_sf
:
9558 READ_ULEB (fc
->cfa_offset
, start
, end
);
9559 fc
->cfa_offset
*= fc
->data_factor
;
9560 if (! do_debug_frames_interp
)
9561 printf (" DW_CFA_def_cfa_offset_sf: %d\n", (int) fc
->cfa_offset
);
9564 case DW_CFA_MIPS_advance_loc8
:
9565 SAFE_BYTE_GET_AND_INC (ofs
, start
, 8, block_end
);
9566 if (do_debug_frames_interp
)
9567 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9569 printf (" DW_CFA_MIPS_advance_loc8: %ld to %s\n",
9570 (unsigned long) (ofs
* fc
->code_factor
),
9571 dwarf_vmatoa_1 (NULL
,
9572 fc
->pc_begin
+ ofs
* fc
->code_factor
,
9574 fc
->pc_begin
+= ofs
* fc
->code_factor
;
9577 case DW_CFA_GNU_window_save
:
9578 if (! do_debug_frames_interp
)
9579 printf (" DW_CFA_GNU_window_save\n");
9582 case DW_CFA_GNU_args_size
:
9583 READ_ULEB (ul
, start
, end
);
9584 if (! do_debug_frames_interp
)
9585 printf (" DW_CFA_GNU_args_size: %ld\n", ul
);
9588 case DW_CFA_GNU_negative_offset_extended
:
9589 READ_ULEB (reg
, start
, end
);
9590 READ_SLEB (l
, start
, end
);
9592 if (frame_need_space (fc
, reg
) < 0)
9593 reg_prefix
= bad_reg
;
9594 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9595 printf (" DW_CFA_GNU_negative_offset_extended: %s%s at cfa%+ld\n",
9596 reg_prefix
, regname (reg
, 0),
9597 (long)(l
* fc
->data_factor
));
9598 if (*reg_prefix
== '\0')
9600 fc
->col_type
[reg
] = DW_CFA_offset
;
9601 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
9606 if (op
>= DW_CFA_lo_user
&& op
<= DW_CFA_hi_user
)
9607 printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op
);
9609 warn (_("Unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op
);
9614 /* Interpret the CFA - as long as it is not completely full of NOPs. */
9615 if (do_debug_frames_interp
&& ! all_nops
)
9616 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9618 if (fde_fc
.col_type
!= NULL
)
9620 free (fde_fc
.col_type
);
9621 fde_fc
.col_type
= NULL
;
9623 if (fde_fc
.col_offset
!= NULL
)
9625 free (fde_fc
.col_offset
);
9626 fde_fc
.col_offset
= NULL
;
9630 eh_addr_size
= saved_eh_addr_size
;
9635 while (remembered_state
!= NULL
)
9637 rs
= remembered_state
;
9638 remembered_state
= rs
->next
;
9639 free (rs
->col_type
);
9640 free (rs
->col_offset
);
9641 rs
->next
= NULL
; /* Paranoia. */
9645 while (chunks
!= NULL
)
9649 free (rs
->col_type
);
9650 free (rs
->col_offset
);
9651 rs
->next
= NULL
; /* Paranoia. */
9655 while (forward_refs
!= NULL
)
9658 forward_refs
= rs
->next
;
9659 free (rs
->col_type
);
9660 free (rs
->col_offset
);
9661 rs
->next
= NULL
; /* Paranoia. */
9671 display_debug_names (struct dwarf_section
*section
, void *file
)
9673 unsigned char *hdrptr
= section
->start
;
9674 dwarf_vma unit_length
;
9675 unsigned char *unit_start
;
9676 const unsigned char *const section_end
= section
->start
+ section
->size
;
9677 unsigned char *unit_end
;
9679 introduce (section
, false);
9681 load_debug_section_with_follow (str
, file
);
9683 for (; hdrptr
< section_end
; hdrptr
= unit_end
)
9685 unsigned int offset_size
;
9686 uint16_t dwarf_version
, padding
;
9687 uint32_t comp_unit_count
, local_type_unit_count
, foreign_type_unit_count
;
9688 uint32_t bucket_count
, name_count
, abbrev_table_size
;
9689 uint32_t augmentation_string_size
;
9691 unsigned long sec_off
;
9692 bool augmentation_printable
;
9693 const char *augmentation_string
;
9695 unit_start
= hdrptr
;
9697 /* Get and check the length of the block. */
9698 SAFE_BYTE_GET_AND_INC (unit_length
, hdrptr
, 4, section_end
);
9700 if (unit_length
== 0xffffffff)
9702 /* This section is 64-bit DWARF. */
9703 SAFE_BYTE_GET_AND_INC (unit_length
, hdrptr
, 8, section_end
);
9708 unit_end
= hdrptr
+ unit_length
;
9710 sec_off
= hdrptr
- section
->start
;
9711 if (sec_off
+ unit_length
< sec_off
9712 || sec_off
+ unit_length
> section
->size
)
9714 warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"),
9716 (unsigned long) (unit_start
- section
->start
),
9717 dwarf_vmatoa ("x", unit_length
));
9721 /* Get and check the version number. */
9722 SAFE_BYTE_GET_AND_INC (dwarf_version
, hdrptr
, 2, unit_end
);
9723 printf (_("Version %ld\n"), (long) dwarf_version
);
9725 /* Prior versions did not exist, and future versions may not be
9726 backwards compatible. */
9727 if (dwarf_version
!= 5)
9729 warn (_("Only DWARF version 5 .debug_names "
9730 "is currently supported.\n"));
9734 SAFE_BYTE_GET_AND_INC (padding
, hdrptr
, 2, unit_end
);
9736 warn (_("Padding field of .debug_names must be 0 (found 0x%x)\n"),
9739 SAFE_BYTE_GET_AND_INC (comp_unit_count
, hdrptr
, 4, unit_end
);
9740 if (comp_unit_count
== 0)
9741 warn (_("Compilation unit count must be >= 1 in .debug_names\n"));
9743 SAFE_BYTE_GET_AND_INC (local_type_unit_count
, hdrptr
, 4, unit_end
);
9744 SAFE_BYTE_GET_AND_INC (foreign_type_unit_count
, hdrptr
, 4, unit_end
);
9745 SAFE_BYTE_GET_AND_INC (bucket_count
, hdrptr
, 4, unit_end
);
9746 SAFE_BYTE_GET_AND_INC (name_count
, hdrptr
, 4, unit_end
);
9747 SAFE_BYTE_GET_AND_INC (abbrev_table_size
, hdrptr
, 4, unit_end
);
9749 SAFE_BYTE_GET_AND_INC (augmentation_string_size
, hdrptr
, 4, unit_end
);
9750 if (augmentation_string_size
% 4 != 0)
9752 warn (_("Augmentation string length %u must be rounded up "
9753 "to a multiple of 4 in .debug_names.\n"),
9754 augmentation_string_size
);
9755 augmentation_string_size
+= (-augmentation_string_size
) & 3;
9758 printf (_("Augmentation string:"));
9760 augmentation_printable
= true;
9761 augmentation_string
= (const char *) hdrptr
;
9763 for (i
= 0; i
< augmentation_string_size
; i
++)
9767 SAFE_BYTE_GET_AND_INC (uc
, hdrptr
, 1, unit_end
);
9768 printf (" %02x", uc
);
9770 if (uc
!= 0 && !ISPRINT (uc
))
9771 augmentation_printable
= false;
9774 if (augmentation_printable
)
9778 i
< augmentation_string_size
&& augmentation_string
[i
];
9780 putchar (augmentation_string
[i
]);
9785 printf (_("CU table:\n"));
9786 for (i
= 0; i
< comp_unit_count
; i
++)
9790 SAFE_BYTE_GET_AND_INC (cu_offset
, hdrptr
, offset_size
, unit_end
);
9791 printf (_("[%3u] 0x%lx\n"), i
, (unsigned long) cu_offset
);
9795 printf (_("TU table:\n"));
9796 for (i
= 0; i
< local_type_unit_count
; i
++)
9800 SAFE_BYTE_GET_AND_INC (tu_offset
, hdrptr
, offset_size
, unit_end
);
9801 printf (_("[%3u] 0x%lx\n"), i
, (unsigned long) tu_offset
);
9805 printf (_("Foreign TU table:\n"));
9806 for (i
= 0; i
< foreign_type_unit_count
; i
++)
9810 SAFE_BYTE_GET_AND_INC (signature
, hdrptr
, 8, unit_end
);
9811 printf (_("[%3u] "), i
);
9812 print_dwarf_vma (signature
, 8);
9817 const uint32_t *const hash_table_buckets
= (uint32_t *) hdrptr
;
9818 hdrptr
+= bucket_count
* sizeof (uint32_t);
9819 const uint32_t *const hash_table_hashes
= (uint32_t *) hdrptr
;
9820 hdrptr
+= name_count
* sizeof (uint32_t);
9821 unsigned char *const name_table_string_offsets
= hdrptr
;
9822 hdrptr
+= name_count
* offset_size
;
9823 unsigned char *const name_table_entry_offsets
= hdrptr
;
9824 hdrptr
+= name_count
* offset_size
;
9825 unsigned char *const abbrev_table
= hdrptr
;
9826 hdrptr
+= abbrev_table_size
;
9827 const unsigned char *const abbrev_table_end
= hdrptr
;
9828 unsigned char *const entry_pool
= hdrptr
;
9829 if (hdrptr
> unit_end
)
9831 warn (_("Entry pool offset (0x%lx) exceeds unit size 0x%lx "
9832 "for unit 0x%lx in the debug_names\n"),
9833 (long) (hdrptr
- section
->start
),
9834 (long) (unit_end
- section
->start
),
9835 (long) (unit_start
- section
->start
));
9839 size_t buckets_filled
= 0;
9841 for (bucketi
= 0; bucketi
< bucket_count
; bucketi
++)
9843 const uint32_t bucket
= hash_table_buckets
[bucketi
];
9848 printf (ngettext ("Used %zu of %lu bucket.\n",
9849 "Used %zu of %lu buckets.\n",
9851 buckets_filled
, (unsigned long) bucket_count
);
9853 uint32_t hash_prev
= 0;
9854 size_t hash_clash_count
= 0;
9855 size_t longest_clash
= 0;
9856 size_t this_length
= 0;
9858 for (hashi
= 0; hashi
< name_count
; hashi
++)
9860 const uint32_t hash_this
= hash_table_hashes
[hashi
];
9864 if (hash_prev
% bucket_count
== hash_this
% bucket_count
)
9868 longest_clash
= MAX (longest_clash
, this_length
);
9873 hash_prev
= hash_this
;
9875 printf (_("Out of %lu items there are %zu bucket clashes"
9876 " (longest of %zu entries).\n"),
9877 (unsigned long) name_count
, hash_clash_count
, longest_clash
);
9878 assert (name_count
== buckets_filled
+ hash_clash_count
);
9880 struct abbrev_lookup_entry
9882 dwarf_vma abbrev_tag
;
9883 unsigned char *abbrev_lookup_ptr
;
9885 struct abbrev_lookup_entry
*abbrev_lookup
= NULL
;
9886 size_t abbrev_lookup_used
= 0;
9887 size_t abbrev_lookup_allocated
= 0;
9889 unsigned char *abbrevptr
= abbrev_table
;
9892 dwarf_vma abbrev_tag
;
9894 READ_ULEB (abbrev_tag
, abbrevptr
, abbrev_table_end
);
9895 if (abbrev_tag
== 0)
9897 if (abbrev_lookup_used
== abbrev_lookup_allocated
)
9899 abbrev_lookup_allocated
= MAX (0x100,
9900 abbrev_lookup_allocated
* 2);
9901 abbrev_lookup
= xrealloc (abbrev_lookup
,
9902 (abbrev_lookup_allocated
9903 * sizeof (*abbrev_lookup
)));
9905 assert (abbrev_lookup_used
< abbrev_lookup_allocated
);
9906 struct abbrev_lookup_entry
*entry
;
9907 for (entry
= abbrev_lookup
;
9908 entry
< abbrev_lookup
+ abbrev_lookup_used
;
9910 if (entry
->abbrev_tag
== abbrev_tag
)
9912 warn (_("Duplicate abbreviation tag %lu "
9913 "in unit 0x%lx in the debug_names\n"),
9914 (long) abbrev_tag
, (long) (unit_start
- section
->start
));
9917 entry
= &abbrev_lookup
[abbrev_lookup_used
++];
9918 entry
->abbrev_tag
= abbrev_tag
;
9919 entry
->abbrev_lookup_ptr
= abbrevptr
;
9921 /* Skip DWARF tag. */
9922 SKIP_ULEB (abbrevptr
, abbrev_table_end
);
9925 dwarf_vma xindex
, form
;
9927 READ_ULEB (xindex
, abbrevptr
, abbrev_table_end
);
9928 READ_ULEB (form
, abbrevptr
, abbrev_table_end
);
9929 if (xindex
== 0 && form
== 0)
9934 printf (_("\nSymbol table:\n"));
9936 for (namei
= 0; namei
< name_count
; ++namei
)
9938 uint64_t string_offset
, entry_offset
;
9940 SAFE_BYTE_GET (string_offset
,
9941 name_table_string_offsets
+ namei
* offset_size
,
9942 offset_size
, unit_end
);
9943 SAFE_BYTE_GET (entry_offset
,
9944 name_table_entry_offsets
+ namei
* offset_size
,
9945 offset_size
, unit_end
);
9947 printf ("[%3u] #%08x %s:", namei
, hash_table_hashes
[namei
],
9948 fetch_indirect_string (string_offset
));
9950 unsigned char *entryptr
= entry_pool
+ entry_offset
;
9952 /* We need to scan first whether there is a single or multiple
9953 entries. TAGNO is -2 for the first entry, it is -1 for the
9954 initial tag read of the second entry, then it becomes 0 for the
9955 first entry for real printing etc. */
9957 /* Initialize it due to a false compiler warning. */
9958 dwarf_vma second_abbrev_tag
= -1;
9961 dwarf_vma abbrev_tag
;
9962 dwarf_vma dwarf_tag
;
9963 const struct abbrev_lookup_entry
*entry
;
9965 READ_ULEB (abbrev_tag
, entryptr
, unit_end
);
9968 second_abbrev_tag
= abbrev_tag
;
9970 entryptr
= entry_pool
+ entry_offset
;
9973 if (abbrev_tag
== 0)
9977 (tagno
== 0 && second_abbrev_tag
== 0 ? " " : "\n\t"),
9978 (unsigned long) abbrev_tag
);
9980 for (entry
= abbrev_lookup
;
9981 entry
< abbrev_lookup
+ abbrev_lookup_used
;
9983 if (entry
->abbrev_tag
== abbrev_tag
)
9985 if (entry
>= abbrev_lookup
+ abbrev_lookup_used
)
9987 warn (_("Undefined abbreviation tag %lu "
9988 "in unit 0x%lx in the debug_names\n"),
9990 (long) (unit_start
- section
->start
));
9993 abbrevptr
= entry
->abbrev_lookup_ptr
;
9994 READ_ULEB (dwarf_tag
, abbrevptr
, abbrev_table_end
);
9996 printf (" %s", get_TAG_name (dwarf_tag
));
9999 dwarf_vma xindex
, form
;
10001 READ_ULEB (xindex
, abbrevptr
, abbrev_table_end
);
10002 READ_ULEB (form
, abbrevptr
, abbrev_table_end
);
10003 if (xindex
== 0 && form
== 0)
10007 printf (" %s", get_IDX_name (xindex
));
10008 entryptr
= read_and_display_attr_value (0, form
, 0,
10009 unit_start
, entryptr
, unit_end
,
10011 dwarf_version
, NULL
,
10018 printf (_(" <no entries>"));
10022 free (abbrev_lookup
);
10029 display_debug_links (struct dwarf_section
* section
,
10030 void * file ATTRIBUTE_UNUSED
)
10032 const unsigned char * filename
;
10033 unsigned int filelen
;
10035 introduce (section
, false);
10037 /* The .gnu_debuglink section is formatted as:
10038 (c-string) Filename.
10039 (padding) If needed to reach a 4 byte boundary.
10040 (uint32_t) CRC32 value.
10042 The .gun_debugaltlink section is formatted as:
10043 (c-string) Filename.
10044 (binary) Build-ID. */
10046 filename
= section
->start
;
10047 filelen
= strnlen ((const char *) filename
, section
->size
);
10048 if (filelen
== section
->size
)
10050 warn (_("The debuglink filename is corrupt/missing\n"));
10054 printf (_(" Separate debug info file: %s\n"), filename
);
10056 if (startswith (section
->name
, ".gnu_debuglink"))
10058 unsigned int crc32
;
10059 unsigned int crc_offset
;
10061 crc_offset
= filelen
+ 1;
10062 crc_offset
= (crc_offset
+ 3) & ~3;
10063 if (crc_offset
+ 4 > section
->size
)
10065 warn (_("CRC offset missing/truncated\n"));
10069 crc32
= byte_get (filename
+ crc_offset
, 4);
10071 printf (_(" CRC value: %#x\n"), crc32
);
10073 if (crc_offset
+ 4 < section
->size
)
10075 warn (_("There are %#lx extraneous bytes at the end of the section\n"),
10076 (long)(section
->size
- (crc_offset
+ 4)));
10080 else /* startswith (section->name, ".gnu_debugaltlink") */
10082 const unsigned char * build_id
= section
->start
+ filelen
+ 1;
10083 bfd_size_type build_id_len
= section
->size
- (filelen
+ 1);
10084 bfd_size_type printed
;
10086 /* FIXME: Should we support smaller build-id notes ? */
10087 if (build_id_len
< 0x14)
10089 warn (_("Build-ID is too short (%#lx bytes)\n"), (long) build_id_len
);
10093 printed
= printf (_(" Build-ID (%#lx bytes):"), (long) build_id_len
);
10094 display_data (printed
, build_id
, build_id_len
);
10103 display_gdb_index (struct dwarf_section
*section
,
10104 void *file ATTRIBUTE_UNUSED
)
10106 unsigned char *start
= section
->start
;
10108 uint32_t cu_list_offset
, tu_list_offset
;
10109 uint32_t address_table_offset
, symbol_table_offset
, constant_pool_offset
;
10110 unsigned int cu_list_elements
, tu_list_elements
;
10111 unsigned int address_table_size
, symbol_table_slots
;
10112 unsigned char *cu_list
, *tu_list
;
10113 unsigned char *address_table
, *symbol_table
, *constant_pool
;
10116 /* The documentation for the format of this file is in gdb/dwarf2read.c. */
10118 introduce (section
, false);
10120 if (section
->size
< 6 * sizeof (uint32_t))
10122 warn (_("Truncated header in the %s section.\n"), section
->name
);
10126 version
= byte_get_little_endian (start
, 4);
10127 printf (_("Version %ld\n"), (long) version
);
10129 /* Prior versions are obsolete, and future versions may not be
10130 backwards compatible. */
10131 if (version
< 3 || version
> 8)
10133 warn (_("Unsupported version %lu.\n"), (unsigned long) version
);
10137 warn (_("The address table data in version 3 may be wrong.\n"));
10139 warn (_("Version 4 does not support case insensitive lookups.\n"));
10141 warn (_("Version 5 does not include inlined functions.\n"));
10143 warn (_("Version 6 does not include symbol attributes.\n"));
10144 /* Version 7 indices generated by Gold have bad type unit references,
10145 PR binutils/15021. But we don't know if the index was generated by
10146 Gold or not, so to avoid worrying users with gdb-generated indices
10147 we say nothing for version 7 here. */
10149 cu_list_offset
= byte_get_little_endian (start
+ 4, 4);
10150 tu_list_offset
= byte_get_little_endian (start
+ 8, 4);
10151 address_table_offset
= byte_get_little_endian (start
+ 12, 4);
10152 symbol_table_offset
= byte_get_little_endian (start
+ 16, 4);
10153 constant_pool_offset
= byte_get_little_endian (start
+ 20, 4);
10155 if (cu_list_offset
> section
->size
10156 || tu_list_offset
> section
->size
10157 || address_table_offset
> section
->size
10158 || symbol_table_offset
> section
->size
10159 || constant_pool_offset
> section
->size
)
10161 warn (_("Corrupt header in the %s section.\n"), section
->name
);
10165 /* PR 17531: file: 418d0a8a. */
10166 if (tu_list_offset
< cu_list_offset
)
10168 warn (_("TU offset (%x) is less than CU offset (%x)\n"),
10169 tu_list_offset
, cu_list_offset
);
10173 cu_list_elements
= (tu_list_offset
- cu_list_offset
) / 8;
10175 if (address_table_offset
< tu_list_offset
)
10177 warn (_("Address table offset (%x) is less than TU offset (%x)\n"),
10178 address_table_offset
, tu_list_offset
);
10182 tu_list_elements
= (address_table_offset
- tu_list_offset
) / 8;
10184 /* PR 17531: file: 18a47d3d. */
10185 if (symbol_table_offset
< address_table_offset
)
10187 warn (_("Symbol table offset (%x) is less then Address table offset (%x)\n"),
10188 symbol_table_offset
, address_table_offset
);
10192 address_table_size
= symbol_table_offset
- address_table_offset
;
10194 if (constant_pool_offset
< symbol_table_offset
)
10196 warn (_("Constant pool offset (%x) is less than symbol table offset (%x)\n"),
10197 constant_pool_offset
, symbol_table_offset
);
10201 symbol_table_slots
= (constant_pool_offset
- symbol_table_offset
) / 8;
10203 cu_list
= start
+ cu_list_offset
;
10204 tu_list
= start
+ tu_list_offset
;
10205 address_table
= start
+ address_table_offset
;
10206 symbol_table
= start
+ symbol_table_offset
;
10207 constant_pool
= start
+ constant_pool_offset
;
10209 if (address_table
+ address_table_size
> section
->start
+ section
->size
)
10211 warn (_("Address table extends beyond end of section.\n"));
10215 printf (_("\nCU table:\n"));
10216 for (i
= 0; i
< cu_list_elements
; i
+= 2)
10218 uint64_t cu_offset
= byte_get_little_endian (cu_list
+ i
* 8, 8);
10219 uint64_t cu_length
= byte_get_little_endian (cu_list
+ i
* 8 + 8, 8);
10221 printf (_("[%3u] 0x%lx - 0x%lx\n"), i
/ 2,
10222 (unsigned long) cu_offset
,
10223 (unsigned long) (cu_offset
+ cu_length
- 1));
10226 printf (_("\nTU table:\n"));
10227 for (i
= 0; i
< tu_list_elements
; i
+= 3)
10229 uint64_t tu_offset
= byte_get_little_endian (tu_list
+ i
* 8, 8);
10230 uint64_t type_offset
= byte_get_little_endian (tu_list
+ i
* 8 + 8, 8);
10231 uint64_t signature
= byte_get_little_endian (tu_list
+ i
* 8 + 16, 8);
10233 printf (_("[%3u] 0x%lx 0x%lx "), i
/ 3,
10234 (unsigned long) tu_offset
,
10235 (unsigned long) type_offset
);
10236 print_dwarf_vma (signature
, 8);
10240 printf (_("\nAddress table:\n"));
10241 for (i
= 0; i
< address_table_size
&& i
<= address_table_size
- (2 * 8 + 4);
10244 uint64_t low
= byte_get_little_endian (address_table
+ i
, 8);
10245 uint64_t high
= byte_get_little_endian (address_table
+ i
+ 8, 8);
10246 uint32_t cu_index
= byte_get_little_endian (address_table
+ i
+ 16, 4);
10248 print_dwarf_vma (low
, 8);
10249 print_dwarf_vma (high
, 8);
10250 printf (_("%lu\n"), (unsigned long) cu_index
);
10253 printf (_("\nSymbol table:\n"));
10254 for (i
= 0; i
< symbol_table_slots
; ++i
)
10256 uint32_t name_offset
= byte_get_little_endian (symbol_table
+ i
* 8, 4);
10257 uint32_t cu_vector_offset
= byte_get_little_endian (symbol_table
+ i
* 8 + 4, 4);
10258 uint32_t num_cus
, cu
;
10260 if (name_offset
!= 0
10261 || cu_vector_offset
!= 0)
10264 unsigned char * adr
;
10266 adr
= constant_pool
+ name_offset
;
10267 /* PR 17531: file: 5b7b07ad. */
10268 if (adr
< constant_pool
|| adr
>= section
->start
+ section
->size
)
10270 printf (_("[%3u] <corrupt offset: %x>"), i
, name_offset
);
10271 warn (_("Corrupt name offset of 0x%x found for symbol table slot %d\n"),
10275 printf ("[%3u] %.*s:", i
,
10276 (int) (section
->size
- (constant_pool_offset
+ name_offset
)),
10277 constant_pool
+ name_offset
);
10279 adr
= constant_pool
+ cu_vector_offset
;
10280 if (adr
< constant_pool
|| adr
>= section
->start
+ section
->size
- 3)
10282 printf (_("<invalid CU vector offset: %x>\n"), cu_vector_offset
);
10283 warn (_("Corrupt CU vector offset of 0x%x found for symbol table slot %d\n"),
10284 cu_vector_offset
, i
);
10288 num_cus
= byte_get_little_endian (adr
, 4);
10290 adr
= constant_pool
+ cu_vector_offset
+ 4 + num_cus
* 4;
10291 if (num_cus
* 4 < num_cus
10292 || adr
>= section
->start
+ section
->size
10293 || adr
< constant_pool
)
10295 printf ("<invalid number of CUs: %d>\n", num_cus
);
10296 warn (_("Invalid number of CUs (0x%x) for symbol table slot %d\n"),
10304 for (j
= 0; j
< num_cus
; ++j
)
10307 gdb_index_symbol_kind kind
;
10309 cu
= byte_get_little_endian (constant_pool
+ cu_vector_offset
+ 4 + j
* 4, 4);
10310 is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu
);
10311 kind
= GDB_INDEX_SYMBOL_KIND_VALUE (cu
);
10312 cu
= GDB_INDEX_CU_VALUE (cu
);
10313 /* Convert to TU number if it's for a type unit. */
10314 if (cu
>= cu_list_elements
/ 2)
10315 printf ("%cT%lu", num_cus
> 1 ? '\t' : ' ',
10316 (unsigned long) (cu
- cu_list_elements
/ 2));
10318 printf ("%c%lu", num_cus
> 1 ? '\t' : ' ', (unsigned long) cu
);
10320 printf (" [%s, %s]",
10321 is_static
? _("static") : _("global"),
10322 get_gdb_index_symbol_kind_name (kind
));
10334 /* Pre-allocate enough space for the CU/TU sets needed. */
10337 prealloc_cu_tu_list (unsigned int nshndx
)
10339 if (shndx_pool
== NULL
)
10341 shndx_pool_size
= nshndx
;
10342 shndx_pool_used
= 0;
10343 shndx_pool
= (unsigned int *) xcmalloc (shndx_pool_size
,
10344 sizeof (unsigned int));
10348 shndx_pool_size
= shndx_pool_used
+ nshndx
;
10349 shndx_pool
= (unsigned int *) xcrealloc (shndx_pool
, shndx_pool_size
,
10350 sizeof (unsigned int));
10355 add_shndx_to_cu_tu_entry (unsigned int shndx
)
10357 if (shndx_pool_used
>= shndx_pool_size
)
10359 error (_("Internal error: out of space in the shndx pool.\n"));
10362 shndx_pool
[shndx_pool_used
++] = shndx
;
10366 end_cu_tu_entry (void)
10368 if (shndx_pool_used
>= shndx_pool_size
)
10370 error (_("Internal error: out of space in the shndx pool.\n"));
10373 shndx_pool
[shndx_pool_used
++] = 0;
10376 /* Return the short name of a DWARF section given by a DW_SECT enumerator. */
10378 static const char *
10379 get_DW_SECT_short_name (unsigned int dw_sect
)
10381 static char buf
[16];
10387 case DW_SECT_TYPES
:
10389 case DW_SECT_ABBREV
:
10395 case DW_SECT_STR_OFFSETS
:
10397 case DW_SECT_MACINFO
:
10399 case DW_SECT_MACRO
:
10405 snprintf (buf
, sizeof (buf
), "%d", dw_sect
);
10409 /* Process a CU or TU index. If DO_DISPLAY is true, print the contents.
10410 These sections are extensions for Fission.
10411 See http://gcc.gnu.org/wiki/DebugFissionDWP. */
10414 process_cu_tu_index (struct dwarf_section
*section
, int do_display
)
10416 unsigned char *phdr
= section
->start
;
10417 unsigned char *limit
= phdr
+ section
->size
;
10418 unsigned char *phash
;
10419 unsigned char *pindex
;
10420 unsigned char *ppool
;
10421 unsigned int version
;
10422 unsigned int ncols
= 0;
10423 unsigned int nused
;
10424 unsigned int nslots
;
10427 dwarf_vma signature_high
;
10428 dwarf_vma signature_low
;
10431 /* PR 17512: file: 002-168123-0.004. */
10434 warn (_("Section %s is empty\n"), section
->name
);
10437 /* PR 17512: file: 002-376-0.004. */
10438 if (section
->size
< 24)
10440 warn (_("Section %s is too small to contain a CU/TU header\n"),
10445 SAFE_BYTE_GET (version
, phdr
, 4, limit
);
10447 SAFE_BYTE_GET (ncols
, phdr
+ 4, 4, limit
);
10448 SAFE_BYTE_GET (nused
, phdr
+ 8, 4, limit
);
10449 SAFE_BYTE_GET (nslots
, phdr
+ 12, 4, limit
);
10452 pindex
= phash
+ (size_t) nslots
* 8;
10453 ppool
= pindex
+ (size_t) nslots
* 4;
10457 introduce (section
, false);
10459 printf (_(" Version: %u\n"), version
);
10461 printf (_(" Number of columns: %u\n"), ncols
);
10462 printf (_(" Number of used entries: %u\n"), nused
);
10463 printf (_(" Number of slots: %u\n\n"), nslots
);
10466 /* PR 17531: file: 45d69832. */
10467 if ((size_t) nslots
* 8 / 8 != nslots
10468 || phash
< phdr
|| phash
> limit
10469 || pindex
< phash
|| pindex
> limit
10470 || ppool
< pindex
|| ppool
> limit
)
10472 warn (ngettext ("Section %s is too small for %u slot\n",
10473 "Section %s is too small for %u slots\n",
10475 section
->name
, nslots
);
10482 prealloc_cu_tu_list ((limit
- ppool
) / 4);
10483 for (i
= 0; i
< nslots
; i
++)
10485 unsigned char *shndx_list
;
10486 unsigned int shndx
;
10488 SAFE_BYTE_GET64 (phash
, &signature_high
, &signature_low
, limit
);
10489 if (signature_high
!= 0 || signature_low
!= 0)
10491 SAFE_BYTE_GET (j
, pindex
, 4, limit
);
10492 shndx_list
= ppool
+ j
* 4;
10493 /* PR 17531: file: 705e010d. */
10494 if (shndx_list
< ppool
)
10496 warn (_("Section index pool located before start of section\n"));
10501 printf (_(" [%3d] Signature: 0x%s Sections: "),
10502 i
, dwarf_vmatoa64 (signature_high
, signature_low
,
10503 buf
, sizeof (buf
)));
10506 if (shndx_list
>= limit
)
10508 warn (_("Section %s too small for shndx pool\n"),
10512 SAFE_BYTE_GET (shndx
, shndx_list
, 4, limit
);
10516 printf (" %d", shndx
);
10518 add_shndx_to_cu_tu_entry (shndx
);
10524 end_cu_tu_entry ();
10530 else if (version
== 2)
10533 unsigned int dw_sect
;
10534 unsigned char *ph
= phash
;
10535 unsigned char *pi
= pindex
;
10536 unsigned char *poffsets
= ppool
+ (size_t) ncols
* 4;
10537 unsigned char *psizes
= poffsets
+ (size_t) nused
* ncols
* 4;
10538 unsigned char *pend
= psizes
+ (size_t) nused
* ncols
* 4;
10540 struct cu_tu_set
*this_set
= NULL
;
10542 unsigned char *prow
;
10544 is_tu_index
= strcmp (section
->name
, ".debug_tu_index") == 0;
10546 /* PR 17531: file: 0dd159bf.
10547 Check for integer overflow (can occur when size_t is 32-bit)
10548 with overlarge ncols or nused values. */
10550 && ((size_t) ncols
* 4 / 4 != ncols
10551 || (size_t) nused
* ncols
* 4 / ((size_t) ncols
* 4) != nused
10552 || poffsets
< ppool
|| poffsets
> limit
10553 || psizes
< poffsets
|| psizes
> limit
10554 || pend
< psizes
|| pend
> limit
))
10556 warn (_("Section %s too small for offset and size tables\n"),
10563 printf (_(" Offset table\n"));
10564 printf (" slot %-16s ",
10565 is_tu_index
? _("signature") : _("dwo_id"));
10572 tu_sets
= xcalloc2 (nused
, sizeof (struct cu_tu_set
));
10573 this_set
= tu_sets
;
10578 cu_sets
= xcalloc2 (nused
, sizeof (struct cu_tu_set
));
10579 this_set
= cu_sets
;
10585 for (j
= 0; j
< ncols
; j
++)
10587 SAFE_BYTE_GET (dw_sect
, ppool
+ j
* 4, 4, limit
);
10588 printf (" %8s", get_DW_SECT_short_name (dw_sect
));
10593 for (i
= 0; i
< nslots
; i
++)
10595 SAFE_BYTE_GET64 (ph
, &signature_high
, &signature_low
, limit
);
10597 SAFE_BYTE_GET (row
, pi
, 4, limit
);
10600 /* PR 17531: file: a05f6ab3. */
10603 warn (_("Row index (%u) is larger than number of used entries (%u)\n"),
10610 size_t num_copy
= sizeof (uint64_t);
10612 /* PR 23064: Beware of buffer overflow. */
10613 if (ph
+ num_copy
< limit
)
10614 memcpy (&this_set
[row
- 1].signature
, ph
, num_copy
);
10617 warn (_("Signature (%p) extends beyond end of space in section\n"), ph
);
10622 prow
= poffsets
+ (row
- 1) * ncols
* 4;
10623 /* PR 17531: file: b8ce60a8. */
10624 if (prow
< poffsets
|| prow
> limit
)
10626 warn (_("Row index (%u) * num columns (%u) > space remaining in section\n"),
10632 printf (_(" [%3d] 0x%s"),
10633 i
, dwarf_vmatoa64 (signature_high
, signature_low
,
10634 buf
, sizeof (buf
)));
10635 for (j
= 0; j
< ncols
; j
++)
10637 SAFE_BYTE_GET (val
, prow
+ j
* 4, 4, limit
);
10639 printf (" %8d", val
);
10642 SAFE_BYTE_GET (dw_sect
, ppool
+ j
* 4, 4, limit
);
10644 /* PR 17531: file: 10796eb3. */
10645 if (dw_sect
>= DW_SECT_MAX
)
10646 warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect
);
10648 this_set
[row
- 1].section_offsets
[dw_sect
] = val
;
10664 printf (_(" Size table\n"));
10665 printf (" slot %-16s ",
10666 is_tu_index
? _("signature") : _("dwo_id"));
10669 for (j
= 0; j
< ncols
; j
++)
10671 SAFE_BYTE_GET (val
, ppool
+ j
* 4, 4, limit
);
10673 printf (" %8s", get_DW_SECT_short_name (val
));
10679 for (i
= 0; i
< nslots
; i
++)
10681 SAFE_BYTE_GET64 (ph
, &signature_high
, &signature_low
, limit
);
10683 SAFE_BYTE_GET (row
, pi
, 4, limit
);
10686 prow
= psizes
+ (row
- 1) * ncols
* 4;
10689 printf (_(" [%3d] 0x%s"),
10690 i
, dwarf_vmatoa64 (signature_high
, signature_low
,
10691 buf
, sizeof (buf
)));
10693 for (j
= 0; j
< ncols
; j
++)
10695 SAFE_BYTE_GET (val
, prow
+ j
* 4, 4, limit
);
10697 printf (" %8d", val
);
10700 SAFE_BYTE_GET (dw_sect
, ppool
+ j
* 4, 4, limit
);
10701 if (dw_sect
>= DW_SECT_MAX
)
10702 warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect
);
10704 this_set
[row
- 1].section_sizes
[dw_sect
] = val
;
10716 else if (do_display
)
10717 printf (_(" Unsupported version (%d)\n"), version
);
10725 static int cu_tu_indexes_read
= -1; /* Tri-state variable. */
10727 /* Load the CU and TU indexes if present. This will build a list of
10728 section sets that we can use to associate a .debug_info.dwo section
10729 with its associated .debug_abbrev.dwo section in a .dwp file. */
10732 load_cu_tu_indexes (void *file
)
10734 /* If we have already loaded (or tried to load) the CU and TU indexes
10735 then do not bother to repeat the task. */
10736 if (cu_tu_indexes_read
== -1)
10738 cu_tu_indexes_read
= true;
10740 if (load_debug_section_with_follow (dwp_cu_index
, file
))
10741 if (! process_cu_tu_index (&debug_displays
[dwp_cu_index
].section
, 0))
10742 cu_tu_indexes_read
= false;
10744 if (load_debug_section_with_follow (dwp_tu_index
, file
))
10745 if (! process_cu_tu_index (&debug_displays
[dwp_tu_index
].section
, 0))
10746 cu_tu_indexes_read
= false;
10749 return (bool) cu_tu_indexes_read
;
10752 /* Find the set of sections that includes section SHNDX. */
10755 find_cu_tu_set (void *file
, unsigned int shndx
)
10759 if (! load_cu_tu_indexes (file
))
10762 /* Find SHNDX in the shndx pool. */
10763 for (i
= 0; i
< shndx_pool_used
; i
++)
10764 if (shndx_pool
[i
] == shndx
)
10767 if (i
>= shndx_pool_used
)
10770 /* Now backup to find the first entry in the set. */
10771 while (i
> 0 && shndx_pool
[i
- 1] != 0)
10774 return shndx_pool
+ i
;
10777 /* Display a .debug_cu_index or .debug_tu_index section. */
10780 display_cu_index (struct dwarf_section
*section
, void *file ATTRIBUTE_UNUSED
)
10782 return process_cu_tu_index (section
, 1);
10786 display_debug_not_supported (struct dwarf_section
*section
,
10787 void *file ATTRIBUTE_UNUSED
)
10789 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
10795 /* Like malloc, but takes two parameters like calloc.
10796 Verifies that the first parameter is not too large.
10797 Note: does *not* initialise the allocated memory to zero. */
10800 cmalloc (size_t nmemb
, size_t size
)
10802 /* Check for overflow. */
10803 if (nmemb
>= ~(size_t) 0 / size
)
10806 return xmalloc (nmemb
* size
);
10809 /* Like xmalloc, but takes two parameters like calloc.
10810 Verifies that the first parameter is not too large.
10811 Note: does *not* initialise the allocated memory to zero. */
10814 xcmalloc (size_t nmemb
, size_t size
)
10816 /* Check for overflow. */
10817 if (nmemb
>= ~(size_t) 0 / size
)
10820 _("Attempt to allocate an array with an excessive number of elements: 0x%lx\n"),
10825 return xmalloc (nmemb
* size
);
10828 /* Like xrealloc, but takes three parameters.
10829 Verifies that the second parameter is not too large.
10830 Note: does *not* initialise any new memory to zero. */
10833 xcrealloc (void *ptr
, size_t nmemb
, size_t size
)
10835 /* Check for overflow. */
10836 if (nmemb
>= ~(size_t) 0 / size
)
10838 error (_("Attempt to re-allocate an array with an excessive number of elements: 0x%lx\n"),
10843 return xrealloc (ptr
, nmemb
* size
);
10846 /* Like xcalloc, but verifies that the first parameter is not too large. */
10849 xcalloc2 (size_t nmemb
, size_t size
)
10851 /* Check for overflow. */
10852 if (nmemb
>= ~(size_t) 0 / size
)
10854 error (_("Attempt to allocate a zero'ed array with an excessive number of elements: 0x%lx\n"),
10859 return xcalloc (nmemb
, size
);
10862 static unsigned long
10863 calc_gnu_debuglink_crc32 (unsigned long crc
,
10864 const unsigned char * buf
,
10867 static const unsigned long crc32_table
[256] =
10869 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
10870 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
10871 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
10872 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
10873 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
10874 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
10875 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
10876 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
10877 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
10878 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
10879 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
10880 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
10881 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
10882 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
10883 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
10884 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
10885 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
10886 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
10887 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
10888 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
10889 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
10890 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
10891 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
10892 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
10893 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
10894 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
10895 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
10896 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
10897 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
10898 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
10899 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
10900 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
10901 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
10902 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
10903 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
10904 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
10905 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
10906 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
10907 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
10908 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
10909 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
10910 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
10911 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
10912 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
10913 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
10914 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
10915 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
10916 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
10917 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
10918 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
10919 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
10922 const unsigned char *end
;
10924 crc
= ~crc
& 0xffffffff;
10925 for (end
= buf
+ len
; buf
< end
; ++ buf
)
10926 crc
= crc32_table
[(crc
^ *buf
) & 0xff] ^ (crc
>> 8);
10927 return ~crc
& 0xffffffff;
10930 typedef bool (*check_func_type
) (const char *, void *);
10931 typedef const char *(* parse_func_type
) (struct dwarf_section
*, void *);
10934 check_gnu_debuglink (const char * pathname
, void * crc_pointer
)
10936 static unsigned char buffer
[8 * 1024];
10938 bfd_size_type count
;
10939 unsigned long crc
= 0;
10942 sep_data
= open_debug_file (pathname
);
10943 if (sep_data
== NULL
)
10946 /* Yes - we are opening the file twice... */
10947 f
= fopen (pathname
, "rb");
10950 /* Paranoia: This should never happen. */
10951 close_debug_file (sep_data
);
10952 warn (_("Unable to reopen separate debug info file: %s\n"), pathname
);
10956 while ((count
= fread (buffer
, 1, sizeof (buffer
), f
)) > 0)
10957 crc
= calc_gnu_debuglink_crc32 (crc
, buffer
, count
);
10961 if (crc
!= * (unsigned long *) crc_pointer
)
10963 close_debug_file (sep_data
);
10964 warn (_("Separate debug info file %s found, but CRC does not match - ignoring\n"),
10972 static const char *
10973 parse_gnu_debuglink (struct dwarf_section
* section
, void * data
)
10976 unsigned int crc_offset
;
10977 unsigned long * crc32
= (unsigned long *) data
;
10979 /* The name is first.
10980 The CRC value is stored after the filename, aligned up to 4 bytes. */
10981 name
= (const char *) section
->start
;
10983 crc_offset
= strnlen (name
, section
->size
) + 1;
10984 if (crc_offset
== 1)
10986 crc_offset
= (crc_offset
+ 3) & ~3;
10987 if (crc_offset
+ 4 > section
->size
)
10990 * crc32
= byte_get (section
->start
+ crc_offset
, 4);
10995 check_gnu_debugaltlink (const char * filename
, void * data ATTRIBUTE_UNUSED
)
10997 void * sep_data
= open_debug_file (filename
);
10999 if (sep_data
== NULL
)
11002 /* FIXME: We should now extract the build-id in the separate file
11008 typedef struct build_id_data
11011 const unsigned char * data
;
11014 static const char *
11015 parse_gnu_debugaltlink (struct dwarf_section
* section
, void * data
)
11018 bfd_size_type namelen
;
11019 bfd_size_type id_len
;
11020 Build_id_data
* build_id_data
;
11022 /* The name is first.
11023 The build-id follows immediately, with no padding, up to the section's end. */
11025 name
= (const char *) section
->start
;
11026 namelen
= strnlen (name
, section
->size
) + 1;
11029 if (namelen
>= section
->size
)
11032 id_len
= section
->size
- namelen
;
11036 build_id_data
= (Build_id_data
*) data
;
11037 build_id_data
->len
= id_len
;
11038 build_id_data
->data
= section
->start
+ namelen
;
11044 add_separate_debug_file (const char * filename
, void * handle
)
11046 separate_info
* i
= xmalloc (sizeof * i
);
11048 i
->filename
= filename
;
11049 i
->handle
= handle
;
11050 i
->next
= first_separate_info
;
11051 first_separate_info
= i
;
11054 #if HAVE_LIBDEBUGINFOD
11055 /* Query debuginfod servers for the target debuglink or debugaltlink
11056 file. If successful, store the path of the file in filename and
11057 return TRUE, otherwise return FALSE. */
11060 debuginfod_fetch_separate_debug_info (struct dwarf_section
* section
,
11064 size_t build_id_len
;
11065 unsigned char * build_id
;
11067 if (strcmp (section
->uncompressed_name
, ".gnu_debuglink") == 0)
11069 /* Get the build-id of file. */
11070 build_id
= get_build_id (file
);
11073 else if (strcmp (section
->uncompressed_name
, ".gnu_debugaltlink") == 0)
11075 /* Get the build-id of the debugaltlink file. */
11076 unsigned int filelen
;
11078 filelen
= strnlen ((const char *)section
->start
, section
->size
);
11079 if (filelen
== section
->size
)
11080 /* Corrupt debugaltlink. */
11083 build_id
= section
->start
+ filelen
+ 1;
11084 build_id_len
= section
->size
- (filelen
+ 1);
11086 if (build_id_len
== 0)
11095 debuginfod_client
* client
;
11097 client
= debuginfod_begin ();
11098 if (client
== NULL
)
11101 /* Query debuginfod servers for the target file. If found its path
11102 will be stored in filename. */
11103 fd
= debuginfod_find_debuginfo (client
, build_id
, build_id_len
, filename
);
11104 debuginfod_end (client
);
11106 /* Only free build_id if we allocated space for a hex string
11107 in get_build_id (). */
11108 if (build_id_len
== 0)
11113 /* File successfully retrieved. Close fd since we want to
11114 use open_debug_file () on filename instead. */
11125 load_separate_debug_info (const char * main_filename
,
11126 struct dwarf_section
* xlink
,
11127 parse_func_type parse_func
,
11128 check_func_type check_func
,
11130 void * file ATTRIBUTE_UNUSED
)
11132 const char * separate_filename
;
11133 char * debug_filename
;
11135 size_t canon_dirlen
;
11138 if ((separate_filename
= parse_func (xlink
, func_data
)) == NULL
)
11140 warn (_("Corrupt debuglink section: %s\n"),
11141 xlink
->name
? xlink
->name
: xlink
->uncompressed_name
);
11145 /* Attempt to locate the separate file.
11146 This should duplicate the logic in bfd/opncls.c:find_separate_debug_file(). */
11148 canon_dir
= lrealpath (main_filename
);
11150 for (canon_dirlen
= strlen (canon_dir
); canon_dirlen
> 0; canon_dirlen
--)
11151 if (IS_DIR_SEPARATOR (canon_dir
[canon_dirlen
- 1]))
11153 canon_dir
[canon_dirlen
] = '\0';
11156 #define DEBUGDIR "/lib/debug"
11158 #ifndef EXTRA_DEBUG_ROOT1
11159 #define EXTRA_DEBUG_ROOT1 "/usr/lib/debug"
11161 #ifndef EXTRA_DEBUG_ROOT2
11162 #define EXTRA_DEBUG_ROOT2 "/usr/lib/debug/usr"
11165 debug_filename
= (char *) malloc (strlen (DEBUGDIR
) + 1
11167 + strlen (".debug/")
11168 #ifdef EXTRA_DEBUG_ROOT1
11169 + strlen (EXTRA_DEBUG_ROOT1
)
11171 #ifdef EXTRA_DEBUG_ROOT2
11172 + strlen (EXTRA_DEBUG_ROOT2
)
11174 + strlen (separate_filename
)
11176 if (debug_filename
== NULL
)
11178 warn (_("Out of memory"));
11183 /* First try in the current directory. */
11184 sprintf (debug_filename
, "%s", separate_filename
);
11185 if (check_func (debug_filename
, func_data
))
11188 /* Then try in a subdirectory called .debug. */
11189 sprintf (debug_filename
, ".debug/%s", separate_filename
);
11190 if (check_func (debug_filename
, func_data
))
11193 /* Then try in the same directory as the original file. */
11194 sprintf (debug_filename
, "%s%s", canon_dir
, separate_filename
);
11195 if (check_func (debug_filename
, func_data
))
11198 /* And the .debug subdirectory of that directory. */
11199 sprintf (debug_filename
, "%s.debug/%s", canon_dir
, separate_filename
);
11200 if (check_func (debug_filename
, func_data
))
11203 #ifdef EXTRA_DEBUG_ROOT1
11204 /* Try the first extra debug file root. */
11205 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT1
, separate_filename
);
11206 if (check_func (debug_filename
, func_data
))
11209 /* Try the first extra debug file root. */
11210 sprintf (debug_filename
, "%s/%s/%s", EXTRA_DEBUG_ROOT1
, canon_dir
, separate_filename
);
11211 if (check_func (debug_filename
, func_data
))
11215 #ifdef EXTRA_DEBUG_ROOT2
11216 /* Try the second extra debug file root. */
11217 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT2
, separate_filename
);
11218 if (check_func (debug_filename
, func_data
))
11222 /* Then try in the global debug_filename directory. */
11223 strcpy (debug_filename
, DEBUGDIR
);
11224 dirlen
= strlen (DEBUGDIR
) - 1;
11225 if (dirlen
> 0 && DEBUGDIR
[dirlen
] != '/')
11226 strcat (debug_filename
, "/");
11227 strcat (debug_filename
, (const char *) separate_filename
);
11229 if (check_func (debug_filename
, func_data
))
11232 #if HAVE_LIBDEBUGINFOD
11234 char * tmp_filename
;
11236 if (debuginfod_fetch_separate_debug_info (xlink
,
11240 /* File successfully downloaded from server, replace
11241 debug_filename with the file's path. */
11242 free (debug_filename
);
11243 debug_filename
= tmp_filename
;
11249 if (do_debug_links
)
11251 /* Failed to find the file. */
11252 warn (_("could not find separate debug file '%s'\n"),
11253 separate_filename
);
11254 warn (_("tried: %s\n"), debug_filename
);
11256 #ifdef EXTRA_DEBUG_ROOT2
11257 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT2
,
11258 separate_filename
);
11259 warn (_("tried: %s\n"), debug_filename
);
11262 #ifdef EXTRA_DEBUG_ROOT1
11263 sprintf (debug_filename
, "%s/%s/%s", EXTRA_DEBUG_ROOT1
,
11264 canon_dir
, separate_filename
);
11265 warn (_("tried: %s\n"), debug_filename
);
11267 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT1
,
11268 separate_filename
);
11269 warn (_("tried: %s\n"), debug_filename
);
11272 sprintf (debug_filename
, "%s.debug/%s", canon_dir
,
11273 separate_filename
);
11274 warn (_("tried: %s\n"), debug_filename
);
11276 sprintf (debug_filename
, "%s%s", canon_dir
, separate_filename
);
11277 warn (_("tried: %s\n"), debug_filename
);
11279 sprintf (debug_filename
, ".debug/%s", separate_filename
);
11280 warn (_("tried: %s\n"), debug_filename
);
11282 sprintf (debug_filename
, "%s", separate_filename
);
11283 warn (_("tried: %s\n"), debug_filename
);
11285 #if HAVE_LIBDEBUGINFOD
11287 char *urls
= getenv (DEBUGINFOD_URLS_ENV_VAR
);
11291 warn (_("tried: DEBUGINFOD_URLS=%s\n"), urls
);
11297 free (debug_filename
);
11303 void * debug_handle
;
11305 /* Now open the file.... */
11306 if ((debug_handle
= open_debug_file (debug_filename
)) == NULL
)
11308 warn (_("failed to open separate debug file: %s\n"), debug_filename
);
11309 free (debug_filename
);
11313 /* FIXME: We do not check to see if there are any other separate debug info
11314 files that would also match. */
11316 if (do_debug_links
)
11317 printf (_("\n%s: Found separate debug info file: %s\n"), main_filename
, debug_filename
);
11318 add_separate_debug_file (debug_filename
, debug_handle
);
11320 /* Do not free debug_filename - it might be referenced inside
11321 the structure returned by open_debug_file(). */
11322 return debug_handle
;
11325 /* Attempt to load a separate dwarf object file. */
11328 load_dwo_file (const char * main_filename
, const char * name
, const char * dir
, const char * id ATTRIBUTE_UNUSED
)
11330 char * separate_filename
;
11331 void * separate_handle
;
11333 if (IS_ABSOLUTE_PATH (name
))
11334 separate_filename
= strdup (name
);
11336 /* FIXME: Skip adding / if dwo_dir ends in /. */
11337 separate_filename
= concat (dir
, "/", name
, NULL
);
11338 if (separate_filename
== NULL
)
11340 warn (_("Out of memory allocating dwo filename\n"));
11344 if ((separate_handle
= open_debug_file (separate_filename
)) == NULL
)
11346 warn (_("Unable to load dwo file: %s\n"), separate_filename
);
11347 free (separate_filename
);
11351 /* FIXME: We should check the dwo_id. */
11353 printf (_("%s: Found separate debug object file: %s\n\n"), main_filename
, separate_filename
);
11355 add_separate_debug_file (separate_filename
, separate_handle
);
11356 /* Note - separate_filename will be freed in free_debug_memory(). */
11357 return separate_handle
;
11361 load_debug_sup_file (const char * main_filename
, void * file
)
11363 if (! load_debug_section (debug_sup
, file
))
11364 return; /* No .debug_sup section. */
11366 struct dwarf_section
* section
;
11367 section
= & debug_displays
[debug_sup
].section
;
11368 assert (section
!= NULL
);
11370 if (section
->start
== NULL
|| section
->size
< 5)
11372 warn (_(".debug_sup section is corrupt/empty\n"));
11376 if (section
->start
[2] != 0)
11377 return; /* This is a supplementary file. */
11379 const char * filename
= (const char *) section
->start
+ 3;
11380 if (strnlen (filename
, section
->size
- 3) == section
->size
- 3)
11382 warn (_("filename in .debug_sup section is corrupt\n"));
11386 if (filename
[0] != '/' && strchr (main_filename
, '/'))
11391 new_len
= asprintf (& new_name
, "%.*s/%s",
11392 (int) (strrchr (main_filename
, '/') - main_filename
),
11397 warn (_("unable to construct path for supplementary debug file"));
11402 filename
= new_name
;
11406 /* PR 27796: Make sure that we pass a filename that can be free'd to
11407 add_separate_debug_file(). */
11408 filename
= strdup (filename
);
11409 if (filename
== NULL
)
11411 warn (_("out of memory constructing filename for .debug_sup link\n"));
11416 void * handle
= open_debug_file (filename
);
11417 if (handle
== NULL
)
11419 warn (_("unable to open file '%s' referenced from .debug_sup section\n"), filename
);
11420 free ((void *) filename
);
11424 printf (_("%s: Found supplementary debug file: %s\n\n"), main_filename
, filename
);
11426 /* FIXME: Compare the checksums, if present. */
11427 add_separate_debug_file (filename
, handle
);
11430 /* Load a debuglink section and/or a debugaltlink section, if either are present.
11431 Recursively check the loaded files for more of these sections.
11432 Also follow any links in .debug_sup sections.
11433 FIXME: Should also check for DWO_* entries in the newly loaded files. */
11436 check_for_and_load_links (void * file
, const char * filename
)
11438 void * handle
= NULL
;
11440 if (load_debug_section (gnu_debugaltlink
, file
))
11442 Build_id_data build_id_data
;
11444 handle
= load_separate_debug_info (filename
,
11445 & debug_displays
[gnu_debugaltlink
].section
,
11446 parse_gnu_debugaltlink
,
11447 check_gnu_debugaltlink
,
11452 assert (handle
== first_separate_info
->handle
);
11453 check_for_and_load_links (first_separate_info
->handle
,
11454 first_separate_info
->filename
);
11458 if (load_debug_section (gnu_debuglink
, file
))
11460 unsigned long crc32
;
11462 handle
= load_separate_debug_info (filename
,
11463 & debug_displays
[gnu_debuglink
].section
,
11464 parse_gnu_debuglink
,
11465 check_gnu_debuglink
,
11470 assert (handle
== first_separate_info
->handle
);
11471 check_for_and_load_links (first_separate_info
->handle
,
11472 first_separate_info
->filename
);
11476 load_debug_sup_file (filename
, file
);
11479 /* Load the separate debug info file(s) attached to FILE, if any exist.
11480 Returns TRUE if any were found, FALSE otherwise.
11481 If TRUE is returned then the linked list starting at first_separate_info
11482 will be populated with open file handles. */
11485 load_separate_debug_files (void * file
, const char * filename
)
11487 /* Skip this operation if we are not interested in debug links. */
11488 if (! do_follow_links
&& ! do_debug_links
)
11491 /* See if there are any dwo links. */
11492 if (load_debug_section (str
, file
)
11493 && load_debug_section (abbrev
, file
)
11494 && load_debug_section (info
, file
))
11498 if (process_debug_info (& debug_displays
[info
].section
, file
, abbrev
,
11501 bool introduced
= false;
11503 const char *dir
= NULL
;
11504 const char *id
= NULL
;
11505 const char *name
= NULL
;
11507 for (dwinfo
= first_dwo_info
; dwinfo
!= NULL
; dwinfo
= dwinfo
->next
)
11509 /* Accumulate NAME, DIR and ID fields. */
11510 switch (dwinfo
->type
)
11514 warn (_("Multiple DWO_NAMEs encountered for the same CU\n"));
11515 name
= dwinfo
->value
;
11519 /* There can be multiple DW_AT_comp_dir entries in a CU,
11520 so do not complain. */
11521 dir
= dwinfo
->value
;
11526 warn (_("multiple DWO_IDs encountered for the same CU\n"));
11527 id
= dwinfo
->value
;
11531 error (_("Unexpected DWO INFO type"));
11535 /* If we have reached the end of our list, or we are changing
11536 CUs, then display the information that we have accumulated
11539 && (dwinfo
->next
== NULL
11540 || dwinfo
->next
->cu_offset
!= dwinfo
->cu_offset
))
11542 if (do_debug_links
)
11546 printf (_("The %s section contains link(s) to dwo file(s):\n\n"),
11547 debug_displays
[info
].section
.uncompressed_name
);
11551 printf (_(" Name: %s\n"), name
);
11552 printf (_(" Directory: %s\n"), dir
? dir
: _("<not-found>"));
11554 display_data (printf (_(" ID: ")), (unsigned char *) id
, 8);
11556 printf (_(" ID: <not specified>\n"));
11560 if (do_follow_links
)
11561 load_dwo_file (filename
, name
, dir
, id
);
11563 name
= dir
= id
= NULL
;
11569 if (! do_follow_links
)
11570 /* The other debug links will be displayed by display_debug_links()
11571 so we do not need to do any further processing here. */
11574 /* FIXME: We do not check for the presence of both link sections in the same file. */
11575 /* FIXME: We do not check for the presence of multiple, same-name debuglink sections. */
11576 /* FIXME: We do not check for the presence of a dwo link as well as a debuglink. */
11578 check_for_and_load_links (file
, filename
);
11579 if (first_separate_info
!= NULL
)
11582 do_follow_links
= 0;
11587 free_debug_memory (void)
11591 free_all_abbrevs ();
11593 free (cu_abbrev_map
);
11594 cu_abbrev_map
= NULL
;
11595 next_free_abbrev_map_entry
= 0;
11599 shndx_pool_size
= 0;
11600 shndx_pool_used
= 0;
11608 memset (level_type_signed
, 0, sizeof level_type_signed
);
11609 cu_tu_indexes_read
= -1;
11611 for (i
= 0; i
< max
; i
++)
11612 free_debug_section ((enum dwarf_section_display_enum
) i
);
11614 if (debug_information
!= NULL
)
11616 for (i
= 0; i
< alloc_num_debug_info_entries
; i
++)
11618 if (debug_information
[i
].max_loc_offsets
)
11620 free (debug_information
[i
].loc_offsets
);
11621 free (debug_information
[i
].have_frame_base
);
11623 if (debug_information
[i
].max_range_lists
)
11624 free (debug_information
[i
].range_lists
);
11626 free (debug_information
);
11627 debug_information
= NULL
;
11628 alloc_num_debug_info_entries
= num_debug_info_entries
= 0;
11632 separate_info
* next
;
11634 for (d
= first_separate_info
; d
!= NULL
; d
= next
)
11636 close_debug_file (d
->handle
);
11637 free ((void *) d
->filename
);
11641 first_separate_info
= NULL
;
11647 dwarf_select_sections_by_names (const char *names
)
11651 const char * option
;
11655 debug_dump_long_opts
;
11657 static const debug_dump_long_opts opts_table
[] =
11659 /* Please keep this table alpha- sorted. */
11660 { "Ranges", & do_debug_ranges
, 1 },
11661 { "abbrev", & do_debug_abbrevs
, 1 },
11662 { "addr", & do_debug_addr
, 1 },
11663 { "aranges", & do_debug_aranges
, 1 },
11664 { "cu_index", & do_debug_cu_index
, 1 },
11665 { "decodedline", & do_debug_lines
, FLAG_DEBUG_LINES_DECODED
},
11666 { "follow-links", & do_follow_links
, 1 },
11667 { "frames", & do_debug_frames
, 1 },
11668 { "frames-interp", & do_debug_frames_interp
, 1 },
11669 /* The special .gdb_index section. */
11670 { "gdb_index", & do_gdb_index
, 1 },
11671 { "info", & do_debug_info
, 1 },
11672 { "line", & do_debug_lines
, FLAG_DEBUG_LINES_RAW
}, /* For backwards compatibility. */
11673 { "links", & do_debug_links
, 1 },
11674 { "loc", & do_debug_loc
, 1 },
11675 { "macro", & do_debug_macinfo
, 1 },
11676 { "no-follow-links", & do_follow_links
, 0 },
11677 { "pubnames", & do_debug_pubnames
, 1 },
11678 { "pubtypes", & do_debug_pubtypes
, 1 },
11679 /* This entry is for compatibility
11680 with earlier versions of readelf. */
11681 { "ranges", & do_debug_aranges
, 1 },
11682 { "rawline", & do_debug_lines
, FLAG_DEBUG_LINES_RAW
},
11683 { "str", & do_debug_str
, 1 },
11684 { "str-offsets", & do_debug_str_offsets
, 1 },
11685 /* These trace_* sections are used by Itanium VMS. */
11686 { "trace_abbrev", & do_trace_abbrevs
, 1 },
11687 { "trace_aranges", & do_trace_aranges
, 1 },
11688 { "trace_info", & do_trace_info
, 1 },
11697 const debug_dump_long_opts
* entry
;
11699 for (entry
= opts_table
; entry
->option
; entry
++)
11701 size_t len
= strlen (entry
->option
);
11703 if (strncmp (p
, entry
->option
, len
) == 0
11704 && (p
[len
] == ',' || p
[len
] == '\0'))
11706 * entry
->variable
= entry
->val
;
11708 /* The --debug-dump=frames-interp option also
11709 enables the --debug-dump=frames option. */
11710 if (do_debug_frames_interp
)
11711 do_debug_frames
= 1;
11718 if (entry
->option
== NULL
)
11720 warn (_("Unrecognized debug option '%s'\n"), p
);
11721 p
= strchr (p
, ',');
11732 dwarf_select_sections_by_letters (const char *letters
)
11734 unsigned int lindex
= 0;
11736 while (letters
[lindex
])
11737 switch (letters
[lindex
++])
11739 case 'A': do_debug_addr
= 1; break;
11740 case 'a': do_debug_abbrevs
= 1; break;
11741 case 'c': do_debug_cu_index
= 1; break;
11742 case 'F': do_debug_frames_interp
= 1; /* Fall through. */
11743 case 'f': do_debug_frames
= 1; break;
11744 case 'g': do_gdb_index
= 1; break;
11745 case 'i': do_debug_info
= 1; break;
11746 case 'K': do_follow_links
= 1; break;
11747 case 'N': do_follow_links
= 0; break;
11748 case 'k': do_debug_links
= 1; break;
11749 case 'l': do_debug_lines
|= FLAG_DEBUG_LINES_RAW
; break;
11750 case 'L': do_debug_lines
|= FLAG_DEBUG_LINES_DECODED
; break;
11751 case 'm': do_debug_macinfo
= 1; break;
11752 case 'O': do_debug_str_offsets
= 1; break;
11753 case 'o': do_debug_loc
= 1; break;
11754 case 'p': do_debug_pubnames
= 1; break;
11755 case 'R': do_debug_ranges
= 1; break;
11756 case 'r': do_debug_aranges
= 1; break;
11757 case 's': do_debug_str
= 1; break;
11758 case 'T': do_trace_aranges
= 1; break;
11759 case 't': do_debug_pubtypes
= 1; break;
11760 case 'U': do_trace_info
= 1; break;
11761 case 'u': do_trace_abbrevs
= 1; break;
11764 warn (_("Unrecognized debug option '%s'\n"), letters
);
11770 dwarf_select_sections_all (void)
11773 do_debug_abbrevs
= 1;
11774 do_debug_lines
= FLAG_DEBUG_LINES_RAW
;
11775 do_debug_pubnames
= 1;
11776 do_debug_pubtypes
= 1;
11777 do_debug_aranges
= 1;
11778 do_debug_ranges
= 1;
11779 do_debug_frames
= 1;
11780 do_debug_macinfo
= 1;
11785 do_trace_abbrevs
= 1;
11786 do_trace_aranges
= 1;
11788 do_debug_cu_index
= 1;
11789 do_follow_links
= 1;
11790 do_debug_links
= 1;
11791 do_debug_str_offsets
= 1;
11794 #define NO_ABBREVS NULL, NULL, NULL, 0, 0, 0, NULL, 0
11795 #define ABBREV(N) NULL, NULL, NULL, 0, 0, N, NULL, 0
11797 /* N.B. The order here must match the order in section_display_enum. */
11799 struct dwarf_section_display debug_displays
[] =
11801 { { ".debug_abbrev", ".zdebug_abbrev", NO_ABBREVS
}, display_debug_abbrev
, &do_debug_abbrevs
, false },
11802 { { ".debug_aranges", ".zdebug_aranges", NO_ABBREVS
}, display_debug_aranges
, &do_debug_aranges
, true },
11803 { { ".debug_frame", ".zdebug_frame", NO_ABBREVS
}, display_debug_frames
, &do_debug_frames
, true },
11804 { { ".debug_info", ".zdebug_info", ABBREV (abbrev
)}, display_debug_info
, &do_debug_info
, true },
11805 { { ".debug_line", ".zdebug_line", NO_ABBREVS
}, display_debug_lines
, &do_debug_lines
, true },
11806 { { ".debug_pubnames", ".zdebug_pubnames", NO_ABBREVS
}, display_debug_pubnames
, &do_debug_pubnames
, false },
11807 { { ".debug_gnu_pubnames", ".zdebug_gnu_pubnames", NO_ABBREVS
}, display_debug_gnu_pubnames
, &do_debug_pubnames
, false },
11808 { { ".eh_frame", "", NO_ABBREVS
}, display_debug_frames
, &do_debug_frames
, true },
11809 { { ".debug_macinfo", ".zdebug_macinfo", NO_ABBREVS
}, display_debug_macinfo
, &do_debug_macinfo
, false },
11810 { { ".debug_macro", ".zdebug_macro", NO_ABBREVS
}, display_debug_macro
, &do_debug_macinfo
, true },
11811 { { ".debug_str", ".zdebug_str", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, false },
11812 { { ".debug_line_str", ".zdebug_line_str", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, false },
11813 { { ".debug_loc", ".zdebug_loc", NO_ABBREVS
}, display_debug_loc
, &do_debug_loc
, true },
11814 { { ".debug_loclists", ".zdebug_loclists", NO_ABBREVS
}, display_debug_loc
, &do_debug_loc
, true },
11815 { { ".debug_pubtypes", ".zdebug_pubtypes", NO_ABBREVS
}, display_debug_pubnames
, &do_debug_pubtypes
, false },
11816 { { ".debug_gnu_pubtypes", ".zdebug_gnu_pubtypes", NO_ABBREVS
}, display_debug_gnu_pubnames
, &do_debug_pubtypes
, false },
11817 { { ".debug_ranges", ".zdebug_ranges", NO_ABBREVS
}, display_debug_ranges
, &do_debug_ranges
, true },
11818 { { ".debug_rnglists", ".zdebug_rnglists", NO_ABBREVS
}, display_debug_ranges
, &do_debug_ranges
, true },
11819 { { ".debug_static_func", ".zdebug_static_func", NO_ABBREVS
}, display_debug_not_supported
, NULL
, false },
11820 { { ".debug_static_vars", ".zdebug_static_vars", NO_ABBREVS
}, display_debug_not_supported
, NULL
, false },
11821 { { ".debug_types", ".zdebug_types", ABBREV (abbrev
) }, display_debug_types
, &do_debug_info
, true },
11822 { { ".debug_weaknames", ".zdebug_weaknames", NO_ABBREVS
}, display_debug_not_supported
, NULL
, false },
11823 { { ".gdb_index", "", NO_ABBREVS
}, display_gdb_index
, &do_gdb_index
, false },
11824 { { ".debug_names", "", NO_ABBREVS
}, display_debug_names
, &do_gdb_index
, false },
11825 { { ".trace_info", "", ABBREV (trace_abbrev
) }, display_trace_info
, &do_trace_info
, true },
11826 { { ".trace_abbrev", "", NO_ABBREVS
}, display_debug_abbrev
, &do_trace_abbrevs
, false },
11827 { { ".trace_aranges", "", NO_ABBREVS
}, display_debug_aranges
, &do_trace_aranges
, false },
11828 { { ".debug_info.dwo", ".zdebug_info.dwo", ABBREV (abbrev_dwo
) }, display_debug_info
, &do_debug_info
, true },
11829 { { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo", NO_ABBREVS
}, display_debug_abbrev
, &do_debug_abbrevs
, false },
11830 { { ".debug_types.dwo", ".zdebug_types.dwo", ABBREV (abbrev_dwo
) }, display_debug_types
, &do_debug_info
, true },
11831 { { ".debug_line.dwo", ".zdebug_line.dwo", NO_ABBREVS
}, display_debug_lines
, &do_debug_lines
, true },
11832 { { ".debug_loc.dwo", ".zdebug_loc.dwo", NO_ABBREVS
}, display_debug_loc
, &do_debug_loc
, true },
11833 { { ".debug_macro.dwo", ".zdebug_macro.dwo", NO_ABBREVS
}, display_debug_macro
, &do_debug_macinfo
, true },
11834 { { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo", NO_ABBREVS
}, display_debug_macinfo
, &do_debug_macinfo
, false },
11835 { { ".debug_str.dwo", ".zdebug_str.dwo", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, true },
11836 { { ".debug_str_offsets", ".zdebug_str_offsets", NO_ABBREVS
}, display_debug_str_offsets
, &do_debug_str_offsets
, true },
11837 { { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo", NO_ABBREVS
}, display_debug_str_offsets
, &do_debug_str_offsets
, true },
11838 { { ".debug_addr", ".zdebug_addr", NO_ABBREVS
}, display_debug_addr
, &do_debug_addr
, true },
11839 { { ".debug_cu_index", "", NO_ABBREVS
}, display_cu_index
, &do_debug_cu_index
, false },
11840 { { ".debug_tu_index", "", NO_ABBREVS
}, display_cu_index
, &do_debug_cu_index
, false },
11841 { { ".gnu_debuglink", "", NO_ABBREVS
}, display_debug_links
, &do_debug_links
, false },
11842 { { ".gnu_debugaltlink", "", NO_ABBREVS
}, display_debug_links
, &do_debug_links
, false },
11843 { { ".debug_sup", "", NO_ABBREVS
}, display_debug_sup
, &do_debug_links
, false },
11844 /* Separate debug info files can containt their own .debug_str section,
11845 and this might be in *addition* to a .debug_str section already present
11846 in the main file. Hence we need to have two entries for .debug_str. */
11847 { { ".debug_str", ".zdebug_str", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, false },
11850 /* A static assertion. */
11851 extern int debug_displays_assert
[ARRAY_SIZE (debug_displays
) == max
? 1 : -1];