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 if (length
<= (dwarf_vma
) (end
- curr
))
7491 entries_end
= curr
+ length
;
7494 warn (_("Section %s is too small %#lx\n"),
7495 section
->name
, (unsigned long) section
->size
);
7500 SAFE_BYTE_GET_AND_INC (version
, curr
, 2, end
);
7502 warn (_("Unexpected version number in str_offset header: %#x\n"), version
);
7505 SAFE_BYTE_GET_AND_INC (padding
, curr
, 2, end
);
7507 warn (_("Unexpected value in str_offset header's padding field: %#x\n"), padding
);
7509 printf (_(" Length: %#lx\n"), (unsigned long) length
);
7510 printf (_(" Version: %#lx\n"), (unsigned long) version
);
7511 printf (_(" Index Offset [String]\n"));
7514 for (idx
= 0; curr
< entries_end
; idx
++)
7517 const unsigned char * string
;
7519 if ((dwarf_vma
) (entries_end
- curr
) < entry_length
)
7520 /* Not enough space to read one entry_length, give up. */
7523 SAFE_BYTE_GET_AND_INC (offset
, curr
, entry_length
, entries_end
);
7525 string
= (const unsigned char *)
7526 fetch_indexed_string (idx
, NULL
, entry_length
, dwo
);
7528 string
= fetch_indirect_string (offset
);
7530 printf (" %8lu %8s %s\n", idx
, dwarf_vmatoa ("x", offset
),
7538 /* Each debug_information[x].range_lists[y] gets this representation for
7539 sorting purposes. */
7543 /* The debug_information[x].range_lists[y] value. */
7544 dwarf_vma ranges_offset
;
7546 /* Original debug_information to find parameters of the data. */
7547 debug_info
*debug_info_p
;
7550 /* Sort struct range_entry in ascending order of its RANGES_OFFSET. */
7553 range_entry_compar (const void *ap
, const void *bp
)
7555 const struct range_entry
*a_re
= (const struct range_entry
*) ap
;
7556 const struct range_entry
*b_re
= (const struct range_entry
*) bp
;
7557 const dwarf_vma a
= a_re
->ranges_offset
;
7558 const dwarf_vma b
= b_re
->ranges_offset
;
7560 return (a
> b
) - (b
> a
);
7564 display_debug_ranges_list (unsigned char *start
, unsigned char *finish
,
7565 unsigned int pointer_size
, unsigned long offset
,
7566 unsigned long base_address
)
7568 while (start
< finish
)
7573 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
7574 if (start
>= finish
)
7576 SAFE_SIGNED_BYTE_GET_AND_INC (end
, start
, pointer_size
, finish
);
7578 printf (" %8.8lx ", offset
);
7580 if (begin
== 0 && end
== 0)
7582 printf (_("<End of list>\n"));
7586 /* Check base address specifiers. */
7587 if (is_max_address (begin
, pointer_size
)
7588 && !is_max_address (end
, pointer_size
))
7591 print_dwarf_vma (begin
, pointer_size
);
7592 print_dwarf_vma (end
, pointer_size
);
7593 printf ("(base address)\n");
7597 print_dwarf_vma (begin
+ base_address
, pointer_size
);
7598 print_dwarf_vma (end
+ base_address
, pointer_size
);
7601 fputs (_("(start == end)"), stdout
);
7602 else if (begin
> end
)
7603 fputs (_("(start > end)"), stdout
);
7610 display_debug_rnglists_list (unsigned char *start
, unsigned char *finish
,
7611 unsigned int pointer_size
, unsigned long offset
,
7612 unsigned long base_address
)
7614 unsigned char *next
= start
;
7618 unsigned long off
= offset
+ (start
- next
);
7619 enum dwarf_range_list_entry rlet
;
7620 /* Initialize it due to a false compiler warning. */
7621 dwarf_vma begin
= -1, length
, end
= -1;
7623 if (start
+ 1 > finish
)
7625 warn (_("Range list starting at offset 0x%lx is not terminated.\n"),
7630 printf (" %8.8lx ", off
);
7632 SAFE_BYTE_GET_AND_INC (rlet
, start
, 1, finish
);
7636 case DW_RLE_end_of_list
:
7637 printf (_("<End of list>\n"));
7639 case DW_RLE_base_address
:
7640 SAFE_BYTE_GET_AND_INC (base_address
, start
, pointer_size
, finish
);
7641 print_dwarf_vma (base_address
, pointer_size
);
7642 printf (_("(base address)\n"));
7644 case DW_RLE_start_length
:
7645 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
7646 READ_ULEB (length
, start
, finish
);
7647 end
= begin
+ length
;
7649 case DW_RLE_offset_pair
:
7650 READ_ULEB (begin
, start
, finish
);
7651 READ_ULEB (end
, start
, finish
);
7653 case DW_RLE_start_end
:
7654 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
7655 SAFE_BYTE_GET_AND_INC (end
, start
, pointer_size
, finish
);
7658 error (_("Invalid range list entry type %d\n"), rlet
);
7659 rlet
= DW_RLE_end_of_list
;
7662 if (rlet
== DW_RLE_end_of_list
)
7664 if (rlet
== DW_RLE_base_address
)
7667 /* Only a DW_RLE_offset_pair needs the base address added. */
7668 if (rlet
== DW_RLE_offset_pair
)
7670 begin
+= base_address
;
7671 end
+= base_address
;
7674 print_dwarf_vma (begin
, pointer_size
);
7675 print_dwarf_vma (end
, pointer_size
);
7678 fputs (_("(start == end)"), stdout
);
7679 else if (begin
> end
)
7680 fputs (_("(start > end)"), stdout
);
7687 display_debug_ranges (struct dwarf_section
*section
,
7688 void *file ATTRIBUTE_UNUSED
)
7690 unsigned char *start
= section
->start
;
7691 unsigned char *last_start
= start
;
7692 unsigned long bytes
= section
->size
;
7693 unsigned char *section_begin
= start
;
7694 unsigned char *finish
= start
+ bytes
;
7695 unsigned int num_range_list
, i
;
7696 struct range_entry
*range_entries
, *range_entry_fill
;
7697 int is_rnglists
= strstr (section
->name
, "debug_rnglists") != NULL
;
7698 /* Initialize it due to a false compiler warning. */
7699 unsigned char address_size
= 0;
7700 dwarf_vma last_offset
= 0;
7704 printf (_("\nThe %s section is empty.\n"), section
->name
);
7710 dwarf_vma initial_length
;
7711 unsigned int initial_length_size
;
7712 unsigned char segment_selector_size
;
7713 unsigned int offset_size
, offset_entry_count
;
7714 unsigned short version
;
7716 /* Get and check the length of the block. */
7717 SAFE_BYTE_GET_AND_INC (initial_length
, start
, 4, finish
);
7719 if (initial_length
== 0xffffffff)
7721 /* This section is 64-bit DWARF 3. */
7722 SAFE_BYTE_GET_AND_INC (initial_length
, start
, 8, finish
);
7724 initial_length_size
= 12;
7729 initial_length_size
= 4;
7732 if (initial_length
+ initial_length_size
> section
->size
)
7734 /* If the length field has a relocation against it, then we should
7735 not complain if it is inaccurate (and probably negative).
7736 It is copied from .debug_line handling code. */
7737 if (reloc_at (section
, (start
- section
->start
) - offset_size
))
7739 initial_length
= (finish
- start
) - initial_length_size
;
7743 warn (_("The length field (0x%lx) in the debug_rnglists header is wrong - the section is too small\n"),
7744 (long) initial_length
);
7749 /* Get and check the version number. */
7750 SAFE_BYTE_GET_AND_INC (version
, start
, 2, finish
);
7754 warn (_("Only DWARF version 5 debug_rnglists info "
7755 "is currently supported.\n"));
7759 SAFE_BYTE_GET_AND_INC (address_size
, start
, 1, finish
);
7761 SAFE_BYTE_GET_AND_INC (segment_selector_size
, start
, 1, finish
);
7762 if (segment_selector_size
!= 0)
7764 warn (_("The %s section contains "
7765 "unsupported segment selector size: %d.\n"),
7766 section
->name
, segment_selector_size
);
7770 SAFE_BYTE_GET_AND_INC (offset_entry_count
, start
, 4, finish
);
7771 if (offset_entry_count
!= 0)
7773 warn (_("The %s section contains "
7774 "unsupported offset entry count: %u.\n"),
7775 section
->name
, offset_entry_count
);
7780 if (load_debug_info (file
) == 0)
7782 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
7788 for (i
= 0; i
< num_debug_info_entries
; i
++)
7790 if (debug_information
[i
].dwarf_version
< 5 && is_rnglists
)
7791 /* Skip .debug_rnglists reference. */
7793 if (debug_information
[i
].dwarf_version
>= 5 && !is_rnglists
)
7794 /* Skip .debug_range reference. */
7796 num_range_list
+= debug_information
[i
].num_range_lists
;
7799 if (num_range_list
== 0)
7801 /* This can happen when the file was compiled with -gsplit-debug
7802 which removes references to range lists from the primary .o file. */
7803 printf (_("No range lists in .debug_info section.\n"));
7807 range_entries
= (struct range_entry
*)
7808 xmalloc (sizeof (*range_entries
) * num_range_list
);
7809 range_entry_fill
= range_entries
;
7811 for (i
= 0; i
< num_debug_info_entries
; i
++)
7813 debug_info
*debug_info_p
= &debug_information
[i
];
7816 if (debug_information
[i
].dwarf_version
< 5 && is_rnglists
)
7817 /* Skip .debug_rnglists reference. */
7819 if (debug_information
[i
].dwarf_version
>= 5 && !is_rnglists
)
7820 /* Skip .debug_range reference. */
7823 for (j
= 0; j
< debug_info_p
->num_range_lists
; j
++)
7825 range_entry_fill
->ranges_offset
= debug_info_p
->range_lists
[j
];
7826 range_entry_fill
->debug_info_p
= debug_info_p
;
7831 qsort (range_entries
, num_range_list
, sizeof (*range_entries
),
7832 range_entry_compar
);
7834 if (dwarf_check
!= 0 && range_entries
[0].ranges_offset
!= 0)
7835 warn (_("Range lists in %s section start at 0x%lx\n"),
7836 section
->name
, (unsigned long) range_entries
[0].ranges_offset
);
7838 introduce (section
, false);
7840 printf (_(" Offset Begin End\n"));
7842 for (i
= 0; i
< num_range_list
; i
++)
7844 struct range_entry
*range_entry
= &range_entries
[i
];
7845 debug_info
*debug_info_p
= range_entry
->debug_info_p
;
7846 unsigned int pointer_size
;
7848 unsigned char *next
;
7849 dwarf_vma base_address
;
7851 pointer_size
= (is_rnglists
? address_size
: debug_info_p
->pointer_size
);
7852 offset
= range_entry
->ranges_offset
;
7853 next
= section_begin
+ offset
;
7854 base_address
= debug_info_p
->base_address
;
7856 /* PR 17512: file: 001-101485-0.001:0.1. */
7857 if (pointer_size
< 2 || pointer_size
> 8)
7859 warn (_("Corrupt pointer size (%d) in debug entry at offset %8.8lx\n"),
7860 pointer_size
, (unsigned long) offset
);
7864 if (next
< section_begin
|| next
>= finish
)
7866 warn (_("Corrupt offset (%#8.8lx) in range entry %u\n"),
7867 (unsigned long) offset
, i
);
7871 /* If multiple DWARF entities reference the same range then we will
7872 have multiple entries in the `range_entries' list for the same
7873 offset. Thanks to the sort above these will all be consecutive in
7874 the `range_entries' list, so we can easily ignore duplicates
7876 if (i
> 0 && last_offset
== offset
)
7878 last_offset
= offset
;
7880 if (dwarf_check
!= 0 && i
> 0)
7883 warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"),
7884 (unsigned long) (start
- section_begin
),
7885 (unsigned long) (next
- section_begin
), section
->name
);
7886 else if (start
> next
)
7888 if (next
== last_start
)
7890 warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"),
7891 (unsigned long) (start
- section_begin
),
7892 (unsigned long) (next
- section_begin
), section
->name
);
7899 (is_rnglists
? display_debug_rnglists_list
: display_debug_ranges_list
)
7900 (start
, finish
, pointer_size
, offset
, base_address
);
7904 free (range_entries
);
7909 typedef struct Frame_Chunk
7911 struct Frame_Chunk
*next
;
7912 unsigned char *chunk_start
;
7914 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
7915 short int *col_type
;
7918 unsigned int code_factor
;
7922 unsigned int cfa_reg
;
7923 dwarf_vma cfa_offset
;
7925 unsigned char fde_encoding
;
7926 unsigned char cfa_exp
;
7927 unsigned char ptr_size
;
7928 unsigned char segment_size
;
7932 typedef const char *(*dwarf_regname_lookup_ftype
) (unsigned int);
7933 static dwarf_regname_lookup_ftype dwarf_regnames_lookup_func
;
7934 static const char *const *dwarf_regnames
;
7935 static unsigned int dwarf_regnames_count
;
7938 /* A marker for a col_type that means this column was never referenced
7939 in the frame info. */
7940 #define DW_CFA_unreferenced (-1)
7942 /* Return 0 if no more space is needed, 1 if more space is needed,
7943 -1 for invalid reg. */
7946 frame_need_space (Frame_Chunk
*fc
, unsigned int reg
)
7948 unsigned int prev
= fc
->ncols
;
7950 if (reg
< (unsigned int) fc
->ncols
)
7953 if (dwarf_regnames_count
> 0
7954 && reg
> dwarf_regnames_count
)
7957 fc
->ncols
= reg
+ 1;
7958 /* PR 17512: file: 10450-2643-0.004.
7959 If reg == -1 then this can happen... */
7963 /* PR 17512: file: 2844a11d. */
7964 if (fc
->ncols
> 1024 && dwarf_regnames_count
== 0)
7966 error (_("Unfeasibly large register number: %u\n"), reg
);
7968 /* FIXME: 1024 is an arbitrary limit. Increase it if
7969 we ever encounter a valid binary that exceeds it. */
7973 fc
->col_type
= (short int *) xcrealloc (fc
->col_type
, fc
->ncols
,
7974 sizeof (short int));
7975 fc
->col_offset
= (int *) xcrealloc (fc
->col_offset
, fc
->ncols
, sizeof (int));
7976 /* PR 17512: file:002-10025-0.005. */
7977 if (fc
->col_type
== NULL
|| fc
->col_offset
== NULL
)
7979 error (_("Out of memory allocating %u columns in dwarf frame arrays\n"),
7985 while (prev
< fc
->ncols
)
7987 fc
->col_type
[prev
] = DW_CFA_unreferenced
;
7988 fc
->col_offset
[prev
] = 0;
7994 static const char *const dwarf_regnames_i386
[] =
7996 "eax", "ecx", "edx", "ebx", /* 0 - 3 */
7997 "esp", "ebp", "esi", "edi", /* 4 - 7 */
7998 "eip", "eflags", NULL
, /* 8 - 10 */
7999 "st0", "st1", "st2", "st3", /* 11 - 14 */
8000 "st4", "st5", "st6", "st7", /* 15 - 18 */
8001 NULL
, NULL
, /* 19 - 20 */
8002 "xmm0", "xmm1", "xmm2", "xmm3", /* 21 - 24 */
8003 "xmm4", "xmm5", "xmm6", "xmm7", /* 25 - 28 */
8004 "mm0", "mm1", "mm2", "mm3", /* 29 - 32 */
8005 "mm4", "mm5", "mm6", "mm7", /* 33 - 36 */
8006 "fcw", "fsw", "mxcsr", /* 37 - 39 */
8007 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
, /* 40 - 47 */
8008 "tr", "ldtr", /* 48 - 49 */
8009 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 50 - 57 */
8010 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 58 - 65 */
8011 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 66 - 73 */
8012 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 74 - 81 */
8013 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 82 - 89 */
8014 NULL
, NULL
, NULL
, /* 90 - 92 */
8015 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7" /* 93 - 100 */
8018 static const char *const dwarf_regnames_iamcu
[] =
8020 "eax", "ecx", "edx", "ebx", /* 0 - 3 */
8021 "esp", "ebp", "esi", "edi", /* 4 - 7 */
8022 "eip", "eflags", NULL
, /* 8 - 10 */
8023 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 11 - 18 */
8024 NULL
, NULL
, /* 19 - 20 */
8025 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 21 - 28 */
8026 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 29 - 36 */
8027 NULL
, NULL
, NULL
, /* 37 - 39 */
8028 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
, /* 40 - 47 */
8029 "tr", "ldtr", /* 48 - 49 */
8030 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 50 - 57 */
8031 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 58 - 65 */
8032 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 66 - 73 */
8033 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 74 - 81 */
8034 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 82 - 89 */
8035 NULL
, NULL
, NULL
, /* 90 - 92 */
8036 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
/* 93 - 100 */
8040 init_dwarf_regnames_i386 (void)
8042 dwarf_regnames
= dwarf_regnames_i386
;
8043 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_i386
);
8044 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8048 init_dwarf_regnames_iamcu (void)
8050 dwarf_regnames
= dwarf_regnames_iamcu
;
8051 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_iamcu
);
8052 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8055 static const char *const dwarf_regnames_x86_64
[] =
8057 "rax", "rdx", "rcx", "rbx",
8058 "rsi", "rdi", "rbp", "rsp",
8059 "r8", "r9", "r10", "r11",
8060 "r12", "r13", "r14", "r15",
8062 "xmm0", "xmm1", "xmm2", "xmm3",
8063 "xmm4", "xmm5", "xmm6", "xmm7",
8064 "xmm8", "xmm9", "xmm10", "xmm11",
8065 "xmm12", "xmm13", "xmm14", "xmm15",
8066 "st0", "st1", "st2", "st3",
8067 "st4", "st5", "st6", "st7",
8068 "mm0", "mm1", "mm2", "mm3",
8069 "mm4", "mm5", "mm6", "mm7",
8071 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
,
8072 "fs.base", "gs.base", NULL
, NULL
,
8074 "mxcsr", "fcw", "fsw",
8075 "xmm16", "xmm17", "xmm18", "xmm19",
8076 "xmm20", "xmm21", "xmm22", "xmm23",
8077 "xmm24", "xmm25", "xmm26", "xmm27",
8078 "xmm28", "xmm29", "xmm30", "xmm31",
8079 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 83 - 90 */
8080 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 91 - 98 */
8081 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 99 - 106 */
8082 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 107 - 114 */
8083 NULL
, NULL
, NULL
, /* 115 - 117 */
8084 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7"
8088 init_dwarf_regnames_x86_64 (void)
8090 dwarf_regnames
= dwarf_regnames_x86_64
;
8091 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_x86_64
);
8092 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8095 static const char *const dwarf_regnames_aarch64
[] =
8097 "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7",
8098 "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15",
8099 "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23",
8100 "x24", "x25", "x26", "x27", "x28", "x29", "x30", "sp",
8101 NULL
, "elr", NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
8102 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, "vg", "ffr",
8103 "p0", "p1", "p2", "p3", "p4", "p5", "p6", "p7",
8104 "p8", "p9", "p10", "p11", "p12", "p13", "p14", "p15",
8105 "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7",
8106 "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15",
8107 "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23",
8108 "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31",
8109 "z0", "z1", "z2", "z3", "z4", "z5", "z6", "z7",
8110 "z8", "z9", "z10", "z11", "z12", "z13", "z14", "z15",
8111 "z16", "z17", "z18", "z19", "z20", "z21", "z22", "z23",
8112 "z24", "z25", "z26", "z27", "z28", "z29", "z30", "z31",
8116 init_dwarf_regnames_aarch64 (void)
8118 dwarf_regnames
= dwarf_regnames_aarch64
;
8119 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_aarch64
);
8120 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8123 static const char *const dwarf_regnames_s390
[] =
8125 /* Avoid saying "r5 (r5)", so omit the names of r0-r15. */
8126 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
8127 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
8128 "f0", "f2", "f4", "f6", "f1", "f3", "f5", "f7",
8129 "f8", "f10", "f12", "f14", "f9", "f11", "f13", "f15",
8130 "cr0", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7",
8131 "cr8", "cr9", "cr10", "cr11", "cr12", "cr13", "cr14", "cr15",
8132 "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7",
8133 "a8", "a9", "a10", "a11", "a12", "a13", "a14", "a15",
8136 "v16", "v18", "v20", "v22", "v17", "v19", "v21", "v23",
8137 "v24", "v26", "v28", "v30", "v25", "v27", "v29", "v31",
8141 init_dwarf_regnames_s390 (void)
8143 dwarf_regnames
= dwarf_regnames_s390
;
8144 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_s390
);
8145 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8148 static const char *const dwarf_regnames_riscv
[] =
8150 "zero", "ra", "sp", "gp", "tp", "t0", "t1", "t2", /* 0 - 7 */
8151 "s0", "s1", "a0", "a1", "a2", "a3", "a4", "a5", /* 8 - 15 */
8152 "a6", "a7", "s2", "s3", "s4", "s5", "s6", "s7", /* 16 - 23 */
8153 "s8", "s9", "s10", "s11", "t3", "t4", "t5", "t6", /* 24 - 31 */
8154 "ft0", "ft1", "ft2", "ft3", "ft4", "ft5", "ft6", "ft7", /* 32 - 39 */
8155 "fs0", "fs1", /* 40 - 41 */
8156 "fa0", "fa1", "fa2", "fa3", "fa4", "fa5", "fa6", "fa7", /* 42 - 49 */
8157 "fs2", "fs3", "fs4", "fs5", "fs6", "fs7", "fs8", "fs9", /* 50 - 57 */
8158 "fs10", "fs11", /* 58 - 59 */
8159 "ft8", "ft9", "ft10", "ft11" /* 60 - 63 */
8162 /* A RISC-V replacement for REGNAME_INTERNAL_BY_TABLE_ONLY which handles
8163 the large number of CSRs. */
8166 regname_internal_riscv (unsigned int regno
)
8168 const char *name
= NULL
;
8170 /* Lookup in the table first, this covers GPR and FPR. */
8171 if (regno
< ARRAY_SIZE (dwarf_regnames_riscv
))
8172 name
= dwarf_regnames_riscv
[regno
];
8173 else if (regno
>= 4096 && regno
<= 8191)
8175 /* This might be a CSR, these live in a sparse number space from 4096
8176 to 8191 These numbers are defined in the RISC-V ELF ABI
8180 #define DECLARE_CSR(NAME,VALUE,CLASS,DEFINE_VER,ABORT_VER) \
8181 case VALUE + 4096: name = #NAME; break;
8182 #include "opcode/riscv-opc.h"
8187 static char csr_name
[10];
8188 snprintf (csr_name
, sizeof (csr_name
), "csr%d", (regno
- 4096));
8199 init_dwarf_regnames_riscv (void)
8201 dwarf_regnames
= NULL
;
8202 dwarf_regnames_count
= 8192;
8203 dwarf_regnames_lookup_func
= regname_internal_riscv
;
8207 init_dwarf_regnames_by_elf_machine_code (unsigned int e_machine
)
8209 dwarf_regnames_lookup_func
= NULL
;
8214 init_dwarf_regnames_i386 ();
8218 init_dwarf_regnames_iamcu ();
8224 init_dwarf_regnames_x86_64 ();
8228 init_dwarf_regnames_aarch64 ();
8232 init_dwarf_regnames_s390 ();
8236 init_dwarf_regnames_riscv ();
8244 /* Initialize the DWARF register name lookup state based on the
8245 architecture and specific machine type of a BFD. */
8248 init_dwarf_regnames_by_bfd_arch_and_mach (enum bfd_architecture arch
,
8251 dwarf_regnames_lookup_func
= NULL
;
8258 case bfd_mach_x86_64
:
8259 case bfd_mach_x86_64_intel_syntax
:
8260 case bfd_mach_x64_32
:
8261 case bfd_mach_x64_32_intel_syntax
:
8262 init_dwarf_regnames_x86_64 ();
8266 init_dwarf_regnames_i386 ();
8271 case bfd_arch_iamcu
:
8272 init_dwarf_regnames_iamcu ();
8275 case bfd_arch_aarch64
:
8276 init_dwarf_regnames_aarch64();
8280 init_dwarf_regnames_s390 ();
8283 case bfd_arch_riscv
:
8284 init_dwarf_regnames_riscv ();
8293 regname_internal_by_table_only (unsigned int regno
)
8295 if (dwarf_regnames
!= NULL
8296 && regno
< dwarf_regnames_count
8297 && dwarf_regnames
[regno
] != NULL
)
8298 return dwarf_regnames
[regno
];
8304 regname (unsigned int regno
, int name_only_p
)
8306 static char reg
[64];
8308 const char *name
= NULL
;
8310 if (dwarf_regnames_lookup_func
!= NULL
)
8311 name
= dwarf_regnames_lookup_func (regno
);
8317 snprintf (reg
, sizeof (reg
), "r%d (%s)", regno
, name
);
8320 snprintf (reg
, sizeof (reg
), "r%d", regno
);
8325 frame_display_row (Frame_Chunk
*fc
, int *need_col_headers
, unsigned int *max_regs
)
8330 if (*max_regs
!= fc
->ncols
)
8331 *max_regs
= fc
->ncols
;
8333 if (*need_col_headers
)
8335 *need_col_headers
= 0;
8337 printf ("%-*s CFA ", eh_addr_size
* 2, " LOC");
8339 for (r
= 0; r
< *max_regs
; r
++)
8340 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
8345 printf ("%-5s ", regname (r
, 1));
8351 print_dwarf_vma (fc
->pc_begin
, eh_addr_size
);
8353 strcpy (tmp
, "exp");
8355 sprintf (tmp
, "%s%+d", regname (fc
->cfa_reg
, 1), (int) fc
->cfa_offset
);
8356 printf ("%-8s ", tmp
);
8358 for (r
= 0; r
< fc
->ncols
; r
++)
8360 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
8362 switch (fc
->col_type
[r
])
8364 case DW_CFA_undefined
:
8367 case DW_CFA_same_value
:
8371 sprintf (tmp
, "c%+d", fc
->col_offset
[r
]);
8373 case DW_CFA_val_offset
:
8374 sprintf (tmp
, "v%+d", fc
->col_offset
[r
]);
8376 case DW_CFA_register
:
8377 sprintf (tmp
, "%s", regname (fc
->col_offset
[r
], 0));
8379 case DW_CFA_expression
:
8380 strcpy (tmp
, "exp");
8382 case DW_CFA_val_expression
:
8383 strcpy (tmp
, "vexp");
8386 strcpy (tmp
, "n/a");
8389 printf ("%-5s ", tmp
);
8395 #define GET(VAR, N) SAFE_BYTE_GET_AND_INC (VAR, start, N, end)
8397 static unsigned char *
8398 read_cie (unsigned char *start
, unsigned char *end
,
8399 Frame_Chunk
**p_cie
, int *p_version
,
8400 bfd_size_type
*p_aug_len
, unsigned char **p_aug
)
8404 unsigned char *augmentation_data
= NULL
;
8405 bfd_size_type augmentation_data_len
= 0;
8408 /* PR 17512: file: 001-228113-0.004. */
8412 fc
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
8413 memset (fc
, 0, sizeof (Frame_Chunk
));
8415 fc
->col_type
= (short int *) xmalloc (sizeof (short int));
8416 fc
->col_offset
= (int *) xmalloc (sizeof (int));
8420 fc
->augmentation
= (char *) start
;
8421 /* PR 17512: file: 001-228113-0.004.
8422 Skip past augmentation name, but avoid running off the end of the data. */
8424 if (* start
++ == '\0')
8428 warn (_("No terminator for augmentation name\n"));
8432 if (strcmp (fc
->augmentation
, "eh") == 0)
8433 start
+= eh_addr_size
;
8437 GET (fc
->ptr_size
, 1);
8438 if (fc
->ptr_size
< 1 || fc
->ptr_size
> 8)
8440 warn (_("Invalid pointer size (%d) in CIE data\n"), fc
->ptr_size
);
8444 GET (fc
->segment_size
, 1);
8445 /* PR 17512: file: e99d2804. */
8446 if (fc
->segment_size
> 8 || fc
->segment_size
+ fc
->ptr_size
> 8)
8448 warn (_("Invalid segment size (%d) in CIE data\n"), fc
->segment_size
);
8452 eh_addr_size
= fc
->ptr_size
;
8456 fc
->ptr_size
= eh_addr_size
;
8457 fc
->segment_size
= 0;
8460 READ_ULEB (fc
->code_factor
, start
, end
);
8461 READ_SLEB (fc
->data_factor
, start
, end
);
8469 READ_ULEB (fc
->ra
, start
, end
);
8472 if (fc
->augmentation
[0] == 'z')
8474 READ_ULEB (augmentation_data_len
, start
, end
);
8475 augmentation_data
= start
;
8476 /* PR 17512: file: 11042-2589-0.004. */
8477 if (augmentation_data_len
> (bfd_size_type
) (end
- start
))
8479 warn (_("Augmentation data too long: 0x%s, expected at most %#lx\n"),
8480 dwarf_vmatoa ("x", augmentation_data_len
),
8481 (unsigned long) (end
- start
));
8484 start
+= augmentation_data_len
;
8487 if (augmentation_data_len
)
8491 unsigned char *qend
;
8493 p
= (unsigned char *) fc
->augmentation
+ 1;
8494 q
= augmentation_data
;
8495 qend
= q
+ augmentation_data_len
;
8497 while (p
< end
&& q
< qend
)
8502 q
+= 1 + size_of_encoded_value (*q
);
8504 fc
->fde_encoding
= *q
++;
8513 /* Note - it is OK if this loop terminates with q < qend.
8514 Padding may have been inserted to align the end of the CIE. */
8519 *p_version
= version
;
8522 *p_aug_len
= augmentation_data_len
;
8523 *p_aug
= augmentation_data
;
8528 free (fc
->col_offset
);
8529 free (fc
->col_type
);
8534 /* Prints out the contents on the DATA array formatted as unsigned bytes.
8535 If do_wide is not enabled, then formats the output to fit into 80 columns.
8536 PRINTED contains the number of characters already written to the current
8540 display_data (bfd_size_type printed
,
8541 const unsigned char * data
,
8542 const bfd_size_type len
)
8544 if (do_wide
|| len
< ((80 - printed
) / 3))
8545 for (printed
= 0; printed
< len
; ++printed
)
8546 printf (" %02x", data
[printed
]);
8549 for (printed
= 0; printed
< len
; ++printed
)
8551 if (printed
% (80 / 3) == 0)
8553 printf (" %02x", data
[printed
]);
8558 /* Prints out the contents on the augmentation data array.
8559 If do_wide is not enabled, then formats the output to fit into 80 columns. */
8562 display_augmentation_data (const unsigned char * data
, const bfd_size_type len
)
8566 i
= printf (_(" Augmentation data: "));
8567 display_data (i
, data
, len
);
8571 display_debug_frames (struct dwarf_section
*section
,
8572 void *file ATTRIBUTE_UNUSED
)
8574 unsigned char *start
= section
->start
;
8575 unsigned char *end
= start
+ section
->size
;
8576 unsigned char *section_start
= start
;
8577 Frame_Chunk
*chunks
= NULL
, *forward_refs
= NULL
;
8578 Frame_Chunk
*remembered_state
= NULL
;
8580 bool is_eh
= strcmp (section
->name
, ".eh_frame") == 0;
8581 unsigned int max_regs
= 0;
8582 const char *bad_reg
= _("bad register: ");
8583 unsigned int saved_eh_addr_size
= eh_addr_size
;
8585 introduce (section
, false);
8589 unsigned char *saved_start
;
8590 unsigned char *block_end
;
8595 int need_col_headers
= 1;
8596 unsigned char *augmentation_data
= NULL
;
8597 bfd_size_type augmentation_data_len
= 0;
8598 unsigned int encoded_ptr_size
= saved_eh_addr_size
;
8599 unsigned int offset_size
;
8600 unsigned int initial_length_size
;
8602 static Frame_Chunk fde_fc
;
8604 saved_start
= start
;
8606 SAFE_BYTE_GET_AND_INC (length
, start
, 4, end
);
8610 printf ("\n%08lx ZERO terminator\n\n",
8611 (unsigned long)(saved_start
- section_start
));
8612 /* Skip any zero terminators that directly follow.
8613 A corrupt section size could have loaded a whole
8614 slew of zero filled memory bytes. eg
8615 PR 17512: file: 070-19381-0.004. */
8616 while (start
< end
&& * start
== 0)
8621 if (length
== 0xffffffff)
8623 SAFE_BYTE_GET_AND_INC (length
, start
, 8, end
);
8625 initial_length_size
= 12;
8630 initial_length_size
= 4;
8633 block_end
= saved_start
+ length
+ initial_length_size
;
8634 if (block_end
> end
|| block_end
< start
)
8636 warn ("Invalid length 0x%s in FDE at %#08lx\n",
8637 dwarf_vmatoa_1 (NULL
, length
, offset_size
),
8638 (unsigned long) (saved_start
- section_start
));
8642 SAFE_BYTE_GET_AND_INC (cie_id
, start
, offset_size
, end
);
8644 if (is_eh
? (cie_id
== 0) : ((offset_size
== 4 && cie_id
== DW_CIE_ID
)
8645 || (offset_size
== 8 && cie_id
== DW64_CIE_ID
)))
8650 start
= read_cie (start
, end
, &cie
, &version
,
8651 &augmentation_data_len
, &augmentation_data
);
8652 /* PR 17512: file: 027-135133-0.005. */
8659 fc
->chunk_start
= saved_start
;
8660 mreg
= max_regs
> 0 ? max_regs
- 1 : 0;
8663 if (frame_need_space (fc
, mreg
) < 0)
8665 if (fc
->fde_encoding
)
8666 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
8668 printf ("\n%08lx ", (unsigned long) (saved_start
- section_start
));
8669 print_dwarf_vma (length
, fc
->ptr_size
);
8670 print_dwarf_vma (cie_id
, offset_size
);
8672 if (do_debug_frames_interp
)
8674 printf ("CIE \"%s\" cf=%d df=%d ra=%d\n", fc
->augmentation
,
8675 fc
->code_factor
, fc
->data_factor
, fc
->ra
);
8680 printf (" Version: %d\n", version
);
8681 printf (" Augmentation: \"%s\"\n", fc
->augmentation
);
8684 printf (" Pointer Size: %u\n", fc
->ptr_size
);
8685 printf (" Segment Size: %u\n", fc
->segment_size
);
8687 printf (" Code alignment factor: %u\n", fc
->code_factor
);
8688 printf (" Data alignment factor: %d\n", fc
->data_factor
);
8689 printf (" Return address column: %d\n", fc
->ra
);
8691 if (augmentation_data_len
)
8692 display_augmentation_data (augmentation_data
, augmentation_data_len
);
8699 unsigned char *look_for
;
8700 unsigned long segment_selector
;
8706 dwarf_vma sign
= (dwarf_vma
) 1 << (offset_size
* 8 - 1);
8707 cie_off
= (cie_off
^ sign
) - sign
;
8708 cie_off
= start
- 4 - section_start
- cie_off
;
8711 look_for
= section_start
+ cie_off
;
8712 if (cie_off
<= (dwarf_vma
) (saved_start
- section_start
))
8714 for (cie
= chunks
; cie
; cie
= cie
->next
)
8715 if (cie
->chunk_start
== look_for
)
8718 else if (cie_off
>= section
->size
)
8722 for (cie
= forward_refs
; cie
; cie
= cie
->next
)
8723 if (cie
->chunk_start
== look_for
)
8727 unsigned int off_size
;
8728 unsigned char *cie_scan
;
8730 cie_scan
= look_for
;
8732 SAFE_BYTE_GET_AND_INC (length
, cie_scan
, 4, end
);
8733 if (length
== 0xffffffff)
8735 SAFE_BYTE_GET_AND_INC (length
, cie_scan
, 8, end
);
8742 SAFE_BYTE_GET_AND_INC (c_id
, cie_scan
, off_size
, end
);
8745 : ((off_size
== 4 && c_id
== DW_CIE_ID
)
8746 || (off_size
== 8 && c_id
== DW64_CIE_ID
)))
8751 read_cie (cie_scan
, end
, &cie
, &version
,
8752 &augmentation_data_len
, &augmentation_data
);
8753 /* PR 17512: file: 3450-2098-0.004. */
8756 warn (_("Failed to read CIE information\n"));
8759 cie
->next
= forward_refs
;
8761 cie
->chunk_start
= look_for
;
8762 mreg
= max_regs
> 0 ? max_regs
- 1 : 0;
8765 if (frame_need_space (cie
, mreg
) < 0)
8767 warn (_("Invalid max register\n"));
8770 if (cie
->fde_encoding
)
8772 = size_of_encoded_value (cie
->fde_encoding
);
8779 memset (fc
, 0, sizeof (Frame_Chunk
));
8783 warn ("Invalid CIE pointer 0x%s in FDE at %#08lx\n",
8784 dwarf_vmatoa_1 (NULL
, cie_id
, offset_size
),
8785 (unsigned long) (saved_start
- section_start
));
8787 fc
->col_type
= (short int *) xmalloc (sizeof (short int));
8788 fc
->col_offset
= (int *) xmalloc (sizeof (int));
8789 if (frame_need_space (fc
, max_regs
> 0 ? max_regs
- 1 : 0) < 0)
8791 warn (_("Invalid max register\n"));
8795 fc
->augmentation
= "";
8796 fc
->fde_encoding
= 0;
8797 fc
->ptr_size
= eh_addr_size
;
8798 fc
->segment_size
= 0;
8802 fc
->ncols
= cie
->ncols
;
8803 fc
->col_type
= (short int *) xcmalloc (fc
->ncols
, sizeof (short int));
8804 fc
->col_offset
= (int *) xcmalloc (fc
->ncols
, sizeof (int));
8805 memcpy (fc
->col_type
, cie
->col_type
, fc
->ncols
* sizeof (short int));
8806 memcpy (fc
->col_offset
, cie
->col_offset
, fc
->ncols
* sizeof (int));
8807 fc
->augmentation
= cie
->augmentation
;
8808 fc
->ptr_size
= cie
->ptr_size
;
8809 eh_addr_size
= cie
->ptr_size
;
8810 fc
->segment_size
= cie
->segment_size
;
8811 fc
->code_factor
= cie
->code_factor
;
8812 fc
->data_factor
= cie
->data_factor
;
8813 fc
->cfa_reg
= cie
->cfa_reg
;
8814 fc
->cfa_offset
= cie
->cfa_offset
;
8816 if (frame_need_space (fc
, max_regs
> 0 ? max_regs
- 1: 0) < 0)
8818 warn (_("Invalid max register\n"));
8821 fc
->fde_encoding
= cie
->fde_encoding
;
8824 if (fc
->fde_encoding
)
8825 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
8827 segment_selector
= 0;
8828 if (fc
->segment_size
)
8830 if (fc
->segment_size
> sizeof (segment_selector
))
8832 /* PR 17512: file: 9e196b3e. */
8833 warn (_("Probably corrupt segment size: %d - using 4 instead\n"), fc
->segment_size
);
8834 fc
->segment_size
= 4;
8836 SAFE_BYTE_GET_AND_INC (segment_selector
, start
, fc
->segment_size
, end
);
8839 fc
->pc_begin
= get_encoded_value (&start
, fc
->fde_encoding
, section
, end
);
8841 /* FIXME: It appears that sometimes the final pc_range value is
8842 encoded in less than encoded_ptr_size bytes. See the x86_64
8843 run of the "objcopy on compressed debug sections" test for an
8845 SAFE_BYTE_GET_AND_INC (fc
->pc_range
, start
, encoded_ptr_size
, end
);
8847 if (cie
->augmentation
[0] == 'z')
8849 READ_ULEB (augmentation_data_len
, start
, end
);
8850 augmentation_data
= start
;
8851 /* PR 17512 file: 722-8446-0.004 and PR 22386. */
8852 if (augmentation_data_len
> (bfd_size_type
) (end
- start
))
8854 warn (_("Augmentation data too long: 0x%s, "
8855 "expected at most %#lx\n"),
8856 dwarf_vmatoa ("x", augmentation_data_len
),
8857 (unsigned long) (end
- start
));
8859 augmentation_data
= NULL
;
8860 augmentation_data_len
= 0;
8862 start
+= augmentation_data_len
;
8865 printf ("\n%08lx %s %s FDE cie=%08lx pc=",
8866 (unsigned long)(saved_start
- section_start
),
8867 dwarf_vmatoa_1 (NULL
, length
, fc
->ptr_size
),
8868 dwarf_vmatoa_1 (NULL
, cie_id
, offset_size
),
8869 (unsigned long)(cie
->chunk_start
- section_start
));
8871 if (fc
->segment_size
)
8872 printf ("%04lx:", segment_selector
);
8875 dwarf_vmatoa_1 (NULL
, fc
->pc_begin
, fc
->ptr_size
),
8876 dwarf_vmatoa_1 (NULL
, fc
->pc_begin
+ fc
->pc_range
, fc
->ptr_size
));
8878 if (! do_debug_frames_interp
&& augmentation_data_len
)
8880 display_augmentation_data (augmentation_data
, augmentation_data_len
);
8885 /* At this point, fc is the current chunk, cie (if any) is set, and
8886 we're about to interpret instructions for the chunk. */
8887 /* ??? At present we need to do this always, since this sizes the
8888 fc->col_type and fc->col_offset arrays, which we write into always.
8889 We should probably split the interpreted and non-interpreted bits
8890 into two different routines, since there's so much that doesn't
8891 really overlap between them. */
8892 if (1 || do_debug_frames_interp
)
8894 /* Start by making a pass over the chunk, allocating storage
8895 and taking note of what registers are used. */
8896 unsigned char *tmp
= start
;
8898 while (start
< block_end
)
8900 unsigned int reg
, op
, opa
;
8902 unsigned char * new_start
;
8909 /* Warning: if you add any more cases to this switch, be
8910 sure to add them to the corresponding switch below. */
8913 case DW_CFA_advance_loc
:
8916 SKIP_ULEB (start
, end
);
8917 if (frame_need_space (fc
, opa
) >= 0)
8918 fc
->col_type
[opa
] = DW_CFA_undefined
;
8920 case DW_CFA_restore
:
8921 if (frame_need_space (fc
, opa
) >= 0)
8922 fc
->col_type
[opa
] = DW_CFA_undefined
;
8924 case DW_CFA_set_loc
:
8925 start
+= encoded_ptr_size
;
8927 case DW_CFA_advance_loc1
:
8930 case DW_CFA_advance_loc2
:
8933 case DW_CFA_advance_loc4
:
8936 case DW_CFA_offset_extended
:
8937 case DW_CFA_val_offset
:
8938 READ_ULEB (reg
, start
, end
);
8939 SKIP_ULEB (start
, end
);
8940 if (frame_need_space (fc
, reg
) >= 0)
8941 fc
->col_type
[reg
] = DW_CFA_undefined
;
8943 case DW_CFA_restore_extended
:
8944 READ_ULEB (reg
, start
, end
);
8945 if (frame_need_space (fc
, reg
) >= 0)
8946 fc
->col_type
[reg
] = DW_CFA_undefined
;
8948 case DW_CFA_undefined
:
8949 READ_ULEB (reg
, start
, end
);
8950 if (frame_need_space (fc
, reg
) >= 0)
8951 fc
->col_type
[reg
] = DW_CFA_undefined
;
8953 case DW_CFA_same_value
:
8954 READ_ULEB (reg
, start
, end
);
8955 if (frame_need_space (fc
, reg
) >= 0)
8956 fc
->col_type
[reg
] = DW_CFA_undefined
;
8958 case DW_CFA_register
:
8959 READ_ULEB (reg
, start
, end
);
8960 SKIP_ULEB (start
, end
);
8961 if (frame_need_space (fc
, reg
) >= 0)
8962 fc
->col_type
[reg
] = DW_CFA_undefined
;
8964 case DW_CFA_def_cfa
:
8965 SKIP_ULEB (start
, end
);
8966 SKIP_ULEB (start
, end
);
8968 case DW_CFA_def_cfa_register
:
8969 SKIP_ULEB (start
, end
);
8971 case DW_CFA_def_cfa_offset
:
8972 SKIP_ULEB (start
, end
);
8974 case DW_CFA_def_cfa_expression
:
8975 READ_ULEB (temp
, start
, end
);
8976 new_start
= start
+ temp
;
8977 if (new_start
< start
)
8979 warn (_("Corrupt CFA_def expression value: %lu\n"), temp
);
8985 case DW_CFA_expression
:
8986 case DW_CFA_val_expression
:
8987 READ_ULEB (reg
, start
, end
);
8988 READ_ULEB (temp
, start
, end
);
8989 new_start
= start
+ temp
;
8990 if (new_start
< start
)
8992 /* PR 17512: file:306-192417-0.005. */
8993 warn (_("Corrupt CFA expression value: %lu\n"), temp
);
8998 if (frame_need_space (fc
, reg
) >= 0)
8999 fc
->col_type
[reg
] = DW_CFA_undefined
;
9001 case DW_CFA_offset_extended_sf
:
9002 case DW_CFA_val_offset_sf
:
9003 READ_ULEB (reg
, start
, end
);
9004 SKIP_SLEB (start
, end
);
9005 if (frame_need_space (fc
, reg
) >= 0)
9006 fc
->col_type
[reg
] = DW_CFA_undefined
;
9008 case DW_CFA_def_cfa_sf
:
9009 SKIP_ULEB (start
, end
);
9010 SKIP_SLEB (start
, end
);
9012 case DW_CFA_def_cfa_offset_sf
:
9013 SKIP_SLEB (start
, end
);
9015 case DW_CFA_MIPS_advance_loc8
:
9018 case DW_CFA_GNU_args_size
:
9019 SKIP_ULEB (start
, end
);
9021 case DW_CFA_GNU_negative_offset_extended
:
9022 READ_ULEB (reg
, start
, end
);
9023 SKIP_ULEB (start
, end
);
9024 if (frame_need_space (fc
, reg
) >= 0)
9025 fc
->col_type
[reg
] = DW_CFA_undefined
;
9036 /* Now we know what registers are used, make a second pass over
9037 the chunk, this time actually printing out the info. */
9039 while (start
< block_end
)
9041 unsigned char * tmp
;
9043 unsigned long ul
, roffs
;
9044 /* Note: It is tempting to use an unsigned long for 'reg' but there
9045 are various functions, notably frame_space_needed() that assume that
9046 reg is an unsigned int. */
9051 const char *reg_prefix
= "";
9058 /* Make a note if something other than DW_CFA_nop happens. */
9059 if (op
!= DW_CFA_nop
)
9062 /* Warning: if you add any more cases to this switch, be
9063 sure to add them to the corresponding switch above. */
9066 case DW_CFA_advance_loc
:
9067 if (do_debug_frames_interp
)
9068 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9070 printf (" DW_CFA_advance_loc: %d to %s\n",
9071 opa
* fc
->code_factor
,
9072 dwarf_vmatoa_1 (NULL
,
9073 fc
->pc_begin
+ opa
* fc
->code_factor
,
9075 fc
->pc_begin
+= opa
* fc
->code_factor
;
9079 READ_ULEB (roffs
, start
, end
);
9080 if (opa
>= (unsigned int) fc
->ncols
)
9081 reg_prefix
= bad_reg
;
9082 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9083 printf (" DW_CFA_offset: %s%s at cfa%+ld\n",
9084 reg_prefix
, regname (opa
, 0),
9085 roffs
* fc
->data_factor
);
9086 if (*reg_prefix
== '\0')
9088 fc
->col_type
[opa
] = DW_CFA_offset
;
9089 fc
->col_offset
[opa
] = roffs
* fc
->data_factor
;
9093 case DW_CFA_restore
:
9094 if (opa
>= (unsigned int) fc
->ncols
)
9095 reg_prefix
= bad_reg
;
9096 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9097 printf (" DW_CFA_restore: %s%s\n",
9098 reg_prefix
, regname (opa
, 0));
9099 if (*reg_prefix
!= '\0')
9102 if (opa
>= (unsigned int) cie
->ncols
9103 || (do_debug_frames_interp
9104 && cie
->col_type
[opa
] == DW_CFA_unreferenced
))
9106 fc
->col_type
[opa
] = DW_CFA_undefined
;
9107 fc
->col_offset
[opa
] = 0;
9111 fc
->col_type
[opa
] = cie
->col_type
[opa
];
9112 fc
->col_offset
[opa
] = cie
->col_offset
[opa
];
9116 case DW_CFA_set_loc
:
9117 vma
= get_encoded_value (&start
, fc
->fde_encoding
, section
, block_end
);
9118 if (do_debug_frames_interp
)
9119 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9121 printf (" DW_CFA_set_loc: %s\n",
9122 dwarf_vmatoa_1 (NULL
, vma
, fc
->ptr_size
));
9126 case DW_CFA_advance_loc1
:
9127 SAFE_BYTE_GET_AND_INC (ofs
, start
, 1, end
);
9128 if (do_debug_frames_interp
)
9129 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9131 printf (" DW_CFA_advance_loc1: %ld to %s\n",
9132 (unsigned long) (ofs
* fc
->code_factor
),
9133 dwarf_vmatoa_1 (NULL
,
9134 fc
->pc_begin
+ ofs
* fc
->code_factor
,
9136 fc
->pc_begin
+= ofs
* fc
->code_factor
;
9139 case DW_CFA_advance_loc2
:
9140 SAFE_BYTE_GET_AND_INC (ofs
, start
, 2, block_end
);
9141 if (do_debug_frames_interp
)
9142 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9144 printf (" DW_CFA_advance_loc2: %ld to %s\n",
9145 (unsigned long) (ofs
* fc
->code_factor
),
9146 dwarf_vmatoa_1 (NULL
,
9147 fc
->pc_begin
+ ofs
* fc
->code_factor
,
9149 fc
->pc_begin
+= ofs
* fc
->code_factor
;
9152 case DW_CFA_advance_loc4
:
9153 SAFE_BYTE_GET_AND_INC (ofs
, start
, 4, block_end
);
9154 if (do_debug_frames_interp
)
9155 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9157 printf (" DW_CFA_advance_loc4: %ld to %s\n",
9158 (unsigned long) (ofs
* fc
->code_factor
),
9159 dwarf_vmatoa_1 (NULL
,
9160 fc
->pc_begin
+ ofs
* fc
->code_factor
,
9162 fc
->pc_begin
+= ofs
* fc
->code_factor
;
9165 case DW_CFA_offset_extended
:
9166 READ_ULEB (reg
, start
, end
);
9167 READ_ULEB (roffs
, start
, end
);
9168 if (reg
>= (unsigned int) fc
->ncols
)
9169 reg_prefix
= bad_reg
;
9170 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9171 printf (" DW_CFA_offset_extended: %s%s at cfa%+ld\n",
9172 reg_prefix
, regname (reg
, 0),
9173 roffs
* fc
->data_factor
);
9174 if (*reg_prefix
== '\0')
9176 fc
->col_type
[reg
] = DW_CFA_offset
;
9177 fc
->col_offset
[reg
] = roffs
* fc
->data_factor
;
9181 case DW_CFA_val_offset
:
9182 READ_ULEB (reg
, start
, end
);
9183 READ_ULEB (roffs
, start
, end
);
9184 if (reg
>= (unsigned int) fc
->ncols
)
9185 reg_prefix
= bad_reg
;
9186 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9187 printf (" DW_CFA_val_offset: %s%s is cfa%+ld\n",
9188 reg_prefix
, regname (reg
, 0),
9189 roffs
* fc
->data_factor
);
9190 if (*reg_prefix
== '\0')
9192 fc
->col_type
[reg
] = DW_CFA_val_offset
;
9193 fc
->col_offset
[reg
] = roffs
* fc
->data_factor
;
9197 case DW_CFA_restore_extended
:
9198 READ_ULEB (reg
, start
, end
);
9199 if (reg
>= (unsigned int) fc
->ncols
)
9200 reg_prefix
= bad_reg
;
9201 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9202 printf (" DW_CFA_restore_extended: %s%s\n",
9203 reg_prefix
, regname (reg
, 0));
9204 if (*reg_prefix
!= '\0')
9207 if (reg
>= (unsigned int) cie
->ncols
)
9209 fc
->col_type
[reg
] = DW_CFA_undefined
;
9210 fc
->col_offset
[reg
] = 0;
9214 fc
->col_type
[reg
] = cie
->col_type
[reg
];
9215 fc
->col_offset
[reg
] = cie
->col_offset
[reg
];
9219 case DW_CFA_undefined
:
9220 READ_ULEB (reg
, start
, end
);
9221 if (reg
>= (unsigned int) fc
->ncols
)
9222 reg_prefix
= bad_reg
;
9223 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9224 printf (" DW_CFA_undefined: %s%s\n",
9225 reg_prefix
, regname (reg
, 0));
9226 if (*reg_prefix
== '\0')
9228 fc
->col_type
[reg
] = DW_CFA_undefined
;
9229 fc
->col_offset
[reg
] = 0;
9233 case DW_CFA_same_value
:
9234 READ_ULEB (reg
, start
, end
);
9235 if (reg
>= (unsigned int) fc
->ncols
)
9236 reg_prefix
= bad_reg
;
9237 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9238 printf (" DW_CFA_same_value: %s%s\n",
9239 reg_prefix
, regname (reg
, 0));
9240 if (*reg_prefix
== '\0')
9242 fc
->col_type
[reg
] = DW_CFA_same_value
;
9243 fc
->col_offset
[reg
] = 0;
9247 case DW_CFA_register
:
9248 READ_ULEB (reg
, start
, end
);
9249 READ_ULEB (roffs
, start
, end
);
9250 if (reg
>= (unsigned int) fc
->ncols
)
9251 reg_prefix
= bad_reg
;
9252 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9254 printf (" DW_CFA_register: %s%s in ",
9255 reg_prefix
, regname (reg
, 0));
9256 puts (regname (roffs
, 0));
9258 if (*reg_prefix
== '\0')
9260 fc
->col_type
[reg
] = DW_CFA_register
;
9261 fc
->col_offset
[reg
] = roffs
;
9265 case DW_CFA_remember_state
:
9266 if (! do_debug_frames_interp
)
9267 printf (" DW_CFA_remember_state\n");
9268 rs
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
9269 rs
->cfa_offset
= fc
->cfa_offset
;
9270 rs
->cfa_reg
= fc
->cfa_reg
;
9272 rs
->cfa_exp
= fc
->cfa_exp
;
9273 rs
->ncols
= fc
->ncols
;
9274 rs
->col_type
= (short int *) xcmalloc (rs
->ncols
,
9275 sizeof (* rs
->col_type
));
9276 rs
->col_offset
= (int *) xcmalloc (rs
->ncols
, sizeof (* rs
->col_offset
));
9277 memcpy (rs
->col_type
, fc
->col_type
, rs
->ncols
* sizeof (* fc
->col_type
));
9278 memcpy (rs
->col_offset
, fc
->col_offset
, rs
->ncols
* sizeof (* fc
->col_offset
));
9279 rs
->next
= remembered_state
;
9280 remembered_state
= rs
;
9283 case DW_CFA_restore_state
:
9284 if (! do_debug_frames_interp
)
9285 printf (" DW_CFA_restore_state\n");
9286 rs
= remembered_state
;
9289 remembered_state
= rs
->next
;
9290 fc
->cfa_offset
= rs
->cfa_offset
;
9291 fc
->cfa_reg
= rs
->cfa_reg
;
9293 fc
->cfa_exp
= rs
->cfa_exp
;
9294 if (frame_need_space (fc
, rs
->ncols
- 1) < 0)
9296 warn (_("Invalid column number in saved frame state\n"));
9300 memcpy (fc
->col_type
, rs
->col_type
, rs
->ncols
* sizeof (* rs
->col_type
));
9301 memcpy (fc
->col_offset
, rs
->col_offset
,
9302 rs
->ncols
* sizeof (* rs
->col_offset
));
9303 free (rs
->col_type
);
9304 free (rs
->col_offset
);
9307 else if (do_debug_frames_interp
)
9308 printf ("Mismatched DW_CFA_restore_state\n");
9311 case DW_CFA_def_cfa
:
9312 READ_ULEB (fc
->cfa_reg
, start
, end
);
9313 READ_ULEB (fc
->cfa_offset
, start
, end
);
9315 if (! do_debug_frames_interp
)
9316 printf (" DW_CFA_def_cfa: %s ofs %d\n",
9317 regname (fc
->cfa_reg
, 0), (int) fc
->cfa_offset
);
9320 case DW_CFA_def_cfa_register
:
9321 READ_ULEB (fc
->cfa_reg
, start
, end
);
9323 if (! do_debug_frames_interp
)
9324 printf (" DW_CFA_def_cfa_register: %s\n",
9325 regname (fc
->cfa_reg
, 0));
9328 case DW_CFA_def_cfa_offset
:
9329 READ_ULEB (fc
->cfa_offset
, start
, end
);
9330 if (! do_debug_frames_interp
)
9331 printf (" DW_CFA_def_cfa_offset: %d\n", (int) fc
->cfa_offset
);
9335 if (! do_debug_frames_interp
)
9336 printf (" DW_CFA_nop\n");
9339 case DW_CFA_def_cfa_expression
:
9340 READ_ULEB (ul
, start
, end
);
9341 if (start
>= block_end
|| ul
> (unsigned long) (block_end
- start
))
9343 printf (_(" DW_CFA_def_cfa_expression: <corrupt len %lu>\n"), ul
);
9346 if (! do_debug_frames_interp
)
9348 printf (" DW_CFA_def_cfa_expression (");
9349 decode_location_expression (start
, eh_addr_size
, 0, -1,
9357 case DW_CFA_expression
:
9358 READ_ULEB (reg
, start
, end
);
9359 READ_ULEB (ul
, start
, end
);
9360 if (reg
>= (unsigned int) fc
->ncols
)
9361 reg_prefix
= bad_reg
;
9362 /* PR 17512: file: 069-133014-0.006. */
9363 /* PR 17512: file: 98c02eb4. */
9365 if (start
>= block_end
|| tmp
> block_end
|| tmp
< start
)
9367 printf (_(" DW_CFA_expression: <corrupt len %lu>\n"), ul
);
9370 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9372 printf (" DW_CFA_expression: %s%s (",
9373 reg_prefix
, regname (reg
, 0));
9374 decode_location_expression (start
, eh_addr_size
, 0, -1,
9378 if (*reg_prefix
== '\0')
9379 fc
->col_type
[reg
] = DW_CFA_expression
;
9383 case DW_CFA_val_expression
:
9384 READ_ULEB (reg
, start
, end
);
9385 READ_ULEB (ul
, start
, end
);
9386 if (reg
>= (unsigned int) fc
->ncols
)
9387 reg_prefix
= bad_reg
;
9389 if (start
>= block_end
|| tmp
> block_end
|| tmp
< start
)
9391 printf (" DW_CFA_val_expression: <corrupt len %lu>\n", ul
);
9394 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9396 printf (" DW_CFA_val_expression: %s%s (",
9397 reg_prefix
, regname (reg
, 0));
9398 decode_location_expression (start
, eh_addr_size
, 0, -1,
9402 if (*reg_prefix
== '\0')
9403 fc
->col_type
[reg
] = DW_CFA_val_expression
;
9407 case DW_CFA_offset_extended_sf
:
9408 READ_ULEB (reg
, start
, end
);
9409 READ_SLEB (l
, start
, end
);
9410 if (frame_need_space (fc
, reg
) < 0)
9411 reg_prefix
= bad_reg
;
9412 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9413 printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+ld\n",
9414 reg_prefix
, regname (reg
, 0),
9415 (long)(l
* fc
->data_factor
));
9416 if (*reg_prefix
== '\0')
9418 fc
->col_type
[reg
] = DW_CFA_offset
;
9419 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
9423 case DW_CFA_val_offset_sf
:
9424 READ_ULEB (reg
, start
, end
);
9425 READ_SLEB (l
, start
, end
);
9426 if (frame_need_space (fc
, reg
) < 0)
9427 reg_prefix
= bad_reg
;
9428 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9429 printf (" DW_CFA_val_offset_sf: %s%s is cfa%+ld\n",
9430 reg_prefix
, regname (reg
, 0),
9431 (long)(l
* fc
->data_factor
));
9432 if (*reg_prefix
== '\0')
9434 fc
->col_type
[reg
] = DW_CFA_val_offset
;
9435 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
9439 case DW_CFA_def_cfa_sf
:
9440 READ_ULEB (fc
->cfa_reg
, start
, end
);
9441 READ_ULEB (fc
->cfa_offset
, start
, end
);
9442 fc
->cfa_offset
= fc
->cfa_offset
* fc
->data_factor
;
9444 if (! do_debug_frames_interp
)
9445 printf (" DW_CFA_def_cfa_sf: %s ofs %d\n",
9446 regname (fc
->cfa_reg
, 0), (int) fc
->cfa_offset
);
9449 case DW_CFA_def_cfa_offset_sf
:
9450 READ_ULEB (fc
->cfa_offset
, start
, end
);
9451 fc
->cfa_offset
*= fc
->data_factor
;
9452 if (! do_debug_frames_interp
)
9453 printf (" DW_CFA_def_cfa_offset_sf: %d\n", (int) fc
->cfa_offset
);
9456 case DW_CFA_MIPS_advance_loc8
:
9457 SAFE_BYTE_GET_AND_INC (ofs
, start
, 8, block_end
);
9458 if (do_debug_frames_interp
)
9459 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9461 printf (" DW_CFA_MIPS_advance_loc8: %ld to %s\n",
9462 (unsigned long) (ofs
* fc
->code_factor
),
9463 dwarf_vmatoa_1 (NULL
,
9464 fc
->pc_begin
+ ofs
* fc
->code_factor
,
9466 fc
->pc_begin
+= ofs
* fc
->code_factor
;
9469 case DW_CFA_GNU_window_save
:
9470 if (! do_debug_frames_interp
)
9471 printf (" DW_CFA_GNU_window_save\n");
9474 case DW_CFA_GNU_args_size
:
9475 READ_ULEB (ul
, start
, end
);
9476 if (! do_debug_frames_interp
)
9477 printf (" DW_CFA_GNU_args_size: %ld\n", ul
);
9480 case DW_CFA_GNU_negative_offset_extended
:
9481 READ_ULEB (reg
, start
, end
);
9482 READ_SLEB (l
, start
, end
);
9484 if (frame_need_space (fc
, reg
) < 0)
9485 reg_prefix
= bad_reg
;
9486 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9487 printf (" DW_CFA_GNU_negative_offset_extended: %s%s at cfa%+ld\n",
9488 reg_prefix
, regname (reg
, 0),
9489 (long)(l
* fc
->data_factor
));
9490 if (*reg_prefix
== '\0')
9492 fc
->col_type
[reg
] = DW_CFA_offset
;
9493 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
9498 if (op
>= DW_CFA_lo_user
&& op
<= DW_CFA_hi_user
)
9499 printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op
);
9501 warn (_("Unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op
);
9506 /* Interpret the CFA - as long as it is not completely full of NOPs. */
9507 if (do_debug_frames_interp
&& ! all_nops
)
9508 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9510 if (fde_fc
.col_type
!= NULL
)
9512 free (fde_fc
.col_type
);
9513 fde_fc
.col_type
= NULL
;
9515 if (fde_fc
.col_offset
!= NULL
)
9517 free (fde_fc
.col_offset
);
9518 fde_fc
.col_offset
= NULL
;
9522 eh_addr_size
= saved_eh_addr_size
;
9527 while (remembered_state
!= NULL
)
9529 rs
= remembered_state
;
9530 remembered_state
= rs
->next
;
9531 free (rs
->col_type
);
9532 free (rs
->col_offset
);
9533 rs
->next
= NULL
; /* Paranoia. */
9537 while (chunks
!= NULL
)
9541 free (rs
->col_type
);
9542 free (rs
->col_offset
);
9543 rs
->next
= NULL
; /* Paranoia. */
9547 while (forward_refs
!= NULL
)
9550 forward_refs
= rs
->next
;
9551 free (rs
->col_type
);
9552 free (rs
->col_offset
);
9553 rs
->next
= NULL
; /* Paranoia. */
9563 display_debug_names (struct dwarf_section
*section
, void *file
)
9565 unsigned char *hdrptr
= section
->start
;
9566 dwarf_vma unit_length
;
9567 unsigned char *unit_start
;
9568 const unsigned char *const section_end
= section
->start
+ section
->size
;
9569 unsigned char *unit_end
;
9571 introduce (section
, false);
9573 load_debug_section_with_follow (str
, file
);
9575 for (; hdrptr
< section_end
; hdrptr
= unit_end
)
9577 unsigned int offset_size
;
9578 uint16_t dwarf_version
, padding
;
9579 uint32_t comp_unit_count
, local_type_unit_count
, foreign_type_unit_count
;
9580 uint32_t bucket_count
, name_count
, abbrev_table_size
;
9581 uint32_t augmentation_string_size
;
9583 unsigned long sec_off
;
9584 bool augmentation_printable
;
9585 const char *augmentation_string
;
9587 unit_start
= hdrptr
;
9589 /* Get and check the length of the block. */
9590 SAFE_BYTE_GET_AND_INC (unit_length
, hdrptr
, 4, section_end
);
9592 if (unit_length
== 0xffffffff)
9594 /* This section is 64-bit DWARF. */
9595 SAFE_BYTE_GET_AND_INC (unit_length
, hdrptr
, 8, section_end
);
9600 unit_end
= hdrptr
+ unit_length
;
9602 sec_off
= hdrptr
- section
->start
;
9603 if (sec_off
+ unit_length
< sec_off
9604 || sec_off
+ unit_length
> section
->size
)
9606 warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"),
9608 (unsigned long) (unit_start
- section
->start
),
9609 dwarf_vmatoa ("x", unit_length
));
9613 /* Get and check the version number. */
9614 SAFE_BYTE_GET_AND_INC (dwarf_version
, hdrptr
, 2, unit_end
);
9615 printf (_("Version %ld\n"), (long) dwarf_version
);
9617 /* Prior versions did not exist, and future versions may not be
9618 backwards compatible. */
9619 if (dwarf_version
!= 5)
9621 warn (_("Only DWARF version 5 .debug_names "
9622 "is currently supported.\n"));
9626 SAFE_BYTE_GET_AND_INC (padding
, hdrptr
, 2, unit_end
);
9628 warn (_("Padding field of .debug_names must be 0 (found 0x%x)\n"),
9631 SAFE_BYTE_GET_AND_INC (comp_unit_count
, hdrptr
, 4, unit_end
);
9632 if (comp_unit_count
== 0)
9633 warn (_("Compilation unit count must be >= 1 in .debug_names\n"));
9635 SAFE_BYTE_GET_AND_INC (local_type_unit_count
, hdrptr
, 4, unit_end
);
9636 SAFE_BYTE_GET_AND_INC (foreign_type_unit_count
, hdrptr
, 4, unit_end
);
9637 SAFE_BYTE_GET_AND_INC (bucket_count
, hdrptr
, 4, unit_end
);
9638 SAFE_BYTE_GET_AND_INC (name_count
, hdrptr
, 4, unit_end
);
9639 SAFE_BYTE_GET_AND_INC (abbrev_table_size
, hdrptr
, 4, unit_end
);
9641 SAFE_BYTE_GET_AND_INC (augmentation_string_size
, hdrptr
, 4, unit_end
);
9642 if (augmentation_string_size
% 4 != 0)
9644 warn (_("Augmentation string length %u must be rounded up "
9645 "to a multiple of 4 in .debug_names.\n"),
9646 augmentation_string_size
);
9647 augmentation_string_size
+= (-augmentation_string_size
) & 3;
9650 printf (_("Augmentation string:"));
9652 augmentation_printable
= true;
9653 augmentation_string
= (const char *) hdrptr
;
9655 for (i
= 0; i
< augmentation_string_size
; i
++)
9659 SAFE_BYTE_GET_AND_INC (uc
, hdrptr
, 1, unit_end
);
9660 printf (" %02x", uc
);
9662 if (uc
!= 0 && !ISPRINT (uc
))
9663 augmentation_printable
= false;
9666 if (augmentation_printable
)
9670 i
< augmentation_string_size
&& augmentation_string
[i
];
9672 putchar (augmentation_string
[i
]);
9677 printf (_("CU table:\n"));
9678 for (i
= 0; i
< comp_unit_count
; i
++)
9682 SAFE_BYTE_GET_AND_INC (cu_offset
, hdrptr
, offset_size
, unit_end
);
9683 printf (_("[%3u] 0x%lx\n"), i
, (unsigned long) cu_offset
);
9687 printf (_("TU table:\n"));
9688 for (i
= 0; i
< local_type_unit_count
; i
++)
9692 SAFE_BYTE_GET_AND_INC (tu_offset
, hdrptr
, offset_size
, unit_end
);
9693 printf (_("[%3u] 0x%lx\n"), i
, (unsigned long) tu_offset
);
9697 printf (_("Foreign TU table:\n"));
9698 for (i
= 0; i
< foreign_type_unit_count
; i
++)
9702 SAFE_BYTE_GET_AND_INC (signature
, hdrptr
, 8, unit_end
);
9703 printf (_("[%3u] "), i
);
9704 print_dwarf_vma (signature
, 8);
9709 const uint32_t *const hash_table_buckets
= (uint32_t *) hdrptr
;
9710 hdrptr
+= bucket_count
* sizeof (uint32_t);
9711 const uint32_t *const hash_table_hashes
= (uint32_t *) hdrptr
;
9712 hdrptr
+= name_count
* sizeof (uint32_t);
9713 unsigned char *const name_table_string_offsets
= hdrptr
;
9714 hdrptr
+= name_count
* offset_size
;
9715 unsigned char *const name_table_entry_offsets
= hdrptr
;
9716 hdrptr
+= name_count
* offset_size
;
9717 unsigned char *const abbrev_table
= hdrptr
;
9718 hdrptr
+= abbrev_table_size
;
9719 const unsigned char *const abbrev_table_end
= hdrptr
;
9720 unsigned char *const entry_pool
= hdrptr
;
9721 if (hdrptr
> unit_end
)
9723 warn (_("Entry pool offset (0x%lx) exceeds unit size 0x%lx "
9724 "for unit 0x%lx in the debug_names\n"),
9725 (long) (hdrptr
- section
->start
),
9726 (long) (unit_end
- section
->start
),
9727 (long) (unit_start
- section
->start
));
9731 size_t buckets_filled
= 0;
9733 for (bucketi
= 0; bucketi
< bucket_count
; bucketi
++)
9735 const uint32_t bucket
= hash_table_buckets
[bucketi
];
9740 printf (ngettext ("Used %zu of %lu bucket.\n",
9741 "Used %zu of %lu buckets.\n",
9743 buckets_filled
, (unsigned long) bucket_count
);
9745 uint32_t hash_prev
= 0;
9746 size_t hash_clash_count
= 0;
9747 size_t longest_clash
= 0;
9748 size_t this_length
= 0;
9750 for (hashi
= 0; hashi
< name_count
; hashi
++)
9752 const uint32_t hash_this
= hash_table_hashes
[hashi
];
9756 if (hash_prev
% bucket_count
== hash_this
% bucket_count
)
9760 longest_clash
= MAX (longest_clash
, this_length
);
9765 hash_prev
= hash_this
;
9767 printf (_("Out of %lu items there are %zu bucket clashes"
9768 " (longest of %zu entries).\n"),
9769 (unsigned long) name_count
, hash_clash_count
, longest_clash
);
9770 assert (name_count
== buckets_filled
+ hash_clash_count
);
9772 struct abbrev_lookup_entry
9774 dwarf_vma abbrev_tag
;
9775 unsigned char *abbrev_lookup_ptr
;
9777 struct abbrev_lookup_entry
*abbrev_lookup
= NULL
;
9778 size_t abbrev_lookup_used
= 0;
9779 size_t abbrev_lookup_allocated
= 0;
9781 unsigned char *abbrevptr
= abbrev_table
;
9784 dwarf_vma abbrev_tag
;
9786 READ_ULEB (abbrev_tag
, abbrevptr
, abbrev_table_end
);
9787 if (abbrev_tag
== 0)
9789 if (abbrev_lookup_used
== abbrev_lookup_allocated
)
9791 abbrev_lookup_allocated
= MAX (0x100,
9792 abbrev_lookup_allocated
* 2);
9793 abbrev_lookup
= xrealloc (abbrev_lookup
,
9794 (abbrev_lookup_allocated
9795 * sizeof (*abbrev_lookup
)));
9797 assert (abbrev_lookup_used
< abbrev_lookup_allocated
);
9798 struct abbrev_lookup_entry
*entry
;
9799 for (entry
= abbrev_lookup
;
9800 entry
< abbrev_lookup
+ abbrev_lookup_used
;
9802 if (entry
->abbrev_tag
== abbrev_tag
)
9804 warn (_("Duplicate abbreviation tag %lu "
9805 "in unit 0x%lx in the debug_names\n"),
9806 (long) abbrev_tag
, (long) (unit_start
- section
->start
));
9809 entry
= &abbrev_lookup
[abbrev_lookup_used
++];
9810 entry
->abbrev_tag
= abbrev_tag
;
9811 entry
->abbrev_lookup_ptr
= abbrevptr
;
9813 /* Skip DWARF tag. */
9814 SKIP_ULEB (abbrevptr
, abbrev_table_end
);
9817 dwarf_vma xindex
, form
;
9819 READ_ULEB (xindex
, abbrevptr
, abbrev_table_end
);
9820 READ_ULEB (form
, abbrevptr
, abbrev_table_end
);
9821 if (xindex
== 0 && form
== 0)
9826 printf (_("\nSymbol table:\n"));
9828 for (namei
= 0; namei
< name_count
; ++namei
)
9830 uint64_t string_offset
, entry_offset
;
9833 p
= name_table_string_offsets
+ namei
* offset_size
;
9834 SAFE_BYTE_GET (string_offset
, p
, offset_size
, unit_end
);
9835 p
= name_table_entry_offsets
+ namei
* offset_size
;
9836 SAFE_BYTE_GET (entry_offset
, p
, offset_size
, unit_end
);
9838 printf ("[%3u] #%08x %s:", namei
, hash_table_hashes
[namei
],
9839 fetch_indirect_string (string_offset
));
9841 unsigned char *entryptr
= entry_pool
+ entry_offset
;
9843 /* We need to scan first whether there is a single or multiple
9844 entries. TAGNO is -2 for the first entry, it is -1 for the
9845 initial tag read of the second entry, then it becomes 0 for the
9846 first entry for real printing etc. */
9848 /* Initialize it due to a false compiler warning. */
9849 dwarf_vma second_abbrev_tag
= -1;
9852 dwarf_vma abbrev_tag
;
9853 dwarf_vma dwarf_tag
;
9854 const struct abbrev_lookup_entry
*entry
;
9856 READ_ULEB (abbrev_tag
, entryptr
, unit_end
);
9859 second_abbrev_tag
= abbrev_tag
;
9861 entryptr
= entry_pool
+ entry_offset
;
9864 if (abbrev_tag
== 0)
9868 (tagno
== 0 && second_abbrev_tag
== 0 ? " " : "\n\t"),
9869 (unsigned long) abbrev_tag
);
9871 for (entry
= abbrev_lookup
;
9872 entry
< abbrev_lookup
+ abbrev_lookup_used
;
9874 if (entry
->abbrev_tag
== abbrev_tag
)
9876 if (entry
>= abbrev_lookup
+ abbrev_lookup_used
)
9878 warn (_("Undefined abbreviation tag %lu "
9879 "in unit 0x%lx in the debug_names\n"),
9881 (long) (unit_start
- section
->start
));
9884 abbrevptr
= entry
->abbrev_lookup_ptr
;
9885 READ_ULEB (dwarf_tag
, abbrevptr
, abbrev_table_end
);
9887 printf (" %s", get_TAG_name (dwarf_tag
));
9890 dwarf_vma xindex
, form
;
9892 READ_ULEB (xindex
, abbrevptr
, abbrev_table_end
);
9893 READ_ULEB (form
, abbrevptr
, abbrev_table_end
);
9894 if (xindex
== 0 && form
== 0)
9898 printf (" %s", get_IDX_name (xindex
));
9899 entryptr
= read_and_display_attr_value (0, form
, 0,
9900 unit_start
, entryptr
, unit_end
,
9902 dwarf_version
, NULL
,
9909 printf (_(" <no entries>"));
9913 free (abbrev_lookup
);
9920 display_debug_links (struct dwarf_section
* section
,
9921 void * file ATTRIBUTE_UNUSED
)
9923 const unsigned char * filename
;
9924 unsigned int filelen
;
9926 introduce (section
, false);
9928 /* The .gnu_debuglink section is formatted as:
9929 (c-string) Filename.
9930 (padding) If needed to reach a 4 byte boundary.
9931 (uint32_t) CRC32 value.
9933 The .gun_debugaltlink section is formatted as:
9934 (c-string) Filename.
9935 (binary) Build-ID. */
9937 filename
= section
->start
;
9938 filelen
= strnlen ((const char *) filename
, section
->size
);
9939 if (filelen
== section
->size
)
9941 warn (_("The debuglink filename is corrupt/missing\n"));
9945 printf (_(" Separate debug info file: %s\n"), filename
);
9947 if (startswith (section
->name
, ".gnu_debuglink"))
9950 unsigned int crc_offset
;
9952 crc_offset
= filelen
+ 1;
9953 crc_offset
= (crc_offset
+ 3) & ~3;
9954 if (crc_offset
+ 4 > section
->size
)
9956 warn (_("CRC offset missing/truncated\n"));
9960 crc32
= byte_get (filename
+ crc_offset
, 4);
9962 printf (_(" CRC value: %#x\n"), crc32
);
9964 if (crc_offset
+ 4 < section
->size
)
9966 warn (_("There are %#lx extraneous bytes at the end of the section\n"),
9967 (long)(section
->size
- (crc_offset
+ 4)));
9971 else /* startswith (section->name, ".gnu_debugaltlink") */
9973 const unsigned char * build_id
= section
->start
+ filelen
+ 1;
9974 bfd_size_type build_id_len
= section
->size
- (filelen
+ 1);
9975 bfd_size_type printed
;
9977 /* FIXME: Should we support smaller build-id notes ? */
9978 if (build_id_len
< 0x14)
9980 warn (_("Build-ID is too short (%#lx bytes)\n"), (long) build_id_len
);
9984 printed
= printf (_(" Build-ID (%#lx bytes):"), (long) build_id_len
);
9985 display_data (printed
, build_id
, build_id_len
);
9994 display_gdb_index (struct dwarf_section
*section
,
9995 void *file ATTRIBUTE_UNUSED
)
9997 unsigned char *start
= section
->start
;
9999 uint32_t cu_list_offset
, tu_list_offset
;
10000 uint32_t address_table_offset
, symbol_table_offset
, constant_pool_offset
;
10001 unsigned int cu_list_elements
, tu_list_elements
;
10002 unsigned int address_table_size
, symbol_table_slots
;
10003 unsigned char *cu_list
, *tu_list
;
10004 unsigned char *address_table
, *symbol_table
, *constant_pool
;
10007 /* The documentation for the format of this file is in gdb/dwarf2read.c. */
10009 introduce (section
, false);
10011 if (section
->size
< 6 * sizeof (uint32_t))
10013 warn (_("Truncated header in the %s section.\n"), section
->name
);
10017 version
= byte_get_little_endian (start
, 4);
10018 printf (_("Version %ld\n"), (long) version
);
10020 /* Prior versions are obsolete, and future versions may not be
10021 backwards compatible. */
10022 if (version
< 3 || version
> 8)
10024 warn (_("Unsupported version %lu.\n"), (unsigned long) version
);
10028 warn (_("The address table data in version 3 may be wrong.\n"));
10030 warn (_("Version 4 does not support case insensitive lookups.\n"));
10032 warn (_("Version 5 does not include inlined functions.\n"));
10034 warn (_("Version 6 does not include symbol attributes.\n"));
10035 /* Version 7 indices generated by Gold have bad type unit references,
10036 PR binutils/15021. But we don't know if the index was generated by
10037 Gold or not, so to avoid worrying users with gdb-generated indices
10038 we say nothing for version 7 here. */
10040 cu_list_offset
= byte_get_little_endian (start
+ 4, 4);
10041 tu_list_offset
= byte_get_little_endian (start
+ 8, 4);
10042 address_table_offset
= byte_get_little_endian (start
+ 12, 4);
10043 symbol_table_offset
= byte_get_little_endian (start
+ 16, 4);
10044 constant_pool_offset
= byte_get_little_endian (start
+ 20, 4);
10046 if (cu_list_offset
> section
->size
10047 || tu_list_offset
> section
->size
10048 || address_table_offset
> section
->size
10049 || symbol_table_offset
> section
->size
10050 || constant_pool_offset
> section
->size
)
10052 warn (_("Corrupt header in the %s section.\n"), section
->name
);
10056 /* PR 17531: file: 418d0a8a. */
10057 if (tu_list_offset
< cu_list_offset
)
10059 warn (_("TU offset (%x) is less than CU offset (%x)\n"),
10060 tu_list_offset
, cu_list_offset
);
10064 cu_list_elements
= (tu_list_offset
- cu_list_offset
) / 8;
10066 if (address_table_offset
< tu_list_offset
)
10068 warn (_("Address table offset (%x) is less than TU offset (%x)\n"),
10069 address_table_offset
, tu_list_offset
);
10073 tu_list_elements
= (address_table_offset
- tu_list_offset
) / 8;
10075 /* PR 17531: file: 18a47d3d. */
10076 if (symbol_table_offset
< address_table_offset
)
10078 warn (_("Symbol table offset (%x) is less then Address table offset (%x)\n"),
10079 symbol_table_offset
, address_table_offset
);
10083 address_table_size
= symbol_table_offset
- address_table_offset
;
10085 if (constant_pool_offset
< symbol_table_offset
)
10087 warn (_("Constant pool offset (%x) is less than symbol table offset (%x)\n"),
10088 constant_pool_offset
, symbol_table_offset
);
10092 symbol_table_slots
= (constant_pool_offset
- symbol_table_offset
) / 8;
10094 cu_list
= start
+ cu_list_offset
;
10095 tu_list
= start
+ tu_list_offset
;
10096 address_table
= start
+ address_table_offset
;
10097 symbol_table
= start
+ symbol_table_offset
;
10098 constant_pool
= start
+ constant_pool_offset
;
10100 if (address_table
+ address_table_size
> section
->start
+ section
->size
)
10102 warn (_("Address table extends beyond end of section.\n"));
10106 printf (_("\nCU table:\n"));
10107 for (i
= 0; i
< cu_list_elements
; i
+= 2)
10109 uint64_t cu_offset
= byte_get_little_endian (cu_list
+ i
* 8, 8);
10110 uint64_t cu_length
= byte_get_little_endian (cu_list
+ i
* 8 + 8, 8);
10112 printf (_("[%3u] 0x%lx - 0x%lx\n"), i
/ 2,
10113 (unsigned long) cu_offset
,
10114 (unsigned long) (cu_offset
+ cu_length
- 1));
10117 printf (_("\nTU table:\n"));
10118 for (i
= 0; i
< tu_list_elements
; i
+= 3)
10120 uint64_t tu_offset
= byte_get_little_endian (tu_list
+ i
* 8, 8);
10121 uint64_t type_offset
= byte_get_little_endian (tu_list
+ i
* 8 + 8, 8);
10122 uint64_t signature
= byte_get_little_endian (tu_list
+ i
* 8 + 16, 8);
10124 printf (_("[%3u] 0x%lx 0x%lx "), i
/ 3,
10125 (unsigned long) tu_offset
,
10126 (unsigned long) type_offset
);
10127 print_dwarf_vma (signature
, 8);
10131 printf (_("\nAddress table:\n"));
10132 for (i
= 0; i
< address_table_size
&& i
<= address_table_size
- (2 * 8 + 4);
10135 uint64_t low
= byte_get_little_endian (address_table
+ i
, 8);
10136 uint64_t high
= byte_get_little_endian (address_table
+ i
+ 8, 8);
10137 uint32_t cu_index
= byte_get_little_endian (address_table
+ i
+ 16, 4);
10139 print_dwarf_vma (low
, 8);
10140 print_dwarf_vma (high
, 8);
10141 printf (_("%lu\n"), (unsigned long) cu_index
);
10144 printf (_("\nSymbol table:\n"));
10145 for (i
= 0; i
< symbol_table_slots
; ++i
)
10147 uint32_t name_offset
= byte_get_little_endian (symbol_table
+ i
* 8, 4);
10148 uint32_t cu_vector_offset
= byte_get_little_endian (symbol_table
+ i
* 8 + 4, 4);
10149 uint32_t num_cus
, cu
;
10151 if (name_offset
!= 0
10152 || cu_vector_offset
!= 0)
10155 unsigned char * adr
;
10157 adr
= constant_pool
+ name_offset
;
10158 /* PR 17531: file: 5b7b07ad. */
10159 if (adr
< constant_pool
|| adr
>= section
->start
+ section
->size
)
10161 printf (_("[%3u] <corrupt offset: %x>"), i
, name_offset
);
10162 warn (_("Corrupt name offset of 0x%x found for symbol table slot %d\n"),
10166 printf ("[%3u] %.*s:", i
,
10167 (int) (section
->size
- (constant_pool_offset
+ name_offset
)),
10168 constant_pool
+ name_offset
);
10170 adr
= constant_pool
+ cu_vector_offset
;
10171 if (adr
< constant_pool
|| adr
>= section
->start
+ section
->size
- 3)
10173 printf (_("<invalid CU vector offset: %x>\n"), cu_vector_offset
);
10174 warn (_("Corrupt CU vector offset of 0x%x found for symbol table slot %d\n"),
10175 cu_vector_offset
, i
);
10179 num_cus
= byte_get_little_endian (adr
, 4);
10181 adr
= constant_pool
+ cu_vector_offset
+ 4 + num_cus
* 4;
10182 if (num_cus
* 4 < num_cus
10183 || adr
>= section
->start
+ section
->size
10184 || adr
< constant_pool
)
10186 printf ("<invalid number of CUs: %d>\n", num_cus
);
10187 warn (_("Invalid number of CUs (0x%x) for symbol table slot %d\n"),
10195 for (j
= 0; j
< num_cus
; ++j
)
10198 gdb_index_symbol_kind kind
;
10200 cu
= byte_get_little_endian (constant_pool
+ cu_vector_offset
+ 4 + j
* 4, 4);
10201 is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu
);
10202 kind
= GDB_INDEX_SYMBOL_KIND_VALUE (cu
);
10203 cu
= GDB_INDEX_CU_VALUE (cu
);
10204 /* Convert to TU number if it's for a type unit. */
10205 if (cu
>= cu_list_elements
/ 2)
10206 printf ("%cT%lu", num_cus
> 1 ? '\t' : ' ',
10207 (unsigned long) (cu
- cu_list_elements
/ 2));
10209 printf ("%c%lu", num_cus
> 1 ? '\t' : ' ', (unsigned long) cu
);
10211 printf (" [%s, %s]",
10212 is_static
? _("static") : _("global"),
10213 get_gdb_index_symbol_kind_name (kind
));
10225 /* Pre-allocate enough space for the CU/TU sets needed. */
10228 prealloc_cu_tu_list (unsigned int nshndx
)
10230 if (shndx_pool
== NULL
)
10232 shndx_pool_size
= nshndx
;
10233 shndx_pool_used
= 0;
10234 shndx_pool
= (unsigned int *) xcmalloc (shndx_pool_size
,
10235 sizeof (unsigned int));
10239 shndx_pool_size
= shndx_pool_used
+ nshndx
;
10240 shndx_pool
= (unsigned int *) xcrealloc (shndx_pool
, shndx_pool_size
,
10241 sizeof (unsigned int));
10246 add_shndx_to_cu_tu_entry (unsigned int shndx
)
10248 if (shndx_pool_used
>= shndx_pool_size
)
10250 error (_("Internal error: out of space in the shndx pool.\n"));
10253 shndx_pool
[shndx_pool_used
++] = shndx
;
10257 end_cu_tu_entry (void)
10259 if (shndx_pool_used
>= shndx_pool_size
)
10261 error (_("Internal error: out of space in the shndx pool.\n"));
10264 shndx_pool
[shndx_pool_used
++] = 0;
10267 /* Return the short name of a DWARF section given by a DW_SECT enumerator. */
10269 static const char *
10270 get_DW_SECT_short_name (unsigned int dw_sect
)
10272 static char buf
[16];
10278 case DW_SECT_TYPES
:
10280 case DW_SECT_ABBREV
:
10286 case DW_SECT_STR_OFFSETS
:
10288 case DW_SECT_MACINFO
:
10290 case DW_SECT_MACRO
:
10296 snprintf (buf
, sizeof (buf
), "%d", dw_sect
);
10300 /* Process a CU or TU index. If DO_DISPLAY is true, print the contents.
10301 These sections are extensions for Fission.
10302 See http://gcc.gnu.org/wiki/DebugFissionDWP. */
10305 process_cu_tu_index (struct dwarf_section
*section
, int do_display
)
10307 unsigned char *phdr
= section
->start
;
10308 unsigned char *limit
= phdr
+ section
->size
;
10309 unsigned char *phash
;
10310 unsigned char *pindex
;
10311 unsigned char *ppool
;
10312 unsigned int version
;
10313 unsigned int ncols
= 0;
10314 unsigned int nused
;
10315 unsigned int nslots
;
10318 dwarf_vma signature
;
10320 /* PR 17512: file: 002-168123-0.004. */
10323 warn (_("Section %s is empty\n"), section
->name
);
10326 /* PR 17512: file: 002-376-0.004. */
10327 if (section
->size
< 24)
10329 warn (_("Section %s is too small to contain a CU/TU header\n"),
10335 SAFE_BYTE_GET_AND_INC (version
, phash
, 4, limit
);
10337 SAFE_BYTE_GET_AND_INC (ncols
, phash
, 4, limit
);
10338 SAFE_BYTE_GET_AND_INC (nused
, phash
, 4, limit
);
10339 SAFE_BYTE_GET_AND_INC (nslots
, phash
, 4, limit
);
10341 pindex
= phash
+ (size_t) nslots
* 8;
10342 ppool
= pindex
+ (size_t) nslots
* 4;
10346 introduce (section
, false);
10348 printf (_(" Version: %u\n"), version
);
10350 printf (_(" Number of columns: %u\n"), ncols
);
10351 printf (_(" Number of used entries: %u\n"), nused
);
10352 printf (_(" Number of slots: %u\n\n"), nslots
);
10355 /* PR 17531: file: 45d69832. */
10356 if ((size_t) nslots
* 8 / 8 != nslots
10357 || phash
< phdr
|| phash
> limit
10358 || pindex
< phash
|| pindex
> limit
10359 || ppool
< pindex
|| ppool
> limit
)
10361 warn (ngettext ("Section %s is too small for %u slot\n",
10362 "Section %s is too small for %u slots\n",
10364 section
->name
, nslots
);
10371 prealloc_cu_tu_list ((limit
- ppool
) / 4);
10372 for (i
= 0; i
< nslots
; i
++)
10374 unsigned char *shndx_list
;
10375 unsigned int shndx
;
10377 SAFE_BYTE_GET (signature
, phash
, 8, limit
);
10378 if (signature
!= 0)
10380 SAFE_BYTE_GET (j
, pindex
, 4, limit
);
10381 shndx_list
= ppool
+ j
* 4;
10382 /* PR 17531: file: 705e010d. */
10383 if (shndx_list
< ppool
)
10385 warn (_("Section index pool located before start of section\n"));
10390 printf (_(" [%3d] Signature: 0x%s Sections: "),
10391 i
, dwarf_vmatoa ("x", signature
));
10394 if (shndx_list
>= limit
)
10396 warn (_("Section %s too small for shndx pool\n"),
10400 SAFE_BYTE_GET (shndx
, shndx_list
, 4, limit
);
10404 printf (" %d", shndx
);
10406 add_shndx_to_cu_tu_entry (shndx
);
10412 end_cu_tu_entry ();
10418 else if (version
== 2)
10421 unsigned int dw_sect
;
10422 unsigned char *ph
= phash
;
10423 unsigned char *pi
= pindex
;
10424 unsigned char *poffsets
= ppool
+ (size_t) ncols
* 4;
10425 unsigned char *psizes
= poffsets
+ (size_t) nused
* ncols
* 4;
10426 unsigned char *pend
= psizes
+ (size_t) nused
* ncols
* 4;
10428 struct cu_tu_set
*this_set
= NULL
;
10430 unsigned char *prow
;
10432 is_tu_index
= strcmp (section
->name
, ".debug_tu_index") == 0;
10434 /* PR 17531: file: 0dd159bf.
10435 Check for integer overflow (can occur when size_t is 32-bit)
10436 with overlarge ncols or nused values. */
10438 && ((size_t) ncols
* 4 / 4 != ncols
10439 || (size_t) nused
* ncols
* 4 / ((size_t) ncols
* 4) != nused
10440 || poffsets
< ppool
|| poffsets
> limit
10441 || psizes
< poffsets
|| psizes
> limit
10442 || pend
< psizes
|| pend
> limit
))
10444 warn (_("Section %s too small for offset and size tables\n"),
10451 printf (_(" Offset table\n"));
10452 printf (" slot %-16s ",
10453 is_tu_index
? _("signature") : _("dwo_id"));
10460 tu_sets
= xcalloc2 (nused
, sizeof (struct cu_tu_set
));
10461 this_set
= tu_sets
;
10466 cu_sets
= xcalloc2 (nused
, sizeof (struct cu_tu_set
));
10467 this_set
= cu_sets
;
10473 for (j
= 0; j
< ncols
; j
++)
10475 unsigned char *p
= ppool
+ j
* 4;
10476 SAFE_BYTE_GET (dw_sect
, p
, 4, limit
);
10477 printf (" %8s", get_DW_SECT_short_name (dw_sect
));
10482 for (i
= 0; i
< nslots
; i
++)
10484 SAFE_BYTE_GET (signature
, ph
, 8, limit
);
10486 SAFE_BYTE_GET (row
, pi
, 4, limit
);
10489 /* PR 17531: file: a05f6ab3. */
10492 warn (_("Row index (%u) is larger than number of used entries (%u)\n"),
10499 size_t num_copy
= sizeof (uint64_t);
10501 /* PR 23064: Beware of buffer overflow. */
10502 if (ph
+ num_copy
< limit
)
10503 memcpy (&this_set
[row
- 1].signature
, ph
, num_copy
);
10506 warn (_("Signature (%p) extends beyond end of space in section\n"), ph
);
10511 prow
= poffsets
+ (row
- 1) * ncols
* 4;
10512 /* PR 17531: file: b8ce60a8. */
10513 if (prow
< poffsets
|| prow
> limit
)
10515 warn (_("Row index (%u) * num columns (%u) > space remaining in section\n"),
10521 printf (_(" [%3d] 0x%s"),
10522 i
, dwarf_vmatoa ("x", signature
));
10523 for (j
= 0; j
< ncols
; j
++)
10525 unsigned char *p
= prow
+ j
* 4;
10526 SAFE_BYTE_GET (val
, p
, 4, limit
);
10528 printf (" %8d", val
);
10532 SAFE_BYTE_GET (dw_sect
, p
, 4, limit
);
10534 /* PR 17531: file: 10796eb3. */
10535 if (dw_sect
>= DW_SECT_MAX
)
10536 warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect
);
10538 this_set
[row
- 1].section_offsets
[dw_sect
] = val
;
10554 printf (_(" Size table\n"));
10555 printf (" slot %-16s ",
10556 is_tu_index
? _("signature") : _("dwo_id"));
10559 for (j
= 0; j
< ncols
; j
++)
10561 unsigned char *p
= ppool
+ j
* 4;
10562 SAFE_BYTE_GET (val
, p
, 4, limit
);
10564 printf (" %8s", get_DW_SECT_short_name (val
));
10570 for (i
= 0; i
< nslots
; i
++)
10572 SAFE_BYTE_GET (signature
, ph
, 8, limit
);
10574 SAFE_BYTE_GET (row
, pi
, 4, limit
);
10577 prow
= psizes
+ (row
- 1) * ncols
* 4;
10580 printf (_(" [%3d] 0x%s"),
10581 i
, dwarf_vmatoa ("x", signature
));
10583 for (j
= 0; j
< ncols
; j
++)
10585 unsigned char *p
= prow
+ j
* 4;
10586 SAFE_BYTE_GET (val
, p
, 4, limit
);
10588 printf (" %8d", val
);
10592 SAFE_BYTE_GET (dw_sect
, p
, 4, limit
);
10593 if (dw_sect
>= DW_SECT_MAX
)
10594 warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect
);
10596 this_set
[row
- 1].section_sizes
[dw_sect
] = val
;
10608 else if (do_display
)
10609 printf (_(" Unsupported version (%d)\n"), version
);
10617 static int cu_tu_indexes_read
= -1; /* Tri-state variable. */
10619 /* Load the CU and TU indexes if present. This will build a list of
10620 section sets that we can use to associate a .debug_info.dwo section
10621 with its associated .debug_abbrev.dwo section in a .dwp file. */
10624 load_cu_tu_indexes (void *file
)
10626 /* If we have already loaded (or tried to load) the CU and TU indexes
10627 then do not bother to repeat the task. */
10628 if (cu_tu_indexes_read
== -1)
10630 cu_tu_indexes_read
= true;
10632 if (load_debug_section_with_follow (dwp_cu_index
, file
))
10633 if (! process_cu_tu_index (&debug_displays
[dwp_cu_index
].section
, 0))
10634 cu_tu_indexes_read
= false;
10636 if (load_debug_section_with_follow (dwp_tu_index
, file
))
10637 if (! process_cu_tu_index (&debug_displays
[dwp_tu_index
].section
, 0))
10638 cu_tu_indexes_read
= false;
10641 return (bool) cu_tu_indexes_read
;
10644 /* Find the set of sections that includes section SHNDX. */
10647 find_cu_tu_set (void *file
, unsigned int shndx
)
10651 if (! load_cu_tu_indexes (file
))
10654 /* Find SHNDX in the shndx pool. */
10655 for (i
= 0; i
< shndx_pool_used
; i
++)
10656 if (shndx_pool
[i
] == shndx
)
10659 if (i
>= shndx_pool_used
)
10662 /* Now backup to find the first entry in the set. */
10663 while (i
> 0 && shndx_pool
[i
- 1] != 0)
10666 return shndx_pool
+ i
;
10669 /* Display a .debug_cu_index or .debug_tu_index section. */
10672 display_cu_index (struct dwarf_section
*section
, void *file ATTRIBUTE_UNUSED
)
10674 return process_cu_tu_index (section
, 1);
10678 display_debug_not_supported (struct dwarf_section
*section
,
10679 void *file ATTRIBUTE_UNUSED
)
10681 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
10687 /* Like malloc, but takes two parameters like calloc.
10688 Verifies that the first parameter is not too large.
10689 Note: does *not* initialise the allocated memory to zero. */
10692 cmalloc (size_t nmemb
, size_t size
)
10694 /* Check for overflow. */
10695 if (nmemb
>= ~(size_t) 0 / size
)
10698 return xmalloc (nmemb
* size
);
10701 /* Like xmalloc, but takes two parameters like calloc.
10702 Verifies that the first parameter is not too large.
10703 Note: does *not* initialise the allocated memory to zero. */
10706 xcmalloc (size_t nmemb
, size_t size
)
10708 /* Check for overflow. */
10709 if (nmemb
>= ~(size_t) 0 / size
)
10712 _("Attempt to allocate an array with an excessive number of elements: 0x%lx\n"),
10717 return xmalloc (nmemb
* size
);
10720 /* Like xrealloc, but takes three parameters.
10721 Verifies that the second parameter is not too large.
10722 Note: does *not* initialise any new memory to zero. */
10725 xcrealloc (void *ptr
, size_t nmemb
, size_t size
)
10727 /* Check for overflow. */
10728 if (nmemb
>= ~(size_t) 0 / size
)
10730 error (_("Attempt to re-allocate an array with an excessive number of elements: 0x%lx\n"),
10735 return xrealloc (ptr
, nmemb
* size
);
10738 /* Like xcalloc, but verifies that the first parameter is not too large. */
10741 xcalloc2 (size_t nmemb
, size_t size
)
10743 /* Check for overflow. */
10744 if (nmemb
>= ~(size_t) 0 / size
)
10746 error (_("Attempt to allocate a zero'ed array with an excessive number of elements: 0x%lx\n"),
10751 return xcalloc (nmemb
, size
);
10754 static unsigned long
10755 calc_gnu_debuglink_crc32 (unsigned long crc
,
10756 const unsigned char * buf
,
10759 static const unsigned long crc32_table
[256] =
10761 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
10762 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
10763 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
10764 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
10765 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
10766 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
10767 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
10768 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
10769 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
10770 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
10771 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
10772 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
10773 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
10774 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
10775 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
10776 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
10777 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
10778 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
10779 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
10780 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
10781 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
10782 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
10783 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
10784 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
10785 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
10786 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
10787 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
10788 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
10789 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
10790 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
10791 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
10792 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
10793 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
10794 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
10795 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
10796 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
10797 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
10798 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
10799 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
10800 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
10801 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
10802 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
10803 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
10804 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
10805 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
10806 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
10807 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
10808 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
10809 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
10810 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
10811 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
10814 const unsigned char *end
;
10816 crc
= ~crc
& 0xffffffff;
10817 for (end
= buf
+ len
; buf
< end
; ++ buf
)
10818 crc
= crc32_table
[(crc
^ *buf
) & 0xff] ^ (crc
>> 8);
10819 return ~crc
& 0xffffffff;
10822 typedef bool (*check_func_type
) (const char *, void *);
10823 typedef const char *(* parse_func_type
) (struct dwarf_section
*, void *);
10826 check_gnu_debuglink (const char * pathname
, void * crc_pointer
)
10828 static unsigned char buffer
[8 * 1024];
10830 bfd_size_type count
;
10831 unsigned long crc
= 0;
10834 sep_data
= open_debug_file (pathname
);
10835 if (sep_data
== NULL
)
10838 /* Yes - we are opening the file twice... */
10839 f
= fopen (pathname
, "rb");
10842 /* Paranoia: This should never happen. */
10843 close_debug_file (sep_data
);
10844 warn (_("Unable to reopen separate debug info file: %s\n"), pathname
);
10848 while ((count
= fread (buffer
, 1, sizeof (buffer
), f
)) > 0)
10849 crc
= calc_gnu_debuglink_crc32 (crc
, buffer
, count
);
10853 if (crc
!= * (unsigned long *) crc_pointer
)
10855 close_debug_file (sep_data
);
10856 warn (_("Separate debug info file %s found, but CRC does not match - ignoring\n"),
10864 static const char *
10865 parse_gnu_debuglink (struct dwarf_section
* section
, void * data
)
10868 unsigned int crc_offset
;
10869 unsigned long * crc32
= (unsigned long *) data
;
10871 /* The name is first.
10872 The CRC value is stored after the filename, aligned up to 4 bytes. */
10873 name
= (const char *) section
->start
;
10875 crc_offset
= strnlen (name
, section
->size
) + 1;
10876 if (crc_offset
== 1)
10878 crc_offset
= (crc_offset
+ 3) & ~3;
10879 if (crc_offset
+ 4 > section
->size
)
10882 * crc32
= byte_get (section
->start
+ crc_offset
, 4);
10887 check_gnu_debugaltlink (const char * filename
, void * data ATTRIBUTE_UNUSED
)
10889 void * sep_data
= open_debug_file (filename
);
10891 if (sep_data
== NULL
)
10894 /* FIXME: We should now extract the build-id in the separate file
10900 typedef struct build_id_data
10903 const unsigned char * data
;
10906 static const char *
10907 parse_gnu_debugaltlink (struct dwarf_section
* section
, void * data
)
10910 bfd_size_type namelen
;
10911 bfd_size_type id_len
;
10912 Build_id_data
* build_id_data
;
10914 /* The name is first.
10915 The build-id follows immediately, with no padding, up to the section's end. */
10917 name
= (const char *) section
->start
;
10918 namelen
= strnlen (name
, section
->size
) + 1;
10921 if (namelen
>= section
->size
)
10924 id_len
= section
->size
- namelen
;
10928 build_id_data
= (Build_id_data
*) data
;
10929 build_id_data
->len
= id_len
;
10930 build_id_data
->data
= section
->start
+ namelen
;
10936 add_separate_debug_file (const char * filename
, void * handle
)
10938 separate_info
* i
= xmalloc (sizeof * i
);
10940 i
->filename
= filename
;
10941 i
->handle
= handle
;
10942 i
->next
= first_separate_info
;
10943 first_separate_info
= i
;
10946 #if HAVE_LIBDEBUGINFOD
10947 /* Query debuginfod servers for the target debuglink or debugaltlink
10948 file. If successful, store the path of the file in filename and
10949 return TRUE, otherwise return FALSE. */
10952 debuginfod_fetch_separate_debug_info (struct dwarf_section
* section
,
10956 size_t build_id_len
;
10957 unsigned char * build_id
;
10959 if (strcmp (section
->uncompressed_name
, ".gnu_debuglink") == 0)
10961 /* Get the build-id of file. */
10962 build_id
= get_build_id (file
);
10965 else if (strcmp (section
->uncompressed_name
, ".gnu_debugaltlink") == 0)
10967 /* Get the build-id of the debugaltlink file. */
10968 unsigned int filelen
;
10970 filelen
= strnlen ((const char *)section
->start
, section
->size
);
10971 if (filelen
== section
->size
)
10972 /* Corrupt debugaltlink. */
10975 build_id
= section
->start
+ filelen
+ 1;
10976 build_id_len
= section
->size
- (filelen
+ 1);
10978 if (build_id_len
== 0)
10987 debuginfod_client
* client
;
10989 client
= debuginfod_begin ();
10990 if (client
== NULL
)
10993 /* Query debuginfod servers for the target file. If found its path
10994 will be stored in filename. */
10995 fd
= debuginfod_find_debuginfo (client
, build_id
, build_id_len
, filename
);
10996 debuginfod_end (client
);
10998 /* Only free build_id if we allocated space for a hex string
10999 in get_build_id (). */
11000 if (build_id_len
== 0)
11005 /* File successfully retrieved. Close fd since we want to
11006 use open_debug_file () on filename instead. */
11017 load_separate_debug_info (const char * main_filename
,
11018 struct dwarf_section
* xlink
,
11019 parse_func_type parse_func
,
11020 check_func_type check_func
,
11022 void * file ATTRIBUTE_UNUSED
)
11024 const char * separate_filename
;
11025 char * debug_filename
;
11027 size_t canon_dirlen
;
11030 if ((separate_filename
= parse_func (xlink
, func_data
)) == NULL
)
11032 warn (_("Corrupt debuglink section: %s\n"),
11033 xlink
->name
? xlink
->name
: xlink
->uncompressed_name
);
11037 /* Attempt to locate the separate file.
11038 This should duplicate the logic in bfd/opncls.c:find_separate_debug_file(). */
11040 canon_dir
= lrealpath (main_filename
);
11042 for (canon_dirlen
= strlen (canon_dir
); canon_dirlen
> 0; canon_dirlen
--)
11043 if (IS_DIR_SEPARATOR (canon_dir
[canon_dirlen
- 1]))
11045 canon_dir
[canon_dirlen
] = '\0';
11048 #define DEBUGDIR "/lib/debug"
11050 #ifndef EXTRA_DEBUG_ROOT1
11051 #define EXTRA_DEBUG_ROOT1 "/usr/lib/debug"
11053 #ifndef EXTRA_DEBUG_ROOT2
11054 #define EXTRA_DEBUG_ROOT2 "/usr/lib/debug/usr"
11057 debug_filename
= (char *) malloc (strlen (DEBUGDIR
) + 1
11059 + strlen (".debug/")
11060 #ifdef EXTRA_DEBUG_ROOT1
11061 + strlen (EXTRA_DEBUG_ROOT1
)
11063 #ifdef EXTRA_DEBUG_ROOT2
11064 + strlen (EXTRA_DEBUG_ROOT2
)
11066 + strlen (separate_filename
)
11068 if (debug_filename
== NULL
)
11070 warn (_("Out of memory"));
11075 /* First try in the current directory. */
11076 sprintf (debug_filename
, "%s", separate_filename
);
11077 if (check_func (debug_filename
, func_data
))
11080 /* Then try in a subdirectory called .debug. */
11081 sprintf (debug_filename
, ".debug/%s", separate_filename
);
11082 if (check_func (debug_filename
, func_data
))
11085 /* Then try in the same directory as the original file. */
11086 sprintf (debug_filename
, "%s%s", canon_dir
, separate_filename
);
11087 if (check_func (debug_filename
, func_data
))
11090 /* And the .debug subdirectory of that directory. */
11091 sprintf (debug_filename
, "%s.debug/%s", canon_dir
, separate_filename
);
11092 if (check_func (debug_filename
, func_data
))
11095 #ifdef EXTRA_DEBUG_ROOT1
11096 /* Try the first extra debug file root. */
11097 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT1
, separate_filename
);
11098 if (check_func (debug_filename
, func_data
))
11101 /* Try the first extra debug file root. */
11102 sprintf (debug_filename
, "%s/%s/%s", EXTRA_DEBUG_ROOT1
, canon_dir
, separate_filename
);
11103 if (check_func (debug_filename
, func_data
))
11107 #ifdef EXTRA_DEBUG_ROOT2
11108 /* Try the second extra debug file root. */
11109 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT2
, separate_filename
);
11110 if (check_func (debug_filename
, func_data
))
11114 /* Then try in the global debug_filename directory. */
11115 strcpy (debug_filename
, DEBUGDIR
);
11116 dirlen
= strlen (DEBUGDIR
) - 1;
11117 if (dirlen
> 0 && DEBUGDIR
[dirlen
] != '/')
11118 strcat (debug_filename
, "/");
11119 strcat (debug_filename
, (const char *) separate_filename
);
11121 if (check_func (debug_filename
, func_data
))
11124 #if HAVE_LIBDEBUGINFOD
11126 char * tmp_filename
;
11128 if (debuginfod_fetch_separate_debug_info (xlink
,
11132 /* File successfully downloaded from server, replace
11133 debug_filename with the file's path. */
11134 free (debug_filename
);
11135 debug_filename
= tmp_filename
;
11141 if (do_debug_links
)
11143 /* Failed to find the file. */
11144 warn (_("could not find separate debug file '%s'\n"),
11145 separate_filename
);
11146 warn (_("tried: %s\n"), debug_filename
);
11148 #ifdef EXTRA_DEBUG_ROOT2
11149 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT2
,
11150 separate_filename
);
11151 warn (_("tried: %s\n"), debug_filename
);
11154 #ifdef EXTRA_DEBUG_ROOT1
11155 sprintf (debug_filename
, "%s/%s/%s", EXTRA_DEBUG_ROOT1
,
11156 canon_dir
, separate_filename
);
11157 warn (_("tried: %s\n"), debug_filename
);
11159 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT1
,
11160 separate_filename
);
11161 warn (_("tried: %s\n"), debug_filename
);
11164 sprintf (debug_filename
, "%s.debug/%s", canon_dir
,
11165 separate_filename
);
11166 warn (_("tried: %s\n"), debug_filename
);
11168 sprintf (debug_filename
, "%s%s", canon_dir
, separate_filename
);
11169 warn (_("tried: %s\n"), debug_filename
);
11171 sprintf (debug_filename
, ".debug/%s", separate_filename
);
11172 warn (_("tried: %s\n"), debug_filename
);
11174 sprintf (debug_filename
, "%s", separate_filename
);
11175 warn (_("tried: %s\n"), debug_filename
);
11177 #if HAVE_LIBDEBUGINFOD
11179 char *urls
= getenv (DEBUGINFOD_URLS_ENV_VAR
);
11183 warn (_("tried: DEBUGINFOD_URLS=%s\n"), urls
);
11189 free (debug_filename
);
11195 void * debug_handle
;
11197 /* Now open the file.... */
11198 if ((debug_handle
= open_debug_file (debug_filename
)) == NULL
)
11200 warn (_("failed to open separate debug file: %s\n"), debug_filename
);
11201 free (debug_filename
);
11205 /* FIXME: We do not check to see if there are any other separate debug info
11206 files that would also match. */
11208 if (do_debug_links
)
11209 printf (_("\n%s: Found separate debug info file: %s\n"), main_filename
, debug_filename
);
11210 add_separate_debug_file (debug_filename
, debug_handle
);
11212 /* Do not free debug_filename - it might be referenced inside
11213 the structure returned by open_debug_file(). */
11214 return debug_handle
;
11217 /* Attempt to load a separate dwarf object file. */
11220 load_dwo_file (const char * main_filename
, const char * name
, const char * dir
, const char * id ATTRIBUTE_UNUSED
)
11222 char * separate_filename
;
11223 void * separate_handle
;
11225 if (IS_ABSOLUTE_PATH (name
))
11226 separate_filename
= strdup (name
);
11228 /* FIXME: Skip adding / if dwo_dir ends in /. */
11229 separate_filename
= concat (dir
, "/", name
, NULL
);
11230 if (separate_filename
== NULL
)
11232 warn (_("Out of memory allocating dwo filename\n"));
11236 if ((separate_handle
= open_debug_file (separate_filename
)) == NULL
)
11238 warn (_("Unable to load dwo file: %s\n"), separate_filename
);
11239 free (separate_filename
);
11243 /* FIXME: We should check the dwo_id. */
11245 printf (_("%s: Found separate debug object file: %s\n\n"), main_filename
, separate_filename
);
11247 add_separate_debug_file (separate_filename
, separate_handle
);
11248 /* Note - separate_filename will be freed in free_debug_memory(). */
11249 return separate_handle
;
11253 load_debug_sup_file (const char * main_filename
, void * file
)
11255 if (! load_debug_section (debug_sup
, file
))
11256 return; /* No .debug_sup section. */
11258 struct dwarf_section
* section
;
11259 section
= & debug_displays
[debug_sup
].section
;
11260 assert (section
!= NULL
);
11262 if (section
->start
== NULL
|| section
->size
< 5)
11264 warn (_(".debug_sup section is corrupt/empty\n"));
11268 if (section
->start
[2] != 0)
11269 return; /* This is a supplementary file. */
11271 const char * filename
= (const char *) section
->start
+ 3;
11272 if (strnlen (filename
, section
->size
- 3) == section
->size
- 3)
11274 warn (_("filename in .debug_sup section is corrupt\n"));
11278 if (filename
[0] != '/' && strchr (main_filename
, '/'))
11283 new_len
= asprintf (& new_name
, "%.*s/%s",
11284 (int) (strrchr (main_filename
, '/') - main_filename
),
11289 warn (_("unable to construct path for supplementary debug file"));
11294 filename
= new_name
;
11298 /* PR 27796: Make sure that we pass a filename that can be free'd to
11299 add_separate_debug_file(). */
11300 filename
= strdup (filename
);
11301 if (filename
== NULL
)
11303 warn (_("out of memory constructing filename for .debug_sup link\n"));
11308 void * handle
= open_debug_file (filename
);
11309 if (handle
== NULL
)
11311 warn (_("unable to open file '%s' referenced from .debug_sup section\n"), filename
);
11312 free ((void *) filename
);
11316 printf (_("%s: Found supplementary debug file: %s\n\n"), main_filename
, filename
);
11318 /* FIXME: Compare the checksums, if present. */
11319 add_separate_debug_file (filename
, handle
);
11322 /* Load a debuglink section and/or a debugaltlink section, if either are present.
11323 Recursively check the loaded files for more of these sections.
11324 Also follow any links in .debug_sup sections.
11325 FIXME: Should also check for DWO_* entries in the newly loaded files. */
11328 check_for_and_load_links (void * file
, const char * filename
)
11330 void * handle
= NULL
;
11332 if (load_debug_section (gnu_debugaltlink
, file
))
11334 Build_id_data build_id_data
;
11336 handle
= load_separate_debug_info (filename
,
11337 & debug_displays
[gnu_debugaltlink
].section
,
11338 parse_gnu_debugaltlink
,
11339 check_gnu_debugaltlink
,
11344 assert (handle
== first_separate_info
->handle
);
11345 check_for_and_load_links (first_separate_info
->handle
,
11346 first_separate_info
->filename
);
11350 if (load_debug_section (gnu_debuglink
, file
))
11352 unsigned long crc32
;
11354 handle
= load_separate_debug_info (filename
,
11355 & debug_displays
[gnu_debuglink
].section
,
11356 parse_gnu_debuglink
,
11357 check_gnu_debuglink
,
11362 assert (handle
== first_separate_info
->handle
);
11363 check_for_and_load_links (first_separate_info
->handle
,
11364 first_separate_info
->filename
);
11368 load_debug_sup_file (filename
, file
);
11371 /* Load the separate debug info file(s) attached to FILE, if any exist.
11372 Returns TRUE if any were found, FALSE otherwise.
11373 If TRUE is returned then the linked list starting at first_separate_info
11374 will be populated with open file handles. */
11377 load_separate_debug_files (void * file
, const char * filename
)
11379 /* Skip this operation if we are not interested in debug links. */
11380 if (! do_follow_links
&& ! do_debug_links
)
11383 /* See if there are any dwo links. */
11384 if (load_debug_section (str
, file
)
11385 && load_debug_section (abbrev
, file
)
11386 && load_debug_section (info
, file
))
11390 if (process_debug_info (& debug_displays
[info
].section
, file
, abbrev
,
11393 bool introduced
= false;
11395 const char *dir
= NULL
;
11396 const char *id
= NULL
;
11397 const char *name
= NULL
;
11399 for (dwinfo
= first_dwo_info
; dwinfo
!= NULL
; dwinfo
= dwinfo
->next
)
11401 /* Accumulate NAME, DIR and ID fields. */
11402 switch (dwinfo
->type
)
11406 warn (_("Multiple DWO_NAMEs encountered for the same CU\n"));
11407 name
= dwinfo
->value
;
11411 /* There can be multiple DW_AT_comp_dir entries in a CU,
11412 so do not complain. */
11413 dir
= dwinfo
->value
;
11418 warn (_("multiple DWO_IDs encountered for the same CU\n"));
11419 id
= dwinfo
->value
;
11423 error (_("Unexpected DWO INFO type"));
11427 /* If we have reached the end of our list, or we are changing
11428 CUs, then display the information that we have accumulated
11431 && (dwinfo
->next
== NULL
11432 || dwinfo
->next
->cu_offset
!= dwinfo
->cu_offset
))
11434 if (do_debug_links
)
11438 printf (_("The %s section contains link(s) to dwo file(s):\n\n"),
11439 debug_displays
[info
].section
.uncompressed_name
);
11443 printf (_(" Name: %s\n"), name
);
11444 printf (_(" Directory: %s\n"), dir
? dir
: _("<not-found>"));
11446 display_data (printf (_(" ID: ")), (unsigned char *) id
, 8);
11448 printf (_(" ID: <not specified>\n"));
11452 if (do_follow_links
)
11453 load_dwo_file (filename
, name
, dir
, id
);
11455 name
= dir
= id
= NULL
;
11461 if (! do_follow_links
)
11462 /* The other debug links will be displayed by display_debug_links()
11463 so we do not need to do any further processing here. */
11466 /* FIXME: We do not check for the presence of both link sections in the same file. */
11467 /* FIXME: We do not check for the presence of multiple, same-name debuglink sections. */
11468 /* FIXME: We do not check for the presence of a dwo link as well as a debuglink. */
11470 check_for_and_load_links (file
, filename
);
11471 if (first_separate_info
!= NULL
)
11474 do_follow_links
= 0;
11479 free_debug_memory (void)
11483 free_all_abbrevs ();
11485 free (cu_abbrev_map
);
11486 cu_abbrev_map
= NULL
;
11487 next_free_abbrev_map_entry
= 0;
11491 shndx_pool_size
= 0;
11492 shndx_pool_used
= 0;
11500 memset (level_type_signed
, 0, sizeof level_type_signed
);
11501 cu_tu_indexes_read
= -1;
11503 for (i
= 0; i
< max
; i
++)
11504 free_debug_section ((enum dwarf_section_display_enum
) i
);
11506 if (debug_information
!= NULL
)
11508 for (i
= 0; i
< alloc_num_debug_info_entries
; i
++)
11510 if (debug_information
[i
].max_loc_offsets
)
11512 free (debug_information
[i
].loc_offsets
);
11513 free (debug_information
[i
].have_frame_base
);
11515 if (debug_information
[i
].max_range_lists
)
11516 free (debug_information
[i
].range_lists
);
11518 free (debug_information
);
11519 debug_information
= NULL
;
11520 alloc_num_debug_info_entries
= num_debug_info_entries
= 0;
11524 separate_info
* next
;
11526 for (d
= first_separate_info
; d
!= NULL
; d
= next
)
11528 close_debug_file (d
->handle
);
11529 free ((void *) d
->filename
);
11533 first_separate_info
= NULL
;
11539 dwarf_select_sections_by_names (const char *names
)
11543 const char * option
;
11547 debug_dump_long_opts
;
11549 static const debug_dump_long_opts opts_table
[] =
11551 /* Please keep this table alpha- sorted. */
11552 { "Ranges", & do_debug_ranges
, 1 },
11553 { "abbrev", & do_debug_abbrevs
, 1 },
11554 { "addr", & do_debug_addr
, 1 },
11555 { "aranges", & do_debug_aranges
, 1 },
11556 { "cu_index", & do_debug_cu_index
, 1 },
11557 { "decodedline", & do_debug_lines
, FLAG_DEBUG_LINES_DECODED
},
11558 { "follow-links", & do_follow_links
, 1 },
11559 { "frames", & do_debug_frames
, 1 },
11560 { "frames-interp", & do_debug_frames_interp
, 1 },
11561 /* The special .gdb_index section. */
11562 { "gdb_index", & do_gdb_index
, 1 },
11563 { "info", & do_debug_info
, 1 },
11564 { "line", & do_debug_lines
, FLAG_DEBUG_LINES_RAW
}, /* For backwards compatibility. */
11565 { "links", & do_debug_links
, 1 },
11566 { "loc", & do_debug_loc
, 1 },
11567 { "macro", & do_debug_macinfo
, 1 },
11568 { "no-follow-links", & do_follow_links
, 0 },
11569 { "pubnames", & do_debug_pubnames
, 1 },
11570 { "pubtypes", & do_debug_pubtypes
, 1 },
11571 /* This entry is for compatibility
11572 with earlier versions of readelf. */
11573 { "ranges", & do_debug_aranges
, 1 },
11574 { "rawline", & do_debug_lines
, FLAG_DEBUG_LINES_RAW
},
11575 { "str", & do_debug_str
, 1 },
11576 { "str-offsets", & do_debug_str_offsets
, 1 },
11577 /* These trace_* sections are used by Itanium VMS. */
11578 { "trace_abbrev", & do_trace_abbrevs
, 1 },
11579 { "trace_aranges", & do_trace_aranges
, 1 },
11580 { "trace_info", & do_trace_info
, 1 },
11589 const debug_dump_long_opts
* entry
;
11591 for (entry
= opts_table
; entry
->option
; entry
++)
11593 size_t len
= strlen (entry
->option
);
11595 if (strncmp (p
, entry
->option
, len
) == 0
11596 && (p
[len
] == ',' || p
[len
] == '\0'))
11598 * entry
->variable
= entry
->val
;
11600 /* The --debug-dump=frames-interp option also
11601 enables the --debug-dump=frames option. */
11602 if (do_debug_frames_interp
)
11603 do_debug_frames
= 1;
11610 if (entry
->option
== NULL
)
11612 warn (_("Unrecognized debug option '%s'\n"), p
);
11613 p
= strchr (p
, ',');
11624 dwarf_select_sections_by_letters (const char *letters
)
11626 unsigned int lindex
= 0;
11628 while (letters
[lindex
])
11629 switch (letters
[lindex
++])
11631 case 'A': do_debug_addr
= 1; break;
11632 case 'a': do_debug_abbrevs
= 1; break;
11633 case 'c': do_debug_cu_index
= 1; break;
11634 case 'F': do_debug_frames_interp
= 1; /* Fall through. */
11635 case 'f': do_debug_frames
= 1; break;
11636 case 'g': do_gdb_index
= 1; break;
11637 case 'i': do_debug_info
= 1; break;
11638 case 'K': do_follow_links
= 1; break;
11639 case 'N': do_follow_links
= 0; break;
11640 case 'k': do_debug_links
= 1; break;
11641 case 'l': do_debug_lines
|= FLAG_DEBUG_LINES_RAW
; break;
11642 case 'L': do_debug_lines
|= FLAG_DEBUG_LINES_DECODED
; break;
11643 case 'm': do_debug_macinfo
= 1; break;
11644 case 'O': do_debug_str_offsets
= 1; break;
11645 case 'o': do_debug_loc
= 1; break;
11646 case 'p': do_debug_pubnames
= 1; break;
11647 case 'R': do_debug_ranges
= 1; break;
11648 case 'r': do_debug_aranges
= 1; break;
11649 case 's': do_debug_str
= 1; break;
11650 case 'T': do_trace_aranges
= 1; break;
11651 case 't': do_debug_pubtypes
= 1; break;
11652 case 'U': do_trace_info
= 1; break;
11653 case 'u': do_trace_abbrevs
= 1; break;
11656 warn (_("Unrecognized debug option '%s'\n"), letters
);
11662 dwarf_select_sections_all (void)
11665 do_debug_abbrevs
= 1;
11666 do_debug_lines
= FLAG_DEBUG_LINES_RAW
;
11667 do_debug_pubnames
= 1;
11668 do_debug_pubtypes
= 1;
11669 do_debug_aranges
= 1;
11670 do_debug_ranges
= 1;
11671 do_debug_frames
= 1;
11672 do_debug_macinfo
= 1;
11677 do_trace_abbrevs
= 1;
11678 do_trace_aranges
= 1;
11680 do_debug_cu_index
= 1;
11681 do_follow_links
= 1;
11682 do_debug_links
= 1;
11683 do_debug_str_offsets
= 1;
11686 #define NO_ABBREVS NULL, NULL, NULL, 0, 0, 0, NULL, 0
11687 #define ABBREV(N) NULL, NULL, NULL, 0, 0, N, NULL, 0
11689 /* N.B. The order here must match the order in section_display_enum. */
11691 struct dwarf_section_display debug_displays
[] =
11693 { { ".debug_abbrev", ".zdebug_abbrev", NO_ABBREVS
}, display_debug_abbrev
, &do_debug_abbrevs
, false },
11694 { { ".debug_aranges", ".zdebug_aranges", NO_ABBREVS
}, display_debug_aranges
, &do_debug_aranges
, true },
11695 { { ".debug_frame", ".zdebug_frame", NO_ABBREVS
}, display_debug_frames
, &do_debug_frames
, true },
11696 { { ".debug_info", ".zdebug_info", ABBREV (abbrev
)}, display_debug_info
, &do_debug_info
, true },
11697 { { ".debug_line", ".zdebug_line", NO_ABBREVS
}, display_debug_lines
, &do_debug_lines
, true },
11698 { { ".debug_pubnames", ".zdebug_pubnames", NO_ABBREVS
}, display_debug_pubnames
, &do_debug_pubnames
, false },
11699 { { ".debug_gnu_pubnames", ".zdebug_gnu_pubnames", NO_ABBREVS
}, display_debug_gnu_pubnames
, &do_debug_pubnames
, false },
11700 { { ".eh_frame", "", NO_ABBREVS
}, display_debug_frames
, &do_debug_frames
, true },
11701 { { ".debug_macinfo", ".zdebug_macinfo", NO_ABBREVS
}, display_debug_macinfo
, &do_debug_macinfo
, false },
11702 { { ".debug_macro", ".zdebug_macro", NO_ABBREVS
}, display_debug_macro
, &do_debug_macinfo
, true },
11703 { { ".debug_str", ".zdebug_str", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, false },
11704 { { ".debug_line_str", ".zdebug_line_str", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, false },
11705 { { ".debug_loc", ".zdebug_loc", NO_ABBREVS
}, display_debug_loc
, &do_debug_loc
, true },
11706 { { ".debug_loclists", ".zdebug_loclists", NO_ABBREVS
}, display_debug_loc
, &do_debug_loc
, true },
11707 { { ".debug_pubtypes", ".zdebug_pubtypes", NO_ABBREVS
}, display_debug_pubnames
, &do_debug_pubtypes
, false },
11708 { { ".debug_gnu_pubtypes", ".zdebug_gnu_pubtypes", NO_ABBREVS
}, display_debug_gnu_pubnames
, &do_debug_pubtypes
, false },
11709 { { ".debug_ranges", ".zdebug_ranges", NO_ABBREVS
}, display_debug_ranges
, &do_debug_ranges
, true },
11710 { { ".debug_rnglists", ".zdebug_rnglists", NO_ABBREVS
}, display_debug_ranges
, &do_debug_ranges
, true },
11711 { { ".debug_static_func", ".zdebug_static_func", NO_ABBREVS
}, display_debug_not_supported
, NULL
, false },
11712 { { ".debug_static_vars", ".zdebug_static_vars", NO_ABBREVS
}, display_debug_not_supported
, NULL
, false },
11713 { { ".debug_types", ".zdebug_types", ABBREV (abbrev
) }, display_debug_types
, &do_debug_info
, true },
11714 { { ".debug_weaknames", ".zdebug_weaknames", NO_ABBREVS
}, display_debug_not_supported
, NULL
, false },
11715 { { ".gdb_index", "", NO_ABBREVS
}, display_gdb_index
, &do_gdb_index
, false },
11716 { { ".debug_names", "", NO_ABBREVS
}, display_debug_names
, &do_gdb_index
, false },
11717 { { ".trace_info", "", ABBREV (trace_abbrev
) }, display_trace_info
, &do_trace_info
, true },
11718 { { ".trace_abbrev", "", NO_ABBREVS
}, display_debug_abbrev
, &do_trace_abbrevs
, false },
11719 { { ".trace_aranges", "", NO_ABBREVS
}, display_debug_aranges
, &do_trace_aranges
, false },
11720 { { ".debug_info.dwo", ".zdebug_info.dwo", ABBREV (abbrev_dwo
) }, display_debug_info
, &do_debug_info
, true },
11721 { { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo", NO_ABBREVS
}, display_debug_abbrev
, &do_debug_abbrevs
, false },
11722 { { ".debug_types.dwo", ".zdebug_types.dwo", ABBREV (abbrev_dwo
) }, display_debug_types
, &do_debug_info
, true },
11723 { { ".debug_line.dwo", ".zdebug_line.dwo", NO_ABBREVS
}, display_debug_lines
, &do_debug_lines
, true },
11724 { { ".debug_loc.dwo", ".zdebug_loc.dwo", NO_ABBREVS
}, display_debug_loc
, &do_debug_loc
, true },
11725 { { ".debug_macro.dwo", ".zdebug_macro.dwo", NO_ABBREVS
}, display_debug_macro
, &do_debug_macinfo
, true },
11726 { { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo", NO_ABBREVS
}, display_debug_macinfo
, &do_debug_macinfo
, false },
11727 { { ".debug_str.dwo", ".zdebug_str.dwo", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, true },
11728 { { ".debug_str_offsets", ".zdebug_str_offsets", NO_ABBREVS
}, display_debug_str_offsets
, &do_debug_str_offsets
, true },
11729 { { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo", NO_ABBREVS
}, display_debug_str_offsets
, &do_debug_str_offsets
, true },
11730 { { ".debug_addr", ".zdebug_addr", NO_ABBREVS
}, display_debug_addr
, &do_debug_addr
, true },
11731 { { ".debug_cu_index", "", NO_ABBREVS
}, display_cu_index
, &do_debug_cu_index
, false },
11732 { { ".debug_tu_index", "", NO_ABBREVS
}, display_cu_index
, &do_debug_cu_index
, false },
11733 { { ".gnu_debuglink", "", NO_ABBREVS
}, display_debug_links
, &do_debug_links
, false },
11734 { { ".gnu_debugaltlink", "", NO_ABBREVS
}, display_debug_links
, &do_debug_links
, false },
11735 { { ".debug_sup", "", NO_ABBREVS
}, display_debug_sup
, &do_debug_links
, false },
11736 /* Separate debug info files can containt their own .debug_str section,
11737 and this might be in *addition* to a .debug_str section already present
11738 in the main file. Hence we need to have two entries for .debug_str. */
11739 { { ".debug_str", ".zdebug_str", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, false },
11742 /* A static assertion. */
11743 extern int debug_displays_assert
[ARRAY_SIZE (debug_displays
) == max
? 1 : -1];