1 /* dwarf.c -- display DWARF contents of a BFD binary file
2 Copyright (C) 2005-2020 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"
24 #include "bfd_stdint.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>
41 #define MAX(a, b) ((a) > (b) ? (a) : (b))
42 #define MIN(a, b) ((a) < (b) ? (a) : (b))
44 static const char *regname (unsigned int regno
, int row
);
45 static const char *regname_internal_by_table_only (unsigned int regno
);
47 static int have_frame_base
;
48 static int need_base_address
;
50 static unsigned int num_debug_info_entries
= 0;
51 static unsigned int alloc_num_debug_info_entries
= 0;
52 static debug_info
*debug_information
= NULL
;
53 /* Special value for num_debug_info_entries to indicate
54 that the .debug_info section could not be loaded/parsed. */
55 #define DEBUG_INFO_UNAVAILABLE (unsigned int) -1
57 /* A .debug_info section can contain multiple links to separate
58 DWO object files. We use these structures to record these links. */
66 typedef struct dwo_info
70 struct dwo_info
* next
;
73 static dwo_info
* first_dwo_info
= NULL
;
74 static bfd_boolean need_dwo_info
;
76 separate_info
* first_separate_info
= NULL
;
78 unsigned int eh_addr_size
;
83 int do_debug_pubnames
;
84 int do_debug_pubtypes
;
88 int do_debug_frames_interp
;
91 int do_debug_str_offsets
;
98 int do_debug_cu_index
;
102 bfd_boolean do_checks
;
104 int dwarf_cutoff_level
= -1;
105 unsigned long dwarf_start_die
;
109 /* Convenient constant, to avoid having to cast -1 to dwarf_vma when
110 testing whether e.g. a locview list is present. */
111 static const dwarf_vma vm1
= -1;
113 /* Collection of CU/TU section sets from .debug_cu_index and .debug_tu_index
114 sections. For version 1 package files, each set is stored in SHNDX_POOL
115 as a zero-terminated list of section indexes comprising one set of debug
116 sections from a .dwo file. */
118 static unsigned int *shndx_pool
= NULL
;
119 static unsigned int shndx_pool_size
= 0;
120 static unsigned int shndx_pool_used
= 0;
122 /* For version 2 package files, each set contains an array of section offsets
123 and an array of section sizes, giving the offset and size of the
124 contribution from a CU or TU within one of the debug sections.
125 When displaying debug info from a package file, we need to use these
126 tables to locate the corresponding contributions to each section. */
131 dwarf_vma section_offsets
[DW_SECT_MAX
];
132 size_t section_sizes
[DW_SECT_MAX
];
135 static int cu_count
= 0;
136 static int tu_count
= 0;
137 static struct cu_tu_set
*cu_sets
= NULL
;
138 static struct cu_tu_set
*tu_sets
= NULL
;
140 static bfd_boolean
load_cu_tu_indexes (void *);
142 /* An array that indicates for a given level of CU nesting whether
143 the latest DW_AT_type seen for that level was a signed type or
145 #define MAX_CU_NESTING (1 << 8)
146 static bfd_boolean level_type_signed
[MAX_CU_NESTING
];
148 /* Values for do_debug_lines. */
149 #define FLAG_DEBUG_LINES_RAW 1
150 #define FLAG_DEBUG_LINES_DECODED 2
153 size_of_encoded_value (int encoding
)
155 switch (encoding
& 0x7)
158 case 0: return eh_addr_size
;
166 get_encoded_value (unsigned char **pdata
,
168 struct dwarf_section
*section
,
171 unsigned char * data
= * pdata
;
172 unsigned int size
= size_of_encoded_value (encoding
);
175 if (data
+ size
>= end
)
177 warn (_("Encoded value extends past end of section\n"));
182 /* PR 17512: file: 002-829853-0.004. */
185 warn (_("Encoded size of %d is too large to read\n"), size
);
190 /* PR 17512: file: 1085-5603-0.004. */
193 warn (_("Encoded size of 0 is too small to read\n"));
198 if (encoding
& DW_EH_PE_signed
)
199 val
= byte_get_signed (data
, size
);
201 val
= byte_get (data
, size
);
203 if ((encoding
& 0x70) == DW_EH_PE_pcrel
)
204 val
+= section
->address
+ (data
- section
->start
);
206 * pdata
= data
+ size
;
210 #if defined HAVE_LONG_LONG && SIZEOF_LONG_LONG > SIZEOF_LONG
212 # define DWARF_VMA_FMT "ll"
213 # define DWARF_VMA_FMT_LONG "%16.16llx"
215 # define DWARF_VMA_FMT "I64"
216 # define DWARF_VMA_FMT_LONG "%016I64x"
219 # define DWARF_VMA_FMT "l"
220 # define DWARF_VMA_FMT_LONG "%16.16lx"
223 /* Convert a dwarf vma value into a string. Returns a pointer to a static
224 buffer containing the converted VALUE. The value is converted according
225 to the printf formating character FMTCH. If NUM_BYTES is non-zero then
226 it specifies the maximum number of bytes to be displayed in the converted
227 value and FMTCH is ignored - hex is always used. */
230 dwarf_vmatoa_1 (const char *fmtch
, dwarf_vma value
, unsigned num_bytes
)
232 /* As dwarf_vmatoa is used more then once in a printf call
233 for output, we are cycling through an fixed array of pointers
234 for return address. */
235 static int buf_pos
= 0;
236 static struct dwarf_vmatoa_buf
242 ret
= buf
[buf_pos
++].place
;
243 buf_pos
%= ARRAY_SIZE (buf
);
247 /* Printf does not have a way of specifying a maximum field width for an
248 integer value, so we print the full value into a buffer and then select
249 the precision we need. */
250 snprintf (ret
, sizeof (buf
[0].place
), DWARF_VMA_FMT_LONG
, value
);
253 return ret
+ (16 - 2 * num_bytes
);
260 sprintf (fmt
, "%%%s%s", DWARF_VMA_FMT
, fmtch
);
262 sprintf (fmt
, "%%%s", DWARF_VMA_FMT
);
263 snprintf (ret
, sizeof (buf
[0].place
), fmt
, value
);
268 static inline const char *
269 dwarf_vmatoa (const char * fmtch
, dwarf_vma value
)
271 return dwarf_vmatoa_1 (fmtch
, value
, 0);
274 /* Print a dwarf_vma value (typically an address, offset or length) in
275 hexadecimal format, followed by a space. The length of the VALUE (and
276 hence the precision displayed) is determined by the NUM_BYTES parameter. */
279 print_dwarf_vma (dwarf_vma value
, unsigned num_bytes
)
281 printf ("%s ", dwarf_vmatoa_1 (NULL
, value
, num_bytes
));
284 /* Print a view number in hexadecimal value, with the same width
285 print_dwarf_vma would have printed it with the same num_bytes.
286 Print blanks for zero view, unless force is nonzero. */
289 print_dwarf_view (dwarf_vma value
, unsigned num_bytes
, int force
)
297 assert (value
== (unsigned long) value
);
299 printf ("v%0*lx ", len
- 1, (unsigned long) value
);
301 printf ("%*s", len
+ 1, "");
304 /* Format a 64-bit value, given as two 32-bit values, in hex.
305 For reentrancy, this uses a buffer provided by the caller. */
308 dwarf_vmatoa64 (dwarf_vma hvalue
, dwarf_vma lvalue
, char *buf
,
309 unsigned int buf_len
)
314 snprintf (buf
, buf_len
, "%" DWARF_VMA_FMT
"x", lvalue
);
317 len
= snprintf (buf
, buf_len
, "%" DWARF_VMA_FMT
"x", hvalue
);
318 snprintf (buf
+ len
, buf_len
- len
,
319 "%08" DWARF_VMA_FMT
"x", lvalue
);
325 /* Read in a LEB128 encoded value starting at address DATA.
326 If SIGN is true, return a signed LEB128 value.
327 If LENGTH_RETURN is not NULL, return in it the number of bytes read.
328 If STATUS_RETURN in not NULL, return with bit 0 (LSB) set if the
329 terminating byte was not found and with bit 1 set if the value
330 overflows a dwarf_vma.
331 No bytes will be read at address END or beyond. */
334 read_leb128 (unsigned char *data
,
335 const unsigned char *const end
,
337 unsigned int *length_return
,
340 dwarf_vma result
= 0;
341 unsigned int num_read
= 0;
342 unsigned int shift
= 0;
347 unsigned char byte
= *data
++;
350 if (shift
< sizeof (result
) * 8)
352 result
|= ((dwarf_vma
) (byte
& 0x7f)) << shift
;
353 if ((result
>> shift
) != (byte
& 0x7f))
358 else if ((byte
& 0x7f) != 0)
361 if ((byte
& 0x80) == 0)
364 if (sign
&& (shift
< 8 * sizeof (result
)) && (byte
& 0x40))
365 result
|= -((dwarf_vma
) 1 << shift
);
370 if (length_return
!= NULL
)
371 *length_return
= num_read
;
372 if (status_return
!= NULL
)
373 *status_return
= status
;
378 /* Read AMOUNT bytes from PTR and store them in VAL as an unsigned value.
379 Checks to make sure that the read will not reach or pass END
380 and that VAL is big enough to hold AMOUNT bytes. */
381 #define SAFE_BYTE_GET(VAL, PTR, AMOUNT, END) \
384 unsigned int amount = (AMOUNT); \
385 if (sizeof (VAL) < amount) \
387 error (ngettext ("internal error: attempt to read %d byte " \
388 "of data in to %d sized variable", \
389 "internal error: attempt to read %d bytes " \
390 "of data in to %d sized variable", \
392 amount, (int) sizeof (VAL)); \
393 amount = sizeof (VAL); \
395 if (((PTR) + amount) >= (END)) \
398 amount = (END) - (PTR); \
402 if (amount == 0 || amount > 8) \
405 VAL = byte_get ((PTR), amount); \
409 /* Like SAFE_BYTE_GET, but also increments PTR by AMOUNT. */
410 #define SAFE_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \
413 SAFE_BYTE_GET (VAL, PTR, AMOUNT, END); \
418 /* Like SAFE_BYTE_GET, but reads a signed value. */
419 #define SAFE_SIGNED_BYTE_GET(VAL, PTR, AMOUNT, END) \
422 unsigned int amount = (AMOUNT); \
423 if (((PTR) + amount) >= (END)) \
426 amount = (END) - (PTR); \
431 VAL = byte_get_signed ((PTR), amount); \
437 /* Like SAFE_SIGNED_BYTE_GET, but also increments PTR by AMOUNT. */
438 #define SAFE_SIGNED_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \
441 SAFE_SIGNED_BYTE_GET (VAL, PTR, AMOUNT, END); \
446 #define SAFE_BYTE_GET64(PTR, HIGH, LOW, END) \
449 if (((PTR) + 8) <= (END)) \
451 byte_get_64 ((PTR), (HIGH), (LOW)); \
455 * (LOW) = * (HIGH) = 0; \
460 typedef struct State_Machine_Registers
469 unsigned char op_index
;
470 unsigned char end_sequence
;
471 /* This variable hold the number of the last entry seen
472 in the File Table. */
473 unsigned int last_file_entry
;
476 static SMR state_machine_regs
;
479 reset_state_machine (int is_stmt
)
481 state_machine_regs
.address
= 0;
482 state_machine_regs
.view
= 0;
483 state_machine_regs
.op_index
= 0;
484 state_machine_regs
.file
= 1;
485 state_machine_regs
.line
= 1;
486 state_machine_regs
.column
= 0;
487 state_machine_regs
.is_stmt
= is_stmt
;
488 state_machine_regs
.basic_block
= 0;
489 state_machine_regs
.end_sequence
= 0;
490 state_machine_regs
.last_file_entry
= 0;
493 /* Handled an extend line op.
494 Returns the number of bytes read. */
497 process_extended_line_op (unsigned char * data
,
501 unsigned char op_code
;
502 size_t len
, header_len
;
504 unsigned char *orig_data
= data
;
507 READ_ULEB (len
, data
, end
);
508 header_len
= data
- orig_data
;
510 if (len
== 0 || data
== end
|| len
> (size_t) (end
- data
))
512 warn (_("Badly formed extended line op encountered!\n"));
518 printf (_(" Extended opcode %d: "), op_code
);
522 case DW_LNE_end_sequence
:
523 printf (_("End of Sequence\n\n"));
524 reset_state_machine (is_stmt
);
527 case DW_LNE_set_address
:
528 /* PR 17512: file: 002-100480-0.004. */
531 warn (_("Length (%lu) of DW_LNE_set_address op is too long\n"),
532 (unsigned long) len
- 1);
536 SAFE_BYTE_GET (adr
, data
, len
- 1, end
);
537 printf (_("set Address to 0x%s\n"), dwarf_vmatoa ("x", adr
));
538 state_machine_regs
.address
= adr
;
539 state_machine_regs
.view
= 0;
540 state_machine_regs
.op_index
= 0;
543 case DW_LNE_define_file
:
544 printf (_("define new File Table entry\n"));
545 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
546 printf (" %d\t", ++state_machine_regs
.last_file_entry
);
552 l
= strnlen ((char *) data
, end
- data
);
554 READ_ULEB (val
, data
, end
);
555 printf ("%s\t", dwarf_vmatoa ("u", val
));
556 READ_ULEB (val
, data
, end
);
557 printf ("%s\t", dwarf_vmatoa ("u", val
));
558 READ_ULEB (val
, data
, end
);
559 printf ("%s\t", dwarf_vmatoa ("u", val
));
560 printf ("%.*s\n\n", (int) l
, name
);
563 if (((size_t) (data
- orig_data
) != len
+ header_len
) || data
== end
)
564 warn (_("DW_LNE_define_file: Bad opcode length\n"));
567 case DW_LNE_set_discriminator
:
568 READ_ULEB (val
, data
, end
);
569 printf (_("set Discriminator to %s\n"), dwarf_vmatoa ("u", val
));
573 case DW_LNE_HP_negate_is_UV_update
:
574 printf ("DW_LNE_HP_negate_is_UV_update\n");
576 case DW_LNE_HP_push_context
:
577 printf ("DW_LNE_HP_push_context\n");
579 case DW_LNE_HP_pop_context
:
580 printf ("DW_LNE_HP_pop_context\n");
582 case DW_LNE_HP_set_file_line_column
:
583 printf ("DW_LNE_HP_set_file_line_column\n");
585 case DW_LNE_HP_set_routine_name
:
586 printf ("DW_LNE_HP_set_routine_name\n");
588 case DW_LNE_HP_set_sequence
:
589 printf ("DW_LNE_HP_set_sequence\n");
591 case DW_LNE_HP_negate_post_semantics
:
592 printf ("DW_LNE_HP_negate_post_semantics\n");
594 case DW_LNE_HP_negate_function_exit
:
595 printf ("DW_LNE_HP_negate_function_exit\n");
597 case DW_LNE_HP_negate_front_end_logical
:
598 printf ("DW_LNE_HP_negate_front_end_logical\n");
600 case DW_LNE_HP_define_proc
:
601 printf ("DW_LNE_HP_define_proc\n");
603 case DW_LNE_HP_source_file_correlation
:
605 unsigned char *edata
= data
+ len
- 1;
607 printf ("DW_LNE_HP_source_file_correlation\n");
613 READ_ULEB (opc
, data
, edata
);
617 case DW_LNE_HP_SFC_formfeed
:
618 printf (" DW_LNE_HP_SFC_formfeed\n");
620 case DW_LNE_HP_SFC_set_listing_line
:
621 READ_ULEB (val
, data
, edata
);
622 printf (" DW_LNE_HP_SFC_set_listing_line (%s)\n",
623 dwarf_vmatoa ("u", val
));
625 case DW_LNE_HP_SFC_associate
:
626 printf (" DW_LNE_HP_SFC_associate ");
627 READ_ULEB (val
, data
, edata
);
628 printf ("(%s", dwarf_vmatoa ("u", val
));
629 READ_ULEB (val
, data
, edata
);
630 printf (",%s", dwarf_vmatoa ("u", val
));
631 READ_ULEB (val
, data
, edata
);
632 printf (",%s)\n", dwarf_vmatoa ("u", val
));
635 printf (_(" UNKNOWN DW_LNE_HP_SFC opcode (%u)\n"), opc
);
645 unsigned int rlen
= len
- 1;
647 if (op_code
>= DW_LNE_lo_user
648 /* The test against DW_LNW_hi_user is redundant due to
649 the limited range of the unsigned char data type used
651 /*&& op_code <= DW_LNE_hi_user*/)
652 printf (_("user defined: "));
654 printf (_("UNKNOWN: "));
655 printf (_("length %d ["), rlen
);
657 printf (" %02x", *data
++);
663 return len
+ header_len
;
666 static const unsigned char *
667 fetch_indirect_string (dwarf_vma offset
)
669 struct dwarf_section
*section
= &debug_displays
[str
].section
;
670 const unsigned char * ret
;
672 if (section
->start
== NULL
)
673 return (const unsigned char *) _("<no .debug_str section>");
675 if (offset
>= section
->size
)
677 warn (_("DW_FORM_strp offset too big: %s\n"),
678 dwarf_vmatoa ("x", offset
));
679 return (const unsigned char *) _("<offset is too big>");
682 ret
= section
->start
+ offset
;
683 /* Unfortunately we cannot rely upon the .debug_str section ending with a
684 NUL byte. Since our caller is expecting to receive a well formed C
685 string we test for the lack of a terminating byte here. */
686 if (strnlen ((const char *) ret
, section
->size
- offset
)
687 == section
->size
- offset
)
688 ret
= (const unsigned char *)
689 _("<no NUL byte at end of .debug_str section>");
694 static const unsigned char *
695 fetch_indirect_line_string (dwarf_vma offset
)
697 struct dwarf_section
*section
= &debug_displays
[line_str
].section
;
698 const unsigned char * ret
;
700 if (section
->start
== NULL
)
701 return (const unsigned char *) _("<no .debug_line_str section>");
703 if (offset
>= section
->size
)
705 warn (_("DW_FORM_line_strp offset too big: %s\n"),
706 dwarf_vmatoa ("x", offset
));
707 return (const unsigned char *) _("<offset is too big>");
710 ret
= section
->start
+ offset
;
711 /* Unfortunately we cannot rely upon the .debug_line_str section ending
712 with a NUL byte. Since our caller is expecting to receive a well formed
713 C string we test for the lack of a terminating byte here. */
714 if (strnlen ((const char *) ret
, section
->size
- offset
)
715 == section
->size
- offset
)
716 ret
= (const unsigned char *)
717 _("<no NUL byte at end of .debug_line_str section>");
723 fetch_indexed_string (dwarf_vma idx
, struct cu_tu_set
*this_set
,
724 dwarf_vma offset_size
, bfd_boolean dwo
)
726 enum dwarf_section_display_enum str_sec_idx
= dwo
? str_dwo
: str
;
727 enum dwarf_section_display_enum idx_sec_idx
= dwo
? str_index_dwo
: str_index
;
728 struct dwarf_section
*index_section
= &debug_displays
[idx_sec_idx
].section
;
729 struct dwarf_section
*str_section
= &debug_displays
[str_sec_idx
].section
;
730 dwarf_vma index_offset
;
731 dwarf_vma str_offset
;
733 unsigned char *curr
= index_section
->start
;
734 const unsigned char *end
= curr
+ index_section
->size
;
737 if (index_section
->start
== NULL
)
738 return (dwo
? _("<no .debug_str_offsets.dwo section>")
739 : _("<no .debug_str_offsets section>"));
741 if (str_section
->start
== NULL
)
742 return (dwo
? _("<no .debug_str.dwo section>")
743 : _("<no .debug_str section>"));
745 /* FIXME: We should cache the length... */
746 SAFE_BYTE_GET_AND_INC (length
, curr
, 4, end
);
747 if (length
== 0xffffffff)
749 if (offset_size
!= 8)
751 SAFE_BYTE_GET_AND_INC (length
, curr
, 8, end
);
753 else if (offset_size
!= 4)
758 /* Skip the version and padding bytes.
759 We assume that they are correct. */
762 /* FIXME: The code below assumes that there is only one table
763 in the .debug_str_offsets section, so check that now. */
764 if ((offset_size
== 4 && curr
+ length
< (end
- 8))
765 || (offset_size
== 8 && curr
+ length
< (end
- 16)))
767 warn (_("index table size is too small %s vs %s\n"),
768 dwarf_vmatoa ("x", length
),
769 dwarf_vmatoa ("x", index_section
->size
));
770 return _("<table too small");
773 index_offset
= idx
* offset_size
;
775 if (this_set
!= NULL
)
776 index_offset
+= this_set
->section_offsets
[DW_SECT_STR_OFFSETS
];
778 if (index_offset
>= length
)
780 warn (_("DW_FORM_GNU_str_index offset too big: %s vs %s\n"),
781 dwarf_vmatoa ("x", index_offset
),
782 dwarf_vmatoa ("x", length
));
783 return _("<index offset is too big>");
786 str_offset
= byte_get (curr
+ index_offset
, offset_size
);
787 str_offset
-= str_section
->address
;
788 if (str_offset
>= str_section
->size
)
790 warn (_("DW_FORM_GNU_str_index indirect offset too big: %s\n"),
791 dwarf_vmatoa ("x", str_offset
));
792 return _("<indirect index offset is too big>");
795 ret
= (const char *) str_section
->start
+ str_offset
;
796 /* Unfortunately we cannot rely upon str_section ending with a NUL byte.
797 Since our caller is expecting to receive a well formed C string we test
798 for the lack of a terminating byte here. */
799 if (strnlen (ret
, str_section
->size
- str_offset
)
800 == str_section
->size
- str_offset
)
801 ret
= (const char *) _("<no NUL byte at end of section>");
807 fetch_indexed_value (dwarf_vma offset
, dwarf_vma bytes
)
809 struct dwarf_section
*section
= &debug_displays
[debug_addr
].section
;
811 if (section
->start
== NULL
)
812 return (_("<no .debug_addr section>"));
814 if (offset
+ bytes
> section
->size
)
816 warn (_("Offset into section %s too big: %s\n"),
817 section
->name
, dwarf_vmatoa ("x", offset
));
818 return "<offset too big>";
821 return dwarf_vmatoa ("x", byte_get (section
->start
+ offset
, bytes
));
825 /* FIXME: There are better and more efficient ways to handle
826 these structures. For now though, I just want something that
827 is simple to implement. */
828 typedef struct abbrev_attr
830 unsigned long attribute
;
832 bfd_signed_vma implicit_const
;
833 struct abbrev_attr
*next
;
837 typedef struct abbrev_entry
842 struct abbrev_attr
*first_attr
;
843 struct abbrev_attr
*last_attr
;
844 struct abbrev_entry
*next
;
848 static abbrev_entry
*first_abbrev
= NULL
;
849 static abbrev_entry
*last_abbrev
= NULL
;
856 for (abbrv
= first_abbrev
; abbrv
;)
858 abbrev_entry
*next_abbrev
= abbrv
->next
;
861 for (attr
= abbrv
->first_attr
; attr
;)
863 abbrev_attr
*next_attr
= attr
->next
;
873 last_abbrev
= first_abbrev
= NULL
;
877 add_abbrev (unsigned long number
, unsigned long tag
, int children
)
881 entry
= (abbrev_entry
*) malloc (sizeof (*entry
));
886 entry
->entry
= number
;
888 entry
->children
= children
;
889 entry
->first_attr
= NULL
;
890 entry
->last_attr
= NULL
;
893 if (first_abbrev
== NULL
)
894 first_abbrev
= entry
;
896 last_abbrev
->next
= entry
;
902 add_abbrev_attr (unsigned long attribute
, unsigned long form
,
903 bfd_signed_vma implicit_const
)
907 attr
= (abbrev_attr
*) malloc (sizeof (*attr
));
912 attr
->attribute
= attribute
;
914 attr
->implicit_const
= implicit_const
;
917 if (last_abbrev
->first_attr
== NULL
)
918 last_abbrev
->first_attr
= attr
;
920 last_abbrev
->last_attr
->next
= attr
;
922 last_abbrev
->last_attr
= attr
;
925 /* Processes the (partial) contents of a .debug_abbrev section.
926 Returns NULL if the end of the section was encountered.
927 Returns the address after the last byte read if the end of
928 an abbreviation set was found. */
930 static unsigned char *
931 process_abbrev_section (unsigned char *start
, unsigned char *end
)
933 if (first_abbrev
!= NULL
)
940 unsigned long attribute
;
943 READ_ULEB (entry
, start
, end
);
945 /* A single zero is supposed to end the section according
946 to the standard. If there's more, then signal that to
953 READ_ULEB (tag
, start
, end
);
959 add_abbrev (entry
, tag
, children
);
964 /* Initialize it due to a false compiler warning. */
965 bfd_signed_vma implicit_const
= -1;
967 READ_ULEB (attribute
, start
, end
);
971 READ_ULEB (form
, start
, end
);
975 if (form
== DW_FORM_implicit_const
)
977 READ_SLEB (implicit_const
, start
, end
);
982 add_abbrev_attr (attribute
, form
, implicit_const
);
984 while (attribute
!= 0);
987 /* Report the missing single zero which ends the section. */
988 error (_(".debug_abbrev section not zero terminated\n"));
994 get_TAG_name (unsigned long tag
)
996 const char *name
= get_DW_TAG_name ((unsigned int) tag
);
1000 static char buffer
[100];
1002 if (tag
>= DW_TAG_lo_user
&& tag
<= DW_TAG_hi_user
)
1003 snprintf (buffer
, sizeof (buffer
), _("User TAG value: %#lx"), tag
);
1005 snprintf (buffer
, sizeof (buffer
), _("Unknown TAG value: %#lx"), tag
);
1013 get_FORM_name (unsigned long form
)
1018 return "DW_FORM value: 0";
1020 name
= get_DW_FORM_name (form
);
1023 static char buffer
[100];
1025 snprintf (buffer
, sizeof (buffer
), _("Unknown FORM value: %lx"), form
);
1033 get_IDX_name (unsigned long idx
)
1035 const char *name
= get_DW_IDX_name ((unsigned int) idx
);
1039 static char buffer
[100];
1041 snprintf (buffer
, sizeof (buffer
), _("Unknown IDX value: %lx"), idx
);
1048 static unsigned char *
1049 display_block (unsigned char *data
,
1051 const unsigned char * const end
, char delimiter
)
1055 printf (_("%c%s byte block: "), delimiter
, dwarf_vmatoa ("u", length
));
1057 return (unsigned char *) end
;
1059 maxlen
= (dwarf_vma
) (end
- data
);
1060 length
= length
> maxlen
? maxlen
: length
;
1063 printf ("%lx ", (unsigned long) byte_get (data
++, 1));
1069 decode_location_expression (unsigned char * data
,
1070 unsigned int pointer_size
,
1071 unsigned int offset_size
,
1074 dwarf_vma cu_offset
,
1075 struct dwarf_section
* section
)
1079 dwarf_signed_vma svalue
;
1080 unsigned char *end
= data
+ length
;
1081 int need_frame_base
= 0;
1090 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1091 printf ("DW_OP_addr: %s", dwarf_vmatoa ("x", uvalue
));
1094 printf ("DW_OP_deref");
1097 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1098 printf ("DW_OP_const1u: %lu", (unsigned long) uvalue
);
1101 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 1, end
);
1102 printf ("DW_OP_const1s: %ld", (long) svalue
);
1105 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
1106 printf ("DW_OP_const2u: %lu", (unsigned long) uvalue
);
1109 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1110 printf ("DW_OP_const2s: %ld", (long) svalue
);
1113 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1114 printf ("DW_OP_const4u: %lu", (unsigned long) uvalue
);
1117 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
1118 printf ("DW_OP_const4s: %ld", (long) svalue
);
1121 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1122 printf ("DW_OP_const8u: %lu ", (unsigned long) uvalue
);
1123 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1124 printf ("%lu", (unsigned long) uvalue
);
1127 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
1128 printf ("DW_OP_const8s: %ld ", (long) svalue
);
1129 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
1130 printf ("%ld", (long) svalue
);
1133 READ_ULEB (uvalue
, data
, end
);
1134 printf ("DW_OP_constu: %s", dwarf_vmatoa ("u", uvalue
));
1137 READ_SLEB (svalue
, data
, end
);
1138 printf ("DW_OP_consts: %s", dwarf_vmatoa ("d", svalue
));
1141 printf ("DW_OP_dup");
1144 printf ("DW_OP_drop");
1147 printf ("DW_OP_over");
1150 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1151 printf ("DW_OP_pick: %ld", (unsigned long) uvalue
);
1154 printf ("DW_OP_swap");
1157 printf ("DW_OP_rot");
1160 printf ("DW_OP_xderef");
1163 printf ("DW_OP_abs");
1166 printf ("DW_OP_and");
1169 printf ("DW_OP_div");
1172 printf ("DW_OP_minus");
1175 printf ("DW_OP_mod");
1178 printf ("DW_OP_mul");
1181 printf ("DW_OP_neg");
1184 printf ("DW_OP_not");
1187 printf ("DW_OP_or");
1190 printf ("DW_OP_plus");
1192 case DW_OP_plus_uconst
:
1193 READ_ULEB (uvalue
, data
, end
);
1194 printf ("DW_OP_plus_uconst: %s", dwarf_vmatoa ("u", uvalue
));
1197 printf ("DW_OP_shl");
1200 printf ("DW_OP_shr");
1203 printf ("DW_OP_shra");
1206 printf ("DW_OP_xor");
1209 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1210 printf ("DW_OP_bra: %ld", (long) svalue
);
1213 printf ("DW_OP_eq");
1216 printf ("DW_OP_ge");
1219 printf ("DW_OP_gt");
1222 printf ("DW_OP_le");
1225 printf ("DW_OP_lt");
1228 printf ("DW_OP_ne");
1231 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1232 printf ("DW_OP_skip: %ld", (long) svalue
);
1267 printf ("DW_OP_lit%d", op
- DW_OP_lit0
);
1302 printf ("DW_OP_reg%d (%s)", op
- DW_OP_reg0
,
1303 regname (op
- DW_OP_reg0
, 1));
1338 READ_SLEB (svalue
, data
, end
);
1339 printf ("DW_OP_breg%d (%s): %s", op
- DW_OP_breg0
,
1340 regname (op
- DW_OP_breg0
, 1), dwarf_vmatoa ("d", svalue
));
1344 READ_ULEB (uvalue
, data
, end
);
1345 printf ("DW_OP_regx: %s (%s)",
1346 dwarf_vmatoa ("u", uvalue
), regname (uvalue
, 1));
1349 need_frame_base
= 1;
1350 READ_SLEB (svalue
, data
, end
);
1351 printf ("DW_OP_fbreg: %s", dwarf_vmatoa ("d", svalue
));
1354 READ_ULEB (uvalue
, data
, end
);
1355 READ_SLEB (svalue
, data
, end
);
1356 printf ("DW_OP_bregx: %s (%s) %s",
1357 dwarf_vmatoa ("u", uvalue
), regname (uvalue
, 1),
1358 dwarf_vmatoa ("d", svalue
));
1361 READ_ULEB (uvalue
, data
, end
);
1362 printf ("DW_OP_piece: %s", dwarf_vmatoa ("u", uvalue
));
1364 case DW_OP_deref_size
:
1365 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1366 printf ("DW_OP_deref_size: %ld", (long) uvalue
);
1368 case DW_OP_xderef_size
:
1369 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1370 printf ("DW_OP_xderef_size: %ld", (long) uvalue
);
1373 printf ("DW_OP_nop");
1376 /* DWARF 3 extensions. */
1377 case DW_OP_push_object_address
:
1378 printf ("DW_OP_push_object_address");
1381 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1382 this ought to be an 8-byte wide computation. */
1383 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1384 printf ("DW_OP_call2: <0x%s>",
1385 dwarf_vmatoa ("x", svalue
+ cu_offset
));
1388 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1389 this ought to be an 8-byte wide computation. */
1390 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
1391 printf ("DW_OP_call4: <0x%s>",
1392 dwarf_vmatoa ("x", svalue
+ cu_offset
));
1394 case DW_OP_call_ref
:
1395 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1396 this ought to be an 8-byte wide computation. */
1397 if (dwarf_version
== -1)
1399 printf (_("(DW_OP_call_ref in frame info)"));
1400 /* No way to tell where the next op is, so just bail. */
1401 return need_frame_base
;
1403 if (dwarf_version
== 2)
1405 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1409 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1411 printf ("DW_OP_call_ref: <0x%s>", dwarf_vmatoa ("x", uvalue
));
1413 case DW_OP_form_tls_address
:
1414 printf ("DW_OP_form_tls_address");
1416 case DW_OP_call_frame_cfa
:
1417 printf ("DW_OP_call_frame_cfa");
1419 case DW_OP_bit_piece
:
1420 printf ("DW_OP_bit_piece: ");
1421 READ_ULEB (uvalue
, data
, end
);
1422 printf (_("size: %s "), dwarf_vmatoa ("u", uvalue
));
1423 READ_ULEB (uvalue
, data
, end
);
1424 printf (_("offset: %s "), dwarf_vmatoa ("u", uvalue
));
1427 /* DWARF 4 extensions. */
1428 case DW_OP_stack_value
:
1429 printf ("DW_OP_stack_value");
1432 case DW_OP_implicit_value
:
1433 printf ("DW_OP_implicit_value");
1434 READ_ULEB (uvalue
, data
, end
);
1435 data
= display_block (data
, uvalue
, end
, ' ');
1438 /* GNU extensions. */
1439 case DW_OP_GNU_push_tls_address
:
1440 printf (_("DW_OP_GNU_push_tls_address or DW_OP_HP_unknown"));
1442 case DW_OP_GNU_uninit
:
1443 printf ("DW_OP_GNU_uninit");
1444 /* FIXME: Is there data associated with this OP ? */
1446 case DW_OP_GNU_encoded_addr
:
1453 addr
= get_encoded_value (&data
, encoding
, section
, end
);
1455 printf ("DW_OP_GNU_encoded_addr: fmt:%02x addr:", encoding
);
1456 print_dwarf_vma (addr
, pointer_size
);
1459 case DW_OP_implicit_pointer
:
1460 case DW_OP_GNU_implicit_pointer
:
1461 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1462 this ought to be an 8-byte wide computation. */
1463 if (dwarf_version
== -1)
1465 printf (_("(%s in frame info)"),
1466 (op
== DW_OP_implicit_pointer
1467 ? "DW_OP_implicit_pointer"
1468 : "DW_OP_GNU_implicit_pointer"));
1469 /* No way to tell where the next op is, so just bail. */
1470 return need_frame_base
;
1472 if (dwarf_version
== 2)
1474 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1478 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1480 READ_SLEB (svalue
, data
, end
);
1481 printf ("%s: <0x%s> %s",
1482 (op
== DW_OP_implicit_pointer
1483 ? "DW_OP_implicit_pointer" : "DW_OP_GNU_implicit_pointer"),
1484 dwarf_vmatoa ("x", uvalue
),
1485 dwarf_vmatoa ("d", svalue
));
1487 case DW_OP_entry_value
:
1488 case DW_OP_GNU_entry_value
:
1489 READ_ULEB (uvalue
, data
, end
);
1490 /* PR 17531: file: 0cc9cd00. */
1491 if (uvalue
> (dwarf_vma
) (end
- data
))
1492 uvalue
= end
- data
;
1493 printf ("%s: (", (op
== DW_OP_entry_value
? "DW_OP_entry_value"
1494 : "DW_OP_GNU_entry_value"));
1495 if (decode_location_expression (data
, pointer_size
, offset_size
,
1496 dwarf_version
, uvalue
,
1497 cu_offset
, section
))
1498 need_frame_base
= 1;
1504 case DW_OP_const_type
:
1505 case DW_OP_GNU_const_type
:
1506 READ_ULEB (uvalue
, data
, end
);
1507 printf ("%s: <0x%s> ",
1508 (op
== DW_OP_const_type
? "DW_OP_const_type"
1509 : "DW_OP_GNU_const_type"),
1510 dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1511 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1512 data
= display_block (data
, uvalue
, end
, ' ');
1514 case DW_OP_regval_type
:
1515 case DW_OP_GNU_regval_type
:
1516 READ_ULEB (uvalue
, data
, end
);
1517 printf ("%s: %s (%s)",
1518 (op
== DW_OP_regval_type
? "DW_OP_regval_type"
1519 : "DW_OP_GNU_regval_type"),
1520 dwarf_vmatoa ("u", uvalue
), regname (uvalue
, 1));
1521 READ_ULEB (uvalue
, data
, end
);
1522 printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1524 case DW_OP_deref_type
:
1525 case DW_OP_GNU_deref_type
:
1526 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1528 (op
== DW_OP_deref_type
? "DW_OP_deref_type"
1529 : "DW_OP_GNU_deref_type"),
1531 READ_ULEB (uvalue
, data
, end
);
1532 printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1535 case DW_OP_GNU_convert
:
1536 READ_ULEB (uvalue
, data
, end
);
1537 printf ("%s <0x%s>",
1538 (op
== DW_OP_convert
? "DW_OP_convert" : "DW_OP_GNU_convert"),
1539 dwarf_vmatoa ("x", uvalue
? cu_offset
+ uvalue
: 0));
1541 case DW_OP_reinterpret
:
1542 case DW_OP_GNU_reinterpret
:
1543 READ_ULEB (uvalue
, data
, end
);
1544 printf ("%s <0x%s>",
1545 (op
== DW_OP_reinterpret
? "DW_OP_reinterpret"
1546 : "DW_OP_GNU_reinterpret"),
1547 dwarf_vmatoa ("x", uvalue
? cu_offset
+ uvalue
: 0));
1549 case DW_OP_GNU_parameter_ref
:
1550 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1551 printf ("DW_OP_GNU_parameter_ref: <0x%s>",
1552 dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1554 case DW_OP_GNU_addr_index
:
1555 READ_ULEB (uvalue
, data
, end
);
1556 printf ("DW_OP_GNU_addr_index <0x%s>", dwarf_vmatoa ("x", uvalue
));
1558 case DW_OP_GNU_const_index
:
1559 READ_ULEB (uvalue
, data
, end
);
1560 printf ("DW_OP_GNU_const_index <0x%s>", dwarf_vmatoa ("x", uvalue
));
1562 case DW_OP_GNU_variable_value
:
1563 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1564 this ought to be an 8-byte wide computation. */
1565 if (dwarf_version
== -1)
1567 printf (_("(DW_OP_GNU_variable_value in frame info)"));
1568 /* No way to tell where the next op is, so just bail. */
1569 return need_frame_base
;
1571 if (dwarf_version
== 2)
1573 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1577 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1579 printf ("DW_OP_GNU_variable_value: <0x%s>", dwarf_vmatoa ("x", uvalue
));
1582 /* HP extensions. */
1583 case DW_OP_HP_is_value
:
1584 printf ("DW_OP_HP_is_value");
1585 /* FIXME: Is there data associated with this OP ? */
1587 case DW_OP_HP_fltconst4
:
1588 printf ("DW_OP_HP_fltconst4");
1589 /* FIXME: Is there data associated with this OP ? */
1591 case DW_OP_HP_fltconst8
:
1592 printf ("DW_OP_HP_fltconst8");
1593 /* FIXME: Is there data associated with this OP ? */
1595 case DW_OP_HP_mod_range
:
1596 printf ("DW_OP_HP_mod_range");
1597 /* FIXME: Is there data associated with this OP ? */
1599 case DW_OP_HP_unmod_range
:
1600 printf ("DW_OP_HP_unmod_range");
1601 /* FIXME: Is there data associated with this OP ? */
1604 printf ("DW_OP_HP_tls");
1605 /* FIXME: Is there data associated with this OP ? */
1608 /* PGI (STMicroelectronics) extensions. */
1609 case DW_OP_PGI_omp_thread_num
:
1610 /* Pushes the thread number for the current thread as it would be
1611 returned by the standard OpenMP library function:
1612 omp_get_thread_num(). The "current thread" is the thread for
1613 which the expression is being evaluated. */
1614 printf ("DW_OP_PGI_omp_thread_num");
1618 if (op
>= DW_OP_lo_user
1619 && op
<= DW_OP_hi_user
)
1620 printf (_("(User defined location op 0x%x)"), op
);
1622 printf (_("(Unknown location op 0x%x)"), op
);
1623 /* No way to tell where the next op is, so just bail. */
1624 return need_frame_base
;
1627 /* Separate the ops. */
1632 return need_frame_base
;
1635 /* Find the CU or TU set corresponding to the given CU_OFFSET.
1636 This is used for DWARF package files. */
1638 static struct cu_tu_set
*
1639 find_cu_tu_set_v2 (dwarf_vma cu_offset
, int do_types
)
1641 struct cu_tu_set
*p
;
1643 unsigned int dw_sect
;
1649 dw_sect
= DW_SECT_TYPES
;
1655 dw_sect
= DW_SECT_INFO
;
1659 if (p
->section_offsets
[dw_sect
] == cu_offset
)
1667 /* Add INC to HIGH_BITS:LOW_BITS. */
1669 add64 (dwarf_vma
* high_bits
, dwarf_vma
* low_bits
, dwarf_vma inc
)
1671 dwarf_vma tmp
= * low_bits
;
1675 /* FIXME: There is probably a better way of handling this:
1677 We need to cope with dwarf_vma being a 32-bit or 64-bit
1678 type. Plus regardless of its size LOW_BITS is meant to
1679 only hold 32-bits, so if there is overflow or wrap around
1680 we must propagate into HIGH_BITS. */
1681 if (tmp
< * low_bits
)
1685 else if (sizeof (tmp
) > 8
1696 fetch_alt_indirect_string (dwarf_vma offset
)
1700 if (! do_follow_links
)
1703 if (first_separate_info
== NULL
)
1704 return _("<no links available>");
1706 for (i
= first_separate_info
; i
!= NULL
; i
= i
->next
)
1708 struct dwarf_section
* section
;
1711 if (! load_debug_section (separate_debug_str
, i
->handle
))
1714 section
= &debug_displays
[separate_debug_str
].section
;
1716 if (section
->start
== NULL
)
1719 if (offset
>= section
->size
)
1722 ret
= (const char *) (section
->start
+ offset
);
1723 /* Unfortunately we cannot rely upon the .debug_str section ending with a
1724 NUL byte. Since our caller is expecting to receive a well formed C
1725 string we test for the lack of a terminating byte here. */
1726 if (strnlen ((const char *) ret
, section
->size
- offset
)
1727 == section
->size
- offset
)
1728 return _("<no NUL byte at end of alt .debug_str section>");
1733 warn (_("DW_FORM_GNU_strp_alt offset (%s) too big or no string sections available\n"),
1734 dwarf_vmatoa ("x", offset
));
1735 return _("<offset is too big>");
1739 get_AT_name (unsigned long attribute
)
1744 return "DW_AT value: 0";
1746 /* One value is shared by the MIPS and HP extensions: */
1747 if (attribute
== DW_AT_MIPS_fde
)
1748 return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable";
1750 name
= get_DW_AT_name (attribute
);
1754 static char buffer
[100];
1756 snprintf (buffer
, sizeof (buffer
), _("Unknown AT value: %lx"),
1765 add_dwo_info (const char * field
, dwo_type type
)
1767 dwo_info
* dwinfo
= xmalloc (sizeof * dwinfo
);
1769 dwinfo
->type
= type
;
1770 dwinfo
->value
= field
;
1771 dwinfo
->next
= first_dwo_info
;
1772 first_dwo_info
= dwinfo
;
1776 add_dwo_name (const char * name
)
1778 add_dwo_info (name
, DWO_NAME
);
1782 add_dwo_dir (const char * dir
)
1784 add_dwo_info (dir
, DWO_DIR
);
1788 add_dwo_id (const char * id
)
1790 add_dwo_info (id
, DWO_ID
);
1794 free_dwo_info (void)
1799 for (dwinfo
= first_dwo_info
; dwinfo
!= NULL
; dwinfo
= next
)
1801 next
= dwinfo
->next
;
1804 first_dwo_info
= NULL
;
1807 /* Ensure that START + UVALUE is less than END.
1808 Return an adjusted UVALUE if necessary to ensure this relationship. */
1810 static inline dwarf_vma
1811 check_uvalue (const unsigned char * start
,
1813 const unsigned char * end
)
1815 dwarf_vma max_uvalue
= end
- start
;
1817 /* See PR 17512: file: 008-103549-0.001:0.1.
1818 and PR 24829 for examples of where these tests are triggered. */
1819 if (uvalue
> max_uvalue
)
1821 warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue
);
1822 uvalue
= max_uvalue
;
1828 static unsigned char *
1829 skip_attr_bytes (unsigned long form
,
1830 unsigned char * data
,
1831 unsigned const char * end
,
1832 dwarf_vma pointer_size
,
1833 dwarf_vma offset_size
,
1835 dwarf_vma
* value_return
)
1837 dwarf_signed_vma svalue
;
1838 dwarf_vma uvalue
= 0;
1844 case DW_FORM_ref_addr
:
1845 if (dwarf_version
== 2)
1846 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1847 else if (dwarf_version
== 3 || dwarf_version
== 4)
1848 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1854 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1858 case DW_FORM_line_strp
:
1859 case DW_FORM_sec_offset
:
1860 case DW_FORM_GNU_ref_alt
:
1861 case DW_FORM_GNU_strp_alt
:
1862 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1865 case DW_FORM_flag_present
:
1872 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1877 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
1882 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1886 READ_SLEB (svalue
, data
, end
);
1890 case DW_FORM_ref_udata
:
1892 case DW_FORM_GNU_str_index
:
1893 case DW_FORM_GNU_addr_index
:
1894 READ_ULEB (uvalue
, data
, end
);
1902 case DW_FORM_data16
:
1906 case DW_FORM_string
:
1907 data
+= strnlen ((char *) data
, end
- data
) + 1;
1911 case DW_FORM_exprloc
:
1912 READ_ULEB (uvalue
, data
, end
);
1915 case DW_FORM_block1
:
1916 SAFE_BYTE_GET (uvalue
, data
, 1, end
);
1920 case DW_FORM_block2
:
1921 SAFE_BYTE_GET (uvalue
, data
, 2, end
);
1925 case DW_FORM_block4
:
1926 SAFE_BYTE_GET (uvalue
, data
, 4, end
);
1930 case DW_FORM_ref_sig8
:
1934 case DW_FORM_indirect
:
1935 /* FIXME: Handle this form. */
1940 * value_return
= uvalue
;
1942 data
= (unsigned char *) end
;
1946 /* Return IS_SIGNED set to TRUE if the type at
1947 DATA can be determined to be a signed type. */
1950 get_type_signedness (unsigned char * start
,
1951 unsigned char * data
,
1952 unsigned const char * end
,
1953 dwarf_vma pointer_size
,
1954 dwarf_vma offset_size
,
1956 bfd_boolean
* is_signed
,
1957 bfd_boolean is_nested
)
1959 unsigned long abbrev_number
;
1960 abbrev_entry
* entry
;
1963 * is_signed
= FALSE
;
1965 READ_ULEB (abbrev_number
, data
, end
);
1967 for (entry
= first_abbrev
;
1968 entry
!= NULL
&& entry
->entry
!= abbrev_number
;
1969 entry
= entry
->next
)
1973 /* FIXME: Issue a warning ? */
1976 for (attr
= entry
->first_attr
;
1977 attr
!= NULL
&& attr
->attribute
;
1980 dwarf_vma uvalue
= 0;
1982 data
= skip_attr_bytes (attr
->form
, data
, end
, pointer_size
,
1983 offset_size
, dwarf_version
, & uvalue
);
1987 switch (attr
->attribute
)
1989 #if 0 /* FIXME: It would be nice to print the name of the type,
1990 but this would mean updating a lot of binutils tests. */
1992 if (attr
->form
== DW_FORM_strp
)
1993 printf ("%s", fetch_indirect_string (uvalue
));
2000 /* FIXME: Warn - or is this expected ?
2001 NB/ We need to avoid infinite recursion. */
2004 if (uvalue
>= (size_t) (end
- start
))
2006 get_type_signedness (start
, start
+ uvalue
, end
, pointer_size
,
2007 offset_size
, dwarf_version
, is_signed
, TRUE
);
2010 case DW_AT_encoding
:
2011 /* Determine signness. */
2014 case DW_ATE_address
:
2015 /* FIXME - some architectures have signed addresses. */
2016 case DW_ATE_boolean
:
2017 case DW_ATE_unsigned
:
2018 case DW_ATE_unsigned_char
:
2019 case DW_ATE_unsigned_fixed
:
2020 * is_signed
= FALSE
;
2024 case DW_ATE_complex_float
:
2027 case DW_ATE_signed_char
:
2028 case DW_ATE_imaginary_float
:
2029 case DW_ATE_decimal_float
:
2030 case DW_ATE_signed_fixed
:
2040 read_and_print_leb128 (unsigned char * data
,
2041 unsigned int * bytes_read
,
2042 unsigned const char * end
,
2043 bfd_boolean is_signed
)
2046 dwarf_vma val
= read_leb128 (data
, end
, is_signed
, bytes_read
, &status
);
2048 report_leb_status (status
, __FILE__
, __LINE__
);
2050 printf ("%s", dwarf_vmatoa (is_signed
? "d" : "u", val
));
2054 display_discr_list (unsigned long form
,
2056 unsigned char * data
,
2057 unsigned const char * end
,
2062 printf ("[default]");
2069 case DW_FORM_block1
:
2070 case DW_FORM_block2
:
2071 case DW_FORM_block4
:
2072 /* Move data pointer back to the start of the byte array. */
2076 printf ("<corrupt>\n");
2077 warn (_("corrupt discr_list - not using a block form\n"));
2083 printf ("<corrupt>\n");
2084 warn (_("corrupt discr_list - block not long enough\n"));
2088 bfd_boolean is_signed
=
2089 (level
> 0 && level
<= MAX_CU_NESTING
)
2090 ? level_type_signed
[level
- 1] : FALSE
;
2095 unsigned char discriminant
;
2096 unsigned int bytes_read
;
2098 SAFE_BYTE_GET (discriminant
, data
, 1, end
);
2102 assert (uvalue
> 0);
2103 switch (discriminant
)
2107 read_and_print_leb128 (data
, & bytes_read
, end
, is_signed
);
2108 assert (bytes_read
<= uvalue
&& bytes_read
> 0);
2109 uvalue
-= bytes_read
;
2115 read_and_print_leb128 (data
, & bytes_read
, end
, is_signed
);
2116 assert (bytes_read
<= uvalue
&& bytes_read
> 0);
2117 uvalue
-= bytes_read
;
2121 read_and_print_leb128 (data
, & bytes_read
, end
, is_signed
);
2122 assert (bytes_read
<= uvalue
&& bytes_read
> 0);
2123 uvalue
-= bytes_read
;
2128 printf ("<corrupt>\n");
2129 warn (_("corrupt discr_list - unrecognised discriminant byte %#x\n"),
2139 printf (")(signed)");
2141 printf (")(unsigned)");
2144 static unsigned char *
2145 read_and_display_attr_value (unsigned long attribute
,
2147 dwarf_signed_vma implicit_const
,
2148 unsigned char * start
,
2149 unsigned char * data
,
2150 unsigned char * end
,
2151 dwarf_vma cu_offset
,
2152 dwarf_vma pointer_size
,
2153 dwarf_vma offset_size
,
2155 debug_info
* debug_info_p
,
2157 struct dwarf_section
* section
,
2158 struct cu_tu_set
* this_set
,
2162 dwarf_signed_vma svalue
;
2163 dwarf_vma uvalue
= 0;
2164 unsigned char * block_start
= NULL
;
2165 unsigned char * orig_data
= data
;
2167 if (data
> end
|| (data
== end
&& form
!= DW_FORM_flag_present
))
2169 warn (_("Corrupt attribute\n"));
2178 case DW_FORM_ref_addr
:
2179 if (dwarf_version
== 2)
2180 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
2181 else if (dwarf_version
== 3 || dwarf_version
== 4)
2182 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
2184 error (_("Internal error: DWARF version is not 2, 3 or 4.\n"));
2189 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
2193 case DW_FORM_line_strp
:
2194 case DW_FORM_sec_offset
:
2195 case DW_FORM_GNU_ref_alt
:
2196 case DW_FORM_GNU_strp_alt
:
2197 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
2200 case DW_FORM_flag_present
:
2207 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
2212 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
2217 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
2221 READ_SLEB (svalue
, data
, end
);
2225 case DW_FORM_GNU_str_index
:
2226 case DW_FORM_ref_udata
:
2228 case DW_FORM_GNU_addr_index
:
2229 READ_ULEB (uvalue
, data
, end
);
2232 case DW_FORM_indirect
:
2233 READ_ULEB (form
, data
, end
);
2235 printf ("%c%s", delimiter
, get_FORM_name (form
));
2236 if (form
== DW_FORM_implicit_const
)
2237 READ_SLEB (implicit_const
, data
, end
);
2238 return read_and_display_attr_value (attribute
, form
, implicit_const
,
2240 cu_offset
, pointer_size
,
2241 offset_size
, dwarf_version
,
2242 debug_info_p
, do_loc
,
2243 section
, this_set
, delimiter
, level
);
2248 case DW_FORM_ref_addr
:
2250 printf ("%c<0x%s>", delimiter
, dwarf_vmatoa ("x",uvalue
));
2253 case DW_FORM_GNU_ref_alt
:
2255 printf ("%c<alt 0x%s>", delimiter
, dwarf_vmatoa ("x",uvalue
));
2256 /* FIXME: Follow the reference... */
2262 case DW_FORM_ref_udata
:
2264 printf ("%c<0x%s>", delimiter
, dwarf_vmatoa ("x", uvalue
+ cu_offset
));
2269 case DW_FORM_sec_offset
:
2271 printf ("%c0x%s", delimiter
, dwarf_vmatoa ("x", uvalue
));
2274 case DW_FORM_flag_present
:
2281 printf ("%c%s", delimiter
, dwarf_vmatoa ("d", uvalue
));
2284 case DW_FORM_implicit_const
:
2286 printf ("%c%s", delimiter
, dwarf_vmatoa ("d", implicit_const
));
2293 dwarf_vma high_bits
;
2297 SAFE_BYTE_GET64 (data
, &high_bits
, &uvalue
, end
);
2299 if (form
== DW_FORM_ref8
)
2300 add64 (& high_bits
, & utmp
, cu_offset
);
2301 printf ("%c0x%s", delimiter
,
2302 dwarf_vmatoa64 (high_bits
, utmp
, buf
, sizeof (buf
)));
2305 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
2306 && num_debug_info_entries
== 0)
2308 if (sizeof (uvalue
) == 8)
2309 SAFE_BYTE_GET (uvalue
, data
, 8, end
);
2311 error (_("DW_FORM_data8 is unsupported when sizeof (dwarf_vma) != 8\n"));
2317 case DW_FORM_data16
:
2320 dwarf_vma left_high_bits
, left_low_bits
;
2321 dwarf_vma right_high_bits
, right_low_bits
;
2323 SAFE_BYTE_GET64 (data
, &left_high_bits
, &left_low_bits
, end
);
2324 SAFE_BYTE_GET64 (data
+ 8, &right_high_bits
, &right_low_bits
, end
);
2325 if (byte_get
== byte_get_little_endian
)
2328 left_high_bits
^= right_high_bits
;
2329 right_high_bits
^= left_high_bits
;
2330 left_high_bits
^= right_high_bits
;
2331 left_low_bits
^= right_low_bits
;
2332 right_low_bits
^= left_low_bits
;
2333 left_low_bits
^= right_low_bits
;
2335 printf (" 0x%08" DWARF_VMA_FMT
"x%08" DWARF_VMA_FMT
"x"
2336 "%08" DWARF_VMA_FMT
"x%08" DWARF_VMA_FMT
"x",
2337 left_high_bits
, left_low_bits
, right_high_bits
,
2343 case DW_FORM_string
:
2345 printf ("%c%.*s", delimiter
, (int) (end
- data
), data
);
2346 data
+= strnlen ((char *) data
, end
- data
) + 1;
2350 case DW_FORM_exprloc
:
2351 READ_ULEB (uvalue
, data
, end
);
2354 if (block_start
>= end
)
2356 warn (_("Block ends prematurely\n"));
2361 uvalue
= check_uvalue (block_start
, uvalue
, end
);
2364 data
= block_start
+ uvalue
;
2366 data
= display_block (block_start
, uvalue
, end
, delimiter
);
2369 case DW_FORM_block1
:
2370 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
2373 case DW_FORM_block2
:
2374 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
2377 case DW_FORM_block4
:
2378 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
2383 printf (_("%c(indirect string, offset: 0x%s): %s"), delimiter
,
2384 dwarf_vmatoa ("x", uvalue
),
2385 fetch_indirect_string (uvalue
));
2388 case DW_FORM_line_strp
:
2390 printf (_("%c(indirect line string, offset: 0x%s): %s"), delimiter
,
2391 dwarf_vmatoa ("x", uvalue
),
2392 fetch_indirect_line_string (uvalue
));
2395 case DW_FORM_GNU_str_index
:
2398 const char * suffix
= strrchr (section
->name
, '.');
2399 bfd_boolean dwo
= (suffix
&& strcmp (suffix
, ".dwo") == 0) ? TRUE
: FALSE
;
2401 printf (_("%c(indexed string: 0x%s): %s"), delimiter
,
2402 dwarf_vmatoa ("x", uvalue
),
2403 fetch_indexed_string (uvalue
, this_set
, offset_size
, dwo
));
2407 case DW_FORM_GNU_strp_alt
:
2410 printf (_("%c(alt indirect string, offset: 0x%s) %s"), delimiter
,
2411 dwarf_vmatoa ("x", uvalue
),
2412 fetch_alt_indirect_string (uvalue
));
2416 case DW_FORM_indirect
:
2417 /* Handled above. */
2420 case DW_FORM_ref_sig8
:
2423 dwarf_vma high_bits
;
2426 SAFE_BYTE_GET64 (data
, &high_bits
, &uvalue
, end
);
2427 printf ("%csignature: 0x%s", delimiter
,
2428 dwarf_vmatoa64 (high_bits
, uvalue
, buf
, sizeof (buf
)));
2433 case DW_FORM_GNU_addr_index
:
2435 printf (_("%c(addr_index: 0x%s): %s"), delimiter
,
2436 dwarf_vmatoa ("x", uvalue
),
2437 fetch_indexed_value (uvalue
* pointer_size
, pointer_size
));
2441 warn (_("Unrecognized form: %lu\n"), form
);
2445 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
2446 && num_debug_info_entries
== 0
2447 && debug_info_p
!= NULL
)
2451 case DW_AT_frame_base
:
2452 have_frame_base
= 1;
2454 case DW_AT_location
:
2455 case DW_AT_GNU_locviews
:
2456 case DW_AT_string_length
:
2457 case DW_AT_return_addr
:
2458 case DW_AT_data_member_location
:
2459 case DW_AT_vtable_elem_location
:
2461 case DW_AT_static_link
:
2462 case DW_AT_use_location
:
2463 case DW_AT_call_value
:
2464 case DW_AT_GNU_call_site_value
:
2465 case DW_AT_call_data_value
:
2466 case DW_AT_GNU_call_site_data_value
:
2467 case DW_AT_call_target
:
2468 case DW_AT_GNU_call_site_target
:
2469 case DW_AT_call_target_clobbered
:
2470 case DW_AT_GNU_call_site_target_clobbered
:
2471 if ((dwarf_version
< 4
2472 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
2473 || form
== DW_FORM_sec_offset
)
2475 /* Process location list. */
2476 unsigned int lmax
= debug_info_p
->max_loc_offsets
;
2477 unsigned int num
= debug_info_p
->num_loc_offsets
;
2479 if (lmax
== 0 || num
>= lmax
)
2482 debug_info_p
->loc_offsets
= (dwarf_vma
*)
2483 xcrealloc (debug_info_p
->loc_offsets
,
2484 lmax
, sizeof (*debug_info_p
->loc_offsets
));
2485 debug_info_p
->loc_views
= (dwarf_vma
*)
2486 xcrealloc (debug_info_p
->loc_views
,
2487 lmax
, sizeof (*debug_info_p
->loc_views
));
2488 debug_info_p
->have_frame_base
= (int *)
2489 xcrealloc (debug_info_p
->have_frame_base
,
2490 lmax
, sizeof (*debug_info_p
->have_frame_base
));
2491 debug_info_p
->max_loc_offsets
= lmax
;
2493 if (this_set
!= NULL
)
2494 uvalue
+= this_set
->section_offsets
[DW_SECT_LOC
];
2495 debug_info_p
->have_frame_base
[num
] = have_frame_base
;
2496 if (attribute
!= DW_AT_GNU_locviews
)
2498 /* Corrupt DWARF info can produce more offsets than views.
2499 See PR 23062 for an example. */
2500 if (debug_info_p
->num_loc_offsets
2501 > debug_info_p
->num_loc_views
)
2502 warn (_("More location offset attributes than DW_AT_GNU_locview attributes\n"));
2505 debug_info_p
->loc_offsets
[num
] = uvalue
;
2506 debug_info_p
->num_loc_offsets
++;
2511 assert (debug_info_p
->num_loc_views
<= num
);
2512 num
= debug_info_p
->num_loc_views
;
2513 if (num
> debug_info_p
->num_loc_offsets
)
2514 warn (_("More DW_AT_GNU_locview attributes than location offset attributes\n"));
2517 debug_info_p
->loc_views
[num
] = uvalue
;
2518 debug_info_p
->num_loc_views
++;
2525 if (need_base_address
)
2526 debug_info_p
->base_address
= uvalue
;
2529 case DW_AT_GNU_addr_base
:
2530 debug_info_p
->addr_base
= uvalue
;
2533 case DW_AT_GNU_ranges_base
:
2534 debug_info_p
->ranges_base
= uvalue
;
2538 if ((dwarf_version
< 4
2539 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
2540 || form
== DW_FORM_sec_offset
)
2542 /* Process range list. */
2543 unsigned int lmax
= debug_info_p
->max_range_lists
;
2544 unsigned int num
= debug_info_p
->num_range_lists
;
2546 if (lmax
== 0 || num
>= lmax
)
2549 debug_info_p
->range_lists
= (dwarf_vma
*)
2550 xcrealloc (debug_info_p
->range_lists
,
2551 lmax
, sizeof (*debug_info_p
->range_lists
));
2552 debug_info_p
->max_range_lists
= lmax
;
2554 debug_info_p
->range_lists
[num
] = uvalue
;
2555 debug_info_p
->num_range_lists
++;
2559 case DW_AT_GNU_dwo_name
:
2560 case DW_AT_dwo_name
:
2565 add_dwo_name ((const char *) fetch_indirect_string (uvalue
));
2567 case DW_FORM_GNU_str_index
:
2568 add_dwo_name (fetch_indexed_string (uvalue
, this_set
, offset_size
, FALSE
));
2570 case DW_FORM_string
:
2571 add_dwo_name ((const char *) orig_data
);
2574 warn (_("Unsupported form (%s) for attribute %s\n"),
2575 get_FORM_name (form
), get_AT_name (attribute
));
2580 case DW_AT_comp_dir
:
2581 /* FIXME: Also extract a build-id in a CU/TU. */
2586 add_dwo_dir ((const char *) fetch_indirect_string (uvalue
));
2588 case DW_FORM_line_strp
:
2589 add_dwo_dir ((const char *) fetch_indirect_line_string (uvalue
));
2591 case DW_FORM_GNU_str_index
:
2592 add_dwo_dir (fetch_indexed_string (uvalue
, this_set
, offset_size
, FALSE
));
2594 case DW_FORM_string
:
2595 add_dwo_dir ((const char *) orig_data
);
2598 warn (_("Unsupported form (%s) for attribute %s\n"),
2599 get_FORM_name (form
), get_AT_name (attribute
));
2604 case DW_AT_GNU_dwo_id
:
2609 /* FIXME: Record the length of the ID as well ? */
2610 add_dwo_id ((const char *) (data
- 8));
2613 warn (_("Unsupported form (%s) for attribute %s\n"),
2614 get_FORM_name (form
), get_AT_name (attribute
));
2624 if (do_loc
|| attribute
== 0)
2627 /* For some attributes we can display further information. */
2631 if (level
>= 0 && level
< MAX_CU_NESTING
2632 && uvalue
< (size_t) (end
- start
))
2634 bfd_boolean is_signed
= FALSE
;
2636 get_type_signedness (start
, start
+ uvalue
, end
, pointer_size
,
2637 offset_size
, dwarf_version
, & is_signed
, FALSE
);
2638 level_type_signed
[level
] = is_signed
;
2646 case DW_INL_not_inlined
:
2647 printf (_("(not inlined)"));
2649 case DW_INL_inlined
:
2650 printf (_("(inlined)"));
2652 case DW_INL_declared_not_inlined
:
2653 printf (_("(declared as inline but ignored)"));
2655 case DW_INL_declared_inlined
:
2656 printf (_("(declared as inline and inlined)"));
2659 printf (_(" (Unknown inline attribute value: %s)"),
2660 dwarf_vmatoa ("x", uvalue
));
2665 case DW_AT_language
:
2669 /* Ordered by the numeric value of these constants. */
2670 case DW_LANG_C89
: printf ("(ANSI C)"); break;
2671 case DW_LANG_C
: printf ("(non-ANSI C)"); break;
2672 case DW_LANG_Ada83
: printf ("(Ada)"); break;
2673 case DW_LANG_C_plus_plus
: printf ("(C++)"); break;
2674 case DW_LANG_Cobol74
: printf ("(Cobol 74)"); break;
2675 case DW_LANG_Cobol85
: printf ("(Cobol 85)"); break;
2676 case DW_LANG_Fortran77
: printf ("(FORTRAN 77)"); break;
2677 case DW_LANG_Fortran90
: printf ("(Fortran 90)"); break;
2678 case DW_LANG_Pascal83
: printf ("(ANSI Pascal)"); break;
2679 case DW_LANG_Modula2
: printf ("(Modula 2)"); break;
2680 /* DWARF 2.1 values. */
2681 case DW_LANG_Java
: printf ("(Java)"); break;
2682 case DW_LANG_C99
: printf ("(ANSI C99)"); break;
2683 case DW_LANG_Ada95
: printf ("(ADA 95)"); break;
2684 case DW_LANG_Fortran95
: printf ("(Fortran 95)"); break;
2685 /* DWARF 3 values. */
2686 case DW_LANG_PLI
: printf ("(PLI)"); break;
2687 case DW_LANG_ObjC
: printf ("(Objective C)"); break;
2688 case DW_LANG_ObjC_plus_plus
: printf ("(Objective C++)"); break;
2689 case DW_LANG_UPC
: printf ("(Unified Parallel C)"); break;
2690 case DW_LANG_D
: printf ("(D)"); break;
2691 /* DWARF 4 values. */
2692 case DW_LANG_Python
: printf ("(Python)"); break;
2693 /* DWARF 5 values. */
2694 case DW_LANG_OpenCL
: printf ("(OpenCL)"); break;
2695 case DW_LANG_Go
: printf ("(Go)"); break;
2696 case DW_LANG_Modula3
: printf ("(Modula 3)"); break;
2697 case DW_LANG_Haskell
: printf ("(Haskell)"); break;
2698 case DW_LANG_C_plus_plus_03
: printf ("(C++03)"); break;
2699 case DW_LANG_C_plus_plus_11
: printf ("(C++11)"); break;
2700 case DW_LANG_OCaml
: printf ("(OCaml)"); break;
2701 case DW_LANG_Rust
: printf ("(Rust)"); break;
2702 case DW_LANG_C11
: printf ("(C11)"); break;
2703 case DW_LANG_Swift
: printf ("(Swift)"); break;
2704 case DW_LANG_Julia
: printf ("(Julia)"); break;
2705 case DW_LANG_Dylan
: printf ("(Dylan)"); break;
2706 case DW_LANG_C_plus_plus_14
: printf ("(C++14)"); break;
2707 case DW_LANG_Fortran03
: printf ("(Fortran 03)"); break;
2708 case DW_LANG_Fortran08
: printf ("(Fortran 08)"); break;
2709 case DW_LANG_RenderScript
: printf ("(RenderScript)"); break;
2710 /* MIPS extension. */
2711 case DW_LANG_Mips_Assembler
: printf ("(MIPS assembler)"); break;
2712 /* UPC extension. */
2713 case DW_LANG_Upc
: printf ("(Unified Parallel C)"); break;
2715 if (uvalue
>= DW_LANG_lo_user
&& uvalue
<= DW_LANG_hi_user
)
2716 printf (_("(implementation defined: %s)"),
2717 dwarf_vmatoa ("x", uvalue
));
2719 printf (_("(Unknown: %s)"), dwarf_vmatoa ("x", uvalue
));
2724 case DW_AT_encoding
:
2728 case DW_ATE_void
: printf ("(void)"); break;
2729 case DW_ATE_address
: printf ("(machine address)"); break;
2730 case DW_ATE_boolean
: printf ("(boolean)"); break;
2731 case DW_ATE_complex_float
: printf ("(complex float)"); break;
2732 case DW_ATE_float
: printf ("(float)"); break;
2733 case DW_ATE_signed
: printf ("(signed)"); break;
2734 case DW_ATE_signed_char
: printf ("(signed char)"); break;
2735 case DW_ATE_unsigned
: printf ("(unsigned)"); break;
2736 case DW_ATE_unsigned_char
: printf ("(unsigned char)"); break;
2737 /* DWARF 2.1 values: */
2738 case DW_ATE_imaginary_float
: printf ("(imaginary float)"); break;
2739 case DW_ATE_decimal_float
: printf ("(decimal float)"); break;
2740 /* DWARF 3 values: */
2741 case DW_ATE_packed_decimal
: printf ("(packed_decimal)"); break;
2742 case DW_ATE_numeric_string
: printf ("(numeric_string)"); break;
2743 case DW_ATE_edited
: printf ("(edited)"); break;
2744 case DW_ATE_signed_fixed
: printf ("(signed_fixed)"); break;
2745 case DW_ATE_unsigned_fixed
: printf ("(unsigned_fixed)"); break;
2746 /* DWARF 4 values: */
2747 case DW_ATE_UTF
: printf ("(unicode string)"); break;
2748 /* DWARF 5 values: */
2749 case DW_ATE_UCS
: printf ("(UCS)"); break;
2750 case DW_ATE_ASCII
: printf ("(ASCII)"); break;
2752 /* HP extensions: */
2753 case DW_ATE_HP_float80
: printf ("(HP_float80)"); break;
2754 case DW_ATE_HP_complex_float80
: printf ("(HP_complex_float80)"); break;
2755 case DW_ATE_HP_float128
: printf ("(HP_float128)"); break;
2756 case DW_ATE_HP_complex_float128
:printf ("(HP_complex_float128)"); break;
2757 case DW_ATE_HP_floathpintel
: printf ("(HP_floathpintel)"); break;
2758 case DW_ATE_HP_imaginary_float80
: printf ("(HP_imaginary_float80)"); break;
2759 case DW_ATE_HP_imaginary_float128
: printf ("(HP_imaginary_float128)"); break;
2762 if (uvalue
>= DW_ATE_lo_user
2763 && uvalue
<= DW_ATE_hi_user
)
2764 printf (_("(user defined type)"));
2766 printf (_("(unknown type)"));
2771 case DW_AT_accessibility
:
2775 case DW_ACCESS_public
: printf ("(public)"); break;
2776 case DW_ACCESS_protected
: printf ("(protected)"); break;
2777 case DW_ACCESS_private
: printf ("(private)"); break;
2779 printf (_("(unknown accessibility)"));
2784 case DW_AT_visibility
:
2788 case DW_VIS_local
: printf ("(local)"); break;
2789 case DW_VIS_exported
: printf ("(exported)"); break;
2790 case DW_VIS_qualified
: printf ("(qualified)"); break;
2791 default: printf (_("(unknown visibility)")); break;
2795 case DW_AT_endianity
:
2799 case DW_END_default
: printf ("(default)"); break;
2800 case DW_END_big
: printf ("(big)"); break;
2801 case DW_END_little
: printf ("(little)"); break;
2803 if (uvalue
>= DW_END_lo_user
&& uvalue
<= DW_END_hi_user
)
2804 printf (_("(user specified)"));
2806 printf (_("(unknown endianity)"));
2811 case DW_AT_virtuality
:
2815 case DW_VIRTUALITY_none
: printf ("(none)"); break;
2816 case DW_VIRTUALITY_virtual
: printf ("(virtual)"); break;
2817 case DW_VIRTUALITY_pure_virtual
:printf ("(pure_virtual)"); break;
2818 default: printf (_("(unknown virtuality)")); break;
2822 case DW_AT_identifier_case
:
2826 case DW_ID_case_sensitive
: printf ("(case_sensitive)"); break;
2827 case DW_ID_up_case
: printf ("(up_case)"); break;
2828 case DW_ID_down_case
: printf ("(down_case)"); break;
2829 case DW_ID_case_insensitive
: printf ("(case_insensitive)"); break;
2830 default: printf (_("(unknown case)")); break;
2834 case DW_AT_calling_convention
:
2838 case DW_CC_normal
: printf ("(normal)"); break;
2839 case DW_CC_program
: printf ("(program)"); break;
2840 case DW_CC_nocall
: printf ("(nocall)"); break;
2841 case DW_CC_pass_by_reference
: printf ("(pass by ref)"); break;
2842 case DW_CC_pass_by_value
: printf ("(pass by value)"); break;
2843 case DW_CC_GNU_renesas_sh
: printf ("(Rensas SH)"); break;
2844 case DW_CC_GNU_borland_fastcall_i386
: printf ("(Borland fastcall i386)"); break;
2846 if (uvalue
>= DW_CC_lo_user
2847 && uvalue
<= DW_CC_hi_user
)
2848 printf (_("(user defined)"));
2850 printf (_("(unknown convention)"));
2854 case DW_AT_ordering
:
2859 case -1: printf (_("(undefined)")); break;
2860 case 0: printf ("(row major)"); break;
2861 case 1: printf ("(column major)"); break;
2865 case DW_AT_decimal_sign
:
2869 case DW_DS_unsigned
: printf (_("(unsigned)")); break;
2870 case DW_DS_leading_overpunch
: printf (_("(leading overpunch)")); break;
2871 case DW_DS_trailing_overpunch
: printf (_("(trailing overpunch)")); break;
2872 case DW_DS_leading_separate
: printf (_("(leading separate)")); break;
2873 case DW_DS_trailing_separate
: printf (_("(trailing separate)")); break;
2874 default: printf (_("(unrecognised)")); break;
2878 case DW_AT_defaulted
:
2882 case DW_DEFAULTED_no
: printf (_("(no)")); break;
2883 case DW_DEFAULTED_in_class
: printf (_("(in class)")); break;
2884 case DW_DEFAULTED_out_of_class
: printf (_("(out of class)")); break;
2885 default: printf (_("(unrecognised)")); break;
2889 case DW_AT_discr_list
:
2891 display_discr_list (form
, uvalue
, data
, end
, level
);
2894 case DW_AT_frame_base
:
2895 have_frame_base
= 1;
2897 case DW_AT_location
:
2898 case DW_AT_string_length
:
2899 case DW_AT_return_addr
:
2900 case DW_AT_data_member_location
:
2901 case DW_AT_vtable_elem_location
:
2903 case DW_AT_static_link
:
2904 case DW_AT_use_location
:
2905 case DW_AT_call_value
:
2906 case DW_AT_GNU_call_site_value
:
2907 case DW_AT_call_data_value
:
2908 case DW_AT_GNU_call_site_data_value
:
2909 case DW_AT_call_target
:
2910 case DW_AT_GNU_call_site_target
:
2911 case DW_AT_call_target_clobbered
:
2912 case DW_AT_GNU_call_site_target_clobbered
:
2913 if ((dwarf_version
< 4
2914 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
2915 || form
== DW_FORM_sec_offset
)
2916 printf (_(" (location list)"));
2918 case DW_AT_allocated
:
2919 case DW_AT_associated
:
2920 case DW_AT_data_location
:
2922 case DW_AT_upper_bound
:
2923 case DW_AT_lower_bound
:
2926 int need_frame_base
;
2929 need_frame_base
= decode_location_expression (block_start
,
2934 cu_offset
, section
);
2936 if (need_frame_base
&& !have_frame_base
)
2937 printf (_(" [without DW_AT_frame_base]"));
2941 case DW_AT_data_bit_offset
:
2942 case DW_AT_byte_size
:
2943 case DW_AT_bit_size
:
2944 case DW_AT_string_length_byte_size
:
2945 case DW_AT_string_length_bit_size
:
2946 case DW_AT_bit_stride
:
2947 if (form
== DW_FORM_exprloc
)
2950 (void) decode_location_expression (block_start
, pointer_size
,
2951 offset_size
, dwarf_version
,
2952 uvalue
, cu_offset
, section
);
2959 if (form
== DW_FORM_ref_sig8
2960 || form
== DW_FORM_GNU_ref_alt
)
2963 if (form
== DW_FORM_ref1
2964 || form
== DW_FORM_ref2
2965 || form
== DW_FORM_ref4
2966 || form
== DW_FORM_ref_udata
)
2967 uvalue
+= cu_offset
;
2969 if (uvalue
>= section
->size
)
2970 warn (_("Offset %s used as value for DW_AT_import attribute of DIE at offset 0x%lx is too big.\n"),
2971 dwarf_vmatoa ("x", uvalue
),
2972 (unsigned long) (orig_data
- section
->start
));
2975 unsigned long abbrev_number
;
2976 abbrev_entry
*entry
;
2977 unsigned char *p
= section
->start
+ uvalue
;
2979 READ_ULEB (abbrev_number
, p
, end
);
2981 printf (_("\t[Abbrev Number: %ld"), abbrev_number
);
2982 /* Don't look up abbrev for DW_FORM_ref_addr, as it very often will
2983 use different abbrev table, and we don't track .debug_info chunks
2985 if (form
!= DW_FORM_ref_addr
)
2987 for (entry
= first_abbrev
; entry
!= NULL
; entry
= entry
->next
)
2988 if (entry
->entry
== abbrev_number
)
2991 printf (" (%s)", get_TAG_name (entry
->tag
));
3005 static unsigned char *
3006 read_and_display_attr (unsigned long attribute
,
3008 dwarf_signed_vma implicit_const
,
3009 unsigned char * start
,
3010 unsigned char * data
,
3011 unsigned char * end
,
3012 dwarf_vma cu_offset
,
3013 dwarf_vma pointer_size
,
3014 dwarf_vma offset_size
,
3016 debug_info
* debug_info_p
,
3018 struct dwarf_section
* section
,
3019 struct cu_tu_set
* this_set
,
3023 printf (" %-18s:", get_AT_name (attribute
));
3024 data
= read_and_display_attr_value (attribute
, form
, implicit_const
,
3026 cu_offset
, pointer_size
, offset_size
,
3027 dwarf_version
, debug_info_p
,
3028 do_loc
, section
, this_set
, ' ', level
);
3034 /* Like load_debug_section, but if the ordinary call fails, and we are
3035 following debug links, then attempt to load the requested section
3036 from one of the separate debug info files. */
3039 load_debug_section_with_follow (enum dwarf_section_display_enum sec_enum
,
3042 if (load_debug_section (sec_enum
, handle
))
3044 if (debug_displays
[sec_enum
].section
.filename
== NULL
)
3046 /* See if we can associate a filename with this section. */
3049 for (i
= first_separate_info
; i
!= NULL
; i
= i
->next
)
3050 if (i
->handle
== handle
)
3052 debug_displays
[sec_enum
].section
.filename
= i
->filename
;
3060 if (do_follow_links
)
3064 for (i
= first_separate_info
; i
!= NULL
; i
= i
->next
)
3066 if (load_debug_section (sec_enum
, i
->handle
))
3068 debug_displays
[sec_enum
].section
.filename
= i
->filename
;
3070 /* FIXME: We should check to see if any of the remaining debug info
3071 files also contain this section, and, umm, do something about it. */
3081 introduce (struct dwarf_section
* section
, bfd_boolean raw
)
3085 if (do_follow_links
&& section
->filename
)
3086 printf (_("Raw dump of debug contents of section %s (loaded from %s):\n\n"),
3087 section
->name
, section
->filename
);
3089 printf (_("Raw dump of debug contents of section %s:\n\n"), section
->name
);
3093 if (do_follow_links
&& section
->filename
)
3094 printf (_("Contents of the %s section (loaded from %s):\n\n"),
3095 section
->name
, section
->filename
);
3097 printf (_("Contents of the %s section:\n\n"), section
->name
);
3101 /* Process the contents of a .debug_info section.
3102 If do_loc is TRUE then we are scanning for location lists and dwo tags
3103 and we do not want to display anything to the user.
3104 If do_types is TRUE, we are processing a .debug_types section instead of
3105 a .debug_info section.
3106 The information displayed is restricted by the values in DWARF_START_DIE
3107 and DWARF_CUTOFF_LEVEL.
3108 Returns TRUE upon success. Otherwise an error or warning message is
3109 printed and FALSE is returned. */
3112 process_debug_info (struct dwarf_section
* section
,
3114 enum dwarf_section_display_enum abbrev_sec
,
3116 bfd_boolean do_types
)
3118 unsigned char *start
= section
->start
;
3119 unsigned char *end
= start
+ section
->size
;
3120 unsigned char *section_begin
;
3122 unsigned int num_units
= 0;
3124 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
3125 && num_debug_info_entries
== 0
3130 /* First scan the section to get the number of comp units. */
3131 for (section_begin
= start
, num_units
= 0; section_begin
< end
;
3134 /* Read the first 4 bytes. For a 32-bit DWARF section, this
3135 will be the length. For a 64-bit DWARF section, it'll be
3136 the escape code 0xffffffff followed by an 8 byte length. */
3137 SAFE_BYTE_GET (length
, section_begin
, 4, end
);
3139 if (length
== 0xffffffff)
3141 SAFE_BYTE_GET (length
, section_begin
+ 4, 8, end
);
3142 section_begin
+= length
+ 12;
3144 else if (length
>= 0xfffffff0 && length
< 0xffffffff)
3146 warn (_("Reserved length value (0x%s) found in section %s\n"),
3147 dwarf_vmatoa ("x", length
), section
->name
);
3151 section_begin
+= length
+ 4;
3153 /* Negative values are illegal, they may even cause infinite
3154 looping. This can happen if we can't accurately apply
3155 relocations to an object file, or if the file is corrupt. */
3156 if ((signed long) length
<= 0 || section_begin
< start
)
3158 warn (_("Corrupt unit length (0x%s) found in section %s\n"),
3159 dwarf_vmatoa ("x", length
), section
->name
);
3166 error (_("No comp units in %s section ?\n"), section
->name
);
3170 /* Then allocate an array to hold the information. */
3171 debug_information
= (debug_info
*) cmalloc (num_units
,
3172 sizeof (* debug_information
));
3173 if (debug_information
== NULL
)
3175 error (_("Not enough memory for a debug info array of %u entries\n"),
3177 alloc_num_debug_info_entries
= num_debug_info_entries
= 0;
3181 /* PR 17531: file: 92ca3797.
3182 We cannot rely upon the debug_information array being initialised
3183 before it is used. A corrupt file could easily contain references
3184 to a unit for which information has not been made available. So
3185 we ensure that the array is zeroed here. */
3186 memset (debug_information
, 0, num_units
* sizeof (*debug_information
));
3188 alloc_num_debug_info_entries
= num_units
;
3193 load_debug_section_with_follow (str
, file
);
3194 load_debug_section_with_follow (line_str
, file
);
3195 load_debug_section_with_follow (str_dwo
, file
);
3196 load_debug_section_with_follow (str_index
, file
);
3197 load_debug_section_with_follow (str_index_dwo
, file
);
3198 load_debug_section_with_follow (debug_addr
, file
);
3201 load_debug_section_with_follow (abbrev_sec
, file
);
3202 if (debug_displays
[abbrev_sec
].section
.start
== NULL
)
3204 warn (_("Unable to locate %s section!\n"),
3205 debug_displays
[abbrev_sec
].section
.uncompressed_name
);
3209 if (!do_loc
&& dwarf_start_die
== 0)
3210 introduce (section
, FALSE
);
3212 for (section_begin
= start
, unit
= 0; start
< end
; unit
++)
3214 DWARF2_Internal_CompUnit compunit
;
3215 unsigned char *hdrptr
;
3216 unsigned char *tags
;
3217 int level
, last_level
, saved_level
;
3218 dwarf_vma cu_offset
;
3219 unsigned long sec_off
;
3220 unsigned int offset_size
;
3221 unsigned int initial_length_size
;
3222 dwarf_vma signature_high
= 0;
3223 dwarf_vma signature_low
= 0;
3224 dwarf_vma type_offset
= 0;
3225 struct cu_tu_set
*this_set
;
3226 dwarf_vma abbrev_base
;
3231 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 4, end
);
3233 if (compunit
.cu_length
== 0xffffffff)
3235 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 8, end
);
3237 initial_length_size
= 12;
3242 initial_length_size
= 4;
3245 SAFE_BYTE_GET_AND_INC (compunit
.cu_version
, hdrptr
, 2, end
);
3247 cu_offset
= start
- section_begin
;
3249 this_set
= find_cu_tu_set_v2 (cu_offset
, do_types
);
3251 if (compunit
.cu_version
< 5)
3253 compunit
.cu_unit_type
= DW_UT_compile
;
3254 /* Initialize it due to a false compiler warning. */
3255 compunit
.cu_pointer_size
= -1;
3259 SAFE_BYTE_GET_AND_INC (compunit
.cu_unit_type
, hdrptr
, 1, end
);
3260 do_types
= (compunit
.cu_unit_type
== DW_UT_type
);
3262 SAFE_BYTE_GET_AND_INC (compunit
.cu_pointer_size
, hdrptr
, 1, end
);
3265 SAFE_BYTE_GET_AND_INC (compunit
.cu_abbrev_offset
, hdrptr
, offset_size
, end
);
3267 if (this_set
== NULL
)
3270 abbrev_size
= debug_displays
[abbrev_sec
].section
.size
;
3274 abbrev_base
= this_set
->section_offsets
[DW_SECT_ABBREV
];
3275 abbrev_size
= this_set
->section_sizes
[DW_SECT_ABBREV
];
3278 if (compunit
.cu_version
< 5)
3279 SAFE_BYTE_GET_AND_INC (compunit
.cu_pointer_size
, hdrptr
, 1, end
);
3281 /* PR 17512: file: 001-108546-0.001:0.1. */
3282 if (compunit
.cu_pointer_size
< 2 || compunit
.cu_pointer_size
> 8)
3284 warn (_("Invalid pointer size (%d) in compunit header, using %d instead\n"),
3285 compunit
.cu_pointer_size
, offset_size
);
3286 compunit
.cu_pointer_size
= offset_size
;
3291 SAFE_BYTE_GET64 (hdrptr
, &signature_high
, &signature_low
, end
);
3293 SAFE_BYTE_GET_AND_INC (type_offset
, hdrptr
, offset_size
, end
);
3296 if (dwarf_start_die
> (cu_offset
+ compunit
.cu_length
3297 + initial_length_size
))
3299 start
= section_begin
+ cu_offset
+ compunit
.cu_length
3300 + initial_length_size
;
3304 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
3305 && num_debug_info_entries
== 0
3306 && alloc_num_debug_info_entries
> unit
3309 debug_information
[unit
].cu_offset
= cu_offset
;
3310 debug_information
[unit
].pointer_size
3311 = compunit
.cu_pointer_size
;
3312 debug_information
[unit
].offset_size
= offset_size
;
3313 debug_information
[unit
].dwarf_version
= compunit
.cu_version
;
3314 debug_information
[unit
].base_address
= 0;
3315 debug_information
[unit
].addr_base
= DEBUG_INFO_UNAVAILABLE
;
3316 debug_information
[unit
].ranges_base
= DEBUG_INFO_UNAVAILABLE
;
3317 debug_information
[unit
].loc_offsets
= NULL
;
3318 debug_information
[unit
].have_frame_base
= NULL
;
3319 debug_information
[unit
].max_loc_offsets
= 0;
3320 debug_information
[unit
].num_loc_offsets
= 0;
3321 debug_information
[unit
].range_lists
= NULL
;
3322 debug_information
[unit
].max_range_lists
= 0;
3323 debug_information
[unit
].num_range_lists
= 0;
3326 if (!do_loc
&& dwarf_start_die
== 0)
3328 printf (_(" Compilation Unit @ offset 0x%s:\n"),
3329 dwarf_vmatoa ("x", cu_offset
));
3330 printf (_(" Length: 0x%s (%s)\n"),
3331 dwarf_vmatoa ("x", compunit
.cu_length
),
3332 offset_size
== 8 ? "64-bit" : "32-bit");
3333 printf (_(" Version: %d\n"), compunit
.cu_version
);
3334 printf (_(" Abbrev Offset: 0x%s\n"),
3335 dwarf_vmatoa ("x", compunit
.cu_abbrev_offset
));
3336 printf (_(" Pointer Size: %d\n"), compunit
.cu_pointer_size
);
3341 printf (_(" Signature: 0x%s\n"),
3342 dwarf_vmatoa64 (signature_high
, signature_low
,
3343 buf
, sizeof (buf
)));
3344 printf (_(" Type Offset: 0x%s\n"),
3345 dwarf_vmatoa ("x", type_offset
));
3347 if (this_set
!= NULL
)
3349 dwarf_vma
*offsets
= this_set
->section_offsets
;
3350 size_t *sizes
= this_set
->section_sizes
;
3352 printf (_(" Section contributions:\n"));
3353 printf (_(" .debug_abbrev.dwo: 0x%s 0x%s\n"),
3354 dwarf_vmatoa ("x", offsets
[DW_SECT_ABBREV
]),
3355 dwarf_vmatoa ("x", sizes
[DW_SECT_ABBREV
]));
3356 printf (_(" .debug_line.dwo: 0x%s 0x%s\n"),
3357 dwarf_vmatoa ("x", offsets
[DW_SECT_LINE
]),
3358 dwarf_vmatoa ("x", sizes
[DW_SECT_LINE
]));
3359 printf (_(" .debug_loc.dwo: 0x%s 0x%s\n"),
3360 dwarf_vmatoa ("x", offsets
[DW_SECT_LOC
]),
3361 dwarf_vmatoa ("x", sizes
[DW_SECT_LOC
]));
3362 printf (_(" .debug_str_offsets.dwo: 0x%s 0x%s\n"),
3363 dwarf_vmatoa ("x", offsets
[DW_SECT_STR_OFFSETS
]),
3364 dwarf_vmatoa ("x", sizes
[DW_SECT_STR_OFFSETS
]));
3368 sec_off
= cu_offset
+ initial_length_size
;
3369 if (sec_off
+ compunit
.cu_length
< sec_off
3370 || sec_off
+ compunit
.cu_length
> section
->size
)
3372 warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"),
3374 (unsigned long) cu_offset
,
3375 dwarf_vmatoa ("x", compunit
.cu_length
));
3381 start
+= compunit
.cu_length
+ initial_length_size
;
3383 if (compunit
.cu_version
< 2 || compunit
.cu_version
> 5)
3385 warn (_("CU at offset %s contains corrupt or "
3386 "unsupported version number: %d.\n"),
3387 dwarf_vmatoa ("x", cu_offset
), compunit
.cu_version
);
3391 if (compunit
.cu_unit_type
!= DW_UT_compile
3392 && compunit
.cu_unit_type
!= DW_UT_type
)
3394 warn (_("CU at offset %s contains corrupt or "
3395 "unsupported unit type: %d.\n"),
3396 dwarf_vmatoa ("x", cu_offset
), compunit
.cu_unit_type
);
3402 /* Process the abbrevs used by this compilation unit. */
3403 if (compunit
.cu_abbrev_offset
>= abbrev_size
)
3404 warn (_("Debug info is corrupted, abbrev offset (%lx) is larger than abbrev section size (%lx)\n"),
3405 (unsigned long) compunit
.cu_abbrev_offset
,
3406 (unsigned long) abbrev_size
);
3407 /* PR 17531: file:4bcd9ce9. */
3408 else if ((abbrev_base
+ abbrev_size
)
3409 > debug_displays
[abbrev_sec
].section
.size
)
3410 warn (_("Debug info is corrupted, abbrev size (%lx) is larger than abbrev section size (%lx)\n"),
3411 (unsigned long) abbrev_base
+ abbrev_size
,
3412 (unsigned long) debug_displays
[abbrev_sec
].section
.size
);
3414 process_abbrev_section
3415 (((unsigned char *) debug_displays
[abbrev_sec
].section
.start
3416 + abbrev_base
+ compunit
.cu_abbrev_offset
),
3417 ((unsigned char *) debug_displays
[abbrev_sec
].section
.start
3418 + abbrev_base
+ abbrev_size
));
3423 while (tags
< start
)
3425 unsigned long abbrev_number
;
3426 unsigned long die_offset
;
3427 abbrev_entry
*entry
;
3429 int do_printing
= 1;
3431 die_offset
= tags
- section_begin
;
3433 READ_ULEB (abbrev_number
, tags
, start
);
3435 /* A null DIE marks the end of a list of siblings or it may also be
3436 a section padding. */
3437 if (abbrev_number
== 0)
3439 /* Check if it can be a section padding for the last CU. */
3440 if (level
== 0 && start
== end
)
3444 for (chk
= tags
; chk
< start
; chk
++)
3451 if (!do_loc
&& die_offset
>= dwarf_start_die
3452 && (dwarf_cutoff_level
== -1
3453 || level
< dwarf_cutoff_level
))
3454 printf (_(" <%d><%lx>: Abbrev Number: 0\n"),
3460 static unsigned num_bogus_warns
= 0;
3462 if (num_bogus_warns
< 3)
3464 warn (_("Bogus end-of-siblings marker detected at offset %lx in %s section\n"),
3465 die_offset
, section
->name
);
3467 if (num_bogus_warns
== 3)
3468 warn (_("Further warnings about bogus end-of-sibling markers suppressed\n"));
3471 if (dwarf_start_die
!= 0 && level
< saved_level
)
3478 if (dwarf_start_die
!= 0 && die_offset
< dwarf_start_die
)
3482 if (dwarf_start_die
!= 0 && die_offset
== dwarf_start_die
)
3483 saved_level
= level
;
3484 do_printing
= (dwarf_cutoff_level
== -1
3485 || level
< dwarf_cutoff_level
);
3487 printf (_(" <%d><%lx>: Abbrev Number: %lu"),
3488 level
, die_offset
, abbrev_number
);
3489 else if (dwarf_cutoff_level
== -1
3490 || last_level
< dwarf_cutoff_level
)
3491 printf (_(" <%d><%lx>: ...\n"), level
, die_offset
);
3496 /* Scan through the abbreviation list until we reach the
3498 for (entry
= first_abbrev
;
3499 entry
&& entry
->entry
!= abbrev_number
;
3500 entry
= entry
->next
)
3505 if (!do_loc
&& do_printing
)
3510 warn (_("DIE at offset 0x%lx refers to abbreviation number %lu which does not exist\n"),
3511 die_offset
, abbrev_number
);
3515 if (!do_loc
&& do_printing
)
3516 printf (" (%s)\n", get_TAG_name (entry
->tag
));
3521 need_base_address
= 0;
3523 case DW_TAG_compile_unit
:
3524 need_base_address
= 1;
3525 need_dwo_info
= do_loc
;
3527 case DW_TAG_entry_point
:
3528 case DW_TAG_subprogram
:
3529 need_base_address
= 0;
3530 /* Assuming that there is no DW_AT_frame_base. */
3531 have_frame_base
= 0;
3535 debug_info
*debug_info_p
=
3536 (debug_information
&& unit
< alloc_num_debug_info_entries
)
3537 ? debug_information
+ unit
: NULL
;
3539 assert (!debug_info_p
3540 || (debug_info_p
->num_loc_offsets
3541 == debug_info_p
->num_loc_views
));
3543 for (attr
= entry
->first_attr
;
3544 attr
&& attr
->attribute
;
3547 if (! do_loc
&& do_printing
)
3548 /* Show the offset from where the tag was extracted. */
3549 printf (" <%lx>", (unsigned long)(tags
- section_begin
));
3550 tags
= read_and_display_attr (attr
->attribute
,
3552 attr
->implicit_const
,
3557 compunit
.cu_pointer_size
,
3559 compunit
.cu_version
,
3561 do_loc
|| ! do_printing
,
3567 /* If a locview attribute appears before a location one,
3568 make sure we don't associate it with an earlier
3571 switch (debug_info_p
->num_loc_offsets
- debug_info_p
->num_loc_views
)
3574 debug_info_p
->loc_views
[debug_info_p
->num_loc_views
] = vm1
;
3575 debug_info_p
->num_loc_views
++;
3576 assert (debug_info_p
->num_loc_views
3577 == debug_info_p
->num_loc_offsets
);
3584 warn(_("DIE has locviews without loclist\n"));
3585 debug_info_p
->num_loc_views
--;
3592 if (entry
->children
)
3597 /* Set num_debug_info_entries here so that it can be used to check if
3598 we need to process .debug_loc and .debug_ranges sections. */
3599 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
3600 && num_debug_info_entries
== 0
3603 if (num_units
> alloc_num_debug_info_entries
)
3604 num_debug_info_entries
= alloc_num_debug_info_entries
;
3606 num_debug_info_entries
= num_units
;
3615 /* Locate and scan the .debug_info section in the file and record the pointer
3616 sizes and offsets for the compilation units in it. Usually an executable
3617 will have just one pointer size, but this is not guaranteed, and so we try
3618 not to make any assumptions. Returns zero upon failure, or the number of
3619 compilation units upon success. */
3622 load_debug_info (void * file
)
3624 /* If we have already tried and failed to load the .debug_info
3625 section then do not bother to repeat the task. */
3626 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
3629 /* If we already have the information there is nothing else to do. */
3630 if (num_debug_info_entries
> 0)
3631 return num_debug_info_entries
;
3633 /* If this is a DWARF package file, load the CU and TU indexes. */
3634 (void) load_cu_tu_indexes (file
);
3636 if (load_debug_section_with_follow (info
, file
)
3637 && process_debug_info (&debug_displays
[info
].section
, file
, abbrev
, TRUE
, FALSE
))
3638 return num_debug_info_entries
;
3640 if (load_debug_section_with_follow (info_dwo
, file
)
3641 && process_debug_info (&debug_displays
[info_dwo
].section
, file
,
3642 abbrev_dwo
, TRUE
, FALSE
))
3643 return num_debug_info_entries
;
3645 num_debug_info_entries
= DEBUG_INFO_UNAVAILABLE
;
3649 /* Read a DWARF .debug_line section header starting at DATA.
3650 Upon success returns an updated DATA pointer and the LINFO
3651 structure and the END_OF_SEQUENCE pointer will be filled in.
3652 Otherwise returns NULL. */
3654 static unsigned char *
3655 read_debug_line_header (struct dwarf_section
* section
,
3656 unsigned char * data
,
3657 unsigned char * end
,
3658 DWARF2_Internal_LineInfo
* linfo
,
3659 unsigned char ** end_of_sequence
)
3661 unsigned char *hdrptr
;
3662 unsigned int initial_length_size
;
3664 /* Extract information from the Line Number Program Header.
3665 (section 6.2.4 in the Dwarf3 doc). */
3668 /* Get and check the length of the block. */
3669 SAFE_BYTE_GET_AND_INC (linfo
->li_length
, hdrptr
, 4, end
);
3671 if (linfo
->li_length
== 0xffffffff)
3673 /* This section is 64-bit DWARF 3. */
3674 SAFE_BYTE_GET_AND_INC (linfo
->li_length
, hdrptr
, 8, end
);
3675 linfo
->li_offset_size
= 8;
3676 initial_length_size
= 12;
3680 linfo
->li_offset_size
= 4;
3681 initial_length_size
= 4;
3684 if (linfo
->li_length
+ initial_length_size
> section
->size
)
3686 /* If the length field has a relocation against it, then we should
3687 not complain if it is inaccurate (and probably negative). This
3688 happens in object files when the .debug_line section is actually
3689 comprised of several different .debug_line.* sections, (some of
3690 which may be removed by linker garbage collection), and a relocation
3691 is used to compute the correct length once that is done. */
3692 if (reloc_at (section
, (hdrptr
- section
->start
) - linfo
->li_offset_size
))
3694 linfo
->li_length
= (end
- data
) - initial_length_size
;
3698 warn (_("The length field (0x%lx) in the debug_line header is wrong - the section is too small\n"),
3699 (long) linfo
->li_length
);
3704 /* Get and check the version number. */
3705 SAFE_BYTE_GET_AND_INC (linfo
->li_version
, hdrptr
, 2, end
);
3707 if (linfo
->li_version
!= 2
3708 && linfo
->li_version
!= 3
3709 && linfo
->li_version
!= 4
3710 && linfo
->li_version
!= 5)
3712 warn (_("Only DWARF version 2, 3, 4 and 5 line info "
3713 "is currently supported.\n"));
3717 if (linfo
->li_version
>= 5)
3719 SAFE_BYTE_GET_AND_INC (linfo
->li_address_size
, hdrptr
, 1, end
);
3721 SAFE_BYTE_GET_AND_INC (linfo
->li_segment_size
, hdrptr
, 1, end
);
3722 if (linfo
->li_segment_size
!= 0)
3724 warn (_("The %s section contains "
3725 "unsupported segment selector size: %d.\n"),
3726 section
->name
, linfo
->li_segment_size
);
3731 SAFE_BYTE_GET_AND_INC (linfo
->li_prologue_length
, hdrptr
,
3732 linfo
->li_offset_size
, end
);
3733 SAFE_BYTE_GET_AND_INC (linfo
->li_min_insn_length
, hdrptr
, 1, end
);
3735 if (linfo
->li_version
>= 4)
3737 SAFE_BYTE_GET_AND_INC (linfo
->li_max_ops_per_insn
, hdrptr
, 1, end
);
3739 if (linfo
->li_max_ops_per_insn
== 0)
3741 warn (_("Invalid maximum operations per insn.\n"));
3746 linfo
->li_max_ops_per_insn
= 1;
3748 SAFE_BYTE_GET_AND_INC (linfo
->li_default_is_stmt
, hdrptr
, 1, end
);
3749 SAFE_SIGNED_BYTE_GET_AND_INC (linfo
->li_line_base
, hdrptr
, 1, end
);
3750 SAFE_BYTE_GET_AND_INC (linfo
->li_line_range
, hdrptr
, 1, end
);
3751 SAFE_BYTE_GET_AND_INC (linfo
->li_opcode_base
, hdrptr
, 1, end
);
3753 * end_of_sequence
= data
+ linfo
->li_length
+ initial_length_size
;
3754 /* PR 17512: file:002-117414-0.004. */
3755 if (* end_of_sequence
> end
)
3757 warn (_("Line length %s extends beyond end of section\n"),
3758 dwarf_vmatoa ("u", linfo
->li_length
));
3759 * end_of_sequence
= end
;
3766 static unsigned char *
3767 display_formatted_table (unsigned char * data
,
3768 unsigned char * start
,
3769 unsigned char * end
,
3770 const DWARF2_Internal_LineInfo
* linfo
,
3771 struct dwarf_section
* section
,
3774 unsigned char *format_start
, format_count
, *format
, formati
;
3775 dwarf_vma data_count
, datai
;
3776 unsigned int namepass
, last_entry
= 0;
3777 const char * table_name
= is_dir
? N_("Directory Table") : N_("File Name Table");
3779 SAFE_BYTE_GET_AND_INC (format_count
, data
, 1, end
);
3780 if (do_checks
&& format_count
> 5)
3781 warn (_("Unexpectedly large number of columns in the %s (%u)\n"),
3782 table_name
, format_count
);
3784 format_start
= data
;
3785 for (formati
= 0; formati
< format_count
; formati
++)
3787 SKIP_ULEB (data
, end
);
3788 SKIP_ULEB (data
, end
);
3791 warn (_("%s: Corrupt format description entry\n"), table_name
);
3796 READ_ULEB (data_count
, data
, end
);
3797 if (data_count
== 0)
3799 printf (_("\n The %s is empty.\n"), table_name
);
3802 else if (data
== end
)
3804 warn (_("%s: Corrupt entry count - expected %s but none found\n"),
3805 table_name
, dwarf_vmatoa ("x", data_count
));
3809 else if (format_count
== 0)
3811 warn (_("%s: format count is zero, but the table is not empty\n"),
3816 printf (_("\n The %s (offset 0x%lx, lines %s, columns %u):\n"),
3817 table_name
, (long) (data
- start
), dwarf_vmatoa ("u", data_count
),
3820 printf (_(" Entry"));
3821 /* Delay displaying name as the last entry for better screen layout. */
3822 for (namepass
= 0; namepass
< 2; namepass
++)
3824 format
= format_start
;
3825 for (formati
= 0; formati
< format_count
; formati
++)
3827 dwarf_vma content_type
;
3829 READ_ULEB (content_type
, format
, end
);
3830 if ((content_type
== DW_LNCT_path
) == (namepass
== 1))
3831 switch (content_type
)
3834 printf (_("\tName"));
3836 case DW_LNCT_directory_index
:
3837 printf (_("\tDir"));
3839 case DW_LNCT_timestamp
:
3840 printf (_("\tTime"));
3843 printf (_("\tSize"));
3846 printf (_("\tMD5\t\t\t"));
3849 printf (_("\t(Unknown format content type %s)"),
3850 dwarf_vmatoa ("u", content_type
));
3852 SKIP_ULEB (format
, end
);
3857 for (datai
= 0; datai
< data_count
; datai
++)
3859 unsigned char *datapass
= data
;
3861 printf (" %d", last_entry
++);
3862 /* Delay displaying name as the last entry for better screen layout. */
3863 for (namepass
= 0; namepass
< 2; namepass
++)
3865 format
= format_start
;
3867 for (formati
= 0; formati
< format_count
; formati
++)
3869 dwarf_vma content_type
, form
;
3871 READ_ULEB (content_type
, format
, end
);
3872 READ_ULEB (form
, format
, end
);
3873 data
= read_and_display_attr_value (0, form
, 0, start
, data
, end
,
3874 0, 0, linfo
->li_offset_size
,
3875 linfo
->li_version
, NULL
,
3876 ((content_type
== DW_LNCT_path
) != (namepass
== 1)),
3877 section
, NULL
, '\t', -1);
3881 if (data
== end
&& (datai
< data_count
- 1))
3883 warn (_("\n%s: Corrupt entries list\n"), table_name
);
3892 display_debug_lines_raw (struct dwarf_section
* section
,
3893 unsigned char * data
,
3894 unsigned char * end
,
3897 unsigned char *start
= section
->start
;
3898 int verbose_view
= 0;
3900 introduce (section
, TRUE
);
3904 static DWARF2_Internal_LineInfo saved_linfo
;
3905 DWARF2_Internal_LineInfo linfo
;
3906 unsigned char *standard_opcodes
;
3907 unsigned char *end_of_sequence
;
3910 if (const_strneq (section
->name
, ".debug_line.")
3911 /* Note: the following does not apply to .debug_line.dwo sections.
3912 These are full debug_line sections. */
3913 && strcmp (section
->name
, ".debug_line.dwo") != 0)
3915 /* Sections named .debug_line.<foo> are fragments of a .debug_line
3916 section containing just the Line Number Statements. They are
3917 created by the assembler and intended to be used alongside gcc's
3918 -ffunction-sections command line option. When the linker's
3919 garbage collection decides to discard a .text.<foo> section it
3920 can then also discard the line number information in .debug_line.<foo>.
3922 Since the section is a fragment it does not have the details
3923 needed to fill out a LineInfo structure, so instead we use the
3924 details from the last full debug_line section that we processed. */
3925 end_of_sequence
= end
;
3926 standard_opcodes
= NULL
;
3927 linfo
= saved_linfo
;
3928 /* PR 17531: file: 0522b371. */
3929 if (linfo
.li_line_range
== 0)
3931 warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n"));
3934 reset_state_machine (linfo
.li_default_is_stmt
);
3938 unsigned char * hdrptr
;
3940 if ((hdrptr
= read_debug_line_header (section
, data
, end
, & linfo
,
3941 & end_of_sequence
)) == NULL
)
3944 printf (_(" Offset: 0x%lx\n"), (long)(data
- start
));
3945 printf (_(" Length: %ld\n"), (long) linfo
.li_length
);
3946 printf (_(" DWARF Version: %d\n"), linfo
.li_version
);
3947 if (linfo
.li_version
>= 5)
3949 printf (_(" Address size (bytes): %d\n"), linfo
.li_address_size
);
3950 printf (_(" Segment selector (bytes): %d\n"), linfo
.li_segment_size
);
3952 printf (_(" Prologue Length: %d\n"), (int) linfo
.li_prologue_length
);
3953 printf (_(" Minimum Instruction Length: %d\n"), linfo
.li_min_insn_length
);
3954 if (linfo
.li_version
>= 4)
3955 printf (_(" Maximum Ops per Instruction: %d\n"), linfo
.li_max_ops_per_insn
);
3956 printf (_(" Initial value of 'is_stmt': %d\n"), linfo
.li_default_is_stmt
);
3957 printf (_(" Line Base: %d\n"), linfo
.li_line_base
);
3958 printf (_(" Line Range: %d\n"), linfo
.li_line_range
);
3959 printf (_(" Opcode Base: %d\n"), linfo
.li_opcode_base
);
3961 /* PR 17512: file: 1665-6428-0.004. */
3962 if (linfo
.li_line_range
== 0)
3964 warn (_("Line range of 0 is invalid, using 1 instead\n"));
3965 linfo
.li_line_range
= 1;
3968 reset_state_machine (linfo
.li_default_is_stmt
);
3970 /* Display the contents of the Opcodes table. */
3971 standard_opcodes
= hdrptr
;
3973 /* PR 17512: file: 002-417945-0.004. */
3974 if (standard_opcodes
+ linfo
.li_opcode_base
>= end
)
3976 warn (_("Line Base extends beyond end of section\n"));
3980 printf (_("\n Opcodes:\n"));
3982 for (i
= 1; i
< linfo
.li_opcode_base
; i
++)
3983 printf (ngettext (" Opcode %d has %d arg\n",
3984 " Opcode %d has %d args\n",
3985 standard_opcodes
[i
- 1]),
3986 i
, standard_opcodes
[i
- 1]);
3988 /* Display the contents of the Directory table. */
3989 data
= standard_opcodes
+ linfo
.li_opcode_base
- 1;
3991 if (linfo
.li_version
>= 5)
3993 load_debug_section_with_follow (line_str
, file
);
3995 data
= display_formatted_table (data
, start
, end
, &linfo
, section
,
3997 data
= display_formatted_table (data
, start
, end
, &linfo
, section
,
4003 printf (_("\n The Directory Table is empty.\n"));
4006 unsigned int last_dir_entry
= 0;
4008 printf (_("\n The Directory Table (offset 0x%lx):\n"),
4009 (long)(data
- start
));
4011 while (data
< end
&& *data
!= 0)
4013 printf (" %d\t%.*s\n", ++last_dir_entry
, (int) (end
- data
), data
);
4015 data
+= strnlen ((char *) data
, end
- data
) + 1;
4018 /* PR 17512: file: 002-132094-0.004. */
4019 if (data
>= end
- 1)
4023 /* Skip the NUL at the end of the table. */
4026 /* Display the contents of the File Name table. */
4028 printf (_("\n The File Name Table is empty.\n"));
4031 printf (_("\n The File Name Table (offset 0x%lx):\n"),
4032 (long)(data
- start
));
4033 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
4035 while (data
< end
&& *data
!= 0)
4037 unsigned char *name
;
4040 printf (" %d\t", ++state_machine_regs
.last_file_entry
);
4042 data
+= strnlen ((char *) data
, end
- data
) + 1;
4044 READ_ULEB (val
, data
, end
);
4045 printf ("%s\t", dwarf_vmatoa ("u", val
));
4046 READ_ULEB (val
, data
, end
);
4047 printf ("%s\t", dwarf_vmatoa ("u", val
));
4048 READ_ULEB (val
, data
, end
);
4049 printf ("%s\t", dwarf_vmatoa ("u", val
));
4050 printf ("%.*s\n", (int)(end
- name
), name
);
4054 warn (_("Corrupt file name table entry\n"));
4060 /* Skip the NUL at the end of the table. */
4065 saved_linfo
= linfo
;
4068 /* Now display the statements. */
4069 if (data
>= end_of_sequence
)
4070 printf (_(" No Line Number Statements.\n"));
4073 printf (_(" Line Number Statements:\n"));
4075 while (data
< end_of_sequence
)
4077 unsigned char op_code
;
4078 dwarf_signed_vma adv
;
4081 printf (" [0x%08lx]", (long)(data
- start
));
4085 if (op_code
>= linfo
.li_opcode_base
)
4087 op_code
-= linfo
.li_opcode_base
;
4088 uladv
= (op_code
/ linfo
.li_line_range
);
4089 if (linfo
.li_max_ops_per_insn
== 1)
4091 uladv
*= linfo
.li_min_insn_length
;
4092 state_machine_regs
.address
+= uladv
;
4094 state_machine_regs
.view
= 0;
4095 printf (_(" Special opcode %d: "
4096 "advance Address by %s to 0x%s%s"),
4097 op_code
, dwarf_vmatoa ("u", uladv
),
4098 dwarf_vmatoa ("x", state_machine_regs
.address
),
4099 verbose_view
&& uladv
4100 ? _(" (reset view)") : "");
4105 = ((state_machine_regs
.op_index
+ uladv
)
4106 / linfo
.li_max_ops_per_insn
)
4107 * linfo
.li_min_insn_length
;
4109 state_machine_regs
.address
+= addrdelta
;
4110 state_machine_regs
.op_index
4111 = (state_machine_regs
.op_index
+ uladv
)
4112 % linfo
.li_max_ops_per_insn
;
4114 state_machine_regs
.view
= 0;
4115 printf (_(" Special opcode %d: "
4116 "advance Address by %s to 0x%s[%d]%s"),
4117 op_code
, dwarf_vmatoa ("u", uladv
),
4118 dwarf_vmatoa ("x", state_machine_regs
.address
),
4119 state_machine_regs
.op_index
,
4120 verbose_view
&& addrdelta
4121 ? _(" (reset view)") : "");
4123 adv
= (op_code
% linfo
.li_line_range
) + linfo
.li_line_base
;
4124 state_machine_regs
.line
+= adv
;
4125 printf (_(" and Line by %s to %d"),
4126 dwarf_vmatoa ("d", adv
), state_machine_regs
.line
);
4127 if (verbose_view
|| state_machine_regs
.view
)
4128 printf (_(" (view %u)\n"), state_machine_regs
.view
);
4131 state_machine_regs
.view
++;
4136 case DW_LNS_extended_op
:
4137 data
+= process_extended_line_op (data
,
4138 linfo
.li_default_is_stmt
,
4143 printf (_(" Copy"));
4144 if (verbose_view
|| state_machine_regs
.view
)
4145 printf (_(" (view %u)\n"), state_machine_regs
.view
);
4148 state_machine_regs
.view
++;
4151 case DW_LNS_advance_pc
:
4152 READ_ULEB (uladv
, data
, end
);
4153 if (linfo
.li_max_ops_per_insn
== 1)
4155 uladv
*= linfo
.li_min_insn_length
;
4156 state_machine_regs
.address
+= uladv
;
4158 state_machine_regs
.view
= 0;
4159 printf (_(" Advance PC by %s to 0x%s%s\n"),
4160 dwarf_vmatoa ("u", uladv
),
4161 dwarf_vmatoa ("x", state_machine_regs
.address
),
4162 verbose_view
&& uladv
4163 ? _(" (reset view)") : "");
4168 = ((state_machine_regs
.op_index
+ uladv
)
4169 / linfo
.li_max_ops_per_insn
)
4170 * linfo
.li_min_insn_length
;
4171 state_machine_regs
.address
4173 state_machine_regs
.op_index
4174 = (state_machine_regs
.op_index
+ uladv
)
4175 % linfo
.li_max_ops_per_insn
;
4177 state_machine_regs
.view
= 0;
4178 printf (_(" Advance PC by %s to 0x%s[%d]%s\n"),
4179 dwarf_vmatoa ("u", uladv
),
4180 dwarf_vmatoa ("x", state_machine_regs
.address
),
4181 state_machine_regs
.op_index
,
4182 verbose_view
&& addrdelta
4183 ? _(" (reset view)") : "");
4187 case DW_LNS_advance_line
:
4188 READ_SLEB (adv
, data
, end
);
4189 state_machine_regs
.line
+= adv
;
4190 printf (_(" Advance Line by %s to %d\n"),
4191 dwarf_vmatoa ("d", adv
),
4192 state_machine_regs
.line
);
4195 case DW_LNS_set_file
:
4196 READ_ULEB (uladv
, data
, end
);
4197 printf (_(" Set File Name to entry %s in the File Name Table\n"),
4198 dwarf_vmatoa ("u", uladv
));
4199 state_machine_regs
.file
= uladv
;
4202 case DW_LNS_set_column
:
4203 READ_ULEB (uladv
, data
, end
);
4204 printf (_(" Set column to %s\n"),
4205 dwarf_vmatoa ("u", uladv
));
4206 state_machine_regs
.column
= uladv
;
4209 case DW_LNS_negate_stmt
:
4210 adv
= state_machine_regs
.is_stmt
;
4212 printf (_(" Set is_stmt to %s\n"), dwarf_vmatoa ("d", adv
));
4213 state_machine_regs
.is_stmt
= adv
;
4216 case DW_LNS_set_basic_block
:
4217 printf (_(" Set basic block\n"));
4218 state_machine_regs
.basic_block
= 1;
4221 case DW_LNS_const_add_pc
:
4222 uladv
= ((255 - linfo
.li_opcode_base
) / linfo
.li_line_range
);
4223 if (linfo
.li_max_ops_per_insn
)
4225 uladv
*= linfo
.li_min_insn_length
;
4226 state_machine_regs
.address
+= uladv
;
4228 state_machine_regs
.view
= 0;
4229 printf (_(" Advance PC by constant %s to 0x%s%s\n"),
4230 dwarf_vmatoa ("u", uladv
),
4231 dwarf_vmatoa ("x", state_machine_regs
.address
),
4232 verbose_view
&& uladv
4233 ? _(" (reset view)") : "");
4238 = ((state_machine_regs
.op_index
+ uladv
)
4239 / linfo
.li_max_ops_per_insn
)
4240 * linfo
.li_min_insn_length
;
4241 state_machine_regs
.address
4243 state_machine_regs
.op_index
4244 = (state_machine_regs
.op_index
+ uladv
)
4245 % linfo
.li_max_ops_per_insn
;
4247 state_machine_regs
.view
= 0;
4248 printf (_(" Advance PC by constant %s to 0x%s[%d]%s\n"),
4249 dwarf_vmatoa ("u", uladv
),
4250 dwarf_vmatoa ("x", state_machine_regs
.address
),
4251 state_machine_regs
.op_index
,
4252 verbose_view
&& addrdelta
4253 ? _(" (reset view)") : "");
4257 case DW_LNS_fixed_advance_pc
:
4258 SAFE_BYTE_GET_AND_INC (uladv
, data
, 2, end
);
4259 state_machine_regs
.address
+= uladv
;
4260 state_machine_regs
.op_index
= 0;
4261 printf (_(" Advance PC by fixed size amount %s to 0x%s\n"),
4262 dwarf_vmatoa ("u", uladv
),
4263 dwarf_vmatoa ("x", state_machine_regs
.address
));
4264 /* Do NOT reset view. */
4267 case DW_LNS_set_prologue_end
:
4268 printf (_(" Set prologue_end to true\n"));
4271 case DW_LNS_set_epilogue_begin
:
4272 printf (_(" Set epilogue_begin to true\n"));
4275 case DW_LNS_set_isa
:
4276 READ_ULEB (uladv
, data
, end
);
4277 printf (_(" Set ISA to %s\n"), dwarf_vmatoa ("u", uladv
));
4281 printf (_(" Unknown opcode %d with operands: "), op_code
);
4283 if (standard_opcodes
!= NULL
)
4284 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
4286 READ_ULEB (uladv
, data
, end
);
4287 printf ("0x%s%s", dwarf_vmatoa ("x", uladv
),
4288 i
== 1 ? "" : ", ");
4303 unsigned char *name
;
4304 unsigned int directory_index
;
4305 unsigned int modification_date
;
4306 unsigned int length
;
4309 /* Output a decoded representation of the .debug_line section. */
4312 display_debug_lines_decoded (struct dwarf_section
* section
,
4313 unsigned char * start
,
4314 unsigned char * data
,
4315 unsigned char * end
,
4318 static DWARF2_Internal_LineInfo saved_linfo
;
4320 introduce (section
, FALSE
);
4324 /* This loop amounts to one iteration per compilation unit. */
4325 DWARF2_Internal_LineInfo linfo
;
4326 unsigned char *standard_opcodes
;
4327 unsigned char *end_of_sequence
;
4329 File_Entry
*file_table
= NULL
;
4330 unsigned int n_files
= 0;
4331 unsigned char **directory_table
= NULL
;
4332 dwarf_vma n_directories
= 0;
4334 if (const_strneq (section
->name
, ".debug_line.")
4335 /* Note: the following does not apply to .debug_line.dwo sections.
4336 These are full debug_line sections. */
4337 && strcmp (section
->name
, ".debug_line.dwo") != 0)
4339 /* See comment in display_debug_lines_raw(). */
4340 end_of_sequence
= end
;
4341 standard_opcodes
= NULL
;
4342 linfo
= saved_linfo
;
4343 /* PR 17531: file: 0522b371. */
4344 if (linfo
.li_line_range
== 0)
4346 warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n"));
4349 reset_state_machine (linfo
.li_default_is_stmt
);
4353 unsigned char *hdrptr
;
4355 if ((hdrptr
= read_debug_line_header (section
, data
, end
, & linfo
,
4356 & end_of_sequence
)) == NULL
)
4359 /* PR 17531: file: 0522b371. */
4360 if (linfo
.li_line_range
== 0)
4362 warn (_("Line range of 0 is invalid, using 1 instead\n"));
4363 linfo
.li_line_range
= 1;
4365 reset_state_machine (linfo
.li_default_is_stmt
);
4367 /* Save a pointer to the contents of the Opcodes table. */
4368 standard_opcodes
= hdrptr
;
4370 /* Traverse the Directory table just to count entries. */
4371 data
= standard_opcodes
+ linfo
.li_opcode_base
- 1;
4375 warn (_("opcode base of %d extends beyond end of section\n"),
4376 linfo
.li_opcode_base
);
4380 if (linfo
.li_version
>= 5)
4382 unsigned char *format_start
, format_count
, *format
;
4383 dwarf_vma formati
, entryi
;
4385 load_debug_section_with_follow (line_str
, fileptr
);
4387 /* Skip directories format. */
4388 SAFE_BYTE_GET_AND_INC (format_count
, data
, 1, end
);
4389 if (do_checks
&& format_count
> 1)
4390 warn (_("Unexpectedly large number of columns in the directory name table (%u)\n"),
4392 format_start
= data
;
4393 for (formati
= 0; formati
< format_count
; formati
++)
4395 SKIP_ULEB (data
, end
);
4396 SKIP_ULEB (data
, end
);
4399 READ_ULEB (n_directories
, data
, end
);
4402 warn (_("Corrupt directories list\n"));
4406 if (n_directories
== 0)
4407 directory_table
= NULL
;
4409 directory_table
= (unsigned char **)
4410 xmalloc (n_directories
* sizeof (unsigned char *));
4412 for (entryi
= 0; entryi
< n_directories
; entryi
++)
4414 unsigned char **pathp
= &directory_table
[entryi
];
4416 format
= format_start
;
4417 for (formati
= 0; formati
< format_count
; formati
++)
4419 dwarf_vma content_type
, form
;
4422 READ_ULEB (content_type
, format
, end
);
4423 READ_ULEB (form
, format
, end
);
4426 warn (_("Corrupt directories list\n"));
4429 switch (content_type
)
4434 case DW_FORM_string
:
4437 case DW_FORM_line_strp
:
4438 SAFE_BYTE_GET (uvalue
, data
, linfo
.li_offset_size
,
4440 /* Remove const by the cast. */
4441 *pathp
= (unsigned char *)
4442 fetch_indirect_line_string (uvalue
);
4447 data
= read_and_display_attr_value (0, form
, 0, start
,
4449 linfo
.li_offset_size
,
4456 warn (_("Corrupt directories list\n"));
4461 /* Skip files format. */
4462 SAFE_BYTE_GET_AND_INC (format_count
, data
, 1, end
);
4463 if (do_checks
&& format_count
> 5)
4464 warn (_("Unexpectedly large number of columns in the file name table (%u)\n"),
4466 format_start
= data
;
4467 for (formati
= 0; formati
< format_count
; formati
++)
4469 SKIP_ULEB (data
, end
);
4470 SKIP_ULEB (data
, end
);
4473 READ_ULEB (n_files
, data
, end
);
4474 if (data
== end
&& n_files
> 0)
4476 warn (_("Corrupt file name list\n"));
4483 file_table
= (File_Entry
*) xcalloc (1, n_files
4484 * sizeof (File_Entry
));
4486 for (entryi
= 0; entryi
< n_files
; entryi
++)
4488 File_Entry
*file
= &file_table
[entryi
];
4490 format
= format_start
;
4491 for (formati
= 0; formati
< format_count
; formati
++)
4493 dwarf_vma content_type
, form
;
4497 READ_ULEB (content_type
, format
, end
);
4498 READ_ULEB (form
, format
, end
);
4501 warn (_("Corrupt file name list\n"));
4504 switch (content_type
)
4509 case DW_FORM_string
:
4512 case DW_FORM_line_strp
:
4513 SAFE_BYTE_GET (uvalue
, data
, linfo
.li_offset_size
,
4515 /* Remove const by the cast. */
4516 file
->name
= (unsigned char *)
4517 fetch_indirect_line_string (uvalue
);
4521 case DW_LNCT_directory_index
:
4525 SAFE_BYTE_GET (file
->directory_index
, data
, 1,
4529 SAFE_BYTE_GET (file
->directory_index
, data
, 2,
4534 READ_ULEB (file
->directory_index
, tmp
, end
);
4539 data
= read_and_display_attr_value (0, form
, 0, start
,
4541 linfo
.li_offset_size
,
4548 warn (_("Corrupt file name list\n"));
4557 unsigned char *ptr_directory_table
= data
;
4559 while (data
< end
&& *data
!= 0)
4561 data
+= strnlen ((char *) data
, end
- data
) + 1;
4568 warn (_("directory table ends unexpectedly\n"));
4573 /* Go through the directory table again to save the directories. */
4574 directory_table
= (unsigned char **)
4575 xmalloc (n_directories
* sizeof (unsigned char *));
4578 while (*ptr_directory_table
!= 0)
4580 directory_table
[i
] = ptr_directory_table
;
4581 ptr_directory_table
+= strnlen ((char *) ptr_directory_table
,
4582 ptr_directory_table
- end
) + 1;
4586 /* Skip the NUL at the end of the table. */
4589 /* Traverse the File Name table just to count the entries. */
4590 if (data
< end
&& *data
!= 0)
4592 unsigned char *ptr_file_name_table
= data
;
4594 while (data
< end
&& *data
!= 0)
4596 /* Skip Name, directory index, last modification
4597 time and length of file. */
4598 data
+= strnlen ((char *) data
, end
- data
) + 1;
4599 SKIP_ULEB (data
, end
);
4600 SKIP_ULEB (data
, end
);
4601 SKIP_ULEB (data
, end
);
4607 warn (_("file table ends unexpectedly\n"));
4612 /* Go through the file table again to save the strings. */
4613 file_table
= (File_Entry
*) xmalloc (n_files
* sizeof (File_Entry
));
4616 while (*ptr_file_name_table
!= 0)
4618 file_table
[i
].name
= ptr_file_name_table
;
4619 ptr_file_name_table
+= strnlen ((char *) ptr_file_name_table
,
4620 end
- ptr_file_name_table
) + 1;
4622 /* We are not interested in directory, time or size. */
4623 READ_ULEB (file_table
[i
].directory_index
,
4624 ptr_file_name_table
, end
);
4625 READ_ULEB (file_table
[i
].modification_date
,
4626 ptr_file_name_table
, end
);
4627 READ_ULEB (file_table
[i
].length
,
4628 ptr_file_name_table
, end
);
4634 /* Skip the NUL at the end of the table. */
4638 /* Print the Compilation Unit's name and a header. */
4639 if (file_table
== NULL
)
4640 printf (_("CU: No directory table\n"));
4641 else if (directory_table
== NULL
)
4642 printf (_("CU: %s:\n"), file_table
[0].name
);
4645 unsigned int ix
= file_table
[0].directory_index
;
4646 const char *directory
;
4651 else if (n_directories
== 0)
4652 directory
= _("<unknown>");
4653 else if (ix
> n_directories
)
4655 warn (_("directory index %u > number of directories %s\n"),
4656 ix
, dwarf_vmatoa ("u", n_directories
));
4657 directory
= _("<corrupt>");
4660 directory
= (char *) directory_table
[ix
- 1];
4662 if (do_wide
|| strlen (directory
) < 76)
4663 printf (_("CU: %s/%s:\n"), directory
, file_table
[0].name
);
4665 printf ("%s:\n", file_table
[0].name
);
4669 printf (_("File name Line number Starting address View Stmt\n"));
4671 printf (_("CU: Empty file name table\n"));
4672 saved_linfo
= linfo
;
4675 /* This loop iterates through the Dwarf Line Number Program. */
4676 while (data
< end_of_sequence
)
4678 unsigned char op_code
;
4681 unsigned long int uladv
;
4682 int is_special_opcode
= 0;
4687 if (op_code
>= linfo
.li_opcode_base
)
4689 op_code
-= linfo
.li_opcode_base
;
4690 uladv
= (op_code
/ linfo
.li_line_range
);
4691 if (linfo
.li_max_ops_per_insn
== 1)
4693 uladv
*= linfo
.li_min_insn_length
;
4694 state_machine_regs
.address
+= uladv
;
4696 state_machine_regs
.view
= 0;
4701 = ((state_machine_regs
.op_index
+ uladv
)
4702 / linfo
.li_max_ops_per_insn
)
4703 * linfo
.li_min_insn_length
;
4704 state_machine_regs
.address
4706 state_machine_regs
.op_index
4707 = (state_machine_regs
.op_index
+ uladv
)
4708 % linfo
.li_max_ops_per_insn
;
4710 state_machine_regs
.view
= 0;
4713 adv
= (op_code
% linfo
.li_line_range
) + linfo
.li_line_base
;
4714 state_machine_regs
.line
+= adv
;
4715 is_special_opcode
= 1;
4716 /* Increment view after printing this row. */
4721 case DW_LNS_extended_op
:
4723 unsigned int ext_op_code_len
;
4724 unsigned char ext_op_code
;
4725 unsigned char *op_code_end
;
4726 unsigned char *op_code_data
= data
;
4728 READ_ULEB (ext_op_code_len
, op_code_data
, end_of_sequence
);
4729 op_code_end
= op_code_data
+ ext_op_code_len
;
4730 if (ext_op_code_len
== 0 || op_code_end
> end_of_sequence
)
4732 warn (_("Badly formed extended line op encountered!\n"));
4735 ext_op_code
= *op_code_data
++;
4739 switch (ext_op_code
)
4741 case DW_LNE_end_sequence
:
4742 /* Reset stuff after printing this row. */
4744 case DW_LNE_set_address
:
4745 SAFE_BYTE_GET_AND_INC (state_machine_regs
.address
,
4747 op_code_end
- op_code_data
,
4749 state_machine_regs
.op_index
= 0;
4750 state_machine_regs
.view
= 0;
4752 case DW_LNE_define_file
:
4753 file_table
= (File_Entry
*) xrealloc
4754 (file_table
, (n_files
+ 1) * sizeof (File_Entry
));
4756 ++state_machine_regs
.last_file_entry
;
4757 /* Source file name. */
4758 file_table
[n_files
].name
= op_code_data
;
4759 op_code_data
+= strlen ((char *) op_code_data
) + 1;
4760 /* Directory index. */
4761 READ_ULEB (file_table
[n_files
].directory_index
,
4762 op_code_data
, op_code_end
);
4763 /* Last modification time. */
4764 READ_ULEB (file_table
[n_files
].modification_date
,
4765 op_code_data
, op_code_end
);
4767 READ_ULEB (file_table
[n_files
].length
,
4768 op_code_data
, op_code_end
);
4772 case DW_LNE_set_discriminator
:
4773 case DW_LNE_HP_set_sequence
:
4774 /* Simply ignored. */
4778 printf (_("UNKNOWN (%u): length %ld\n"),
4779 ext_op_code
, (long int) (op_code_data
- data
));
4786 /* Increment view after printing this row. */
4789 case DW_LNS_advance_pc
:
4790 READ_ULEB (uladv
, data
, end
);
4791 if (linfo
.li_max_ops_per_insn
== 1)
4793 uladv
*= linfo
.li_min_insn_length
;
4794 state_machine_regs
.address
+= uladv
;
4796 state_machine_regs
.view
= 0;
4801 = ((state_machine_regs
.op_index
+ uladv
)
4802 / linfo
.li_max_ops_per_insn
)
4803 * linfo
.li_min_insn_length
;
4804 state_machine_regs
.address
4806 state_machine_regs
.op_index
4807 = (state_machine_regs
.op_index
+ uladv
)
4808 % linfo
.li_max_ops_per_insn
;
4810 state_machine_regs
.view
= 0;
4814 case DW_LNS_advance_line
:
4815 READ_SLEB (adv
, data
, end
);
4816 state_machine_regs
.line
+= adv
;
4819 case DW_LNS_set_file
:
4820 READ_ULEB (uladv
, data
, end
);
4821 state_machine_regs
.file
= uladv
;
4824 unsigned file
= state_machine_regs
.file
- 1;
4827 if (file_table
== NULL
|| n_files
== 0)
4828 printf (_("\n [Use file table entry %d]\n"), file
);
4830 else if (file
>= n_files
)
4832 warn (_("file index %u > number of files %u\n"), file
+ 1, n_files
);
4833 printf (_("\n <over large file table index %u>"), file
);
4835 else if ((dir
= file_table
[file
].directory_index
) == 0)
4836 /* If directory index is 0, that means current directory. */
4837 printf ("\n./%s:[++]\n", file_table
[file
].name
);
4838 else if (directory_table
== NULL
|| n_directories
== 0)
4839 printf (_("\n [Use file %s in directory table entry %d]\n"),
4840 file_table
[file
].name
, dir
);
4842 else if (dir
> n_directories
)
4844 warn (_("directory index %u > number of directories %s\n"),
4845 dir
, dwarf_vmatoa ("u", n_directories
));
4846 printf (_("\n <over large directory table entry %u>\n"), dir
);
4849 printf ("\n%s/%s:\n",
4850 /* The directory index starts counting at 1. */
4851 directory_table
[dir
- 1], file_table
[file
].name
);
4855 case DW_LNS_set_column
:
4856 READ_ULEB (uladv
, data
, end
);
4857 state_machine_regs
.column
= uladv
;
4860 case DW_LNS_negate_stmt
:
4861 adv
= state_machine_regs
.is_stmt
;
4863 state_machine_regs
.is_stmt
= adv
;
4866 case DW_LNS_set_basic_block
:
4867 state_machine_regs
.basic_block
= 1;
4870 case DW_LNS_const_add_pc
:
4871 uladv
= ((255 - linfo
.li_opcode_base
) / linfo
.li_line_range
);
4872 if (linfo
.li_max_ops_per_insn
== 1)
4874 uladv
*= linfo
.li_min_insn_length
;
4875 state_machine_regs
.address
+= uladv
;
4877 state_machine_regs
.view
= 0;
4882 = ((state_machine_regs
.op_index
+ uladv
)
4883 / linfo
.li_max_ops_per_insn
)
4884 * linfo
.li_min_insn_length
;
4885 state_machine_regs
.address
4887 state_machine_regs
.op_index
4888 = (state_machine_regs
.op_index
+ uladv
)
4889 % linfo
.li_max_ops_per_insn
;
4891 state_machine_regs
.view
= 0;
4895 case DW_LNS_fixed_advance_pc
:
4896 SAFE_BYTE_GET_AND_INC (uladv
, data
, 2, end
);
4897 state_machine_regs
.address
+= uladv
;
4898 state_machine_regs
.op_index
= 0;
4899 /* Do NOT reset view. */
4902 case DW_LNS_set_prologue_end
:
4905 case DW_LNS_set_epilogue_begin
:
4908 case DW_LNS_set_isa
:
4909 READ_ULEB (uladv
, data
, end
);
4910 printf (_(" Set ISA to %lu\n"), uladv
);
4914 printf (_(" Unknown opcode %d with operands: "), op_code
);
4916 if (standard_opcodes
!= NULL
)
4917 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
4921 READ_ULEB (val
, data
, end
);
4922 printf ("0x%s%s", dwarf_vmatoa ("x", val
),
4923 i
== 1 ? "" : ", ");
4929 /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row
4930 to the DWARF address/line matrix. */
4931 if ((is_special_opcode
) || (xop
== -DW_LNE_end_sequence
)
4932 || (xop
== DW_LNS_copy
))
4934 const unsigned int MAX_FILENAME_LENGTH
= 35;
4936 char *newFileName
= NULL
;
4937 size_t fileNameLength
;
4941 unsigned indx
= state_machine_regs
.file
- 1;
4943 if (indx
>= n_files
)
4945 warn (_("corrupt file index %u encountered\n"), indx
);
4946 fileName
= _("<corrupt>");
4949 fileName
= (char *) file_table
[indx
].name
;
4952 fileName
= _("<unknown>");
4954 fileNameLength
= strlen (fileName
);
4956 if ((fileNameLength
> MAX_FILENAME_LENGTH
) && (!do_wide
))
4958 newFileName
= (char *) xmalloc (MAX_FILENAME_LENGTH
+ 1);
4959 /* Truncate file name */
4960 strncpy (newFileName
,
4961 fileName
+ fileNameLength
- MAX_FILENAME_LENGTH
,
4962 MAX_FILENAME_LENGTH
+ 1);
4963 /* FIXME: This is to pacify gcc-10 which can warn that the
4964 strncpy above might leave a non-NUL terminated string
4965 in newFileName. It won't, but gcc's analysis doesn't
4966 quite go far enough to discover this. */
4967 newFileName
[MAX_FILENAME_LENGTH
] = 0;
4971 newFileName
= (char *) xmalloc (fileNameLength
+ 1);
4972 strncpy (newFileName
, fileName
, fileNameLength
+ 1);
4975 if (!do_wide
|| (fileNameLength
<= MAX_FILENAME_LENGTH
))
4977 if (linfo
.li_max_ops_per_insn
== 1)
4978 printf ("%-35s %11d %#18" DWARF_VMA_FMT
"x",
4979 newFileName
, state_machine_regs
.line
,
4980 state_machine_regs
.address
);
4982 printf ("%-35s %11d %#18" DWARF_VMA_FMT
"x[%d]",
4983 newFileName
, state_machine_regs
.line
,
4984 state_machine_regs
.address
,
4985 state_machine_regs
.op_index
);
4989 if (linfo
.li_max_ops_per_insn
== 1)
4990 printf ("%s %11d %#18" DWARF_VMA_FMT
"x",
4991 newFileName
, state_machine_regs
.line
,
4992 state_machine_regs
.address
);
4994 printf ("%s %11d %#18" DWARF_VMA_FMT
"x[%d]",
4995 newFileName
, state_machine_regs
.line
,
4996 state_machine_regs
.address
,
4997 state_machine_regs
.op_index
);
5000 if (state_machine_regs
.view
)
5001 printf (" %6u", state_machine_regs
.view
);
5005 if (state_machine_regs
.is_stmt
)
5009 state_machine_regs
.view
++;
5011 if (xop
== -DW_LNE_end_sequence
)
5013 reset_state_machine (linfo
.li_default_is_stmt
);
5028 if (directory_table
)
5030 free (directory_table
);
5031 directory_table
= NULL
;
5042 display_debug_lines (struct dwarf_section
*section
, void *file
)
5044 unsigned char *data
= section
->start
;
5045 unsigned char *end
= data
+ section
->size
;
5047 int retValDecoded
= 1;
5049 if (do_debug_lines
== 0)
5050 do_debug_lines
|= FLAG_DEBUG_LINES_RAW
;
5052 if (do_debug_lines
& FLAG_DEBUG_LINES_RAW
)
5053 retValRaw
= display_debug_lines_raw (section
, data
, end
, file
);
5055 if (do_debug_lines
& FLAG_DEBUG_LINES_DECODED
)
5056 retValDecoded
= display_debug_lines_decoded (section
, data
, data
, end
, file
);
5058 if (!retValRaw
|| !retValDecoded
)
5065 find_debug_info_for_offset (unsigned long offset
)
5069 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
5072 for (i
= 0; i
< num_debug_info_entries
; i
++)
5073 if (debug_information
[i
].cu_offset
== offset
)
5074 return debug_information
+ i
;
5080 get_gdb_index_symbol_kind_name (gdb_index_symbol_kind kind
)
5082 /* See gdb/gdb-index.h. */
5083 static const char * const kinds
[] =
5095 return _ (kinds
[kind
]);
5099 display_debug_pubnames_worker (struct dwarf_section
*section
,
5100 void *file ATTRIBUTE_UNUSED
,
5103 DWARF2_Internal_PubNames names
;
5104 unsigned char *start
= section
->start
;
5105 unsigned char *end
= start
+ section
->size
;
5107 /* It does not matter if this load fails,
5108 we test for that later on. */
5109 load_debug_info (file
);
5111 introduce (section
, FALSE
);
5115 unsigned char *data
;
5116 unsigned long sec_off
;
5117 unsigned int offset_size
, initial_length_size
;
5119 SAFE_BYTE_GET_AND_INC (names
.pn_length
, start
, 4, end
);
5120 if (names
.pn_length
== 0xffffffff)
5122 SAFE_BYTE_GET_AND_INC (names
.pn_length
, start
, 8, end
);
5124 initial_length_size
= 12;
5129 initial_length_size
= 4;
5132 sec_off
= start
- section
->start
;
5133 if (sec_off
+ names
.pn_length
< sec_off
5134 || sec_off
+ names
.pn_length
> section
->size
)
5136 warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"),
5138 sec_off
- initial_length_size
,
5139 dwarf_vmatoa ("x", names
.pn_length
));
5144 start
+= names
.pn_length
;
5146 SAFE_BYTE_GET_AND_INC (names
.pn_version
, data
, 2, end
);
5147 SAFE_BYTE_GET_AND_INC (names
.pn_offset
, data
, offset_size
, end
);
5149 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
5150 && num_debug_info_entries
> 0
5151 && find_debug_info_for_offset (names
.pn_offset
) == NULL
)
5152 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
5153 (unsigned long) names
.pn_offset
, section
->name
);
5155 SAFE_BYTE_GET_AND_INC (names
.pn_size
, data
, offset_size
, end
);
5157 printf (_(" Length: %ld\n"),
5158 (long) names
.pn_length
);
5159 printf (_(" Version: %d\n"),
5161 printf (_(" Offset into .debug_info section: 0x%lx\n"),
5162 (unsigned long) names
.pn_offset
);
5163 printf (_(" Size of area in .debug_info section: %ld\n"),
5164 (long) names
.pn_size
);
5166 if (names
.pn_version
!= 2 && names
.pn_version
!= 3)
5168 static int warned
= 0;
5172 warn (_("Only DWARF 2 and 3 pubnames are currently supported\n"));
5180 printf (_("\n Offset Kind Name\n"));
5182 printf (_("\n Offset\tName\n"));
5186 bfd_size_type maxprint
;
5189 SAFE_BYTE_GET (offset
, data
, offset_size
, end
);
5194 data
+= offset_size
;
5197 maxprint
= (end
- data
) - 1;
5201 unsigned int kind_data
;
5202 gdb_index_symbol_kind kind
;
5203 const char *kind_name
;
5206 SAFE_BYTE_GET (kind_data
, data
, 1, end
);
5209 /* GCC computes the kind as the upper byte in the CU index
5210 word, and then right shifts it by the CU index size.
5211 Left shift KIND to where the gdb-index.h accessor macros
5213 kind_data
<<= GDB_INDEX_CU_BITSIZE
;
5214 kind
= GDB_INDEX_SYMBOL_KIND_VALUE (kind_data
);
5215 kind_name
= get_gdb_index_symbol_kind_name (kind
);
5216 is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (kind_data
);
5217 printf (" %-6lx %s,%-10s %.*s\n",
5218 (unsigned long) offset
, is_static
? _("s") : _("g"),
5219 kind_name
, (int) maxprint
, data
);
5222 printf (" %-6lx\t%.*s\n",
5223 (unsigned long) offset
, (int) maxprint
, data
);
5225 data
+= strnlen ((char *) data
, maxprint
) + 1;
5236 display_debug_pubnames (struct dwarf_section
*section
, void *file
)
5238 return display_debug_pubnames_worker (section
, file
, 0);
5242 display_debug_gnu_pubnames (struct dwarf_section
*section
, void *file
)
5244 return display_debug_pubnames_worker (section
, file
, 1);
5248 display_debug_macinfo (struct dwarf_section
*section
,
5249 void *file ATTRIBUTE_UNUSED
)
5251 unsigned char *start
= section
->start
;
5252 unsigned char *end
= start
+ section
->size
;
5253 unsigned char *curr
= start
;
5254 enum dwarf_macinfo_record_type op
;
5256 introduce (section
, FALSE
);
5260 unsigned int lineno
;
5261 const unsigned char *string
;
5263 op
= (enum dwarf_macinfo_record_type
) *curr
;
5268 case DW_MACINFO_start_file
:
5270 unsigned int filenum
;
5272 READ_ULEB (lineno
, curr
, end
);
5273 READ_ULEB (filenum
, curr
, end
);
5274 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"),
5279 case DW_MACINFO_end_file
:
5280 printf (_(" DW_MACINFO_end_file\n"));
5283 case DW_MACINFO_define
:
5284 READ_ULEB (lineno
, curr
, end
);
5286 curr
+= strnlen ((char *) string
, end
- string
) + 1;
5287 printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"),
5291 case DW_MACINFO_undef
:
5292 READ_ULEB (lineno
, curr
, end
);
5294 curr
+= strnlen ((char *) string
, end
- string
) + 1;
5295 printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"),
5299 case DW_MACINFO_vendor_ext
:
5301 unsigned int constant
;
5303 READ_ULEB (constant
, curr
, end
);
5305 curr
+= strnlen ((char *) string
, end
- string
) + 1;
5306 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"),
5316 /* Given LINE_OFFSET into the .debug_line section, attempt to return
5317 filename and dirname corresponding to file name table entry with index
5318 FILEIDX. Return NULL on failure. */
5320 static unsigned char *
5321 get_line_filename_and_dirname (dwarf_vma line_offset
,
5323 unsigned char **dir_name
)
5325 struct dwarf_section
*section
= &debug_displays
[line
].section
;
5326 unsigned char *hdrptr
, *dirtable
, *file_name
;
5327 unsigned int offset_size
, initial_length_size
;
5328 unsigned int version
, opcode_base
;
5329 dwarf_vma length
, diridx
;
5330 const unsigned char * end
;
5333 if (section
->start
== NULL
5334 || line_offset
>= section
->size
5338 hdrptr
= section
->start
+ line_offset
;
5339 end
= section
->start
+ section
->size
;
5341 SAFE_BYTE_GET_AND_INC (length
, hdrptr
, 4, end
);
5342 if (length
== 0xffffffff)
5344 /* This section is 64-bit DWARF 3. */
5345 SAFE_BYTE_GET_AND_INC (length
, hdrptr
, 8, end
);
5347 initial_length_size
= 12;
5352 initial_length_size
= 4;
5354 if (length
+ initial_length_size
< length
5355 || length
+ initial_length_size
> section
->size
)
5358 SAFE_BYTE_GET_AND_INC (version
, hdrptr
, 2, end
);
5359 if (version
!= 2 && version
!= 3 && version
!= 4)
5361 hdrptr
+= offset_size
+ 1;/* Skip prologue_length and min_insn_length. */
5363 hdrptr
++; /* Skip max_ops_per_insn. */
5364 hdrptr
+= 3; /* Skip default_is_stmt, line_base, line_range. */
5366 SAFE_BYTE_GET_AND_INC (opcode_base
, hdrptr
, 1, end
);
5367 if (opcode_base
== 0)
5370 hdrptr
+= opcode_base
- 1;
5375 /* Skip over dirname table. */
5376 while (*hdrptr
!= '\0')
5378 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
) + 1;
5382 hdrptr
++; /* Skip the NUL at the end of the table. */
5384 /* Now skip over preceding filename table entries. */
5385 for (; hdrptr
< end
&& *hdrptr
!= '\0' && fileidx
> 1; fileidx
--)
5387 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
) + 1;
5388 SKIP_ULEB (hdrptr
, end
);
5389 SKIP_ULEB (hdrptr
, end
);
5390 SKIP_ULEB (hdrptr
, end
);
5392 if (hdrptr
>= end
|| *hdrptr
== '\0')
5396 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
) + 1;
5399 READ_ULEB (diridx
, hdrptr
, end
);
5402 for (; dirtable
< end
&& *dirtable
!= '\0' && diridx
> 1; diridx
--)
5403 dirtable
+= strnlen ((char *) dirtable
, end
- dirtable
) + 1;
5404 if (dirtable
>= end
|| *dirtable
== '\0')
5406 *dir_name
= dirtable
;
5411 display_debug_macro (struct dwarf_section
*section
,
5414 unsigned char *start
= section
->start
;
5415 unsigned char *end
= start
+ section
->size
;
5416 unsigned char *curr
= start
;
5417 unsigned char *extended_op_buf
[256];
5419 load_debug_section_with_follow (str
, file
);
5420 load_debug_section_with_follow (line
, file
);
5421 load_debug_section_with_follow (str_index
, file
);
5423 introduce (section
, FALSE
);
5427 unsigned int lineno
, version
, flags
;
5428 unsigned int offset_size
= 4;
5429 const unsigned char *string
;
5430 dwarf_vma line_offset
= 0, sec_offset
= curr
- start
, offset
;
5431 unsigned char **extended_ops
= NULL
;
5433 SAFE_BYTE_GET_AND_INC (version
, curr
, 2, end
);
5434 if (version
!= 4 && version
!= 5)
5436 error (_("Only GNU extension to DWARF 4 or 5 of %s is currently supported.\n"),
5441 SAFE_BYTE_GET_AND_INC (flags
, curr
, 1, end
);
5444 printf (_(" Offset: 0x%lx\n"),
5445 (unsigned long) sec_offset
);
5446 printf (_(" Version: %d\n"), version
);
5447 printf (_(" Offset size: %d\n"), offset_size
);
5450 SAFE_BYTE_GET_AND_INC (line_offset
, curr
, offset_size
, end
);
5451 printf (_(" Offset into .debug_line: 0x%lx\n"),
5452 (unsigned long) line_offset
);
5456 unsigned int i
, count
, op
;
5459 SAFE_BYTE_GET_AND_INC (count
, curr
, 1, end
);
5461 memset (extended_op_buf
, 0, sizeof (extended_op_buf
));
5462 extended_ops
= extended_op_buf
;
5465 printf (_(" Extension opcode arguments:\n"));
5466 for (i
= 0; i
< count
; i
++)
5468 SAFE_BYTE_GET_AND_INC (op
, curr
, 1, end
);
5469 extended_ops
[op
] = curr
;
5470 READ_ULEB (nargs
, curr
, end
);
5472 printf (_(" DW_MACRO_%02x has no arguments\n"), op
);
5475 printf (_(" DW_MACRO_%02x arguments: "), op
);
5476 for (n
= 0; n
< nargs
; n
++)
5480 SAFE_BYTE_GET_AND_INC (form
, curr
, 1, end
);
5481 printf ("%s%s", get_FORM_name (form
),
5482 n
== nargs
- 1 ? "\n" : ", ");
5492 case DW_FORM_block1
:
5493 case DW_FORM_block2
:
5494 case DW_FORM_block4
:
5496 case DW_FORM_string
:
5498 case DW_FORM_sec_offset
:
5501 error (_("Invalid extension opcode form %s\n"),
5502 get_FORM_name (form
));
5518 error (_(".debug_macro section not zero terminated\n"));
5522 SAFE_BYTE_GET_AND_INC (op
, curr
, 1, end
);
5528 case DW_MACRO_define
:
5529 READ_ULEB (lineno
, curr
, end
);
5531 curr
+= strnlen ((char *) string
, end
- string
) + 1;
5532 printf (_(" DW_MACRO_define - lineno : %d macro : %s\n"),
5536 case DW_MACRO_undef
:
5537 READ_ULEB (lineno
, curr
, end
);
5539 curr
+= strnlen ((char *) string
, end
- string
) + 1;
5540 printf (_(" DW_MACRO_undef - lineno : %d macro : %s\n"),
5544 case DW_MACRO_start_file
:
5546 unsigned int filenum
;
5547 unsigned char *file_name
= NULL
, *dir_name
= NULL
;
5549 READ_ULEB (lineno
, curr
, end
);
5550 READ_ULEB (filenum
, curr
, end
);
5552 if ((flags
& 2) == 0)
5553 error (_("DW_MACRO_start_file used, but no .debug_line offset provided.\n"));
5556 = get_line_filename_and_dirname (line_offset
, filenum
,
5558 if (file_name
== NULL
)
5559 printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d\n"),
5562 printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d filename: %s%s%s\n"),
5564 dir_name
!= NULL
? (const char *) dir_name
: "",
5565 dir_name
!= NULL
? "/" : "", file_name
);
5569 case DW_MACRO_end_file
:
5570 printf (_(" DW_MACRO_end_file\n"));
5573 case DW_MACRO_define_strp
:
5574 READ_ULEB (lineno
, curr
, end
);
5575 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
5576 string
= fetch_indirect_string (offset
);
5577 printf (_(" DW_MACRO_define_strp - lineno : %d macro : %s\n"),
5581 case DW_MACRO_undef_strp
:
5582 READ_ULEB (lineno
, curr
, end
);
5583 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
5584 string
= fetch_indirect_string (offset
);
5585 printf (_(" DW_MACRO_undef_strp - lineno : %d macro : %s\n"),
5589 case DW_MACRO_import
:
5590 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
5591 printf (_(" DW_MACRO_import - offset : 0x%lx\n"),
5592 (unsigned long) offset
);
5595 case DW_MACRO_define_sup
:
5596 READ_ULEB (lineno
, curr
, end
);
5597 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
5598 printf (_(" DW_MACRO_define_sup - lineno : %d macro offset : 0x%lx\n"),
5599 lineno
, (unsigned long) offset
);
5602 case DW_MACRO_undef_sup
:
5603 READ_ULEB (lineno
, curr
, end
);
5604 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
5605 printf (_(" DW_MACRO_undef_sup - lineno : %d macro offset : 0x%lx\n"),
5606 lineno
, (unsigned long) offset
);
5609 case DW_MACRO_import_sup
:
5610 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
5611 printf (_(" DW_MACRO_import_sup - offset : 0x%lx\n"),
5612 (unsigned long) offset
);
5615 case DW_MACRO_define_strx
:
5616 case DW_MACRO_undef_strx
:
5617 READ_ULEB (lineno
, curr
, end
);
5618 READ_ULEB (offset
, curr
, end
);
5619 string
= (const unsigned char *)
5620 fetch_indexed_string (offset
, NULL
, offset_size
, FALSE
);
5621 if (op
== DW_MACRO_define_strx
)
5622 printf (" DW_MACRO_define_strx ");
5624 printf (" DW_MACRO_undef_strx ");
5626 printf (_("(with offset %s) "), dwarf_vmatoa (NULL
, offset
));
5627 printf (_("lineno : %d macro : %s\n"),
5632 if (op
>= DW_MACRO_lo_user
&& op
<= DW_MACRO_hi_user
)
5634 printf (_(" <Target Specific macro op: %#x - UNHANDLED"), op
);
5638 if (extended_ops
== NULL
|| extended_ops
[op
] == NULL
)
5640 error (_(" Unknown macro opcode %02x seen\n"), op
);
5645 /* Skip over unhandled opcodes. */
5647 unsigned char *desc
= extended_ops
[op
];
5648 READ_ULEB (nargs
, desc
, end
);
5651 printf (_(" DW_MACRO_%02x\n"), op
);
5654 printf (_(" DW_MACRO_%02x -"), op
);
5655 for (n
= 0; n
< nargs
; n
++)
5659 /* DW_FORM_implicit_const is not expected here. */
5660 SAFE_BYTE_GET_AND_INC (val
, desc
, 1, end
);
5662 = read_and_display_attr_value (0, val
, 0,
5663 start
, curr
, end
, 0, 0, offset_size
,
5664 version
, NULL
, 0, NULL
,
5682 display_debug_abbrev (struct dwarf_section
*section
,
5683 void *file ATTRIBUTE_UNUSED
)
5685 abbrev_entry
*entry
;
5686 unsigned char *start
= section
->start
;
5687 unsigned char *end
= start
+ section
->size
;
5689 introduce (section
, FALSE
);
5693 unsigned char *last
;
5698 start
= process_abbrev_section (start
, end
);
5700 if (first_abbrev
== NULL
)
5703 printf (_(" Number TAG (0x%lx)\n"), (long) (last
- section
->start
));
5705 for (entry
= first_abbrev
; entry
; entry
= entry
->next
)
5709 printf (" %ld %s [%s]\n",
5711 get_TAG_name (entry
->tag
),
5712 entry
->children
? _("has children") : _("no children"));
5714 for (attr
= entry
->first_attr
; attr
; attr
= attr
->next
)
5716 printf (" %-18s %s",
5717 get_AT_name (attr
->attribute
),
5718 get_FORM_name (attr
->form
));
5719 if (attr
->form
== DW_FORM_implicit_const
)
5720 printf (": %" BFD_VMA_FMT
"d", attr
->implicit_const
);
5732 /* Return true when ADDR is the maximum address, when addresses are
5733 POINTER_SIZE bytes long. */
5736 is_max_address (dwarf_vma addr
, unsigned int pointer_size
)
5738 dwarf_vma mask
= ~(~(dwarf_vma
) 1 << (pointer_size
* 8 - 1));
5739 return ((addr
& mask
) == mask
);
5742 /* Display a view pair list starting at *VSTART_PTR and ending at
5743 VLISTEND within SECTION. */
5746 display_view_pair_list (struct dwarf_section
*section
,
5747 unsigned char **vstart_ptr
,
5748 unsigned int debug_info_entry
,
5749 unsigned char *vlistend
)
5751 unsigned char *vstart
= *vstart_ptr
;
5752 unsigned char *section_end
= section
->start
+ section
->size
;
5753 unsigned int pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
5755 if (vlistend
< section_end
)
5756 section_end
= vlistend
;
5760 while (vstart
< section_end
)
5762 dwarf_vma off
= vstart
- section
->start
;
5763 dwarf_vma vbegin
, vend
;
5765 READ_ULEB (vbegin
, vstart
, section_end
);
5766 if (vstart
== section_end
)
5769 READ_ULEB (vend
, vstart
, section_end
);
5770 printf (" %8.8lx ", (unsigned long) off
);
5772 print_dwarf_view (vbegin
, pointer_size
, 1);
5773 print_dwarf_view (vend
, pointer_size
, 1);
5774 printf (_("location view pair\n"));
5778 *vstart_ptr
= vstart
;
5781 /* Display a location list from a normal (ie, non-dwo) .debug_loc section. */
5784 display_loc_list (struct dwarf_section
*section
,
5785 unsigned char **start_ptr
,
5786 unsigned int debug_info_entry
,
5788 dwarf_vma base_address
,
5789 unsigned char **vstart_ptr
,
5792 unsigned char *start
= *start_ptr
, *vstart
= *vstart_ptr
;
5793 unsigned char *section_end
= section
->start
+ section
->size
;
5794 unsigned long cu_offset
;
5795 unsigned int pointer_size
;
5796 unsigned int offset_size
;
5801 unsigned short length
;
5802 int need_frame_base
;
5804 if (debug_info_entry
>= num_debug_info_entries
)
5806 warn (_("No debug information available for loc lists of entry: %u\n"),
5811 cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
5812 pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
5813 offset_size
= debug_information
[debug_info_entry
].offset_size
;
5814 dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
5816 if (pointer_size
< 2 || pointer_size
> 8)
5818 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
5819 pointer_size
, debug_info_entry
);
5825 dwarf_vma off
= offset
+ (start
- *start_ptr
);
5826 dwarf_vma vbegin
= vm1
, vend
= vm1
;
5828 if (start
+ 2 * pointer_size
> section_end
)
5830 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5831 (unsigned long) offset
);
5835 printf (" %8.8lx ", (unsigned long) off
);
5837 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, section_end
);
5838 SAFE_BYTE_GET_AND_INC (end
, start
, pointer_size
, section_end
);
5840 if (begin
== 0 && end
== 0)
5842 /* PR 18374: In a object file we can have a location list that
5843 starts with a begin and end of 0 because there are relocations
5844 that need to be applied to the addresses. Actually applying
5845 the relocations now does not help as they will probably resolve
5846 to 0, since the object file has not been fully linked. Real
5847 end of list markers will not have any relocations against them. */
5848 if (! reloc_at (section
, off
)
5849 && ! reloc_at (section
, off
+ pointer_size
))
5851 printf (_("<End of list>\n"));
5856 /* Check base address specifiers. */
5857 if (is_max_address (begin
, pointer_size
)
5858 && !is_max_address (end
, pointer_size
))
5861 print_dwarf_vma (begin
, pointer_size
);
5862 print_dwarf_vma (end
, pointer_size
);
5863 printf (_("(base address)\n"));
5869 off
= offset
+ (vstart
- *start_ptr
);
5871 READ_ULEB (vbegin
, vstart
, section_end
);
5872 print_dwarf_view (vbegin
, pointer_size
, 1);
5874 READ_ULEB (vend
, vstart
, section_end
);
5875 print_dwarf_view (vend
, pointer_size
, 1);
5877 printf (_("views at %8.8lx for:\n %*s "),
5878 (unsigned long) off
, 8, "");
5881 if (start
+ 2 > section_end
)
5883 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5884 (unsigned long) offset
);
5888 SAFE_BYTE_GET_AND_INC (length
, start
, 2, section_end
);
5890 if (start
+ length
> section_end
)
5892 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5893 (unsigned long) offset
);
5897 print_dwarf_vma (begin
+ base_address
, pointer_size
);
5898 print_dwarf_vma (end
+ base_address
, pointer_size
);
5901 need_frame_base
= decode_location_expression (start
,
5906 cu_offset
, section
);
5909 if (need_frame_base
&& !has_frame_base
)
5910 printf (_(" [without DW_AT_frame_base]"));
5912 if (begin
== end
&& vbegin
== vend
)
5913 fputs (_(" (start == end)"), stdout
);
5914 else if (begin
> end
|| (begin
== end
&& vbegin
> vend
))
5915 fputs (_(" (start > end)"), stdout
);
5923 *vstart_ptr
= vstart
;
5926 /* Display a location list from a normal (ie, non-dwo) .debug_loclists section. */
5929 display_loclists_list (struct dwarf_section
*section
,
5930 unsigned char **start_ptr
,
5931 unsigned int debug_info_entry
,
5933 dwarf_vma base_address
,
5934 unsigned char **vstart_ptr
,
5937 unsigned char *start
= *start_ptr
, *vstart
= *vstart_ptr
;
5938 unsigned char *section_end
= section
->start
+ section
->size
;
5939 unsigned long cu_offset
;
5940 unsigned int pointer_size
;
5941 unsigned int offset_size
;
5944 /* Initialize it due to a false compiler warning. */
5945 dwarf_vma begin
= -1, vbegin
= -1;
5946 dwarf_vma end
= -1, vend
= -1;
5948 int need_frame_base
;
5950 if (debug_info_entry
>= num_debug_info_entries
)
5952 warn (_("No debug information available for "
5953 "loclists lists of entry: %u\n"),
5958 cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
5959 pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
5960 offset_size
= debug_information
[debug_info_entry
].offset_size
;
5961 dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
5963 if (pointer_size
< 2 || pointer_size
> 8)
5965 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
5966 pointer_size
, debug_info_entry
);
5972 dwarf_vma off
= offset
+ (start
- *start_ptr
);
5973 enum dwarf_location_list_entry_type llet
;
5975 if (start
+ 1 > section_end
)
5977 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5978 (unsigned long) offset
);
5982 printf (" %8.8lx ", (unsigned long) off
);
5984 SAFE_BYTE_GET_AND_INC (llet
, start
, 1, section_end
);
5986 if (vstart
&& llet
== DW_LLE_offset_pair
)
5988 off
= offset
+ (vstart
- *start_ptr
);
5990 READ_ULEB (vbegin
, vstart
, section_end
);
5991 print_dwarf_view (vbegin
, pointer_size
, 1);
5993 READ_ULEB (vend
, vstart
, section_end
);
5994 print_dwarf_view (vend
, pointer_size
, 1);
5996 printf (_("views at %8.8lx for:\n %*s "),
5997 (unsigned long) off
, 8, "");
6002 case DW_LLE_end_of_list
:
6003 printf (_("<End of list>\n"));
6005 case DW_LLE_offset_pair
:
6006 READ_ULEB (begin
, start
, section_end
);
6007 READ_ULEB (end
, start
, section_end
);
6009 case DW_LLE_base_address
:
6010 SAFE_BYTE_GET_AND_INC (base_address
, start
, pointer_size
,
6012 print_dwarf_vma (base_address
, pointer_size
);
6013 printf (_("(base address)\n"));
6015 #ifdef DW_LLE_view_pair
6016 case DW_LLE_view_pair
:
6018 printf (_("View pair entry in loclist with locviews attribute\n"));
6019 READ_ULEB (vbegin
, start
, section_end
);
6020 print_dwarf_view (vbegin
, pointer_size
, 1);
6022 READ_ULEB (vend
, start
, section_end
);
6023 print_dwarf_view (vend
, pointer_size
, 1);
6025 printf (_("views for:\n"));
6029 error (_("Invalid location list entry type %d\n"), llet
);
6032 if (llet
== DW_LLE_end_of_list
)
6034 if (llet
!= DW_LLE_offset_pair
)
6037 if (start
+ 2 > section_end
)
6039 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6040 (unsigned long) offset
);
6044 READ_ULEB (length
, start
, section_end
);
6046 print_dwarf_vma (begin
+ base_address
, pointer_size
);
6047 print_dwarf_vma (end
+ base_address
, pointer_size
);
6050 need_frame_base
= decode_location_expression (start
,
6055 cu_offset
, section
);
6058 if (need_frame_base
&& !has_frame_base
)
6059 printf (_(" [without DW_AT_frame_base]"));
6061 if (begin
== end
&& vbegin
== vend
)
6062 fputs (_(" (start == end)"), stdout
);
6063 else if (begin
> end
|| (begin
== end
&& vbegin
> vend
))
6064 fputs (_(" (start > end)"), stdout
);
6072 if (vbegin
!= vm1
|| vend
!= vm1
)
6073 printf (_("Trailing view pair not used in a range"));
6076 *vstart_ptr
= vstart
;
6079 /* Print a .debug_addr table index in decimal, surrounded by square brackets,
6080 right-adjusted in a field of length LEN, and followed by a space. */
6083 print_addr_index (unsigned int idx
, unsigned int len
)
6085 static char buf
[15];
6086 snprintf (buf
, sizeof (buf
), "[%d]", idx
);
6087 printf ("%*s ", len
, buf
);
6090 /* Display a location list from a .dwo section. It uses address indexes rather
6091 than embedded addresses. This code closely follows display_loc_list, but the
6092 two are sufficiently different that combining things is very ugly. */
6095 display_loc_list_dwo (struct dwarf_section
*section
,
6096 unsigned char **start_ptr
,
6097 unsigned int debug_info_entry
,
6099 unsigned char **vstart_ptr
,
6102 unsigned char *start
= *start_ptr
, *vstart
= *vstart_ptr
;
6103 unsigned char *section_end
= section
->start
+ section
->size
;
6104 unsigned long cu_offset
;
6105 unsigned int pointer_size
;
6106 unsigned int offset_size
;
6109 unsigned short length
;
6110 int need_frame_base
;
6113 if (debug_info_entry
>= num_debug_info_entries
)
6115 warn (_("No debug information for loc lists of entry: %u\n"),
6120 cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
6121 pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
6122 offset_size
= debug_information
[debug_info_entry
].offset_size
;
6123 dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
6125 if (pointer_size
< 2 || pointer_size
> 8)
6127 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
6128 pointer_size
, debug_info_entry
);
6134 printf (" %8.8lx ", (unsigned long) (offset
+ (start
- *start_ptr
)));
6136 if (start
>= section_end
)
6138 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6139 (unsigned long) offset
);
6143 SAFE_BYTE_GET_AND_INC (entry_type
, start
, 1, section_end
);
6156 dwarf_vma off
= offset
+ (vstart
- *start_ptr
);
6158 READ_ULEB (view
, vstart
, section_end
);
6159 print_dwarf_view (view
, 8, 1);
6161 READ_ULEB (view
, vstart
, section_end
);
6162 print_dwarf_view (view
, 8, 1);
6164 printf (_("views at %8.8lx for:\n %*s "),
6165 (unsigned long) off
, 8, "");
6173 case 0: /* A terminating entry. */
6175 *vstart_ptr
= vstart
;
6176 printf (_("<End of list>\n"));
6178 case 1: /* A base-address entry. */
6179 READ_ULEB (idx
, start
, section_end
);
6180 print_addr_index (idx
, 8);
6181 printf ("%*s", 9 + (vstart
? 2 * 6 : 0), "");
6182 printf (_("(base address selection entry)\n"));
6184 case 2: /* A start/end entry. */
6185 READ_ULEB (idx
, start
, section_end
);
6186 print_addr_index (idx
, 8);
6187 READ_ULEB (idx
, start
, section_end
);
6188 print_addr_index (idx
, 8);
6190 case 3: /* A start/length entry. */
6191 READ_ULEB (idx
, start
, section_end
);
6192 print_addr_index (idx
, 8);
6193 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
6194 printf ("%08x ", idx
);
6196 case 4: /* An offset pair entry. */
6197 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
6198 printf ("%08x ", idx
);
6199 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
6200 printf ("%08x ", idx
);
6203 warn (_("Unknown location list entry type 0x%x.\n"), entry_type
);
6205 *vstart_ptr
= vstart
;
6209 if (start
+ 2 > section_end
)
6211 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6212 (unsigned long) offset
);
6216 SAFE_BYTE_GET_AND_INC (length
, start
, 2, section_end
);
6217 if (start
+ length
> section_end
)
6219 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6220 (unsigned long) offset
);
6225 need_frame_base
= decode_location_expression (start
,
6230 cu_offset
, section
);
6233 if (need_frame_base
&& !has_frame_base
)
6234 printf (_(" [without DW_AT_frame_base]"));
6242 *vstart_ptr
= vstart
;
6245 /* Sort array of indexes in ascending order of loc_offsets[idx] and
6248 static dwarf_vma
*loc_offsets
, *loc_views
;
6251 loc_offsets_compar (const void *ap
, const void *bp
)
6253 dwarf_vma a
= loc_offsets
[*(const unsigned int *) ap
];
6254 dwarf_vma b
= loc_offsets
[*(const unsigned int *) bp
];
6256 int ret
= (a
> b
) - (b
> a
);
6260 a
= loc_views
[*(const unsigned int *) ap
];
6261 b
= loc_views
[*(const unsigned int *) bp
];
6263 ret
= (a
> b
) - (b
> a
);
6269 display_debug_loc (struct dwarf_section
*section
, void *file
)
6271 unsigned char *start
= section
->start
, *vstart
= NULL
;
6272 unsigned long bytes
;
6273 unsigned char *section_begin
= start
;
6274 unsigned int num_loc_list
= 0;
6275 unsigned long last_offset
= 0;
6276 unsigned long last_view
= 0;
6277 unsigned int first
= 0;
6280 int seen_first_offset
= 0;
6281 int locs_sorted
= 1;
6282 unsigned char *next
= start
, *vnext
= vstart
;
6283 unsigned int *array
= NULL
;
6284 const char *suffix
= strrchr (section
->name
, '.');
6285 bfd_boolean is_dwo
= FALSE
;
6286 int is_loclists
= strstr (section
->name
, "debug_loclists") != NULL
;
6287 dwarf_vma expected_start
= 0;
6289 if (suffix
&& strcmp (suffix
, ".dwo") == 0)
6292 bytes
= section
->size
;
6296 printf (_("\nThe %s section is empty.\n"), section
->name
);
6302 unsigned char *hdrptr
= section_begin
;
6303 dwarf_vma ll_length
;
6304 unsigned short ll_version
;
6305 unsigned char *end
= section_begin
+ section
->size
;
6306 unsigned char address_size
, segment_selector_size
;
6307 uint32_t offset_entry_count
;
6309 SAFE_BYTE_GET_AND_INC (ll_length
, hdrptr
, 4, end
);
6310 if (ll_length
== 0xffffffff)
6311 SAFE_BYTE_GET_AND_INC (ll_length
, hdrptr
, 8, end
);
6313 SAFE_BYTE_GET_AND_INC (ll_version
, hdrptr
, 2, end
);
6314 if (ll_version
!= 5)
6316 warn (_("The %s section contains corrupt or "
6317 "unsupported version number: %d.\n"),
6318 section
->name
, ll_version
);
6322 SAFE_BYTE_GET_AND_INC (address_size
, hdrptr
, 1, end
);
6324 SAFE_BYTE_GET_AND_INC (segment_selector_size
, hdrptr
, 1, end
);
6325 if (segment_selector_size
!= 0)
6327 warn (_("The %s section contains "
6328 "unsupported segment selector size: %d.\n"),
6329 section
->name
, segment_selector_size
);
6333 SAFE_BYTE_GET_AND_INC (offset_entry_count
, hdrptr
, 4, end
);
6334 if (offset_entry_count
!= 0)
6336 warn (_("The %s section contains "
6337 "unsupported offset entry count: %d.\n"),
6338 section
->name
, offset_entry_count
);
6342 expected_start
= hdrptr
- section_begin
;
6345 if (load_debug_info (file
) == 0)
6347 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
6352 /* Check the order of location list in .debug_info section. If
6353 offsets of location lists are in the ascending order, we can
6354 use `debug_information' directly. */
6355 for (i
= 0; i
< num_debug_info_entries
; i
++)
6359 num
= debug_information
[i
].num_loc_offsets
;
6360 if (num
> num_loc_list
)
6363 /* Check if we can use `debug_information' directly. */
6364 if (locs_sorted
&& num
!= 0)
6366 if (!seen_first_offset
)
6368 /* This is the first location list. */
6369 last_offset
= debug_information
[i
].loc_offsets
[0];
6370 last_view
= debug_information
[i
].loc_views
[0];
6372 seen_first_offset
= 1;
6378 for (; j
< num
; j
++)
6381 debug_information
[i
].loc_offsets
[j
]
6382 || (last_offset
== debug_information
[i
].loc_offsets
[j
]
6383 && last_view
> debug_information
[i
].loc_views
[j
]))
6388 last_offset
= debug_information
[i
].loc_offsets
[j
];
6389 last_view
= debug_information
[i
].loc_views
[j
];
6394 if (!seen_first_offset
)
6395 error (_("No location lists in .debug_info section!\n"));
6397 if (debug_information
[first
].num_loc_offsets
> 0
6398 && debug_information
[first
].loc_offsets
[0] != expected_start
6399 && debug_information
[first
].loc_views
[0] != expected_start
)
6400 warn (_("Location lists in %s section start at 0x%s\n"),
6402 dwarf_vmatoa ("x", debug_information
[first
].loc_offsets
[0]));
6405 array
= (unsigned int *) xcmalloc (num_loc_list
, sizeof (unsigned int));
6407 introduce (section
, FALSE
);
6409 if (reloc_at (section
, 0))
6410 printf (_(" Warning: This section has relocations - addresses seen here may not be accurate.\n\n"));
6412 printf (_(" Offset Begin End Expression\n"));
6414 seen_first_offset
= 0;
6415 for (i
= first
; i
< num_debug_info_entries
; i
++)
6417 dwarf_vma offset
, voffset
;
6418 dwarf_vma base_address
;
6424 for (k
= 0; k
< debug_information
[i
].num_loc_offsets
; k
++)
6426 loc_offsets
= debug_information
[i
].loc_offsets
;
6427 loc_views
= debug_information
[i
].loc_views
;
6428 qsort (array
, debug_information
[i
].num_loc_offsets
,
6429 sizeof (*array
), loc_offsets_compar
);
6432 int adjacent_view_loclists
= 1;
6433 for (k
= 0; k
< debug_information
[i
].num_loc_offsets
; k
++)
6435 j
= locs_sorted
? k
: array
[k
];
6437 && (debug_information
[i
].loc_offsets
[locs_sorted
6438 ? k
- 1 : array
[k
- 1]]
6439 == debug_information
[i
].loc_offsets
[j
])
6440 && (debug_information
[i
].loc_views
[locs_sorted
6441 ? k
- 1 : array
[k
- 1]]
6442 == debug_information
[i
].loc_views
[j
]))
6444 has_frame_base
= debug_information
[i
].have_frame_base
[j
];
6445 offset
= debug_information
[i
].loc_offsets
[j
];
6446 next
= section_begin
+ offset
;
6447 voffset
= debug_information
[i
].loc_views
[j
];
6449 vnext
= section_begin
+ voffset
;
6452 base_address
= debug_information
[i
].base_address
;
6454 if (vnext
&& vnext
< next
)
6457 display_view_pair_list (section
, &vstart
, i
, next
);
6462 if (!seen_first_offset
|| !adjacent_view_loclists
)
6463 seen_first_offset
= 1;
6467 warn (_("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n"),
6468 (unsigned long) (start
- section_begin
),
6469 (unsigned long) offset
);
6470 else if (start
> next
)
6471 warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n"),
6472 (unsigned long) (start
- section_begin
),
6473 (unsigned long) offset
);
6478 if (offset
>= bytes
)
6480 warn (_("Offset 0x%lx is bigger than .debug_loc section size.\n"),
6481 (unsigned long) offset
);
6485 if (vnext
&& voffset
>= bytes
)
6487 warn (_("View Offset 0x%lx is bigger than .debug_loc section size.\n"),
6488 (unsigned long) voffset
);
6495 display_loc_list_dwo (section
, &start
, i
, offset
,
6496 &vstart
, has_frame_base
);
6498 display_loc_list (section
, &start
, i
, offset
, base_address
,
6499 &vstart
, has_frame_base
);
6504 warn (_("DWO is not yet supported.\n"));
6506 display_loclists_list (section
, &start
, i
, offset
, base_address
,
6507 &vstart
, has_frame_base
);
6510 /* FIXME: this arrangement is quite simplistic. Nothing
6511 requires locview lists to be adjacent to corresponding
6512 loclists, and a single loclist could be augmented by
6513 different locview lists, and vice-versa, unlikely as it
6514 is that it would make sense to do so. Hopefully we'll
6515 have view pair support built into loclists before we ever
6516 need to address all these possibilities. */
6517 if (adjacent_view_loclists
&& vnext
6518 && vnext
!= start
&& vstart
!= next
)
6520 adjacent_view_loclists
= 0;
6521 warn (_("Hole and overlap detection requires adjacent view lists and loclists.\n"));
6524 if (vnext
&& vnext
== start
)
6525 display_view_pair_list (section
, &start
, i
, vstart
);
6529 if (start
< section
->start
+ section
->size
)
6530 warn (ngettext ("There is %ld unused byte at the end of section %s\n",
6531 "There are %ld unused bytes at the end of section %s\n",
6532 (long) (section
->start
+ section
->size
- start
)),
6533 (long) (section
->start
+ section
->size
- start
), section
->name
);
6540 display_debug_str (struct dwarf_section
*section
,
6541 void *file ATTRIBUTE_UNUSED
)
6543 unsigned char *start
= section
->start
;
6544 unsigned long bytes
= section
->size
;
6545 dwarf_vma addr
= section
->address
;
6549 printf (_("\nThe %s section is empty.\n"), section
->name
);
6553 introduce (section
, FALSE
);
6561 lbytes
= (bytes
> 16 ? 16 : bytes
);
6563 printf (" 0x%8.8lx ", (unsigned long) addr
);
6565 for (j
= 0; j
< 16; j
++)
6568 printf ("%2.2x", start
[j
]);
6576 for (j
= 0; j
< lbytes
; j
++)
6579 if (k
>= ' ' && k
< 0x80)
6598 display_debug_info (struct dwarf_section
*section
, void *file
)
6600 return process_debug_info (section
, file
, section
->abbrev_sec
, FALSE
, FALSE
);
6604 display_debug_types (struct dwarf_section
*section
, void *file
)
6606 return process_debug_info (section
, file
, section
->abbrev_sec
, FALSE
, TRUE
);
6610 display_trace_info (struct dwarf_section
*section
, void *file
)
6612 return process_debug_info (section
, file
, section
->abbrev_sec
, FALSE
, TRUE
);
6616 display_debug_aranges (struct dwarf_section
*section
,
6617 void *file ATTRIBUTE_UNUSED
)
6619 unsigned char *start
= section
->start
;
6620 unsigned char *end
= start
+ section
->size
;
6622 introduce (section
, FALSE
);
6624 /* It does not matter if this load fails,
6625 we test for that later on. */
6626 load_debug_info (file
);
6630 unsigned char *hdrptr
;
6631 DWARF2_Internal_ARange arange
;
6632 unsigned char *addr_ranges
;
6635 unsigned long sec_off
;
6636 unsigned char address_size
;
6638 unsigned int offset_size
;
6639 unsigned int initial_length_size
;
6643 SAFE_BYTE_GET_AND_INC (arange
.ar_length
, hdrptr
, 4, end
);
6644 if (arange
.ar_length
== 0xffffffff)
6646 SAFE_BYTE_GET_AND_INC (arange
.ar_length
, hdrptr
, 8, end
);
6648 initial_length_size
= 12;
6653 initial_length_size
= 4;
6656 sec_off
= hdrptr
- section
->start
;
6657 if (sec_off
+ arange
.ar_length
< sec_off
6658 || sec_off
+ arange
.ar_length
> section
->size
)
6660 warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"),
6662 sec_off
- initial_length_size
,
6663 dwarf_vmatoa ("x", arange
.ar_length
));
6667 SAFE_BYTE_GET_AND_INC (arange
.ar_version
, hdrptr
, 2, end
);
6668 SAFE_BYTE_GET_AND_INC (arange
.ar_info_offset
, hdrptr
, offset_size
, end
);
6670 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
6671 && num_debug_info_entries
> 0
6672 && find_debug_info_for_offset (arange
.ar_info_offset
) == NULL
)
6673 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
6674 (unsigned long) arange
.ar_info_offset
, section
->name
);
6676 SAFE_BYTE_GET_AND_INC (arange
.ar_pointer_size
, hdrptr
, 1, end
);
6677 SAFE_BYTE_GET_AND_INC (arange
.ar_segment_size
, hdrptr
, 1, end
);
6679 if (arange
.ar_version
!= 2 && arange
.ar_version
!= 3)
6681 /* PR 19872: A version number of 0 probably means that there is
6682 padding at the end of the .debug_aranges section. Gold puts
6683 it there when performing an incremental link, for example.
6684 So do not generate a warning in this case. */
6685 if (arange
.ar_version
)
6686 warn (_("Only DWARF 2 and 3 aranges are currently supported.\n"));
6690 printf (_(" Length: %ld\n"),
6691 (long) arange
.ar_length
);
6692 printf (_(" Version: %d\n"), arange
.ar_version
);
6693 printf (_(" Offset into .debug_info: 0x%lx\n"),
6694 (unsigned long) arange
.ar_info_offset
);
6695 printf (_(" Pointer Size: %d\n"), arange
.ar_pointer_size
);
6696 printf (_(" Segment Size: %d\n"), arange
.ar_segment_size
);
6698 address_size
= arange
.ar_pointer_size
+ arange
.ar_segment_size
;
6700 /* PR 17512: file: 001-108546-0.001:0.1. */
6701 if (address_size
== 0 || address_size
> 8)
6703 error (_("Invalid address size in %s section!\n"),
6708 /* The DWARF spec does not require that the address size be a power
6709 of two, but we do. This will have to change if we ever encounter
6710 an uneven architecture. */
6711 if ((address_size
& (address_size
- 1)) != 0)
6713 warn (_("Pointer size + Segment size is not a power of two.\n"));
6717 if (address_size
> 4)
6718 printf (_("\n Address Length\n"));
6720 printf (_("\n Address Length\n"));
6722 addr_ranges
= hdrptr
;
6724 /* Must pad to an alignment boundary that is twice the address size. */
6725 excess
= (hdrptr
- start
) % (2 * address_size
);
6727 addr_ranges
+= (2 * address_size
) - excess
;
6729 start
+= arange
.ar_length
+ initial_length_size
;
6731 while (addr_ranges
+ 2 * address_size
<= start
)
6733 SAFE_BYTE_GET_AND_INC (address
, addr_ranges
, address_size
, end
);
6734 SAFE_BYTE_GET_AND_INC (length
, addr_ranges
, address_size
, end
);
6737 print_dwarf_vma (address
, address_size
);
6738 print_dwarf_vma (length
, address_size
);
6748 /* Comparison function for qsort. */
6750 comp_addr_base (const void * v0
, const void * v1
)
6752 debug_info
*info0
= *(debug_info
**) v0
;
6753 debug_info
*info1
= *(debug_info
**) v1
;
6754 return info0
->addr_base
- info1
->addr_base
;
6757 /* Display the debug_addr section. */
6759 display_debug_addr (struct dwarf_section
*section
,
6762 debug_info
**debug_addr_info
;
6763 unsigned char *entry
;
6768 if (section
->size
== 0)
6770 printf (_("\nThe %s section is empty.\n"), section
->name
);
6774 if (load_debug_info (file
) == 0)
6776 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
6781 introduce (section
, FALSE
);
6783 /* PR 17531: file: cf38d01b.
6784 We use xcalloc because a corrupt file may not have initialised all of the
6785 fields in the debug_info structure, which means that the sort below might
6786 try to move uninitialised data. */
6787 debug_addr_info
= (debug_info
**) xcalloc ((num_debug_info_entries
+ 1),
6788 sizeof (debug_info
*));
6791 for (i
= 0; i
< num_debug_info_entries
; i
++)
6792 if (debug_information
[i
].addr_base
!= DEBUG_INFO_UNAVAILABLE
)
6794 /* PR 17531: file: cf38d01b. */
6795 if (debug_information
[i
].addr_base
>= section
->size
)
6796 warn (_("Corrupt address base (%lx) found in debug section %u\n"),
6797 (unsigned long) debug_information
[i
].addr_base
, i
);
6799 debug_addr_info
[count
++] = debug_information
+ i
;
6802 /* Add a sentinel to make iteration convenient. */
6803 debug_addr_info
[count
] = (debug_info
*) xmalloc (sizeof (debug_info
));
6804 debug_addr_info
[count
]->addr_base
= section
->size
;
6805 qsort (debug_addr_info
, count
, sizeof (debug_info
*), comp_addr_base
);
6807 for (i
= 0; i
< count
; i
++)
6810 unsigned int address_size
= debug_addr_info
[i
]->pointer_size
;
6812 printf (_(" For compilation unit at offset 0x%s:\n"),
6813 dwarf_vmatoa ("x", debug_addr_info
[i
]->cu_offset
));
6815 printf (_("\tIndex\tAddress\n"));
6816 entry
= section
->start
+ debug_addr_info
[i
]->addr_base
;
6817 end
= section
->start
+ debug_addr_info
[i
+ 1]->addr_base
;
6821 dwarf_vma base
= byte_get (entry
, address_size
);
6822 printf (_("\t%d:\t"), idx
);
6823 print_dwarf_vma (base
, address_size
);
6825 entry
+= address_size
;
6831 free (debug_addr_info
);
6835 /* Display the .debug_str_offsets and .debug_str_offsets.dwo sections. */
6838 display_debug_str_offsets (struct dwarf_section
*section
,
6839 void *file ATTRIBUTE_UNUSED
)
6841 if (section
->size
== 0)
6843 printf (_("\nThe %s section is empty.\n"), section
->name
);
6847 unsigned char *start
= section
->start
;
6848 unsigned char *end
= start
+ section
->size
;
6849 unsigned char *curr
= start
;
6851 load_debug_section_with_follow (str
, file
);
6853 introduce (section
, FALSE
);
6858 dwarf_vma entry_length
;
6860 SAFE_BYTE_GET_AND_INC (length
, curr
, 4, end
);
6861 /* FIXME: We assume that this means 64-bit DWARF is being used. */
6862 if (length
== 0xffffffff)
6864 SAFE_BYTE_GET (length
, curr
, 8, end
);
6871 SAFE_BYTE_GET_AND_INC (version
, curr
, 2, end
);
6873 warn (_("Unexpected version number in str_offset header: %#x\n"), version
);
6876 SAFE_BYTE_GET_AND_INC (padding
, curr
, 2, end
);
6878 warn (_("Unexpected value in str_offset header's padding field: %#x\n"), padding
);
6880 printf (_(" Length: %#lx\n"), (unsigned long) length
);
6881 printf (_(" Version: %#lx\n"), (unsigned long) version
);
6882 printf (_(" Index Offset [String]\n"));
6884 unsigned long index
;
6885 for (index
= 0; length
>= entry_length
&& curr
< end
; index
++)
6888 const unsigned char * string
;
6890 SAFE_BYTE_GET_AND_INC (offset
, curr
, entry_length
, end
);
6891 string
= fetch_indirect_string (offset
);
6892 printf (" %8lu %s %s\n", index
,
6893 dwarf_vmatoa (NULL
, offset
),
6897 /* TODO: Dump the contents. This is made somewhat difficult by not knowing
6898 what the offset size is for this section. */
6902 /* Each debug_information[x].range_lists[y] gets this representation for
6903 sorting purposes. */
6907 /* The debug_information[x].range_lists[y] value. */
6908 dwarf_vma ranges_offset
;
6910 /* Original debug_information to find parameters of the data. */
6911 debug_info
*debug_info_p
;
6914 /* Sort struct range_entry in ascending order of its RANGES_OFFSET. */
6917 range_entry_compar (const void *ap
, const void *bp
)
6919 const struct range_entry
*a_re
= (const struct range_entry
*) ap
;
6920 const struct range_entry
*b_re
= (const struct range_entry
*) bp
;
6921 const dwarf_vma a
= a_re
->ranges_offset
;
6922 const dwarf_vma b
= b_re
->ranges_offset
;
6924 return (a
> b
) - (b
> a
);
6928 display_debug_ranges_list (unsigned char *start
, unsigned char *finish
,
6929 unsigned int pointer_size
, unsigned long offset
,
6930 unsigned long base_address
)
6932 while (start
< finish
)
6937 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
6938 if (start
>= finish
)
6940 SAFE_SIGNED_BYTE_GET_AND_INC (end
, start
, pointer_size
, finish
);
6943 printf (" %8.8lx ", offset
);
6945 if (begin
== 0 && end
== 0)
6947 printf (_("<End of list>\n"));
6951 /* Check base address specifiers. */
6952 if (is_max_address (begin
, pointer_size
)
6953 && !is_max_address (end
, pointer_size
))
6956 print_dwarf_vma (begin
, pointer_size
);
6957 print_dwarf_vma (end
, pointer_size
);
6958 printf ("(base address)\n");
6962 print_dwarf_vma (begin
+ base_address
, pointer_size
);
6963 print_dwarf_vma (end
+ base_address
, pointer_size
);
6966 fputs (_("(start == end)"), stdout
);
6967 else if (begin
> end
)
6968 fputs (_("(start > end)"), stdout
);
6975 display_debug_rnglists_list (unsigned char *start
, unsigned char *finish
,
6976 unsigned int pointer_size
, unsigned long offset
,
6977 unsigned long base_address
)
6979 unsigned char *next
= start
;
6983 unsigned long off
= offset
+ (start
- next
);
6984 enum dwarf_range_list_entry rlet
;
6985 /* Initialize it due to a false compiler warning. */
6986 dwarf_vma begin
= -1, length
, end
= -1;
6988 if (start
+ 1 > finish
)
6990 warn (_("Range list starting at offset 0x%lx is not terminated.\n"),
6995 printf (" %8.8lx ", off
);
6997 SAFE_BYTE_GET_AND_INC (rlet
, start
, 1, finish
);
7001 case DW_RLE_end_of_list
:
7002 printf (_("<End of list>\n"));
7004 case DW_RLE_base_address
:
7005 SAFE_BYTE_GET_AND_INC (base_address
, start
, pointer_size
, finish
);
7006 print_dwarf_vma (base_address
, pointer_size
);
7007 printf (_("(base address)\n"));
7009 case DW_RLE_start_length
:
7010 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
7011 READ_ULEB (length
, start
, finish
);
7012 end
= begin
+ length
;
7014 case DW_RLE_offset_pair
:
7015 READ_ULEB (begin
, start
, finish
);
7016 READ_ULEB (end
, start
, finish
);
7018 case DW_RLE_start_end
:
7019 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
7020 SAFE_BYTE_GET_AND_INC (end
, start
, pointer_size
, finish
);
7023 error (_("Invalid range list entry type %d\n"), rlet
);
7024 rlet
= DW_RLE_end_of_list
;
7027 if (rlet
== DW_RLE_end_of_list
)
7029 if (rlet
== DW_RLE_base_address
)
7032 print_dwarf_vma (begin
+ base_address
, pointer_size
);
7033 print_dwarf_vma (end
+ base_address
, pointer_size
);
7036 fputs (_("(start == end)"), stdout
);
7037 else if (begin
> end
)
7038 fputs (_("(start > end)"), stdout
);
7045 display_debug_ranges (struct dwarf_section
*section
,
7046 void *file ATTRIBUTE_UNUSED
)
7048 unsigned char *start
= section
->start
;
7049 unsigned char *last_start
= start
;
7050 unsigned long bytes
= section
->size
;
7051 unsigned char *section_begin
= start
;
7052 unsigned char *finish
= start
+ bytes
;
7053 unsigned int num_range_list
, i
;
7054 struct range_entry
*range_entries
, *range_entry_fill
;
7055 int is_rnglists
= strstr (section
->name
, "debug_rnglists") != NULL
;
7056 /* Initialize it due to a false compiler warning. */
7057 unsigned char address_size
= 0;
7058 dwarf_vma last_offset
= 0;
7062 printf (_("\nThe %s section is empty.\n"), section
->name
);
7068 dwarf_vma initial_length
;
7069 unsigned int initial_length_size
;
7070 unsigned char segment_selector_size
;
7071 unsigned int offset_size
, offset_entry_count
;
7072 unsigned short version
;
7074 /* Get and check the length of the block. */
7075 SAFE_BYTE_GET_AND_INC (initial_length
, start
, 4, finish
);
7077 if (initial_length
== 0xffffffff)
7079 /* This section is 64-bit DWARF 3. */
7080 SAFE_BYTE_GET_AND_INC (initial_length
, start
, 8, finish
);
7082 initial_length_size
= 12;
7087 initial_length_size
= 4;
7090 if (initial_length
+ initial_length_size
> section
->size
)
7092 /* If the length field has a relocation against it, then we should
7093 not complain if it is inaccurate (and probably negative).
7094 It is copied from .debug_line handling code. */
7095 if (reloc_at (section
, (start
- section
->start
) - offset_size
))
7097 initial_length
= (finish
- start
) - initial_length_size
;
7101 warn (_("The length field (0x%lx) in the debug_rnglists header is wrong - the section is too small\n"),
7102 (long) initial_length
);
7107 /* Get and check the version number. */
7108 SAFE_BYTE_GET_AND_INC (version
, start
, 2, finish
);
7112 warn (_("Only DWARF version 5 debug_rnglists info "
7113 "is currently supported.\n"));
7117 SAFE_BYTE_GET_AND_INC (address_size
, start
, 1, finish
);
7119 SAFE_BYTE_GET_AND_INC (segment_selector_size
, start
, 1, finish
);
7120 if (segment_selector_size
!= 0)
7122 warn (_("The %s section contains "
7123 "unsupported segment selector size: %d.\n"),
7124 section
->name
, segment_selector_size
);
7128 SAFE_BYTE_GET_AND_INC (offset_entry_count
, start
, 4, finish
);
7129 if (offset_entry_count
!= 0)
7131 warn (_("The %s section contains "
7132 "unsupported offset entry count: %u.\n"),
7133 section
->name
, offset_entry_count
);
7138 if (load_debug_info (file
) == 0)
7140 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
7146 for (i
= 0; i
< num_debug_info_entries
; i
++)
7147 num_range_list
+= debug_information
[i
].num_range_lists
;
7149 if (num_range_list
== 0)
7151 /* This can happen when the file was compiled with -gsplit-debug
7152 which removes references to range lists from the primary .o file. */
7153 printf (_("No range lists in .debug_info section.\n"));
7157 range_entries
= (struct range_entry
*)
7158 xmalloc (sizeof (*range_entries
) * num_range_list
);
7159 range_entry_fill
= range_entries
;
7161 for (i
= 0; i
< num_debug_info_entries
; i
++)
7163 debug_info
*debug_info_p
= &debug_information
[i
];
7166 for (j
= 0; j
< debug_info_p
->num_range_lists
; j
++)
7168 range_entry_fill
->ranges_offset
= debug_info_p
->range_lists
[j
];
7169 range_entry_fill
->debug_info_p
= debug_info_p
;
7174 qsort (range_entries
, num_range_list
, sizeof (*range_entries
),
7175 range_entry_compar
);
7177 if (dwarf_check
!= 0 && range_entries
[0].ranges_offset
!= 0)
7178 warn (_("Range lists in %s section start at 0x%lx\n"),
7179 section
->name
, (unsigned long) range_entries
[0].ranges_offset
);
7181 introduce (section
, FALSE
);
7183 printf (_(" Offset Begin End\n"));
7185 for (i
= 0; i
< num_range_list
; i
++)
7187 struct range_entry
*range_entry
= &range_entries
[i
];
7188 debug_info
*debug_info_p
= range_entry
->debug_info_p
;
7189 unsigned int pointer_size
;
7191 unsigned char *next
;
7192 dwarf_vma base_address
;
7194 pointer_size
= (is_rnglists
? address_size
: debug_info_p
->pointer_size
);
7195 offset
= range_entry
->ranges_offset
;
7196 next
= section_begin
+ offset
;
7197 base_address
= debug_info_p
->base_address
;
7199 /* PR 17512: file: 001-101485-0.001:0.1. */
7200 if (pointer_size
< 2 || pointer_size
> 8)
7202 warn (_("Corrupt pointer size (%d) in debug entry at offset %8.8lx\n"),
7203 pointer_size
, (unsigned long) offset
);
7207 if (next
< section_begin
|| next
>= finish
)
7209 warn (_("Corrupt offset (%#8.8lx) in range entry %u\n"),
7210 (unsigned long) offset
, i
);
7214 /* If multiple DWARF entities reference the same range then we will
7215 have multiple entries in the `range_entries' list for the same
7216 offset. Thanks to the sort above these will all be consecutive in
7217 the `range_entries' list, so we can easily ignore duplicates
7219 if (i
> 0 && last_offset
== offset
)
7221 last_offset
= offset
;
7223 if (dwarf_check
!= 0 && i
> 0)
7226 warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"),
7227 (unsigned long) (start
- section_begin
),
7228 (unsigned long) (next
- section_begin
), section
->name
);
7229 else if (start
> next
)
7231 if (next
== last_start
)
7233 warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"),
7234 (unsigned long) (start
- section_begin
),
7235 (unsigned long) (next
- section_begin
), section
->name
);
7242 (is_rnglists
? display_debug_rnglists_list
: display_debug_ranges_list
)
7243 (start
, finish
, pointer_size
, offset
, base_address
);
7247 free (range_entries
);
7252 typedef struct Frame_Chunk
7254 struct Frame_Chunk
*next
;
7255 unsigned char *chunk_start
;
7257 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
7258 short int *col_type
;
7261 unsigned int code_factor
;
7265 unsigned int cfa_reg
;
7266 dwarf_vma cfa_offset
;
7268 unsigned char fde_encoding
;
7269 unsigned char cfa_exp
;
7270 unsigned char ptr_size
;
7271 unsigned char segment_size
;
7275 typedef const char *(*dwarf_regname_lookup_ftype
) (unsigned int);
7276 static dwarf_regname_lookup_ftype dwarf_regnames_lookup_func
;
7277 static const char *const *dwarf_regnames
;
7278 static unsigned int dwarf_regnames_count
;
7281 /* A marker for a col_type that means this column was never referenced
7282 in the frame info. */
7283 #define DW_CFA_unreferenced (-1)
7285 /* Return 0 if no more space is needed, 1 if more space is needed,
7286 -1 for invalid reg. */
7289 frame_need_space (Frame_Chunk
*fc
, unsigned int reg
)
7291 unsigned int prev
= fc
->ncols
;
7293 if (reg
< (unsigned int) fc
->ncols
)
7296 if (dwarf_regnames_count
> 0
7297 && reg
> dwarf_regnames_count
)
7300 fc
->ncols
= reg
+ 1;
7301 /* PR 17512: file: 10450-2643-0.004.
7302 If reg == -1 then this can happen... */
7306 /* PR 17512: file: 2844a11d. */
7307 if (fc
->ncols
> 1024 && dwarf_regnames_count
== 0)
7309 error (_("Unfeasibly large register number: %u\n"), reg
);
7311 /* FIXME: 1024 is an arbitrary limit. Increase it if
7312 we ever encounter a valid binary that exceeds it. */
7316 fc
->col_type
= (short int *) xcrealloc (fc
->col_type
, fc
->ncols
,
7317 sizeof (short int));
7318 fc
->col_offset
= (int *) xcrealloc (fc
->col_offset
, fc
->ncols
, sizeof (int));
7319 /* PR 17512: file:002-10025-0.005. */
7320 if (fc
->col_type
== NULL
|| fc
->col_offset
== NULL
)
7322 error (_("Out of memory allocating %u columns in dwarf frame arrays\n"),
7328 while (prev
< fc
->ncols
)
7330 fc
->col_type
[prev
] = DW_CFA_unreferenced
;
7331 fc
->col_offset
[prev
] = 0;
7337 static const char *const dwarf_regnames_i386
[] =
7339 "eax", "ecx", "edx", "ebx", /* 0 - 3 */
7340 "esp", "ebp", "esi", "edi", /* 4 - 7 */
7341 "eip", "eflags", NULL
, /* 8 - 10 */
7342 "st0", "st1", "st2", "st3", /* 11 - 14 */
7343 "st4", "st5", "st6", "st7", /* 15 - 18 */
7344 NULL
, NULL
, /* 19 - 20 */
7345 "xmm0", "xmm1", "xmm2", "xmm3", /* 21 - 24 */
7346 "xmm4", "xmm5", "xmm6", "xmm7", /* 25 - 28 */
7347 "mm0", "mm1", "mm2", "mm3", /* 29 - 32 */
7348 "mm4", "mm5", "mm6", "mm7", /* 33 - 36 */
7349 "fcw", "fsw", "mxcsr", /* 37 - 39 */
7350 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
, /* 40 - 47 */
7351 "tr", "ldtr", /* 48 - 49 */
7352 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 50 - 57 */
7353 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 58 - 65 */
7354 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 66 - 73 */
7355 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 74 - 81 */
7356 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 82 - 89 */
7357 NULL
, NULL
, NULL
, /* 90 - 92 */
7358 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7" /* 93 - 100 */
7361 static const char *const dwarf_regnames_iamcu
[] =
7363 "eax", "ecx", "edx", "ebx", /* 0 - 3 */
7364 "esp", "ebp", "esi", "edi", /* 4 - 7 */
7365 "eip", "eflags", NULL
, /* 8 - 10 */
7366 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 11 - 18 */
7367 NULL
, NULL
, /* 19 - 20 */
7368 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 21 - 28 */
7369 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 29 - 36 */
7370 NULL
, NULL
, NULL
, /* 37 - 39 */
7371 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
, /* 40 - 47 */
7372 "tr", "ldtr", /* 48 - 49 */
7373 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 50 - 57 */
7374 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 58 - 65 */
7375 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 66 - 73 */
7376 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 74 - 81 */
7377 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 82 - 89 */
7378 NULL
, NULL
, NULL
, /* 90 - 92 */
7379 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
/* 93 - 100 */
7383 init_dwarf_regnames_i386 (void)
7385 dwarf_regnames
= dwarf_regnames_i386
;
7386 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_i386
);
7387 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
7391 init_dwarf_regnames_iamcu (void)
7393 dwarf_regnames
= dwarf_regnames_iamcu
;
7394 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_iamcu
);
7395 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
7398 static const char *const dwarf_regnames_x86_64
[] =
7400 "rax", "rdx", "rcx", "rbx",
7401 "rsi", "rdi", "rbp", "rsp",
7402 "r8", "r9", "r10", "r11",
7403 "r12", "r13", "r14", "r15",
7405 "xmm0", "xmm1", "xmm2", "xmm3",
7406 "xmm4", "xmm5", "xmm6", "xmm7",
7407 "xmm8", "xmm9", "xmm10", "xmm11",
7408 "xmm12", "xmm13", "xmm14", "xmm15",
7409 "st0", "st1", "st2", "st3",
7410 "st4", "st5", "st6", "st7",
7411 "mm0", "mm1", "mm2", "mm3",
7412 "mm4", "mm5", "mm6", "mm7",
7414 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
,
7415 "fs.base", "gs.base", NULL
, NULL
,
7417 "mxcsr", "fcw", "fsw",
7418 "xmm16", "xmm17", "xmm18", "xmm19",
7419 "xmm20", "xmm21", "xmm22", "xmm23",
7420 "xmm24", "xmm25", "xmm26", "xmm27",
7421 "xmm28", "xmm29", "xmm30", "xmm31",
7422 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 83 - 90 */
7423 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 91 - 98 */
7424 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 99 - 106 */
7425 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 107 - 114 */
7426 NULL
, NULL
, NULL
, /* 115 - 117 */
7427 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7"
7431 init_dwarf_regnames_x86_64 (void)
7433 dwarf_regnames
= dwarf_regnames_x86_64
;
7434 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_x86_64
);
7435 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
7438 static const char *const dwarf_regnames_aarch64
[] =
7440 "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7",
7441 "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15",
7442 "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23",
7443 "x24", "x25", "x26", "x27", "x28", "x29", "x30", "sp",
7444 NULL
, "elr", NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
7445 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, "vg", "ffr",
7446 "p0", "p1", "p2", "p3", "p4", "p5", "p6", "p7",
7447 "p8", "p9", "p10", "p11", "p12", "p13", "p14", "p15",
7448 "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7",
7449 "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15",
7450 "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23",
7451 "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31",
7452 "z0", "z1", "z2", "z3", "z4", "z5", "z6", "z7",
7453 "z8", "z9", "z10", "z11", "z12", "z13", "z14", "z15",
7454 "z16", "z17", "z18", "z19", "z20", "z21", "z22", "z23",
7455 "z24", "z25", "z26", "z27", "z28", "z29", "z30", "z31",
7459 init_dwarf_regnames_aarch64 (void)
7461 dwarf_regnames
= dwarf_regnames_aarch64
;
7462 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_aarch64
);
7463 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
7466 static const char *const dwarf_regnames_s390
[] =
7468 /* Avoid saying "r5 (r5)", so omit the names of r0-r15. */
7469 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
7470 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
7471 "f0", "f2", "f4", "f6", "f1", "f3", "f5", "f7",
7472 "f8", "f10", "f12", "f14", "f9", "f11", "f13", "f15",
7473 "cr0", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7",
7474 "cr8", "cr9", "cr10", "cr11", "cr12", "cr13", "cr14", "cr15",
7475 "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7",
7476 "a8", "a9", "a10", "a11", "a12", "a13", "a14", "a15",
7479 "v16", "v18", "v20", "v22", "v17", "v19", "v21", "v23",
7480 "v24", "v26", "v28", "v30", "v25", "v27", "v29", "v31",
7484 init_dwarf_regnames_s390 (void)
7486 dwarf_regnames
= dwarf_regnames_s390
;
7487 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_s390
);
7488 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
7491 static const char *const dwarf_regnames_riscv
[] =
7493 "zero", "ra", "sp", "gp", "tp", "t0", "t1", "t2", /* 0 - 7 */
7494 "s0", "s1", "a0", "a1", "a2", "a3", "a4", "a5", /* 8 - 15 */
7495 "a6", "a7", "s2", "s3", "s4", "s5", "s6", "s7", /* 16 - 23 */
7496 "s8", "s9", "s10", "s11", "t3", "t4", "t5", "t6", /* 24 - 31 */
7497 "ft0", "ft1", "ft2", "ft3", "ft4", "ft5", "ft6", "ft7", /* 32 - 39 */
7498 "fs0", "fs1", /* 40 - 41 */
7499 "fa0", "fa1", "fa2", "fa3", "fa4", "fa5", "fa6", "fa7", /* 42 - 49 */
7500 "fs2", "fs3", "fs4", "fs5", "fs6", "fs7", "fs8", "fs9", /* 50 - 57 */
7501 "fs10", "fs11", /* 58 - 59 */
7502 "ft8", "ft9", "ft10", "ft11" /* 60 - 63 */
7505 /* A RISC-V replacement for REGNAME_INTERNAL_BY_TABLE_ONLY which handles
7506 the large number of CSRs. */
7509 regname_internal_riscv (unsigned int regno
)
7511 const char *name
= NULL
;
7513 /* Lookup in the table first, this covers GPR and FPR. */
7514 if (regno
< ARRAY_SIZE (dwarf_regnames_riscv
))
7515 name
= dwarf_regnames_riscv
[regno
];
7516 else if (regno
>= 4096 && regno
<= 8191)
7518 /* This might be a CSR, these live in a sparse number space from 4096
7519 to 8191 These numbers are defined in the RISC-V ELF ABI
7523 #define DECLARE_CSR(NAME,VALUE,CLASS,DEFINE_VER,ABORT_VER) \
7524 case VALUE + 4096: name = #NAME; break;
7525 #include "opcode/riscv-opc.h"
7530 static char csr_name
[10];
7531 snprintf (csr_name
, sizeof (csr_name
), "csr%d", (regno
- 4096));
7542 init_dwarf_regnames_riscv (void)
7544 dwarf_regnames
= NULL
;
7545 dwarf_regnames_count
= 8192;
7546 dwarf_regnames_lookup_func
= regname_internal_riscv
;
7550 init_dwarf_regnames_by_elf_machine_code (unsigned int e_machine
)
7552 dwarf_regnames_lookup_func
= NULL
;
7557 init_dwarf_regnames_i386 ();
7561 init_dwarf_regnames_iamcu ();
7567 init_dwarf_regnames_x86_64 ();
7571 init_dwarf_regnames_aarch64 ();
7575 init_dwarf_regnames_s390 ();
7579 init_dwarf_regnames_riscv ();
7587 /* Initialize the DWARF register name lookup state based on the
7588 architecture and specific machine type of a BFD. */
7591 init_dwarf_regnames_by_bfd_arch_and_mach (enum bfd_architecture arch
,
7594 dwarf_regnames_lookup_func
= NULL
;
7601 case bfd_mach_x86_64
:
7602 case bfd_mach_x86_64_intel_syntax
:
7603 case bfd_mach_x86_64_nacl
:
7604 case bfd_mach_x64_32
:
7605 case bfd_mach_x64_32_intel_syntax
:
7606 case bfd_mach_x64_32_nacl
:
7607 init_dwarf_regnames_x86_64 ();
7611 init_dwarf_regnames_i386 ();
7616 case bfd_arch_iamcu
:
7617 init_dwarf_regnames_iamcu ();
7620 case bfd_arch_aarch64
:
7621 init_dwarf_regnames_aarch64();
7625 init_dwarf_regnames_s390 ();
7628 case bfd_arch_riscv
:
7629 init_dwarf_regnames_riscv ();
7638 regname_internal_by_table_only (unsigned int regno
)
7640 if (dwarf_regnames
!= NULL
7641 && regno
< dwarf_regnames_count
7642 && dwarf_regnames
[regno
] != NULL
)
7643 return dwarf_regnames
[regno
];
7649 regname (unsigned int regno
, int name_only_p
)
7651 static char reg
[64];
7653 const char *name
= NULL
;
7655 if (dwarf_regnames_lookup_func
!= NULL
)
7656 name
= dwarf_regnames_lookup_func (regno
);
7662 snprintf (reg
, sizeof (reg
), "r%d (%s)", regno
, name
);
7665 snprintf (reg
, sizeof (reg
), "r%d", regno
);
7670 frame_display_row (Frame_Chunk
*fc
, int *need_col_headers
, unsigned int *max_regs
)
7675 if (*max_regs
!= fc
->ncols
)
7676 *max_regs
= fc
->ncols
;
7678 if (*need_col_headers
)
7680 static const char *sloc
= " LOC";
7682 *need_col_headers
= 0;
7684 printf ("%-*s CFA ", eh_addr_size
* 2, sloc
);
7686 for (r
= 0; r
< *max_regs
; r
++)
7687 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
7692 printf ("%-5s ", regname (r
, 1));
7698 print_dwarf_vma (fc
->pc_begin
, eh_addr_size
);
7700 strcpy (tmp
, "exp");
7702 sprintf (tmp
, "%s%+d", regname (fc
->cfa_reg
, 1), (int) fc
->cfa_offset
);
7703 printf ("%-8s ", tmp
);
7705 for (r
= 0; r
< fc
->ncols
; r
++)
7707 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
7709 switch (fc
->col_type
[r
])
7711 case DW_CFA_undefined
:
7714 case DW_CFA_same_value
:
7718 sprintf (tmp
, "c%+d", fc
->col_offset
[r
]);
7720 case DW_CFA_val_offset
:
7721 sprintf (tmp
, "v%+d", fc
->col_offset
[r
]);
7723 case DW_CFA_register
:
7724 sprintf (tmp
, "%s", regname (fc
->col_offset
[r
], 0));
7726 case DW_CFA_expression
:
7727 strcpy (tmp
, "exp");
7729 case DW_CFA_val_expression
:
7730 strcpy (tmp
, "vexp");
7733 strcpy (tmp
, "n/a");
7736 printf ("%-5s ", tmp
);
7742 #define GET(VAR, N) SAFE_BYTE_GET_AND_INC (VAR, start, N, end)
7744 static unsigned char *
7745 read_cie (unsigned char *start
, unsigned char *end
,
7746 Frame_Chunk
**p_cie
, int *p_version
,
7747 bfd_size_type
*p_aug_len
, unsigned char **p_aug
)
7751 unsigned char *augmentation_data
= NULL
;
7752 bfd_size_type augmentation_data_len
= 0;
7755 /* PR 17512: file: 001-228113-0.004. */
7759 fc
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
7760 memset (fc
, 0, sizeof (Frame_Chunk
));
7762 fc
->col_type
= (short int *) xmalloc (sizeof (short int));
7763 fc
->col_offset
= (int *) xmalloc (sizeof (int));
7767 fc
->augmentation
= (char *) start
;
7768 /* PR 17512: file: 001-228113-0.004.
7769 Skip past augmentation name, but avoid running off the end of the data. */
7771 if (* start
++ == '\0')
7775 warn (_("No terminator for augmentation name\n"));
7779 if (strcmp (fc
->augmentation
, "eh") == 0)
7780 start
+= eh_addr_size
;
7784 GET (fc
->ptr_size
, 1);
7785 if (fc
->ptr_size
< 1 || fc
->ptr_size
> 8)
7787 warn (_("Invalid pointer size (%d) in CIE data\n"), fc
->ptr_size
);
7791 GET (fc
->segment_size
, 1);
7792 /* PR 17512: file: e99d2804. */
7793 if (fc
->segment_size
> 8 || fc
->segment_size
+ fc
->ptr_size
> 8)
7795 warn (_("Invalid segment size (%d) in CIE data\n"), fc
->segment_size
);
7799 eh_addr_size
= fc
->ptr_size
;
7803 fc
->ptr_size
= eh_addr_size
;
7804 fc
->segment_size
= 0;
7807 READ_ULEB (fc
->code_factor
, start
, end
);
7808 READ_SLEB (fc
->data_factor
, start
, end
);
7816 READ_ULEB (fc
->ra
, start
, end
);
7819 if (fc
->augmentation
[0] == 'z')
7821 READ_ULEB (augmentation_data_len
, start
, end
);
7822 augmentation_data
= start
;
7823 /* PR 17512: file: 11042-2589-0.004. */
7824 if (augmentation_data_len
> (bfd_size_type
) (end
- start
))
7826 warn (_("Augmentation data too long: 0x%s, expected at most %#lx\n"),
7827 dwarf_vmatoa ("x", augmentation_data_len
),
7828 (unsigned long) (end
- start
));
7831 start
+= augmentation_data_len
;
7834 if (augmentation_data_len
)
7838 unsigned char *qend
;
7840 p
= (unsigned char *) fc
->augmentation
+ 1;
7841 q
= augmentation_data
;
7842 qend
= q
+ augmentation_data_len
;
7844 while (p
< end
&& q
< qend
)
7849 q
+= 1 + size_of_encoded_value (*q
);
7851 fc
->fde_encoding
= *q
++;
7860 /* Note - it is OK if this loop terminates with q < qend.
7861 Padding may have been inserted to align the end of the CIE. */
7866 *p_version
= version
;
7869 *p_aug_len
= augmentation_data_len
;
7870 *p_aug
= augmentation_data
;
7875 free (fc
->col_offset
);
7876 free (fc
->col_type
);
7881 /* Prints out the contents on the DATA array formatted as unsigned bytes.
7882 If do_wide is not enabled, then formats the output to fit into 80 columns.
7883 PRINTED contains the number of characters already written to the current
7887 display_data (bfd_size_type printed
,
7888 const unsigned char * data
,
7889 const bfd_size_type len
)
7891 if (do_wide
|| len
< ((80 - printed
) / 3))
7892 for (printed
= 0; printed
< len
; ++printed
)
7893 printf (" %02x", data
[printed
]);
7896 for (printed
= 0; printed
< len
; ++printed
)
7898 if (printed
% (80 / 3) == 0)
7900 printf (" %02x", data
[printed
]);
7905 /* Prints out the contents on the augmentation data array.
7906 If do_wide is not enabled, then formats the output to fit into 80 columns. */
7909 display_augmentation_data (const unsigned char * data
, const bfd_size_type len
)
7913 i
= printf (_(" Augmentation data: "));
7914 display_data (i
, data
, len
);
7918 display_debug_frames (struct dwarf_section
*section
,
7919 void *file ATTRIBUTE_UNUSED
)
7921 unsigned char *start
= section
->start
;
7922 unsigned char *end
= start
+ section
->size
;
7923 unsigned char *section_start
= start
;
7924 Frame_Chunk
*chunks
= NULL
, *forward_refs
= NULL
;
7925 Frame_Chunk
*remembered_state
= NULL
;
7927 bfd_boolean is_eh
= strcmp (section
->name
, ".eh_frame") == 0;
7928 unsigned int max_regs
= 0;
7929 const char *bad_reg
= _("bad register: ");
7930 unsigned int saved_eh_addr_size
= eh_addr_size
;
7932 introduce (section
, FALSE
);
7936 unsigned char *saved_start
;
7937 unsigned char *block_end
;
7942 int need_col_headers
= 1;
7943 unsigned char *augmentation_data
= NULL
;
7944 bfd_size_type augmentation_data_len
= 0;
7945 unsigned int encoded_ptr_size
= saved_eh_addr_size
;
7946 unsigned int offset_size
;
7947 unsigned int initial_length_size
;
7948 bfd_boolean all_nops
;
7949 static Frame_Chunk fde_fc
;
7951 saved_start
= start
;
7953 SAFE_BYTE_GET_AND_INC (length
, start
, 4, end
);
7957 printf ("\n%08lx ZERO terminator\n\n",
7958 (unsigned long)(saved_start
- section_start
));
7959 /* Skip any zero terminators that directly follow.
7960 A corrupt section size could have loaded a whole
7961 slew of zero filled memory bytes. eg
7962 PR 17512: file: 070-19381-0.004. */
7963 while (start
< end
&& * start
== 0)
7968 if (length
== 0xffffffff)
7970 SAFE_BYTE_GET_AND_INC (length
, start
, 8, end
);
7972 initial_length_size
= 12;
7977 initial_length_size
= 4;
7980 block_end
= saved_start
+ length
+ initial_length_size
;
7981 if (block_end
> end
|| block_end
< start
)
7983 warn ("Invalid length 0x%s in FDE at %#08lx\n",
7984 dwarf_vmatoa_1 (NULL
, length
, offset_size
),
7985 (unsigned long) (saved_start
- section_start
));
7989 SAFE_BYTE_GET_AND_INC (cie_id
, start
, offset_size
, end
);
7991 if (is_eh
? (cie_id
== 0) : ((offset_size
== 4 && cie_id
== DW_CIE_ID
)
7992 || (offset_size
== 8 && cie_id
== DW64_CIE_ID
)))
7997 start
= read_cie (start
, end
, &cie
, &version
,
7998 &augmentation_data_len
, &augmentation_data
);
7999 /* PR 17512: file: 027-135133-0.005. */
8006 fc
->chunk_start
= saved_start
;
8007 mreg
= max_regs
> 0 ? max_regs
- 1 : 0;
8010 if (frame_need_space (fc
, mreg
) < 0)
8012 if (fc
->fde_encoding
)
8013 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
8015 printf ("\n%08lx ", (unsigned long) (saved_start
- section_start
));
8016 print_dwarf_vma (length
, fc
->ptr_size
);
8017 print_dwarf_vma (cie_id
, offset_size
);
8019 if (do_debug_frames_interp
)
8021 printf ("CIE \"%s\" cf=%d df=%d ra=%d\n", fc
->augmentation
,
8022 fc
->code_factor
, fc
->data_factor
, fc
->ra
);
8027 printf (" Version: %d\n", version
);
8028 printf (" Augmentation: \"%s\"\n", fc
->augmentation
);
8031 printf (" Pointer Size: %u\n", fc
->ptr_size
);
8032 printf (" Segment Size: %u\n", fc
->segment_size
);
8034 printf (" Code alignment factor: %u\n", fc
->code_factor
);
8035 printf (" Data alignment factor: %d\n", fc
->data_factor
);
8036 printf (" Return address column: %d\n", fc
->ra
);
8038 if (augmentation_data_len
)
8039 display_augmentation_data (augmentation_data
, augmentation_data_len
);
8046 unsigned char *look_for
;
8047 unsigned long segment_selector
;
8051 dwarf_vma sign
= (dwarf_vma
) 1 << (offset_size
* 8 - 1);
8052 look_for
= start
- 4 - ((cie_id
^ sign
) - sign
);
8055 look_for
= section_start
+ cie_id
;
8057 if (look_for
<= saved_start
)
8059 for (cie
= chunks
; cie
; cie
= cie
->next
)
8060 if (cie
->chunk_start
== look_for
)
8065 for (cie
= forward_refs
; cie
; cie
= cie
->next
)
8066 if (cie
->chunk_start
== look_for
)
8070 unsigned int off_size
;
8071 unsigned char *cie_scan
;
8073 cie_scan
= look_for
;
8075 SAFE_BYTE_GET_AND_INC (length
, cie_scan
, 4, end
);
8076 if (length
== 0xffffffff)
8078 SAFE_BYTE_GET_AND_INC (length
, cie_scan
, 8, end
);
8085 SAFE_BYTE_GET_AND_INC (c_id
, cie_scan
, off_size
, end
);
8088 : ((off_size
== 4 && c_id
== DW_CIE_ID
)
8089 || (off_size
== 8 && c_id
== DW64_CIE_ID
)))
8094 read_cie (cie_scan
, end
, &cie
, &version
,
8095 &augmentation_data_len
, &augmentation_data
);
8096 /* PR 17512: file: 3450-2098-0.004. */
8099 warn (_("Failed to read CIE information\n"));
8102 cie
->next
= forward_refs
;
8104 cie
->chunk_start
= look_for
;
8105 mreg
= max_regs
> 0 ? max_regs
- 1 : 0;
8108 if (frame_need_space (cie
, mreg
) < 0)
8110 warn (_("Invalid max register\n"));
8113 if (cie
->fde_encoding
)
8115 = size_of_encoded_value (cie
->fde_encoding
);
8122 memset (fc
, 0, sizeof (Frame_Chunk
));
8126 warn ("Invalid CIE pointer 0x%s in FDE at %#08lx\n",
8127 dwarf_vmatoa_1 (NULL
, cie_id
, offset_size
),
8128 (unsigned long) (saved_start
- section_start
));
8130 fc
->col_type
= (short int *) xmalloc (sizeof (short int));
8131 fc
->col_offset
= (int *) xmalloc (sizeof (int));
8132 if (frame_need_space (fc
, max_regs
> 0 ? max_regs
- 1 : 0) < 0)
8134 warn (_("Invalid max register\n"));
8138 fc
->augmentation
= "";
8139 fc
->fde_encoding
= 0;
8140 fc
->ptr_size
= eh_addr_size
;
8141 fc
->segment_size
= 0;
8145 fc
->ncols
= cie
->ncols
;
8146 fc
->col_type
= (short int *) xcmalloc (fc
->ncols
, sizeof (short int));
8147 fc
->col_offset
= (int *) xcmalloc (fc
->ncols
, sizeof (int));
8148 memcpy (fc
->col_type
, cie
->col_type
, fc
->ncols
* sizeof (short int));
8149 memcpy (fc
->col_offset
, cie
->col_offset
, fc
->ncols
* sizeof (int));
8150 fc
->augmentation
= cie
->augmentation
;
8151 fc
->ptr_size
= cie
->ptr_size
;
8152 eh_addr_size
= cie
->ptr_size
;
8153 fc
->segment_size
= cie
->segment_size
;
8154 fc
->code_factor
= cie
->code_factor
;
8155 fc
->data_factor
= cie
->data_factor
;
8156 fc
->cfa_reg
= cie
->cfa_reg
;
8157 fc
->cfa_offset
= cie
->cfa_offset
;
8159 if (frame_need_space (fc
, max_regs
> 0 ? max_regs
- 1: 0) < 0)
8161 warn (_("Invalid max register\n"));
8164 fc
->fde_encoding
= cie
->fde_encoding
;
8167 if (fc
->fde_encoding
)
8168 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
8170 segment_selector
= 0;
8171 if (fc
->segment_size
)
8173 if (fc
->segment_size
> sizeof (segment_selector
))
8175 /* PR 17512: file: 9e196b3e. */
8176 warn (_("Probably corrupt segment size: %d - using 4 instead\n"), fc
->segment_size
);
8177 fc
->segment_size
= 4;
8179 SAFE_BYTE_GET_AND_INC (segment_selector
, start
, fc
->segment_size
, end
);
8182 fc
->pc_begin
= get_encoded_value (&start
, fc
->fde_encoding
, section
, end
);
8184 /* FIXME: It appears that sometimes the final pc_range value is
8185 encoded in less than encoded_ptr_size bytes. See the x86_64
8186 run of the "objcopy on compressed debug sections" test for an
8188 SAFE_BYTE_GET_AND_INC (fc
->pc_range
, start
, encoded_ptr_size
, end
);
8190 if (cie
->augmentation
[0] == 'z')
8192 READ_ULEB (augmentation_data_len
, start
, end
);
8193 augmentation_data
= start
;
8194 /* PR 17512 file: 722-8446-0.004 and PR 22386. */
8195 if (augmentation_data_len
> (bfd_size_type
) (end
- start
))
8197 warn (_("Augmentation data too long: 0x%s, "
8198 "expected at most %#lx\n"),
8199 dwarf_vmatoa ("x", augmentation_data_len
),
8200 (unsigned long) (end
- start
));
8202 augmentation_data
= NULL
;
8203 augmentation_data_len
= 0;
8205 start
+= augmentation_data_len
;
8208 printf ("\n%08lx %s %s FDE cie=%08lx pc=",
8209 (unsigned long)(saved_start
- section_start
),
8210 dwarf_vmatoa_1 (NULL
, length
, fc
->ptr_size
),
8211 dwarf_vmatoa_1 (NULL
, cie_id
, offset_size
),
8212 (unsigned long)(cie
->chunk_start
- section_start
));
8214 if (fc
->segment_size
)
8215 printf ("%04lx:", segment_selector
);
8218 dwarf_vmatoa_1 (NULL
, fc
->pc_begin
, fc
->ptr_size
),
8219 dwarf_vmatoa_1 (NULL
, fc
->pc_begin
+ fc
->pc_range
, fc
->ptr_size
));
8221 if (! do_debug_frames_interp
&& augmentation_data_len
)
8223 display_augmentation_data (augmentation_data
, augmentation_data_len
);
8228 /* At this point, fc is the current chunk, cie (if any) is set, and
8229 we're about to interpret instructions for the chunk. */
8230 /* ??? At present we need to do this always, since this sizes the
8231 fc->col_type and fc->col_offset arrays, which we write into always.
8232 We should probably split the interpreted and non-interpreted bits
8233 into two different routines, since there's so much that doesn't
8234 really overlap between them. */
8235 if (1 || do_debug_frames_interp
)
8237 /* Start by making a pass over the chunk, allocating storage
8238 and taking note of what registers are used. */
8239 unsigned char *tmp
= start
;
8241 while (start
< block_end
)
8243 unsigned int reg
, op
, opa
;
8245 unsigned char * new_start
;
8252 /* Warning: if you add any more cases to this switch, be
8253 sure to add them to the corresponding switch below. */
8256 case DW_CFA_advance_loc
:
8259 SKIP_ULEB (start
, end
);
8260 if (frame_need_space (fc
, opa
) >= 0)
8261 fc
->col_type
[opa
] = DW_CFA_undefined
;
8263 case DW_CFA_restore
:
8264 if (frame_need_space (fc
, opa
) >= 0)
8265 fc
->col_type
[opa
] = DW_CFA_undefined
;
8267 case DW_CFA_set_loc
:
8268 start
+= encoded_ptr_size
;
8270 case DW_CFA_advance_loc1
:
8273 case DW_CFA_advance_loc2
:
8276 case DW_CFA_advance_loc4
:
8279 case DW_CFA_offset_extended
:
8280 case DW_CFA_val_offset
:
8281 READ_ULEB (reg
, start
, end
);
8282 SKIP_ULEB (start
, end
);
8283 if (frame_need_space (fc
, reg
) >= 0)
8284 fc
->col_type
[reg
] = DW_CFA_undefined
;
8286 case DW_CFA_restore_extended
:
8287 READ_ULEB (reg
, start
, end
);
8288 if (frame_need_space (fc
, reg
) >= 0)
8289 fc
->col_type
[reg
] = DW_CFA_undefined
;
8291 case DW_CFA_undefined
:
8292 READ_ULEB (reg
, start
, end
);
8293 if (frame_need_space (fc
, reg
) >= 0)
8294 fc
->col_type
[reg
] = DW_CFA_undefined
;
8296 case DW_CFA_same_value
:
8297 READ_ULEB (reg
, start
, end
);
8298 if (frame_need_space (fc
, reg
) >= 0)
8299 fc
->col_type
[reg
] = DW_CFA_undefined
;
8301 case DW_CFA_register
:
8302 READ_ULEB (reg
, start
, end
);
8303 SKIP_ULEB (start
, end
);
8304 if (frame_need_space (fc
, reg
) >= 0)
8305 fc
->col_type
[reg
] = DW_CFA_undefined
;
8307 case DW_CFA_def_cfa
:
8308 SKIP_ULEB (start
, end
);
8309 SKIP_ULEB (start
, end
);
8311 case DW_CFA_def_cfa_register
:
8312 SKIP_ULEB (start
, end
);
8314 case DW_CFA_def_cfa_offset
:
8315 SKIP_ULEB (start
, end
);
8317 case DW_CFA_def_cfa_expression
:
8318 READ_ULEB (temp
, start
, end
);
8319 new_start
= start
+ temp
;
8320 if (new_start
< start
)
8322 warn (_("Corrupt CFA_def expression value: %lu\n"), temp
);
8328 case DW_CFA_expression
:
8329 case DW_CFA_val_expression
:
8330 READ_ULEB (reg
, start
, end
);
8331 READ_ULEB (temp
, start
, end
);
8332 new_start
= start
+ temp
;
8333 if (new_start
< start
)
8335 /* PR 17512: file:306-192417-0.005. */
8336 warn (_("Corrupt CFA expression value: %lu\n"), temp
);
8341 if (frame_need_space (fc
, reg
) >= 0)
8342 fc
->col_type
[reg
] = DW_CFA_undefined
;
8344 case DW_CFA_offset_extended_sf
:
8345 case DW_CFA_val_offset_sf
:
8346 READ_ULEB (reg
, start
, end
);
8347 SKIP_SLEB (start
, end
);
8348 if (frame_need_space (fc
, reg
) >= 0)
8349 fc
->col_type
[reg
] = DW_CFA_undefined
;
8351 case DW_CFA_def_cfa_sf
:
8352 SKIP_ULEB (start
, end
);
8353 SKIP_SLEB (start
, end
);
8355 case DW_CFA_def_cfa_offset_sf
:
8356 SKIP_SLEB (start
, end
);
8358 case DW_CFA_MIPS_advance_loc8
:
8361 case DW_CFA_GNU_args_size
:
8362 SKIP_ULEB (start
, end
);
8364 case DW_CFA_GNU_negative_offset_extended
:
8365 READ_ULEB (reg
, start
, end
);
8366 SKIP_ULEB (start
, end
);
8367 if (frame_need_space (fc
, reg
) >= 0)
8368 fc
->col_type
[reg
] = DW_CFA_undefined
;
8379 /* Now we know what registers are used, make a second pass over
8380 the chunk, this time actually printing out the info. */
8382 while (start
< block_end
)
8384 unsigned char * tmp
;
8386 unsigned long ul
, roffs
;
8387 /* Note: It is tempting to use an unsigned long for 'reg' but there
8388 are various functions, notably frame_space_needed() that assume that
8389 reg is an unsigned int. */
8394 const char *reg_prefix
= "";
8401 /* Make a note if something other than DW_CFA_nop happens. */
8402 if (op
!= DW_CFA_nop
)
8405 /* Warning: if you add any more cases to this switch, be
8406 sure to add them to the corresponding switch above. */
8409 case DW_CFA_advance_loc
:
8410 if (do_debug_frames_interp
)
8411 frame_display_row (fc
, &need_col_headers
, &max_regs
);
8413 printf (" DW_CFA_advance_loc: %d to %s\n",
8414 opa
* fc
->code_factor
,
8415 dwarf_vmatoa_1 (NULL
,
8416 fc
->pc_begin
+ opa
* fc
->code_factor
,
8418 fc
->pc_begin
+= opa
* fc
->code_factor
;
8422 READ_ULEB (roffs
, start
, end
);
8423 if (opa
>= (unsigned int) fc
->ncols
)
8424 reg_prefix
= bad_reg
;
8425 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
8426 printf (" DW_CFA_offset: %s%s at cfa%+ld\n",
8427 reg_prefix
, regname (opa
, 0),
8428 roffs
* fc
->data_factor
);
8429 if (*reg_prefix
== '\0')
8431 fc
->col_type
[opa
] = DW_CFA_offset
;
8432 fc
->col_offset
[opa
] = roffs
* fc
->data_factor
;
8436 case DW_CFA_restore
:
8437 if (opa
>= (unsigned int) fc
->ncols
)
8438 reg_prefix
= bad_reg
;
8439 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
8440 printf (" DW_CFA_restore: %s%s\n",
8441 reg_prefix
, regname (opa
, 0));
8442 if (*reg_prefix
!= '\0')
8445 if (opa
>= (unsigned int) cie
->ncols
8446 || (do_debug_frames_interp
8447 && cie
->col_type
[opa
] == DW_CFA_unreferenced
))
8449 fc
->col_type
[opa
] = DW_CFA_undefined
;
8450 fc
->col_offset
[opa
] = 0;
8454 fc
->col_type
[opa
] = cie
->col_type
[opa
];
8455 fc
->col_offset
[opa
] = cie
->col_offset
[opa
];
8459 case DW_CFA_set_loc
:
8460 vma
= get_encoded_value (&start
, fc
->fde_encoding
, section
, block_end
);
8461 if (do_debug_frames_interp
)
8462 frame_display_row (fc
, &need_col_headers
, &max_regs
);
8464 printf (" DW_CFA_set_loc: %s\n",
8465 dwarf_vmatoa_1 (NULL
, vma
, fc
->ptr_size
));
8469 case DW_CFA_advance_loc1
:
8470 SAFE_BYTE_GET_AND_INC (ofs
, start
, 1, end
);
8471 if (do_debug_frames_interp
)
8472 frame_display_row (fc
, &need_col_headers
, &max_regs
);
8474 printf (" DW_CFA_advance_loc1: %ld to %s\n",
8475 (unsigned long) (ofs
* fc
->code_factor
),
8476 dwarf_vmatoa_1 (NULL
,
8477 fc
->pc_begin
+ ofs
* fc
->code_factor
,
8479 fc
->pc_begin
+= ofs
* fc
->code_factor
;
8482 case DW_CFA_advance_loc2
:
8483 SAFE_BYTE_GET_AND_INC (ofs
, start
, 2, block_end
);
8484 if (do_debug_frames_interp
)
8485 frame_display_row (fc
, &need_col_headers
, &max_regs
);
8487 printf (" DW_CFA_advance_loc2: %ld to %s\n",
8488 (unsigned long) (ofs
* fc
->code_factor
),
8489 dwarf_vmatoa_1 (NULL
,
8490 fc
->pc_begin
+ ofs
* fc
->code_factor
,
8492 fc
->pc_begin
+= ofs
* fc
->code_factor
;
8495 case DW_CFA_advance_loc4
:
8496 SAFE_BYTE_GET_AND_INC (ofs
, start
, 4, block_end
);
8497 if (do_debug_frames_interp
)
8498 frame_display_row (fc
, &need_col_headers
, &max_regs
);
8500 printf (" DW_CFA_advance_loc4: %ld to %s\n",
8501 (unsigned long) (ofs
* fc
->code_factor
),
8502 dwarf_vmatoa_1 (NULL
,
8503 fc
->pc_begin
+ ofs
* fc
->code_factor
,
8505 fc
->pc_begin
+= ofs
* fc
->code_factor
;
8508 case DW_CFA_offset_extended
:
8509 READ_ULEB (reg
, start
, end
);
8510 READ_ULEB (roffs
, start
, end
);
8511 if (reg
>= (unsigned int) fc
->ncols
)
8512 reg_prefix
= bad_reg
;
8513 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
8514 printf (" DW_CFA_offset_extended: %s%s at cfa%+ld\n",
8515 reg_prefix
, regname (reg
, 0),
8516 roffs
* fc
->data_factor
);
8517 if (*reg_prefix
== '\0')
8519 fc
->col_type
[reg
] = DW_CFA_offset
;
8520 fc
->col_offset
[reg
] = roffs
* fc
->data_factor
;
8524 case DW_CFA_val_offset
:
8525 READ_ULEB (reg
, start
, end
);
8526 READ_ULEB (roffs
, start
, end
);
8527 if (reg
>= (unsigned int) fc
->ncols
)
8528 reg_prefix
= bad_reg
;
8529 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
8530 printf (" DW_CFA_val_offset: %s%s is cfa%+ld\n",
8531 reg_prefix
, regname (reg
, 0),
8532 roffs
* fc
->data_factor
);
8533 if (*reg_prefix
== '\0')
8535 fc
->col_type
[reg
] = DW_CFA_val_offset
;
8536 fc
->col_offset
[reg
] = roffs
* fc
->data_factor
;
8540 case DW_CFA_restore_extended
:
8541 READ_ULEB (reg
, start
, end
);
8542 if (reg
>= (unsigned int) fc
->ncols
)
8543 reg_prefix
= bad_reg
;
8544 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
8545 printf (" DW_CFA_restore_extended: %s%s\n",
8546 reg_prefix
, regname (reg
, 0));
8547 if (*reg_prefix
!= '\0')
8550 if (reg
>= (unsigned int) cie
->ncols
)
8552 fc
->col_type
[reg
] = DW_CFA_undefined
;
8553 fc
->col_offset
[reg
] = 0;
8557 fc
->col_type
[reg
] = cie
->col_type
[reg
];
8558 fc
->col_offset
[reg
] = cie
->col_offset
[reg
];
8562 case DW_CFA_undefined
:
8563 READ_ULEB (reg
, start
, end
);
8564 if (reg
>= (unsigned int) fc
->ncols
)
8565 reg_prefix
= bad_reg
;
8566 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
8567 printf (" DW_CFA_undefined: %s%s\n",
8568 reg_prefix
, regname (reg
, 0));
8569 if (*reg_prefix
== '\0')
8571 fc
->col_type
[reg
] = DW_CFA_undefined
;
8572 fc
->col_offset
[reg
] = 0;
8576 case DW_CFA_same_value
:
8577 READ_ULEB (reg
, start
, end
);
8578 if (reg
>= (unsigned int) fc
->ncols
)
8579 reg_prefix
= bad_reg
;
8580 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
8581 printf (" DW_CFA_same_value: %s%s\n",
8582 reg_prefix
, regname (reg
, 0));
8583 if (*reg_prefix
== '\0')
8585 fc
->col_type
[reg
] = DW_CFA_same_value
;
8586 fc
->col_offset
[reg
] = 0;
8590 case DW_CFA_register
:
8591 READ_ULEB (reg
, start
, end
);
8592 READ_ULEB (roffs
, start
, end
);
8593 if (reg
>= (unsigned int) fc
->ncols
)
8594 reg_prefix
= bad_reg
;
8595 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
8597 printf (" DW_CFA_register: %s%s in ",
8598 reg_prefix
, regname (reg
, 0));
8599 puts (regname (roffs
, 0));
8601 if (*reg_prefix
== '\0')
8603 fc
->col_type
[reg
] = DW_CFA_register
;
8604 fc
->col_offset
[reg
] = roffs
;
8608 case DW_CFA_remember_state
:
8609 if (! do_debug_frames_interp
)
8610 printf (" DW_CFA_remember_state\n");
8611 rs
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
8612 rs
->cfa_offset
= fc
->cfa_offset
;
8613 rs
->cfa_reg
= fc
->cfa_reg
;
8615 rs
->cfa_exp
= fc
->cfa_exp
;
8616 rs
->ncols
= fc
->ncols
;
8617 rs
->col_type
= (short int *) xcmalloc (rs
->ncols
,
8618 sizeof (* rs
->col_type
));
8619 rs
->col_offset
= (int *) xcmalloc (rs
->ncols
, sizeof (* rs
->col_offset
));
8620 memcpy (rs
->col_type
, fc
->col_type
, rs
->ncols
* sizeof (* fc
->col_type
));
8621 memcpy (rs
->col_offset
, fc
->col_offset
, rs
->ncols
* sizeof (* fc
->col_offset
));
8622 rs
->next
= remembered_state
;
8623 remembered_state
= rs
;
8626 case DW_CFA_restore_state
:
8627 if (! do_debug_frames_interp
)
8628 printf (" DW_CFA_restore_state\n");
8629 rs
= remembered_state
;
8632 remembered_state
= rs
->next
;
8633 fc
->cfa_offset
= rs
->cfa_offset
;
8634 fc
->cfa_reg
= rs
->cfa_reg
;
8636 fc
->cfa_exp
= rs
->cfa_exp
;
8637 if (frame_need_space (fc
, rs
->ncols
- 1) < 0)
8639 warn (_("Invalid column number in saved frame state\n"));
8643 memcpy (fc
->col_type
, rs
->col_type
, rs
->ncols
* sizeof (* rs
->col_type
));
8644 memcpy (fc
->col_offset
, rs
->col_offset
,
8645 rs
->ncols
* sizeof (* rs
->col_offset
));
8646 free (rs
->col_type
);
8647 free (rs
->col_offset
);
8650 else if (do_debug_frames_interp
)
8651 printf ("Mismatched DW_CFA_restore_state\n");
8654 case DW_CFA_def_cfa
:
8655 READ_ULEB (fc
->cfa_reg
, start
, end
);
8656 READ_ULEB (fc
->cfa_offset
, start
, end
);
8658 if (! do_debug_frames_interp
)
8659 printf (" DW_CFA_def_cfa: %s ofs %d\n",
8660 regname (fc
->cfa_reg
, 0), (int) fc
->cfa_offset
);
8663 case DW_CFA_def_cfa_register
:
8664 READ_ULEB (fc
->cfa_reg
, start
, end
);
8666 if (! do_debug_frames_interp
)
8667 printf (" DW_CFA_def_cfa_register: %s\n",
8668 regname (fc
->cfa_reg
, 0));
8671 case DW_CFA_def_cfa_offset
:
8672 READ_ULEB (fc
->cfa_offset
, start
, end
);
8673 if (! do_debug_frames_interp
)
8674 printf (" DW_CFA_def_cfa_offset: %d\n", (int) fc
->cfa_offset
);
8678 if (! do_debug_frames_interp
)
8679 printf (" DW_CFA_nop\n");
8682 case DW_CFA_def_cfa_expression
:
8683 READ_ULEB (ul
, start
, end
);
8684 if (start
>= block_end
|| ul
> (unsigned long) (block_end
- start
))
8686 printf (_(" DW_CFA_def_cfa_expression: <corrupt len %lu>\n"), ul
);
8689 if (! do_debug_frames_interp
)
8691 printf (" DW_CFA_def_cfa_expression (");
8692 decode_location_expression (start
, eh_addr_size
, 0, -1,
8700 case DW_CFA_expression
:
8701 READ_ULEB (reg
, start
, end
);
8702 READ_ULEB (ul
, start
, end
);
8703 if (reg
>= (unsigned int) fc
->ncols
)
8704 reg_prefix
= bad_reg
;
8705 /* PR 17512: file: 069-133014-0.006. */
8706 /* PR 17512: file: 98c02eb4. */
8708 if (start
>= block_end
|| tmp
> block_end
|| tmp
< start
)
8710 printf (_(" DW_CFA_expression: <corrupt len %lu>\n"), ul
);
8713 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
8715 printf (" DW_CFA_expression: %s%s (",
8716 reg_prefix
, regname (reg
, 0));
8717 decode_location_expression (start
, eh_addr_size
, 0, -1,
8721 if (*reg_prefix
== '\0')
8722 fc
->col_type
[reg
] = DW_CFA_expression
;
8726 case DW_CFA_val_expression
:
8727 READ_ULEB (reg
, start
, end
);
8728 READ_ULEB (ul
, start
, end
);
8729 if (reg
>= (unsigned int) fc
->ncols
)
8730 reg_prefix
= bad_reg
;
8732 if (start
>= block_end
|| tmp
> block_end
|| tmp
< start
)
8734 printf (" DW_CFA_val_expression: <corrupt len %lu>\n", ul
);
8737 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
8739 printf (" DW_CFA_val_expression: %s%s (",
8740 reg_prefix
, regname (reg
, 0));
8741 decode_location_expression (start
, eh_addr_size
, 0, -1,
8745 if (*reg_prefix
== '\0')
8746 fc
->col_type
[reg
] = DW_CFA_val_expression
;
8750 case DW_CFA_offset_extended_sf
:
8751 READ_ULEB (reg
, start
, end
);
8752 READ_SLEB (l
, start
, end
);
8753 if (frame_need_space (fc
, reg
) < 0)
8754 reg_prefix
= bad_reg
;
8755 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
8756 printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+ld\n",
8757 reg_prefix
, regname (reg
, 0),
8758 (long)(l
* fc
->data_factor
));
8759 if (*reg_prefix
== '\0')
8761 fc
->col_type
[reg
] = DW_CFA_offset
;
8762 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
8766 case DW_CFA_val_offset_sf
:
8767 READ_ULEB (reg
, start
, end
);
8768 READ_SLEB (l
, start
, end
);
8769 if (frame_need_space (fc
, reg
) < 0)
8770 reg_prefix
= bad_reg
;
8771 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
8772 printf (" DW_CFA_val_offset_sf: %s%s is cfa%+ld\n",
8773 reg_prefix
, regname (reg
, 0),
8774 (long)(l
* fc
->data_factor
));
8775 if (*reg_prefix
== '\0')
8777 fc
->col_type
[reg
] = DW_CFA_val_offset
;
8778 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
8782 case DW_CFA_def_cfa_sf
:
8783 READ_ULEB (fc
->cfa_reg
, start
, end
);
8784 READ_ULEB (fc
->cfa_offset
, start
, end
);
8785 fc
->cfa_offset
= fc
->cfa_offset
* fc
->data_factor
;
8787 if (! do_debug_frames_interp
)
8788 printf (" DW_CFA_def_cfa_sf: %s ofs %d\n",
8789 regname (fc
->cfa_reg
, 0), (int) fc
->cfa_offset
);
8792 case DW_CFA_def_cfa_offset_sf
:
8793 READ_ULEB (fc
->cfa_offset
, start
, end
);
8794 fc
->cfa_offset
*= fc
->data_factor
;
8795 if (! do_debug_frames_interp
)
8796 printf (" DW_CFA_def_cfa_offset_sf: %d\n", (int) fc
->cfa_offset
);
8799 case DW_CFA_MIPS_advance_loc8
:
8800 SAFE_BYTE_GET_AND_INC (ofs
, start
, 8, block_end
);
8801 if (do_debug_frames_interp
)
8802 frame_display_row (fc
, &need_col_headers
, &max_regs
);
8804 printf (" DW_CFA_MIPS_advance_loc8: %ld to %s\n",
8805 (unsigned long) (ofs
* fc
->code_factor
),
8806 dwarf_vmatoa_1 (NULL
,
8807 fc
->pc_begin
+ ofs
* fc
->code_factor
,
8809 fc
->pc_begin
+= ofs
* fc
->code_factor
;
8812 case DW_CFA_GNU_window_save
:
8813 if (! do_debug_frames_interp
)
8814 printf (" DW_CFA_GNU_window_save\n");
8817 case DW_CFA_GNU_args_size
:
8818 READ_ULEB (ul
, start
, end
);
8819 if (! do_debug_frames_interp
)
8820 printf (" DW_CFA_GNU_args_size: %ld\n", ul
);
8823 case DW_CFA_GNU_negative_offset_extended
:
8824 READ_ULEB (reg
, start
, end
);
8825 READ_SLEB (l
, start
, end
);
8827 if (frame_need_space (fc
, reg
) < 0)
8828 reg_prefix
= bad_reg
;
8829 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
8830 printf (" DW_CFA_GNU_negative_offset_extended: %s%s at cfa%+ld\n",
8831 reg_prefix
, regname (reg
, 0),
8832 (long)(l
* fc
->data_factor
));
8833 if (*reg_prefix
== '\0')
8835 fc
->col_type
[reg
] = DW_CFA_offset
;
8836 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
8841 if (op
>= DW_CFA_lo_user
&& op
<= DW_CFA_hi_user
)
8842 printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op
);
8844 warn (_("Unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op
);
8849 /* Interpret the CFA - as long as it is not completely full of NOPs. */
8850 if (do_debug_frames_interp
&& ! all_nops
)
8851 frame_display_row (fc
, &need_col_headers
, &max_regs
);
8853 if (fde_fc
.col_type
!= NULL
)
8855 free (fde_fc
.col_type
);
8856 fde_fc
.col_type
= NULL
;
8858 if (fde_fc
.col_offset
!= NULL
)
8860 free (fde_fc
.col_offset
);
8861 fde_fc
.col_offset
= NULL
;
8865 eh_addr_size
= saved_eh_addr_size
;
8870 while (remembered_state
!= NULL
)
8872 rs
= remembered_state
;
8873 remembered_state
= rs
->next
;
8874 free (rs
->col_type
);
8875 free (rs
->col_offset
);
8876 rs
->next
= NULL
; /* Paranoia. */
8880 while (chunks
!= NULL
)
8884 free (rs
->col_type
);
8885 free (rs
->col_offset
);
8886 rs
->next
= NULL
; /* Paranoia. */
8890 while (forward_refs
!= NULL
)
8893 forward_refs
= rs
->next
;
8894 free (rs
->col_type
);
8895 free (rs
->col_offset
);
8896 rs
->next
= NULL
; /* Paranoia. */
8906 display_debug_names (struct dwarf_section
*section
, void *file
)
8908 unsigned char *hdrptr
= section
->start
;
8909 dwarf_vma unit_length
;
8910 unsigned char *unit_start
;
8911 const unsigned char *const section_end
= section
->start
+ section
->size
;
8912 unsigned char *unit_end
;
8914 introduce (section
, FALSE
);
8916 load_debug_section_with_follow (str
, file
);
8918 for (; hdrptr
< section_end
; hdrptr
= unit_end
)
8920 unsigned int offset_size
;
8921 uint16_t dwarf_version
, padding
;
8922 uint32_t comp_unit_count
, local_type_unit_count
, foreign_type_unit_count
;
8923 uint32_t bucket_count
, name_count
, abbrev_table_size
;
8924 uint32_t augmentation_string_size
;
8926 unsigned long sec_off
;
8927 bfd_boolean augmentation_printable
;
8928 const char *augmentation_string
;
8930 unit_start
= hdrptr
;
8932 /* Get and check the length of the block. */
8933 SAFE_BYTE_GET_AND_INC (unit_length
, hdrptr
, 4, section_end
);
8935 if (unit_length
== 0xffffffff)
8937 /* This section is 64-bit DWARF. */
8938 SAFE_BYTE_GET_AND_INC (unit_length
, hdrptr
, 8, section_end
);
8943 unit_end
= hdrptr
+ unit_length
;
8945 sec_off
= hdrptr
- section
->start
;
8946 if (sec_off
+ unit_length
< sec_off
8947 || sec_off
+ unit_length
> section
->size
)
8949 warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"),
8951 (unsigned long) (unit_start
- section
->start
),
8952 dwarf_vmatoa ("x", unit_length
));
8956 /* Get and check the version number. */
8957 SAFE_BYTE_GET_AND_INC (dwarf_version
, hdrptr
, 2, unit_end
);
8958 printf (_("Version %ld\n"), (long) dwarf_version
);
8960 /* Prior versions did not exist, and future versions may not be
8961 backwards compatible. */
8962 if (dwarf_version
!= 5)
8964 warn (_("Only DWARF version 5 .debug_names "
8965 "is currently supported.\n"));
8969 SAFE_BYTE_GET_AND_INC (padding
, hdrptr
, 2, unit_end
);
8971 warn (_("Padding field of .debug_names must be 0 (found 0x%x)\n"),
8974 SAFE_BYTE_GET_AND_INC (comp_unit_count
, hdrptr
, 4, unit_end
);
8975 if (comp_unit_count
== 0)
8976 warn (_("Compilation unit count must be >= 1 in .debug_names\n"));
8978 SAFE_BYTE_GET_AND_INC (local_type_unit_count
, hdrptr
, 4, unit_end
);
8979 SAFE_BYTE_GET_AND_INC (foreign_type_unit_count
, hdrptr
, 4, unit_end
);
8980 SAFE_BYTE_GET_AND_INC (bucket_count
, hdrptr
, 4, unit_end
);
8981 SAFE_BYTE_GET_AND_INC (name_count
, hdrptr
, 4, unit_end
);
8982 SAFE_BYTE_GET_AND_INC (abbrev_table_size
, hdrptr
, 4, unit_end
);
8984 SAFE_BYTE_GET_AND_INC (augmentation_string_size
, hdrptr
, 4, unit_end
);
8985 if (augmentation_string_size
% 4 != 0)
8987 warn (_("Augmentation string length %u must be rounded up "
8988 "to a multiple of 4 in .debug_names.\n"),
8989 augmentation_string_size
);
8990 augmentation_string_size
+= (-augmentation_string_size
) & 3;
8993 printf (_("Augmentation string:"));
8995 augmentation_printable
= TRUE
;
8996 augmentation_string
= (const char *) hdrptr
;
8998 for (i
= 0; i
< augmentation_string_size
; i
++)
9002 SAFE_BYTE_GET_AND_INC (uc
, hdrptr
, 1, unit_end
);
9003 printf (" %02x", uc
);
9005 if (uc
!= 0 && !ISPRINT (uc
))
9006 augmentation_printable
= FALSE
;
9009 if (augmentation_printable
)
9013 i
< augmentation_string_size
&& augmentation_string
[i
];
9015 putchar (augmentation_string
[i
]);
9020 printf (_("CU table:\n"));
9021 for (i
= 0; i
< comp_unit_count
; i
++)
9025 SAFE_BYTE_GET_AND_INC (cu_offset
, hdrptr
, offset_size
, unit_end
);
9026 printf (_("[%3u] 0x%lx\n"), i
, (unsigned long) cu_offset
);
9030 printf (_("TU table:\n"));
9031 for (i
= 0; i
< local_type_unit_count
; i
++)
9035 SAFE_BYTE_GET_AND_INC (tu_offset
, hdrptr
, offset_size
, unit_end
);
9036 printf (_("[%3u] 0x%lx\n"), i
, (unsigned long) tu_offset
);
9040 printf (_("Foreign TU table:\n"));
9041 for (i
= 0; i
< foreign_type_unit_count
; i
++)
9045 SAFE_BYTE_GET_AND_INC (signature
, hdrptr
, 8, unit_end
);
9046 printf (_("[%3u] "), i
);
9047 print_dwarf_vma (signature
, 8);
9052 const uint32_t *const hash_table_buckets
= (uint32_t *) hdrptr
;
9053 hdrptr
+= bucket_count
* sizeof (uint32_t);
9054 const uint32_t *const hash_table_hashes
= (uint32_t *) hdrptr
;
9055 hdrptr
+= name_count
* sizeof (uint32_t);
9056 unsigned char *const name_table_string_offsets
= hdrptr
;
9057 hdrptr
+= name_count
* offset_size
;
9058 unsigned char *const name_table_entry_offsets
= hdrptr
;
9059 hdrptr
+= name_count
* offset_size
;
9060 unsigned char *const abbrev_table
= hdrptr
;
9061 hdrptr
+= abbrev_table_size
;
9062 const unsigned char *const abbrev_table_end
= hdrptr
;
9063 unsigned char *const entry_pool
= hdrptr
;
9064 if (hdrptr
> unit_end
)
9066 warn (_("Entry pool offset (0x%lx) exceeds unit size 0x%lx "
9067 "for unit 0x%lx in the debug_names\n"),
9068 (long) (hdrptr
- section
->start
),
9069 (long) (unit_end
- section
->start
),
9070 (long) (unit_start
- section
->start
));
9074 size_t buckets_filled
= 0;
9076 for (bucketi
= 0; bucketi
< bucket_count
; bucketi
++)
9078 const uint32_t bucket
= hash_table_buckets
[bucketi
];
9083 printf (ngettext ("Used %zu of %lu bucket.\n",
9084 "Used %zu of %lu buckets.\n",
9086 buckets_filled
, (unsigned long) bucket_count
);
9088 uint32_t hash_prev
= 0;
9089 size_t hash_clash_count
= 0;
9090 size_t longest_clash
= 0;
9091 size_t this_length
= 0;
9093 for (hashi
= 0; hashi
< name_count
; hashi
++)
9095 const uint32_t hash_this
= hash_table_hashes
[hashi
];
9099 if (hash_prev
% bucket_count
== hash_this
% bucket_count
)
9103 longest_clash
= MAX (longest_clash
, this_length
);
9108 hash_prev
= hash_this
;
9110 printf (_("Out of %lu items there are %zu bucket clashes"
9111 " (longest of %zu entries).\n"),
9112 (unsigned long) name_count
, hash_clash_count
, longest_clash
);
9113 assert (name_count
== buckets_filled
+ hash_clash_count
);
9115 struct abbrev_lookup_entry
9117 dwarf_vma abbrev_tag
;
9118 unsigned char *abbrev_lookup_ptr
;
9120 struct abbrev_lookup_entry
*abbrev_lookup
= NULL
;
9121 size_t abbrev_lookup_used
= 0;
9122 size_t abbrev_lookup_allocated
= 0;
9124 unsigned char *abbrevptr
= abbrev_table
;
9127 dwarf_vma abbrev_tag
;
9129 READ_ULEB (abbrev_tag
, abbrevptr
, abbrev_table_end
);
9130 if (abbrev_tag
== 0)
9132 if (abbrev_lookup_used
== abbrev_lookup_allocated
)
9134 abbrev_lookup_allocated
= MAX (0x100,
9135 abbrev_lookup_allocated
* 2);
9136 abbrev_lookup
= xrealloc (abbrev_lookup
,
9137 (abbrev_lookup_allocated
9138 * sizeof (*abbrev_lookup
)));
9140 assert (abbrev_lookup_used
< abbrev_lookup_allocated
);
9141 struct abbrev_lookup_entry
*entry
;
9142 for (entry
= abbrev_lookup
;
9143 entry
< abbrev_lookup
+ abbrev_lookup_used
;
9145 if (entry
->abbrev_tag
== abbrev_tag
)
9147 warn (_("Duplicate abbreviation tag %lu "
9148 "in unit 0x%lx in the debug_names\n"),
9149 (long) abbrev_tag
, (long) (unit_start
- section
->start
));
9152 entry
= &abbrev_lookup
[abbrev_lookup_used
++];
9153 entry
->abbrev_tag
= abbrev_tag
;
9154 entry
->abbrev_lookup_ptr
= abbrevptr
;
9156 /* Skip DWARF tag. */
9157 SKIP_ULEB (abbrevptr
, abbrev_table_end
);
9160 dwarf_vma xindex
, form
;
9162 READ_ULEB (xindex
, abbrevptr
, abbrev_table_end
);
9163 READ_ULEB (form
, abbrevptr
, abbrev_table_end
);
9164 if (xindex
== 0 && form
== 0)
9169 printf (_("\nSymbol table:\n"));
9171 for (namei
= 0; namei
< name_count
; ++namei
)
9173 uint64_t string_offset
, entry_offset
;
9175 SAFE_BYTE_GET (string_offset
,
9176 name_table_string_offsets
+ namei
* offset_size
,
9177 offset_size
, unit_end
);
9178 SAFE_BYTE_GET (entry_offset
,
9179 name_table_entry_offsets
+ namei
* offset_size
,
9180 offset_size
, unit_end
);
9182 printf ("[%3u] #%08x %s:", namei
, hash_table_hashes
[namei
],
9183 fetch_indirect_string (string_offset
));
9185 unsigned char *entryptr
= entry_pool
+ entry_offset
;
9187 // We need to scan first whether there is a single or multiple
9188 // entries. TAGNO is -2 for the first entry, it is -1 for the
9189 // initial tag read of the second entry, then it becomes 0 for the
9190 // first entry for real printing etc.
9192 /* Initialize it due to a false compiler warning. */
9193 dwarf_vma second_abbrev_tag
= -1;
9196 dwarf_vma abbrev_tag
;
9197 dwarf_vma dwarf_tag
;
9198 const struct abbrev_lookup_entry
*entry
;
9200 READ_ULEB (abbrev_tag
, entryptr
, unit_end
);
9203 second_abbrev_tag
= abbrev_tag
;
9205 entryptr
= entry_pool
+ entry_offset
;
9208 if (abbrev_tag
== 0)
9212 (tagno
== 0 && second_abbrev_tag
== 0 ? " " : "\n\t"),
9213 (unsigned long) abbrev_tag
);
9215 for (entry
= abbrev_lookup
;
9216 entry
< abbrev_lookup
+ abbrev_lookup_used
;
9218 if (entry
->abbrev_tag
== abbrev_tag
)
9220 if (entry
>= abbrev_lookup
+ abbrev_lookup_used
)
9222 warn (_("Undefined abbreviation tag %lu "
9223 "in unit 0x%lx in the debug_names\n"),
9225 (long) (unit_start
- section
->start
));
9228 abbrevptr
= entry
->abbrev_lookup_ptr
;
9229 READ_ULEB (dwarf_tag
, abbrevptr
, abbrev_table_end
);
9231 printf (" %s", get_TAG_name (dwarf_tag
));
9234 dwarf_vma xindex
, form
;
9236 READ_ULEB (xindex
, abbrevptr
, abbrev_table_end
);
9237 READ_ULEB (form
, abbrevptr
, abbrev_table_end
);
9238 if (xindex
== 0 && form
== 0)
9242 printf (" %s", get_IDX_name (xindex
));
9243 entryptr
= read_and_display_attr_value (0, form
, 0,
9244 unit_start
, entryptr
, unit_end
,
9246 dwarf_version
, NULL
,
9253 printf (_(" <no entries>"));
9257 free (abbrev_lookup
);
9264 display_debug_links (struct dwarf_section
* section
,
9265 void * file ATTRIBUTE_UNUSED
)
9267 const unsigned char * filename
;
9268 unsigned int filelen
;
9270 introduce (section
, FALSE
);
9272 /* The .gnu_debuglink section is formatted as:
9273 (c-string) Filename.
9274 (padding) If needed to reach a 4 byte boundary.
9275 (uint32_t) CRC32 value.
9277 The .gun_debugaltlink section is formatted as:
9278 (c-string) Filename.
9279 (binary) Build-ID. */
9281 filename
= section
->start
;
9282 filelen
= strnlen ((const char *) filename
, section
->size
);
9283 if (filelen
== section
->size
)
9285 warn (_("The debuglink filename is corrupt/missing\n"));
9289 printf (_(" Separate debug info file: %s\n"), filename
);
9291 if (const_strneq (section
->name
, ".gnu_debuglink"))
9294 unsigned int crc_offset
;
9296 crc_offset
= filelen
+ 1;
9297 crc_offset
= (crc_offset
+ 3) & ~3;
9298 if (crc_offset
+ 4 > section
->size
)
9300 warn (_("CRC offset missing/truncated\n"));
9304 crc32
= byte_get (filename
+ crc_offset
, 4);
9306 printf (_(" CRC value: %#x\n"), crc32
);
9308 if (crc_offset
+ 4 < section
->size
)
9310 warn (_("There are %#lx extraneous bytes at the end of the section\n"),
9311 (long)(section
->size
- (crc_offset
+ 4)));
9315 else /* const_strneq (section->name, ".gnu_debugaltlink") */
9317 const unsigned char * build_id
= section
->start
+ filelen
+ 1;
9318 bfd_size_type build_id_len
= section
->size
- (filelen
+ 1);
9319 bfd_size_type printed
;
9321 /* FIXME: Should we support smaller build-id notes ? */
9322 if (build_id_len
< 0x14)
9324 warn (_("Build-ID is too short (%#lx bytes)\n"), (long) build_id_len
);
9328 printed
= printf (_(" Build-ID (%#lx bytes):"), (long) build_id_len
);
9329 display_data (printed
, build_id
, build_id_len
);
9338 display_gdb_index (struct dwarf_section
*section
,
9339 void *file ATTRIBUTE_UNUSED
)
9341 unsigned char *start
= section
->start
;
9343 uint32_t cu_list_offset
, tu_list_offset
;
9344 uint32_t address_table_offset
, symbol_table_offset
, constant_pool_offset
;
9345 unsigned int cu_list_elements
, tu_list_elements
;
9346 unsigned int address_table_size
, symbol_table_slots
;
9347 unsigned char *cu_list
, *tu_list
;
9348 unsigned char *address_table
, *symbol_table
, *constant_pool
;
9351 /* The documentation for the format of this file is in gdb/dwarf2read.c. */
9353 introduce (section
, FALSE
);
9355 if (section
->size
< 6 * sizeof (uint32_t))
9357 warn (_("Truncated header in the %s section.\n"), section
->name
);
9361 version
= byte_get_little_endian (start
, 4);
9362 printf (_("Version %ld\n"), (long) version
);
9364 /* Prior versions are obsolete, and future versions may not be
9365 backwards compatible. */
9366 if (version
< 3 || version
> 8)
9368 warn (_("Unsupported version %lu.\n"), (unsigned long) version
);
9372 warn (_("The address table data in version 3 may be wrong.\n"));
9374 warn (_("Version 4 does not support case insensitive lookups.\n"));
9376 warn (_("Version 5 does not include inlined functions.\n"));
9378 warn (_("Version 6 does not include symbol attributes.\n"));
9379 /* Version 7 indices generated by Gold have bad type unit references,
9380 PR binutils/15021. But we don't know if the index was generated by
9381 Gold or not, so to avoid worrying users with gdb-generated indices
9382 we say nothing for version 7 here. */
9384 cu_list_offset
= byte_get_little_endian (start
+ 4, 4);
9385 tu_list_offset
= byte_get_little_endian (start
+ 8, 4);
9386 address_table_offset
= byte_get_little_endian (start
+ 12, 4);
9387 symbol_table_offset
= byte_get_little_endian (start
+ 16, 4);
9388 constant_pool_offset
= byte_get_little_endian (start
+ 20, 4);
9390 if (cu_list_offset
> section
->size
9391 || tu_list_offset
> section
->size
9392 || address_table_offset
> section
->size
9393 || symbol_table_offset
> section
->size
9394 || constant_pool_offset
> section
->size
)
9396 warn (_("Corrupt header in the %s section.\n"), section
->name
);
9400 /* PR 17531: file: 418d0a8a. */
9401 if (tu_list_offset
< cu_list_offset
)
9403 warn (_("TU offset (%x) is less than CU offset (%x)\n"),
9404 tu_list_offset
, cu_list_offset
);
9408 cu_list_elements
= (tu_list_offset
- cu_list_offset
) / 8;
9410 if (address_table_offset
< tu_list_offset
)
9412 warn (_("Address table offset (%x) is less than TU offset (%x)\n"),
9413 address_table_offset
, tu_list_offset
);
9417 tu_list_elements
= (address_table_offset
- tu_list_offset
) / 8;
9419 /* PR 17531: file: 18a47d3d. */
9420 if (symbol_table_offset
< address_table_offset
)
9422 warn (_("Symbol table offset (%x) is less then Address table offset (%x)\n"),
9423 symbol_table_offset
, address_table_offset
);
9427 address_table_size
= symbol_table_offset
- address_table_offset
;
9429 if (constant_pool_offset
< symbol_table_offset
)
9431 warn (_("Constant pool offset (%x) is less than symbol table offset (%x)\n"),
9432 constant_pool_offset
, symbol_table_offset
);
9436 symbol_table_slots
= (constant_pool_offset
- symbol_table_offset
) / 8;
9438 cu_list
= start
+ cu_list_offset
;
9439 tu_list
= start
+ tu_list_offset
;
9440 address_table
= start
+ address_table_offset
;
9441 symbol_table
= start
+ symbol_table_offset
;
9442 constant_pool
= start
+ constant_pool_offset
;
9444 if (address_table
+ address_table_size
> section
->start
+ section
->size
)
9446 warn (_("Address table extends beyond end of section.\n"));
9450 printf (_("\nCU table:\n"));
9451 for (i
= 0; i
< cu_list_elements
; i
+= 2)
9453 uint64_t cu_offset
= byte_get_little_endian (cu_list
+ i
* 8, 8);
9454 uint64_t cu_length
= byte_get_little_endian (cu_list
+ i
* 8 + 8, 8);
9456 printf (_("[%3u] 0x%lx - 0x%lx\n"), i
/ 2,
9457 (unsigned long) cu_offset
,
9458 (unsigned long) (cu_offset
+ cu_length
- 1));
9461 printf (_("\nTU table:\n"));
9462 for (i
= 0; i
< tu_list_elements
; i
+= 3)
9464 uint64_t tu_offset
= byte_get_little_endian (tu_list
+ i
* 8, 8);
9465 uint64_t type_offset
= byte_get_little_endian (tu_list
+ i
* 8 + 8, 8);
9466 uint64_t signature
= byte_get_little_endian (tu_list
+ i
* 8 + 16, 8);
9468 printf (_("[%3u] 0x%lx 0x%lx "), i
/ 3,
9469 (unsigned long) tu_offset
,
9470 (unsigned long) type_offset
);
9471 print_dwarf_vma (signature
, 8);
9475 printf (_("\nAddress table:\n"));
9476 for (i
= 0; i
< address_table_size
&& i
<= address_table_size
- (2 * 8 + 4);
9479 uint64_t low
= byte_get_little_endian (address_table
+ i
, 8);
9480 uint64_t high
= byte_get_little_endian (address_table
+ i
+ 8, 8);
9481 uint32_t cu_index
= byte_get_little_endian (address_table
+ i
+ 16, 4);
9483 print_dwarf_vma (low
, 8);
9484 print_dwarf_vma (high
, 8);
9485 printf (_("%lu\n"), (unsigned long) cu_index
);
9488 printf (_("\nSymbol table:\n"));
9489 for (i
= 0; i
< symbol_table_slots
; ++i
)
9491 uint32_t name_offset
= byte_get_little_endian (symbol_table
+ i
* 8, 4);
9492 uint32_t cu_vector_offset
= byte_get_little_endian (symbol_table
+ i
* 8 + 4, 4);
9493 uint32_t num_cus
, cu
;
9495 if (name_offset
!= 0
9496 || cu_vector_offset
!= 0)
9499 unsigned char * adr
;
9501 adr
= constant_pool
+ name_offset
;
9502 /* PR 17531: file: 5b7b07ad. */
9503 if (adr
< constant_pool
|| adr
>= section
->start
+ section
->size
)
9505 printf (_("[%3u] <corrupt offset: %x>"), i
, name_offset
);
9506 warn (_("Corrupt name offset of 0x%x found for symbol table slot %d\n"),
9510 printf ("[%3u] %.*s:", i
,
9511 (int) (section
->size
- (constant_pool_offset
+ name_offset
)),
9512 constant_pool
+ name_offset
);
9514 adr
= constant_pool
+ cu_vector_offset
;
9515 if (adr
< constant_pool
|| adr
>= section
->start
+ section
->size
- 3)
9517 printf (_("<invalid CU vector offset: %x>\n"), cu_vector_offset
);
9518 warn (_("Corrupt CU vector offset of 0x%x found for symbol table slot %d\n"),
9519 cu_vector_offset
, i
);
9523 num_cus
= byte_get_little_endian (adr
, 4);
9525 adr
= constant_pool
+ cu_vector_offset
+ 4 + num_cus
* 4;
9526 if (num_cus
* 4 < num_cus
9527 || adr
>= section
->start
+ section
->size
9528 || adr
< constant_pool
)
9530 printf ("<invalid number of CUs: %d>\n", num_cus
);
9531 warn (_("Invalid number of CUs (0x%x) for symbol table slot %d\n"),
9539 for (j
= 0; j
< num_cus
; ++j
)
9542 gdb_index_symbol_kind kind
;
9544 cu
= byte_get_little_endian (constant_pool
+ cu_vector_offset
+ 4 + j
* 4, 4);
9545 is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu
);
9546 kind
= GDB_INDEX_SYMBOL_KIND_VALUE (cu
);
9547 cu
= GDB_INDEX_CU_VALUE (cu
);
9548 /* Convert to TU number if it's for a type unit. */
9549 if (cu
>= cu_list_elements
/ 2)
9550 printf ("%cT%lu", num_cus
> 1 ? '\t' : ' ',
9551 (unsigned long) (cu
- cu_list_elements
/ 2));
9553 printf ("%c%lu", num_cus
> 1 ? '\t' : ' ', (unsigned long) cu
);
9555 printf (" [%s, %s]",
9556 is_static
? _("static") : _("global"),
9557 get_gdb_index_symbol_kind_name (kind
));
9569 /* Pre-allocate enough space for the CU/TU sets needed. */
9572 prealloc_cu_tu_list (unsigned int nshndx
)
9574 if (shndx_pool
== NULL
)
9576 shndx_pool_size
= nshndx
;
9577 shndx_pool_used
= 0;
9578 shndx_pool
= (unsigned int *) xcmalloc (shndx_pool_size
,
9579 sizeof (unsigned int));
9583 shndx_pool_size
= shndx_pool_used
+ nshndx
;
9584 shndx_pool
= (unsigned int *) xcrealloc (shndx_pool
, shndx_pool_size
,
9585 sizeof (unsigned int));
9590 add_shndx_to_cu_tu_entry (unsigned int shndx
)
9592 if (shndx_pool_used
>= shndx_pool_size
)
9594 error (_("Internal error: out of space in the shndx pool.\n"));
9597 shndx_pool
[shndx_pool_used
++] = shndx
;
9601 end_cu_tu_entry (void)
9603 if (shndx_pool_used
>= shndx_pool_size
)
9605 error (_("Internal error: out of space in the shndx pool.\n"));
9608 shndx_pool
[shndx_pool_used
++] = 0;
9611 /* Return the short name of a DWARF section given by a DW_SECT enumerator. */
9614 get_DW_SECT_short_name (unsigned int dw_sect
)
9616 static char buf
[16];
9624 case DW_SECT_ABBREV
:
9630 case DW_SECT_STR_OFFSETS
:
9632 case DW_SECT_MACINFO
:
9640 snprintf (buf
, sizeof (buf
), "%d", dw_sect
);
9644 /* Process a CU or TU index. If DO_DISPLAY is true, print the contents.
9645 These sections are extensions for Fission.
9646 See http://gcc.gnu.org/wiki/DebugFissionDWP. */
9649 process_cu_tu_index (struct dwarf_section
*section
, int do_display
)
9651 unsigned char *phdr
= section
->start
;
9652 unsigned char *limit
= phdr
+ section
->size
;
9653 unsigned char *phash
;
9654 unsigned char *pindex
;
9655 unsigned char *ppool
;
9656 unsigned int version
;
9657 unsigned int ncols
= 0;
9659 unsigned int nslots
;
9662 dwarf_vma signature_high
;
9663 dwarf_vma signature_low
;
9666 /* PR 17512: file: 002-168123-0.004. */
9669 warn (_("Section %s is empty\n"), section
->name
);
9672 /* PR 17512: file: 002-376-0.004. */
9673 if (section
->size
< 24)
9675 warn (_("Section %s is too small to contain a CU/TU header\n"),
9680 SAFE_BYTE_GET (version
, phdr
, 4, limit
);
9682 SAFE_BYTE_GET (ncols
, phdr
+ 4, 4, limit
);
9683 SAFE_BYTE_GET (nused
, phdr
+ 8, 4, limit
);
9684 SAFE_BYTE_GET (nslots
, phdr
+ 12, 4, limit
);
9687 pindex
= phash
+ (size_t) nslots
* 8;
9688 ppool
= pindex
+ (size_t) nslots
* 4;
9692 introduce (section
, FALSE
);
9694 printf (_(" Version: %u\n"), version
);
9696 printf (_(" Number of columns: %u\n"), ncols
);
9697 printf (_(" Number of used entries: %u\n"), nused
);
9698 printf (_(" Number of slots: %u\n\n"), nslots
);
9701 /* PR 17531: file: 45d69832. */
9702 if ((size_t) nslots
* 8 / 8 != nslots
9703 || phash
< phdr
|| phash
> limit
9704 || pindex
< phash
|| pindex
> limit
9705 || ppool
< pindex
|| ppool
> limit
)
9707 warn (ngettext ("Section %s is too small for %u slot\n",
9708 "Section %s is too small for %u slots\n",
9710 section
->name
, nslots
);
9717 prealloc_cu_tu_list ((limit
- ppool
) / 4);
9718 for (i
= 0; i
< nslots
; i
++)
9720 unsigned char *shndx_list
;
9723 SAFE_BYTE_GET64 (phash
, &signature_high
, &signature_low
, limit
);
9724 if (signature_high
!= 0 || signature_low
!= 0)
9726 SAFE_BYTE_GET (j
, pindex
, 4, limit
);
9727 shndx_list
= ppool
+ j
* 4;
9728 /* PR 17531: file: 705e010d. */
9729 if (shndx_list
< ppool
)
9731 warn (_("Section index pool located before start of section\n"));
9736 printf (_(" [%3d] Signature: 0x%s Sections: "),
9737 i
, dwarf_vmatoa64 (signature_high
, signature_low
,
9738 buf
, sizeof (buf
)));
9741 if (shndx_list
>= limit
)
9743 warn (_("Section %s too small for shndx pool\n"),
9747 SAFE_BYTE_GET (shndx
, shndx_list
, 4, limit
);
9751 printf (" %d", shndx
);
9753 add_shndx_to_cu_tu_entry (shndx
);
9765 else if (version
== 2)
9768 unsigned int dw_sect
;
9769 unsigned char *ph
= phash
;
9770 unsigned char *pi
= pindex
;
9771 unsigned char *poffsets
= ppool
+ (size_t) ncols
* 4;
9772 unsigned char *psizes
= poffsets
+ (size_t) nused
* ncols
* 4;
9773 unsigned char *pend
= psizes
+ (size_t) nused
* ncols
* 4;
9774 bfd_boolean is_tu_index
;
9775 struct cu_tu_set
*this_set
= NULL
;
9777 unsigned char *prow
;
9779 is_tu_index
= strcmp (section
->name
, ".debug_tu_index") == 0;
9781 /* PR 17531: file: 0dd159bf.
9782 Check for integer overflow (can occur when size_t is 32-bit)
9783 with overlarge ncols or nused values. */
9785 && ((size_t) ncols
* 4 / 4 != ncols
9786 || (size_t) nused
* ncols
* 4 / ((size_t) ncols
* 4) != nused
9787 || poffsets
< ppool
|| poffsets
> limit
9788 || psizes
< poffsets
|| psizes
> limit
9789 || pend
< psizes
|| pend
> limit
))
9791 warn (_("Section %s too small for offset and size tables\n"),
9798 printf (_(" Offset table\n"));
9799 printf (" slot %-16s ",
9800 is_tu_index
? _("signature") : _("dwo_id"));
9807 tu_sets
= xcalloc2 (nused
, sizeof (struct cu_tu_set
));
9813 cu_sets
= xcalloc2 (nused
, sizeof (struct cu_tu_set
));
9820 for (j
= 0; j
< ncols
; j
++)
9822 SAFE_BYTE_GET (dw_sect
, ppool
+ j
* 4, 4, limit
);
9823 printf (" %8s", get_DW_SECT_short_name (dw_sect
));
9828 for (i
= 0; i
< nslots
; i
++)
9830 SAFE_BYTE_GET64 (ph
, &signature_high
, &signature_low
, limit
);
9832 SAFE_BYTE_GET (row
, pi
, 4, limit
);
9835 /* PR 17531: file: a05f6ab3. */
9838 warn (_("Row index (%u) is larger than number of used entries (%u)\n"),
9845 size_t num_copy
= sizeof (uint64_t);
9847 /* PR 23064: Beware of buffer overflow. */
9848 if (ph
+ num_copy
< limit
)
9849 memcpy (&this_set
[row
- 1].signature
, ph
, num_copy
);
9852 warn (_("Signature (%p) extends beyond end of space in section\n"), ph
);
9857 prow
= poffsets
+ (row
- 1) * ncols
* 4;
9858 /* PR 17531: file: b8ce60a8. */
9859 if (prow
< poffsets
|| prow
> limit
)
9861 warn (_("Row index (%u) * num columns (%u) > space remaining in section\n"),
9867 printf (_(" [%3d] 0x%s"),
9868 i
, dwarf_vmatoa64 (signature_high
, signature_low
,
9869 buf
, sizeof (buf
)));
9870 for (j
= 0; j
< ncols
; j
++)
9872 SAFE_BYTE_GET (val
, prow
+ j
* 4, 4, limit
);
9874 printf (" %8d", val
);
9877 SAFE_BYTE_GET (dw_sect
, ppool
+ j
* 4, 4, limit
);
9879 /* PR 17531: file: 10796eb3. */
9880 if (dw_sect
>= DW_SECT_MAX
)
9881 warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect
);
9883 this_set
[row
- 1].section_offsets
[dw_sect
] = val
;
9899 printf (_(" Size table\n"));
9900 printf (" slot %-16s ",
9901 is_tu_index
? _("signature") : _("dwo_id"));
9904 for (j
= 0; j
< ncols
; j
++)
9906 SAFE_BYTE_GET (val
, ppool
+ j
* 4, 4, limit
);
9908 printf (" %8s", get_DW_SECT_short_name (val
));
9914 for (i
= 0; i
< nslots
; i
++)
9916 SAFE_BYTE_GET64 (ph
, &signature_high
, &signature_low
, limit
);
9918 SAFE_BYTE_GET (row
, pi
, 4, limit
);
9921 prow
= psizes
+ (row
- 1) * ncols
* 4;
9924 printf (_(" [%3d] 0x%s"),
9925 i
, dwarf_vmatoa64 (signature_high
, signature_low
,
9926 buf
, sizeof (buf
)));
9928 for (j
= 0; j
< ncols
; j
++)
9930 SAFE_BYTE_GET (val
, prow
+ j
* 4, 4, limit
);
9932 printf (" %8d", val
);
9935 SAFE_BYTE_GET (dw_sect
, ppool
+ j
* 4, 4, limit
);
9936 if (dw_sect
>= DW_SECT_MAX
)
9937 warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect
);
9939 this_set
[row
- 1].section_sizes
[dw_sect
] = val
;
9951 else if (do_display
)
9952 printf (_(" Unsupported version (%d)\n"), version
);
9960 /* Load the CU and TU indexes if present. This will build a list of
9961 section sets that we can use to associate a .debug_info.dwo section
9962 with its associated .debug_abbrev.dwo section in a .dwp file. */
9965 load_cu_tu_indexes (void *file
)
9967 static int cu_tu_indexes_read
= -1; /* Tri-state variable. */
9969 /* If we have already loaded (or tried to load) the CU and TU indexes
9970 then do not bother to repeat the task. */
9971 if (cu_tu_indexes_read
== -1)
9973 cu_tu_indexes_read
= TRUE
;
9975 if (load_debug_section_with_follow (dwp_cu_index
, file
))
9976 if (! process_cu_tu_index (&debug_displays
[dwp_cu_index
].section
, 0))
9977 cu_tu_indexes_read
= FALSE
;
9979 if (load_debug_section_with_follow (dwp_tu_index
, file
))
9980 if (! process_cu_tu_index (&debug_displays
[dwp_tu_index
].section
, 0))
9981 cu_tu_indexes_read
= FALSE
;
9984 return (bfd_boolean
) cu_tu_indexes_read
;
9987 /* Find the set of sections that includes section SHNDX. */
9990 find_cu_tu_set (void *file
, unsigned int shndx
)
9994 if (! load_cu_tu_indexes (file
))
9997 /* Find SHNDX in the shndx pool. */
9998 for (i
= 0; i
< shndx_pool_used
; i
++)
9999 if (shndx_pool
[i
] == shndx
)
10002 if (i
>= shndx_pool_used
)
10005 /* Now backup to find the first entry in the set. */
10006 while (i
> 0 && shndx_pool
[i
- 1] != 0)
10009 return shndx_pool
+ i
;
10012 /* Display a .debug_cu_index or .debug_tu_index section. */
10015 display_cu_index (struct dwarf_section
*section
, void *file ATTRIBUTE_UNUSED
)
10017 return process_cu_tu_index (section
, 1);
10021 display_debug_not_supported (struct dwarf_section
*section
,
10022 void *file ATTRIBUTE_UNUSED
)
10024 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
10030 /* Like malloc, but takes two parameters like calloc.
10031 Verifies that the first parameter is not too large.
10032 Note: does *not* initialise the allocated memory to zero. */
10035 cmalloc (size_t nmemb
, size_t size
)
10037 /* Check for overflow. */
10038 if (nmemb
>= ~(size_t) 0 / size
)
10041 return xmalloc (nmemb
* size
);
10044 /* Like xmalloc, but takes two parameters like calloc.
10045 Verifies that the first parameter is not too large.
10046 Note: does *not* initialise the allocated memory to zero. */
10049 xcmalloc (size_t nmemb
, size_t size
)
10051 /* Check for overflow. */
10052 if (nmemb
>= ~(size_t) 0 / size
)
10055 _("Attempt to allocate an array with an excessive number of elements: 0x%lx\n"),
10060 return xmalloc (nmemb
* size
);
10063 /* Like xrealloc, but takes three parameters.
10064 Verifies that the second parameter is not too large.
10065 Note: does *not* initialise any new memory to zero. */
10068 xcrealloc (void *ptr
, size_t nmemb
, size_t size
)
10070 /* Check for overflow. */
10071 if (nmemb
>= ~(size_t) 0 / size
)
10073 error (_("Attempt to re-allocate an array with an excessive number of elements: 0x%lx\n"),
10078 return xrealloc (ptr
, nmemb
* size
);
10081 /* Like xcalloc, but verifies that the first parameter is not too large. */
10084 xcalloc2 (size_t nmemb
, size_t size
)
10086 /* Check for overflow. */
10087 if (nmemb
>= ~(size_t) 0 / size
)
10089 error (_("Attempt to allocate a zero'ed array with an excessive number of elements: 0x%lx\n"),
10094 return xcalloc (nmemb
, size
);
10097 static unsigned long
10098 calc_gnu_debuglink_crc32 (unsigned long crc
,
10099 const unsigned char * buf
,
10102 static const unsigned long crc32_table
[256] =
10104 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
10105 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
10106 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
10107 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
10108 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
10109 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
10110 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
10111 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
10112 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
10113 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
10114 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
10115 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
10116 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
10117 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
10118 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
10119 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
10120 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
10121 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
10122 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
10123 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
10124 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
10125 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
10126 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
10127 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
10128 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
10129 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
10130 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
10131 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
10132 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
10133 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
10134 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
10135 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
10136 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
10137 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
10138 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
10139 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
10140 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
10141 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
10142 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
10143 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
10144 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
10145 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
10146 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
10147 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
10148 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
10149 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
10150 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
10151 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
10152 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
10153 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
10154 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
10157 const unsigned char *end
;
10159 crc
= ~crc
& 0xffffffff;
10160 for (end
= buf
+ len
; buf
< end
; ++ buf
)
10161 crc
= crc32_table
[(crc
^ *buf
) & 0xff] ^ (crc
>> 8);
10162 return ~crc
& 0xffffffff;
10165 typedef bfd_boolean (* check_func_type
) (const char *, void *);
10166 typedef const char * (* parse_func_type
) (struct dwarf_section
*, void *);
10169 check_gnu_debuglink (const char * pathname
, void * crc_pointer
)
10171 static unsigned char buffer
[8 * 1024];
10173 bfd_size_type count
;
10174 unsigned long crc
= 0;
10177 sep_data
= open_debug_file (pathname
);
10178 if (sep_data
== NULL
)
10181 /* Yes - we are opening the file twice... */
10182 f
= fopen (pathname
, "rb");
10185 /* Paranoia: This should never happen. */
10186 close_debug_file (sep_data
);
10187 warn (_("Unable to reopen separate debug info file: %s\n"), pathname
);
10191 while ((count
= fread (buffer
, 1, sizeof (buffer
), f
)) > 0)
10192 crc
= calc_gnu_debuglink_crc32 (crc
, buffer
, count
);
10196 if (crc
!= * (unsigned long *) crc_pointer
)
10198 close_debug_file (sep_data
);
10199 warn (_("Separate debug info file %s found, but CRC does not match - ignoring\n"),
10207 static const char *
10208 parse_gnu_debuglink (struct dwarf_section
* section
, void * data
)
10211 unsigned int crc_offset
;
10212 unsigned long * crc32
= (unsigned long *) data
;
10214 /* The name is first.
10215 The CRC value is stored after the filename, aligned up to 4 bytes. */
10216 name
= (const char *) section
->start
;
10219 crc_offset
= strnlen (name
, section
->size
) + 1;
10220 crc_offset
= (crc_offset
+ 3) & ~3;
10221 if (crc_offset
+ 4 > section
->size
)
10224 * crc32
= byte_get (section
->start
+ crc_offset
, 4);
10229 check_gnu_debugaltlink (const char * filename
, void * data ATTRIBUTE_UNUSED
)
10231 void * sep_data
= open_debug_file (filename
);
10233 if (sep_data
== NULL
)
10236 /* FIXME: We should now extract the build-id in the separate file
10242 typedef struct build_id_data
10245 const unsigned char * data
;
10248 static const char *
10249 parse_gnu_debugaltlink (struct dwarf_section
* section
, void * data
)
10252 bfd_size_type namelen
;
10253 bfd_size_type id_len
;
10254 Build_id_data
* build_id_data
;
10256 /* The name is first.
10257 The build-id follows immediately, with no padding, up to the section's end. */
10259 name
= (const char *) section
->start
;
10260 namelen
= strnlen (name
, section
->size
) + 1;
10261 if (namelen
>= section
->size
)
10264 id_len
= section
->size
- namelen
;
10268 build_id_data
= calloc (1, sizeof * build_id_data
);
10269 if (build_id_data
== NULL
)
10272 build_id_data
->len
= id_len
;
10273 build_id_data
->data
= section
->start
+ namelen
;
10275 * (Build_id_data
**) data
= build_id_data
;
10281 add_separate_debug_file (const char * filename
, void * handle
)
10283 separate_info
* i
= xmalloc (sizeof * i
);
10285 i
->filename
= filename
;
10286 i
->handle
= handle
;
10287 i
->next
= first_separate_info
;
10288 first_separate_info
= i
;
10291 #if HAVE_LIBDEBUGINFOD
10292 /* Query debuginfod servers for the target debuglink or debugaltlink
10293 file. If successful, store the path of the file in filename and
10294 return TRUE, otherwise return FALSE. */
10297 debuginfod_fetch_separate_debug_info (struct dwarf_section
* section
,
10301 size_t build_id_len
;
10302 unsigned char * build_id
;
10304 if (strcmp (section
->uncompressed_name
, ".gnu_debuglink") == 0)
10306 /* Get the build-id of file. */
10307 build_id
= get_build_id (file
);
10310 else if (strcmp (section
->uncompressed_name
, ".gnu_debugaltlink") == 0)
10312 /* Get the build-id of the debugaltlink file. */
10313 unsigned int filelen
;
10315 filelen
= strnlen ((const char *)section
->start
, section
->size
);
10316 if (filelen
== section
->size
)
10317 /* Corrupt debugaltlink. */
10320 build_id
= section
->start
+ filelen
+ 1;
10321 build_id_len
= section
->size
- (filelen
+ 1);
10323 if (build_id_len
== 0)
10332 debuginfod_client
* client
;
10334 client
= debuginfod_begin ();
10335 if (client
== NULL
)
10338 /* Query debuginfod servers for the target file. If found its path
10339 will be stored in filename. */
10340 fd
= debuginfod_find_debuginfo (client
, build_id
, build_id_len
, filename
);
10341 debuginfod_end (client
);
10343 /* Only free build_id if we allocated space for a hex string
10344 in get_build_id (). */
10345 if (build_id_len
== 0)
10350 /* File successfully retrieved. Close fd since we want to
10351 use open_debug_file () on filename instead. */
10362 load_separate_debug_info (const char * main_filename
,
10363 struct dwarf_section
* xlink
,
10364 parse_func_type parse_func
,
10365 check_func_type check_func
,
10367 void * file ATTRIBUTE_UNUSED
)
10369 const char * separate_filename
;
10370 char * debug_filename
;
10372 size_t canon_dirlen
;
10375 if ((separate_filename
= parse_func (xlink
, func_data
)) == NULL
)
10377 warn (_("Corrupt debuglink section: %s\n"),
10378 xlink
->name
? xlink
->name
: xlink
->uncompressed_name
);
10382 /* Attempt to locate the separate file.
10383 This should duplicate the logic in bfd/opncls.c:find_separate_debug_file(). */
10385 canon_dir
= lrealpath (main_filename
);
10387 for (canon_dirlen
= strlen (canon_dir
); canon_dirlen
> 0; canon_dirlen
--)
10388 if (IS_DIR_SEPARATOR (canon_dir
[canon_dirlen
- 1]))
10390 canon_dir
[canon_dirlen
] = '\0';
10393 #define DEBUGDIR "/lib/debug"
10395 #ifndef EXTRA_DEBUG_ROOT1
10396 #define EXTRA_DEBUG_ROOT1 "/usr/lib/debug"
10398 #ifndef EXTRA_DEBUG_ROOT2
10399 #define EXTRA_DEBUG_ROOT2 "/usr/lib/debug/usr"
10402 debug_filename
= (char *) malloc (strlen (DEBUGDIR
) + 1
10404 + strlen (".debug/")
10405 #ifdef EXTRA_DEBUG_ROOT1
10406 + strlen (EXTRA_DEBUG_ROOT1
)
10408 #ifdef EXTRA_DEBUG_ROOT2
10409 + strlen (EXTRA_DEBUG_ROOT2
)
10411 + strlen (separate_filename
)
10413 if (debug_filename
== NULL
)
10415 warn (_("Out of memory"));
10420 /* First try in the current directory. */
10421 sprintf (debug_filename
, "%s", separate_filename
);
10422 if (check_func (debug_filename
, func_data
))
10425 /* Then try in a subdirectory called .debug. */
10426 sprintf (debug_filename
, ".debug/%s", separate_filename
);
10427 if (check_func (debug_filename
, func_data
))
10430 /* Then try in the same directory as the original file. */
10431 sprintf (debug_filename
, "%s%s", canon_dir
, separate_filename
);
10432 if (check_func (debug_filename
, func_data
))
10435 /* And the .debug subdirectory of that directory. */
10436 sprintf (debug_filename
, "%s.debug/%s", canon_dir
, separate_filename
);
10437 if (check_func (debug_filename
, func_data
))
10440 #ifdef EXTRA_DEBUG_ROOT1
10441 /* Try the first extra debug file root. */
10442 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT1
, separate_filename
);
10443 if (check_func (debug_filename
, func_data
))
10446 /* Try the first extra debug file root. */
10447 sprintf (debug_filename
, "%s/%s/%s", EXTRA_DEBUG_ROOT1
, canon_dir
, separate_filename
);
10448 if (check_func (debug_filename
, func_data
))
10452 #ifdef EXTRA_DEBUG_ROOT2
10453 /* Try the second extra debug file root. */
10454 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT2
, separate_filename
);
10455 if (check_func (debug_filename
, func_data
))
10459 /* Then try in the global debug_filename directory. */
10460 strcpy (debug_filename
, DEBUGDIR
);
10461 dirlen
= strlen (DEBUGDIR
) - 1;
10462 if (dirlen
> 0 && DEBUGDIR
[dirlen
] != '/')
10463 strcat (debug_filename
, "/");
10464 strcat (debug_filename
, (const char *) separate_filename
);
10466 if (check_func (debug_filename
, func_data
))
10469 #if HAVE_LIBDEBUGINFOD
10471 char * tmp_filename
;
10473 if (debuginfod_fetch_separate_debug_info (xlink
,
10477 /* File successfully downloaded from server, replace
10478 debug_filename with the file's path. */
10479 free (debug_filename
);
10480 debug_filename
= tmp_filename
;
10486 /* Failed to find the file. */
10487 warn (_("could not find separate debug file '%s'\n"), separate_filename
);
10488 warn (_("tried: %s\n"), debug_filename
);
10490 #ifdef EXTRA_DEBUG_ROOT2
10491 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT2
, separate_filename
);
10492 warn (_("tried: %s\n"), debug_filename
);
10495 #ifdef EXTRA_DEBUG_ROOT1
10496 sprintf (debug_filename
, "%s/%s/%s", EXTRA_DEBUG_ROOT1
, canon_dir
, separate_filename
);
10497 warn (_("tried: %s\n"), debug_filename
);
10499 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT1
, separate_filename
);
10500 warn (_("tried: %s\n"), debug_filename
);
10503 sprintf (debug_filename
, "%s.debug/%s", canon_dir
, separate_filename
);
10504 warn (_("tried: %s\n"), debug_filename
);
10506 sprintf (debug_filename
, "%s%s", canon_dir
, separate_filename
);
10507 warn (_("tried: %s\n"), debug_filename
);
10509 sprintf (debug_filename
, ".debug/%s", separate_filename
);
10510 warn (_("tried: %s\n"), debug_filename
);
10512 sprintf (debug_filename
, "%s", separate_filename
);
10513 warn (_("tried: %s\n"), debug_filename
);
10515 #if HAVE_LIBDEBUGINFOD
10517 char *urls
= getenv (DEBUGINFOD_URLS_ENV_VAR
);
10521 warn (_("tried: DEBUGINFOD_URLS=%s\n"), urls
);
10526 free (debug_filename
);
10532 void * debug_handle
;
10534 /* Now open the file.... */
10535 if ((debug_handle
= open_debug_file (debug_filename
)) == NULL
)
10537 warn (_("failed to open separate debug file: %s\n"), debug_filename
);
10538 free (debug_filename
);
10542 /* FIXME: We do not check to see if there are any other separate debug info
10543 files that would also match. */
10545 printf (_("%s: Found separate debug info file: %s\n\n"), main_filename
, debug_filename
);
10546 add_separate_debug_file (debug_filename
, debug_handle
);
10548 /* Do not free debug_filename - it might be referenced inside
10549 the structure returned by open_debug_file(). */
10550 return debug_handle
;
10553 /* Attempt to load a separate dwarf object file. */
10556 load_dwo_file (const char * main_filename
, const char * name
, const char * dir
, const char * id ATTRIBUTE_UNUSED
)
10558 char * separate_filename
;
10559 void * separate_handle
;
10561 /* FIXME: Skip adding / if dwo_dir ends in /. */
10562 separate_filename
= concat (dir
, "/", name
, NULL
);
10563 if (separate_filename
== NULL
)
10565 warn (_("Out of memory allocating dwo filename\n"));
10569 if ((separate_handle
= open_debug_file (separate_filename
)) == NULL
)
10571 warn (_("Unable to load dwo file: %s\n"), separate_filename
);
10572 free (separate_filename
);
10576 /* FIXME: We should check the dwo_id. */
10578 printf (_("%s: Found separate debug object file: %s\n\n"), main_filename
, separate_filename
);
10579 add_separate_debug_file (separate_filename
, separate_handle
);
10580 /* Note - separate_filename will be freed in free_debug_memory(). */
10581 return separate_handle
;
10584 /* Load the separate debug info file(s) attached to FILE, if any exist.
10585 Returns TRUE if any were found, FALSE otherwise.
10586 If TRUE is returned then the linked list starting at first_separate_info
10587 will be populated with open file handles. */
10590 load_separate_debug_files (void * file
, const char * filename
)
10592 /* Skip this operation if we are not interested in debug links. */
10593 if (! do_follow_links
&& ! do_debug_links
)
10596 /* See if there are any dwo links. */
10597 if (load_debug_section (str
, file
)
10598 && load_debug_section (abbrev
, file
)
10599 && load_debug_section (info
, file
))
10603 if (process_debug_info (& debug_displays
[info
].section
, file
, abbrev
, TRUE
, FALSE
))
10605 bfd_boolean introduced
= FALSE
;
10607 const char * dir
= NULL
;
10608 const char * id
= NULL
;
10610 for (dwinfo
= first_dwo_info
; dwinfo
!= NULL
; dwinfo
= dwinfo
->next
)
10612 switch (dwinfo
->type
)
10615 if (do_debug_links
)
10619 printf (_("The %s section contains link(s) to dwo file(s):\n\n"),
10620 debug_displays
[info
].section
.uncompressed_name
);
10624 printf (_(" Name: %s\n"), dwinfo
->value
);
10625 printf (_(" Directory: %s\n"), dir
? dir
: _("<not-found>"));
10627 display_data (printf (_(" ID: ")), (unsigned char *) id
, 8);
10629 printf (_(" ID: <unknown>\n"));
10633 if (do_follow_links
)
10634 load_dwo_file (filename
, dwinfo
->value
, dir
, id
);
10638 dir
= dwinfo
->value
;
10642 id
= dwinfo
->value
;
10646 error (_("Unexpected DWO INFO type"));
10653 if (! do_follow_links
)
10654 /* The other debug links will be displayed by display_debug_links()
10655 so we do not need to do any further processing here. */
10658 /* FIXME: We do not check for the presence of both link sections in the same file. */
10659 /* FIXME: We do not check the separate debug info file to see if it too contains debuglinks. */
10660 /* FIXME: We do not check for the presence of multiple, same-name debuglink sections. */
10661 /* FIXME: We do not check for the presence of a dwo link as well as a debuglink. */
10663 if (load_debug_section (gnu_debugaltlink
, file
))
10665 Build_id_data
* build_id_data
;
10667 load_separate_debug_info (filename
,
10668 & debug_displays
[gnu_debugaltlink
].section
,
10669 parse_gnu_debugaltlink
,
10670 check_gnu_debugaltlink
,
10675 if (load_debug_section (gnu_debuglink
, file
))
10677 unsigned long crc32
;
10679 load_separate_debug_info (filename
,
10680 & debug_displays
[gnu_debuglink
].section
,
10681 parse_gnu_debuglink
,
10682 check_gnu_debuglink
,
10687 if (first_separate_info
!= NULL
)
10690 do_follow_links
= 0;
10695 free_debug_memory (void)
10701 for (i
= 0; i
< max
; i
++)
10702 free_debug_section ((enum dwarf_section_display_enum
) i
);
10704 if (debug_information
!= NULL
)
10706 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
)
10708 for (i
= 0; i
< num_debug_info_entries
; i
++)
10710 if (!debug_information
[i
].max_loc_offsets
)
10712 free (debug_information
[i
].loc_offsets
);
10713 free (debug_information
[i
].have_frame_base
);
10715 if (!debug_information
[i
].max_range_lists
)
10716 free (debug_information
[i
].range_lists
);
10719 free (debug_information
);
10720 debug_information
= NULL
;
10721 alloc_num_debug_info_entries
= num_debug_info_entries
= 0;
10725 separate_info
* next
;
10727 for (d
= first_separate_info
; d
!= NULL
; d
= next
)
10729 close_debug_file (d
->handle
);
10730 free ((void *) d
->filename
);
10734 first_separate_info
= NULL
;
10740 dwarf_select_sections_by_names (const char *names
)
10744 const char * option
;
10748 debug_dump_long_opts
;
10750 static const debug_dump_long_opts opts_table
[] =
10752 /* Please keep this table alpha- sorted. */
10753 { "Ranges", & do_debug_ranges
, 1 },
10754 { "abbrev", & do_debug_abbrevs
, 1 },
10755 { "addr", & do_debug_addr
, 1 },
10756 { "aranges", & do_debug_aranges
, 1 },
10757 { "cu_index", & do_debug_cu_index
, 1 },
10758 { "decodedline", & do_debug_lines
, FLAG_DEBUG_LINES_DECODED
},
10759 { "follow-links", & do_follow_links
, 1 },
10760 { "frames", & do_debug_frames
, 1 },
10761 { "frames-interp", & do_debug_frames_interp
, 1 },
10762 /* The special .gdb_index section. */
10763 { "gdb_index", & do_gdb_index
, 1 },
10764 { "info", & do_debug_info
, 1 },
10765 { "line", & do_debug_lines
, FLAG_DEBUG_LINES_RAW
}, /* For backwards compatibility. */
10766 { "links", & do_debug_links
, 1 },
10767 { "loc", & do_debug_loc
, 1 },
10768 { "macro", & do_debug_macinfo
, 1 },
10769 { "pubnames", & do_debug_pubnames
, 1 },
10770 { "pubtypes", & do_debug_pubtypes
, 1 },
10771 /* This entry is for compatibility
10772 with earlier versions of readelf. */
10773 { "ranges", & do_debug_aranges
, 1 },
10774 { "rawline", & do_debug_lines
, FLAG_DEBUG_LINES_RAW
},
10775 { "str", & do_debug_str
, 1 },
10776 { "str-offsets", & do_debug_str_offsets
, 1 },
10777 /* These trace_* sections are used by Itanium VMS. */
10778 { "trace_abbrev", & do_trace_abbrevs
, 1 },
10779 { "trace_aranges", & do_trace_aranges
, 1 },
10780 { "trace_info", & do_trace_info
, 1 },
10789 const debug_dump_long_opts
* entry
;
10791 for (entry
= opts_table
; entry
->option
; entry
++)
10793 size_t len
= strlen (entry
->option
);
10795 if (strncmp (p
, entry
->option
, len
) == 0
10796 && (p
[len
] == ',' || p
[len
] == '\0'))
10798 * entry
->variable
|= entry
->val
;
10800 /* The --debug-dump=frames-interp option also
10801 enables the --debug-dump=frames option. */
10802 if (do_debug_frames_interp
)
10803 do_debug_frames
= 1;
10810 if (entry
->option
== NULL
)
10812 warn (_("Unrecognized debug option '%s'\n"), p
);
10813 p
= strchr (p
, ',');
10824 dwarf_select_sections_by_letters (const char *letters
)
10826 unsigned int lindex
= 0;
10828 while (letters
[lindex
])
10829 switch (letters
[lindex
++])
10831 case 'A': do_debug_addr
= 1; break;
10832 case 'a': do_debug_abbrevs
= 1; break;
10833 case 'c': do_debug_cu_index
= 1; break;
10834 case 'F': do_debug_frames_interp
= 1; /* Fall through. */
10835 case 'f': do_debug_frames
= 1; break;
10836 case 'g': do_gdb_index
= 1; break;
10837 case 'i': do_debug_info
= 1; break;
10838 case 'K': do_follow_links
= 1; break;
10839 case 'k': do_debug_links
= 1; break;
10840 case 'l': do_debug_lines
|= FLAG_DEBUG_LINES_RAW
; break;
10841 case 'L': do_debug_lines
|= FLAG_DEBUG_LINES_DECODED
; break;
10842 case 'm': do_debug_macinfo
= 1; break;
10843 case 'O': do_debug_str_offsets
= 1; break;
10844 case 'o': do_debug_loc
= 1; break;
10845 case 'p': do_debug_pubnames
= 1; break;
10846 case 'R': do_debug_ranges
= 1; break;
10847 case 'r': do_debug_aranges
= 1; break;
10848 case 's': do_debug_str
= 1; break;
10849 case 'T': do_trace_aranges
= 1; break;
10850 case 't': do_debug_pubtypes
= 1; break;
10851 case 'U': do_trace_info
= 1; break;
10852 case 'u': do_trace_abbrevs
= 1; break;
10855 warn (_("Unrecognized debug option '%s'\n"), letters
);
10861 dwarf_select_sections_all (void)
10864 do_debug_abbrevs
= 1;
10865 do_debug_lines
= FLAG_DEBUG_LINES_RAW
;
10866 do_debug_pubnames
= 1;
10867 do_debug_pubtypes
= 1;
10868 do_debug_aranges
= 1;
10869 do_debug_ranges
= 1;
10870 do_debug_frames
= 1;
10871 do_debug_macinfo
= 1;
10876 do_trace_abbrevs
= 1;
10877 do_trace_aranges
= 1;
10879 do_debug_cu_index
= 1;
10880 do_follow_links
= 1;
10881 do_debug_links
= 1;
10882 do_debug_str_offsets
= 1;
10885 #define NO_ABBREVS NULL, NULL, NULL, 0, 0, 0, NULL, 0, NULL
10886 #define ABBREV(N) NULL, NULL, NULL, 0, 0, N, NULL, 0, NULL
10888 /* N.B. The order here must match the order in section_display_enum. */
10890 struct dwarf_section_display debug_displays
[] =
10892 { { ".debug_abbrev", ".zdebug_abbrev", NO_ABBREVS
}, display_debug_abbrev
, &do_debug_abbrevs
, FALSE
},
10893 { { ".debug_aranges", ".zdebug_aranges", NO_ABBREVS
}, display_debug_aranges
, &do_debug_aranges
, TRUE
},
10894 { { ".debug_frame", ".zdebug_frame", NO_ABBREVS
}, display_debug_frames
, &do_debug_frames
, TRUE
},
10895 { { ".debug_info", ".zdebug_info", ABBREV (abbrev
)}, display_debug_info
, &do_debug_info
, TRUE
},
10896 { { ".debug_line", ".zdebug_line", NO_ABBREVS
}, display_debug_lines
, &do_debug_lines
, TRUE
},
10897 { { ".debug_pubnames", ".zdebug_pubnames", NO_ABBREVS
}, display_debug_pubnames
, &do_debug_pubnames
, FALSE
},
10898 { { ".debug_gnu_pubnames", ".zdebug_gnu_pubnames", NO_ABBREVS
}, display_debug_gnu_pubnames
, &do_debug_pubnames
, FALSE
},
10899 { { ".eh_frame", "", NO_ABBREVS
}, display_debug_frames
, &do_debug_frames
, TRUE
},
10900 { { ".debug_macinfo", ".zdebug_macinfo", NO_ABBREVS
}, display_debug_macinfo
, &do_debug_macinfo
, FALSE
},
10901 { { ".debug_macro", ".zdebug_macro", NO_ABBREVS
}, display_debug_macro
, &do_debug_macinfo
, TRUE
},
10902 { { ".debug_str", ".zdebug_str", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, FALSE
},
10903 { { ".debug_line_str", ".zdebug_line_str", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, FALSE
},
10904 { { ".debug_loc", ".zdebug_loc", NO_ABBREVS
}, display_debug_loc
, &do_debug_loc
, TRUE
},
10905 { { ".debug_loclists", ".zdebug_loclists", NO_ABBREVS
}, display_debug_loc
, &do_debug_loc
, TRUE
},
10906 { { ".debug_pubtypes", ".zdebug_pubtypes", NO_ABBREVS
}, display_debug_pubnames
, &do_debug_pubtypes
, FALSE
},
10907 { { ".debug_gnu_pubtypes", ".zdebug_gnu_pubtypes", NO_ABBREVS
}, display_debug_gnu_pubnames
, &do_debug_pubtypes
, FALSE
},
10908 { { ".debug_ranges", ".zdebug_ranges", NO_ABBREVS
}, display_debug_ranges
, &do_debug_ranges
, TRUE
},
10909 { { ".debug_rnglists", ".zdebug_rnglists", NO_ABBREVS
}, display_debug_ranges
, &do_debug_ranges
, TRUE
},
10910 { { ".debug_static_func", ".zdebug_static_func", NO_ABBREVS
}, display_debug_not_supported
, NULL
, FALSE
},
10911 { { ".debug_static_vars", ".zdebug_static_vars", NO_ABBREVS
}, display_debug_not_supported
, NULL
, FALSE
},
10912 { { ".debug_types", ".zdebug_types", ABBREV (abbrev
) }, display_debug_types
, &do_debug_info
, TRUE
},
10913 { { ".debug_weaknames", ".zdebug_weaknames", NO_ABBREVS
}, display_debug_not_supported
, NULL
, FALSE
},
10914 { { ".gdb_index", "", NO_ABBREVS
}, display_gdb_index
, &do_gdb_index
, FALSE
},
10915 { { ".debug_names", "", NO_ABBREVS
}, display_debug_names
, &do_gdb_index
, FALSE
},
10916 { { ".trace_info", "", ABBREV (trace_abbrev
) }, display_trace_info
, &do_trace_info
, TRUE
},
10917 { { ".trace_abbrev", "", NO_ABBREVS
}, display_debug_abbrev
, &do_trace_abbrevs
, FALSE
},
10918 { { ".trace_aranges", "", NO_ABBREVS
}, display_debug_aranges
, &do_trace_aranges
, FALSE
},
10919 { { ".debug_info.dwo", ".zdebug_info.dwo", ABBREV (abbrev_dwo
) }, display_debug_info
, &do_debug_info
, TRUE
},
10920 { { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo", NO_ABBREVS
}, display_debug_abbrev
, &do_debug_abbrevs
, FALSE
},
10921 { { ".debug_types.dwo", ".zdebug_types.dwo", ABBREV (abbrev_dwo
) }, display_debug_types
, &do_debug_info
, TRUE
},
10922 { { ".debug_line.dwo", ".zdebug_line.dwo", NO_ABBREVS
}, display_debug_lines
, &do_debug_lines
, TRUE
},
10923 { { ".debug_loc.dwo", ".zdebug_loc.dwo", NO_ABBREVS
}, display_debug_loc
, &do_debug_loc
, TRUE
},
10924 { { ".debug_macro.dwo", ".zdebug_macro.dwo", NO_ABBREVS
}, display_debug_macro
, &do_debug_macinfo
, TRUE
},
10925 { { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo", NO_ABBREVS
}, display_debug_macinfo
, &do_debug_macinfo
, FALSE
},
10926 { { ".debug_str.dwo", ".zdebug_str.dwo", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, TRUE
},
10927 { { ".debug_str_offsets", ".zdebug_str_offsets", NO_ABBREVS
}, display_debug_str_offsets
, &do_debug_str_offsets
, TRUE
},
10928 { { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo", NO_ABBREVS
}, display_debug_str_offsets
, &do_debug_str_offsets
, TRUE
},
10929 { { ".debug_addr", ".zdebug_addr", NO_ABBREVS
}, display_debug_addr
, &do_debug_addr
, TRUE
},
10930 { { ".debug_cu_index", "", NO_ABBREVS
}, display_cu_index
, &do_debug_cu_index
, FALSE
},
10931 { { ".debug_tu_index", "", NO_ABBREVS
}, display_cu_index
, &do_debug_cu_index
, FALSE
},
10932 { { ".gnu_debuglink", "", NO_ABBREVS
}, display_debug_links
, &do_debug_links
, FALSE
},
10933 { { ".gnu_debugaltlink", "", NO_ABBREVS
}, display_debug_links
, &do_debug_links
, FALSE
},
10934 /* Separate debug info files can containt their own .debug_str section,
10935 and this might be in *addition* to a .debug_str section already present
10936 in the main file. Hence we need to have two entries for .debug_str. */
10937 { { ".debug_str", ".zdebug_str", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, FALSE
},
10940 /* A static assertion. */
10941 extern int debug_displays_assert
[ARRAY_SIZE (debug_displays
) == max
? 1 : -1];