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 /* FIXME: Testing "(start + uvalue) < start" miscompiles with gcc 4.8.3
1852 running on an x86_64 host in 32-bit mode. So we pre-compute the value
1854 const unsigned char * ptr
= start
+ uvalue
;
1856 /* See PR 17512: file: 008-103549-0.001:0.1.
1857 and PR 24829 for examples of where these tests are triggered. */
1858 if (uvalue
> max_uvalue
1862 warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue
);
1863 uvalue
= max_uvalue
;
1869 static unsigned char *
1870 skip_attr_bytes (unsigned long form
,
1871 unsigned char * data
,
1872 unsigned const char * end
,
1873 dwarf_vma pointer_size
,
1874 dwarf_vma offset_size
,
1876 dwarf_vma
* value_return
)
1878 unsigned int bytes_read
;
1879 dwarf_vma uvalue
= 0;
1885 case DW_FORM_ref_addr
:
1886 if (dwarf_version
== 2)
1887 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1888 else if (dwarf_version
== 3 || dwarf_version
== 4)
1889 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1895 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1899 case DW_FORM_line_strp
:
1900 case DW_FORM_sec_offset
:
1901 case DW_FORM_GNU_ref_alt
:
1902 case DW_FORM_GNU_strp_alt
:
1903 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1906 case DW_FORM_flag_present
:
1913 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1918 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
1923 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1927 uvalue
= read_sleb128 (data
, & bytes_read
, end
);
1931 case DW_FORM_ref_udata
:
1933 case DW_FORM_GNU_str_index
:
1934 case DW_FORM_GNU_addr_index
:
1935 uvalue
= read_uleb128 (data
, & bytes_read
, end
);
1944 case DW_FORM_data16
:
1948 case DW_FORM_string
:
1949 data
+= strnlen ((char *) data
, end
- data
) + 1;
1953 case DW_FORM_exprloc
:
1954 uvalue
= read_uleb128 (data
, & bytes_read
, end
);
1955 data
+= bytes_read
+ uvalue
;
1958 case DW_FORM_block1
:
1959 SAFE_BYTE_GET (uvalue
, data
, 1, end
);
1963 case DW_FORM_block2
:
1964 SAFE_BYTE_GET (uvalue
, data
, 2, end
);
1968 case DW_FORM_block4
:
1969 SAFE_BYTE_GET (uvalue
, data
, 4, end
);
1973 case DW_FORM_ref_sig8
:
1977 case DW_FORM_indirect
:
1978 /* FIXME: Handle this form. */
1983 * value_return
= uvalue
;
1985 data
= (unsigned char *) end
;
1989 /* Return IS_SIGNED set to TRUE if the type at
1990 DATA can be determined to be a signed type. */
1993 get_type_signedness (unsigned char * start
,
1994 unsigned char * data
,
1995 unsigned const char * end
,
1996 dwarf_vma pointer_size
,
1997 dwarf_vma offset_size
,
1999 bfd_boolean
* is_signed
,
2000 bfd_boolean is_nested
)
2002 unsigned long abbrev_number
;
2003 unsigned int bytes_read
;
2004 abbrev_entry
* entry
;
2007 * is_signed
= FALSE
;
2012 abbrev_number
= read_uleb128 (data
, & bytes_read
, end
);
2015 for (entry
= first_abbrev
;
2016 entry
!= NULL
&& entry
->entry
!= abbrev_number
;
2017 entry
= entry
->next
)
2021 /* FIXME: Issue a warning ? */
2024 for (attr
= entry
->first_attr
;
2025 attr
!= NULL
&& attr
->attribute
;
2028 dwarf_vma uvalue
= 0;
2030 data
= skip_attr_bytes (attr
->form
, data
, end
, pointer_size
,
2031 offset_size
, dwarf_version
, & uvalue
);
2035 switch (attr
->attribute
)
2037 #if 0 /* FIXME: It would be nice to print the name of the type,
2038 but this would mean updating a lot of binutils tests. */
2040 if (attr
->form
== DW_FORM_strp
)
2041 printf ("%s", fetch_indirect_string (uvalue
));
2048 /* FIXME: Warn - or is this expected ?
2049 NB/ We need to avoid infinite recursion. */
2052 get_type_signedness (start
, start
+ uvalue
, end
, pointer_size
,
2053 offset_size
, dwarf_version
, is_signed
, TRUE
);
2056 case DW_AT_encoding
:
2057 /* Determine signness. */
2060 case DW_ATE_address
:
2061 /* FIXME - some architectures have signed addresses. */
2062 case DW_ATE_boolean
:
2063 case DW_ATE_unsigned
:
2064 case DW_ATE_unsigned_char
:
2065 case DW_ATE_unsigned_fixed
:
2066 * is_signed
= FALSE
;
2070 case DW_ATE_complex_float
:
2073 case DW_ATE_signed_char
:
2074 case DW_ATE_imaginary_float
:
2075 case DW_ATE_decimal_float
:
2076 case DW_ATE_signed_fixed
:
2086 read_and_print_leb128 (unsigned char * data
,
2087 unsigned int * bytes_read
,
2088 unsigned const char * end
,
2089 bfd_boolean is_signed
)
2093 dwarf_signed_vma sval
= read_sleb128 (data
, bytes_read
, end
);
2094 printf ("%ld", (long) sval
);
2098 dwarf_vma uval
= read_uleb128 (data
, bytes_read
, end
);
2099 printf ("%lu", (unsigned long) uval
);
2104 display_discr_list (unsigned long form
,
2106 unsigned char * data
,
2107 unsigned const char * end
,
2112 printf ("[default]");
2119 case DW_FORM_block1
:
2120 case DW_FORM_block2
:
2121 case DW_FORM_block4
:
2122 /* Move data pointer back to the start of the byte array. */
2126 printf ("<corrupt>\n");
2127 warn (_("corrupt discr_list - not using a block form\n"));
2133 printf ("<corrupt>\n");
2134 warn (_("corrupt discr_list - block not long enough\n"));
2138 bfd_boolean is_signed
=
2139 (level
> 0 && level
<= MAX_CU_NESTING
)
2140 ? level_type_signed
[level
- 1] : FALSE
;
2145 unsigned char discriminant
;
2146 unsigned int bytes_read
;
2148 SAFE_BYTE_GET (discriminant
, data
, 1, end
);
2152 assert (uvalue
> 0);
2153 switch (discriminant
)
2157 read_and_print_leb128 (data
, & bytes_read
, end
, is_signed
);
2158 assert (bytes_read
<= uvalue
&& bytes_read
> 0);
2159 uvalue
-= bytes_read
;
2165 read_and_print_leb128 (data
, & bytes_read
, end
, is_signed
);
2166 assert (bytes_read
<= uvalue
&& bytes_read
> 0);
2167 uvalue
-= bytes_read
;
2171 read_and_print_leb128 (data
, & bytes_read
, end
, is_signed
);
2172 assert (bytes_read
<= uvalue
&& bytes_read
> 0);
2173 uvalue
-= bytes_read
;
2178 printf ("<corrupt>\n");
2179 warn (_("corrupt discr_list - unrecognised discriminant byte %#x\n"),
2189 printf (")(signed)");
2191 printf (")(unsigned)");
2194 static unsigned char *
2195 read_and_display_attr_value (unsigned long attribute
,
2197 dwarf_signed_vma implicit_const
,
2198 unsigned char * start
,
2199 unsigned char * data
,
2200 unsigned char * end
,
2201 dwarf_vma cu_offset
,
2202 dwarf_vma pointer_size
,
2203 dwarf_vma offset_size
,
2205 debug_info
* debug_info_p
,
2207 struct dwarf_section
* section
,
2208 struct cu_tu_set
* this_set
,
2212 dwarf_vma uvalue
= 0;
2213 unsigned char * block_start
= NULL
;
2214 unsigned char * orig_data
= data
;
2215 unsigned int bytes_read
;
2217 if (data
> end
|| (data
== end
&& form
!= DW_FORM_flag_present
))
2219 warn (_("Corrupt attribute\n"));
2228 case DW_FORM_ref_addr
:
2229 if (dwarf_version
== 2)
2230 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
2231 else if (dwarf_version
== 3 || dwarf_version
== 4)
2232 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
2234 error (_("Internal error: DWARF version is not 2, 3 or 4.\n"));
2239 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
2243 case DW_FORM_line_strp
:
2244 case DW_FORM_sec_offset
:
2245 case DW_FORM_GNU_ref_alt
:
2246 case DW_FORM_GNU_strp_alt
:
2247 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
2250 case DW_FORM_flag_present
:
2257 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
2262 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
2267 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
2271 uvalue
= read_sleb128 (data
, & bytes_read
, end
);
2275 case DW_FORM_GNU_str_index
:
2276 uvalue
= read_uleb128 (data
, & bytes_read
, end
);
2280 case DW_FORM_ref_udata
:
2282 uvalue
= read_uleb128 (data
, & bytes_read
, end
);
2286 case DW_FORM_indirect
:
2287 form
= read_uleb128 (data
, & bytes_read
, end
);
2290 printf ("%c%s", delimiter
, get_FORM_name (form
));
2291 if (form
== DW_FORM_implicit_const
)
2293 implicit_const
= read_sleb128 (data
, & bytes_read
, end
);
2296 return read_and_display_attr_value (attribute
, form
, implicit_const
,
2298 cu_offset
, pointer_size
,
2299 offset_size
, dwarf_version
,
2300 debug_info_p
, do_loc
,
2301 section
, this_set
, delimiter
, level
);
2302 case DW_FORM_GNU_addr_index
:
2303 uvalue
= read_uleb128 (data
, & bytes_read
, end
);
2310 case DW_FORM_ref_addr
:
2312 printf ("%c<0x%s>", delimiter
, dwarf_vmatoa ("x",uvalue
));
2315 case DW_FORM_GNU_ref_alt
:
2317 printf ("%c<alt 0x%s>", delimiter
, dwarf_vmatoa ("x",uvalue
));
2318 /* FIXME: Follow the reference... */
2324 case DW_FORM_ref_udata
:
2326 printf ("%c<0x%s>", delimiter
, dwarf_vmatoa ("x", uvalue
+ cu_offset
));
2331 case DW_FORM_sec_offset
:
2333 printf ("%c0x%s", delimiter
, dwarf_vmatoa ("x", uvalue
));
2336 case DW_FORM_flag_present
:
2343 printf ("%c%s", delimiter
, dwarf_vmatoa ("d", uvalue
));
2346 case DW_FORM_implicit_const
:
2348 printf ("%c%s", delimiter
, dwarf_vmatoa ("d", implicit_const
));
2355 dwarf_vma high_bits
;
2359 SAFE_BYTE_GET64 (data
, &high_bits
, &uvalue
, end
);
2361 if (form
== DW_FORM_ref8
)
2362 add64 (& high_bits
, & utmp
, cu_offset
);
2363 printf ("%c0x%s", delimiter
,
2364 dwarf_vmatoa64 (high_bits
, utmp
, buf
, sizeof (buf
)));
2367 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
2368 && num_debug_info_entries
== 0)
2370 if (sizeof (uvalue
) == 8)
2371 SAFE_BYTE_GET (uvalue
, data
, 8, end
);
2373 error (_("DW_FORM_data8 is unsupported when sizeof (dwarf_vma) != 8\n"));
2379 case DW_FORM_data16
:
2382 dwarf_vma left_high_bits
, left_low_bits
;
2383 dwarf_vma right_high_bits
, right_low_bits
;
2385 SAFE_BYTE_GET64 (data
, &left_high_bits
, &left_low_bits
, end
);
2386 SAFE_BYTE_GET64 (data
+ 8, &right_high_bits
, &right_low_bits
, end
);
2387 if (byte_get
== byte_get_little_endian
)
2390 left_high_bits
^= right_high_bits
;
2391 right_high_bits
^= left_high_bits
;
2392 left_high_bits
^= right_high_bits
;
2393 left_low_bits
^= right_low_bits
;
2394 right_low_bits
^= left_low_bits
;
2395 left_low_bits
^= right_low_bits
;
2397 printf (" 0x%08" DWARF_VMA_FMT
"x%08" DWARF_VMA_FMT
"x"
2398 "%08" DWARF_VMA_FMT
"x%08" DWARF_VMA_FMT
"x",
2399 left_high_bits
, left_low_bits
, right_high_bits
,
2405 case DW_FORM_string
:
2407 printf ("%c%.*s", delimiter
, (int) (end
- data
), data
);
2408 data
+= strnlen ((char *) data
, end
- data
) + 1;
2412 case DW_FORM_exprloc
:
2413 uvalue
= read_uleb128 (data
, & bytes_read
, end
);
2414 block_start
= data
+ bytes_read
;
2415 if (block_start
>= end
)
2417 warn (_("Block ends prematurely\n"));
2422 uvalue
= check_uvalue (block_start
, uvalue
, end
);
2425 data
= block_start
+ uvalue
;
2427 data
= display_block (block_start
, uvalue
, end
, delimiter
);
2430 case DW_FORM_block1
:
2431 SAFE_BYTE_GET (uvalue
, data
, 1, end
);
2432 block_start
= data
+ 1;
2433 if (block_start
>= end
)
2435 warn (_("Block ends prematurely\n"));
2440 uvalue
= check_uvalue (block_start
, uvalue
, end
);
2443 data
= block_start
+ uvalue
;
2445 data
= display_block (block_start
, uvalue
, end
, delimiter
);
2448 case DW_FORM_block2
:
2449 SAFE_BYTE_GET (uvalue
, data
, 2, end
);
2450 block_start
= data
+ 2;
2451 if (block_start
>= end
)
2453 warn (_("Block ends prematurely\n"));
2458 uvalue
= check_uvalue (block_start
, uvalue
, end
);
2461 data
= block_start
+ uvalue
;
2463 data
= display_block (block_start
, uvalue
, end
, delimiter
);
2466 case DW_FORM_block4
:
2467 SAFE_BYTE_GET (uvalue
, data
, 4, end
);
2468 block_start
= data
+ 4;
2469 /* PR 17512: file: 3371-3907-0.004. */
2470 if (block_start
>= end
)
2472 warn (_("Block ends prematurely\n"));
2477 uvalue
= check_uvalue (block_start
, uvalue
, end
);
2480 data
= block_start
+ uvalue
;
2482 data
= display_block (block_start
, uvalue
, end
, delimiter
);
2487 printf (_("%c(indirect string, offset: 0x%s): %s"), delimiter
,
2488 dwarf_vmatoa ("x", uvalue
),
2489 fetch_indirect_string (uvalue
));
2492 case DW_FORM_line_strp
:
2494 printf (_("%c(indirect line string, offset: 0x%s): %s"), delimiter
,
2495 dwarf_vmatoa ("x", uvalue
),
2496 fetch_indirect_line_string (uvalue
));
2499 case DW_FORM_GNU_str_index
:
2502 const char * suffix
= strrchr (section
->name
, '.');
2503 bfd_boolean dwo
= (suffix
&& strcmp (suffix
, ".dwo") == 0) ? TRUE
: FALSE
;
2505 printf (_("%c(indexed string: 0x%s): %s"), delimiter
,
2506 dwarf_vmatoa ("x", uvalue
),
2507 fetch_indexed_string (uvalue
, this_set
, offset_size
, dwo
));
2511 case DW_FORM_GNU_strp_alt
:
2514 printf (_("%c(alt indirect string, offset: 0x%s) %s"), delimiter
,
2515 dwarf_vmatoa ("x", uvalue
),
2516 fetch_alt_indirect_string (uvalue
));
2520 case DW_FORM_indirect
:
2521 /* Handled above. */
2524 case DW_FORM_ref_sig8
:
2527 dwarf_vma high_bits
;
2530 SAFE_BYTE_GET64 (data
, &high_bits
, &uvalue
, end
);
2531 printf ("%csignature: 0x%s", delimiter
,
2532 dwarf_vmatoa64 (high_bits
, uvalue
, buf
, sizeof (buf
)));
2537 case DW_FORM_GNU_addr_index
:
2539 printf (_("%c(addr_index: 0x%s): %s"), delimiter
,
2540 dwarf_vmatoa ("x", uvalue
),
2541 fetch_indexed_value (uvalue
* pointer_size
, pointer_size
));
2545 warn (_("Unrecognized form: %lu\n"), form
);
2549 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
2550 && num_debug_info_entries
== 0
2551 && debug_info_p
!= NULL
)
2555 case DW_AT_frame_base
:
2556 have_frame_base
= 1;
2558 case DW_AT_location
:
2559 case DW_AT_GNU_locviews
:
2560 case DW_AT_string_length
:
2561 case DW_AT_return_addr
:
2562 case DW_AT_data_member_location
:
2563 case DW_AT_vtable_elem_location
:
2565 case DW_AT_static_link
:
2566 case DW_AT_use_location
:
2567 case DW_AT_call_value
:
2568 case DW_AT_GNU_call_site_value
:
2569 case DW_AT_call_data_value
:
2570 case DW_AT_GNU_call_site_data_value
:
2571 case DW_AT_call_target
:
2572 case DW_AT_GNU_call_site_target
:
2573 case DW_AT_call_target_clobbered
:
2574 case DW_AT_GNU_call_site_target_clobbered
:
2575 if ((dwarf_version
< 4
2576 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
2577 || form
== DW_FORM_sec_offset
)
2579 /* Process location list. */
2580 unsigned int lmax
= debug_info_p
->max_loc_offsets
;
2581 unsigned int num
= debug_info_p
->num_loc_offsets
;
2583 if (lmax
== 0 || num
>= lmax
)
2586 debug_info_p
->loc_offsets
= (dwarf_vma
*)
2587 xcrealloc (debug_info_p
->loc_offsets
,
2588 lmax
, sizeof (*debug_info_p
->loc_offsets
));
2589 debug_info_p
->loc_views
= (dwarf_vma
*)
2590 xcrealloc (debug_info_p
->loc_views
,
2591 lmax
, sizeof (*debug_info_p
->loc_views
));
2592 debug_info_p
->have_frame_base
= (int *)
2593 xcrealloc (debug_info_p
->have_frame_base
,
2594 lmax
, sizeof (*debug_info_p
->have_frame_base
));
2595 debug_info_p
->max_loc_offsets
= lmax
;
2597 if (this_set
!= NULL
)
2598 uvalue
+= this_set
->section_offsets
[DW_SECT_LOC
];
2599 debug_info_p
->have_frame_base
[num
] = have_frame_base
;
2600 if (attribute
!= DW_AT_GNU_locviews
)
2602 /* Corrupt DWARF info can produce more offsets than views.
2603 See PR 23062 for an example. */
2604 if (debug_info_p
->num_loc_offsets
2605 > debug_info_p
->num_loc_views
)
2606 warn (_("More location offset attributes than DW_AT_GNU_locview attributes\n"));
2609 debug_info_p
->loc_offsets
[num
] = uvalue
;
2610 debug_info_p
->num_loc_offsets
++;
2615 assert (debug_info_p
->num_loc_views
<= num
);
2616 num
= debug_info_p
->num_loc_views
;
2617 if (num
> debug_info_p
->num_loc_offsets
)
2618 warn (_("More DW_AT_GNU_locview attributes than location offset attributes\n"));
2621 debug_info_p
->loc_views
[num
] = uvalue
;
2622 debug_info_p
->num_loc_views
++;
2629 if (need_base_address
)
2630 debug_info_p
->base_address
= uvalue
;
2633 case DW_AT_GNU_addr_base
:
2634 debug_info_p
->addr_base
= uvalue
;
2637 case DW_AT_GNU_ranges_base
:
2638 debug_info_p
->ranges_base
= uvalue
;
2642 if ((dwarf_version
< 4
2643 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
2644 || form
== DW_FORM_sec_offset
)
2646 /* Process range list. */
2647 unsigned int lmax
= debug_info_p
->max_range_lists
;
2648 unsigned int num
= debug_info_p
->num_range_lists
;
2650 if (lmax
== 0 || num
>= lmax
)
2653 debug_info_p
->range_lists
= (dwarf_vma
*)
2654 xcrealloc (debug_info_p
->range_lists
,
2655 lmax
, sizeof (*debug_info_p
->range_lists
));
2656 debug_info_p
->max_range_lists
= lmax
;
2658 debug_info_p
->range_lists
[num
] = uvalue
;
2659 debug_info_p
->num_range_lists
++;
2663 case DW_AT_GNU_dwo_name
:
2664 case DW_AT_dwo_name
:
2669 add_dwo_name ((const char *) fetch_indirect_string (uvalue
));
2671 case DW_FORM_GNU_str_index
:
2672 add_dwo_name (fetch_indexed_string (uvalue
, this_set
, offset_size
, FALSE
));
2674 case DW_FORM_string
:
2675 add_dwo_name ((const char *) orig_data
);
2678 warn (_("Unsupported form (%s) for attribute %s\n"),
2679 get_FORM_name (form
), get_AT_name (attribute
));
2684 case DW_AT_comp_dir
:
2685 /* FIXME: Also extract a build-id in a CU/TU. */
2690 add_dwo_dir ((const char *) fetch_indirect_string (uvalue
));
2692 case DW_FORM_line_strp
:
2693 add_dwo_dir ((const char *) fetch_indirect_line_string (uvalue
));
2695 case DW_FORM_GNU_str_index
:
2696 add_dwo_dir (fetch_indexed_string (uvalue
, this_set
, offset_size
, FALSE
));
2698 case DW_FORM_string
:
2699 add_dwo_dir ((const char *) orig_data
);
2702 warn (_("Unsupported form (%s) for attribute %s\n"),
2703 get_FORM_name (form
), get_AT_name (attribute
));
2708 case DW_AT_GNU_dwo_id
:
2713 /* FIXME: Record the length of the ID as well ? */
2714 add_dwo_id ((const char *) (data
- 8));
2717 warn (_("Unsupported form (%s) for attribute %s\n"),
2718 get_FORM_name (form
), get_AT_name (attribute
));
2728 if (do_loc
|| attribute
== 0)
2731 /* For some attributes we can display further information. */
2735 if (level
>= 0 && level
< MAX_CU_NESTING
)
2737 bfd_boolean is_signed
= FALSE
;
2739 get_type_signedness (start
, start
+ uvalue
, end
, pointer_size
,
2740 offset_size
, dwarf_version
, & is_signed
, FALSE
);
2741 level_type_signed
[level
] = is_signed
;
2749 case DW_INL_not_inlined
:
2750 printf (_("(not inlined)"));
2752 case DW_INL_inlined
:
2753 printf (_("(inlined)"));
2755 case DW_INL_declared_not_inlined
:
2756 printf (_("(declared as inline but ignored)"));
2758 case DW_INL_declared_inlined
:
2759 printf (_("(declared as inline and inlined)"));
2762 printf (_(" (Unknown inline attribute value: %s)"),
2763 dwarf_vmatoa ("x", uvalue
));
2768 case DW_AT_language
:
2772 /* Ordered by the numeric value of these constants. */
2773 case DW_LANG_C89
: printf ("(ANSI C)"); break;
2774 case DW_LANG_C
: printf ("(non-ANSI C)"); break;
2775 case DW_LANG_Ada83
: printf ("(Ada)"); break;
2776 case DW_LANG_C_plus_plus
: printf ("(C++)"); break;
2777 case DW_LANG_Cobol74
: printf ("(Cobol 74)"); break;
2778 case DW_LANG_Cobol85
: printf ("(Cobol 85)"); break;
2779 case DW_LANG_Fortran77
: printf ("(FORTRAN 77)"); break;
2780 case DW_LANG_Fortran90
: printf ("(Fortran 90)"); break;
2781 case DW_LANG_Pascal83
: printf ("(ANSI Pascal)"); break;
2782 case DW_LANG_Modula2
: printf ("(Modula 2)"); break;
2783 /* DWARF 2.1 values. */
2784 case DW_LANG_Java
: printf ("(Java)"); break;
2785 case DW_LANG_C99
: printf ("(ANSI C99)"); break;
2786 case DW_LANG_Ada95
: printf ("(ADA 95)"); break;
2787 case DW_LANG_Fortran95
: printf ("(Fortran 95)"); break;
2788 /* DWARF 3 values. */
2789 case DW_LANG_PLI
: printf ("(PLI)"); break;
2790 case DW_LANG_ObjC
: printf ("(Objective C)"); break;
2791 case DW_LANG_ObjC_plus_plus
: printf ("(Objective C++)"); break;
2792 case DW_LANG_UPC
: printf ("(Unified Parallel C)"); break;
2793 case DW_LANG_D
: printf ("(D)"); break;
2794 /* DWARF 4 values. */
2795 case DW_LANG_Python
: printf ("(Python)"); break;
2796 /* DWARF 5 values. */
2797 case DW_LANG_OpenCL
: printf ("(OpenCL)"); break;
2798 case DW_LANG_Go
: printf ("(Go)"); break;
2799 case DW_LANG_Modula3
: printf ("(Modula 3)"); break;
2800 case DW_LANG_Haskell
: printf ("(Haskell)"); break;
2801 case DW_LANG_C_plus_plus_03
: printf ("(C++03)"); break;
2802 case DW_LANG_C_plus_plus_11
: printf ("(C++11)"); break;
2803 case DW_LANG_OCaml
: printf ("(OCaml)"); break;
2804 case DW_LANG_Rust
: printf ("(Rust)"); break;
2805 case DW_LANG_C11
: printf ("(C11)"); break;
2806 case DW_LANG_Swift
: printf ("(Swift)"); break;
2807 case DW_LANG_Julia
: printf ("(Julia)"); break;
2808 case DW_LANG_Dylan
: printf ("(Dylan)"); break;
2809 case DW_LANG_C_plus_plus_14
: printf ("(C++14)"); break;
2810 case DW_LANG_Fortran03
: printf ("(Fortran 03)"); break;
2811 case DW_LANG_Fortran08
: printf ("(Fortran 08)"); break;
2812 case DW_LANG_RenderScript
: printf ("(RenderScript)"); break;
2813 /* MIPS extension. */
2814 case DW_LANG_Mips_Assembler
: printf ("(MIPS assembler)"); break;
2815 /* UPC extension. */
2816 case DW_LANG_Upc
: printf ("(Unified Parallel C)"); break;
2818 if (uvalue
>= DW_LANG_lo_user
&& uvalue
<= DW_LANG_hi_user
)
2819 printf (_("(implementation defined: %s)"),
2820 dwarf_vmatoa ("x", uvalue
));
2822 printf (_("(Unknown: %s)"), dwarf_vmatoa ("x", uvalue
));
2827 case DW_AT_encoding
:
2831 case DW_ATE_void
: printf ("(void)"); break;
2832 case DW_ATE_address
: printf ("(machine address)"); break;
2833 case DW_ATE_boolean
: printf ("(boolean)"); break;
2834 case DW_ATE_complex_float
: printf ("(complex float)"); break;
2835 case DW_ATE_float
: printf ("(float)"); break;
2836 case DW_ATE_signed
: printf ("(signed)"); break;
2837 case DW_ATE_signed_char
: printf ("(signed char)"); break;
2838 case DW_ATE_unsigned
: printf ("(unsigned)"); break;
2839 case DW_ATE_unsigned_char
: printf ("(unsigned char)"); break;
2840 /* DWARF 2.1 values: */
2841 case DW_ATE_imaginary_float
: printf ("(imaginary float)"); break;
2842 case DW_ATE_decimal_float
: printf ("(decimal float)"); break;
2843 /* DWARF 3 values: */
2844 case DW_ATE_packed_decimal
: printf ("(packed_decimal)"); break;
2845 case DW_ATE_numeric_string
: printf ("(numeric_string)"); break;
2846 case DW_ATE_edited
: printf ("(edited)"); break;
2847 case DW_ATE_signed_fixed
: printf ("(signed_fixed)"); break;
2848 case DW_ATE_unsigned_fixed
: printf ("(unsigned_fixed)"); break;
2849 /* DWARF 4 values: */
2850 case DW_ATE_UTF
: printf ("(unicode string)"); break;
2851 /* DWARF 5 values: */
2852 case DW_ATE_UCS
: printf ("(UCS)"); break;
2853 case DW_ATE_ASCII
: printf ("(ASCII)"); break;
2855 /* HP extensions: */
2856 case DW_ATE_HP_float80
: printf ("(HP_float80)"); break;
2857 case DW_ATE_HP_complex_float80
: printf ("(HP_complex_float80)"); break;
2858 case DW_ATE_HP_float128
: printf ("(HP_float128)"); break;
2859 case DW_ATE_HP_complex_float128
:printf ("(HP_complex_float128)"); break;
2860 case DW_ATE_HP_floathpintel
: printf ("(HP_floathpintel)"); break;
2861 case DW_ATE_HP_imaginary_float80
: printf ("(HP_imaginary_float80)"); break;
2862 case DW_ATE_HP_imaginary_float128
: printf ("(HP_imaginary_float128)"); break;
2865 if (uvalue
>= DW_ATE_lo_user
2866 && uvalue
<= DW_ATE_hi_user
)
2867 printf (_("(user defined type)"));
2869 printf (_("(unknown type)"));
2874 case DW_AT_accessibility
:
2878 case DW_ACCESS_public
: printf ("(public)"); break;
2879 case DW_ACCESS_protected
: printf ("(protected)"); break;
2880 case DW_ACCESS_private
: printf ("(private)"); break;
2882 printf (_("(unknown accessibility)"));
2887 case DW_AT_visibility
:
2891 case DW_VIS_local
: printf ("(local)"); break;
2892 case DW_VIS_exported
: printf ("(exported)"); break;
2893 case DW_VIS_qualified
: printf ("(qualified)"); break;
2894 default: printf (_("(unknown visibility)")); break;
2898 case DW_AT_endianity
:
2902 case DW_END_default
: printf ("(default)"); break;
2903 case DW_END_big
: printf ("(big)"); break;
2904 case DW_END_little
: printf ("(little)"); break;
2906 if (uvalue
>= DW_END_lo_user
&& uvalue
<= DW_END_hi_user
)
2907 printf (_("(user specified)"));
2909 printf (_("(unknown endianity)"));
2914 case DW_AT_virtuality
:
2918 case DW_VIRTUALITY_none
: printf ("(none)"); break;
2919 case DW_VIRTUALITY_virtual
: printf ("(virtual)"); break;
2920 case DW_VIRTUALITY_pure_virtual
:printf ("(pure_virtual)"); break;
2921 default: printf (_("(unknown virtuality)")); break;
2925 case DW_AT_identifier_case
:
2929 case DW_ID_case_sensitive
: printf ("(case_sensitive)"); break;
2930 case DW_ID_up_case
: printf ("(up_case)"); break;
2931 case DW_ID_down_case
: printf ("(down_case)"); break;
2932 case DW_ID_case_insensitive
: printf ("(case_insensitive)"); break;
2933 default: printf (_("(unknown case)")); break;
2937 case DW_AT_calling_convention
:
2941 case DW_CC_normal
: printf ("(normal)"); break;
2942 case DW_CC_program
: printf ("(program)"); break;
2943 case DW_CC_nocall
: printf ("(nocall)"); break;
2944 case DW_CC_pass_by_reference
: printf ("(pass by ref)"); break;
2945 case DW_CC_pass_by_value
: printf ("(pass by value)"); break;
2946 case DW_CC_GNU_renesas_sh
: printf ("(Rensas SH)"); break;
2947 case DW_CC_GNU_borland_fastcall_i386
: printf ("(Borland fastcall i386)"); break;
2949 if (uvalue
>= DW_CC_lo_user
2950 && uvalue
<= DW_CC_hi_user
)
2951 printf (_("(user defined)"));
2953 printf (_("(unknown convention)"));
2957 case DW_AT_ordering
:
2962 case -1: printf (_("(undefined)")); break;
2963 case 0: printf ("(row major)"); break;
2964 case 1: printf ("(column major)"); break;
2968 case DW_AT_decimal_sign
:
2972 case DW_DS_unsigned
: printf (_("(unsigned)")); break;
2973 case DW_DS_leading_overpunch
: printf (_("(leading overpunch)")); break;
2974 case DW_DS_trailing_overpunch
: printf (_("(trailing overpunch)")); break;
2975 case DW_DS_leading_separate
: printf (_("(leading separate)")); break;
2976 case DW_DS_trailing_separate
: printf (_("(trailing separate)")); break;
2977 default: printf (_("(unrecognised)")); break;
2981 case DW_AT_defaulted
:
2985 case DW_DEFAULTED_no
: printf (_("(no)")); break;
2986 case DW_DEFAULTED_in_class
: printf (_("(in class)")); break;
2987 case DW_DEFAULTED_out_of_class
: printf (_("(out of class)")); break;
2988 default: printf (_("(unrecognised)")); break;
2992 case DW_AT_discr_list
:
2994 display_discr_list (form
, uvalue
, data
, end
, level
);
2997 case DW_AT_frame_base
:
2998 have_frame_base
= 1;
3000 case DW_AT_location
:
3001 case DW_AT_string_length
:
3002 case DW_AT_return_addr
:
3003 case DW_AT_data_member_location
:
3004 case DW_AT_vtable_elem_location
:
3006 case DW_AT_static_link
:
3007 case DW_AT_use_location
:
3008 case DW_AT_call_value
:
3009 case DW_AT_GNU_call_site_value
:
3010 case DW_AT_call_data_value
:
3011 case DW_AT_GNU_call_site_data_value
:
3012 case DW_AT_call_target
:
3013 case DW_AT_GNU_call_site_target
:
3014 case DW_AT_call_target_clobbered
:
3015 case DW_AT_GNU_call_site_target_clobbered
:
3016 if ((dwarf_version
< 4
3017 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
3018 || form
== DW_FORM_sec_offset
)
3019 printf (_(" (location list)"));
3021 case DW_AT_allocated
:
3022 case DW_AT_associated
:
3023 case DW_AT_data_location
:
3025 case DW_AT_upper_bound
:
3026 case DW_AT_lower_bound
:
3029 int need_frame_base
;
3032 need_frame_base
= decode_location_expression (block_start
,
3037 cu_offset
, section
);
3039 if (need_frame_base
&& !have_frame_base
)
3040 printf (_(" [without DW_AT_frame_base]"));
3044 case DW_AT_data_bit_offset
:
3045 case DW_AT_byte_size
:
3046 case DW_AT_bit_size
:
3047 case DW_AT_string_length_byte_size
:
3048 case DW_AT_string_length_bit_size
:
3049 case DW_AT_bit_stride
:
3050 if (form
== DW_FORM_exprloc
)
3053 (void) decode_location_expression (block_start
, pointer_size
,
3054 offset_size
, dwarf_version
,
3055 uvalue
, cu_offset
, section
);
3062 if (form
== DW_FORM_ref_sig8
3063 || form
== DW_FORM_GNU_ref_alt
)
3066 if (form
== DW_FORM_ref1
3067 || form
== DW_FORM_ref2
3068 || form
== DW_FORM_ref4
3069 || form
== DW_FORM_ref_udata
)
3070 uvalue
+= cu_offset
;
3072 if (uvalue
>= section
->size
)
3073 warn (_("Offset %s used as value for DW_AT_import attribute of DIE at offset 0x%lx is too big.\n"),
3074 dwarf_vmatoa ("x", uvalue
),
3075 (unsigned long) (orig_data
- section
->start
));
3078 unsigned long abbrev_number
;
3079 abbrev_entry
* entry
;
3081 abbrev_number
= read_uleb128 (section
->start
+ uvalue
, NULL
, end
);
3083 printf (_("\t[Abbrev Number: %ld"), abbrev_number
);
3084 /* Don't look up abbrev for DW_FORM_ref_addr, as it very often will
3085 use different abbrev table, and we don't track .debug_info chunks
3087 if (form
!= DW_FORM_ref_addr
)
3089 for (entry
= first_abbrev
; entry
!= NULL
; entry
= entry
->next
)
3090 if (entry
->entry
== abbrev_number
)
3093 printf (" (%s)", get_TAG_name (entry
->tag
));
3107 static unsigned char *
3108 read_and_display_attr (unsigned long attribute
,
3110 dwarf_signed_vma implicit_const
,
3111 unsigned char * start
,
3112 unsigned char * data
,
3113 unsigned char * end
,
3114 dwarf_vma cu_offset
,
3115 dwarf_vma pointer_size
,
3116 dwarf_vma offset_size
,
3118 debug_info
* debug_info_p
,
3120 struct dwarf_section
* section
,
3121 struct cu_tu_set
* this_set
,
3125 printf (" %-18s:", get_AT_name (attribute
));
3126 data
= read_and_display_attr_value (attribute
, form
, implicit_const
,
3128 cu_offset
, pointer_size
, offset_size
,
3129 dwarf_version
, debug_info_p
,
3130 do_loc
, section
, this_set
, ' ', level
);
3136 /* Like load_debug_section, but if the ordinary call fails, and we are
3137 following debug links, then attempt to load the requested section
3138 from one of the separate debug info files. */
3141 load_debug_section_with_follow (enum dwarf_section_display_enum sec_enum
,
3144 if (load_debug_section (sec_enum
, handle
))
3146 if (debug_displays
[sec_enum
].section
.filename
== NULL
)
3148 /* See if we can associate a filename with this section. */
3151 for (i
= first_separate_info
; i
!= NULL
; i
= i
->next
)
3152 if (i
->handle
== handle
)
3154 debug_displays
[sec_enum
].section
.filename
= i
->filename
;
3162 if (do_follow_links
)
3166 for (i
= first_separate_info
; i
!= NULL
; i
= i
->next
)
3168 if (load_debug_section (sec_enum
, i
->handle
))
3170 debug_displays
[sec_enum
].section
.filename
= i
->filename
;
3172 /* FIXME: We should check to see if any of the remaining debug info
3173 files also contain this section, and, umm, do something about it. */
3183 introduce (struct dwarf_section
* section
, bfd_boolean raw
)
3187 if (do_follow_links
&& section
->filename
)
3188 printf (_("Raw dump of debug contents of section %s (loaded from %s):\n\n"),
3189 section
->name
, section
->filename
);
3191 printf (_("Raw dump of debug contents of section %s:\n\n"), section
->name
);
3195 if (do_follow_links
&& section
->filename
)
3196 printf (_("Contents of the %s section (loaded from %s):\n\n"),
3197 section
->name
, section
->filename
);
3199 printf (_("Contents of the %s section:\n\n"), section
->name
);
3203 /* Process the contents of a .debug_info section.
3204 If do_loc is TRUE then we are scanning for location lists and dwo tags
3205 and we do not want to display anything to the user.
3206 If do_types is TRUE, we are processing a .debug_types section instead of
3207 a .debug_info section.
3208 The information displayed is restricted by the values in DWARF_START_DIE
3209 and DWARF_CUTOFF_LEVEL.
3210 Returns TRUE upon success. Otherwise an error or warning message is
3211 printed and FALSE is returned. */
3214 process_debug_info (struct dwarf_section
* section
,
3216 enum dwarf_section_display_enum abbrev_sec
,
3218 bfd_boolean do_types
)
3220 unsigned char *start
= section
->start
;
3221 unsigned char *end
= start
+ section
->size
;
3222 unsigned char *section_begin
;
3224 unsigned int num_units
= 0;
3226 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
3227 && num_debug_info_entries
== 0
3232 /* First scan the section to get the number of comp units. */
3233 for (section_begin
= start
, num_units
= 0; section_begin
< end
;
3236 /* Read the first 4 bytes. For a 32-bit DWARF section, this
3237 will be the length. For a 64-bit DWARF section, it'll be
3238 the escape code 0xffffffff followed by an 8 byte length. */
3239 SAFE_BYTE_GET (length
, section_begin
, 4, end
);
3241 if (length
== 0xffffffff)
3243 SAFE_BYTE_GET (length
, section_begin
+ 4, 8, end
);
3244 section_begin
+= length
+ 12;
3246 else if (length
>= 0xfffffff0 && length
< 0xffffffff)
3248 warn (_("Reserved length value (0x%s) found in section %s\n"),
3249 dwarf_vmatoa ("x", length
), section
->name
);
3253 section_begin
+= length
+ 4;
3255 /* Negative values are illegal, they may even cause infinite
3256 looping. This can happen if we can't accurately apply
3257 relocations to an object file, or if the file is corrupt. */
3258 if ((signed long) length
<= 0 || section_begin
< start
)
3260 warn (_("Corrupt unit length (0x%s) found in section %s\n"),
3261 dwarf_vmatoa ("x", length
), section
->name
);
3268 error (_("No comp units in %s section ?\n"), section
->name
);
3272 /* Then allocate an array to hold the information. */
3273 debug_information
= (debug_info
*) cmalloc (num_units
,
3274 sizeof (* debug_information
));
3275 if (debug_information
== NULL
)
3277 error (_("Not enough memory for a debug info array of %u entries\n"),
3279 alloc_num_debug_info_entries
= num_debug_info_entries
= 0;
3283 /* PR 17531: file: 92ca3797.
3284 We cannot rely upon the debug_information array being initialised
3285 before it is used. A corrupt file could easily contain references
3286 to a unit for which information has not been made available. So
3287 we ensure that the array is zeroed here. */
3288 memset (debug_information
, 0, num_units
* sizeof (*debug_information
));
3290 alloc_num_debug_info_entries
= num_units
;
3295 load_debug_section_with_follow (str
, file
);
3296 load_debug_section_with_follow (line_str
, file
);
3297 load_debug_section_with_follow (str_dwo
, file
);
3298 load_debug_section_with_follow (str_index
, file
);
3299 load_debug_section_with_follow (str_index_dwo
, file
);
3300 load_debug_section_with_follow (debug_addr
, file
);
3303 load_debug_section_with_follow (abbrev_sec
, file
);
3304 if (debug_displays
[abbrev_sec
].section
.start
== NULL
)
3306 warn (_("Unable to locate %s section!\n"),
3307 debug_displays
[abbrev_sec
].section
.uncompressed_name
);
3311 if (!do_loc
&& dwarf_start_die
== 0)
3312 introduce (section
, FALSE
);
3314 for (section_begin
= start
, unit
= 0; start
< end
; unit
++)
3316 DWARF2_Internal_CompUnit compunit
;
3317 unsigned char *hdrptr
;
3318 unsigned char *tags
;
3319 int level
, last_level
, saved_level
;
3320 dwarf_vma cu_offset
;
3321 unsigned long sec_off
;
3322 unsigned int offset_size
;
3323 unsigned int initial_length_size
;
3324 dwarf_vma signature_high
= 0;
3325 dwarf_vma signature_low
= 0;
3326 dwarf_vma type_offset
= 0;
3327 struct cu_tu_set
*this_set
;
3328 dwarf_vma abbrev_base
;
3333 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 4, end
);
3335 if (compunit
.cu_length
== 0xffffffff)
3337 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 8, end
);
3339 initial_length_size
= 12;
3344 initial_length_size
= 4;
3347 SAFE_BYTE_GET_AND_INC (compunit
.cu_version
, hdrptr
, 2, end
);
3349 cu_offset
= start
- section_begin
;
3351 this_set
= find_cu_tu_set_v2 (cu_offset
, do_types
);
3353 if (compunit
.cu_version
< 5)
3355 compunit
.cu_unit_type
= DW_UT_compile
;
3356 /* Initialize it due to a false compiler warning. */
3357 compunit
.cu_pointer_size
= -1;
3361 SAFE_BYTE_GET_AND_INC (compunit
.cu_unit_type
, hdrptr
, 1, end
);
3362 do_types
= (compunit
.cu_unit_type
== DW_UT_type
);
3364 SAFE_BYTE_GET_AND_INC (compunit
.cu_pointer_size
, hdrptr
, 1, end
);
3367 SAFE_BYTE_GET_AND_INC (compunit
.cu_abbrev_offset
, hdrptr
, offset_size
, end
);
3369 if (this_set
== NULL
)
3372 abbrev_size
= debug_displays
[abbrev_sec
].section
.size
;
3376 abbrev_base
= this_set
->section_offsets
[DW_SECT_ABBREV
];
3377 abbrev_size
= this_set
->section_sizes
[DW_SECT_ABBREV
];
3380 if (compunit
.cu_version
< 5)
3381 SAFE_BYTE_GET_AND_INC (compunit
.cu_pointer_size
, hdrptr
, 1, end
);
3383 /* PR 17512: file: 001-108546-0.001:0.1. */
3384 if (compunit
.cu_pointer_size
< 2 || compunit
.cu_pointer_size
> 8)
3386 warn (_("Invalid pointer size (%d) in compunit header, using %d instead\n"),
3387 compunit
.cu_pointer_size
, offset_size
);
3388 compunit
.cu_pointer_size
= offset_size
;
3393 SAFE_BYTE_GET64 (hdrptr
, &signature_high
, &signature_low
, end
);
3395 SAFE_BYTE_GET_AND_INC (type_offset
, hdrptr
, offset_size
, end
);
3398 if (dwarf_start_die
> (cu_offset
+ compunit
.cu_length
3399 + initial_length_size
))
3401 start
= section_begin
+ cu_offset
+ compunit
.cu_length
3402 + initial_length_size
;
3406 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
3407 && num_debug_info_entries
== 0
3410 debug_information
[unit
].cu_offset
= cu_offset
;
3411 debug_information
[unit
].pointer_size
3412 = compunit
.cu_pointer_size
;
3413 debug_information
[unit
].offset_size
= offset_size
;
3414 debug_information
[unit
].dwarf_version
= compunit
.cu_version
;
3415 debug_information
[unit
].base_address
= 0;
3416 debug_information
[unit
].addr_base
= DEBUG_INFO_UNAVAILABLE
;
3417 debug_information
[unit
].ranges_base
= DEBUG_INFO_UNAVAILABLE
;
3418 debug_information
[unit
].loc_offsets
= NULL
;
3419 debug_information
[unit
].have_frame_base
= NULL
;
3420 debug_information
[unit
].max_loc_offsets
= 0;
3421 debug_information
[unit
].num_loc_offsets
= 0;
3422 debug_information
[unit
].range_lists
= NULL
;
3423 debug_information
[unit
].max_range_lists
= 0;
3424 debug_information
[unit
].num_range_lists
= 0;
3427 if (!do_loc
&& dwarf_start_die
== 0)
3429 printf (_(" Compilation Unit @ offset 0x%s:\n"),
3430 dwarf_vmatoa ("x", cu_offset
));
3431 printf (_(" Length: 0x%s (%s)\n"),
3432 dwarf_vmatoa ("x", compunit
.cu_length
),
3433 offset_size
== 8 ? "64-bit" : "32-bit");
3434 printf (_(" Version: %d\n"), compunit
.cu_version
);
3435 printf (_(" Abbrev Offset: 0x%s\n"),
3436 dwarf_vmatoa ("x", compunit
.cu_abbrev_offset
));
3437 printf (_(" Pointer Size: %d\n"), compunit
.cu_pointer_size
);
3442 printf (_(" Signature: 0x%s\n"),
3443 dwarf_vmatoa64 (signature_high
, signature_low
,
3444 buf
, sizeof (buf
)));
3445 printf (_(" Type Offset: 0x%s\n"),
3446 dwarf_vmatoa ("x", type_offset
));
3448 if (this_set
!= NULL
)
3450 dwarf_vma
*offsets
= this_set
->section_offsets
;
3451 size_t *sizes
= this_set
->section_sizes
;
3453 printf (_(" Section contributions:\n"));
3454 printf (_(" .debug_abbrev.dwo: 0x%s 0x%s\n"),
3455 dwarf_vmatoa ("x", offsets
[DW_SECT_ABBREV
]),
3456 dwarf_vmatoa ("x", sizes
[DW_SECT_ABBREV
]));
3457 printf (_(" .debug_line.dwo: 0x%s 0x%s\n"),
3458 dwarf_vmatoa ("x", offsets
[DW_SECT_LINE
]),
3459 dwarf_vmatoa ("x", sizes
[DW_SECT_LINE
]));
3460 printf (_(" .debug_loc.dwo: 0x%s 0x%s\n"),
3461 dwarf_vmatoa ("x", offsets
[DW_SECT_LOC
]),
3462 dwarf_vmatoa ("x", sizes
[DW_SECT_LOC
]));
3463 printf (_(" .debug_str_offsets.dwo: 0x%s 0x%s\n"),
3464 dwarf_vmatoa ("x", offsets
[DW_SECT_STR_OFFSETS
]),
3465 dwarf_vmatoa ("x", sizes
[DW_SECT_STR_OFFSETS
]));
3469 sec_off
= cu_offset
+ initial_length_size
;
3470 if (sec_off
+ compunit
.cu_length
< sec_off
3471 || sec_off
+ compunit
.cu_length
> section
->size
)
3473 warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"),
3475 (unsigned long) cu_offset
,
3476 dwarf_vmatoa ("x", compunit
.cu_length
));
3482 start
+= compunit
.cu_length
+ initial_length_size
;
3484 if (compunit
.cu_version
< 2 || compunit
.cu_version
> 5)
3486 warn (_("CU at offset %s contains corrupt or "
3487 "unsupported version number: %d.\n"),
3488 dwarf_vmatoa ("x", cu_offset
), compunit
.cu_version
);
3492 if (compunit
.cu_unit_type
!= DW_UT_compile
3493 && compunit
.cu_unit_type
!= DW_UT_type
)
3495 warn (_("CU at offset %s contains corrupt or "
3496 "unsupported unit type: %d.\n"),
3497 dwarf_vmatoa ("x", cu_offset
), compunit
.cu_unit_type
);
3503 /* Process the abbrevs used by this compilation unit. */
3504 if (compunit
.cu_abbrev_offset
>= abbrev_size
)
3505 warn (_("Debug info is corrupted, abbrev offset (%lx) is larger than abbrev section size (%lx)\n"),
3506 (unsigned long) compunit
.cu_abbrev_offset
,
3507 (unsigned long) abbrev_size
);
3508 /* PR 17531: file:4bcd9ce9. */
3509 else if ((abbrev_base
+ abbrev_size
)
3510 > debug_displays
[abbrev_sec
].section
.size
)
3511 warn (_("Debug info is corrupted, abbrev size (%lx) is larger than abbrev section size (%lx)\n"),
3512 (unsigned long) abbrev_base
+ abbrev_size
,
3513 (unsigned long) debug_displays
[abbrev_sec
].section
.size
);
3515 process_abbrev_section
3516 (((unsigned char *) debug_displays
[abbrev_sec
].section
.start
3517 + abbrev_base
+ compunit
.cu_abbrev_offset
),
3518 ((unsigned char *) debug_displays
[abbrev_sec
].section
.start
3519 + abbrev_base
+ abbrev_size
));
3524 while (tags
< start
)
3526 unsigned int bytes_read
;
3527 unsigned long abbrev_number
;
3528 unsigned long die_offset
;
3529 abbrev_entry
*entry
;
3531 int do_printing
= 1;
3533 die_offset
= tags
- section_begin
;
3535 abbrev_number
= read_uleb128 (tags
, & bytes_read
, start
);
3538 /* A null DIE marks the end of a list of siblings or it may also be
3539 a section padding. */
3540 if (abbrev_number
== 0)
3542 /* Check if it can be a section padding for the last CU. */
3543 if (level
== 0 && start
== end
)
3547 for (chk
= tags
; chk
< start
; chk
++)
3554 if (!do_loc
&& die_offset
>= dwarf_start_die
3555 && (dwarf_cutoff_level
== -1
3556 || level
< dwarf_cutoff_level
))
3557 printf (_(" <%d><%lx>: Abbrev Number: 0\n"),
3563 static unsigned num_bogus_warns
= 0;
3565 if (num_bogus_warns
< 3)
3567 warn (_("Bogus end-of-siblings marker detected at offset %lx in %s section\n"),
3568 die_offset
, section
->name
);
3570 if (num_bogus_warns
== 3)
3571 warn (_("Further warnings about bogus end-of-sibling markers suppressed\n"));
3574 if (dwarf_start_die
!= 0 && level
< saved_level
)
3581 if (dwarf_start_die
!= 0 && die_offset
< dwarf_start_die
)
3585 if (dwarf_start_die
!= 0 && die_offset
== dwarf_start_die
)
3586 saved_level
= level
;
3587 do_printing
= (dwarf_cutoff_level
== -1
3588 || level
< dwarf_cutoff_level
);
3590 printf (_(" <%d><%lx>: Abbrev Number: %lu"),
3591 level
, die_offset
, abbrev_number
);
3592 else if (dwarf_cutoff_level
== -1
3593 || last_level
< dwarf_cutoff_level
)
3594 printf (_(" <%d><%lx>: ...\n"), level
, die_offset
);
3599 /* Scan through the abbreviation list until we reach the
3601 for (entry
= first_abbrev
;
3602 entry
&& entry
->entry
!= abbrev_number
;
3603 entry
= entry
->next
)
3608 if (!do_loc
&& do_printing
)
3613 warn (_("DIE at offset 0x%lx refers to abbreviation number %lu which does not exist\n"),
3614 die_offset
, abbrev_number
);
3618 if (!do_loc
&& do_printing
)
3619 printf (" (%s)\n", get_TAG_name (entry
->tag
));
3624 need_base_address
= 0;
3626 case DW_TAG_compile_unit
:
3627 need_base_address
= 1;
3628 need_dwo_info
= do_loc
;
3630 case DW_TAG_entry_point
:
3631 case DW_TAG_subprogram
:
3632 need_base_address
= 0;
3633 /* Assuming that there is no DW_AT_frame_base. */
3634 have_frame_base
= 0;
3638 debug_info
*debug_info_p
=
3639 (debug_information
&& unit
< alloc_num_debug_info_entries
)
3640 ? debug_information
+ unit
: NULL
;
3642 assert (!debug_info_p
3643 || (debug_info_p
->num_loc_offsets
3644 == debug_info_p
->num_loc_views
));
3646 for (attr
= entry
->first_attr
;
3647 attr
&& attr
->attribute
;
3650 if (! do_loc
&& do_printing
)
3651 /* Show the offset from where the tag was extracted. */
3652 printf (" <%lx>", (unsigned long)(tags
- section_begin
));
3653 tags
= read_and_display_attr (attr
->attribute
,
3655 attr
->implicit_const
,
3660 compunit
.cu_pointer_size
,
3662 compunit
.cu_version
,
3664 do_loc
|| ! do_printing
,
3670 /* If a locview attribute appears before a location one,
3671 make sure we don't associate it with an earlier
3674 switch (debug_info_p
->num_loc_offsets
- debug_info_p
->num_loc_views
)
3677 debug_info_p
->loc_views
[debug_info_p
->num_loc_views
] = vm1
;
3678 debug_info_p
->num_loc_views
++;
3679 assert (debug_info_p
->num_loc_views
3680 == debug_info_p
->num_loc_offsets
);
3687 warn(_("DIE has locviews without loclist\n"));
3688 debug_info_p
->num_loc_views
--;
3695 if (entry
->children
)
3700 /* Set num_debug_info_entries here so that it can be used to check if
3701 we need to process .debug_loc and .debug_ranges sections. */
3702 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
3703 && num_debug_info_entries
== 0
3706 if (num_units
> alloc_num_debug_info_entries
)
3707 num_debug_info_entries
= alloc_num_debug_info_entries
;
3709 num_debug_info_entries
= num_units
;
3718 /* Locate and scan the .debug_info section in the file and record the pointer
3719 sizes and offsets for the compilation units in it. Usually an executable
3720 will have just one pointer size, but this is not guaranteed, and so we try
3721 not to make any assumptions. Returns zero upon failure, or the number of
3722 compilation units upon success. */
3725 load_debug_info (void * file
)
3727 /* If we have already tried and failed to load the .debug_info
3728 section then do not bother to repeat the task. */
3729 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
3732 /* If we already have the information there is nothing else to do. */
3733 if (num_debug_info_entries
> 0)
3734 return num_debug_info_entries
;
3736 /* If this is a DWARF package file, load the CU and TU indexes. */
3737 (void) load_cu_tu_indexes (file
);
3739 if (load_debug_section_with_follow (info
, file
)
3740 && process_debug_info (&debug_displays
[info
].section
, file
, abbrev
, TRUE
, FALSE
))
3741 return num_debug_info_entries
;
3743 if (load_debug_section_with_follow (info_dwo
, file
)
3744 && process_debug_info (&debug_displays
[info_dwo
].section
, file
,
3745 abbrev_dwo
, TRUE
, FALSE
))
3746 return num_debug_info_entries
;
3748 num_debug_info_entries
= DEBUG_INFO_UNAVAILABLE
;
3752 /* Read a DWARF .debug_line section header starting at DATA.
3753 Upon success returns an updated DATA pointer and the LINFO
3754 structure and the END_OF_SEQUENCE pointer will be filled in.
3755 Otherwise returns NULL. */
3757 static unsigned char *
3758 read_debug_line_header (struct dwarf_section
* section
,
3759 unsigned char * data
,
3760 unsigned char * end
,
3761 DWARF2_Internal_LineInfo
* linfo
,
3762 unsigned char ** end_of_sequence
)
3764 unsigned char *hdrptr
;
3765 unsigned int initial_length_size
;
3766 unsigned char address_size
, segment_selector_size
;
3768 /* Extract information from the Line Number Program Header.
3769 (section 6.2.4 in the Dwarf3 doc). */
3772 /* Get and check the length of the block. */
3773 SAFE_BYTE_GET_AND_INC (linfo
->li_length
, hdrptr
, 4, end
);
3775 if (linfo
->li_length
== 0xffffffff)
3777 /* This section is 64-bit DWARF 3. */
3778 SAFE_BYTE_GET_AND_INC (linfo
->li_length
, hdrptr
, 8, end
);
3779 linfo
->li_offset_size
= 8;
3780 initial_length_size
= 12;
3784 linfo
->li_offset_size
= 4;
3785 initial_length_size
= 4;
3788 if (linfo
->li_length
+ initial_length_size
> section
->size
)
3790 /* If the length field has a relocation against it, then we should
3791 not complain if it is inaccurate (and probably negative). This
3792 happens in object files when the .debug_line section is actually
3793 comprised of several different .debug_line.* sections, (some of
3794 which may be removed by linker garbage collection), and a relocation
3795 is used to compute the correct length once that is done. */
3796 if (reloc_at (section
, (hdrptr
- section
->start
) - linfo
->li_offset_size
))
3798 linfo
->li_length
= (end
- data
) - initial_length_size
;
3802 warn (_("The length field (0x%lx) in the debug_line header is wrong - the section is too small\n"),
3803 (long) linfo
->li_length
);
3808 /* Get and check the version number. */
3809 SAFE_BYTE_GET_AND_INC (linfo
->li_version
, hdrptr
, 2, end
);
3811 if (linfo
->li_version
!= 2
3812 && linfo
->li_version
!= 3
3813 && linfo
->li_version
!= 4
3814 && linfo
->li_version
!= 5)
3816 warn (_("Only DWARF version 2, 3, 4 and 5 line info "
3817 "is currently supported.\n"));
3821 if (linfo
->li_version
>= 5)
3823 SAFE_BYTE_GET_AND_INC (address_size
, hdrptr
, 1, end
);
3825 SAFE_BYTE_GET_AND_INC (segment_selector_size
, hdrptr
, 1, end
);
3826 if (segment_selector_size
!= 0)
3828 warn (_("The %s section contains "
3829 "unsupported segment selector size: %d.\n"),
3830 section
->name
, segment_selector_size
);
3835 SAFE_BYTE_GET_AND_INC (linfo
->li_prologue_length
, hdrptr
,
3836 linfo
->li_offset_size
, end
);
3837 SAFE_BYTE_GET_AND_INC (linfo
->li_min_insn_length
, hdrptr
, 1, end
);
3839 if (linfo
->li_version
>= 4)
3841 SAFE_BYTE_GET_AND_INC (linfo
->li_max_ops_per_insn
, hdrptr
, 1, end
);
3843 if (linfo
->li_max_ops_per_insn
== 0)
3845 warn (_("Invalid maximum operations per insn.\n"));
3850 linfo
->li_max_ops_per_insn
= 1;
3852 SAFE_BYTE_GET_AND_INC (linfo
->li_default_is_stmt
, hdrptr
, 1, end
);
3853 SAFE_SIGNED_BYTE_GET_AND_INC (linfo
->li_line_base
, hdrptr
, 1, end
);
3854 SAFE_BYTE_GET_AND_INC (linfo
->li_line_range
, hdrptr
, 1, end
);
3855 SAFE_BYTE_GET_AND_INC (linfo
->li_opcode_base
, hdrptr
, 1, end
);
3857 * end_of_sequence
= data
+ linfo
->li_length
+ initial_length_size
;
3858 /* PR 17512: file:002-117414-0.004. */
3859 if (* end_of_sequence
> end
)
3861 warn (_("Line length %s extends beyond end of section\n"),
3862 dwarf_vmatoa ("u", linfo
->li_length
));
3863 * end_of_sequence
= end
;
3870 static unsigned char *
3871 display_formatted_table (unsigned char * data
,
3872 unsigned char * start
,
3873 unsigned char * end
,
3874 const DWARF2_Internal_LineInfo
* linfo
,
3875 struct dwarf_section
* section
,
3878 unsigned char *format_start
, format_count
, *format
, formati
;
3879 dwarf_vma data_count
, datai
;
3880 unsigned int bytes_read
, namepass
, last_entry
= 0;
3882 SAFE_BYTE_GET_AND_INC (format_count
, data
, 1, end
);
3883 format_start
= data
;
3884 for (formati
= 0; formati
< format_count
; formati
++)
3886 read_uleb128 (data
, & bytes_read
, end
);
3888 read_uleb128 (data
, & bytes_read
, end
);
3893 warn (_("Corrupt directory format table entry\n"));
3895 warn (_("Corrupt file name format table entry\n"));
3900 data_count
= read_uleb128 (data
, & bytes_read
, end
);
3905 warn (_("Corrupt directory list\n"));
3907 warn (_("Corrupt file name list\n"));
3911 if (data_count
== 0)
3914 printf (_("\n The Directory Table is empty.\n"));
3916 printf (_("\n The File Name Table is empty.\n"));
3921 printf (_("\n The Directory Table (offset 0x%lx):\n"),
3922 (long) (data
- start
));
3924 printf (_("\n The File Name Table (offset 0x%lx):\n"),
3925 (long) (data
- start
));
3927 printf (_(" Entry"));
3928 /* Delay displaying name as the last entry for better screen layout. */
3929 for (namepass
= 0; namepass
< 2; namepass
++)
3931 format
= format_start
;
3932 for (formati
= 0; formati
< format_count
; formati
++)
3934 dwarf_vma content_type
;
3936 content_type
= read_uleb128 (format
, & bytes_read
, end
);
3937 format
+= bytes_read
;
3938 if ((content_type
== DW_LNCT_path
) == (namepass
== 1))
3939 switch (content_type
)
3942 printf (_("\tName"));
3944 case DW_LNCT_directory_index
:
3945 printf (_("\tDir"));
3947 case DW_LNCT_timestamp
:
3948 printf (_("\tTime"));
3951 printf (_("\tSize"));
3954 printf (_("\tMD5"));
3957 printf (_("\t(Unknown format content type %s)"),
3958 dwarf_vmatoa ("u", content_type
));
3960 read_uleb128 (format
, & bytes_read
, end
);
3961 format
+= bytes_read
;
3966 for (datai
= 0; datai
< data_count
; datai
++)
3968 unsigned char *datapass
= data
;
3970 printf (" %d", last_entry
++);
3971 /* Delay displaying name as the last entry for better screen layout. */
3972 for (namepass
= 0; namepass
< 2; namepass
++)
3974 format
= format_start
;
3976 for (formati
= 0; formati
< format_count
; formati
++)
3978 dwarf_vma content_type
, form
;
3980 content_type
= read_uleb128 (format
, & bytes_read
, end
);
3981 format
+= bytes_read
;
3982 form
= read_uleb128 (format
, & bytes_read
, end
);
3983 format
+= bytes_read
;
3984 data
= read_and_display_attr_value (0, form
, 0, start
, data
, end
, 0, 0,
3985 linfo
->li_offset_size
,
3986 linfo
->li_version
, NULL
,
3987 ((content_type
== DW_LNCT_path
) != (namepass
== 1)),
3988 section
, NULL
, '\t', -1);
3994 warn (_("Corrupt directory entries list\n"));
3996 warn (_("Corrupt file name entries list\n"));
4005 display_debug_lines_raw (struct dwarf_section
* section
,
4006 unsigned char * data
,
4007 unsigned char * end
,
4010 unsigned char *start
= section
->start
;
4011 int verbose_view
= 0;
4013 introduce (section
, TRUE
);
4017 static DWARF2_Internal_LineInfo saved_linfo
;
4018 DWARF2_Internal_LineInfo linfo
;
4019 unsigned char *standard_opcodes
;
4020 unsigned char *end_of_sequence
;
4023 if (const_strneq (section
->name
, ".debug_line.")
4024 /* Note: the following does not apply to .debug_line.dwo sections.
4025 These are full debug_line sections. */
4026 && strcmp (section
->name
, ".debug_line.dwo") != 0)
4028 /* Sections named .debug_line.<foo> are fragments of a .debug_line
4029 section containing just the Line Number Statements. They are
4030 created by the assembler and intended to be used alongside gcc's
4031 -ffunction-sections command line option. When the linker's
4032 garbage collection decides to discard a .text.<foo> section it
4033 can then also discard the line number information in .debug_line.<foo>.
4035 Since the section is a fragment it does not have the details
4036 needed to fill out a LineInfo structure, so instead we use the
4037 details from the last full debug_line section that we processed. */
4038 end_of_sequence
= end
;
4039 standard_opcodes
= NULL
;
4040 linfo
= saved_linfo
;
4041 /* PR 17531: file: 0522b371. */
4042 if (linfo
.li_line_range
== 0)
4044 warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n"));
4047 reset_state_machine (linfo
.li_default_is_stmt
);
4051 unsigned char * hdrptr
;
4053 if ((hdrptr
= read_debug_line_header (section
, data
, end
, & linfo
,
4054 & end_of_sequence
)) == NULL
)
4057 printf (_(" Offset: 0x%lx\n"), (long)(data
- start
));
4058 printf (_(" Length: %ld\n"), (long) linfo
.li_length
);
4059 printf (_(" DWARF Version: %d\n"), linfo
.li_version
);
4060 printf (_(" Prologue Length: %d\n"), (int) linfo
.li_prologue_length
);
4061 printf (_(" Minimum Instruction Length: %d\n"), linfo
.li_min_insn_length
);
4062 if (linfo
.li_version
>= 4)
4063 printf (_(" Maximum Ops per Instruction: %d\n"), linfo
.li_max_ops_per_insn
);
4064 printf (_(" Initial value of 'is_stmt': %d\n"), linfo
.li_default_is_stmt
);
4065 printf (_(" Line Base: %d\n"), linfo
.li_line_base
);
4066 printf (_(" Line Range: %d\n"), linfo
.li_line_range
);
4067 printf (_(" Opcode Base: %d\n"), linfo
.li_opcode_base
);
4069 /* PR 17512: file: 1665-6428-0.004. */
4070 if (linfo
.li_line_range
== 0)
4072 warn (_("Line range of 0 is invalid, using 1 instead\n"));
4073 linfo
.li_line_range
= 1;
4076 reset_state_machine (linfo
.li_default_is_stmt
);
4078 /* Display the contents of the Opcodes table. */
4079 standard_opcodes
= hdrptr
;
4081 /* PR 17512: file: 002-417945-0.004. */
4082 if (standard_opcodes
+ linfo
.li_opcode_base
>= end
)
4084 warn (_("Line Base extends beyond end of section\n"));
4088 printf (_("\n Opcodes:\n"));
4090 for (i
= 1; i
< linfo
.li_opcode_base
; i
++)
4091 printf (ngettext (" Opcode %d has %d arg\n",
4092 " Opcode %d has %d args\n",
4093 standard_opcodes
[i
- 1]),
4094 i
, standard_opcodes
[i
- 1]);
4096 /* Display the contents of the Directory table. */
4097 data
= standard_opcodes
+ linfo
.li_opcode_base
- 1;
4099 if (linfo
.li_version
>= 5)
4101 load_debug_section_with_follow (line_str
, file
);
4103 data
= display_formatted_table (data
, start
, end
, &linfo
, section
,
4105 data
= display_formatted_table (data
, start
, end
, &linfo
, section
,
4111 printf (_("\n The Directory Table is empty.\n"));
4114 unsigned int last_dir_entry
= 0;
4116 printf (_("\n The Directory Table (offset 0x%lx):\n"),
4117 (long)(data
- start
));
4119 while (data
< end
&& *data
!= 0)
4121 printf (" %d\t%.*s\n", ++last_dir_entry
, (int) (end
- data
), data
);
4123 data
+= strnlen ((char *) data
, end
- data
) + 1;
4126 /* PR 17512: file: 002-132094-0.004. */
4127 if (data
>= end
- 1)
4131 /* Skip the NUL at the end of the table. */
4134 /* Display the contents of the File Name table. */
4136 printf (_("\n The File Name Table is empty.\n"));
4139 printf (_("\n The File Name Table (offset 0x%lx):\n"),
4140 (long)(data
- start
));
4141 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
4143 while (data
< end
&& *data
!= 0)
4145 unsigned char *name
;
4146 unsigned int bytes_read
;
4148 printf (" %d\t", ++state_machine_regs
.last_file_entry
);
4150 data
+= strnlen ((char *) data
, end
- data
) + 1;
4153 dwarf_vmatoa ("u", read_uleb128 (data
, & bytes_read
, end
)));
4156 dwarf_vmatoa ("u", read_uleb128 (data
, & bytes_read
, end
)));
4159 dwarf_vmatoa ("u", read_uleb128 (data
, & bytes_read
, end
)));
4161 printf ("%.*s\n", (int)(end
- name
), name
);
4165 warn (_("Corrupt file name table entry\n"));
4171 /* Skip the NUL at the end of the table. */
4176 saved_linfo
= linfo
;
4179 /* Now display the statements. */
4180 if (data
>= end_of_sequence
)
4181 printf (_(" No Line Number Statements.\n"));
4184 printf (_(" Line Number Statements:\n"));
4186 while (data
< end_of_sequence
)
4188 unsigned char op_code
;
4189 dwarf_signed_vma adv
;
4191 unsigned int bytes_read
;
4193 printf (" [0x%08lx]", (long)(data
- start
));
4197 if (op_code
>= linfo
.li_opcode_base
)
4199 op_code
-= linfo
.li_opcode_base
;
4200 uladv
= (op_code
/ linfo
.li_line_range
);
4201 if (linfo
.li_max_ops_per_insn
== 1)
4203 uladv
*= linfo
.li_min_insn_length
;
4204 state_machine_regs
.address
+= uladv
;
4206 state_machine_regs
.view
= 0;
4207 printf (_(" Special opcode %d: "
4208 "advance Address by %s to 0x%s%s"),
4209 op_code
, dwarf_vmatoa ("u", uladv
),
4210 dwarf_vmatoa ("x", state_machine_regs
.address
),
4211 verbose_view
&& uladv
4212 ? _(" (reset view)") : "");
4217 = ((state_machine_regs
.op_index
+ uladv
)
4218 / linfo
.li_max_ops_per_insn
)
4219 * linfo
.li_min_insn_length
;
4221 state_machine_regs
.address
+= addrdelta
;
4222 state_machine_regs
.op_index
4223 = (state_machine_regs
.op_index
+ uladv
)
4224 % linfo
.li_max_ops_per_insn
;
4226 state_machine_regs
.view
= 0;
4227 printf (_(" Special opcode %d: "
4228 "advance Address by %s to 0x%s[%d]%s"),
4229 op_code
, dwarf_vmatoa ("u", uladv
),
4230 dwarf_vmatoa ("x", state_machine_regs
.address
),
4231 state_machine_regs
.op_index
,
4232 verbose_view
&& addrdelta
4233 ? _(" (reset view)") : "");
4235 adv
= (op_code
% linfo
.li_line_range
) + linfo
.li_line_base
;
4236 state_machine_regs
.line
+= adv
;
4237 printf (_(" and Line by %s to %d"),
4238 dwarf_vmatoa ("d", adv
), state_machine_regs
.line
);
4239 if (verbose_view
|| state_machine_regs
.view
)
4240 printf (_(" (view %u)\n"), state_machine_regs
.view
);
4243 state_machine_regs
.view
++;
4245 else switch (op_code
)
4247 case DW_LNS_extended_op
:
4248 data
+= process_extended_line_op (data
, linfo
.li_default_is_stmt
, end
);
4252 printf (_(" Copy"));
4253 if (verbose_view
|| state_machine_regs
.view
)
4254 printf (_(" (view %u)\n"), state_machine_regs
.view
);
4257 state_machine_regs
.view
++;
4260 case DW_LNS_advance_pc
:
4261 uladv
= read_uleb128 (data
, & bytes_read
, end
);
4263 if (linfo
.li_max_ops_per_insn
== 1)
4265 uladv
*= linfo
.li_min_insn_length
;
4266 state_machine_regs
.address
+= uladv
;
4268 state_machine_regs
.view
= 0;
4269 printf (_(" Advance PC by %s to 0x%s%s\n"),
4270 dwarf_vmatoa ("u", uladv
),
4271 dwarf_vmatoa ("x", state_machine_regs
.address
),
4272 verbose_view
&& uladv
4273 ? _(" (reset view)") : "");
4278 = ((state_machine_regs
.op_index
+ uladv
)
4279 / linfo
.li_max_ops_per_insn
)
4280 * linfo
.li_min_insn_length
;
4281 state_machine_regs
.address
4283 state_machine_regs
.op_index
4284 = (state_machine_regs
.op_index
+ uladv
)
4285 % linfo
.li_max_ops_per_insn
;
4287 state_machine_regs
.view
= 0;
4288 printf (_(" Advance PC by %s to 0x%s[%d]%s\n"),
4289 dwarf_vmatoa ("u", uladv
),
4290 dwarf_vmatoa ("x", state_machine_regs
.address
),
4291 state_machine_regs
.op_index
,
4292 verbose_view
&& addrdelta
4293 ? _(" (reset view)") : "");
4297 case DW_LNS_advance_line
:
4298 adv
= read_sleb128 (data
, & bytes_read
, end
);
4300 state_machine_regs
.line
+= adv
;
4301 printf (_(" Advance Line by %s to %d\n"),
4302 dwarf_vmatoa ("d", adv
),
4303 state_machine_regs
.line
);
4306 case DW_LNS_set_file
:
4307 adv
= read_uleb128 (data
, & bytes_read
, end
);
4309 printf (_(" Set File Name to entry %s in the File Name Table\n"),
4310 dwarf_vmatoa ("d", adv
));
4311 state_machine_regs
.file
= adv
;
4314 case DW_LNS_set_column
:
4315 uladv
= read_uleb128 (data
, & bytes_read
, end
);
4317 printf (_(" Set column to %s\n"),
4318 dwarf_vmatoa ("u", uladv
));
4319 state_machine_regs
.column
= uladv
;
4322 case DW_LNS_negate_stmt
:
4323 adv
= state_machine_regs
.is_stmt
;
4325 printf (_(" Set is_stmt to %s\n"), dwarf_vmatoa ("d", adv
));
4326 state_machine_regs
.is_stmt
= adv
;
4329 case DW_LNS_set_basic_block
:
4330 printf (_(" Set basic block\n"));
4331 state_machine_regs
.basic_block
= 1;
4334 case DW_LNS_const_add_pc
:
4335 uladv
= ((255 - linfo
.li_opcode_base
) / linfo
.li_line_range
);
4336 if (linfo
.li_max_ops_per_insn
)
4338 uladv
*= linfo
.li_min_insn_length
;
4339 state_machine_regs
.address
+= uladv
;
4341 state_machine_regs
.view
= 0;
4342 printf (_(" Advance PC by constant %s to 0x%s%s\n"),
4343 dwarf_vmatoa ("u", uladv
),
4344 dwarf_vmatoa ("x", state_machine_regs
.address
),
4345 verbose_view
&& uladv
4346 ? _(" (reset view)") : "");
4351 = ((state_machine_regs
.op_index
+ uladv
)
4352 / linfo
.li_max_ops_per_insn
)
4353 * linfo
.li_min_insn_length
;
4354 state_machine_regs
.address
4356 state_machine_regs
.op_index
4357 = (state_machine_regs
.op_index
+ uladv
)
4358 % linfo
.li_max_ops_per_insn
;
4360 state_machine_regs
.view
= 0;
4361 printf (_(" Advance PC by constant %s to 0x%s[%d]%s\n"),
4362 dwarf_vmatoa ("u", uladv
),
4363 dwarf_vmatoa ("x", state_machine_regs
.address
),
4364 state_machine_regs
.op_index
,
4365 verbose_view
&& addrdelta
4366 ? _(" (reset view)") : "");
4370 case DW_LNS_fixed_advance_pc
:
4371 SAFE_BYTE_GET_AND_INC (uladv
, data
, 2, end
);
4372 state_machine_regs
.address
+= uladv
;
4373 state_machine_regs
.op_index
= 0;
4374 printf (_(" Advance PC by fixed size amount %s to 0x%s\n"),
4375 dwarf_vmatoa ("u", uladv
),
4376 dwarf_vmatoa ("x", state_machine_regs
.address
));
4377 /* Do NOT reset view. */
4380 case DW_LNS_set_prologue_end
:
4381 printf (_(" Set prologue_end to true\n"));
4384 case DW_LNS_set_epilogue_begin
:
4385 printf (_(" Set epilogue_begin to true\n"));
4388 case DW_LNS_set_isa
:
4389 uladv
= read_uleb128 (data
, & bytes_read
, end
);
4391 printf (_(" Set ISA to %s\n"), dwarf_vmatoa ("u", uladv
));
4395 printf (_(" Unknown opcode %d with operands: "), op_code
);
4397 if (standard_opcodes
!= NULL
)
4398 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
4400 printf ("0x%s%s", dwarf_vmatoa ("x", read_uleb128 (data
,
4402 i
== 1 ? "" : ", ");
4418 unsigned char *name
;
4419 unsigned int directory_index
;
4420 unsigned int modification_date
;
4421 unsigned int length
;
4424 /* Output a decoded representation of the .debug_line section. */
4427 display_debug_lines_decoded (struct dwarf_section
* section
,
4428 unsigned char * start
,
4429 unsigned char * data
,
4430 unsigned char * end
,
4433 static DWARF2_Internal_LineInfo saved_linfo
;
4435 introduce (section
, FALSE
);
4439 /* This loop amounts to one iteration per compilation unit. */
4440 DWARF2_Internal_LineInfo linfo
;
4441 unsigned char *standard_opcodes
;
4442 unsigned char *end_of_sequence
;
4444 File_Entry
*file_table
= NULL
;
4445 unsigned int n_files
= 0;
4446 unsigned char **directory_table
= NULL
;
4447 dwarf_vma n_directories
= 0;
4449 if (const_strneq (section
->name
, ".debug_line.")
4450 /* Note: the following does not apply to .debug_line.dwo sections.
4451 These are full debug_line sections. */
4452 && strcmp (section
->name
, ".debug_line.dwo") != 0)
4454 /* See comment in display_debug_lines_raw(). */
4455 end_of_sequence
= end
;
4456 standard_opcodes
= NULL
;
4457 linfo
= saved_linfo
;
4458 /* PR 17531: file: 0522b371. */
4459 if (linfo
.li_line_range
== 0)
4461 warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n"));
4464 reset_state_machine (linfo
.li_default_is_stmt
);
4468 unsigned char *hdrptr
;
4470 if ((hdrptr
= read_debug_line_header (section
, data
, end
, & linfo
,
4471 & end_of_sequence
)) == NULL
)
4474 /* PR 17531: file: 0522b371. */
4475 if (linfo
.li_line_range
== 0)
4477 warn (_("Line range of 0 is invalid, using 1 instead\n"));
4478 linfo
.li_line_range
= 1;
4480 reset_state_machine (linfo
.li_default_is_stmt
);
4482 /* Save a pointer to the contents of the Opcodes table. */
4483 standard_opcodes
= hdrptr
;
4485 /* Traverse the Directory table just to count entries. */
4486 data
= standard_opcodes
+ linfo
.li_opcode_base
- 1;
4490 warn (_("opcode base of %d extends beyond end of section\n"),
4491 linfo
.li_opcode_base
);
4495 if (linfo
.li_version
>= 5)
4497 unsigned char *format_start
, format_count
, *format
;
4498 dwarf_vma formati
, entryi
;
4499 unsigned int bytes_read
;
4501 load_debug_section_with_follow (line_str
, fileptr
);
4503 /* Skip directories format. */
4504 SAFE_BYTE_GET_AND_INC (format_count
, data
, 1, end
);
4505 format_start
= data
;
4506 for (formati
= 0; formati
< format_count
; formati
++)
4508 read_uleb128 (data
, & bytes_read
, end
);
4510 read_uleb128 (data
, & bytes_read
, end
);
4514 n_directories
= read_uleb128 (data
, & bytes_read
, end
);
4518 warn (_("Corrupt directories list\n"));
4522 directory_table
= (unsigned char **)
4523 xmalloc (n_directories
* sizeof (unsigned char *));
4525 for (entryi
= 0; entryi
< n_directories
; entryi
++)
4527 unsigned char **pathp
= &directory_table
[entryi
];
4529 format
= format_start
;
4530 for (formati
= 0; formati
< format_count
; formati
++)
4532 dwarf_vma content_type
, form
;
4535 content_type
= read_uleb128 (format
, & bytes_read
, end
);
4536 format
+= bytes_read
;
4537 form
= read_uleb128 (format
, & bytes_read
, end
);
4538 format
+= bytes_read
;
4541 warn (_("Corrupt directories list\n"));
4544 switch (content_type
)
4549 case DW_FORM_string
:
4552 case DW_FORM_line_strp
:
4553 SAFE_BYTE_GET (uvalue
, data
, linfo
.li_offset_size
,
4555 /* Remove const by the cast. */
4556 *pathp
= (unsigned char *)
4557 fetch_indirect_line_string (uvalue
);
4562 data
= read_and_display_attr_value (0, form
, 0, start
, data
, end
,
4564 linfo
.li_offset_size
,
4571 warn (_("Corrupt directories list\n"));
4576 /* Skip files format. */
4577 SAFE_BYTE_GET_AND_INC (format_count
, data
, 1, end
);
4578 format_start
= data
;
4579 for (formati
= 0; formati
< format_count
; formati
++)
4581 read_uleb128 (data
, & bytes_read
, end
);
4583 read_uleb128 (data
, & bytes_read
, end
);
4587 n_files
= read_uleb128 (data
, & bytes_read
, end
);
4591 warn (_("Corrupt file name list\n"));
4595 file_table
= (File_Entry
*) xcalloc (1, n_files
4596 * sizeof (File_Entry
));
4598 for (entryi
= 0; entryi
< n_files
; entryi
++)
4600 File_Entry
*file
= &file_table
[entryi
];
4602 format
= format_start
;
4603 for (formati
= 0; formati
< format_count
; formati
++)
4605 dwarf_vma content_type
, form
;
4608 content_type
= read_uleb128 (format
, & bytes_read
, end
);
4609 format
+= bytes_read
;
4610 form
= read_uleb128 (format
, & bytes_read
, end
);
4611 format
+= bytes_read
;
4614 warn (_("Corrupt file name list\n"));
4617 switch (content_type
)
4622 case DW_FORM_string
:
4625 case DW_FORM_line_strp
:
4626 SAFE_BYTE_GET (uvalue
, data
, linfo
.li_offset_size
,
4628 /* Remove const by the cast. */
4629 file
->name
= (unsigned char *)
4630 fetch_indirect_line_string (uvalue
);
4634 case DW_LNCT_directory_index
:
4638 SAFE_BYTE_GET (file
->directory_index
, data
, 1,
4642 SAFE_BYTE_GET (file
->directory_index
, data
, 2,
4646 file
->directory_index
= read_uleb128 (data
, NULL
,
4652 data
= read_and_display_attr_value (0, form
, 0, start
, data
, end
,
4654 linfo
.li_offset_size
,
4661 warn (_("Corrupt file name list\n"));
4670 unsigned char *ptr_directory_table
= data
;
4672 while (data
< end
&& *data
!= 0)
4674 data
+= strnlen ((char *) data
, end
- data
) + 1;
4681 warn (_("directory table ends unexpectedly\n"));
4686 /* Go through the directory table again to save the directories. */
4687 directory_table
= (unsigned char **)
4688 xmalloc (n_directories
* sizeof (unsigned char *));
4691 while (*ptr_directory_table
!= 0)
4693 directory_table
[i
] = ptr_directory_table
;
4694 ptr_directory_table
+= strnlen ((char *) ptr_directory_table
,
4695 ptr_directory_table
- end
) + 1;
4699 /* Skip the NUL at the end of the table. */
4702 /* Traverse the File Name table just to count the entries. */
4703 if (data
< end
&& *data
!= 0)
4705 unsigned char *ptr_file_name_table
= data
;
4707 while (data
< end
&& *data
!= 0)
4709 unsigned int bytes_read
;
4711 /* Skip Name, directory index, last modification time and length
4713 data
+= strnlen ((char *) data
, end
- data
) + 1;
4714 read_uleb128 (data
, & bytes_read
, end
);
4716 read_uleb128 (data
, & bytes_read
, end
);
4718 read_uleb128 (data
, & bytes_read
, end
);
4726 warn (_("file table ends unexpectedly\n"));
4731 /* Go through the file table again to save the strings. */
4732 file_table
= (File_Entry
*) xmalloc (n_files
* sizeof (File_Entry
));
4735 while (*ptr_file_name_table
!= 0)
4737 unsigned int bytes_read
;
4739 file_table
[i
].name
= ptr_file_name_table
;
4740 ptr_file_name_table
+= strnlen ((char *) ptr_file_name_table
,
4741 end
- ptr_file_name_table
) + 1;
4743 /* We are not interested in directory, time or size. */
4744 file_table
[i
].directory_index
= read_uleb128 (ptr_file_name_table
,
4746 ptr_file_name_table
+= bytes_read
;
4747 file_table
[i
].modification_date
= read_uleb128 (ptr_file_name_table
,
4749 ptr_file_name_table
+= bytes_read
;
4750 file_table
[i
].length
= read_uleb128 (ptr_file_name_table
, & bytes_read
, end
);
4751 ptr_file_name_table
+= bytes_read
;
4757 /* Skip the NUL at the end of the table. */
4761 /* Print the Compilation Unit's name and a header. */
4762 if (file_table
== NULL
)
4764 else if (directory_table
== NULL
)
4765 printf (_("CU: %s:\n"), file_table
[0].name
);
4768 unsigned int ix
= file_table
[0].directory_index
;
4769 const char *directory
;
4774 else if (n_directories
== 0)
4775 directory
= _("<unknown>");
4776 else if (ix
> n_directories
)
4778 warn (_("directory index %u > number of directories %s\n"),
4779 ix
, dwarf_vmatoa ("u", n_directories
));
4780 directory
= _("<corrupt>");
4783 directory
= (char *) directory_table
[ix
- 1];
4785 if (do_wide
|| strlen (directory
) < 76)
4786 printf (_("CU: %s/%s:\n"), directory
, file_table
[0].name
);
4788 printf ("%s:\n", file_table
[0].name
);
4791 printf (_("File name Line number Starting address View Stmt\n"));
4792 saved_linfo
= linfo
;
4795 /* This loop iterates through the Dwarf Line Number Program. */
4796 while (data
< end_of_sequence
)
4798 unsigned char op_code
;
4801 unsigned long int uladv
;
4802 unsigned int bytes_read
;
4803 int is_special_opcode
= 0;
4808 if (op_code
>= linfo
.li_opcode_base
)
4810 op_code
-= linfo
.li_opcode_base
;
4811 uladv
= (op_code
/ linfo
.li_line_range
);
4812 if (linfo
.li_max_ops_per_insn
== 1)
4814 uladv
*= linfo
.li_min_insn_length
;
4815 state_machine_regs
.address
+= uladv
;
4817 state_machine_regs
.view
= 0;
4822 = ((state_machine_regs
.op_index
+ uladv
)
4823 / linfo
.li_max_ops_per_insn
)
4824 * linfo
.li_min_insn_length
;
4825 state_machine_regs
.address
4827 state_machine_regs
.op_index
4828 = (state_machine_regs
.op_index
+ uladv
)
4829 % linfo
.li_max_ops_per_insn
;
4831 state_machine_regs
.view
= 0;
4834 adv
= (op_code
% linfo
.li_line_range
) + linfo
.li_line_base
;
4835 state_machine_regs
.line
+= adv
;
4836 is_special_opcode
= 1;
4837 /* Increment view after printing this row. */
4839 else switch (op_code
)
4841 case DW_LNS_extended_op
:
4843 unsigned int ext_op_code_len
;
4844 unsigned char ext_op_code
;
4845 unsigned char *op_code_data
= data
;
4847 ext_op_code_len
= read_uleb128 (op_code_data
, &bytes_read
,
4849 op_code_data
+= bytes_read
;
4851 if (ext_op_code_len
== 0)
4853 warn (_("Badly formed extended line op encountered!\n"));
4856 ext_op_code_len
+= bytes_read
;
4857 ext_op_code
= *op_code_data
++;
4861 switch (ext_op_code
)
4863 case DW_LNE_end_sequence
:
4864 /* Reset stuff after printing this row. */
4866 case DW_LNE_set_address
:
4867 SAFE_BYTE_GET_AND_INC (state_machine_regs
.address
,
4869 ext_op_code_len
- bytes_read
- 1,
4871 state_machine_regs
.op_index
= 0;
4872 state_machine_regs
.view
= 0;
4874 case DW_LNE_define_file
:
4876 file_table
= (File_Entry
*) xrealloc
4877 (file_table
, (n_files
+ 1) * sizeof (File_Entry
));
4879 ++state_machine_regs
.last_file_entry
;
4880 /* Source file name. */
4881 file_table
[n_files
].name
= op_code_data
;
4882 op_code_data
+= strlen ((char *) op_code_data
) + 1;
4883 /* Directory index. */
4884 file_table
[n_files
].directory_index
=
4885 read_uleb128 (op_code_data
, & bytes_read
,
4887 op_code_data
+= bytes_read
;
4888 /* Last modification time. */
4889 file_table
[n_files
].modification_date
=
4890 read_uleb128 (op_code_data
, & bytes_read
,
4892 op_code_data
+= bytes_read
;
4894 file_table
[n_files
].length
=
4895 read_uleb128 (op_code_data
, & bytes_read
,
4901 case DW_LNE_set_discriminator
:
4902 case DW_LNE_HP_set_sequence
:
4903 /* Simply ignored. */
4907 printf (_("UNKNOWN (%u): length %d\n"),
4908 ext_op_code
, ext_op_code_len
- bytes_read
);
4911 data
+= ext_op_code_len
;
4915 /* Increment view after printing this row. */
4918 case DW_LNS_advance_pc
:
4919 uladv
= read_uleb128 (data
, & bytes_read
, end
);
4921 if (linfo
.li_max_ops_per_insn
== 1)
4923 uladv
*= linfo
.li_min_insn_length
;
4924 state_machine_regs
.address
+= uladv
;
4926 state_machine_regs
.view
= 0;
4931 = ((state_machine_regs
.op_index
+ uladv
)
4932 / linfo
.li_max_ops_per_insn
)
4933 * linfo
.li_min_insn_length
;
4934 state_machine_regs
.address
4936 state_machine_regs
.op_index
4937 = (state_machine_regs
.op_index
+ uladv
)
4938 % linfo
.li_max_ops_per_insn
;
4940 state_machine_regs
.view
= 0;
4944 case DW_LNS_advance_line
:
4945 adv
= read_sleb128 (data
, & bytes_read
, end
);
4947 state_machine_regs
.line
+= adv
;
4950 case DW_LNS_set_file
:
4951 adv
= read_uleb128 (data
, & bytes_read
, end
);
4953 state_machine_regs
.file
= adv
;
4956 unsigned file
= state_machine_regs
.file
- 1;
4959 if (file_table
== NULL
|| n_files
== 0)
4960 printf (_("\n [Use file table entry %d]\n"), file
);
4962 else if (file
>= n_files
)
4964 warn (_("file index %u > number of files %u\n"), file
+ 1, n_files
);
4965 printf (_("\n <over large file table index %u>"), file
);
4967 else if ((dir
= file_table
[file
].directory_index
) == 0)
4968 /* If directory index is 0, that means current directory. */
4969 printf ("\n./%s:[++]\n", file_table
[file
].name
);
4970 else if (directory_table
== NULL
|| n_directories
== 0)
4971 printf (_("\n [Use file %s in directory table entry %d]\n"),
4972 file_table
[file
].name
, dir
);
4974 else if (dir
> n_directories
)
4976 warn (_("directory index %u > number of directories %s\n"),
4977 dir
, dwarf_vmatoa ("u", n_directories
));
4978 printf (_("\n <over large directory table entry %u>\n"), dir
);
4981 printf ("\n%s/%s:\n",
4982 /* The directory index starts counting at 1. */
4983 directory_table
[dir
- 1], file_table
[file
].name
);
4987 case DW_LNS_set_column
:
4988 uladv
= read_uleb128 (data
, & bytes_read
, end
);
4990 state_machine_regs
.column
= uladv
;
4993 case DW_LNS_negate_stmt
:
4994 adv
= state_machine_regs
.is_stmt
;
4996 state_machine_regs
.is_stmt
= adv
;
4999 case DW_LNS_set_basic_block
:
5000 state_machine_regs
.basic_block
= 1;
5003 case DW_LNS_const_add_pc
:
5004 uladv
= ((255 - linfo
.li_opcode_base
) / linfo
.li_line_range
);
5005 if (linfo
.li_max_ops_per_insn
== 1)
5007 uladv
*= linfo
.li_min_insn_length
;
5008 state_machine_regs
.address
+= uladv
;
5010 state_machine_regs
.view
= 0;
5015 = ((state_machine_regs
.op_index
+ uladv
)
5016 / linfo
.li_max_ops_per_insn
)
5017 * linfo
.li_min_insn_length
;
5018 state_machine_regs
.address
5020 state_machine_regs
.op_index
5021 = (state_machine_regs
.op_index
+ uladv
)
5022 % linfo
.li_max_ops_per_insn
;
5024 state_machine_regs
.view
= 0;
5028 case DW_LNS_fixed_advance_pc
:
5029 SAFE_BYTE_GET_AND_INC (uladv
, data
, 2, end
);
5030 state_machine_regs
.address
+= uladv
;
5031 state_machine_regs
.op_index
= 0;
5032 /* Do NOT reset view. */
5035 case DW_LNS_set_prologue_end
:
5038 case DW_LNS_set_epilogue_begin
:
5041 case DW_LNS_set_isa
:
5042 uladv
= read_uleb128 (data
, & bytes_read
, end
);
5044 printf (_(" Set ISA to %lu\n"), uladv
);
5048 printf (_(" Unknown opcode %d with operands: "), op_code
);
5050 if (standard_opcodes
!= NULL
)
5051 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
5053 printf ("0x%s%s", dwarf_vmatoa ("x", read_uleb128 (data
,
5055 i
== 1 ? "" : ", ");
5062 /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row
5063 to the DWARF address/line matrix. */
5064 if ((is_special_opcode
) || (xop
== -DW_LNE_end_sequence
)
5065 || (xop
== DW_LNS_copy
))
5067 const unsigned int MAX_FILENAME_LENGTH
= 35;
5069 char *newFileName
= NULL
;
5070 size_t fileNameLength
;
5074 unsigned indx
= state_machine_regs
.file
- 1;
5076 if (indx
>= n_files
)
5078 warn (_("corrupt file index %u encountered\n"), indx
);
5079 fileName
= _("<corrupt>");
5082 fileName
= (char *) file_table
[indx
].name
;
5085 fileName
= _("<unknown>");
5087 fileNameLength
= strlen (fileName
);
5089 if ((fileNameLength
> MAX_FILENAME_LENGTH
) && (!do_wide
))
5091 newFileName
= (char *) xmalloc (MAX_FILENAME_LENGTH
+ 1);
5092 /* Truncate file name */
5093 strncpy (newFileName
,
5094 fileName
+ fileNameLength
- MAX_FILENAME_LENGTH
,
5095 MAX_FILENAME_LENGTH
+ 1);
5099 newFileName
= (char *) xmalloc (fileNameLength
+ 1);
5100 strncpy (newFileName
, fileName
, fileNameLength
+ 1);
5103 if (!do_wide
|| (fileNameLength
<= MAX_FILENAME_LENGTH
))
5105 if (linfo
.li_max_ops_per_insn
== 1)
5106 printf ("%-35s %11d %#18" DWARF_VMA_FMT
"x",
5107 newFileName
, state_machine_regs
.line
,
5108 state_machine_regs
.address
);
5110 printf ("%-35s %11d %#18" DWARF_VMA_FMT
"x[%d]",
5111 newFileName
, state_machine_regs
.line
,
5112 state_machine_regs
.address
,
5113 state_machine_regs
.op_index
);
5117 if (linfo
.li_max_ops_per_insn
== 1)
5118 printf ("%s %11d %#18" DWARF_VMA_FMT
"x",
5119 newFileName
, state_machine_regs
.line
,
5120 state_machine_regs
.address
);
5122 printf ("%s %11d %#18" DWARF_VMA_FMT
"x[%d]",
5123 newFileName
, state_machine_regs
.line
,
5124 state_machine_regs
.address
,
5125 state_machine_regs
.op_index
);
5128 if (state_machine_regs
.view
)
5129 printf (" %6u", state_machine_regs
.view
);
5133 if (state_machine_regs
.is_stmt
)
5137 state_machine_regs
.view
++;
5139 if (xop
== -DW_LNE_end_sequence
)
5141 reset_state_machine (linfo
.li_default_is_stmt
);
5156 if (directory_table
)
5158 free (directory_table
);
5159 directory_table
= NULL
;
5170 display_debug_lines (struct dwarf_section
*section
, void *file
)
5172 unsigned char *data
= section
->start
;
5173 unsigned char *end
= data
+ section
->size
;
5175 int retValDecoded
= 1;
5177 if (do_debug_lines
== 0)
5178 do_debug_lines
|= FLAG_DEBUG_LINES_RAW
;
5180 if (do_debug_lines
& FLAG_DEBUG_LINES_RAW
)
5181 retValRaw
= display_debug_lines_raw (section
, data
, end
, file
);
5183 if (do_debug_lines
& FLAG_DEBUG_LINES_DECODED
)
5184 retValDecoded
= display_debug_lines_decoded (section
, data
, data
, end
, file
);
5186 if (!retValRaw
|| !retValDecoded
)
5193 find_debug_info_for_offset (unsigned long offset
)
5197 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
5200 for (i
= 0; i
< num_debug_info_entries
; i
++)
5201 if (debug_information
[i
].cu_offset
== offset
)
5202 return debug_information
+ i
;
5208 get_gdb_index_symbol_kind_name (gdb_index_symbol_kind kind
)
5210 /* See gdb/gdb-index.h. */
5211 static const char * const kinds
[] =
5223 return _ (kinds
[kind
]);
5227 display_debug_pubnames_worker (struct dwarf_section
*section
,
5228 void *file ATTRIBUTE_UNUSED
,
5231 DWARF2_Internal_PubNames names
;
5232 unsigned char *start
= section
->start
;
5233 unsigned char *end
= start
+ section
->size
;
5235 /* It does not matter if this load fails,
5236 we test for that later on. */
5237 load_debug_info (file
);
5239 introduce (section
, FALSE
);
5243 unsigned char *data
;
5244 unsigned long sec_off
;
5245 unsigned int offset_size
, initial_length_size
;
5247 SAFE_BYTE_GET_AND_INC (names
.pn_length
, start
, 4, end
);
5248 if (names
.pn_length
== 0xffffffff)
5250 SAFE_BYTE_GET_AND_INC (names
.pn_length
, start
, 8, end
);
5252 initial_length_size
= 12;
5257 initial_length_size
= 4;
5260 sec_off
= start
- section
->start
;
5261 if (sec_off
+ names
.pn_length
< sec_off
5262 || sec_off
+ names
.pn_length
> section
->size
)
5264 warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"),
5266 sec_off
- initial_length_size
,
5267 dwarf_vmatoa ("x", names
.pn_length
));
5272 start
+= names
.pn_length
;
5274 SAFE_BYTE_GET_AND_INC (names
.pn_version
, data
, 2, end
);
5275 SAFE_BYTE_GET_AND_INC (names
.pn_offset
, data
, offset_size
, end
);
5277 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
5278 && num_debug_info_entries
> 0
5279 && find_debug_info_for_offset (names
.pn_offset
) == NULL
)
5280 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
5281 (unsigned long) names
.pn_offset
, section
->name
);
5283 SAFE_BYTE_GET_AND_INC (names
.pn_size
, data
, offset_size
, end
);
5285 printf (_(" Length: %ld\n"),
5286 (long) names
.pn_length
);
5287 printf (_(" Version: %d\n"),
5289 printf (_(" Offset into .debug_info section: 0x%lx\n"),
5290 (unsigned long) names
.pn_offset
);
5291 printf (_(" Size of area in .debug_info section: %ld\n"),
5292 (long) names
.pn_size
);
5294 if (names
.pn_version
!= 2 && names
.pn_version
!= 3)
5296 static int warned
= 0;
5300 warn (_("Only DWARF 2 and 3 pubnames are currently supported\n"));
5308 printf (_("\n Offset Kind Name\n"));
5310 printf (_("\n Offset\tName\n"));
5314 bfd_size_type maxprint
;
5317 SAFE_BYTE_GET (offset
, data
, offset_size
, end
);
5322 data
+= offset_size
;
5325 maxprint
= (end
- data
) - 1;
5329 unsigned int kind_data
;
5330 gdb_index_symbol_kind kind
;
5331 const char *kind_name
;
5334 SAFE_BYTE_GET (kind_data
, data
, 1, end
);
5337 /* GCC computes the kind as the upper byte in the CU index
5338 word, and then right shifts it by the CU index size.
5339 Left shift KIND to where the gdb-index.h accessor macros
5341 kind_data
<<= GDB_INDEX_CU_BITSIZE
;
5342 kind
= GDB_INDEX_SYMBOL_KIND_VALUE (kind_data
);
5343 kind_name
= get_gdb_index_symbol_kind_name (kind
);
5344 is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (kind_data
);
5345 printf (" %-6lx %s,%-10s %.*s\n",
5346 (unsigned long) offset
, is_static
? _("s") : _("g"),
5347 kind_name
, (int) maxprint
, data
);
5350 printf (" %-6lx\t%.*s\n",
5351 (unsigned long) offset
, (int) maxprint
, data
);
5353 data
+= strnlen ((char *) data
, maxprint
) + 1;
5364 display_debug_pubnames (struct dwarf_section
*section
, void *file
)
5366 return display_debug_pubnames_worker (section
, file
, 0);
5370 display_debug_gnu_pubnames (struct dwarf_section
*section
, void *file
)
5372 return display_debug_pubnames_worker (section
, file
, 1);
5376 display_debug_macinfo (struct dwarf_section
*section
,
5377 void *file ATTRIBUTE_UNUSED
)
5379 unsigned char *start
= section
->start
;
5380 unsigned char *end
= start
+ section
->size
;
5381 unsigned char *curr
= start
;
5382 unsigned int bytes_read
;
5383 enum dwarf_macinfo_record_type op
;
5385 introduce (section
, FALSE
);
5389 unsigned int lineno
;
5390 const unsigned char *string
;
5392 op
= (enum dwarf_macinfo_record_type
) *curr
;
5397 case DW_MACINFO_start_file
:
5399 unsigned int filenum
;
5401 lineno
= read_uleb128 (curr
, & bytes_read
, end
);
5403 filenum
= read_uleb128 (curr
, & bytes_read
, end
);
5406 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"),
5411 case DW_MACINFO_end_file
:
5412 printf (_(" DW_MACINFO_end_file\n"));
5415 case DW_MACINFO_define
:
5416 lineno
= read_uleb128 (curr
, & bytes_read
, end
);
5419 curr
+= strnlen ((char *) string
, end
- string
) + 1;
5420 printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"),
5424 case DW_MACINFO_undef
:
5425 lineno
= read_uleb128 (curr
, & bytes_read
, end
);
5428 curr
+= strnlen ((char *) string
, end
- string
) + 1;
5429 printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"),
5433 case DW_MACINFO_vendor_ext
:
5435 unsigned int constant
;
5437 constant
= read_uleb128 (curr
, & bytes_read
, end
);
5440 curr
+= strnlen ((char *) string
, end
- string
) + 1;
5441 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"),
5451 /* Given LINE_OFFSET into the .debug_line section, attempt to return
5452 filename and dirname corresponding to file name table entry with index
5453 FILEIDX. Return NULL on failure. */
5455 static unsigned char *
5456 get_line_filename_and_dirname (dwarf_vma line_offset
,
5458 unsigned char **dir_name
)
5460 struct dwarf_section
*section
= &debug_displays
[line
].section
;
5461 unsigned char *hdrptr
, *dirtable
, *file_name
;
5462 unsigned int offset_size
, initial_length_size
;
5463 unsigned int version
, opcode_base
, bytes_read
;
5464 dwarf_vma length
, diridx
;
5465 const unsigned char * end
;
5468 if (section
->start
== NULL
5469 || line_offset
>= section
->size
5473 hdrptr
= section
->start
+ line_offset
;
5474 end
= section
->start
+ section
->size
;
5476 SAFE_BYTE_GET_AND_INC (length
, hdrptr
, 4, end
);
5477 if (length
== 0xffffffff)
5479 /* This section is 64-bit DWARF 3. */
5480 SAFE_BYTE_GET_AND_INC (length
, hdrptr
, 8, end
);
5482 initial_length_size
= 12;
5487 initial_length_size
= 4;
5489 if (length
+ initial_length_size
< length
5490 || length
+ initial_length_size
> section
->size
)
5493 SAFE_BYTE_GET_AND_INC (version
, hdrptr
, 2, end
);
5494 if (version
!= 2 && version
!= 3 && version
!= 4)
5496 hdrptr
+= offset_size
+ 1;/* Skip prologue_length and min_insn_length. */
5498 hdrptr
++; /* Skip max_ops_per_insn. */
5499 hdrptr
+= 3; /* Skip default_is_stmt, line_base, line_range. */
5501 SAFE_BYTE_GET_AND_INC (opcode_base
, hdrptr
, 1, end
);
5502 if (opcode_base
== 0)
5505 hdrptr
+= opcode_base
- 1;
5510 /* Skip over dirname table. */
5511 while (*hdrptr
!= '\0')
5513 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
) + 1;
5517 hdrptr
++; /* Skip the NUL at the end of the table. */
5519 /* Now skip over preceding filename table entries. */
5520 for (; hdrptr
< end
&& *hdrptr
!= '\0' && fileidx
> 1; fileidx
--)
5522 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
) + 1;
5523 read_uleb128 (hdrptr
, &bytes_read
, end
);
5524 hdrptr
+= bytes_read
;
5525 read_uleb128 (hdrptr
, &bytes_read
, end
);
5526 hdrptr
+= bytes_read
;
5527 read_uleb128 (hdrptr
, &bytes_read
, end
);
5528 hdrptr
+= bytes_read
;
5530 if (hdrptr
>= end
|| *hdrptr
== '\0')
5534 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
) + 1;
5537 diridx
= read_uleb128 (hdrptr
, &bytes_read
, end
);
5540 for (; dirtable
< end
&& *dirtable
!= '\0' && diridx
> 1; diridx
--)
5541 dirtable
+= strnlen ((char *) dirtable
, end
- dirtable
) + 1;
5542 if (dirtable
>= end
|| *dirtable
== '\0')
5544 *dir_name
= dirtable
;
5549 display_debug_macro (struct dwarf_section
*section
,
5552 unsigned char *start
= section
->start
;
5553 unsigned char *end
= start
+ section
->size
;
5554 unsigned char *curr
= start
;
5555 unsigned char *extended_op_buf
[256];
5556 unsigned int bytes_read
;
5558 load_debug_section_with_follow (str
, file
);
5559 load_debug_section_with_follow (line
, file
);
5561 introduce (section
, FALSE
);
5565 unsigned int lineno
, version
, flags
;
5566 unsigned int offset_size
= 4;
5567 const unsigned char *string
;
5568 dwarf_vma line_offset
= 0, sec_offset
= curr
- start
, offset
;
5569 unsigned char **extended_ops
= NULL
;
5571 SAFE_BYTE_GET_AND_INC (version
, curr
, 2, end
);
5572 if (version
!= 4 && version
!= 5)
5574 error (_("Only GNU extension to DWARF 4 or 5 of %s is currently supported.\n"),
5579 SAFE_BYTE_GET_AND_INC (flags
, curr
, 1, end
);
5582 printf (_(" Offset: 0x%lx\n"),
5583 (unsigned long) sec_offset
);
5584 printf (_(" Version: %d\n"), version
);
5585 printf (_(" Offset size: %d\n"), offset_size
);
5588 SAFE_BYTE_GET_AND_INC (line_offset
, curr
, offset_size
, end
);
5589 printf (_(" Offset into .debug_line: 0x%lx\n"),
5590 (unsigned long) line_offset
);
5594 unsigned int i
, count
, op
;
5597 SAFE_BYTE_GET_AND_INC (count
, curr
, 1, end
);
5599 memset (extended_op_buf
, 0, sizeof (extended_op_buf
));
5600 extended_ops
= extended_op_buf
;
5603 printf (_(" Extension opcode arguments:\n"));
5604 for (i
= 0; i
< count
; i
++)
5606 SAFE_BYTE_GET_AND_INC (op
, curr
, 1, end
);
5607 extended_ops
[op
] = curr
;
5608 nargs
= read_uleb128 (curr
, &bytes_read
, end
);
5611 printf (_(" DW_MACRO_%02x has no arguments\n"), op
);
5614 printf (_(" DW_MACRO_%02x arguments: "), op
);
5615 for (n
= 0; n
< nargs
; n
++)
5619 SAFE_BYTE_GET_AND_INC (form
, curr
, 1, end
);
5620 printf ("%s%s", get_FORM_name (form
),
5621 n
== nargs
- 1 ? "\n" : ", ");
5631 case DW_FORM_block1
:
5632 case DW_FORM_block2
:
5633 case DW_FORM_block4
:
5635 case DW_FORM_string
:
5637 case DW_FORM_sec_offset
:
5640 error (_("Invalid extension opcode form %s\n"),
5641 get_FORM_name (form
));
5657 error (_(".debug_macro section not zero terminated\n"));
5661 SAFE_BYTE_GET_AND_INC (op
, curr
, 1, end
);
5667 case DW_MACRO_start_file
:
5669 unsigned int filenum
;
5670 unsigned char *file_name
= NULL
, *dir_name
= NULL
;
5672 lineno
= read_uleb128 (curr
, &bytes_read
, end
);
5674 filenum
= read_uleb128 (curr
, &bytes_read
, end
);
5677 if ((flags
& 2) == 0)
5678 error (_("DW_MACRO_start_file used, but no .debug_line offset provided.\n"));
5681 = get_line_filename_and_dirname (line_offset
, filenum
,
5683 if (file_name
== NULL
)
5684 printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d\n"),
5687 printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d filename: %s%s%s\n"),
5689 dir_name
!= NULL
? (const char *) dir_name
: "",
5690 dir_name
!= NULL
? "/" : "", file_name
);
5694 case DW_MACRO_end_file
:
5695 printf (_(" DW_MACRO_end_file\n"));
5698 case DW_MACRO_define
:
5699 lineno
= read_uleb128 (curr
, &bytes_read
, end
);
5702 curr
+= strnlen ((char *) string
, end
- string
) + 1;
5703 printf (_(" DW_MACRO_define - lineno : %d macro : %s\n"),
5707 case DW_MACRO_undef
:
5708 lineno
= read_uleb128 (curr
, &bytes_read
, end
);
5711 curr
+= strnlen ((char *) string
, end
- string
) + 1;
5712 printf (_(" DW_MACRO_undef - lineno : %d macro : %s\n"),
5716 case DW_MACRO_define_strp
:
5717 lineno
= read_uleb128 (curr
, &bytes_read
, end
);
5719 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
5720 string
= fetch_indirect_string (offset
);
5721 printf (_(" DW_MACRO_define_strp - lineno : %d macro : %s\n"),
5725 case DW_MACRO_undef_strp
:
5726 lineno
= read_uleb128 (curr
, &bytes_read
, end
);
5728 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
5729 string
= fetch_indirect_string (offset
);
5730 printf (_(" DW_MACRO_undef_strp - lineno : %d macro : %s\n"),
5734 case DW_MACRO_import
:
5735 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
5736 printf (_(" DW_MACRO_import - offset : 0x%lx\n"),
5737 (unsigned long) offset
);
5740 case DW_MACRO_define_sup
:
5741 lineno
= read_uleb128 (curr
, &bytes_read
, end
);
5743 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
5744 printf (_(" DW_MACRO_define_sup - lineno : %d macro offset : 0x%lx\n"),
5745 lineno
, (unsigned long) offset
);
5748 case DW_MACRO_undef_sup
:
5749 lineno
= read_uleb128 (curr
, &bytes_read
, end
);
5751 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
5752 printf (_(" DW_MACRO_undef_sup - lineno : %d macro offset : 0x%lx\n"),
5753 lineno
, (unsigned long) offset
);
5756 case DW_MACRO_import_sup
:
5757 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
5758 printf (_(" DW_MACRO_import_sup - offset : 0x%lx\n"),
5759 (unsigned long) offset
);
5763 if (extended_ops
== NULL
|| extended_ops
[op
] == NULL
)
5765 error (_(" Unknown macro opcode %02x seen\n"), op
);
5770 /* Skip over unhandled opcodes. */
5772 unsigned char *desc
= extended_ops
[op
];
5773 nargs
= read_uleb128 (desc
, &bytes_read
, end
);
5777 printf (_(" DW_MACRO_%02x\n"), op
);
5780 printf (_(" DW_MACRO_%02x -"), op
);
5781 for (n
= 0; n
< nargs
; n
++)
5785 /* DW_FORM_implicit_const is not expected here. */
5786 SAFE_BYTE_GET_AND_INC (val
, desc
, 1, end
);
5788 = read_and_display_attr_value (0, val
, 0,
5789 start
, curr
, end
, 0, 0, offset_size
,
5790 version
, NULL
, 0, NULL
,
5808 display_debug_abbrev (struct dwarf_section
*section
,
5809 void *file ATTRIBUTE_UNUSED
)
5811 abbrev_entry
*entry
;
5812 unsigned char *start
= section
->start
;
5813 unsigned char *end
= start
+ section
->size
;
5815 introduce (section
, FALSE
);
5819 unsigned char *last
;
5824 start
= process_abbrev_section (start
, end
);
5826 if (first_abbrev
== NULL
)
5829 printf (_(" Number TAG (0x%lx)\n"), (long) (last
- section
->start
));
5831 for (entry
= first_abbrev
; entry
; entry
= entry
->next
)
5835 printf (" %ld %s [%s]\n",
5837 get_TAG_name (entry
->tag
),
5838 entry
->children
? _("has children") : _("no children"));
5840 for (attr
= entry
->first_attr
; attr
; attr
= attr
->next
)
5842 printf (" %-18s %s",
5843 get_AT_name (attr
->attribute
),
5844 get_FORM_name (attr
->form
));
5845 if (attr
->form
== DW_FORM_implicit_const
)
5846 printf (": %" BFD_VMA_FMT
"d", attr
->implicit_const
);
5858 /* Return true when ADDR is the maximum address, when addresses are
5859 POINTER_SIZE bytes long. */
5862 is_max_address (dwarf_vma addr
, unsigned int pointer_size
)
5864 dwarf_vma mask
= ~(~(dwarf_vma
) 1 << (pointer_size
* 8 - 1));
5865 return ((addr
& mask
) == mask
);
5868 /* Display a view pair list starting at *VSTART_PTR and ending at
5869 VLISTEND within SECTION. */
5872 display_view_pair_list (struct dwarf_section
*section
,
5873 unsigned char **vstart_ptr
,
5874 unsigned int debug_info_entry
,
5875 unsigned char *vlistend
)
5877 unsigned char *vstart
= *vstart_ptr
;
5878 unsigned char *section_end
= section
->start
+ section
->size
;
5879 unsigned int pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
5881 if (vlistend
< section_end
)
5882 section_end
= vlistend
;
5886 while (vstart
< section_end
)
5888 dwarf_vma off
= vstart
- section
->start
;
5889 dwarf_vma vbegin
, vend
;
5891 unsigned int bytes_read
;
5892 vbegin
= read_uleb128 (vstart
, &bytes_read
, section_end
);
5893 vstart
+= bytes_read
;
5894 if (vstart
== section_end
)
5896 vstart
-= bytes_read
;
5900 vend
= read_uleb128 (vstart
, &bytes_read
, section_end
);
5901 vstart
+= bytes_read
;
5903 printf (" %8.8lx ", (unsigned long) off
);
5905 print_dwarf_view (vbegin
, pointer_size
, 1);
5906 print_dwarf_view (vend
, pointer_size
, 1);
5907 printf (_("location view pair\n"));
5911 *vstart_ptr
= vstart
;
5914 /* Display a location list from a normal (ie, non-dwo) .debug_loc section. */
5917 display_loc_list (struct dwarf_section
*section
,
5918 unsigned char **start_ptr
,
5919 unsigned int debug_info_entry
,
5921 dwarf_vma base_address
,
5922 unsigned char **vstart_ptr
,
5925 unsigned char *start
= *start_ptr
, *vstart
= *vstart_ptr
;
5926 unsigned char *section_end
= section
->start
+ section
->size
;
5927 unsigned long cu_offset
;
5928 unsigned int pointer_size
;
5929 unsigned int offset_size
;
5934 unsigned short length
;
5935 int need_frame_base
;
5937 if (debug_info_entry
>= num_debug_info_entries
)
5939 warn (_("No debug information available for loc lists of entry: %u\n"),
5944 cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
5945 pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
5946 offset_size
= debug_information
[debug_info_entry
].offset_size
;
5947 dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
5949 if (pointer_size
< 2 || pointer_size
> 8)
5951 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
5952 pointer_size
, debug_info_entry
);
5958 dwarf_vma off
= offset
+ (start
- *start_ptr
);
5959 dwarf_vma vbegin
= vm1
, vend
= vm1
;
5961 if (start
+ 2 * pointer_size
> section_end
)
5963 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5964 (unsigned long) offset
);
5968 printf (" %8.8lx ", (unsigned long) off
);
5970 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, section_end
);
5971 SAFE_BYTE_GET_AND_INC (end
, start
, pointer_size
, section_end
);
5973 if (begin
== 0 && end
== 0)
5975 /* PR 18374: In a object file we can have a location list that
5976 starts with a begin and end of 0 because there are relocations
5977 that need to be applied to the addresses. Actually applying
5978 the relocations now does not help as they will probably resolve
5979 to 0, since the object file has not been fully linked. Real
5980 end of list markers will not have any relocations against them. */
5981 if (! reloc_at (section
, off
)
5982 && ! reloc_at (section
, off
+ pointer_size
))
5984 printf (_("<End of list>\n"));
5989 /* Check base address specifiers. */
5990 if (is_max_address (begin
, pointer_size
)
5991 && !is_max_address (end
, pointer_size
))
5994 print_dwarf_vma (begin
, pointer_size
);
5995 print_dwarf_vma (end
, pointer_size
);
5996 printf (_("(base address)\n"));
6002 unsigned int bytes_read
;
6004 off
= offset
+ (vstart
- *start_ptr
);
6006 vbegin
= read_uleb128 (vstart
, &bytes_read
, section_end
);
6007 vstart
+= bytes_read
;
6008 print_dwarf_view (vbegin
, pointer_size
, 1);
6010 vend
= read_uleb128 (vstart
, &bytes_read
, section_end
);
6011 vstart
+= bytes_read
;
6012 print_dwarf_view (vend
, pointer_size
, 1);
6014 printf (_("views at %8.8lx for:\n %*s "),
6015 (unsigned long) off
, 8, "");
6018 if (start
+ 2 > section_end
)
6020 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6021 (unsigned long) offset
);
6025 SAFE_BYTE_GET_AND_INC (length
, start
, 2, section_end
);
6027 if (start
+ length
> section_end
)
6029 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6030 (unsigned long) offset
);
6034 print_dwarf_vma (begin
+ base_address
, pointer_size
);
6035 print_dwarf_vma (end
+ base_address
, pointer_size
);
6038 need_frame_base
= decode_location_expression (start
,
6043 cu_offset
, section
);
6046 if (need_frame_base
&& !has_frame_base
)
6047 printf (_(" [without DW_AT_frame_base]"));
6049 if (begin
== end
&& vbegin
== vend
)
6050 fputs (_(" (start == end)"), stdout
);
6051 else if (begin
> end
|| (begin
== end
&& vbegin
> vend
))
6052 fputs (_(" (start > end)"), stdout
);
6060 *vstart_ptr
= vstart
;
6063 /* Display a location list from a normal (ie, non-dwo) .debug_loclists section. */
6066 display_loclists_list (struct dwarf_section
*section
,
6067 unsigned char **start_ptr
,
6068 unsigned int debug_info_entry
,
6070 dwarf_vma base_address
,
6071 unsigned char **vstart_ptr
,
6074 unsigned char *start
= *start_ptr
, *vstart
= *vstart_ptr
;
6075 unsigned char *section_end
= section
->start
+ section
->size
;
6076 unsigned long cu_offset
;
6077 unsigned int pointer_size
;
6078 unsigned int offset_size
;
6080 unsigned int bytes_read
;
6082 /* Initialize it due to a false compiler warning. */
6083 dwarf_vma begin
= -1, vbegin
= -1;
6084 dwarf_vma end
= -1, vend
= -1;
6086 int need_frame_base
;
6088 if (debug_info_entry
>= num_debug_info_entries
)
6090 warn (_("No debug information available for "
6091 "loclists lists of entry: %u\n"),
6096 cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
6097 pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
6098 offset_size
= debug_information
[debug_info_entry
].offset_size
;
6099 dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
6101 if (pointer_size
< 2 || pointer_size
> 8)
6103 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
6104 pointer_size
, debug_info_entry
);
6110 dwarf_vma off
= offset
+ (start
- *start_ptr
);
6111 enum dwarf_location_list_entry_type llet
;
6113 if (start
+ 1 > section_end
)
6115 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6116 (unsigned long) offset
);
6120 printf (" %8.8lx ", (unsigned long) off
);
6122 SAFE_BYTE_GET_AND_INC (llet
, start
, 1, section_end
);
6124 if (vstart
&& llet
== DW_LLE_offset_pair
)
6126 off
= offset
+ (vstart
- *start_ptr
);
6128 vbegin
= read_uleb128 (vstart
, &bytes_read
, section_end
);
6129 vstart
+= bytes_read
;
6130 print_dwarf_view (vbegin
, pointer_size
, 1);
6132 vend
= read_uleb128 (vstart
, &bytes_read
, section_end
);
6133 vstart
+= bytes_read
;
6134 print_dwarf_view (vend
, pointer_size
, 1);
6136 printf (_("views at %8.8lx for:\n %*s "),
6137 (unsigned long) off
, 8, "");
6142 case DW_LLE_end_of_list
:
6143 printf (_("<End of list>\n"));
6145 case DW_LLE_offset_pair
:
6146 begin
= read_uleb128 (start
, &bytes_read
, section_end
);
6147 start
+= bytes_read
;
6148 end
= read_uleb128 (start
, &bytes_read
, section_end
);
6149 start
+= bytes_read
;
6151 case DW_LLE_base_address
:
6152 SAFE_BYTE_GET_AND_INC (base_address
, start
, pointer_size
,
6154 print_dwarf_vma (base_address
, pointer_size
);
6155 printf (_("(base address)\n"));
6157 #ifdef DW_LLE_view_pair
6158 case DW_LLE_view_pair
:
6160 printf (_("View pair entry in loclist with locviews attribute\n"));
6161 vbegin
= read_uleb128 (start
, &bytes_read
, section_end
);
6162 start
+= bytes_read
;
6163 print_dwarf_view (vbegin
, pointer_size
, 1);
6165 vend
= read_uleb128 (start
, &bytes_read
, section_end
);
6166 start
+= bytes_read
;
6167 print_dwarf_view (vend
, pointer_size
, 1);
6169 printf (_("views for:\n"));
6173 error (_("Invalid location list entry type %d\n"), llet
);
6176 if (llet
== DW_LLE_end_of_list
)
6178 if (llet
!= DW_LLE_offset_pair
)
6181 if (start
+ 2 > section_end
)
6183 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6184 (unsigned long) offset
);
6188 length
= read_uleb128 (start
, &bytes_read
, section_end
);
6189 start
+= bytes_read
;
6191 print_dwarf_vma (begin
+ base_address
, pointer_size
);
6192 print_dwarf_vma (end
+ base_address
, pointer_size
);
6195 need_frame_base
= decode_location_expression (start
,
6200 cu_offset
, section
);
6203 if (need_frame_base
&& !has_frame_base
)
6204 printf (_(" [without DW_AT_frame_base]"));
6206 if (begin
== end
&& vbegin
== vend
)
6207 fputs (_(" (start == end)"), stdout
);
6208 else if (begin
> end
|| (begin
== end
&& vbegin
> vend
))
6209 fputs (_(" (start > end)"), stdout
);
6217 if (vbegin
!= vm1
|| vend
!= vm1
)
6218 printf (_("Trailing view pair not used in a range"));
6221 *vstart_ptr
= vstart
;
6224 /* Print a .debug_addr table index in decimal, surrounded by square brackets,
6225 right-adjusted in a field of length LEN, and followed by a space. */
6228 print_addr_index (unsigned int idx
, unsigned int len
)
6230 static char buf
[15];
6231 snprintf (buf
, sizeof (buf
), "[%d]", idx
);
6232 printf ("%*s ", len
, buf
);
6235 /* Display a location list from a .dwo section. It uses address indexes rather
6236 than embedded addresses. This code closely follows display_loc_list, but the
6237 two are sufficiently different that combining things is very ugly. */
6240 display_loc_list_dwo (struct dwarf_section
*section
,
6241 unsigned char **start_ptr
,
6242 unsigned int debug_info_entry
,
6244 unsigned char **vstart_ptr
,
6247 unsigned char *start
= *start_ptr
, *vstart
= *vstart_ptr
;
6248 unsigned char *section_end
= section
->start
+ section
->size
;
6249 unsigned long cu_offset
;
6250 unsigned int pointer_size
;
6251 unsigned int offset_size
;
6254 unsigned short length
;
6255 int need_frame_base
;
6257 unsigned int bytes_read
;
6259 if (debug_info_entry
>= num_debug_info_entries
)
6261 warn (_("No debug information for loc lists of entry: %u\n"),
6266 cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
6267 pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
6268 offset_size
= debug_information
[debug_info_entry
].offset_size
;
6269 dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
6271 if (pointer_size
< 2 || pointer_size
> 8)
6273 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
6274 pointer_size
, debug_info_entry
);
6280 printf (" %8.8lx ", (unsigned long) (offset
+ (start
- *start_ptr
)));
6282 if (start
>= section_end
)
6284 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6285 (unsigned long) offset
);
6289 SAFE_BYTE_GET_AND_INC (entry_type
, start
, 1, section_end
);
6302 dwarf_vma off
= offset
+ (vstart
- *start_ptr
);
6304 view
= read_uleb128 (vstart
, &bytes_read
, section_end
);
6305 vstart
+= bytes_read
;
6306 print_dwarf_view (view
, 8, 1);
6308 view
= read_uleb128 (vstart
, &bytes_read
, section_end
);
6309 vstart
+= bytes_read
;
6310 print_dwarf_view (view
, 8, 1);
6312 printf (_("views at %8.8lx for:\n %*s "),
6313 (unsigned long) off
, 8, "");
6321 case 0: /* A terminating entry. */
6323 *vstart_ptr
= vstart
;
6324 printf (_("<End of list>\n"));
6326 case 1: /* A base-address entry. */
6327 idx
= read_uleb128 (start
, &bytes_read
, section_end
);
6328 start
+= bytes_read
;
6329 print_addr_index (idx
, 8);
6330 printf ("%*s", 9 + (vstart
? 2 * 6 : 0), "");
6331 printf (_("(base address selection entry)\n"));
6333 case 2: /* A start/end entry. */
6334 idx
= read_uleb128 (start
, &bytes_read
, section_end
);
6335 start
+= bytes_read
;
6336 print_addr_index (idx
, 8);
6337 idx
= read_uleb128 (start
, &bytes_read
, section_end
);
6338 start
+= bytes_read
;
6339 print_addr_index (idx
, 8);
6341 case 3: /* A start/length entry. */
6342 idx
= read_uleb128 (start
, &bytes_read
, section_end
);
6343 start
+= bytes_read
;
6344 print_addr_index (idx
, 8);
6345 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
6346 printf ("%08x ", idx
);
6348 case 4: /* An offset pair entry. */
6349 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
6350 printf ("%08x ", idx
);
6351 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
6352 printf ("%08x ", idx
);
6355 warn (_("Unknown location list entry type 0x%x.\n"), entry_type
);
6357 *vstart_ptr
= vstart
;
6361 if (start
+ 2 > section_end
)
6363 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6364 (unsigned long) offset
);
6368 SAFE_BYTE_GET_AND_INC (length
, start
, 2, section_end
);
6369 if (start
+ length
> section_end
)
6371 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6372 (unsigned long) offset
);
6377 need_frame_base
= decode_location_expression (start
,
6382 cu_offset
, section
);
6385 if (need_frame_base
&& !has_frame_base
)
6386 printf (_(" [without DW_AT_frame_base]"));
6394 *vstart_ptr
= vstart
;
6397 /* Sort array of indexes in ascending order of loc_offsets[idx] and
6400 static dwarf_vma
*loc_offsets
, *loc_views
;
6403 loc_offsets_compar (const void *ap
, const void *bp
)
6405 dwarf_vma a
= loc_offsets
[*(const unsigned int *) ap
];
6406 dwarf_vma b
= loc_offsets
[*(const unsigned int *) bp
];
6408 int ret
= (a
> b
) - (b
> a
);
6412 a
= loc_views
[*(const unsigned int *) ap
];
6413 b
= loc_views
[*(const unsigned int *) bp
];
6415 ret
= (a
> b
) - (b
> a
);
6421 display_debug_loc (struct dwarf_section
*section
, void *file
)
6423 unsigned char *start
= section
->start
, *vstart
= NULL
;
6424 unsigned long bytes
;
6425 unsigned char *section_begin
= start
;
6426 unsigned int num_loc_list
= 0;
6427 unsigned long last_offset
= 0;
6428 unsigned long last_view
= 0;
6429 unsigned int first
= 0;
6432 int seen_first_offset
= 0;
6433 int locs_sorted
= 1;
6434 unsigned char *next
= start
, *vnext
= vstart
;
6435 unsigned int *array
= NULL
;
6436 const char *suffix
= strrchr (section
->name
, '.');
6437 bfd_boolean is_dwo
= FALSE
;
6438 int is_loclists
= strstr (section
->name
, "debug_loclists") != NULL
;
6439 dwarf_vma expected_start
= 0;
6441 if (suffix
&& strcmp (suffix
, ".dwo") == 0)
6444 bytes
= section
->size
;
6448 printf (_("\nThe %s section is empty.\n"), section
->name
);
6454 unsigned char *hdrptr
= section_begin
;
6455 dwarf_vma ll_length
;
6456 unsigned short ll_version
;
6457 unsigned char *end
= section_begin
+ section
->size
;
6458 unsigned char address_size
, segment_selector_size
;
6459 uint32_t offset_entry_count
;
6461 SAFE_BYTE_GET_AND_INC (ll_length
, hdrptr
, 4, end
);
6462 if (ll_length
== 0xffffffff)
6463 SAFE_BYTE_GET_AND_INC (ll_length
, hdrptr
, 8, end
);
6465 SAFE_BYTE_GET_AND_INC (ll_version
, hdrptr
, 2, end
);
6466 if (ll_version
!= 5)
6468 warn (_("The %s section contains corrupt or "
6469 "unsupported version number: %d.\n"),
6470 section
->name
, ll_version
);
6474 SAFE_BYTE_GET_AND_INC (address_size
, hdrptr
, 1, end
);
6476 SAFE_BYTE_GET_AND_INC (segment_selector_size
, hdrptr
, 1, end
);
6477 if (segment_selector_size
!= 0)
6479 warn (_("The %s section contains "
6480 "unsupported segment selector size: %d.\n"),
6481 section
->name
, segment_selector_size
);
6485 SAFE_BYTE_GET_AND_INC (offset_entry_count
, hdrptr
, 4, end
);
6486 if (offset_entry_count
!= 0)
6488 warn (_("The %s section contains "
6489 "unsupported offset entry count: %d.\n"),
6490 section
->name
, offset_entry_count
);
6494 expected_start
= hdrptr
- section_begin
;
6497 if (load_debug_info (file
) == 0)
6499 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
6504 /* Check the order of location list in .debug_info section. If
6505 offsets of location lists are in the ascending order, we can
6506 use `debug_information' directly. */
6507 for (i
= 0; i
< num_debug_info_entries
; i
++)
6511 num
= debug_information
[i
].num_loc_offsets
;
6512 if (num
> num_loc_list
)
6515 /* Check if we can use `debug_information' directly. */
6516 if (locs_sorted
&& num
!= 0)
6518 if (!seen_first_offset
)
6520 /* This is the first location list. */
6521 last_offset
= debug_information
[i
].loc_offsets
[0];
6522 last_view
= debug_information
[i
].loc_views
[0];
6524 seen_first_offset
= 1;
6530 for (; j
< num
; j
++)
6533 debug_information
[i
].loc_offsets
[j
]
6534 || (last_offset
== debug_information
[i
].loc_offsets
[j
]
6535 && last_view
> debug_information
[i
].loc_views
[j
]))
6540 last_offset
= debug_information
[i
].loc_offsets
[j
];
6541 last_view
= debug_information
[i
].loc_views
[j
];
6546 if (!seen_first_offset
)
6547 error (_("No location lists in .debug_info section!\n"));
6549 if (debug_information
[first
].num_loc_offsets
> 0
6550 && debug_information
[first
].loc_offsets
[0] != expected_start
6551 && debug_information
[first
].loc_views
[0] != expected_start
)
6552 warn (_("Location lists in %s section start at 0x%s\n"),
6554 dwarf_vmatoa ("x", debug_information
[first
].loc_offsets
[0]));
6557 array
= (unsigned int *) xcmalloc (num_loc_list
, sizeof (unsigned int));
6559 introduce (section
, FALSE
);
6561 if (reloc_at (section
, 0))
6562 printf (_(" Warning: This section has relocations - addresses seen here may not be accurate.\n\n"));
6564 printf (_(" Offset Begin End Expression\n"));
6566 seen_first_offset
= 0;
6567 for (i
= first
; i
< num_debug_info_entries
; i
++)
6569 dwarf_vma offset
, voffset
;
6570 dwarf_vma base_address
;
6576 for (k
= 0; k
< debug_information
[i
].num_loc_offsets
; k
++)
6578 loc_offsets
= debug_information
[i
].loc_offsets
;
6579 loc_views
= debug_information
[i
].loc_views
;
6580 qsort (array
, debug_information
[i
].num_loc_offsets
,
6581 sizeof (*array
), loc_offsets_compar
);
6584 int adjacent_view_loclists
= 1;
6585 for (k
= 0; k
< debug_information
[i
].num_loc_offsets
; k
++)
6587 j
= locs_sorted
? k
: array
[k
];
6589 && (debug_information
[i
].loc_offsets
[locs_sorted
6590 ? k
- 1 : array
[k
- 1]]
6591 == debug_information
[i
].loc_offsets
[j
])
6592 && (debug_information
[i
].loc_views
[locs_sorted
6593 ? k
- 1 : array
[k
- 1]]
6594 == debug_information
[i
].loc_views
[j
]))
6596 has_frame_base
= debug_information
[i
].have_frame_base
[j
];
6597 offset
= debug_information
[i
].loc_offsets
[j
];
6598 next
= section_begin
+ offset
;
6599 voffset
= debug_information
[i
].loc_views
[j
];
6601 vnext
= section_begin
+ voffset
;
6604 base_address
= debug_information
[i
].base_address
;
6606 if (vnext
&& vnext
< next
)
6609 display_view_pair_list (section
, &vstart
, i
, next
);
6614 if (!seen_first_offset
|| !adjacent_view_loclists
)
6615 seen_first_offset
= 1;
6619 warn (_("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n"),
6620 (unsigned long) (start
- section_begin
),
6621 (unsigned long) offset
);
6622 else if (start
> next
)
6623 warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n"),
6624 (unsigned long) (start
- section_begin
),
6625 (unsigned long) offset
);
6630 if (offset
>= bytes
)
6632 warn (_("Offset 0x%lx is bigger than .debug_loc section size.\n"),
6633 (unsigned long) offset
);
6637 if (vnext
&& voffset
>= bytes
)
6639 warn (_("View Offset 0x%lx is bigger than .debug_loc section size.\n"),
6640 (unsigned long) voffset
);
6647 display_loc_list_dwo (section
, &start
, i
, offset
,
6648 &vstart
, has_frame_base
);
6650 display_loc_list (section
, &start
, i
, offset
, base_address
,
6651 &vstart
, has_frame_base
);
6656 warn (_("DWO is not yet supported.\n"));
6658 display_loclists_list (section
, &start
, i
, offset
, base_address
,
6659 &vstart
, has_frame_base
);
6662 /* FIXME: this arrangement is quite simplistic. Nothing
6663 requires locview lists to be adjacent to corresponding
6664 loclists, and a single loclist could be augmented by
6665 different locview lists, and vice-versa, unlikely as it
6666 is that it would make sense to do so. Hopefully we'll
6667 have view pair support built into loclists before we ever
6668 need to address all these possibilities. */
6669 if (adjacent_view_loclists
&& vnext
6670 && vnext
!= start
&& vstart
!= next
)
6672 adjacent_view_loclists
= 0;
6673 warn (_("Hole and overlap detection requires adjacent view lists and loclists.\n"));
6676 if (vnext
&& vnext
== start
)
6677 display_view_pair_list (section
, &start
, i
, vstart
);
6681 if (start
< section
->start
+ section
->size
)
6682 warn (ngettext ("There is %ld unused byte at the end of section %s\n",
6683 "There are %ld unused bytes at the end of section %s\n",
6684 (long) (section
->start
+ section
->size
- start
)),
6685 (long) (section
->start
+ section
->size
- start
), section
->name
);
6692 display_debug_str (struct dwarf_section
*section
,
6693 void *file ATTRIBUTE_UNUSED
)
6695 unsigned char *start
= section
->start
;
6696 unsigned long bytes
= section
->size
;
6697 dwarf_vma addr
= section
->address
;
6701 printf (_("\nThe %s section is empty.\n"), section
->name
);
6705 introduce (section
, FALSE
);
6713 lbytes
= (bytes
> 16 ? 16 : bytes
);
6715 printf (" 0x%8.8lx ", (unsigned long) addr
);
6717 for (j
= 0; j
< 16; j
++)
6720 printf ("%2.2x", start
[j
]);
6728 for (j
= 0; j
< lbytes
; j
++)
6731 if (k
>= ' ' && k
< 0x80)
6750 display_debug_info (struct dwarf_section
*section
, void *file
)
6752 return process_debug_info (section
, file
, section
->abbrev_sec
, FALSE
, FALSE
);
6756 display_debug_types (struct dwarf_section
*section
, void *file
)
6758 return process_debug_info (section
, file
, section
->abbrev_sec
, FALSE
, TRUE
);
6762 display_trace_info (struct dwarf_section
*section
, void *file
)
6764 return process_debug_info (section
, file
, section
->abbrev_sec
, FALSE
, TRUE
);
6768 display_debug_aranges (struct dwarf_section
*section
,
6769 void *file ATTRIBUTE_UNUSED
)
6771 unsigned char *start
= section
->start
;
6772 unsigned char *end
= start
+ section
->size
;
6774 introduce (section
, FALSE
);
6776 /* It does not matter if this load fails,
6777 we test for that later on. */
6778 load_debug_info (file
);
6782 unsigned char *hdrptr
;
6783 DWARF2_Internal_ARange arange
;
6784 unsigned char *addr_ranges
;
6787 unsigned long sec_off
;
6788 unsigned char address_size
;
6790 unsigned int offset_size
;
6791 unsigned int initial_length_size
;
6795 SAFE_BYTE_GET_AND_INC (arange
.ar_length
, hdrptr
, 4, end
);
6796 if (arange
.ar_length
== 0xffffffff)
6798 SAFE_BYTE_GET_AND_INC (arange
.ar_length
, hdrptr
, 8, end
);
6800 initial_length_size
= 12;
6805 initial_length_size
= 4;
6808 sec_off
= hdrptr
- section
->start
;
6809 if (sec_off
+ arange
.ar_length
< sec_off
6810 || sec_off
+ arange
.ar_length
> section
->size
)
6812 warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"),
6814 sec_off
- initial_length_size
,
6815 dwarf_vmatoa ("x", arange
.ar_length
));
6819 SAFE_BYTE_GET_AND_INC (arange
.ar_version
, hdrptr
, 2, end
);
6820 SAFE_BYTE_GET_AND_INC (arange
.ar_info_offset
, hdrptr
, offset_size
, end
);
6822 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
6823 && num_debug_info_entries
> 0
6824 && find_debug_info_for_offset (arange
.ar_info_offset
) == NULL
)
6825 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
6826 (unsigned long) arange
.ar_info_offset
, section
->name
);
6828 SAFE_BYTE_GET_AND_INC (arange
.ar_pointer_size
, hdrptr
, 1, end
);
6829 SAFE_BYTE_GET_AND_INC (arange
.ar_segment_size
, hdrptr
, 1, end
);
6831 if (arange
.ar_version
!= 2 && arange
.ar_version
!= 3)
6833 /* PR 19872: A version number of 0 probably means that there is
6834 padding at the end of the .debug_aranges section. Gold puts
6835 it there when performing an incremental link, for example.
6836 So do not generate a warning in this case. */
6837 if (arange
.ar_version
)
6838 warn (_("Only DWARF 2 and 3 aranges are currently supported.\n"));
6842 printf (_(" Length: %ld\n"),
6843 (long) arange
.ar_length
);
6844 printf (_(" Version: %d\n"), arange
.ar_version
);
6845 printf (_(" Offset into .debug_info: 0x%lx\n"),
6846 (unsigned long) arange
.ar_info_offset
);
6847 printf (_(" Pointer Size: %d\n"), arange
.ar_pointer_size
);
6848 printf (_(" Segment Size: %d\n"), arange
.ar_segment_size
);
6850 address_size
= arange
.ar_pointer_size
+ arange
.ar_segment_size
;
6852 /* PR 17512: file: 001-108546-0.001:0.1. */
6853 if (address_size
== 0 || address_size
> 8)
6855 error (_("Invalid address size in %s section!\n"),
6860 /* The DWARF spec does not require that the address size be a power
6861 of two, but we do. This will have to change if we ever encounter
6862 an uneven architecture. */
6863 if ((address_size
& (address_size
- 1)) != 0)
6865 warn (_("Pointer size + Segment size is not a power of two.\n"));
6869 if (address_size
> 4)
6870 printf (_("\n Address Length\n"));
6872 printf (_("\n Address Length\n"));
6874 addr_ranges
= hdrptr
;
6876 /* Must pad to an alignment boundary that is twice the address size. */
6877 excess
= (hdrptr
- start
) % (2 * address_size
);
6879 addr_ranges
+= (2 * address_size
) - excess
;
6881 start
+= arange
.ar_length
+ initial_length_size
;
6883 while (addr_ranges
+ 2 * address_size
<= start
)
6885 SAFE_BYTE_GET_AND_INC (address
, addr_ranges
, address_size
, end
);
6886 SAFE_BYTE_GET_AND_INC (length
, addr_ranges
, address_size
, end
);
6889 print_dwarf_vma (address
, address_size
);
6890 print_dwarf_vma (length
, address_size
);
6900 /* Comparison function for qsort. */
6902 comp_addr_base (const void * v0
, const void * v1
)
6904 debug_info
*info0
= *(debug_info
**) v0
;
6905 debug_info
*info1
= *(debug_info
**) v1
;
6906 return info0
->addr_base
- info1
->addr_base
;
6909 /* Display the debug_addr section. */
6911 display_debug_addr (struct dwarf_section
*section
,
6914 debug_info
**debug_addr_info
;
6915 unsigned char *entry
;
6920 if (section
->size
== 0)
6922 printf (_("\nThe %s section is empty.\n"), section
->name
);
6926 if (load_debug_info (file
) == 0)
6928 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
6933 introduce (section
, FALSE
);
6935 /* PR 17531: file: cf38d01b.
6936 We use xcalloc because a corrupt file may not have initialised all of the
6937 fields in the debug_info structure, which means that the sort below might
6938 try to move uninitialised data. */
6939 debug_addr_info
= (debug_info
**) xcalloc ((num_debug_info_entries
+ 1),
6940 sizeof (debug_info
*));
6943 for (i
= 0; i
< num_debug_info_entries
; i
++)
6944 if (debug_information
[i
].addr_base
!= DEBUG_INFO_UNAVAILABLE
)
6946 /* PR 17531: file: cf38d01b. */
6947 if (debug_information
[i
].addr_base
>= section
->size
)
6948 warn (_("Corrupt address base (%lx) found in debug section %u\n"),
6949 (unsigned long) debug_information
[i
].addr_base
, i
);
6951 debug_addr_info
[count
++] = debug_information
+ i
;
6954 /* Add a sentinel to make iteration convenient. */
6955 debug_addr_info
[count
] = (debug_info
*) xmalloc (sizeof (debug_info
));
6956 debug_addr_info
[count
]->addr_base
= section
->size
;
6957 qsort (debug_addr_info
, count
, sizeof (debug_info
*), comp_addr_base
);
6959 for (i
= 0; i
< count
; i
++)
6962 unsigned int address_size
= debug_addr_info
[i
]->pointer_size
;
6964 printf (_(" For compilation unit at offset 0x%s:\n"),
6965 dwarf_vmatoa ("x", debug_addr_info
[i
]->cu_offset
));
6967 printf (_("\tIndex\tAddress\n"));
6968 entry
= section
->start
+ debug_addr_info
[i
]->addr_base
;
6969 end
= section
->start
+ debug_addr_info
[i
+ 1]->addr_base
;
6973 dwarf_vma base
= byte_get (entry
, address_size
);
6974 printf (_("\t%d:\t"), idx
);
6975 print_dwarf_vma (base
, address_size
);
6977 entry
+= address_size
;
6983 free (debug_addr_info
);
6987 /* Display the .debug_str_offsets and .debug_str_offsets.dwo sections. */
6990 display_debug_str_offsets (struct dwarf_section
*section
,
6991 void *file ATTRIBUTE_UNUSED
)
6993 if (section
->size
== 0)
6995 printf (_("\nThe %s section is empty.\n"), section
->name
);
6998 /* TODO: Dump the contents. This is made somewhat difficult by not knowing
6999 what the offset size is for this section. */
7003 /* Each debug_information[x].range_lists[y] gets this representation for
7004 sorting purposes. */
7008 /* The debug_information[x].range_lists[y] value. */
7009 dwarf_vma ranges_offset
;
7011 /* Original debug_information to find parameters of the data. */
7012 debug_info
*debug_info_p
;
7015 /* Sort struct range_entry in ascending order of its RANGES_OFFSET. */
7018 range_entry_compar (const void *ap
, const void *bp
)
7020 const struct range_entry
*a_re
= (const struct range_entry
*) ap
;
7021 const struct range_entry
*b_re
= (const struct range_entry
*) bp
;
7022 const dwarf_vma a
= a_re
->ranges_offset
;
7023 const dwarf_vma b
= b_re
->ranges_offset
;
7025 return (a
> b
) - (b
> a
);
7029 display_debug_ranges_list (unsigned char *start
, unsigned char *finish
,
7030 unsigned int pointer_size
, unsigned long offset
,
7031 unsigned long base_address
)
7033 while (start
< finish
)
7038 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
7039 if (start
>= finish
)
7041 SAFE_SIGNED_BYTE_GET_AND_INC (end
, start
, pointer_size
, finish
);
7044 printf (" %8.8lx ", offset
);
7046 if (begin
== 0 && end
== 0)
7048 printf (_("<End of list>\n"));
7052 /* Check base address specifiers. */
7053 if (is_max_address (begin
, pointer_size
)
7054 && !is_max_address (end
, pointer_size
))
7057 print_dwarf_vma (begin
, pointer_size
);
7058 print_dwarf_vma (end
, pointer_size
);
7059 printf ("(base address)\n");
7063 print_dwarf_vma (begin
+ base_address
, pointer_size
);
7064 print_dwarf_vma (end
+ base_address
, pointer_size
);
7067 fputs (_("(start == end)"), stdout
);
7068 else if (begin
> end
)
7069 fputs (_("(start > end)"), stdout
);
7076 display_debug_rnglists_list (unsigned char *start
, unsigned char *finish
,
7077 unsigned int pointer_size
, unsigned long offset
,
7078 unsigned long base_address
)
7080 unsigned char *next
= start
;
7084 unsigned long off
= offset
+ (start
- next
);
7085 enum dwarf_range_list_entry rlet
;
7086 /* Initialize it due to a false compiler warning. */
7087 dwarf_vma begin
= -1, length
, end
= -1;
7088 unsigned int bytes_read
;
7090 if (start
+ 1 > finish
)
7092 warn (_("Range list starting at offset 0x%lx is not terminated.\n"),
7097 printf (" %8.8lx ", off
);
7099 SAFE_BYTE_GET_AND_INC (rlet
, start
, 1, finish
);
7103 case DW_RLE_end_of_list
:
7104 printf (_("<End of list>\n"));
7106 case DW_RLE_base_address
:
7107 SAFE_BYTE_GET_AND_INC (base_address
, start
, pointer_size
, finish
);
7108 print_dwarf_vma (base_address
, pointer_size
);
7109 printf (_("(base address)\n"));
7111 case DW_RLE_start_length
:
7112 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
7113 length
= read_uleb128 (start
, &bytes_read
, finish
);
7114 start
+= bytes_read
;
7115 end
= begin
+ length
;
7117 case DW_RLE_offset_pair
:
7118 begin
= read_uleb128 (start
, &bytes_read
, finish
);
7119 start
+= bytes_read
;
7120 end
= read_uleb128 (start
, &bytes_read
, finish
);
7121 start
+= bytes_read
;
7123 case DW_RLE_start_end
:
7124 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
7125 SAFE_BYTE_GET_AND_INC (end
, start
, pointer_size
, finish
);
7128 error (_("Invalid range list entry type %d\n"), rlet
);
7129 rlet
= DW_RLE_end_of_list
;
7132 if (rlet
== DW_RLE_end_of_list
)
7134 if (rlet
== DW_RLE_base_address
)
7137 print_dwarf_vma (begin
+ base_address
, pointer_size
);
7138 print_dwarf_vma (end
+ base_address
, pointer_size
);
7141 fputs (_("(start == end)"), stdout
);
7142 else if (begin
> end
)
7143 fputs (_("(start > end)"), stdout
);
7150 display_debug_ranges (struct dwarf_section
*section
,
7151 void *file ATTRIBUTE_UNUSED
)
7153 unsigned char *start
= section
->start
;
7154 unsigned char *last_start
= start
;
7155 unsigned long bytes
= section
->size
;
7156 unsigned char *section_begin
= start
;
7157 unsigned char *finish
= start
+ bytes
;
7158 unsigned int num_range_list
, i
;
7159 struct range_entry
*range_entries
, *range_entry_fill
;
7160 int is_rnglists
= strstr (section
->name
, "debug_rnglists") != NULL
;
7161 /* Initialize it due to a false compiler warning. */
7162 unsigned char address_size
= 0;
7166 printf (_("\nThe %s section is empty.\n"), section
->name
);
7172 dwarf_vma initial_length
;
7173 unsigned int initial_length_size
;
7174 unsigned char segment_selector_size
;
7175 unsigned int offset_size
, offset_entry_count
;
7176 unsigned short version
;
7178 /* Get and check the length of the block. */
7179 SAFE_BYTE_GET_AND_INC (initial_length
, start
, 4, finish
);
7181 if (initial_length
== 0xffffffff)
7183 /* This section is 64-bit DWARF 3. */
7184 SAFE_BYTE_GET_AND_INC (initial_length
, start
, 8, finish
);
7186 initial_length_size
= 12;
7191 initial_length_size
= 4;
7194 if (initial_length
+ initial_length_size
> section
->size
)
7196 /* If the length field has a relocation against it, then we should
7197 not complain if it is inaccurate (and probably negative).
7198 It is copied from .debug_line handling code. */
7199 if (reloc_at (section
, (start
- section
->start
) - offset_size
))
7201 initial_length
= (finish
- start
) - initial_length_size
;
7205 warn (_("The length field (0x%lx) in the debug_rnglists header is wrong - the section is too small\n"),
7206 (long) initial_length
);
7211 /* Get and check the version number. */
7212 SAFE_BYTE_GET_AND_INC (version
, start
, 2, finish
);
7216 warn (_("Only DWARF version 5 debug_rnglists info "
7217 "is currently supported.\n"));
7221 SAFE_BYTE_GET_AND_INC (address_size
, start
, 1, finish
);
7223 SAFE_BYTE_GET_AND_INC (segment_selector_size
, start
, 1, finish
);
7224 if (segment_selector_size
!= 0)
7226 warn (_("The %s section contains "
7227 "unsupported segment selector size: %d.\n"),
7228 section
->name
, segment_selector_size
);
7232 SAFE_BYTE_GET_AND_INC (offset_entry_count
, start
, 4, finish
);
7233 if (offset_entry_count
!= 0)
7235 warn (_("The %s section contains "
7236 "unsupported offset entry count: %u.\n"),
7237 section
->name
, offset_entry_count
);
7242 if (load_debug_info (file
) == 0)
7244 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
7250 for (i
= 0; i
< num_debug_info_entries
; i
++)
7251 num_range_list
+= debug_information
[i
].num_range_lists
;
7253 if (num_range_list
== 0)
7255 /* This can happen when the file was compiled with -gsplit-debug
7256 which removes references to range lists from the primary .o file. */
7257 printf (_("No range lists in .debug_info section.\n"));
7261 range_entries
= (struct range_entry
*)
7262 xmalloc (sizeof (*range_entries
) * num_range_list
);
7263 range_entry_fill
= range_entries
;
7265 for (i
= 0; i
< num_debug_info_entries
; i
++)
7267 debug_info
*debug_info_p
= &debug_information
[i
];
7270 for (j
= 0; j
< debug_info_p
->num_range_lists
; j
++)
7272 range_entry_fill
->ranges_offset
= debug_info_p
->range_lists
[j
];
7273 range_entry_fill
->debug_info_p
= debug_info_p
;
7278 qsort (range_entries
, num_range_list
, sizeof (*range_entries
),
7279 range_entry_compar
);
7281 if (dwarf_check
!= 0 && range_entries
[0].ranges_offset
!= 0)
7282 warn (_("Range lists in %s section start at 0x%lx\n"),
7283 section
->name
, (unsigned long) range_entries
[0].ranges_offset
);
7285 introduce (section
, FALSE
);
7287 printf (_(" Offset Begin End\n"));
7289 for (i
= 0; i
< num_range_list
; i
++)
7291 struct range_entry
*range_entry
= &range_entries
[i
];
7292 debug_info
*debug_info_p
= range_entry
->debug_info_p
;
7293 unsigned int pointer_size
;
7295 unsigned char *next
;
7296 dwarf_vma base_address
;
7298 pointer_size
= (is_rnglists
? address_size
: debug_info_p
->pointer_size
);
7299 offset
= range_entry
->ranges_offset
;
7300 next
= section_begin
+ offset
;
7301 base_address
= debug_info_p
->base_address
;
7303 /* PR 17512: file: 001-101485-0.001:0.1. */
7304 if (pointer_size
< 2 || pointer_size
> 8)
7306 warn (_("Corrupt pointer size (%d) in debug entry at offset %8.8lx\n"),
7307 pointer_size
, (unsigned long) offset
);
7311 if (next
< section_begin
|| next
>= finish
)
7313 warn (_("Corrupt offset (%#8.8lx) in range entry %u\n"),
7314 (unsigned long) offset
, i
);
7318 if (dwarf_check
!= 0 && i
> 0)
7321 warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"),
7322 (unsigned long) (start
- section_begin
),
7323 (unsigned long) (next
- section_begin
), section
->name
);
7324 else if (start
> next
)
7326 if (next
== last_start
)
7328 warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"),
7329 (unsigned long) (start
- section_begin
),
7330 (unsigned long) (next
- section_begin
), section
->name
);
7337 (is_rnglists
? display_debug_rnglists_list
: display_debug_ranges_list
)
7338 (start
, finish
, pointer_size
, offset
, base_address
);
7342 free (range_entries
);
7347 typedef struct Frame_Chunk
7349 struct Frame_Chunk
*next
;
7350 unsigned char *chunk_start
;
7352 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
7353 short int *col_type
;
7356 unsigned int code_factor
;
7360 unsigned int cfa_reg
;
7361 dwarf_vma cfa_offset
;
7363 unsigned char fde_encoding
;
7364 unsigned char cfa_exp
;
7365 unsigned char ptr_size
;
7366 unsigned char segment_size
;
7370 static const char *const *dwarf_regnames
;
7371 static unsigned int dwarf_regnames_count
;
7373 /* A marker for a col_type that means this column was never referenced
7374 in the frame info. */
7375 #define DW_CFA_unreferenced (-1)
7377 /* Return 0 if no more space is needed, 1 if more space is needed,
7378 -1 for invalid reg. */
7381 frame_need_space (Frame_Chunk
*fc
, unsigned int reg
)
7383 unsigned int prev
= fc
->ncols
;
7385 if (reg
< (unsigned int) fc
->ncols
)
7388 if (dwarf_regnames_count
7389 && reg
> dwarf_regnames_count
)
7392 fc
->ncols
= reg
+ 1;
7393 /* PR 17512: file: 10450-2643-0.004.
7394 If reg == -1 then this can happen... */
7398 /* PR 17512: file: 2844a11d. */
7399 if (fc
->ncols
> 1024)
7401 error (_("Unfeasibly large register number: %u\n"), reg
);
7403 /* FIXME: 1024 is an arbitrary limit. Increase it if
7404 we ever encounter a valid binary that exceeds it. */
7408 fc
->col_type
= (short int *) xcrealloc (fc
->col_type
, fc
->ncols
,
7409 sizeof (short int));
7410 fc
->col_offset
= (int *) xcrealloc (fc
->col_offset
, fc
->ncols
, sizeof (int));
7411 /* PR 17512: file:002-10025-0.005. */
7412 if (fc
->col_type
== NULL
|| fc
->col_offset
== NULL
)
7414 error (_("Out of memory allocating %u columns in dwarf frame arrays\n"),
7420 while (prev
< fc
->ncols
)
7422 fc
->col_type
[prev
] = DW_CFA_unreferenced
;
7423 fc
->col_offset
[prev
] = 0;
7429 static const char *const dwarf_regnames_i386
[] =
7431 "eax", "ecx", "edx", "ebx", /* 0 - 3 */
7432 "esp", "ebp", "esi", "edi", /* 4 - 7 */
7433 "eip", "eflags", NULL
, /* 8 - 10 */
7434 "st0", "st1", "st2", "st3", /* 11 - 14 */
7435 "st4", "st5", "st6", "st7", /* 15 - 18 */
7436 NULL
, NULL
, /* 19 - 20 */
7437 "xmm0", "xmm1", "xmm2", "xmm3", /* 21 - 24 */
7438 "xmm4", "xmm5", "xmm6", "xmm7", /* 25 - 28 */
7439 "mm0", "mm1", "mm2", "mm3", /* 29 - 32 */
7440 "mm4", "mm5", "mm6", "mm7", /* 33 - 36 */
7441 "fcw", "fsw", "mxcsr", /* 37 - 39 */
7442 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
, /* 40 - 47 */
7443 "tr", "ldtr", /* 48 - 49 */
7444 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 50 - 57 */
7445 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 58 - 65 */
7446 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 66 - 73 */
7447 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 74 - 81 */
7448 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 82 - 89 */
7449 NULL
, NULL
, NULL
, /* 90 - 92 */
7450 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7" /* 93 - 100 */
7453 static const char *const dwarf_regnames_iamcu
[] =
7455 "eax", "ecx", "edx", "ebx", /* 0 - 3 */
7456 "esp", "ebp", "esi", "edi", /* 4 - 7 */
7457 "eip", "eflags", NULL
, /* 8 - 10 */
7458 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 11 - 18 */
7459 NULL
, NULL
, /* 19 - 20 */
7460 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 21 - 28 */
7461 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 29 - 36 */
7462 NULL
, NULL
, NULL
, /* 37 - 39 */
7463 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
, /* 40 - 47 */
7464 "tr", "ldtr", /* 48 - 49 */
7465 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 50 - 57 */
7466 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 58 - 65 */
7467 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 66 - 73 */
7468 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 74 - 81 */
7469 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 82 - 89 */
7470 NULL
, NULL
, NULL
, /* 90 - 92 */
7471 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
/* 93 - 100 */
7475 init_dwarf_regnames_i386 (void)
7477 dwarf_regnames
= dwarf_regnames_i386
;
7478 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_i386
);
7482 init_dwarf_regnames_iamcu (void)
7484 dwarf_regnames
= dwarf_regnames_iamcu
;
7485 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_iamcu
);
7488 static const char *const dwarf_regnames_x86_64
[] =
7490 "rax", "rdx", "rcx", "rbx",
7491 "rsi", "rdi", "rbp", "rsp",
7492 "r8", "r9", "r10", "r11",
7493 "r12", "r13", "r14", "r15",
7495 "xmm0", "xmm1", "xmm2", "xmm3",
7496 "xmm4", "xmm5", "xmm6", "xmm7",
7497 "xmm8", "xmm9", "xmm10", "xmm11",
7498 "xmm12", "xmm13", "xmm14", "xmm15",
7499 "st0", "st1", "st2", "st3",
7500 "st4", "st5", "st6", "st7",
7501 "mm0", "mm1", "mm2", "mm3",
7502 "mm4", "mm5", "mm6", "mm7",
7504 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
,
7505 "fs.base", "gs.base", NULL
, NULL
,
7507 "mxcsr", "fcw", "fsw",
7508 "xmm16", "xmm17", "xmm18", "xmm19",
7509 "xmm20", "xmm21", "xmm22", "xmm23",
7510 "xmm24", "xmm25", "xmm26", "xmm27",
7511 "xmm28", "xmm29", "xmm30", "xmm31",
7512 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 83 - 90 */
7513 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 91 - 98 */
7514 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 99 - 106 */
7515 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 107 - 114 */
7516 NULL
, NULL
, NULL
, /* 115 - 117 */
7517 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7"
7521 init_dwarf_regnames_x86_64 (void)
7523 dwarf_regnames
= dwarf_regnames_x86_64
;
7524 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_x86_64
);
7527 static const char *const dwarf_regnames_aarch64
[] =
7529 "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7",
7530 "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15",
7531 "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23",
7532 "x24", "x25", "x26", "x27", "x28", "x29", "x30", "sp",
7533 NULL
, "elr", NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
7534 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, "vg", "ffr",
7535 "p0", "p1", "p2", "p3", "p4", "p5", "p6", "p7",
7536 "p8", "p9", "p10", "p11", "p12", "p13", "p14", "p15",
7537 "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7",
7538 "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15",
7539 "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23",
7540 "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31",
7541 "z0", "z1", "z2", "z3", "z4", "z5", "z6", "z7",
7542 "z8", "z9", "z10", "z11", "z12", "z13", "z14", "z15",
7543 "z16", "z17", "z18", "z19", "z20", "z21", "z22", "z23",
7544 "z24", "z25", "z26", "z27", "z28", "z29", "z30", "z31",
7548 init_dwarf_regnames_aarch64 (void)
7550 dwarf_regnames
= dwarf_regnames_aarch64
;
7551 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_aarch64
);
7554 static const char *const dwarf_regnames_s390
[] =
7556 /* Avoid saying "r5 (r5)", so omit the names of r0-r15. */
7557 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
7558 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
7559 "f0", "f2", "f4", "f6", "f1", "f3", "f5", "f7",
7560 "f8", "f10", "f12", "f14", "f9", "f11", "f13", "f15",
7561 "cr0", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7",
7562 "cr8", "cr9", "cr10", "cr11", "cr12", "cr13", "cr14", "cr15",
7563 "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7",
7564 "a8", "a9", "a10", "a11", "a12", "a13", "a14", "a15",
7567 "v16", "v18", "v20", "v22", "v17", "v19", "v21", "v23",
7568 "v24", "v26", "v28", "v30", "v25", "v27", "v29", "v31",
7572 init_dwarf_regnames_s390 (void)
7574 dwarf_regnames
= dwarf_regnames_s390
;
7575 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_s390
);
7578 static const char *const dwarf_regnames_riscv
[] =
7580 "zero", "ra", "sp", "gp", "tp", "t0", "t1", "t2", /* 0 - 7 */
7581 "s0", "s1", "a0", "a1", "a2", "a3", "a4", "a5", /* 8 - 15 */
7582 "a6", "a7", "s2", "s3", "s4", "s5", "s6", "s7", /* 16 - 23 */
7583 "s8", "s9", "s10", "s11", "t3", "t4", "t5", "t6", /* 24 - 31 */
7584 "ft0", "ft1", "ft2", "ft3", "ft4", "ft5", "ft6", "ft7", /* 32 - 39 */
7585 "fs0", "fs1", /* 40 - 41 */
7586 "fa0", "fa1", "fa2", "fa3", "fa4", "fa5", "fa6", "fa7", /* 42 - 49 */
7587 "fs2", "fs3", "fs4", "fs5", "fs6", "fs7", "fs8", "fs9", /* 50 - 57 */
7588 "fs10", "fs11", /* 58 - 59 */
7589 "ft8", "ft9", "ft10", "ft11" /* 60 - 63 */
7593 init_dwarf_regnames_riscv (void)
7595 dwarf_regnames
= dwarf_regnames_riscv
;
7596 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_riscv
);
7600 init_dwarf_regnames (unsigned int e_machine
)
7605 init_dwarf_regnames_i386 ();
7609 init_dwarf_regnames_iamcu ();
7615 init_dwarf_regnames_x86_64 ();
7619 init_dwarf_regnames_aarch64 ();
7623 init_dwarf_regnames_s390 ();
7627 init_dwarf_regnames_riscv ();
7636 regname (unsigned int regno
, int row
)
7638 static char reg
[64];
7641 && regno
< dwarf_regnames_count
7642 && dwarf_regnames
[regno
] != NULL
)
7645 return dwarf_regnames
[regno
];
7646 snprintf (reg
, sizeof (reg
), "r%d (%s)", regno
,
7647 dwarf_regnames
[regno
]);
7650 snprintf (reg
, sizeof (reg
), "r%d", regno
);
7655 frame_display_row (Frame_Chunk
*fc
, int *need_col_headers
, unsigned int *max_regs
)
7660 if (*max_regs
!= fc
->ncols
)
7661 *max_regs
= fc
->ncols
;
7663 if (*need_col_headers
)
7665 static const char *sloc
= " LOC";
7667 *need_col_headers
= 0;
7669 printf ("%-*s CFA ", eh_addr_size
* 2, sloc
);
7671 for (r
= 0; r
< *max_regs
; r
++)
7672 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
7677 printf ("%-5s ", regname (r
, 1));
7683 print_dwarf_vma (fc
->pc_begin
, eh_addr_size
);
7685 strcpy (tmp
, "exp");
7687 sprintf (tmp
, "%s%+d", regname (fc
->cfa_reg
, 1), (int) fc
->cfa_offset
);
7688 printf ("%-8s ", tmp
);
7690 for (r
= 0; r
< fc
->ncols
; r
++)
7692 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
7694 switch (fc
->col_type
[r
])
7696 case DW_CFA_undefined
:
7699 case DW_CFA_same_value
:
7703 sprintf (tmp
, "c%+d", fc
->col_offset
[r
]);
7705 case DW_CFA_val_offset
:
7706 sprintf (tmp
, "v%+d", fc
->col_offset
[r
]);
7708 case DW_CFA_register
:
7709 sprintf (tmp
, "%s", regname (fc
->col_offset
[r
], 0));
7711 case DW_CFA_expression
:
7712 strcpy (tmp
, "exp");
7714 case DW_CFA_val_expression
:
7715 strcpy (tmp
, "vexp");
7718 strcpy (tmp
, "n/a");
7721 printf ("%-5s ", tmp
);
7727 #define GET(VAR, N) SAFE_BYTE_GET_AND_INC (VAR, start, N, end)
7729 static unsigned char *
7730 read_cie (unsigned char *start
, unsigned char *end
,
7731 Frame_Chunk
**p_cie
, int *p_version
,
7732 bfd_size_type
*p_aug_len
, unsigned char **p_aug
)
7736 unsigned int length_return
;
7737 unsigned char *augmentation_data
= NULL
;
7738 bfd_size_type augmentation_data_len
= 0;
7741 /* PR 17512: file: 001-228113-0.004. */
7745 fc
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
7746 memset (fc
, 0, sizeof (Frame_Chunk
));
7748 fc
->col_type
= (short int *) xmalloc (sizeof (short int));
7749 fc
->col_offset
= (int *) xmalloc (sizeof (int));
7753 fc
->augmentation
= (char *) start
;
7754 /* PR 17512: file: 001-228113-0.004.
7755 Skip past augmentation name, but avoid running off the end of the data. */
7757 if (* start
++ == '\0')
7761 warn (_("No terminator for augmentation name\n"));
7765 if (strcmp (fc
->augmentation
, "eh") == 0)
7766 start
+= eh_addr_size
;
7770 GET (fc
->ptr_size
, 1);
7771 if (fc
->ptr_size
< 1 || fc
->ptr_size
> 8)
7773 warn (_("Invalid pointer size (%d) in CIE data\n"), fc
->ptr_size
);
7777 GET (fc
->segment_size
, 1);
7778 /* PR 17512: file: e99d2804. */
7779 if (fc
->segment_size
> 8 || fc
->segment_size
+ fc
->ptr_size
> 8)
7781 warn (_("Invalid segment size (%d) in CIE data\n"), fc
->segment_size
);
7785 eh_addr_size
= fc
->ptr_size
;
7789 fc
->ptr_size
= eh_addr_size
;
7790 fc
->segment_size
= 0;
7793 READ_ULEB (fc
->code_factor
);
7794 READ_SLEB (fc
->data_factor
);
7805 if (fc
->augmentation
[0] == 'z')
7807 READ_ULEB (augmentation_data_len
);
7808 augmentation_data
= start
;
7809 /* PR 17512: file: 11042-2589-0.004. */
7810 if (augmentation_data_len
> (bfd_size_type
) (end
- start
))
7812 warn (_("Augmentation data too long: 0x%s, expected at most %#lx\n"),
7813 dwarf_vmatoa ("x", augmentation_data_len
),
7814 (unsigned long) (end
- start
));
7817 start
+= augmentation_data_len
;
7820 if (augmentation_data_len
)
7824 unsigned char *qend
;
7826 p
= (unsigned char *) fc
->augmentation
+ 1;
7827 q
= augmentation_data
;
7828 qend
= q
+ augmentation_data_len
;
7830 while (p
< end
&& q
< qend
)
7835 q
+= 1 + size_of_encoded_value (*q
);
7837 fc
->fde_encoding
= *q
++;
7846 /* Note - it is OK if this loop terminates with q < qend.
7847 Padding may have been inserted to align the end of the CIE. */
7852 *p_version
= version
;
7855 *p_aug_len
= augmentation_data_len
;
7856 *p_aug
= augmentation_data
;
7861 free (fc
->col_offset
);
7862 free (fc
->col_type
);
7867 /* Prints out the contents on the DATA array formatted as unsigned bytes.
7868 If do_wide is not enabled, then formats the output to fit into 80 columns.
7869 PRINTED contains the number of characters already written to the current
7873 display_data (bfd_size_type printed
,
7874 const unsigned char * data
,
7875 const bfd_size_type len
)
7877 if (do_wide
|| len
< ((80 - printed
) / 3))
7878 for (printed
= 0; printed
< len
; ++printed
)
7879 printf (" %02x", data
[printed
]);
7882 for (printed
= 0; printed
< len
; ++printed
)
7884 if (printed
% (80 / 3) == 0)
7886 printf (" %02x", data
[printed
]);
7891 /* Prints out the contents on the augmentation data array.
7892 If do_wide is not enabled, then formats the output to fit into 80 columns. */
7895 display_augmentation_data (const unsigned char * data
, const bfd_size_type len
)
7899 i
= printf (_(" Augmentation data: "));
7900 display_data (i
, data
, len
);
7904 display_debug_frames (struct dwarf_section
*section
,
7905 void *file ATTRIBUTE_UNUSED
)
7907 unsigned char *start
= section
->start
;
7908 unsigned char *end
= start
+ section
->size
;
7909 unsigned char *section_start
= start
;
7910 Frame_Chunk
*chunks
= NULL
, *forward_refs
= NULL
;
7911 Frame_Chunk
*remembered_state
= NULL
;
7913 bfd_boolean is_eh
= strcmp (section
->name
, ".eh_frame") == 0;
7914 unsigned int length_return
;
7915 unsigned int max_regs
= 0;
7916 const char *bad_reg
= _("bad register: ");
7917 unsigned int saved_eh_addr_size
= eh_addr_size
;
7919 introduce (section
, FALSE
);
7923 unsigned char *saved_start
;
7924 unsigned char *block_end
;
7929 int need_col_headers
= 1;
7930 unsigned char *augmentation_data
= NULL
;
7931 bfd_size_type augmentation_data_len
= 0;
7932 unsigned int encoded_ptr_size
= saved_eh_addr_size
;
7933 unsigned int offset_size
;
7934 unsigned int initial_length_size
;
7935 bfd_boolean all_nops
;
7937 saved_start
= start
;
7939 SAFE_BYTE_GET_AND_INC (length
, start
, 4, end
);
7943 printf ("\n%08lx ZERO terminator\n\n",
7944 (unsigned long)(saved_start
- section_start
));
7945 /* Skip any zero terminators that directly follow.
7946 A corrupt section size could have loaded a whole
7947 slew of zero filled memory bytes. eg
7948 PR 17512: file: 070-19381-0.004. */
7949 while (start
< end
&& * start
== 0)
7954 if (length
== 0xffffffff)
7956 SAFE_BYTE_GET_AND_INC (length
, start
, 8, end
);
7958 initial_length_size
= 12;
7963 initial_length_size
= 4;
7966 block_end
= saved_start
+ length
+ initial_length_size
;
7967 if (block_end
> end
|| block_end
< start
)
7969 warn ("Invalid length 0x%s in FDE at %#08lx\n",
7970 dwarf_vmatoa_1 (NULL
, length
, offset_size
),
7971 (unsigned long) (saved_start
- section_start
));
7975 SAFE_BYTE_GET_AND_INC (cie_id
, start
, offset_size
, end
);
7977 if (is_eh
? (cie_id
== 0) : ((offset_size
== 4 && cie_id
== DW_CIE_ID
)
7978 || (offset_size
== 8 && cie_id
== DW64_CIE_ID
)))
7983 start
= read_cie (start
, end
, &cie
, &version
,
7984 &augmentation_data_len
, &augmentation_data
);
7985 /* PR 17512: file: 027-135133-0.005. */
7992 fc
->chunk_start
= saved_start
;
7993 mreg
= max_regs
> 0 ? max_regs
- 1 : 0;
7996 if (frame_need_space (fc
, mreg
) < 0)
7998 if (fc
->fde_encoding
)
7999 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
8001 printf ("\n%08lx ", (unsigned long) (saved_start
- section_start
));
8002 print_dwarf_vma (length
, fc
->ptr_size
);
8003 print_dwarf_vma (cie_id
, offset_size
);
8005 if (do_debug_frames_interp
)
8007 printf ("CIE \"%s\" cf=%d df=%d ra=%d\n", fc
->augmentation
,
8008 fc
->code_factor
, fc
->data_factor
, fc
->ra
);
8013 printf (" Version: %d\n", version
);
8014 printf (" Augmentation: \"%s\"\n", fc
->augmentation
);
8017 printf (" Pointer Size: %u\n", fc
->ptr_size
);
8018 printf (" Segment Size: %u\n", fc
->segment_size
);
8020 printf (" Code alignment factor: %u\n", fc
->code_factor
);
8021 printf (" Data alignment factor: %d\n", fc
->data_factor
);
8022 printf (" Return address column: %d\n", fc
->ra
);
8024 if (augmentation_data_len
)
8025 display_augmentation_data (augmentation_data
, augmentation_data_len
);
8032 unsigned char *look_for
;
8033 static Frame_Chunk fde_fc
;
8034 unsigned long segment_selector
;
8038 dwarf_vma sign
= (dwarf_vma
) 1 << (offset_size
* 8 - 1);
8039 look_for
= start
- 4 - ((cie_id
^ sign
) - sign
);
8042 look_for
= section_start
+ cie_id
;
8044 if (look_for
<= saved_start
)
8046 for (cie
= chunks
; cie
; cie
= cie
->next
)
8047 if (cie
->chunk_start
== look_for
)
8052 for (cie
= forward_refs
; cie
; cie
= cie
->next
)
8053 if (cie
->chunk_start
== look_for
)
8057 unsigned int off_size
;
8058 unsigned char *cie_scan
;
8060 cie_scan
= look_for
;
8062 SAFE_BYTE_GET_AND_INC (length
, cie_scan
, 4, end
);
8063 if (length
== 0xffffffff)
8065 SAFE_BYTE_GET_AND_INC (length
, cie_scan
, 8, end
);
8072 SAFE_BYTE_GET_AND_INC (c_id
, cie_scan
, off_size
, end
);
8075 : ((off_size
== 4 && c_id
== DW_CIE_ID
)
8076 || (off_size
== 8 && c_id
== DW64_CIE_ID
)))
8081 read_cie (cie_scan
, end
, &cie
, &version
,
8082 &augmentation_data_len
, &augmentation_data
);
8083 /* PR 17512: file: 3450-2098-0.004. */
8086 warn (_("Failed to read CIE information\n"));
8089 cie
->next
= forward_refs
;
8091 cie
->chunk_start
= look_for
;
8092 mreg
= max_regs
> 0 ? max_regs
- 1 : 0;
8095 if (frame_need_space (cie
, mreg
) < 0)
8097 warn (_("Invalid max register\n"));
8100 if (cie
->fde_encoding
)
8102 = size_of_encoded_value (cie
->fde_encoding
);
8109 memset (fc
, 0, sizeof (Frame_Chunk
));
8113 warn ("Invalid CIE pointer 0x%s in FDE at %#08lx\n",
8114 dwarf_vmatoa_1 (NULL
, cie_id
, offset_size
),
8115 (unsigned long) (saved_start
- section_start
));
8117 fc
->col_type
= (short int *) xmalloc (sizeof (short int));
8118 fc
->col_offset
= (int *) xmalloc (sizeof (int));
8119 if (frame_need_space (fc
, max_regs
> 0 ? max_regs
- 1 : 0) < 0)
8121 warn (_("Invalid max register\n"));
8125 fc
->augmentation
= "";
8126 fc
->fde_encoding
= 0;
8127 fc
->ptr_size
= eh_addr_size
;
8128 fc
->segment_size
= 0;
8132 fc
->ncols
= cie
->ncols
;
8133 fc
->col_type
= (short int *) xcmalloc (fc
->ncols
, sizeof (short int));
8134 fc
->col_offset
= (int *) xcmalloc (fc
->ncols
, sizeof (int));
8135 memcpy (fc
->col_type
, cie
->col_type
, fc
->ncols
* sizeof (short int));
8136 memcpy (fc
->col_offset
, cie
->col_offset
, fc
->ncols
* sizeof (int));
8137 fc
->augmentation
= cie
->augmentation
;
8138 fc
->ptr_size
= cie
->ptr_size
;
8139 eh_addr_size
= cie
->ptr_size
;
8140 fc
->segment_size
= cie
->segment_size
;
8141 fc
->code_factor
= cie
->code_factor
;
8142 fc
->data_factor
= cie
->data_factor
;
8143 fc
->cfa_reg
= cie
->cfa_reg
;
8144 fc
->cfa_offset
= cie
->cfa_offset
;
8146 if (frame_need_space (fc
, max_regs
> 0 ? max_regs
- 1: 0) < 0)
8148 warn (_("Invalid max register\n"));
8151 fc
->fde_encoding
= cie
->fde_encoding
;
8154 if (fc
->fde_encoding
)
8155 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
8157 segment_selector
= 0;
8158 if (fc
->segment_size
)
8160 if (fc
->segment_size
> sizeof (segment_selector
))
8162 /* PR 17512: file: 9e196b3e. */
8163 warn (_("Probably corrupt segment size: %d - using 4 instead\n"), fc
->segment_size
);
8164 fc
->segment_size
= 4;
8166 SAFE_BYTE_GET_AND_INC (segment_selector
, start
, fc
->segment_size
, end
);
8169 fc
->pc_begin
= get_encoded_value (&start
, fc
->fde_encoding
, section
, end
);
8171 /* FIXME: It appears that sometimes the final pc_range value is
8172 encoded in less than encoded_ptr_size bytes. See the x86_64
8173 run of the "objcopy on compressed debug sections" test for an
8175 SAFE_BYTE_GET_AND_INC (fc
->pc_range
, start
, encoded_ptr_size
, end
);
8177 if (cie
->augmentation
[0] == 'z')
8179 READ_ULEB (augmentation_data_len
);
8180 augmentation_data
= start
;
8181 /* PR 17512 file: 722-8446-0.004 and PR 22386. */
8182 if (augmentation_data_len
> (bfd_size_type
) (end
- start
))
8184 warn (_("Augmentation data too long: 0x%s, "
8185 "expected at most %#lx\n"),
8186 dwarf_vmatoa ("x", augmentation_data_len
),
8187 (unsigned long) (end
- start
));
8189 augmentation_data
= NULL
;
8190 augmentation_data_len
= 0;
8192 start
+= augmentation_data_len
;
8195 printf ("\n%08lx %s %s FDE cie=%08lx pc=",
8196 (unsigned long)(saved_start
- section_start
),
8197 dwarf_vmatoa_1 (NULL
, length
, fc
->ptr_size
),
8198 dwarf_vmatoa_1 (NULL
, cie_id
, offset_size
),
8199 (unsigned long)(cie
->chunk_start
- section_start
));
8201 if (fc
->segment_size
)
8202 printf ("%04lx:", segment_selector
);
8205 dwarf_vmatoa_1 (NULL
, fc
->pc_begin
, fc
->ptr_size
),
8206 dwarf_vmatoa_1 (NULL
, fc
->pc_begin
+ fc
->pc_range
, fc
->ptr_size
));
8208 if (! do_debug_frames_interp
&& augmentation_data_len
)
8210 display_augmentation_data (augmentation_data
, augmentation_data_len
);
8215 /* At this point, fc is the current chunk, cie (if any) is set, and
8216 we're about to interpret instructions for the chunk. */
8217 /* ??? At present we need to do this always, since this sizes the
8218 fc->col_type and fc->col_offset arrays, which we write into always.
8219 We should probably split the interpreted and non-interpreted bits
8220 into two different routines, since there's so much that doesn't
8221 really overlap between them. */
8222 if (1 || do_debug_frames_interp
)
8224 /* Start by making a pass over the chunk, allocating storage
8225 and taking note of what registers are used. */
8226 unsigned char *tmp
= start
;
8228 while (start
< block_end
)
8230 unsigned int reg
, op
, opa
;
8232 unsigned char * new_start
;
8239 /* Warning: if you add any more cases to this switch, be
8240 sure to add them to the corresponding switch below. */
8243 case DW_CFA_advance_loc
:
8247 if (frame_need_space (fc
, opa
) >= 0)
8248 fc
->col_type
[opa
] = DW_CFA_undefined
;
8250 case DW_CFA_restore
:
8251 if (frame_need_space (fc
, opa
) >= 0)
8252 fc
->col_type
[opa
] = DW_CFA_undefined
;
8254 case DW_CFA_set_loc
:
8255 start
+= encoded_ptr_size
;
8257 case DW_CFA_advance_loc1
:
8260 case DW_CFA_advance_loc2
:
8263 case DW_CFA_advance_loc4
:
8266 case DW_CFA_offset_extended
:
8267 case DW_CFA_val_offset
:
8270 if (frame_need_space (fc
, reg
) >= 0)
8271 fc
->col_type
[reg
] = DW_CFA_undefined
;
8273 case DW_CFA_restore_extended
:
8275 if (frame_need_space (fc
, reg
) >= 0)
8276 fc
->col_type
[reg
] = DW_CFA_undefined
;
8278 case DW_CFA_undefined
:
8280 if (frame_need_space (fc
, reg
) >= 0)
8281 fc
->col_type
[reg
] = DW_CFA_undefined
;
8283 case DW_CFA_same_value
:
8285 if (frame_need_space (fc
, reg
) >= 0)
8286 fc
->col_type
[reg
] = DW_CFA_undefined
;
8288 case DW_CFA_register
:
8291 if (frame_need_space (fc
, reg
) >= 0)
8292 fc
->col_type
[reg
] = DW_CFA_undefined
;
8294 case DW_CFA_def_cfa
:
8298 case DW_CFA_def_cfa_register
:
8301 case DW_CFA_def_cfa_offset
:
8304 case DW_CFA_def_cfa_expression
:
8306 new_start
= start
+ temp
;
8307 if (new_start
< start
)
8309 warn (_("Corrupt CFA_def expression value: %lu\n"), temp
);
8315 case DW_CFA_expression
:
8316 case DW_CFA_val_expression
:
8319 new_start
= start
+ temp
;
8320 if (new_start
< start
)
8322 /* PR 17512: file:306-192417-0.005. */
8323 warn (_("Corrupt CFA expression value: %lu\n"), temp
);
8328 if (frame_need_space (fc
, reg
) >= 0)
8329 fc
->col_type
[reg
] = DW_CFA_undefined
;
8331 case DW_CFA_offset_extended_sf
:
8332 case DW_CFA_val_offset_sf
:
8335 if (frame_need_space (fc
, reg
) >= 0)
8336 fc
->col_type
[reg
] = DW_CFA_undefined
;
8338 case DW_CFA_def_cfa_sf
:
8342 case DW_CFA_def_cfa_offset_sf
:
8345 case DW_CFA_MIPS_advance_loc8
:
8348 case DW_CFA_GNU_args_size
:
8351 case DW_CFA_GNU_negative_offset_extended
:
8354 if (frame_need_space (fc
, reg
) >= 0)
8355 fc
->col_type
[reg
] = DW_CFA_undefined
;
8366 /* Now we know what registers are used, make a second pass over
8367 the chunk, this time actually printing out the info. */
8369 while (start
< block_end
)
8371 unsigned char * tmp
;
8373 unsigned long ul
, roffs
;
8374 /* Note: It is tempting to use an unsigned long for 'reg' but there
8375 are various functions, notably frame_space_needed() that assume that
8376 reg is an unsigned int. */
8381 const char *reg_prefix
= "";
8388 /* Make a note if something other than DW_CFA_nop happens. */
8389 if (op
!= DW_CFA_nop
)
8392 /* Warning: if you add any more cases to this switch, be
8393 sure to add them to the corresponding switch above. */
8396 case DW_CFA_advance_loc
:
8397 if (do_debug_frames_interp
)
8398 frame_display_row (fc
, &need_col_headers
, &max_regs
);
8400 printf (" DW_CFA_advance_loc: %d to %s\n",
8401 opa
* fc
->code_factor
,
8402 dwarf_vmatoa_1 (NULL
,
8403 fc
->pc_begin
+ opa
* fc
->code_factor
,
8405 fc
->pc_begin
+= opa
* fc
->code_factor
;
8410 if (opa
>= (unsigned int) fc
->ncols
)
8411 reg_prefix
= bad_reg
;
8412 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
8413 printf (" DW_CFA_offset: %s%s at cfa%+ld\n",
8414 reg_prefix
, regname (opa
, 0),
8415 roffs
* fc
->data_factor
);
8416 if (*reg_prefix
== '\0')
8418 fc
->col_type
[opa
] = DW_CFA_offset
;
8419 fc
->col_offset
[opa
] = roffs
* fc
->data_factor
;
8423 case DW_CFA_restore
:
8424 if (opa
>= (unsigned int) fc
->ncols
)
8425 reg_prefix
= bad_reg
;
8426 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
8427 printf (" DW_CFA_restore: %s%s\n",
8428 reg_prefix
, regname (opa
, 0));
8429 if (*reg_prefix
!= '\0')
8432 if (opa
>= (unsigned int) cie
->ncols
8433 || (do_debug_frames_interp
8434 && cie
->col_type
[opa
] == DW_CFA_unreferenced
))
8436 fc
->col_type
[opa
] = DW_CFA_undefined
;
8437 fc
->col_offset
[opa
] = 0;
8441 fc
->col_type
[opa
] = cie
->col_type
[opa
];
8442 fc
->col_offset
[opa
] = cie
->col_offset
[opa
];
8446 case DW_CFA_set_loc
:
8447 vma
= get_encoded_value (&start
, fc
->fde_encoding
, section
, block_end
);
8448 if (do_debug_frames_interp
)
8449 frame_display_row (fc
, &need_col_headers
, &max_regs
);
8451 printf (" DW_CFA_set_loc: %s\n",
8452 dwarf_vmatoa_1 (NULL
, vma
, fc
->ptr_size
));
8456 case DW_CFA_advance_loc1
:
8457 SAFE_BYTE_GET_AND_INC (ofs
, start
, 1, end
);
8458 if (do_debug_frames_interp
)
8459 frame_display_row (fc
, &need_col_headers
, &max_regs
);
8461 printf (" DW_CFA_advance_loc1: %ld to %s\n",
8462 (unsigned long) (ofs
* fc
->code_factor
),
8463 dwarf_vmatoa_1 (NULL
,
8464 fc
->pc_begin
+ ofs
* fc
->code_factor
,
8466 fc
->pc_begin
+= ofs
* fc
->code_factor
;
8469 case DW_CFA_advance_loc2
:
8470 SAFE_BYTE_GET_AND_INC (ofs
, start
, 2, block_end
);
8471 if (do_debug_frames_interp
)
8472 frame_display_row (fc
, &need_col_headers
, &max_regs
);
8474 printf (" DW_CFA_advance_loc2: %ld to %s\n",
8475 (unsigned long) (ofs
* fc
->code_factor
),
8476 dwarf_vmatoa_1 (NULL
,
8477 fc
->pc_begin
+ ofs
* fc
->code_factor
,
8479 fc
->pc_begin
+= ofs
* fc
->code_factor
;
8482 case DW_CFA_advance_loc4
:
8483 SAFE_BYTE_GET_AND_INC (ofs
, start
, 4, block_end
);
8484 if (do_debug_frames_interp
)
8485 frame_display_row (fc
, &need_col_headers
, &max_regs
);
8487 printf (" DW_CFA_advance_loc4: %ld to %s\n",
8488 (unsigned long) (ofs
* fc
->code_factor
),
8489 dwarf_vmatoa_1 (NULL
,
8490 fc
->pc_begin
+ ofs
* fc
->code_factor
,
8492 fc
->pc_begin
+= ofs
* fc
->code_factor
;
8495 case DW_CFA_offset_extended
:
8498 if (reg
>= (unsigned int) fc
->ncols
)
8499 reg_prefix
= bad_reg
;
8500 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
8501 printf (" DW_CFA_offset_extended: %s%s at cfa%+ld\n",
8502 reg_prefix
, regname (reg
, 0),
8503 roffs
* fc
->data_factor
);
8504 if (*reg_prefix
== '\0')
8506 fc
->col_type
[reg
] = DW_CFA_offset
;
8507 fc
->col_offset
[reg
] = roffs
* fc
->data_factor
;
8511 case DW_CFA_val_offset
:
8514 if (reg
>= (unsigned int) fc
->ncols
)
8515 reg_prefix
= bad_reg
;
8516 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
8517 printf (" DW_CFA_val_offset: %s%s is cfa%+ld\n",
8518 reg_prefix
, regname (reg
, 0),
8519 roffs
* fc
->data_factor
);
8520 if (*reg_prefix
== '\0')
8522 fc
->col_type
[reg
] = DW_CFA_val_offset
;
8523 fc
->col_offset
[reg
] = roffs
* fc
->data_factor
;
8527 case DW_CFA_restore_extended
:
8529 if (reg
>= (unsigned int) fc
->ncols
)
8530 reg_prefix
= bad_reg
;
8531 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
8532 printf (" DW_CFA_restore_extended: %s%s\n",
8533 reg_prefix
, regname (reg
, 0));
8534 if (*reg_prefix
!= '\0')
8537 if (reg
>= (unsigned int) cie
->ncols
)
8539 fc
->col_type
[reg
] = DW_CFA_undefined
;
8540 fc
->col_offset
[reg
] = 0;
8544 fc
->col_type
[reg
] = cie
->col_type
[reg
];
8545 fc
->col_offset
[reg
] = cie
->col_offset
[reg
];
8549 case DW_CFA_undefined
:
8551 if (reg
>= (unsigned int) fc
->ncols
)
8552 reg_prefix
= bad_reg
;
8553 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
8554 printf (" DW_CFA_undefined: %s%s\n",
8555 reg_prefix
, regname (reg
, 0));
8556 if (*reg_prefix
== '\0')
8558 fc
->col_type
[reg
] = DW_CFA_undefined
;
8559 fc
->col_offset
[reg
] = 0;
8563 case DW_CFA_same_value
:
8565 if (reg
>= (unsigned int) fc
->ncols
)
8566 reg_prefix
= bad_reg
;
8567 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
8568 printf (" DW_CFA_same_value: %s%s\n",
8569 reg_prefix
, regname (reg
, 0));
8570 if (*reg_prefix
== '\0')
8572 fc
->col_type
[reg
] = DW_CFA_same_value
;
8573 fc
->col_offset
[reg
] = 0;
8577 case DW_CFA_register
:
8580 if (reg
>= (unsigned int) fc
->ncols
)
8581 reg_prefix
= bad_reg
;
8582 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
8584 printf (" DW_CFA_register: %s%s in ",
8585 reg_prefix
, regname (reg
, 0));
8586 puts (regname (roffs
, 0));
8588 if (*reg_prefix
== '\0')
8590 fc
->col_type
[reg
] = DW_CFA_register
;
8591 fc
->col_offset
[reg
] = roffs
;
8595 case DW_CFA_remember_state
:
8596 if (! do_debug_frames_interp
)
8597 printf (" DW_CFA_remember_state\n");
8598 rs
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
8599 rs
->cfa_offset
= fc
->cfa_offset
;
8600 rs
->cfa_reg
= fc
->cfa_reg
;
8602 rs
->cfa_exp
= fc
->cfa_exp
;
8603 rs
->ncols
= fc
->ncols
;
8604 rs
->col_type
= (short int *) xcmalloc (rs
->ncols
,
8605 sizeof (* rs
->col_type
));
8606 rs
->col_offset
= (int *) xcmalloc (rs
->ncols
, sizeof (* rs
->col_offset
));
8607 memcpy (rs
->col_type
, fc
->col_type
, rs
->ncols
* sizeof (* fc
->col_type
));
8608 memcpy (rs
->col_offset
, fc
->col_offset
, rs
->ncols
* sizeof (* fc
->col_offset
));
8609 rs
->next
= remembered_state
;
8610 remembered_state
= rs
;
8613 case DW_CFA_restore_state
:
8614 if (! do_debug_frames_interp
)
8615 printf (" DW_CFA_restore_state\n");
8616 rs
= remembered_state
;
8619 remembered_state
= rs
->next
;
8620 fc
->cfa_offset
= rs
->cfa_offset
;
8621 fc
->cfa_reg
= rs
->cfa_reg
;
8623 fc
->cfa_exp
= rs
->cfa_exp
;
8624 if (frame_need_space (fc
, rs
->ncols
- 1) < 0)
8626 warn (_("Invalid column number in saved frame state\n"));
8630 memcpy (fc
->col_type
, rs
->col_type
, rs
->ncols
* sizeof (* rs
->col_type
));
8631 memcpy (fc
->col_offset
, rs
->col_offset
,
8632 rs
->ncols
* sizeof (* rs
->col_offset
));
8633 free (rs
->col_type
);
8634 free (rs
->col_offset
);
8637 else if (do_debug_frames_interp
)
8638 printf ("Mismatched DW_CFA_restore_state\n");
8641 case DW_CFA_def_cfa
:
8642 READ_ULEB (fc
->cfa_reg
);
8643 READ_ULEB (fc
->cfa_offset
);
8645 if (! do_debug_frames_interp
)
8646 printf (" DW_CFA_def_cfa: %s ofs %d\n",
8647 regname (fc
->cfa_reg
, 0), (int) fc
->cfa_offset
);
8650 case DW_CFA_def_cfa_register
:
8651 READ_ULEB (fc
->cfa_reg
);
8653 if (! do_debug_frames_interp
)
8654 printf (" DW_CFA_def_cfa_register: %s\n",
8655 regname (fc
->cfa_reg
, 0));
8658 case DW_CFA_def_cfa_offset
:
8659 READ_ULEB (fc
->cfa_offset
);
8660 if (! do_debug_frames_interp
)
8661 printf (" DW_CFA_def_cfa_offset: %d\n", (int) fc
->cfa_offset
);
8665 if (! do_debug_frames_interp
)
8666 printf (" DW_CFA_nop\n");
8669 case DW_CFA_def_cfa_expression
:
8671 if (start
>= block_end
|| ul
> (unsigned long) (block_end
- start
))
8673 printf (_(" DW_CFA_def_cfa_expression: <corrupt len %lu>\n"), ul
);
8676 if (! do_debug_frames_interp
)
8678 printf (" DW_CFA_def_cfa_expression (");
8679 decode_location_expression (start
, eh_addr_size
, 0, -1,
8687 case DW_CFA_expression
:
8690 if (reg
>= (unsigned int) fc
->ncols
)
8691 reg_prefix
= bad_reg
;
8692 /* PR 17512: file: 069-133014-0.006. */
8693 /* PR 17512: file: 98c02eb4. */
8695 if (start
>= block_end
|| tmp
> block_end
|| tmp
< start
)
8697 printf (_(" DW_CFA_expression: <corrupt len %lu>\n"), ul
);
8700 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
8702 printf (" DW_CFA_expression: %s%s (",
8703 reg_prefix
, regname (reg
, 0));
8704 decode_location_expression (start
, eh_addr_size
, 0, -1,
8708 if (*reg_prefix
== '\0')
8709 fc
->col_type
[reg
] = DW_CFA_expression
;
8713 case DW_CFA_val_expression
:
8716 if (reg
>= (unsigned int) fc
->ncols
)
8717 reg_prefix
= bad_reg
;
8719 if (start
>= block_end
|| tmp
> block_end
|| tmp
< start
)
8721 printf (" DW_CFA_val_expression: <corrupt len %lu>\n", ul
);
8724 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
8726 printf (" DW_CFA_val_expression: %s%s (",
8727 reg_prefix
, regname (reg
, 0));
8728 decode_location_expression (start
, eh_addr_size
, 0, -1,
8732 if (*reg_prefix
== '\0')
8733 fc
->col_type
[reg
] = DW_CFA_val_expression
;
8737 case DW_CFA_offset_extended_sf
:
8740 if (frame_need_space (fc
, reg
) < 0)
8741 reg_prefix
= bad_reg
;
8742 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
8743 printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+ld\n",
8744 reg_prefix
, regname (reg
, 0),
8745 (long)(l
* fc
->data_factor
));
8746 if (*reg_prefix
== '\0')
8748 fc
->col_type
[reg
] = DW_CFA_offset
;
8749 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
8753 case DW_CFA_val_offset_sf
:
8756 if (frame_need_space (fc
, reg
) < 0)
8757 reg_prefix
= bad_reg
;
8758 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
8759 printf (" DW_CFA_val_offset_sf: %s%s is cfa%+ld\n",
8760 reg_prefix
, regname (reg
, 0),
8761 (long)(l
* fc
->data_factor
));
8762 if (*reg_prefix
== '\0')
8764 fc
->col_type
[reg
] = DW_CFA_val_offset
;
8765 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
8769 case DW_CFA_def_cfa_sf
:
8770 READ_ULEB (fc
->cfa_reg
);
8771 READ_ULEB (fc
->cfa_offset
);
8772 fc
->cfa_offset
= fc
->cfa_offset
* fc
->data_factor
;
8774 if (! do_debug_frames_interp
)
8775 printf (" DW_CFA_def_cfa_sf: %s ofs %d\n",
8776 regname (fc
->cfa_reg
, 0), (int) fc
->cfa_offset
);
8779 case DW_CFA_def_cfa_offset_sf
:
8780 READ_ULEB (fc
->cfa_offset
);
8781 fc
->cfa_offset
*= fc
->data_factor
;
8782 if (! do_debug_frames_interp
)
8783 printf (" DW_CFA_def_cfa_offset_sf: %d\n", (int) fc
->cfa_offset
);
8786 case DW_CFA_MIPS_advance_loc8
:
8787 SAFE_BYTE_GET_AND_INC (ofs
, start
, 8, block_end
);
8788 if (do_debug_frames_interp
)
8789 frame_display_row (fc
, &need_col_headers
, &max_regs
);
8791 printf (" DW_CFA_MIPS_advance_loc8: %ld to %s\n",
8792 (unsigned long) (ofs
* fc
->code_factor
),
8793 dwarf_vmatoa_1 (NULL
,
8794 fc
->pc_begin
+ ofs
* fc
->code_factor
,
8796 fc
->pc_begin
+= ofs
* fc
->code_factor
;
8799 case DW_CFA_GNU_window_save
:
8800 if (! do_debug_frames_interp
)
8801 printf (" DW_CFA_GNU_window_save\n");
8804 case DW_CFA_GNU_args_size
:
8806 if (! do_debug_frames_interp
)
8807 printf (" DW_CFA_GNU_args_size: %ld\n", ul
);
8810 case DW_CFA_GNU_negative_offset_extended
:
8814 if (frame_need_space (fc
, reg
) < 0)
8815 reg_prefix
= bad_reg
;
8816 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
8817 printf (" DW_CFA_GNU_negative_offset_extended: %s%s at cfa%+ld\n",
8818 reg_prefix
, regname (reg
, 0),
8819 (long)(l
* fc
->data_factor
));
8820 if (*reg_prefix
== '\0')
8822 fc
->col_type
[reg
] = DW_CFA_offset
;
8823 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
8828 if (op
>= DW_CFA_lo_user
&& op
<= DW_CFA_hi_user
)
8829 printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op
);
8831 warn (_("Unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op
);
8836 /* Interpret the CFA - as long as it is not completely full of NOPs. */
8837 if (do_debug_frames_interp
&& ! all_nops
)
8838 frame_display_row (fc
, &need_col_headers
, &max_regs
);
8841 eh_addr_size
= saved_eh_addr_size
;
8846 while (remembered_state
!= NULL
)
8848 rs
= remembered_state
;
8849 remembered_state
= rs
->next
;
8850 free (rs
->col_type
);
8851 free (rs
->col_offset
);
8852 rs
->next
= NULL
; /* Paranoia. */
8856 while (chunks
!= NULL
)
8860 free (rs
->col_type
);
8861 free (rs
->col_offset
);
8862 rs
->next
= NULL
; /* Paranoia. */
8866 while (forward_refs
!= NULL
)
8869 forward_refs
= rs
->next
;
8870 free (rs
->col_type
);
8871 free (rs
->col_offset
);
8872 rs
->next
= NULL
; /* Paranoia. */
8882 display_debug_names (struct dwarf_section
*section
, void *file
)
8884 unsigned char *hdrptr
= section
->start
;
8885 dwarf_vma unit_length
;
8886 unsigned char *unit_start
;
8887 const unsigned char *const section_end
= section
->start
+ section
->size
;
8888 unsigned char *unit_end
;
8890 introduce (section
, FALSE
);
8892 load_debug_section_with_follow (str
, file
);
8894 for (; hdrptr
< section_end
; hdrptr
= unit_end
)
8896 unsigned int offset_size
;
8897 uint16_t dwarf_version
, padding
;
8898 uint32_t comp_unit_count
, local_type_unit_count
, foreign_type_unit_count
;
8899 uint32_t bucket_count
, name_count
, abbrev_table_size
;
8900 uint32_t augmentation_string_size
;
8902 unsigned long sec_off
;
8903 bfd_boolean augmentation_printable
;
8904 const char *augmentation_string
;
8906 unit_start
= hdrptr
;
8908 /* Get and check the length of the block. */
8909 SAFE_BYTE_GET_AND_INC (unit_length
, hdrptr
, 4, section_end
);
8911 if (unit_length
== 0xffffffff)
8913 /* This section is 64-bit DWARF. */
8914 SAFE_BYTE_GET_AND_INC (unit_length
, hdrptr
, 8, section_end
);
8919 unit_end
= hdrptr
+ unit_length
;
8921 sec_off
= hdrptr
- section
->start
;
8922 if (sec_off
+ unit_length
< sec_off
8923 || sec_off
+ unit_length
> section
->size
)
8925 warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"),
8927 (unsigned long) (unit_start
- section
->start
),
8928 dwarf_vmatoa ("x", unit_length
));
8932 /* Get and check the version number. */
8933 SAFE_BYTE_GET_AND_INC (dwarf_version
, hdrptr
, 2, unit_end
);
8934 printf (_("Version %ld\n"), (long) dwarf_version
);
8936 /* Prior versions did not exist, and future versions may not be
8937 backwards compatible. */
8938 if (dwarf_version
!= 5)
8940 warn (_("Only DWARF version 5 .debug_names "
8941 "is currently supported.\n"));
8945 SAFE_BYTE_GET_AND_INC (padding
, hdrptr
, 2, unit_end
);
8947 warn (_("Padding field of .debug_names must be 0 (found 0x%x)\n"),
8950 SAFE_BYTE_GET_AND_INC (comp_unit_count
, hdrptr
, 4, unit_end
);
8951 if (comp_unit_count
== 0)
8952 warn (_("Compilation unit count must be >= 1 in .debug_names\n"));
8954 SAFE_BYTE_GET_AND_INC (local_type_unit_count
, hdrptr
, 4, unit_end
);
8955 SAFE_BYTE_GET_AND_INC (foreign_type_unit_count
, hdrptr
, 4, unit_end
);
8956 SAFE_BYTE_GET_AND_INC (bucket_count
, hdrptr
, 4, unit_end
);
8957 SAFE_BYTE_GET_AND_INC (name_count
, hdrptr
, 4, unit_end
);
8958 SAFE_BYTE_GET_AND_INC (abbrev_table_size
, hdrptr
, 4, unit_end
);
8960 SAFE_BYTE_GET_AND_INC (augmentation_string_size
, hdrptr
, 4, unit_end
);
8961 if (augmentation_string_size
% 4 != 0)
8963 warn (_("Augmentation string length %u must be rounded up "
8964 "to a multiple of 4 in .debug_names.\n"),
8965 augmentation_string_size
);
8966 augmentation_string_size
+= (-augmentation_string_size
) & 3;
8969 printf (_("Augmentation string:"));
8971 augmentation_printable
= TRUE
;
8972 augmentation_string
= (const char *) hdrptr
;
8974 for (i
= 0; i
< augmentation_string_size
; i
++)
8978 SAFE_BYTE_GET_AND_INC (uc
, hdrptr
, 1, unit_end
);
8979 printf (" %02x", uc
);
8981 if (uc
!= 0 && !ISPRINT (uc
))
8982 augmentation_printable
= FALSE
;
8985 if (augmentation_printable
)
8989 i
< augmentation_string_size
&& augmentation_string
[i
];
8991 putchar (augmentation_string
[i
]);
8996 printf (_("CU table:\n"));
8997 for (i
= 0; i
< comp_unit_count
; i
++)
9001 SAFE_BYTE_GET_AND_INC (cu_offset
, hdrptr
, offset_size
, unit_end
);
9002 printf (_("[%3u] 0x%lx\n"), i
, (unsigned long) cu_offset
);
9006 printf (_("TU table:\n"));
9007 for (i
= 0; i
< local_type_unit_count
; i
++)
9011 SAFE_BYTE_GET_AND_INC (tu_offset
, hdrptr
, offset_size
, unit_end
);
9012 printf (_("[%3u] 0x%lx\n"), i
, (unsigned long) tu_offset
);
9016 printf (_("Foreign TU table:\n"));
9017 for (i
= 0; i
< foreign_type_unit_count
; i
++)
9021 SAFE_BYTE_GET_AND_INC (signature
, hdrptr
, 8, unit_end
);
9022 printf (_("[%3u] "), i
);
9023 print_dwarf_vma (signature
, 8);
9028 const uint32_t *const hash_table_buckets
= (uint32_t *) hdrptr
;
9029 hdrptr
+= bucket_count
* sizeof (uint32_t);
9030 const uint32_t *const hash_table_hashes
= (uint32_t *) hdrptr
;
9031 hdrptr
+= name_count
* sizeof (uint32_t);
9032 unsigned char *const name_table_string_offsets
= hdrptr
;
9033 hdrptr
+= name_count
* offset_size
;
9034 unsigned char *const name_table_entry_offsets
= hdrptr
;
9035 hdrptr
+= name_count
* offset_size
;
9036 unsigned char *const abbrev_table
= hdrptr
;
9037 hdrptr
+= abbrev_table_size
;
9038 const unsigned char *const abbrev_table_end
= hdrptr
;
9039 unsigned char *const entry_pool
= hdrptr
;
9040 if (hdrptr
> unit_end
)
9042 warn (_("Entry pool offset (0x%lx) exceeds unit size 0x%lx "
9043 "for unit 0x%lx in the debug_names\n"),
9044 (long) (hdrptr
- section
->start
),
9045 (long) (unit_end
- section
->start
),
9046 (long) (unit_start
- section
->start
));
9050 size_t buckets_filled
= 0;
9052 for (bucketi
= 0; bucketi
< bucket_count
; bucketi
++)
9054 const uint32_t bucket
= hash_table_buckets
[bucketi
];
9059 printf (ngettext ("Used %zu of %lu bucket.\n",
9060 "Used %zu of %lu buckets.\n",
9062 buckets_filled
, (unsigned long) bucket_count
);
9064 uint32_t hash_prev
= 0;
9065 size_t hash_clash_count
= 0;
9066 size_t longest_clash
= 0;
9067 size_t this_length
= 0;
9069 for (hashi
= 0; hashi
< name_count
; hashi
++)
9071 const uint32_t hash_this
= hash_table_hashes
[hashi
];
9075 if (hash_prev
% bucket_count
== hash_this
% bucket_count
)
9079 longest_clash
= MAX (longest_clash
, this_length
);
9084 hash_prev
= hash_this
;
9086 printf (_("Out of %lu items there are %zu bucket clashes"
9087 " (longest of %zu entries).\n"),
9088 (unsigned long) name_count
, hash_clash_count
, longest_clash
);
9089 assert (name_count
== buckets_filled
+ hash_clash_count
);
9091 struct abbrev_lookup_entry
9093 dwarf_vma abbrev_tag
;
9094 unsigned char *abbrev_lookup_ptr
;
9096 struct abbrev_lookup_entry
*abbrev_lookup
= NULL
;
9097 size_t abbrev_lookup_used
= 0;
9098 size_t abbrev_lookup_allocated
= 0;
9100 unsigned char *abbrevptr
= abbrev_table
;
9103 unsigned int bytes_read
;
9104 const dwarf_vma abbrev_tag
= read_uleb128 (abbrevptr
, &bytes_read
,
9106 abbrevptr
+= bytes_read
;
9107 if (abbrev_tag
== 0)
9109 if (abbrev_lookup_used
== abbrev_lookup_allocated
)
9111 abbrev_lookup_allocated
= MAX (0x100,
9112 abbrev_lookup_allocated
* 2);
9113 abbrev_lookup
= xrealloc (abbrev_lookup
,
9114 (abbrev_lookup_allocated
9115 * sizeof (*abbrev_lookup
)));
9117 assert (abbrev_lookup_used
< abbrev_lookup_allocated
);
9118 struct abbrev_lookup_entry
*entry
;
9119 for (entry
= abbrev_lookup
;
9120 entry
< abbrev_lookup
+ abbrev_lookup_used
;
9122 if (entry
->abbrev_tag
== abbrev_tag
)
9124 warn (_("Duplicate abbreviation tag %lu "
9125 "in unit 0x%lx in the debug_names\n"),
9126 (long) abbrev_tag
, (long) (unit_start
- section
->start
));
9129 entry
= &abbrev_lookup
[abbrev_lookup_used
++];
9130 entry
->abbrev_tag
= abbrev_tag
;
9131 entry
->abbrev_lookup_ptr
= abbrevptr
;
9133 /* Skip DWARF tag. */
9134 read_uleb128 (abbrevptr
, &bytes_read
, abbrev_table_end
);
9135 abbrevptr
+= bytes_read
;
9138 const dwarf_vma xindex
= read_uleb128 (abbrevptr
,
9141 abbrevptr
+= bytes_read
;
9142 const dwarf_vma form
= read_uleb128 (abbrevptr
, &bytes_read
,
9144 abbrevptr
+= bytes_read
;
9145 if (xindex
== 0 && form
== 0)
9150 printf (_("\nSymbol table:\n"));
9152 for (namei
= 0; namei
< name_count
; ++namei
)
9154 uint64_t string_offset
, entry_offset
;
9156 SAFE_BYTE_GET (string_offset
,
9157 name_table_string_offsets
+ namei
* offset_size
,
9158 offset_size
, unit_end
);
9159 SAFE_BYTE_GET (entry_offset
,
9160 name_table_entry_offsets
+ namei
* offset_size
,
9161 offset_size
, unit_end
);
9163 printf ("[%3u] #%08x %s:", namei
, hash_table_hashes
[namei
],
9164 fetch_indirect_string (string_offset
));
9166 unsigned char *entryptr
= entry_pool
+ entry_offset
;
9168 // We need to scan first whether there is a single or multiple
9169 // entries. TAGNO is -2 for the first entry, it is -1 for the
9170 // initial tag read of the second entry, then it becomes 0 for the
9171 // first entry for real printing etc.
9173 /* Initialize it due to a false compiler warning. */
9174 dwarf_vma second_abbrev_tag
= -1;
9177 unsigned int bytes_read
;
9178 const dwarf_vma abbrev_tag
= read_uleb128 (entryptr
, &bytes_read
,
9180 entryptr
+= bytes_read
;
9183 second_abbrev_tag
= abbrev_tag
;
9185 entryptr
= entry_pool
+ entry_offset
;
9188 if (abbrev_tag
== 0)
9192 (tagno
== 0 && second_abbrev_tag
== 0 ? " " : "\n\t"),
9193 (unsigned long) abbrev_tag
);
9195 const struct abbrev_lookup_entry
*entry
;
9196 for (entry
= abbrev_lookup
;
9197 entry
< abbrev_lookup
+ abbrev_lookup_used
;
9199 if (entry
->abbrev_tag
== abbrev_tag
)
9201 if (entry
>= abbrev_lookup
+ abbrev_lookup_used
)
9203 warn (_("Undefined abbreviation tag %lu "
9204 "in unit 0x%lx in the debug_names\n"),
9206 (long) (unit_start
- section
->start
));
9209 abbrevptr
= entry
->abbrev_lookup_ptr
;
9210 const dwarf_vma dwarf_tag
= read_uleb128 (abbrevptr
, &bytes_read
,
9212 abbrevptr
+= bytes_read
;
9214 printf (" %s", get_TAG_name (dwarf_tag
));
9217 const dwarf_vma xindex
= read_uleb128 (abbrevptr
,
9220 abbrevptr
+= bytes_read
;
9221 const dwarf_vma form
= read_uleb128 (abbrevptr
, &bytes_read
,
9223 abbrevptr
+= bytes_read
;
9224 if (xindex
== 0 && form
== 0)
9228 printf (" %s", get_IDX_name (xindex
));
9229 entryptr
= read_and_display_attr_value (0, form
, 0,
9230 unit_start
, entryptr
, unit_end
,
9232 dwarf_version
, NULL
,
9239 printf (_(" <no entries>"));
9243 free (abbrev_lookup
);
9250 display_debug_links (struct dwarf_section
* section
,
9251 void * file ATTRIBUTE_UNUSED
)
9253 const unsigned char * filename
;
9254 unsigned int filelen
;
9256 introduce (section
, FALSE
);
9258 /* The .gnu_debuglink section is formatted as:
9259 (c-string) Filename.
9260 (padding) If needed to reach a 4 byte boundary.
9261 (uint32_t) CRC32 value.
9263 The .gun_debugaltlink section is formatted as:
9264 (c-string) Filename.
9265 (binary) Build-ID. */
9267 filename
= section
->start
;
9268 filelen
= strnlen ((const char *) filename
, section
->size
);
9269 if (filelen
== section
->size
)
9271 warn (_("The debuglink filename is corrupt/missing\n"));
9275 printf (_(" Separate debug info file: %s\n"), filename
);
9277 if (const_strneq (section
->name
, ".gnu_debuglink"))
9280 unsigned int crc_offset
;
9282 crc_offset
= filelen
+ 1;
9283 crc_offset
= (crc_offset
+ 3) & ~3;
9284 if (crc_offset
+ 4 > section
->size
)
9286 warn (_("CRC offset missing/truncated\n"));
9290 crc32
= byte_get (filename
+ crc_offset
, 4);
9292 printf (_(" CRC value: %#x\n"), crc32
);
9294 if (crc_offset
+ 4 < section
->size
)
9296 warn (_("There are %#lx extraneous bytes at the end of the section\n"),
9297 (long)(section
->size
- (crc_offset
+ 4)));
9301 else /* const_strneq (section->name, ".gnu_debugaltlink") */
9303 const unsigned char * build_id
= section
->start
+ filelen
+ 1;
9304 bfd_size_type build_id_len
= section
->size
- (filelen
+ 1);
9305 bfd_size_type printed
;
9307 /* FIXME: Should we support smaller build-id notes ? */
9308 if (build_id_len
< 0x14)
9310 warn (_("Build-ID is too short (%#lx bytes)\n"), (long) build_id_len
);
9314 printed
= printf (_(" Build-ID (%#lx bytes):"), (long) build_id_len
);
9315 display_data (printed
, build_id
, build_id_len
);
9324 display_gdb_index (struct dwarf_section
*section
,
9325 void *file ATTRIBUTE_UNUSED
)
9327 unsigned char *start
= section
->start
;
9329 uint32_t cu_list_offset
, tu_list_offset
;
9330 uint32_t address_table_offset
, symbol_table_offset
, constant_pool_offset
;
9331 unsigned int cu_list_elements
, tu_list_elements
;
9332 unsigned int address_table_size
, symbol_table_slots
;
9333 unsigned char *cu_list
, *tu_list
;
9334 unsigned char *address_table
, *symbol_table
, *constant_pool
;
9337 /* The documentation for the format of this file is in gdb/dwarf2read.c. */
9339 introduce (section
, FALSE
);
9341 if (section
->size
< 6 * sizeof (uint32_t))
9343 warn (_("Truncated header in the %s section.\n"), section
->name
);
9347 version
= byte_get_little_endian (start
, 4);
9348 printf (_("Version %ld\n"), (long) version
);
9350 /* Prior versions are obsolete, and future versions may not be
9351 backwards compatible. */
9352 if (version
< 3 || version
> 8)
9354 warn (_("Unsupported version %lu.\n"), (unsigned long) version
);
9358 warn (_("The address table data in version 3 may be wrong.\n"));
9360 warn (_("Version 4 does not support case insensitive lookups.\n"));
9362 warn (_("Version 5 does not include inlined functions.\n"));
9364 warn (_("Version 6 does not include symbol attributes.\n"));
9365 /* Version 7 indices generated by Gold have bad type unit references,
9366 PR binutils/15021. But we don't know if the index was generated by
9367 Gold or not, so to avoid worrying users with gdb-generated indices
9368 we say nothing for version 7 here. */
9370 cu_list_offset
= byte_get_little_endian (start
+ 4, 4);
9371 tu_list_offset
= byte_get_little_endian (start
+ 8, 4);
9372 address_table_offset
= byte_get_little_endian (start
+ 12, 4);
9373 symbol_table_offset
= byte_get_little_endian (start
+ 16, 4);
9374 constant_pool_offset
= byte_get_little_endian (start
+ 20, 4);
9376 if (cu_list_offset
> section
->size
9377 || tu_list_offset
> section
->size
9378 || address_table_offset
> section
->size
9379 || symbol_table_offset
> section
->size
9380 || constant_pool_offset
> section
->size
)
9382 warn (_("Corrupt header in the %s section.\n"), section
->name
);
9386 /* PR 17531: file: 418d0a8a. */
9387 if (tu_list_offset
< cu_list_offset
)
9389 warn (_("TU offset (%x) is less than CU offset (%x)\n"),
9390 tu_list_offset
, cu_list_offset
);
9394 cu_list_elements
= (tu_list_offset
- cu_list_offset
) / 8;
9396 if (address_table_offset
< tu_list_offset
)
9398 warn (_("Address table offset (%x) is less than TU offset (%x)\n"),
9399 address_table_offset
, tu_list_offset
);
9403 tu_list_elements
= (address_table_offset
- tu_list_offset
) / 8;
9405 /* PR 17531: file: 18a47d3d. */
9406 if (symbol_table_offset
< address_table_offset
)
9408 warn (_("Symbol table offset (%x) is less then Address table offset (%x)\n"),
9409 symbol_table_offset
, address_table_offset
);
9413 address_table_size
= symbol_table_offset
- address_table_offset
;
9415 if (constant_pool_offset
< symbol_table_offset
)
9417 warn (_("Constant pool offset (%x) is less than symbol table offset (%x)\n"),
9418 constant_pool_offset
, symbol_table_offset
);
9422 symbol_table_slots
= (constant_pool_offset
- symbol_table_offset
) / 8;
9424 cu_list
= start
+ cu_list_offset
;
9425 tu_list
= start
+ tu_list_offset
;
9426 address_table
= start
+ address_table_offset
;
9427 symbol_table
= start
+ symbol_table_offset
;
9428 constant_pool
= start
+ constant_pool_offset
;
9430 if (address_table
+ address_table_size
> section
->start
+ section
->size
)
9432 warn (_("Address table extends beyond end of section.\n"));
9436 printf (_("\nCU table:\n"));
9437 for (i
= 0; i
< cu_list_elements
; i
+= 2)
9439 uint64_t cu_offset
= byte_get_little_endian (cu_list
+ i
* 8, 8);
9440 uint64_t cu_length
= byte_get_little_endian (cu_list
+ i
* 8 + 8, 8);
9442 printf (_("[%3u] 0x%lx - 0x%lx\n"), i
/ 2,
9443 (unsigned long) cu_offset
,
9444 (unsigned long) (cu_offset
+ cu_length
- 1));
9447 printf (_("\nTU table:\n"));
9448 for (i
= 0; i
< tu_list_elements
; i
+= 3)
9450 uint64_t tu_offset
= byte_get_little_endian (tu_list
+ i
* 8, 8);
9451 uint64_t type_offset
= byte_get_little_endian (tu_list
+ i
* 8 + 8, 8);
9452 uint64_t signature
= byte_get_little_endian (tu_list
+ i
* 8 + 16, 8);
9454 printf (_("[%3u] 0x%lx 0x%lx "), i
/ 3,
9455 (unsigned long) tu_offset
,
9456 (unsigned long) type_offset
);
9457 print_dwarf_vma (signature
, 8);
9461 printf (_("\nAddress table:\n"));
9462 for (i
= 0; i
< address_table_size
&& i
<= address_table_size
- (2 * 8 + 4);
9465 uint64_t low
= byte_get_little_endian (address_table
+ i
, 8);
9466 uint64_t high
= byte_get_little_endian (address_table
+ i
+ 8, 8);
9467 uint32_t cu_index
= byte_get_little_endian (address_table
+ i
+ 16, 4);
9469 print_dwarf_vma (low
, 8);
9470 print_dwarf_vma (high
, 8);
9471 printf (_("%lu\n"), (unsigned long) cu_index
);
9474 printf (_("\nSymbol table:\n"));
9475 for (i
= 0; i
< symbol_table_slots
; ++i
)
9477 uint32_t name_offset
= byte_get_little_endian (symbol_table
+ i
* 8, 4);
9478 uint32_t cu_vector_offset
= byte_get_little_endian (symbol_table
+ i
* 8 + 4, 4);
9479 uint32_t num_cus
, cu
;
9481 if (name_offset
!= 0
9482 || cu_vector_offset
!= 0)
9485 unsigned char * adr
;
9487 adr
= constant_pool
+ name_offset
;
9488 /* PR 17531: file: 5b7b07ad. */
9489 if (adr
< constant_pool
|| adr
>= section
->start
+ section
->size
)
9491 printf (_("[%3u] <corrupt offset: %x>"), i
, name_offset
);
9492 warn (_("Corrupt name offset of 0x%x found for symbol table slot %d\n"),
9496 printf ("[%3u] %.*s:", i
,
9497 (int) (section
->size
- (constant_pool_offset
+ name_offset
)),
9498 constant_pool
+ name_offset
);
9500 adr
= constant_pool
+ cu_vector_offset
;
9501 if (adr
< constant_pool
|| adr
>= section
->start
+ section
->size
- 3)
9503 printf (_("<invalid CU vector offset: %x>\n"), cu_vector_offset
);
9504 warn (_("Corrupt CU vector offset of 0x%x found for symbol table slot %d\n"),
9505 cu_vector_offset
, i
);
9509 num_cus
= byte_get_little_endian (adr
, 4);
9511 adr
= constant_pool
+ cu_vector_offset
+ 4 + num_cus
* 4;
9512 if (num_cus
* 4 < num_cus
9513 || adr
>= section
->start
+ section
->size
9514 || adr
< constant_pool
)
9516 printf ("<invalid number of CUs: %d>\n", num_cus
);
9517 warn (_("Invalid number of CUs (0x%x) for symbol table slot %d\n"),
9525 for (j
= 0; j
< num_cus
; ++j
)
9528 gdb_index_symbol_kind kind
;
9530 cu
= byte_get_little_endian (constant_pool
+ cu_vector_offset
+ 4 + j
* 4, 4);
9531 is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu
);
9532 kind
= GDB_INDEX_SYMBOL_KIND_VALUE (cu
);
9533 cu
= GDB_INDEX_CU_VALUE (cu
);
9534 /* Convert to TU number if it's for a type unit. */
9535 if (cu
>= cu_list_elements
/ 2)
9536 printf ("%cT%lu", num_cus
> 1 ? '\t' : ' ',
9537 (unsigned long) (cu
- cu_list_elements
/ 2));
9539 printf ("%c%lu", num_cus
> 1 ? '\t' : ' ', (unsigned long) cu
);
9541 printf (" [%s, %s]",
9542 is_static
? _("static") : _("global"),
9543 get_gdb_index_symbol_kind_name (kind
));
9555 /* Pre-allocate enough space for the CU/TU sets needed. */
9558 prealloc_cu_tu_list (unsigned int nshndx
)
9560 if (shndx_pool
== NULL
)
9562 shndx_pool_size
= nshndx
;
9563 shndx_pool_used
= 0;
9564 shndx_pool
= (unsigned int *) xcmalloc (shndx_pool_size
,
9565 sizeof (unsigned int));
9569 shndx_pool_size
= shndx_pool_used
+ nshndx
;
9570 shndx_pool
= (unsigned int *) xcrealloc (shndx_pool
, shndx_pool_size
,
9571 sizeof (unsigned int));
9576 add_shndx_to_cu_tu_entry (unsigned int shndx
)
9578 if (shndx_pool_used
>= shndx_pool_size
)
9580 error (_("Internal error: out of space in the shndx pool.\n"));
9583 shndx_pool
[shndx_pool_used
++] = shndx
;
9587 end_cu_tu_entry (void)
9589 if (shndx_pool_used
>= shndx_pool_size
)
9591 error (_("Internal error: out of space in the shndx pool.\n"));
9594 shndx_pool
[shndx_pool_used
++] = 0;
9597 /* Return the short name of a DWARF section given by a DW_SECT enumerator. */
9600 get_DW_SECT_short_name (unsigned int dw_sect
)
9602 static char buf
[16];
9610 case DW_SECT_ABBREV
:
9616 case DW_SECT_STR_OFFSETS
:
9618 case DW_SECT_MACINFO
:
9626 snprintf (buf
, sizeof (buf
), "%d", dw_sect
);
9630 /* Process a CU or TU index. If DO_DISPLAY is true, print the contents.
9631 These sections are extensions for Fission.
9632 See http://gcc.gnu.org/wiki/DebugFissionDWP. */
9635 process_cu_tu_index (struct dwarf_section
*section
, int do_display
)
9637 unsigned char *phdr
= section
->start
;
9638 unsigned char *limit
= phdr
+ section
->size
;
9639 unsigned char *phash
;
9640 unsigned char *pindex
;
9641 unsigned char *ppool
;
9642 unsigned int version
;
9643 unsigned int ncols
= 0;
9645 unsigned int nslots
;
9648 dwarf_vma signature_high
;
9649 dwarf_vma signature_low
;
9652 /* PR 17512: file: 002-168123-0.004. */
9655 warn (_("Section %s is empty\n"), section
->name
);
9658 /* PR 17512: file: 002-376-0.004. */
9659 if (section
->size
< 24)
9661 warn (_("Section %s is too small to contain a CU/TU header\n"),
9666 SAFE_BYTE_GET (version
, phdr
, 4, limit
);
9668 SAFE_BYTE_GET (ncols
, phdr
+ 4, 4, limit
);
9669 SAFE_BYTE_GET (nused
, phdr
+ 8, 4, limit
);
9670 SAFE_BYTE_GET (nslots
, phdr
+ 12, 4, limit
);
9673 pindex
= phash
+ (size_t) nslots
* 8;
9674 ppool
= pindex
+ (size_t) nslots
* 4;
9678 introduce (section
, FALSE
);
9680 printf (_(" Version: %u\n"), version
);
9682 printf (_(" Number of columns: %u\n"), ncols
);
9683 printf (_(" Number of used entries: %u\n"), nused
);
9684 printf (_(" Number of slots: %u\n\n"), nslots
);
9687 /* PR 17531: file: 45d69832. */
9688 if ((size_t) nslots
* 8 / 8 != nslots
9689 || phash
< phdr
|| phash
> limit
9690 || pindex
< phash
|| pindex
> limit
9691 || ppool
< pindex
|| ppool
> limit
)
9693 warn (ngettext ("Section %s is too small for %u slot\n",
9694 "Section %s is too small for %u slots\n",
9696 section
->name
, nslots
);
9703 prealloc_cu_tu_list ((limit
- ppool
) / 4);
9704 for (i
= 0; i
< nslots
; i
++)
9706 unsigned char *shndx_list
;
9709 SAFE_BYTE_GET64 (phash
, &signature_high
, &signature_low
, limit
);
9710 if (signature_high
!= 0 || signature_low
!= 0)
9712 SAFE_BYTE_GET (j
, pindex
, 4, limit
);
9713 shndx_list
= ppool
+ j
* 4;
9714 /* PR 17531: file: 705e010d. */
9715 if (shndx_list
< ppool
)
9717 warn (_("Section index pool located before start of section\n"));
9722 printf (_(" [%3d] Signature: 0x%s Sections: "),
9723 i
, dwarf_vmatoa64 (signature_high
, signature_low
,
9724 buf
, sizeof (buf
)));
9727 if (shndx_list
>= limit
)
9729 warn (_("Section %s too small for shndx pool\n"),
9733 SAFE_BYTE_GET (shndx
, shndx_list
, 4, limit
);
9737 printf (" %d", shndx
);
9739 add_shndx_to_cu_tu_entry (shndx
);
9751 else if (version
== 2)
9754 unsigned int dw_sect
;
9755 unsigned char *ph
= phash
;
9756 unsigned char *pi
= pindex
;
9757 unsigned char *poffsets
= ppool
+ (size_t) ncols
* 4;
9758 unsigned char *psizes
= poffsets
+ (size_t) nused
* ncols
* 4;
9759 unsigned char *pend
= psizes
+ (size_t) nused
* ncols
* 4;
9760 bfd_boolean is_tu_index
;
9761 struct cu_tu_set
*this_set
= NULL
;
9763 unsigned char *prow
;
9765 is_tu_index
= strcmp (section
->name
, ".debug_tu_index") == 0;
9767 /* PR 17531: file: 0dd159bf.
9768 Check for integer overflow (can occur when size_t is 32-bit)
9769 with overlarge ncols or nused values. */
9771 && ((size_t) ncols
* 4 / 4 != ncols
9772 || (size_t) nused
* ncols
* 4 / ((size_t) ncols
* 4) != nused
9773 || poffsets
< ppool
|| poffsets
> limit
9774 || psizes
< poffsets
|| psizes
> limit
9775 || pend
< psizes
|| pend
> limit
))
9777 warn (_("Section %s too small for offset and size tables\n"),
9784 printf (_(" Offset table\n"));
9785 printf (" slot %-16s ",
9786 is_tu_index
? _("signature") : _("dwo_id"));
9793 tu_sets
= xcalloc2 (nused
, sizeof (struct cu_tu_set
));
9799 cu_sets
= xcalloc2 (nused
, sizeof (struct cu_tu_set
));
9806 for (j
= 0; j
< ncols
; j
++)
9808 SAFE_BYTE_GET (dw_sect
, ppool
+ j
* 4, 4, limit
);
9809 printf (" %8s", get_DW_SECT_short_name (dw_sect
));
9814 for (i
= 0; i
< nslots
; i
++)
9816 SAFE_BYTE_GET64 (ph
, &signature_high
, &signature_low
, limit
);
9818 SAFE_BYTE_GET (row
, pi
, 4, limit
);
9821 /* PR 17531: file: a05f6ab3. */
9824 warn (_("Row index (%u) is larger than number of used entries (%u)\n"),
9831 size_t num_copy
= sizeof (uint64_t);
9833 /* PR 23064: Beware of buffer overflow. */
9834 if (ph
+ num_copy
< limit
)
9835 memcpy (&this_set
[row
- 1].signature
, ph
, num_copy
);
9838 warn (_("Signature (%p) extends beyond end of space in section\n"), ph
);
9843 prow
= poffsets
+ (row
- 1) * ncols
* 4;
9844 /* PR 17531: file: b8ce60a8. */
9845 if (prow
< poffsets
|| prow
> limit
)
9847 warn (_("Row index (%u) * num columns (%u) > space remaining in section\n"),
9853 printf (_(" [%3d] 0x%s"),
9854 i
, dwarf_vmatoa64 (signature_high
, signature_low
,
9855 buf
, sizeof (buf
)));
9856 for (j
= 0; j
< ncols
; j
++)
9858 SAFE_BYTE_GET (val
, prow
+ j
* 4, 4, limit
);
9860 printf (" %8d", val
);
9863 SAFE_BYTE_GET (dw_sect
, ppool
+ j
* 4, 4, limit
);
9865 /* PR 17531: file: 10796eb3. */
9866 if (dw_sect
>= DW_SECT_MAX
)
9867 warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect
);
9869 this_set
[row
- 1].section_offsets
[dw_sect
] = val
;
9885 printf (_(" Size table\n"));
9886 printf (" slot %-16s ",
9887 is_tu_index
? _("signature") : _("dwo_id"));
9890 for (j
= 0; j
< ncols
; j
++)
9892 SAFE_BYTE_GET (val
, ppool
+ j
* 4, 4, limit
);
9894 printf (" %8s", get_DW_SECT_short_name (val
));
9900 for (i
= 0; i
< nslots
; i
++)
9902 SAFE_BYTE_GET64 (ph
, &signature_high
, &signature_low
, limit
);
9904 SAFE_BYTE_GET (row
, pi
, 4, limit
);
9907 prow
= psizes
+ (row
- 1) * ncols
* 4;
9910 printf (_(" [%3d] 0x%s"),
9911 i
, dwarf_vmatoa64 (signature_high
, signature_low
,
9912 buf
, sizeof (buf
)));
9914 for (j
= 0; j
< ncols
; j
++)
9916 SAFE_BYTE_GET (val
, prow
+ j
* 4, 4, limit
);
9918 printf (" %8d", val
);
9921 SAFE_BYTE_GET (dw_sect
, ppool
+ j
* 4, 4, limit
);
9922 if (dw_sect
>= DW_SECT_MAX
)
9923 warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect
);
9925 this_set
[row
- 1].section_sizes
[dw_sect
] = val
;
9937 else if (do_display
)
9938 printf (_(" Unsupported version (%d)\n"), version
);
9946 /* Load the CU and TU indexes if present. This will build a list of
9947 section sets that we can use to associate a .debug_info.dwo section
9948 with its associated .debug_abbrev.dwo section in a .dwp file. */
9951 load_cu_tu_indexes (void *file
)
9953 static int cu_tu_indexes_read
= -1; /* Tri-state variable. */
9955 /* If we have already loaded (or tried to load) the CU and TU indexes
9956 then do not bother to repeat the task. */
9957 if (cu_tu_indexes_read
== -1)
9959 cu_tu_indexes_read
= TRUE
;
9961 if (load_debug_section_with_follow (dwp_cu_index
, file
))
9962 if (! process_cu_tu_index (&debug_displays
[dwp_cu_index
].section
, 0))
9963 cu_tu_indexes_read
= FALSE
;
9965 if (load_debug_section_with_follow (dwp_tu_index
, file
))
9966 if (! process_cu_tu_index (&debug_displays
[dwp_tu_index
].section
, 0))
9967 cu_tu_indexes_read
= FALSE
;
9970 return (bfd_boolean
) cu_tu_indexes_read
;
9973 /* Find the set of sections that includes section SHNDX. */
9976 find_cu_tu_set (void *file
, unsigned int shndx
)
9980 if (! load_cu_tu_indexes (file
))
9983 /* Find SHNDX in the shndx pool. */
9984 for (i
= 0; i
< shndx_pool_used
; i
++)
9985 if (shndx_pool
[i
] == shndx
)
9988 if (i
>= shndx_pool_used
)
9991 /* Now backup to find the first entry in the set. */
9992 while (i
> 0 && shndx_pool
[i
- 1] != 0)
9995 return shndx_pool
+ i
;
9998 /* Display a .debug_cu_index or .debug_tu_index section. */
10001 display_cu_index (struct dwarf_section
*section
, void *file ATTRIBUTE_UNUSED
)
10003 return process_cu_tu_index (section
, 1);
10007 display_debug_not_supported (struct dwarf_section
*section
,
10008 void *file ATTRIBUTE_UNUSED
)
10010 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
10016 /* Like malloc, but takes two parameters like calloc.
10017 Verifies that the first parameter is not too large.
10018 Note: does *not* initialise the allocated memory to zero. */
10021 cmalloc (size_t nmemb
, size_t size
)
10023 /* Check for overflow. */
10024 if (nmemb
>= ~(size_t) 0 / size
)
10027 return xmalloc (nmemb
* size
);
10030 /* Like xmalloc, but takes two parameters like calloc.
10031 Verifies that the first parameter is not too large.
10032 Note: does *not* initialise the allocated memory to zero. */
10035 xcmalloc (size_t nmemb
, size_t size
)
10037 /* Check for overflow. */
10038 if (nmemb
>= ~(size_t) 0 / size
)
10041 _("Attempt to allocate an array with an excessive number of elements: 0x%lx\n"),
10046 return xmalloc (nmemb
* size
);
10049 /* Like xrealloc, but takes three parameters.
10050 Verifies that the second parameter is not too large.
10051 Note: does *not* initialise any new memory to zero. */
10054 xcrealloc (void *ptr
, size_t nmemb
, size_t size
)
10056 /* Check for overflow. */
10057 if (nmemb
>= ~(size_t) 0 / size
)
10059 error (_("Attempt to re-allocate an array with an excessive number of elements: 0x%lx\n"),
10064 return xrealloc (ptr
, nmemb
* size
);
10067 /* Like xcalloc, but verifies that the first parameter is not too large. */
10070 xcalloc2 (size_t nmemb
, size_t size
)
10072 /* Check for overflow. */
10073 if (nmemb
>= ~(size_t) 0 / size
)
10075 error (_("Attempt to allocate a zero'ed array with an excessive number of elements: 0x%lx\n"),
10080 return xcalloc (nmemb
, size
);
10083 static unsigned long
10084 calc_gnu_debuglink_crc32 (unsigned long crc
,
10085 const unsigned char * buf
,
10088 static const unsigned long crc32_table
[256] =
10090 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
10091 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
10092 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
10093 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
10094 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
10095 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
10096 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
10097 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
10098 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
10099 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
10100 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
10101 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
10102 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
10103 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
10104 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
10105 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
10106 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
10107 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
10108 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
10109 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
10110 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
10111 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
10112 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
10113 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
10114 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
10115 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
10116 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
10117 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
10118 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
10119 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
10120 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
10121 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
10122 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
10123 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
10124 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
10125 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
10126 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
10127 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
10128 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
10129 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
10130 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
10131 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
10132 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
10133 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
10134 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
10135 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
10136 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
10137 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
10138 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
10139 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
10140 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
10143 const unsigned char *end
;
10145 crc
= ~crc
& 0xffffffff;
10146 for (end
= buf
+ len
; buf
< end
; ++ buf
)
10147 crc
= crc32_table
[(crc
^ *buf
) & 0xff] ^ (crc
>> 8);
10148 return ~crc
& 0xffffffff;
10151 typedef bfd_boolean (* check_func_type
) (const char *, void *);
10152 typedef const char * (* parse_func_type
) (struct dwarf_section
*, void *);
10155 check_gnu_debuglink (const char * pathname
, void * crc_pointer
)
10157 static unsigned char buffer
[8 * 1024];
10159 bfd_size_type count
;
10160 unsigned long crc
= 0;
10163 sep_data
= open_debug_file (pathname
);
10164 if (sep_data
== NULL
)
10167 /* Yes - we are opening the file twice... */
10168 f
= fopen (pathname
, "rb");
10171 /* Paranoia: This should never happen. */
10172 close_debug_file (sep_data
);
10173 warn (_("Unable to reopen separate debug info file: %s\n"), pathname
);
10177 while ((count
= fread (buffer
, 1, sizeof (buffer
), f
)) > 0)
10178 crc
= calc_gnu_debuglink_crc32 (crc
, buffer
, count
);
10182 if (crc
!= * (unsigned long *) crc_pointer
)
10184 close_debug_file (sep_data
);
10185 warn (_("Separate debug info file %s found, but CRC does not match - ignoring\n"),
10193 static const char *
10194 parse_gnu_debuglink (struct dwarf_section
* section
, void * data
)
10197 unsigned int crc_offset
;
10198 unsigned long * crc32
= (unsigned long *) data
;
10200 /* The name is first.
10201 The CRC value is stored after the filename, aligned up to 4 bytes. */
10202 name
= (const char *) section
->start
;
10205 crc_offset
= strnlen (name
, section
->size
) + 1;
10206 crc_offset
= (crc_offset
+ 3) & ~3;
10207 if (crc_offset
+ 4 > section
->size
)
10210 * crc32
= byte_get (section
->start
+ crc_offset
, 4);
10215 check_gnu_debugaltlink (const char * filename
, void * data ATTRIBUTE_UNUSED
)
10217 void * sep_data
= open_debug_file (filename
);
10219 if (sep_data
== NULL
)
10222 /* FIXME: We should now extract the build-id in the separate file
10228 typedef struct build_id_data
10231 const unsigned char * data
;
10234 static const char *
10235 parse_gnu_debugaltlink (struct dwarf_section
* section
, void * data
)
10238 bfd_size_type namelen
;
10239 bfd_size_type id_len
;
10240 Build_id_data
* build_id_data
;
10242 /* The name is first.
10243 The build-id follows immediately, with no padding, up to the section's end. */
10245 name
= (const char *) section
->start
;
10246 namelen
= strnlen (name
, section
->size
) + 1;
10247 if (namelen
>= section
->size
)
10250 id_len
= section
->size
- namelen
;
10254 build_id_data
= calloc (1, sizeof * build_id_data
);
10255 if (build_id_data
== NULL
)
10258 build_id_data
->len
= id_len
;
10259 build_id_data
->data
= section
->start
+ namelen
;
10261 * (Build_id_data
**) data
= build_id_data
;
10267 add_separate_debug_file (const char * filename
, void * handle
)
10269 separate_info
* i
= xmalloc (sizeof * i
);
10271 i
->filename
= filename
;
10272 i
->handle
= handle
;
10273 i
->next
= first_separate_info
;
10274 first_separate_info
= i
;
10278 load_separate_debug_info (const char * main_filename
,
10279 struct dwarf_section
* xlink
,
10280 parse_func_type parse_func
,
10281 check_func_type check_func
,
10284 const char * separate_filename
;
10285 char * debug_filename
;
10287 size_t canon_dirlen
;
10290 if ((separate_filename
= parse_func (xlink
, func_data
)) == NULL
)
10292 warn (_("Corrupt debuglink section: %s\n"),
10293 xlink
->name
? xlink
->name
: xlink
->uncompressed_name
);
10297 /* Attempt to locate the separate file.
10298 This should duplicate the logic in bfd/opncls.c:find_separate_debug_file(). */
10300 canon_dir
= lrealpath (main_filename
);
10302 for (canon_dirlen
= strlen (canon_dir
); canon_dirlen
> 0; canon_dirlen
--)
10303 if (IS_DIR_SEPARATOR (canon_dir
[canon_dirlen
- 1]))
10305 canon_dir
[canon_dirlen
] = '\0';
10308 #define DEBUGDIR "/lib/debug"
10310 #ifndef EXTRA_DEBUG_ROOT1
10311 #define EXTRA_DEBUG_ROOT1 "/usr/lib/debug"
10313 #ifndef EXTRA_DEBUG_ROOT2
10314 #define EXTRA_DEBUG_ROOT2 "/usr/lib/debug/usr"
10317 debug_filename
= (char *) malloc (strlen (DEBUGDIR
) + 1
10319 + strlen (".debug/")
10320 #ifdef EXTRA_DEBUG_ROOT1
10321 + strlen (EXTRA_DEBUG_ROOT1
)
10323 #ifdef EXTRA_DEBUG_ROOT2
10324 + strlen (EXTRA_DEBUG_ROOT2
)
10326 + strlen (separate_filename
)
10328 if (debug_filename
== NULL
)
10330 warn (_("Out of memory"));
10335 /* First try in the current directory. */
10336 sprintf (debug_filename
, "%s", separate_filename
);
10337 if (check_func (debug_filename
, func_data
))
10340 /* Then try in a subdirectory called .debug. */
10341 sprintf (debug_filename
, ".debug/%s", separate_filename
);
10342 if (check_func (debug_filename
, func_data
))
10345 /* Then try in the same directory as the original file. */
10346 sprintf (debug_filename
, "%s%s", canon_dir
, separate_filename
);
10347 if (check_func (debug_filename
, func_data
))
10350 /* And the .debug subdirectory of that directory. */
10351 sprintf (debug_filename
, "%s.debug/%s", canon_dir
, separate_filename
);
10352 if (check_func (debug_filename
, func_data
))
10355 #ifdef EXTRA_DEBUG_ROOT1
10356 /* Try the first extra debug file root. */
10357 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT1
, separate_filename
);
10358 if (check_func (debug_filename
, func_data
))
10361 /* Try the first extra debug file root. */
10362 sprintf (debug_filename
, "%s/%s/%s", EXTRA_DEBUG_ROOT1
, canon_dir
, separate_filename
);
10363 if (check_func (debug_filename
, func_data
))
10367 #ifdef EXTRA_DEBUG_ROOT2
10368 /* Try the second extra debug file root. */
10369 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT2
, separate_filename
);
10370 if (check_func (debug_filename
, func_data
))
10374 /* Then try in the global debug_filename directory. */
10375 strcpy (debug_filename
, DEBUGDIR
);
10376 dirlen
= strlen (DEBUGDIR
) - 1;
10377 if (dirlen
> 0 && DEBUGDIR
[dirlen
] != '/')
10378 strcat (debug_filename
, "/");
10379 strcat (debug_filename
, (const char *) separate_filename
);
10381 if (check_func (debug_filename
, func_data
))
10384 /* Failed to find the file. */
10385 warn (_("could not find separate debug file '%s'\n"), separate_filename
);
10386 warn (_("tried: %s\n"), debug_filename
);
10388 #ifdef EXTRA_DEBUG_ROOT2
10389 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT2
, separate_filename
);
10390 warn (_("tried: %s\n"), debug_filename
);
10393 #ifdef EXTRA_DEBUG_ROOT1
10394 sprintf (debug_filename
, "%s/%s/%s", EXTRA_DEBUG_ROOT1
, canon_dir
, separate_filename
);
10395 warn (_("tried: %s\n"), debug_filename
);
10397 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT1
, separate_filename
);
10398 warn (_("tried: %s\n"), debug_filename
);
10401 sprintf (debug_filename
, "%s.debug/%s", canon_dir
, separate_filename
);
10402 warn (_("tried: %s\n"), debug_filename
);
10404 sprintf (debug_filename
, "%s%s", canon_dir
, separate_filename
);
10405 warn (_("tried: %s\n"), debug_filename
);
10407 sprintf (debug_filename
, ".debug/%s", separate_filename
);
10408 warn (_("tried: %s\n"), debug_filename
);
10410 sprintf (debug_filename
, "%s", separate_filename
);
10411 warn (_("tried: %s\n"), debug_filename
);
10414 free (debug_filename
);
10420 void * debug_handle
;
10422 /* Now open the file.... */
10423 if ((debug_handle
= open_debug_file (debug_filename
)) == NULL
)
10425 warn (_("failed to open separate debug file: %s\n"), debug_filename
);
10426 free (debug_filename
);
10430 /* FIXME: We do not check to see if there are any other separate debug info
10431 files that would also match. */
10433 printf (_("%s: Found separate debug info file: %s\n\n"), main_filename
, debug_filename
);
10434 add_separate_debug_file (debug_filename
, debug_handle
);
10436 /* Do not free debug_filename - it might be referenced inside
10437 the structure returned by open_debug_file(). */
10438 return debug_handle
;
10441 /* Attempt to load a separate dwarf object file. */
10444 load_dwo_file (const char * main_filename
, const char * name
, const char * dir
, const char * id ATTRIBUTE_UNUSED
)
10446 char * separate_filename
;
10447 void * separate_handle
;
10449 /* FIXME: Skip adding / if dwo_dir ends in /. */
10450 separate_filename
= concat (dir
, "/", name
, NULL
);
10451 if (separate_filename
== NULL
)
10453 warn (_("Out of memory allocating dwo filename\n"));
10457 if ((separate_handle
= open_debug_file (separate_filename
)) == NULL
)
10459 warn (_("Unable to load dwo file: %s\n"), separate_filename
);
10460 free (separate_filename
);
10464 /* FIXME: We should check the dwo_id. */
10466 printf (_("%s: Found separate debug object file: %s\n\n"), main_filename
, separate_filename
);
10467 add_separate_debug_file (separate_filename
, separate_handle
);
10468 /* Note - separate_filename will be freed in free_debug_memory(). */
10469 return separate_handle
;
10472 /* Load the separate debug info file(s) attached to FILE, if any exist.
10473 Returns TRUE if any were found, FALSE otherwise.
10474 If TRUE is returned then the linked list starting at first_separate_info
10475 will be populated with open file handles. */
10478 load_separate_debug_files (void * file
, const char * filename
)
10480 /* Skip this operation if we are not interested in debug links. */
10481 if (! do_follow_links
&& ! do_debug_links
)
10484 /* See if there are any dwo links. */
10485 if (load_debug_section (str
, file
)
10486 && load_debug_section (abbrev
, file
)
10487 && load_debug_section (info
, file
))
10491 if (process_debug_info (& debug_displays
[info
].section
, file
, abbrev
, TRUE
, FALSE
))
10493 bfd_boolean introduced
= FALSE
;
10495 const char * dir
= NULL
;
10496 const char * id
= NULL
;
10498 for (dwinfo
= first_dwo_info
; dwinfo
!= NULL
; dwinfo
= dwinfo
->next
)
10500 switch (dwinfo
->type
)
10503 if (do_debug_links
)
10507 printf (_("The %s section contains link(s) to dwo file(s):\n\n"),
10508 debug_displays
[info
].section
.uncompressed_name
);
10512 printf (_(" Name: %s\n"), dwinfo
->value
);
10513 printf (_(" Directory: %s\n"), dir
? dir
: _("<not-found>"));
10515 display_data (printf (_(" ID: ")), (unsigned char *) id
, 8);
10517 printf (_(" ID: <unknown>\n"));
10521 if (do_follow_links
)
10522 load_dwo_file (filename
, dwinfo
->value
, dir
, id
);
10526 dir
= dwinfo
->value
;
10530 id
= dwinfo
->value
;
10534 error (_("Unexpected DWO INFO type"));
10541 if (! do_follow_links
)
10542 /* The other debug links will be displayed by display_debug_links()
10543 so we do not need to do any further processing here. */
10546 /* FIXME: We do not check for the presence of both link sections in the same file. */
10547 /* FIXME: We do not check the separate debug info file to see if it too contains debuglinks. */
10548 /* FIXME: We do not check for the presence of multiple, same-name debuglink sections. */
10549 /* FIXME: We do not check for the presence of a dwo link as well as a debuglink. */
10551 if (load_debug_section (gnu_debugaltlink
, file
))
10553 Build_id_data
* build_id_data
;
10555 load_separate_debug_info (filename
,
10556 & debug_displays
[gnu_debugaltlink
].section
,
10557 parse_gnu_debugaltlink
,
10558 check_gnu_debugaltlink
,
10562 if (load_debug_section (gnu_debuglink
, file
))
10564 unsigned long crc32
;
10566 load_separate_debug_info (filename
,
10567 & debug_displays
[gnu_debuglink
].section
,
10568 parse_gnu_debuglink
,
10569 check_gnu_debuglink
,
10573 if (first_separate_info
!= NULL
)
10576 do_follow_links
= 0;
10581 free_debug_memory (void)
10587 for (i
= 0; i
< max
; i
++)
10588 free_debug_section ((enum dwarf_section_display_enum
) i
);
10590 if (debug_information
!= NULL
)
10592 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
)
10594 for (i
= 0; i
< num_debug_info_entries
; i
++)
10596 if (!debug_information
[i
].max_loc_offsets
)
10598 free (debug_information
[i
].loc_offsets
);
10599 free (debug_information
[i
].have_frame_base
);
10601 if (!debug_information
[i
].max_range_lists
)
10602 free (debug_information
[i
].range_lists
);
10605 free (debug_information
);
10606 debug_information
= NULL
;
10607 alloc_num_debug_info_entries
= num_debug_info_entries
= 0;
10611 separate_info
* next
;
10613 for (d
= first_separate_info
; d
!= NULL
; d
= next
)
10615 close_debug_file (d
->handle
);
10616 free ((void *) d
->filename
);
10620 first_separate_info
= NULL
;
10626 dwarf_select_sections_by_names (const char *names
)
10630 const char * option
;
10634 debug_dump_long_opts
;
10636 static const debug_dump_long_opts opts_table
[] =
10638 /* Please keep this table alpha- sorted. */
10639 { "Ranges", & do_debug_ranges
, 1 },
10640 { "abbrev", & do_debug_abbrevs
, 1 },
10641 { "addr", & do_debug_addr
, 1 },
10642 { "aranges", & do_debug_aranges
, 1 },
10643 { "cu_index", & do_debug_cu_index
, 1 },
10644 { "decodedline", & do_debug_lines
, FLAG_DEBUG_LINES_DECODED
},
10645 { "follow-links", & do_follow_links
, 1 },
10646 { "frames", & do_debug_frames
, 1 },
10647 { "frames-interp", & do_debug_frames_interp
, 1 },
10648 /* The special .gdb_index section. */
10649 { "gdb_index", & do_gdb_index
, 1 },
10650 { "info", & do_debug_info
, 1 },
10651 { "line", & do_debug_lines
, FLAG_DEBUG_LINES_RAW
}, /* For backwards compatibility. */
10652 { "links", & do_debug_links
, 1 },
10653 { "loc", & do_debug_loc
, 1 },
10654 { "macro", & do_debug_macinfo
, 1 },
10655 { "pubnames", & do_debug_pubnames
, 1 },
10656 { "pubtypes", & do_debug_pubtypes
, 1 },
10657 /* This entry is for compatibility
10658 with earlier versions of readelf. */
10659 { "ranges", & do_debug_aranges
, 1 },
10660 { "rawline", & do_debug_lines
, FLAG_DEBUG_LINES_RAW
},
10661 { "str", & do_debug_str
, 1 },
10662 /* These trace_* sections are used by Itanium VMS. */
10663 { "trace_abbrev", & do_trace_abbrevs
, 1 },
10664 { "trace_aranges", & do_trace_aranges
, 1 },
10665 { "trace_info", & do_trace_info
, 1 },
10674 const debug_dump_long_opts
* entry
;
10676 for (entry
= opts_table
; entry
->option
; entry
++)
10678 size_t len
= strlen (entry
->option
);
10680 if (strncmp (p
, entry
->option
, len
) == 0
10681 && (p
[len
] == ',' || p
[len
] == '\0'))
10683 * entry
->variable
|= entry
->val
;
10685 /* The --debug-dump=frames-interp option also
10686 enables the --debug-dump=frames option. */
10687 if (do_debug_frames_interp
)
10688 do_debug_frames
= 1;
10695 if (entry
->option
== NULL
)
10697 warn (_("Unrecognized debug option '%s'\n"), p
);
10698 p
= strchr (p
, ',');
10709 dwarf_select_sections_by_letters (const char *letters
)
10711 unsigned int lindex
= 0;
10713 while (letters
[lindex
])
10714 switch (letters
[lindex
++])
10716 case 'A': do_debug_addr
= 1; break;
10717 case 'a': do_debug_abbrevs
= 1; break;
10718 case 'c': do_debug_cu_index
= 1; break;
10719 case 'F': do_debug_frames_interp
= 1; /* Fall through. */
10720 case 'f': do_debug_frames
= 1; break;
10721 case 'g': do_gdb_index
= 1; break;
10722 case 'i': do_debug_info
= 1; break;
10723 case 'K': do_follow_links
= 1; break;
10724 case 'k': do_debug_links
= 1; break;
10725 case 'l': do_debug_lines
|= FLAG_DEBUG_LINES_RAW
; break;
10726 case 'L': do_debug_lines
|= FLAG_DEBUG_LINES_DECODED
; break;
10727 case 'm': do_debug_macinfo
= 1; break;
10728 case 'o': do_debug_loc
= 1; break;
10729 case 'p': do_debug_pubnames
= 1; break;
10730 case 'R': do_debug_ranges
= 1; break;
10731 case 'r': do_debug_aranges
= 1; break;
10732 case 's': do_debug_str
= 1; break;
10733 case 'T': do_trace_aranges
= 1; break;
10734 case 't': do_debug_pubtypes
= 1; break;
10735 case 'U': do_trace_info
= 1; break;
10736 case 'u': do_trace_abbrevs
= 1; break;
10739 warn (_("Unrecognized debug option '%s'\n"), letters
);
10745 dwarf_select_sections_all (void)
10748 do_debug_abbrevs
= 1;
10749 do_debug_lines
= FLAG_DEBUG_LINES_RAW
;
10750 do_debug_pubnames
= 1;
10751 do_debug_pubtypes
= 1;
10752 do_debug_aranges
= 1;
10753 do_debug_ranges
= 1;
10754 do_debug_frames
= 1;
10755 do_debug_macinfo
= 1;
10760 do_trace_abbrevs
= 1;
10761 do_trace_aranges
= 1;
10763 do_debug_cu_index
= 1;
10764 do_follow_links
= 1;
10765 do_debug_links
= 1;
10768 #define NO_ABBREVS NULL, NULL, NULL, 0, 0, 0, NULL, 0, NULL
10769 #define ABBREV(N) NULL, NULL, NULL, 0, 0, N, NULL, 0, NULL
10771 /* N.B. The order here must match the order in section_display_enum. */
10773 struct dwarf_section_display debug_displays
[] =
10775 { { ".debug_abbrev", ".zdebug_abbrev", NO_ABBREVS
}, display_debug_abbrev
, &do_debug_abbrevs
, FALSE
},
10776 { { ".debug_aranges", ".zdebug_aranges", NO_ABBREVS
}, display_debug_aranges
, &do_debug_aranges
, TRUE
},
10777 { { ".debug_frame", ".zdebug_frame", NO_ABBREVS
}, display_debug_frames
, &do_debug_frames
, TRUE
},
10778 { { ".debug_info", ".zdebug_info", ABBREV (abbrev
)}, display_debug_info
, &do_debug_info
, TRUE
},
10779 { { ".debug_line", ".zdebug_line", NO_ABBREVS
}, display_debug_lines
, &do_debug_lines
, TRUE
},
10780 { { ".debug_pubnames", ".zdebug_pubnames", NO_ABBREVS
}, display_debug_pubnames
, &do_debug_pubnames
, FALSE
},
10781 { { ".debug_gnu_pubnames", ".zdebug_gnu_pubnames", NO_ABBREVS
}, display_debug_gnu_pubnames
, &do_debug_pubnames
, FALSE
},
10782 { { ".eh_frame", "", NO_ABBREVS
}, display_debug_frames
, &do_debug_frames
, TRUE
},
10783 { { ".debug_macinfo", ".zdebug_macinfo", NO_ABBREVS
}, display_debug_macinfo
, &do_debug_macinfo
, FALSE
},
10784 { { ".debug_macro", ".zdebug_macro", NO_ABBREVS
}, display_debug_macro
, &do_debug_macinfo
, TRUE
},
10785 { { ".debug_str", ".zdebug_str", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, FALSE
},
10786 { { ".debug_line_str", ".zdebug_line_str", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, FALSE
},
10787 { { ".debug_loc", ".zdebug_loc", NO_ABBREVS
}, display_debug_loc
, &do_debug_loc
, TRUE
},
10788 { { ".debug_loclists", ".zdebug_loclists", NO_ABBREVS
}, display_debug_loc
, &do_debug_loc
, TRUE
},
10789 { { ".debug_pubtypes", ".zdebug_pubtypes", NO_ABBREVS
}, display_debug_pubnames
, &do_debug_pubtypes
, FALSE
},
10790 { { ".debug_gnu_pubtypes", ".zdebug_gnu_pubtypes", NO_ABBREVS
}, display_debug_gnu_pubnames
, &do_debug_pubtypes
, FALSE
},
10791 { { ".debug_ranges", ".zdebug_ranges", NO_ABBREVS
}, display_debug_ranges
, &do_debug_ranges
, TRUE
},
10792 { { ".debug_rnglists", ".zdebug_rnglists", NO_ABBREVS
}, display_debug_ranges
, &do_debug_ranges
, TRUE
},
10793 { { ".debug_static_func", ".zdebug_static_func", NO_ABBREVS
}, display_debug_not_supported
, NULL
, FALSE
},
10794 { { ".debug_static_vars", ".zdebug_static_vars", NO_ABBREVS
}, display_debug_not_supported
, NULL
, FALSE
},
10795 { { ".debug_types", ".zdebug_types", ABBREV (abbrev
) }, display_debug_types
, &do_debug_info
, TRUE
},
10796 { { ".debug_weaknames", ".zdebug_weaknames", NO_ABBREVS
}, display_debug_not_supported
, NULL
, FALSE
},
10797 { { ".gdb_index", "", NO_ABBREVS
}, display_gdb_index
, &do_gdb_index
, FALSE
},
10798 { { ".debug_names", "", NO_ABBREVS
}, display_debug_names
, &do_gdb_index
, FALSE
},
10799 { { ".trace_info", "", ABBREV (trace_abbrev
) }, display_trace_info
, &do_trace_info
, TRUE
},
10800 { { ".trace_abbrev", "", NO_ABBREVS
}, display_debug_abbrev
, &do_trace_abbrevs
, FALSE
},
10801 { { ".trace_aranges", "", NO_ABBREVS
}, display_debug_aranges
, &do_trace_aranges
, FALSE
},
10802 { { ".debug_info.dwo", ".zdebug_info.dwo", ABBREV (abbrev_dwo
) }, display_debug_info
, &do_debug_info
, TRUE
},
10803 { { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo", NO_ABBREVS
}, display_debug_abbrev
, &do_debug_abbrevs
, FALSE
},
10804 { { ".debug_types.dwo", ".zdebug_types.dwo", ABBREV (abbrev_dwo
) }, display_debug_types
, &do_debug_info
, TRUE
},
10805 { { ".debug_line.dwo", ".zdebug_line.dwo", NO_ABBREVS
}, display_debug_lines
, &do_debug_lines
, TRUE
},
10806 { { ".debug_loc.dwo", ".zdebug_loc.dwo", NO_ABBREVS
}, display_debug_loc
, &do_debug_loc
, TRUE
},
10807 { { ".debug_macro.dwo", ".zdebug_macro.dwo", NO_ABBREVS
}, display_debug_macro
, &do_debug_macinfo
, TRUE
},
10808 { { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo", NO_ABBREVS
}, display_debug_macinfo
, &do_debug_macinfo
, FALSE
},
10809 { { ".debug_str.dwo", ".zdebug_str.dwo", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, TRUE
},
10810 { { ".debug_str_offsets", ".zdebug_str_offsets", NO_ABBREVS
}, display_debug_str_offsets
, NULL
, FALSE
},
10811 { { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo", NO_ABBREVS
}, display_debug_str_offsets
, NULL
, FALSE
},
10812 { { ".debug_addr", ".zdebug_addr", NO_ABBREVS
}, display_debug_addr
, &do_debug_addr
, TRUE
},
10813 { { ".debug_cu_index", "", NO_ABBREVS
}, display_cu_index
, &do_debug_cu_index
, FALSE
},
10814 { { ".debug_tu_index", "", NO_ABBREVS
}, display_cu_index
, &do_debug_cu_index
, FALSE
},
10815 { { ".gnu_debuglink", "", NO_ABBREVS
}, display_debug_links
, &do_debug_links
, FALSE
},
10816 { { ".gnu_debugaltlink", "", NO_ABBREVS
}, display_debug_links
, &do_debug_links
, FALSE
},
10817 /* Separate debug info files can containt their own .debug_str section,
10818 and this might be in *addition* to a .debug_str section already present
10819 in the main file. Hence we need to have two entries for .debug_str. */
10820 { { ".debug_str", ".zdebug_str", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, FALSE
},
10823 /* A static assertion. */
10824 extern int debug_displays_assert
[ARRAY_SIZE (debug_displays
) == max
? 1 : -1];