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"
32 static const char *regname (unsigned int regno
, int row
);
34 static int have_frame_base
;
35 static int need_base_address
;
37 static unsigned int last_pointer_size
= 0;
38 static int warned_about_missing_comp_units
= FALSE
;
40 static unsigned int num_debug_info_entries
= 0;
41 static unsigned int alloc_num_debug_info_entries
= 0;
42 static debug_info
*debug_information
= NULL
;
43 /* Special value for num_debug_info_entries to indicate
44 that the .debug_info section could not be loaded/parsed. */
45 #define DEBUG_INFO_UNAVAILABLE (unsigned int) -1
47 unsigned int eh_addr_size
;
52 int do_debug_pubnames
;
53 int do_debug_pubtypes
;
57 int do_debug_frames_interp
;
66 int do_debug_cu_index
;
69 int dwarf_cutoff_level
= -1;
70 unsigned long dwarf_start_die
;
74 /* Collection of CU/TU section sets from .debug_cu_index and .debug_tu_index
75 sections. For version 1 package files, each set is stored in SHNDX_POOL
76 as a zero-terminated list of section indexes comprising one set of debug
77 sections from a .dwo file. */
79 static unsigned int *shndx_pool
= NULL
;
80 static unsigned int shndx_pool_size
= 0;
81 static unsigned int shndx_pool_used
= 0;
83 /* For version 2 package files, each set contains an array of section offsets
84 and an array of section sizes, giving the offset and size of the
85 contribution from a CU or TU within one of the debug sections.
86 When displaying debug info from a package file, we need to use these
87 tables to locate the corresponding contributions to each section. */
92 dwarf_vma section_offsets
[DW_SECT_MAX
];
93 size_t section_sizes
[DW_SECT_MAX
];
96 static int cu_count
= 0;
97 static int tu_count
= 0;
98 static struct cu_tu_set
*cu_sets
= NULL
;
99 static struct cu_tu_set
*tu_sets
= NULL
;
101 static bfd_boolean
load_cu_tu_indexes (void *);
103 /* Values for do_debug_lines. */
104 #define FLAG_DEBUG_LINES_RAW 1
105 #define FLAG_DEBUG_LINES_DECODED 2
108 size_of_encoded_value (int encoding
)
110 switch (encoding
& 0x7)
113 case 0: return eh_addr_size
;
121 get_encoded_value (unsigned char **pdata
,
123 struct dwarf_section
*section
,
126 unsigned char * data
= * pdata
;
127 unsigned int size
= size_of_encoded_value (encoding
);
130 if (data
+ size
>= end
)
132 warn (_("Encoded value extends past end of section\n"));
137 /* PR 17512: file: 002-829853-0.004. */
140 warn (_("Encoded size of %d is too large to read\n"), size
);
145 /* PR 17512: file: 1085-5603-0.004. */
148 warn (_("Encoded size of 0 is too small to read\n"));
153 if (encoding
& DW_EH_PE_signed
)
154 val
= byte_get_signed (data
, size
);
156 val
= byte_get (data
, size
);
158 if ((encoding
& 0x70) == DW_EH_PE_pcrel
)
159 val
+= section
->address
+ (data
- section
->start
);
161 * pdata
= data
+ size
;
165 #if defined HAVE_LONG_LONG && SIZEOF_LONG_LONG > SIZEOF_LONG
167 # define DWARF_VMA_FMT "ll"
168 # define DWARF_VMA_FMT_LONG "%16.16llx"
170 # define DWARF_VMA_FMT "I64"
171 # define DWARF_VMA_FMT_LONG "%016I64x"
174 # define DWARF_VMA_FMT "l"
175 # define DWARF_VMA_FMT_LONG "%16.16lx"
178 /* Convert a dwarf vma value into a string. Returns a pointer to a static
179 buffer containing the converted VALUE. The value is converted according
180 to the printf formating character FMTCH. If NUM_BYTES is non-zero then
181 it specifies the maximum number of bytes to be displayed in the converted
182 value and FMTCH is ignored - hex is always used. */
185 dwarf_vmatoa_1 (const char *fmtch
, dwarf_vma value
, unsigned num_bytes
)
187 /* As dwarf_vmatoa is used more then once in a printf call
188 for output, we are cycling through an fixed array of pointers
189 for return address. */
190 static int buf_pos
= 0;
191 static struct dwarf_vmatoa_buf
197 ret
= buf
[buf_pos
++].place
;
198 buf_pos
%= ARRAY_SIZE (buf
);
202 /* Printf does not have a way of specifying a maximum field width for an
203 integer value, so we print the full value into a buffer and then select
204 the precision we need. */
205 snprintf (ret
, sizeof (buf
[0].place
), DWARF_VMA_FMT_LONG
, value
);
208 return ret
+ (16 - 2 * num_bytes
);
214 sprintf (fmt
, "%%%s%s", DWARF_VMA_FMT
, fmtch
);
215 snprintf (ret
, sizeof (buf
[0].place
), fmt
, value
);
220 static inline const char *
221 dwarf_vmatoa (const char * fmtch
, dwarf_vma value
)
223 return dwarf_vmatoa_1 (fmtch
, value
, 0);
226 /* Print a dwarf_vma value (typically an address, offset or length) in
227 hexadecimal format, followed by a space. The length of the VALUE (and
228 hence the precision displayed) is determined by the NUM_BYTES parameter. */
231 print_dwarf_vma (dwarf_vma value
, unsigned num_bytes
)
233 printf ("%s ", dwarf_vmatoa_1 (NULL
, value
, num_bytes
));
236 /* Format a 64-bit value, given as two 32-bit values, in hex.
237 For reentrancy, this uses a buffer provided by the caller. */
240 dwarf_vmatoa64 (dwarf_vma hvalue
, dwarf_vma lvalue
, char *buf
,
241 unsigned int buf_len
)
246 snprintf (buf
, buf_len
, "%" DWARF_VMA_FMT
"x", lvalue
);
249 len
= snprintf (buf
, buf_len
, "%" DWARF_VMA_FMT
"x", hvalue
);
250 snprintf (buf
+ len
, buf_len
- len
,
251 "%08" DWARF_VMA_FMT
"x", lvalue
);
257 /* Read in a LEB128 encoded value starting at address DATA.
258 If SIGN is true, return a signed LEB128 value.
259 If LENGTH_RETURN is not NULL, return in it the number of bytes read.
260 No bytes will be read at address END or beyond. */
263 read_leb128 (unsigned char *data
,
264 unsigned int *length_return
,
266 const unsigned char * const end
)
268 dwarf_vma result
= 0;
269 unsigned int num_read
= 0;
270 unsigned int shift
= 0;
271 unsigned char byte
= 0;
278 result
|= ((dwarf_vma
) (byte
& 0x7f)) << shift
;
281 if ((byte
& 0x80) == 0)
284 /* PR 17512: file: 0ca183b8.
285 FIXME: Should we signal this error somehow ? */
286 if (shift
>= sizeof (result
) * 8)
290 if (length_return
!= NULL
)
291 *length_return
= num_read
;
293 if (sign
&& (shift
< 8 * sizeof (result
)) && (byte
& 0x40))
294 result
|= -((dwarf_vma
) 1 << shift
);
299 /* Create a signed version to avoid painful typecasts. */
300 static inline dwarf_signed_vma
301 read_sleb128 (unsigned char * data
,
302 unsigned int * length_return
,
303 const unsigned char * const end
)
305 return (dwarf_signed_vma
) read_leb128 (data
, length_return
, TRUE
, end
);
308 static inline dwarf_vma
309 read_uleb128 (unsigned char * data
,
310 unsigned int * length_return
,
311 const unsigned char * const end
)
313 return read_leb128 (data
, length_return
, FALSE
, end
);
316 #define SAFE_BYTE_GET(VAL, PTR, AMOUNT, END) \
319 unsigned int amount = (AMOUNT); \
320 if (sizeof (VAL) < amount) \
322 error (_("internal error: attempt to read %d bytes of data in to %d sized variable"),\
323 amount, (int) sizeof (VAL)); \
324 amount = sizeof (VAL); \
326 if (((PTR) + amount) >= (END)) \
329 amount = (END) - (PTR); \
333 if (amount == 0 || amount > 8) \
336 VAL = byte_get ((PTR), amount); \
340 #define SAFE_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \
343 SAFE_BYTE_GET (VAL, PTR, AMOUNT, END); \
348 #define SAFE_SIGNED_BYTE_GET(VAL, PTR, AMOUNT, END) \
351 unsigned int amount = (AMOUNT); \
352 if (((PTR) + amount) >= (END)) \
355 amount = (END) - (PTR); \
360 VAL = byte_get_signed ((PTR), amount); \
366 #define SAFE_SIGNED_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \
369 SAFE_SIGNED_BYTE_GET (VAL, PTR, AMOUNT, END); \
374 #define SAFE_BYTE_GET64(PTR, HIGH, LOW, END) \
377 if (((PTR) + 8) <= (END)) \
379 byte_get_64 ((PTR), (HIGH), (LOW)); \
383 * (LOW) = * (HIGH) = 0; \
388 typedef struct State_Machine_Registers
396 unsigned char op_index
;
397 unsigned char end_sequence
;
398 /* This variable hold the number of the last entry seen
399 in the File Table. */
400 unsigned int last_file_entry
;
403 static SMR state_machine_regs
;
406 reset_state_machine (int is_stmt
)
408 state_machine_regs
.address
= 0;
409 state_machine_regs
.op_index
= 0;
410 state_machine_regs
.file
= 1;
411 state_machine_regs
.line
= 1;
412 state_machine_regs
.column
= 0;
413 state_machine_regs
.is_stmt
= is_stmt
;
414 state_machine_regs
.basic_block
= 0;
415 state_machine_regs
.end_sequence
= 0;
416 state_machine_regs
.last_file_entry
= 0;
419 /* Handled an extend line op.
420 Returns the number of bytes read. */
423 process_extended_line_op (unsigned char * data
,
427 unsigned char op_code
;
428 unsigned int bytes_read
;
431 unsigned char *orig_data
= data
;
434 len
= read_uleb128 (data
, & bytes_read
, end
);
437 if (len
== 0 || data
== end
|| len
> (uintptr_t) (end
- data
))
439 warn (_("Badly formed extended line op encountered!\n"));
446 printf (_(" Extended opcode %d: "), op_code
);
450 case DW_LNE_end_sequence
:
451 printf (_("End of Sequence\n\n"));
452 reset_state_machine (is_stmt
);
455 case DW_LNE_set_address
:
456 /* PR 17512: file: 002-100480-0.004. */
457 if (len
- bytes_read
- 1 > 8)
459 warn (_("Length (%d) of DW_LNE_set_address op is too long\n"),
460 len
- bytes_read
- 1);
464 SAFE_BYTE_GET (adr
, data
, len
- bytes_read
- 1, end
);
465 printf (_("set Address to 0x%s\n"), dwarf_vmatoa ("x", adr
));
466 state_machine_regs
.address
= adr
;
467 state_machine_regs
.op_index
= 0;
470 case DW_LNE_define_file
:
471 printf (_("define new File Table entry\n"));
472 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
473 printf (" %d\t", ++state_machine_regs
.last_file_entry
);
476 data
+= strnlen ((char *) data
, end
- data
) + 1;
477 printf ("%s\t", dwarf_vmatoa ("u", read_uleb128 (data
, & bytes_read
, end
)));
479 printf ("%s\t", dwarf_vmatoa ("u", read_uleb128 (data
, & bytes_read
, end
)));
481 printf ("%s\t", dwarf_vmatoa ("u", read_uleb128 (data
, & bytes_read
, end
)));
483 printf ("%s\n\n", name
);
485 if (((unsigned int) (data
- orig_data
) != len
) || data
== end
)
486 warn (_("DW_LNE_define_file: Bad opcode length\n"));
489 case DW_LNE_set_discriminator
:
490 printf (_("set Discriminator to %s\n"),
491 dwarf_vmatoa ("u", read_uleb128 (data
, & bytes_read
, end
)));
495 case DW_LNE_HP_negate_is_UV_update
:
496 printf ("DW_LNE_HP_negate_is_UV_update\n");
498 case DW_LNE_HP_push_context
:
499 printf ("DW_LNE_HP_push_context\n");
501 case DW_LNE_HP_pop_context
:
502 printf ("DW_LNE_HP_pop_context\n");
504 case DW_LNE_HP_set_file_line_column
:
505 printf ("DW_LNE_HP_set_file_line_column\n");
507 case DW_LNE_HP_set_routine_name
:
508 printf ("DW_LNE_HP_set_routine_name\n");
510 case DW_LNE_HP_set_sequence
:
511 printf ("DW_LNE_HP_set_sequence\n");
513 case DW_LNE_HP_negate_post_semantics
:
514 printf ("DW_LNE_HP_negate_post_semantics\n");
516 case DW_LNE_HP_negate_function_exit
:
517 printf ("DW_LNE_HP_negate_function_exit\n");
519 case DW_LNE_HP_negate_front_end_logical
:
520 printf ("DW_LNE_HP_negate_front_end_logical\n");
522 case DW_LNE_HP_define_proc
:
523 printf ("DW_LNE_HP_define_proc\n");
525 case DW_LNE_HP_source_file_correlation
:
527 unsigned char *edata
= data
+ len
- bytes_read
- 1;
529 printf ("DW_LNE_HP_source_file_correlation\n");
535 opc
= read_uleb128 (data
, & bytes_read
, edata
);
540 case DW_LNE_HP_SFC_formfeed
:
541 printf (" DW_LNE_HP_SFC_formfeed\n");
543 case DW_LNE_HP_SFC_set_listing_line
:
544 printf (" DW_LNE_HP_SFC_set_listing_line (%s)\n",
546 read_uleb128 (data
, & bytes_read
, edata
)));
549 case DW_LNE_HP_SFC_associate
:
550 printf (" DW_LNE_HP_SFC_associate ");
553 read_uleb128 (data
, & bytes_read
, edata
)));
557 read_uleb128 (data
, & bytes_read
, edata
)));
561 read_uleb128 (data
, & bytes_read
, edata
)));
565 printf (_(" UNKNOWN DW_LNE_HP_SFC opcode (%u)\n"), opc
);
575 unsigned int rlen
= len
- bytes_read
- 1;
577 if (op_code
>= DW_LNE_lo_user
578 /* The test against DW_LNW_hi_user is redundant due to
579 the limited range of the unsigned char data type used
581 /*&& op_code <= DW_LNE_hi_user*/)
582 printf (_("user defined: "));
584 printf (_("UNKNOWN: "));
585 printf (_("length %d ["), rlen
);
587 printf (" %02x", *data
++);
596 static const unsigned char *
597 fetch_indirect_string (dwarf_vma offset
)
599 struct dwarf_section
*section
= &debug_displays
[str
].section
;
601 if (section
->start
== NULL
)
602 return (const unsigned char *) _("<no .debug_str section>");
604 if (offset
> section
->size
)
606 warn (_("DW_FORM_strp offset too big: %s\n"),
607 dwarf_vmatoa ("x", offset
));
608 return (const unsigned char *) _("<offset is too big>");
611 return (const unsigned char *) section
->start
+ offset
;
614 static const unsigned char *
615 fetch_indirect_line_string (dwarf_vma offset
)
617 struct dwarf_section
*section
= &debug_displays
[line_str
].section
;
619 if (section
->start
== NULL
)
620 return (const unsigned char *) _("<no .debug_line_str section>");
622 if (offset
> section
->size
)
624 warn (_("DW_FORM_line_strp offset too big: %s\n"),
625 dwarf_vmatoa ("x", offset
));
626 return (const unsigned char *) _("<offset is too big>");
629 return (const unsigned char *) section
->start
+ offset
;
633 fetch_indexed_string (dwarf_vma idx
, struct cu_tu_set
*this_set
,
634 dwarf_vma offset_size
, int dwo
)
636 enum dwarf_section_display_enum str_sec_idx
= dwo
? str_dwo
: str
;
637 enum dwarf_section_display_enum idx_sec_idx
= dwo
? str_index_dwo
: str_index
;
638 struct dwarf_section
*index_section
= &debug_displays
[idx_sec_idx
].section
;
639 struct dwarf_section
*str_section
= &debug_displays
[str_sec_idx
].section
;
640 dwarf_vma index_offset
= idx
* offset_size
;
641 dwarf_vma str_offset
;
643 if (index_section
->start
== NULL
)
644 return (dwo
? _("<no .debug_str_offsets.dwo section>")
645 : _("<no .debug_str_offsets section>"));
647 if (this_set
!= NULL
)
648 index_offset
+= this_set
->section_offsets
[DW_SECT_STR_OFFSETS
];
649 if (index_offset
> index_section
->size
)
651 warn (_("DW_FORM_GNU_str_index offset too big: %s\n"),
652 dwarf_vmatoa ("x", index_offset
));
653 return _("<index offset is too big>");
656 if (str_section
->start
== NULL
)
657 return (dwo
? _("<no .debug_str.dwo section>")
658 : _("<no .debug_str section>"));
660 str_offset
= byte_get (index_section
->start
+ index_offset
, offset_size
);
661 str_offset
-= str_section
->address
;
662 if (str_offset
> str_section
->size
)
664 warn (_("DW_FORM_GNU_str_index indirect offset too big: %s\n"),
665 dwarf_vmatoa ("x", str_offset
));
666 return _("<indirect index offset is too big>");
669 return (const char *) str_section
->start
+ str_offset
;
673 fetch_indexed_value (dwarf_vma offset
, dwarf_vma bytes
)
675 struct dwarf_section
*section
= &debug_displays
[debug_addr
].section
;
677 if (section
->start
== NULL
)
678 return (_("<no .debug_addr section>"));
680 if (offset
+ bytes
> section
->size
)
682 warn (_("Offset into section %s too big: %s\n"),
683 section
->name
, dwarf_vmatoa ("x", offset
));
684 return "<offset too big>";
687 return dwarf_vmatoa ("x", byte_get (section
->start
+ offset
, bytes
));
691 /* FIXME: There are better and more efficient ways to handle
692 these structures. For now though, I just want something that
693 is simple to implement. */
694 typedef struct abbrev_attr
696 unsigned long attribute
;
698 bfd_signed_vma implicit_const
;
699 struct abbrev_attr
*next
;
703 typedef struct abbrev_entry
708 struct abbrev_attr
*first_attr
;
709 struct abbrev_attr
*last_attr
;
710 struct abbrev_entry
*next
;
714 static abbrev_entry
*first_abbrev
= NULL
;
715 static abbrev_entry
*last_abbrev
= NULL
;
722 for (abbrv
= first_abbrev
; abbrv
;)
724 abbrev_entry
*next_abbrev
= abbrv
->next
;
727 for (attr
= abbrv
->first_attr
; attr
;)
729 abbrev_attr
*next_attr
= attr
->next
;
739 last_abbrev
= first_abbrev
= NULL
;
743 add_abbrev (unsigned long number
, unsigned long tag
, int children
)
747 entry
= (abbrev_entry
*) malloc (sizeof (*entry
));
752 entry
->entry
= number
;
754 entry
->children
= children
;
755 entry
->first_attr
= NULL
;
756 entry
->last_attr
= NULL
;
759 if (first_abbrev
== NULL
)
760 first_abbrev
= entry
;
762 last_abbrev
->next
= entry
;
768 add_abbrev_attr (unsigned long attribute
, unsigned long form
,
769 bfd_signed_vma implicit_const
)
773 attr
= (abbrev_attr
*) malloc (sizeof (*attr
));
778 attr
->attribute
= attribute
;
780 attr
->implicit_const
= implicit_const
;
783 if (last_abbrev
->first_attr
== NULL
)
784 last_abbrev
->first_attr
= attr
;
786 last_abbrev
->last_attr
->next
= attr
;
788 last_abbrev
->last_attr
= attr
;
791 /* Processes the (partial) contents of a .debug_abbrev section.
792 Returns NULL if the end of the section was encountered.
793 Returns the address after the last byte read if the end of
794 an abbreviation set was found. */
796 static unsigned char *
797 process_abbrev_section (unsigned char *start
, unsigned char *end
)
799 if (first_abbrev
!= NULL
)
804 unsigned int bytes_read
;
807 unsigned long attribute
;
810 entry
= read_uleb128 (start
, & bytes_read
, end
);
813 /* A single zero is supposed to end the section according
814 to the standard. If there's more, then signal that to
821 tag
= read_uleb128 (start
, & bytes_read
, end
);
828 add_abbrev (entry
, tag
, children
);
833 /* Initialize it due to a false compiler warning. */
834 bfd_signed_vma implicit_const
= -1;
836 attribute
= read_uleb128 (start
, & bytes_read
, end
);
841 form
= read_uleb128 (start
, & bytes_read
, end
);
846 if (form
== DW_FORM_implicit_const
)
848 implicit_const
= read_sleb128 (start
, & bytes_read
, end
);
854 add_abbrev_attr (attribute
, form
, implicit_const
);
856 while (attribute
!= 0);
859 /* Report the missing single zero which ends the section. */
860 error (_(".debug_abbrev section not zero terminated\n"));
866 get_TAG_name (unsigned long tag
)
868 const char *name
= get_DW_TAG_name ((unsigned int)tag
);
872 static char buffer
[100];
874 snprintf (buffer
, sizeof (buffer
), _("Unknown TAG value: %lx"), tag
);
882 get_FORM_name (unsigned long form
)
887 return "DW_FORM value: 0";
889 name
= get_DW_FORM_name (form
);
892 static char buffer
[100];
894 snprintf (buffer
, sizeof (buffer
), _("Unknown FORM value: %lx"), form
);
901 static unsigned char *
902 display_block (unsigned char *data
,
904 const unsigned char * const end
, char delimiter
)
908 printf (_("%c%s byte block: "), delimiter
, dwarf_vmatoa ("u", length
));
910 return (unsigned char *) end
;
912 maxlen
= (dwarf_vma
) (end
- data
);
913 length
= length
> maxlen
? maxlen
: length
;
916 printf ("%lx ", (unsigned long) byte_get (data
++, 1));
922 decode_location_expression (unsigned char * data
,
923 unsigned int pointer_size
,
924 unsigned int offset_size
,
928 struct dwarf_section
* section
)
931 unsigned int bytes_read
;
933 dwarf_signed_vma svalue
;
934 unsigned char *end
= data
+ length
;
935 int need_frame_base
= 0;
944 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
945 printf ("DW_OP_addr: %s", dwarf_vmatoa ("x", uvalue
));
948 printf ("DW_OP_deref");
951 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
952 printf ("DW_OP_const1u: %lu", (unsigned long) uvalue
);
955 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 1, end
);
956 printf ("DW_OP_const1s: %ld", (long) svalue
);
959 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
960 printf ("DW_OP_const2u: %lu", (unsigned long) uvalue
);
963 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
964 printf ("DW_OP_const2s: %ld", (long) svalue
);
967 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
968 printf ("DW_OP_const4u: %lu", (unsigned long) uvalue
);
971 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
972 printf ("DW_OP_const4s: %ld", (long) svalue
);
975 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
976 printf ("DW_OP_const8u: %lu ", (unsigned long) uvalue
);
977 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
978 printf ("%lu", (unsigned long) uvalue
);
981 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
982 printf ("DW_OP_const8s: %ld ", (long) svalue
);
983 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
984 printf ("%ld", (long) svalue
);
987 printf ("DW_OP_constu: %s",
988 dwarf_vmatoa ("u", read_uleb128 (data
, &bytes_read
, end
)));
992 printf ("DW_OP_consts: %s",
993 dwarf_vmatoa ("d", read_sleb128 (data
, &bytes_read
, end
)));
997 printf ("DW_OP_dup");
1000 printf ("DW_OP_drop");
1003 printf ("DW_OP_over");
1006 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1007 printf ("DW_OP_pick: %ld", (unsigned long) uvalue
);
1010 printf ("DW_OP_swap");
1013 printf ("DW_OP_rot");
1016 printf ("DW_OP_xderef");
1019 printf ("DW_OP_abs");
1022 printf ("DW_OP_and");
1025 printf ("DW_OP_div");
1028 printf ("DW_OP_minus");
1031 printf ("DW_OP_mod");
1034 printf ("DW_OP_mul");
1037 printf ("DW_OP_neg");
1040 printf ("DW_OP_not");
1043 printf ("DW_OP_or");
1046 printf ("DW_OP_plus");
1048 case DW_OP_plus_uconst
:
1049 printf ("DW_OP_plus_uconst: %s",
1050 dwarf_vmatoa ("u", read_uleb128 (data
, &bytes_read
, end
)));
1054 printf ("DW_OP_shl");
1057 printf ("DW_OP_shr");
1060 printf ("DW_OP_shra");
1063 printf ("DW_OP_xor");
1066 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1067 printf ("DW_OP_bra: %ld", (long) svalue
);
1070 printf ("DW_OP_eq");
1073 printf ("DW_OP_ge");
1076 printf ("DW_OP_gt");
1079 printf ("DW_OP_le");
1082 printf ("DW_OP_lt");
1085 printf ("DW_OP_ne");
1088 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1089 printf ("DW_OP_skip: %ld", (long) svalue
);
1124 printf ("DW_OP_lit%d", op
- DW_OP_lit0
);
1159 printf ("DW_OP_reg%d (%s)", op
- DW_OP_reg0
,
1160 regname (op
- DW_OP_reg0
, 1));
1195 printf ("DW_OP_breg%d (%s): %s",
1197 regname (op
- DW_OP_breg0
, 1),
1198 dwarf_vmatoa ("d", read_sleb128 (data
, &bytes_read
, end
)));
1203 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1205 printf ("DW_OP_regx: %s (%s)",
1206 dwarf_vmatoa ("u", uvalue
), regname (uvalue
, 1));
1209 need_frame_base
= 1;
1210 printf ("DW_OP_fbreg: %s",
1211 dwarf_vmatoa ("d", read_sleb128 (data
, &bytes_read
, end
)));
1215 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1217 printf ("DW_OP_bregx: %s (%s) %s",
1218 dwarf_vmatoa ("u", uvalue
), regname (uvalue
, 1),
1219 dwarf_vmatoa ("d", read_sleb128 (data
, &bytes_read
, end
)));
1223 printf ("DW_OP_piece: %s",
1224 dwarf_vmatoa ("u", read_uleb128 (data
, &bytes_read
, end
)));
1227 case DW_OP_deref_size
:
1228 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1229 printf ("DW_OP_deref_size: %ld", (long) uvalue
);
1231 case DW_OP_xderef_size
:
1232 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1233 printf ("DW_OP_xderef_size: %ld", (long) uvalue
);
1236 printf ("DW_OP_nop");
1239 /* DWARF 3 extensions. */
1240 case DW_OP_push_object_address
:
1241 printf ("DW_OP_push_object_address");
1244 /* XXX: Strictly speaking for 64-bit DWARF3 files
1245 this ought to be an 8-byte wide computation. */
1246 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1247 printf ("DW_OP_call2: <0x%s>",
1248 dwarf_vmatoa ("x", svalue
+ cu_offset
));
1251 /* XXX: Strictly speaking for 64-bit DWARF3 files
1252 this ought to be an 8-byte wide computation. */
1253 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
1254 printf ("DW_OP_call4: <0x%s>",
1255 dwarf_vmatoa ("x", svalue
+ cu_offset
));
1257 case DW_OP_call_ref
:
1258 /* XXX: Strictly speaking for 64-bit DWARF3 files
1259 this ought to be an 8-byte wide computation. */
1260 if (dwarf_version
== -1)
1262 printf (_("(DW_OP_call_ref in frame info)"));
1263 /* No way to tell where the next op is, so just bail. */
1264 return need_frame_base
;
1266 if (dwarf_version
== 2)
1268 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1272 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1274 printf ("DW_OP_call_ref: <0x%s>", dwarf_vmatoa ("x", uvalue
));
1276 case DW_OP_form_tls_address
:
1277 printf ("DW_OP_form_tls_address");
1279 case DW_OP_call_frame_cfa
:
1280 printf ("DW_OP_call_frame_cfa");
1282 case DW_OP_bit_piece
:
1283 printf ("DW_OP_bit_piece: ");
1284 printf (_("size: %s "),
1285 dwarf_vmatoa ("u", read_uleb128 (data
, &bytes_read
, end
)));
1287 printf (_("offset: %s "),
1288 dwarf_vmatoa ("u", read_uleb128 (data
, &bytes_read
, end
)));
1292 /* DWARF 4 extensions. */
1293 case DW_OP_stack_value
:
1294 printf ("DW_OP_stack_value");
1297 case DW_OP_implicit_value
:
1298 printf ("DW_OP_implicit_value");
1299 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1301 data
= display_block (data
, uvalue
, end
, ' ');
1304 /* GNU extensions. */
1305 case DW_OP_GNU_push_tls_address
:
1306 printf (_("DW_OP_GNU_push_tls_address or DW_OP_HP_unknown"));
1308 case DW_OP_GNU_uninit
:
1309 printf ("DW_OP_GNU_uninit");
1310 /* FIXME: Is there data associated with this OP ? */
1312 case DW_OP_GNU_encoded_addr
:
1319 addr
= get_encoded_value (&data
, encoding
, section
, end
);
1321 printf ("DW_OP_GNU_encoded_addr: fmt:%02x addr:", encoding
);
1322 print_dwarf_vma (addr
, pointer_size
);
1325 case DW_OP_GNU_implicit_pointer
:
1326 /* XXX: Strictly speaking for 64-bit DWARF3 files
1327 this ought to be an 8-byte wide computation. */
1328 if (dwarf_version
== -1)
1330 printf (_("(DW_OP_GNU_implicit_pointer in frame info)"));
1331 /* No way to tell where the next op is, so just bail. */
1332 return need_frame_base
;
1334 if (dwarf_version
== 2)
1336 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1340 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1342 printf ("DW_OP_GNU_implicit_pointer: <0x%s> %s",
1343 dwarf_vmatoa ("x", uvalue
),
1344 dwarf_vmatoa ("d", read_sleb128 (data
,
1345 &bytes_read
, end
)));
1348 case DW_OP_entry_value
:
1349 case DW_OP_GNU_entry_value
:
1350 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1352 /* PR 17531: file: 0cc9cd00. */
1353 if (uvalue
> (dwarf_vma
) (end
- data
))
1354 uvalue
= end
- data
;
1355 printf ("%s: (", (op
== DW_OP_entry_value
? "DW_OP_entry_value"
1356 : "DW_OP_GNU_entry_value"));
1357 if (decode_location_expression (data
, pointer_size
, offset_size
,
1358 dwarf_version
, uvalue
,
1359 cu_offset
, section
))
1360 need_frame_base
= 1;
1366 case DW_OP_GNU_const_type
:
1367 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1369 printf ("DW_OP_GNU_const_type: <0x%s> ",
1370 dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1371 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1372 data
= display_block (data
, uvalue
, end
, ' ');
1374 case DW_OP_GNU_regval_type
:
1375 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1377 printf ("DW_OP_GNU_regval_type: %s (%s)",
1378 dwarf_vmatoa ("u", uvalue
), regname (uvalue
, 1));
1379 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1381 printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1383 case DW_OP_GNU_deref_type
:
1384 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1385 printf ("DW_OP_GNU_deref_type: %ld", (long) uvalue
);
1386 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1388 printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1390 case DW_OP_GNU_convert
:
1391 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1393 printf ("DW_OP_GNU_convert <0x%s>",
1394 dwarf_vmatoa ("x", uvalue
? cu_offset
+ uvalue
: 0));
1396 case DW_OP_GNU_reinterpret
:
1397 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1399 printf ("DW_OP_GNU_reinterpret <0x%s>",
1400 dwarf_vmatoa ("x", uvalue
? cu_offset
+ uvalue
: 0));
1402 case DW_OP_GNU_parameter_ref
:
1403 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1404 printf ("DW_OP_GNU_parameter_ref: <0x%s>",
1405 dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1407 case DW_OP_GNU_addr_index
:
1408 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1410 printf ("DW_OP_GNU_addr_index <0x%s>", dwarf_vmatoa ("x", uvalue
));
1412 case DW_OP_GNU_const_index
:
1413 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1415 printf ("DW_OP_GNU_const_index <0x%s>", dwarf_vmatoa ("x", uvalue
));
1418 /* HP extensions. */
1419 case DW_OP_HP_is_value
:
1420 printf ("DW_OP_HP_is_value");
1421 /* FIXME: Is there data associated with this OP ? */
1423 case DW_OP_HP_fltconst4
:
1424 printf ("DW_OP_HP_fltconst4");
1425 /* FIXME: Is there data associated with this OP ? */
1427 case DW_OP_HP_fltconst8
:
1428 printf ("DW_OP_HP_fltconst8");
1429 /* FIXME: Is there data associated with this OP ? */
1431 case DW_OP_HP_mod_range
:
1432 printf ("DW_OP_HP_mod_range");
1433 /* FIXME: Is there data associated with this OP ? */
1435 case DW_OP_HP_unmod_range
:
1436 printf ("DW_OP_HP_unmod_range");
1437 /* FIXME: Is there data associated with this OP ? */
1440 printf ("DW_OP_HP_tls");
1441 /* FIXME: Is there data associated with this OP ? */
1444 /* PGI (STMicroelectronics) extensions. */
1445 case DW_OP_PGI_omp_thread_num
:
1446 /* Pushes the thread number for the current thread as it would be
1447 returned by the standard OpenMP library function:
1448 omp_get_thread_num(). The "current thread" is the thread for
1449 which the expression is being evaluated. */
1450 printf ("DW_OP_PGI_omp_thread_num");
1454 if (op
>= DW_OP_lo_user
1455 && op
<= DW_OP_hi_user
)
1456 printf (_("(User defined location op 0x%x)"), op
);
1458 printf (_("(Unknown location op 0x%x)"), op
);
1459 /* No way to tell where the next op is, so just bail. */
1460 return need_frame_base
;
1463 /* Separate the ops. */
1468 return need_frame_base
;
1471 /* Find the CU or TU set corresponding to the given CU_OFFSET.
1472 This is used for DWARF package files. */
1474 static struct cu_tu_set
*
1475 find_cu_tu_set_v2 (dwarf_vma cu_offset
, int do_types
)
1477 struct cu_tu_set
*p
;
1479 unsigned int dw_sect
;
1485 dw_sect
= DW_SECT_TYPES
;
1491 dw_sect
= DW_SECT_INFO
;
1495 if (p
->section_offsets
[dw_sect
] == cu_offset
)
1503 /* Add INC to HIGH_BITS:LOW_BITS. */
1505 add64 (dwarf_vma
* high_bits
, dwarf_vma
* low_bits
, dwarf_vma inc
)
1507 dwarf_vma tmp
= * low_bits
;
1511 /* FIXME: There is probably a better way of handling this:
1513 We need to cope with dwarf_vma being a 32-bit or 64-bit
1514 type. Plus regardless of its size LOW_BITS is meant to
1515 only hold 32-bits, so if there is overflow or wrap around
1516 we must propagate into HIGH_BITS. */
1517 if (tmp
< * low_bits
)
1521 else if (sizeof (tmp
) > 8
1531 static unsigned char *
1532 read_and_display_attr_value (unsigned long attribute
,
1534 dwarf_signed_vma implicit_const
,
1535 unsigned char * data
,
1536 unsigned char * end
,
1537 dwarf_vma cu_offset
,
1538 dwarf_vma pointer_size
,
1539 dwarf_vma offset_size
,
1541 debug_info
* debug_info_p
,
1543 struct dwarf_section
* section
,
1544 struct cu_tu_set
* this_set
, char delimiter
)
1546 dwarf_vma uvalue
= 0;
1547 unsigned char *block_start
= NULL
;
1548 unsigned char * orig_data
= data
;
1549 unsigned int bytes_read
;
1551 if (data
> end
|| (data
== end
&& form
!= DW_FORM_flag_present
))
1553 warn (_("Corrupt attribute\n"));
1562 case DW_FORM_ref_addr
:
1563 if (dwarf_version
== 2)
1564 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1565 else if (dwarf_version
== 3 || dwarf_version
== 4)
1566 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1568 error (_("Internal error: DWARF version is not 2, 3 or 4.\n"));
1573 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1577 case DW_FORM_line_strp
:
1578 case DW_FORM_sec_offset
:
1579 case DW_FORM_GNU_ref_alt
:
1580 case DW_FORM_GNU_strp_alt
:
1581 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1584 case DW_FORM_flag_present
:
1591 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1596 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
1601 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1605 uvalue
= read_sleb128 (data
, & bytes_read
, end
);
1609 case DW_FORM_GNU_str_index
:
1610 uvalue
= read_uleb128 (data
, & bytes_read
, end
);
1614 case DW_FORM_ref_udata
:
1616 uvalue
= read_uleb128 (data
, & bytes_read
, end
);
1620 case DW_FORM_indirect
:
1621 form
= read_uleb128 (data
, & bytes_read
, end
);
1624 printf ("%c%s", delimiter
, get_FORM_name (form
));
1625 if (form
== DW_FORM_implicit_const
)
1627 implicit_const
= read_sleb128 (data
, & bytes_read
, end
);
1630 return read_and_display_attr_value (attribute
, form
, implicit_const
, data
,
1631 end
, cu_offset
, pointer_size
,
1632 offset_size
, dwarf_version
,
1633 debug_info_p
, do_loc
,
1634 section
, this_set
, delimiter
);
1635 case DW_FORM_GNU_addr_index
:
1636 uvalue
= read_uleb128 (data
, & bytes_read
, end
);
1643 case DW_FORM_ref_addr
:
1645 printf ("%c<0x%s>", delimiter
, dwarf_vmatoa ("x",uvalue
));
1648 case DW_FORM_GNU_ref_alt
:
1650 printf ("%c<alt 0x%s>", delimiter
, dwarf_vmatoa ("x",uvalue
));
1656 case DW_FORM_ref_udata
:
1658 printf ("%c<0x%s>", delimiter
, dwarf_vmatoa ("x", uvalue
+ cu_offset
));
1663 case DW_FORM_sec_offset
:
1665 printf ("%c0x%s", delimiter
, dwarf_vmatoa ("x", uvalue
));
1668 case DW_FORM_flag_present
:
1675 printf ("%c%s", delimiter
, dwarf_vmatoa ("d", uvalue
));
1678 case DW_FORM_implicit_const
:
1680 printf ("%c%s", delimiter
, dwarf_vmatoa ("d", implicit_const
));
1687 dwarf_vma high_bits
;
1691 SAFE_BYTE_GET64 (data
, &high_bits
, &uvalue
, end
);
1693 if (form
== DW_FORM_ref8
)
1694 add64 (& high_bits
, & utmp
, cu_offset
);
1695 printf ("%c0x%s", delimiter
,
1696 dwarf_vmatoa64 (high_bits
, utmp
, buf
, sizeof (buf
)));
1699 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
1700 && num_debug_info_entries
== 0)
1702 if (sizeof (uvalue
) == 8)
1703 SAFE_BYTE_GET (uvalue
, data
, 8, end
);
1705 error (_("DW_FORM_data8 is unsupported when sizeof (dwarf_vma) != 8\n"));
1711 case DW_FORM_string
:
1713 printf ("%c%.*s", delimiter
, (int) (end
- data
), data
);
1714 data
+= strnlen ((char *) data
, end
- data
) + 1;
1718 case DW_FORM_exprloc
:
1719 uvalue
= read_uleb128 (data
, & bytes_read
, end
);
1720 block_start
= data
+ bytes_read
;
1721 if (block_start
>= end
)
1723 warn (_("Block ends prematurely\n"));
1727 /* FIXME: Testing "(block_start + uvalue) < block_start" miscompiles with
1728 gcc 4.8.3 running on an x86_64 host in 32-bit mode. So we pre-compute
1729 block_start + uvalue here. */
1730 data
= block_start
+ uvalue
;
1731 /* PR 17512: file: 008-103549-0.001:0.1. */
1732 if (block_start
+ uvalue
> end
|| data
< block_start
)
1734 warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue
);
1735 uvalue
= end
- block_start
;
1738 data
= block_start
+ uvalue
;
1740 data
= display_block (block_start
, uvalue
, end
, delimiter
);
1743 case DW_FORM_block1
:
1744 SAFE_BYTE_GET (uvalue
, data
, 1, end
);
1745 block_start
= data
+ 1;
1746 if (block_start
>= end
)
1748 warn (_("Block ends prematurely\n"));
1752 data
= block_start
+ uvalue
;
1753 if (block_start
+ uvalue
> end
|| data
< block_start
)
1755 warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue
);
1756 uvalue
= end
- block_start
;
1759 data
= block_start
+ uvalue
;
1761 data
= display_block (block_start
, uvalue
, end
, delimiter
);
1764 case DW_FORM_block2
:
1765 SAFE_BYTE_GET (uvalue
, data
, 2, end
);
1766 block_start
= data
+ 2;
1767 if (block_start
>= end
)
1769 warn (_("Block ends prematurely\n"));
1773 data
= block_start
+ uvalue
;
1774 if (block_start
+ uvalue
> end
|| data
< block_start
)
1776 warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue
);
1777 uvalue
= end
- block_start
;
1780 data
= block_start
+ uvalue
;
1782 data
= display_block (block_start
, uvalue
, end
, delimiter
);
1785 case DW_FORM_block4
:
1786 SAFE_BYTE_GET (uvalue
, data
, 4, end
);
1787 block_start
= data
+ 4;
1788 /* PR 17512: file: 3371-3907-0.004. */
1789 if (block_start
>= end
)
1791 warn (_("Block ends prematurely\n"));
1795 data
= block_start
+ uvalue
;
1796 if (block_start
+ uvalue
> end
1797 /* PR 17531: file: 5b5f0592. */
1798 || data
< block_start
)
1800 warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue
);
1801 uvalue
= end
- block_start
;
1804 data
= block_start
+ uvalue
;
1806 data
= display_block (block_start
, uvalue
, end
, delimiter
);
1811 printf (_("%c(indirect string, offset: 0x%s): %s"), delimiter
,
1812 dwarf_vmatoa ("x", uvalue
),
1813 fetch_indirect_string (uvalue
));
1816 case DW_FORM_line_strp
:
1818 printf (_("%c(indirect line string, offset: 0x%s): %s"), delimiter
,
1819 dwarf_vmatoa ("x", uvalue
),
1820 fetch_indirect_line_string (uvalue
));
1823 case DW_FORM_GNU_str_index
:
1826 const char *suffix
= strrchr (section
->name
, '.');
1827 int dwo
= (suffix
&& strcmp (suffix
, ".dwo") == 0) ? 1 : 0;
1829 printf (_("%c(indexed string: 0x%s): %s"), delimiter
,
1830 dwarf_vmatoa ("x", uvalue
),
1831 fetch_indexed_string (uvalue
, this_set
, offset_size
, dwo
));
1835 case DW_FORM_GNU_strp_alt
:
1837 printf (_("%c(alt indirect string, offset: 0x%s)"), delimiter
,
1838 dwarf_vmatoa ("x", uvalue
));
1841 case DW_FORM_indirect
:
1842 /* Handled above. */
1845 case DW_FORM_ref_sig8
:
1848 dwarf_vma high_bits
;
1851 SAFE_BYTE_GET64 (data
, &high_bits
, &uvalue
, end
);
1852 printf ("%csignature: 0x%s", delimiter
,
1853 dwarf_vmatoa64 (high_bits
, uvalue
, buf
, sizeof (buf
)));
1858 case DW_FORM_GNU_addr_index
:
1860 printf (_("%c(addr_index: 0x%s): %s"), delimiter
,
1861 dwarf_vmatoa ("x", uvalue
),
1862 fetch_indexed_value (uvalue
* pointer_size
, pointer_size
));
1866 warn (_("Unrecognized form: %lu\n"), form
);
1870 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
1871 && num_debug_info_entries
== 0
1872 && debug_info_p
!= NULL
)
1876 case DW_AT_frame_base
:
1877 have_frame_base
= 1;
1879 case DW_AT_location
:
1880 case DW_AT_string_length
:
1881 case DW_AT_return_addr
:
1882 case DW_AT_data_member_location
:
1883 case DW_AT_vtable_elem_location
:
1885 case DW_AT_static_link
:
1886 case DW_AT_use_location
:
1887 case DW_AT_GNU_call_site_value
:
1888 case DW_AT_GNU_call_site_data_value
:
1889 case DW_AT_GNU_call_site_target
:
1890 case DW_AT_GNU_call_site_target_clobbered
:
1891 if ((dwarf_version
< 4
1892 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
1893 || form
== DW_FORM_sec_offset
)
1895 /* Process location list. */
1896 unsigned int lmax
= debug_info_p
->max_loc_offsets
;
1897 unsigned int num
= debug_info_p
->num_loc_offsets
;
1899 if (lmax
== 0 || num
>= lmax
)
1902 debug_info_p
->loc_offsets
= (dwarf_vma
*)
1903 xcrealloc (debug_info_p
->loc_offsets
,
1904 lmax
, sizeof (*debug_info_p
->loc_offsets
));
1905 debug_info_p
->have_frame_base
= (int *)
1906 xcrealloc (debug_info_p
->have_frame_base
,
1907 lmax
, sizeof (*debug_info_p
->have_frame_base
));
1908 debug_info_p
->max_loc_offsets
= lmax
;
1910 if (this_set
!= NULL
)
1911 uvalue
+= this_set
->section_offsets
[DW_SECT_LOC
];
1912 debug_info_p
->loc_offsets
[num
] = uvalue
;
1913 debug_info_p
->have_frame_base
[num
] = have_frame_base
;
1914 debug_info_p
->num_loc_offsets
++;
1919 if (need_base_address
)
1920 debug_info_p
->base_address
= uvalue
;
1923 case DW_AT_GNU_addr_base
:
1924 debug_info_p
->addr_base
= uvalue
;
1927 case DW_AT_GNU_ranges_base
:
1928 debug_info_p
->ranges_base
= uvalue
;
1932 if ((dwarf_version
< 4
1933 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
1934 || form
== DW_FORM_sec_offset
)
1936 /* Process range list. */
1937 unsigned int lmax
= debug_info_p
->max_range_lists
;
1938 unsigned int num
= debug_info_p
->num_range_lists
;
1940 if (lmax
== 0 || num
>= lmax
)
1943 debug_info_p
->range_lists
= (dwarf_vma
*)
1944 xcrealloc (debug_info_p
->range_lists
,
1945 lmax
, sizeof (*debug_info_p
->range_lists
));
1946 debug_info_p
->max_range_lists
= lmax
;
1948 debug_info_p
->range_lists
[num
] = uvalue
;
1949 debug_info_p
->num_range_lists
++;
1958 if (do_loc
|| attribute
== 0)
1961 /* For some attributes we can display further information. */
1968 case DW_INL_not_inlined
:
1969 printf (_("(not inlined)"));
1971 case DW_INL_inlined
:
1972 printf (_("(inlined)"));
1974 case DW_INL_declared_not_inlined
:
1975 printf (_("(declared as inline but ignored)"));
1977 case DW_INL_declared_inlined
:
1978 printf (_("(declared as inline and inlined)"));
1981 printf (_(" (Unknown inline attribute value: %s)"),
1982 dwarf_vmatoa ("x", uvalue
));
1987 case DW_AT_language
:
1991 /* Ordered by the numeric value of these constants. */
1992 case DW_LANG_C89
: printf ("(ANSI C)"); break;
1993 case DW_LANG_C
: printf ("(non-ANSI C)"); break;
1994 case DW_LANG_Ada83
: printf ("(Ada)"); break;
1995 case DW_LANG_C_plus_plus
: printf ("(C++)"); break;
1996 case DW_LANG_Cobol74
: printf ("(Cobol 74)"); break;
1997 case DW_LANG_Cobol85
: printf ("(Cobol 85)"); break;
1998 case DW_LANG_Fortran77
: printf ("(FORTRAN 77)"); break;
1999 case DW_LANG_Fortran90
: printf ("(Fortran 90)"); break;
2000 case DW_LANG_Pascal83
: printf ("(ANSI Pascal)"); break;
2001 case DW_LANG_Modula2
: printf ("(Modula 2)"); break;
2002 /* DWARF 2.1 values. */
2003 case DW_LANG_Java
: printf ("(Java)"); break;
2004 case DW_LANG_C99
: printf ("(ANSI C99)"); break;
2005 case DW_LANG_Ada95
: printf ("(ADA 95)"); break;
2006 case DW_LANG_Fortran95
: printf ("(Fortran 95)"); break;
2007 /* DWARF 3 values. */
2008 case DW_LANG_PLI
: printf ("(PLI)"); break;
2009 case DW_LANG_ObjC
: printf ("(Objective C)"); break;
2010 case DW_LANG_ObjC_plus_plus
: printf ("(Objective C++)"); break;
2011 case DW_LANG_UPC
: printf ("(Unified Parallel C)"); break;
2012 case DW_LANG_D
: printf ("(D)"); break;
2013 /* DWARF 4 values. */
2014 case DW_LANG_Python
: printf ("(Python)"); break;
2015 /* DWARF 5 values. */
2016 case DW_LANG_Go
: printf ("(Go)"); break;
2017 case DW_LANG_C_plus_plus_11
: printf ("(C++11)"); break;
2018 case DW_LANG_C11
: printf ("(C11)"); break;
2019 case DW_LANG_C_plus_plus_14
: printf ("(C++14)"); break;
2020 case DW_LANG_Fortran03
: printf ("(Fortran 03)"); break;
2021 case DW_LANG_Fortran08
: printf ("(Fortran 08)"); break;
2022 /* MIPS extension. */
2023 case DW_LANG_Mips_Assembler
: printf ("(MIPS assembler)"); break;
2024 /* UPC extension. */
2025 case DW_LANG_Upc
: printf ("(Unified Parallel C)"); break;
2027 if (uvalue
>= DW_LANG_lo_user
&& uvalue
<= DW_LANG_hi_user
)
2028 printf (_("(implementation defined: %s)"),
2029 dwarf_vmatoa ("x", uvalue
));
2031 printf (_("(Unknown: %s)"), dwarf_vmatoa ("x", uvalue
));
2036 case DW_AT_encoding
:
2040 case DW_ATE_void
: printf ("(void)"); break;
2041 case DW_ATE_address
: printf ("(machine address)"); break;
2042 case DW_ATE_boolean
: printf ("(boolean)"); break;
2043 case DW_ATE_complex_float
: printf ("(complex float)"); break;
2044 case DW_ATE_float
: printf ("(float)"); break;
2045 case DW_ATE_signed
: printf ("(signed)"); break;
2046 case DW_ATE_signed_char
: printf ("(signed char)"); break;
2047 case DW_ATE_unsigned
: printf ("(unsigned)"); break;
2048 case DW_ATE_unsigned_char
: printf ("(unsigned char)"); break;
2049 /* DWARF 2.1 values: */
2050 case DW_ATE_imaginary_float
: printf ("(imaginary float)"); break;
2051 case DW_ATE_decimal_float
: printf ("(decimal float)"); break;
2052 /* DWARF 3 values: */
2053 case DW_ATE_packed_decimal
: printf ("(packed_decimal)"); break;
2054 case DW_ATE_numeric_string
: printf ("(numeric_string)"); break;
2055 case DW_ATE_edited
: printf ("(edited)"); break;
2056 case DW_ATE_signed_fixed
: printf ("(signed_fixed)"); break;
2057 case DW_ATE_unsigned_fixed
: printf ("(unsigned_fixed)"); break;
2058 /* HP extensions: */
2059 case DW_ATE_HP_float80
: printf ("(HP_float80)"); break;
2060 case DW_ATE_HP_complex_float80
: printf ("(HP_complex_float80)"); break;
2061 case DW_ATE_HP_float128
: printf ("(HP_float128)"); break;
2062 case DW_ATE_HP_complex_float128
:printf ("(HP_complex_float128)"); break;
2063 case DW_ATE_HP_floathpintel
: printf ("(HP_floathpintel)"); break;
2064 case DW_ATE_HP_imaginary_float80
: printf ("(HP_imaginary_float80)"); break;
2065 case DW_ATE_HP_imaginary_float128
: printf ("(HP_imaginary_float128)"); break;
2066 /* DWARF 4 values: */
2067 case DW_ATE_UTF
: printf ("(unicode string)"); break;
2070 if (uvalue
>= DW_ATE_lo_user
2071 && uvalue
<= DW_ATE_hi_user
)
2072 printf (_("(user defined type)"));
2074 printf (_("(unknown type)"));
2079 case DW_AT_accessibility
:
2083 case DW_ACCESS_public
: printf ("(public)"); break;
2084 case DW_ACCESS_protected
: printf ("(protected)"); break;
2085 case DW_ACCESS_private
: printf ("(private)"); break;
2087 printf (_("(unknown accessibility)"));
2092 case DW_AT_visibility
:
2096 case DW_VIS_local
: printf ("(local)"); break;
2097 case DW_VIS_exported
: printf ("(exported)"); break;
2098 case DW_VIS_qualified
: printf ("(qualified)"); break;
2099 default: printf (_("(unknown visibility)")); break;
2103 case DW_AT_virtuality
:
2107 case DW_VIRTUALITY_none
: printf ("(none)"); break;
2108 case DW_VIRTUALITY_virtual
: printf ("(virtual)"); break;
2109 case DW_VIRTUALITY_pure_virtual
:printf ("(pure_virtual)"); break;
2110 default: printf (_("(unknown virtuality)")); break;
2114 case DW_AT_identifier_case
:
2118 case DW_ID_case_sensitive
: printf ("(case_sensitive)"); break;
2119 case DW_ID_up_case
: printf ("(up_case)"); break;
2120 case DW_ID_down_case
: printf ("(down_case)"); break;
2121 case DW_ID_case_insensitive
: printf ("(case_insensitive)"); break;
2122 default: printf (_("(unknown case)")); break;
2126 case DW_AT_calling_convention
:
2130 case DW_CC_normal
: printf ("(normal)"); break;
2131 case DW_CC_program
: printf ("(program)"); break;
2132 case DW_CC_nocall
: printf ("(nocall)"); break;
2134 if (uvalue
>= DW_CC_lo_user
2135 && uvalue
<= DW_CC_hi_user
)
2136 printf (_("(user defined)"));
2138 printf (_("(unknown convention)"));
2142 case DW_AT_ordering
:
2146 case -1: printf (_("(undefined)")); break;
2147 case 0: printf ("(row major)"); break;
2148 case 1: printf ("(column major)"); break;
2152 case DW_AT_frame_base
:
2153 have_frame_base
= 1;
2155 case DW_AT_location
:
2156 case DW_AT_string_length
:
2157 case DW_AT_return_addr
:
2158 case DW_AT_data_member_location
:
2159 case DW_AT_vtable_elem_location
:
2161 case DW_AT_static_link
:
2162 case DW_AT_use_location
:
2163 case DW_AT_GNU_call_site_value
:
2164 case DW_AT_GNU_call_site_data_value
:
2165 case DW_AT_GNU_call_site_target
:
2166 case DW_AT_GNU_call_site_target_clobbered
:
2167 if ((dwarf_version
< 4
2168 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
2169 || form
== DW_FORM_sec_offset
)
2170 printf (_(" (location list)"));
2172 case DW_AT_allocated
:
2173 case DW_AT_associated
:
2174 case DW_AT_data_location
:
2176 case DW_AT_upper_bound
:
2177 case DW_AT_lower_bound
:
2180 int need_frame_base
;
2183 need_frame_base
= decode_location_expression (block_start
,
2188 cu_offset
, section
);
2190 if (need_frame_base
&& !have_frame_base
)
2191 printf (_(" [without DW_AT_frame_base]"));
2197 if (form
== DW_FORM_ref_sig8
2198 || form
== DW_FORM_GNU_ref_alt
)
2201 if (form
== DW_FORM_ref1
2202 || form
== DW_FORM_ref2
2203 || form
== DW_FORM_ref4
2204 || form
== DW_FORM_ref_udata
)
2205 uvalue
+= cu_offset
;
2207 if (uvalue
>= section
->size
)
2208 warn (_("Offset %s used as value for DW_AT_import attribute of DIE at offset 0x%lx is too big.\n"),
2209 dwarf_vmatoa ("x", uvalue
),
2210 (unsigned long) (orig_data
- section
->start
));
2213 unsigned long abbrev_number
;
2214 abbrev_entry
* entry
;
2216 abbrev_number
= read_uleb128 (section
->start
+ uvalue
, NULL
, end
);
2218 printf (_("\t[Abbrev Number: %ld"), abbrev_number
);
2219 /* Don't look up abbrev for DW_FORM_ref_addr, as it very often will
2220 use different abbrev table, and we don't track .debug_info chunks
2222 if (form
!= DW_FORM_ref_addr
)
2224 for (entry
= first_abbrev
; entry
!= NULL
; entry
= entry
->next
)
2225 if (entry
->entry
== abbrev_number
)
2228 printf (" (%s)", get_TAG_name (entry
->tag
));
2243 get_AT_name (unsigned long attribute
)
2248 return "DW_AT value: 0";
2250 /* One value is shared by the MIPS and HP extensions: */
2251 if (attribute
== DW_AT_MIPS_fde
)
2252 return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable";
2254 name
= get_DW_AT_name (attribute
);
2258 static char buffer
[100];
2260 snprintf (buffer
, sizeof (buffer
), _("Unknown AT value: %lx"),
2268 static unsigned char *
2269 read_and_display_attr (unsigned long attribute
,
2271 dwarf_signed_vma implicit_const
,
2272 unsigned char * data
,
2273 unsigned char * end
,
2274 dwarf_vma cu_offset
,
2275 dwarf_vma pointer_size
,
2276 dwarf_vma offset_size
,
2278 debug_info
* debug_info_p
,
2280 struct dwarf_section
* section
,
2281 struct cu_tu_set
* this_set
)
2284 printf (" %-18s:", get_AT_name (attribute
));
2285 data
= read_and_display_attr_value (attribute
, form
, implicit_const
, data
, end
,
2286 cu_offset
, pointer_size
, offset_size
,
2287 dwarf_version
, debug_info_p
,
2288 do_loc
, section
, this_set
, ' ');
2294 /* Process the contents of a .debug_info section. If do_loc is non-zero
2295 then we are scanning for location lists and we do not want to display
2296 anything to the user. If do_types is non-zero, we are processing
2297 a .debug_types section instead of a .debug_info section. */
2300 process_debug_info (struct dwarf_section
*section
,
2302 enum dwarf_section_display_enum abbrev_sec
,
2306 unsigned char *start
= section
->start
;
2307 unsigned char *end
= start
+ section
->size
;
2308 unsigned char *section_begin
;
2310 unsigned int num_units
= 0;
2312 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
2313 && num_debug_info_entries
== 0
2318 /* First scan the section to get the number of comp units. */
2319 for (section_begin
= start
, num_units
= 0; section_begin
< end
;
2322 /* Read the first 4 bytes. For a 32-bit DWARF section, this
2323 will be the length. For a 64-bit DWARF section, it'll be
2324 the escape code 0xffffffff followed by an 8 byte length. */
2325 SAFE_BYTE_GET (length
, section_begin
, 4, end
);
2327 if (length
== 0xffffffff)
2329 SAFE_BYTE_GET (length
, section_begin
+ 4, 8, end
);
2330 section_begin
+= length
+ 12;
2332 else if (length
>= 0xfffffff0 && length
< 0xffffffff)
2334 warn (_("Reserved length value (0x%s) found in section %s\n"),
2335 dwarf_vmatoa ("x", length
), section
->name
);
2339 section_begin
+= length
+ 4;
2341 /* Negative values are illegal, they may even cause infinite
2342 looping. This can happen if we can't accurately apply
2343 relocations to an object file, or if the file is corrupt. */
2344 if ((signed long) length
<= 0 || section_begin
< start
)
2346 warn (_("Corrupt unit length (0x%s) found in section %s\n"),
2347 dwarf_vmatoa ("x", length
), section
->name
);
2354 error (_("No comp units in %s section ?\n"), section
->name
);
2358 /* Then allocate an array to hold the information. */
2359 debug_information
= (debug_info
*) cmalloc (num_units
,
2360 sizeof (* debug_information
));
2361 if (debug_information
== NULL
)
2363 error (_("Not enough memory for a debug info array of %u entries\n"),
2365 alloc_num_debug_info_entries
= num_debug_info_entries
= 0;
2368 /* PR 17531: file: 92ca3797.
2369 We cannot rely upon the debug_information array being initialised
2370 before it is used. A corrupt file could easily contain references
2371 to a unit for which information has not been made available. So
2372 we ensure that the array is zeroed here. */
2373 memset (debug_information
, 0, num_units
* sizeof (*debug_information
));
2375 alloc_num_debug_info_entries
= num_units
;
2380 if (dwarf_start_die
== 0)
2381 printf (_("Contents of the %s section:\n\n"), section
->name
);
2383 load_debug_section (str
, file
);
2384 load_debug_section (line_str
, file
);
2385 load_debug_section (str_dwo
, file
);
2386 load_debug_section (str_index
, file
);
2387 load_debug_section (str_index_dwo
, file
);
2388 load_debug_section (debug_addr
, file
);
2391 load_debug_section (abbrev_sec
, file
);
2392 if (debug_displays
[abbrev_sec
].section
.start
== NULL
)
2394 warn (_("Unable to locate %s section!\n"),
2395 debug_displays
[abbrev_sec
].section
.name
);
2399 for (section_begin
= start
, unit
= 0; start
< end
; unit
++)
2401 DWARF2_Internal_CompUnit compunit
;
2402 unsigned char *hdrptr
;
2403 unsigned char *tags
;
2404 int level
, last_level
, saved_level
;
2405 dwarf_vma cu_offset
;
2406 unsigned int offset_size
;
2407 int initial_length_size
;
2408 dwarf_vma signature_high
= 0;
2409 dwarf_vma signature_low
= 0;
2410 dwarf_vma type_offset
= 0;
2411 struct cu_tu_set
*this_set
;
2412 dwarf_vma abbrev_base
;
2417 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 4, end
);
2419 if (compunit
.cu_length
== 0xffffffff)
2421 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 8, end
);
2423 initial_length_size
= 12;
2428 initial_length_size
= 4;
2431 SAFE_BYTE_GET_AND_INC (compunit
.cu_version
, hdrptr
, 2, end
);
2433 cu_offset
= start
- section_begin
;
2435 this_set
= find_cu_tu_set_v2 (cu_offset
, do_types
);
2437 if (compunit
.cu_version
< 5)
2439 compunit
.cu_unit_type
= DW_UT_compile
;
2440 /* Initialize it due to a false compiler warning. */
2441 compunit
.cu_pointer_size
= -1;
2445 SAFE_BYTE_GET_AND_INC (compunit
.cu_unit_type
, hdrptr
, 1, end
);
2446 do_types
= (compunit
.cu_unit_type
== DW_UT_type
);
2448 SAFE_BYTE_GET_AND_INC (compunit
.cu_pointer_size
, hdrptr
, 1, end
);
2451 SAFE_BYTE_GET_AND_INC (compunit
.cu_abbrev_offset
, hdrptr
, offset_size
, end
);
2453 if (this_set
== NULL
)
2456 abbrev_size
= debug_displays
[abbrev_sec
].section
.size
;
2460 abbrev_base
= this_set
->section_offsets
[DW_SECT_ABBREV
];
2461 abbrev_size
= this_set
->section_sizes
[DW_SECT_ABBREV
];
2464 if (compunit
.cu_version
< 5)
2465 SAFE_BYTE_GET_AND_INC (compunit
.cu_pointer_size
, hdrptr
, 1, end
);
2467 /* PR 17512: file: 001-108546-0.001:0.1. */
2468 if (compunit
.cu_pointer_size
< 2 || compunit
.cu_pointer_size
> 8)
2470 warn (_("Invalid pointer size (%d) in compunit header, using %d instead\n"),
2471 compunit
.cu_pointer_size
, offset_size
);
2472 compunit
.cu_pointer_size
= offset_size
;
2477 SAFE_BYTE_GET64 (hdrptr
, &signature_high
, &signature_low
, end
);
2479 SAFE_BYTE_GET_AND_INC (type_offset
, hdrptr
, offset_size
, end
);
2482 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
2483 && num_debug_info_entries
== 0
2486 debug_information
[unit
].cu_offset
= cu_offset
;
2487 debug_information
[unit
].pointer_size
2488 = compunit
.cu_pointer_size
;
2489 debug_information
[unit
].offset_size
= offset_size
;
2490 debug_information
[unit
].dwarf_version
= compunit
.cu_version
;
2491 debug_information
[unit
].base_address
= 0;
2492 debug_information
[unit
].addr_base
= DEBUG_INFO_UNAVAILABLE
;
2493 debug_information
[unit
].ranges_base
= DEBUG_INFO_UNAVAILABLE
;
2494 debug_information
[unit
].loc_offsets
= NULL
;
2495 debug_information
[unit
].have_frame_base
= NULL
;
2496 debug_information
[unit
].max_loc_offsets
= 0;
2497 debug_information
[unit
].num_loc_offsets
= 0;
2498 debug_information
[unit
].range_lists
= NULL
;
2499 debug_information
[unit
].max_range_lists
= 0;
2500 debug_information
[unit
].num_range_lists
= 0;
2503 if (!do_loc
&& dwarf_start_die
== 0)
2505 printf (_(" Compilation Unit @ offset 0x%s:\n"),
2506 dwarf_vmatoa ("x", cu_offset
));
2507 printf (_(" Length: 0x%s (%s)\n"),
2508 dwarf_vmatoa ("x", compunit
.cu_length
),
2509 offset_size
== 8 ? "64-bit" : "32-bit");
2510 printf (_(" Version: %d\n"), compunit
.cu_version
);
2511 printf (_(" Abbrev Offset: 0x%s\n"),
2512 dwarf_vmatoa ("x", compunit
.cu_abbrev_offset
));
2513 printf (_(" Pointer Size: %d\n"), compunit
.cu_pointer_size
);
2518 printf (_(" Signature: 0x%s\n"),
2519 dwarf_vmatoa64 (signature_high
, signature_low
,
2520 buf
, sizeof (buf
)));
2521 printf (_(" Type Offset: 0x%s\n"),
2522 dwarf_vmatoa ("x", type_offset
));
2524 if (this_set
!= NULL
)
2526 dwarf_vma
*offsets
= this_set
->section_offsets
;
2527 size_t *sizes
= this_set
->section_sizes
;
2529 printf (_(" Section contributions:\n"));
2530 printf (_(" .debug_abbrev.dwo: 0x%s 0x%s\n"),
2531 dwarf_vmatoa ("x", offsets
[DW_SECT_ABBREV
]),
2532 dwarf_vmatoa ("x", sizes
[DW_SECT_ABBREV
]));
2533 printf (_(" .debug_line.dwo: 0x%s 0x%s\n"),
2534 dwarf_vmatoa ("x", offsets
[DW_SECT_LINE
]),
2535 dwarf_vmatoa ("x", sizes
[DW_SECT_LINE
]));
2536 printf (_(" .debug_loc.dwo: 0x%s 0x%s\n"),
2537 dwarf_vmatoa ("x", offsets
[DW_SECT_LOC
]),
2538 dwarf_vmatoa ("x", sizes
[DW_SECT_LOC
]));
2539 printf (_(" .debug_str_offsets.dwo: 0x%s 0x%s\n"),
2540 dwarf_vmatoa ("x", offsets
[DW_SECT_STR_OFFSETS
]),
2541 dwarf_vmatoa ("x", sizes
[DW_SECT_STR_OFFSETS
]));
2545 if (cu_offset
+ compunit
.cu_length
+ initial_length_size
2548 warn (_("Debug info is corrupted, length of CU at %s"
2549 " extends beyond end of section (length = %s)\n"),
2550 dwarf_vmatoa ("x", cu_offset
),
2551 dwarf_vmatoa ("x", compunit
.cu_length
));
2556 start
+= compunit
.cu_length
+ initial_length_size
;
2560 warn (_("Debug info is corrupt. CU at %s extends beyond end of section"),
2561 dwarf_vmatoa ("x", cu_offset
));
2565 if (compunit
.cu_version
< 2 || compunit
.cu_version
> 5)
2567 warn (_("CU at offset %s contains corrupt or "
2568 "unsupported version number: %d.\n"),
2569 dwarf_vmatoa ("x", cu_offset
), compunit
.cu_version
);
2573 if (compunit
.cu_unit_type
!= DW_UT_compile
2574 && compunit
.cu_unit_type
!= DW_UT_type
)
2576 warn (_("CU at offset %s contains corrupt or "
2577 "unsupported unit type: %d.\n"),
2578 dwarf_vmatoa ("x", cu_offset
), compunit
.cu_unit_type
);
2584 /* Process the abbrevs used by this compilation unit. */
2585 if (compunit
.cu_abbrev_offset
>= abbrev_size
)
2586 warn (_("Debug info is corrupted, abbrev offset (%lx) is larger than abbrev section size (%lx)\n"),
2587 (unsigned long) compunit
.cu_abbrev_offset
,
2588 (unsigned long) abbrev_size
);
2589 /* PR 17531: file:4bcd9ce9. */
2590 else if ((abbrev_base
+ abbrev_size
)
2591 > debug_displays
[abbrev_sec
].section
.size
)
2592 warn (_("Debug info is corrupted, abbrev size (%lx) is larger than abbrev section size (%lx)\n"),
2593 (unsigned long) abbrev_base
+ abbrev_size
,
2594 (unsigned long) debug_displays
[abbrev_sec
].section
.size
);
2596 process_abbrev_section
2597 (((unsigned char *) debug_displays
[abbrev_sec
].section
.start
2598 + abbrev_base
+ compunit
.cu_abbrev_offset
),
2599 ((unsigned char *) debug_displays
[abbrev_sec
].section
.start
2600 + abbrev_base
+ abbrev_size
));
2605 while (tags
< start
)
2607 unsigned int bytes_read
;
2608 unsigned long abbrev_number
;
2609 unsigned long die_offset
;
2610 abbrev_entry
*entry
;
2612 int do_printing
= 1;
2614 die_offset
= tags
- section_begin
;
2616 abbrev_number
= read_uleb128 (tags
, & bytes_read
, start
);
2619 /* A null DIE marks the end of a list of siblings or it may also be
2620 a section padding. */
2621 if (abbrev_number
== 0)
2623 /* Check if it can be a section padding for the last CU. */
2624 if (level
== 0 && start
== end
)
2628 for (chk
= tags
; chk
< start
; chk
++)
2635 if (!do_loc
&& die_offset
>= dwarf_start_die
2636 && (dwarf_cutoff_level
== -1
2637 || level
< dwarf_cutoff_level
))
2638 printf (_(" <%d><%lx>: Abbrev Number: 0\n"),
2644 static unsigned num_bogus_warns
= 0;
2646 if (num_bogus_warns
< 3)
2648 warn (_("Bogus end-of-siblings marker detected at offset %lx in %s section\n"),
2649 die_offset
, section
->name
);
2651 if (num_bogus_warns
== 3)
2652 warn (_("Further warnings about bogus end-of-sibling markers suppressed\n"));
2655 if (dwarf_start_die
!= 0 && level
< saved_level
)
2662 if (dwarf_start_die
!= 0 && die_offset
< dwarf_start_die
)
2666 if (dwarf_start_die
!= 0 && die_offset
== dwarf_start_die
)
2667 saved_level
= level
;
2668 do_printing
= (dwarf_cutoff_level
== -1
2669 || level
< dwarf_cutoff_level
);
2671 printf (_(" <%d><%lx>: Abbrev Number: %lu"),
2672 level
, die_offset
, abbrev_number
);
2673 else if (dwarf_cutoff_level
== -1
2674 || last_level
< dwarf_cutoff_level
)
2675 printf (_(" <%d><%lx>: ...\n"), level
, die_offset
);
2680 /* Scan through the abbreviation list until we reach the
2682 for (entry
= first_abbrev
;
2683 entry
&& entry
->entry
!= abbrev_number
;
2684 entry
= entry
->next
)
2689 if (!do_loc
&& do_printing
)
2694 warn (_("DIE at offset 0x%lx refers to abbreviation number %lu which does not exist\n"),
2695 die_offset
, abbrev_number
);
2699 if (!do_loc
&& do_printing
)
2700 printf (" (%s)\n", get_TAG_name (entry
->tag
));
2705 need_base_address
= 0;
2707 case DW_TAG_compile_unit
:
2708 need_base_address
= 1;
2710 case DW_TAG_entry_point
:
2711 case DW_TAG_subprogram
:
2712 need_base_address
= 0;
2713 /* Assuming that there is no DW_AT_frame_base. */
2714 have_frame_base
= 0;
2718 for (attr
= entry
->first_attr
;
2719 attr
&& attr
->attribute
;
2724 if (! do_loc
&& do_printing
)
2725 /* Show the offset from where the tag was extracted. */
2726 printf (" <%lx>", (unsigned long)(tags
- section_begin
));
2728 if (debug_information
&& unit
< alloc_num_debug_info_entries
)
2729 arg
= debug_information
+ unit
;
2733 tags
= read_and_display_attr (attr
->attribute
,
2735 attr
->implicit_const
,
2739 compunit
.cu_pointer_size
,
2741 compunit
.cu_version
,
2743 do_loc
|| ! do_printing
,
2748 if (entry
->children
)
2753 /* Set num_debug_info_entries here so that it can be used to check if
2754 we need to process .debug_loc and .debug_ranges sections. */
2755 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
2756 && num_debug_info_entries
== 0
2759 if (num_units
> alloc_num_debug_info_entries
)
2760 num_debug_info_entries
= alloc_num_debug_info_entries
;
2762 num_debug_info_entries
= num_units
;
2771 /* Locate and scan the .debug_info section in the file and record the pointer
2772 sizes and offsets for the compilation units in it. Usually an executable
2773 will have just one pointer size, but this is not guaranteed, and so we try
2774 not to make any assumptions. Returns zero upon failure, or the number of
2775 compilation units upon success. */
2778 load_debug_info (void * file
)
2780 /* Reset the last pointer size so that we can issue correct error
2781 messages if we are displaying the contents of more than one section. */
2782 last_pointer_size
= 0;
2783 warned_about_missing_comp_units
= FALSE
;
2785 /* If we have already tried and failed to load the .debug_info
2786 section then do not bother to repeat the task. */
2787 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
2790 /* If we already have the information there is nothing else to do. */
2791 if (num_debug_info_entries
> 0)
2792 return num_debug_info_entries
;
2794 /* If this is a DWARF package file, load the CU and TU indexes. */
2795 (void) load_cu_tu_indexes (file
);
2797 if (load_debug_section (info
, file
)
2798 && process_debug_info (&debug_displays
[info
].section
, file
, abbrev
, 1, 0))
2799 return num_debug_info_entries
;
2801 if (load_debug_section (info_dwo
, file
)
2802 && process_debug_info (&debug_displays
[info_dwo
].section
, file
,
2804 return num_debug_info_entries
;
2806 num_debug_info_entries
= DEBUG_INFO_UNAVAILABLE
;
2810 /* Read a DWARF .debug_line section header starting at DATA.
2811 Upon success returns an updated DATA pointer and the LINFO
2812 structure and the END_OF_SEQUENCE pointer will be filled in.
2813 Otherwise returns NULL. */
2815 static unsigned char *
2816 read_debug_line_header (struct dwarf_section
* section
,
2817 unsigned char * data
,
2818 unsigned char * end
,
2819 DWARF2_Internal_LineInfo
* linfo
,
2820 unsigned char ** end_of_sequence
)
2822 unsigned char *hdrptr
;
2823 unsigned int initial_length_size
;
2824 unsigned char address_size
, segment_selector_size
;
2826 /* Extract information from the Line Number Program Header.
2827 (section 6.2.4 in the Dwarf3 doc). */
2830 /* Get and check the length of the block. */
2831 SAFE_BYTE_GET_AND_INC (linfo
->li_length
, hdrptr
, 4, end
);
2833 if (linfo
->li_length
== 0xffffffff)
2835 /* This section is 64-bit DWARF 3. */
2836 SAFE_BYTE_GET_AND_INC (linfo
->li_length
, hdrptr
, 8, end
);
2837 linfo
->li_offset_size
= 8;
2838 initial_length_size
= 12;
2842 linfo
->li_offset_size
= 4;
2843 initial_length_size
= 4;
2846 if (linfo
->li_length
+ initial_length_size
> section
->size
)
2848 /* If the length field has a relocation against it, then we should
2849 not complain if it is inaccurate (and probably negative). This
2850 happens in object files when the .debug_line section is actually
2851 comprised of several different .debug_line.* sections, (some of
2852 which may be removed by linker garbage collection), and a relocation
2853 is used to compute the correct length once that is done. */
2854 if (reloc_at (section
, (hdrptr
- section
->start
) - linfo
->li_offset_size
))
2856 linfo
->li_length
= (end
- data
) - initial_length_size
;
2860 warn (_("The length field (0x%lx) in the debug_line header is wrong - the section is too small\n"),
2861 (long) linfo
->li_length
);
2866 /* Get and check the version number. */
2867 SAFE_BYTE_GET_AND_INC (linfo
->li_version
, hdrptr
, 2, end
);
2869 if (linfo
->li_version
!= 2
2870 && linfo
->li_version
!= 3
2871 && linfo
->li_version
!= 4
2872 && linfo
->li_version
!= 5)
2874 warn (_("Only DWARF version 2, 3, 4 and 5 line info "
2875 "is currently supported.\n"));
2879 if (linfo
->li_version
>= 5)
2881 SAFE_BYTE_GET_AND_INC (address_size
, hdrptr
, 1, end
);
2883 SAFE_BYTE_GET_AND_INC (segment_selector_size
, hdrptr
, 1, end
);
2884 if (segment_selector_size
!= 0)
2886 warn (_("The %s section contains "
2887 "unsupported segment selector size: %d.\n"),
2888 section
->name
, segment_selector_size
);
2893 SAFE_BYTE_GET_AND_INC (linfo
->li_prologue_length
, hdrptr
,
2894 linfo
->li_offset_size
, end
);
2895 SAFE_BYTE_GET_AND_INC (linfo
->li_min_insn_length
, hdrptr
, 1, end
);
2897 if (linfo
->li_version
>= 4)
2899 SAFE_BYTE_GET_AND_INC (linfo
->li_max_ops_per_insn
, hdrptr
, 1, end
);
2901 if (linfo
->li_max_ops_per_insn
== 0)
2903 warn (_("Invalid maximum operations per insn.\n"));
2908 linfo
->li_max_ops_per_insn
= 1;
2910 SAFE_BYTE_GET_AND_INC (linfo
->li_default_is_stmt
, hdrptr
, 1, end
);
2911 SAFE_SIGNED_BYTE_GET_AND_INC (linfo
->li_line_base
, hdrptr
, 1, end
);
2912 SAFE_BYTE_GET_AND_INC (linfo
->li_line_range
, hdrptr
, 1, end
);
2913 SAFE_BYTE_GET_AND_INC (linfo
->li_opcode_base
, hdrptr
, 1, end
);
2915 * end_of_sequence
= data
+ linfo
->li_length
+ initial_length_size
;
2916 /* PR 17512: file:002-117414-0.004. */
2917 if (* end_of_sequence
> end
)
2919 warn (_("Line length %s extends beyond end of section\n"),
2920 dwarf_vmatoa ("u", linfo
->li_length
));
2921 * end_of_sequence
= end
;
2928 static unsigned char *
2929 display_formatted_table (unsigned char *data
,
2930 unsigned char *start
, unsigned char *end
,
2931 const DWARF2_Internal_LineInfo
*linfo
,
2932 struct dwarf_section
*section
, const char *what
)
2934 unsigned char *format_start
, format_count
, *format
, formati
;
2935 dwarf_vma data_count
, datai
;
2936 unsigned int bytes_read
, namepass
, last_entry
= 0;
2938 SAFE_BYTE_GET_AND_INC (format_count
, data
, 1, end
);
2939 format_start
= data
;
2940 for (formati
= 0; formati
< format_count
; formati
++)
2942 read_uleb128 (data
, & bytes_read
, end
);
2944 read_uleb128 (data
, & bytes_read
, end
);
2948 warn (_("Corrupt %s entry format table entry\n"), what
);
2953 data_count
= read_uleb128 (data
, & bytes_read
, end
);
2957 warn (_("Corrupt %s list\n"), what
);
2961 if (data_count
== 0)
2963 printf (_("\n The %s Table is empty.\n"), what
);
2967 printf (_("\n The %s Table (offset 0x%lx):\n"), what
,
2968 (long)(data
- start
));
2970 printf (_(" Entry"));
2971 /* Delay displaying name as the last entry for better screen layout. */
2972 for (namepass
= 0; namepass
< 2; namepass
++)
2974 format
= format_start
;
2975 for (formati
= 0; formati
< format_count
; formati
++)
2977 dwarf_vma content_type
;
2979 content_type
= read_uleb128 (format
, & bytes_read
, end
);
2980 format
+= bytes_read
;
2981 if ((content_type
== DW_LNCT_path
) == (namepass
== 1))
2982 switch (content_type
)
2985 printf (_("\tName"));
2987 case DW_LNCT_directory_index
:
2988 printf (_("\tDir"));
2990 case DW_LNCT_timestamp
:
2991 printf (_("\tTime"));
2994 printf (_("\tSize"));
2997 printf (_("\tMD5"));
3000 printf (_("\t(Unknown format content type %s)"),
3001 dwarf_vmatoa ("u", content_type
));
3003 read_uleb128 (format
, & bytes_read
, end
);
3004 format
+= bytes_read
;
3009 for (datai
= 0; datai
< data_count
; datai
++)
3011 unsigned char *datapass
= data
;
3013 printf (" %d", last_entry
++);
3014 /* Delay displaying name as the last entry for better screen layout. */
3015 for (namepass
= 0; namepass
< 2; namepass
++)
3017 format
= format_start
;
3019 for (formati
= 0; formati
< format_count
; formati
++)
3021 dwarf_vma content_type
, form
;
3023 content_type
= read_uleb128 (format
, & bytes_read
, end
);
3024 format
+= bytes_read
;
3025 form
= read_uleb128 (format
, & bytes_read
, end
);
3026 format
+= bytes_read
;
3027 data
= read_and_display_attr_value (0, form
, 0, data
, end
, 0, 0,
3028 linfo
->li_offset_size
,
3029 linfo
->li_version
, NULL
,
3030 ((content_type
== DW_LNCT_path
) != (namepass
== 1)),
3031 section
, NULL
, '\t');
3036 warn (_("Corrupt %s entries list\n"), what
);
3045 display_debug_lines_raw (struct dwarf_section
*section
,
3046 unsigned char *data
,
3047 unsigned char *end
, void *file
)
3049 unsigned char *start
= section
->start
;
3051 printf (_("Raw dump of debug contents of section %s:\n\n"),
3056 static DWARF2_Internal_LineInfo saved_linfo
;
3057 DWARF2_Internal_LineInfo linfo
;
3058 unsigned char *standard_opcodes
;
3059 unsigned char *end_of_sequence
;
3062 if (const_strneq (section
->name
, ".debug_line.")
3063 /* Note: the following does not apply to .debug_line.dwo sections.
3064 These are full debug_line sections. */
3065 && strcmp (section
->name
, ".debug_line.dwo") != 0)
3067 /* Sections named .debug_line.<foo> are fragments of a .debug_line
3068 section containing just the Line Number Statements. They are
3069 created by the assembler and intended to be used alongside gcc's
3070 -ffunction-sections command line option. When the linker's
3071 garbage collection decides to discard a .text.<foo> section it
3072 can then also discard the line number information in .debug_line.<foo>.
3074 Since the section is a fragment it does not have the details
3075 needed to fill out a LineInfo structure, so instead we use the
3076 details from the last full debug_line section that we processed. */
3077 end_of_sequence
= end
;
3078 standard_opcodes
= NULL
;
3079 linfo
= saved_linfo
;
3080 /* PR 17531: file: 0522b371. */
3081 if (linfo
.li_line_range
== 0)
3083 warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n"));
3086 reset_state_machine (linfo
.li_default_is_stmt
);
3090 unsigned char * hdrptr
;
3092 if ((hdrptr
= read_debug_line_header (section
, data
, end
, & linfo
,
3093 & end_of_sequence
)) == NULL
)
3096 printf (_(" Offset: 0x%lx\n"), (long)(data
- start
));
3097 printf (_(" Length: %ld\n"), (long) linfo
.li_length
);
3098 printf (_(" DWARF Version: %d\n"), linfo
.li_version
);
3099 printf (_(" Prologue Length: %d\n"), (int) linfo
.li_prologue_length
);
3100 printf (_(" Minimum Instruction Length: %d\n"), linfo
.li_min_insn_length
);
3101 if (linfo
.li_version
>= 4)
3102 printf (_(" Maximum Ops per Instruction: %d\n"), linfo
.li_max_ops_per_insn
);
3103 printf (_(" Initial value of 'is_stmt': %d\n"), linfo
.li_default_is_stmt
);
3104 printf (_(" Line Base: %d\n"), linfo
.li_line_base
);
3105 printf (_(" Line Range: %d\n"), linfo
.li_line_range
);
3106 printf (_(" Opcode Base: %d\n"), linfo
.li_opcode_base
);
3108 /* PR 17512: file: 1665-6428-0.004. */
3109 if (linfo
.li_line_range
== 0)
3111 warn (_("Line range of 0 is invalid, using 1 instead\n"));
3112 linfo
.li_line_range
= 1;
3115 reset_state_machine (linfo
.li_default_is_stmt
);
3117 /* Display the contents of the Opcodes table. */
3118 standard_opcodes
= hdrptr
;
3120 /* PR 17512: file: 002-417945-0.004. */
3121 if (standard_opcodes
+ linfo
.li_opcode_base
>= end
)
3123 warn (_("Line Base extends beyond end of section\n"));
3127 printf (_("\n Opcodes:\n"));
3129 for (i
= 1; i
< linfo
.li_opcode_base
; i
++)
3130 printf (_(" Opcode %d has %d args\n"), i
, standard_opcodes
[i
- 1]);
3132 /* Display the contents of the Directory table. */
3133 data
= standard_opcodes
+ linfo
.li_opcode_base
- 1;
3135 if (linfo
.li_version
>= 5)
3137 load_debug_section (line_str
, file
);
3139 data
= display_formatted_table (data
, start
, end
, &linfo
, section
,
3141 data
= display_formatted_table (data
, start
, end
, &linfo
, section
,
3147 printf (_("\n The Directory Table is empty.\n"));
3150 unsigned int last_dir_entry
= 0;
3152 printf (_("\n The Directory Table (offset 0x%lx):\n"),
3153 (long)(data
- start
));
3155 while (data
< end
&& *data
!= 0)
3157 printf (" %d\t%.*s\n", ++last_dir_entry
, (int) (end
- data
), data
);
3159 data
+= strnlen ((char *) data
, end
- data
) + 1;
3162 /* PR 17512: file: 002-132094-0.004. */
3163 if (data
>= end
- 1)
3167 /* Skip the NUL at the end of the table. */
3170 /* Display the contents of the File Name table. */
3172 printf (_("\n The File Name Table is empty.\n"));
3175 printf (_("\n The File Name Table (offset 0x%lx):\n"),
3176 (long)(data
- start
));
3177 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
3179 while (data
< end
&& *data
!= 0)
3181 unsigned char *name
;
3182 unsigned int bytes_read
;
3184 printf (" %d\t", ++state_machine_regs
.last_file_entry
);
3186 data
+= strnlen ((char *) data
, end
- data
) + 1;
3189 dwarf_vmatoa ("u", read_uleb128 (data
, & bytes_read
, end
)));
3192 dwarf_vmatoa ("u", read_uleb128 (data
, & bytes_read
, end
)));
3195 dwarf_vmatoa ("u", read_uleb128 (data
, & bytes_read
, end
)));
3197 printf ("%.*s\n", (int)(end
- name
), name
);
3201 warn (_("Corrupt file name table entry\n"));
3207 /* Skip the NUL at the end of the table. */
3212 saved_linfo
= linfo
;
3215 /* Now display the statements. */
3216 if (data
>= end_of_sequence
)
3217 printf (_(" No Line Number Statements.\n"));
3220 printf (_(" Line Number Statements:\n"));
3222 while (data
< end_of_sequence
)
3224 unsigned char op_code
;
3225 dwarf_signed_vma adv
;
3227 unsigned int bytes_read
;
3229 printf (" [0x%08lx]", (long)(data
- start
));
3233 if (op_code
>= linfo
.li_opcode_base
)
3235 op_code
-= linfo
.li_opcode_base
;
3236 uladv
= (op_code
/ linfo
.li_line_range
);
3237 if (linfo
.li_max_ops_per_insn
== 1)
3239 uladv
*= linfo
.li_min_insn_length
;
3240 state_machine_regs
.address
+= uladv
;
3241 printf (_(" Special opcode %d: "
3242 "advance Address by %s to 0x%s"),
3243 op_code
, dwarf_vmatoa ("u", uladv
),
3244 dwarf_vmatoa ("x", state_machine_regs
.address
));
3248 state_machine_regs
.address
3249 += ((state_machine_regs
.op_index
+ uladv
)
3250 / linfo
.li_max_ops_per_insn
)
3251 * linfo
.li_min_insn_length
;
3252 state_machine_regs
.op_index
3253 = (state_machine_regs
.op_index
+ uladv
)
3254 % linfo
.li_max_ops_per_insn
;
3255 printf (_(" Special opcode %d: "
3256 "advance Address by %s to 0x%s[%d]"),
3257 op_code
, dwarf_vmatoa ("u", uladv
),
3258 dwarf_vmatoa ("x", state_machine_regs
.address
),
3259 state_machine_regs
.op_index
);
3261 adv
= (op_code
% linfo
.li_line_range
) + linfo
.li_line_base
;
3262 state_machine_regs
.line
+= adv
;
3263 printf (_(" and Line by %s to %d\n"),
3264 dwarf_vmatoa ("d", adv
), state_machine_regs
.line
);
3266 else switch (op_code
)
3268 case DW_LNS_extended_op
:
3269 data
+= process_extended_line_op (data
, linfo
.li_default_is_stmt
, end
);
3273 printf (_(" Copy\n"));
3276 case DW_LNS_advance_pc
:
3277 uladv
= read_uleb128 (data
, & bytes_read
, end
);
3279 if (linfo
.li_max_ops_per_insn
== 1)
3281 uladv
*= linfo
.li_min_insn_length
;
3282 state_machine_regs
.address
+= uladv
;
3283 printf (_(" Advance PC by %s to 0x%s\n"),
3284 dwarf_vmatoa ("u", uladv
),
3285 dwarf_vmatoa ("x", state_machine_regs
.address
));
3289 state_machine_regs
.address
3290 += ((state_machine_regs
.op_index
+ uladv
)
3291 / linfo
.li_max_ops_per_insn
)
3292 * linfo
.li_min_insn_length
;
3293 state_machine_regs
.op_index
3294 = (state_machine_regs
.op_index
+ uladv
)
3295 % linfo
.li_max_ops_per_insn
;
3296 printf (_(" Advance PC by %s to 0x%s[%d]\n"),
3297 dwarf_vmatoa ("u", uladv
),
3298 dwarf_vmatoa ("x", state_machine_regs
.address
),
3299 state_machine_regs
.op_index
);
3303 case DW_LNS_advance_line
:
3304 adv
= read_sleb128 (data
, & bytes_read
, end
);
3306 state_machine_regs
.line
+= adv
;
3307 printf (_(" Advance Line by %s to %d\n"),
3308 dwarf_vmatoa ("d", adv
),
3309 state_machine_regs
.line
);
3312 case DW_LNS_set_file
:
3313 adv
= read_uleb128 (data
, & bytes_read
, end
);
3315 printf (_(" Set File Name to entry %s in the File Name Table\n"),
3316 dwarf_vmatoa ("d", adv
));
3317 state_machine_regs
.file
= adv
;
3320 case DW_LNS_set_column
:
3321 uladv
= read_uleb128 (data
, & bytes_read
, end
);
3323 printf (_(" Set column to %s\n"),
3324 dwarf_vmatoa ("u", uladv
));
3325 state_machine_regs
.column
= uladv
;
3328 case DW_LNS_negate_stmt
:
3329 adv
= state_machine_regs
.is_stmt
;
3331 printf (_(" Set is_stmt to %s\n"), dwarf_vmatoa ("d", adv
));
3332 state_machine_regs
.is_stmt
= adv
;
3335 case DW_LNS_set_basic_block
:
3336 printf (_(" Set basic block\n"));
3337 state_machine_regs
.basic_block
= 1;
3340 case DW_LNS_const_add_pc
:
3341 uladv
= ((255 - linfo
.li_opcode_base
) / linfo
.li_line_range
);
3342 if (linfo
.li_max_ops_per_insn
)
3344 uladv
*= linfo
.li_min_insn_length
;
3345 state_machine_regs
.address
+= uladv
;
3346 printf (_(" Advance PC by constant %s to 0x%s\n"),
3347 dwarf_vmatoa ("u", uladv
),
3348 dwarf_vmatoa ("x", state_machine_regs
.address
));
3352 state_machine_regs
.address
3353 += ((state_machine_regs
.op_index
+ uladv
)
3354 / linfo
.li_max_ops_per_insn
)
3355 * linfo
.li_min_insn_length
;
3356 state_machine_regs
.op_index
3357 = (state_machine_regs
.op_index
+ uladv
)
3358 % linfo
.li_max_ops_per_insn
;
3359 printf (_(" Advance PC by constant %s to 0x%s[%d]\n"),
3360 dwarf_vmatoa ("u", uladv
),
3361 dwarf_vmatoa ("x", state_machine_regs
.address
),
3362 state_machine_regs
.op_index
);
3366 case DW_LNS_fixed_advance_pc
:
3367 SAFE_BYTE_GET_AND_INC (uladv
, data
, 2, end
);
3368 state_machine_regs
.address
+= uladv
;
3369 state_machine_regs
.op_index
= 0;
3370 printf (_(" Advance PC by fixed size amount %s to 0x%s\n"),
3371 dwarf_vmatoa ("u", uladv
),
3372 dwarf_vmatoa ("x", state_machine_regs
.address
));
3375 case DW_LNS_set_prologue_end
:
3376 printf (_(" Set prologue_end to true\n"));
3379 case DW_LNS_set_epilogue_begin
:
3380 printf (_(" Set epilogue_begin to true\n"));
3383 case DW_LNS_set_isa
:
3384 uladv
= read_uleb128 (data
, & bytes_read
, end
);
3386 printf (_(" Set ISA to %s\n"), dwarf_vmatoa ("u", uladv
));
3390 printf (_(" Unknown opcode %d with operands: "), op_code
);
3392 if (standard_opcodes
!= NULL
)
3393 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
3395 printf ("0x%s%s", dwarf_vmatoa ("x", read_uleb128 (data
,
3397 i
== 1 ? "" : ", ");
3413 unsigned char *name
;
3414 unsigned int directory_index
;
3415 unsigned int modification_date
;
3416 unsigned int length
;
3419 /* Output a decoded representation of the .debug_line section. */
3422 display_debug_lines_decoded (struct dwarf_section
*section
,
3423 unsigned char *data
,
3424 unsigned char *end
, void *fileptr
)
3426 static DWARF2_Internal_LineInfo saved_linfo
;
3428 printf (_("Decoded dump of debug contents of section %s:\n\n"),
3433 /* This loop amounts to one iteration per compilation unit. */
3434 DWARF2_Internal_LineInfo linfo
;
3435 unsigned char *standard_opcodes
;
3436 unsigned char *end_of_sequence
;
3438 File_Entry
*file_table
= NULL
;
3439 unsigned int n_files
= 0;
3440 unsigned char **directory_table
= NULL
;
3441 dwarf_vma n_directories
= 0;
3443 if (const_strneq (section
->name
, ".debug_line.")
3444 /* Note: the following does not apply to .debug_line.dwo sections.
3445 These are full debug_line sections. */
3446 && strcmp (section
->name
, ".debug_line.dwo") != 0)
3448 /* See comment in display_debug_lines_raw(). */
3449 end_of_sequence
= end
;
3450 standard_opcodes
= NULL
;
3451 linfo
= saved_linfo
;
3452 /* PR 17531: file: 0522b371. */
3453 if (linfo
.li_line_range
== 0)
3455 warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n"));
3458 reset_state_machine (linfo
.li_default_is_stmt
);
3462 unsigned char *hdrptr
;
3464 if ((hdrptr
= read_debug_line_header (section
, data
, end
, & linfo
,
3465 & end_of_sequence
)) == NULL
)
3468 /* PR 17531: file: 0522b371. */
3469 if (linfo
.li_line_range
== 0)
3471 warn (_("Line range of 0 is invalid, using 1 instead\n"));
3472 linfo
.li_line_range
= 1;
3474 reset_state_machine (linfo
.li_default_is_stmt
);
3476 /* Save a pointer to the contents of the Opcodes table. */
3477 standard_opcodes
= hdrptr
;
3479 /* Traverse the Directory table just to count entries. */
3480 data
= standard_opcodes
+ linfo
.li_opcode_base
- 1;
3484 warn (_("opcode base of %d extends beyond end of section\n"),
3485 linfo
.li_opcode_base
);
3489 if (linfo
.li_version
>= 5)
3491 unsigned char *format_start
, format_count
, *format
;
3492 dwarf_vma formati
, entryi
;
3493 unsigned int bytes_read
;
3495 load_debug_section (line_str
, fileptr
);
3497 /* Skip directories format. */
3498 SAFE_BYTE_GET_AND_INC (format_count
, data
, 1, end
);
3499 format_start
= data
;
3500 for (formati
= 0; formati
< format_count
; formati
++)
3502 read_uleb128 (data
, & bytes_read
, end
);
3504 read_uleb128 (data
, & bytes_read
, end
);
3508 n_directories
= read_uleb128 (data
, & bytes_read
, end
);
3512 warn (_("Corrupt directories list\n"));
3516 directory_table
= (unsigned char **)
3517 xmalloc (n_directories
* sizeof (unsigned char *));
3519 for (entryi
= 0; entryi
< n_directories
; entryi
++)
3521 unsigned char **pathp
= &directory_table
[entryi
];
3523 format
= format_start
;
3524 for (formati
= 0; formati
< format_count
; formati
++)
3526 dwarf_vma content_type
, form
;
3529 content_type
= read_uleb128 (format
, & bytes_read
, end
);
3530 format
+= bytes_read
;
3531 form
= read_uleb128 (format
, & bytes_read
, end
);
3532 format
+= bytes_read
;
3535 warn (_("Corrupt directories list\n"));
3538 switch (content_type
)
3543 case DW_FORM_string
:
3546 case DW_FORM_line_strp
:
3547 SAFE_BYTE_GET (uvalue
, data
, linfo
.li_offset_size
,
3549 /* Remove const by the cast. */
3550 *pathp
= (unsigned char *)
3551 fetch_indirect_line_string (uvalue
);
3556 data
= read_and_display_attr_value (0, form
, 0, data
, end
,
3558 linfo
.li_offset_size
,
3565 warn (_("Corrupt directories list\n"));
3570 /* Skip files format. */
3571 SAFE_BYTE_GET_AND_INC (format_count
, data
, 1, end
);
3572 format_start
= data
;
3573 for (formati
= 0; formati
< format_count
; formati
++)
3575 read_uleb128 (data
, & bytes_read
, end
);
3577 read_uleb128 (data
, & bytes_read
, end
);
3581 n_files
= read_uleb128 (data
, & bytes_read
, end
);
3585 warn (_("Corrupt file name list\n"));
3589 file_table
= (File_Entry
*) xcalloc (1, n_files
3590 * sizeof (File_Entry
));
3592 for (entryi
= 0; entryi
< n_files
; entryi
++)
3594 File_Entry
*file
= &file_table
[entryi
];
3596 format
= format_start
;
3597 for (formati
= 0; formati
< format_count
; formati
++)
3599 dwarf_vma content_type
, form
;
3602 content_type
= read_uleb128 (format
, & bytes_read
, end
);
3603 format
+= bytes_read
;
3604 form
= read_uleb128 (format
, & bytes_read
, end
);
3605 format
+= bytes_read
;
3608 warn (_("Corrupt file name list\n"));
3611 switch (content_type
)
3616 case DW_FORM_string
:
3619 case DW_FORM_line_strp
:
3620 SAFE_BYTE_GET (uvalue
, data
, linfo
.li_offset_size
,
3622 /* Remove const by the cast. */
3623 file
->name
= (unsigned char *)
3624 fetch_indirect_line_string (uvalue
);
3628 case DW_LNCT_directory_index
:
3632 SAFE_BYTE_GET (file
->directory_index
, data
, 1,
3636 SAFE_BYTE_GET (file
->directory_index
, data
, 2,
3640 file
->directory_index
= read_uleb128 (data
, NULL
,
3646 data
= read_and_display_attr_value (0, form
, 0, data
, end
,
3648 linfo
.li_offset_size
,
3655 warn (_("Corrupt file name list\n"));
3664 unsigned char *ptr_directory_table
= data
;
3666 while (data
< end
&& *data
!= 0)
3668 data
+= strnlen ((char *) data
, end
- data
) + 1;
3675 warn (_("directory table ends unexpectedly\n"));
3680 /* Go through the directory table again to save the directories. */
3681 directory_table
= (unsigned char **)
3682 xmalloc (n_directories
* sizeof (unsigned char *));
3685 while (*ptr_directory_table
!= 0)
3687 directory_table
[i
] = ptr_directory_table
;
3688 ptr_directory_table
+= strnlen ((char *) ptr_directory_table
,
3689 ptr_directory_table
- end
) + 1;
3693 /* Skip the NUL at the end of the table. */
3696 /* Traverse the File Name table just to count the entries. */
3697 if (data
< end
&& *data
!= 0)
3699 unsigned char *ptr_file_name_table
= data
;
3701 while (data
< end
&& *data
!= 0)
3703 unsigned int bytes_read
;
3705 /* Skip Name, directory index, last modification time and length
3707 data
+= strnlen ((char *) data
, end
- data
) + 1;
3708 read_uleb128 (data
, & bytes_read
, end
);
3710 read_uleb128 (data
, & bytes_read
, end
);
3712 read_uleb128 (data
, & bytes_read
, end
);
3720 warn (_("file table ends unexpectedly\n"));
3725 /* Go through the file table again to save the strings. */
3726 file_table
= (File_Entry
*) xmalloc (n_files
* sizeof (File_Entry
));
3729 while (*ptr_file_name_table
!= 0)
3731 unsigned int bytes_read
;
3733 file_table
[i
].name
= ptr_file_name_table
;
3734 ptr_file_name_table
+= strnlen ((char *) ptr_file_name_table
,
3735 end
- ptr_file_name_table
) + 1;
3737 /* We are not interested in directory, time or size. */
3738 file_table
[i
].directory_index
= read_uleb128 (ptr_file_name_table
,
3740 ptr_file_name_table
+= bytes_read
;
3741 file_table
[i
].modification_date
= read_uleb128 (ptr_file_name_table
,
3743 ptr_file_name_table
+= bytes_read
;
3744 file_table
[i
].length
= read_uleb128 (ptr_file_name_table
, & bytes_read
, end
);
3745 ptr_file_name_table
+= bytes_read
;
3751 /* Skip the NUL at the end of the table. */
3755 /* Print the Compilation Unit's name and a header. */
3756 if (directory_table
== NULL
)
3758 printf (_("CU: %s:\n"), file_table
[0].name
);
3759 printf (_("File name Line number Starting address\n"));
3763 unsigned int ix
= file_table
[0].directory_index
;
3764 const char *directory
;
3769 else if (n_directories
== 0)
3770 directory
= _("<unknown>");
3771 else if (ix
> n_directories
)
3773 warn (_("directory index %u > number of directories %s\n"),
3774 ix
, dwarf_vmatoa ("u", n_directories
));
3775 directory
= _("<corrupt>");
3778 directory
= (char *) directory_table
[ix
- 1];
3780 if (do_wide
|| strlen (directory
) < 76)
3781 printf (_("CU: %s/%s:\n"), directory
, file_table
[0].name
);
3783 printf ("%s:\n", file_table
[0].name
);
3785 printf (_("File name Line number Starting address\n"));
3788 saved_linfo
= linfo
;
3791 /* This loop iterates through the Dwarf Line Number Program. */
3792 while (data
< end_of_sequence
)
3794 unsigned char op_code
;
3796 unsigned long int uladv
;
3797 unsigned int bytes_read
;
3798 int is_special_opcode
= 0;
3802 if (op_code
>= linfo
.li_opcode_base
)
3804 op_code
-= linfo
.li_opcode_base
;
3805 uladv
= (op_code
/ linfo
.li_line_range
);
3806 if (linfo
.li_max_ops_per_insn
== 1)
3808 uladv
*= linfo
.li_min_insn_length
;
3809 state_machine_regs
.address
+= uladv
;
3813 state_machine_regs
.address
3814 += ((state_machine_regs
.op_index
+ uladv
)
3815 / linfo
.li_max_ops_per_insn
)
3816 * linfo
.li_min_insn_length
;
3817 state_machine_regs
.op_index
3818 = (state_machine_regs
.op_index
+ uladv
)
3819 % linfo
.li_max_ops_per_insn
;
3822 adv
= (op_code
% linfo
.li_line_range
) + linfo
.li_line_base
;
3823 state_machine_regs
.line
+= adv
;
3824 is_special_opcode
= 1;
3826 else switch (op_code
)
3828 case DW_LNS_extended_op
:
3830 unsigned int ext_op_code_len
;
3831 unsigned char ext_op_code
;
3832 unsigned char *op_code_data
= data
;
3834 ext_op_code_len
= read_uleb128 (op_code_data
, &bytes_read
,
3836 op_code_data
+= bytes_read
;
3838 if (ext_op_code_len
== 0)
3840 warn (_("Badly formed extended line op encountered!\n"));
3843 ext_op_code_len
+= bytes_read
;
3844 ext_op_code
= *op_code_data
++;
3846 switch (ext_op_code
)
3848 case DW_LNE_end_sequence
:
3849 reset_state_machine (linfo
.li_default_is_stmt
);
3851 case DW_LNE_set_address
:
3852 SAFE_BYTE_GET_AND_INC (state_machine_regs
.address
,
3854 ext_op_code_len
- bytes_read
- 1,
3856 state_machine_regs
.op_index
= 0;
3858 case DW_LNE_define_file
:
3860 file_table
= (File_Entry
*) xrealloc
3861 (file_table
, (n_files
+ 1) * sizeof (File_Entry
));
3863 ++state_machine_regs
.last_file_entry
;
3864 /* Source file name. */
3865 file_table
[n_files
].name
= op_code_data
;
3866 op_code_data
+= strlen ((char *) op_code_data
) + 1;
3867 /* Directory index. */
3868 file_table
[n_files
].directory_index
=
3869 read_uleb128 (op_code_data
, & bytes_read
,
3871 op_code_data
+= bytes_read
;
3872 /* Last modification time. */
3873 file_table
[n_files
].modification_date
=
3874 read_uleb128 (op_code_data
, & bytes_read
,
3876 op_code_data
+= bytes_read
;
3878 file_table
[n_files
].length
=
3879 read_uleb128 (op_code_data
, & bytes_read
,
3885 case DW_LNE_set_discriminator
:
3886 case DW_LNE_HP_set_sequence
:
3887 /* Simply ignored. */
3891 printf (_("UNKNOWN (%u): length %d\n"),
3892 ext_op_code
, ext_op_code_len
- bytes_read
);
3895 data
+= ext_op_code_len
;
3901 case DW_LNS_advance_pc
:
3902 uladv
= read_uleb128 (data
, & bytes_read
, end
);
3904 if (linfo
.li_max_ops_per_insn
== 1)
3906 uladv
*= linfo
.li_min_insn_length
;
3907 state_machine_regs
.address
+= uladv
;
3911 state_machine_regs
.address
3912 += ((state_machine_regs
.op_index
+ uladv
)
3913 / linfo
.li_max_ops_per_insn
)
3914 * linfo
.li_min_insn_length
;
3915 state_machine_regs
.op_index
3916 = (state_machine_regs
.op_index
+ uladv
)
3917 % linfo
.li_max_ops_per_insn
;
3921 case DW_LNS_advance_line
:
3922 adv
= read_sleb128 (data
, & bytes_read
, end
);
3924 state_machine_regs
.line
+= adv
;
3927 case DW_LNS_set_file
:
3928 adv
= read_uleb128 (data
, & bytes_read
, end
);
3930 state_machine_regs
.file
= adv
;
3933 unsigned file
= state_machine_regs
.file
- 1;
3936 if (file_table
== NULL
|| n_files
== 0)
3937 printf (_("\n [Use file table entry %d]\n"), file
);
3939 else if (file
>= n_files
)
3941 warn (_("file index %u > number of files %u\n"), file
+ 1, n_files
);
3942 printf (_("\n <over large file table index %u>"), file
);
3944 else if ((dir
= file_table
[file
].directory_index
) == 0)
3945 /* If directory index is 0, that means current directory. */
3946 printf ("\n./%s:[++]\n", file_table
[file
].name
);
3947 else if (directory_table
== NULL
|| n_directories
== 0)
3948 printf (_("\n [Use file %s in directory table entry %d]\n"),
3949 file_table
[file
].name
, dir
);
3951 else if (dir
> n_directories
)
3953 warn (_("directory index %u > number of directories %s\n"),
3954 dir
, dwarf_vmatoa ("u", n_directories
));
3955 printf (_("\n <over large directory table entry %u>\n"), dir
);
3958 printf ("\n%s/%s:\n",
3959 /* The directory index starts counting at 1. */
3960 directory_table
[dir
- 1], file_table
[file
].name
);
3964 case DW_LNS_set_column
:
3965 uladv
= read_uleb128 (data
, & bytes_read
, end
);
3967 state_machine_regs
.column
= uladv
;
3970 case DW_LNS_negate_stmt
:
3971 adv
= state_machine_regs
.is_stmt
;
3973 state_machine_regs
.is_stmt
= adv
;
3976 case DW_LNS_set_basic_block
:
3977 state_machine_regs
.basic_block
= 1;
3980 case DW_LNS_const_add_pc
:
3981 uladv
= ((255 - linfo
.li_opcode_base
) / linfo
.li_line_range
);
3982 if (linfo
.li_max_ops_per_insn
== 1)
3984 uladv
*= linfo
.li_min_insn_length
;
3985 state_machine_regs
.address
+= uladv
;
3989 state_machine_regs
.address
3990 += ((state_machine_regs
.op_index
+ uladv
)
3991 / linfo
.li_max_ops_per_insn
)
3992 * linfo
.li_min_insn_length
;
3993 state_machine_regs
.op_index
3994 = (state_machine_regs
.op_index
+ uladv
)
3995 % linfo
.li_max_ops_per_insn
;
3999 case DW_LNS_fixed_advance_pc
:
4000 SAFE_BYTE_GET_AND_INC (uladv
, data
, 2, end
);
4001 state_machine_regs
.address
+= uladv
;
4002 state_machine_regs
.op_index
= 0;
4005 case DW_LNS_set_prologue_end
:
4008 case DW_LNS_set_epilogue_begin
:
4011 case DW_LNS_set_isa
:
4012 uladv
= read_uleb128 (data
, & bytes_read
, end
);
4014 printf (_(" Set ISA to %lu\n"), uladv
);
4018 printf (_(" Unknown opcode %d with operands: "), op_code
);
4020 if (standard_opcodes
!= NULL
)
4021 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
4023 printf ("0x%s%s", dwarf_vmatoa ("x", read_uleb128 (data
,
4025 i
== 1 ? "" : ", ");
4032 /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row
4033 to the DWARF address/line matrix. */
4034 if ((is_special_opcode
) || (op_code
== DW_LNE_end_sequence
)
4035 || (op_code
== DW_LNS_copy
))
4037 const unsigned int MAX_FILENAME_LENGTH
= 35;
4039 char *newFileName
= NULL
;
4040 size_t fileNameLength
;
4044 unsigned indx
= state_machine_regs
.file
- 1;
4046 if (indx
>= n_files
)
4048 warn (_("corrupt file index %u encountered\n"), indx
);
4049 fileName
= _("<corrupt>");
4052 fileName
= (char *) file_table
[indx
].name
;
4055 fileName
= _("<unknown>");
4057 fileNameLength
= strlen (fileName
);
4059 if ((fileNameLength
> MAX_FILENAME_LENGTH
) && (!do_wide
))
4061 newFileName
= (char *) xmalloc (MAX_FILENAME_LENGTH
+ 1);
4062 /* Truncate file name */
4063 strncpy (newFileName
,
4064 fileName
+ fileNameLength
- MAX_FILENAME_LENGTH
,
4065 MAX_FILENAME_LENGTH
+ 1);
4069 newFileName
= (char *) xmalloc (fileNameLength
+ 1);
4070 strncpy (newFileName
, fileName
, fileNameLength
+ 1);
4073 if (!do_wide
|| (fileNameLength
<= MAX_FILENAME_LENGTH
))
4075 if (linfo
.li_max_ops_per_insn
== 1)
4076 printf ("%-35s %11d %#18" DWARF_VMA_FMT
"x\n",
4077 newFileName
, state_machine_regs
.line
,
4078 state_machine_regs
.address
);
4080 printf ("%-35s %11d %#18" DWARF_VMA_FMT
"x[%d]\n",
4081 newFileName
, state_machine_regs
.line
,
4082 state_machine_regs
.address
,
4083 state_machine_regs
.op_index
);
4087 if (linfo
.li_max_ops_per_insn
== 1)
4088 printf ("%s %11d %#18" DWARF_VMA_FMT
"x\n",
4089 newFileName
, state_machine_regs
.line
,
4090 state_machine_regs
.address
);
4092 printf ("%s %11d %#18" DWARF_VMA_FMT
"x[%d]\n",
4093 newFileName
, state_machine_regs
.line
,
4094 state_machine_regs
.address
,
4095 state_machine_regs
.op_index
);
4098 if (op_code
== DW_LNE_end_sequence
)
4112 if (directory_table
)
4114 free (directory_table
);
4115 directory_table
= NULL
;
4126 display_debug_lines (struct dwarf_section
*section
, void *file
)
4128 unsigned char *data
= section
->start
;
4129 unsigned char *end
= data
+ section
->size
;
4131 int retValDecoded
= 1;
4133 if (do_debug_lines
== 0)
4134 do_debug_lines
|= FLAG_DEBUG_LINES_RAW
;
4136 if (do_debug_lines
& FLAG_DEBUG_LINES_RAW
)
4137 retValRaw
= display_debug_lines_raw (section
, data
, end
, file
);
4139 if (do_debug_lines
& FLAG_DEBUG_LINES_DECODED
)
4140 retValDecoded
= display_debug_lines_decoded (section
, data
, end
, file
);
4142 if (!retValRaw
|| !retValDecoded
)
4149 find_debug_info_for_offset (unsigned long offset
)
4153 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
4156 for (i
= 0; i
< num_debug_info_entries
; i
++)
4157 if (debug_information
[i
].cu_offset
== offset
)
4158 return debug_information
+ i
;
4164 get_gdb_index_symbol_kind_name (gdb_index_symbol_kind kind
)
4166 /* See gdb/gdb-index.h. */
4167 static const char * const kinds
[] =
4179 return _ (kinds
[kind
]);
4183 display_debug_pubnames_worker (struct dwarf_section
*section
,
4184 void *file ATTRIBUTE_UNUSED
,
4187 DWARF2_Internal_PubNames names
;
4188 unsigned char *start
= section
->start
;
4189 unsigned char *end
= start
+ section
->size
;
4191 /* It does not matter if this load fails,
4192 we test for that later on. */
4193 load_debug_info (file
);
4195 printf (_("Contents of the %s section:\n\n"), section
->name
);
4199 unsigned char *data
;
4202 unsigned int offset_size
, initial_length_size
;
4206 SAFE_BYTE_GET_AND_INC (names
.pn_length
, data
, 4, end
);
4207 if (names
.pn_length
== 0xffffffff)
4209 SAFE_BYTE_GET_AND_INC (names
.pn_length
, data
, 8, end
);
4211 initial_length_size
= 12;
4216 initial_length_size
= 4;
4219 SAFE_BYTE_GET_AND_INC (names
.pn_version
, data
, 2, end
);
4220 SAFE_BYTE_GET_AND_INC (names
.pn_offset
, data
, offset_size
, end
);
4222 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
4223 && num_debug_info_entries
> 0
4224 && find_debug_info_for_offset (names
.pn_offset
) == NULL
)
4225 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
4226 (unsigned long) names
.pn_offset
, section
->name
);
4228 SAFE_BYTE_GET_AND_INC (names
.pn_size
, data
, offset_size
, end
);
4230 adr
= start
+ names
.pn_length
+ initial_length_size
;
4231 /* PR 17531: file: 7615b6b2. */
4232 if ((dwarf_signed_vma
) names
.pn_length
< 0
4233 /* PR 17531: file: a5dbeaa7. */
4236 warn (_("Negative length for public name: 0x%lx\n"), (long) names
.pn_length
);
4242 printf (_(" Length: %ld\n"),
4243 (long) names
.pn_length
);
4244 printf (_(" Version: %d\n"),
4246 printf (_(" Offset into .debug_info section: 0x%lx\n"),
4247 (unsigned long) names
.pn_offset
);
4248 printf (_(" Size of area in .debug_info section: %ld\n"),
4249 (long) names
.pn_size
);
4251 if (names
.pn_version
!= 2 && names
.pn_version
!= 3)
4253 static int warned
= 0;
4257 warn (_("Only DWARF 2 and 3 pubnames are currently supported\n"));
4265 printf (_("\n Offset Kind Name\n"));
4267 printf (_("\n Offset\tName\n"));
4271 bfd_size_type maxprint
;
4273 SAFE_BYTE_GET (offset
, data
, offset_size
, end
);
4277 data
+= offset_size
;
4280 maxprint
= (end
- data
) - 1;
4284 unsigned int kind_data
;
4285 gdb_index_symbol_kind kind
;
4286 const char *kind_name
;
4289 SAFE_BYTE_GET (kind_data
, data
, 1, end
);
4292 /* GCC computes the kind as the upper byte in the CU index
4293 word, and then right shifts it by the CU index size.
4294 Left shift KIND to where the gdb-index.h accessor macros
4296 kind_data
<<= GDB_INDEX_CU_BITSIZE
;
4297 kind
= GDB_INDEX_SYMBOL_KIND_VALUE (kind_data
);
4298 kind_name
= get_gdb_index_symbol_kind_name (kind
);
4299 is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (kind_data
);
4300 printf (" %-6lx %s,%-10s %.*s\n",
4301 (unsigned long) offset
, is_static
? _("s") : _("g"),
4302 kind_name
, (int) maxprint
, data
);
4305 printf (" %-6lx\t%.*s\n",
4306 (unsigned long) offset
, (int) maxprint
, data
);
4308 data
+= strnlen ((char *) data
, maxprint
) + 1;
4313 while (offset
!= 0);
4321 display_debug_pubnames (struct dwarf_section
*section
, void *file
)
4323 return display_debug_pubnames_worker (section
, file
, 0);
4327 display_debug_gnu_pubnames (struct dwarf_section
*section
, void *file
)
4329 return display_debug_pubnames_worker (section
, file
, 1);
4333 display_debug_macinfo (struct dwarf_section
*section
,
4334 void *file ATTRIBUTE_UNUSED
)
4336 unsigned char *start
= section
->start
;
4337 unsigned char *end
= start
+ section
->size
;
4338 unsigned char *curr
= start
;
4339 unsigned int bytes_read
;
4340 enum dwarf_macinfo_record_type op
;
4342 printf (_("Contents of the %s section:\n\n"), section
->name
);
4346 unsigned int lineno
;
4347 const unsigned char *string
;
4349 op
= (enum dwarf_macinfo_record_type
) *curr
;
4354 case DW_MACINFO_start_file
:
4356 unsigned int filenum
;
4358 lineno
= read_uleb128 (curr
, & bytes_read
, end
);
4360 filenum
= read_uleb128 (curr
, & bytes_read
, end
);
4363 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"),
4368 case DW_MACINFO_end_file
:
4369 printf (_(" DW_MACINFO_end_file\n"));
4372 case DW_MACINFO_define
:
4373 lineno
= read_uleb128 (curr
, & bytes_read
, end
);
4376 curr
+= strnlen ((char *) string
, end
- string
) + 1;
4377 printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"),
4381 case DW_MACINFO_undef
:
4382 lineno
= read_uleb128 (curr
, & bytes_read
, end
);
4385 curr
+= strnlen ((char *) string
, end
- string
) + 1;
4386 printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"),
4390 case DW_MACINFO_vendor_ext
:
4392 unsigned int constant
;
4394 constant
= read_uleb128 (curr
, & bytes_read
, end
);
4397 curr
+= strnlen ((char *) string
, end
- string
) + 1;
4398 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"),
4408 /* Given LINE_OFFSET into the .debug_line section, attempt to return
4409 filename and dirname corresponding to file name table entry with index
4410 FILEIDX. Return NULL on failure. */
4412 static unsigned char *
4413 get_line_filename_and_dirname (dwarf_vma line_offset
,
4415 unsigned char **dir_name
)
4417 struct dwarf_section
*section
= &debug_displays
[line
].section
;
4418 unsigned char *hdrptr
, *dirtable
, *file_name
;
4419 unsigned int offset_size
, initial_length_size
;
4420 unsigned int version
, opcode_base
, bytes_read
;
4421 dwarf_vma length
, diridx
;
4422 const unsigned char * end
;
4425 if (section
->start
== NULL
4426 || line_offset
>= section
->size
4430 hdrptr
= section
->start
+ line_offset
;
4431 end
= section
->start
+ section
->size
;
4433 SAFE_BYTE_GET_AND_INC (length
, hdrptr
, 4, end
);
4434 if (length
== 0xffffffff)
4436 /* This section is 64-bit DWARF 3. */
4437 SAFE_BYTE_GET_AND_INC (length
, hdrptr
, 8, end
);
4439 initial_length_size
= 12;
4444 initial_length_size
= 4;
4446 if (length
+ initial_length_size
> section
->size
)
4449 SAFE_BYTE_GET_AND_INC (version
, hdrptr
, 2, end
);
4450 if (version
!= 2 && version
!= 3 && version
!= 4)
4452 hdrptr
+= offset_size
+ 1;/* Skip prologue_length and min_insn_length. */
4454 hdrptr
++; /* Skip max_ops_per_insn. */
4455 hdrptr
+= 3; /* Skip default_is_stmt, line_base, line_range. */
4457 SAFE_BYTE_GET_AND_INC (opcode_base
, hdrptr
, 1, end
);
4458 if (opcode_base
== 0)
4461 hdrptr
+= opcode_base
- 1;
4463 /* Skip over dirname table. */
4464 while (*hdrptr
!= '\0')
4465 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
) + 1;
4466 hdrptr
++; /* Skip the NUL at the end of the table. */
4467 /* Now skip over preceding filename table entries. */
4468 for (; *hdrptr
!= '\0' && fileidx
> 1; fileidx
--)
4470 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
) + 1;
4471 read_uleb128 (hdrptr
, &bytes_read
, end
);
4472 hdrptr
+= bytes_read
;
4473 read_uleb128 (hdrptr
, &bytes_read
, end
);
4474 hdrptr
+= bytes_read
;
4475 read_uleb128 (hdrptr
, &bytes_read
, end
);
4476 hdrptr
+= bytes_read
;
4478 if (hdrptr
== end
|| *hdrptr
== '\0')
4481 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
) + 1;
4482 diridx
= read_uleb128 (hdrptr
, &bytes_read
, end
);
4485 for (; *dirtable
!= '\0' && diridx
> 1; diridx
--)
4486 dirtable
+= strnlen ((char *) dirtable
, end
- dirtable
) + 1;
4487 if (*dirtable
== '\0')
4489 *dir_name
= dirtable
;
4494 display_debug_macro (struct dwarf_section
*section
,
4497 unsigned char *start
= section
->start
;
4498 unsigned char *end
= start
+ section
->size
;
4499 unsigned char *curr
= start
;
4500 unsigned char *extended_op_buf
[256];
4501 unsigned int bytes_read
;
4503 load_debug_section (str
, file
);
4504 load_debug_section (line
, file
);
4506 printf (_("Contents of the %s section:\n\n"), section
->name
);
4510 unsigned int lineno
, version
, flags
;
4511 unsigned int offset_size
= 4;
4512 const unsigned char *string
;
4513 dwarf_vma line_offset
= 0, sec_offset
= curr
- start
, offset
;
4514 unsigned char **extended_ops
= NULL
;
4516 SAFE_BYTE_GET_AND_INC (version
, curr
, 2, end
);
4519 error (_("Only GNU extension to DWARF 4 of %s is currently supported.\n"),
4524 SAFE_BYTE_GET_AND_INC (flags
, curr
, 1, end
);
4527 printf (_(" Offset: 0x%lx\n"),
4528 (unsigned long) sec_offset
);
4529 printf (_(" Version: %d\n"), version
);
4530 printf (_(" Offset size: %d\n"), offset_size
);
4533 SAFE_BYTE_GET_AND_INC (line_offset
, curr
, offset_size
, end
);
4534 printf (_(" Offset into .debug_line: 0x%lx\n"),
4535 (unsigned long) line_offset
);
4539 unsigned int i
, count
, op
;
4542 SAFE_BYTE_GET_AND_INC (count
, curr
, 1, end
);
4544 memset (extended_op_buf
, 0, sizeof (extended_op_buf
));
4545 extended_ops
= extended_op_buf
;
4548 printf (_(" Extension opcode arguments:\n"));
4549 for (i
= 0; i
< count
; i
++)
4551 SAFE_BYTE_GET_AND_INC (op
, curr
, 1, end
);
4552 extended_ops
[op
] = curr
;
4553 nargs
= read_uleb128 (curr
, &bytes_read
, end
);
4556 printf (_(" DW_MACRO_GNU_%02x has no arguments\n"), op
);
4559 printf (_(" DW_MACRO_GNU_%02x arguments: "), op
);
4560 for (n
= 0; n
< nargs
; n
++)
4564 SAFE_BYTE_GET_AND_INC (form
, curr
, 1, end
);
4565 printf ("%s%s", get_FORM_name (form
),
4566 n
== nargs
- 1 ? "\n" : ", ");
4576 case DW_FORM_block1
:
4577 case DW_FORM_block2
:
4578 case DW_FORM_block4
:
4580 case DW_FORM_string
:
4582 case DW_FORM_sec_offset
:
4585 error (_("Invalid extension opcode form %s\n"),
4586 get_FORM_name (form
));
4602 error (_(".debug_macro section not zero terminated\n"));
4606 SAFE_BYTE_GET_AND_INC (op
, curr
, 1, end
);
4612 case DW_MACRO_GNU_start_file
:
4614 unsigned int filenum
;
4615 unsigned char *file_name
= NULL
, *dir_name
= NULL
;
4617 lineno
= read_uleb128 (curr
, &bytes_read
, end
);
4619 filenum
= read_uleb128 (curr
, &bytes_read
, end
);
4622 if ((flags
& 2) == 0)
4623 error (_("DW_MACRO_GNU_start_file used, but no .debug_line offset provided.\n"));
4626 = get_line_filename_and_dirname (line_offset
, filenum
,
4628 if (file_name
== NULL
)
4629 printf (_(" DW_MACRO_GNU_start_file - lineno: %d filenum: %d\n"),
4632 printf (_(" DW_MACRO_GNU_start_file - lineno: %d filenum: %d filename: %s%s%s\n"),
4634 dir_name
!= NULL
? (const char *) dir_name
: "",
4635 dir_name
!= NULL
? "/" : "", file_name
);
4639 case DW_MACRO_GNU_end_file
:
4640 printf (_(" DW_MACRO_GNU_end_file\n"));
4643 case DW_MACRO_GNU_define
:
4644 lineno
= read_uleb128 (curr
, &bytes_read
, end
);
4647 curr
+= strnlen ((char *) string
, end
- string
) + 1;
4648 printf (_(" DW_MACRO_GNU_define - lineno : %d macro : %s\n"),
4652 case DW_MACRO_GNU_undef
:
4653 lineno
= read_uleb128 (curr
, &bytes_read
, end
);
4656 curr
+= strnlen ((char *) string
, end
- string
) + 1;
4657 printf (_(" DW_MACRO_GNU_undef - lineno : %d macro : %s\n"),
4661 case DW_MACRO_GNU_define_indirect
:
4662 lineno
= read_uleb128 (curr
, &bytes_read
, end
);
4664 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
4665 string
= fetch_indirect_string (offset
);
4666 printf (_(" DW_MACRO_GNU_define_indirect - lineno : %d macro : %s\n"),
4670 case DW_MACRO_GNU_undef_indirect
:
4671 lineno
= read_uleb128 (curr
, &bytes_read
, end
);
4673 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
4674 string
= fetch_indirect_string (offset
);
4675 printf (_(" DW_MACRO_GNU_undef_indirect - lineno : %d macro : %s\n"),
4679 case DW_MACRO_GNU_transparent_include
:
4680 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
4681 printf (_(" DW_MACRO_GNU_transparent_include - offset : 0x%lx\n"),
4682 (unsigned long) offset
);
4685 case DW_MACRO_GNU_define_indirect_alt
:
4686 lineno
= read_uleb128 (curr
, &bytes_read
, end
);
4688 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
4689 printf (_(" DW_MACRO_GNU_define_indirect_alt - lineno : %d macro offset : 0x%lx\n"),
4690 lineno
, (unsigned long) offset
);
4693 case DW_MACRO_GNU_undef_indirect_alt
:
4694 lineno
= read_uleb128 (curr
, &bytes_read
, end
);
4696 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
4697 printf (_(" DW_MACRO_GNU_undef_indirect_alt - lineno : %d macro offset : 0x%lx\n"),
4698 lineno
, (unsigned long) offset
);
4701 case DW_MACRO_GNU_transparent_include_alt
:
4702 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
4703 printf (_(" DW_MACRO_GNU_transparent_include_alt - offset : 0x%lx\n"),
4704 (unsigned long) offset
);
4708 if (extended_ops
== NULL
|| extended_ops
[op
] == NULL
)
4710 error (_(" Unknown macro opcode %02x seen\n"), op
);
4715 /* Skip over unhandled opcodes. */
4717 unsigned char *desc
= extended_ops
[op
];
4718 nargs
= read_uleb128 (desc
, &bytes_read
, end
);
4722 printf (_(" DW_MACRO_GNU_%02x\n"), op
);
4725 printf (_(" DW_MACRO_GNU_%02x -"), op
);
4726 for (n
= 0; n
< nargs
; n
++)
4730 /* DW_FORM_implicit_const is not expected here. */
4731 SAFE_BYTE_GET_AND_INC (val
, desc
, 1, end
);
4733 = read_and_display_attr_value (0, val
, 0,
4734 curr
, end
, 0, 0, offset_size
,
4735 version
, NULL
, 0, NULL
,
4753 display_debug_abbrev (struct dwarf_section
*section
,
4754 void *file ATTRIBUTE_UNUSED
)
4756 abbrev_entry
*entry
;
4757 unsigned char *start
= section
->start
;
4758 unsigned char *end
= start
+ section
->size
;
4760 printf (_("Contents of the %s section:\n\n"), section
->name
);
4764 unsigned char *last
;
4769 start
= process_abbrev_section (start
, end
);
4771 if (first_abbrev
== NULL
)
4774 printf (_(" Number TAG (0x%lx)\n"), (long) (last
- section
->start
));
4776 for (entry
= first_abbrev
; entry
; entry
= entry
->next
)
4780 printf (" %ld %s [%s]\n",
4782 get_TAG_name (entry
->tag
),
4783 entry
->children
? _("has children") : _("no children"));
4785 for (attr
= entry
->first_attr
; attr
; attr
= attr
->next
)
4787 printf (" %-18s %s",
4788 get_AT_name (attr
->attribute
),
4789 get_FORM_name (attr
->form
));
4790 if (attr
->form
== DW_FORM_implicit_const
)
4791 printf (": %" BFD_VMA_FMT
"d", attr
->implicit_const
);
4803 /* Return true when ADDR is the maximum address, when addresses are
4804 POINTER_SIZE bytes long. */
4807 is_max_address (dwarf_vma addr
, unsigned int pointer_size
)
4809 dwarf_vma mask
= ~(~(dwarf_vma
) 1 << (pointer_size
* 8 - 1));
4810 return ((addr
& mask
) == mask
);
4813 /* Display a location list from a normal (ie, non-dwo) .debug_loc section. */
4816 display_loc_list (struct dwarf_section
*section
,
4817 unsigned char **start_ptr
,
4818 unsigned int debug_info_entry
,
4820 dwarf_vma base_address
,
4823 unsigned char *start
= *start_ptr
;
4824 unsigned char *section_end
= section
->start
+ section
->size
;
4825 unsigned long cu_offset
;
4826 unsigned int pointer_size
;
4827 unsigned int offset_size
;
4832 unsigned short length
;
4833 int need_frame_base
;
4835 if (debug_info_entry
>= num_debug_info_entries
)
4837 warn (_("No debug information available for loc lists of entry: %u\n"),
4842 cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
4843 pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
4844 offset_size
= debug_information
[debug_info_entry
].offset_size
;
4845 dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
4847 if (pointer_size
< 2 || pointer_size
> 8)
4849 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
4850 pointer_size
, debug_info_entry
);
4856 dwarf_vma off
= offset
+ (start
- *start_ptr
);
4858 if (start
+ 2 * pointer_size
> section_end
)
4860 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
4861 (unsigned long) offset
);
4865 printf (" %8.8lx ", (unsigned long) off
);
4867 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, section_end
);
4868 SAFE_BYTE_GET_AND_INC (end
, start
, pointer_size
, section_end
);
4870 if (begin
== 0 && end
== 0)
4872 /* PR 18374: In a object file we can have a location list that
4873 starts with a begin and end of 0 because there are relocations
4874 that need to be applied to the addresses. Actually applying
4875 the relocations now does not help as they will probably resolve
4876 to 0, since the object file has not been fully linked. Real
4877 end of list markers will not have any relocations against them. */
4878 if (! reloc_at (section
, off
)
4879 && ! reloc_at (section
, off
+ pointer_size
))
4881 printf (_("<End of list>\n"));
4886 /* Check base address specifiers. */
4887 if (is_max_address (begin
, pointer_size
)
4888 && !is_max_address (end
, pointer_size
))
4891 print_dwarf_vma (begin
, pointer_size
);
4892 print_dwarf_vma (end
, pointer_size
);
4893 printf (_("(base address)\n"));
4897 if (start
+ 2 > section_end
)
4899 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
4900 (unsigned long) offset
);
4904 SAFE_BYTE_GET_AND_INC (length
, start
, 2, section_end
);
4906 if (start
+ length
> section_end
)
4908 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
4909 (unsigned long) offset
);
4913 print_dwarf_vma (begin
+ base_address
, pointer_size
);
4914 print_dwarf_vma (end
+ base_address
, pointer_size
);
4917 need_frame_base
= decode_location_expression (start
,
4922 cu_offset
, section
);
4925 if (need_frame_base
&& !has_frame_base
)
4926 printf (_(" [without DW_AT_frame_base]"));
4929 fputs (_(" (start == end)"), stdout
);
4930 else if (begin
> end
)
4931 fputs (_(" (start > end)"), stdout
);
4941 /* Display a location list from a normal (ie, non-dwo) .debug_loclists section. */
4944 display_loclists_list (struct dwarf_section
*section
,
4945 unsigned char **start_ptr
,
4946 unsigned int debug_info_entry
,
4948 dwarf_vma base_address
,
4951 unsigned char *start
= *start_ptr
;
4952 unsigned char *section_end
= section
->start
+ section
->size
;
4953 unsigned long cu_offset
;
4954 unsigned int pointer_size
;
4955 unsigned int offset_size
;
4957 unsigned int bytes_read
;
4962 int need_frame_base
;
4964 if (debug_info_entry
>= num_debug_info_entries
)
4966 warn (_("No debug information available for "
4967 "loclists lists of entry: %u\n"),
4972 cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
4973 pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
4974 offset_size
= debug_information
[debug_info_entry
].offset_size
;
4975 dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
4977 if (pointer_size
< 2 || pointer_size
> 8)
4979 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
4980 pointer_size
, debug_info_entry
);
4986 dwarf_vma off
= offset
+ (start
- *start_ptr
);
4987 enum dwarf_location_list_entry_type llet
;
4989 if (start
+ 1 > section_end
)
4991 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
4992 (unsigned long) offset
);
4996 printf (" %8.8lx ", (unsigned long) off
);
4998 SAFE_BYTE_GET_AND_INC (llet
, start
, 1, section_end
);
5002 case DW_LLE_end_of_list
:
5003 printf (_("<End of list>\n"));
5005 case DW_LLE_offset_pair
:
5006 begin
= read_uleb128 (start
, &bytes_read
, section_end
);
5007 start
+= bytes_read
;
5008 end
= read_uleb128 (start
, &bytes_read
, section_end
);
5009 start
+= bytes_read
;
5011 case DW_LLE_base_address
:
5012 SAFE_BYTE_GET_AND_INC (base_address
, start
, pointer_size
,
5014 print_dwarf_vma (base_address
, pointer_size
);
5015 printf (_("(base address)\n"));
5018 error (_("Invalid location list entry type %d\n"), llet
);
5021 if (llet
== DW_LLE_end_of_list
)
5023 if (llet
!= DW_LLE_offset_pair
)
5026 if (start
+ 2 > section_end
)
5028 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5029 (unsigned long) offset
);
5033 length
= read_uleb128 (start
, &bytes_read
, section_end
);
5034 start
+= bytes_read
;
5036 print_dwarf_vma (begin
+ base_address
, pointer_size
);
5037 print_dwarf_vma (end
+ base_address
, pointer_size
);
5040 need_frame_base
= decode_location_expression (start
,
5045 cu_offset
, section
);
5048 if (need_frame_base
&& !has_frame_base
)
5049 printf (_(" [without DW_AT_frame_base]"));
5052 fputs (_(" (start == end)"), stdout
);
5053 else if (begin
> end
)
5054 fputs (_(" (start > end)"), stdout
);
5064 /* Print a .debug_addr table index in decimal, surrounded by square brackets,
5065 right-adjusted in a field of length LEN, and followed by a space. */
5068 print_addr_index (unsigned int idx
, unsigned int len
)
5070 static char buf
[15];
5071 snprintf (buf
, sizeof (buf
), "[%d]", idx
);
5072 printf ("%*s ", len
, buf
);
5075 /* Display a location list from a .dwo section. It uses address indexes rather
5076 than embedded addresses. This code closely follows display_loc_list, but the
5077 two are sufficiently different that combining things is very ugly. */
5080 display_loc_list_dwo (struct dwarf_section
*section
,
5081 unsigned char **start_ptr
,
5082 unsigned int debug_info_entry
,
5086 unsigned char *start
= *start_ptr
;
5087 unsigned char *section_end
= section
->start
+ section
->size
;
5088 unsigned long cu_offset
;
5089 unsigned int pointer_size
;
5090 unsigned int offset_size
;
5093 unsigned short length
;
5094 int need_frame_base
;
5096 unsigned int bytes_read
;
5098 if (debug_info_entry
>= num_debug_info_entries
)
5100 warn (_("No debug information for loc lists of entry: %u\n"),
5105 cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
5106 pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
5107 offset_size
= debug_information
[debug_info_entry
].offset_size
;
5108 dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
5110 if (pointer_size
< 2 || pointer_size
> 8)
5112 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
5113 pointer_size
, debug_info_entry
);
5119 printf (" %8.8lx ", (unsigned long) (offset
+ (start
- *start_ptr
)));
5121 if (start
>= section_end
)
5123 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5124 (unsigned long) offset
);
5128 SAFE_BYTE_GET_AND_INC (entry_type
, start
, 1, section_end
);
5131 case 0: /* A terminating entry. */
5133 printf (_("<End of list>\n"));
5135 case 1: /* A base-address entry. */
5136 idx
= read_uleb128 (start
, &bytes_read
, section_end
);
5137 start
+= bytes_read
;
5138 print_addr_index (idx
, 8);
5140 printf (_("(base address selection entry)\n"));
5142 case 2: /* A start/end entry. */
5143 idx
= read_uleb128 (start
, &bytes_read
, section_end
);
5144 start
+= bytes_read
;
5145 print_addr_index (idx
, 8);
5146 idx
= read_uleb128 (start
, &bytes_read
, section_end
);
5147 start
+= bytes_read
;
5148 print_addr_index (idx
, 8);
5150 case 3: /* A start/length entry. */
5151 idx
= read_uleb128 (start
, &bytes_read
, section_end
);
5152 start
+= bytes_read
;
5153 print_addr_index (idx
, 8);
5154 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
5155 printf ("%08x ", idx
);
5157 case 4: /* An offset pair entry. */
5158 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
5159 printf ("%08x ", idx
);
5160 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
5161 printf ("%08x ", idx
);
5164 warn (_("Unknown location list entry type 0x%x.\n"), entry_type
);
5169 if (start
+ 2 > section_end
)
5171 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5172 (unsigned long) offset
);
5176 SAFE_BYTE_GET_AND_INC (length
, start
, 2, section_end
);
5177 if (start
+ length
> section_end
)
5179 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5180 (unsigned long) offset
);
5185 need_frame_base
= decode_location_expression (start
,
5190 cu_offset
, section
);
5193 if (need_frame_base
&& !has_frame_base
)
5194 printf (_(" [without DW_AT_frame_base]"));
5204 /* Sort array of indexes in ascending order of loc_offsets[idx]. */
5206 static dwarf_vma
*loc_offsets
;
5209 loc_offsets_compar (const void *ap
, const void *bp
)
5211 dwarf_vma a
= loc_offsets
[*(const unsigned int *) ap
];
5212 dwarf_vma b
= loc_offsets
[*(const unsigned int *) bp
];
5214 return (a
> b
) - (b
> a
);
5218 display_debug_loc (struct dwarf_section
*section
, void *file
)
5220 unsigned char *start
= section
->start
;
5221 unsigned long bytes
;
5222 unsigned char *section_begin
= start
;
5223 unsigned int num_loc_list
= 0;
5224 unsigned long last_offset
= 0;
5225 unsigned int first
= 0;
5228 int seen_first_offset
= 0;
5229 int locs_sorted
= 1;
5230 unsigned char *next
;
5231 unsigned int *array
= NULL
;
5232 const char *suffix
= strrchr (section
->name
, '.');
5234 int is_loclists
= strstr (section
->name
, "debug_loclists") != NULL
;
5235 dwarf_vma expected_start
= 0;
5237 if (suffix
&& strcmp (suffix
, ".dwo") == 0)
5240 bytes
= section
->size
;
5244 printf (_("\nThe %s section is empty.\n"), section
->name
);
5250 unsigned char *hdrptr
= section_begin
;
5251 dwarf_vma ll_length
;
5252 unsigned short ll_version
;
5253 unsigned char *end
= section_begin
+ section
->size
;
5254 unsigned char address_size
, segment_selector_size
;
5255 uint32_t offset_entry_count
;
5257 SAFE_BYTE_GET_AND_INC (ll_length
, hdrptr
, 4, end
);
5258 if (ll_length
== 0xffffffff)
5259 SAFE_BYTE_GET_AND_INC (ll_length
, hdrptr
, 8, end
);
5261 SAFE_BYTE_GET_AND_INC (ll_version
, hdrptr
, 2, end
);
5262 if (ll_version
!= 5)
5264 warn (_("The %s section contains corrupt or "
5265 "unsupported version number: %d.\n"),
5266 section
->name
, ll_version
);
5270 SAFE_BYTE_GET_AND_INC (address_size
, hdrptr
, 1, end
);
5272 SAFE_BYTE_GET_AND_INC (segment_selector_size
, hdrptr
, 1, end
);
5273 if (segment_selector_size
!= 0)
5275 warn (_("The %s section contains "
5276 "unsupported segment selector size: %d.\n"),
5277 section
->name
, segment_selector_size
);
5281 SAFE_BYTE_GET_AND_INC (offset_entry_count
, hdrptr
, 4, end
);
5282 if (offset_entry_count
!= 0)
5284 warn (_("The %s section contains "
5285 "unsupported offset entry count: %d.\n"),
5286 section
->name
, offset_entry_count
);
5290 expected_start
= hdrptr
- section_begin
;
5293 if (load_debug_info (file
) == 0)
5295 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
5300 /* Check the order of location list in .debug_info section. If
5301 offsets of location lists are in the ascending order, we can
5302 use `debug_information' directly. */
5303 for (i
= 0; i
< num_debug_info_entries
; i
++)
5307 num
= debug_information
[i
].num_loc_offsets
;
5308 if (num
> num_loc_list
)
5311 /* Check if we can use `debug_information' directly. */
5312 if (locs_sorted
&& num
!= 0)
5314 if (!seen_first_offset
)
5316 /* This is the first location list. */
5317 last_offset
= debug_information
[i
].loc_offsets
[0];
5319 seen_first_offset
= 1;
5325 for (; j
< num
; j
++)
5328 debug_information
[i
].loc_offsets
[j
])
5333 last_offset
= debug_information
[i
].loc_offsets
[j
];
5338 if (!seen_first_offset
)
5339 error (_("No location lists in .debug_info section!\n"));
5341 if (debug_information
[first
].num_loc_offsets
> 0
5342 && debug_information
[first
].loc_offsets
[0] != expected_start
)
5343 warn (_("Location lists in %s section start at 0x%s\n"),
5345 dwarf_vmatoa ("x", debug_information
[first
].loc_offsets
[0]));
5348 array
= (unsigned int *) xcmalloc (num_loc_list
, sizeof (unsigned int));
5349 printf (_("Contents of the %s section:\n\n"), section
->name
);
5350 if (reloc_at (section
, 0))
5351 printf (_(" Warning: This section has relocations - addresses seen here may not be accurate.\n\n"));
5352 printf (_(" Offset Begin End Expression\n"));
5354 seen_first_offset
= 0;
5355 for (i
= first
; i
< num_debug_info_entries
; i
++)
5358 dwarf_vma base_address
;
5364 for (k
= 0; k
< debug_information
[i
].num_loc_offsets
; k
++)
5366 loc_offsets
= debug_information
[i
].loc_offsets
;
5367 qsort (array
, debug_information
[i
].num_loc_offsets
,
5368 sizeof (*array
), loc_offsets_compar
);
5371 for (k
= 0; k
< debug_information
[i
].num_loc_offsets
; k
++)
5373 j
= locs_sorted
? k
: array
[k
];
5375 && debug_information
[i
].loc_offsets
[locs_sorted
5376 ? k
- 1 : array
[k
- 1]]
5377 == debug_information
[i
].loc_offsets
[j
])
5379 has_frame_base
= debug_information
[i
].have_frame_base
[j
];
5380 offset
= debug_information
[i
].loc_offsets
[j
];
5381 next
= section_begin
+ offset
;
5382 base_address
= debug_information
[i
].base_address
;
5384 if (!seen_first_offset
)
5385 seen_first_offset
= 1;
5389 warn (_("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n"),
5390 (unsigned long) (start
- section_begin
),
5391 (unsigned long) offset
);
5392 else if (start
> next
)
5393 warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n"),
5394 (unsigned long) (start
- section_begin
),
5395 (unsigned long) offset
);
5399 if (offset
>= bytes
)
5401 warn (_("Offset 0x%lx is bigger than .debug_loc section size.\n"),
5402 (unsigned long) offset
);
5409 display_loc_list_dwo (section
, &start
, i
, offset
,
5412 display_loc_list (section
, &start
, i
, offset
, base_address
,
5418 warn (_("DWO is not yet supported.\n"));
5420 display_loclists_list (section
, &start
, i
, offset
, base_address
,
5426 if (start
< section
->start
+ section
->size
)
5427 warn (_("There are %ld unused bytes at the end of section %s\n"),
5428 (long) (section
->start
+ section
->size
- start
), section
->name
);
5435 display_debug_str (struct dwarf_section
*section
,
5436 void *file ATTRIBUTE_UNUSED
)
5438 unsigned char *start
= section
->start
;
5439 unsigned long bytes
= section
->size
;
5440 dwarf_vma addr
= section
->address
;
5444 printf (_("\nThe %s section is empty.\n"), section
->name
);
5448 printf (_("Contents of the %s section:\n\n"), section
->name
);
5456 lbytes
= (bytes
> 16 ? 16 : bytes
);
5458 printf (" 0x%8.8lx ", (unsigned long) addr
);
5460 for (j
= 0; j
< 16; j
++)
5463 printf ("%2.2x", start
[j
]);
5471 for (j
= 0; j
< lbytes
; j
++)
5474 if (k
>= ' ' && k
< 0x80)
5493 display_debug_info (struct dwarf_section
*section
, void *file
)
5495 return process_debug_info (section
, file
, section
->abbrev_sec
, 0, 0);
5499 display_debug_types (struct dwarf_section
*section
, void *file
)
5501 return process_debug_info (section
, file
, section
->abbrev_sec
, 0, 1);
5505 display_trace_info (struct dwarf_section
*section
, void *file
)
5507 return process_debug_info (section
, file
, section
->abbrev_sec
, 0, 0);
5511 display_debug_aranges (struct dwarf_section
*section
,
5512 void *file ATTRIBUTE_UNUSED
)
5514 unsigned char *start
= section
->start
;
5515 unsigned char *end
= start
+ section
->size
;
5517 printf (_("Contents of the %s section:\n\n"), section
->name
);
5519 /* It does not matter if this load fails,
5520 we test for that later on. */
5521 load_debug_info (file
);
5525 unsigned char *hdrptr
;
5526 DWARF2_Internal_ARange arange
;
5527 unsigned char *addr_ranges
;
5530 unsigned char address_size
;
5532 unsigned int offset_size
;
5533 unsigned int initial_length_size
;
5537 SAFE_BYTE_GET_AND_INC (arange
.ar_length
, hdrptr
, 4, end
);
5538 if (arange
.ar_length
== 0xffffffff)
5540 SAFE_BYTE_GET_AND_INC (arange
.ar_length
, hdrptr
, 8, end
);
5542 initial_length_size
= 12;
5547 initial_length_size
= 4;
5550 SAFE_BYTE_GET_AND_INC (arange
.ar_version
, hdrptr
, 2, end
);
5551 SAFE_BYTE_GET_AND_INC (arange
.ar_info_offset
, hdrptr
, offset_size
, end
);
5553 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
5554 && num_debug_info_entries
> 0
5555 && find_debug_info_for_offset (arange
.ar_info_offset
) == NULL
)
5556 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
5557 (unsigned long) arange
.ar_info_offset
, section
->name
);
5559 SAFE_BYTE_GET_AND_INC (arange
.ar_pointer_size
, hdrptr
, 1, end
);
5560 SAFE_BYTE_GET_AND_INC (arange
.ar_segment_size
, hdrptr
, 1, end
);
5562 if (arange
.ar_version
!= 2 && arange
.ar_version
!= 3)
5564 /* PR 19872: A version number of 0 probably means that there is
5565 padding at the end of the .debug_aranges section. Gold puts
5566 it there when performing an incremental link, for example.
5567 So do not generate a warning in this case. */
5568 if (arange
.ar_version
)
5569 warn (_("Only DWARF 2 and 3 aranges are currently supported.\n"));
5573 printf (_(" Length: %ld\n"),
5574 (long) arange
.ar_length
);
5575 printf (_(" Version: %d\n"), arange
.ar_version
);
5576 printf (_(" Offset into .debug_info: 0x%lx\n"),
5577 (unsigned long) arange
.ar_info_offset
);
5578 printf (_(" Pointer Size: %d\n"), arange
.ar_pointer_size
);
5579 printf (_(" Segment Size: %d\n"), arange
.ar_segment_size
);
5581 address_size
= arange
.ar_pointer_size
+ arange
.ar_segment_size
;
5583 /* PR 17512: file: 001-108546-0.001:0.1. */
5584 if (address_size
== 0 || address_size
> 8)
5586 error (_("Invalid address size in %s section!\n"),
5591 /* The DWARF spec does not require that the address size be a power
5592 of two, but we do. This will have to change if we ever encounter
5593 an uneven architecture. */
5594 if ((address_size
& (address_size
- 1)) != 0)
5596 warn (_("Pointer size + Segment size is not a power of two.\n"));
5600 if (address_size
> 4)
5601 printf (_("\n Address Length\n"));
5603 printf (_("\n Address Length\n"));
5605 addr_ranges
= hdrptr
;
5607 /* Must pad to an alignment boundary that is twice the address size. */
5608 excess
= (hdrptr
- start
) % (2 * address_size
);
5610 addr_ranges
+= (2 * address_size
) - excess
;
5612 hdrptr
= start
+ arange
.ar_length
+ initial_length_size
;
5613 if (hdrptr
< start
|| hdrptr
> end
)
5615 error (_("Excessive header length: %lx\n"), (long) arange
.ar_length
);
5620 while (addr_ranges
+ 2 * address_size
<= start
)
5622 SAFE_BYTE_GET_AND_INC (address
, addr_ranges
, address_size
, end
);
5623 SAFE_BYTE_GET_AND_INC (length
, addr_ranges
, address_size
, end
);
5626 print_dwarf_vma (address
, address_size
);
5627 print_dwarf_vma (length
, address_size
);
5637 /* Comparison function for qsort. */
5639 comp_addr_base (const void * v0
, const void * v1
)
5641 debug_info
* info0
= (debug_info
*) v0
;
5642 debug_info
* info1
= (debug_info
*) v1
;
5643 return info0
->addr_base
- info1
->addr_base
;
5646 /* Display the debug_addr section. */
5648 display_debug_addr (struct dwarf_section
*section
,
5651 debug_info
**debug_addr_info
;
5652 unsigned char *entry
;
5657 if (section
->size
== 0)
5659 printf (_("\nThe %s section is empty.\n"), section
->name
);
5663 if (load_debug_info (file
) == 0)
5665 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
5670 printf (_("Contents of the %s section:\n\n"), section
->name
);
5672 /* PR 17531: file: cf38d01b.
5673 We use xcalloc because a corrupt file may not have initialised all of the
5674 fields in the debug_info structure, which means that the sort below might
5675 try to move uninitialised data. */
5676 debug_addr_info
= (debug_info
**) xcalloc ((num_debug_info_entries
+ 1),
5677 sizeof (debug_info
*));
5680 for (i
= 0; i
< num_debug_info_entries
; i
++)
5681 if (debug_information
[i
].addr_base
!= DEBUG_INFO_UNAVAILABLE
)
5683 /* PR 17531: file: cf38d01b. */
5684 if (debug_information
[i
].addr_base
>= section
->size
)
5685 warn (_("Corrupt address base (%lx) found in debug section %u\n"),
5686 (unsigned long) debug_information
[i
].addr_base
, i
);
5688 debug_addr_info
[count
++] = debug_information
+ i
;
5691 /* Add a sentinel to make iteration convenient. */
5692 debug_addr_info
[count
] = (debug_info
*) xmalloc (sizeof (debug_info
));
5693 debug_addr_info
[count
]->addr_base
= section
->size
;
5694 qsort (debug_addr_info
, count
, sizeof (debug_info
*), comp_addr_base
);
5696 for (i
= 0; i
< count
; i
++)
5699 unsigned int address_size
= debug_addr_info
[i
]->pointer_size
;
5701 printf (_(" For compilation unit at offset 0x%s:\n"),
5702 dwarf_vmatoa ("x", debug_addr_info
[i
]->cu_offset
));
5704 printf (_("\tIndex\tAddress\n"));
5705 entry
= section
->start
+ debug_addr_info
[i
]->addr_base
;
5706 end
= section
->start
+ debug_addr_info
[i
+ 1]->addr_base
;
5710 dwarf_vma base
= byte_get (entry
, address_size
);
5711 printf (_("\t%d:\t"), idx
);
5712 print_dwarf_vma (base
, address_size
);
5714 entry
+= address_size
;
5720 free (debug_addr_info
);
5724 /* Display the .debug_str_offsets and .debug_str_offsets.dwo sections. */
5726 display_debug_str_offsets (struct dwarf_section
*section
,
5727 void *file ATTRIBUTE_UNUSED
)
5729 if (section
->size
== 0)
5731 printf (_("\nThe %s section is empty.\n"), section
->name
);
5734 /* TODO: Dump the contents. This is made somewhat difficult by not knowing
5735 what the offset size is for this section. */
5739 /* Each debug_information[x].range_lists[y] gets this representation for
5740 sorting purposes. */
5744 /* The debug_information[x].range_lists[y] value. */
5745 dwarf_vma ranges_offset
;
5747 /* Original debug_information to find parameters of the data. */
5748 debug_info
*debug_info_p
;
5751 /* Sort struct range_entry in ascending order of its RANGES_OFFSET. */
5754 range_entry_compar (const void *ap
, const void *bp
)
5756 const struct range_entry
*a_re
= (const struct range_entry
*) ap
;
5757 const struct range_entry
*b_re
= (const struct range_entry
*) bp
;
5758 const dwarf_vma a
= a_re
->ranges_offset
;
5759 const dwarf_vma b
= b_re
->ranges_offset
;
5761 return (a
> b
) - (b
> a
);
5765 display_debug_ranges_list (unsigned char *start
, unsigned char *finish
,
5766 unsigned int pointer_size
, unsigned long offset
,
5767 unsigned long base_address
)
5769 while (start
< finish
)
5774 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
5775 if (start
>= finish
)
5777 SAFE_SIGNED_BYTE_GET_AND_INC (end
, start
, pointer_size
, finish
);
5779 printf (" %8.8lx ", offset
);
5781 if (begin
== 0 && end
== 0)
5783 printf (_("<End of list>\n"));
5787 /* Check base address specifiers. */
5788 if (is_max_address (begin
, pointer_size
)
5789 && !is_max_address (end
, pointer_size
))
5792 print_dwarf_vma (begin
, pointer_size
);
5793 print_dwarf_vma (end
, pointer_size
);
5794 printf ("(base address)\n");
5798 print_dwarf_vma (begin
+ base_address
, pointer_size
);
5799 print_dwarf_vma (end
+ base_address
, pointer_size
);
5802 fputs (_("(start == end)"), stdout
);
5803 else if (begin
> end
)
5804 fputs (_("(start > end)"), stdout
);
5811 display_debug_rnglists_list (unsigned char *start
, unsigned char *finish
,
5812 unsigned int pointer_size
, unsigned long offset
,
5813 unsigned long base_address
)
5815 unsigned char *next
= start
;
5819 unsigned long off
= offset
+ (start
- next
);
5820 enum dwarf_range_list_entry rlet
;
5821 dwarf_vma begin
, length
, end
;
5822 unsigned int bytes_read
;
5824 if (start
+ 1 > finish
)
5826 warn (_("Range list starting at offset 0x%lx is not terminated.\n"),
5831 printf (" %8.8lx ", off
);
5833 SAFE_BYTE_GET_AND_INC (rlet
, start
, 1, finish
);
5837 case DW_RLE_end_of_list
:
5838 printf (_("<End of list>\n"));
5840 case DW_RLE_base_address
:
5841 SAFE_BYTE_GET_AND_INC (base_address
, start
, pointer_size
, finish
);
5842 print_dwarf_vma (base_address
, pointer_size
);
5843 printf (_("(base address)\n"));
5845 case DW_RLE_start_length
:
5846 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
5847 length
= read_uleb128 (start
, &bytes_read
, finish
);
5848 start
+= bytes_read
;
5849 end
= begin
+ length
;
5851 case DW_RLE_offset_pair
:
5852 begin
= read_uleb128 (start
, &bytes_read
, finish
);
5853 start
+= bytes_read
;
5854 end
= read_uleb128 (start
, &bytes_read
, finish
);
5855 start
+= bytes_read
;
5857 case DW_RLE_start_end
:
5858 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
5859 SAFE_BYTE_GET_AND_INC (end
, start
, pointer_size
, finish
);
5862 error (_("Invalid range list entry type %d\n"), rlet
);
5863 rlet
= DW_RLE_end_of_list
;
5866 if (rlet
== DW_RLE_end_of_list
)
5868 if (rlet
== DW_RLE_base_address
)
5871 print_dwarf_vma (begin
+ base_address
, pointer_size
);
5872 print_dwarf_vma (end
+ base_address
, pointer_size
);
5875 fputs (_("(start == end)"), stdout
);
5876 else if (begin
> end
)
5877 fputs (_("(start > end)"), stdout
);
5884 display_debug_ranges (struct dwarf_section
*section
,
5885 void *file ATTRIBUTE_UNUSED
)
5887 unsigned char *start
= section
->start
;
5888 unsigned char *last_start
= start
;
5889 unsigned long bytes
= section
->size
;
5890 unsigned char *section_begin
= start
;
5891 unsigned char *finish
= start
+ bytes
;
5892 unsigned int num_range_list
, i
;
5893 struct range_entry
*range_entries
, *range_entry_fill
;
5894 int is_rnglists
= strstr (section
->name
, "debug_rnglists") != NULL
;
5895 /* Initialize it due to a false compiler warning. */
5896 unsigned char address_size
= 0;
5900 printf (_("\nThe %s section is empty.\n"), section
->name
);
5906 dwarf_vma initial_length
;
5907 unsigned int initial_length_size
;
5908 unsigned char segment_selector_size
;
5909 unsigned int offset_size
, offset_entry_count
;
5910 unsigned short version
;
5912 /* Get and check the length of the block. */
5913 SAFE_BYTE_GET_AND_INC (initial_length
, start
, 4, finish
);
5915 if (initial_length
== 0xffffffff)
5917 /* This section is 64-bit DWARF 3. */
5918 SAFE_BYTE_GET_AND_INC (initial_length
, start
, 8, finish
);
5920 initial_length_size
= 12;
5925 initial_length_size
= 4;
5928 if (initial_length
+ initial_length_size
> section
->size
)
5930 /* If the length field has a relocation against it, then we should
5931 not complain if it is inaccurate (and probably negative).
5932 It is copied from .debug_line handling code. */
5933 if (reloc_at (section
, (start
- section
->start
) - offset_size
))
5935 initial_length
= (finish
- start
) - initial_length_size
;
5939 warn (_("The length field (0x%lx) in the debug_rnglists header is wrong - the section is too small\n"),
5940 (long) initial_length
);
5945 /* Get and check the version number. */
5946 SAFE_BYTE_GET_AND_INC (version
, start
, 2, finish
);
5950 warn (_("Only DWARF version 5 debug_rnglists info "
5951 "is currently supported.\n"));
5955 SAFE_BYTE_GET_AND_INC (address_size
, start
, 1, finish
);
5957 SAFE_BYTE_GET_AND_INC (segment_selector_size
, start
, 1, finish
);
5958 if (segment_selector_size
!= 0)
5960 warn (_("The %s section contains "
5961 "unsupported segment selector size: %d.\n"),
5962 section
->name
, segment_selector_size
);
5966 SAFE_BYTE_GET_AND_INC (offset_entry_count
, start
, 4, finish
);
5967 if (offset_entry_count
!= 0)
5969 warn (_("The %s section contains "
5970 "unsupported offset entry count: %u.\n"),
5971 section
->name
, offset_entry_count
);
5976 if (load_debug_info (file
) == 0)
5978 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
5984 for (i
= 0; i
< num_debug_info_entries
; i
++)
5985 num_range_list
+= debug_information
[i
].num_range_lists
;
5987 if (num_range_list
== 0)
5989 /* This can happen when the file was compiled with -gsplit-debug
5990 which removes references to range lists from the primary .o file. */
5991 printf (_("No range lists in .debug_info section.\n"));
5995 range_entries
= (struct range_entry
*)
5996 xmalloc (sizeof (*range_entries
) * num_range_list
);
5997 range_entry_fill
= range_entries
;
5999 for (i
= 0; i
< num_debug_info_entries
; i
++)
6001 debug_info
*debug_info_p
= &debug_information
[i
];
6004 for (j
= 0; j
< debug_info_p
->num_range_lists
; j
++)
6006 range_entry_fill
->ranges_offset
= debug_info_p
->range_lists
[j
];
6007 range_entry_fill
->debug_info_p
= debug_info_p
;
6012 qsort (range_entries
, num_range_list
, sizeof (*range_entries
),
6013 range_entry_compar
);
6015 if (dwarf_check
!= 0 && range_entries
[0].ranges_offset
!= 0)
6016 warn (_("Range lists in %s section start at 0x%lx\n"),
6017 section
->name
, (unsigned long) range_entries
[0].ranges_offset
);
6019 printf (_("Contents of the %s section:\n\n"), section
->name
);
6020 printf (_(" Offset Begin End\n"));
6022 for (i
= 0; i
< num_range_list
; i
++)
6024 struct range_entry
*range_entry
= &range_entries
[i
];
6025 debug_info
*debug_info_p
= range_entry
->debug_info_p
;
6026 unsigned int pointer_size
;
6028 unsigned char *next
;
6029 dwarf_vma base_address
;
6031 pointer_size
= (is_rnglists
? address_size
: debug_info_p
->pointer_size
);
6032 offset
= range_entry
->ranges_offset
;
6033 next
= section_begin
+ offset
;
6034 base_address
= debug_info_p
->base_address
;
6036 /* PR 17512: file: 001-101485-0.001:0.1. */
6037 if (pointer_size
< 2 || pointer_size
> 8)
6039 warn (_("Corrupt pointer size (%d) in debug entry at offset %8.8lx\n"),
6040 pointer_size
, (unsigned long) offset
);
6044 if (dwarf_check
!= 0 && i
> 0)
6047 warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"),
6048 (unsigned long) (start
- section_begin
),
6049 (unsigned long) (next
- section_begin
), section
->name
);
6050 else if (start
> next
)
6052 if (next
== last_start
)
6054 warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"),
6055 (unsigned long) (start
- section_begin
),
6056 (unsigned long) (next
- section_begin
), section
->name
);
6062 (is_rnglists
? display_debug_rnglists_list
: display_debug_ranges_list
)
6063 (start
, finish
, pointer_size
, offset
, base_address
);
6067 free (range_entries
);
6072 typedef struct Frame_Chunk
6074 struct Frame_Chunk
*next
;
6075 unsigned char *chunk_start
;
6077 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
6078 short int *col_type
;
6081 unsigned int code_factor
;
6086 dwarf_vma cfa_offset
;
6088 unsigned char fde_encoding
;
6089 unsigned char cfa_exp
;
6090 unsigned char ptr_size
;
6091 unsigned char segment_size
;
6095 static const char *const *dwarf_regnames
;
6096 static unsigned int dwarf_regnames_count
;
6098 /* A marker for a col_type that means this column was never referenced
6099 in the frame info. */
6100 #define DW_CFA_unreferenced (-1)
6102 /* Return 0 if no more space is needed, 1 if more space is needed,
6103 -1 for invalid reg. */
6106 frame_need_space (Frame_Chunk
*fc
, unsigned int reg
)
6108 unsigned int prev
= fc
->ncols
;
6110 if (reg
< (unsigned int) fc
->ncols
)
6113 if (dwarf_regnames_count
6114 && reg
> dwarf_regnames_count
)
6117 fc
->ncols
= reg
+ 1;
6118 /* PR 17512: file: 10450-2643-0.004.
6119 If reg == -1 then this can happen... */
6123 /* PR 17512: file: 2844a11d. */
6124 if (fc
->ncols
> 1024)
6126 error (_("Unfeasibly large register number: %u\n"), reg
);
6128 /* FIXME: 1024 is an arbitrary limit. Increase it if
6129 we ever encounter a valid binary that exceeds it. */
6133 fc
->col_type
= (short int *) xcrealloc (fc
->col_type
, fc
->ncols
,
6134 sizeof (short int));
6135 fc
->col_offset
= (int *) xcrealloc (fc
->col_offset
, fc
->ncols
, sizeof (int));
6136 /* PR 17512: file:002-10025-0.005. */
6137 if (fc
->col_type
== NULL
|| fc
->col_offset
== NULL
)
6139 error (_("Out of memory allocating %u columns in dwarf frame arrays\n"),
6145 while (prev
< fc
->ncols
)
6147 fc
->col_type
[prev
] = DW_CFA_unreferenced
;
6148 fc
->col_offset
[prev
] = 0;
6154 static const char *const dwarf_regnames_i386
[] =
6156 "eax", "ecx", "edx", "ebx", /* 0 - 3 */
6157 "esp", "ebp", "esi", "edi", /* 4 - 7 */
6158 "eip", "eflags", NULL
, /* 8 - 10 */
6159 "st0", "st1", "st2", "st3", /* 11 - 14 */
6160 "st4", "st5", "st6", "st7", /* 15 - 18 */
6161 NULL
, NULL
, /* 19 - 20 */
6162 "xmm0", "xmm1", "xmm2", "xmm3", /* 21 - 24 */
6163 "xmm4", "xmm5", "xmm6", "xmm7", /* 25 - 28 */
6164 "mm0", "mm1", "mm2", "mm3", /* 29 - 32 */
6165 "mm4", "mm5", "mm6", "mm7", /* 33 - 36 */
6166 "fcw", "fsw", "mxcsr", /* 37 - 39 */
6167 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
, /* 40 - 47 */
6168 "tr", "ldtr", /* 48 - 49 */
6169 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 50 - 57 */
6170 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 58 - 65 */
6171 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 66 - 73 */
6172 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 74 - 81 */
6173 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 82 - 89 */
6174 NULL
, NULL
, NULL
, /* 90 - 92 */
6175 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7" /* 93 - 100 */
6178 static const char *const dwarf_regnames_iamcu
[] =
6180 "eax", "ecx", "edx", "ebx", /* 0 - 3 */
6181 "esp", "ebp", "esi", "edi", /* 4 - 7 */
6182 "eip", "eflags", NULL
, /* 8 - 10 */
6183 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 11 - 18 */
6184 NULL
, NULL
, /* 19 - 20 */
6185 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 21 - 28 */
6186 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 29 - 36 */
6187 NULL
, NULL
, NULL
, /* 37 - 39 */
6188 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
, /* 40 - 47 */
6189 "tr", "ldtr", /* 48 - 49 */
6190 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 50 - 57 */
6191 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 58 - 65 */
6192 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 66 - 73 */
6193 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 74 - 81 */
6194 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 82 - 89 */
6195 NULL
, NULL
, NULL
, /* 90 - 92 */
6196 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
/* 93 - 100 */
6200 init_dwarf_regnames_i386 (void)
6202 dwarf_regnames
= dwarf_regnames_i386
;
6203 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_i386
);
6207 init_dwarf_regnames_iamcu (void)
6209 dwarf_regnames
= dwarf_regnames_iamcu
;
6210 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_iamcu
);
6213 static const char *const dwarf_regnames_x86_64
[] =
6215 "rax", "rdx", "rcx", "rbx",
6216 "rsi", "rdi", "rbp", "rsp",
6217 "r8", "r9", "r10", "r11",
6218 "r12", "r13", "r14", "r15",
6220 "xmm0", "xmm1", "xmm2", "xmm3",
6221 "xmm4", "xmm5", "xmm6", "xmm7",
6222 "xmm8", "xmm9", "xmm10", "xmm11",
6223 "xmm12", "xmm13", "xmm14", "xmm15",
6224 "st0", "st1", "st2", "st3",
6225 "st4", "st5", "st6", "st7",
6226 "mm0", "mm1", "mm2", "mm3",
6227 "mm4", "mm5", "mm6", "mm7",
6229 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
,
6230 "fs.base", "gs.base", NULL
, NULL
,
6232 "mxcsr", "fcw", "fsw",
6233 "xmm16", "xmm17", "xmm18", "xmm19",
6234 "xmm20", "xmm21", "xmm22", "xmm23",
6235 "xmm24", "xmm25", "xmm26", "xmm27",
6236 "xmm28", "xmm29", "xmm30", "xmm31",
6237 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 83 - 90 */
6238 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 91 - 98 */
6239 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 99 - 106 */
6240 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 107 - 114 */
6241 NULL
, NULL
, NULL
, /* 115 - 117 */
6242 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7"
6246 init_dwarf_regnames_x86_64 (void)
6248 dwarf_regnames
= dwarf_regnames_x86_64
;
6249 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_x86_64
);
6252 static const char *const dwarf_regnames_aarch64
[] =
6254 "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7",
6255 "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15",
6256 "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23",
6257 "x24", "x25", "x26", "x27", "x28", "x29", "x30", "sp",
6258 NULL
, "elr", NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
6259 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
6260 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
6261 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
6262 "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7",
6263 "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15",
6264 "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23",
6265 "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31",
6269 init_dwarf_regnames_aarch64 (void)
6271 dwarf_regnames
= dwarf_regnames_aarch64
;
6272 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_aarch64
);
6275 static const char *const dwarf_regnames_s390
[] =
6277 /* Avoid saying "r5 (r5)", so omit the names of r0-r15. */
6278 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
6279 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
6280 "f0", "f2", "f4", "f6", "f1", "f3", "f5", "f7",
6281 "f8", "f10", "f12", "f14", "f9", "f11", "f13", "f15",
6282 "cr0", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7",
6283 "cr8", "cr9", "cr10", "cr11", "cr12", "cr13", "cr14", "cr15",
6284 "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7",
6285 "a8", "a9", "a10", "a11", "a12", "a13", "a14", "a15",
6288 "v16", "v18", "v20", "v22", "v17", "v19", "v21", "v23",
6289 "v24", "v26", "v28", "v30", "v25", "v27", "v29", "v31",
6293 init_dwarf_regnames_s390 (void)
6295 dwarf_regnames
= dwarf_regnames_s390
;
6296 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_s390
);
6300 init_dwarf_regnames (unsigned int e_machine
)
6305 init_dwarf_regnames_i386 ();
6309 init_dwarf_regnames_iamcu ();
6315 init_dwarf_regnames_x86_64 ();
6319 init_dwarf_regnames_aarch64 ();
6323 init_dwarf_regnames_s390 ();
6332 regname (unsigned int regno
, int row
)
6334 static char reg
[64];
6336 && regno
< dwarf_regnames_count
6337 && dwarf_regnames
[regno
] != NULL
)
6340 return dwarf_regnames
[regno
];
6341 snprintf (reg
, sizeof (reg
), "r%d (%s)", regno
,
6342 dwarf_regnames
[regno
]);
6345 snprintf (reg
, sizeof (reg
), "r%d", regno
);
6350 frame_display_row (Frame_Chunk
*fc
, int *need_col_headers
, unsigned int *max_regs
)
6355 if (*max_regs
!= fc
->ncols
)
6356 *max_regs
= fc
->ncols
;
6358 if (*need_col_headers
)
6360 static const char *sloc
= " LOC";
6362 *need_col_headers
= 0;
6364 printf ("%-*s CFA ", eh_addr_size
* 2, sloc
);
6366 for (r
= 0; r
< *max_regs
; r
++)
6367 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
6372 printf ("%-5s ", regname (r
, 1));
6378 print_dwarf_vma (fc
->pc_begin
, eh_addr_size
);
6380 strcpy (tmp
, "exp");
6382 sprintf (tmp
, "%s%+d", regname (fc
->cfa_reg
, 1), (int) fc
->cfa_offset
);
6383 printf ("%-8s ", tmp
);
6385 for (r
= 0; r
< fc
->ncols
; r
++)
6387 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
6389 switch (fc
->col_type
[r
])
6391 case DW_CFA_undefined
:
6394 case DW_CFA_same_value
:
6398 sprintf (tmp
, "c%+d", fc
->col_offset
[r
]);
6400 case DW_CFA_val_offset
:
6401 sprintf (tmp
, "v%+d", fc
->col_offset
[r
]);
6403 case DW_CFA_register
:
6404 sprintf (tmp
, "%s", regname (fc
->col_offset
[r
], 0));
6406 case DW_CFA_expression
:
6407 strcpy (tmp
, "exp");
6409 case DW_CFA_val_expression
:
6410 strcpy (tmp
, "vexp");
6413 strcpy (tmp
, "n/a");
6416 printf ("%-5s ", tmp
);
6422 #define GET(VAR, N) SAFE_BYTE_GET_AND_INC (VAR, start, N, end)
6423 #define LEB() read_uleb128 (start, & length_return, end); start += length_return
6424 #define SLEB() read_sleb128 (start, & length_return, end); start += length_return
6426 static unsigned char *
6427 read_cie (unsigned char *start
, unsigned char *end
,
6428 Frame_Chunk
**p_cie
, int *p_version
,
6429 unsigned long *p_aug_len
, unsigned char **p_aug
)
6433 unsigned int length_return
;
6434 unsigned char *augmentation_data
= NULL
;
6435 unsigned long augmentation_data_len
= 0;
6438 /* PR 17512: file: 001-228113-0.004. */
6442 fc
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
6443 memset (fc
, 0, sizeof (Frame_Chunk
));
6445 fc
->col_type
= (short int *) xmalloc (sizeof (short int));
6446 fc
->col_offset
= (int *) xmalloc (sizeof (int));
6450 fc
->augmentation
= (char *) start
;
6451 /* PR 17512: file: 001-228113-0.004.
6452 Skip past augmentation name, but avoid running off the end of the data. */
6454 if (* start
++ == '\0')
6458 warn (_("No terminator for augmentation name\n"));
6462 if (strcmp (fc
->augmentation
, "eh") == 0)
6463 start
+= eh_addr_size
;
6467 GET (fc
->ptr_size
, 1);
6468 if (fc
->ptr_size
< 1 || fc
->ptr_size
> 8)
6470 warn (_("Invalid pointer size (%d) in CIE data\n"), fc
->ptr_size
);
6474 GET (fc
->segment_size
, 1);
6475 /* PR 17512: file: e99d2804. */
6476 if (fc
->segment_size
> 8 || fc
->segment_size
+ fc
->ptr_size
> 8)
6478 warn (_("Invalid segment size (%d) in CIE data\n"), fc
->segment_size
);
6482 eh_addr_size
= fc
->ptr_size
;
6486 fc
->ptr_size
= eh_addr_size
;
6487 fc
->segment_size
= 0;
6489 fc
->code_factor
= LEB ();
6490 fc
->data_factor
= SLEB ();
6500 if (fc
->augmentation
[0] == 'z')
6502 augmentation_data_len
= LEB ();
6503 augmentation_data
= start
;
6504 start
+= augmentation_data_len
;
6505 /* PR 17512: file: 11042-2589-0.004. */
6508 warn (_("Augmentation data too long: 0x%lx\n"), augmentation_data_len
);
6513 if (augmentation_data_len
)
6517 unsigned char *qend
;
6519 p
= (unsigned char *) fc
->augmentation
+ 1;
6520 q
= augmentation_data
;
6521 qend
= q
+ augmentation_data_len
;
6523 /* PR 17531: file: 015adfaa. */
6526 warn (_("Negative augmentation data length: 0x%lx"), augmentation_data_len
);
6527 augmentation_data_len
= 0;
6530 while (p
< end
&& q
< augmentation_data
+ augmentation_data_len
)
6535 q
+= 1 + size_of_encoded_value (*q
);
6537 fc
->fde_encoding
= *q
++;
6544 /* Note - it is OK if this loop terminates with q < qend.
6545 Padding may have been inserted to align the end of the CIE. */
6550 *p_version
= version
;
6553 *p_aug_len
= augmentation_data_len
;
6554 *p_aug
= augmentation_data
;
6560 display_debug_frames (struct dwarf_section
*section
,
6561 void *file ATTRIBUTE_UNUSED
)
6563 unsigned char *start
= section
->start
;
6564 unsigned char *end
= start
+ section
->size
;
6565 unsigned char *section_start
= start
;
6566 Frame_Chunk
*chunks
= 0, *forward_refs
= 0;
6567 Frame_Chunk
*remembered_state
= 0;
6569 int is_eh
= strcmp (section
->name
, ".eh_frame") == 0;
6570 unsigned int length_return
;
6571 unsigned int max_regs
= 0;
6572 const char *bad_reg
= _("bad register: ");
6573 unsigned int saved_eh_addr_size
= eh_addr_size
;
6575 printf (_("Contents of the %s section:\n"), section
->name
);
6579 unsigned char *saved_start
;
6580 unsigned char *block_end
;
6585 int need_col_headers
= 1;
6586 unsigned char *augmentation_data
= NULL
;
6587 unsigned long augmentation_data_len
= 0;
6588 unsigned int encoded_ptr_size
= saved_eh_addr_size
;
6589 unsigned int offset_size
;
6590 unsigned int initial_length_size
;
6591 bfd_boolean all_nops
;
6593 saved_start
= start
;
6595 SAFE_BYTE_GET_AND_INC (length
, start
, 4, end
);
6599 printf ("\n%08lx ZERO terminator\n\n",
6600 (unsigned long)(saved_start
- section_start
));
6601 /* Skip any zero terminators that directly follow.
6602 A corrupt section size could have loaded a whole
6603 slew of zero filled memory bytes. eg
6604 PR 17512: file: 070-19381-0.004. */
6605 while (start
< end
&& * start
== 0)
6610 if (length
== 0xffffffff)
6612 SAFE_BYTE_GET_AND_INC (length
, start
, 8, end
);
6614 initial_length_size
= 12;
6619 initial_length_size
= 4;
6622 block_end
= saved_start
+ length
+ initial_length_size
;
6623 if (block_end
> end
|| block_end
< start
)
6625 warn ("Invalid length 0x%s in FDE at %#08lx\n",
6626 dwarf_vmatoa_1 (NULL
, length
, offset_size
),
6627 (unsigned long) (saved_start
- section_start
));
6631 SAFE_BYTE_GET_AND_INC (cie_id
, start
, offset_size
, end
);
6633 if (is_eh
? (cie_id
== 0) : ((offset_size
== 4 && cie_id
== DW_CIE_ID
)
6634 || (offset_size
== 8 && cie_id
== DW64_CIE_ID
)))
6639 start
= read_cie (start
, end
, &cie
, &version
,
6640 &augmentation_data_len
, &augmentation_data
);
6641 /* PR 17512: file: 027-135133-0.005. */
6648 fc
->chunk_start
= saved_start
;
6649 mreg
= max_regs
> 0 ? max_regs
- 1 : 0;
6652 if (frame_need_space (fc
, mreg
) < 0)
6654 if (fc
->fde_encoding
)
6655 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
6657 printf ("\n%08lx ", (unsigned long) (saved_start
- section_start
));
6658 print_dwarf_vma (length
, fc
->ptr_size
);
6659 print_dwarf_vma (cie_id
, offset_size
);
6661 if (do_debug_frames_interp
)
6663 printf ("CIE \"%s\" cf=%d df=%d ra=%d\n", fc
->augmentation
,
6664 fc
->code_factor
, fc
->data_factor
, fc
->ra
);
6669 printf (" Version: %d\n", version
);
6670 printf (" Augmentation: \"%s\"\n", fc
->augmentation
);
6673 printf (" Pointer Size: %u\n", fc
->ptr_size
);
6674 printf (" Segment Size: %u\n", fc
->segment_size
);
6676 printf (" Code alignment factor: %u\n", fc
->code_factor
);
6677 printf (" Data alignment factor: %d\n", fc
->data_factor
);
6678 printf (" Return address column: %d\n", fc
->ra
);
6680 if (augmentation_data_len
)
6684 printf (" Augmentation data: ");
6685 for (i
= 0; i
< augmentation_data_len
; ++i
)
6686 /* FIXME: If do_wide is FALSE, then we should
6687 add carriage returns at 80 columns... */
6688 printf (" %02x", augmentation_data
[i
]);
6696 unsigned char *look_for
;
6697 static Frame_Chunk fde_fc
;
6698 unsigned long segment_selector
;
6702 dwarf_vma sign
= (dwarf_vma
) 1 << (offset_size
* 8 - 1);
6703 look_for
= start
- 4 - ((cie_id
^ sign
) - sign
);
6706 look_for
= section_start
+ cie_id
;
6708 if (look_for
<= saved_start
)
6710 for (cie
= chunks
; cie
; cie
= cie
->next
)
6711 if (cie
->chunk_start
== look_for
)
6716 for (cie
= forward_refs
; cie
; cie
= cie
->next
)
6717 if (cie
->chunk_start
== look_for
)
6721 unsigned int off_size
;
6722 unsigned char *cie_scan
;
6724 cie_scan
= look_for
;
6726 SAFE_BYTE_GET_AND_INC (length
, cie_scan
, 4, end
);
6727 if (length
== 0xffffffff)
6729 SAFE_BYTE_GET_AND_INC (length
, cie_scan
, 8, end
);
6736 SAFE_BYTE_GET_AND_INC (c_id
, cie_scan
, off_size
, end
);
6739 : ((off_size
== 4 && c_id
== DW_CIE_ID
)
6740 || (off_size
== 8 && c_id
== DW64_CIE_ID
)))
6745 read_cie (cie_scan
, end
, &cie
, &version
,
6746 &augmentation_data_len
, &augmentation_data
);
6747 /* PR 17512: file: 3450-2098-0.004. */
6750 warn (_("Failed to read CIE information\n"));
6753 cie
->next
= forward_refs
;
6755 cie
->chunk_start
= look_for
;
6756 mreg
= max_regs
> 0 ? max_regs
- 1 : 0;
6759 if (frame_need_space (cie
, mreg
) < 0)
6761 warn (_("Invalid max register\n"));
6764 if (cie
->fde_encoding
)
6766 = size_of_encoded_value (cie
->fde_encoding
);
6773 memset (fc
, 0, sizeof (Frame_Chunk
));
6777 warn ("Invalid CIE pointer 0x%s in FDE at %#08lx\n",
6778 dwarf_vmatoa_1 (NULL
, cie_id
, offset_size
),
6779 (unsigned long) (saved_start
- section_start
));
6781 fc
->col_type
= (short int *) xmalloc (sizeof (short int));
6782 fc
->col_offset
= (int *) xmalloc (sizeof (int));
6783 if (frame_need_space (fc
, max_regs
> 0 ? max_regs
- 1 : 0) < 0)
6785 warn (_("Invalid max register\n"));
6789 fc
->augmentation
= "";
6790 fc
->fde_encoding
= 0;
6791 fc
->ptr_size
= eh_addr_size
;
6792 fc
->segment_size
= 0;
6796 fc
->ncols
= cie
->ncols
;
6797 fc
->col_type
= (short int *) xcmalloc (fc
->ncols
, sizeof (short int));
6798 fc
->col_offset
= (int *) xcmalloc (fc
->ncols
, sizeof (int));
6799 memcpy (fc
->col_type
, cie
->col_type
, fc
->ncols
* sizeof (short int));
6800 memcpy (fc
->col_offset
, cie
->col_offset
, fc
->ncols
* sizeof (int));
6801 fc
->augmentation
= cie
->augmentation
;
6802 fc
->ptr_size
= cie
->ptr_size
;
6803 eh_addr_size
= cie
->ptr_size
;
6804 fc
->segment_size
= cie
->segment_size
;
6805 fc
->code_factor
= cie
->code_factor
;
6806 fc
->data_factor
= cie
->data_factor
;
6807 fc
->cfa_reg
= cie
->cfa_reg
;
6808 fc
->cfa_offset
= cie
->cfa_offset
;
6810 if (frame_need_space (fc
, max_regs
> 0 ? max_regs
- 1: 0) < 0)
6812 warn (_("Invalid max register\n"));
6815 fc
->fde_encoding
= cie
->fde_encoding
;
6818 if (fc
->fde_encoding
)
6819 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
6821 segment_selector
= 0;
6822 if (fc
->segment_size
)
6824 if (fc
->segment_size
> sizeof (segment_selector
))
6826 /* PR 17512: file: 9e196b3e. */
6827 warn (_("Probably corrupt segment size: %d - using 4 instead\n"), fc
->segment_size
);
6828 fc
->segment_size
= 4;
6830 SAFE_BYTE_GET_AND_INC (segment_selector
, start
, fc
->segment_size
, end
);
6833 fc
->pc_begin
= get_encoded_value (&start
, fc
->fde_encoding
, section
, end
);
6835 /* FIXME: It appears that sometimes the final pc_range value is
6836 encoded in less than encoded_ptr_size bytes. See the x86_64
6837 run of the "objcopy on compressed debug sections" test for an
6839 SAFE_BYTE_GET_AND_INC (fc
->pc_range
, start
, encoded_ptr_size
, end
);
6841 if (cie
->augmentation
[0] == 'z')
6843 augmentation_data_len
= LEB ();
6844 augmentation_data
= start
;
6845 start
+= augmentation_data_len
;
6846 /* PR 17512: file: 722-8446-0.004. */
6847 if (start
>= end
|| ((signed long) augmentation_data_len
) < 0)
6849 warn (_("Corrupt augmentation data length: %lx\n"),
6850 augmentation_data_len
);
6852 augmentation_data
= NULL
;
6853 augmentation_data_len
= 0;
6857 printf ("\n%08lx %s %s FDE cie=%08lx pc=",
6858 (unsigned long)(saved_start
- section_start
),
6859 dwarf_vmatoa_1 (NULL
, length
, fc
->ptr_size
),
6860 dwarf_vmatoa_1 (NULL
, cie_id
, offset_size
),
6861 (unsigned long)(cie
->chunk_start
- section_start
));
6863 if (fc
->segment_size
)
6864 printf ("%04lx:", segment_selector
);
6867 dwarf_vmatoa_1 (NULL
, fc
->pc_begin
, fc
->ptr_size
),
6868 dwarf_vmatoa_1 (NULL
, fc
->pc_begin
+ fc
->pc_range
, fc
->ptr_size
));
6870 if (! do_debug_frames_interp
&& augmentation_data_len
)
6874 printf (" Augmentation data: ");
6875 for (i
= 0; i
< augmentation_data_len
; ++i
)
6876 printf (" %02x", augmentation_data
[i
]);
6882 /* At this point, fc is the current chunk, cie (if any) is set, and
6883 we're about to interpret instructions for the chunk. */
6884 /* ??? At present we need to do this always, since this sizes the
6885 fc->col_type and fc->col_offset arrays, which we write into always.
6886 We should probably split the interpreted and non-interpreted bits
6887 into two different routines, since there's so much that doesn't
6888 really overlap between them. */
6889 if (1 || do_debug_frames_interp
)
6891 /* Start by making a pass over the chunk, allocating storage
6892 and taking note of what registers are used. */
6893 unsigned char *tmp
= start
;
6895 while (start
< block_end
)
6897 unsigned int reg
, op
, opa
;
6899 unsigned char * new_start
;
6906 /* Warning: if you add any more cases to this switch, be
6907 sure to add them to the corresponding switch below. */
6910 case DW_CFA_advance_loc
:
6914 if (frame_need_space (fc
, opa
) >= 0)
6915 fc
->col_type
[opa
] = DW_CFA_undefined
;
6917 case DW_CFA_restore
:
6918 if (frame_need_space (fc
, opa
) >= 0)
6919 fc
->col_type
[opa
] = DW_CFA_undefined
;
6921 case DW_CFA_set_loc
:
6922 start
+= encoded_ptr_size
;
6924 case DW_CFA_advance_loc1
:
6927 case DW_CFA_advance_loc2
:
6930 case DW_CFA_advance_loc4
:
6933 case DW_CFA_offset_extended
:
6934 case DW_CFA_val_offset
:
6935 reg
= LEB (); LEB ();
6936 if (frame_need_space (fc
, reg
) >= 0)
6937 fc
->col_type
[reg
] = DW_CFA_undefined
;
6939 case DW_CFA_restore_extended
:
6941 if (frame_need_space (fc
, reg
) >= 0)
6942 fc
->col_type
[reg
] = DW_CFA_undefined
;
6944 case DW_CFA_undefined
:
6946 if (frame_need_space (fc
, reg
) >= 0)
6947 fc
->col_type
[reg
] = DW_CFA_undefined
;
6949 case DW_CFA_same_value
:
6951 if (frame_need_space (fc
, reg
) >= 0)
6952 fc
->col_type
[reg
] = DW_CFA_undefined
;
6954 case DW_CFA_register
:
6955 reg
= LEB (); LEB ();
6956 if (frame_need_space (fc
, reg
) >= 0)
6957 fc
->col_type
[reg
] = DW_CFA_undefined
;
6959 case DW_CFA_def_cfa
:
6962 case DW_CFA_def_cfa_register
:
6965 case DW_CFA_def_cfa_offset
:
6968 case DW_CFA_def_cfa_expression
:
6970 new_start
= start
+ temp
;
6971 if (new_start
< start
)
6973 warn (_("Corrupt CFA_def expression value: %lu\n"), temp
);
6979 case DW_CFA_expression
:
6980 case DW_CFA_val_expression
:
6983 new_start
= start
+ temp
;
6984 if (new_start
< start
)
6986 /* PR 17512: file:306-192417-0.005. */
6987 warn (_("Corrupt CFA expression value: %lu\n"), temp
);
6992 if (frame_need_space (fc
, reg
) >= 0)
6993 fc
->col_type
[reg
] = DW_CFA_undefined
;
6995 case DW_CFA_offset_extended_sf
:
6996 case DW_CFA_val_offset_sf
:
6997 reg
= LEB (); SLEB ();
6998 if (frame_need_space (fc
, reg
) >= 0)
6999 fc
->col_type
[reg
] = DW_CFA_undefined
;
7001 case DW_CFA_def_cfa_sf
:
7004 case DW_CFA_def_cfa_offset_sf
:
7007 case DW_CFA_MIPS_advance_loc8
:
7010 case DW_CFA_GNU_args_size
:
7013 case DW_CFA_GNU_negative_offset_extended
:
7014 reg
= LEB (); LEB ();
7015 if (frame_need_space (fc
, reg
) >= 0)
7016 fc
->col_type
[reg
] = DW_CFA_undefined
;
7027 /* Now we know what registers are used, make a second pass over
7028 the chunk, this time actually printing out the info. */
7030 while (start
< block_end
)
7032 unsigned char * tmp
;
7034 unsigned long ul
, reg
, roffs
;
7038 const char *reg_prefix
= "";
7045 /* Make a note if something other than DW_CFA_nop happens. */
7046 if (op
!= DW_CFA_nop
)
7049 /* Warning: if you add any more cases to this switch, be
7050 sure to add them to the corresponding switch above. */
7053 case DW_CFA_advance_loc
:
7054 if (do_debug_frames_interp
)
7055 frame_display_row (fc
, &need_col_headers
, &max_regs
);
7057 printf (" DW_CFA_advance_loc: %d to %s\n",
7058 opa
* fc
->code_factor
,
7059 dwarf_vmatoa_1 (NULL
,
7060 fc
->pc_begin
+ opa
* fc
->code_factor
,
7062 fc
->pc_begin
+= opa
* fc
->code_factor
;
7067 if (opa
>= (unsigned int) fc
->ncols
)
7068 reg_prefix
= bad_reg
;
7069 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
7070 printf (" DW_CFA_offset: %s%s at cfa%+ld\n",
7071 reg_prefix
, regname (opa
, 0),
7072 roffs
* fc
->data_factor
);
7073 if (*reg_prefix
== '\0')
7075 fc
->col_type
[opa
] = DW_CFA_offset
;
7076 fc
->col_offset
[opa
] = roffs
* fc
->data_factor
;
7080 case DW_CFA_restore
:
7081 if (opa
>= (unsigned int) fc
->ncols
)
7082 reg_prefix
= bad_reg
;
7083 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
7084 printf (" DW_CFA_restore: %s%s\n",
7085 reg_prefix
, regname (opa
, 0));
7086 if (*reg_prefix
!= '\0')
7089 if (opa
>= (unsigned int) cie
->ncols
7090 || (do_debug_frames_interp
7091 && cie
->col_type
[opa
] == DW_CFA_unreferenced
))
7093 fc
->col_type
[opa
] = DW_CFA_undefined
;
7094 fc
->col_offset
[opa
] = 0;
7098 fc
->col_type
[opa
] = cie
->col_type
[opa
];
7099 fc
->col_offset
[opa
] = cie
->col_offset
[opa
];
7103 case DW_CFA_set_loc
:
7104 vma
= get_encoded_value (&start
, fc
->fde_encoding
, section
, block_end
);
7105 if (do_debug_frames_interp
)
7106 frame_display_row (fc
, &need_col_headers
, &max_regs
);
7108 printf (" DW_CFA_set_loc: %s\n",
7109 dwarf_vmatoa_1 (NULL
, vma
, fc
->ptr_size
));
7113 case DW_CFA_advance_loc1
:
7114 SAFE_BYTE_GET_AND_INC (ofs
, start
, 1, end
);
7115 if (do_debug_frames_interp
)
7116 frame_display_row (fc
, &need_col_headers
, &max_regs
);
7118 printf (" DW_CFA_advance_loc1: %ld to %s\n",
7119 (unsigned long) (ofs
* fc
->code_factor
),
7120 dwarf_vmatoa_1 (NULL
,
7121 fc
->pc_begin
+ ofs
* fc
->code_factor
,
7123 fc
->pc_begin
+= ofs
* fc
->code_factor
;
7126 case DW_CFA_advance_loc2
:
7127 SAFE_BYTE_GET_AND_INC (ofs
, start
, 2, block_end
);
7128 if (do_debug_frames_interp
)
7129 frame_display_row (fc
, &need_col_headers
, &max_regs
);
7131 printf (" DW_CFA_advance_loc2: %ld to %s\n",
7132 (unsigned long) (ofs
* fc
->code_factor
),
7133 dwarf_vmatoa_1 (NULL
,
7134 fc
->pc_begin
+ ofs
* fc
->code_factor
,
7136 fc
->pc_begin
+= ofs
* fc
->code_factor
;
7139 case DW_CFA_advance_loc4
:
7140 SAFE_BYTE_GET_AND_INC (ofs
, start
, 4, block_end
);
7141 if (do_debug_frames_interp
)
7142 frame_display_row (fc
, &need_col_headers
, &max_regs
);
7144 printf (" DW_CFA_advance_loc4: %ld to %s\n",
7145 (unsigned long) (ofs
* fc
->code_factor
),
7146 dwarf_vmatoa_1 (NULL
,
7147 fc
->pc_begin
+ ofs
* fc
->code_factor
,
7149 fc
->pc_begin
+= ofs
* fc
->code_factor
;
7152 case DW_CFA_offset_extended
:
7155 if (reg
>= (unsigned int) fc
->ncols
)
7156 reg_prefix
= bad_reg
;
7157 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
7158 printf (" DW_CFA_offset_extended: %s%s at cfa%+ld\n",
7159 reg_prefix
, regname (reg
, 0),
7160 roffs
* fc
->data_factor
);
7161 if (*reg_prefix
== '\0')
7163 fc
->col_type
[reg
] = DW_CFA_offset
;
7164 fc
->col_offset
[reg
] = roffs
* fc
->data_factor
;
7168 case DW_CFA_val_offset
:
7171 if (reg
>= (unsigned int) fc
->ncols
)
7172 reg_prefix
= bad_reg
;
7173 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
7174 printf (" DW_CFA_val_offset: %s%s is cfa%+ld\n",
7175 reg_prefix
, regname (reg
, 0),
7176 roffs
* fc
->data_factor
);
7177 if (*reg_prefix
== '\0')
7179 fc
->col_type
[reg
] = DW_CFA_val_offset
;
7180 fc
->col_offset
[reg
] = roffs
* fc
->data_factor
;
7184 case DW_CFA_restore_extended
:
7186 if (reg
>= (unsigned int) fc
->ncols
)
7187 reg_prefix
= bad_reg
;
7188 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
7189 printf (" DW_CFA_restore_extended: %s%s\n",
7190 reg_prefix
, regname (reg
, 0));
7191 if (*reg_prefix
!= '\0')
7194 if (reg
>= (unsigned int) cie
->ncols
)
7196 fc
->col_type
[reg
] = DW_CFA_undefined
;
7197 fc
->col_offset
[reg
] = 0;
7201 fc
->col_type
[reg
] = cie
->col_type
[reg
];
7202 fc
->col_offset
[reg
] = cie
->col_offset
[reg
];
7206 case DW_CFA_undefined
:
7208 if (reg
>= (unsigned int) fc
->ncols
)
7209 reg_prefix
= bad_reg
;
7210 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
7211 printf (" DW_CFA_undefined: %s%s\n",
7212 reg_prefix
, regname (reg
, 0));
7213 if (*reg_prefix
== '\0')
7215 fc
->col_type
[reg
] = DW_CFA_undefined
;
7216 fc
->col_offset
[reg
] = 0;
7220 case DW_CFA_same_value
:
7222 if (reg
>= (unsigned int) fc
->ncols
)
7223 reg_prefix
= bad_reg
;
7224 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
7225 printf (" DW_CFA_same_value: %s%s\n",
7226 reg_prefix
, regname (reg
, 0));
7227 if (*reg_prefix
== '\0')
7229 fc
->col_type
[reg
] = DW_CFA_same_value
;
7230 fc
->col_offset
[reg
] = 0;
7234 case DW_CFA_register
:
7237 if (reg
>= (unsigned int) fc
->ncols
)
7238 reg_prefix
= bad_reg
;
7239 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
7241 printf (" DW_CFA_register: %s%s in ",
7242 reg_prefix
, regname (reg
, 0));
7243 puts (regname (roffs
, 0));
7245 if (*reg_prefix
== '\0')
7247 fc
->col_type
[reg
] = DW_CFA_register
;
7248 fc
->col_offset
[reg
] = roffs
;
7252 case DW_CFA_remember_state
:
7253 if (! do_debug_frames_interp
)
7254 printf (" DW_CFA_remember_state\n");
7255 rs
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
7256 rs
->cfa_offset
= fc
->cfa_offset
;
7257 rs
->cfa_reg
= fc
->cfa_reg
;
7259 rs
->cfa_exp
= fc
->cfa_exp
;
7260 rs
->ncols
= fc
->ncols
;
7261 rs
->col_type
= (short int *) xcmalloc (rs
->ncols
,
7262 sizeof (* rs
->col_type
));
7263 rs
->col_offset
= (int *) xcmalloc (rs
->ncols
, sizeof (* rs
->col_offset
));
7264 memcpy (rs
->col_type
, fc
->col_type
, rs
->ncols
* sizeof (* fc
->col_type
));
7265 memcpy (rs
->col_offset
, fc
->col_offset
, rs
->ncols
* sizeof (* fc
->col_offset
));
7266 rs
->next
= remembered_state
;
7267 remembered_state
= rs
;
7270 case DW_CFA_restore_state
:
7271 if (! do_debug_frames_interp
)
7272 printf (" DW_CFA_restore_state\n");
7273 rs
= remembered_state
;
7276 remembered_state
= rs
->next
;
7277 fc
->cfa_offset
= rs
->cfa_offset
;
7278 fc
->cfa_reg
= rs
->cfa_reg
;
7280 fc
->cfa_exp
= rs
->cfa_exp
;
7281 if (frame_need_space (fc
, rs
->ncols
- 1) < 0)
7283 warn (_("Invalid column number in saved frame state\n"));
7287 memcpy (fc
->col_type
, rs
->col_type
, rs
->ncols
* sizeof (* rs
->col_type
));
7288 memcpy (fc
->col_offset
, rs
->col_offset
,
7289 rs
->ncols
* sizeof (* rs
->col_offset
));
7290 free (rs
->col_type
);
7291 free (rs
->col_offset
);
7294 else if (do_debug_frames_interp
)
7295 printf ("Mismatched DW_CFA_restore_state\n");
7298 case DW_CFA_def_cfa
:
7299 fc
->cfa_reg
= LEB ();
7300 fc
->cfa_offset
= LEB ();
7302 if (! do_debug_frames_interp
)
7303 printf (" DW_CFA_def_cfa: %s ofs %d\n",
7304 regname (fc
->cfa_reg
, 0), (int) fc
->cfa_offset
);
7307 case DW_CFA_def_cfa_register
:
7308 fc
->cfa_reg
= LEB ();
7310 if (! do_debug_frames_interp
)
7311 printf (" DW_CFA_def_cfa_register: %s\n",
7312 regname (fc
->cfa_reg
, 0));
7315 case DW_CFA_def_cfa_offset
:
7316 fc
->cfa_offset
= LEB ();
7317 if (! do_debug_frames_interp
)
7318 printf (" DW_CFA_def_cfa_offset: %d\n", (int) fc
->cfa_offset
);
7322 if (! do_debug_frames_interp
)
7323 printf (" DW_CFA_nop\n");
7326 case DW_CFA_def_cfa_expression
:
7328 if (start
>= block_end
|| ul
> (unsigned long) (block_end
- start
))
7330 printf (_(" DW_CFA_def_cfa_expression: <corrupt len %lu>\n"), ul
);
7333 if (! do_debug_frames_interp
)
7335 printf (" DW_CFA_def_cfa_expression (");
7336 decode_location_expression (start
, eh_addr_size
, 0, -1,
7344 case DW_CFA_expression
:
7347 if (reg
>= (unsigned int) fc
->ncols
)
7348 reg_prefix
= bad_reg
;
7349 /* PR 17512: file: 069-133014-0.006. */
7350 /* PR 17512: file: 98c02eb4. */
7352 if (start
>= block_end
|| tmp
> block_end
|| tmp
< start
)
7354 printf (_(" DW_CFA_expression: <corrupt len %lu>\n"), ul
);
7357 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
7359 printf (" DW_CFA_expression: %s%s (",
7360 reg_prefix
, regname (reg
, 0));
7361 decode_location_expression (start
, eh_addr_size
, 0, -1,
7365 if (*reg_prefix
== '\0')
7366 fc
->col_type
[reg
] = DW_CFA_expression
;
7370 case DW_CFA_val_expression
:
7373 if (reg
>= (unsigned int) fc
->ncols
)
7374 reg_prefix
= bad_reg
;
7376 if (start
>= block_end
|| tmp
> block_end
|| tmp
< start
)
7378 printf (" DW_CFA_val_expression: <corrupt len %lu>\n", ul
);
7381 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
7383 printf (" DW_CFA_val_expression: %s%s (",
7384 reg_prefix
, regname (reg
, 0));
7385 decode_location_expression (start
, eh_addr_size
, 0, -1,
7389 if (*reg_prefix
== '\0')
7390 fc
->col_type
[reg
] = DW_CFA_val_expression
;
7394 case DW_CFA_offset_extended_sf
:
7397 if (frame_need_space (fc
, reg
) < 0)
7398 reg_prefix
= bad_reg
;
7399 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
7400 printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+ld\n",
7401 reg_prefix
, regname (reg
, 0),
7402 (long)(l
* fc
->data_factor
));
7403 if (*reg_prefix
== '\0')
7405 fc
->col_type
[reg
] = DW_CFA_offset
;
7406 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
7410 case DW_CFA_val_offset_sf
:
7413 if (frame_need_space (fc
, reg
) < 0)
7414 reg_prefix
= bad_reg
;
7415 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
7416 printf (" DW_CFA_val_offset_sf: %s%s is cfa%+ld\n",
7417 reg_prefix
, regname (reg
, 0),
7418 (long)(l
* fc
->data_factor
));
7419 if (*reg_prefix
== '\0')
7421 fc
->col_type
[reg
] = DW_CFA_val_offset
;
7422 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
7426 case DW_CFA_def_cfa_sf
:
7427 fc
->cfa_reg
= LEB ();
7428 fc
->cfa_offset
= SLEB ();
7429 fc
->cfa_offset
= fc
->cfa_offset
* fc
->data_factor
;
7431 if (! do_debug_frames_interp
)
7432 printf (" DW_CFA_def_cfa_sf: %s ofs %d\n",
7433 regname (fc
->cfa_reg
, 0), (int) fc
->cfa_offset
);
7436 case DW_CFA_def_cfa_offset_sf
:
7437 fc
->cfa_offset
= SLEB ();
7438 fc
->cfa_offset
*= fc
->data_factor
;
7439 if (! do_debug_frames_interp
)
7440 printf (" DW_CFA_def_cfa_offset_sf: %d\n", (int) fc
->cfa_offset
);
7443 case DW_CFA_MIPS_advance_loc8
:
7444 SAFE_BYTE_GET_AND_INC (ofs
, start
, 8, block_end
);
7445 if (do_debug_frames_interp
)
7446 frame_display_row (fc
, &need_col_headers
, &max_regs
);
7448 printf (" DW_CFA_MIPS_advance_loc8: %ld to %s\n",
7449 (unsigned long) (ofs
* fc
->code_factor
),
7450 dwarf_vmatoa_1 (NULL
,
7451 fc
->pc_begin
+ ofs
* fc
->code_factor
,
7453 fc
->pc_begin
+= ofs
* fc
->code_factor
;
7456 case DW_CFA_GNU_window_save
:
7457 if (! do_debug_frames_interp
)
7458 printf (" DW_CFA_GNU_window_save\n");
7461 case DW_CFA_GNU_args_size
:
7463 if (! do_debug_frames_interp
)
7464 printf (" DW_CFA_GNU_args_size: %ld\n", ul
);
7467 case DW_CFA_GNU_negative_offset_extended
:
7470 if (frame_need_space (fc
, reg
) < 0)
7471 reg_prefix
= bad_reg
;
7472 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
7473 printf (" DW_CFA_GNU_negative_offset_extended: %s%s at cfa%+ld\n",
7474 reg_prefix
, regname (reg
, 0),
7475 (long)(l
* fc
->data_factor
));
7476 if (*reg_prefix
== '\0')
7478 fc
->col_type
[reg
] = DW_CFA_offset
;
7479 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
7484 if (op
>= DW_CFA_lo_user
&& op
<= DW_CFA_hi_user
)
7485 printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op
);
7487 warn (_("Unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op
);
7492 /* Interpret the CFA - as long as it is not completely full of NOPs. */
7493 if (do_debug_frames_interp
&& ! all_nops
)
7494 frame_display_row (fc
, &need_col_headers
, &max_regs
);
7497 eh_addr_size
= saved_eh_addr_size
;
7510 display_gdb_index (struct dwarf_section
*section
,
7511 void *file ATTRIBUTE_UNUSED
)
7513 unsigned char *start
= section
->start
;
7515 uint32_t cu_list_offset
, tu_list_offset
;
7516 uint32_t address_table_offset
, symbol_table_offset
, constant_pool_offset
;
7517 unsigned int cu_list_elements
, tu_list_elements
;
7518 unsigned int address_table_size
, symbol_table_slots
;
7519 unsigned char *cu_list
, *tu_list
;
7520 unsigned char *address_table
, *symbol_table
, *constant_pool
;
7523 /* The documentation for the format of this file is in gdb/dwarf2read.c. */
7525 printf (_("Contents of the %s section:\n"), section
->name
);
7527 if (section
->size
< 6 * sizeof (uint32_t))
7529 warn (_("Truncated header in the %s section.\n"), section
->name
);
7533 version
= byte_get_little_endian (start
, 4);
7534 printf (_("Version %ld\n"), (long) version
);
7536 /* Prior versions are obsolete, and future versions may not be
7537 backwards compatible. */
7538 if (version
< 3 || version
> 8)
7540 warn (_("Unsupported version %lu.\n"), (unsigned long) version
);
7544 warn (_("The address table data in version 3 may be wrong.\n"));
7546 warn (_("Version 4 does not support case insensitive lookups.\n"));
7548 warn (_("Version 5 does not include inlined functions.\n"));
7550 warn (_("Version 6 does not include symbol attributes.\n"));
7551 /* Version 7 indices generated by Gold have bad type unit references,
7552 PR binutils/15021. But we don't know if the index was generated by
7553 Gold or not, so to avoid worrying users with gdb-generated indices
7554 we say nothing for version 7 here. */
7556 cu_list_offset
= byte_get_little_endian (start
+ 4, 4);
7557 tu_list_offset
= byte_get_little_endian (start
+ 8, 4);
7558 address_table_offset
= byte_get_little_endian (start
+ 12, 4);
7559 symbol_table_offset
= byte_get_little_endian (start
+ 16, 4);
7560 constant_pool_offset
= byte_get_little_endian (start
+ 20, 4);
7562 if (cu_list_offset
> section
->size
7563 || tu_list_offset
> section
->size
7564 || address_table_offset
> section
->size
7565 || symbol_table_offset
> section
->size
7566 || constant_pool_offset
> section
->size
)
7568 warn (_("Corrupt header in the %s section.\n"), section
->name
);
7572 /* PR 17531: file: 418d0a8a. */
7573 if (tu_list_offset
< cu_list_offset
)
7575 warn (_("TU offset (%x) is less than CU offset (%x)\n"),
7576 tu_list_offset
, cu_list_offset
);
7580 cu_list_elements
= (tu_list_offset
- cu_list_offset
) / 8;
7582 if (address_table_offset
< tu_list_offset
)
7584 warn (_("Address table offset (%x) is less than TU offset (%x)\n"),
7585 address_table_offset
, tu_list_offset
);
7589 tu_list_elements
= (address_table_offset
- tu_list_offset
) / 8;
7591 /* PR 17531: file: 18a47d3d. */
7592 if (symbol_table_offset
< address_table_offset
)
7594 warn (_("Symbol table offset (%xl) is less then Address table offset (%x)\n"),
7595 symbol_table_offset
, address_table_offset
);
7599 address_table_size
= symbol_table_offset
- address_table_offset
;
7601 if (constant_pool_offset
< symbol_table_offset
)
7603 warn (_("Constant pool offset (%x) is less than symbol table offset (%x)\n"),
7604 constant_pool_offset
, symbol_table_offset
);
7608 symbol_table_slots
= (constant_pool_offset
- symbol_table_offset
) / 8;
7610 cu_list
= start
+ cu_list_offset
;
7611 tu_list
= start
+ tu_list_offset
;
7612 address_table
= start
+ address_table_offset
;
7613 symbol_table
= start
+ symbol_table_offset
;
7614 constant_pool
= start
+ constant_pool_offset
;
7616 if (address_table
+ address_table_size
* (2 + 8 + 4) > section
->start
+ section
->size
)
7618 warn (_("Address table extends beyond end of section.\n"));
7622 printf (_("\nCU table:\n"));
7623 for (i
= 0; i
< cu_list_elements
; i
+= 2)
7625 uint64_t cu_offset
= byte_get_little_endian (cu_list
+ i
* 8, 8);
7626 uint64_t cu_length
= byte_get_little_endian (cu_list
+ i
* 8 + 8, 8);
7628 printf (_("[%3u] 0x%lx - 0x%lx\n"), i
/ 2,
7629 (unsigned long) cu_offset
,
7630 (unsigned long) (cu_offset
+ cu_length
- 1));
7633 printf (_("\nTU table:\n"));
7634 for (i
= 0; i
< tu_list_elements
; i
+= 3)
7636 uint64_t tu_offset
= byte_get_little_endian (tu_list
+ i
* 8, 8);
7637 uint64_t type_offset
= byte_get_little_endian (tu_list
+ i
* 8 + 8, 8);
7638 uint64_t signature
= byte_get_little_endian (tu_list
+ i
* 8 + 16, 8);
7640 printf (_("[%3u] 0x%lx 0x%lx "), i
/ 3,
7641 (unsigned long) tu_offset
,
7642 (unsigned long) type_offset
);
7643 print_dwarf_vma (signature
, 8);
7647 printf (_("\nAddress table:\n"));
7648 for (i
= 0; i
< address_table_size
&& i
<= address_table_size
- (2 * 8 + 4);
7651 uint64_t low
= byte_get_little_endian (address_table
+ i
, 8);
7652 uint64_t high
= byte_get_little_endian (address_table
+ i
+ 8, 8);
7653 uint32_t cu_index
= byte_get_little_endian (address_table
+ i
+ 16, 4);
7655 print_dwarf_vma (low
, 8);
7656 print_dwarf_vma (high
, 8);
7657 printf (_("%lu\n"), (unsigned long) cu_index
);
7660 printf (_("\nSymbol table:\n"));
7661 for (i
= 0; i
< symbol_table_slots
; ++i
)
7663 uint32_t name_offset
= byte_get_little_endian (symbol_table
+ i
* 8, 4);
7664 uint32_t cu_vector_offset
= byte_get_little_endian (symbol_table
+ i
* 8 + 4, 4);
7665 uint32_t num_cus
, cu
;
7667 if (name_offset
!= 0
7668 || cu_vector_offset
!= 0)
7671 unsigned char * adr
;
7673 adr
= constant_pool
+ name_offset
;
7674 /* PR 17531: file: 5b7b07ad. */
7675 if (adr
< constant_pool
|| adr
>= section
->start
+ section
->size
)
7677 printf (_("[%3u] <corrupt offset: %x>"), i
, name_offset
);
7678 warn (_("Corrupt name offset of 0x%x found for symbol table slot %d\n"),
7682 printf ("[%3u] %.*s:", i
,
7683 (int) (section
->size
- (constant_pool_offset
+ name_offset
)),
7684 constant_pool
+ name_offset
);
7686 adr
= constant_pool
+ cu_vector_offset
;
7687 if (adr
< constant_pool
|| adr
>= section
->start
+ section
->size
- 3)
7689 printf (_("<invalid CU vector offset: %x>\n"), cu_vector_offset
);
7690 warn (_("Corrupt CU vector offset of 0x%x found for symbol table slot %d\n"),
7691 cu_vector_offset
, i
);
7695 num_cus
= byte_get_little_endian (adr
, 4);
7697 adr
= constant_pool
+ cu_vector_offset
+ 4 + num_cus
* 4;
7698 if (num_cus
* 4 < num_cus
7699 || adr
>= section
->start
+ section
->size
7700 || adr
< constant_pool
)
7702 printf ("<invalid number of CUs: %d>\n", num_cus
);
7703 warn (_("Invalid number of CUs (0x%x) for symbol table slot %d\n"),
7711 for (j
= 0; j
< num_cus
; ++j
)
7714 gdb_index_symbol_kind kind
;
7716 cu
= byte_get_little_endian (constant_pool
+ cu_vector_offset
+ 4 + j
* 4, 4);
7717 is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu
);
7718 kind
= GDB_INDEX_SYMBOL_KIND_VALUE (cu
);
7719 cu
= GDB_INDEX_CU_VALUE (cu
);
7720 /* Convert to TU number if it's for a type unit. */
7721 if (cu
>= cu_list_elements
/ 2)
7722 printf ("%cT%lu", num_cus
> 1 ? '\t' : ' ',
7723 (unsigned long) (cu
- cu_list_elements
/ 2));
7725 printf ("%c%lu", num_cus
> 1 ? '\t' : ' ', (unsigned long) cu
);
7727 printf (" [%s, %s]",
7728 is_static
? _("static") : _("global"),
7729 get_gdb_index_symbol_kind_name (kind
));
7741 /* Pre-allocate enough space for the CU/TU sets needed. */
7744 prealloc_cu_tu_list (unsigned int nshndx
)
7746 if (shndx_pool
== NULL
)
7748 shndx_pool_size
= nshndx
;
7749 shndx_pool_used
= 0;
7750 shndx_pool
= (unsigned int *) xcmalloc (shndx_pool_size
,
7751 sizeof (unsigned int));
7755 shndx_pool_size
= shndx_pool_used
+ nshndx
;
7756 shndx_pool
= (unsigned int *) xcrealloc (shndx_pool
, shndx_pool_size
,
7757 sizeof (unsigned int));
7762 add_shndx_to_cu_tu_entry (unsigned int shndx
)
7764 if (shndx_pool_used
>= shndx_pool_size
)
7766 error (_("Internal error: out of space in the shndx pool.\n"));
7769 shndx_pool
[shndx_pool_used
++] = shndx
;
7773 end_cu_tu_entry (void)
7775 if (shndx_pool_used
>= shndx_pool_size
)
7777 error (_("Internal error: out of space in the shndx pool.\n"));
7780 shndx_pool
[shndx_pool_used
++] = 0;
7783 /* Return the short name of a DWARF section given by a DW_SECT enumerator. */
7786 get_DW_SECT_short_name (unsigned int dw_sect
)
7788 static char buf
[16];
7796 case DW_SECT_ABBREV
:
7802 case DW_SECT_STR_OFFSETS
:
7804 case DW_SECT_MACINFO
:
7812 snprintf (buf
, sizeof (buf
), "%d", dw_sect
);
7816 /* Process a CU or TU index. If DO_DISPLAY is true, print the contents.
7817 These sections are extensions for Fission.
7818 See http://gcc.gnu.org/wiki/DebugFissionDWP. */
7821 process_cu_tu_index (struct dwarf_section
*section
, int do_display
)
7823 unsigned char *phdr
= section
->start
;
7824 unsigned char *limit
= phdr
+ section
->size
;
7825 unsigned char *phash
;
7826 unsigned char *pindex
;
7827 unsigned char *ppool
;
7828 unsigned int version
;
7829 unsigned int ncols
= 0;
7831 unsigned int nslots
;
7834 dwarf_vma signature_high
;
7835 dwarf_vma signature_low
;
7838 /* PR 17512: file: 002-168123-0.004. */
7841 warn (_("Section %s is empty\n"), section
->name
);
7844 /* PR 17512: file: 002-376-0.004. */
7845 if (section
->size
< 24)
7847 warn (_("Section %s is too small to contain a CU/TU header\n"),
7852 SAFE_BYTE_GET (version
, phdr
, 4, limit
);
7854 SAFE_BYTE_GET (ncols
, phdr
+ 4, 4, limit
);
7855 SAFE_BYTE_GET (nused
, phdr
+ 8, 4, limit
);
7856 SAFE_BYTE_GET (nslots
, phdr
+ 12, 4, limit
);
7859 pindex
= phash
+ nslots
* 8;
7860 ppool
= pindex
+ nslots
* 4;
7862 /* PR 17531: file: 45d69832. */
7863 if (pindex
< phash
|| ppool
< phdr
|| (pindex
== phash
&& nslots
!= 0))
7865 warn (_("Section %s is too small for %d slots\n"),
7866 section
->name
, nslots
);
7872 printf (_("Contents of the %s section:\n\n"), section
->name
);
7873 printf (_(" Version: %d\n"), version
);
7875 printf (_(" Number of columns: %d\n"), ncols
);
7876 printf (_(" Number of used entries: %d\n"), nused
);
7877 printf (_(" Number of slots: %d\n\n"), nslots
);
7880 if (ppool
> limit
|| ppool
< phdr
)
7882 warn (_("Section %s too small for %d hash table entries\n"),
7883 section
->name
, nslots
);
7890 prealloc_cu_tu_list ((limit
- ppool
) / 4);
7891 for (i
= 0; i
< nslots
; i
++)
7893 unsigned char *shndx_list
;
7896 SAFE_BYTE_GET64 (phash
, &signature_high
, &signature_low
, limit
);
7897 if (signature_high
!= 0 || signature_low
!= 0)
7899 SAFE_BYTE_GET (j
, pindex
, 4, limit
);
7900 shndx_list
= ppool
+ j
* 4;
7901 /* PR 17531: file: 705e010d. */
7902 if (shndx_list
< ppool
)
7904 warn (_("Section index pool located before start of section\n"));
7909 printf (_(" [%3d] Signature: 0x%s Sections: "),
7910 i
, dwarf_vmatoa64 (signature_high
, signature_low
,
7911 buf
, sizeof (buf
)));
7914 if (shndx_list
>= limit
)
7916 warn (_("Section %s too small for shndx pool\n"),
7920 SAFE_BYTE_GET (shndx
, shndx_list
, 4, limit
);
7924 printf (" %d", shndx
);
7926 add_shndx_to_cu_tu_entry (shndx
);
7938 else if (version
== 2)
7941 unsigned int dw_sect
;
7942 unsigned char *ph
= phash
;
7943 unsigned char *pi
= pindex
;
7944 unsigned char *poffsets
= ppool
+ ncols
* 4;
7945 unsigned char *psizes
= poffsets
+ nused
* ncols
* 4;
7946 unsigned char *pend
= psizes
+ nused
* ncols
* 4;
7947 bfd_boolean is_tu_index
;
7948 struct cu_tu_set
*this_set
= NULL
;
7950 unsigned char *prow
;
7952 is_tu_index
= strcmp (section
->name
, ".debug_tu_index") == 0;
7954 /* PR 17531: file: 0dd159bf.
7955 Check for wraparound with an overlarge ncols value. */
7956 if (poffsets
< ppool
|| (unsigned int) ((poffsets
- ppool
) / 4) != ncols
)
7958 warn (_("Overlarge number of columns: %x\n"), ncols
);
7964 warn (_("Section %s too small for offset and size tables\n"),
7971 printf (_(" Offset table\n"));
7972 printf (" slot %-16s ",
7973 is_tu_index
? _("signature") : _("dwo_id"));
7980 tu_sets
= xcalloc2 (nused
, sizeof (struct cu_tu_set
));
7986 cu_sets
= xcalloc2 (nused
, sizeof (struct cu_tu_set
));
7993 for (j
= 0; j
< ncols
; j
++)
7995 SAFE_BYTE_GET (dw_sect
, ppool
+ j
* 4, 4, limit
);
7996 printf (" %8s", get_DW_SECT_short_name (dw_sect
));
8001 for (i
= 0; i
< nslots
; i
++)
8003 SAFE_BYTE_GET64 (ph
, &signature_high
, &signature_low
, limit
);
8005 SAFE_BYTE_GET (row
, pi
, 4, limit
);
8008 /* PR 17531: file: a05f6ab3. */
8011 warn (_("Row index (%u) is larger than number of used entries (%u)\n"),
8017 memcpy (&this_set
[row
- 1].signature
, ph
, sizeof (uint64_t));
8019 prow
= poffsets
+ (row
- 1) * ncols
* 4;
8020 /* PR 17531: file: b8ce60a8. */
8021 if (prow
< poffsets
|| prow
> limit
)
8023 warn (_("Row index (%u) * num columns (%u) > space remaining in section\n"),
8029 printf (_(" [%3d] 0x%s"),
8030 i
, dwarf_vmatoa64 (signature_high
, signature_low
,
8031 buf
, sizeof (buf
)));
8032 for (j
= 0; j
< ncols
; j
++)
8034 SAFE_BYTE_GET (val
, prow
+ j
* 4, 4, limit
);
8036 printf (" %8d", val
);
8039 SAFE_BYTE_GET (dw_sect
, ppool
+ j
* 4, 4, limit
);
8041 /* PR 17531: file: 10796eb3. */
8042 if (dw_sect
>= DW_SECT_MAX
)
8043 warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect
);
8045 this_set
[row
- 1].section_offsets
[dw_sect
] = val
;
8061 printf (_(" Size table\n"));
8062 printf (" slot %-16s ",
8063 is_tu_index
? _("signature") : _("dwo_id"));
8066 for (j
= 0; j
< ncols
; j
++)
8068 SAFE_BYTE_GET (val
, ppool
+ j
* 4, 4, limit
);
8070 printf (" %8s", get_DW_SECT_short_name (val
));
8076 for (i
= 0; i
< nslots
; i
++)
8078 SAFE_BYTE_GET64 (ph
, &signature_high
, &signature_low
, limit
);
8080 SAFE_BYTE_GET (row
, pi
, 4, limit
);
8083 prow
= psizes
+ (row
- 1) * ncols
* 4;
8086 printf (_(" [%3d] 0x%s"),
8087 i
, dwarf_vmatoa64 (signature_high
, signature_low
,
8088 buf
, sizeof (buf
)));
8090 for (j
= 0; j
< ncols
; j
++)
8092 SAFE_BYTE_GET (val
, prow
+ j
* 4, 4, limit
);
8094 printf (" %8d", val
);
8097 SAFE_BYTE_GET (dw_sect
, ppool
+ j
* 4, 4, limit
);
8098 if (dw_sect
>= DW_SECT_MAX
)
8099 warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect
);
8101 this_set
[row
- 1].section_sizes
[dw_sect
] = val
;
8113 else if (do_display
)
8114 printf (_(" Unsupported version (%d)\n"), version
);
8122 /* Load the CU and TU indexes if present. This will build a list of
8123 section sets that we can use to associate a .debug_info.dwo section
8124 with its associated .debug_abbrev.dwo section in a .dwp file. */
8127 load_cu_tu_indexes (void *file
)
8129 static int cu_tu_indexes_read
= -1; /* Tri-state variable. */
8131 /* If we have already loaded (or tried to load) the CU and TU indexes
8132 then do not bother to repeat the task. */
8133 if (cu_tu_indexes_read
== -1)
8135 cu_tu_indexes_read
= TRUE
;
8137 if (load_debug_section (dwp_cu_index
, file
))
8138 if (! process_cu_tu_index (&debug_displays
[dwp_cu_index
].section
, 0))
8139 cu_tu_indexes_read
= FALSE
;
8141 if (load_debug_section (dwp_tu_index
, file
))
8142 if (! process_cu_tu_index (&debug_displays
[dwp_tu_index
].section
, 0))
8143 cu_tu_indexes_read
= FALSE
;
8146 return (bfd_boolean
) cu_tu_indexes_read
;
8149 /* Find the set of sections that includes section SHNDX. */
8152 find_cu_tu_set (void *file
, unsigned int shndx
)
8156 if (! load_cu_tu_indexes (file
))
8159 /* Find SHNDX in the shndx pool. */
8160 for (i
= 0; i
< shndx_pool_used
; i
++)
8161 if (shndx_pool
[i
] == shndx
)
8164 if (i
>= shndx_pool_used
)
8167 /* Now backup to find the first entry in the set. */
8168 while (i
> 0 && shndx_pool
[i
- 1] != 0)
8171 return shndx_pool
+ i
;
8174 /* Display a .debug_cu_index or .debug_tu_index section. */
8177 display_cu_index (struct dwarf_section
*section
, void *file ATTRIBUTE_UNUSED
)
8179 return process_cu_tu_index (section
, 1);
8183 display_debug_not_supported (struct dwarf_section
*section
,
8184 void *file ATTRIBUTE_UNUSED
)
8186 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
8192 /* Like malloc, but takes two parameters like calloc.
8193 Verifies that the first parameter is not too large.
8194 Note: does *not* initialise the allocated memory to zero. */
8196 cmalloc (size_t nmemb
, size_t size
)
8198 /* Check for overflow. */
8199 if (nmemb
>= ~(size_t) 0 / size
)
8202 return xmalloc (nmemb
* size
);
8205 /* Like xmalloc, but takes two parameters like calloc.
8206 Verifies that the first parameter is not too large.
8207 Note: does *not* initialise the allocated memory to zero. */
8209 xcmalloc (size_t nmemb
, size_t size
)
8211 /* Check for overflow. */
8212 if (nmemb
>= ~(size_t) 0 / size
)
8215 _("Attempt to allocate an array with an excessive number of elements: 0x%lx\n"),
8220 return xmalloc (nmemb
* size
);
8223 /* Like xrealloc, but takes three parameters.
8224 Verifies that the second parameter is not too large.
8225 Note: does *not* initialise any new memory to zero. */
8227 xcrealloc (void *ptr
, size_t nmemb
, size_t size
)
8229 /* Check for overflow. */
8230 if (nmemb
>= ~(size_t) 0 / size
)
8233 _("Attempt to re-allocate an array with an excessive number of elements: 0x%lx\n"),
8238 return xrealloc (ptr
, nmemb
* size
);
8241 /* Like xcalloc, but verifies that the first parameter is not too large. */
8243 xcalloc2 (size_t nmemb
, size_t size
)
8245 /* Check for overflow. */
8246 if (nmemb
>= ~(size_t) 0 / size
)
8249 _("Attempt to allocate a zero'ed array with an excessive number of elements: 0x%lx\n"),
8254 return xcalloc (nmemb
, size
);
8258 free_debug_memory (void)
8264 for (i
= 0; i
< max
; i
++)
8265 free_debug_section ((enum dwarf_section_display_enum
) i
);
8267 if (debug_information
!= NULL
)
8269 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
)
8271 for (i
= 0; i
< num_debug_info_entries
; i
++)
8273 if (!debug_information
[i
].max_loc_offsets
)
8275 free (debug_information
[i
].loc_offsets
);
8276 free (debug_information
[i
].have_frame_base
);
8278 if (!debug_information
[i
].max_range_lists
)
8279 free (debug_information
[i
].range_lists
);
8282 free (debug_information
);
8283 debug_information
= NULL
;
8284 alloc_num_debug_info_entries
= num_debug_info_entries
= 0;
8289 dwarf_select_sections_by_names (const char *names
)
8293 const char * option
;
8297 debug_dump_long_opts
;
8299 static const debug_dump_long_opts opts_table
[] =
8301 /* Please keep this table alpha- sorted. */
8302 { "Ranges", & do_debug_ranges
, 1 },
8303 { "abbrev", & do_debug_abbrevs
, 1 },
8304 { "addr", & do_debug_addr
, 1 },
8305 { "aranges", & do_debug_aranges
, 1 },
8306 { "cu_index", & do_debug_cu_index
, 1 },
8307 { "decodedline", & do_debug_lines
, FLAG_DEBUG_LINES_DECODED
},
8308 { "frames", & do_debug_frames
, 1 },
8309 { "frames-interp", & do_debug_frames_interp
, 1 },
8310 /* The special .gdb_index section. */
8311 { "gdb_index", & do_gdb_index
, 1 },
8312 { "info", & do_debug_info
, 1 },
8313 { "line", & do_debug_lines
, FLAG_DEBUG_LINES_RAW
}, /* For backwards compatibility. */
8314 { "loc", & do_debug_loc
, 1 },
8315 { "macro", & do_debug_macinfo
, 1 },
8316 { "pubnames", & do_debug_pubnames
, 1 },
8317 { "pubtypes", & do_debug_pubtypes
, 1 },
8318 /* This entry is for compatibility
8319 with earlier versions of readelf. */
8320 { "ranges", & do_debug_aranges
, 1 },
8321 { "rawline", & do_debug_lines
, FLAG_DEBUG_LINES_RAW
},
8322 { "str", & do_debug_str
, 1 },
8323 /* These trace_* sections are used by Itanium VMS. */
8324 { "trace_abbrev", & do_trace_abbrevs
, 1 },
8325 { "trace_aranges", & do_trace_aranges
, 1 },
8326 { "trace_info", & do_trace_info
, 1 },
8335 const debug_dump_long_opts
* entry
;
8337 for (entry
= opts_table
; entry
->option
; entry
++)
8339 size_t len
= strlen (entry
->option
);
8341 if (strncmp (p
, entry
->option
, len
) == 0
8342 && (p
[len
] == ',' || p
[len
] == '\0'))
8344 * entry
->variable
|= entry
->val
;
8346 /* The --debug-dump=frames-interp option also
8347 enables the --debug-dump=frames option. */
8348 if (do_debug_frames_interp
)
8349 do_debug_frames
= 1;
8356 if (entry
->option
== NULL
)
8358 warn (_("Unrecognized debug option '%s'\n"), p
);
8359 p
= strchr (p
, ',');
8370 dwarf_select_sections_by_letters (const char *letters
)
8372 unsigned int lindex
= 0;
8374 while (letters
[lindex
])
8375 switch (letters
[lindex
++])
8382 do_debug_abbrevs
= 1;
8386 do_debug_lines
|= FLAG_DEBUG_LINES_RAW
;
8390 do_debug_lines
|= FLAG_DEBUG_LINES_DECODED
;
8394 do_debug_pubnames
= 1;
8398 do_debug_pubtypes
= 1;
8402 do_debug_aranges
= 1;
8406 do_debug_ranges
= 1;
8410 do_debug_frames_interp
= 1;
8413 do_debug_frames
= 1;
8417 do_debug_macinfo
= 1;
8429 warn (_("Unrecognized debug option '%s'\n"), letters
);
8435 dwarf_select_sections_all (void)
8438 do_debug_abbrevs
= 1;
8439 do_debug_lines
= FLAG_DEBUG_LINES_RAW
;
8440 do_debug_pubnames
= 1;
8441 do_debug_pubtypes
= 1;
8442 do_debug_aranges
= 1;
8443 do_debug_ranges
= 1;
8444 do_debug_frames
= 1;
8445 do_debug_macinfo
= 1;
8450 do_trace_abbrevs
= 1;
8451 do_trace_aranges
= 1;
8453 do_debug_cu_index
= 1;
8456 struct dwarf_section_display debug_displays
[] =
8458 { { ".debug_abbrev", ".zdebug_abbrev", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
8459 display_debug_abbrev
, &do_debug_abbrevs
, FALSE
},
8460 { { ".debug_aranges", ".zdebug_aranges", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
8461 display_debug_aranges
, &do_debug_aranges
, TRUE
},
8462 { { ".debug_frame", ".zdebug_frame", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
8463 display_debug_frames
, &do_debug_frames
, TRUE
},
8464 { { ".debug_info", ".zdebug_info", NULL
, NULL
, 0, 0, abbrev
, NULL
, 0, NULL
},
8465 display_debug_info
, &do_debug_info
, TRUE
},
8466 { { ".debug_line", ".zdebug_line", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
8467 display_debug_lines
, &do_debug_lines
, TRUE
},
8468 { { ".debug_pubnames", ".zdebug_pubnames", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
8469 display_debug_pubnames
, &do_debug_pubnames
, FALSE
},
8470 { { ".debug_gnu_pubnames", ".zdebug_gnu_pubnames", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
8471 display_debug_gnu_pubnames
, &do_debug_pubnames
, FALSE
},
8472 { { ".eh_frame", "", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
8473 display_debug_frames
, &do_debug_frames
, TRUE
},
8474 { { ".debug_macinfo", ".zdebug_macinfo", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
8475 display_debug_macinfo
, &do_debug_macinfo
, FALSE
},
8476 { { ".debug_macro", ".zdebug_macro", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
8477 display_debug_macro
, &do_debug_macinfo
, TRUE
},
8478 { { ".debug_str", ".zdebug_str", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
8479 display_debug_str
, &do_debug_str
, FALSE
},
8480 { { ".debug_line_str", ".zdebug_line_str", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
8481 display_debug_str
, &do_debug_str
, FALSE
},
8482 { { ".debug_loc", ".zdebug_loc", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
8483 display_debug_loc
, &do_debug_loc
, TRUE
},
8484 { { ".debug_loclists", ".zdebug_loclists", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
8485 display_debug_loc
, &do_debug_loc
, TRUE
},
8486 { { ".debug_pubtypes", ".zdebug_pubtypes", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
8487 display_debug_pubnames
, &do_debug_pubtypes
, FALSE
},
8488 { { ".debug_gnu_pubtypes", ".zdebug_gnu_pubtypes", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
8489 display_debug_gnu_pubnames
, &do_debug_pubtypes
, FALSE
},
8490 { { ".debug_ranges", ".zdebug_ranges", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
8491 display_debug_ranges
, &do_debug_ranges
, TRUE
},
8492 { { ".debug_rnglists", ".zdebug_rnglists", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
8493 display_debug_ranges
, &do_debug_ranges
, TRUE
},
8494 { { ".debug_static_func", ".zdebug_static_func", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
8495 display_debug_not_supported
, NULL
, FALSE
},
8496 { { ".debug_static_vars", ".zdebug_static_vars", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
8497 display_debug_not_supported
, NULL
, FALSE
},
8498 { { ".debug_types", ".zdebug_types", NULL
, NULL
, 0, 0, abbrev
, NULL
, 0, NULL
},
8499 display_debug_types
, &do_debug_info
, TRUE
},
8500 { { ".debug_weaknames", ".zdebug_weaknames", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
8501 display_debug_not_supported
, NULL
, FALSE
},
8502 { { ".gdb_index", "", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
8503 display_gdb_index
, &do_gdb_index
, FALSE
},
8504 { { ".trace_info", "", NULL
, NULL
, 0, 0, trace_abbrev
, NULL
, 0, NULL
},
8505 display_trace_info
, &do_trace_info
, TRUE
},
8506 { { ".trace_abbrev", "", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
8507 display_debug_abbrev
, &do_trace_abbrevs
, FALSE
},
8508 { { ".trace_aranges", "", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
8509 display_debug_aranges
, &do_trace_aranges
, FALSE
},
8510 { { ".debug_info.dwo", ".zdebug_info.dwo", NULL
, NULL
, 0, 0, abbrev_dwo
, NULL
, 0, NULL
},
8511 display_debug_info
, &do_debug_info
, TRUE
},
8512 { { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
8513 display_debug_abbrev
, &do_debug_abbrevs
, FALSE
},
8514 { { ".debug_types.dwo", ".zdebug_types.dwo", NULL
, NULL
, 0, 0, abbrev_dwo
, NULL
, 0, NULL
},
8515 display_debug_types
, &do_debug_info
, TRUE
},
8516 { { ".debug_line.dwo", ".zdebug_line.dwo", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
8517 display_debug_lines
, &do_debug_lines
, TRUE
},
8518 { { ".debug_loc.dwo", ".zdebug_loc.dwo", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
8519 display_debug_loc
, &do_debug_loc
, TRUE
},
8520 { { ".debug_macro.dwo", ".zdebug_macro.dwo", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
8521 display_debug_macro
, &do_debug_macinfo
, TRUE
},
8522 { { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
8523 display_debug_macinfo
, &do_debug_macinfo
, FALSE
},
8524 { { ".debug_str.dwo", ".zdebug_str.dwo", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
8525 display_debug_str
, &do_debug_str
, TRUE
},
8526 { { ".debug_str_offsets", ".zdebug_str_offsets", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
8527 display_debug_str_offsets
, NULL
, FALSE
},
8528 { { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
8529 display_debug_str_offsets
, NULL
, FALSE
},
8530 { { ".debug_addr", ".zdebug_addr", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
8531 display_debug_addr
, &do_debug_addr
, TRUE
},
8532 { { ".debug_cu_index", "", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
8533 display_cu_index
, &do_debug_cu_index
, FALSE
},
8534 { { ".debug_tu_index", "", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
8535 display_cu_index
, &do_debug_cu_index
, FALSE
},