1 /* dwarf.c -- display DWARF contents of a BFD binary file
2 Copyright (C) 2005-2019 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"
37 #define MAX(a, b) ((a) > (b) ? (a) : (b))
38 #define MIN(a, b) ((a) < (b) ? (a) : (b))
40 static const char *regname (unsigned int regno
, int row
);
42 static int have_frame_base
;
43 static int need_base_address
;
45 static unsigned int num_debug_info_entries
= 0;
46 static unsigned int alloc_num_debug_info_entries
= 0;
47 static debug_info
*debug_information
= NULL
;
48 /* Special value for num_debug_info_entries to indicate
49 that the .debug_info section could not be loaded/parsed. */
50 #define DEBUG_INFO_UNAVAILABLE (unsigned int) -1
52 /* A .debug_info section can contain multiple links to separate
53 DWO object files. We use these structures to record these links. */
61 typedef struct dwo_info
65 struct dwo_info
* next
;
68 static dwo_info
* first_dwo_info
= NULL
;
69 static bfd_boolean need_dwo_info
;
71 separate_info
* first_separate_info
= NULL
;
73 unsigned int eh_addr_size
;
78 int do_debug_pubnames
;
79 int do_debug_pubtypes
;
83 int do_debug_frames_interp
;
92 int do_debug_cu_index
;
97 int dwarf_cutoff_level
= -1;
98 unsigned long dwarf_start_die
;
102 /* Convenient constant, to avoid having to cast -1 to dwarf_vma when
103 testing whether e.g. a locview list is present. */
104 static const dwarf_vma vm1
= -1;
106 /* Collection of CU/TU section sets from .debug_cu_index and .debug_tu_index
107 sections. For version 1 package files, each set is stored in SHNDX_POOL
108 as a zero-terminated list of section indexes comprising one set of debug
109 sections from a .dwo file. */
111 static unsigned int *shndx_pool
= NULL
;
112 static unsigned int shndx_pool_size
= 0;
113 static unsigned int shndx_pool_used
= 0;
115 /* For version 2 package files, each set contains an array of section offsets
116 and an array of section sizes, giving the offset and size of the
117 contribution from a CU or TU within one of the debug sections.
118 When displaying debug info from a package file, we need to use these
119 tables to locate the corresponding contributions to each section. */
124 dwarf_vma section_offsets
[DW_SECT_MAX
];
125 size_t section_sizes
[DW_SECT_MAX
];
128 static int cu_count
= 0;
129 static int tu_count
= 0;
130 static struct cu_tu_set
*cu_sets
= NULL
;
131 static struct cu_tu_set
*tu_sets
= NULL
;
133 static bfd_boolean
load_cu_tu_indexes (void *);
135 /* An array that indicates for a given level of CU nesting whether
136 the latest DW_AT_type seen for that level was a signed type or
138 #define MAX_CU_NESTING (1 << 8)
139 static bfd_boolean level_type_signed
[MAX_CU_NESTING
];
141 /* Values for do_debug_lines. */
142 #define FLAG_DEBUG_LINES_RAW 1
143 #define FLAG_DEBUG_LINES_DECODED 2
146 size_of_encoded_value (int encoding
)
148 switch (encoding
& 0x7)
151 case 0: return eh_addr_size
;
159 get_encoded_value (unsigned char **pdata
,
161 struct dwarf_section
*section
,
164 unsigned char * data
= * pdata
;
165 unsigned int size
= size_of_encoded_value (encoding
);
168 if (data
+ size
>= end
)
170 warn (_("Encoded value extends past end of section\n"));
175 /* PR 17512: file: 002-829853-0.004. */
178 warn (_("Encoded size of %d is too large to read\n"), size
);
183 /* PR 17512: file: 1085-5603-0.004. */
186 warn (_("Encoded size of 0 is too small to read\n"));
191 if (encoding
& DW_EH_PE_signed
)
192 val
= byte_get_signed (data
, size
);
194 val
= byte_get (data
, size
);
196 if ((encoding
& 0x70) == DW_EH_PE_pcrel
)
197 val
+= section
->address
+ (data
- section
->start
);
199 * pdata
= data
+ size
;
203 #if defined HAVE_LONG_LONG && SIZEOF_LONG_LONG > SIZEOF_LONG
205 # define DWARF_VMA_FMT "ll"
206 # define DWARF_VMA_FMT_LONG "%16.16llx"
208 # define DWARF_VMA_FMT "I64"
209 # define DWARF_VMA_FMT_LONG "%016I64x"
212 # define DWARF_VMA_FMT "l"
213 # define DWARF_VMA_FMT_LONG "%16.16lx"
216 /* Convert a dwarf vma value into a string. Returns a pointer to a static
217 buffer containing the converted VALUE. The value is converted according
218 to the printf formating character FMTCH. If NUM_BYTES is non-zero then
219 it specifies the maximum number of bytes to be displayed in the converted
220 value and FMTCH is ignored - hex is always used. */
223 dwarf_vmatoa_1 (const char *fmtch
, dwarf_vma value
, unsigned num_bytes
)
225 /* As dwarf_vmatoa is used more then once in a printf call
226 for output, we are cycling through an fixed array of pointers
227 for return address. */
228 static int buf_pos
= 0;
229 static struct dwarf_vmatoa_buf
235 ret
= buf
[buf_pos
++].place
;
236 buf_pos
%= ARRAY_SIZE (buf
);
240 /* Printf does not have a way of specifying a maximum field width for an
241 integer value, so we print the full value into a buffer and then select
242 the precision we need. */
243 snprintf (ret
, sizeof (buf
[0].place
), DWARF_VMA_FMT_LONG
, value
);
246 return ret
+ (16 - 2 * num_bytes
);
253 sprintf (fmt
, "%%%s%s", DWARF_VMA_FMT
, fmtch
);
255 sprintf (fmt
, "%%%s", DWARF_VMA_FMT
);
256 snprintf (ret
, sizeof (buf
[0].place
), fmt
, value
);
261 static inline const char *
262 dwarf_vmatoa (const char * fmtch
, dwarf_vma value
)
264 return dwarf_vmatoa_1 (fmtch
, value
, 0);
267 /* Print a dwarf_vma value (typically an address, offset or length) in
268 hexadecimal format, followed by a space. The length of the VALUE (and
269 hence the precision displayed) is determined by the NUM_BYTES parameter. */
272 print_dwarf_vma (dwarf_vma value
, unsigned num_bytes
)
274 printf ("%s ", dwarf_vmatoa_1 (NULL
, value
, num_bytes
));
277 /* Print a view number in hexadecimal value, with the same width
278 print_dwarf_vma would have printed it with the same num_bytes.
279 Print blanks for zero view, unless force is nonzero. */
282 print_dwarf_view (dwarf_vma value
, unsigned num_bytes
, int force
)
290 assert (value
== (unsigned long) value
);
292 printf ("v%0*lx ", len
- 1, (unsigned long) value
);
294 printf ("%*s", len
+ 1, "");
297 /* Format a 64-bit value, given as two 32-bit values, in hex.
298 For reentrancy, this uses a buffer provided by the caller. */
301 dwarf_vmatoa64 (dwarf_vma hvalue
, dwarf_vma lvalue
, char *buf
,
302 unsigned int buf_len
)
307 snprintf (buf
, buf_len
, "%" DWARF_VMA_FMT
"x", lvalue
);
310 len
= snprintf (buf
, buf_len
, "%" DWARF_VMA_FMT
"x", hvalue
);
311 snprintf (buf
+ len
, buf_len
- len
,
312 "%08" DWARF_VMA_FMT
"x", lvalue
);
318 /* Read in a LEB128 encoded value starting at address DATA.
319 If SIGN is true, return a signed LEB128 value.
320 If LENGTH_RETURN is not NULL, return in it the number of bytes read.
321 No bytes will be read at address END or beyond. */
324 read_leb128 (unsigned char *data
,
325 unsigned int *length_return
,
327 const unsigned char * const end
)
329 dwarf_vma result
= 0;
330 unsigned int num_read
= 0;
331 unsigned int shift
= 0;
332 unsigned char byte
= 0;
339 result
|= ((dwarf_vma
) (byte
& 0x7f)) << shift
;
342 if ((byte
& 0x80) == 0)
345 /* PR 17512: file: 0ca183b8.
346 FIXME: Should we signal this error somehow ? */
347 if (shift
>= sizeof (result
) * 8)
351 if (length_return
!= NULL
)
352 *length_return
= num_read
;
354 if (sign
&& (shift
< 8 * sizeof (result
)) && (byte
& 0x40))
355 result
|= -((dwarf_vma
) 1 << shift
);
360 /* Create a signed version to avoid painful typecasts. */
361 static inline dwarf_signed_vma
362 read_sleb128 (unsigned char * data
,
363 unsigned int * length_return
,
364 const unsigned char * const end
)
366 return (dwarf_signed_vma
) read_leb128 (data
, length_return
, TRUE
, end
);
369 static inline dwarf_vma
370 read_uleb128 (unsigned char * data
,
371 unsigned int * length_return
,
372 const unsigned char * const end
)
374 return read_leb128 (data
, length_return
, FALSE
, end
);
377 #define SKIP_ULEB() read_uleb128 (start, & length_return, end); start += length_return
378 #define SKIP_SLEB() read_sleb128 (start, & length_return, end); start += length_return
380 #define READ_ULEB(var) \
385 (var) = _val = read_uleb128 (start, &length_return, end); \
387 error (_("Internal error: %s:%d: LEB value (%s) " \
388 "too large for containing variable\n"), \
389 __FILE__, __LINE__, dwarf_vmatoa ("u", _val)); \
390 start += length_return; \
394 #define READ_SLEB(var) \
397 dwarf_signed_vma _val; \
399 (var) = _val = read_sleb128 (start, &length_return, end); \
401 error (_("Internal error: %s:%d: LEB value (%s) " \
402 "too large for containing variable\n"), \
403 __FILE__, __LINE__, dwarf_vmatoa ("d", _val)); \
404 start += length_return; \
408 /* Read AMOUNT bytes from PTR and store them in VAL as an unsigned value.
409 Checks to make sure that the read will not reach or pass END
410 and that VAL is big enough to hold AMOUNT bytes. */
411 #define SAFE_BYTE_GET(VAL, PTR, AMOUNT, END) \
414 unsigned int amount = (AMOUNT); \
415 if (sizeof (VAL) < amount) \
417 error (ngettext ("internal error: attempt to read %d byte " \
418 "of data in to %d sized variable", \
419 "internal error: attempt to read %d bytes " \
420 "of data in to %d sized variable", \
422 amount, (int) sizeof (VAL)); \
423 amount = sizeof (VAL); \
425 if (((PTR) + amount) >= (END)) \
428 amount = (END) - (PTR); \
432 if (amount == 0 || amount > 8) \
435 VAL = byte_get ((PTR), amount); \
439 /* Like SAFE_BYTE_GET, but also increments PTR by AMOUNT. */
440 #define SAFE_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \
443 SAFE_BYTE_GET (VAL, PTR, AMOUNT, END); \
448 /* Like SAFE_BYTE_GET, but reads a signed value. */
449 #define SAFE_SIGNED_BYTE_GET(VAL, PTR, AMOUNT, END) \
452 unsigned int amount = (AMOUNT); \
453 if (((PTR) + amount) >= (END)) \
456 amount = (END) - (PTR); \
461 VAL = byte_get_signed ((PTR), amount); \
467 /* Like SAFE_SIGNED_BYTE_GET, but also increments PTR by AMOUNT. */
468 #define SAFE_SIGNED_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \
471 SAFE_SIGNED_BYTE_GET (VAL, PTR, AMOUNT, END); \
476 #define SAFE_BYTE_GET64(PTR, HIGH, LOW, END) \
479 if (((PTR) + 8) <= (END)) \
481 byte_get_64 ((PTR), (HIGH), (LOW)); \
485 * (LOW) = * (HIGH) = 0; \
490 typedef struct State_Machine_Registers
499 unsigned char op_index
;
500 unsigned char end_sequence
;
501 /* This variable hold the number of the last entry seen
502 in the File Table. */
503 unsigned int last_file_entry
;
506 static SMR state_machine_regs
;
509 reset_state_machine (int is_stmt
)
511 state_machine_regs
.address
= 0;
512 state_machine_regs
.view
= 0;
513 state_machine_regs
.op_index
= 0;
514 state_machine_regs
.file
= 1;
515 state_machine_regs
.line
= 1;
516 state_machine_regs
.column
= 0;
517 state_machine_regs
.is_stmt
= is_stmt
;
518 state_machine_regs
.basic_block
= 0;
519 state_machine_regs
.end_sequence
= 0;
520 state_machine_regs
.last_file_entry
= 0;
523 /* Handled an extend line op.
524 Returns the number of bytes read. */
527 process_extended_line_op (unsigned char * data
,
531 unsigned char op_code
;
532 unsigned int bytes_read
;
535 unsigned char *orig_data
= data
;
538 len
= read_uleb128 (data
, & bytes_read
, end
);
541 if (len
== 0 || data
== end
|| len
> (uintptr_t) (end
- data
))
543 warn (_("Badly formed extended line op encountered!\n"));
550 printf (_(" Extended opcode %d: "), op_code
);
554 case DW_LNE_end_sequence
:
555 printf (_("End of Sequence\n\n"));
556 reset_state_machine (is_stmt
);
559 case DW_LNE_set_address
:
560 /* PR 17512: file: 002-100480-0.004. */
561 if (len
- bytes_read
- 1 > 8)
563 warn (_("Length (%d) of DW_LNE_set_address op is too long\n"),
564 len
- bytes_read
- 1);
568 SAFE_BYTE_GET (adr
, data
, len
- bytes_read
- 1, end
);
569 printf (_("set Address to 0x%s\n"), dwarf_vmatoa ("x", adr
));
570 state_machine_regs
.address
= adr
;
571 state_machine_regs
.view
= 0;
572 state_machine_regs
.op_index
= 0;
575 case DW_LNE_define_file
:
576 printf (_("define new File Table entry\n"));
577 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
578 printf (" %d\t", ++state_machine_regs
.last_file_entry
);
584 l
= strnlen ((char *) data
, end
- data
);
586 printf ("%s\t", dwarf_vmatoa ("u", read_uleb128 (data
, & bytes_read
, end
)));
588 printf ("%s\t", dwarf_vmatoa ("u", read_uleb128 (data
, & bytes_read
, end
)));
590 printf ("%s\t", dwarf_vmatoa ("u", read_uleb128 (data
, & bytes_read
, end
)));
592 printf ("%.*s\n\n", (int) l
, name
);
595 if (((unsigned int) (data
- orig_data
) != len
) || data
== end
)
596 warn (_("DW_LNE_define_file: Bad opcode length\n"));
599 case DW_LNE_set_discriminator
:
600 printf (_("set Discriminator to %s\n"),
601 dwarf_vmatoa ("u", read_uleb128 (data
, & bytes_read
, end
)));
605 case DW_LNE_HP_negate_is_UV_update
:
606 printf ("DW_LNE_HP_negate_is_UV_update\n");
608 case DW_LNE_HP_push_context
:
609 printf ("DW_LNE_HP_push_context\n");
611 case DW_LNE_HP_pop_context
:
612 printf ("DW_LNE_HP_pop_context\n");
614 case DW_LNE_HP_set_file_line_column
:
615 printf ("DW_LNE_HP_set_file_line_column\n");
617 case DW_LNE_HP_set_routine_name
:
618 printf ("DW_LNE_HP_set_routine_name\n");
620 case DW_LNE_HP_set_sequence
:
621 printf ("DW_LNE_HP_set_sequence\n");
623 case DW_LNE_HP_negate_post_semantics
:
624 printf ("DW_LNE_HP_negate_post_semantics\n");
626 case DW_LNE_HP_negate_function_exit
:
627 printf ("DW_LNE_HP_negate_function_exit\n");
629 case DW_LNE_HP_negate_front_end_logical
:
630 printf ("DW_LNE_HP_negate_front_end_logical\n");
632 case DW_LNE_HP_define_proc
:
633 printf ("DW_LNE_HP_define_proc\n");
635 case DW_LNE_HP_source_file_correlation
:
637 unsigned char *edata
= data
+ len
- bytes_read
- 1;
639 printf ("DW_LNE_HP_source_file_correlation\n");
645 opc
= read_uleb128 (data
, & bytes_read
, edata
);
650 case DW_LNE_HP_SFC_formfeed
:
651 printf (" DW_LNE_HP_SFC_formfeed\n");
653 case DW_LNE_HP_SFC_set_listing_line
:
654 printf (" DW_LNE_HP_SFC_set_listing_line (%s)\n",
656 read_uleb128 (data
, & bytes_read
, edata
)));
659 case DW_LNE_HP_SFC_associate
:
660 printf (" DW_LNE_HP_SFC_associate ");
663 read_uleb128 (data
, & bytes_read
, edata
)));
667 read_uleb128 (data
, & bytes_read
, edata
)));
671 read_uleb128 (data
, & bytes_read
, edata
)));
675 printf (_(" UNKNOWN DW_LNE_HP_SFC opcode (%u)\n"), opc
);
685 unsigned int rlen
= len
- bytes_read
- 1;
687 if (op_code
>= DW_LNE_lo_user
688 /* The test against DW_LNW_hi_user is redundant due to
689 the limited range of the unsigned char data type used
691 /*&& op_code <= DW_LNE_hi_user*/)
692 printf (_("user defined: "));
694 printf (_("UNKNOWN: "));
695 printf (_("length %d ["), rlen
);
697 printf (" %02x", *data
++);
706 static const unsigned char *
707 fetch_indirect_string (dwarf_vma offset
)
709 struct dwarf_section
*section
= &debug_displays
[str
].section
;
710 const unsigned char * ret
;
712 if (section
->start
== NULL
)
713 return (const unsigned char *) _("<no .debug_str section>");
715 if (offset
>= section
->size
)
717 warn (_("DW_FORM_strp offset too big: %s\n"),
718 dwarf_vmatoa ("x", offset
));
719 return (const unsigned char *) _("<offset is too big>");
722 ret
= section
->start
+ offset
;
723 /* Unfortunately we cannot rely upon the .debug_str section ending with a
724 NUL byte. Since our caller is expecting to receive a well formed C
725 string we test for the lack of a terminating byte here. */
726 if (strnlen ((const char *) ret
, section
->size
- offset
)
727 == section
->size
- offset
)
728 ret
= (const unsigned char *)
729 _("<no NUL byte at end of .debug_str section>");
734 static const unsigned char *
735 fetch_indirect_line_string (dwarf_vma offset
)
737 struct dwarf_section
*section
= &debug_displays
[line_str
].section
;
738 const unsigned char * ret
;
740 if (section
->start
== NULL
)
741 return (const unsigned char *) _("<no .debug_line_str section>");
743 if (offset
>= section
->size
)
745 warn (_("DW_FORM_line_strp offset too big: %s\n"),
746 dwarf_vmatoa ("x", offset
));
747 return (const unsigned char *) _("<offset is too big>");
750 ret
= section
->start
+ offset
;
751 /* Unfortunately we cannot rely upon the .debug_line_str section ending
752 with a NUL byte. Since our caller is expecting to receive a well formed
753 C string we test for the lack of a terminating byte here. */
754 if (strnlen ((const char *) ret
, section
->size
- offset
)
755 == section
->size
- offset
)
756 ret
= (const unsigned char *)
757 _("<no NUL byte at end of .debug_line_str section>");
763 fetch_indexed_string (dwarf_vma idx
, struct cu_tu_set
*this_set
,
764 dwarf_vma offset_size
, bfd_boolean dwo
)
766 enum dwarf_section_display_enum str_sec_idx
= dwo
? str_dwo
: str
;
767 enum dwarf_section_display_enum idx_sec_idx
= dwo
? str_index_dwo
: str_index
;
768 struct dwarf_section
*index_section
= &debug_displays
[idx_sec_idx
].section
;
769 struct dwarf_section
*str_section
= &debug_displays
[str_sec_idx
].section
;
770 dwarf_vma index_offset
= idx
* offset_size
;
771 dwarf_vma str_offset
;
774 if (index_section
->start
== NULL
)
775 return (dwo
? _("<no .debug_str_offsets.dwo section>")
776 : _("<no .debug_str_offsets section>"));
778 if (this_set
!= NULL
)
779 index_offset
+= this_set
->section_offsets
[DW_SECT_STR_OFFSETS
];
780 if (index_offset
>= index_section
->size
)
782 warn (_("DW_FORM_GNU_str_index offset too big: %s\n"),
783 dwarf_vmatoa ("x", index_offset
));
784 return _("<index offset is too big>");
787 if (str_section
->start
== NULL
)
788 return (dwo
? _("<no .debug_str.dwo section>")
789 : _("<no .debug_str section>"));
791 str_offset
= byte_get (index_section
->start
+ index_offset
, offset_size
);
792 str_offset
-= str_section
->address
;
793 if (str_offset
>= str_section
->size
)
795 warn (_("DW_FORM_GNU_str_index indirect offset too big: %s\n"),
796 dwarf_vmatoa ("x", str_offset
));
797 return _("<indirect index offset is too big>");
800 ret
= (const char *) str_section
->start
+ str_offset
;
801 /* Unfortunately we cannot rely upon str_section ending with a NUL byte.
802 Since our caller is expecting to receive a well formed C string we test
803 for the lack of a terminating byte here. */
804 if (strnlen (ret
, str_section
->size
- str_offset
)
805 == str_section
->size
- str_offset
)
806 ret
= (const char *) _("<no NUL byte at end of section>");
812 fetch_indexed_value (dwarf_vma offset
, dwarf_vma bytes
)
814 struct dwarf_section
*section
= &debug_displays
[debug_addr
].section
;
816 if (section
->start
== NULL
)
817 return (_("<no .debug_addr section>"));
819 if (offset
+ bytes
> section
->size
)
821 warn (_("Offset into section %s too big: %s\n"),
822 section
->name
, dwarf_vmatoa ("x", offset
));
823 return "<offset too big>";
826 return dwarf_vmatoa ("x", byte_get (section
->start
+ offset
, bytes
));
830 /* FIXME: There are better and more efficient ways to handle
831 these structures. For now though, I just want something that
832 is simple to implement. */
833 typedef struct abbrev_attr
835 unsigned long attribute
;
837 bfd_signed_vma implicit_const
;
838 struct abbrev_attr
*next
;
842 typedef struct abbrev_entry
847 struct abbrev_attr
*first_attr
;
848 struct abbrev_attr
*last_attr
;
849 struct abbrev_entry
*next
;
853 static abbrev_entry
*first_abbrev
= NULL
;
854 static abbrev_entry
*last_abbrev
= NULL
;
861 for (abbrv
= first_abbrev
; abbrv
;)
863 abbrev_entry
*next_abbrev
= abbrv
->next
;
866 for (attr
= abbrv
->first_attr
; attr
;)
868 abbrev_attr
*next_attr
= attr
->next
;
878 last_abbrev
= first_abbrev
= NULL
;
882 add_abbrev (unsigned long number
, unsigned long tag
, int children
)
886 entry
= (abbrev_entry
*) malloc (sizeof (*entry
));
891 entry
->entry
= number
;
893 entry
->children
= children
;
894 entry
->first_attr
= NULL
;
895 entry
->last_attr
= NULL
;
898 if (first_abbrev
== NULL
)
899 first_abbrev
= entry
;
901 last_abbrev
->next
= entry
;
907 add_abbrev_attr (unsigned long attribute
, unsigned long form
,
908 bfd_signed_vma implicit_const
)
912 attr
= (abbrev_attr
*) malloc (sizeof (*attr
));
917 attr
->attribute
= attribute
;
919 attr
->implicit_const
= implicit_const
;
922 if (last_abbrev
->first_attr
== NULL
)
923 last_abbrev
->first_attr
= attr
;
925 last_abbrev
->last_attr
->next
= attr
;
927 last_abbrev
->last_attr
= attr
;
930 /* Processes the (partial) contents of a .debug_abbrev section.
931 Returns NULL if the end of the section was encountered.
932 Returns the address after the last byte read if the end of
933 an abbreviation set was found. */
935 static unsigned char *
936 process_abbrev_section (unsigned char *start
, unsigned char *end
)
938 if (first_abbrev
!= NULL
)
943 unsigned int bytes_read
;
946 unsigned long attribute
;
949 entry
= read_uleb128 (start
, & bytes_read
, end
);
952 /* A single zero is supposed to end the section according
953 to the standard. If there's more, then signal that to
960 tag
= read_uleb128 (start
, & bytes_read
, end
);
967 add_abbrev (entry
, tag
, children
);
972 /* Initialize it due to a false compiler warning. */
973 bfd_signed_vma implicit_const
= -1;
975 attribute
= read_uleb128 (start
, & bytes_read
, end
);
980 form
= read_uleb128 (start
, & bytes_read
, end
);
985 if (form
== DW_FORM_implicit_const
)
987 implicit_const
= read_sleb128 (start
, & bytes_read
, end
);
993 add_abbrev_attr (attribute
, form
, implicit_const
);
995 while (attribute
!= 0);
998 /* Report the missing single zero which ends the section. */
999 error (_(".debug_abbrev section not zero terminated\n"));
1005 get_TAG_name (unsigned long tag
)
1007 const char *name
= get_DW_TAG_name ((unsigned int) tag
);
1011 static char buffer
[100];
1013 if (tag
>= DW_TAG_lo_user
&& tag
<= DW_TAG_hi_user
)
1014 snprintf (buffer
, sizeof (buffer
), _("User TAG value: %#lx"), tag
);
1016 snprintf (buffer
, sizeof (buffer
), _("Unknown TAG value: %#lx"), tag
);
1024 get_FORM_name (unsigned long form
)
1029 return "DW_FORM value: 0";
1031 name
= get_DW_FORM_name (form
);
1034 static char buffer
[100];
1036 snprintf (buffer
, sizeof (buffer
), _("Unknown FORM value: %lx"), form
);
1044 get_IDX_name (unsigned long idx
)
1046 const char *name
= get_DW_IDX_name ((unsigned int) idx
);
1050 static char buffer
[100];
1052 snprintf (buffer
, sizeof (buffer
), _("Unknown IDX value: %lx"), idx
);
1059 static unsigned char *
1060 display_block (unsigned char *data
,
1062 const unsigned char * const end
, char delimiter
)
1066 printf (_("%c%s byte block: "), delimiter
, dwarf_vmatoa ("u", length
));
1068 return (unsigned char *) end
;
1070 maxlen
= (dwarf_vma
) (end
- data
);
1071 length
= length
> maxlen
? maxlen
: length
;
1074 printf ("%lx ", (unsigned long) byte_get (data
++, 1));
1080 decode_location_expression (unsigned char * data
,
1081 unsigned int pointer_size
,
1082 unsigned int offset_size
,
1085 dwarf_vma cu_offset
,
1086 struct dwarf_section
* section
)
1089 unsigned int bytes_read
;
1091 dwarf_signed_vma svalue
;
1092 unsigned char *end
= data
+ length
;
1093 int need_frame_base
= 0;
1102 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1103 printf ("DW_OP_addr: %s", dwarf_vmatoa ("x", uvalue
));
1106 printf ("DW_OP_deref");
1109 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1110 printf ("DW_OP_const1u: %lu", (unsigned long) uvalue
);
1113 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 1, end
);
1114 printf ("DW_OP_const1s: %ld", (long) svalue
);
1117 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
1118 printf ("DW_OP_const2u: %lu", (unsigned long) uvalue
);
1121 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1122 printf ("DW_OP_const2s: %ld", (long) svalue
);
1125 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1126 printf ("DW_OP_const4u: %lu", (unsigned long) uvalue
);
1129 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
1130 printf ("DW_OP_const4s: %ld", (long) svalue
);
1133 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1134 printf ("DW_OP_const8u: %lu ", (unsigned long) uvalue
);
1135 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1136 printf ("%lu", (unsigned long) uvalue
);
1139 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
1140 printf ("DW_OP_const8s: %ld ", (long) svalue
);
1141 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
1142 printf ("%ld", (long) svalue
);
1145 printf ("DW_OP_constu: %s",
1146 dwarf_vmatoa ("u", read_uleb128 (data
, &bytes_read
, end
)));
1150 printf ("DW_OP_consts: %s",
1151 dwarf_vmatoa ("d", read_sleb128 (data
, &bytes_read
, end
)));
1155 printf ("DW_OP_dup");
1158 printf ("DW_OP_drop");
1161 printf ("DW_OP_over");
1164 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1165 printf ("DW_OP_pick: %ld", (unsigned long) uvalue
);
1168 printf ("DW_OP_swap");
1171 printf ("DW_OP_rot");
1174 printf ("DW_OP_xderef");
1177 printf ("DW_OP_abs");
1180 printf ("DW_OP_and");
1183 printf ("DW_OP_div");
1186 printf ("DW_OP_minus");
1189 printf ("DW_OP_mod");
1192 printf ("DW_OP_mul");
1195 printf ("DW_OP_neg");
1198 printf ("DW_OP_not");
1201 printf ("DW_OP_or");
1204 printf ("DW_OP_plus");
1206 case DW_OP_plus_uconst
:
1207 printf ("DW_OP_plus_uconst: %s",
1208 dwarf_vmatoa ("u", read_uleb128 (data
, &bytes_read
, end
)));
1212 printf ("DW_OP_shl");
1215 printf ("DW_OP_shr");
1218 printf ("DW_OP_shra");
1221 printf ("DW_OP_xor");
1224 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1225 printf ("DW_OP_bra: %ld", (long) svalue
);
1228 printf ("DW_OP_eq");
1231 printf ("DW_OP_ge");
1234 printf ("DW_OP_gt");
1237 printf ("DW_OP_le");
1240 printf ("DW_OP_lt");
1243 printf ("DW_OP_ne");
1246 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1247 printf ("DW_OP_skip: %ld", (long) svalue
);
1282 printf ("DW_OP_lit%d", op
- DW_OP_lit0
);
1317 printf ("DW_OP_reg%d (%s)", op
- DW_OP_reg0
,
1318 regname (op
- DW_OP_reg0
, 1));
1353 printf ("DW_OP_breg%d (%s): %s",
1355 regname (op
- DW_OP_breg0
, 1),
1356 dwarf_vmatoa ("d", read_sleb128 (data
, &bytes_read
, end
)));
1361 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1363 printf ("DW_OP_regx: %s (%s)",
1364 dwarf_vmatoa ("u", uvalue
), regname (uvalue
, 1));
1367 need_frame_base
= 1;
1368 printf ("DW_OP_fbreg: %s",
1369 dwarf_vmatoa ("d", read_sleb128 (data
, &bytes_read
, end
)));
1373 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1375 printf ("DW_OP_bregx: %s (%s) %s",
1376 dwarf_vmatoa ("u", uvalue
), regname (uvalue
, 1),
1377 dwarf_vmatoa ("d", read_sleb128 (data
, &bytes_read
, end
)));
1381 printf ("DW_OP_piece: %s",
1382 dwarf_vmatoa ("u", read_uleb128 (data
, &bytes_read
, end
)));
1385 case DW_OP_deref_size
:
1386 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1387 printf ("DW_OP_deref_size: %ld", (long) uvalue
);
1389 case DW_OP_xderef_size
:
1390 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1391 printf ("DW_OP_xderef_size: %ld", (long) uvalue
);
1394 printf ("DW_OP_nop");
1397 /* DWARF 3 extensions. */
1398 case DW_OP_push_object_address
:
1399 printf ("DW_OP_push_object_address");
1402 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1403 this ought to be an 8-byte wide computation. */
1404 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1405 printf ("DW_OP_call2: <0x%s>",
1406 dwarf_vmatoa ("x", svalue
+ cu_offset
));
1409 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1410 this ought to be an 8-byte wide computation. */
1411 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
1412 printf ("DW_OP_call4: <0x%s>",
1413 dwarf_vmatoa ("x", svalue
+ cu_offset
));
1415 case DW_OP_call_ref
:
1416 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1417 this ought to be an 8-byte wide computation. */
1418 if (dwarf_version
== -1)
1420 printf (_("(DW_OP_call_ref in frame info)"));
1421 /* No way to tell where the next op is, so just bail. */
1422 return need_frame_base
;
1424 if (dwarf_version
== 2)
1426 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1430 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1432 printf ("DW_OP_call_ref: <0x%s>", dwarf_vmatoa ("x", uvalue
));
1434 case DW_OP_form_tls_address
:
1435 printf ("DW_OP_form_tls_address");
1437 case DW_OP_call_frame_cfa
:
1438 printf ("DW_OP_call_frame_cfa");
1440 case DW_OP_bit_piece
:
1441 printf ("DW_OP_bit_piece: ");
1442 printf (_("size: %s "),
1443 dwarf_vmatoa ("u", read_uleb128 (data
, &bytes_read
, end
)));
1445 printf (_("offset: %s "),
1446 dwarf_vmatoa ("u", read_uleb128 (data
, &bytes_read
, end
)));
1450 /* DWARF 4 extensions. */
1451 case DW_OP_stack_value
:
1452 printf ("DW_OP_stack_value");
1455 case DW_OP_implicit_value
:
1456 printf ("DW_OP_implicit_value");
1457 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1459 data
= display_block (data
, uvalue
, end
, ' ');
1462 /* GNU extensions. */
1463 case DW_OP_GNU_push_tls_address
:
1464 printf (_("DW_OP_GNU_push_tls_address or DW_OP_HP_unknown"));
1466 case DW_OP_GNU_uninit
:
1467 printf ("DW_OP_GNU_uninit");
1468 /* FIXME: Is there data associated with this OP ? */
1470 case DW_OP_GNU_encoded_addr
:
1477 addr
= get_encoded_value (&data
, encoding
, section
, end
);
1479 printf ("DW_OP_GNU_encoded_addr: fmt:%02x addr:", encoding
);
1480 print_dwarf_vma (addr
, pointer_size
);
1483 case DW_OP_implicit_pointer
:
1484 case DW_OP_GNU_implicit_pointer
:
1485 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1486 this ought to be an 8-byte wide computation. */
1487 if (dwarf_version
== -1)
1489 printf (_("(%s in frame info)"),
1490 (op
== DW_OP_implicit_pointer
1491 ? "DW_OP_implicit_pointer"
1492 : "DW_OP_GNU_implicit_pointer"));
1493 /* No way to tell where the next op is, so just bail. */
1494 return need_frame_base
;
1496 if (dwarf_version
== 2)
1498 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1502 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1504 printf ("%s: <0x%s> %s",
1505 (op
== DW_OP_implicit_pointer
1506 ? "DW_OP_implicit_pointer" : "DW_OP_GNU_implicit_pointer"),
1507 dwarf_vmatoa ("x", uvalue
),
1508 dwarf_vmatoa ("d", read_sleb128 (data
,
1509 &bytes_read
, end
)));
1512 case DW_OP_entry_value
:
1513 case DW_OP_GNU_entry_value
:
1514 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1516 /* PR 17531: file: 0cc9cd00. */
1517 if (uvalue
> (dwarf_vma
) (end
- data
))
1518 uvalue
= end
- data
;
1519 printf ("%s: (", (op
== DW_OP_entry_value
? "DW_OP_entry_value"
1520 : "DW_OP_GNU_entry_value"));
1521 if (decode_location_expression (data
, pointer_size
, offset_size
,
1522 dwarf_version
, uvalue
,
1523 cu_offset
, section
))
1524 need_frame_base
= 1;
1530 case DW_OP_const_type
:
1531 case DW_OP_GNU_const_type
:
1532 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1534 printf ("%s: <0x%s> ",
1535 (op
== DW_OP_const_type
? "DW_OP_const_type"
1536 : "DW_OP_GNU_const_type"),
1537 dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1538 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1539 data
= display_block (data
, uvalue
, end
, ' ');
1541 case DW_OP_regval_type
:
1542 case DW_OP_GNU_regval_type
:
1543 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1545 printf ("%s: %s (%s)",
1546 (op
== DW_OP_regval_type
? "DW_OP_regval_type"
1547 : "DW_OP_GNU_regval_type"),
1548 dwarf_vmatoa ("u", uvalue
), regname (uvalue
, 1));
1549 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1551 printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1553 case DW_OP_deref_type
:
1554 case DW_OP_GNU_deref_type
:
1555 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1557 (op
== DW_OP_deref_type
? "DW_OP_deref_type"
1558 : "DW_OP_GNU_deref_type"),
1560 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1562 printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1565 case DW_OP_GNU_convert
:
1566 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1568 printf ("%s <0x%s>",
1569 (op
== DW_OP_convert
? "DW_OP_convert" : "DW_OP_GNU_convert"),
1570 dwarf_vmatoa ("x", uvalue
? cu_offset
+ uvalue
: 0));
1572 case DW_OP_reinterpret
:
1573 case DW_OP_GNU_reinterpret
:
1574 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1576 printf ("%s <0x%s>",
1577 (op
== DW_OP_reinterpret
? "DW_OP_reinterpret"
1578 : "DW_OP_GNU_reinterpret"),
1579 dwarf_vmatoa ("x", uvalue
? cu_offset
+ uvalue
: 0));
1581 case DW_OP_GNU_parameter_ref
:
1582 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1583 printf ("DW_OP_GNU_parameter_ref: <0x%s>",
1584 dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1586 case DW_OP_GNU_addr_index
:
1587 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1589 printf ("DW_OP_GNU_addr_index <0x%s>", dwarf_vmatoa ("x", uvalue
));
1591 case DW_OP_GNU_const_index
:
1592 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1594 printf ("DW_OP_GNU_const_index <0x%s>", dwarf_vmatoa ("x", uvalue
));
1596 case DW_OP_GNU_variable_value
:
1597 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1598 this ought to be an 8-byte wide computation. */
1599 if (dwarf_version
== -1)
1601 printf (_("(DW_OP_GNU_variable_value in frame info)"));
1602 /* No way to tell where the next op is, so just bail. */
1603 return need_frame_base
;
1605 if (dwarf_version
== 2)
1607 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1611 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1613 printf ("DW_OP_GNU_variable_value: <0x%s>", dwarf_vmatoa ("x", uvalue
));
1616 /* HP extensions. */
1617 case DW_OP_HP_is_value
:
1618 printf ("DW_OP_HP_is_value");
1619 /* FIXME: Is there data associated with this OP ? */
1621 case DW_OP_HP_fltconst4
:
1622 printf ("DW_OP_HP_fltconst4");
1623 /* FIXME: Is there data associated with this OP ? */
1625 case DW_OP_HP_fltconst8
:
1626 printf ("DW_OP_HP_fltconst8");
1627 /* FIXME: Is there data associated with this OP ? */
1629 case DW_OP_HP_mod_range
:
1630 printf ("DW_OP_HP_mod_range");
1631 /* FIXME: Is there data associated with this OP ? */
1633 case DW_OP_HP_unmod_range
:
1634 printf ("DW_OP_HP_unmod_range");
1635 /* FIXME: Is there data associated with this OP ? */
1638 printf ("DW_OP_HP_tls");
1639 /* FIXME: Is there data associated with this OP ? */
1642 /* PGI (STMicroelectronics) extensions. */
1643 case DW_OP_PGI_omp_thread_num
:
1644 /* Pushes the thread number for the current thread as it would be
1645 returned by the standard OpenMP library function:
1646 omp_get_thread_num(). The "current thread" is the thread for
1647 which the expression is being evaluated. */
1648 printf ("DW_OP_PGI_omp_thread_num");
1652 if (op
>= DW_OP_lo_user
1653 && op
<= DW_OP_hi_user
)
1654 printf (_("(User defined location op 0x%x)"), op
);
1656 printf (_("(Unknown location op 0x%x)"), op
);
1657 /* No way to tell where the next op is, so just bail. */
1658 return need_frame_base
;
1661 /* Separate the ops. */
1666 return need_frame_base
;
1669 /* Find the CU or TU set corresponding to the given CU_OFFSET.
1670 This is used for DWARF package files. */
1672 static struct cu_tu_set
*
1673 find_cu_tu_set_v2 (dwarf_vma cu_offset
, int do_types
)
1675 struct cu_tu_set
*p
;
1677 unsigned int dw_sect
;
1683 dw_sect
= DW_SECT_TYPES
;
1689 dw_sect
= DW_SECT_INFO
;
1693 if (p
->section_offsets
[dw_sect
] == cu_offset
)
1701 /* Add INC to HIGH_BITS:LOW_BITS. */
1703 add64 (dwarf_vma
* high_bits
, dwarf_vma
* low_bits
, dwarf_vma inc
)
1705 dwarf_vma tmp
= * low_bits
;
1709 /* FIXME: There is probably a better way of handling this:
1711 We need to cope with dwarf_vma being a 32-bit or 64-bit
1712 type. Plus regardless of its size LOW_BITS is meant to
1713 only hold 32-bits, so if there is overflow or wrap around
1714 we must propagate into HIGH_BITS. */
1715 if (tmp
< * low_bits
)
1719 else if (sizeof (tmp
) > 8
1730 fetch_alt_indirect_string (dwarf_vma offset
)
1734 if (! do_follow_links
)
1737 if (first_separate_info
== NULL
)
1738 return _("<no links available>");
1740 for (i
= first_separate_info
; i
!= NULL
; i
= i
->next
)
1742 struct dwarf_section
* section
;
1745 if (! load_debug_section (separate_debug_str
, i
->handle
))
1748 section
= &debug_displays
[separate_debug_str
].section
;
1750 if (section
->start
== NULL
)
1753 if (offset
>= section
->size
)
1756 ret
= (const char *) (section
->start
+ offset
);
1757 /* Unfortunately we cannot rely upon the .debug_str section ending with a
1758 NUL byte. Since our caller is expecting to receive a well formed C
1759 string we test for the lack of a terminating byte here. */
1760 if (strnlen ((const char *) ret
, section
->size
- offset
)
1761 == section
->size
- offset
)
1762 return _("<no NUL byte at end of alt .debug_str section>");
1767 warn (_("DW_FORM_GNU_strp_alt offset (%s) too big or no string sections available\n"),
1768 dwarf_vmatoa ("x", offset
));
1769 return _("<offset is too big>");
1773 get_AT_name (unsigned long attribute
)
1778 return "DW_AT value: 0";
1780 /* One value is shared by the MIPS and HP extensions: */
1781 if (attribute
== DW_AT_MIPS_fde
)
1782 return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable";
1784 name
= get_DW_AT_name (attribute
);
1788 static char buffer
[100];
1790 snprintf (buffer
, sizeof (buffer
), _("Unknown AT value: %lx"),
1799 add_dwo_info (const char * field
, dwo_type type
)
1801 dwo_info
* dwinfo
= xmalloc (sizeof * dwinfo
);
1803 dwinfo
->type
= type
;
1804 dwinfo
->value
= field
;
1805 dwinfo
->next
= first_dwo_info
;
1806 first_dwo_info
= dwinfo
;
1810 add_dwo_name (const char * name
)
1812 add_dwo_info (name
, DWO_NAME
);
1816 add_dwo_dir (const char * dir
)
1818 add_dwo_info (dir
, DWO_DIR
);
1822 add_dwo_id (const char * id
)
1824 add_dwo_info (id
, DWO_ID
);
1828 free_dwo_info (void)
1833 for (dwinfo
= first_dwo_info
; dwinfo
!= NULL
; dwinfo
= next
)
1835 next
= dwinfo
->next
;
1838 first_dwo_info
= NULL
;
1841 /* Ensure that START + UVALUE is less than END.
1842 Return an adjusted UVALUE if necessary to ensure this relationship. */
1844 static inline dwarf_vma
1845 check_uvalue (const unsigned char * start
,
1847 const unsigned char * end
)
1849 dwarf_vma max_uvalue
= end
- start
;
1851 /* See PR 17512: file: 008-103549-0.001:0.1.
1852 and PR 24829 for examples of where these tests are triggered. */
1853 if (uvalue
> max_uvalue
)
1855 warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue
);
1856 uvalue
= max_uvalue
;
1862 static unsigned char *
1863 skip_attr_bytes (unsigned long form
,
1864 unsigned char * data
,
1865 unsigned const char * end
,
1866 dwarf_vma pointer_size
,
1867 dwarf_vma offset_size
,
1869 dwarf_vma
* value_return
)
1871 unsigned int bytes_read
;
1872 dwarf_vma uvalue
= 0;
1878 case DW_FORM_ref_addr
:
1879 if (dwarf_version
== 2)
1880 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1881 else if (dwarf_version
== 3 || dwarf_version
== 4)
1882 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1888 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1892 case DW_FORM_line_strp
:
1893 case DW_FORM_sec_offset
:
1894 case DW_FORM_GNU_ref_alt
:
1895 case DW_FORM_GNU_strp_alt
:
1896 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1899 case DW_FORM_flag_present
:
1906 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1911 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
1916 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1920 uvalue
= read_sleb128 (data
, & bytes_read
, end
);
1924 case DW_FORM_ref_udata
:
1926 case DW_FORM_GNU_str_index
:
1927 case DW_FORM_GNU_addr_index
:
1928 uvalue
= read_uleb128 (data
, & bytes_read
, end
);
1937 case DW_FORM_data16
:
1941 case DW_FORM_string
:
1942 data
+= strnlen ((char *) data
, end
- data
) + 1;
1946 case DW_FORM_exprloc
:
1947 uvalue
= read_uleb128 (data
, & bytes_read
, end
);
1948 data
+= bytes_read
+ uvalue
;
1951 case DW_FORM_block1
:
1952 SAFE_BYTE_GET (uvalue
, data
, 1, end
);
1956 case DW_FORM_block2
:
1957 SAFE_BYTE_GET (uvalue
, data
, 2, end
);
1961 case DW_FORM_block4
:
1962 SAFE_BYTE_GET (uvalue
, data
, 4, end
);
1966 case DW_FORM_ref_sig8
:
1970 case DW_FORM_indirect
:
1971 /* FIXME: Handle this form. */
1976 * value_return
= uvalue
;
1978 data
= (unsigned char *) end
;
1982 /* Return IS_SIGNED set to TRUE if the type at
1983 DATA can be determined to be a signed type. */
1986 get_type_signedness (unsigned char * start
,
1987 unsigned char * data
,
1988 unsigned const char * end
,
1989 dwarf_vma pointer_size
,
1990 dwarf_vma offset_size
,
1992 bfd_boolean
* is_signed
,
1993 bfd_boolean is_nested
)
1995 unsigned long abbrev_number
;
1996 unsigned int bytes_read
;
1997 abbrev_entry
* entry
;
2000 * is_signed
= FALSE
;
2002 abbrev_number
= read_uleb128 (data
, & bytes_read
, end
);
2005 for (entry
= first_abbrev
;
2006 entry
!= NULL
&& entry
->entry
!= abbrev_number
;
2007 entry
= entry
->next
)
2011 /* FIXME: Issue a warning ? */
2014 for (attr
= entry
->first_attr
;
2015 attr
!= NULL
&& attr
->attribute
;
2018 dwarf_vma uvalue
= 0;
2020 data
= skip_attr_bytes (attr
->form
, data
, end
, pointer_size
,
2021 offset_size
, dwarf_version
, & uvalue
);
2025 switch (attr
->attribute
)
2027 #if 0 /* FIXME: It would be nice to print the name of the type,
2028 but this would mean updating a lot of binutils tests. */
2030 if (attr
->form
== DW_FORM_strp
)
2031 printf ("%s", fetch_indirect_string (uvalue
));
2038 /* FIXME: Warn - or is this expected ?
2039 NB/ We need to avoid infinite recursion. */
2042 if (uvalue
>= (size_t) (end
- start
))
2044 get_type_signedness (start
, start
+ uvalue
, end
, pointer_size
,
2045 offset_size
, dwarf_version
, is_signed
, TRUE
);
2048 case DW_AT_encoding
:
2049 /* Determine signness. */
2052 case DW_ATE_address
:
2053 /* FIXME - some architectures have signed addresses. */
2054 case DW_ATE_boolean
:
2055 case DW_ATE_unsigned
:
2056 case DW_ATE_unsigned_char
:
2057 case DW_ATE_unsigned_fixed
:
2058 * is_signed
= FALSE
;
2062 case DW_ATE_complex_float
:
2065 case DW_ATE_signed_char
:
2066 case DW_ATE_imaginary_float
:
2067 case DW_ATE_decimal_float
:
2068 case DW_ATE_signed_fixed
:
2078 read_and_print_leb128 (unsigned char * data
,
2079 unsigned int * bytes_read
,
2080 unsigned const char * end
,
2081 bfd_boolean is_signed
)
2085 dwarf_signed_vma sval
= read_sleb128 (data
, bytes_read
, end
);
2086 printf ("%ld", (long) sval
);
2090 dwarf_vma uval
= read_uleb128 (data
, bytes_read
, end
);
2091 printf ("%lu", (unsigned long) uval
);
2096 display_discr_list (unsigned long form
,
2098 unsigned char * data
,
2099 unsigned const char * end
,
2104 printf ("[default]");
2111 case DW_FORM_block1
:
2112 case DW_FORM_block2
:
2113 case DW_FORM_block4
:
2114 /* Move data pointer back to the start of the byte array. */
2118 printf ("<corrupt>\n");
2119 warn (_("corrupt discr_list - not using a block form\n"));
2125 printf ("<corrupt>\n");
2126 warn (_("corrupt discr_list - block not long enough\n"));
2130 bfd_boolean is_signed
=
2131 (level
> 0 && level
<= MAX_CU_NESTING
)
2132 ? level_type_signed
[level
- 1] : FALSE
;
2137 unsigned char discriminant
;
2138 unsigned int bytes_read
;
2140 SAFE_BYTE_GET (discriminant
, data
, 1, end
);
2144 assert (uvalue
> 0);
2145 switch (discriminant
)
2149 read_and_print_leb128 (data
, & bytes_read
, end
, is_signed
);
2150 assert (bytes_read
<= uvalue
&& bytes_read
> 0);
2151 uvalue
-= bytes_read
;
2157 read_and_print_leb128 (data
, & bytes_read
, end
, is_signed
);
2158 assert (bytes_read
<= uvalue
&& bytes_read
> 0);
2159 uvalue
-= bytes_read
;
2163 read_and_print_leb128 (data
, & bytes_read
, end
, is_signed
);
2164 assert (bytes_read
<= uvalue
&& bytes_read
> 0);
2165 uvalue
-= bytes_read
;
2170 printf ("<corrupt>\n");
2171 warn (_("corrupt discr_list - unrecognised discriminant byte %#x\n"),
2181 printf (")(signed)");
2183 printf (")(unsigned)");
2186 static unsigned char *
2187 read_and_display_attr_value (unsigned long attribute
,
2189 dwarf_signed_vma implicit_const
,
2190 unsigned char * start
,
2191 unsigned char * data
,
2192 unsigned char * end
,
2193 dwarf_vma cu_offset
,
2194 dwarf_vma pointer_size
,
2195 dwarf_vma offset_size
,
2197 debug_info
* debug_info_p
,
2199 struct dwarf_section
* section
,
2200 struct cu_tu_set
* this_set
,
2204 dwarf_vma uvalue
= 0;
2205 unsigned char * block_start
= NULL
;
2206 unsigned char * orig_data
= data
;
2207 unsigned int bytes_read
;
2209 if (data
> end
|| (data
== end
&& form
!= DW_FORM_flag_present
))
2211 warn (_("Corrupt attribute\n"));
2220 case DW_FORM_ref_addr
:
2221 if (dwarf_version
== 2)
2222 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
2223 else if (dwarf_version
== 3 || dwarf_version
== 4)
2224 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
2226 error (_("Internal error: DWARF version is not 2, 3 or 4.\n"));
2231 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
2235 case DW_FORM_line_strp
:
2236 case DW_FORM_sec_offset
:
2237 case DW_FORM_GNU_ref_alt
:
2238 case DW_FORM_GNU_strp_alt
:
2239 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
2242 case DW_FORM_flag_present
:
2249 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
2254 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
2259 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
2263 uvalue
= read_sleb128 (data
, & bytes_read
, end
);
2267 case DW_FORM_GNU_str_index
:
2268 uvalue
= read_uleb128 (data
, & bytes_read
, end
);
2272 case DW_FORM_ref_udata
:
2274 uvalue
= read_uleb128 (data
, & bytes_read
, end
);
2278 case DW_FORM_indirect
:
2279 form
= read_uleb128 (data
, & bytes_read
, end
);
2282 printf ("%c%s", delimiter
, get_FORM_name (form
));
2283 if (form
== DW_FORM_implicit_const
)
2285 implicit_const
= read_sleb128 (data
, & bytes_read
, end
);
2288 return read_and_display_attr_value (attribute
, form
, implicit_const
,
2290 cu_offset
, pointer_size
,
2291 offset_size
, dwarf_version
,
2292 debug_info_p
, do_loc
,
2293 section
, this_set
, delimiter
, level
);
2294 case DW_FORM_GNU_addr_index
:
2295 uvalue
= read_uleb128 (data
, & bytes_read
, end
);
2302 case DW_FORM_ref_addr
:
2304 printf ("%c<0x%s>", delimiter
, dwarf_vmatoa ("x",uvalue
));
2307 case DW_FORM_GNU_ref_alt
:
2309 printf ("%c<alt 0x%s>", delimiter
, dwarf_vmatoa ("x",uvalue
));
2310 /* FIXME: Follow the reference... */
2316 case DW_FORM_ref_udata
:
2318 printf ("%c<0x%s>", delimiter
, dwarf_vmatoa ("x", uvalue
+ cu_offset
));
2323 case DW_FORM_sec_offset
:
2325 printf ("%c0x%s", delimiter
, dwarf_vmatoa ("x", uvalue
));
2328 case DW_FORM_flag_present
:
2335 printf ("%c%s", delimiter
, dwarf_vmatoa ("d", uvalue
));
2338 case DW_FORM_implicit_const
:
2340 printf ("%c%s", delimiter
, dwarf_vmatoa ("d", implicit_const
));
2347 dwarf_vma high_bits
;
2351 SAFE_BYTE_GET64 (data
, &high_bits
, &uvalue
, end
);
2353 if (form
== DW_FORM_ref8
)
2354 add64 (& high_bits
, & utmp
, cu_offset
);
2355 printf ("%c0x%s", delimiter
,
2356 dwarf_vmatoa64 (high_bits
, utmp
, buf
, sizeof (buf
)));
2359 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
2360 && num_debug_info_entries
== 0)
2362 if (sizeof (uvalue
) == 8)
2363 SAFE_BYTE_GET (uvalue
, data
, 8, end
);
2365 error (_("DW_FORM_data8 is unsupported when sizeof (dwarf_vma) != 8\n"));
2371 case DW_FORM_data16
:
2374 dwarf_vma left_high_bits
, left_low_bits
;
2375 dwarf_vma right_high_bits
, right_low_bits
;
2377 SAFE_BYTE_GET64 (data
, &left_high_bits
, &left_low_bits
, end
);
2378 SAFE_BYTE_GET64 (data
+ 8, &right_high_bits
, &right_low_bits
, end
);
2379 if (byte_get
== byte_get_little_endian
)
2382 left_high_bits
^= right_high_bits
;
2383 right_high_bits
^= left_high_bits
;
2384 left_high_bits
^= right_high_bits
;
2385 left_low_bits
^= right_low_bits
;
2386 right_low_bits
^= left_low_bits
;
2387 left_low_bits
^= right_low_bits
;
2389 printf (" 0x%08" DWARF_VMA_FMT
"x%08" DWARF_VMA_FMT
"x"
2390 "%08" DWARF_VMA_FMT
"x%08" DWARF_VMA_FMT
"x",
2391 left_high_bits
, left_low_bits
, right_high_bits
,
2397 case DW_FORM_string
:
2399 printf ("%c%.*s", delimiter
, (int) (end
- data
), data
);
2400 data
+= strnlen ((char *) data
, end
- data
) + 1;
2404 case DW_FORM_exprloc
:
2405 uvalue
= read_uleb128 (data
, & bytes_read
, end
);
2406 block_start
= data
+ bytes_read
;
2407 if (block_start
>= end
)
2409 warn (_("Block ends prematurely\n"));
2414 uvalue
= check_uvalue (block_start
, uvalue
, end
);
2417 data
= block_start
+ uvalue
;
2419 data
= display_block (block_start
, uvalue
, end
, delimiter
);
2422 case DW_FORM_block1
:
2423 SAFE_BYTE_GET (uvalue
, data
, 1, end
);
2424 block_start
= data
+ 1;
2425 if (block_start
>= end
)
2427 warn (_("Block ends prematurely\n"));
2432 uvalue
= check_uvalue (block_start
, uvalue
, end
);
2435 data
= block_start
+ uvalue
;
2437 data
= display_block (block_start
, uvalue
, end
, delimiter
);
2440 case DW_FORM_block2
:
2441 SAFE_BYTE_GET (uvalue
, data
, 2, end
);
2442 block_start
= data
+ 2;
2443 if (block_start
>= end
)
2445 warn (_("Block ends prematurely\n"));
2450 uvalue
= check_uvalue (block_start
, uvalue
, end
);
2453 data
= block_start
+ uvalue
;
2455 data
= display_block (block_start
, uvalue
, end
, delimiter
);
2458 case DW_FORM_block4
:
2459 SAFE_BYTE_GET (uvalue
, data
, 4, end
);
2460 block_start
= data
+ 4;
2461 /* PR 17512: file: 3371-3907-0.004. */
2462 if (block_start
>= end
)
2464 warn (_("Block ends prematurely\n"));
2469 uvalue
= check_uvalue (block_start
, uvalue
, end
);
2472 data
= block_start
+ uvalue
;
2474 data
= display_block (block_start
, uvalue
, end
, delimiter
);
2479 printf (_("%c(indirect string, offset: 0x%s): %s"), delimiter
,
2480 dwarf_vmatoa ("x", uvalue
),
2481 fetch_indirect_string (uvalue
));
2484 case DW_FORM_line_strp
:
2486 printf (_("%c(indirect line string, offset: 0x%s): %s"), delimiter
,
2487 dwarf_vmatoa ("x", uvalue
),
2488 fetch_indirect_line_string (uvalue
));
2491 case DW_FORM_GNU_str_index
:
2494 const char * suffix
= strrchr (section
->name
, '.');
2495 bfd_boolean dwo
= (suffix
&& strcmp (suffix
, ".dwo") == 0) ? TRUE
: FALSE
;
2497 printf (_("%c(indexed string: 0x%s): %s"), delimiter
,
2498 dwarf_vmatoa ("x", uvalue
),
2499 fetch_indexed_string (uvalue
, this_set
, offset_size
, dwo
));
2503 case DW_FORM_GNU_strp_alt
:
2506 printf (_("%c(alt indirect string, offset: 0x%s) %s"), delimiter
,
2507 dwarf_vmatoa ("x", uvalue
),
2508 fetch_alt_indirect_string (uvalue
));
2512 case DW_FORM_indirect
:
2513 /* Handled above. */
2516 case DW_FORM_ref_sig8
:
2519 dwarf_vma high_bits
;
2522 SAFE_BYTE_GET64 (data
, &high_bits
, &uvalue
, end
);
2523 printf ("%csignature: 0x%s", delimiter
,
2524 dwarf_vmatoa64 (high_bits
, uvalue
, buf
, sizeof (buf
)));
2529 case DW_FORM_GNU_addr_index
:
2531 printf (_("%c(addr_index: 0x%s): %s"), delimiter
,
2532 dwarf_vmatoa ("x", uvalue
),
2533 fetch_indexed_value (uvalue
* pointer_size
, pointer_size
));
2537 warn (_("Unrecognized form: %lu\n"), form
);
2541 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
2542 && num_debug_info_entries
== 0
2543 && debug_info_p
!= NULL
)
2547 case DW_AT_frame_base
:
2548 have_frame_base
= 1;
2550 case DW_AT_location
:
2551 case DW_AT_GNU_locviews
:
2552 case DW_AT_string_length
:
2553 case DW_AT_return_addr
:
2554 case DW_AT_data_member_location
:
2555 case DW_AT_vtable_elem_location
:
2557 case DW_AT_static_link
:
2558 case DW_AT_use_location
:
2559 case DW_AT_call_value
:
2560 case DW_AT_GNU_call_site_value
:
2561 case DW_AT_call_data_value
:
2562 case DW_AT_GNU_call_site_data_value
:
2563 case DW_AT_call_target
:
2564 case DW_AT_GNU_call_site_target
:
2565 case DW_AT_call_target_clobbered
:
2566 case DW_AT_GNU_call_site_target_clobbered
:
2567 if ((dwarf_version
< 4
2568 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
2569 || form
== DW_FORM_sec_offset
)
2571 /* Process location list. */
2572 unsigned int lmax
= debug_info_p
->max_loc_offsets
;
2573 unsigned int num
= debug_info_p
->num_loc_offsets
;
2575 if (lmax
== 0 || num
>= lmax
)
2578 debug_info_p
->loc_offsets
= (dwarf_vma
*)
2579 xcrealloc (debug_info_p
->loc_offsets
,
2580 lmax
, sizeof (*debug_info_p
->loc_offsets
));
2581 debug_info_p
->loc_views
= (dwarf_vma
*)
2582 xcrealloc (debug_info_p
->loc_views
,
2583 lmax
, sizeof (*debug_info_p
->loc_views
));
2584 debug_info_p
->have_frame_base
= (int *)
2585 xcrealloc (debug_info_p
->have_frame_base
,
2586 lmax
, sizeof (*debug_info_p
->have_frame_base
));
2587 debug_info_p
->max_loc_offsets
= lmax
;
2589 if (this_set
!= NULL
)
2590 uvalue
+= this_set
->section_offsets
[DW_SECT_LOC
];
2591 debug_info_p
->have_frame_base
[num
] = have_frame_base
;
2592 if (attribute
!= DW_AT_GNU_locviews
)
2594 /* Corrupt DWARF info can produce more offsets than views.
2595 See PR 23062 for an example. */
2596 if (debug_info_p
->num_loc_offsets
2597 > debug_info_p
->num_loc_views
)
2598 warn (_("More location offset attributes than DW_AT_GNU_locview attributes\n"));
2601 debug_info_p
->loc_offsets
[num
] = uvalue
;
2602 debug_info_p
->num_loc_offsets
++;
2607 assert (debug_info_p
->num_loc_views
<= num
);
2608 num
= debug_info_p
->num_loc_views
;
2609 if (num
> debug_info_p
->num_loc_offsets
)
2610 warn (_("More DW_AT_GNU_locview attributes than location offset attributes\n"));
2613 debug_info_p
->loc_views
[num
] = uvalue
;
2614 debug_info_p
->num_loc_views
++;
2621 if (need_base_address
)
2622 debug_info_p
->base_address
= uvalue
;
2625 case DW_AT_GNU_addr_base
:
2626 debug_info_p
->addr_base
= uvalue
;
2629 case DW_AT_GNU_ranges_base
:
2630 debug_info_p
->ranges_base
= uvalue
;
2634 if ((dwarf_version
< 4
2635 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
2636 || form
== DW_FORM_sec_offset
)
2638 /* Process range list. */
2639 unsigned int lmax
= debug_info_p
->max_range_lists
;
2640 unsigned int num
= debug_info_p
->num_range_lists
;
2642 if (lmax
== 0 || num
>= lmax
)
2645 debug_info_p
->range_lists
= (dwarf_vma
*)
2646 xcrealloc (debug_info_p
->range_lists
,
2647 lmax
, sizeof (*debug_info_p
->range_lists
));
2648 debug_info_p
->max_range_lists
= lmax
;
2650 debug_info_p
->range_lists
[num
] = uvalue
;
2651 debug_info_p
->num_range_lists
++;
2655 case DW_AT_GNU_dwo_name
:
2656 case DW_AT_dwo_name
:
2661 add_dwo_name ((const char *) fetch_indirect_string (uvalue
));
2663 case DW_FORM_GNU_str_index
:
2664 add_dwo_name (fetch_indexed_string (uvalue
, this_set
, offset_size
, FALSE
));
2666 case DW_FORM_string
:
2667 add_dwo_name ((const char *) orig_data
);
2670 warn (_("Unsupported form (%s) for attribute %s\n"),
2671 get_FORM_name (form
), get_AT_name (attribute
));
2676 case DW_AT_comp_dir
:
2677 /* FIXME: Also extract a build-id in a CU/TU. */
2682 add_dwo_dir ((const char *) fetch_indirect_string (uvalue
));
2684 case DW_FORM_line_strp
:
2685 add_dwo_dir ((const char *) fetch_indirect_line_string (uvalue
));
2687 case DW_FORM_GNU_str_index
:
2688 add_dwo_dir (fetch_indexed_string (uvalue
, this_set
, offset_size
, FALSE
));
2690 case DW_FORM_string
:
2691 add_dwo_dir ((const char *) orig_data
);
2694 warn (_("Unsupported form (%s) for attribute %s\n"),
2695 get_FORM_name (form
), get_AT_name (attribute
));
2700 case DW_AT_GNU_dwo_id
:
2705 /* FIXME: Record the length of the ID as well ? */
2706 add_dwo_id ((const char *) (data
- 8));
2709 warn (_("Unsupported form (%s) for attribute %s\n"),
2710 get_FORM_name (form
), get_AT_name (attribute
));
2720 if (do_loc
|| attribute
== 0)
2723 /* For some attributes we can display further information. */
2727 if (level
>= 0 && level
< MAX_CU_NESTING
2728 && uvalue
< (size_t) (end
- start
))
2730 bfd_boolean is_signed
= FALSE
;
2732 get_type_signedness (start
, start
+ uvalue
, end
, pointer_size
,
2733 offset_size
, dwarf_version
, & is_signed
, FALSE
);
2734 level_type_signed
[level
] = is_signed
;
2742 case DW_INL_not_inlined
:
2743 printf (_("(not inlined)"));
2745 case DW_INL_inlined
:
2746 printf (_("(inlined)"));
2748 case DW_INL_declared_not_inlined
:
2749 printf (_("(declared as inline but ignored)"));
2751 case DW_INL_declared_inlined
:
2752 printf (_("(declared as inline and inlined)"));
2755 printf (_(" (Unknown inline attribute value: %s)"),
2756 dwarf_vmatoa ("x", uvalue
));
2761 case DW_AT_language
:
2765 /* Ordered by the numeric value of these constants. */
2766 case DW_LANG_C89
: printf ("(ANSI C)"); break;
2767 case DW_LANG_C
: printf ("(non-ANSI C)"); break;
2768 case DW_LANG_Ada83
: printf ("(Ada)"); break;
2769 case DW_LANG_C_plus_plus
: printf ("(C++)"); break;
2770 case DW_LANG_Cobol74
: printf ("(Cobol 74)"); break;
2771 case DW_LANG_Cobol85
: printf ("(Cobol 85)"); break;
2772 case DW_LANG_Fortran77
: printf ("(FORTRAN 77)"); break;
2773 case DW_LANG_Fortran90
: printf ("(Fortran 90)"); break;
2774 case DW_LANG_Pascal83
: printf ("(ANSI Pascal)"); break;
2775 case DW_LANG_Modula2
: printf ("(Modula 2)"); break;
2776 /* DWARF 2.1 values. */
2777 case DW_LANG_Java
: printf ("(Java)"); break;
2778 case DW_LANG_C99
: printf ("(ANSI C99)"); break;
2779 case DW_LANG_Ada95
: printf ("(ADA 95)"); break;
2780 case DW_LANG_Fortran95
: printf ("(Fortran 95)"); break;
2781 /* DWARF 3 values. */
2782 case DW_LANG_PLI
: printf ("(PLI)"); break;
2783 case DW_LANG_ObjC
: printf ("(Objective C)"); break;
2784 case DW_LANG_ObjC_plus_plus
: printf ("(Objective C++)"); break;
2785 case DW_LANG_UPC
: printf ("(Unified Parallel C)"); break;
2786 case DW_LANG_D
: printf ("(D)"); break;
2787 /* DWARF 4 values. */
2788 case DW_LANG_Python
: printf ("(Python)"); break;
2789 /* DWARF 5 values. */
2790 case DW_LANG_OpenCL
: printf ("(OpenCL)"); break;
2791 case DW_LANG_Go
: printf ("(Go)"); break;
2792 case DW_LANG_Modula3
: printf ("(Modula 3)"); break;
2793 case DW_LANG_Haskell
: printf ("(Haskell)"); break;
2794 case DW_LANG_C_plus_plus_03
: printf ("(C++03)"); break;
2795 case DW_LANG_C_plus_plus_11
: printf ("(C++11)"); break;
2796 case DW_LANG_OCaml
: printf ("(OCaml)"); break;
2797 case DW_LANG_Rust
: printf ("(Rust)"); break;
2798 case DW_LANG_C11
: printf ("(C11)"); break;
2799 case DW_LANG_Swift
: printf ("(Swift)"); break;
2800 case DW_LANG_Julia
: printf ("(Julia)"); break;
2801 case DW_LANG_Dylan
: printf ("(Dylan)"); break;
2802 case DW_LANG_C_plus_plus_14
: printf ("(C++14)"); break;
2803 case DW_LANG_Fortran03
: printf ("(Fortran 03)"); break;
2804 case DW_LANG_Fortran08
: printf ("(Fortran 08)"); break;
2805 case DW_LANG_RenderScript
: printf ("(RenderScript)"); break;
2806 /* MIPS extension. */
2807 case DW_LANG_Mips_Assembler
: printf ("(MIPS assembler)"); break;
2808 /* UPC extension. */
2809 case DW_LANG_Upc
: printf ("(Unified Parallel C)"); break;
2811 if (uvalue
>= DW_LANG_lo_user
&& uvalue
<= DW_LANG_hi_user
)
2812 printf (_("(implementation defined: %s)"),
2813 dwarf_vmatoa ("x", uvalue
));
2815 printf (_("(Unknown: %s)"), dwarf_vmatoa ("x", uvalue
));
2820 case DW_AT_encoding
:
2824 case DW_ATE_void
: printf ("(void)"); break;
2825 case DW_ATE_address
: printf ("(machine address)"); break;
2826 case DW_ATE_boolean
: printf ("(boolean)"); break;
2827 case DW_ATE_complex_float
: printf ("(complex float)"); break;
2828 case DW_ATE_float
: printf ("(float)"); break;
2829 case DW_ATE_signed
: printf ("(signed)"); break;
2830 case DW_ATE_signed_char
: printf ("(signed char)"); break;
2831 case DW_ATE_unsigned
: printf ("(unsigned)"); break;
2832 case DW_ATE_unsigned_char
: printf ("(unsigned char)"); break;
2833 /* DWARF 2.1 values: */
2834 case DW_ATE_imaginary_float
: printf ("(imaginary float)"); break;
2835 case DW_ATE_decimal_float
: printf ("(decimal float)"); break;
2836 /* DWARF 3 values: */
2837 case DW_ATE_packed_decimal
: printf ("(packed_decimal)"); break;
2838 case DW_ATE_numeric_string
: printf ("(numeric_string)"); break;
2839 case DW_ATE_edited
: printf ("(edited)"); break;
2840 case DW_ATE_signed_fixed
: printf ("(signed_fixed)"); break;
2841 case DW_ATE_unsigned_fixed
: printf ("(unsigned_fixed)"); break;
2842 /* DWARF 4 values: */
2843 case DW_ATE_UTF
: printf ("(unicode string)"); break;
2844 /* DWARF 5 values: */
2845 case DW_ATE_UCS
: printf ("(UCS)"); break;
2846 case DW_ATE_ASCII
: printf ("(ASCII)"); break;
2848 /* HP extensions: */
2849 case DW_ATE_HP_float80
: printf ("(HP_float80)"); break;
2850 case DW_ATE_HP_complex_float80
: printf ("(HP_complex_float80)"); break;
2851 case DW_ATE_HP_float128
: printf ("(HP_float128)"); break;
2852 case DW_ATE_HP_complex_float128
:printf ("(HP_complex_float128)"); break;
2853 case DW_ATE_HP_floathpintel
: printf ("(HP_floathpintel)"); break;
2854 case DW_ATE_HP_imaginary_float80
: printf ("(HP_imaginary_float80)"); break;
2855 case DW_ATE_HP_imaginary_float128
: printf ("(HP_imaginary_float128)"); break;
2858 if (uvalue
>= DW_ATE_lo_user
2859 && uvalue
<= DW_ATE_hi_user
)
2860 printf (_("(user defined type)"));
2862 printf (_("(unknown type)"));
2867 case DW_AT_accessibility
:
2871 case DW_ACCESS_public
: printf ("(public)"); break;
2872 case DW_ACCESS_protected
: printf ("(protected)"); break;
2873 case DW_ACCESS_private
: printf ("(private)"); break;
2875 printf (_("(unknown accessibility)"));
2880 case DW_AT_visibility
:
2884 case DW_VIS_local
: printf ("(local)"); break;
2885 case DW_VIS_exported
: printf ("(exported)"); break;
2886 case DW_VIS_qualified
: printf ("(qualified)"); break;
2887 default: printf (_("(unknown visibility)")); break;
2891 case DW_AT_endianity
:
2895 case DW_END_default
: printf ("(default)"); break;
2896 case DW_END_big
: printf ("(big)"); break;
2897 case DW_END_little
: printf ("(little)"); break;
2899 if (uvalue
>= DW_END_lo_user
&& uvalue
<= DW_END_hi_user
)
2900 printf (_("(user specified)"));
2902 printf (_("(unknown endianity)"));
2907 case DW_AT_virtuality
:
2911 case DW_VIRTUALITY_none
: printf ("(none)"); break;
2912 case DW_VIRTUALITY_virtual
: printf ("(virtual)"); break;
2913 case DW_VIRTUALITY_pure_virtual
:printf ("(pure_virtual)"); break;
2914 default: printf (_("(unknown virtuality)")); break;
2918 case DW_AT_identifier_case
:
2922 case DW_ID_case_sensitive
: printf ("(case_sensitive)"); break;
2923 case DW_ID_up_case
: printf ("(up_case)"); break;
2924 case DW_ID_down_case
: printf ("(down_case)"); break;
2925 case DW_ID_case_insensitive
: printf ("(case_insensitive)"); break;
2926 default: printf (_("(unknown case)")); break;
2930 case DW_AT_calling_convention
:
2934 case DW_CC_normal
: printf ("(normal)"); break;
2935 case DW_CC_program
: printf ("(program)"); break;
2936 case DW_CC_nocall
: printf ("(nocall)"); break;
2937 case DW_CC_pass_by_reference
: printf ("(pass by ref)"); break;
2938 case DW_CC_pass_by_value
: printf ("(pass by value)"); break;
2939 case DW_CC_GNU_renesas_sh
: printf ("(Rensas SH)"); break;
2940 case DW_CC_GNU_borland_fastcall_i386
: printf ("(Borland fastcall i386)"); break;
2942 if (uvalue
>= DW_CC_lo_user
2943 && uvalue
<= DW_CC_hi_user
)
2944 printf (_("(user defined)"));
2946 printf (_("(unknown convention)"));
2950 case DW_AT_ordering
:
2955 case -1: printf (_("(undefined)")); break;
2956 case 0: printf ("(row major)"); break;
2957 case 1: printf ("(column major)"); break;
2961 case DW_AT_decimal_sign
:
2965 case DW_DS_unsigned
: printf (_("(unsigned)")); break;
2966 case DW_DS_leading_overpunch
: printf (_("(leading overpunch)")); break;
2967 case DW_DS_trailing_overpunch
: printf (_("(trailing overpunch)")); break;
2968 case DW_DS_leading_separate
: printf (_("(leading separate)")); break;
2969 case DW_DS_trailing_separate
: printf (_("(trailing separate)")); break;
2970 default: printf (_("(unrecognised)")); break;
2974 case DW_AT_defaulted
:
2978 case DW_DEFAULTED_no
: printf (_("(no)")); break;
2979 case DW_DEFAULTED_in_class
: printf (_("(in class)")); break;
2980 case DW_DEFAULTED_out_of_class
: printf (_("(out of class)")); break;
2981 default: printf (_("(unrecognised)")); break;
2985 case DW_AT_discr_list
:
2987 display_discr_list (form
, uvalue
, data
, end
, level
);
2990 case DW_AT_frame_base
:
2991 have_frame_base
= 1;
2993 case DW_AT_location
:
2994 case DW_AT_string_length
:
2995 case DW_AT_return_addr
:
2996 case DW_AT_data_member_location
:
2997 case DW_AT_vtable_elem_location
:
2999 case DW_AT_static_link
:
3000 case DW_AT_use_location
:
3001 case DW_AT_call_value
:
3002 case DW_AT_GNU_call_site_value
:
3003 case DW_AT_call_data_value
:
3004 case DW_AT_GNU_call_site_data_value
:
3005 case DW_AT_call_target
:
3006 case DW_AT_GNU_call_site_target
:
3007 case DW_AT_call_target_clobbered
:
3008 case DW_AT_GNU_call_site_target_clobbered
:
3009 if ((dwarf_version
< 4
3010 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
3011 || form
== DW_FORM_sec_offset
)
3012 printf (_(" (location list)"));
3014 case DW_AT_allocated
:
3015 case DW_AT_associated
:
3016 case DW_AT_data_location
:
3018 case DW_AT_upper_bound
:
3019 case DW_AT_lower_bound
:
3022 int need_frame_base
;
3025 need_frame_base
= decode_location_expression (block_start
,
3030 cu_offset
, section
);
3032 if (need_frame_base
&& !have_frame_base
)
3033 printf (_(" [without DW_AT_frame_base]"));
3037 case DW_AT_data_bit_offset
:
3038 case DW_AT_byte_size
:
3039 case DW_AT_bit_size
:
3040 case DW_AT_string_length_byte_size
:
3041 case DW_AT_string_length_bit_size
:
3042 case DW_AT_bit_stride
:
3043 if (form
== DW_FORM_exprloc
)
3046 (void) decode_location_expression (block_start
, pointer_size
,
3047 offset_size
, dwarf_version
,
3048 uvalue
, cu_offset
, section
);
3055 if (form
== DW_FORM_ref_sig8
3056 || form
== DW_FORM_GNU_ref_alt
)
3059 if (form
== DW_FORM_ref1
3060 || form
== DW_FORM_ref2
3061 || form
== DW_FORM_ref4
3062 || form
== DW_FORM_ref_udata
)
3063 uvalue
+= cu_offset
;
3065 if (uvalue
>= section
->size
)
3066 warn (_("Offset %s used as value for DW_AT_import attribute of DIE at offset 0x%lx is too big.\n"),
3067 dwarf_vmatoa ("x", uvalue
),
3068 (unsigned long) (orig_data
- section
->start
));
3071 unsigned long abbrev_number
;
3072 abbrev_entry
* entry
;
3074 abbrev_number
= read_uleb128 (section
->start
+ uvalue
, NULL
, end
);
3076 printf (_("\t[Abbrev Number: %ld"), abbrev_number
);
3077 /* Don't look up abbrev for DW_FORM_ref_addr, as it very often will
3078 use different abbrev table, and we don't track .debug_info chunks
3080 if (form
!= DW_FORM_ref_addr
)
3082 for (entry
= first_abbrev
; entry
!= NULL
; entry
= entry
->next
)
3083 if (entry
->entry
== abbrev_number
)
3086 printf (" (%s)", get_TAG_name (entry
->tag
));
3100 static unsigned char *
3101 read_and_display_attr (unsigned long attribute
,
3103 dwarf_signed_vma implicit_const
,
3104 unsigned char * start
,
3105 unsigned char * data
,
3106 unsigned char * end
,
3107 dwarf_vma cu_offset
,
3108 dwarf_vma pointer_size
,
3109 dwarf_vma offset_size
,
3111 debug_info
* debug_info_p
,
3113 struct dwarf_section
* section
,
3114 struct cu_tu_set
* this_set
,
3118 printf (" %-18s:", get_AT_name (attribute
));
3119 data
= read_and_display_attr_value (attribute
, form
, implicit_const
,
3121 cu_offset
, pointer_size
, offset_size
,
3122 dwarf_version
, debug_info_p
,
3123 do_loc
, section
, this_set
, ' ', level
);
3129 /* Like load_debug_section, but if the ordinary call fails, and we are
3130 following debug links, then attempt to load the requested section
3131 from one of the separate debug info files. */
3134 load_debug_section_with_follow (enum dwarf_section_display_enum sec_enum
,
3137 if (load_debug_section (sec_enum
, handle
))
3139 if (debug_displays
[sec_enum
].section
.filename
== NULL
)
3141 /* See if we can associate a filename with this section. */
3144 for (i
= first_separate_info
; i
!= NULL
; i
= i
->next
)
3145 if (i
->handle
== handle
)
3147 debug_displays
[sec_enum
].section
.filename
= i
->filename
;
3155 if (do_follow_links
)
3159 for (i
= first_separate_info
; i
!= NULL
; i
= i
->next
)
3161 if (load_debug_section (sec_enum
, i
->handle
))
3163 debug_displays
[sec_enum
].section
.filename
= i
->filename
;
3165 /* FIXME: We should check to see if any of the remaining debug info
3166 files also contain this section, and, umm, do something about it. */
3176 introduce (struct dwarf_section
* section
, bfd_boolean raw
)
3180 if (do_follow_links
&& section
->filename
)
3181 printf (_("Raw dump of debug contents of section %s (loaded from %s):\n\n"),
3182 section
->name
, section
->filename
);
3184 printf (_("Raw dump of debug contents of section %s:\n\n"), section
->name
);
3188 if (do_follow_links
&& section
->filename
)
3189 printf (_("Contents of the %s section (loaded from %s):\n\n"),
3190 section
->name
, section
->filename
);
3192 printf (_("Contents of the %s section:\n\n"), section
->name
);
3196 /* Process the contents of a .debug_info section.
3197 If do_loc is TRUE then we are scanning for location lists and dwo tags
3198 and we do not want to display anything to the user.
3199 If do_types is TRUE, we are processing a .debug_types section instead of
3200 a .debug_info section.
3201 The information displayed is restricted by the values in DWARF_START_DIE
3202 and DWARF_CUTOFF_LEVEL.
3203 Returns TRUE upon success. Otherwise an error or warning message is
3204 printed and FALSE is returned. */
3207 process_debug_info (struct dwarf_section
* section
,
3209 enum dwarf_section_display_enum abbrev_sec
,
3211 bfd_boolean do_types
)
3213 unsigned char *start
= section
->start
;
3214 unsigned char *end
= start
+ section
->size
;
3215 unsigned char *section_begin
;
3217 unsigned int num_units
= 0;
3219 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
3220 && num_debug_info_entries
== 0
3225 /* First scan the section to get the number of comp units. */
3226 for (section_begin
= start
, num_units
= 0; section_begin
< end
;
3229 /* Read the first 4 bytes. For a 32-bit DWARF section, this
3230 will be the length. For a 64-bit DWARF section, it'll be
3231 the escape code 0xffffffff followed by an 8 byte length. */
3232 SAFE_BYTE_GET (length
, section_begin
, 4, end
);
3234 if (length
== 0xffffffff)
3236 SAFE_BYTE_GET (length
, section_begin
+ 4, 8, end
);
3237 section_begin
+= length
+ 12;
3239 else if (length
>= 0xfffffff0 && length
< 0xffffffff)
3241 warn (_("Reserved length value (0x%s) found in section %s\n"),
3242 dwarf_vmatoa ("x", length
), section
->name
);
3246 section_begin
+= length
+ 4;
3248 /* Negative values are illegal, they may even cause infinite
3249 looping. This can happen if we can't accurately apply
3250 relocations to an object file, or if the file is corrupt. */
3251 if ((signed long) length
<= 0 || section_begin
< start
)
3253 warn (_("Corrupt unit length (0x%s) found in section %s\n"),
3254 dwarf_vmatoa ("x", length
), section
->name
);
3261 error (_("No comp units in %s section ?\n"), section
->name
);
3265 /* Then allocate an array to hold the information. */
3266 debug_information
= (debug_info
*) cmalloc (num_units
,
3267 sizeof (* debug_information
));
3268 if (debug_information
== NULL
)
3270 error (_("Not enough memory for a debug info array of %u entries\n"),
3272 alloc_num_debug_info_entries
= num_debug_info_entries
= 0;
3276 /* PR 17531: file: 92ca3797.
3277 We cannot rely upon the debug_information array being initialised
3278 before it is used. A corrupt file could easily contain references
3279 to a unit for which information has not been made available. So
3280 we ensure that the array is zeroed here. */
3281 memset (debug_information
, 0, num_units
* sizeof (*debug_information
));
3283 alloc_num_debug_info_entries
= num_units
;
3288 load_debug_section_with_follow (str
, file
);
3289 load_debug_section_with_follow (line_str
, file
);
3290 load_debug_section_with_follow (str_dwo
, file
);
3291 load_debug_section_with_follow (str_index
, file
);
3292 load_debug_section_with_follow (str_index_dwo
, file
);
3293 load_debug_section_with_follow (debug_addr
, file
);
3296 load_debug_section_with_follow (abbrev_sec
, file
);
3297 if (debug_displays
[abbrev_sec
].section
.start
== NULL
)
3299 warn (_("Unable to locate %s section!\n"),
3300 debug_displays
[abbrev_sec
].section
.uncompressed_name
);
3304 if (!do_loc
&& dwarf_start_die
== 0)
3305 introduce (section
, FALSE
);
3307 for (section_begin
= start
, unit
= 0; start
< end
; unit
++)
3309 DWARF2_Internal_CompUnit compunit
;
3310 unsigned char *hdrptr
;
3311 unsigned char *tags
;
3312 int level
, last_level
, saved_level
;
3313 dwarf_vma cu_offset
;
3314 unsigned long sec_off
;
3315 unsigned int offset_size
;
3316 unsigned int initial_length_size
;
3317 dwarf_vma signature_high
= 0;
3318 dwarf_vma signature_low
= 0;
3319 dwarf_vma type_offset
= 0;
3320 struct cu_tu_set
*this_set
;
3321 dwarf_vma abbrev_base
;
3326 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 4, end
);
3328 if (compunit
.cu_length
== 0xffffffff)
3330 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 8, end
);
3332 initial_length_size
= 12;
3337 initial_length_size
= 4;
3340 SAFE_BYTE_GET_AND_INC (compunit
.cu_version
, hdrptr
, 2, end
);
3342 cu_offset
= start
- section_begin
;
3344 this_set
= find_cu_tu_set_v2 (cu_offset
, do_types
);
3346 if (compunit
.cu_version
< 5)
3348 compunit
.cu_unit_type
= DW_UT_compile
;
3349 /* Initialize it due to a false compiler warning. */
3350 compunit
.cu_pointer_size
= -1;
3354 SAFE_BYTE_GET_AND_INC (compunit
.cu_unit_type
, hdrptr
, 1, end
);
3355 do_types
= (compunit
.cu_unit_type
== DW_UT_type
);
3357 SAFE_BYTE_GET_AND_INC (compunit
.cu_pointer_size
, hdrptr
, 1, end
);
3360 SAFE_BYTE_GET_AND_INC (compunit
.cu_abbrev_offset
, hdrptr
, offset_size
, end
);
3362 if (this_set
== NULL
)
3365 abbrev_size
= debug_displays
[abbrev_sec
].section
.size
;
3369 abbrev_base
= this_set
->section_offsets
[DW_SECT_ABBREV
];
3370 abbrev_size
= this_set
->section_sizes
[DW_SECT_ABBREV
];
3373 if (compunit
.cu_version
< 5)
3374 SAFE_BYTE_GET_AND_INC (compunit
.cu_pointer_size
, hdrptr
, 1, end
);
3376 /* PR 17512: file: 001-108546-0.001:0.1. */
3377 if (compunit
.cu_pointer_size
< 2 || compunit
.cu_pointer_size
> 8)
3379 warn (_("Invalid pointer size (%d) in compunit header, using %d instead\n"),
3380 compunit
.cu_pointer_size
, offset_size
);
3381 compunit
.cu_pointer_size
= offset_size
;
3386 SAFE_BYTE_GET64 (hdrptr
, &signature_high
, &signature_low
, end
);
3388 SAFE_BYTE_GET_AND_INC (type_offset
, hdrptr
, offset_size
, end
);
3391 if (dwarf_start_die
> (cu_offset
+ compunit
.cu_length
3392 + initial_length_size
))
3394 start
= section_begin
+ cu_offset
+ compunit
.cu_length
3395 + initial_length_size
;
3399 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
3400 && num_debug_info_entries
== 0
3403 debug_information
[unit
].cu_offset
= cu_offset
;
3404 debug_information
[unit
].pointer_size
3405 = compunit
.cu_pointer_size
;
3406 debug_information
[unit
].offset_size
= offset_size
;
3407 debug_information
[unit
].dwarf_version
= compunit
.cu_version
;
3408 debug_information
[unit
].base_address
= 0;
3409 debug_information
[unit
].addr_base
= DEBUG_INFO_UNAVAILABLE
;
3410 debug_information
[unit
].ranges_base
= DEBUG_INFO_UNAVAILABLE
;
3411 debug_information
[unit
].loc_offsets
= NULL
;
3412 debug_information
[unit
].have_frame_base
= NULL
;
3413 debug_information
[unit
].max_loc_offsets
= 0;
3414 debug_information
[unit
].num_loc_offsets
= 0;
3415 debug_information
[unit
].range_lists
= NULL
;
3416 debug_information
[unit
].max_range_lists
= 0;
3417 debug_information
[unit
].num_range_lists
= 0;
3420 if (!do_loc
&& dwarf_start_die
== 0)
3422 printf (_(" Compilation Unit @ offset 0x%s:\n"),
3423 dwarf_vmatoa ("x", cu_offset
));
3424 printf (_(" Length: 0x%s (%s)\n"),
3425 dwarf_vmatoa ("x", compunit
.cu_length
),
3426 offset_size
== 8 ? "64-bit" : "32-bit");
3427 printf (_(" Version: %d\n"), compunit
.cu_version
);
3428 printf (_(" Abbrev Offset: 0x%s\n"),
3429 dwarf_vmatoa ("x", compunit
.cu_abbrev_offset
));
3430 printf (_(" Pointer Size: %d\n"), compunit
.cu_pointer_size
);
3435 printf (_(" Signature: 0x%s\n"),
3436 dwarf_vmatoa64 (signature_high
, signature_low
,
3437 buf
, sizeof (buf
)));
3438 printf (_(" Type Offset: 0x%s\n"),
3439 dwarf_vmatoa ("x", type_offset
));
3441 if (this_set
!= NULL
)
3443 dwarf_vma
*offsets
= this_set
->section_offsets
;
3444 size_t *sizes
= this_set
->section_sizes
;
3446 printf (_(" Section contributions:\n"));
3447 printf (_(" .debug_abbrev.dwo: 0x%s 0x%s\n"),
3448 dwarf_vmatoa ("x", offsets
[DW_SECT_ABBREV
]),
3449 dwarf_vmatoa ("x", sizes
[DW_SECT_ABBREV
]));
3450 printf (_(" .debug_line.dwo: 0x%s 0x%s\n"),
3451 dwarf_vmatoa ("x", offsets
[DW_SECT_LINE
]),
3452 dwarf_vmatoa ("x", sizes
[DW_SECT_LINE
]));
3453 printf (_(" .debug_loc.dwo: 0x%s 0x%s\n"),
3454 dwarf_vmatoa ("x", offsets
[DW_SECT_LOC
]),
3455 dwarf_vmatoa ("x", sizes
[DW_SECT_LOC
]));
3456 printf (_(" .debug_str_offsets.dwo: 0x%s 0x%s\n"),
3457 dwarf_vmatoa ("x", offsets
[DW_SECT_STR_OFFSETS
]),
3458 dwarf_vmatoa ("x", sizes
[DW_SECT_STR_OFFSETS
]));
3462 sec_off
= cu_offset
+ initial_length_size
;
3463 if (sec_off
+ compunit
.cu_length
< sec_off
3464 || sec_off
+ compunit
.cu_length
> section
->size
)
3466 warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"),
3468 (unsigned long) cu_offset
,
3469 dwarf_vmatoa ("x", compunit
.cu_length
));
3475 start
+= compunit
.cu_length
+ initial_length_size
;
3477 if (compunit
.cu_version
< 2 || compunit
.cu_version
> 5)
3479 warn (_("CU at offset %s contains corrupt or "
3480 "unsupported version number: %d.\n"),
3481 dwarf_vmatoa ("x", cu_offset
), compunit
.cu_version
);
3485 if (compunit
.cu_unit_type
!= DW_UT_compile
3486 && compunit
.cu_unit_type
!= DW_UT_type
)
3488 warn (_("CU at offset %s contains corrupt or "
3489 "unsupported unit type: %d.\n"),
3490 dwarf_vmatoa ("x", cu_offset
), compunit
.cu_unit_type
);
3496 /* Process the abbrevs used by this compilation unit. */
3497 if (compunit
.cu_abbrev_offset
>= abbrev_size
)
3498 warn (_("Debug info is corrupted, abbrev offset (%lx) is larger than abbrev section size (%lx)\n"),
3499 (unsigned long) compunit
.cu_abbrev_offset
,
3500 (unsigned long) abbrev_size
);
3501 /* PR 17531: file:4bcd9ce9. */
3502 else if ((abbrev_base
+ abbrev_size
)
3503 > debug_displays
[abbrev_sec
].section
.size
)
3504 warn (_("Debug info is corrupted, abbrev size (%lx) is larger than abbrev section size (%lx)\n"),
3505 (unsigned long) abbrev_base
+ abbrev_size
,
3506 (unsigned long) debug_displays
[abbrev_sec
].section
.size
);
3508 process_abbrev_section
3509 (((unsigned char *) debug_displays
[abbrev_sec
].section
.start
3510 + abbrev_base
+ compunit
.cu_abbrev_offset
),
3511 ((unsigned char *) debug_displays
[abbrev_sec
].section
.start
3512 + abbrev_base
+ abbrev_size
));
3517 while (tags
< start
)
3519 unsigned int bytes_read
;
3520 unsigned long abbrev_number
;
3521 unsigned long die_offset
;
3522 abbrev_entry
*entry
;
3524 int do_printing
= 1;
3526 die_offset
= tags
- section_begin
;
3528 abbrev_number
= read_uleb128 (tags
, & bytes_read
, start
);
3531 /* A null DIE marks the end of a list of siblings or it may also be
3532 a section padding. */
3533 if (abbrev_number
== 0)
3535 /* Check if it can be a section padding for the last CU. */
3536 if (level
== 0 && start
== end
)
3540 for (chk
= tags
; chk
< start
; chk
++)
3547 if (!do_loc
&& die_offset
>= dwarf_start_die
3548 && (dwarf_cutoff_level
== -1
3549 || level
< dwarf_cutoff_level
))
3550 printf (_(" <%d><%lx>: Abbrev Number: 0\n"),
3556 static unsigned num_bogus_warns
= 0;
3558 if (num_bogus_warns
< 3)
3560 warn (_("Bogus end-of-siblings marker detected at offset %lx in %s section\n"),
3561 die_offset
, section
->name
);
3563 if (num_bogus_warns
== 3)
3564 warn (_("Further warnings about bogus end-of-sibling markers suppressed\n"));
3567 if (dwarf_start_die
!= 0 && level
< saved_level
)
3574 if (dwarf_start_die
!= 0 && die_offset
< dwarf_start_die
)
3578 if (dwarf_start_die
!= 0 && die_offset
== dwarf_start_die
)
3579 saved_level
= level
;
3580 do_printing
= (dwarf_cutoff_level
== -1
3581 || level
< dwarf_cutoff_level
);
3583 printf (_(" <%d><%lx>: Abbrev Number: %lu"),
3584 level
, die_offset
, abbrev_number
);
3585 else if (dwarf_cutoff_level
== -1
3586 || last_level
< dwarf_cutoff_level
)
3587 printf (_(" <%d><%lx>: ...\n"), level
, die_offset
);
3592 /* Scan through the abbreviation list until we reach the
3594 for (entry
= first_abbrev
;
3595 entry
&& entry
->entry
!= abbrev_number
;
3596 entry
= entry
->next
)
3601 if (!do_loc
&& do_printing
)
3606 warn (_("DIE at offset 0x%lx refers to abbreviation number %lu which does not exist\n"),
3607 die_offset
, abbrev_number
);
3611 if (!do_loc
&& do_printing
)
3612 printf (" (%s)\n", get_TAG_name (entry
->tag
));
3617 need_base_address
= 0;
3619 case DW_TAG_compile_unit
:
3620 need_base_address
= 1;
3621 need_dwo_info
= do_loc
;
3623 case DW_TAG_entry_point
:
3624 case DW_TAG_subprogram
:
3625 need_base_address
= 0;
3626 /* Assuming that there is no DW_AT_frame_base. */
3627 have_frame_base
= 0;
3631 debug_info
*debug_info_p
=
3632 (debug_information
&& unit
< alloc_num_debug_info_entries
)
3633 ? debug_information
+ unit
: NULL
;
3635 assert (!debug_info_p
3636 || (debug_info_p
->num_loc_offsets
3637 == debug_info_p
->num_loc_views
));
3639 for (attr
= entry
->first_attr
;
3640 attr
&& attr
->attribute
;
3643 if (! do_loc
&& do_printing
)
3644 /* Show the offset from where the tag was extracted. */
3645 printf (" <%lx>", (unsigned long)(tags
- section_begin
));
3646 tags
= read_and_display_attr (attr
->attribute
,
3648 attr
->implicit_const
,
3653 compunit
.cu_pointer_size
,
3655 compunit
.cu_version
,
3657 do_loc
|| ! do_printing
,
3663 /* If a locview attribute appears before a location one,
3664 make sure we don't associate it with an earlier
3667 switch (debug_info_p
->num_loc_offsets
- debug_info_p
->num_loc_views
)
3670 debug_info_p
->loc_views
[debug_info_p
->num_loc_views
] = vm1
;
3671 debug_info_p
->num_loc_views
++;
3672 assert (debug_info_p
->num_loc_views
3673 == debug_info_p
->num_loc_offsets
);
3680 warn(_("DIE has locviews without loclist\n"));
3681 debug_info_p
->num_loc_views
--;
3688 if (entry
->children
)
3693 /* Set num_debug_info_entries here so that it can be used to check if
3694 we need to process .debug_loc and .debug_ranges sections. */
3695 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
3696 && num_debug_info_entries
== 0
3699 if (num_units
> alloc_num_debug_info_entries
)
3700 num_debug_info_entries
= alloc_num_debug_info_entries
;
3702 num_debug_info_entries
= num_units
;
3711 /* Locate and scan the .debug_info section in the file and record the pointer
3712 sizes and offsets for the compilation units in it. Usually an executable
3713 will have just one pointer size, but this is not guaranteed, and so we try
3714 not to make any assumptions. Returns zero upon failure, or the number of
3715 compilation units upon success. */
3718 load_debug_info (void * file
)
3720 /* If we have already tried and failed to load the .debug_info
3721 section then do not bother to repeat the task. */
3722 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
3725 /* If we already have the information there is nothing else to do. */
3726 if (num_debug_info_entries
> 0)
3727 return num_debug_info_entries
;
3729 /* If this is a DWARF package file, load the CU and TU indexes. */
3730 (void) load_cu_tu_indexes (file
);
3732 if (load_debug_section_with_follow (info
, file
)
3733 && process_debug_info (&debug_displays
[info
].section
, file
, abbrev
, TRUE
, FALSE
))
3734 return num_debug_info_entries
;
3736 if (load_debug_section_with_follow (info_dwo
, file
)
3737 && process_debug_info (&debug_displays
[info_dwo
].section
, file
,
3738 abbrev_dwo
, TRUE
, FALSE
))
3739 return num_debug_info_entries
;
3741 num_debug_info_entries
= DEBUG_INFO_UNAVAILABLE
;
3745 /* Read a DWARF .debug_line section header starting at DATA.
3746 Upon success returns an updated DATA pointer and the LINFO
3747 structure and the END_OF_SEQUENCE pointer will be filled in.
3748 Otherwise returns NULL. */
3750 static unsigned char *
3751 read_debug_line_header (struct dwarf_section
* section
,
3752 unsigned char * data
,
3753 unsigned char * end
,
3754 DWARF2_Internal_LineInfo
* linfo
,
3755 unsigned char ** end_of_sequence
)
3757 unsigned char *hdrptr
;
3758 unsigned int initial_length_size
;
3759 unsigned char address_size
, segment_selector_size
;
3761 /* Extract information from the Line Number Program Header.
3762 (section 6.2.4 in the Dwarf3 doc). */
3765 /* Get and check the length of the block. */
3766 SAFE_BYTE_GET_AND_INC (linfo
->li_length
, hdrptr
, 4, end
);
3768 if (linfo
->li_length
== 0xffffffff)
3770 /* This section is 64-bit DWARF 3. */
3771 SAFE_BYTE_GET_AND_INC (linfo
->li_length
, hdrptr
, 8, end
);
3772 linfo
->li_offset_size
= 8;
3773 initial_length_size
= 12;
3777 linfo
->li_offset_size
= 4;
3778 initial_length_size
= 4;
3781 if (linfo
->li_length
+ initial_length_size
> section
->size
)
3783 /* If the length field has a relocation against it, then we should
3784 not complain if it is inaccurate (and probably negative). This
3785 happens in object files when the .debug_line section is actually
3786 comprised of several different .debug_line.* sections, (some of
3787 which may be removed by linker garbage collection), and a relocation
3788 is used to compute the correct length once that is done. */
3789 if (reloc_at (section
, (hdrptr
- section
->start
) - linfo
->li_offset_size
))
3791 linfo
->li_length
= (end
- data
) - initial_length_size
;
3795 warn (_("The length field (0x%lx) in the debug_line header is wrong - the section is too small\n"),
3796 (long) linfo
->li_length
);
3801 /* Get and check the version number. */
3802 SAFE_BYTE_GET_AND_INC (linfo
->li_version
, hdrptr
, 2, end
);
3804 if (linfo
->li_version
!= 2
3805 && linfo
->li_version
!= 3
3806 && linfo
->li_version
!= 4
3807 && linfo
->li_version
!= 5)
3809 warn (_("Only DWARF version 2, 3, 4 and 5 line info "
3810 "is currently supported.\n"));
3814 if (linfo
->li_version
>= 5)
3816 SAFE_BYTE_GET_AND_INC (address_size
, hdrptr
, 1, end
);
3818 SAFE_BYTE_GET_AND_INC (segment_selector_size
, hdrptr
, 1, end
);
3819 if (segment_selector_size
!= 0)
3821 warn (_("The %s section contains "
3822 "unsupported segment selector size: %d.\n"),
3823 section
->name
, segment_selector_size
);
3828 SAFE_BYTE_GET_AND_INC (linfo
->li_prologue_length
, hdrptr
,
3829 linfo
->li_offset_size
, end
);
3830 SAFE_BYTE_GET_AND_INC (linfo
->li_min_insn_length
, hdrptr
, 1, end
);
3832 if (linfo
->li_version
>= 4)
3834 SAFE_BYTE_GET_AND_INC (linfo
->li_max_ops_per_insn
, hdrptr
, 1, end
);
3836 if (linfo
->li_max_ops_per_insn
== 0)
3838 warn (_("Invalid maximum operations per insn.\n"));
3843 linfo
->li_max_ops_per_insn
= 1;
3845 SAFE_BYTE_GET_AND_INC (linfo
->li_default_is_stmt
, hdrptr
, 1, end
);
3846 SAFE_SIGNED_BYTE_GET_AND_INC (linfo
->li_line_base
, hdrptr
, 1, end
);
3847 SAFE_BYTE_GET_AND_INC (linfo
->li_line_range
, hdrptr
, 1, end
);
3848 SAFE_BYTE_GET_AND_INC (linfo
->li_opcode_base
, hdrptr
, 1, end
);
3850 * end_of_sequence
= data
+ linfo
->li_length
+ initial_length_size
;
3851 /* PR 17512: file:002-117414-0.004. */
3852 if (* end_of_sequence
> end
)
3854 warn (_("Line length %s extends beyond end of section\n"),
3855 dwarf_vmatoa ("u", linfo
->li_length
));
3856 * end_of_sequence
= end
;
3863 static unsigned char *
3864 display_formatted_table (unsigned char * data
,
3865 unsigned char * start
,
3866 unsigned char * end
,
3867 const DWARF2_Internal_LineInfo
* linfo
,
3868 struct dwarf_section
* section
,
3871 unsigned char *format_start
, format_count
, *format
, formati
;
3872 dwarf_vma data_count
, datai
;
3873 unsigned int bytes_read
, namepass
, last_entry
= 0;
3875 SAFE_BYTE_GET_AND_INC (format_count
, data
, 1, end
);
3876 format_start
= data
;
3877 for (formati
= 0; formati
< format_count
; formati
++)
3879 read_uleb128 (data
, & bytes_read
, end
);
3881 read_uleb128 (data
, & bytes_read
, end
);
3886 warn (_("Corrupt directory format table entry\n"));
3888 warn (_("Corrupt file name format table entry\n"));
3893 data_count
= read_uleb128 (data
, & bytes_read
, end
);
3898 warn (_("Corrupt directory list\n"));
3900 warn (_("Corrupt file name list\n"));
3904 if (data_count
== 0)
3907 printf (_("\n The Directory Table is empty.\n"));
3909 printf (_("\n The File Name Table is empty.\n"));
3914 printf (_("\n The Directory Table (offset 0x%lx):\n"),
3915 (long) (data
- start
));
3917 printf (_("\n The File Name Table (offset 0x%lx):\n"),
3918 (long) (data
- start
));
3920 printf (_(" Entry"));
3921 /* Delay displaying name as the last entry for better screen layout. */
3922 for (namepass
= 0; namepass
< 2; namepass
++)
3924 format
= format_start
;
3925 for (formati
= 0; formati
< format_count
; formati
++)
3927 dwarf_vma content_type
;
3929 content_type
= read_uleb128 (format
, & bytes_read
, end
);
3930 format
+= bytes_read
;
3931 if ((content_type
== DW_LNCT_path
) == (namepass
== 1))
3932 switch (content_type
)
3935 printf (_("\tName"));
3937 case DW_LNCT_directory_index
:
3938 printf (_("\tDir"));
3940 case DW_LNCT_timestamp
:
3941 printf (_("\tTime"));
3944 printf (_("\tSize"));
3947 printf (_("\tMD5"));
3950 printf (_("\t(Unknown format content type %s)"),
3951 dwarf_vmatoa ("u", content_type
));
3953 read_uleb128 (format
, & bytes_read
, end
);
3954 format
+= bytes_read
;
3959 for (datai
= 0; datai
< data_count
; datai
++)
3961 unsigned char *datapass
= data
;
3963 printf (" %d", last_entry
++);
3964 /* Delay displaying name as the last entry for better screen layout. */
3965 for (namepass
= 0; namepass
< 2; namepass
++)
3967 format
= format_start
;
3969 for (formati
= 0; formati
< format_count
; formati
++)
3971 dwarf_vma content_type
, form
;
3973 content_type
= read_uleb128 (format
, & bytes_read
, end
);
3974 format
+= bytes_read
;
3975 form
= read_uleb128 (format
, & bytes_read
, end
);
3976 format
+= bytes_read
;
3977 data
= read_and_display_attr_value (0, form
, 0, start
, data
, end
, 0, 0,
3978 linfo
->li_offset_size
,
3979 linfo
->li_version
, NULL
,
3980 ((content_type
== DW_LNCT_path
) != (namepass
== 1)),
3981 section
, NULL
, '\t', -1);
3987 warn (_("Corrupt directory entries list\n"));
3989 warn (_("Corrupt file name entries list\n"));
3998 display_debug_lines_raw (struct dwarf_section
* section
,
3999 unsigned char * data
,
4000 unsigned char * end
,
4003 unsigned char *start
= section
->start
;
4004 int verbose_view
= 0;
4006 introduce (section
, TRUE
);
4010 static DWARF2_Internal_LineInfo saved_linfo
;
4011 DWARF2_Internal_LineInfo linfo
;
4012 unsigned char *standard_opcodes
;
4013 unsigned char *end_of_sequence
;
4016 if (const_strneq (section
->name
, ".debug_line.")
4017 /* Note: the following does not apply to .debug_line.dwo sections.
4018 These are full debug_line sections. */
4019 && strcmp (section
->name
, ".debug_line.dwo") != 0)
4021 /* Sections named .debug_line.<foo> are fragments of a .debug_line
4022 section containing just the Line Number Statements. They are
4023 created by the assembler and intended to be used alongside gcc's
4024 -ffunction-sections command line option. When the linker's
4025 garbage collection decides to discard a .text.<foo> section it
4026 can then also discard the line number information in .debug_line.<foo>.
4028 Since the section is a fragment it does not have the details
4029 needed to fill out a LineInfo structure, so instead we use the
4030 details from the last full debug_line section that we processed. */
4031 end_of_sequence
= end
;
4032 standard_opcodes
= NULL
;
4033 linfo
= saved_linfo
;
4034 /* PR 17531: file: 0522b371. */
4035 if (linfo
.li_line_range
== 0)
4037 warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n"));
4040 reset_state_machine (linfo
.li_default_is_stmt
);
4044 unsigned char * hdrptr
;
4046 if ((hdrptr
= read_debug_line_header (section
, data
, end
, & linfo
,
4047 & end_of_sequence
)) == NULL
)
4050 printf (_(" Offset: 0x%lx\n"), (long)(data
- start
));
4051 printf (_(" Length: %ld\n"), (long) linfo
.li_length
);
4052 printf (_(" DWARF Version: %d\n"), linfo
.li_version
);
4053 printf (_(" Prologue Length: %d\n"), (int) linfo
.li_prologue_length
);
4054 printf (_(" Minimum Instruction Length: %d\n"), linfo
.li_min_insn_length
);
4055 if (linfo
.li_version
>= 4)
4056 printf (_(" Maximum Ops per Instruction: %d\n"), linfo
.li_max_ops_per_insn
);
4057 printf (_(" Initial value of 'is_stmt': %d\n"), linfo
.li_default_is_stmt
);
4058 printf (_(" Line Base: %d\n"), linfo
.li_line_base
);
4059 printf (_(" Line Range: %d\n"), linfo
.li_line_range
);
4060 printf (_(" Opcode Base: %d\n"), linfo
.li_opcode_base
);
4062 /* PR 17512: file: 1665-6428-0.004. */
4063 if (linfo
.li_line_range
== 0)
4065 warn (_("Line range of 0 is invalid, using 1 instead\n"));
4066 linfo
.li_line_range
= 1;
4069 reset_state_machine (linfo
.li_default_is_stmt
);
4071 /* Display the contents of the Opcodes table. */
4072 standard_opcodes
= hdrptr
;
4074 /* PR 17512: file: 002-417945-0.004. */
4075 if (standard_opcodes
+ linfo
.li_opcode_base
>= end
)
4077 warn (_("Line Base extends beyond end of section\n"));
4081 printf (_("\n Opcodes:\n"));
4083 for (i
= 1; i
< linfo
.li_opcode_base
; i
++)
4084 printf (ngettext (" Opcode %d has %d arg\n",
4085 " Opcode %d has %d args\n",
4086 standard_opcodes
[i
- 1]),
4087 i
, standard_opcodes
[i
- 1]);
4089 /* Display the contents of the Directory table. */
4090 data
= standard_opcodes
+ linfo
.li_opcode_base
- 1;
4092 if (linfo
.li_version
>= 5)
4094 load_debug_section_with_follow (line_str
, file
);
4096 data
= display_formatted_table (data
, start
, end
, &linfo
, section
,
4098 data
= display_formatted_table (data
, start
, end
, &linfo
, section
,
4104 printf (_("\n The Directory Table is empty.\n"));
4107 unsigned int last_dir_entry
= 0;
4109 printf (_("\n The Directory Table (offset 0x%lx):\n"),
4110 (long)(data
- start
));
4112 while (data
< end
&& *data
!= 0)
4114 printf (" %d\t%.*s\n", ++last_dir_entry
, (int) (end
- data
), data
);
4116 data
+= strnlen ((char *) data
, end
- data
) + 1;
4119 /* PR 17512: file: 002-132094-0.004. */
4120 if (data
>= end
- 1)
4124 /* Skip the NUL at the end of the table. */
4127 /* Display the contents of the File Name table. */
4129 printf (_("\n The File Name Table is empty.\n"));
4132 printf (_("\n The File Name Table (offset 0x%lx):\n"),
4133 (long)(data
- start
));
4134 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
4136 while (data
< end
&& *data
!= 0)
4138 unsigned char *name
;
4139 unsigned int bytes_read
;
4141 printf (" %d\t", ++state_machine_regs
.last_file_entry
);
4143 data
+= strnlen ((char *) data
, end
- data
) + 1;
4146 dwarf_vmatoa ("u", read_uleb128 (data
, & bytes_read
, end
)));
4149 dwarf_vmatoa ("u", read_uleb128 (data
, & bytes_read
, end
)));
4152 dwarf_vmatoa ("u", read_uleb128 (data
, & bytes_read
, end
)));
4154 printf ("%.*s\n", (int)(end
- name
), name
);
4158 warn (_("Corrupt file name table entry\n"));
4164 /* Skip the NUL at the end of the table. */
4169 saved_linfo
= linfo
;
4172 /* Now display the statements. */
4173 if (data
>= end_of_sequence
)
4174 printf (_(" No Line Number Statements.\n"));
4177 printf (_(" Line Number Statements:\n"));
4179 while (data
< end_of_sequence
)
4181 unsigned char op_code
;
4182 dwarf_signed_vma adv
;
4184 unsigned int bytes_read
;
4186 printf (" [0x%08lx]", (long)(data
- start
));
4190 if (op_code
>= linfo
.li_opcode_base
)
4192 op_code
-= linfo
.li_opcode_base
;
4193 uladv
= (op_code
/ linfo
.li_line_range
);
4194 if (linfo
.li_max_ops_per_insn
== 1)
4196 uladv
*= linfo
.li_min_insn_length
;
4197 state_machine_regs
.address
+= uladv
;
4199 state_machine_regs
.view
= 0;
4200 printf (_(" Special opcode %d: "
4201 "advance Address by %s to 0x%s%s"),
4202 op_code
, dwarf_vmatoa ("u", uladv
),
4203 dwarf_vmatoa ("x", state_machine_regs
.address
),
4204 verbose_view
&& uladv
4205 ? _(" (reset view)") : "");
4210 = ((state_machine_regs
.op_index
+ uladv
)
4211 / linfo
.li_max_ops_per_insn
)
4212 * linfo
.li_min_insn_length
;
4214 state_machine_regs
.address
+= addrdelta
;
4215 state_machine_regs
.op_index
4216 = (state_machine_regs
.op_index
+ uladv
)
4217 % linfo
.li_max_ops_per_insn
;
4219 state_machine_regs
.view
= 0;
4220 printf (_(" Special opcode %d: "
4221 "advance Address by %s to 0x%s[%d]%s"),
4222 op_code
, dwarf_vmatoa ("u", uladv
),
4223 dwarf_vmatoa ("x", state_machine_regs
.address
),
4224 state_machine_regs
.op_index
,
4225 verbose_view
&& addrdelta
4226 ? _(" (reset view)") : "");
4228 adv
= (op_code
% linfo
.li_line_range
) + linfo
.li_line_base
;
4229 state_machine_regs
.line
+= adv
;
4230 printf (_(" and Line by %s to %d"),
4231 dwarf_vmatoa ("d", adv
), state_machine_regs
.line
);
4232 if (verbose_view
|| state_machine_regs
.view
)
4233 printf (_(" (view %u)\n"), state_machine_regs
.view
);
4236 state_machine_regs
.view
++;
4238 else switch (op_code
)
4240 case DW_LNS_extended_op
:
4241 data
+= process_extended_line_op (data
, linfo
.li_default_is_stmt
, end
);
4245 printf (_(" Copy"));
4246 if (verbose_view
|| state_machine_regs
.view
)
4247 printf (_(" (view %u)\n"), state_machine_regs
.view
);
4250 state_machine_regs
.view
++;
4253 case DW_LNS_advance_pc
:
4254 uladv
= read_uleb128 (data
, & bytes_read
, end
);
4256 if (linfo
.li_max_ops_per_insn
== 1)
4258 uladv
*= linfo
.li_min_insn_length
;
4259 state_machine_regs
.address
+= uladv
;
4261 state_machine_regs
.view
= 0;
4262 printf (_(" Advance PC by %s to 0x%s%s\n"),
4263 dwarf_vmatoa ("u", uladv
),
4264 dwarf_vmatoa ("x", state_machine_regs
.address
),
4265 verbose_view
&& uladv
4266 ? _(" (reset view)") : "");
4271 = ((state_machine_regs
.op_index
+ uladv
)
4272 / linfo
.li_max_ops_per_insn
)
4273 * linfo
.li_min_insn_length
;
4274 state_machine_regs
.address
4276 state_machine_regs
.op_index
4277 = (state_machine_regs
.op_index
+ uladv
)
4278 % linfo
.li_max_ops_per_insn
;
4280 state_machine_regs
.view
= 0;
4281 printf (_(" Advance PC by %s to 0x%s[%d]%s\n"),
4282 dwarf_vmatoa ("u", uladv
),
4283 dwarf_vmatoa ("x", state_machine_regs
.address
),
4284 state_machine_regs
.op_index
,
4285 verbose_view
&& addrdelta
4286 ? _(" (reset view)") : "");
4290 case DW_LNS_advance_line
:
4291 adv
= read_sleb128 (data
, & bytes_read
, end
);
4293 state_machine_regs
.line
+= adv
;
4294 printf (_(" Advance Line by %s to %d\n"),
4295 dwarf_vmatoa ("d", adv
),
4296 state_machine_regs
.line
);
4299 case DW_LNS_set_file
:
4300 adv
= read_uleb128 (data
, & bytes_read
, end
);
4302 printf (_(" Set File Name to entry %s in the File Name Table\n"),
4303 dwarf_vmatoa ("d", adv
));
4304 state_machine_regs
.file
= adv
;
4307 case DW_LNS_set_column
:
4308 uladv
= read_uleb128 (data
, & bytes_read
, end
);
4310 printf (_(" Set column to %s\n"),
4311 dwarf_vmatoa ("u", uladv
));
4312 state_machine_regs
.column
= uladv
;
4315 case DW_LNS_negate_stmt
:
4316 adv
= state_machine_regs
.is_stmt
;
4318 printf (_(" Set is_stmt to %s\n"), dwarf_vmatoa ("d", adv
));
4319 state_machine_regs
.is_stmt
= adv
;
4322 case DW_LNS_set_basic_block
:
4323 printf (_(" Set basic block\n"));
4324 state_machine_regs
.basic_block
= 1;
4327 case DW_LNS_const_add_pc
:
4328 uladv
= ((255 - linfo
.li_opcode_base
) / linfo
.li_line_range
);
4329 if (linfo
.li_max_ops_per_insn
)
4331 uladv
*= linfo
.li_min_insn_length
;
4332 state_machine_regs
.address
+= uladv
;
4334 state_machine_regs
.view
= 0;
4335 printf (_(" Advance PC by constant %s to 0x%s%s\n"),
4336 dwarf_vmatoa ("u", uladv
),
4337 dwarf_vmatoa ("x", state_machine_regs
.address
),
4338 verbose_view
&& uladv
4339 ? _(" (reset view)") : "");
4344 = ((state_machine_regs
.op_index
+ uladv
)
4345 / linfo
.li_max_ops_per_insn
)
4346 * linfo
.li_min_insn_length
;
4347 state_machine_regs
.address
4349 state_machine_regs
.op_index
4350 = (state_machine_regs
.op_index
+ uladv
)
4351 % linfo
.li_max_ops_per_insn
;
4353 state_machine_regs
.view
= 0;
4354 printf (_(" Advance PC by constant %s to 0x%s[%d]%s\n"),
4355 dwarf_vmatoa ("u", uladv
),
4356 dwarf_vmatoa ("x", state_machine_regs
.address
),
4357 state_machine_regs
.op_index
,
4358 verbose_view
&& addrdelta
4359 ? _(" (reset view)") : "");
4363 case DW_LNS_fixed_advance_pc
:
4364 SAFE_BYTE_GET_AND_INC (uladv
, data
, 2, end
);
4365 state_machine_regs
.address
+= uladv
;
4366 state_machine_regs
.op_index
= 0;
4367 printf (_(" Advance PC by fixed size amount %s to 0x%s\n"),
4368 dwarf_vmatoa ("u", uladv
),
4369 dwarf_vmatoa ("x", state_machine_regs
.address
));
4370 /* Do NOT reset view. */
4373 case DW_LNS_set_prologue_end
:
4374 printf (_(" Set prologue_end to true\n"));
4377 case DW_LNS_set_epilogue_begin
:
4378 printf (_(" Set epilogue_begin to true\n"));
4381 case DW_LNS_set_isa
:
4382 uladv
= read_uleb128 (data
, & bytes_read
, end
);
4384 printf (_(" Set ISA to %s\n"), dwarf_vmatoa ("u", uladv
));
4388 printf (_(" Unknown opcode %d with operands: "), op_code
);
4390 if (standard_opcodes
!= NULL
)
4391 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
4393 printf ("0x%s%s", dwarf_vmatoa ("x", read_uleb128 (data
,
4395 i
== 1 ? "" : ", ");
4411 unsigned char *name
;
4412 unsigned int directory_index
;
4413 unsigned int modification_date
;
4414 unsigned int length
;
4417 /* Output a decoded representation of the .debug_line section. */
4420 display_debug_lines_decoded (struct dwarf_section
* section
,
4421 unsigned char * start
,
4422 unsigned char * data
,
4423 unsigned char * end
,
4426 static DWARF2_Internal_LineInfo saved_linfo
;
4428 introduce (section
, FALSE
);
4432 /* This loop amounts to one iteration per compilation unit. */
4433 DWARF2_Internal_LineInfo linfo
;
4434 unsigned char *standard_opcodes
;
4435 unsigned char *end_of_sequence
;
4437 File_Entry
*file_table
= NULL
;
4438 unsigned int n_files
= 0;
4439 unsigned char **directory_table
= NULL
;
4440 dwarf_vma n_directories
= 0;
4442 if (const_strneq (section
->name
, ".debug_line.")
4443 /* Note: the following does not apply to .debug_line.dwo sections.
4444 These are full debug_line sections. */
4445 && strcmp (section
->name
, ".debug_line.dwo") != 0)
4447 /* See comment in display_debug_lines_raw(). */
4448 end_of_sequence
= end
;
4449 standard_opcodes
= NULL
;
4450 linfo
= saved_linfo
;
4451 /* PR 17531: file: 0522b371. */
4452 if (linfo
.li_line_range
== 0)
4454 warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n"));
4457 reset_state_machine (linfo
.li_default_is_stmt
);
4461 unsigned char *hdrptr
;
4463 if ((hdrptr
= read_debug_line_header (section
, data
, end
, & linfo
,
4464 & end_of_sequence
)) == NULL
)
4467 /* PR 17531: file: 0522b371. */
4468 if (linfo
.li_line_range
== 0)
4470 warn (_("Line range of 0 is invalid, using 1 instead\n"));
4471 linfo
.li_line_range
= 1;
4473 reset_state_machine (linfo
.li_default_is_stmt
);
4475 /* Save a pointer to the contents of the Opcodes table. */
4476 standard_opcodes
= hdrptr
;
4478 /* Traverse the Directory table just to count entries. */
4479 data
= standard_opcodes
+ linfo
.li_opcode_base
- 1;
4483 warn (_("opcode base of %d extends beyond end of section\n"),
4484 linfo
.li_opcode_base
);
4488 if (linfo
.li_version
>= 5)
4490 unsigned char *format_start
, format_count
, *format
;
4491 dwarf_vma formati
, entryi
;
4492 unsigned int bytes_read
;
4494 load_debug_section_with_follow (line_str
, fileptr
);
4496 /* Skip directories format. */
4497 SAFE_BYTE_GET_AND_INC (format_count
, data
, 1, end
);
4498 format_start
= data
;
4499 for (formati
= 0; formati
< format_count
; formati
++)
4501 read_uleb128 (data
, & bytes_read
, end
);
4503 read_uleb128 (data
, & bytes_read
, end
);
4507 n_directories
= read_uleb128 (data
, & bytes_read
, end
);
4511 warn (_("Corrupt directories list\n"));
4515 directory_table
= (unsigned char **)
4516 xmalloc (n_directories
* sizeof (unsigned char *));
4518 for (entryi
= 0; entryi
< n_directories
; entryi
++)
4520 unsigned char **pathp
= &directory_table
[entryi
];
4522 format
= format_start
;
4523 for (formati
= 0; formati
< format_count
; formati
++)
4525 dwarf_vma content_type
, form
;
4528 content_type
= read_uleb128 (format
, & bytes_read
, end
);
4529 format
+= bytes_read
;
4530 form
= read_uleb128 (format
, & bytes_read
, end
);
4531 format
+= bytes_read
;
4534 warn (_("Corrupt directories list\n"));
4537 switch (content_type
)
4542 case DW_FORM_string
:
4545 case DW_FORM_line_strp
:
4546 SAFE_BYTE_GET (uvalue
, data
, linfo
.li_offset_size
,
4548 /* Remove const by the cast. */
4549 *pathp
= (unsigned char *)
4550 fetch_indirect_line_string (uvalue
);
4555 data
= read_and_display_attr_value (0, form
, 0, start
, data
, end
,
4557 linfo
.li_offset_size
,
4564 warn (_("Corrupt directories list\n"));
4569 /* Skip files format. */
4570 SAFE_BYTE_GET_AND_INC (format_count
, data
, 1, end
);
4571 format_start
= data
;
4572 for (formati
= 0; formati
< format_count
; formati
++)
4574 read_uleb128 (data
, & bytes_read
, end
);
4576 read_uleb128 (data
, & bytes_read
, end
);
4580 n_files
= read_uleb128 (data
, & bytes_read
, end
);
4584 warn (_("Corrupt file name list\n"));
4588 file_table
= (File_Entry
*) xcalloc (1, n_files
4589 * sizeof (File_Entry
));
4591 for (entryi
= 0; entryi
< n_files
; entryi
++)
4593 File_Entry
*file
= &file_table
[entryi
];
4595 format
= format_start
;
4596 for (formati
= 0; formati
< format_count
; formati
++)
4598 dwarf_vma content_type
, form
;
4601 content_type
= read_uleb128 (format
, & bytes_read
, end
);
4602 format
+= bytes_read
;
4603 form
= read_uleb128 (format
, & bytes_read
, end
);
4604 format
+= bytes_read
;
4607 warn (_("Corrupt file name list\n"));
4610 switch (content_type
)
4615 case DW_FORM_string
:
4618 case DW_FORM_line_strp
:
4619 SAFE_BYTE_GET (uvalue
, data
, linfo
.li_offset_size
,
4621 /* Remove const by the cast. */
4622 file
->name
= (unsigned char *)
4623 fetch_indirect_line_string (uvalue
);
4627 case DW_LNCT_directory_index
:
4631 SAFE_BYTE_GET (file
->directory_index
, data
, 1,
4635 SAFE_BYTE_GET (file
->directory_index
, data
, 2,
4639 file
->directory_index
= read_uleb128 (data
, NULL
,
4645 data
= read_and_display_attr_value (0, form
, 0, start
, data
, end
,
4647 linfo
.li_offset_size
,
4654 warn (_("Corrupt file name list\n"));
4663 unsigned char *ptr_directory_table
= data
;
4665 while (data
< end
&& *data
!= 0)
4667 data
+= strnlen ((char *) data
, end
- data
) + 1;
4674 warn (_("directory table ends unexpectedly\n"));
4679 /* Go through the directory table again to save the directories. */
4680 directory_table
= (unsigned char **)
4681 xmalloc (n_directories
* sizeof (unsigned char *));
4684 while (*ptr_directory_table
!= 0)
4686 directory_table
[i
] = ptr_directory_table
;
4687 ptr_directory_table
+= strnlen ((char *) ptr_directory_table
,
4688 ptr_directory_table
- end
) + 1;
4692 /* Skip the NUL at the end of the table. */
4695 /* Traverse the File Name table just to count the entries. */
4696 if (data
< end
&& *data
!= 0)
4698 unsigned char *ptr_file_name_table
= data
;
4700 while (data
< end
&& *data
!= 0)
4702 unsigned int bytes_read
;
4704 /* Skip Name, directory index, last modification time and length
4706 data
+= strnlen ((char *) data
, end
- data
) + 1;
4707 read_uleb128 (data
, & bytes_read
, end
);
4709 read_uleb128 (data
, & bytes_read
, end
);
4711 read_uleb128 (data
, & bytes_read
, end
);
4719 warn (_("file table ends unexpectedly\n"));
4724 /* Go through the file table again to save the strings. */
4725 file_table
= (File_Entry
*) xmalloc (n_files
* sizeof (File_Entry
));
4728 while (*ptr_file_name_table
!= 0)
4730 unsigned int bytes_read
;
4732 file_table
[i
].name
= ptr_file_name_table
;
4733 ptr_file_name_table
+= strnlen ((char *) ptr_file_name_table
,
4734 end
- ptr_file_name_table
) + 1;
4736 /* We are not interested in directory, time or size. */
4737 file_table
[i
].directory_index
= read_uleb128 (ptr_file_name_table
,
4739 ptr_file_name_table
+= bytes_read
;
4740 file_table
[i
].modification_date
= read_uleb128 (ptr_file_name_table
,
4742 ptr_file_name_table
+= bytes_read
;
4743 file_table
[i
].length
= read_uleb128 (ptr_file_name_table
, & bytes_read
, end
);
4744 ptr_file_name_table
+= bytes_read
;
4750 /* Skip the NUL at the end of the table. */
4754 /* Print the Compilation Unit's name and a header. */
4755 if (file_table
== NULL
)
4757 else if (directory_table
== NULL
)
4758 printf (_("CU: %s:\n"), file_table
[0].name
);
4761 unsigned int ix
= file_table
[0].directory_index
;
4762 const char *directory
;
4767 else if (n_directories
== 0)
4768 directory
= _("<unknown>");
4769 else if (ix
> n_directories
)
4771 warn (_("directory index %u > number of directories %s\n"),
4772 ix
, dwarf_vmatoa ("u", n_directories
));
4773 directory
= _("<corrupt>");
4776 directory
= (char *) directory_table
[ix
- 1];
4778 if (do_wide
|| strlen (directory
) < 76)
4779 printf (_("CU: %s/%s:\n"), directory
, file_table
[0].name
);
4781 printf ("%s:\n", file_table
[0].name
);
4784 printf (_("File name Line number Starting address View Stmt\n"));
4785 saved_linfo
= linfo
;
4788 /* This loop iterates through the Dwarf Line Number Program. */
4789 while (data
< end_of_sequence
)
4791 unsigned char op_code
;
4794 unsigned long int uladv
;
4795 unsigned int bytes_read
;
4796 int is_special_opcode
= 0;
4801 if (op_code
>= linfo
.li_opcode_base
)
4803 op_code
-= linfo
.li_opcode_base
;
4804 uladv
= (op_code
/ linfo
.li_line_range
);
4805 if (linfo
.li_max_ops_per_insn
== 1)
4807 uladv
*= linfo
.li_min_insn_length
;
4808 state_machine_regs
.address
+= uladv
;
4810 state_machine_regs
.view
= 0;
4815 = ((state_machine_regs
.op_index
+ uladv
)
4816 / linfo
.li_max_ops_per_insn
)
4817 * linfo
.li_min_insn_length
;
4818 state_machine_regs
.address
4820 state_machine_regs
.op_index
4821 = (state_machine_regs
.op_index
+ uladv
)
4822 % linfo
.li_max_ops_per_insn
;
4824 state_machine_regs
.view
= 0;
4827 adv
= (op_code
% linfo
.li_line_range
) + linfo
.li_line_base
;
4828 state_machine_regs
.line
+= adv
;
4829 is_special_opcode
= 1;
4830 /* Increment view after printing this row. */
4832 else switch (op_code
)
4834 case DW_LNS_extended_op
:
4836 unsigned int ext_op_code_len
;
4837 unsigned char ext_op_code
;
4838 unsigned char *op_code_data
= data
;
4840 ext_op_code_len
= read_uleb128 (op_code_data
, &bytes_read
,
4842 op_code_data
+= bytes_read
;
4844 if (ext_op_code_len
== 0)
4846 warn (_("Badly formed extended line op encountered!\n"));
4849 ext_op_code_len
+= bytes_read
;
4850 ext_op_code
= *op_code_data
++;
4854 switch (ext_op_code
)
4856 case DW_LNE_end_sequence
:
4857 /* Reset stuff after printing this row. */
4859 case DW_LNE_set_address
:
4860 SAFE_BYTE_GET_AND_INC (state_machine_regs
.address
,
4862 ext_op_code_len
- bytes_read
- 1,
4864 state_machine_regs
.op_index
= 0;
4865 state_machine_regs
.view
= 0;
4867 case DW_LNE_define_file
:
4869 file_table
= (File_Entry
*) xrealloc
4870 (file_table
, (n_files
+ 1) * sizeof (File_Entry
));
4872 ++state_machine_regs
.last_file_entry
;
4873 /* Source file name. */
4874 file_table
[n_files
].name
= op_code_data
;
4875 op_code_data
+= strlen ((char *) op_code_data
) + 1;
4876 /* Directory index. */
4877 file_table
[n_files
].directory_index
=
4878 read_uleb128 (op_code_data
, & bytes_read
,
4880 op_code_data
+= bytes_read
;
4881 /* Last modification time. */
4882 file_table
[n_files
].modification_date
=
4883 read_uleb128 (op_code_data
, & bytes_read
,
4885 op_code_data
+= bytes_read
;
4887 file_table
[n_files
].length
=
4888 read_uleb128 (op_code_data
, & bytes_read
,
4894 case DW_LNE_set_discriminator
:
4895 case DW_LNE_HP_set_sequence
:
4896 /* Simply ignored. */
4900 printf (_("UNKNOWN (%u): length %d\n"),
4901 ext_op_code
, ext_op_code_len
- bytes_read
);
4904 data
+= ext_op_code_len
;
4908 /* Increment view after printing this row. */
4911 case DW_LNS_advance_pc
:
4912 uladv
= read_uleb128 (data
, & bytes_read
, end
);
4914 if (linfo
.li_max_ops_per_insn
== 1)
4916 uladv
*= linfo
.li_min_insn_length
;
4917 state_machine_regs
.address
+= uladv
;
4919 state_machine_regs
.view
= 0;
4924 = ((state_machine_regs
.op_index
+ uladv
)
4925 / linfo
.li_max_ops_per_insn
)
4926 * linfo
.li_min_insn_length
;
4927 state_machine_regs
.address
4929 state_machine_regs
.op_index
4930 = (state_machine_regs
.op_index
+ uladv
)
4931 % linfo
.li_max_ops_per_insn
;
4933 state_machine_regs
.view
= 0;
4937 case DW_LNS_advance_line
:
4938 adv
= read_sleb128 (data
, & bytes_read
, end
);
4940 state_machine_regs
.line
+= adv
;
4943 case DW_LNS_set_file
:
4944 adv
= read_uleb128 (data
, & bytes_read
, end
);
4946 state_machine_regs
.file
= adv
;
4949 unsigned file
= state_machine_regs
.file
- 1;
4952 if (file_table
== NULL
|| n_files
== 0)
4953 printf (_("\n [Use file table entry %d]\n"), file
);
4955 else if (file
>= n_files
)
4957 warn (_("file index %u > number of files %u\n"), file
+ 1, n_files
);
4958 printf (_("\n <over large file table index %u>"), file
);
4960 else if ((dir
= file_table
[file
].directory_index
) == 0)
4961 /* If directory index is 0, that means current directory. */
4962 printf ("\n./%s:[++]\n", file_table
[file
].name
);
4963 else if (directory_table
== NULL
|| n_directories
== 0)
4964 printf (_("\n [Use file %s in directory table entry %d]\n"),
4965 file_table
[file
].name
, dir
);
4967 else if (dir
> n_directories
)
4969 warn (_("directory index %u > number of directories %s\n"),
4970 dir
, dwarf_vmatoa ("u", n_directories
));
4971 printf (_("\n <over large directory table entry %u>\n"), dir
);
4974 printf ("\n%s/%s:\n",
4975 /* The directory index starts counting at 1. */
4976 directory_table
[dir
- 1], file_table
[file
].name
);
4980 case DW_LNS_set_column
:
4981 uladv
= read_uleb128 (data
, & bytes_read
, end
);
4983 state_machine_regs
.column
= uladv
;
4986 case DW_LNS_negate_stmt
:
4987 adv
= state_machine_regs
.is_stmt
;
4989 state_machine_regs
.is_stmt
= adv
;
4992 case DW_LNS_set_basic_block
:
4993 state_machine_regs
.basic_block
= 1;
4996 case DW_LNS_const_add_pc
:
4997 uladv
= ((255 - linfo
.li_opcode_base
) / linfo
.li_line_range
);
4998 if (linfo
.li_max_ops_per_insn
== 1)
5000 uladv
*= linfo
.li_min_insn_length
;
5001 state_machine_regs
.address
+= uladv
;
5003 state_machine_regs
.view
= 0;
5008 = ((state_machine_regs
.op_index
+ uladv
)
5009 / linfo
.li_max_ops_per_insn
)
5010 * linfo
.li_min_insn_length
;
5011 state_machine_regs
.address
5013 state_machine_regs
.op_index
5014 = (state_machine_regs
.op_index
+ uladv
)
5015 % linfo
.li_max_ops_per_insn
;
5017 state_machine_regs
.view
= 0;
5021 case DW_LNS_fixed_advance_pc
:
5022 SAFE_BYTE_GET_AND_INC (uladv
, data
, 2, end
);
5023 state_machine_regs
.address
+= uladv
;
5024 state_machine_regs
.op_index
= 0;
5025 /* Do NOT reset view. */
5028 case DW_LNS_set_prologue_end
:
5031 case DW_LNS_set_epilogue_begin
:
5034 case DW_LNS_set_isa
:
5035 uladv
= read_uleb128 (data
, & bytes_read
, end
);
5037 printf (_(" Set ISA to %lu\n"), uladv
);
5041 printf (_(" Unknown opcode %d with operands: "), op_code
);
5043 if (standard_opcodes
!= NULL
)
5044 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
5046 printf ("0x%s%s", dwarf_vmatoa ("x", read_uleb128 (data
,
5048 i
== 1 ? "" : ", ");
5055 /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row
5056 to the DWARF address/line matrix. */
5057 if ((is_special_opcode
) || (xop
== -DW_LNE_end_sequence
)
5058 || (xop
== DW_LNS_copy
))
5060 const unsigned int MAX_FILENAME_LENGTH
= 35;
5062 char *newFileName
= NULL
;
5063 size_t fileNameLength
;
5067 unsigned indx
= state_machine_regs
.file
- 1;
5069 if (indx
>= n_files
)
5071 warn (_("corrupt file index %u encountered\n"), indx
);
5072 fileName
= _("<corrupt>");
5075 fileName
= (char *) file_table
[indx
].name
;
5078 fileName
= _("<unknown>");
5080 fileNameLength
= strlen (fileName
);
5082 if ((fileNameLength
> MAX_FILENAME_LENGTH
) && (!do_wide
))
5084 newFileName
= (char *) xmalloc (MAX_FILENAME_LENGTH
+ 1);
5085 /* Truncate file name */
5086 strncpy (newFileName
,
5087 fileName
+ fileNameLength
- MAX_FILENAME_LENGTH
,
5088 MAX_FILENAME_LENGTH
+ 1);
5092 newFileName
= (char *) xmalloc (fileNameLength
+ 1);
5093 strncpy (newFileName
, fileName
, fileNameLength
+ 1);
5096 if (!do_wide
|| (fileNameLength
<= MAX_FILENAME_LENGTH
))
5098 if (linfo
.li_max_ops_per_insn
== 1)
5099 printf ("%-35s %11d %#18" DWARF_VMA_FMT
"x",
5100 newFileName
, state_machine_regs
.line
,
5101 state_machine_regs
.address
);
5103 printf ("%-35s %11d %#18" DWARF_VMA_FMT
"x[%d]",
5104 newFileName
, state_machine_regs
.line
,
5105 state_machine_regs
.address
,
5106 state_machine_regs
.op_index
);
5110 if (linfo
.li_max_ops_per_insn
== 1)
5111 printf ("%s %11d %#18" DWARF_VMA_FMT
"x",
5112 newFileName
, state_machine_regs
.line
,
5113 state_machine_regs
.address
);
5115 printf ("%s %11d %#18" DWARF_VMA_FMT
"x[%d]",
5116 newFileName
, state_machine_regs
.line
,
5117 state_machine_regs
.address
,
5118 state_machine_regs
.op_index
);
5121 if (state_machine_regs
.view
)
5122 printf (" %6u", state_machine_regs
.view
);
5126 if (state_machine_regs
.is_stmt
)
5130 state_machine_regs
.view
++;
5132 if (xop
== -DW_LNE_end_sequence
)
5134 reset_state_machine (linfo
.li_default_is_stmt
);
5149 if (directory_table
)
5151 free (directory_table
);
5152 directory_table
= NULL
;
5163 display_debug_lines (struct dwarf_section
*section
, void *file
)
5165 unsigned char *data
= section
->start
;
5166 unsigned char *end
= data
+ section
->size
;
5168 int retValDecoded
= 1;
5170 if (do_debug_lines
== 0)
5171 do_debug_lines
|= FLAG_DEBUG_LINES_RAW
;
5173 if (do_debug_lines
& FLAG_DEBUG_LINES_RAW
)
5174 retValRaw
= display_debug_lines_raw (section
, data
, end
, file
);
5176 if (do_debug_lines
& FLAG_DEBUG_LINES_DECODED
)
5177 retValDecoded
= display_debug_lines_decoded (section
, data
, data
, end
, file
);
5179 if (!retValRaw
|| !retValDecoded
)
5186 find_debug_info_for_offset (unsigned long offset
)
5190 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
5193 for (i
= 0; i
< num_debug_info_entries
; i
++)
5194 if (debug_information
[i
].cu_offset
== offset
)
5195 return debug_information
+ i
;
5201 get_gdb_index_symbol_kind_name (gdb_index_symbol_kind kind
)
5203 /* See gdb/gdb-index.h. */
5204 static const char * const kinds
[] =
5216 return _ (kinds
[kind
]);
5220 display_debug_pubnames_worker (struct dwarf_section
*section
,
5221 void *file ATTRIBUTE_UNUSED
,
5224 DWARF2_Internal_PubNames names
;
5225 unsigned char *start
= section
->start
;
5226 unsigned char *end
= start
+ section
->size
;
5228 /* It does not matter if this load fails,
5229 we test for that later on. */
5230 load_debug_info (file
);
5232 introduce (section
, FALSE
);
5236 unsigned char *data
;
5237 unsigned long sec_off
;
5238 unsigned int offset_size
, initial_length_size
;
5240 SAFE_BYTE_GET_AND_INC (names
.pn_length
, start
, 4, end
);
5241 if (names
.pn_length
== 0xffffffff)
5243 SAFE_BYTE_GET_AND_INC (names
.pn_length
, start
, 8, end
);
5245 initial_length_size
= 12;
5250 initial_length_size
= 4;
5253 sec_off
= start
- section
->start
;
5254 if (sec_off
+ names
.pn_length
< sec_off
5255 || sec_off
+ names
.pn_length
> section
->size
)
5257 warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"),
5259 sec_off
- initial_length_size
,
5260 dwarf_vmatoa ("x", names
.pn_length
));
5265 start
+= names
.pn_length
;
5267 SAFE_BYTE_GET_AND_INC (names
.pn_version
, data
, 2, end
);
5268 SAFE_BYTE_GET_AND_INC (names
.pn_offset
, data
, offset_size
, end
);
5270 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
5271 && num_debug_info_entries
> 0
5272 && find_debug_info_for_offset (names
.pn_offset
) == NULL
)
5273 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
5274 (unsigned long) names
.pn_offset
, section
->name
);
5276 SAFE_BYTE_GET_AND_INC (names
.pn_size
, data
, offset_size
, end
);
5278 printf (_(" Length: %ld\n"),
5279 (long) names
.pn_length
);
5280 printf (_(" Version: %d\n"),
5282 printf (_(" Offset into .debug_info section: 0x%lx\n"),
5283 (unsigned long) names
.pn_offset
);
5284 printf (_(" Size of area in .debug_info section: %ld\n"),
5285 (long) names
.pn_size
);
5287 if (names
.pn_version
!= 2 && names
.pn_version
!= 3)
5289 static int warned
= 0;
5293 warn (_("Only DWARF 2 and 3 pubnames are currently supported\n"));
5301 printf (_("\n Offset Kind Name\n"));
5303 printf (_("\n Offset\tName\n"));
5307 bfd_size_type maxprint
;
5310 SAFE_BYTE_GET (offset
, data
, offset_size
, end
);
5315 data
+= offset_size
;
5318 maxprint
= (end
- data
) - 1;
5322 unsigned int kind_data
;
5323 gdb_index_symbol_kind kind
;
5324 const char *kind_name
;
5327 SAFE_BYTE_GET (kind_data
, data
, 1, end
);
5330 /* GCC computes the kind as the upper byte in the CU index
5331 word, and then right shifts it by the CU index size.
5332 Left shift KIND to where the gdb-index.h accessor macros
5334 kind_data
<<= GDB_INDEX_CU_BITSIZE
;
5335 kind
= GDB_INDEX_SYMBOL_KIND_VALUE (kind_data
);
5336 kind_name
= get_gdb_index_symbol_kind_name (kind
);
5337 is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (kind_data
);
5338 printf (" %-6lx %s,%-10s %.*s\n",
5339 (unsigned long) offset
, is_static
? _("s") : _("g"),
5340 kind_name
, (int) maxprint
, data
);
5343 printf (" %-6lx\t%.*s\n",
5344 (unsigned long) offset
, (int) maxprint
, data
);
5346 data
+= strnlen ((char *) data
, maxprint
) + 1;
5357 display_debug_pubnames (struct dwarf_section
*section
, void *file
)
5359 return display_debug_pubnames_worker (section
, file
, 0);
5363 display_debug_gnu_pubnames (struct dwarf_section
*section
, void *file
)
5365 return display_debug_pubnames_worker (section
, file
, 1);
5369 display_debug_macinfo (struct dwarf_section
*section
,
5370 void *file ATTRIBUTE_UNUSED
)
5372 unsigned char *start
= section
->start
;
5373 unsigned char *end
= start
+ section
->size
;
5374 unsigned char *curr
= start
;
5375 unsigned int bytes_read
;
5376 enum dwarf_macinfo_record_type op
;
5378 introduce (section
, FALSE
);
5382 unsigned int lineno
;
5383 const unsigned char *string
;
5385 op
= (enum dwarf_macinfo_record_type
) *curr
;
5390 case DW_MACINFO_start_file
:
5392 unsigned int filenum
;
5394 lineno
= read_uleb128 (curr
, & bytes_read
, end
);
5396 filenum
= read_uleb128 (curr
, & bytes_read
, end
);
5399 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"),
5404 case DW_MACINFO_end_file
:
5405 printf (_(" DW_MACINFO_end_file\n"));
5408 case DW_MACINFO_define
:
5409 lineno
= read_uleb128 (curr
, & bytes_read
, end
);
5412 curr
+= strnlen ((char *) string
, end
- string
) + 1;
5413 printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"),
5417 case DW_MACINFO_undef
:
5418 lineno
= read_uleb128 (curr
, & bytes_read
, end
);
5421 curr
+= strnlen ((char *) string
, end
- string
) + 1;
5422 printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"),
5426 case DW_MACINFO_vendor_ext
:
5428 unsigned int constant
;
5430 constant
= read_uleb128 (curr
, & bytes_read
, end
);
5433 curr
+= strnlen ((char *) string
, end
- string
) + 1;
5434 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"),
5444 /* Given LINE_OFFSET into the .debug_line section, attempt to return
5445 filename and dirname corresponding to file name table entry with index
5446 FILEIDX. Return NULL on failure. */
5448 static unsigned char *
5449 get_line_filename_and_dirname (dwarf_vma line_offset
,
5451 unsigned char **dir_name
)
5453 struct dwarf_section
*section
= &debug_displays
[line
].section
;
5454 unsigned char *hdrptr
, *dirtable
, *file_name
;
5455 unsigned int offset_size
, initial_length_size
;
5456 unsigned int version
, opcode_base
, bytes_read
;
5457 dwarf_vma length
, diridx
;
5458 const unsigned char * end
;
5461 if (section
->start
== NULL
5462 || line_offset
>= section
->size
5466 hdrptr
= section
->start
+ line_offset
;
5467 end
= section
->start
+ section
->size
;
5469 SAFE_BYTE_GET_AND_INC (length
, hdrptr
, 4, end
);
5470 if (length
== 0xffffffff)
5472 /* This section is 64-bit DWARF 3. */
5473 SAFE_BYTE_GET_AND_INC (length
, hdrptr
, 8, end
);
5475 initial_length_size
= 12;
5480 initial_length_size
= 4;
5482 if (length
+ initial_length_size
< length
5483 || length
+ initial_length_size
> section
->size
)
5486 SAFE_BYTE_GET_AND_INC (version
, hdrptr
, 2, end
);
5487 if (version
!= 2 && version
!= 3 && version
!= 4)
5489 hdrptr
+= offset_size
+ 1;/* Skip prologue_length and min_insn_length. */
5491 hdrptr
++; /* Skip max_ops_per_insn. */
5492 hdrptr
+= 3; /* Skip default_is_stmt, line_base, line_range. */
5494 SAFE_BYTE_GET_AND_INC (opcode_base
, hdrptr
, 1, end
);
5495 if (opcode_base
== 0)
5498 hdrptr
+= opcode_base
- 1;
5503 /* Skip over dirname table. */
5504 while (*hdrptr
!= '\0')
5506 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
) + 1;
5510 hdrptr
++; /* Skip the NUL at the end of the table. */
5512 /* Now skip over preceding filename table entries. */
5513 for (; hdrptr
< end
&& *hdrptr
!= '\0' && fileidx
> 1; fileidx
--)
5515 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
) + 1;
5516 read_uleb128 (hdrptr
, &bytes_read
, end
);
5517 hdrptr
+= bytes_read
;
5518 read_uleb128 (hdrptr
, &bytes_read
, end
);
5519 hdrptr
+= bytes_read
;
5520 read_uleb128 (hdrptr
, &bytes_read
, end
);
5521 hdrptr
+= bytes_read
;
5523 if (hdrptr
>= end
|| *hdrptr
== '\0')
5527 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
) + 1;
5530 diridx
= read_uleb128 (hdrptr
, &bytes_read
, end
);
5533 for (; dirtable
< end
&& *dirtable
!= '\0' && diridx
> 1; diridx
--)
5534 dirtable
+= strnlen ((char *) dirtable
, end
- dirtable
) + 1;
5535 if (dirtable
>= end
|| *dirtable
== '\0')
5537 *dir_name
= dirtable
;
5542 display_debug_macro (struct dwarf_section
*section
,
5545 unsigned char *start
= section
->start
;
5546 unsigned char *end
= start
+ section
->size
;
5547 unsigned char *curr
= start
;
5548 unsigned char *extended_op_buf
[256];
5549 unsigned int bytes_read
;
5551 load_debug_section_with_follow (str
, file
);
5552 load_debug_section_with_follow (line
, file
);
5554 introduce (section
, FALSE
);
5558 unsigned int lineno
, version
, flags
;
5559 unsigned int offset_size
= 4;
5560 const unsigned char *string
;
5561 dwarf_vma line_offset
= 0, sec_offset
= curr
- start
, offset
;
5562 unsigned char **extended_ops
= NULL
;
5564 SAFE_BYTE_GET_AND_INC (version
, curr
, 2, end
);
5565 if (version
!= 4 && version
!= 5)
5567 error (_("Only GNU extension to DWARF 4 or 5 of %s is currently supported.\n"),
5572 SAFE_BYTE_GET_AND_INC (flags
, curr
, 1, end
);
5575 printf (_(" Offset: 0x%lx\n"),
5576 (unsigned long) sec_offset
);
5577 printf (_(" Version: %d\n"), version
);
5578 printf (_(" Offset size: %d\n"), offset_size
);
5581 SAFE_BYTE_GET_AND_INC (line_offset
, curr
, offset_size
, end
);
5582 printf (_(" Offset into .debug_line: 0x%lx\n"),
5583 (unsigned long) line_offset
);
5587 unsigned int i
, count
, op
;
5590 SAFE_BYTE_GET_AND_INC (count
, curr
, 1, end
);
5592 memset (extended_op_buf
, 0, sizeof (extended_op_buf
));
5593 extended_ops
= extended_op_buf
;
5596 printf (_(" Extension opcode arguments:\n"));
5597 for (i
= 0; i
< count
; i
++)
5599 SAFE_BYTE_GET_AND_INC (op
, curr
, 1, end
);
5600 extended_ops
[op
] = curr
;
5601 nargs
= read_uleb128 (curr
, &bytes_read
, end
);
5604 printf (_(" DW_MACRO_%02x has no arguments\n"), op
);
5607 printf (_(" DW_MACRO_%02x arguments: "), op
);
5608 for (n
= 0; n
< nargs
; n
++)
5612 SAFE_BYTE_GET_AND_INC (form
, curr
, 1, end
);
5613 printf ("%s%s", get_FORM_name (form
),
5614 n
== nargs
- 1 ? "\n" : ", ");
5624 case DW_FORM_block1
:
5625 case DW_FORM_block2
:
5626 case DW_FORM_block4
:
5628 case DW_FORM_string
:
5630 case DW_FORM_sec_offset
:
5633 error (_("Invalid extension opcode form %s\n"),
5634 get_FORM_name (form
));
5650 error (_(".debug_macro section not zero terminated\n"));
5654 SAFE_BYTE_GET_AND_INC (op
, curr
, 1, end
);
5660 case DW_MACRO_start_file
:
5662 unsigned int filenum
;
5663 unsigned char *file_name
= NULL
, *dir_name
= NULL
;
5665 lineno
= read_uleb128 (curr
, &bytes_read
, end
);
5667 filenum
= read_uleb128 (curr
, &bytes_read
, end
);
5670 if ((flags
& 2) == 0)
5671 error (_("DW_MACRO_start_file used, but no .debug_line offset provided.\n"));
5674 = get_line_filename_and_dirname (line_offset
, filenum
,
5676 if (file_name
== NULL
)
5677 printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d\n"),
5680 printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d filename: %s%s%s\n"),
5682 dir_name
!= NULL
? (const char *) dir_name
: "",
5683 dir_name
!= NULL
? "/" : "", file_name
);
5687 case DW_MACRO_end_file
:
5688 printf (_(" DW_MACRO_end_file\n"));
5691 case DW_MACRO_define
:
5692 lineno
= read_uleb128 (curr
, &bytes_read
, end
);
5695 curr
+= strnlen ((char *) string
, end
- string
) + 1;
5696 printf (_(" DW_MACRO_define - lineno : %d macro : %s\n"),
5700 case DW_MACRO_undef
:
5701 lineno
= read_uleb128 (curr
, &bytes_read
, end
);
5704 curr
+= strnlen ((char *) string
, end
- string
) + 1;
5705 printf (_(" DW_MACRO_undef - lineno : %d macro : %s\n"),
5709 case DW_MACRO_define_strp
:
5710 lineno
= read_uleb128 (curr
, &bytes_read
, end
);
5712 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
5713 string
= fetch_indirect_string (offset
);
5714 printf (_(" DW_MACRO_define_strp - lineno : %d macro : %s\n"),
5718 case DW_MACRO_undef_strp
:
5719 lineno
= read_uleb128 (curr
, &bytes_read
, end
);
5721 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
5722 string
= fetch_indirect_string (offset
);
5723 printf (_(" DW_MACRO_undef_strp - lineno : %d macro : %s\n"),
5727 case DW_MACRO_import
:
5728 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
5729 printf (_(" DW_MACRO_import - offset : 0x%lx\n"),
5730 (unsigned long) offset
);
5733 case DW_MACRO_define_sup
:
5734 lineno
= read_uleb128 (curr
, &bytes_read
, end
);
5736 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
5737 printf (_(" DW_MACRO_define_sup - lineno : %d macro offset : 0x%lx\n"),
5738 lineno
, (unsigned long) offset
);
5741 case DW_MACRO_undef_sup
:
5742 lineno
= read_uleb128 (curr
, &bytes_read
, end
);
5744 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
5745 printf (_(" DW_MACRO_undef_sup - lineno : %d macro offset : 0x%lx\n"),
5746 lineno
, (unsigned long) offset
);
5749 case DW_MACRO_import_sup
:
5750 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
5751 printf (_(" DW_MACRO_import_sup - offset : 0x%lx\n"),
5752 (unsigned long) offset
);
5756 if (extended_ops
== NULL
|| extended_ops
[op
] == NULL
)
5758 error (_(" Unknown macro opcode %02x seen\n"), op
);
5763 /* Skip over unhandled opcodes. */
5765 unsigned char *desc
= extended_ops
[op
];
5766 nargs
= read_uleb128 (desc
, &bytes_read
, end
);
5770 printf (_(" DW_MACRO_%02x\n"), op
);
5773 printf (_(" DW_MACRO_%02x -"), op
);
5774 for (n
= 0; n
< nargs
; n
++)
5778 /* DW_FORM_implicit_const is not expected here. */
5779 SAFE_BYTE_GET_AND_INC (val
, desc
, 1, end
);
5781 = read_and_display_attr_value (0, val
, 0,
5782 start
, curr
, end
, 0, 0, offset_size
,
5783 version
, NULL
, 0, NULL
,
5801 display_debug_abbrev (struct dwarf_section
*section
,
5802 void *file ATTRIBUTE_UNUSED
)
5804 abbrev_entry
*entry
;
5805 unsigned char *start
= section
->start
;
5806 unsigned char *end
= start
+ section
->size
;
5808 introduce (section
, FALSE
);
5812 unsigned char *last
;
5817 start
= process_abbrev_section (start
, end
);
5819 if (first_abbrev
== NULL
)
5822 printf (_(" Number TAG (0x%lx)\n"), (long) (last
- section
->start
));
5824 for (entry
= first_abbrev
; entry
; entry
= entry
->next
)
5828 printf (" %ld %s [%s]\n",
5830 get_TAG_name (entry
->tag
),
5831 entry
->children
? _("has children") : _("no children"));
5833 for (attr
= entry
->first_attr
; attr
; attr
= attr
->next
)
5835 printf (" %-18s %s",
5836 get_AT_name (attr
->attribute
),
5837 get_FORM_name (attr
->form
));
5838 if (attr
->form
== DW_FORM_implicit_const
)
5839 printf (": %" BFD_VMA_FMT
"d", attr
->implicit_const
);
5851 /* Return true when ADDR is the maximum address, when addresses are
5852 POINTER_SIZE bytes long. */
5855 is_max_address (dwarf_vma addr
, unsigned int pointer_size
)
5857 dwarf_vma mask
= ~(~(dwarf_vma
) 1 << (pointer_size
* 8 - 1));
5858 return ((addr
& mask
) == mask
);
5861 /* Display a view pair list starting at *VSTART_PTR and ending at
5862 VLISTEND within SECTION. */
5865 display_view_pair_list (struct dwarf_section
*section
,
5866 unsigned char **vstart_ptr
,
5867 unsigned int debug_info_entry
,
5868 unsigned char *vlistend
)
5870 unsigned char *vstart
= *vstart_ptr
;
5871 unsigned char *section_end
= section
->start
+ section
->size
;
5872 unsigned int pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
5874 if (vlistend
< section_end
)
5875 section_end
= vlistend
;
5879 while (vstart
< section_end
)
5881 dwarf_vma off
= vstart
- section
->start
;
5882 dwarf_vma vbegin
, vend
;
5884 unsigned int bytes_read
;
5885 vbegin
= read_uleb128 (vstart
, &bytes_read
, section_end
);
5886 vstart
+= bytes_read
;
5887 if (vstart
== section_end
)
5889 vstart
-= bytes_read
;
5893 vend
= read_uleb128 (vstart
, &bytes_read
, section_end
);
5894 vstart
+= bytes_read
;
5896 printf (" %8.8lx ", (unsigned long) off
);
5898 print_dwarf_view (vbegin
, pointer_size
, 1);
5899 print_dwarf_view (vend
, pointer_size
, 1);
5900 printf (_("location view pair\n"));
5904 *vstart_ptr
= vstart
;
5907 /* Display a location list from a normal (ie, non-dwo) .debug_loc section. */
5910 display_loc_list (struct dwarf_section
*section
,
5911 unsigned char **start_ptr
,
5912 unsigned int debug_info_entry
,
5914 dwarf_vma base_address
,
5915 unsigned char **vstart_ptr
,
5918 unsigned char *start
= *start_ptr
, *vstart
= *vstart_ptr
;
5919 unsigned char *section_end
= section
->start
+ section
->size
;
5920 unsigned long cu_offset
;
5921 unsigned int pointer_size
;
5922 unsigned int offset_size
;
5927 unsigned short length
;
5928 int need_frame_base
;
5930 if (debug_info_entry
>= num_debug_info_entries
)
5932 warn (_("No debug information available for loc lists of entry: %u\n"),
5937 cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
5938 pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
5939 offset_size
= debug_information
[debug_info_entry
].offset_size
;
5940 dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
5942 if (pointer_size
< 2 || pointer_size
> 8)
5944 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
5945 pointer_size
, debug_info_entry
);
5951 dwarf_vma off
= offset
+ (start
- *start_ptr
);
5952 dwarf_vma vbegin
= vm1
, vend
= vm1
;
5954 if (start
+ 2 * pointer_size
> section_end
)
5956 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5957 (unsigned long) offset
);
5961 printf (" %8.8lx ", (unsigned long) off
);
5963 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, section_end
);
5964 SAFE_BYTE_GET_AND_INC (end
, start
, pointer_size
, section_end
);
5966 if (begin
== 0 && end
== 0)
5968 /* PR 18374: In a object file we can have a location list that
5969 starts with a begin and end of 0 because there are relocations
5970 that need to be applied to the addresses. Actually applying
5971 the relocations now does not help as they will probably resolve
5972 to 0, since the object file has not been fully linked. Real
5973 end of list markers will not have any relocations against them. */
5974 if (! reloc_at (section
, off
)
5975 && ! reloc_at (section
, off
+ pointer_size
))
5977 printf (_("<End of list>\n"));
5982 /* Check base address specifiers. */
5983 if (is_max_address (begin
, pointer_size
)
5984 && !is_max_address (end
, pointer_size
))
5987 print_dwarf_vma (begin
, pointer_size
);
5988 print_dwarf_vma (end
, pointer_size
);
5989 printf (_("(base address)\n"));
5995 unsigned int bytes_read
;
5997 off
= offset
+ (vstart
- *start_ptr
);
5999 vbegin
= read_uleb128 (vstart
, &bytes_read
, section_end
);
6000 vstart
+= bytes_read
;
6001 print_dwarf_view (vbegin
, pointer_size
, 1);
6003 vend
= read_uleb128 (vstart
, &bytes_read
, section_end
);
6004 vstart
+= bytes_read
;
6005 print_dwarf_view (vend
, pointer_size
, 1);
6007 printf (_("views at %8.8lx for:\n %*s "),
6008 (unsigned long) off
, 8, "");
6011 if (start
+ 2 > section_end
)
6013 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6014 (unsigned long) offset
);
6018 SAFE_BYTE_GET_AND_INC (length
, start
, 2, section_end
);
6020 if (start
+ length
> section_end
)
6022 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6023 (unsigned long) offset
);
6027 print_dwarf_vma (begin
+ base_address
, pointer_size
);
6028 print_dwarf_vma (end
+ base_address
, pointer_size
);
6031 need_frame_base
= decode_location_expression (start
,
6036 cu_offset
, section
);
6039 if (need_frame_base
&& !has_frame_base
)
6040 printf (_(" [without DW_AT_frame_base]"));
6042 if (begin
== end
&& vbegin
== vend
)
6043 fputs (_(" (start == end)"), stdout
);
6044 else if (begin
> end
|| (begin
== end
&& vbegin
> vend
))
6045 fputs (_(" (start > end)"), stdout
);
6053 *vstart_ptr
= vstart
;
6056 /* Display a location list from a normal (ie, non-dwo) .debug_loclists section. */
6059 display_loclists_list (struct dwarf_section
*section
,
6060 unsigned char **start_ptr
,
6061 unsigned int debug_info_entry
,
6063 dwarf_vma base_address
,
6064 unsigned char **vstart_ptr
,
6067 unsigned char *start
= *start_ptr
, *vstart
= *vstart_ptr
;
6068 unsigned char *section_end
= section
->start
+ section
->size
;
6069 unsigned long cu_offset
;
6070 unsigned int pointer_size
;
6071 unsigned int offset_size
;
6073 unsigned int bytes_read
;
6075 /* Initialize it due to a false compiler warning. */
6076 dwarf_vma begin
= -1, vbegin
= -1;
6077 dwarf_vma end
= -1, vend
= -1;
6079 int need_frame_base
;
6081 if (debug_info_entry
>= num_debug_info_entries
)
6083 warn (_("No debug information available for "
6084 "loclists lists of entry: %u\n"),
6089 cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
6090 pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
6091 offset_size
= debug_information
[debug_info_entry
].offset_size
;
6092 dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
6094 if (pointer_size
< 2 || pointer_size
> 8)
6096 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
6097 pointer_size
, debug_info_entry
);
6103 dwarf_vma off
= offset
+ (start
- *start_ptr
);
6104 enum dwarf_location_list_entry_type llet
;
6106 if (start
+ 1 > section_end
)
6108 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6109 (unsigned long) offset
);
6113 printf (" %8.8lx ", (unsigned long) off
);
6115 SAFE_BYTE_GET_AND_INC (llet
, start
, 1, section_end
);
6117 if (vstart
&& llet
== DW_LLE_offset_pair
)
6119 off
= offset
+ (vstart
- *start_ptr
);
6121 vbegin
= read_uleb128 (vstart
, &bytes_read
, section_end
);
6122 vstart
+= bytes_read
;
6123 print_dwarf_view (vbegin
, pointer_size
, 1);
6125 vend
= read_uleb128 (vstart
, &bytes_read
, section_end
);
6126 vstart
+= bytes_read
;
6127 print_dwarf_view (vend
, pointer_size
, 1);
6129 printf (_("views at %8.8lx for:\n %*s "),
6130 (unsigned long) off
, 8, "");
6135 case DW_LLE_end_of_list
:
6136 printf (_("<End of list>\n"));
6138 case DW_LLE_offset_pair
:
6139 begin
= read_uleb128 (start
, &bytes_read
, section_end
);
6140 start
+= bytes_read
;
6141 end
= read_uleb128 (start
, &bytes_read
, section_end
);
6142 start
+= bytes_read
;
6144 case DW_LLE_base_address
:
6145 SAFE_BYTE_GET_AND_INC (base_address
, start
, pointer_size
,
6147 print_dwarf_vma (base_address
, pointer_size
);
6148 printf (_("(base address)\n"));
6150 #ifdef DW_LLE_view_pair
6151 case DW_LLE_view_pair
:
6153 printf (_("View pair entry in loclist with locviews attribute\n"));
6154 vbegin
= read_uleb128 (start
, &bytes_read
, section_end
);
6155 start
+= bytes_read
;
6156 print_dwarf_view (vbegin
, pointer_size
, 1);
6158 vend
= read_uleb128 (start
, &bytes_read
, section_end
);
6159 start
+= bytes_read
;
6160 print_dwarf_view (vend
, pointer_size
, 1);
6162 printf (_("views for:\n"));
6166 error (_("Invalid location list entry type %d\n"), llet
);
6169 if (llet
== DW_LLE_end_of_list
)
6171 if (llet
!= DW_LLE_offset_pair
)
6174 if (start
+ 2 > section_end
)
6176 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6177 (unsigned long) offset
);
6181 length
= read_uleb128 (start
, &bytes_read
, section_end
);
6182 start
+= bytes_read
;
6184 print_dwarf_vma (begin
+ base_address
, pointer_size
);
6185 print_dwarf_vma (end
+ base_address
, pointer_size
);
6188 need_frame_base
= decode_location_expression (start
,
6193 cu_offset
, section
);
6196 if (need_frame_base
&& !has_frame_base
)
6197 printf (_(" [without DW_AT_frame_base]"));
6199 if (begin
== end
&& vbegin
== vend
)
6200 fputs (_(" (start == end)"), stdout
);
6201 else if (begin
> end
|| (begin
== end
&& vbegin
> vend
))
6202 fputs (_(" (start > end)"), stdout
);
6210 if (vbegin
!= vm1
|| vend
!= vm1
)
6211 printf (_("Trailing view pair not used in a range"));
6214 *vstart_ptr
= vstart
;
6217 /* Print a .debug_addr table index in decimal, surrounded by square brackets,
6218 right-adjusted in a field of length LEN, and followed by a space. */
6221 print_addr_index (unsigned int idx
, unsigned int len
)
6223 static char buf
[15];
6224 snprintf (buf
, sizeof (buf
), "[%d]", idx
);
6225 printf ("%*s ", len
, buf
);
6228 /* Display a location list from a .dwo section. It uses address indexes rather
6229 than embedded addresses. This code closely follows display_loc_list, but the
6230 two are sufficiently different that combining things is very ugly. */
6233 display_loc_list_dwo (struct dwarf_section
*section
,
6234 unsigned char **start_ptr
,
6235 unsigned int debug_info_entry
,
6237 unsigned char **vstart_ptr
,
6240 unsigned char *start
= *start_ptr
, *vstart
= *vstart_ptr
;
6241 unsigned char *section_end
= section
->start
+ section
->size
;
6242 unsigned long cu_offset
;
6243 unsigned int pointer_size
;
6244 unsigned int offset_size
;
6247 unsigned short length
;
6248 int need_frame_base
;
6250 unsigned int bytes_read
;
6252 if (debug_info_entry
>= num_debug_info_entries
)
6254 warn (_("No debug information for loc lists of entry: %u\n"),
6259 cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
6260 pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
6261 offset_size
= debug_information
[debug_info_entry
].offset_size
;
6262 dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
6264 if (pointer_size
< 2 || pointer_size
> 8)
6266 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
6267 pointer_size
, debug_info_entry
);
6273 printf (" %8.8lx ", (unsigned long) (offset
+ (start
- *start_ptr
)));
6275 if (start
>= section_end
)
6277 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6278 (unsigned long) offset
);
6282 SAFE_BYTE_GET_AND_INC (entry_type
, start
, 1, section_end
);
6295 dwarf_vma off
= offset
+ (vstart
- *start_ptr
);
6297 view
= read_uleb128 (vstart
, &bytes_read
, section_end
);
6298 vstart
+= bytes_read
;
6299 print_dwarf_view (view
, 8, 1);
6301 view
= read_uleb128 (vstart
, &bytes_read
, section_end
);
6302 vstart
+= bytes_read
;
6303 print_dwarf_view (view
, 8, 1);
6305 printf (_("views at %8.8lx for:\n %*s "),
6306 (unsigned long) off
, 8, "");
6314 case 0: /* A terminating entry. */
6316 *vstart_ptr
= vstart
;
6317 printf (_("<End of list>\n"));
6319 case 1: /* A base-address entry. */
6320 idx
= read_uleb128 (start
, &bytes_read
, section_end
);
6321 start
+= bytes_read
;
6322 print_addr_index (idx
, 8);
6323 printf ("%*s", 9 + (vstart
? 2 * 6 : 0), "");
6324 printf (_("(base address selection entry)\n"));
6326 case 2: /* A start/end entry. */
6327 idx
= read_uleb128 (start
, &bytes_read
, section_end
);
6328 start
+= bytes_read
;
6329 print_addr_index (idx
, 8);
6330 idx
= read_uleb128 (start
, &bytes_read
, section_end
);
6331 start
+= bytes_read
;
6332 print_addr_index (idx
, 8);
6334 case 3: /* A start/length entry. */
6335 idx
= read_uleb128 (start
, &bytes_read
, section_end
);
6336 start
+= bytes_read
;
6337 print_addr_index (idx
, 8);
6338 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
6339 printf ("%08x ", idx
);
6341 case 4: /* An offset pair entry. */
6342 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
6343 printf ("%08x ", idx
);
6344 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
6345 printf ("%08x ", idx
);
6348 warn (_("Unknown location list entry type 0x%x.\n"), entry_type
);
6350 *vstart_ptr
= vstart
;
6354 if (start
+ 2 > section_end
)
6356 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6357 (unsigned long) offset
);
6361 SAFE_BYTE_GET_AND_INC (length
, start
, 2, section_end
);
6362 if (start
+ length
> section_end
)
6364 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6365 (unsigned long) offset
);
6370 need_frame_base
= decode_location_expression (start
,
6375 cu_offset
, section
);
6378 if (need_frame_base
&& !has_frame_base
)
6379 printf (_(" [without DW_AT_frame_base]"));
6387 *vstart_ptr
= vstart
;
6390 /* Sort array of indexes in ascending order of loc_offsets[idx] and
6393 static dwarf_vma
*loc_offsets
, *loc_views
;
6396 loc_offsets_compar (const void *ap
, const void *bp
)
6398 dwarf_vma a
= loc_offsets
[*(const unsigned int *) ap
];
6399 dwarf_vma b
= loc_offsets
[*(const unsigned int *) bp
];
6401 int ret
= (a
> b
) - (b
> a
);
6405 a
= loc_views
[*(const unsigned int *) ap
];
6406 b
= loc_views
[*(const unsigned int *) bp
];
6408 ret
= (a
> b
) - (b
> a
);
6414 display_debug_loc (struct dwarf_section
*section
, void *file
)
6416 unsigned char *start
= section
->start
, *vstart
= NULL
;
6417 unsigned long bytes
;
6418 unsigned char *section_begin
= start
;
6419 unsigned int num_loc_list
= 0;
6420 unsigned long last_offset
= 0;
6421 unsigned long last_view
= 0;
6422 unsigned int first
= 0;
6425 int seen_first_offset
= 0;
6426 int locs_sorted
= 1;
6427 unsigned char *next
= start
, *vnext
= vstart
;
6428 unsigned int *array
= NULL
;
6429 const char *suffix
= strrchr (section
->name
, '.');
6430 bfd_boolean is_dwo
= FALSE
;
6431 int is_loclists
= strstr (section
->name
, "debug_loclists") != NULL
;
6432 dwarf_vma expected_start
= 0;
6434 if (suffix
&& strcmp (suffix
, ".dwo") == 0)
6437 bytes
= section
->size
;
6441 printf (_("\nThe %s section is empty.\n"), section
->name
);
6447 unsigned char *hdrptr
= section_begin
;
6448 dwarf_vma ll_length
;
6449 unsigned short ll_version
;
6450 unsigned char *end
= section_begin
+ section
->size
;
6451 unsigned char address_size
, segment_selector_size
;
6452 uint32_t offset_entry_count
;
6454 SAFE_BYTE_GET_AND_INC (ll_length
, hdrptr
, 4, end
);
6455 if (ll_length
== 0xffffffff)
6456 SAFE_BYTE_GET_AND_INC (ll_length
, hdrptr
, 8, end
);
6458 SAFE_BYTE_GET_AND_INC (ll_version
, hdrptr
, 2, end
);
6459 if (ll_version
!= 5)
6461 warn (_("The %s section contains corrupt or "
6462 "unsupported version number: %d.\n"),
6463 section
->name
, ll_version
);
6467 SAFE_BYTE_GET_AND_INC (address_size
, hdrptr
, 1, end
);
6469 SAFE_BYTE_GET_AND_INC (segment_selector_size
, hdrptr
, 1, end
);
6470 if (segment_selector_size
!= 0)
6472 warn (_("The %s section contains "
6473 "unsupported segment selector size: %d.\n"),
6474 section
->name
, segment_selector_size
);
6478 SAFE_BYTE_GET_AND_INC (offset_entry_count
, hdrptr
, 4, end
);
6479 if (offset_entry_count
!= 0)
6481 warn (_("The %s section contains "
6482 "unsupported offset entry count: %d.\n"),
6483 section
->name
, offset_entry_count
);
6487 expected_start
= hdrptr
- section_begin
;
6490 if (load_debug_info (file
) == 0)
6492 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
6497 /* Check the order of location list in .debug_info section. If
6498 offsets of location lists are in the ascending order, we can
6499 use `debug_information' directly. */
6500 for (i
= 0; i
< num_debug_info_entries
; i
++)
6504 num
= debug_information
[i
].num_loc_offsets
;
6505 if (num
> num_loc_list
)
6508 /* Check if we can use `debug_information' directly. */
6509 if (locs_sorted
&& num
!= 0)
6511 if (!seen_first_offset
)
6513 /* This is the first location list. */
6514 last_offset
= debug_information
[i
].loc_offsets
[0];
6515 last_view
= debug_information
[i
].loc_views
[0];
6517 seen_first_offset
= 1;
6523 for (; j
< num
; j
++)
6526 debug_information
[i
].loc_offsets
[j
]
6527 || (last_offset
== debug_information
[i
].loc_offsets
[j
]
6528 && last_view
> debug_information
[i
].loc_views
[j
]))
6533 last_offset
= debug_information
[i
].loc_offsets
[j
];
6534 last_view
= debug_information
[i
].loc_views
[j
];
6539 if (!seen_first_offset
)
6540 error (_("No location lists in .debug_info section!\n"));
6542 if (debug_information
[first
].num_loc_offsets
> 0
6543 && debug_information
[first
].loc_offsets
[0] != expected_start
6544 && debug_information
[first
].loc_views
[0] != expected_start
)
6545 warn (_("Location lists in %s section start at 0x%s\n"),
6547 dwarf_vmatoa ("x", debug_information
[first
].loc_offsets
[0]));
6550 array
= (unsigned int *) xcmalloc (num_loc_list
, sizeof (unsigned int));
6552 introduce (section
, FALSE
);
6554 if (reloc_at (section
, 0))
6555 printf (_(" Warning: This section has relocations - addresses seen here may not be accurate.\n\n"));
6557 printf (_(" Offset Begin End Expression\n"));
6559 seen_first_offset
= 0;
6560 for (i
= first
; i
< num_debug_info_entries
; i
++)
6562 dwarf_vma offset
, voffset
;
6563 dwarf_vma base_address
;
6569 for (k
= 0; k
< debug_information
[i
].num_loc_offsets
; k
++)
6571 loc_offsets
= debug_information
[i
].loc_offsets
;
6572 loc_views
= debug_information
[i
].loc_views
;
6573 qsort (array
, debug_information
[i
].num_loc_offsets
,
6574 sizeof (*array
), loc_offsets_compar
);
6577 int adjacent_view_loclists
= 1;
6578 for (k
= 0; k
< debug_information
[i
].num_loc_offsets
; k
++)
6580 j
= locs_sorted
? k
: array
[k
];
6582 && (debug_information
[i
].loc_offsets
[locs_sorted
6583 ? k
- 1 : array
[k
- 1]]
6584 == debug_information
[i
].loc_offsets
[j
])
6585 && (debug_information
[i
].loc_views
[locs_sorted
6586 ? k
- 1 : array
[k
- 1]]
6587 == debug_information
[i
].loc_views
[j
]))
6589 has_frame_base
= debug_information
[i
].have_frame_base
[j
];
6590 offset
= debug_information
[i
].loc_offsets
[j
];
6591 next
= section_begin
+ offset
;
6592 voffset
= debug_information
[i
].loc_views
[j
];
6594 vnext
= section_begin
+ voffset
;
6597 base_address
= debug_information
[i
].base_address
;
6599 if (vnext
&& vnext
< next
)
6602 display_view_pair_list (section
, &vstart
, i
, next
);
6607 if (!seen_first_offset
|| !adjacent_view_loclists
)
6608 seen_first_offset
= 1;
6612 warn (_("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n"),
6613 (unsigned long) (start
- section_begin
),
6614 (unsigned long) offset
);
6615 else if (start
> next
)
6616 warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n"),
6617 (unsigned long) (start
- section_begin
),
6618 (unsigned long) offset
);
6623 if (offset
>= bytes
)
6625 warn (_("Offset 0x%lx is bigger than .debug_loc section size.\n"),
6626 (unsigned long) offset
);
6630 if (vnext
&& voffset
>= bytes
)
6632 warn (_("View Offset 0x%lx is bigger than .debug_loc section size.\n"),
6633 (unsigned long) voffset
);
6640 display_loc_list_dwo (section
, &start
, i
, offset
,
6641 &vstart
, has_frame_base
);
6643 display_loc_list (section
, &start
, i
, offset
, base_address
,
6644 &vstart
, has_frame_base
);
6649 warn (_("DWO is not yet supported.\n"));
6651 display_loclists_list (section
, &start
, i
, offset
, base_address
,
6652 &vstart
, has_frame_base
);
6655 /* FIXME: this arrangement is quite simplistic. Nothing
6656 requires locview lists to be adjacent to corresponding
6657 loclists, and a single loclist could be augmented by
6658 different locview lists, and vice-versa, unlikely as it
6659 is that it would make sense to do so. Hopefully we'll
6660 have view pair support built into loclists before we ever
6661 need to address all these possibilities. */
6662 if (adjacent_view_loclists
&& vnext
6663 && vnext
!= start
&& vstart
!= next
)
6665 adjacent_view_loclists
= 0;
6666 warn (_("Hole and overlap detection requires adjacent view lists and loclists.\n"));
6669 if (vnext
&& vnext
== start
)
6670 display_view_pair_list (section
, &start
, i
, vstart
);
6674 if (start
< section
->start
+ section
->size
)
6675 warn (ngettext ("There is %ld unused byte at the end of section %s\n",
6676 "There are %ld unused bytes at the end of section %s\n",
6677 (long) (section
->start
+ section
->size
- start
)),
6678 (long) (section
->start
+ section
->size
- start
), section
->name
);
6685 display_debug_str (struct dwarf_section
*section
,
6686 void *file ATTRIBUTE_UNUSED
)
6688 unsigned char *start
= section
->start
;
6689 unsigned long bytes
= section
->size
;
6690 dwarf_vma addr
= section
->address
;
6694 printf (_("\nThe %s section is empty.\n"), section
->name
);
6698 introduce (section
, FALSE
);
6706 lbytes
= (bytes
> 16 ? 16 : bytes
);
6708 printf (" 0x%8.8lx ", (unsigned long) addr
);
6710 for (j
= 0; j
< 16; j
++)
6713 printf ("%2.2x", start
[j
]);
6721 for (j
= 0; j
< lbytes
; j
++)
6724 if (k
>= ' ' && k
< 0x80)
6743 display_debug_info (struct dwarf_section
*section
, void *file
)
6745 return process_debug_info (section
, file
, section
->abbrev_sec
, FALSE
, FALSE
);
6749 display_debug_types (struct dwarf_section
*section
, void *file
)
6751 return process_debug_info (section
, file
, section
->abbrev_sec
, FALSE
, TRUE
);
6755 display_trace_info (struct dwarf_section
*section
, void *file
)
6757 return process_debug_info (section
, file
, section
->abbrev_sec
, FALSE
, TRUE
);
6761 display_debug_aranges (struct dwarf_section
*section
,
6762 void *file ATTRIBUTE_UNUSED
)
6764 unsigned char *start
= section
->start
;
6765 unsigned char *end
= start
+ section
->size
;
6767 introduce (section
, FALSE
);
6769 /* It does not matter if this load fails,
6770 we test for that later on. */
6771 load_debug_info (file
);
6775 unsigned char *hdrptr
;
6776 DWARF2_Internal_ARange arange
;
6777 unsigned char *addr_ranges
;
6780 unsigned long sec_off
;
6781 unsigned char address_size
;
6783 unsigned int offset_size
;
6784 unsigned int initial_length_size
;
6788 SAFE_BYTE_GET_AND_INC (arange
.ar_length
, hdrptr
, 4, end
);
6789 if (arange
.ar_length
== 0xffffffff)
6791 SAFE_BYTE_GET_AND_INC (arange
.ar_length
, hdrptr
, 8, end
);
6793 initial_length_size
= 12;
6798 initial_length_size
= 4;
6801 sec_off
= hdrptr
- section
->start
;
6802 if (sec_off
+ arange
.ar_length
< sec_off
6803 || sec_off
+ arange
.ar_length
> section
->size
)
6805 warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"),
6807 sec_off
- initial_length_size
,
6808 dwarf_vmatoa ("x", arange
.ar_length
));
6812 SAFE_BYTE_GET_AND_INC (arange
.ar_version
, hdrptr
, 2, end
);
6813 SAFE_BYTE_GET_AND_INC (arange
.ar_info_offset
, hdrptr
, offset_size
, end
);
6815 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
6816 && num_debug_info_entries
> 0
6817 && find_debug_info_for_offset (arange
.ar_info_offset
) == NULL
)
6818 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
6819 (unsigned long) arange
.ar_info_offset
, section
->name
);
6821 SAFE_BYTE_GET_AND_INC (arange
.ar_pointer_size
, hdrptr
, 1, end
);
6822 SAFE_BYTE_GET_AND_INC (arange
.ar_segment_size
, hdrptr
, 1, end
);
6824 if (arange
.ar_version
!= 2 && arange
.ar_version
!= 3)
6826 /* PR 19872: A version number of 0 probably means that there is
6827 padding at the end of the .debug_aranges section. Gold puts
6828 it there when performing an incremental link, for example.
6829 So do not generate a warning in this case. */
6830 if (arange
.ar_version
)
6831 warn (_("Only DWARF 2 and 3 aranges are currently supported.\n"));
6835 printf (_(" Length: %ld\n"),
6836 (long) arange
.ar_length
);
6837 printf (_(" Version: %d\n"), arange
.ar_version
);
6838 printf (_(" Offset into .debug_info: 0x%lx\n"),
6839 (unsigned long) arange
.ar_info_offset
);
6840 printf (_(" Pointer Size: %d\n"), arange
.ar_pointer_size
);
6841 printf (_(" Segment Size: %d\n"), arange
.ar_segment_size
);
6843 address_size
= arange
.ar_pointer_size
+ arange
.ar_segment_size
;
6845 /* PR 17512: file: 001-108546-0.001:0.1. */
6846 if (address_size
== 0 || address_size
> 8)
6848 error (_("Invalid address size in %s section!\n"),
6853 /* The DWARF spec does not require that the address size be a power
6854 of two, but we do. This will have to change if we ever encounter
6855 an uneven architecture. */
6856 if ((address_size
& (address_size
- 1)) != 0)
6858 warn (_("Pointer size + Segment size is not a power of two.\n"));
6862 if (address_size
> 4)
6863 printf (_("\n Address Length\n"));
6865 printf (_("\n Address Length\n"));
6867 addr_ranges
= hdrptr
;
6869 /* Must pad to an alignment boundary that is twice the address size. */
6870 excess
= (hdrptr
- start
) % (2 * address_size
);
6872 addr_ranges
+= (2 * address_size
) - excess
;
6874 start
+= arange
.ar_length
+ initial_length_size
;
6876 while (addr_ranges
+ 2 * address_size
<= start
)
6878 SAFE_BYTE_GET_AND_INC (address
, addr_ranges
, address_size
, end
);
6879 SAFE_BYTE_GET_AND_INC (length
, addr_ranges
, address_size
, end
);
6882 print_dwarf_vma (address
, address_size
);
6883 print_dwarf_vma (length
, address_size
);
6893 /* Comparison function for qsort. */
6895 comp_addr_base (const void * v0
, const void * v1
)
6897 debug_info
*info0
= *(debug_info
**) v0
;
6898 debug_info
*info1
= *(debug_info
**) v1
;
6899 return info0
->addr_base
- info1
->addr_base
;
6902 /* Display the debug_addr section. */
6904 display_debug_addr (struct dwarf_section
*section
,
6907 debug_info
**debug_addr_info
;
6908 unsigned char *entry
;
6913 if (section
->size
== 0)
6915 printf (_("\nThe %s section is empty.\n"), section
->name
);
6919 if (load_debug_info (file
) == 0)
6921 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
6926 introduce (section
, FALSE
);
6928 /* PR 17531: file: cf38d01b.
6929 We use xcalloc because a corrupt file may not have initialised all of the
6930 fields in the debug_info structure, which means that the sort below might
6931 try to move uninitialised data. */
6932 debug_addr_info
= (debug_info
**) xcalloc ((num_debug_info_entries
+ 1),
6933 sizeof (debug_info
*));
6936 for (i
= 0; i
< num_debug_info_entries
; i
++)
6937 if (debug_information
[i
].addr_base
!= DEBUG_INFO_UNAVAILABLE
)
6939 /* PR 17531: file: cf38d01b. */
6940 if (debug_information
[i
].addr_base
>= section
->size
)
6941 warn (_("Corrupt address base (%lx) found in debug section %u\n"),
6942 (unsigned long) debug_information
[i
].addr_base
, i
);
6944 debug_addr_info
[count
++] = debug_information
+ i
;
6947 /* Add a sentinel to make iteration convenient. */
6948 debug_addr_info
[count
] = (debug_info
*) xmalloc (sizeof (debug_info
));
6949 debug_addr_info
[count
]->addr_base
= section
->size
;
6950 qsort (debug_addr_info
, count
, sizeof (debug_info
*), comp_addr_base
);
6952 for (i
= 0; i
< count
; i
++)
6955 unsigned int address_size
= debug_addr_info
[i
]->pointer_size
;
6957 printf (_(" For compilation unit at offset 0x%s:\n"),
6958 dwarf_vmatoa ("x", debug_addr_info
[i
]->cu_offset
));
6960 printf (_("\tIndex\tAddress\n"));
6961 entry
= section
->start
+ debug_addr_info
[i
]->addr_base
;
6962 end
= section
->start
+ debug_addr_info
[i
+ 1]->addr_base
;
6966 dwarf_vma base
= byte_get (entry
, address_size
);
6967 printf (_("\t%d:\t"), idx
);
6968 print_dwarf_vma (base
, address_size
);
6970 entry
+= address_size
;
6976 free (debug_addr_info
);
6980 /* Display the .debug_str_offsets and .debug_str_offsets.dwo sections. */
6983 display_debug_str_offsets (struct dwarf_section
*section
,
6984 void *file ATTRIBUTE_UNUSED
)
6986 if (section
->size
== 0)
6988 printf (_("\nThe %s section is empty.\n"), section
->name
);
6991 /* TODO: Dump the contents. This is made somewhat difficult by not knowing
6992 what the offset size is for this section. */
6996 /* Each debug_information[x].range_lists[y] gets this representation for
6997 sorting purposes. */
7001 /* The debug_information[x].range_lists[y] value. */
7002 dwarf_vma ranges_offset
;
7004 /* Original debug_information to find parameters of the data. */
7005 debug_info
*debug_info_p
;
7008 /* Sort struct range_entry in ascending order of its RANGES_OFFSET. */
7011 range_entry_compar (const void *ap
, const void *bp
)
7013 const struct range_entry
*a_re
= (const struct range_entry
*) ap
;
7014 const struct range_entry
*b_re
= (const struct range_entry
*) bp
;
7015 const dwarf_vma a
= a_re
->ranges_offset
;
7016 const dwarf_vma b
= b_re
->ranges_offset
;
7018 return (a
> b
) - (b
> a
);
7022 display_debug_ranges_list (unsigned char *start
, unsigned char *finish
,
7023 unsigned int pointer_size
, unsigned long offset
,
7024 unsigned long base_address
)
7026 while (start
< finish
)
7031 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
7032 if (start
>= finish
)
7034 SAFE_SIGNED_BYTE_GET_AND_INC (end
, start
, pointer_size
, finish
);
7037 printf (" %8.8lx ", offset
);
7039 if (begin
== 0 && end
== 0)
7041 printf (_("<End of list>\n"));
7045 /* Check base address specifiers. */
7046 if (is_max_address (begin
, pointer_size
)
7047 && !is_max_address (end
, pointer_size
))
7050 print_dwarf_vma (begin
, pointer_size
);
7051 print_dwarf_vma (end
, pointer_size
);
7052 printf ("(base address)\n");
7056 print_dwarf_vma (begin
+ base_address
, pointer_size
);
7057 print_dwarf_vma (end
+ base_address
, pointer_size
);
7060 fputs (_("(start == end)"), stdout
);
7061 else if (begin
> end
)
7062 fputs (_("(start > end)"), stdout
);
7069 display_debug_rnglists_list (unsigned char *start
, unsigned char *finish
,
7070 unsigned int pointer_size
, unsigned long offset
,
7071 unsigned long base_address
)
7073 unsigned char *next
= start
;
7077 unsigned long off
= offset
+ (start
- next
);
7078 enum dwarf_range_list_entry rlet
;
7079 /* Initialize it due to a false compiler warning. */
7080 dwarf_vma begin
= -1, length
, end
= -1;
7081 unsigned int bytes_read
;
7083 if (start
+ 1 > finish
)
7085 warn (_("Range list starting at offset 0x%lx is not terminated.\n"),
7090 printf (" %8.8lx ", off
);
7092 SAFE_BYTE_GET_AND_INC (rlet
, start
, 1, finish
);
7096 case DW_RLE_end_of_list
:
7097 printf (_("<End of list>\n"));
7099 case DW_RLE_base_address
:
7100 SAFE_BYTE_GET_AND_INC (base_address
, start
, pointer_size
, finish
);
7101 print_dwarf_vma (base_address
, pointer_size
);
7102 printf (_("(base address)\n"));
7104 case DW_RLE_start_length
:
7105 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
7106 length
= read_uleb128 (start
, &bytes_read
, finish
);
7107 start
+= bytes_read
;
7108 end
= begin
+ length
;
7110 case DW_RLE_offset_pair
:
7111 begin
= read_uleb128 (start
, &bytes_read
, finish
);
7112 start
+= bytes_read
;
7113 end
= read_uleb128 (start
, &bytes_read
, finish
);
7114 start
+= bytes_read
;
7116 case DW_RLE_start_end
:
7117 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
7118 SAFE_BYTE_GET_AND_INC (end
, start
, pointer_size
, finish
);
7121 error (_("Invalid range list entry type %d\n"), rlet
);
7122 rlet
= DW_RLE_end_of_list
;
7125 if (rlet
== DW_RLE_end_of_list
)
7127 if (rlet
== DW_RLE_base_address
)
7130 print_dwarf_vma (begin
+ base_address
, pointer_size
);
7131 print_dwarf_vma (end
+ base_address
, pointer_size
);
7134 fputs (_("(start == end)"), stdout
);
7135 else if (begin
> end
)
7136 fputs (_("(start > end)"), stdout
);
7143 display_debug_ranges (struct dwarf_section
*section
,
7144 void *file ATTRIBUTE_UNUSED
)
7146 unsigned char *start
= section
->start
;
7147 unsigned char *last_start
= start
;
7148 unsigned long bytes
= section
->size
;
7149 unsigned char *section_begin
= start
;
7150 unsigned char *finish
= start
+ bytes
;
7151 unsigned int num_range_list
, i
;
7152 struct range_entry
*range_entries
, *range_entry_fill
;
7153 int is_rnglists
= strstr (section
->name
, "debug_rnglists") != NULL
;
7154 /* Initialize it due to a false compiler warning. */
7155 unsigned char address_size
= 0;
7159 printf (_("\nThe %s section is empty.\n"), section
->name
);
7165 dwarf_vma initial_length
;
7166 unsigned int initial_length_size
;
7167 unsigned char segment_selector_size
;
7168 unsigned int offset_size
, offset_entry_count
;
7169 unsigned short version
;
7171 /* Get and check the length of the block. */
7172 SAFE_BYTE_GET_AND_INC (initial_length
, start
, 4, finish
);
7174 if (initial_length
== 0xffffffff)
7176 /* This section is 64-bit DWARF 3. */
7177 SAFE_BYTE_GET_AND_INC (initial_length
, start
, 8, finish
);
7179 initial_length_size
= 12;
7184 initial_length_size
= 4;
7187 if (initial_length
+ initial_length_size
> section
->size
)
7189 /* If the length field has a relocation against it, then we should
7190 not complain if it is inaccurate (and probably negative).
7191 It is copied from .debug_line handling code. */
7192 if (reloc_at (section
, (start
- section
->start
) - offset_size
))
7194 initial_length
= (finish
- start
) - initial_length_size
;
7198 warn (_("The length field (0x%lx) in the debug_rnglists header is wrong - the section is too small\n"),
7199 (long) initial_length
);
7204 /* Get and check the version number. */
7205 SAFE_BYTE_GET_AND_INC (version
, start
, 2, finish
);
7209 warn (_("Only DWARF version 5 debug_rnglists info "
7210 "is currently supported.\n"));
7214 SAFE_BYTE_GET_AND_INC (address_size
, start
, 1, finish
);
7216 SAFE_BYTE_GET_AND_INC (segment_selector_size
, start
, 1, finish
);
7217 if (segment_selector_size
!= 0)
7219 warn (_("The %s section contains "
7220 "unsupported segment selector size: %d.\n"),
7221 section
->name
, segment_selector_size
);
7225 SAFE_BYTE_GET_AND_INC (offset_entry_count
, start
, 4, finish
);
7226 if (offset_entry_count
!= 0)
7228 warn (_("The %s section contains "
7229 "unsupported offset entry count: %u.\n"),
7230 section
->name
, offset_entry_count
);
7235 if (load_debug_info (file
) == 0)
7237 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
7243 for (i
= 0; i
< num_debug_info_entries
; i
++)
7244 num_range_list
+= debug_information
[i
].num_range_lists
;
7246 if (num_range_list
== 0)
7248 /* This can happen when the file was compiled with -gsplit-debug
7249 which removes references to range lists from the primary .o file. */
7250 printf (_("No range lists in .debug_info section.\n"));
7254 range_entries
= (struct range_entry
*)
7255 xmalloc (sizeof (*range_entries
) * num_range_list
);
7256 range_entry_fill
= range_entries
;
7258 for (i
= 0; i
< num_debug_info_entries
; i
++)
7260 debug_info
*debug_info_p
= &debug_information
[i
];
7263 for (j
= 0; j
< debug_info_p
->num_range_lists
; j
++)
7265 range_entry_fill
->ranges_offset
= debug_info_p
->range_lists
[j
];
7266 range_entry_fill
->debug_info_p
= debug_info_p
;
7271 qsort (range_entries
, num_range_list
, sizeof (*range_entries
),
7272 range_entry_compar
);
7274 if (dwarf_check
!= 0 && range_entries
[0].ranges_offset
!= 0)
7275 warn (_("Range lists in %s section start at 0x%lx\n"),
7276 section
->name
, (unsigned long) range_entries
[0].ranges_offset
);
7278 introduce (section
, FALSE
);
7280 printf (_(" Offset Begin End\n"));
7282 for (i
= 0; i
< num_range_list
; i
++)
7284 struct range_entry
*range_entry
= &range_entries
[i
];
7285 debug_info
*debug_info_p
= range_entry
->debug_info_p
;
7286 unsigned int pointer_size
;
7288 unsigned char *next
;
7289 dwarf_vma base_address
;
7291 pointer_size
= (is_rnglists
? address_size
: debug_info_p
->pointer_size
);
7292 offset
= range_entry
->ranges_offset
;
7293 next
= section_begin
+ offset
;
7294 base_address
= debug_info_p
->base_address
;
7296 /* PR 17512: file: 001-101485-0.001:0.1. */
7297 if (pointer_size
< 2 || pointer_size
> 8)
7299 warn (_("Corrupt pointer size (%d) in debug entry at offset %8.8lx\n"),
7300 pointer_size
, (unsigned long) offset
);
7304 if (next
< section_begin
|| next
>= finish
)
7306 warn (_("Corrupt offset (%#8.8lx) in range entry %u\n"),
7307 (unsigned long) offset
, i
);
7311 if (dwarf_check
!= 0 && i
> 0)
7314 warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"),
7315 (unsigned long) (start
- section_begin
),
7316 (unsigned long) (next
- section_begin
), section
->name
);
7317 else if (start
> next
)
7319 if (next
== last_start
)
7321 warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"),
7322 (unsigned long) (start
- section_begin
),
7323 (unsigned long) (next
- section_begin
), section
->name
);
7330 (is_rnglists
? display_debug_rnglists_list
: display_debug_ranges_list
)
7331 (start
, finish
, pointer_size
, offset
, base_address
);
7335 free (range_entries
);
7340 typedef struct Frame_Chunk
7342 struct Frame_Chunk
*next
;
7343 unsigned char *chunk_start
;
7345 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
7346 short int *col_type
;
7349 unsigned int code_factor
;
7353 unsigned int cfa_reg
;
7354 dwarf_vma cfa_offset
;
7356 unsigned char fde_encoding
;
7357 unsigned char cfa_exp
;
7358 unsigned char ptr_size
;
7359 unsigned char segment_size
;
7363 static const char *const *dwarf_regnames
;
7364 static unsigned int dwarf_regnames_count
;
7366 /* A marker for a col_type that means this column was never referenced
7367 in the frame info. */
7368 #define DW_CFA_unreferenced (-1)
7370 /* Return 0 if no more space is needed, 1 if more space is needed,
7371 -1 for invalid reg. */
7374 frame_need_space (Frame_Chunk
*fc
, unsigned int reg
)
7376 unsigned int prev
= fc
->ncols
;
7378 if (reg
< (unsigned int) fc
->ncols
)
7381 if (dwarf_regnames_count
7382 && reg
> dwarf_regnames_count
)
7385 fc
->ncols
= reg
+ 1;
7386 /* PR 17512: file: 10450-2643-0.004.
7387 If reg == -1 then this can happen... */
7391 /* PR 17512: file: 2844a11d. */
7392 if (fc
->ncols
> 1024)
7394 error (_("Unfeasibly large register number: %u\n"), reg
);
7396 /* FIXME: 1024 is an arbitrary limit. Increase it if
7397 we ever encounter a valid binary that exceeds it. */
7401 fc
->col_type
= (short int *) xcrealloc (fc
->col_type
, fc
->ncols
,
7402 sizeof (short int));
7403 fc
->col_offset
= (int *) xcrealloc (fc
->col_offset
, fc
->ncols
, sizeof (int));
7404 /* PR 17512: file:002-10025-0.005. */
7405 if (fc
->col_type
== NULL
|| fc
->col_offset
== NULL
)
7407 error (_("Out of memory allocating %u columns in dwarf frame arrays\n"),
7413 while (prev
< fc
->ncols
)
7415 fc
->col_type
[prev
] = DW_CFA_unreferenced
;
7416 fc
->col_offset
[prev
] = 0;
7422 static const char *const dwarf_regnames_i386
[] =
7424 "eax", "ecx", "edx", "ebx", /* 0 - 3 */
7425 "esp", "ebp", "esi", "edi", /* 4 - 7 */
7426 "eip", "eflags", NULL
, /* 8 - 10 */
7427 "st0", "st1", "st2", "st3", /* 11 - 14 */
7428 "st4", "st5", "st6", "st7", /* 15 - 18 */
7429 NULL
, NULL
, /* 19 - 20 */
7430 "xmm0", "xmm1", "xmm2", "xmm3", /* 21 - 24 */
7431 "xmm4", "xmm5", "xmm6", "xmm7", /* 25 - 28 */
7432 "mm0", "mm1", "mm2", "mm3", /* 29 - 32 */
7433 "mm4", "mm5", "mm6", "mm7", /* 33 - 36 */
7434 "fcw", "fsw", "mxcsr", /* 37 - 39 */
7435 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
, /* 40 - 47 */
7436 "tr", "ldtr", /* 48 - 49 */
7437 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 50 - 57 */
7438 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 58 - 65 */
7439 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 66 - 73 */
7440 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 74 - 81 */
7441 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 82 - 89 */
7442 NULL
, NULL
, NULL
, /* 90 - 92 */
7443 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7" /* 93 - 100 */
7446 static const char *const dwarf_regnames_iamcu
[] =
7448 "eax", "ecx", "edx", "ebx", /* 0 - 3 */
7449 "esp", "ebp", "esi", "edi", /* 4 - 7 */
7450 "eip", "eflags", NULL
, /* 8 - 10 */
7451 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 11 - 18 */
7452 NULL
, NULL
, /* 19 - 20 */
7453 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 21 - 28 */
7454 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 29 - 36 */
7455 NULL
, NULL
, NULL
, /* 37 - 39 */
7456 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
, /* 40 - 47 */
7457 "tr", "ldtr", /* 48 - 49 */
7458 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 50 - 57 */
7459 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 58 - 65 */
7460 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 66 - 73 */
7461 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 74 - 81 */
7462 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 82 - 89 */
7463 NULL
, NULL
, NULL
, /* 90 - 92 */
7464 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
/* 93 - 100 */
7468 init_dwarf_regnames_i386 (void)
7470 dwarf_regnames
= dwarf_regnames_i386
;
7471 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_i386
);
7475 init_dwarf_regnames_iamcu (void)
7477 dwarf_regnames
= dwarf_regnames_iamcu
;
7478 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_iamcu
);
7481 static const char *const dwarf_regnames_x86_64
[] =
7483 "rax", "rdx", "rcx", "rbx",
7484 "rsi", "rdi", "rbp", "rsp",
7485 "r8", "r9", "r10", "r11",
7486 "r12", "r13", "r14", "r15",
7488 "xmm0", "xmm1", "xmm2", "xmm3",
7489 "xmm4", "xmm5", "xmm6", "xmm7",
7490 "xmm8", "xmm9", "xmm10", "xmm11",
7491 "xmm12", "xmm13", "xmm14", "xmm15",
7492 "st0", "st1", "st2", "st3",
7493 "st4", "st5", "st6", "st7",
7494 "mm0", "mm1", "mm2", "mm3",
7495 "mm4", "mm5", "mm6", "mm7",
7497 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
,
7498 "fs.base", "gs.base", NULL
, NULL
,
7500 "mxcsr", "fcw", "fsw",
7501 "xmm16", "xmm17", "xmm18", "xmm19",
7502 "xmm20", "xmm21", "xmm22", "xmm23",
7503 "xmm24", "xmm25", "xmm26", "xmm27",
7504 "xmm28", "xmm29", "xmm30", "xmm31",
7505 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 83 - 90 */
7506 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 91 - 98 */
7507 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 99 - 106 */
7508 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 107 - 114 */
7509 NULL
, NULL
, NULL
, /* 115 - 117 */
7510 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7"
7514 init_dwarf_regnames_x86_64 (void)
7516 dwarf_regnames
= dwarf_regnames_x86_64
;
7517 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_x86_64
);
7520 static const char *const dwarf_regnames_aarch64
[] =
7522 "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7",
7523 "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15",
7524 "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23",
7525 "x24", "x25", "x26", "x27", "x28", "x29", "x30", "sp",
7526 NULL
, "elr", NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
7527 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, "vg", "ffr",
7528 "p0", "p1", "p2", "p3", "p4", "p5", "p6", "p7",
7529 "p8", "p9", "p10", "p11", "p12", "p13", "p14", "p15",
7530 "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7",
7531 "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15",
7532 "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23",
7533 "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31",
7534 "z0", "z1", "z2", "z3", "z4", "z5", "z6", "z7",
7535 "z8", "z9", "z10", "z11", "z12", "z13", "z14", "z15",
7536 "z16", "z17", "z18", "z19", "z20", "z21", "z22", "z23",
7537 "z24", "z25", "z26", "z27", "z28", "z29", "z30", "z31",
7541 init_dwarf_regnames_aarch64 (void)
7543 dwarf_regnames
= dwarf_regnames_aarch64
;
7544 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_aarch64
);
7547 static const char *const dwarf_regnames_s390
[] =
7549 /* Avoid saying "r5 (r5)", so omit the names of r0-r15. */
7550 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
7551 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
7552 "f0", "f2", "f4", "f6", "f1", "f3", "f5", "f7",
7553 "f8", "f10", "f12", "f14", "f9", "f11", "f13", "f15",
7554 "cr0", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7",
7555 "cr8", "cr9", "cr10", "cr11", "cr12", "cr13", "cr14", "cr15",
7556 "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7",
7557 "a8", "a9", "a10", "a11", "a12", "a13", "a14", "a15",
7560 "v16", "v18", "v20", "v22", "v17", "v19", "v21", "v23",
7561 "v24", "v26", "v28", "v30", "v25", "v27", "v29", "v31",
7565 init_dwarf_regnames_s390 (void)
7567 dwarf_regnames
= dwarf_regnames_s390
;
7568 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_s390
);
7571 static const char *const dwarf_regnames_riscv
[] =
7573 "zero", "ra", "sp", "gp", "tp", "t0", "t1", "t2", /* 0 - 7 */
7574 "s0", "s1", "a0", "a1", "a2", "a3", "a4", "a5", /* 8 - 15 */
7575 "a6", "a7", "s2", "s3", "s4", "s5", "s6", "s7", /* 16 - 23 */
7576 "s8", "s9", "s10", "s11", "t3", "t4", "t5", "t6", /* 24 - 31 */
7577 "ft0", "ft1", "ft2", "ft3", "ft4", "ft5", "ft6", "ft7", /* 32 - 39 */
7578 "fs0", "fs1", /* 40 - 41 */
7579 "fa0", "fa1", "fa2", "fa3", "fa4", "fa5", "fa6", "fa7", /* 42 - 49 */
7580 "fs2", "fs3", "fs4", "fs5", "fs6", "fs7", "fs8", "fs9", /* 50 - 57 */
7581 "fs10", "fs11", /* 58 - 59 */
7582 "ft8", "ft9", "ft10", "ft11" /* 60 - 63 */
7586 init_dwarf_regnames_riscv (void)
7588 dwarf_regnames
= dwarf_regnames_riscv
;
7589 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_riscv
);
7593 init_dwarf_regnames (unsigned int e_machine
)
7598 init_dwarf_regnames_i386 ();
7602 init_dwarf_regnames_iamcu ();
7608 init_dwarf_regnames_x86_64 ();
7612 init_dwarf_regnames_aarch64 ();
7616 init_dwarf_regnames_s390 ();
7620 init_dwarf_regnames_riscv ();
7629 regname (unsigned int regno
, int row
)
7631 static char reg
[64];
7634 && regno
< dwarf_regnames_count
7635 && dwarf_regnames
[regno
] != NULL
)
7638 return dwarf_regnames
[regno
];
7639 snprintf (reg
, sizeof (reg
), "r%d (%s)", regno
,
7640 dwarf_regnames
[regno
]);
7643 snprintf (reg
, sizeof (reg
), "r%d", regno
);
7648 frame_display_row (Frame_Chunk
*fc
, int *need_col_headers
, unsigned int *max_regs
)
7653 if (*max_regs
!= fc
->ncols
)
7654 *max_regs
= fc
->ncols
;
7656 if (*need_col_headers
)
7658 static const char *sloc
= " LOC";
7660 *need_col_headers
= 0;
7662 printf ("%-*s CFA ", eh_addr_size
* 2, sloc
);
7664 for (r
= 0; r
< *max_regs
; r
++)
7665 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
7670 printf ("%-5s ", regname (r
, 1));
7676 print_dwarf_vma (fc
->pc_begin
, eh_addr_size
);
7678 strcpy (tmp
, "exp");
7680 sprintf (tmp
, "%s%+d", regname (fc
->cfa_reg
, 1), (int) fc
->cfa_offset
);
7681 printf ("%-8s ", tmp
);
7683 for (r
= 0; r
< fc
->ncols
; r
++)
7685 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
7687 switch (fc
->col_type
[r
])
7689 case DW_CFA_undefined
:
7692 case DW_CFA_same_value
:
7696 sprintf (tmp
, "c%+d", fc
->col_offset
[r
]);
7698 case DW_CFA_val_offset
:
7699 sprintf (tmp
, "v%+d", fc
->col_offset
[r
]);
7701 case DW_CFA_register
:
7702 sprintf (tmp
, "%s", regname (fc
->col_offset
[r
], 0));
7704 case DW_CFA_expression
:
7705 strcpy (tmp
, "exp");
7707 case DW_CFA_val_expression
:
7708 strcpy (tmp
, "vexp");
7711 strcpy (tmp
, "n/a");
7714 printf ("%-5s ", tmp
);
7720 #define GET(VAR, N) SAFE_BYTE_GET_AND_INC (VAR, start, N, end)
7722 static unsigned char *
7723 read_cie (unsigned char *start
, unsigned char *end
,
7724 Frame_Chunk
**p_cie
, int *p_version
,
7725 bfd_size_type
*p_aug_len
, unsigned char **p_aug
)
7729 unsigned int length_return
;
7730 unsigned char *augmentation_data
= NULL
;
7731 bfd_size_type augmentation_data_len
= 0;
7734 /* PR 17512: file: 001-228113-0.004. */
7738 fc
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
7739 memset (fc
, 0, sizeof (Frame_Chunk
));
7741 fc
->col_type
= (short int *) xmalloc (sizeof (short int));
7742 fc
->col_offset
= (int *) xmalloc (sizeof (int));
7746 fc
->augmentation
= (char *) start
;
7747 /* PR 17512: file: 001-228113-0.004.
7748 Skip past augmentation name, but avoid running off the end of the data. */
7750 if (* start
++ == '\0')
7754 warn (_("No terminator for augmentation name\n"));
7758 if (strcmp (fc
->augmentation
, "eh") == 0)
7759 start
+= eh_addr_size
;
7763 GET (fc
->ptr_size
, 1);
7764 if (fc
->ptr_size
< 1 || fc
->ptr_size
> 8)
7766 warn (_("Invalid pointer size (%d) in CIE data\n"), fc
->ptr_size
);
7770 GET (fc
->segment_size
, 1);
7771 /* PR 17512: file: e99d2804. */
7772 if (fc
->segment_size
> 8 || fc
->segment_size
+ fc
->ptr_size
> 8)
7774 warn (_("Invalid segment size (%d) in CIE data\n"), fc
->segment_size
);
7778 eh_addr_size
= fc
->ptr_size
;
7782 fc
->ptr_size
= eh_addr_size
;
7783 fc
->segment_size
= 0;
7786 READ_ULEB (fc
->code_factor
);
7787 READ_SLEB (fc
->data_factor
);
7798 if (fc
->augmentation
[0] == 'z')
7800 READ_ULEB (augmentation_data_len
);
7801 augmentation_data
= start
;
7802 /* PR 17512: file: 11042-2589-0.004. */
7803 if (augmentation_data_len
> (bfd_size_type
) (end
- start
))
7805 warn (_("Augmentation data too long: 0x%s, expected at most %#lx\n"),
7806 dwarf_vmatoa ("x", augmentation_data_len
),
7807 (unsigned long) (end
- start
));
7810 start
+= augmentation_data_len
;
7813 if (augmentation_data_len
)
7817 unsigned char *qend
;
7819 p
= (unsigned char *) fc
->augmentation
+ 1;
7820 q
= augmentation_data
;
7821 qend
= q
+ augmentation_data_len
;
7823 while (p
< end
&& q
< qend
)
7828 q
+= 1 + size_of_encoded_value (*q
);
7830 fc
->fde_encoding
= *q
++;
7839 /* Note - it is OK if this loop terminates with q < qend.
7840 Padding may have been inserted to align the end of the CIE. */
7845 *p_version
= version
;
7848 *p_aug_len
= augmentation_data_len
;
7849 *p_aug
= augmentation_data
;
7854 free (fc
->col_offset
);
7855 free (fc
->col_type
);
7860 /* Prints out the contents on the DATA array formatted as unsigned bytes.
7861 If do_wide is not enabled, then formats the output to fit into 80 columns.
7862 PRINTED contains the number of characters already written to the current
7866 display_data (bfd_size_type printed
,
7867 const unsigned char * data
,
7868 const bfd_size_type len
)
7870 if (do_wide
|| len
< ((80 - printed
) / 3))
7871 for (printed
= 0; printed
< len
; ++printed
)
7872 printf (" %02x", data
[printed
]);
7875 for (printed
= 0; printed
< len
; ++printed
)
7877 if (printed
% (80 / 3) == 0)
7879 printf (" %02x", data
[printed
]);
7884 /* Prints out the contents on the augmentation data array.
7885 If do_wide is not enabled, then formats the output to fit into 80 columns. */
7888 display_augmentation_data (const unsigned char * data
, const bfd_size_type len
)
7892 i
= printf (_(" Augmentation data: "));
7893 display_data (i
, data
, len
);
7897 display_debug_frames (struct dwarf_section
*section
,
7898 void *file ATTRIBUTE_UNUSED
)
7900 unsigned char *start
= section
->start
;
7901 unsigned char *end
= start
+ section
->size
;
7902 unsigned char *section_start
= start
;
7903 Frame_Chunk
*chunks
= NULL
, *forward_refs
= NULL
;
7904 Frame_Chunk
*remembered_state
= NULL
;
7906 bfd_boolean is_eh
= strcmp (section
->name
, ".eh_frame") == 0;
7907 unsigned int length_return
;
7908 unsigned int max_regs
= 0;
7909 const char *bad_reg
= _("bad register: ");
7910 unsigned int saved_eh_addr_size
= eh_addr_size
;
7912 introduce (section
, FALSE
);
7916 unsigned char *saved_start
;
7917 unsigned char *block_end
;
7922 int need_col_headers
= 1;
7923 unsigned char *augmentation_data
= NULL
;
7924 bfd_size_type augmentation_data_len
= 0;
7925 unsigned int encoded_ptr_size
= saved_eh_addr_size
;
7926 unsigned int offset_size
;
7927 unsigned int initial_length_size
;
7928 bfd_boolean all_nops
;
7930 saved_start
= start
;
7932 SAFE_BYTE_GET_AND_INC (length
, start
, 4, end
);
7936 printf ("\n%08lx ZERO terminator\n\n",
7937 (unsigned long)(saved_start
- section_start
));
7938 /* Skip any zero terminators that directly follow.
7939 A corrupt section size could have loaded a whole
7940 slew of zero filled memory bytes. eg
7941 PR 17512: file: 070-19381-0.004. */
7942 while (start
< end
&& * start
== 0)
7947 if (length
== 0xffffffff)
7949 SAFE_BYTE_GET_AND_INC (length
, start
, 8, end
);
7951 initial_length_size
= 12;
7956 initial_length_size
= 4;
7959 block_end
= saved_start
+ length
+ initial_length_size
;
7960 if (block_end
> end
|| block_end
< start
)
7962 warn ("Invalid length 0x%s in FDE at %#08lx\n",
7963 dwarf_vmatoa_1 (NULL
, length
, offset_size
),
7964 (unsigned long) (saved_start
- section_start
));
7968 SAFE_BYTE_GET_AND_INC (cie_id
, start
, offset_size
, end
);
7970 if (is_eh
? (cie_id
== 0) : ((offset_size
== 4 && cie_id
== DW_CIE_ID
)
7971 || (offset_size
== 8 && cie_id
== DW64_CIE_ID
)))
7976 start
= read_cie (start
, end
, &cie
, &version
,
7977 &augmentation_data_len
, &augmentation_data
);
7978 /* PR 17512: file: 027-135133-0.005. */
7985 fc
->chunk_start
= saved_start
;
7986 mreg
= max_regs
> 0 ? max_regs
- 1 : 0;
7989 if (frame_need_space (fc
, mreg
) < 0)
7991 if (fc
->fde_encoding
)
7992 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
7994 printf ("\n%08lx ", (unsigned long) (saved_start
- section_start
));
7995 print_dwarf_vma (length
, fc
->ptr_size
);
7996 print_dwarf_vma (cie_id
, offset_size
);
7998 if (do_debug_frames_interp
)
8000 printf ("CIE \"%s\" cf=%d df=%d ra=%d\n", fc
->augmentation
,
8001 fc
->code_factor
, fc
->data_factor
, fc
->ra
);
8006 printf (" Version: %d\n", version
);
8007 printf (" Augmentation: \"%s\"\n", fc
->augmentation
);
8010 printf (" Pointer Size: %u\n", fc
->ptr_size
);
8011 printf (" Segment Size: %u\n", fc
->segment_size
);
8013 printf (" Code alignment factor: %u\n", fc
->code_factor
);
8014 printf (" Data alignment factor: %d\n", fc
->data_factor
);
8015 printf (" Return address column: %d\n", fc
->ra
);
8017 if (augmentation_data_len
)
8018 display_augmentation_data (augmentation_data
, augmentation_data_len
);
8025 unsigned char *look_for
;
8026 static Frame_Chunk fde_fc
;
8027 unsigned long segment_selector
;
8031 dwarf_vma sign
= (dwarf_vma
) 1 << (offset_size
* 8 - 1);
8032 look_for
= start
- 4 - ((cie_id
^ sign
) - sign
);
8035 look_for
= section_start
+ cie_id
;
8037 if (look_for
<= saved_start
)
8039 for (cie
= chunks
; cie
; cie
= cie
->next
)
8040 if (cie
->chunk_start
== look_for
)
8045 for (cie
= forward_refs
; cie
; cie
= cie
->next
)
8046 if (cie
->chunk_start
== look_for
)
8050 unsigned int off_size
;
8051 unsigned char *cie_scan
;
8053 cie_scan
= look_for
;
8055 SAFE_BYTE_GET_AND_INC (length
, cie_scan
, 4, end
);
8056 if (length
== 0xffffffff)
8058 SAFE_BYTE_GET_AND_INC (length
, cie_scan
, 8, end
);
8065 SAFE_BYTE_GET_AND_INC (c_id
, cie_scan
, off_size
, end
);
8068 : ((off_size
== 4 && c_id
== DW_CIE_ID
)
8069 || (off_size
== 8 && c_id
== DW64_CIE_ID
)))
8074 read_cie (cie_scan
, end
, &cie
, &version
,
8075 &augmentation_data_len
, &augmentation_data
);
8076 /* PR 17512: file: 3450-2098-0.004. */
8079 warn (_("Failed to read CIE information\n"));
8082 cie
->next
= forward_refs
;
8084 cie
->chunk_start
= look_for
;
8085 mreg
= max_regs
> 0 ? max_regs
- 1 : 0;
8088 if (frame_need_space (cie
, mreg
) < 0)
8090 warn (_("Invalid max register\n"));
8093 if (cie
->fde_encoding
)
8095 = size_of_encoded_value (cie
->fde_encoding
);
8102 memset (fc
, 0, sizeof (Frame_Chunk
));
8106 warn ("Invalid CIE pointer 0x%s in FDE at %#08lx\n",
8107 dwarf_vmatoa_1 (NULL
, cie_id
, offset_size
),
8108 (unsigned long) (saved_start
- section_start
));
8110 fc
->col_type
= (short int *) xmalloc (sizeof (short int));
8111 fc
->col_offset
= (int *) xmalloc (sizeof (int));
8112 if (frame_need_space (fc
, max_regs
> 0 ? max_regs
- 1 : 0) < 0)
8114 warn (_("Invalid max register\n"));
8118 fc
->augmentation
= "";
8119 fc
->fde_encoding
= 0;
8120 fc
->ptr_size
= eh_addr_size
;
8121 fc
->segment_size
= 0;
8125 fc
->ncols
= cie
->ncols
;
8126 fc
->col_type
= (short int *) xcmalloc (fc
->ncols
, sizeof (short int));
8127 fc
->col_offset
= (int *) xcmalloc (fc
->ncols
, sizeof (int));
8128 memcpy (fc
->col_type
, cie
->col_type
, fc
->ncols
* sizeof (short int));
8129 memcpy (fc
->col_offset
, cie
->col_offset
, fc
->ncols
* sizeof (int));
8130 fc
->augmentation
= cie
->augmentation
;
8131 fc
->ptr_size
= cie
->ptr_size
;
8132 eh_addr_size
= cie
->ptr_size
;
8133 fc
->segment_size
= cie
->segment_size
;
8134 fc
->code_factor
= cie
->code_factor
;
8135 fc
->data_factor
= cie
->data_factor
;
8136 fc
->cfa_reg
= cie
->cfa_reg
;
8137 fc
->cfa_offset
= cie
->cfa_offset
;
8139 if (frame_need_space (fc
, max_regs
> 0 ? max_regs
- 1: 0) < 0)
8141 warn (_("Invalid max register\n"));
8144 fc
->fde_encoding
= cie
->fde_encoding
;
8147 if (fc
->fde_encoding
)
8148 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
8150 segment_selector
= 0;
8151 if (fc
->segment_size
)
8153 if (fc
->segment_size
> sizeof (segment_selector
))
8155 /* PR 17512: file: 9e196b3e. */
8156 warn (_("Probably corrupt segment size: %d - using 4 instead\n"), fc
->segment_size
);
8157 fc
->segment_size
= 4;
8159 SAFE_BYTE_GET_AND_INC (segment_selector
, start
, fc
->segment_size
, end
);
8162 fc
->pc_begin
= get_encoded_value (&start
, fc
->fde_encoding
, section
, end
);
8164 /* FIXME: It appears that sometimes the final pc_range value is
8165 encoded in less than encoded_ptr_size bytes. See the x86_64
8166 run of the "objcopy on compressed debug sections" test for an
8168 SAFE_BYTE_GET_AND_INC (fc
->pc_range
, start
, encoded_ptr_size
, end
);
8170 if (cie
->augmentation
[0] == 'z')
8172 READ_ULEB (augmentation_data_len
);
8173 augmentation_data
= start
;
8174 /* PR 17512 file: 722-8446-0.004 and PR 22386. */
8175 if (augmentation_data_len
> (bfd_size_type
) (end
- start
))
8177 warn (_("Augmentation data too long: 0x%s, "
8178 "expected at most %#lx\n"),
8179 dwarf_vmatoa ("x", augmentation_data_len
),
8180 (unsigned long) (end
- start
));
8182 augmentation_data
= NULL
;
8183 augmentation_data_len
= 0;
8185 start
+= augmentation_data_len
;
8188 printf ("\n%08lx %s %s FDE cie=%08lx pc=",
8189 (unsigned long)(saved_start
- section_start
),
8190 dwarf_vmatoa_1 (NULL
, length
, fc
->ptr_size
),
8191 dwarf_vmatoa_1 (NULL
, cie_id
, offset_size
),
8192 (unsigned long)(cie
->chunk_start
- section_start
));
8194 if (fc
->segment_size
)
8195 printf ("%04lx:", segment_selector
);
8198 dwarf_vmatoa_1 (NULL
, fc
->pc_begin
, fc
->ptr_size
),
8199 dwarf_vmatoa_1 (NULL
, fc
->pc_begin
+ fc
->pc_range
, fc
->ptr_size
));
8201 if (! do_debug_frames_interp
&& augmentation_data_len
)
8203 display_augmentation_data (augmentation_data
, augmentation_data_len
);
8208 /* At this point, fc is the current chunk, cie (if any) is set, and
8209 we're about to interpret instructions for the chunk. */
8210 /* ??? At present we need to do this always, since this sizes the
8211 fc->col_type and fc->col_offset arrays, which we write into always.
8212 We should probably split the interpreted and non-interpreted bits
8213 into two different routines, since there's so much that doesn't
8214 really overlap between them. */
8215 if (1 || do_debug_frames_interp
)
8217 /* Start by making a pass over the chunk, allocating storage
8218 and taking note of what registers are used. */
8219 unsigned char *tmp
= start
;
8221 while (start
< block_end
)
8223 unsigned int reg
, op
, opa
;
8225 unsigned char * new_start
;
8232 /* Warning: if you add any more cases to this switch, be
8233 sure to add them to the corresponding switch below. */
8236 case DW_CFA_advance_loc
:
8240 if (frame_need_space (fc
, opa
) >= 0)
8241 fc
->col_type
[opa
] = DW_CFA_undefined
;
8243 case DW_CFA_restore
:
8244 if (frame_need_space (fc
, opa
) >= 0)
8245 fc
->col_type
[opa
] = DW_CFA_undefined
;
8247 case DW_CFA_set_loc
:
8248 start
+= encoded_ptr_size
;
8250 case DW_CFA_advance_loc1
:
8253 case DW_CFA_advance_loc2
:
8256 case DW_CFA_advance_loc4
:
8259 case DW_CFA_offset_extended
:
8260 case DW_CFA_val_offset
:
8263 if (frame_need_space (fc
, reg
) >= 0)
8264 fc
->col_type
[reg
] = DW_CFA_undefined
;
8266 case DW_CFA_restore_extended
:
8268 if (frame_need_space (fc
, reg
) >= 0)
8269 fc
->col_type
[reg
] = DW_CFA_undefined
;
8271 case DW_CFA_undefined
:
8273 if (frame_need_space (fc
, reg
) >= 0)
8274 fc
->col_type
[reg
] = DW_CFA_undefined
;
8276 case DW_CFA_same_value
:
8278 if (frame_need_space (fc
, reg
) >= 0)
8279 fc
->col_type
[reg
] = DW_CFA_undefined
;
8281 case DW_CFA_register
:
8284 if (frame_need_space (fc
, reg
) >= 0)
8285 fc
->col_type
[reg
] = DW_CFA_undefined
;
8287 case DW_CFA_def_cfa
:
8291 case DW_CFA_def_cfa_register
:
8294 case DW_CFA_def_cfa_offset
:
8297 case DW_CFA_def_cfa_expression
:
8299 new_start
= start
+ temp
;
8300 if (new_start
< start
)
8302 warn (_("Corrupt CFA_def expression value: %lu\n"), temp
);
8308 case DW_CFA_expression
:
8309 case DW_CFA_val_expression
:
8312 new_start
= start
+ temp
;
8313 if (new_start
< start
)
8315 /* PR 17512: file:306-192417-0.005. */
8316 warn (_("Corrupt CFA expression value: %lu\n"), temp
);
8321 if (frame_need_space (fc
, reg
) >= 0)
8322 fc
->col_type
[reg
] = DW_CFA_undefined
;
8324 case DW_CFA_offset_extended_sf
:
8325 case DW_CFA_val_offset_sf
:
8328 if (frame_need_space (fc
, reg
) >= 0)
8329 fc
->col_type
[reg
] = DW_CFA_undefined
;
8331 case DW_CFA_def_cfa_sf
:
8335 case DW_CFA_def_cfa_offset_sf
:
8338 case DW_CFA_MIPS_advance_loc8
:
8341 case DW_CFA_GNU_args_size
:
8344 case DW_CFA_GNU_negative_offset_extended
:
8347 if (frame_need_space (fc
, reg
) >= 0)
8348 fc
->col_type
[reg
] = DW_CFA_undefined
;
8359 /* Now we know what registers are used, make a second pass over
8360 the chunk, this time actually printing out the info. */
8362 while (start
< block_end
)
8364 unsigned char * tmp
;
8366 unsigned long ul
, roffs
;
8367 /* Note: It is tempting to use an unsigned long for 'reg' but there
8368 are various functions, notably frame_space_needed() that assume that
8369 reg is an unsigned int. */
8374 const char *reg_prefix
= "";
8381 /* Make a note if something other than DW_CFA_nop happens. */
8382 if (op
!= DW_CFA_nop
)
8385 /* Warning: if you add any more cases to this switch, be
8386 sure to add them to the corresponding switch above. */
8389 case DW_CFA_advance_loc
:
8390 if (do_debug_frames_interp
)
8391 frame_display_row (fc
, &need_col_headers
, &max_regs
);
8393 printf (" DW_CFA_advance_loc: %d to %s\n",
8394 opa
* fc
->code_factor
,
8395 dwarf_vmatoa_1 (NULL
,
8396 fc
->pc_begin
+ opa
* fc
->code_factor
,
8398 fc
->pc_begin
+= opa
* fc
->code_factor
;
8403 if (opa
>= (unsigned int) fc
->ncols
)
8404 reg_prefix
= bad_reg
;
8405 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
8406 printf (" DW_CFA_offset: %s%s at cfa%+ld\n",
8407 reg_prefix
, regname (opa
, 0),
8408 roffs
* fc
->data_factor
);
8409 if (*reg_prefix
== '\0')
8411 fc
->col_type
[opa
] = DW_CFA_offset
;
8412 fc
->col_offset
[opa
] = roffs
* fc
->data_factor
;
8416 case DW_CFA_restore
:
8417 if (opa
>= (unsigned int) fc
->ncols
)
8418 reg_prefix
= bad_reg
;
8419 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
8420 printf (" DW_CFA_restore: %s%s\n",
8421 reg_prefix
, regname (opa
, 0));
8422 if (*reg_prefix
!= '\0')
8425 if (opa
>= (unsigned int) cie
->ncols
8426 || (do_debug_frames_interp
8427 && cie
->col_type
[opa
] == DW_CFA_unreferenced
))
8429 fc
->col_type
[opa
] = DW_CFA_undefined
;
8430 fc
->col_offset
[opa
] = 0;
8434 fc
->col_type
[opa
] = cie
->col_type
[opa
];
8435 fc
->col_offset
[opa
] = cie
->col_offset
[opa
];
8439 case DW_CFA_set_loc
:
8440 vma
= get_encoded_value (&start
, fc
->fde_encoding
, section
, block_end
);
8441 if (do_debug_frames_interp
)
8442 frame_display_row (fc
, &need_col_headers
, &max_regs
);
8444 printf (" DW_CFA_set_loc: %s\n",
8445 dwarf_vmatoa_1 (NULL
, vma
, fc
->ptr_size
));
8449 case DW_CFA_advance_loc1
:
8450 SAFE_BYTE_GET_AND_INC (ofs
, start
, 1, end
);
8451 if (do_debug_frames_interp
)
8452 frame_display_row (fc
, &need_col_headers
, &max_regs
);
8454 printf (" DW_CFA_advance_loc1: %ld to %s\n",
8455 (unsigned long) (ofs
* fc
->code_factor
),
8456 dwarf_vmatoa_1 (NULL
,
8457 fc
->pc_begin
+ ofs
* fc
->code_factor
,
8459 fc
->pc_begin
+= ofs
* fc
->code_factor
;
8462 case DW_CFA_advance_loc2
:
8463 SAFE_BYTE_GET_AND_INC (ofs
, start
, 2, block_end
);
8464 if (do_debug_frames_interp
)
8465 frame_display_row (fc
, &need_col_headers
, &max_regs
);
8467 printf (" DW_CFA_advance_loc2: %ld to %s\n",
8468 (unsigned long) (ofs
* fc
->code_factor
),
8469 dwarf_vmatoa_1 (NULL
,
8470 fc
->pc_begin
+ ofs
* fc
->code_factor
,
8472 fc
->pc_begin
+= ofs
* fc
->code_factor
;
8475 case DW_CFA_advance_loc4
:
8476 SAFE_BYTE_GET_AND_INC (ofs
, start
, 4, block_end
);
8477 if (do_debug_frames_interp
)
8478 frame_display_row (fc
, &need_col_headers
, &max_regs
);
8480 printf (" DW_CFA_advance_loc4: %ld to %s\n",
8481 (unsigned long) (ofs
* fc
->code_factor
),
8482 dwarf_vmatoa_1 (NULL
,
8483 fc
->pc_begin
+ ofs
* fc
->code_factor
,
8485 fc
->pc_begin
+= ofs
* fc
->code_factor
;
8488 case DW_CFA_offset_extended
:
8491 if (reg
>= (unsigned int) fc
->ncols
)
8492 reg_prefix
= bad_reg
;
8493 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
8494 printf (" DW_CFA_offset_extended: %s%s at cfa%+ld\n",
8495 reg_prefix
, regname (reg
, 0),
8496 roffs
* fc
->data_factor
);
8497 if (*reg_prefix
== '\0')
8499 fc
->col_type
[reg
] = DW_CFA_offset
;
8500 fc
->col_offset
[reg
] = roffs
* fc
->data_factor
;
8504 case DW_CFA_val_offset
:
8507 if (reg
>= (unsigned int) fc
->ncols
)
8508 reg_prefix
= bad_reg
;
8509 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
8510 printf (" DW_CFA_val_offset: %s%s is cfa%+ld\n",
8511 reg_prefix
, regname (reg
, 0),
8512 roffs
* fc
->data_factor
);
8513 if (*reg_prefix
== '\0')
8515 fc
->col_type
[reg
] = DW_CFA_val_offset
;
8516 fc
->col_offset
[reg
] = roffs
* fc
->data_factor
;
8520 case DW_CFA_restore_extended
:
8522 if (reg
>= (unsigned int) fc
->ncols
)
8523 reg_prefix
= bad_reg
;
8524 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
8525 printf (" DW_CFA_restore_extended: %s%s\n",
8526 reg_prefix
, regname (reg
, 0));
8527 if (*reg_prefix
!= '\0')
8530 if (reg
>= (unsigned int) cie
->ncols
)
8532 fc
->col_type
[reg
] = DW_CFA_undefined
;
8533 fc
->col_offset
[reg
] = 0;
8537 fc
->col_type
[reg
] = cie
->col_type
[reg
];
8538 fc
->col_offset
[reg
] = cie
->col_offset
[reg
];
8542 case DW_CFA_undefined
:
8544 if (reg
>= (unsigned int) fc
->ncols
)
8545 reg_prefix
= bad_reg
;
8546 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
8547 printf (" DW_CFA_undefined: %s%s\n",
8548 reg_prefix
, regname (reg
, 0));
8549 if (*reg_prefix
== '\0')
8551 fc
->col_type
[reg
] = DW_CFA_undefined
;
8552 fc
->col_offset
[reg
] = 0;
8556 case DW_CFA_same_value
:
8558 if (reg
>= (unsigned int) fc
->ncols
)
8559 reg_prefix
= bad_reg
;
8560 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
8561 printf (" DW_CFA_same_value: %s%s\n",
8562 reg_prefix
, regname (reg
, 0));
8563 if (*reg_prefix
== '\0')
8565 fc
->col_type
[reg
] = DW_CFA_same_value
;
8566 fc
->col_offset
[reg
] = 0;
8570 case DW_CFA_register
:
8573 if (reg
>= (unsigned int) fc
->ncols
)
8574 reg_prefix
= bad_reg
;
8575 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
8577 printf (" DW_CFA_register: %s%s in ",
8578 reg_prefix
, regname (reg
, 0));
8579 puts (regname (roffs
, 0));
8581 if (*reg_prefix
== '\0')
8583 fc
->col_type
[reg
] = DW_CFA_register
;
8584 fc
->col_offset
[reg
] = roffs
;
8588 case DW_CFA_remember_state
:
8589 if (! do_debug_frames_interp
)
8590 printf (" DW_CFA_remember_state\n");
8591 rs
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
8592 rs
->cfa_offset
= fc
->cfa_offset
;
8593 rs
->cfa_reg
= fc
->cfa_reg
;
8595 rs
->cfa_exp
= fc
->cfa_exp
;
8596 rs
->ncols
= fc
->ncols
;
8597 rs
->col_type
= (short int *) xcmalloc (rs
->ncols
,
8598 sizeof (* rs
->col_type
));
8599 rs
->col_offset
= (int *) xcmalloc (rs
->ncols
, sizeof (* rs
->col_offset
));
8600 memcpy (rs
->col_type
, fc
->col_type
, rs
->ncols
* sizeof (* fc
->col_type
));
8601 memcpy (rs
->col_offset
, fc
->col_offset
, rs
->ncols
* sizeof (* fc
->col_offset
));
8602 rs
->next
= remembered_state
;
8603 remembered_state
= rs
;
8606 case DW_CFA_restore_state
:
8607 if (! do_debug_frames_interp
)
8608 printf (" DW_CFA_restore_state\n");
8609 rs
= remembered_state
;
8612 remembered_state
= rs
->next
;
8613 fc
->cfa_offset
= rs
->cfa_offset
;
8614 fc
->cfa_reg
= rs
->cfa_reg
;
8616 fc
->cfa_exp
= rs
->cfa_exp
;
8617 if (frame_need_space (fc
, rs
->ncols
- 1) < 0)
8619 warn (_("Invalid column number in saved frame state\n"));
8623 memcpy (fc
->col_type
, rs
->col_type
, rs
->ncols
* sizeof (* rs
->col_type
));
8624 memcpy (fc
->col_offset
, rs
->col_offset
,
8625 rs
->ncols
* sizeof (* rs
->col_offset
));
8626 free (rs
->col_type
);
8627 free (rs
->col_offset
);
8630 else if (do_debug_frames_interp
)
8631 printf ("Mismatched DW_CFA_restore_state\n");
8634 case DW_CFA_def_cfa
:
8635 READ_ULEB (fc
->cfa_reg
);
8636 READ_ULEB (fc
->cfa_offset
);
8638 if (! do_debug_frames_interp
)
8639 printf (" DW_CFA_def_cfa: %s ofs %d\n",
8640 regname (fc
->cfa_reg
, 0), (int) fc
->cfa_offset
);
8643 case DW_CFA_def_cfa_register
:
8644 READ_ULEB (fc
->cfa_reg
);
8646 if (! do_debug_frames_interp
)
8647 printf (" DW_CFA_def_cfa_register: %s\n",
8648 regname (fc
->cfa_reg
, 0));
8651 case DW_CFA_def_cfa_offset
:
8652 READ_ULEB (fc
->cfa_offset
);
8653 if (! do_debug_frames_interp
)
8654 printf (" DW_CFA_def_cfa_offset: %d\n", (int) fc
->cfa_offset
);
8658 if (! do_debug_frames_interp
)
8659 printf (" DW_CFA_nop\n");
8662 case DW_CFA_def_cfa_expression
:
8664 if (start
>= block_end
|| ul
> (unsigned long) (block_end
- start
))
8666 printf (_(" DW_CFA_def_cfa_expression: <corrupt len %lu>\n"), ul
);
8669 if (! do_debug_frames_interp
)
8671 printf (" DW_CFA_def_cfa_expression (");
8672 decode_location_expression (start
, eh_addr_size
, 0, -1,
8680 case DW_CFA_expression
:
8683 if (reg
>= (unsigned int) fc
->ncols
)
8684 reg_prefix
= bad_reg
;
8685 /* PR 17512: file: 069-133014-0.006. */
8686 /* PR 17512: file: 98c02eb4. */
8688 if (start
>= block_end
|| tmp
> block_end
|| tmp
< start
)
8690 printf (_(" DW_CFA_expression: <corrupt len %lu>\n"), ul
);
8693 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
8695 printf (" DW_CFA_expression: %s%s (",
8696 reg_prefix
, regname (reg
, 0));
8697 decode_location_expression (start
, eh_addr_size
, 0, -1,
8701 if (*reg_prefix
== '\0')
8702 fc
->col_type
[reg
] = DW_CFA_expression
;
8706 case DW_CFA_val_expression
:
8709 if (reg
>= (unsigned int) fc
->ncols
)
8710 reg_prefix
= bad_reg
;
8712 if (start
>= block_end
|| tmp
> block_end
|| tmp
< start
)
8714 printf (" DW_CFA_val_expression: <corrupt len %lu>\n", ul
);
8717 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
8719 printf (" DW_CFA_val_expression: %s%s (",
8720 reg_prefix
, regname (reg
, 0));
8721 decode_location_expression (start
, eh_addr_size
, 0, -1,
8725 if (*reg_prefix
== '\0')
8726 fc
->col_type
[reg
] = DW_CFA_val_expression
;
8730 case DW_CFA_offset_extended_sf
:
8733 if (frame_need_space (fc
, reg
) < 0)
8734 reg_prefix
= bad_reg
;
8735 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
8736 printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+ld\n",
8737 reg_prefix
, regname (reg
, 0),
8738 (long)(l
* fc
->data_factor
));
8739 if (*reg_prefix
== '\0')
8741 fc
->col_type
[reg
] = DW_CFA_offset
;
8742 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
8746 case DW_CFA_val_offset_sf
:
8749 if (frame_need_space (fc
, reg
) < 0)
8750 reg_prefix
= bad_reg
;
8751 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
8752 printf (" DW_CFA_val_offset_sf: %s%s is cfa%+ld\n",
8753 reg_prefix
, regname (reg
, 0),
8754 (long)(l
* fc
->data_factor
));
8755 if (*reg_prefix
== '\0')
8757 fc
->col_type
[reg
] = DW_CFA_val_offset
;
8758 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
8762 case DW_CFA_def_cfa_sf
:
8763 READ_ULEB (fc
->cfa_reg
);
8764 READ_ULEB (fc
->cfa_offset
);
8765 fc
->cfa_offset
= fc
->cfa_offset
* fc
->data_factor
;
8767 if (! do_debug_frames_interp
)
8768 printf (" DW_CFA_def_cfa_sf: %s ofs %d\n",
8769 regname (fc
->cfa_reg
, 0), (int) fc
->cfa_offset
);
8772 case DW_CFA_def_cfa_offset_sf
:
8773 READ_ULEB (fc
->cfa_offset
);
8774 fc
->cfa_offset
*= fc
->data_factor
;
8775 if (! do_debug_frames_interp
)
8776 printf (" DW_CFA_def_cfa_offset_sf: %d\n", (int) fc
->cfa_offset
);
8779 case DW_CFA_MIPS_advance_loc8
:
8780 SAFE_BYTE_GET_AND_INC (ofs
, start
, 8, block_end
);
8781 if (do_debug_frames_interp
)
8782 frame_display_row (fc
, &need_col_headers
, &max_regs
);
8784 printf (" DW_CFA_MIPS_advance_loc8: %ld to %s\n",
8785 (unsigned long) (ofs
* fc
->code_factor
),
8786 dwarf_vmatoa_1 (NULL
,
8787 fc
->pc_begin
+ ofs
* fc
->code_factor
,
8789 fc
->pc_begin
+= ofs
* fc
->code_factor
;
8792 case DW_CFA_GNU_window_save
:
8793 if (! do_debug_frames_interp
)
8794 printf (" DW_CFA_GNU_window_save\n");
8797 case DW_CFA_GNU_args_size
:
8799 if (! do_debug_frames_interp
)
8800 printf (" DW_CFA_GNU_args_size: %ld\n", ul
);
8803 case DW_CFA_GNU_negative_offset_extended
:
8807 if (frame_need_space (fc
, reg
) < 0)
8808 reg_prefix
= bad_reg
;
8809 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
8810 printf (" DW_CFA_GNU_negative_offset_extended: %s%s at cfa%+ld\n",
8811 reg_prefix
, regname (reg
, 0),
8812 (long)(l
* fc
->data_factor
));
8813 if (*reg_prefix
== '\0')
8815 fc
->col_type
[reg
] = DW_CFA_offset
;
8816 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
8821 if (op
>= DW_CFA_lo_user
&& op
<= DW_CFA_hi_user
)
8822 printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op
);
8824 warn (_("Unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op
);
8829 /* Interpret the CFA - as long as it is not completely full of NOPs. */
8830 if (do_debug_frames_interp
&& ! all_nops
)
8831 frame_display_row (fc
, &need_col_headers
, &max_regs
);
8834 eh_addr_size
= saved_eh_addr_size
;
8839 while (remembered_state
!= NULL
)
8841 rs
= remembered_state
;
8842 remembered_state
= rs
->next
;
8843 free (rs
->col_type
);
8844 free (rs
->col_offset
);
8845 rs
->next
= NULL
; /* Paranoia. */
8849 while (chunks
!= NULL
)
8853 free (rs
->col_type
);
8854 free (rs
->col_offset
);
8855 rs
->next
= NULL
; /* Paranoia. */
8859 while (forward_refs
!= NULL
)
8862 forward_refs
= rs
->next
;
8863 free (rs
->col_type
);
8864 free (rs
->col_offset
);
8865 rs
->next
= NULL
; /* Paranoia. */
8875 display_debug_names (struct dwarf_section
*section
, void *file
)
8877 unsigned char *hdrptr
= section
->start
;
8878 dwarf_vma unit_length
;
8879 unsigned char *unit_start
;
8880 const unsigned char *const section_end
= section
->start
+ section
->size
;
8881 unsigned char *unit_end
;
8883 introduce (section
, FALSE
);
8885 load_debug_section_with_follow (str
, file
);
8887 for (; hdrptr
< section_end
; hdrptr
= unit_end
)
8889 unsigned int offset_size
;
8890 uint16_t dwarf_version
, padding
;
8891 uint32_t comp_unit_count
, local_type_unit_count
, foreign_type_unit_count
;
8892 uint32_t bucket_count
, name_count
, abbrev_table_size
;
8893 uint32_t augmentation_string_size
;
8895 unsigned long sec_off
;
8896 bfd_boolean augmentation_printable
;
8897 const char *augmentation_string
;
8899 unit_start
= hdrptr
;
8901 /* Get and check the length of the block. */
8902 SAFE_BYTE_GET_AND_INC (unit_length
, hdrptr
, 4, section_end
);
8904 if (unit_length
== 0xffffffff)
8906 /* This section is 64-bit DWARF. */
8907 SAFE_BYTE_GET_AND_INC (unit_length
, hdrptr
, 8, section_end
);
8912 unit_end
= hdrptr
+ unit_length
;
8914 sec_off
= hdrptr
- section
->start
;
8915 if (sec_off
+ unit_length
< sec_off
8916 || sec_off
+ unit_length
> section
->size
)
8918 warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"),
8920 (unsigned long) (unit_start
- section
->start
),
8921 dwarf_vmatoa ("x", unit_length
));
8925 /* Get and check the version number. */
8926 SAFE_BYTE_GET_AND_INC (dwarf_version
, hdrptr
, 2, unit_end
);
8927 printf (_("Version %ld\n"), (long) dwarf_version
);
8929 /* Prior versions did not exist, and future versions may not be
8930 backwards compatible. */
8931 if (dwarf_version
!= 5)
8933 warn (_("Only DWARF version 5 .debug_names "
8934 "is currently supported.\n"));
8938 SAFE_BYTE_GET_AND_INC (padding
, hdrptr
, 2, unit_end
);
8940 warn (_("Padding field of .debug_names must be 0 (found 0x%x)\n"),
8943 SAFE_BYTE_GET_AND_INC (comp_unit_count
, hdrptr
, 4, unit_end
);
8944 if (comp_unit_count
== 0)
8945 warn (_("Compilation unit count must be >= 1 in .debug_names\n"));
8947 SAFE_BYTE_GET_AND_INC (local_type_unit_count
, hdrptr
, 4, unit_end
);
8948 SAFE_BYTE_GET_AND_INC (foreign_type_unit_count
, hdrptr
, 4, unit_end
);
8949 SAFE_BYTE_GET_AND_INC (bucket_count
, hdrptr
, 4, unit_end
);
8950 SAFE_BYTE_GET_AND_INC (name_count
, hdrptr
, 4, unit_end
);
8951 SAFE_BYTE_GET_AND_INC (abbrev_table_size
, hdrptr
, 4, unit_end
);
8953 SAFE_BYTE_GET_AND_INC (augmentation_string_size
, hdrptr
, 4, unit_end
);
8954 if (augmentation_string_size
% 4 != 0)
8956 warn (_("Augmentation string length %u must be rounded up "
8957 "to a multiple of 4 in .debug_names.\n"),
8958 augmentation_string_size
);
8959 augmentation_string_size
+= (-augmentation_string_size
) & 3;
8962 printf (_("Augmentation string:"));
8964 augmentation_printable
= TRUE
;
8965 augmentation_string
= (const char *) hdrptr
;
8967 for (i
= 0; i
< augmentation_string_size
; i
++)
8971 SAFE_BYTE_GET_AND_INC (uc
, hdrptr
, 1, unit_end
);
8972 printf (" %02x", uc
);
8974 if (uc
!= 0 && !ISPRINT (uc
))
8975 augmentation_printable
= FALSE
;
8978 if (augmentation_printable
)
8982 i
< augmentation_string_size
&& augmentation_string
[i
];
8984 putchar (augmentation_string
[i
]);
8989 printf (_("CU table:\n"));
8990 for (i
= 0; i
< comp_unit_count
; i
++)
8994 SAFE_BYTE_GET_AND_INC (cu_offset
, hdrptr
, offset_size
, unit_end
);
8995 printf (_("[%3u] 0x%lx\n"), i
, (unsigned long) cu_offset
);
8999 printf (_("TU table:\n"));
9000 for (i
= 0; i
< local_type_unit_count
; i
++)
9004 SAFE_BYTE_GET_AND_INC (tu_offset
, hdrptr
, offset_size
, unit_end
);
9005 printf (_("[%3u] 0x%lx\n"), i
, (unsigned long) tu_offset
);
9009 printf (_("Foreign TU table:\n"));
9010 for (i
= 0; i
< foreign_type_unit_count
; i
++)
9014 SAFE_BYTE_GET_AND_INC (signature
, hdrptr
, 8, unit_end
);
9015 printf (_("[%3u] "), i
);
9016 print_dwarf_vma (signature
, 8);
9021 const uint32_t *const hash_table_buckets
= (uint32_t *) hdrptr
;
9022 hdrptr
+= bucket_count
* sizeof (uint32_t);
9023 const uint32_t *const hash_table_hashes
= (uint32_t *) hdrptr
;
9024 hdrptr
+= name_count
* sizeof (uint32_t);
9025 unsigned char *const name_table_string_offsets
= hdrptr
;
9026 hdrptr
+= name_count
* offset_size
;
9027 unsigned char *const name_table_entry_offsets
= hdrptr
;
9028 hdrptr
+= name_count
* offset_size
;
9029 unsigned char *const abbrev_table
= hdrptr
;
9030 hdrptr
+= abbrev_table_size
;
9031 const unsigned char *const abbrev_table_end
= hdrptr
;
9032 unsigned char *const entry_pool
= hdrptr
;
9033 if (hdrptr
> unit_end
)
9035 warn (_("Entry pool offset (0x%lx) exceeds unit size 0x%lx "
9036 "for unit 0x%lx in the debug_names\n"),
9037 (long) (hdrptr
- section
->start
),
9038 (long) (unit_end
- section
->start
),
9039 (long) (unit_start
- section
->start
));
9043 size_t buckets_filled
= 0;
9045 for (bucketi
= 0; bucketi
< bucket_count
; bucketi
++)
9047 const uint32_t bucket
= hash_table_buckets
[bucketi
];
9052 printf (ngettext ("Used %zu of %lu bucket.\n",
9053 "Used %zu of %lu buckets.\n",
9055 buckets_filled
, (unsigned long) bucket_count
);
9057 uint32_t hash_prev
= 0;
9058 size_t hash_clash_count
= 0;
9059 size_t longest_clash
= 0;
9060 size_t this_length
= 0;
9062 for (hashi
= 0; hashi
< name_count
; hashi
++)
9064 const uint32_t hash_this
= hash_table_hashes
[hashi
];
9068 if (hash_prev
% bucket_count
== hash_this
% bucket_count
)
9072 longest_clash
= MAX (longest_clash
, this_length
);
9077 hash_prev
= hash_this
;
9079 printf (_("Out of %lu items there are %zu bucket clashes"
9080 " (longest of %zu entries).\n"),
9081 (unsigned long) name_count
, hash_clash_count
, longest_clash
);
9082 assert (name_count
== buckets_filled
+ hash_clash_count
);
9084 struct abbrev_lookup_entry
9086 dwarf_vma abbrev_tag
;
9087 unsigned char *abbrev_lookup_ptr
;
9089 struct abbrev_lookup_entry
*abbrev_lookup
= NULL
;
9090 size_t abbrev_lookup_used
= 0;
9091 size_t abbrev_lookup_allocated
= 0;
9093 unsigned char *abbrevptr
= abbrev_table
;
9096 unsigned int bytes_read
;
9097 const dwarf_vma abbrev_tag
= read_uleb128 (abbrevptr
, &bytes_read
,
9099 abbrevptr
+= bytes_read
;
9100 if (abbrev_tag
== 0)
9102 if (abbrev_lookup_used
== abbrev_lookup_allocated
)
9104 abbrev_lookup_allocated
= MAX (0x100,
9105 abbrev_lookup_allocated
* 2);
9106 abbrev_lookup
= xrealloc (abbrev_lookup
,
9107 (abbrev_lookup_allocated
9108 * sizeof (*abbrev_lookup
)));
9110 assert (abbrev_lookup_used
< abbrev_lookup_allocated
);
9111 struct abbrev_lookup_entry
*entry
;
9112 for (entry
= abbrev_lookup
;
9113 entry
< abbrev_lookup
+ abbrev_lookup_used
;
9115 if (entry
->abbrev_tag
== abbrev_tag
)
9117 warn (_("Duplicate abbreviation tag %lu "
9118 "in unit 0x%lx in the debug_names\n"),
9119 (long) abbrev_tag
, (long) (unit_start
- section
->start
));
9122 entry
= &abbrev_lookup
[abbrev_lookup_used
++];
9123 entry
->abbrev_tag
= abbrev_tag
;
9124 entry
->abbrev_lookup_ptr
= abbrevptr
;
9126 /* Skip DWARF tag. */
9127 read_uleb128 (abbrevptr
, &bytes_read
, abbrev_table_end
);
9128 abbrevptr
+= bytes_read
;
9131 const dwarf_vma xindex
= read_uleb128 (abbrevptr
,
9134 abbrevptr
+= bytes_read
;
9135 const dwarf_vma form
= read_uleb128 (abbrevptr
, &bytes_read
,
9137 abbrevptr
+= bytes_read
;
9138 if (xindex
== 0 && form
== 0)
9143 printf (_("\nSymbol table:\n"));
9145 for (namei
= 0; namei
< name_count
; ++namei
)
9147 uint64_t string_offset
, entry_offset
;
9149 SAFE_BYTE_GET (string_offset
,
9150 name_table_string_offsets
+ namei
* offset_size
,
9151 offset_size
, unit_end
);
9152 SAFE_BYTE_GET (entry_offset
,
9153 name_table_entry_offsets
+ namei
* offset_size
,
9154 offset_size
, unit_end
);
9156 printf ("[%3u] #%08x %s:", namei
, hash_table_hashes
[namei
],
9157 fetch_indirect_string (string_offset
));
9159 unsigned char *entryptr
= entry_pool
+ entry_offset
;
9161 // We need to scan first whether there is a single or multiple
9162 // entries. TAGNO is -2 for the first entry, it is -1 for the
9163 // initial tag read of the second entry, then it becomes 0 for the
9164 // first entry for real printing etc.
9166 /* Initialize it due to a false compiler warning. */
9167 dwarf_vma second_abbrev_tag
= -1;
9170 unsigned int bytes_read
;
9171 const dwarf_vma abbrev_tag
= read_uleb128 (entryptr
, &bytes_read
,
9173 entryptr
+= bytes_read
;
9176 second_abbrev_tag
= abbrev_tag
;
9178 entryptr
= entry_pool
+ entry_offset
;
9181 if (abbrev_tag
== 0)
9185 (tagno
== 0 && second_abbrev_tag
== 0 ? " " : "\n\t"),
9186 (unsigned long) abbrev_tag
);
9188 const struct abbrev_lookup_entry
*entry
;
9189 for (entry
= abbrev_lookup
;
9190 entry
< abbrev_lookup
+ abbrev_lookup_used
;
9192 if (entry
->abbrev_tag
== abbrev_tag
)
9194 if (entry
>= abbrev_lookup
+ abbrev_lookup_used
)
9196 warn (_("Undefined abbreviation tag %lu "
9197 "in unit 0x%lx in the debug_names\n"),
9199 (long) (unit_start
- section
->start
));
9202 abbrevptr
= entry
->abbrev_lookup_ptr
;
9203 const dwarf_vma dwarf_tag
= read_uleb128 (abbrevptr
, &bytes_read
,
9205 abbrevptr
+= bytes_read
;
9207 printf (" %s", get_TAG_name (dwarf_tag
));
9210 const dwarf_vma xindex
= read_uleb128 (abbrevptr
,
9213 abbrevptr
+= bytes_read
;
9214 const dwarf_vma form
= read_uleb128 (abbrevptr
, &bytes_read
,
9216 abbrevptr
+= bytes_read
;
9217 if (xindex
== 0 && form
== 0)
9221 printf (" %s", get_IDX_name (xindex
));
9222 entryptr
= read_and_display_attr_value (0, form
, 0,
9223 unit_start
, entryptr
, unit_end
,
9225 dwarf_version
, NULL
,
9232 printf (_(" <no entries>"));
9236 free (abbrev_lookup
);
9243 display_debug_links (struct dwarf_section
* section
,
9244 void * file ATTRIBUTE_UNUSED
)
9246 const unsigned char * filename
;
9247 unsigned int filelen
;
9249 introduce (section
, FALSE
);
9251 /* The .gnu_debuglink section is formatted as:
9252 (c-string) Filename.
9253 (padding) If needed to reach a 4 byte boundary.
9254 (uint32_t) CRC32 value.
9256 The .gun_debugaltlink section is formatted as:
9257 (c-string) Filename.
9258 (binary) Build-ID. */
9260 filename
= section
->start
;
9261 filelen
= strnlen ((const char *) filename
, section
->size
);
9262 if (filelen
== section
->size
)
9264 warn (_("The debuglink filename is corrupt/missing\n"));
9268 printf (_(" Separate debug info file: %s\n"), filename
);
9270 if (const_strneq (section
->name
, ".gnu_debuglink"))
9273 unsigned int crc_offset
;
9275 crc_offset
= filelen
+ 1;
9276 crc_offset
= (crc_offset
+ 3) & ~3;
9277 if (crc_offset
+ 4 > section
->size
)
9279 warn (_("CRC offset missing/truncated\n"));
9283 crc32
= byte_get (filename
+ crc_offset
, 4);
9285 printf (_(" CRC value: %#x\n"), crc32
);
9287 if (crc_offset
+ 4 < section
->size
)
9289 warn (_("There are %#lx extraneous bytes at the end of the section\n"),
9290 (long)(section
->size
- (crc_offset
+ 4)));
9294 else /* const_strneq (section->name, ".gnu_debugaltlink") */
9296 const unsigned char * build_id
= section
->start
+ filelen
+ 1;
9297 bfd_size_type build_id_len
= section
->size
- (filelen
+ 1);
9298 bfd_size_type printed
;
9300 /* FIXME: Should we support smaller build-id notes ? */
9301 if (build_id_len
< 0x14)
9303 warn (_("Build-ID is too short (%#lx bytes)\n"), (long) build_id_len
);
9307 printed
= printf (_(" Build-ID (%#lx bytes):"), (long) build_id_len
);
9308 display_data (printed
, build_id
, build_id_len
);
9317 display_gdb_index (struct dwarf_section
*section
,
9318 void *file ATTRIBUTE_UNUSED
)
9320 unsigned char *start
= section
->start
;
9322 uint32_t cu_list_offset
, tu_list_offset
;
9323 uint32_t address_table_offset
, symbol_table_offset
, constant_pool_offset
;
9324 unsigned int cu_list_elements
, tu_list_elements
;
9325 unsigned int address_table_size
, symbol_table_slots
;
9326 unsigned char *cu_list
, *tu_list
;
9327 unsigned char *address_table
, *symbol_table
, *constant_pool
;
9330 /* The documentation for the format of this file is in gdb/dwarf2read.c. */
9332 introduce (section
, FALSE
);
9334 if (section
->size
< 6 * sizeof (uint32_t))
9336 warn (_("Truncated header in the %s section.\n"), section
->name
);
9340 version
= byte_get_little_endian (start
, 4);
9341 printf (_("Version %ld\n"), (long) version
);
9343 /* Prior versions are obsolete, and future versions may not be
9344 backwards compatible. */
9345 if (version
< 3 || version
> 8)
9347 warn (_("Unsupported version %lu.\n"), (unsigned long) version
);
9351 warn (_("The address table data in version 3 may be wrong.\n"));
9353 warn (_("Version 4 does not support case insensitive lookups.\n"));
9355 warn (_("Version 5 does not include inlined functions.\n"));
9357 warn (_("Version 6 does not include symbol attributes.\n"));
9358 /* Version 7 indices generated by Gold have bad type unit references,
9359 PR binutils/15021. But we don't know if the index was generated by
9360 Gold or not, so to avoid worrying users with gdb-generated indices
9361 we say nothing for version 7 here. */
9363 cu_list_offset
= byte_get_little_endian (start
+ 4, 4);
9364 tu_list_offset
= byte_get_little_endian (start
+ 8, 4);
9365 address_table_offset
= byte_get_little_endian (start
+ 12, 4);
9366 symbol_table_offset
= byte_get_little_endian (start
+ 16, 4);
9367 constant_pool_offset
= byte_get_little_endian (start
+ 20, 4);
9369 if (cu_list_offset
> section
->size
9370 || tu_list_offset
> section
->size
9371 || address_table_offset
> section
->size
9372 || symbol_table_offset
> section
->size
9373 || constant_pool_offset
> section
->size
)
9375 warn (_("Corrupt header in the %s section.\n"), section
->name
);
9379 /* PR 17531: file: 418d0a8a. */
9380 if (tu_list_offset
< cu_list_offset
)
9382 warn (_("TU offset (%x) is less than CU offset (%x)\n"),
9383 tu_list_offset
, cu_list_offset
);
9387 cu_list_elements
= (tu_list_offset
- cu_list_offset
) / 8;
9389 if (address_table_offset
< tu_list_offset
)
9391 warn (_("Address table offset (%x) is less than TU offset (%x)\n"),
9392 address_table_offset
, tu_list_offset
);
9396 tu_list_elements
= (address_table_offset
- tu_list_offset
) / 8;
9398 /* PR 17531: file: 18a47d3d. */
9399 if (symbol_table_offset
< address_table_offset
)
9401 warn (_("Symbol table offset (%x) is less then Address table offset (%x)\n"),
9402 symbol_table_offset
, address_table_offset
);
9406 address_table_size
= symbol_table_offset
- address_table_offset
;
9408 if (constant_pool_offset
< symbol_table_offset
)
9410 warn (_("Constant pool offset (%x) is less than symbol table offset (%x)\n"),
9411 constant_pool_offset
, symbol_table_offset
);
9415 symbol_table_slots
= (constant_pool_offset
- symbol_table_offset
) / 8;
9417 cu_list
= start
+ cu_list_offset
;
9418 tu_list
= start
+ tu_list_offset
;
9419 address_table
= start
+ address_table_offset
;
9420 symbol_table
= start
+ symbol_table_offset
;
9421 constant_pool
= start
+ constant_pool_offset
;
9423 if (address_table
+ address_table_size
> section
->start
+ section
->size
)
9425 warn (_("Address table extends beyond end of section.\n"));
9429 printf (_("\nCU table:\n"));
9430 for (i
= 0; i
< cu_list_elements
; i
+= 2)
9432 uint64_t cu_offset
= byte_get_little_endian (cu_list
+ i
* 8, 8);
9433 uint64_t cu_length
= byte_get_little_endian (cu_list
+ i
* 8 + 8, 8);
9435 printf (_("[%3u] 0x%lx - 0x%lx\n"), i
/ 2,
9436 (unsigned long) cu_offset
,
9437 (unsigned long) (cu_offset
+ cu_length
- 1));
9440 printf (_("\nTU table:\n"));
9441 for (i
= 0; i
< tu_list_elements
; i
+= 3)
9443 uint64_t tu_offset
= byte_get_little_endian (tu_list
+ i
* 8, 8);
9444 uint64_t type_offset
= byte_get_little_endian (tu_list
+ i
* 8 + 8, 8);
9445 uint64_t signature
= byte_get_little_endian (tu_list
+ i
* 8 + 16, 8);
9447 printf (_("[%3u] 0x%lx 0x%lx "), i
/ 3,
9448 (unsigned long) tu_offset
,
9449 (unsigned long) type_offset
);
9450 print_dwarf_vma (signature
, 8);
9454 printf (_("\nAddress table:\n"));
9455 for (i
= 0; i
< address_table_size
&& i
<= address_table_size
- (2 * 8 + 4);
9458 uint64_t low
= byte_get_little_endian (address_table
+ i
, 8);
9459 uint64_t high
= byte_get_little_endian (address_table
+ i
+ 8, 8);
9460 uint32_t cu_index
= byte_get_little_endian (address_table
+ i
+ 16, 4);
9462 print_dwarf_vma (low
, 8);
9463 print_dwarf_vma (high
, 8);
9464 printf (_("%lu\n"), (unsigned long) cu_index
);
9467 printf (_("\nSymbol table:\n"));
9468 for (i
= 0; i
< symbol_table_slots
; ++i
)
9470 uint32_t name_offset
= byte_get_little_endian (symbol_table
+ i
* 8, 4);
9471 uint32_t cu_vector_offset
= byte_get_little_endian (symbol_table
+ i
* 8 + 4, 4);
9472 uint32_t num_cus
, cu
;
9474 if (name_offset
!= 0
9475 || cu_vector_offset
!= 0)
9478 unsigned char * adr
;
9480 adr
= constant_pool
+ name_offset
;
9481 /* PR 17531: file: 5b7b07ad. */
9482 if (adr
< constant_pool
|| adr
>= section
->start
+ section
->size
)
9484 printf (_("[%3u] <corrupt offset: %x>"), i
, name_offset
);
9485 warn (_("Corrupt name offset of 0x%x found for symbol table slot %d\n"),
9489 printf ("[%3u] %.*s:", i
,
9490 (int) (section
->size
- (constant_pool_offset
+ name_offset
)),
9491 constant_pool
+ name_offset
);
9493 adr
= constant_pool
+ cu_vector_offset
;
9494 if (adr
< constant_pool
|| adr
>= section
->start
+ section
->size
- 3)
9496 printf (_("<invalid CU vector offset: %x>\n"), cu_vector_offset
);
9497 warn (_("Corrupt CU vector offset of 0x%x found for symbol table slot %d\n"),
9498 cu_vector_offset
, i
);
9502 num_cus
= byte_get_little_endian (adr
, 4);
9504 adr
= constant_pool
+ cu_vector_offset
+ 4 + num_cus
* 4;
9505 if (num_cus
* 4 < num_cus
9506 || adr
>= section
->start
+ section
->size
9507 || adr
< constant_pool
)
9509 printf ("<invalid number of CUs: %d>\n", num_cus
);
9510 warn (_("Invalid number of CUs (0x%x) for symbol table slot %d\n"),
9518 for (j
= 0; j
< num_cus
; ++j
)
9521 gdb_index_symbol_kind kind
;
9523 cu
= byte_get_little_endian (constant_pool
+ cu_vector_offset
+ 4 + j
* 4, 4);
9524 is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu
);
9525 kind
= GDB_INDEX_SYMBOL_KIND_VALUE (cu
);
9526 cu
= GDB_INDEX_CU_VALUE (cu
);
9527 /* Convert to TU number if it's for a type unit. */
9528 if (cu
>= cu_list_elements
/ 2)
9529 printf ("%cT%lu", num_cus
> 1 ? '\t' : ' ',
9530 (unsigned long) (cu
- cu_list_elements
/ 2));
9532 printf ("%c%lu", num_cus
> 1 ? '\t' : ' ', (unsigned long) cu
);
9534 printf (" [%s, %s]",
9535 is_static
? _("static") : _("global"),
9536 get_gdb_index_symbol_kind_name (kind
));
9548 /* Pre-allocate enough space for the CU/TU sets needed. */
9551 prealloc_cu_tu_list (unsigned int nshndx
)
9553 if (shndx_pool
== NULL
)
9555 shndx_pool_size
= nshndx
;
9556 shndx_pool_used
= 0;
9557 shndx_pool
= (unsigned int *) xcmalloc (shndx_pool_size
,
9558 sizeof (unsigned int));
9562 shndx_pool_size
= shndx_pool_used
+ nshndx
;
9563 shndx_pool
= (unsigned int *) xcrealloc (shndx_pool
, shndx_pool_size
,
9564 sizeof (unsigned int));
9569 add_shndx_to_cu_tu_entry (unsigned int shndx
)
9571 if (shndx_pool_used
>= shndx_pool_size
)
9573 error (_("Internal error: out of space in the shndx pool.\n"));
9576 shndx_pool
[shndx_pool_used
++] = shndx
;
9580 end_cu_tu_entry (void)
9582 if (shndx_pool_used
>= shndx_pool_size
)
9584 error (_("Internal error: out of space in the shndx pool.\n"));
9587 shndx_pool
[shndx_pool_used
++] = 0;
9590 /* Return the short name of a DWARF section given by a DW_SECT enumerator. */
9593 get_DW_SECT_short_name (unsigned int dw_sect
)
9595 static char buf
[16];
9603 case DW_SECT_ABBREV
:
9609 case DW_SECT_STR_OFFSETS
:
9611 case DW_SECT_MACINFO
:
9619 snprintf (buf
, sizeof (buf
), "%d", dw_sect
);
9623 /* Process a CU or TU index. If DO_DISPLAY is true, print the contents.
9624 These sections are extensions for Fission.
9625 See http://gcc.gnu.org/wiki/DebugFissionDWP. */
9628 process_cu_tu_index (struct dwarf_section
*section
, int do_display
)
9630 unsigned char *phdr
= section
->start
;
9631 unsigned char *limit
= phdr
+ section
->size
;
9632 unsigned char *phash
;
9633 unsigned char *pindex
;
9634 unsigned char *ppool
;
9635 unsigned int version
;
9636 unsigned int ncols
= 0;
9638 unsigned int nslots
;
9641 dwarf_vma signature_high
;
9642 dwarf_vma signature_low
;
9645 /* PR 17512: file: 002-168123-0.004. */
9648 warn (_("Section %s is empty\n"), section
->name
);
9651 /* PR 17512: file: 002-376-0.004. */
9652 if (section
->size
< 24)
9654 warn (_("Section %s is too small to contain a CU/TU header\n"),
9659 SAFE_BYTE_GET (version
, phdr
, 4, limit
);
9661 SAFE_BYTE_GET (ncols
, phdr
+ 4, 4, limit
);
9662 SAFE_BYTE_GET (nused
, phdr
+ 8, 4, limit
);
9663 SAFE_BYTE_GET (nslots
, phdr
+ 12, 4, limit
);
9666 pindex
= phash
+ (size_t) nslots
* 8;
9667 ppool
= pindex
+ (size_t) nslots
* 4;
9671 introduce (section
, FALSE
);
9673 printf (_(" Version: %u\n"), version
);
9675 printf (_(" Number of columns: %u\n"), ncols
);
9676 printf (_(" Number of used entries: %u\n"), nused
);
9677 printf (_(" Number of slots: %u\n\n"), nslots
);
9680 /* PR 17531: file: 45d69832. */
9681 if ((size_t) nslots
* 8 / 8 != nslots
9682 || phash
< phdr
|| phash
> limit
9683 || pindex
< phash
|| pindex
> limit
9684 || ppool
< pindex
|| ppool
> limit
)
9686 warn (ngettext ("Section %s is too small for %u slot\n",
9687 "Section %s is too small for %u slots\n",
9689 section
->name
, nslots
);
9696 prealloc_cu_tu_list ((limit
- ppool
) / 4);
9697 for (i
= 0; i
< nslots
; i
++)
9699 unsigned char *shndx_list
;
9702 SAFE_BYTE_GET64 (phash
, &signature_high
, &signature_low
, limit
);
9703 if (signature_high
!= 0 || signature_low
!= 0)
9705 SAFE_BYTE_GET (j
, pindex
, 4, limit
);
9706 shndx_list
= ppool
+ j
* 4;
9707 /* PR 17531: file: 705e010d. */
9708 if (shndx_list
< ppool
)
9710 warn (_("Section index pool located before start of section\n"));
9715 printf (_(" [%3d] Signature: 0x%s Sections: "),
9716 i
, dwarf_vmatoa64 (signature_high
, signature_low
,
9717 buf
, sizeof (buf
)));
9720 if (shndx_list
>= limit
)
9722 warn (_("Section %s too small for shndx pool\n"),
9726 SAFE_BYTE_GET (shndx
, shndx_list
, 4, limit
);
9730 printf (" %d", shndx
);
9732 add_shndx_to_cu_tu_entry (shndx
);
9744 else if (version
== 2)
9747 unsigned int dw_sect
;
9748 unsigned char *ph
= phash
;
9749 unsigned char *pi
= pindex
;
9750 unsigned char *poffsets
= ppool
+ (size_t) ncols
* 4;
9751 unsigned char *psizes
= poffsets
+ (size_t) nused
* ncols
* 4;
9752 unsigned char *pend
= psizes
+ (size_t) nused
* ncols
* 4;
9753 bfd_boolean is_tu_index
;
9754 struct cu_tu_set
*this_set
= NULL
;
9756 unsigned char *prow
;
9758 is_tu_index
= strcmp (section
->name
, ".debug_tu_index") == 0;
9760 /* PR 17531: file: 0dd159bf.
9761 Check for integer overflow (can occur when size_t is 32-bit)
9762 with overlarge ncols or nused values. */
9764 && ((size_t) ncols
* 4 / 4 != ncols
9765 || (size_t) nused
* ncols
* 4 / ((size_t) ncols
* 4) != nused
9766 || poffsets
< ppool
|| poffsets
> limit
9767 || psizes
< poffsets
|| psizes
> limit
9768 || pend
< psizes
|| pend
> limit
))
9770 warn (_("Section %s too small for offset and size tables\n"),
9777 printf (_(" Offset table\n"));
9778 printf (" slot %-16s ",
9779 is_tu_index
? _("signature") : _("dwo_id"));
9786 tu_sets
= xcalloc2 (nused
, sizeof (struct cu_tu_set
));
9792 cu_sets
= xcalloc2 (nused
, sizeof (struct cu_tu_set
));
9799 for (j
= 0; j
< ncols
; j
++)
9801 SAFE_BYTE_GET (dw_sect
, ppool
+ j
* 4, 4, limit
);
9802 printf (" %8s", get_DW_SECT_short_name (dw_sect
));
9807 for (i
= 0; i
< nslots
; i
++)
9809 SAFE_BYTE_GET64 (ph
, &signature_high
, &signature_low
, limit
);
9811 SAFE_BYTE_GET (row
, pi
, 4, limit
);
9814 /* PR 17531: file: a05f6ab3. */
9817 warn (_("Row index (%u) is larger than number of used entries (%u)\n"),
9824 size_t num_copy
= sizeof (uint64_t);
9826 /* PR 23064: Beware of buffer overflow. */
9827 if (ph
+ num_copy
< limit
)
9828 memcpy (&this_set
[row
- 1].signature
, ph
, num_copy
);
9831 warn (_("Signature (%p) extends beyond end of space in section\n"), ph
);
9836 prow
= poffsets
+ (row
- 1) * ncols
* 4;
9837 /* PR 17531: file: b8ce60a8. */
9838 if (prow
< poffsets
|| prow
> limit
)
9840 warn (_("Row index (%u) * num columns (%u) > space remaining in section\n"),
9846 printf (_(" [%3d] 0x%s"),
9847 i
, dwarf_vmatoa64 (signature_high
, signature_low
,
9848 buf
, sizeof (buf
)));
9849 for (j
= 0; j
< ncols
; j
++)
9851 SAFE_BYTE_GET (val
, prow
+ j
* 4, 4, limit
);
9853 printf (" %8d", val
);
9856 SAFE_BYTE_GET (dw_sect
, ppool
+ j
* 4, 4, limit
);
9858 /* PR 17531: file: 10796eb3. */
9859 if (dw_sect
>= DW_SECT_MAX
)
9860 warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect
);
9862 this_set
[row
- 1].section_offsets
[dw_sect
] = val
;
9878 printf (_(" Size table\n"));
9879 printf (" slot %-16s ",
9880 is_tu_index
? _("signature") : _("dwo_id"));
9883 for (j
= 0; j
< ncols
; j
++)
9885 SAFE_BYTE_GET (val
, ppool
+ j
* 4, 4, limit
);
9887 printf (" %8s", get_DW_SECT_short_name (val
));
9893 for (i
= 0; i
< nslots
; i
++)
9895 SAFE_BYTE_GET64 (ph
, &signature_high
, &signature_low
, limit
);
9897 SAFE_BYTE_GET (row
, pi
, 4, limit
);
9900 prow
= psizes
+ (row
- 1) * ncols
* 4;
9903 printf (_(" [%3d] 0x%s"),
9904 i
, dwarf_vmatoa64 (signature_high
, signature_low
,
9905 buf
, sizeof (buf
)));
9907 for (j
= 0; j
< ncols
; j
++)
9909 SAFE_BYTE_GET (val
, prow
+ j
* 4, 4, limit
);
9911 printf (" %8d", val
);
9914 SAFE_BYTE_GET (dw_sect
, ppool
+ j
* 4, 4, limit
);
9915 if (dw_sect
>= DW_SECT_MAX
)
9916 warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect
);
9918 this_set
[row
- 1].section_sizes
[dw_sect
] = val
;
9930 else if (do_display
)
9931 printf (_(" Unsupported version (%d)\n"), version
);
9939 /* Load the CU and TU indexes if present. This will build a list of
9940 section sets that we can use to associate a .debug_info.dwo section
9941 with its associated .debug_abbrev.dwo section in a .dwp file. */
9944 load_cu_tu_indexes (void *file
)
9946 static int cu_tu_indexes_read
= -1; /* Tri-state variable. */
9948 /* If we have already loaded (or tried to load) the CU and TU indexes
9949 then do not bother to repeat the task. */
9950 if (cu_tu_indexes_read
== -1)
9952 cu_tu_indexes_read
= TRUE
;
9954 if (load_debug_section_with_follow (dwp_cu_index
, file
))
9955 if (! process_cu_tu_index (&debug_displays
[dwp_cu_index
].section
, 0))
9956 cu_tu_indexes_read
= FALSE
;
9958 if (load_debug_section_with_follow (dwp_tu_index
, file
))
9959 if (! process_cu_tu_index (&debug_displays
[dwp_tu_index
].section
, 0))
9960 cu_tu_indexes_read
= FALSE
;
9963 return (bfd_boolean
) cu_tu_indexes_read
;
9966 /* Find the set of sections that includes section SHNDX. */
9969 find_cu_tu_set (void *file
, unsigned int shndx
)
9973 if (! load_cu_tu_indexes (file
))
9976 /* Find SHNDX in the shndx pool. */
9977 for (i
= 0; i
< shndx_pool_used
; i
++)
9978 if (shndx_pool
[i
] == shndx
)
9981 if (i
>= shndx_pool_used
)
9984 /* Now backup to find the first entry in the set. */
9985 while (i
> 0 && shndx_pool
[i
- 1] != 0)
9988 return shndx_pool
+ i
;
9991 /* Display a .debug_cu_index or .debug_tu_index section. */
9994 display_cu_index (struct dwarf_section
*section
, void *file ATTRIBUTE_UNUSED
)
9996 return process_cu_tu_index (section
, 1);
10000 display_debug_not_supported (struct dwarf_section
*section
,
10001 void *file ATTRIBUTE_UNUSED
)
10003 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
10009 /* Like malloc, but takes two parameters like calloc.
10010 Verifies that the first parameter is not too large.
10011 Note: does *not* initialise the allocated memory to zero. */
10014 cmalloc (size_t nmemb
, size_t size
)
10016 /* Check for overflow. */
10017 if (nmemb
>= ~(size_t) 0 / size
)
10020 return xmalloc (nmemb
* size
);
10023 /* Like xmalloc, but takes two parameters like calloc.
10024 Verifies that the first parameter is not too large.
10025 Note: does *not* initialise the allocated memory to zero. */
10028 xcmalloc (size_t nmemb
, size_t size
)
10030 /* Check for overflow. */
10031 if (nmemb
>= ~(size_t) 0 / size
)
10034 _("Attempt to allocate an array with an excessive number of elements: 0x%lx\n"),
10039 return xmalloc (nmemb
* size
);
10042 /* Like xrealloc, but takes three parameters.
10043 Verifies that the second parameter is not too large.
10044 Note: does *not* initialise any new memory to zero. */
10047 xcrealloc (void *ptr
, size_t nmemb
, size_t size
)
10049 /* Check for overflow. */
10050 if (nmemb
>= ~(size_t) 0 / size
)
10052 error (_("Attempt to re-allocate an array with an excessive number of elements: 0x%lx\n"),
10057 return xrealloc (ptr
, nmemb
* size
);
10060 /* Like xcalloc, but verifies that the first parameter is not too large. */
10063 xcalloc2 (size_t nmemb
, size_t size
)
10065 /* Check for overflow. */
10066 if (nmemb
>= ~(size_t) 0 / size
)
10068 error (_("Attempt to allocate a zero'ed array with an excessive number of elements: 0x%lx\n"),
10073 return xcalloc (nmemb
, size
);
10076 static unsigned long
10077 calc_gnu_debuglink_crc32 (unsigned long crc
,
10078 const unsigned char * buf
,
10081 static const unsigned long crc32_table
[256] =
10083 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
10084 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
10085 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
10086 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
10087 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
10088 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
10089 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
10090 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
10091 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
10092 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
10093 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
10094 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
10095 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
10096 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
10097 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
10098 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
10099 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
10100 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
10101 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
10102 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
10103 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
10104 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
10105 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
10106 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
10107 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
10108 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
10109 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
10110 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
10111 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
10112 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
10113 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
10114 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
10115 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
10116 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
10117 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
10118 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
10119 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
10120 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
10121 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
10122 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
10123 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
10124 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
10125 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
10126 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
10127 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
10128 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
10129 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
10130 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
10131 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
10132 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
10133 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
10136 const unsigned char *end
;
10138 crc
= ~crc
& 0xffffffff;
10139 for (end
= buf
+ len
; buf
< end
; ++ buf
)
10140 crc
= crc32_table
[(crc
^ *buf
) & 0xff] ^ (crc
>> 8);
10141 return ~crc
& 0xffffffff;
10144 typedef bfd_boolean (* check_func_type
) (const char *, void *);
10145 typedef const char * (* parse_func_type
) (struct dwarf_section
*, void *);
10148 check_gnu_debuglink (const char * pathname
, void * crc_pointer
)
10150 static unsigned char buffer
[8 * 1024];
10152 bfd_size_type count
;
10153 unsigned long crc
= 0;
10156 sep_data
= open_debug_file (pathname
);
10157 if (sep_data
== NULL
)
10160 /* Yes - we are opening the file twice... */
10161 f
= fopen (pathname
, "rb");
10164 /* Paranoia: This should never happen. */
10165 close_debug_file (sep_data
);
10166 warn (_("Unable to reopen separate debug info file: %s\n"), pathname
);
10170 while ((count
= fread (buffer
, 1, sizeof (buffer
), f
)) > 0)
10171 crc
= calc_gnu_debuglink_crc32 (crc
, buffer
, count
);
10175 if (crc
!= * (unsigned long *) crc_pointer
)
10177 close_debug_file (sep_data
);
10178 warn (_("Separate debug info file %s found, but CRC does not match - ignoring\n"),
10186 static const char *
10187 parse_gnu_debuglink (struct dwarf_section
* section
, void * data
)
10190 unsigned int crc_offset
;
10191 unsigned long * crc32
= (unsigned long *) data
;
10193 /* The name is first.
10194 The CRC value is stored after the filename, aligned up to 4 bytes. */
10195 name
= (const char *) section
->start
;
10198 crc_offset
= strnlen (name
, section
->size
) + 1;
10199 crc_offset
= (crc_offset
+ 3) & ~3;
10200 if (crc_offset
+ 4 > section
->size
)
10203 * crc32
= byte_get (section
->start
+ crc_offset
, 4);
10208 check_gnu_debugaltlink (const char * filename
, void * data ATTRIBUTE_UNUSED
)
10210 void * sep_data
= open_debug_file (filename
);
10212 if (sep_data
== NULL
)
10215 /* FIXME: We should now extract the build-id in the separate file
10221 typedef struct build_id_data
10224 const unsigned char * data
;
10227 static const char *
10228 parse_gnu_debugaltlink (struct dwarf_section
* section
, void * data
)
10231 bfd_size_type namelen
;
10232 bfd_size_type id_len
;
10233 Build_id_data
* build_id_data
;
10235 /* The name is first.
10236 The build-id follows immediately, with no padding, up to the section's end. */
10238 name
= (const char *) section
->start
;
10239 namelen
= strnlen (name
, section
->size
) + 1;
10240 if (namelen
>= section
->size
)
10243 id_len
= section
->size
- namelen
;
10247 build_id_data
= calloc (1, sizeof * build_id_data
);
10248 if (build_id_data
== NULL
)
10251 build_id_data
->len
= id_len
;
10252 build_id_data
->data
= section
->start
+ namelen
;
10254 * (Build_id_data
**) data
= build_id_data
;
10260 add_separate_debug_file (const char * filename
, void * handle
)
10262 separate_info
* i
= xmalloc (sizeof * i
);
10264 i
->filename
= filename
;
10265 i
->handle
= handle
;
10266 i
->next
= first_separate_info
;
10267 first_separate_info
= i
;
10271 load_separate_debug_info (const char * main_filename
,
10272 struct dwarf_section
* xlink
,
10273 parse_func_type parse_func
,
10274 check_func_type check_func
,
10277 const char * separate_filename
;
10278 char * debug_filename
;
10280 size_t canon_dirlen
;
10283 if ((separate_filename
= parse_func (xlink
, func_data
)) == NULL
)
10285 warn (_("Corrupt debuglink section: %s\n"),
10286 xlink
->name
? xlink
->name
: xlink
->uncompressed_name
);
10290 /* Attempt to locate the separate file.
10291 This should duplicate the logic in bfd/opncls.c:find_separate_debug_file(). */
10293 canon_dir
= lrealpath (main_filename
);
10295 for (canon_dirlen
= strlen (canon_dir
); canon_dirlen
> 0; canon_dirlen
--)
10296 if (IS_DIR_SEPARATOR (canon_dir
[canon_dirlen
- 1]))
10298 canon_dir
[canon_dirlen
] = '\0';
10301 #define DEBUGDIR "/lib/debug"
10303 #ifndef EXTRA_DEBUG_ROOT1
10304 #define EXTRA_DEBUG_ROOT1 "/usr/lib/debug"
10306 #ifndef EXTRA_DEBUG_ROOT2
10307 #define EXTRA_DEBUG_ROOT2 "/usr/lib/debug/usr"
10310 debug_filename
= (char *) malloc (strlen (DEBUGDIR
) + 1
10312 + strlen (".debug/")
10313 #ifdef EXTRA_DEBUG_ROOT1
10314 + strlen (EXTRA_DEBUG_ROOT1
)
10316 #ifdef EXTRA_DEBUG_ROOT2
10317 + strlen (EXTRA_DEBUG_ROOT2
)
10319 + strlen (separate_filename
)
10321 if (debug_filename
== NULL
)
10323 warn (_("Out of memory"));
10328 /* First try in the current directory. */
10329 sprintf (debug_filename
, "%s", separate_filename
);
10330 if (check_func (debug_filename
, func_data
))
10333 /* Then try in a subdirectory called .debug. */
10334 sprintf (debug_filename
, ".debug/%s", separate_filename
);
10335 if (check_func (debug_filename
, func_data
))
10338 /* Then try in the same directory as the original file. */
10339 sprintf (debug_filename
, "%s%s", canon_dir
, separate_filename
);
10340 if (check_func (debug_filename
, func_data
))
10343 /* And the .debug subdirectory of that directory. */
10344 sprintf (debug_filename
, "%s.debug/%s", canon_dir
, separate_filename
);
10345 if (check_func (debug_filename
, func_data
))
10348 #ifdef EXTRA_DEBUG_ROOT1
10349 /* Try the first extra debug file root. */
10350 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT1
, separate_filename
);
10351 if (check_func (debug_filename
, func_data
))
10354 /* Try the first extra debug file root. */
10355 sprintf (debug_filename
, "%s/%s/%s", EXTRA_DEBUG_ROOT1
, canon_dir
, separate_filename
);
10356 if (check_func (debug_filename
, func_data
))
10360 #ifdef EXTRA_DEBUG_ROOT2
10361 /* Try the second extra debug file root. */
10362 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT2
, separate_filename
);
10363 if (check_func (debug_filename
, func_data
))
10367 /* Then try in the global debug_filename directory. */
10368 strcpy (debug_filename
, DEBUGDIR
);
10369 dirlen
= strlen (DEBUGDIR
) - 1;
10370 if (dirlen
> 0 && DEBUGDIR
[dirlen
] != '/')
10371 strcat (debug_filename
, "/");
10372 strcat (debug_filename
, (const char *) separate_filename
);
10374 if (check_func (debug_filename
, func_data
))
10377 /* Failed to find the file. */
10378 warn (_("could not find separate debug file '%s'\n"), separate_filename
);
10379 warn (_("tried: %s\n"), debug_filename
);
10381 #ifdef EXTRA_DEBUG_ROOT2
10382 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT2
, separate_filename
);
10383 warn (_("tried: %s\n"), debug_filename
);
10386 #ifdef EXTRA_DEBUG_ROOT1
10387 sprintf (debug_filename
, "%s/%s/%s", EXTRA_DEBUG_ROOT1
, canon_dir
, separate_filename
);
10388 warn (_("tried: %s\n"), debug_filename
);
10390 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT1
, separate_filename
);
10391 warn (_("tried: %s\n"), debug_filename
);
10394 sprintf (debug_filename
, "%s.debug/%s", canon_dir
, separate_filename
);
10395 warn (_("tried: %s\n"), debug_filename
);
10397 sprintf (debug_filename
, "%s%s", canon_dir
, separate_filename
);
10398 warn (_("tried: %s\n"), debug_filename
);
10400 sprintf (debug_filename
, ".debug/%s", separate_filename
);
10401 warn (_("tried: %s\n"), debug_filename
);
10403 sprintf (debug_filename
, "%s", separate_filename
);
10404 warn (_("tried: %s\n"), debug_filename
);
10407 free (debug_filename
);
10413 void * debug_handle
;
10415 /* Now open the file.... */
10416 if ((debug_handle
= open_debug_file (debug_filename
)) == NULL
)
10418 warn (_("failed to open separate debug file: %s\n"), debug_filename
);
10419 free (debug_filename
);
10423 /* FIXME: We do not check to see if there are any other separate debug info
10424 files that would also match. */
10426 printf (_("%s: Found separate debug info file: %s\n\n"), main_filename
, debug_filename
);
10427 add_separate_debug_file (debug_filename
, debug_handle
);
10429 /* Do not free debug_filename - it might be referenced inside
10430 the structure returned by open_debug_file(). */
10431 return debug_handle
;
10434 /* Attempt to load a separate dwarf object file. */
10437 load_dwo_file (const char * main_filename
, const char * name
, const char * dir
, const char * id ATTRIBUTE_UNUSED
)
10439 char * separate_filename
;
10440 void * separate_handle
;
10442 /* FIXME: Skip adding / if dwo_dir ends in /. */
10443 separate_filename
= concat (dir
, "/", name
, NULL
);
10444 if (separate_filename
== NULL
)
10446 warn (_("Out of memory allocating dwo filename\n"));
10450 if ((separate_handle
= open_debug_file (separate_filename
)) == NULL
)
10452 warn (_("Unable to load dwo file: %s\n"), separate_filename
);
10453 free (separate_filename
);
10457 /* FIXME: We should check the dwo_id. */
10459 printf (_("%s: Found separate debug object file: %s\n\n"), main_filename
, separate_filename
);
10460 add_separate_debug_file (separate_filename
, separate_handle
);
10461 /* Note - separate_filename will be freed in free_debug_memory(). */
10462 return separate_handle
;
10465 /* Load the separate debug info file(s) attached to FILE, if any exist.
10466 Returns TRUE if any were found, FALSE otherwise.
10467 If TRUE is returned then the linked list starting at first_separate_info
10468 will be populated with open file handles. */
10471 load_separate_debug_files (void * file
, const char * filename
)
10473 /* Skip this operation if we are not interested in debug links. */
10474 if (! do_follow_links
&& ! do_debug_links
)
10477 /* See if there are any dwo links. */
10478 if (load_debug_section (str
, file
)
10479 && load_debug_section (abbrev
, file
)
10480 && load_debug_section (info
, file
))
10484 if (process_debug_info (& debug_displays
[info
].section
, file
, abbrev
, TRUE
, FALSE
))
10486 bfd_boolean introduced
= FALSE
;
10488 const char * dir
= NULL
;
10489 const char * id
= NULL
;
10491 for (dwinfo
= first_dwo_info
; dwinfo
!= NULL
; dwinfo
= dwinfo
->next
)
10493 switch (dwinfo
->type
)
10496 if (do_debug_links
)
10500 printf (_("The %s section contains link(s) to dwo file(s):\n\n"),
10501 debug_displays
[info
].section
.uncompressed_name
);
10505 printf (_(" Name: %s\n"), dwinfo
->value
);
10506 printf (_(" Directory: %s\n"), dir
? dir
: _("<not-found>"));
10508 display_data (printf (_(" ID: ")), (unsigned char *) id
, 8);
10510 printf (_(" ID: <unknown>\n"));
10514 if (do_follow_links
)
10515 load_dwo_file (filename
, dwinfo
->value
, dir
, id
);
10519 dir
= dwinfo
->value
;
10523 id
= dwinfo
->value
;
10527 error (_("Unexpected DWO INFO type"));
10534 if (! do_follow_links
)
10535 /* The other debug links will be displayed by display_debug_links()
10536 so we do not need to do any further processing here. */
10539 /* FIXME: We do not check for the presence of both link sections in the same file. */
10540 /* FIXME: We do not check the separate debug info file to see if it too contains debuglinks. */
10541 /* FIXME: We do not check for the presence of multiple, same-name debuglink sections. */
10542 /* FIXME: We do not check for the presence of a dwo link as well as a debuglink. */
10544 if (load_debug_section (gnu_debugaltlink
, file
))
10546 Build_id_data
* build_id_data
;
10548 load_separate_debug_info (filename
,
10549 & debug_displays
[gnu_debugaltlink
].section
,
10550 parse_gnu_debugaltlink
,
10551 check_gnu_debugaltlink
,
10555 if (load_debug_section (gnu_debuglink
, file
))
10557 unsigned long crc32
;
10559 load_separate_debug_info (filename
,
10560 & debug_displays
[gnu_debuglink
].section
,
10561 parse_gnu_debuglink
,
10562 check_gnu_debuglink
,
10566 if (first_separate_info
!= NULL
)
10569 do_follow_links
= 0;
10574 free_debug_memory (void)
10580 for (i
= 0; i
< max
; i
++)
10581 free_debug_section ((enum dwarf_section_display_enum
) i
);
10583 if (debug_information
!= NULL
)
10585 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
)
10587 for (i
= 0; i
< num_debug_info_entries
; i
++)
10589 if (!debug_information
[i
].max_loc_offsets
)
10591 free (debug_information
[i
].loc_offsets
);
10592 free (debug_information
[i
].have_frame_base
);
10594 if (!debug_information
[i
].max_range_lists
)
10595 free (debug_information
[i
].range_lists
);
10598 free (debug_information
);
10599 debug_information
= NULL
;
10600 alloc_num_debug_info_entries
= num_debug_info_entries
= 0;
10604 separate_info
* next
;
10606 for (d
= first_separate_info
; d
!= NULL
; d
= next
)
10608 close_debug_file (d
->handle
);
10609 free ((void *) d
->filename
);
10613 first_separate_info
= NULL
;
10619 dwarf_select_sections_by_names (const char *names
)
10623 const char * option
;
10627 debug_dump_long_opts
;
10629 static const debug_dump_long_opts opts_table
[] =
10631 /* Please keep this table alpha- sorted. */
10632 { "Ranges", & do_debug_ranges
, 1 },
10633 { "abbrev", & do_debug_abbrevs
, 1 },
10634 { "addr", & do_debug_addr
, 1 },
10635 { "aranges", & do_debug_aranges
, 1 },
10636 { "cu_index", & do_debug_cu_index
, 1 },
10637 { "decodedline", & do_debug_lines
, FLAG_DEBUG_LINES_DECODED
},
10638 { "follow-links", & do_follow_links
, 1 },
10639 { "frames", & do_debug_frames
, 1 },
10640 { "frames-interp", & do_debug_frames_interp
, 1 },
10641 /* The special .gdb_index section. */
10642 { "gdb_index", & do_gdb_index
, 1 },
10643 { "info", & do_debug_info
, 1 },
10644 { "line", & do_debug_lines
, FLAG_DEBUG_LINES_RAW
}, /* For backwards compatibility. */
10645 { "links", & do_debug_links
, 1 },
10646 { "loc", & do_debug_loc
, 1 },
10647 { "macro", & do_debug_macinfo
, 1 },
10648 { "pubnames", & do_debug_pubnames
, 1 },
10649 { "pubtypes", & do_debug_pubtypes
, 1 },
10650 /* This entry is for compatibility
10651 with earlier versions of readelf. */
10652 { "ranges", & do_debug_aranges
, 1 },
10653 { "rawline", & do_debug_lines
, FLAG_DEBUG_LINES_RAW
},
10654 { "str", & do_debug_str
, 1 },
10655 /* These trace_* sections are used by Itanium VMS. */
10656 { "trace_abbrev", & do_trace_abbrevs
, 1 },
10657 { "trace_aranges", & do_trace_aranges
, 1 },
10658 { "trace_info", & do_trace_info
, 1 },
10667 const debug_dump_long_opts
* entry
;
10669 for (entry
= opts_table
; entry
->option
; entry
++)
10671 size_t len
= strlen (entry
->option
);
10673 if (strncmp (p
, entry
->option
, len
) == 0
10674 && (p
[len
] == ',' || p
[len
] == '\0'))
10676 * entry
->variable
|= entry
->val
;
10678 /* The --debug-dump=frames-interp option also
10679 enables the --debug-dump=frames option. */
10680 if (do_debug_frames_interp
)
10681 do_debug_frames
= 1;
10688 if (entry
->option
== NULL
)
10690 warn (_("Unrecognized debug option '%s'\n"), p
);
10691 p
= strchr (p
, ',');
10702 dwarf_select_sections_by_letters (const char *letters
)
10704 unsigned int lindex
= 0;
10706 while (letters
[lindex
])
10707 switch (letters
[lindex
++])
10709 case 'A': do_debug_addr
= 1; break;
10710 case 'a': do_debug_abbrevs
= 1; break;
10711 case 'c': do_debug_cu_index
= 1; break;
10712 case 'F': do_debug_frames_interp
= 1; /* Fall through. */
10713 case 'f': do_debug_frames
= 1; break;
10714 case 'g': do_gdb_index
= 1; break;
10715 case 'i': do_debug_info
= 1; break;
10716 case 'K': do_follow_links
= 1; break;
10717 case 'k': do_debug_links
= 1; break;
10718 case 'l': do_debug_lines
|= FLAG_DEBUG_LINES_RAW
; break;
10719 case 'L': do_debug_lines
|= FLAG_DEBUG_LINES_DECODED
; break;
10720 case 'm': do_debug_macinfo
= 1; break;
10721 case 'o': do_debug_loc
= 1; break;
10722 case 'p': do_debug_pubnames
= 1; break;
10723 case 'R': do_debug_ranges
= 1; break;
10724 case 'r': do_debug_aranges
= 1; break;
10725 case 's': do_debug_str
= 1; break;
10726 case 'T': do_trace_aranges
= 1; break;
10727 case 't': do_debug_pubtypes
= 1; break;
10728 case 'U': do_trace_info
= 1; break;
10729 case 'u': do_trace_abbrevs
= 1; break;
10732 warn (_("Unrecognized debug option '%s'\n"), letters
);
10738 dwarf_select_sections_all (void)
10741 do_debug_abbrevs
= 1;
10742 do_debug_lines
= FLAG_DEBUG_LINES_RAW
;
10743 do_debug_pubnames
= 1;
10744 do_debug_pubtypes
= 1;
10745 do_debug_aranges
= 1;
10746 do_debug_ranges
= 1;
10747 do_debug_frames
= 1;
10748 do_debug_macinfo
= 1;
10753 do_trace_abbrevs
= 1;
10754 do_trace_aranges
= 1;
10756 do_debug_cu_index
= 1;
10757 do_follow_links
= 1;
10758 do_debug_links
= 1;
10761 #define NO_ABBREVS NULL, NULL, NULL, 0, 0, 0, NULL, 0, NULL
10762 #define ABBREV(N) NULL, NULL, NULL, 0, 0, N, NULL, 0, NULL
10764 /* N.B. The order here must match the order in section_display_enum. */
10766 struct dwarf_section_display debug_displays
[] =
10768 { { ".debug_abbrev", ".zdebug_abbrev", NO_ABBREVS
}, display_debug_abbrev
, &do_debug_abbrevs
, FALSE
},
10769 { { ".debug_aranges", ".zdebug_aranges", NO_ABBREVS
}, display_debug_aranges
, &do_debug_aranges
, TRUE
},
10770 { { ".debug_frame", ".zdebug_frame", NO_ABBREVS
}, display_debug_frames
, &do_debug_frames
, TRUE
},
10771 { { ".debug_info", ".zdebug_info", ABBREV (abbrev
)}, display_debug_info
, &do_debug_info
, TRUE
},
10772 { { ".debug_line", ".zdebug_line", NO_ABBREVS
}, display_debug_lines
, &do_debug_lines
, TRUE
},
10773 { { ".debug_pubnames", ".zdebug_pubnames", NO_ABBREVS
}, display_debug_pubnames
, &do_debug_pubnames
, FALSE
},
10774 { { ".debug_gnu_pubnames", ".zdebug_gnu_pubnames", NO_ABBREVS
}, display_debug_gnu_pubnames
, &do_debug_pubnames
, FALSE
},
10775 { { ".eh_frame", "", NO_ABBREVS
}, display_debug_frames
, &do_debug_frames
, TRUE
},
10776 { { ".debug_macinfo", ".zdebug_macinfo", NO_ABBREVS
}, display_debug_macinfo
, &do_debug_macinfo
, FALSE
},
10777 { { ".debug_macro", ".zdebug_macro", NO_ABBREVS
}, display_debug_macro
, &do_debug_macinfo
, TRUE
},
10778 { { ".debug_str", ".zdebug_str", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, FALSE
},
10779 { { ".debug_line_str", ".zdebug_line_str", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, FALSE
},
10780 { { ".debug_loc", ".zdebug_loc", NO_ABBREVS
}, display_debug_loc
, &do_debug_loc
, TRUE
},
10781 { { ".debug_loclists", ".zdebug_loclists", NO_ABBREVS
}, display_debug_loc
, &do_debug_loc
, TRUE
},
10782 { { ".debug_pubtypes", ".zdebug_pubtypes", NO_ABBREVS
}, display_debug_pubnames
, &do_debug_pubtypes
, FALSE
},
10783 { { ".debug_gnu_pubtypes", ".zdebug_gnu_pubtypes", NO_ABBREVS
}, display_debug_gnu_pubnames
, &do_debug_pubtypes
, FALSE
},
10784 { { ".debug_ranges", ".zdebug_ranges", NO_ABBREVS
}, display_debug_ranges
, &do_debug_ranges
, TRUE
},
10785 { { ".debug_rnglists", ".zdebug_rnglists", NO_ABBREVS
}, display_debug_ranges
, &do_debug_ranges
, TRUE
},
10786 { { ".debug_static_func", ".zdebug_static_func", NO_ABBREVS
}, display_debug_not_supported
, NULL
, FALSE
},
10787 { { ".debug_static_vars", ".zdebug_static_vars", NO_ABBREVS
}, display_debug_not_supported
, NULL
, FALSE
},
10788 { { ".debug_types", ".zdebug_types", ABBREV (abbrev
) }, display_debug_types
, &do_debug_info
, TRUE
},
10789 { { ".debug_weaknames", ".zdebug_weaknames", NO_ABBREVS
}, display_debug_not_supported
, NULL
, FALSE
},
10790 { { ".gdb_index", "", NO_ABBREVS
}, display_gdb_index
, &do_gdb_index
, FALSE
},
10791 { { ".debug_names", "", NO_ABBREVS
}, display_debug_names
, &do_gdb_index
, FALSE
},
10792 { { ".trace_info", "", ABBREV (trace_abbrev
) }, display_trace_info
, &do_trace_info
, TRUE
},
10793 { { ".trace_abbrev", "", NO_ABBREVS
}, display_debug_abbrev
, &do_trace_abbrevs
, FALSE
},
10794 { { ".trace_aranges", "", NO_ABBREVS
}, display_debug_aranges
, &do_trace_aranges
, FALSE
},
10795 { { ".debug_info.dwo", ".zdebug_info.dwo", ABBREV (abbrev_dwo
) }, display_debug_info
, &do_debug_info
, TRUE
},
10796 { { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo", NO_ABBREVS
}, display_debug_abbrev
, &do_debug_abbrevs
, FALSE
},
10797 { { ".debug_types.dwo", ".zdebug_types.dwo", ABBREV (abbrev_dwo
) }, display_debug_types
, &do_debug_info
, TRUE
},
10798 { { ".debug_line.dwo", ".zdebug_line.dwo", NO_ABBREVS
}, display_debug_lines
, &do_debug_lines
, TRUE
},
10799 { { ".debug_loc.dwo", ".zdebug_loc.dwo", NO_ABBREVS
}, display_debug_loc
, &do_debug_loc
, TRUE
},
10800 { { ".debug_macro.dwo", ".zdebug_macro.dwo", NO_ABBREVS
}, display_debug_macro
, &do_debug_macinfo
, TRUE
},
10801 { { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo", NO_ABBREVS
}, display_debug_macinfo
, &do_debug_macinfo
, FALSE
},
10802 { { ".debug_str.dwo", ".zdebug_str.dwo", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, TRUE
},
10803 { { ".debug_str_offsets", ".zdebug_str_offsets", NO_ABBREVS
}, display_debug_str_offsets
, NULL
, FALSE
},
10804 { { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo", NO_ABBREVS
}, display_debug_str_offsets
, NULL
, FALSE
},
10805 { { ".debug_addr", ".zdebug_addr", NO_ABBREVS
}, display_debug_addr
, &do_debug_addr
, TRUE
},
10806 { { ".debug_cu_index", "", NO_ABBREVS
}, display_cu_index
, &do_debug_cu_index
, FALSE
},
10807 { { ".debug_tu_index", "", NO_ABBREVS
}, display_cu_index
, &do_debug_cu_index
, FALSE
},
10808 { { ".gnu_debuglink", "", NO_ABBREVS
}, display_debug_links
, &do_debug_links
, FALSE
},
10809 { { ".gnu_debugaltlink", "", NO_ABBREVS
}, display_debug_links
, &do_debug_links
, FALSE
},
10810 /* Separate debug info files can containt their own .debug_str section,
10811 and this might be in *addition* to a .debug_str section already present
10812 in the main file. Hence we need to have two entries for .debug_str. */
10813 { { ".debug_str", ".zdebug_str", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, FALSE
},
10816 /* A static assertion. */
10817 extern int debug_displays_assert
[ARRAY_SIZE (debug_displays
) == max
? 1 : -1];