1 /* dwarf.c -- display DWARF contents of a BFD binary file
2 Copyright (C) 2005-2014 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 debug_info
*debug_information
= NULL
;
42 /* Special value for num_debug_info_entries to indicate
43 that the .debug_info section could not be loaded/parsed. */
44 #define DEBUG_INFO_UNAVAILABLE (unsigned int) -1
51 int do_debug_pubnames
;
52 int do_debug_pubtypes
;
56 int do_debug_frames_interp
;
65 int do_debug_cu_index
;
68 int dwarf_cutoff_level
= -1;
69 unsigned long dwarf_start_die
;
73 /* Collection of CU/TU section sets from .debug_cu_index and .debug_tu_index
74 sections. For version 1 package files, each set is stored in SHNDX_POOL
75 as a zero-terminated list of section indexes comprising one set of debug
76 sections from a .dwo file. */
78 static int cu_tu_indexes_read
= 0;
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 void load_cu_tu_indexes (void *file
);
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 __STDC_VERSION__ >= 199901L || (defined(__GNUC__) && __GNUC__ >= 2)
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 specifiying 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)
285 if (length_return
!= NULL
)
286 *length_return
= num_read
;
288 if (sign
&& (shift
< 8 * sizeof (result
)) && (byte
& 0x40))
289 result
|= (dwarf_vma
) -1 << shift
;
294 /* Create a signed version to avoid painful typecasts. */
295 static inline dwarf_signed_vma
296 read_sleb128 (unsigned char * data
,
297 unsigned int * length_return
,
298 const unsigned char * const end
)
300 return (dwarf_signed_vma
) read_leb128 (data
, length_return
, TRUE
, end
);
303 static inline dwarf_vma
304 read_uleb128 (unsigned char * data
,
305 unsigned int * length_return
,
306 const unsigned char * const end
)
308 return read_leb128 (data
, length_return
, FALSE
, end
);
311 #define SAFE_BYTE_GET(VAL, PTR, AMOUNT, END) \
314 int dummy [sizeof (VAL) < (AMOUNT) ? -1 : 1] ATTRIBUTE_UNUSED ; \
315 unsigned int amount = (AMOUNT); \
316 if (((PTR) + amount) >= (END)) \
319 amount = (END) - (PTR); \
323 if (amount == 0 || amount > 8) \
326 VAL = byte_get ((PTR), amount); \
330 #define SAFE_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \
333 SAFE_BYTE_GET (VAL, PTR, AMOUNT, END); \
338 #define SAFE_SIGNED_BYTE_GET(VAL, PTR, AMOUNT, END) \
341 unsigned int amount = (AMOUNT); \
342 if (((PTR) + amount) >= (END)) \
345 amount = (END) - (PTR); \
350 VAL = byte_get_signed ((PTR), amount); \
356 #define SAFE_SIGNED_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \
359 SAFE_SIGNED_BYTE_GET (VAL, PTR, AMOUNT, END); \
364 #define SAFE_BYTE_GET64(PTR, HIGH, LOW, END) \
367 if (((PTR) + 8) <= (END)) \
369 byte_get_64 ((PTR), (HIGH), (LOW)); \
373 * (LOW) = * (HIGH) = 0; \
378 typedef struct State_Machine_Registers
386 unsigned char op_index
;
387 unsigned char end_sequence
;
388 /* This variable hold the number of the last entry seen
389 in the File Table. */
390 unsigned int last_file_entry
;
393 static SMR state_machine_regs
;
396 reset_state_machine (int is_stmt
)
398 state_machine_regs
.address
= 0;
399 state_machine_regs
.op_index
= 0;
400 state_machine_regs
.file
= 1;
401 state_machine_regs
.line
= 1;
402 state_machine_regs
.column
= 0;
403 state_machine_regs
.is_stmt
= is_stmt
;
404 state_machine_regs
.basic_block
= 0;
405 state_machine_regs
.end_sequence
= 0;
406 state_machine_regs
.last_file_entry
= 0;
409 /* Handled an extend line op.
410 Returns the number of bytes read. */
413 process_extended_line_op (unsigned char * data
,
417 unsigned char op_code
;
418 unsigned int bytes_read
;
421 unsigned char *orig_data
= data
;
424 len
= read_uleb128 (data
, & bytes_read
, end
);
427 if (len
== 0 || data
== end
|| len
> (uintptr_t) (end
- data
))
429 warn (_("Badly formed extended line op encountered!\n"));
436 printf (_(" Extended opcode %d: "), op_code
);
440 case DW_LNE_end_sequence
:
441 printf (_("End of Sequence\n\n"));
442 reset_state_machine (is_stmt
);
445 case DW_LNE_set_address
:
446 /* PR 17512: file: 002-100480-0.004. */
447 if (len
- bytes_read
- 1 > 8)
448 warn (_("Length (%d) of DW_LNE_set_address op is too long\n"),
449 len
- bytes_read
- 1);
450 SAFE_BYTE_GET (adr
, data
, len
- bytes_read
- 1, end
);
451 printf (_("set Address to 0x%s\n"), dwarf_vmatoa ("x", adr
));
452 state_machine_regs
.address
= adr
;
453 state_machine_regs
.op_index
= 0;
456 case DW_LNE_define_file
:
457 printf (_("define new File Table entry\n"));
458 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
459 printf (" %d\t", ++state_machine_regs
.last_file_entry
);
462 data
+= strnlen ((char *) data
, end
- data
) + 1;
463 printf ("%s\t", dwarf_vmatoa ("u", read_uleb128 (data
, & bytes_read
, end
)));
465 printf ("%s\t", dwarf_vmatoa ("u", read_uleb128 (data
, & bytes_read
, end
)));
467 printf ("%s\t", dwarf_vmatoa ("u", read_uleb128 (data
, & bytes_read
, end
)));
469 printf ("%s\n\n", name
);
471 if (((unsigned int) (data
- orig_data
) != len
) || data
== end
)
472 warn (_("DW_LNE_define_file: Bad opcode length\n"));
475 case DW_LNE_set_discriminator
:
476 printf (_("set Discriminator to %s\n"),
477 dwarf_vmatoa ("u", read_uleb128 (data
, & bytes_read
, end
)));
481 case DW_LNE_HP_negate_is_UV_update
:
482 printf ("DW_LNE_HP_negate_is_UV_update\n");
484 case DW_LNE_HP_push_context
:
485 printf ("DW_LNE_HP_push_context\n");
487 case DW_LNE_HP_pop_context
:
488 printf ("DW_LNE_HP_pop_context\n");
490 case DW_LNE_HP_set_file_line_column
:
491 printf ("DW_LNE_HP_set_file_line_column\n");
493 case DW_LNE_HP_set_routine_name
:
494 printf ("DW_LNE_HP_set_routine_name\n");
496 case DW_LNE_HP_set_sequence
:
497 printf ("DW_LNE_HP_set_sequence\n");
499 case DW_LNE_HP_negate_post_semantics
:
500 printf ("DW_LNE_HP_negate_post_semantics\n");
502 case DW_LNE_HP_negate_function_exit
:
503 printf ("DW_LNE_HP_negate_function_exit\n");
505 case DW_LNE_HP_negate_front_end_logical
:
506 printf ("DW_LNE_HP_negate_front_end_logical\n");
508 case DW_LNE_HP_define_proc
:
509 printf ("DW_LNE_HP_define_proc\n");
511 case DW_LNE_HP_source_file_correlation
:
513 unsigned char *edata
= data
+ len
- bytes_read
- 1;
515 printf ("DW_LNE_HP_source_file_correlation\n");
521 opc
= read_uleb128 (data
, & bytes_read
, edata
);
526 case DW_LNE_HP_SFC_formfeed
:
527 printf (" DW_LNE_HP_SFC_formfeed\n");
529 case DW_LNE_HP_SFC_set_listing_line
:
530 printf (" DW_LNE_HP_SFC_set_listing_line (%s)\n",
532 read_uleb128 (data
, & bytes_read
, edata
)));
535 case DW_LNE_HP_SFC_associate
:
536 printf (" DW_LNE_HP_SFC_associate ");
539 read_uleb128 (data
, & bytes_read
, edata
)));
543 read_uleb128 (data
, & bytes_read
, edata
)));
547 read_uleb128 (data
, & bytes_read
, edata
)));
551 printf (_(" UNKNOWN DW_LNE_HP_SFC opcode (%u)\n"), opc
);
561 unsigned int rlen
= len
- bytes_read
- 1;
563 if (op_code
>= DW_LNE_lo_user
564 /* The test against DW_LNW_hi_user is redundant due to
565 the limited range of the unsigned char data type used
567 /*&& op_code <= DW_LNE_hi_user*/)
568 printf (_("user defined: "));
570 printf (_("UNKNOWN: "));
571 printf (_("length %d ["), rlen
);
573 printf (" %02x", *data
++);
582 static const unsigned char *
583 fetch_indirect_string (dwarf_vma offset
)
585 struct dwarf_section
*section
= &debug_displays
[str
].section
;
587 if (section
->start
== NULL
)
588 return (const unsigned char *) _("<no .debug_str section>");
590 if (offset
> section
->size
)
592 warn (_("DW_FORM_strp offset too big: %s\n"),
593 dwarf_vmatoa ("x", offset
));
594 return (const unsigned char *) _("<offset is too big>");
597 return (const unsigned char *) section
->start
+ offset
;
601 fetch_indexed_string (dwarf_vma idx
, struct cu_tu_set
*this_set
,
602 dwarf_vma offset_size
, int dwo
)
604 enum dwarf_section_display_enum str_sec_idx
= dwo
? str_dwo
: str
;
605 enum dwarf_section_display_enum idx_sec_idx
= dwo
? str_index_dwo
: str_index
;
606 struct dwarf_section
*index_section
= &debug_displays
[idx_sec_idx
].section
;
607 struct dwarf_section
*str_section
= &debug_displays
[str_sec_idx
].section
;
608 dwarf_vma index_offset
= idx
* offset_size
;
609 dwarf_vma str_offset
;
611 if (index_section
->start
== NULL
)
612 return (dwo
? _("<no .debug_str_offsets.dwo section>")
613 : _("<no .debug_str_offsets section>"));
615 if (this_set
!= NULL
)
616 index_offset
+= this_set
->section_offsets
[DW_SECT_STR_OFFSETS
];
617 if (index_offset
> index_section
->size
)
619 warn (_("DW_FORM_GNU_str_index offset too big: %s\n"),
620 dwarf_vmatoa ("x", index_offset
));
621 return _("<index offset is too big>");
624 if (str_section
->start
== NULL
)
625 return (dwo
? _("<no .debug_str.dwo section>")
626 : _("<no .debug_str section>"));
628 str_offset
= byte_get (index_section
->start
+ index_offset
, offset_size
);
629 str_offset
-= str_section
->address
;
630 if (str_offset
> str_section
->size
)
632 warn (_("DW_FORM_GNU_str_index indirect offset too big: %s\n"),
633 dwarf_vmatoa ("x", str_offset
));
634 return _("<indirect index offset is too big>");
637 return (const char *) str_section
->start
+ str_offset
;
641 fetch_indexed_value (dwarf_vma offset
, dwarf_vma bytes
)
643 struct dwarf_section
*section
= &debug_displays
[debug_addr
].section
;
645 if (section
->start
== NULL
)
646 return (_("<no .debug_addr section>"));
648 if (offset
+ bytes
> section
->size
)
650 warn (_("Offset into section %s too big: %s\n"),
651 section
->name
, dwarf_vmatoa ("x", offset
));
652 return "<offset too big>";
655 return dwarf_vmatoa ("x", byte_get (section
->start
+ offset
, bytes
));
659 /* FIXME: There are better and more efficient ways to handle
660 these structures. For now though, I just want something that
661 is simple to implement. */
662 typedef struct abbrev_attr
664 unsigned long attribute
;
666 struct abbrev_attr
*next
;
670 typedef struct abbrev_entry
675 struct abbrev_attr
*first_attr
;
676 struct abbrev_attr
*last_attr
;
677 struct abbrev_entry
*next
;
681 static abbrev_entry
*first_abbrev
= NULL
;
682 static abbrev_entry
*last_abbrev
= NULL
;
689 for (abbrv
= first_abbrev
; abbrv
;)
691 abbrev_entry
*next_abbrev
= abbrv
->next
;
694 for (attr
= abbrv
->first_attr
; attr
;)
696 abbrev_attr
*next_attr
= attr
->next
;
706 last_abbrev
= first_abbrev
= NULL
;
710 add_abbrev (unsigned long number
, unsigned long tag
, int children
)
714 entry
= (abbrev_entry
*) malloc (sizeof (*entry
));
719 entry
->entry
= number
;
721 entry
->children
= children
;
722 entry
->first_attr
= NULL
;
723 entry
->last_attr
= NULL
;
726 if (first_abbrev
== NULL
)
727 first_abbrev
= entry
;
729 last_abbrev
->next
= entry
;
735 add_abbrev_attr (unsigned long attribute
, unsigned long form
)
739 attr
= (abbrev_attr
*) malloc (sizeof (*attr
));
744 attr
->attribute
= attribute
;
748 if (last_abbrev
->first_attr
== NULL
)
749 last_abbrev
->first_attr
= attr
;
751 last_abbrev
->last_attr
->next
= attr
;
753 last_abbrev
->last_attr
= attr
;
756 /* Processes the (partial) contents of a .debug_abbrev section.
757 Returns NULL if the end of the section was encountered.
758 Returns the address after the last byte read if the end of
759 an abbreviation set was found. */
761 static unsigned char *
762 process_abbrev_section (unsigned char *start
, unsigned char *end
)
764 if (first_abbrev
!= NULL
)
769 unsigned int bytes_read
;
772 unsigned long attribute
;
775 entry
= read_uleb128 (start
, & bytes_read
, end
);
778 /* A single zero is supposed to end the section according
779 to the standard. If there's more, then signal that to
786 tag
= read_uleb128 (start
, & bytes_read
, end
);
793 add_abbrev (entry
, tag
, children
);
799 attribute
= read_uleb128 (start
, & bytes_read
, end
);
804 form
= read_uleb128 (start
, & bytes_read
, end
);
809 add_abbrev_attr (attribute
, form
);
811 while (attribute
!= 0);
814 /* Report the missing single zero which ends the section. */
815 error (_(".debug_abbrev section not zero terminated\n"));
821 get_TAG_name (unsigned long tag
)
823 const char *name
= get_DW_TAG_name ((unsigned int)tag
);
827 static char buffer
[100];
829 snprintf (buffer
, sizeof (buffer
), _("Unknown TAG value: %lx"), tag
);
837 get_FORM_name (unsigned long form
)
842 return "DW_FORM value: 0";
844 name
= get_DW_FORM_name (form
);
847 static char buffer
[100];
849 snprintf (buffer
, sizeof (buffer
), _("Unknown FORM value: %lx"), form
);
856 static unsigned char *
857 display_block (unsigned char *data
,
859 const unsigned char * const end
)
863 printf (_(" %s byte block: "), dwarf_vmatoa ("u", length
));
865 return (unsigned char *) end
;
867 maxlen
= (dwarf_vma
) (end
- data
);
868 length
= length
> maxlen
? maxlen
: length
;
871 printf ("%lx ", (unsigned long) byte_get (data
++, 1));
877 decode_location_expression (unsigned char * data
,
878 unsigned int pointer_size
,
879 unsigned int offset_size
,
883 struct dwarf_section
* section
)
886 unsigned int bytes_read
;
888 dwarf_signed_vma svalue
;
889 unsigned char *end
= data
+ length
;
890 int need_frame_base
= 0;
899 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
900 printf ("DW_OP_addr: %s", dwarf_vmatoa ("x", uvalue
));
903 printf ("DW_OP_deref");
906 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
907 printf ("DW_OP_const1u: %lu", (unsigned long) uvalue
);
910 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 1, end
);
911 printf ("DW_OP_const1s: %ld", (long) svalue
);
914 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
915 printf ("DW_OP_const2u: %lu", (unsigned long) uvalue
);
918 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
919 printf ("DW_OP_const2s: %ld", (long) svalue
);
922 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
923 printf ("DW_OP_const4u: %lu", (unsigned long) uvalue
);
926 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
927 printf ("DW_OP_const4s: %ld", (long) svalue
);
930 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
931 printf ("DW_OP_const8u: %lu ", (unsigned long) uvalue
);
932 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
933 printf ("%lu", (unsigned long) uvalue
);
936 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
937 printf ("DW_OP_const8s: %ld ", (long) svalue
);
938 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
939 printf ("%ld", (long) svalue
);
942 printf ("DW_OP_constu: %s",
943 dwarf_vmatoa ("u", read_uleb128 (data
, &bytes_read
, end
)));
947 printf ("DW_OP_consts: %s",
948 dwarf_vmatoa ("d", read_sleb128 (data
, &bytes_read
, end
)));
952 printf ("DW_OP_dup");
955 printf ("DW_OP_drop");
958 printf ("DW_OP_over");
961 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
962 printf ("DW_OP_pick: %ld", (unsigned long) uvalue
);
965 printf ("DW_OP_swap");
968 printf ("DW_OP_rot");
971 printf ("DW_OP_xderef");
974 printf ("DW_OP_abs");
977 printf ("DW_OP_and");
980 printf ("DW_OP_div");
983 printf ("DW_OP_minus");
986 printf ("DW_OP_mod");
989 printf ("DW_OP_mul");
992 printf ("DW_OP_neg");
995 printf ("DW_OP_not");
1001 printf ("DW_OP_plus");
1003 case DW_OP_plus_uconst
:
1004 printf ("DW_OP_plus_uconst: %s",
1005 dwarf_vmatoa ("u", read_uleb128 (data
, &bytes_read
, end
)));
1009 printf ("DW_OP_shl");
1012 printf ("DW_OP_shr");
1015 printf ("DW_OP_shra");
1018 printf ("DW_OP_xor");
1021 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1022 printf ("DW_OP_bra: %ld", (long) svalue
);
1025 printf ("DW_OP_eq");
1028 printf ("DW_OP_ge");
1031 printf ("DW_OP_gt");
1034 printf ("DW_OP_le");
1037 printf ("DW_OP_lt");
1040 printf ("DW_OP_ne");
1043 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1044 printf ("DW_OP_skip: %ld", (long) svalue
);
1079 printf ("DW_OP_lit%d", op
- DW_OP_lit0
);
1114 printf ("DW_OP_reg%d (%s)", op
- DW_OP_reg0
,
1115 regname (op
- DW_OP_reg0
, 1));
1150 printf ("DW_OP_breg%d (%s): %s",
1152 regname (op
- DW_OP_breg0
, 1),
1153 dwarf_vmatoa ("d", read_sleb128 (data
, &bytes_read
, end
)));
1158 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1160 printf ("DW_OP_regx: %s (%s)",
1161 dwarf_vmatoa ("u", uvalue
), regname (uvalue
, 1));
1164 need_frame_base
= 1;
1165 printf ("DW_OP_fbreg: %s",
1166 dwarf_vmatoa ("d", read_sleb128 (data
, &bytes_read
, end
)));
1170 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1172 printf ("DW_OP_bregx: %s (%s) %s",
1173 dwarf_vmatoa ("u", uvalue
), regname (uvalue
, 1),
1174 dwarf_vmatoa ("d", read_sleb128 (data
, &bytes_read
, end
)));
1178 printf ("DW_OP_piece: %s",
1179 dwarf_vmatoa ("u", read_uleb128 (data
, &bytes_read
, end
)));
1182 case DW_OP_deref_size
:
1183 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1184 printf ("DW_OP_deref_size: %ld", (long) uvalue
);
1186 case DW_OP_xderef_size
:
1187 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1188 printf ("DW_OP_xderef_size: %ld", (long) uvalue
);
1191 printf ("DW_OP_nop");
1194 /* DWARF 3 extensions. */
1195 case DW_OP_push_object_address
:
1196 printf ("DW_OP_push_object_address");
1199 /* XXX: Strictly speaking for 64-bit DWARF3 files
1200 this ought to be an 8-byte wide computation. */
1201 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1202 printf ("DW_OP_call2: <0x%s>",
1203 dwarf_vmatoa ("x", svalue
+ cu_offset
));
1206 /* XXX: Strictly speaking for 64-bit DWARF3 files
1207 this ought to be an 8-byte wide computation. */
1208 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
1209 printf ("DW_OP_call4: <0x%s>",
1210 dwarf_vmatoa ("x", svalue
+ cu_offset
));
1212 case DW_OP_call_ref
:
1213 /* XXX: Strictly speaking for 64-bit DWARF3 files
1214 this ought to be an 8-byte wide computation. */
1215 if (dwarf_version
== -1)
1217 printf (_("(DW_OP_call_ref in frame info)"));
1218 /* No way to tell where the next op is, so just bail. */
1219 return need_frame_base
;
1221 if (dwarf_version
== 2)
1223 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1227 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1229 printf ("DW_OP_call_ref: <0x%s>", dwarf_vmatoa ("x", uvalue
));
1231 case DW_OP_form_tls_address
:
1232 printf ("DW_OP_form_tls_address");
1234 case DW_OP_call_frame_cfa
:
1235 printf ("DW_OP_call_frame_cfa");
1237 case DW_OP_bit_piece
:
1238 printf ("DW_OP_bit_piece: ");
1239 printf (_("size: %s "),
1240 dwarf_vmatoa ("u", read_uleb128 (data
, &bytes_read
, end
)));
1242 printf (_("offset: %s "),
1243 dwarf_vmatoa ("u", read_uleb128 (data
, &bytes_read
, end
)));
1247 /* DWARF 4 extensions. */
1248 case DW_OP_stack_value
:
1249 printf ("DW_OP_stack_value");
1252 case DW_OP_implicit_value
:
1253 printf ("DW_OP_implicit_value");
1254 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1256 data
= display_block (data
, uvalue
, end
);
1259 /* GNU extensions. */
1260 case DW_OP_GNU_push_tls_address
:
1261 printf (_("DW_OP_GNU_push_tls_address or DW_OP_HP_unknown"));
1263 case DW_OP_GNU_uninit
:
1264 printf ("DW_OP_GNU_uninit");
1265 /* FIXME: Is there data associated with this OP ? */
1267 case DW_OP_GNU_encoded_addr
:
1274 addr
= get_encoded_value (&data
, encoding
, section
, end
);
1276 printf ("DW_OP_GNU_encoded_addr: fmt:%02x addr:", encoding
);
1277 print_dwarf_vma (addr
, pointer_size
);
1280 case DW_OP_GNU_implicit_pointer
:
1281 /* XXX: Strictly speaking for 64-bit DWARF3 files
1282 this ought to be an 8-byte wide computation. */
1283 if (dwarf_version
== -1)
1285 printf (_("(DW_OP_GNU_implicit_pointer in frame info)"));
1286 /* No way to tell where the next op is, so just bail. */
1287 return need_frame_base
;
1289 if (dwarf_version
== 2)
1291 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1295 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1297 printf ("DW_OP_GNU_implicit_pointer: <0x%s> %s",
1298 dwarf_vmatoa ("x", uvalue
),
1299 dwarf_vmatoa ("d", read_sleb128 (data
,
1300 &bytes_read
, end
)));
1303 case DW_OP_GNU_entry_value
:
1304 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1306 printf ("DW_OP_GNU_entry_value: (");
1307 if (decode_location_expression (data
, pointer_size
, offset_size
,
1308 dwarf_version
, uvalue
,
1309 cu_offset
, section
))
1310 need_frame_base
= 1;
1316 case DW_OP_GNU_const_type
:
1317 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1319 printf ("DW_OP_GNU_const_type: <0x%s> ",
1320 dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1321 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1322 data
= display_block (data
, uvalue
, end
);
1324 case DW_OP_GNU_regval_type
:
1325 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1327 printf ("DW_OP_GNU_regval_type: %s (%s)",
1328 dwarf_vmatoa ("u", uvalue
), regname (uvalue
, 1));
1329 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1331 printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1333 case DW_OP_GNU_deref_type
:
1334 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1335 printf ("DW_OP_GNU_deref_type: %ld", (long) uvalue
);
1336 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1338 printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1340 case DW_OP_GNU_convert
:
1341 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1343 printf ("DW_OP_GNU_convert <0x%s>",
1344 dwarf_vmatoa ("x", uvalue
? cu_offset
+ uvalue
: 0));
1346 case DW_OP_GNU_reinterpret
:
1347 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1349 printf ("DW_OP_GNU_reinterpret <0x%s>",
1350 dwarf_vmatoa ("x", uvalue
? cu_offset
+ uvalue
: 0));
1352 case DW_OP_GNU_parameter_ref
:
1353 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1354 printf ("DW_OP_GNU_parameter_ref: <0x%s>",
1355 dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1357 case DW_OP_GNU_addr_index
:
1358 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1360 printf ("DW_OP_GNU_addr_index <0x%s>", dwarf_vmatoa ("x", uvalue
));
1362 case DW_OP_GNU_const_index
:
1363 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1365 printf ("DW_OP_GNU_const_index <0x%s>", dwarf_vmatoa ("x", uvalue
));
1368 /* HP extensions. */
1369 case DW_OP_HP_is_value
:
1370 printf ("DW_OP_HP_is_value");
1371 /* FIXME: Is there data associated with this OP ? */
1373 case DW_OP_HP_fltconst4
:
1374 printf ("DW_OP_HP_fltconst4");
1375 /* FIXME: Is there data associated with this OP ? */
1377 case DW_OP_HP_fltconst8
:
1378 printf ("DW_OP_HP_fltconst8");
1379 /* FIXME: Is there data associated with this OP ? */
1381 case DW_OP_HP_mod_range
:
1382 printf ("DW_OP_HP_mod_range");
1383 /* FIXME: Is there data associated with this OP ? */
1385 case DW_OP_HP_unmod_range
:
1386 printf ("DW_OP_HP_unmod_range");
1387 /* FIXME: Is there data associated with this OP ? */
1390 printf ("DW_OP_HP_tls");
1391 /* FIXME: Is there data associated with this OP ? */
1394 /* PGI (STMicroelectronics) extensions. */
1395 case DW_OP_PGI_omp_thread_num
:
1396 /* Pushes the thread number for the current thread as it would be
1397 returned by the standard OpenMP library function:
1398 omp_get_thread_num(). The "current thread" is the thread for
1399 which the expression is being evaluated. */
1400 printf ("DW_OP_PGI_omp_thread_num");
1404 if (op
>= DW_OP_lo_user
1405 && op
<= DW_OP_hi_user
)
1406 printf (_("(User defined location op)"));
1408 printf (_("(Unknown location op)"));
1409 /* No way to tell where the next op is, so just bail. */
1410 return need_frame_base
;
1413 /* Separate the ops. */
1418 return need_frame_base
;
1421 /* Find the CU or TU set corresponding to the given CU_OFFSET.
1422 This is used for DWARF package files. */
1424 static struct cu_tu_set
*
1425 find_cu_tu_set_v2 (dwarf_vma cu_offset
, int do_types
)
1427 struct cu_tu_set
*p
;
1429 unsigned int dw_sect
;
1435 dw_sect
= DW_SECT_TYPES
;
1441 dw_sect
= DW_SECT_INFO
;
1445 if (p
->section_offsets
[dw_sect
] == cu_offset
)
1453 /* Add INC to HIGH_BITS:LOW_BITS. */
1455 add64 (dwarf_vma
* high_bits
, dwarf_vma
* low_bits
, dwarf_vma inc
)
1457 dwarf_vma tmp
= * low_bits
;
1461 /* FIXME: There is probably a better way of handling this:
1463 We need to cope with dwarf_vma being a 32-bit or 64-bit
1464 type. Plus regardless of its size LOW_BITS is meant to
1465 only hold 32-bits, so if there is overflow or wrap around
1466 we must propagate into HIGH_BITS. */
1467 if (tmp
< * low_bits
)
1471 else if (sizeof (tmp
) > 8
1481 static unsigned char *
1482 read_and_display_attr_value (unsigned long attribute
,
1484 unsigned char * data
,
1485 unsigned char * end
,
1486 dwarf_vma cu_offset
,
1487 dwarf_vma pointer_size
,
1488 dwarf_vma offset_size
,
1490 debug_info
* debug_info_p
,
1492 struct dwarf_section
* section
,
1493 struct cu_tu_set
* this_set
)
1495 dwarf_vma uvalue
= 0;
1496 unsigned char *block_start
= NULL
;
1497 unsigned char * orig_data
= data
;
1498 unsigned int bytes_read
;
1500 if (data
> end
|| (data
== end
&& form
!= DW_FORM_flag_present
))
1502 warn (_("Corrupt attribute\n"));
1511 case DW_FORM_ref_addr
:
1512 if (dwarf_version
== 2)
1513 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1514 else if (dwarf_version
== 3 || dwarf_version
== 4)
1515 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1517 error (_("Internal error: DWARF version is not 2, 3 or 4.\n"));
1522 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1526 case DW_FORM_sec_offset
:
1527 case DW_FORM_GNU_ref_alt
:
1528 case DW_FORM_GNU_strp_alt
:
1529 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1532 case DW_FORM_flag_present
:
1539 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1544 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
1549 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1553 uvalue
= read_sleb128 (data
, & bytes_read
, end
);
1557 case DW_FORM_GNU_str_index
:
1558 uvalue
= read_uleb128 (data
, & bytes_read
, end
);
1562 case DW_FORM_ref_udata
:
1564 uvalue
= read_uleb128 (data
, & bytes_read
, end
);
1568 case DW_FORM_indirect
:
1569 form
= read_uleb128 (data
, & bytes_read
, end
);
1572 printf (" %s", get_FORM_name (form
));
1573 return read_and_display_attr_value (attribute
, form
, data
, end
,
1574 cu_offset
, pointer_size
,
1575 offset_size
, dwarf_version
,
1576 debug_info_p
, do_loc
,
1578 case DW_FORM_GNU_addr_index
:
1579 uvalue
= read_uleb128 (data
, & bytes_read
, end
);
1586 case DW_FORM_ref_addr
:
1588 printf (" <0x%s>", dwarf_vmatoa ("x",uvalue
));
1591 case DW_FORM_GNU_ref_alt
:
1593 printf (" <alt 0x%s>", dwarf_vmatoa ("x",uvalue
));
1599 case DW_FORM_ref_udata
:
1601 printf (" <0x%s>", dwarf_vmatoa ("x", uvalue
+ cu_offset
));
1606 case DW_FORM_sec_offset
:
1608 printf (" 0x%s", dwarf_vmatoa ("x", uvalue
));
1611 case DW_FORM_flag_present
:
1618 printf (" %s", dwarf_vmatoa ("d", uvalue
));
1625 dwarf_vma high_bits
;
1629 SAFE_BYTE_GET64 (data
, &high_bits
, &uvalue
, end
);
1631 if (form
== DW_FORM_ref8
)
1632 add64 (& high_bits
, & utmp
, cu_offset
);
1634 dwarf_vmatoa64 (high_bits
, utmp
, buf
, sizeof (buf
)));
1637 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
1638 && num_debug_info_entries
== 0)
1640 if (sizeof (uvalue
) == 8)
1641 SAFE_BYTE_GET (uvalue
, data
, 8, end
);
1643 error (_("DW_FORM_data8 is unsupported when sizeof (dwarf_vma) != 8\n"));
1649 case DW_FORM_string
:
1651 printf (" %.*s", (int) (end
- data
), data
);
1652 data
+= strnlen ((char *) data
, end
- data
) + 1;
1656 case DW_FORM_exprloc
:
1657 uvalue
= read_uleb128 (data
, & bytes_read
, end
);
1658 block_start
= data
+ bytes_read
;
1659 if (block_start
>= end
)
1661 warn (_("Block ends prematurely\n"));
1665 /* PR 17512: file: 008-103549-0.001:0.1. */
1666 if (block_start
+ uvalue
> end
)
1668 warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue
);
1669 uvalue
= end
- block_start
;
1672 data
= block_start
+ uvalue
;
1674 data
= display_block (block_start
, uvalue
, end
);
1677 case DW_FORM_block1
:
1678 SAFE_BYTE_GET (uvalue
, data
, 1, end
);
1679 block_start
= data
+ 1;
1680 if (block_start
>= end
)
1682 warn (_("Block ends prematurely\n"));
1686 if (block_start
+ uvalue
> end
)
1688 warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue
);
1689 uvalue
= end
- block_start
;
1692 data
= block_start
+ uvalue
;
1694 data
= display_block (block_start
, uvalue
, end
);
1697 case DW_FORM_block2
:
1698 SAFE_BYTE_GET (uvalue
, data
, 2, end
);
1699 block_start
= data
+ 2;
1700 if (block_start
>= end
)
1702 warn (_("Block ends prematurely\n"));
1706 if (block_start
+ uvalue
> end
)
1708 warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue
);
1709 uvalue
= end
- block_start
;
1712 data
= block_start
+ uvalue
;
1714 data
= display_block (block_start
, uvalue
, end
);
1717 case DW_FORM_block4
:
1718 SAFE_BYTE_GET (uvalue
, data
, 4, end
);
1719 block_start
= data
+ 4;
1720 /* PR 17512: file: 3371-3907-0.004. */
1721 if (block_start
>= end
)
1723 warn (_("Block ends prematurely\n"));
1727 if (block_start
+ uvalue
> end
)
1729 warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue
);
1730 uvalue
= end
- block_start
;
1733 data
= block_start
+ uvalue
;
1735 data
= display_block (block_start
, uvalue
, end
);
1740 printf (_(" (indirect string, offset: 0x%s): %s"),
1741 dwarf_vmatoa ("x", uvalue
),
1742 fetch_indirect_string (uvalue
));
1745 case DW_FORM_GNU_str_index
:
1748 const char *suffix
= strrchr (section
->name
, '.');
1749 int dwo
= (suffix
&& strcmp (suffix
, ".dwo") == 0) ? 1 : 0;
1751 printf (_(" (indexed string: 0x%s): %s"),
1752 dwarf_vmatoa ("x", uvalue
),
1753 fetch_indexed_string (uvalue
, this_set
, offset_size
, dwo
));
1757 case DW_FORM_GNU_strp_alt
:
1759 printf (_(" (alt indirect string, offset: 0x%s)"),
1760 dwarf_vmatoa ("x", uvalue
));
1763 case DW_FORM_indirect
:
1764 /* Handled above. */
1767 case DW_FORM_ref_sig8
:
1770 dwarf_vma high_bits
;
1773 SAFE_BYTE_GET64 (data
, &high_bits
, &uvalue
, end
);
1774 printf (" signature: 0x%s",
1775 dwarf_vmatoa64 (high_bits
, uvalue
, buf
, sizeof (buf
)));
1780 case DW_FORM_GNU_addr_index
:
1782 printf (_(" (addr_index: 0x%s): %s"),
1783 dwarf_vmatoa ("x", uvalue
),
1784 fetch_indexed_value (uvalue
* pointer_size
, pointer_size
));
1788 warn (_("Unrecognized form: %lu\n"), form
);
1792 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
1793 && num_debug_info_entries
== 0
1794 && debug_info_p
!= NULL
)
1798 case DW_AT_frame_base
:
1799 have_frame_base
= 1;
1800 case DW_AT_location
:
1801 case DW_AT_string_length
:
1802 case DW_AT_return_addr
:
1803 case DW_AT_data_member_location
:
1804 case DW_AT_vtable_elem_location
:
1806 case DW_AT_static_link
:
1807 case DW_AT_use_location
:
1808 case DW_AT_GNU_call_site_value
:
1809 case DW_AT_GNU_call_site_data_value
:
1810 case DW_AT_GNU_call_site_target
:
1811 case DW_AT_GNU_call_site_target_clobbered
:
1812 if ((dwarf_version
< 4
1813 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
1814 || form
== DW_FORM_sec_offset
)
1816 /* Process location list. */
1817 unsigned int lmax
= debug_info_p
->max_loc_offsets
;
1818 unsigned int num
= debug_info_p
->num_loc_offsets
;
1820 if (lmax
== 0 || num
>= lmax
)
1823 debug_info_p
->loc_offsets
= (dwarf_vma
*)
1824 xcrealloc (debug_info_p
->loc_offsets
,
1825 lmax
, sizeof (*debug_info_p
->loc_offsets
));
1826 debug_info_p
->have_frame_base
= (int *)
1827 xcrealloc (debug_info_p
->have_frame_base
,
1828 lmax
, sizeof (*debug_info_p
->have_frame_base
));
1829 debug_info_p
->max_loc_offsets
= lmax
;
1831 if (this_set
!= NULL
)
1832 uvalue
+= this_set
->section_offsets
[DW_SECT_LOC
];
1833 debug_info_p
->loc_offsets
[num
] = uvalue
;
1834 debug_info_p
->have_frame_base
[num
] = have_frame_base
;
1835 debug_info_p
->num_loc_offsets
++;
1840 if (need_base_address
)
1841 debug_info_p
->base_address
= uvalue
;
1844 case DW_AT_GNU_addr_base
:
1845 debug_info_p
->addr_base
= uvalue
;
1848 case DW_AT_GNU_ranges_base
:
1849 debug_info_p
->ranges_base
= uvalue
;
1853 if ((dwarf_version
< 4
1854 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
1855 || form
== DW_FORM_sec_offset
)
1857 /* Process range list. */
1858 unsigned int lmax
= debug_info_p
->max_range_lists
;
1859 unsigned int num
= debug_info_p
->num_range_lists
;
1861 if (lmax
== 0 || num
>= lmax
)
1864 debug_info_p
->range_lists
= (dwarf_vma
*)
1865 xcrealloc (debug_info_p
->range_lists
,
1866 lmax
, sizeof (*debug_info_p
->range_lists
));
1867 debug_info_p
->max_range_lists
= lmax
;
1869 debug_info_p
->range_lists
[num
] = uvalue
;
1870 debug_info_p
->num_range_lists
++;
1879 if (do_loc
|| attribute
== 0)
1882 /* For some attributes we can display further information. */
1889 case DW_INL_not_inlined
:
1890 printf (_("(not inlined)"));
1892 case DW_INL_inlined
:
1893 printf (_("(inlined)"));
1895 case DW_INL_declared_not_inlined
:
1896 printf (_("(declared as inline but ignored)"));
1898 case DW_INL_declared_inlined
:
1899 printf (_("(declared as inline and inlined)"));
1902 printf (_(" (Unknown inline attribute value: %s)"),
1903 dwarf_vmatoa ("x", uvalue
));
1908 case DW_AT_language
:
1912 /* Ordered by the numeric value of these constants. */
1913 case DW_LANG_C89
: printf ("(ANSI C)"); break;
1914 case DW_LANG_C
: printf ("(non-ANSI C)"); break;
1915 case DW_LANG_Ada83
: printf ("(Ada)"); break;
1916 case DW_LANG_C_plus_plus
: printf ("(C++)"); break;
1917 case DW_LANG_Cobol74
: printf ("(Cobol 74)"); break;
1918 case DW_LANG_Cobol85
: printf ("(Cobol 85)"); break;
1919 case DW_LANG_Fortran77
: printf ("(FORTRAN 77)"); break;
1920 case DW_LANG_Fortran90
: printf ("(Fortran 90)"); break;
1921 case DW_LANG_Pascal83
: printf ("(ANSI Pascal)"); break;
1922 case DW_LANG_Modula2
: printf ("(Modula 2)"); break;
1923 /* DWARF 2.1 values. */
1924 case DW_LANG_Java
: printf ("(Java)"); break;
1925 case DW_LANG_C99
: printf ("(ANSI C99)"); break;
1926 case DW_LANG_Ada95
: printf ("(ADA 95)"); break;
1927 case DW_LANG_Fortran95
: printf ("(Fortran 95)"); break;
1928 /* DWARF 3 values. */
1929 case DW_LANG_PLI
: printf ("(PLI)"); break;
1930 case DW_LANG_ObjC
: printf ("(Objective C)"); break;
1931 case DW_LANG_ObjC_plus_plus
: printf ("(Objective C++)"); break;
1932 case DW_LANG_UPC
: printf ("(Unified Parallel C)"); break;
1933 case DW_LANG_D
: printf ("(D)"); break;
1934 /* DWARF 4 values. */
1935 case DW_LANG_Python
: printf ("(Python)"); break;
1936 /* DWARF 5 values. */
1937 case DW_LANG_Go
: printf ("(Go)"); break;
1938 case DW_LANG_C_plus_plus_11
: printf ("(C++11)"); break;
1939 case DW_LANG_C11
: printf ("(ANSI C11)"); break;
1940 case DW_LANG_C_plus_plus_14
: printf ("(C++14)"); break;
1941 /* MIPS extension. */
1942 case DW_LANG_Mips_Assembler
: printf ("(MIPS assembler)"); break;
1943 /* UPC extension. */
1944 case DW_LANG_Upc
: printf ("(Unified Parallel C)"); break;
1946 if (uvalue
>= DW_LANG_lo_user
&& uvalue
<= DW_LANG_hi_user
)
1947 printf (_("(implementation defined: %s)"),
1948 dwarf_vmatoa ("x", uvalue
));
1950 printf (_("(Unknown: %s)"), dwarf_vmatoa ("x", uvalue
));
1955 case DW_AT_encoding
:
1959 case DW_ATE_void
: printf ("(void)"); break;
1960 case DW_ATE_address
: printf ("(machine address)"); break;
1961 case DW_ATE_boolean
: printf ("(boolean)"); break;
1962 case DW_ATE_complex_float
: printf ("(complex float)"); break;
1963 case DW_ATE_float
: printf ("(float)"); break;
1964 case DW_ATE_signed
: printf ("(signed)"); break;
1965 case DW_ATE_signed_char
: printf ("(signed char)"); break;
1966 case DW_ATE_unsigned
: printf ("(unsigned)"); break;
1967 case DW_ATE_unsigned_char
: printf ("(unsigned char)"); break;
1968 /* DWARF 2.1 values: */
1969 case DW_ATE_imaginary_float
: printf ("(imaginary float)"); break;
1970 case DW_ATE_decimal_float
: printf ("(decimal float)"); break;
1971 /* DWARF 3 values: */
1972 case DW_ATE_packed_decimal
: printf ("(packed_decimal)"); break;
1973 case DW_ATE_numeric_string
: printf ("(numeric_string)"); break;
1974 case DW_ATE_edited
: printf ("(edited)"); break;
1975 case DW_ATE_signed_fixed
: printf ("(signed_fixed)"); break;
1976 case DW_ATE_unsigned_fixed
: printf ("(unsigned_fixed)"); break;
1977 /* HP extensions: */
1978 case DW_ATE_HP_float80
: printf ("(HP_float80)"); break;
1979 case DW_ATE_HP_complex_float80
: printf ("(HP_complex_float80)"); break;
1980 case DW_ATE_HP_float128
: printf ("(HP_float128)"); break;
1981 case DW_ATE_HP_complex_float128
:printf ("(HP_complex_float128)"); break;
1982 case DW_ATE_HP_floathpintel
: printf ("(HP_floathpintel)"); break;
1983 case DW_ATE_HP_imaginary_float80
: printf ("(HP_imaginary_float80)"); break;
1984 case DW_ATE_HP_imaginary_float128
: printf ("(HP_imaginary_float128)"); break;
1987 if (uvalue
>= DW_ATE_lo_user
1988 && uvalue
<= DW_ATE_hi_user
)
1989 printf (_("(user defined type)"));
1991 printf (_("(unknown type)"));
1996 case DW_AT_accessibility
:
2000 case DW_ACCESS_public
: printf ("(public)"); break;
2001 case DW_ACCESS_protected
: printf ("(protected)"); break;
2002 case DW_ACCESS_private
: printf ("(private)"); break;
2004 printf (_("(unknown accessibility)"));
2009 case DW_AT_visibility
:
2013 case DW_VIS_local
: printf ("(local)"); break;
2014 case DW_VIS_exported
: printf ("(exported)"); break;
2015 case DW_VIS_qualified
: printf ("(qualified)"); break;
2016 default: printf (_("(unknown visibility)")); break;
2020 case DW_AT_virtuality
:
2024 case DW_VIRTUALITY_none
: printf ("(none)"); break;
2025 case DW_VIRTUALITY_virtual
: printf ("(virtual)"); break;
2026 case DW_VIRTUALITY_pure_virtual
:printf ("(pure_virtual)"); break;
2027 default: printf (_("(unknown virtuality)")); break;
2031 case DW_AT_identifier_case
:
2035 case DW_ID_case_sensitive
: printf ("(case_sensitive)"); break;
2036 case DW_ID_up_case
: printf ("(up_case)"); break;
2037 case DW_ID_down_case
: printf ("(down_case)"); break;
2038 case DW_ID_case_insensitive
: printf ("(case_insensitive)"); break;
2039 default: printf (_("(unknown case)")); break;
2043 case DW_AT_calling_convention
:
2047 case DW_CC_normal
: printf ("(normal)"); break;
2048 case DW_CC_program
: printf ("(program)"); break;
2049 case DW_CC_nocall
: printf ("(nocall)"); break;
2051 if (uvalue
>= DW_CC_lo_user
2052 && uvalue
<= DW_CC_hi_user
)
2053 printf (_("(user defined)"));
2055 printf (_("(unknown convention)"));
2059 case DW_AT_ordering
:
2063 case -1: printf (_("(undefined)")); break;
2064 case 0: printf ("(row major)"); break;
2065 case 1: printf ("(column major)"); break;
2069 case DW_AT_frame_base
:
2070 have_frame_base
= 1;
2071 case DW_AT_location
:
2072 case DW_AT_string_length
:
2073 case DW_AT_return_addr
:
2074 case DW_AT_data_member_location
:
2075 case DW_AT_vtable_elem_location
:
2077 case DW_AT_static_link
:
2078 case DW_AT_use_location
:
2079 case DW_AT_GNU_call_site_value
:
2080 case DW_AT_GNU_call_site_data_value
:
2081 case DW_AT_GNU_call_site_target
:
2082 case DW_AT_GNU_call_site_target_clobbered
:
2083 if ((dwarf_version
< 4
2084 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
2085 || form
== DW_FORM_sec_offset
)
2086 printf (_(" (location list)"));
2088 case DW_AT_allocated
:
2089 case DW_AT_associated
:
2090 case DW_AT_data_location
:
2092 case DW_AT_upper_bound
:
2093 case DW_AT_lower_bound
:
2096 int need_frame_base
;
2099 need_frame_base
= decode_location_expression (block_start
,
2104 cu_offset
, section
);
2106 if (need_frame_base
&& !have_frame_base
)
2107 printf (_(" [without DW_AT_frame_base]"));
2113 if (form
== DW_FORM_ref_sig8
2114 || form
== DW_FORM_GNU_ref_alt
)
2117 if (form
== DW_FORM_ref1
2118 || form
== DW_FORM_ref2
2119 || form
== DW_FORM_ref4
2120 || form
== DW_FORM_ref_udata
)
2121 uvalue
+= cu_offset
;
2123 if (uvalue
>= section
->size
)
2124 warn (_("Offset %s used as value for DW_AT_import attribute of DIE at offset %lx is too big.\n"),
2125 dwarf_vmatoa ("x", uvalue
),
2126 (unsigned long) (orig_data
- section
->start
));
2129 unsigned long abbrev_number
;
2130 abbrev_entry
* entry
;
2132 abbrev_number
= read_uleb128 (section
->start
+ uvalue
, NULL
, end
);
2134 printf (_("\t[Abbrev Number: %ld"), abbrev_number
);
2135 /* Don't look up abbrev for DW_FORM_ref_addr, as it very often will
2136 use different abbrev table, and we don't track .debug_info chunks
2138 if (form
!= DW_FORM_ref_addr
)
2140 for (entry
= first_abbrev
; entry
!= NULL
; entry
= entry
->next
)
2141 if (entry
->entry
== abbrev_number
)
2144 printf (" (%s)", get_TAG_name (entry
->tag
));
2159 get_AT_name (unsigned long attribute
)
2164 return "DW_AT value: 0";
2166 /* One value is shared by the MIPS and HP extensions: */
2167 if (attribute
== DW_AT_MIPS_fde
)
2168 return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable";
2170 name
= get_DW_AT_name (attribute
);
2174 static char buffer
[100];
2176 snprintf (buffer
, sizeof (buffer
), _("Unknown AT value: %lx"),
2184 static unsigned char *
2185 read_and_display_attr (unsigned long attribute
,
2187 unsigned char * data
,
2188 unsigned char * end
,
2189 dwarf_vma cu_offset
,
2190 dwarf_vma pointer_size
,
2191 dwarf_vma offset_size
,
2193 debug_info
* debug_info_p
,
2195 struct dwarf_section
* section
,
2196 struct cu_tu_set
* this_set
)
2199 printf (" %-18s:", get_AT_name (attribute
));
2200 data
= read_and_display_attr_value (attribute
, form
, data
, end
,
2201 cu_offset
, pointer_size
, offset_size
,
2202 dwarf_version
, debug_info_p
,
2203 do_loc
, section
, this_set
);
2209 /* Process the contents of a .debug_info section. If do_loc is non-zero
2210 then we are scanning for location lists and we do not want to display
2211 anything to the user. If do_types is non-zero, we are processing
2212 a .debug_types section instead of a .debug_info section. */
2215 process_debug_info (struct dwarf_section
*section
,
2217 enum dwarf_section_display_enum abbrev_sec
,
2221 unsigned char *start
= section
->start
;
2222 unsigned char *end
= start
+ section
->size
;
2223 unsigned char *section_begin
;
2225 unsigned int num_units
= 0;
2227 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
2228 && num_debug_info_entries
== 0
2233 /* First scan the section to get the number of comp units. */
2234 for (section_begin
= start
, num_units
= 0; section_begin
< end
;
2237 /* Read the first 4 bytes. For a 32-bit DWARF section, this
2238 will be the length. For a 64-bit DWARF section, it'll be
2239 the escape code 0xffffffff followed by an 8 byte length. */
2240 SAFE_BYTE_GET (length
, section_begin
, 4, end
);
2242 if (length
== 0xffffffff)
2244 SAFE_BYTE_GET (length
, section_begin
+ 4, 8, end
);
2245 section_begin
+= length
+ 12;
2247 else if (length
>= 0xfffffff0 && length
< 0xffffffff)
2249 warn (_("Reserved length value (0x%s) found in section %s\n"),
2250 dwarf_vmatoa ("x", length
), section
->name
);
2254 section_begin
+= length
+ 4;
2256 /* Negative values are illegal, they may even cause infinite
2257 looping. This can happen if we can't accurately apply
2258 relocations to an object file. */
2259 if ((signed long) length
<= 0)
2261 warn (_("Corrupt unit length (0x%s) found in section %s\n"),
2262 dwarf_vmatoa ("x", length
), section
->name
);
2269 error (_("No comp units in %s section ?\n"), section
->name
);
2273 /* Then allocate an array to hold the information. */
2274 debug_information
= (debug_info
*) cmalloc (num_units
,
2275 sizeof (* debug_information
));
2276 if (debug_information
== NULL
)
2278 error (_("Not enough memory for a debug info array of %u entries\n"),
2286 if (dwarf_start_die
== 0)
2287 printf (_("Contents of the %s section:\n\n"), section
->name
);
2289 load_debug_section (str
, file
);
2290 load_debug_section (str_dwo
, file
);
2291 load_debug_section (str_index
, file
);
2292 load_debug_section (str_index_dwo
, file
);
2293 load_debug_section (debug_addr
, file
);
2296 load_debug_section (abbrev_sec
, file
);
2297 if (debug_displays
[abbrev_sec
].section
.start
== NULL
)
2299 warn (_("Unable to locate %s section!\n"),
2300 debug_displays
[abbrev_sec
].section
.name
);
2304 for (section_begin
= start
, unit
= 0; start
< end
; unit
++)
2306 DWARF2_Internal_CompUnit compunit
;
2307 unsigned char *hdrptr
;
2308 unsigned char *tags
;
2309 int level
, last_level
, saved_level
;
2310 dwarf_vma cu_offset
;
2311 unsigned int offset_size
;
2312 int initial_length_size
;
2313 dwarf_vma signature_high
= 0;
2314 dwarf_vma signature_low
= 0;
2315 dwarf_vma type_offset
= 0;
2316 struct cu_tu_set
*this_set
;
2317 dwarf_vma abbrev_base
;
2322 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 4, end
);
2324 if (compunit
.cu_length
== 0xffffffff)
2326 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 8, end
);
2328 initial_length_size
= 12;
2333 initial_length_size
= 4;
2336 SAFE_BYTE_GET_AND_INC (compunit
.cu_version
, hdrptr
, 2, end
);
2338 cu_offset
= start
- section_begin
;
2340 this_set
= find_cu_tu_set_v2 (cu_offset
, do_types
);
2342 SAFE_BYTE_GET_AND_INC (compunit
.cu_abbrev_offset
, hdrptr
, offset_size
, end
);
2344 if (this_set
== NULL
)
2347 abbrev_size
= debug_displays
[abbrev_sec
].section
.size
;
2351 abbrev_base
= this_set
->section_offsets
[DW_SECT_ABBREV
];
2352 abbrev_size
= this_set
->section_sizes
[DW_SECT_ABBREV
];
2355 SAFE_BYTE_GET_AND_INC (compunit
.cu_pointer_size
, hdrptr
, 1, end
);
2356 /* PR 17512: file: 001-108546-0.001:0.1. */
2357 if (compunit
.cu_pointer_size
< 2 || compunit
.cu_pointer_size
> 8)
2359 warn (_("Invalid pointer size (%d) in compunit header, using %d instead\n"),
2360 compunit
.cu_pointer_size
, offset_size
);
2361 compunit
.cu_pointer_size
= offset_size
;
2366 SAFE_BYTE_GET64 (hdrptr
, &signature_high
, &signature_low
, end
);
2368 SAFE_BYTE_GET_AND_INC (type_offset
, hdrptr
, offset_size
, end
);
2371 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
2372 && num_debug_info_entries
== 0
2375 debug_information
[unit
].cu_offset
= cu_offset
;
2376 debug_information
[unit
].pointer_size
2377 = compunit
.cu_pointer_size
;
2378 debug_information
[unit
].offset_size
= offset_size
;
2379 debug_information
[unit
].dwarf_version
= compunit
.cu_version
;
2380 debug_information
[unit
].base_address
= 0;
2381 debug_information
[unit
].addr_base
= DEBUG_INFO_UNAVAILABLE
;
2382 debug_information
[unit
].ranges_base
= DEBUG_INFO_UNAVAILABLE
;
2383 debug_information
[unit
].loc_offsets
= NULL
;
2384 debug_information
[unit
].have_frame_base
= NULL
;
2385 debug_information
[unit
].max_loc_offsets
= 0;
2386 debug_information
[unit
].num_loc_offsets
= 0;
2387 debug_information
[unit
].range_lists
= NULL
;
2388 debug_information
[unit
].max_range_lists
= 0;
2389 debug_information
[unit
].num_range_lists
= 0;
2392 if (!do_loc
&& dwarf_start_die
== 0)
2394 printf (_(" Compilation Unit @ offset 0x%s:\n"),
2395 dwarf_vmatoa ("x", cu_offset
));
2396 printf (_(" Length: 0x%s (%s)\n"),
2397 dwarf_vmatoa ("x", compunit
.cu_length
),
2398 offset_size
== 8 ? "64-bit" : "32-bit");
2399 printf (_(" Version: %d\n"), compunit
.cu_version
);
2400 printf (_(" Abbrev Offset: 0x%s\n"),
2401 dwarf_vmatoa ("x", compunit
.cu_abbrev_offset
));
2402 printf (_(" Pointer Size: %d\n"), compunit
.cu_pointer_size
);
2407 printf (_(" Signature: 0x%s\n"),
2408 dwarf_vmatoa64 (signature_high
, signature_low
,
2409 buf
, sizeof (buf
)));
2410 printf (_(" Type Offset: 0x%s\n"),
2411 dwarf_vmatoa ("x", type_offset
));
2413 if (this_set
!= NULL
)
2415 dwarf_vma
*offsets
= this_set
->section_offsets
;
2416 size_t *sizes
= this_set
->section_sizes
;
2418 printf (_(" Section contributions:\n"));
2419 printf (_(" .debug_abbrev.dwo: 0x%s 0x%s\n"),
2420 dwarf_vmatoa ("x", offsets
[DW_SECT_ABBREV
]),
2421 dwarf_vmatoa ("x", sizes
[DW_SECT_ABBREV
]));
2422 printf (_(" .debug_line.dwo: 0x%s 0x%s\n"),
2423 dwarf_vmatoa ("x", offsets
[DW_SECT_LINE
]),
2424 dwarf_vmatoa ("x", sizes
[DW_SECT_LINE
]));
2425 printf (_(" .debug_loc.dwo: 0x%s 0x%s\n"),
2426 dwarf_vmatoa ("x", offsets
[DW_SECT_LOC
]),
2427 dwarf_vmatoa ("x", sizes
[DW_SECT_LOC
]));
2428 printf (_(" .debug_str_offsets.dwo: 0x%s 0x%s\n"),
2429 dwarf_vmatoa ("x", offsets
[DW_SECT_STR_OFFSETS
]),
2430 dwarf_vmatoa ("x", sizes
[DW_SECT_STR_OFFSETS
]));
2434 if (cu_offset
+ compunit
.cu_length
+ initial_length_size
2437 warn (_("Debug info is corrupted, length of CU at %s"
2438 " extends beyond end of section (length = %s)\n"),
2439 dwarf_vmatoa ("x", cu_offset
),
2440 dwarf_vmatoa ("x", compunit
.cu_length
));
2444 start
+= compunit
.cu_length
+ initial_length_size
;
2446 if (compunit
.cu_version
!= 2
2447 && compunit
.cu_version
!= 3
2448 && compunit
.cu_version
!= 4)
2450 warn (_("CU at offset %s contains corrupt or "
2451 "unsupported version number: %d.\n"),
2452 dwarf_vmatoa ("x", cu_offset
), compunit
.cu_version
);
2458 /* Process the abbrevs used by this compilation unit. */
2459 if (compunit
.cu_abbrev_offset
>= abbrev_size
)
2460 warn (_("Debug info is corrupted, abbrev offset (%lx) is larger than abbrev section size (%lx)\n"),
2461 (unsigned long) compunit
.cu_abbrev_offset
,
2462 (unsigned long) abbrev_size
);
2464 process_abbrev_section
2465 (((unsigned char *) debug_displays
[abbrev_sec
].section
.start
2466 + abbrev_base
+ compunit
.cu_abbrev_offset
),
2467 ((unsigned char *) debug_displays
[abbrev_sec
].section
.start
2468 + abbrev_base
+ abbrev_size
));
2473 while (tags
< start
)
2475 unsigned int bytes_read
;
2476 unsigned long abbrev_number
;
2477 unsigned long die_offset
;
2478 abbrev_entry
*entry
;
2480 int do_printing
= 1;
2482 die_offset
= tags
- section_begin
;
2484 abbrev_number
= read_uleb128 (tags
, & bytes_read
, start
);
2487 /* A null DIE marks the end of a list of siblings or it may also be
2488 a section padding. */
2489 if (abbrev_number
== 0)
2491 /* Check if it can be a section padding for the last CU. */
2492 if (level
== 0 && start
== end
)
2496 for (chk
= tags
; chk
< start
; chk
++)
2503 if (!do_loc
&& die_offset
>= dwarf_start_die
2504 && (dwarf_cutoff_level
== -1
2505 || level
< dwarf_cutoff_level
))
2506 printf (_(" <%d><%lx>: Abbrev Number: 0\n"),
2512 static unsigned num_bogus_warns
= 0;
2514 if (num_bogus_warns
< 3)
2516 warn (_("Bogus end-of-siblings marker detected at offset %lx in %s section\n"),
2517 die_offset
, section
->name
);
2519 if (num_bogus_warns
== 3)
2520 warn (_("Further warnings about bogus end-of-sibling markers suppressed\n"));
2523 if (dwarf_start_die
!= 0 && level
< saved_level
)
2530 if (dwarf_start_die
!= 0 && die_offset
< dwarf_start_die
)
2534 if (dwarf_start_die
!= 0 && die_offset
== dwarf_start_die
)
2535 saved_level
= level
;
2536 do_printing
= (dwarf_cutoff_level
== -1
2537 || level
< dwarf_cutoff_level
);
2539 printf (_(" <%d><%lx>: Abbrev Number: %lu"),
2540 level
, die_offset
, abbrev_number
);
2541 else if (dwarf_cutoff_level
== -1
2542 || last_level
< dwarf_cutoff_level
)
2543 printf (_(" <%d><%lx>: ...\n"), level
, die_offset
);
2548 /* Scan through the abbreviation list until we reach the
2550 for (entry
= first_abbrev
;
2551 entry
&& entry
->entry
!= abbrev_number
;
2552 entry
= entry
->next
)
2557 if (!do_loc
&& do_printing
)
2562 warn (_("DIE at offset %lx refers to abbreviation number %lu which does not exist\n"),
2563 die_offset
, abbrev_number
);
2567 if (!do_loc
&& do_printing
)
2568 printf (" (%s)\n", get_TAG_name (entry
->tag
));
2573 need_base_address
= 0;
2575 case DW_TAG_compile_unit
:
2576 need_base_address
= 1;
2578 case DW_TAG_entry_point
:
2579 case DW_TAG_subprogram
:
2580 need_base_address
= 0;
2581 /* Assuming that there is no DW_AT_frame_base. */
2582 have_frame_base
= 0;
2586 for (attr
= entry
->first_attr
;
2587 attr
&& attr
->attribute
;
2592 if (! do_loc
&& do_printing
)
2593 /* Show the offset from where the tag was extracted. */
2594 printf (" <%lx>", (unsigned long)(tags
- section_begin
));
2596 arg
= debug_information
;
2597 if (debug_information
)
2600 tags
= read_and_display_attr (attr
->attribute
,
2605 compunit
.cu_pointer_size
,
2607 compunit
.cu_version
,
2609 do_loc
|| ! do_printing
,
2614 if (entry
->children
)
2619 /* Set num_debug_info_entries here so that it can be used to check if
2620 we need to process .debug_loc and .debug_ranges sections. */
2621 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
2622 && num_debug_info_entries
== 0
2624 num_debug_info_entries
= num_units
;
2632 /* Locate and scan the .debug_info section in the file and record the pointer
2633 sizes and offsets for the compilation units in it. Usually an executable
2634 will have just one pointer size, but this is not guaranteed, and so we try
2635 not to make any assumptions. Returns zero upon failure, or the number of
2636 compilation units upon success. */
2639 load_debug_info (void * file
)
2641 /* Reset the last pointer size so that we can issue correct error
2642 messages if we are displaying the contents of more than one section. */
2643 last_pointer_size
= 0;
2644 warned_about_missing_comp_units
= FALSE
;
2646 /* If we have already tried and failed to load the .debug_info
2647 section then do not bother to repeat the task. */
2648 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
2651 /* If we already have the information there is nothing else to do. */
2652 if (num_debug_info_entries
> 0)
2653 return num_debug_info_entries
;
2655 /* If this is a DWARF package file, load the CU and TU indexes. */
2656 load_cu_tu_indexes (file
);
2658 if (load_debug_section (info
, file
)
2659 && process_debug_info (&debug_displays
[info
].section
, file
, abbrev
, 1, 0))
2660 return num_debug_info_entries
;
2661 else if (load_debug_section (info_dwo
, file
)
2662 && process_debug_info (&debug_displays
[info_dwo
].section
, file
,
2664 return num_debug_info_entries
;
2666 num_debug_info_entries
= DEBUG_INFO_UNAVAILABLE
;
2670 /* Read a DWARF .debug_line section header starting at DATA.
2671 Upon success returns an updated DATA pointer and the LINFO
2672 structure and the END_OF_SEQUENCE pointer will be filled in.
2673 Otherwise returns NULL. */
2675 static unsigned char *
2676 read_debug_line_header (struct dwarf_section
* section
,
2677 unsigned char * data
,
2678 unsigned char * end
,
2679 DWARF2_Internal_LineInfo
* linfo
,
2680 unsigned char ** end_of_sequence
)
2682 unsigned char *hdrptr
;
2683 unsigned int offset_size
;
2684 unsigned int initial_length_size
;
2686 /* Extract information from the Line Number Program Header.
2687 (section 6.2.4 in the Dwarf3 doc). */
2690 /* Get and check the length of the block. */
2691 SAFE_BYTE_GET_AND_INC (linfo
->li_length
, hdrptr
, 4, end
);
2693 if (linfo
->li_length
== 0xffffffff)
2695 /* This section is 64-bit DWARF 3. */
2696 SAFE_BYTE_GET_AND_INC (linfo
->li_length
, hdrptr
, 8, end
);
2698 initial_length_size
= 12;
2703 initial_length_size
= 4;
2706 if (linfo
->li_length
+ initial_length_size
> section
->size
)
2708 /* If the length is just a bias against the initial_length_size then
2709 this means that the field has a relocation against it which has not
2710 been applied. (Ie we are dealing with an object file, not a linked
2711 binary). Do not complain but instead assume that the rest of the
2712 section applies to this particular header. */
2713 if (linfo
->li_length
== - initial_length_size
)
2715 linfo
->li_length
= section
->size
- initial_length_size
;
2719 warn (_("The line info appears to be corrupt - the section is too small\n"));
2724 /* Get and check the version number. */
2725 SAFE_BYTE_GET_AND_INC (linfo
->li_version
, hdrptr
, 2, end
);
2727 if (linfo
->li_version
!= 2
2728 && linfo
->li_version
!= 3
2729 && linfo
->li_version
!= 4)
2731 warn (_("Only DWARF version 2, 3 and 4 line info is currently supported.\n"));
2735 SAFE_BYTE_GET_AND_INC (linfo
->li_prologue_length
, hdrptr
, offset_size
, end
);
2736 SAFE_BYTE_GET_AND_INC (linfo
->li_min_insn_length
, hdrptr
, 1, end
);
2738 if (linfo
->li_version
>= 4)
2740 SAFE_BYTE_GET_AND_INC (linfo
->li_max_ops_per_insn
, hdrptr
, 1, end
);
2742 if (linfo
->li_max_ops_per_insn
== 0)
2744 warn (_("Invalid maximum operations per insn.\n"));
2749 linfo
->li_max_ops_per_insn
= 1;
2751 SAFE_BYTE_GET_AND_INC (linfo
->li_default_is_stmt
, hdrptr
, 1, end
);
2752 SAFE_SIGNED_BYTE_GET_AND_INC (linfo
->li_line_base
, hdrptr
, 1, end
);
2753 SAFE_BYTE_GET_AND_INC (linfo
->li_line_range
, hdrptr
, 1, end
);
2754 SAFE_BYTE_GET_AND_INC (linfo
->li_opcode_base
, hdrptr
, 1, end
);
2756 * end_of_sequence
= data
+ linfo
->li_length
+ initial_length_size
;
2757 /* PR 17512: file:002-117414-0.004. */
2758 if (* end_of_sequence
> end
)
2760 warn (_("Line length %lld extends beyond end of section\n"), linfo
->li_length
);
2761 * end_of_sequence
= end
;
2769 display_debug_lines_raw (struct dwarf_section
*section
,
2770 unsigned char *data
,
2773 unsigned char *start
= section
->start
;
2775 printf (_("Raw dump of debug contents of section %s:\n\n"),
2780 static DWARF2_Internal_LineInfo saved_linfo
;
2781 DWARF2_Internal_LineInfo linfo
;
2782 unsigned char *standard_opcodes
;
2783 unsigned char *end_of_sequence
;
2784 unsigned int last_dir_entry
= 0;
2787 if (const_strneq (section
->name
, ".debug_line.")
2788 /* Note: the following does not apply to .debug_line.dwo sections.
2789 These are full debug_line sections. */
2790 && strcmp (section
->name
, ".debug_line.dwo") != 0)
2792 /* Sections named .debug_line.<foo> are fragments of a .debug_line
2793 section containing just the Line Number Statements. They are
2794 created by the assembler and intended to be used alongside gcc's
2795 -ffunction-sections command line option. When the linker's
2796 garbage collection decides to discard a .text.<foo> section it
2797 can then also discard the line number information in .debug_line.<foo>.
2799 Since the section is a fragment it does not have the details
2800 needed to fill out a LineInfo structure, so instead we use the
2801 details from the last full debug_line section that we processed. */
2802 end_of_sequence
= end
;
2803 standard_opcodes
= NULL
;
2804 linfo
= saved_linfo
;
2805 reset_state_machine (linfo
.li_default_is_stmt
);
2809 unsigned char * hdrptr
;
2811 if ((hdrptr
= read_debug_line_header (section
, data
, end
, & linfo
,
2812 & end_of_sequence
)) == NULL
)
2815 printf (_(" Offset: 0x%lx\n"), (long)(data
- start
));
2816 printf (_(" Length: %ld\n"), (long) linfo
.li_length
);
2817 printf (_(" DWARF Version: %d\n"), linfo
.li_version
);
2818 printf (_(" Prologue Length: %d\n"), linfo
.li_prologue_length
);
2819 printf (_(" Minimum Instruction Length: %d\n"), linfo
.li_min_insn_length
);
2820 if (linfo
.li_version
>= 4)
2821 printf (_(" Maximum Ops per Instruction: %d\n"), linfo
.li_max_ops_per_insn
);
2822 printf (_(" Initial value of 'is_stmt': %d\n"), linfo
.li_default_is_stmt
);
2823 printf (_(" Line Base: %d\n"), linfo
.li_line_base
);
2824 printf (_(" Line Range: %d\n"), linfo
.li_line_range
);
2825 printf (_(" Opcode Base: %d\n"), linfo
.li_opcode_base
);
2827 /* PR 17512: file: 1665-6428-0.004. */
2828 if (linfo
.li_line_range
== 0)
2830 warn (_("Line range of 0 is invalid, using 1 instead\n"));
2831 linfo
.li_line_range
= 1;
2834 reset_state_machine (linfo
.li_default_is_stmt
);
2836 /* Display the contents of the Opcodes table. */
2837 standard_opcodes
= hdrptr
;
2839 /* PR 17512: file: 002-417945-0.004. */
2840 if (standard_opcodes
+ linfo
.li_opcode_base
>= end
)
2842 warn (_("Line Base extends beyond end of section\n"));
2846 printf (_("\n Opcodes:\n"));
2848 for (i
= 1; i
< linfo
.li_opcode_base
; i
++)
2849 printf (_(" Opcode %d has %d args\n"), i
, standard_opcodes
[i
- 1]);
2851 /* Display the contents of the Directory table. */
2852 data
= standard_opcodes
+ linfo
.li_opcode_base
- 1;
2855 printf (_("\n The Directory Table is empty.\n"));
2858 printf (_("\n The Directory Table (offset 0x%lx):\n"),
2859 (long)(data
- start
));
2861 while (data
< end
&& *data
!= 0)
2863 printf (" %d\t%.*s\n", ++last_dir_entry
, (int) (end
- data
), data
);
2865 data
+= strnlen ((char *) data
, end
- data
) + 1;
2868 /* PR 17512: file: 002-132094-0.004. */
2869 if (data
>= end
- 1)
2873 /* Skip the NUL at the end of the table. */
2876 /* Display the contents of the File Name table. */
2878 printf (_("\n The File Name Table is empty.\n"));
2881 printf (_("\n The File Name Table (offset 0x%lx):\n"),
2882 (long)(data
- start
));
2883 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
2885 while (data
< end
&& *data
!= 0)
2887 unsigned char *name
;
2888 unsigned int bytes_read
;
2890 printf (" %d\t", ++state_machine_regs
.last_file_entry
);
2892 data
+= strnlen ((char *) data
, end
- data
) + 1;
2895 dwarf_vmatoa ("u", read_uleb128 (data
, & bytes_read
, end
)));
2898 dwarf_vmatoa ("u", read_uleb128 (data
, & bytes_read
, end
)));
2901 dwarf_vmatoa ("u", read_uleb128 (data
, & bytes_read
, end
)));
2903 printf ("%.*s\n", (int)(end
- name
), name
);
2907 warn (_("Corrupt file name table entry\n"));
2913 /* Skip the NUL at the end of the table. */
2916 saved_linfo
= linfo
;
2919 /* Now display the statements. */
2920 if (data
>= end_of_sequence
)
2921 printf (_(" No Line Number Statements.\n"));
2924 printf (_(" Line Number Statements:\n"));
2926 while (data
< end_of_sequence
)
2928 unsigned char op_code
;
2929 dwarf_signed_vma adv
;
2931 unsigned int bytes_read
;
2933 printf (" [0x%08lx]", (long)(data
- start
));
2937 if (op_code
>= linfo
.li_opcode_base
)
2939 op_code
-= linfo
.li_opcode_base
;
2940 uladv
= (op_code
/ linfo
.li_line_range
);
2941 if (linfo
.li_max_ops_per_insn
== 1)
2943 uladv
*= linfo
.li_min_insn_length
;
2944 state_machine_regs
.address
+= uladv
;
2945 printf (_(" Special opcode %d: "
2946 "advance Address by %s to 0x%s"),
2947 op_code
, dwarf_vmatoa ("u", uladv
),
2948 dwarf_vmatoa ("x", state_machine_regs
.address
));
2952 state_machine_regs
.address
2953 += ((state_machine_regs
.op_index
+ uladv
)
2954 / linfo
.li_max_ops_per_insn
)
2955 * linfo
.li_min_insn_length
;
2956 state_machine_regs
.op_index
2957 = (state_machine_regs
.op_index
+ uladv
)
2958 % linfo
.li_max_ops_per_insn
;
2959 printf (_(" Special opcode %d: "
2960 "advance Address by %s to 0x%s[%d]"),
2961 op_code
, dwarf_vmatoa ("u", uladv
),
2962 dwarf_vmatoa ("x", state_machine_regs
.address
),
2963 state_machine_regs
.op_index
);
2965 adv
= (op_code
% linfo
.li_line_range
) + linfo
.li_line_base
;
2966 state_machine_regs
.line
+= adv
;
2967 printf (_(" and Line by %s to %d\n"),
2968 dwarf_vmatoa ("d", adv
), state_machine_regs
.line
);
2970 else switch (op_code
)
2972 case DW_LNS_extended_op
:
2973 data
+= process_extended_line_op (data
, linfo
.li_default_is_stmt
, end
);
2977 printf (_(" Copy\n"));
2980 case DW_LNS_advance_pc
:
2981 uladv
= read_uleb128 (data
, & bytes_read
, end
);
2983 if (linfo
.li_max_ops_per_insn
== 1)
2985 uladv
*= linfo
.li_min_insn_length
;
2986 state_machine_regs
.address
+= uladv
;
2987 printf (_(" Advance PC by %s to 0x%s\n"),
2988 dwarf_vmatoa ("u", uladv
),
2989 dwarf_vmatoa ("x", state_machine_regs
.address
));
2993 state_machine_regs
.address
2994 += ((state_machine_regs
.op_index
+ uladv
)
2995 / linfo
.li_max_ops_per_insn
)
2996 * linfo
.li_min_insn_length
;
2997 state_machine_regs
.op_index
2998 = (state_machine_regs
.op_index
+ uladv
)
2999 % linfo
.li_max_ops_per_insn
;
3000 printf (_(" Advance PC by %s to 0x%s[%d]\n"),
3001 dwarf_vmatoa ("u", uladv
),
3002 dwarf_vmatoa ("x", state_machine_regs
.address
),
3003 state_machine_regs
.op_index
);
3007 case DW_LNS_advance_line
:
3008 adv
= read_sleb128 (data
, & bytes_read
, end
);
3010 state_machine_regs
.line
+= adv
;
3011 printf (_(" Advance Line by %s to %d\n"),
3012 dwarf_vmatoa ("d", adv
),
3013 state_machine_regs
.line
);
3016 case DW_LNS_set_file
:
3017 adv
= read_uleb128 (data
, & bytes_read
, end
);
3019 printf (_(" Set File Name to entry %s in the File Name Table\n"),
3020 dwarf_vmatoa ("d", adv
));
3021 state_machine_regs
.file
= adv
;
3024 case DW_LNS_set_column
:
3025 uladv
= read_uleb128 (data
, & bytes_read
, end
);
3027 printf (_(" Set column to %s\n"),
3028 dwarf_vmatoa ("u", uladv
));
3029 state_machine_regs
.column
= uladv
;
3032 case DW_LNS_negate_stmt
:
3033 adv
= state_machine_regs
.is_stmt
;
3035 printf (_(" Set is_stmt to %s\n"), dwarf_vmatoa ("d", adv
));
3036 state_machine_regs
.is_stmt
= adv
;
3039 case DW_LNS_set_basic_block
:
3040 printf (_(" Set basic block\n"));
3041 state_machine_regs
.basic_block
= 1;
3044 case DW_LNS_const_add_pc
:
3045 uladv
= ((255 - linfo
.li_opcode_base
) / linfo
.li_line_range
);
3046 if (linfo
.li_max_ops_per_insn
)
3048 uladv
*= linfo
.li_min_insn_length
;
3049 state_machine_regs
.address
+= uladv
;
3050 printf (_(" Advance PC by constant %s to 0x%s\n"),
3051 dwarf_vmatoa ("u", uladv
),
3052 dwarf_vmatoa ("x", state_machine_regs
.address
));
3056 state_machine_regs
.address
3057 += ((state_machine_regs
.op_index
+ uladv
)
3058 / linfo
.li_max_ops_per_insn
)
3059 * linfo
.li_min_insn_length
;
3060 state_machine_regs
.op_index
3061 = (state_machine_regs
.op_index
+ uladv
)
3062 % linfo
.li_max_ops_per_insn
;
3063 printf (_(" Advance PC by constant %s to 0x%s[%d]\n"),
3064 dwarf_vmatoa ("u", uladv
),
3065 dwarf_vmatoa ("x", state_machine_regs
.address
),
3066 state_machine_regs
.op_index
);
3070 case DW_LNS_fixed_advance_pc
:
3071 SAFE_BYTE_GET_AND_INC (uladv
, data
, 2, end
);
3072 state_machine_regs
.address
+= uladv
;
3073 state_machine_regs
.op_index
= 0;
3074 printf (_(" Advance PC by fixed size amount %s to 0x%s\n"),
3075 dwarf_vmatoa ("u", uladv
),
3076 dwarf_vmatoa ("x", state_machine_regs
.address
));
3079 case DW_LNS_set_prologue_end
:
3080 printf (_(" Set prologue_end to true\n"));
3083 case DW_LNS_set_epilogue_begin
:
3084 printf (_(" Set epilogue_begin to true\n"));
3087 case DW_LNS_set_isa
:
3088 uladv
= read_uleb128 (data
, & bytes_read
, end
);
3090 printf (_(" Set ISA to %s\n"), dwarf_vmatoa ("u", uladv
));
3094 printf (_(" Unknown opcode %d with operands: "), op_code
);
3096 if (standard_opcodes
!= NULL
)
3097 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
3099 printf ("0x%s%s", dwarf_vmatoa ("x", read_uleb128 (data
,
3101 i
== 1 ? "" : ", ");
3117 unsigned char *name
;
3118 unsigned int directory_index
;
3119 unsigned int modification_date
;
3120 unsigned int length
;
3123 /* Output a decoded representation of the .debug_line section. */
3126 display_debug_lines_decoded (struct dwarf_section
*section
,
3127 unsigned char *data
,
3130 static DWARF2_Internal_LineInfo saved_linfo
;
3132 printf (_("Decoded dump of debug contents of section %s:\n\n"),
3137 /* This loop amounts to one iteration per compilation unit. */
3138 DWARF2_Internal_LineInfo linfo
;
3139 unsigned char *standard_opcodes
;
3140 unsigned char *end_of_sequence
;
3142 File_Entry
*file_table
= NULL
;
3143 unsigned int n_files
= 0;
3144 unsigned char **directory_table
= NULL
;
3145 unsigned int n_directories
= 0;
3147 if (const_strneq (section
->name
, ".debug_line.")
3148 /* Note: the following does not apply to .debug_line.dwo sections.
3149 These are full debug_line sections. */
3150 && strcmp (section
->name
, ".debug_line.dwo") != 0)
3152 /* See comment in display_debug_lines_raw(). */
3153 end_of_sequence
= end
;
3154 standard_opcodes
= NULL
;
3155 linfo
= saved_linfo
;
3156 reset_state_machine (linfo
.li_default_is_stmt
);
3160 unsigned char *hdrptr
;
3162 if ((hdrptr
= read_debug_line_header (section
, data
, end
, & linfo
,
3163 & end_of_sequence
)) == NULL
)
3166 reset_state_machine (linfo
.li_default_is_stmt
);
3168 /* Save a pointer to the contents of the Opcodes table. */
3169 standard_opcodes
= hdrptr
;
3171 /* Traverse the Directory table just to count entries. */
3172 data
= standard_opcodes
+ linfo
.li_opcode_base
- 1;
3175 unsigned char *ptr_directory_table
= data
;
3179 data
+= strnlen ((char *) data
, end
- data
) + 1;
3183 /* Go through the directory table again to save the directories. */
3184 directory_table
= (unsigned char **)
3185 xmalloc (n_directories
* sizeof (unsigned char *));
3188 while (*ptr_directory_table
!= 0)
3190 directory_table
[i
] = ptr_directory_table
;
3191 ptr_directory_table
+= strnlen ((char *) ptr_directory_table
,
3192 ptr_directory_table
- end
) + 1;
3196 /* Skip the NUL at the end of the table. */
3199 /* Traverse the File Name table just to count the entries. */
3202 unsigned char *ptr_file_name_table
= data
;
3206 unsigned int bytes_read
;
3208 /* Skip Name, directory index, last modification time and length
3210 data
+= strnlen ((char *) data
, end
- data
) + 1;
3211 read_uleb128 (data
, & bytes_read
, end
);
3213 read_uleb128 (data
, & bytes_read
, end
);
3215 read_uleb128 (data
, & bytes_read
, end
);
3221 /* Go through the file table again to save the strings. */
3222 file_table
= (File_Entry
*) xmalloc (n_files
* sizeof (File_Entry
));
3225 while (*ptr_file_name_table
!= 0)
3227 unsigned int bytes_read
;
3229 file_table
[i
].name
= ptr_file_name_table
;
3230 ptr_file_name_table
+= strnlen ((char *) ptr_file_name_table
,
3231 end
- ptr_file_name_table
) + 1;
3233 /* We are not interested in directory, time or size. */
3234 file_table
[i
].directory_index
= read_uleb128 (ptr_file_name_table
,
3236 ptr_file_name_table
+= bytes_read
;
3237 file_table
[i
].modification_date
= read_uleb128 (ptr_file_name_table
,
3239 ptr_file_name_table
+= bytes_read
;
3240 file_table
[i
].length
= read_uleb128 (ptr_file_name_table
, & bytes_read
, end
);
3241 ptr_file_name_table
+= bytes_read
;
3246 /* Print the Compilation Unit's name and a header. */
3247 if (directory_table
== NULL
)
3249 printf (_("CU: %s:\n"), file_table
[0].name
);
3250 printf (_("File name Line number Starting address\n"));
3254 unsigned int ix
= file_table
[0].directory_index
;
3255 const char *directory
= ix
? (char *)directory_table
[ix
- 1] : ".";
3257 if (do_wide
|| strlen (directory
) < 76)
3258 printf (_("CU: %s/%s:\n"), directory
, file_table
[0].name
);
3260 printf ("%s:\n", file_table
[0].name
);
3262 printf (_("File name Line number Starting address\n"));
3266 /* Skip the NUL at the end of the table. */
3269 saved_linfo
= linfo
;
3272 /* This loop iterates through the Dwarf Line Number Program. */
3273 while (data
< end_of_sequence
)
3275 unsigned char op_code
;
3277 unsigned long int uladv
;
3278 unsigned int bytes_read
;
3279 int is_special_opcode
= 0;
3283 if (op_code
>= linfo
.li_opcode_base
)
3285 op_code
-= linfo
.li_opcode_base
;
3286 uladv
= (op_code
/ linfo
.li_line_range
);
3287 if (linfo
.li_max_ops_per_insn
== 1)
3289 uladv
*= linfo
.li_min_insn_length
;
3290 state_machine_regs
.address
+= uladv
;
3294 state_machine_regs
.address
3295 += ((state_machine_regs
.op_index
+ uladv
)
3296 / linfo
.li_max_ops_per_insn
)
3297 * linfo
.li_min_insn_length
;
3298 state_machine_regs
.op_index
3299 = (state_machine_regs
.op_index
+ uladv
)
3300 % linfo
.li_max_ops_per_insn
;
3303 adv
= (op_code
% linfo
.li_line_range
) + linfo
.li_line_base
;
3304 state_machine_regs
.line
+= adv
;
3305 is_special_opcode
= 1;
3307 else switch (op_code
)
3309 case DW_LNS_extended_op
:
3311 unsigned int ext_op_code_len
;
3312 unsigned char ext_op_code
;
3313 unsigned char *op_code_data
= data
;
3315 ext_op_code_len
= read_uleb128 (op_code_data
, &bytes_read
,
3317 op_code_data
+= bytes_read
;
3319 if (ext_op_code_len
== 0)
3321 warn (_("Badly formed extended line op encountered!\n"));
3324 ext_op_code_len
+= bytes_read
;
3325 ext_op_code
= *op_code_data
++;
3327 switch (ext_op_code
)
3329 case DW_LNE_end_sequence
:
3330 reset_state_machine (linfo
.li_default_is_stmt
);
3332 case DW_LNE_set_address
:
3333 SAFE_BYTE_GET_AND_INC (state_machine_regs
.address
,
3335 ext_op_code_len
- bytes_read
- 1,
3337 state_machine_regs
.op_index
= 0;
3339 case DW_LNE_define_file
:
3341 file_table
= (File_Entry
*) xrealloc
3342 (file_table
, (n_files
+ 1) * sizeof (File_Entry
));
3344 ++state_machine_regs
.last_file_entry
;
3345 /* Source file name. */
3346 file_table
[n_files
].name
= op_code_data
;
3347 op_code_data
+= strlen ((char *) op_code_data
) + 1;
3348 /* Directory index. */
3349 file_table
[n_files
].directory_index
=
3350 read_uleb128 (op_code_data
, & bytes_read
,
3352 op_code_data
+= bytes_read
;
3353 /* Last modification time. */
3354 file_table
[n_files
].modification_date
=
3355 read_uleb128 (op_code_data
, & bytes_read
,
3357 op_code_data
+= bytes_read
;
3359 file_table
[n_files
].length
=
3360 read_uleb128 (op_code_data
, & bytes_read
,
3366 case DW_LNE_set_discriminator
:
3367 case DW_LNE_HP_set_sequence
:
3368 /* Simply ignored. */
3372 printf (_("UNKNOWN (%u): length %d\n"),
3373 ext_op_code
, ext_op_code_len
- bytes_read
);
3376 data
+= ext_op_code_len
;
3382 case DW_LNS_advance_pc
:
3383 uladv
= read_uleb128 (data
, & bytes_read
, end
);
3385 if (linfo
.li_max_ops_per_insn
== 1)
3387 uladv
*= linfo
.li_min_insn_length
;
3388 state_machine_regs
.address
+= uladv
;
3392 state_machine_regs
.address
3393 += ((state_machine_regs
.op_index
+ uladv
)
3394 / linfo
.li_max_ops_per_insn
)
3395 * linfo
.li_min_insn_length
;
3396 state_machine_regs
.op_index
3397 = (state_machine_regs
.op_index
+ uladv
)
3398 % linfo
.li_max_ops_per_insn
;
3402 case DW_LNS_advance_line
:
3403 adv
= read_sleb128 (data
, & bytes_read
, end
);
3405 state_machine_regs
.line
+= adv
;
3408 case DW_LNS_set_file
:
3409 adv
= read_uleb128 (data
, & bytes_read
, end
);
3411 state_machine_regs
.file
= adv
;
3413 if (file_table
== NULL
)
3414 printf (_("\n [Use file table entry %d]\n"), state_machine_regs
.file
- 1);
3415 else if (file_table
[state_machine_regs
.file
- 1].directory_index
== 0)
3416 /* If directory index is 0, that means current directory. */
3417 printf ("\n./%s:[++]\n",
3418 file_table
[state_machine_regs
.file
- 1].name
);
3419 else if (directory_table
== NULL
)
3420 printf (_("\n [Use directory table entry %d]\n"),
3421 file_table
[state_machine_regs
.file
- 1].directory_index
- 1);
3423 /* The directory index starts counting at 1. */
3424 printf ("\n%s/%s:\n",
3425 directory_table
[file_table
[state_machine_regs
.file
- 1].directory_index
- 1],
3426 file_table
[state_machine_regs
.file
- 1].name
);
3429 case DW_LNS_set_column
:
3430 uladv
= read_uleb128 (data
, & bytes_read
, end
);
3432 state_machine_regs
.column
= uladv
;
3435 case DW_LNS_negate_stmt
:
3436 adv
= state_machine_regs
.is_stmt
;
3438 state_machine_regs
.is_stmt
= adv
;
3441 case DW_LNS_set_basic_block
:
3442 state_machine_regs
.basic_block
= 1;
3445 case DW_LNS_const_add_pc
:
3446 uladv
= ((255 - linfo
.li_opcode_base
) / linfo
.li_line_range
);
3447 if (linfo
.li_max_ops_per_insn
== 1)
3449 uladv
*= linfo
.li_min_insn_length
;
3450 state_machine_regs
.address
+= uladv
;
3454 state_machine_regs
.address
3455 += ((state_machine_regs
.op_index
+ uladv
)
3456 / linfo
.li_max_ops_per_insn
)
3457 * linfo
.li_min_insn_length
;
3458 state_machine_regs
.op_index
3459 = (state_machine_regs
.op_index
+ uladv
)
3460 % linfo
.li_max_ops_per_insn
;
3464 case DW_LNS_fixed_advance_pc
:
3465 SAFE_BYTE_GET_AND_INC (uladv
, data
, 2, end
);
3466 state_machine_regs
.address
+= uladv
;
3467 state_machine_regs
.op_index
= 0;
3470 case DW_LNS_set_prologue_end
:
3473 case DW_LNS_set_epilogue_begin
:
3476 case DW_LNS_set_isa
:
3477 uladv
= read_uleb128 (data
, & bytes_read
, end
);
3479 printf (_(" Set ISA to %lu\n"), uladv
);
3483 printf (_(" Unknown opcode %d with operands: "), op_code
);
3485 if (standard_opcodes
!= NULL
)
3486 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
3488 printf ("0x%s%s", dwarf_vmatoa ("x", read_uleb128 (data
,
3490 i
== 1 ? "" : ", ");
3497 /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row
3498 to the DWARF address/line matrix. */
3499 if ((is_special_opcode
) || (op_code
== DW_LNE_end_sequence
)
3500 || (op_code
== DW_LNS_copy
))
3502 const unsigned int MAX_FILENAME_LENGTH
= 35;
3504 char *newFileName
= NULL
;
3505 size_t fileNameLength
;
3508 fileName
= (char *) file_table
[state_machine_regs
.file
- 1].name
;
3510 fileName
= "<unknown>";
3512 fileNameLength
= strlen (fileName
);
3514 if ((fileNameLength
> MAX_FILENAME_LENGTH
) && (!do_wide
))
3516 newFileName
= (char *) xmalloc (MAX_FILENAME_LENGTH
+ 1);
3517 /* Truncate file name */
3518 strncpy (newFileName
,
3519 fileName
+ fileNameLength
- MAX_FILENAME_LENGTH
,
3520 MAX_FILENAME_LENGTH
+ 1);
3524 newFileName
= (char *) xmalloc (fileNameLength
+ 1);
3525 strncpy (newFileName
, fileName
, fileNameLength
+ 1);
3528 if (!do_wide
|| (fileNameLength
<= MAX_FILENAME_LENGTH
))
3530 if (linfo
.li_max_ops_per_insn
== 1)
3531 printf ("%-35s %11d %#18" DWARF_VMA_FMT
"x\n",
3532 newFileName
, state_machine_regs
.line
,
3533 state_machine_regs
.address
);
3535 printf ("%-35s %11d %#18" DWARF_VMA_FMT
"x[%d]\n",
3536 newFileName
, state_machine_regs
.line
,
3537 state_machine_regs
.address
,
3538 state_machine_regs
.op_index
);
3542 if (linfo
.li_max_ops_per_insn
== 1)
3543 printf ("%s %11d %#18" DWARF_VMA_FMT
"x\n",
3544 newFileName
, state_machine_regs
.line
,
3545 state_machine_regs
.address
);
3547 printf ("%s %11d %#18" DWARF_VMA_FMT
"x[%d]\n",
3548 newFileName
, state_machine_regs
.line
,
3549 state_machine_regs
.address
,
3550 state_machine_regs
.op_index
);
3553 if (op_code
== DW_LNE_end_sequence
)
3567 if (directory_table
)
3569 free (directory_table
);
3570 directory_table
= NULL
;
3581 display_debug_lines (struct dwarf_section
*section
, void *file ATTRIBUTE_UNUSED
)
3583 unsigned char *data
= section
->start
;
3584 unsigned char *end
= data
+ section
->size
;
3586 int retValDecoded
= 1;
3588 if (do_debug_lines
== 0)
3589 do_debug_lines
|= FLAG_DEBUG_LINES_RAW
;
3591 if (do_debug_lines
& FLAG_DEBUG_LINES_RAW
)
3592 retValRaw
= display_debug_lines_raw (section
, data
, end
);
3594 if (do_debug_lines
& FLAG_DEBUG_LINES_DECODED
)
3595 retValDecoded
= display_debug_lines_decoded (section
, data
, end
);
3597 if (!retValRaw
|| !retValDecoded
)
3604 find_debug_info_for_offset (unsigned long offset
)
3608 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
3611 for (i
= 0; i
< num_debug_info_entries
; i
++)
3612 if (debug_information
[i
].cu_offset
== offset
)
3613 return debug_information
+ i
;
3619 get_gdb_index_symbol_kind_name (gdb_index_symbol_kind kind
)
3621 /* See gdb/gdb-index.h. */
3622 static const char * const kinds
[] =
3634 return _ (kinds
[kind
]);
3638 display_debug_pubnames_worker (struct dwarf_section
*section
,
3639 void *file ATTRIBUTE_UNUSED
,
3642 DWARF2_Internal_PubNames names
;
3643 unsigned char *start
= section
->start
;
3644 unsigned char *end
= start
+ section
->size
;
3646 /* It does not matter if this load fails,
3647 we test for that later on. */
3648 load_debug_info (file
);
3650 printf (_("Contents of the %s section:\n\n"), section
->name
);
3654 unsigned char *data
;
3655 unsigned long offset
;
3656 unsigned int offset_size
, initial_length_size
;
3660 SAFE_BYTE_GET_AND_INC (names
.pn_length
, data
, 4, end
);
3661 if (names
.pn_length
== 0xffffffff)
3663 SAFE_BYTE_GET_AND_INC (names
.pn_length
, data
, 8, end
);
3665 initial_length_size
= 12;
3670 initial_length_size
= 4;
3673 SAFE_BYTE_GET_AND_INC (names
.pn_version
, data
, 2, end
);
3674 SAFE_BYTE_GET_AND_INC (names
.pn_offset
, data
, offset_size
, end
);
3676 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
3677 && num_debug_info_entries
> 0
3678 && find_debug_info_for_offset (names
.pn_offset
) == NULL
)
3679 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
3680 (unsigned long) names
.pn_offset
, section
->name
);
3682 SAFE_BYTE_GET_AND_INC (names
.pn_size
, data
, offset_size
, end
);
3684 start
+= names
.pn_length
+ initial_length_size
;
3686 if (names
.pn_version
!= 2 && names
.pn_version
!= 3)
3688 static int warned
= 0;
3692 warn (_("Only DWARF 2 and 3 pubnames are currently supported\n"));
3699 printf (_(" Length: %ld\n"),
3700 (long) names
.pn_length
);
3701 printf (_(" Version: %d\n"),
3703 printf (_(" Offset into .debug_info section: 0x%lx\n"),
3704 (unsigned long) names
.pn_offset
);
3705 printf (_(" Size of area in .debug_info section: %ld\n"),
3706 (long) names
.pn_size
);
3709 printf (_("\n Offset Kind Name\n"));
3711 printf (_("\n Offset\tName\n"));
3715 bfd_size_type maxprint
;
3717 SAFE_BYTE_GET (offset
, data
, offset_size
, end
);
3721 data
+= offset_size
;
3724 maxprint
= (end
- data
) - 1;
3728 unsigned int kind_data
;
3729 gdb_index_symbol_kind kind
;
3730 const char *kind_name
;
3733 SAFE_BYTE_GET (kind_data
, data
, 1, end
);
3736 /* GCC computes the kind as the upper byte in the CU index
3737 word, and then right shifts it by the CU index size.
3738 Left shift KIND to where the gdb-index.h accessor macros
3740 kind_data
<<= GDB_INDEX_CU_BITSIZE
;
3741 kind
= GDB_INDEX_SYMBOL_KIND_VALUE (kind_data
);
3742 kind_name
= get_gdb_index_symbol_kind_name (kind
);
3743 is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (kind_data
);
3744 printf (" %-6lx %s,%-10s %.*s\n",
3745 offset
, is_static
? _("s") : _("g"),
3746 kind_name
, (int) maxprint
, data
);
3749 printf (" %-6lx\t%.*s\n", offset
, (int) maxprint
, data
);
3751 data
+= strnlen ((char *) data
, maxprint
) + 1;
3756 while (offset
!= 0);
3764 display_debug_pubnames (struct dwarf_section
*section
, void *file
)
3766 return display_debug_pubnames_worker (section
, file
, 0);
3770 display_debug_gnu_pubnames (struct dwarf_section
*section
, void *file
)
3772 return display_debug_pubnames_worker (section
, file
, 1);
3776 display_debug_macinfo (struct dwarf_section
*section
,
3777 void *file ATTRIBUTE_UNUSED
)
3779 unsigned char *start
= section
->start
;
3780 unsigned char *end
= start
+ section
->size
;
3781 unsigned char *curr
= start
;
3782 unsigned int bytes_read
;
3783 enum dwarf_macinfo_record_type op
;
3785 printf (_("Contents of the %s section:\n\n"), section
->name
);
3789 unsigned int lineno
;
3790 const unsigned char *string
;
3792 op
= (enum dwarf_macinfo_record_type
) *curr
;
3797 case DW_MACINFO_start_file
:
3799 unsigned int filenum
;
3801 lineno
= read_uleb128 (curr
, & bytes_read
, end
);
3803 filenum
= read_uleb128 (curr
, & bytes_read
, end
);
3806 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"),
3811 case DW_MACINFO_end_file
:
3812 printf (_(" DW_MACINFO_end_file\n"));
3815 case DW_MACINFO_define
:
3816 lineno
= read_uleb128 (curr
, & bytes_read
, end
);
3819 curr
+= strnlen ((char *) string
, end
- string
) + 1;
3820 printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"),
3824 case DW_MACINFO_undef
:
3825 lineno
= read_uleb128 (curr
, & bytes_read
, end
);
3828 curr
+= strnlen ((char *) string
, end
- string
) + 1;
3829 printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"),
3833 case DW_MACINFO_vendor_ext
:
3835 unsigned int constant
;
3837 constant
= read_uleb128 (curr
, & bytes_read
, end
);
3840 curr
+= strnlen ((char *) string
, end
- string
) + 1;
3841 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"),
3851 /* Given LINE_OFFSET into the .debug_line section, attempt to return
3852 filename and dirname corresponding to file name table entry with index
3853 FILEIDX. Return NULL on failure. */
3855 static unsigned char *
3856 get_line_filename_and_dirname (dwarf_vma line_offset
,
3858 unsigned char **dir_name
)
3860 struct dwarf_section
*section
= &debug_displays
[line
].section
;
3861 unsigned char *hdrptr
, *dirtable
, *file_name
;
3862 unsigned int offset_size
, initial_length_size
;
3863 unsigned int version
, opcode_base
, bytes_read
;
3864 dwarf_vma length
, diridx
;
3865 const unsigned char * end
;
3868 if (section
->start
== NULL
3869 || line_offset
>= section
->size
3873 hdrptr
= section
->start
+ line_offset
;
3874 end
= section
->start
+ section
->size
;
3876 SAFE_BYTE_GET_AND_INC (length
, hdrptr
, 4, end
);
3877 if (length
== 0xffffffff)
3879 /* This section is 64-bit DWARF 3. */
3880 SAFE_BYTE_GET_AND_INC (length
, hdrptr
, 8, end
);
3882 initial_length_size
= 12;
3887 initial_length_size
= 4;
3889 if (length
+ initial_length_size
> section
->size
)
3892 SAFE_BYTE_GET_AND_INC (version
, hdrptr
, 2, end
);
3893 if (version
!= 2 && version
!= 3 && version
!= 4)
3895 hdrptr
+= offset_size
+ 1;/* Skip prologue_length and min_insn_length. */
3897 hdrptr
++; /* Skip max_ops_per_insn. */
3898 hdrptr
+= 3; /* Skip default_is_stmt, line_base, line_range. */
3900 SAFE_BYTE_GET_AND_INC (opcode_base
, hdrptr
, 1, end
);
3901 if (opcode_base
== 0)
3904 hdrptr
+= opcode_base
- 1;
3906 /* Skip over dirname table. */
3907 while (*hdrptr
!= '\0')
3908 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
) + 1;
3909 hdrptr
++; /* Skip the NUL at the end of the table. */
3910 /* Now skip over preceding filename table entries. */
3911 for (; *hdrptr
!= '\0' && fileidx
> 1; fileidx
--)
3913 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
) + 1;
3914 read_uleb128 (hdrptr
, &bytes_read
, end
);
3915 hdrptr
+= bytes_read
;
3916 read_uleb128 (hdrptr
, &bytes_read
, end
);
3917 hdrptr
+= bytes_read
;
3918 read_uleb128 (hdrptr
, &bytes_read
, end
);
3919 hdrptr
+= bytes_read
;
3921 if (hdrptr
== end
|| *hdrptr
== '\0')
3924 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
) + 1;
3925 diridx
= read_uleb128 (hdrptr
, &bytes_read
, end
);
3928 for (; *dirtable
!= '\0' && diridx
> 1; diridx
--)
3929 dirtable
+= strnlen ((char *) dirtable
, end
- dirtable
) + 1;
3930 if (*dirtable
== '\0')
3932 *dir_name
= dirtable
;
3937 display_debug_macro (struct dwarf_section
*section
,
3940 unsigned char *start
= section
->start
;
3941 unsigned char *end
= start
+ section
->size
;
3942 unsigned char *curr
= start
;
3943 unsigned char *extended_op_buf
[256];
3944 unsigned int bytes_read
;
3946 load_debug_section (str
, file
);
3947 load_debug_section (line
, file
);
3949 printf (_("Contents of the %s section:\n\n"), section
->name
);
3953 unsigned int lineno
, version
, flags
;
3954 unsigned int offset_size
= 4;
3955 const unsigned char *string
;
3956 dwarf_vma line_offset
= 0, sec_offset
= curr
- start
, offset
;
3957 unsigned char **extended_ops
= NULL
;
3959 SAFE_BYTE_GET_AND_INC (version
, curr
, 2, end
);
3962 error (_("Only GNU extension to DWARF 4 of %s is currently supported.\n"),
3967 SAFE_BYTE_GET_AND_INC (flags
, curr
, 1, end
);
3970 printf (_(" Offset: 0x%lx\n"),
3971 (unsigned long) sec_offset
);
3972 printf (_(" Version: %d\n"), version
);
3973 printf (_(" Offset size: %d\n"), offset_size
);
3976 SAFE_BYTE_GET_AND_INC (line_offset
, curr
, offset_size
, end
);
3977 printf (_(" Offset into .debug_line: 0x%lx\n"),
3978 (unsigned long) line_offset
);
3982 unsigned int i
, count
, op
;
3985 SAFE_BYTE_GET_AND_INC (count
, curr
, 1, end
);
3987 memset (extended_op_buf
, 0, sizeof (extended_op_buf
));
3988 extended_ops
= extended_op_buf
;
3991 printf (_(" Extension opcode arguments:\n"));
3992 for (i
= 0; i
< count
; i
++)
3994 SAFE_BYTE_GET_AND_INC (op
, curr
, 1, end
);
3995 extended_ops
[op
] = curr
;
3996 nargs
= read_uleb128 (curr
, &bytes_read
, end
);
3999 printf (_(" DW_MACRO_GNU_%02x has no arguments\n"), op
);
4002 printf (_(" DW_MACRO_GNU_%02x arguments: "), op
);
4003 for (n
= 0; n
< nargs
; n
++)
4007 SAFE_BYTE_GET_AND_INC (form
, curr
, 1, end
);
4008 printf ("%s%s", get_FORM_name (form
),
4009 n
== nargs
- 1 ? "\n" : ", ");
4019 case DW_FORM_block1
:
4020 case DW_FORM_block2
:
4021 case DW_FORM_block4
:
4023 case DW_FORM_string
:
4025 case DW_FORM_sec_offset
:
4028 error (_("Invalid extension opcode form %s\n"),
4029 get_FORM_name (form
));
4045 error (_(".debug_macro section not zero terminated\n"));
4049 SAFE_BYTE_GET_AND_INC (op
, curr
, 1, end
);
4055 case DW_MACRO_GNU_start_file
:
4057 unsigned int filenum
;
4058 unsigned char *file_name
= NULL
, *dir_name
= NULL
;
4060 lineno
= read_uleb128 (curr
, &bytes_read
, end
);
4062 filenum
= read_uleb128 (curr
, &bytes_read
, end
);
4065 if ((flags
& 2) == 0)
4066 error (_("DW_MACRO_GNU_start_file used, but no .debug_line offset provided.\n"));
4069 = get_line_filename_and_dirname (line_offset
, filenum
,
4071 if (file_name
== NULL
)
4072 printf (_(" DW_MACRO_GNU_start_file - lineno: %d filenum: %d\n"),
4075 printf (_(" DW_MACRO_GNU_start_file - lineno: %d filenum: %d filename: %s%s%s\n"),
4077 dir_name
!= NULL
? (const char *) dir_name
: "",
4078 dir_name
!= NULL
? "/" : "", file_name
);
4082 case DW_MACRO_GNU_end_file
:
4083 printf (_(" DW_MACRO_GNU_end_file\n"));
4086 case DW_MACRO_GNU_define
:
4087 lineno
= read_uleb128 (curr
, &bytes_read
, end
);
4090 curr
+= strnlen ((char *) string
, end
- string
) + 1;
4091 printf (_(" DW_MACRO_GNU_define - lineno : %d macro : %s\n"),
4095 case DW_MACRO_GNU_undef
:
4096 lineno
= read_uleb128 (curr
, &bytes_read
, end
);
4099 curr
+= strnlen ((char *) string
, end
- string
) + 1;
4100 printf (_(" DW_MACRO_GNU_undef - lineno : %d macro : %s\n"),
4104 case DW_MACRO_GNU_define_indirect
:
4105 lineno
= read_uleb128 (curr
, &bytes_read
, end
);
4107 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
4108 string
= fetch_indirect_string (offset
);
4109 printf (_(" DW_MACRO_GNU_define_indirect - lineno : %d macro : %s\n"),
4113 case DW_MACRO_GNU_undef_indirect
:
4114 lineno
= read_uleb128 (curr
, &bytes_read
, end
);
4116 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
4117 string
= fetch_indirect_string (offset
);
4118 printf (_(" DW_MACRO_GNU_undef_indirect - lineno : %d macro : %s\n"),
4122 case DW_MACRO_GNU_transparent_include
:
4123 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
4124 printf (_(" DW_MACRO_GNU_transparent_include - offset : 0x%lx\n"),
4125 (unsigned long) offset
);
4128 case DW_MACRO_GNU_define_indirect_alt
:
4129 lineno
= read_uleb128 (curr
, &bytes_read
, end
);
4131 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
4132 printf (_(" DW_MACRO_GNU_define_indirect_alt - lineno : %d macro offset : 0x%lx\n"),
4133 lineno
, (unsigned long) offset
);
4136 case DW_MACRO_GNU_undef_indirect_alt
:
4137 lineno
= read_uleb128 (curr
, &bytes_read
, end
);
4139 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
4140 printf (_(" DW_MACRO_GNU_undef_indirect_alt - lineno : %d macro offset : 0x%lx\n"),
4141 lineno
, (unsigned long) offset
);
4144 case DW_MACRO_GNU_transparent_include_alt
:
4145 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
4146 printf (_(" DW_MACRO_GNU_transparent_include_alt - offset : 0x%lx\n"),
4147 (unsigned long) offset
);
4151 if (extended_ops
== NULL
|| extended_ops
[op
] == NULL
)
4153 error (_(" Unknown macro opcode %02x seen\n"), op
);
4158 /* Skip over unhandled opcodes. */
4160 unsigned char *desc
= extended_ops
[op
];
4161 nargs
= read_uleb128 (desc
, &bytes_read
, end
);
4165 printf (_(" DW_MACRO_GNU_%02x\n"), op
);
4168 printf (_(" DW_MACRO_GNU_%02x -"), op
);
4169 for (n
= 0; n
< nargs
; n
++)
4173 SAFE_BYTE_GET_AND_INC (val
, desc
, 1, end
);
4175 = read_and_display_attr_value (0, val
,
4176 curr
, end
, 0, 0, offset_size
,
4177 version
, NULL
, 0, NULL
,
4195 display_debug_abbrev (struct dwarf_section
*section
,
4196 void *file ATTRIBUTE_UNUSED
)
4198 abbrev_entry
*entry
;
4199 unsigned char *start
= section
->start
;
4200 unsigned char *end
= start
+ section
->size
;
4202 printf (_("Contents of the %s section:\n\n"), section
->name
);
4206 unsigned char *last
;
4211 start
= process_abbrev_section (start
, end
);
4213 if (first_abbrev
== NULL
)
4216 printf (_(" Number TAG (0x%lx)\n"), (long) (last
- section
->start
));
4218 for (entry
= first_abbrev
; entry
; entry
= entry
->next
)
4222 printf (" %ld %s [%s]\n",
4224 get_TAG_name (entry
->tag
),
4225 entry
->children
? _("has children") : _("no children"));
4227 for (attr
= entry
->first_attr
; attr
; attr
= attr
->next
)
4228 printf (" %-18s %s\n",
4229 get_AT_name (attr
->attribute
),
4230 get_FORM_name (attr
->form
));
4240 /* Display a location list from a normal (ie, non-dwo) .debug_loc section. */
4243 display_loc_list (struct dwarf_section
*section
,
4244 unsigned char **start_ptr
,
4245 int debug_info_entry
,
4246 unsigned long offset
,
4247 unsigned long base_address
,
4250 unsigned char *start
= *start_ptr
;
4251 unsigned char *section_end
= section
->start
+ section
->size
;
4252 unsigned long cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
4253 unsigned int pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
4254 unsigned int offset_size
= debug_information
[debug_info_entry
].offset_size
;
4255 int dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
4259 unsigned short length
;
4260 int need_frame_base
;
4262 if (pointer_size
< 2 || pointer_size
> 8)
4264 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
4265 pointer_size
, debug_info_entry
);
4271 if (start
+ 2 * pointer_size
> section_end
)
4273 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
4278 printf (" %8.8lx ", offset
+ (start
- *start_ptr
));
4280 /* Note: we use sign extension here in order to be sure that we can detect
4281 the -1 escape value. Sign extension into the top 32 bits of a 32-bit
4282 address will not affect the values that we display since we always show
4283 hex values, and always the bottom 32-bits. */
4284 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, section_end
);
4285 SAFE_BYTE_GET_AND_INC (end
, start
, pointer_size
, section_end
);
4287 if (begin
== 0 && end
== 0)
4289 printf (_("<End of list>\n"));
4293 /* Check base address specifiers. */
4294 if (begin
== (dwarf_vma
) -1 && end
!= (dwarf_vma
) -1)
4297 print_dwarf_vma (begin
, pointer_size
);
4298 print_dwarf_vma (end
, pointer_size
);
4299 printf (_("(base address)\n"));
4303 if (start
+ 2 > section_end
)
4305 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
4310 SAFE_BYTE_GET_AND_INC (length
, start
, 2, section_end
);
4312 if (start
+ length
> section_end
)
4314 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
4319 print_dwarf_vma (begin
+ base_address
, pointer_size
);
4320 print_dwarf_vma (end
+ base_address
, pointer_size
);
4323 need_frame_base
= decode_location_expression (start
,
4328 cu_offset
, section
);
4331 if (need_frame_base
&& !has_frame_base
)
4332 printf (_(" [without DW_AT_frame_base]"));
4335 fputs (_(" (start == end)"), stdout
);
4336 else if (begin
> end
)
4337 fputs (_(" (start > end)"), stdout
);
4347 /* Print a .debug_addr table index in decimal, surrounded by square brackets,
4348 right-adjusted in a field of length LEN, and followed by a space. */
4351 print_addr_index (unsigned int idx
, unsigned int len
)
4353 static char buf
[15];
4354 snprintf (buf
, sizeof (buf
), "[%d]", idx
);
4355 printf ("%*s ", len
, buf
);
4358 /* Display a location list from a .dwo section. It uses address indexes rather
4359 than embedded addresses. This code closely follows display_loc_list, but the
4360 two are sufficiently different that combining things is very ugly. */
4363 display_loc_list_dwo (struct dwarf_section
*section
,
4364 unsigned char **start_ptr
,
4365 int debug_info_entry
,
4366 unsigned long offset
,
4369 unsigned char *start
= *start_ptr
;
4370 unsigned char *section_end
= section
->start
+ section
->size
;
4371 unsigned long cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
4372 unsigned int pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
4373 unsigned int offset_size
= debug_information
[debug_info_entry
].offset_size
;
4374 int dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
4376 unsigned short length
;
4377 int need_frame_base
;
4379 unsigned int bytes_read
;
4381 if (pointer_size
< 2 || pointer_size
> 8)
4383 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
4384 pointer_size
, debug_info_entry
);
4390 printf (" %8.8lx ", offset
+ (start
- *start_ptr
));
4392 if (start
>= section_end
)
4394 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
4399 SAFE_BYTE_GET_AND_INC (entry_type
, start
, 1, section_end
);
4402 case 0: /* A terminating entry. */
4404 printf (_("<End of list>\n"));
4406 case 1: /* A base-address entry. */
4407 idx
= read_uleb128 (start
, &bytes_read
, section_end
);
4408 start
+= bytes_read
;
4409 print_addr_index (idx
, 8);
4411 printf (_("(base address selection entry)\n"));
4413 case 2: /* A start/end entry. */
4414 idx
= read_uleb128 (start
, &bytes_read
, section_end
);
4415 start
+= bytes_read
;
4416 print_addr_index (idx
, 8);
4417 idx
= read_uleb128 (start
, &bytes_read
, section_end
);
4418 start
+= bytes_read
;
4419 print_addr_index (idx
, 8);
4421 case 3: /* A start/length entry. */
4422 idx
= read_uleb128 (start
, &bytes_read
, section_end
);
4423 start
+= bytes_read
;
4424 print_addr_index (idx
, 8);
4425 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
4426 printf ("%08x ", idx
);
4428 case 4: /* An offset pair entry. */
4429 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
4430 printf ("%08x ", idx
);
4431 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
4432 printf ("%08x ", idx
);
4435 warn (_("Unknown location list entry type 0x%x.\n"), entry_type
);
4440 if (start
+ 2 > section_end
)
4442 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
4447 SAFE_BYTE_GET_AND_INC (length
, start
, 2, section_end
);
4448 if (start
+ length
> section_end
)
4450 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
4456 need_frame_base
= decode_location_expression (start
,
4461 cu_offset
, section
);
4464 if (need_frame_base
&& !has_frame_base
)
4465 printf (_(" [without DW_AT_frame_base]"));
4475 /* Sort array of indexes in ascending order of loc_offsets[idx]. */
4477 static dwarf_vma
*loc_offsets
;
4480 loc_offsets_compar (const void *ap
, const void *bp
)
4482 dwarf_vma a
= loc_offsets
[*(const unsigned int *) ap
];
4483 dwarf_vma b
= loc_offsets
[*(const unsigned int *) bp
];
4485 return (a
> b
) - (b
> a
);
4489 display_debug_loc (struct dwarf_section
*section
, void *file
)
4491 unsigned char *start
= section
->start
;
4492 unsigned long bytes
;
4493 unsigned char *section_begin
= start
;
4494 unsigned int num_loc_list
= 0;
4495 unsigned long last_offset
= 0;
4496 unsigned int first
= 0;
4500 int seen_first_offset
= 0;
4501 int locs_sorted
= 1;
4502 unsigned char *next
;
4503 unsigned int *array
= NULL
;
4504 const char *suffix
= strrchr (section
->name
, '.');
4507 if (suffix
&& strcmp (suffix
, ".dwo") == 0)
4510 bytes
= section
->size
;
4514 printf (_("\nThe %s section is empty.\n"), section
->name
);
4518 if (load_debug_info (file
) == 0)
4520 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
4525 /* Check the order of location list in .debug_info section. If
4526 offsets of location lists are in the ascending order, we can
4527 use `debug_information' directly. */
4528 for (i
= 0; i
< num_debug_info_entries
; i
++)
4532 num
= debug_information
[i
].num_loc_offsets
;
4533 if (num
> num_loc_list
)
4536 /* Check if we can use `debug_information' directly. */
4537 if (locs_sorted
&& num
!= 0)
4539 if (!seen_first_offset
)
4541 /* This is the first location list. */
4542 last_offset
= debug_information
[i
].loc_offsets
[0];
4544 seen_first_offset
= 1;
4550 for (; j
< num
; j
++)
4553 debug_information
[i
].loc_offsets
[j
])
4558 last_offset
= debug_information
[i
].loc_offsets
[j
];
4563 if (!seen_first_offset
)
4564 error (_("No location lists in .debug_info section!\n"));
4566 if (debug_information
[first
].num_loc_offsets
> 0
4567 && debug_information
[first
].loc_offsets
[0] != 0)
4568 warn (_("Location lists in %s section start at 0x%s\n"),
4570 dwarf_vmatoa ("x", debug_information
[first
].loc_offsets
[0]));
4573 array
= (unsigned int *) xcmalloc (num_loc_list
, sizeof (unsigned int));
4574 printf (_("Contents of the %s section:\n\n"), section
->name
);
4575 printf (_(" Offset Begin End Expression\n"));
4577 seen_first_offset
= 0;
4578 for (i
= first
; i
< num_debug_info_entries
; i
++)
4580 unsigned long offset
;
4581 unsigned long base_address
;
4586 for (k
= 0; k
< debug_information
[i
].num_loc_offsets
; k
++)
4588 loc_offsets
= debug_information
[i
].loc_offsets
;
4589 qsort (array
, debug_information
[i
].num_loc_offsets
,
4590 sizeof (*array
), loc_offsets_compar
);
4593 for (k
= 0; k
< debug_information
[i
].num_loc_offsets
; k
++)
4595 j
= locs_sorted
? k
: array
[k
];
4597 && debug_information
[i
].loc_offsets
[locs_sorted
4598 ? k
- 1 : array
[k
- 1]]
4599 == debug_information
[i
].loc_offsets
[j
])
4601 has_frame_base
= debug_information
[i
].have_frame_base
[j
];
4602 offset
= debug_information
[i
].loc_offsets
[j
];
4603 next
= section_begin
+ offset
;
4604 base_address
= debug_information
[i
].base_address
;
4606 if (!seen_first_offset
)
4607 seen_first_offset
= 1;
4611 warn (_("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n"),
4612 (unsigned long) (start
- section_begin
),
4613 (unsigned long) (next
- section_begin
));
4614 else if (start
> next
)
4615 warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n"),
4616 (unsigned long) (start
- section_begin
),
4617 (unsigned long) (next
- section_begin
));
4621 if (offset
>= bytes
)
4623 warn (_("Offset 0x%lx is bigger than .debug_loc section size.\n"),
4629 display_loc_list_dwo (section
, &start
, i
, offset
, has_frame_base
);
4631 display_loc_list (section
, &start
, i
, offset
, base_address
,
4636 if (start
< section
->start
+ section
->size
)
4637 warn (_("There are %ld unused bytes at the end of section %s\n"),
4638 (long) (section
->start
+ section
->size
- start
), section
->name
);
4645 display_debug_str (struct dwarf_section
*section
,
4646 void *file ATTRIBUTE_UNUSED
)
4648 unsigned char *start
= section
->start
;
4649 unsigned long bytes
= section
->size
;
4650 dwarf_vma addr
= section
->address
;
4654 printf (_("\nThe %s section is empty.\n"), section
->name
);
4658 printf (_("Contents of the %s section:\n\n"), section
->name
);
4666 lbytes
= (bytes
> 16 ? 16 : bytes
);
4668 printf (" 0x%8.8lx ", (unsigned long) addr
);
4670 for (j
= 0; j
< 16; j
++)
4673 printf ("%2.2x", start
[j
]);
4681 for (j
= 0; j
< lbytes
; j
++)
4684 if (k
>= ' ' && k
< 0x80)
4703 display_debug_info (struct dwarf_section
*section
, void *file
)
4705 return process_debug_info (section
, file
, section
->abbrev_sec
, 0, 0);
4709 display_debug_types (struct dwarf_section
*section
, void *file
)
4711 return process_debug_info (section
, file
, section
->abbrev_sec
, 0, 1);
4715 display_trace_info (struct dwarf_section
*section
, void *file
)
4717 return process_debug_info (section
, file
, section
->abbrev_sec
, 0, 0);
4721 display_debug_aranges (struct dwarf_section
*section
,
4722 void *file ATTRIBUTE_UNUSED
)
4724 unsigned char *start
= section
->start
;
4725 unsigned char *end
= start
+ section
->size
;
4727 printf (_("Contents of the %s section:\n\n"), section
->name
);
4729 /* It does not matter if this load fails,
4730 we test for that later on. */
4731 load_debug_info (file
);
4735 unsigned char *hdrptr
;
4736 DWARF2_Internal_ARange arange
;
4737 unsigned char *addr_ranges
;
4740 unsigned char address_size
;
4742 unsigned int offset_size
;
4743 unsigned int initial_length_size
;
4747 SAFE_BYTE_GET_AND_INC (arange
.ar_length
, hdrptr
, 4, end
);
4748 if (arange
.ar_length
== 0xffffffff)
4750 SAFE_BYTE_GET_AND_INC (arange
.ar_length
, hdrptr
, 8, end
);
4752 initial_length_size
= 12;
4757 initial_length_size
= 4;
4760 SAFE_BYTE_GET_AND_INC (arange
.ar_version
, hdrptr
, 2, end
);
4761 SAFE_BYTE_GET_AND_INC (arange
.ar_info_offset
, hdrptr
, offset_size
, end
);
4763 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
4764 && num_debug_info_entries
> 0
4765 && find_debug_info_for_offset (arange
.ar_info_offset
) == NULL
)
4766 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
4767 (unsigned long) arange
.ar_info_offset
, section
->name
);
4769 SAFE_BYTE_GET_AND_INC (arange
.ar_pointer_size
, hdrptr
, 1, end
);
4770 SAFE_BYTE_GET_AND_INC (arange
.ar_segment_size
, hdrptr
, 1, end
);
4772 if (arange
.ar_version
!= 2 && arange
.ar_version
!= 3)
4774 warn (_("Only DWARF 2 and 3 aranges are currently supported.\n"));
4778 printf (_(" Length: %ld\n"),
4779 (long) arange
.ar_length
);
4780 printf (_(" Version: %d\n"), arange
.ar_version
);
4781 printf (_(" Offset into .debug_info: 0x%lx\n"),
4782 (unsigned long) arange
.ar_info_offset
);
4783 printf (_(" Pointer Size: %d\n"), arange
.ar_pointer_size
);
4784 printf (_(" Segment Size: %d\n"), arange
.ar_segment_size
);
4786 address_size
= arange
.ar_pointer_size
+ arange
.ar_segment_size
;
4788 /* PR 17512: file: 001-108546-0.001:0.1. */
4789 if (address_size
== 0 || address_size
> 8)
4791 error (_("Invalid address size in %s section!\n"),
4796 /* The DWARF spec does not require that the address size be a power
4797 of two, but we do. This will have to change if we ever encounter
4798 an uneven architecture. */
4799 if ((address_size
& (address_size
- 1)) != 0)
4801 warn (_("Pointer size + Segment size is not a power of two.\n"));
4805 if (address_size
> 4)
4806 printf (_("\n Address Length\n"));
4808 printf (_("\n Address Length\n"));
4810 addr_ranges
= hdrptr
;
4812 /* Must pad to an alignment boundary that is twice the address size. */
4813 excess
= (hdrptr
- start
) % (2 * address_size
);
4815 addr_ranges
+= (2 * address_size
) - excess
;
4817 start
+= arange
.ar_length
+ initial_length_size
;
4819 while (addr_ranges
+ 2 * address_size
<= start
)
4821 SAFE_BYTE_GET_AND_INC (address
, addr_ranges
, address_size
, end
);
4822 SAFE_BYTE_GET_AND_INC (length
, addr_ranges
, address_size
, end
);
4825 print_dwarf_vma (address
, address_size
);
4826 print_dwarf_vma (length
, address_size
);
4836 /* Comparison function for qsort. */
4838 comp_addr_base (const void * v0
, const void * v1
)
4840 debug_info
* info0
= (debug_info
*) v0
;
4841 debug_info
* info1
= (debug_info
*) v1
;
4842 return info0
->addr_base
- info1
->addr_base
;
4845 /* Display the debug_addr section. */
4847 display_debug_addr (struct dwarf_section
*section
,
4850 debug_info
**debug_addr_info
;
4851 unsigned char *entry
;
4856 if (section
->size
== 0)
4858 printf (_("\nThe %s section is empty.\n"), section
->name
);
4862 if (load_debug_info (file
) == 0)
4864 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
4869 printf (_("Contents of the %s section:\n\n"), section
->name
);
4871 debug_addr_info
= (debug_info
**) xmalloc ((num_debug_info_entries
+ 1)
4872 * sizeof (debug_info
*));
4875 for (i
= 0; i
< num_debug_info_entries
; i
++)
4877 if (debug_information
[i
].addr_base
!= DEBUG_INFO_UNAVAILABLE
)
4878 debug_addr_info
[count
++] = &debug_information
[i
];
4881 /* Add a sentinel to make iteration convenient. */
4882 debug_addr_info
[count
] = (debug_info
*) xmalloc (sizeof (debug_info
));
4883 debug_addr_info
[count
]->addr_base
= section
->size
;
4885 qsort (debug_addr_info
, count
, sizeof (debug_info
*), comp_addr_base
);
4886 for (i
= 0; i
< count
; i
++)
4889 unsigned int address_size
= debug_addr_info
[i
]->pointer_size
;
4891 printf (_(" For compilation unit at offset 0x%s:\n"),
4892 dwarf_vmatoa ("x", debug_addr_info
[i
]->cu_offset
));
4894 printf (_("\tIndex\tAddress\n"));
4895 entry
= section
->start
+ debug_addr_info
[i
]->addr_base
;
4896 end
= section
->start
+ debug_addr_info
[i
+ 1]->addr_base
;
4900 dwarf_vma base
= byte_get (entry
, address_size
);
4901 printf (_("\t%d:\t"), idx
);
4902 print_dwarf_vma (base
, address_size
);
4904 entry
+= address_size
;
4910 free (debug_addr_info
);
4914 /* Display the .debug_str_offsets and .debug_str_offsets.dwo sections. */
4916 display_debug_str_offsets (struct dwarf_section
*section
,
4917 void *file ATTRIBUTE_UNUSED
)
4919 if (section
->size
== 0)
4921 printf (_("\nThe %s section is empty.\n"), section
->name
);
4924 /* TODO: Dump the contents. This is made somewhat difficult by not knowing
4925 what the offset size is for this section. */
4929 /* Each debug_information[x].range_lists[y] gets this representation for
4930 sorting purposes. */
4934 /* The debug_information[x].range_lists[y] value. */
4935 unsigned long ranges_offset
;
4937 /* Original debug_information to find parameters of the data. */
4938 debug_info
*debug_info_p
;
4941 /* Sort struct range_entry in ascending order of its RANGES_OFFSET. */
4944 range_entry_compar (const void *ap
, const void *bp
)
4946 const struct range_entry
*a_re
= (const struct range_entry
*) ap
;
4947 const struct range_entry
*b_re
= (const struct range_entry
*) bp
;
4948 const unsigned long a
= a_re
->ranges_offset
;
4949 const unsigned long b
= b_re
->ranges_offset
;
4951 return (a
> b
) - (b
> a
);
4955 display_debug_ranges (struct dwarf_section
*section
,
4956 void *file ATTRIBUTE_UNUSED
)
4958 unsigned char *start
= section
->start
;
4959 unsigned char *last_start
= start
;
4960 unsigned long bytes
= section
->size
;
4961 unsigned char *section_begin
= start
;
4962 unsigned char *finish
= start
+ bytes
;
4963 unsigned int num_range_list
, i
;
4964 struct range_entry
*range_entries
, *range_entry_fill
;
4968 printf (_("\nThe %s section is empty.\n"), section
->name
);
4972 if (load_debug_info (file
) == 0)
4974 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
4980 for (i
= 0; i
< num_debug_info_entries
; i
++)
4981 num_range_list
+= debug_information
[i
].num_range_lists
;
4983 if (num_range_list
== 0)
4985 /* This can happen when the file was compiled with -gsplit-debug
4986 which removes references to range lists from the primary .o file. */
4987 printf (_("No range lists in .debug_info section.\n"));
4991 range_entries
= (struct range_entry
*)
4992 xmalloc (sizeof (*range_entries
) * num_range_list
);
4993 range_entry_fill
= range_entries
;
4995 for (i
= 0; i
< num_debug_info_entries
; i
++)
4997 debug_info
*debug_info_p
= &debug_information
[i
];
5000 for (j
= 0; j
< debug_info_p
->num_range_lists
; j
++)
5002 range_entry_fill
->ranges_offset
= debug_info_p
->range_lists
[j
];
5003 range_entry_fill
->debug_info_p
= debug_info_p
;
5008 qsort (range_entries
, num_range_list
, sizeof (*range_entries
),
5009 range_entry_compar
);
5011 if (dwarf_check
!= 0 && range_entries
[0].ranges_offset
!= 0)
5012 warn (_("Range lists in %s section start at 0x%lx\n"),
5013 section
->name
, range_entries
[0].ranges_offset
);
5015 printf (_("Contents of the %s section:\n\n"), section
->name
);
5016 printf (_(" Offset Begin End\n"));
5018 for (i
= 0; i
< num_range_list
; i
++)
5020 struct range_entry
*range_entry
= &range_entries
[i
];
5021 debug_info
*debug_info_p
= range_entry
->debug_info_p
;
5022 unsigned int pointer_size
;
5023 unsigned long offset
;
5024 unsigned char *next
;
5025 unsigned long base_address
;
5027 pointer_size
= debug_info_p
->pointer_size
;
5028 offset
= range_entry
->ranges_offset
;
5029 next
= section_begin
+ offset
;
5030 base_address
= debug_info_p
->base_address
;
5032 /* PR 17512: file: 001-101485-0.001:0.1. */
5033 if (pointer_size
< 2 || pointer_size
> 8)
5035 warn (_("Corrupt pointer size (%d) in debug entry at offset %8.8lx\n"),
5036 pointer_size
, offset
);
5040 if (dwarf_check
!= 0 && i
> 0)
5043 warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"),
5044 (unsigned long) (start
- section_begin
),
5045 (unsigned long) (next
- section_begin
), section
->name
);
5046 else if (start
> next
)
5048 if (next
== last_start
)
5050 warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"),
5051 (unsigned long) (start
- section_begin
),
5052 (unsigned long) (next
- section_begin
), section
->name
);
5058 while (start
< finish
)
5063 /* Note: we use sign extension here in order to be sure that
5064 we can detect the -1 escape value. Sign extension into the
5065 top 32 bits of a 32-bit address will not affect the values
5066 that we display since we always show hex values, and always
5067 the bottom 32-bits. */
5068 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
5069 if (start
>= finish
)
5071 SAFE_SIGNED_BYTE_GET_AND_INC (end
, start
, pointer_size
, finish
);
5073 printf (" %8.8lx ", offset
);
5075 if (begin
== 0 && end
== 0)
5077 printf (_("<End of list>\n"));
5081 /* Check base address specifiers. */
5082 if (begin
== (dwarf_vma
) -1 && end
!= (dwarf_vma
) -1)
5085 print_dwarf_vma (begin
, pointer_size
);
5086 print_dwarf_vma (end
, pointer_size
);
5087 printf ("(base address)\n");
5091 print_dwarf_vma (begin
+ base_address
, pointer_size
);
5092 print_dwarf_vma (end
+ base_address
, pointer_size
);
5095 fputs (_("(start == end)"), stdout
);
5096 else if (begin
> end
)
5097 fputs (_("(start > end)"), stdout
);
5104 free (range_entries
);
5109 typedef struct Frame_Chunk
5111 struct Frame_Chunk
*next
;
5112 unsigned char *chunk_start
;
5114 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
5115 short int *col_type
;
5118 unsigned int code_factor
;
5125 unsigned char fde_encoding
;
5126 unsigned char cfa_exp
;
5127 unsigned char ptr_size
;
5128 unsigned char segment_size
;
5132 static const char *const *dwarf_regnames
;
5133 static unsigned int dwarf_regnames_count
;
5135 /* A marker for a col_type that means this column was never referenced
5136 in the frame info. */
5137 #define DW_CFA_unreferenced (-1)
5139 /* Return 0 if no more space is needed, 1 if more space is needed,
5140 -1 for invalid reg. */
5143 frame_need_space (Frame_Chunk
*fc
, unsigned int reg
)
5145 unsigned int prev
= fc
->ncols
;
5147 if (reg
< (unsigned int) fc
->ncols
)
5150 if (dwarf_regnames_count
5151 && reg
> dwarf_regnames_count
)
5154 fc
->ncols
= reg
+ 1;
5155 /* PR 17512: file: 10450-2643-0.004.
5156 If reg == -1 then this can happen... */
5160 /* PR 17512: file: 2844a11d. */
5161 if (fc
->ncols
> 1024)
5163 error (_("Unfeasibly large register number: %u\n"), reg
);
5165 /* FIXME: 1024 is an arbitrary limit. Increase it if
5166 we ever encounter a valid binary that exceeds it. */
5170 fc
->col_type
= (short int *) xcrealloc (fc
->col_type
, fc
->ncols
,
5171 sizeof (short int));
5172 fc
->col_offset
= (int *) xcrealloc (fc
->col_offset
, fc
->ncols
, sizeof (int));
5173 /* PR 17512: file:002-10025-0.005. */
5174 if (fc
->col_type
== NULL
|| fc
->col_offset
== NULL
)
5176 error (_("Out of memory allocating %u columns in dwarf frame arrays\n"),
5182 while (prev
< fc
->ncols
)
5184 fc
->col_type
[prev
] = DW_CFA_unreferenced
;
5185 fc
->col_offset
[prev
] = 0;
5191 static const char *const dwarf_regnames_i386
[] =
5193 "eax", "ecx", "edx", "ebx", /* 0 - 3 */
5194 "esp", "ebp", "esi", "edi", /* 4 - 7 */
5195 "eip", "eflags", NULL
, /* 8 - 10 */
5196 "st0", "st1", "st2", "st3", /* 11 - 14 */
5197 "st4", "st5", "st6", "st7", /* 15 - 18 */
5198 NULL
, NULL
, /* 19 - 20 */
5199 "xmm0", "xmm1", "xmm2", "xmm3", /* 21 - 24 */
5200 "xmm4", "xmm5", "xmm6", "xmm7", /* 25 - 28 */
5201 "mm0", "mm1", "mm2", "mm3", /* 29 - 32 */
5202 "mm4", "mm5", "mm6", "mm7", /* 33 - 36 */
5203 "fcw", "fsw", "mxcsr", /* 37 - 39 */
5204 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
, /* 40 - 47 */
5205 "tr", "ldtr", /* 48 - 49 */
5206 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 50 - 57 */
5207 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 58 - 65 */
5208 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 66 - 73 */
5209 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 74 - 81 */
5210 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 82 - 89 */
5211 NULL
, NULL
, NULL
, /* 90 - 92 */
5212 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7" /* 93 - 100 */
5216 init_dwarf_regnames_i386 (void)
5218 dwarf_regnames
= dwarf_regnames_i386
;
5219 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_i386
);
5222 static const char *const dwarf_regnames_x86_64
[] =
5224 "rax", "rdx", "rcx", "rbx",
5225 "rsi", "rdi", "rbp", "rsp",
5226 "r8", "r9", "r10", "r11",
5227 "r12", "r13", "r14", "r15",
5229 "xmm0", "xmm1", "xmm2", "xmm3",
5230 "xmm4", "xmm5", "xmm6", "xmm7",
5231 "xmm8", "xmm9", "xmm10", "xmm11",
5232 "xmm12", "xmm13", "xmm14", "xmm15",
5233 "st0", "st1", "st2", "st3",
5234 "st4", "st5", "st6", "st7",
5235 "mm0", "mm1", "mm2", "mm3",
5236 "mm4", "mm5", "mm6", "mm7",
5238 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
,
5239 "fs.base", "gs.base", NULL
, NULL
,
5241 "mxcsr", "fcw", "fsw",
5242 "xmm16", "xmm17", "xmm18", "xmm19",
5243 "xmm20", "xmm21", "xmm22", "xmm23",
5244 "xmm24", "xmm25", "xmm26", "xmm27",
5245 "xmm28", "xmm29", "xmm30", "xmm31",
5246 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 83 - 90 */
5247 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 91 - 98 */
5248 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 99 - 106 */
5249 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 107 - 114 */
5250 NULL
, NULL
, NULL
, /* 115 - 117 */
5251 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7"
5255 init_dwarf_regnames_x86_64 (void)
5257 dwarf_regnames
= dwarf_regnames_x86_64
;
5258 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_x86_64
);
5261 static const char *const dwarf_regnames_aarch64
[] =
5263 "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7",
5264 "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15",
5265 "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23",
5266 "x24", "x25", "x26", "x27", "x28", "x29", "x30", "sp",
5267 NULL
, "elr", NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
5268 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
5269 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
5270 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
5271 "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7",
5272 "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15",
5273 "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23",
5274 "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31",
5278 init_dwarf_regnames_aarch64 (void)
5280 dwarf_regnames
= dwarf_regnames_aarch64
;
5281 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_aarch64
);
5285 init_dwarf_regnames (unsigned int e_machine
)
5291 init_dwarf_regnames_i386 ();
5297 init_dwarf_regnames_x86_64 ();
5301 init_dwarf_regnames_aarch64 ();
5310 regname (unsigned int regno
, int row
)
5312 static char reg
[64];
5314 && regno
< dwarf_regnames_count
5315 && dwarf_regnames
[regno
] != NULL
)
5318 return dwarf_regnames
[regno
];
5319 snprintf (reg
, sizeof (reg
), "r%d (%s)", regno
,
5320 dwarf_regnames
[regno
]);
5323 snprintf (reg
, sizeof (reg
), "r%d", regno
);
5328 frame_display_row (Frame_Chunk
*fc
, int *need_col_headers
, unsigned int *max_regs
)
5333 if (*max_regs
< fc
->ncols
)
5334 *max_regs
= fc
->ncols
;
5336 if (*need_col_headers
)
5338 static const char *sloc
= " LOC";
5340 *need_col_headers
= 0;
5342 printf ("%-*s CFA ", eh_addr_size
* 2, sloc
);
5344 for (r
= 0; r
< *max_regs
; r
++)
5345 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
5350 printf ("%-5s ", regname (r
, 1));
5356 print_dwarf_vma (fc
->pc_begin
, eh_addr_size
);
5358 strcpy (tmp
, "exp");
5360 sprintf (tmp
, "%s%+d", regname (fc
->cfa_reg
, 1), fc
->cfa_offset
);
5361 printf ("%-8s ", tmp
);
5363 for (r
= 0; r
< fc
->ncols
; r
++)
5365 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
5367 switch (fc
->col_type
[r
])
5369 case DW_CFA_undefined
:
5372 case DW_CFA_same_value
:
5376 sprintf (tmp
, "c%+d", fc
->col_offset
[r
]);
5378 case DW_CFA_val_offset
:
5379 sprintf (tmp
, "v%+d", fc
->col_offset
[r
]);
5381 case DW_CFA_register
:
5382 sprintf (tmp
, "%s", regname (fc
->col_offset
[r
], 0));
5384 case DW_CFA_expression
:
5385 strcpy (tmp
, "exp");
5387 case DW_CFA_val_expression
:
5388 strcpy (tmp
, "vexp");
5391 strcpy (tmp
, "n/a");
5394 printf ("%-5s ", tmp
);
5400 #define GET(VAR, N) SAFE_BYTE_GET_AND_INC (VAR, start, N, end)
5401 #define LEB() read_uleb128 (start, & length_return, end); start += length_return
5402 #define SLEB() read_sleb128 (start, & length_return, end); start += length_return
5404 static unsigned char *
5405 read_cie (unsigned char *start
, unsigned char *end
,
5406 Frame_Chunk
**p_cie
, int *p_version
,
5407 unsigned long *p_aug_len
, unsigned char **p_aug
)
5411 unsigned int length_return
;
5412 unsigned char *augmentation_data
= NULL
;
5413 unsigned long augmentation_data_len
= 0;
5416 /* PR 17512: file: 001-228113-0.004. */
5420 fc
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
5421 memset (fc
, 0, sizeof (Frame_Chunk
));
5423 fc
->col_type
= (short int *) xmalloc (sizeof (short int));
5424 fc
->col_offset
= (int *) xmalloc (sizeof (int));
5428 fc
->augmentation
= (char *) start
;
5429 /* PR 17512: file: 001-228113-0.004.
5430 Skip past augmentation name, but avoid running off the end of the data. */
5432 if (* start
++ == '\0')
5436 warn (_("No terminator for augmentation name\n"));
5440 if (strcmp (fc
->augmentation
, "eh") == 0)
5441 start
+= eh_addr_size
;
5445 GET (fc
->ptr_size
, 1);
5446 GET (fc
->segment_size
, 1);
5447 eh_addr_size
= fc
->ptr_size
;
5451 fc
->ptr_size
= eh_addr_size
;
5452 fc
->segment_size
= 0;
5454 fc
->code_factor
= LEB ();
5455 fc
->data_factor
= SLEB ();
5465 if (fc
->augmentation
[0] == 'z')
5467 augmentation_data_len
= LEB ();
5468 augmentation_data
= start
;
5469 start
+= augmentation_data_len
;
5470 /* PR 17512: file: 11042-2589-0.004. */
5473 warn (_("Augmentation data too long: 0x%lx"), augmentation_data_len
);
5478 if (augmentation_data_len
)
5480 unsigned char *p
, *q
;
5481 p
= (unsigned char *) fc
->augmentation
+ 1;
5482 q
= augmentation_data
;
5484 while (p
< end
&& q
< augmentation_data
+ augmentation_data_len
)
5489 q
+= 1 + size_of_encoded_value (*q
);
5491 fc
->fde_encoding
= *q
++;
5502 *p_version
= version
;
5505 *p_aug_len
= augmentation_data_len
;
5506 *p_aug
= augmentation_data
;
5512 display_debug_frames (struct dwarf_section
*section
,
5513 void *file ATTRIBUTE_UNUSED
)
5515 unsigned char *start
= section
->start
;
5516 unsigned char *end
= start
+ section
->size
;
5517 unsigned char *section_start
= start
;
5518 Frame_Chunk
*chunks
= 0, *forward_refs
= 0;
5519 Frame_Chunk
*remembered_state
= 0;
5521 int is_eh
= strcmp (section
->name
, ".eh_frame") == 0;
5522 unsigned int length_return
;
5523 unsigned int max_regs
= 0;
5524 const char *bad_reg
= _("bad register: ");
5525 int saved_eh_addr_size
= eh_addr_size
;
5527 printf (_("Contents of the %s section:\n"), section
->name
);
5531 unsigned char *saved_start
;
5532 unsigned char *block_end
;
5537 int need_col_headers
= 1;
5538 unsigned char *augmentation_data
= NULL
;
5539 unsigned long augmentation_data_len
= 0;
5540 unsigned int encoded_ptr_size
= saved_eh_addr_size
;
5541 unsigned int offset_size
;
5542 unsigned int initial_length_size
;
5544 saved_start
= start
;
5546 SAFE_BYTE_GET_AND_INC (length
, start
, 4, end
);
5550 printf ("\n%08lx ZERO terminator\n\n",
5551 (unsigned long)(saved_start
- section_start
));
5552 /* Skip any zero terminators that directly follow.
5553 A corrupt section size could have loaded a whole
5554 slew of zero filled memory bytes. eg
5555 PR 17512: file: 070-19381-0.004. */
5556 while (start
< end
&& * start
== 0)
5561 if (length
== 0xffffffff)
5563 SAFE_BYTE_GET_AND_INC (length
, start
, 8, end
);
5565 initial_length_size
= 12;
5570 initial_length_size
= 4;
5573 block_end
= saved_start
+ length
+ initial_length_size
;
5574 if (block_end
> end
|| block_end
< start
)
5576 warn ("Invalid length 0x%s in FDE at %#08lx\n",
5577 dwarf_vmatoa_1 (NULL
, length
, offset_size
),
5578 (unsigned long) (saved_start
- section_start
));
5582 SAFE_BYTE_GET_AND_INC (cie_id
, start
, offset_size
, end
);
5584 if (is_eh
? (cie_id
== 0) : ((offset_size
== 4 && cie_id
== DW_CIE_ID
)
5585 || (offset_size
== 8 && cie_id
== DW64_CIE_ID
)))
5590 start
= read_cie (start
, end
, &cie
, &version
,
5591 &augmentation_data_len
, &augmentation_data
);
5592 /* PR 17512: file: 027-135133-0.005. */
5599 fc
->chunk_start
= saved_start
;
5600 mreg
= max_regs
> 0 ? max_regs
- 1 : 0;
5603 if (frame_need_space (fc
, mreg
) < 0)
5605 if (fc
->fde_encoding
)
5606 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
5608 printf ("\n%08lx ", (unsigned long) (saved_start
- section_start
));
5609 print_dwarf_vma (length
, fc
->ptr_size
);
5610 print_dwarf_vma (cie_id
, offset_size
);
5612 if (do_debug_frames_interp
)
5614 printf ("CIE \"%s\" cf=%d df=%d ra=%d\n", fc
->augmentation
,
5615 fc
->code_factor
, fc
->data_factor
, fc
->ra
);
5620 printf (" Version: %d\n", version
);
5621 printf (" Augmentation: \"%s\"\n", fc
->augmentation
);
5624 printf (" Pointer Size: %u\n", fc
->ptr_size
);
5625 printf (" Segment Size: %u\n", fc
->segment_size
);
5627 printf (" Code alignment factor: %u\n", fc
->code_factor
);
5628 printf (" Data alignment factor: %d\n", fc
->data_factor
);
5629 printf (" Return address column: %d\n", fc
->ra
);
5631 if (augmentation_data_len
)
5635 printf (" Augmentation data: ");
5636 for (i
= 0; i
< augmentation_data_len
; ++i
)
5637 /* FIXME: If do_wide is FALSE, then we should
5638 add carriage returns at 80 columns... */
5639 printf (" %02x", augmentation_data
[i
]);
5647 unsigned char *look_for
;
5648 static Frame_Chunk fde_fc
;
5649 unsigned long segment_selector
;
5653 dwarf_vma sign
= (dwarf_vma
) 1 << (offset_size
* 8 - 1);
5654 look_for
= start
- 4 - ((cie_id
^ sign
) - sign
);
5657 look_for
= section_start
+ cie_id
;
5659 if (look_for
<= saved_start
)
5661 for (cie
= chunks
; cie
; cie
= cie
->next
)
5662 if (cie
->chunk_start
== look_for
)
5667 for (cie
= forward_refs
; cie
; cie
= cie
->next
)
5668 if (cie
->chunk_start
== look_for
)
5672 unsigned int off_size
;
5673 unsigned char *cie_scan
;
5675 cie_scan
= look_for
;
5677 SAFE_BYTE_GET_AND_INC (length
, cie_scan
, 4, end
);
5678 if (length
== 0xffffffff)
5680 SAFE_BYTE_GET_AND_INC (length
, cie_scan
, 8, end
);
5687 SAFE_BYTE_GET_AND_INC (c_id
, cie_scan
, off_size
, end
);
5690 : ((off_size
== 4 && c_id
== DW_CIE_ID
)
5691 || (off_size
== 8 && c_id
== DW64_CIE_ID
)))
5696 read_cie (cie_scan
, end
, &cie
, &version
,
5697 &augmentation_data_len
, &augmentation_data
);
5698 /* PR 17512: file: 3450-2098-0.004. */
5701 warn (_("Failed to read CIE information\n"));
5704 cie
->next
= forward_refs
;
5706 cie
->chunk_start
= look_for
;
5707 mreg
= max_regs
> 0 ? max_regs
- 1 : 0;
5710 if (frame_need_space (cie
, mreg
) < 0)
5712 warn (_("Invalid max register\n"));
5715 if (cie
->fde_encoding
)
5717 = size_of_encoded_value (cie
->fde_encoding
);
5724 memset (fc
, 0, sizeof (Frame_Chunk
));
5728 warn ("Invalid CIE pointer 0x%s in FDE at %#08lx\n",
5729 dwarf_vmatoa_1 (NULL
, cie_id
, offset_size
),
5730 (unsigned long) (saved_start
- section_start
));
5732 fc
->col_type
= (short int *) xmalloc (sizeof (short int));
5733 fc
->col_offset
= (int *) xmalloc (sizeof (int));
5734 if (frame_need_space (fc
, max_regs
> 0 ? max_regs
- 1 : 0) < 0)
5736 warn (_("Invalid max register\n"));
5740 fc
->augmentation
= "";
5741 fc
->fde_encoding
= 0;
5742 fc
->ptr_size
= eh_addr_size
;
5743 fc
->segment_size
= 0;
5747 fc
->ncols
= cie
->ncols
;
5748 fc
->col_type
= (short int *) xcmalloc (fc
->ncols
, sizeof (short int));
5749 fc
->col_offset
= (int *) xcmalloc (fc
->ncols
, sizeof (int));
5750 memcpy (fc
->col_type
, cie
->col_type
, fc
->ncols
* sizeof (short int));
5751 memcpy (fc
->col_offset
, cie
->col_offset
, fc
->ncols
* sizeof (int));
5752 fc
->augmentation
= cie
->augmentation
;
5753 fc
->ptr_size
= cie
->ptr_size
;
5754 eh_addr_size
= cie
->ptr_size
;
5755 fc
->segment_size
= cie
->segment_size
;
5756 fc
->code_factor
= cie
->code_factor
;
5757 fc
->data_factor
= cie
->data_factor
;
5758 fc
->cfa_reg
= cie
->cfa_reg
;
5759 fc
->cfa_offset
= cie
->cfa_offset
;
5761 if (frame_need_space (fc
, max_regs
> 0 ? max_regs
- 1: 0) < 0)
5763 warn (_("Invalid max register\n"));
5766 fc
->fde_encoding
= cie
->fde_encoding
;
5769 if (fc
->fde_encoding
)
5770 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
5772 segment_selector
= 0;
5773 if (fc
->segment_size
)
5774 SAFE_BYTE_GET_AND_INC (segment_selector
, start
, fc
->segment_size
, end
);
5776 fc
->pc_begin
= get_encoded_value (&start
, fc
->fde_encoding
, section
, end
);
5778 /* FIXME: It appears that sometimes the final pc_range value is
5779 encoded in less than encoded_ptr_size bytes. See the x86_64
5780 run of the "objcopy on compressed debug sections" test for an
5782 SAFE_BYTE_GET_AND_INC (fc
->pc_range
, start
, encoded_ptr_size
, end
);
5784 if (cie
->augmentation
[0] == 'z')
5786 augmentation_data_len
= LEB ();
5787 augmentation_data
= start
;
5788 start
+= augmentation_data_len
;
5789 /* PR 17512: file: 722-8446-0.004. */
5790 if (start
>= end
|| ((signed long) augmentation_data_len
) < 0)
5792 warn (_("Corrupt augmentation data length: %lx\n"),
5793 augmentation_data_len
);
5795 augmentation_data
= NULL
;
5796 augmentation_data_len
= 0;
5800 printf ("\n%08lx %s %s FDE cie=%08lx pc=",
5801 (unsigned long)(saved_start
- section_start
),
5802 dwarf_vmatoa_1 (NULL
, length
, fc
->ptr_size
),
5803 dwarf_vmatoa_1 (NULL
, cie_id
, offset_size
),
5804 (unsigned long)(cie
->chunk_start
- section_start
));
5806 if (fc
->segment_size
)
5807 printf ("%04lx:", segment_selector
);
5810 dwarf_vmatoa_1 (NULL
, fc
->pc_begin
, fc
->ptr_size
),
5811 dwarf_vmatoa_1 (NULL
, fc
->pc_begin
+ fc
->pc_range
, fc
->ptr_size
));
5813 if (! do_debug_frames_interp
&& augmentation_data_len
)
5817 printf (" Augmentation data: ");
5818 for (i
= 0; i
< augmentation_data_len
; ++i
)
5819 printf (" %02x", augmentation_data
[i
]);
5825 /* At this point, fc is the current chunk, cie (if any) is set, and
5826 we're about to interpret instructions for the chunk. */
5827 /* ??? At present we need to do this always, since this sizes the
5828 fc->col_type and fc->col_offset arrays, which we write into always.
5829 We should probably split the interpreted and non-interpreted bits
5830 into two different routines, since there's so much that doesn't
5831 really overlap between them. */
5832 if (1 || do_debug_frames_interp
)
5834 /* Start by making a pass over the chunk, allocating storage
5835 and taking note of what registers are used. */
5836 unsigned char *tmp
= start
;
5838 while (start
< block_end
)
5840 unsigned int reg
, op
, opa
;
5848 /* Warning: if you add any more cases to this switch, be
5849 sure to add them to the corresponding switch below. */
5852 case DW_CFA_advance_loc
:
5856 if (frame_need_space (fc
, opa
) >= 0)
5857 fc
->col_type
[opa
] = DW_CFA_undefined
;
5859 case DW_CFA_restore
:
5860 if (frame_need_space (fc
, opa
) >= 0)
5861 fc
->col_type
[opa
] = DW_CFA_undefined
;
5863 case DW_CFA_set_loc
:
5864 start
+= encoded_ptr_size
;
5866 case DW_CFA_advance_loc1
:
5869 case DW_CFA_advance_loc2
:
5872 case DW_CFA_advance_loc4
:
5875 case DW_CFA_offset_extended
:
5876 case DW_CFA_val_offset
:
5877 reg
= LEB (); LEB ();
5878 if (frame_need_space (fc
, reg
) >= 0)
5879 fc
->col_type
[reg
] = DW_CFA_undefined
;
5881 case DW_CFA_restore_extended
:
5883 if (frame_need_space (fc
, reg
) >= 0)
5884 fc
->col_type
[reg
] = DW_CFA_undefined
;
5886 case DW_CFA_undefined
:
5888 if (frame_need_space (fc
, reg
) >= 0)
5889 fc
->col_type
[reg
] = DW_CFA_undefined
;
5891 case DW_CFA_same_value
:
5893 if (frame_need_space (fc
, reg
) >= 0)
5894 fc
->col_type
[reg
] = DW_CFA_undefined
;
5896 case DW_CFA_register
:
5897 reg
= LEB (); LEB ();
5898 if (frame_need_space (fc
, reg
) >= 0)
5899 fc
->col_type
[reg
] = DW_CFA_undefined
;
5901 case DW_CFA_def_cfa
:
5904 case DW_CFA_def_cfa_register
:
5907 case DW_CFA_def_cfa_offset
:
5910 case DW_CFA_def_cfa_expression
:
5912 if (start
+ temp
< start
)
5914 warn (_("Corrupt CFA_def expression value: %lu\n"), temp
);
5920 case DW_CFA_expression
:
5921 case DW_CFA_val_expression
:
5924 if (start
+ temp
< start
)
5926 /* PR 17512: file:306-192417-0.005. */
5927 warn (_("Corrupt CFA expression value: %lu\n"), temp
);
5932 if (frame_need_space (fc
, reg
) >= 0)
5933 fc
->col_type
[reg
] = DW_CFA_undefined
;
5935 case DW_CFA_offset_extended_sf
:
5936 case DW_CFA_val_offset_sf
:
5937 reg
= LEB (); SLEB ();
5938 if (frame_need_space (fc
, reg
) >= 0)
5939 fc
->col_type
[reg
] = DW_CFA_undefined
;
5941 case DW_CFA_def_cfa_sf
:
5944 case DW_CFA_def_cfa_offset_sf
:
5947 case DW_CFA_MIPS_advance_loc8
:
5950 case DW_CFA_GNU_args_size
:
5953 case DW_CFA_GNU_negative_offset_extended
:
5954 reg
= LEB (); LEB ();
5955 if (frame_need_space (fc
, reg
) >= 0)
5956 fc
->col_type
[reg
] = DW_CFA_undefined
;
5965 /* Now we know what registers are used, make a second pass over
5966 the chunk, this time actually printing out the info. */
5968 while (start
< block_end
)
5971 unsigned long ul
, reg
, roffs
;
5975 const char *reg_prefix
= "";
5982 /* Warning: if you add any more cases to this switch, be
5983 sure to add them to the corresponding switch above. */
5986 case DW_CFA_advance_loc
:
5987 if (do_debug_frames_interp
)
5988 frame_display_row (fc
, &need_col_headers
, &max_regs
);
5990 printf (" DW_CFA_advance_loc: %d to %s\n",
5991 opa
* fc
->code_factor
,
5992 dwarf_vmatoa_1 (NULL
,
5993 fc
->pc_begin
+ opa
* fc
->code_factor
,
5995 fc
->pc_begin
+= opa
* fc
->code_factor
;
6000 if (opa
>= (unsigned int) fc
->ncols
)
6001 reg_prefix
= bad_reg
;
6002 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
6003 printf (" DW_CFA_offset: %s%s at cfa%+ld\n",
6004 reg_prefix
, regname (opa
, 0),
6005 roffs
* fc
->data_factor
);
6006 if (*reg_prefix
== '\0')
6008 fc
->col_type
[opa
] = DW_CFA_offset
;
6009 fc
->col_offset
[opa
] = roffs
* fc
->data_factor
;
6013 case DW_CFA_restore
:
6014 if (opa
>= (unsigned int) cie
->ncols
6015 || opa
>= (unsigned int) fc
->ncols
)
6016 reg_prefix
= bad_reg
;
6017 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
6018 printf (" DW_CFA_restore: %s%s\n",
6019 reg_prefix
, regname (opa
, 0));
6020 if (*reg_prefix
== '\0')
6022 fc
->col_type
[opa
] = cie
->col_type
[opa
];
6023 fc
->col_offset
[opa
] = cie
->col_offset
[opa
];
6024 if (do_debug_frames_interp
6025 && fc
->col_type
[opa
] == DW_CFA_unreferenced
)
6026 fc
->col_type
[opa
] = DW_CFA_undefined
;
6030 case DW_CFA_set_loc
:
6031 vma
= get_encoded_value (&start
, fc
->fde_encoding
, section
, block_end
);
6032 if (do_debug_frames_interp
)
6033 frame_display_row (fc
, &need_col_headers
, &max_regs
);
6035 printf (" DW_CFA_set_loc: %s\n",
6036 dwarf_vmatoa_1 (NULL
, vma
, fc
->ptr_size
));
6040 case DW_CFA_advance_loc1
:
6041 SAFE_BYTE_GET_AND_INC (ofs
, start
, 1, end
);
6042 if (do_debug_frames_interp
)
6043 frame_display_row (fc
, &need_col_headers
, &max_regs
);
6045 printf (" DW_CFA_advance_loc1: %ld to %s\n",
6046 (unsigned long) (ofs
* fc
->code_factor
),
6047 dwarf_vmatoa_1 (NULL
,
6048 fc
->pc_begin
+ ofs
* fc
->code_factor
,
6050 fc
->pc_begin
+= ofs
* fc
->code_factor
;
6053 case DW_CFA_advance_loc2
:
6054 SAFE_BYTE_GET_AND_INC (ofs
, start
, 2, block_end
);
6055 if (do_debug_frames_interp
)
6056 frame_display_row (fc
, &need_col_headers
, &max_regs
);
6058 printf (" DW_CFA_advance_loc2: %ld to %s\n",
6059 (unsigned long) (ofs
* fc
->code_factor
),
6060 dwarf_vmatoa_1 (NULL
,
6061 fc
->pc_begin
+ ofs
* fc
->code_factor
,
6063 fc
->pc_begin
+= ofs
* fc
->code_factor
;
6066 case DW_CFA_advance_loc4
:
6067 SAFE_BYTE_GET_AND_INC (ofs
, start
, 4, block_end
);
6068 if (do_debug_frames_interp
)
6069 frame_display_row (fc
, &need_col_headers
, &max_regs
);
6071 printf (" DW_CFA_advance_loc4: %ld to %s\n",
6072 (unsigned long) (ofs
* fc
->code_factor
),
6073 dwarf_vmatoa_1 (NULL
,
6074 fc
->pc_begin
+ ofs
* fc
->code_factor
,
6076 fc
->pc_begin
+= ofs
* fc
->code_factor
;
6079 case DW_CFA_offset_extended
:
6082 if (reg
>= (unsigned int) fc
->ncols
)
6083 reg_prefix
= bad_reg
;
6084 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
6085 printf (" DW_CFA_offset_extended: %s%s at cfa%+ld\n",
6086 reg_prefix
, regname (reg
, 0),
6087 roffs
* fc
->data_factor
);
6088 if (*reg_prefix
== '\0')
6090 fc
->col_type
[reg
] = DW_CFA_offset
;
6091 fc
->col_offset
[reg
] = roffs
* fc
->data_factor
;
6095 case DW_CFA_val_offset
:
6098 if (reg
>= (unsigned int) fc
->ncols
)
6099 reg_prefix
= bad_reg
;
6100 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
6101 printf (" DW_CFA_val_offset: %s%s at cfa%+ld\n",
6102 reg_prefix
, regname (reg
, 0),
6103 roffs
* fc
->data_factor
);
6104 if (*reg_prefix
== '\0')
6106 fc
->col_type
[reg
] = DW_CFA_val_offset
;
6107 fc
->col_offset
[reg
] = roffs
* fc
->data_factor
;
6111 case DW_CFA_restore_extended
:
6113 if (reg
>= (unsigned int) cie
->ncols
6114 || reg
>= (unsigned int) fc
->ncols
)
6115 reg_prefix
= bad_reg
;
6116 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
6117 printf (" DW_CFA_restore_extended: %s%s\n",
6118 reg_prefix
, regname (reg
, 0));
6119 if (*reg_prefix
== '\0')
6121 fc
->col_type
[reg
] = cie
->col_type
[reg
];
6122 fc
->col_offset
[reg
] = cie
->col_offset
[reg
];
6126 case DW_CFA_undefined
:
6128 if (reg
>= (unsigned int) fc
->ncols
)
6129 reg_prefix
= bad_reg
;
6130 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
6131 printf (" DW_CFA_undefined: %s%s\n",
6132 reg_prefix
, regname (reg
, 0));
6133 if (*reg_prefix
== '\0')
6135 fc
->col_type
[reg
] = DW_CFA_undefined
;
6136 fc
->col_offset
[reg
] = 0;
6140 case DW_CFA_same_value
:
6142 if (reg
>= (unsigned int) fc
->ncols
)
6143 reg_prefix
= bad_reg
;
6144 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
6145 printf (" DW_CFA_same_value: %s%s\n",
6146 reg_prefix
, regname (reg
, 0));
6147 if (*reg_prefix
== '\0')
6149 fc
->col_type
[reg
] = DW_CFA_same_value
;
6150 fc
->col_offset
[reg
] = 0;
6154 case DW_CFA_register
:
6157 if (reg
>= (unsigned int) fc
->ncols
)
6158 reg_prefix
= bad_reg
;
6159 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
6161 printf (" DW_CFA_register: %s%s in ",
6162 reg_prefix
, regname (reg
, 0));
6163 puts (regname (roffs
, 0));
6165 if (*reg_prefix
== '\0')
6167 fc
->col_type
[reg
] = DW_CFA_register
;
6168 fc
->col_offset
[reg
] = roffs
;
6172 case DW_CFA_remember_state
:
6173 if (! do_debug_frames_interp
)
6174 printf (" DW_CFA_remember_state\n");
6175 rs
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
6176 rs
->cfa_offset
= fc
->cfa_offset
;
6177 rs
->cfa_reg
= fc
->cfa_reg
;
6179 rs
->cfa_exp
= fc
->cfa_exp
;
6180 rs
->ncols
= fc
->ncols
;
6181 rs
->col_type
= (short int *) xcmalloc (rs
->ncols
,
6182 sizeof (* rs
->col_type
));
6183 rs
->col_offset
= (int *) xcmalloc (rs
->ncols
, sizeof (* rs
->col_offset
));
6184 memcpy (rs
->col_type
, fc
->col_type
, rs
->ncols
* sizeof (* fc
->col_type
));
6185 memcpy (rs
->col_offset
, fc
->col_offset
, rs
->ncols
* sizeof (* fc
->col_offset
));
6186 rs
->next
= remembered_state
;
6187 remembered_state
= rs
;
6190 case DW_CFA_restore_state
:
6191 if (! do_debug_frames_interp
)
6192 printf (" DW_CFA_restore_state\n");
6193 rs
= remembered_state
;
6196 remembered_state
= rs
->next
;
6197 fc
->cfa_offset
= rs
->cfa_offset
;
6198 fc
->cfa_reg
= rs
->cfa_reg
;
6200 fc
->cfa_exp
= rs
->cfa_exp
;
6201 if (frame_need_space (fc
, rs
->ncols
- 1) < 0)
6203 warn (_("Invalid column number in saved frame state"));
6207 memcpy (fc
->col_type
, rs
->col_type
, rs
->ncols
* sizeof (* rs
->col_type
));
6208 memcpy (fc
->col_offset
, rs
->col_offset
,
6209 rs
->ncols
* sizeof (* rs
->col_offset
));
6210 free (rs
->col_type
);
6211 free (rs
->col_offset
);
6214 else if (do_debug_frames_interp
)
6215 printf ("Mismatched DW_CFA_restore_state\n");
6218 case DW_CFA_def_cfa
:
6219 fc
->cfa_reg
= LEB ();
6220 fc
->cfa_offset
= LEB ();
6222 if (! do_debug_frames_interp
)
6223 printf (" DW_CFA_def_cfa: %s ofs %d\n",
6224 regname (fc
->cfa_reg
, 0), fc
->cfa_offset
);
6227 case DW_CFA_def_cfa_register
:
6228 fc
->cfa_reg
= LEB ();
6230 if (! do_debug_frames_interp
)
6231 printf (" DW_CFA_def_cfa_register: %s\n",
6232 regname (fc
->cfa_reg
, 0));
6235 case DW_CFA_def_cfa_offset
:
6236 fc
->cfa_offset
= LEB ();
6237 if (! do_debug_frames_interp
)
6238 printf (" DW_CFA_def_cfa_offset: %d\n", fc
->cfa_offset
);
6242 if (! do_debug_frames_interp
)
6243 printf (" DW_CFA_nop\n");
6246 case DW_CFA_def_cfa_expression
:
6248 if (start
>= block_end
|| start
+ ul
> block_end
|| start
+ ul
< start
)
6250 printf (_(" DW_CFA_def_cfa_expression: <corrupt len %lu>\n"), ul
);
6253 if (! do_debug_frames_interp
)
6255 printf (" DW_CFA_def_cfa_expression (");
6256 decode_location_expression (start
, eh_addr_size
, 0, -1,
6264 case DW_CFA_expression
:
6267 if (reg
>= (unsigned int) fc
->ncols
)
6268 reg_prefix
= bad_reg
;
6269 /* PR 17512: file: 069-133014-0.006. */
6270 /* PR 17512: file: 98c02eb4. */
6271 if (start
>= block_end
|| start
+ ul
> block_end
|| start
+ ul
< start
)
6273 printf (_(" DW_CFA_expression: <corrupt len %lu>\n"), ul
);
6276 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
6278 printf (" DW_CFA_expression: %s%s (",
6279 reg_prefix
, regname (reg
, 0));
6280 decode_location_expression (start
, eh_addr_size
, 0, -1,
6284 if (*reg_prefix
== '\0')
6285 fc
->col_type
[reg
] = DW_CFA_expression
;
6289 case DW_CFA_val_expression
:
6292 if (reg
>= (unsigned int) fc
->ncols
)
6293 reg_prefix
= bad_reg
;
6294 if (start
>= block_end
|| start
+ ul
> block_end
|| start
+ ul
< start
)
6296 printf (" DW_CFA_val_expression: <corrupt len %lu>\n", ul
);
6299 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
6301 printf (" DW_CFA_val_expression: %s%s (",
6302 reg_prefix
, regname (reg
, 0));
6303 decode_location_expression (start
, eh_addr_size
, 0, -1,
6307 if (*reg_prefix
== '\0')
6308 fc
->col_type
[reg
] = DW_CFA_val_expression
;
6312 case DW_CFA_offset_extended_sf
:
6315 if (frame_need_space (fc
, reg
) < 0)
6316 reg_prefix
= bad_reg
;
6317 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
6318 printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+ld\n",
6319 reg_prefix
, regname (reg
, 0),
6320 l
* fc
->data_factor
);
6321 if (*reg_prefix
== '\0')
6323 fc
->col_type
[reg
] = DW_CFA_offset
;
6324 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
6328 case DW_CFA_val_offset_sf
:
6331 if (frame_need_space (fc
, reg
) < 0)
6332 reg_prefix
= bad_reg
;
6333 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
6334 printf (" DW_CFA_val_offset_sf: %s%s at cfa%+ld\n",
6335 reg_prefix
, regname (reg
, 0),
6336 l
* fc
->data_factor
);
6337 if (*reg_prefix
== '\0')
6339 fc
->col_type
[reg
] = DW_CFA_val_offset
;
6340 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
6344 case DW_CFA_def_cfa_sf
:
6345 fc
->cfa_reg
= LEB ();
6346 fc
->cfa_offset
= SLEB ();
6347 fc
->cfa_offset
= fc
->cfa_offset
* fc
->data_factor
;
6349 if (! do_debug_frames_interp
)
6350 printf (" DW_CFA_def_cfa_sf: %s ofs %d\n",
6351 regname (fc
->cfa_reg
, 0), fc
->cfa_offset
);
6354 case DW_CFA_def_cfa_offset_sf
:
6355 fc
->cfa_offset
= SLEB ();
6356 fc
->cfa_offset
= fc
->cfa_offset
* fc
->data_factor
;
6357 if (! do_debug_frames_interp
)
6358 printf (" DW_CFA_def_cfa_offset_sf: %d\n", fc
->cfa_offset
);
6361 case DW_CFA_MIPS_advance_loc8
:
6362 SAFE_BYTE_GET_AND_INC (ofs
, start
, 8, block_end
);
6363 if (do_debug_frames_interp
)
6364 frame_display_row (fc
, &need_col_headers
, &max_regs
);
6366 printf (" DW_CFA_MIPS_advance_loc8: %ld to %s\n",
6367 (unsigned long) (ofs
* fc
->code_factor
),
6368 dwarf_vmatoa_1 (NULL
,
6369 fc
->pc_begin
+ ofs
* fc
->code_factor
,
6371 fc
->pc_begin
+= ofs
* fc
->code_factor
;
6374 case DW_CFA_GNU_window_save
:
6375 if (! do_debug_frames_interp
)
6376 printf (" DW_CFA_GNU_window_save\n");
6379 case DW_CFA_GNU_args_size
:
6381 if (! do_debug_frames_interp
)
6382 printf (" DW_CFA_GNU_args_size: %ld\n", ul
);
6385 case DW_CFA_GNU_negative_offset_extended
:
6388 if (frame_need_space (fc
, reg
) < 0)
6389 reg_prefix
= bad_reg
;
6390 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
6391 printf (" DW_CFA_GNU_negative_offset_extended: %s%s at cfa%+ld\n",
6392 reg_prefix
, regname (reg
, 0),
6393 l
* fc
->data_factor
);
6394 if (*reg_prefix
== '\0')
6396 fc
->col_type
[reg
] = DW_CFA_offset
;
6397 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
6402 if (op
>= DW_CFA_lo_user
&& op
<= DW_CFA_hi_user
)
6403 printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op
);
6405 warn (_("Unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op
);
6410 if (do_debug_frames_interp
)
6411 frame_display_row (fc
, &need_col_headers
, &max_regs
);
6414 eh_addr_size
= saved_eh_addr_size
;
6427 display_gdb_index (struct dwarf_section
*section
,
6428 void *file ATTRIBUTE_UNUSED
)
6430 unsigned char *start
= section
->start
;
6432 uint32_t cu_list_offset
, tu_list_offset
;
6433 uint32_t address_table_offset
, symbol_table_offset
, constant_pool_offset
;
6434 unsigned int cu_list_elements
, tu_list_elements
;
6435 unsigned int address_table_size
, symbol_table_slots
;
6436 unsigned char *cu_list
, *tu_list
;
6437 unsigned char *address_table
, *symbol_table
, *constant_pool
;
6440 /* The documentation for the format of this file is in gdb/dwarf2read.c. */
6442 printf (_("Contents of the %s section:\n"), section
->name
);
6444 if (section
->size
< 6 * sizeof (uint32_t))
6446 warn (_("Truncated header in the %s section.\n"), section
->name
);
6450 version
= byte_get_little_endian (start
, 4);
6451 printf (_("Version %ld\n"), (long) version
);
6453 /* Prior versions are obsolete, and future versions may not be
6454 backwards compatible. */
6455 if (version
< 3 || version
> 8)
6457 warn (_("Unsupported version %lu.\n"), (unsigned long) version
);
6461 warn (_("The address table data in version 3 may be wrong.\n"));
6463 warn (_("Version 4 does not support case insensitive lookups.\n"));
6465 warn (_("Version 5 does not include inlined functions.\n"));
6467 warn (_("Version 6 does not include symbol attributes.\n"));
6468 /* Version 7 indices generated by Gold have bad type unit references,
6469 PR binutils/15021. But we don't know if the index was generated by
6470 Gold or not, so to avoid worrying users with gdb-generated indices
6471 we say nothing for version 7 here. */
6473 cu_list_offset
= byte_get_little_endian (start
+ 4, 4);
6474 tu_list_offset
= byte_get_little_endian (start
+ 8, 4);
6475 address_table_offset
= byte_get_little_endian (start
+ 12, 4);
6476 symbol_table_offset
= byte_get_little_endian (start
+ 16, 4);
6477 constant_pool_offset
= byte_get_little_endian (start
+ 20, 4);
6479 if (cu_list_offset
> section
->size
6480 || tu_list_offset
> section
->size
6481 || address_table_offset
> section
->size
6482 || symbol_table_offset
> section
->size
6483 || constant_pool_offset
> section
->size
)
6485 warn (_("Corrupt header in the %s section.\n"), section
->name
);
6489 /* PR 17531: file: 418d0a8a. */
6490 if (tu_list_offset
< cu_list_offset
)
6492 warn (_("TU offset (%x) is less than CU offset (%x)\n"),
6493 tu_list_offset
, cu_list_offset
);
6497 cu_list_elements
= (tu_list_offset
- cu_list_offset
) / 8;
6499 if (address_table_offset
< tu_list_offset
)
6501 warn (_("Address table offset (%x) is less than TU offset (%x)\n"),
6502 address_table_offset
, tu_list_offset
);
6506 tu_list_elements
= (address_table_offset
- tu_list_offset
) / 8;
6508 /* PR 17531: file: 18a47d3d. */
6509 if (symbol_table_offset
< address_table_offset
)
6511 warn (_("Symbolt table offset (%xl) is less then Address table offset (%x)\n"),
6512 symbol_table_offset
, address_table_offset
);
6516 address_table_size
= symbol_table_offset
- address_table_offset
;
6518 if (constant_pool_offset
< symbol_table_offset
)
6520 warn (_("Constant pool offset (%x) is less than symbol table offset (%x)\n"),
6521 constant_pool_offset
, symbol_table_offset
);
6525 symbol_table_slots
= (constant_pool_offset
- symbol_table_offset
) / 8;
6527 cu_list
= start
+ cu_list_offset
;
6528 tu_list
= start
+ tu_list_offset
;
6529 address_table
= start
+ address_table_offset
;
6530 symbol_table
= start
+ symbol_table_offset
;
6531 constant_pool
= start
+ constant_pool_offset
;
6533 printf (_("\nCU table:\n"));
6534 for (i
= 0; i
< cu_list_elements
; i
+= 2)
6536 uint64_t cu_offset
= byte_get_little_endian (cu_list
+ i
* 8, 8);
6537 uint64_t cu_length
= byte_get_little_endian (cu_list
+ i
* 8 + 8, 8);
6539 printf (_("[%3u] 0x%lx - 0x%lx\n"), i
/ 2,
6540 (unsigned long) cu_offset
,
6541 (unsigned long) (cu_offset
+ cu_length
- 1));
6544 printf (_("\nTU table:\n"));
6545 for (i
= 0; i
< tu_list_elements
; i
+= 3)
6547 uint64_t tu_offset
= byte_get_little_endian (tu_list
+ i
* 8, 8);
6548 uint64_t type_offset
= byte_get_little_endian (tu_list
+ i
* 8 + 8, 8);
6549 uint64_t signature
= byte_get_little_endian (tu_list
+ i
* 8 + 16, 8);
6551 printf (_("[%3u] 0x%lx 0x%lx "), i
/ 3,
6552 (unsigned long) tu_offset
,
6553 (unsigned long) type_offset
);
6554 print_dwarf_vma (signature
, 8);
6558 printf (_("\nAddress table:\n"));
6559 for (i
= 0; i
<= address_table_size
- (2 * 8 + 4); i
+= 2 * 8 + 4)
6561 uint64_t low
= byte_get_little_endian (address_table
+ i
, 8);
6562 uint64_t high
= byte_get_little_endian (address_table
+ i
+ 8, 8);
6563 uint32_t cu_index
= byte_get_little_endian (address_table
+ i
+ 16, 4);
6565 print_dwarf_vma (low
, 8);
6566 print_dwarf_vma (high
, 8);
6567 printf (_("%lu\n"), (unsigned long) cu_index
);
6570 printf (_("\nSymbol table:\n"));
6571 for (i
= 0; i
< symbol_table_slots
; ++i
)
6573 uint32_t name_offset
= byte_get_little_endian (symbol_table
+ i
* 8, 4);
6574 uint32_t cu_vector_offset
= byte_get_little_endian (symbol_table
+ i
* 8 + 4, 4);
6575 uint32_t num_cus
, cu
;
6577 if (name_offset
!= 0
6578 || cu_vector_offset
!= 0)
6582 /* PR 17531: file: 5b7b07ad. */
6583 if (constant_pool
+ name_offset
< constant_pool
6584 || constant_pool
+ name_offset
>= section
->start
+ section
->size
)
6586 printf (_("[%3u] <corrupt offset: %x>"), i
, name_offset
);
6587 warn (_("Corrupt name offset of 0x%x found for symbol table slot %d\n"),
6591 printf ("[%3u] %s:", i
, constant_pool
+ name_offset
);
6593 if (constant_pool
+ cu_vector_offset
< constant_pool
6594 || constant_pool
+ cu_vector_offset
>= section
->start
+ section
->size
)
6596 printf (_("<invalid CU vector offset: %x>\n"), cu_vector_offset
);
6597 warn (_("Corrupt CU vector offset of 0x%x found for symbol table slot %d\n"),
6598 cu_vector_offset
, i
);
6602 num_cus
= byte_get_little_endian (constant_pool
+ cu_vector_offset
, 4);
6604 if (constant_pool
+ cu_vector_offset
+ 4 + num_cus
* 4 >=
6605 section
->start
+ section
->size
)
6607 printf ("<invalid number of CUs: %d>\n", num_cus
);
6608 warn (_("Invalid number of CUs (%d) for symbol table slot %d\n"),
6615 for (j
= 0; j
< num_cus
; ++j
)
6618 gdb_index_symbol_kind kind
;
6620 cu
= byte_get_little_endian (constant_pool
+ cu_vector_offset
+ 4 + j
* 4, 4);
6621 is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu
);
6622 kind
= GDB_INDEX_SYMBOL_KIND_VALUE (cu
);
6623 cu
= GDB_INDEX_CU_VALUE (cu
);
6624 /* Convert to TU number if it's for a type unit. */
6625 if (cu
>= cu_list_elements
/ 2)
6626 printf ("%cT%lu", num_cus
> 1 ? '\t' : ' ',
6627 (unsigned long) (cu
- cu_list_elements
/ 2));
6629 printf ("%c%lu", num_cus
> 1 ? '\t' : ' ', (unsigned long) cu
);
6631 printf (" [%s, %s]",
6632 is_static
? _("static") : _("global"),
6633 get_gdb_index_symbol_kind_name (kind
));
6645 /* Pre-allocate enough space for the CU/TU sets needed. */
6648 prealloc_cu_tu_list (unsigned int nshndx
)
6650 if (shndx_pool
== NULL
)
6652 shndx_pool_size
= nshndx
;
6653 shndx_pool_used
= 0;
6654 shndx_pool
= (unsigned int *) xcmalloc (shndx_pool_size
,
6655 sizeof (unsigned int));
6659 shndx_pool_size
= shndx_pool_used
+ nshndx
;
6660 shndx_pool
= (unsigned int *) xcrealloc (shndx_pool
, shndx_pool_size
,
6661 sizeof (unsigned int));
6666 add_shndx_to_cu_tu_entry (unsigned int shndx
)
6668 if (shndx_pool_used
>= shndx_pool_size
)
6670 error (_("Internal error: out of space in the shndx pool.\n"));
6673 shndx_pool
[shndx_pool_used
++] = shndx
;
6677 end_cu_tu_entry (void)
6679 if (shndx_pool_used
>= shndx_pool_size
)
6681 error (_("Internal error: out of space in the shndx pool.\n"));
6684 shndx_pool
[shndx_pool_used
++] = 0;
6687 /* Return the short name of a DWARF section given by a DW_SECT enumerator. */
6690 get_DW_SECT_short_name (unsigned int dw_sect
)
6692 static char buf
[16];
6700 case DW_SECT_ABBREV
:
6706 case DW_SECT_STR_OFFSETS
:
6708 case DW_SECT_MACINFO
:
6716 snprintf (buf
, sizeof (buf
), "%d", dw_sect
);
6720 /* Process a CU or TU index. If DO_DISPLAY is true, print the contents.
6721 These sections are extensions for Fission.
6722 See http://gcc.gnu.org/wiki/DebugFissionDWP. */
6725 process_cu_tu_index (struct dwarf_section
*section
, int do_display
)
6727 unsigned char *phdr
= section
->start
;
6728 unsigned char *limit
= phdr
+ section
->size
;
6729 unsigned char *phash
;
6730 unsigned char *pindex
;
6731 unsigned char *ppool
;
6732 unsigned int version
;
6733 unsigned int ncols
= 0;
6735 unsigned int nslots
;
6738 dwarf_vma signature_high
;
6739 dwarf_vma signature_low
;
6742 /* PR 17512: file: 002-168123-0.004. */
6745 warn (_("Section %s is empty\n"), section
->name
);
6748 /* PR 17512: file: 002-376-0.004. */
6749 if (section
->size
< 24)
6751 warn (_("Section %s is too small to contain a CU/TU header"),
6756 SAFE_BYTE_GET (version
, phdr
, 4, limit
);
6758 SAFE_BYTE_GET (ncols
, phdr
+ 4, 4, limit
);
6759 SAFE_BYTE_GET (nused
, phdr
+ 8, 4, limit
);
6760 SAFE_BYTE_GET (nslots
, phdr
+ 12, 4, limit
);
6763 pindex
= phash
+ nslots
* 8;
6764 ppool
= pindex
+ nslots
* 4;
6768 printf (_("Contents of the %s section:\n\n"), section
->name
);
6769 printf (_(" Version: %d\n"), version
);
6771 printf (_(" Number of columns: %d\n"), ncols
);
6772 printf (_(" Number of used entries: %d\n"), nused
);
6773 printf (_(" Number of slots: %d\n\n"), nslots
);
6778 warn (_("Section %s too small for %d hash table entries\n"),
6779 section
->name
, nslots
);
6786 prealloc_cu_tu_list ((limit
- ppool
) / 4);
6787 for (i
= 0; i
< nslots
; i
++)
6789 unsigned char *shndx_list
;
6792 SAFE_BYTE_GET64 (phash
, &signature_high
, &signature_low
, limit
);
6793 if (signature_high
!= 0 || signature_low
!= 0)
6795 SAFE_BYTE_GET (j
, pindex
, 4, limit
);
6796 shndx_list
= ppool
+ j
* 4;
6798 printf (_(" [%3d] Signature: 0x%s Sections: "),
6799 i
, dwarf_vmatoa64 (signature_high
, signature_low
,
6800 buf
, sizeof (buf
)));
6803 if (shndx_list
>= limit
)
6805 warn (_("Section %s too small for shndx pool\n"),
6809 SAFE_BYTE_GET (shndx
, shndx_list
, 4, limit
);
6813 printf (" %d", shndx
);
6815 add_shndx_to_cu_tu_entry (shndx
);
6827 else if (version
== 2)
6830 unsigned int dw_sect
;
6831 unsigned char *ph
= phash
;
6832 unsigned char *pi
= pindex
;
6833 unsigned char *poffsets
= ppool
+ ncols
* 4;
6834 unsigned char *psizes
= poffsets
+ nused
* ncols
* 4;
6835 unsigned char *pend
= psizes
+ nused
* ncols
* 4;
6836 bfd_boolean is_tu_index
;
6837 struct cu_tu_set
*this_set
= NULL
;
6839 unsigned char *prow
;
6841 is_tu_index
= strcmp (section
->name
, ".debug_tu_index") == 0;
6845 warn (_("Section %s too small for offset and size tables\n"),
6852 printf (_(" Offset table\n"));
6853 printf (" slot %-16s ",
6854 is_tu_index
? _("signature") : _("dwo_id"));
6861 tu_sets
= xcmalloc (nused
, sizeof (struct cu_tu_set
));
6867 cu_sets
= xcmalloc (nused
, sizeof (struct cu_tu_set
));
6874 for (j
= 0; j
< ncols
; j
++)
6876 SAFE_BYTE_GET (dw_sect
, ppool
+ j
* 4, 4, limit
);
6877 printf (" %8s", get_DW_SECT_short_name (dw_sect
));
6882 for (i
= 0; i
< nslots
; i
++)
6884 SAFE_BYTE_GET64 (ph
, &signature_high
, &signature_low
, limit
);
6886 SAFE_BYTE_GET (row
, pi
, 4, limit
);
6889 /* PR 17531: file: a05f6ab3. */
6892 warn (_("Row index (%u) is larger than number of used entries (%u)\n"),
6898 memcpy (&this_set
[row
- 1].signature
, ph
, sizeof (uint64_t));
6900 prow
= poffsets
+ (row
- 1) * ncols
* 4;
6903 printf (_(" [%3d] 0x%s"),
6904 i
, dwarf_vmatoa64 (signature_high
, signature_low
,
6905 buf
, sizeof (buf
)));
6906 for (j
= 0; j
< ncols
; j
++)
6908 SAFE_BYTE_GET (val
, prow
+ j
* 4, 4, limit
);
6910 printf (" %8d", val
);
6913 SAFE_BYTE_GET (dw_sect
, ppool
+ j
* 4, 4, limit
);
6914 this_set
[row
- 1].section_offsets
[dw_sect
] = val
;
6930 printf (_(" Size table\n"));
6931 printf (" slot %-16s ",
6932 is_tu_index
? _("signature") : _("dwo_id"));
6935 for (j
= 0; j
< ncols
; j
++)
6937 SAFE_BYTE_GET (val
, ppool
+ j
* 4, 4, limit
);
6939 printf (" %8s", get_DW_SECT_short_name (val
));
6945 for (i
= 0; i
< nslots
; i
++)
6947 SAFE_BYTE_GET64 (ph
, &signature_high
, &signature_low
, limit
);
6949 SAFE_BYTE_GET (row
, pi
, 4, limit
);
6952 prow
= psizes
+ (row
- 1) * ncols
* 4;
6955 printf (_(" [%3d] 0x%s"),
6956 i
, dwarf_vmatoa64 (signature_high
, signature_low
,
6957 buf
, sizeof (buf
)));
6959 for (j
= 0; j
< ncols
; j
++)
6961 SAFE_BYTE_GET (val
, prow
+ j
* 4, 4, limit
);
6963 printf (" %8d", val
);
6966 SAFE_BYTE_GET (dw_sect
, ppool
+ j
* 4, 4, limit
);
6967 this_set
[row
- 1].section_sizes
[dw_sect
] = val
;
6979 else if (do_display
)
6980 printf (_(" Unsupported version (%d)\n"), version
);
6988 /* Load the CU and TU indexes if present. This will build a list of
6989 section sets that we can use to associate a .debug_info.dwo section
6990 with its associated .debug_abbrev.dwo section in a .dwp file. */
6993 load_cu_tu_indexes (void *file
)
6995 /* If we have already loaded (or tried to load) the CU and TU indexes
6996 then do not bother to repeat the task. */
6997 if (cu_tu_indexes_read
)
7000 if (load_debug_section (dwp_cu_index
, file
))
7001 process_cu_tu_index (&debug_displays
[dwp_cu_index
].section
, 0);
7003 if (load_debug_section (dwp_tu_index
, file
))
7004 process_cu_tu_index (&debug_displays
[dwp_tu_index
].section
, 0);
7006 cu_tu_indexes_read
= 1;
7009 /* Find the set of sections that includes section SHNDX. */
7012 find_cu_tu_set (void *file
, unsigned int shndx
)
7016 load_cu_tu_indexes (file
);
7018 /* Find SHNDX in the shndx pool. */
7019 for (i
= 0; i
< shndx_pool_used
; i
++)
7020 if (shndx_pool
[i
] == shndx
)
7023 if (i
>= shndx_pool_used
)
7026 /* Now backup to find the first entry in the set. */
7027 while (i
> 0 && shndx_pool
[i
- 1] != 0)
7030 return shndx_pool
+ i
;
7033 /* Display a .debug_cu_index or .debug_tu_index section. */
7036 display_cu_index (struct dwarf_section
*section
, void *file ATTRIBUTE_UNUSED
)
7038 return process_cu_tu_index (section
, 1);
7042 display_debug_not_supported (struct dwarf_section
*section
,
7043 void *file ATTRIBUTE_UNUSED
)
7045 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
7052 cmalloc (size_t nmemb
, size_t size
)
7054 /* Check for overflow. */
7055 if (nmemb
>= ~(size_t) 0 / size
)
7058 return malloc (nmemb
* size
);
7062 xcmalloc (size_t nmemb
, size_t size
)
7064 /* Check for overflow. */
7065 if (nmemb
>= ~(size_t) 0 / size
)
7068 return xmalloc (nmemb
* size
);
7072 xcrealloc (void *ptr
, size_t nmemb
, size_t size
)
7074 /* Check for overflow. */
7075 if (nmemb
>= ~(size_t) 0 / size
)
7078 return xrealloc (ptr
, nmemb
* size
);
7082 free_debug_memory (void)
7088 for (i
= 0; i
< max
; i
++)
7089 free_debug_section ((enum dwarf_section_display_enum
) i
);
7091 if (debug_information
!= NULL
)
7093 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
)
7095 for (i
= 0; i
< num_debug_info_entries
; i
++)
7097 if (!debug_information
[i
].max_loc_offsets
)
7099 free (debug_information
[i
].loc_offsets
);
7100 free (debug_information
[i
].have_frame_base
);
7102 if (!debug_information
[i
].max_range_lists
)
7103 free (debug_information
[i
].range_lists
);
7107 free (debug_information
);
7108 debug_information
= NULL
;
7109 num_debug_info_entries
= 0;
7114 dwarf_select_sections_by_names (const char *names
)
7118 const char * option
;
7122 debug_dump_long_opts
;
7124 static const debug_dump_long_opts opts_table
[] =
7126 /* Please keep this table alpha- sorted. */
7127 { "Ranges", & do_debug_ranges
, 1 },
7128 { "abbrev", & do_debug_abbrevs
, 1 },
7129 { "addr", & do_debug_addr
, 1 },
7130 { "aranges", & do_debug_aranges
, 1 },
7131 { "cu_index", & do_debug_cu_index
, 1 },
7132 { "decodedline", & do_debug_lines
, FLAG_DEBUG_LINES_DECODED
},
7133 { "frames", & do_debug_frames
, 1 },
7134 { "frames-interp", & do_debug_frames_interp
, 1 },
7135 /* The special .gdb_index section. */
7136 { "gdb_index", & do_gdb_index
, 1 },
7137 { "info", & do_debug_info
, 1 },
7138 { "line", & do_debug_lines
, FLAG_DEBUG_LINES_RAW
}, /* For backwards compatibility. */
7139 { "loc", & do_debug_loc
, 1 },
7140 { "macro", & do_debug_macinfo
, 1 },
7141 { "pubnames", & do_debug_pubnames
, 1 },
7142 { "pubtypes", & do_debug_pubtypes
, 1 },
7143 /* This entry is for compatability
7144 with earlier versions of readelf. */
7145 { "ranges", & do_debug_aranges
, 1 },
7146 { "rawline", & do_debug_lines
, FLAG_DEBUG_LINES_RAW
},
7147 { "str", & do_debug_str
, 1 },
7148 /* These trace_* sections are used by Itanium VMS. */
7149 { "trace_abbrev", & do_trace_abbrevs
, 1 },
7150 { "trace_aranges", & do_trace_aranges
, 1 },
7151 { "trace_info", & do_trace_info
, 1 },
7160 const debug_dump_long_opts
* entry
;
7162 for (entry
= opts_table
; entry
->option
; entry
++)
7164 size_t len
= strlen (entry
->option
);
7166 if (strncmp (p
, entry
->option
, len
) == 0
7167 && (p
[len
] == ',' || p
[len
] == '\0'))
7169 * entry
->variable
|= entry
->val
;
7171 /* The --debug-dump=frames-interp option also
7172 enables the --debug-dump=frames option. */
7173 if (do_debug_frames_interp
)
7174 do_debug_frames
= 1;
7181 if (entry
->option
== NULL
)
7183 warn (_("Unrecognized debug option '%s'\n"), p
);
7184 p
= strchr (p
, ',');
7195 dwarf_select_sections_by_letters (const char *letters
)
7197 unsigned int lindex
= 0;
7199 while (letters
[lindex
])
7200 switch (letters
[lindex
++])
7207 do_debug_abbrevs
= 1;
7211 do_debug_lines
|= FLAG_DEBUG_LINES_RAW
;
7215 do_debug_lines
|= FLAG_DEBUG_LINES_DECODED
;
7219 do_debug_pubnames
= 1;
7223 do_debug_pubtypes
= 1;
7227 do_debug_aranges
= 1;
7231 do_debug_ranges
= 1;
7235 do_debug_frames_interp
= 1;
7237 do_debug_frames
= 1;
7241 do_debug_macinfo
= 1;
7253 warn (_("Unrecognized debug option '%s'\n"), optarg
);
7259 dwarf_select_sections_all (void)
7262 do_debug_abbrevs
= 1;
7263 do_debug_lines
= FLAG_DEBUG_LINES_RAW
;
7264 do_debug_pubnames
= 1;
7265 do_debug_pubtypes
= 1;
7266 do_debug_aranges
= 1;
7267 do_debug_ranges
= 1;
7268 do_debug_frames
= 1;
7269 do_debug_macinfo
= 1;
7274 do_trace_abbrevs
= 1;
7275 do_trace_aranges
= 1;
7277 do_debug_cu_index
= 1;
7280 struct dwarf_section_display debug_displays
[] =
7282 { { ".debug_abbrev", ".zdebug_abbrev", NULL
, NULL
, 0, 0, 0, NULL
},
7283 display_debug_abbrev
, &do_debug_abbrevs
, 0 },
7284 { { ".debug_aranges", ".zdebug_aranges", NULL
, NULL
, 0, 0, 0, NULL
},
7285 display_debug_aranges
, &do_debug_aranges
, 1 },
7286 { { ".debug_frame", ".zdebug_frame", NULL
, NULL
, 0, 0, 0, NULL
},
7287 display_debug_frames
, &do_debug_frames
, 1 },
7288 { { ".debug_info", ".zdebug_info", NULL
, NULL
, 0, 0, abbrev
, NULL
},
7289 display_debug_info
, &do_debug_info
, 1 },
7290 { { ".debug_line", ".zdebug_line", NULL
, NULL
, 0, 0, 0, NULL
},
7291 display_debug_lines
, &do_debug_lines
, 1 },
7292 { { ".debug_pubnames", ".zdebug_pubnames", NULL
, NULL
, 0, 0, 0, NULL
},
7293 display_debug_pubnames
, &do_debug_pubnames
, 0 },
7294 { { ".debug_gnu_pubnames", ".zdebug_gnu_pubnames", NULL
, NULL
, 0, 0, 0, NULL
},
7295 display_debug_gnu_pubnames
, &do_debug_pubnames
, 0 },
7296 { { ".eh_frame", "", NULL
, NULL
, 0, 0, 0, NULL
},
7297 display_debug_frames
, &do_debug_frames
, 1 },
7298 { { ".debug_macinfo", ".zdebug_macinfo", NULL
, NULL
, 0, 0, 0, NULL
},
7299 display_debug_macinfo
, &do_debug_macinfo
, 0 },
7300 { { ".debug_macro", ".zdebug_macro", NULL
, NULL
, 0, 0, 0, NULL
},
7301 display_debug_macro
, &do_debug_macinfo
, 1 },
7302 { { ".debug_str", ".zdebug_str", NULL
, NULL
, 0, 0, 0, NULL
},
7303 display_debug_str
, &do_debug_str
, 0 },
7304 { { ".debug_loc", ".zdebug_loc", NULL
, NULL
, 0, 0, 0, NULL
},
7305 display_debug_loc
, &do_debug_loc
, 1 },
7306 { { ".debug_pubtypes", ".zdebug_pubtypes", NULL
, NULL
, 0, 0, 0, NULL
},
7307 display_debug_pubnames
, &do_debug_pubtypes
, 0 },
7308 { { ".debug_gnu_pubtypes", ".zdebug_gnu_pubtypes", NULL
, NULL
, 0, 0, 0, NULL
},
7309 display_debug_gnu_pubnames
, &do_debug_pubtypes
, 0 },
7310 { { ".debug_ranges", ".zdebug_ranges", NULL
, NULL
, 0, 0, 0, NULL
},
7311 display_debug_ranges
, &do_debug_ranges
, 1 },
7312 { { ".debug_static_func", ".zdebug_static_func", NULL
, NULL
, 0, 0, 0, NULL
},
7313 display_debug_not_supported
, NULL
, 0 },
7314 { { ".debug_static_vars", ".zdebug_static_vars", NULL
, NULL
, 0, 0, 0, NULL
},
7315 display_debug_not_supported
, NULL
, 0 },
7316 { { ".debug_types", ".zdebug_types", NULL
, NULL
, 0, 0, abbrev
, NULL
},
7317 display_debug_types
, &do_debug_info
, 1 },
7318 { { ".debug_weaknames", ".zdebug_weaknames", NULL
, NULL
, 0, 0, 0, NULL
},
7319 display_debug_not_supported
, NULL
, 0 },
7320 { { ".gdb_index", "", NULL
, NULL
, 0, 0, 0, NULL
},
7321 display_gdb_index
, &do_gdb_index
, 0 },
7322 { { ".trace_info", "", NULL
, NULL
, 0, 0, trace_abbrev
, NULL
},
7323 display_trace_info
, &do_trace_info
, 1 },
7324 { { ".trace_abbrev", "", NULL
, NULL
, 0, 0, 0, NULL
},
7325 display_debug_abbrev
, &do_trace_abbrevs
, 0 },
7326 { { ".trace_aranges", "", NULL
, NULL
, 0, 0, 0, NULL
},
7327 display_debug_aranges
, &do_trace_aranges
, 0 },
7328 { { ".debug_info.dwo", ".zdebug_info.dwo", NULL
, NULL
, 0, 0, abbrev_dwo
, NULL
},
7329 display_debug_info
, &do_debug_info
, 1 },
7330 { { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo", NULL
, NULL
, 0, 0, 0, NULL
},
7331 display_debug_abbrev
, &do_debug_abbrevs
, 0 },
7332 { { ".debug_types.dwo", ".zdebug_types.dwo", NULL
, NULL
, 0, 0, abbrev_dwo
, NULL
},
7333 display_debug_types
, &do_debug_info
, 1 },
7334 { { ".debug_line.dwo", ".zdebug_line.dwo", NULL
, NULL
, 0, 0, 0, NULL
},
7335 display_debug_lines
, &do_debug_lines
, 1 },
7336 { { ".debug_loc.dwo", ".zdebug_loc.dwo", NULL
, NULL
, 0, 0, 0, NULL
},
7337 display_debug_loc
, &do_debug_loc
, 1 },
7338 { { ".debug_macro.dwo", ".zdebug_macro.dwo", NULL
, NULL
, 0, 0, 0, NULL
},
7339 display_debug_macro
, &do_debug_macinfo
, 1 },
7340 { { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo", NULL
, NULL
, 0, 0, 0, NULL
},
7341 display_debug_macinfo
, &do_debug_macinfo
, 0 },
7342 { { ".debug_str.dwo", ".zdebug_str.dwo", NULL
, NULL
, 0, 0, 0, NULL
},
7343 display_debug_str
, &do_debug_str
, 1 },
7344 { { ".debug_str_offsets", ".zdebug_str_offsets", NULL
, NULL
, 0, 0, 0, NULL
},
7345 display_debug_str_offsets
, NULL
, 0 },
7346 { { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo", NULL
, NULL
, 0, 0, 0, NULL
},
7347 display_debug_str_offsets
, NULL
, 0 },
7348 { { ".debug_addr", ".zdebug_addr", NULL
, NULL
, 0, 0, 0, NULL
},
7349 display_debug_addr
, &do_debug_addr
, 1 },
7350 { { ".debug_cu_index", "", NULL
, NULL
, 0, 0, 0, NULL
},
7351 display_cu_index
, &do_debug_cu_index
, 0 },
7352 { { ".debug_tu_index", "", NULL
, NULL
, 0, 0, 0, NULL
},
7353 display_cu_index
, &do_debug_cu_index
, 0 },