1 /* dwarf.c -- display DWARF contents of a BFD binary file
2 Copyright (C) 2005-2021 Free Software Foundation, Inc.
4 This file is part of GNU Binutils.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
22 #include "libiberty.h"
27 #include "elf/common.h"
30 #include "gdb/gdb-index.h"
31 #include "filenames.h"
32 #include "safe-ctype.h"
35 #ifdef HAVE_LIBDEBUGINFOD
36 #include <elfutils/debuginfod.h>
46 #define MAX(a, b) ((a) > (b) ? (a) : (b))
47 #define MIN(a, b) ((a) < (b) ? (a) : (b))
49 static const char *regname (unsigned int regno
, int row
);
50 static const char *regname_internal_by_table_only (unsigned int regno
);
52 static int have_frame_base
;
53 static int need_base_address
;
55 static unsigned int num_debug_info_entries
= 0;
56 static unsigned int alloc_num_debug_info_entries
= 0;
57 static debug_info
*debug_information
= NULL
;
58 /* Special value for num_debug_info_entries to indicate
59 that the .debug_info section could not be loaded/parsed. */
60 #define DEBUG_INFO_UNAVAILABLE (unsigned int) -1
62 /* A .debug_info section can contain multiple links to separate
63 DWO object files. We use these structures to record these links. */
71 typedef struct dwo_info
76 struct dwo_info
* next
;
79 static dwo_info
*first_dwo_info
= NULL
;
80 static bool need_dwo_info
;
82 separate_info
* first_separate_info
= NULL
;
84 unsigned int eh_addr_size
;
89 int do_debug_pubnames
;
90 int do_debug_pubtypes
;
94 int do_debug_frames_interp
;
97 int do_debug_str_offsets
;
101 int do_trace_abbrevs
;
102 int do_trace_aranges
;
104 int do_debug_cu_index
;
107 int do_follow_links
= DEFAULT_FOR_FOLLOW_LINKS
;
110 int dwarf_cutoff_level
= -1;
111 unsigned long dwarf_start_die
;
115 /* Convenient constant, to avoid having to cast -1 to dwarf_vma when
116 testing whether e.g. a locview list is present. */
117 static const dwarf_vma vm1
= -1;
119 /* Collection of CU/TU section sets from .debug_cu_index and .debug_tu_index
120 sections. For version 1 package files, each set is stored in SHNDX_POOL
121 as a zero-terminated list of section indexes comprising one set of debug
122 sections from a .dwo file. */
124 static unsigned int *shndx_pool
= NULL
;
125 static unsigned int shndx_pool_size
= 0;
126 static unsigned int shndx_pool_used
= 0;
128 /* For version 2 package files, each set contains an array of section offsets
129 and an array of section sizes, giving the offset and size of the
130 contribution from a CU or TU within one of the debug sections.
131 When displaying debug info from a package file, we need to use these
132 tables to locate the corresponding contributions to each section. */
137 dwarf_vma section_offsets
[DW_SECT_MAX
];
138 size_t section_sizes
[DW_SECT_MAX
];
141 static int cu_count
= 0;
142 static int tu_count
= 0;
143 static struct cu_tu_set
*cu_sets
= NULL
;
144 static struct cu_tu_set
*tu_sets
= NULL
;
146 static bool load_cu_tu_indexes (void *);
148 /* An array that indicates for a given level of CU nesting whether
149 the latest DW_AT_type seen for that level was a signed type or
151 #define MAX_CU_NESTING (1 << 8)
152 static bool level_type_signed
[MAX_CU_NESTING
];
154 /* Values for do_debug_lines. */
155 #define FLAG_DEBUG_LINES_RAW 1
156 #define FLAG_DEBUG_LINES_DECODED 2
159 size_of_encoded_value (int encoding
)
161 switch (encoding
& 0x7)
164 case 0: return eh_addr_size
;
172 get_encoded_value (unsigned char **pdata
,
174 struct dwarf_section
*section
,
177 unsigned char * data
= * pdata
;
178 unsigned int size
= size_of_encoded_value (encoding
);
181 if (data
+ size
>= end
)
183 warn (_("Encoded value extends past end of section\n"));
188 /* PR 17512: file: 002-829853-0.004. */
191 warn (_("Encoded size of %d is too large to read\n"), size
);
196 /* PR 17512: file: 1085-5603-0.004. */
199 warn (_("Encoded size of 0 is too small to read\n"));
204 if (encoding
& DW_EH_PE_signed
)
205 val
= byte_get_signed (data
, size
);
207 val
= byte_get (data
, size
);
209 if ((encoding
& 0x70) == DW_EH_PE_pcrel
)
210 val
+= section
->address
+ (data
- section
->start
);
212 * pdata
= data
+ size
;
216 #if SIZEOF_LONG_LONG > SIZEOF_LONG
218 # define DWARF_VMA_FMT "ll"
219 # define DWARF_VMA_FMT_LONG "%16.16llx"
221 # define DWARF_VMA_FMT "I64"
222 # define DWARF_VMA_FMT_LONG "%016I64x"
225 # define DWARF_VMA_FMT "l"
226 # define DWARF_VMA_FMT_LONG "%16.16lx"
229 /* Convert a dwarf vma value into a string. Returns a pointer to a static
230 buffer containing the converted VALUE. The value is converted according
231 to the printf formating character FMTCH. If NUM_BYTES is non-zero then
232 it specifies the maximum number of bytes to be displayed in the converted
233 value and FMTCH is ignored - hex is always used. */
236 dwarf_vmatoa_1 (const char *fmtch
, dwarf_vma value
, unsigned num_bytes
)
238 /* As dwarf_vmatoa is used more then once in a printf call
239 for output, we are cycling through an fixed array of pointers
240 for return address. */
241 static int buf_pos
= 0;
242 static struct dwarf_vmatoa_buf
248 ret
= buf
[buf_pos
++].place
;
249 buf_pos
%= ARRAY_SIZE (buf
);
253 /* Printf does not have a way of specifying a maximum field width for an
254 integer value, so we print the full value into a buffer and then select
255 the precision we need. */
256 snprintf (ret
, sizeof (buf
[0].place
), DWARF_VMA_FMT_LONG
, value
);
259 return ret
+ (16 - 2 * num_bytes
);
266 sprintf (fmt
, "%%%s%s", DWARF_VMA_FMT
, fmtch
);
268 sprintf (fmt
, "%%%s", DWARF_VMA_FMT
);
269 snprintf (ret
, sizeof (buf
[0].place
), fmt
, value
);
274 static inline const char *
275 dwarf_vmatoa (const char * fmtch
, dwarf_vma value
)
277 return dwarf_vmatoa_1 (fmtch
, value
, 0);
280 /* Print a dwarf_vma value (typically an address, offset or length) in
281 hexadecimal format, followed by a space. The length of the VALUE (and
282 hence the precision displayed) is determined by the NUM_BYTES parameter. */
285 print_dwarf_vma (dwarf_vma value
, unsigned num_bytes
)
287 printf ("%s ", dwarf_vmatoa_1 (NULL
, value
, num_bytes
));
290 /* Print a view number in hexadecimal value, with the same width
291 print_dwarf_vma would have printed it with the same num_bytes.
292 Print blanks for zero view, unless force is nonzero. */
295 print_dwarf_view (dwarf_vma value
, unsigned num_bytes
, int force
)
303 assert (value
== (unsigned long) value
);
305 printf ("v%0*lx ", len
- 1, (unsigned long) value
);
307 printf ("%*s", len
+ 1, "");
310 /* Read in a LEB128 encoded value starting at address DATA.
311 If SIGN is true, return a signed LEB128 value.
312 If LENGTH_RETURN is not NULL, return in it the number of bytes read.
313 If STATUS_RETURN is not NULL, return with bit 0 (LSB) set if the
314 terminating byte was not found and with bit 1 set if the value
315 overflows a dwarf_vma.
316 No bytes will be read at address END or beyond. */
319 read_leb128 (unsigned char *data
,
320 const unsigned char *const end
,
322 unsigned int *length_return
,
325 dwarf_vma result
= 0;
326 unsigned int num_read
= 0;
327 unsigned int shift
= 0;
332 unsigned char byte
= *data
++;
333 unsigned char lost
, mask
;
337 if (shift
< CHAR_BIT
* sizeof (result
))
339 result
|= ((dwarf_vma
) (byte
& 0x7f)) << shift
;
340 /* These bits overflowed. */
341 lost
= byte
^ (result
>> shift
);
342 /* And this is the mask of possible overflow bits. */
343 mask
= 0x7f ^ ((dwarf_vma
) 0x7f << shift
>> shift
);
351 if ((lost
& mask
) != (sign
&& (dwarf_signed_vma
) result
< 0 ? mask
: 0))
354 if ((byte
& 0x80) == 0)
357 if (sign
&& shift
< CHAR_BIT
* sizeof (result
) && (byte
& 0x40))
358 result
|= -((dwarf_vma
) 1 << shift
);
363 if (length_return
!= NULL
)
364 *length_return
= num_read
;
365 if (status_return
!= NULL
)
366 *status_return
= status
;
371 /* Read AMOUNT bytes from PTR and store them in VAL.
372 Checks to make sure that the read will not reach or pass END.
373 FUNC chooses whether the value read is unsigned or signed, and may
374 be either byte_get or byte_get_signed. If INC is true, PTR is
375 incremented after reading the value.
376 This macro cannot protect against PTR values derived from user input.
377 The C standard sections 6.5.6 and 6.5.8 say attempts to do so using
378 pointers is undefined behaviour. */
379 #define SAFE_BYTE_GET_INTERNAL(VAL, PTR, AMOUNT, END, FUNC, INC) \
382 size_t amount = (AMOUNT); \
383 if (sizeof (VAL) < amount) \
385 error (ngettext ("internal error: attempt to read %d byte " \
386 "of data in to %d sized variable", \
387 "internal error: attempt to read %d bytes " \
388 "of data in to %d sized variable", \
390 (int) amount, (int) sizeof (VAL)); \
391 amount = sizeof (VAL); \
393 assert ((PTR) <= (END)); \
394 size_t avail = (END) - (PTR); \
395 if (amount > avail) \
400 (VAL) = (FUNC) ((PTR), amount); \
406 #define SAFE_BYTE_GET(VAL, PTR, AMOUNT, END) \
407 SAFE_BYTE_GET_INTERNAL (VAL, PTR, AMOUNT, END, byte_get, false)
409 #define SAFE_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \
410 SAFE_BYTE_GET_INTERNAL (VAL, PTR, AMOUNT, END, byte_get, true)
412 #define SAFE_SIGNED_BYTE_GET(VAL, PTR, AMOUNT, END) \
413 SAFE_BYTE_GET_INTERNAL (VAL, PTR, AMOUNT, END, byte_get_signed, false)
415 #define SAFE_SIGNED_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \
416 SAFE_BYTE_GET_INTERNAL (VAL, PTR, AMOUNT, END, byte_get_signed, true)
418 typedef struct State_Machine_Registers
427 unsigned char op_index
;
428 unsigned char end_sequence
;
429 /* This variable hold the number of the last entry seen
430 in the File Table. */
431 unsigned int last_file_entry
;
434 static SMR state_machine_regs
;
437 reset_state_machine (int is_stmt
)
439 state_machine_regs
.address
= 0;
440 state_machine_regs
.view
= 0;
441 state_machine_regs
.op_index
= 0;
442 state_machine_regs
.file
= 1;
443 state_machine_regs
.line
= 1;
444 state_machine_regs
.column
= 0;
445 state_machine_regs
.is_stmt
= is_stmt
;
446 state_machine_regs
.basic_block
= 0;
447 state_machine_regs
.end_sequence
= 0;
448 state_machine_regs
.last_file_entry
= 0;
451 /* Handled an extend line op.
452 Returns the number of bytes read. */
455 process_extended_line_op (unsigned char * data
,
459 unsigned char op_code
;
460 size_t len
, header_len
;
462 unsigned char *orig_data
= data
;
465 READ_ULEB (len
, data
, end
);
466 header_len
= data
- orig_data
;
468 if (len
== 0 || data
>= end
|| len
> (size_t) (end
- data
))
470 warn (_("Badly formed extended line op encountered!\n"));
476 printf (_(" Extended opcode %d: "), op_code
);
480 case DW_LNE_end_sequence
:
481 printf (_("End of Sequence\n\n"));
482 reset_state_machine (is_stmt
);
485 case DW_LNE_set_address
:
486 /* PR 17512: file: 002-100480-0.004. */
489 warn (_("Length (%lu) of DW_LNE_set_address op is too long\n"),
490 (unsigned long) len
- 1);
494 SAFE_BYTE_GET (adr
, data
, len
- 1, end
);
495 printf (_("set Address to 0x%s\n"), dwarf_vmatoa ("x", adr
));
496 state_machine_regs
.address
= adr
;
497 state_machine_regs
.view
= 0;
498 state_machine_regs
.op_index
= 0;
501 case DW_LNE_define_file
:
502 printf (_("define new File Table entry\n"));
503 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
504 printf (" %d\t", ++state_machine_regs
.last_file_entry
);
510 l
= strnlen ((char *) data
, end
- data
);
514 READ_ULEB (val
, data
, end
);
515 printf ("%s\t", dwarf_vmatoa ("u", val
));
516 READ_ULEB (val
, data
, end
);
517 printf ("%s\t", dwarf_vmatoa ("u", val
));
518 READ_ULEB (val
, data
, end
);
519 printf ("%s\t", dwarf_vmatoa ("u", val
));
520 printf ("%.*s\n\n", (int) l
, name
);
523 if (((size_t) (data
- orig_data
) != len
+ header_len
) || data
>= end
)
524 warn (_("DW_LNE_define_file: Bad opcode length\n"));
527 case DW_LNE_set_discriminator
:
528 READ_ULEB (val
, data
, end
);
529 printf (_("set Discriminator to %s\n"), dwarf_vmatoa ("u", val
));
533 case DW_LNE_HP_negate_is_UV_update
:
534 printf ("DW_LNE_HP_negate_is_UV_update\n");
536 case DW_LNE_HP_push_context
:
537 printf ("DW_LNE_HP_push_context\n");
539 case DW_LNE_HP_pop_context
:
540 printf ("DW_LNE_HP_pop_context\n");
542 case DW_LNE_HP_set_file_line_column
:
543 printf ("DW_LNE_HP_set_file_line_column\n");
545 case DW_LNE_HP_set_routine_name
:
546 printf ("DW_LNE_HP_set_routine_name\n");
548 case DW_LNE_HP_set_sequence
:
549 printf ("DW_LNE_HP_set_sequence\n");
551 case DW_LNE_HP_negate_post_semantics
:
552 printf ("DW_LNE_HP_negate_post_semantics\n");
554 case DW_LNE_HP_negate_function_exit
:
555 printf ("DW_LNE_HP_negate_function_exit\n");
557 case DW_LNE_HP_negate_front_end_logical
:
558 printf ("DW_LNE_HP_negate_front_end_logical\n");
560 case DW_LNE_HP_define_proc
:
561 printf ("DW_LNE_HP_define_proc\n");
563 case DW_LNE_HP_source_file_correlation
:
565 unsigned char *edata
= data
+ len
- 1;
567 printf ("DW_LNE_HP_source_file_correlation\n");
573 READ_ULEB (opc
, data
, edata
);
577 case DW_LNE_HP_SFC_formfeed
:
578 printf (" DW_LNE_HP_SFC_formfeed\n");
580 case DW_LNE_HP_SFC_set_listing_line
:
581 READ_ULEB (val
, data
, edata
);
582 printf (" DW_LNE_HP_SFC_set_listing_line (%s)\n",
583 dwarf_vmatoa ("u", val
));
585 case DW_LNE_HP_SFC_associate
:
586 printf (" DW_LNE_HP_SFC_associate ");
587 READ_ULEB (val
, data
, edata
);
588 printf ("(%s", dwarf_vmatoa ("u", val
));
589 READ_ULEB (val
, data
, edata
);
590 printf (",%s", dwarf_vmatoa ("u", val
));
591 READ_ULEB (val
, data
, edata
);
592 printf (",%s)\n", dwarf_vmatoa ("u", val
));
595 printf (_(" UNKNOWN DW_LNE_HP_SFC opcode (%u)\n"), opc
);
605 unsigned int rlen
= len
- 1;
607 if (op_code
>= DW_LNE_lo_user
608 /* The test against DW_LNW_hi_user is redundant due to
609 the limited range of the unsigned char data type used
611 /*&& op_code <= DW_LNE_hi_user*/)
612 printf (_("user defined: "));
614 printf (_("UNKNOWN: "));
615 printf (_("length %d ["), rlen
);
617 printf (" %02x", *data
++);
623 return len
+ header_len
;
626 static const unsigned char *
627 fetch_indirect_string (dwarf_vma offset
)
629 struct dwarf_section
*section
= &debug_displays
[str
].section
;
630 const unsigned char * ret
;
632 if (section
->start
== NULL
)
633 return (const unsigned char *) _("<no .debug_str section>");
635 if (offset
>= section
->size
)
637 warn (_("DW_FORM_strp offset too big: 0x%s\n"),
638 dwarf_vmatoa ("x", offset
));
639 return (const unsigned char *) _("<offset is too big>");
642 ret
= section
->start
+ offset
;
643 /* Unfortunately we cannot rely upon the .debug_str section ending with a
644 NUL byte. Since our caller is expecting to receive a well formed C
645 string we test for the lack of a terminating byte here. */
646 if (strnlen ((const char *) ret
, section
->size
- offset
)
647 == section
->size
- offset
)
648 ret
= (const unsigned char *)
649 _("<no NUL byte at end of .debug_str section>");
654 static const unsigned char *
655 fetch_indirect_line_string (dwarf_vma offset
)
657 struct dwarf_section
*section
= &debug_displays
[line_str
].section
;
658 const unsigned char * ret
;
660 if (section
->start
== NULL
)
661 return (const unsigned char *) _("<no .debug_line_str section>");
663 if (offset
>= section
->size
)
665 warn (_("DW_FORM_line_strp offset too big: 0x%s\n"),
666 dwarf_vmatoa ("x", offset
));
667 return (const unsigned char *) _("<offset is too big>");
670 ret
= section
->start
+ offset
;
671 /* Unfortunately we cannot rely upon the .debug_line_str section ending
672 with a NUL byte. Since our caller is expecting to receive a well formed
673 C string we test for the lack of a terminating byte here. */
674 if (strnlen ((const char *) ret
, section
->size
- offset
)
675 == section
->size
- offset
)
676 ret
= (const unsigned char *)
677 _("<no NUL byte at end of .debug_line_str section>");
683 fetch_indexed_string (dwarf_vma idx
, struct cu_tu_set
*this_set
,
684 dwarf_vma offset_size
, bool dwo
)
686 enum dwarf_section_display_enum str_sec_idx
= dwo
? str_dwo
: str
;
687 enum dwarf_section_display_enum idx_sec_idx
= dwo
? str_index_dwo
: str_index
;
688 struct dwarf_section
*index_section
= &debug_displays
[idx_sec_idx
].section
;
689 struct dwarf_section
*str_section
= &debug_displays
[str_sec_idx
].section
;
690 dwarf_vma index_offset
;
691 dwarf_vma str_offset
;
693 unsigned char *curr
= index_section
->start
;
694 unsigned char *end
= curr
+ index_section
->size
;
697 if (index_section
->start
== NULL
)
698 return (dwo
? _("<no .debug_str_offsets.dwo section>")
699 : _("<no .debug_str_offsets section>"));
701 if (str_section
->start
== NULL
)
702 return (dwo
? _("<no .debug_str.dwo section>")
703 : _("<no .debug_str section>"));
705 /* FIXME: We should cache the length... */
706 SAFE_BYTE_GET_AND_INC (length
, curr
, 4, end
);
707 if (length
== 0xffffffff)
709 if (offset_size
!= 8)
710 warn (_("Expected offset size of 8 but given %s"), dwarf_vmatoa ("x", offset_size
));
711 SAFE_BYTE_GET_AND_INC (length
, curr
, 8, end
);
713 else if (offset_size
!= 4)
715 warn (_("Expected offset size of 4 but given %s"), dwarf_vmatoa ("x", offset_size
));
720 /* This is probably an old style .debug_str_offset section which
721 just contains offsets and no header (and the first offset is 0). */
722 curr
= index_section
->start
;
723 length
= index_section
->size
;
727 /* Skip the version and padding bytes.
728 We assume that they are correct. */
739 && this_set
->section_sizes
[DW_SECT_STR_OFFSETS
] < length
)
740 length
= this_set
->section_sizes
[DW_SECT_STR_OFFSETS
];
742 if (length
> (dwarf_vma
) (end
- curr
))
744 warn (_("index table size too large for section %s vs %s\n"),
745 dwarf_vmatoa ("x", length
),
746 dwarf_vmatoa ("x", index_section
->size
));
750 if (length
< offset_size
)
752 warn (_("index table size %s is too small\n"),
753 dwarf_vmatoa ("x", length
));
754 return _("<table too small>");
758 index_offset
= idx
* offset_size
;
760 if (this_set
!= NULL
)
761 index_offset
+= this_set
->section_offsets
[DW_SECT_STR_OFFSETS
];
763 if (index_offset
>= length
764 || length
- index_offset
< offset_size
)
766 warn (_("DW_FORM_GNU_str_index offset too big: 0x%s vs 0x%s\n"),
767 dwarf_vmatoa ("x", index_offset
),
768 dwarf_vmatoa ("x", length
));
769 return _("<index offset is too big>");
772 str_offset
= byte_get (curr
+ index_offset
, offset_size
);
773 str_offset
-= str_section
->address
;
774 if (str_offset
>= str_section
->size
)
776 warn (_("DW_FORM_GNU_str_index indirect offset too big: 0x%s\n"),
777 dwarf_vmatoa ("x", str_offset
));
778 return _("<indirect index offset is too big>");
781 ret
= (const char *) str_section
->start
+ str_offset
;
782 /* Unfortunately we cannot rely upon str_section ending with a NUL byte.
783 Since our caller is expecting to receive a well formed C string we test
784 for the lack of a terminating byte here. */
785 if (strnlen (ret
, str_section
->size
- str_offset
)
786 == str_section
->size
- str_offset
)
787 ret
= (const char *) _("<no NUL byte at end of section>");
793 fetch_indexed_value (dwarf_vma offset
, dwarf_vma bytes
)
795 struct dwarf_section
*section
= &debug_displays
[debug_addr
].section
;
797 if (section
->start
== NULL
)
798 return (_("<no .debug_addr section>"));
800 if (offset
+ bytes
> section
->size
)
802 warn (_("Offset into section %s too big: 0x%s\n"),
803 section
->name
, dwarf_vmatoa ("x", offset
));
804 return "<offset too big>";
807 return dwarf_vmatoa ("x", byte_get (section
->start
+ offset
, bytes
));
811 /* FIXME: There are better and more efficient ways to handle
812 these structures. For now though, I just want something that
813 is simple to implement. */
814 /* Records a single attribute in an abbrev. */
815 typedef struct abbrev_attr
817 unsigned long attribute
;
819 bfd_signed_vma implicit_const
;
820 struct abbrev_attr
* next
;
824 /* Records a single abbrev. */
825 typedef struct abbrev_entry
827 unsigned long number
;
830 struct abbrev_attr
* first_attr
;
831 struct abbrev_attr
* last_attr
;
832 struct abbrev_entry
* next
;
836 /* Records a set of abbreviations. */
837 typedef struct abbrev_list
839 abbrev_entry
* first_abbrev
;
840 abbrev_entry
* last_abbrev
;
841 dwarf_vma abbrev_base
;
842 dwarf_vma abbrev_offset
;
843 struct abbrev_list
* next
;
844 unsigned char * start_of_next_abbrevs
;
848 /* Records all the abbrevs found so far. */
849 static struct abbrev_list
* abbrev_lists
= NULL
;
851 typedef struct abbrev_map
858 /* Maps between CU offsets and abbrev sets. */
859 static abbrev_map
* cu_abbrev_map
= NULL
;
860 static unsigned long num_abbrev_map_entries
= 0;
861 static unsigned long next_free_abbrev_map_entry
= 0;
863 #define INITIAL_NUM_ABBREV_MAP_ENTRIES 8
864 #define ABBREV_MAP_ENTRIES_INCREMENT 8
867 record_abbrev_list_for_cu (dwarf_vma start
, dwarf_vma end
, abbrev_list
* list
)
869 if (cu_abbrev_map
== NULL
)
871 num_abbrev_map_entries
= INITIAL_NUM_ABBREV_MAP_ENTRIES
;
872 cu_abbrev_map
= xmalloc (num_abbrev_map_entries
* sizeof (* cu_abbrev_map
));
874 else if (next_free_abbrev_map_entry
== num_abbrev_map_entries
)
876 num_abbrev_map_entries
+= ABBREV_MAP_ENTRIES_INCREMENT
;
877 cu_abbrev_map
= xrealloc (cu_abbrev_map
, num_abbrev_map_entries
* sizeof (* cu_abbrev_map
));
880 cu_abbrev_map
[next_free_abbrev_map_entry
].start
= start
;
881 cu_abbrev_map
[next_free_abbrev_map_entry
].end
= end
;
882 cu_abbrev_map
[next_free_abbrev_map_entry
].list
= list
;
883 next_free_abbrev_map_entry
++;
887 free_all_abbrevs (void)
891 for (list
= abbrev_lists
; list
!= NULL
;)
893 abbrev_list
* next
= list
->next
;
894 abbrev_entry
* abbrv
;
896 for (abbrv
= list
->first_abbrev
; abbrv
!= NULL
;)
898 abbrev_entry
* next_abbrev
= abbrv
->next
;
901 for (attr
= abbrv
->first_attr
; attr
;)
903 abbrev_attr
*next_attr
= attr
->next
;
921 new_abbrev_list (dwarf_vma abbrev_base
, dwarf_vma abbrev_offset
)
923 abbrev_list
* list
= (abbrev_list
*) xcalloc (sizeof * list
, 1);
925 list
->abbrev_base
= abbrev_base
;
926 list
->abbrev_offset
= abbrev_offset
;
928 list
->next
= abbrev_lists
;
935 find_abbrev_list_by_abbrev_offset (dwarf_vma abbrev_base
,
936 dwarf_vma abbrev_offset
)
940 for (list
= abbrev_lists
; list
!= NULL
; list
= list
->next
)
941 if (list
->abbrev_base
== abbrev_base
942 && list
->abbrev_offset
== abbrev_offset
)
948 /* Find the abbreviation map for the CU that includes OFFSET.
949 OFFSET is an absolute offset from the start of the .debug_info section. */
950 /* FIXME: This function is going to slow down readelf & objdump.
951 Consider using a better algorithm to mitigate this effect. */
954 find_abbrev_map_by_offset (dwarf_vma offset
)
958 for (i
= 0; i
< next_free_abbrev_map_entry
; i
++)
959 if (cu_abbrev_map
[i
].start
<= offset
960 && cu_abbrev_map
[i
].end
> offset
)
961 return cu_abbrev_map
+ i
;
967 add_abbrev (unsigned long number
,
972 abbrev_entry
* entry
;
974 entry
= (abbrev_entry
*) xmalloc (sizeof (*entry
));
976 entry
->number
= number
;
978 entry
->children
= children
;
979 entry
->first_attr
= NULL
;
980 entry
->last_attr
= NULL
;
983 assert (list
!= NULL
);
985 if (list
->first_abbrev
== NULL
)
986 list
->first_abbrev
= entry
;
988 list
->last_abbrev
->next
= entry
;
990 list
->last_abbrev
= entry
;
994 add_abbrev_attr (unsigned long attribute
,
996 bfd_signed_vma implicit_const
,
1001 attr
= (abbrev_attr
*) xmalloc (sizeof (*attr
));
1003 attr
->attribute
= attribute
;
1005 attr
->implicit_const
= implicit_const
;
1008 assert (list
!= NULL
&& list
->last_abbrev
!= NULL
);
1010 if (list
->last_abbrev
->first_attr
== NULL
)
1011 list
->last_abbrev
->first_attr
= attr
;
1013 list
->last_abbrev
->last_attr
->next
= attr
;
1015 list
->last_abbrev
->last_attr
= attr
;
1018 /* Processes the (partial) contents of a .debug_abbrev section.
1019 Returns NULL if the end of the section was encountered.
1020 Returns the address after the last byte read if the end of
1021 an abbreviation set was found. */
1023 static unsigned char *
1024 process_abbrev_set (struct dwarf_section
*section
,
1025 dwarf_vma abbrev_base
,
1026 dwarf_vma abbrev_size
,
1027 dwarf_vma abbrev_offset
,
1030 if (abbrev_base
>= section
->size
1031 || abbrev_size
> section
->size
- abbrev_base
)
1033 /* PR 17531: file:4bcd9ce9. */
1034 warn (_("Debug info is corrupted, abbrev size (%lx) is larger than "
1035 "abbrev section size (%lx)\n"),
1036 (unsigned long) (abbrev_base
+ abbrev_size
),
1037 (unsigned long) section
->size
);
1040 if (abbrev_offset
>= abbrev_size
)
1042 warn (_("Debug info is corrupted, abbrev offset (%lx) is larger than "
1043 "abbrev section size (%lx)\n"),
1044 (unsigned long) abbrev_offset
,
1045 (unsigned long) abbrev_size
);
1049 unsigned char *start
= section
->start
+ abbrev_base
;
1050 unsigned char *end
= start
+ abbrev_size
;
1051 start
+= abbrev_offset
;
1054 unsigned long entry
;
1056 unsigned long attribute
;
1059 READ_ULEB (entry
, start
, end
);
1061 /* A single zero is supposed to end the set according
1062 to the standard. If there's more, then signal that to
1069 READ_ULEB (tag
, start
, end
);
1073 children
= *start
++;
1075 add_abbrev (entry
, tag
, children
, list
);
1080 /* Initialize it due to a false compiler warning. */
1081 bfd_signed_vma implicit_const
= -1;
1083 READ_ULEB (attribute
, start
, end
);
1087 READ_ULEB (form
, start
, end
);
1091 if (form
== DW_FORM_implicit_const
)
1093 READ_SLEB (implicit_const
, start
, end
);
1098 add_abbrev_attr (attribute
, form
, implicit_const
, list
);
1100 while (attribute
!= 0);
1103 /* Report the missing single zero which ends the section. */
1104 error (_(".debug_abbrev section not zero terminated\n"));
1110 get_TAG_name (unsigned long tag
)
1112 const char *name
= get_DW_TAG_name ((unsigned int) tag
);
1116 static char buffer
[100];
1118 if (tag
>= DW_TAG_lo_user
&& tag
<= DW_TAG_hi_user
)
1119 snprintf (buffer
, sizeof (buffer
), _("User TAG value: %#lx"), tag
);
1121 snprintf (buffer
, sizeof (buffer
), _("Unknown TAG value: %#lx"), tag
);
1129 get_FORM_name (unsigned long form
)
1134 return "DW_FORM value: 0";
1136 name
= get_DW_FORM_name (form
);
1139 static char buffer
[100];
1141 snprintf (buffer
, sizeof (buffer
), _("Unknown FORM value: %lx"), form
);
1149 get_IDX_name (unsigned long idx
)
1151 const char *name
= get_DW_IDX_name ((unsigned int) idx
);
1155 static char buffer
[100];
1157 snprintf (buffer
, sizeof (buffer
), _("Unknown IDX value: %lx"), idx
);
1164 static unsigned char *
1165 display_block (unsigned char *data
,
1167 const unsigned char * const end
, char delimiter
)
1171 printf (_("%c%s byte block: "), delimiter
, dwarf_vmatoa ("u", length
));
1173 return (unsigned char *) end
;
1175 maxlen
= (dwarf_vma
) (end
- data
);
1176 length
= length
> maxlen
? maxlen
: length
;
1179 printf ("%lx ", (unsigned long) byte_get (data
++, 1));
1185 decode_location_expression (unsigned char * data
,
1186 unsigned int pointer_size
,
1187 unsigned int offset_size
,
1190 dwarf_vma cu_offset
,
1191 struct dwarf_section
* section
)
1195 dwarf_signed_vma svalue
;
1196 unsigned char *end
= data
+ length
;
1197 int need_frame_base
= 0;
1206 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1207 printf ("DW_OP_addr: %s", dwarf_vmatoa ("x", uvalue
));
1210 printf ("DW_OP_deref");
1213 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1214 printf ("DW_OP_const1u: %lu", (unsigned long) uvalue
);
1217 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 1, end
);
1218 printf ("DW_OP_const1s: %ld", (long) svalue
);
1221 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
1222 printf ("DW_OP_const2u: %lu", (unsigned long) uvalue
);
1225 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1226 printf ("DW_OP_const2s: %ld", (long) svalue
);
1229 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1230 printf ("DW_OP_const4u: %lu", (unsigned long) uvalue
);
1233 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
1234 printf ("DW_OP_const4s: %ld", (long) svalue
);
1237 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1238 printf ("DW_OP_const8u: %lu ", (unsigned long) uvalue
);
1239 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1240 printf ("%lu", (unsigned long) uvalue
);
1243 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
1244 printf ("DW_OP_const8s: %ld ", (long) svalue
);
1245 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
1246 printf ("%ld", (long) svalue
);
1249 READ_ULEB (uvalue
, data
, end
);
1250 printf ("DW_OP_constu: %s", dwarf_vmatoa ("u", uvalue
));
1253 READ_SLEB (svalue
, data
, end
);
1254 printf ("DW_OP_consts: %s", dwarf_vmatoa ("d", svalue
));
1257 printf ("DW_OP_dup");
1260 printf ("DW_OP_drop");
1263 printf ("DW_OP_over");
1266 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1267 printf ("DW_OP_pick: %ld", (unsigned long) uvalue
);
1270 printf ("DW_OP_swap");
1273 printf ("DW_OP_rot");
1276 printf ("DW_OP_xderef");
1279 printf ("DW_OP_abs");
1282 printf ("DW_OP_and");
1285 printf ("DW_OP_div");
1288 printf ("DW_OP_minus");
1291 printf ("DW_OP_mod");
1294 printf ("DW_OP_mul");
1297 printf ("DW_OP_neg");
1300 printf ("DW_OP_not");
1303 printf ("DW_OP_or");
1306 printf ("DW_OP_plus");
1308 case DW_OP_plus_uconst
:
1309 READ_ULEB (uvalue
, data
, end
);
1310 printf ("DW_OP_plus_uconst: %s", dwarf_vmatoa ("u", uvalue
));
1313 printf ("DW_OP_shl");
1316 printf ("DW_OP_shr");
1319 printf ("DW_OP_shra");
1322 printf ("DW_OP_xor");
1325 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1326 printf ("DW_OP_bra: %ld", (long) svalue
);
1329 printf ("DW_OP_eq");
1332 printf ("DW_OP_ge");
1335 printf ("DW_OP_gt");
1338 printf ("DW_OP_le");
1341 printf ("DW_OP_lt");
1344 printf ("DW_OP_ne");
1347 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1348 printf ("DW_OP_skip: %ld", (long) svalue
);
1383 printf ("DW_OP_lit%d", op
- DW_OP_lit0
);
1418 printf ("DW_OP_reg%d (%s)", op
- DW_OP_reg0
,
1419 regname (op
- DW_OP_reg0
, 1));
1454 READ_SLEB (svalue
, data
, end
);
1455 printf ("DW_OP_breg%d (%s): %s", op
- DW_OP_breg0
,
1456 regname (op
- DW_OP_breg0
, 1), dwarf_vmatoa ("d", svalue
));
1460 READ_ULEB (uvalue
, data
, end
);
1461 printf ("DW_OP_regx: %s (%s)",
1462 dwarf_vmatoa ("u", uvalue
), regname (uvalue
, 1));
1465 need_frame_base
= 1;
1466 READ_SLEB (svalue
, data
, end
);
1467 printf ("DW_OP_fbreg: %s", dwarf_vmatoa ("d", svalue
));
1470 READ_ULEB (uvalue
, data
, end
);
1471 READ_SLEB (svalue
, data
, end
);
1472 printf ("DW_OP_bregx: %s (%s) %s",
1473 dwarf_vmatoa ("u", uvalue
), regname (uvalue
, 1),
1474 dwarf_vmatoa ("d", svalue
));
1477 READ_ULEB (uvalue
, data
, end
);
1478 printf ("DW_OP_piece: %s", dwarf_vmatoa ("u", uvalue
));
1480 case DW_OP_deref_size
:
1481 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1482 printf ("DW_OP_deref_size: %ld", (long) uvalue
);
1484 case DW_OP_xderef_size
:
1485 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1486 printf ("DW_OP_xderef_size: %ld", (long) uvalue
);
1489 printf ("DW_OP_nop");
1492 /* DWARF 3 extensions. */
1493 case DW_OP_push_object_address
:
1494 printf ("DW_OP_push_object_address");
1497 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1498 this ought to be an 8-byte wide computation. */
1499 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1500 printf ("DW_OP_call2: <0x%s>",
1501 dwarf_vmatoa ("x", svalue
+ cu_offset
));
1504 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1505 this ought to be an 8-byte wide computation. */
1506 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
1507 printf ("DW_OP_call4: <0x%s>",
1508 dwarf_vmatoa ("x", svalue
+ cu_offset
));
1510 case DW_OP_call_ref
:
1511 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1512 this ought to be an 8-byte wide computation. */
1513 if (dwarf_version
== -1)
1515 printf (_("(DW_OP_call_ref in frame info)"));
1516 /* No way to tell where the next op is, so just bail. */
1517 return need_frame_base
;
1519 if (dwarf_version
== 2)
1521 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1525 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1527 printf ("DW_OP_call_ref: <0x%s>", dwarf_vmatoa ("x", uvalue
));
1529 case DW_OP_form_tls_address
:
1530 printf ("DW_OP_form_tls_address");
1532 case DW_OP_call_frame_cfa
:
1533 printf ("DW_OP_call_frame_cfa");
1535 case DW_OP_bit_piece
:
1536 printf ("DW_OP_bit_piece: ");
1537 READ_ULEB (uvalue
, data
, end
);
1538 printf (_("size: %s "), dwarf_vmatoa ("u", uvalue
));
1539 READ_ULEB (uvalue
, data
, end
);
1540 printf (_("offset: %s "), dwarf_vmatoa ("u", uvalue
));
1543 /* DWARF 4 extensions. */
1544 case DW_OP_stack_value
:
1545 printf ("DW_OP_stack_value");
1548 case DW_OP_implicit_value
:
1549 printf ("DW_OP_implicit_value");
1550 READ_ULEB (uvalue
, data
, end
);
1551 data
= display_block (data
, uvalue
, end
, ' ');
1554 /* GNU extensions. */
1555 case DW_OP_GNU_push_tls_address
:
1556 printf (_("DW_OP_GNU_push_tls_address or DW_OP_HP_unknown"));
1558 case DW_OP_GNU_uninit
:
1559 printf ("DW_OP_GNU_uninit");
1560 /* FIXME: Is there data associated with this OP ? */
1562 case DW_OP_GNU_encoded_addr
:
1569 addr
= get_encoded_value (&data
, encoding
, section
, end
);
1571 printf ("DW_OP_GNU_encoded_addr: fmt:%02x addr:", encoding
);
1572 print_dwarf_vma (addr
, pointer_size
);
1575 case DW_OP_implicit_pointer
:
1576 case DW_OP_GNU_implicit_pointer
:
1577 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1578 this ought to be an 8-byte wide computation. */
1579 if (dwarf_version
== -1)
1581 printf (_("(%s in frame info)"),
1582 (op
== DW_OP_implicit_pointer
1583 ? "DW_OP_implicit_pointer"
1584 : "DW_OP_GNU_implicit_pointer"));
1585 /* No way to tell where the next op is, so just bail. */
1586 return need_frame_base
;
1588 if (dwarf_version
== 2)
1590 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1594 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1596 READ_SLEB (svalue
, data
, end
);
1597 printf ("%s: <0x%s> %s",
1598 (op
== DW_OP_implicit_pointer
1599 ? "DW_OP_implicit_pointer" : "DW_OP_GNU_implicit_pointer"),
1600 dwarf_vmatoa ("x", uvalue
),
1601 dwarf_vmatoa ("d", svalue
));
1603 case DW_OP_entry_value
:
1604 case DW_OP_GNU_entry_value
:
1605 READ_ULEB (uvalue
, data
, end
);
1606 /* PR 17531: file: 0cc9cd00. */
1607 if (uvalue
> (dwarf_vma
) (end
- data
))
1608 uvalue
= end
- data
;
1609 printf ("%s: (", (op
== DW_OP_entry_value
? "DW_OP_entry_value"
1610 : "DW_OP_GNU_entry_value"));
1611 if (decode_location_expression (data
, pointer_size
, offset_size
,
1612 dwarf_version
, uvalue
,
1613 cu_offset
, section
))
1614 need_frame_base
= 1;
1618 case DW_OP_const_type
:
1619 case DW_OP_GNU_const_type
:
1620 READ_ULEB (uvalue
, data
, end
);
1621 printf ("%s: <0x%s> ",
1622 (op
== DW_OP_const_type
? "DW_OP_const_type"
1623 : "DW_OP_GNU_const_type"),
1624 dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1625 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1626 data
= display_block (data
, uvalue
, end
, ' ');
1628 case DW_OP_regval_type
:
1629 case DW_OP_GNU_regval_type
:
1630 READ_ULEB (uvalue
, data
, end
);
1631 printf ("%s: %s (%s)",
1632 (op
== DW_OP_regval_type
? "DW_OP_regval_type"
1633 : "DW_OP_GNU_regval_type"),
1634 dwarf_vmatoa ("u", uvalue
), regname (uvalue
, 1));
1635 READ_ULEB (uvalue
, data
, end
);
1636 printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1638 case DW_OP_deref_type
:
1639 case DW_OP_GNU_deref_type
:
1640 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1642 (op
== DW_OP_deref_type
? "DW_OP_deref_type"
1643 : "DW_OP_GNU_deref_type"),
1645 READ_ULEB (uvalue
, data
, end
);
1646 printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1649 case DW_OP_GNU_convert
:
1650 READ_ULEB (uvalue
, data
, end
);
1651 printf ("%s <0x%s>",
1652 (op
== DW_OP_convert
? "DW_OP_convert" : "DW_OP_GNU_convert"),
1653 dwarf_vmatoa ("x", uvalue
? cu_offset
+ uvalue
: 0));
1655 case DW_OP_reinterpret
:
1656 case DW_OP_GNU_reinterpret
:
1657 READ_ULEB (uvalue
, data
, end
);
1658 printf ("%s <0x%s>",
1659 (op
== DW_OP_reinterpret
? "DW_OP_reinterpret"
1660 : "DW_OP_GNU_reinterpret"),
1661 dwarf_vmatoa ("x", uvalue
? cu_offset
+ uvalue
: 0));
1663 case DW_OP_GNU_parameter_ref
:
1664 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1665 printf ("DW_OP_GNU_parameter_ref: <0x%s>",
1666 dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1668 case DW_OP_GNU_addr_index
:
1669 READ_ULEB (uvalue
, data
, end
);
1670 printf ("DW_OP_GNU_addr_index <0x%s>", dwarf_vmatoa ("x", uvalue
));
1672 case DW_OP_GNU_const_index
:
1673 READ_ULEB (uvalue
, data
, end
);
1674 printf ("DW_OP_GNU_const_index <0x%s>", dwarf_vmatoa ("x", uvalue
));
1676 case DW_OP_GNU_variable_value
:
1677 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1678 this ought to be an 8-byte wide computation. */
1679 if (dwarf_version
== -1)
1681 printf (_("(DW_OP_GNU_variable_value in frame info)"));
1682 /* No way to tell where the next op is, so just bail. */
1683 return need_frame_base
;
1685 if (dwarf_version
== 2)
1687 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1691 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1693 printf ("DW_OP_GNU_variable_value: <0x%s>", dwarf_vmatoa ("x", uvalue
));
1696 /* HP extensions. */
1697 case DW_OP_HP_is_value
:
1698 printf ("DW_OP_HP_is_value");
1699 /* FIXME: Is there data associated with this OP ? */
1701 case DW_OP_HP_fltconst4
:
1702 printf ("DW_OP_HP_fltconst4");
1703 /* FIXME: Is there data associated with this OP ? */
1705 case DW_OP_HP_fltconst8
:
1706 printf ("DW_OP_HP_fltconst8");
1707 /* FIXME: Is there data associated with this OP ? */
1709 case DW_OP_HP_mod_range
:
1710 printf ("DW_OP_HP_mod_range");
1711 /* FIXME: Is there data associated with this OP ? */
1713 case DW_OP_HP_unmod_range
:
1714 printf ("DW_OP_HP_unmod_range");
1715 /* FIXME: Is there data associated with this OP ? */
1718 printf ("DW_OP_HP_tls");
1719 /* FIXME: Is there data associated with this OP ? */
1722 /* PGI (STMicroelectronics) extensions. */
1723 case DW_OP_PGI_omp_thread_num
:
1724 /* Pushes the thread number for the current thread as it would be
1725 returned by the standard OpenMP library function:
1726 omp_get_thread_num(). The "current thread" is the thread for
1727 which the expression is being evaluated. */
1728 printf ("DW_OP_PGI_omp_thread_num");
1732 if (op
>= DW_OP_lo_user
1733 && op
<= DW_OP_hi_user
)
1734 printf (_("(User defined location op 0x%x)"), op
);
1736 printf (_("(Unknown location op 0x%x)"), op
);
1737 /* No way to tell where the next op is, so just bail. */
1738 return need_frame_base
;
1741 /* Separate the ops. */
1746 return need_frame_base
;
1749 /* Find the CU or TU set corresponding to the given CU_OFFSET.
1750 This is used for DWARF package files. */
1752 static struct cu_tu_set
*
1753 find_cu_tu_set_v2 (dwarf_vma cu_offset
, int do_types
)
1755 struct cu_tu_set
*p
;
1757 unsigned int dw_sect
;
1763 dw_sect
= DW_SECT_TYPES
;
1769 dw_sect
= DW_SECT_INFO
;
1773 if (p
->section_offsets
[dw_sect
] == cu_offset
)
1782 fetch_alt_indirect_string (dwarf_vma offset
)
1786 if (! do_follow_links
)
1789 if (first_separate_info
== NULL
)
1790 return _("<no links available>");
1792 for (i
= first_separate_info
; i
!= NULL
; i
= i
->next
)
1794 struct dwarf_section
* section
;
1797 if (! load_debug_section (separate_debug_str
, i
->handle
))
1800 section
= &debug_displays
[separate_debug_str
].section
;
1802 if (section
->start
== NULL
)
1805 if (offset
>= section
->size
)
1808 ret
= (const char *) (section
->start
+ offset
);
1809 /* Unfortunately we cannot rely upon the .debug_str section ending with a
1810 NUL byte. Since our caller is expecting to receive a well formed C
1811 string we test for the lack of a terminating byte here. */
1812 if (strnlen ((const char *) ret
, section
->size
- offset
)
1813 == section
->size
- offset
)
1814 return _("<no NUL byte at end of alt .debug_str section>");
1819 warn (_("DW_FORM_GNU_strp_alt offset (%s) too big or no string sections available\n"),
1820 dwarf_vmatoa ("x", offset
));
1821 return _("<offset is too big>");
1825 get_AT_name (unsigned long attribute
)
1830 return "DW_AT value: 0";
1832 /* One value is shared by the MIPS and HP extensions: */
1833 if (attribute
== DW_AT_MIPS_fde
)
1834 return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable";
1836 name
= get_DW_AT_name (attribute
);
1840 static char buffer
[100];
1842 snprintf (buffer
, sizeof (buffer
), _("Unknown AT value: %lx"),
1851 add_dwo_info (const char * value
, dwarf_vma cu_offset
, dwo_type type
)
1853 dwo_info
* dwinfo
= xmalloc (sizeof * dwinfo
);
1855 dwinfo
->type
= type
;
1856 dwinfo
->value
= value
;
1857 dwinfo
->cu_offset
= cu_offset
;
1858 dwinfo
->next
= first_dwo_info
;
1859 first_dwo_info
= dwinfo
;
1863 add_dwo_name (const char * name
, dwarf_vma cu_offset
)
1865 add_dwo_info (name
, cu_offset
, DWO_NAME
);
1869 add_dwo_dir (const char * dir
, dwarf_vma cu_offset
)
1871 add_dwo_info (dir
, cu_offset
, DWO_DIR
);
1875 add_dwo_id (const char * id
, dwarf_vma cu_offset
)
1877 add_dwo_info (id
, cu_offset
, DWO_ID
);
1881 free_dwo_info (void)
1886 for (dwinfo
= first_dwo_info
; dwinfo
!= NULL
; dwinfo
= next
)
1888 next
= dwinfo
->next
;
1891 first_dwo_info
= NULL
;
1894 /* Ensure that START + UVALUE is less than END.
1895 Return an adjusted UVALUE if necessary to ensure this relationship. */
1897 static inline dwarf_vma
1898 check_uvalue (const unsigned char * start
,
1900 const unsigned char * end
)
1902 dwarf_vma max_uvalue
= end
- start
;
1904 /* See PR 17512: file: 008-103549-0.001:0.1.
1905 and PR 24829 for examples of where these tests are triggered. */
1906 if (uvalue
> max_uvalue
)
1908 warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue
);
1909 uvalue
= max_uvalue
;
1915 static unsigned char *
1916 skip_attr_bytes (unsigned long form
,
1917 unsigned char *data
,
1919 dwarf_vma pointer_size
,
1920 dwarf_vma offset_size
,
1922 dwarf_vma
*value_return
)
1924 dwarf_signed_vma svalue
;
1925 dwarf_vma uvalue
= 0;
1932 case DW_FORM_ref_addr
:
1933 if (dwarf_version
== 2)
1934 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1935 else if (dwarf_version
> 2)
1936 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1942 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1946 case DW_FORM_line_strp
:
1947 case DW_FORM_sec_offset
:
1948 case DW_FORM_GNU_ref_alt
:
1949 case DW_FORM_GNU_strp_alt
:
1950 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1953 case DW_FORM_flag_present
:
1961 case DW_FORM_addrx1
:
1962 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1966 case DW_FORM_addrx3
:
1967 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 3, end
);
1973 case DW_FORM_addrx2
:
1974 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
1980 case DW_FORM_addrx4
:
1981 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1985 READ_SLEB (svalue
, data
, end
);
1989 case DW_FORM_ref_udata
:
1991 case DW_FORM_GNU_str_index
:
1993 case DW_FORM_GNU_addr_index
:
1995 READ_ULEB (uvalue
, data
, end
);
1999 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 8, end
);
2003 case DW_FORM_ref_sig8
:
2007 case DW_FORM_data16
:
2011 case DW_FORM_string
:
2012 inc
= strnlen ((char *) data
, end
- data
) + 1;
2016 case DW_FORM_exprloc
:
2017 READ_ULEB (uvalue
, data
, end
);
2021 case DW_FORM_block1
:
2022 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
2026 case DW_FORM_block2
:
2027 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
2031 case DW_FORM_block4
:
2032 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
2036 case DW_FORM_indirect
:
2037 READ_ULEB (form
, data
, end
);
2038 if (form
== DW_FORM_implicit_const
)
2039 SKIP_ULEB (data
, end
);
2040 return skip_attr_bytes (form
, data
, end
, pointer_size
, offset_size
,
2041 dwarf_version
, value_return
);
2047 * value_return
= uvalue
;
2048 if (inc
<= (dwarf_vma
) (end
- data
))
2055 /* Given form FORM with value UVALUE, locate and return the abbreviation
2056 associated with it. */
2058 static abbrev_entry
*
2059 get_type_abbrev_from_form (unsigned long form
,
2060 unsigned long uvalue
,
2061 dwarf_vma cu_offset
,
2062 const struct dwarf_section
* section
,
2063 unsigned long * abbrev_num_return
,
2064 unsigned char ** data_return
,
2065 unsigned long * cu_offset_return
)
2067 unsigned long abbrev_number
;
2069 abbrev_entry
* entry
;
2070 unsigned char * data
;
2072 if (abbrev_num_return
!= NULL
)
2073 * abbrev_num_return
= 0;
2074 if (data_return
!= NULL
)
2075 * data_return
= NULL
;
2079 case DW_FORM_GNU_ref_alt
:
2080 case DW_FORM_ref_sig8
:
2081 /* FIXME: We are unable to handle this form at the moment. */
2084 case DW_FORM_ref_addr
:
2085 if (uvalue
>= section
->size
)
2087 warn (_("Unable to resolve ref_addr form: uvalue %lx > section size %lx (%s)\n"),
2088 uvalue
, (long) section
->size
, section
->name
);
2093 case DW_FORM_ref_sup4
:
2094 case DW_FORM_ref_sup8
:
2101 case DW_FORM_ref_udata
:
2102 if (uvalue
+ cu_offset
> section
->size
)
2104 warn (_("Unable to resolve ref form: uvalue %lx + cu_offset %lx > section size %lx\n"),
2105 uvalue
, (long) cu_offset
, (long) section
->size
);
2108 uvalue
+= cu_offset
;
2111 /* FIXME: Are there other DW_FORMs that can be used by types ? */
2114 warn (_("Unexpected form %lx encountered whilst finding abbreviation for type\n"), form
);
2118 data
= (unsigned char *) section
->start
+ uvalue
;
2119 map
= find_abbrev_map_by_offset (uvalue
);
2123 warn (_("Unable to find abbreviations for CU offset %#lx\n"), uvalue
);
2126 if (map
->list
== NULL
)
2128 warn (_("Empty abbreviation list encountered for CU offset %lx\n"), uvalue
);
2132 if (cu_offset_return
!= NULL
)
2134 if (form
== DW_FORM_ref_addr
)
2135 * cu_offset_return
= map
->start
;
2137 * cu_offset_return
= cu_offset
;
2140 READ_ULEB (abbrev_number
, data
, section
->start
+ section
->size
);
2142 for (entry
= map
->list
->first_abbrev
; entry
!= NULL
; entry
= entry
->next
)
2143 if (entry
->number
== abbrev_number
)
2146 if (abbrev_num_return
!= NULL
)
2147 * abbrev_num_return
= abbrev_number
;
2149 if (data_return
!= NULL
)
2150 * data_return
= data
;
2153 warn (_("Unable to find entry for abbreviation %lu\n"), abbrev_number
);
2158 /* Return IS_SIGNED set to TRUE if the type using abbreviation ENTRY
2159 can be determined to be a signed type. The data for ENTRY can be
2160 found starting at DATA. */
2163 get_type_signedness (abbrev_entry
*entry
,
2164 const struct dwarf_section
*section
,
2165 unsigned char *data
,
2167 dwarf_vma cu_offset
,
2168 dwarf_vma pointer_size
,
2169 dwarf_vma offset_size
,
2172 unsigned int nesting
)
2176 * is_signed
= false;
2178 #define MAX_NESTING 20
2179 if (nesting
> MAX_NESTING
)
2181 /* FIXME: Warn - or is this expected ?
2182 NB/ We need to avoid infinite recursion. */
2186 for (attr
= entry
->first_attr
;
2187 attr
!= NULL
&& attr
->attribute
;
2190 unsigned char * orig_data
= data
;
2191 dwarf_vma uvalue
= 0;
2193 data
= skip_attr_bytes (attr
->form
, data
, end
, pointer_size
,
2194 offset_size
, dwarf_version
, & uvalue
);
2198 switch (attr
->attribute
)
2200 case DW_AT_linkage_name
:
2204 if (attr
->form
== DW_FORM_strp
)
2205 printf (", %s", fetch_indirect_string (uvalue
));
2206 else if (attr
->form
== DW_FORM_string
)
2207 printf (", %s", orig_data
);
2214 abbrev_entry
* type_abbrev
;
2215 unsigned char * type_data
;
2216 unsigned long type_cu_offset
;
2218 type_abbrev
= get_type_abbrev_from_form (attr
->form
,
2222 NULL
/* abbrev num return */,
2225 if (type_abbrev
== NULL
)
2228 get_type_signedness (type_abbrev
, section
, type_data
, end
, type_cu_offset
,
2229 pointer_size
, offset_size
, dwarf_version
,
2230 is_signed
, nesting
+ 1);
2234 case DW_AT_encoding
:
2235 /* Determine signness. */
2238 case DW_ATE_address
:
2239 /* FIXME - some architectures have signed addresses. */
2240 case DW_ATE_boolean
:
2241 case DW_ATE_unsigned
:
2242 case DW_ATE_unsigned_char
:
2243 case DW_ATE_unsigned_fixed
:
2244 * is_signed
= false;
2248 case DW_ATE_complex_float
:
2251 case DW_ATE_signed_char
:
2252 case DW_ATE_imaginary_float
:
2253 case DW_ATE_decimal_float
:
2254 case DW_ATE_signed_fixed
:
2264 read_and_print_leb128 (unsigned char *data
,
2265 unsigned int *bytes_read
,
2266 unsigned const char *end
,
2270 dwarf_vma val
= read_leb128 (data
, end
, is_signed
, bytes_read
, &status
);
2272 report_leb_status (status
, __FILE__
, __LINE__
);
2274 printf ("%s", dwarf_vmatoa (is_signed
? "d" : "u", val
));
2278 display_discr_list (unsigned long form
,
2280 unsigned char * data
,
2281 unsigned const char * end
,
2286 printf ("[default]");
2293 case DW_FORM_block1
:
2294 case DW_FORM_block2
:
2295 case DW_FORM_block4
:
2296 /* Move data pointer back to the start of the byte array. */
2300 printf ("<corrupt>\n");
2301 warn (_("corrupt discr_list - not using a block form\n"));
2307 printf ("<corrupt>\n");
2308 warn (_("corrupt discr_list - block not long enough\n"));
2313 (level
> 0 && level
<= MAX_CU_NESTING
)
2314 ? level_type_signed
[level
- 1] : false;
2319 unsigned char discriminant
;
2320 unsigned int bytes_read
;
2322 SAFE_BYTE_GET_AND_INC (discriminant
, data
, 1, end
);
2325 assert (uvalue
> 0);
2326 switch (discriminant
)
2330 read_and_print_leb128 (data
, & bytes_read
, end
, is_signed
);
2331 assert (bytes_read
<= uvalue
&& bytes_read
> 0);
2332 uvalue
-= bytes_read
;
2338 read_and_print_leb128 (data
, & bytes_read
, end
, is_signed
);
2339 assert (bytes_read
<= uvalue
&& bytes_read
> 0);
2340 uvalue
-= bytes_read
;
2344 read_and_print_leb128 (data
, & bytes_read
, end
, is_signed
);
2345 assert (bytes_read
<= uvalue
&& bytes_read
> 0);
2346 uvalue
-= bytes_read
;
2351 printf ("<corrupt>\n");
2352 warn (_("corrupt discr_list - unrecognized discriminant byte %#x\n"),
2362 printf (")(signed)");
2364 printf (")(unsigned)");
2367 static unsigned char *
2368 read_and_display_attr_value (unsigned long attribute
,
2370 dwarf_signed_vma implicit_const
,
2371 unsigned char * start
,
2372 unsigned char * data
,
2373 unsigned char * end
,
2374 dwarf_vma cu_offset
,
2375 dwarf_vma pointer_size
,
2376 dwarf_vma offset_size
,
2378 debug_info
* debug_info_p
,
2380 struct dwarf_section
* section
,
2381 struct cu_tu_set
* this_set
,
2385 dwarf_signed_vma svalue
;
2386 dwarf_vma uvalue
= 0;
2387 dwarf_vma uvalue_hi
= 0;
2388 unsigned char *block_start
= NULL
;
2389 unsigned char *orig_data
= data
;
2391 if (data
> end
|| (data
== end
&& form
!= DW_FORM_flag_present
))
2393 warn (_("Corrupt attribute\n"));
2397 if (do_wide
&& ! do_loc
)
2399 /* PR 26847: Display the name of the form. */
2400 const char * name
= get_FORM_name (form
);
2402 /* For convenience we skip the DW_FORM_ prefix to the name. */
2404 name
+= 8; /* strlen ("DW_FORM_") */
2405 printf ("%c(%s)", delimiter
, name
);
2413 case DW_FORM_ref_addr
:
2414 if (dwarf_version
== 2)
2415 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
2416 else if (dwarf_version
> 2)
2417 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
2419 error (_("Internal error: DW_FORM_ref_addr is not supported in DWARF version 1.\n"));
2423 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
2426 case DW_FORM_strp_sup
:
2428 case DW_FORM_line_strp
:
2429 case DW_FORM_sec_offset
:
2430 case DW_FORM_GNU_ref_alt
:
2431 case DW_FORM_GNU_strp_alt
:
2432 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
2435 case DW_FORM_flag_present
:
2443 case DW_FORM_addrx1
:
2444 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
2450 case DW_FORM_addrx2
:
2451 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
2455 case DW_FORM_addrx3
:
2456 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 3, end
);
2459 case DW_FORM_ref_sup4
:
2463 case DW_FORM_addrx4
:
2464 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
2467 case DW_FORM_ref_sup8
:
2470 case DW_FORM_ref_sig8
:
2471 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 8, end
);
2474 case DW_FORM_data16
:
2475 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 8, end
);
2476 SAFE_BYTE_GET_AND_INC (uvalue_hi
, data
, 8, end
);
2477 if (byte_get
!= byte_get_little_endian
)
2479 dwarf_vma utmp
= uvalue
;
2486 READ_SLEB (svalue
, data
, end
);
2490 case DW_FORM_GNU_str_index
:
2492 case DW_FORM_ref_udata
:
2494 case DW_FORM_GNU_addr_index
:
2496 READ_ULEB (uvalue
, data
, end
);
2499 case DW_FORM_indirect
:
2500 READ_ULEB (form
, data
, end
);
2502 printf ("%c%s", delimiter
, get_FORM_name (form
));
2503 if (form
== DW_FORM_implicit_const
)
2504 READ_SLEB (implicit_const
, data
, end
);
2505 return read_and_display_attr_value (attribute
, form
, implicit_const
,
2507 cu_offset
, pointer_size
,
2508 offset_size
, dwarf_version
,
2509 debug_info_p
, do_loc
,
2510 section
, this_set
, delimiter
, level
);
2515 case DW_FORM_ref_addr
:
2517 printf ("%c<0x%s>", delimiter
, dwarf_vmatoa ("x", uvalue
));
2520 case DW_FORM_GNU_ref_alt
:
2524 /* We have already printed the form name. */
2525 printf ("%c<0x%s>", delimiter
, dwarf_vmatoa ("x", uvalue
));
2527 printf ("%c<alt 0x%s>", delimiter
, dwarf_vmatoa ("x", uvalue
));
2529 /* FIXME: Follow the reference... */
2535 case DW_FORM_ref_sup4
:
2536 case DW_FORM_ref_udata
:
2538 printf ("%c<0x%s>", delimiter
, dwarf_vmatoa ("x", uvalue
+ cu_offset
));
2543 case DW_FORM_sec_offset
:
2545 printf ("%c0x%s", delimiter
, dwarf_vmatoa ("x", uvalue
));
2548 case DW_FORM_flag_present
:
2555 printf ("%c%s", delimiter
, dwarf_vmatoa ("d", uvalue
));
2558 case DW_FORM_implicit_const
:
2560 printf ("%c%s", delimiter
, dwarf_vmatoa ("d", implicit_const
));
2563 case DW_FORM_ref_sup8
:
2568 dwarf_vma utmp
= uvalue
;
2569 if (form
== DW_FORM_ref8
)
2571 printf ("%c0x%s", delimiter
, dwarf_vmatoa ("x", utmp
));
2575 case DW_FORM_data16
:
2578 uvalue_hi
== 0 ? "" : dwarf_vmatoa ("x", uvalue_hi
),
2579 dwarf_vmatoa_1 ("x", uvalue
, uvalue_hi
== 0 ? 0 : 8));
2582 case DW_FORM_string
:
2584 printf ("%c%.*s", delimiter
, (int) (end
- data
), data
);
2585 data
+= strnlen ((char *) data
, end
- data
);
2591 case DW_FORM_exprloc
:
2592 READ_ULEB (uvalue
, data
, end
);
2595 if (block_start
>= end
)
2597 warn (_("Block ends prematurely\n"));
2602 uvalue
= check_uvalue (block_start
, uvalue
, end
);
2605 data
= block_start
+ uvalue
;
2607 data
= display_block (block_start
, uvalue
, end
, delimiter
);
2610 case DW_FORM_block1
:
2611 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
2614 case DW_FORM_block2
:
2615 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
2618 case DW_FORM_block4
:
2619 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
2626 /* We have already displayed the form name. */
2627 printf (_("%c(offset: 0x%s): %s"), delimiter
,
2628 dwarf_vmatoa ("x", uvalue
),
2629 fetch_indirect_string (uvalue
));
2631 printf (_("%c(indirect string, offset: 0x%s): %s"), delimiter
,
2632 dwarf_vmatoa ("x", uvalue
),
2633 fetch_indirect_string (uvalue
));
2637 case DW_FORM_line_strp
:
2641 /* We have already displayed the form name. */
2642 printf (_("%c(offset: 0x%s): %s"), delimiter
,
2643 dwarf_vmatoa ("x", uvalue
),
2644 fetch_indirect_line_string (uvalue
));
2646 printf (_("%c(indirect line string, offset: 0x%s): %s"), delimiter
,
2647 dwarf_vmatoa ("x", uvalue
),
2648 fetch_indirect_line_string (uvalue
));
2652 case DW_FORM_GNU_str_index
:
2660 const char *suffix
= strrchr (section
->name
, '.');
2661 bool dwo
= suffix
&& strcmp (suffix
, ".dwo") == 0;
2664 /* We have already displayed the form name. */
2665 printf (_("%c(offset: 0x%s): %s"), delimiter
,
2666 dwarf_vmatoa ("x", uvalue
),
2667 fetch_indexed_string (uvalue
, this_set
, offset_size
, dwo
));
2669 printf (_("%c(indexed string: 0x%s): %s"), delimiter
,
2670 dwarf_vmatoa ("x", uvalue
),
2671 fetch_indexed_string (uvalue
, this_set
, offset_size
, dwo
));
2675 case DW_FORM_GNU_strp_alt
:
2679 /* We have already displayed the form name. */
2680 printf (_("%c(offset: 0x%s) %s"), delimiter
,
2681 dwarf_vmatoa ("x", uvalue
),
2682 fetch_alt_indirect_string (uvalue
));
2684 printf (_("%c(alt indirect string, offset: 0x%s) %s"), delimiter
,
2685 dwarf_vmatoa ("x", uvalue
),
2686 fetch_alt_indirect_string (uvalue
));
2690 case DW_FORM_indirect
:
2691 /* Handled above. */
2694 case DW_FORM_ref_sig8
:
2696 printf ("%c%s: 0x%s", delimiter
, do_wide
? "" : "signature",
2697 dwarf_vmatoa ("x", uvalue
));
2700 case DW_FORM_GNU_addr_index
:
2702 case DW_FORM_addrx1
:
2703 case DW_FORM_addrx2
:
2704 case DW_FORM_addrx3
:
2705 case DW_FORM_addrx4
:
2711 if (debug_info_p
== NULL
)
2713 else if (debug_info_p
->addr_base
== DEBUG_INFO_UNAVAILABLE
)
2716 base
= debug_info_p
->addr_base
;
2718 offset
= base
+ uvalue
* pointer_size
;
2721 /* We have already displayed the form name. */
2722 printf (_("%c(index: 0x%s): %s"), delimiter
,
2723 dwarf_vmatoa ("x", uvalue
),
2724 fetch_indexed_value (offset
, pointer_size
));
2726 printf (_("%c(addr_index: 0x%s): %s"), delimiter
,
2727 dwarf_vmatoa ("x", uvalue
),
2728 fetch_indexed_value (offset
, pointer_size
));
2732 case DW_FORM_strp_sup
:
2734 printf ("%c<0x%s>", delimiter
, dwarf_vmatoa ("x", uvalue
+ cu_offset
));
2738 warn (_("Unrecognized form: 0x%lx\n"), form
);
2742 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
2743 && num_debug_info_entries
== 0
2744 && debug_info_p
!= NULL
)
2748 case DW_AT_frame_base
:
2749 have_frame_base
= 1;
2751 case DW_AT_location
:
2752 case DW_AT_GNU_locviews
:
2753 case DW_AT_string_length
:
2754 case DW_AT_return_addr
:
2755 case DW_AT_data_member_location
:
2756 case DW_AT_vtable_elem_location
:
2758 case DW_AT_static_link
:
2759 case DW_AT_use_location
:
2760 case DW_AT_call_value
:
2761 case DW_AT_GNU_call_site_value
:
2762 case DW_AT_call_data_value
:
2763 case DW_AT_GNU_call_site_data_value
:
2764 case DW_AT_call_target
:
2765 case DW_AT_GNU_call_site_target
:
2766 case DW_AT_call_target_clobbered
:
2767 case DW_AT_GNU_call_site_target_clobbered
:
2768 if ((dwarf_version
< 4
2769 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
2770 || form
== DW_FORM_sec_offset
)
2772 /* Process location list. */
2773 unsigned int lmax
= debug_info_p
->max_loc_offsets
;
2774 unsigned int num
= debug_info_p
->num_loc_offsets
;
2776 if (lmax
== 0 || num
>= lmax
)
2779 debug_info_p
->loc_offsets
= (dwarf_vma
*)
2780 xcrealloc (debug_info_p
->loc_offsets
,
2781 lmax
, sizeof (*debug_info_p
->loc_offsets
));
2782 debug_info_p
->loc_views
= (dwarf_vma
*)
2783 xcrealloc (debug_info_p
->loc_views
,
2784 lmax
, sizeof (*debug_info_p
->loc_views
));
2785 debug_info_p
->have_frame_base
= (int *)
2786 xcrealloc (debug_info_p
->have_frame_base
,
2787 lmax
, sizeof (*debug_info_p
->have_frame_base
));
2788 debug_info_p
->max_loc_offsets
= lmax
;
2790 if (this_set
!= NULL
)
2791 uvalue
+= this_set
->section_offsets
[DW_SECT_LOC
];
2792 debug_info_p
->have_frame_base
[num
] = have_frame_base
;
2793 if (attribute
!= DW_AT_GNU_locviews
)
2795 /* Corrupt DWARF info can produce more offsets than views.
2796 See PR 23062 for an example. */
2797 if (debug_info_p
->num_loc_offsets
2798 > debug_info_p
->num_loc_views
)
2799 warn (_("More location offset attributes than DW_AT_GNU_locview attributes\n"));
2802 debug_info_p
->loc_offsets
[num
] = uvalue
;
2803 debug_info_p
->num_loc_offsets
++;
2808 assert (debug_info_p
->num_loc_views
<= num
);
2809 num
= debug_info_p
->num_loc_views
;
2810 if (num
> debug_info_p
->num_loc_offsets
)
2811 warn (_("More DW_AT_GNU_locview attributes than location offset attributes\n"));
2814 debug_info_p
->loc_views
[num
] = uvalue
;
2815 debug_info_p
->num_loc_views
++;
2822 if (need_base_address
)
2823 debug_info_p
->base_address
= uvalue
;
2826 case DW_AT_GNU_addr_base
:
2827 case DW_AT_addr_base
:
2828 debug_info_p
->addr_base
= uvalue
;
2831 case DW_AT_GNU_ranges_base
:
2832 debug_info_p
->ranges_base
= uvalue
;
2836 if ((dwarf_version
< 4
2837 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
2838 || form
== DW_FORM_sec_offset
)
2840 /* Process range list. */
2841 unsigned int lmax
= debug_info_p
->max_range_lists
;
2842 unsigned int num
= debug_info_p
->num_range_lists
;
2844 if (lmax
== 0 || num
>= lmax
)
2847 debug_info_p
->range_lists
= (dwarf_vma
*)
2848 xcrealloc (debug_info_p
->range_lists
,
2849 lmax
, sizeof (*debug_info_p
->range_lists
));
2850 debug_info_p
->max_range_lists
= lmax
;
2852 debug_info_p
->range_lists
[num
] = uvalue
;
2853 debug_info_p
->num_range_lists
++;
2857 case DW_AT_GNU_dwo_name
:
2858 case DW_AT_dwo_name
:
2863 add_dwo_name ((const char *) fetch_indirect_string (uvalue
), cu_offset
);
2865 case DW_FORM_GNU_strp_alt
:
2866 add_dwo_name ((const char *) fetch_alt_indirect_string (uvalue
), cu_offset
);
2868 case DW_FORM_GNU_str_index
:
2874 add_dwo_name (fetch_indexed_string (uvalue
, this_set
, offset_size
, false), cu_offset
);
2876 case DW_FORM_string
:
2877 add_dwo_name ((const char *) orig_data
, cu_offset
);
2880 warn (_("Unsupported form (%s) for attribute %s\n"),
2881 get_FORM_name (form
), get_AT_name (attribute
));
2886 case DW_AT_comp_dir
:
2887 /* FIXME: Also extract a build-id in a CU/TU. */
2892 add_dwo_dir ((const char *) fetch_indirect_string (uvalue
), cu_offset
);
2894 case DW_FORM_GNU_strp_alt
:
2895 add_dwo_dir (fetch_alt_indirect_string (uvalue
), cu_offset
);
2897 case DW_FORM_line_strp
:
2898 add_dwo_dir ((const char *) fetch_indirect_line_string (uvalue
), cu_offset
);
2900 case DW_FORM_GNU_str_index
:
2906 add_dwo_dir (fetch_indexed_string (uvalue
, this_set
, offset_size
, false), cu_offset
);
2908 case DW_FORM_string
:
2909 add_dwo_dir ((const char *) orig_data
, cu_offset
);
2912 warn (_("Unsupported form (%s) for attribute %s\n"),
2913 get_FORM_name (form
), get_AT_name (attribute
));
2918 case DW_AT_GNU_dwo_id
:
2923 /* FIXME: Record the length of the ID as well ? */
2924 add_dwo_id ((const char *) (data
- 8), cu_offset
);
2927 warn (_("Unsupported form (%s) for attribute %s\n"),
2928 get_FORM_name (form
), get_AT_name (attribute
));
2938 if (do_loc
|| attribute
== 0)
2941 /* For some attributes we can display further information. */
2945 if (level
>= 0 && level
< MAX_CU_NESTING
2946 && uvalue
< (size_t) (end
- start
))
2948 bool is_signed
= false;
2949 abbrev_entry
*type_abbrev
;
2950 unsigned char *type_data
;
2951 unsigned long type_cu_offset
;
2953 type_abbrev
= get_type_abbrev_from_form (form
, uvalue
, cu_offset
,
2954 section
, NULL
, & type_data
, & type_cu_offset
);
2955 if (type_abbrev
!= NULL
)
2957 get_type_signedness (type_abbrev
, section
, type_data
, end
, type_cu_offset
,
2958 pointer_size
, offset_size
, dwarf_version
,
2961 level_type_signed
[level
] = is_signed
;
2969 case DW_INL_not_inlined
:
2970 printf (_("(not inlined)"));
2972 case DW_INL_inlined
:
2973 printf (_("(inlined)"));
2975 case DW_INL_declared_not_inlined
:
2976 printf (_("(declared as inline but ignored)"));
2978 case DW_INL_declared_inlined
:
2979 printf (_("(declared as inline and inlined)"));
2982 printf (_(" (Unknown inline attribute value: %s)"),
2983 dwarf_vmatoa ("x", uvalue
));
2988 case DW_AT_language
:
2992 /* Ordered by the numeric value of these constants. */
2993 case DW_LANG_C89
: printf ("(ANSI C)"); break;
2994 case DW_LANG_C
: printf ("(non-ANSI C)"); break;
2995 case DW_LANG_Ada83
: printf ("(Ada)"); break;
2996 case DW_LANG_C_plus_plus
: printf ("(C++)"); break;
2997 case DW_LANG_Cobol74
: printf ("(Cobol 74)"); break;
2998 case DW_LANG_Cobol85
: printf ("(Cobol 85)"); break;
2999 case DW_LANG_Fortran77
: printf ("(FORTRAN 77)"); break;
3000 case DW_LANG_Fortran90
: printf ("(Fortran 90)"); break;
3001 case DW_LANG_Pascal83
: printf ("(ANSI Pascal)"); break;
3002 case DW_LANG_Modula2
: printf ("(Modula 2)"); break;
3003 /* DWARF 2.1 values. */
3004 case DW_LANG_Java
: printf ("(Java)"); break;
3005 case DW_LANG_C99
: printf ("(ANSI C99)"); break;
3006 case DW_LANG_Ada95
: printf ("(ADA 95)"); break;
3007 case DW_LANG_Fortran95
: printf ("(Fortran 95)"); break;
3008 /* DWARF 3 values. */
3009 case DW_LANG_PLI
: printf ("(PLI)"); break;
3010 case DW_LANG_ObjC
: printf ("(Objective C)"); break;
3011 case DW_LANG_ObjC_plus_plus
: printf ("(Objective C++)"); break;
3012 case DW_LANG_UPC
: printf ("(Unified Parallel C)"); break;
3013 case DW_LANG_D
: printf ("(D)"); break;
3014 /* DWARF 4 values. */
3015 case DW_LANG_Python
: printf ("(Python)"); break;
3016 /* DWARF 5 values. */
3017 case DW_LANG_OpenCL
: printf ("(OpenCL)"); break;
3018 case DW_LANG_Go
: printf ("(Go)"); break;
3019 case DW_LANG_Modula3
: printf ("(Modula 3)"); break;
3020 case DW_LANG_Haskell
: printf ("(Haskell)"); break;
3021 case DW_LANG_C_plus_plus_03
: printf ("(C++03)"); break;
3022 case DW_LANG_C_plus_plus_11
: printf ("(C++11)"); break;
3023 case DW_LANG_OCaml
: printf ("(OCaml)"); break;
3024 case DW_LANG_Rust
: printf ("(Rust)"); break;
3025 case DW_LANG_C11
: printf ("(C11)"); break;
3026 case DW_LANG_Swift
: printf ("(Swift)"); break;
3027 case DW_LANG_Julia
: printf ("(Julia)"); break;
3028 case DW_LANG_Dylan
: printf ("(Dylan)"); break;
3029 case DW_LANG_C_plus_plus_14
: printf ("(C++14)"); break;
3030 case DW_LANG_Fortran03
: printf ("(Fortran 03)"); break;
3031 case DW_LANG_Fortran08
: printf ("(Fortran 08)"); break;
3032 case DW_LANG_RenderScript
: printf ("(RenderScript)"); break;
3033 /* MIPS extension. */
3034 case DW_LANG_Mips_Assembler
: printf ("(MIPS assembler)"); break;
3035 /* UPC extension. */
3036 case DW_LANG_Upc
: printf ("(Unified Parallel C)"); break;
3038 if (uvalue
>= DW_LANG_lo_user
&& uvalue
<= DW_LANG_hi_user
)
3039 printf (_("(implementation defined: %s)"),
3040 dwarf_vmatoa ("x", uvalue
));
3042 printf (_("(Unknown: %s)"), dwarf_vmatoa ("x", uvalue
));
3047 case DW_AT_encoding
:
3051 case DW_ATE_void
: printf ("(void)"); break;
3052 case DW_ATE_address
: printf ("(machine address)"); break;
3053 case DW_ATE_boolean
: printf ("(boolean)"); break;
3054 case DW_ATE_complex_float
: printf ("(complex float)"); break;
3055 case DW_ATE_float
: printf ("(float)"); break;
3056 case DW_ATE_signed
: printf ("(signed)"); break;
3057 case DW_ATE_signed_char
: printf ("(signed char)"); break;
3058 case DW_ATE_unsigned
: printf ("(unsigned)"); break;
3059 case DW_ATE_unsigned_char
: printf ("(unsigned char)"); break;
3060 /* DWARF 2.1 values: */
3061 case DW_ATE_imaginary_float
: printf ("(imaginary float)"); break;
3062 case DW_ATE_decimal_float
: printf ("(decimal float)"); break;
3063 /* DWARF 3 values: */
3064 case DW_ATE_packed_decimal
: printf ("(packed_decimal)"); break;
3065 case DW_ATE_numeric_string
: printf ("(numeric_string)"); break;
3066 case DW_ATE_edited
: printf ("(edited)"); break;
3067 case DW_ATE_signed_fixed
: printf ("(signed_fixed)"); break;
3068 case DW_ATE_unsigned_fixed
: printf ("(unsigned_fixed)"); break;
3069 /* DWARF 4 values: */
3070 case DW_ATE_UTF
: printf ("(unicode string)"); break;
3071 /* DWARF 5 values: */
3072 case DW_ATE_UCS
: printf ("(UCS)"); break;
3073 case DW_ATE_ASCII
: printf ("(ASCII)"); break;
3075 /* HP extensions: */
3076 case DW_ATE_HP_float80
: printf ("(HP_float80)"); break;
3077 case DW_ATE_HP_complex_float80
: printf ("(HP_complex_float80)"); break;
3078 case DW_ATE_HP_float128
: printf ("(HP_float128)"); break;
3079 case DW_ATE_HP_complex_float128
:printf ("(HP_complex_float128)"); break;
3080 case DW_ATE_HP_floathpintel
: printf ("(HP_floathpintel)"); break;
3081 case DW_ATE_HP_imaginary_float80
: printf ("(HP_imaginary_float80)"); break;
3082 case DW_ATE_HP_imaginary_float128
: printf ("(HP_imaginary_float128)"); break;
3085 if (uvalue
>= DW_ATE_lo_user
3086 && uvalue
<= DW_ATE_hi_user
)
3087 printf (_("(user defined type)"));
3089 printf (_("(unknown type)"));
3094 case DW_AT_accessibility
:
3098 case DW_ACCESS_public
: printf ("(public)"); break;
3099 case DW_ACCESS_protected
: printf ("(protected)"); break;
3100 case DW_ACCESS_private
: printf ("(private)"); break;
3102 printf (_("(unknown accessibility)"));
3107 case DW_AT_visibility
:
3111 case DW_VIS_local
: printf ("(local)"); break;
3112 case DW_VIS_exported
: printf ("(exported)"); break;
3113 case DW_VIS_qualified
: printf ("(qualified)"); break;
3114 default: printf (_("(unknown visibility)")); break;
3118 case DW_AT_endianity
:
3122 case DW_END_default
: printf ("(default)"); break;
3123 case DW_END_big
: printf ("(big)"); break;
3124 case DW_END_little
: printf ("(little)"); break;
3126 if (uvalue
>= DW_END_lo_user
&& uvalue
<= DW_END_hi_user
)
3127 printf (_("(user specified)"));
3129 printf (_("(unknown endianity)"));
3134 case DW_AT_virtuality
:
3138 case DW_VIRTUALITY_none
: printf ("(none)"); break;
3139 case DW_VIRTUALITY_virtual
: printf ("(virtual)"); break;
3140 case DW_VIRTUALITY_pure_virtual
:printf ("(pure_virtual)"); break;
3141 default: printf (_("(unknown virtuality)")); break;
3145 case DW_AT_identifier_case
:
3149 case DW_ID_case_sensitive
: printf ("(case_sensitive)"); break;
3150 case DW_ID_up_case
: printf ("(up_case)"); break;
3151 case DW_ID_down_case
: printf ("(down_case)"); break;
3152 case DW_ID_case_insensitive
: printf ("(case_insensitive)"); break;
3153 default: printf (_("(unknown case)")); break;
3157 case DW_AT_calling_convention
:
3161 case DW_CC_normal
: printf ("(normal)"); break;
3162 case DW_CC_program
: printf ("(program)"); break;
3163 case DW_CC_nocall
: printf ("(nocall)"); break;
3164 case DW_CC_pass_by_reference
: printf ("(pass by ref)"); break;
3165 case DW_CC_pass_by_value
: printf ("(pass by value)"); break;
3166 case DW_CC_GNU_renesas_sh
: printf ("(Rensas SH)"); break;
3167 case DW_CC_GNU_borland_fastcall_i386
: printf ("(Borland fastcall i386)"); break;
3169 if (uvalue
>= DW_CC_lo_user
3170 && uvalue
<= DW_CC_hi_user
)
3171 printf (_("(user defined)"));
3173 printf (_("(unknown convention)"));
3177 case DW_AT_ordering
:
3182 case -1: printf (_("(undefined)")); break;
3183 case 0: printf ("(row major)"); break;
3184 case 1: printf ("(column major)"); break;
3188 case DW_AT_decimal_sign
:
3192 case DW_DS_unsigned
: printf (_("(unsigned)")); break;
3193 case DW_DS_leading_overpunch
: printf (_("(leading overpunch)")); break;
3194 case DW_DS_trailing_overpunch
: printf (_("(trailing overpunch)")); break;
3195 case DW_DS_leading_separate
: printf (_("(leading separate)")); break;
3196 case DW_DS_trailing_separate
: printf (_("(trailing separate)")); break;
3197 default: printf (_("(unrecognised)")); break;
3201 case DW_AT_defaulted
:
3205 case DW_DEFAULTED_no
: printf (_("(no)")); break;
3206 case DW_DEFAULTED_in_class
: printf (_("(in class)")); break;
3207 case DW_DEFAULTED_out_of_class
: printf (_("(out of class)")); break;
3208 default: printf (_("(unrecognised)")); break;
3212 case DW_AT_discr_list
:
3214 display_discr_list (form
, uvalue
, data
, end
, level
);
3217 case DW_AT_frame_base
:
3218 have_frame_base
= 1;
3220 case DW_AT_location
:
3221 case DW_AT_string_length
:
3222 case DW_AT_return_addr
:
3223 case DW_AT_data_member_location
:
3224 case DW_AT_vtable_elem_location
:
3226 case DW_AT_static_link
:
3227 case DW_AT_use_location
:
3228 case DW_AT_call_value
:
3229 case DW_AT_GNU_call_site_value
:
3230 case DW_AT_call_data_value
:
3231 case DW_AT_GNU_call_site_data_value
:
3232 case DW_AT_call_target
:
3233 case DW_AT_GNU_call_site_target
:
3234 case DW_AT_call_target_clobbered
:
3235 case DW_AT_GNU_call_site_target_clobbered
:
3236 if ((dwarf_version
< 4
3237 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
3238 || form
== DW_FORM_sec_offset
)
3239 printf (_(" (location list)"));
3241 case DW_AT_allocated
:
3242 case DW_AT_associated
:
3243 case DW_AT_data_location
:
3245 case DW_AT_upper_bound
:
3246 case DW_AT_lower_bound
:
3249 int need_frame_base
;
3252 need_frame_base
= decode_location_expression (block_start
,
3257 cu_offset
, section
);
3259 if (need_frame_base
&& !have_frame_base
)
3260 printf (_(" [without DW_AT_frame_base]"));
3264 case DW_AT_data_bit_offset
:
3265 case DW_AT_byte_size
:
3266 case DW_AT_bit_size
:
3267 case DW_AT_string_length_byte_size
:
3268 case DW_AT_string_length_bit_size
:
3269 case DW_AT_bit_stride
:
3270 if (form
== DW_FORM_exprloc
)
3273 (void) decode_location_expression (block_start
, pointer_size
,
3274 offset_size
, dwarf_version
,
3275 uvalue
, cu_offset
, section
);
3282 unsigned long abbrev_number
;
3283 abbrev_entry
*entry
;
3285 entry
= get_type_abbrev_from_form (form
, uvalue
, cu_offset
,
3286 section
, & abbrev_number
, NULL
, NULL
);
3289 if (form
!= DW_FORM_GNU_ref_alt
)
3290 warn (_("Offset %s used as value for DW_AT_import attribute of DIE at offset 0x%lx is too big.\n"),
3291 dwarf_vmatoa ("x", uvalue
),
3292 (unsigned long) (orig_data
- section
->start
));
3296 printf (_("\t[Abbrev Number: %ld"), abbrev_number
);
3297 printf (" (%s)", get_TAG_name (entry
->tag
));
3310 static unsigned char *
3311 read_and_display_attr (unsigned long attribute
,
3313 dwarf_signed_vma implicit_const
,
3314 unsigned char * start
,
3315 unsigned char * data
,
3316 unsigned char * end
,
3317 dwarf_vma cu_offset
,
3318 dwarf_vma pointer_size
,
3319 dwarf_vma offset_size
,
3321 debug_info
* debug_info_p
,
3323 struct dwarf_section
* section
,
3324 struct cu_tu_set
* this_set
,
3328 printf (" %-18s:", get_AT_name (attribute
));
3329 data
= read_and_display_attr_value (attribute
, form
, implicit_const
,
3331 cu_offset
, pointer_size
, offset_size
,
3332 dwarf_version
, debug_info_p
,
3333 do_loc
, section
, this_set
, ' ', level
);
3339 /* Like load_debug_section, but if the ordinary call fails, and we are
3340 following debug links, then attempt to load the requested section
3341 from one of the separate debug info files. */
3344 load_debug_section_with_follow (enum dwarf_section_display_enum sec_enum
,
3347 if (load_debug_section (sec_enum
, handle
))
3349 if (debug_displays
[sec_enum
].section
.filename
== NULL
)
3351 /* See if we can associate a filename with this section. */
3354 for (i
= first_separate_info
; i
!= NULL
; i
= i
->next
)
3355 if (i
->handle
== handle
)
3357 debug_displays
[sec_enum
].section
.filename
= i
->filename
;
3365 if (do_follow_links
)
3369 for (i
= first_separate_info
; i
!= NULL
; i
= i
->next
)
3371 if (load_debug_section (sec_enum
, i
->handle
))
3373 debug_displays
[sec_enum
].section
.filename
= i
->filename
;
3375 /* FIXME: We should check to see if any of the remaining debug info
3376 files also contain this section, and, umm, do something about it. */
3386 introduce (struct dwarf_section
* section
, bool raw
)
3390 if (do_follow_links
&& section
->filename
)
3391 printf (_("Raw dump of debug contents of section %s (loaded from %s):\n\n"),
3392 section
->name
, section
->filename
);
3394 printf (_("Raw dump of debug contents of section %s:\n\n"), section
->name
);
3398 if (do_follow_links
&& section
->filename
)
3399 printf (_("Contents of the %s section (loaded from %s):\n\n"),
3400 section
->name
, section
->filename
);
3402 printf (_("Contents of the %s section:\n\n"), section
->name
);
3406 /* Process the contents of a .debug_info section.
3407 If do_loc is TRUE then we are scanning for location lists and dwo tags
3408 and we do not want to display anything to the user.
3409 If do_types is TRUE, we are processing a .debug_types section instead of
3410 a .debug_info section.
3411 The information displayed is restricted by the values in DWARF_START_DIE
3412 and DWARF_CUTOFF_LEVEL.
3413 Returns TRUE upon success. Otherwise an error or warning message is
3414 printed and FALSE is returned. */
3417 process_debug_info (struct dwarf_section
* section
,
3419 enum dwarf_section_display_enum abbrev_sec
,
3423 unsigned char *start
= section
->start
;
3424 unsigned char *end
= start
+ section
->size
;
3425 unsigned char *section_begin
;
3427 unsigned int num_units
= 0;
3429 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
3430 && num_debug_info_entries
== 0
3435 /* First scan the section to get the number of comp units. */
3436 for (section_begin
= start
, num_units
= 0; section_begin
< end
;
3439 /* Read the first 4 bytes. For a 32-bit DWARF section, this
3440 will be the length. For a 64-bit DWARF section, it'll be
3441 the escape code 0xffffffff followed by an 8 byte length. */
3442 SAFE_BYTE_GET_AND_INC (length
, section_begin
, 4, end
);
3444 if (length
== 0xffffffff)
3445 SAFE_BYTE_GET_AND_INC (length
, section_begin
, 8, end
);
3446 else if (length
>= 0xfffffff0 && length
< 0xffffffff)
3448 warn (_("Reserved length value (0x%s) found in section %s\n"),
3449 dwarf_vmatoa ("x", length
), section
->name
);
3453 /* Negative values are illegal, they may even cause infinite
3454 looping. This can happen if we can't accurately apply
3455 relocations to an object file, or if the file is corrupt. */
3456 if (length
> (size_t) (end
- section_begin
))
3458 warn (_("Corrupt unit length (0x%s) found in section %s\n"),
3459 dwarf_vmatoa ("x", length
), section
->name
);
3462 section_begin
+= length
;
3467 error (_("No comp units in %s section ?\n"), section
->name
);
3471 /* Then allocate an array to hold the information. */
3472 debug_information
= (debug_info
*) cmalloc (num_units
,
3473 sizeof (* debug_information
));
3474 if (debug_information
== NULL
)
3476 error (_("Not enough memory for a debug info array of %u entries\n"),
3478 alloc_num_debug_info_entries
= num_debug_info_entries
= 0;
3482 /* PR 17531: file: 92ca3797.
3483 We cannot rely upon the debug_information array being initialised
3484 before it is used. A corrupt file could easily contain references
3485 to a unit for which information has not been made available. So
3486 we ensure that the array is zeroed here. */
3487 memset (debug_information
, 0, num_units
* sizeof (*debug_information
));
3489 alloc_num_debug_info_entries
= num_units
;
3494 load_debug_section_with_follow (str
, file
);
3495 load_debug_section_with_follow (line_str
, file
);
3496 load_debug_section_with_follow (str_dwo
, file
);
3497 load_debug_section_with_follow (str_index
, file
);
3498 load_debug_section_with_follow (str_index_dwo
, file
);
3499 load_debug_section_with_follow (debug_addr
, file
);
3502 load_debug_section_with_follow (abbrev_sec
, file
);
3503 if (debug_displays
[abbrev_sec
].section
.start
== NULL
)
3505 warn (_("Unable to locate %s section!\n"),
3506 debug_displays
[abbrev_sec
].section
.uncompressed_name
);
3510 if (!do_loc
&& dwarf_start_die
== 0)
3511 introduce (section
, false);
3513 free_all_abbrevs ();
3514 free (cu_abbrev_map
);
3515 cu_abbrev_map
= NULL
;
3516 next_free_abbrev_map_entry
= 0;
3518 /* In order to be able to resolve DW_FORM_ref_attr forms we need
3519 to load *all* of the abbrevs for all CUs in this .debug_info
3520 section. This does effectively mean that we (partially) read
3521 every CU header twice. */
3522 for (section_begin
= start
; start
< end
;)
3524 DWARF2_Internal_CompUnit compunit
;
3525 unsigned char * hdrptr
;
3526 dwarf_vma abbrev_base
;
3528 dwarf_vma cu_offset
;
3529 unsigned int offset_size
;
3530 unsigned int initial_length_size
;
3531 struct cu_tu_set
* this_set
;
3536 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 4, end
);
3538 if (compunit
.cu_length
== 0xffffffff)
3540 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 8, end
);
3542 initial_length_size
= 12;
3547 initial_length_size
= 4;
3550 SAFE_BYTE_GET_AND_INC (compunit
.cu_version
, hdrptr
, 2, end
);
3552 cu_offset
= start
- section_begin
;
3554 this_set
= find_cu_tu_set_v2 (cu_offset
, do_types
);
3556 if (compunit
.cu_version
< 5)
3558 compunit
.cu_unit_type
= DW_UT_compile
;
3559 /* Initialize it due to a false compiler warning. */
3560 compunit
.cu_pointer_size
= -1;
3564 SAFE_BYTE_GET_AND_INC (compunit
.cu_unit_type
, hdrptr
, 1, end
);
3565 do_types
= (compunit
.cu_unit_type
== DW_UT_type
);
3567 SAFE_BYTE_GET_AND_INC (compunit
.cu_pointer_size
, hdrptr
, 1, end
);
3570 SAFE_BYTE_GET_AND_INC (compunit
.cu_abbrev_offset
, hdrptr
, offset_size
, end
);
3572 if (compunit
.cu_unit_type
== DW_UT_split_compile
3573 || compunit
.cu_unit_type
== DW_UT_skeleton
)
3576 SAFE_BYTE_GET_AND_INC (dwo_id
, hdrptr
, 8, end
);
3579 if (this_set
== NULL
)
3582 abbrev_size
= debug_displays
[abbrev_sec
].section
.size
;
3586 abbrev_base
= this_set
->section_offsets
[DW_SECT_ABBREV
];
3587 abbrev_size
= this_set
->section_sizes
[DW_SECT_ABBREV
];
3590 list
= find_abbrev_list_by_abbrev_offset (abbrev_base
,
3591 compunit
.cu_abbrev_offset
);
3594 unsigned char * next
;
3596 list
= new_abbrev_list (abbrev_base
,
3597 compunit
.cu_abbrev_offset
);
3598 next
= process_abbrev_set (&debug_displays
[abbrev_sec
].section
,
3599 abbrev_base
, abbrev_size
,
3600 compunit
.cu_abbrev_offset
, list
);
3601 list
->start_of_next_abbrevs
= next
;
3604 start
= section_begin
+ cu_offset
+ compunit
.cu_length
3605 + initial_length_size
;
3606 record_abbrev_list_for_cu (cu_offset
, start
- section_begin
, list
);
3609 for (start
= section_begin
, unit
= 0; start
< end
; unit
++)
3611 DWARF2_Internal_CompUnit compunit
;
3612 unsigned char *hdrptr
;
3613 unsigned char *tags
;
3614 int level
, last_level
, saved_level
;
3615 dwarf_vma cu_offset
;
3616 unsigned long sec_off
;
3617 unsigned int offset_size
;
3618 unsigned int initial_length_size
;
3619 dwarf_vma signature
= 0;
3620 dwarf_vma type_offset
= 0;
3621 struct cu_tu_set
*this_set
;
3622 dwarf_vma abbrev_base
;
3624 abbrev_list
* list
= NULL
;
3628 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 4, end
);
3630 if (compunit
.cu_length
== 0xffffffff)
3632 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 8, end
);
3634 initial_length_size
= 12;
3639 initial_length_size
= 4;
3642 SAFE_BYTE_GET_AND_INC (compunit
.cu_version
, hdrptr
, 2, end
);
3644 cu_offset
= start
- section_begin
;
3646 this_set
= find_cu_tu_set_v2 (cu_offset
, do_types
);
3648 if (compunit
.cu_version
< 5)
3650 compunit
.cu_unit_type
= DW_UT_compile
;
3651 /* Initialize it due to a false compiler warning. */
3652 compunit
.cu_pointer_size
= -1;
3656 SAFE_BYTE_GET_AND_INC (compunit
.cu_unit_type
, hdrptr
, 1, end
);
3657 do_types
= (compunit
.cu_unit_type
== DW_UT_type
);
3659 SAFE_BYTE_GET_AND_INC (compunit
.cu_pointer_size
, hdrptr
, 1, end
);
3662 SAFE_BYTE_GET_AND_INC (compunit
.cu_abbrev_offset
, hdrptr
, offset_size
, end
);
3664 if (this_set
== NULL
)
3667 abbrev_size
= debug_displays
[abbrev_sec
].section
.size
;
3671 abbrev_base
= this_set
->section_offsets
[DW_SECT_ABBREV
];
3672 abbrev_size
= this_set
->section_sizes
[DW_SECT_ABBREV
];
3675 if (compunit
.cu_version
< 5)
3676 SAFE_BYTE_GET_AND_INC (compunit
.cu_pointer_size
, hdrptr
, 1, end
);
3678 bool do_dwo_id
= false;
3679 uint64_t dwo_id
= 0;
3680 if (compunit
.cu_unit_type
== DW_UT_split_compile
3681 || compunit
.cu_unit_type
== DW_UT_skeleton
)
3683 SAFE_BYTE_GET_AND_INC (dwo_id
, hdrptr
, 8, end
);
3687 /* PR 17512: file: 001-108546-0.001:0.1. */
3688 if (compunit
.cu_pointer_size
< 2 || compunit
.cu_pointer_size
> 8)
3690 warn (_("Invalid pointer size (%d) in compunit header, using %d instead\n"),
3691 compunit
.cu_pointer_size
, offset_size
);
3692 compunit
.cu_pointer_size
= offset_size
;
3697 SAFE_BYTE_GET_AND_INC (signature
, hdrptr
, 8, end
);
3698 SAFE_BYTE_GET_AND_INC (type_offset
, hdrptr
, offset_size
, end
);
3701 if (dwarf_start_die
> (cu_offset
+ compunit
.cu_length
3702 + initial_length_size
))
3704 start
= section_begin
+ cu_offset
+ compunit
.cu_length
3705 + initial_length_size
;
3709 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
3710 && num_debug_info_entries
== 0
3711 && alloc_num_debug_info_entries
> unit
3714 debug_information
[unit
].cu_offset
= cu_offset
;
3715 debug_information
[unit
].pointer_size
3716 = compunit
.cu_pointer_size
;
3717 debug_information
[unit
].offset_size
= offset_size
;
3718 debug_information
[unit
].dwarf_version
= compunit
.cu_version
;
3719 debug_information
[unit
].base_address
= 0;
3720 debug_information
[unit
].addr_base
= DEBUG_INFO_UNAVAILABLE
;
3721 debug_information
[unit
].ranges_base
= DEBUG_INFO_UNAVAILABLE
;
3722 debug_information
[unit
].loc_offsets
= NULL
;
3723 debug_information
[unit
].have_frame_base
= NULL
;
3724 debug_information
[unit
].max_loc_offsets
= 0;
3725 debug_information
[unit
].num_loc_offsets
= 0;
3726 debug_information
[unit
].range_lists
= NULL
;
3727 debug_information
[unit
].max_range_lists
= 0;
3728 debug_information
[unit
].num_range_lists
= 0;
3731 if (!do_loc
&& dwarf_start_die
== 0)
3733 printf (_(" Compilation Unit @ offset 0x%s:\n"),
3734 dwarf_vmatoa ("x", cu_offset
));
3735 printf (_(" Length: 0x%s (%s)\n"),
3736 dwarf_vmatoa ("x", compunit
.cu_length
),
3737 offset_size
== 8 ? "64-bit" : "32-bit");
3738 printf (_(" Version: %d\n"), compunit
.cu_version
);
3739 if (compunit
.cu_version
>= 5)
3741 const char *name
= get_DW_UT_name (compunit
.cu_unit_type
);
3743 printf (_(" Unit Type: %s (%x)\n"),
3744 name
? name
: "???",
3745 compunit
.cu_unit_type
);
3747 printf (_(" Abbrev Offset: 0x%s\n"),
3748 dwarf_vmatoa ("x", compunit
.cu_abbrev_offset
));
3749 printf (_(" Pointer Size: %d\n"), compunit
.cu_pointer_size
);
3752 printf (_(" Signature: 0x%s\n"),
3753 dwarf_vmatoa ("x", signature
));
3754 printf (_(" Type Offset: 0x%s\n"),
3755 dwarf_vmatoa ("x", type_offset
));
3758 printf (_(" DWO ID: 0x%s\n"), dwarf_vmatoa ("x", dwo_id
));
3759 if (this_set
!= NULL
)
3761 dwarf_vma
*offsets
= this_set
->section_offsets
;
3762 size_t *sizes
= this_set
->section_sizes
;
3764 printf (_(" Section contributions:\n"));
3765 printf (_(" .debug_abbrev.dwo: 0x%s 0x%s\n"),
3766 dwarf_vmatoa ("x", offsets
[DW_SECT_ABBREV
]),
3767 dwarf_vmatoa ("x", sizes
[DW_SECT_ABBREV
]));
3768 printf (_(" .debug_line.dwo: 0x%s 0x%s\n"),
3769 dwarf_vmatoa ("x", offsets
[DW_SECT_LINE
]),
3770 dwarf_vmatoa ("x", sizes
[DW_SECT_LINE
]));
3771 printf (_(" .debug_loc.dwo: 0x%s 0x%s\n"),
3772 dwarf_vmatoa ("x", offsets
[DW_SECT_LOC
]),
3773 dwarf_vmatoa ("x", sizes
[DW_SECT_LOC
]));
3774 printf (_(" .debug_str_offsets.dwo: 0x%s 0x%s\n"),
3775 dwarf_vmatoa ("x", offsets
[DW_SECT_STR_OFFSETS
]),
3776 dwarf_vmatoa ("x", sizes
[DW_SECT_STR_OFFSETS
]));
3780 sec_off
= cu_offset
+ initial_length_size
;
3781 if (sec_off
+ compunit
.cu_length
< sec_off
3782 || sec_off
+ compunit
.cu_length
> section
->size
)
3784 warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"),
3786 (unsigned long) cu_offset
,
3787 dwarf_vmatoa ("x", compunit
.cu_length
));
3793 start
+= compunit
.cu_length
+ initial_length_size
;
3795 if (compunit
.cu_version
< 2 || compunit
.cu_version
> 5)
3797 warn (_("CU at offset %s contains corrupt or "
3798 "unsupported version number: %d.\n"),
3799 dwarf_vmatoa ("x", cu_offset
), compunit
.cu_version
);
3803 if (compunit
.cu_unit_type
!= DW_UT_compile
3804 && compunit
.cu_unit_type
!= DW_UT_partial
3805 && compunit
.cu_unit_type
!= DW_UT_type
3806 && compunit
.cu_unit_type
!= DW_UT_split_compile
3807 && compunit
.cu_unit_type
!= DW_UT_skeleton
)
3809 warn (_("CU at offset %s contains corrupt or "
3810 "unsupported unit type: %d.\n"),
3811 dwarf_vmatoa ("x", cu_offset
), compunit
.cu_unit_type
);
3815 /* Process the abbrevs used by this compilation unit. */
3816 list
= find_abbrev_list_by_abbrev_offset (abbrev_base
,
3817 compunit
.cu_abbrev_offset
);
3820 unsigned char *next
;
3822 list
= new_abbrev_list (abbrev_base
,
3823 compunit
.cu_abbrev_offset
);
3824 next
= process_abbrev_set (&debug_displays
[abbrev_sec
].section
,
3825 abbrev_base
, abbrev_size
,
3826 compunit
.cu_abbrev_offset
, list
);
3827 list
->start_of_next_abbrevs
= next
;
3833 while (tags
< start
)
3835 unsigned long abbrev_number
;
3836 unsigned long die_offset
;
3837 abbrev_entry
*entry
;
3839 int do_printing
= 1;
3841 die_offset
= tags
- section_begin
;
3843 READ_ULEB (abbrev_number
, tags
, start
);
3845 /* A null DIE marks the end of a list of siblings or it may also be
3846 a section padding. */
3847 if (abbrev_number
== 0)
3849 /* Check if it can be a section padding for the last CU. */
3850 if (level
== 0 && start
== end
)
3854 for (chk
= tags
; chk
< start
; chk
++)
3861 if (!do_loc
&& die_offset
>= dwarf_start_die
3862 && (dwarf_cutoff_level
== -1
3863 || level
< dwarf_cutoff_level
))
3864 printf (_(" <%d><%lx>: Abbrev Number: 0\n"),
3870 static unsigned num_bogus_warns
= 0;
3872 if (num_bogus_warns
< 3)
3874 warn (_("Bogus end-of-siblings marker detected at offset %lx in %s section\n"),
3875 die_offset
, section
->name
);
3877 if (num_bogus_warns
== 3)
3878 warn (_("Further warnings about bogus end-of-sibling markers suppressed\n"));
3881 if (dwarf_start_die
!= 0 && level
< saved_level
)
3888 if (dwarf_start_die
!= 0 && die_offset
< dwarf_start_die
)
3892 if (dwarf_start_die
!= 0 && die_offset
== dwarf_start_die
)
3893 saved_level
= level
;
3894 do_printing
= (dwarf_cutoff_level
== -1
3895 || level
< dwarf_cutoff_level
);
3897 printf (_(" <%d><%lx>: Abbrev Number: %lu"),
3898 level
, die_offset
, abbrev_number
);
3899 else if (dwarf_cutoff_level
== -1
3900 || last_level
< dwarf_cutoff_level
)
3901 printf (_(" <%d><%lx>: ...\n"), level
, die_offset
);
3906 /* Scan through the abbreviation list until we reach the
3911 for (entry
= list
->first_abbrev
; entry
!= NULL
; entry
= entry
->next
)
3912 if (entry
->number
== abbrev_number
)
3917 if (!do_loc
&& do_printing
)
3922 warn (_("DIE at offset 0x%lx refers to abbreviation number %lu which does not exist\n"),
3923 die_offset
, abbrev_number
);
3927 if (!do_loc
&& do_printing
)
3928 printf (" (%s)\n", get_TAG_name (entry
->tag
));
3933 need_base_address
= 0;
3935 case DW_TAG_compile_unit
:
3936 need_base_address
= 1;
3937 need_dwo_info
= do_loc
;
3939 case DW_TAG_entry_point
:
3940 case DW_TAG_subprogram
:
3941 need_base_address
= 0;
3942 /* Assuming that there is no DW_AT_frame_base. */
3943 have_frame_base
= 0;
3947 debug_info
*debug_info_p
=
3948 (debug_information
&& unit
< alloc_num_debug_info_entries
)
3949 ? debug_information
+ unit
: NULL
;
3951 assert (!debug_info_p
3952 || (debug_info_p
->num_loc_offsets
3953 == debug_info_p
->num_loc_views
));
3955 for (attr
= entry
->first_attr
;
3956 attr
&& attr
->attribute
;
3959 if (! do_loc
&& do_printing
)
3960 /* Show the offset from where the tag was extracted. */
3961 printf (" <%lx>", (unsigned long)(tags
- section_begin
));
3962 tags
= read_and_display_attr (attr
->attribute
,
3964 attr
->implicit_const
,
3969 compunit
.cu_pointer_size
,
3971 compunit
.cu_version
,
3973 do_loc
|| ! do_printing
,
3979 /* If a locview attribute appears before a location one,
3980 make sure we don't associate it with an earlier
3983 switch (debug_info_p
->num_loc_offsets
- debug_info_p
->num_loc_views
)
3986 debug_info_p
->loc_views
[debug_info_p
->num_loc_views
] = vm1
;
3987 debug_info_p
->num_loc_views
++;
3988 assert (debug_info_p
->num_loc_views
3989 == debug_info_p
->num_loc_offsets
);
3996 warn(_("DIE has locviews without loclist\n"));
3997 debug_info_p
->num_loc_views
--;
4004 if (entry
->children
)
4009 /* Set num_debug_info_entries here so that it can be used to check if
4010 we need to process .debug_loc and .debug_ranges sections. */
4011 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
4012 && num_debug_info_entries
== 0
4015 if (num_units
> alloc_num_debug_info_entries
)
4016 num_debug_info_entries
= alloc_num_debug_info_entries
;
4018 num_debug_info_entries
= num_units
;
4027 /* Locate and scan the .debug_info section in the file and record the pointer
4028 sizes and offsets for the compilation units in it. Usually an executable
4029 will have just one pointer size, but this is not guaranteed, and so we try
4030 not to make any assumptions. Returns zero upon failure, or the number of
4031 compilation units upon success. */
4034 load_debug_info (void * file
)
4036 /* If we have already tried and failed to load the .debug_info
4037 section then do not bother to repeat the task. */
4038 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
4041 /* If we already have the information there is nothing else to do. */
4042 if (num_debug_info_entries
> 0)
4043 return num_debug_info_entries
;
4045 /* If this is a DWARF package file, load the CU and TU indexes. */
4046 (void) load_cu_tu_indexes (file
);
4048 if (load_debug_section_with_follow (info
, file
)
4049 && process_debug_info (&debug_displays
[info
].section
, file
, abbrev
, true, false))
4050 return num_debug_info_entries
;
4052 if (load_debug_section_with_follow (info_dwo
, file
)
4053 && process_debug_info (&debug_displays
[info_dwo
].section
, file
,
4054 abbrev_dwo
, true, false))
4055 return num_debug_info_entries
;
4057 num_debug_info_entries
= DEBUG_INFO_UNAVAILABLE
;
4061 /* Read a DWARF .debug_line section header starting at DATA.
4062 Upon success returns an updated DATA pointer and the LINFO
4063 structure and the END_OF_SEQUENCE pointer will be filled in.
4064 Otherwise returns NULL. */
4066 static unsigned char *
4067 read_debug_line_header (struct dwarf_section
* section
,
4068 unsigned char * data
,
4069 unsigned char * end
,
4070 DWARF2_Internal_LineInfo
* linfo
,
4071 unsigned char ** end_of_sequence
)
4073 unsigned char *hdrptr
;
4074 unsigned int initial_length_size
;
4076 /* Extract information from the Line Number Program Header.
4077 (section 6.2.4 in the Dwarf3 doc). */
4080 /* Get and check the length of the block. */
4081 SAFE_BYTE_GET_AND_INC (linfo
->li_length
, hdrptr
, 4, end
);
4083 if (linfo
->li_length
== 0xffffffff)
4085 /* This section is 64-bit DWARF 3. */
4086 SAFE_BYTE_GET_AND_INC (linfo
->li_length
, hdrptr
, 8, end
);
4087 linfo
->li_offset_size
= 8;
4088 initial_length_size
= 12;
4092 linfo
->li_offset_size
= 4;
4093 initial_length_size
= 4;
4096 if (linfo
->li_length
+ initial_length_size
> section
->size
)
4098 /* If the length field has a relocation against it, then we should
4099 not complain if it is inaccurate (and probably negative). This
4100 happens in object files when the .debug_line section is actually
4101 comprised of several different .debug_line.* sections, (some of
4102 which may be removed by linker garbage collection), and a relocation
4103 is used to compute the correct length once that is done. */
4104 if (reloc_at (section
, (hdrptr
- section
->start
) - linfo
->li_offset_size
))
4106 linfo
->li_length
= (end
- data
) - initial_length_size
;
4110 warn (_("The length field (0x%lx) in the debug_line header is wrong - the section is too small\n"),
4111 (long) linfo
->li_length
);
4116 /* Get and check the version number. */
4117 SAFE_BYTE_GET_AND_INC (linfo
->li_version
, hdrptr
, 2, end
);
4119 if (linfo
->li_version
!= 2
4120 && linfo
->li_version
!= 3
4121 && linfo
->li_version
!= 4
4122 && linfo
->li_version
!= 5)
4124 warn (_("Only DWARF version 2, 3, 4 and 5 line info "
4125 "is currently supported.\n"));
4129 if (linfo
->li_version
>= 5)
4131 SAFE_BYTE_GET_AND_INC (linfo
->li_address_size
, hdrptr
, 1, end
);
4133 SAFE_BYTE_GET_AND_INC (linfo
->li_segment_size
, hdrptr
, 1, end
);
4134 if (linfo
->li_segment_size
!= 0)
4136 warn (_("The %s section contains "
4137 "unsupported segment selector size: %d.\n"),
4138 section
->name
, linfo
->li_segment_size
);
4143 SAFE_BYTE_GET_AND_INC (linfo
->li_prologue_length
, hdrptr
,
4144 linfo
->li_offset_size
, end
);
4145 SAFE_BYTE_GET_AND_INC (linfo
->li_min_insn_length
, hdrptr
, 1, end
);
4147 if (linfo
->li_version
>= 4)
4149 SAFE_BYTE_GET_AND_INC (linfo
->li_max_ops_per_insn
, hdrptr
, 1, end
);
4151 if (linfo
->li_max_ops_per_insn
== 0)
4153 warn (_("Invalid maximum operations per insn.\n"));
4158 linfo
->li_max_ops_per_insn
= 1;
4160 SAFE_BYTE_GET_AND_INC (linfo
->li_default_is_stmt
, hdrptr
, 1, end
);
4161 SAFE_SIGNED_BYTE_GET_AND_INC (linfo
->li_line_base
, hdrptr
, 1, end
);
4162 SAFE_BYTE_GET_AND_INC (linfo
->li_line_range
, hdrptr
, 1, end
);
4163 SAFE_BYTE_GET_AND_INC (linfo
->li_opcode_base
, hdrptr
, 1, end
);
4165 * end_of_sequence
= data
+ linfo
->li_length
+ initial_length_size
;
4166 /* PR 17512: file:002-117414-0.004. */
4167 if (* end_of_sequence
> end
)
4169 warn (_("Line length %s extends beyond end of section\n"),
4170 dwarf_vmatoa ("u", linfo
->li_length
));
4171 * end_of_sequence
= end
;
4178 static unsigned char *
4179 display_formatted_table (unsigned char *data
,
4180 unsigned char *start
,
4182 const DWARF2_Internal_LineInfo
*linfo
,
4183 struct dwarf_section
*section
,
4186 unsigned char *format_start
, format_count
, *format
, formati
;
4187 dwarf_vma data_count
, datai
;
4188 unsigned int namepass
, last_entry
= 0;
4189 const char * table_name
= is_dir
? N_("Directory Table") : N_("File Name Table");
4191 SAFE_BYTE_GET_AND_INC (format_count
, data
, 1, end
);
4192 if (do_checks
&& format_count
> 5)
4193 warn (_("Unexpectedly large number of columns in the %s (%u)\n"),
4194 table_name
, format_count
);
4196 format_start
= data
;
4197 for (formati
= 0; formati
< format_count
; formati
++)
4199 SKIP_ULEB (data
, end
);
4200 SKIP_ULEB (data
, end
);
4203 warn (_("%s: Corrupt format description entry\n"), table_name
);
4208 READ_ULEB (data_count
, data
, end
);
4209 if (data_count
== 0)
4211 printf (_("\n The %s is empty.\n"), table_name
);
4214 else if (data
>= end
)
4216 warn (_("%s: Corrupt entry count - expected %s but none found\n"),
4217 table_name
, dwarf_vmatoa ("x", data_count
));
4221 else if (format_count
== 0)
4223 warn (_("%s: format count is zero, but the table is not empty\n"),
4228 printf (_("\n The %s (offset 0x%lx, lines %s, columns %u):\n"),
4229 table_name
, (long) (data
- start
), dwarf_vmatoa ("u", data_count
),
4232 printf (_(" Entry"));
4233 /* Delay displaying name as the last entry for better screen layout. */
4234 for (namepass
= 0; namepass
< 2; namepass
++)
4236 format
= format_start
;
4237 for (formati
= 0; formati
< format_count
; formati
++)
4239 dwarf_vma content_type
;
4241 READ_ULEB (content_type
, format
, end
);
4242 if ((content_type
== DW_LNCT_path
) == (namepass
== 1))
4243 switch (content_type
)
4246 printf (_("\tName"));
4248 case DW_LNCT_directory_index
:
4249 printf (_("\tDir"));
4251 case DW_LNCT_timestamp
:
4252 printf (_("\tTime"));
4255 printf (_("\tSize"));
4258 printf (_("\tMD5\t\t\t"));
4261 printf (_("\t(Unknown format content type %s)"),
4262 dwarf_vmatoa ("u", content_type
));
4264 SKIP_ULEB (format
, end
);
4269 for (datai
= 0; datai
< data_count
; datai
++)
4271 unsigned char *datapass
= data
;
4273 printf (" %d", last_entry
++);
4274 /* Delay displaying name as the last entry for better screen layout. */
4275 for (namepass
= 0; namepass
< 2; namepass
++)
4277 format
= format_start
;
4279 for (formati
= 0; formati
< format_count
; formati
++)
4281 dwarf_vma content_type
, form
;
4283 READ_ULEB (content_type
, format
, end
);
4284 READ_ULEB (form
, format
, end
);
4285 data
= read_and_display_attr_value (0, form
, 0, start
, data
, end
,
4286 0, 0, linfo
->li_offset_size
,
4287 linfo
->li_version
, NULL
,
4288 ((content_type
== DW_LNCT_path
) != (namepass
== 1)),
4289 section
, NULL
, '\t', -1);
4293 if (data
>= end
&& (datai
< data_count
- 1))
4295 warn (_("\n%s: Corrupt entries list\n"), table_name
);
4304 display_debug_sup (struct dwarf_section
* section
,
4305 void * file ATTRIBUTE_UNUSED
)
4307 unsigned char * start
= section
->start
;
4308 unsigned char * end
= section
->start
+ section
->size
;
4309 unsigned int version
;
4310 char is_supplementary
;
4311 const unsigned char * sup_filename
;
4312 size_t sup_filename_len
;
4313 unsigned int num_read
;
4315 dwarf_vma checksum_len
;
4318 introduce (section
, true);
4319 if (section
->size
< 4)
4321 error (_("corrupt .debug_sup section: size is too small\n"));
4325 /* Read the data. */
4326 SAFE_BYTE_GET_AND_INC (version
, start
, 2, end
);
4328 warn (_("corrupt .debug_sup section: version < 5"));
4330 SAFE_BYTE_GET_AND_INC (is_supplementary
, start
, 1, end
);
4331 if (is_supplementary
!= 0 && is_supplementary
!= 1)
4332 warn (_("corrupt .debug_sup section: is_supplementary not 0 or 1\n"));
4334 sup_filename
= start
;
4335 if (is_supplementary
&& sup_filename
[0] != 0)
4336 warn (_("corrupt .debug_sup section: filename not empty in supplementary section\n"));
4338 sup_filename_len
= strnlen ((const char *) start
, end
- start
);
4339 if (sup_filename_len
== (size_t) (end
- start
))
4341 error (_("corrupt .debug_sup section: filename is not NUL terminated\n"));
4344 start
+= sup_filename_len
+ 1;
4346 checksum_len
= read_leb128 (start
, end
, false /* unsigned */, & num_read
, & status
);
4349 error (_("corrupt .debug_sup section: bad LEB128 field for checksum length\n"));
4353 if (checksum_len
> (dwarf_vma
) (end
- start
))
4355 error (_("corrupt .debug_sup section: checksum length is longer than the remaining section length\n"));
4356 checksum_len
= end
- start
;
4358 else if (checksum_len
< (dwarf_vma
) (end
- start
))
4360 warn (_("corrupt .debug_sup section: there are 0x%lx extra, unused bytes at the end of the section\n"),
4361 (long) ((end
- start
) - checksum_len
));
4364 printf (_(" Version: %u\n"), version
);
4365 printf (_(" Is Supp: %u\n"), is_supplementary
);
4366 printf (_(" Filename: %s\n"), sup_filename
);
4367 printf (_(" Checksum Len: %lu\n"), (long) checksum_len
);
4368 if (checksum_len
> 0)
4370 printf (_(" Checksum: "));
4371 while (checksum_len
--)
4372 printf ("0x%x ", * start
++ );
4379 display_debug_lines_raw (struct dwarf_section
* section
,
4380 unsigned char * data
,
4381 unsigned char * end
,
4384 unsigned char *start
= section
->start
;
4385 int verbose_view
= 0;
4387 introduce (section
, true);
4391 static DWARF2_Internal_LineInfo saved_linfo
;
4392 DWARF2_Internal_LineInfo linfo
;
4393 unsigned char *standard_opcodes
;
4394 unsigned char *end_of_sequence
;
4397 if (startswith (section
->name
, ".debug_line.")
4398 /* Note: the following does not apply to .debug_line.dwo sections.
4399 These are full debug_line sections. */
4400 && strcmp (section
->name
, ".debug_line.dwo") != 0)
4402 /* Sections named .debug_line.<foo> are fragments of a .debug_line
4403 section containing just the Line Number Statements. They are
4404 created by the assembler and intended to be used alongside gcc's
4405 -ffunction-sections command line option. When the linker's
4406 garbage collection decides to discard a .text.<foo> section it
4407 can then also discard the line number information in .debug_line.<foo>.
4409 Since the section is a fragment it does not have the details
4410 needed to fill out a LineInfo structure, so instead we use the
4411 details from the last full debug_line section that we processed. */
4412 end_of_sequence
= end
;
4413 standard_opcodes
= NULL
;
4414 linfo
= saved_linfo
;
4415 /* PR 17531: file: 0522b371. */
4416 if (linfo
.li_line_range
== 0)
4418 warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n"));
4421 reset_state_machine (linfo
.li_default_is_stmt
);
4425 unsigned char * hdrptr
;
4427 if ((hdrptr
= read_debug_line_header (section
, data
, end
, & linfo
,
4428 & end_of_sequence
)) == NULL
)
4431 printf (_(" Offset: 0x%lx\n"), (long)(data
- start
));
4432 printf (_(" Length: %ld\n"), (long) linfo
.li_length
);
4433 printf (_(" DWARF Version: %d\n"), linfo
.li_version
);
4434 if (linfo
.li_version
>= 5)
4436 printf (_(" Address size (bytes): %d\n"), linfo
.li_address_size
);
4437 printf (_(" Segment selector (bytes): %d\n"), linfo
.li_segment_size
);
4439 printf (_(" Prologue Length: %d\n"), (int) linfo
.li_prologue_length
);
4440 printf (_(" Minimum Instruction Length: %d\n"), linfo
.li_min_insn_length
);
4441 if (linfo
.li_version
>= 4)
4442 printf (_(" Maximum Ops per Instruction: %d\n"), linfo
.li_max_ops_per_insn
);
4443 printf (_(" Initial value of 'is_stmt': %d\n"), linfo
.li_default_is_stmt
);
4444 printf (_(" Line Base: %d\n"), linfo
.li_line_base
);
4445 printf (_(" Line Range: %d\n"), linfo
.li_line_range
);
4446 printf (_(" Opcode Base: %d\n"), linfo
.li_opcode_base
);
4448 /* PR 17512: file: 1665-6428-0.004. */
4449 if (linfo
.li_line_range
== 0)
4451 warn (_("Line range of 0 is invalid, using 1 instead\n"));
4452 linfo
.li_line_range
= 1;
4455 reset_state_machine (linfo
.li_default_is_stmt
);
4457 /* Display the contents of the Opcodes table. */
4458 standard_opcodes
= hdrptr
;
4460 /* PR 17512: file: 002-417945-0.004. */
4461 if (standard_opcodes
+ linfo
.li_opcode_base
>= end
)
4463 warn (_("Line Base extends beyond end of section\n"));
4467 printf (_("\n Opcodes:\n"));
4469 for (i
= 1; i
< linfo
.li_opcode_base
; i
++)
4470 printf (ngettext (" Opcode %d has %d arg\n",
4471 " Opcode %d has %d args\n",
4472 standard_opcodes
[i
- 1]),
4473 i
, standard_opcodes
[i
- 1]);
4475 /* Display the contents of the Directory table. */
4476 data
= standard_opcodes
+ linfo
.li_opcode_base
- 1;
4478 if (linfo
.li_version
>= 5)
4480 load_debug_section_with_follow (line_str
, file
);
4482 data
= display_formatted_table (data
, start
, end
, &linfo
, section
,
4484 data
= display_formatted_table (data
, start
, end
, &linfo
, section
,
4490 printf (_("\n The Directory Table is empty.\n"));
4493 unsigned int last_dir_entry
= 0;
4495 printf (_("\n The Directory Table (offset 0x%lx):\n"),
4496 (long)(data
- start
));
4498 while (data
< end
&& *data
!= 0)
4500 printf (" %d\t%.*s\n", ++last_dir_entry
, (int) (end
- data
), data
);
4502 data
+= strnlen ((char *) data
, end
- data
);
4507 /* PR 17512: file: 002-132094-0.004. */
4508 if (data
>= end
- 1)
4512 /* Skip the NUL at the end of the table. */
4516 /* Display the contents of the File Name table. */
4517 if (data
>= end
|| *data
== 0)
4518 printf (_("\n The File Name Table is empty.\n"));
4521 printf (_("\n The File Name Table (offset 0x%lx):\n"),
4522 (long)(data
- start
));
4523 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
4525 while (data
< end
&& *data
!= 0)
4527 unsigned char *name
;
4530 printf (" %d\t", ++state_machine_regs
.last_file_entry
);
4532 data
+= strnlen ((char *) data
, end
- data
);
4536 READ_ULEB (val
, data
, end
);
4537 printf ("%s\t", dwarf_vmatoa ("u", val
));
4538 READ_ULEB (val
, data
, end
);
4539 printf ("%s\t", dwarf_vmatoa ("u", val
));
4540 READ_ULEB (val
, data
, end
);
4541 printf ("%s\t", dwarf_vmatoa ("u", val
));
4542 printf ("%.*s\n", (int)(end
- name
), name
);
4546 warn (_("Corrupt file name table entry\n"));
4552 /* Skip the NUL at the end of the table. */
4558 saved_linfo
= linfo
;
4561 /* Now display the statements. */
4562 if (data
>= end_of_sequence
)
4563 printf (_(" No Line Number Statements.\n"));
4566 printf (_(" Line Number Statements:\n"));
4568 while (data
< end_of_sequence
)
4570 unsigned char op_code
;
4571 dwarf_signed_vma adv
;
4574 printf (" [0x%08lx]", (long)(data
- start
));
4578 if (op_code
>= linfo
.li_opcode_base
)
4580 op_code
-= linfo
.li_opcode_base
;
4581 uladv
= (op_code
/ linfo
.li_line_range
);
4582 if (linfo
.li_max_ops_per_insn
== 1)
4584 uladv
*= linfo
.li_min_insn_length
;
4585 state_machine_regs
.address
+= uladv
;
4587 state_machine_regs
.view
= 0;
4588 printf (_(" Special opcode %d: "
4589 "advance Address by %s to 0x%s%s"),
4590 op_code
, dwarf_vmatoa ("u", uladv
),
4591 dwarf_vmatoa ("x", state_machine_regs
.address
),
4592 verbose_view
&& uladv
4593 ? _(" (reset view)") : "");
4598 = ((state_machine_regs
.op_index
+ uladv
)
4599 / linfo
.li_max_ops_per_insn
)
4600 * linfo
.li_min_insn_length
;
4602 state_machine_regs
.address
+= addrdelta
;
4603 state_machine_regs
.op_index
4604 = (state_machine_regs
.op_index
+ uladv
)
4605 % linfo
.li_max_ops_per_insn
;
4607 state_machine_regs
.view
= 0;
4608 printf (_(" Special opcode %d: "
4609 "advance Address by %s to 0x%s[%d]%s"),
4610 op_code
, dwarf_vmatoa ("u", uladv
),
4611 dwarf_vmatoa ("x", state_machine_regs
.address
),
4612 state_machine_regs
.op_index
,
4613 verbose_view
&& addrdelta
4614 ? _(" (reset view)") : "");
4616 adv
= (op_code
% linfo
.li_line_range
) + linfo
.li_line_base
;
4617 state_machine_regs
.line
+= adv
;
4618 printf (_(" and Line by %s to %d"),
4619 dwarf_vmatoa ("d", adv
), state_machine_regs
.line
);
4620 if (verbose_view
|| state_machine_regs
.view
)
4621 printf (_(" (view %u)\n"), state_machine_regs
.view
);
4624 state_machine_regs
.view
++;
4629 case DW_LNS_extended_op
:
4630 data
+= process_extended_line_op (data
,
4631 linfo
.li_default_is_stmt
,
4636 printf (_(" Copy"));
4637 if (verbose_view
|| state_machine_regs
.view
)
4638 printf (_(" (view %u)\n"), state_machine_regs
.view
);
4641 state_machine_regs
.view
++;
4644 case DW_LNS_advance_pc
:
4645 READ_ULEB (uladv
, data
, end
);
4646 if (linfo
.li_max_ops_per_insn
== 1)
4648 uladv
*= linfo
.li_min_insn_length
;
4649 state_machine_regs
.address
+= uladv
;
4651 state_machine_regs
.view
= 0;
4652 printf (_(" Advance PC by %s to 0x%s%s\n"),
4653 dwarf_vmatoa ("u", uladv
),
4654 dwarf_vmatoa ("x", state_machine_regs
.address
),
4655 verbose_view
&& uladv
4656 ? _(" (reset view)") : "");
4661 = ((state_machine_regs
.op_index
+ uladv
)
4662 / linfo
.li_max_ops_per_insn
)
4663 * linfo
.li_min_insn_length
;
4664 state_machine_regs
.address
4666 state_machine_regs
.op_index
4667 = (state_machine_regs
.op_index
+ uladv
)
4668 % linfo
.li_max_ops_per_insn
;
4670 state_machine_regs
.view
= 0;
4671 printf (_(" Advance PC by %s to 0x%s[%d]%s\n"),
4672 dwarf_vmatoa ("u", uladv
),
4673 dwarf_vmatoa ("x", state_machine_regs
.address
),
4674 state_machine_regs
.op_index
,
4675 verbose_view
&& addrdelta
4676 ? _(" (reset view)") : "");
4680 case DW_LNS_advance_line
:
4681 READ_SLEB (adv
, data
, end
);
4682 state_machine_regs
.line
+= adv
;
4683 printf (_(" Advance Line by %s to %d\n"),
4684 dwarf_vmatoa ("d", adv
),
4685 state_machine_regs
.line
);
4688 case DW_LNS_set_file
:
4689 READ_ULEB (uladv
, data
, end
);
4690 printf (_(" Set File Name to entry %s in the File Name Table\n"),
4691 dwarf_vmatoa ("u", uladv
));
4692 state_machine_regs
.file
= uladv
;
4695 case DW_LNS_set_column
:
4696 READ_ULEB (uladv
, data
, end
);
4697 printf (_(" Set column to %s\n"),
4698 dwarf_vmatoa ("u", uladv
));
4699 state_machine_regs
.column
= uladv
;
4702 case DW_LNS_negate_stmt
:
4703 adv
= state_machine_regs
.is_stmt
;
4705 printf (_(" Set is_stmt to %s\n"), dwarf_vmatoa ("d", adv
));
4706 state_machine_regs
.is_stmt
= adv
;
4709 case DW_LNS_set_basic_block
:
4710 printf (_(" Set basic block\n"));
4711 state_machine_regs
.basic_block
= 1;
4714 case DW_LNS_const_add_pc
:
4715 uladv
= ((255 - linfo
.li_opcode_base
) / linfo
.li_line_range
);
4716 if (linfo
.li_max_ops_per_insn
)
4718 uladv
*= linfo
.li_min_insn_length
;
4719 state_machine_regs
.address
+= uladv
;
4721 state_machine_regs
.view
= 0;
4722 printf (_(" Advance PC by constant %s to 0x%s%s\n"),
4723 dwarf_vmatoa ("u", uladv
),
4724 dwarf_vmatoa ("x", state_machine_regs
.address
),
4725 verbose_view
&& uladv
4726 ? _(" (reset view)") : "");
4731 = ((state_machine_regs
.op_index
+ uladv
)
4732 / linfo
.li_max_ops_per_insn
)
4733 * linfo
.li_min_insn_length
;
4734 state_machine_regs
.address
4736 state_machine_regs
.op_index
4737 = (state_machine_regs
.op_index
+ uladv
)
4738 % linfo
.li_max_ops_per_insn
;
4740 state_machine_regs
.view
= 0;
4741 printf (_(" Advance PC by constant %s to 0x%s[%d]%s\n"),
4742 dwarf_vmatoa ("u", uladv
),
4743 dwarf_vmatoa ("x", state_machine_regs
.address
),
4744 state_machine_regs
.op_index
,
4745 verbose_view
&& addrdelta
4746 ? _(" (reset view)") : "");
4750 case DW_LNS_fixed_advance_pc
:
4751 SAFE_BYTE_GET_AND_INC (uladv
, data
, 2, end
);
4752 state_machine_regs
.address
+= uladv
;
4753 state_machine_regs
.op_index
= 0;
4754 printf (_(" Advance PC by fixed size amount %s to 0x%s\n"),
4755 dwarf_vmatoa ("u", uladv
),
4756 dwarf_vmatoa ("x", state_machine_regs
.address
));
4757 /* Do NOT reset view. */
4760 case DW_LNS_set_prologue_end
:
4761 printf (_(" Set prologue_end to true\n"));
4764 case DW_LNS_set_epilogue_begin
:
4765 printf (_(" Set epilogue_begin to true\n"));
4768 case DW_LNS_set_isa
:
4769 READ_ULEB (uladv
, data
, end
);
4770 printf (_(" Set ISA to %s\n"), dwarf_vmatoa ("u", uladv
));
4774 printf (_(" Unknown opcode %d with operands: "), op_code
);
4776 if (standard_opcodes
!= NULL
)
4777 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
4779 READ_ULEB (uladv
, data
, end
);
4780 printf ("0x%s%s", dwarf_vmatoa ("x", uladv
),
4781 i
== 1 ? "" : ", ");
4796 unsigned char *name
;
4797 unsigned int directory_index
;
4798 unsigned int modification_date
;
4799 unsigned int length
;
4802 /* Output a decoded representation of the .debug_line section. */
4805 display_debug_lines_decoded (struct dwarf_section
* section
,
4806 unsigned char * start
,
4807 unsigned char * data
,
4808 unsigned char * end
,
4811 static DWARF2_Internal_LineInfo saved_linfo
;
4813 introduce (section
, false);
4817 /* This loop amounts to one iteration per compilation unit. */
4818 DWARF2_Internal_LineInfo linfo
;
4819 unsigned char *standard_opcodes
;
4820 unsigned char *end_of_sequence
;
4822 File_Entry
*file_table
= NULL
;
4823 unsigned int n_files
= 0;
4824 unsigned char **directory_table
= NULL
;
4825 dwarf_vma n_directories
= 0;
4827 if (startswith (section
->name
, ".debug_line.")
4828 /* Note: the following does not apply to .debug_line.dwo sections.
4829 These are full debug_line sections. */
4830 && strcmp (section
->name
, ".debug_line.dwo") != 0)
4832 /* See comment in display_debug_lines_raw(). */
4833 end_of_sequence
= end
;
4834 standard_opcodes
= NULL
;
4835 linfo
= saved_linfo
;
4836 /* PR 17531: file: 0522b371. */
4837 if (linfo
.li_line_range
== 0)
4839 warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n"));
4842 reset_state_machine (linfo
.li_default_is_stmt
);
4846 unsigned char *hdrptr
;
4848 if ((hdrptr
= read_debug_line_header (section
, data
, end
, & linfo
,
4849 & end_of_sequence
)) == NULL
)
4852 /* PR 17531: file: 0522b371. */
4853 if (linfo
.li_line_range
== 0)
4855 warn (_("Line range of 0 is invalid, using 1 instead\n"));
4856 linfo
.li_line_range
= 1;
4858 reset_state_machine (linfo
.li_default_is_stmt
);
4860 /* Save a pointer to the contents of the Opcodes table. */
4861 standard_opcodes
= hdrptr
;
4863 /* Traverse the Directory table just to count entries. */
4864 data
= standard_opcodes
+ linfo
.li_opcode_base
- 1;
4868 warn (_("opcode base of %d extends beyond end of section\n"),
4869 linfo
.li_opcode_base
);
4873 if (linfo
.li_version
>= 5)
4875 unsigned char *format_start
, format_count
, *format
;
4876 dwarf_vma formati
, entryi
;
4878 load_debug_section_with_follow (line_str
, fileptr
);
4880 /* Skip directories format. */
4881 SAFE_BYTE_GET_AND_INC (format_count
, data
, 1, end
);
4882 if (do_checks
&& format_count
> 1)
4883 warn (_("Unexpectedly large number of columns in the directory name table (%u)\n"),
4885 format_start
= data
;
4886 for (formati
= 0; formati
< format_count
; formati
++)
4888 SKIP_ULEB (data
, end
);
4889 SKIP_ULEB (data
, end
);
4892 READ_ULEB (n_directories
, data
, end
);
4895 warn (_("Corrupt directories list\n"));
4899 if (n_directories
== 0)
4900 directory_table
= NULL
;
4902 directory_table
= (unsigned char **)
4903 xmalloc (n_directories
* sizeof (unsigned char *));
4905 for (entryi
= 0; entryi
< n_directories
; entryi
++)
4907 unsigned char **pathp
= &directory_table
[entryi
];
4909 format
= format_start
;
4910 for (formati
= 0; formati
< format_count
; formati
++)
4912 dwarf_vma content_type
, form
;
4915 READ_ULEB (content_type
, format
, end
);
4916 READ_ULEB (form
, format
, end
);
4919 warn (_("Corrupt directories list\n"));
4922 switch (content_type
)
4927 case DW_FORM_string
:
4930 case DW_FORM_line_strp
:
4931 SAFE_BYTE_GET (uvalue
, data
, linfo
.li_offset_size
,
4933 /* Remove const by the cast. */
4934 *pathp
= (unsigned char *)
4935 fetch_indirect_line_string (uvalue
);
4940 data
= read_and_display_attr_value (0, form
, 0, start
,
4942 linfo
.li_offset_size
,
4949 warn (_("Corrupt directories list\n"));
4954 /* Skip files format. */
4955 SAFE_BYTE_GET_AND_INC (format_count
, data
, 1, end
);
4956 if (do_checks
&& format_count
> 5)
4957 warn (_("Unexpectedly large number of columns in the file name table (%u)\n"),
4959 format_start
= data
;
4960 for (formati
= 0; formati
< format_count
; formati
++)
4962 SKIP_ULEB (data
, end
);
4963 SKIP_ULEB (data
, end
);
4966 READ_ULEB (n_files
, data
, end
);
4967 if (data
>= end
&& n_files
> 0)
4969 warn (_("Corrupt file name list\n"));
4976 file_table
= (File_Entry
*) xcalloc (1, n_files
4977 * sizeof (File_Entry
));
4979 for (entryi
= 0; entryi
< n_files
; entryi
++)
4981 File_Entry
*file
= &file_table
[entryi
];
4983 format
= format_start
;
4984 for (formati
= 0; formati
< format_count
; formati
++)
4986 dwarf_vma content_type
, form
;
4990 READ_ULEB (content_type
, format
, end
);
4991 READ_ULEB (form
, format
, end
);
4994 warn (_("Corrupt file name list\n"));
4997 switch (content_type
)
5002 case DW_FORM_string
:
5005 case DW_FORM_line_strp
:
5006 SAFE_BYTE_GET (uvalue
, data
, linfo
.li_offset_size
,
5008 /* Remove const by the cast. */
5009 file
->name
= (unsigned char *)
5010 fetch_indirect_line_string (uvalue
);
5014 case DW_LNCT_directory_index
:
5018 SAFE_BYTE_GET (file
->directory_index
, data
, 1,
5022 SAFE_BYTE_GET (file
->directory_index
, data
, 2,
5027 READ_ULEB (file
->directory_index
, tmp
, end
);
5032 data
= read_and_display_attr_value (0, form
, 0, start
,
5034 linfo
.li_offset_size
,
5041 warn (_("Corrupt file name list\n"));
5050 unsigned char *ptr_directory_table
= data
;
5052 while (data
< end
&& *data
!= 0)
5054 data
+= strnlen ((char *) data
, end
- data
);
5063 warn (_("directory table ends unexpectedly\n"));
5068 /* Go through the directory table again to save the directories. */
5069 directory_table
= (unsigned char **)
5070 xmalloc (n_directories
* sizeof (unsigned char *));
5073 while (*ptr_directory_table
!= 0)
5075 directory_table
[i
] = ptr_directory_table
;
5076 ptr_directory_table
+= strnlen ((char *) ptr_directory_table
,
5077 ptr_directory_table
- end
) + 1;
5081 /* Skip the NUL at the end of the table. */
5084 /* Traverse the File Name table just to count the entries. */
5085 if (data
< end
&& *data
!= 0)
5087 unsigned char *ptr_file_name_table
= data
;
5089 while (data
< end
&& *data
!= 0)
5091 /* Skip Name, directory index, last modification
5092 time and length of file. */
5093 data
+= strnlen ((char *) data
, end
- data
);
5096 SKIP_ULEB (data
, end
);
5097 SKIP_ULEB (data
, end
);
5098 SKIP_ULEB (data
, end
);
5104 warn (_("file table ends unexpectedly\n"));
5109 /* Go through the file table again to save the strings. */
5110 file_table
= (File_Entry
*) xmalloc (n_files
* sizeof (File_Entry
));
5113 while (*ptr_file_name_table
!= 0)
5115 file_table
[i
].name
= ptr_file_name_table
;
5116 ptr_file_name_table
+= strnlen ((char *) ptr_file_name_table
,
5117 end
- ptr_file_name_table
) + 1;
5119 /* We are not interested in directory, time or size. */
5120 READ_ULEB (file_table
[i
].directory_index
,
5121 ptr_file_name_table
, end
);
5122 READ_ULEB (file_table
[i
].modification_date
,
5123 ptr_file_name_table
, end
);
5124 READ_ULEB (file_table
[i
].length
,
5125 ptr_file_name_table
, end
);
5131 /* Skip the NUL at the end of the table. */
5135 /* Print the Compilation Unit's name and a header. */
5136 if (file_table
== NULL
)
5137 printf (_("CU: No directory table\n"));
5138 else if (directory_table
== NULL
)
5139 printf (_("CU: %s:\n"), file_table
[0].name
);
5142 unsigned int ix
= file_table
[0].directory_index
;
5143 const char *directory
;
5148 else if (n_directories
== 0)
5149 directory
= _("<unknown>");
5150 else if (ix
> n_directories
)
5152 warn (_("directory index %u > number of directories %s\n"),
5153 ix
, dwarf_vmatoa ("u", n_directories
));
5154 directory
= _("<corrupt>");
5157 directory
= (char *) directory_table
[ix
- 1];
5159 if (do_wide
|| strlen (directory
) < 76)
5160 printf (_("CU: %s/%s:\n"), directory
, file_table
[0].name
);
5162 printf ("%s:\n", file_table
[0].name
);
5166 printf (_("File name Line number Starting address View Stmt\n"));
5168 printf (_("CU: Empty file name table\n"));
5169 saved_linfo
= linfo
;
5172 /* This loop iterates through the Dwarf Line Number Program. */
5173 while (data
< end_of_sequence
)
5175 unsigned char op_code
;
5178 unsigned long int uladv
;
5179 int is_special_opcode
= 0;
5184 if (op_code
>= linfo
.li_opcode_base
)
5186 op_code
-= linfo
.li_opcode_base
;
5187 uladv
= (op_code
/ linfo
.li_line_range
);
5188 if (linfo
.li_max_ops_per_insn
== 1)
5190 uladv
*= linfo
.li_min_insn_length
;
5191 state_machine_regs
.address
+= uladv
;
5193 state_machine_regs
.view
= 0;
5198 = ((state_machine_regs
.op_index
+ uladv
)
5199 / linfo
.li_max_ops_per_insn
)
5200 * linfo
.li_min_insn_length
;
5201 state_machine_regs
.address
5203 state_machine_regs
.op_index
5204 = (state_machine_regs
.op_index
+ uladv
)
5205 % linfo
.li_max_ops_per_insn
;
5207 state_machine_regs
.view
= 0;
5210 adv
= (op_code
% linfo
.li_line_range
) + linfo
.li_line_base
;
5211 state_machine_regs
.line
+= adv
;
5212 is_special_opcode
= 1;
5213 /* Increment view after printing this row. */
5218 case DW_LNS_extended_op
:
5220 unsigned int ext_op_code_len
;
5221 unsigned char ext_op_code
;
5222 unsigned char *op_code_end
;
5223 unsigned char *op_code_data
= data
;
5225 READ_ULEB (ext_op_code_len
, op_code_data
, end_of_sequence
);
5226 op_code_end
= op_code_data
+ ext_op_code_len
;
5227 if (ext_op_code_len
== 0 || op_code_end
> end_of_sequence
)
5229 warn (_("Badly formed extended line op encountered!\n"));
5232 ext_op_code
= *op_code_data
++;
5236 switch (ext_op_code
)
5238 case DW_LNE_end_sequence
:
5239 /* Reset stuff after printing this row. */
5241 case DW_LNE_set_address
:
5242 SAFE_BYTE_GET_AND_INC (state_machine_regs
.address
,
5244 op_code_end
- op_code_data
,
5246 state_machine_regs
.op_index
= 0;
5247 state_machine_regs
.view
= 0;
5249 case DW_LNE_define_file
:
5250 file_table
= (File_Entry
*) xrealloc
5251 (file_table
, (n_files
+ 1) * sizeof (File_Entry
));
5253 ++state_machine_regs
.last_file_entry
;
5254 /* Source file name. */
5255 file_table
[n_files
].name
= op_code_data
;
5256 op_code_data
+= strlen ((char *) op_code_data
) + 1;
5257 /* Directory index. */
5258 READ_ULEB (file_table
[n_files
].directory_index
,
5259 op_code_data
, op_code_end
);
5260 /* Last modification time. */
5261 READ_ULEB (file_table
[n_files
].modification_date
,
5262 op_code_data
, op_code_end
);
5264 READ_ULEB (file_table
[n_files
].length
,
5265 op_code_data
, op_code_end
);
5269 case DW_LNE_set_discriminator
:
5270 case DW_LNE_HP_set_sequence
:
5271 /* Simply ignored. */
5275 printf (_("UNKNOWN (%u): length %ld\n"),
5276 ext_op_code
, (long int) (op_code_data
- data
));
5283 /* Increment view after printing this row. */
5286 case DW_LNS_advance_pc
:
5287 READ_ULEB (uladv
, data
, end
);
5288 if (linfo
.li_max_ops_per_insn
== 1)
5290 uladv
*= linfo
.li_min_insn_length
;
5291 state_machine_regs
.address
+= uladv
;
5293 state_machine_regs
.view
= 0;
5298 = ((state_machine_regs
.op_index
+ uladv
)
5299 / linfo
.li_max_ops_per_insn
)
5300 * linfo
.li_min_insn_length
;
5301 state_machine_regs
.address
5303 state_machine_regs
.op_index
5304 = (state_machine_regs
.op_index
+ uladv
)
5305 % linfo
.li_max_ops_per_insn
;
5307 state_machine_regs
.view
= 0;
5311 case DW_LNS_advance_line
:
5312 READ_SLEB (adv
, data
, end
);
5313 state_machine_regs
.line
+= adv
;
5316 case DW_LNS_set_file
:
5317 READ_ULEB (uladv
, data
, end
);
5318 state_machine_regs
.file
= uladv
;
5321 unsigned file
= state_machine_regs
.file
- 1;
5324 if (file_table
== NULL
|| n_files
== 0)
5325 printf (_("\n [Use file table entry %d]\n"), file
);
5327 else if (file
>= n_files
)
5329 warn (_("file index %u > number of files %u\n"), file
+ 1, n_files
);
5330 printf (_("\n <over large file table index %u>"), file
);
5332 else if ((dir
= file_table
[file
].directory_index
) == 0)
5333 /* If directory index is 0, that means current directory. */
5334 printf ("\n./%s:[++]\n", file_table
[file
].name
);
5335 else if (directory_table
== NULL
|| n_directories
== 0)
5336 printf (_("\n [Use file %s in directory table entry %d]\n"),
5337 file_table
[file
].name
, dir
);
5339 else if (dir
> n_directories
)
5341 warn (_("directory index %u > number of directories %s\n"),
5342 dir
, dwarf_vmatoa ("u", n_directories
));
5343 printf (_("\n <over large directory table entry %u>\n"), dir
);
5346 printf ("\n%s/%s:\n",
5347 /* The directory index starts counting at 1. */
5348 directory_table
[dir
- 1], file_table
[file
].name
);
5352 case DW_LNS_set_column
:
5353 READ_ULEB (uladv
, data
, end
);
5354 state_machine_regs
.column
= uladv
;
5357 case DW_LNS_negate_stmt
:
5358 adv
= state_machine_regs
.is_stmt
;
5360 state_machine_regs
.is_stmt
= adv
;
5363 case DW_LNS_set_basic_block
:
5364 state_machine_regs
.basic_block
= 1;
5367 case DW_LNS_const_add_pc
:
5368 uladv
= ((255 - linfo
.li_opcode_base
) / linfo
.li_line_range
);
5369 if (linfo
.li_max_ops_per_insn
== 1)
5371 uladv
*= linfo
.li_min_insn_length
;
5372 state_machine_regs
.address
+= uladv
;
5374 state_machine_regs
.view
= 0;
5379 = ((state_machine_regs
.op_index
+ uladv
)
5380 / linfo
.li_max_ops_per_insn
)
5381 * linfo
.li_min_insn_length
;
5382 state_machine_regs
.address
5384 state_machine_regs
.op_index
5385 = (state_machine_regs
.op_index
+ uladv
)
5386 % linfo
.li_max_ops_per_insn
;
5388 state_machine_regs
.view
= 0;
5392 case DW_LNS_fixed_advance_pc
:
5393 SAFE_BYTE_GET_AND_INC (uladv
, data
, 2, end
);
5394 state_machine_regs
.address
+= uladv
;
5395 state_machine_regs
.op_index
= 0;
5396 /* Do NOT reset view. */
5399 case DW_LNS_set_prologue_end
:
5402 case DW_LNS_set_epilogue_begin
:
5405 case DW_LNS_set_isa
:
5406 READ_ULEB (uladv
, data
, end
);
5407 printf (_(" Set ISA to %lu\n"), uladv
);
5411 printf (_(" Unknown opcode %d with operands: "), op_code
);
5413 if (standard_opcodes
!= NULL
)
5414 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
5418 READ_ULEB (val
, data
, end
);
5419 printf ("0x%s%s", dwarf_vmatoa ("x", val
),
5420 i
== 1 ? "" : ", ");
5426 /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row
5427 to the DWARF address/line matrix. */
5428 if ((is_special_opcode
) || (xop
== -DW_LNE_end_sequence
)
5429 || (xop
== DW_LNS_copy
))
5431 const unsigned int MAX_FILENAME_LENGTH
= 35;
5433 char *newFileName
= NULL
;
5434 size_t fileNameLength
;
5438 unsigned indx
= state_machine_regs
.file
- 1;
5440 if (indx
>= n_files
)
5442 warn (_("corrupt file index %u encountered\n"), indx
);
5443 fileName
= _("<corrupt>");
5446 fileName
= (char *) file_table
[indx
].name
;
5449 fileName
= _("<unknown>");
5451 fileNameLength
= strlen (fileName
);
5453 if ((fileNameLength
> MAX_FILENAME_LENGTH
) && (!do_wide
))
5455 newFileName
= (char *) xmalloc (MAX_FILENAME_LENGTH
+ 1);
5456 /* Truncate file name */
5457 strncpy (newFileName
,
5458 fileName
+ fileNameLength
- MAX_FILENAME_LENGTH
,
5459 MAX_FILENAME_LENGTH
+ 1);
5460 /* FIXME: This is to pacify gcc-10 which can warn that the
5461 strncpy above might leave a non-NUL terminated string
5462 in newFileName. It won't, but gcc's analysis doesn't
5463 quite go far enough to discover this. */
5464 newFileName
[MAX_FILENAME_LENGTH
] = 0;
5468 newFileName
= (char *) xmalloc (fileNameLength
+ 1);
5469 strncpy (newFileName
, fileName
, fileNameLength
+ 1);
5472 /* A row with end_seq set to true has a meaningful address, but
5473 the other information in the same row is not significant.
5474 In such a row, print line as "-", and don't print
5476 if (!do_wide
|| (fileNameLength
<= MAX_FILENAME_LENGTH
))
5478 if (linfo
.li_max_ops_per_insn
== 1)
5480 if (xop
== -DW_LNE_end_sequence
)
5481 printf ("%-35s %11s %#18" DWARF_VMA_FMT
"x",
5483 state_machine_regs
.address
);
5485 printf ("%-35s %11d %#18" DWARF_VMA_FMT
"x",
5486 newFileName
, state_machine_regs
.line
,
5487 state_machine_regs
.address
);
5491 if (xop
== -DW_LNE_end_sequence
)
5492 printf ("%-35s %11s %#18" DWARF_VMA_FMT
"x[%d]",
5494 state_machine_regs
.address
,
5495 state_machine_regs
.op_index
);
5497 printf ("%-35s %11d %#18" DWARF_VMA_FMT
"x[%d]",
5498 newFileName
, state_machine_regs
.line
,
5499 state_machine_regs
.address
,
5500 state_machine_regs
.op_index
);
5505 if (linfo
.li_max_ops_per_insn
== 1)
5507 if (xop
== -DW_LNE_end_sequence
)
5508 printf ("%s %11s %#18" DWARF_VMA_FMT
"x",
5510 state_machine_regs
.address
);
5512 printf ("%s %11d %#18" DWARF_VMA_FMT
"x",
5513 newFileName
, state_machine_regs
.line
,
5514 state_machine_regs
.address
);
5518 if (xop
== -DW_LNE_end_sequence
)
5519 printf ("%s %11s %#18" DWARF_VMA_FMT
"x[%d]",
5521 state_machine_regs
.address
,
5522 state_machine_regs
.op_index
);
5524 printf ("%s %11d %#18" DWARF_VMA_FMT
"x[%d]",
5525 newFileName
, state_machine_regs
.line
,
5526 state_machine_regs
.address
,
5527 state_machine_regs
.op_index
);
5531 if (xop
!= -DW_LNE_end_sequence
)
5533 if (state_machine_regs
.view
)
5534 printf (" %6u", state_machine_regs
.view
);
5538 if (state_machine_regs
.is_stmt
)
5543 state_machine_regs
.view
++;
5545 if (xop
== -DW_LNE_end_sequence
)
5547 reset_state_machine (linfo
.li_default_is_stmt
);
5562 if (directory_table
)
5564 free (directory_table
);
5565 directory_table
= NULL
;
5576 display_debug_lines (struct dwarf_section
*section
, void *file
)
5578 unsigned char *data
= section
->start
;
5579 unsigned char *end
= data
+ section
->size
;
5581 int retValDecoded
= 1;
5583 if (do_debug_lines
== 0)
5584 do_debug_lines
|= FLAG_DEBUG_LINES_RAW
;
5586 if (do_debug_lines
& FLAG_DEBUG_LINES_RAW
)
5587 retValRaw
= display_debug_lines_raw (section
, data
, end
, file
);
5589 if (do_debug_lines
& FLAG_DEBUG_LINES_DECODED
)
5590 retValDecoded
= display_debug_lines_decoded (section
, data
, data
, end
, file
);
5592 if (!retValRaw
|| !retValDecoded
)
5599 find_debug_info_for_offset (unsigned long offset
)
5603 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
5606 for (i
= 0; i
< num_debug_info_entries
; i
++)
5607 if (debug_information
[i
].cu_offset
== offset
)
5608 return debug_information
+ i
;
5614 get_gdb_index_symbol_kind_name (gdb_index_symbol_kind kind
)
5616 /* See gdb/gdb-index.h. */
5617 static const char * const kinds
[] =
5629 return _ (kinds
[kind
]);
5633 display_debug_pubnames_worker (struct dwarf_section
*section
,
5634 void *file ATTRIBUTE_UNUSED
,
5637 DWARF2_Internal_PubNames names
;
5638 unsigned char *start
= section
->start
;
5639 unsigned char *end
= start
+ section
->size
;
5641 /* It does not matter if this load fails,
5642 we test for that later on. */
5643 load_debug_info (file
);
5645 introduce (section
, false);
5649 unsigned char *data
;
5650 unsigned long sec_off
;
5651 unsigned int offset_size
, initial_length_size
;
5653 SAFE_BYTE_GET_AND_INC (names
.pn_length
, start
, 4, end
);
5654 if (names
.pn_length
== 0xffffffff)
5656 SAFE_BYTE_GET_AND_INC (names
.pn_length
, start
, 8, end
);
5658 initial_length_size
= 12;
5663 initial_length_size
= 4;
5666 sec_off
= start
- section
->start
;
5667 if (sec_off
+ names
.pn_length
< sec_off
5668 || sec_off
+ names
.pn_length
> section
->size
)
5670 warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"),
5672 sec_off
- initial_length_size
,
5673 dwarf_vmatoa ("x", names
.pn_length
));
5678 start
+= names
.pn_length
;
5680 SAFE_BYTE_GET_AND_INC (names
.pn_version
, data
, 2, end
);
5681 SAFE_BYTE_GET_AND_INC (names
.pn_offset
, data
, offset_size
, end
);
5683 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
5684 && num_debug_info_entries
> 0
5685 && find_debug_info_for_offset (names
.pn_offset
) == NULL
)
5686 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
5687 (unsigned long) names
.pn_offset
, section
->name
);
5689 SAFE_BYTE_GET_AND_INC (names
.pn_size
, data
, offset_size
, end
);
5691 printf (_(" Length: %ld\n"),
5692 (long) names
.pn_length
);
5693 printf (_(" Version: %d\n"),
5695 printf (_(" Offset into .debug_info section: 0x%lx\n"),
5696 (unsigned long) names
.pn_offset
);
5697 printf (_(" Size of area in .debug_info section: %ld\n"),
5698 (long) names
.pn_size
);
5700 if (names
.pn_version
!= 2 && names
.pn_version
!= 3)
5702 static int warned
= 0;
5706 warn (_("Only DWARF 2 and 3 pubnames are currently supported\n"));
5714 printf (_("\n Offset Kind Name\n"));
5716 printf (_("\n Offset\tName\n"));
5720 bfd_size_type maxprint
;
5723 SAFE_BYTE_GET_AND_INC (offset
, data
, offset_size
, end
);
5730 maxprint
= (end
- data
) - 1;
5734 unsigned int kind_data
;
5735 gdb_index_symbol_kind kind
;
5736 const char *kind_name
;
5739 SAFE_BYTE_GET_AND_INC (kind_data
, data
, 1, end
);
5741 /* GCC computes the kind as the upper byte in the CU index
5742 word, and then right shifts it by the CU index size.
5743 Left shift KIND to where the gdb-index.h accessor macros
5745 kind_data
<<= GDB_INDEX_CU_BITSIZE
;
5746 kind
= GDB_INDEX_SYMBOL_KIND_VALUE (kind_data
);
5747 kind_name
= get_gdb_index_symbol_kind_name (kind
);
5748 is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (kind_data
);
5749 printf (" %-6lx %s,%-10s %.*s\n",
5750 (unsigned long) offset
, is_static
? _("s") : _("g"),
5751 kind_name
, (int) maxprint
, data
);
5754 printf (" %-6lx\t%.*s\n",
5755 (unsigned long) offset
, (int) maxprint
, data
);
5757 data
+= strnlen ((char *) data
, maxprint
);
5770 display_debug_pubnames (struct dwarf_section
*section
, void *file
)
5772 return display_debug_pubnames_worker (section
, file
, 0);
5776 display_debug_gnu_pubnames (struct dwarf_section
*section
, void *file
)
5778 return display_debug_pubnames_worker (section
, file
, 1);
5782 display_debug_macinfo (struct dwarf_section
*section
,
5783 void *file ATTRIBUTE_UNUSED
)
5785 unsigned char *start
= section
->start
;
5786 unsigned char *end
= start
+ section
->size
;
5787 unsigned char *curr
= start
;
5788 enum dwarf_macinfo_record_type op
;
5790 introduce (section
, false);
5794 unsigned int lineno
;
5795 const unsigned char *string
;
5797 op
= (enum dwarf_macinfo_record_type
) *curr
;
5802 case DW_MACINFO_start_file
:
5804 unsigned int filenum
;
5806 READ_ULEB (lineno
, curr
, end
);
5807 READ_ULEB (filenum
, curr
, end
);
5808 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"),
5813 case DW_MACINFO_end_file
:
5814 printf (_(" DW_MACINFO_end_file\n"));
5817 case DW_MACINFO_define
:
5818 READ_ULEB (lineno
, curr
, end
);
5820 curr
+= strnlen ((char *) string
, end
- string
) + 1;
5821 printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"),
5825 case DW_MACINFO_undef
:
5826 READ_ULEB (lineno
, curr
, end
);
5828 curr
+= strnlen ((char *) string
, end
- string
) + 1;
5829 printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"),
5833 case DW_MACINFO_vendor_ext
:
5835 unsigned int constant
;
5837 READ_ULEB (constant
, curr
, end
);
5839 curr
+= strnlen ((char *) string
, end
- string
) + 1;
5840 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"),
5850 /* Given LINE_OFFSET into the .debug_line section, attempt to return
5851 filename and dirname corresponding to file name table entry with index
5852 FILEIDX. Return NULL on failure. */
5854 static unsigned char *
5855 get_line_filename_and_dirname (dwarf_vma line_offset
,
5857 unsigned char **dir_name
)
5859 struct dwarf_section
*section
= &debug_displays
[line
].section
;
5860 unsigned char *hdrptr
, *dirtable
, *file_name
;
5861 unsigned int offset_size
, initial_length_size
;
5862 unsigned int version
, opcode_base
;
5863 dwarf_vma length
, diridx
;
5864 const unsigned char * end
;
5867 if (section
->start
== NULL
5868 || line_offset
>= section
->size
5872 hdrptr
= section
->start
+ line_offset
;
5873 end
= section
->start
+ section
->size
;
5875 SAFE_BYTE_GET_AND_INC (length
, hdrptr
, 4, end
);
5876 if (length
== 0xffffffff)
5878 /* This section is 64-bit DWARF 3. */
5879 SAFE_BYTE_GET_AND_INC (length
, hdrptr
, 8, end
);
5881 initial_length_size
= 12;
5886 initial_length_size
= 4;
5888 if (length
+ initial_length_size
< length
5889 || length
+ initial_length_size
> section
->size
)
5892 SAFE_BYTE_GET_AND_INC (version
, hdrptr
, 2, end
);
5893 if (version
!= 2 && version
!= 3 && version
!= 4)
5895 hdrptr
+= offset_size
+ 1;/* Skip prologue_length and min_insn_length. */
5897 hdrptr
++; /* Skip max_ops_per_insn. */
5898 hdrptr
+= 3; /* Skip default_is_stmt, line_base, line_range. */
5900 SAFE_BYTE_GET_AND_INC (opcode_base
, hdrptr
, 1, end
);
5901 if (opcode_base
== 0)
5904 hdrptr
+= opcode_base
- 1;
5909 /* Skip over dirname table. */
5910 while (*hdrptr
!= '\0')
5912 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
) + 1;
5916 hdrptr
++; /* Skip the NUL at the end of the table. */
5918 /* Now skip over preceding filename table entries. */
5919 for (; hdrptr
< end
&& *hdrptr
!= '\0' && fileidx
> 1; fileidx
--)
5921 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
) + 1;
5922 SKIP_ULEB (hdrptr
, end
);
5923 SKIP_ULEB (hdrptr
, end
);
5924 SKIP_ULEB (hdrptr
, end
);
5926 if (hdrptr
>= end
|| *hdrptr
== '\0')
5930 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
) + 1;
5933 READ_ULEB (diridx
, hdrptr
, end
);
5936 for (; dirtable
< end
&& *dirtable
!= '\0' && diridx
> 1; diridx
--)
5937 dirtable
+= strnlen ((char *) dirtable
, end
- dirtable
) + 1;
5938 if (dirtable
>= end
|| *dirtable
== '\0')
5940 *dir_name
= dirtable
;
5945 display_debug_macro (struct dwarf_section
*section
,
5948 unsigned char *start
= section
->start
;
5949 unsigned char *end
= start
+ section
->size
;
5950 unsigned char *curr
= start
;
5951 unsigned char *extended_op_buf
[256];
5952 bool is_dwo
= false;
5953 const char *suffix
= strrchr (section
->name
, '.');
5955 if (suffix
&& strcmp (suffix
, ".dwo") == 0)
5958 load_debug_section_with_follow (str
, file
);
5959 load_debug_section_with_follow (line
, file
);
5960 load_debug_section_with_follow (str_index
, file
);
5962 introduce (section
, false);
5966 unsigned int lineno
, version
, flags
;
5967 unsigned int offset_size
;
5968 const unsigned char *string
;
5969 dwarf_vma line_offset
= 0, sec_offset
= curr
- start
, offset
;
5970 unsigned char **extended_ops
= NULL
;
5972 SAFE_BYTE_GET_AND_INC (version
, curr
, 2, end
);
5973 if (version
!= 4 && version
!= 5)
5975 error (_("Expected to find a version number of 4 or 5 in section %s but found %d instead\n"),
5976 section
->name
, version
);
5980 SAFE_BYTE_GET_AND_INC (flags
, curr
, 1, end
);
5981 offset_size
= (flags
& 1) ? 8 : 4;
5982 printf (_(" Offset: 0x%lx\n"),
5983 (unsigned long) sec_offset
);
5984 printf (_(" Version: %d\n"), version
);
5985 printf (_(" Offset size: %d\n"), offset_size
);
5988 SAFE_BYTE_GET_AND_INC (line_offset
, curr
, offset_size
, end
);
5989 printf (_(" Offset into .debug_line: 0x%lx\n"),
5990 (unsigned long) line_offset
);
5994 unsigned int i
, count
, op
;
5997 SAFE_BYTE_GET_AND_INC (count
, curr
, 1, end
);
5999 memset (extended_op_buf
, 0, sizeof (extended_op_buf
));
6000 extended_ops
= extended_op_buf
;
6003 printf (_(" Extension opcode arguments:\n"));
6004 for (i
= 0; i
< count
; i
++)
6006 SAFE_BYTE_GET_AND_INC (op
, curr
, 1, end
);
6007 extended_ops
[op
] = curr
;
6008 READ_ULEB (nargs
, curr
, end
);
6010 printf (_(" DW_MACRO_%02x has no arguments\n"), op
);
6013 printf (_(" DW_MACRO_%02x arguments: "), op
);
6014 for (n
= 0; n
< nargs
; n
++)
6018 SAFE_BYTE_GET_AND_INC (form
, curr
, 1, end
);
6019 printf ("%s%s", get_FORM_name (form
),
6020 n
== nargs
- 1 ? "\n" : ", ");
6030 case DW_FORM_block1
:
6031 case DW_FORM_block2
:
6032 case DW_FORM_block4
:
6034 case DW_FORM_string
:
6036 case DW_FORM_sec_offset
:
6039 error (_("Invalid extension opcode form %s\n"),
6040 get_FORM_name (form
));
6056 error (_(".debug_macro section not zero terminated\n"));
6060 SAFE_BYTE_GET_AND_INC (op
, curr
, 1, end
);
6066 case DW_MACRO_define
:
6067 READ_ULEB (lineno
, curr
, end
);
6069 curr
+= strnlen ((char *) string
, end
- string
) + 1;
6070 printf (_(" DW_MACRO_define - lineno : %d macro : %s\n"),
6074 case DW_MACRO_undef
:
6075 READ_ULEB (lineno
, curr
, end
);
6077 curr
+= strnlen ((char *) string
, end
- string
) + 1;
6078 printf (_(" DW_MACRO_undef - lineno : %d macro : %s\n"),
6082 case DW_MACRO_start_file
:
6084 unsigned int filenum
;
6085 unsigned char *file_name
= NULL
, *dir_name
= NULL
;
6087 READ_ULEB (lineno
, curr
, end
);
6088 READ_ULEB (filenum
, curr
, end
);
6090 if ((flags
& 2) == 0)
6091 error (_("DW_MACRO_start_file used, but no .debug_line offset provided.\n"));
6094 = get_line_filename_and_dirname (line_offset
, filenum
,
6096 if (file_name
== NULL
)
6097 printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d\n"),
6100 printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d filename: %s%s%s\n"),
6102 dir_name
!= NULL
? (const char *) dir_name
: "",
6103 dir_name
!= NULL
? "/" : "", file_name
);
6107 case DW_MACRO_end_file
:
6108 printf (_(" DW_MACRO_end_file\n"));
6111 case DW_MACRO_define_strp
:
6112 READ_ULEB (lineno
, curr
, end
);
6113 if (version
== 4 && is_dwo
)
6114 READ_ULEB (offset
, curr
, end
);
6116 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6117 string
= fetch_indirect_string (offset
);
6118 printf (_(" DW_MACRO_define_strp - lineno : %d macro : %s\n"),
6122 case DW_MACRO_undef_strp
:
6123 READ_ULEB (lineno
, curr
, end
);
6124 if (version
== 4 && is_dwo
)
6125 READ_ULEB (offset
, curr
, end
);
6127 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6128 string
= fetch_indirect_string (offset
);
6129 printf (_(" DW_MACRO_undef_strp - lineno : %d macro : %s\n"),
6133 case DW_MACRO_import
:
6134 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6135 printf (_(" DW_MACRO_import - offset : 0x%lx\n"),
6136 (unsigned long) offset
);
6139 case DW_MACRO_define_sup
:
6140 READ_ULEB (lineno
, curr
, end
);
6141 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6142 printf (_(" DW_MACRO_define_sup - lineno : %d macro offset : 0x%lx\n"),
6143 lineno
, (unsigned long) offset
);
6146 case DW_MACRO_undef_sup
:
6147 READ_ULEB (lineno
, curr
, end
);
6148 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6149 printf (_(" DW_MACRO_undef_sup - lineno : %d macro offset : 0x%lx\n"),
6150 lineno
, (unsigned long) offset
);
6153 case DW_MACRO_import_sup
:
6154 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6155 printf (_(" DW_MACRO_import_sup - offset : 0x%lx\n"),
6156 (unsigned long) offset
);
6159 case DW_MACRO_define_strx
:
6160 case DW_MACRO_undef_strx
:
6161 READ_ULEB (lineno
, curr
, end
);
6162 READ_ULEB (offset
, curr
, end
);
6163 string
= (const unsigned char *)
6164 fetch_indexed_string (offset
, NULL
, offset_size
, false);
6165 if (op
== DW_MACRO_define_strx
)
6166 printf (" DW_MACRO_define_strx ");
6168 printf (" DW_MACRO_undef_strx ");
6170 printf (_("(with offset %s) "), dwarf_vmatoa ("x", offset
));
6171 printf (_("lineno : %d macro : %s\n"),
6176 if (op
>= DW_MACRO_lo_user
&& op
<= DW_MACRO_hi_user
)
6178 printf (_(" <Target Specific macro op: %#x - UNHANDLED"), op
);
6182 if (extended_ops
== NULL
|| extended_ops
[op
] == NULL
)
6184 error (_(" Unknown macro opcode %02x seen\n"), op
);
6189 /* Skip over unhandled opcodes. */
6191 unsigned char *desc
= extended_ops
[op
];
6192 READ_ULEB (nargs
, desc
, end
);
6195 printf (_(" DW_MACRO_%02x\n"), op
);
6198 printf (_(" DW_MACRO_%02x -"), op
);
6199 for (n
= 0; n
< nargs
; n
++)
6203 /* DW_FORM_implicit_const is not expected here. */
6204 SAFE_BYTE_GET_AND_INC (val
, desc
, 1, end
);
6206 = read_and_display_attr_value (0, val
, 0,
6207 start
, curr
, end
, 0, 0, offset_size
,
6208 version
, NULL
, 0, NULL
,
6226 display_debug_abbrev (struct dwarf_section
*section
,
6227 void *file ATTRIBUTE_UNUSED
)
6229 abbrev_entry
*entry
;
6230 unsigned char *start
= section
->start
;
6232 introduce (section
, false);
6239 offset
= start
- section
->start
;
6240 list
= find_abbrev_list_by_abbrev_offset (0, offset
);
6243 list
= new_abbrev_list (0, offset
);
6244 start
= process_abbrev_set (section
, 0, section
->size
, offset
, list
);
6245 list
->start_of_next_abbrevs
= start
;
6248 start
= list
->start_of_next_abbrevs
;
6250 if (list
->first_abbrev
== NULL
)
6253 printf (_(" Number TAG (0x%lx)\n"), (long) offset
);
6255 for (entry
= list
->first_abbrev
; entry
; entry
= entry
->next
)
6259 printf (" %ld %s [%s]\n",
6261 get_TAG_name (entry
->tag
),
6262 entry
->children
? _("has children") : _("no children"));
6264 for (attr
= entry
->first_attr
; attr
; attr
= attr
->next
)
6266 printf (" %-18s %s",
6267 get_AT_name (attr
->attribute
),
6268 get_FORM_name (attr
->form
));
6269 if (attr
->form
== DW_FORM_implicit_const
)
6270 printf (": %" BFD_VMA_FMT
"d", attr
->implicit_const
);
6282 /* Return true when ADDR is the maximum address, when addresses are
6283 POINTER_SIZE bytes long. */
6286 is_max_address (dwarf_vma addr
, unsigned int pointer_size
)
6288 dwarf_vma mask
= ~(~(dwarf_vma
) 1 << (pointer_size
* 8 - 1));
6289 return ((addr
& mask
) == mask
);
6292 /* Display a view pair list starting at *VSTART_PTR and ending at
6293 VLISTEND within SECTION. */
6296 display_view_pair_list (struct dwarf_section
*section
,
6297 unsigned char **vstart_ptr
,
6298 unsigned int debug_info_entry
,
6299 unsigned char *vlistend
)
6301 unsigned char *vstart
= *vstart_ptr
;
6302 unsigned char *section_end
= section
->start
+ section
->size
;
6303 unsigned int pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
6305 if (vlistend
< section_end
)
6306 section_end
= vlistend
;
6310 while (vstart
< section_end
)
6312 dwarf_vma off
= vstart
- section
->start
;
6313 dwarf_vma vbegin
, vend
;
6315 READ_ULEB (vbegin
, vstart
, section_end
);
6316 if (vstart
== section_end
)
6319 READ_ULEB (vend
, vstart
, section_end
);
6320 printf (" %8.8lx ", (unsigned long) off
);
6322 print_dwarf_view (vbegin
, pointer_size
, 1);
6323 print_dwarf_view (vend
, pointer_size
, 1);
6324 printf (_("location view pair\n"));
6328 *vstart_ptr
= vstart
;
6331 /* Display a location list from a normal (ie, non-dwo) .debug_loc section. */
6334 display_loc_list (struct dwarf_section
*section
,
6335 unsigned char **start_ptr
,
6336 unsigned int debug_info_entry
,
6338 dwarf_vma base_address
,
6339 unsigned char **vstart_ptr
,
6342 unsigned char *start
= *start_ptr
, *vstart
= *vstart_ptr
;
6343 unsigned char *section_end
= section
->start
+ section
->size
;
6344 unsigned long cu_offset
;
6345 unsigned int pointer_size
;
6346 unsigned int offset_size
;
6351 unsigned short length
;
6352 int need_frame_base
;
6354 if (debug_info_entry
>= num_debug_info_entries
)
6356 warn (_("No debug information available for loc lists of entry: %u\n"),
6361 cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
6362 pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
6363 offset_size
= debug_information
[debug_info_entry
].offset_size
;
6364 dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
6366 if (pointer_size
< 2 || pointer_size
> 8)
6368 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
6369 pointer_size
, debug_info_entry
);
6375 dwarf_vma off
= offset
+ (start
- *start_ptr
);
6376 dwarf_vma vbegin
= vm1
, vend
= vm1
;
6378 if (start
+ 2 * pointer_size
> section_end
)
6380 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6381 (unsigned long) offset
);
6385 printf (" %8.8lx ", (unsigned long) off
);
6387 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, section_end
);
6388 SAFE_BYTE_GET_AND_INC (end
, start
, pointer_size
, section_end
);
6390 if (begin
== 0 && end
== 0)
6392 /* PR 18374: In a object file we can have a location list that
6393 starts with a begin and end of 0 because there are relocations
6394 that need to be applied to the addresses. Actually applying
6395 the relocations now does not help as they will probably resolve
6396 to 0, since the object file has not been fully linked. Real
6397 end of list markers will not have any relocations against them. */
6398 if (! reloc_at (section
, off
)
6399 && ! reloc_at (section
, off
+ pointer_size
))
6401 printf (_("<End of list>\n"));
6406 /* Check base address specifiers. */
6407 if (is_max_address (begin
, pointer_size
)
6408 && !is_max_address (end
, pointer_size
))
6411 print_dwarf_vma (begin
, pointer_size
);
6412 print_dwarf_vma (end
, pointer_size
);
6413 printf (_("(base address)\n"));
6419 off
= offset
+ (vstart
- *start_ptr
);
6421 READ_ULEB (vbegin
, vstart
, section_end
);
6422 print_dwarf_view (vbegin
, pointer_size
, 1);
6424 READ_ULEB (vend
, vstart
, section_end
);
6425 print_dwarf_view (vend
, pointer_size
, 1);
6427 printf (_("views at %8.8lx for:\n %*s "),
6428 (unsigned long) off
, 8, "");
6431 if (start
+ 2 > section_end
)
6433 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6434 (unsigned long) offset
);
6438 SAFE_BYTE_GET_AND_INC (length
, start
, 2, section_end
);
6440 if (start
+ length
> section_end
)
6442 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6443 (unsigned long) offset
);
6447 print_dwarf_vma (begin
+ base_address
, pointer_size
);
6448 print_dwarf_vma (end
+ base_address
, pointer_size
);
6451 need_frame_base
= decode_location_expression (start
,
6456 cu_offset
, section
);
6459 if (need_frame_base
&& !has_frame_base
)
6460 printf (_(" [without DW_AT_frame_base]"));
6462 if (begin
== end
&& vbegin
== vend
)
6463 fputs (_(" (start == end)"), stdout
);
6464 else if (begin
> end
|| (begin
== end
&& vbegin
> vend
))
6465 fputs (_(" (start > end)"), stdout
);
6473 *vstart_ptr
= vstart
;
6476 /* Display a location list from a normal (ie, non-dwo) .debug_loclists section. */
6479 display_loclists_list (struct dwarf_section
*section
,
6480 unsigned char **start_ptr
,
6481 unsigned int debug_info_entry
,
6483 dwarf_vma base_address
,
6484 unsigned char **vstart_ptr
,
6487 unsigned char *start
= *start_ptr
, *vstart
= *vstart_ptr
;
6488 unsigned char *section_end
= section
->start
+ section
->size
;
6489 unsigned long cu_offset
;
6490 unsigned int pointer_size
;
6491 unsigned int offset_size
;
6494 /* Initialize it due to a false compiler warning. */
6495 dwarf_vma begin
= -1, vbegin
= -1;
6496 dwarf_vma end
= -1, vend
= -1;
6498 int need_frame_base
;
6500 if (debug_info_entry
>= num_debug_info_entries
)
6502 warn (_("No debug information available for "
6503 "loclists lists of entry: %u\n"),
6508 cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
6509 pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
6510 offset_size
= debug_information
[debug_info_entry
].offset_size
;
6511 dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
6513 if (pointer_size
< 2 || pointer_size
> 8)
6515 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
6516 pointer_size
, debug_info_entry
);
6522 dwarf_vma off
= offset
+ (start
- *start_ptr
);
6523 enum dwarf_location_list_entry_type llet
;
6525 if (start
+ 1 > section_end
)
6527 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6528 (unsigned long) offset
);
6532 printf (" %8.8lx ", (unsigned long) off
);
6534 SAFE_BYTE_GET_AND_INC (llet
, start
, 1, section_end
);
6536 if (vstart
&& (llet
== DW_LLE_offset_pair
6537 || llet
== DW_LLE_start_end
6538 || llet
== DW_LLE_start_length
))
6540 off
= offset
+ (vstart
- *start_ptr
);
6542 READ_ULEB (vbegin
, vstart
, section_end
);
6543 print_dwarf_view (vbegin
, pointer_size
, 1);
6545 READ_ULEB (vend
, vstart
, section_end
);
6546 print_dwarf_view (vend
, pointer_size
, 1);
6548 printf (_("views at %8.8lx for:\n %*s "),
6549 (unsigned long) off
, 8, "");
6554 case DW_LLE_end_of_list
:
6555 printf (_("<End of list>\n"));
6557 case DW_LLE_offset_pair
:
6558 READ_ULEB (begin
, start
, section_end
);
6559 begin
+= base_address
;
6560 READ_ULEB (end
, start
, section_end
);
6561 end
+= base_address
;
6563 case DW_LLE_start_end
:
6564 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, section_end
);
6565 SAFE_BYTE_GET_AND_INC (end
, start
, pointer_size
, section_end
);
6567 case DW_LLE_start_length
:
6568 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, section_end
);
6569 READ_ULEB (end
, start
, section_end
);
6572 case DW_LLE_base_address
:
6573 SAFE_BYTE_GET_AND_INC (base_address
, start
, pointer_size
,
6575 print_dwarf_vma (base_address
, pointer_size
);
6576 printf (_("(base address)\n"));
6578 #ifdef DW_LLE_view_pair
6579 case DW_LLE_view_pair
:
6581 printf (_("View pair entry in loclist with locviews attribute\n"));
6582 READ_ULEB (vbegin
, start
, section_end
);
6583 print_dwarf_view (vbegin
, pointer_size
, 1);
6585 READ_ULEB (vend
, start
, section_end
);
6586 print_dwarf_view (vend
, pointer_size
, 1);
6588 printf (_("views for:\n"));
6592 error (_("Invalid location list entry type %d\n"), llet
);
6595 if (llet
== DW_LLE_end_of_list
)
6597 if (llet
!= DW_LLE_offset_pair
6598 && llet
!= DW_LLE_start_end
6599 && llet
!= DW_LLE_start_length
)
6602 if (start
+ 2 > section_end
)
6604 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6605 (unsigned long) offset
);
6609 READ_ULEB (length
, start
, section_end
);
6611 print_dwarf_vma (begin
, pointer_size
);
6612 print_dwarf_vma (end
, pointer_size
);
6615 need_frame_base
= decode_location_expression (start
,
6620 cu_offset
, section
);
6623 if (need_frame_base
&& !has_frame_base
)
6624 printf (_(" [without DW_AT_frame_base]"));
6626 if (begin
== end
&& vbegin
== vend
)
6627 fputs (_(" (start == end)"), stdout
);
6628 else if (begin
> end
|| (begin
== end
&& vbegin
> vend
))
6629 fputs (_(" (start > end)"), stdout
);
6637 if (vbegin
!= vm1
|| vend
!= vm1
)
6638 printf (_("Trailing view pair not used in a range"));
6641 *vstart_ptr
= vstart
;
6644 /* Print a .debug_addr table index in decimal, surrounded by square brackets,
6645 right-adjusted in a field of length LEN, and followed by a space. */
6648 print_addr_index (unsigned int idx
, unsigned int len
)
6650 static char buf
[15];
6651 snprintf (buf
, sizeof (buf
), "[%d]", idx
);
6652 printf ("%*s ", len
, buf
);
6655 /* Display a location list from a .dwo section. It uses address indexes rather
6656 than embedded addresses. This code closely follows display_loc_list, but the
6657 two are sufficiently different that combining things is very ugly. */
6660 display_loc_list_dwo (struct dwarf_section
*section
,
6661 unsigned char **start_ptr
,
6662 unsigned int debug_info_entry
,
6664 unsigned char **vstart_ptr
,
6667 unsigned char *start
= *start_ptr
, *vstart
= *vstart_ptr
;
6668 unsigned char *section_end
= section
->start
+ section
->size
;
6669 unsigned long cu_offset
;
6670 unsigned int pointer_size
;
6671 unsigned int offset_size
;
6674 unsigned short length
;
6675 int need_frame_base
;
6678 if (debug_info_entry
>= num_debug_info_entries
)
6680 warn (_("No debug information for loc lists of entry: %u\n"),
6685 cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
6686 pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
6687 offset_size
= debug_information
[debug_info_entry
].offset_size
;
6688 dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
6690 if (pointer_size
< 2 || pointer_size
> 8)
6692 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
6693 pointer_size
, debug_info_entry
);
6699 printf (" %8.8lx ", (unsigned long) (offset
+ (start
- *start_ptr
)));
6701 if (start
>= section_end
)
6703 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6704 (unsigned long) offset
);
6708 SAFE_BYTE_GET_AND_INC (entry_type
, start
, 1, section_end
);
6721 dwarf_vma off
= offset
+ (vstart
- *start_ptr
);
6723 READ_ULEB (view
, vstart
, section_end
);
6724 print_dwarf_view (view
, 8, 1);
6726 READ_ULEB (view
, vstart
, section_end
);
6727 print_dwarf_view (view
, 8, 1);
6729 printf (_("views at %8.8lx for:\n %*s "),
6730 (unsigned long) off
, 8, "");
6738 case 0: /* A terminating entry. */
6740 *vstart_ptr
= vstart
;
6741 printf (_("<End of list>\n"));
6743 case 1: /* A base-address entry. */
6744 READ_ULEB (idx
, start
, section_end
);
6745 print_addr_index (idx
, 8);
6746 printf ("%*s", 9 + (vstart
? 2 * 6 : 0), "");
6747 printf (_("(base address selection entry)\n"));
6749 case 2: /* A start/end entry. */
6750 READ_ULEB (idx
, start
, section_end
);
6751 print_addr_index (idx
, 8);
6752 READ_ULEB (idx
, start
, section_end
);
6753 print_addr_index (idx
, 8);
6755 case 3: /* A start/length entry. */
6756 READ_ULEB (idx
, start
, section_end
);
6757 print_addr_index (idx
, 8);
6758 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
6759 printf ("%08x ", idx
);
6761 case 4: /* An offset pair entry. */
6762 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
6763 printf ("%08x ", idx
);
6764 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
6765 printf ("%08x ", idx
);
6768 warn (_("Unknown location list entry type 0x%x.\n"), entry_type
);
6770 *vstart_ptr
= vstart
;
6774 if (start
+ 2 > section_end
)
6776 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6777 (unsigned long) offset
);
6781 SAFE_BYTE_GET_AND_INC (length
, start
, 2, section_end
);
6782 if (start
+ length
> section_end
)
6784 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6785 (unsigned long) offset
);
6790 need_frame_base
= decode_location_expression (start
,
6795 cu_offset
, section
);
6798 if (need_frame_base
&& !has_frame_base
)
6799 printf (_(" [without DW_AT_frame_base]"));
6807 *vstart_ptr
= vstart
;
6810 /* Sort array of indexes in ascending order of loc_offsets[idx] and
6813 static dwarf_vma
*loc_offsets
, *loc_views
;
6816 loc_offsets_compar (const void *ap
, const void *bp
)
6818 dwarf_vma a
= loc_offsets
[*(const unsigned int *) ap
];
6819 dwarf_vma b
= loc_offsets
[*(const unsigned int *) bp
];
6821 int ret
= (a
> b
) - (b
> a
);
6825 a
= loc_views
[*(const unsigned int *) ap
];
6826 b
= loc_views
[*(const unsigned int *) bp
];
6828 ret
= (a
> b
) - (b
> a
);
6834 display_debug_loc (struct dwarf_section
*section
, void *file
)
6836 unsigned char *start
= section
->start
, *vstart
= NULL
;
6837 unsigned long bytes
;
6838 unsigned char *section_begin
= start
;
6839 unsigned int num_loc_list
= 0;
6840 unsigned long last_offset
= 0;
6841 unsigned long last_view
= 0;
6842 unsigned int first
= 0;
6845 int seen_first_offset
= 0;
6846 int locs_sorted
= 1;
6847 unsigned char *next
= start
, *vnext
= vstart
;
6848 unsigned int *array
= NULL
;
6849 const char *suffix
= strrchr (section
->name
, '.');
6850 bool is_dwo
= false;
6851 int is_loclists
= strstr (section
->name
, "debug_loclists") != NULL
;
6852 dwarf_vma expected_start
= 0;
6854 if (suffix
&& strcmp (suffix
, ".dwo") == 0)
6857 bytes
= section
->size
;
6861 printf (_("\nThe %s section is empty.\n"), section
->name
);
6867 unsigned char *hdrptr
= section_begin
;
6868 dwarf_vma ll_length
;
6869 unsigned short ll_version
;
6870 unsigned char *end
= section_begin
+ section
->size
;
6871 unsigned char address_size
, segment_selector_size
;
6872 uint32_t offset_entry_count
;
6874 SAFE_BYTE_GET_AND_INC (ll_length
, hdrptr
, 4, end
);
6875 if (ll_length
== 0xffffffff)
6876 SAFE_BYTE_GET_AND_INC (ll_length
, hdrptr
, 8, end
);
6878 SAFE_BYTE_GET_AND_INC (ll_version
, hdrptr
, 2, end
);
6879 if (ll_version
!= 5)
6881 warn (_("The %s section contains corrupt or "
6882 "unsupported version number: %d.\n"),
6883 section
->name
, ll_version
);
6887 SAFE_BYTE_GET_AND_INC (address_size
, hdrptr
, 1, end
);
6889 SAFE_BYTE_GET_AND_INC (segment_selector_size
, hdrptr
, 1, end
);
6890 if (segment_selector_size
!= 0)
6892 warn (_("The %s section contains "
6893 "unsupported segment selector size: %d.\n"),
6894 section
->name
, segment_selector_size
);
6898 SAFE_BYTE_GET_AND_INC (offset_entry_count
, hdrptr
, 4, end
);
6899 if (offset_entry_count
!= 0)
6901 warn (_("The %s section contains "
6902 "unsupported offset entry count: %d.\n"),
6903 section
->name
, offset_entry_count
);
6907 expected_start
= hdrptr
- section_begin
;
6910 if (load_debug_info (file
) == 0)
6912 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
6917 /* Check the order of location list in .debug_info section. If
6918 offsets of location lists are in the ascending order, we can
6919 use `debug_information' directly. */
6920 for (i
= 0; i
< num_debug_info_entries
; i
++)
6924 num
= debug_information
[i
].num_loc_offsets
;
6925 if (num
> num_loc_list
)
6928 /* Check if we can use `debug_information' directly. */
6929 if (locs_sorted
&& num
!= 0)
6931 if (!seen_first_offset
)
6933 /* This is the first location list. */
6934 last_offset
= debug_information
[i
].loc_offsets
[0];
6935 last_view
= debug_information
[i
].loc_views
[0];
6937 seen_first_offset
= 1;
6943 for (; j
< num
; j
++)
6946 debug_information
[i
].loc_offsets
[j
]
6947 || (last_offset
== debug_information
[i
].loc_offsets
[j
]
6948 && last_view
> debug_information
[i
].loc_views
[j
]))
6953 last_offset
= debug_information
[i
].loc_offsets
[j
];
6954 last_view
= debug_information
[i
].loc_views
[j
];
6959 if (!seen_first_offset
)
6960 error (_("No location lists in .debug_info section!\n"));
6962 if (debug_information
[first
].num_loc_offsets
> 0
6963 && debug_information
[first
].loc_offsets
[0] != expected_start
6964 && debug_information
[first
].loc_views
[0] != expected_start
)
6965 warn (_("Location lists in %s section start at 0x%s\n"),
6967 dwarf_vmatoa ("x", debug_information
[first
].loc_offsets
[0]));
6970 array
= (unsigned int *) xcmalloc (num_loc_list
, sizeof (unsigned int));
6972 introduce (section
, false);
6974 if (reloc_at (section
, 0))
6975 printf (_(" Warning: This section has relocations - addresses seen here may not be accurate.\n\n"));
6977 printf (_(" Offset Begin End Expression\n"));
6979 seen_first_offset
= 0;
6980 for (i
= first
; i
< num_debug_info_entries
; i
++)
6982 dwarf_vma offset
, voffset
;
6983 dwarf_vma base_address
;
6989 for (k
= 0; k
< debug_information
[i
].num_loc_offsets
; k
++)
6991 loc_offsets
= debug_information
[i
].loc_offsets
;
6992 loc_views
= debug_information
[i
].loc_views
;
6993 qsort (array
, debug_information
[i
].num_loc_offsets
,
6994 sizeof (*array
), loc_offsets_compar
);
6997 int adjacent_view_loclists
= 1;
6998 for (k
= 0; k
< debug_information
[i
].num_loc_offsets
; k
++)
7000 j
= locs_sorted
? k
: array
[k
];
7002 && (debug_information
[i
].loc_offsets
[locs_sorted
7003 ? k
- 1 : array
[k
- 1]]
7004 == debug_information
[i
].loc_offsets
[j
])
7005 && (debug_information
[i
].loc_views
[locs_sorted
7006 ? k
- 1 : array
[k
- 1]]
7007 == debug_information
[i
].loc_views
[j
]))
7009 has_frame_base
= debug_information
[i
].have_frame_base
[j
];
7010 offset
= debug_information
[i
].loc_offsets
[j
];
7011 next
= section_begin
+ offset
;
7012 voffset
= debug_information
[i
].loc_views
[j
];
7014 vnext
= section_begin
+ voffset
;
7017 base_address
= debug_information
[i
].base_address
;
7019 if (vnext
&& vnext
< next
)
7022 display_view_pair_list (section
, &vstart
, i
, next
);
7027 if (!seen_first_offset
|| !adjacent_view_loclists
)
7028 seen_first_offset
= 1;
7032 warn (_("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n"),
7033 (unsigned long) (start
- section_begin
),
7034 (unsigned long) offset
);
7035 else if (start
> next
)
7036 warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n"),
7037 (unsigned long) (start
- section_begin
),
7038 (unsigned long) offset
);
7043 if (offset
>= bytes
)
7045 warn (_("Offset 0x%lx is bigger than .debug_loc section size.\n"),
7046 (unsigned long) offset
);
7050 if (vnext
&& voffset
>= bytes
)
7052 warn (_("View Offset 0x%lx is bigger than .debug_loc section size.\n"),
7053 (unsigned long) voffset
);
7060 display_loc_list_dwo (section
, &start
, i
, offset
,
7061 &vstart
, has_frame_base
);
7063 display_loc_list (section
, &start
, i
, offset
, base_address
,
7064 &vstart
, has_frame_base
);
7069 warn (_("DWO is not yet supported.\n"));
7071 display_loclists_list (section
, &start
, i
, offset
, base_address
,
7072 &vstart
, has_frame_base
);
7075 /* FIXME: this arrangement is quite simplistic. Nothing
7076 requires locview lists to be adjacent to corresponding
7077 loclists, and a single loclist could be augmented by
7078 different locview lists, and vice-versa, unlikely as it
7079 is that it would make sense to do so. Hopefully we'll
7080 have view pair support built into loclists before we ever
7081 need to address all these possibilities. */
7082 if (adjacent_view_loclists
&& vnext
7083 && vnext
!= start
&& vstart
!= next
)
7085 adjacent_view_loclists
= 0;
7086 warn (_("Hole and overlap detection requires adjacent view lists and loclists.\n"));
7089 if (vnext
&& vnext
== start
)
7090 display_view_pair_list (section
, &start
, i
, vstart
);
7094 if (start
< section
->start
+ section
->size
)
7095 warn (ngettext ("There is %ld unused byte at the end of section %s\n",
7096 "There are %ld unused bytes at the end of section %s\n",
7097 (long) (section
->start
+ section
->size
- start
)),
7098 (long) (section
->start
+ section
->size
- start
), section
->name
);
7105 display_debug_str (struct dwarf_section
*section
,
7106 void *file ATTRIBUTE_UNUSED
)
7108 unsigned char *start
= section
->start
;
7109 unsigned long bytes
= section
->size
;
7110 dwarf_vma addr
= section
->address
;
7114 printf (_("\nThe %s section is empty.\n"), section
->name
);
7118 introduce (section
, false);
7126 lbytes
= (bytes
> 16 ? 16 : bytes
);
7128 printf (" 0x%8.8lx ", (unsigned long) addr
);
7130 for (j
= 0; j
< 16; j
++)
7133 printf ("%2.2x", start
[j
]);
7141 for (j
= 0; j
< lbytes
; j
++)
7144 if (k
>= ' ' && k
< 0x80)
7163 display_debug_info (struct dwarf_section
*section
, void *file
)
7165 return process_debug_info (section
, file
, section
->abbrev_sec
, false, false);
7169 display_debug_types (struct dwarf_section
*section
, void *file
)
7171 return process_debug_info (section
, file
, section
->abbrev_sec
, false, true);
7175 display_trace_info (struct dwarf_section
*section
, void *file
)
7177 return process_debug_info (section
, file
, section
->abbrev_sec
, false, true);
7181 display_debug_aranges (struct dwarf_section
*section
,
7182 void *file ATTRIBUTE_UNUSED
)
7184 unsigned char *start
= section
->start
;
7185 unsigned char *end
= start
+ section
->size
;
7187 introduce (section
, false);
7189 /* It does not matter if this load fails,
7190 we test for that later on. */
7191 load_debug_info (file
);
7195 unsigned char *hdrptr
;
7196 DWARF2_Internal_ARange arange
;
7197 unsigned char *addr_ranges
;
7200 unsigned long sec_off
;
7201 unsigned char address_size
;
7203 unsigned int offset_size
;
7204 unsigned int initial_length_size
;
7208 SAFE_BYTE_GET_AND_INC (arange
.ar_length
, hdrptr
, 4, end
);
7209 if (arange
.ar_length
== 0xffffffff)
7211 SAFE_BYTE_GET_AND_INC (arange
.ar_length
, hdrptr
, 8, end
);
7213 initial_length_size
= 12;
7218 initial_length_size
= 4;
7221 sec_off
= hdrptr
- section
->start
;
7222 if (sec_off
+ arange
.ar_length
< sec_off
7223 || sec_off
+ arange
.ar_length
> section
->size
)
7225 warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"),
7227 sec_off
- initial_length_size
,
7228 dwarf_vmatoa ("x", arange
.ar_length
));
7232 SAFE_BYTE_GET_AND_INC (arange
.ar_version
, hdrptr
, 2, end
);
7233 SAFE_BYTE_GET_AND_INC (arange
.ar_info_offset
, hdrptr
, offset_size
, end
);
7235 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
7236 && num_debug_info_entries
> 0
7237 && find_debug_info_for_offset (arange
.ar_info_offset
) == NULL
)
7238 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
7239 (unsigned long) arange
.ar_info_offset
, section
->name
);
7241 SAFE_BYTE_GET_AND_INC (arange
.ar_pointer_size
, hdrptr
, 1, end
);
7242 SAFE_BYTE_GET_AND_INC (arange
.ar_segment_size
, hdrptr
, 1, end
);
7244 if (arange
.ar_version
!= 2 && arange
.ar_version
!= 3)
7246 /* PR 19872: A version number of 0 probably means that there is
7247 padding at the end of the .debug_aranges section. Gold puts
7248 it there when performing an incremental link, for example.
7249 So do not generate a warning in this case. */
7250 if (arange
.ar_version
)
7251 warn (_("Only DWARF 2 and 3 aranges are currently supported.\n"));
7255 printf (_(" Length: %ld\n"),
7256 (long) arange
.ar_length
);
7257 printf (_(" Version: %d\n"), arange
.ar_version
);
7258 printf (_(" Offset into .debug_info: 0x%lx\n"),
7259 (unsigned long) arange
.ar_info_offset
);
7260 printf (_(" Pointer Size: %d\n"), arange
.ar_pointer_size
);
7261 printf (_(" Segment Size: %d\n"), arange
.ar_segment_size
);
7263 address_size
= arange
.ar_pointer_size
+ arange
.ar_segment_size
;
7265 /* PR 17512: file: 001-108546-0.001:0.1. */
7266 if (address_size
== 0 || address_size
> 8)
7268 error (_("Invalid address size in %s section!\n"),
7273 /* The DWARF spec does not require that the address size be a power
7274 of two, but we do. This will have to change if we ever encounter
7275 an uneven architecture. */
7276 if ((address_size
& (address_size
- 1)) != 0)
7278 warn (_("Pointer size + Segment size is not a power of two.\n"));
7282 if (address_size
> 4)
7283 printf (_("\n Address Length\n"));
7285 printf (_("\n Address Length\n"));
7287 addr_ranges
= hdrptr
;
7289 /* Must pad to an alignment boundary that is twice the address size. */
7290 excess
= (hdrptr
- start
) % (2 * address_size
);
7292 addr_ranges
+= (2 * address_size
) - excess
;
7294 start
+= arange
.ar_length
+ initial_length_size
;
7296 while (addr_ranges
+ 2 * address_size
<= start
)
7298 SAFE_BYTE_GET_AND_INC (address
, addr_ranges
, address_size
, end
);
7299 SAFE_BYTE_GET_AND_INC (length
, addr_ranges
, address_size
, end
);
7302 print_dwarf_vma (address
, address_size
);
7303 print_dwarf_vma (length
, address_size
);
7313 /* Comparison function for qsort. */
7315 comp_addr_base (const void * v0
, const void * v1
)
7317 debug_info
*info0
= *(debug_info
**) v0
;
7318 debug_info
*info1
= *(debug_info
**) v1
;
7319 return info0
->addr_base
- info1
->addr_base
;
7322 /* Display the debug_addr section. */
7324 display_debug_addr (struct dwarf_section
*section
,
7327 debug_info
**debug_addr_info
;
7328 unsigned char *entry
;
7332 unsigned char * header
;
7334 if (section
->size
== 0)
7336 printf (_("\nThe %s section is empty.\n"), section
->name
);
7340 if (load_debug_info (file
) == 0)
7342 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
7347 introduce (section
, false);
7349 /* PR 17531: file: cf38d01b.
7350 We use xcalloc because a corrupt file may not have initialised all of the
7351 fields in the debug_info structure, which means that the sort below might
7352 try to move uninitialised data. */
7353 debug_addr_info
= (debug_info
**) xcalloc ((num_debug_info_entries
+ 1),
7354 sizeof (debug_info
*));
7357 for (i
= 0; i
< num_debug_info_entries
; i
++)
7358 if (debug_information
[i
].addr_base
!= DEBUG_INFO_UNAVAILABLE
)
7360 /* PR 17531: file: cf38d01b. */
7361 if (debug_information
[i
].addr_base
>= section
->size
)
7362 warn (_("Corrupt address base (%lx) found in debug section %u\n"),
7363 (unsigned long) debug_information
[i
].addr_base
, i
);
7365 debug_addr_info
[count
++] = debug_information
+ i
;
7368 /* Add a sentinel to make iteration convenient. */
7369 debug_addr_info
[count
] = (debug_info
*) xmalloc (sizeof (debug_info
));
7370 debug_addr_info
[count
]->addr_base
= section
->size
;
7371 qsort (debug_addr_info
, count
, sizeof (debug_info
*), comp_addr_base
);
7373 header
= section
->start
;
7374 for (i
= 0; i
< count
; i
++)
7377 unsigned int address_size
= debug_addr_info
[i
]->pointer_size
;
7379 printf (_(" For compilation unit at offset 0x%s:\n"),
7380 dwarf_vmatoa ("x", debug_addr_info
[i
]->cu_offset
));
7382 printf (_("\tIndex\tAddress\n"));
7383 entry
= section
->start
+ debug_addr_info
[i
]->addr_base
;
7384 if (debug_addr_info
[i
]->dwarf_version
>= 5)
7386 size_t header_size
= entry
- header
;
7387 unsigned char * curr_header
= header
;
7390 int segment_selector_size
;
7392 if (header_size
!= 8 && header_size
!= 16)
7394 warn (_("Corrupt %s section: expecting header size of 8 or 16, but found %ld instead\n"),
7395 section
->name
, (long) header_size
);
7399 SAFE_BYTE_GET_AND_INC (length
, curr_header
, 4, entry
);
7400 if (length
== 0xffffffff)
7401 SAFE_BYTE_GET_AND_INC (length
, curr_header
, 8, entry
);
7402 end
= curr_header
+ length
;
7404 SAFE_BYTE_GET_AND_INC (version
, curr_header
, 2, entry
);
7406 warn (_("Corrupt %s section: expecting version number 5 in header but found %d instead\n"),
7407 section
->name
, version
);
7409 SAFE_BYTE_GET_AND_INC (address_size
, curr_header
, 1, entry
);
7410 SAFE_BYTE_GET_AND_INC (segment_selector_size
, curr_header
, 1, entry
);
7411 address_size
+= segment_selector_size
;
7414 end
= section
->start
+ debug_addr_info
[i
+ 1]->addr_base
;
7419 dwarf_vma base
= byte_get (entry
, address_size
);
7420 printf (_("\t%d:\t"), idx
);
7421 print_dwarf_vma (base
, address_size
);
7423 entry
+= address_size
;
7429 free (debug_addr_info
);
7433 /* Display the .debug_str_offsets and .debug_str_offsets.dwo sections. */
7436 display_debug_str_offsets (struct dwarf_section
*section
,
7437 void *file ATTRIBUTE_UNUSED
)
7441 if (section
->size
== 0)
7443 printf (_("\nThe %s section is empty.\n"), section
->name
);
7447 unsigned char *start
= section
->start
;
7448 unsigned char *end
= start
+ section
->size
;
7449 unsigned char *curr
= start
;
7451 const char *suffix
= strrchr (section
->name
, '.');
7452 bool dwo
= suffix
&& strcmp (suffix
, ".dwo") == 0;
7455 load_debug_section_with_follow (str_dwo
, file
);
7457 load_debug_section_with_follow (str
, file
);
7459 introduce (section
, false);
7464 dwarf_vma entry_length
;
7466 SAFE_BYTE_GET_AND_INC (length
, curr
, 4, end
);
7467 /* FIXME: We assume that this means 64-bit DWARF is being used. */
7468 if (length
== 0xffffffff)
7470 SAFE_BYTE_GET_AND_INC (length
, curr
, 8, end
);
7476 unsigned char *entries_end
;
7479 /* This is probably an old style .debug_str_offset section which
7480 just contains offsets and no header (and the first offset is 0). */
7481 length
= section
->size
;
7482 curr
= section
->start
;
7485 printf (_(" Length: %#lx\n"), (unsigned long) length
);
7486 printf (_(" Index Offset [String]\n"));
7490 entries_end
= curr
+ length
;
7493 SAFE_BYTE_GET_AND_INC (version
, curr
, 2, end
);
7495 warn (_("Unexpected version number in str_offset header: %#x\n"), version
);
7498 SAFE_BYTE_GET_AND_INC (padding
, curr
, 2, end
);
7500 warn (_("Unexpected value in str_offset header's padding field: %#x\n"), padding
);
7502 printf (_(" Length: %#lx\n"), (unsigned long) length
);
7503 printf (_(" Version: %#lx\n"), (unsigned long) version
);
7504 printf (_(" Index Offset [String]\n"));
7507 for (idx
= 0; curr
< entries_end
; idx
++)
7510 const unsigned char * string
;
7512 if ((dwarf_vma
) (entries_end
- curr
) < entry_length
)
7513 /* Not enough space to read one entry_length, give up. */
7516 SAFE_BYTE_GET_AND_INC (offset
, curr
, entry_length
, end
);
7518 string
= (const unsigned char *)
7519 fetch_indexed_string (idx
, NULL
, entry_length
, dwo
);
7521 string
= fetch_indirect_string (offset
);
7523 printf (" %8lu %8s %s\n", idx
, dwarf_vmatoa ("x", offset
),
7531 /* Each debug_information[x].range_lists[y] gets this representation for
7532 sorting purposes. */
7536 /* The debug_information[x].range_lists[y] value. */
7537 dwarf_vma ranges_offset
;
7539 /* Original debug_information to find parameters of the data. */
7540 debug_info
*debug_info_p
;
7543 /* Sort struct range_entry in ascending order of its RANGES_OFFSET. */
7546 range_entry_compar (const void *ap
, const void *bp
)
7548 const struct range_entry
*a_re
= (const struct range_entry
*) ap
;
7549 const struct range_entry
*b_re
= (const struct range_entry
*) bp
;
7550 const dwarf_vma a
= a_re
->ranges_offset
;
7551 const dwarf_vma b
= b_re
->ranges_offset
;
7553 return (a
> b
) - (b
> a
);
7557 display_debug_ranges_list (unsigned char *start
, unsigned char *finish
,
7558 unsigned int pointer_size
, unsigned long offset
,
7559 unsigned long base_address
)
7561 while (start
< finish
)
7566 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
7567 if (start
>= finish
)
7569 SAFE_SIGNED_BYTE_GET_AND_INC (end
, start
, pointer_size
, finish
);
7571 printf (" %8.8lx ", offset
);
7573 if (begin
== 0 && end
== 0)
7575 printf (_("<End of list>\n"));
7579 /* Check base address specifiers. */
7580 if (is_max_address (begin
, pointer_size
)
7581 && !is_max_address (end
, pointer_size
))
7584 print_dwarf_vma (begin
, pointer_size
);
7585 print_dwarf_vma (end
, pointer_size
);
7586 printf ("(base address)\n");
7590 print_dwarf_vma (begin
+ base_address
, pointer_size
);
7591 print_dwarf_vma (end
+ base_address
, pointer_size
);
7594 fputs (_("(start == end)"), stdout
);
7595 else if (begin
> end
)
7596 fputs (_("(start > end)"), stdout
);
7603 display_debug_rnglists_list (unsigned char *start
, unsigned char *finish
,
7604 unsigned int pointer_size
, unsigned long offset
,
7605 unsigned long base_address
)
7607 unsigned char *next
= start
;
7611 unsigned long off
= offset
+ (start
- next
);
7612 enum dwarf_range_list_entry rlet
;
7613 /* Initialize it due to a false compiler warning. */
7614 dwarf_vma begin
= -1, length
, end
= -1;
7616 if (start
+ 1 > finish
)
7618 warn (_("Range list starting at offset 0x%lx is not terminated.\n"),
7623 printf (" %8.8lx ", off
);
7625 SAFE_BYTE_GET_AND_INC (rlet
, start
, 1, finish
);
7629 case DW_RLE_end_of_list
:
7630 printf (_("<End of list>\n"));
7632 case DW_RLE_base_address
:
7633 SAFE_BYTE_GET_AND_INC (base_address
, start
, pointer_size
, finish
);
7634 print_dwarf_vma (base_address
, pointer_size
);
7635 printf (_("(base address)\n"));
7637 case DW_RLE_start_length
:
7638 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
7639 READ_ULEB (length
, start
, finish
);
7640 end
= begin
+ length
;
7642 case DW_RLE_offset_pair
:
7643 READ_ULEB (begin
, start
, finish
);
7644 READ_ULEB (end
, start
, finish
);
7646 case DW_RLE_start_end
:
7647 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
7648 SAFE_BYTE_GET_AND_INC (end
, start
, pointer_size
, finish
);
7651 error (_("Invalid range list entry type %d\n"), rlet
);
7652 rlet
= DW_RLE_end_of_list
;
7655 if (rlet
== DW_RLE_end_of_list
)
7657 if (rlet
== DW_RLE_base_address
)
7660 /* Only a DW_RLE_offset_pair needs the base address added. */
7661 if (rlet
== DW_RLE_offset_pair
)
7663 begin
+= base_address
;
7664 end
+= base_address
;
7667 print_dwarf_vma (begin
, pointer_size
);
7668 print_dwarf_vma (end
, pointer_size
);
7671 fputs (_("(start == end)"), stdout
);
7672 else if (begin
> end
)
7673 fputs (_("(start > end)"), stdout
);
7680 display_debug_ranges (struct dwarf_section
*section
,
7681 void *file ATTRIBUTE_UNUSED
)
7683 unsigned char *start
= section
->start
;
7684 unsigned char *last_start
= start
;
7685 unsigned long bytes
= section
->size
;
7686 unsigned char *section_begin
= start
;
7687 unsigned char *finish
= start
+ bytes
;
7688 unsigned int num_range_list
, i
;
7689 struct range_entry
*range_entries
, *range_entry_fill
;
7690 int is_rnglists
= strstr (section
->name
, "debug_rnglists") != NULL
;
7691 /* Initialize it due to a false compiler warning. */
7692 unsigned char address_size
= 0;
7693 dwarf_vma last_offset
= 0;
7697 printf (_("\nThe %s section is empty.\n"), section
->name
);
7703 dwarf_vma initial_length
;
7704 unsigned int initial_length_size
;
7705 unsigned char segment_selector_size
;
7706 unsigned int offset_size
, offset_entry_count
;
7707 unsigned short version
;
7709 /* Get and check the length of the block. */
7710 SAFE_BYTE_GET_AND_INC (initial_length
, start
, 4, finish
);
7712 if (initial_length
== 0xffffffff)
7714 /* This section is 64-bit DWARF 3. */
7715 SAFE_BYTE_GET_AND_INC (initial_length
, start
, 8, finish
);
7717 initial_length_size
= 12;
7722 initial_length_size
= 4;
7725 if (initial_length
+ initial_length_size
> section
->size
)
7727 /* If the length field has a relocation against it, then we should
7728 not complain if it is inaccurate (and probably negative).
7729 It is copied from .debug_line handling code. */
7730 if (reloc_at (section
, (start
- section
->start
) - offset_size
))
7732 initial_length
= (finish
- start
) - initial_length_size
;
7736 warn (_("The length field (0x%lx) in the debug_rnglists header is wrong - the section is too small\n"),
7737 (long) initial_length
);
7742 /* Get and check the version number. */
7743 SAFE_BYTE_GET_AND_INC (version
, start
, 2, finish
);
7747 warn (_("Only DWARF version 5 debug_rnglists info "
7748 "is currently supported.\n"));
7752 SAFE_BYTE_GET_AND_INC (address_size
, start
, 1, finish
);
7754 SAFE_BYTE_GET_AND_INC (segment_selector_size
, start
, 1, finish
);
7755 if (segment_selector_size
!= 0)
7757 warn (_("The %s section contains "
7758 "unsupported segment selector size: %d.\n"),
7759 section
->name
, segment_selector_size
);
7763 SAFE_BYTE_GET_AND_INC (offset_entry_count
, start
, 4, finish
);
7764 if (offset_entry_count
!= 0)
7766 warn (_("The %s section contains "
7767 "unsupported offset entry count: %u.\n"),
7768 section
->name
, offset_entry_count
);
7773 if (load_debug_info (file
) == 0)
7775 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
7781 for (i
= 0; i
< num_debug_info_entries
; i
++)
7783 if (debug_information
[i
].dwarf_version
< 5 && is_rnglists
)
7784 /* Skip .debug_rnglists reference. */
7786 if (debug_information
[i
].dwarf_version
>= 5 && !is_rnglists
)
7787 /* Skip .debug_range reference. */
7789 num_range_list
+= debug_information
[i
].num_range_lists
;
7792 if (num_range_list
== 0)
7794 /* This can happen when the file was compiled with -gsplit-debug
7795 which removes references to range lists from the primary .o file. */
7796 printf (_("No range lists in .debug_info section.\n"));
7800 range_entries
= (struct range_entry
*)
7801 xmalloc (sizeof (*range_entries
) * num_range_list
);
7802 range_entry_fill
= range_entries
;
7804 for (i
= 0; i
< num_debug_info_entries
; i
++)
7806 debug_info
*debug_info_p
= &debug_information
[i
];
7809 if (debug_information
[i
].dwarf_version
< 5 && is_rnglists
)
7810 /* Skip .debug_rnglists reference. */
7812 if (debug_information
[i
].dwarf_version
>= 5 && !is_rnglists
)
7813 /* Skip .debug_range reference. */
7816 for (j
= 0; j
< debug_info_p
->num_range_lists
; j
++)
7818 range_entry_fill
->ranges_offset
= debug_info_p
->range_lists
[j
];
7819 range_entry_fill
->debug_info_p
= debug_info_p
;
7824 qsort (range_entries
, num_range_list
, sizeof (*range_entries
),
7825 range_entry_compar
);
7827 if (dwarf_check
!= 0 && range_entries
[0].ranges_offset
!= 0)
7828 warn (_("Range lists in %s section start at 0x%lx\n"),
7829 section
->name
, (unsigned long) range_entries
[0].ranges_offset
);
7831 introduce (section
, false);
7833 printf (_(" Offset Begin End\n"));
7835 for (i
= 0; i
< num_range_list
; i
++)
7837 struct range_entry
*range_entry
= &range_entries
[i
];
7838 debug_info
*debug_info_p
= range_entry
->debug_info_p
;
7839 unsigned int pointer_size
;
7841 unsigned char *next
;
7842 dwarf_vma base_address
;
7844 pointer_size
= (is_rnglists
? address_size
: debug_info_p
->pointer_size
);
7845 offset
= range_entry
->ranges_offset
;
7846 next
= section_begin
+ offset
;
7847 base_address
= debug_info_p
->base_address
;
7849 /* PR 17512: file: 001-101485-0.001:0.1. */
7850 if (pointer_size
< 2 || pointer_size
> 8)
7852 warn (_("Corrupt pointer size (%d) in debug entry at offset %8.8lx\n"),
7853 pointer_size
, (unsigned long) offset
);
7857 if (next
< section_begin
|| next
>= finish
)
7859 warn (_("Corrupt offset (%#8.8lx) in range entry %u\n"),
7860 (unsigned long) offset
, i
);
7864 /* If multiple DWARF entities reference the same range then we will
7865 have multiple entries in the `range_entries' list for the same
7866 offset. Thanks to the sort above these will all be consecutive in
7867 the `range_entries' list, so we can easily ignore duplicates
7869 if (i
> 0 && last_offset
== offset
)
7871 last_offset
= offset
;
7873 if (dwarf_check
!= 0 && i
> 0)
7876 warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"),
7877 (unsigned long) (start
- section_begin
),
7878 (unsigned long) (next
- section_begin
), section
->name
);
7879 else if (start
> next
)
7881 if (next
== last_start
)
7883 warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"),
7884 (unsigned long) (start
- section_begin
),
7885 (unsigned long) (next
- section_begin
), section
->name
);
7892 (is_rnglists
? display_debug_rnglists_list
: display_debug_ranges_list
)
7893 (start
, finish
, pointer_size
, offset
, base_address
);
7897 free (range_entries
);
7902 typedef struct Frame_Chunk
7904 struct Frame_Chunk
*next
;
7905 unsigned char *chunk_start
;
7907 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
7908 short int *col_type
;
7911 unsigned int code_factor
;
7915 unsigned int cfa_reg
;
7916 dwarf_vma cfa_offset
;
7918 unsigned char fde_encoding
;
7919 unsigned char cfa_exp
;
7920 unsigned char ptr_size
;
7921 unsigned char segment_size
;
7925 typedef const char *(*dwarf_regname_lookup_ftype
) (unsigned int);
7926 static dwarf_regname_lookup_ftype dwarf_regnames_lookup_func
;
7927 static const char *const *dwarf_regnames
;
7928 static unsigned int dwarf_regnames_count
;
7931 /* A marker for a col_type that means this column was never referenced
7932 in the frame info. */
7933 #define DW_CFA_unreferenced (-1)
7935 /* Return 0 if no more space is needed, 1 if more space is needed,
7936 -1 for invalid reg. */
7939 frame_need_space (Frame_Chunk
*fc
, unsigned int reg
)
7941 unsigned int prev
= fc
->ncols
;
7943 if (reg
< (unsigned int) fc
->ncols
)
7946 if (dwarf_regnames_count
> 0
7947 && reg
> dwarf_regnames_count
)
7950 fc
->ncols
= reg
+ 1;
7951 /* PR 17512: file: 10450-2643-0.004.
7952 If reg == -1 then this can happen... */
7956 /* PR 17512: file: 2844a11d. */
7957 if (fc
->ncols
> 1024 && dwarf_regnames_count
== 0)
7959 error (_("Unfeasibly large register number: %u\n"), reg
);
7961 /* FIXME: 1024 is an arbitrary limit. Increase it if
7962 we ever encounter a valid binary that exceeds it. */
7966 fc
->col_type
= (short int *) xcrealloc (fc
->col_type
, fc
->ncols
,
7967 sizeof (short int));
7968 fc
->col_offset
= (int *) xcrealloc (fc
->col_offset
, fc
->ncols
, sizeof (int));
7969 /* PR 17512: file:002-10025-0.005. */
7970 if (fc
->col_type
== NULL
|| fc
->col_offset
== NULL
)
7972 error (_("Out of memory allocating %u columns in dwarf frame arrays\n"),
7978 while (prev
< fc
->ncols
)
7980 fc
->col_type
[prev
] = DW_CFA_unreferenced
;
7981 fc
->col_offset
[prev
] = 0;
7987 static const char *const dwarf_regnames_i386
[] =
7989 "eax", "ecx", "edx", "ebx", /* 0 - 3 */
7990 "esp", "ebp", "esi", "edi", /* 4 - 7 */
7991 "eip", "eflags", NULL
, /* 8 - 10 */
7992 "st0", "st1", "st2", "st3", /* 11 - 14 */
7993 "st4", "st5", "st6", "st7", /* 15 - 18 */
7994 NULL
, NULL
, /* 19 - 20 */
7995 "xmm0", "xmm1", "xmm2", "xmm3", /* 21 - 24 */
7996 "xmm4", "xmm5", "xmm6", "xmm7", /* 25 - 28 */
7997 "mm0", "mm1", "mm2", "mm3", /* 29 - 32 */
7998 "mm4", "mm5", "mm6", "mm7", /* 33 - 36 */
7999 "fcw", "fsw", "mxcsr", /* 37 - 39 */
8000 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
, /* 40 - 47 */
8001 "tr", "ldtr", /* 48 - 49 */
8002 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 50 - 57 */
8003 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 58 - 65 */
8004 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 66 - 73 */
8005 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 74 - 81 */
8006 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 82 - 89 */
8007 NULL
, NULL
, NULL
, /* 90 - 92 */
8008 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7" /* 93 - 100 */
8011 static const char *const dwarf_regnames_iamcu
[] =
8013 "eax", "ecx", "edx", "ebx", /* 0 - 3 */
8014 "esp", "ebp", "esi", "edi", /* 4 - 7 */
8015 "eip", "eflags", NULL
, /* 8 - 10 */
8016 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 11 - 18 */
8017 NULL
, NULL
, /* 19 - 20 */
8018 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 21 - 28 */
8019 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 29 - 36 */
8020 NULL
, NULL
, NULL
, /* 37 - 39 */
8021 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
, /* 40 - 47 */
8022 "tr", "ldtr", /* 48 - 49 */
8023 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 50 - 57 */
8024 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 58 - 65 */
8025 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 66 - 73 */
8026 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 74 - 81 */
8027 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 82 - 89 */
8028 NULL
, NULL
, NULL
, /* 90 - 92 */
8029 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
/* 93 - 100 */
8033 init_dwarf_regnames_i386 (void)
8035 dwarf_regnames
= dwarf_regnames_i386
;
8036 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_i386
);
8037 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8041 init_dwarf_regnames_iamcu (void)
8043 dwarf_regnames
= dwarf_regnames_iamcu
;
8044 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_iamcu
);
8045 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8048 static const char *const dwarf_regnames_x86_64
[] =
8050 "rax", "rdx", "rcx", "rbx",
8051 "rsi", "rdi", "rbp", "rsp",
8052 "r8", "r9", "r10", "r11",
8053 "r12", "r13", "r14", "r15",
8055 "xmm0", "xmm1", "xmm2", "xmm3",
8056 "xmm4", "xmm5", "xmm6", "xmm7",
8057 "xmm8", "xmm9", "xmm10", "xmm11",
8058 "xmm12", "xmm13", "xmm14", "xmm15",
8059 "st0", "st1", "st2", "st3",
8060 "st4", "st5", "st6", "st7",
8061 "mm0", "mm1", "mm2", "mm3",
8062 "mm4", "mm5", "mm6", "mm7",
8064 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
,
8065 "fs.base", "gs.base", NULL
, NULL
,
8067 "mxcsr", "fcw", "fsw",
8068 "xmm16", "xmm17", "xmm18", "xmm19",
8069 "xmm20", "xmm21", "xmm22", "xmm23",
8070 "xmm24", "xmm25", "xmm26", "xmm27",
8071 "xmm28", "xmm29", "xmm30", "xmm31",
8072 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 83 - 90 */
8073 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 91 - 98 */
8074 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 99 - 106 */
8075 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 107 - 114 */
8076 NULL
, NULL
, NULL
, /* 115 - 117 */
8077 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7"
8081 init_dwarf_regnames_x86_64 (void)
8083 dwarf_regnames
= dwarf_regnames_x86_64
;
8084 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_x86_64
);
8085 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8088 static const char *const dwarf_regnames_aarch64
[] =
8090 "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7",
8091 "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15",
8092 "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23",
8093 "x24", "x25", "x26", "x27", "x28", "x29", "x30", "sp",
8094 NULL
, "elr", NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
8095 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, "vg", "ffr",
8096 "p0", "p1", "p2", "p3", "p4", "p5", "p6", "p7",
8097 "p8", "p9", "p10", "p11", "p12", "p13", "p14", "p15",
8098 "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7",
8099 "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15",
8100 "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23",
8101 "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31",
8102 "z0", "z1", "z2", "z3", "z4", "z5", "z6", "z7",
8103 "z8", "z9", "z10", "z11", "z12", "z13", "z14", "z15",
8104 "z16", "z17", "z18", "z19", "z20", "z21", "z22", "z23",
8105 "z24", "z25", "z26", "z27", "z28", "z29", "z30", "z31",
8109 init_dwarf_regnames_aarch64 (void)
8111 dwarf_regnames
= dwarf_regnames_aarch64
;
8112 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_aarch64
);
8113 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8116 static const char *const dwarf_regnames_s390
[] =
8118 /* Avoid saying "r5 (r5)", so omit the names of r0-r15. */
8119 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
8120 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
8121 "f0", "f2", "f4", "f6", "f1", "f3", "f5", "f7",
8122 "f8", "f10", "f12", "f14", "f9", "f11", "f13", "f15",
8123 "cr0", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7",
8124 "cr8", "cr9", "cr10", "cr11", "cr12", "cr13", "cr14", "cr15",
8125 "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7",
8126 "a8", "a9", "a10", "a11", "a12", "a13", "a14", "a15",
8129 "v16", "v18", "v20", "v22", "v17", "v19", "v21", "v23",
8130 "v24", "v26", "v28", "v30", "v25", "v27", "v29", "v31",
8134 init_dwarf_regnames_s390 (void)
8136 dwarf_regnames
= dwarf_regnames_s390
;
8137 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_s390
);
8138 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8141 static const char *const dwarf_regnames_riscv
[] =
8143 "zero", "ra", "sp", "gp", "tp", "t0", "t1", "t2", /* 0 - 7 */
8144 "s0", "s1", "a0", "a1", "a2", "a3", "a4", "a5", /* 8 - 15 */
8145 "a6", "a7", "s2", "s3", "s4", "s5", "s6", "s7", /* 16 - 23 */
8146 "s8", "s9", "s10", "s11", "t3", "t4", "t5", "t6", /* 24 - 31 */
8147 "ft0", "ft1", "ft2", "ft3", "ft4", "ft5", "ft6", "ft7", /* 32 - 39 */
8148 "fs0", "fs1", /* 40 - 41 */
8149 "fa0", "fa1", "fa2", "fa3", "fa4", "fa5", "fa6", "fa7", /* 42 - 49 */
8150 "fs2", "fs3", "fs4", "fs5", "fs6", "fs7", "fs8", "fs9", /* 50 - 57 */
8151 "fs10", "fs11", /* 58 - 59 */
8152 "ft8", "ft9", "ft10", "ft11" /* 60 - 63 */
8155 /* A RISC-V replacement for REGNAME_INTERNAL_BY_TABLE_ONLY which handles
8156 the large number of CSRs. */
8159 regname_internal_riscv (unsigned int regno
)
8161 const char *name
= NULL
;
8163 /* Lookup in the table first, this covers GPR and FPR. */
8164 if (regno
< ARRAY_SIZE (dwarf_regnames_riscv
))
8165 name
= dwarf_regnames_riscv
[regno
];
8166 else if (regno
>= 4096 && regno
<= 8191)
8168 /* This might be a CSR, these live in a sparse number space from 4096
8169 to 8191 These numbers are defined in the RISC-V ELF ABI
8173 #define DECLARE_CSR(NAME,VALUE,CLASS,DEFINE_VER,ABORT_VER) \
8174 case VALUE + 4096: name = #NAME; break;
8175 #include "opcode/riscv-opc.h"
8180 static char csr_name
[10];
8181 snprintf (csr_name
, sizeof (csr_name
), "csr%d", (regno
- 4096));
8192 init_dwarf_regnames_riscv (void)
8194 dwarf_regnames
= NULL
;
8195 dwarf_regnames_count
= 8192;
8196 dwarf_regnames_lookup_func
= regname_internal_riscv
;
8200 init_dwarf_regnames_by_elf_machine_code (unsigned int e_machine
)
8202 dwarf_regnames_lookup_func
= NULL
;
8207 init_dwarf_regnames_i386 ();
8211 init_dwarf_regnames_iamcu ();
8217 init_dwarf_regnames_x86_64 ();
8221 init_dwarf_regnames_aarch64 ();
8225 init_dwarf_regnames_s390 ();
8229 init_dwarf_regnames_riscv ();
8237 /* Initialize the DWARF register name lookup state based on the
8238 architecture and specific machine type of a BFD. */
8241 init_dwarf_regnames_by_bfd_arch_and_mach (enum bfd_architecture arch
,
8244 dwarf_regnames_lookup_func
= NULL
;
8251 case bfd_mach_x86_64
:
8252 case bfd_mach_x86_64_intel_syntax
:
8253 case bfd_mach_x64_32
:
8254 case bfd_mach_x64_32_intel_syntax
:
8255 init_dwarf_regnames_x86_64 ();
8259 init_dwarf_regnames_i386 ();
8264 case bfd_arch_iamcu
:
8265 init_dwarf_regnames_iamcu ();
8268 case bfd_arch_aarch64
:
8269 init_dwarf_regnames_aarch64();
8273 init_dwarf_regnames_s390 ();
8276 case bfd_arch_riscv
:
8277 init_dwarf_regnames_riscv ();
8286 regname_internal_by_table_only (unsigned int regno
)
8288 if (dwarf_regnames
!= NULL
8289 && regno
< dwarf_regnames_count
8290 && dwarf_regnames
[regno
] != NULL
)
8291 return dwarf_regnames
[regno
];
8297 regname (unsigned int regno
, int name_only_p
)
8299 static char reg
[64];
8301 const char *name
= NULL
;
8303 if (dwarf_regnames_lookup_func
!= NULL
)
8304 name
= dwarf_regnames_lookup_func (regno
);
8310 snprintf (reg
, sizeof (reg
), "r%d (%s)", regno
, name
);
8313 snprintf (reg
, sizeof (reg
), "r%d", regno
);
8318 frame_display_row (Frame_Chunk
*fc
, int *need_col_headers
, unsigned int *max_regs
)
8323 if (*max_regs
!= fc
->ncols
)
8324 *max_regs
= fc
->ncols
;
8326 if (*need_col_headers
)
8328 *need_col_headers
= 0;
8330 printf ("%-*s CFA ", eh_addr_size
* 2, " LOC");
8332 for (r
= 0; r
< *max_regs
; r
++)
8333 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
8338 printf ("%-5s ", regname (r
, 1));
8344 print_dwarf_vma (fc
->pc_begin
, eh_addr_size
);
8346 strcpy (tmp
, "exp");
8348 sprintf (tmp
, "%s%+d", regname (fc
->cfa_reg
, 1), (int) fc
->cfa_offset
);
8349 printf ("%-8s ", tmp
);
8351 for (r
= 0; r
< fc
->ncols
; r
++)
8353 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
8355 switch (fc
->col_type
[r
])
8357 case DW_CFA_undefined
:
8360 case DW_CFA_same_value
:
8364 sprintf (tmp
, "c%+d", fc
->col_offset
[r
]);
8366 case DW_CFA_val_offset
:
8367 sprintf (tmp
, "v%+d", fc
->col_offset
[r
]);
8369 case DW_CFA_register
:
8370 sprintf (tmp
, "%s", regname (fc
->col_offset
[r
], 0));
8372 case DW_CFA_expression
:
8373 strcpy (tmp
, "exp");
8375 case DW_CFA_val_expression
:
8376 strcpy (tmp
, "vexp");
8379 strcpy (tmp
, "n/a");
8382 printf ("%-5s ", tmp
);
8388 #define GET(VAR, N) SAFE_BYTE_GET_AND_INC (VAR, start, N, end)
8390 static unsigned char *
8391 read_cie (unsigned char *start
, unsigned char *end
,
8392 Frame_Chunk
**p_cie
, int *p_version
,
8393 bfd_size_type
*p_aug_len
, unsigned char **p_aug
)
8397 unsigned char *augmentation_data
= NULL
;
8398 bfd_size_type augmentation_data_len
= 0;
8401 /* PR 17512: file: 001-228113-0.004. */
8405 fc
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
8406 memset (fc
, 0, sizeof (Frame_Chunk
));
8408 fc
->col_type
= (short int *) xmalloc (sizeof (short int));
8409 fc
->col_offset
= (int *) xmalloc (sizeof (int));
8413 fc
->augmentation
= (char *) start
;
8414 /* PR 17512: file: 001-228113-0.004.
8415 Skip past augmentation name, but avoid running off the end of the data. */
8417 if (* start
++ == '\0')
8421 warn (_("No terminator for augmentation name\n"));
8425 if (strcmp (fc
->augmentation
, "eh") == 0)
8426 start
+= eh_addr_size
;
8430 GET (fc
->ptr_size
, 1);
8431 if (fc
->ptr_size
< 1 || fc
->ptr_size
> 8)
8433 warn (_("Invalid pointer size (%d) in CIE data\n"), fc
->ptr_size
);
8437 GET (fc
->segment_size
, 1);
8438 /* PR 17512: file: e99d2804. */
8439 if (fc
->segment_size
> 8 || fc
->segment_size
+ fc
->ptr_size
> 8)
8441 warn (_("Invalid segment size (%d) in CIE data\n"), fc
->segment_size
);
8445 eh_addr_size
= fc
->ptr_size
;
8449 fc
->ptr_size
= eh_addr_size
;
8450 fc
->segment_size
= 0;
8453 READ_ULEB (fc
->code_factor
, start
, end
);
8454 READ_SLEB (fc
->data_factor
, start
, end
);
8462 READ_ULEB (fc
->ra
, start
, end
);
8465 if (fc
->augmentation
[0] == 'z')
8467 READ_ULEB (augmentation_data_len
, start
, end
);
8468 augmentation_data
= start
;
8469 /* PR 17512: file: 11042-2589-0.004. */
8470 if (augmentation_data_len
> (bfd_size_type
) (end
- start
))
8472 warn (_("Augmentation data too long: 0x%s, expected at most %#lx\n"),
8473 dwarf_vmatoa ("x", augmentation_data_len
),
8474 (unsigned long) (end
- start
));
8477 start
+= augmentation_data_len
;
8480 if (augmentation_data_len
)
8484 unsigned char *qend
;
8486 p
= (unsigned char *) fc
->augmentation
+ 1;
8487 q
= augmentation_data
;
8488 qend
= q
+ augmentation_data_len
;
8490 while (p
< end
&& q
< qend
)
8495 q
+= 1 + size_of_encoded_value (*q
);
8497 fc
->fde_encoding
= *q
++;
8506 /* Note - it is OK if this loop terminates with q < qend.
8507 Padding may have been inserted to align the end of the CIE. */
8512 *p_version
= version
;
8515 *p_aug_len
= augmentation_data_len
;
8516 *p_aug
= augmentation_data
;
8521 free (fc
->col_offset
);
8522 free (fc
->col_type
);
8527 /* Prints out the contents on the DATA array formatted as unsigned bytes.
8528 If do_wide is not enabled, then formats the output to fit into 80 columns.
8529 PRINTED contains the number of characters already written to the current
8533 display_data (bfd_size_type printed
,
8534 const unsigned char * data
,
8535 const bfd_size_type len
)
8537 if (do_wide
|| len
< ((80 - printed
) / 3))
8538 for (printed
= 0; printed
< len
; ++printed
)
8539 printf (" %02x", data
[printed
]);
8542 for (printed
= 0; printed
< len
; ++printed
)
8544 if (printed
% (80 / 3) == 0)
8546 printf (" %02x", data
[printed
]);
8551 /* Prints out the contents on the augmentation data array.
8552 If do_wide is not enabled, then formats the output to fit into 80 columns. */
8555 display_augmentation_data (const unsigned char * data
, const bfd_size_type len
)
8559 i
= printf (_(" Augmentation data: "));
8560 display_data (i
, data
, len
);
8564 display_debug_frames (struct dwarf_section
*section
,
8565 void *file ATTRIBUTE_UNUSED
)
8567 unsigned char *start
= section
->start
;
8568 unsigned char *end
= start
+ section
->size
;
8569 unsigned char *section_start
= start
;
8570 Frame_Chunk
*chunks
= NULL
, *forward_refs
= NULL
;
8571 Frame_Chunk
*remembered_state
= NULL
;
8573 bool is_eh
= strcmp (section
->name
, ".eh_frame") == 0;
8574 unsigned int max_regs
= 0;
8575 const char *bad_reg
= _("bad register: ");
8576 unsigned int saved_eh_addr_size
= eh_addr_size
;
8578 introduce (section
, false);
8582 unsigned char *saved_start
;
8583 unsigned char *block_end
;
8588 int need_col_headers
= 1;
8589 unsigned char *augmentation_data
= NULL
;
8590 bfd_size_type augmentation_data_len
= 0;
8591 unsigned int encoded_ptr_size
= saved_eh_addr_size
;
8592 unsigned int offset_size
;
8593 unsigned int initial_length_size
;
8595 static Frame_Chunk fde_fc
;
8597 saved_start
= start
;
8599 SAFE_BYTE_GET_AND_INC (length
, start
, 4, end
);
8603 printf ("\n%08lx ZERO terminator\n\n",
8604 (unsigned long)(saved_start
- section_start
));
8605 /* Skip any zero terminators that directly follow.
8606 A corrupt section size could have loaded a whole
8607 slew of zero filled memory bytes. eg
8608 PR 17512: file: 070-19381-0.004. */
8609 while (start
< end
&& * start
== 0)
8614 if (length
== 0xffffffff)
8616 SAFE_BYTE_GET_AND_INC (length
, start
, 8, end
);
8618 initial_length_size
= 12;
8623 initial_length_size
= 4;
8626 block_end
= saved_start
+ length
+ initial_length_size
;
8627 if (block_end
> end
|| block_end
< start
)
8629 warn ("Invalid length 0x%s in FDE at %#08lx\n",
8630 dwarf_vmatoa_1 (NULL
, length
, offset_size
),
8631 (unsigned long) (saved_start
- section_start
));
8635 SAFE_BYTE_GET_AND_INC (cie_id
, start
, offset_size
, end
);
8637 if (is_eh
? (cie_id
== 0) : ((offset_size
== 4 && cie_id
== DW_CIE_ID
)
8638 || (offset_size
== 8 && cie_id
== DW64_CIE_ID
)))
8643 start
= read_cie (start
, end
, &cie
, &version
,
8644 &augmentation_data_len
, &augmentation_data
);
8645 /* PR 17512: file: 027-135133-0.005. */
8652 fc
->chunk_start
= saved_start
;
8653 mreg
= max_regs
> 0 ? max_regs
- 1 : 0;
8656 if (frame_need_space (fc
, mreg
) < 0)
8658 if (fc
->fde_encoding
)
8659 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
8661 printf ("\n%08lx ", (unsigned long) (saved_start
- section_start
));
8662 print_dwarf_vma (length
, fc
->ptr_size
);
8663 print_dwarf_vma (cie_id
, offset_size
);
8665 if (do_debug_frames_interp
)
8667 printf ("CIE \"%s\" cf=%d df=%d ra=%d\n", fc
->augmentation
,
8668 fc
->code_factor
, fc
->data_factor
, fc
->ra
);
8673 printf (" Version: %d\n", version
);
8674 printf (" Augmentation: \"%s\"\n", fc
->augmentation
);
8677 printf (" Pointer Size: %u\n", fc
->ptr_size
);
8678 printf (" Segment Size: %u\n", fc
->segment_size
);
8680 printf (" Code alignment factor: %u\n", fc
->code_factor
);
8681 printf (" Data alignment factor: %d\n", fc
->data_factor
);
8682 printf (" Return address column: %d\n", fc
->ra
);
8684 if (augmentation_data_len
)
8685 display_augmentation_data (augmentation_data
, augmentation_data_len
);
8692 unsigned char *look_for
;
8693 unsigned long segment_selector
;
8699 dwarf_vma sign
= (dwarf_vma
) 1 << (offset_size
* 8 - 1);
8700 cie_off
= (cie_off
^ sign
) - sign
;
8701 cie_off
= start
- 4 - section_start
- cie_off
;
8704 look_for
= section_start
+ cie_off
;
8705 if (cie_off
<= (dwarf_vma
) (saved_start
- section_start
))
8707 for (cie
= chunks
; cie
; cie
= cie
->next
)
8708 if (cie
->chunk_start
== look_for
)
8713 for (cie
= forward_refs
; cie
; cie
= cie
->next
)
8714 if (cie
->chunk_start
== look_for
)
8718 unsigned int off_size
;
8719 unsigned char *cie_scan
;
8721 cie_scan
= look_for
;
8723 SAFE_BYTE_GET_AND_INC (length
, cie_scan
, 4, end
);
8724 if (length
== 0xffffffff)
8726 SAFE_BYTE_GET_AND_INC (length
, cie_scan
, 8, end
);
8733 SAFE_BYTE_GET_AND_INC (c_id
, cie_scan
, off_size
, end
);
8736 : ((off_size
== 4 && c_id
== DW_CIE_ID
)
8737 || (off_size
== 8 && c_id
== DW64_CIE_ID
)))
8742 read_cie (cie_scan
, end
, &cie
, &version
,
8743 &augmentation_data_len
, &augmentation_data
);
8744 /* PR 17512: file: 3450-2098-0.004. */
8747 warn (_("Failed to read CIE information\n"));
8750 cie
->next
= forward_refs
;
8752 cie
->chunk_start
= look_for
;
8753 mreg
= max_regs
> 0 ? max_regs
- 1 : 0;
8756 if (frame_need_space (cie
, mreg
) < 0)
8758 warn (_("Invalid max register\n"));
8761 if (cie
->fde_encoding
)
8763 = size_of_encoded_value (cie
->fde_encoding
);
8770 memset (fc
, 0, sizeof (Frame_Chunk
));
8774 warn ("Invalid CIE pointer 0x%s in FDE at %#08lx\n",
8775 dwarf_vmatoa_1 (NULL
, cie_id
, offset_size
),
8776 (unsigned long) (saved_start
- section_start
));
8778 fc
->col_type
= (short int *) xmalloc (sizeof (short int));
8779 fc
->col_offset
= (int *) xmalloc (sizeof (int));
8780 if (frame_need_space (fc
, max_regs
> 0 ? max_regs
- 1 : 0) < 0)
8782 warn (_("Invalid max register\n"));
8786 fc
->augmentation
= "";
8787 fc
->fde_encoding
= 0;
8788 fc
->ptr_size
= eh_addr_size
;
8789 fc
->segment_size
= 0;
8793 fc
->ncols
= cie
->ncols
;
8794 fc
->col_type
= (short int *) xcmalloc (fc
->ncols
, sizeof (short int));
8795 fc
->col_offset
= (int *) xcmalloc (fc
->ncols
, sizeof (int));
8796 memcpy (fc
->col_type
, cie
->col_type
, fc
->ncols
* sizeof (short int));
8797 memcpy (fc
->col_offset
, cie
->col_offset
, fc
->ncols
* sizeof (int));
8798 fc
->augmentation
= cie
->augmentation
;
8799 fc
->ptr_size
= cie
->ptr_size
;
8800 eh_addr_size
= cie
->ptr_size
;
8801 fc
->segment_size
= cie
->segment_size
;
8802 fc
->code_factor
= cie
->code_factor
;
8803 fc
->data_factor
= cie
->data_factor
;
8804 fc
->cfa_reg
= cie
->cfa_reg
;
8805 fc
->cfa_offset
= cie
->cfa_offset
;
8807 if (frame_need_space (fc
, max_regs
> 0 ? max_regs
- 1: 0) < 0)
8809 warn (_("Invalid max register\n"));
8812 fc
->fde_encoding
= cie
->fde_encoding
;
8815 if (fc
->fde_encoding
)
8816 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
8818 segment_selector
= 0;
8819 if (fc
->segment_size
)
8821 if (fc
->segment_size
> sizeof (segment_selector
))
8823 /* PR 17512: file: 9e196b3e. */
8824 warn (_("Probably corrupt segment size: %d - using 4 instead\n"), fc
->segment_size
);
8825 fc
->segment_size
= 4;
8827 SAFE_BYTE_GET_AND_INC (segment_selector
, start
, fc
->segment_size
, end
);
8830 fc
->pc_begin
= get_encoded_value (&start
, fc
->fde_encoding
, section
, end
);
8832 /* FIXME: It appears that sometimes the final pc_range value is
8833 encoded in less than encoded_ptr_size bytes. See the x86_64
8834 run of the "objcopy on compressed debug sections" test for an
8836 SAFE_BYTE_GET_AND_INC (fc
->pc_range
, start
, encoded_ptr_size
, end
);
8838 if (cie
->augmentation
[0] == 'z')
8840 READ_ULEB (augmentation_data_len
, start
, end
);
8841 augmentation_data
= start
;
8842 /* PR 17512 file: 722-8446-0.004 and PR 22386. */
8843 if (augmentation_data_len
> (bfd_size_type
) (end
- start
))
8845 warn (_("Augmentation data too long: 0x%s, "
8846 "expected at most %#lx\n"),
8847 dwarf_vmatoa ("x", augmentation_data_len
),
8848 (unsigned long) (end
- start
));
8850 augmentation_data
= NULL
;
8851 augmentation_data_len
= 0;
8853 start
+= augmentation_data_len
;
8856 printf ("\n%08lx %s %s FDE cie=%08lx pc=",
8857 (unsigned long)(saved_start
- section_start
),
8858 dwarf_vmatoa_1 (NULL
, length
, fc
->ptr_size
),
8859 dwarf_vmatoa_1 (NULL
, cie_id
, offset_size
),
8860 (unsigned long)(cie
->chunk_start
- section_start
));
8862 if (fc
->segment_size
)
8863 printf ("%04lx:", segment_selector
);
8866 dwarf_vmatoa_1 (NULL
, fc
->pc_begin
, fc
->ptr_size
),
8867 dwarf_vmatoa_1 (NULL
, fc
->pc_begin
+ fc
->pc_range
, fc
->ptr_size
));
8869 if (! do_debug_frames_interp
&& augmentation_data_len
)
8871 display_augmentation_data (augmentation_data
, augmentation_data_len
);
8876 /* At this point, fc is the current chunk, cie (if any) is set, and
8877 we're about to interpret instructions for the chunk. */
8878 /* ??? At present we need to do this always, since this sizes the
8879 fc->col_type and fc->col_offset arrays, which we write into always.
8880 We should probably split the interpreted and non-interpreted bits
8881 into two different routines, since there's so much that doesn't
8882 really overlap between them. */
8883 if (1 || do_debug_frames_interp
)
8885 /* Start by making a pass over the chunk, allocating storage
8886 and taking note of what registers are used. */
8887 unsigned char *tmp
= start
;
8889 while (start
< block_end
)
8891 unsigned int reg
, op
, opa
;
8893 unsigned char * new_start
;
8900 /* Warning: if you add any more cases to this switch, be
8901 sure to add them to the corresponding switch below. */
8904 case DW_CFA_advance_loc
:
8907 SKIP_ULEB (start
, end
);
8908 if (frame_need_space (fc
, opa
) >= 0)
8909 fc
->col_type
[opa
] = DW_CFA_undefined
;
8911 case DW_CFA_restore
:
8912 if (frame_need_space (fc
, opa
) >= 0)
8913 fc
->col_type
[opa
] = DW_CFA_undefined
;
8915 case DW_CFA_set_loc
:
8916 start
+= encoded_ptr_size
;
8918 case DW_CFA_advance_loc1
:
8921 case DW_CFA_advance_loc2
:
8924 case DW_CFA_advance_loc4
:
8927 case DW_CFA_offset_extended
:
8928 case DW_CFA_val_offset
:
8929 READ_ULEB (reg
, start
, end
);
8930 SKIP_ULEB (start
, end
);
8931 if (frame_need_space (fc
, reg
) >= 0)
8932 fc
->col_type
[reg
] = DW_CFA_undefined
;
8934 case DW_CFA_restore_extended
:
8935 READ_ULEB (reg
, start
, end
);
8936 if (frame_need_space (fc
, reg
) >= 0)
8937 fc
->col_type
[reg
] = DW_CFA_undefined
;
8939 case DW_CFA_undefined
:
8940 READ_ULEB (reg
, start
, end
);
8941 if (frame_need_space (fc
, reg
) >= 0)
8942 fc
->col_type
[reg
] = DW_CFA_undefined
;
8944 case DW_CFA_same_value
:
8945 READ_ULEB (reg
, start
, end
);
8946 if (frame_need_space (fc
, reg
) >= 0)
8947 fc
->col_type
[reg
] = DW_CFA_undefined
;
8949 case DW_CFA_register
:
8950 READ_ULEB (reg
, start
, end
);
8951 SKIP_ULEB (start
, end
);
8952 if (frame_need_space (fc
, reg
) >= 0)
8953 fc
->col_type
[reg
] = DW_CFA_undefined
;
8955 case DW_CFA_def_cfa
:
8956 SKIP_ULEB (start
, end
);
8957 SKIP_ULEB (start
, end
);
8959 case DW_CFA_def_cfa_register
:
8960 SKIP_ULEB (start
, end
);
8962 case DW_CFA_def_cfa_offset
:
8963 SKIP_ULEB (start
, end
);
8965 case DW_CFA_def_cfa_expression
:
8966 READ_ULEB (temp
, start
, end
);
8967 new_start
= start
+ temp
;
8968 if (new_start
< start
)
8970 warn (_("Corrupt CFA_def expression value: %lu\n"), temp
);
8976 case DW_CFA_expression
:
8977 case DW_CFA_val_expression
:
8978 READ_ULEB (reg
, start
, end
);
8979 READ_ULEB (temp
, start
, end
);
8980 new_start
= start
+ temp
;
8981 if (new_start
< start
)
8983 /* PR 17512: file:306-192417-0.005. */
8984 warn (_("Corrupt CFA expression value: %lu\n"), temp
);
8989 if (frame_need_space (fc
, reg
) >= 0)
8990 fc
->col_type
[reg
] = DW_CFA_undefined
;
8992 case DW_CFA_offset_extended_sf
:
8993 case DW_CFA_val_offset_sf
:
8994 READ_ULEB (reg
, start
, end
);
8995 SKIP_SLEB (start
, end
);
8996 if (frame_need_space (fc
, reg
) >= 0)
8997 fc
->col_type
[reg
] = DW_CFA_undefined
;
8999 case DW_CFA_def_cfa_sf
:
9000 SKIP_ULEB (start
, end
);
9001 SKIP_SLEB (start
, end
);
9003 case DW_CFA_def_cfa_offset_sf
:
9004 SKIP_SLEB (start
, end
);
9006 case DW_CFA_MIPS_advance_loc8
:
9009 case DW_CFA_GNU_args_size
:
9010 SKIP_ULEB (start
, end
);
9012 case DW_CFA_GNU_negative_offset_extended
:
9013 READ_ULEB (reg
, start
, end
);
9014 SKIP_ULEB (start
, end
);
9015 if (frame_need_space (fc
, reg
) >= 0)
9016 fc
->col_type
[reg
] = DW_CFA_undefined
;
9027 /* Now we know what registers are used, make a second pass over
9028 the chunk, this time actually printing out the info. */
9030 while (start
< block_end
)
9032 unsigned char * tmp
;
9034 unsigned long ul
, roffs
;
9035 /* Note: It is tempting to use an unsigned long for 'reg' but there
9036 are various functions, notably frame_space_needed() that assume that
9037 reg is an unsigned int. */
9042 const char *reg_prefix
= "";
9049 /* Make a note if something other than DW_CFA_nop happens. */
9050 if (op
!= DW_CFA_nop
)
9053 /* Warning: if you add any more cases to this switch, be
9054 sure to add them to the corresponding switch above. */
9057 case DW_CFA_advance_loc
:
9058 if (do_debug_frames_interp
)
9059 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9061 printf (" DW_CFA_advance_loc: %d to %s\n",
9062 opa
* fc
->code_factor
,
9063 dwarf_vmatoa_1 (NULL
,
9064 fc
->pc_begin
+ opa
* fc
->code_factor
,
9066 fc
->pc_begin
+= opa
* fc
->code_factor
;
9070 READ_ULEB (roffs
, start
, end
);
9071 if (opa
>= (unsigned int) fc
->ncols
)
9072 reg_prefix
= bad_reg
;
9073 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9074 printf (" DW_CFA_offset: %s%s at cfa%+ld\n",
9075 reg_prefix
, regname (opa
, 0),
9076 roffs
* fc
->data_factor
);
9077 if (*reg_prefix
== '\0')
9079 fc
->col_type
[opa
] = DW_CFA_offset
;
9080 fc
->col_offset
[opa
] = roffs
* fc
->data_factor
;
9084 case DW_CFA_restore
:
9085 if (opa
>= (unsigned int) fc
->ncols
)
9086 reg_prefix
= bad_reg
;
9087 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9088 printf (" DW_CFA_restore: %s%s\n",
9089 reg_prefix
, regname (opa
, 0));
9090 if (*reg_prefix
!= '\0')
9093 if (opa
>= (unsigned int) cie
->ncols
9094 || (do_debug_frames_interp
9095 && cie
->col_type
[opa
] == DW_CFA_unreferenced
))
9097 fc
->col_type
[opa
] = DW_CFA_undefined
;
9098 fc
->col_offset
[opa
] = 0;
9102 fc
->col_type
[opa
] = cie
->col_type
[opa
];
9103 fc
->col_offset
[opa
] = cie
->col_offset
[opa
];
9107 case DW_CFA_set_loc
:
9108 vma
= get_encoded_value (&start
, fc
->fde_encoding
, section
, block_end
);
9109 if (do_debug_frames_interp
)
9110 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9112 printf (" DW_CFA_set_loc: %s\n",
9113 dwarf_vmatoa_1 (NULL
, vma
, fc
->ptr_size
));
9117 case DW_CFA_advance_loc1
:
9118 SAFE_BYTE_GET_AND_INC (ofs
, start
, 1, end
);
9119 if (do_debug_frames_interp
)
9120 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9122 printf (" DW_CFA_advance_loc1: %ld to %s\n",
9123 (unsigned long) (ofs
* fc
->code_factor
),
9124 dwarf_vmatoa_1 (NULL
,
9125 fc
->pc_begin
+ ofs
* fc
->code_factor
,
9127 fc
->pc_begin
+= ofs
* fc
->code_factor
;
9130 case DW_CFA_advance_loc2
:
9131 SAFE_BYTE_GET_AND_INC (ofs
, start
, 2, block_end
);
9132 if (do_debug_frames_interp
)
9133 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9135 printf (" DW_CFA_advance_loc2: %ld to %s\n",
9136 (unsigned long) (ofs
* fc
->code_factor
),
9137 dwarf_vmatoa_1 (NULL
,
9138 fc
->pc_begin
+ ofs
* fc
->code_factor
,
9140 fc
->pc_begin
+= ofs
* fc
->code_factor
;
9143 case DW_CFA_advance_loc4
:
9144 SAFE_BYTE_GET_AND_INC (ofs
, start
, 4, block_end
);
9145 if (do_debug_frames_interp
)
9146 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9148 printf (" DW_CFA_advance_loc4: %ld to %s\n",
9149 (unsigned long) (ofs
* fc
->code_factor
),
9150 dwarf_vmatoa_1 (NULL
,
9151 fc
->pc_begin
+ ofs
* fc
->code_factor
,
9153 fc
->pc_begin
+= ofs
* fc
->code_factor
;
9156 case DW_CFA_offset_extended
:
9157 READ_ULEB (reg
, start
, end
);
9158 READ_ULEB (roffs
, start
, end
);
9159 if (reg
>= (unsigned int) fc
->ncols
)
9160 reg_prefix
= bad_reg
;
9161 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9162 printf (" DW_CFA_offset_extended: %s%s at cfa%+ld\n",
9163 reg_prefix
, regname (reg
, 0),
9164 roffs
* fc
->data_factor
);
9165 if (*reg_prefix
== '\0')
9167 fc
->col_type
[reg
] = DW_CFA_offset
;
9168 fc
->col_offset
[reg
] = roffs
* fc
->data_factor
;
9172 case DW_CFA_val_offset
:
9173 READ_ULEB (reg
, start
, end
);
9174 READ_ULEB (roffs
, start
, end
);
9175 if (reg
>= (unsigned int) fc
->ncols
)
9176 reg_prefix
= bad_reg
;
9177 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9178 printf (" DW_CFA_val_offset: %s%s is cfa%+ld\n",
9179 reg_prefix
, regname (reg
, 0),
9180 roffs
* fc
->data_factor
);
9181 if (*reg_prefix
== '\0')
9183 fc
->col_type
[reg
] = DW_CFA_val_offset
;
9184 fc
->col_offset
[reg
] = roffs
* fc
->data_factor
;
9188 case DW_CFA_restore_extended
:
9189 READ_ULEB (reg
, start
, end
);
9190 if (reg
>= (unsigned int) fc
->ncols
)
9191 reg_prefix
= bad_reg
;
9192 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9193 printf (" DW_CFA_restore_extended: %s%s\n",
9194 reg_prefix
, regname (reg
, 0));
9195 if (*reg_prefix
!= '\0')
9198 if (reg
>= (unsigned int) cie
->ncols
)
9200 fc
->col_type
[reg
] = DW_CFA_undefined
;
9201 fc
->col_offset
[reg
] = 0;
9205 fc
->col_type
[reg
] = cie
->col_type
[reg
];
9206 fc
->col_offset
[reg
] = cie
->col_offset
[reg
];
9210 case DW_CFA_undefined
:
9211 READ_ULEB (reg
, start
, end
);
9212 if (reg
>= (unsigned int) fc
->ncols
)
9213 reg_prefix
= bad_reg
;
9214 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9215 printf (" DW_CFA_undefined: %s%s\n",
9216 reg_prefix
, regname (reg
, 0));
9217 if (*reg_prefix
== '\0')
9219 fc
->col_type
[reg
] = DW_CFA_undefined
;
9220 fc
->col_offset
[reg
] = 0;
9224 case DW_CFA_same_value
:
9225 READ_ULEB (reg
, start
, end
);
9226 if (reg
>= (unsigned int) fc
->ncols
)
9227 reg_prefix
= bad_reg
;
9228 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9229 printf (" DW_CFA_same_value: %s%s\n",
9230 reg_prefix
, regname (reg
, 0));
9231 if (*reg_prefix
== '\0')
9233 fc
->col_type
[reg
] = DW_CFA_same_value
;
9234 fc
->col_offset
[reg
] = 0;
9238 case DW_CFA_register
:
9239 READ_ULEB (reg
, start
, end
);
9240 READ_ULEB (roffs
, start
, end
);
9241 if (reg
>= (unsigned int) fc
->ncols
)
9242 reg_prefix
= bad_reg
;
9243 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9245 printf (" DW_CFA_register: %s%s in ",
9246 reg_prefix
, regname (reg
, 0));
9247 puts (regname (roffs
, 0));
9249 if (*reg_prefix
== '\0')
9251 fc
->col_type
[reg
] = DW_CFA_register
;
9252 fc
->col_offset
[reg
] = roffs
;
9256 case DW_CFA_remember_state
:
9257 if (! do_debug_frames_interp
)
9258 printf (" DW_CFA_remember_state\n");
9259 rs
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
9260 rs
->cfa_offset
= fc
->cfa_offset
;
9261 rs
->cfa_reg
= fc
->cfa_reg
;
9263 rs
->cfa_exp
= fc
->cfa_exp
;
9264 rs
->ncols
= fc
->ncols
;
9265 rs
->col_type
= (short int *) xcmalloc (rs
->ncols
,
9266 sizeof (* rs
->col_type
));
9267 rs
->col_offset
= (int *) xcmalloc (rs
->ncols
, sizeof (* rs
->col_offset
));
9268 memcpy (rs
->col_type
, fc
->col_type
, rs
->ncols
* sizeof (* fc
->col_type
));
9269 memcpy (rs
->col_offset
, fc
->col_offset
, rs
->ncols
* sizeof (* fc
->col_offset
));
9270 rs
->next
= remembered_state
;
9271 remembered_state
= rs
;
9274 case DW_CFA_restore_state
:
9275 if (! do_debug_frames_interp
)
9276 printf (" DW_CFA_restore_state\n");
9277 rs
= remembered_state
;
9280 remembered_state
= rs
->next
;
9281 fc
->cfa_offset
= rs
->cfa_offset
;
9282 fc
->cfa_reg
= rs
->cfa_reg
;
9284 fc
->cfa_exp
= rs
->cfa_exp
;
9285 if (frame_need_space (fc
, rs
->ncols
- 1) < 0)
9287 warn (_("Invalid column number in saved frame state\n"));
9291 memcpy (fc
->col_type
, rs
->col_type
, rs
->ncols
* sizeof (* rs
->col_type
));
9292 memcpy (fc
->col_offset
, rs
->col_offset
,
9293 rs
->ncols
* sizeof (* rs
->col_offset
));
9294 free (rs
->col_type
);
9295 free (rs
->col_offset
);
9298 else if (do_debug_frames_interp
)
9299 printf ("Mismatched DW_CFA_restore_state\n");
9302 case DW_CFA_def_cfa
:
9303 READ_ULEB (fc
->cfa_reg
, start
, end
);
9304 READ_ULEB (fc
->cfa_offset
, start
, end
);
9306 if (! do_debug_frames_interp
)
9307 printf (" DW_CFA_def_cfa: %s ofs %d\n",
9308 regname (fc
->cfa_reg
, 0), (int) fc
->cfa_offset
);
9311 case DW_CFA_def_cfa_register
:
9312 READ_ULEB (fc
->cfa_reg
, start
, end
);
9314 if (! do_debug_frames_interp
)
9315 printf (" DW_CFA_def_cfa_register: %s\n",
9316 regname (fc
->cfa_reg
, 0));
9319 case DW_CFA_def_cfa_offset
:
9320 READ_ULEB (fc
->cfa_offset
, start
, end
);
9321 if (! do_debug_frames_interp
)
9322 printf (" DW_CFA_def_cfa_offset: %d\n", (int) fc
->cfa_offset
);
9326 if (! do_debug_frames_interp
)
9327 printf (" DW_CFA_nop\n");
9330 case DW_CFA_def_cfa_expression
:
9331 READ_ULEB (ul
, start
, end
);
9332 if (start
>= block_end
|| ul
> (unsigned long) (block_end
- start
))
9334 printf (_(" DW_CFA_def_cfa_expression: <corrupt len %lu>\n"), ul
);
9337 if (! do_debug_frames_interp
)
9339 printf (" DW_CFA_def_cfa_expression (");
9340 decode_location_expression (start
, eh_addr_size
, 0, -1,
9348 case DW_CFA_expression
:
9349 READ_ULEB (reg
, start
, end
);
9350 READ_ULEB (ul
, start
, end
);
9351 if (reg
>= (unsigned int) fc
->ncols
)
9352 reg_prefix
= bad_reg
;
9353 /* PR 17512: file: 069-133014-0.006. */
9354 /* PR 17512: file: 98c02eb4. */
9356 if (start
>= block_end
|| tmp
> block_end
|| tmp
< start
)
9358 printf (_(" DW_CFA_expression: <corrupt len %lu>\n"), ul
);
9361 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9363 printf (" DW_CFA_expression: %s%s (",
9364 reg_prefix
, regname (reg
, 0));
9365 decode_location_expression (start
, eh_addr_size
, 0, -1,
9369 if (*reg_prefix
== '\0')
9370 fc
->col_type
[reg
] = DW_CFA_expression
;
9374 case DW_CFA_val_expression
:
9375 READ_ULEB (reg
, start
, end
);
9376 READ_ULEB (ul
, start
, end
);
9377 if (reg
>= (unsigned int) fc
->ncols
)
9378 reg_prefix
= bad_reg
;
9380 if (start
>= block_end
|| tmp
> block_end
|| tmp
< start
)
9382 printf (" DW_CFA_val_expression: <corrupt len %lu>\n", ul
);
9385 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9387 printf (" DW_CFA_val_expression: %s%s (",
9388 reg_prefix
, regname (reg
, 0));
9389 decode_location_expression (start
, eh_addr_size
, 0, -1,
9393 if (*reg_prefix
== '\0')
9394 fc
->col_type
[reg
] = DW_CFA_val_expression
;
9398 case DW_CFA_offset_extended_sf
:
9399 READ_ULEB (reg
, start
, end
);
9400 READ_SLEB (l
, start
, end
);
9401 if (frame_need_space (fc
, reg
) < 0)
9402 reg_prefix
= bad_reg
;
9403 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9404 printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+ld\n",
9405 reg_prefix
, regname (reg
, 0),
9406 (long)(l
* fc
->data_factor
));
9407 if (*reg_prefix
== '\0')
9409 fc
->col_type
[reg
] = DW_CFA_offset
;
9410 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
9414 case DW_CFA_val_offset_sf
:
9415 READ_ULEB (reg
, start
, end
);
9416 READ_SLEB (l
, start
, end
);
9417 if (frame_need_space (fc
, reg
) < 0)
9418 reg_prefix
= bad_reg
;
9419 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9420 printf (" DW_CFA_val_offset_sf: %s%s is cfa%+ld\n",
9421 reg_prefix
, regname (reg
, 0),
9422 (long)(l
* fc
->data_factor
));
9423 if (*reg_prefix
== '\0')
9425 fc
->col_type
[reg
] = DW_CFA_val_offset
;
9426 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
9430 case DW_CFA_def_cfa_sf
:
9431 READ_ULEB (fc
->cfa_reg
, start
, end
);
9432 READ_ULEB (fc
->cfa_offset
, start
, end
);
9433 fc
->cfa_offset
= fc
->cfa_offset
* fc
->data_factor
;
9435 if (! do_debug_frames_interp
)
9436 printf (" DW_CFA_def_cfa_sf: %s ofs %d\n",
9437 regname (fc
->cfa_reg
, 0), (int) fc
->cfa_offset
);
9440 case DW_CFA_def_cfa_offset_sf
:
9441 READ_ULEB (fc
->cfa_offset
, start
, end
);
9442 fc
->cfa_offset
*= fc
->data_factor
;
9443 if (! do_debug_frames_interp
)
9444 printf (" DW_CFA_def_cfa_offset_sf: %d\n", (int) fc
->cfa_offset
);
9447 case DW_CFA_MIPS_advance_loc8
:
9448 SAFE_BYTE_GET_AND_INC (ofs
, start
, 8, block_end
);
9449 if (do_debug_frames_interp
)
9450 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9452 printf (" DW_CFA_MIPS_advance_loc8: %ld to %s\n",
9453 (unsigned long) (ofs
* fc
->code_factor
),
9454 dwarf_vmatoa_1 (NULL
,
9455 fc
->pc_begin
+ ofs
* fc
->code_factor
,
9457 fc
->pc_begin
+= ofs
* fc
->code_factor
;
9460 case DW_CFA_GNU_window_save
:
9461 if (! do_debug_frames_interp
)
9462 printf (" DW_CFA_GNU_window_save\n");
9465 case DW_CFA_GNU_args_size
:
9466 READ_ULEB (ul
, start
, end
);
9467 if (! do_debug_frames_interp
)
9468 printf (" DW_CFA_GNU_args_size: %ld\n", ul
);
9471 case DW_CFA_GNU_negative_offset_extended
:
9472 READ_ULEB (reg
, start
, end
);
9473 READ_SLEB (l
, start
, end
);
9475 if (frame_need_space (fc
, reg
) < 0)
9476 reg_prefix
= bad_reg
;
9477 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9478 printf (" DW_CFA_GNU_negative_offset_extended: %s%s at cfa%+ld\n",
9479 reg_prefix
, regname (reg
, 0),
9480 (long)(l
* fc
->data_factor
));
9481 if (*reg_prefix
== '\0')
9483 fc
->col_type
[reg
] = DW_CFA_offset
;
9484 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
9489 if (op
>= DW_CFA_lo_user
&& op
<= DW_CFA_hi_user
)
9490 printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op
);
9492 warn (_("Unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op
);
9497 /* Interpret the CFA - as long as it is not completely full of NOPs. */
9498 if (do_debug_frames_interp
&& ! all_nops
)
9499 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9501 if (fde_fc
.col_type
!= NULL
)
9503 free (fde_fc
.col_type
);
9504 fde_fc
.col_type
= NULL
;
9506 if (fde_fc
.col_offset
!= NULL
)
9508 free (fde_fc
.col_offset
);
9509 fde_fc
.col_offset
= NULL
;
9513 eh_addr_size
= saved_eh_addr_size
;
9518 while (remembered_state
!= NULL
)
9520 rs
= remembered_state
;
9521 remembered_state
= rs
->next
;
9522 free (rs
->col_type
);
9523 free (rs
->col_offset
);
9524 rs
->next
= NULL
; /* Paranoia. */
9528 while (chunks
!= NULL
)
9532 free (rs
->col_type
);
9533 free (rs
->col_offset
);
9534 rs
->next
= NULL
; /* Paranoia. */
9538 while (forward_refs
!= NULL
)
9541 forward_refs
= rs
->next
;
9542 free (rs
->col_type
);
9543 free (rs
->col_offset
);
9544 rs
->next
= NULL
; /* Paranoia. */
9554 display_debug_names (struct dwarf_section
*section
, void *file
)
9556 unsigned char *hdrptr
= section
->start
;
9557 dwarf_vma unit_length
;
9558 unsigned char *unit_start
;
9559 const unsigned char *const section_end
= section
->start
+ section
->size
;
9560 unsigned char *unit_end
;
9562 introduce (section
, false);
9564 load_debug_section_with_follow (str
, file
);
9566 for (; hdrptr
< section_end
; hdrptr
= unit_end
)
9568 unsigned int offset_size
;
9569 uint16_t dwarf_version
, padding
;
9570 uint32_t comp_unit_count
, local_type_unit_count
, foreign_type_unit_count
;
9571 uint32_t bucket_count
, name_count
, abbrev_table_size
;
9572 uint32_t augmentation_string_size
;
9574 unsigned long sec_off
;
9575 bool augmentation_printable
;
9576 const char *augmentation_string
;
9578 unit_start
= hdrptr
;
9580 /* Get and check the length of the block. */
9581 SAFE_BYTE_GET_AND_INC (unit_length
, hdrptr
, 4, section_end
);
9583 if (unit_length
== 0xffffffff)
9585 /* This section is 64-bit DWARF. */
9586 SAFE_BYTE_GET_AND_INC (unit_length
, hdrptr
, 8, section_end
);
9591 unit_end
= hdrptr
+ unit_length
;
9593 sec_off
= hdrptr
- section
->start
;
9594 if (sec_off
+ unit_length
< sec_off
9595 || sec_off
+ unit_length
> section
->size
)
9597 warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"),
9599 (unsigned long) (unit_start
- section
->start
),
9600 dwarf_vmatoa ("x", unit_length
));
9604 /* Get and check the version number. */
9605 SAFE_BYTE_GET_AND_INC (dwarf_version
, hdrptr
, 2, unit_end
);
9606 printf (_("Version %ld\n"), (long) dwarf_version
);
9608 /* Prior versions did not exist, and future versions may not be
9609 backwards compatible. */
9610 if (dwarf_version
!= 5)
9612 warn (_("Only DWARF version 5 .debug_names "
9613 "is currently supported.\n"));
9617 SAFE_BYTE_GET_AND_INC (padding
, hdrptr
, 2, unit_end
);
9619 warn (_("Padding field of .debug_names must be 0 (found 0x%x)\n"),
9622 SAFE_BYTE_GET_AND_INC (comp_unit_count
, hdrptr
, 4, unit_end
);
9623 if (comp_unit_count
== 0)
9624 warn (_("Compilation unit count must be >= 1 in .debug_names\n"));
9626 SAFE_BYTE_GET_AND_INC (local_type_unit_count
, hdrptr
, 4, unit_end
);
9627 SAFE_BYTE_GET_AND_INC (foreign_type_unit_count
, hdrptr
, 4, unit_end
);
9628 SAFE_BYTE_GET_AND_INC (bucket_count
, hdrptr
, 4, unit_end
);
9629 SAFE_BYTE_GET_AND_INC (name_count
, hdrptr
, 4, unit_end
);
9630 SAFE_BYTE_GET_AND_INC (abbrev_table_size
, hdrptr
, 4, unit_end
);
9632 SAFE_BYTE_GET_AND_INC (augmentation_string_size
, hdrptr
, 4, unit_end
);
9633 if (augmentation_string_size
% 4 != 0)
9635 warn (_("Augmentation string length %u must be rounded up "
9636 "to a multiple of 4 in .debug_names.\n"),
9637 augmentation_string_size
);
9638 augmentation_string_size
+= (-augmentation_string_size
) & 3;
9641 printf (_("Augmentation string:"));
9643 augmentation_printable
= true;
9644 augmentation_string
= (const char *) hdrptr
;
9646 for (i
= 0; i
< augmentation_string_size
; i
++)
9650 SAFE_BYTE_GET_AND_INC (uc
, hdrptr
, 1, unit_end
);
9651 printf (" %02x", uc
);
9653 if (uc
!= 0 && !ISPRINT (uc
))
9654 augmentation_printable
= false;
9657 if (augmentation_printable
)
9661 i
< augmentation_string_size
&& augmentation_string
[i
];
9663 putchar (augmentation_string
[i
]);
9668 printf (_("CU table:\n"));
9669 for (i
= 0; i
< comp_unit_count
; i
++)
9673 SAFE_BYTE_GET_AND_INC (cu_offset
, hdrptr
, offset_size
, unit_end
);
9674 printf (_("[%3u] 0x%lx\n"), i
, (unsigned long) cu_offset
);
9678 printf (_("TU table:\n"));
9679 for (i
= 0; i
< local_type_unit_count
; i
++)
9683 SAFE_BYTE_GET_AND_INC (tu_offset
, hdrptr
, offset_size
, unit_end
);
9684 printf (_("[%3u] 0x%lx\n"), i
, (unsigned long) tu_offset
);
9688 printf (_("Foreign TU table:\n"));
9689 for (i
= 0; i
< foreign_type_unit_count
; i
++)
9693 SAFE_BYTE_GET_AND_INC (signature
, hdrptr
, 8, unit_end
);
9694 printf (_("[%3u] "), i
);
9695 print_dwarf_vma (signature
, 8);
9700 const uint32_t *const hash_table_buckets
= (uint32_t *) hdrptr
;
9701 hdrptr
+= bucket_count
* sizeof (uint32_t);
9702 const uint32_t *const hash_table_hashes
= (uint32_t *) hdrptr
;
9703 hdrptr
+= name_count
* sizeof (uint32_t);
9704 unsigned char *const name_table_string_offsets
= hdrptr
;
9705 hdrptr
+= name_count
* offset_size
;
9706 unsigned char *const name_table_entry_offsets
= hdrptr
;
9707 hdrptr
+= name_count
* offset_size
;
9708 unsigned char *const abbrev_table
= hdrptr
;
9709 hdrptr
+= abbrev_table_size
;
9710 const unsigned char *const abbrev_table_end
= hdrptr
;
9711 unsigned char *const entry_pool
= hdrptr
;
9712 if (hdrptr
> unit_end
)
9714 warn (_("Entry pool offset (0x%lx) exceeds unit size 0x%lx "
9715 "for unit 0x%lx in the debug_names\n"),
9716 (long) (hdrptr
- section
->start
),
9717 (long) (unit_end
- section
->start
),
9718 (long) (unit_start
- section
->start
));
9722 size_t buckets_filled
= 0;
9724 for (bucketi
= 0; bucketi
< bucket_count
; bucketi
++)
9726 const uint32_t bucket
= hash_table_buckets
[bucketi
];
9731 printf (ngettext ("Used %zu of %lu bucket.\n",
9732 "Used %zu of %lu buckets.\n",
9734 buckets_filled
, (unsigned long) bucket_count
);
9736 uint32_t hash_prev
= 0;
9737 size_t hash_clash_count
= 0;
9738 size_t longest_clash
= 0;
9739 size_t this_length
= 0;
9741 for (hashi
= 0; hashi
< name_count
; hashi
++)
9743 const uint32_t hash_this
= hash_table_hashes
[hashi
];
9747 if (hash_prev
% bucket_count
== hash_this
% bucket_count
)
9751 longest_clash
= MAX (longest_clash
, this_length
);
9756 hash_prev
= hash_this
;
9758 printf (_("Out of %lu items there are %zu bucket clashes"
9759 " (longest of %zu entries).\n"),
9760 (unsigned long) name_count
, hash_clash_count
, longest_clash
);
9761 assert (name_count
== buckets_filled
+ hash_clash_count
);
9763 struct abbrev_lookup_entry
9765 dwarf_vma abbrev_tag
;
9766 unsigned char *abbrev_lookup_ptr
;
9768 struct abbrev_lookup_entry
*abbrev_lookup
= NULL
;
9769 size_t abbrev_lookup_used
= 0;
9770 size_t abbrev_lookup_allocated
= 0;
9772 unsigned char *abbrevptr
= abbrev_table
;
9775 dwarf_vma abbrev_tag
;
9777 READ_ULEB (abbrev_tag
, abbrevptr
, abbrev_table_end
);
9778 if (abbrev_tag
== 0)
9780 if (abbrev_lookup_used
== abbrev_lookup_allocated
)
9782 abbrev_lookup_allocated
= MAX (0x100,
9783 abbrev_lookup_allocated
* 2);
9784 abbrev_lookup
= xrealloc (abbrev_lookup
,
9785 (abbrev_lookup_allocated
9786 * sizeof (*abbrev_lookup
)));
9788 assert (abbrev_lookup_used
< abbrev_lookup_allocated
);
9789 struct abbrev_lookup_entry
*entry
;
9790 for (entry
= abbrev_lookup
;
9791 entry
< abbrev_lookup
+ abbrev_lookup_used
;
9793 if (entry
->abbrev_tag
== abbrev_tag
)
9795 warn (_("Duplicate abbreviation tag %lu "
9796 "in unit 0x%lx in the debug_names\n"),
9797 (long) abbrev_tag
, (long) (unit_start
- section
->start
));
9800 entry
= &abbrev_lookup
[abbrev_lookup_used
++];
9801 entry
->abbrev_tag
= abbrev_tag
;
9802 entry
->abbrev_lookup_ptr
= abbrevptr
;
9804 /* Skip DWARF tag. */
9805 SKIP_ULEB (abbrevptr
, abbrev_table_end
);
9808 dwarf_vma xindex
, form
;
9810 READ_ULEB (xindex
, abbrevptr
, abbrev_table_end
);
9811 READ_ULEB (form
, abbrevptr
, abbrev_table_end
);
9812 if (xindex
== 0 && form
== 0)
9817 printf (_("\nSymbol table:\n"));
9819 for (namei
= 0; namei
< name_count
; ++namei
)
9821 uint64_t string_offset
, entry_offset
;
9824 p
= name_table_string_offsets
+ namei
* offset_size
;
9825 SAFE_BYTE_GET (string_offset
, p
, offset_size
, unit_end
);
9826 p
= name_table_entry_offsets
+ namei
* offset_size
;
9827 SAFE_BYTE_GET (entry_offset
, p
, offset_size
, unit_end
);
9829 printf ("[%3u] #%08x %s:", namei
, hash_table_hashes
[namei
],
9830 fetch_indirect_string (string_offset
));
9832 unsigned char *entryptr
= entry_pool
+ entry_offset
;
9834 /* We need to scan first whether there is a single or multiple
9835 entries. TAGNO is -2 for the first entry, it is -1 for the
9836 initial tag read of the second entry, then it becomes 0 for the
9837 first entry for real printing etc. */
9839 /* Initialize it due to a false compiler warning. */
9840 dwarf_vma second_abbrev_tag
= -1;
9843 dwarf_vma abbrev_tag
;
9844 dwarf_vma dwarf_tag
;
9845 const struct abbrev_lookup_entry
*entry
;
9847 READ_ULEB (abbrev_tag
, entryptr
, unit_end
);
9850 second_abbrev_tag
= abbrev_tag
;
9852 entryptr
= entry_pool
+ entry_offset
;
9855 if (abbrev_tag
== 0)
9859 (tagno
== 0 && second_abbrev_tag
== 0 ? " " : "\n\t"),
9860 (unsigned long) abbrev_tag
);
9862 for (entry
= abbrev_lookup
;
9863 entry
< abbrev_lookup
+ abbrev_lookup_used
;
9865 if (entry
->abbrev_tag
== abbrev_tag
)
9867 if (entry
>= abbrev_lookup
+ abbrev_lookup_used
)
9869 warn (_("Undefined abbreviation tag %lu "
9870 "in unit 0x%lx in the debug_names\n"),
9872 (long) (unit_start
- section
->start
));
9875 abbrevptr
= entry
->abbrev_lookup_ptr
;
9876 READ_ULEB (dwarf_tag
, abbrevptr
, abbrev_table_end
);
9878 printf (" %s", get_TAG_name (dwarf_tag
));
9881 dwarf_vma xindex
, form
;
9883 READ_ULEB (xindex
, abbrevptr
, abbrev_table_end
);
9884 READ_ULEB (form
, abbrevptr
, abbrev_table_end
);
9885 if (xindex
== 0 && form
== 0)
9889 printf (" %s", get_IDX_name (xindex
));
9890 entryptr
= read_and_display_attr_value (0, form
, 0,
9891 unit_start
, entryptr
, unit_end
,
9893 dwarf_version
, NULL
,
9900 printf (_(" <no entries>"));
9904 free (abbrev_lookup
);
9911 display_debug_links (struct dwarf_section
* section
,
9912 void * file ATTRIBUTE_UNUSED
)
9914 const unsigned char * filename
;
9915 unsigned int filelen
;
9917 introduce (section
, false);
9919 /* The .gnu_debuglink section is formatted as:
9920 (c-string) Filename.
9921 (padding) If needed to reach a 4 byte boundary.
9922 (uint32_t) CRC32 value.
9924 The .gun_debugaltlink section is formatted as:
9925 (c-string) Filename.
9926 (binary) Build-ID. */
9928 filename
= section
->start
;
9929 filelen
= strnlen ((const char *) filename
, section
->size
);
9930 if (filelen
== section
->size
)
9932 warn (_("The debuglink filename is corrupt/missing\n"));
9936 printf (_(" Separate debug info file: %s\n"), filename
);
9938 if (startswith (section
->name
, ".gnu_debuglink"))
9941 unsigned int crc_offset
;
9943 crc_offset
= filelen
+ 1;
9944 crc_offset
= (crc_offset
+ 3) & ~3;
9945 if (crc_offset
+ 4 > section
->size
)
9947 warn (_("CRC offset missing/truncated\n"));
9951 crc32
= byte_get (filename
+ crc_offset
, 4);
9953 printf (_(" CRC value: %#x\n"), crc32
);
9955 if (crc_offset
+ 4 < section
->size
)
9957 warn (_("There are %#lx extraneous bytes at the end of the section\n"),
9958 (long)(section
->size
- (crc_offset
+ 4)));
9962 else /* startswith (section->name, ".gnu_debugaltlink") */
9964 const unsigned char * build_id
= section
->start
+ filelen
+ 1;
9965 bfd_size_type build_id_len
= section
->size
- (filelen
+ 1);
9966 bfd_size_type printed
;
9968 /* FIXME: Should we support smaller build-id notes ? */
9969 if (build_id_len
< 0x14)
9971 warn (_("Build-ID is too short (%#lx bytes)\n"), (long) build_id_len
);
9975 printed
= printf (_(" Build-ID (%#lx bytes):"), (long) build_id_len
);
9976 display_data (printed
, build_id
, build_id_len
);
9985 display_gdb_index (struct dwarf_section
*section
,
9986 void *file ATTRIBUTE_UNUSED
)
9988 unsigned char *start
= section
->start
;
9990 uint32_t cu_list_offset
, tu_list_offset
;
9991 uint32_t address_table_offset
, symbol_table_offset
, constant_pool_offset
;
9992 unsigned int cu_list_elements
, tu_list_elements
;
9993 unsigned int address_table_size
, symbol_table_slots
;
9994 unsigned char *cu_list
, *tu_list
;
9995 unsigned char *address_table
, *symbol_table
, *constant_pool
;
9998 /* The documentation for the format of this file is in gdb/dwarf2read.c. */
10000 introduce (section
, false);
10002 if (section
->size
< 6 * sizeof (uint32_t))
10004 warn (_("Truncated header in the %s section.\n"), section
->name
);
10008 version
= byte_get_little_endian (start
, 4);
10009 printf (_("Version %ld\n"), (long) version
);
10011 /* Prior versions are obsolete, and future versions may not be
10012 backwards compatible. */
10013 if (version
< 3 || version
> 8)
10015 warn (_("Unsupported version %lu.\n"), (unsigned long) version
);
10019 warn (_("The address table data in version 3 may be wrong.\n"));
10021 warn (_("Version 4 does not support case insensitive lookups.\n"));
10023 warn (_("Version 5 does not include inlined functions.\n"));
10025 warn (_("Version 6 does not include symbol attributes.\n"));
10026 /* Version 7 indices generated by Gold have bad type unit references,
10027 PR binutils/15021. But we don't know if the index was generated by
10028 Gold or not, so to avoid worrying users with gdb-generated indices
10029 we say nothing for version 7 here. */
10031 cu_list_offset
= byte_get_little_endian (start
+ 4, 4);
10032 tu_list_offset
= byte_get_little_endian (start
+ 8, 4);
10033 address_table_offset
= byte_get_little_endian (start
+ 12, 4);
10034 symbol_table_offset
= byte_get_little_endian (start
+ 16, 4);
10035 constant_pool_offset
= byte_get_little_endian (start
+ 20, 4);
10037 if (cu_list_offset
> section
->size
10038 || tu_list_offset
> section
->size
10039 || address_table_offset
> section
->size
10040 || symbol_table_offset
> section
->size
10041 || constant_pool_offset
> section
->size
)
10043 warn (_("Corrupt header in the %s section.\n"), section
->name
);
10047 /* PR 17531: file: 418d0a8a. */
10048 if (tu_list_offset
< cu_list_offset
)
10050 warn (_("TU offset (%x) is less than CU offset (%x)\n"),
10051 tu_list_offset
, cu_list_offset
);
10055 cu_list_elements
= (tu_list_offset
- cu_list_offset
) / 8;
10057 if (address_table_offset
< tu_list_offset
)
10059 warn (_("Address table offset (%x) is less than TU offset (%x)\n"),
10060 address_table_offset
, tu_list_offset
);
10064 tu_list_elements
= (address_table_offset
- tu_list_offset
) / 8;
10066 /* PR 17531: file: 18a47d3d. */
10067 if (symbol_table_offset
< address_table_offset
)
10069 warn (_("Symbol table offset (%x) is less then Address table offset (%x)\n"),
10070 symbol_table_offset
, address_table_offset
);
10074 address_table_size
= symbol_table_offset
- address_table_offset
;
10076 if (constant_pool_offset
< symbol_table_offset
)
10078 warn (_("Constant pool offset (%x) is less than symbol table offset (%x)\n"),
10079 constant_pool_offset
, symbol_table_offset
);
10083 symbol_table_slots
= (constant_pool_offset
- symbol_table_offset
) / 8;
10085 cu_list
= start
+ cu_list_offset
;
10086 tu_list
= start
+ tu_list_offset
;
10087 address_table
= start
+ address_table_offset
;
10088 symbol_table
= start
+ symbol_table_offset
;
10089 constant_pool
= start
+ constant_pool_offset
;
10091 if (address_table
+ address_table_size
> section
->start
+ section
->size
)
10093 warn (_("Address table extends beyond end of section.\n"));
10097 printf (_("\nCU table:\n"));
10098 for (i
= 0; i
< cu_list_elements
; i
+= 2)
10100 uint64_t cu_offset
= byte_get_little_endian (cu_list
+ i
* 8, 8);
10101 uint64_t cu_length
= byte_get_little_endian (cu_list
+ i
* 8 + 8, 8);
10103 printf (_("[%3u] 0x%lx - 0x%lx\n"), i
/ 2,
10104 (unsigned long) cu_offset
,
10105 (unsigned long) (cu_offset
+ cu_length
- 1));
10108 printf (_("\nTU table:\n"));
10109 for (i
= 0; i
< tu_list_elements
; i
+= 3)
10111 uint64_t tu_offset
= byte_get_little_endian (tu_list
+ i
* 8, 8);
10112 uint64_t type_offset
= byte_get_little_endian (tu_list
+ i
* 8 + 8, 8);
10113 uint64_t signature
= byte_get_little_endian (tu_list
+ i
* 8 + 16, 8);
10115 printf (_("[%3u] 0x%lx 0x%lx "), i
/ 3,
10116 (unsigned long) tu_offset
,
10117 (unsigned long) type_offset
);
10118 print_dwarf_vma (signature
, 8);
10122 printf (_("\nAddress table:\n"));
10123 for (i
= 0; i
< address_table_size
&& i
<= address_table_size
- (2 * 8 + 4);
10126 uint64_t low
= byte_get_little_endian (address_table
+ i
, 8);
10127 uint64_t high
= byte_get_little_endian (address_table
+ i
+ 8, 8);
10128 uint32_t cu_index
= byte_get_little_endian (address_table
+ i
+ 16, 4);
10130 print_dwarf_vma (low
, 8);
10131 print_dwarf_vma (high
, 8);
10132 printf (_("%lu\n"), (unsigned long) cu_index
);
10135 printf (_("\nSymbol table:\n"));
10136 for (i
= 0; i
< symbol_table_slots
; ++i
)
10138 uint32_t name_offset
= byte_get_little_endian (symbol_table
+ i
* 8, 4);
10139 uint32_t cu_vector_offset
= byte_get_little_endian (symbol_table
+ i
* 8 + 4, 4);
10140 uint32_t num_cus
, cu
;
10142 if (name_offset
!= 0
10143 || cu_vector_offset
!= 0)
10146 unsigned char * adr
;
10148 adr
= constant_pool
+ name_offset
;
10149 /* PR 17531: file: 5b7b07ad. */
10150 if (adr
< constant_pool
|| adr
>= section
->start
+ section
->size
)
10152 printf (_("[%3u] <corrupt offset: %x>"), i
, name_offset
);
10153 warn (_("Corrupt name offset of 0x%x found for symbol table slot %d\n"),
10157 printf ("[%3u] %.*s:", i
,
10158 (int) (section
->size
- (constant_pool_offset
+ name_offset
)),
10159 constant_pool
+ name_offset
);
10161 adr
= constant_pool
+ cu_vector_offset
;
10162 if (adr
< constant_pool
|| adr
>= section
->start
+ section
->size
- 3)
10164 printf (_("<invalid CU vector offset: %x>\n"), cu_vector_offset
);
10165 warn (_("Corrupt CU vector offset of 0x%x found for symbol table slot %d\n"),
10166 cu_vector_offset
, i
);
10170 num_cus
= byte_get_little_endian (adr
, 4);
10172 adr
= constant_pool
+ cu_vector_offset
+ 4 + num_cus
* 4;
10173 if (num_cus
* 4 < num_cus
10174 || adr
>= section
->start
+ section
->size
10175 || adr
< constant_pool
)
10177 printf ("<invalid number of CUs: %d>\n", num_cus
);
10178 warn (_("Invalid number of CUs (0x%x) for symbol table slot %d\n"),
10186 for (j
= 0; j
< num_cus
; ++j
)
10189 gdb_index_symbol_kind kind
;
10191 cu
= byte_get_little_endian (constant_pool
+ cu_vector_offset
+ 4 + j
* 4, 4);
10192 is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu
);
10193 kind
= GDB_INDEX_SYMBOL_KIND_VALUE (cu
);
10194 cu
= GDB_INDEX_CU_VALUE (cu
);
10195 /* Convert to TU number if it's for a type unit. */
10196 if (cu
>= cu_list_elements
/ 2)
10197 printf ("%cT%lu", num_cus
> 1 ? '\t' : ' ',
10198 (unsigned long) (cu
- cu_list_elements
/ 2));
10200 printf ("%c%lu", num_cus
> 1 ? '\t' : ' ', (unsigned long) cu
);
10202 printf (" [%s, %s]",
10203 is_static
? _("static") : _("global"),
10204 get_gdb_index_symbol_kind_name (kind
));
10216 /* Pre-allocate enough space for the CU/TU sets needed. */
10219 prealloc_cu_tu_list (unsigned int nshndx
)
10221 if (shndx_pool
== NULL
)
10223 shndx_pool_size
= nshndx
;
10224 shndx_pool_used
= 0;
10225 shndx_pool
= (unsigned int *) xcmalloc (shndx_pool_size
,
10226 sizeof (unsigned int));
10230 shndx_pool_size
= shndx_pool_used
+ nshndx
;
10231 shndx_pool
= (unsigned int *) xcrealloc (shndx_pool
, shndx_pool_size
,
10232 sizeof (unsigned int));
10237 add_shndx_to_cu_tu_entry (unsigned int shndx
)
10239 if (shndx_pool_used
>= shndx_pool_size
)
10241 error (_("Internal error: out of space in the shndx pool.\n"));
10244 shndx_pool
[shndx_pool_used
++] = shndx
;
10248 end_cu_tu_entry (void)
10250 if (shndx_pool_used
>= shndx_pool_size
)
10252 error (_("Internal error: out of space in the shndx pool.\n"));
10255 shndx_pool
[shndx_pool_used
++] = 0;
10258 /* Return the short name of a DWARF section given by a DW_SECT enumerator. */
10260 static const char *
10261 get_DW_SECT_short_name (unsigned int dw_sect
)
10263 static char buf
[16];
10269 case DW_SECT_TYPES
:
10271 case DW_SECT_ABBREV
:
10277 case DW_SECT_STR_OFFSETS
:
10279 case DW_SECT_MACINFO
:
10281 case DW_SECT_MACRO
:
10287 snprintf (buf
, sizeof (buf
), "%d", dw_sect
);
10291 /* Process a CU or TU index. If DO_DISPLAY is true, print the contents.
10292 These sections are extensions for Fission.
10293 See http://gcc.gnu.org/wiki/DebugFissionDWP. */
10296 process_cu_tu_index (struct dwarf_section
*section
, int do_display
)
10298 unsigned char *phdr
= section
->start
;
10299 unsigned char *limit
= phdr
+ section
->size
;
10300 unsigned char *phash
;
10301 unsigned char *pindex
;
10302 unsigned char *ppool
;
10303 unsigned int version
;
10304 unsigned int ncols
= 0;
10305 unsigned int nused
;
10306 unsigned int nslots
;
10309 dwarf_vma signature
;
10311 /* PR 17512: file: 002-168123-0.004. */
10314 warn (_("Section %s is empty\n"), section
->name
);
10317 /* PR 17512: file: 002-376-0.004. */
10318 if (section
->size
< 24)
10320 warn (_("Section %s is too small to contain a CU/TU header\n"),
10326 SAFE_BYTE_GET_AND_INC (version
, phash
, 4, limit
);
10328 SAFE_BYTE_GET_AND_INC (ncols
, phash
, 4, limit
);
10329 SAFE_BYTE_GET_AND_INC (nused
, phash
, 4, limit
);
10330 SAFE_BYTE_GET_AND_INC (nslots
, phash
, 4, limit
);
10332 pindex
= phash
+ (size_t) nslots
* 8;
10333 ppool
= pindex
+ (size_t) nslots
* 4;
10337 introduce (section
, false);
10339 printf (_(" Version: %u\n"), version
);
10341 printf (_(" Number of columns: %u\n"), ncols
);
10342 printf (_(" Number of used entries: %u\n"), nused
);
10343 printf (_(" Number of slots: %u\n\n"), nslots
);
10346 /* PR 17531: file: 45d69832. */
10347 if ((size_t) nslots
* 8 / 8 != nslots
10348 || phash
< phdr
|| phash
> limit
10349 || pindex
< phash
|| pindex
> limit
10350 || ppool
< pindex
|| ppool
> limit
)
10352 warn (ngettext ("Section %s is too small for %u slot\n",
10353 "Section %s is too small for %u slots\n",
10355 section
->name
, nslots
);
10362 prealloc_cu_tu_list ((limit
- ppool
) / 4);
10363 for (i
= 0; i
< nslots
; i
++)
10365 unsigned char *shndx_list
;
10366 unsigned int shndx
;
10368 SAFE_BYTE_GET (signature
, phash
, 8, limit
);
10369 if (signature
!= 0)
10371 SAFE_BYTE_GET (j
, pindex
, 4, limit
);
10372 shndx_list
= ppool
+ j
* 4;
10373 /* PR 17531: file: 705e010d. */
10374 if (shndx_list
< ppool
)
10376 warn (_("Section index pool located before start of section\n"));
10381 printf (_(" [%3d] Signature: 0x%s Sections: "),
10382 i
, dwarf_vmatoa ("x", signature
));
10385 if (shndx_list
>= limit
)
10387 warn (_("Section %s too small for shndx pool\n"),
10391 SAFE_BYTE_GET (shndx
, shndx_list
, 4, limit
);
10395 printf (" %d", shndx
);
10397 add_shndx_to_cu_tu_entry (shndx
);
10403 end_cu_tu_entry ();
10409 else if (version
== 2)
10412 unsigned int dw_sect
;
10413 unsigned char *ph
= phash
;
10414 unsigned char *pi
= pindex
;
10415 unsigned char *poffsets
= ppool
+ (size_t) ncols
* 4;
10416 unsigned char *psizes
= poffsets
+ (size_t) nused
* ncols
* 4;
10417 unsigned char *pend
= psizes
+ (size_t) nused
* ncols
* 4;
10419 struct cu_tu_set
*this_set
= NULL
;
10421 unsigned char *prow
;
10423 is_tu_index
= strcmp (section
->name
, ".debug_tu_index") == 0;
10425 /* PR 17531: file: 0dd159bf.
10426 Check for integer overflow (can occur when size_t is 32-bit)
10427 with overlarge ncols or nused values. */
10429 && ((size_t) ncols
* 4 / 4 != ncols
10430 || (size_t) nused
* ncols
* 4 / ((size_t) ncols
* 4) != nused
10431 || poffsets
< ppool
|| poffsets
> limit
10432 || psizes
< poffsets
|| psizes
> limit
10433 || pend
< psizes
|| pend
> limit
))
10435 warn (_("Section %s too small for offset and size tables\n"),
10442 printf (_(" Offset table\n"));
10443 printf (" slot %-16s ",
10444 is_tu_index
? _("signature") : _("dwo_id"));
10451 tu_sets
= xcalloc2 (nused
, sizeof (struct cu_tu_set
));
10452 this_set
= tu_sets
;
10457 cu_sets
= xcalloc2 (nused
, sizeof (struct cu_tu_set
));
10458 this_set
= cu_sets
;
10464 for (j
= 0; j
< ncols
; j
++)
10466 unsigned char *p
= ppool
+ j
* 4;
10467 SAFE_BYTE_GET (dw_sect
, p
, 4, limit
);
10468 printf (" %8s", get_DW_SECT_short_name (dw_sect
));
10473 for (i
= 0; i
< nslots
; i
++)
10475 SAFE_BYTE_GET (signature
, ph
, 8, limit
);
10477 SAFE_BYTE_GET (row
, pi
, 4, limit
);
10480 /* PR 17531: file: a05f6ab3. */
10483 warn (_("Row index (%u) is larger than number of used entries (%u)\n"),
10490 size_t num_copy
= sizeof (uint64_t);
10492 /* PR 23064: Beware of buffer overflow. */
10493 if (ph
+ num_copy
< limit
)
10494 memcpy (&this_set
[row
- 1].signature
, ph
, num_copy
);
10497 warn (_("Signature (%p) extends beyond end of space in section\n"), ph
);
10502 prow
= poffsets
+ (row
- 1) * ncols
* 4;
10503 /* PR 17531: file: b8ce60a8. */
10504 if (prow
< poffsets
|| prow
> limit
)
10506 warn (_("Row index (%u) * num columns (%u) > space remaining in section\n"),
10512 printf (_(" [%3d] 0x%s"),
10513 i
, dwarf_vmatoa ("x", signature
));
10514 for (j
= 0; j
< ncols
; j
++)
10516 unsigned char *p
= prow
+ j
* 4;
10517 SAFE_BYTE_GET (val
, p
, 4, limit
);
10519 printf (" %8d", val
);
10523 SAFE_BYTE_GET (dw_sect
, p
, 4, limit
);
10525 /* PR 17531: file: 10796eb3. */
10526 if (dw_sect
>= DW_SECT_MAX
)
10527 warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect
);
10529 this_set
[row
- 1].section_offsets
[dw_sect
] = val
;
10545 printf (_(" Size table\n"));
10546 printf (" slot %-16s ",
10547 is_tu_index
? _("signature") : _("dwo_id"));
10550 for (j
= 0; j
< ncols
; j
++)
10552 unsigned char *p
= ppool
+ j
* 4;
10553 SAFE_BYTE_GET (val
, p
, 4, limit
);
10555 printf (" %8s", get_DW_SECT_short_name (val
));
10561 for (i
= 0; i
< nslots
; i
++)
10563 SAFE_BYTE_GET (signature
, ph
, 8, limit
);
10565 SAFE_BYTE_GET (row
, pi
, 4, limit
);
10568 prow
= psizes
+ (row
- 1) * ncols
* 4;
10571 printf (_(" [%3d] 0x%s"),
10572 i
, dwarf_vmatoa ("x", signature
));
10574 for (j
= 0; j
< ncols
; j
++)
10576 unsigned char *p
= prow
+ j
* 4;
10577 SAFE_BYTE_GET (val
, p
, 4, limit
);
10579 printf (" %8d", val
);
10583 SAFE_BYTE_GET (dw_sect
, p
, 4, limit
);
10584 if (dw_sect
>= DW_SECT_MAX
)
10585 warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect
);
10587 this_set
[row
- 1].section_sizes
[dw_sect
] = val
;
10599 else if (do_display
)
10600 printf (_(" Unsupported version (%d)\n"), version
);
10608 static int cu_tu_indexes_read
= -1; /* Tri-state variable. */
10610 /* Load the CU and TU indexes if present. This will build a list of
10611 section sets that we can use to associate a .debug_info.dwo section
10612 with its associated .debug_abbrev.dwo section in a .dwp file. */
10615 load_cu_tu_indexes (void *file
)
10617 /* If we have already loaded (or tried to load) the CU and TU indexes
10618 then do not bother to repeat the task. */
10619 if (cu_tu_indexes_read
== -1)
10621 cu_tu_indexes_read
= true;
10623 if (load_debug_section_with_follow (dwp_cu_index
, file
))
10624 if (! process_cu_tu_index (&debug_displays
[dwp_cu_index
].section
, 0))
10625 cu_tu_indexes_read
= false;
10627 if (load_debug_section_with_follow (dwp_tu_index
, file
))
10628 if (! process_cu_tu_index (&debug_displays
[dwp_tu_index
].section
, 0))
10629 cu_tu_indexes_read
= false;
10632 return (bool) cu_tu_indexes_read
;
10635 /* Find the set of sections that includes section SHNDX. */
10638 find_cu_tu_set (void *file
, unsigned int shndx
)
10642 if (! load_cu_tu_indexes (file
))
10645 /* Find SHNDX in the shndx pool. */
10646 for (i
= 0; i
< shndx_pool_used
; i
++)
10647 if (shndx_pool
[i
] == shndx
)
10650 if (i
>= shndx_pool_used
)
10653 /* Now backup to find the first entry in the set. */
10654 while (i
> 0 && shndx_pool
[i
- 1] != 0)
10657 return shndx_pool
+ i
;
10660 /* Display a .debug_cu_index or .debug_tu_index section. */
10663 display_cu_index (struct dwarf_section
*section
, void *file ATTRIBUTE_UNUSED
)
10665 return process_cu_tu_index (section
, 1);
10669 display_debug_not_supported (struct dwarf_section
*section
,
10670 void *file ATTRIBUTE_UNUSED
)
10672 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
10678 /* Like malloc, but takes two parameters like calloc.
10679 Verifies that the first parameter is not too large.
10680 Note: does *not* initialise the allocated memory to zero. */
10683 cmalloc (size_t nmemb
, size_t size
)
10685 /* Check for overflow. */
10686 if (nmemb
>= ~(size_t) 0 / size
)
10689 return xmalloc (nmemb
* size
);
10692 /* Like xmalloc, but takes two parameters like calloc.
10693 Verifies that the first parameter is not too large.
10694 Note: does *not* initialise the allocated memory to zero. */
10697 xcmalloc (size_t nmemb
, size_t size
)
10699 /* Check for overflow. */
10700 if (nmemb
>= ~(size_t) 0 / size
)
10703 _("Attempt to allocate an array with an excessive number of elements: 0x%lx\n"),
10708 return xmalloc (nmemb
* size
);
10711 /* Like xrealloc, but takes three parameters.
10712 Verifies that the second parameter is not too large.
10713 Note: does *not* initialise any new memory to zero. */
10716 xcrealloc (void *ptr
, size_t nmemb
, size_t size
)
10718 /* Check for overflow. */
10719 if (nmemb
>= ~(size_t) 0 / size
)
10721 error (_("Attempt to re-allocate an array with an excessive number of elements: 0x%lx\n"),
10726 return xrealloc (ptr
, nmemb
* size
);
10729 /* Like xcalloc, but verifies that the first parameter is not too large. */
10732 xcalloc2 (size_t nmemb
, size_t size
)
10734 /* Check for overflow. */
10735 if (nmemb
>= ~(size_t) 0 / size
)
10737 error (_("Attempt to allocate a zero'ed array with an excessive number of elements: 0x%lx\n"),
10742 return xcalloc (nmemb
, size
);
10745 static unsigned long
10746 calc_gnu_debuglink_crc32 (unsigned long crc
,
10747 const unsigned char * buf
,
10750 static const unsigned long crc32_table
[256] =
10752 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
10753 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
10754 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
10755 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
10756 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
10757 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
10758 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
10759 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
10760 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
10761 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
10762 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
10763 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
10764 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
10765 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
10766 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
10767 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
10768 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
10769 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
10770 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
10771 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
10772 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
10773 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
10774 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
10775 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
10776 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
10777 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
10778 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
10779 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
10780 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
10781 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
10782 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
10783 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
10784 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
10785 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
10786 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
10787 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
10788 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
10789 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
10790 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
10791 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
10792 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
10793 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
10794 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
10795 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
10796 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
10797 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
10798 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
10799 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
10800 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
10801 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
10802 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
10805 const unsigned char *end
;
10807 crc
= ~crc
& 0xffffffff;
10808 for (end
= buf
+ len
; buf
< end
; ++ buf
)
10809 crc
= crc32_table
[(crc
^ *buf
) & 0xff] ^ (crc
>> 8);
10810 return ~crc
& 0xffffffff;
10813 typedef bool (*check_func_type
) (const char *, void *);
10814 typedef const char *(* parse_func_type
) (struct dwarf_section
*, void *);
10817 check_gnu_debuglink (const char * pathname
, void * crc_pointer
)
10819 static unsigned char buffer
[8 * 1024];
10821 bfd_size_type count
;
10822 unsigned long crc
= 0;
10825 sep_data
= open_debug_file (pathname
);
10826 if (sep_data
== NULL
)
10829 /* Yes - we are opening the file twice... */
10830 f
= fopen (pathname
, "rb");
10833 /* Paranoia: This should never happen. */
10834 close_debug_file (sep_data
);
10835 warn (_("Unable to reopen separate debug info file: %s\n"), pathname
);
10839 while ((count
= fread (buffer
, 1, sizeof (buffer
), f
)) > 0)
10840 crc
= calc_gnu_debuglink_crc32 (crc
, buffer
, count
);
10844 if (crc
!= * (unsigned long *) crc_pointer
)
10846 close_debug_file (sep_data
);
10847 warn (_("Separate debug info file %s found, but CRC does not match - ignoring\n"),
10855 static const char *
10856 parse_gnu_debuglink (struct dwarf_section
* section
, void * data
)
10859 unsigned int crc_offset
;
10860 unsigned long * crc32
= (unsigned long *) data
;
10862 /* The name is first.
10863 The CRC value is stored after the filename, aligned up to 4 bytes. */
10864 name
= (const char *) section
->start
;
10866 crc_offset
= strnlen (name
, section
->size
) + 1;
10867 if (crc_offset
== 1)
10869 crc_offset
= (crc_offset
+ 3) & ~3;
10870 if (crc_offset
+ 4 > section
->size
)
10873 * crc32
= byte_get (section
->start
+ crc_offset
, 4);
10878 check_gnu_debugaltlink (const char * filename
, void * data ATTRIBUTE_UNUSED
)
10880 void * sep_data
= open_debug_file (filename
);
10882 if (sep_data
== NULL
)
10885 /* FIXME: We should now extract the build-id in the separate file
10891 typedef struct build_id_data
10894 const unsigned char * data
;
10897 static const char *
10898 parse_gnu_debugaltlink (struct dwarf_section
* section
, void * data
)
10901 bfd_size_type namelen
;
10902 bfd_size_type id_len
;
10903 Build_id_data
* build_id_data
;
10905 /* The name is first.
10906 The build-id follows immediately, with no padding, up to the section's end. */
10908 name
= (const char *) section
->start
;
10909 namelen
= strnlen (name
, section
->size
) + 1;
10912 if (namelen
>= section
->size
)
10915 id_len
= section
->size
- namelen
;
10919 build_id_data
= (Build_id_data
*) data
;
10920 build_id_data
->len
= id_len
;
10921 build_id_data
->data
= section
->start
+ namelen
;
10927 add_separate_debug_file (const char * filename
, void * handle
)
10929 separate_info
* i
= xmalloc (sizeof * i
);
10931 i
->filename
= filename
;
10932 i
->handle
= handle
;
10933 i
->next
= first_separate_info
;
10934 first_separate_info
= i
;
10937 #if HAVE_LIBDEBUGINFOD
10938 /* Query debuginfod servers for the target debuglink or debugaltlink
10939 file. If successful, store the path of the file in filename and
10940 return TRUE, otherwise return FALSE. */
10943 debuginfod_fetch_separate_debug_info (struct dwarf_section
* section
,
10947 size_t build_id_len
;
10948 unsigned char * build_id
;
10950 if (strcmp (section
->uncompressed_name
, ".gnu_debuglink") == 0)
10952 /* Get the build-id of file. */
10953 build_id
= get_build_id (file
);
10956 else if (strcmp (section
->uncompressed_name
, ".gnu_debugaltlink") == 0)
10958 /* Get the build-id of the debugaltlink file. */
10959 unsigned int filelen
;
10961 filelen
= strnlen ((const char *)section
->start
, section
->size
);
10962 if (filelen
== section
->size
)
10963 /* Corrupt debugaltlink. */
10966 build_id
= section
->start
+ filelen
+ 1;
10967 build_id_len
= section
->size
- (filelen
+ 1);
10969 if (build_id_len
== 0)
10978 debuginfod_client
* client
;
10980 client
= debuginfod_begin ();
10981 if (client
== NULL
)
10984 /* Query debuginfod servers for the target file. If found its path
10985 will be stored in filename. */
10986 fd
= debuginfod_find_debuginfo (client
, build_id
, build_id_len
, filename
);
10987 debuginfod_end (client
);
10989 /* Only free build_id if we allocated space for a hex string
10990 in get_build_id (). */
10991 if (build_id_len
== 0)
10996 /* File successfully retrieved. Close fd since we want to
10997 use open_debug_file () on filename instead. */
11008 load_separate_debug_info (const char * main_filename
,
11009 struct dwarf_section
* xlink
,
11010 parse_func_type parse_func
,
11011 check_func_type check_func
,
11013 void * file ATTRIBUTE_UNUSED
)
11015 const char * separate_filename
;
11016 char * debug_filename
;
11018 size_t canon_dirlen
;
11021 if ((separate_filename
= parse_func (xlink
, func_data
)) == NULL
)
11023 warn (_("Corrupt debuglink section: %s\n"),
11024 xlink
->name
? xlink
->name
: xlink
->uncompressed_name
);
11028 /* Attempt to locate the separate file.
11029 This should duplicate the logic in bfd/opncls.c:find_separate_debug_file(). */
11031 canon_dir
= lrealpath (main_filename
);
11033 for (canon_dirlen
= strlen (canon_dir
); canon_dirlen
> 0; canon_dirlen
--)
11034 if (IS_DIR_SEPARATOR (canon_dir
[canon_dirlen
- 1]))
11036 canon_dir
[canon_dirlen
] = '\0';
11039 #define DEBUGDIR "/lib/debug"
11041 #ifndef EXTRA_DEBUG_ROOT1
11042 #define EXTRA_DEBUG_ROOT1 "/usr/lib/debug"
11044 #ifndef EXTRA_DEBUG_ROOT2
11045 #define EXTRA_DEBUG_ROOT2 "/usr/lib/debug/usr"
11048 debug_filename
= (char *) malloc (strlen (DEBUGDIR
) + 1
11050 + strlen (".debug/")
11051 #ifdef EXTRA_DEBUG_ROOT1
11052 + strlen (EXTRA_DEBUG_ROOT1
)
11054 #ifdef EXTRA_DEBUG_ROOT2
11055 + strlen (EXTRA_DEBUG_ROOT2
)
11057 + strlen (separate_filename
)
11059 if (debug_filename
== NULL
)
11061 warn (_("Out of memory"));
11066 /* First try in the current directory. */
11067 sprintf (debug_filename
, "%s", separate_filename
);
11068 if (check_func (debug_filename
, func_data
))
11071 /* Then try in a subdirectory called .debug. */
11072 sprintf (debug_filename
, ".debug/%s", separate_filename
);
11073 if (check_func (debug_filename
, func_data
))
11076 /* Then try in the same directory as the original file. */
11077 sprintf (debug_filename
, "%s%s", canon_dir
, separate_filename
);
11078 if (check_func (debug_filename
, func_data
))
11081 /* And the .debug subdirectory of that directory. */
11082 sprintf (debug_filename
, "%s.debug/%s", canon_dir
, separate_filename
);
11083 if (check_func (debug_filename
, func_data
))
11086 #ifdef EXTRA_DEBUG_ROOT1
11087 /* Try the first extra debug file root. */
11088 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT1
, separate_filename
);
11089 if (check_func (debug_filename
, func_data
))
11092 /* Try the first extra debug file root. */
11093 sprintf (debug_filename
, "%s/%s/%s", EXTRA_DEBUG_ROOT1
, canon_dir
, separate_filename
);
11094 if (check_func (debug_filename
, func_data
))
11098 #ifdef EXTRA_DEBUG_ROOT2
11099 /* Try the second extra debug file root. */
11100 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT2
, separate_filename
);
11101 if (check_func (debug_filename
, func_data
))
11105 /* Then try in the global debug_filename directory. */
11106 strcpy (debug_filename
, DEBUGDIR
);
11107 dirlen
= strlen (DEBUGDIR
) - 1;
11108 if (dirlen
> 0 && DEBUGDIR
[dirlen
] != '/')
11109 strcat (debug_filename
, "/");
11110 strcat (debug_filename
, (const char *) separate_filename
);
11112 if (check_func (debug_filename
, func_data
))
11115 #if HAVE_LIBDEBUGINFOD
11117 char * tmp_filename
;
11119 if (debuginfod_fetch_separate_debug_info (xlink
,
11123 /* File successfully downloaded from server, replace
11124 debug_filename with the file's path. */
11125 free (debug_filename
);
11126 debug_filename
= tmp_filename
;
11132 if (do_debug_links
)
11134 /* Failed to find the file. */
11135 warn (_("could not find separate debug file '%s'\n"),
11136 separate_filename
);
11137 warn (_("tried: %s\n"), debug_filename
);
11139 #ifdef EXTRA_DEBUG_ROOT2
11140 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT2
,
11141 separate_filename
);
11142 warn (_("tried: %s\n"), debug_filename
);
11145 #ifdef EXTRA_DEBUG_ROOT1
11146 sprintf (debug_filename
, "%s/%s/%s", EXTRA_DEBUG_ROOT1
,
11147 canon_dir
, separate_filename
);
11148 warn (_("tried: %s\n"), debug_filename
);
11150 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT1
,
11151 separate_filename
);
11152 warn (_("tried: %s\n"), debug_filename
);
11155 sprintf (debug_filename
, "%s.debug/%s", canon_dir
,
11156 separate_filename
);
11157 warn (_("tried: %s\n"), debug_filename
);
11159 sprintf (debug_filename
, "%s%s", canon_dir
, separate_filename
);
11160 warn (_("tried: %s\n"), debug_filename
);
11162 sprintf (debug_filename
, ".debug/%s", separate_filename
);
11163 warn (_("tried: %s\n"), debug_filename
);
11165 sprintf (debug_filename
, "%s", separate_filename
);
11166 warn (_("tried: %s\n"), debug_filename
);
11168 #if HAVE_LIBDEBUGINFOD
11170 char *urls
= getenv (DEBUGINFOD_URLS_ENV_VAR
);
11174 warn (_("tried: DEBUGINFOD_URLS=%s\n"), urls
);
11180 free (debug_filename
);
11186 void * debug_handle
;
11188 /* Now open the file.... */
11189 if ((debug_handle
= open_debug_file (debug_filename
)) == NULL
)
11191 warn (_("failed to open separate debug file: %s\n"), debug_filename
);
11192 free (debug_filename
);
11196 /* FIXME: We do not check to see if there are any other separate debug info
11197 files that would also match. */
11199 if (do_debug_links
)
11200 printf (_("\n%s: Found separate debug info file: %s\n"), main_filename
, debug_filename
);
11201 add_separate_debug_file (debug_filename
, debug_handle
);
11203 /* Do not free debug_filename - it might be referenced inside
11204 the structure returned by open_debug_file(). */
11205 return debug_handle
;
11208 /* Attempt to load a separate dwarf object file. */
11211 load_dwo_file (const char * main_filename
, const char * name
, const char * dir
, const char * id ATTRIBUTE_UNUSED
)
11213 char * separate_filename
;
11214 void * separate_handle
;
11216 if (IS_ABSOLUTE_PATH (name
))
11217 separate_filename
= strdup (name
);
11219 /* FIXME: Skip adding / if dwo_dir ends in /. */
11220 separate_filename
= concat (dir
, "/", name
, NULL
);
11221 if (separate_filename
== NULL
)
11223 warn (_("Out of memory allocating dwo filename\n"));
11227 if ((separate_handle
= open_debug_file (separate_filename
)) == NULL
)
11229 warn (_("Unable to load dwo file: %s\n"), separate_filename
);
11230 free (separate_filename
);
11234 /* FIXME: We should check the dwo_id. */
11236 printf (_("%s: Found separate debug object file: %s\n\n"), main_filename
, separate_filename
);
11238 add_separate_debug_file (separate_filename
, separate_handle
);
11239 /* Note - separate_filename will be freed in free_debug_memory(). */
11240 return separate_handle
;
11244 load_debug_sup_file (const char * main_filename
, void * file
)
11246 if (! load_debug_section (debug_sup
, file
))
11247 return; /* No .debug_sup section. */
11249 struct dwarf_section
* section
;
11250 section
= & debug_displays
[debug_sup
].section
;
11251 assert (section
!= NULL
);
11253 if (section
->start
== NULL
|| section
->size
< 5)
11255 warn (_(".debug_sup section is corrupt/empty\n"));
11259 if (section
->start
[2] != 0)
11260 return; /* This is a supplementary file. */
11262 const char * filename
= (const char *) section
->start
+ 3;
11263 if (strnlen (filename
, section
->size
- 3) == section
->size
- 3)
11265 warn (_("filename in .debug_sup section is corrupt\n"));
11269 if (filename
[0] != '/' && strchr (main_filename
, '/'))
11274 new_len
= asprintf (& new_name
, "%.*s/%s",
11275 (int) (strrchr (main_filename
, '/') - main_filename
),
11280 warn (_("unable to construct path for supplementary debug file"));
11285 filename
= new_name
;
11289 /* PR 27796: Make sure that we pass a filename that can be free'd to
11290 add_separate_debug_file(). */
11291 filename
= strdup (filename
);
11292 if (filename
== NULL
)
11294 warn (_("out of memory constructing filename for .debug_sup link\n"));
11299 void * handle
= open_debug_file (filename
);
11300 if (handle
== NULL
)
11302 warn (_("unable to open file '%s' referenced from .debug_sup section\n"), filename
);
11303 free ((void *) filename
);
11307 printf (_("%s: Found supplementary debug file: %s\n\n"), main_filename
, filename
);
11309 /* FIXME: Compare the checksums, if present. */
11310 add_separate_debug_file (filename
, handle
);
11313 /* Load a debuglink section and/or a debugaltlink section, if either are present.
11314 Recursively check the loaded files for more of these sections.
11315 Also follow any links in .debug_sup sections.
11316 FIXME: Should also check for DWO_* entries in the newly loaded files. */
11319 check_for_and_load_links (void * file
, const char * filename
)
11321 void * handle
= NULL
;
11323 if (load_debug_section (gnu_debugaltlink
, file
))
11325 Build_id_data build_id_data
;
11327 handle
= load_separate_debug_info (filename
,
11328 & debug_displays
[gnu_debugaltlink
].section
,
11329 parse_gnu_debugaltlink
,
11330 check_gnu_debugaltlink
,
11335 assert (handle
== first_separate_info
->handle
);
11336 check_for_and_load_links (first_separate_info
->handle
,
11337 first_separate_info
->filename
);
11341 if (load_debug_section (gnu_debuglink
, file
))
11343 unsigned long crc32
;
11345 handle
= load_separate_debug_info (filename
,
11346 & debug_displays
[gnu_debuglink
].section
,
11347 parse_gnu_debuglink
,
11348 check_gnu_debuglink
,
11353 assert (handle
== first_separate_info
->handle
);
11354 check_for_and_load_links (first_separate_info
->handle
,
11355 first_separate_info
->filename
);
11359 load_debug_sup_file (filename
, file
);
11362 /* Load the separate debug info file(s) attached to FILE, if any exist.
11363 Returns TRUE if any were found, FALSE otherwise.
11364 If TRUE is returned then the linked list starting at first_separate_info
11365 will be populated with open file handles. */
11368 load_separate_debug_files (void * file
, const char * filename
)
11370 /* Skip this operation if we are not interested in debug links. */
11371 if (! do_follow_links
&& ! do_debug_links
)
11374 /* See if there are any dwo links. */
11375 if (load_debug_section (str
, file
)
11376 && load_debug_section (abbrev
, file
)
11377 && load_debug_section (info
, file
))
11381 if (process_debug_info (& debug_displays
[info
].section
, file
, abbrev
,
11384 bool introduced
= false;
11386 const char *dir
= NULL
;
11387 const char *id
= NULL
;
11388 const char *name
= NULL
;
11390 for (dwinfo
= first_dwo_info
; dwinfo
!= NULL
; dwinfo
= dwinfo
->next
)
11392 /* Accumulate NAME, DIR and ID fields. */
11393 switch (dwinfo
->type
)
11397 warn (_("Multiple DWO_NAMEs encountered for the same CU\n"));
11398 name
= dwinfo
->value
;
11402 /* There can be multiple DW_AT_comp_dir entries in a CU,
11403 so do not complain. */
11404 dir
= dwinfo
->value
;
11409 warn (_("multiple DWO_IDs encountered for the same CU\n"));
11410 id
= dwinfo
->value
;
11414 error (_("Unexpected DWO INFO type"));
11418 /* If we have reached the end of our list, or we are changing
11419 CUs, then display the information that we have accumulated
11422 && (dwinfo
->next
== NULL
11423 || dwinfo
->next
->cu_offset
!= dwinfo
->cu_offset
))
11425 if (do_debug_links
)
11429 printf (_("The %s section contains link(s) to dwo file(s):\n\n"),
11430 debug_displays
[info
].section
.uncompressed_name
);
11434 printf (_(" Name: %s\n"), name
);
11435 printf (_(" Directory: %s\n"), dir
? dir
: _("<not-found>"));
11437 display_data (printf (_(" ID: ")), (unsigned char *) id
, 8);
11439 printf (_(" ID: <not specified>\n"));
11443 if (do_follow_links
)
11444 load_dwo_file (filename
, name
, dir
, id
);
11446 name
= dir
= id
= NULL
;
11452 if (! do_follow_links
)
11453 /* The other debug links will be displayed by display_debug_links()
11454 so we do not need to do any further processing here. */
11457 /* FIXME: We do not check for the presence of both link sections in the same file. */
11458 /* FIXME: We do not check for the presence of multiple, same-name debuglink sections. */
11459 /* FIXME: We do not check for the presence of a dwo link as well as a debuglink. */
11461 check_for_and_load_links (file
, filename
);
11462 if (first_separate_info
!= NULL
)
11465 do_follow_links
= 0;
11470 free_debug_memory (void)
11474 free_all_abbrevs ();
11476 free (cu_abbrev_map
);
11477 cu_abbrev_map
= NULL
;
11478 next_free_abbrev_map_entry
= 0;
11482 shndx_pool_size
= 0;
11483 shndx_pool_used
= 0;
11491 memset (level_type_signed
, 0, sizeof level_type_signed
);
11492 cu_tu_indexes_read
= -1;
11494 for (i
= 0; i
< max
; i
++)
11495 free_debug_section ((enum dwarf_section_display_enum
) i
);
11497 if (debug_information
!= NULL
)
11499 for (i
= 0; i
< alloc_num_debug_info_entries
; i
++)
11501 if (debug_information
[i
].max_loc_offsets
)
11503 free (debug_information
[i
].loc_offsets
);
11504 free (debug_information
[i
].have_frame_base
);
11506 if (debug_information
[i
].max_range_lists
)
11507 free (debug_information
[i
].range_lists
);
11509 free (debug_information
);
11510 debug_information
= NULL
;
11511 alloc_num_debug_info_entries
= num_debug_info_entries
= 0;
11515 separate_info
* next
;
11517 for (d
= first_separate_info
; d
!= NULL
; d
= next
)
11519 close_debug_file (d
->handle
);
11520 free ((void *) d
->filename
);
11524 first_separate_info
= NULL
;
11530 dwarf_select_sections_by_names (const char *names
)
11534 const char * option
;
11538 debug_dump_long_opts
;
11540 static const debug_dump_long_opts opts_table
[] =
11542 /* Please keep this table alpha- sorted. */
11543 { "Ranges", & do_debug_ranges
, 1 },
11544 { "abbrev", & do_debug_abbrevs
, 1 },
11545 { "addr", & do_debug_addr
, 1 },
11546 { "aranges", & do_debug_aranges
, 1 },
11547 { "cu_index", & do_debug_cu_index
, 1 },
11548 { "decodedline", & do_debug_lines
, FLAG_DEBUG_LINES_DECODED
},
11549 { "follow-links", & do_follow_links
, 1 },
11550 { "frames", & do_debug_frames
, 1 },
11551 { "frames-interp", & do_debug_frames_interp
, 1 },
11552 /* The special .gdb_index section. */
11553 { "gdb_index", & do_gdb_index
, 1 },
11554 { "info", & do_debug_info
, 1 },
11555 { "line", & do_debug_lines
, FLAG_DEBUG_LINES_RAW
}, /* For backwards compatibility. */
11556 { "links", & do_debug_links
, 1 },
11557 { "loc", & do_debug_loc
, 1 },
11558 { "macro", & do_debug_macinfo
, 1 },
11559 { "no-follow-links", & do_follow_links
, 0 },
11560 { "pubnames", & do_debug_pubnames
, 1 },
11561 { "pubtypes", & do_debug_pubtypes
, 1 },
11562 /* This entry is for compatibility
11563 with earlier versions of readelf. */
11564 { "ranges", & do_debug_aranges
, 1 },
11565 { "rawline", & do_debug_lines
, FLAG_DEBUG_LINES_RAW
},
11566 { "str", & do_debug_str
, 1 },
11567 { "str-offsets", & do_debug_str_offsets
, 1 },
11568 /* These trace_* sections are used by Itanium VMS. */
11569 { "trace_abbrev", & do_trace_abbrevs
, 1 },
11570 { "trace_aranges", & do_trace_aranges
, 1 },
11571 { "trace_info", & do_trace_info
, 1 },
11580 const debug_dump_long_opts
* entry
;
11582 for (entry
= opts_table
; entry
->option
; entry
++)
11584 size_t len
= strlen (entry
->option
);
11586 if (strncmp (p
, entry
->option
, len
) == 0
11587 && (p
[len
] == ',' || p
[len
] == '\0'))
11589 * entry
->variable
= entry
->val
;
11591 /* The --debug-dump=frames-interp option also
11592 enables the --debug-dump=frames option. */
11593 if (do_debug_frames_interp
)
11594 do_debug_frames
= 1;
11601 if (entry
->option
== NULL
)
11603 warn (_("Unrecognized debug option '%s'\n"), p
);
11604 p
= strchr (p
, ',');
11615 dwarf_select_sections_by_letters (const char *letters
)
11617 unsigned int lindex
= 0;
11619 while (letters
[lindex
])
11620 switch (letters
[lindex
++])
11622 case 'A': do_debug_addr
= 1; break;
11623 case 'a': do_debug_abbrevs
= 1; break;
11624 case 'c': do_debug_cu_index
= 1; break;
11625 case 'F': do_debug_frames_interp
= 1; /* Fall through. */
11626 case 'f': do_debug_frames
= 1; break;
11627 case 'g': do_gdb_index
= 1; break;
11628 case 'i': do_debug_info
= 1; break;
11629 case 'K': do_follow_links
= 1; break;
11630 case 'N': do_follow_links
= 0; break;
11631 case 'k': do_debug_links
= 1; break;
11632 case 'l': do_debug_lines
|= FLAG_DEBUG_LINES_RAW
; break;
11633 case 'L': do_debug_lines
|= FLAG_DEBUG_LINES_DECODED
; break;
11634 case 'm': do_debug_macinfo
= 1; break;
11635 case 'O': do_debug_str_offsets
= 1; break;
11636 case 'o': do_debug_loc
= 1; break;
11637 case 'p': do_debug_pubnames
= 1; break;
11638 case 'R': do_debug_ranges
= 1; break;
11639 case 'r': do_debug_aranges
= 1; break;
11640 case 's': do_debug_str
= 1; break;
11641 case 'T': do_trace_aranges
= 1; break;
11642 case 't': do_debug_pubtypes
= 1; break;
11643 case 'U': do_trace_info
= 1; break;
11644 case 'u': do_trace_abbrevs
= 1; break;
11647 warn (_("Unrecognized debug option '%s'\n"), letters
);
11653 dwarf_select_sections_all (void)
11656 do_debug_abbrevs
= 1;
11657 do_debug_lines
= FLAG_DEBUG_LINES_RAW
;
11658 do_debug_pubnames
= 1;
11659 do_debug_pubtypes
= 1;
11660 do_debug_aranges
= 1;
11661 do_debug_ranges
= 1;
11662 do_debug_frames
= 1;
11663 do_debug_macinfo
= 1;
11668 do_trace_abbrevs
= 1;
11669 do_trace_aranges
= 1;
11671 do_debug_cu_index
= 1;
11672 do_follow_links
= 1;
11673 do_debug_links
= 1;
11674 do_debug_str_offsets
= 1;
11677 #define NO_ABBREVS NULL, NULL, NULL, 0, 0, 0, NULL, 0
11678 #define ABBREV(N) NULL, NULL, NULL, 0, 0, N, NULL, 0
11680 /* N.B. The order here must match the order in section_display_enum. */
11682 struct dwarf_section_display debug_displays
[] =
11684 { { ".debug_abbrev", ".zdebug_abbrev", NO_ABBREVS
}, display_debug_abbrev
, &do_debug_abbrevs
, false },
11685 { { ".debug_aranges", ".zdebug_aranges", NO_ABBREVS
}, display_debug_aranges
, &do_debug_aranges
, true },
11686 { { ".debug_frame", ".zdebug_frame", NO_ABBREVS
}, display_debug_frames
, &do_debug_frames
, true },
11687 { { ".debug_info", ".zdebug_info", ABBREV (abbrev
)}, display_debug_info
, &do_debug_info
, true },
11688 { { ".debug_line", ".zdebug_line", NO_ABBREVS
}, display_debug_lines
, &do_debug_lines
, true },
11689 { { ".debug_pubnames", ".zdebug_pubnames", NO_ABBREVS
}, display_debug_pubnames
, &do_debug_pubnames
, false },
11690 { { ".debug_gnu_pubnames", ".zdebug_gnu_pubnames", NO_ABBREVS
}, display_debug_gnu_pubnames
, &do_debug_pubnames
, false },
11691 { { ".eh_frame", "", NO_ABBREVS
}, display_debug_frames
, &do_debug_frames
, true },
11692 { { ".debug_macinfo", ".zdebug_macinfo", NO_ABBREVS
}, display_debug_macinfo
, &do_debug_macinfo
, false },
11693 { { ".debug_macro", ".zdebug_macro", NO_ABBREVS
}, display_debug_macro
, &do_debug_macinfo
, true },
11694 { { ".debug_str", ".zdebug_str", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, false },
11695 { { ".debug_line_str", ".zdebug_line_str", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, false },
11696 { { ".debug_loc", ".zdebug_loc", NO_ABBREVS
}, display_debug_loc
, &do_debug_loc
, true },
11697 { { ".debug_loclists", ".zdebug_loclists", NO_ABBREVS
}, display_debug_loc
, &do_debug_loc
, true },
11698 { { ".debug_pubtypes", ".zdebug_pubtypes", NO_ABBREVS
}, display_debug_pubnames
, &do_debug_pubtypes
, false },
11699 { { ".debug_gnu_pubtypes", ".zdebug_gnu_pubtypes", NO_ABBREVS
}, display_debug_gnu_pubnames
, &do_debug_pubtypes
, false },
11700 { { ".debug_ranges", ".zdebug_ranges", NO_ABBREVS
}, display_debug_ranges
, &do_debug_ranges
, true },
11701 { { ".debug_rnglists", ".zdebug_rnglists", NO_ABBREVS
}, display_debug_ranges
, &do_debug_ranges
, true },
11702 { { ".debug_static_func", ".zdebug_static_func", NO_ABBREVS
}, display_debug_not_supported
, NULL
, false },
11703 { { ".debug_static_vars", ".zdebug_static_vars", NO_ABBREVS
}, display_debug_not_supported
, NULL
, false },
11704 { { ".debug_types", ".zdebug_types", ABBREV (abbrev
) }, display_debug_types
, &do_debug_info
, true },
11705 { { ".debug_weaknames", ".zdebug_weaknames", NO_ABBREVS
}, display_debug_not_supported
, NULL
, false },
11706 { { ".gdb_index", "", NO_ABBREVS
}, display_gdb_index
, &do_gdb_index
, false },
11707 { { ".debug_names", "", NO_ABBREVS
}, display_debug_names
, &do_gdb_index
, false },
11708 { { ".trace_info", "", ABBREV (trace_abbrev
) }, display_trace_info
, &do_trace_info
, true },
11709 { { ".trace_abbrev", "", NO_ABBREVS
}, display_debug_abbrev
, &do_trace_abbrevs
, false },
11710 { { ".trace_aranges", "", NO_ABBREVS
}, display_debug_aranges
, &do_trace_aranges
, false },
11711 { { ".debug_info.dwo", ".zdebug_info.dwo", ABBREV (abbrev_dwo
) }, display_debug_info
, &do_debug_info
, true },
11712 { { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo", NO_ABBREVS
}, display_debug_abbrev
, &do_debug_abbrevs
, false },
11713 { { ".debug_types.dwo", ".zdebug_types.dwo", ABBREV (abbrev_dwo
) }, display_debug_types
, &do_debug_info
, true },
11714 { { ".debug_line.dwo", ".zdebug_line.dwo", NO_ABBREVS
}, display_debug_lines
, &do_debug_lines
, true },
11715 { { ".debug_loc.dwo", ".zdebug_loc.dwo", NO_ABBREVS
}, display_debug_loc
, &do_debug_loc
, true },
11716 { { ".debug_macro.dwo", ".zdebug_macro.dwo", NO_ABBREVS
}, display_debug_macro
, &do_debug_macinfo
, true },
11717 { { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo", NO_ABBREVS
}, display_debug_macinfo
, &do_debug_macinfo
, false },
11718 { { ".debug_str.dwo", ".zdebug_str.dwo", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, true },
11719 { { ".debug_str_offsets", ".zdebug_str_offsets", NO_ABBREVS
}, display_debug_str_offsets
, &do_debug_str_offsets
, true },
11720 { { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo", NO_ABBREVS
}, display_debug_str_offsets
, &do_debug_str_offsets
, true },
11721 { { ".debug_addr", ".zdebug_addr", NO_ABBREVS
}, display_debug_addr
, &do_debug_addr
, true },
11722 { { ".debug_cu_index", "", NO_ABBREVS
}, display_cu_index
, &do_debug_cu_index
, false },
11723 { { ".debug_tu_index", "", NO_ABBREVS
}, display_cu_index
, &do_debug_cu_index
, false },
11724 { { ".gnu_debuglink", "", NO_ABBREVS
}, display_debug_links
, &do_debug_links
, false },
11725 { { ".gnu_debugaltlink", "", NO_ABBREVS
}, display_debug_links
, &do_debug_links
, false },
11726 { { ".debug_sup", "", NO_ABBREVS
}, display_debug_sup
, &do_debug_links
, false },
11727 /* Separate debug info files can containt their own .debug_str section,
11728 and this might be in *addition* to a .debug_str section already present
11729 in the main file. Hence we need to have two entries for .debug_str. */
11730 { { ".debug_str", ".zdebug_str", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, false },
11733 /* A static assertion. */
11734 extern int debug_displays_assert
[ARRAY_SIZE (debug_displays
) == max
? 1 : -1];