1 /* dwarf.c -- display DWARF contents of a BFD binary file
2 Copyright (C) 2005-2017 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"
35 #define MAX(a, b) ((a) > (b) ? (a) : (b))
36 #define MIN(a, b) ((a) < (b) ? (a) : (b))
38 static const char *regname (unsigned int regno
, int row
);
40 static int have_frame_base
;
41 static int need_base_address
;
43 static unsigned int num_debug_info_entries
= 0;
44 static unsigned int alloc_num_debug_info_entries
= 0;
45 static debug_info
*debug_information
= NULL
;
46 /* Special value for num_debug_info_entries to indicate
47 that the .debug_info section could not be loaded/parsed. */
48 #define DEBUG_INFO_UNAVAILABLE (unsigned int) -1
50 unsigned int eh_addr_size
;
55 int do_debug_pubnames
;
56 int do_debug_pubtypes
;
60 int do_debug_frames_interp
;
69 int do_debug_cu_index
;
72 int dwarf_cutoff_level
= -1;
73 unsigned long dwarf_start_die
;
77 /* Convenient constant, to avoid having to cast -1 to dwarf_vma when
78 testing whether e.g. a locview list is present. */
79 static const dwarf_vma vm1
= -1;
81 /* Collection of CU/TU section sets from .debug_cu_index and .debug_tu_index
82 sections. For version 1 package files, each set is stored in SHNDX_POOL
83 as a zero-terminated list of section indexes comprising one set of debug
84 sections from a .dwo file. */
86 static unsigned int *shndx_pool
= NULL
;
87 static unsigned int shndx_pool_size
= 0;
88 static unsigned int shndx_pool_used
= 0;
90 /* For version 2 package files, each set contains an array of section offsets
91 and an array of section sizes, giving the offset and size of the
92 contribution from a CU or TU within one of the debug sections.
93 When displaying debug info from a package file, we need to use these
94 tables to locate the corresponding contributions to each section. */
99 dwarf_vma section_offsets
[DW_SECT_MAX
];
100 size_t section_sizes
[DW_SECT_MAX
];
103 static int cu_count
= 0;
104 static int tu_count
= 0;
105 static struct cu_tu_set
*cu_sets
= NULL
;
106 static struct cu_tu_set
*tu_sets
= NULL
;
108 static bfd_boolean
load_cu_tu_indexes (void *);
110 /* Values for do_debug_lines. */
111 #define FLAG_DEBUG_LINES_RAW 1
112 #define FLAG_DEBUG_LINES_DECODED 2
115 size_of_encoded_value (int encoding
)
117 switch (encoding
& 0x7)
120 case 0: return eh_addr_size
;
128 get_encoded_value (unsigned char **pdata
,
130 struct dwarf_section
*section
,
133 unsigned char * data
= * pdata
;
134 unsigned int size
= size_of_encoded_value (encoding
);
137 if (data
+ size
>= end
)
139 warn (_("Encoded value extends past end of section\n"));
144 /* PR 17512: file: 002-829853-0.004. */
147 warn (_("Encoded size of %d is too large to read\n"), size
);
152 /* PR 17512: file: 1085-5603-0.004. */
155 warn (_("Encoded size of 0 is too small to read\n"));
160 if (encoding
& DW_EH_PE_signed
)
161 val
= byte_get_signed (data
, size
);
163 val
= byte_get (data
, size
);
165 if ((encoding
& 0x70) == DW_EH_PE_pcrel
)
166 val
+= section
->address
+ (data
- section
->start
);
168 * pdata
= data
+ size
;
172 #if defined HAVE_LONG_LONG && SIZEOF_LONG_LONG > SIZEOF_LONG
174 # define DWARF_VMA_FMT "ll"
175 # define DWARF_VMA_FMT_LONG "%16.16llx"
177 # define DWARF_VMA_FMT "I64"
178 # define DWARF_VMA_FMT_LONG "%016I64x"
181 # define DWARF_VMA_FMT "l"
182 # define DWARF_VMA_FMT_LONG "%16.16lx"
185 /* Convert a dwarf vma value into a string. Returns a pointer to a static
186 buffer containing the converted VALUE. The value is converted according
187 to the printf formating character FMTCH. If NUM_BYTES is non-zero then
188 it specifies the maximum number of bytes to be displayed in the converted
189 value and FMTCH is ignored - hex is always used. */
192 dwarf_vmatoa_1 (const char *fmtch
, dwarf_vma value
, unsigned num_bytes
)
194 /* As dwarf_vmatoa is used more then once in a printf call
195 for output, we are cycling through an fixed array of pointers
196 for return address. */
197 static int buf_pos
= 0;
198 static struct dwarf_vmatoa_buf
204 ret
= buf
[buf_pos
++].place
;
205 buf_pos
%= ARRAY_SIZE (buf
);
209 /* Printf does not have a way of specifying a maximum field width for an
210 integer value, so we print the full value into a buffer and then select
211 the precision we need. */
212 snprintf (ret
, sizeof (buf
[0].place
), DWARF_VMA_FMT_LONG
, value
);
215 return ret
+ (16 - 2 * num_bytes
);
222 sprintf (fmt
, "%%%s%s", DWARF_VMA_FMT
, fmtch
);
224 sprintf (fmt
, "%%%s", DWARF_VMA_FMT
);
225 snprintf (ret
, sizeof (buf
[0].place
), fmt
, value
);
230 static inline const char *
231 dwarf_vmatoa (const char * fmtch
, dwarf_vma value
)
233 return dwarf_vmatoa_1 (fmtch
, value
, 0);
236 /* Print a dwarf_vma value (typically an address, offset or length) in
237 hexadecimal format, followed by a space. The length of the VALUE (and
238 hence the precision displayed) is determined by the NUM_BYTES parameter. */
241 print_dwarf_vma (dwarf_vma value
, unsigned num_bytes
)
243 printf ("%s ", dwarf_vmatoa_1 (NULL
, value
, num_bytes
));
246 /* Print a view number in hexadecimal value, with the same width
247 print_dwarf_vma would have printed it with the same num_bytes.
248 Print blanks for zero view, unless force is nonzero. */
251 print_dwarf_view (dwarf_vma value
, unsigned num_bytes
, int force
)
259 assert (value
== (unsigned long) value
);
261 printf ("v%0*lx ", len
- 1, (unsigned long) value
);
263 printf ("%*s", len
+ 1, "");
266 /* Format a 64-bit value, given as two 32-bit values, in hex.
267 For reentrancy, this uses a buffer provided by the caller. */
270 dwarf_vmatoa64 (dwarf_vma hvalue
, dwarf_vma lvalue
, char *buf
,
271 unsigned int buf_len
)
276 snprintf (buf
, buf_len
, "%" DWARF_VMA_FMT
"x", lvalue
);
279 len
= snprintf (buf
, buf_len
, "%" DWARF_VMA_FMT
"x", hvalue
);
280 snprintf (buf
+ len
, buf_len
- len
,
281 "%08" DWARF_VMA_FMT
"x", lvalue
);
287 /* Read in a LEB128 encoded value starting at address DATA.
288 If SIGN is true, return a signed LEB128 value.
289 If LENGTH_RETURN is not NULL, return in it the number of bytes read.
290 No bytes will be read at address END or beyond. */
293 read_leb128 (unsigned char *data
,
294 unsigned int *length_return
,
296 const unsigned char * const end
)
298 dwarf_vma result
= 0;
299 unsigned int num_read
= 0;
300 unsigned int shift
= 0;
301 unsigned char byte
= 0;
308 result
|= ((dwarf_vma
) (byte
& 0x7f)) << shift
;
311 if ((byte
& 0x80) == 0)
314 /* PR 17512: file: 0ca183b8.
315 FIXME: Should we signal this error somehow ? */
316 if (shift
>= sizeof (result
) * 8)
320 if (length_return
!= NULL
)
321 *length_return
= num_read
;
323 if (sign
&& (shift
< 8 * sizeof (result
)) && (byte
& 0x40))
324 result
|= -((dwarf_vma
) 1 << shift
);
329 /* Create a signed version to avoid painful typecasts. */
330 static inline dwarf_signed_vma
331 read_sleb128 (unsigned char * data
,
332 unsigned int * length_return
,
333 const unsigned char * const end
)
335 return (dwarf_signed_vma
) read_leb128 (data
, length_return
, TRUE
, end
);
338 static inline dwarf_vma
339 read_uleb128 (unsigned char * data
,
340 unsigned int * length_return
,
341 const unsigned char * const end
)
343 return read_leb128 (data
, length_return
, FALSE
, end
);
346 #define SKIP_ULEB() read_uleb128 (start, & length_return, end); start += length_return
347 #define SKIP_SLEB() read_sleb128 (start, & length_return, end); start += length_return
349 #define READ_ULEB(var) \
354 (var) = _val = read_uleb128 (start, &length_return, end); \
356 error (_("Internal error: %s:%d: LEB value (%s) " \
357 "too large for containing variable\n"), \
358 __FILE__, __LINE__, dwarf_vmatoa ("u", _val)); \
359 start += length_return; \
363 #define READ_SLEB(var) \
366 dwarf_signed_vma _val; \
368 (var) = _val = read_sleb128 (start, &length_return, end); \
370 error (_("Internal error: %s:%d: LEB value (%s) " \
371 "too large for containing variable\n"), \
372 __FILE__, __LINE__, dwarf_vmatoa ("d", _val)); \
373 start += length_return; \
377 #define SAFE_BYTE_GET(VAL, PTR, AMOUNT, END) \
380 unsigned int amount = (AMOUNT); \
381 if (sizeof (VAL) < amount) \
383 error (ngettext ("internal error: attempt to read %d byte " \
384 "of data in to %d sized variable", \
385 "internal error: attempt to read %d bytes " \
386 "of data in to %d sized variable", \
388 amount, (int) sizeof (VAL)); \
389 amount = sizeof (VAL); \
391 if (((PTR) + amount) >= (END)) \
394 amount = (END) - (PTR); \
398 if (amount == 0 || amount > 8) \
401 VAL = byte_get ((PTR), amount); \
405 #define SAFE_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \
408 SAFE_BYTE_GET (VAL, PTR, AMOUNT, END); \
413 #define SAFE_SIGNED_BYTE_GET(VAL, PTR, AMOUNT, END) \
416 unsigned int amount = (AMOUNT); \
417 if (((PTR) + amount) >= (END)) \
420 amount = (END) - (PTR); \
425 VAL = byte_get_signed ((PTR), amount); \
431 #define SAFE_SIGNED_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \
434 SAFE_SIGNED_BYTE_GET (VAL, PTR, AMOUNT, END); \
439 #define SAFE_BYTE_GET64(PTR, HIGH, LOW, END) \
442 if (((PTR) + 8) <= (END)) \
444 byte_get_64 ((PTR), (HIGH), (LOW)); \
448 * (LOW) = * (HIGH) = 0; \
453 typedef struct State_Machine_Registers
462 unsigned char op_index
;
463 unsigned char end_sequence
;
464 /* This variable hold the number of the last entry seen
465 in the File Table. */
466 unsigned int last_file_entry
;
469 static SMR state_machine_regs
;
472 reset_state_machine (int is_stmt
)
474 state_machine_regs
.address
= 0;
475 state_machine_regs
.view
= 0;
476 state_machine_regs
.op_index
= 0;
477 state_machine_regs
.file
= 1;
478 state_machine_regs
.line
= 1;
479 state_machine_regs
.column
= 0;
480 state_machine_regs
.is_stmt
= is_stmt
;
481 state_machine_regs
.basic_block
= 0;
482 state_machine_regs
.end_sequence
= 0;
483 state_machine_regs
.last_file_entry
= 0;
486 /* Handled an extend line op.
487 Returns the number of bytes read. */
490 process_extended_line_op (unsigned char * data
,
494 unsigned char op_code
;
495 unsigned int bytes_read
;
498 unsigned char *orig_data
= data
;
501 len
= read_uleb128 (data
, & bytes_read
, end
);
504 if (len
== 0 || data
== end
|| len
> (uintptr_t) (end
- data
))
506 warn (_("Badly formed extended line op encountered!\n"));
513 printf (_(" Extended opcode %d: "), op_code
);
517 case DW_LNE_end_sequence
:
518 printf (_("End of Sequence\n\n"));
519 reset_state_machine (is_stmt
);
522 case DW_LNE_set_address
:
523 /* PR 17512: file: 002-100480-0.004. */
524 if (len
- bytes_read
- 1 > 8)
526 warn (_("Length (%d) of DW_LNE_set_address op is too long\n"),
527 len
- bytes_read
- 1);
531 SAFE_BYTE_GET (adr
, data
, len
- bytes_read
- 1, end
);
532 printf (_("set Address to 0x%s\n"), dwarf_vmatoa ("x", adr
));
533 state_machine_regs
.address
= adr
;
534 state_machine_regs
.view
= 0;
535 state_machine_regs
.op_index
= 0;
538 case DW_LNE_define_file
:
539 printf (_("define new File Table entry\n"));
540 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
541 printf (" %d\t", ++state_machine_regs
.last_file_entry
);
547 l
= strnlen ((char *) data
, end
- data
);
549 printf ("%s\t", dwarf_vmatoa ("u", read_uleb128 (data
, & bytes_read
, end
)));
551 printf ("%s\t", dwarf_vmatoa ("u", read_uleb128 (data
, & bytes_read
, end
)));
553 printf ("%s\t", dwarf_vmatoa ("u", read_uleb128 (data
, & bytes_read
, end
)));
555 printf ("%.*s\n\n", (int) l
, name
);
558 if (((unsigned int) (data
- orig_data
) != len
) || data
== end
)
559 warn (_("DW_LNE_define_file: Bad opcode length\n"));
562 case DW_LNE_set_discriminator
:
563 printf (_("set Discriminator to %s\n"),
564 dwarf_vmatoa ("u", read_uleb128 (data
, & bytes_read
, end
)));
568 case DW_LNE_HP_negate_is_UV_update
:
569 printf ("DW_LNE_HP_negate_is_UV_update\n");
571 case DW_LNE_HP_push_context
:
572 printf ("DW_LNE_HP_push_context\n");
574 case DW_LNE_HP_pop_context
:
575 printf ("DW_LNE_HP_pop_context\n");
577 case DW_LNE_HP_set_file_line_column
:
578 printf ("DW_LNE_HP_set_file_line_column\n");
580 case DW_LNE_HP_set_routine_name
:
581 printf ("DW_LNE_HP_set_routine_name\n");
583 case DW_LNE_HP_set_sequence
:
584 printf ("DW_LNE_HP_set_sequence\n");
586 case DW_LNE_HP_negate_post_semantics
:
587 printf ("DW_LNE_HP_negate_post_semantics\n");
589 case DW_LNE_HP_negate_function_exit
:
590 printf ("DW_LNE_HP_negate_function_exit\n");
592 case DW_LNE_HP_negate_front_end_logical
:
593 printf ("DW_LNE_HP_negate_front_end_logical\n");
595 case DW_LNE_HP_define_proc
:
596 printf ("DW_LNE_HP_define_proc\n");
598 case DW_LNE_HP_source_file_correlation
:
600 unsigned char *edata
= data
+ len
- bytes_read
- 1;
602 printf ("DW_LNE_HP_source_file_correlation\n");
608 opc
= read_uleb128 (data
, & bytes_read
, edata
);
613 case DW_LNE_HP_SFC_formfeed
:
614 printf (" DW_LNE_HP_SFC_formfeed\n");
616 case DW_LNE_HP_SFC_set_listing_line
:
617 printf (" DW_LNE_HP_SFC_set_listing_line (%s)\n",
619 read_uleb128 (data
, & bytes_read
, edata
)));
622 case DW_LNE_HP_SFC_associate
:
623 printf (" DW_LNE_HP_SFC_associate ");
626 read_uleb128 (data
, & bytes_read
, edata
)));
630 read_uleb128 (data
, & bytes_read
, edata
)));
634 read_uleb128 (data
, & bytes_read
, edata
)));
638 printf (_(" UNKNOWN DW_LNE_HP_SFC opcode (%u)\n"), opc
);
648 unsigned int rlen
= len
- bytes_read
- 1;
650 if (op_code
>= DW_LNE_lo_user
651 /* The test against DW_LNW_hi_user is redundant due to
652 the limited range of the unsigned char data type used
654 /*&& op_code <= DW_LNE_hi_user*/)
655 printf (_("user defined: "));
657 printf (_("UNKNOWN: "));
658 printf (_("length %d ["), rlen
);
660 printf (" %02x", *data
++);
669 static const unsigned char *
670 fetch_indirect_string (dwarf_vma offset
)
672 struct dwarf_section
*section
= &debug_displays
[str
].section
;
673 const unsigned char * ret
;
675 if (section
->start
== NULL
)
676 return (const unsigned char *) _("<no .debug_str section>");
678 if (offset
>= section
->size
)
680 warn (_("DW_FORM_strp offset too big: %s\n"),
681 dwarf_vmatoa ("x", offset
));
682 return (const unsigned char *) _("<offset is too big>");
685 ret
= section
->start
+ offset
;
686 /* Unfortunately we cannot rely upon the .debug_str section ending with a
687 NUL byte. Since our caller is expecting to receive a well formed C
688 string we test for the lack of a terminating byte here. */
689 if (strnlen ((const char *) ret
, section
->size
- offset
)
690 == section
->size
- offset
)
691 ret
= (const unsigned char *)
692 _("<no NUL byte at end of .debug_str section>");
697 static const unsigned char *
698 fetch_indirect_line_string (dwarf_vma offset
)
700 struct dwarf_section
*section
= &debug_displays
[line_str
].section
;
701 const unsigned char * ret
;
703 if (section
->start
== NULL
)
704 return (const unsigned char *) _("<no .debug_line_str section>");
706 if (offset
>= section
->size
)
708 warn (_("DW_FORM_line_strp offset too big: %s\n"),
709 dwarf_vmatoa ("x", offset
));
710 return (const unsigned char *) _("<offset is too big>");
713 ret
= section
->start
+ offset
;
714 /* Unfortunately we cannot rely upon the .debug_line_str section ending
715 with a NUL byte. Since our caller is expecting to receive a well formed
716 C string we test for the lack of a terminating byte here. */
717 if (strnlen ((const char *) ret
, section
->size
- offset
)
718 == section
->size
- offset
)
719 ret
= (const unsigned char *)
720 _("<no NUL byte at end of .debug_line_str section>");
726 fetch_indexed_string (dwarf_vma idx
, struct cu_tu_set
*this_set
,
727 dwarf_vma offset_size
, int dwo
)
729 enum dwarf_section_display_enum str_sec_idx
= dwo
? str_dwo
: str
;
730 enum dwarf_section_display_enum idx_sec_idx
= dwo
? str_index_dwo
: str_index
;
731 struct dwarf_section
*index_section
= &debug_displays
[idx_sec_idx
].section
;
732 struct dwarf_section
*str_section
= &debug_displays
[str_sec_idx
].section
;
733 dwarf_vma index_offset
= idx
* offset_size
;
734 dwarf_vma str_offset
;
737 if (index_section
->start
== NULL
)
738 return (dwo
? _("<no .debug_str_offsets.dwo section>")
739 : _("<no .debug_str_offsets section>"));
741 if (this_set
!= NULL
)
742 index_offset
+= this_set
->section_offsets
[DW_SECT_STR_OFFSETS
];
743 if (index_offset
>= index_section
->size
)
745 warn (_("DW_FORM_GNU_str_index offset too big: %s\n"),
746 dwarf_vmatoa ("x", index_offset
));
747 return _("<index offset is too big>");
750 if (str_section
->start
== NULL
)
751 return (dwo
? _("<no .debug_str.dwo section>")
752 : _("<no .debug_str section>"));
754 str_offset
= byte_get (index_section
->start
+ index_offset
, offset_size
);
755 str_offset
-= str_section
->address
;
756 if (str_offset
>= str_section
->size
)
758 warn (_("DW_FORM_GNU_str_index indirect offset too big: %s\n"),
759 dwarf_vmatoa ("x", str_offset
));
760 return _("<indirect index offset is too big>");
763 ret
= (const char *) str_section
->start
+ str_offset
;
764 /* Unfortunately we cannot rely upon str_section ending with a NUL byte.
765 Since our caller is expecting to receive a well formed C string we test
766 for the lack of a terminating byte here. */
767 if (strnlen (ret
, str_section
->size
- str_offset
)
768 == str_section
->size
- str_offset
)
769 ret
= (const char *) _("<no NUL byte at end of section>");
775 fetch_indexed_value (dwarf_vma offset
, dwarf_vma bytes
)
777 struct dwarf_section
*section
= &debug_displays
[debug_addr
].section
;
779 if (section
->start
== NULL
)
780 return (_("<no .debug_addr section>"));
782 if (offset
+ bytes
> section
->size
)
784 warn (_("Offset into section %s too big: %s\n"),
785 section
->name
, dwarf_vmatoa ("x", offset
));
786 return "<offset too big>";
789 return dwarf_vmatoa ("x", byte_get (section
->start
+ offset
, bytes
));
793 /* FIXME: There are better and more efficient ways to handle
794 these structures. For now though, I just want something that
795 is simple to implement. */
796 typedef struct abbrev_attr
798 unsigned long attribute
;
800 bfd_signed_vma implicit_const
;
801 struct abbrev_attr
*next
;
805 typedef struct abbrev_entry
810 struct abbrev_attr
*first_attr
;
811 struct abbrev_attr
*last_attr
;
812 struct abbrev_entry
*next
;
816 static abbrev_entry
*first_abbrev
= NULL
;
817 static abbrev_entry
*last_abbrev
= NULL
;
824 for (abbrv
= first_abbrev
; abbrv
;)
826 abbrev_entry
*next_abbrev
= abbrv
->next
;
829 for (attr
= abbrv
->first_attr
; attr
;)
831 abbrev_attr
*next_attr
= attr
->next
;
841 last_abbrev
= first_abbrev
= NULL
;
845 add_abbrev (unsigned long number
, unsigned long tag
, int children
)
849 entry
= (abbrev_entry
*) malloc (sizeof (*entry
));
854 entry
->entry
= number
;
856 entry
->children
= children
;
857 entry
->first_attr
= NULL
;
858 entry
->last_attr
= NULL
;
861 if (first_abbrev
== NULL
)
862 first_abbrev
= entry
;
864 last_abbrev
->next
= entry
;
870 add_abbrev_attr (unsigned long attribute
, unsigned long form
,
871 bfd_signed_vma implicit_const
)
875 attr
= (abbrev_attr
*) malloc (sizeof (*attr
));
880 attr
->attribute
= attribute
;
882 attr
->implicit_const
= implicit_const
;
885 if (last_abbrev
->first_attr
== NULL
)
886 last_abbrev
->first_attr
= attr
;
888 last_abbrev
->last_attr
->next
= attr
;
890 last_abbrev
->last_attr
= attr
;
893 /* Processes the (partial) contents of a .debug_abbrev section.
894 Returns NULL if the end of the section was encountered.
895 Returns the address after the last byte read if the end of
896 an abbreviation set was found. */
898 static unsigned char *
899 process_abbrev_section (unsigned char *start
, unsigned char *end
)
901 if (first_abbrev
!= NULL
)
906 unsigned int bytes_read
;
909 unsigned long attribute
;
912 entry
= read_uleb128 (start
, & bytes_read
, end
);
915 /* A single zero is supposed to end the section according
916 to the standard. If there's more, then signal that to
923 tag
= read_uleb128 (start
, & bytes_read
, end
);
930 add_abbrev (entry
, tag
, children
);
935 /* Initialize it due to a false compiler warning. */
936 bfd_signed_vma implicit_const
= -1;
938 attribute
= read_uleb128 (start
, & bytes_read
, end
);
943 form
= read_uleb128 (start
, & bytes_read
, end
);
948 if (form
== DW_FORM_implicit_const
)
950 implicit_const
= read_sleb128 (start
, & bytes_read
, end
);
956 add_abbrev_attr (attribute
, form
, implicit_const
);
958 while (attribute
!= 0);
961 /* Report the missing single zero which ends the section. */
962 error (_(".debug_abbrev section not zero terminated\n"));
968 get_TAG_name (unsigned long tag
)
970 const char *name
= get_DW_TAG_name ((unsigned int) tag
);
974 static char buffer
[100];
976 if (tag
>= DW_TAG_lo_user
&& tag
<= DW_TAG_hi_user
)
977 snprintf (buffer
, sizeof (buffer
), _("User TAG value: %#lx"), tag
);
979 snprintf (buffer
, sizeof (buffer
), _("Unknown TAG value: %#lx"), tag
);
987 get_FORM_name (unsigned long form
)
992 return "DW_FORM value: 0";
994 name
= get_DW_FORM_name (form
);
997 static char buffer
[100];
999 snprintf (buffer
, sizeof (buffer
), _("Unknown FORM value: %lx"), form
);
1007 get_IDX_name (unsigned long idx
)
1009 const char *name
= get_DW_IDX_name ((unsigned int) idx
);
1013 static char buffer
[100];
1015 snprintf (buffer
, sizeof (buffer
), _("Unknown IDX value: %lx"), idx
);
1022 static unsigned char *
1023 display_block (unsigned char *data
,
1025 const unsigned char * const end
, char delimiter
)
1029 printf (_("%c%s byte block: "), delimiter
, dwarf_vmatoa ("u", length
));
1031 return (unsigned char *) end
;
1033 maxlen
= (dwarf_vma
) (end
- data
);
1034 length
= length
> maxlen
? maxlen
: length
;
1037 printf ("%lx ", (unsigned long) byte_get (data
++, 1));
1043 decode_location_expression (unsigned char * data
,
1044 unsigned int pointer_size
,
1045 unsigned int offset_size
,
1048 dwarf_vma cu_offset
,
1049 struct dwarf_section
* section
)
1052 unsigned int bytes_read
;
1054 dwarf_signed_vma svalue
;
1055 unsigned char *end
= data
+ length
;
1056 int need_frame_base
= 0;
1065 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1066 printf ("DW_OP_addr: %s", dwarf_vmatoa ("x", uvalue
));
1069 printf ("DW_OP_deref");
1072 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1073 printf ("DW_OP_const1u: %lu", (unsigned long) uvalue
);
1076 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 1, end
);
1077 printf ("DW_OP_const1s: %ld", (long) svalue
);
1080 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
1081 printf ("DW_OP_const2u: %lu", (unsigned long) uvalue
);
1084 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1085 printf ("DW_OP_const2s: %ld", (long) svalue
);
1088 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1089 printf ("DW_OP_const4u: %lu", (unsigned long) uvalue
);
1092 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
1093 printf ("DW_OP_const4s: %ld", (long) svalue
);
1096 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1097 printf ("DW_OP_const8u: %lu ", (unsigned long) uvalue
);
1098 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1099 printf ("%lu", (unsigned long) uvalue
);
1102 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
1103 printf ("DW_OP_const8s: %ld ", (long) svalue
);
1104 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
1105 printf ("%ld", (long) svalue
);
1108 printf ("DW_OP_constu: %s",
1109 dwarf_vmatoa ("u", read_uleb128 (data
, &bytes_read
, end
)));
1113 printf ("DW_OP_consts: %s",
1114 dwarf_vmatoa ("d", read_sleb128 (data
, &bytes_read
, end
)));
1118 printf ("DW_OP_dup");
1121 printf ("DW_OP_drop");
1124 printf ("DW_OP_over");
1127 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1128 printf ("DW_OP_pick: %ld", (unsigned long) uvalue
);
1131 printf ("DW_OP_swap");
1134 printf ("DW_OP_rot");
1137 printf ("DW_OP_xderef");
1140 printf ("DW_OP_abs");
1143 printf ("DW_OP_and");
1146 printf ("DW_OP_div");
1149 printf ("DW_OP_minus");
1152 printf ("DW_OP_mod");
1155 printf ("DW_OP_mul");
1158 printf ("DW_OP_neg");
1161 printf ("DW_OP_not");
1164 printf ("DW_OP_or");
1167 printf ("DW_OP_plus");
1169 case DW_OP_plus_uconst
:
1170 printf ("DW_OP_plus_uconst: %s",
1171 dwarf_vmatoa ("u", read_uleb128 (data
, &bytes_read
, end
)));
1175 printf ("DW_OP_shl");
1178 printf ("DW_OP_shr");
1181 printf ("DW_OP_shra");
1184 printf ("DW_OP_xor");
1187 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1188 printf ("DW_OP_bra: %ld", (long) svalue
);
1191 printf ("DW_OP_eq");
1194 printf ("DW_OP_ge");
1197 printf ("DW_OP_gt");
1200 printf ("DW_OP_le");
1203 printf ("DW_OP_lt");
1206 printf ("DW_OP_ne");
1209 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1210 printf ("DW_OP_skip: %ld", (long) svalue
);
1245 printf ("DW_OP_lit%d", op
- DW_OP_lit0
);
1280 printf ("DW_OP_reg%d (%s)", op
- DW_OP_reg0
,
1281 regname (op
- DW_OP_reg0
, 1));
1316 printf ("DW_OP_breg%d (%s): %s",
1318 regname (op
- DW_OP_breg0
, 1),
1319 dwarf_vmatoa ("d", read_sleb128 (data
, &bytes_read
, end
)));
1324 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1326 printf ("DW_OP_regx: %s (%s)",
1327 dwarf_vmatoa ("u", uvalue
), regname (uvalue
, 1));
1330 need_frame_base
= 1;
1331 printf ("DW_OP_fbreg: %s",
1332 dwarf_vmatoa ("d", read_sleb128 (data
, &bytes_read
, end
)));
1336 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1338 printf ("DW_OP_bregx: %s (%s) %s",
1339 dwarf_vmatoa ("u", uvalue
), regname (uvalue
, 1),
1340 dwarf_vmatoa ("d", read_sleb128 (data
, &bytes_read
, end
)));
1344 printf ("DW_OP_piece: %s",
1345 dwarf_vmatoa ("u", read_uleb128 (data
, &bytes_read
, end
)));
1348 case DW_OP_deref_size
:
1349 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1350 printf ("DW_OP_deref_size: %ld", (long) uvalue
);
1352 case DW_OP_xderef_size
:
1353 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1354 printf ("DW_OP_xderef_size: %ld", (long) uvalue
);
1357 printf ("DW_OP_nop");
1360 /* DWARF 3 extensions. */
1361 case DW_OP_push_object_address
:
1362 printf ("DW_OP_push_object_address");
1365 /* XXX: Strictly speaking for 64-bit DWARF3 files
1366 this ought to be an 8-byte wide computation. */
1367 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1368 printf ("DW_OP_call2: <0x%s>",
1369 dwarf_vmatoa ("x", svalue
+ cu_offset
));
1372 /* XXX: Strictly speaking for 64-bit DWARF3 files
1373 this ought to be an 8-byte wide computation. */
1374 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
1375 printf ("DW_OP_call4: <0x%s>",
1376 dwarf_vmatoa ("x", svalue
+ cu_offset
));
1378 case DW_OP_call_ref
:
1379 /* XXX: Strictly speaking for 64-bit DWARF3 files
1380 this ought to be an 8-byte wide computation. */
1381 if (dwarf_version
== -1)
1383 printf (_("(DW_OP_call_ref in frame info)"));
1384 /* No way to tell where the next op is, so just bail. */
1385 return need_frame_base
;
1387 if (dwarf_version
== 2)
1389 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1393 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1395 printf ("DW_OP_call_ref: <0x%s>", dwarf_vmatoa ("x", uvalue
));
1397 case DW_OP_form_tls_address
:
1398 printf ("DW_OP_form_tls_address");
1400 case DW_OP_call_frame_cfa
:
1401 printf ("DW_OP_call_frame_cfa");
1403 case DW_OP_bit_piece
:
1404 printf ("DW_OP_bit_piece: ");
1405 printf (_("size: %s "),
1406 dwarf_vmatoa ("u", read_uleb128 (data
, &bytes_read
, end
)));
1408 printf (_("offset: %s "),
1409 dwarf_vmatoa ("u", read_uleb128 (data
, &bytes_read
, end
)));
1413 /* DWARF 4 extensions. */
1414 case DW_OP_stack_value
:
1415 printf ("DW_OP_stack_value");
1418 case DW_OP_implicit_value
:
1419 printf ("DW_OP_implicit_value");
1420 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1422 data
= display_block (data
, uvalue
, end
, ' ');
1425 /* GNU extensions. */
1426 case DW_OP_GNU_push_tls_address
:
1427 printf (_("DW_OP_GNU_push_tls_address or DW_OP_HP_unknown"));
1429 case DW_OP_GNU_uninit
:
1430 printf ("DW_OP_GNU_uninit");
1431 /* FIXME: Is there data associated with this OP ? */
1433 case DW_OP_GNU_encoded_addr
:
1440 addr
= get_encoded_value (&data
, encoding
, section
, end
);
1442 printf ("DW_OP_GNU_encoded_addr: fmt:%02x addr:", encoding
);
1443 print_dwarf_vma (addr
, pointer_size
);
1446 case DW_OP_implicit_pointer
:
1447 case DW_OP_GNU_implicit_pointer
:
1448 /* XXX: Strictly speaking for 64-bit DWARF3 files
1449 this ought to be an 8-byte wide computation. */
1450 if (dwarf_version
== -1)
1452 printf (_("(%s in frame info)"),
1453 (op
== DW_OP_implicit_pointer
1454 ? "DW_OP_implicit_pointer"
1455 : "DW_OP_GNU_implicit_pointer"));
1456 /* No way to tell where the next op is, so just bail. */
1457 return need_frame_base
;
1459 if (dwarf_version
== 2)
1461 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1465 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1467 printf ("%s: <0x%s> %s",
1468 (op
== DW_OP_implicit_pointer
1469 ? "DW_OP_implicit_pointer" : "DW_OP_GNU_implicit_pointer"),
1470 dwarf_vmatoa ("x", uvalue
),
1471 dwarf_vmatoa ("d", read_sleb128 (data
,
1472 &bytes_read
, end
)));
1475 case DW_OP_entry_value
:
1476 case DW_OP_GNU_entry_value
:
1477 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1479 /* PR 17531: file: 0cc9cd00. */
1480 if (uvalue
> (dwarf_vma
) (end
- data
))
1481 uvalue
= end
- data
;
1482 printf ("%s: (", (op
== DW_OP_entry_value
? "DW_OP_entry_value"
1483 : "DW_OP_GNU_entry_value"));
1484 if (decode_location_expression (data
, pointer_size
, offset_size
,
1485 dwarf_version
, uvalue
,
1486 cu_offset
, section
))
1487 need_frame_base
= 1;
1493 case DW_OP_const_type
:
1494 case DW_OP_GNU_const_type
:
1495 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1497 printf ("%s: <0x%s> ",
1498 (op
== DW_OP_const_type
? "DW_OP_const_type"
1499 : "DW_OP_GNU_const_type"),
1500 dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1501 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1502 data
= display_block (data
, uvalue
, end
, ' ');
1504 case DW_OP_regval_type
:
1505 case DW_OP_GNU_regval_type
:
1506 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1508 printf ("%s: %s (%s)",
1509 (op
== DW_OP_regval_type
? "DW_OP_regval_type"
1510 : "DW_OP_GNU_regval_type"),
1511 dwarf_vmatoa ("u", uvalue
), regname (uvalue
, 1));
1512 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1514 printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1516 case DW_OP_deref_type
:
1517 case DW_OP_GNU_deref_type
:
1518 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1520 (op
== DW_OP_deref_type
? "DW_OP_deref_type"
1521 : "DW_OP_GNU_deref_type"),
1523 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1525 printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1528 case DW_OP_GNU_convert
:
1529 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1531 printf ("%s <0x%s>",
1532 (op
== DW_OP_convert
? "DW_OP_convert" : "DW_OP_GNU_convert"),
1533 dwarf_vmatoa ("x", uvalue
? cu_offset
+ uvalue
: 0));
1535 case DW_OP_reinterpret
:
1536 case DW_OP_GNU_reinterpret
:
1537 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1539 printf ("%s <0x%s>",
1540 (op
== DW_OP_reinterpret
? "DW_OP_reinterpret"
1541 : "DW_OP_GNU_reinterpret"),
1542 dwarf_vmatoa ("x", uvalue
? cu_offset
+ uvalue
: 0));
1544 case DW_OP_GNU_parameter_ref
:
1545 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1546 printf ("DW_OP_GNU_parameter_ref: <0x%s>",
1547 dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1549 case DW_OP_GNU_addr_index
:
1550 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1552 printf ("DW_OP_GNU_addr_index <0x%s>", dwarf_vmatoa ("x", uvalue
));
1554 case DW_OP_GNU_const_index
:
1555 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1557 printf ("DW_OP_GNU_const_index <0x%s>", dwarf_vmatoa ("x", uvalue
));
1560 /* HP extensions. */
1561 case DW_OP_HP_is_value
:
1562 printf ("DW_OP_HP_is_value");
1563 /* FIXME: Is there data associated with this OP ? */
1565 case DW_OP_HP_fltconst4
:
1566 printf ("DW_OP_HP_fltconst4");
1567 /* FIXME: Is there data associated with this OP ? */
1569 case DW_OP_HP_fltconst8
:
1570 printf ("DW_OP_HP_fltconst8");
1571 /* FIXME: Is there data associated with this OP ? */
1573 case DW_OP_HP_mod_range
:
1574 printf ("DW_OP_HP_mod_range");
1575 /* FIXME: Is there data associated with this OP ? */
1577 case DW_OP_HP_unmod_range
:
1578 printf ("DW_OP_HP_unmod_range");
1579 /* FIXME: Is there data associated with this OP ? */
1582 printf ("DW_OP_HP_tls");
1583 /* FIXME: Is there data associated with this OP ? */
1586 /* PGI (STMicroelectronics) extensions. */
1587 case DW_OP_PGI_omp_thread_num
:
1588 /* Pushes the thread number for the current thread as it would be
1589 returned by the standard OpenMP library function:
1590 omp_get_thread_num(). The "current thread" is the thread for
1591 which the expression is being evaluated. */
1592 printf ("DW_OP_PGI_omp_thread_num");
1596 if (op
>= DW_OP_lo_user
1597 && op
<= DW_OP_hi_user
)
1598 printf (_("(User defined location op 0x%x)"), op
);
1600 printf (_("(Unknown location op 0x%x)"), op
);
1601 /* No way to tell where the next op is, so just bail. */
1602 return need_frame_base
;
1605 /* Separate the ops. */
1610 return need_frame_base
;
1613 /* Find the CU or TU set corresponding to the given CU_OFFSET.
1614 This is used for DWARF package files. */
1616 static struct cu_tu_set
*
1617 find_cu_tu_set_v2 (dwarf_vma cu_offset
, int do_types
)
1619 struct cu_tu_set
*p
;
1621 unsigned int dw_sect
;
1627 dw_sect
= DW_SECT_TYPES
;
1633 dw_sect
= DW_SECT_INFO
;
1637 if (p
->section_offsets
[dw_sect
] == cu_offset
)
1645 /* Add INC to HIGH_BITS:LOW_BITS. */
1647 add64 (dwarf_vma
* high_bits
, dwarf_vma
* low_bits
, dwarf_vma inc
)
1649 dwarf_vma tmp
= * low_bits
;
1653 /* FIXME: There is probably a better way of handling this:
1655 We need to cope with dwarf_vma being a 32-bit or 64-bit
1656 type. Plus regardless of its size LOW_BITS is meant to
1657 only hold 32-bits, so if there is overflow or wrap around
1658 we must propagate into HIGH_BITS. */
1659 if (tmp
< * low_bits
)
1663 else if (sizeof (tmp
) > 8
1673 static unsigned char *
1674 read_and_display_attr_value (unsigned long attribute
,
1676 dwarf_signed_vma implicit_const
,
1677 unsigned char * data
,
1678 unsigned char * end
,
1679 dwarf_vma cu_offset
,
1680 dwarf_vma pointer_size
,
1681 dwarf_vma offset_size
,
1683 debug_info
* debug_info_p
,
1685 struct dwarf_section
* section
,
1686 struct cu_tu_set
* this_set
, char delimiter
)
1688 dwarf_vma uvalue
= 0;
1689 unsigned char *block_start
= NULL
;
1690 unsigned char * orig_data
= data
;
1691 unsigned int bytes_read
;
1693 if (data
> end
|| (data
== end
&& form
!= DW_FORM_flag_present
))
1695 warn (_("Corrupt attribute\n"));
1704 case DW_FORM_ref_addr
:
1705 if (dwarf_version
== 2)
1706 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1707 else if (dwarf_version
== 3 || dwarf_version
== 4)
1708 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1710 error (_("Internal error: DWARF version is not 2, 3 or 4.\n"));
1715 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1719 case DW_FORM_line_strp
:
1720 case DW_FORM_sec_offset
:
1721 case DW_FORM_GNU_ref_alt
:
1722 case DW_FORM_GNU_strp_alt
:
1723 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1726 case DW_FORM_flag_present
:
1733 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1738 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
1743 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1747 uvalue
= read_sleb128 (data
, & bytes_read
, end
);
1751 case DW_FORM_GNU_str_index
:
1752 uvalue
= read_uleb128 (data
, & bytes_read
, end
);
1756 case DW_FORM_ref_udata
:
1758 uvalue
= read_uleb128 (data
, & bytes_read
, end
);
1762 case DW_FORM_indirect
:
1763 form
= read_uleb128 (data
, & bytes_read
, end
);
1766 printf ("%c%s", delimiter
, get_FORM_name (form
));
1767 if (form
== DW_FORM_implicit_const
)
1769 implicit_const
= read_sleb128 (data
, & bytes_read
, end
);
1772 return read_and_display_attr_value (attribute
, form
, implicit_const
, data
,
1773 end
, cu_offset
, pointer_size
,
1774 offset_size
, dwarf_version
,
1775 debug_info_p
, do_loc
,
1776 section
, this_set
, delimiter
);
1777 case DW_FORM_GNU_addr_index
:
1778 uvalue
= read_uleb128 (data
, & bytes_read
, end
);
1785 case DW_FORM_ref_addr
:
1787 printf ("%c<0x%s>", delimiter
, dwarf_vmatoa ("x",uvalue
));
1790 case DW_FORM_GNU_ref_alt
:
1792 printf ("%c<alt 0x%s>", delimiter
, dwarf_vmatoa ("x",uvalue
));
1798 case DW_FORM_ref_udata
:
1800 printf ("%c<0x%s>", delimiter
, dwarf_vmatoa ("x", uvalue
+ cu_offset
));
1805 case DW_FORM_sec_offset
:
1807 printf ("%c0x%s", delimiter
, dwarf_vmatoa ("x", uvalue
));
1810 case DW_FORM_flag_present
:
1817 printf ("%c%s", delimiter
, dwarf_vmatoa ("d", uvalue
));
1820 case DW_FORM_implicit_const
:
1822 printf ("%c%s", delimiter
, dwarf_vmatoa ("d", implicit_const
));
1829 dwarf_vma high_bits
;
1833 SAFE_BYTE_GET64 (data
, &high_bits
, &uvalue
, end
);
1835 if (form
== DW_FORM_ref8
)
1836 add64 (& high_bits
, & utmp
, cu_offset
);
1837 printf ("%c0x%s", delimiter
,
1838 dwarf_vmatoa64 (high_bits
, utmp
, buf
, sizeof (buf
)));
1841 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
1842 && num_debug_info_entries
== 0)
1844 if (sizeof (uvalue
) == 8)
1845 SAFE_BYTE_GET (uvalue
, data
, 8, end
);
1847 error (_("DW_FORM_data8 is unsupported when sizeof (dwarf_vma) != 8\n"));
1853 case DW_FORM_data16
:
1856 dwarf_vma left_high_bits
, left_low_bits
;
1857 dwarf_vma right_high_bits
, right_low_bits
;
1859 SAFE_BYTE_GET64 (data
, &left_high_bits
, &left_low_bits
, end
);
1860 SAFE_BYTE_GET64 (data
+ 8, &right_high_bits
, &right_low_bits
, end
);
1861 if (byte_get
== byte_get_little_endian
)
1864 left_high_bits
^= right_high_bits
;
1865 right_high_bits
^= left_high_bits
;
1866 left_high_bits
^= right_high_bits
;
1867 left_low_bits
^= right_low_bits
;
1868 right_low_bits
^= left_low_bits
;
1869 left_low_bits
^= right_low_bits
;
1871 printf (" 0x%08" DWARF_VMA_FMT
"x%08" DWARF_VMA_FMT
"x"
1872 "%08" DWARF_VMA_FMT
"x%08" DWARF_VMA_FMT
"x",
1873 left_high_bits
, left_low_bits
, right_high_bits
,
1879 case DW_FORM_string
:
1881 printf ("%c%.*s", delimiter
, (int) (end
- data
), data
);
1882 data
+= strnlen ((char *) data
, end
- data
) + 1;
1886 case DW_FORM_exprloc
:
1887 uvalue
= read_uleb128 (data
, & bytes_read
, end
);
1888 block_start
= data
+ bytes_read
;
1889 if (block_start
>= end
)
1891 warn (_("Block ends prematurely\n"));
1895 /* FIXME: Testing "(block_start + uvalue) < block_start" miscompiles with
1896 gcc 4.8.3 running on an x86_64 host in 32-bit mode. So we pre-compute
1897 block_start + uvalue here. */
1898 data
= block_start
+ uvalue
;
1899 /* PR 17512: file: 008-103549-0.001:0.1. */
1900 if (block_start
+ uvalue
> end
|| data
< block_start
)
1902 warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue
);
1903 uvalue
= end
- block_start
;
1906 data
= block_start
+ uvalue
;
1908 data
= display_block (block_start
, uvalue
, end
, delimiter
);
1911 case DW_FORM_block1
:
1912 SAFE_BYTE_GET (uvalue
, data
, 1, end
);
1913 block_start
= data
+ 1;
1914 if (block_start
>= end
)
1916 warn (_("Block ends prematurely\n"));
1920 data
= block_start
+ uvalue
;
1921 if (block_start
+ uvalue
> end
|| data
< block_start
)
1923 warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue
);
1924 uvalue
= end
- block_start
;
1927 data
= block_start
+ uvalue
;
1929 data
= display_block (block_start
, uvalue
, end
, delimiter
);
1932 case DW_FORM_block2
:
1933 SAFE_BYTE_GET (uvalue
, data
, 2, end
);
1934 block_start
= data
+ 2;
1935 if (block_start
>= end
)
1937 warn (_("Block ends prematurely\n"));
1941 data
= block_start
+ uvalue
;
1942 if (block_start
+ uvalue
> end
|| data
< block_start
)
1944 warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue
);
1945 uvalue
= end
- block_start
;
1948 data
= block_start
+ uvalue
;
1950 data
= display_block (block_start
, uvalue
, end
, delimiter
);
1953 case DW_FORM_block4
:
1954 SAFE_BYTE_GET (uvalue
, data
, 4, end
);
1955 block_start
= data
+ 4;
1956 /* PR 17512: file: 3371-3907-0.004. */
1957 if (block_start
>= end
)
1959 warn (_("Block ends prematurely\n"));
1963 data
= block_start
+ uvalue
;
1964 if (block_start
+ uvalue
> end
1965 /* PR 17531: file: 5b5f0592. */
1966 || data
< block_start
)
1968 warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue
);
1969 uvalue
= end
- block_start
;
1972 data
= block_start
+ uvalue
;
1974 data
= display_block (block_start
, uvalue
, end
, delimiter
);
1979 printf (_("%c(indirect string, offset: 0x%s): %s"), delimiter
,
1980 dwarf_vmatoa ("x", uvalue
),
1981 fetch_indirect_string (uvalue
));
1984 case DW_FORM_line_strp
:
1986 printf (_("%c(indirect line string, offset: 0x%s): %s"), delimiter
,
1987 dwarf_vmatoa ("x", uvalue
),
1988 fetch_indirect_line_string (uvalue
));
1991 case DW_FORM_GNU_str_index
:
1994 const char *suffix
= strrchr (section
->name
, '.');
1995 int dwo
= (suffix
&& strcmp (suffix
, ".dwo") == 0) ? 1 : 0;
1997 printf (_("%c(indexed string: 0x%s): %s"), delimiter
,
1998 dwarf_vmatoa ("x", uvalue
),
1999 fetch_indexed_string (uvalue
, this_set
, offset_size
, dwo
));
2003 case DW_FORM_GNU_strp_alt
:
2005 printf (_("%c(alt indirect string, offset: 0x%s)"), delimiter
,
2006 dwarf_vmatoa ("x", uvalue
));
2009 case DW_FORM_indirect
:
2010 /* Handled above. */
2013 case DW_FORM_ref_sig8
:
2016 dwarf_vma high_bits
;
2019 SAFE_BYTE_GET64 (data
, &high_bits
, &uvalue
, end
);
2020 printf ("%csignature: 0x%s", delimiter
,
2021 dwarf_vmatoa64 (high_bits
, uvalue
, buf
, sizeof (buf
)));
2026 case DW_FORM_GNU_addr_index
:
2028 printf (_("%c(addr_index: 0x%s): %s"), delimiter
,
2029 dwarf_vmatoa ("x", uvalue
),
2030 fetch_indexed_value (uvalue
* pointer_size
, pointer_size
));
2034 warn (_("Unrecognized form: %lu\n"), form
);
2038 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
2039 && num_debug_info_entries
== 0
2040 && debug_info_p
!= NULL
)
2044 case DW_AT_frame_base
:
2045 have_frame_base
= 1;
2047 case DW_AT_location
:
2048 case DW_AT_GNU_locviews
:
2049 case DW_AT_string_length
:
2050 case DW_AT_return_addr
:
2051 case DW_AT_data_member_location
:
2052 case DW_AT_vtable_elem_location
:
2054 case DW_AT_static_link
:
2055 case DW_AT_use_location
:
2056 case DW_AT_call_value
:
2057 case DW_AT_GNU_call_site_value
:
2058 case DW_AT_call_data_value
:
2059 case DW_AT_GNU_call_site_data_value
:
2060 case DW_AT_call_target
:
2061 case DW_AT_GNU_call_site_target
:
2062 case DW_AT_call_target_clobbered
:
2063 case DW_AT_GNU_call_site_target_clobbered
:
2064 if ((dwarf_version
< 4
2065 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
2066 || form
== DW_FORM_sec_offset
)
2068 /* Process location list. */
2069 unsigned int lmax
= debug_info_p
->max_loc_offsets
;
2070 unsigned int num
= debug_info_p
->num_loc_offsets
;
2072 if (lmax
== 0 || num
>= lmax
)
2075 debug_info_p
->loc_offsets
= (dwarf_vma
*)
2076 xcrealloc (debug_info_p
->loc_offsets
,
2077 lmax
, sizeof (*debug_info_p
->loc_offsets
));
2078 debug_info_p
->loc_views
= (dwarf_vma
*)
2079 xcrealloc (debug_info_p
->loc_views
,
2080 lmax
, sizeof (*debug_info_p
->loc_views
));
2081 debug_info_p
->have_frame_base
= (int *)
2082 xcrealloc (debug_info_p
->have_frame_base
,
2083 lmax
, sizeof (*debug_info_p
->have_frame_base
));
2084 debug_info_p
->max_loc_offsets
= lmax
;
2086 if (this_set
!= NULL
)
2087 uvalue
+= this_set
->section_offsets
[DW_SECT_LOC
];
2088 debug_info_p
->have_frame_base
[num
] = have_frame_base
;
2089 if (attribute
!= DW_AT_GNU_locviews
)
2091 debug_info_p
->loc_offsets
[num
] = uvalue
;
2092 debug_info_p
->num_loc_offsets
++;
2093 assert (debug_info_p
->num_loc_offsets
2094 - debug_info_p
->num_loc_views
<= 1);
2098 assert (debug_info_p
->num_loc_views
<= num
);
2099 num
= debug_info_p
->num_loc_views
;
2100 debug_info_p
->loc_views
[num
] = uvalue
;
2101 debug_info_p
->num_loc_views
++;
2102 assert (debug_info_p
->num_loc_views
2103 - debug_info_p
->num_loc_offsets
<= 1);
2109 if (need_base_address
)
2110 debug_info_p
->base_address
= uvalue
;
2113 case DW_AT_GNU_addr_base
:
2114 debug_info_p
->addr_base
= uvalue
;
2117 case DW_AT_GNU_ranges_base
:
2118 debug_info_p
->ranges_base
= uvalue
;
2122 if ((dwarf_version
< 4
2123 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
2124 || form
== DW_FORM_sec_offset
)
2126 /* Process range list. */
2127 unsigned int lmax
= debug_info_p
->max_range_lists
;
2128 unsigned int num
= debug_info_p
->num_range_lists
;
2130 if (lmax
== 0 || num
>= lmax
)
2133 debug_info_p
->range_lists
= (dwarf_vma
*)
2134 xcrealloc (debug_info_p
->range_lists
,
2135 lmax
, sizeof (*debug_info_p
->range_lists
));
2136 debug_info_p
->max_range_lists
= lmax
;
2138 debug_info_p
->range_lists
[num
] = uvalue
;
2139 debug_info_p
->num_range_lists
++;
2148 if (do_loc
|| attribute
== 0)
2151 /* For some attributes we can display further information. */
2158 case DW_INL_not_inlined
:
2159 printf (_("(not inlined)"));
2161 case DW_INL_inlined
:
2162 printf (_("(inlined)"));
2164 case DW_INL_declared_not_inlined
:
2165 printf (_("(declared as inline but ignored)"));
2167 case DW_INL_declared_inlined
:
2168 printf (_("(declared as inline and inlined)"));
2171 printf (_(" (Unknown inline attribute value: %s)"),
2172 dwarf_vmatoa ("x", uvalue
));
2177 case DW_AT_language
:
2181 /* Ordered by the numeric value of these constants. */
2182 case DW_LANG_C89
: printf ("(ANSI C)"); break;
2183 case DW_LANG_C
: printf ("(non-ANSI C)"); break;
2184 case DW_LANG_Ada83
: printf ("(Ada)"); break;
2185 case DW_LANG_C_plus_plus
: printf ("(C++)"); break;
2186 case DW_LANG_Cobol74
: printf ("(Cobol 74)"); break;
2187 case DW_LANG_Cobol85
: printf ("(Cobol 85)"); break;
2188 case DW_LANG_Fortran77
: printf ("(FORTRAN 77)"); break;
2189 case DW_LANG_Fortran90
: printf ("(Fortran 90)"); break;
2190 case DW_LANG_Pascal83
: printf ("(ANSI Pascal)"); break;
2191 case DW_LANG_Modula2
: printf ("(Modula 2)"); break;
2192 /* DWARF 2.1 values. */
2193 case DW_LANG_Java
: printf ("(Java)"); break;
2194 case DW_LANG_C99
: printf ("(ANSI C99)"); break;
2195 case DW_LANG_Ada95
: printf ("(ADA 95)"); break;
2196 case DW_LANG_Fortran95
: printf ("(Fortran 95)"); break;
2197 /* DWARF 3 values. */
2198 case DW_LANG_PLI
: printf ("(PLI)"); break;
2199 case DW_LANG_ObjC
: printf ("(Objective C)"); break;
2200 case DW_LANG_ObjC_plus_plus
: printf ("(Objective C++)"); break;
2201 case DW_LANG_UPC
: printf ("(Unified Parallel C)"); break;
2202 case DW_LANG_D
: printf ("(D)"); break;
2203 /* DWARF 4 values. */
2204 case DW_LANG_Python
: printf ("(Python)"); break;
2205 /* DWARF 5 values. */
2206 case DW_LANG_Go
: printf ("(Go)"); break;
2207 case DW_LANG_C_plus_plus_11
: printf ("(C++11)"); break;
2208 case DW_LANG_C11
: printf ("(C11)"); break;
2209 case DW_LANG_C_plus_plus_14
: printf ("(C++14)"); break;
2210 case DW_LANG_Fortran03
: printf ("(Fortran 03)"); break;
2211 case DW_LANG_Fortran08
: printf ("(Fortran 08)"); break;
2212 /* MIPS extension. */
2213 case DW_LANG_Mips_Assembler
: printf ("(MIPS assembler)"); break;
2214 /* UPC extension. */
2215 case DW_LANG_Upc
: printf ("(Unified Parallel C)"); break;
2217 if (uvalue
>= DW_LANG_lo_user
&& uvalue
<= DW_LANG_hi_user
)
2218 printf (_("(implementation defined: %s)"),
2219 dwarf_vmatoa ("x", uvalue
));
2221 printf (_("(Unknown: %s)"), dwarf_vmatoa ("x", uvalue
));
2226 case DW_AT_encoding
:
2230 case DW_ATE_void
: printf ("(void)"); break;
2231 case DW_ATE_address
: printf ("(machine address)"); break;
2232 case DW_ATE_boolean
: printf ("(boolean)"); break;
2233 case DW_ATE_complex_float
: printf ("(complex float)"); break;
2234 case DW_ATE_float
: printf ("(float)"); break;
2235 case DW_ATE_signed
: printf ("(signed)"); break;
2236 case DW_ATE_signed_char
: printf ("(signed char)"); break;
2237 case DW_ATE_unsigned
: printf ("(unsigned)"); break;
2238 case DW_ATE_unsigned_char
: printf ("(unsigned char)"); break;
2239 /* DWARF 2.1 values: */
2240 case DW_ATE_imaginary_float
: printf ("(imaginary float)"); break;
2241 case DW_ATE_decimal_float
: printf ("(decimal float)"); break;
2242 /* DWARF 3 values: */
2243 case DW_ATE_packed_decimal
: printf ("(packed_decimal)"); break;
2244 case DW_ATE_numeric_string
: printf ("(numeric_string)"); break;
2245 case DW_ATE_edited
: printf ("(edited)"); break;
2246 case DW_ATE_signed_fixed
: printf ("(signed_fixed)"); break;
2247 case DW_ATE_unsigned_fixed
: printf ("(unsigned_fixed)"); break;
2248 /* DWARF 4 values: */
2249 case DW_ATE_UTF
: printf ("(unicode string)"); break;
2250 /* DWARF 5 values: */
2251 case DW_ATE_UCS
: printf ("(UCS)"); break;
2252 case DW_ATE_ASCII
: printf ("(ASCII)"); break;
2254 /* HP extensions: */
2255 case DW_ATE_HP_float80
: printf ("(HP_float80)"); break;
2256 case DW_ATE_HP_complex_float80
: printf ("(HP_complex_float80)"); break;
2257 case DW_ATE_HP_float128
: printf ("(HP_float128)"); break;
2258 case DW_ATE_HP_complex_float128
:printf ("(HP_complex_float128)"); break;
2259 case DW_ATE_HP_floathpintel
: printf ("(HP_floathpintel)"); break;
2260 case DW_ATE_HP_imaginary_float80
: printf ("(HP_imaginary_float80)"); break;
2261 case DW_ATE_HP_imaginary_float128
: printf ("(HP_imaginary_float128)"); break;
2264 if (uvalue
>= DW_ATE_lo_user
2265 && uvalue
<= DW_ATE_hi_user
)
2266 printf (_("(user defined type)"));
2268 printf (_("(unknown type)"));
2273 case DW_AT_accessibility
:
2277 case DW_ACCESS_public
: printf ("(public)"); break;
2278 case DW_ACCESS_protected
: printf ("(protected)"); break;
2279 case DW_ACCESS_private
: printf ("(private)"); break;
2281 printf (_("(unknown accessibility)"));
2286 case DW_AT_visibility
:
2290 case DW_VIS_local
: printf ("(local)"); break;
2291 case DW_VIS_exported
: printf ("(exported)"); break;
2292 case DW_VIS_qualified
: printf ("(qualified)"); break;
2293 default: printf (_("(unknown visibility)")); break;
2297 case DW_AT_endianity
:
2301 case DW_END_default
: printf ("(default)"); break;
2302 case DW_END_big
: printf ("(big)"); break;
2303 case DW_END_little
: printf ("(little)"); break;
2305 if (uvalue
>= DW_END_lo_user
&& uvalue
<= DW_END_hi_user
)
2306 printf (_("(user specified)"));
2308 printf (_("(unknown endianity)"));
2313 case DW_AT_virtuality
:
2317 case DW_VIRTUALITY_none
: printf ("(none)"); break;
2318 case DW_VIRTUALITY_virtual
: printf ("(virtual)"); break;
2319 case DW_VIRTUALITY_pure_virtual
:printf ("(pure_virtual)"); break;
2320 default: printf (_("(unknown virtuality)")); break;
2324 case DW_AT_identifier_case
:
2328 case DW_ID_case_sensitive
: printf ("(case_sensitive)"); break;
2329 case DW_ID_up_case
: printf ("(up_case)"); break;
2330 case DW_ID_down_case
: printf ("(down_case)"); break;
2331 case DW_ID_case_insensitive
: printf ("(case_insensitive)"); break;
2332 default: printf (_("(unknown case)")); break;
2336 case DW_AT_calling_convention
:
2340 case DW_CC_normal
: printf ("(normal)"); break;
2341 case DW_CC_program
: printf ("(program)"); break;
2342 case DW_CC_nocall
: printf ("(nocall)"); break;
2343 case DW_CC_pass_by_reference
: printf ("(pass by ref)"); break;
2344 case DW_CC_pass_by_value
: printf ("(pass by value)"); break;
2345 case DW_CC_GNU_renesas_sh
: printf ("(Rensas SH)"); break;
2346 case DW_CC_GNU_borland_fastcall_i386
: printf ("(Borland fastcall i386)"); break;
2348 if (uvalue
>= DW_CC_lo_user
2349 && uvalue
<= DW_CC_hi_user
)
2350 printf (_("(user defined)"));
2352 printf (_("(unknown convention)"));
2356 case DW_AT_ordering
:
2361 case -1: printf (_("(undefined)")); break;
2362 case 0: printf ("(row major)"); break;
2363 case 1: printf ("(column major)"); break;
2367 case DW_AT_decimal_sign
:
2371 case DW_DS_unsigned
: printf (_("(unsigned)")); break;
2372 case DW_DS_leading_overpunch
: printf (_("(leading overpunch)")); break;
2373 case DW_DS_trailing_overpunch
: printf (_("(trailing overpunch)")); break;
2374 case DW_DS_leading_separate
: printf (_("(leading separate)")); break;
2375 case DW_DS_trailing_separate
: printf (_("(trailing separate)")); break;
2376 default: printf (_("(unrecognised)")); break;
2380 case DW_AT_defaulted
:
2384 case DW_DEFAULTED_no
: printf (_("(no)")); break;
2385 case DW_DEFAULTED_in_class
: printf (_("(in class)")); break;
2386 case DW_DEFAULTED_out_of_class
: printf (_("(out of class)")); break;
2387 default: printf (_("(unrecognised)")); break;
2391 case DW_AT_discr_list
:
2395 case DW_DSC_label
: printf (_("(label)")); break;
2396 case DW_DSC_range
: printf (_("(range)")); break;
2397 default: printf (_("(unrecognised)")); break;
2401 case DW_AT_frame_base
:
2402 have_frame_base
= 1;
2404 case DW_AT_location
:
2405 case DW_AT_string_length
:
2406 case DW_AT_return_addr
:
2407 case DW_AT_data_member_location
:
2408 case DW_AT_vtable_elem_location
:
2410 case DW_AT_static_link
:
2411 case DW_AT_use_location
:
2412 case DW_AT_call_value
:
2413 case DW_AT_GNU_call_site_value
:
2414 case DW_AT_call_data_value
:
2415 case DW_AT_GNU_call_site_data_value
:
2416 case DW_AT_call_target
:
2417 case DW_AT_GNU_call_site_target
:
2418 case DW_AT_call_target_clobbered
:
2419 case DW_AT_GNU_call_site_target_clobbered
:
2420 if ((dwarf_version
< 4
2421 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
2422 || form
== DW_FORM_sec_offset
)
2423 printf (_(" (location list)"));
2425 case DW_AT_allocated
:
2426 case DW_AT_associated
:
2427 case DW_AT_data_location
:
2429 case DW_AT_upper_bound
:
2430 case DW_AT_lower_bound
:
2433 int need_frame_base
;
2436 need_frame_base
= decode_location_expression (block_start
,
2441 cu_offset
, section
);
2443 if (need_frame_base
&& !have_frame_base
)
2444 printf (_(" [without DW_AT_frame_base]"));
2450 if (form
== DW_FORM_ref_sig8
2451 || form
== DW_FORM_GNU_ref_alt
)
2454 if (form
== DW_FORM_ref1
2455 || form
== DW_FORM_ref2
2456 || form
== DW_FORM_ref4
2457 || form
== DW_FORM_ref_udata
)
2458 uvalue
+= cu_offset
;
2460 if (uvalue
>= section
->size
)
2461 warn (_("Offset %s used as value for DW_AT_import attribute of DIE at offset 0x%lx is too big.\n"),
2462 dwarf_vmatoa ("x", uvalue
),
2463 (unsigned long) (orig_data
- section
->start
));
2466 unsigned long abbrev_number
;
2467 abbrev_entry
* entry
;
2469 abbrev_number
= read_uleb128 (section
->start
+ uvalue
, NULL
, end
);
2471 printf (_("\t[Abbrev Number: %ld"), abbrev_number
);
2472 /* Don't look up abbrev for DW_FORM_ref_addr, as it very often will
2473 use different abbrev table, and we don't track .debug_info chunks
2475 if (form
!= DW_FORM_ref_addr
)
2477 for (entry
= first_abbrev
; entry
!= NULL
; entry
= entry
->next
)
2478 if (entry
->entry
== abbrev_number
)
2481 printf (" (%s)", get_TAG_name (entry
->tag
));
2496 get_AT_name (unsigned long attribute
)
2501 return "DW_AT value: 0";
2503 /* One value is shared by the MIPS and HP extensions: */
2504 if (attribute
== DW_AT_MIPS_fde
)
2505 return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable";
2507 name
= get_DW_AT_name (attribute
);
2511 static char buffer
[100];
2513 snprintf (buffer
, sizeof (buffer
), _("Unknown AT value: %lx"),
2521 static unsigned char *
2522 read_and_display_attr (unsigned long attribute
,
2524 dwarf_signed_vma implicit_const
,
2525 unsigned char * data
,
2526 unsigned char * end
,
2527 dwarf_vma cu_offset
,
2528 dwarf_vma pointer_size
,
2529 dwarf_vma offset_size
,
2531 debug_info
* debug_info_p
,
2533 struct dwarf_section
* section
,
2534 struct cu_tu_set
* this_set
)
2537 printf (" %-18s:", get_AT_name (attribute
));
2538 data
= read_and_display_attr_value (attribute
, form
, implicit_const
, data
, end
,
2539 cu_offset
, pointer_size
, offset_size
,
2540 dwarf_version
, debug_info_p
,
2541 do_loc
, section
, this_set
, ' ');
2547 /* Process the contents of a .debug_info section. If do_loc is non-zero
2548 then we are scanning for location lists and we do not want to display
2549 anything to the user. If do_types is non-zero, we are processing
2550 a .debug_types section instead of a .debug_info section. */
2553 process_debug_info (struct dwarf_section
*section
,
2555 enum dwarf_section_display_enum abbrev_sec
,
2559 unsigned char *start
= section
->start
;
2560 unsigned char *end
= start
+ section
->size
;
2561 unsigned char *section_begin
;
2563 unsigned int num_units
= 0;
2565 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
2566 && num_debug_info_entries
== 0
2571 /* First scan the section to get the number of comp units. */
2572 for (section_begin
= start
, num_units
= 0; section_begin
< end
;
2575 /* Read the first 4 bytes. For a 32-bit DWARF section, this
2576 will be the length. For a 64-bit DWARF section, it'll be
2577 the escape code 0xffffffff followed by an 8 byte length. */
2578 SAFE_BYTE_GET (length
, section_begin
, 4, end
);
2580 if (length
== 0xffffffff)
2582 SAFE_BYTE_GET (length
, section_begin
+ 4, 8, end
);
2583 section_begin
+= length
+ 12;
2585 else if (length
>= 0xfffffff0 && length
< 0xffffffff)
2587 warn (_("Reserved length value (0x%s) found in section %s\n"),
2588 dwarf_vmatoa ("x", length
), section
->name
);
2592 section_begin
+= length
+ 4;
2594 /* Negative values are illegal, they may even cause infinite
2595 looping. This can happen if we can't accurately apply
2596 relocations to an object file, or if the file is corrupt. */
2597 if ((signed long) length
<= 0 || section_begin
< start
)
2599 warn (_("Corrupt unit length (0x%s) found in section %s\n"),
2600 dwarf_vmatoa ("x", length
), section
->name
);
2607 error (_("No comp units in %s section ?\n"), section
->name
);
2611 /* Then allocate an array to hold the information. */
2612 debug_information
= (debug_info
*) cmalloc (num_units
,
2613 sizeof (* debug_information
));
2614 if (debug_information
== NULL
)
2616 error (_("Not enough memory for a debug info array of %u entries\n"),
2618 alloc_num_debug_info_entries
= num_debug_info_entries
= 0;
2621 /* PR 17531: file: 92ca3797.
2622 We cannot rely upon the debug_information array being initialised
2623 before it is used. A corrupt file could easily contain references
2624 to a unit for which information has not been made available. So
2625 we ensure that the array is zeroed here. */
2626 memset (debug_information
, 0, num_units
* sizeof (*debug_information
));
2628 alloc_num_debug_info_entries
= num_units
;
2633 if (dwarf_start_die
== 0)
2634 printf (_("Contents of the %s section:\n\n"), section
->name
);
2636 load_debug_section (str
, file
);
2637 load_debug_section (line_str
, file
);
2638 load_debug_section (str_dwo
, file
);
2639 load_debug_section (str_index
, file
);
2640 load_debug_section (str_index_dwo
, file
);
2641 load_debug_section (debug_addr
, file
);
2644 load_debug_section (abbrev_sec
, file
);
2645 if (debug_displays
[abbrev_sec
].section
.start
== NULL
)
2647 warn (_("Unable to locate %s section!\n"),
2648 debug_displays
[abbrev_sec
].section
.name
);
2652 for (section_begin
= start
, unit
= 0; start
< end
; unit
++)
2654 DWARF2_Internal_CompUnit compunit
;
2655 unsigned char *hdrptr
;
2656 unsigned char *tags
;
2657 int level
, last_level
, saved_level
;
2658 dwarf_vma cu_offset
;
2659 unsigned long sec_off
;
2660 unsigned int offset_size
;
2661 unsigned int initial_length_size
;
2662 dwarf_vma signature_high
= 0;
2663 dwarf_vma signature_low
= 0;
2664 dwarf_vma type_offset
= 0;
2665 struct cu_tu_set
*this_set
;
2666 dwarf_vma abbrev_base
;
2671 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 4, end
);
2673 if (compunit
.cu_length
== 0xffffffff)
2675 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 8, end
);
2677 initial_length_size
= 12;
2682 initial_length_size
= 4;
2685 SAFE_BYTE_GET_AND_INC (compunit
.cu_version
, hdrptr
, 2, end
);
2687 cu_offset
= start
- section_begin
;
2689 this_set
= find_cu_tu_set_v2 (cu_offset
, do_types
);
2691 if (compunit
.cu_version
< 5)
2693 compunit
.cu_unit_type
= DW_UT_compile
;
2694 /* Initialize it due to a false compiler warning. */
2695 compunit
.cu_pointer_size
= -1;
2699 SAFE_BYTE_GET_AND_INC (compunit
.cu_unit_type
, hdrptr
, 1, end
);
2700 do_types
= (compunit
.cu_unit_type
== DW_UT_type
);
2702 SAFE_BYTE_GET_AND_INC (compunit
.cu_pointer_size
, hdrptr
, 1, end
);
2705 SAFE_BYTE_GET_AND_INC (compunit
.cu_abbrev_offset
, hdrptr
, offset_size
, end
);
2707 if (this_set
== NULL
)
2710 abbrev_size
= debug_displays
[abbrev_sec
].section
.size
;
2714 abbrev_base
= this_set
->section_offsets
[DW_SECT_ABBREV
];
2715 abbrev_size
= this_set
->section_sizes
[DW_SECT_ABBREV
];
2718 if (compunit
.cu_version
< 5)
2719 SAFE_BYTE_GET_AND_INC (compunit
.cu_pointer_size
, hdrptr
, 1, end
);
2721 /* PR 17512: file: 001-108546-0.001:0.1. */
2722 if (compunit
.cu_pointer_size
< 2 || compunit
.cu_pointer_size
> 8)
2724 warn (_("Invalid pointer size (%d) in compunit header, using %d instead\n"),
2725 compunit
.cu_pointer_size
, offset_size
);
2726 compunit
.cu_pointer_size
= offset_size
;
2731 SAFE_BYTE_GET64 (hdrptr
, &signature_high
, &signature_low
, end
);
2733 SAFE_BYTE_GET_AND_INC (type_offset
, hdrptr
, offset_size
, end
);
2736 if (dwarf_start_die
> (cu_offset
+ compunit
.cu_length
2737 + initial_length_size
))
2739 start
= section_begin
+ cu_offset
+ compunit
.cu_length
2740 + initial_length_size
;
2744 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
2745 && num_debug_info_entries
== 0
2748 debug_information
[unit
].cu_offset
= cu_offset
;
2749 debug_information
[unit
].pointer_size
2750 = compunit
.cu_pointer_size
;
2751 debug_information
[unit
].offset_size
= offset_size
;
2752 debug_information
[unit
].dwarf_version
= compunit
.cu_version
;
2753 debug_information
[unit
].base_address
= 0;
2754 debug_information
[unit
].addr_base
= DEBUG_INFO_UNAVAILABLE
;
2755 debug_information
[unit
].ranges_base
= DEBUG_INFO_UNAVAILABLE
;
2756 debug_information
[unit
].loc_offsets
= NULL
;
2757 debug_information
[unit
].have_frame_base
= NULL
;
2758 debug_information
[unit
].max_loc_offsets
= 0;
2759 debug_information
[unit
].num_loc_offsets
= 0;
2760 debug_information
[unit
].range_lists
= NULL
;
2761 debug_information
[unit
].max_range_lists
= 0;
2762 debug_information
[unit
].num_range_lists
= 0;
2765 if (!do_loc
&& dwarf_start_die
== 0)
2767 printf (_(" Compilation Unit @ offset 0x%s:\n"),
2768 dwarf_vmatoa ("x", cu_offset
));
2769 printf (_(" Length: 0x%s (%s)\n"),
2770 dwarf_vmatoa ("x", compunit
.cu_length
),
2771 offset_size
== 8 ? "64-bit" : "32-bit");
2772 printf (_(" Version: %d\n"), compunit
.cu_version
);
2773 printf (_(" Abbrev Offset: 0x%s\n"),
2774 dwarf_vmatoa ("x", compunit
.cu_abbrev_offset
));
2775 printf (_(" Pointer Size: %d\n"), compunit
.cu_pointer_size
);
2780 printf (_(" Signature: 0x%s\n"),
2781 dwarf_vmatoa64 (signature_high
, signature_low
,
2782 buf
, sizeof (buf
)));
2783 printf (_(" Type Offset: 0x%s\n"),
2784 dwarf_vmatoa ("x", type_offset
));
2786 if (this_set
!= NULL
)
2788 dwarf_vma
*offsets
= this_set
->section_offsets
;
2789 size_t *sizes
= this_set
->section_sizes
;
2791 printf (_(" Section contributions:\n"));
2792 printf (_(" .debug_abbrev.dwo: 0x%s 0x%s\n"),
2793 dwarf_vmatoa ("x", offsets
[DW_SECT_ABBREV
]),
2794 dwarf_vmatoa ("x", sizes
[DW_SECT_ABBREV
]));
2795 printf (_(" .debug_line.dwo: 0x%s 0x%s\n"),
2796 dwarf_vmatoa ("x", offsets
[DW_SECT_LINE
]),
2797 dwarf_vmatoa ("x", sizes
[DW_SECT_LINE
]));
2798 printf (_(" .debug_loc.dwo: 0x%s 0x%s\n"),
2799 dwarf_vmatoa ("x", offsets
[DW_SECT_LOC
]),
2800 dwarf_vmatoa ("x", sizes
[DW_SECT_LOC
]));
2801 printf (_(" .debug_str_offsets.dwo: 0x%s 0x%s\n"),
2802 dwarf_vmatoa ("x", offsets
[DW_SECT_STR_OFFSETS
]),
2803 dwarf_vmatoa ("x", sizes
[DW_SECT_STR_OFFSETS
]));
2807 sec_off
= cu_offset
+ initial_length_size
;
2808 if (sec_off
+ compunit
.cu_length
< sec_off
2809 || sec_off
+ compunit
.cu_length
> section
->size
)
2811 warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"),
2813 (unsigned long) cu_offset
,
2814 dwarf_vmatoa ("x", compunit
.cu_length
));
2820 start
+= compunit
.cu_length
+ initial_length_size
;
2822 if (compunit
.cu_version
< 2 || compunit
.cu_version
> 5)
2824 warn (_("CU at offset %s contains corrupt or "
2825 "unsupported version number: %d.\n"),
2826 dwarf_vmatoa ("x", cu_offset
), compunit
.cu_version
);
2830 if (compunit
.cu_unit_type
!= DW_UT_compile
2831 && compunit
.cu_unit_type
!= DW_UT_type
)
2833 warn (_("CU at offset %s contains corrupt or "
2834 "unsupported unit type: %d.\n"),
2835 dwarf_vmatoa ("x", cu_offset
), compunit
.cu_unit_type
);
2841 /* Process the abbrevs used by this compilation unit. */
2842 if (compunit
.cu_abbrev_offset
>= abbrev_size
)
2843 warn (_("Debug info is corrupted, abbrev offset (%lx) is larger than abbrev section size (%lx)\n"),
2844 (unsigned long) compunit
.cu_abbrev_offset
,
2845 (unsigned long) abbrev_size
);
2846 /* PR 17531: file:4bcd9ce9. */
2847 else if ((abbrev_base
+ abbrev_size
)
2848 > debug_displays
[abbrev_sec
].section
.size
)
2849 warn (_("Debug info is corrupted, abbrev size (%lx) is larger than abbrev section size (%lx)\n"),
2850 (unsigned long) abbrev_base
+ abbrev_size
,
2851 (unsigned long) debug_displays
[abbrev_sec
].section
.size
);
2853 process_abbrev_section
2854 (((unsigned char *) debug_displays
[abbrev_sec
].section
.start
2855 + abbrev_base
+ compunit
.cu_abbrev_offset
),
2856 ((unsigned char *) debug_displays
[abbrev_sec
].section
.start
2857 + abbrev_base
+ abbrev_size
));
2862 while (tags
< start
)
2864 unsigned int bytes_read
;
2865 unsigned long abbrev_number
;
2866 unsigned long die_offset
;
2867 abbrev_entry
*entry
;
2869 int do_printing
= 1;
2871 die_offset
= tags
- section_begin
;
2873 abbrev_number
= read_uleb128 (tags
, & bytes_read
, start
);
2876 /* A null DIE marks the end of a list of siblings or it may also be
2877 a section padding. */
2878 if (abbrev_number
== 0)
2880 /* Check if it can be a section padding for the last CU. */
2881 if (level
== 0 && start
== end
)
2885 for (chk
= tags
; chk
< start
; chk
++)
2892 if (!do_loc
&& die_offset
>= dwarf_start_die
2893 && (dwarf_cutoff_level
== -1
2894 || level
< dwarf_cutoff_level
))
2895 printf (_(" <%d><%lx>: Abbrev Number: 0\n"),
2901 static unsigned num_bogus_warns
= 0;
2903 if (num_bogus_warns
< 3)
2905 warn (_("Bogus end-of-siblings marker detected at offset %lx in %s section\n"),
2906 die_offset
, section
->name
);
2908 if (num_bogus_warns
== 3)
2909 warn (_("Further warnings about bogus end-of-sibling markers suppressed\n"));
2912 if (dwarf_start_die
!= 0 && level
< saved_level
)
2919 if (dwarf_start_die
!= 0 && die_offset
< dwarf_start_die
)
2923 if (dwarf_start_die
!= 0 && die_offset
== dwarf_start_die
)
2924 saved_level
= level
;
2925 do_printing
= (dwarf_cutoff_level
== -1
2926 || level
< dwarf_cutoff_level
);
2928 printf (_(" <%d><%lx>: Abbrev Number: %lu"),
2929 level
, die_offset
, abbrev_number
);
2930 else if (dwarf_cutoff_level
== -1
2931 || last_level
< dwarf_cutoff_level
)
2932 printf (_(" <%d><%lx>: ...\n"), level
, die_offset
);
2937 /* Scan through the abbreviation list until we reach the
2939 for (entry
= first_abbrev
;
2940 entry
&& entry
->entry
!= abbrev_number
;
2941 entry
= entry
->next
)
2946 if (!do_loc
&& do_printing
)
2951 warn (_("DIE at offset 0x%lx refers to abbreviation number %lu which does not exist\n"),
2952 die_offset
, abbrev_number
);
2956 if (!do_loc
&& do_printing
)
2957 printf (" (%s)\n", get_TAG_name (entry
->tag
));
2962 need_base_address
= 0;
2964 case DW_TAG_compile_unit
:
2965 need_base_address
= 1;
2967 case DW_TAG_entry_point
:
2968 case DW_TAG_subprogram
:
2969 need_base_address
= 0;
2970 /* Assuming that there is no DW_AT_frame_base. */
2971 have_frame_base
= 0;
2975 debug_info
*debug_info_p
=
2976 (debug_information
&& unit
< alloc_num_debug_info_entries
)
2977 ? debug_information
+ unit
: NULL
;
2979 assert (!debug_info_p
2980 || (debug_info_p
->num_loc_offsets
2981 == debug_info_p
->num_loc_views
));
2983 for (attr
= entry
->first_attr
;
2984 attr
&& attr
->attribute
;
2987 if (! do_loc
&& do_printing
)
2988 /* Show the offset from where the tag was extracted. */
2989 printf (" <%lx>", (unsigned long)(tags
- section_begin
));
2991 tags
= read_and_display_attr (attr
->attribute
,
2993 attr
->implicit_const
,
2997 compunit
.cu_pointer_size
,
2999 compunit
.cu_version
,
3001 do_loc
|| ! do_printing
,
3006 /* If a locview attribute appears before a location one,
3007 make sure we don't associate it with an earlier
3010 switch (debug_info_p
->num_loc_offsets
- debug_info_p
->num_loc_views
)
3013 debug_info_p
->loc_views
[debug_info_p
->num_loc_views
] = vm1
;
3014 debug_info_p
->num_loc_views
++;
3015 assert (debug_info_p
->num_loc_views
3016 == debug_info_p
->num_loc_offsets
);
3023 warn(_("DIE has locviews without loclist\n"));
3024 debug_info_p
->num_loc_views
--;
3031 if (entry
->children
)
3036 /* Set num_debug_info_entries here so that it can be used to check if
3037 we need to process .debug_loc and .debug_ranges sections. */
3038 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
3039 && num_debug_info_entries
== 0
3042 if (num_units
> alloc_num_debug_info_entries
)
3043 num_debug_info_entries
= alloc_num_debug_info_entries
;
3045 num_debug_info_entries
= num_units
;
3054 /* Locate and scan the .debug_info section in the file and record the pointer
3055 sizes and offsets for the compilation units in it. Usually an executable
3056 will have just one pointer size, but this is not guaranteed, and so we try
3057 not to make any assumptions. Returns zero upon failure, or the number of
3058 compilation units upon success. */
3061 load_debug_info (void * file
)
3063 /* If we have already tried and failed to load the .debug_info
3064 section then do not bother to repeat the task. */
3065 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
3068 /* If we already have the information there is nothing else to do. */
3069 if (num_debug_info_entries
> 0)
3070 return num_debug_info_entries
;
3072 /* If this is a DWARF package file, load the CU and TU indexes. */
3073 (void) load_cu_tu_indexes (file
);
3075 if (load_debug_section (info
, file
)
3076 && process_debug_info (&debug_displays
[info
].section
, file
, abbrev
, 1, 0))
3077 return num_debug_info_entries
;
3079 if (load_debug_section (info_dwo
, file
)
3080 && process_debug_info (&debug_displays
[info_dwo
].section
, file
,
3082 return num_debug_info_entries
;
3084 num_debug_info_entries
= DEBUG_INFO_UNAVAILABLE
;
3088 /* Read a DWARF .debug_line section header starting at DATA.
3089 Upon success returns an updated DATA pointer and the LINFO
3090 structure and the END_OF_SEQUENCE pointer will be filled in.
3091 Otherwise returns NULL. */
3093 static unsigned char *
3094 read_debug_line_header (struct dwarf_section
* section
,
3095 unsigned char * data
,
3096 unsigned char * end
,
3097 DWARF2_Internal_LineInfo
* linfo
,
3098 unsigned char ** end_of_sequence
)
3100 unsigned char *hdrptr
;
3101 unsigned int initial_length_size
;
3102 unsigned char address_size
, segment_selector_size
;
3104 /* Extract information from the Line Number Program Header.
3105 (section 6.2.4 in the Dwarf3 doc). */
3108 /* Get and check the length of the block. */
3109 SAFE_BYTE_GET_AND_INC (linfo
->li_length
, hdrptr
, 4, end
);
3111 if (linfo
->li_length
== 0xffffffff)
3113 /* This section is 64-bit DWARF 3. */
3114 SAFE_BYTE_GET_AND_INC (linfo
->li_length
, hdrptr
, 8, end
);
3115 linfo
->li_offset_size
= 8;
3116 initial_length_size
= 12;
3120 linfo
->li_offset_size
= 4;
3121 initial_length_size
= 4;
3124 if (linfo
->li_length
+ initial_length_size
> section
->size
)
3126 /* If the length field has a relocation against it, then we should
3127 not complain if it is inaccurate (and probably negative). This
3128 happens in object files when the .debug_line section is actually
3129 comprised of several different .debug_line.* sections, (some of
3130 which may be removed by linker garbage collection), and a relocation
3131 is used to compute the correct length once that is done. */
3132 if (reloc_at (section
, (hdrptr
- section
->start
) - linfo
->li_offset_size
))
3134 linfo
->li_length
= (end
- data
) - initial_length_size
;
3138 warn (_("The length field (0x%lx) in the debug_line header is wrong - the section is too small\n"),
3139 (long) linfo
->li_length
);
3144 /* Get and check the version number. */
3145 SAFE_BYTE_GET_AND_INC (linfo
->li_version
, hdrptr
, 2, end
);
3147 if (linfo
->li_version
!= 2
3148 && linfo
->li_version
!= 3
3149 && linfo
->li_version
!= 4
3150 && linfo
->li_version
!= 5)
3152 warn (_("Only DWARF version 2, 3, 4 and 5 line info "
3153 "is currently supported.\n"));
3157 if (linfo
->li_version
>= 5)
3159 SAFE_BYTE_GET_AND_INC (address_size
, hdrptr
, 1, end
);
3161 SAFE_BYTE_GET_AND_INC (segment_selector_size
, hdrptr
, 1, end
);
3162 if (segment_selector_size
!= 0)
3164 warn (_("The %s section contains "
3165 "unsupported segment selector size: %d.\n"),
3166 section
->name
, segment_selector_size
);
3171 SAFE_BYTE_GET_AND_INC (linfo
->li_prologue_length
, hdrptr
,
3172 linfo
->li_offset_size
, end
);
3173 SAFE_BYTE_GET_AND_INC (linfo
->li_min_insn_length
, hdrptr
, 1, end
);
3175 if (linfo
->li_version
>= 4)
3177 SAFE_BYTE_GET_AND_INC (linfo
->li_max_ops_per_insn
, hdrptr
, 1, end
);
3179 if (linfo
->li_max_ops_per_insn
== 0)
3181 warn (_("Invalid maximum operations per insn.\n"));
3186 linfo
->li_max_ops_per_insn
= 1;
3188 SAFE_BYTE_GET_AND_INC (linfo
->li_default_is_stmt
, hdrptr
, 1, end
);
3189 SAFE_SIGNED_BYTE_GET_AND_INC (linfo
->li_line_base
, hdrptr
, 1, end
);
3190 SAFE_BYTE_GET_AND_INC (linfo
->li_line_range
, hdrptr
, 1, end
);
3191 SAFE_BYTE_GET_AND_INC (linfo
->li_opcode_base
, hdrptr
, 1, end
);
3193 * end_of_sequence
= data
+ linfo
->li_length
+ initial_length_size
;
3194 /* PR 17512: file:002-117414-0.004. */
3195 if (* end_of_sequence
> end
)
3197 warn (_("Line length %s extends beyond end of section\n"),
3198 dwarf_vmatoa ("u", linfo
->li_length
));
3199 * end_of_sequence
= end
;
3206 static unsigned char *
3207 display_formatted_table (unsigned char *data
,
3208 unsigned char *start
, unsigned char *end
,
3209 const DWARF2_Internal_LineInfo
*linfo
,
3210 struct dwarf_section
*section
, const char *what
)
3212 unsigned char *format_start
, format_count
, *format
, formati
;
3213 dwarf_vma data_count
, datai
;
3214 unsigned int bytes_read
, namepass
, last_entry
= 0;
3216 SAFE_BYTE_GET_AND_INC (format_count
, data
, 1, end
);
3217 format_start
= data
;
3218 for (formati
= 0; formati
< format_count
; formati
++)
3220 read_uleb128 (data
, & bytes_read
, end
);
3222 read_uleb128 (data
, & bytes_read
, end
);
3226 warn (_("Corrupt %s format table entry\n"), what
);
3231 data_count
= read_uleb128 (data
, & bytes_read
, end
);
3235 warn (_("Corrupt %s list\n"), what
);
3239 if (data_count
== 0)
3241 printf (_("\n The %s Table is empty.\n"), what
);
3245 printf (_("\n The %s Table (offset 0x%lx):\n"), what
,
3246 (long)(data
- start
));
3248 printf (_(" Entry"));
3249 /* Delay displaying name as the last entry for better screen layout. */
3250 for (namepass
= 0; namepass
< 2; namepass
++)
3252 format
= format_start
;
3253 for (formati
= 0; formati
< format_count
; formati
++)
3255 dwarf_vma content_type
;
3257 content_type
= read_uleb128 (format
, & bytes_read
, end
);
3258 format
+= bytes_read
;
3259 if ((content_type
== DW_LNCT_path
) == (namepass
== 1))
3260 switch (content_type
)
3263 printf (_("\tName"));
3265 case DW_LNCT_directory_index
:
3266 printf (_("\tDir"));
3268 case DW_LNCT_timestamp
:
3269 printf (_("\tTime"));
3272 printf (_("\tSize"));
3275 printf (_("\tMD5"));
3278 printf (_("\t(Unknown format content type %s)"),
3279 dwarf_vmatoa ("u", content_type
));
3281 read_uleb128 (format
, & bytes_read
, end
);
3282 format
+= bytes_read
;
3287 for (datai
= 0; datai
< data_count
; datai
++)
3289 unsigned char *datapass
= data
;
3291 printf (" %d", last_entry
++);
3292 /* Delay displaying name as the last entry for better screen layout. */
3293 for (namepass
= 0; namepass
< 2; namepass
++)
3295 format
= format_start
;
3297 for (formati
= 0; formati
< format_count
; formati
++)
3299 dwarf_vma content_type
, form
;
3301 content_type
= read_uleb128 (format
, & bytes_read
, end
);
3302 format
+= bytes_read
;
3303 form
= read_uleb128 (format
, & bytes_read
, end
);
3304 format
+= bytes_read
;
3305 data
= read_and_display_attr_value (0, form
, 0, data
, end
, 0, 0,
3306 linfo
->li_offset_size
,
3307 linfo
->li_version
, NULL
,
3308 ((content_type
== DW_LNCT_path
) != (namepass
== 1)),
3309 section
, NULL
, '\t');
3314 warn (_("Corrupt %s entries list\n"), what
);
3323 display_debug_lines_raw (struct dwarf_section
*section
,
3324 unsigned char *data
,
3325 unsigned char *end
, void *file
)
3327 unsigned char *start
= section
->start
;
3328 int verbose_view
= 0;
3330 printf (_("Raw dump of debug contents of section %s:\n\n"),
3335 static DWARF2_Internal_LineInfo saved_linfo
;
3336 DWARF2_Internal_LineInfo linfo
;
3337 unsigned char *standard_opcodes
;
3338 unsigned char *end_of_sequence
;
3341 if (const_strneq (section
->name
, ".debug_line.")
3342 /* Note: the following does not apply to .debug_line.dwo sections.
3343 These are full debug_line sections. */
3344 && strcmp (section
->name
, ".debug_line.dwo") != 0)
3346 /* Sections named .debug_line.<foo> are fragments of a .debug_line
3347 section containing just the Line Number Statements. They are
3348 created by the assembler and intended to be used alongside gcc's
3349 -ffunction-sections command line option. When the linker's
3350 garbage collection decides to discard a .text.<foo> section it
3351 can then also discard the line number information in .debug_line.<foo>.
3353 Since the section is a fragment it does not have the details
3354 needed to fill out a LineInfo structure, so instead we use the
3355 details from the last full debug_line section that we processed. */
3356 end_of_sequence
= end
;
3357 standard_opcodes
= NULL
;
3358 linfo
= saved_linfo
;
3359 /* PR 17531: file: 0522b371. */
3360 if (linfo
.li_line_range
== 0)
3362 warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n"));
3365 reset_state_machine (linfo
.li_default_is_stmt
);
3369 unsigned char * hdrptr
;
3371 if ((hdrptr
= read_debug_line_header (section
, data
, end
, & linfo
,
3372 & end_of_sequence
)) == NULL
)
3375 printf (_(" Offset: 0x%lx\n"), (long)(data
- start
));
3376 printf (_(" Length: %ld\n"), (long) linfo
.li_length
);
3377 printf (_(" DWARF Version: %d\n"), linfo
.li_version
);
3378 printf (_(" Prologue Length: %d\n"), (int) linfo
.li_prologue_length
);
3379 printf (_(" Minimum Instruction Length: %d\n"), linfo
.li_min_insn_length
);
3380 if (linfo
.li_version
>= 4)
3381 printf (_(" Maximum Ops per Instruction: %d\n"), linfo
.li_max_ops_per_insn
);
3382 printf (_(" Initial value of 'is_stmt': %d\n"), linfo
.li_default_is_stmt
);
3383 printf (_(" Line Base: %d\n"), linfo
.li_line_base
);
3384 printf (_(" Line Range: %d\n"), linfo
.li_line_range
);
3385 printf (_(" Opcode Base: %d\n"), linfo
.li_opcode_base
);
3387 /* PR 17512: file: 1665-6428-0.004. */
3388 if (linfo
.li_line_range
== 0)
3390 warn (_("Line range of 0 is invalid, using 1 instead\n"));
3391 linfo
.li_line_range
= 1;
3394 reset_state_machine (linfo
.li_default_is_stmt
);
3396 /* Display the contents of the Opcodes table. */
3397 standard_opcodes
= hdrptr
;
3399 /* PR 17512: file: 002-417945-0.004. */
3400 if (standard_opcodes
+ linfo
.li_opcode_base
>= end
)
3402 warn (_("Line Base extends beyond end of section\n"));
3406 printf (_("\n Opcodes:\n"));
3408 for (i
= 1; i
< linfo
.li_opcode_base
; i
++)
3409 printf (ngettext (" Opcode %d has %d arg\n",
3410 " Opcode %d has %d args\n",
3411 standard_opcodes
[i
- 1]),
3412 i
, standard_opcodes
[i
- 1]);
3414 /* Display the contents of the Directory table. */
3415 data
= standard_opcodes
+ linfo
.li_opcode_base
- 1;
3417 if (linfo
.li_version
>= 5)
3419 load_debug_section (line_str
, file
);
3421 data
= display_formatted_table (data
, start
, end
, &linfo
, section
,
3423 data
= display_formatted_table (data
, start
, end
, &linfo
, section
,
3429 printf (_("\n The Directory Table is empty.\n"));
3432 unsigned int last_dir_entry
= 0;
3434 printf (_("\n The Directory Table (offset 0x%lx):\n"),
3435 (long)(data
- start
));
3437 while (data
< end
&& *data
!= 0)
3439 printf (" %d\t%.*s\n", ++last_dir_entry
, (int) (end
- data
), data
);
3441 data
+= strnlen ((char *) data
, end
- data
) + 1;
3444 /* PR 17512: file: 002-132094-0.004. */
3445 if (data
>= end
- 1)
3449 /* Skip the NUL at the end of the table. */
3452 /* Display the contents of the File Name table. */
3454 printf (_("\n The File Name Table is empty.\n"));
3457 printf (_("\n The File Name Table (offset 0x%lx):\n"),
3458 (long)(data
- start
));
3459 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
3461 while (data
< end
&& *data
!= 0)
3463 unsigned char *name
;
3464 unsigned int bytes_read
;
3466 printf (" %d\t", ++state_machine_regs
.last_file_entry
);
3468 data
+= strnlen ((char *) data
, end
- data
) + 1;
3471 dwarf_vmatoa ("u", read_uleb128 (data
, & bytes_read
, end
)));
3474 dwarf_vmatoa ("u", read_uleb128 (data
, & bytes_read
, end
)));
3477 dwarf_vmatoa ("u", read_uleb128 (data
, & bytes_read
, end
)));
3479 printf ("%.*s\n", (int)(end
- name
), name
);
3483 warn (_("Corrupt file name table entry\n"));
3489 /* Skip the NUL at the end of the table. */
3494 saved_linfo
= linfo
;
3497 /* Now display the statements. */
3498 if (data
>= end_of_sequence
)
3499 printf (_(" No Line Number Statements.\n"));
3502 printf (_(" Line Number Statements:\n"));
3504 while (data
< end_of_sequence
)
3506 unsigned char op_code
;
3507 dwarf_signed_vma adv
;
3509 unsigned int bytes_read
;
3511 printf (" [0x%08lx]", (long)(data
- start
));
3515 if (op_code
>= linfo
.li_opcode_base
)
3517 op_code
-= linfo
.li_opcode_base
;
3518 uladv
= (op_code
/ linfo
.li_line_range
);
3519 if (linfo
.li_max_ops_per_insn
== 1)
3521 uladv
*= linfo
.li_min_insn_length
;
3522 state_machine_regs
.address
+= uladv
;
3524 state_machine_regs
.view
= 0;
3525 printf (_(" Special opcode %d: "
3526 "advance Address by %s to 0x%s%s"),
3527 op_code
, dwarf_vmatoa ("u", uladv
),
3528 dwarf_vmatoa ("x", state_machine_regs
.address
),
3529 verbose_view
&& uladv
3530 ? _(" (reset view)") : "");
3535 = ((state_machine_regs
.op_index
+ uladv
)
3536 / linfo
.li_max_ops_per_insn
)
3537 * linfo
.li_min_insn_length
;
3539 state_machine_regs
.address
+= addrdelta
;
3540 state_machine_regs
.op_index
3541 = (state_machine_regs
.op_index
+ uladv
)
3542 % linfo
.li_max_ops_per_insn
;
3544 state_machine_regs
.view
= 0;
3545 printf (_(" Special opcode %d: "
3546 "advance Address by %s to 0x%s[%d]%s"),
3547 op_code
, dwarf_vmatoa ("u", uladv
),
3548 dwarf_vmatoa ("x", state_machine_regs
.address
),
3549 state_machine_regs
.op_index
,
3550 verbose_view
&& addrdelta
3551 ? _(" (reset view)") : "");
3553 adv
= (op_code
% linfo
.li_line_range
) + linfo
.li_line_base
;
3554 state_machine_regs
.line
+= adv
;
3555 printf (_(" and Line by %s to %d"),
3556 dwarf_vmatoa ("d", adv
), state_machine_regs
.line
);
3557 if (verbose_view
|| state_machine_regs
.view
)
3558 printf (_(" (view %u)\n"), state_machine_regs
.view
);
3561 state_machine_regs
.view
++;
3563 else switch (op_code
)
3565 case DW_LNS_extended_op
:
3566 data
+= process_extended_line_op (data
, linfo
.li_default_is_stmt
, end
);
3570 printf (_(" Copy"));
3571 if (verbose_view
|| state_machine_regs
.view
)
3572 printf (_(" (view %u)\n"), state_machine_regs
.view
);
3575 state_machine_regs
.view
++;
3578 case DW_LNS_advance_pc
:
3579 uladv
= read_uleb128 (data
, & bytes_read
, end
);
3581 if (linfo
.li_max_ops_per_insn
== 1)
3583 uladv
*= linfo
.li_min_insn_length
;
3584 state_machine_regs
.address
+= uladv
;
3586 state_machine_regs
.view
= 0;
3587 printf (_(" Advance PC by %s to 0x%s%s\n"),
3588 dwarf_vmatoa ("u", uladv
),
3589 dwarf_vmatoa ("x", state_machine_regs
.address
),
3590 verbose_view
&& uladv
3591 ? _(" (reset view)") : "");
3596 = ((state_machine_regs
.op_index
+ uladv
)
3597 / linfo
.li_max_ops_per_insn
)
3598 * linfo
.li_min_insn_length
;
3599 state_machine_regs
.address
3601 state_machine_regs
.op_index
3602 = (state_machine_regs
.op_index
+ uladv
)
3603 % linfo
.li_max_ops_per_insn
;
3605 state_machine_regs
.view
= 0;
3606 printf (_(" Advance PC by %s to 0x%s[%d]%s\n"),
3607 dwarf_vmatoa ("u", uladv
),
3608 dwarf_vmatoa ("x", state_machine_regs
.address
),
3609 state_machine_regs
.op_index
,
3610 verbose_view
&& addrdelta
3611 ? _(" (reset view)") : "");
3615 case DW_LNS_advance_line
:
3616 adv
= read_sleb128 (data
, & bytes_read
, end
);
3618 state_machine_regs
.line
+= adv
;
3619 printf (_(" Advance Line by %s to %d\n"),
3620 dwarf_vmatoa ("d", adv
),
3621 state_machine_regs
.line
);
3624 case DW_LNS_set_file
:
3625 adv
= read_uleb128 (data
, & bytes_read
, end
);
3627 printf (_(" Set File Name to entry %s in the File Name Table\n"),
3628 dwarf_vmatoa ("d", adv
));
3629 state_machine_regs
.file
= adv
;
3632 case DW_LNS_set_column
:
3633 uladv
= read_uleb128 (data
, & bytes_read
, end
);
3635 printf (_(" Set column to %s\n"),
3636 dwarf_vmatoa ("u", uladv
));
3637 state_machine_regs
.column
= uladv
;
3640 case DW_LNS_negate_stmt
:
3641 adv
= state_machine_regs
.is_stmt
;
3643 printf (_(" Set is_stmt to %s\n"), dwarf_vmatoa ("d", adv
));
3644 state_machine_regs
.is_stmt
= adv
;
3647 case DW_LNS_set_basic_block
:
3648 printf (_(" Set basic block\n"));
3649 state_machine_regs
.basic_block
= 1;
3652 case DW_LNS_const_add_pc
:
3653 uladv
= ((255 - linfo
.li_opcode_base
) / linfo
.li_line_range
);
3654 if (linfo
.li_max_ops_per_insn
)
3656 uladv
*= linfo
.li_min_insn_length
;
3657 state_machine_regs
.address
+= uladv
;
3659 state_machine_regs
.view
= 0;
3660 printf (_(" Advance PC by constant %s to 0x%s%s\n"),
3661 dwarf_vmatoa ("u", uladv
),
3662 dwarf_vmatoa ("x", state_machine_regs
.address
),
3663 verbose_view
&& uladv
3664 ? _(" (reset view)") : "");
3669 = ((state_machine_regs
.op_index
+ uladv
)
3670 / linfo
.li_max_ops_per_insn
)
3671 * linfo
.li_min_insn_length
;
3672 state_machine_regs
.address
3674 state_machine_regs
.op_index
3675 = (state_machine_regs
.op_index
+ uladv
)
3676 % linfo
.li_max_ops_per_insn
;
3678 state_machine_regs
.view
= 0;
3679 printf (_(" Advance PC by constant %s to 0x%s[%d]%s\n"),
3680 dwarf_vmatoa ("u", uladv
),
3681 dwarf_vmatoa ("x", state_machine_regs
.address
),
3682 state_machine_regs
.op_index
,
3683 verbose_view
&& addrdelta
3684 ? _(" (reset view)") : "");
3688 case DW_LNS_fixed_advance_pc
:
3689 SAFE_BYTE_GET_AND_INC (uladv
, data
, 2, end
);
3690 state_machine_regs
.address
+= uladv
;
3691 state_machine_regs
.op_index
= 0;
3692 printf (_(" Advance PC by fixed size amount %s to 0x%s\n"),
3693 dwarf_vmatoa ("u", uladv
),
3694 dwarf_vmatoa ("x", state_machine_regs
.address
));
3695 /* Do NOT reset view. */
3698 case DW_LNS_set_prologue_end
:
3699 printf (_(" Set prologue_end to true\n"));
3702 case DW_LNS_set_epilogue_begin
:
3703 printf (_(" Set epilogue_begin to true\n"));
3706 case DW_LNS_set_isa
:
3707 uladv
= read_uleb128 (data
, & bytes_read
, end
);
3709 printf (_(" Set ISA to %s\n"), dwarf_vmatoa ("u", uladv
));
3713 printf (_(" Unknown opcode %d with operands: "), op_code
);
3715 if (standard_opcodes
!= NULL
)
3716 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
3718 printf ("0x%s%s", dwarf_vmatoa ("x", read_uleb128 (data
,
3720 i
== 1 ? "" : ", ");
3736 unsigned char *name
;
3737 unsigned int directory_index
;
3738 unsigned int modification_date
;
3739 unsigned int length
;
3742 /* Output a decoded representation of the .debug_line section. */
3745 display_debug_lines_decoded (struct dwarf_section
*section
,
3746 unsigned char *data
,
3747 unsigned char *end
, void *fileptr
)
3749 static DWARF2_Internal_LineInfo saved_linfo
;
3751 printf (_("Decoded dump of debug contents of section %s:\n\n"),
3756 /* This loop amounts to one iteration per compilation unit. */
3757 DWARF2_Internal_LineInfo linfo
;
3758 unsigned char *standard_opcodes
;
3759 unsigned char *end_of_sequence
;
3761 File_Entry
*file_table
= NULL
;
3762 unsigned int n_files
= 0;
3763 unsigned char **directory_table
= NULL
;
3764 dwarf_vma n_directories
= 0;
3766 if (const_strneq (section
->name
, ".debug_line.")
3767 /* Note: the following does not apply to .debug_line.dwo sections.
3768 These are full debug_line sections. */
3769 && strcmp (section
->name
, ".debug_line.dwo") != 0)
3771 /* See comment in display_debug_lines_raw(). */
3772 end_of_sequence
= end
;
3773 standard_opcodes
= NULL
;
3774 linfo
= saved_linfo
;
3775 /* PR 17531: file: 0522b371. */
3776 if (linfo
.li_line_range
== 0)
3778 warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n"));
3781 reset_state_machine (linfo
.li_default_is_stmt
);
3785 unsigned char *hdrptr
;
3787 if ((hdrptr
= read_debug_line_header (section
, data
, end
, & linfo
,
3788 & end_of_sequence
)) == NULL
)
3791 /* PR 17531: file: 0522b371. */
3792 if (linfo
.li_line_range
== 0)
3794 warn (_("Line range of 0 is invalid, using 1 instead\n"));
3795 linfo
.li_line_range
= 1;
3797 reset_state_machine (linfo
.li_default_is_stmt
);
3799 /* Save a pointer to the contents of the Opcodes table. */
3800 standard_opcodes
= hdrptr
;
3802 /* Traverse the Directory table just to count entries. */
3803 data
= standard_opcodes
+ linfo
.li_opcode_base
- 1;
3807 warn (_("opcode base of %d extends beyond end of section\n"),
3808 linfo
.li_opcode_base
);
3812 if (linfo
.li_version
>= 5)
3814 unsigned char *format_start
, format_count
, *format
;
3815 dwarf_vma formati
, entryi
;
3816 unsigned int bytes_read
;
3818 load_debug_section (line_str
, fileptr
);
3820 /* Skip directories format. */
3821 SAFE_BYTE_GET_AND_INC (format_count
, data
, 1, end
);
3822 format_start
= data
;
3823 for (formati
= 0; formati
< format_count
; formati
++)
3825 read_uleb128 (data
, & bytes_read
, end
);
3827 read_uleb128 (data
, & bytes_read
, end
);
3831 n_directories
= read_uleb128 (data
, & bytes_read
, end
);
3835 warn (_("Corrupt directories list\n"));
3839 directory_table
= (unsigned char **)
3840 xmalloc (n_directories
* sizeof (unsigned char *));
3842 for (entryi
= 0; entryi
< n_directories
; entryi
++)
3844 unsigned char **pathp
= &directory_table
[entryi
];
3846 format
= format_start
;
3847 for (formati
= 0; formati
< format_count
; formati
++)
3849 dwarf_vma content_type
, form
;
3852 content_type
= read_uleb128 (format
, & bytes_read
, end
);
3853 format
+= bytes_read
;
3854 form
= read_uleb128 (format
, & bytes_read
, end
);
3855 format
+= bytes_read
;
3858 warn (_("Corrupt directories list\n"));
3861 switch (content_type
)
3866 case DW_FORM_string
:
3869 case DW_FORM_line_strp
:
3870 SAFE_BYTE_GET (uvalue
, data
, linfo
.li_offset_size
,
3872 /* Remove const by the cast. */
3873 *pathp
= (unsigned char *)
3874 fetch_indirect_line_string (uvalue
);
3879 data
= read_and_display_attr_value (0, form
, 0, data
, end
,
3881 linfo
.li_offset_size
,
3888 warn (_("Corrupt directories list\n"));
3893 /* Skip files format. */
3894 SAFE_BYTE_GET_AND_INC (format_count
, data
, 1, end
);
3895 format_start
= data
;
3896 for (formati
= 0; formati
< format_count
; formati
++)
3898 read_uleb128 (data
, & bytes_read
, end
);
3900 read_uleb128 (data
, & bytes_read
, end
);
3904 n_files
= read_uleb128 (data
, & bytes_read
, end
);
3908 warn (_("Corrupt file name list\n"));
3912 file_table
= (File_Entry
*) xcalloc (1, n_files
3913 * sizeof (File_Entry
));
3915 for (entryi
= 0; entryi
< n_files
; entryi
++)
3917 File_Entry
*file
= &file_table
[entryi
];
3919 format
= format_start
;
3920 for (formati
= 0; formati
< format_count
; formati
++)
3922 dwarf_vma content_type
, form
;
3925 content_type
= read_uleb128 (format
, & bytes_read
, end
);
3926 format
+= bytes_read
;
3927 form
= read_uleb128 (format
, & bytes_read
, end
);
3928 format
+= bytes_read
;
3931 warn (_("Corrupt file name list\n"));
3934 switch (content_type
)
3939 case DW_FORM_string
:
3942 case DW_FORM_line_strp
:
3943 SAFE_BYTE_GET (uvalue
, data
, linfo
.li_offset_size
,
3945 /* Remove const by the cast. */
3946 file
->name
= (unsigned char *)
3947 fetch_indirect_line_string (uvalue
);
3951 case DW_LNCT_directory_index
:
3955 SAFE_BYTE_GET (file
->directory_index
, data
, 1,
3959 SAFE_BYTE_GET (file
->directory_index
, data
, 2,
3963 file
->directory_index
= read_uleb128 (data
, NULL
,
3969 data
= read_and_display_attr_value (0, form
, 0, data
, end
,
3971 linfo
.li_offset_size
,
3978 warn (_("Corrupt file name list\n"));
3987 unsigned char *ptr_directory_table
= data
;
3989 while (data
< end
&& *data
!= 0)
3991 data
+= strnlen ((char *) data
, end
- data
) + 1;
3998 warn (_("directory table ends unexpectedly\n"));
4003 /* Go through the directory table again to save the directories. */
4004 directory_table
= (unsigned char **)
4005 xmalloc (n_directories
* sizeof (unsigned char *));
4008 while (*ptr_directory_table
!= 0)
4010 directory_table
[i
] = ptr_directory_table
;
4011 ptr_directory_table
+= strnlen ((char *) ptr_directory_table
,
4012 ptr_directory_table
- end
) + 1;
4016 /* Skip the NUL at the end of the table. */
4019 /* Traverse the File Name table just to count the entries. */
4020 if (data
< end
&& *data
!= 0)
4022 unsigned char *ptr_file_name_table
= data
;
4024 while (data
< end
&& *data
!= 0)
4026 unsigned int bytes_read
;
4028 /* Skip Name, directory index, last modification time and length
4030 data
+= strnlen ((char *) data
, end
- data
) + 1;
4031 read_uleb128 (data
, & bytes_read
, end
);
4033 read_uleb128 (data
, & bytes_read
, end
);
4035 read_uleb128 (data
, & bytes_read
, end
);
4043 warn (_("file table ends unexpectedly\n"));
4048 /* Go through the file table again to save the strings. */
4049 file_table
= (File_Entry
*) xmalloc (n_files
* sizeof (File_Entry
));
4052 while (*ptr_file_name_table
!= 0)
4054 unsigned int bytes_read
;
4056 file_table
[i
].name
= ptr_file_name_table
;
4057 ptr_file_name_table
+= strnlen ((char *) ptr_file_name_table
,
4058 end
- ptr_file_name_table
) + 1;
4060 /* We are not interested in directory, time or size. */
4061 file_table
[i
].directory_index
= read_uleb128 (ptr_file_name_table
,
4063 ptr_file_name_table
+= bytes_read
;
4064 file_table
[i
].modification_date
= read_uleb128 (ptr_file_name_table
,
4066 ptr_file_name_table
+= bytes_read
;
4067 file_table
[i
].length
= read_uleb128 (ptr_file_name_table
, & bytes_read
, end
);
4068 ptr_file_name_table
+= bytes_read
;
4074 /* Skip the NUL at the end of the table. */
4078 /* Print the Compilation Unit's name and a header. */
4079 if (file_table
== NULL
)
4081 else if (directory_table
== NULL
)
4082 printf (_("CU: %s:\n"), file_table
[0].name
);
4085 unsigned int ix
= file_table
[0].directory_index
;
4086 const char *directory
;
4091 else if (n_directories
== 0)
4092 directory
= _("<unknown>");
4093 else if (ix
> n_directories
)
4095 warn (_("directory index %u > number of directories %s\n"),
4096 ix
, dwarf_vmatoa ("u", n_directories
));
4097 directory
= _("<corrupt>");
4100 directory
= (char *) directory_table
[ix
- 1];
4102 if (do_wide
|| strlen (directory
) < 76)
4103 printf (_("CU: %s/%s:\n"), directory
, file_table
[0].name
);
4105 printf ("%s:\n", file_table
[0].name
);
4108 printf (_("File name Line number Starting address View\n"));
4109 saved_linfo
= linfo
;
4112 /* This loop iterates through the Dwarf Line Number Program. */
4113 while (data
< end_of_sequence
)
4115 unsigned char op_code
;
4118 unsigned long int uladv
;
4119 unsigned int bytes_read
;
4120 int is_special_opcode
= 0;
4125 if (op_code
>= linfo
.li_opcode_base
)
4127 op_code
-= linfo
.li_opcode_base
;
4128 uladv
= (op_code
/ linfo
.li_line_range
);
4129 if (linfo
.li_max_ops_per_insn
== 1)
4131 uladv
*= linfo
.li_min_insn_length
;
4132 state_machine_regs
.address
+= uladv
;
4134 state_machine_regs
.view
= 0;
4139 = ((state_machine_regs
.op_index
+ uladv
)
4140 / linfo
.li_max_ops_per_insn
)
4141 * linfo
.li_min_insn_length
;
4142 state_machine_regs
.address
4144 state_machine_regs
.op_index
4145 = (state_machine_regs
.op_index
+ uladv
)
4146 % linfo
.li_max_ops_per_insn
;
4148 state_machine_regs
.view
= 0;
4151 adv
= (op_code
% linfo
.li_line_range
) + linfo
.li_line_base
;
4152 state_machine_regs
.line
+= adv
;
4153 is_special_opcode
= 1;
4154 /* Increment view after printing this row. */
4156 else switch (op_code
)
4158 case DW_LNS_extended_op
:
4160 unsigned int ext_op_code_len
;
4161 unsigned char ext_op_code
;
4162 unsigned char *op_code_data
= data
;
4164 ext_op_code_len
= read_uleb128 (op_code_data
, &bytes_read
,
4166 op_code_data
+= bytes_read
;
4168 if (ext_op_code_len
== 0)
4170 warn (_("Badly formed extended line op encountered!\n"));
4173 ext_op_code_len
+= bytes_read
;
4174 ext_op_code
= *op_code_data
++;
4178 switch (ext_op_code
)
4180 case DW_LNE_end_sequence
:
4181 /* Reset stuff after printing this row. */
4183 case DW_LNE_set_address
:
4184 SAFE_BYTE_GET_AND_INC (state_machine_regs
.address
,
4186 ext_op_code_len
- bytes_read
- 1,
4188 state_machine_regs
.op_index
= 0;
4189 state_machine_regs
.view
= 0;
4191 case DW_LNE_define_file
:
4193 file_table
= (File_Entry
*) xrealloc
4194 (file_table
, (n_files
+ 1) * sizeof (File_Entry
));
4196 ++state_machine_regs
.last_file_entry
;
4197 /* Source file name. */
4198 file_table
[n_files
].name
= op_code_data
;
4199 op_code_data
+= strlen ((char *) op_code_data
) + 1;
4200 /* Directory index. */
4201 file_table
[n_files
].directory_index
=
4202 read_uleb128 (op_code_data
, & bytes_read
,
4204 op_code_data
+= bytes_read
;
4205 /* Last modification time. */
4206 file_table
[n_files
].modification_date
=
4207 read_uleb128 (op_code_data
, & bytes_read
,
4209 op_code_data
+= bytes_read
;
4211 file_table
[n_files
].length
=
4212 read_uleb128 (op_code_data
, & bytes_read
,
4218 case DW_LNE_set_discriminator
:
4219 case DW_LNE_HP_set_sequence
:
4220 /* Simply ignored. */
4224 printf (_("UNKNOWN (%u): length %d\n"),
4225 ext_op_code
, ext_op_code_len
- bytes_read
);
4228 data
+= ext_op_code_len
;
4232 /* Increment view after printing this row. */
4235 case DW_LNS_advance_pc
:
4236 uladv
= read_uleb128 (data
, & bytes_read
, end
);
4238 if (linfo
.li_max_ops_per_insn
== 1)
4240 uladv
*= linfo
.li_min_insn_length
;
4241 state_machine_regs
.address
+= uladv
;
4243 state_machine_regs
.view
= 0;
4248 = ((state_machine_regs
.op_index
+ uladv
)
4249 / linfo
.li_max_ops_per_insn
)
4250 * linfo
.li_min_insn_length
;
4251 state_machine_regs
.address
4253 state_machine_regs
.op_index
4254 = (state_machine_regs
.op_index
+ uladv
)
4255 % linfo
.li_max_ops_per_insn
;
4257 state_machine_regs
.view
= 0;
4261 case DW_LNS_advance_line
:
4262 adv
= read_sleb128 (data
, & bytes_read
, end
);
4264 state_machine_regs
.line
+= adv
;
4267 case DW_LNS_set_file
:
4268 adv
= read_uleb128 (data
, & bytes_read
, end
);
4270 state_machine_regs
.file
= adv
;
4273 unsigned file
= state_machine_regs
.file
- 1;
4276 if (file_table
== NULL
|| n_files
== 0)
4277 printf (_("\n [Use file table entry %d]\n"), file
);
4279 else if (file
>= n_files
)
4281 warn (_("file index %u > number of files %u\n"), file
+ 1, n_files
);
4282 printf (_("\n <over large file table index %u>"), file
);
4284 else if ((dir
= file_table
[file
].directory_index
) == 0)
4285 /* If directory index is 0, that means current directory. */
4286 printf ("\n./%s:[++]\n", file_table
[file
].name
);
4287 else if (directory_table
== NULL
|| n_directories
== 0)
4288 printf (_("\n [Use file %s in directory table entry %d]\n"),
4289 file_table
[file
].name
, dir
);
4291 else if (dir
> n_directories
)
4293 warn (_("directory index %u > number of directories %s\n"),
4294 dir
, dwarf_vmatoa ("u", n_directories
));
4295 printf (_("\n <over large directory table entry %u>\n"), dir
);
4298 printf ("\n%s/%s:\n",
4299 /* The directory index starts counting at 1. */
4300 directory_table
[dir
- 1], file_table
[file
].name
);
4304 case DW_LNS_set_column
:
4305 uladv
= read_uleb128 (data
, & bytes_read
, end
);
4307 state_machine_regs
.column
= uladv
;
4310 case DW_LNS_negate_stmt
:
4311 adv
= state_machine_regs
.is_stmt
;
4313 state_machine_regs
.is_stmt
= adv
;
4316 case DW_LNS_set_basic_block
:
4317 state_machine_regs
.basic_block
= 1;
4320 case DW_LNS_const_add_pc
:
4321 uladv
= ((255 - linfo
.li_opcode_base
) / linfo
.li_line_range
);
4322 if (linfo
.li_max_ops_per_insn
== 1)
4324 uladv
*= linfo
.li_min_insn_length
;
4325 state_machine_regs
.address
+= uladv
;
4327 state_machine_regs
.view
= 0;
4332 = ((state_machine_regs
.op_index
+ uladv
)
4333 / linfo
.li_max_ops_per_insn
)
4334 * linfo
.li_min_insn_length
;
4335 state_machine_regs
.address
4337 state_machine_regs
.op_index
4338 = (state_machine_regs
.op_index
+ uladv
)
4339 % linfo
.li_max_ops_per_insn
;
4341 state_machine_regs
.view
= 0;
4345 case DW_LNS_fixed_advance_pc
:
4346 SAFE_BYTE_GET_AND_INC (uladv
, data
, 2, end
);
4347 state_machine_regs
.address
+= uladv
;
4348 state_machine_regs
.op_index
= 0;
4349 /* Do NOT reset view. */
4352 case DW_LNS_set_prologue_end
:
4355 case DW_LNS_set_epilogue_begin
:
4358 case DW_LNS_set_isa
:
4359 uladv
= read_uleb128 (data
, & bytes_read
, end
);
4361 printf (_(" Set ISA to %lu\n"), uladv
);
4365 printf (_(" Unknown opcode %d with operands: "), op_code
);
4367 if (standard_opcodes
!= NULL
)
4368 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
4370 printf ("0x%s%s", dwarf_vmatoa ("x", read_uleb128 (data
,
4372 i
== 1 ? "" : ", ");
4379 /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row
4380 to the DWARF address/line matrix. */
4381 if ((is_special_opcode
) || (xop
== -DW_LNE_end_sequence
)
4382 || (xop
== DW_LNS_copy
))
4384 const unsigned int MAX_FILENAME_LENGTH
= 35;
4386 char *newFileName
= NULL
;
4387 size_t fileNameLength
;
4391 unsigned indx
= state_machine_regs
.file
- 1;
4393 if (indx
>= n_files
)
4395 warn (_("corrupt file index %u encountered\n"), indx
);
4396 fileName
= _("<corrupt>");
4399 fileName
= (char *) file_table
[indx
].name
;
4402 fileName
= _("<unknown>");
4404 fileNameLength
= strlen (fileName
);
4406 if ((fileNameLength
> MAX_FILENAME_LENGTH
) && (!do_wide
))
4408 newFileName
= (char *) xmalloc (MAX_FILENAME_LENGTH
+ 1);
4409 /* Truncate file name */
4410 strncpy (newFileName
,
4411 fileName
+ fileNameLength
- MAX_FILENAME_LENGTH
,
4412 MAX_FILENAME_LENGTH
+ 1);
4416 newFileName
= (char *) xmalloc (fileNameLength
+ 1);
4417 strncpy (newFileName
, fileName
, fileNameLength
+ 1);
4420 if (!do_wide
|| (fileNameLength
<= MAX_FILENAME_LENGTH
))
4422 if (linfo
.li_max_ops_per_insn
== 1)
4423 printf ("%-35s %11d %#18" DWARF_VMA_FMT
"x",
4424 newFileName
, state_machine_regs
.line
,
4425 state_machine_regs
.address
);
4427 printf ("%-35s %11d %#18" DWARF_VMA_FMT
"x[%d]",
4428 newFileName
, state_machine_regs
.line
,
4429 state_machine_regs
.address
,
4430 state_machine_regs
.op_index
);
4434 if (linfo
.li_max_ops_per_insn
== 1)
4435 printf ("%s %11d %#18" DWARF_VMA_FMT
"x",
4436 newFileName
, state_machine_regs
.line
,
4437 state_machine_regs
.address
);
4439 printf ("%s %11d %#18" DWARF_VMA_FMT
"x[%d]",
4440 newFileName
, state_machine_regs
.line
,
4441 state_machine_regs
.address
,
4442 state_machine_regs
.op_index
);
4445 if (state_machine_regs
.view
)
4446 printf (" %6u\n", state_machine_regs
.view
);
4449 state_machine_regs
.view
++;
4451 if (xop
== -DW_LNE_end_sequence
)
4453 reset_state_machine (linfo
.li_default_is_stmt
);
4468 if (directory_table
)
4470 free (directory_table
);
4471 directory_table
= NULL
;
4482 display_debug_lines (struct dwarf_section
*section
, void *file
)
4484 unsigned char *data
= section
->start
;
4485 unsigned char *end
= data
+ section
->size
;
4487 int retValDecoded
= 1;
4489 if (do_debug_lines
== 0)
4490 do_debug_lines
|= FLAG_DEBUG_LINES_RAW
;
4492 if (do_debug_lines
& FLAG_DEBUG_LINES_RAW
)
4493 retValRaw
= display_debug_lines_raw (section
, data
, end
, file
);
4495 if (do_debug_lines
& FLAG_DEBUG_LINES_DECODED
)
4496 retValDecoded
= display_debug_lines_decoded (section
, data
, end
, file
);
4498 if (!retValRaw
|| !retValDecoded
)
4505 find_debug_info_for_offset (unsigned long offset
)
4509 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
4512 for (i
= 0; i
< num_debug_info_entries
; i
++)
4513 if (debug_information
[i
].cu_offset
== offset
)
4514 return debug_information
+ i
;
4520 get_gdb_index_symbol_kind_name (gdb_index_symbol_kind kind
)
4522 /* See gdb/gdb-index.h. */
4523 static const char * const kinds
[] =
4535 return _ (kinds
[kind
]);
4539 display_debug_pubnames_worker (struct dwarf_section
*section
,
4540 void *file ATTRIBUTE_UNUSED
,
4543 DWARF2_Internal_PubNames names
;
4544 unsigned char *start
= section
->start
;
4545 unsigned char *end
= start
+ section
->size
;
4547 /* It does not matter if this load fails,
4548 we test for that later on. */
4549 load_debug_info (file
);
4551 printf (_("Contents of the %s section:\n\n"), section
->name
);
4555 unsigned char *data
;
4556 unsigned long sec_off
;
4557 unsigned int offset_size
, initial_length_size
;
4559 SAFE_BYTE_GET_AND_INC (names
.pn_length
, start
, 4, end
);
4560 if (names
.pn_length
== 0xffffffff)
4562 SAFE_BYTE_GET_AND_INC (names
.pn_length
, start
, 8, end
);
4564 initial_length_size
= 12;
4569 initial_length_size
= 4;
4572 sec_off
= start
- section
->start
;
4573 if (sec_off
+ names
.pn_length
< sec_off
4574 || sec_off
+ names
.pn_length
> section
->size
)
4576 warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"),
4578 sec_off
- initial_length_size
,
4579 dwarf_vmatoa ("x", names
.pn_length
));
4584 start
+= names
.pn_length
;
4586 SAFE_BYTE_GET_AND_INC (names
.pn_version
, data
, 2, end
);
4587 SAFE_BYTE_GET_AND_INC (names
.pn_offset
, data
, offset_size
, end
);
4589 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
4590 && num_debug_info_entries
> 0
4591 && find_debug_info_for_offset (names
.pn_offset
) == NULL
)
4592 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
4593 (unsigned long) names
.pn_offset
, section
->name
);
4595 SAFE_BYTE_GET_AND_INC (names
.pn_size
, data
, offset_size
, end
);
4597 printf (_(" Length: %ld\n"),
4598 (long) names
.pn_length
);
4599 printf (_(" Version: %d\n"),
4601 printf (_(" Offset into .debug_info section: 0x%lx\n"),
4602 (unsigned long) names
.pn_offset
);
4603 printf (_(" Size of area in .debug_info section: %ld\n"),
4604 (long) names
.pn_size
);
4606 if (names
.pn_version
!= 2 && names
.pn_version
!= 3)
4608 static int warned
= 0;
4612 warn (_("Only DWARF 2 and 3 pubnames are currently supported\n"));
4620 printf (_("\n Offset Kind Name\n"));
4622 printf (_("\n Offset\tName\n"));
4626 bfd_size_type maxprint
;
4629 SAFE_BYTE_GET (offset
, data
, offset_size
, end
);
4634 data
+= offset_size
;
4637 maxprint
= (end
- data
) - 1;
4641 unsigned int kind_data
;
4642 gdb_index_symbol_kind kind
;
4643 const char *kind_name
;
4646 SAFE_BYTE_GET (kind_data
, data
, 1, end
);
4649 /* GCC computes the kind as the upper byte in the CU index
4650 word, and then right shifts it by the CU index size.
4651 Left shift KIND to where the gdb-index.h accessor macros
4653 kind_data
<<= GDB_INDEX_CU_BITSIZE
;
4654 kind
= GDB_INDEX_SYMBOL_KIND_VALUE (kind_data
);
4655 kind_name
= get_gdb_index_symbol_kind_name (kind
);
4656 is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (kind_data
);
4657 printf (" %-6lx %s,%-10s %.*s\n",
4658 (unsigned long) offset
, is_static
? _("s") : _("g"),
4659 kind_name
, (int) maxprint
, data
);
4662 printf (" %-6lx\t%.*s\n",
4663 (unsigned long) offset
, (int) maxprint
, data
);
4665 data
+= strnlen ((char *) data
, maxprint
) + 1;
4676 display_debug_pubnames (struct dwarf_section
*section
, void *file
)
4678 return display_debug_pubnames_worker (section
, file
, 0);
4682 display_debug_gnu_pubnames (struct dwarf_section
*section
, void *file
)
4684 return display_debug_pubnames_worker (section
, file
, 1);
4688 display_debug_macinfo (struct dwarf_section
*section
,
4689 void *file ATTRIBUTE_UNUSED
)
4691 unsigned char *start
= section
->start
;
4692 unsigned char *end
= start
+ section
->size
;
4693 unsigned char *curr
= start
;
4694 unsigned int bytes_read
;
4695 enum dwarf_macinfo_record_type op
;
4697 printf (_("Contents of the %s section:\n\n"), section
->name
);
4701 unsigned int lineno
;
4702 const unsigned char *string
;
4704 op
= (enum dwarf_macinfo_record_type
) *curr
;
4709 case DW_MACINFO_start_file
:
4711 unsigned int filenum
;
4713 lineno
= read_uleb128 (curr
, & bytes_read
, end
);
4715 filenum
= read_uleb128 (curr
, & bytes_read
, end
);
4718 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"),
4723 case DW_MACINFO_end_file
:
4724 printf (_(" DW_MACINFO_end_file\n"));
4727 case DW_MACINFO_define
:
4728 lineno
= read_uleb128 (curr
, & bytes_read
, end
);
4731 curr
+= strnlen ((char *) string
, end
- string
) + 1;
4732 printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"),
4736 case DW_MACINFO_undef
:
4737 lineno
= read_uleb128 (curr
, & bytes_read
, end
);
4740 curr
+= strnlen ((char *) string
, end
- string
) + 1;
4741 printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"),
4745 case DW_MACINFO_vendor_ext
:
4747 unsigned int constant
;
4749 constant
= read_uleb128 (curr
, & bytes_read
, end
);
4752 curr
+= strnlen ((char *) string
, end
- string
) + 1;
4753 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"),
4763 /* Given LINE_OFFSET into the .debug_line section, attempt to return
4764 filename and dirname corresponding to file name table entry with index
4765 FILEIDX. Return NULL on failure. */
4767 static unsigned char *
4768 get_line_filename_and_dirname (dwarf_vma line_offset
,
4770 unsigned char **dir_name
)
4772 struct dwarf_section
*section
= &debug_displays
[line
].section
;
4773 unsigned char *hdrptr
, *dirtable
, *file_name
;
4774 unsigned int offset_size
, initial_length_size
;
4775 unsigned int version
, opcode_base
, bytes_read
;
4776 dwarf_vma length
, diridx
;
4777 const unsigned char * end
;
4780 if (section
->start
== NULL
4781 || line_offset
>= section
->size
4785 hdrptr
= section
->start
+ line_offset
;
4786 end
= section
->start
+ section
->size
;
4788 SAFE_BYTE_GET_AND_INC (length
, hdrptr
, 4, end
);
4789 if (length
== 0xffffffff)
4791 /* This section is 64-bit DWARF 3. */
4792 SAFE_BYTE_GET_AND_INC (length
, hdrptr
, 8, end
);
4794 initial_length_size
= 12;
4799 initial_length_size
= 4;
4801 if (length
+ initial_length_size
< length
4802 || length
+ initial_length_size
> section
->size
)
4805 SAFE_BYTE_GET_AND_INC (version
, hdrptr
, 2, end
);
4806 if (version
!= 2 && version
!= 3 && version
!= 4)
4808 hdrptr
+= offset_size
+ 1;/* Skip prologue_length and min_insn_length. */
4810 hdrptr
++; /* Skip max_ops_per_insn. */
4811 hdrptr
+= 3; /* Skip default_is_stmt, line_base, line_range. */
4813 SAFE_BYTE_GET_AND_INC (opcode_base
, hdrptr
, 1, end
);
4814 if (opcode_base
== 0)
4817 hdrptr
+= opcode_base
- 1;
4822 /* Skip over dirname table. */
4823 while (*hdrptr
!= '\0')
4825 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
) + 1;
4829 hdrptr
++; /* Skip the NUL at the end of the table. */
4831 /* Now skip over preceding filename table entries. */
4832 for (; hdrptr
< end
&& *hdrptr
!= '\0' && fileidx
> 1; fileidx
--)
4834 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
) + 1;
4835 read_uleb128 (hdrptr
, &bytes_read
, end
);
4836 hdrptr
+= bytes_read
;
4837 read_uleb128 (hdrptr
, &bytes_read
, end
);
4838 hdrptr
+= bytes_read
;
4839 read_uleb128 (hdrptr
, &bytes_read
, end
);
4840 hdrptr
+= bytes_read
;
4842 if (hdrptr
>= end
|| *hdrptr
== '\0')
4846 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
) + 1;
4849 diridx
= read_uleb128 (hdrptr
, &bytes_read
, end
);
4852 for (; dirtable
< end
&& *dirtable
!= '\0' && diridx
> 1; diridx
--)
4853 dirtable
+= strnlen ((char *) dirtable
, end
- dirtable
) + 1;
4854 if (dirtable
>= end
|| *dirtable
== '\0')
4856 *dir_name
= dirtable
;
4861 display_debug_macro (struct dwarf_section
*section
,
4864 unsigned char *start
= section
->start
;
4865 unsigned char *end
= start
+ section
->size
;
4866 unsigned char *curr
= start
;
4867 unsigned char *extended_op_buf
[256];
4868 unsigned int bytes_read
;
4870 load_debug_section (str
, file
);
4871 load_debug_section (line
, file
);
4873 printf (_("Contents of the %s section:\n\n"), section
->name
);
4877 unsigned int lineno
, version
, flags
;
4878 unsigned int offset_size
= 4;
4879 const unsigned char *string
;
4880 dwarf_vma line_offset
= 0, sec_offset
= curr
- start
, offset
;
4881 unsigned char **extended_ops
= NULL
;
4883 SAFE_BYTE_GET_AND_INC (version
, curr
, 2, end
);
4884 if (version
!= 4 && version
!= 5)
4886 error (_("Only GNU extension to DWARF 4 or 5 of %s is currently supported.\n"),
4891 SAFE_BYTE_GET_AND_INC (flags
, curr
, 1, end
);
4894 printf (_(" Offset: 0x%lx\n"),
4895 (unsigned long) sec_offset
);
4896 printf (_(" Version: %d\n"), version
);
4897 printf (_(" Offset size: %d\n"), offset_size
);
4900 SAFE_BYTE_GET_AND_INC (line_offset
, curr
, offset_size
, end
);
4901 printf (_(" Offset into .debug_line: 0x%lx\n"),
4902 (unsigned long) line_offset
);
4906 unsigned int i
, count
, op
;
4909 SAFE_BYTE_GET_AND_INC (count
, curr
, 1, end
);
4911 memset (extended_op_buf
, 0, sizeof (extended_op_buf
));
4912 extended_ops
= extended_op_buf
;
4915 printf (_(" Extension opcode arguments:\n"));
4916 for (i
= 0; i
< count
; i
++)
4918 SAFE_BYTE_GET_AND_INC (op
, curr
, 1, end
);
4919 extended_ops
[op
] = curr
;
4920 nargs
= read_uleb128 (curr
, &bytes_read
, end
);
4923 printf (_(" DW_MACRO_%02x has no arguments\n"), op
);
4926 printf (_(" DW_MACRO_%02x arguments: "), op
);
4927 for (n
= 0; n
< nargs
; n
++)
4931 SAFE_BYTE_GET_AND_INC (form
, curr
, 1, end
);
4932 printf ("%s%s", get_FORM_name (form
),
4933 n
== nargs
- 1 ? "\n" : ", ");
4943 case DW_FORM_block1
:
4944 case DW_FORM_block2
:
4945 case DW_FORM_block4
:
4947 case DW_FORM_string
:
4949 case DW_FORM_sec_offset
:
4952 error (_("Invalid extension opcode form %s\n"),
4953 get_FORM_name (form
));
4969 error (_(".debug_macro section not zero terminated\n"));
4973 SAFE_BYTE_GET_AND_INC (op
, curr
, 1, end
);
4979 case DW_MACRO_start_file
:
4981 unsigned int filenum
;
4982 unsigned char *file_name
= NULL
, *dir_name
= NULL
;
4984 lineno
= read_uleb128 (curr
, &bytes_read
, end
);
4986 filenum
= read_uleb128 (curr
, &bytes_read
, end
);
4989 if ((flags
& 2) == 0)
4990 error (_("DW_MACRO_start_file used, but no .debug_line offset provided.\n"));
4993 = get_line_filename_and_dirname (line_offset
, filenum
,
4995 if (file_name
== NULL
)
4996 printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d\n"),
4999 printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d filename: %s%s%s\n"),
5001 dir_name
!= NULL
? (const char *) dir_name
: "",
5002 dir_name
!= NULL
? "/" : "", file_name
);
5006 case DW_MACRO_end_file
:
5007 printf (_(" DW_MACRO_end_file\n"));
5010 case DW_MACRO_define
:
5011 lineno
= read_uleb128 (curr
, &bytes_read
, end
);
5014 curr
+= strnlen ((char *) string
, end
- string
) + 1;
5015 printf (_(" DW_MACRO_define - lineno : %d macro : %s\n"),
5019 case DW_MACRO_undef
:
5020 lineno
= read_uleb128 (curr
, &bytes_read
, end
);
5023 curr
+= strnlen ((char *) string
, end
- string
) + 1;
5024 printf (_(" DW_MACRO_undef - lineno : %d macro : %s\n"),
5028 case DW_MACRO_define_strp
:
5029 lineno
= read_uleb128 (curr
, &bytes_read
, end
);
5031 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
5032 string
= fetch_indirect_string (offset
);
5033 printf (_(" DW_MACRO_define_strp - lineno : %d macro : %s\n"),
5037 case DW_MACRO_undef_strp
:
5038 lineno
= read_uleb128 (curr
, &bytes_read
, end
);
5040 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
5041 string
= fetch_indirect_string (offset
);
5042 printf (_(" DW_MACRO_undef_strp - lineno : %d macro : %s\n"),
5046 case DW_MACRO_import
:
5047 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
5048 printf (_(" DW_MACRO_import - offset : 0x%lx\n"),
5049 (unsigned long) offset
);
5052 case DW_MACRO_define_sup
:
5053 lineno
= read_uleb128 (curr
, &bytes_read
, end
);
5055 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
5056 printf (_(" DW_MACRO_define_sup - lineno : %d macro offset : 0x%lx\n"),
5057 lineno
, (unsigned long) offset
);
5060 case DW_MACRO_undef_sup
:
5061 lineno
= read_uleb128 (curr
, &bytes_read
, end
);
5063 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
5064 printf (_(" DW_MACRO_undef_sup - lineno : %d macro offset : 0x%lx\n"),
5065 lineno
, (unsigned long) offset
);
5068 case DW_MACRO_import_sup
:
5069 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
5070 printf (_(" DW_MACRO_import_sup - offset : 0x%lx\n"),
5071 (unsigned long) offset
);
5075 if (extended_ops
== NULL
|| extended_ops
[op
] == NULL
)
5077 error (_(" Unknown macro opcode %02x seen\n"), op
);
5082 /* Skip over unhandled opcodes. */
5084 unsigned char *desc
= extended_ops
[op
];
5085 nargs
= read_uleb128 (desc
, &bytes_read
, end
);
5089 printf (_(" DW_MACRO_%02x\n"), op
);
5092 printf (_(" DW_MACRO_%02x -"), op
);
5093 for (n
= 0; n
< nargs
; n
++)
5097 /* DW_FORM_implicit_const is not expected here. */
5098 SAFE_BYTE_GET_AND_INC (val
, desc
, 1, end
);
5100 = read_and_display_attr_value (0, val
, 0,
5101 curr
, end
, 0, 0, offset_size
,
5102 version
, NULL
, 0, NULL
,
5120 display_debug_abbrev (struct dwarf_section
*section
,
5121 void *file ATTRIBUTE_UNUSED
)
5123 abbrev_entry
*entry
;
5124 unsigned char *start
= section
->start
;
5125 unsigned char *end
= start
+ section
->size
;
5127 printf (_("Contents of the %s section:\n\n"), section
->name
);
5131 unsigned char *last
;
5136 start
= process_abbrev_section (start
, end
);
5138 if (first_abbrev
== NULL
)
5141 printf (_(" Number TAG (0x%lx)\n"), (long) (last
- section
->start
));
5143 for (entry
= first_abbrev
; entry
; entry
= entry
->next
)
5147 printf (" %ld %s [%s]\n",
5149 get_TAG_name (entry
->tag
),
5150 entry
->children
? _("has children") : _("no children"));
5152 for (attr
= entry
->first_attr
; attr
; attr
= attr
->next
)
5154 printf (" %-18s %s",
5155 get_AT_name (attr
->attribute
),
5156 get_FORM_name (attr
->form
));
5157 if (attr
->form
== DW_FORM_implicit_const
)
5158 printf (": %" BFD_VMA_FMT
"d", attr
->implicit_const
);
5170 /* Return true when ADDR is the maximum address, when addresses are
5171 POINTER_SIZE bytes long. */
5174 is_max_address (dwarf_vma addr
, unsigned int pointer_size
)
5176 dwarf_vma mask
= ~(~(dwarf_vma
) 1 << (pointer_size
* 8 - 1));
5177 return ((addr
& mask
) == mask
);
5180 /* Display a view pair list starting at *VSTART_PTR and ending at
5181 VLISTEND within SECTION. */
5184 display_view_pair_list (struct dwarf_section
*section
,
5185 unsigned char **vstart_ptr
,
5186 unsigned int debug_info_entry
,
5187 unsigned char *vlistend
)
5189 unsigned char *vstart
= *vstart_ptr
;
5190 unsigned char *section_end
= section
->start
+ section
->size
;
5191 unsigned int pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
5193 if (vlistend
< section_end
)
5194 section_end
= vlistend
;
5198 while (vstart
< section_end
)
5200 dwarf_vma off
= vstart
- section
->start
;
5201 dwarf_vma vbegin
, vend
;
5203 unsigned int bytes_read
;
5204 vbegin
= read_uleb128 (vstart
, &bytes_read
, section_end
);
5205 vstart
+= bytes_read
;
5206 if (vstart
== section_end
)
5208 vstart
-= bytes_read
;
5212 vend
= read_uleb128 (vstart
, &bytes_read
, section_end
);
5213 vstart
+= bytes_read
;
5215 printf (" %8.8lx ", (unsigned long) off
);
5217 print_dwarf_view (vbegin
, pointer_size
, 1);
5218 print_dwarf_view (vend
, pointer_size
, 1);
5219 printf (_("location view pair\n"));
5223 *vstart_ptr
= vstart
;
5226 /* Display a location list from a normal (ie, non-dwo) .debug_loc section. */
5229 display_loc_list (struct dwarf_section
*section
,
5230 unsigned char **start_ptr
,
5231 unsigned int debug_info_entry
,
5233 dwarf_vma base_address
,
5234 unsigned char **vstart_ptr
,
5237 unsigned char *start
= *start_ptr
, *vstart
= *vstart_ptr
;
5238 unsigned char *section_end
= section
->start
+ section
->size
;
5239 unsigned long cu_offset
;
5240 unsigned int pointer_size
;
5241 unsigned int offset_size
;
5246 unsigned short length
;
5247 int need_frame_base
;
5249 if (debug_info_entry
>= num_debug_info_entries
)
5251 warn (_("No debug information available for loc lists of entry: %u\n"),
5256 cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
5257 pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
5258 offset_size
= debug_information
[debug_info_entry
].offset_size
;
5259 dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
5261 if (pointer_size
< 2 || pointer_size
> 8)
5263 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
5264 pointer_size
, debug_info_entry
);
5270 dwarf_vma off
= offset
+ (start
- *start_ptr
);
5271 dwarf_vma vbegin
= vm1
, vend
= vm1
;
5273 if (start
+ 2 * pointer_size
> section_end
)
5275 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5276 (unsigned long) offset
);
5280 printf (" %8.8lx ", (unsigned long) off
);
5282 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, section_end
);
5283 SAFE_BYTE_GET_AND_INC (end
, start
, pointer_size
, section_end
);
5285 if (begin
== 0 && end
== 0)
5287 /* PR 18374: In a object file we can have a location list that
5288 starts with a begin and end of 0 because there are relocations
5289 that need to be applied to the addresses. Actually applying
5290 the relocations now does not help as they will probably resolve
5291 to 0, since the object file has not been fully linked. Real
5292 end of list markers will not have any relocations against them. */
5293 if (! reloc_at (section
, off
)
5294 && ! reloc_at (section
, off
+ pointer_size
))
5296 printf (_("<End of list>\n"));
5301 /* Check base address specifiers. */
5302 if (is_max_address (begin
, pointer_size
)
5303 && !is_max_address (end
, pointer_size
))
5306 print_dwarf_vma (begin
, pointer_size
);
5307 print_dwarf_vma (end
, pointer_size
);
5308 printf (_("(base address)\n"));
5314 unsigned int bytes_read
;
5316 off
= offset
+ (vstart
- *start_ptr
);
5318 vbegin
= read_uleb128 (vstart
, &bytes_read
, section_end
);
5319 vstart
+= bytes_read
;
5320 print_dwarf_view (vbegin
, pointer_size
, 1);
5322 vend
= read_uleb128 (vstart
, &bytes_read
, section_end
);
5323 vstart
+= bytes_read
;
5324 print_dwarf_view (vend
, pointer_size
, 1);
5326 printf (_("views at %8.8lx for:\n %*s "),
5327 (unsigned long) off
, 8, "");
5330 if (start
+ 2 > section_end
)
5332 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5333 (unsigned long) offset
);
5337 SAFE_BYTE_GET_AND_INC (length
, start
, 2, section_end
);
5339 if (start
+ length
> section_end
)
5341 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5342 (unsigned long) offset
);
5346 print_dwarf_vma (begin
+ base_address
, pointer_size
);
5347 print_dwarf_vma (end
+ base_address
, pointer_size
);
5350 need_frame_base
= decode_location_expression (start
,
5355 cu_offset
, section
);
5358 if (need_frame_base
&& !has_frame_base
)
5359 printf (_(" [without DW_AT_frame_base]"));
5361 if (begin
== end
&& vbegin
== vend
)
5362 fputs (_(" (start == end)"), stdout
);
5363 else if (begin
> end
|| (begin
== end
&& vbegin
> vend
))
5364 fputs (_(" (start > end)"), stdout
);
5372 *vstart_ptr
= vstart
;
5375 /* Display a location list from a normal (ie, non-dwo) .debug_loclists section. */
5378 display_loclists_list (struct dwarf_section
*section
,
5379 unsigned char **start_ptr
,
5380 unsigned int debug_info_entry
,
5382 dwarf_vma base_address
,
5383 unsigned char **vstart_ptr
,
5386 unsigned char *start
= *start_ptr
, *vstart
= *vstart_ptr
;
5387 unsigned char *section_end
= section
->start
+ section
->size
;
5388 unsigned long cu_offset
;
5389 unsigned int pointer_size
;
5390 unsigned int offset_size
;
5392 unsigned int bytes_read
;
5394 /* Initialize it due to a false compiler warning. */
5395 dwarf_vma begin
= -1, vbegin
= -1;
5396 dwarf_vma end
= -1, vend
= -1;
5398 int need_frame_base
;
5400 if (debug_info_entry
>= num_debug_info_entries
)
5402 warn (_("No debug information available for "
5403 "loclists lists of entry: %u\n"),
5408 cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
5409 pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
5410 offset_size
= debug_information
[debug_info_entry
].offset_size
;
5411 dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
5413 if (pointer_size
< 2 || pointer_size
> 8)
5415 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
5416 pointer_size
, debug_info_entry
);
5422 dwarf_vma off
= offset
+ (start
- *start_ptr
);
5423 enum dwarf_location_list_entry_type llet
;
5425 if (start
+ 1 > section_end
)
5427 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5428 (unsigned long) offset
);
5432 printf (" %8.8lx ", (unsigned long) off
);
5434 SAFE_BYTE_GET_AND_INC (llet
, start
, 1, section_end
);
5436 if (vstart
&& llet
== DW_LLE_offset_pair
)
5438 off
= offset
+ (vstart
- *start_ptr
);
5440 vbegin
= read_uleb128 (vstart
, &bytes_read
, section_end
);
5441 vstart
+= bytes_read
;
5442 print_dwarf_view (vbegin
, pointer_size
, 1);
5444 vend
= read_uleb128 (vstart
, &bytes_read
, section_end
);
5445 vstart
+= bytes_read
;
5446 print_dwarf_view (vend
, pointer_size
, 1);
5448 printf (_("views at %8.8lx for:\n %*s "),
5449 (unsigned long) off
, 8, "");
5454 case DW_LLE_end_of_list
:
5455 printf (_("<End of list>\n"));
5457 case DW_LLE_offset_pair
:
5458 begin
= read_uleb128 (start
, &bytes_read
, section_end
);
5459 start
+= bytes_read
;
5460 end
= read_uleb128 (start
, &bytes_read
, section_end
);
5461 start
+= bytes_read
;
5463 case DW_LLE_base_address
:
5464 SAFE_BYTE_GET_AND_INC (base_address
, start
, pointer_size
,
5466 print_dwarf_vma (base_address
, pointer_size
);
5467 printf (_("(base address)\n"));
5469 #ifdef DW_LLE_view_pair
5470 case DW_LLE_view_pair
:
5472 printf (_("View pair entry in loclist with locviews attribute\n"));
5473 vbegin
= read_uleb128 (start
, &bytes_read
, section_end
);
5474 start
+= bytes_read
;
5475 print_dwarf_view (vbegin
, pointer_size
, 1);
5477 vend
= read_uleb128 (start
, &bytes_read
, section_end
);
5478 start
+= bytes_read
;
5479 print_dwarf_view (vend
, pointer_size
, 1);
5481 printf (_("views for:\n"));
5485 error (_("Invalid location list entry type %d\n"), llet
);
5488 if (llet
== DW_LLE_end_of_list
)
5490 if (llet
!= DW_LLE_offset_pair
)
5493 if (start
+ 2 > section_end
)
5495 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5496 (unsigned long) offset
);
5500 length
= read_uleb128 (start
, &bytes_read
, section_end
);
5501 start
+= bytes_read
;
5503 print_dwarf_vma (begin
+ base_address
, pointer_size
);
5504 print_dwarf_vma (end
+ base_address
, pointer_size
);
5507 need_frame_base
= decode_location_expression (start
,
5512 cu_offset
, section
);
5515 if (need_frame_base
&& !has_frame_base
)
5516 printf (_(" [without DW_AT_frame_base]"));
5518 if (begin
== end
&& vbegin
== vend
)
5519 fputs (_(" (start == end)"), stdout
);
5520 else if (begin
> end
|| (begin
== end
&& vbegin
> vend
))
5521 fputs (_(" (start > end)"), stdout
);
5529 if (vbegin
!= vm1
|| vend
!= vm1
)
5530 printf (_("Trailing view pair not used in a range"));
5533 *vstart_ptr
= vstart
;
5536 /* Print a .debug_addr table index in decimal, surrounded by square brackets,
5537 right-adjusted in a field of length LEN, and followed by a space. */
5540 print_addr_index (unsigned int idx
, unsigned int len
)
5542 static char buf
[15];
5543 snprintf (buf
, sizeof (buf
), "[%d]", idx
);
5544 printf ("%*s ", len
, buf
);
5547 /* Display a location list from a .dwo section. It uses address indexes rather
5548 than embedded addresses. This code closely follows display_loc_list, but the
5549 two are sufficiently different that combining things is very ugly. */
5552 display_loc_list_dwo (struct dwarf_section
*section
,
5553 unsigned char **start_ptr
,
5554 unsigned int debug_info_entry
,
5556 unsigned char **vstart_ptr
,
5559 unsigned char *start
= *start_ptr
, *vstart
= *vstart_ptr
;
5560 unsigned char *section_end
= section
->start
+ section
->size
;
5561 unsigned long cu_offset
;
5562 unsigned int pointer_size
;
5563 unsigned int offset_size
;
5566 unsigned short length
;
5567 int need_frame_base
;
5569 unsigned int bytes_read
;
5571 if (debug_info_entry
>= num_debug_info_entries
)
5573 warn (_("No debug information for loc lists of entry: %u\n"),
5578 cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
5579 pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
5580 offset_size
= debug_information
[debug_info_entry
].offset_size
;
5581 dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
5583 if (pointer_size
< 2 || pointer_size
> 8)
5585 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
5586 pointer_size
, debug_info_entry
);
5592 printf (" %8.8lx ", (unsigned long) (offset
+ (start
- *start_ptr
)));
5594 if (start
>= section_end
)
5596 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5597 (unsigned long) offset
);
5601 SAFE_BYTE_GET_AND_INC (entry_type
, start
, 1, section_end
);
5614 dwarf_vma off
= offset
+ (vstart
- *start_ptr
);
5616 view
= read_uleb128 (vstart
, &bytes_read
, section_end
);
5617 vstart
+= bytes_read
;
5618 print_dwarf_view (view
, 8, 1);
5620 view
= read_uleb128 (vstart
, &bytes_read
, section_end
);
5621 vstart
+= bytes_read
;
5622 print_dwarf_view (view
, 8, 1);
5624 printf (_("views at %8.8lx for:\n %*s "),
5625 (unsigned long) off
, 8, "");
5633 case 0: /* A terminating entry. */
5635 *vstart_ptr
= vstart
;
5636 printf (_("<End of list>\n"));
5638 case 1: /* A base-address entry. */
5639 idx
= read_uleb128 (start
, &bytes_read
, section_end
);
5640 start
+= bytes_read
;
5641 print_addr_index (idx
, 8);
5642 printf ("%*s", 9 + (vstart
? 2 * 6 : 0), "");
5643 printf (_("(base address selection entry)\n"));
5645 case 2: /* A start/end entry. */
5646 idx
= read_uleb128 (start
, &bytes_read
, section_end
);
5647 start
+= bytes_read
;
5648 print_addr_index (idx
, 8);
5649 idx
= read_uleb128 (start
, &bytes_read
, section_end
);
5650 start
+= bytes_read
;
5651 print_addr_index (idx
, 8);
5653 case 3: /* A start/length entry. */
5654 idx
= read_uleb128 (start
, &bytes_read
, section_end
);
5655 start
+= bytes_read
;
5656 print_addr_index (idx
, 8);
5657 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
5658 printf ("%08x ", idx
);
5660 case 4: /* An offset pair entry. */
5661 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
5662 printf ("%08x ", idx
);
5663 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
5664 printf ("%08x ", idx
);
5667 warn (_("Unknown location list entry type 0x%x.\n"), entry_type
);
5669 *vstart_ptr
= vstart
;
5673 if (start
+ 2 > section_end
)
5675 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5676 (unsigned long) offset
);
5680 SAFE_BYTE_GET_AND_INC (length
, start
, 2, section_end
);
5681 if (start
+ length
> section_end
)
5683 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5684 (unsigned long) offset
);
5689 need_frame_base
= decode_location_expression (start
,
5694 cu_offset
, section
);
5697 if (need_frame_base
&& !has_frame_base
)
5698 printf (_(" [without DW_AT_frame_base]"));
5706 *vstart_ptr
= vstart
;
5709 /* Sort array of indexes in ascending order of loc_offsets[idx] and
5712 static dwarf_vma
*loc_offsets
, *loc_views
;
5715 loc_offsets_compar (const void *ap
, const void *bp
)
5717 dwarf_vma a
= loc_offsets
[*(const unsigned int *) ap
];
5718 dwarf_vma b
= loc_offsets
[*(const unsigned int *) bp
];
5720 int ret
= (a
> b
) - (b
> a
);
5724 a
= loc_views
[*(const unsigned int *) ap
];
5725 b
= loc_views
[*(const unsigned int *) bp
];
5727 ret
= (a
> b
) - (b
> a
);
5733 display_debug_loc (struct dwarf_section
*section
, void *file
)
5735 unsigned char *start
= section
->start
, *vstart
= NULL
;
5736 unsigned long bytes
;
5737 unsigned char *section_begin
= start
;
5738 unsigned int num_loc_list
= 0;
5739 unsigned long last_offset
= 0;
5740 unsigned long last_view
= 0;
5741 unsigned int first
= 0;
5744 int seen_first_offset
= 0;
5745 int locs_sorted
= 1;
5746 unsigned char *next
= start
, *vnext
= vstart
;
5747 unsigned int *array
= NULL
;
5748 const char *suffix
= strrchr (section
->name
, '.');
5750 int is_loclists
= strstr (section
->name
, "debug_loclists") != NULL
;
5751 dwarf_vma expected_start
= 0;
5753 if (suffix
&& strcmp (suffix
, ".dwo") == 0)
5756 bytes
= section
->size
;
5760 printf (_("\nThe %s section is empty.\n"), section
->name
);
5766 unsigned char *hdrptr
= section_begin
;
5767 dwarf_vma ll_length
;
5768 unsigned short ll_version
;
5769 unsigned char *end
= section_begin
+ section
->size
;
5770 unsigned char address_size
, segment_selector_size
;
5771 uint32_t offset_entry_count
;
5773 SAFE_BYTE_GET_AND_INC (ll_length
, hdrptr
, 4, end
);
5774 if (ll_length
== 0xffffffff)
5775 SAFE_BYTE_GET_AND_INC (ll_length
, hdrptr
, 8, end
);
5777 SAFE_BYTE_GET_AND_INC (ll_version
, hdrptr
, 2, end
);
5778 if (ll_version
!= 5)
5780 warn (_("The %s section contains corrupt or "
5781 "unsupported version number: %d.\n"),
5782 section
->name
, ll_version
);
5786 SAFE_BYTE_GET_AND_INC (address_size
, hdrptr
, 1, end
);
5788 SAFE_BYTE_GET_AND_INC (segment_selector_size
, hdrptr
, 1, end
);
5789 if (segment_selector_size
!= 0)
5791 warn (_("The %s section contains "
5792 "unsupported segment selector size: %d.\n"),
5793 section
->name
, segment_selector_size
);
5797 SAFE_BYTE_GET_AND_INC (offset_entry_count
, hdrptr
, 4, end
);
5798 if (offset_entry_count
!= 0)
5800 warn (_("The %s section contains "
5801 "unsupported offset entry count: %d.\n"),
5802 section
->name
, offset_entry_count
);
5806 expected_start
= hdrptr
- section_begin
;
5809 if (load_debug_info (file
) == 0)
5811 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
5816 /* Check the order of location list in .debug_info section. If
5817 offsets of location lists are in the ascending order, we can
5818 use `debug_information' directly. */
5819 for (i
= 0; i
< num_debug_info_entries
; i
++)
5823 num
= debug_information
[i
].num_loc_offsets
;
5824 if (num
> num_loc_list
)
5827 /* Check if we can use `debug_information' directly. */
5828 if (locs_sorted
&& num
!= 0)
5830 if (!seen_first_offset
)
5832 /* This is the first location list. */
5833 last_offset
= debug_information
[i
].loc_offsets
[0];
5834 last_view
= debug_information
[i
].loc_views
[0];
5836 seen_first_offset
= 1;
5842 for (; j
< num
; j
++)
5845 debug_information
[i
].loc_offsets
[j
]
5846 || (last_offset
== debug_information
[i
].loc_offsets
[j
]
5847 && last_view
> debug_information
[i
].loc_views
[j
]))
5852 last_offset
= debug_information
[i
].loc_offsets
[j
];
5853 last_view
= debug_information
[i
].loc_views
[j
];
5858 if (!seen_first_offset
)
5859 error (_("No location lists in .debug_info section!\n"));
5861 if (debug_information
[first
].num_loc_offsets
> 0
5862 && debug_information
[first
].loc_offsets
[0] != expected_start
5863 && debug_information
[first
].loc_views
[0] != expected_start
)
5864 warn (_("Location lists in %s section start at 0x%s\n"),
5866 dwarf_vmatoa ("x", debug_information
[first
].loc_offsets
[0]));
5869 array
= (unsigned int *) xcmalloc (num_loc_list
, sizeof (unsigned int));
5870 printf (_("Contents of the %s section:\n\n"), section
->name
);
5871 if (reloc_at (section
, 0))
5872 printf (_(" Warning: This section has relocations - addresses seen here may not be accurate.\n\n"));
5873 printf (_(" Offset Begin End Expression\n"));
5875 seen_first_offset
= 0;
5876 for (i
= first
; i
< num_debug_info_entries
; i
++)
5878 dwarf_vma offset
, voffset
;
5879 dwarf_vma base_address
;
5885 for (k
= 0; k
< debug_information
[i
].num_loc_offsets
; k
++)
5887 loc_offsets
= debug_information
[i
].loc_offsets
;
5888 loc_views
= debug_information
[i
].loc_views
;
5889 qsort (array
, debug_information
[i
].num_loc_offsets
,
5890 sizeof (*array
), loc_offsets_compar
);
5893 int adjacent_view_loclists
= 1;
5894 for (k
= 0; k
< debug_information
[i
].num_loc_offsets
; k
++)
5896 j
= locs_sorted
? k
: array
[k
];
5898 && (debug_information
[i
].loc_offsets
[locs_sorted
5899 ? k
- 1 : array
[k
- 1]]
5900 == debug_information
[i
].loc_offsets
[j
])
5901 && (debug_information
[i
].loc_views
[locs_sorted
5902 ? k
- 1 : array
[k
- 1]]
5903 == debug_information
[i
].loc_views
[j
]))
5905 has_frame_base
= debug_information
[i
].have_frame_base
[j
];
5906 offset
= debug_information
[i
].loc_offsets
[j
];
5907 next
= section_begin
+ offset
;
5908 voffset
= debug_information
[i
].loc_views
[j
];
5910 vnext
= section_begin
+ voffset
;
5913 base_address
= debug_information
[i
].base_address
;
5915 if (vnext
&& vnext
< next
)
5918 display_view_pair_list (section
, &vstart
, i
, next
);
5923 if (!seen_first_offset
|| !adjacent_view_loclists
)
5924 seen_first_offset
= 1;
5928 warn (_("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n"),
5929 (unsigned long) (start
- section_begin
),
5930 (unsigned long) offset
);
5931 else if (start
> next
)
5932 warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n"),
5933 (unsigned long) (start
- section_begin
),
5934 (unsigned long) offset
);
5939 if (offset
>= bytes
)
5941 warn (_("Offset 0x%lx is bigger than .debug_loc section size.\n"),
5942 (unsigned long) offset
);
5946 if (vnext
&& voffset
>= bytes
)
5948 warn (_("View Offset 0x%lx is bigger than .debug_loc section size.\n"),
5949 (unsigned long) voffset
);
5956 display_loc_list_dwo (section
, &start
, i
, offset
,
5957 &vstart
, has_frame_base
);
5959 display_loc_list (section
, &start
, i
, offset
, base_address
,
5960 &vstart
, has_frame_base
);
5965 warn (_("DWO is not yet supported.\n"));
5967 display_loclists_list (section
, &start
, i
, offset
, base_address
,
5968 &vstart
, has_frame_base
);
5971 /* FIXME: this arrangement is quite simplistic. Nothing
5972 requires locview lists to be adjacent to corresponding
5973 loclists, and a single loclist could be augmented by
5974 different locview lists, and vice-versa, unlikely as it
5975 is that it would make sense to do so. Hopefully we'll
5976 have view pair support built into loclists before we ever
5977 need to address all these possibilities. */
5978 if (adjacent_view_loclists
&& vnext
5979 && vnext
!= start
&& vstart
!= next
)
5981 adjacent_view_loclists
= 0;
5982 warn (_("Hole and overlap detection requires adjacent view lists and loclists.\n"));
5985 if (vnext
&& vnext
== start
)
5986 display_view_pair_list (section
, &start
, i
, vstart
);
5990 if (start
< section
->start
+ section
->size
)
5991 warn (ngettext ("There is %ld unused byte at the end of section %s\n",
5992 "There are %ld unused bytes at the end of section %s\n",
5993 (long) (section
->start
+ section
->size
- start
)),
5994 (long) (section
->start
+ section
->size
- start
), section
->name
);
6001 display_debug_str (struct dwarf_section
*section
,
6002 void *file ATTRIBUTE_UNUSED
)
6004 unsigned char *start
= section
->start
;
6005 unsigned long bytes
= section
->size
;
6006 dwarf_vma addr
= section
->address
;
6010 printf (_("\nThe %s section is empty.\n"), section
->name
);
6014 printf (_("Contents of the %s section:\n\n"), section
->name
);
6022 lbytes
= (bytes
> 16 ? 16 : bytes
);
6024 printf (" 0x%8.8lx ", (unsigned long) addr
);
6026 for (j
= 0; j
< 16; j
++)
6029 printf ("%2.2x", start
[j
]);
6037 for (j
= 0; j
< lbytes
; j
++)
6040 if (k
>= ' ' && k
< 0x80)
6059 display_debug_info (struct dwarf_section
*section
, void *file
)
6061 return process_debug_info (section
, file
, section
->abbrev_sec
, 0, 0);
6065 display_debug_types (struct dwarf_section
*section
, void *file
)
6067 return process_debug_info (section
, file
, section
->abbrev_sec
, 0, 1);
6071 display_trace_info (struct dwarf_section
*section
, void *file
)
6073 return process_debug_info (section
, file
, section
->abbrev_sec
, 0, 0);
6077 display_debug_aranges (struct dwarf_section
*section
,
6078 void *file ATTRIBUTE_UNUSED
)
6080 unsigned char *start
= section
->start
;
6081 unsigned char *end
= start
+ section
->size
;
6083 printf (_("Contents of the %s section:\n\n"), section
->name
);
6085 /* It does not matter if this load fails,
6086 we test for that later on. */
6087 load_debug_info (file
);
6091 unsigned char *hdrptr
;
6092 DWARF2_Internal_ARange arange
;
6093 unsigned char *addr_ranges
;
6096 unsigned long sec_off
;
6097 unsigned char address_size
;
6099 unsigned int offset_size
;
6100 unsigned int initial_length_size
;
6104 SAFE_BYTE_GET_AND_INC (arange
.ar_length
, hdrptr
, 4, end
);
6105 if (arange
.ar_length
== 0xffffffff)
6107 SAFE_BYTE_GET_AND_INC (arange
.ar_length
, hdrptr
, 8, end
);
6109 initial_length_size
= 12;
6114 initial_length_size
= 4;
6117 sec_off
= hdrptr
- section
->start
;
6118 if (sec_off
+ arange
.ar_length
< sec_off
6119 || sec_off
+ arange
.ar_length
> section
->size
)
6121 warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"),
6123 sec_off
- initial_length_size
,
6124 dwarf_vmatoa ("x", arange
.ar_length
));
6128 SAFE_BYTE_GET_AND_INC (arange
.ar_version
, hdrptr
, 2, end
);
6129 SAFE_BYTE_GET_AND_INC (arange
.ar_info_offset
, hdrptr
, offset_size
, end
);
6131 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
6132 && num_debug_info_entries
> 0
6133 && find_debug_info_for_offset (arange
.ar_info_offset
) == NULL
)
6134 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
6135 (unsigned long) arange
.ar_info_offset
, section
->name
);
6137 SAFE_BYTE_GET_AND_INC (arange
.ar_pointer_size
, hdrptr
, 1, end
);
6138 SAFE_BYTE_GET_AND_INC (arange
.ar_segment_size
, hdrptr
, 1, end
);
6140 if (arange
.ar_version
!= 2 && arange
.ar_version
!= 3)
6142 /* PR 19872: A version number of 0 probably means that there is
6143 padding at the end of the .debug_aranges section. Gold puts
6144 it there when performing an incremental link, for example.
6145 So do not generate a warning in this case. */
6146 if (arange
.ar_version
)
6147 warn (_("Only DWARF 2 and 3 aranges are currently supported.\n"));
6151 printf (_(" Length: %ld\n"),
6152 (long) arange
.ar_length
);
6153 printf (_(" Version: %d\n"), arange
.ar_version
);
6154 printf (_(" Offset into .debug_info: 0x%lx\n"),
6155 (unsigned long) arange
.ar_info_offset
);
6156 printf (_(" Pointer Size: %d\n"), arange
.ar_pointer_size
);
6157 printf (_(" Segment Size: %d\n"), arange
.ar_segment_size
);
6159 address_size
= arange
.ar_pointer_size
+ arange
.ar_segment_size
;
6161 /* PR 17512: file: 001-108546-0.001:0.1. */
6162 if (address_size
== 0 || address_size
> 8)
6164 error (_("Invalid address size in %s section!\n"),
6169 /* The DWARF spec does not require that the address size be a power
6170 of two, but we do. This will have to change if we ever encounter
6171 an uneven architecture. */
6172 if ((address_size
& (address_size
- 1)) != 0)
6174 warn (_("Pointer size + Segment size is not a power of two.\n"));
6178 if (address_size
> 4)
6179 printf (_("\n Address Length\n"));
6181 printf (_("\n Address Length\n"));
6183 addr_ranges
= hdrptr
;
6185 /* Must pad to an alignment boundary that is twice the address size. */
6186 excess
= (hdrptr
- start
) % (2 * address_size
);
6188 addr_ranges
+= (2 * address_size
) - excess
;
6190 start
+= arange
.ar_length
+ initial_length_size
;
6192 while (addr_ranges
+ 2 * address_size
<= start
)
6194 SAFE_BYTE_GET_AND_INC (address
, addr_ranges
, address_size
, end
);
6195 SAFE_BYTE_GET_AND_INC (length
, addr_ranges
, address_size
, end
);
6198 print_dwarf_vma (address
, address_size
);
6199 print_dwarf_vma (length
, address_size
);
6209 /* Comparison function for qsort. */
6211 comp_addr_base (const void * v0
, const void * v1
)
6213 debug_info
* info0
= (debug_info
*) v0
;
6214 debug_info
* info1
= (debug_info
*) v1
;
6215 return info0
->addr_base
- info1
->addr_base
;
6218 /* Display the debug_addr section. */
6220 display_debug_addr (struct dwarf_section
*section
,
6223 debug_info
**debug_addr_info
;
6224 unsigned char *entry
;
6229 if (section
->size
== 0)
6231 printf (_("\nThe %s section is empty.\n"), section
->name
);
6235 if (load_debug_info (file
) == 0)
6237 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
6242 printf (_("Contents of the %s section:\n\n"), section
->name
);
6244 /* PR 17531: file: cf38d01b.
6245 We use xcalloc because a corrupt file may not have initialised all of the
6246 fields in the debug_info structure, which means that the sort below might
6247 try to move uninitialised data. */
6248 debug_addr_info
= (debug_info
**) xcalloc ((num_debug_info_entries
+ 1),
6249 sizeof (debug_info
*));
6252 for (i
= 0; i
< num_debug_info_entries
; i
++)
6253 if (debug_information
[i
].addr_base
!= DEBUG_INFO_UNAVAILABLE
)
6255 /* PR 17531: file: cf38d01b. */
6256 if (debug_information
[i
].addr_base
>= section
->size
)
6257 warn (_("Corrupt address base (%lx) found in debug section %u\n"),
6258 (unsigned long) debug_information
[i
].addr_base
, i
);
6260 debug_addr_info
[count
++] = debug_information
+ i
;
6263 /* Add a sentinel to make iteration convenient. */
6264 debug_addr_info
[count
] = (debug_info
*) xmalloc (sizeof (debug_info
));
6265 debug_addr_info
[count
]->addr_base
= section
->size
;
6266 qsort (debug_addr_info
, count
, sizeof (debug_info
*), comp_addr_base
);
6268 for (i
= 0; i
< count
; i
++)
6271 unsigned int address_size
= debug_addr_info
[i
]->pointer_size
;
6273 printf (_(" For compilation unit at offset 0x%s:\n"),
6274 dwarf_vmatoa ("x", debug_addr_info
[i
]->cu_offset
));
6276 printf (_("\tIndex\tAddress\n"));
6277 entry
= section
->start
+ debug_addr_info
[i
]->addr_base
;
6278 end
= section
->start
+ debug_addr_info
[i
+ 1]->addr_base
;
6282 dwarf_vma base
= byte_get (entry
, address_size
);
6283 printf (_("\t%d:\t"), idx
);
6284 print_dwarf_vma (base
, address_size
);
6286 entry
+= address_size
;
6292 free (debug_addr_info
);
6296 /* Display the .debug_str_offsets and .debug_str_offsets.dwo sections. */
6298 display_debug_str_offsets (struct dwarf_section
*section
,
6299 void *file ATTRIBUTE_UNUSED
)
6301 if (section
->size
== 0)
6303 printf (_("\nThe %s section is empty.\n"), section
->name
);
6306 /* TODO: Dump the contents. This is made somewhat difficult by not knowing
6307 what the offset size is for this section. */
6311 /* Each debug_information[x].range_lists[y] gets this representation for
6312 sorting purposes. */
6316 /* The debug_information[x].range_lists[y] value. */
6317 dwarf_vma ranges_offset
;
6319 /* Original debug_information to find parameters of the data. */
6320 debug_info
*debug_info_p
;
6323 /* Sort struct range_entry in ascending order of its RANGES_OFFSET. */
6326 range_entry_compar (const void *ap
, const void *bp
)
6328 const struct range_entry
*a_re
= (const struct range_entry
*) ap
;
6329 const struct range_entry
*b_re
= (const struct range_entry
*) bp
;
6330 const dwarf_vma a
= a_re
->ranges_offset
;
6331 const dwarf_vma b
= b_re
->ranges_offset
;
6333 return (a
> b
) - (b
> a
);
6337 display_debug_ranges_list (unsigned char *start
, unsigned char *finish
,
6338 unsigned int pointer_size
, unsigned long offset
,
6339 unsigned long base_address
)
6341 while (start
< finish
)
6346 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
6347 if (start
>= finish
)
6349 SAFE_SIGNED_BYTE_GET_AND_INC (end
, start
, pointer_size
, finish
);
6351 printf (" %8.8lx ", offset
);
6353 if (begin
== 0 && end
== 0)
6355 printf (_("<End of list>\n"));
6359 /* Check base address specifiers. */
6360 if (is_max_address (begin
, pointer_size
)
6361 && !is_max_address (end
, pointer_size
))
6364 print_dwarf_vma (begin
, pointer_size
);
6365 print_dwarf_vma (end
, pointer_size
);
6366 printf ("(base address)\n");
6370 print_dwarf_vma (begin
+ base_address
, pointer_size
);
6371 print_dwarf_vma (end
+ base_address
, pointer_size
);
6374 fputs (_("(start == end)"), stdout
);
6375 else if (begin
> end
)
6376 fputs (_("(start > end)"), stdout
);
6383 display_debug_rnglists_list (unsigned char *start
, unsigned char *finish
,
6384 unsigned int pointer_size
, unsigned long offset
,
6385 unsigned long base_address
)
6387 unsigned char *next
= start
;
6391 unsigned long off
= offset
+ (start
- next
);
6392 enum dwarf_range_list_entry rlet
;
6393 /* Initialize it due to a false compiler warning. */
6394 dwarf_vma begin
= -1, length
, end
= -1;
6395 unsigned int bytes_read
;
6397 if (start
+ 1 > finish
)
6399 warn (_("Range list starting at offset 0x%lx is not terminated.\n"),
6404 printf (" %8.8lx ", off
);
6406 SAFE_BYTE_GET_AND_INC (rlet
, start
, 1, finish
);
6410 case DW_RLE_end_of_list
:
6411 printf (_("<End of list>\n"));
6413 case DW_RLE_base_address
:
6414 SAFE_BYTE_GET_AND_INC (base_address
, start
, pointer_size
, finish
);
6415 print_dwarf_vma (base_address
, pointer_size
);
6416 printf (_("(base address)\n"));
6418 case DW_RLE_start_length
:
6419 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
6420 length
= read_uleb128 (start
, &bytes_read
, finish
);
6421 start
+= bytes_read
;
6422 end
= begin
+ length
;
6424 case DW_RLE_offset_pair
:
6425 begin
= read_uleb128 (start
, &bytes_read
, finish
);
6426 start
+= bytes_read
;
6427 end
= read_uleb128 (start
, &bytes_read
, finish
);
6428 start
+= bytes_read
;
6430 case DW_RLE_start_end
:
6431 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
6432 SAFE_BYTE_GET_AND_INC (end
, start
, pointer_size
, finish
);
6435 error (_("Invalid range list entry type %d\n"), rlet
);
6436 rlet
= DW_RLE_end_of_list
;
6439 if (rlet
== DW_RLE_end_of_list
)
6441 if (rlet
== DW_RLE_base_address
)
6444 print_dwarf_vma (begin
+ base_address
, pointer_size
);
6445 print_dwarf_vma (end
+ base_address
, pointer_size
);
6448 fputs (_("(start == end)"), stdout
);
6449 else if (begin
> end
)
6450 fputs (_("(start > end)"), stdout
);
6457 display_debug_ranges (struct dwarf_section
*section
,
6458 void *file ATTRIBUTE_UNUSED
)
6460 unsigned char *start
= section
->start
;
6461 unsigned char *last_start
= start
;
6462 unsigned long bytes
= section
->size
;
6463 unsigned char *section_begin
= start
;
6464 unsigned char *finish
= start
+ bytes
;
6465 unsigned int num_range_list
, i
;
6466 struct range_entry
*range_entries
, *range_entry_fill
;
6467 int is_rnglists
= strstr (section
->name
, "debug_rnglists") != NULL
;
6468 /* Initialize it due to a false compiler warning. */
6469 unsigned char address_size
= 0;
6473 printf (_("\nThe %s section is empty.\n"), section
->name
);
6479 dwarf_vma initial_length
;
6480 unsigned int initial_length_size
;
6481 unsigned char segment_selector_size
;
6482 unsigned int offset_size
, offset_entry_count
;
6483 unsigned short version
;
6485 /* Get and check the length of the block. */
6486 SAFE_BYTE_GET_AND_INC (initial_length
, start
, 4, finish
);
6488 if (initial_length
== 0xffffffff)
6490 /* This section is 64-bit DWARF 3. */
6491 SAFE_BYTE_GET_AND_INC (initial_length
, start
, 8, finish
);
6493 initial_length_size
= 12;
6498 initial_length_size
= 4;
6501 if (initial_length
+ initial_length_size
> section
->size
)
6503 /* If the length field has a relocation against it, then we should
6504 not complain if it is inaccurate (and probably negative).
6505 It is copied from .debug_line handling code. */
6506 if (reloc_at (section
, (start
- section
->start
) - offset_size
))
6508 initial_length
= (finish
- start
) - initial_length_size
;
6512 warn (_("The length field (0x%lx) in the debug_rnglists header is wrong - the section is too small\n"),
6513 (long) initial_length
);
6518 /* Get and check the version number. */
6519 SAFE_BYTE_GET_AND_INC (version
, start
, 2, finish
);
6523 warn (_("Only DWARF version 5 debug_rnglists info "
6524 "is currently supported.\n"));
6528 SAFE_BYTE_GET_AND_INC (address_size
, start
, 1, finish
);
6530 SAFE_BYTE_GET_AND_INC (segment_selector_size
, start
, 1, finish
);
6531 if (segment_selector_size
!= 0)
6533 warn (_("The %s section contains "
6534 "unsupported segment selector size: %d.\n"),
6535 section
->name
, segment_selector_size
);
6539 SAFE_BYTE_GET_AND_INC (offset_entry_count
, start
, 4, finish
);
6540 if (offset_entry_count
!= 0)
6542 warn (_("The %s section contains "
6543 "unsupported offset entry count: %u.\n"),
6544 section
->name
, offset_entry_count
);
6549 if (load_debug_info (file
) == 0)
6551 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
6557 for (i
= 0; i
< num_debug_info_entries
; i
++)
6558 num_range_list
+= debug_information
[i
].num_range_lists
;
6560 if (num_range_list
== 0)
6562 /* This can happen when the file was compiled with -gsplit-debug
6563 which removes references to range lists from the primary .o file. */
6564 printf (_("No range lists in .debug_info section.\n"));
6568 range_entries
= (struct range_entry
*)
6569 xmalloc (sizeof (*range_entries
) * num_range_list
);
6570 range_entry_fill
= range_entries
;
6572 for (i
= 0; i
< num_debug_info_entries
; i
++)
6574 debug_info
*debug_info_p
= &debug_information
[i
];
6577 for (j
= 0; j
< debug_info_p
->num_range_lists
; j
++)
6579 range_entry_fill
->ranges_offset
= debug_info_p
->range_lists
[j
];
6580 range_entry_fill
->debug_info_p
= debug_info_p
;
6585 qsort (range_entries
, num_range_list
, sizeof (*range_entries
),
6586 range_entry_compar
);
6588 if (dwarf_check
!= 0 && range_entries
[0].ranges_offset
!= 0)
6589 warn (_("Range lists in %s section start at 0x%lx\n"),
6590 section
->name
, (unsigned long) range_entries
[0].ranges_offset
);
6592 printf (_("Contents of the %s section:\n\n"), section
->name
);
6593 printf (_(" Offset Begin End\n"));
6595 for (i
= 0; i
< num_range_list
; i
++)
6597 struct range_entry
*range_entry
= &range_entries
[i
];
6598 debug_info
*debug_info_p
= range_entry
->debug_info_p
;
6599 unsigned int pointer_size
;
6601 unsigned char *next
;
6602 dwarf_vma base_address
;
6604 pointer_size
= (is_rnglists
? address_size
: debug_info_p
->pointer_size
);
6605 offset
= range_entry
->ranges_offset
;
6606 next
= section_begin
+ offset
;
6607 base_address
= debug_info_p
->base_address
;
6609 /* PR 17512: file: 001-101485-0.001:0.1. */
6610 if (pointer_size
< 2 || pointer_size
> 8)
6612 warn (_("Corrupt pointer size (%d) in debug entry at offset %8.8lx\n"),
6613 pointer_size
, (unsigned long) offset
);
6617 if (dwarf_check
!= 0 && i
> 0)
6620 warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"),
6621 (unsigned long) (start
- section_begin
),
6622 (unsigned long) (next
- section_begin
), section
->name
);
6623 else if (start
> next
)
6625 if (next
== last_start
)
6627 warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"),
6628 (unsigned long) (start
- section_begin
),
6629 (unsigned long) (next
- section_begin
), section
->name
);
6635 (is_rnglists
? display_debug_rnglists_list
: display_debug_ranges_list
)
6636 (start
, finish
, pointer_size
, offset
, base_address
);
6640 free (range_entries
);
6645 typedef struct Frame_Chunk
6647 struct Frame_Chunk
*next
;
6648 unsigned char *chunk_start
;
6650 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
6651 short int *col_type
;
6654 unsigned int code_factor
;
6658 unsigned int cfa_reg
;
6659 dwarf_vma cfa_offset
;
6661 unsigned char fde_encoding
;
6662 unsigned char cfa_exp
;
6663 unsigned char ptr_size
;
6664 unsigned char segment_size
;
6668 static const char *const *dwarf_regnames
;
6669 static unsigned int dwarf_regnames_count
;
6671 /* A marker for a col_type that means this column was never referenced
6672 in the frame info. */
6673 #define DW_CFA_unreferenced (-1)
6675 /* Return 0 if no more space is needed, 1 if more space is needed,
6676 -1 for invalid reg. */
6679 frame_need_space (Frame_Chunk
*fc
, unsigned int reg
)
6681 unsigned int prev
= fc
->ncols
;
6683 if (reg
< (unsigned int) fc
->ncols
)
6686 if (dwarf_regnames_count
6687 && reg
> dwarf_regnames_count
)
6690 fc
->ncols
= reg
+ 1;
6691 /* PR 17512: file: 10450-2643-0.004.
6692 If reg == -1 then this can happen... */
6696 /* PR 17512: file: 2844a11d. */
6697 if (fc
->ncols
> 1024)
6699 error (_("Unfeasibly large register number: %u\n"), reg
);
6701 /* FIXME: 1024 is an arbitrary limit. Increase it if
6702 we ever encounter a valid binary that exceeds it. */
6706 fc
->col_type
= (short int *) xcrealloc (fc
->col_type
, fc
->ncols
,
6707 sizeof (short int));
6708 fc
->col_offset
= (int *) xcrealloc (fc
->col_offset
, fc
->ncols
, sizeof (int));
6709 /* PR 17512: file:002-10025-0.005. */
6710 if (fc
->col_type
== NULL
|| fc
->col_offset
== NULL
)
6712 error (_("Out of memory allocating %u columns in dwarf frame arrays\n"),
6718 while (prev
< fc
->ncols
)
6720 fc
->col_type
[prev
] = DW_CFA_unreferenced
;
6721 fc
->col_offset
[prev
] = 0;
6727 static const char *const dwarf_regnames_i386
[] =
6729 "eax", "ecx", "edx", "ebx", /* 0 - 3 */
6730 "esp", "ebp", "esi", "edi", /* 4 - 7 */
6731 "eip", "eflags", NULL
, /* 8 - 10 */
6732 "st0", "st1", "st2", "st3", /* 11 - 14 */
6733 "st4", "st5", "st6", "st7", /* 15 - 18 */
6734 NULL
, NULL
, /* 19 - 20 */
6735 "xmm0", "xmm1", "xmm2", "xmm3", /* 21 - 24 */
6736 "xmm4", "xmm5", "xmm6", "xmm7", /* 25 - 28 */
6737 "mm0", "mm1", "mm2", "mm3", /* 29 - 32 */
6738 "mm4", "mm5", "mm6", "mm7", /* 33 - 36 */
6739 "fcw", "fsw", "mxcsr", /* 37 - 39 */
6740 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
, /* 40 - 47 */
6741 "tr", "ldtr", /* 48 - 49 */
6742 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 50 - 57 */
6743 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 58 - 65 */
6744 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 66 - 73 */
6745 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 74 - 81 */
6746 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 82 - 89 */
6747 NULL
, NULL
, NULL
, /* 90 - 92 */
6748 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7" /* 93 - 100 */
6751 static const char *const dwarf_regnames_iamcu
[] =
6753 "eax", "ecx", "edx", "ebx", /* 0 - 3 */
6754 "esp", "ebp", "esi", "edi", /* 4 - 7 */
6755 "eip", "eflags", NULL
, /* 8 - 10 */
6756 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 11 - 18 */
6757 NULL
, NULL
, /* 19 - 20 */
6758 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 21 - 28 */
6759 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 29 - 36 */
6760 NULL
, NULL
, NULL
, /* 37 - 39 */
6761 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
, /* 40 - 47 */
6762 "tr", "ldtr", /* 48 - 49 */
6763 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 50 - 57 */
6764 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 58 - 65 */
6765 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 66 - 73 */
6766 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 74 - 81 */
6767 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 82 - 89 */
6768 NULL
, NULL
, NULL
, /* 90 - 92 */
6769 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
/* 93 - 100 */
6773 init_dwarf_regnames_i386 (void)
6775 dwarf_regnames
= dwarf_regnames_i386
;
6776 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_i386
);
6780 init_dwarf_regnames_iamcu (void)
6782 dwarf_regnames
= dwarf_regnames_iamcu
;
6783 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_iamcu
);
6786 static const char *const dwarf_regnames_x86_64
[] =
6788 "rax", "rdx", "rcx", "rbx",
6789 "rsi", "rdi", "rbp", "rsp",
6790 "r8", "r9", "r10", "r11",
6791 "r12", "r13", "r14", "r15",
6793 "xmm0", "xmm1", "xmm2", "xmm3",
6794 "xmm4", "xmm5", "xmm6", "xmm7",
6795 "xmm8", "xmm9", "xmm10", "xmm11",
6796 "xmm12", "xmm13", "xmm14", "xmm15",
6797 "st0", "st1", "st2", "st3",
6798 "st4", "st5", "st6", "st7",
6799 "mm0", "mm1", "mm2", "mm3",
6800 "mm4", "mm5", "mm6", "mm7",
6802 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
,
6803 "fs.base", "gs.base", NULL
, NULL
,
6805 "mxcsr", "fcw", "fsw",
6806 "xmm16", "xmm17", "xmm18", "xmm19",
6807 "xmm20", "xmm21", "xmm22", "xmm23",
6808 "xmm24", "xmm25", "xmm26", "xmm27",
6809 "xmm28", "xmm29", "xmm30", "xmm31",
6810 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 83 - 90 */
6811 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 91 - 98 */
6812 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 99 - 106 */
6813 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 107 - 114 */
6814 NULL
, NULL
, NULL
, /* 115 - 117 */
6815 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7"
6819 init_dwarf_regnames_x86_64 (void)
6821 dwarf_regnames
= dwarf_regnames_x86_64
;
6822 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_x86_64
);
6825 static const char *const dwarf_regnames_aarch64
[] =
6827 "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7",
6828 "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15",
6829 "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23",
6830 "x24", "x25", "x26", "x27", "x28", "x29", "x30", "sp",
6831 NULL
, "elr", NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
6832 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
6833 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
6834 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
6835 "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7",
6836 "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15",
6837 "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23",
6838 "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31",
6842 init_dwarf_regnames_aarch64 (void)
6844 dwarf_regnames
= dwarf_regnames_aarch64
;
6845 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_aarch64
);
6848 static const char *const dwarf_regnames_s390
[] =
6850 /* Avoid saying "r5 (r5)", so omit the names of r0-r15. */
6851 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
6852 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
6853 "f0", "f2", "f4", "f6", "f1", "f3", "f5", "f7",
6854 "f8", "f10", "f12", "f14", "f9", "f11", "f13", "f15",
6855 "cr0", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7",
6856 "cr8", "cr9", "cr10", "cr11", "cr12", "cr13", "cr14", "cr15",
6857 "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7",
6858 "a8", "a9", "a10", "a11", "a12", "a13", "a14", "a15",
6861 "v16", "v18", "v20", "v22", "v17", "v19", "v21", "v23",
6862 "v24", "v26", "v28", "v30", "v25", "v27", "v29", "v31",
6866 init_dwarf_regnames_s390 (void)
6868 dwarf_regnames
= dwarf_regnames_s390
;
6869 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_s390
);
6873 init_dwarf_regnames (unsigned int e_machine
)
6878 init_dwarf_regnames_i386 ();
6882 init_dwarf_regnames_iamcu ();
6888 init_dwarf_regnames_x86_64 ();
6892 init_dwarf_regnames_aarch64 ();
6896 init_dwarf_regnames_s390 ();
6905 regname (unsigned int regno
, int row
)
6907 static char reg
[64];
6910 && regno
< dwarf_regnames_count
6911 && dwarf_regnames
[regno
] != NULL
)
6914 return dwarf_regnames
[regno
];
6915 snprintf (reg
, sizeof (reg
), "r%d (%s)", regno
,
6916 dwarf_regnames
[regno
]);
6919 snprintf (reg
, sizeof (reg
), "r%d", regno
);
6924 frame_display_row (Frame_Chunk
*fc
, int *need_col_headers
, unsigned int *max_regs
)
6929 if (*max_regs
!= fc
->ncols
)
6930 *max_regs
= fc
->ncols
;
6932 if (*need_col_headers
)
6934 static const char *sloc
= " LOC";
6936 *need_col_headers
= 0;
6938 printf ("%-*s CFA ", eh_addr_size
* 2, sloc
);
6940 for (r
= 0; r
< *max_regs
; r
++)
6941 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
6946 printf ("%-5s ", regname (r
, 1));
6952 print_dwarf_vma (fc
->pc_begin
, eh_addr_size
);
6954 strcpy (tmp
, "exp");
6956 sprintf (tmp
, "%s%+d", regname (fc
->cfa_reg
, 1), (int) fc
->cfa_offset
);
6957 printf ("%-8s ", tmp
);
6959 for (r
= 0; r
< fc
->ncols
; r
++)
6961 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
6963 switch (fc
->col_type
[r
])
6965 case DW_CFA_undefined
:
6968 case DW_CFA_same_value
:
6972 sprintf (tmp
, "c%+d", fc
->col_offset
[r
]);
6974 case DW_CFA_val_offset
:
6975 sprintf (tmp
, "v%+d", fc
->col_offset
[r
]);
6977 case DW_CFA_register
:
6978 sprintf (tmp
, "%s", regname (fc
->col_offset
[r
], 0));
6980 case DW_CFA_expression
:
6981 strcpy (tmp
, "exp");
6983 case DW_CFA_val_expression
:
6984 strcpy (tmp
, "vexp");
6987 strcpy (tmp
, "n/a");
6990 printf ("%-5s ", tmp
);
6996 #define GET(VAR, N) SAFE_BYTE_GET_AND_INC (VAR, start, N, end)
6998 static unsigned char *
6999 read_cie (unsigned char *start
, unsigned char *end
,
7000 Frame_Chunk
**p_cie
, int *p_version
,
7001 bfd_size_type
*p_aug_len
, unsigned char **p_aug
)
7005 unsigned int length_return
;
7006 unsigned char *augmentation_data
= NULL
;
7007 bfd_size_type augmentation_data_len
= 0;
7010 /* PR 17512: file: 001-228113-0.004. */
7014 fc
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
7015 memset (fc
, 0, sizeof (Frame_Chunk
));
7017 fc
->col_type
= (short int *) xmalloc (sizeof (short int));
7018 fc
->col_offset
= (int *) xmalloc (sizeof (int));
7022 fc
->augmentation
= (char *) start
;
7023 /* PR 17512: file: 001-228113-0.004.
7024 Skip past augmentation name, but avoid running off the end of the data. */
7026 if (* start
++ == '\0')
7030 warn (_("No terminator for augmentation name\n"));
7034 if (strcmp (fc
->augmentation
, "eh") == 0)
7035 start
+= eh_addr_size
;
7039 GET (fc
->ptr_size
, 1);
7040 if (fc
->ptr_size
< 1 || fc
->ptr_size
> 8)
7042 warn (_("Invalid pointer size (%d) in CIE data\n"), fc
->ptr_size
);
7046 GET (fc
->segment_size
, 1);
7047 /* PR 17512: file: e99d2804. */
7048 if (fc
->segment_size
> 8 || fc
->segment_size
+ fc
->ptr_size
> 8)
7050 warn (_("Invalid segment size (%d) in CIE data\n"), fc
->segment_size
);
7054 eh_addr_size
= fc
->ptr_size
;
7058 fc
->ptr_size
= eh_addr_size
;
7059 fc
->segment_size
= 0;
7061 READ_ULEB (fc
->code_factor
);
7062 READ_SLEB (fc
->data_factor
);
7072 if (fc
->augmentation
[0] == 'z')
7074 READ_ULEB (augmentation_data_len
);
7075 augmentation_data
= start
;
7076 /* PR 17512: file: 11042-2589-0.004. */
7077 if (augmentation_data_len
> (bfd_size_type
) (end
- start
))
7079 warn (_("Augmentation data too long: 0x%s, expected at most %#lx\n"),
7080 dwarf_vmatoa ("x", augmentation_data_len
),
7081 (unsigned long) (end
- start
));
7084 start
+= augmentation_data_len
;
7087 if (augmentation_data_len
)
7091 unsigned char *qend
;
7093 p
= (unsigned char *) fc
->augmentation
+ 1;
7094 q
= augmentation_data
;
7095 qend
= q
+ augmentation_data_len
;
7097 while (p
< end
&& q
< qend
)
7102 q
+= 1 + size_of_encoded_value (*q
);
7104 fc
->fde_encoding
= *q
++;
7111 /* Note - it is OK if this loop terminates with q < qend.
7112 Padding may have been inserted to align the end of the CIE. */
7117 *p_version
= version
;
7120 *p_aug_len
= augmentation_data_len
;
7121 *p_aug
= augmentation_data
;
7126 /* Prints out the contents on the augmentation data array.
7127 If do_wide is not enabled, then formats the output to fit into 80 columns. */
7130 display_augmentation_data (const unsigned char * data
, const bfd_size_type len
)
7134 i
= printf (_(" Augmentation data: "));
7136 if (do_wide
|| len
< ((80 - i
) / 3))
7137 for (i
= 0; i
< len
; ++i
)
7138 printf (" %02x", data
[i
]);
7141 for (i
= 0; i
< len
; ++i
)
7143 if (i
% (80 / 3) == 0)
7145 printf (" %02x", data
[i
]);
7152 display_debug_frames (struct dwarf_section
*section
,
7153 void *file ATTRIBUTE_UNUSED
)
7155 unsigned char *start
= section
->start
;
7156 unsigned char *end
= start
+ section
->size
;
7157 unsigned char *section_start
= start
;
7158 Frame_Chunk
*chunks
= 0, *forward_refs
= 0;
7159 Frame_Chunk
*remembered_state
= 0;
7161 int is_eh
= strcmp (section
->name
, ".eh_frame") == 0;
7162 unsigned int length_return
;
7163 unsigned int max_regs
= 0;
7164 const char *bad_reg
= _("bad register: ");
7165 unsigned int saved_eh_addr_size
= eh_addr_size
;
7167 printf (_("Contents of the %s section:\n"), section
->name
);
7171 unsigned char *saved_start
;
7172 unsigned char *block_end
;
7177 int need_col_headers
= 1;
7178 unsigned char *augmentation_data
= NULL
;
7179 bfd_size_type augmentation_data_len
= 0;
7180 unsigned int encoded_ptr_size
= saved_eh_addr_size
;
7181 unsigned int offset_size
;
7182 unsigned int initial_length_size
;
7183 bfd_boolean all_nops
;
7185 saved_start
= start
;
7187 SAFE_BYTE_GET_AND_INC (length
, start
, 4, end
);
7191 printf ("\n%08lx ZERO terminator\n\n",
7192 (unsigned long)(saved_start
- section_start
));
7193 /* Skip any zero terminators that directly follow.
7194 A corrupt section size could have loaded a whole
7195 slew of zero filled memory bytes. eg
7196 PR 17512: file: 070-19381-0.004. */
7197 while (start
< end
&& * start
== 0)
7202 if (length
== 0xffffffff)
7204 SAFE_BYTE_GET_AND_INC (length
, start
, 8, end
);
7206 initial_length_size
= 12;
7211 initial_length_size
= 4;
7214 block_end
= saved_start
+ length
+ initial_length_size
;
7215 if (block_end
> end
|| block_end
< start
)
7217 warn ("Invalid length 0x%s in FDE at %#08lx\n",
7218 dwarf_vmatoa_1 (NULL
, length
, offset_size
),
7219 (unsigned long) (saved_start
- section_start
));
7223 SAFE_BYTE_GET_AND_INC (cie_id
, start
, offset_size
, end
);
7225 if (is_eh
? (cie_id
== 0) : ((offset_size
== 4 && cie_id
== DW_CIE_ID
)
7226 || (offset_size
== 8 && cie_id
== DW64_CIE_ID
)))
7231 start
= read_cie (start
, end
, &cie
, &version
,
7232 &augmentation_data_len
, &augmentation_data
);
7233 /* PR 17512: file: 027-135133-0.005. */
7240 fc
->chunk_start
= saved_start
;
7241 mreg
= max_regs
> 0 ? max_regs
- 1 : 0;
7244 if (frame_need_space (fc
, mreg
) < 0)
7246 if (fc
->fde_encoding
)
7247 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
7249 printf ("\n%08lx ", (unsigned long) (saved_start
- section_start
));
7250 print_dwarf_vma (length
, fc
->ptr_size
);
7251 print_dwarf_vma (cie_id
, offset_size
);
7253 if (do_debug_frames_interp
)
7255 printf ("CIE \"%s\" cf=%d df=%d ra=%d\n", fc
->augmentation
,
7256 fc
->code_factor
, fc
->data_factor
, fc
->ra
);
7261 printf (" Version: %d\n", version
);
7262 printf (" Augmentation: \"%s\"\n", fc
->augmentation
);
7265 printf (" Pointer Size: %u\n", fc
->ptr_size
);
7266 printf (" Segment Size: %u\n", fc
->segment_size
);
7268 printf (" Code alignment factor: %u\n", fc
->code_factor
);
7269 printf (" Data alignment factor: %d\n", fc
->data_factor
);
7270 printf (" Return address column: %d\n", fc
->ra
);
7272 if (augmentation_data_len
)
7273 display_augmentation_data (augmentation_data
, augmentation_data_len
);
7280 unsigned char *look_for
;
7281 static Frame_Chunk fde_fc
;
7282 unsigned long segment_selector
;
7286 dwarf_vma sign
= (dwarf_vma
) 1 << (offset_size
* 8 - 1);
7287 look_for
= start
- 4 - ((cie_id
^ sign
) - sign
);
7290 look_for
= section_start
+ cie_id
;
7292 if (look_for
<= saved_start
)
7294 for (cie
= chunks
; cie
; cie
= cie
->next
)
7295 if (cie
->chunk_start
== look_for
)
7300 for (cie
= forward_refs
; cie
; cie
= cie
->next
)
7301 if (cie
->chunk_start
== look_for
)
7305 unsigned int off_size
;
7306 unsigned char *cie_scan
;
7308 cie_scan
= look_for
;
7310 SAFE_BYTE_GET_AND_INC (length
, cie_scan
, 4, end
);
7311 if (length
== 0xffffffff)
7313 SAFE_BYTE_GET_AND_INC (length
, cie_scan
, 8, end
);
7320 SAFE_BYTE_GET_AND_INC (c_id
, cie_scan
, off_size
, end
);
7323 : ((off_size
== 4 && c_id
== DW_CIE_ID
)
7324 || (off_size
== 8 && c_id
== DW64_CIE_ID
)))
7329 read_cie (cie_scan
, end
, &cie
, &version
,
7330 &augmentation_data_len
, &augmentation_data
);
7331 /* PR 17512: file: 3450-2098-0.004. */
7334 warn (_("Failed to read CIE information\n"));
7337 cie
->next
= forward_refs
;
7339 cie
->chunk_start
= look_for
;
7340 mreg
= max_regs
> 0 ? max_regs
- 1 : 0;
7343 if (frame_need_space (cie
, mreg
) < 0)
7345 warn (_("Invalid max register\n"));
7348 if (cie
->fde_encoding
)
7350 = size_of_encoded_value (cie
->fde_encoding
);
7357 memset (fc
, 0, sizeof (Frame_Chunk
));
7361 warn ("Invalid CIE pointer 0x%s in FDE at %#08lx\n",
7362 dwarf_vmatoa_1 (NULL
, cie_id
, offset_size
),
7363 (unsigned long) (saved_start
- section_start
));
7365 fc
->col_type
= (short int *) xmalloc (sizeof (short int));
7366 fc
->col_offset
= (int *) xmalloc (sizeof (int));
7367 if (frame_need_space (fc
, max_regs
> 0 ? max_regs
- 1 : 0) < 0)
7369 warn (_("Invalid max register\n"));
7373 fc
->augmentation
= "";
7374 fc
->fde_encoding
= 0;
7375 fc
->ptr_size
= eh_addr_size
;
7376 fc
->segment_size
= 0;
7380 fc
->ncols
= cie
->ncols
;
7381 fc
->col_type
= (short int *) xcmalloc (fc
->ncols
, sizeof (short int));
7382 fc
->col_offset
= (int *) xcmalloc (fc
->ncols
, sizeof (int));
7383 memcpy (fc
->col_type
, cie
->col_type
, fc
->ncols
* sizeof (short int));
7384 memcpy (fc
->col_offset
, cie
->col_offset
, fc
->ncols
* sizeof (int));
7385 fc
->augmentation
= cie
->augmentation
;
7386 fc
->ptr_size
= cie
->ptr_size
;
7387 eh_addr_size
= cie
->ptr_size
;
7388 fc
->segment_size
= cie
->segment_size
;
7389 fc
->code_factor
= cie
->code_factor
;
7390 fc
->data_factor
= cie
->data_factor
;
7391 fc
->cfa_reg
= cie
->cfa_reg
;
7392 fc
->cfa_offset
= cie
->cfa_offset
;
7394 if (frame_need_space (fc
, max_regs
> 0 ? max_regs
- 1: 0) < 0)
7396 warn (_("Invalid max register\n"));
7399 fc
->fde_encoding
= cie
->fde_encoding
;
7402 if (fc
->fde_encoding
)
7403 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
7405 segment_selector
= 0;
7406 if (fc
->segment_size
)
7408 if (fc
->segment_size
> sizeof (segment_selector
))
7410 /* PR 17512: file: 9e196b3e. */
7411 warn (_("Probably corrupt segment size: %d - using 4 instead\n"), fc
->segment_size
);
7412 fc
->segment_size
= 4;
7414 SAFE_BYTE_GET_AND_INC (segment_selector
, start
, fc
->segment_size
, end
);
7417 fc
->pc_begin
= get_encoded_value (&start
, fc
->fde_encoding
, section
, end
);
7419 /* FIXME: It appears that sometimes the final pc_range value is
7420 encoded in less than encoded_ptr_size bytes. See the x86_64
7421 run of the "objcopy on compressed debug sections" test for an
7423 SAFE_BYTE_GET_AND_INC (fc
->pc_range
, start
, encoded_ptr_size
, end
);
7425 if (cie
->augmentation
[0] == 'z')
7427 READ_ULEB (augmentation_data_len
);
7428 augmentation_data
= start
;
7429 start
+= augmentation_data_len
;
7430 /* PR 17512 file: 722-8446-0.004 and PR 22386. */
7432 || ((bfd_signed_vma
) augmentation_data_len
) < 0
7433 || augmentation_data
> start
)
7435 warn (_("Corrupt augmentation data length: 0x%s\n"),
7436 dwarf_vmatoa ("x", augmentation_data_len
));
7438 augmentation_data
= NULL
;
7439 augmentation_data_len
= 0;
7443 printf ("\n%08lx %s %s FDE cie=%08lx pc=",
7444 (unsigned long)(saved_start
- section_start
),
7445 dwarf_vmatoa_1 (NULL
, length
, fc
->ptr_size
),
7446 dwarf_vmatoa_1 (NULL
, cie_id
, offset_size
),
7447 (unsigned long)(cie
->chunk_start
- section_start
));
7449 if (fc
->segment_size
)
7450 printf ("%04lx:", segment_selector
);
7453 dwarf_vmatoa_1 (NULL
, fc
->pc_begin
, fc
->ptr_size
),
7454 dwarf_vmatoa_1 (NULL
, fc
->pc_begin
+ fc
->pc_range
, fc
->ptr_size
));
7456 if (! do_debug_frames_interp
&& augmentation_data_len
)
7458 display_augmentation_data (augmentation_data
, augmentation_data_len
);
7463 /* At this point, fc is the current chunk, cie (if any) is set, and
7464 we're about to interpret instructions for the chunk. */
7465 /* ??? At present we need to do this always, since this sizes the
7466 fc->col_type and fc->col_offset arrays, which we write into always.
7467 We should probably split the interpreted and non-interpreted bits
7468 into two different routines, since there's so much that doesn't
7469 really overlap between them. */
7470 if (1 || do_debug_frames_interp
)
7472 /* Start by making a pass over the chunk, allocating storage
7473 and taking note of what registers are used. */
7474 unsigned char *tmp
= start
;
7476 while (start
< block_end
)
7478 unsigned int reg
, op
, opa
;
7480 unsigned char * new_start
;
7487 /* Warning: if you add any more cases to this switch, be
7488 sure to add them to the corresponding switch below. */
7491 case DW_CFA_advance_loc
:
7495 if (frame_need_space (fc
, opa
) >= 0)
7496 fc
->col_type
[opa
] = DW_CFA_undefined
;
7498 case DW_CFA_restore
:
7499 if (frame_need_space (fc
, opa
) >= 0)
7500 fc
->col_type
[opa
] = DW_CFA_undefined
;
7502 case DW_CFA_set_loc
:
7503 start
+= encoded_ptr_size
;
7505 case DW_CFA_advance_loc1
:
7508 case DW_CFA_advance_loc2
:
7511 case DW_CFA_advance_loc4
:
7514 case DW_CFA_offset_extended
:
7515 case DW_CFA_val_offset
:
7518 if (frame_need_space (fc
, reg
) >= 0)
7519 fc
->col_type
[reg
] = DW_CFA_undefined
;
7521 case DW_CFA_restore_extended
:
7523 if (frame_need_space (fc
, reg
) >= 0)
7524 fc
->col_type
[reg
] = DW_CFA_undefined
;
7526 case DW_CFA_undefined
:
7528 if (frame_need_space (fc
, reg
) >= 0)
7529 fc
->col_type
[reg
] = DW_CFA_undefined
;
7531 case DW_CFA_same_value
:
7533 if (frame_need_space (fc
, reg
) >= 0)
7534 fc
->col_type
[reg
] = DW_CFA_undefined
;
7536 case DW_CFA_register
:
7539 if (frame_need_space (fc
, reg
) >= 0)
7540 fc
->col_type
[reg
] = DW_CFA_undefined
;
7542 case DW_CFA_def_cfa
:
7546 case DW_CFA_def_cfa_register
:
7549 case DW_CFA_def_cfa_offset
:
7552 case DW_CFA_def_cfa_expression
:
7554 new_start
= start
+ temp
;
7555 if (new_start
< start
)
7557 warn (_("Corrupt CFA_def expression value: %lu\n"), temp
);
7563 case DW_CFA_expression
:
7564 case DW_CFA_val_expression
:
7567 new_start
= start
+ temp
;
7568 if (new_start
< start
)
7570 /* PR 17512: file:306-192417-0.005. */
7571 warn (_("Corrupt CFA expression value: %lu\n"), temp
);
7576 if (frame_need_space (fc
, reg
) >= 0)
7577 fc
->col_type
[reg
] = DW_CFA_undefined
;
7579 case DW_CFA_offset_extended_sf
:
7580 case DW_CFA_val_offset_sf
:
7583 if (frame_need_space (fc
, reg
) >= 0)
7584 fc
->col_type
[reg
] = DW_CFA_undefined
;
7586 case DW_CFA_def_cfa_sf
:
7590 case DW_CFA_def_cfa_offset_sf
:
7593 case DW_CFA_MIPS_advance_loc8
:
7596 case DW_CFA_GNU_args_size
:
7599 case DW_CFA_GNU_negative_offset_extended
:
7602 if (frame_need_space (fc
, reg
) >= 0)
7603 fc
->col_type
[reg
] = DW_CFA_undefined
;
7614 /* Now we know what registers are used, make a second pass over
7615 the chunk, this time actually printing out the info. */
7617 while (start
< block_end
)
7619 unsigned char * tmp
;
7621 unsigned long ul
, roffs
;
7622 /* Note: It is tempting to use an unsigned long for 'reg' but there
7623 are various functions, notably frame_space_needed() that assume that
7624 reg is an unsigned int. */
7629 const char *reg_prefix
= "";
7636 /* Make a note if something other than DW_CFA_nop happens. */
7637 if (op
!= DW_CFA_nop
)
7640 /* Warning: if you add any more cases to this switch, be
7641 sure to add them to the corresponding switch above. */
7644 case DW_CFA_advance_loc
:
7645 if (do_debug_frames_interp
)
7646 frame_display_row (fc
, &need_col_headers
, &max_regs
);
7648 printf (" DW_CFA_advance_loc: %d to %s\n",
7649 opa
* fc
->code_factor
,
7650 dwarf_vmatoa_1 (NULL
,
7651 fc
->pc_begin
+ opa
* fc
->code_factor
,
7653 fc
->pc_begin
+= opa
* fc
->code_factor
;
7658 if (opa
>= (unsigned int) fc
->ncols
)
7659 reg_prefix
= bad_reg
;
7660 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
7661 printf (" DW_CFA_offset: %s%s at cfa%+ld\n",
7662 reg_prefix
, regname (opa
, 0),
7663 roffs
* fc
->data_factor
);
7664 if (*reg_prefix
== '\0')
7666 fc
->col_type
[opa
] = DW_CFA_offset
;
7667 fc
->col_offset
[opa
] = roffs
* fc
->data_factor
;
7671 case DW_CFA_restore
:
7672 if (opa
>= (unsigned int) fc
->ncols
)
7673 reg_prefix
= bad_reg
;
7674 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
7675 printf (" DW_CFA_restore: %s%s\n",
7676 reg_prefix
, regname (opa
, 0));
7677 if (*reg_prefix
!= '\0')
7680 if (opa
>= (unsigned int) cie
->ncols
7681 || (do_debug_frames_interp
7682 && cie
->col_type
[opa
] == DW_CFA_unreferenced
))
7684 fc
->col_type
[opa
] = DW_CFA_undefined
;
7685 fc
->col_offset
[opa
] = 0;
7689 fc
->col_type
[opa
] = cie
->col_type
[opa
];
7690 fc
->col_offset
[opa
] = cie
->col_offset
[opa
];
7694 case DW_CFA_set_loc
:
7695 vma
= get_encoded_value (&start
, fc
->fde_encoding
, section
, block_end
);
7696 if (do_debug_frames_interp
)
7697 frame_display_row (fc
, &need_col_headers
, &max_regs
);
7699 printf (" DW_CFA_set_loc: %s\n",
7700 dwarf_vmatoa_1 (NULL
, vma
, fc
->ptr_size
));
7704 case DW_CFA_advance_loc1
:
7705 SAFE_BYTE_GET_AND_INC (ofs
, start
, 1, end
);
7706 if (do_debug_frames_interp
)
7707 frame_display_row (fc
, &need_col_headers
, &max_regs
);
7709 printf (" DW_CFA_advance_loc1: %ld to %s\n",
7710 (unsigned long) (ofs
* fc
->code_factor
),
7711 dwarf_vmatoa_1 (NULL
,
7712 fc
->pc_begin
+ ofs
* fc
->code_factor
,
7714 fc
->pc_begin
+= ofs
* fc
->code_factor
;
7717 case DW_CFA_advance_loc2
:
7718 SAFE_BYTE_GET_AND_INC (ofs
, start
, 2, block_end
);
7719 if (do_debug_frames_interp
)
7720 frame_display_row (fc
, &need_col_headers
, &max_regs
);
7722 printf (" DW_CFA_advance_loc2: %ld to %s\n",
7723 (unsigned long) (ofs
* fc
->code_factor
),
7724 dwarf_vmatoa_1 (NULL
,
7725 fc
->pc_begin
+ ofs
* fc
->code_factor
,
7727 fc
->pc_begin
+= ofs
* fc
->code_factor
;
7730 case DW_CFA_advance_loc4
:
7731 SAFE_BYTE_GET_AND_INC (ofs
, start
, 4, block_end
);
7732 if (do_debug_frames_interp
)
7733 frame_display_row (fc
, &need_col_headers
, &max_regs
);
7735 printf (" DW_CFA_advance_loc4: %ld to %s\n",
7736 (unsigned long) (ofs
* fc
->code_factor
),
7737 dwarf_vmatoa_1 (NULL
,
7738 fc
->pc_begin
+ ofs
* fc
->code_factor
,
7740 fc
->pc_begin
+= ofs
* fc
->code_factor
;
7743 case DW_CFA_offset_extended
:
7746 if (reg
>= (unsigned int) fc
->ncols
)
7747 reg_prefix
= bad_reg
;
7748 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
7749 printf (" DW_CFA_offset_extended: %s%s at cfa%+ld\n",
7750 reg_prefix
, regname (reg
, 0),
7751 roffs
* fc
->data_factor
);
7752 if (*reg_prefix
== '\0')
7754 fc
->col_type
[reg
] = DW_CFA_offset
;
7755 fc
->col_offset
[reg
] = roffs
* fc
->data_factor
;
7759 case DW_CFA_val_offset
:
7762 if (reg
>= (unsigned int) fc
->ncols
)
7763 reg_prefix
= bad_reg
;
7764 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
7765 printf (" DW_CFA_val_offset: %s%s is cfa%+ld\n",
7766 reg_prefix
, regname (reg
, 0),
7767 roffs
* fc
->data_factor
);
7768 if (*reg_prefix
== '\0')
7770 fc
->col_type
[reg
] = DW_CFA_val_offset
;
7771 fc
->col_offset
[reg
] = roffs
* fc
->data_factor
;
7775 case DW_CFA_restore_extended
:
7777 if (reg
>= (unsigned int) fc
->ncols
)
7778 reg_prefix
= bad_reg
;
7779 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
7780 printf (" DW_CFA_restore_extended: %s%s\n",
7781 reg_prefix
, regname (reg
, 0));
7782 if (*reg_prefix
!= '\0')
7785 if (reg
>= (unsigned int) cie
->ncols
)
7787 fc
->col_type
[reg
] = DW_CFA_undefined
;
7788 fc
->col_offset
[reg
] = 0;
7792 fc
->col_type
[reg
] = cie
->col_type
[reg
];
7793 fc
->col_offset
[reg
] = cie
->col_offset
[reg
];
7797 case DW_CFA_undefined
:
7799 if (reg
>= (unsigned int) fc
->ncols
)
7800 reg_prefix
= bad_reg
;
7801 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
7802 printf (" DW_CFA_undefined: %s%s\n",
7803 reg_prefix
, regname (reg
, 0));
7804 if (*reg_prefix
== '\0')
7806 fc
->col_type
[reg
] = DW_CFA_undefined
;
7807 fc
->col_offset
[reg
] = 0;
7811 case DW_CFA_same_value
:
7813 if (reg
>= (unsigned int) fc
->ncols
)
7814 reg_prefix
= bad_reg
;
7815 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
7816 printf (" DW_CFA_same_value: %s%s\n",
7817 reg_prefix
, regname (reg
, 0));
7818 if (*reg_prefix
== '\0')
7820 fc
->col_type
[reg
] = DW_CFA_same_value
;
7821 fc
->col_offset
[reg
] = 0;
7825 case DW_CFA_register
:
7828 if (reg
>= (unsigned int) fc
->ncols
)
7829 reg_prefix
= bad_reg
;
7830 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
7832 printf (" DW_CFA_register: %s%s in ",
7833 reg_prefix
, regname (reg
, 0));
7834 puts (regname (roffs
, 0));
7836 if (*reg_prefix
== '\0')
7838 fc
->col_type
[reg
] = DW_CFA_register
;
7839 fc
->col_offset
[reg
] = roffs
;
7843 case DW_CFA_remember_state
:
7844 if (! do_debug_frames_interp
)
7845 printf (" DW_CFA_remember_state\n");
7846 rs
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
7847 rs
->cfa_offset
= fc
->cfa_offset
;
7848 rs
->cfa_reg
= fc
->cfa_reg
;
7850 rs
->cfa_exp
= fc
->cfa_exp
;
7851 rs
->ncols
= fc
->ncols
;
7852 rs
->col_type
= (short int *) xcmalloc (rs
->ncols
,
7853 sizeof (* rs
->col_type
));
7854 rs
->col_offset
= (int *) xcmalloc (rs
->ncols
, sizeof (* rs
->col_offset
));
7855 memcpy (rs
->col_type
, fc
->col_type
, rs
->ncols
* sizeof (* fc
->col_type
));
7856 memcpy (rs
->col_offset
, fc
->col_offset
, rs
->ncols
* sizeof (* fc
->col_offset
));
7857 rs
->next
= remembered_state
;
7858 remembered_state
= rs
;
7861 case DW_CFA_restore_state
:
7862 if (! do_debug_frames_interp
)
7863 printf (" DW_CFA_restore_state\n");
7864 rs
= remembered_state
;
7867 remembered_state
= rs
->next
;
7868 fc
->cfa_offset
= rs
->cfa_offset
;
7869 fc
->cfa_reg
= rs
->cfa_reg
;
7871 fc
->cfa_exp
= rs
->cfa_exp
;
7872 if (frame_need_space (fc
, rs
->ncols
- 1) < 0)
7874 warn (_("Invalid column number in saved frame state\n"));
7878 memcpy (fc
->col_type
, rs
->col_type
, rs
->ncols
* sizeof (* rs
->col_type
));
7879 memcpy (fc
->col_offset
, rs
->col_offset
,
7880 rs
->ncols
* sizeof (* rs
->col_offset
));
7881 free (rs
->col_type
);
7882 free (rs
->col_offset
);
7885 else if (do_debug_frames_interp
)
7886 printf ("Mismatched DW_CFA_restore_state\n");
7889 case DW_CFA_def_cfa
:
7890 READ_ULEB (fc
->cfa_reg
);
7891 READ_ULEB (fc
->cfa_offset
);
7893 if (! do_debug_frames_interp
)
7894 printf (" DW_CFA_def_cfa: %s ofs %d\n",
7895 regname (fc
->cfa_reg
, 0), (int) fc
->cfa_offset
);
7898 case DW_CFA_def_cfa_register
:
7899 READ_ULEB (fc
->cfa_reg
);
7901 if (! do_debug_frames_interp
)
7902 printf (" DW_CFA_def_cfa_register: %s\n",
7903 regname (fc
->cfa_reg
, 0));
7906 case DW_CFA_def_cfa_offset
:
7907 READ_ULEB (fc
->cfa_offset
);
7908 if (! do_debug_frames_interp
)
7909 printf (" DW_CFA_def_cfa_offset: %d\n", (int) fc
->cfa_offset
);
7913 if (! do_debug_frames_interp
)
7914 printf (" DW_CFA_nop\n");
7917 case DW_CFA_def_cfa_expression
:
7919 if (start
>= block_end
|| ul
> (unsigned long) (block_end
- start
))
7921 printf (_(" DW_CFA_def_cfa_expression: <corrupt len %lu>\n"), ul
);
7924 if (! do_debug_frames_interp
)
7926 printf (" DW_CFA_def_cfa_expression (");
7927 decode_location_expression (start
, eh_addr_size
, 0, -1,
7935 case DW_CFA_expression
:
7938 if (reg
>= (unsigned int) fc
->ncols
)
7939 reg_prefix
= bad_reg
;
7940 /* PR 17512: file: 069-133014-0.006. */
7941 /* PR 17512: file: 98c02eb4. */
7943 if (start
>= block_end
|| tmp
> block_end
|| tmp
< start
)
7945 printf (_(" DW_CFA_expression: <corrupt len %lu>\n"), ul
);
7948 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
7950 printf (" DW_CFA_expression: %s%s (",
7951 reg_prefix
, regname (reg
, 0));
7952 decode_location_expression (start
, eh_addr_size
, 0, -1,
7956 if (*reg_prefix
== '\0')
7957 fc
->col_type
[reg
] = DW_CFA_expression
;
7961 case DW_CFA_val_expression
:
7964 if (reg
>= (unsigned int) fc
->ncols
)
7965 reg_prefix
= bad_reg
;
7967 if (start
>= block_end
|| tmp
> block_end
|| tmp
< start
)
7969 printf (" DW_CFA_val_expression: <corrupt len %lu>\n", ul
);
7972 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
7974 printf (" DW_CFA_val_expression: %s%s (",
7975 reg_prefix
, regname (reg
, 0));
7976 decode_location_expression (start
, eh_addr_size
, 0, -1,
7980 if (*reg_prefix
== '\0')
7981 fc
->col_type
[reg
] = DW_CFA_val_expression
;
7985 case DW_CFA_offset_extended_sf
:
7988 if (frame_need_space (fc
, reg
) < 0)
7989 reg_prefix
= bad_reg
;
7990 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
7991 printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+ld\n",
7992 reg_prefix
, regname (reg
, 0),
7993 (long)(l
* fc
->data_factor
));
7994 if (*reg_prefix
== '\0')
7996 fc
->col_type
[reg
] = DW_CFA_offset
;
7997 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
8001 case DW_CFA_val_offset_sf
:
8004 if (frame_need_space (fc
, reg
) < 0)
8005 reg_prefix
= bad_reg
;
8006 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
8007 printf (" DW_CFA_val_offset_sf: %s%s is cfa%+ld\n",
8008 reg_prefix
, regname (reg
, 0),
8009 (long)(l
* fc
->data_factor
));
8010 if (*reg_prefix
== '\0')
8012 fc
->col_type
[reg
] = DW_CFA_val_offset
;
8013 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
8017 case DW_CFA_def_cfa_sf
:
8018 READ_ULEB (fc
->cfa_reg
);
8019 READ_ULEB (fc
->cfa_offset
);
8020 fc
->cfa_offset
= fc
->cfa_offset
* fc
->data_factor
;
8022 if (! do_debug_frames_interp
)
8023 printf (" DW_CFA_def_cfa_sf: %s ofs %d\n",
8024 regname (fc
->cfa_reg
, 0), (int) fc
->cfa_offset
);
8027 case DW_CFA_def_cfa_offset_sf
:
8028 READ_ULEB (fc
->cfa_offset
);
8029 fc
->cfa_offset
*= fc
->data_factor
;
8030 if (! do_debug_frames_interp
)
8031 printf (" DW_CFA_def_cfa_offset_sf: %d\n", (int) fc
->cfa_offset
);
8034 case DW_CFA_MIPS_advance_loc8
:
8035 SAFE_BYTE_GET_AND_INC (ofs
, start
, 8, block_end
);
8036 if (do_debug_frames_interp
)
8037 frame_display_row (fc
, &need_col_headers
, &max_regs
);
8039 printf (" DW_CFA_MIPS_advance_loc8: %ld to %s\n",
8040 (unsigned long) (ofs
* fc
->code_factor
),
8041 dwarf_vmatoa_1 (NULL
,
8042 fc
->pc_begin
+ ofs
* fc
->code_factor
,
8044 fc
->pc_begin
+= ofs
* fc
->code_factor
;
8047 case DW_CFA_GNU_window_save
:
8048 if (! do_debug_frames_interp
)
8049 printf (" DW_CFA_GNU_window_save\n");
8052 case DW_CFA_GNU_args_size
:
8054 if (! do_debug_frames_interp
)
8055 printf (" DW_CFA_GNU_args_size: %ld\n", ul
);
8058 case DW_CFA_GNU_negative_offset_extended
:
8062 if (frame_need_space (fc
, reg
) < 0)
8063 reg_prefix
= bad_reg
;
8064 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
8065 printf (" DW_CFA_GNU_negative_offset_extended: %s%s at cfa%+ld\n",
8066 reg_prefix
, regname (reg
, 0),
8067 (long)(l
* fc
->data_factor
));
8068 if (*reg_prefix
== '\0')
8070 fc
->col_type
[reg
] = DW_CFA_offset
;
8071 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
8076 if (op
>= DW_CFA_lo_user
&& op
<= DW_CFA_hi_user
)
8077 printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op
);
8079 warn (_("Unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op
);
8084 /* Interpret the CFA - as long as it is not completely full of NOPs. */
8085 if (do_debug_frames_interp
&& ! all_nops
)
8086 frame_display_row (fc
, &need_col_headers
, &max_regs
);
8089 eh_addr_size
= saved_eh_addr_size
;
8100 display_debug_names (struct dwarf_section
*section
, void *file
)
8102 unsigned char *hdrptr
= section
->start
;
8103 dwarf_vma unit_length
;
8104 unsigned char *unit_start
;
8105 const unsigned char *const section_end
= section
->start
+ section
->size
;
8106 unsigned char *unit_end
;
8108 printf (_("Contents of the %s section:\n"), section
->name
);
8110 load_debug_section (str
, file
);
8112 for (; hdrptr
< section_end
; hdrptr
= unit_end
)
8114 unsigned int offset_size
;
8115 uint16_t dwarf_version
, padding
;
8116 uint32_t comp_unit_count
, local_type_unit_count
, foreign_type_unit_count
;
8117 uint32_t bucket_count
, name_count
, abbrev_table_size
;
8118 uint32_t augmentation_string_size
;
8120 unsigned long sec_off
;
8122 unit_start
= hdrptr
;
8124 /* Get and check the length of the block. */
8125 SAFE_BYTE_GET_AND_INC (unit_length
, hdrptr
, 4, section_end
);
8127 if (unit_length
== 0xffffffff)
8129 /* This section is 64-bit DWARF. */
8130 SAFE_BYTE_GET_AND_INC (unit_length
, hdrptr
, 8, section_end
);
8135 unit_end
= hdrptr
+ unit_length
;
8137 sec_off
= hdrptr
- section
->start
;
8138 if (sec_off
+ unit_length
< sec_off
8139 || sec_off
+ unit_length
> section
->size
)
8141 warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"),
8143 (unsigned long) (unit_start
- section
->start
),
8144 dwarf_vmatoa ("x", unit_length
));
8148 /* Get and check the version number. */
8149 SAFE_BYTE_GET_AND_INC (dwarf_version
, hdrptr
, 2, unit_end
);
8150 printf (_("Version %ld\n"), (long) dwarf_version
);
8152 /* Prior versions did not exist, and future versions may not be
8153 backwards compatible. */
8154 if (dwarf_version
!= 5)
8156 warn (_("Only DWARF version 5 .debug_names "
8157 "is currently supported.\n"));
8161 SAFE_BYTE_GET_AND_INC (padding
, hdrptr
, 2, unit_end
);
8163 warn (_("Padding field of .debug_names must be 0 (found 0x%x)\n"),
8166 SAFE_BYTE_GET_AND_INC (comp_unit_count
, hdrptr
, 4, unit_end
);
8167 if (comp_unit_count
== 0)
8168 warn (_("Compilation unit count must be >= 1 in .debug_names\n"));
8170 SAFE_BYTE_GET_AND_INC (local_type_unit_count
, hdrptr
, 4, unit_end
);
8171 SAFE_BYTE_GET_AND_INC (foreign_type_unit_count
, hdrptr
, 4, unit_end
);
8172 SAFE_BYTE_GET_AND_INC (bucket_count
, hdrptr
, 4, unit_end
);
8173 SAFE_BYTE_GET_AND_INC (name_count
, hdrptr
, 4, unit_end
);
8174 SAFE_BYTE_GET_AND_INC (abbrev_table_size
, hdrptr
, 4, unit_end
);
8176 SAFE_BYTE_GET_AND_INC (augmentation_string_size
, hdrptr
, 4, unit_end
);
8177 if (augmentation_string_size
% 4 != 0)
8179 warn (_("Augmentation string length %u must be rounded up "
8180 "to a multiple of 4 in .debug_names.\n"),
8181 augmentation_string_size
);
8182 augmentation_string_size
+= (-augmentation_string_size
) & 3;
8184 printf (_("Augmentation string:"));
8185 for (i
= 0; i
< augmentation_string_size
; i
++)
8189 SAFE_BYTE_GET_AND_INC (uc
, hdrptr
, 1, unit_end
);
8190 printf (" %02x", uc
);
8195 printf (_("CU table:\n"));
8196 for (i
= 0; i
< comp_unit_count
; i
++)
8200 SAFE_BYTE_GET_AND_INC (cu_offset
, hdrptr
, offset_size
, unit_end
);
8201 printf (_("[%3u] 0x%lx\n"), i
, (unsigned long) cu_offset
);
8205 printf (_("TU table:\n"));
8206 for (i
= 0; i
< local_type_unit_count
; i
++)
8210 SAFE_BYTE_GET_AND_INC (tu_offset
, hdrptr
, offset_size
, unit_end
);
8211 printf (_("[%3u] 0x%lx\n"), i
, (unsigned long) tu_offset
);
8215 printf (_("Foreign TU table:\n"));
8216 for (i
= 0; i
< foreign_type_unit_count
; i
++)
8220 SAFE_BYTE_GET_AND_INC (signature
, hdrptr
, 8, unit_end
);
8221 printf (_("[%3u] "), i
);
8222 print_dwarf_vma (signature
, 8);
8227 const uint32_t *const hash_table_buckets
= (uint32_t *) hdrptr
;
8228 hdrptr
+= bucket_count
* sizeof (uint32_t);
8229 const uint32_t *const hash_table_hashes
= (uint32_t *) hdrptr
;
8230 hdrptr
+= name_count
* sizeof (uint32_t);
8231 unsigned char *const name_table_string_offsets
= hdrptr
;
8232 hdrptr
+= name_count
* offset_size
;
8233 unsigned char *const name_table_entry_offsets
= hdrptr
;
8234 hdrptr
+= name_count
* offset_size
;
8235 unsigned char *const abbrev_table
= hdrptr
;
8236 hdrptr
+= abbrev_table_size
;
8237 const unsigned char *const abbrev_table_end
= hdrptr
;
8238 unsigned char *const entry_pool
= hdrptr
;
8239 if (hdrptr
> unit_end
)
8241 warn (_("Entry pool offset (0x%lx) exceeds unit size 0x%lx "
8242 "for unit 0x%lx in the debug_names\n"),
8243 (long) (hdrptr
- section
->start
),
8244 (long) (unit_end
- section
->start
),
8245 (long) (unit_start
- section
->start
));
8249 size_t buckets_filled
= 0;
8251 for (bucketi
= 0; bucketi
< bucket_count
; bucketi
++)
8253 const uint32_t bucket
= hash_table_buckets
[bucketi
];
8258 printf (ngettext ("Used %zu of %lu bucket.\n",
8259 "Used %zu of %lu buckets.\n",
8261 buckets_filled
, (unsigned long) bucket_count
);
8263 uint32_t hash_prev
= 0;
8264 size_t hash_clash_count
= 0;
8265 size_t longest_clash
= 0;
8266 size_t this_length
= 0;
8268 for (hashi
= 0; hashi
< name_count
; hashi
++)
8270 const uint32_t hash_this
= hash_table_hashes
[hashi
];
8274 if (hash_prev
% bucket_count
== hash_this
% bucket_count
)
8278 longest_clash
= MAX (longest_clash
, this_length
);
8283 hash_prev
= hash_this
;
8285 printf (_("Out of %lu items there are %zu bucket clashes"
8286 " (longest of %zu entries).\n"),
8287 (unsigned long) name_count
, hash_clash_count
, longest_clash
);
8288 assert (name_count
== buckets_filled
+ hash_clash_count
);
8290 struct abbrev_lookup_entry
8292 dwarf_vma abbrev_tag
;
8293 unsigned char *abbrev_lookup_ptr
;
8295 struct abbrev_lookup_entry
*abbrev_lookup
= NULL
;
8296 size_t abbrev_lookup_used
= 0;
8297 size_t abbrev_lookup_allocated
= 0;
8299 unsigned char *abbrevptr
= abbrev_table
;
8302 unsigned int bytes_read
;
8303 const dwarf_vma abbrev_tag
= read_uleb128 (abbrevptr
, &bytes_read
,
8305 abbrevptr
+= bytes_read
;
8306 if (abbrev_tag
== 0)
8308 if (abbrev_lookup_used
== abbrev_lookup_allocated
)
8310 abbrev_lookup_allocated
= MAX (0x100,
8311 abbrev_lookup_allocated
* 2);
8312 abbrev_lookup
= xrealloc (abbrev_lookup
,
8313 (abbrev_lookup_allocated
8314 * sizeof (*abbrev_lookup
)));
8316 assert (abbrev_lookup_used
< abbrev_lookup_allocated
);
8317 struct abbrev_lookup_entry
*entry
;
8318 for (entry
= abbrev_lookup
;
8319 entry
< abbrev_lookup
+ abbrev_lookup_used
;
8321 if (entry
->abbrev_tag
== abbrev_tag
)
8323 warn (_("Duplicate abbreviation tag %lu "
8324 "in unit 0x%lx in the debug_names\n"),
8325 (long) abbrev_tag
, (long) (unit_start
- section
->start
));
8328 entry
= &abbrev_lookup
[abbrev_lookup_used
++];
8329 entry
->abbrev_tag
= abbrev_tag
;
8330 entry
->abbrev_lookup_ptr
= abbrevptr
;
8332 /* Skip DWARF tag. */
8333 read_uleb128 (abbrevptr
, &bytes_read
, abbrev_table_end
);
8334 abbrevptr
+= bytes_read
;
8337 const dwarf_vma xindex
= read_uleb128 (abbrevptr
,
8340 abbrevptr
+= bytes_read
;
8341 const dwarf_vma form
= read_uleb128 (abbrevptr
, &bytes_read
,
8343 abbrevptr
+= bytes_read
;
8344 if (xindex
== 0 && form
== 0)
8349 printf (_("\nSymbol table:\n"));
8351 for (namei
= 0; namei
< name_count
; ++namei
)
8353 uint64_t string_offset
, entry_offset
;
8355 SAFE_BYTE_GET (string_offset
,
8356 name_table_string_offsets
+ namei
* offset_size
,
8357 offset_size
, unit_end
);
8358 SAFE_BYTE_GET (entry_offset
,
8359 name_table_entry_offsets
+ namei
* offset_size
,
8360 offset_size
, unit_end
);
8362 printf ("[%3u] #%08x %s:", namei
, hash_table_hashes
[namei
],
8363 fetch_indirect_string (string_offset
));
8365 unsigned char *entryptr
= entry_pool
+ entry_offset
;
8367 // We need to scan first whether there is a single or multiple
8368 // entries. TAGNO is -2 for the first entry, it is -1 for the
8369 // initial tag read of the second entry, then it becomes 0 for the
8370 // first entry for real printing etc.
8372 /* Initialize it due to a false compiler warning. */
8373 dwarf_vma second_abbrev_tag
= -1;
8376 unsigned int bytes_read
;
8377 const dwarf_vma abbrev_tag
= read_uleb128 (entryptr
, &bytes_read
,
8379 entryptr
+= bytes_read
;
8382 second_abbrev_tag
= abbrev_tag
;
8384 entryptr
= entry_pool
+ entry_offset
;
8387 if (abbrev_tag
== 0)
8391 (tagno
== 0 && second_abbrev_tag
== 0 ? " " : "\n\t"),
8392 (unsigned long) abbrev_tag
);
8394 const struct abbrev_lookup_entry
*entry
;
8395 for (entry
= abbrev_lookup
;
8396 entry
< abbrev_lookup
+ abbrev_lookup_used
;
8398 if (entry
->abbrev_tag
== abbrev_tag
)
8400 if (entry
>= abbrev_lookup
+ abbrev_lookup_used
)
8402 warn (_("Undefined abbreviation tag %lu "
8403 "in unit 0x%lx in the debug_names\n"),
8405 (long) (unit_start
- section
->start
));
8408 abbrevptr
= entry
->abbrev_lookup_ptr
;
8409 const dwarf_vma dwarf_tag
= read_uleb128 (abbrevptr
, &bytes_read
,
8411 abbrevptr
+= bytes_read
;
8413 printf (" %s", get_TAG_name (dwarf_tag
));
8416 const dwarf_vma xindex
= read_uleb128 (abbrevptr
,
8419 abbrevptr
+= bytes_read
;
8420 const dwarf_vma form
= read_uleb128 (abbrevptr
, &bytes_read
,
8422 abbrevptr
+= bytes_read
;
8423 if (xindex
== 0 && form
== 0)
8427 printf (" %s", get_IDX_name (xindex
));
8428 entryptr
= read_and_display_attr_value (0, form
, 0, entryptr
,
8431 dwarf_version
, NULL
,
8438 printf (_(" <no entries>"));
8442 free (abbrev_lookup
);
8449 display_gdb_index (struct dwarf_section
*section
,
8450 void *file ATTRIBUTE_UNUSED
)
8452 unsigned char *start
= section
->start
;
8454 uint32_t cu_list_offset
, tu_list_offset
;
8455 uint32_t address_table_offset
, symbol_table_offset
, constant_pool_offset
;
8456 unsigned int cu_list_elements
, tu_list_elements
;
8457 unsigned int address_table_size
, symbol_table_slots
;
8458 unsigned char *cu_list
, *tu_list
;
8459 unsigned char *address_table
, *symbol_table
, *constant_pool
;
8462 /* The documentation for the format of this file is in gdb/dwarf2read.c. */
8464 printf (_("Contents of the %s section:\n"), section
->name
);
8466 if (section
->size
< 6 * sizeof (uint32_t))
8468 warn (_("Truncated header in the %s section.\n"), section
->name
);
8472 version
= byte_get_little_endian (start
, 4);
8473 printf (_("Version %ld\n"), (long) version
);
8475 /* Prior versions are obsolete, and future versions may not be
8476 backwards compatible. */
8477 if (version
< 3 || version
> 8)
8479 warn (_("Unsupported version %lu.\n"), (unsigned long) version
);
8483 warn (_("The address table data in version 3 may be wrong.\n"));
8485 warn (_("Version 4 does not support case insensitive lookups.\n"));
8487 warn (_("Version 5 does not include inlined functions.\n"));
8489 warn (_("Version 6 does not include symbol attributes.\n"));
8490 /* Version 7 indices generated by Gold have bad type unit references,
8491 PR binutils/15021. But we don't know if the index was generated by
8492 Gold or not, so to avoid worrying users with gdb-generated indices
8493 we say nothing for version 7 here. */
8495 cu_list_offset
= byte_get_little_endian (start
+ 4, 4);
8496 tu_list_offset
= byte_get_little_endian (start
+ 8, 4);
8497 address_table_offset
= byte_get_little_endian (start
+ 12, 4);
8498 symbol_table_offset
= byte_get_little_endian (start
+ 16, 4);
8499 constant_pool_offset
= byte_get_little_endian (start
+ 20, 4);
8501 if (cu_list_offset
> section
->size
8502 || tu_list_offset
> section
->size
8503 || address_table_offset
> section
->size
8504 || symbol_table_offset
> section
->size
8505 || constant_pool_offset
> section
->size
)
8507 warn (_("Corrupt header in the %s section.\n"), section
->name
);
8511 /* PR 17531: file: 418d0a8a. */
8512 if (tu_list_offset
< cu_list_offset
)
8514 warn (_("TU offset (%x) is less than CU offset (%x)\n"),
8515 tu_list_offset
, cu_list_offset
);
8519 cu_list_elements
= (tu_list_offset
- cu_list_offset
) / 8;
8521 if (address_table_offset
< tu_list_offset
)
8523 warn (_("Address table offset (%x) is less than TU offset (%x)\n"),
8524 address_table_offset
, tu_list_offset
);
8528 tu_list_elements
= (address_table_offset
- tu_list_offset
) / 8;
8530 /* PR 17531: file: 18a47d3d. */
8531 if (symbol_table_offset
< address_table_offset
)
8533 warn (_("Symbol table offset (%x) is less then Address table offset (%x)\n"),
8534 symbol_table_offset
, address_table_offset
);
8538 address_table_size
= symbol_table_offset
- address_table_offset
;
8540 if (constant_pool_offset
< symbol_table_offset
)
8542 warn (_("Constant pool offset (%x) is less than symbol table offset (%x)\n"),
8543 constant_pool_offset
, symbol_table_offset
);
8547 symbol_table_slots
= (constant_pool_offset
- symbol_table_offset
) / 8;
8549 cu_list
= start
+ cu_list_offset
;
8550 tu_list
= start
+ tu_list_offset
;
8551 address_table
= start
+ address_table_offset
;
8552 symbol_table
= start
+ symbol_table_offset
;
8553 constant_pool
= start
+ constant_pool_offset
;
8555 if (address_table
+ address_table_size
> section
->start
+ section
->size
)
8557 warn (_("Address table extends beyond end of section.\n"));
8561 printf (_("\nCU table:\n"));
8562 for (i
= 0; i
< cu_list_elements
; i
+= 2)
8564 uint64_t cu_offset
= byte_get_little_endian (cu_list
+ i
* 8, 8);
8565 uint64_t cu_length
= byte_get_little_endian (cu_list
+ i
* 8 + 8, 8);
8567 printf (_("[%3u] 0x%lx - 0x%lx\n"), i
/ 2,
8568 (unsigned long) cu_offset
,
8569 (unsigned long) (cu_offset
+ cu_length
- 1));
8572 printf (_("\nTU table:\n"));
8573 for (i
= 0; i
< tu_list_elements
; i
+= 3)
8575 uint64_t tu_offset
= byte_get_little_endian (tu_list
+ i
* 8, 8);
8576 uint64_t type_offset
= byte_get_little_endian (tu_list
+ i
* 8 + 8, 8);
8577 uint64_t signature
= byte_get_little_endian (tu_list
+ i
* 8 + 16, 8);
8579 printf (_("[%3u] 0x%lx 0x%lx "), i
/ 3,
8580 (unsigned long) tu_offset
,
8581 (unsigned long) type_offset
);
8582 print_dwarf_vma (signature
, 8);
8586 printf (_("\nAddress table:\n"));
8587 for (i
= 0; i
< address_table_size
&& i
<= address_table_size
- (2 * 8 + 4);
8590 uint64_t low
= byte_get_little_endian (address_table
+ i
, 8);
8591 uint64_t high
= byte_get_little_endian (address_table
+ i
+ 8, 8);
8592 uint32_t cu_index
= byte_get_little_endian (address_table
+ i
+ 16, 4);
8594 print_dwarf_vma (low
, 8);
8595 print_dwarf_vma (high
, 8);
8596 printf (_("%lu\n"), (unsigned long) cu_index
);
8599 printf (_("\nSymbol table:\n"));
8600 for (i
= 0; i
< symbol_table_slots
; ++i
)
8602 uint32_t name_offset
= byte_get_little_endian (symbol_table
+ i
* 8, 4);
8603 uint32_t cu_vector_offset
= byte_get_little_endian (symbol_table
+ i
* 8 + 4, 4);
8604 uint32_t num_cus
, cu
;
8606 if (name_offset
!= 0
8607 || cu_vector_offset
!= 0)
8610 unsigned char * adr
;
8612 adr
= constant_pool
+ name_offset
;
8613 /* PR 17531: file: 5b7b07ad. */
8614 if (adr
< constant_pool
|| adr
>= section
->start
+ section
->size
)
8616 printf (_("[%3u] <corrupt offset: %x>"), i
, name_offset
);
8617 warn (_("Corrupt name offset of 0x%x found for symbol table slot %d\n"),
8621 printf ("[%3u] %.*s:", i
,
8622 (int) (section
->size
- (constant_pool_offset
+ name_offset
)),
8623 constant_pool
+ name_offset
);
8625 adr
= constant_pool
+ cu_vector_offset
;
8626 if (adr
< constant_pool
|| adr
>= section
->start
+ section
->size
- 3)
8628 printf (_("<invalid CU vector offset: %x>\n"), cu_vector_offset
);
8629 warn (_("Corrupt CU vector offset of 0x%x found for symbol table slot %d\n"),
8630 cu_vector_offset
, i
);
8634 num_cus
= byte_get_little_endian (adr
, 4);
8636 adr
= constant_pool
+ cu_vector_offset
+ 4 + num_cus
* 4;
8637 if (num_cus
* 4 < num_cus
8638 || adr
>= section
->start
+ section
->size
8639 || adr
< constant_pool
)
8641 printf ("<invalid number of CUs: %d>\n", num_cus
);
8642 warn (_("Invalid number of CUs (0x%x) for symbol table slot %d\n"),
8650 for (j
= 0; j
< num_cus
; ++j
)
8653 gdb_index_symbol_kind kind
;
8655 cu
= byte_get_little_endian (constant_pool
+ cu_vector_offset
+ 4 + j
* 4, 4);
8656 is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu
);
8657 kind
= GDB_INDEX_SYMBOL_KIND_VALUE (cu
);
8658 cu
= GDB_INDEX_CU_VALUE (cu
);
8659 /* Convert to TU number if it's for a type unit. */
8660 if (cu
>= cu_list_elements
/ 2)
8661 printf ("%cT%lu", num_cus
> 1 ? '\t' : ' ',
8662 (unsigned long) (cu
- cu_list_elements
/ 2));
8664 printf ("%c%lu", num_cus
> 1 ? '\t' : ' ', (unsigned long) cu
);
8666 printf (" [%s, %s]",
8667 is_static
? _("static") : _("global"),
8668 get_gdb_index_symbol_kind_name (kind
));
8680 /* Pre-allocate enough space for the CU/TU sets needed. */
8683 prealloc_cu_tu_list (unsigned int nshndx
)
8685 if (shndx_pool
== NULL
)
8687 shndx_pool_size
= nshndx
;
8688 shndx_pool_used
= 0;
8689 shndx_pool
= (unsigned int *) xcmalloc (shndx_pool_size
,
8690 sizeof (unsigned int));
8694 shndx_pool_size
= shndx_pool_used
+ nshndx
;
8695 shndx_pool
= (unsigned int *) xcrealloc (shndx_pool
, shndx_pool_size
,
8696 sizeof (unsigned int));
8701 add_shndx_to_cu_tu_entry (unsigned int shndx
)
8703 if (shndx_pool_used
>= shndx_pool_size
)
8705 error (_("Internal error: out of space in the shndx pool.\n"));
8708 shndx_pool
[shndx_pool_used
++] = shndx
;
8712 end_cu_tu_entry (void)
8714 if (shndx_pool_used
>= shndx_pool_size
)
8716 error (_("Internal error: out of space in the shndx pool.\n"));
8719 shndx_pool
[shndx_pool_used
++] = 0;
8722 /* Return the short name of a DWARF section given by a DW_SECT enumerator. */
8725 get_DW_SECT_short_name (unsigned int dw_sect
)
8727 static char buf
[16];
8735 case DW_SECT_ABBREV
:
8741 case DW_SECT_STR_OFFSETS
:
8743 case DW_SECT_MACINFO
:
8751 snprintf (buf
, sizeof (buf
), "%d", dw_sect
);
8755 /* Process a CU or TU index. If DO_DISPLAY is true, print the contents.
8756 These sections are extensions for Fission.
8757 See http://gcc.gnu.org/wiki/DebugFissionDWP. */
8760 process_cu_tu_index (struct dwarf_section
*section
, int do_display
)
8762 unsigned char *phdr
= section
->start
;
8763 unsigned char *limit
= phdr
+ section
->size
;
8764 unsigned char *phash
;
8765 unsigned char *pindex
;
8766 unsigned char *ppool
;
8767 unsigned int version
;
8768 unsigned int ncols
= 0;
8770 unsigned int nslots
;
8773 dwarf_vma signature_high
;
8774 dwarf_vma signature_low
;
8777 /* PR 17512: file: 002-168123-0.004. */
8780 warn (_("Section %s is empty\n"), section
->name
);
8783 /* PR 17512: file: 002-376-0.004. */
8784 if (section
->size
< 24)
8786 warn (_("Section %s is too small to contain a CU/TU header\n"),
8791 SAFE_BYTE_GET (version
, phdr
, 4, limit
);
8793 SAFE_BYTE_GET (ncols
, phdr
+ 4, 4, limit
);
8794 SAFE_BYTE_GET (nused
, phdr
+ 8, 4, limit
);
8795 SAFE_BYTE_GET (nslots
, phdr
+ 12, 4, limit
);
8798 pindex
= phash
+ nslots
* 8;
8799 ppool
= pindex
+ nslots
* 4;
8801 /* PR 17531: file: 45d69832. */
8802 if (pindex
< phash
|| ppool
< phdr
|| (pindex
== phash
&& nslots
!= 0))
8804 warn (ngettext ("Section %s is too small for %d slot\n",
8805 "Section %s is too small for %d slots\n",
8807 section
->name
, nslots
);
8813 printf (_("Contents of the %s section:\n\n"), section
->name
);
8814 printf (_(" Version: %d\n"), version
);
8816 printf (_(" Number of columns: %d\n"), ncols
);
8817 printf (_(" Number of used entries: %d\n"), nused
);
8818 printf (_(" Number of slots: %d\n\n"), nslots
);
8821 if (ppool
> limit
|| ppool
< phdr
)
8823 warn (_("Section %s too small for %d hash table entries\n"),
8824 section
->name
, nslots
);
8831 prealloc_cu_tu_list ((limit
- ppool
) / 4);
8832 for (i
= 0; i
< nslots
; i
++)
8834 unsigned char *shndx_list
;
8837 SAFE_BYTE_GET64 (phash
, &signature_high
, &signature_low
, limit
);
8838 if (signature_high
!= 0 || signature_low
!= 0)
8840 SAFE_BYTE_GET (j
, pindex
, 4, limit
);
8841 shndx_list
= ppool
+ j
* 4;
8842 /* PR 17531: file: 705e010d. */
8843 if (shndx_list
< ppool
)
8845 warn (_("Section index pool located before start of section\n"));
8850 printf (_(" [%3d] Signature: 0x%s Sections: "),
8851 i
, dwarf_vmatoa64 (signature_high
, signature_low
,
8852 buf
, sizeof (buf
)));
8855 if (shndx_list
>= limit
)
8857 warn (_("Section %s too small for shndx pool\n"),
8861 SAFE_BYTE_GET (shndx
, shndx_list
, 4, limit
);
8865 printf (" %d", shndx
);
8867 add_shndx_to_cu_tu_entry (shndx
);
8879 else if (version
== 2)
8882 unsigned int dw_sect
;
8883 unsigned char *ph
= phash
;
8884 unsigned char *pi
= pindex
;
8885 unsigned char *poffsets
= ppool
+ ncols
* 4;
8886 unsigned char *psizes
= poffsets
+ nused
* ncols
* 4;
8887 unsigned char *pend
= psizes
+ nused
* ncols
* 4;
8888 bfd_boolean is_tu_index
;
8889 struct cu_tu_set
*this_set
= NULL
;
8891 unsigned char *prow
;
8893 is_tu_index
= strcmp (section
->name
, ".debug_tu_index") == 0;
8895 /* PR 17531: file: 0dd159bf.
8896 Check for wraparound with an overlarge ncols value. */
8897 if (poffsets
< ppool
|| (unsigned int) ((poffsets
- ppool
) / 4) != ncols
)
8899 warn (_("Overlarge number of columns: %x\n"), ncols
);
8905 warn (_("Section %s too small for offset and size tables\n"),
8912 printf (_(" Offset table\n"));
8913 printf (" slot %-16s ",
8914 is_tu_index
? _("signature") : _("dwo_id"));
8921 tu_sets
= xcalloc2 (nused
, sizeof (struct cu_tu_set
));
8927 cu_sets
= xcalloc2 (nused
, sizeof (struct cu_tu_set
));
8934 for (j
= 0; j
< ncols
; j
++)
8936 SAFE_BYTE_GET (dw_sect
, ppool
+ j
* 4, 4, limit
);
8937 printf (" %8s", get_DW_SECT_short_name (dw_sect
));
8942 for (i
= 0; i
< nslots
; i
++)
8944 SAFE_BYTE_GET64 (ph
, &signature_high
, &signature_low
, limit
);
8946 SAFE_BYTE_GET (row
, pi
, 4, limit
);
8949 /* PR 17531: file: a05f6ab3. */
8952 warn (_("Row index (%u) is larger than number of used entries (%u)\n"),
8958 memcpy (&this_set
[row
- 1].signature
, ph
, sizeof (uint64_t));
8960 prow
= poffsets
+ (row
- 1) * ncols
* 4;
8961 /* PR 17531: file: b8ce60a8. */
8962 if (prow
< poffsets
|| prow
> limit
)
8964 warn (_("Row index (%u) * num columns (%u) > space remaining in section\n"),
8970 printf (_(" [%3d] 0x%s"),
8971 i
, dwarf_vmatoa64 (signature_high
, signature_low
,
8972 buf
, sizeof (buf
)));
8973 for (j
= 0; j
< ncols
; j
++)
8975 SAFE_BYTE_GET (val
, prow
+ j
* 4, 4, limit
);
8977 printf (" %8d", val
);
8980 SAFE_BYTE_GET (dw_sect
, ppool
+ j
* 4, 4, limit
);
8982 /* PR 17531: file: 10796eb3. */
8983 if (dw_sect
>= DW_SECT_MAX
)
8984 warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect
);
8986 this_set
[row
- 1].section_offsets
[dw_sect
] = val
;
9002 printf (_(" Size table\n"));
9003 printf (" slot %-16s ",
9004 is_tu_index
? _("signature") : _("dwo_id"));
9007 for (j
= 0; j
< ncols
; j
++)
9009 SAFE_BYTE_GET (val
, ppool
+ j
* 4, 4, limit
);
9011 printf (" %8s", get_DW_SECT_short_name (val
));
9017 for (i
= 0; i
< nslots
; i
++)
9019 SAFE_BYTE_GET64 (ph
, &signature_high
, &signature_low
, limit
);
9021 SAFE_BYTE_GET (row
, pi
, 4, limit
);
9024 prow
= psizes
+ (row
- 1) * ncols
* 4;
9027 printf (_(" [%3d] 0x%s"),
9028 i
, dwarf_vmatoa64 (signature_high
, signature_low
,
9029 buf
, sizeof (buf
)));
9031 for (j
= 0; j
< ncols
; j
++)
9033 SAFE_BYTE_GET (val
, prow
+ j
* 4, 4, limit
);
9035 printf (" %8d", val
);
9038 SAFE_BYTE_GET (dw_sect
, ppool
+ j
* 4, 4, limit
);
9039 if (dw_sect
>= DW_SECT_MAX
)
9040 warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect
);
9042 this_set
[row
- 1].section_sizes
[dw_sect
] = val
;
9054 else if (do_display
)
9055 printf (_(" Unsupported version (%d)\n"), version
);
9063 /* Load the CU and TU indexes if present. This will build a list of
9064 section sets that we can use to associate a .debug_info.dwo section
9065 with its associated .debug_abbrev.dwo section in a .dwp file. */
9068 load_cu_tu_indexes (void *file
)
9070 static int cu_tu_indexes_read
= -1; /* Tri-state variable. */
9072 /* If we have already loaded (or tried to load) the CU and TU indexes
9073 then do not bother to repeat the task. */
9074 if (cu_tu_indexes_read
== -1)
9076 cu_tu_indexes_read
= TRUE
;
9078 if (load_debug_section (dwp_cu_index
, file
))
9079 if (! process_cu_tu_index (&debug_displays
[dwp_cu_index
].section
, 0))
9080 cu_tu_indexes_read
= FALSE
;
9082 if (load_debug_section (dwp_tu_index
, file
))
9083 if (! process_cu_tu_index (&debug_displays
[dwp_tu_index
].section
, 0))
9084 cu_tu_indexes_read
= FALSE
;
9087 return (bfd_boolean
) cu_tu_indexes_read
;
9090 /* Find the set of sections that includes section SHNDX. */
9093 find_cu_tu_set (void *file
, unsigned int shndx
)
9097 if (! load_cu_tu_indexes (file
))
9100 /* Find SHNDX in the shndx pool. */
9101 for (i
= 0; i
< shndx_pool_used
; i
++)
9102 if (shndx_pool
[i
] == shndx
)
9105 if (i
>= shndx_pool_used
)
9108 /* Now backup to find the first entry in the set. */
9109 while (i
> 0 && shndx_pool
[i
- 1] != 0)
9112 return shndx_pool
+ i
;
9115 /* Display a .debug_cu_index or .debug_tu_index section. */
9118 display_cu_index (struct dwarf_section
*section
, void *file ATTRIBUTE_UNUSED
)
9120 return process_cu_tu_index (section
, 1);
9124 display_debug_not_supported (struct dwarf_section
*section
,
9125 void *file ATTRIBUTE_UNUSED
)
9127 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
9133 /* Like malloc, but takes two parameters like calloc.
9134 Verifies that the first parameter is not too large.
9135 Note: does *not* initialise the allocated memory to zero. */
9137 cmalloc (size_t nmemb
, size_t size
)
9139 /* Check for overflow. */
9140 if (nmemb
>= ~(size_t) 0 / size
)
9143 return xmalloc (nmemb
* size
);
9146 /* Like xmalloc, but takes two parameters like calloc.
9147 Verifies that the first parameter is not too large.
9148 Note: does *not* initialise the allocated memory to zero. */
9150 xcmalloc (size_t nmemb
, size_t size
)
9152 /* Check for overflow. */
9153 if (nmemb
>= ~(size_t) 0 / size
)
9156 _("Attempt to allocate an array with an excessive number of elements: 0x%lx\n"),
9161 return xmalloc (nmemb
* size
);
9164 /* Like xrealloc, but takes three parameters.
9165 Verifies that the second parameter is not too large.
9166 Note: does *not* initialise any new memory to zero. */
9168 xcrealloc (void *ptr
, size_t nmemb
, size_t size
)
9170 /* Check for overflow. */
9171 if (nmemb
>= ~(size_t) 0 / size
)
9174 _("Attempt to re-allocate an array with an excessive number of elements: 0x%lx\n"),
9179 return xrealloc (ptr
, nmemb
* size
);
9182 /* Like xcalloc, but verifies that the first parameter is not too large. */
9184 xcalloc2 (size_t nmemb
, size_t size
)
9186 /* Check for overflow. */
9187 if (nmemb
>= ~(size_t) 0 / size
)
9190 _("Attempt to allocate a zero'ed array with an excessive number of elements: 0x%lx\n"),
9195 return xcalloc (nmemb
, size
);
9199 free_debug_memory (void)
9205 for (i
= 0; i
< max
; i
++)
9206 free_debug_section ((enum dwarf_section_display_enum
) i
);
9208 if (debug_information
!= NULL
)
9210 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
)
9212 for (i
= 0; i
< num_debug_info_entries
; i
++)
9214 if (!debug_information
[i
].max_loc_offsets
)
9216 free (debug_information
[i
].loc_offsets
);
9217 free (debug_information
[i
].have_frame_base
);
9219 if (!debug_information
[i
].max_range_lists
)
9220 free (debug_information
[i
].range_lists
);
9223 free (debug_information
);
9224 debug_information
= NULL
;
9225 alloc_num_debug_info_entries
= num_debug_info_entries
= 0;
9230 dwarf_select_sections_by_names (const char *names
)
9234 const char * option
;
9238 debug_dump_long_opts
;
9240 static const debug_dump_long_opts opts_table
[] =
9242 /* Please keep this table alpha- sorted. */
9243 { "Ranges", & do_debug_ranges
, 1 },
9244 { "abbrev", & do_debug_abbrevs
, 1 },
9245 { "addr", & do_debug_addr
, 1 },
9246 { "aranges", & do_debug_aranges
, 1 },
9247 { "cu_index", & do_debug_cu_index
, 1 },
9248 { "decodedline", & do_debug_lines
, FLAG_DEBUG_LINES_DECODED
},
9249 { "frames", & do_debug_frames
, 1 },
9250 { "frames-interp", & do_debug_frames_interp
, 1 },
9251 /* The special .gdb_index section. */
9252 { "gdb_index", & do_gdb_index
, 1 },
9253 { "info", & do_debug_info
, 1 },
9254 { "line", & do_debug_lines
, FLAG_DEBUG_LINES_RAW
}, /* For backwards compatibility. */
9255 { "loc", & do_debug_loc
, 1 },
9256 { "macro", & do_debug_macinfo
, 1 },
9257 { "pubnames", & do_debug_pubnames
, 1 },
9258 { "pubtypes", & do_debug_pubtypes
, 1 },
9259 /* This entry is for compatibility
9260 with earlier versions of readelf. */
9261 { "ranges", & do_debug_aranges
, 1 },
9262 { "rawline", & do_debug_lines
, FLAG_DEBUG_LINES_RAW
},
9263 { "str", & do_debug_str
, 1 },
9264 /* These trace_* sections are used by Itanium VMS. */
9265 { "trace_abbrev", & do_trace_abbrevs
, 1 },
9266 { "trace_aranges", & do_trace_aranges
, 1 },
9267 { "trace_info", & do_trace_info
, 1 },
9276 const debug_dump_long_opts
* entry
;
9278 for (entry
= opts_table
; entry
->option
; entry
++)
9280 size_t len
= strlen (entry
->option
);
9282 if (strncmp (p
, entry
->option
, len
) == 0
9283 && (p
[len
] == ',' || p
[len
] == '\0'))
9285 * entry
->variable
|= entry
->val
;
9287 /* The --debug-dump=frames-interp option also
9288 enables the --debug-dump=frames option. */
9289 if (do_debug_frames_interp
)
9290 do_debug_frames
= 1;
9297 if (entry
->option
== NULL
)
9299 warn (_("Unrecognized debug option '%s'\n"), p
);
9300 p
= strchr (p
, ',');
9311 dwarf_select_sections_by_letters (const char *letters
)
9313 unsigned int lindex
= 0;
9315 while (letters
[lindex
])
9316 switch (letters
[lindex
++])
9323 do_debug_abbrevs
= 1;
9327 do_debug_lines
|= FLAG_DEBUG_LINES_RAW
;
9331 do_debug_lines
|= FLAG_DEBUG_LINES_DECODED
;
9335 do_debug_pubnames
= 1;
9339 do_debug_pubtypes
= 1;
9343 do_debug_aranges
= 1;
9347 do_debug_ranges
= 1;
9351 do_debug_frames_interp
= 1;
9354 do_debug_frames
= 1;
9358 do_debug_macinfo
= 1;
9370 warn (_("Unrecognized debug option '%s'\n"), letters
);
9376 dwarf_select_sections_all (void)
9379 do_debug_abbrevs
= 1;
9380 do_debug_lines
= FLAG_DEBUG_LINES_RAW
;
9381 do_debug_pubnames
= 1;
9382 do_debug_pubtypes
= 1;
9383 do_debug_aranges
= 1;
9384 do_debug_ranges
= 1;
9385 do_debug_frames
= 1;
9386 do_debug_macinfo
= 1;
9391 do_trace_abbrevs
= 1;
9392 do_trace_aranges
= 1;
9394 do_debug_cu_index
= 1;
9397 struct dwarf_section_display debug_displays
[] =
9399 { { ".debug_abbrev", ".zdebug_abbrev", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
9400 display_debug_abbrev
, &do_debug_abbrevs
, FALSE
},
9401 { { ".debug_aranges", ".zdebug_aranges", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
9402 display_debug_aranges
, &do_debug_aranges
, TRUE
},
9403 { { ".debug_frame", ".zdebug_frame", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
9404 display_debug_frames
, &do_debug_frames
, TRUE
},
9405 { { ".debug_info", ".zdebug_info", NULL
, NULL
, 0, 0, abbrev
, NULL
, 0, NULL
},
9406 display_debug_info
, &do_debug_info
, TRUE
},
9407 { { ".debug_line", ".zdebug_line", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
9408 display_debug_lines
, &do_debug_lines
, TRUE
},
9409 { { ".debug_pubnames", ".zdebug_pubnames", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
9410 display_debug_pubnames
, &do_debug_pubnames
, FALSE
},
9411 { { ".debug_gnu_pubnames", ".zdebug_gnu_pubnames", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
9412 display_debug_gnu_pubnames
, &do_debug_pubnames
, FALSE
},
9413 { { ".eh_frame", "", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
9414 display_debug_frames
, &do_debug_frames
, TRUE
},
9415 { { ".debug_macinfo", ".zdebug_macinfo", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
9416 display_debug_macinfo
, &do_debug_macinfo
, FALSE
},
9417 { { ".debug_macro", ".zdebug_macro", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
9418 display_debug_macro
, &do_debug_macinfo
, TRUE
},
9419 { { ".debug_str", ".zdebug_str", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
9420 display_debug_str
, &do_debug_str
, FALSE
},
9421 { { ".debug_line_str", ".zdebug_line_str", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
9422 display_debug_str
, &do_debug_str
, FALSE
},
9423 { { ".debug_loc", ".zdebug_loc", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
9424 display_debug_loc
, &do_debug_loc
, TRUE
},
9425 { { ".debug_loclists", ".zdebug_loclists", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
9426 display_debug_loc
, &do_debug_loc
, TRUE
},
9427 { { ".debug_pubtypes", ".zdebug_pubtypes", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
9428 display_debug_pubnames
, &do_debug_pubtypes
, FALSE
},
9429 { { ".debug_gnu_pubtypes", ".zdebug_gnu_pubtypes", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
9430 display_debug_gnu_pubnames
, &do_debug_pubtypes
, FALSE
},
9431 { { ".debug_ranges", ".zdebug_ranges", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
9432 display_debug_ranges
, &do_debug_ranges
, TRUE
},
9433 { { ".debug_rnglists", ".zdebug_rnglists", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
9434 display_debug_ranges
, &do_debug_ranges
, TRUE
},
9435 { { ".debug_static_func", ".zdebug_static_func", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
9436 display_debug_not_supported
, NULL
, FALSE
},
9437 { { ".debug_static_vars", ".zdebug_static_vars", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
9438 display_debug_not_supported
, NULL
, FALSE
},
9439 { { ".debug_types", ".zdebug_types", NULL
, NULL
, 0, 0, abbrev
, NULL
, 0, NULL
},
9440 display_debug_types
, &do_debug_info
, TRUE
},
9441 { { ".debug_weaknames", ".zdebug_weaknames", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
9442 display_debug_not_supported
, NULL
, FALSE
},
9443 { { ".gdb_index", "", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
9444 display_gdb_index
, &do_gdb_index
, FALSE
},
9445 { { ".debug_names", "", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
9446 display_debug_names
, &do_gdb_index
, FALSE
},
9447 { { ".trace_info", "", NULL
, NULL
, 0, 0, trace_abbrev
, NULL
, 0, NULL
},
9448 display_trace_info
, &do_trace_info
, TRUE
},
9449 { { ".trace_abbrev", "", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
9450 display_debug_abbrev
, &do_trace_abbrevs
, FALSE
},
9451 { { ".trace_aranges", "", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
9452 display_debug_aranges
, &do_trace_aranges
, FALSE
},
9453 { { ".debug_info.dwo", ".zdebug_info.dwo", NULL
, NULL
, 0, 0, abbrev_dwo
, NULL
, 0, NULL
},
9454 display_debug_info
, &do_debug_info
, TRUE
},
9455 { { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
9456 display_debug_abbrev
, &do_debug_abbrevs
, FALSE
},
9457 { { ".debug_types.dwo", ".zdebug_types.dwo", NULL
, NULL
, 0, 0, abbrev_dwo
, NULL
, 0, NULL
},
9458 display_debug_types
, &do_debug_info
, TRUE
},
9459 { { ".debug_line.dwo", ".zdebug_line.dwo", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
9460 display_debug_lines
, &do_debug_lines
, TRUE
},
9461 { { ".debug_loc.dwo", ".zdebug_loc.dwo", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
9462 display_debug_loc
, &do_debug_loc
, TRUE
},
9463 { { ".debug_macro.dwo", ".zdebug_macro.dwo", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
9464 display_debug_macro
, &do_debug_macinfo
, TRUE
},
9465 { { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
9466 display_debug_macinfo
, &do_debug_macinfo
, FALSE
},
9467 { { ".debug_str.dwo", ".zdebug_str.dwo", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
9468 display_debug_str
, &do_debug_str
, TRUE
},
9469 { { ".debug_str_offsets", ".zdebug_str_offsets", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
9470 display_debug_str_offsets
, NULL
, FALSE
},
9471 { { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
9472 display_debug_str_offsets
, NULL
, FALSE
},
9473 { { ".debug_addr", ".zdebug_addr", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
9474 display_debug_addr
, &do_debug_addr
, TRUE
},
9475 { { ".debug_cu_index", "", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
9476 display_cu_index
, &do_debug_cu_index
, FALSE
},
9477 { { ".debug_tu_index", "", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
9478 display_cu_index
, &do_debug_cu_index
, FALSE
},
9481 /* A static assertion. */
9482 extern int debug_displays_assert
[ARRAY_SIZE (debug_displays
) == max
? 1 : -1];