1 /* dwarf.c -- display DWARF contents of a BFD binary file
2 Copyright (C) 2005-2018 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"
36 #define MAX(a, b) ((a) > (b) ? (a) : (b))
37 #define MIN(a, b) ((a) < (b) ? (a) : (b))
39 static const char *regname (unsigned int regno
, int row
);
41 static int have_frame_base
;
42 static int need_base_address
;
44 static unsigned int num_debug_info_entries
= 0;
45 static unsigned int alloc_num_debug_info_entries
= 0;
46 static debug_info
*debug_information
= NULL
;
47 /* Special value for num_debug_info_entries to indicate
48 that the .debug_info section could not be loaded/parsed. */
49 #define DEBUG_INFO_UNAVAILABLE (unsigned int) -1
51 static const char * dwo_name
;
52 static const char * dwo_dir
;
53 static const unsigned char * dwo_id
;
54 static bfd_size_type dwo_id_len
;
55 static bfd_boolean need_dwo_info
;
57 unsigned int eh_addr_size
;
62 int do_debug_pubnames
;
63 int do_debug_pubtypes
;
67 int do_debug_frames_interp
;
76 int do_debug_cu_index
;
81 int dwarf_cutoff_level
= -1;
82 unsigned long dwarf_start_die
;
86 /* Convenient constant, to avoid having to cast -1 to dwarf_vma when
87 testing whether e.g. a locview list is present. */
88 static const dwarf_vma vm1
= -1;
90 /* Collection of CU/TU section sets from .debug_cu_index and .debug_tu_index
91 sections. For version 1 package files, each set is stored in SHNDX_POOL
92 as a zero-terminated list of section indexes comprising one set of debug
93 sections from a .dwo file. */
95 static unsigned int *shndx_pool
= NULL
;
96 static unsigned int shndx_pool_size
= 0;
97 static unsigned int shndx_pool_used
= 0;
99 /* Pointer to a separate file containing extra debug information. */
100 static void * separate_debug_file
= NULL
;
101 static const char * separate_debug_filename
= NULL
;
103 /* For version 2 package files, each set contains an array of section offsets
104 and an array of section sizes, giving the offset and size of the
105 contribution from a CU or TU within one of the debug sections.
106 When displaying debug info from a package file, we need to use these
107 tables to locate the corresponding contributions to each section. */
112 dwarf_vma section_offsets
[DW_SECT_MAX
];
113 size_t section_sizes
[DW_SECT_MAX
];
116 static int cu_count
= 0;
117 static int tu_count
= 0;
118 static struct cu_tu_set
*cu_sets
= NULL
;
119 static struct cu_tu_set
*tu_sets
= NULL
;
121 static bfd_boolean
load_cu_tu_indexes (void *);
123 /* Values for do_debug_lines. */
124 #define FLAG_DEBUG_LINES_RAW 1
125 #define FLAG_DEBUG_LINES_DECODED 2
128 size_of_encoded_value (int encoding
)
130 switch (encoding
& 0x7)
133 case 0: return eh_addr_size
;
141 get_encoded_value (unsigned char **pdata
,
143 struct dwarf_section
*section
,
146 unsigned char * data
= * pdata
;
147 unsigned int size
= size_of_encoded_value (encoding
);
150 if (data
+ size
>= end
)
152 warn (_("Encoded value extends past end of section\n"));
157 /* PR 17512: file: 002-829853-0.004. */
160 warn (_("Encoded size of %d is too large to read\n"), size
);
165 /* PR 17512: file: 1085-5603-0.004. */
168 warn (_("Encoded size of 0 is too small to read\n"));
173 if (encoding
& DW_EH_PE_signed
)
174 val
= byte_get_signed (data
, size
);
176 val
= byte_get (data
, size
);
178 if ((encoding
& 0x70) == DW_EH_PE_pcrel
)
179 val
+= section
->address
+ (data
- section
->start
);
181 * pdata
= data
+ size
;
185 #if defined HAVE_LONG_LONG && SIZEOF_LONG_LONG > SIZEOF_LONG
187 # define DWARF_VMA_FMT "ll"
188 # define DWARF_VMA_FMT_LONG "%16.16llx"
190 # define DWARF_VMA_FMT "I64"
191 # define DWARF_VMA_FMT_LONG "%016I64x"
194 # define DWARF_VMA_FMT "l"
195 # define DWARF_VMA_FMT_LONG "%16.16lx"
198 /* Convert a dwarf vma value into a string. Returns a pointer to a static
199 buffer containing the converted VALUE. The value is converted according
200 to the printf formating character FMTCH. If NUM_BYTES is non-zero then
201 it specifies the maximum number of bytes to be displayed in the converted
202 value and FMTCH is ignored - hex is always used. */
205 dwarf_vmatoa_1 (const char *fmtch
, dwarf_vma value
, unsigned num_bytes
)
207 /* As dwarf_vmatoa is used more then once in a printf call
208 for output, we are cycling through an fixed array of pointers
209 for return address. */
210 static int buf_pos
= 0;
211 static struct dwarf_vmatoa_buf
217 ret
= buf
[buf_pos
++].place
;
218 buf_pos
%= ARRAY_SIZE (buf
);
222 /* Printf does not have a way of specifying a maximum field width for an
223 integer value, so we print the full value into a buffer and then select
224 the precision we need. */
225 snprintf (ret
, sizeof (buf
[0].place
), DWARF_VMA_FMT_LONG
, value
);
228 return ret
+ (16 - 2 * num_bytes
);
235 sprintf (fmt
, "%%%s%s", DWARF_VMA_FMT
, fmtch
);
237 sprintf (fmt
, "%%%s", DWARF_VMA_FMT
);
238 snprintf (ret
, sizeof (buf
[0].place
), fmt
, value
);
243 static inline const char *
244 dwarf_vmatoa (const char * fmtch
, dwarf_vma value
)
246 return dwarf_vmatoa_1 (fmtch
, value
, 0);
249 /* Print a dwarf_vma value (typically an address, offset or length) in
250 hexadecimal format, followed by a space. The length of the VALUE (and
251 hence the precision displayed) is determined by the NUM_BYTES parameter. */
254 print_dwarf_vma (dwarf_vma value
, unsigned num_bytes
)
256 printf ("%s ", dwarf_vmatoa_1 (NULL
, value
, num_bytes
));
259 /* Print a view number in hexadecimal value, with the same width
260 print_dwarf_vma would have printed it with the same num_bytes.
261 Print blanks for zero view, unless force is nonzero. */
264 print_dwarf_view (dwarf_vma value
, unsigned num_bytes
, int force
)
272 assert (value
== (unsigned long) value
);
274 printf ("v%0*lx ", len
- 1, (unsigned long) value
);
276 printf ("%*s", len
+ 1, "");
279 /* Format a 64-bit value, given as two 32-bit values, in hex.
280 For reentrancy, this uses a buffer provided by the caller. */
283 dwarf_vmatoa64 (dwarf_vma hvalue
, dwarf_vma lvalue
, char *buf
,
284 unsigned int buf_len
)
289 snprintf (buf
, buf_len
, "%" DWARF_VMA_FMT
"x", lvalue
);
292 len
= snprintf (buf
, buf_len
, "%" DWARF_VMA_FMT
"x", hvalue
);
293 snprintf (buf
+ len
, buf_len
- len
,
294 "%08" DWARF_VMA_FMT
"x", lvalue
);
300 /* Read in a LEB128 encoded value starting at address DATA.
301 If SIGN is true, return a signed LEB128 value.
302 If LENGTH_RETURN is not NULL, return in it the number of bytes read.
303 No bytes will be read at address END or beyond. */
306 read_leb128 (unsigned char *data
,
307 unsigned int *length_return
,
309 const unsigned char * const end
)
311 dwarf_vma result
= 0;
312 unsigned int num_read
= 0;
313 unsigned int shift
= 0;
314 unsigned char byte
= 0;
321 result
|= ((dwarf_vma
) (byte
& 0x7f)) << shift
;
324 if ((byte
& 0x80) == 0)
327 /* PR 17512: file: 0ca183b8.
328 FIXME: Should we signal this error somehow ? */
329 if (shift
>= sizeof (result
) * 8)
333 if (length_return
!= NULL
)
334 *length_return
= num_read
;
336 if (sign
&& (shift
< 8 * sizeof (result
)) && (byte
& 0x40))
337 result
|= -((dwarf_vma
) 1 << shift
);
342 /* Create a signed version to avoid painful typecasts. */
343 static inline dwarf_signed_vma
344 read_sleb128 (unsigned char * data
,
345 unsigned int * length_return
,
346 const unsigned char * const end
)
348 return (dwarf_signed_vma
) read_leb128 (data
, length_return
, TRUE
, end
);
351 static inline dwarf_vma
352 read_uleb128 (unsigned char * data
,
353 unsigned int * length_return
,
354 const unsigned char * const end
)
356 return read_leb128 (data
, length_return
, FALSE
, end
);
359 #define SKIP_ULEB() read_uleb128 (start, & length_return, end); start += length_return
360 #define SKIP_SLEB() read_sleb128 (start, & length_return, end); start += length_return
362 #define READ_ULEB(var) \
367 (var) = _val = read_uleb128 (start, &length_return, end); \
369 error (_("Internal error: %s:%d: LEB value (%s) " \
370 "too large for containing variable\n"), \
371 __FILE__, __LINE__, dwarf_vmatoa ("u", _val)); \
372 start += length_return; \
376 #define READ_SLEB(var) \
379 dwarf_signed_vma _val; \
381 (var) = _val = read_sleb128 (start, &length_return, end); \
383 error (_("Internal error: %s:%d: LEB value (%s) " \
384 "too large for containing variable\n"), \
385 __FILE__, __LINE__, dwarf_vmatoa ("d", _val)); \
386 start += length_return; \
390 /* Read AMOUNT bytes from PTR and store them in VAL as an unsigned value.
391 Checks to make sure that the read will not reach or pass END
392 and that VAL is big enough to hold AMOUNT bytes. */
393 #define SAFE_BYTE_GET(VAL, PTR, AMOUNT, END) \
396 unsigned int amount = (AMOUNT); \
397 if (sizeof (VAL) < amount) \
399 error (ngettext ("internal error: attempt to read %d byte " \
400 "of data in to %d sized variable", \
401 "internal error: attempt to read %d bytes " \
402 "of data in to %d sized variable", \
404 amount, (int) sizeof (VAL)); \
405 amount = sizeof (VAL); \
407 if (((PTR) + amount) >= (END)) \
410 amount = (END) - (PTR); \
414 if (amount == 0 || amount > 8) \
417 VAL = byte_get ((PTR), amount); \
421 /* Like SAFE_BYTE_GET, but also increments PTR by AMOUNT. */
422 #define SAFE_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \
425 SAFE_BYTE_GET (VAL, PTR, AMOUNT, END); \
430 /* Like SAFE_BYTE_GET, but reads a signed value. */
431 #define SAFE_SIGNED_BYTE_GET(VAL, PTR, AMOUNT, END) \
434 unsigned int amount = (AMOUNT); \
435 if (((PTR) + amount) >= (END)) \
438 amount = (END) - (PTR); \
443 VAL = byte_get_signed ((PTR), amount); \
449 /* Like SAFE_SIGNED_BYTE_GET, but also increments PTR by AMOUNT. */
450 #define SAFE_SIGNED_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \
453 SAFE_SIGNED_BYTE_GET (VAL, PTR, AMOUNT, END); \
458 #define SAFE_BYTE_GET64(PTR, HIGH, LOW, END) \
461 if (((PTR) + 8) <= (END)) \
463 byte_get_64 ((PTR), (HIGH), (LOW)); \
467 * (LOW) = * (HIGH) = 0; \
472 typedef struct State_Machine_Registers
481 unsigned char op_index
;
482 unsigned char end_sequence
;
483 /* This variable hold the number of the last entry seen
484 in the File Table. */
485 unsigned int last_file_entry
;
488 static SMR state_machine_regs
;
491 reset_state_machine (int is_stmt
)
493 state_machine_regs
.address
= 0;
494 state_machine_regs
.view
= 0;
495 state_machine_regs
.op_index
= 0;
496 state_machine_regs
.file
= 1;
497 state_machine_regs
.line
= 1;
498 state_machine_regs
.column
= 0;
499 state_machine_regs
.is_stmt
= is_stmt
;
500 state_machine_regs
.basic_block
= 0;
501 state_machine_regs
.end_sequence
= 0;
502 state_machine_regs
.last_file_entry
= 0;
505 /* Handled an extend line op.
506 Returns the number of bytes read. */
509 process_extended_line_op (unsigned char * data
,
513 unsigned char op_code
;
514 unsigned int bytes_read
;
517 unsigned char *orig_data
= data
;
520 len
= read_uleb128 (data
, & bytes_read
, end
);
523 if (len
== 0 || data
== end
|| len
> (uintptr_t) (end
- data
))
525 warn (_("Badly formed extended line op encountered!\n"));
532 printf (_(" Extended opcode %d: "), op_code
);
536 case DW_LNE_end_sequence
:
537 printf (_("End of Sequence\n\n"));
538 reset_state_machine (is_stmt
);
541 case DW_LNE_set_address
:
542 /* PR 17512: file: 002-100480-0.004. */
543 if (len
- bytes_read
- 1 > 8)
545 warn (_("Length (%d) of DW_LNE_set_address op is too long\n"),
546 len
- bytes_read
- 1);
550 SAFE_BYTE_GET (adr
, data
, len
- bytes_read
- 1, end
);
551 printf (_("set Address to 0x%s\n"), dwarf_vmatoa ("x", adr
));
552 state_machine_regs
.address
= adr
;
553 state_machine_regs
.view
= 0;
554 state_machine_regs
.op_index
= 0;
557 case DW_LNE_define_file
:
558 printf (_("define new File Table entry\n"));
559 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
560 printf (" %d\t", ++state_machine_regs
.last_file_entry
);
566 l
= strnlen ((char *) data
, end
- data
);
568 printf ("%s\t", dwarf_vmatoa ("u", read_uleb128 (data
, & bytes_read
, end
)));
570 printf ("%s\t", dwarf_vmatoa ("u", read_uleb128 (data
, & bytes_read
, end
)));
572 printf ("%s\t", dwarf_vmatoa ("u", read_uleb128 (data
, & bytes_read
, end
)));
574 printf ("%.*s\n\n", (int) l
, name
);
577 if (((unsigned int) (data
- orig_data
) != len
) || data
== end
)
578 warn (_("DW_LNE_define_file: Bad opcode length\n"));
581 case DW_LNE_set_discriminator
:
582 printf (_("set Discriminator to %s\n"),
583 dwarf_vmatoa ("u", read_uleb128 (data
, & bytes_read
, end
)));
587 case DW_LNE_HP_negate_is_UV_update
:
588 printf ("DW_LNE_HP_negate_is_UV_update\n");
590 case DW_LNE_HP_push_context
:
591 printf ("DW_LNE_HP_push_context\n");
593 case DW_LNE_HP_pop_context
:
594 printf ("DW_LNE_HP_pop_context\n");
596 case DW_LNE_HP_set_file_line_column
:
597 printf ("DW_LNE_HP_set_file_line_column\n");
599 case DW_LNE_HP_set_routine_name
:
600 printf ("DW_LNE_HP_set_routine_name\n");
602 case DW_LNE_HP_set_sequence
:
603 printf ("DW_LNE_HP_set_sequence\n");
605 case DW_LNE_HP_negate_post_semantics
:
606 printf ("DW_LNE_HP_negate_post_semantics\n");
608 case DW_LNE_HP_negate_function_exit
:
609 printf ("DW_LNE_HP_negate_function_exit\n");
611 case DW_LNE_HP_negate_front_end_logical
:
612 printf ("DW_LNE_HP_negate_front_end_logical\n");
614 case DW_LNE_HP_define_proc
:
615 printf ("DW_LNE_HP_define_proc\n");
617 case DW_LNE_HP_source_file_correlation
:
619 unsigned char *edata
= data
+ len
- bytes_read
- 1;
621 printf ("DW_LNE_HP_source_file_correlation\n");
627 opc
= read_uleb128 (data
, & bytes_read
, edata
);
632 case DW_LNE_HP_SFC_formfeed
:
633 printf (" DW_LNE_HP_SFC_formfeed\n");
635 case DW_LNE_HP_SFC_set_listing_line
:
636 printf (" DW_LNE_HP_SFC_set_listing_line (%s)\n",
638 read_uleb128 (data
, & bytes_read
, edata
)));
641 case DW_LNE_HP_SFC_associate
:
642 printf (" DW_LNE_HP_SFC_associate ");
645 read_uleb128 (data
, & bytes_read
, edata
)));
649 read_uleb128 (data
, & bytes_read
, edata
)));
653 read_uleb128 (data
, & bytes_read
, edata
)));
657 printf (_(" UNKNOWN DW_LNE_HP_SFC opcode (%u)\n"), opc
);
667 unsigned int rlen
= len
- bytes_read
- 1;
669 if (op_code
>= DW_LNE_lo_user
670 /* The test against DW_LNW_hi_user is redundant due to
671 the limited range of the unsigned char data type used
673 /*&& op_code <= DW_LNE_hi_user*/)
674 printf (_("user defined: "));
676 printf (_("UNKNOWN: "));
677 printf (_("length %d ["), rlen
);
679 printf (" %02x", *data
++);
688 static const unsigned char *
689 fetch_indirect_string (dwarf_vma offset
)
691 struct dwarf_section
*section
= &debug_displays
[str
].section
;
692 const unsigned char * ret
;
694 if (section
->start
== NULL
)
695 return (const unsigned char *) _("<no .debug_str section>");
697 if (offset
>= section
->size
)
699 warn (_("DW_FORM_strp offset too big: %s\n"),
700 dwarf_vmatoa ("x", offset
));
701 return (const unsigned char *) _("<offset is too big>");
704 ret
= section
->start
+ offset
;
705 /* Unfortunately we cannot rely upon the .debug_str section ending with a
706 NUL byte. Since our caller is expecting to receive a well formed C
707 string we test for the lack of a terminating byte here. */
708 if (strnlen ((const char *) ret
, section
->size
- offset
)
709 == section
->size
- offset
)
710 ret
= (const unsigned char *)
711 _("<no NUL byte at end of .debug_str section>");
716 static const unsigned char *
717 fetch_indirect_line_string (dwarf_vma offset
)
719 struct dwarf_section
*section
= &debug_displays
[line_str
].section
;
720 const unsigned char * ret
;
722 if (section
->start
== NULL
)
723 return (const unsigned char *) _("<no .debug_line_str section>");
725 if (offset
>= section
->size
)
727 warn (_("DW_FORM_line_strp offset too big: %s\n"),
728 dwarf_vmatoa ("x", offset
));
729 return (const unsigned char *) _("<offset is too big>");
732 ret
= section
->start
+ offset
;
733 /* Unfortunately we cannot rely upon the .debug_line_str section ending
734 with a NUL byte. Since our caller is expecting to receive a well formed
735 C string we test for the lack of a terminating byte here. */
736 if (strnlen ((const char *) ret
, section
->size
- offset
)
737 == section
->size
- offset
)
738 ret
= (const unsigned char *)
739 _("<no NUL byte at end of .debug_line_str section>");
745 fetch_indexed_string (dwarf_vma idx
, struct cu_tu_set
*this_set
,
746 dwarf_vma offset_size
, bfd_boolean dwo
)
748 enum dwarf_section_display_enum str_sec_idx
= dwo
? str_dwo
: str
;
749 enum dwarf_section_display_enum idx_sec_idx
= dwo
? str_index_dwo
: str_index
;
750 struct dwarf_section
*index_section
= &debug_displays
[idx_sec_idx
].section
;
751 struct dwarf_section
*str_section
= &debug_displays
[str_sec_idx
].section
;
752 dwarf_vma index_offset
= idx
* offset_size
;
753 dwarf_vma str_offset
;
756 if (index_section
->start
== NULL
)
757 return (dwo
? _("<no .debug_str_offsets.dwo section>")
758 : _("<no .debug_str_offsets section>"));
760 if (this_set
!= NULL
)
761 index_offset
+= this_set
->section_offsets
[DW_SECT_STR_OFFSETS
];
762 if (index_offset
>= index_section
->size
)
764 warn (_("DW_FORM_GNU_str_index offset too big: %s\n"),
765 dwarf_vmatoa ("x", index_offset
));
766 return _("<index offset is too big>");
769 if (str_section
->start
== NULL
)
770 return (dwo
? _("<no .debug_str.dwo section>")
771 : _("<no .debug_str section>"));
773 str_offset
= byte_get (index_section
->start
+ index_offset
, offset_size
);
774 str_offset
-= str_section
->address
;
775 if (str_offset
>= str_section
->size
)
777 warn (_("DW_FORM_GNU_str_index indirect offset too big: %s\n"),
778 dwarf_vmatoa ("x", str_offset
));
779 return _("<indirect index offset is too big>");
782 ret
= (const char *) str_section
->start
+ str_offset
;
783 /* Unfortunately we cannot rely upon str_section ending with a NUL byte.
784 Since our caller is expecting to receive a well formed C string we test
785 for the lack of a terminating byte here. */
786 if (strnlen (ret
, str_section
->size
- str_offset
)
787 == str_section
->size
- str_offset
)
788 ret
= (const char *) _("<no NUL byte at end of section>");
794 fetch_indexed_value (dwarf_vma offset
, dwarf_vma bytes
)
796 struct dwarf_section
*section
= &debug_displays
[debug_addr
].section
;
798 if (section
->start
== NULL
)
799 return (_("<no .debug_addr section>"));
801 if (offset
+ bytes
> section
->size
)
803 warn (_("Offset into section %s too big: %s\n"),
804 section
->name
, dwarf_vmatoa ("x", offset
));
805 return "<offset too big>";
808 return dwarf_vmatoa ("x", byte_get (section
->start
+ offset
, bytes
));
812 /* FIXME: There are better and more efficient ways to handle
813 these structures. For now though, I just want something that
814 is simple to implement. */
815 typedef struct abbrev_attr
817 unsigned long attribute
;
819 bfd_signed_vma implicit_const
;
820 struct abbrev_attr
*next
;
824 typedef struct abbrev_entry
829 struct abbrev_attr
*first_attr
;
830 struct abbrev_attr
*last_attr
;
831 struct abbrev_entry
*next
;
835 static abbrev_entry
*first_abbrev
= NULL
;
836 static abbrev_entry
*last_abbrev
= NULL
;
843 for (abbrv
= first_abbrev
; abbrv
;)
845 abbrev_entry
*next_abbrev
= abbrv
->next
;
848 for (attr
= abbrv
->first_attr
; attr
;)
850 abbrev_attr
*next_attr
= attr
->next
;
860 last_abbrev
= first_abbrev
= NULL
;
864 add_abbrev (unsigned long number
, unsigned long tag
, int children
)
868 entry
= (abbrev_entry
*) malloc (sizeof (*entry
));
873 entry
->entry
= number
;
875 entry
->children
= children
;
876 entry
->first_attr
= NULL
;
877 entry
->last_attr
= NULL
;
880 if (first_abbrev
== NULL
)
881 first_abbrev
= entry
;
883 last_abbrev
->next
= entry
;
889 add_abbrev_attr (unsigned long attribute
, unsigned long form
,
890 bfd_signed_vma implicit_const
)
894 attr
= (abbrev_attr
*) malloc (sizeof (*attr
));
899 attr
->attribute
= attribute
;
901 attr
->implicit_const
= implicit_const
;
904 if (last_abbrev
->first_attr
== NULL
)
905 last_abbrev
->first_attr
= attr
;
907 last_abbrev
->last_attr
->next
= attr
;
909 last_abbrev
->last_attr
= attr
;
912 /* Processes the (partial) contents of a .debug_abbrev section.
913 Returns NULL if the end of the section was encountered.
914 Returns the address after the last byte read if the end of
915 an abbreviation set was found. */
917 static unsigned char *
918 process_abbrev_section (unsigned char *start
, unsigned char *end
)
920 if (first_abbrev
!= NULL
)
925 unsigned int bytes_read
;
928 unsigned long attribute
;
931 entry
= read_uleb128 (start
, & bytes_read
, end
);
934 /* A single zero is supposed to end the section according
935 to the standard. If there's more, then signal that to
942 tag
= read_uleb128 (start
, & bytes_read
, end
);
949 add_abbrev (entry
, tag
, children
);
954 /* Initialize it due to a false compiler warning. */
955 bfd_signed_vma implicit_const
= -1;
957 attribute
= read_uleb128 (start
, & bytes_read
, end
);
962 form
= read_uleb128 (start
, & bytes_read
, end
);
967 if (form
== DW_FORM_implicit_const
)
969 implicit_const
= read_sleb128 (start
, & bytes_read
, end
);
975 add_abbrev_attr (attribute
, form
, implicit_const
);
977 while (attribute
!= 0);
980 /* Report the missing single zero which ends the section. */
981 error (_(".debug_abbrev section not zero terminated\n"));
987 get_TAG_name (unsigned long tag
)
989 const char *name
= get_DW_TAG_name ((unsigned int) tag
);
993 static char buffer
[100];
995 if (tag
>= DW_TAG_lo_user
&& tag
<= DW_TAG_hi_user
)
996 snprintf (buffer
, sizeof (buffer
), _("User TAG value: %#lx"), tag
);
998 snprintf (buffer
, sizeof (buffer
), _("Unknown TAG value: %#lx"), tag
);
1006 get_FORM_name (unsigned long form
)
1011 return "DW_FORM value: 0";
1013 name
= get_DW_FORM_name (form
);
1016 static char buffer
[100];
1018 snprintf (buffer
, sizeof (buffer
), _("Unknown FORM value: %lx"), form
);
1026 get_IDX_name (unsigned long idx
)
1028 const char *name
= get_DW_IDX_name ((unsigned int) idx
);
1032 static char buffer
[100];
1034 snprintf (buffer
, sizeof (buffer
), _("Unknown IDX value: %lx"), idx
);
1041 static unsigned char *
1042 display_block (unsigned char *data
,
1044 const unsigned char * const end
, char delimiter
)
1048 printf (_("%c%s byte block: "), delimiter
, dwarf_vmatoa ("u", length
));
1050 return (unsigned char *) end
;
1052 maxlen
= (dwarf_vma
) (end
- data
);
1053 length
= length
> maxlen
? maxlen
: length
;
1056 printf ("%lx ", (unsigned long) byte_get (data
++, 1));
1062 decode_location_expression (unsigned char * data
,
1063 unsigned int pointer_size
,
1064 unsigned int offset_size
,
1067 dwarf_vma cu_offset
,
1068 struct dwarf_section
* section
)
1071 unsigned int bytes_read
;
1073 dwarf_signed_vma svalue
;
1074 unsigned char *end
= data
+ length
;
1075 int need_frame_base
= 0;
1084 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1085 printf ("DW_OP_addr: %s", dwarf_vmatoa ("x", uvalue
));
1088 printf ("DW_OP_deref");
1091 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1092 printf ("DW_OP_const1u: %lu", (unsigned long) uvalue
);
1095 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 1, end
);
1096 printf ("DW_OP_const1s: %ld", (long) svalue
);
1099 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
1100 printf ("DW_OP_const2u: %lu", (unsigned long) uvalue
);
1103 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1104 printf ("DW_OP_const2s: %ld", (long) svalue
);
1107 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1108 printf ("DW_OP_const4u: %lu", (unsigned long) uvalue
);
1111 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
1112 printf ("DW_OP_const4s: %ld", (long) svalue
);
1115 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1116 printf ("DW_OP_const8u: %lu ", (unsigned long) uvalue
);
1117 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1118 printf ("%lu", (unsigned long) uvalue
);
1121 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
1122 printf ("DW_OP_const8s: %ld ", (long) svalue
);
1123 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
1124 printf ("%ld", (long) svalue
);
1127 printf ("DW_OP_constu: %s",
1128 dwarf_vmatoa ("u", read_uleb128 (data
, &bytes_read
, end
)));
1132 printf ("DW_OP_consts: %s",
1133 dwarf_vmatoa ("d", read_sleb128 (data
, &bytes_read
, end
)));
1137 printf ("DW_OP_dup");
1140 printf ("DW_OP_drop");
1143 printf ("DW_OP_over");
1146 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1147 printf ("DW_OP_pick: %ld", (unsigned long) uvalue
);
1150 printf ("DW_OP_swap");
1153 printf ("DW_OP_rot");
1156 printf ("DW_OP_xderef");
1159 printf ("DW_OP_abs");
1162 printf ("DW_OP_and");
1165 printf ("DW_OP_div");
1168 printf ("DW_OP_minus");
1171 printf ("DW_OP_mod");
1174 printf ("DW_OP_mul");
1177 printf ("DW_OP_neg");
1180 printf ("DW_OP_not");
1183 printf ("DW_OP_or");
1186 printf ("DW_OP_plus");
1188 case DW_OP_plus_uconst
:
1189 printf ("DW_OP_plus_uconst: %s",
1190 dwarf_vmatoa ("u", read_uleb128 (data
, &bytes_read
, end
)));
1194 printf ("DW_OP_shl");
1197 printf ("DW_OP_shr");
1200 printf ("DW_OP_shra");
1203 printf ("DW_OP_xor");
1206 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1207 printf ("DW_OP_bra: %ld", (long) svalue
);
1210 printf ("DW_OP_eq");
1213 printf ("DW_OP_ge");
1216 printf ("DW_OP_gt");
1219 printf ("DW_OP_le");
1222 printf ("DW_OP_lt");
1225 printf ("DW_OP_ne");
1228 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1229 printf ("DW_OP_skip: %ld", (long) svalue
);
1264 printf ("DW_OP_lit%d", op
- DW_OP_lit0
);
1299 printf ("DW_OP_reg%d (%s)", op
- DW_OP_reg0
,
1300 regname (op
- DW_OP_reg0
, 1));
1335 printf ("DW_OP_breg%d (%s): %s",
1337 regname (op
- DW_OP_breg0
, 1),
1338 dwarf_vmatoa ("d", read_sleb128 (data
, &bytes_read
, end
)));
1343 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1345 printf ("DW_OP_regx: %s (%s)",
1346 dwarf_vmatoa ("u", uvalue
), regname (uvalue
, 1));
1349 need_frame_base
= 1;
1350 printf ("DW_OP_fbreg: %s",
1351 dwarf_vmatoa ("d", read_sleb128 (data
, &bytes_read
, end
)));
1355 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1357 printf ("DW_OP_bregx: %s (%s) %s",
1358 dwarf_vmatoa ("u", uvalue
), regname (uvalue
, 1),
1359 dwarf_vmatoa ("d", read_sleb128 (data
, &bytes_read
, end
)));
1363 printf ("DW_OP_piece: %s",
1364 dwarf_vmatoa ("u", read_uleb128 (data
, &bytes_read
, end
)));
1367 case DW_OP_deref_size
:
1368 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1369 printf ("DW_OP_deref_size: %ld", (long) uvalue
);
1371 case DW_OP_xderef_size
:
1372 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1373 printf ("DW_OP_xderef_size: %ld", (long) uvalue
);
1376 printf ("DW_OP_nop");
1379 /* DWARF 3 extensions. */
1380 case DW_OP_push_object_address
:
1381 printf ("DW_OP_push_object_address");
1384 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1385 this ought to be an 8-byte wide computation. */
1386 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1387 printf ("DW_OP_call2: <0x%s>",
1388 dwarf_vmatoa ("x", svalue
+ cu_offset
));
1391 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1392 this ought to be an 8-byte wide computation. */
1393 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
1394 printf ("DW_OP_call4: <0x%s>",
1395 dwarf_vmatoa ("x", svalue
+ cu_offset
));
1397 case DW_OP_call_ref
:
1398 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1399 this ought to be an 8-byte wide computation. */
1400 if (dwarf_version
== -1)
1402 printf (_("(DW_OP_call_ref in frame info)"));
1403 /* No way to tell where the next op is, so just bail. */
1404 return need_frame_base
;
1406 if (dwarf_version
== 2)
1408 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1412 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1414 printf ("DW_OP_call_ref: <0x%s>", dwarf_vmatoa ("x", uvalue
));
1416 case DW_OP_form_tls_address
:
1417 printf ("DW_OP_form_tls_address");
1419 case DW_OP_call_frame_cfa
:
1420 printf ("DW_OP_call_frame_cfa");
1422 case DW_OP_bit_piece
:
1423 printf ("DW_OP_bit_piece: ");
1424 printf (_("size: %s "),
1425 dwarf_vmatoa ("u", read_uleb128 (data
, &bytes_read
, end
)));
1427 printf (_("offset: %s "),
1428 dwarf_vmatoa ("u", read_uleb128 (data
, &bytes_read
, end
)));
1432 /* DWARF 4 extensions. */
1433 case DW_OP_stack_value
:
1434 printf ("DW_OP_stack_value");
1437 case DW_OP_implicit_value
:
1438 printf ("DW_OP_implicit_value");
1439 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1441 data
= display_block (data
, uvalue
, end
, ' ');
1444 /* GNU extensions. */
1445 case DW_OP_GNU_push_tls_address
:
1446 printf (_("DW_OP_GNU_push_tls_address or DW_OP_HP_unknown"));
1448 case DW_OP_GNU_uninit
:
1449 printf ("DW_OP_GNU_uninit");
1450 /* FIXME: Is there data associated with this OP ? */
1452 case DW_OP_GNU_encoded_addr
:
1459 addr
= get_encoded_value (&data
, encoding
, section
, end
);
1461 printf ("DW_OP_GNU_encoded_addr: fmt:%02x addr:", encoding
);
1462 print_dwarf_vma (addr
, pointer_size
);
1465 case DW_OP_implicit_pointer
:
1466 case DW_OP_GNU_implicit_pointer
:
1467 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1468 this ought to be an 8-byte wide computation. */
1469 if (dwarf_version
== -1)
1471 printf (_("(%s in frame info)"),
1472 (op
== DW_OP_implicit_pointer
1473 ? "DW_OP_implicit_pointer"
1474 : "DW_OP_GNU_implicit_pointer"));
1475 /* No way to tell where the next op is, so just bail. */
1476 return need_frame_base
;
1478 if (dwarf_version
== 2)
1480 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1484 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1486 printf ("%s: <0x%s> %s",
1487 (op
== DW_OP_implicit_pointer
1488 ? "DW_OP_implicit_pointer" : "DW_OP_GNU_implicit_pointer"),
1489 dwarf_vmatoa ("x", uvalue
),
1490 dwarf_vmatoa ("d", read_sleb128 (data
,
1491 &bytes_read
, end
)));
1494 case DW_OP_entry_value
:
1495 case DW_OP_GNU_entry_value
:
1496 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1498 /* PR 17531: file: 0cc9cd00. */
1499 if (uvalue
> (dwarf_vma
) (end
- data
))
1500 uvalue
= end
- data
;
1501 printf ("%s: (", (op
== DW_OP_entry_value
? "DW_OP_entry_value"
1502 : "DW_OP_GNU_entry_value"));
1503 if (decode_location_expression (data
, pointer_size
, offset_size
,
1504 dwarf_version
, uvalue
,
1505 cu_offset
, section
))
1506 need_frame_base
= 1;
1512 case DW_OP_const_type
:
1513 case DW_OP_GNU_const_type
:
1514 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1516 printf ("%s: <0x%s> ",
1517 (op
== DW_OP_const_type
? "DW_OP_const_type"
1518 : "DW_OP_GNU_const_type"),
1519 dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1520 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1521 data
= display_block (data
, uvalue
, end
, ' ');
1523 case DW_OP_regval_type
:
1524 case DW_OP_GNU_regval_type
:
1525 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1527 printf ("%s: %s (%s)",
1528 (op
== DW_OP_regval_type
? "DW_OP_regval_type"
1529 : "DW_OP_GNU_regval_type"),
1530 dwarf_vmatoa ("u", uvalue
), regname (uvalue
, 1));
1531 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1533 printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1535 case DW_OP_deref_type
:
1536 case DW_OP_GNU_deref_type
:
1537 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1539 (op
== DW_OP_deref_type
? "DW_OP_deref_type"
1540 : "DW_OP_GNU_deref_type"),
1542 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1544 printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1547 case DW_OP_GNU_convert
:
1548 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1550 printf ("%s <0x%s>",
1551 (op
== DW_OP_convert
? "DW_OP_convert" : "DW_OP_GNU_convert"),
1552 dwarf_vmatoa ("x", uvalue
? cu_offset
+ uvalue
: 0));
1554 case DW_OP_reinterpret
:
1555 case DW_OP_GNU_reinterpret
:
1556 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1558 printf ("%s <0x%s>",
1559 (op
== DW_OP_reinterpret
? "DW_OP_reinterpret"
1560 : "DW_OP_GNU_reinterpret"),
1561 dwarf_vmatoa ("x", uvalue
? cu_offset
+ uvalue
: 0));
1563 case DW_OP_GNU_parameter_ref
:
1564 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1565 printf ("DW_OP_GNU_parameter_ref: <0x%s>",
1566 dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1568 case DW_OP_GNU_addr_index
:
1569 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1571 printf ("DW_OP_GNU_addr_index <0x%s>", dwarf_vmatoa ("x", uvalue
));
1573 case DW_OP_GNU_const_index
:
1574 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1576 printf ("DW_OP_GNU_const_index <0x%s>", dwarf_vmatoa ("x", uvalue
));
1579 /* HP extensions. */
1580 case DW_OP_HP_is_value
:
1581 printf ("DW_OP_HP_is_value");
1582 /* FIXME: Is there data associated with this OP ? */
1584 case DW_OP_HP_fltconst4
:
1585 printf ("DW_OP_HP_fltconst4");
1586 /* FIXME: Is there data associated with this OP ? */
1588 case DW_OP_HP_fltconst8
:
1589 printf ("DW_OP_HP_fltconst8");
1590 /* FIXME: Is there data associated with this OP ? */
1592 case DW_OP_HP_mod_range
:
1593 printf ("DW_OP_HP_mod_range");
1594 /* FIXME: Is there data associated with this OP ? */
1596 case DW_OP_HP_unmod_range
:
1597 printf ("DW_OP_HP_unmod_range");
1598 /* FIXME: Is there data associated with this OP ? */
1601 printf ("DW_OP_HP_tls");
1602 /* FIXME: Is there data associated with this OP ? */
1605 /* PGI (STMicroelectronics) extensions. */
1606 case DW_OP_PGI_omp_thread_num
:
1607 /* Pushes the thread number for the current thread as it would be
1608 returned by the standard OpenMP library function:
1609 omp_get_thread_num(). The "current thread" is the thread for
1610 which the expression is being evaluated. */
1611 printf ("DW_OP_PGI_omp_thread_num");
1615 if (op
>= DW_OP_lo_user
1616 && op
<= DW_OP_hi_user
)
1617 printf (_("(User defined location op 0x%x)"), op
);
1619 printf (_("(Unknown location op 0x%x)"), op
);
1620 /* No way to tell where the next op is, so just bail. */
1621 return need_frame_base
;
1624 /* Separate the ops. */
1629 return need_frame_base
;
1632 /* Find the CU or TU set corresponding to the given CU_OFFSET.
1633 This is used for DWARF package files. */
1635 static struct cu_tu_set
*
1636 find_cu_tu_set_v2 (dwarf_vma cu_offset
, int do_types
)
1638 struct cu_tu_set
*p
;
1640 unsigned int dw_sect
;
1646 dw_sect
= DW_SECT_TYPES
;
1652 dw_sect
= DW_SECT_INFO
;
1656 if (p
->section_offsets
[dw_sect
] == cu_offset
)
1664 /* Add INC to HIGH_BITS:LOW_BITS. */
1666 add64 (dwarf_vma
* high_bits
, dwarf_vma
* low_bits
, dwarf_vma inc
)
1668 dwarf_vma tmp
= * low_bits
;
1672 /* FIXME: There is probably a better way of handling this:
1674 We need to cope with dwarf_vma being a 32-bit or 64-bit
1675 type. Plus regardless of its size LOW_BITS is meant to
1676 only hold 32-bits, so if there is overflow or wrap around
1677 we must propagate into HIGH_BITS. */
1678 if (tmp
< * low_bits
)
1682 else if (sizeof (tmp
) > 8
1693 fetch_alt_indirect_string (dwarf_vma offset
)
1695 struct dwarf_section
* section
;
1698 if (! do_follow_links
)
1701 if (separate_debug_file
== NULL
)
1702 return _("<following link not possible>");
1704 if (! load_debug_section (separate_debug_str
, separate_debug_file
))
1705 return _("<could not load separate string section>");
1707 section
= &debug_displays
[separate_debug_str
].section
;
1708 if (section
->start
== NULL
)
1709 return _("<no .debug_str section>");
1711 if (offset
>= section
->size
)
1713 warn (_("DW_FORM_GNU_strp_alt offset too big: %s\n"), dwarf_vmatoa ("x", offset
));
1714 return _("<offset is too big>");
1717 ret
= (const char *) (section
->start
+ offset
);
1718 /* Unfortunately we cannot rely upon the .debug_str section ending with a
1719 NUL byte. Since our caller is expecting to receive a well formed C
1720 string we test for the lack of a terminating byte here. */
1721 if (strnlen ((const char *) ret
, section
->size
- offset
)
1722 == section
->size
- offset
)
1723 return _("<no NUL byte at end of .debug_str section>");
1729 get_AT_name (unsigned long attribute
)
1734 return "DW_AT value: 0";
1736 /* One value is shared by the MIPS and HP extensions: */
1737 if (attribute
== DW_AT_MIPS_fde
)
1738 return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable";
1740 name
= get_DW_AT_name (attribute
);
1744 static char buffer
[100];
1746 snprintf (buffer
, sizeof (buffer
), _("Unknown AT value: %lx"),
1754 static unsigned char *
1755 read_and_display_attr_value (unsigned long attribute
,
1757 dwarf_signed_vma implicit_const
,
1758 unsigned char * data
,
1759 unsigned char * end
,
1760 dwarf_vma cu_offset
,
1761 dwarf_vma pointer_size
,
1762 dwarf_vma offset_size
,
1764 debug_info
* debug_info_p
,
1766 struct dwarf_section
* section
,
1767 struct cu_tu_set
* this_set
,
1770 dwarf_vma uvalue
= 0;
1771 unsigned char *block_start
= NULL
;
1772 unsigned char * orig_data
= data
;
1773 unsigned int bytes_read
;
1775 if (data
> end
|| (data
== end
&& form
!= DW_FORM_flag_present
))
1777 warn (_("Corrupt attribute\n"));
1786 case DW_FORM_ref_addr
:
1787 if (dwarf_version
== 2)
1788 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1789 else if (dwarf_version
== 3 || dwarf_version
== 4)
1790 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1792 error (_("Internal error: DWARF version is not 2, 3 or 4.\n"));
1797 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1801 case DW_FORM_line_strp
:
1802 case DW_FORM_sec_offset
:
1803 case DW_FORM_GNU_ref_alt
:
1804 case DW_FORM_GNU_strp_alt
:
1805 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1808 case DW_FORM_flag_present
:
1815 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1820 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
1825 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1829 uvalue
= read_sleb128 (data
, & bytes_read
, end
);
1833 case DW_FORM_GNU_str_index
:
1834 uvalue
= read_uleb128 (data
, & bytes_read
, end
);
1838 case DW_FORM_ref_udata
:
1840 uvalue
= read_uleb128 (data
, & bytes_read
, end
);
1844 case DW_FORM_indirect
:
1845 form
= read_uleb128 (data
, & bytes_read
, end
);
1848 printf ("%c%s", delimiter
, get_FORM_name (form
));
1849 if (form
== DW_FORM_implicit_const
)
1851 implicit_const
= read_sleb128 (data
, & bytes_read
, end
);
1854 return read_and_display_attr_value (attribute
, form
, implicit_const
, data
,
1855 end
, cu_offset
, pointer_size
,
1856 offset_size
, dwarf_version
,
1857 debug_info_p
, do_loc
,
1858 section
, this_set
, delimiter
);
1859 case DW_FORM_GNU_addr_index
:
1860 uvalue
= read_uleb128 (data
, & bytes_read
, end
);
1867 case DW_FORM_ref_addr
:
1869 printf ("%c<0x%s>", delimiter
, dwarf_vmatoa ("x",uvalue
));
1872 case DW_FORM_GNU_ref_alt
:
1874 printf ("%c<alt 0x%s>", delimiter
, dwarf_vmatoa ("x",uvalue
));
1875 /* FIXME: Follow the reference... */
1881 case DW_FORM_ref_udata
:
1883 printf ("%c<0x%s>", delimiter
, dwarf_vmatoa ("x", uvalue
+ cu_offset
));
1888 case DW_FORM_sec_offset
:
1890 printf ("%c0x%s", delimiter
, dwarf_vmatoa ("x", uvalue
));
1893 case DW_FORM_flag_present
:
1900 printf ("%c%s", delimiter
, dwarf_vmatoa ("d", uvalue
));
1903 case DW_FORM_implicit_const
:
1905 printf ("%c%s", delimiter
, dwarf_vmatoa ("d", implicit_const
));
1912 dwarf_vma high_bits
;
1916 SAFE_BYTE_GET64 (data
, &high_bits
, &uvalue
, end
);
1918 if (form
== DW_FORM_ref8
)
1919 add64 (& high_bits
, & utmp
, cu_offset
);
1920 printf ("%c0x%s", delimiter
,
1921 dwarf_vmatoa64 (high_bits
, utmp
, buf
, sizeof (buf
)));
1924 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
1925 && num_debug_info_entries
== 0)
1927 if (sizeof (uvalue
) == 8)
1928 SAFE_BYTE_GET (uvalue
, data
, 8, end
);
1930 error (_("DW_FORM_data8 is unsupported when sizeof (dwarf_vma) != 8\n"));
1936 case DW_FORM_data16
:
1939 dwarf_vma left_high_bits
, left_low_bits
;
1940 dwarf_vma right_high_bits
, right_low_bits
;
1942 SAFE_BYTE_GET64 (data
, &left_high_bits
, &left_low_bits
, end
);
1943 SAFE_BYTE_GET64 (data
+ 8, &right_high_bits
, &right_low_bits
, end
);
1944 if (byte_get
== byte_get_little_endian
)
1947 left_high_bits
^= right_high_bits
;
1948 right_high_bits
^= left_high_bits
;
1949 left_high_bits
^= right_high_bits
;
1950 left_low_bits
^= right_low_bits
;
1951 right_low_bits
^= left_low_bits
;
1952 left_low_bits
^= right_low_bits
;
1954 printf (" 0x%08" DWARF_VMA_FMT
"x%08" DWARF_VMA_FMT
"x"
1955 "%08" DWARF_VMA_FMT
"x%08" DWARF_VMA_FMT
"x",
1956 left_high_bits
, left_low_bits
, right_high_bits
,
1962 case DW_FORM_string
:
1964 printf ("%c%.*s", delimiter
, (int) (end
- data
), data
);
1965 data
+= strnlen ((char *) data
, end
- data
) + 1;
1969 case DW_FORM_exprloc
:
1970 uvalue
= read_uleb128 (data
, & bytes_read
, end
);
1971 block_start
= data
+ bytes_read
;
1972 if (block_start
>= end
)
1974 warn (_("Block ends prematurely\n"));
1978 /* FIXME: Testing "(block_start + uvalue) < block_start" miscompiles with
1979 gcc 4.8.3 running on an x86_64 host in 32-bit mode. So we pre-compute
1980 block_start + uvalue here. */
1981 data
= block_start
+ uvalue
;
1982 /* PR 17512: file: 008-103549-0.001:0.1. */
1983 if (block_start
+ uvalue
> end
|| data
< block_start
)
1985 warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue
);
1986 uvalue
= end
- block_start
;
1989 data
= block_start
+ uvalue
;
1991 data
= display_block (block_start
, uvalue
, end
, delimiter
);
1994 case DW_FORM_block1
:
1995 SAFE_BYTE_GET (uvalue
, data
, 1, end
);
1996 block_start
= data
+ 1;
1997 if (block_start
>= end
)
1999 warn (_("Block ends prematurely\n"));
2003 data
= block_start
+ uvalue
;
2004 if (block_start
+ uvalue
> end
|| data
< block_start
)
2006 warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue
);
2007 uvalue
= end
- block_start
;
2010 data
= block_start
+ uvalue
;
2012 data
= display_block (block_start
, uvalue
, end
, delimiter
);
2015 case DW_FORM_block2
:
2016 SAFE_BYTE_GET (uvalue
, data
, 2, end
);
2017 block_start
= data
+ 2;
2018 if (block_start
>= end
)
2020 warn (_("Block ends prematurely\n"));
2024 data
= block_start
+ uvalue
;
2025 if (block_start
+ uvalue
> end
|| data
< block_start
)
2027 warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue
);
2028 uvalue
= end
- block_start
;
2031 data
= block_start
+ uvalue
;
2033 data
= display_block (block_start
, uvalue
, end
, delimiter
);
2036 case DW_FORM_block4
:
2037 SAFE_BYTE_GET (uvalue
, data
, 4, end
);
2038 block_start
= data
+ 4;
2039 /* PR 17512: file: 3371-3907-0.004. */
2040 if (block_start
>= end
)
2042 warn (_("Block ends prematurely\n"));
2046 data
= block_start
+ uvalue
;
2047 if (block_start
+ uvalue
> end
2048 /* PR 17531: file: 5b5f0592. */
2049 || data
< block_start
)
2051 warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue
);
2052 uvalue
= end
- block_start
;
2055 data
= block_start
+ uvalue
;
2057 data
= display_block (block_start
, uvalue
, end
, delimiter
);
2062 printf (_("%c(indirect string, offset: 0x%s): %s"), delimiter
,
2063 dwarf_vmatoa ("x", uvalue
),
2064 fetch_indirect_string (uvalue
));
2067 case DW_FORM_line_strp
:
2069 printf (_("%c(indirect line string, offset: 0x%s): %s"), delimiter
,
2070 dwarf_vmatoa ("x", uvalue
),
2071 fetch_indirect_line_string (uvalue
));
2074 case DW_FORM_GNU_str_index
:
2077 const char * suffix
= strrchr (section
->name
, '.');
2078 bfd_boolean dwo
= (suffix
&& strcmp (suffix
, ".dwo") == 0) ? TRUE
: FALSE
;
2080 printf (_("%c(indexed string: 0x%s): %s"), delimiter
,
2081 dwarf_vmatoa ("x", uvalue
),
2082 fetch_indexed_string (uvalue
, this_set
, offset_size
, dwo
));
2086 case DW_FORM_GNU_strp_alt
:
2089 printf (_("%c(alt indirect string, offset: 0x%s) %s"), delimiter
,
2090 dwarf_vmatoa ("x", uvalue
),
2091 fetch_alt_indirect_string (uvalue
));
2095 case DW_FORM_indirect
:
2096 /* Handled above. */
2099 case DW_FORM_ref_sig8
:
2102 dwarf_vma high_bits
;
2105 SAFE_BYTE_GET64 (data
, &high_bits
, &uvalue
, end
);
2106 printf ("%csignature: 0x%s", delimiter
,
2107 dwarf_vmatoa64 (high_bits
, uvalue
, buf
, sizeof (buf
)));
2112 case DW_FORM_GNU_addr_index
:
2114 printf (_("%c(addr_index: 0x%s): %s"), delimiter
,
2115 dwarf_vmatoa ("x", uvalue
),
2116 fetch_indexed_value (uvalue
* pointer_size
, pointer_size
));
2120 warn (_("Unrecognized form: %lu\n"), form
);
2124 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
2125 && num_debug_info_entries
== 0
2126 && debug_info_p
!= NULL
)
2130 case DW_AT_frame_base
:
2131 have_frame_base
= 1;
2133 case DW_AT_location
:
2134 case DW_AT_GNU_locviews
:
2135 case DW_AT_string_length
:
2136 case DW_AT_return_addr
:
2137 case DW_AT_data_member_location
:
2138 case DW_AT_vtable_elem_location
:
2140 case DW_AT_static_link
:
2141 case DW_AT_use_location
:
2142 case DW_AT_call_value
:
2143 case DW_AT_GNU_call_site_value
:
2144 case DW_AT_call_data_value
:
2145 case DW_AT_GNU_call_site_data_value
:
2146 case DW_AT_call_target
:
2147 case DW_AT_GNU_call_site_target
:
2148 case DW_AT_call_target_clobbered
:
2149 case DW_AT_GNU_call_site_target_clobbered
:
2150 if ((dwarf_version
< 4
2151 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
2152 || form
== DW_FORM_sec_offset
)
2154 /* Process location list. */
2155 unsigned int lmax
= debug_info_p
->max_loc_offsets
;
2156 unsigned int num
= debug_info_p
->num_loc_offsets
;
2158 if (lmax
== 0 || num
>= lmax
)
2161 debug_info_p
->loc_offsets
= (dwarf_vma
*)
2162 xcrealloc (debug_info_p
->loc_offsets
,
2163 lmax
, sizeof (*debug_info_p
->loc_offsets
));
2164 debug_info_p
->loc_views
= (dwarf_vma
*)
2165 xcrealloc (debug_info_p
->loc_views
,
2166 lmax
, sizeof (*debug_info_p
->loc_views
));
2167 debug_info_p
->have_frame_base
= (int *)
2168 xcrealloc (debug_info_p
->have_frame_base
,
2169 lmax
, sizeof (*debug_info_p
->have_frame_base
));
2170 debug_info_p
->max_loc_offsets
= lmax
;
2172 if (this_set
!= NULL
)
2173 uvalue
+= this_set
->section_offsets
[DW_SECT_LOC
];
2174 debug_info_p
->have_frame_base
[num
] = have_frame_base
;
2175 if (attribute
!= DW_AT_GNU_locviews
)
2177 /* Corrupt DWARF info can produce more offsets than views.
2178 See PR 23062 for an example. */
2179 if (debug_info_p
->num_loc_offsets
2180 > debug_info_p
->num_loc_views
)
2181 warn (_("More location offset attributes than DW_AT_GNU_locview attributes\n"));
2184 debug_info_p
->loc_offsets
[num
] = uvalue
;
2185 debug_info_p
->num_loc_offsets
++;
2190 assert (debug_info_p
->num_loc_views
<= num
);
2191 num
= debug_info_p
->num_loc_views
;
2192 if (num
> debug_info_p
->num_loc_offsets
)
2193 warn (_("More DW_AT_GNU_locview attributes than location offset attributes\n"));
2196 debug_info_p
->loc_views
[num
] = uvalue
;
2197 debug_info_p
->num_loc_views
++;
2204 if (need_base_address
)
2205 debug_info_p
->base_address
= uvalue
;
2208 case DW_AT_GNU_addr_base
:
2209 debug_info_p
->addr_base
= uvalue
;
2212 case DW_AT_GNU_ranges_base
:
2213 debug_info_p
->ranges_base
= uvalue
;
2217 if ((dwarf_version
< 4
2218 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
2219 || form
== DW_FORM_sec_offset
)
2221 /* Process range list. */
2222 unsigned int lmax
= debug_info_p
->max_range_lists
;
2223 unsigned int num
= debug_info_p
->num_range_lists
;
2225 if (lmax
== 0 || num
>= lmax
)
2228 debug_info_p
->range_lists
= (dwarf_vma
*)
2229 xcrealloc (debug_info_p
->range_lists
,
2230 lmax
, sizeof (*debug_info_p
->range_lists
));
2231 debug_info_p
->max_range_lists
= lmax
;
2233 debug_info_p
->range_lists
[num
] = uvalue
;
2234 debug_info_p
->num_range_lists
++;
2238 case DW_AT_GNU_dwo_name
:
2239 case DW_AT_dwo_name
:
2244 dwo_name
= (const char *) fetch_indirect_string (uvalue
);
2246 case DW_FORM_GNU_str_index
:
2247 dwo_name
= fetch_indexed_string (uvalue
, this_set
, offset_size
, FALSE
);
2249 case DW_FORM_string
:
2250 dwo_name
= (const char *) orig_data
;
2253 warn (_("Unsupported form (%s) for attribute %s\n"),
2254 get_FORM_name (form
), get_AT_name (attribute
));
2255 dwo_name
= _("<unknown>");
2260 case DW_AT_comp_dir
:
2261 /* FIXME: Also extract a build-id in a CU/TU. */
2266 dwo_dir
= (const char *) fetch_indirect_string (uvalue
);
2268 case DW_FORM_line_strp
:
2269 dwo_dir
= (const char *) fetch_indirect_line_string (uvalue
);
2271 case DW_FORM_GNU_str_index
:
2272 dwo_dir
= fetch_indexed_string (uvalue
, this_set
, offset_size
, FALSE
);
2274 case DW_FORM_string
:
2275 dwo_dir
= (const char *) orig_data
;
2278 warn (_("Unsupported form (%s) for attribute %s\n"),
2279 get_FORM_name (form
), get_AT_name (attribute
));
2280 dwo_dir
= _("<unknown>");
2285 case DW_AT_GNU_dwo_id
:
2294 warn (_("Unsupported form (%s) for attribute %s\n"),
2295 get_FORM_name (form
), get_AT_name (attribute
));
2306 if (do_loc
|| attribute
== 0)
2309 /* For some attributes we can display further information. */
2316 case DW_INL_not_inlined
:
2317 printf (_("(not inlined)"));
2319 case DW_INL_inlined
:
2320 printf (_("(inlined)"));
2322 case DW_INL_declared_not_inlined
:
2323 printf (_("(declared as inline but ignored)"));
2325 case DW_INL_declared_inlined
:
2326 printf (_("(declared as inline and inlined)"));
2329 printf (_(" (Unknown inline attribute value: %s)"),
2330 dwarf_vmatoa ("x", uvalue
));
2335 case DW_AT_language
:
2339 /* Ordered by the numeric value of these constants. */
2340 case DW_LANG_C89
: printf ("(ANSI C)"); break;
2341 case DW_LANG_C
: printf ("(non-ANSI C)"); break;
2342 case DW_LANG_Ada83
: printf ("(Ada)"); break;
2343 case DW_LANG_C_plus_plus
: printf ("(C++)"); break;
2344 case DW_LANG_Cobol74
: printf ("(Cobol 74)"); break;
2345 case DW_LANG_Cobol85
: printf ("(Cobol 85)"); break;
2346 case DW_LANG_Fortran77
: printf ("(FORTRAN 77)"); break;
2347 case DW_LANG_Fortran90
: printf ("(Fortran 90)"); break;
2348 case DW_LANG_Pascal83
: printf ("(ANSI Pascal)"); break;
2349 case DW_LANG_Modula2
: printf ("(Modula 2)"); break;
2350 /* DWARF 2.1 values. */
2351 case DW_LANG_Java
: printf ("(Java)"); break;
2352 case DW_LANG_C99
: printf ("(ANSI C99)"); break;
2353 case DW_LANG_Ada95
: printf ("(ADA 95)"); break;
2354 case DW_LANG_Fortran95
: printf ("(Fortran 95)"); break;
2355 /* DWARF 3 values. */
2356 case DW_LANG_PLI
: printf ("(PLI)"); break;
2357 case DW_LANG_ObjC
: printf ("(Objective C)"); break;
2358 case DW_LANG_ObjC_plus_plus
: printf ("(Objective C++)"); break;
2359 case DW_LANG_UPC
: printf ("(Unified Parallel C)"); break;
2360 case DW_LANG_D
: printf ("(D)"); break;
2361 /* DWARF 4 values. */
2362 case DW_LANG_Python
: printf ("(Python)"); break;
2363 /* DWARF 5 values. */
2364 case DW_LANG_OpenCL
: printf ("(OpenCL)"); break;
2365 case DW_LANG_Go
: printf ("(Go)"); break;
2366 case DW_LANG_Modula3
: printf ("(Modula 3)"); break;
2367 case DW_LANG_Haskell
: printf ("(Haskell)"); break;
2368 case DW_LANG_C_plus_plus_03
: printf ("(C++03)"); break;
2369 case DW_LANG_C_plus_plus_11
: printf ("(C++11)"); break;
2370 case DW_LANG_OCaml
: printf ("(OCaml)"); break;
2371 case DW_LANG_Rust
: printf ("(Rust)"); break;
2372 case DW_LANG_C11
: printf ("(C11)"); break;
2373 case DW_LANG_Swift
: printf ("(Swift)"); break;
2374 case DW_LANG_Julia
: printf ("(Julia)"); break;
2375 case DW_LANG_Dylan
: printf ("(Dylan)"); break;
2376 case DW_LANG_C_plus_plus_14
: printf ("(C++14)"); break;
2377 case DW_LANG_Fortran03
: printf ("(Fortran 03)"); break;
2378 case DW_LANG_Fortran08
: printf ("(Fortran 08)"); break;
2379 case DW_LANG_RenderScript
: printf ("(RenderScript)"); break;
2380 /* MIPS extension. */
2381 case DW_LANG_Mips_Assembler
: printf ("(MIPS assembler)"); break;
2382 /* UPC extension. */
2383 case DW_LANG_Upc
: printf ("(Unified Parallel C)"); break;
2385 if (uvalue
>= DW_LANG_lo_user
&& uvalue
<= DW_LANG_hi_user
)
2386 printf (_("(implementation defined: %s)"),
2387 dwarf_vmatoa ("x", uvalue
));
2389 printf (_("(Unknown: %s)"), dwarf_vmatoa ("x", uvalue
));
2394 case DW_AT_encoding
:
2398 case DW_ATE_void
: printf ("(void)"); break;
2399 case DW_ATE_address
: printf ("(machine address)"); break;
2400 case DW_ATE_boolean
: printf ("(boolean)"); break;
2401 case DW_ATE_complex_float
: printf ("(complex float)"); break;
2402 case DW_ATE_float
: printf ("(float)"); break;
2403 case DW_ATE_signed
: printf ("(signed)"); break;
2404 case DW_ATE_signed_char
: printf ("(signed char)"); break;
2405 case DW_ATE_unsigned
: printf ("(unsigned)"); break;
2406 case DW_ATE_unsigned_char
: printf ("(unsigned char)"); break;
2407 /* DWARF 2.1 values: */
2408 case DW_ATE_imaginary_float
: printf ("(imaginary float)"); break;
2409 case DW_ATE_decimal_float
: printf ("(decimal float)"); break;
2410 /* DWARF 3 values: */
2411 case DW_ATE_packed_decimal
: printf ("(packed_decimal)"); break;
2412 case DW_ATE_numeric_string
: printf ("(numeric_string)"); break;
2413 case DW_ATE_edited
: printf ("(edited)"); break;
2414 case DW_ATE_signed_fixed
: printf ("(signed_fixed)"); break;
2415 case DW_ATE_unsigned_fixed
: printf ("(unsigned_fixed)"); break;
2416 /* DWARF 4 values: */
2417 case DW_ATE_UTF
: printf ("(unicode string)"); break;
2418 /* DWARF 5 values: */
2419 case DW_ATE_UCS
: printf ("(UCS)"); break;
2420 case DW_ATE_ASCII
: printf ("(ASCII)"); break;
2422 /* HP extensions: */
2423 case DW_ATE_HP_float80
: printf ("(HP_float80)"); break;
2424 case DW_ATE_HP_complex_float80
: printf ("(HP_complex_float80)"); break;
2425 case DW_ATE_HP_float128
: printf ("(HP_float128)"); break;
2426 case DW_ATE_HP_complex_float128
:printf ("(HP_complex_float128)"); break;
2427 case DW_ATE_HP_floathpintel
: printf ("(HP_floathpintel)"); break;
2428 case DW_ATE_HP_imaginary_float80
: printf ("(HP_imaginary_float80)"); break;
2429 case DW_ATE_HP_imaginary_float128
: printf ("(HP_imaginary_float128)"); break;
2432 if (uvalue
>= DW_ATE_lo_user
2433 && uvalue
<= DW_ATE_hi_user
)
2434 printf (_("(user defined type)"));
2436 printf (_("(unknown type)"));
2441 case DW_AT_accessibility
:
2445 case DW_ACCESS_public
: printf ("(public)"); break;
2446 case DW_ACCESS_protected
: printf ("(protected)"); break;
2447 case DW_ACCESS_private
: printf ("(private)"); break;
2449 printf (_("(unknown accessibility)"));
2454 case DW_AT_visibility
:
2458 case DW_VIS_local
: printf ("(local)"); break;
2459 case DW_VIS_exported
: printf ("(exported)"); break;
2460 case DW_VIS_qualified
: printf ("(qualified)"); break;
2461 default: printf (_("(unknown visibility)")); break;
2465 case DW_AT_endianity
:
2469 case DW_END_default
: printf ("(default)"); break;
2470 case DW_END_big
: printf ("(big)"); break;
2471 case DW_END_little
: printf ("(little)"); break;
2473 if (uvalue
>= DW_END_lo_user
&& uvalue
<= DW_END_hi_user
)
2474 printf (_("(user specified)"));
2476 printf (_("(unknown endianity)"));
2481 case DW_AT_virtuality
:
2485 case DW_VIRTUALITY_none
: printf ("(none)"); break;
2486 case DW_VIRTUALITY_virtual
: printf ("(virtual)"); break;
2487 case DW_VIRTUALITY_pure_virtual
:printf ("(pure_virtual)"); break;
2488 default: printf (_("(unknown virtuality)")); break;
2492 case DW_AT_identifier_case
:
2496 case DW_ID_case_sensitive
: printf ("(case_sensitive)"); break;
2497 case DW_ID_up_case
: printf ("(up_case)"); break;
2498 case DW_ID_down_case
: printf ("(down_case)"); break;
2499 case DW_ID_case_insensitive
: printf ("(case_insensitive)"); break;
2500 default: printf (_("(unknown case)")); break;
2504 case DW_AT_calling_convention
:
2508 case DW_CC_normal
: printf ("(normal)"); break;
2509 case DW_CC_program
: printf ("(program)"); break;
2510 case DW_CC_nocall
: printf ("(nocall)"); break;
2511 case DW_CC_pass_by_reference
: printf ("(pass by ref)"); break;
2512 case DW_CC_pass_by_value
: printf ("(pass by value)"); break;
2513 case DW_CC_GNU_renesas_sh
: printf ("(Rensas SH)"); break;
2514 case DW_CC_GNU_borland_fastcall_i386
: printf ("(Borland fastcall i386)"); break;
2516 if (uvalue
>= DW_CC_lo_user
2517 && uvalue
<= DW_CC_hi_user
)
2518 printf (_("(user defined)"));
2520 printf (_("(unknown convention)"));
2524 case DW_AT_ordering
:
2529 case -1: printf (_("(undefined)")); break;
2530 case 0: printf ("(row major)"); break;
2531 case 1: printf ("(column major)"); break;
2535 case DW_AT_decimal_sign
:
2539 case DW_DS_unsigned
: printf (_("(unsigned)")); break;
2540 case DW_DS_leading_overpunch
: printf (_("(leading overpunch)")); break;
2541 case DW_DS_trailing_overpunch
: printf (_("(trailing overpunch)")); break;
2542 case DW_DS_leading_separate
: printf (_("(leading separate)")); break;
2543 case DW_DS_trailing_separate
: printf (_("(trailing separate)")); break;
2544 default: printf (_("(unrecognised)")); break;
2548 case DW_AT_defaulted
:
2552 case DW_DEFAULTED_no
: printf (_("(no)")); break;
2553 case DW_DEFAULTED_in_class
: printf (_("(in class)")); break;
2554 case DW_DEFAULTED_out_of_class
: printf (_("(out of class)")); break;
2555 default: printf (_("(unrecognised)")); break;
2559 case DW_AT_discr_list
:
2563 case DW_DSC_label
: printf (_("(label)")); break;
2564 case DW_DSC_range
: printf (_("(range)")); break;
2565 default: printf (_("(unrecognised)")); break;
2569 case DW_AT_frame_base
:
2570 have_frame_base
= 1;
2572 case DW_AT_location
:
2573 case DW_AT_string_length
:
2574 case DW_AT_return_addr
:
2575 case DW_AT_data_member_location
:
2576 case DW_AT_vtable_elem_location
:
2578 case DW_AT_static_link
:
2579 case DW_AT_use_location
:
2580 case DW_AT_call_value
:
2581 case DW_AT_GNU_call_site_value
:
2582 case DW_AT_call_data_value
:
2583 case DW_AT_GNU_call_site_data_value
:
2584 case DW_AT_call_target
:
2585 case DW_AT_GNU_call_site_target
:
2586 case DW_AT_call_target_clobbered
:
2587 case DW_AT_GNU_call_site_target_clobbered
:
2588 if ((dwarf_version
< 4
2589 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
2590 || form
== DW_FORM_sec_offset
)
2591 printf (_(" (location list)"));
2593 case DW_AT_allocated
:
2594 case DW_AT_associated
:
2595 case DW_AT_data_location
:
2597 case DW_AT_upper_bound
:
2598 case DW_AT_lower_bound
:
2601 int need_frame_base
;
2604 need_frame_base
= decode_location_expression (block_start
,
2609 cu_offset
, section
);
2611 if (need_frame_base
&& !have_frame_base
)
2612 printf (_(" [without DW_AT_frame_base]"));
2616 case DW_AT_data_bit_offset
:
2617 case DW_AT_byte_size
:
2618 case DW_AT_bit_size
:
2619 case DW_AT_string_length_byte_size
:
2620 case DW_AT_string_length_bit_size
:
2621 case DW_AT_bit_stride
:
2622 if (form
== DW_FORM_exprloc
)
2625 (void) decode_location_expression (block_start
, pointer_size
,
2626 offset_size
, dwarf_version
,
2627 uvalue
, cu_offset
, section
);
2634 if (form
== DW_FORM_ref_sig8
2635 || form
== DW_FORM_GNU_ref_alt
)
2638 if (form
== DW_FORM_ref1
2639 || form
== DW_FORM_ref2
2640 || form
== DW_FORM_ref4
2641 || form
== DW_FORM_ref_udata
)
2642 uvalue
+= cu_offset
;
2644 if (uvalue
>= section
->size
)
2645 warn (_("Offset %s used as value for DW_AT_import attribute of DIE at offset 0x%lx is too big.\n"),
2646 dwarf_vmatoa ("x", uvalue
),
2647 (unsigned long) (orig_data
- section
->start
));
2650 unsigned long abbrev_number
;
2651 abbrev_entry
* entry
;
2653 abbrev_number
= read_uleb128 (section
->start
+ uvalue
, NULL
, end
);
2655 printf (_("\t[Abbrev Number: %ld"), abbrev_number
);
2656 /* Don't look up abbrev for DW_FORM_ref_addr, as it very often will
2657 use different abbrev table, and we don't track .debug_info chunks
2659 if (form
!= DW_FORM_ref_addr
)
2661 for (entry
= first_abbrev
; entry
!= NULL
; entry
= entry
->next
)
2662 if (entry
->entry
== abbrev_number
)
2665 printf (" (%s)", get_TAG_name (entry
->tag
));
2679 static unsigned char *
2680 read_and_display_attr (unsigned long attribute
,
2682 dwarf_signed_vma implicit_const
,
2683 unsigned char * data
,
2684 unsigned char * end
,
2685 dwarf_vma cu_offset
,
2686 dwarf_vma pointer_size
,
2687 dwarf_vma offset_size
,
2689 debug_info
* debug_info_p
,
2691 struct dwarf_section
* section
,
2692 struct cu_tu_set
* this_set
)
2695 printf (" %-18s:", get_AT_name (attribute
));
2696 data
= read_and_display_attr_value (attribute
, form
, implicit_const
, data
, end
,
2697 cu_offset
, pointer_size
, offset_size
,
2698 dwarf_version
, debug_info_p
,
2699 do_loc
, section
, this_set
, ' ');
2705 /* Like load_debug_section, but if the ordinary call fails, and we are
2706 following debug links, and we have been able to load a separate debug
2707 info file, then attempt to load the requested section from the separate
2711 load_debug_section_with_follow (enum dwarf_section_display_enum sec_enum
,
2714 if (load_debug_section (sec_enum
, data
))
2716 if (data
== separate_debug_file
)
2717 debug_displays
[sec_enum
].section
.filename
= separate_debug_filename
;
2719 /* FIXME: We should check to see if there is a separate debug info file
2720 that also contains this section, and if so, issue a warning. */
2724 if (do_follow_links
&& separate_debug_file
!= NULL
)
2725 if (load_debug_section (sec_enum
, separate_debug_file
))
2727 debug_displays
[sec_enum
].section
.filename
= separate_debug_filename
;
2735 introduce (struct dwarf_section
* section
, bfd_boolean raw
)
2739 if (do_follow_links
&& section
->filename
)
2740 printf (_("Raw dump of debug contents of section %s (loaded from %s):\n\n"),
2741 section
->name
, section
->filename
);
2743 printf (_("Raw dump of debug contents of section %s:\n\n"), section
->name
);
2747 if (do_follow_links
&& section
->filename
)
2748 printf (_("Contents of the %s section (loaded from %s):\n\n"),
2749 section
->name
, section
->filename
);
2751 printf (_("Contents of the %s section:\n\n"), section
->name
);
2755 /* Process the contents of a .debug_info section.
2756 If do_loc is TRUE then we are scanning for location lists and dwo tags
2757 and we do not want to display anything to the user.
2758 If do_types is TRUE, we are processing a .debug_types section instead of
2759 a .debug_info section.
2760 The information displayed is restricted by the values in DWARF_START_DIE
2761 and DWARF_CUTOFF_LEVEL.
2762 Returns TRUE upon success. Otherwise an error or warning message is
2763 printed and FALSE is returned. */
2766 process_debug_info (struct dwarf_section
* section
,
2768 enum dwarf_section_display_enum abbrev_sec
,
2770 bfd_boolean do_types
)
2772 unsigned char *start
= section
->start
;
2773 unsigned char *end
= start
+ section
->size
;
2774 unsigned char *section_begin
;
2776 unsigned int num_units
= 0;
2778 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
2779 && num_debug_info_entries
== 0
2784 /* First scan the section to get the number of comp units. */
2785 for (section_begin
= start
, num_units
= 0; section_begin
< end
;
2788 /* Read the first 4 bytes. For a 32-bit DWARF section, this
2789 will be the length. For a 64-bit DWARF section, it'll be
2790 the escape code 0xffffffff followed by an 8 byte length. */
2791 SAFE_BYTE_GET (length
, section_begin
, 4, end
);
2793 if (length
== 0xffffffff)
2795 SAFE_BYTE_GET (length
, section_begin
+ 4, 8, end
);
2796 section_begin
+= length
+ 12;
2798 else if (length
>= 0xfffffff0 && length
< 0xffffffff)
2800 warn (_("Reserved length value (0x%s) found in section %s\n"),
2801 dwarf_vmatoa ("x", length
), section
->name
);
2805 section_begin
+= length
+ 4;
2807 /* Negative values are illegal, they may even cause infinite
2808 looping. This can happen if we can't accurately apply
2809 relocations to an object file, or if the file is corrupt. */
2810 if ((signed long) length
<= 0 || section_begin
< start
)
2812 warn (_("Corrupt unit length (0x%s) found in section %s\n"),
2813 dwarf_vmatoa ("x", length
), section
->name
);
2820 error (_("No comp units in %s section ?\n"), section
->name
);
2824 /* Then allocate an array to hold the information. */
2825 debug_information
= (debug_info
*) cmalloc (num_units
,
2826 sizeof (* debug_information
));
2827 if (debug_information
== NULL
)
2829 error (_("Not enough memory for a debug info array of %u entries\n"),
2831 alloc_num_debug_info_entries
= num_debug_info_entries
= 0;
2835 /* PR 17531: file: 92ca3797.
2836 We cannot rely upon the debug_information array being initialised
2837 before it is used. A corrupt file could easily contain references
2838 to a unit for which information has not been made available. So
2839 we ensure that the array is zeroed here. */
2840 memset (debug_information
, 0, num_units
* sizeof (*debug_information
));
2842 alloc_num_debug_info_entries
= num_units
;
2847 load_debug_section_with_follow (str
, file
);
2848 load_debug_section_with_follow (line_str
, file
);
2849 load_debug_section_with_follow (str_dwo
, file
);
2850 load_debug_section_with_follow (str_index
, file
);
2851 load_debug_section_with_follow (str_index_dwo
, file
);
2852 load_debug_section_with_follow (debug_addr
, file
);
2855 load_debug_section_with_follow (abbrev_sec
, file
);
2856 if (debug_displays
[abbrev_sec
].section
.start
== NULL
)
2858 warn (_("Unable to locate %s section!\n"),
2859 debug_displays
[abbrev_sec
].section
.uncompressed_name
);
2863 if (!do_loc
&& dwarf_start_die
== 0)
2864 introduce (section
, FALSE
);
2866 for (section_begin
= start
, unit
= 0; start
< end
; unit
++)
2868 DWARF2_Internal_CompUnit compunit
;
2869 unsigned char *hdrptr
;
2870 unsigned char *tags
;
2871 int level
, last_level
, saved_level
;
2872 dwarf_vma cu_offset
;
2873 unsigned long sec_off
;
2874 unsigned int offset_size
;
2875 unsigned int initial_length_size
;
2876 dwarf_vma signature_high
= 0;
2877 dwarf_vma signature_low
= 0;
2878 dwarf_vma type_offset
= 0;
2879 struct cu_tu_set
*this_set
;
2880 dwarf_vma abbrev_base
;
2885 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 4, end
);
2887 if (compunit
.cu_length
== 0xffffffff)
2889 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 8, end
);
2891 initial_length_size
= 12;
2896 initial_length_size
= 4;
2899 SAFE_BYTE_GET_AND_INC (compunit
.cu_version
, hdrptr
, 2, end
);
2901 cu_offset
= start
- section_begin
;
2903 this_set
= find_cu_tu_set_v2 (cu_offset
, do_types
);
2905 if (compunit
.cu_version
< 5)
2907 compunit
.cu_unit_type
= DW_UT_compile
;
2908 /* Initialize it due to a false compiler warning. */
2909 compunit
.cu_pointer_size
= -1;
2913 SAFE_BYTE_GET_AND_INC (compunit
.cu_unit_type
, hdrptr
, 1, end
);
2914 do_types
= (compunit
.cu_unit_type
== DW_UT_type
);
2916 SAFE_BYTE_GET_AND_INC (compunit
.cu_pointer_size
, hdrptr
, 1, end
);
2919 SAFE_BYTE_GET_AND_INC (compunit
.cu_abbrev_offset
, hdrptr
, offset_size
, end
);
2921 if (this_set
== NULL
)
2924 abbrev_size
= debug_displays
[abbrev_sec
].section
.size
;
2928 abbrev_base
= this_set
->section_offsets
[DW_SECT_ABBREV
];
2929 abbrev_size
= this_set
->section_sizes
[DW_SECT_ABBREV
];
2932 if (compunit
.cu_version
< 5)
2933 SAFE_BYTE_GET_AND_INC (compunit
.cu_pointer_size
, hdrptr
, 1, end
);
2935 /* PR 17512: file: 001-108546-0.001:0.1. */
2936 if (compunit
.cu_pointer_size
< 2 || compunit
.cu_pointer_size
> 8)
2938 warn (_("Invalid pointer size (%d) in compunit header, using %d instead\n"),
2939 compunit
.cu_pointer_size
, offset_size
);
2940 compunit
.cu_pointer_size
= offset_size
;
2945 SAFE_BYTE_GET64 (hdrptr
, &signature_high
, &signature_low
, end
);
2947 SAFE_BYTE_GET_AND_INC (type_offset
, hdrptr
, offset_size
, end
);
2950 if (dwarf_start_die
> (cu_offset
+ compunit
.cu_length
2951 + initial_length_size
))
2953 start
= section_begin
+ cu_offset
+ compunit
.cu_length
2954 + initial_length_size
;
2958 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
2959 && num_debug_info_entries
== 0
2962 debug_information
[unit
].cu_offset
= cu_offset
;
2963 debug_information
[unit
].pointer_size
2964 = compunit
.cu_pointer_size
;
2965 debug_information
[unit
].offset_size
= offset_size
;
2966 debug_information
[unit
].dwarf_version
= compunit
.cu_version
;
2967 debug_information
[unit
].base_address
= 0;
2968 debug_information
[unit
].addr_base
= DEBUG_INFO_UNAVAILABLE
;
2969 debug_information
[unit
].ranges_base
= DEBUG_INFO_UNAVAILABLE
;
2970 debug_information
[unit
].loc_offsets
= NULL
;
2971 debug_information
[unit
].have_frame_base
= NULL
;
2972 debug_information
[unit
].max_loc_offsets
= 0;
2973 debug_information
[unit
].num_loc_offsets
= 0;
2974 debug_information
[unit
].range_lists
= NULL
;
2975 debug_information
[unit
].max_range_lists
= 0;
2976 debug_information
[unit
].num_range_lists
= 0;
2979 if (!do_loc
&& dwarf_start_die
== 0)
2981 printf (_(" Compilation Unit @ offset 0x%s:\n"),
2982 dwarf_vmatoa ("x", cu_offset
));
2983 printf (_(" Length: 0x%s (%s)\n"),
2984 dwarf_vmatoa ("x", compunit
.cu_length
),
2985 offset_size
== 8 ? "64-bit" : "32-bit");
2986 printf (_(" Version: %d\n"), compunit
.cu_version
);
2987 printf (_(" Abbrev Offset: 0x%s\n"),
2988 dwarf_vmatoa ("x", compunit
.cu_abbrev_offset
));
2989 printf (_(" Pointer Size: %d\n"), compunit
.cu_pointer_size
);
2994 printf (_(" Signature: 0x%s\n"),
2995 dwarf_vmatoa64 (signature_high
, signature_low
,
2996 buf
, sizeof (buf
)));
2997 printf (_(" Type Offset: 0x%s\n"),
2998 dwarf_vmatoa ("x", type_offset
));
3000 if (this_set
!= NULL
)
3002 dwarf_vma
*offsets
= this_set
->section_offsets
;
3003 size_t *sizes
= this_set
->section_sizes
;
3005 printf (_(" Section contributions:\n"));
3006 printf (_(" .debug_abbrev.dwo: 0x%s 0x%s\n"),
3007 dwarf_vmatoa ("x", offsets
[DW_SECT_ABBREV
]),
3008 dwarf_vmatoa ("x", sizes
[DW_SECT_ABBREV
]));
3009 printf (_(" .debug_line.dwo: 0x%s 0x%s\n"),
3010 dwarf_vmatoa ("x", offsets
[DW_SECT_LINE
]),
3011 dwarf_vmatoa ("x", sizes
[DW_SECT_LINE
]));
3012 printf (_(" .debug_loc.dwo: 0x%s 0x%s\n"),
3013 dwarf_vmatoa ("x", offsets
[DW_SECT_LOC
]),
3014 dwarf_vmatoa ("x", sizes
[DW_SECT_LOC
]));
3015 printf (_(" .debug_str_offsets.dwo: 0x%s 0x%s\n"),
3016 dwarf_vmatoa ("x", offsets
[DW_SECT_STR_OFFSETS
]),
3017 dwarf_vmatoa ("x", sizes
[DW_SECT_STR_OFFSETS
]));
3021 sec_off
= cu_offset
+ initial_length_size
;
3022 if (sec_off
+ compunit
.cu_length
< sec_off
3023 || sec_off
+ compunit
.cu_length
> section
->size
)
3025 warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"),
3027 (unsigned long) cu_offset
,
3028 dwarf_vmatoa ("x", compunit
.cu_length
));
3034 start
+= compunit
.cu_length
+ initial_length_size
;
3036 if (compunit
.cu_version
< 2 || compunit
.cu_version
> 5)
3038 warn (_("CU at offset %s contains corrupt or "
3039 "unsupported version number: %d.\n"),
3040 dwarf_vmatoa ("x", cu_offset
), compunit
.cu_version
);
3044 if (compunit
.cu_unit_type
!= DW_UT_compile
3045 && compunit
.cu_unit_type
!= DW_UT_type
)
3047 warn (_("CU at offset %s contains corrupt or "
3048 "unsupported unit type: %d.\n"),
3049 dwarf_vmatoa ("x", cu_offset
), compunit
.cu_unit_type
);
3055 /* Process the abbrevs used by this compilation unit. */
3056 if (compunit
.cu_abbrev_offset
>= abbrev_size
)
3057 warn (_("Debug info is corrupted, abbrev offset (%lx) is larger than abbrev section size (%lx)\n"),
3058 (unsigned long) compunit
.cu_abbrev_offset
,
3059 (unsigned long) abbrev_size
);
3060 /* PR 17531: file:4bcd9ce9. */
3061 else if ((abbrev_base
+ abbrev_size
)
3062 > debug_displays
[abbrev_sec
].section
.size
)
3063 warn (_("Debug info is corrupted, abbrev size (%lx) is larger than abbrev section size (%lx)\n"),
3064 (unsigned long) abbrev_base
+ abbrev_size
,
3065 (unsigned long) debug_displays
[abbrev_sec
].section
.size
);
3067 process_abbrev_section
3068 (((unsigned char *) debug_displays
[abbrev_sec
].section
.start
3069 + abbrev_base
+ compunit
.cu_abbrev_offset
),
3070 ((unsigned char *) debug_displays
[abbrev_sec
].section
.start
3071 + abbrev_base
+ abbrev_size
));
3076 while (tags
< start
)
3078 unsigned int bytes_read
;
3079 unsigned long abbrev_number
;
3080 unsigned long die_offset
;
3081 abbrev_entry
*entry
;
3083 int do_printing
= 1;
3085 die_offset
= tags
- section_begin
;
3087 abbrev_number
= read_uleb128 (tags
, & bytes_read
, start
);
3090 /* A null DIE marks the end of a list of siblings or it may also be
3091 a section padding. */
3092 if (abbrev_number
== 0)
3094 /* Check if it can be a section padding for the last CU. */
3095 if (level
== 0 && start
== end
)
3099 for (chk
= tags
; chk
< start
; chk
++)
3106 if (!do_loc
&& die_offset
>= dwarf_start_die
3107 && (dwarf_cutoff_level
== -1
3108 || level
< dwarf_cutoff_level
))
3109 printf (_(" <%d><%lx>: Abbrev Number: 0\n"),
3115 static unsigned num_bogus_warns
= 0;
3117 if (num_bogus_warns
< 3)
3119 warn (_("Bogus end-of-siblings marker detected at offset %lx in %s section\n"),
3120 die_offset
, section
->name
);
3122 if (num_bogus_warns
== 3)
3123 warn (_("Further warnings about bogus end-of-sibling markers suppressed\n"));
3126 if (dwarf_start_die
!= 0 && level
< saved_level
)
3133 if (dwarf_start_die
!= 0 && die_offset
< dwarf_start_die
)
3137 if (dwarf_start_die
!= 0 && die_offset
== dwarf_start_die
)
3138 saved_level
= level
;
3139 do_printing
= (dwarf_cutoff_level
== -1
3140 || level
< dwarf_cutoff_level
);
3142 printf (_(" <%d><%lx>: Abbrev Number: %lu"),
3143 level
, die_offset
, abbrev_number
);
3144 else if (dwarf_cutoff_level
== -1
3145 || last_level
< dwarf_cutoff_level
)
3146 printf (_(" <%d><%lx>: ...\n"), level
, die_offset
);
3151 /* Scan through the abbreviation list until we reach the
3153 for (entry
= first_abbrev
;
3154 entry
&& entry
->entry
!= abbrev_number
;
3155 entry
= entry
->next
)
3160 if (!do_loc
&& do_printing
)
3165 warn (_("DIE at offset 0x%lx refers to abbreviation number %lu which does not exist\n"),
3166 die_offset
, abbrev_number
);
3170 if (!do_loc
&& do_printing
)
3171 printf (" (%s)\n", get_TAG_name (entry
->tag
));
3176 need_base_address
= 0;
3178 case DW_TAG_compile_unit
:
3179 need_base_address
= 1;
3180 need_dwo_info
= do_loc
;
3182 case DW_TAG_entry_point
:
3183 case DW_TAG_subprogram
:
3184 need_base_address
= 0;
3185 /* Assuming that there is no DW_AT_frame_base. */
3186 have_frame_base
= 0;
3190 debug_info
*debug_info_p
=
3191 (debug_information
&& unit
< alloc_num_debug_info_entries
)
3192 ? debug_information
+ unit
: NULL
;
3194 assert (!debug_info_p
3195 || (debug_info_p
->num_loc_offsets
3196 == debug_info_p
->num_loc_views
));
3198 for (attr
= entry
->first_attr
;
3199 attr
&& attr
->attribute
;
3202 if (! do_loc
&& do_printing
)
3203 /* Show the offset from where the tag was extracted. */
3204 printf (" <%lx>", (unsigned long)(tags
- section_begin
));
3206 tags
= read_and_display_attr (attr
->attribute
,
3208 attr
->implicit_const
,
3212 compunit
.cu_pointer_size
,
3214 compunit
.cu_version
,
3216 do_loc
|| ! do_printing
,
3221 /* If a locview attribute appears before a location one,
3222 make sure we don't associate it with an earlier
3225 switch (debug_info_p
->num_loc_offsets
- debug_info_p
->num_loc_views
)
3228 debug_info_p
->loc_views
[debug_info_p
->num_loc_views
] = vm1
;
3229 debug_info_p
->num_loc_views
++;
3230 assert (debug_info_p
->num_loc_views
3231 == debug_info_p
->num_loc_offsets
);
3238 warn(_("DIE has locviews without loclist\n"));
3239 debug_info_p
->num_loc_views
--;
3246 if (entry
->children
)
3251 /* Set num_debug_info_entries here so that it can be used to check if
3252 we need to process .debug_loc and .debug_ranges sections. */
3253 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
3254 && num_debug_info_entries
== 0
3257 if (num_units
> alloc_num_debug_info_entries
)
3258 num_debug_info_entries
= alloc_num_debug_info_entries
;
3260 num_debug_info_entries
= num_units
;
3269 /* Locate and scan the .debug_info section in the file and record the pointer
3270 sizes and offsets for the compilation units in it. Usually an executable
3271 will have just one pointer size, but this is not guaranteed, and so we try
3272 not to make any assumptions. Returns zero upon failure, or the number of
3273 compilation units upon success. */
3276 load_debug_info (void * file
)
3278 /* If we have already tried and failed to load the .debug_info
3279 section then do not bother to repeat the task. */
3280 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
3283 /* If we already have the information there is nothing else to do. */
3284 if (num_debug_info_entries
> 0)
3285 return num_debug_info_entries
;
3287 /* If this is a DWARF package file, load the CU and TU indexes. */
3288 (void) load_cu_tu_indexes (file
);
3290 if (load_debug_section_with_follow (info
, file
)
3291 && process_debug_info (&debug_displays
[info
].section
, file
, abbrev
, TRUE
, FALSE
))
3292 return num_debug_info_entries
;
3294 if (load_debug_section_with_follow (info_dwo
, file
)
3295 && process_debug_info (&debug_displays
[info_dwo
].section
, file
,
3296 abbrev_dwo
, TRUE
, FALSE
))
3297 return num_debug_info_entries
;
3299 num_debug_info_entries
= DEBUG_INFO_UNAVAILABLE
;
3303 /* Read a DWARF .debug_line section header starting at DATA.
3304 Upon success returns an updated DATA pointer and the LINFO
3305 structure and the END_OF_SEQUENCE pointer will be filled in.
3306 Otherwise returns NULL. */
3308 static unsigned char *
3309 read_debug_line_header (struct dwarf_section
* section
,
3310 unsigned char * data
,
3311 unsigned char * end
,
3312 DWARF2_Internal_LineInfo
* linfo
,
3313 unsigned char ** end_of_sequence
)
3315 unsigned char *hdrptr
;
3316 unsigned int initial_length_size
;
3317 unsigned char address_size
, segment_selector_size
;
3319 /* Extract information from the Line Number Program Header.
3320 (section 6.2.4 in the Dwarf3 doc). */
3323 /* Get and check the length of the block. */
3324 SAFE_BYTE_GET_AND_INC (linfo
->li_length
, hdrptr
, 4, end
);
3326 if (linfo
->li_length
== 0xffffffff)
3328 /* This section is 64-bit DWARF 3. */
3329 SAFE_BYTE_GET_AND_INC (linfo
->li_length
, hdrptr
, 8, end
);
3330 linfo
->li_offset_size
= 8;
3331 initial_length_size
= 12;
3335 linfo
->li_offset_size
= 4;
3336 initial_length_size
= 4;
3339 if (linfo
->li_length
+ initial_length_size
> section
->size
)
3341 /* If the length field has a relocation against it, then we should
3342 not complain if it is inaccurate (and probably negative). This
3343 happens in object files when the .debug_line section is actually
3344 comprised of several different .debug_line.* sections, (some of
3345 which may be removed by linker garbage collection), and a relocation
3346 is used to compute the correct length once that is done. */
3347 if (reloc_at (section
, (hdrptr
- section
->start
) - linfo
->li_offset_size
))
3349 linfo
->li_length
= (end
- data
) - initial_length_size
;
3353 warn (_("The length field (0x%lx) in the debug_line header is wrong - the section is too small\n"),
3354 (long) linfo
->li_length
);
3359 /* Get and check the version number. */
3360 SAFE_BYTE_GET_AND_INC (linfo
->li_version
, hdrptr
, 2, end
);
3362 if (linfo
->li_version
!= 2
3363 && linfo
->li_version
!= 3
3364 && linfo
->li_version
!= 4
3365 && linfo
->li_version
!= 5)
3367 warn (_("Only DWARF version 2, 3, 4 and 5 line info "
3368 "is currently supported.\n"));
3372 if (linfo
->li_version
>= 5)
3374 SAFE_BYTE_GET_AND_INC (address_size
, hdrptr
, 1, end
);
3376 SAFE_BYTE_GET_AND_INC (segment_selector_size
, hdrptr
, 1, end
);
3377 if (segment_selector_size
!= 0)
3379 warn (_("The %s section contains "
3380 "unsupported segment selector size: %d.\n"),
3381 section
->name
, segment_selector_size
);
3386 SAFE_BYTE_GET_AND_INC (linfo
->li_prologue_length
, hdrptr
,
3387 linfo
->li_offset_size
, end
);
3388 SAFE_BYTE_GET_AND_INC (linfo
->li_min_insn_length
, hdrptr
, 1, end
);
3390 if (linfo
->li_version
>= 4)
3392 SAFE_BYTE_GET_AND_INC (linfo
->li_max_ops_per_insn
, hdrptr
, 1, end
);
3394 if (linfo
->li_max_ops_per_insn
== 0)
3396 warn (_("Invalid maximum operations per insn.\n"));
3401 linfo
->li_max_ops_per_insn
= 1;
3403 SAFE_BYTE_GET_AND_INC (linfo
->li_default_is_stmt
, hdrptr
, 1, end
);
3404 SAFE_SIGNED_BYTE_GET_AND_INC (linfo
->li_line_base
, hdrptr
, 1, end
);
3405 SAFE_BYTE_GET_AND_INC (linfo
->li_line_range
, hdrptr
, 1, end
);
3406 SAFE_BYTE_GET_AND_INC (linfo
->li_opcode_base
, hdrptr
, 1, end
);
3408 * end_of_sequence
= data
+ linfo
->li_length
+ initial_length_size
;
3409 /* PR 17512: file:002-117414-0.004. */
3410 if (* end_of_sequence
> end
)
3412 warn (_("Line length %s extends beyond end of section\n"),
3413 dwarf_vmatoa ("u", linfo
->li_length
));
3414 * end_of_sequence
= end
;
3421 static unsigned char *
3422 display_formatted_table (unsigned char * data
,
3423 unsigned char * start
,
3424 unsigned char * end
,
3425 const DWARF2_Internal_LineInfo
* linfo
,
3426 struct dwarf_section
* section
,
3429 unsigned char *format_start
, format_count
, *format
, formati
;
3430 dwarf_vma data_count
, datai
;
3431 unsigned int bytes_read
, namepass
, last_entry
= 0;
3433 SAFE_BYTE_GET_AND_INC (format_count
, data
, 1, end
);
3434 format_start
= data
;
3435 for (formati
= 0; formati
< format_count
; formati
++)
3437 read_uleb128 (data
, & bytes_read
, end
);
3439 read_uleb128 (data
, & bytes_read
, end
);
3443 warn (_("Corrupt %s format table entry\n"), what
);
3448 data_count
= read_uleb128 (data
, & bytes_read
, end
);
3452 warn (_("Corrupt %s list\n"), what
);
3456 if (data_count
== 0)
3458 printf (_("\n The %s Table is empty.\n"), what
);
3462 printf (_("\n The %s Table (offset 0x%lx):\n"), what
,
3463 (long)(data
- start
));
3465 printf (_(" Entry"));
3466 /* Delay displaying name as the last entry for better screen layout. */
3467 for (namepass
= 0; namepass
< 2; namepass
++)
3469 format
= format_start
;
3470 for (formati
= 0; formati
< format_count
; formati
++)
3472 dwarf_vma content_type
;
3474 content_type
= read_uleb128 (format
, & bytes_read
, end
);
3475 format
+= bytes_read
;
3476 if ((content_type
== DW_LNCT_path
) == (namepass
== 1))
3477 switch (content_type
)
3480 printf (_("\tName"));
3482 case DW_LNCT_directory_index
:
3483 printf (_("\tDir"));
3485 case DW_LNCT_timestamp
:
3486 printf (_("\tTime"));
3489 printf (_("\tSize"));
3492 printf (_("\tMD5"));
3495 printf (_("\t(Unknown format content type %s)"),
3496 dwarf_vmatoa ("u", content_type
));
3498 read_uleb128 (format
, & bytes_read
, end
);
3499 format
+= bytes_read
;
3504 for (datai
= 0; datai
< data_count
; datai
++)
3506 unsigned char *datapass
= data
;
3508 printf (" %d", last_entry
++);
3509 /* Delay displaying name as the last entry for better screen layout. */
3510 for (namepass
= 0; namepass
< 2; namepass
++)
3512 format
= format_start
;
3514 for (formati
= 0; formati
< format_count
; formati
++)
3516 dwarf_vma content_type
, form
;
3518 content_type
= read_uleb128 (format
, & bytes_read
, end
);
3519 format
+= bytes_read
;
3520 form
= read_uleb128 (format
, & bytes_read
, end
);
3521 format
+= bytes_read
;
3522 data
= read_and_display_attr_value (0, form
, 0, data
, end
, 0, 0,
3523 linfo
->li_offset_size
,
3524 linfo
->li_version
, NULL
,
3525 ((content_type
== DW_LNCT_path
) != (namepass
== 1)),
3526 section
, NULL
, '\t');
3531 warn (_("Corrupt %s entries list\n"), what
);
3540 display_debug_lines_raw (struct dwarf_section
* section
,
3541 unsigned char * data
,
3542 unsigned char * end
,
3545 unsigned char *start
= section
->start
;
3546 int verbose_view
= 0;
3548 introduce (section
, TRUE
);
3552 static DWARF2_Internal_LineInfo saved_linfo
;
3553 DWARF2_Internal_LineInfo linfo
;
3554 unsigned char *standard_opcodes
;
3555 unsigned char *end_of_sequence
;
3558 if (const_strneq (section
->name
, ".debug_line.")
3559 /* Note: the following does not apply to .debug_line.dwo sections.
3560 These are full debug_line sections. */
3561 && strcmp (section
->name
, ".debug_line.dwo") != 0)
3563 /* Sections named .debug_line.<foo> are fragments of a .debug_line
3564 section containing just the Line Number Statements. They are
3565 created by the assembler and intended to be used alongside gcc's
3566 -ffunction-sections command line option. When the linker's
3567 garbage collection decides to discard a .text.<foo> section it
3568 can then also discard the line number information in .debug_line.<foo>.
3570 Since the section is a fragment it does not have the details
3571 needed to fill out a LineInfo structure, so instead we use the
3572 details from the last full debug_line section that we processed. */
3573 end_of_sequence
= end
;
3574 standard_opcodes
= NULL
;
3575 linfo
= saved_linfo
;
3576 /* PR 17531: file: 0522b371. */
3577 if (linfo
.li_line_range
== 0)
3579 warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n"));
3582 reset_state_machine (linfo
.li_default_is_stmt
);
3586 unsigned char * hdrptr
;
3588 if ((hdrptr
= read_debug_line_header (section
, data
, end
, & linfo
,
3589 & end_of_sequence
)) == NULL
)
3592 printf (_(" Offset: 0x%lx\n"), (long)(data
- start
));
3593 printf (_(" Length: %ld\n"), (long) linfo
.li_length
);
3594 printf (_(" DWARF Version: %d\n"), linfo
.li_version
);
3595 printf (_(" Prologue Length: %d\n"), (int) linfo
.li_prologue_length
);
3596 printf (_(" Minimum Instruction Length: %d\n"), linfo
.li_min_insn_length
);
3597 if (linfo
.li_version
>= 4)
3598 printf (_(" Maximum Ops per Instruction: %d\n"), linfo
.li_max_ops_per_insn
);
3599 printf (_(" Initial value of 'is_stmt': %d\n"), linfo
.li_default_is_stmt
);
3600 printf (_(" Line Base: %d\n"), linfo
.li_line_base
);
3601 printf (_(" Line Range: %d\n"), linfo
.li_line_range
);
3602 printf (_(" Opcode Base: %d\n"), linfo
.li_opcode_base
);
3604 /* PR 17512: file: 1665-6428-0.004. */
3605 if (linfo
.li_line_range
== 0)
3607 warn (_("Line range of 0 is invalid, using 1 instead\n"));
3608 linfo
.li_line_range
= 1;
3611 reset_state_machine (linfo
.li_default_is_stmt
);
3613 /* Display the contents of the Opcodes table. */
3614 standard_opcodes
= hdrptr
;
3616 /* PR 17512: file: 002-417945-0.004. */
3617 if (standard_opcodes
+ linfo
.li_opcode_base
>= end
)
3619 warn (_("Line Base extends beyond end of section\n"));
3623 printf (_("\n Opcodes:\n"));
3625 for (i
= 1; i
< linfo
.li_opcode_base
; i
++)
3626 printf (ngettext (" Opcode %d has %d arg\n",
3627 " Opcode %d has %d args\n",
3628 standard_opcodes
[i
- 1]),
3629 i
, standard_opcodes
[i
- 1]);
3631 /* Display the contents of the Directory table. */
3632 data
= standard_opcodes
+ linfo
.li_opcode_base
- 1;
3634 if (linfo
.li_version
>= 5)
3636 load_debug_section_with_follow (line_str
, file
);
3638 data
= display_formatted_table (data
, start
, end
, &linfo
, section
,
3640 data
= display_formatted_table (data
, start
, end
, &linfo
, section
,
3646 printf (_("\n The Directory Table is empty.\n"));
3649 unsigned int last_dir_entry
= 0;
3651 printf (_("\n The Directory Table (offset 0x%lx):\n"),
3652 (long)(data
- start
));
3654 while (data
< end
&& *data
!= 0)
3656 printf (" %d\t%.*s\n", ++last_dir_entry
, (int) (end
- data
), data
);
3658 data
+= strnlen ((char *) data
, end
- data
) + 1;
3661 /* PR 17512: file: 002-132094-0.004. */
3662 if (data
>= end
- 1)
3666 /* Skip the NUL at the end of the table. */
3669 /* Display the contents of the File Name table. */
3671 printf (_("\n The File Name Table is empty.\n"));
3674 printf (_("\n The File Name Table (offset 0x%lx):\n"),
3675 (long)(data
- start
));
3676 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
3678 while (data
< end
&& *data
!= 0)
3680 unsigned char *name
;
3681 unsigned int bytes_read
;
3683 printf (" %d\t", ++state_machine_regs
.last_file_entry
);
3685 data
+= strnlen ((char *) data
, end
- data
) + 1;
3688 dwarf_vmatoa ("u", read_uleb128 (data
, & bytes_read
, end
)));
3691 dwarf_vmatoa ("u", read_uleb128 (data
, & bytes_read
, end
)));
3694 dwarf_vmatoa ("u", read_uleb128 (data
, & bytes_read
, end
)));
3696 printf ("%.*s\n", (int)(end
- name
), name
);
3700 warn (_("Corrupt file name table entry\n"));
3706 /* Skip the NUL at the end of the table. */
3711 saved_linfo
= linfo
;
3714 /* Now display the statements. */
3715 if (data
>= end_of_sequence
)
3716 printf (_(" No Line Number Statements.\n"));
3719 printf (_(" Line Number Statements:\n"));
3721 while (data
< end_of_sequence
)
3723 unsigned char op_code
;
3724 dwarf_signed_vma adv
;
3726 unsigned int bytes_read
;
3728 printf (" [0x%08lx]", (long)(data
- start
));
3732 if (op_code
>= linfo
.li_opcode_base
)
3734 op_code
-= linfo
.li_opcode_base
;
3735 uladv
= (op_code
/ linfo
.li_line_range
);
3736 if (linfo
.li_max_ops_per_insn
== 1)
3738 uladv
*= linfo
.li_min_insn_length
;
3739 state_machine_regs
.address
+= uladv
;
3741 state_machine_regs
.view
= 0;
3742 printf (_(" Special opcode %d: "
3743 "advance Address by %s to 0x%s%s"),
3744 op_code
, dwarf_vmatoa ("u", uladv
),
3745 dwarf_vmatoa ("x", state_machine_regs
.address
),
3746 verbose_view
&& uladv
3747 ? _(" (reset view)") : "");
3752 = ((state_machine_regs
.op_index
+ uladv
)
3753 / linfo
.li_max_ops_per_insn
)
3754 * linfo
.li_min_insn_length
;
3756 state_machine_regs
.address
+= addrdelta
;
3757 state_machine_regs
.op_index
3758 = (state_machine_regs
.op_index
+ uladv
)
3759 % linfo
.li_max_ops_per_insn
;
3761 state_machine_regs
.view
= 0;
3762 printf (_(" Special opcode %d: "
3763 "advance Address by %s to 0x%s[%d]%s"),
3764 op_code
, dwarf_vmatoa ("u", uladv
),
3765 dwarf_vmatoa ("x", state_machine_regs
.address
),
3766 state_machine_regs
.op_index
,
3767 verbose_view
&& addrdelta
3768 ? _(" (reset view)") : "");
3770 adv
= (op_code
% linfo
.li_line_range
) + linfo
.li_line_base
;
3771 state_machine_regs
.line
+= adv
;
3772 printf (_(" and Line by %s to %d"),
3773 dwarf_vmatoa ("d", adv
), state_machine_regs
.line
);
3774 if (verbose_view
|| state_machine_regs
.view
)
3775 printf (_(" (view %u)\n"), state_machine_regs
.view
);
3778 state_machine_regs
.view
++;
3780 else switch (op_code
)
3782 case DW_LNS_extended_op
:
3783 data
+= process_extended_line_op (data
, linfo
.li_default_is_stmt
, end
);
3787 printf (_(" Copy"));
3788 if (verbose_view
|| state_machine_regs
.view
)
3789 printf (_(" (view %u)\n"), state_machine_regs
.view
);
3792 state_machine_regs
.view
++;
3795 case DW_LNS_advance_pc
:
3796 uladv
= read_uleb128 (data
, & bytes_read
, end
);
3798 if (linfo
.li_max_ops_per_insn
== 1)
3800 uladv
*= linfo
.li_min_insn_length
;
3801 state_machine_regs
.address
+= uladv
;
3803 state_machine_regs
.view
= 0;
3804 printf (_(" Advance PC by %s to 0x%s%s\n"),
3805 dwarf_vmatoa ("u", uladv
),
3806 dwarf_vmatoa ("x", state_machine_regs
.address
),
3807 verbose_view
&& uladv
3808 ? _(" (reset view)") : "");
3813 = ((state_machine_regs
.op_index
+ uladv
)
3814 / linfo
.li_max_ops_per_insn
)
3815 * linfo
.li_min_insn_length
;
3816 state_machine_regs
.address
3818 state_machine_regs
.op_index
3819 = (state_machine_regs
.op_index
+ uladv
)
3820 % linfo
.li_max_ops_per_insn
;
3822 state_machine_regs
.view
= 0;
3823 printf (_(" Advance PC by %s to 0x%s[%d]%s\n"),
3824 dwarf_vmatoa ("u", uladv
),
3825 dwarf_vmatoa ("x", state_machine_regs
.address
),
3826 state_machine_regs
.op_index
,
3827 verbose_view
&& addrdelta
3828 ? _(" (reset view)") : "");
3832 case DW_LNS_advance_line
:
3833 adv
= read_sleb128 (data
, & bytes_read
, end
);
3835 state_machine_regs
.line
+= adv
;
3836 printf (_(" Advance Line by %s to %d\n"),
3837 dwarf_vmatoa ("d", adv
),
3838 state_machine_regs
.line
);
3841 case DW_LNS_set_file
:
3842 adv
= read_uleb128 (data
, & bytes_read
, end
);
3844 printf (_(" Set File Name to entry %s in the File Name Table\n"),
3845 dwarf_vmatoa ("d", adv
));
3846 state_machine_regs
.file
= adv
;
3849 case DW_LNS_set_column
:
3850 uladv
= read_uleb128 (data
, & bytes_read
, end
);
3852 printf (_(" Set column to %s\n"),
3853 dwarf_vmatoa ("u", uladv
));
3854 state_machine_regs
.column
= uladv
;
3857 case DW_LNS_negate_stmt
:
3858 adv
= state_machine_regs
.is_stmt
;
3860 printf (_(" Set is_stmt to %s\n"), dwarf_vmatoa ("d", adv
));
3861 state_machine_regs
.is_stmt
= adv
;
3864 case DW_LNS_set_basic_block
:
3865 printf (_(" Set basic block\n"));
3866 state_machine_regs
.basic_block
= 1;
3869 case DW_LNS_const_add_pc
:
3870 uladv
= ((255 - linfo
.li_opcode_base
) / linfo
.li_line_range
);
3871 if (linfo
.li_max_ops_per_insn
)
3873 uladv
*= linfo
.li_min_insn_length
;
3874 state_machine_regs
.address
+= uladv
;
3876 state_machine_regs
.view
= 0;
3877 printf (_(" Advance PC by constant %s to 0x%s%s\n"),
3878 dwarf_vmatoa ("u", uladv
),
3879 dwarf_vmatoa ("x", state_machine_regs
.address
),
3880 verbose_view
&& uladv
3881 ? _(" (reset view)") : "");
3886 = ((state_machine_regs
.op_index
+ uladv
)
3887 / linfo
.li_max_ops_per_insn
)
3888 * linfo
.li_min_insn_length
;
3889 state_machine_regs
.address
3891 state_machine_regs
.op_index
3892 = (state_machine_regs
.op_index
+ uladv
)
3893 % linfo
.li_max_ops_per_insn
;
3895 state_machine_regs
.view
= 0;
3896 printf (_(" Advance PC by constant %s to 0x%s[%d]%s\n"),
3897 dwarf_vmatoa ("u", uladv
),
3898 dwarf_vmatoa ("x", state_machine_regs
.address
),
3899 state_machine_regs
.op_index
,
3900 verbose_view
&& addrdelta
3901 ? _(" (reset view)") : "");
3905 case DW_LNS_fixed_advance_pc
:
3906 SAFE_BYTE_GET_AND_INC (uladv
, data
, 2, end
);
3907 state_machine_regs
.address
+= uladv
;
3908 state_machine_regs
.op_index
= 0;
3909 printf (_(" Advance PC by fixed size amount %s to 0x%s\n"),
3910 dwarf_vmatoa ("u", uladv
),
3911 dwarf_vmatoa ("x", state_machine_regs
.address
));
3912 /* Do NOT reset view. */
3915 case DW_LNS_set_prologue_end
:
3916 printf (_(" Set prologue_end to true\n"));
3919 case DW_LNS_set_epilogue_begin
:
3920 printf (_(" Set epilogue_begin to true\n"));
3923 case DW_LNS_set_isa
:
3924 uladv
= read_uleb128 (data
, & bytes_read
, end
);
3926 printf (_(" Set ISA to %s\n"), dwarf_vmatoa ("u", uladv
));
3930 printf (_(" Unknown opcode %d with operands: "), op_code
);
3932 if (standard_opcodes
!= NULL
)
3933 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
3935 printf ("0x%s%s", dwarf_vmatoa ("x", read_uleb128 (data
,
3937 i
== 1 ? "" : ", ");
3953 unsigned char *name
;
3954 unsigned int directory_index
;
3955 unsigned int modification_date
;
3956 unsigned int length
;
3959 /* Output a decoded representation of the .debug_line section. */
3962 display_debug_lines_decoded (struct dwarf_section
* section
,
3963 unsigned char * data
,
3964 unsigned char * end
,
3967 static DWARF2_Internal_LineInfo saved_linfo
;
3969 introduce (section
, FALSE
);
3973 /* This loop amounts to one iteration per compilation unit. */
3974 DWARF2_Internal_LineInfo linfo
;
3975 unsigned char *standard_opcodes
;
3976 unsigned char *end_of_sequence
;
3978 File_Entry
*file_table
= NULL
;
3979 unsigned int n_files
= 0;
3980 unsigned char **directory_table
= NULL
;
3981 dwarf_vma n_directories
= 0;
3983 if (const_strneq (section
->name
, ".debug_line.")
3984 /* Note: the following does not apply to .debug_line.dwo sections.
3985 These are full debug_line sections. */
3986 && strcmp (section
->name
, ".debug_line.dwo") != 0)
3988 /* See comment in display_debug_lines_raw(). */
3989 end_of_sequence
= end
;
3990 standard_opcodes
= NULL
;
3991 linfo
= saved_linfo
;
3992 /* PR 17531: file: 0522b371. */
3993 if (linfo
.li_line_range
== 0)
3995 warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n"));
3998 reset_state_machine (linfo
.li_default_is_stmt
);
4002 unsigned char *hdrptr
;
4004 if ((hdrptr
= read_debug_line_header (section
, data
, end
, & linfo
,
4005 & end_of_sequence
)) == NULL
)
4008 /* PR 17531: file: 0522b371. */
4009 if (linfo
.li_line_range
== 0)
4011 warn (_("Line range of 0 is invalid, using 1 instead\n"));
4012 linfo
.li_line_range
= 1;
4014 reset_state_machine (linfo
.li_default_is_stmt
);
4016 /* Save a pointer to the contents of the Opcodes table. */
4017 standard_opcodes
= hdrptr
;
4019 /* Traverse the Directory table just to count entries. */
4020 data
= standard_opcodes
+ linfo
.li_opcode_base
- 1;
4024 warn (_("opcode base of %d extends beyond end of section\n"),
4025 linfo
.li_opcode_base
);
4029 if (linfo
.li_version
>= 5)
4031 unsigned char *format_start
, format_count
, *format
;
4032 dwarf_vma formati
, entryi
;
4033 unsigned int bytes_read
;
4035 load_debug_section_with_follow (line_str
, fileptr
);
4037 /* Skip directories format. */
4038 SAFE_BYTE_GET_AND_INC (format_count
, data
, 1, end
);
4039 format_start
= data
;
4040 for (formati
= 0; formati
< format_count
; formati
++)
4042 read_uleb128 (data
, & bytes_read
, end
);
4044 read_uleb128 (data
, & bytes_read
, end
);
4048 n_directories
= read_uleb128 (data
, & bytes_read
, end
);
4052 warn (_("Corrupt directories list\n"));
4056 directory_table
= (unsigned char **)
4057 xmalloc (n_directories
* sizeof (unsigned char *));
4059 for (entryi
= 0; entryi
< n_directories
; entryi
++)
4061 unsigned char **pathp
= &directory_table
[entryi
];
4063 format
= format_start
;
4064 for (formati
= 0; formati
< format_count
; formati
++)
4066 dwarf_vma content_type
, form
;
4069 content_type
= read_uleb128 (format
, & bytes_read
, end
);
4070 format
+= bytes_read
;
4071 form
= read_uleb128 (format
, & bytes_read
, end
);
4072 format
+= bytes_read
;
4075 warn (_("Corrupt directories list\n"));
4078 switch (content_type
)
4083 case DW_FORM_string
:
4086 case DW_FORM_line_strp
:
4087 SAFE_BYTE_GET (uvalue
, data
, linfo
.li_offset_size
,
4089 /* Remove const by the cast. */
4090 *pathp
= (unsigned char *)
4091 fetch_indirect_line_string (uvalue
);
4096 data
= read_and_display_attr_value (0, form
, 0, data
, end
,
4098 linfo
.li_offset_size
,
4105 warn (_("Corrupt directories list\n"));
4110 /* Skip files format. */
4111 SAFE_BYTE_GET_AND_INC (format_count
, data
, 1, end
);
4112 format_start
= data
;
4113 for (formati
= 0; formati
< format_count
; formati
++)
4115 read_uleb128 (data
, & bytes_read
, end
);
4117 read_uleb128 (data
, & bytes_read
, end
);
4121 n_files
= read_uleb128 (data
, & bytes_read
, end
);
4125 warn (_("Corrupt file name list\n"));
4129 file_table
= (File_Entry
*) xcalloc (1, n_files
4130 * sizeof (File_Entry
));
4132 for (entryi
= 0; entryi
< n_files
; entryi
++)
4134 File_Entry
*file
= &file_table
[entryi
];
4136 format
= format_start
;
4137 for (formati
= 0; formati
< format_count
; formati
++)
4139 dwarf_vma content_type
, form
;
4142 content_type
= read_uleb128 (format
, & bytes_read
, end
);
4143 format
+= bytes_read
;
4144 form
= read_uleb128 (format
, & bytes_read
, end
);
4145 format
+= bytes_read
;
4148 warn (_("Corrupt file name list\n"));
4151 switch (content_type
)
4156 case DW_FORM_string
:
4159 case DW_FORM_line_strp
:
4160 SAFE_BYTE_GET (uvalue
, data
, linfo
.li_offset_size
,
4162 /* Remove const by the cast. */
4163 file
->name
= (unsigned char *)
4164 fetch_indirect_line_string (uvalue
);
4168 case DW_LNCT_directory_index
:
4172 SAFE_BYTE_GET (file
->directory_index
, data
, 1,
4176 SAFE_BYTE_GET (file
->directory_index
, data
, 2,
4180 file
->directory_index
= read_uleb128 (data
, NULL
,
4186 data
= read_and_display_attr_value (0, form
, 0, data
, end
,
4188 linfo
.li_offset_size
,
4195 warn (_("Corrupt file name list\n"));
4204 unsigned char *ptr_directory_table
= data
;
4206 while (data
< end
&& *data
!= 0)
4208 data
+= strnlen ((char *) data
, end
- data
) + 1;
4215 warn (_("directory table ends unexpectedly\n"));
4220 /* Go through the directory table again to save the directories. */
4221 directory_table
= (unsigned char **)
4222 xmalloc (n_directories
* sizeof (unsigned char *));
4225 while (*ptr_directory_table
!= 0)
4227 directory_table
[i
] = ptr_directory_table
;
4228 ptr_directory_table
+= strnlen ((char *) ptr_directory_table
,
4229 ptr_directory_table
- end
) + 1;
4233 /* Skip the NUL at the end of the table. */
4236 /* Traverse the File Name table just to count the entries. */
4237 if (data
< end
&& *data
!= 0)
4239 unsigned char *ptr_file_name_table
= data
;
4241 while (data
< end
&& *data
!= 0)
4243 unsigned int bytes_read
;
4245 /* Skip Name, directory index, last modification time and length
4247 data
+= strnlen ((char *) data
, end
- data
) + 1;
4248 read_uleb128 (data
, & bytes_read
, end
);
4250 read_uleb128 (data
, & bytes_read
, end
);
4252 read_uleb128 (data
, & bytes_read
, end
);
4260 warn (_("file table ends unexpectedly\n"));
4265 /* Go through the file table again to save the strings. */
4266 file_table
= (File_Entry
*) xmalloc (n_files
* sizeof (File_Entry
));
4269 while (*ptr_file_name_table
!= 0)
4271 unsigned int bytes_read
;
4273 file_table
[i
].name
= ptr_file_name_table
;
4274 ptr_file_name_table
+= strnlen ((char *) ptr_file_name_table
,
4275 end
- ptr_file_name_table
) + 1;
4277 /* We are not interested in directory, time or size. */
4278 file_table
[i
].directory_index
= read_uleb128 (ptr_file_name_table
,
4280 ptr_file_name_table
+= bytes_read
;
4281 file_table
[i
].modification_date
= read_uleb128 (ptr_file_name_table
,
4283 ptr_file_name_table
+= bytes_read
;
4284 file_table
[i
].length
= read_uleb128 (ptr_file_name_table
, & bytes_read
, end
);
4285 ptr_file_name_table
+= bytes_read
;
4291 /* Skip the NUL at the end of the table. */
4295 /* Print the Compilation Unit's name and a header. */
4296 if (file_table
== NULL
)
4298 else if (directory_table
== NULL
)
4299 printf (_("CU: %s:\n"), file_table
[0].name
);
4302 unsigned int ix
= file_table
[0].directory_index
;
4303 const char *directory
;
4308 else if (n_directories
== 0)
4309 directory
= _("<unknown>");
4310 else if (ix
> n_directories
)
4312 warn (_("directory index %u > number of directories %s\n"),
4313 ix
, dwarf_vmatoa ("u", n_directories
));
4314 directory
= _("<corrupt>");
4317 directory
= (char *) directory_table
[ix
- 1];
4319 if (do_wide
|| strlen (directory
) < 76)
4320 printf (_("CU: %s/%s:\n"), directory
, file_table
[0].name
);
4322 printf ("%s:\n", file_table
[0].name
);
4325 printf (_("File name Line number Starting address View\n"));
4326 saved_linfo
= linfo
;
4329 /* This loop iterates through the Dwarf Line Number Program. */
4330 while (data
< end_of_sequence
)
4332 unsigned char op_code
;
4335 unsigned long int uladv
;
4336 unsigned int bytes_read
;
4337 int is_special_opcode
= 0;
4342 if (op_code
>= linfo
.li_opcode_base
)
4344 op_code
-= linfo
.li_opcode_base
;
4345 uladv
= (op_code
/ linfo
.li_line_range
);
4346 if (linfo
.li_max_ops_per_insn
== 1)
4348 uladv
*= linfo
.li_min_insn_length
;
4349 state_machine_regs
.address
+= uladv
;
4351 state_machine_regs
.view
= 0;
4356 = ((state_machine_regs
.op_index
+ uladv
)
4357 / linfo
.li_max_ops_per_insn
)
4358 * linfo
.li_min_insn_length
;
4359 state_machine_regs
.address
4361 state_machine_regs
.op_index
4362 = (state_machine_regs
.op_index
+ uladv
)
4363 % linfo
.li_max_ops_per_insn
;
4365 state_machine_regs
.view
= 0;
4368 adv
= (op_code
% linfo
.li_line_range
) + linfo
.li_line_base
;
4369 state_machine_regs
.line
+= adv
;
4370 is_special_opcode
= 1;
4371 /* Increment view after printing this row. */
4373 else switch (op_code
)
4375 case DW_LNS_extended_op
:
4377 unsigned int ext_op_code_len
;
4378 unsigned char ext_op_code
;
4379 unsigned char *op_code_data
= data
;
4381 ext_op_code_len
= read_uleb128 (op_code_data
, &bytes_read
,
4383 op_code_data
+= bytes_read
;
4385 if (ext_op_code_len
== 0)
4387 warn (_("Badly formed extended line op encountered!\n"));
4390 ext_op_code_len
+= bytes_read
;
4391 ext_op_code
= *op_code_data
++;
4395 switch (ext_op_code
)
4397 case DW_LNE_end_sequence
:
4398 /* Reset stuff after printing this row. */
4400 case DW_LNE_set_address
:
4401 SAFE_BYTE_GET_AND_INC (state_machine_regs
.address
,
4403 ext_op_code_len
- bytes_read
- 1,
4405 state_machine_regs
.op_index
= 0;
4406 state_machine_regs
.view
= 0;
4408 case DW_LNE_define_file
:
4410 file_table
= (File_Entry
*) xrealloc
4411 (file_table
, (n_files
+ 1) * sizeof (File_Entry
));
4413 ++state_machine_regs
.last_file_entry
;
4414 /* Source file name. */
4415 file_table
[n_files
].name
= op_code_data
;
4416 op_code_data
+= strlen ((char *) op_code_data
) + 1;
4417 /* Directory index. */
4418 file_table
[n_files
].directory_index
=
4419 read_uleb128 (op_code_data
, & bytes_read
,
4421 op_code_data
+= bytes_read
;
4422 /* Last modification time. */
4423 file_table
[n_files
].modification_date
=
4424 read_uleb128 (op_code_data
, & bytes_read
,
4426 op_code_data
+= bytes_read
;
4428 file_table
[n_files
].length
=
4429 read_uleb128 (op_code_data
, & bytes_read
,
4435 case DW_LNE_set_discriminator
:
4436 case DW_LNE_HP_set_sequence
:
4437 /* Simply ignored. */
4441 printf (_("UNKNOWN (%u): length %d\n"),
4442 ext_op_code
, ext_op_code_len
- bytes_read
);
4445 data
+= ext_op_code_len
;
4449 /* Increment view after printing this row. */
4452 case DW_LNS_advance_pc
:
4453 uladv
= read_uleb128 (data
, & bytes_read
, end
);
4455 if (linfo
.li_max_ops_per_insn
== 1)
4457 uladv
*= linfo
.li_min_insn_length
;
4458 state_machine_regs
.address
+= uladv
;
4460 state_machine_regs
.view
= 0;
4465 = ((state_machine_regs
.op_index
+ uladv
)
4466 / linfo
.li_max_ops_per_insn
)
4467 * linfo
.li_min_insn_length
;
4468 state_machine_regs
.address
4470 state_machine_regs
.op_index
4471 = (state_machine_regs
.op_index
+ uladv
)
4472 % linfo
.li_max_ops_per_insn
;
4474 state_machine_regs
.view
= 0;
4478 case DW_LNS_advance_line
:
4479 adv
= read_sleb128 (data
, & bytes_read
, end
);
4481 state_machine_regs
.line
+= adv
;
4484 case DW_LNS_set_file
:
4485 adv
= read_uleb128 (data
, & bytes_read
, end
);
4487 state_machine_regs
.file
= adv
;
4490 unsigned file
= state_machine_regs
.file
- 1;
4493 if (file_table
== NULL
|| n_files
== 0)
4494 printf (_("\n [Use file table entry %d]\n"), file
);
4496 else if (file
>= n_files
)
4498 warn (_("file index %u > number of files %u\n"), file
+ 1, n_files
);
4499 printf (_("\n <over large file table index %u>"), file
);
4501 else if ((dir
= file_table
[file
].directory_index
) == 0)
4502 /* If directory index is 0, that means current directory. */
4503 printf ("\n./%s:[++]\n", file_table
[file
].name
);
4504 else if (directory_table
== NULL
|| n_directories
== 0)
4505 printf (_("\n [Use file %s in directory table entry %d]\n"),
4506 file_table
[file
].name
, dir
);
4508 else if (dir
> n_directories
)
4510 warn (_("directory index %u > number of directories %s\n"),
4511 dir
, dwarf_vmatoa ("u", n_directories
));
4512 printf (_("\n <over large directory table entry %u>\n"), dir
);
4515 printf ("\n%s/%s:\n",
4516 /* The directory index starts counting at 1. */
4517 directory_table
[dir
- 1], file_table
[file
].name
);
4521 case DW_LNS_set_column
:
4522 uladv
= read_uleb128 (data
, & bytes_read
, end
);
4524 state_machine_regs
.column
= uladv
;
4527 case DW_LNS_negate_stmt
:
4528 adv
= state_machine_regs
.is_stmt
;
4530 state_machine_regs
.is_stmt
= adv
;
4533 case DW_LNS_set_basic_block
:
4534 state_machine_regs
.basic_block
= 1;
4537 case DW_LNS_const_add_pc
:
4538 uladv
= ((255 - linfo
.li_opcode_base
) / linfo
.li_line_range
);
4539 if (linfo
.li_max_ops_per_insn
== 1)
4541 uladv
*= linfo
.li_min_insn_length
;
4542 state_machine_regs
.address
+= uladv
;
4544 state_machine_regs
.view
= 0;
4549 = ((state_machine_regs
.op_index
+ uladv
)
4550 / linfo
.li_max_ops_per_insn
)
4551 * linfo
.li_min_insn_length
;
4552 state_machine_regs
.address
4554 state_machine_regs
.op_index
4555 = (state_machine_regs
.op_index
+ uladv
)
4556 % linfo
.li_max_ops_per_insn
;
4558 state_machine_regs
.view
= 0;
4562 case DW_LNS_fixed_advance_pc
:
4563 SAFE_BYTE_GET_AND_INC (uladv
, data
, 2, end
);
4564 state_machine_regs
.address
+= uladv
;
4565 state_machine_regs
.op_index
= 0;
4566 /* Do NOT reset view. */
4569 case DW_LNS_set_prologue_end
:
4572 case DW_LNS_set_epilogue_begin
:
4575 case DW_LNS_set_isa
:
4576 uladv
= read_uleb128 (data
, & bytes_read
, end
);
4578 printf (_(" Set ISA to %lu\n"), uladv
);
4582 printf (_(" Unknown opcode %d with operands: "), op_code
);
4584 if (standard_opcodes
!= NULL
)
4585 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
4587 printf ("0x%s%s", dwarf_vmatoa ("x", read_uleb128 (data
,
4589 i
== 1 ? "" : ", ");
4596 /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row
4597 to the DWARF address/line matrix. */
4598 if ((is_special_opcode
) || (xop
== -DW_LNE_end_sequence
)
4599 || (xop
== DW_LNS_copy
))
4601 const unsigned int MAX_FILENAME_LENGTH
= 35;
4603 char *newFileName
= NULL
;
4604 size_t fileNameLength
;
4608 unsigned indx
= state_machine_regs
.file
- 1;
4610 if (indx
>= n_files
)
4612 warn (_("corrupt file index %u encountered\n"), indx
);
4613 fileName
= _("<corrupt>");
4616 fileName
= (char *) file_table
[indx
].name
;
4619 fileName
= _("<unknown>");
4621 fileNameLength
= strlen (fileName
);
4623 if ((fileNameLength
> MAX_FILENAME_LENGTH
) && (!do_wide
))
4625 newFileName
= (char *) xmalloc (MAX_FILENAME_LENGTH
+ 1);
4626 /* Truncate file name */
4627 strncpy (newFileName
,
4628 fileName
+ fileNameLength
- MAX_FILENAME_LENGTH
,
4629 MAX_FILENAME_LENGTH
+ 1);
4633 newFileName
= (char *) xmalloc (fileNameLength
+ 1);
4634 strncpy (newFileName
, fileName
, fileNameLength
+ 1);
4637 if (!do_wide
|| (fileNameLength
<= MAX_FILENAME_LENGTH
))
4639 if (linfo
.li_max_ops_per_insn
== 1)
4640 printf ("%-35s %11d %#18" DWARF_VMA_FMT
"x",
4641 newFileName
, state_machine_regs
.line
,
4642 state_machine_regs
.address
);
4644 printf ("%-35s %11d %#18" DWARF_VMA_FMT
"x[%d]",
4645 newFileName
, state_machine_regs
.line
,
4646 state_machine_regs
.address
,
4647 state_machine_regs
.op_index
);
4651 if (linfo
.li_max_ops_per_insn
== 1)
4652 printf ("%s %11d %#18" DWARF_VMA_FMT
"x",
4653 newFileName
, state_machine_regs
.line
,
4654 state_machine_regs
.address
);
4656 printf ("%s %11d %#18" DWARF_VMA_FMT
"x[%d]",
4657 newFileName
, state_machine_regs
.line
,
4658 state_machine_regs
.address
,
4659 state_machine_regs
.op_index
);
4662 if (state_machine_regs
.view
)
4663 printf (" %6u\n", state_machine_regs
.view
);
4666 state_machine_regs
.view
++;
4668 if (xop
== -DW_LNE_end_sequence
)
4670 reset_state_machine (linfo
.li_default_is_stmt
);
4685 if (directory_table
)
4687 free (directory_table
);
4688 directory_table
= NULL
;
4699 display_debug_lines (struct dwarf_section
*section
, void *file
)
4701 unsigned char *data
= section
->start
;
4702 unsigned char *end
= data
+ section
->size
;
4704 int retValDecoded
= 1;
4706 if (do_debug_lines
== 0)
4707 do_debug_lines
|= FLAG_DEBUG_LINES_RAW
;
4709 if (do_debug_lines
& FLAG_DEBUG_LINES_RAW
)
4710 retValRaw
= display_debug_lines_raw (section
, data
, end
, file
);
4712 if (do_debug_lines
& FLAG_DEBUG_LINES_DECODED
)
4713 retValDecoded
= display_debug_lines_decoded (section
, data
, end
, file
);
4715 if (!retValRaw
|| !retValDecoded
)
4722 find_debug_info_for_offset (unsigned long offset
)
4726 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
4729 for (i
= 0; i
< num_debug_info_entries
; i
++)
4730 if (debug_information
[i
].cu_offset
== offset
)
4731 return debug_information
+ i
;
4737 get_gdb_index_symbol_kind_name (gdb_index_symbol_kind kind
)
4739 /* See gdb/gdb-index.h. */
4740 static const char * const kinds
[] =
4752 return _ (kinds
[kind
]);
4756 display_debug_pubnames_worker (struct dwarf_section
*section
,
4757 void *file ATTRIBUTE_UNUSED
,
4760 DWARF2_Internal_PubNames names
;
4761 unsigned char *start
= section
->start
;
4762 unsigned char *end
= start
+ section
->size
;
4764 /* It does not matter if this load fails,
4765 we test for that later on. */
4766 load_debug_info (file
);
4768 introduce (section
, FALSE
);
4772 unsigned char *data
;
4773 unsigned long sec_off
;
4774 unsigned int offset_size
, initial_length_size
;
4776 SAFE_BYTE_GET_AND_INC (names
.pn_length
, start
, 4, end
);
4777 if (names
.pn_length
== 0xffffffff)
4779 SAFE_BYTE_GET_AND_INC (names
.pn_length
, start
, 8, end
);
4781 initial_length_size
= 12;
4786 initial_length_size
= 4;
4789 sec_off
= start
- section
->start
;
4790 if (sec_off
+ names
.pn_length
< sec_off
4791 || sec_off
+ names
.pn_length
> section
->size
)
4793 warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"),
4795 sec_off
- initial_length_size
,
4796 dwarf_vmatoa ("x", names
.pn_length
));
4801 start
+= names
.pn_length
;
4803 SAFE_BYTE_GET_AND_INC (names
.pn_version
, data
, 2, end
);
4804 SAFE_BYTE_GET_AND_INC (names
.pn_offset
, data
, offset_size
, end
);
4806 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
4807 && num_debug_info_entries
> 0
4808 && find_debug_info_for_offset (names
.pn_offset
) == NULL
)
4809 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
4810 (unsigned long) names
.pn_offset
, section
->name
);
4812 SAFE_BYTE_GET_AND_INC (names
.pn_size
, data
, offset_size
, end
);
4814 printf (_(" Length: %ld\n"),
4815 (long) names
.pn_length
);
4816 printf (_(" Version: %d\n"),
4818 printf (_(" Offset into .debug_info section: 0x%lx\n"),
4819 (unsigned long) names
.pn_offset
);
4820 printf (_(" Size of area in .debug_info section: %ld\n"),
4821 (long) names
.pn_size
);
4823 if (names
.pn_version
!= 2 && names
.pn_version
!= 3)
4825 static int warned
= 0;
4829 warn (_("Only DWARF 2 and 3 pubnames are currently supported\n"));
4837 printf (_("\n Offset Kind Name\n"));
4839 printf (_("\n Offset\tName\n"));
4843 bfd_size_type maxprint
;
4846 SAFE_BYTE_GET (offset
, data
, offset_size
, end
);
4851 data
+= offset_size
;
4854 maxprint
= (end
- data
) - 1;
4858 unsigned int kind_data
;
4859 gdb_index_symbol_kind kind
;
4860 const char *kind_name
;
4863 SAFE_BYTE_GET (kind_data
, data
, 1, end
);
4866 /* GCC computes the kind as the upper byte in the CU index
4867 word, and then right shifts it by the CU index size.
4868 Left shift KIND to where the gdb-index.h accessor macros
4870 kind_data
<<= GDB_INDEX_CU_BITSIZE
;
4871 kind
= GDB_INDEX_SYMBOL_KIND_VALUE (kind_data
);
4872 kind_name
= get_gdb_index_symbol_kind_name (kind
);
4873 is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (kind_data
);
4874 printf (" %-6lx %s,%-10s %.*s\n",
4875 (unsigned long) offset
, is_static
? _("s") : _("g"),
4876 kind_name
, (int) maxprint
, data
);
4879 printf (" %-6lx\t%.*s\n",
4880 (unsigned long) offset
, (int) maxprint
, data
);
4882 data
+= strnlen ((char *) data
, maxprint
) + 1;
4893 display_debug_pubnames (struct dwarf_section
*section
, void *file
)
4895 return display_debug_pubnames_worker (section
, file
, 0);
4899 display_debug_gnu_pubnames (struct dwarf_section
*section
, void *file
)
4901 return display_debug_pubnames_worker (section
, file
, 1);
4905 display_debug_macinfo (struct dwarf_section
*section
,
4906 void *file ATTRIBUTE_UNUSED
)
4908 unsigned char *start
= section
->start
;
4909 unsigned char *end
= start
+ section
->size
;
4910 unsigned char *curr
= start
;
4911 unsigned int bytes_read
;
4912 enum dwarf_macinfo_record_type op
;
4914 introduce (section
, FALSE
);
4918 unsigned int lineno
;
4919 const unsigned char *string
;
4921 op
= (enum dwarf_macinfo_record_type
) *curr
;
4926 case DW_MACINFO_start_file
:
4928 unsigned int filenum
;
4930 lineno
= read_uleb128 (curr
, & bytes_read
, end
);
4932 filenum
= read_uleb128 (curr
, & bytes_read
, end
);
4935 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"),
4940 case DW_MACINFO_end_file
:
4941 printf (_(" DW_MACINFO_end_file\n"));
4944 case DW_MACINFO_define
:
4945 lineno
= read_uleb128 (curr
, & bytes_read
, end
);
4948 curr
+= strnlen ((char *) string
, end
- string
) + 1;
4949 printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"),
4953 case DW_MACINFO_undef
:
4954 lineno
= read_uleb128 (curr
, & bytes_read
, end
);
4957 curr
+= strnlen ((char *) string
, end
- string
) + 1;
4958 printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"),
4962 case DW_MACINFO_vendor_ext
:
4964 unsigned int constant
;
4966 constant
= read_uleb128 (curr
, & bytes_read
, end
);
4969 curr
+= strnlen ((char *) string
, end
- string
) + 1;
4970 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"),
4980 /* Given LINE_OFFSET into the .debug_line section, attempt to return
4981 filename and dirname corresponding to file name table entry with index
4982 FILEIDX. Return NULL on failure. */
4984 static unsigned char *
4985 get_line_filename_and_dirname (dwarf_vma line_offset
,
4987 unsigned char **dir_name
)
4989 struct dwarf_section
*section
= &debug_displays
[line
].section
;
4990 unsigned char *hdrptr
, *dirtable
, *file_name
;
4991 unsigned int offset_size
, initial_length_size
;
4992 unsigned int version
, opcode_base
, bytes_read
;
4993 dwarf_vma length
, diridx
;
4994 const unsigned char * end
;
4997 if (section
->start
== NULL
4998 || line_offset
>= section
->size
5002 hdrptr
= section
->start
+ line_offset
;
5003 end
= section
->start
+ section
->size
;
5005 SAFE_BYTE_GET_AND_INC (length
, hdrptr
, 4, end
);
5006 if (length
== 0xffffffff)
5008 /* This section is 64-bit DWARF 3. */
5009 SAFE_BYTE_GET_AND_INC (length
, hdrptr
, 8, end
);
5011 initial_length_size
= 12;
5016 initial_length_size
= 4;
5018 if (length
+ initial_length_size
< length
5019 || length
+ initial_length_size
> section
->size
)
5022 SAFE_BYTE_GET_AND_INC (version
, hdrptr
, 2, end
);
5023 if (version
!= 2 && version
!= 3 && version
!= 4)
5025 hdrptr
+= offset_size
+ 1;/* Skip prologue_length and min_insn_length. */
5027 hdrptr
++; /* Skip max_ops_per_insn. */
5028 hdrptr
+= 3; /* Skip default_is_stmt, line_base, line_range. */
5030 SAFE_BYTE_GET_AND_INC (opcode_base
, hdrptr
, 1, end
);
5031 if (opcode_base
== 0)
5034 hdrptr
+= opcode_base
- 1;
5039 /* Skip over dirname table. */
5040 while (*hdrptr
!= '\0')
5042 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
) + 1;
5046 hdrptr
++; /* Skip the NUL at the end of the table. */
5048 /* Now skip over preceding filename table entries. */
5049 for (; hdrptr
< end
&& *hdrptr
!= '\0' && fileidx
> 1; fileidx
--)
5051 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
) + 1;
5052 read_uleb128 (hdrptr
, &bytes_read
, end
);
5053 hdrptr
+= bytes_read
;
5054 read_uleb128 (hdrptr
, &bytes_read
, end
);
5055 hdrptr
+= bytes_read
;
5056 read_uleb128 (hdrptr
, &bytes_read
, end
);
5057 hdrptr
+= bytes_read
;
5059 if (hdrptr
>= end
|| *hdrptr
== '\0')
5063 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
) + 1;
5066 diridx
= read_uleb128 (hdrptr
, &bytes_read
, end
);
5069 for (; dirtable
< end
&& *dirtable
!= '\0' && diridx
> 1; diridx
--)
5070 dirtable
+= strnlen ((char *) dirtable
, end
- dirtable
) + 1;
5071 if (dirtable
>= end
|| *dirtable
== '\0')
5073 *dir_name
= dirtable
;
5078 display_debug_macro (struct dwarf_section
*section
,
5081 unsigned char *start
= section
->start
;
5082 unsigned char *end
= start
+ section
->size
;
5083 unsigned char *curr
= start
;
5084 unsigned char *extended_op_buf
[256];
5085 unsigned int bytes_read
;
5087 load_debug_section_with_follow (str
, file
);
5088 load_debug_section_with_follow (line
, file
);
5090 introduce (section
, FALSE
);
5094 unsigned int lineno
, version
, flags
;
5095 unsigned int offset_size
= 4;
5096 const unsigned char *string
;
5097 dwarf_vma line_offset
= 0, sec_offset
= curr
- start
, offset
;
5098 unsigned char **extended_ops
= NULL
;
5100 SAFE_BYTE_GET_AND_INC (version
, curr
, 2, end
);
5101 if (version
!= 4 && version
!= 5)
5103 error (_("Only GNU extension to DWARF 4 or 5 of %s is currently supported.\n"),
5108 SAFE_BYTE_GET_AND_INC (flags
, curr
, 1, end
);
5111 printf (_(" Offset: 0x%lx\n"),
5112 (unsigned long) sec_offset
);
5113 printf (_(" Version: %d\n"), version
);
5114 printf (_(" Offset size: %d\n"), offset_size
);
5117 SAFE_BYTE_GET_AND_INC (line_offset
, curr
, offset_size
, end
);
5118 printf (_(" Offset into .debug_line: 0x%lx\n"),
5119 (unsigned long) line_offset
);
5123 unsigned int i
, count
, op
;
5126 SAFE_BYTE_GET_AND_INC (count
, curr
, 1, end
);
5128 memset (extended_op_buf
, 0, sizeof (extended_op_buf
));
5129 extended_ops
= extended_op_buf
;
5132 printf (_(" Extension opcode arguments:\n"));
5133 for (i
= 0; i
< count
; i
++)
5135 SAFE_BYTE_GET_AND_INC (op
, curr
, 1, end
);
5136 extended_ops
[op
] = curr
;
5137 nargs
= read_uleb128 (curr
, &bytes_read
, end
);
5140 printf (_(" DW_MACRO_%02x has no arguments\n"), op
);
5143 printf (_(" DW_MACRO_%02x arguments: "), op
);
5144 for (n
= 0; n
< nargs
; n
++)
5148 SAFE_BYTE_GET_AND_INC (form
, curr
, 1, end
);
5149 printf ("%s%s", get_FORM_name (form
),
5150 n
== nargs
- 1 ? "\n" : ", ");
5160 case DW_FORM_block1
:
5161 case DW_FORM_block2
:
5162 case DW_FORM_block4
:
5164 case DW_FORM_string
:
5166 case DW_FORM_sec_offset
:
5169 error (_("Invalid extension opcode form %s\n"),
5170 get_FORM_name (form
));
5186 error (_(".debug_macro section not zero terminated\n"));
5190 SAFE_BYTE_GET_AND_INC (op
, curr
, 1, end
);
5196 case DW_MACRO_start_file
:
5198 unsigned int filenum
;
5199 unsigned char *file_name
= NULL
, *dir_name
= NULL
;
5201 lineno
= read_uleb128 (curr
, &bytes_read
, end
);
5203 filenum
= read_uleb128 (curr
, &bytes_read
, end
);
5206 if ((flags
& 2) == 0)
5207 error (_("DW_MACRO_start_file used, but no .debug_line offset provided.\n"));
5210 = get_line_filename_and_dirname (line_offset
, filenum
,
5212 if (file_name
== NULL
)
5213 printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d\n"),
5216 printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d filename: %s%s%s\n"),
5218 dir_name
!= NULL
? (const char *) dir_name
: "",
5219 dir_name
!= NULL
? "/" : "", file_name
);
5223 case DW_MACRO_end_file
:
5224 printf (_(" DW_MACRO_end_file\n"));
5227 case DW_MACRO_define
:
5228 lineno
= read_uleb128 (curr
, &bytes_read
, end
);
5231 curr
+= strnlen ((char *) string
, end
- string
) + 1;
5232 printf (_(" DW_MACRO_define - lineno : %d macro : %s\n"),
5236 case DW_MACRO_undef
:
5237 lineno
= read_uleb128 (curr
, &bytes_read
, end
);
5240 curr
+= strnlen ((char *) string
, end
- string
) + 1;
5241 printf (_(" DW_MACRO_undef - lineno : %d macro : %s\n"),
5245 case DW_MACRO_define_strp
:
5246 lineno
= read_uleb128 (curr
, &bytes_read
, end
);
5248 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
5249 string
= fetch_indirect_string (offset
);
5250 printf (_(" DW_MACRO_define_strp - lineno : %d macro : %s\n"),
5254 case DW_MACRO_undef_strp
:
5255 lineno
= read_uleb128 (curr
, &bytes_read
, end
);
5257 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
5258 string
= fetch_indirect_string (offset
);
5259 printf (_(" DW_MACRO_undef_strp - lineno : %d macro : %s\n"),
5263 case DW_MACRO_import
:
5264 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
5265 printf (_(" DW_MACRO_import - offset : 0x%lx\n"),
5266 (unsigned long) offset
);
5269 case DW_MACRO_define_sup
:
5270 lineno
= read_uleb128 (curr
, &bytes_read
, end
);
5272 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
5273 printf (_(" DW_MACRO_define_sup - lineno : %d macro offset : 0x%lx\n"),
5274 lineno
, (unsigned long) offset
);
5277 case DW_MACRO_undef_sup
:
5278 lineno
= read_uleb128 (curr
, &bytes_read
, end
);
5280 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
5281 printf (_(" DW_MACRO_undef_sup - lineno : %d macro offset : 0x%lx\n"),
5282 lineno
, (unsigned long) offset
);
5285 case DW_MACRO_import_sup
:
5286 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
5287 printf (_(" DW_MACRO_import_sup - offset : 0x%lx\n"),
5288 (unsigned long) offset
);
5292 if (extended_ops
== NULL
|| extended_ops
[op
] == NULL
)
5294 error (_(" Unknown macro opcode %02x seen\n"), op
);
5299 /* Skip over unhandled opcodes. */
5301 unsigned char *desc
= extended_ops
[op
];
5302 nargs
= read_uleb128 (desc
, &bytes_read
, end
);
5306 printf (_(" DW_MACRO_%02x\n"), op
);
5309 printf (_(" DW_MACRO_%02x -"), op
);
5310 for (n
= 0; n
< nargs
; n
++)
5314 /* DW_FORM_implicit_const is not expected here. */
5315 SAFE_BYTE_GET_AND_INC (val
, desc
, 1, end
);
5317 = read_and_display_attr_value (0, val
, 0,
5318 curr
, end
, 0, 0, offset_size
,
5319 version
, NULL
, 0, NULL
,
5337 display_debug_abbrev (struct dwarf_section
*section
,
5338 void *file ATTRIBUTE_UNUSED
)
5340 abbrev_entry
*entry
;
5341 unsigned char *start
= section
->start
;
5342 unsigned char *end
= start
+ section
->size
;
5344 introduce (section
, FALSE
);
5348 unsigned char *last
;
5353 start
= process_abbrev_section (start
, end
);
5355 if (first_abbrev
== NULL
)
5358 printf (_(" Number TAG (0x%lx)\n"), (long) (last
- section
->start
));
5360 for (entry
= first_abbrev
; entry
; entry
= entry
->next
)
5364 printf (" %ld %s [%s]\n",
5366 get_TAG_name (entry
->tag
),
5367 entry
->children
? _("has children") : _("no children"));
5369 for (attr
= entry
->first_attr
; attr
; attr
= attr
->next
)
5371 printf (" %-18s %s",
5372 get_AT_name (attr
->attribute
),
5373 get_FORM_name (attr
->form
));
5374 if (attr
->form
== DW_FORM_implicit_const
)
5375 printf (": %" BFD_VMA_FMT
"d", attr
->implicit_const
);
5387 /* Return true when ADDR is the maximum address, when addresses are
5388 POINTER_SIZE bytes long. */
5391 is_max_address (dwarf_vma addr
, unsigned int pointer_size
)
5393 dwarf_vma mask
= ~(~(dwarf_vma
) 1 << (pointer_size
* 8 - 1));
5394 return ((addr
& mask
) == mask
);
5397 /* Display a view pair list starting at *VSTART_PTR and ending at
5398 VLISTEND within SECTION. */
5401 display_view_pair_list (struct dwarf_section
*section
,
5402 unsigned char **vstart_ptr
,
5403 unsigned int debug_info_entry
,
5404 unsigned char *vlistend
)
5406 unsigned char *vstart
= *vstart_ptr
;
5407 unsigned char *section_end
= section
->start
+ section
->size
;
5408 unsigned int pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
5410 if (vlistend
< section_end
)
5411 section_end
= vlistend
;
5415 while (vstart
< section_end
)
5417 dwarf_vma off
= vstart
- section
->start
;
5418 dwarf_vma vbegin
, vend
;
5420 unsigned int bytes_read
;
5421 vbegin
= read_uleb128 (vstart
, &bytes_read
, section_end
);
5422 vstart
+= bytes_read
;
5423 if (vstart
== section_end
)
5425 vstart
-= bytes_read
;
5429 vend
= read_uleb128 (vstart
, &bytes_read
, section_end
);
5430 vstart
+= bytes_read
;
5432 printf (" %8.8lx ", (unsigned long) off
);
5434 print_dwarf_view (vbegin
, pointer_size
, 1);
5435 print_dwarf_view (vend
, pointer_size
, 1);
5436 printf (_("location view pair\n"));
5440 *vstart_ptr
= vstart
;
5443 /* Display a location list from a normal (ie, non-dwo) .debug_loc section. */
5446 display_loc_list (struct dwarf_section
*section
,
5447 unsigned char **start_ptr
,
5448 unsigned int debug_info_entry
,
5450 dwarf_vma base_address
,
5451 unsigned char **vstart_ptr
,
5454 unsigned char *start
= *start_ptr
, *vstart
= *vstart_ptr
;
5455 unsigned char *section_end
= section
->start
+ section
->size
;
5456 unsigned long cu_offset
;
5457 unsigned int pointer_size
;
5458 unsigned int offset_size
;
5463 unsigned short length
;
5464 int need_frame_base
;
5466 if (debug_info_entry
>= num_debug_info_entries
)
5468 warn (_("No debug information available for loc lists of entry: %u\n"),
5473 cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
5474 pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
5475 offset_size
= debug_information
[debug_info_entry
].offset_size
;
5476 dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
5478 if (pointer_size
< 2 || pointer_size
> 8)
5480 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
5481 pointer_size
, debug_info_entry
);
5487 dwarf_vma off
= offset
+ (start
- *start_ptr
);
5488 dwarf_vma vbegin
= vm1
, vend
= vm1
;
5490 if (start
+ 2 * pointer_size
> section_end
)
5492 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5493 (unsigned long) offset
);
5497 printf (" %8.8lx ", (unsigned long) off
);
5499 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, section_end
);
5500 SAFE_BYTE_GET_AND_INC (end
, start
, pointer_size
, section_end
);
5502 if (begin
== 0 && end
== 0)
5504 /* PR 18374: In a object file we can have a location list that
5505 starts with a begin and end of 0 because there are relocations
5506 that need to be applied to the addresses. Actually applying
5507 the relocations now does not help as they will probably resolve
5508 to 0, since the object file has not been fully linked. Real
5509 end of list markers will not have any relocations against them. */
5510 if (! reloc_at (section
, off
)
5511 && ! reloc_at (section
, off
+ pointer_size
))
5513 printf (_("<End of list>\n"));
5518 /* Check base address specifiers. */
5519 if (is_max_address (begin
, pointer_size
)
5520 && !is_max_address (end
, pointer_size
))
5523 print_dwarf_vma (begin
, pointer_size
);
5524 print_dwarf_vma (end
, pointer_size
);
5525 printf (_("(base address)\n"));
5531 unsigned int bytes_read
;
5533 off
= offset
+ (vstart
- *start_ptr
);
5535 vbegin
= read_uleb128 (vstart
, &bytes_read
, section_end
);
5536 vstart
+= bytes_read
;
5537 print_dwarf_view (vbegin
, pointer_size
, 1);
5539 vend
= read_uleb128 (vstart
, &bytes_read
, section_end
);
5540 vstart
+= bytes_read
;
5541 print_dwarf_view (vend
, pointer_size
, 1);
5543 printf (_("views at %8.8lx for:\n %*s "),
5544 (unsigned long) off
, 8, "");
5547 if (start
+ 2 > section_end
)
5549 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5550 (unsigned long) offset
);
5554 SAFE_BYTE_GET_AND_INC (length
, start
, 2, section_end
);
5556 if (start
+ length
> section_end
)
5558 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5559 (unsigned long) offset
);
5563 print_dwarf_vma (begin
+ base_address
, pointer_size
);
5564 print_dwarf_vma (end
+ base_address
, pointer_size
);
5567 need_frame_base
= decode_location_expression (start
,
5572 cu_offset
, section
);
5575 if (need_frame_base
&& !has_frame_base
)
5576 printf (_(" [without DW_AT_frame_base]"));
5578 if (begin
== end
&& vbegin
== vend
)
5579 fputs (_(" (start == end)"), stdout
);
5580 else if (begin
> end
|| (begin
== end
&& vbegin
> vend
))
5581 fputs (_(" (start > end)"), stdout
);
5589 *vstart_ptr
= vstart
;
5592 /* Display a location list from a normal (ie, non-dwo) .debug_loclists section. */
5595 display_loclists_list (struct dwarf_section
*section
,
5596 unsigned char **start_ptr
,
5597 unsigned int debug_info_entry
,
5599 dwarf_vma base_address
,
5600 unsigned char **vstart_ptr
,
5603 unsigned char *start
= *start_ptr
, *vstart
= *vstart_ptr
;
5604 unsigned char *section_end
= section
->start
+ section
->size
;
5605 unsigned long cu_offset
;
5606 unsigned int pointer_size
;
5607 unsigned int offset_size
;
5609 unsigned int bytes_read
;
5611 /* Initialize it due to a false compiler warning. */
5612 dwarf_vma begin
= -1, vbegin
= -1;
5613 dwarf_vma end
= -1, vend
= -1;
5615 int need_frame_base
;
5617 if (debug_info_entry
>= num_debug_info_entries
)
5619 warn (_("No debug information available for "
5620 "loclists lists of entry: %u\n"),
5625 cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
5626 pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
5627 offset_size
= debug_information
[debug_info_entry
].offset_size
;
5628 dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
5630 if (pointer_size
< 2 || pointer_size
> 8)
5632 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
5633 pointer_size
, debug_info_entry
);
5639 dwarf_vma off
= offset
+ (start
- *start_ptr
);
5640 enum dwarf_location_list_entry_type llet
;
5642 if (start
+ 1 > section_end
)
5644 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5645 (unsigned long) offset
);
5649 printf (" %8.8lx ", (unsigned long) off
);
5651 SAFE_BYTE_GET_AND_INC (llet
, start
, 1, section_end
);
5653 if (vstart
&& llet
== DW_LLE_offset_pair
)
5655 off
= offset
+ (vstart
- *start_ptr
);
5657 vbegin
= read_uleb128 (vstart
, &bytes_read
, section_end
);
5658 vstart
+= bytes_read
;
5659 print_dwarf_view (vbegin
, pointer_size
, 1);
5661 vend
= read_uleb128 (vstart
, &bytes_read
, section_end
);
5662 vstart
+= bytes_read
;
5663 print_dwarf_view (vend
, pointer_size
, 1);
5665 printf (_("views at %8.8lx for:\n %*s "),
5666 (unsigned long) off
, 8, "");
5671 case DW_LLE_end_of_list
:
5672 printf (_("<End of list>\n"));
5674 case DW_LLE_offset_pair
:
5675 begin
= read_uleb128 (start
, &bytes_read
, section_end
);
5676 start
+= bytes_read
;
5677 end
= read_uleb128 (start
, &bytes_read
, section_end
);
5678 start
+= bytes_read
;
5680 case DW_LLE_base_address
:
5681 SAFE_BYTE_GET_AND_INC (base_address
, start
, pointer_size
,
5683 print_dwarf_vma (base_address
, pointer_size
);
5684 printf (_("(base address)\n"));
5686 #ifdef DW_LLE_view_pair
5687 case DW_LLE_view_pair
:
5689 printf (_("View pair entry in loclist with locviews attribute\n"));
5690 vbegin
= read_uleb128 (start
, &bytes_read
, section_end
);
5691 start
+= bytes_read
;
5692 print_dwarf_view (vbegin
, pointer_size
, 1);
5694 vend
= read_uleb128 (start
, &bytes_read
, section_end
);
5695 start
+= bytes_read
;
5696 print_dwarf_view (vend
, pointer_size
, 1);
5698 printf (_("views for:\n"));
5702 error (_("Invalid location list entry type %d\n"), llet
);
5705 if (llet
== DW_LLE_end_of_list
)
5707 if (llet
!= DW_LLE_offset_pair
)
5710 if (start
+ 2 > section_end
)
5712 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5713 (unsigned long) offset
);
5717 length
= read_uleb128 (start
, &bytes_read
, section_end
);
5718 start
+= bytes_read
;
5720 print_dwarf_vma (begin
+ base_address
, pointer_size
);
5721 print_dwarf_vma (end
+ base_address
, pointer_size
);
5724 need_frame_base
= decode_location_expression (start
,
5729 cu_offset
, section
);
5732 if (need_frame_base
&& !has_frame_base
)
5733 printf (_(" [without DW_AT_frame_base]"));
5735 if (begin
== end
&& vbegin
== vend
)
5736 fputs (_(" (start == end)"), stdout
);
5737 else if (begin
> end
|| (begin
== end
&& vbegin
> vend
))
5738 fputs (_(" (start > end)"), stdout
);
5746 if (vbegin
!= vm1
|| vend
!= vm1
)
5747 printf (_("Trailing view pair not used in a range"));
5750 *vstart_ptr
= vstart
;
5753 /* Print a .debug_addr table index in decimal, surrounded by square brackets,
5754 right-adjusted in a field of length LEN, and followed by a space. */
5757 print_addr_index (unsigned int idx
, unsigned int len
)
5759 static char buf
[15];
5760 snprintf (buf
, sizeof (buf
), "[%d]", idx
);
5761 printf ("%*s ", len
, buf
);
5764 /* Display a location list from a .dwo section. It uses address indexes rather
5765 than embedded addresses. This code closely follows display_loc_list, but the
5766 two are sufficiently different that combining things is very ugly. */
5769 display_loc_list_dwo (struct dwarf_section
*section
,
5770 unsigned char **start_ptr
,
5771 unsigned int debug_info_entry
,
5773 unsigned char **vstart_ptr
,
5776 unsigned char *start
= *start_ptr
, *vstart
= *vstart_ptr
;
5777 unsigned char *section_end
= section
->start
+ section
->size
;
5778 unsigned long cu_offset
;
5779 unsigned int pointer_size
;
5780 unsigned int offset_size
;
5783 unsigned short length
;
5784 int need_frame_base
;
5786 unsigned int bytes_read
;
5788 if (debug_info_entry
>= num_debug_info_entries
)
5790 warn (_("No debug information for loc lists of entry: %u\n"),
5795 cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
5796 pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
5797 offset_size
= debug_information
[debug_info_entry
].offset_size
;
5798 dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
5800 if (pointer_size
< 2 || pointer_size
> 8)
5802 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
5803 pointer_size
, debug_info_entry
);
5809 printf (" %8.8lx ", (unsigned long) (offset
+ (start
- *start_ptr
)));
5811 if (start
>= section_end
)
5813 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5814 (unsigned long) offset
);
5818 SAFE_BYTE_GET_AND_INC (entry_type
, start
, 1, section_end
);
5831 dwarf_vma off
= offset
+ (vstart
- *start_ptr
);
5833 view
= read_uleb128 (vstart
, &bytes_read
, section_end
);
5834 vstart
+= bytes_read
;
5835 print_dwarf_view (view
, 8, 1);
5837 view
= read_uleb128 (vstart
, &bytes_read
, section_end
);
5838 vstart
+= bytes_read
;
5839 print_dwarf_view (view
, 8, 1);
5841 printf (_("views at %8.8lx for:\n %*s "),
5842 (unsigned long) off
, 8, "");
5850 case 0: /* A terminating entry. */
5852 *vstart_ptr
= vstart
;
5853 printf (_("<End of list>\n"));
5855 case 1: /* A base-address entry. */
5856 idx
= read_uleb128 (start
, &bytes_read
, section_end
);
5857 start
+= bytes_read
;
5858 print_addr_index (idx
, 8);
5859 printf ("%*s", 9 + (vstart
? 2 * 6 : 0), "");
5860 printf (_("(base address selection entry)\n"));
5862 case 2: /* A start/end entry. */
5863 idx
= read_uleb128 (start
, &bytes_read
, section_end
);
5864 start
+= bytes_read
;
5865 print_addr_index (idx
, 8);
5866 idx
= read_uleb128 (start
, &bytes_read
, section_end
);
5867 start
+= bytes_read
;
5868 print_addr_index (idx
, 8);
5870 case 3: /* A start/length entry. */
5871 idx
= read_uleb128 (start
, &bytes_read
, section_end
);
5872 start
+= bytes_read
;
5873 print_addr_index (idx
, 8);
5874 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
5875 printf ("%08x ", idx
);
5877 case 4: /* An offset pair entry. */
5878 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
5879 printf ("%08x ", idx
);
5880 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
5881 printf ("%08x ", idx
);
5884 warn (_("Unknown location list entry type 0x%x.\n"), entry_type
);
5886 *vstart_ptr
= vstart
;
5890 if (start
+ 2 > section_end
)
5892 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5893 (unsigned long) offset
);
5897 SAFE_BYTE_GET_AND_INC (length
, start
, 2, section_end
);
5898 if (start
+ length
> section_end
)
5900 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5901 (unsigned long) offset
);
5906 need_frame_base
= decode_location_expression (start
,
5911 cu_offset
, section
);
5914 if (need_frame_base
&& !has_frame_base
)
5915 printf (_(" [without DW_AT_frame_base]"));
5923 *vstart_ptr
= vstart
;
5926 /* Sort array of indexes in ascending order of loc_offsets[idx] and
5929 static dwarf_vma
*loc_offsets
, *loc_views
;
5932 loc_offsets_compar (const void *ap
, const void *bp
)
5934 dwarf_vma a
= loc_offsets
[*(const unsigned int *) ap
];
5935 dwarf_vma b
= loc_offsets
[*(const unsigned int *) bp
];
5937 int ret
= (a
> b
) - (b
> a
);
5941 a
= loc_views
[*(const unsigned int *) ap
];
5942 b
= loc_views
[*(const unsigned int *) bp
];
5944 ret
= (a
> b
) - (b
> a
);
5950 display_debug_loc (struct dwarf_section
*section
, void *file
)
5952 unsigned char *start
= section
->start
, *vstart
= NULL
;
5953 unsigned long bytes
;
5954 unsigned char *section_begin
= start
;
5955 unsigned int num_loc_list
= 0;
5956 unsigned long last_offset
= 0;
5957 unsigned long last_view
= 0;
5958 unsigned int first
= 0;
5961 int seen_first_offset
= 0;
5962 int locs_sorted
= 1;
5963 unsigned char *next
= start
, *vnext
= vstart
;
5964 unsigned int *array
= NULL
;
5965 const char *suffix
= strrchr (section
->name
, '.');
5967 int is_loclists
= strstr (section
->name
, "debug_loclists") != NULL
;
5968 dwarf_vma expected_start
= 0;
5970 if (suffix
&& strcmp (suffix
, ".dwo") == 0)
5973 bytes
= section
->size
;
5977 printf (_("\nThe %s section is empty.\n"), section
->name
);
5983 unsigned char *hdrptr
= section_begin
;
5984 dwarf_vma ll_length
;
5985 unsigned short ll_version
;
5986 unsigned char *end
= section_begin
+ section
->size
;
5987 unsigned char address_size
, segment_selector_size
;
5988 uint32_t offset_entry_count
;
5990 SAFE_BYTE_GET_AND_INC (ll_length
, hdrptr
, 4, end
);
5991 if (ll_length
== 0xffffffff)
5992 SAFE_BYTE_GET_AND_INC (ll_length
, hdrptr
, 8, end
);
5994 SAFE_BYTE_GET_AND_INC (ll_version
, hdrptr
, 2, end
);
5995 if (ll_version
!= 5)
5997 warn (_("The %s section contains corrupt or "
5998 "unsupported version number: %d.\n"),
5999 section
->name
, ll_version
);
6003 SAFE_BYTE_GET_AND_INC (address_size
, hdrptr
, 1, end
);
6005 SAFE_BYTE_GET_AND_INC (segment_selector_size
, hdrptr
, 1, end
);
6006 if (segment_selector_size
!= 0)
6008 warn (_("The %s section contains "
6009 "unsupported segment selector size: %d.\n"),
6010 section
->name
, segment_selector_size
);
6014 SAFE_BYTE_GET_AND_INC (offset_entry_count
, hdrptr
, 4, end
);
6015 if (offset_entry_count
!= 0)
6017 warn (_("The %s section contains "
6018 "unsupported offset entry count: %d.\n"),
6019 section
->name
, offset_entry_count
);
6023 expected_start
= hdrptr
- section_begin
;
6026 if (load_debug_info (file
) == 0)
6028 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
6033 /* Check the order of location list in .debug_info section. If
6034 offsets of location lists are in the ascending order, we can
6035 use `debug_information' directly. */
6036 for (i
= 0; i
< num_debug_info_entries
; i
++)
6040 num
= debug_information
[i
].num_loc_offsets
;
6041 if (num
> num_loc_list
)
6044 /* Check if we can use `debug_information' directly. */
6045 if (locs_sorted
&& num
!= 0)
6047 if (!seen_first_offset
)
6049 /* This is the first location list. */
6050 last_offset
= debug_information
[i
].loc_offsets
[0];
6051 last_view
= debug_information
[i
].loc_views
[0];
6053 seen_first_offset
= 1;
6059 for (; j
< num
; j
++)
6062 debug_information
[i
].loc_offsets
[j
]
6063 || (last_offset
== debug_information
[i
].loc_offsets
[j
]
6064 && last_view
> debug_information
[i
].loc_views
[j
]))
6069 last_offset
= debug_information
[i
].loc_offsets
[j
];
6070 last_view
= debug_information
[i
].loc_views
[j
];
6075 if (!seen_first_offset
)
6076 error (_("No location lists in .debug_info section!\n"));
6078 if (debug_information
[first
].num_loc_offsets
> 0
6079 && debug_information
[first
].loc_offsets
[0] != expected_start
6080 && debug_information
[first
].loc_views
[0] != expected_start
)
6081 warn (_("Location lists in %s section start at 0x%s\n"),
6083 dwarf_vmatoa ("x", debug_information
[first
].loc_offsets
[0]));
6086 array
= (unsigned int *) xcmalloc (num_loc_list
, sizeof (unsigned int));
6088 introduce (section
, FALSE
);
6090 if (reloc_at (section
, 0))
6091 printf (_(" Warning: This section has relocations - addresses seen here may not be accurate.\n\n"));
6093 printf (_(" Offset Begin End Expression\n"));
6095 seen_first_offset
= 0;
6096 for (i
= first
; i
< num_debug_info_entries
; i
++)
6098 dwarf_vma offset
, voffset
;
6099 dwarf_vma base_address
;
6105 for (k
= 0; k
< debug_information
[i
].num_loc_offsets
; k
++)
6107 loc_offsets
= debug_information
[i
].loc_offsets
;
6108 loc_views
= debug_information
[i
].loc_views
;
6109 qsort (array
, debug_information
[i
].num_loc_offsets
,
6110 sizeof (*array
), loc_offsets_compar
);
6113 int adjacent_view_loclists
= 1;
6114 for (k
= 0; k
< debug_information
[i
].num_loc_offsets
; k
++)
6116 j
= locs_sorted
? k
: array
[k
];
6118 && (debug_information
[i
].loc_offsets
[locs_sorted
6119 ? k
- 1 : array
[k
- 1]]
6120 == debug_information
[i
].loc_offsets
[j
])
6121 && (debug_information
[i
].loc_views
[locs_sorted
6122 ? k
- 1 : array
[k
- 1]]
6123 == debug_information
[i
].loc_views
[j
]))
6125 has_frame_base
= debug_information
[i
].have_frame_base
[j
];
6126 offset
= debug_information
[i
].loc_offsets
[j
];
6127 next
= section_begin
+ offset
;
6128 voffset
= debug_information
[i
].loc_views
[j
];
6130 vnext
= section_begin
+ voffset
;
6133 base_address
= debug_information
[i
].base_address
;
6135 if (vnext
&& vnext
< next
)
6138 display_view_pair_list (section
, &vstart
, i
, next
);
6143 if (!seen_first_offset
|| !adjacent_view_loclists
)
6144 seen_first_offset
= 1;
6148 warn (_("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n"),
6149 (unsigned long) (start
- section_begin
),
6150 (unsigned long) offset
);
6151 else if (start
> next
)
6152 warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n"),
6153 (unsigned long) (start
- section_begin
),
6154 (unsigned long) offset
);
6159 if (offset
>= bytes
)
6161 warn (_("Offset 0x%lx is bigger than .debug_loc section size.\n"),
6162 (unsigned long) offset
);
6166 if (vnext
&& voffset
>= bytes
)
6168 warn (_("View Offset 0x%lx is bigger than .debug_loc section size.\n"),
6169 (unsigned long) voffset
);
6176 display_loc_list_dwo (section
, &start
, i
, offset
,
6177 &vstart
, has_frame_base
);
6179 display_loc_list (section
, &start
, i
, offset
, base_address
,
6180 &vstart
, has_frame_base
);
6185 warn (_("DWO is not yet supported.\n"));
6187 display_loclists_list (section
, &start
, i
, offset
, base_address
,
6188 &vstart
, has_frame_base
);
6191 /* FIXME: this arrangement is quite simplistic. Nothing
6192 requires locview lists to be adjacent to corresponding
6193 loclists, and a single loclist could be augmented by
6194 different locview lists, and vice-versa, unlikely as it
6195 is that it would make sense to do so. Hopefully we'll
6196 have view pair support built into loclists before we ever
6197 need to address all these possibilities. */
6198 if (adjacent_view_loclists
&& vnext
6199 && vnext
!= start
&& vstart
!= next
)
6201 adjacent_view_loclists
= 0;
6202 warn (_("Hole and overlap detection requires adjacent view lists and loclists.\n"));
6205 if (vnext
&& vnext
== start
)
6206 display_view_pair_list (section
, &start
, i
, vstart
);
6210 if (start
< section
->start
+ section
->size
)
6211 warn (ngettext ("There is %ld unused byte at the end of section %s\n",
6212 "There are %ld unused bytes at the end of section %s\n",
6213 (long) (section
->start
+ section
->size
- start
)),
6214 (long) (section
->start
+ section
->size
- start
), section
->name
);
6221 display_debug_str (struct dwarf_section
*section
,
6222 void *file ATTRIBUTE_UNUSED
)
6224 unsigned char *start
= section
->start
;
6225 unsigned long bytes
= section
->size
;
6226 dwarf_vma addr
= section
->address
;
6230 printf (_("\nThe %s section is empty.\n"), section
->name
);
6234 introduce (section
, FALSE
);
6242 lbytes
= (bytes
> 16 ? 16 : bytes
);
6244 printf (" 0x%8.8lx ", (unsigned long) addr
);
6246 for (j
= 0; j
< 16; j
++)
6249 printf ("%2.2x", start
[j
]);
6257 for (j
= 0; j
< lbytes
; j
++)
6260 if (k
>= ' ' && k
< 0x80)
6279 display_debug_info (struct dwarf_section
*section
, void *file
)
6281 return process_debug_info (section
, file
, section
->abbrev_sec
, FALSE
, FALSE
);
6285 display_debug_types (struct dwarf_section
*section
, void *file
)
6287 return process_debug_info (section
, file
, section
->abbrev_sec
, FALSE
, TRUE
);
6291 display_trace_info (struct dwarf_section
*section
, void *file
)
6293 return process_debug_info (section
, file
, section
->abbrev_sec
, FALSE
, TRUE
);
6297 display_debug_aranges (struct dwarf_section
*section
,
6298 void *file ATTRIBUTE_UNUSED
)
6300 unsigned char *start
= section
->start
;
6301 unsigned char *end
= start
+ section
->size
;
6303 introduce (section
, FALSE
);
6305 /* It does not matter if this load fails,
6306 we test for that later on. */
6307 load_debug_info (file
);
6311 unsigned char *hdrptr
;
6312 DWARF2_Internal_ARange arange
;
6313 unsigned char *addr_ranges
;
6316 unsigned long sec_off
;
6317 unsigned char address_size
;
6319 unsigned int offset_size
;
6320 unsigned int initial_length_size
;
6324 SAFE_BYTE_GET_AND_INC (arange
.ar_length
, hdrptr
, 4, end
);
6325 if (arange
.ar_length
== 0xffffffff)
6327 SAFE_BYTE_GET_AND_INC (arange
.ar_length
, hdrptr
, 8, end
);
6329 initial_length_size
= 12;
6334 initial_length_size
= 4;
6337 sec_off
= hdrptr
- section
->start
;
6338 if (sec_off
+ arange
.ar_length
< sec_off
6339 || sec_off
+ arange
.ar_length
> section
->size
)
6341 warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"),
6343 sec_off
- initial_length_size
,
6344 dwarf_vmatoa ("x", arange
.ar_length
));
6348 SAFE_BYTE_GET_AND_INC (arange
.ar_version
, hdrptr
, 2, end
);
6349 SAFE_BYTE_GET_AND_INC (arange
.ar_info_offset
, hdrptr
, offset_size
, end
);
6351 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
6352 && num_debug_info_entries
> 0
6353 && find_debug_info_for_offset (arange
.ar_info_offset
) == NULL
)
6354 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
6355 (unsigned long) arange
.ar_info_offset
, section
->name
);
6357 SAFE_BYTE_GET_AND_INC (arange
.ar_pointer_size
, hdrptr
, 1, end
);
6358 SAFE_BYTE_GET_AND_INC (arange
.ar_segment_size
, hdrptr
, 1, end
);
6360 if (arange
.ar_version
!= 2 && arange
.ar_version
!= 3)
6362 /* PR 19872: A version number of 0 probably means that there is
6363 padding at the end of the .debug_aranges section. Gold puts
6364 it there when performing an incremental link, for example.
6365 So do not generate a warning in this case. */
6366 if (arange
.ar_version
)
6367 warn (_("Only DWARF 2 and 3 aranges are currently supported.\n"));
6371 printf (_(" Length: %ld\n"),
6372 (long) arange
.ar_length
);
6373 printf (_(" Version: %d\n"), arange
.ar_version
);
6374 printf (_(" Offset into .debug_info: 0x%lx\n"),
6375 (unsigned long) arange
.ar_info_offset
);
6376 printf (_(" Pointer Size: %d\n"), arange
.ar_pointer_size
);
6377 printf (_(" Segment Size: %d\n"), arange
.ar_segment_size
);
6379 address_size
= arange
.ar_pointer_size
+ arange
.ar_segment_size
;
6381 /* PR 17512: file: 001-108546-0.001:0.1. */
6382 if (address_size
== 0 || address_size
> 8)
6384 error (_("Invalid address size in %s section!\n"),
6389 /* The DWARF spec does not require that the address size be a power
6390 of two, but we do. This will have to change if we ever encounter
6391 an uneven architecture. */
6392 if ((address_size
& (address_size
- 1)) != 0)
6394 warn (_("Pointer size + Segment size is not a power of two.\n"));
6398 if (address_size
> 4)
6399 printf (_("\n Address Length\n"));
6401 printf (_("\n Address Length\n"));
6403 addr_ranges
= hdrptr
;
6405 /* Must pad to an alignment boundary that is twice the address size. */
6406 excess
= (hdrptr
- start
) % (2 * address_size
);
6408 addr_ranges
+= (2 * address_size
) - excess
;
6410 start
+= arange
.ar_length
+ initial_length_size
;
6412 while (addr_ranges
+ 2 * address_size
<= start
)
6414 SAFE_BYTE_GET_AND_INC (address
, addr_ranges
, address_size
, end
);
6415 SAFE_BYTE_GET_AND_INC (length
, addr_ranges
, address_size
, end
);
6418 print_dwarf_vma (address
, address_size
);
6419 print_dwarf_vma (length
, address_size
);
6429 /* Comparison function for qsort. */
6431 comp_addr_base (const void * v0
, const void * v1
)
6433 debug_info
* info0
= (debug_info
*) v0
;
6434 debug_info
* info1
= (debug_info
*) v1
;
6435 return info0
->addr_base
- info1
->addr_base
;
6438 /* Display the debug_addr section. */
6440 display_debug_addr (struct dwarf_section
*section
,
6443 debug_info
**debug_addr_info
;
6444 unsigned char *entry
;
6449 if (section
->size
== 0)
6451 printf (_("\nThe %s section is empty.\n"), section
->name
);
6455 if (load_debug_info (file
) == 0)
6457 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
6462 introduce (section
, FALSE
);
6464 /* PR 17531: file: cf38d01b.
6465 We use xcalloc because a corrupt file may not have initialised all of the
6466 fields in the debug_info structure, which means that the sort below might
6467 try to move uninitialised data. */
6468 debug_addr_info
= (debug_info
**) xcalloc ((num_debug_info_entries
+ 1),
6469 sizeof (debug_info
*));
6472 for (i
= 0; i
< num_debug_info_entries
; i
++)
6473 if (debug_information
[i
].addr_base
!= DEBUG_INFO_UNAVAILABLE
)
6475 /* PR 17531: file: cf38d01b. */
6476 if (debug_information
[i
].addr_base
>= section
->size
)
6477 warn (_("Corrupt address base (%lx) found in debug section %u\n"),
6478 (unsigned long) debug_information
[i
].addr_base
, i
);
6480 debug_addr_info
[count
++] = debug_information
+ i
;
6483 /* Add a sentinel to make iteration convenient. */
6484 debug_addr_info
[count
] = (debug_info
*) xmalloc (sizeof (debug_info
));
6485 debug_addr_info
[count
]->addr_base
= section
->size
;
6486 qsort (debug_addr_info
, count
, sizeof (debug_info
*), comp_addr_base
);
6488 for (i
= 0; i
< count
; i
++)
6491 unsigned int address_size
= debug_addr_info
[i
]->pointer_size
;
6493 printf (_(" For compilation unit at offset 0x%s:\n"),
6494 dwarf_vmatoa ("x", debug_addr_info
[i
]->cu_offset
));
6496 printf (_("\tIndex\tAddress\n"));
6497 entry
= section
->start
+ debug_addr_info
[i
]->addr_base
;
6498 end
= section
->start
+ debug_addr_info
[i
+ 1]->addr_base
;
6502 dwarf_vma base
= byte_get (entry
, address_size
);
6503 printf (_("\t%d:\t"), idx
);
6504 print_dwarf_vma (base
, address_size
);
6506 entry
+= address_size
;
6512 free (debug_addr_info
);
6516 /* Display the .debug_str_offsets and .debug_str_offsets.dwo sections. */
6518 display_debug_str_offsets (struct dwarf_section
*section
,
6519 void *file ATTRIBUTE_UNUSED
)
6521 if (section
->size
== 0)
6523 printf (_("\nThe %s section is empty.\n"), section
->name
);
6526 /* TODO: Dump the contents. This is made somewhat difficult by not knowing
6527 what the offset size is for this section. */
6531 /* Each debug_information[x].range_lists[y] gets this representation for
6532 sorting purposes. */
6536 /* The debug_information[x].range_lists[y] value. */
6537 dwarf_vma ranges_offset
;
6539 /* Original debug_information to find parameters of the data. */
6540 debug_info
*debug_info_p
;
6543 /* Sort struct range_entry in ascending order of its RANGES_OFFSET. */
6546 range_entry_compar (const void *ap
, const void *bp
)
6548 const struct range_entry
*a_re
= (const struct range_entry
*) ap
;
6549 const struct range_entry
*b_re
= (const struct range_entry
*) bp
;
6550 const dwarf_vma a
= a_re
->ranges_offset
;
6551 const dwarf_vma b
= b_re
->ranges_offset
;
6553 return (a
> b
) - (b
> a
);
6557 display_debug_ranges_list (unsigned char *start
, unsigned char *finish
,
6558 unsigned int pointer_size
, unsigned long offset
,
6559 unsigned long base_address
)
6561 while (start
< finish
)
6566 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
6567 if (start
>= finish
)
6569 SAFE_SIGNED_BYTE_GET_AND_INC (end
, start
, pointer_size
, finish
);
6572 printf (" %8.8lx ", offset
);
6574 if (begin
== 0 && end
== 0)
6576 printf (_("<End of list>\n"));
6580 /* Check base address specifiers. */
6581 if (is_max_address (begin
, pointer_size
)
6582 && !is_max_address (end
, pointer_size
))
6585 print_dwarf_vma (begin
, pointer_size
);
6586 print_dwarf_vma (end
, pointer_size
);
6587 printf ("(base address)\n");
6591 print_dwarf_vma (begin
+ base_address
, pointer_size
);
6592 print_dwarf_vma (end
+ base_address
, pointer_size
);
6595 fputs (_("(start == end)"), stdout
);
6596 else if (begin
> end
)
6597 fputs (_("(start > end)"), stdout
);
6604 display_debug_rnglists_list (unsigned char *start
, unsigned char *finish
,
6605 unsigned int pointer_size
, unsigned long offset
,
6606 unsigned long base_address
)
6608 unsigned char *next
= start
;
6612 unsigned long off
= offset
+ (start
- next
);
6613 enum dwarf_range_list_entry rlet
;
6614 /* Initialize it due to a false compiler warning. */
6615 dwarf_vma begin
= -1, length
, end
= -1;
6616 unsigned int bytes_read
;
6618 if (start
+ 1 > finish
)
6620 warn (_("Range list starting at offset 0x%lx is not terminated.\n"),
6625 printf (" %8.8lx ", off
);
6627 SAFE_BYTE_GET_AND_INC (rlet
, start
, 1, finish
);
6631 case DW_RLE_end_of_list
:
6632 printf (_("<End of list>\n"));
6634 case DW_RLE_base_address
:
6635 SAFE_BYTE_GET_AND_INC (base_address
, start
, pointer_size
, finish
);
6636 print_dwarf_vma (base_address
, pointer_size
);
6637 printf (_("(base address)\n"));
6639 case DW_RLE_start_length
:
6640 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
6641 length
= read_uleb128 (start
, &bytes_read
, finish
);
6642 start
+= bytes_read
;
6643 end
= begin
+ length
;
6645 case DW_RLE_offset_pair
:
6646 begin
= read_uleb128 (start
, &bytes_read
, finish
);
6647 start
+= bytes_read
;
6648 end
= read_uleb128 (start
, &bytes_read
, finish
);
6649 start
+= bytes_read
;
6651 case DW_RLE_start_end
:
6652 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
6653 SAFE_BYTE_GET_AND_INC (end
, start
, pointer_size
, finish
);
6656 error (_("Invalid range list entry type %d\n"), rlet
);
6657 rlet
= DW_RLE_end_of_list
;
6660 if (rlet
== DW_RLE_end_of_list
)
6662 if (rlet
== DW_RLE_base_address
)
6665 print_dwarf_vma (begin
+ base_address
, pointer_size
);
6666 print_dwarf_vma (end
+ base_address
, pointer_size
);
6669 fputs (_("(start == end)"), stdout
);
6670 else if (begin
> end
)
6671 fputs (_("(start > end)"), stdout
);
6678 display_debug_ranges (struct dwarf_section
*section
,
6679 void *file ATTRIBUTE_UNUSED
)
6681 unsigned char *start
= section
->start
;
6682 unsigned char *last_start
= start
;
6683 unsigned long bytes
= section
->size
;
6684 unsigned char *section_begin
= start
;
6685 unsigned char *finish
= start
+ bytes
;
6686 unsigned int num_range_list
, i
;
6687 struct range_entry
*range_entries
, *range_entry_fill
;
6688 int is_rnglists
= strstr (section
->name
, "debug_rnglists") != NULL
;
6689 /* Initialize it due to a false compiler warning. */
6690 unsigned char address_size
= 0;
6694 printf (_("\nThe %s section is empty.\n"), section
->name
);
6700 dwarf_vma initial_length
;
6701 unsigned int initial_length_size
;
6702 unsigned char segment_selector_size
;
6703 unsigned int offset_size
, offset_entry_count
;
6704 unsigned short version
;
6706 /* Get and check the length of the block. */
6707 SAFE_BYTE_GET_AND_INC (initial_length
, start
, 4, finish
);
6709 if (initial_length
== 0xffffffff)
6711 /* This section is 64-bit DWARF 3. */
6712 SAFE_BYTE_GET_AND_INC (initial_length
, start
, 8, finish
);
6714 initial_length_size
= 12;
6719 initial_length_size
= 4;
6722 if (initial_length
+ initial_length_size
> section
->size
)
6724 /* If the length field has a relocation against it, then we should
6725 not complain if it is inaccurate (and probably negative).
6726 It is copied from .debug_line handling code. */
6727 if (reloc_at (section
, (start
- section
->start
) - offset_size
))
6729 initial_length
= (finish
- start
) - initial_length_size
;
6733 warn (_("The length field (0x%lx) in the debug_rnglists header is wrong - the section is too small\n"),
6734 (long) initial_length
);
6739 /* Get and check the version number. */
6740 SAFE_BYTE_GET_AND_INC (version
, start
, 2, finish
);
6744 warn (_("Only DWARF version 5 debug_rnglists info "
6745 "is currently supported.\n"));
6749 SAFE_BYTE_GET_AND_INC (address_size
, start
, 1, finish
);
6751 SAFE_BYTE_GET_AND_INC (segment_selector_size
, start
, 1, finish
);
6752 if (segment_selector_size
!= 0)
6754 warn (_("The %s section contains "
6755 "unsupported segment selector size: %d.\n"),
6756 section
->name
, segment_selector_size
);
6760 SAFE_BYTE_GET_AND_INC (offset_entry_count
, start
, 4, finish
);
6761 if (offset_entry_count
!= 0)
6763 warn (_("The %s section contains "
6764 "unsupported offset entry count: %u.\n"),
6765 section
->name
, offset_entry_count
);
6770 if (load_debug_info (file
) == 0)
6772 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
6778 for (i
= 0; i
< num_debug_info_entries
; i
++)
6779 num_range_list
+= debug_information
[i
].num_range_lists
;
6781 if (num_range_list
== 0)
6783 /* This can happen when the file was compiled with -gsplit-debug
6784 which removes references to range lists from the primary .o file. */
6785 printf (_("No range lists in .debug_info section.\n"));
6789 range_entries
= (struct range_entry
*)
6790 xmalloc (sizeof (*range_entries
) * num_range_list
);
6791 range_entry_fill
= range_entries
;
6793 for (i
= 0; i
< num_debug_info_entries
; i
++)
6795 debug_info
*debug_info_p
= &debug_information
[i
];
6798 for (j
= 0; j
< debug_info_p
->num_range_lists
; j
++)
6800 range_entry_fill
->ranges_offset
= debug_info_p
->range_lists
[j
];
6801 range_entry_fill
->debug_info_p
= debug_info_p
;
6806 qsort (range_entries
, num_range_list
, sizeof (*range_entries
),
6807 range_entry_compar
);
6809 if (dwarf_check
!= 0 && range_entries
[0].ranges_offset
!= 0)
6810 warn (_("Range lists in %s section start at 0x%lx\n"),
6811 section
->name
, (unsigned long) range_entries
[0].ranges_offset
);
6813 introduce (section
, FALSE
);
6815 printf (_(" Offset Begin End\n"));
6817 for (i
= 0; i
< num_range_list
; i
++)
6819 struct range_entry
*range_entry
= &range_entries
[i
];
6820 debug_info
*debug_info_p
= range_entry
->debug_info_p
;
6821 unsigned int pointer_size
;
6823 unsigned char *next
;
6824 dwarf_vma base_address
;
6826 pointer_size
= (is_rnglists
? address_size
: debug_info_p
->pointer_size
);
6827 offset
= range_entry
->ranges_offset
;
6828 next
= section_begin
+ offset
;
6829 base_address
= debug_info_p
->base_address
;
6831 /* PR 17512: file: 001-101485-0.001:0.1. */
6832 if (pointer_size
< 2 || pointer_size
> 8)
6834 warn (_("Corrupt pointer size (%d) in debug entry at offset %8.8lx\n"),
6835 pointer_size
, (unsigned long) offset
);
6839 if (next
< section_begin
|| next
>= finish
)
6841 warn (_("Corrupt offset (%#8.8lx) in range entry %u\n"),
6842 (unsigned long) offset
, i
);
6846 if (dwarf_check
!= 0 && i
> 0)
6849 warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"),
6850 (unsigned long) (start
- section_begin
),
6851 (unsigned long) (next
- section_begin
), section
->name
);
6852 else if (start
> next
)
6854 if (next
== last_start
)
6856 warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"),
6857 (unsigned long) (start
- section_begin
),
6858 (unsigned long) (next
- section_begin
), section
->name
);
6865 (is_rnglists
? display_debug_rnglists_list
: display_debug_ranges_list
)
6866 (start
, finish
, pointer_size
, offset
, base_address
);
6870 free (range_entries
);
6875 typedef struct Frame_Chunk
6877 struct Frame_Chunk
*next
;
6878 unsigned char *chunk_start
;
6880 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
6881 short int *col_type
;
6884 unsigned int code_factor
;
6888 unsigned int cfa_reg
;
6889 dwarf_vma cfa_offset
;
6891 unsigned char fde_encoding
;
6892 unsigned char cfa_exp
;
6893 unsigned char ptr_size
;
6894 unsigned char segment_size
;
6898 static const char *const *dwarf_regnames
;
6899 static unsigned int dwarf_regnames_count
;
6901 /* A marker for a col_type that means this column was never referenced
6902 in the frame info. */
6903 #define DW_CFA_unreferenced (-1)
6905 /* Return 0 if no more space is needed, 1 if more space is needed,
6906 -1 for invalid reg. */
6909 frame_need_space (Frame_Chunk
*fc
, unsigned int reg
)
6911 unsigned int prev
= fc
->ncols
;
6913 if (reg
< (unsigned int) fc
->ncols
)
6916 if (dwarf_regnames_count
6917 && reg
> dwarf_regnames_count
)
6920 fc
->ncols
= reg
+ 1;
6921 /* PR 17512: file: 10450-2643-0.004.
6922 If reg == -1 then this can happen... */
6926 /* PR 17512: file: 2844a11d. */
6927 if (fc
->ncols
> 1024)
6929 error (_("Unfeasibly large register number: %u\n"), reg
);
6931 /* FIXME: 1024 is an arbitrary limit. Increase it if
6932 we ever encounter a valid binary that exceeds it. */
6936 fc
->col_type
= (short int *) xcrealloc (fc
->col_type
, fc
->ncols
,
6937 sizeof (short int));
6938 fc
->col_offset
= (int *) xcrealloc (fc
->col_offset
, fc
->ncols
, sizeof (int));
6939 /* PR 17512: file:002-10025-0.005. */
6940 if (fc
->col_type
== NULL
|| fc
->col_offset
== NULL
)
6942 error (_("Out of memory allocating %u columns in dwarf frame arrays\n"),
6948 while (prev
< fc
->ncols
)
6950 fc
->col_type
[prev
] = DW_CFA_unreferenced
;
6951 fc
->col_offset
[prev
] = 0;
6957 static const char *const dwarf_regnames_i386
[] =
6959 "eax", "ecx", "edx", "ebx", /* 0 - 3 */
6960 "esp", "ebp", "esi", "edi", /* 4 - 7 */
6961 "eip", "eflags", NULL
, /* 8 - 10 */
6962 "st0", "st1", "st2", "st3", /* 11 - 14 */
6963 "st4", "st5", "st6", "st7", /* 15 - 18 */
6964 NULL
, NULL
, /* 19 - 20 */
6965 "xmm0", "xmm1", "xmm2", "xmm3", /* 21 - 24 */
6966 "xmm4", "xmm5", "xmm6", "xmm7", /* 25 - 28 */
6967 "mm0", "mm1", "mm2", "mm3", /* 29 - 32 */
6968 "mm4", "mm5", "mm6", "mm7", /* 33 - 36 */
6969 "fcw", "fsw", "mxcsr", /* 37 - 39 */
6970 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
, /* 40 - 47 */
6971 "tr", "ldtr", /* 48 - 49 */
6972 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 50 - 57 */
6973 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 58 - 65 */
6974 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 66 - 73 */
6975 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 74 - 81 */
6976 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 82 - 89 */
6977 NULL
, NULL
, NULL
, /* 90 - 92 */
6978 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7" /* 93 - 100 */
6981 static const char *const dwarf_regnames_iamcu
[] =
6983 "eax", "ecx", "edx", "ebx", /* 0 - 3 */
6984 "esp", "ebp", "esi", "edi", /* 4 - 7 */
6985 "eip", "eflags", NULL
, /* 8 - 10 */
6986 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 11 - 18 */
6987 NULL
, NULL
, /* 19 - 20 */
6988 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 21 - 28 */
6989 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 29 - 36 */
6990 NULL
, NULL
, NULL
, /* 37 - 39 */
6991 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
, /* 40 - 47 */
6992 "tr", "ldtr", /* 48 - 49 */
6993 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 50 - 57 */
6994 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 58 - 65 */
6995 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 66 - 73 */
6996 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 74 - 81 */
6997 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 82 - 89 */
6998 NULL
, NULL
, NULL
, /* 90 - 92 */
6999 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
/* 93 - 100 */
7003 init_dwarf_regnames_i386 (void)
7005 dwarf_regnames
= dwarf_regnames_i386
;
7006 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_i386
);
7010 init_dwarf_regnames_iamcu (void)
7012 dwarf_regnames
= dwarf_regnames_iamcu
;
7013 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_iamcu
);
7016 static const char *const dwarf_regnames_x86_64
[] =
7018 "rax", "rdx", "rcx", "rbx",
7019 "rsi", "rdi", "rbp", "rsp",
7020 "r8", "r9", "r10", "r11",
7021 "r12", "r13", "r14", "r15",
7023 "xmm0", "xmm1", "xmm2", "xmm3",
7024 "xmm4", "xmm5", "xmm6", "xmm7",
7025 "xmm8", "xmm9", "xmm10", "xmm11",
7026 "xmm12", "xmm13", "xmm14", "xmm15",
7027 "st0", "st1", "st2", "st3",
7028 "st4", "st5", "st6", "st7",
7029 "mm0", "mm1", "mm2", "mm3",
7030 "mm4", "mm5", "mm6", "mm7",
7032 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
,
7033 "fs.base", "gs.base", NULL
, NULL
,
7035 "mxcsr", "fcw", "fsw",
7036 "xmm16", "xmm17", "xmm18", "xmm19",
7037 "xmm20", "xmm21", "xmm22", "xmm23",
7038 "xmm24", "xmm25", "xmm26", "xmm27",
7039 "xmm28", "xmm29", "xmm30", "xmm31",
7040 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 83 - 90 */
7041 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 91 - 98 */
7042 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 99 - 106 */
7043 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 107 - 114 */
7044 NULL
, NULL
, NULL
, /* 115 - 117 */
7045 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7"
7049 init_dwarf_regnames_x86_64 (void)
7051 dwarf_regnames
= dwarf_regnames_x86_64
;
7052 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_x86_64
);
7055 static const char *const dwarf_regnames_aarch64
[] =
7057 "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7",
7058 "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15",
7059 "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23",
7060 "x24", "x25", "x26", "x27", "x28", "x29", "x30", "sp",
7061 NULL
, "elr", NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
7062 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
7063 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
7064 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
7065 "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7",
7066 "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15",
7067 "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23",
7068 "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31",
7072 init_dwarf_regnames_aarch64 (void)
7074 dwarf_regnames
= dwarf_regnames_aarch64
;
7075 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_aarch64
);
7078 static const char *const dwarf_regnames_s390
[] =
7080 /* Avoid saying "r5 (r5)", so omit the names of r0-r15. */
7081 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
7082 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
7083 "f0", "f2", "f4", "f6", "f1", "f3", "f5", "f7",
7084 "f8", "f10", "f12", "f14", "f9", "f11", "f13", "f15",
7085 "cr0", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7",
7086 "cr8", "cr9", "cr10", "cr11", "cr12", "cr13", "cr14", "cr15",
7087 "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7",
7088 "a8", "a9", "a10", "a11", "a12", "a13", "a14", "a15",
7091 "v16", "v18", "v20", "v22", "v17", "v19", "v21", "v23",
7092 "v24", "v26", "v28", "v30", "v25", "v27", "v29", "v31",
7096 init_dwarf_regnames_s390 (void)
7098 dwarf_regnames
= dwarf_regnames_s390
;
7099 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_s390
);
7102 static const char *const dwarf_regnames_riscv
[] =
7104 "zero", "ra", "sp", "gp", "tp", "t0", "t1", "t2", /* 0 - 7 */
7105 "s0", "s1", "a0", "a1", "a2", "a3", "a4", "a5", /* 8 - 15 */
7106 "a6", "a7", "s2", "s3", "s4", "s5", "s6", "s7", /* 16 - 23 */
7107 "s8", "s9", "s10", "s11", "t3", "t4", "t5", "t6", /* 24 - 31 */
7108 "ft0", "ft1", "ft2", "ft3", "ft4", "ft5", "ft6", "ft7", /* 32 - 39 */
7109 "fs0", "fs1", /* 40 - 41 */
7110 "fa0", "fa1", "fa2", "fa3", "fa4", "fa5", "fa6", "fa7", /* 42 - 49 */
7111 "fs2", "fs3", "fs4", "fs5", "fs6", "fs7", "fs8", "fs9", /* 50 - 57 */
7112 "fs10", "fs11", /* 58 - 59 */
7113 "ft8", "ft9", "ft10", "ft11" /* 60 - 63 */
7117 init_dwarf_regnames_riscv (void)
7119 dwarf_regnames
= dwarf_regnames_riscv
;
7120 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_riscv
);
7124 init_dwarf_regnames (unsigned int e_machine
)
7129 init_dwarf_regnames_i386 ();
7133 init_dwarf_regnames_iamcu ();
7139 init_dwarf_regnames_x86_64 ();
7143 init_dwarf_regnames_aarch64 ();
7147 init_dwarf_regnames_s390 ();
7151 init_dwarf_regnames_riscv ();
7160 regname (unsigned int regno
, int row
)
7162 static char reg
[64];
7165 && regno
< dwarf_regnames_count
7166 && dwarf_regnames
[regno
] != NULL
)
7169 return dwarf_regnames
[regno
];
7170 snprintf (reg
, sizeof (reg
), "r%d (%s)", regno
,
7171 dwarf_regnames
[regno
]);
7174 snprintf (reg
, sizeof (reg
), "r%d", regno
);
7179 frame_display_row (Frame_Chunk
*fc
, int *need_col_headers
, unsigned int *max_regs
)
7184 if (*max_regs
!= fc
->ncols
)
7185 *max_regs
= fc
->ncols
;
7187 if (*need_col_headers
)
7189 static const char *sloc
= " LOC";
7191 *need_col_headers
= 0;
7193 printf ("%-*s CFA ", eh_addr_size
* 2, sloc
);
7195 for (r
= 0; r
< *max_regs
; r
++)
7196 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
7201 printf ("%-5s ", regname (r
, 1));
7207 print_dwarf_vma (fc
->pc_begin
, eh_addr_size
);
7209 strcpy (tmp
, "exp");
7211 sprintf (tmp
, "%s%+d", regname (fc
->cfa_reg
, 1), (int) fc
->cfa_offset
);
7212 printf ("%-8s ", tmp
);
7214 for (r
= 0; r
< fc
->ncols
; r
++)
7216 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
7218 switch (fc
->col_type
[r
])
7220 case DW_CFA_undefined
:
7223 case DW_CFA_same_value
:
7227 sprintf (tmp
, "c%+d", fc
->col_offset
[r
]);
7229 case DW_CFA_val_offset
:
7230 sprintf (tmp
, "v%+d", fc
->col_offset
[r
]);
7232 case DW_CFA_register
:
7233 sprintf (tmp
, "%s", regname (fc
->col_offset
[r
], 0));
7235 case DW_CFA_expression
:
7236 strcpy (tmp
, "exp");
7238 case DW_CFA_val_expression
:
7239 strcpy (tmp
, "vexp");
7242 strcpy (tmp
, "n/a");
7245 printf ("%-5s ", tmp
);
7251 #define GET(VAR, N) SAFE_BYTE_GET_AND_INC (VAR, start, N, end)
7253 static unsigned char *
7254 read_cie (unsigned char *start
, unsigned char *end
,
7255 Frame_Chunk
**p_cie
, int *p_version
,
7256 bfd_size_type
*p_aug_len
, unsigned char **p_aug
)
7260 unsigned int length_return
;
7261 unsigned char *augmentation_data
= NULL
;
7262 bfd_size_type augmentation_data_len
= 0;
7265 /* PR 17512: file: 001-228113-0.004. */
7269 fc
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
7270 memset (fc
, 0, sizeof (Frame_Chunk
));
7272 fc
->col_type
= (short int *) xmalloc (sizeof (short int));
7273 fc
->col_offset
= (int *) xmalloc (sizeof (int));
7277 fc
->augmentation
= (char *) start
;
7278 /* PR 17512: file: 001-228113-0.004.
7279 Skip past augmentation name, but avoid running off the end of the data. */
7281 if (* start
++ == '\0')
7285 warn (_("No terminator for augmentation name\n"));
7289 if (strcmp (fc
->augmentation
, "eh") == 0)
7290 start
+= eh_addr_size
;
7294 GET (fc
->ptr_size
, 1);
7295 if (fc
->ptr_size
< 1 || fc
->ptr_size
> 8)
7297 warn (_("Invalid pointer size (%d) in CIE data\n"), fc
->ptr_size
);
7301 GET (fc
->segment_size
, 1);
7302 /* PR 17512: file: e99d2804. */
7303 if (fc
->segment_size
> 8 || fc
->segment_size
+ fc
->ptr_size
> 8)
7305 warn (_("Invalid segment size (%d) in CIE data\n"), fc
->segment_size
);
7309 eh_addr_size
= fc
->ptr_size
;
7313 fc
->ptr_size
= eh_addr_size
;
7314 fc
->segment_size
= 0;
7316 READ_ULEB (fc
->code_factor
);
7317 READ_SLEB (fc
->data_factor
);
7327 if (fc
->augmentation
[0] == 'z')
7329 READ_ULEB (augmentation_data_len
);
7330 augmentation_data
= start
;
7331 /* PR 17512: file: 11042-2589-0.004. */
7332 if (augmentation_data_len
> (bfd_size_type
) (end
- start
))
7334 warn (_("Augmentation data too long: 0x%s, expected at most %#lx\n"),
7335 dwarf_vmatoa ("x", augmentation_data_len
),
7336 (unsigned long) (end
- start
));
7339 start
+= augmentation_data_len
;
7342 if (augmentation_data_len
)
7346 unsigned char *qend
;
7348 p
= (unsigned char *) fc
->augmentation
+ 1;
7349 q
= augmentation_data
;
7350 qend
= q
+ augmentation_data_len
;
7352 while (p
< end
&& q
< qend
)
7357 q
+= 1 + size_of_encoded_value (*q
);
7359 fc
->fde_encoding
= *q
++;
7366 /* Note - it is OK if this loop terminates with q < qend.
7367 Padding may have been inserted to align the end of the CIE. */
7372 *p_version
= version
;
7375 *p_aug_len
= augmentation_data_len
;
7376 *p_aug
= augmentation_data
;
7381 /* Prints out the contents on the DATA array formatted as unsigned bytes.
7382 If do_wide is not enabled, then formats the output to fit into 80 columns.
7383 PRINTED contains the number of characters already written to the current
7387 display_data (bfd_size_type printed
,
7388 const unsigned char * data
,
7389 const bfd_size_type len
)
7391 if (do_wide
|| len
< ((80 - printed
) / 3))
7392 for (printed
= 0; printed
< len
; ++printed
)
7393 printf (" %02x", data
[printed
]);
7396 for (printed
= 0; printed
< len
; ++printed
)
7398 if (printed
% (80 / 3) == 0)
7400 printf (" %02x", data
[printed
]);
7405 /* Prints out the contents on the augmentation data array.
7406 If do_wide is not enabled, then formats the output to fit into 80 columns. */
7409 display_augmentation_data (const unsigned char * data
, const bfd_size_type len
)
7413 i
= printf (_(" Augmentation data: "));
7414 display_data (i
, data
, len
);
7418 display_debug_frames (struct dwarf_section
*section
,
7419 void *file ATTRIBUTE_UNUSED
)
7421 unsigned char *start
= section
->start
;
7422 unsigned char *end
= start
+ section
->size
;
7423 unsigned char *section_start
= start
;
7424 Frame_Chunk
*chunks
= 0, *forward_refs
= 0;
7425 Frame_Chunk
*remembered_state
= 0;
7427 int is_eh
= strcmp (section
->name
, ".eh_frame") == 0;
7428 unsigned int length_return
;
7429 unsigned int max_regs
= 0;
7430 const char *bad_reg
= _("bad register: ");
7431 unsigned int saved_eh_addr_size
= eh_addr_size
;
7433 introduce (section
, FALSE
);
7437 unsigned char *saved_start
;
7438 unsigned char *block_end
;
7443 int need_col_headers
= 1;
7444 unsigned char *augmentation_data
= NULL
;
7445 bfd_size_type augmentation_data_len
= 0;
7446 unsigned int encoded_ptr_size
= saved_eh_addr_size
;
7447 unsigned int offset_size
;
7448 unsigned int initial_length_size
;
7449 bfd_boolean all_nops
;
7451 saved_start
= start
;
7453 SAFE_BYTE_GET_AND_INC (length
, start
, 4, end
);
7457 printf ("\n%08lx ZERO terminator\n\n",
7458 (unsigned long)(saved_start
- section_start
));
7459 /* Skip any zero terminators that directly follow.
7460 A corrupt section size could have loaded a whole
7461 slew of zero filled memory bytes. eg
7462 PR 17512: file: 070-19381-0.004. */
7463 while (start
< end
&& * start
== 0)
7468 if (length
== 0xffffffff)
7470 SAFE_BYTE_GET_AND_INC (length
, start
, 8, end
);
7472 initial_length_size
= 12;
7477 initial_length_size
= 4;
7480 block_end
= saved_start
+ length
+ initial_length_size
;
7481 if (block_end
> end
|| block_end
< start
)
7483 warn ("Invalid length 0x%s in FDE at %#08lx\n",
7484 dwarf_vmatoa_1 (NULL
, length
, offset_size
),
7485 (unsigned long) (saved_start
- section_start
));
7489 SAFE_BYTE_GET_AND_INC (cie_id
, start
, offset_size
, end
);
7491 if (is_eh
? (cie_id
== 0) : ((offset_size
== 4 && cie_id
== DW_CIE_ID
)
7492 || (offset_size
== 8 && cie_id
== DW64_CIE_ID
)))
7497 start
= read_cie (start
, end
, &cie
, &version
,
7498 &augmentation_data_len
, &augmentation_data
);
7499 /* PR 17512: file: 027-135133-0.005. */
7506 fc
->chunk_start
= saved_start
;
7507 mreg
= max_regs
> 0 ? max_regs
- 1 : 0;
7510 if (frame_need_space (fc
, mreg
) < 0)
7512 if (fc
->fde_encoding
)
7513 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
7515 printf ("\n%08lx ", (unsigned long) (saved_start
- section_start
));
7516 print_dwarf_vma (length
, fc
->ptr_size
);
7517 print_dwarf_vma (cie_id
, offset_size
);
7519 if (do_debug_frames_interp
)
7521 printf ("CIE \"%s\" cf=%d df=%d ra=%d\n", fc
->augmentation
,
7522 fc
->code_factor
, fc
->data_factor
, fc
->ra
);
7527 printf (" Version: %d\n", version
);
7528 printf (" Augmentation: \"%s\"\n", fc
->augmentation
);
7531 printf (" Pointer Size: %u\n", fc
->ptr_size
);
7532 printf (" Segment Size: %u\n", fc
->segment_size
);
7534 printf (" Code alignment factor: %u\n", fc
->code_factor
);
7535 printf (" Data alignment factor: %d\n", fc
->data_factor
);
7536 printf (" Return address column: %d\n", fc
->ra
);
7538 if (augmentation_data_len
)
7539 display_augmentation_data (augmentation_data
, augmentation_data_len
);
7546 unsigned char *look_for
;
7547 static Frame_Chunk fde_fc
;
7548 unsigned long segment_selector
;
7552 dwarf_vma sign
= (dwarf_vma
) 1 << (offset_size
* 8 - 1);
7553 look_for
= start
- 4 - ((cie_id
^ sign
) - sign
);
7556 look_for
= section_start
+ cie_id
;
7558 if (look_for
<= saved_start
)
7560 for (cie
= chunks
; cie
; cie
= cie
->next
)
7561 if (cie
->chunk_start
== look_for
)
7566 for (cie
= forward_refs
; cie
; cie
= cie
->next
)
7567 if (cie
->chunk_start
== look_for
)
7571 unsigned int off_size
;
7572 unsigned char *cie_scan
;
7574 cie_scan
= look_for
;
7576 SAFE_BYTE_GET_AND_INC (length
, cie_scan
, 4, end
);
7577 if (length
== 0xffffffff)
7579 SAFE_BYTE_GET_AND_INC (length
, cie_scan
, 8, end
);
7586 SAFE_BYTE_GET_AND_INC (c_id
, cie_scan
, off_size
, end
);
7589 : ((off_size
== 4 && c_id
== DW_CIE_ID
)
7590 || (off_size
== 8 && c_id
== DW64_CIE_ID
)))
7595 read_cie (cie_scan
, end
, &cie
, &version
,
7596 &augmentation_data_len
, &augmentation_data
);
7597 /* PR 17512: file: 3450-2098-0.004. */
7600 warn (_("Failed to read CIE information\n"));
7603 cie
->next
= forward_refs
;
7605 cie
->chunk_start
= look_for
;
7606 mreg
= max_regs
> 0 ? max_regs
- 1 : 0;
7609 if (frame_need_space (cie
, mreg
) < 0)
7611 warn (_("Invalid max register\n"));
7614 if (cie
->fde_encoding
)
7616 = size_of_encoded_value (cie
->fde_encoding
);
7623 memset (fc
, 0, sizeof (Frame_Chunk
));
7627 warn ("Invalid CIE pointer 0x%s in FDE at %#08lx\n",
7628 dwarf_vmatoa_1 (NULL
, cie_id
, offset_size
),
7629 (unsigned long) (saved_start
- section_start
));
7631 fc
->col_type
= (short int *) xmalloc (sizeof (short int));
7632 fc
->col_offset
= (int *) xmalloc (sizeof (int));
7633 if (frame_need_space (fc
, max_regs
> 0 ? max_regs
- 1 : 0) < 0)
7635 warn (_("Invalid max register\n"));
7639 fc
->augmentation
= "";
7640 fc
->fde_encoding
= 0;
7641 fc
->ptr_size
= eh_addr_size
;
7642 fc
->segment_size
= 0;
7646 fc
->ncols
= cie
->ncols
;
7647 fc
->col_type
= (short int *) xcmalloc (fc
->ncols
, sizeof (short int));
7648 fc
->col_offset
= (int *) xcmalloc (fc
->ncols
, sizeof (int));
7649 memcpy (fc
->col_type
, cie
->col_type
, fc
->ncols
* sizeof (short int));
7650 memcpy (fc
->col_offset
, cie
->col_offset
, fc
->ncols
* sizeof (int));
7651 fc
->augmentation
= cie
->augmentation
;
7652 fc
->ptr_size
= cie
->ptr_size
;
7653 eh_addr_size
= cie
->ptr_size
;
7654 fc
->segment_size
= cie
->segment_size
;
7655 fc
->code_factor
= cie
->code_factor
;
7656 fc
->data_factor
= cie
->data_factor
;
7657 fc
->cfa_reg
= cie
->cfa_reg
;
7658 fc
->cfa_offset
= cie
->cfa_offset
;
7660 if (frame_need_space (fc
, max_regs
> 0 ? max_regs
- 1: 0) < 0)
7662 warn (_("Invalid max register\n"));
7665 fc
->fde_encoding
= cie
->fde_encoding
;
7668 if (fc
->fde_encoding
)
7669 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
7671 segment_selector
= 0;
7672 if (fc
->segment_size
)
7674 if (fc
->segment_size
> sizeof (segment_selector
))
7676 /* PR 17512: file: 9e196b3e. */
7677 warn (_("Probably corrupt segment size: %d - using 4 instead\n"), fc
->segment_size
);
7678 fc
->segment_size
= 4;
7680 SAFE_BYTE_GET_AND_INC (segment_selector
, start
, fc
->segment_size
, end
);
7683 fc
->pc_begin
= get_encoded_value (&start
, fc
->fde_encoding
, section
, end
);
7685 /* FIXME: It appears that sometimes the final pc_range value is
7686 encoded in less than encoded_ptr_size bytes. See the x86_64
7687 run of the "objcopy on compressed debug sections" test for an
7689 SAFE_BYTE_GET_AND_INC (fc
->pc_range
, start
, encoded_ptr_size
, end
);
7691 if (cie
->augmentation
[0] == 'z')
7693 READ_ULEB (augmentation_data_len
);
7694 augmentation_data
= start
;
7695 start
+= augmentation_data_len
;
7696 /* PR 17512 file: 722-8446-0.004 and PR 22386. */
7698 || ((bfd_signed_vma
) augmentation_data_len
) < 0
7699 || augmentation_data
> start
)
7701 warn (_("Corrupt augmentation data length: 0x%s\n"),
7702 dwarf_vmatoa ("x", augmentation_data_len
));
7704 augmentation_data
= NULL
;
7705 augmentation_data_len
= 0;
7709 printf ("\n%08lx %s %s FDE cie=%08lx pc=",
7710 (unsigned long)(saved_start
- section_start
),
7711 dwarf_vmatoa_1 (NULL
, length
, fc
->ptr_size
),
7712 dwarf_vmatoa_1 (NULL
, cie_id
, offset_size
),
7713 (unsigned long)(cie
->chunk_start
- section_start
));
7715 if (fc
->segment_size
)
7716 printf ("%04lx:", segment_selector
);
7719 dwarf_vmatoa_1 (NULL
, fc
->pc_begin
, fc
->ptr_size
),
7720 dwarf_vmatoa_1 (NULL
, fc
->pc_begin
+ fc
->pc_range
, fc
->ptr_size
));
7722 if (! do_debug_frames_interp
&& augmentation_data_len
)
7724 display_augmentation_data (augmentation_data
, augmentation_data_len
);
7729 /* At this point, fc is the current chunk, cie (if any) is set, and
7730 we're about to interpret instructions for the chunk. */
7731 /* ??? At present we need to do this always, since this sizes the
7732 fc->col_type and fc->col_offset arrays, which we write into always.
7733 We should probably split the interpreted and non-interpreted bits
7734 into two different routines, since there's so much that doesn't
7735 really overlap between them. */
7736 if (1 || do_debug_frames_interp
)
7738 /* Start by making a pass over the chunk, allocating storage
7739 and taking note of what registers are used. */
7740 unsigned char *tmp
= start
;
7742 while (start
< block_end
)
7744 unsigned int reg
, op
, opa
;
7746 unsigned char * new_start
;
7753 /* Warning: if you add any more cases to this switch, be
7754 sure to add them to the corresponding switch below. */
7757 case DW_CFA_advance_loc
:
7761 if (frame_need_space (fc
, opa
) >= 0)
7762 fc
->col_type
[opa
] = DW_CFA_undefined
;
7764 case DW_CFA_restore
:
7765 if (frame_need_space (fc
, opa
) >= 0)
7766 fc
->col_type
[opa
] = DW_CFA_undefined
;
7768 case DW_CFA_set_loc
:
7769 start
+= encoded_ptr_size
;
7771 case DW_CFA_advance_loc1
:
7774 case DW_CFA_advance_loc2
:
7777 case DW_CFA_advance_loc4
:
7780 case DW_CFA_offset_extended
:
7781 case DW_CFA_val_offset
:
7784 if (frame_need_space (fc
, reg
) >= 0)
7785 fc
->col_type
[reg
] = DW_CFA_undefined
;
7787 case DW_CFA_restore_extended
:
7789 if (frame_need_space (fc
, reg
) >= 0)
7790 fc
->col_type
[reg
] = DW_CFA_undefined
;
7792 case DW_CFA_undefined
:
7794 if (frame_need_space (fc
, reg
) >= 0)
7795 fc
->col_type
[reg
] = DW_CFA_undefined
;
7797 case DW_CFA_same_value
:
7799 if (frame_need_space (fc
, reg
) >= 0)
7800 fc
->col_type
[reg
] = DW_CFA_undefined
;
7802 case DW_CFA_register
:
7805 if (frame_need_space (fc
, reg
) >= 0)
7806 fc
->col_type
[reg
] = DW_CFA_undefined
;
7808 case DW_CFA_def_cfa
:
7812 case DW_CFA_def_cfa_register
:
7815 case DW_CFA_def_cfa_offset
:
7818 case DW_CFA_def_cfa_expression
:
7820 new_start
= start
+ temp
;
7821 if (new_start
< start
)
7823 warn (_("Corrupt CFA_def expression value: %lu\n"), temp
);
7829 case DW_CFA_expression
:
7830 case DW_CFA_val_expression
:
7833 new_start
= start
+ temp
;
7834 if (new_start
< start
)
7836 /* PR 17512: file:306-192417-0.005. */
7837 warn (_("Corrupt CFA expression value: %lu\n"), temp
);
7842 if (frame_need_space (fc
, reg
) >= 0)
7843 fc
->col_type
[reg
] = DW_CFA_undefined
;
7845 case DW_CFA_offset_extended_sf
:
7846 case DW_CFA_val_offset_sf
:
7849 if (frame_need_space (fc
, reg
) >= 0)
7850 fc
->col_type
[reg
] = DW_CFA_undefined
;
7852 case DW_CFA_def_cfa_sf
:
7856 case DW_CFA_def_cfa_offset_sf
:
7859 case DW_CFA_MIPS_advance_loc8
:
7862 case DW_CFA_GNU_args_size
:
7865 case DW_CFA_GNU_negative_offset_extended
:
7868 if (frame_need_space (fc
, reg
) >= 0)
7869 fc
->col_type
[reg
] = DW_CFA_undefined
;
7880 /* Now we know what registers are used, make a second pass over
7881 the chunk, this time actually printing out the info. */
7883 while (start
< block_end
)
7885 unsigned char * tmp
;
7887 unsigned long ul
, roffs
;
7888 /* Note: It is tempting to use an unsigned long for 'reg' but there
7889 are various functions, notably frame_space_needed() that assume that
7890 reg is an unsigned int. */
7895 const char *reg_prefix
= "";
7902 /* Make a note if something other than DW_CFA_nop happens. */
7903 if (op
!= DW_CFA_nop
)
7906 /* Warning: if you add any more cases to this switch, be
7907 sure to add them to the corresponding switch above. */
7910 case DW_CFA_advance_loc
:
7911 if (do_debug_frames_interp
)
7912 frame_display_row (fc
, &need_col_headers
, &max_regs
);
7914 printf (" DW_CFA_advance_loc: %d to %s\n",
7915 opa
* fc
->code_factor
,
7916 dwarf_vmatoa_1 (NULL
,
7917 fc
->pc_begin
+ opa
* fc
->code_factor
,
7919 fc
->pc_begin
+= opa
* fc
->code_factor
;
7924 if (opa
>= (unsigned int) fc
->ncols
)
7925 reg_prefix
= bad_reg
;
7926 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
7927 printf (" DW_CFA_offset: %s%s at cfa%+ld\n",
7928 reg_prefix
, regname (opa
, 0),
7929 roffs
* fc
->data_factor
);
7930 if (*reg_prefix
== '\0')
7932 fc
->col_type
[opa
] = DW_CFA_offset
;
7933 fc
->col_offset
[opa
] = roffs
* fc
->data_factor
;
7937 case DW_CFA_restore
:
7938 if (opa
>= (unsigned int) fc
->ncols
)
7939 reg_prefix
= bad_reg
;
7940 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
7941 printf (" DW_CFA_restore: %s%s\n",
7942 reg_prefix
, regname (opa
, 0));
7943 if (*reg_prefix
!= '\0')
7946 if (opa
>= (unsigned int) cie
->ncols
7947 || (do_debug_frames_interp
7948 && cie
->col_type
[opa
] == DW_CFA_unreferenced
))
7950 fc
->col_type
[opa
] = DW_CFA_undefined
;
7951 fc
->col_offset
[opa
] = 0;
7955 fc
->col_type
[opa
] = cie
->col_type
[opa
];
7956 fc
->col_offset
[opa
] = cie
->col_offset
[opa
];
7960 case DW_CFA_set_loc
:
7961 vma
= get_encoded_value (&start
, fc
->fde_encoding
, section
, block_end
);
7962 if (do_debug_frames_interp
)
7963 frame_display_row (fc
, &need_col_headers
, &max_regs
);
7965 printf (" DW_CFA_set_loc: %s\n",
7966 dwarf_vmatoa_1 (NULL
, vma
, fc
->ptr_size
));
7970 case DW_CFA_advance_loc1
:
7971 SAFE_BYTE_GET_AND_INC (ofs
, start
, 1, end
);
7972 if (do_debug_frames_interp
)
7973 frame_display_row (fc
, &need_col_headers
, &max_regs
);
7975 printf (" DW_CFA_advance_loc1: %ld to %s\n",
7976 (unsigned long) (ofs
* fc
->code_factor
),
7977 dwarf_vmatoa_1 (NULL
,
7978 fc
->pc_begin
+ ofs
* fc
->code_factor
,
7980 fc
->pc_begin
+= ofs
* fc
->code_factor
;
7983 case DW_CFA_advance_loc2
:
7984 SAFE_BYTE_GET_AND_INC (ofs
, start
, 2, block_end
);
7985 if (do_debug_frames_interp
)
7986 frame_display_row (fc
, &need_col_headers
, &max_regs
);
7988 printf (" DW_CFA_advance_loc2: %ld to %s\n",
7989 (unsigned long) (ofs
* fc
->code_factor
),
7990 dwarf_vmatoa_1 (NULL
,
7991 fc
->pc_begin
+ ofs
* fc
->code_factor
,
7993 fc
->pc_begin
+= ofs
* fc
->code_factor
;
7996 case DW_CFA_advance_loc4
:
7997 SAFE_BYTE_GET_AND_INC (ofs
, start
, 4, block_end
);
7998 if (do_debug_frames_interp
)
7999 frame_display_row (fc
, &need_col_headers
, &max_regs
);
8001 printf (" DW_CFA_advance_loc4: %ld to %s\n",
8002 (unsigned long) (ofs
* fc
->code_factor
),
8003 dwarf_vmatoa_1 (NULL
,
8004 fc
->pc_begin
+ ofs
* fc
->code_factor
,
8006 fc
->pc_begin
+= ofs
* fc
->code_factor
;
8009 case DW_CFA_offset_extended
:
8012 if (reg
>= (unsigned int) fc
->ncols
)
8013 reg_prefix
= bad_reg
;
8014 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
8015 printf (" DW_CFA_offset_extended: %s%s at cfa%+ld\n",
8016 reg_prefix
, regname (reg
, 0),
8017 roffs
* fc
->data_factor
);
8018 if (*reg_prefix
== '\0')
8020 fc
->col_type
[reg
] = DW_CFA_offset
;
8021 fc
->col_offset
[reg
] = roffs
* fc
->data_factor
;
8025 case DW_CFA_val_offset
:
8028 if (reg
>= (unsigned int) fc
->ncols
)
8029 reg_prefix
= bad_reg
;
8030 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
8031 printf (" DW_CFA_val_offset: %s%s is cfa%+ld\n",
8032 reg_prefix
, regname (reg
, 0),
8033 roffs
* fc
->data_factor
);
8034 if (*reg_prefix
== '\0')
8036 fc
->col_type
[reg
] = DW_CFA_val_offset
;
8037 fc
->col_offset
[reg
] = roffs
* fc
->data_factor
;
8041 case DW_CFA_restore_extended
:
8043 if (reg
>= (unsigned int) fc
->ncols
)
8044 reg_prefix
= bad_reg
;
8045 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
8046 printf (" DW_CFA_restore_extended: %s%s\n",
8047 reg_prefix
, regname (reg
, 0));
8048 if (*reg_prefix
!= '\0')
8051 if (reg
>= (unsigned int) cie
->ncols
)
8053 fc
->col_type
[reg
] = DW_CFA_undefined
;
8054 fc
->col_offset
[reg
] = 0;
8058 fc
->col_type
[reg
] = cie
->col_type
[reg
];
8059 fc
->col_offset
[reg
] = cie
->col_offset
[reg
];
8063 case DW_CFA_undefined
:
8065 if (reg
>= (unsigned int) fc
->ncols
)
8066 reg_prefix
= bad_reg
;
8067 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
8068 printf (" DW_CFA_undefined: %s%s\n",
8069 reg_prefix
, regname (reg
, 0));
8070 if (*reg_prefix
== '\0')
8072 fc
->col_type
[reg
] = DW_CFA_undefined
;
8073 fc
->col_offset
[reg
] = 0;
8077 case DW_CFA_same_value
:
8079 if (reg
>= (unsigned int) fc
->ncols
)
8080 reg_prefix
= bad_reg
;
8081 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
8082 printf (" DW_CFA_same_value: %s%s\n",
8083 reg_prefix
, regname (reg
, 0));
8084 if (*reg_prefix
== '\0')
8086 fc
->col_type
[reg
] = DW_CFA_same_value
;
8087 fc
->col_offset
[reg
] = 0;
8091 case DW_CFA_register
:
8094 if (reg
>= (unsigned int) fc
->ncols
)
8095 reg_prefix
= bad_reg
;
8096 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
8098 printf (" DW_CFA_register: %s%s in ",
8099 reg_prefix
, regname (reg
, 0));
8100 puts (regname (roffs
, 0));
8102 if (*reg_prefix
== '\0')
8104 fc
->col_type
[reg
] = DW_CFA_register
;
8105 fc
->col_offset
[reg
] = roffs
;
8109 case DW_CFA_remember_state
:
8110 if (! do_debug_frames_interp
)
8111 printf (" DW_CFA_remember_state\n");
8112 rs
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
8113 rs
->cfa_offset
= fc
->cfa_offset
;
8114 rs
->cfa_reg
= fc
->cfa_reg
;
8116 rs
->cfa_exp
= fc
->cfa_exp
;
8117 rs
->ncols
= fc
->ncols
;
8118 rs
->col_type
= (short int *) xcmalloc (rs
->ncols
,
8119 sizeof (* rs
->col_type
));
8120 rs
->col_offset
= (int *) xcmalloc (rs
->ncols
, sizeof (* rs
->col_offset
));
8121 memcpy (rs
->col_type
, fc
->col_type
, rs
->ncols
* sizeof (* fc
->col_type
));
8122 memcpy (rs
->col_offset
, fc
->col_offset
, rs
->ncols
* sizeof (* fc
->col_offset
));
8123 rs
->next
= remembered_state
;
8124 remembered_state
= rs
;
8127 case DW_CFA_restore_state
:
8128 if (! do_debug_frames_interp
)
8129 printf (" DW_CFA_restore_state\n");
8130 rs
= remembered_state
;
8133 remembered_state
= rs
->next
;
8134 fc
->cfa_offset
= rs
->cfa_offset
;
8135 fc
->cfa_reg
= rs
->cfa_reg
;
8137 fc
->cfa_exp
= rs
->cfa_exp
;
8138 if (frame_need_space (fc
, rs
->ncols
- 1) < 0)
8140 warn (_("Invalid column number in saved frame state\n"));
8144 memcpy (fc
->col_type
, rs
->col_type
, rs
->ncols
* sizeof (* rs
->col_type
));
8145 memcpy (fc
->col_offset
, rs
->col_offset
,
8146 rs
->ncols
* sizeof (* rs
->col_offset
));
8147 free (rs
->col_type
);
8148 free (rs
->col_offset
);
8151 else if (do_debug_frames_interp
)
8152 printf ("Mismatched DW_CFA_restore_state\n");
8155 case DW_CFA_def_cfa
:
8156 READ_ULEB (fc
->cfa_reg
);
8157 READ_ULEB (fc
->cfa_offset
);
8159 if (! do_debug_frames_interp
)
8160 printf (" DW_CFA_def_cfa: %s ofs %d\n",
8161 regname (fc
->cfa_reg
, 0), (int) fc
->cfa_offset
);
8164 case DW_CFA_def_cfa_register
:
8165 READ_ULEB (fc
->cfa_reg
);
8167 if (! do_debug_frames_interp
)
8168 printf (" DW_CFA_def_cfa_register: %s\n",
8169 regname (fc
->cfa_reg
, 0));
8172 case DW_CFA_def_cfa_offset
:
8173 READ_ULEB (fc
->cfa_offset
);
8174 if (! do_debug_frames_interp
)
8175 printf (" DW_CFA_def_cfa_offset: %d\n", (int) fc
->cfa_offset
);
8179 if (! do_debug_frames_interp
)
8180 printf (" DW_CFA_nop\n");
8183 case DW_CFA_def_cfa_expression
:
8185 if (start
>= block_end
|| ul
> (unsigned long) (block_end
- start
))
8187 printf (_(" DW_CFA_def_cfa_expression: <corrupt len %lu>\n"), ul
);
8190 if (! do_debug_frames_interp
)
8192 printf (" DW_CFA_def_cfa_expression (");
8193 decode_location_expression (start
, eh_addr_size
, 0, -1,
8201 case DW_CFA_expression
:
8204 if (reg
>= (unsigned int) fc
->ncols
)
8205 reg_prefix
= bad_reg
;
8206 /* PR 17512: file: 069-133014-0.006. */
8207 /* PR 17512: file: 98c02eb4. */
8209 if (start
>= block_end
|| tmp
> block_end
|| tmp
< start
)
8211 printf (_(" DW_CFA_expression: <corrupt len %lu>\n"), ul
);
8214 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
8216 printf (" DW_CFA_expression: %s%s (",
8217 reg_prefix
, regname (reg
, 0));
8218 decode_location_expression (start
, eh_addr_size
, 0, -1,
8222 if (*reg_prefix
== '\0')
8223 fc
->col_type
[reg
] = DW_CFA_expression
;
8227 case DW_CFA_val_expression
:
8230 if (reg
>= (unsigned int) fc
->ncols
)
8231 reg_prefix
= bad_reg
;
8233 if (start
>= block_end
|| tmp
> block_end
|| tmp
< start
)
8235 printf (" DW_CFA_val_expression: <corrupt len %lu>\n", ul
);
8238 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
8240 printf (" DW_CFA_val_expression: %s%s (",
8241 reg_prefix
, regname (reg
, 0));
8242 decode_location_expression (start
, eh_addr_size
, 0, -1,
8246 if (*reg_prefix
== '\0')
8247 fc
->col_type
[reg
] = DW_CFA_val_expression
;
8251 case DW_CFA_offset_extended_sf
:
8254 if (frame_need_space (fc
, reg
) < 0)
8255 reg_prefix
= bad_reg
;
8256 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
8257 printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+ld\n",
8258 reg_prefix
, regname (reg
, 0),
8259 (long)(l
* fc
->data_factor
));
8260 if (*reg_prefix
== '\0')
8262 fc
->col_type
[reg
] = DW_CFA_offset
;
8263 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
8267 case DW_CFA_val_offset_sf
:
8270 if (frame_need_space (fc
, reg
) < 0)
8271 reg_prefix
= bad_reg
;
8272 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
8273 printf (" DW_CFA_val_offset_sf: %s%s is cfa%+ld\n",
8274 reg_prefix
, regname (reg
, 0),
8275 (long)(l
* fc
->data_factor
));
8276 if (*reg_prefix
== '\0')
8278 fc
->col_type
[reg
] = DW_CFA_val_offset
;
8279 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
8283 case DW_CFA_def_cfa_sf
:
8284 READ_ULEB (fc
->cfa_reg
);
8285 READ_ULEB (fc
->cfa_offset
);
8286 fc
->cfa_offset
= fc
->cfa_offset
* fc
->data_factor
;
8288 if (! do_debug_frames_interp
)
8289 printf (" DW_CFA_def_cfa_sf: %s ofs %d\n",
8290 regname (fc
->cfa_reg
, 0), (int) fc
->cfa_offset
);
8293 case DW_CFA_def_cfa_offset_sf
:
8294 READ_ULEB (fc
->cfa_offset
);
8295 fc
->cfa_offset
*= fc
->data_factor
;
8296 if (! do_debug_frames_interp
)
8297 printf (" DW_CFA_def_cfa_offset_sf: %d\n", (int) fc
->cfa_offset
);
8300 case DW_CFA_MIPS_advance_loc8
:
8301 SAFE_BYTE_GET_AND_INC (ofs
, start
, 8, block_end
);
8302 if (do_debug_frames_interp
)
8303 frame_display_row (fc
, &need_col_headers
, &max_regs
);
8305 printf (" DW_CFA_MIPS_advance_loc8: %ld to %s\n",
8306 (unsigned long) (ofs
* fc
->code_factor
),
8307 dwarf_vmatoa_1 (NULL
,
8308 fc
->pc_begin
+ ofs
* fc
->code_factor
,
8310 fc
->pc_begin
+= ofs
* fc
->code_factor
;
8313 case DW_CFA_GNU_window_save
:
8314 if (! do_debug_frames_interp
)
8315 printf (" DW_CFA_GNU_window_save\n");
8318 case DW_CFA_GNU_args_size
:
8320 if (! do_debug_frames_interp
)
8321 printf (" DW_CFA_GNU_args_size: %ld\n", ul
);
8324 case DW_CFA_GNU_negative_offset_extended
:
8328 if (frame_need_space (fc
, reg
) < 0)
8329 reg_prefix
= bad_reg
;
8330 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
8331 printf (" DW_CFA_GNU_negative_offset_extended: %s%s at cfa%+ld\n",
8332 reg_prefix
, regname (reg
, 0),
8333 (long)(l
* fc
->data_factor
));
8334 if (*reg_prefix
== '\0')
8336 fc
->col_type
[reg
] = DW_CFA_offset
;
8337 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
8342 if (op
>= DW_CFA_lo_user
&& op
<= DW_CFA_hi_user
)
8343 printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op
);
8345 warn (_("Unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op
);
8350 /* Interpret the CFA - as long as it is not completely full of NOPs. */
8351 if (do_debug_frames_interp
&& ! all_nops
)
8352 frame_display_row (fc
, &need_col_headers
, &max_regs
);
8355 eh_addr_size
= saved_eh_addr_size
;
8366 display_debug_names (struct dwarf_section
*section
, void *file
)
8368 unsigned char *hdrptr
= section
->start
;
8369 dwarf_vma unit_length
;
8370 unsigned char *unit_start
;
8371 const unsigned char *const section_end
= section
->start
+ section
->size
;
8372 unsigned char *unit_end
;
8374 introduce (section
, FALSE
);
8376 load_debug_section_with_follow (str
, file
);
8378 for (; hdrptr
< section_end
; hdrptr
= unit_end
)
8380 unsigned int offset_size
;
8381 uint16_t dwarf_version
, padding
;
8382 uint32_t comp_unit_count
, local_type_unit_count
, foreign_type_unit_count
;
8383 uint32_t bucket_count
, name_count
, abbrev_table_size
;
8384 uint32_t augmentation_string_size
;
8386 unsigned long sec_off
;
8388 unit_start
= hdrptr
;
8390 /* Get and check the length of the block. */
8391 SAFE_BYTE_GET_AND_INC (unit_length
, hdrptr
, 4, section_end
);
8393 if (unit_length
== 0xffffffff)
8395 /* This section is 64-bit DWARF. */
8396 SAFE_BYTE_GET_AND_INC (unit_length
, hdrptr
, 8, section_end
);
8401 unit_end
= hdrptr
+ unit_length
;
8403 sec_off
= hdrptr
- section
->start
;
8404 if (sec_off
+ unit_length
< sec_off
8405 || sec_off
+ unit_length
> section
->size
)
8407 warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"),
8409 (unsigned long) (unit_start
- section
->start
),
8410 dwarf_vmatoa ("x", unit_length
));
8414 /* Get and check the version number. */
8415 SAFE_BYTE_GET_AND_INC (dwarf_version
, hdrptr
, 2, unit_end
);
8416 printf (_("Version %ld\n"), (long) dwarf_version
);
8418 /* Prior versions did not exist, and future versions may not be
8419 backwards compatible. */
8420 if (dwarf_version
!= 5)
8422 warn (_("Only DWARF version 5 .debug_names "
8423 "is currently supported.\n"));
8427 SAFE_BYTE_GET_AND_INC (padding
, hdrptr
, 2, unit_end
);
8429 warn (_("Padding field of .debug_names must be 0 (found 0x%x)\n"),
8432 SAFE_BYTE_GET_AND_INC (comp_unit_count
, hdrptr
, 4, unit_end
);
8433 if (comp_unit_count
== 0)
8434 warn (_("Compilation unit count must be >= 1 in .debug_names\n"));
8436 SAFE_BYTE_GET_AND_INC (local_type_unit_count
, hdrptr
, 4, unit_end
);
8437 SAFE_BYTE_GET_AND_INC (foreign_type_unit_count
, hdrptr
, 4, unit_end
);
8438 SAFE_BYTE_GET_AND_INC (bucket_count
, hdrptr
, 4, unit_end
);
8439 SAFE_BYTE_GET_AND_INC (name_count
, hdrptr
, 4, unit_end
);
8440 SAFE_BYTE_GET_AND_INC (abbrev_table_size
, hdrptr
, 4, unit_end
);
8442 SAFE_BYTE_GET_AND_INC (augmentation_string_size
, hdrptr
, 4, unit_end
);
8443 if (augmentation_string_size
% 4 != 0)
8445 warn (_("Augmentation string length %u must be rounded up "
8446 "to a multiple of 4 in .debug_names.\n"),
8447 augmentation_string_size
);
8448 augmentation_string_size
+= (-augmentation_string_size
) & 3;
8450 printf (_("Augmentation string:"));
8451 for (i
= 0; i
< augmentation_string_size
; i
++)
8455 SAFE_BYTE_GET_AND_INC (uc
, hdrptr
, 1, unit_end
);
8456 printf (" %02x", uc
);
8461 printf (_("CU table:\n"));
8462 for (i
= 0; i
< comp_unit_count
; i
++)
8466 SAFE_BYTE_GET_AND_INC (cu_offset
, hdrptr
, offset_size
, unit_end
);
8467 printf (_("[%3u] 0x%lx\n"), i
, (unsigned long) cu_offset
);
8471 printf (_("TU table:\n"));
8472 for (i
= 0; i
< local_type_unit_count
; i
++)
8476 SAFE_BYTE_GET_AND_INC (tu_offset
, hdrptr
, offset_size
, unit_end
);
8477 printf (_("[%3u] 0x%lx\n"), i
, (unsigned long) tu_offset
);
8481 printf (_("Foreign TU table:\n"));
8482 for (i
= 0; i
< foreign_type_unit_count
; i
++)
8486 SAFE_BYTE_GET_AND_INC (signature
, hdrptr
, 8, unit_end
);
8487 printf (_("[%3u] "), i
);
8488 print_dwarf_vma (signature
, 8);
8493 const uint32_t *const hash_table_buckets
= (uint32_t *) hdrptr
;
8494 hdrptr
+= bucket_count
* sizeof (uint32_t);
8495 const uint32_t *const hash_table_hashes
= (uint32_t *) hdrptr
;
8496 hdrptr
+= name_count
* sizeof (uint32_t);
8497 unsigned char *const name_table_string_offsets
= hdrptr
;
8498 hdrptr
+= name_count
* offset_size
;
8499 unsigned char *const name_table_entry_offsets
= hdrptr
;
8500 hdrptr
+= name_count
* offset_size
;
8501 unsigned char *const abbrev_table
= hdrptr
;
8502 hdrptr
+= abbrev_table_size
;
8503 const unsigned char *const abbrev_table_end
= hdrptr
;
8504 unsigned char *const entry_pool
= hdrptr
;
8505 if (hdrptr
> unit_end
)
8507 warn (_("Entry pool offset (0x%lx) exceeds unit size 0x%lx "
8508 "for unit 0x%lx in the debug_names\n"),
8509 (long) (hdrptr
- section
->start
),
8510 (long) (unit_end
- section
->start
),
8511 (long) (unit_start
- section
->start
));
8515 size_t buckets_filled
= 0;
8517 for (bucketi
= 0; bucketi
< bucket_count
; bucketi
++)
8519 const uint32_t bucket
= hash_table_buckets
[bucketi
];
8524 printf (ngettext ("Used %zu of %lu bucket.\n",
8525 "Used %zu of %lu buckets.\n",
8527 buckets_filled
, (unsigned long) bucket_count
);
8529 uint32_t hash_prev
= 0;
8530 size_t hash_clash_count
= 0;
8531 size_t longest_clash
= 0;
8532 size_t this_length
= 0;
8534 for (hashi
= 0; hashi
< name_count
; hashi
++)
8536 const uint32_t hash_this
= hash_table_hashes
[hashi
];
8540 if (hash_prev
% bucket_count
== hash_this
% bucket_count
)
8544 longest_clash
= MAX (longest_clash
, this_length
);
8549 hash_prev
= hash_this
;
8551 printf (_("Out of %lu items there are %zu bucket clashes"
8552 " (longest of %zu entries).\n"),
8553 (unsigned long) name_count
, hash_clash_count
, longest_clash
);
8554 assert (name_count
== buckets_filled
+ hash_clash_count
);
8556 struct abbrev_lookup_entry
8558 dwarf_vma abbrev_tag
;
8559 unsigned char *abbrev_lookup_ptr
;
8561 struct abbrev_lookup_entry
*abbrev_lookup
= NULL
;
8562 size_t abbrev_lookup_used
= 0;
8563 size_t abbrev_lookup_allocated
= 0;
8565 unsigned char *abbrevptr
= abbrev_table
;
8568 unsigned int bytes_read
;
8569 const dwarf_vma abbrev_tag
= read_uleb128 (abbrevptr
, &bytes_read
,
8571 abbrevptr
+= bytes_read
;
8572 if (abbrev_tag
== 0)
8574 if (abbrev_lookup_used
== abbrev_lookup_allocated
)
8576 abbrev_lookup_allocated
= MAX (0x100,
8577 abbrev_lookup_allocated
* 2);
8578 abbrev_lookup
= xrealloc (abbrev_lookup
,
8579 (abbrev_lookup_allocated
8580 * sizeof (*abbrev_lookup
)));
8582 assert (abbrev_lookup_used
< abbrev_lookup_allocated
);
8583 struct abbrev_lookup_entry
*entry
;
8584 for (entry
= abbrev_lookup
;
8585 entry
< abbrev_lookup
+ abbrev_lookup_used
;
8587 if (entry
->abbrev_tag
== abbrev_tag
)
8589 warn (_("Duplicate abbreviation tag %lu "
8590 "in unit 0x%lx in the debug_names\n"),
8591 (long) abbrev_tag
, (long) (unit_start
- section
->start
));
8594 entry
= &abbrev_lookup
[abbrev_lookup_used
++];
8595 entry
->abbrev_tag
= abbrev_tag
;
8596 entry
->abbrev_lookup_ptr
= abbrevptr
;
8598 /* Skip DWARF tag. */
8599 read_uleb128 (abbrevptr
, &bytes_read
, abbrev_table_end
);
8600 abbrevptr
+= bytes_read
;
8603 const dwarf_vma xindex
= read_uleb128 (abbrevptr
,
8606 abbrevptr
+= bytes_read
;
8607 const dwarf_vma form
= read_uleb128 (abbrevptr
, &bytes_read
,
8609 abbrevptr
+= bytes_read
;
8610 if (xindex
== 0 && form
== 0)
8615 printf (_("\nSymbol table:\n"));
8617 for (namei
= 0; namei
< name_count
; ++namei
)
8619 uint64_t string_offset
, entry_offset
;
8621 SAFE_BYTE_GET (string_offset
,
8622 name_table_string_offsets
+ namei
* offset_size
,
8623 offset_size
, unit_end
);
8624 SAFE_BYTE_GET (entry_offset
,
8625 name_table_entry_offsets
+ namei
* offset_size
,
8626 offset_size
, unit_end
);
8628 printf ("[%3u] #%08x %s:", namei
, hash_table_hashes
[namei
],
8629 fetch_indirect_string (string_offset
));
8631 unsigned char *entryptr
= entry_pool
+ entry_offset
;
8633 // We need to scan first whether there is a single or multiple
8634 // entries. TAGNO is -2 for the first entry, it is -1 for the
8635 // initial tag read of the second entry, then it becomes 0 for the
8636 // first entry for real printing etc.
8638 /* Initialize it due to a false compiler warning. */
8639 dwarf_vma second_abbrev_tag
= -1;
8642 unsigned int bytes_read
;
8643 const dwarf_vma abbrev_tag
= read_uleb128 (entryptr
, &bytes_read
,
8645 entryptr
+= bytes_read
;
8648 second_abbrev_tag
= abbrev_tag
;
8650 entryptr
= entry_pool
+ entry_offset
;
8653 if (abbrev_tag
== 0)
8657 (tagno
== 0 && second_abbrev_tag
== 0 ? " " : "\n\t"),
8658 (unsigned long) abbrev_tag
);
8660 const struct abbrev_lookup_entry
*entry
;
8661 for (entry
= abbrev_lookup
;
8662 entry
< abbrev_lookup
+ abbrev_lookup_used
;
8664 if (entry
->abbrev_tag
== abbrev_tag
)
8666 if (entry
>= abbrev_lookup
+ abbrev_lookup_used
)
8668 warn (_("Undefined abbreviation tag %lu "
8669 "in unit 0x%lx in the debug_names\n"),
8671 (long) (unit_start
- section
->start
));
8674 abbrevptr
= entry
->abbrev_lookup_ptr
;
8675 const dwarf_vma dwarf_tag
= read_uleb128 (abbrevptr
, &bytes_read
,
8677 abbrevptr
+= bytes_read
;
8679 printf (" %s", get_TAG_name (dwarf_tag
));
8682 const dwarf_vma xindex
= read_uleb128 (abbrevptr
,
8685 abbrevptr
+= bytes_read
;
8686 const dwarf_vma form
= read_uleb128 (abbrevptr
, &bytes_read
,
8688 abbrevptr
+= bytes_read
;
8689 if (xindex
== 0 && form
== 0)
8693 printf (" %s", get_IDX_name (xindex
));
8694 entryptr
= read_and_display_attr_value (0, form
, 0, entryptr
,
8697 dwarf_version
, NULL
,
8704 printf (_(" <no entries>"));
8708 free (abbrev_lookup
);
8715 display_debug_links (struct dwarf_section
* section
,
8716 void * file ATTRIBUTE_UNUSED
)
8718 const unsigned char * filename
;
8719 unsigned int filelen
;
8721 introduce (section
, FALSE
);
8723 /* The .gnu_debuglink section is formatted as:
8724 (c-string) Filename.
8725 (padding) If needed to reach a 4 byte boundary.
8726 (uint32_t) CRC32 value.
8728 The .gun_debugaltlink section is formatted as:
8729 (c-string) Filename.
8730 (binary) Build-ID. */
8732 filename
= section
->start
;
8733 filelen
= strnlen ((const char *) filename
, section
->size
);
8734 if (filelen
== section
->size
)
8736 warn (_("The debuglink filename is corrupt/missing\n"));
8740 printf (_(" Separate debug info file: %s\n"), filename
);
8742 if (const_strneq (section
->name
, ".gnu_debuglink"))
8745 unsigned int crc_offset
;
8747 crc_offset
= filelen
+ 1;
8748 crc_offset
= (crc_offset
+ 3) & ~3;
8749 if (crc_offset
+ 4 > section
->size
)
8751 warn (_("CRC offset missing/truncated\n"));
8755 crc32
= byte_get (filename
+ crc_offset
, 4);
8757 printf (_(" CRC value: %#x\n"), crc32
);
8759 if (crc_offset
+ 4 < section
->size
)
8761 warn (_("There are %#lx extraneous bytes at the end of the section\n"),
8762 (long)(section
->size
- (crc_offset
+ 4)));
8766 else /* const_strneq (section->name, ".gnu_debugaltlink") */
8768 const unsigned char * build_id
= section
->start
+ filelen
+ 1;
8769 bfd_size_type build_id_len
= section
->size
- (filelen
+ 1);
8770 bfd_size_type printed
;
8772 /* FIXME: Should we support smaller build-id notes ? */
8773 if (build_id_len
< 0x14)
8775 warn (_("Build-ID is too short (%#lx bytes)\n"), (long) build_id_len
);
8779 printed
= printf (_(" Build-ID (%#lx bytes):"), (long) build_id_len
);
8780 display_data (printed
, build_id
, build_id_len
);
8789 display_gdb_index (struct dwarf_section
*section
,
8790 void *file ATTRIBUTE_UNUSED
)
8792 unsigned char *start
= section
->start
;
8794 uint32_t cu_list_offset
, tu_list_offset
;
8795 uint32_t address_table_offset
, symbol_table_offset
, constant_pool_offset
;
8796 unsigned int cu_list_elements
, tu_list_elements
;
8797 unsigned int address_table_size
, symbol_table_slots
;
8798 unsigned char *cu_list
, *tu_list
;
8799 unsigned char *address_table
, *symbol_table
, *constant_pool
;
8802 /* The documentation for the format of this file is in gdb/dwarf2read.c. */
8804 introduce (section
, FALSE
);
8806 if (section
->size
< 6 * sizeof (uint32_t))
8808 warn (_("Truncated header in the %s section.\n"), section
->name
);
8812 version
= byte_get_little_endian (start
, 4);
8813 printf (_("Version %ld\n"), (long) version
);
8815 /* Prior versions are obsolete, and future versions may not be
8816 backwards compatible. */
8817 if (version
< 3 || version
> 8)
8819 warn (_("Unsupported version %lu.\n"), (unsigned long) version
);
8823 warn (_("The address table data in version 3 may be wrong.\n"));
8825 warn (_("Version 4 does not support case insensitive lookups.\n"));
8827 warn (_("Version 5 does not include inlined functions.\n"));
8829 warn (_("Version 6 does not include symbol attributes.\n"));
8830 /* Version 7 indices generated by Gold have bad type unit references,
8831 PR binutils/15021. But we don't know if the index was generated by
8832 Gold or not, so to avoid worrying users with gdb-generated indices
8833 we say nothing for version 7 here. */
8835 cu_list_offset
= byte_get_little_endian (start
+ 4, 4);
8836 tu_list_offset
= byte_get_little_endian (start
+ 8, 4);
8837 address_table_offset
= byte_get_little_endian (start
+ 12, 4);
8838 symbol_table_offset
= byte_get_little_endian (start
+ 16, 4);
8839 constant_pool_offset
= byte_get_little_endian (start
+ 20, 4);
8841 if (cu_list_offset
> section
->size
8842 || tu_list_offset
> section
->size
8843 || address_table_offset
> section
->size
8844 || symbol_table_offset
> section
->size
8845 || constant_pool_offset
> section
->size
)
8847 warn (_("Corrupt header in the %s section.\n"), section
->name
);
8851 /* PR 17531: file: 418d0a8a. */
8852 if (tu_list_offset
< cu_list_offset
)
8854 warn (_("TU offset (%x) is less than CU offset (%x)\n"),
8855 tu_list_offset
, cu_list_offset
);
8859 cu_list_elements
= (tu_list_offset
- cu_list_offset
) / 8;
8861 if (address_table_offset
< tu_list_offset
)
8863 warn (_("Address table offset (%x) is less than TU offset (%x)\n"),
8864 address_table_offset
, tu_list_offset
);
8868 tu_list_elements
= (address_table_offset
- tu_list_offset
) / 8;
8870 /* PR 17531: file: 18a47d3d. */
8871 if (symbol_table_offset
< address_table_offset
)
8873 warn (_("Symbol table offset (%x) is less then Address table offset (%x)\n"),
8874 symbol_table_offset
, address_table_offset
);
8878 address_table_size
= symbol_table_offset
- address_table_offset
;
8880 if (constant_pool_offset
< symbol_table_offset
)
8882 warn (_("Constant pool offset (%x) is less than symbol table offset (%x)\n"),
8883 constant_pool_offset
, symbol_table_offset
);
8887 symbol_table_slots
= (constant_pool_offset
- symbol_table_offset
) / 8;
8889 cu_list
= start
+ cu_list_offset
;
8890 tu_list
= start
+ tu_list_offset
;
8891 address_table
= start
+ address_table_offset
;
8892 symbol_table
= start
+ symbol_table_offset
;
8893 constant_pool
= start
+ constant_pool_offset
;
8895 if (address_table
+ address_table_size
> section
->start
+ section
->size
)
8897 warn (_("Address table extends beyond end of section.\n"));
8901 printf (_("\nCU table:\n"));
8902 for (i
= 0; i
< cu_list_elements
; i
+= 2)
8904 uint64_t cu_offset
= byte_get_little_endian (cu_list
+ i
* 8, 8);
8905 uint64_t cu_length
= byte_get_little_endian (cu_list
+ i
* 8 + 8, 8);
8907 printf (_("[%3u] 0x%lx - 0x%lx\n"), i
/ 2,
8908 (unsigned long) cu_offset
,
8909 (unsigned long) (cu_offset
+ cu_length
- 1));
8912 printf (_("\nTU table:\n"));
8913 for (i
= 0; i
< tu_list_elements
; i
+= 3)
8915 uint64_t tu_offset
= byte_get_little_endian (tu_list
+ i
* 8, 8);
8916 uint64_t type_offset
= byte_get_little_endian (tu_list
+ i
* 8 + 8, 8);
8917 uint64_t signature
= byte_get_little_endian (tu_list
+ i
* 8 + 16, 8);
8919 printf (_("[%3u] 0x%lx 0x%lx "), i
/ 3,
8920 (unsigned long) tu_offset
,
8921 (unsigned long) type_offset
);
8922 print_dwarf_vma (signature
, 8);
8926 printf (_("\nAddress table:\n"));
8927 for (i
= 0; i
< address_table_size
&& i
<= address_table_size
- (2 * 8 + 4);
8930 uint64_t low
= byte_get_little_endian (address_table
+ i
, 8);
8931 uint64_t high
= byte_get_little_endian (address_table
+ i
+ 8, 8);
8932 uint32_t cu_index
= byte_get_little_endian (address_table
+ i
+ 16, 4);
8934 print_dwarf_vma (low
, 8);
8935 print_dwarf_vma (high
, 8);
8936 printf (_("%lu\n"), (unsigned long) cu_index
);
8939 printf (_("\nSymbol table:\n"));
8940 for (i
= 0; i
< symbol_table_slots
; ++i
)
8942 uint32_t name_offset
= byte_get_little_endian (symbol_table
+ i
* 8, 4);
8943 uint32_t cu_vector_offset
= byte_get_little_endian (symbol_table
+ i
* 8 + 4, 4);
8944 uint32_t num_cus
, cu
;
8946 if (name_offset
!= 0
8947 || cu_vector_offset
!= 0)
8950 unsigned char * adr
;
8952 adr
= constant_pool
+ name_offset
;
8953 /* PR 17531: file: 5b7b07ad. */
8954 if (adr
< constant_pool
|| adr
>= section
->start
+ section
->size
)
8956 printf (_("[%3u] <corrupt offset: %x>"), i
, name_offset
);
8957 warn (_("Corrupt name offset of 0x%x found for symbol table slot %d\n"),
8961 printf ("[%3u] %.*s:", i
,
8962 (int) (section
->size
- (constant_pool_offset
+ name_offset
)),
8963 constant_pool
+ name_offset
);
8965 adr
= constant_pool
+ cu_vector_offset
;
8966 if (adr
< constant_pool
|| adr
>= section
->start
+ section
->size
- 3)
8968 printf (_("<invalid CU vector offset: %x>\n"), cu_vector_offset
);
8969 warn (_("Corrupt CU vector offset of 0x%x found for symbol table slot %d\n"),
8970 cu_vector_offset
, i
);
8974 num_cus
= byte_get_little_endian (adr
, 4);
8976 adr
= constant_pool
+ cu_vector_offset
+ 4 + num_cus
* 4;
8977 if (num_cus
* 4 < num_cus
8978 || adr
>= section
->start
+ section
->size
8979 || adr
< constant_pool
)
8981 printf ("<invalid number of CUs: %d>\n", num_cus
);
8982 warn (_("Invalid number of CUs (0x%x) for symbol table slot %d\n"),
8990 for (j
= 0; j
< num_cus
; ++j
)
8993 gdb_index_symbol_kind kind
;
8995 cu
= byte_get_little_endian (constant_pool
+ cu_vector_offset
+ 4 + j
* 4, 4);
8996 is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu
);
8997 kind
= GDB_INDEX_SYMBOL_KIND_VALUE (cu
);
8998 cu
= GDB_INDEX_CU_VALUE (cu
);
8999 /* Convert to TU number if it's for a type unit. */
9000 if (cu
>= cu_list_elements
/ 2)
9001 printf ("%cT%lu", num_cus
> 1 ? '\t' : ' ',
9002 (unsigned long) (cu
- cu_list_elements
/ 2));
9004 printf ("%c%lu", num_cus
> 1 ? '\t' : ' ', (unsigned long) cu
);
9006 printf (" [%s, %s]",
9007 is_static
? _("static") : _("global"),
9008 get_gdb_index_symbol_kind_name (kind
));
9020 /* Pre-allocate enough space for the CU/TU sets needed. */
9023 prealloc_cu_tu_list (unsigned int nshndx
)
9025 if (shndx_pool
== NULL
)
9027 shndx_pool_size
= nshndx
;
9028 shndx_pool_used
= 0;
9029 shndx_pool
= (unsigned int *) xcmalloc (shndx_pool_size
,
9030 sizeof (unsigned int));
9034 shndx_pool_size
= shndx_pool_used
+ nshndx
;
9035 shndx_pool
= (unsigned int *) xcrealloc (shndx_pool
, shndx_pool_size
,
9036 sizeof (unsigned int));
9041 add_shndx_to_cu_tu_entry (unsigned int shndx
)
9043 if (shndx_pool_used
>= shndx_pool_size
)
9045 error (_("Internal error: out of space in the shndx pool.\n"));
9048 shndx_pool
[shndx_pool_used
++] = shndx
;
9052 end_cu_tu_entry (void)
9054 if (shndx_pool_used
>= shndx_pool_size
)
9056 error (_("Internal error: out of space in the shndx pool.\n"));
9059 shndx_pool
[shndx_pool_used
++] = 0;
9062 /* Return the short name of a DWARF section given by a DW_SECT enumerator. */
9065 get_DW_SECT_short_name (unsigned int dw_sect
)
9067 static char buf
[16];
9075 case DW_SECT_ABBREV
:
9081 case DW_SECT_STR_OFFSETS
:
9083 case DW_SECT_MACINFO
:
9091 snprintf (buf
, sizeof (buf
), "%d", dw_sect
);
9095 /* Process a CU or TU index. If DO_DISPLAY is true, print the contents.
9096 These sections are extensions for Fission.
9097 See http://gcc.gnu.org/wiki/DebugFissionDWP. */
9100 process_cu_tu_index (struct dwarf_section
*section
, int do_display
)
9102 unsigned char *phdr
= section
->start
;
9103 unsigned char *limit
= phdr
+ section
->size
;
9104 unsigned char *phash
;
9105 unsigned char *pindex
;
9106 unsigned char *ppool
;
9107 unsigned int version
;
9108 unsigned int ncols
= 0;
9110 unsigned int nslots
;
9113 dwarf_vma signature_high
;
9114 dwarf_vma signature_low
;
9117 /* PR 17512: file: 002-168123-0.004. */
9120 warn (_("Section %s is empty\n"), section
->name
);
9123 /* PR 17512: file: 002-376-0.004. */
9124 if (section
->size
< 24)
9126 warn (_("Section %s is too small to contain a CU/TU header\n"),
9131 SAFE_BYTE_GET (version
, phdr
, 4, limit
);
9133 SAFE_BYTE_GET (ncols
, phdr
+ 4, 4, limit
);
9134 SAFE_BYTE_GET (nused
, phdr
+ 8, 4, limit
);
9135 SAFE_BYTE_GET (nslots
, phdr
+ 12, 4, limit
);
9138 pindex
= phash
+ nslots
* 8;
9139 ppool
= pindex
+ nslots
* 4;
9141 /* PR 17531: file: 45d69832. */
9142 if (pindex
< phash
|| ppool
< phdr
|| (pindex
== phash
&& nslots
!= 0))
9144 warn (ngettext ("Section %s is too small for %d slot\n",
9145 "Section %s is too small for %d slots\n",
9147 section
->name
, nslots
);
9153 introduce (section
, FALSE
);
9155 printf (_(" Version: %d\n"), version
);
9157 printf (_(" Number of columns: %d\n"), ncols
);
9158 printf (_(" Number of used entries: %d\n"), nused
);
9159 printf (_(" Number of slots: %d\n\n"), nslots
);
9162 if (ppool
> limit
|| ppool
< phdr
)
9164 warn (_("Section %s too small for %d hash table entries\n"),
9165 section
->name
, nslots
);
9172 prealloc_cu_tu_list ((limit
- ppool
) / 4);
9173 for (i
= 0; i
< nslots
; i
++)
9175 unsigned char *shndx_list
;
9178 SAFE_BYTE_GET64 (phash
, &signature_high
, &signature_low
, limit
);
9179 if (signature_high
!= 0 || signature_low
!= 0)
9181 SAFE_BYTE_GET (j
, pindex
, 4, limit
);
9182 shndx_list
= ppool
+ j
* 4;
9183 /* PR 17531: file: 705e010d. */
9184 if (shndx_list
< ppool
)
9186 warn (_("Section index pool located before start of section\n"));
9191 printf (_(" [%3d] Signature: 0x%s Sections: "),
9192 i
, dwarf_vmatoa64 (signature_high
, signature_low
,
9193 buf
, sizeof (buf
)));
9196 if (shndx_list
>= limit
)
9198 warn (_("Section %s too small for shndx pool\n"),
9202 SAFE_BYTE_GET (shndx
, shndx_list
, 4, limit
);
9206 printf (" %d", shndx
);
9208 add_shndx_to_cu_tu_entry (shndx
);
9220 else if (version
== 2)
9223 unsigned int dw_sect
;
9224 unsigned char *ph
= phash
;
9225 unsigned char *pi
= pindex
;
9226 unsigned char *poffsets
= ppool
+ ncols
* 4;
9227 unsigned char *psizes
= poffsets
+ nused
* ncols
* 4;
9228 unsigned char *pend
= psizes
+ nused
* ncols
* 4;
9229 bfd_boolean is_tu_index
;
9230 struct cu_tu_set
*this_set
= NULL
;
9232 unsigned char *prow
;
9234 is_tu_index
= strcmp (section
->name
, ".debug_tu_index") == 0;
9236 /* PR 17531: file: 0dd159bf.
9237 Check for wraparound with an overlarge ncols value. */
9238 if (poffsets
< ppool
|| (unsigned int) ((poffsets
- ppool
) / 4) != ncols
)
9240 warn (_("Overlarge number of columns: %x\n"), ncols
);
9246 warn (_("Section %s too small for offset and size tables\n"),
9253 printf (_(" Offset table\n"));
9254 printf (" slot %-16s ",
9255 is_tu_index
? _("signature") : _("dwo_id"));
9262 tu_sets
= xcalloc2 (nused
, sizeof (struct cu_tu_set
));
9268 cu_sets
= xcalloc2 (nused
, sizeof (struct cu_tu_set
));
9275 for (j
= 0; j
< ncols
; j
++)
9277 SAFE_BYTE_GET (dw_sect
, ppool
+ j
* 4, 4, limit
);
9278 printf (" %8s", get_DW_SECT_short_name (dw_sect
));
9283 for (i
= 0; i
< nslots
; i
++)
9285 SAFE_BYTE_GET64 (ph
, &signature_high
, &signature_low
, limit
);
9287 SAFE_BYTE_GET (row
, pi
, 4, limit
);
9290 /* PR 17531: file: a05f6ab3. */
9293 warn (_("Row index (%u) is larger than number of used entries (%u)\n"),
9300 size_t num_copy
= sizeof (uint64_t);
9302 /* PR 23064: Beware of buffer overflow. */
9303 if (ph
+ num_copy
< limit
)
9304 memcpy (&this_set
[row
- 1].signature
, ph
, num_copy
);
9307 warn (_("Signature (%p) extends beyond end of space in section\n"), ph
);
9312 prow
= poffsets
+ (row
- 1) * ncols
* 4;
9313 /* PR 17531: file: b8ce60a8. */
9314 if (prow
< poffsets
|| prow
> limit
)
9316 warn (_("Row index (%u) * num columns (%u) > space remaining in section\n"),
9322 printf (_(" [%3d] 0x%s"),
9323 i
, dwarf_vmatoa64 (signature_high
, signature_low
,
9324 buf
, sizeof (buf
)));
9325 for (j
= 0; j
< ncols
; j
++)
9327 SAFE_BYTE_GET (val
, prow
+ j
* 4, 4, limit
);
9329 printf (" %8d", val
);
9332 SAFE_BYTE_GET (dw_sect
, ppool
+ j
* 4, 4, limit
);
9334 /* PR 17531: file: 10796eb3. */
9335 if (dw_sect
>= DW_SECT_MAX
)
9336 warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect
);
9338 this_set
[row
- 1].section_offsets
[dw_sect
] = val
;
9354 printf (_(" Size table\n"));
9355 printf (" slot %-16s ",
9356 is_tu_index
? _("signature") : _("dwo_id"));
9359 for (j
= 0; j
< ncols
; j
++)
9361 SAFE_BYTE_GET (val
, ppool
+ j
* 4, 4, limit
);
9363 printf (" %8s", get_DW_SECT_short_name (val
));
9369 for (i
= 0; i
< nslots
; i
++)
9371 SAFE_BYTE_GET64 (ph
, &signature_high
, &signature_low
, limit
);
9373 SAFE_BYTE_GET (row
, pi
, 4, limit
);
9376 prow
= psizes
+ (row
- 1) * ncols
* 4;
9379 printf (_(" [%3d] 0x%s"),
9380 i
, dwarf_vmatoa64 (signature_high
, signature_low
,
9381 buf
, sizeof (buf
)));
9383 for (j
= 0; j
< ncols
; j
++)
9385 SAFE_BYTE_GET (val
, prow
+ j
* 4, 4, limit
);
9387 printf (" %8d", val
);
9390 SAFE_BYTE_GET (dw_sect
, ppool
+ j
* 4, 4, limit
);
9391 if (dw_sect
>= DW_SECT_MAX
)
9392 warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect
);
9394 this_set
[row
- 1].section_sizes
[dw_sect
] = val
;
9406 else if (do_display
)
9407 printf (_(" Unsupported version (%d)\n"), version
);
9415 /* Load the CU and TU indexes if present. This will build a list of
9416 section sets that we can use to associate a .debug_info.dwo section
9417 with its associated .debug_abbrev.dwo section in a .dwp file. */
9420 load_cu_tu_indexes (void *file
)
9422 static int cu_tu_indexes_read
= -1; /* Tri-state variable. */
9424 /* If we have already loaded (or tried to load) the CU and TU indexes
9425 then do not bother to repeat the task. */
9426 if (cu_tu_indexes_read
== -1)
9428 cu_tu_indexes_read
= TRUE
;
9430 if (load_debug_section_with_follow (dwp_cu_index
, file
))
9431 if (! process_cu_tu_index (&debug_displays
[dwp_cu_index
].section
, 0))
9432 cu_tu_indexes_read
= FALSE
;
9434 if (load_debug_section_with_follow (dwp_tu_index
, file
))
9435 if (! process_cu_tu_index (&debug_displays
[dwp_tu_index
].section
, 0))
9436 cu_tu_indexes_read
= FALSE
;
9439 return (bfd_boolean
) cu_tu_indexes_read
;
9442 /* Find the set of sections that includes section SHNDX. */
9445 find_cu_tu_set (void *file
, unsigned int shndx
)
9449 if (! load_cu_tu_indexes (file
))
9452 /* Find SHNDX in the shndx pool. */
9453 for (i
= 0; i
< shndx_pool_used
; i
++)
9454 if (shndx_pool
[i
] == shndx
)
9457 if (i
>= shndx_pool_used
)
9460 /* Now backup to find the first entry in the set. */
9461 while (i
> 0 && shndx_pool
[i
- 1] != 0)
9464 return shndx_pool
+ i
;
9467 /* Display a .debug_cu_index or .debug_tu_index section. */
9470 display_cu_index (struct dwarf_section
*section
, void *file ATTRIBUTE_UNUSED
)
9472 return process_cu_tu_index (section
, 1);
9476 display_debug_not_supported (struct dwarf_section
*section
,
9477 void *file ATTRIBUTE_UNUSED
)
9479 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
9485 /* Like malloc, but takes two parameters like calloc.
9486 Verifies that the first parameter is not too large.
9487 Note: does *not* initialise the allocated memory to zero. */
9490 cmalloc (size_t nmemb
, size_t size
)
9492 /* Check for overflow. */
9493 if (nmemb
>= ~(size_t) 0 / size
)
9496 return xmalloc (nmemb
* size
);
9499 /* Like xmalloc, but takes two parameters like calloc.
9500 Verifies that the first parameter is not too large.
9501 Note: does *not* initialise the allocated memory to zero. */
9504 xcmalloc (size_t nmemb
, size_t size
)
9506 /* Check for overflow. */
9507 if (nmemb
>= ~(size_t) 0 / size
)
9510 _("Attempt to allocate an array with an excessive number of elements: 0x%lx\n"),
9515 return xmalloc (nmemb
* size
);
9518 /* Like xrealloc, but takes three parameters.
9519 Verifies that the second parameter is not too large.
9520 Note: does *not* initialise any new memory to zero. */
9523 xcrealloc (void *ptr
, size_t nmemb
, size_t size
)
9525 /* Check for overflow. */
9526 if (nmemb
>= ~(size_t) 0 / size
)
9528 error (_("Attempt to re-allocate an array with an excessive number of elements: 0x%lx\n"),
9533 return xrealloc (ptr
, nmemb
* size
);
9536 /* Like xcalloc, but verifies that the first parameter is not too large. */
9539 xcalloc2 (size_t nmemb
, size_t size
)
9541 /* Check for overflow. */
9542 if (nmemb
>= ~(size_t) 0 / size
)
9544 error (_("Attempt to allocate a zero'ed array with an excessive number of elements: 0x%lx\n"),
9549 return xcalloc (nmemb
, size
);
9552 static unsigned long
9553 calc_gnu_debuglink_crc32 (unsigned long crc
,
9554 const unsigned char * buf
,
9557 static const unsigned long crc32_table
[256] =
9559 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
9560 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
9561 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
9562 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
9563 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
9564 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
9565 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
9566 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
9567 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
9568 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
9569 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
9570 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
9571 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
9572 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
9573 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
9574 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
9575 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
9576 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
9577 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
9578 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
9579 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
9580 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
9581 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
9582 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
9583 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
9584 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
9585 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
9586 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
9587 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
9588 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
9589 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
9590 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
9591 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
9592 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
9593 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
9594 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
9595 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
9596 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
9597 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
9598 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
9599 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
9600 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
9601 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
9602 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
9603 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
9604 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
9605 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
9606 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
9607 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
9608 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
9609 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
9612 const unsigned char *end
;
9614 crc
= ~crc
& 0xffffffff;
9615 for (end
= buf
+ len
; buf
< end
; ++ buf
)
9616 crc
= crc32_table
[(crc
^ *buf
) & 0xff] ^ (crc
>> 8);
9617 return ~crc
& 0xffffffff;
9620 typedef bfd_boolean (* check_func_type
) (const char *, void *);
9621 typedef const char * (* parse_func_type
) (struct dwarf_section
*, void *);
9624 check_gnu_debuglink (const char * pathname
, void * crc_pointer
)
9626 static unsigned char buffer
[8 * 1024];
9628 bfd_size_type count
;
9629 unsigned long crc
= 0;
9632 sep_data
= open_debug_file (pathname
);
9633 if (sep_data
== NULL
)
9636 /* Yes - we are opening the file twice... */
9637 f
= fopen (pathname
, "rb");
9640 /* Paranoia: This should never happen. */
9641 close_debug_file (sep_data
);
9642 warn (_("Unable to reopen separate debug info file: %s\n"), pathname
);
9646 while ((count
= fread (buffer
, 1, sizeof (buffer
), f
)) > 0)
9647 crc
= calc_gnu_debuglink_crc32 (crc
, buffer
, count
);
9651 if (crc
!= * (unsigned long *) crc_pointer
)
9653 close_debug_file (sep_data
);
9654 warn (_("Separate debug info file %s found, but CRC does not match - ignoring\n"),
9663 parse_gnu_debuglink (struct dwarf_section
* section
, void * data
)
9666 unsigned int crc_offset
;
9667 unsigned long * crc32
= (unsigned long *) data
;
9669 /* The name is first.
9670 The CRC value is stored after the filename, aligned up to 4 bytes. */
9671 name
= (const char *) section
->start
;
9673 crc_offset
= strnlen (name
, section
->size
) + 1;
9674 crc_offset
= (crc_offset
+ 3) & ~3;
9675 if (crc_offset
+ 4 > section
->size
)
9678 * crc32
= byte_get (section
->start
+ crc_offset
, 4);
9683 check_gnu_debugaltlink (const char * filename
, void * data ATTRIBUTE_UNUSED
)
9685 void * sep_data
= open_debug_file (filename
);
9687 if (sep_data
== NULL
)
9690 /* FIXME: We should now extract the build-id in the separate file
9696 typedef struct build_id_data
9699 const unsigned char * data
;
9703 parse_gnu_debugaltlink (struct dwarf_section
* section
, void * data
)
9706 bfd_size_type namelen
;
9707 bfd_size_type id_len
;
9708 Build_id_data
* build_id_data
;
9710 /* The name is first.
9711 The build-id follows immediately, with no padding, up to the section's end. */
9713 name
= (const char *) section
->start
;
9714 namelen
= strnlen (name
, section
->size
) + 1;
9715 if (namelen
>= section
->size
)
9718 id_len
= section
->size
- namelen
;
9722 build_id_data
= calloc (1, sizeof * build_id_data
);
9723 if (build_id_data
== NULL
)
9726 build_id_data
->len
= id_len
;
9727 build_id_data
->data
= section
->start
+ namelen
;
9729 * (Build_id_data
**) data
= build_id_data
;
9735 load_separate_debug_info (const char * main_filename
,
9736 struct dwarf_section
* xlink
,
9737 parse_func_type parse_func
,
9738 check_func_type check_func
,
9741 const char * separate_filename
;
9744 size_t canon_dirlen
;
9747 if ((separate_filename
= parse_func (xlink
, func_data
)) == NULL
)
9749 warn (_("Corrupt debuglink section: %s\n"),
9750 xlink
->name
? xlink
->name
: xlink
->uncompressed_name
);
9754 /* Attempt to locate the separate file.
9755 This should duplicate the logic in bfd/opncls.c:find_separate_debug_file(). */
9757 canon_dir
= lrealpath (main_filename
);
9759 for (canon_dirlen
= strlen (canon_dir
); canon_dirlen
> 0; canon_dirlen
--)
9760 if (IS_DIR_SEPARATOR (canon_dir
[canon_dirlen
- 1]))
9762 canon_dir
[canon_dirlen
] = '\0';
9765 #define DEBUGDIR "/lib/debug"
9767 #ifndef EXTRA_DEBUG_ROOT1
9768 #define EXTRA_DEBUG_ROOT1 "/usr/lib/debug"
9770 #ifndef EXTRA_DEBUG_ROOT2
9771 #define EXTRA_DEBUG_ROOT2 "/usr/lib/debug/usr"
9774 debugfile
= (char *) malloc (strlen (DEBUGDIR
) + 1
9776 + strlen (".debug/")
9777 #ifdef EXTRA_DEBUG_ROOT1
9778 + strlen (EXTRA_DEBUG_ROOT1
)
9780 #ifdef EXTRA_DEBUG_ROOT2
9781 + strlen (EXTRA_DEBUG_ROOT2
)
9783 + strlen (separate_filename
)
9785 if (debugfile
== NULL
)
9787 warn (_("Out of memory"));
9791 /* First try in the current directory. */
9792 sprintf (debugfile
, "%s", separate_filename
);
9793 if (check_func (debugfile
, func_data
))
9796 /* Then try in a subdirectory called .debug. */
9797 sprintf (debugfile
, ".debug/%s", separate_filename
);
9798 if (check_func (debugfile
, func_data
))
9801 /* Then try in the same directory as the original file. */
9802 sprintf (debugfile
, "%s%s", canon_dir
, separate_filename
);
9803 if (check_func (debugfile
, func_data
))
9806 /* And the .debug subdirectory of that directory. */
9807 sprintf (debugfile
, "%s.debug/%s", canon_dir
, separate_filename
);
9808 if (check_func (debugfile
, func_data
))
9811 #ifdef EXTRA_DEBUG_ROOT1
9812 /* Try the first extra debug file root. */
9813 sprintf (debugfile
, "%s/%s", EXTRA_DEBUG_ROOT1
, separate_filename
);
9814 if (check_func (debugfile
, func_data
))
9818 #ifdef EXTRA_DEBUG_ROOT2
9819 /* Try the second extra debug file root. */
9820 sprintf (debugfile
, "%s/%s", EXTRA_DEBUG_ROOT2
, separate_filename
);
9821 if (check_func (debugfile
, func_data
))
9825 /* Then try in the global debugfile directory. */
9826 strcpy (debugfile
, DEBUGDIR
);
9827 dirlen
= strlen (DEBUGDIR
) - 1;
9828 if (dirlen
> 0 && DEBUGDIR
[dirlen
] != '/')
9829 strcat (debugfile
, "/");
9830 strcat (debugfile
, (const char *) separate_filename
);
9832 if (check_func (debugfile
, func_data
))
9835 /* Failed to find the file. */
9836 warn (_("could not find separate debug file '%s'\n"), separate_filename
);
9837 warn (_("tried: %s\n"), debugfile
);
9839 #ifdef EXTRA_DEBUG_ROOT2
9840 sprintf (debugfile
, "%s/%s", EXTRA_DEBUG_ROOT2
, separate_filename
);
9841 warn (_("tried: %s\n"), debugfile
);
9844 #ifdef EXTRA_DEBUG_ROOT1
9845 sprintf (debugfile
, "%s/%s", EXTRA_DEBUG_ROOT1
, separate_filename
);
9846 warn (_("tried: %s\n"), debugfile
);
9849 sprintf (debugfile
, "%s.debug/%s", canon_dir
, separate_filename
);
9850 warn (_("tried: %s\n"), debugfile
);
9852 sprintf (debugfile
, "%s%s", canon_dir
, separate_filename
);
9853 warn (_("tried: %s\n"), debugfile
);
9855 sprintf (debugfile
, ".debug/%s", separate_filename
);
9856 warn (_("tried: %s\n"), debugfile
);
9858 sprintf (debugfile
, "%s", separate_filename
);
9859 warn (_("tried: %s\n"), debugfile
);
9868 /* Now open the file.... */
9869 if ((separate_debug_file
= open_debug_file (debugfile
)) == NULL
)
9871 warn (_("failed to open separate debug file: %s\n"), debugfile
);
9876 /* FIXME: We do not check to see if there are any other separate debug info
9877 files that would also match. */
9879 printf (_("%s: Found separate debug info file: %s\n\n"), main_filename
, debugfile
);
9880 separate_debug_filename
= debugfile
;
9882 /* Do not free debugfile - it might be referenced inside
9883 the structure returned by open_debug_file(). */
9884 return separate_debug_file
;
9887 /* Attempt to load a separate dwarf object file. */
9890 load_dwo_file (const char * main_filename
)
9894 /* FIXME: Skip adding / if dwo_dir ends in /. */
9895 filename
= concat (dwo_dir
, "/", dwo_name
, NULL
);
9896 if (filename
== NULL
)
9898 warn (_("Out of memory allocating dwo filename\n"));
9902 if ((separate_debug_file
= open_debug_file (filename
)) == NULL
)
9904 warn (_("Unable to load dwo file: %s\n"), filename
);
9909 /* FIXME: We should check the dwo_id. */
9911 printf (_("%s: Found separate debug object file: %s\n\n"), main_filename
, filename
);
9912 separate_debug_filename
= filename
;
9913 return separate_debug_file
;
9916 /* Load a separate debug info file, if it exists.
9917 Returns the data pointer that is the result of calling open_debug_file
9918 on the separate debug info file, or NULL if there were problems or there
9922 load_separate_debug_file (void * file
, const char * filename
)
9924 /* Skip this operation if we are not interested in debug links. */
9925 if (! do_follow_links
&& ! do_debug_links
)
9928 /* See if there is a dwo link. */
9929 if (load_debug_section (str
, file
)
9930 && load_debug_section (abbrev
, file
)
9931 && load_debug_section (info
, file
))
9933 dwo_name
= dwo_dir
= NULL
;
9937 if (process_debug_info (& debug_displays
[info
].section
, file
, abbrev
, TRUE
, FALSE
))
9939 if (dwo_name
!= NULL
)
9943 printf (_("The %s section contains a link to a dwo file:\n"),
9944 debug_displays
[info
].section
.uncompressed_name
);
9945 printf (_(" Name: %s\n"), dwo_name
);
9946 printf (_(" Directory: %s\n"), dwo_dir
? dwo_dir
: _("<not-found>"));
9948 display_data (printf (_(" ID: ")), dwo_id
, dwo_id_len
);
9950 printf (_(" ID: <unknown>\n"));
9954 /* FIXME: We do not check to see if there are any more dwo links in the file... */
9955 if (do_follow_links
)
9956 return load_dwo_file (filename
);
9961 if (! do_follow_links
)
9962 /* The other debug links will be displayed by display_debug_links()
9963 so we do not need to do any further processing here. */
9966 /* FIXME: We do not check for the presence of both link sections in the same file. */
9967 /* FIXME: We do not check the separate debug info file to see if it too contains debuglinks. */
9968 /* FIXME: We do not check for the presence of multiple, same-name debuglink sections. */
9969 /* FIXME: We do not check for the presence of a dwo link as well as a debuglink. */
9971 if (load_debug_section (gnu_debugaltlink
, file
))
9973 Build_id_data
* build_id_data
;
9975 return load_separate_debug_info (filename
,
9976 & debug_displays
[gnu_debugaltlink
].section
,
9977 parse_gnu_debugaltlink
,
9978 check_gnu_debugaltlink
,
9982 if (load_debug_section (gnu_debuglink
, file
))
9984 unsigned long crc32
;
9986 return load_separate_debug_info (filename
,
9987 & debug_displays
[gnu_debuglink
].section
,
9988 parse_gnu_debuglink
,
9989 check_gnu_debuglink
,
9993 do_follow_links
= 0;
9998 free_debug_memory (void)
10004 for (i
= 0; i
< max
; i
++)
10005 free_debug_section ((enum dwarf_section_display_enum
) i
);
10007 if (debug_information
!= NULL
)
10009 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
)
10011 for (i
= 0; i
< num_debug_info_entries
; i
++)
10013 if (!debug_information
[i
].max_loc_offsets
)
10015 free (debug_information
[i
].loc_offsets
);
10016 free (debug_information
[i
].have_frame_base
);
10018 if (!debug_information
[i
].max_range_lists
)
10019 free (debug_information
[i
].range_lists
);
10022 free (debug_information
);
10023 debug_information
= NULL
;
10024 alloc_num_debug_info_entries
= num_debug_info_entries
= 0;
10027 if (separate_debug_file
!= NULL
)
10029 close_debug_file (separate_debug_file
);
10030 separate_debug_file
= NULL
;
10032 free ((void *) separate_debug_filename
);
10033 separate_debug_filename
= NULL
;
10038 dwarf_select_sections_by_names (const char *names
)
10042 const char * option
;
10046 debug_dump_long_opts
;
10048 static const debug_dump_long_opts opts_table
[] =
10050 /* Please keep this table alpha- sorted. */
10051 { "Ranges", & do_debug_ranges
, 1 },
10052 { "abbrev", & do_debug_abbrevs
, 1 },
10053 { "addr", & do_debug_addr
, 1 },
10054 { "aranges", & do_debug_aranges
, 1 },
10055 { "cu_index", & do_debug_cu_index
, 1 },
10056 { "decodedline", & do_debug_lines
, FLAG_DEBUG_LINES_DECODED
},
10057 { "follow-links", & do_follow_links
, 1 },
10058 { "frames", & do_debug_frames
, 1 },
10059 { "frames-interp", & do_debug_frames_interp
, 1 },
10060 /* The special .gdb_index section. */
10061 { "gdb_index", & do_gdb_index
, 1 },
10062 { "info", & do_debug_info
, 1 },
10063 { "line", & do_debug_lines
, FLAG_DEBUG_LINES_RAW
}, /* For backwards compatibility. */
10064 { "links", & do_debug_links
, 1 },
10065 { "loc", & do_debug_loc
, 1 },
10066 { "macro", & do_debug_macinfo
, 1 },
10067 { "pubnames", & do_debug_pubnames
, 1 },
10068 { "pubtypes", & do_debug_pubtypes
, 1 },
10069 /* This entry is for compatibility
10070 with earlier versions of readelf. */
10071 { "ranges", & do_debug_aranges
, 1 },
10072 { "rawline", & do_debug_lines
, FLAG_DEBUG_LINES_RAW
},
10073 { "str", & do_debug_str
, 1 },
10074 /* These trace_* sections are used by Itanium VMS. */
10075 { "trace_abbrev", & do_trace_abbrevs
, 1 },
10076 { "trace_aranges", & do_trace_aranges
, 1 },
10077 { "trace_info", & do_trace_info
, 1 },
10086 const debug_dump_long_opts
* entry
;
10088 for (entry
= opts_table
; entry
->option
; entry
++)
10090 size_t len
= strlen (entry
->option
);
10092 if (strncmp (p
, entry
->option
, len
) == 0
10093 && (p
[len
] == ',' || p
[len
] == '\0'))
10095 * entry
->variable
|= entry
->val
;
10097 /* The --debug-dump=frames-interp option also
10098 enables the --debug-dump=frames option. */
10099 if (do_debug_frames_interp
)
10100 do_debug_frames
= 1;
10107 if (entry
->option
== NULL
)
10109 warn (_("Unrecognized debug option '%s'\n"), p
);
10110 p
= strchr (p
, ',');
10121 dwarf_select_sections_by_letters (const char *letters
)
10123 unsigned int lindex
= 0;
10125 while (letters
[lindex
])
10126 switch (letters
[lindex
++])
10128 case 'A': do_debug_addr
= 1; break;
10129 case 'a': do_debug_abbrevs
= 1; break;
10130 case 'c': do_debug_cu_index
= 1; break;
10131 case 'F': do_debug_frames_interp
= 1; /* Fall through. */
10132 case 'f': do_debug_frames
= 1; break;
10133 case 'g': do_gdb_index
= 1; break;
10134 case 'i': do_debug_info
= 1; break;
10135 case 'K': do_follow_links
= 1; break;
10136 case 'k': do_debug_links
= 1; break;
10137 case 'l': do_debug_lines
|= FLAG_DEBUG_LINES_RAW
; break;
10138 case 'L': do_debug_lines
|= FLAG_DEBUG_LINES_DECODED
; break;
10139 case 'm': do_debug_macinfo
= 1; break;
10140 case 'o': do_debug_loc
= 1; break;
10141 case 'p': do_debug_pubnames
= 1; break;
10142 case 'R': do_debug_ranges
= 1; break;
10143 case 'r': do_debug_aranges
= 1; break;
10144 case 's': do_debug_str
= 1; break;
10145 case 'T': do_trace_aranges
= 1; break;
10146 case 't': do_debug_pubtypes
= 1; break;
10147 case 'U': do_trace_info
= 1; break;
10148 case 'u': do_trace_abbrevs
= 1; break;
10151 warn (_("Unrecognized debug option '%s'\n"), letters
);
10157 dwarf_select_sections_all (void)
10160 do_debug_abbrevs
= 1;
10161 do_debug_lines
= FLAG_DEBUG_LINES_RAW
;
10162 do_debug_pubnames
= 1;
10163 do_debug_pubtypes
= 1;
10164 do_debug_aranges
= 1;
10165 do_debug_ranges
= 1;
10166 do_debug_frames
= 1;
10167 do_debug_macinfo
= 1;
10172 do_trace_abbrevs
= 1;
10173 do_trace_aranges
= 1;
10175 do_debug_cu_index
= 1;
10176 do_follow_links
= 1;
10177 do_debug_links
= 1;
10180 #define NO_ABBREVS NULL, NULL, NULL, 0, 0, 0, NULL, 0, NULL
10181 #define ABBREV(N) NULL, NULL, NULL, 0, 0, N, NULL, 0, NULL
10183 /* N.B. The order here must match the order in section_display_enum. */
10185 struct dwarf_section_display debug_displays
[] =
10187 { { ".debug_abbrev", ".zdebug_abbrev", NO_ABBREVS
}, display_debug_abbrev
, &do_debug_abbrevs
, FALSE
},
10188 { { ".debug_aranges", ".zdebug_aranges", NO_ABBREVS
}, display_debug_aranges
, &do_debug_aranges
, TRUE
},
10189 { { ".debug_frame", ".zdebug_frame", NO_ABBREVS
}, display_debug_frames
, &do_debug_frames
, TRUE
},
10190 { { ".debug_info", ".zdebug_info", ABBREV (abbrev
)}, display_debug_info
, &do_debug_info
, TRUE
},
10191 { { ".debug_line", ".zdebug_line", NO_ABBREVS
}, display_debug_lines
, &do_debug_lines
, TRUE
},
10192 { { ".debug_pubnames", ".zdebug_pubnames", NO_ABBREVS
}, display_debug_pubnames
, &do_debug_pubnames
, FALSE
},
10193 { { ".debug_gnu_pubnames", ".zdebug_gnu_pubnames", NO_ABBREVS
}, display_debug_gnu_pubnames
, &do_debug_pubnames
, FALSE
},
10194 { { ".eh_frame", "", NO_ABBREVS
}, display_debug_frames
, &do_debug_frames
, TRUE
},
10195 { { ".debug_macinfo", ".zdebug_macinfo", NO_ABBREVS
}, display_debug_macinfo
, &do_debug_macinfo
, FALSE
},
10196 { { ".debug_macro", ".zdebug_macro", NO_ABBREVS
}, display_debug_macro
, &do_debug_macinfo
, TRUE
},
10197 { { ".debug_str", ".zdebug_str", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, FALSE
},
10198 { { ".debug_line_str", ".zdebug_line_str", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, FALSE
},
10199 { { ".debug_loc", ".zdebug_loc", NO_ABBREVS
}, display_debug_loc
, &do_debug_loc
, TRUE
},
10200 { { ".debug_loclists", ".zdebug_loclists", NO_ABBREVS
}, display_debug_loc
, &do_debug_loc
, TRUE
},
10201 { { ".debug_pubtypes", ".zdebug_pubtypes", NO_ABBREVS
}, display_debug_pubnames
, &do_debug_pubtypes
, FALSE
},
10202 { { ".debug_gnu_pubtypes", ".zdebug_gnu_pubtypes", NO_ABBREVS
}, display_debug_gnu_pubnames
, &do_debug_pubtypes
, FALSE
},
10203 { { ".debug_ranges", ".zdebug_ranges", NO_ABBREVS
}, display_debug_ranges
, &do_debug_ranges
, TRUE
},
10204 { { ".debug_rnglists", ".zdebug_rnglists", NO_ABBREVS
}, display_debug_ranges
, &do_debug_ranges
, TRUE
},
10205 { { ".debug_static_func", ".zdebug_static_func", NO_ABBREVS
}, display_debug_not_supported
, NULL
, FALSE
},
10206 { { ".debug_static_vars", ".zdebug_static_vars", NO_ABBREVS
}, display_debug_not_supported
, NULL
, FALSE
},
10207 { { ".debug_types", ".zdebug_types", ABBREV (abbrev
) }, display_debug_types
, &do_debug_info
, TRUE
},
10208 { { ".debug_weaknames", ".zdebug_weaknames", NO_ABBREVS
}, display_debug_not_supported
, NULL
, FALSE
},
10209 { { ".gdb_index", "", NO_ABBREVS
}, display_gdb_index
, &do_gdb_index
, FALSE
},
10210 { { ".debug_names", "", NO_ABBREVS
}, display_debug_names
, &do_gdb_index
, FALSE
},
10211 { { ".trace_info", "", ABBREV (trace_abbrev
) }, display_trace_info
, &do_trace_info
, TRUE
},
10212 { { ".trace_abbrev", "", NO_ABBREVS
}, display_debug_abbrev
, &do_trace_abbrevs
, FALSE
},
10213 { { ".trace_aranges", "", NO_ABBREVS
}, display_debug_aranges
, &do_trace_aranges
, FALSE
},
10214 { { ".debug_info.dwo", ".zdebug_info.dwo", ABBREV (abbrev_dwo
) }, display_debug_info
, &do_debug_info
, TRUE
},
10215 { { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo", NO_ABBREVS
}, display_debug_abbrev
, &do_debug_abbrevs
, FALSE
},
10216 { { ".debug_types.dwo", ".zdebug_types.dwo", ABBREV (abbrev_dwo
) }, display_debug_types
, &do_debug_info
, TRUE
},
10217 { { ".debug_line.dwo", ".zdebug_line.dwo", NO_ABBREVS
}, display_debug_lines
, &do_debug_lines
, TRUE
},
10218 { { ".debug_loc.dwo", ".zdebug_loc.dwo", NO_ABBREVS
}, display_debug_loc
, &do_debug_loc
, TRUE
},
10219 { { ".debug_macro.dwo", ".zdebug_macro.dwo", NO_ABBREVS
}, display_debug_macro
, &do_debug_macinfo
, TRUE
},
10220 { { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo", NO_ABBREVS
}, display_debug_macinfo
, &do_debug_macinfo
, FALSE
},
10221 { { ".debug_str.dwo", ".zdebug_str.dwo", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, TRUE
},
10222 { { ".debug_str_offsets", ".zdebug_str_offsets", NO_ABBREVS
}, display_debug_str_offsets
, NULL
, FALSE
},
10223 { { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo", NO_ABBREVS
}, display_debug_str_offsets
, NULL
, FALSE
},
10224 { { ".debug_addr", ".zdebug_addr", NO_ABBREVS
}, display_debug_addr
, &do_debug_addr
, TRUE
},
10225 { { ".debug_cu_index", "", NO_ABBREVS
}, display_cu_index
, &do_debug_cu_index
, FALSE
},
10226 { { ".debug_tu_index", "", NO_ABBREVS
}, display_cu_index
, &do_debug_cu_index
, FALSE
},
10227 { { ".gnu_debuglink", "", NO_ABBREVS
}, display_debug_links
, &do_debug_links
, FALSE
},
10228 { { ".gnu_debugaltlink", "", NO_ABBREVS
}, display_debug_links
, &do_debug_links
, FALSE
},
10229 /* Separate debug info files can containt their own .debug_str section,
10230 and this might be in *addition* to a .debug_str section already present
10231 in the main file. Hence we need to have two entries for .debug_str. */
10232 { { ".debug_str", ".zdebug_str", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, FALSE
},
10235 /* A static assertion. */
10236 extern int debug_displays_assert
[ARRAY_SIZE (debug_displays
) == max
? 1 : -1];