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 maxlen
= (dwarf_vma
) (end
- data
);
866 length
= length
> maxlen
? maxlen
: length
;
869 printf ("%lx ", (unsigned long) byte_get (data
++, 1));
875 decode_location_expression (unsigned char * data
,
876 unsigned int pointer_size
,
877 unsigned int offset_size
,
881 struct dwarf_section
* section
)
884 unsigned int bytes_read
;
886 dwarf_signed_vma svalue
;
887 unsigned char *end
= data
+ length
;
888 int need_frame_base
= 0;
897 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
898 printf ("DW_OP_addr: %s", dwarf_vmatoa ("x", uvalue
));
901 printf ("DW_OP_deref");
904 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
905 printf ("DW_OP_const1u: %lu", (unsigned long) uvalue
);
908 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 1, end
);
909 printf ("DW_OP_const1s: %ld", (long) svalue
);
912 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
913 printf ("DW_OP_const2u: %lu", (unsigned long) uvalue
);
916 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
917 printf ("DW_OP_const2s: %ld", (long) svalue
);
920 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
921 printf ("DW_OP_const4u: %lu", (unsigned long) uvalue
);
924 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
925 printf ("DW_OP_const4s: %ld", (long) svalue
);
928 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
929 printf ("DW_OP_const8u: %lu ", (unsigned long) uvalue
);
930 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
931 printf ("%lu", (unsigned long) uvalue
);
934 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
935 printf ("DW_OP_const8s: %ld ", (long) svalue
);
936 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
937 printf ("%ld", (long) svalue
);
940 printf ("DW_OP_constu: %s",
941 dwarf_vmatoa ("u", read_uleb128 (data
, &bytes_read
, end
)));
945 printf ("DW_OP_consts: %s",
946 dwarf_vmatoa ("d", read_sleb128 (data
, &bytes_read
, end
)));
950 printf ("DW_OP_dup");
953 printf ("DW_OP_drop");
956 printf ("DW_OP_over");
959 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
960 printf ("DW_OP_pick: %ld", (unsigned long) uvalue
);
963 printf ("DW_OP_swap");
966 printf ("DW_OP_rot");
969 printf ("DW_OP_xderef");
972 printf ("DW_OP_abs");
975 printf ("DW_OP_and");
978 printf ("DW_OP_div");
981 printf ("DW_OP_minus");
984 printf ("DW_OP_mod");
987 printf ("DW_OP_mul");
990 printf ("DW_OP_neg");
993 printf ("DW_OP_not");
999 printf ("DW_OP_plus");
1001 case DW_OP_plus_uconst
:
1002 printf ("DW_OP_plus_uconst: %s",
1003 dwarf_vmatoa ("u", read_uleb128 (data
, &bytes_read
, end
)));
1007 printf ("DW_OP_shl");
1010 printf ("DW_OP_shr");
1013 printf ("DW_OP_shra");
1016 printf ("DW_OP_xor");
1019 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1020 printf ("DW_OP_bra: %ld", (long) svalue
);
1023 printf ("DW_OP_eq");
1026 printf ("DW_OP_ge");
1029 printf ("DW_OP_gt");
1032 printf ("DW_OP_le");
1035 printf ("DW_OP_lt");
1038 printf ("DW_OP_ne");
1041 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1042 printf ("DW_OP_skip: %ld", (long) svalue
);
1077 printf ("DW_OP_lit%d", op
- DW_OP_lit0
);
1112 printf ("DW_OP_reg%d (%s)", op
- DW_OP_reg0
,
1113 regname (op
- DW_OP_reg0
, 1));
1148 printf ("DW_OP_breg%d (%s): %s",
1150 regname (op
- DW_OP_breg0
, 1),
1151 dwarf_vmatoa ("d", read_sleb128 (data
, &bytes_read
, end
)));
1156 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1158 printf ("DW_OP_regx: %s (%s)",
1159 dwarf_vmatoa ("u", uvalue
), regname (uvalue
, 1));
1162 need_frame_base
= 1;
1163 printf ("DW_OP_fbreg: %s",
1164 dwarf_vmatoa ("d", read_sleb128 (data
, &bytes_read
, end
)));
1168 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1170 printf ("DW_OP_bregx: %s (%s) %s",
1171 dwarf_vmatoa ("u", uvalue
), regname (uvalue
, 1),
1172 dwarf_vmatoa ("d", read_sleb128 (data
, &bytes_read
, end
)));
1176 printf ("DW_OP_piece: %s",
1177 dwarf_vmatoa ("u", read_uleb128 (data
, &bytes_read
, end
)));
1180 case DW_OP_deref_size
:
1181 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1182 printf ("DW_OP_deref_size: %ld", (long) uvalue
);
1184 case DW_OP_xderef_size
:
1185 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1186 printf ("DW_OP_xderef_size: %ld", (long) uvalue
);
1189 printf ("DW_OP_nop");
1192 /* DWARF 3 extensions. */
1193 case DW_OP_push_object_address
:
1194 printf ("DW_OP_push_object_address");
1197 /* XXX: Strictly speaking for 64-bit DWARF3 files
1198 this ought to be an 8-byte wide computation. */
1199 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1200 printf ("DW_OP_call2: <0x%s>",
1201 dwarf_vmatoa ("x", svalue
+ cu_offset
));
1204 /* XXX: Strictly speaking for 64-bit DWARF3 files
1205 this ought to be an 8-byte wide computation. */
1206 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
1207 printf ("DW_OP_call4: <0x%s>",
1208 dwarf_vmatoa ("x", svalue
+ cu_offset
));
1210 case DW_OP_call_ref
:
1211 /* XXX: Strictly speaking for 64-bit DWARF3 files
1212 this ought to be an 8-byte wide computation. */
1213 if (dwarf_version
== -1)
1215 printf (_("(DW_OP_call_ref in frame info)"));
1216 /* No way to tell where the next op is, so just bail. */
1217 return need_frame_base
;
1219 if (dwarf_version
== 2)
1221 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1225 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1227 printf ("DW_OP_call_ref: <0x%s>", dwarf_vmatoa ("x", uvalue
));
1229 case DW_OP_form_tls_address
:
1230 printf ("DW_OP_form_tls_address");
1232 case DW_OP_call_frame_cfa
:
1233 printf ("DW_OP_call_frame_cfa");
1235 case DW_OP_bit_piece
:
1236 printf ("DW_OP_bit_piece: ");
1237 printf (_("size: %s "),
1238 dwarf_vmatoa ("u", read_uleb128 (data
, &bytes_read
, end
)));
1240 printf (_("offset: %s "),
1241 dwarf_vmatoa ("u", read_uleb128 (data
, &bytes_read
, end
)));
1245 /* DWARF 4 extensions. */
1246 case DW_OP_stack_value
:
1247 printf ("DW_OP_stack_value");
1250 case DW_OP_implicit_value
:
1251 printf ("DW_OP_implicit_value");
1252 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1254 data
= display_block (data
, uvalue
, end
);
1257 /* GNU extensions. */
1258 case DW_OP_GNU_push_tls_address
:
1259 printf (_("DW_OP_GNU_push_tls_address or DW_OP_HP_unknown"));
1261 case DW_OP_GNU_uninit
:
1262 printf ("DW_OP_GNU_uninit");
1263 /* FIXME: Is there data associated with this OP ? */
1265 case DW_OP_GNU_encoded_addr
:
1272 addr
= get_encoded_value (&data
, encoding
, section
, end
);
1274 printf ("DW_OP_GNU_encoded_addr: fmt:%02x addr:", encoding
);
1275 print_dwarf_vma (addr
, pointer_size
);
1278 case DW_OP_GNU_implicit_pointer
:
1279 /* XXX: Strictly speaking for 64-bit DWARF3 files
1280 this ought to be an 8-byte wide computation. */
1281 if (dwarf_version
== -1)
1283 printf (_("(DW_OP_GNU_implicit_pointer in frame info)"));
1284 /* No way to tell where the next op is, so just bail. */
1285 return need_frame_base
;
1287 if (dwarf_version
== 2)
1289 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1293 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1295 printf ("DW_OP_GNU_implicit_pointer: <0x%s> %s",
1296 dwarf_vmatoa ("x", uvalue
),
1297 dwarf_vmatoa ("d", read_sleb128 (data
,
1298 &bytes_read
, end
)));
1301 case DW_OP_GNU_entry_value
:
1302 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1304 printf ("DW_OP_GNU_entry_value: (");
1305 if (decode_location_expression (data
, pointer_size
, offset_size
,
1306 dwarf_version
, uvalue
,
1307 cu_offset
, section
))
1308 need_frame_base
= 1;
1314 case DW_OP_GNU_const_type
:
1315 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1317 printf ("DW_OP_GNU_const_type: <0x%s> ",
1318 dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1319 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1320 data
= display_block (data
, uvalue
, end
);
1322 case DW_OP_GNU_regval_type
:
1323 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1325 printf ("DW_OP_GNU_regval_type: %s (%s)",
1326 dwarf_vmatoa ("u", uvalue
), regname (uvalue
, 1));
1327 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1329 printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1331 case DW_OP_GNU_deref_type
:
1332 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1333 printf ("DW_OP_GNU_deref_type: %ld", (long) uvalue
);
1334 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1336 printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1338 case DW_OP_GNU_convert
:
1339 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1341 printf ("DW_OP_GNU_convert <0x%s>",
1342 dwarf_vmatoa ("x", uvalue
? cu_offset
+ uvalue
: 0));
1344 case DW_OP_GNU_reinterpret
:
1345 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1347 printf ("DW_OP_GNU_reinterpret <0x%s>",
1348 dwarf_vmatoa ("x", uvalue
? cu_offset
+ uvalue
: 0));
1350 case DW_OP_GNU_parameter_ref
:
1351 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1352 printf ("DW_OP_GNU_parameter_ref: <0x%s>",
1353 dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1355 case DW_OP_GNU_addr_index
:
1356 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1358 printf ("DW_OP_GNU_addr_index <0x%s>", dwarf_vmatoa ("x", uvalue
));
1360 case DW_OP_GNU_const_index
:
1361 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1363 printf ("DW_OP_GNU_const_index <0x%s>", dwarf_vmatoa ("x", uvalue
));
1366 /* HP extensions. */
1367 case DW_OP_HP_is_value
:
1368 printf ("DW_OP_HP_is_value");
1369 /* FIXME: Is there data associated with this OP ? */
1371 case DW_OP_HP_fltconst4
:
1372 printf ("DW_OP_HP_fltconst4");
1373 /* FIXME: Is there data associated with this OP ? */
1375 case DW_OP_HP_fltconst8
:
1376 printf ("DW_OP_HP_fltconst8");
1377 /* FIXME: Is there data associated with this OP ? */
1379 case DW_OP_HP_mod_range
:
1380 printf ("DW_OP_HP_mod_range");
1381 /* FIXME: Is there data associated with this OP ? */
1383 case DW_OP_HP_unmod_range
:
1384 printf ("DW_OP_HP_unmod_range");
1385 /* FIXME: Is there data associated with this OP ? */
1388 printf ("DW_OP_HP_tls");
1389 /* FIXME: Is there data associated with this OP ? */
1392 /* PGI (STMicroelectronics) extensions. */
1393 case DW_OP_PGI_omp_thread_num
:
1394 /* Pushes the thread number for the current thread as it would be
1395 returned by the standard OpenMP library function:
1396 omp_get_thread_num(). The "current thread" is the thread for
1397 which the expression is being evaluated. */
1398 printf ("DW_OP_PGI_omp_thread_num");
1402 if (op
>= DW_OP_lo_user
1403 && op
<= DW_OP_hi_user
)
1404 printf (_("(User defined location op)"));
1406 printf (_("(Unknown location op)"));
1407 /* No way to tell where the next op is, so just bail. */
1408 return need_frame_base
;
1411 /* Separate the ops. */
1416 return need_frame_base
;
1419 /* Find the CU or TU set corresponding to the given CU_OFFSET.
1420 This is used for DWARF package files. */
1422 static struct cu_tu_set
*
1423 find_cu_tu_set_v2 (dwarf_vma cu_offset
, int do_types
)
1425 struct cu_tu_set
*p
;
1427 unsigned int dw_sect
;
1433 dw_sect
= DW_SECT_TYPES
;
1439 dw_sect
= DW_SECT_INFO
;
1443 if (p
->section_offsets
[dw_sect
] == cu_offset
)
1451 /* Add INC to HIGH_BITS:LOW_BITS. */
1453 add64 (dwarf_vma
* high_bits
, dwarf_vma
* low_bits
, dwarf_vma inc
)
1455 dwarf_vma tmp
= * low_bits
;
1459 /* FIXME: There is probably a better way of handling this:
1461 We need to cope with dwarf_vma being a 32-bit or 64-bit
1462 type. Plus regardless of its size LOW_BITS is meant to
1463 only hold 32-bits, so if there is overflow or wrap around
1464 we must propagate into HIGH_BITS. */
1465 if (tmp
< * low_bits
)
1469 else if (sizeof (tmp
) > 8
1479 static unsigned char *
1480 read_and_display_attr_value (unsigned long attribute
,
1482 unsigned char * data
,
1483 unsigned char * end
,
1484 dwarf_vma cu_offset
,
1485 dwarf_vma pointer_size
,
1486 dwarf_vma offset_size
,
1488 debug_info
* debug_info_p
,
1490 struct dwarf_section
* section
,
1491 struct cu_tu_set
* this_set
)
1493 dwarf_vma uvalue
= 0;
1494 unsigned char *block_start
= NULL
;
1495 unsigned char * orig_data
= data
;
1496 unsigned int bytes_read
;
1498 if (data
> end
|| (data
== end
&& form
!= DW_FORM_flag_present
))
1500 warn (_("Corrupt attribute\n"));
1509 case DW_FORM_ref_addr
:
1510 if (dwarf_version
== 2)
1511 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1512 else if (dwarf_version
== 3 || dwarf_version
== 4)
1513 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1515 error (_("Internal error: DWARF version is not 2, 3 or 4.\n"));
1520 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1524 case DW_FORM_sec_offset
:
1525 case DW_FORM_GNU_ref_alt
:
1526 case DW_FORM_GNU_strp_alt
:
1527 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1530 case DW_FORM_flag_present
:
1537 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1542 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
1547 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1551 uvalue
= read_sleb128 (data
, & bytes_read
, end
);
1555 case DW_FORM_GNU_str_index
:
1556 uvalue
= read_uleb128 (data
, & bytes_read
, end
);
1560 case DW_FORM_ref_udata
:
1562 uvalue
= read_uleb128 (data
, & bytes_read
, end
);
1566 case DW_FORM_indirect
:
1567 form
= read_uleb128 (data
, & bytes_read
, end
);
1570 printf (" %s", get_FORM_name (form
));
1571 return read_and_display_attr_value (attribute
, form
, data
, end
,
1572 cu_offset
, pointer_size
,
1573 offset_size
, dwarf_version
,
1574 debug_info_p
, do_loc
,
1576 case DW_FORM_GNU_addr_index
:
1577 uvalue
= read_uleb128 (data
, & bytes_read
, end
);
1584 case DW_FORM_ref_addr
:
1586 printf (" <0x%s>", dwarf_vmatoa ("x",uvalue
));
1589 case DW_FORM_GNU_ref_alt
:
1591 printf (" <alt 0x%s>", dwarf_vmatoa ("x",uvalue
));
1597 case DW_FORM_ref_udata
:
1599 printf (" <0x%s>", dwarf_vmatoa ("x", uvalue
+ cu_offset
));
1604 case DW_FORM_sec_offset
:
1606 printf (" 0x%s", dwarf_vmatoa ("x", uvalue
));
1609 case DW_FORM_flag_present
:
1616 printf (" %s", dwarf_vmatoa ("d", uvalue
));
1623 dwarf_vma high_bits
;
1627 SAFE_BYTE_GET64 (data
, &high_bits
, &uvalue
, end
);
1629 if (form
== DW_FORM_ref8
)
1630 add64 (& high_bits
, & utmp
, cu_offset
);
1632 dwarf_vmatoa64 (high_bits
, utmp
, buf
, sizeof (buf
)));
1635 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
1636 && num_debug_info_entries
== 0)
1638 if (sizeof (uvalue
) == 8)
1639 SAFE_BYTE_GET (uvalue
, data
, 8, end
);
1641 error (_("DW_FORM_data8 is unsupported when sizeof (dwarf_vma) != 8\n"));
1647 case DW_FORM_string
:
1649 printf (" %.*s", (int) (end
- data
), data
);
1650 data
+= strnlen ((char *) data
, end
- data
) + 1;
1654 case DW_FORM_exprloc
:
1655 uvalue
= read_uleb128 (data
, & bytes_read
, end
);
1656 block_start
= data
+ bytes_read
;
1657 /* PR 17512: file: 008-103549-0.001:0.1. */
1658 if (block_start
+ uvalue
> end
)
1660 warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue
);
1661 uvalue
= end
- block_start
;
1664 data
= block_start
+ uvalue
;
1666 data
= display_block (block_start
, uvalue
, end
);
1669 case DW_FORM_block1
:
1670 SAFE_BYTE_GET (uvalue
, data
, 1, end
);
1671 block_start
= data
+ 1;
1672 if (block_start
+ uvalue
> end
)
1674 warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue
);
1675 uvalue
= end
- block_start
;
1678 data
= block_start
+ uvalue
;
1680 data
= display_block (block_start
, uvalue
, end
);
1683 case DW_FORM_block2
:
1684 SAFE_BYTE_GET (uvalue
, data
, 2, end
);
1685 block_start
= data
+ 2;
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_block4
:
1698 SAFE_BYTE_GET (uvalue
, data
, 4, end
);
1699 block_start
= data
+ 4;
1700 if (block_start
+ uvalue
> end
)
1702 warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue
);
1703 uvalue
= end
- block_start
;
1706 data
= block_start
+ uvalue
;
1708 data
= display_block (block_start
, uvalue
, end
);
1713 printf (_(" (indirect string, offset: 0x%s): %s"),
1714 dwarf_vmatoa ("x", uvalue
),
1715 fetch_indirect_string (uvalue
));
1718 case DW_FORM_GNU_str_index
:
1721 const char *suffix
= strrchr (section
->name
, '.');
1722 int dwo
= (suffix
&& strcmp (suffix
, ".dwo") == 0) ? 1 : 0;
1724 printf (_(" (indexed string: 0x%s): %s"),
1725 dwarf_vmatoa ("x", uvalue
),
1726 fetch_indexed_string (uvalue
, this_set
, offset_size
, dwo
));
1730 case DW_FORM_GNU_strp_alt
:
1732 printf (_(" (alt indirect string, offset: 0x%s)"),
1733 dwarf_vmatoa ("x", uvalue
));
1736 case DW_FORM_indirect
:
1737 /* Handled above. */
1740 case DW_FORM_ref_sig8
:
1743 dwarf_vma high_bits
;
1746 SAFE_BYTE_GET64 (data
, &high_bits
, &uvalue
, end
);
1747 printf (" signature: 0x%s",
1748 dwarf_vmatoa64 (high_bits
, uvalue
, buf
, sizeof (buf
)));
1753 case DW_FORM_GNU_addr_index
:
1755 printf (_(" (addr_index: 0x%s): %s"),
1756 dwarf_vmatoa ("x", uvalue
),
1757 fetch_indexed_value (uvalue
* pointer_size
, pointer_size
));
1761 warn (_("Unrecognized form: %lu\n"), form
);
1765 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
1766 && num_debug_info_entries
== 0
1767 && debug_info_p
!= NULL
)
1771 case DW_AT_frame_base
:
1772 have_frame_base
= 1;
1773 case DW_AT_location
:
1774 case DW_AT_string_length
:
1775 case DW_AT_return_addr
:
1776 case DW_AT_data_member_location
:
1777 case DW_AT_vtable_elem_location
:
1779 case DW_AT_static_link
:
1780 case DW_AT_use_location
:
1781 case DW_AT_GNU_call_site_value
:
1782 case DW_AT_GNU_call_site_data_value
:
1783 case DW_AT_GNU_call_site_target
:
1784 case DW_AT_GNU_call_site_target_clobbered
:
1785 if ((dwarf_version
< 4
1786 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
1787 || form
== DW_FORM_sec_offset
)
1789 /* Process location list. */
1790 unsigned int lmax
= debug_info_p
->max_loc_offsets
;
1791 unsigned int num
= debug_info_p
->num_loc_offsets
;
1793 if (lmax
== 0 || num
>= lmax
)
1796 debug_info_p
->loc_offsets
= (dwarf_vma
*)
1797 xcrealloc (debug_info_p
->loc_offsets
,
1798 lmax
, sizeof (*debug_info_p
->loc_offsets
));
1799 debug_info_p
->have_frame_base
= (int *)
1800 xcrealloc (debug_info_p
->have_frame_base
,
1801 lmax
, sizeof (*debug_info_p
->have_frame_base
));
1802 debug_info_p
->max_loc_offsets
= lmax
;
1804 if (this_set
!= NULL
)
1805 uvalue
+= this_set
->section_offsets
[DW_SECT_LOC
];
1806 debug_info_p
->loc_offsets
[num
] = uvalue
;
1807 debug_info_p
->have_frame_base
[num
] = have_frame_base
;
1808 debug_info_p
->num_loc_offsets
++;
1813 if (need_base_address
)
1814 debug_info_p
->base_address
= uvalue
;
1817 case DW_AT_GNU_addr_base
:
1818 debug_info_p
->addr_base
= uvalue
;
1821 case DW_AT_GNU_ranges_base
:
1822 debug_info_p
->ranges_base
= uvalue
;
1826 if ((dwarf_version
< 4
1827 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
1828 || form
== DW_FORM_sec_offset
)
1830 /* Process range list. */
1831 unsigned int lmax
= debug_info_p
->max_range_lists
;
1832 unsigned int num
= debug_info_p
->num_range_lists
;
1834 if (lmax
== 0 || num
>= lmax
)
1837 debug_info_p
->range_lists
= (dwarf_vma
*)
1838 xcrealloc (debug_info_p
->range_lists
,
1839 lmax
, sizeof (*debug_info_p
->range_lists
));
1840 debug_info_p
->max_range_lists
= lmax
;
1842 debug_info_p
->range_lists
[num
] = uvalue
;
1843 debug_info_p
->num_range_lists
++;
1852 if (do_loc
|| attribute
== 0)
1855 /* For some attributes we can display further information. */
1862 case DW_INL_not_inlined
:
1863 printf (_("(not inlined)"));
1865 case DW_INL_inlined
:
1866 printf (_("(inlined)"));
1868 case DW_INL_declared_not_inlined
:
1869 printf (_("(declared as inline but ignored)"));
1871 case DW_INL_declared_inlined
:
1872 printf (_("(declared as inline and inlined)"));
1875 printf (_(" (Unknown inline attribute value: %s)"),
1876 dwarf_vmatoa ("x", uvalue
));
1881 case DW_AT_language
:
1885 /* Ordered by the numeric value of these constants. */
1886 case DW_LANG_C89
: printf ("(ANSI C)"); break;
1887 case DW_LANG_C
: printf ("(non-ANSI C)"); break;
1888 case DW_LANG_Ada83
: printf ("(Ada)"); break;
1889 case DW_LANG_C_plus_plus
: printf ("(C++)"); break;
1890 case DW_LANG_Cobol74
: printf ("(Cobol 74)"); break;
1891 case DW_LANG_Cobol85
: printf ("(Cobol 85)"); break;
1892 case DW_LANG_Fortran77
: printf ("(FORTRAN 77)"); break;
1893 case DW_LANG_Fortran90
: printf ("(Fortran 90)"); break;
1894 case DW_LANG_Pascal83
: printf ("(ANSI Pascal)"); break;
1895 case DW_LANG_Modula2
: printf ("(Modula 2)"); break;
1896 /* DWARF 2.1 values. */
1897 case DW_LANG_Java
: printf ("(Java)"); break;
1898 case DW_LANG_C99
: printf ("(ANSI C99)"); break;
1899 case DW_LANG_Ada95
: printf ("(ADA 95)"); break;
1900 case DW_LANG_Fortran95
: printf ("(Fortran 95)"); break;
1901 /* DWARF 3 values. */
1902 case DW_LANG_PLI
: printf ("(PLI)"); break;
1903 case DW_LANG_ObjC
: printf ("(Objective C)"); break;
1904 case DW_LANG_ObjC_plus_plus
: printf ("(Objective C++)"); break;
1905 case DW_LANG_UPC
: printf ("(Unified Parallel C)"); break;
1906 case DW_LANG_D
: printf ("(D)"); break;
1907 /* DWARF 4 values. */
1908 case DW_LANG_Python
: printf ("(Python)"); break;
1909 /* DWARF 5 values. */
1910 case DW_LANG_Go
: printf ("(Go)"); break;
1911 /* MIPS extension. */
1912 case DW_LANG_Mips_Assembler
: printf ("(MIPS assembler)"); break;
1913 /* UPC extension. */
1914 case DW_LANG_Upc
: printf ("(Unified Parallel C)"); break;
1916 if (uvalue
>= DW_LANG_lo_user
&& uvalue
<= DW_LANG_hi_user
)
1917 printf (_("(implementation defined: %s)"),
1918 dwarf_vmatoa ("x", uvalue
));
1920 printf (_("(Unknown: %s)"), dwarf_vmatoa ("x", uvalue
));
1925 case DW_AT_encoding
:
1929 case DW_ATE_void
: printf ("(void)"); break;
1930 case DW_ATE_address
: printf ("(machine address)"); break;
1931 case DW_ATE_boolean
: printf ("(boolean)"); break;
1932 case DW_ATE_complex_float
: printf ("(complex float)"); break;
1933 case DW_ATE_float
: printf ("(float)"); break;
1934 case DW_ATE_signed
: printf ("(signed)"); break;
1935 case DW_ATE_signed_char
: printf ("(signed char)"); break;
1936 case DW_ATE_unsigned
: printf ("(unsigned)"); break;
1937 case DW_ATE_unsigned_char
: printf ("(unsigned char)"); break;
1938 /* DWARF 2.1 values: */
1939 case DW_ATE_imaginary_float
: printf ("(imaginary float)"); break;
1940 case DW_ATE_decimal_float
: printf ("(decimal float)"); break;
1941 /* DWARF 3 values: */
1942 case DW_ATE_packed_decimal
: printf ("(packed_decimal)"); break;
1943 case DW_ATE_numeric_string
: printf ("(numeric_string)"); break;
1944 case DW_ATE_edited
: printf ("(edited)"); break;
1945 case DW_ATE_signed_fixed
: printf ("(signed_fixed)"); break;
1946 case DW_ATE_unsigned_fixed
: printf ("(unsigned_fixed)"); break;
1947 /* HP extensions: */
1948 case DW_ATE_HP_float80
: printf ("(HP_float80)"); break;
1949 case DW_ATE_HP_complex_float80
: printf ("(HP_complex_float80)"); break;
1950 case DW_ATE_HP_float128
: printf ("(HP_float128)"); break;
1951 case DW_ATE_HP_complex_float128
:printf ("(HP_complex_float128)"); break;
1952 case DW_ATE_HP_floathpintel
: printf ("(HP_floathpintel)"); break;
1953 case DW_ATE_HP_imaginary_float80
: printf ("(HP_imaginary_float80)"); break;
1954 case DW_ATE_HP_imaginary_float128
: printf ("(HP_imaginary_float128)"); break;
1957 if (uvalue
>= DW_ATE_lo_user
1958 && uvalue
<= DW_ATE_hi_user
)
1959 printf (_("(user defined type)"));
1961 printf (_("(unknown type)"));
1966 case DW_AT_accessibility
:
1970 case DW_ACCESS_public
: printf ("(public)"); break;
1971 case DW_ACCESS_protected
: printf ("(protected)"); break;
1972 case DW_ACCESS_private
: printf ("(private)"); break;
1974 printf (_("(unknown accessibility)"));
1979 case DW_AT_visibility
:
1983 case DW_VIS_local
: printf ("(local)"); break;
1984 case DW_VIS_exported
: printf ("(exported)"); break;
1985 case DW_VIS_qualified
: printf ("(qualified)"); break;
1986 default: printf (_("(unknown visibility)")); break;
1990 case DW_AT_virtuality
:
1994 case DW_VIRTUALITY_none
: printf ("(none)"); break;
1995 case DW_VIRTUALITY_virtual
: printf ("(virtual)"); break;
1996 case DW_VIRTUALITY_pure_virtual
:printf ("(pure_virtual)"); break;
1997 default: printf (_("(unknown virtuality)")); break;
2001 case DW_AT_identifier_case
:
2005 case DW_ID_case_sensitive
: printf ("(case_sensitive)"); break;
2006 case DW_ID_up_case
: printf ("(up_case)"); break;
2007 case DW_ID_down_case
: printf ("(down_case)"); break;
2008 case DW_ID_case_insensitive
: printf ("(case_insensitive)"); break;
2009 default: printf (_("(unknown case)")); break;
2013 case DW_AT_calling_convention
:
2017 case DW_CC_normal
: printf ("(normal)"); break;
2018 case DW_CC_program
: printf ("(program)"); break;
2019 case DW_CC_nocall
: printf ("(nocall)"); break;
2021 if (uvalue
>= DW_CC_lo_user
2022 && uvalue
<= DW_CC_hi_user
)
2023 printf (_("(user defined)"));
2025 printf (_("(unknown convention)"));
2029 case DW_AT_ordering
:
2033 case -1: printf (_("(undefined)")); break;
2034 case 0: printf ("(row major)"); break;
2035 case 1: printf ("(column major)"); break;
2039 case DW_AT_frame_base
:
2040 have_frame_base
= 1;
2041 case DW_AT_location
:
2042 case DW_AT_string_length
:
2043 case DW_AT_return_addr
:
2044 case DW_AT_data_member_location
:
2045 case DW_AT_vtable_elem_location
:
2047 case DW_AT_static_link
:
2048 case DW_AT_use_location
:
2049 case DW_AT_GNU_call_site_value
:
2050 case DW_AT_GNU_call_site_data_value
:
2051 case DW_AT_GNU_call_site_target
:
2052 case DW_AT_GNU_call_site_target_clobbered
:
2053 if ((dwarf_version
< 4
2054 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
2055 || form
== DW_FORM_sec_offset
)
2056 printf (_(" (location list)"));
2058 case DW_AT_allocated
:
2059 case DW_AT_associated
:
2060 case DW_AT_data_location
:
2062 case DW_AT_upper_bound
:
2063 case DW_AT_lower_bound
:
2066 int need_frame_base
;
2069 need_frame_base
= decode_location_expression (block_start
,
2074 cu_offset
, section
);
2076 if (need_frame_base
&& !have_frame_base
)
2077 printf (_(" [without DW_AT_frame_base]"));
2083 if (form
== DW_FORM_ref_sig8
2084 || form
== DW_FORM_GNU_ref_alt
)
2087 if (form
== DW_FORM_ref1
2088 || form
== DW_FORM_ref2
2089 || form
== DW_FORM_ref4
2090 || form
== DW_FORM_ref_udata
)
2091 uvalue
+= cu_offset
;
2093 if (uvalue
>= section
->size
)
2094 warn (_("Offset %s used as value for DW_AT_import attribute of DIE at offset %lx is too big.\n"),
2095 dwarf_vmatoa ("x", uvalue
),
2096 (unsigned long) (orig_data
- section
->start
));
2099 unsigned long abbrev_number
;
2100 abbrev_entry
* entry
;
2102 abbrev_number
= read_uleb128 (section
->start
+ uvalue
, NULL
, end
);
2104 printf (_("\t[Abbrev Number: %ld"), abbrev_number
);
2105 /* Don't look up abbrev for DW_FORM_ref_addr, as it very often will
2106 use different abbrev table, and we don't track .debug_info chunks
2108 if (form
!= DW_FORM_ref_addr
)
2110 for (entry
= first_abbrev
; entry
!= NULL
; entry
= entry
->next
)
2111 if (entry
->entry
== abbrev_number
)
2114 printf (" (%s)", get_TAG_name (entry
->tag
));
2129 get_AT_name (unsigned long attribute
)
2134 return "DW_AT value: 0";
2136 /* One value is shared by the MIPS and HP extensions: */
2137 if (attribute
== DW_AT_MIPS_fde
)
2138 return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable";
2140 name
= get_DW_AT_name (attribute
);
2144 static char buffer
[100];
2146 snprintf (buffer
, sizeof (buffer
), _("Unknown AT value: %lx"),
2154 static unsigned char *
2155 read_and_display_attr (unsigned long attribute
,
2157 unsigned char * data
,
2158 unsigned char * end
,
2159 dwarf_vma cu_offset
,
2160 dwarf_vma pointer_size
,
2161 dwarf_vma offset_size
,
2163 debug_info
* debug_info_p
,
2165 struct dwarf_section
* section
,
2166 struct cu_tu_set
* this_set
)
2169 printf (" %-18s:", get_AT_name (attribute
));
2170 data
= read_and_display_attr_value (attribute
, form
, data
, end
,
2171 cu_offset
, pointer_size
, offset_size
,
2172 dwarf_version
, debug_info_p
,
2173 do_loc
, section
, this_set
);
2179 /* Process the contents of a .debug_info section. If do_loc is non-zero
2180 then we are scanning for location lists and we do not want to display
2181 anything to the user. If do_types is non-zero, we are processing
2182 a .debug_types section instead of a .debug_info section. */
2185 process_debug_info (struct dwarf_section
*section
,
2187 enum dwarf_section_display_enum abbrev_sec
,
2191 unsigned char *start
= section
->start
;
2192 unsigned char *end
= start
+ section
->size
;
2193 unsigned char *section_begin
;
2195 unsigned int num_units
= 0;
2197 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
2198 && num_debug_info_entries
== 0
2203 /* First scan the section to get the number of comp units. */
2204 for (section_begin
= start
, num_units
= 0; section_begin
< end
;
2207 /* Read the first 4 bytes. For a 32-bit DWARF section, this
2208 will be the length. For a 64-bit DWARF section, it'll be
2209 the escape code 0xffffffff followed by an 8 byte length. */
2210 SAFE_BYTE_GET (length
, section_begin
, 4, end
);
2212 if (length
== 0xffffffff)
2214 SAFE_BYTE_GET (length
, section_begin
+ 4, 8, end
);
2215 section_begin
+= length
+ 12;
2217 else if (length
>= 0xfffffff0 && length
< 0xffffffff)
2219 warn (_("Reserved length value (0x%s) found in section %s\n"),
2220 dwarf_vmatoa ("x", length
), section
->name
);
2224 section_begin
+= length
+ 4;
2226 /* Negative values are illegal, they may even cause infinite
2227 looping. This can happen if we can't accurately apply
2228 relocations to an object file. */
2229 if ((signed long) length
<= 0)
2231 warn (_("Corrupt unit length (0x%s) found in section %s\n"),
2232 dwarf_vmatoa ("x", length
), section
->name
);
2239 error (_("No comp units in %s section ?\n"), section
->name
);
2243 /* Then allocate an array to hold the information. */
2244 debug_information
= (debug_info
*) cmalloc (num_units
,
2245 sizeof (* debug_information
));
2246 if (debug_information
== NULL
)
2248 error (_("Not enough memory for a debug info array of %u entries\n"),
2256 if (dwarf_start_die
== 0)
2257 printf (_("Contents of the %s section:\n\n"), section
->name
);
2259 load_debug_section (str
, file
);
2260 load_debug_section (str_dwo
, file
);
2261 load_debug_section (str_index
, file
);
2262 load_debug_section (str_index_dwo
, file
);
2263 load_debug_section (debug_addr
, file
);
2266 load_debug_section (abbrev_sec
, file
);
2267 if (debug_displays
[abbrev_sec
].section
.start
== NULL
)
2269 warn (_("Unable to locate %s section!\n"),
2270 debug_displays
[abbrev_sec
].section
.name
);
2274 for (section_begin
= start
, unit
= 0; start
< end
; unit
++)
2276 DWARF2_Internal_CompUnit compunit
;
2277 unsigned char *hdrptr
;
2278 unsigned char *tags
;
2279 int level
, last_level
, saved_level
;
2280 dwarf_vma cu_offset
;
2281 unsigned int offset_size
;
2282 int initial_length_size
;
2283 dwarf_vma signature_high
= 0;
2284 dwarf_vma signature_low
= 0;
2285 dwarf_vma type_offset
= 0;
2286 struct cu_tu_set
*this_set
;
2287 dwarf_vma abbrev_base
;
2292 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 4, end
);
2294 if (compunit
.cu_length
== 0xffffffff)
2296 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 8, end
);
2298 initial_length_size
= 12;
2303 initial_length_size
= 4;
2306 SAFE_BYTE_GET_AND_INC (compunit
.cu_version
, hdrptr
, 2, end
);
2308 cu_offset
= start
- section_begin
;
2310 this_set
= find_cu_tu_set_v2 (cu_offset
, do_types
);
2312 SAFE_BYTE_GET_AND_INC (compunit
.cu_abbrev_offset
, hdrptr
, offset_size
, end
);
2314 if (this_set
== NULL
)
2317 abbrev_size
= debug_displays
[abbrev_sec
].section
.size
;
2321 abbrev_base
= this_set
->section_offsets
[DW_SECT_ABBREV
];
2322 abbrev_size
= this_set
->section_sizes
[DW_SECT_ABBREV
];
2325 SAFE_BYTE_GET_AND_INC (compunit
.cu_pointer_size
, hdrptr
, 1, end
);
2326 /* PR 17512: file: 001-108546-0.001:0.1. */
2327 if (compunit
.cu_pointer_size
< 2 || compunit
.cu_pointer_size
> 8)
2329 warn (_("Invalid pointer size (%d) in compunit header, using %d instead\n"),
2330 compunit
.cu_pointer_size
, offset_size
);
2331 compunit
.cu_pointer_size
= offset_size
;
2336 SAFE_BYTE_GET64 (hdrptr
, &signature_high
, &signature_low
, end
);
2338 SAFE_BYTE_GET_AND_INC (type_offset
, hdrptr
, offset_size
, end
);
2341 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
2342 && num_debug_info_entries
== 0
2345 debug_information
[unit
].cu_offset
= cu_offset
;
2346 debug_information
[unit
].pointer_size
2347 = compunit
.cu_pointer_size
;
2348 debug_information
[unit
].offset_size
= offset_size
;
2349 debug_information
[unit
].dwarf_version
= compunit
.cu_version
;
2350 debug_information
[unit
].base_address
= 0;
2351 debug_information
[unit
].addr_base
= DEBUG_INFO_UNAVAILABLE
;
2352 debug_information
[unit
].ranges_base
= DEBUG_INFO_UNAVAILABLE
;
2353 debug_information
[unit
].loc_offsets
= NULL
;
2354 debug_information
[unit
].have_frame_base
= NULL
;
2355 debug_information
[unit
].max_loc_offsets
= 0;
2356 debug_information
[unit
].num_loc_offsets
= 0;
2357 debug_information
[unit
].range_lists
= NULL
;
2358 debug_information
[unit
].max_range_lists
= 0;
2359 debug_information
[unit
].num_range_lists
= 0;
2362 if (!do_loc
&& dwarf_start_die
== 0)
2364 printf (_(" Compilation Unit @ offset 0x%s:\n"),
2365 dwarf_vmatoa ("x", cu_offset
));
2366 printf (_(" Length: 0x%s (%s)\n"),
2367 dwarf_vmatoa ("x", compunit
.cu_length
),
2368 offset_size
== 8 ? "64-bit" : "32-bit");
2369 printf (_(" Version: %d\n"), compunit
.cu_version
);
2370 printf (_(" Abbrev Offset: 0x%s\n"),
2371 dwarf_vmatoa ("x", compunit
.cu_abbrev_offset
));
2372 printf (_(" Pointer Size: %d\n"), compunit
.cu_pointer_size
);
2377 printf (_(" Signature: 0x%s\n"),
2378 dwarf_vmatoa64 (signature_high
, signature_low
,
2379 buf
, sizeof (buf
)));
2380 printf (_(" Type Offset: 0x%s\n"),
2381 dwarf_vmatoa ("x", type_offset
));
2383 if (this_set
!= NULL
)
2385 dwarf_vma
*offsets
= this_set
->section_offsets
;
2386 size_t *sizes
= this_set
->section_sizes
;
2388 printf (_(" Section contributions:\n"));
2389 printf (_(" .debug_abbrev.dwo: 0x%s 0x%s\n"),
2390 dwarf_vmatoa ("x", offsets
[DW_SECT_ABBREV
]),
2391 dwarf_vmatoa ("x", sizes
[DW_SECT_ABBREV
]));
2392 printf (_(" .debug_line.dwo: 0x%s 0x%s\n"),
2393 dwarf_vmatoa ("x", offsets
[DW_SECT_LINE
]),
2394 dwarf_vmatoa ("x", sizes
[DW_SECT_LINE
]));
2395 printf (_(" .debug_loc.dwo: 0x%s 0x%s\n"),
2396 dwarf_vmatoa ("x", offsets
[DW_SECT_LOC
]),
2397 dwarf_vmatoa ("x", sizes
[DW_SECT_LOC
]));
2398 printf (_(" .debug_str_offsets.dwo: 0x%s 0x%s\n"),
2399 dwarf_vmatoa ("x", offsets
[DW_SECT_STR_OFFSETS
]),
2400 dwarf_vmatoa ("x", sizes
[DW_SECT_STR_OFFSETS
]));
2404 if (cu_offset
+ compunit
.cu_length
+ initial_length_size
2407 warn (_("Debug info is corrupted, length of CU at %s"
2408 " extends beyond end of section (length = %s)\n"),
2409 dwarf_vmatoa ("x", cu_offset
),
2410 dwarf_vmatoa ("x", compunit
.cu_length
));
2414 start
+= compunit
.cu_length
+ initial_length_size
;
2416 if (compunit
.cu_version
!= 2
2417 && compunit
.cu_version
!= 3
2418 && compunit
.cu_version
!= 4)
2420 warn (_("CU at offset %s contains corrupt or "
2421 "unsupported version number: %d.\n"),
2422 dwarf_vmatoa ("x", cu_offset
), compunit
.cu_version
);
2428 /* Process the abbrevs used by this compilation unit. */
2429 if (compunit
.cu_abbrev_offset
>= abbrev_size
)
2430 warn (_("Debug info is corrupted, abbrev offset (%lx) is larger than abbrev section size (%lx)\n"),
2431 (unsigned long) compunit
.cu_abbrev_offset
,
2432 (unsigned long) abbrev_size
);
2434 process_abbrev_section
2435 (((unsigned char *) debug_displays
[abbrev_sec
].section
.start
2436 + abbrev_base
+ compunit
.cu_abbrev_offset
),
2437 ((unsigned char *) debug_displays
[abbrev_sec
].section
.start
2438 + abbrev_base
+ abbrev_size
));
2443 while (tags
< start
)
2445 unsigned int bytes_read
;
2446 unsigned long abbrev_number
;
2447 unsigned long die_offset
;
2448 abbrev_entry
*entry
;
2450 int do_printing
= 1;
2452 die_offset
= tags
- section_begin
;
2454 abbrev_number
= read_uleb128 (tags
, & bytes_read
, start
);
2457 /* A null DIE marks the end of a list of siblings or it may also be
2458 a section padding. */
2459 if (abbrev_number
== 0)
2461 /* Check if it can be a section padding for the last CU. */
2462 if (level
== 0 && start
== end
)
2466 for (chk
= tags
; chk
< start
; chk
++)
2473 if (!do_loc
&& die_offset
>= dwarf_start_die
2474 && (dwarf_cutoff_level
== -1
2475 || level
< dwarf_cutoff_level
))
2476 printf (_(" <%d><%lx>: Abbrev Number: 0\n"),
2482 static unsigned num_bogus_warns
= 0;
2484 if (num_bogus_warns
< 3)
2486 warn (_("Bogus end-of-siblings marker detected at offset %lx in %s section\n"),
2487 die_offset
, section
->name
);
2489 if (num_bogus_warns
== 3)
2490 warn (_("Further warnings about bogus end-of-sibling markers suppressed\n"));
2493 if (dwarf_start_die
!= 0 && level
< saved_level
)
2500 if (dwarf_start_die
!= 0 && die_offset
< dwarf_start_die
)
2504 if (dwarf_start_die
!= 0 && die_offset
== dwarf_start_die
)
2505 saved_level
= level
;
2506 do_printing
= (dwarf_cutoff_level
== -1
2507 || level
< dwarf_cutoff_level
);
2509 printf (_(" <%d><%lx>: Abbrev Number: %lu"),
2510 level
, die_offset
, abbrev_number
);
2511 else if (dwarf_cutoff_level
== -1
2512 || last_level
< dwarf_cutoff_level
)
2513 printf (_(" <%d><%lx>: ...\n"), level
, die_offset
);
2518 /* Scan through the abbreviation list until we reach the
2520 for (entry
= first_abbrev
;
2521 entry
&& entry
->entry
!= abbrev_number
;
2522 entry
= entry
->next
)
2527 if (!do_loc
&& do_printing
)
2532 warn (_("DIE at offset %lx refers to abbreviation number %lu which does not exist\n"),
2533 die_offset
, abbrev_number
);
2537 if (!do_loc
&& do_printing
)
2538 printf (" (%s)\n", get_TAG_name (entry
->tag
));
2543 need_base_address
= 0;
2545 case DW_TAG_compile_unit
:
2546 need_base_address
= 1;
2548 case DW_TAG_entry_point
:
2549 case DW_TAG_subprogram
:
2550 need_base_address
= 0;
2551 /* Assuming that there is no DW_AT_frame_base. */
2552 have_frame_base
= 0;
2556 for (attr
= entry
->first_attr
;
2557 attr
&& attr
->attribute
;
2562 if (! do_loc
&& do_printing
)
2563 /* Show the offset from where the tag was extracted. */
2564 printf (" <%lx>", (unsigned long)(tags
- section_begin
));
2566 arg
= debug_information
;
2567 if (debug_information
)
2570 tags
= read_and_display_attr (attr
->attribute
,
2575 compunit
.cu_pointer_size
,
2577 compunit
.cu_version
,
2579 do_loc
|| ! do_printing
,
2584 if (entry
->children
)
2589 /* Set num_debug_info_entries here so that it can be used to check if
2590 we need to process .debug_loc and .debug_ranges sections. */
2591 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
2592 && num_debug_info_entries
== 0
2594 num_debug_info_entries
= num_units
;
2602 /* Locate and scan the .debug_info section in the file and record the pointer
2603 sizes and offsets for the compilation units in it. Usually an executable
2604 will have just one pointer size, but this is not guaranteed, and so we try
2605 not to make any assumptions. Returns zero upon failure, or the number of
2606 compilation units upon success. */
2609 load_debug_info (void * file
)
2611 /* Reset the last pointer size so that we can issue correct error
2612 messages if we are displaying the contents of more than one section. */
2613 last_pointer_size
= 0;
2614 warned_about_missing_comp_units
= FALSE
;
2616 /* If we have already tried and failed to load the .debug_info
2617 section then do not bother to repeat the task. */
2618 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
2621 /* If we already have the information there is nothing else to do. */
2622 if (num_debug_info_entries
> 0)
2623 return num_debug_info_entries
;
2625 /* If this is a DWARF package file, load the CU and TU indexes. */
2626 load_cu_tu_indexes (file
);
2628 if (load_debug_section (info
, file
)
2629 && process_debug_info (&debug_displays
[info
].section
, file
, abbrev
, 1, 0))
2630 return num_debug_info_entries
;
2631 else if (load_debug_section (info_dwo
, file
)
2632 && process_debug_info (&debug_displays
[info_dwo
].section
, file
,
2634 return num_debug_info_entries
;
2636 num_debug_info_entries
= DEBUG_INFO_UNAVAILABLE
;
2640 /* Read a DWARF .debug_line section header starting at DATA.
2641 Upon success returns an updated DATA pointer and the LINFO
2642 structure and the END_OF_SEQUENCE pointer will be filled in.
2643 Otherwise returns NULL. */
2645 static unsigned char *
2646 read_debug_line_header (struct dwarf_section
* section
,
2647 unsigned char * data
,
2648 unsigned char * end
,
2649 DWARF2_Internal_LineInfo
* linfo
,
2650 unsigned char ** end_of_sequence
)
2652 unsigned char *hdrptr
;
2653 unsigned int offset_size
;
2654 unsigned int initial_length_size
;
2656 /* Extract information from the Line Number Program Header.
2657 (section 6.2.4 in the Dwarf3 doc). */
2660 /* Get and check the length of the block. */
2661 SAFE_BYTE_GET_AND_INC (linfo
->li_length
, hdrptr
, 4, end
);
2663 if (linfo
->li_length
== 0xffffffff)
2665 /* This section is 64-bit DWARF 3. */
2666 SAFE_BYTE_GET_AND_INC (linfo
->li_length
, hdrptr
, 8, end
);
2668 initial_length_size
= 12;
2673 initial_length_size
= 4;
2676 if (linfo
->li_length
+ initial_length_size
> section
->size
)
2678 /* If the length is just a bias against the initial_length_size then
2679 this means that the field has a relocation against it which has not
2680 been applied. (Ie we are dealing with an object file, not a linked
2681 binary). Do not complain but instead assume that the rest of the
2682 section applies to this particular header. */
2683 if (linfo
->li_length
== - initial_length_size
)
2685 linfo
->li_length
= section
->size
- initial_length_size
;
2689 warn (_("The line info appears to be corrupt - the section is too small\n"));
2694 /* Get and check the version number. */
2695 SAFE_BYTE_GET_AND_INC (linfo
->li_version
, hdrptr
, 2, end
);
2697 if (linfo
->li_version
!= 2
2698 && linfo
->li_version
!= 3
2699 && linfo
->li_version
!= 4)
2701 warn (_("Only DWARF version 2, 3 and 4 line info is currently supported.\n"));
2705 SAFE_BYTE_GET_AND_INC (linfo
->li_prologue_length
, hdrptr
, offset_size
, end
);
2706 SAFE_BYTE_GET_AND_INC (linfo
->li_min_insn_length
, hdrptr
, 1, end
);
2708 if (linfo
->li_version
>= 4)
2710 SAFE_BYTE_GET_AND_INC (linfo
->li_max_ops_per_insn
, hdrptr
, 1, end
);
2712 if (linfo
->li_max_ops_per_insn
== 0)
2714 warn (_("Invalid maximum operations per insn.\n"));
2719 linfo
->li_max_ops_per_insn
= 1;
2721 SAFE_BYTE_GET_AND_INC (linfo
->li_default_is_stmt
, hdrptr
, 1, end
);
2722 SAFE_SIGNED_BYTE_GET_AND_INC (linfo
->li_line_base
, hdrptr
, 1, end
);
2723 SAFE_BYTE_GET_AND_INC (linfo
->li_line_range
, hdrptr
, 1, end
);
2724 SAFE_BYTE_GET_AND_INC (linfo
->li_opcode_base
, hdrptr
, 1, end
);
2726 * end_of_sequence
= data
+ linfo
->li_length
+ initial_length_size
;
2727 /* PR 17512: file:002-117414-0.004. */
2728 if (* end_of_sequence
> end
)
2730 warn (_("Line length %lld extends beyond end of section\n"), linfo
->li_length
);
2731 * end_of_sequence
= end
;
2739 display_debug_lines_raw (struct dwarf_section
*section
,
2740 unsigned char *data
,
2743 unsigned char *start
= section
->start
;
2745 printf (_("Raw dump of debug contents of section %s:\n\n"),
2750 static DWARF2_Internal_LineInfo saved_linfo
;
2751 DWARF2_Internal_LineInfo linfo
;
2752 unsigned char *standard_opcodes
;
2753 unsigned char *end_of_sequence
;
2754 unsigned int last_dir_entry
= 0;
2757 if (const_strneq (section
->name
, ".debug_line.")
2758 /* Note: the following does not apply to .debug_line.dwo sections.
2759 These are full debug_line sections. */
2760 && strcmp (section
->name
, ".debug_line.dwo") != 0)
2762 /* Sections named .debug_line.<foo> are fragments of a .debug_line
2763 section containing just the Line Number Statements. They are
2764 created by the assembler and intended to be used alongside gcc's
2765 -ffunction-sections command line option. When the linker's
2766 garbage collection decides to discard a .text.<foo> section it
2767 can then also discard the line number information in .debug_line.<foo>.
2769 Since the section is a fragment it does not have the details
2770 needed to fill out a LineInfo structure, so instead we use the
2771 details from the last full debug_line section that we processed. */
2772 end_of_sequence
= end
;
2773 standard_opcodes
= NULL
;
2774 linfo
= saved_linfo
;
2775 reset_state_machine (linfo
.li_default_is_stmt
);
2779 unsigned char * hdrptr
;
2781 if ((hdrptr
= read_debug_line_header (section
, data
, end
, & linfo
,
2782 & end_of_sequence
)) == NULL
)
2785 printf (_(" Offset: 0x%lx\n"), (long)(data
- start
));
2786 printf (_(" Length: %ld\n"), (long) linfo
.li_length
);
2787 printf (_(" DWARF Version: %d\n"), linfo
.li_version
);
2788 printf (_(" Prologue Length: %d\n"), linfo
.li_prologue_length
);
2789 printf (_(" Minimum Instruction Length: %d\n"), linfo
.li_min_insn_length
);
2790 if (linfo
.li_version
>= 4)
2791 printf (_(" Maximum Ops per Instruction: %d\n"), linfo
.li_max_ops_per_insn
);
2792 printf (_(" Initial value of 'is_stmt': %d\n"), linfo
.li_default_is_stmt
);
2793 printf (_(" Line Base: %d\n"), linfo
.li_line_base
);
2794 printf (_(" Line Range: %d\n"), linfo
.li_line_range
);
2795 printf (_(" Opcode Base: %d\n"), linfo
.li_opcode_base
);
2797 /* PR 17512: file: 1665-6428-0.004. */
2798 if (linfo
.li_line_range
== 0)
2800 warn (_("Line range of 0 is invalid, using 1 instead\n"));
2801 linfo
.li_line_range
= 1;
2804 reset_state_machine (linfo
.li_default_is_stmt
);
2806 /* Display the contents of the Opcodes table. */
2807 standard_opcodes
= hdrptr
;
2809 /* PR 17512: file: 002-417945-0.004. */
2810 if (standard_opcodes
+ linfo
.li_opcode_base
>= end
)
2812 warn (_("Line Base extends beyond end of section\n"));
2816 printf (_("\n Opcodes:\n"));
2818 for (i
= 1; i
< linfo
.li_opcode_base
; i
++)
2819 printf (_(" Opcode %d has %d args\n"), i
, standard_opcodes
[i
- 1]);
2821 /* Display the contents of the Directory table. */
2822 data
= standard_opcodes
+ linfo
.li_opcode_base
- 1;
2825 printf (_("\n The Directory Table is empty.\n"));
2828 printf (_("\n The Directory Table (offset 0x%lx):\n"),
2829 (long)(data
- start
));
2831 while (data
< end
&& *data
!= 0)
2833 printf (" %d\t%.*s\n", ++last_dir_entry
, (int) (end
- data
), data
);
2835 data
+= strnlen ((char *) data
, end
- data
) + 1;
2838 /* PR 17512: file: 002-132094-0.004. */
2839 if (data
>= end
- 1)
2843 /* Skip the NUL at the end of the table. */
2846 /* Display the contents of the File Name table. */
2848 printf (_("\n The File Name Table is empty.\n"));
2851 printf (_("\n The File Name Table (offset 0x%lx):\n"),
2852 (long)(data
- start
));
2853 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
2855 while (data
< end
&& *data
!= 0)
2857 unsigned char *name
;
2858 unsigned int bytes_read
;
2860 printf (" %d\t", ++state_machine_regs
.last_file_entry
);
2862 data
+= strnlen ((char *) data
, end
- data
) + 1;
2865 dwarf_vmatoa ("u", read_uleb128 (data
, & bytes_read
, end
)));
2868 dwarf_vmatoa ("u", read_uleb128 (data
, & bytes_read
, end
)));
2871 dwarf_vmatoa ("u", read_uleb128 (data
, & bytes_read
, end
)));
2873 printf ("%.*s\n", (int)(end
- name
), name
);
2877 warn (_("Corrupt file name table entry\n"));
2883 /* Skip the NUL at the end of the table. */
2886 saved_linfo
= linfo
;
2889 /* Now display the statements. */
2890 if (data
>= end_of_sequence
)
2891 printf (_(" No Line Number Statements.\n"));
2894 printf (_(" Line Number Statements:\n"));
2896 while (data
< end_of_sequence
)
2898 unsigned char op_code
;
2899 dwarf_signed_vma adv
;
2901 unsigned int bytes_read
;
2903 printf (" [0x%08lx]", (long)(data
- start
));
2907 if (op_code
>= linfo
.li_opcode_base
)
2909 op_code
-= linfo
.li_opcode_base
;
2910 uladv
= (op_code
/ linfo
.li_line_range
);
2911 if (linfo
.li_max_ops_per_insn
== 1)
2913 uladv
*= linfo
.li_min_insn_length
;
2914 state_machine_regs
.address
+= uladv
;
2915 printf (_(" Special opcode %d: "
2916 "advance Address by %s to 0x%s"),
2917 op_code
, dwarf_vmatoa ("u", uladv
),
2918 dwarf_vmatoa ("x", state_machine_regs
.address
));
2922 state_machine_regs
.address
2923 += ((state_machine_regs
.op_index
+ uladv
)
2924 / linfo
.li_max_ops_per_insn
)
2925 * linfo
.li_min_insn_length
;
2926 state_machine_regs
.op_index
2927 = (state_machine_regs
.op_index
+ uladv
)
2928 % linfo
.li_max_ops_per_insn
;
2929 printf (_(" Special opcode %d: "
2930 "advance Address by %s to 0x%s[%d]"),
2931 op_code
, dwarf_vmatoa ("u", uladv
),
2932 dwarf_vmatoa ("x", state_machine_regs
.address
),
2933 state_machine_regs
.op_index
);
2935 adv
= (op_code
% linfo
.li_line_range
) + linfo
.li_line_base
;
2936 state_machine_regs
.line
+= adv
;
2937 printf (_(" and Line by %s to %d\n"),
2938 dwarf_vmatoa ("d", adv
), state_machine_regs
.line
);
2940 else switch (op_code
)
2942 case DW_LNS_extended_op
:
2943 data
+= process_extended_line_op (data
, linfo
.li_default_is_stmt
, end
);
2947 printf (_(" Copy\n"));
2950 case DW_LNS_advance_pc
:
2951 uladv
= read_uleb128 (data
, & bytes_read
, end
);
2953 if (linfo
.li_max_ops_per_insn
== 1)
2955 uladv
*= linfo
.li_min_insn_length
;
2956 state_machine_regs
.address
+= uladv
;
2957 printf (_(" Advance PC by %s to 0x%s\n"),
2958 dwarf_vmatoa ("u", uladv
),
2959 dwarf_vmatoa ("x", state_machine_regs
.address
));
2963 state_machine_regs
.address
2964 += ((state_machine_regs
.op_index
+ uladv
)
2965 / linfo
.li_max_ops_per_insn
)
2966 * linfo
.li_min_insn_length
;
2967 state_machine_regs
.op_index
2968 = (state_machine_regs
.op_index
+ uladv
)
2969 % linfo
.li_max_ops_per_insn
;
2970 printf (_(" Advance PC by %s to 0x%s[%d]\n"),
2971 dwarf_vmatoa ("u", uladv
),
2972 dwarf_vmatoa ("x", state_machine_regs
.address
),
2973 state_machine_regs
.op_index
);
2977 case DW_LNS_advance_line
:
2978 adv
= read_sleb128 (data
, & bytes_read
, end
);
2980 state_machine_regs
.line
+= adv
;
2981 printf (_(" Advance Line by %s to %d\n"),
2982 dwarf_vmatoa ("d", adv
),
2983 state_machine_regs
.line
);
2986 case DW_LNS_set_file
:
2987 adv
= read_uleb128 (data
, & bytes_read
, end
);
2989 printf (_(" Set File Name to entry %s in the File Name Table\n"),
2990 dwarf_vmatoa ("d", adv
));
2991 state_machine_regs
.file
= adv
;
2994 case DW_LNS_set_column
:
2995 uladv
= read_uleb128 (data
, & bytes_read
, end
);
2997 printf (_(" Set column to %s\n"),
2998 dwarf_vmatoa ("u", uladv
));
2999 state_machine_regs
.column
= uladv
;
3002 case DW_LNS_negate_stmt
:
3003 adv
= state_machine_regs
.is_stmt
;
3005 printf (_(" Set is_stmt to %s\n"), dwarf_vmatoa ("d", adv
));
3006 state_machine_regs
.is_stmt
= adv
;
3009 case DW_LNS_set_basic_block
:
3010 printf (_(" Set basic block\n"));
3011 state_machine_regs
.basic_block
= 1;
3014 case DW_LNS_const_add_pc
:
3015 uladv
= ((255 - linfo
.li_opcode_base
) / linfo
.li_line_range
);
3016 if (linfo
.li_max_ops_per_insn
)
3018 uladv
*= linfo
.li_min_insn_length
;
3019 state_machine_regs
.address
+= uladv
;
3020 printf (_(" Advance PC by constant %s to 0x%s\n"),
3021 dwarf_vmatoa ("u", uladv
),
3022 dwarf_vmatoa ("x", state_machine_regs
.address
));
3026 state_machine_regs
.address
3027 += ((state_machine_regs
.op_index
+ uladv
)
3028 / linfo
.li_max_ops_per_insn
)
3029 * linfo
.li_min_insn_length
;
3030 state_machine_regs
.op_index
3031 = (state_machine_regs
.op_index
+ uladv
)
3032 % linfo
.li_max_ops_per_insn
;
3033 printf (_(" Advance PC by constant %s to 0x%s[%d]\n"),
3034 dwarf_vmatoa ("u", uladv
),
3035 dwarf_vmatoa ("x", state_machine_regs
.address
),
3036 state_machine_regs
.op_index
);
3040 case DW_LNS_fixed_advance_pc
:
3041 SAFE_BYTE_GET_AND_INC (uladv
, data
, 2, end
);
3042 state_machine_regs
.address
+= uladv
;
3043 state_machine_regs
.op_index
= 0;
3044 printf (_(" Advance PC by fixed size amount %s to 0x%s\n"),
3045 dwarf_vmatoa ("u", uladv
),
3046 dwarf_vmatoa ("x", state_machine_regs
.address
));
3049 case DW_LNS_set_prologue_end
:
3050 printf (_(" Set prologue_end to true\n"));
3053 case DW_LNS_set_epilogue_begin
:
3054 printf (_(" Set epilogue_begin to true\n"));
3057 case DW_LNS_set_isa
:
3058 uladv
= read_uleb128 (data
, & bytes_read
, end
);
3060 printf (_(" Set ISA to %s\n"), dwarf_vmatoa ("u", uladv
));
3064 printf (_(" Unknown opcode %d with operands: "), op_code
);
3066 if (standard_opcodes
!= NULL
)
3067 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
3069 printf ("0x%s%s", dwarf_vmatoa ("x", read_uleb128 (data
,
3071 i
== 1 ? "" : ", ");
3087 unsigned char *name
;
3088 unsigned int directory_index
;
3089 unsigned int modification_date
;
3090 unsigned int length
;
3093 /* Output a decoded representation of the .debug_line section. */
3096 display_debug_lines_decoded (struct dwarf_section
*section
,
3097 unsigned char *data
,
3100 static DWARF2_Internal_LineInfo saved_linfo
;
3102 printf (_("Decoded dump of debug contents of section %s:\n\n"),
3107 /* This loop amounts to one iteration per compilation unit. */
3108 DWARF2_Internal_LineInfo linfo
;
3109 unsigned char *standard_opcodes
;
3110 unsigned char *end_of_sequence
;
3112 File_Entry
*file_table
= NULL
;
3113 unsigned int n_files
= 0;
3114 unsigned char **directory_table
= NULL
;
3115 unsigned int n_directories
= 0;
3117 if (const_strneq (section
->name
, ".debug_line.")
3118 /* Note: the following does not apply to .debug_line.dwo sections.
3119 These are full debug_line sections. */
3120 && strcmp (section
->name
, ".debug_line.dwo") != 0)
3122 /* See comment in display_debug_lines_raw(). */
3123 end_of_sequence
= end
;
3124 standard_opcodes
= NULL
;
3125 linfo
= saved_linfo
;
3126 reset_state_machine (linfo
.li_default_is_stmt
);
3130 unsigned char *hdrptr
;
3132 if ((hdrptr
= read_debug_line_header (section
, data
, end
, & linfo
,
3133 & end_of_sequence
)) == NULL
)
3136 reset_state_machine (linfo
.li_default_is_stmt
);
3138 /* Save a pointer to the contents of the Opcodes table. */
3139 standard_opcodes
= hdrptr
;
3141 /* Traverse the Directory table just to count entries. */
3142 data
= standard_opcodes
+ linfo
.li_opcode_base
- 1;
3145 unsigned char *ptr_directory_table
= data
;
3149 data
+= strnlen ((char *) data
, end
- data
) + 1;
3153 /* Go through the directory table again to save the directories. */
3154 directory_table
= (unsigned char **)
3155 xmalloc (n_directories
* sizeof (unsigned char *));
3158 while (*ptr_directory_table
!= 0)
3160 directory_table
[i
] = ptr_directory_table
;
3161 ptr_directory_table
+= strnlen ((char *) ptr_directory_table
,
3162 ptr_directory_table
- end
) + 1;
3166 /* Skip the NUL at the end of the table. */
3169 /* Traverse the File Name table just to count the entries. */
3172 unsigned char *ptr_file_name_table
= data
;
3176 unsigned int bytes_read
;
3178 /* Skip Name, directory index, last modification time and length
3180 data
+= strnlen ((char *) data
, end
- data
) + 1;
3181 read_uleb128 (data
, & bytes_read
, end
);
3183 read_uleb128 (data
, & bytes_read
, end
);
3185 read_uleb128 (data
, & bytes_read
, end
);
3191 /* Go through the file table again to save the strings. */
3192 file_table
= (File_Entry
*) xmalloc (n_files
* sizeof (File_Entry
));
3195 while (*ptr_file_name_table
!= 0)
3197 unsigned int bytes_read
;
3199 file_table
[i
].name
= ptr_file_name_table
;
3200 ptr_file_name_table
+= strnlen ((char *) ptr_file_name_table
,
3201 end
- ptr_file_name_table
) + 1;
3203 /* We are not interested in directory, time or size. */
3204 file_table
[i
].directory_index
= read_uleb128 (ptr_file_name_table
,
3206 ptr_file_name_table
+= bytes_read
;
3207 file_table
[i
].modification_date
= read_uleb128 (ptr_file_name_table
,
3209 ptr_file_name_table
+= bytes_read
;
3210 file_table
[i
].length
= read_uleb128 (ptr_file_name_table
, & bytes_read
, end
);
3211 ptr_file_name_table
+= bytes_read
;
3216 /* Print the Compilation Unit's name and a header. */
3217 if (directory_table
== NULL
)
3219 printf (_("CU: %s:\n"), file_table
[0].name
);
3220 printf (_("File name Line number Starting address\n"));
3224 unsigned int ix
= file_table
[0].directory_index
;
3225 const char *directory
= ix
? (char *)directory_table
[ix
- 1] : ".";
3227 if (do_wide
|| strlen (directory
) < 76)
3228 printf (_("CU: %s/%s:\n"), directory
, file_table
[0].name
);
3230 printf ("%s:\n", file_table
[0].name
);
3232 printf (_("File name Line number Starting address\n"));
3236 /* Skip the NUL at the end of the table. */
3239 saved_linfo
= linfo
;
3242 /* This loop iterates through the Dwarf Line Number Program. */
3243 while (data
< end_of_sequence
)
3245 unsigned char op_code
;
3247 unsigned long int uladv
;
3248 unsigned int bytes_read
;
3249 int is_special_opcode
= 0;
3253 if (op_code
>= linfo
.li_opcode_base
)
3255 op_code
-= linfo
.li_opcode_base
;
3256 uladv
= (op_code
/ linfo
.li_line_range
);
3257 if (linfo
.li_max_ops_per_insn
== 1)
3259 uladv
*= linfo
.li_min_insn_length
;
3260 state_machine_regs
.address
+= uladv
;
3264 state_machine_regs
.address
3265 += ((state_machine_regs
.op_index
+ uladv
)
3266 / linfo
.li_max_ops_per_insn
)
3267 * linfo
.li_min_insn_length
;
3268 state_machine_regs
.op_index
3269 = (state_machine_regs
.op_index
+ uladv
)
3270 % linfo
.li_max_ops_per_insn
;
3273 adv
= (op_code
% linfo
.li_line_range
) + linfo
.li_line_base
;
3274 state_machine_regs
.line
+= adv
;
3275 is_special_opcode
= 1;
3277 else switch (op_code
)
3279 case DW_LNS_extended_op
:
3281 unsigned int ext_op_code_len
;
3282 unsigned char ext_op_code
;
3283 unsigned char *op_code_data
= data
;
3285 ext_op_code_len
= read_uleb128 (op_code_data
, &bytes_read
,
3287 op_code_data
+= bytes_read
;
3289 if (ext_op_code_len
== 0)
3291 warn (_("Badly formed extended line op encountered!\n"));
3294 ext_op_code_len
+= bytes_read
;
3295 ext_op_code
= *op_code_data
++;
3297 switch (ext_op_code
)
3299 case DW_LNE_end_sequence
:
3300 reset_state_machine (linfo
.li_default_is_stmt
);
3302 case DW_LNE_set_address
:
3303 SAFE_BYTE_GET_AND_INC (state_machine_regs
.address
,
3305 ext_op_code_len
- bytes_read
- 1,
3307 state_machine_regs
.op_index
= 0;
3309 case DW_LNE_define_file
:
3311 file_table
= (File_Entry
*) xrealloc
3312 (file_table
, (n_files
+ 1) * sizeof (File_Entry
));
3314 ++state_machine_regs
.last_file_entry
;
3315 /* Source file name. */
3316 file_table
[n_files
].name
= op_code_data
;
3317 op_code_data
+= strlen ((char *) op_code_data
) + 1;
3318 /* Directory index. */
3319 file_table
[n_files
].directory_index
=
3320 read_uleb128 (op_code_data
, & bytes_read
,
3322 op_code_data
+= bytes_read
;
3323 /* Last modification time. */
3324 file_table
[n_files
].modification_date
=
3325 read_uleb128 (op_code_data
, & bytes_read
,
3327 op_code_data
+= bytes_read
;
3329 file_table
[n_files
].length
=
3330 read_uleb128 (op_code_data
, & bytes_read
,
3336 case DW_LNE_set_discriminator
:
3337 case DW_LNE_HP_set_sequence
:
3338 /* Simply ignored. */
3342 printf (_("UNKNOWN (%u): length %d\n"),
3343 ext_op_code
, ext_op_code_len
- bytes_read
);
3346 data
+= ext_op_code_len
;
3352 case DW_LNS_advance_pc
:
3353 uladv
= read_uleb128 (data
, & bytes_read
, end
);
3355 if (linfo
.li_max_ops_per_insn
== 1)
3357 uladv
*= linfo
.li_min_insn_length
;
3358 state_machine_regs
.address
+= uladv
;
3362 state_machine_regs
.address
3363 += ((state_machine_regs
.op_index
+ uladv
)
3364 / linfo
.li_max_ops_per_insn
)
3365 * linfo
.li_min_insn_length
;
3366 state_machine_regs
.op_index
3367 = (state_machine_regs
.op_index
+ uladv
)
3368 % linfo
.li_max_ops_per_insn
;
3372 case DW_LNS_advance_line
:
3373 adv
= read_sleb128 (data
, & bytes_read
, end
);
3375 state_machine_regs
.line
+= adv
;
3378 case DW_LNS_set_file
:
3379 adv
= read_uleb128 (data
, & bytes_read
, end
);
3381 state_machine_regs
.file
= adv
;
3383 if (file_table
== NULL
)
3384 printf (_("\n [Use file table entry %d]\n"), state_machine_regs
.file
- 1);
3385 else if (file_table
[state_machine_regs
.file
- 1].directory_index
== 0)
3386 /* If directory index is 0, that means current directory. */
3387 printf ("\n./%s:[++]\n",
3388 file_table
[state_machine_regs
.file
- 1].name
);
3389 else if (directory_table
== NULL
)
3390 printf (_("\n [Use directory table entry %d]\n"),
3391 file_table
[state_machine_regs
.file
- 1].directory_index
- 1);
3393 /* The directory index starts counting at 1. */
3394 printf ("\n%s/%s:\n",
3395 directory_table
[file_table
[state_machine_regs
.file
- 1].directory_index
- 1],
3396 file_table
[state_machine_regs
.file
- 1].name
);
3399 case DW_LNS_set_column
:
3400 uladv
= read_uleb128 (data
, & bytes_read
, end
);
3402 state_machine_regs
.column
= uladv
;
3405 case DW_LNS_negate_stmt
:
3406 adv
= state_machine_regs
.is_stmt
;
3408 state_machine_regs
.is_stmt
= adv
;
3411 case DW_LNS_set_basic_block
:
3412 state_machine_regs
.basic_block
= 1;
3415 case DW_LNS_const_add_pc
:
3416 uladv
= ((255 - linfo
.li_opcode_base
) / linfo
.li_line_range
);
3417 if (linfo
.li_max_ops_per_insn
== 1)
3419 uladv
*= linfo
.li_min_insn_length
;
3420 state_machine_regs
.address
+= uladv
;
3424 state_machine_regs
.address
3425 += ((state_machine_regs
.op_index
+ uladv
)
3426 / linfo
.li_max_ops_per_insn
)
3427 * linfo
.li_min_insn_length
;
3428 state_machine_regs
.op_index
3429 = (state_machine_regs
.op_index
+ uladv
)
3430 % linfo
.li_max_ops_per_insn
;
3434 case DW_LNS_fixed_advance_pc
:
3435 SAFE_BYTE_GET_AND_INC (uladv
, data
, 2, end
);
3436 state_machine_regs
.address
+= uladv
;
3437 state_machine_regs
.op_index
= 0;
3440 case DW_LNS_set_prologue_end
:
3443 case DW_LNS_set_epilogue_begin
:
3446 case DW_LNS_set_isa
:
3447 uladv
= read_uleb128 (data
, & bytes_read
, end
);
3449 printf (_(" Set ISA to %lu\n"), uladv
);
3453 printf (_(" Unknown opcode %d with operands: "), op_code
);
3455 if (standard_opcodes
!= NULL
)
3456 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
3458 printf ("0x%s%s", dwarf_vmatoa ("x", read_uleb128 (data
,
3460 i
== 1 ? "" : ", ");
3467 /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row
3468 to the DWARF address/line matrix. */
3469 if ((is_special_opcode
) || (op_code
== DW_LNE_end_sequence
)
3470 || (op_code
== DW_LNS_copy
))
3472 const unsigned int MAX_FILENAME_LENGTH
= 35;
3474 char *newFileName
= NULL
;
3475 size_t fileNameLength
;
3478 fileName
= (char *) file_table
[state_machine_regs
.file
- 1].name
;
3480 fileName
= "<unknown>";
3482 fileNameLength
= strlen (fileName
);
3484 if ((fileNameLength
> MAX_FILENAME_LENGTH
) && (!do_wide
))
3486 newFileName
= (char *) xmalloc (MAX_FILENAME_LENGTH
+ 1);
3487 /* Truncate file name */
3488 strncpy (newFileName
,
3489 fileName
+ fileNameLength
- MAX_FILENAME_LENGTH
,
3490 MAX_FILENAME_LENGTH
+ 1);
3494 newFileName
= (char *) xmalloc (fileNameLength
+ 1);
3495 strncpy (newFileName
, fileName
, fileNameLength
+ 1);
3498 if (!do_wide
|| (fileNameLength
<= MAX_FILENAME_LENGTH
))
3500 if (linfo
.li_max_ops_per_insn
== 1)
3501 printf ("%-35s %11d %#18" DWARF_VMA_FMT
"x\n",
3502 newFileName
, state_machine_regs
.line
,
3503 state_machine_regs
.address
);
3505 printf ("%-35s %11d %#18" DWARF_VMA_FMT
"x[%d]\n",
3506 newFileName
, state_machine_regs
.line
,
3507 state_machine_regs
.address
,
3508 state_machine_regs
.op_index
);
3512 if (linfo
.li_max_ops_per_insn
== 1)
3513 printf ("%s %11d %#18" DWARF_VMA_FMT
"x\n",
3514 newFileName
, state_machine_regs
.line
,
3515 state_machine_regs
.address
);
3517 printf ("%s %11d %#18" DWARF_VMA_FMT
"x[%d]\n",
3518 newFileName
, state_machine_regs
.line
,
3519 state_machine_regs
.address
,
3520 state_machine_regs
.op_index
);
3523 if (op_code
== DW_LNE_end_sequence
)
3537 if (directory_table
)
3539 free (directory_table
);
3540 directory_table
= NULL
;
3551 display_debug_lines (struct dwarf_section
*section
, void *file ATTRIBUTE_UNUSED
)
3553 unsigned char *data
= section
->start
;
3554 unsigned char *end
= data
+ section
->size
;
3556 int retValDecoded
= 1;
3558 if (do_debug_lines
== 0)
3559 do_debug_lines
|= FLAG_DEBUG_LINES_RAW
;
3561 if (do_debug_lines
& FLAG_DEBUG_LINES_RAW
)
3562 retValRaw
= display_debug_lines_raw (section
, data
, end
);
3564 if (do_debug_lines
& FLAG_DEBUG_LINES_DECODED
)
3565 retValDecoded
= display_debug_lines_decoded (section
, data
, end
);
3567 if (!retValRaw
|| !retValDecoded
)
3574 find_debug_info_for_offset (unsigned long offset
)
3578 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
3581 for (i
= 0; i
< num_debug_info_entries
; i
++)
3582 if (debug_information
[i
].cu_offset
== offset
)
3583 return debug_information
+ i
;
3589 get_gdb_index_symbol_kind_name (gdb_index_symbol_kind kind
)
3591 /* See gdb/gdb-index.h. */
3592 static const char * const kinds
[] =
3604 return _ (kinds
[kind
]);
3608 display_debug_pubnames_worker (struct dwarf_section
*section
,
3609 void *file ATTRIBUTE_UNUSED
,
3612 DWARF2_Internal_PubNames names
;
3613 unsigned char *start
= section
->start
;
3614 unsigned char *end
= start
+ section
->size
;
3616 /* It does not matter if this load fails,
3617 we test for that later on. */
3618 load_debug_info (file
);
3620 printf (_("Contents of the %s section:\n\n"), section
->name
);
3624 unsigned char *data
;
3625 unsigned long offset
;
3626 unsigned int offset_size
, initial_length_size
;
3630 SAFE_BYTE_GET_AND_INC (names
.pn_length
, data
, 4, end
);
3631 if (names
.pn_length
== 0xffffffff)
3633 SAFE_BYTE_GET_AND_INC (names
.pn_length
, data
, 8, end
);
3635 initial_length_size
= 12;
3640 initial_length_size
= 4;
3643 SAFE_BYTE_GET_AND_INC (names
.pn_version
, data
, 2, end
);
3644 SAFE_BYTE_GET_AND_INC (names
.pn_offset
, data
, offset_size
, end
);
3646 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
3647 && num_debug_info_entries
> 0
3648 && find_debug_info_for_offset (names
.pn_offset
) == NULL
)
3649 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
3650 (unsigned long) names
.pn_offset
, section
->name
);
3652 SAFE_BYTE_GET_AND_INC (names
.pn_size
, data
, offset_size
, end
);
3654 start
+= names
.pn_length
+ initial_length_size
;
3656 if (names
.pn_version
!= 2 && names
.pn_version
!= 3)
3658 static int warned
= 0;
3662 warn (_("Only DWARF 2 and 3 pubnames are currently supported\n"));
3669 printf (_(" Length: %ld\n"),
3670 (long) names
.pn_length
);
3671 printf (_(" Version: %d\n"),
3673 printf (_(" Offset into .debug_info section: 0x%lx\n"),
3674 (unsigned long) names
.pn_offset
);
3675 printf (_(" Size of area in .debug_info section: %ld\n"),
3676 (long) names
.pn_size
);
3679 printf (_("\n Offset Kind Name\n"));
3681 printf (_("\n Offset\tName\n"));
3685 bfd_size_type maxprint
;
3687 SAFE_BYTE_GET (offset
, data
, offset_size
, end
);
3691 data
+= offset_size
;
3694 maxprint
= (end
- data
) - 1;
3698 unsigned int kind_data
;
3699 gdb_index_symbol_kind kind
;
3700 const char *kind_name
;
3703 SAFE_BYTE_GET (kind_data
, data
, 1, end
);
3706 /* GCC computes the kind as the upper byte in the CU index
3707 word, and then right shifts it by the CU index size.
3708 Left shift KIND to where the gdb-index.h accessor macros
3710 kind_data
<<= GDB_INDEX_CU_BITSIZE
;
3711 kind
= GDB_INDEX_SYMBOL_KIND_VALUE (kind_data
);
3712 kind_name
= get_gdb_index_symbol_kind_name (kind
);
3713 is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (kind_data
);
3714 printf (" %-6lx %s,%-10s %.*s\n",
3715 offset
, is_static
? _("s") : _("g"),
3716 kind_name
, (int) maxprint
, data
);
3719 printf (" %-6lx\t%.*s\n", offset
, (int) maxprint
, data
);
3721 data
+= strnlen ((char *) data
, maxprint
) + 1;
3726 while (offset
!= 0);
3734 display_debug_pubnames (struct dwarf_section
*section
, void *file
)
3736 return display_debug_pubnames_worker (section
, file
, 0);
3740 display_debug_gnu_pubnames (struct dwarf_section
*section
, void *file
)
3742 return display_debug_pubnames_worker (section
, file
, 1);
3746 display_debug_macinfo (struct dwarf_section
*section
,
3747 void *file ATTRIBUTE_UNUSED
)
3749 unsigned char *start
= section
->start
;
3750 unsigned char *end
= start
+ section
->size
;
3751 unsigned char *curr
= start
;
3752 unsigned int bytes_read
;
3753 enum dwarf_macinfo_record_type op
;
3755 printf (_("Contents of the %s section:\n\n"), section
->name
);
3759 unsigned int lineno
;
3760 const unsigned char *string
;
3762 op
= (enum dwarf_macinfo_record_type
) *curr
;
3767 case DW_MACINFO_start_file
:
3769 unsigned int filenum
;
3771 lineno
= read_uleb128 (curr
, & bytes_read
, end
);
3773 filenum
= read_uleb128 (curr
, & bytes_read
, end
);
3776 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"),
3781 case DW_MACINFO_end_file
:
3782 printf (_(" DW_MACINFO_end_file\n"));
3785 case DW_MACINFO_define
:
3786 lineno
= read_uleb128 (curr
, & bytes_read
, end
);
3789 curr
+= strnlen ((char *) string
, end
- string
) + 1;
3790 printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"),
3794 case DW_MACINFO_undef
:
3795 lineno
= read_uleb128 (curr
, & bytes_read
, end
);
3798 curr
+= strnlen ((char *) string
, end
- string
) + 1;
3799 printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"),
3803 case DW_MACINFO_vendor_ext
:
3805 unsigned int constant
;
3807 constant
= read_uleb128 (curr
, & bytes_read
, end
);
3810 curr
+= strnlen ((char *) string
, end
- string
) + 1;
3811 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"),
3821 /* Given LINE_OFFSET into the .debug_line section, attempt to return
3822 filename and dirname corresponding to file name table entry with index
3823 FILEIDX. Return NULL on failure. */
3825 static unsigned char *
3826 get_line_filename_and_dirname (dwarf_vma line_offset
,
3828 unsigned char **dir_name
)
3830 struct dwarf_section
*section
= &debug_displays
[line
].section
;
3831 unsigned char *hdrptr
, *dirtable
, *file_name
;
3832 unsigned int offset_size
, initial_length_size
;
3833 unsigned int version
, opcode_base
, bytes_read
;
3834 dwarf_vma length
, diridx
;
3835 const unsigned char * end
;
3838 if (section
->start
== NULL
3839 || line_offset
>= section
->size
3843 hdrptr
= section
->start
+ line_offset
;
3844 end
= section
->start
+ section
->size
;
3846 SAFE_BYTE_GET_AND_INC (length
, hdrptr
, 4, end
);
3847 if (length
== 0xffffffff)
3849 /* This section is 64-bit DWARF 3. */
3850 SAFE_BYTE_GET_AND_INC (length
, hdrptr
, 8, end
);
3852 initial_length_size
= 12;
3857 initial_length_size
= 4;
3859 if (length
+ initial_length_size
> section
->size
)
3862 SAFE_BYTE_GET_AND_INC (version
, hdrptr
, 2, end
);
3863 if (version
!= 2 && version
!= 3 && version
!= 4)
3865 hdrptr
+= offset_size
+ 1;/* Skip prologue_length and min_insn_length. */
3867 hdrptr
++; /* Skip max_ops_per_insn. */
3868 hdrptr
+= 3; /* Skip default_is_stmt, line_base, line_range. */
3870 SAFE_BYTE_GET_AND_INC (opcode_base
, hdrptr
, 1, end
);
3871 if (opcode_base
== 0)
3874 hdrptr
+= opcode_base
- 1;
3876 /* Skip over dirname table. */
3877 while (*hdrptr
!= '\0')
3878 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
) + 1;
3879 hdrptr
++; /* Skip the NUL at the end of the table. */
3880 /* Now skip over preceding filename table entries. */
3881 for (; *hdrptr
!= '\0' && fileidx
> 1; fileidx
--)
3883 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
) + 1;
3884 read_uleb128 (hdrptr
, &bytes_read
, end
);
3885 hdrptr
+= bytes_read
;
3886 read_uleb128 (hdrptr
, &bytes_read
, end
);
3887 hdrptr
+= bytes_read
;
3888 read_uleb128 (hdrptr
, &bytes_read
, end
);
3889 hdrptr
+= bytes_read
;
3891 if (hdrptr
== end
|| *hdrptr
== '\0')
3894 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
) + 1;
3895 diridx
= read_uleb128 (hdrptr
, &bytes_read
, end
);
3898 for (; *dirtable
!= '\0' && diridx
> 1; diridx
--)
3899 dirtable
+= strnlen ((char *) dirtable
, end
- dirtable
) + 1;
3900 if (*dirtable
== '\0')
3902 *dir_name
= dirtable
;
3907 display_debug_macro (struct dwarf_section
*section
,
3910 unsigned char *start
= section
->start
;
3911 unsigned char *end
= start
+ section
->size
;
3912 unsigned char *curr
= start
;
3913 unsigned char *extended_op_buf
[256];
3914 unsigned int bytes_read
;
3916 load_debug_section (str
, file
);
3917 load_debug_section (line
, file
);
3919 printf (_("Contents of the %s section:\n\n"), section
->name
);
3923 unsigned int lineno
, version
, flags
;
3924 unsigned int offset_size
= 4;
3925 const unsigned char *string
;
3926 dwarf_vma line_offset
= 0, sec_offset
= curr
- start
, offset
;
3927 unsigned char **extended_ops
= NULL
;
3929 SAFE_BYTE_GET_AND_INC (version
, curr
, 2, end
);
3932 error (_("Only GNU extension to DWARF 4 of %s is currently supported.\n"),
3937 SAFE_BYTE_GET_AND_INC (flags
, curr
, 1, end
);
3940 printf (_(" Offset: 0x%lx\n"),
3941 (unsigned long) sec_offset
);
3942 printf (_(" Version: %d\n"), version
);
3943 printf (_(" Offset size: %d\n"), offset_size
);
3946 SAFE_BYTE_GET_AND_INC (line_offset
, curr
, offset_size
, end
);
3947 printf (_(" Offset into .debug_line: 0x%lx\n"),
3948 (unsigned long) line_offset
);
3952 unsigned int i
, count
, op
;
3955 SAFE_BYTE_GET_AND_INC (count
, curr
, 1, end
);
3957 memset (extended_op_buf
, 0, sizeof (extended_op_buf
));
3958 extended_ops
= extended_op_buf
;
3961 printf (_(" Extension opcode arguments:\n"));
3962 for (i
= 0; i
< count
; i
++)
3964 SAFE_BYTE_GET_AND_INC (op
, curr
, 1, end
);
3965 extended_ops
[op
] = curr
;
3966 nargs
= read_uleb128 (curr
, &bytes_read
, end
);
3969 printf (_(" DW_MACRO_GNU_%02x has no arguments\n"), op
);
3972 printf (_(" DW_MACRO_GNU_%02x arguments: "), op
);
3973 for (n
= 0; n
< nargs
; n
++)
3977 SAFE_BYTE_GET_AND_INC (form
, curr
, 1, end
);
3978 printf ("%s%s", get_FORM_name (form
),
3979 n
== nargs
- 1 ? "\n" : ", ");
3989 case DW_FORM_block1
:
3990 case DW_FORM_block2
:
3991 case DW_FORM_block4
:
3993 case DW_FORM_string
:
3995 case DW_FORM_sec_offset
:
3998 error (_("Invalid extension opcode form %s\n"),
3999 get_FORM_name (form
));
4015 error (_(".debug_macro section not zero terminated\n"));
4019 SAFE_BYTE_GET_AND_INC (op
, curr
, 1, end
);
4025 case DW_MACRO_GNU_start_file
:
4027 unsigned int filenum
;
4028 unsigned char *file_name
= NULL
, *dir_name
= NULL
;
4030 lineno
= read_uleb128 (curr
, &bytes_read
, end
);
4032 filenum
= read_uleb128 (curr
, &bytes_read
, end
);
4035 if ((flags
& 2) == 0)
4036 error (_("DW_MACRO_GNU_start_file used, but no .debug_line offset provided.\n"));
4039 = get_line_filename_and_dirname (line_offset
, filenum
,
4041 if (file_name
== NULL
)
4042 printf (_(" DW_MACRO_GNU_start_file - lineno: %d filenum: %d\n"),
4045 printf (_(" DW_MACRO_GNU_start_file - lineno: %d filenum: %d filename: %s%s%s\n"),
4047 dir_name
!= NULL
? (const char *) dir_name
: "",
4048 dir_name
!= NULL
? "/" : "", file_name
);
4052 case DW_MACRO_GNU_end_file
:
4053 printf (_(" DW_MACRO_GNU_end_file\n"));
4056 case DW_MACRO_GNU_define
:
4057 lineno
= read_uleb128 (curr
, &bytes_read
, end
);
4060 curr
+= strnlen ((char *) string
, end
- string
) + 1;
4061 printf (_(" DW_MACRO_GNU_define - lineno : %d macro : %s\n"),
4065 case DW_MACRO_GNU_undef
:
4066 lineno
= read_uleb128 (curr
, &bytes_read
, end
);
4069 curr
+= strnlen ((char *) string
, end
- string
) + 1;
4070 printf (_(" DW_MACRO_GNU_undef - lineno : %d macro : %s\n"),
4074 case DW_MACRO_GNU_define_indirect
:
4075 lineno
= read_uleb128 (curr
, &bytes_read
, end
);
4077 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
4078 string
= fetch_indirect_string (offset
);
4079 printf (_(" DW_MACRO_GNU_define_indirect - lineno : %d macro : %s\n"),
4083 case DW_MACRO_GNU_undef_indirect
:
4084 lineno
= read_uleb128 (curr
, &bytes_read
, end
);
4086 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
4087 string
= fetch_indirect_string (offset
);
4088 printf (_(" DW_MACRO_GNU_undef_indirect - lineno : %d macro : %s\n"),
4092 case DW_MACRO_GNU_transparent_include
:
4093 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
4094 printf (_(" DW_MACRO_GNU_transparent_include - offset : 0x%lx\n"),
4095 (unsigned long) offset
);
4098 case DW_MACRO_GNU_define_indirect_alt
:
4099 lineno
= read_uleb128 (curr
, &bytes_read
, end
);
4101 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
4102 printf (_(" DW_MACRO_GNU_define_indirect_alt - lineno : %d macro offset : 0x%lx\n"),
4103 lineno
, (unsigned long) offset
);
4106 case DW_MACRO_GNU_undef_indirect_alt
:
4107 lineno
= read_uleb128 (curr
, &bytes_read
, end
);
4109 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
4110 printf (_(" DW_MACRO_GNU_undef_indirect_alt - lineno : %d macro offset : 0x%lx\n"),
4111 lineno
, (unsigned long) offset
);
4114 case DW_MACRO_GNU_transparent_include_alt
:
4115 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
4116 printf (_(" DW_MACRO_GNU_transparent_include_alt - offset : 0x%lx\n"),
4117 (unsigned long) offset
);
4121 if (extended_ops
== NULL
|| extended_ops
[op
] == NULL
)
4123 error (_(" Unknown macro opcode %02x seen\n"), op
);
4128 /* Skip over unhandled opcodes. */
4130 unsigned char *desc
= extended_ops
[op
];
4131 nargs
= read_uleb128 (desc
, &bytes_read
, end
);
4135 printf (_(" DW_MACRO_GNU_%02x\n"), op
);
4138 printf (_(" DW_MACRO_GNU_%02x -"), op
);
4139 for (n
= 0; n
< nargs
; n
++)
4143 SAFE_BYTE_GET_AND_INC (val
, desc
, 1, end
);
4145 = read_and_display_attr_value (0, val
,
4146 curr
, end
, 0, 0, offset_size
,
4147 version
, NULL
, 0, NULL
,
4165 display_debug_abbrev (struct dwarf_section
*section
,
4166 void *file ATTRIBUTE_UNUSED
)
4168 abbrev_entry
*entry
;
4169 unsigned char *start
= section
->start
;
4170 unsigned char *end
= start
+ section
->size
;
4172 printf (_("Contents of the %s section:\n\n"), section
->name
);
4176 unsigned char *last
;
4181 start
= process_abbrev_section (start
, end
);
4183 if (first_abbrev
== NULL
)
4186 printf (_(" Number TAG (0x%lx)\n"), (long) (last
- section
->start
));
4188 for (entry
= first_abbrev
; entry
; entry
= entry
->next
)
4192 printf (" %ld %s [%s]\n",
4194 get_TAG_name (entry
->tag
),
4195 entry
->children
? _("has children") : _("no children"));
4197 for (attr
= entry
->first_attr
; attr
; attr
= attr
->next
)
4198 printf (" %-18s %s\n",
4199 get_AT_name (attr
->attribute
),
4200 get_FORM_name (attr
->form
));
4210 /* Display a location list from a normal (ie, non-dwo) .debug_loc section. */
4213 display_loc_list (struct dwarf_section
*section
,
4214 unsigned char **start_ptr
,
4215 int debug_info_entry
,
4216 unsigned long offset
,
4217 unsigned long base_address
,
4220 unsigned char *start
= *start_ptr
;
4221 unsigned char *section_end
= section
->start
+ section
->size
;
4222 unsigned long cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
4223 unsigned int pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
4224 unsigned int offset_size
= debug_information
[debug_info_entry
].offset_size
;
4225 int dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
4229 unsigned short length
;
4230 int need_frame_base
;
4232 if (pointer_size
< 2 || pointer_size
> 8)
4234 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
4235 pointer_size
, debug_info_entry
);
4241 if (start
+ 2 * pointer_size
> section_end
)
4243 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
4248 printf (" %8.8lx ", offset
+ (start
- *start_ptr
));
4250 /* Note: we use sign extension here in order to be sure that we can detect
4251 the -1 escape value. Sign extension into the top 32 bits of a 32-bit
4252 address will not affect the values that we display since we always show
4253 hex values, and always the bottom 32-bits. */
4254 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, section_end
);
4255 SAFE_BYTE_GET_AND_INC (end
, start
, pointer_size
, section_end
);
4257 if (begin
== 0 && end
== 0)
4259 printf (_("<End of list>\n"));
4263 /* Check base address specifiers. */
4264 if (begin
== (dwarf_vma
) -1 && end
!= (dwarf_vma
) -1)
4267 print_dwarf_vma (begin
, pointer_size
);
4268 print_dwarf_vma (end
, pointer_size
);
4269 printf (_("(base address)\n"));
4273 if (start
+ 2 > section_end
)
4275 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
4280 SAFE_BYTE_GET_AND_INC (length
, start
, 2, section_end
);
4282 if (start
+ length
> section_end
)
4284 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
4289 print_dwarf_vma (begin
+ base_address
, pointer_size
);
4290 print_dwarf_vma (end
+ base_address
, pointer_size
);
4293 need_frame_base
= decode_location_expression (start
,
4298 cu_offset
, section
);
4301 if (need_frame_base
&& !has_frame_base
)
4302 printf (_(" [without DW_AT_frame_base]"));
4305 fputs (_(" (start == end)"), stdout
);
4306 else if (begin
> end
)
4307 fputs (_(" (start > end)"), stdout
);
4317 /* Print a .debug_addr table index in decimal, surrounded by square brackets,
4318 right-adjusted in a field of length LEN, and followed by a space. */
4321 print_addr_index (unsigned int idx
, unsigned int len
)
4323 static char buf
[15];
4324 snprintf (buf
, sizeof (buf
), "[%d]", idx
);
4325 printf ("%*s ", len
, buf
);
4328 /* Display a location list from a .dwo section. It uses address indexes rather
4329 than embedded addresses. This code closely follows display_loc_list, but the
4330 two are sufficiently different that combining things is very ugly. */
4333 display_loc_list_dwo (struct dwarf_section
*section
,
4334 unsigned char **start_ptr
,
4335 int debug_info_entry
,
4336 unsigned long offset
,
4339 unsigned char *start
= *start_ptr
;
4340 unsigned char *section_end
= section
->start
+ section
->size
;
4341 unsigned long cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
4342 unsigned int pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
4343 unsigned int offset_size
= debug_information
[debug_info_entry
].offset_size
;
4344 int dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
4346 unsigned short length
;
4347 int need_frame_base
;
4349 unsigned int bytes_read
;
4351 if (pointer_size
< 2 || pointer_size
> 8)
4353 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
4354 pointer_size
, debug_info_entry
);
4360 printf (" %8.8lx ", offset
+ (start
- *start_ptr
));
4362 if (start
>= section_end
)
4364 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
4369 SAFE_BYTE_GET_AND_INC (entry_type
, start
, 1, section_end
);
4372 case 0: /* A terminating entry. */
4374 printf (_("<End of list>\n"));
4376 case 1: /* A base-address entry. */
4377 idx
= read_uleb128 (start
, &bytes_read
, section_end
);
4378 start
+= bytes_read
;
4379 print_addr_index (idx
, 8);
4381 printf (_("(base address selection entry)\n"));
4383 case 2: /* A start/end entry. */
4384 idx
= read_uleb128 (start
, &bytes_read
, section_end
);
4385 start
+= bytes_read
;
4386 print_addr_index (idx
, 8);
4387 idx
= read_uleb128 (start
, &bytes_read
, section_end
);
4388 start
+= bytes_read
;
4389 print_addr_index (idx
, 8);
4391 case 3: /* A start/length entry. */
4392 idx
= read_uleb128 (start
, &bytes_read
, section_end
);
4393 start
+= bytes_read
;
4394 print_addr_index (idx
, 8);
4395 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
4396 printf ("%08x ", idx
);
4398 case 4: /* An offset pair entry. */
4399 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
4400 printf ("%08x ", idx
);
4401 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
4402 printf ("%08x ", idx
);
4405 warn (_("Unknown location list entry type 0x%x.\n"), entry_type
);
4410 if (start
+ 2 > section_end
)
4412 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
4417 SAFE_BYTE_GET_AND_INC (length
, start
, 2, section_end
);
4418 if (start
+ length
> section_end
)
4420 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
4426 need_frame_base
= decode_location_expression (start
,
4431 cu_offset
, section
);
4434 if (need_frame_base
&& !has_frame_base
)
4435 printf (_(" [without DW_AT_frame_base]"));
4445 /* Sort array of indexes in ascending order of loc_offsets[idx]. */
4447 static dwarf_vma
*loc_offsets
;
4450 loc_offsets_compar (const void *ap
, const void *bp
)
4452 dwarf_vma a
= loc_offsets
[*(const unsigned int *) ap
];
4453 dwarf_vma b
= loc_offsets
[*(const unsigned int *) bp
];
4455 return (a
> b
) - (b
> a
);
4459 display_debug_loc (struct dwarf_section
*section
, void *file
)
4461 unsigned char *start
= section
->start
;
4462 unsigned long bytes
;
4463 unsigned char *section_begin
= start
;
4464 unsigned int num_loc_list
= 0;
4465 unsigned long last_offset
= 0;
4466 unsigned int first
= 0;
4470 int seen_first_offset
= 0;
4471 int locs_sorted
= 1;
4472 unsigned char *next
;
4473 unsigned int *array
= NULL
;
4474 const char *suffix
= strrchr (section
->name
, '.');
4477 if (suffix
&& strcmp (suffix
, ".dwo") == 0)
4480 bytes
= section
->size
;
4484 printf (_("\nThe %s section is empty.\n"), section
->name
);
4488 if (load_debug_info (file
) == 0)
4490 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
4495 /* Check the order of location list in .debug_info section. If
4496 offsets of location lists are in the ascending order, we can
4497 use `debug_information' directly. */
4498 for (i
= 0; i
< num_debug_info_entries
; i
++)
4502 num
= debug_information
[i
].num_loc_offsets
;
4503 if (num
> num_loc_list
)
4506 /* Check if we can use `debug_information' directly. */
4507 if (locs_sorted
&& num
!= 0)
4509 if (!seen_first_offset
)
4511 /* This is the first location list. */
4512 last_offset
= debug_information
[i
].loc_offsets
[0];
4514 seen_first_offset
= 1;
4520 for (; j
< num
; j
++)
4523 debug_information
[i
].loc_offsets
[j
])
4528 last_offset
= debug_information
[i
].loc_offsets
[j
];
4533 if (!seen_first_offset
)
4534 error (_("No location lists in .debug_info section!\n"));
4536 if (debug_information
[first
].num_loc_offsets
> 0
4537 && debug_information
[first
].loc_offsets
[0] != 0)
4538 warn (_("Location lists in %s section start at 0x%s\n"),
4540 dwarf_vmatoa ("x", debug_information
[first
].loc_offsets
[0]));
4543 array
= (unsigned int *) xcmalloc (num_loc_list
, sizeof (unsigned int));
4544 printf (_("Contents of the %s section:\n\n"), section
->name
);
4545 printf (_(" Offset Begin End Expression\n"));
4547 seen_first_offset
= 0;
4548 for (i
= first
; i
< num_debug_info_entries
; i
++)
4550 unsigned long offset
;
4551 unsigned long base_address
;
4556 for (k
= 0; k
< debug_information
[i
].num_loc_offsets
; k
++)
4558 loc_offsets
= debug_information
[i
].loc_offsets
;
4559 qsort (array
, debug_information
[i
].num_loc_offsets
,
4560 sizeof (*array
), loc_offsets_compar
);
4563 for (k
= 0; k
< debug_information
[i
].num_loc_offsets
; k
++)
4565 j
= locs_sorted
? k
: array
[k
];
4567 && debug_information
[i
].loc_offsets
[locs_sorted
4568 ? k
- 1 : array
[k
- 1]]
4569 == debug_information
[i
].loc_offsets
[j
])
4571 has_frame_base
= debug_information
[i
].have_frame_base
[j
];
4572 offset
= debug_information
[i
].loc_offsets
[j
];
4573 next
= section_begin
+ offset
;
4574 base_address
= debug_information
[i
].base_address
;
4576 if (!seen_first_offset
)
4577 seen_first_offset
= 1;
4581 warn (_("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n"),
4582 (unsigned long) (start
- section_begin
),
4583 (unsigned long) (next
- section_begin
));
4584 else if (start
> next
)
4585 warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n"),
4586 (unsigned long) (start
- section_begin
),
4587 (unsigned long) (next
- section_begin
));
4591 if (offset
>= bytes
)
4593 warn (_("Offset 0x%lx is bigger than .debug_loc section size.\n"),
4599 display_loc_list_dwo (section
, &start
, i
, offset
, has_frame_base
);
4601 display_loc_list (section
, &start
, i
, offset
, base_address
,
4606 if (start
< section
->start
+ section
->size
)
4607 warn (_("There are %ld unused bytes at the end of section %s\n"),
4608 (long) (section
->start
+ section
->size
- start
), section
->name
);
4615 display_debug_str (struct dwarf_section
*section
,
4616 void *file ATTRIBUTE_UNUSED
)
4618 unsigned char *start
= section
->start
;
4619 unsigned long bytes
= section
->size
;
4620 dwarf_vma addr
= section
->address
;
4624 printf (_("\nThe %s section is empty.\n"), section
->name
);
4628 printf (_("Contents of the %s section:\n\n"), section
->name
);
4636 lbytes
= (bytes
> 16 ? 16 : bytes
);
4638 printf (" 0x%8.8lx ", (unsigned long) addr
);
4640 for (j
= 0; j
< 16; j
++)
4643 printf ("%2.2x", start
[j
]);
4651 for (j
= 0; j
< lbytes
; j
++)
4654 if (k
>= ' ' && k
< 0x80)
4673 display_debug_info (struct dwarf_section
*section
, void *file
)
4675 return process_debug_info (section
, file
, section
->abbrev_sec
, 0, 0);
4679 display_debug_types (struct dwarf_section
*section
, void *file
)
4681 return process_debug_info (section
, file
, section
->abbrev_sec
, 0, 1);
4685 display_trace_info (struct dwarf_section
*section
, void *file
)
4687 return process_debug_info (section
, file
, section
->abbrev_sec
, 0, 0);
4691 display_debug_aranges (struct dwarf_section
*section
,
4692 void *file ATTRIBUTE_UNUSED
)
4694 unsigned char *start
= section
->start
;
4695 unsigned char *end
= start
+ section
->size
;
4697 printf (_("Contents of the %s section:\n\n"), section
->name
);
4699 /* It does not matter if this load fails,
4700 we test for that later on. */
4701 load_debug_info (file
);
4705 unsigned char *hdrptr
;
4706 DWARF2_Internal_ARange arange
;
4707 unsigned char *addr_ranges
;
4710 unsigned char address_size
;
4712 unsigned int offset_size
;
4713 unsigned int initial_length_size
;
4717 SAFE_BYTE_GET_AND_INC (arange
.ar_length
, hdrptr
, 4, end
);
4718 if (arange
.ar_length
== 0xffffffff)
4720 SAFE_BYTE_GET_AND_INC (arange
.ar_length
, hdrptr
, 8, end
);
4722 initial_length_size
= 12;
4727 initial_length_size
= 4;
4730 SAFE_BYTE_GET_AND_INC (arange
.ar_version
, hdrptr
, 2, end
);
4731 SAFE_BYTE_GET_AND_INC (arange
.ar_info_offset
, hdrptr
, offset_size
, end
);
4733 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
4734 && num_debug_info_entries
> 0
4735 && find_debug_info_for_offset (arange
.ar_info_offset
) == NULL
)
4736 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
4737 (unsigned long) arange
.ar_info_offset
, section
->name
);
4739 SAFE_BYTE_GET_AND_INC (arange
.ar_pointer_size
, hdrptr
, 1, end
);
4740 SAFE_BYTE_GET_AND_INC (arange
.ar_segment_size
, hdrptr
, 1, end
);
4742 if (arange
.ar_version
!= 2 && arange
.ar_version
!= 3)
4744 warn (_("Only DWARF 2 and 3 aranges are currently supported.\n"));
4748 printf (_(" Length: %ld\n"),
4749 (long) arange
.ar_length
);
4750 printf (_(" Version: %d\n"), arange
.ar_version
);
4751 printf (_(" Offset into .debug_info: 0x%lx\n"),
4752 (unsigned long) arange
.ar_info_offset
);
4753 printf (_(" Pointer Size: %d\n"), arange
.ar_pointer_size
);
4754 printf (_(" Segment Size: %d\n"), arange
.ar_segment_size
);
4756 address_size
= arange
.ar_pointer_size
+ arange
.ar_segment_size
;
4758 /* PR 17512: file: 001-108546-0.001:0.1. */
4759 if (address_size
== 0 || address_size
> 8)
4761 error (_("Invalid address size in %s section!\n"),
4766 /* The DWARF spec does not require that the address size be a power
4767 of two, but we do. This will have to change if we ever encounter
4768 an uneven architecture. */
4769 if ((address_size
& (address_size
- 1)) != 0)
4771 warn (_("Pointer size + Segment size is not a power of two.\n"));
4775 if (address_size
> 4)
4776 printf (_("\n Address Length\n"));
4778 printf (_("\n Address Length\n"));
4780 addr_ranges
= hdrptr
;
4782 /* Must pad to an alignment boundary that is twice the address size. */
4783 excess
= (hdrptr
- start
) % (2 * address_size
);
4785 addr_ranges
+= (2 * address_size
) - excess
;
4787 start
+= arange
.ar_length
+ initial_length_size
;
4789 while (addr_ranges
+ 2 * address_size
<= start
)
4791 SAFE_BYTE_GET_AND_INC (address
, addr_ranges
, address_size
, end
);
4792 SAFE_BYTE_GET_AND_INC (length
, addr_ranges
, address_size
, end
);
4795 print_dwarf_vma (address
, address_size
);
4796 print_dwarf_vma (length
, address_size
);
4806 /* Comparison function for qsort. */
4808 comp_addr_base (const void * v0
, const void * v1
)
4810 debug_info
* info0
= (debug_info
*) v0
;
4811 debug_info
* info1
= (debug_info
*) v1
;
4812 return info0
->addr_base
- info1
->addr_base
;
4815 /* Display the debug_addr section. */
4817 display_debug_addr (struct dwarf_section
*section
,
4820 debug_info
**debug_addr_info
;
4821 unsigned char *entry
;
4826 if (section
->size
== 0)
4828 printf (_("\nThe %s section is empty.\n"), section
->name
);
4832 if (load_debug_info (file
) == 0)
4834 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
4839 printf (_("Contents of the %s section:\n\n"), section
->name
);
4841 debug_addr_info
= (debug_info
**) xmalloc ((num_debug_info_entries
+ 1)
4842 * sizeof (debug_info
*));
4845 for (i
= 0; i
< num_debug_info_entries
; i
++)
4847 if (debug_information
[i
].addr_base
!= DEBUG_INFO_UNAVAILABLE
)
4848 debug_addr_info
[count
++] = &debug_information
[i
];
4851 /* Add a sentinel to make iteration convenient. */
4852 debug_addr_info
[count
] = (debug_info
*) xmalloc (sizeof (debug_info
));
4853 debug_addr_info
[count
]->addr_base
= section
->size
;
4855 qsort (debug_addr_info
, count
, sizeof (debug_info
*), comp_addr_base
);
4856 for (i
= 0; i
< count
; i
++)
4859 unsigned int address_size
= debug_addr_info
[i
]->pointer_size
;
4861 printf (_(" For compilation unit at offset 0x%s:\n"),
4862 dwarf_vmatoa ("x", debug_addr_info
[i
]->cu_offset
));
4864 printf (_("\tIndex\tAddress\n"));
4865 entry
= section
->start
+ debug_addr_info
[i
]->addr_base
;
4866 end
= section
->start
+ debug_addr_info
[i
+ 1]->addr_base
;
4870 dwarf_vma base
= byte_get (entry
, address_size
);
4871 printf (_("\t%d:\t"), idx
);
4872 print_dwarf_vma (base
, address_size
);
4874 entry
+= address_size
;
4880 free (debug_addr_info
);
4884 /* Display the .debug_str_offsets and .debug_str_offsets.dwo sections. */
4886 display_debug_str_offsets (struct dwarf_section
*section
,
4887 void *file ATTRIBUTE_UNUSED
)
4889 if (section
->size
== 0)
4891 printf (_("\nThe %s section is empty.\n"), section
->name
);
4894 /* TODO: Dump the contents. This is made somewhat difficult by not knowing
4895 what the offset size is for this section. */
4899 /* Each debug_information[x].range_lists[y] gets this representation for
4900 sorting purposes. */
4904 /* The debug_information[x].range_lists[y] value. */
4905 unsigned long ranges_offset
;
4907 /* Original debug_information to find parameters of the data. */
4908 debug_info
*debug_info_p
;
4911 /* Sort struct range_entry in ascending order of its RANGES_OFFSET. */
4914 range_entry_compar (const void *ap
, const void *bp
)
4916 const struct range_entry
*a_re
= (const struct range_entry
*) ap
;
4917 const struct range_entry
*b_re
= (const struct range_entry
*) bp
;
4918 const unsigned long a
= a_re
->ranges_offset
;
4919 const unsigned long b
= b_re
->ranges_offset
;
4921 return (a
> b
) - (b
> a
);
4925 display_debug_ranges (struct dwarf_section
*section
,
4926 void *file ATTRIBUTE_UNUSED
)
4928 unsigned char *start
= section
->start
;
4929 unsigned char *last_start
= start
;
4930 unsigned long bytes
= section
->size
;
4931 unsigned char *section_begin
= start
;
4932 unsigned char *finish
= start
+ bytes
;
4933 unsigned int num_range_list
, i
;
4934 struct range_entry
*range_entries
, *range_entry_fill
;
4938 printf (_("\nThe %s section is empty.\n"), section
->name
);
4942 if (load_debug_info (file
) == 0)
4944 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
4950 for (i
= 0; i
< num_debug_info_entries
; i
++)
4951 num_range_list
+= debug_information
[i
].num_range_lists
;
4953 if (num_range_list
== 0)
4955 /* This can happen when the file was compiled with -gsplit-debug
4956 which removes references to range lists from the primary .o file. */
4957 printf (_("No range lists in .debug_info section.\n"));
4961 range_entries
= (struct range_entry
*)
4962 xmalloc (sizeof (*range_entries
) * num_range_list
);
4963 range_entry_fill
= range_entries
;
4965 for (i
= 0; i
< num_debug_info_entries
; i
++)
4967 debug_info
*debug_info_p
= &debug_information
[i
];
4970 for (j
= 0; j
< debug_info_p
->num_range_lists
; j
++)
4972 range_entry_fill
->ranges_offset
= debug_info_p
->range_lists
[j
];
4973 range_entry_fill
->debug_info_p
= debug_info_p
;
4978 qsort (range_entries
, num_range_list
, sizeof (*range_entries
),
4979 range_entry_compar
);
4981 if (dwarf_check
!= 0 && range_entries
[0].ranges_offset
!= 0)
4982 warn (_("Range lists in %s section start at 0x%lx\n"),
4983 section
->name
, range_entries
[0].ranges_offset
);
4985 printf (_("Contents of the %s section:\n\n"), section
->name
);
4986 printf (_(" Offset Begin End\n"));
4988 for (i
= 0; i
< num_range_list
; i
++)
4990 struct range_entry
*range_entry
= &range_entries
[i
];
4991 debug_info
*debug_info_p
= range_entry
->debug_info_p
;
4992 unsigned int pointer_size
;
4993 unsigned long offset
;
4994 unsigned char *next
;
4995 unsigned long base_address
;
4997 pointer_size
= debug_info_p
->pointer_size
;
4998 offset
= range_entry
->ranges_offset
;
4999 next
= section_begin
+ offset
;
5000 base_address
= debug_info_p
->base_address
;
5002 /* PR 17512: file: 001-101485-0.001:0.1. */
5003 if (pointer_size
< 2 || pointer_size
> 8)
5005 warn (_("Corrupt pointer size (%d) in debug entry at offset %8.8lx\n"),
5006 pointer_size
, offset
);
5010 if (dwarf_check
!= 0 && i
> 0)
5013 warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"),
5014 (unsigned long) (start
- section_begin
),
5015 (unsigned long) (next
- section_begin
), section
->name
);
5016 else if (start
> next
)
5018 if (next
== last_start
)
5020 warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"),
5021 (unsigned long) (start
- section_begin
),
5022 (unsigned long) (next
- section_begin
), section
->name
);
5028 while (start
< finish
)
5033 /* Note: we use sign extension here in order to be sure that
5034 we can detect the -1 escape value. Sign extension into the
5035 top 32 bits of a 32-bit address will not affect the values
5036 that we display since we always show hex values, and always
5037 the bottom 32-bits. */
5038 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
5039 if (start
>= finish
)
5041 SAFE_SIGNED_BYTE_GET_AND_INC (end
, start
, pointer_size
, finish
);
5043 printf (" %8.8lx ", offset
);
5045 if (begin
== 0 && end
== 0)
5047 printf (_("<End of list>\n"));
5051 /* Check base address specifiers. */
5052 if (begin
== (dwarf_vma
) -1 && end
!= (dwarf_vma
) -1)
5055 print_dwarf_vma (begin
, pointer_size
);
5056 print_dwarf_vma (end
, pointer_size
);
5057 printf ("(base address)\n");
5061 print_dwarf_vma (begin
+ base_address
, pointer_size
);
5062 print_dwarf_vma (end
+ base_address
, pointer_size
);
5065 fputs (_("(start == end)"), stdout
);
5066 else if (begin
> end
)
5067 fputs (_("(start > end)"), stdout
);
5074 free (range_entries
);
5079 typedef struct Frame_Chunk
5081 struct Frame_Chunk
*next
;
5082 unsigned char *chunk_start
;
5084 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
5085 short int *col_type
;
5088 unsigned int code_factor
;
5095 unsigned char fde_encoding
;
5096 unsigned char cfa_exp
;
5097 unsigned char ptr_size
;
5098 unsigned char segment_size
;
5102 static const char *const *dwarf_regnames
;
5103 static unsigned int dwarf_regnames_count
;
5105 /* A marker for a col_type that means this column was never referenced
5106 in the frame info. */
5107 #define DW_CFA_unreferenced (-1)
5109 /* Return 0 if not more space is needed, 1 if more space is needed,
5110 -1 for invalid reg. */
5113 frame_need_space (Frame_Chunk
*fc
, unsigned int reg
)
5115 int prev
= fc
->ncols
;
5117 if (reg
< (unsigned int) fc
->ncols
)
5120 if (dwarf_regnames_count
5121 && reg
> dwarf_regnames_count
)
5124 fc
->ncols
= reg
+ 1;
5125 fc
->col_type
= (short int *) xcrealloc (fc
->col_type
, fc
->ncols
,
5126 sizeof (short int));
5127 fc
->col_offset
= (int *) xcrealloc (fc
->col_offset
, fc
->ncols
, sizeof (int));
5128 /* PR 17512: file:002-10025-0.005. */
5129 if (fc
->col_type
== NULL
|| fc
->col_offset
== NULL
)
5131 error (_("Out of memory allocating %u columns in dwarf frame arrays\n"),
5137 while (prev
< fc
->ncols
)
5139 fc
->col_type
[prev
] = DW_CFA_unreferenced
;
5140 fc
->col_offset
[prev
] = 0;
5146 static const char *const dwarf_regnames_i386
[] =
5148 "eax", "ecx", "edx", "ebx", /* 0 - 3 */
5149 "esp", "ebp", "esi", "edi", /* 4 - 7 */
5150 "eip", "eflags", NULL
, /* 8 - 10 */
5151 "st0", "st1", "st2", "st3", /* 11 - 14 */
5152 "st4", "st5", "st6", "st7", /* 15 - 18 */
5153 NULL
, NULL
, /* 19 - 20 */
5154 "xmm0", "xmm1", "xmm2", "xmm3", /* 21 - 24 */
5155 "xmm4", "xmm5", "xmm6", "xmm7", /* 25 - 28 */
5156 "mm0", "mm1", "mm2", "mm3", /* 29 - 32 */
5157 "mm4", "mm5", "mm6", "mm7", /* 33 - 36 */
5158 "fcw", "fsw", "mxcsr", /* 37 - 39 */
5159 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
, /* 40 - 47 */
5160 "tr", "ldtr", /* 48 - 49 */
5161 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 50 - 57 */
5162 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 58 - 65 */
5163 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 66 - 73 */
5164 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 74 - 81 */
5165 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 82 - 89 */
5166 NULL
, NULL
, NULL
, /* 90 - 92 */
5167 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7" /* 93 - 100 */
5171 init_dwarf_regnames_i386 (void)
5173 dwarf_regnames
= dwarf_regnames_i386
;
5174 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_i386
);
5177 static const char *const dwarf_regnames_x86_64
[] =
5179 "rax", "rdx", "rcx", "rbx",
5180 "rsi", "rdi", "rbp", "rsp",
5181 "r8", "r9", "r10", "r11",
5182 "r12", "r13", "r14", "r15",
5184 "xmm0", "xmm1", "xmm2", "xmm3",
5185 "xmm4", "xmm5", "xmm6", "xmm7",
5186 "xmm8", "xmm9", "xmm10", "xmm11",
5187 "xmm12", "xmm13", "xmm14", "xmm15",
5188 "st0", "st1", "st2", "st3",
5189 "st4", "st5", "st6", "st7",
5190 "mm0", "mm1", "mm2", "mm3",
5191 "mm4", "mm5", "mm6", "mm7",
5193 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
,
5194 "fs.base", "gs.base", NULL
, NULL
,
5196 "mxcsr", "fcw", "fsw",
5197 "xmm16", "xmm17", "xmm18", "xmm19",
5198 "xmm20", "xmm21", "xmm22", "xmm23",
5199 "xmm24", "xmm25", "xmm26", "xmm27",
5200 "xmm28", "xmm29", "xmm30", "xmm31",
5201 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 83 - 90 */
5202 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 91 - 98 */
5203 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 99 - 106 */
5204 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 107 - 114 */
5205 NULL
, NULL
, NULL
, /* 115 - 117 */
5206 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7"
5210 init_dwarf_regnames_x86_64 (void)
5212 dwarf_regnames
= dwarf_regnames_x86_64
;
5213 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_x86_64
);
5216 static const char *const dwarf_regnames_aarch64
[] =
5218 "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7",
5219 "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15",
5220 "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23",
5221 "x24", "x25", "x26", "x27", "x28", "x29", "x30", "sp",
5222 NULL
, "elr", NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
5223 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
5224 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
5225 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
5226 "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7",
5227 "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15",
5228 "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23",
5229 "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31",
5233 init_dwarf_regnames_aarch64 (void)
5235 dwarf_regnames
= dwarf_regnames_aarch64
;
5236 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_aarch64
);
5240 init_dwarf_regnames (unsigned int e_machine
)
5246 init_dwarf_regnames_i386 ();
5252 init_dwarf_regnames_x86_64 ();
5256 init_dwarf_regnames_aarch64 ();
5265 regname (unsigned int regno
, int row
)
5267 static char reg
[64];
5269 && regno
< dwarf_regnames_count
5270 && dwarf_regnames
[regno
] != NULL
)
5273 return dwarf_regnames
[regno
];
5274 snprintf (reg
, sizeof (reg
), "r%d (%s)", regno
,
5275 dwarf_regnames
[regno
]);
5278 snprintf (reg
, sizeof (reg
), "r%d", regno
);
5283 frame_display_row (Frame_Chunk
*fc
, int *need_col_headers
, int *max_regs
)
5288 if (*max_regs
< fc
->ncols
)
5289 *max_regs
= fc
->ncols
;
5291 if (*need_col_headers
)
5293 static const char *sloc
= " LOC";
5295 *need_col_headers
= 0;
5297 printf ("%-*s CFA ", eh_addr_size
* 2, sloc
);
5299 for (r
= 0; r
< *max_regs
; r
++)
5300 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
5305 printf ("%-5s ", regname (r
, 1));
5311 print_dwarf_vma (fc
->pc_begin
, eh_addr_size
);
5313 strcpy (tmp
, "exp");
5315 sprintf (tmp
, "%s%+d", regname (fc
->cfa_reg
, 1), fc
->cfa_offset
);
5316 printf ("%-8s ", tmp
);
5318 for (r
= 0; r
< fc
->ncols
; r
++)
5320 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
5322 switch (fc
->col_type
[r
])
5324 case DW_CFA_undefined
:
5327 case DW_CFA_same_value
:
5331 sprintf (tmp
, "c%+d", fc
->col_offset
[r
]);
5333 case DW_CFA_val_offset
:
5334 sprintf (tmp
, "v%+d", fc
->col_offset
[r
]);
5336 case DW_CFA_register
:
5337 sprintf (tmp
, "%s", regname (fc
->col_offset
[r
], 0));
5339 case DW_CFA_expression
:
5340 strcpy (tmp
, "exp");
5342 case DW_CFA_val_expression
:
5343 strcpy (tmp
, "vexp");
5346 strcpy (tmp
, "n/a");
5349 printf ("%-5s ", tmp
);
5355 #define GET(VAR, N) SAFE_BYTE_GET_AND_INC (VAR, start, N, end)
5356 #define LEB() read_uleb128 (start, & length_return, end); start += length_return
5357 #define SLEB() read_sleb128 (start, & length_return, end); start += length_return
5359 static unsigned char *
5360 read_cie (unsigned char *start
, unsigned char *end
,
5361 Frame_Chunk
**p_cie
, int *p_version
,
5362 unsigned long *p_aug_len
, unsigned char **p_aug
)
5366 unsigned int length_return
;
5367 unsigned char *augmentation_data
= NULL
;
5368 unsigned long augmentation_data_len
= 0;
5371 /* PR 17512: file: 001-228113-0.004. */
5375 fc
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
5376 memset (fc
, 0, sizeof (Frame_Chunk
));
5378 fc
->col_type
= (short int *) xmalloc (sizeof (short int));
5379 fc
->col_offset
= (int *) xmalloc (sizeof (int));
5383 fc
->augmentation
= (char *) start
;
5384 /* PR 17512: file: 001-228113-0.004.
5385 Skip past augmentation name, but avoid running off the end of the data. */
5387 if (* start
++ == '\0')
5391 warn (_("No terminator for augmentation name\n"));
5395 if (strcmp (fc
->augmentation
, "eh") == 0)
5396 start
+= eh_addr_size
;
5400 GET (fc
->ptr_size
, 1);
5401 GET (fc
->segment_size
, 1);
5402 eh_addr_size
= fc
->ptr_size
;
5406 fc
->ptr_size
= eh_addr_size
;
5407 fc
->segment_size
= 0;
5409 fc
->code_factor
= LEB ();
5410 fc
->data_factor
= SLEB ();
5420 if (fc
->augmentation
[0] == 'z')
5422 augmentation_data_len
= LEB ();
5423 augmentation_data
= start
;
5424 start
+= augmentation_data_len
;
5427 if (augmentation_data_len
)
5429 unsigned char *p
, *q
;
5430 p
= (unsigned char *) fc
->augmentation
+ 1;
5431 q
= augmentation_data
;
5438 q
+= 1 + size_of_encoded_value (*q
);
5440 fc
->fde_encoding
= *q
++;
5451 *p_version
= version
;
5454 *p_aug_len
= augmentation_data_len
;
5455 *p_aug
= augmentation_data
;
5461 display_debug_frames (struct dwarf_section
*section
,
5462 void *file ATTRIBUTE_UNUSED
)
5464 unsigned char *start
= section
->start
;
5465 unsigned char *end
= start
+ section
->size
;
5466 unsigned char *section_start
= start
;
5467 Frame_Chunk
*chunks
= 0, *forward_refs
= 0;
5468 Frame_Chunk
*remembered_state
= 0;
5470 int is_eh
= strcmp (section
->name
, ".eh_frame") == 0;
5471 unsigned int length_return
;
5473 const char *bad_reg
= _("bad register: ");
5474 int saved_eh_addr_size
= eh_addr_size
;
5476 printf (_("Contents of the %s section:\n"), section
->name
);
5480 unsigned char *saved_start
;
5481 unsigned char *block_end
;
5486 int need_col_headers
= 1;
5487 unsigned char *augmentation_data
= NULL
;
5488 unsigned long augmentation_data_len
= 0;
5489 unsigned int encoded_ptr_size
= saved_eh_addr_size
;
5490 unsigned int offset_size
;
5491 unsigned int initial_length_size
;
5493 saved_start
= start
;
5495 SAFE_BYTE_GET_AND_INC (length
, start
, 4, end
);
5499 printf ("\n%08lx ZERO terminator\n\n",
5500 (unsigned long)(saved_start
- section_start
));
5501 /* Skip any zero terminators that directly follow.
5502 A corrupt section size could have loaded a whole
5503 slew of zero filled memory bytes. eg
5504 PR 17512: file: 070-19381-0.004. */
5505 while (start
< end
&& * start
== 0)
5510 if (length
== 0xffffffff)
5512 SAFE_BYTE_GET_AND_INC (length
, start
, 8, end
);
5514 initial_length_size
= 12;
5519 initial_length_size
= 4;
5522 block_end
= saved_start
+ length
+ initial_length_size
;
5523 if (block_end
> end
|| block_end
< start
)
5525 warn ("Invalid length 0x%s in FDE at %#08lx\n",
5526 dwarf_vmatoa_1 (NULL
, length
, offset_size
),
5527 (unsigned long) (saved_start
- section_start
));
5531 SAFE_BYTE_GET_AND_INC (cie_id
, start
, offset_size
, end
);
5533 if (is_eh
? (cie_id
== 0) : ((offset_size
== 4 && cie_id
== DW_CIE_ID
)
5534 || (offset_size
== 8 && cie_id
== DW64_CIE_ID
)))
5539 start
= read_cie (start
, end
, &cie
, &version
,
5540 &augmentation_data_len
, &augmentation_data
);
5541 /* PR 17512: file: 027-135133-0.005. */
5547 fc
->chunk_start
= saved_start
;
5548 mreg
= max_regs
- 1;
5551 frame_need_space (fc
, mreg
);
5552 if (fc
->fde_encoding
)
5553 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
5555 printf ("\n%08lx ", (unsigned long) (saved_start
- section_start
));
5556 print_dwarf_vma (length
, fc
->ptr_size
);
5557 print_dwarf_vma (cie_id
, offset_size
);
5559 if (do_debug_frames_interp
)
5561 printf ("CIE \"%s\" cf=%d df=%d ra=%d\n", fc
->augmentation
,
5562 fc
->code_factor
, fc
->data_factor
, fc
->ra
);
5567 printf (" Version: %d\n", version
);
5568 printf (" Augmentation: \"%s\"\n", fc
->augmentation
);
5571 printf (" Pointer Size: %u\n", fc
->ptr_size
);
5572 printf (" Segment Size: %u\n", fc
->segment_size
);
5574 printf (" Code alignment factor: %u\n", fc
->code_factor
);
5575 printf (" Data alignment factor: %d\n", fc
->data_factor
);
5576 printf (" Return address column: %d\n", fc
->ra
);
5578 if (augmentation_data_len
)
5581 printf (" Augmentation data: ");
5582 for (i
= 0; i
< augmentation_data_len
; ++i
)
5583 printf (" %02x", augmentation_data
[i
]);
5591 unsigned char *look_for
;
5592 static Frame_Chunk fde_fc
;
5593 unsigned long segment_selector
;
5597 dwarf_vma sign
= (dwarf_vma
) 1 << (offset_size
* 8 - 1);
5598 look_for
= start
- 4 - ((cie_id
^ sign
) - sign
);
5601 look_for
= section_start
+ cie_id
;
5603 if (look_for
<= saved_start
)
5605 for (cie
= chunks
; cie
; cie
= cie
->next
)
5606 if (cie
->chunk_start
== look_for
)
5611 for (cie
= forward_refs
; cie
; cie
= cie
->next
)
5612 if (cie
->chunk_start
== look_for
)
5616 unsigned int off_size
;
5617 unsigned char *cie_scan
;
5619 cie_scan
= look_for
;
5621 SAFE_BYTE_GET_AND_INC (length
, cie_scan
, 4, end
);
5622 if (length
== 0xffffffff)
5624 SAFE_BYTE_GET_AND_INC (length
, cie_scan
, 8, end
);
5631 SAFE_BYTE_GET_AND_INC (c_id
, cie_scan
, off_size
, end
);
5634 : ((off_size
== 4 && c_id
== DW_CIE_ID
)
5635 || (off_size
== 8 && c_id
== DW64_CIE_ID
)))
5640 read_cie (cie_scan
, end
, &cie
, &version
,
5641 &augmentation_data_len
, &augmentation_data
);
5642 cie
->next
= forward_refs
;
5644 cie
->chunk_start
= look_for
;
5645 mreg
= max_regs
- 1;
5648 frame_need_space (cie
, mreg
);
5649 if (cie
->fde_encoding
)
5651 = size_of_encoded_value (cie
->fde_encoding
);
5658 memset (fc
, 0, sizeof (Frame_Chunk
));
5662 warn ("Invalid CIE pointer 0x%s in FDE at %#08lx\n",
5663 dwarf_vmatoa_1 (NULL
, cie_id
, offset_size
),
5664 (unsigned long) (saved_start
- section_start
));
5666 fc
->col_type
= (short int *) xmalloc (sizeof (short int));
5667 fc
->col_offset
= (int *) xmalloc (sizeof (int));
5668 frame_need_space (fc
, max_regs
- 1);
5670 fc
->augmentation
= "";
5671 fc
->fde_encoding
= 0;
5672 fc
->ptr_size
= eh_addr_size
;
5673 fc
->segment_size
= 0;
5677 fc
->ncols
= cie
->ncols
;
5678 fc
->col_type
= (short int *) xcmalloc (fc
->ncols
, sizeof (short int));
5679 fc
->col_offset
= (int *) xcmalloc (fc
->ncols
, sizeof (int));
5680 memcpy (fc
->col_type
, cie
->col_type
, fc
->ncols
* sizeof (short int));
5681 memcpy (fc
->col_offset
, cie
->col_offset
, fc
->ncols
* sizeof (int));
5682 fc
->augmentation
= cie
->augmentation
;
5683 fc
->ptr_size
= cie
->ptr_size
;
5684 eh_addr_size
= cie
->ptr_size
;
5685 fc
->segment_size
= cie
->segment_size
;
5686 fc
->code_factor
= cie
->code_factor
;
5687 fc
->data_factor
= cie
->data_factor
;
5688 fc
->cfa_reg
= cie
->cfa_reg
;
5689 fc
->cfa_offset
= cie
->cfa_offset
;
5691 frame_need_space (fc
, max_regs
- 1);
5692 fc
->fde_encoding
= cie
->fde_encoding
;
5695 if (fc
->fde_encoding
)
5696 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
5698 segment_selector
= 0;
5699 if (fc
->segment_size
)
5700 SAFE_BYTE_GET_AND_INC (segment_selector
, start
, fc
->segment_size
, end
);
5702 fc
->pc_begin
= get_encoded_value (&start
, fc
->fde_encoding
, section
, end
);
5704 /* FIXME: It appears that sometimes the final pc_range value is
5705 encoded in less than encoded_ptr_size bytes. See the x86_64
5706 run of the "objcopy on compressed debug sections" test for an
5708 SAFE_BYTE_GET_AND_INC (fc
->pc_range
, start
, encoded_ptr_size
, end
);
5710 if (cie
->augmentation
[0] == 'z')
5712 augmentation_data_len
= LEB ();
5713 augmentation_data
= start
;
5714 start
+= augmentation_data_len
;
5715 /* PR 17512: file: 722-8446-0.004. */
5718 warn (_("Corrupt augmentation data length: %lx\n"),
5719 augmentation_data_len
);
5721 augmentation_data
= NULL
;
5722 augmentation_data_len
= 0;
5726 printf ("\n%08lx %s %s FDE cie=%08lx pc=",
5727 (unsigned long)(saved_start
- section_start
),
5728 dwarf_vmatoa_1 (NULL
, length
, fc
->ptr_size
),
5729 dwarf_vmatoa_1 (NULL
, cie_id
, offset_size
),
5730 (unsigned long)(cie
->chunk_start
- section_start
));
5732 if (fc
->segment_size
)
5733 printf ("%04lx:", segment_selector
);
5736 dwarf_vmatoa_1 (NULL
, fc
->pc_begin
, fc
->ptr_size
),
5737 dwarf_vmatoa_1 (NULL
, fc
->pc_begin
+ fc
->pc_range
, fc
->ptr_size
));
5739 if (! do_debug_frames_interp
&& augmentation_data_len
)
5743 printf (" Augmentation data: ");
5744 for (i
= 0; i
< augmentation_data_len
; ++i
)
5745 printf (" %02x", augmentation_data
[i
]);
5751 /* At this point, fc is the current chunk, cie (if any) is set, and
5752 we're about to interpret instructions for the chunk. */
5753 /* ??? At present we need to do this always, since this sizes the
5754 fc->col_type and fc->col_offset arrays, which we write into always.
5755 We should probably split the interpreted and non-interpreted bits
5756 into two different routines, since there's so much that doesn't
5757 really overlap between them. */
5758 if (1 || do_debug_frames_interp
)
5760 /* Start by making a pass over the chunk, allocating storage
5761 and taking note of what registers are used. */
5762 unsigned char *tmp
= start
;
5764 while (start
< block_end
)
5766 unsigned int reg
, op
, opa
;
5774 /* Warning: if you add any more cases to this switch, be
5775 sure to add them to the corresponding switch below. */
5778 case DW_CFA_advance_loc
:
5782 if (frame_need_space (fc
, opa
) >= 0)
5783 fc
->col_type
[opa
] = DW_CFA_undefined
;
5785 case DW_CFA_restore
:
5786 if (frame_need_space (fc
, opa
) >= 0)
5787 fc
->col_type
[opa
] = DW_CFA_undefined
;
5789 case DW_CFA_set_loc
:
5790 start
+= encoded_ptr_size
;
5792 case DW_CFA_advance_loc1
:
5795 case DW_CFA_advance_loc2
:
5798 case DW_CFA_advance_loc4
:
5801 case DW_CFA_offset_extended
:
5802 case DW_CFA_val_offset
:
5803 reg
= LEB (); LEB ();
5804 if (frame_need_space (fc
, reg
) >= 0)
5805 fc
->col_type
[reg
] = DW_CFA_undefined
;
5807 case DW_CFA_restore_extended
:
5809 frame_need_space (fc
, reg
);
5810 if (frame_need_space (fc
, reg
) >= 0)
5811 fc
->col_type
[reg
] = DW_CFA_undefined
;
5813 case DW_CFA_undefined
:
5815 if (frame_need_space (fc
, reg
) >= 0)
5816 fc
->col_type
[reg
] = DW_CFA_undefined
;
5818 case DW_CFA_same_value
:
5820 if (frame_need_space (fc
, reg
) >= 0)
5821 fc
->col_type
[reg
] = DW_CFA_undefined
;
5823 case DW_CFA_register
:
5824 reg
= LEB (); LEB ();
5825 if (frame_need_space (fc
, reg
) >= 0)
5826 fc
->col_type
[reg
] = DW_CFA_undefined
;
5828 case DW_CFA_def_cfa
:
5831 case DW_CFA_def_cfa_register
:
5834 case DW_CFA_def_cfa_offset
:
5837 case DW_CFA_def_cfa_expression
:
5839 if (start
+ temp
< start
)
5841 warn (_("Corrupt CFA_def expression value: %lu\n"), temp
);
5847 case DW_CFA_expression
:
5848 case DW_CFA_val_expression
:
5851 if (start
+ temp
< start
)
5853 /* PR 17512: file:306-192417-0.005. */
5854 warn (_("Corrupt CFA expression value: %lu\n"), temp
);
5859 if (frame_need_space (fc
, reg
) >= 0)
5860 fc
->col_type
[reg
] = DW_CFA_undefined
;
5862 case DW_CFA_offset_extended_sf
:
5863 case DW_CFA_val_offset_sf
:
5864 reg
= LEB (); SLEB ();
5865 if (frame_need_space (fc
, reg
) >= 0)
5866 fc
->col_type
[reg
] = DW_CFA_undefined
;
5868 case DW_CFA_def_cfa_sf
:
5871 case DW_CFA_def_cfa_offset_sf
:
5874 case DW_CFA_MIPS_advance_loc8
:
5877 case DW_CFA_GNU_args_size
:
5880 case DW_CFA_GNU_negative_offset_extended
:
5881 reg
= LEB (); LEB ();
5882 if (frame_need_space (fc
, reg
) >= 0)
5883 fc
->col_type
[reg
] = DW_CFA_undefined
;
5892 /* Now we know what registers are used, make a second pass over
5893 the chunk, this time actually printing out the info. */
5895 while (start
< block_end
)
5898 unsigned long ul
, reg
, roffs
;
5902 const char *reg_prefix
= "";
5909 /* Warning: if you add any more cases to this switch, be
5910 sure to add them to the corresponding switch above. */
5913 case DW_CFA_advance_loc
:
5914 if (do_debug_frames_interp
)
5915 frame_display_row (fc
, &need_col_headers
, &max_regs
);
5917 printf (" DW_CFA_advance_loc: %d to %s\n",
5918 opa
* fc
->code_factor
,
5919 dwarf_vmatoa_1 (NULL
,
5920 fc
->pc_begin
+ opa
* fc
->code_factor
,
5922 fc
->pc_begin
+= opa
* fc
->code_factor
;
5927 if (opa
>= (unsigned int) fc
->ncols
)
5928 reg_prefix
= bad_reg
;
5929 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
5930 printf (" DW_CFA_offset: %s%s at cfa%+ld\n",
5931 reg_prefix
, regname (opa
, 0),
5932 roffs
* fc
->data_factor
);
5933 if (*reg_prefix
== '\0')
5935 fc
->col_type
[opa
] = DW_CFA_offset
;
5936 fc
->col_offset
[opa
] = roffs
* fc
->data_factor
;
5940 case DW_CFA_restore
:
5941 if (opa
>= (unsigned int) cie
->ncols
5942 || opa
>= (unsigned int) fc
->ncols
)
5943 reg_prefix
= bad_reg
;
5944 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
5945 printf (" DW_CFA_restore: %s%s\n",
5946 reg_prefix
, regname (opa
, 0));
5947 if (*reg_prefix
== '\0')
5949 fc
->col_type
[opa
] = cie
->col_type
[opa
];
5950 fc
->col_offset
[opa
] = cie
->col_offset
[opa
];
5951 if (do_debug_frames_interp
5952 && fc
->col_type
[opa
] == DW_CFA_unreferenced
)
5953 fc
->col_type
[opa
] = DW_CFA_undefined
;
5957 case DW_CFA_set_loc
:
5958 vma
= get_encoded_value (&start
, fc
->fde_encoding
, section
, block_end
);
5959 if (do_debug_frames_interp
)
5960 frame_display_row (fc
, &need_col_headers
, &max_regs
);
5962 printf (" DW_CFA_set_loc: %s\n",
5963 dwarf_vmatoa_1 (NULL
, vma
, fc
->ptr_size
));
5967 case DW_CFA_advance_loc1
:
5968 SAFE_BYTE_GET_AND_INC (ofs
, start
, 1, end
);
5969 if (do_debug_frames_interp
)
5970 frame_display_row (fc
, &need_col_headers
, &max_regs
);
5972 printf (" DW_CFA_advance_loc1: %ld to %s\n",
5973 (unsigned long) (ofs
* fc
->code_factor
),
5974 dwarf_vmatoa_1 (NULL
,
5975 fc
->pc_begin
+ ofs
* fc
->code_factor
,
5977 fc
->pc_begin
+= ofs
* fc
->code_factor
;
5980 case DW_CFA_advance_loc2
:
5981 SAFE_BYTE_GET_AND_INC (ofs
, start
, 2, block_end
);
5982 if (do_debug_frames_interp
)
5983 frame_display_row (fc
, &need_col_headers
, &max_regs
);
5985 printf (" DW_CFA_advance_loc2: %ld to %s\n",
5986 (unsigned long) (ofs
* fc
->code_factor
),
5987 dwarf_vmatoa_1 (NULL
,
5988 fc
->pc_begin
+ ofs
* fc
->code_factor
,
5990 fc
->pc_begin
+= ofs
* fc
->code_factor
;
5993 case DW_CFA_advance_loc4
:
5994 SAFE_BYTE_GET_AND_INC (ofs
, start
, 4, block_end
);
5995 if (do_debug_frames_interp
)
5996 frame_display_row (fc
, &need_col_headers
, &max_regs
);
5998 printf (" DW_CFA_advance_loc4: %ld to %s\n",
5999 (unsigned long) (ofs
* fc
->code_factor
),
6000 dwarf_vmatoa_1 (NULL
,
6001 fc
->pc_begin
+ ofs
* fc
->code_factor
,
6003 fc
->pc_begin
+= ofs
* fc
->code_factor
;
6006 case DW_CFA_offset_extended
:
6009 if (reg
>= (unsigned int) fc
->ncols
)
6010 reg_prefix
= bad_reg
;
6011 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
6012 printf (" DW_CFA_offset_extended: %s%s at cfa%+ld\n",
6013 reg_prefix
, regname (reg
, 0),
6014 roffs
* fc
->data_factor
);
6015 if (*reg_prefix
== '\0')
6017 fc
->col_type
[reg
] = DW_CFA_offset
;
6018 fc
->col_offset
[reg
] = roffs
* fc
->data_factor
;
6022 case DW_CFA_val_offset
:
6025 if (reg
>= (unsigned int) fc
->ncols
)
6026 reg_prefix
= bad_reg
;
6027 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
6028 printf (" DW_CFA_val_offset: %s%s at cfa%+ld\n",
6029 reg_prefix
, regname (reg
, 0),
6030 roffs
* fc
->data_factor
);
6031 if (*reg_prefix
== '\0')
6033 fc
->col_type
[reg
] = DW_CFA_val_offset
;
6034 fc
->col_offset
[reg
] = roffs
* fc
->data_factor
;
6038 case DW_CFA_restore_extended
:
6040 if (reg
>= (unsigned int) cie
->ncols
6041 || reg
>= (unsigned int) fc
->ncols
)
6042 reg_prefix
= bad_reg
;
6043 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
6044 printf (" DW_CFA_restore_extended: %s%s\n",
6045 reg_prefix
, regname (reg
, 0));
6046 if (*reg_prefix
== '\0')
6048 fc
->col_type
[reg
] = cie
->col_type
[reg
];
6049 fc
->col_offset
[reg
] = cie
->col_offset
[reg
];
6053 case DW_CFA_undefined
:
6055 if (reg
>= (unsigned int) fc
->ncols
)
6056 reg_prefix
= bad_reg
;
6057 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
6058 printf (" DW_CFA_undefined: %s%s\n",
6059 reg_prefix
, regname (reg
, 0));
6060 if (*reg_prefix
== '\0')
6062 fc
->col_type
[reg
] = DW_CFA_undefined
;
6063 fc
->col_offset
[reg
] = 0;
6067 case DW_CFA_same_value
:
6069 if (reg
>= (unsigned int) fc
->ncols
)
6070 reg_prefix
= bad_reg
;
6071 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
6072 printf (" DW_CFA_same_value: %s%s\n",
6073 reg_prefix
, regname (reg
, 0));
6074 if (*reg_prefix
== '\0')
6076 fc
->col_type
[reg
] = DW_CFA_same_value
;
6077 fc
->col_offset
[reg
] = 0;
6081 case DW_CFA_register
:
6084 if (reg
>= (unsigned int) fc
->ncols
)
6085 reg_prefix
= bad_reg
;
6086 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
6088 printf (" DW_CFA_register: %s%s in ",
6089 reg_prefix
, regname (reg
, 0));
6090 puts (regname (roffs
, 0));
6092 if (*reg_prefix
== '\0')
6094 fc
->col_type
[reg
] = DW_CFA_register
;
6095 fc
->col_offset
[reg
] = roffs
;
6099 case DW_CFA_remember_state
:
6100 if (! do_debug_frames_interp
)
6101 printf (" DW_CFA_remember_state\n");
6102 rs
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
6103 rs
->cfa_offset
= fc
->cfa_offset
;
6104 rs
->cfa_reg
= fc
->cfa_reg
;
6106 rs
->cfa_exp
= fc
->cfa_exp
;
6107 rs
->ncols
= fc
->ncols
;
6108 rs
->col_type
= (short int *) xcmalloc (rs
->ncols
,
6109 sizeof (* rs
->col_type
));
6110 rs
->col_offset
= (int *) xcmalloc (rs
->ncols
, sizeof (* rs
->col_offset
));
6111 memcpy (rs
->col_type
, fc
->col_type
, rs
->ncols
* sizeof (* fc
->col_type
));
6112 memcpy (rs
->col_offset
, fc
->col_offset
, rs
->ncols
* sizeof (* fc
->col_offset
));
6113 rs
->next
= remembered_state
;
6114 remembered_state
= rs
;
6117 case DW_CFA_restore_state
:
6118 if (! do_debug_frames_interp
)
6119 printf (" DW_CFA_restore_state\n");
6120 rs
= remembered_state
;
6123 remembered_state
= rs
->next
;
6124 fc
->cfa_offset
= rs
->cfa_offset
;
6125 fc
->cfa_reg
= rs
->cfa_reg
;
6127 fc
->cfa_exp
= rs
->cfa_exp
;
6128 frame_need_space (fc
, rs
->ncols
- 1);
6129 memcpy (fc
->col_type
, rs
->col_type
, rs
->ncols
* sizeof (* rs
->col_type
));
6130 memcpy (fc
->col_offset
, rs
->col_offset
,
6131 rs
->ncols
* sizeof (* rs
->col_offset
));
6132 free (rs
->col_type
);
6133 free (rs
->col_offset
);
6136 else if (do_debug_frames_interp
)
6137 printf ("Mismatched DW_CFA_restore_state\n");
6140 case DW_CFA_def_cfa
:
6141 fc
->cfa_reg
= LEB ();
6142 fc
->cfa_offset
= LEB ();
6144 if (! do_debug_frames_interp
)
6145 printf (" DW_CFA_def_cfa: %s ofs %d\n",
6146 regname (fc
->cfa_reg
, 0), fc
->cfa_offset
);
6149 case DW_CFA_def_cfa_register
:
6150 fc
->cfa_reg
= LEB ();
6152 if (! do_debug_frames_interp
)
6153 printf (" DW_CFA_def_cfa_register: %s\n",
6154 regname (fc
->cfa_reg
, 0));
6157 case DW_CFA_def_cfa_offset
:
6158 fc
->cfa_offset
= LEB ();
6159 if (! do_debug_frames_interp
)
6160 printf (" DW_CFA_def_cfa_offset: %d\n", fc
->cfa_offset
);
6164 if (! do_debug_frames_interp
)
6165 printf (" DW_CFA_nop\n");
6168 case DW_CFA_def_cfa_expression
:
6170 if (start
>= block_end
)
6172 printf (" DW_CFA_def_cfa_expression: <corrupt>\n");
6173 warn (_("Corrupt length field in DW_CFA_def_cfa_expression\n"));
6176 if (! do_debug_frames_interp
)
6178 printf (" DW_CFA_def_cfa_expression (");
6179 decode_location_expression (start
, eh_addr_size
, 0, -1,
6187 case DW_CFA_expression
:
6190 if (reg
>= (unsigned int) fc
->ncols
)
6191 reg_prefix
= bad_reg
;
6192 /* PR 17512: file: 069-133014-0.006. */
6193 if (start
>= block_end
)
6195 printf (" DW_CFA_expression: <corrupt>\n");
6196 warn (_("Corrupt length field in DW_CFA_expression\n"));
6199 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
6201 printf (" DW_CFA_expression: %s%s (",
6202 reg_prefix
, regname (reg
, 0));
6203 decode_location_expression (start
, eh_addr_size
, 0, -1,
6207 if (*reg_prefix
== '\0')
6208 fc
->col_type
[reg
] = DW_CFA_expression
;
6212 case DW_CFA_val_expression
:
6215 if (reg
>= (unsigned int) fc
->ncols
)
6216 reg_prefix
= bad_reg
;
6217 if (start
>= block_end
)
6219 printf (" DW_CFA_val_expression: <corrupt>\n");
6220 warn (_("Corrupt length field in DW_CFA_val_expression\n"));
6223 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
6225 printf (" DW_CFA_val_expression: %s%s (",
6226 reg_prefix
, regname (reg
, 0));
6227 decode_location_expression (start
, eh_addr_size
, 0, -1,
6231 if (*reg_prefix
== '\0')
6232 fc
->col_type
[reg
] = DW_CFA_val_expression
;
6236 case DW_CFA_offset_extended_sf
:
6239 if (frame_need_space (fc
, reg
) < 0)
6240 reg_prefix
= bad_reg
;
6241 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
6242 printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+ld\n",
6243 reg_prefix
, regname (reg
, 0),
6244 l
* fc
->data_factor
);
6245 if (*reg_prefix
== '\0')
6247 fc
->col_type
[reg
] = DW_CFA_offset
;
6248 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
6252 case DW_CFA_val_offset_sf
:
6255 if (frame_need_space (fc
, reg
) < 0)
6256 reg_prefix
= bad_reg
;
6257 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
6258 printf (" DW_CFA_val_offset_sf: %s%s at cfa%+ld\n",
6259 reg_prefix
, regname (reg
, 0),
6260 l
* fc
->data_factor
);
6261 if (*reg_prefix
== '\0')
6263 fc
->col_type
[reg
] = DW_CFA_val_offset
;
6264 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
6268 case DW_CFA_def_cfa_sf
:
6269 fc
->cfa_reg
= LEB ();
6270 fc
->cfa_offset
= SLEB ();
6271 fc
->cfa_offset
= fc
->cfa_offset
* fc
->data_factor
;
6273 if (! do_debug_frames_interp
)
6274 printf (" DW_CFA_def_cfa_sf: %s ofs %d\n",
6275 regname (fc
->cfa_reg
, 0), fc
->cfa_offset
);
6278 case DW_CFA_def_cfa_offset_sf
:
6279 fc
->cfa_offset
= SLEB ();
6280 fc
->cfa_offset
= fc
->cfa_offset
* fc
->data_factor
;
6281 if (! do_debug_frames_interp
)
6282 printf (" DW_CFA_def_cfa_offset_sf: %d\n", fc
->cfa_offset
);
6285 case DW_CFA_MIPS_advance_loc8
:
6286 SAFE_BYTE_GET_AND_INC (ofs
, start
, 8, block_end
);
6287 if (do_debug_frames_interp
)
6288 frame_display_row (fc
, &need_col_headers
, &max_regs
);
6290 printf (" DW_CFA_MIPS_advance_loc8: %ld to %s\n",
6291 (unsigned long) (ofs
* fc
->code_factor
),
6292 dwarf_vmatoa_1 (NULL
,
6293 fc
->pc_begin
+ ofs
* fc
->code_factor
,
6295 fc
->pc_begin
+= ofs
* fc
->code_factor
;
6298 case DW_CFA_GNU_window_save
:
6299 if (! do_debug_frames_interp
)
6300 printf (" DW_CFA_GNU_window_save\n");
6303 case DW_CFA_GNU_args_size
:
6305 if (! do_debug_frames_interp
)
6306 printf (" DW_CFA_GNU_args_size: %ld\n", ul
);
6309 case DW_CFA_GNU_negative_offset_extended
:
6312 if (frame_need_space (fc
, reg
) < 0)
6313 reg_prefix
= bad_reg
;
6314 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
6315 printf (" DW_CFA_GNU_negative_offset_extended: %s%s at cfa%+ld\n",
6316 reg_prefix
, regname (reg
, 0),
6317 l
* fc
->data_factor
);
6318 if (*reg_prefix
== '\0')
6320 fc
->col_type
[reg
] = DW_CFA_offset
;
6321 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
6326 if (op
>= DW_CFA_lo_user
&& op
<= DW_CFA_hi_user
)
6327 printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op
);
6329 warn (_("Unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op
);
6334 if (do_debug_frames_interp
)
6335 frame_display_row (fc
, &need_col_headers
, &max_regs
);
6338 eh_addr_size
= saved_eh_addr_size
;
6351 display_gdb_index (struct dwarf_section
*section
,
6352 void *file ATTRIBUTE_UNUSED
)
6354 unsigned char *start
= section
->start
;
6356 uint32_t cu_list_offset
, tu_list_offset
;
6357 uint32_t address_table_offset
, symbol_table_offset
, constant_pool_offset
;
6358 unsigned int cu_list_elements
, tu_list_elements
;
6359 unsigned int address_table_size
, symbol_table_slots
;
6360 unsigned char *cu_list
, *tu_list
;
6361 unsigned char *address_table
, *symbol_table
, *constant_pool
;
6364 /* The documentation for the format of this file is in gdb/dwarf2read.c. */
6366 printf (_("Contents of the %s section:\n"), section
->name
);
6368 if (section
->size
< 6 * sizeof (uint32_t))
6370 warn (_("Truncated header in the %s section.\n"), section
->name
);
6374 version
= byte_get_little_endian (start
, 4);
6375 printf (_("Version %ld\n"), (long) version
);
6377 /* Prior versions are obsolete, and future versions may not be
6378 backwards compatible. */
6379 if (version
< 3 || version
> 8)
6381 warn (_("Unsupported version %lu.\n"), (unsigned long) version
);
6385 warn (_("The address table data in version 3 may be wrong.\n"));
6387 warn (_("Version 4 does not support case insensitive lookups.\n"));
6389 warn (_("Version 5 does not include inlined functions.\n"));
6391 warn (_("Version 6 does not include symbol attributes.\n"));
6392 /* Version 7 indices generated by Gold have bad type unit references,
6393 PR binutils/15021. But we don't know if the index was generated by
6394 Gold or not, so to avoid worrying users with gdb-generated indices
6395 we say nothing for version 7 here. */
6397 cu_list_offset
= byte_get_little_endian (start
+ 4, 4);
6398 tu_list_offset
= byte_get_little_endian (start
+ 8, 4);
6399 address_table_offset
= byte_get_little_endian (start
+ 12, 4);
6400 symbol_table_offset
= byte_get_little_endian (start
+ 16, 4);
6401 constant_pool_offset
= byte_get_little_endian (start
+ 20, 4);
6403 if (cu_list_offset
> section
->size
6404 || tu_list_offset
> section
->size
6405 || address_table_offset
> section
->size
6406 || symbol_table_offset
> section
->size
6407 || constant_pool_offset
> section
->size
)
6409 warn (_("Corrupt header in the %s section.\n"), section
->name
);
6413 cu_list_elements
= (tu_list_offset
- cu_list_offset
) / 8;
6414 tu_list_elements
= (address_table_offset
- tu_list_offset
) / 8;
6415 address_table_size
= symbol_table_offset
- address_table_offset
;
6416 symbol_table_slots
= (constant_pool_offset
- symbol_table_offset
) / 8;
6418 cu_list
= start
+ cu_list_offset
;
6419 tu_list
= start
+ tu_list_offset
;
6420 address_table
= start
+ address_table_offset
;
6421 symbol_table
= start
+ symbol_table_offset
;
6422 constant_pool
= start
+ constant_pool_offset
;
6424 printf (_("\nCU table:\n"));
6425 for (i
= 0; i
< cu_list_elements
; i
+= 2)
6427 uint64_t cu_offset
= byte_get_little_endian (cu_list
+ i
* 8, 8);
6428 uint64_t cu_length
= byte_get_little_endian (cu_list
+ i
* 8 + 8, 8);
6430 printf (_("[%3u] 0x%lx - 0x%lx\n"), i
/ 2,
6431 (unsigned long) cu_offset
,
6432 (unsigned long) (cu_offset
+ cu_length
- 1));
6435 printf (_("\nTU table:\n"));
6436 for (i
= 0; i
< tu_list_elements
; i
+= 3)
6438 uint64_t tu_offset
= byte_get_little_endian (tu_list
+ i
* 8, 8);
6439 uint64_t type_offset
= byte_get_little_endian (tu_list
+ i
* 8 + 8, 8);
6440 uint64_t signature
= byte_get_little_endian (tu_list
+ i
* 8 + 16, 8);
6442 printf (_("[%3u] 0x%lx 0x%lx "), i
/ 3,
6443 (unsigned long) tu_offset
,
6444 (unsigned long) type_offset
);
6445 print_dwarf_vma (signature
, 8);
6449 printf (_("\nAddress table:\n"));
6450 for (i
= 0; i
< address_table_size
; i
+= 2 * 8 + 4)
6452 uint64_t low
= byte_get_little_endian (address_table
+ i
, 8);
6453 uint64_t high
= byte_get_little_endian (address_table
+ i
+ 8, 8);
6454 uint32_t cu_index
= byte_get_little_endian (address_table
+ i
+ 16, 4);
6456 print_dwarf_vma (low
, 8);
6457 print_dwarf_vma (high
, 8);
6458 printf (_("%lu\n"), (unsigned long) cu_index
);
6461 printf (_("\nSymbol table:\n"));
6462 for (i
= 0; i
< symbol_table_slots
; ++i
)
6464 uint32_t name_offset
= byte_get_little_endian (symbol_table
+ i
* 8, 4);
6465 uint32_t cu_vector_offset
= byte_get_little_endian (symbol_table
+ i
* 8 + 4, 4);
6466 uint32_t num_cus
, cu
;
6468 if (name_offset
!= 0
6469 || cu_vector_offset
!= 0)
6473 printf ("[%3u] %s:", i
, constant_pool
+ name_offset
);
6474 num_cus
= byte_get_little_endian (constant_pool
+ cu_vector_offset
, 4);
6477 for (j
= 0; j
< num_cus
; ++j
)
6480 gdb_index_symbol_kind kind
;
6482 cu
= byte_get_little_endian (constant_pool
+ cu_vector_offset
+ 4 + j
* 4, 4);
6483 is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu
);
6484 kind
= GDB_INDEX_SYMBOL_KIND_VALUE (cu
);
6485 cu
= GDB_INDEX_CU_VALUE (cu
);
6486 /* Convert to TU number if it's for a type unit. */
6487 if (cu
>= cu_list_elements
/ 2)
6488 printf ("%cT%lu", num_cus
> 1 ? '\t' : ' ',
6489 (unsigned long) (cu
- cu_list_elements
/ 2));
6491 printf ("%c%lu", num_cus
> 1 ? '\t' : ' ', (unsigned long) cu
);
6493 printf (" [%s, %s]",
6494 is_static
? _("static") : _("global"),
6495 get_gdb_index_symbol_kind_name (kind
));
6507 /* Pre-allocate enough space for the CU/TU sets needed. */
6510 prealloc_cu_tu_list (unsigned int nshndx
)
6512 if (shndx_pool
== NULL
)
6514 shndx_pool_size
= nshndx
;
6515 shndx_pool_used
= 0;
6516 shndx_pool
= (unsigned int *) xcmalloc (shndx_pool_size
,
6517 sizeof (unsigned int));
6521 shndx_pool_size
= shndx_pool_used
+ nshndx
;
6522 shndx_pool
= (unsigned int *) xcrealloc (shndx_pool
, shndx_pool_size
,
6523 sizeof (unsigned int));
6528 add_shndx_to_cu_tu_entry (unsigned int shndx
)
6530 if (shndx_pool_used
>= shndx_pool_size
)
6532 error (_("Internal error: out of space in the shndx pool.\n"));
6535 shndx_pool
[shndx_pool_used
++] = shndx
;
6539 end_cu_tu_entry (void)
6541 if (shndx_pool_used
>= shndx_pool_size
)
6543 error (_("Internal error: out of space in the shndx pool.\n"));
6546 shndx_pool
[shndx_pool_used
++] = 0;
6549 /* Return the short name of a DWARF section given by a DW_SECT enumerator. */
6552 get_DW_SECT_short_name (unsigned int dw_sect
)
6554 static char buf
[16];
6562 case DW_SECT_ABBREV
:
6568 case DW_SECT_STR_OFFSETS
:
6570 case DW_SECT_MACINFO
:
6578 snprintf (buf
, sizeof (buf
), "%d", dw_sect
);
6582 /* Process a CU or TU index. If DO_DISPLAY is true, print the contents.
6583 These sections are extensions for Fission.
6584 See http://gcc.gnu.org/wiki/DebugFissionDWP. */
6587 process_cu_tu_index (struct dwarf_section
*section
, int do_display
)
6589 unsigned char *phdr
= section
->start
;
6590 unsigned char *limit
= phdr
+ section
->size
;
6591 unsigned char *phash
;
6592 unsigned char *pindex
;
6593 unsigned char *ppool
;
6594 unsigned int version
;
6595 unsigned int ncols
= 0;
6597 unsigned int nslots
;
6600 dwarf_vma signature_high
;
6601 dwarf_vma signature_low
;
6604 /* PR 17512: file: 002-168123-0.004. */
6607 warn (_("Section %s is empty\n"), section
->name
);
6610 /* PR 17512: file: 002-376-0.004. */
6611 if (section
->size
< 24)
6613 warn (_("Section %s is too small to contain a CU/TU header"),
6618 SAFE_BYTE_GET (version
, phdr
, 4, limit
);
6620 SAFE_BYTE_GET (ncols
, phdr
+ 4, 4, limit
);
6621 SAFE_BYTE_GET (nused
, phdr
+ 8, 4, limit
);
6622 SAFE_BYTE_GET (nslots
, phdr
+ 12, 4, limit
);
6625 pindex
= phash
+ nslots
* 8;
6626 ppool
= pindex
+ nslots
* 4;
6630 printf (_("Contents of the %s section:\n\n"), section
->name
);
6631 printf (_(" Version: %d\n"), version
);
6633 printf (_(" Number of columns: %d\n"), ncols
);
6634 printf (_(" Number of used entries: %d\n"), nused
);
6635 printf (_(" Number of slots: %d\n\n"), nslots
);
6640 warn (_("Section %s too small for %d hash table entries\n"),
6641 section
->name
, nslots
);
6648 prealloc_cu_tu_list ((limit
- ppool
) / 4);
6649 for (i
= 0; i
< nslots
; i
++)
6651 unsigned char *shndx_list
;
6654 SAFE_BYTE_GET64 (phash
, &signature_high
, &signature_low
, limit
);
6655 if (signature_high
!= 0 || signature_low
!= 0)
6657 SAFE_BYTE_GET (j
, pindex
, 4, limit
);
6658 shndx_list
= ppool
+ j
* 4;
6660 printf (_(" [%3d] Signature: 0x%s Sections: "),
6661 i
, dwarf_vmatoa64 (signature_high
, signature_low
,
6662 buf
, sizeof (buf
)));
6665 if (shndx_list
>= limit
)
6667 warn (_("Section %s too small for shndx pool\n"),
6671 SAFE_BYTE_GET (shndx
, shndx_list
, 4, limit
);
6675 printf (" %d", shndx
);
6677 add_shndx_to_cu_tu_entry (shndx
);
6689 else if (version
== 2)
6692 unsigned int dw_sect
;
6693 unsigned char *ph
= phash
;
6694 unsigned char *pi
= pindex
;
6695 unsigned char *poffsets
= ppool
+ ncols
* 4;
6696 unsigned char *psizes
= poffsets
+ nused
* ncols
* 4;
6697 unsigned char *pend
= psizes
+ nused
* ncols
* 4;
6698 bfd_boolean is_tu_index
;
6699 struct cu_tu_set
*this_set
= NULL
;
6701 unsigned char *prow
;
6703 is_tu_index
= strcmp (section
->name
, ".debug_tu_index") == 0;
6707 warn (_("Section %s too small for offset and size tables\n"),
6714 printf (_(" Offset table\n"));
6715 printf (" slot %-16s ",
6716 is_tu_index
? _("signature") : _("dwo_id"));
6723 tu_sets
= xcmalloc (nused
, sizeof (struct cu_tu_set
));
6729 cu_sets
= xcmalloc (nused
, sizeof (struct cu_tu_set
));
6736 for (j
= 0; j
< ncols
; j
++)
6738 SAFE_BYTE_GET (dw_sect
, ppool
+ j
* 4, 4, limit
);
6739 printf (" %8s", get_DW_SECT_short_name (dw_sect
));
6744 for (i
= 0; i
< nslots
; i
++)
6746 SAFE_BYTE_GET64 (ph
, &signature_high
, &signature_low
, limit
);
6748 SAFE_BYTE_GET (row
, pi
, 4, limit
);
6752 memcpy (&this_set
[row
- 1].signature
, ph
, sizeof (uint64_t));
6754 prow
= poffsets
+ (row
- 1) * ncols
* 4;
6757 printf (_(" [%3d] 0x%s"),
6758 i
, dwarf_vmatoa64 (signature_high
, signature_low
,
6759 buf
, sizeof (buf
)));
6760 for (j
= 0; j
< ncols
; j
++)
6762 SAFE_BYTE_GET (val
, prow
+ j
* 4, 4, limit
);
6764 printf (" %8d", val
);
6767 SAFE_BYTE_GET (dw_sect
, ppool
+ j
* 4, 4, limit
);
6768 this_set
[row
- 1].section_offsets
[dw_sect
] = val
;
6784 printf (_(" Size table\n"));
6785 printf (" slot %-16s ",
6786 is_tu_index
? _("signature") : _("dwo_id"));
6789 for (j
= 0; j
< ncols
; j
++)
6791 SAFE_BYTE_GET (val
, ppool
+ j
* 4, 4, limit
);
6793 printf (" %8s", get_DW_SECT_short_name (val
));
6799 for (i
= 0; i
< nslots
; i
++)
6801 SAFE_BYTE_GET64 (ph
, &signature_high
, &signature_low
, limit
);
6803 SAFE_BYTE_GET (row
, pi
, 4, limit
);
6806 prow
= psizes
+ (row
- 1) * ncols
* 4;
6809 printf (_(" [%3d] 0x%s"),
6810 i
, dwarf_vmatoa64 (signature_high
, signature_low
,
6811 buf
, sizeof (buf
)));
6813 for (j
= 0; j
< ncols
; j
++)
6815 SAFE_BYTE_GET (val
, prow
+ j
* 4, 4, limit
);
6817 printf (" %8d", val
);
6820 SAFE_BYTE_GET (dw_sect
, ppool
+ j
* 4, 4, limit
);
6821 this_set
[row
- 1].section_sizes
[dw_sect
] = val
;
6833 else if (do_display
)
6834 printf (_(" Unsupported version (%d)\n"), version
);
6842 /* Load the CU and TU indexes if present. This will build a list of
6843 section sets that we can use to associate a .debug_info.dwo section
6844 with its associated .debug_abbrev.dwo section in a .dwp file. */
6847 load_cu_tu_indexes (void *file
)
6849 /* If we have already loaded (or tried to load) the CU and TU indexes
6850 then do not bother to repeat the task. */
6851 if (cu_tu_indexes_read
)
6854 if (load_debug_section (dwp_cu_index
, file
))
6855 process_cu_tu_index (&debug_displays
[dwp_cu_index
].section
, 0);
6857 if (load_debug_section (dwp_tu_index
, file
))
6858 process_cu_tu_index (&debug_displays
[dwp_tu_index
].section
, 0);
6860 cu_tu_indexes_read
= 1;
6863 /* Find the set of sections that includes section SHNDX. */
6866 find_cu_tu_set (void *file
, unsigned int shndx
)
6870 load_cu_tu_indexes (file
);
6872 /* Find SHNDX in the shndx pool. */
6873 for (i
= 0; i
< shndx_pool_used
; i
++)
6874 if (shndx_pool
[i
] == shndx
)
6877 if (i
>= shndx_pool_used
)
6880 /* Now backup to find the first entry in the set. */
6881 while (i
> 0 && shndx_pool
[i
- 1] != 0)
6884 return shndx_pool
+ i
;
6887 /* Display a .debug_cu_index or .debug_tu_index section. */
6890 display_cu_index (struct dwarf_section
*section
, void *file ATTRIBUTE_UNUSED
)
6892 return process_cu_tu_index (section
, 1);
6896 display_debug_not_supported (struct dwarf_section
*section
,
6897 void *file ATTRIBUTE_UNUSED
)
6899 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
6906 cmalloc (size_t nmemb
, size_t size
)
6908 /* Check for overflow. */
6909 if (nmemb
>= ~(size_t) 0 / size
)
6912 return malloc (nmemb
* size
);
6916 xcmalloc (size_t nmemb
, size_t size
)
6918 /* Check for overflow. */
6919 if (nmemb
>= ~(size_t) 0 / size
)
6922 return xmalloc (nmemb
* size
);
6926 xcrealloc (void *ptr
, size_t nmemb
, size_t size
)
6928 /* Check for overflow. */
6929 if (nmemb
>= ~(size_t) 0 / size
)
6932 return xrealloc (ptr
, nmemb
* size
);
6936 free_debug_memory (void)
6942 for (i
= 0; i
< max
; i
++)
6943 free_debug_section ((enum dwarf_section_display_enum
) i
);
6945 if (debug_information
!= NULL
)
6947 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
)
6949 for (i
= 0; i
< num_debug_info_entries
; i
++)
6951 if (!debug_information
[i
].max_loc_offsets
)
6953 free (debug_information
[i
].loc_offsets
);
6954 free (debug_information
[i
].have_frame_base
);
6956 if (!debug_information
[i
].max_range_lists
)
6957 free (debug_information
[i
].range_lists
);
6961 free (debug_information
);
6962 debug_information
= NULL
;
6963 num_debug_info_entries
= 0;
6968 dwarf_select_sections_by_names (const char *names
)
6972 const char * option
;
6976 debug_dump_long_opts
;
6978 static const debug_dump_long_opts opts_table
[] =
6980 /* Please keep this table alpha- sorted. */
6981 { "Ranges", & do_debug_ranges
, 1 },
6982 { "abbrev", & do_debug_abbrevs
, 1 },
6983 { "addr", & do_debug_addr
, 1 },
6984 { "aranges", & do_debug_aranges
, 1 },
6985 { "cu_index", & do_debug_cu_index
, 1 },
6986 { "decodedline", & do_debug_lines
, FLAG_DEBUG_LINES_DECODED
},
6987 { "frames", & do_debug_frames
, 1 },
6988 { "frames-interp", & do_debug_frames_interp
, 1 },
6989 /* The special .gdb_index section. */
6990 { "gdb_index", & do_gdb_index
, 1 },
6991 { "info", & do_debug_info
, 1 },
6992 { "line", & do_debug_lines
, FLAG_DEBUG_LINES_RAW
}, /* For backwards compatibility. */
6993 { "loc", & do_debug_loc
, 1 },
6994 { "macro", & do_debug_macinfo
, 1 },
6995 { "pubnames", & do_debug_pubnames
, 1 },
6996 { "pubtypes", & do_debug_pubtypes
, 1 },
6997 /* This entry is for compatability
6998 with earlier versions of readelf. */
6999 { "ranges", & do_debug_aranges
, 1 },
7000 { "rawline", & do_debug_lines
, FLAG_DEBUG_LINES_RAW
},
7001 { "str", & do_debug_str
, 1 },
7002 /* These trace_* sections are used by Itanium VMS. */
7003 { "trace_abbrev", & do_trace_abbrevs
, 1 },
7004 { "trace_aranges", & do_trace_aranges
, 1 },
7005 { "trace_info", & do_trace_info
, 1 },
7014 const debug_dump_long_opts
* entry
;
7016 for (entry
= opts_table
; entry
->option
; entry
++)
7018 size_t len
= strlen (entry
->option
);
7020 if (strncmp (p
, entry
->option
, len
) == 0
7021 && (p
[len
] == ',' || p
[len
] == '\0'))
7023 * entry
->variable
|= entry
->val
;
7025 /* The --debug-dump=frames-interp option also
7026 enables the --debug-dump=frames option. */
7027 if (do_debug_frames_interp
)
7028 do_debug_frames
= 1;
7035 if (entry
->option
== NULL
)
7037 warn (_("Unrecognized debug option '%s'\n"), p
);
7038 p
= strchr (p
, ',');
7049 dwarf_select_sections_by_letters (const char *letters
)
7051 unsigned int lindex
= 0;
7053 while (letters
[lindex
])
7054 switch (letters
[lindex
++])
7061 do_debug_abbrevs
= 1;
7065 do_debug_lines
|= FLAG_DEBUG_LINES_RAW
;
7069 do_debug_lines
|= FLAG_DEBUG_LINES_DECODED
;
7073 do_debug_pubnames
= 1;
7077 do_debug_pubtypes
= 1;
7081 do_debug_aranges
= 1;
7085 do_debug_ranges
= 1;
7089 do_debug_frames_interp
= 1;
7091 do_debug_frames
= 1;
7095 do_debug_macinfo
= 1;
7107 warn (_("Unrecognized debug option '%s'\n"), optarg
);
7113 dwarf_select_sections_all (void)
7116 do_debug_abbrevs
= 1;
7117 do_debug_lines
= FLAG_DEBUG_LINES_RAW
;
7118 do_debug_pubnames
= 1;
7119 do_debug_pubtypes
= 1;
7120 do_debug_aranges
= 1;
7121 do_debug_ranges
= 1;
7122 do_debug_frames
= 1;
7123 do_debug_macinfo
= 1;
7128 do_trace_abbrevs
= 1;
7129 do_trace_aranges
= 1;
7131 do_debug_cu_index
= 1;
7134 struct dwarf_section_display debug_displays
[] =
7136 { { ".debug_abbrev", ".zdebug_abbrev", NULL
, NULL
, 0, 0, 0 },
7137 display_debug_abbrev
, &do_debug_abbrevs
, 0 },
7138 { { ".debug_aranges", ".zdebug_aranges", NULL
, NULL
, 0, 0, 0 },
7139 display_debug_aranges
, &do_debug_aranges
, 1 },
7140 { { ".debug_frame", ".zdebug_frame", NULL
, NULL
, 0, 0, 0 },
7141 display_debug_frames
, &do_debug_frames
, 1 },
7142 { { ".debug_info", ".zdebug_info", NULL
, NULL
, 0, 0, abbrev
},
7143 display_debug_info
, &do_debug_info
, 1 },
7144 { { ".debug_line", ".zdebug_line", NULL
, NULL
, 0, 0, 0 },
7145 display_debug_lines
, &do_debug_lines
, 1 },
7146 { { ".debug_pubnames", ".zdebug_pubnames", NULL
, NULL
, 0, 0, 0 },
7147 display_debug_pubnames
, &do_debug_pubnames
, 0 },
7148 { { ".debug_gnu_pubnames", ".zdebug_gnu_pubnames", NULL
, NULL
, 0, 0, 0 },
7149 display_debug_gnu_pubnames
, &do_debug_pubnames
, 0 },
7150 { { ".eh_frame", "", NULL
, NULL
, 0, 0, 0 },
7151 display_debug_frames
, &do_debug_frames
, 1 },
7152 { { ".debug_macinfo", ".zdebug_macinfo", NULL
, NULL
, 0, 0, 0 },
7153 display_debug_macinfo
, &do_debug_macinfo
, 0 },
7154 { { ".debug_macro", ".zdebug_macro", NULL
, NULL
, 0, 0, 0 },
7155 display_debug_macro
, &do_debug_macinfo
, 1 },
7156 { { ".debug_str", ".zdebug_str", NULL
, NULL
, 0, 0, 0 },
7157 display_debug_str
, &do_debug_str
, 0 },
7158 { { ".debug_loc", ".zdebug_loc", NULL
, NULL
, 0, 0, 0 },
7159 display_debug_loc
, &do_debug_loc
, 1 },
7160 { { ".debug_pubtypes", ".zdebug_pubtypes", NULL
, NULL
, 0, 0, 0 },
7161 display_debug_pubnames
, &do_debug_pubtypes
, 0 },
7162 { { ".debug_gnu_pubtypes", ".zdebug_gnu_pubtypes", NULL
, NULL
, 0, 0, 0 },
7163 display_debug_gnu_pubnames
, &do_debug_pubtypes
, 0 },
7164 { { ".debug_ranges", ".zdebug_ranges", NULL
, NULL
, 0, 0, 0 },
7165 display_debug_ranges
, &do_debug_ranges
, 1 },
7166 { { ".debug_static_func", ".zdebug_static_func", NULL
, NULL
, 0, 0, 0 },
7167 display_debug_not_supported
, NULL
, 0 },
7168 { { ".debug_static_vars", ".zdebug_static_vars", NULL
, NULL
, 0, 0, 0 },
7169 display_debug_not_supported
, NULL
, 0 },
7170 { { ".debug_types", ".zdebug_types", NULL
, NULL
, 0, 0, abbrev
},
7171 display_debug_types
, &do_debug_info
, 1 },
7172 { { ".debug_weaknames", ".zdebug_weaknames", NULL
, NULL
, 0, 0, 0 },
7173 display_debug_not_supported
, NULL
, 0 },
7174 { { ".gdb_index", "", NULL
, NULL
, 0, 0, 0 },
7175 display_gdb_index
, &do_gdb_index
, 0 },
7176 { { ".trace_info", "", NULL
, NULL
, 0, 0, trace_abbrev
},
7177 display_trace_info
, &do_trace_info
, 1 },
7178 { { ".trace_abbrev", "", NULL
, NULL
, 0, 0, 0 },
7179 display_debug_abbrev
, &do_trace_abbrevs
, 0 },
7180 { { ".trace_aranges", "", NULL
, NULL
, 0, 0, 0 },
7181 display_debug_aranges
, &do_trace_aranges
, 0 },
7182 { { ".debug_info.dwo", ".zdebug_info.dwo", NULL
, NULL
, 0, 0, abbrev_dwo
},
7183 display_debug_info
, &do_debug_info
, 1 },
7184 { { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo", NULL
, NULL
, 0, 0, 0 },
7185 display_debug_abbrev
, &do_debug_abbrevs
, 0 },
7186 { { ".debug_types.dwo", ".zdebug_types.dwo", NULL
, NULL
, 0, 0, abbrev_dwo
},
7187 display_debug_types
, &do_debug_info
, 1 },
7188 { { ".debug_line.dwo", ".zdebug_line.dwo", NULL
, NULL
, 0, 0, 0 },
7189 display_debug_lines
, &do_debug_lines
, 1 },
7190 { { ".debug_loc.dwo", ".zdebug_loc.dwo", NULL
, NULL
, 0, 0, 0 },
7191 display_debug_loc
, &do_debug_loc
, 1 },
7192 { { ".debug_macro.dwo", ".zdebug_macro.dwo", NULL
, NULL
, 0, 0, 0 },
7193 display_debug_macro
, &do_debug_macinfo
, 1 },
7194 { { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo", NULL
, NULL
, 0, 0, 0 },
7195 display_debug_macinfo
, &do_debug_macinfo
, 0 },
7196 { { ".debug_str.dwo", ".zdebug_str.dwo", NULL
, NULL
, 0, 0, 0 },
7197 display_debug_str
, &do_debug_str
, 1 },
7198 { { ".debug_str_offsets", ".zdebug_str_offsets", NULL
, NULL
, 0, 0, 0 },
7199 display_debug_str_offsets
, NULL
, 0 },
7200 { { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo", NULL
, NULL
, 0, 0, 0 },
7201 display_debug_str_offsets
, NULL
, 0 },
7202 { { ".debug_addr", ".zdebug_addr", NULL
, NULL
, 0, 0, 0 },
7203 display_debug_addr
, &do_debug_addr
, 1 },
7204 { { ".debug_cu_index", "", NULL
, NULL
, 0, 0, 0 },
7205 display_cu_index
, &do_debug_cu_index
, 0 },
7206 { { ".debug_tu_index", "", NULL
, NULL
, 0, 0, 0 },
7207 display_cu_index
, &do_debug_cu_index
, 0 },