1 /* dwarf.c -- display DWARF contents of a BFD binary file
2 Copyright 2005-2013 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 #if !HAVE_DECL_STRNLEN
33 size_t strnlen (const char *, size_t);
36 static const char *regname (unsigned int regno
, int row
);
38 static int have_frame_base
;
39 static int need_base_address
;
41 static unsigned int last_pointer_size
= 0;
42 static int warned_about_missing_comp_units
= FALSE
;
44 static unsigned int num_debug_info_entries
= 0;
45 static debug_info
*debug_information
= NULL
;
46 /* Special value for num_debug_info_entries to indicate
47 that the .debug_info section could not be loaded/parsed. */
48 #define DEBUG_INFO_UNAVAILABLE (unsigned int) -1
55 int do_debug_pubnames
;
56 int do_debug_pubtypes
;
60 int do_debug_frames_interp
;
69 int do_debug_cu_index
;
72 int dwarf_cutoff_level
= -1;
73 unsigned long dwarf_start_die
;
77 /* Collection of CU/TU section sets from .debug_cu_index and .debug_tu_index
78 sections. For version 1 package files, each set is stored in SHNDX_POOL
79 as a zero-terminated list of section indexes comprising one set of debug
80 sections from a .dwo file. */
82 static int cu_tu_indexes_read
= 0;
83 static unsigned int *shndx_pool
= NULL
;
84 static unsigned int shndx_pool_size
= 0;
85 static unsigned int shndx_pool_used
= 0;
87 /* For version 2 package files, each set contains an array of section offsets
88 and an array of section sizes, giving the offset and size of the
89 contribution from a CU or TU within one of the debug sections.
90 When displaying debug info from a package file, we need to use these
91 tables to locate the corresponding contributions to each section. */
96 dwarf_vma section_offsets
[DW_SECT_MAX
];
97 size_t section_sizes
[DW_SECT_MAX
];
100 static int cu_count
= 0;
101 static int tu_count
= 0;
102 static struct cu_tu_set
*cu_sets
= NULL
;
103 static struct cu_tu_set
*tu_sets
= NULL
;
105 static void load_cu_tu_indexes (void *file
);
107 /* Values for do_debug_lines. */
108 #define FLAG_DEBUG_LINES_RAW 1
109 #define FLAG_DEBUG_LINES_DECODED 2
112 size_of_encoded_value (int encoding
)
114 switch (encoding
& 0x7)
117 case 0: return eh_addr_size
;
125 get_encoded_value (unsigned char *data
,
127 struct dwarf_section
*section
)
129 int size
= size_of_encoded_value (encoding
);
132 if (encoding
& DW_EH_PE_signed
)
133 val
= byte_get_signed (data
, size
);
135 val
= byte_get (data
, size
);
137 if ((encoding
& 0x70) == DW_EH_PE_pcrel
)
138 val
+= section
->address
+ (data
- section
->start
);
142 #if __STDC_VERSION__ >= 199901L || (defined(__GNUC__) && __GNUC__ >= 2)
144 #define DWARF_VMA_FMT "ll"
145 #define DWARF_VMA_FMT_LONG "%16.16llx"
147 #define DWARF_VMA_FMT "I64"
148 #define DWARF_VMA_FMT_LONG "%016I64x"
151 #define DWARF_VMA_FMT "l"
152 #define DWARF_VMA_FMT_LONG "%16.16lx"
155 /* Convert a dwarf vma value into a string. Returns a pointer to a static
156 buffer containing the converted VALUE. The value is converted according
157 to the printf formating character FMTCH. If NUM_BYTES is non-zero then
158 it specifies the maximum number of bytes to be displayed in the converted
159 value and FMTCH is ignored - hex is always used. */
162 dwarf_vmatoa_1 (const char *fmtch
, dwarf_vma value
, unsigned num_bytes
)
164 /* As dwarf_vmatoa is used more then once in a printf call
165 for output, we are cycling through an fixed array of pointers
166 for return address. */
167 static int buf_pos
= 0;
168 static struct dwarf_vmatoa_buf
174 ret
= buf
[buf_pos
++].place
;
175 buf_pos
%= ARRAY_SIZE (buf
);
179 /* Printf does not have a way of specifiying a maximum field width for an
180 integer value, so we print the full value into a buffer and then select
181 the precision we need. */
182 snprintf (ret
, sizeof (buf
[0].place
), DWARF_VMA_FMT_LONG
, value
);
185 return ret
+ (16 - 2 * num_bytes
);
191 sprintf (fmt
, "%%%s%s", DWARF_VMA_FMT
, fmtch
);
192 snprintf (ret
, sizeof (buf
[0].place
), fmt
, value
);
197 static inline const char *
198 dwarf_vmatoa (const char * fmtch
, dwarf_vma value
)
200 return dwarf_vmatoa_1 (fmtch
, value
, 0);
203 /* Print a dwarf_vma value (typically an address, offset or length) in
204 hexadecimal format, followed by a space. The length of the VALUE (and
205 hence the precision displayed) is determined by the NUM_BYTES parameter. */
208 print_dwarf_vma (dwarf_vma value
, unsigned num_bytes
)
210 printf ("%s ", dwarf_vmatoa_1 (NULL
, value
, num_bytes
));
213 /* Format a 64-bit value, given as two 32-bit values, in hex.
214 For reentrancy, this uses a buffer provided by the caller. */
217 dwarf_vmatoa64 (dwarf_vma hvalue
, dwarf_vma lvalue
, char *buf
,
218 unsigned int buf_len
)
223 snprintf (buf
, buf_len
, "%" DWARF_VMA_FMT
"x", lvalue
);
226 len
= snprintf (buf
, buf_len
, "%" DWARF_VMA_FMT
"x", hvalue
);
227 snprintf (buf
+ len
, buf_len
- len
,
228 "%08" DWARF_VMA_FMT
"x", lvalue
);
234 /* Read in a LEB128 encoded value starting at address DATA.
235 If SIGN is true, return a signed LEB128 value.
236 If LENGTH_RETURN is not NULL, return in it the number of bytes read.
237 No bytes will be read at address END or beyond. */
240 read_leb128 (unsigned char *data
,
241 unsigned int *length_return
,
243 const unsigned char * const end
)
245 dwarf_vma result
= 0;
246 unsigned int num_read
= 0;
247 unsigned int shift
= 0;
248 unsigned char byte
= 0;
255 result
|= ((dwarf_vma
) (byte
& 0x7f)) << shift
;
258 if ((byte
& 0x80) == 0)
262 if (length_return
!= NULL
)
263 *length_return
= num_read
;
265 if (sign
&& (shift
< 8 * sizeof (result
)) && (byte
& 0x40))
266 result
|= -1L << shift
;
271 /* Create a signed version to avoid painful typecasts. */
272 static inline dwarf_signed_vma
273 read_sleb128 (unsigned char * data
,
274 unsigned int * length_return
,
275 const unsigned char * const end
)
277 return (dwarf_signed_vma
) read_leb128 (data
, length_return
, TRUE
, end
);
280 static inline dwarf_vma
281 read_uleb128 (unsigned char * data
,
282 unsigned int * length_return
,
283 const unsigned char * const end
)
285 return read_leb128 (data
, length_return
, FALSE
, end
);
288 #define SAFE_BYTE_GET(VAL, PTR, AMOUNT, END) \
291 int dummy [sizeof (VAL) < (AMOUNT) ? -1 : 1] ATTRIBUTE_UNUSED ; \
292 unsigned int amount = (AMOUNT); \
293 if (((PTR) + amount) >= (END)) \
296 amount = (END) - (PTR); \
301 VAL = byte_get ((PTR), amount); \
307 #define SAFE_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \
310 SAFE_BYTE_GET (VAL, PTR, AMOUNT, END); \
315 #define SAFE_SIGNED_BYTE_GET(VAL, PTR, AMOUNT, END) \
318 unsigned int amount = (AMOUNT); \
319 if (((PTR) + amount) >= (END)) \
322 amount = (END) - (PTR); \
327 VAL = byte_get_signed ((PTR), amount); \
333 #define SAFE_SIGNED_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \
336 SAFE_SIGNED_BYTE_GET (VAL, PTR, AMOUNT, END); \
341 #define SAFE_BYTE_GET64(PTR, HIGH, LOW, END) \
344 if (((PTR) + 8) <= (END)) \
346 byte_get_64 ((PTR), (HIGH), (LOW)); \
350 * (LOW) = * (HIGH) = 0; \
355 typedef struct State_Machine_Registers
363 unsigned char op_index
;
364 unsigned char end_sequence
;
365 /* This variable hold the number of the last entry seen
366 in the File Table. */
367 unsigned int last_file_entry
;
370 static SMR state_machine_regs
;
373 reset_state_machine (int is_stmt
)
375 state_machine_regs
.address
= 0;
376 state_machine_regs
.op_index
= 0;
377 state_machine_regs
.file
= 1;
378 state_machine_regs
.line
= 1;
379 state_machine_regs
.column
= 0;
380 state_machine_regs
.is_stmt
= is_stmt
;
381 state_machine_regs
.basic_block
= 0;
382 state_machine_regs
.end_sequence
= 0;
383 state_machine_regs
.last_file_entry
= 0;
386 /* Handled an extend line op.
387 Returns the number of bytes read. */
390 process_extended_line_op (unsigned char * data
,
394 unsigned char op_code
;
395 unsigned int bytes_read
;
398 unsigned char *orig_data
= data
;
401 len
= read_uleb128 (data
, & bytes_read
, end
);
404 if (len
== 0 || data
== end
)
406 warn (_("badly formed extended line op encountered!\n"));
413 printf (_(" Extended opcode %d: "), op_code
);
417 case DW_LNE_end_sequence
:
418 printf (_("End of Sequence\n\n"));
419 reset_state_machine (is_stmt
);
422 case DW_LNE_set_address
:
423 SAFE_BYTE_GET (adr
, data
, len
- bytes_read
- 1, end
);
424 printf (_("set Address to 0x%s\n"), dwarf_vmatoa ("x", adr
));
425 state_machine_regs
.address
= adr
;
426 state_machine_regs
.op_index
= 0;
429 case DW_LNE_define_file
:
430 printf (_("define new File Table entry\n"));
431 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
432 printf (" %d\t", ++state_machine_regs
.last_file_entry
);
435 data
+= strnlen ((char *) data
, end
- data
) + 1;
436 printf ("%s\t", dwarf_vmatoa ("u", read_uleb128 (data
, & bytes_read
, end
)));
438 printf ("%s\t", dwarf_vmatoa ("u", read_uleb128 (data
, & bytes_read
, end
)));
440 printf ("%s\t", dwarf_vmatoa ("u", read_uleb128 (data
, & bytes_read
, end
)));
442 printf ("%s\n\n", name
);
444 if (((unsigned int) (data
- orig_data
) != len
) || data
== end
)
445 warn (_("DW_LNE_define_file: Bad opcode length\n"));
448 case DW_LNE_set_discriminator
:
449 printf (_("set Discriminator to %s\n"),
450 dwarf_vmatoa ("u", read_uleb128 (data
, & bytes_read
, end
)));
454 case DW_LNE_HP_negate_is_UV_update
:
455 printf ("DW_LNE_HP_negate_is_UV_update\n");
457 case DW_LNE_HP_push_context
:
458 printf ("DW_LNE_HP_push_context\n");
460 case DW_LNE_HP_pop_context
:
461 printf ("DW_LNE_HP_pop_context\n");
463 case DW_LNE_HP_set_file_line_column
:
464 printf ("DW_LNE_HP_set_file_line_column\n");
466 case DW_LNE_HP_set_routine_name
:
467 printf ("DW_LNE_HP_set_routine_name\n");
469 case DW_LNE_HP_set_sequence
:
470 printf ("DW_LNE_HP_set_sequence\n");
472 case DW_LNE_HP_negate_post_semantics
:
473 printf ("DW_LNE_HP_negate_post_semantics\n");
475 case DW_LNE_HP_negate_function_exit
:
476 printf ("DW_LNE_HP_negate_function_exit\n");
478 case DW_LNE_HP_negate_front_end_logical
:
479 printf ("DW_LNE_HP_negate_front_end_logical\n");
481 case DW_LNE_HP_define_proc
:
482 printf ("DW_LNE_HP_define_proc\n");
484 case DW_LNE_HP_source_file_correlation
:
486 unsigned char *edata
= data
+ len
- bytes_read
- 1;
488 printf ("DW_LNE_HP_source_file_correlation\n");
494 opc
= read_uleb128 (data
, & bytes_read
, edata
);
499 case DW_LNE_HP_SFC_formfeed
:
500 printf (" DW_LNE_HP_SFC_formfeed\n");
502 case DW_LNE_HP_SFC_set_listing_line
:
503 printf (" DW_LNE_HP_SFC_set_listing_line (%s)\n",
505 read_uleb128 (data
, & bytes_read
, edata
)));
508 case DW_LNE_HP_SFC_associate
:
509 printf (" DW_LNE_HP_SFC_associate ");
512 read_uleb128 (data
, & bytes_read
, edata
)));
516 read_uleb128 (data
, & bytes_read
, edata
)));
520 read_uleb128 (data
, & bytes_read
, edata
)));
524 printf (_(" UNKNOWN DW_LNE_HP_SFC opcode (%u)\n"), opc
);
534 unsigned int rlen
= len
- bytes_read
- 1;
536 if (op_code
>= DW_LNE_lo_user
537 /* The test against DW_LNW_hi_user is redundant due to
538 the limited range of the unsigned char data type used
540 /*&& op_code <= DW_LNE_hi_user*/)
541 printf (_("user defined: "));
543 printf (_("UNKNOWN: "));
544 printf (_("length %d ["), rlen
);
546 printf (" %02x", *data
++);
555 static const unsigned char *
556 fetch_indirect_string (dwarf_vma offset
)
558 struct dwarf_section
*section
= &debug_displays
[str
].section
;
560 if (section
->start
== NULL
)
561 return (const unsigned char *) _("<no .debug_str section>");
563 /* DWARF sections under Mach-O have non-zero addresses. */
564 offset
-= section
->address
;
565 if (offset
> section
->size
)
567 warn (_("DW_FORM_strp offset too big: %s\n"),
568 dwarf_vmatoa ("x", offset
));
569 return (const unsigned char *) _("<offset is too big>");
572 return (const unsigned char *) section
->start
+ offset
;
576 fetch_indexed_string (dwarf_vma idx
, struct cu_tu_set
*this_set
,
577 dwarf_vma offset_size
, int dwo
)
579 enum dwarf_section_display_enum str_sec_idx
= dwo
? str_dwo
: str
;
580 enum dwarf_section_display_enum idx_sec_idx
= dwo
? str_index_dwo
: str_index
;
581 struct dwarf_section
*index_section
= &debug_displays
[idx_sec_idx
].section
;
582 struct dwarf_section
*str_section
= &debug_displays
[str_sec_idx
].section
;
583 dwarf_vma index_offset
= idx
* offset_size
;
584 dwarf_vma str_offset
;
586 if (index_section
->start
== NULL
)
587 return (dwo
? _("<no .debug_str_offsets.dwo section>")
588 : _("<no .debug_str_offsets section>"));
590 /* DWARF sections under Mach-O have non-zero addresses. */
591 index_offset
-= index_section
->address
;
592 if (this_set
!= NULL
)
593 index_offset
+= this_set
->section_offsets
[DW_SECT_STR_OFFSETS
];
594 if (index_offset
> index_section
->size
)
596 warn (_("DW_FORM_GNU_str_index offset too big: %s\n"),
597 dwarf_vmatoa ("x", index_offset
));
598 return _("<index offset is too big>");
601 if (str_section
->start
== NULL
)
602 return (dwo
? _("<no .debug_str.dwo section>")
603 : _("<no .debug_str section>"));
605 str_offset
= byte_get (index_section
->start
+ index_offset
, offset_size
);
606 str_offset
-= str_section
->address
;
607 if (str_offset
> str_section
->size
)
609 warn (_("DW_FORM_GNU_str_index indirect offset too big: %s\n"),
610 dwarf_vmatoa ("x", str_offset
));
611 return _("<indirect index offset is too big>");
614 return (const char *) str_section
->start
+ str_offset
;
618 fetch_indexed_value (dwarf_vma offset
, dwarf_vma bytes
)
620 struct dwarf_section
*section
= &debug_displays
[debug_addr
].section
;
622 if (section
->start
== NULL
)
623 return (_("<no .debug_addr section>"));
625 if (offset
+ bytes
> section
->size
)
627 warn (_("Offset into section %s too big: %s\n"),
628 section
->name
, dwarf_vmatoa ("x", offset
));
629 return "<offset too big>";
632 return dwarf_vmatoa ("x", byte_get (section
->start
+ offset
, bytes
));
636 /* FIXME: There are better and more efficient ways to handle
637 these structures. For now though, I just want something that
638 is simple to implement. */
639 typedef struct abbrev_attr
641 unsigned long attribute
;
643 struct abbrev_attr
*next
;
647 typedef struct abbrev_entry
652 struct abbrev_attr
*first_attr
;
653 struct abbrev_attr
*last_attr
;
654 struct abbrev_entry
*next
;
658 static abbrev_entry
*first_abbrev
= NULL
;
659 static abbrev_entry
*last_abbrev
= NULL
;
666 for (abbrv
= first_abbrev
; abbrv
;)
668 abbrev_entry
*next_abbrev
= abbrv
->next
;
671 for (attr
= abbrv
->first_attr
; attr
;)
673 abbrev_attr
*next_attr
= attr
->next
;
683 last_abbrev
= first_abbrev
= NULL
;
687 add_abbrev (unsigned long number
, unsigned long tag
, int children
)
691 entry
= (abbrev_entry
*) malloc (sizeof (*entry
));
696 entry
->entry
= number
;
698 entry
->children
= children
;
699 entry
->first_attr
= NULL
;
700 entry
->last_attr
= NULL
;
703 if (first_abbrev
== NULL
)
704 first_abbrev
= entry
;
706 last_abbrev
->next
= entry
;
712 add_abbrev_attr (unsigned long attribute
, unsigned long form
)
716 attr
= (abbrev_attr
*) malloc (sizeof (*attr
));
721 attr
->attribute
= attribute
;
725 if (last_abbrev
->first_attr
== NULL
)
726 last_abbrev
->first_attr
= attr
;
728 last_abbrev
->last_attr
->next
= attr
;
730 last_abbrev
->last_attr
= attr
;
733 /* Processes the (partial) contents of a .debug_abbrev section.
734 Returns NULL if the end of the section was encountered.
735 Returns the address after the last byte read if the end of
736 an abbreviation set was found. */
738 static unsigned char *
739 process_abbrev_section (unsigned char *start
, unsigned char *end
)
741 if (first_abbrev
!= NULL
)
746 unsigned int bytes_read
;
749 unsigned long attribute
;
752 entry
= read_uleb128 (start
, & bytes_read
, end
);
755 /* A single zero is supposed to end the section according
756 to the standard. If there's more, then signal that to
763 tag
= read_uleb128 (start
, & bytes_read
, end
);
770 add_abbrev (entry
, tag
, children
);
776 attribute
= read_uleb128 (start
, & bytes_read
, end
);
781 form
= read_uleb128 (start
, & bytes_read
, end
);
786 add_abbrev_attr (attribute
, form
);
788 while (attribute
!= 0);
791 /* Report the missing single zero which ends the section. */
792 error (_(".debug_abbrev section not zero terminated\n"));
798 get_TAG_name (unsigned long tag
)
800 const char *name
= get_DW_TAG_name ((unsigned int)tag
);
804 static char buffer
[100];
806 snprintf (buffer
, sizeof (buffer
), _("Unknown TAG value: %lx"), tag
);
814 get_FORM_name (unsigned long form
)
819 return "DW_FORM value: 0";
821 name
= get_DW_FORM_name (form
);
824 static char buffer
[100];
826 snprintf (buffer
, sizeof (buffer
), _("Unknown FORM value: %lx"), form
);
833 static unsigned char *
834 display_block (unsigned char *data
,
836 const unsigned char * const end
)
840 printf (_(" %s byte block: "), dwarf_vmatoa ("u", length
));
842 maxlen
= (dwarf_vma
) (end
- data
);
843 length
= length
> maxlen
? maxlen
: length
;
846 printf ("%lx ", (unsigned long) byte_get (data
++, 1));
852 decode_location_expression (unsigned char * data
,
853 unsigned int pointer_size
,
854 unsigned int offset_size
,
858 struct dwarf_section
* section
)
861 unsigned int bytes_read
;
863 dwarf_signed_vma svalue
;
864 unsigned char *end
= data
+ length
;
865 int need_frame_base
= 0;
874 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
875 printf ("DW_OP_addr: %s", dwarf_vmatoa ("x", uvalue
));
878 printf ("DW_OP_deref");
881 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
882 printf ("DW_OP_const1u: %lu", (unsigned long) uvalue
);
885 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 1, end
);
886 printf ("DW_OP_const1s: %ld", (long) svalue
);
889 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
890 printf ("DW_OP_const2u: %lu", (unsigned long) uvalue
);
893 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
894 printf ("DW_OP_const2s: %ld", (long) svalue
);
897 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
898 printf ("DW_OP_const4u: %lu", (unsigned long) uvalue
);
901 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
902 printf ("DW_OP_const4s: %ld", (long) svalue
);
905 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
906 printf ("DW_OP_const8u: %lu ", (unsigned long) uvalue
);
907 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
908 printf ("%lu", (unsigned long) uvalue
);
911 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
912 printf ("DW_OP_const8s: %ld ", (long) svalue
);
913 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
914 printf ("%ld", (long) svalue
);
917 printf ("DW_OP_constu: %s",
918 dwarf_vmatoa ("u", read_uleb128 (data
, &bytes_read
, end
)));
922 printf ("DW_OP_consts: %s",
923 dwarf_vmatoa ("d", read_sleb128 (data
, &bytes_read
, end
)));
927 printf ("DW_OP_dup");
930 printf ("DW_OP_drop");
933 printf ("DW_OP_over");
936 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
937 printf ("DW_OP_pick: %ld", (unsigned long) uvalue
);
940 printf ("DW_OP_swap");
943 printf ("DW_OP_rot");
946 printf ("DW_OP_xderef");
949 printf ("DW_OP_abs");
952 printf ("DW_OP_and");
955 printf ("DW_OP_div");
958 printf ("DW_OP_minus");
961 printf ("DW_OP_mod");
964 printf ("DW_OP_mul");
967 printf ("DW_OP_neg");
970 printf ("DW_OP_not");
976 printf ("DW_OP_plus");
978 case DW_OP_plus_uconst
:
979 printf ("DW_OP_plus_uconst: %s",
980 dwarf_vmatoa ("u", read_uleb128 (data
, &bytes_read
, end
)));
984 printf ("DW_OP_shl");
987 printf ("DW_OP_shr");
990 printf ("DW_OP_shra");
993 printf ("DW_OP_xor");
996 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
997 printf ("DW_OP_bra: %ld", (long) svalue
);
1000 printf ("DW_OP_eq");
1003 printf ("DW_OP_ge");
1006 printf ("DW_OP_gt");
1009 printf ("DW_OP_le");
1012 printf ("DW_OP_lt");
1015 printf ("DW_OP_ne");
1018 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1019 printf ("DW_OP_skip: %ld", (long) svalue
);
1054 printf ("DW_OP_lit%d", op
- DW_OP_lit0
);
1089 printf ("DW_OP_reg%d (%s)", op
- DW_OP_reg0
,
1090 regname (op
- DW_OP_reg0
, 1));
1125 printf ("DW_OP_breg%d (%s): %s",
1127 regname (op
- DW_OP_breg0
, 1),
1128 dwarf_vmatoa ("d", read_sleb128 (data
, &bytes_read
, end
)));
1133 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1135 printf ("DW_OP_regx: %s (%s)",
1136 dwarf_vmatoa ("u", uvalue
), regname (uvalue
, 1));
1139 need_frame_base
= 1;
1140 printf ("DW_OP_fbreg: %s",
1141 dwarf_vmatoa ("d", read_sleb128 (data
, &bytes_read
, end
)));
1145 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1147 printf ("DW_OP_bregx: %s (%s) %s",
1148 dwarf_vmatoa ("u", uvalue
), regname (uvalue
, 1),
1149 dwarf_vmatoa ("d", read_sleb128 (data
, &bytes_read
, end
)));
1153 printf ("DW_OP_piece: %s",
1154 dwarf_vmatoa ("u", read_uleb128 (data
, &bytes_read
, end
)));
1157 case DW_OP_deref_size
:
1158 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1159 printf ("DW_OP_deref_size: %ld", (long) uvalue
);
1161 case DW_OP_xderef_size
:
1162 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1163 printf ("DW_OP_xderef_size: %ld", (long) uvalue
);
1166 printf ("DW_OP_nop");
1169 /* DWARF 3 extensions. */
1170 case DW_OP_push_object_address
:
1171 printf ("DW_OP_push_object_address");
1174 /* XXX: Strictly speaking for 64-bit DWARF3 files
1175 this ought to be an 8-byte wide computation. */
1176 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1177 printf ("DW_OP_call2: <0x%s>",
1178 dwarf_vmatoa ("x", svalue
+ cu_offset
));
1181 /* XXX: Strictly speaking for 64-bit DWARF3 files
1182 this ought to be an 8-byte wide computation. */
1183 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
1184 printf ("DW_OP_call4: <0x%s>",
1185 dwarf_vmatoa ("x", svalue
+ cu_offset
));
1187 case DW_OP_call_ref
:
1188 /* XXX: Strictly speaking for 64-bit DWARF3 files
1189 this ought to be an 8-byte wide computation. */
1190 if (dwarf_version
== -1)
1192 printf (_("(DW_OP_call_ref in frame info)"));
1193 /* No way to tell where the next op is, so just bail. */
1194 return need_frame_base
;
1196 if (dwarf_version
== 2)
1198 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1202 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1204 printf ("DW_OP_call_ref: <0x%s>", dwarf_vmatoa ("x", uvalue
));
1206 case DW_OP_form_tls_address
:
1207 printf ("DW_OP_form_tls_address");
1209 case DW_OP_call_frame_cfa
:
1210 printf ("DW_OP_call_frame_cfa");
1212 case DW_OP_bit_piece
:
1213 printf ("DW_OP_bit_piece: ");
1214 printf (_("size: %s "),
1215 dwarf_vmatoa ("u", read_uleb128 (data
, &bytes_read
, end
)));
1217 printf (_("offset: %s "),
1218 dwarf_vmatoa ("u", read_uleb128 (data
, &bytes_read
, end
)));
1222 /* DWARF 4 extensions. */
1223 case DW_OP_stack_value
:
1224 printf ("DW_OP_stack_value");
1227 case DW_OP_implicit_value
:
1228 printf ("DW_OP_implicit_value");
1229 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1231 display_block (data
, uvalue
, end
);
1235 /* GNU extensions. */
1236 case DW_OP_GNU_push_tls_address
:
1237 printf (_("DW_OP_GNU_push_tls_address or DW_OP_HP_unknown"));
1239 case DW_OP_GNU_uninit
:
1240 printf ("DW_OP_GNU_uninit");
1241 /* FIXME: Is there data associated with this OP ? */
1243 case DW_OP_GNU_encoded_addr
:
1249 addr
= get_encoded_value (data
, encoding
, section
);
1250 data
+= size_of_encoded_value (encoding
);
1252 printf ("DW_OP_GNU_encoded_addr: fmt:%02x addr:", encoding
);
1253 print_dwarf_vma (addr
, pointer_size
);
1256 case DW_OP_GNU_implicit_pointer
:
1257 /* XXX: Strictly speaking for 64-bit DWARF3 files
1258 this ought to be an 8-byte wide computation. */
1259 if (dwarf_version
== -1)
1261 printf (_("(DW_OP_GNU_implicit_pointer in frame info)"));
1262 /* No way to tell where the next op is, so just bail. */
1263 return need_frame_base
;
1265 if (dwarf_version
== 2)
1267 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1271 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1273 printf ("DW_OP_GNU_implicit_pointer: <0x%s> %s",
1274 dwarf_vmatoa ("x", uvalue
),
1275 dwarf_vmatoa ("d", read_sleb128 (data
,
1276 &bytes_read
, end
)));
1279 case DW_OP_GNU_entry_value
:
1280 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1282 printf ("DW_OP_GNU_entry_value: (");
1283 if (decode_location_expression (data
, pointer_size
, offset_size
,
1284 dwarf_version
, uvalue
,
1285 cu_offset
, section
))
1286 need_frame_base
= 1;
1290 case DW_OP_GNU_const_type
:
1291 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1293 printf ("DW_OP_GNU_const_type: <0x%s> ",
1294 dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1295 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1296 display_block (data
, uvalue
, end
);
1299 case DW_OP_GNU_regval_type
:
1300 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1302 printf ("DW_OP_GNU_regval_type: %s (%s)",
1303 dwarf_vmatoa ("u", uvalue
), regname (uvalue
, 1));
1304 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1306 printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1308 case DW_OP_GNU_deref_type
:
1309 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1310 printf ("DW_OP_GNU_deref_type: %ld", (long) uvalue
);
1311 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1313 printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1315 case DW_OP_GNU_convert
:
1316 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1318 printf ("DW_OP_GNU_convert <0x%s>",
1319 dwarf_vmatoa ("x", uvalue
? cu_offset
+ uvalue
: 0));
1321 case DW_OP_GNU_reinterpret
:
1322 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1324 printf ("DW_OP_GNU_reinterpret <0x%s>",
1325 dwarf_vmatoa ("x", uvalue
? cu_offset
+ uvalue
: 0));
1327 case DW_OP_GNU_parameter_ref
:
1328 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1329 printf ("DW_OP_GNU_parameter_ref: <0x%s>",
1330 dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1332 case DW_OP_GNU_addr_index
:
1333 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1335 printf ("DW_OP_GNU_addr_index <0x%s>", dwarf_vmatoa ("x", uvalue
));
1337 case DW_OP_GNU_const_index
:
1338 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1340 printf ("DW_OP_GNU_const_index <0x%s>", dwarf_vmatoa ("x", uvalue
));
1343 /* HP extensions. */
1344 case DW_OP_HP_is_value
:
1345 printf ("DW_OP_HP_is_value");
1346 /* FIXME: Is there data associated with this OP ? */
1348 case DW_OP_HP_fltconst4
:
1349 printf ("DW_OP_HP_fltconst4");
1350 /* FIXME: Is there data associated with this OP ? */
1352 case DW_OP_HP_fltconst8
:
1353 printf ("DW_OP_HP_fltconst8");
1354 /* FIXME: Is there data associated with this OP ? */
1356 case DW_OP_HP_mod_range
:
1357 printf ("DW_OP_HP_mod_range");
1358 /* FIXME: Is there data associated with this OP ? */
1360 case DW_OP_HP_unmod_range
:
1361 printf ("DW_OP_HP_unmod_range");
1362 /* FIXME: Is there data associated with this OP ? */
1365 printf ("DW_OP_HP_tls");
1366 /* FIXME: Is there data associated with this OP ? */
1369 /* PGI (STMicroelectronics) extensions. */
1370 case DW_OP_PGI_omp_thread_num
:
1371 /* Pushes the thread number for the current thread as it would be
1372 returned by the standard OpenMP library function:
1373 omp_get_thread_num(). The "current thread" is the thread for
1374 which the expression is being evaluated. */
1375 printf ("DW_OP_PGI_omp_thread_num");
1379 if (op
>= DW_OP_lo_user
1380 && op
<= DW_OP_hi_user
)
1381 printf (_("(User defined location op)"));
1383 printf (_("(Unknown location op)"));
1384 /* No way to tell where the next op is, so just bail. */
1385 return need_frame_base
;
1388 /* Separate the ops. */
1393 return need_frame_base
;
1396 /* Find the CU or TU set corresponding to the given CU_OFFSET.
1397 This is used for DWARF package files. */
1399 static struct cu_tu_set
*
1400 find_cu_tu_set_v2 (dwarf_vma cu_offset
, int do_types
)
1402 struct cu_tu_set
*p
;
1404 unsigned int dw_sect
;
1410 dw_sect
= DW_SECT_TYPES
;
1416 dw_sect
= DW_SECT_INFO
;
1420 if (p
->section_offsets
[dw_sect
] == cu_offset
)
1428 /* Add INC to HIGH_BITS:LOW_BITS. */
1430 add64 (dwarf_vma
* high_bits
, dwarf_vma
* low_bits
, dwarf_vma inc
)
1432 dwarf_vma tmp
= * low_bits
;
1436 /* FIXME: There is probably a better way of handling this:
1438 We need to cope with dwarf_vma being a 32-bit or 64-bit
1439 type. Plus regardless of its size LOW_BITS is meant to
1440 only hold 32-bits, so if there is overflow or wrap around
1441 we must propagate into HIGH_BITS. */
1442 if (tmp
< * low_bits
)
1446 else if (sizeof (tmp
) > 8
1456 static unsigned char *
1457 read_and_display_attr_value (unsigned long attribute
,
1459 unsigned char * data
,
1460 unsigned char * end
,
1461 dwarf_vma cu_offset
,
1462 dwarf_vma pointer_size
,
1463 dwarf_vma offset_size
,
1465 debug_info
* debug_info_p
,
1467 struct dwarf_section
* section
,
1468 struct cu_tu_set
* this_set
)
1470 dwarf_vma uvalue
= 0;
1471 unsigned char *block_start
= NULL
;
1472 unsigned char * orig_data
= data
;
1473 unsigned int bytes_read
;
1477 warn (_("corrupt attribute\n"));
1486 case DW_FORM_ref_addr
:
1487 if (dwarf_version
== 2)
1488 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1489 else if (dwarf_version
== 3 || dwarf_version
== 4)
1490 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1492 error (_("Internal error: DWARF version is not 2, 3 or 4.\n"));
1497 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1501 case DW_FORM_sec_offset
:
1502 case DW_FORM_GNU_ref_alt
:
1503 case DW_FORM_GNU_strp_alt
:
1504 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1507 case DW_FORM_flag_present
:
1514 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1519 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
1524 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1528 uvalue
= read_sleb128 (data
, & bytes_read
, end
);
1532 case DW_FORM_GNU_str_index
:
1533 uvalue
= read_uleb128 (data
, & bytes_read
, end
);
1537 case DW_FORM_ref_udata
:
1539 uvalue
= read_uleb128 (data
, & bytes_read
, end
);
1543 case DW_FORM_indirect
:
1544 form
= read_uleb128 (data
, & bytes_read
, end
);
1547 printf (" %s", get_FORM_name (form
));
1548 return read_and_display_attr_value (attribute
, form
, data
, end
,
1549 cu_offset
, pointer_size
,
1550 offset_size
, dwarf_version
,
1551 debug_info_p
, do_loc
,
1553 case DW_FORM_GNU_addr_index
:
1554 uvalue
= read_uleb128 (data
, & bytes_read
, end
);
1561 case DW_FORM_ref_addr
:
1563 printf (" <0x%s>", dwarf_vmatoa ("x",uvalue
));
1566 case DW_FORM_GNU_ref_alt
:
1568 printf (" <alt 0x%s>", dwarf_vmatoa ("x",uvalue
));
1574 case DW_FORM_ref_udata
:
1576 printf (" <0x%s>", dwarf_vmatoa ("x", uvalue
+ cu_offset
));
1581 case DW_FORM_sec_offset
:
1583 printf (" 0x%s", dwarf_vmatoa ("x", uvalue
));
1586 case DW_FORM_flag_present
:
1593 printf (" %s", dwarf_vmatoa ("d", uvalue
));
1600 dwarf_vma high_bits
;
1604 SAFE_BYTE_GET64 (data
, &high_bits
, &uvalue
, end
);
1606 if (form
== DW_FORM_ref8
)
1607 add64 (& high_bits
, & utmp
, cu_offset
);
1609 dwarf_vmatoa64 (high_bits
, utmp
, buf
, sizeof (buf
)));
1612 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
1613 && num_debug_info_entries
== 0)
1615 if (sizeof (uvalue
) == 8)
1616 SAFE_BYTE_GET (uvalue
, data
, 8, end
);
1618 error (_("DW_FORM_data8 is unsupported when sizeof (dwarf_vma) != 8\n"));
1624 case DW_FORM_string
:
1626 printf (" %.*s", (int) (end
- data
), data
);
1627 data
+= strnlen ((char *) data
, end
- data
) + 1;
1631 case DW_FORM_exprloc
:
1632 uvalue
= read_uleb128 (data
, & bytes_read
, end
);
1633 block_start
= data
+ bytes_read
;
1635 data
= block_start
+ uvalue
;
1637 data
= display_block (block_start
, uvalue
, end
);
1640 case DW_FORM_block1
:
1641 SAFE_BYTE_GET (uvalue
, data
, 1, end
);
1642 block_start
= data
+ 1;
1644 data
= block_start
+ uvalue
;
1646 data
= display_block (block_start
, uvalue
, end
);
1649 case DW_FORM_block2
:
1650 SAFE_BYTE_GET (uvalue
, data
, 2, end
);
1651 block_start
= data
+ 2;
1653 data
= block_start
+ uvalue
;
1655 data
= display_block (block_start
, uvalue
, end
);
1658 case DW_FORM_block4
:
1659 SAFE_BYTE_GET (uvalue
, data
, 4, end
);
1660 block_start
= data
+ 4;
1662 data
= block_start
+ uvalue
;
1664 data
= display_block (block_start
, uvalue
, end
);
1669 printf (_(" (indirect string, offset: 0x%s): %s"),
1670 dwarf_vmatoa ("x", uvalue
),
1671 fetch_indirect_string (uvalue
));
1674 case DW_FORM_GNU_str_index
:
1677 const char *suffix
= strrchr (section
->name
, '.');
1678 int dwo
= (suffix
&& strcmp (suffix
, ".dwo") == 0) ? 1 : 0;
1680 printf (_(" (indexed string: 0x%s): %s"),
1681 dwarf_vmatoa ("x", uvalue
),
1682 fetch_indexed_string (uvalue
, this_set
, offset_size
, dwo
));
1686 case DW_FORM_GNU_strp_alt
:
1688 printf (_(" (alt indirect string, offset: 0x%s)"),
1689 dwarf_vmatoa ("x", uvalue
));
1692 case DW_FORM_indirect
:
1693 /* Handled above. */
1696 case DW_FORM_ref_sig8
:
1699 dwarf_vma high_bits
;
1702 SAFE_BYTE_GET64 (data
, &high_bits
, &uvalue
, end
);
1703 printf (" signature: 0x%s",
1704 dwarf_vmatoa64 (high_bits
, uvalue
, buf
, sizeof (buf
)));
1709 case DW_FORM_GNU_addr_index
:
1711 printf (_(" (addr_index: 0x%s): %s"),
1712 dwarf_vmatoa ("x", uvalue
),
1713 fetch_indexed_value (uvalue
* pointer_size
, pointer_size
));
1717 warn (_("Unrecognized form: %lu\n"), form
);
1721 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
1722 && num_debug_info_entries
== 0
1723 && debug_info_p
!= NULL
)
1727 case DW_AT_frame_base
:
1728 have_frame_base
= 1;
1729 case DW_AT_location
:
1730 case DW_AT_string_length
:
1731 case DW_AT_return_addr
:
1732 case DW_AT_data_member_location
:
1733 case DW_AT_vtable_elem_location
:
1735 case DW_AT_static_link
:
1736 case DW_AT_use_location
:
1737 case DW_AT_GNU_call_site_value
:
1738 case DW_AT_GNU_call_site_data_value
:
1739 case DW_AT_GNU_call_site_target
:
1740 case DW_AT_GNU_call_site_target_clobbered
:
1741 if ((dwarf_version
< 4
1742 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
1743 || form
== DW_FORM_sec_offset
)
1745 /* Process location list. */
1746 unsigned int lmax
= debug_info_p
->max_loc_offsets
;
1747 unsigned int num
= debug_info_p
->num_loc_offsets
;
1749 if (lmax
== 0 || num
>= lmax
)
1752 debug_info_p
->loc_offsets
= (dwarf_vma
*)
1753 xcrealloc (debug_info_p
->loc_offsets
,
1754 lmax
, sizeof (*debug_info_p
->loc_offsets
));
1755 debug_info_p
->have_frame_base
= (int *)
1756 xcrealloc (debug_info_p
->have_frame_base
,
1757 lmax
, sizeof (*debug_info_p
->have_frame_base
));
1758 debug_info_p
->max_loc_offsets
= lmax
;
1760 if (this_set
!= NULL
)
1761 uvalue
+= this_set
->section_offsets
[DW_SECT_LOC
];
1762 debug_info_p
->loc_offsets
[num
] = uvalue
;
1763 debug_info_p
->have_frame_base
[num
] = have_frame_base
;
1764 debug_info_p
->num_loc_offsets
++;
1769 if (need_base_address
)
1770 debug_info_p
->base_address
= uvalue
;
1773 case DW_AT_GNU_addr_base
:
1774 debug_info_p
->addr_base
= uvalue
;
1777 case DW_AT_GNU_ranges_base
:
1778 debug_info_p
->ranges_base
= uvalue
;
1782 if ((dwarf_version
< 4
1783 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
1784 || form
== DW_FORM_sec_offset
)
1786 /* Process range list. */
1787 unsigned int lmax
= debug_info_p
->max_range_lists
;
1788 unsigned int num
= debug_info_p
->num_range_lists
;
1790 if (lmax
== 0 || num
>= lmax
)
1793 debug_info_p
->range_lists
= (dwarf_vma
*)
1794 xcrealloc (debug_info_p
->range_lists
,
1795 lmax
, sizeof (*debug_info_p
->range_lists
));
1796 debug_info_p
->max_range_lists
= lmax
;
1798 debug_info_p
->range_lists
[num
] = uvalue
;
1799 debug_info_p
->num_range_lists
++;
1808 if (do_loc
|| attribute
== 0)
1811 /* For some attributes we can display further information. */
1819 case DW_INL_not_inlined
:
1820 printf (_("(not inlined)"));
1822 case DW_INL_inlined
:
1823 printf (_("(inlined)"));
1825 case DW_INL_declared_not_inlined
:
1826 printf (_("(declared as inline but ignored)"));
1828 case DW_INL_declared_inlined
:
1829 printf (_("(declared as inline and inlined)"));
1832 printf (_(" (Unknown inline attribute value: %s)"),
1833 dwarf_vmatoa ("x", uvalue
));
1838 case DW_AT_language
:
1841 /* Ordered by the numeric value of these constants. */
1842 case DW_LANG_C89
: printf ("(ANSI C)"); break;
1843 case DW_LANG_C
: printf ("(non-ANSI C)"); break;
1844 case DW_LANG_Ada83
: printf ("(Ada)"); break;
1845 case DW_LANG_C_plus_plus
: printf ("(C++)"); break;
1846 case DW_LANG_Cobol74
: printf ("(Cobol 74)"); break;
1847 case DW_LANG_Cobol85
: printf ("(Cobol 85)"); break;
1848 case DW_LANG_Fortran77
: printf ("(FORTRAN 77)"); break;
1849 case DW_LANG_Fortran90
: printf ("(Fortran 90)"); break;
1850 case DW_LANG_Pascal83
: printf ("(ANSI Pascal)"); break;
1851 case DW_LANG_Modula2
: printf ("(Modula 2)"); break;
1852 /* DWARF 2.1 values. */
1853 case DW_LANG_Java
: printf ("(Java)"); break;
1854 case DW_LANG_C99
: printf ("(ANSI C99)"); break;
1855 case DW_LANG_Ada95
: printf ("(ADA 95)"); break;
1856 case DW_LANG_Fortran95
: printf ("(Fortran 95)"); break;
1857 /* DWARF 3 values. */
1858 case DW_LANG_PLI
: printf ("(PLI)"); break;
1859 case DW_LANG_ObjC
: printf ("(Objective C)"); break;
1860 case DW_LANG_ObjC_plus_plus
: printf ("(Objective C++)"); break;
1861 case DW_LANG_UPC
: printf ("(Unified Parallel C)"); break;
1862 case DW_LANG_D
: printf ("(D)"); break;
1863 /* DWARF 4 values. */
1864 case DW_LANG_Python
: printf ("(Python)"); break;
1865 /* DWARF 5 values. */
1866 case DW_LANG_Go
: printf ("(Go)"); break;
1867 /* MIPS extension. */
1868 case DW_LANG_Mips_Assembler
: printf ("(MIPS assembler)"); break;
1869 /* UPC extension. */
1870 case DW_LANG_Upc
: printf ("(Unified Parallel C)"); break;
1872 if (uvalue
>= DW_LANG_lo_user
&& uvalue
<= DW_LANG_hi_user
)
1873 printf (_("(implementation defined: %s)"),
1874 dwarf_vmatoa ("x", uvalue
));
1876 printf (_("(Unknown: %s)"), dwarf_vmatoa ("x", uvalue
));
1881 case DW_AT_encoding
:
1884 case DW_ATE_void
: printf ("(void)"); break;
1885 case DW_ATE_address
: printf ("(machine address)"); break;
1886 case DW_ATE_boolean
: printf ("(boolean)"); break;
1887 case DW_ATE_complex_float
: printf ("(complex float)"); break;
1888 case DW_ATE_float
: printf ("(float)"); break;
1889 case DW_ATE_signed
: printf ("(signed)"); break;
1890 case DW_ATE_signed_char
: printf ("(signed char)"); break;
1891 case DW_ATE_unsigned
: printf ("(unsigned)"); break;
1892 case DW_ATE_unsigned_char
: printf ("(unsigned char)"); break;
1893 /* DWARF 2.1 values: */
1894 case DW_ATE_imaginary_float
: printf ("(imaginary float)"); break;
1895 case DW_ATE_decimal_float
: printf ("(decimal float)"); break;
1896 /* DWARF 3 values: */
1897 case DW_ATE_packed_decimal
: printf ("(packed_decimal)"); break;
1898 case DW_ATE_numeric_string
: printf ("(numeric_string)"); break;
1899 case DW_ATE_edited
: printf ("(edited)"); break;
1900 case DW_ATE_signed_fixed
: printf ("(signed_fixed)"); break;
1901 case DW_ATE_unsigned_fixed
: printf ("(unsigned_fixed)"); break;
1902 /* HP extensions: */
1903 case DW_ATE_HP_float80
: printf ("(HP_float80)"); break;
1904 case DW_ATE_HP_complex_float80
: printf ("(HP_complex_float80)"); break;
1905 case DW_ATE_HP_float128
: printf ("(HP_float128)"); break;
1906 case DW_ATE_HP_complex_float128
:printf ("(HP_complex_float128)"); break;
1907 case DW_ATE_HP_floathpintel
: printf ("(HP_floathpintel)"); break;
1908 case DW_ATE_HP_imaginary_float80
: printf ("(HP_imaginary_float80)"); break;
1909 case DW_ATE_HP_imaginary_float128
: printf ("(HP_imaginary_float128)"); break;
1912 if (uvalue
>= DW_ATE_lo_user
1913 && uvalue
<= DW_ATE_hi_user
)
1914 printf (_("(user defined type)"));
1916 printf (_("(unknown type)"));
1921 case DW_AT_accessibility
:
1924 case DW_ACCESS_public
: printf ("(public)"); break;
1925 case DW_ACCESS_protected
: printf ("(protected)"); break;
1926 case DW_ACCESS_private
: printf ("(private)"); break;
1928 printf (_("(unknown accessibility)"));
1933 case DW_AT_visibility
:
1936 case DW_VIS_local
: printf ("(local)"); break;
1937 case DW_VIS_exported
: printf ("(exported)"); break;
1938 case DW_VIS_qualified
: printf ("(qualified)"); break;
1939 default: printf (_("(unknown visibility)")); break;
1943 case DW_AT_virtuality
:
1946 case DW_VIRTUALITY_none
: printf ("(none)"); break;
1947 case DW_VIRTUALITY_virtual
: printf ("(virtual)"); break;
1948 case DW_VIRTUALITY_pure_virtual
:printf ("(pure_virtual)"); break;
1949 default: printf (_("(unknown virtuality)")); break;
1953 case DW_AT_identifier_case
:
1956 case DW_ID_case_sensitive
: printf ("(case_sensitive)"); break;
1957 case DW_ID_up_case
: printf ("(up_case)"); break;
1958 case DW_ID_down_case
: printf ("(down_case)"); break;
1959 case DW_ID_case_insensitive
: printf ("(case_insensitive)"); break;
1960 default: printf (_("(unknown case)")); break;
1964 case DW_AT_calling_convention
:
1967 case DW_CC_normal
: printf ("(normal)"); break;
1968 case DW_CC_program
: printf ("(program)"); break;
1969 case DW_CC_nocall
: printf ("(nocall)"); break;
1971 if (uvalue
>= DW_CC_lo_user
1972 && uvalue
<= DW_CC_hi_user
)
1973 printf (_("(user defined)"));
1975 printf (_("(unknown convention)"));
1979 case DW_AT_ordering
:
1982 case -1: printf (_("(undefined)")); break;
1983 case 0: printf ("(row major)"); break;
1984 case 1: printf ("(column major)"); break;
1988 case DW_AT_frame_base
:
1989 have_frame_base
= 1;
1990 case DW_AT_location
:
1991 case DW_AT_string_length
:
1992 case DW_AT_return_addr
:
1993 case DW_AT_data_member_location
:
1994 case DW_AT_vtable_elem_location
:
1996 case DW_AT_static_link
:
1997 case DW_AT_use_location
:
1998 case DW_AT_GNU_call_site_value
:
1999 case DW_AT_GNU_call_site_data_value
:
2000 case DW_AT_GNU_call_site_target
:
2001 case DW_AT_GNU_call_site_target_clobbered
:
2002 if ((dwarf_version
< 4
2003 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
2004 || form
== DW_FORM_sec_offset
)
2005 printf (_("(location list)"));
2007 case DW_AT_allocated
:
2008 case DW_AT_associated
:
2009 case DW_AT_data_location
:
2011 case DW_AT_upper_bound
:
2012 case DW_AT_lower_bound
:
2015 int need_frame_base
;
2018 need_frame_base
= decode_location_expression (block_start
,
2023 cu_offset
, section
);
2025 if (need_frame_base
&& !have_frame_base
)
2026 printf (_(" [without DW_AT_frame_base]"));
2032 if (form
== DW_FORM_ref_sig8
2033 || form
== DW_FORM_GNU_ref_alt
)
2036 if (form
== DW_FORM_ref1
2037 || form
== DW_FORM_ref2
2038 || form
== DW_FORM_ref4
2039 || form
== DW_FORM_ref_udata
)
2040 uvalue
+= cu_offset
;
2042 if (uvalue
>= section
->size
)
2043 warn (_("Offset %s used as value for DW_AT_import attribute of DIE at offset %lx is too big.\n"),
2044 dwarf_vmatoa ("x", uvalue
),
2045 (unsigned long) (orig_data
- section
->start
));
2048 unsigned long abbrev_number
;
2049 abbrev_entry
* entry
;
2051 abbrev_number
= read_uleb128 (section
->start
+ uvalue
, NULL
, end
);
2053 printf (_("[Abbrev Number: %ld"), abbrev_number
);
2054 /* Don't look up abbrev for DW_FORM_ref_addr, as it very often will
2055 use different abbrev table, and we don't track .debug_info chunks
2057 if (form
!= DW_FORM_ref_addr
)
2059 for (entry
= first_abbrev
; entry
!= NULL
; entry
= entry
->next
)
2060 if (entry
->entry
== abbrev_number
)
2063 printf (" (%s)", get_TAG_name (entry
->tag
));
2078 get_AT_name (unsigned long attribute
)
2083 return "DW_AT value: 0";
2085 /* One value is shared by the MIPS and HP extensions: */
2086 if (attribute
== DW_AT_MIPS_fde
)
2087 return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable";
2089 name
= get_DW_AT_name (attribute
);
2093 static char buffer
[100];
2095 snprintf (buffer
, sizeof (buffer
), _("Unknown AT value: %lx"),
2103 static unsigned char *
2104 read_and_display_attr (unsigned long attribute
,
2106 unsigned char * data
,
2107 unsigned char * end
,
2108 dwarf_vma cu_offset
,
2109 dwarf_vma pointer_size
,
2110 dwarf_vma offset_size
,
2112 debug_info
* debug_info_p
,
2114 struct dwarf_section
* section
,
2115 struct cu_tu_set
* this_set
)
2118 printf (" %-18s:", get_AT_name (attribute
));
2119 data
= read_and_display_attr_value (attribute
, form
, data
, end
,
2120 cu_offset
, pointer_size
, offset_size
,
2121 dwarf_version
, debug_info_p
,
2122 do_loc
, section
, this_set
);
2128 /* Process the contents of a .debug_info section. If do_loc is non-zero
2129 then we are scanning for location lists and we do not want to display
2130 anything to the user. If do_types is non-zero, we are processing
2131 a .debug_types section instead of a .debug_info section. */
2134 process_debug_info (struct dwarf_section
*section
,
2136 enum dwarf_section_display_enum abbrev_sec
,
2140 unsigned char *start
= section
->start
;
2141 unsigned char *end
= start
+ section
->size
;
2142 unsigned char *section_begin
;
2144 unsigned int num_units
= 0;
2146 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
2147 && num_debug_info_entries
== 0
2152 /* First scan the section to get the number of comp units. */
2153 for (section_begin
= start
, num_units
= 0; section_begin
< end
;
2156 /* Read the first 4 bytes. For a 32-bit DWARF section, this
2157 will be the length. For a 64-bit DWARF section, it'll be
2158 the escape code 0xffffffff followed by an 8 byte length. */
2159 SAFE_BYTE_GET (length
, section_begin
, 4, end
);
2161 if (length
== 0xffffffff)
2163 SAFE_BYTE_GET (length
, section_begin
+ 4, 8, end
);
2164 section_begin
+= length
+ 12;
2166 else if (length
>= 0xfffffff0 && length
< 0xffffffff)
2168 warn (_("Reserved length value (0x%s) found in section %s\n"),
2169 dwarf_vmatoa ("x", length
), section
->name
);
2173 section_begin
+= length
+ 4;
2175 /* Negative values are illegal, they may even cause infinite
2176 looping. This can happen if we can't accurately apply
2177 relocations to an object file. */
2178 if ((signed long) length
<= 0)
2180 warn (_("Corrupt unit length (0x%s) found in section %s\n"),
2181 dwarf_vmatoa ("x", length
), section
->name
);
2188 error (_("No comp units in %s section ?"), section
->name
);
2192 /* Then allocate an array to hold the information. */
2193 debug_information
= (debug_info
*) cmalloc (num_units
,
2194 sizeof (* debug_information
));
2195 if (debug_information
== NULL
)
2197 error (_("Not enough memory for a debug info array of %u entries"),
2205 if (dwarf_start_die
== 0)
2206 printf (_("Contents of the %s section:\n\n"), section
->name
);
2208 load_debug_section (str
, file
);
2209 load_debug_section (str_dwo
, file
);
2210 load_debug_section (str_index
, file
);
2211 load_debug_section (str_index_dwo
, file
);
2212 load_debug_section (debug_addr
, file
);
2215 load_debug_section (abbrev_sec
, file
);
2216 if (debug_displays
[abbrev_sec
].section
.start
== NULL
)
2218 warn (_("Unable to locate %s section!\n"),
2219 debug_displays
[abbrev_sec
].section
.name
);
2223 for (section_begin
= start
, unit
= 0; start
< end
; unit
++)
2225 DWARF2_Internal_CompUnit compunit
;
2226 unsigned char *hdrptr
;
2227 unsigned char *tags
;
2228 int level
, last_level
, saved_level
;
2229 dwarf_vma cu_offset
;
2230 unsigned int offset_size
;
2231 int initial_length_size
;
2232 dwarf_vma signature_high
= 0;
2233 dwarf_vma signature_low
= 0;
2234 dwarf_vma type_offset
= 0;
2235 struct cu_tu_set
*this_set
;
2236 dwarf_vma abbrev_base
;
2241 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 4, end
);
2243 if (compunit
.cu_length
== 0xffffffff)
2245 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 8, end
);
2247 initial_length_size
= 12;
2252 initial_length_size
= 4;
2255 SAFE_BYTE_GET_AND_INC (compunit
.cu_version
, hdrptr
, 2, end
);
2257 cu_offset
= start
- section_begin
;
2259 this_set
= find_cu_tu_set_v2 (cu_offset
, do_types
);
2261 SAFE_BYTE_GET_AND_INC (compunit
.cu_abbrev_offset
, hdrptr
, offset_size
, end
);
2263 if (this_set
== NULL
)
2266 abbrev_size
= debug_displays
[abbrev_sec
].section
.size
;
2270 abbrev_base
= this_set
->section_offsets
[DW_SECT_ABBREV
];
2271 abbrev_size
= this_set
->section_sizes
[DW_SECT_ABBREV
];
2274 SAFE_BYTE_GET_AND_INC (compunit
.cu_pointer_size
, hdrptr
, 1, end
);
2278 SAFE_BYTE_GET64 (hdrptr
, &signature_high
, &signature_low
, end
);
2280 SAFE_BYTE_GET_AND_INC (type_offset
, hdrptr
, offset_size
, end
);
2283 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
2284 && num_debug_info_entries
== 0
2287 debug_information
[unit
].cu_offset
= cu_offset
;
2288 debug_information
[unit
].pointer_size
2289 = compunit
.cu_pointer_size
;
2290 debug_information
[unit
].offset_size
= offset_size
;
2291 debug_information
[unit
].dwarf_version
= compunit
.cu_version
;
2292 debug_information
[unit
].base_address
= 0;
2293 debug_information
[unit
].addr_base
= DEBUG_INFO_UNAVAILABLE
;
2294 debug_information
[unit
].ranges_base
= DEBUG_INFO_UNAVAILABLE
;
2295 debug_information
[unit
].loc_offsets
= NULL
;
2296 debug_information
[unit
].have_frame_base
= NULL
;
2297 debug_information
[unit
].max_loc_offsets
= 0;
2298 debug_information
[unit
].num_loc_offsets
= 0;
2299 debug_information
[unit
].range_lists
= NULL
;
2300 debug_information
[unit
].max_range_lists
= 0;
2301 debug_information
[unit
].num_range_lists
= 0;
2304 if (!do_loc
&& dwarf_start_die
== 0)
2306 printf (_(" Compilation Unit @ offset 0x%s:\n"),
2307 dwarf_vmatoa ("x", cu_offset
));
2308 printf (_(" Length: 0x%s (%s)\n"),
2309 dwarf_vmatoa ("x", compunit
.cu_length
),
2310 offset_size
== 8 ? "64-bit" : "32-bit");
2311 printf (_(" Version: %d\n"), compunit
.cu_version
);
2312 printf (_(" Abbrev Offset: 0x%s\n"),
2313 dwarf_vmatoa ("x", compunit
.cu_abbrev_offset
));
2314 printf (_(" Pointer Size: %d\n"), compunit
.cu_pointer_size
);
2319 printf (_(" Signature: 0x%s\n"),
2320 dwarf_vmatoa64 (signature_high
, signature_low
,
2321 buf
, sizeof (buf
)));
2322 printf (_(" Type Offset: 0x%s\n"),
2323 dwarf_vmatoa ("x", type_offset
));
2325 if (this_set
!= NULL
)
2327 dwarf_vma
*offsets
= this_set
->section_offsets
;
2328 size_t *sizes
= this_set
->section_sizes
;
2330 printf (_(" Section contributions:\n"));
2331 printf (_(" .debug_abbrev.dwo: 0x%s 0x%s\n"),
2332 dwarf_vmatoa ("x", offsets
[DW_SECT_ABBREV
]),
2333 dwarf_vmatoa ("x", sizes
[DW_SECT_ABBREV
]));
2334 printf (_(" .debug_line.dwo: 0x%s 0x%s\n"),
2335 dwarf_vmatoa ("x", offsets
[DW_SECT_LINE
]),
2336 dwarf_vmatoa ("x", sizes
[DW_SECT_LINE
]));
2337 printf (_(" .debug_loc.dwo: 0x%s 0x%s\n"),
2338 dwarf_vmatoa ("x", offsets
[DW_SECT_LOC
]),
2339 dwarf_vmatoa ("x", sizes
[DW_SECT_LOC
]));
2340 printf (_(" .debug_str_offsets.dwo: 0x%s 0x%s\n"),
2341 dwarf_vmatoa ("x", offsets
[DW_SECT_STR_OFFSETS
]),
2342 dwarf_vmatoa ("x", sizes
[DW_SECT_STR_OFFSETS
]));
2346 if (cu_offset
+ compunit
.cu_length
+ initial_length_size
2349 warn (_("Debug info is corrupted, length of CU at %s"
2350 " extends beyond end of section (length = %s)\n"),
2351 dwarf_vmatoa ("x", cu_offset
),
2352 dwarf_vmatoa ("x", compunit
.cu_length
));
2356 start
+= compunit
.cu_length
+ initial_length_size
;
2358 if (compunit
.cu_version
!= 2
2359 && compunit
.cu_version
!= 3
2360 && compunit
.cu_version
!= 4)
2362 warn (_("CU at offset %s contains corrupt or "
2363 "unsupported version number: %d.\n"),
2364 dwarf_vmatoa ("x", cu_offset
), compunit
.cu_version
);
2370 /* Process the abbrevs used by this compilation unit. DWARF
2371 sections under Mach-O have non-zero addresses. */
2372 if (compunit
.cu_abbrev_offset
>= abbrev_size
)
2373 warn (_("Debug info is corrupted, abbrev offset (%lx) is larger than abbrev section size (%lx)\n"),
2374 (unsigned long) compunit
.cu_abbrev_offset
,
2375 (unsigned long) abbrev_size
);
2377 process_abbrev_section
2378 (((unsigned char *) debug_displays
[abbrev_sec
].section
.start
2379 + abbrev_base
+ compunit
.cu_abbrev_offset
),
2380 ((unsigned char *) debug_displays
[abbrev_sec
].section
.start
2381 + abbrev_base
+ abbrev_size
));
2386 while (tags
< start
)
2388 unsigned int bytes_read
;
2389 unsigned long abbrev_number
;
2390 unsigned long die_offset
;
2391 abbrev_entry
*entry
;
2393 int do_printing
= 1;
2395 die_offset
= tags
- section_begin
;
2397 abbrev_number
= read_uleb128 (tags
, & bytes_read
, start
);
2400 /* A null DIE marks the end of a list of siblings or it may also be
2401 a section padding. */
2402 if (abbrev_number
== 0)
2404 /* Check if it can be a section padding for the last CU. */
2405 if (level
== 0 && start
== end
)
2409 for (chk
= tags
; chk
< start
; chk
++)
2416 if (!do_loc
&& die_offset
>= dwarf_start_die
2417 && (dwarf_cutoff_level
== -1
2418 || level
< dwarf_cutoff_level
))
2419 printf (_(" <%d><%lx>: Abbrev Number: 0\n"),
2425 static unsigned num_bogus_warns
= 0;
2427 if (num_bogus_warns
< 3)
2429 warn (_("Bogus end-of-siblings marker detected at offset %lx in %s section\n"),
2430 die_offset
, section
->name
);
2432 if (num_bogus_warns
== 3)
2433 warn (_("Further warnings about bogus end-of-sibling markers suppressed\n"));
2436 if (dwarf_start_die
!= 0 && level
< saved_level
)
2443 if (dwarf_start_die
!= 0 && die_offset
< dwarf_start_die
)
2447 if (dwarf_start_die
!= 0 && die_offset
== dwarf_start_die
)
2448 saved_level
= level
;
2449 do_printing
= (dwarf_cutoff_level
== -1
2450 || level
< dwarf_cutoff_level
);
2452 printf (_(" <%d><%lx>: Abbrev Number: %lu"),
2453 level
, die_offset
, abbrev_number
);
2454 else if (dwarf_cutoff_level
== -1
2455 || last_level
< dwarf_cutoff_level
)
2456 printf (_(" <%d><%lx>: ...\n"), level
, die_offset
);
2461 /* Scan through the abbreviation list until we reach the
2463 for (entry
= first_abbrev
;
2464 entry
&& entry
->entry
!= abbrev_number
;
2465 entry
= entry
->next
)
2470 if (!do_loc
&& do_printing
)
2475 warn (_("DIE at offset %lx refers to abbreviation number %lu which does not exist\n"),
2476 die_offset
, abbrev_number
);
2480 if (!do_loc
&& do_printing
)
2481 printf (" (%s)\n", get_TAG_name (entry
->tag
));
2486 need_base_address
= 0;
2488 case DW_TAG_compile_unit
:
2489 need_base_address
= 1;
2491 case DW_TAG_entry_point
:
2492 case DW_TAG_subprogram
:
2493 need_base_address
= 0;
2494 /* Assuming that there is no DW_AT_frame_base. */
2495 have_frame_base
= 0;
2499 for (attr
= entry
->first_attr
;
2500 attr
&& attr
->attribute
;
2505 if (! do_loc
&& do_printing
)
2506 /* Show the offset from where the tag was extracted. */
2507 printf (" <%lx>", (unsigned long)(tags
- section_begin
));
2509 arg
= debug_information
;
2510 if (debug_information
)
2513 tags
= read_and_display_attr (attr
->attribute
,
2518 compunit
.cu_pointer_size
,
2520 compunit
.cu_version
,
2522 do_loc
|| ! do_printing
,
2527 if (entry
->children
)
2532 /* Set num_debug_info_entries here so that it can be used to check if
2533 we need to process .debug_loc and .debug_ranges sections. */
2534 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
2535 && num_debug_info_entries
== 0
2537 num_debug_info_entries
= num_units
;
2545 /* Locate and scan the .debug_info section in the file and record the pointer
2546 sizes and offsets for the compilation units in it. Usually an executable
2547 will have just one pointer size, but this is not guaranteed, and so we try
2548 not to make any assumptions. Returns zero upon failure, or the number of
2549 compilation units upon success. */
2552 load_debug_info (void * file
)
2554 /* Reset the last pointer size so that we can issue correct error
2555 messages if we are displaying the contents of more than one section. */
2556 last_pointer_size
= 0;
2557 warned_about_missing_comp_units
= FALSE
;
2559 /* If we have already tried and failed to load the .debug_info
2560 section then do not bother to repeat the task. */
2561 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
2564 /* If we already have the information there is nothing else to do. */
2565 if (num_debug_info_entries
> 0)
2566 return num_debug_info_entries
;
2568 /* If this is a DWARF package file, load the CU and TU indexes. */
2569 load_cu_tu_indexes (file
);
2571 if (load_debug_section (info
, file
)
2572 && process_debug_info (&debug_displays
[info
].section
, file
, abbrev
, 1, 0))
2573 return num_debug_info_entries
;
2574 else if (load_debug_section (info_dwo
, file
)
2575 && process_debug_info (&debug_displays
[info_dwo
].section
, file
,
2577 return num_debug_info_entries
;
2579 num_debug_info_entries
= DEBUG_INFO_UNAVAILABLE
;
2583 /* Read a DWARF .debug_line section header starting at DATA.
2584 Upon success returns an updated DATA pointer and the LINFO
2585 structure and the END_OF_SEQUENCE pointer will be filled in.
2586 Otherwise returns NULL. */
2588 static unsigned char *
2589 read_debug_line_header (struct dwarf_section
* section
,
2590 unsigned char * data
,
2591 unsigned char * end
,
2592 DWARF2_Internal_LineInfo
* linfo
,
2593 unsigned char ** end_of_sequence
)
2595 unsigned char *hdrptr
;
2596 unsigned int offset_size
;
2597 unsigned int initial_length_size
;
2599 /* Extract information from the Line Number Program Header.
2600 (section 6.2.4 in the Dwarf3 doc). */
2603 /* Get and check the length of the block. */
2604 SAFE_BYTE_GET_AND_INC (linfo
->li_length
, hdrptr
, 4, end
);
2606 if (linfo
->li_length
== 0xffffffff)
2608 /* This section is 64-bit DWARF 3. */
2609 SAFE_BYTE_GET_AND_INC (linfo
->li_length
, hdrptr
, 8, end
);
2611 initial_length_size
= 12;
2616 initial_length_size
= 4;
2619 if (linfo
->li_length
+ initial_length_size
> section
->size
)
2621 /* If the length is just a bias against the initial_length_size then
2622 this means that the field has a relocation against it which has not
2623 been applied. (Ie we are dealing with an object file, not a linked
2624 binary). Do not complain but instead assume that the rest of the
2625 section applies to this particular header. */
2626 if (linfo
->li_length
== - initial_length_size
)
2628 linfo
->li_length
= section
->size
- initial_length_size
;
2632 warn (_("The line info appears to be corrupt - "
2633 "the section is too small\n"));
2638 /* Get and check the version number. */
2639 SAFE_BYTE_GET_AND_INC (linfo
->li_version
, hdrptr
, 2, end
);
2641 if (linfo
->li_version
!= 2
2642 && linfo
->li_version
!= 3
2643 && linfo
->li_version
!= 4)
2645 warn (_("Only DWARF version 2, 3 and 4 line info is currently supported.\n"));
2649 SAFE_BYTE_GET_AND_INC (linfo
->li_prologue_length
, hdrptr
, offset_size
, end
);
2650 SAFE_BYTE_GET_AND_INC (linfo
->li_min_insn_length
, hdrptr
, 1, end
);
2652 if (linfo
->li_version
>= 4)
2654 SAFE_BYTE_GET_AND_INC (linfo
->li_max_ops_per_insn
, hdrptr
, 1, end
);
2656 if (linfo
->li_max_ops_per_insn
== 0)
2658 warn (_("Invalid maximum operations per insn.\n"));
2663 linfo
->li_max_ops_per_insn
= 1;
2665 SAFE_BYTE_GET_AND_INC (linfo
->li_default_is_stmt
, hdrptr
, 1, end
);
2666 SAFE_BYTE_GET_AND_INC (linfo
->li_line_base
, hdrptr
, 1, end
);
2667 SAFE_BYTE_GET_AND_INC (linfo
->li_line_range
, hdrptr
, 1, end
);
2668 SAFE_BYTE_GET_AND_INC (linfo
->li_opcode_base
, hdrptr
, 1, end
);
2670 /* Sign extend the line base field. */
2671 linfo
->li_line_base
<<= 24;
2672 linfo
->li_line_base
>>= 24;
2674 * end_of_sequence
= data
+ linfo
->li_length
+ initial_length_size
;
2679 display_debug_lines_raw (struct dwarf_section
*section
,
2680 unsigned char *data
,
2683 unsigned char *start
= section
->start
;
2685 printf (_("Raw dump of debug contents of section %s:\n\n"),
2690 static DWARF2_Internal_LineInfo saved_linfo
;
2691 DWARF2_Internal_LineInfo linfo
;
2692 unsigned char *standard_opcodes
;
2693 unsigned char *end_of_sequence
;
2694 unsigned int last_dir_entry
= 0;
2697 if (const_strneq (section
->name
, ".debug_line.")
2698 /* Note: the following does not apply to .debug_line.dwo sections.
2699 These are full debug_line sections. */
2700 && strcmp (section
->name
, ".debug_line.dwo") != 0)
2702 /* Sections named .debug_line.<foo> are fragments of a .debug_line
2703 section containing just the Line Number Statements. They are
2704 created by the assembler and intended to be used alongside gcc's
2705 -ffunction-sections command line option. When the linker's
2706 garbage collection decides to discard a .text.<foo> section it
2707 can then also discard the line number information in .debug_line.<foo>.
2709 Since the section is a fragment it does not have the details
2710 needed to fill out a LineInfo structure, so instead we use the
2711 details from the last full debug_line section that we processed. */
2712 end_of_sequence
= end
;
2713 standard_opcodes
= NULL
;
2714 linfo
= saved_linfo
;
2715 reset_state_machine (linfo
.li_default_is_stmt
);
2719 unsigned char * hdrptr
;
2721 if ((hdrptr
= read_debug_line_header (section
, data
, end
, & linfo
,
2722 & end_of_sequence
)) == NULL
)
2725 printf (_(" Offset: 0x%lx\n"), (long)(data
- start
));
2726 printf (_(" Length: %ld\n"), (long) linfo
.li_length
);
2727 printf (_(" DWARF Version: %d\n"), linfo
.li_version
);
2728 printf (_(" Prologue Length: %d\n"), linfo
.li_prologue_length
);
2729 printf (_(" Minimum Instruction Length: %d\n"), linfo
.li_min_insn_length
);
2730 if (linfo
.li_version
>= 4)
2731 printf (_(" Maximum Ops per Instruction: %d\n"), linfo
.li_max_ops_per_insn
);
2732 printf (_(" Initial value of 'is_stmt': %d\n"), linfo
.li_default_is_stmt
);
2733 printf (_(" Line Base: %d\n"), linfo
.li_line_base
);
2734 printf (_(" Line Range: %d\n"), linfo
.li_line_range
);
2735 printf (_(" Opcode Base: %d\n"), linfo
.li_opcode_base
);
2737 reset_state_machine (linfo
.li_default_is_stmt
);
2739 /* Display the contents of the Opcodes table. */
2740 standard_opcodes
= hdrptr
;
2742 printf (_("\n Opcodes:\n"));
2744 for (i
= 1; i
< linfo
.li_opcode_base
; i
++)
2745 printf (_(" Opcode %d has %d args\n"), i
, standard_opcodes
[i
- 1]);
2747 /* Display the contents of the Directory table. */
2748 data
= standard_opcodes
+ linfo
.li_opcode_base
- 1;
2751 printf (_("\n The Directory Table is empty.\n"));
2754 printf (_("\n The Directory Table (offset 0x%lx):\n"),
2755 (long)(data
- start
));
2759 printf (" %d\t%s\n", ++last_dir_entry
, data
);
2761 data
+= strnlen ((char *) data
, end
- data
) + 1;
2765 /* Skip the NUL at the end of the table. */
2768 /* Display the contents of the File Name table. */
2770 printf (_("\n The File Name Table is empty.\n"));
2773 printf (_("\n The File Name Table (offset 0x%lx):\n"),
2774 (long)(data
- start
));
2775 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
2779 unsigned char *name
;
2780 unsigned int bytes_read
;
2782 printf (" %d\t", ++state_machine_regs
.last_file_entry
);
2784 data
+= strnlen ((char *) data
, end
- data
) + 1;
2787 dwarf_vmatoa ("u", read_uleb128 (data
, & bytes_read
, end
)));
2790 dwarf_vmatoa ("u", read_uleb128 (data
, & bytes_read
, end
)));
2793 dwarf_vmatoa ("u", read_uleb128 (data
, & bytes_read
, end
)));
2795 printf ("%s\n", name
);
2799 warn (_("Corrupt file name table entry\n"));
2805 /* Skip the NUL at the end of the table. */
2808 saved_linfo
= linfo
;
2811 /* Now display the statements. */
2812 if (data
>= end_of_sequence
)
2813 printf (_(" No Line Number Statements.\n"));
2816 printf (_(" Line Number Statements:\n"));
2818 while (data
< end_of_sequence
)
2820 unsigned char op_code
;
2821 dwarf_signed_vma adv
;
2823 unsigned int bytes_read
;
2825 printf (" [0x%08lx]", (long)(data
- start
));
2829 if (op_code
>= linfo
.li_opcode_base
)
2831 op_code
-= linfo
.li_opcode_base
;
2832 uladv
= (op_code
/ linfo
.li_line_range
);
2833 if (linfo
.li_max_ops_per_insn
== 1)
2835 uladv
*= linfo
.li_min_insn_length
;
2836 state_machine_regs
.address
+= uladv
;
2837 printf (_(" Special opcode %d: "
2838 "advance Address by %s to 0x%s"),
2839 op_code
, dwarf_vmatoa ("u", uladv
),
2840 dwarf_vmatoa ("x", state_machine_regs
.address
));
2844 state_machine_regs
.address
2845 += ((state_machine_regs
.op_index
+ uladv
)
2846 / linfo
.li_max_ops_per_insn
)
2847 * linfo
.li_min_insn_length
;
2848 state_machine_regs
.op_index
2849 = (state_machine_regs
.op_index
+ uladv
)
2850 % linfo
.li_max_ops_per_insn
;
2851 printf (_(" Special opcode %d: "
2852 "advance Address by %s to 0x%s[%d]"),
2853 op_code
, dwarf_vmatoa ("u", uladv
),
2854 dwarf_vmatoa ("x", state_machine_regs
.address
),
2855 state_machine_regs
.op_index
);
2857 adv
= (op_code
% linfo
.li_line_range
) + linfo
.li_line_base
;
2858 state_machine_regs
.line
+= adv
;
2859 printf (_(" and Line by %s to %d\n"),
2860 dwarf_vmatoa ("d", adv
), state_machine_regs
.line
);
2862 else switch (op_code
)
2864 case DW_LNS_extended_op
:
2865 data
+= process_extended_line_op (data
, linfo
.li_default_is_stmt
, end
);
2869 printf (_(" Copy\n"));
2872 case DW_LNS_advance_pc
:
2873 uladv
= read_uleb128 (data
, & bytes_read
, end
);
2875 if (linfo
.li_max_ops_per_insn
== 1)
2877 uladv
*= linfo
.li_min_insn_length
;
2878 state_machine_regs
.address
+= uladv
;
2879 printf (_(" Advance PC by %s to 0x%s\n"),
2880 dwarf_vmatoa ("u", uladv
),
2881 dwarf_vmatoa ("x", state_machine_regs
.address
));
2885 state_machine_regs
.address
2886 += ((state_machine_regs
.op_index
+ uladv
)
2887 / linfo
.li_max_ops_per_insn
)
2888 * linfo
.li_min_insn_length
;
2889 state_machine_regs
.op_index
2890 = (state_machine_regs
.op_index
+ uladv
)
2891 % linfo
.li_max_ops_per_insn
;
2892 printf (_(" Advance PC by %s to 0x%s[%d]\n"),
2893 dwarf_vmatoa ("u", uladv
),
2894 dwarf_vmatoa ("x", state_machine_regs
.address
),
2895 state_machine_regs
.op_index
);
2899 case DW_LNS_advance_line
:
2900 adv
= read_sleb128 (data
, & bytes_read
, end
);
2902 state_machine_regs
.line
+= adv
;
2903 printf (_(" Advance Line by %s to %d\n"),
2904 dwarf_vmatoa ("d", adv
),
2905 state_machine_regs
.line
);
2908 case DW_LNS_set_file
:
2909 adv
= read_uleb128 (data
, & bytes_read
, end
);
2911 printf (_(" Set File Name to entry %s in the File Name Table\n"),
2912 dwarf_vmatoa ("d", adv
));
2913 state_machine_regs
.file
= adv
;
2916 case DW_LNS_set_column
:
2917 uladv
= read_uleb128 (data
, & bytes_read
, end
);
2919 printf (_(" Set column to %s\n"),
2920 dwarf_vmatoa ("u", uladv
));
2921 state_machine_regs
.column
= uladv
;
2924 case DW_LNS_negate_stmt
:
2925 adv
= state_machine_regs
.is_stmt
;
2927 printf (_(" Set is_stmt to %s\n"), dwarf_vmatoa ("d", adv
));
2928 state_machine_regs
.is_stmt
= adv
;
2931 case DW_LNS_set_basic_block
:
2932 printf (_(" Set basic block\n"));
2933 state_machine_regs
.basic_block
= 1;
2936 case DW_LNS_const_add_pc
:
2937 uladv
= ((255 - linfo
.li_opcode_base
) / linfo
.li_line_range
);
2938 if (linfo
.li_max_ops_per_insn
)
2940 uladv
*= linfo
.li_min_insn_length
;
2941 state_machine_regs
.address
+= uladv
;
2942 printf (_(" Advance PC by constant %s to 0x%s\n"),
2943 dwarf_vmatoa ("u", uladv
),
2944 dwarf_vmatoa ("x", state_machine_regs
.address
));
2948 state_machine_regs
.address
2949 += ((state_machine_regs
.op_index
+ uladv
)
2950 / linfo
.li_max_ops_per_insn
)
2951 * linfo
.li_min_insn_length
;
2952 state_machine_regs
.op_index
2953 = (state_machine_regs
.op_index
+ uladv
)
2954 % linfo
.li_max_ops_per_insn
;
2955 printf (_(" Advance PC by constant %s to 0x%s[%d]\n"),
2956 dwarf_vmatoa ("u", uladv
),
2957 dwarf_vmatoa ("x", state_machine_regs
.address
),
2958 state_machine_regs
.op_index
);
2962 case DW_LNS_fixed_advance_pc
:
2963 SAFE_BYTE_GET_AND_INC (uladv
, data
, 2, end
);
2964 state_machine_regs
.address
+= uladv
;
2965 state_machine_regs
.op_index
= 0;
2966 printf (_(" Advance PC by fixed size amount %s to 0x%s\n"),
2967 dwarf_vmatoa ("u", uladv
),
2968 dwarf_vmatoa ("x", state_machine_regs
.address
));
2971 case DW_LNS_set_prologue_end
:
2972 printf (_(" Set prologue_end to true\n"));
2975 case DW_LNS_set_epilogue_begin
:
2976 printf (_(" Set epilogue_begin to true\n"));
2979 case DW_LNS_set_isa
:
2980 uladv
= read_uleb128 (data
, & bytes_read
, end
);
2982 printf (_(" Set ISA to %s\n"), dwarf_vmatoa ("u", uladv
));
2986 printf (_(" Unknown opcode %d with operands: "), op_code
);
2988 if (standard_opcodes
!= NULL
)
2989 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
2991 printf ("0x%s%s", dwarf_vmatoa ("x", read_uleb128 (data
,
2993 i
== 1 ? "" : ", ");
3009 unsigned char *name
;
3010 unsigned int directory_index
;
3011 unsigned int modification_date
;
3012 unsigned int length
;
3015 /* Output a decoded representation of the .debug_line section. */
3018 display_debug_lines_decoded (struct dwarf_section
*section
,
3019 unsigned char *data
,
3022 static DWARF2_Internal_LineInfo saved_linfo
;
3024 printf (_("Decoded dump of debug contents of section %s:\n\n"),
3029 /* This loop amounts to one iteration per compilation unit. */
3030 DWARF2_Internal_LineInfo linfo
;
3031 unsigned char *standard_opcodes
;
3032 unsigned char *end_of_sequence
;
3034 File_Entry
*file_table
= NULL
;
3035 unsigned int n_files
= 0;
3036 unsigned char **directory_table
= NULL
;
3037 unsigned int n_directories
= 0;
3039 if (const_strneq (section
->name
, ".debug_line.")
3040 /* Note: the following does not apply to .debug_line.dwo sections.
3041 These are full debug_line sections. */
3042 && strcmp (section
->name
, ".debug_line.dwo") != 0)
3044 /* See comment in display_debug_lines_raw(). */
3045 end_of_sequence
= end
;
3046 standard_opcodes
= NULL
;
3047 linfo
= saved_linfo
;
3048 reset_state_machine (linfo
.li_default_is_stmt
);
3052 unsigned char *hdrptr
;
3054 if ((hdrptr
= read_debug_line_header (section
, data
, end
, & linfo
,
3055 & end_of_sequence
)) == NULL
)
3058 reset_state_machine (linfo
.li_default_is_stmt
);
3060 /* Save a pointer to the contents of the Opcodes table. */
3061 standard_opcodes
= hdrptr
;
3063 /* Traverse the Directory table just to count entries. */
3064 data
= standard_opcodes
+ linfo
.li_opcode_base
- 1;
3067 unsigned char *ptr_directory_table
= data
;
3071 data
+= strnlen ((char *) data
, end
- data
) + 1;
3075 /* Go through the directory table again to save the directories. */
3076 directory_table
= (unsigned char **)
3077 xmalloc (n_directories
* sizeof (unsigned char *));
3080 while (*ptr_directory_table
!= 0)
3082 directory_table
[i
] = ptr_directory_table
;
3083 ptr_directory_table
+= strnlen ((char *) ptr_directory_table
,
3084 ptr_directory_table
- end
) + 1;
3088 /* Skip the NUL at the end of the table. */
3091 /* Traverse the File Name table just to count the entries. */
3094 unsigned char *ptr_file_name_table
= data
;
3098 unsigned int bytes_read
;
3100 /* Skip Name, directory index, last modification time and length
3102 data
+= strnlen ((char *) data
, end
- data
) + 1;
3103 read_uleb128 (data
, & bytes_read
, end
);
3105 read_uleb128 (data
, & bytes_read
, end
);
3107 read_uleb128 (data
, & bytes_read
, end
);
3113 /* Go through the file table again to save the strings. */
3114 file_table
= (File_Entry
*) xmalloc (n_files
* sizeof (File_Entry
));
3117 while (*ptr_file_name_table
!= 0)
3119 unsigned int bytes_read
;
3121 file_table
[i
].name
= ptr_file_name_table
;
3122 ptr_file_name_table
+= strnlen ((char *) ptr_file_name_table
,
3123 end
- ptr_file_name_table
) + 1;
3125 /* We are not interested in directory, time or size. */
3126 file_table
[i
].directory_index
= read_uleb128 (ptr_file_name_table
,
3128 ptr_file_name_table
+= bytes_read
;
3129 file_table
[i
].modification_date
= read_uleb128 (ptr_file_name_table
,
3131 ptr_file_name_table
+= bytes_read
;
3132 file_table
[i
].length
= read_uleb128 (ptr_file_name_table
, & bytes_read
, end
);
3133 ptr_file_name_table
+= bytes_read
;
3138 /* Print the Compilation Unit's name and a header. */
3139 if (directory_table
== NULL
)
3141 printf (_("CU: %s:\n"), file_table
[0].name
);
3142 printf (_("File name Line number Starting address\n"));
3146 unsigned int ix
= file_table
[0].directory_index
;
3147 const char *directory
= ix
? (char *)directory_table
[ix
- 1] : ".";
3149 if (do_wide
|| strlen (directory
) < 76)
3150 printf (_("CU: %s/%s:\n"), directory
, file_table
[0].name
);
3152 printf ("%s:\n", file_table
[0].name
);
3154 printf (_("File name Line number Starting address\n"));
3158 /* Skip the NUL at the end of the table. */
3161 saved_linfo
= linfo
;
3164 /* This loop iterates through the Dwarf Line Number Program. */
3165 while (data
< end_of_sequence
)
3167 unsigned char op_code
;
3169 unsigned long int uladv
;
3170 unsigned int bytes_read
;
3171 int is_special_opcode
= 0;
3175 if (op_code
>= linfo
.li_opcode_base
)
3177 op_code
-= linfo
.li_opcode_base
;
3178 uladv
= (op_code
/ linfo
.li_line_range
);
3179 if (linfo
.li_max_ops_per_insn
== 1)
3181 uladv
*= linfo
.li_min_insn_length
;
3182 state_machine_regs
.address
+= uladv
;
3186 state_machine_regs
.address
3187 += ((state_machine_regs
.op_index
+ uladv
)
3188 / linfo
.li_max_ops_per_insn
)
3189 * linfo
.li_min_insn_length
;
3190 state_machine_regs
.op_index
3191 = (state_machine_regs
.op_index
+ uladv
)
3192 % linfo
.li_max_ops_per_insn
;
3195 adv
= (op_code
% linfo
.li_line_range
) + linfo
.li_line_base
;
3196 state_machine_regs
.line
+= adv
;
3197 is_special_opcode
= 1;
3199 else switch (op_code
)
3201 case DW_LNS_extended_op
:
3203 unsigned int ext_op_code_len
;
3204 unsigned char ext_op_code
;
3205 unsigned char *op_code_data
= data
;
3207 ext_op_code_len
= read_uleb128 (op_code_data
, &bytes_read
,
3209 op_code_data
+= bytes_read
;
3211 if (ext_op_code_len
== 0)
3213 warn (_("badly formed extended line op encountered!\n"));
3216 ext_op_code_len
+= bytes_read
;
3217 ext_op_code
= *op_code_data
++;
3219 switch (ext_op_code
)
3221 case DW_LNE_end_sequence
:
3222 reset_state_machine (linfo
.li_default_is_stmt
);
3224 case DW_LNE_set_address
:
3225 SAFE_BYTE_GET_AND_INC (state_machine_regs
.address
,
3227 ext_op_code_len
- bytes_read
- 1,
3229 state_machine_regs
.op_index
= 0;
3231 case DW_LNE_define_file
:
3233 file_table
= (File_Entry
*) xrealloc
3234 (file_table
, (n_files
+ 1) * sizeof (File_Entry
));
3236 ++state_machine_regs
.last_file_entry
;
3237 /* Source file name. */
3238 file_table
[n_files
].name
= op_code_data
;
3239 op_code_data
+= strlen ((char *) op_code_data
) + 1;
3240 /* Directory index. */
3241 file_table
[n_files
].directory_index
=
3242 read_uleb128 (op_code_data
, & bytes_read
,
3244 op_code_data
+= bytes_read
;
3245 /* Last modification time. */
3246 file_table
[n_files
].modification_date
=
3247 read_uleb128 (op_code_data
, & bytes_read
,
3249 op_code_data
+= bytes_read
;
3251 file_table
[n_files
].length
=
3252 read_uleb128 (op_code_data
, & bytes_read
,
3258 case DW_LNE_set_discriminator
:
3259 case DW_LNE_HP_set_sequence
:
3260 /* Simply ignored. */
3264 printf (_("UNKNOWN (%u): length %d\n"),
3265 ext_op_code
, ext_op_code_len
- bytes_read
);
3268 data
+= ext_op_code_len
;
3274 case DW_LNS_advance_pc
:
3275 uladv
= read_uleb128 (data
, & bytes_read
, end
);
3277 if (linfo
.li_max_ops_per_insn
== 1)
3279 uladv
*= linfo
.li_min_insn_length
;
3280 state_machine_regs
.address
+= uladv
;
3284 state_machine_regs
.address
3285 += ((state_machine_regs
.op_index
+ uladv
)
3286 / linfo
.li_max_ops_per_insn
)
3287 * linfo
.li_min_insn_length
;
3288 state_machine_regs
.op_index
3289 = (state_machine_regs
.op_index
+ uladv
)
3290 % linfo
.li_max_ops_per_insn
;
3294 case DW_LNS_advance_line
:
3295 adv
= read_sleb128 (data
, & bytes_read
, end
);
3297 state_machine_regs
.line
+= adv
;
3300 case DW_LNS_set_file
:
3301 adv
= read_uleb128 (data
, & bytes_read
, end
);
3303 state_machine_regs
.file
= adv
;
3305 if (file_table
== NULL
)
3306 printf (_("\n [Use file table entry %d]\n"), state_machine_regs
.file
- 1);
3307 else if (file_table
[state_machine_regs
.file
- 1].directory_index
== 0)
3308 /* If directory index is 0, that means current directory. */
3309 printf ("\n./%s:[++]\n",
3310 file_table
[state_machine_regs
.file
- 1].name
);
3311 else if (directory_table
== NULL
)
3312 printf (_("\n [Use directory table entry %d]\n"),
3313 file_table
[state_machine_regs
.file
- 1].directory_index
- 1);
3315 /* The directory index starts counting at 1. */
3316 printf ("\n%s/%s:\n",
3317 directory_table
[file_table
[state_machine_regs
.file
- 1].directory_index
- 1],
3318 file_table
[state_machine_regs
.file
- 1].name
);
3321 case DW_LNS_set_column
:
3322 uladv
= read_uleb128 (data
, & bytes_read
, end
);
3324 state_machine_regs
.column
= uladv
;
3327 case DW_LNS_negate_stmt
:
3328 adv
= state_machine_regs
.is_stmt
;
3330 state_machine_regs
.is_stmt
= adv
;
3333 case DW_LNS_set_basic_block
:
3334 state_machine_regs
.basic_block
= 1;
3337 case DW_LNS_const_add_pc
:
3338 uladv
= ((255 - linfo
.li_opcode_base
) / linfo
.li_line_range
);
3339 if (linfo
.li_max_ops_per_insn
== 1)
3341 uladv
*= linfo
.li_min_insn_length
;
3342 state_machine_regs
.address
+= uladv
;
3346 state_machine_regs
.address
3347 += ((state_machine_regs
.op_index
+ uladv
)
3348 / linfo
.li_max_ops_per_insn
)
3349 * linfo
.li_min_insn_length
;
3350 state_machine_regs
.op_index
3351 = (state_machine_regs
.op_index
+ uladv
)
3352 % linfo
.li_max_ops_per_insn
;
3356 case DW_LNS_fixed_advance_pc
:
3357 SAFE_BYTE_GET_AND_INC (uladv
, data
, 2, end
);
3358 state_machine_regs
.address
+= uladv
;
3359 state_machine_regs
.op_index
= 0;
3362 case DW_LNS_set_prologue_end
:
3365 case DW_LNS_set_epilogue_begin
:
3368 case DW_LNS_set_isa
:
3369 uladv
= read_uleb128 (data
, & bytes_read
, end
);
3371 printf (_(" Set ISA to %lu\n"), uladv
);
3375 printf (_(" Unknown opcode %d with operands: "), op_code
);
3377 if (standard_opcodes
!= NULL
)
3378 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
3380 printf ("0x%s%s", dwarf_vmatoa ("x", read_uleb128 (data
,
3382 i
== 1 ? "" : ", ");
3389 /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row
3390 to the DWARF address/line matrix. */
3391 if ((is_special_opcode
) || (op_code
== DW_LNE_end_sequence
)
3392 || (op_code
== DW_LNS_copy
))
3394 const unsigned int MAX_FILENAME_LENGTH
= 35;
3396 char *newFileName
= NULL
;
3397 size_t fileNameLength
;
3400 fileName
= (char *) file_table
[state_machine_regs
.file
- 1].name
;
3402 fileName
= "<unknown>";
3404 fileNameLength
= strlen (fileName
);
3406 if ((fileNameLength
> MAX_FILENAME_LENGTH
) && (!do_wide
))
3408 newFileName
= (char *) xmalloc (MAX_FILENAME_LENGTH
+ 1);
3409 /* Truncate file name */
3410 strncpy (newFileName
,
3411 fileName
+ fileNameLength
- MAX_FILENAME_LENGTH
,
3412 MAX_FILENAME_LENGTH
+ 1);
3416 newFileName
= (char *) xmalloc (fileNameLength
+ 1);
3417 strncpy (newFileName
, fileName
, fileNameLength
+ 1);
3420 if (!do_wide
|| (fileNameLength
<= MAX_FILENAME_LENGTH
))
3422 if (linfo
.li_max_ops_per_insn
== 1)
3423 printf ("%-35s %11d %#18" DWARF_VMA_FMT
"x\n",
3424 newFileName
, state_machine_regs
.line
,
3425 state_machine_regs
.address
);
3427 printf ("%-35s %11d %#18" DWARF_VMA_FMT
"x[%d]\n",
3428 newFileName
, state_machine_regs
.line
,
3429 state_machine_regs
.address
,
3430 state_machine_regs
.op_index
);
3434 if (linfo
.li_max_ops_per_insn
== 1)
3435 printf ("%s %11d %#18" DWARF_VMA_FMT
"x\n",
3436 newFileName
, state_machine_regs
.line
,
3437 state_machine_regs
.address
);
3439 printf ("%s %11d %#18" DWARF_VMA_FMT
"x[%d]\n",
3440 newFileName
, state_machine_regs
.line
,
3441 state_machine_regs
.address
,
3442 state_machine_regs
.op_index
);
3445 if (op_code
== DW_LNE_end_sequence
)
3459 if (directory_table
)
3461 free (directory_table
);
3462 directory_table
= NULL
;
3473 display_debug_lines (struct dwarf_section
*section
, void *file ATTRIBUTE_UNUSED
)
3475 unsigned char *data
= section
->start
;
3476 unsigned char *end
= data
+ section
->size
;
3478 int retValDecoded
= 1;
3480 if (do_debug_lines
== 0)
3481 do_debug_lines
|= FLAG_DEBUG_LINES_RAW
;
3483 if (do_debug_lines
& FLAG_DEBUG_LINES_RAW
)
3484 retValRaw
= display_debug_lines_raw (section
, data
, end
);
3486 if (do_debug_lines
& FLAG_DEBUG_LINES_DECODED
)
3487 retValDecoded
= display_debug_lines_decoded (section
, data
, end
);
3489 if (!retValRaw
|| !retValDecoded
)
3496 find_debug_info_for_offset (unsigned long offset
)
3500 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
3503 for (i
= 0; i
< num_debug_info_entries
; i
++)
3504 if (debug_information
[i
].cu_offset
== offset
)
3505 return debug_information
+ i
;
3511 display_debug_pubnames (struct dwarf_section
*section
,
3512 void *file ATTRIBUTE_UNUSED
)
3514 DWARF2_Internal_PubNames names
;
3515 unsigned char *start
= section
->start
;
3516 unsigned char *end
= start
+ section
->size
;
3518 /* It does not matter if this load fails,
3519 we test for that later on. */
3520 load_debug_info (file
);
3522 printf (_("Contents of the %s section:\n\n"), section
->name
);
3526 unsigned char *data
;
3527 unsigned long offset
;
3528 unsigned int offset_size
, initial_length_size
;
3532 SAFE_BYTE_GET_AND_INC (names
.pn_length
, data
, 4, end
);
3533 if (names
.pn_length
== 0xffffffff)
3535 SAFE_BYTE_GET_AND_INC (names
.pn_length
, data
, 8, end
);
3537 initial_length_size
= 12;
3542 initial_length_size
= 4;
3545 SAFE_BYTE_GET_AND_INC (names
.pn_version
, data
, 2, end
);
3546 SAFE_BYTE_GET_AND_INC (names
.pn_offset
, data
, offset_size
, end
);
3548 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
3549 && num_debug_info_entries
> 0
3550 && find_debug_info_for_offset (names
.pn_offset
) == NULL
)
3551 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
3552 (unsigned long) names
.pn_offset
, section
->name
);
3554 SAFE_BYTE_GET_AND_INC (names
.pn_size
, data
, offset_size
, end
);
3556 start
+= names
.pn_length
+ initial_length_size
;
3558 if (names
.pn_version
!= 2 && names
.pn_version
!= 3)
3560 static int warned
= 0;
3564 warn (_("Only DWARF 2 and 3 pubnames are currently supported\n"));
3571 printf (_(" Length: %ld\n"),
3572 (long) names
.pn_length
);
3573 printf (_(" Version: %d\n"),
3575 printf (_(" Offset into .debug_info section: 0x%lx\n"),
3576 (unsigned long) names
.pn_offset
);
3577 printf (_(" Size of area in .debug_info section: %ld\n"),
3578 (long) names
.pn_size
);
3580 printf (_("\n Offset\tName\n"));
3584 SAFE_BYTE_GET (offset
, data
, offset_size
, end
);
3588 data
+= offset_size
;
3589 printf (" %-6lx\t%s\n", offset
, data
);
3590 data
+= strnlen ((char *) data
, end
- data
) + 1;
3593 while (offset
!= 0);
3601 display_debug_macinfo (struct dwarf_section
*section
,
3602 void *file ATTRIBUTE_UNUSED
)
3604 unsigned char *start
= section
->start
;
3605 unsigned char *end
= start
+ section
->size
;
3606 unsigned char *curr
= start
;
3607 unsigned int bytes_read
;
3608 enum dwarf_macinfo_record_type op
;
3610 printf (_("Contents of the %s section:\n\n"), section
->name
);
3614 unsigned int lineno
;
3615 const unsigned char *string
;
3617 op
= (enum dwarf_macinfo_record_type
) *curr
;
3622 case DW_MACINFO_start_file
:
3624 unsigned int filenum
;
3626 lineno
= read_uleb128 (curr
, & bytes_read
, end
);
3628 filenum
= read_uleb128 (curr
, & bytes_read
, end
);
3631 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"),
3636 case DW_MACINFO_end_file
:
3637 printf (_(" DW_MACINFO_end_file\n"));
3640 case DW_MACINFO_define
:
3641 lineno
= read_uleb128 (curr
, & bytes_read
, end
);
3644 curr
+= strnlen ((char *) string
, end
- string
) + 1;
3645 printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"),
3649 case DW_MACINFO_undef
:
3650 lineno
= read_uleb128 (curr
, & bytes_read
, end
);
3653 curr
+= strnlen ((char *) string
, end
- string
) + 1;
3654 printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"),
3658 case DW_MACINFO_vendor_ext
:
3660 unsigned int constant
;
3662 constant
= read_uleb128 (curr
, & bytes_read
, end
);
3665 curr
+= strnlen ((char *) string
, end
- string
) + 1;
3666 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"),
3676 /* Given LINE_OFFSET into the .debug_line section, attempt to return
3677 filename and dirname corresponding to file name table entry with index
3678 FILEIDX. Return NULL on failure. */
3680 static unsigned char *
3681 get_line_filename_and_dirname (dwarf_vma line_offset
,
3683 unsigned char **dir_name
)
3685 struct dwarf_section
*section
= &debug_displays
[line
].section
;
3686 unsigned char *hdrptr
, *dirtable
, *file_name
;
3687 unsigned int offset_size
, initial_length_size
;
3688 unsigned int version
, opcode_base
, bytes_read
;
3689 dwarf_vma length
, diridx
;
3690 const unsigned char * end
;
3693 if (section
->start
== NULL
3694 || line_offset
>= section
->size
3698 hdrptr
= section
->start
+ line_offset
;
3699 end
= section
->start
+ section
->size
;
3701 SAFE_BYTE_GET_AND_INC (length
, hdrptr
, 4, end
);
3702 if (length
== 0xffffffff)
3704 /* This section is 64-bit DWARF 3. */
3705 SAFE_BYTE_GET_AND_INC (length
, hdrptr
, 8, end
);
3707 initial_length_size
= 12;
3712 initial_length_size
= 4;
3714 if (length
+ initial_length_size
> section
->size
)
3717 SAFE_BYTE_GET_AND_INC (version
, hdrptr
, 2, end
);
3718 if (version
!= 2 && version
!= 3 && version
!= 4)
3720 hdrptr
+= offset_size
+ 1;/* Skip prologue_length and min_insn_length. */
3722 hdrptr
++; /* Skip max_ops_per_insn. */
3723 hdrptr
+= 3; /* Skip default_is_stmt, line_base, line_range. */
3725 SAFE_BYTE_GET_AND_INC (opcode_base
, hdrptr
, 1, end
);
3726 if (opcode_base
== 0)
3729 hdrptr
+= opcode_base
- 1;
3731 /* Skip over dirname table. */
3732 while (*hdrptr
!= '\0')
3733 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
) + 1;
3734 hdrptr
++; /* Skip the NUL at the end of the table. */
3735 /* Now skip over preceding filename table entries. */
3736 for (; *hdrptr
!= '\0' && fileidx
> 1; fileidx
--)
3738 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
) + 1;
3739 read_uleb128 (hdrptr
, &bytes_read
, end
);
3740 hdrptr
+= bytes_read
;
3741 read_uleb128 (hdrptr
, &bytes_read
, end
);
3742 hdrptr
+= bytes_read
;
3743 read_uleb128 (hdrptr
, &bytes_read
, end
);
3744 hdrptr
+= bytes_read
;
3746 if (hdrptr
== end
|| *hdrptr
== '\0')
3749 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
) + 1;
3750 diridx
= read_uleb128 (hdrptr
, &bytes_read
, end
);
3753 for (; *dirtable
!= '\0' && diridx
> 1; diridx
--)
3754 dirtable
+= strnlen ((char *) dirtable
, end
- dirtable
) + 1;
3755 if (*dirtable
== '\0')
3757 *dir_name
= dirtable
;
3762 display_debug_macro (struct dwarf_section
*section
,
3765 unsigned char *start
= section
->start
;
3766 unsigned char *end
= start
+ section
->size
;
3767 unsigned char *curr
= start
;
3768 unsigned char *extended_op_buf
[256];
3769 unsigned int bytes_read
;
3771 load_debug_section (str
, file
);
3772 load_debug_section (line
, file
);
3774 printf (_("Contents of the %s section:\n\n"), section
->name
);
3778 unsigned int lineno
, version
, flags
;
3779 unsigned int offset_size
= 4;
3780 const unsigned char *string
;
3781 dwarf_vma line_offset
= 0, sec_offset
= curr
- start
, offset
;
3782 unsigned char **extended_ops
= NULL
;
3784 SAFE_BYTE_GET_AND_INC (version
, curr
, 2, end
);
3787 error (_("Only GNU extension to DWARF 4 of %s is currently supported.\n"),
3792 SAFE_BYTE_GET_AND_INC (flags
, curr
, 1, end
);
3795 printf (_(" Offset: 0x%lx\n"),
3796 (unsigned long) sec_offset
);
3797 printf (_(" Version: %d\n"), version
);
3798 printf (_(" Offset size: %d\n"), offset_size
);
3801 SAFE_BYTE_GET_AND_INC (line_offset
, curr
, offset_size
, end
);
3802 printf (_(" Offset into .debug_line: 0x%lx\n"),
3803 (unsigned long) line_offset
);
3807 unsigned int i
, count
, op
;
3810 SAFE_BYTE_GET_AND_INC (count
, curr
, 1, end
);
3812 memset (extended_op_buf
, 0, sizeof (extended_op_buf
));
3813 extended_ops
= extended_op_buf
;
3816 printf (_(" Extension opcode arguments:\n"));
3817 for (i
= 0; i
< count
; i
++)
3819 SAFE_BYTE_GET_AND_INC (op
, curr
, 1, end
);
3820 extended_ops
[op
] = curr
;
3821 nargs
= read_uleb128 (curr
, &bytes_read
, end
);
3824 printf (_(" DW_MACRO_GNU_%02x has no arguments\n"), op
);
3827 printf (_(" DW_MACRO_GNU_%02x arguments: "), op
);
3828 for (n
= 0; n
< nargs
; n
++)
3832 SAFE_BYTE_GET_AND_INC (form
, curr
, 1, end
);
3833 printf ("%s%s", get_FORM_name (form
),
3834 n
== nargs
- 1 ? "\n" : ", ");
3844 case DW_FORM_block1
:
3845 case DW_FORM_block2
:
3846 case DW_FORM_block4
:
3848 case DW_FORM_string
:
3850 case DW_FORM_sec_offset
:
3853 error (_("Invalid extension opcode form %s\n"),
3854 get_FORM_name (form
));
3870 error (_(".debug_macro section not zero terminated\n"));
3874 SAFE_BYTE_GET_AND_INC (op
, curr
, 1, end
);
3880 case DW_MACRO_GNU_start_file
:
3882 unsigned int filenum
;
3883 unsigned char *file_name
= NULL
, *dir_name
= NULL
;
3885 lineno
= read_uleb128 (curr
, &bytes_read
, end
);
3887 filenum
= read_uleb128 (curr
, &bytes_read
, end
);
3890 if ((flags
& 2) == 0)
3891 error (_("DW_MACRO_GNU_start_file used, but no .debug_line offset provided.\n"));
3894 = get_line_filename_and_dirname (line_offset
, filenum
,
3896 if (file_name
== NULL
)
3897 printf (_(" DW_MACRO_GNU_start_file - lineno: %d filenum: %d\n"),
3900 printf (_(" DW_MACRO_GNU_start_file - lineno: %d filenum: %d filename: %s%s%s\n"),
3902 dir_name
!= NULL
? (const char *) dir_name
: "",
3903 dir_name
!= NULL
? "/" : "", file_name
);
3907 case DW_MACRO_GNU_end_file
:
3908 printf (_(" DW_MACRO_GNU_end_file\n"));
3911 case DW_MACRO_GNU_define
:
3912 lineno
= read_uleb128 (curr
, &bytes_read
, end
);
3915 curr
+= strnlen ((char *) string
, end
- string
) + 1;
3916 printf (_(" DW_MACRO_GNU_define - lineno : %d macro : %s\n"),
3920 case DW_MACRO_GNU_undef
:
3921 lineno
= read_uleb128 (curr
, &bytes_read
, end
);
3924 curr
+= strnlen ((char *) string
, end
- string
) + 1;
3925 printf (_(" DW_MACRO_GNU_undef - lineno : %d macro : %s\n"),
3929 case DW_MACRO_GNU_define_indirect
:
3930 lineno
= read_uleb128 (curr
, &bytes_read
, end
);
3932 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
3933 string
= fetch_indirect_string (offset
);
3934 printf (_(" DW_MACRO_GNU_define_indirect - lineno : %d macro : %s\n"),
3938 case DW_MACRO_GNU_undef_indirect
:
3939 lineno
= read_uleb128 (curr
, &bytes_read
, end
);
3941 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
3942 string
= fetch_indirect_string (offset
);
3943 printf (_(" DW_MACRO_GNU_undef_indirect - lineno : %d macro : %s\n"),
3947 case DW_MACRO_GNU_transparent_include
:
3948 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
3949 printf (_(" DW_MACRO_GNU_transparent_include - offset : 0x%lx\n"),
3950 (unsigned long) offset
);
3953 case DW_MACRO_GNU_define_indirect_alt
:
3954 lineno
= read_uleb128 (curr
, &bytes_read
, end
);
3956 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
3957 printf (_(" DW_MACRO_GNU_define_indirect_alt - lineno : %d macro offset : 0x%lx\n"),
3958 lineno
, (unsigned long) offset
);
3961 case DW_MACRO_GNU_undef_indirect_alt
:
3962 lineno
= read_uleb128 (curr
, &bytes_read
, end
);
3964 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
3965 printf (_(" DW_MACRO_GNU_undef_indirect_alt - lineno : %d macro offset : 0x%lx\n"),
3966 lineno
, (unsigned long) offset
);
3969 case DW_MACRO_GNU_transparent_include_alt
:
3970 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
3971 printf (_(" DW_MACRO_GNU_transparent_include_alt - offset : 0x%lx\n"),
3972 (unsigned long) offset
);
3976 if (extended_ops
== NULL
|| extended_ops
[op
] == NULL
)
3978 error (_(" Unknown macro opcode %02x seen\n"), op
);
3983 /* Skip over unhandled opcodes. */
3985 unsigned char *desc
= extended_ops
[op
];
3986 nargs
= read_uleb128 (desc
, &bytes_read
, end
);
3990 printf (_(" DW_MACRO_GNU_%02x\n"), op
);
3993 printf (_(" DW_MACRO_GNU_%02x -"), op
);
3994 for (n
= 0; n
< nargs
; n
++)
3998 SAFE_BYTE_GET_AND_INC (val
, desc
, 1, end
);
4000 = read_and_display_attr_value (0, val
,
4001 curr
, end
, 0, 0, offset_size
,
4002 version
, NULL
, 0, NULL
,
4020 display_debug_abbrev (struct dwarf_section
*section
,
4021 void *file ATTRIBUTE_UNUSED
)
4023 abbrev_entry
*entry
;
4024 unsigned char *start
= section
->start
;
4025 unsigned char *end
= start
+ section
->size
;
4027 printf (_("Contents of the %s section:\n\n"), section
->name
);
4031 unsigned char *last
;
4036 start
= process_abbrev_section (start
, end
);
4038 if (first_abbrev
== NULL
)
4041 printf (_(" Number TAG (0x%lx)\n"), (long) (last
- section
->start
));
4043 for (entry
= first_abbrev
; entry
; entry
= entry
->next
)
4047 printf (" %ld %s [%s]\n",
4049 get_TAG_name (entry
->tag
),
4050 entry
->children
? _("has children") : _("no children"));
4052 for (attr
= entry
->first_attr
; attr
; attr
= attr
->next
)
4053 printf (" %-18s %s\n",
4054 get_AT_name (attr
->attribute
),
4055 get_FORM_name (attr
->form
));
4065 /* Display a location list from a normal (ie, non-dwo) .debug_loc section. */
4068 display_loc_list (struct dwarf_section
*section
,
4069 unsigned char **start_ptr
,
4070 int debug_info_entry
,
4071 unsigned long offset
,
4072 unsigned long base_address
,
4075 unsigned char *start
= *start_ptr
;
4076 unsigned char *section_end
= section
->start
+ section
->size
;
4077 unsigned long cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
4078 unsigned int pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
4079 unsigned int offset_size
= debug_information
[debug_info_entry
].offset_size
;
4080 int dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
4084 unsigned short length
;
4085 int need_frame_base
;
4089 if (start
+ 2 * pointer_size
> section_end
)
4091 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
4096 printf (" %8.8lx ", offset
+ (start
- *start_ptr
));
4098 /* Note: we use sign extension here in order to be sure that we can detect
4099 the -1 escape value. Sign extension into the top 32 bits of a 32-bit
4100 address will not affect the values that we display since we always show
4101 hex values, and always the bottom 32-bits. */
4102 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, section_end
);
4103 SAFE_BYTE_GET_AND_INC (end
, start
, pointer_size
, section_end
);
4105 if (begin
== 0 && end
== 0)
4107 printf (_("<End of list>\n"));
4111 /* Check base address specifiers. */
4112 if (begin
== (dwarf_vma
) -1 && end
!= (dwarf_vma
) -1)
4115 print_dwarf_vma (begin
, pointer_size
);
4116 print_dwarf_vma (end
, pointer_size
);
4117 printf (_("(base address)\n"));
4121 if (start
+ 2 > section_end
)
4123 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
4128 SAFE_BYTE_GET_AND_INC (length
, start
, 2, section_end
);
4130 if (start
+ length
> section_end
)
4132 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
4137 print_dwarf_vma (begin
+ base_address
, pointer_size
);
4138 print_dwarf_vma (end
+ base_address
, pointer_size
);
4141 need_frame_base
= decode_location_expression (start
,
4146 cu_offset
, section
);
4149 if (need_frame_base
&& !has_frame_base
)
4150 printf (_(" [without DW_AT_frame_base]"));
4153 fputs (_(" (start == end)"), stdout
);
4154 else if (begin
> end
)
4155 fputs (_(" (start > end)"), stdout
);
4165 /* Print a .debug_addr table index in decimal, surrounded by square brackets,
4166 right-adjusted in a field of length LEN, and followed by a space. */
4169 print_addr_index (unsigned int idx
, unsigned int len
)
4171 static char buf
[15];
4172 snprintf (buf
, sizeof (buf
), "[%d]", idx
);
4173 printf ("%*s ", len
, buf
);
4176 /* Display a location list from a .dwo section. It uses address indexes rather
4177 than embedded addresses. This code closely follows display_loc_list, but the
4178 two are sufficiently different that combining things is very ugly. */
4181 display_loc_list_dwo (struct dwarf_section
*section
,
4182 unsigned char **start_ptr
,
4183 int debug_info_entry
,
4184 unsigned long offset
,
4187 unsigned char *start
= *start_ptr
;
4188 unsigned char *section_end
= section
->start
+ section
->size
;
4189 unsigned long cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
4190 unsigned int pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
4191 unsigned int offset_size
= debug_information
[debug_info_entry
].offset_size
;
4192 int dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
4194 unsigned short length
;
4195 int need_frame_base
;
4197 unsigned int bytes_read
;
4201 printf (" %8.8lx ", offset
+ (start
- *start_ptr
));
4203 if (start
>= section_end
)
4205 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
4210 SAFE_BYTE_GET_AND_INC (entry_type
, start
, 1, section_end
);
4213 case 0: /* A terminating entry. */
4215 printf (_("<End of list>\n"));
4217 case 1: /* A base-address entry. */
4218 idx
= read_uleb128 (start
, &bytes_read
, section_end
);
4219 start
+= bytes_read
;
4220 print_addr_index (idx
, 8);
4222 printf (_("(base address selection entry)\n"));
4224 case 2: /* A start/end entry. */
4225 idx
= read_uleb128 (start
, &bytes_read
, section_end
);
4226 start
+= bytes_read
;
4227 print_addr_index (idx
, 8);
4228 idx
= read_uleb128 (start
, &bytes_read
, section_end
);
4229 start
+= bytes_read
;
4230 print_addr_index (idx
, 8);
4232 case 3: /* A start/length entry. */
4233 idx
= read_uleb128 (start
, &bytes_read
, section_end
);
4234 start
+= bytes_read
;
4235 print_addr_index (idx
, 8);
4236 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
4237 printf ("%08x ", idx
);
4239 case 4: /* An offset pair entry. */
4240 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
4241 printf ("%08x ", idx
);
4242 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
4243 printf ("%08x ", idx
);
4246 warn (_("Unknown location list entry type 0x%x.\n"), entry_type
);
4251 if (start
+ 2 > section_end
)
4253 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
4258 SAFE_BYTE_GET_AND_INC (length
, start
, 2, section_end
);
4259 if (start
+ length
> section_end
)
4261 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
4267 need_frame_base
= decode_location_expression (start
,
4272 cu_offset
, section
);
4275 if (need_frame_base
&& !has_frame_base
)
4276 printf (_(" [without DW_AT_frame_base]"));
4286 /* Sort array of indexes in ascending order of loc_offsets[idx]. */
4288 static dwarf_vma
*loc_offsets
;
4291 loc_offsets_compar (const void *ap
, const void *bp
)
4293 dwarf_vma a
= loc_offsets
[*(const unsigned int *) ap
];
4294 dwarf_vma b
= loc_offsets
[*(const unsigned int *) bp
];
4296 return (a
> b
) - (b
> a
);
4300 display_debug_loc (struct dwarf_section
*section
, void *file
)
4302 unsigned char *start
= section
->start
;
4303 unsigned long bytes
;
4304 unsigned char *section_begin
= start
;
4305 unsigned int num_loc_list
= 0;
4306 unsigned long last_offset
= 0;
4307 unsigned int first
= 0;
4311 int seen_first_offset
= 0;
4312 int locs_sorted
= 1;
4313 unsigned char *next
;
4314 unsigned int *array
= NULL
;
4315 const char *suffix
= strrchr (section
->name
, '.');
4318 if (suffix
&& strcmp (suffix
, ".dwo") == 0)
4321 bytes
= section
->size
;
4325 printf (_("\nThe %s section is empty.\n"), section
->name
);
4329 if (load_debug_info (file
) == 0)
4331 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
4336 /* Check the order of location list in .debug_info section. If
4337 offsets of location lists are in the ascending order, we can
4338 use `debug_information' directly. */
4339 for (i
= 0; i
< num_debug_info_entries
; i
++)
4343 num
= debug_information
[i
].num_loc_offsets
;
4344 if (num
> num_loc_list
)
4347 /* Check if we can use `debug_information' directly. */
4348 if (locs_sorted
&& num
!= 0)
4350 if (!seen_first_offset
)
4352 /* This is the first location list. */
4353 last_offset
= debug_information
[i
].loc_offsets
[0];
4355 seen_first_offset
= 1;
4361 for (; j
< num
; j
++)
4364 debug_information
[i
].loc_offsets
[j
])
4369 last_offset
= debug_information
[i
].loc_offsets
[j
];
4374 if (!seen_first_offset
)
4375 error (_("No location lists in .debug_info section!\n"));
4377 /* DWARF sections under Mach-O have non-zero addresses. */
4378 if (debug_information
[first
].num_loc_offsets
> 0
4379 && debug_information
[first
].loc_offsets
[0] != section
->address
)
4380 warn (_("Location lists in %s section start at 0x%s\n"),
4382 dwarf_vmatoa ("x", debug_information
[first
].loc_offsets
[0]));
4385 array
= (unsigned int *) xcmalloc (num_loc_list
, sizeof (unsigned int));
4386 printf (_("Contents of the %s section:\n\n"), section
->name
);
4387 printf (_(" Offset Begin End Expression\n"));
4389 seen_first_offset
= 0;
4390 for (i
= first
; i
< num_debug_info_entries
; i
++)
4392 unsigned long offset
;
4393 unsigned long base_address
;
4398 for (k
= 0; k
< debug_information
[i
].num_loc_offsets
; k
++)
4400 loc_offsets
= debug_information
[i
].loc_offsets
;
4401 qsort (array
, debug_information
[i
].num_loc_offsets
,
4402 sizeof (*array
), loc_offsets_compar
);
4405 for (k
= 0; k
< debug_information
[i
].num_loc_offsets
; k
++)
4407 j
= locs_sorted
? k
: array
[k
];
4409 && debug_information
[i
].loc_offsets
[locs_sorted
4410 ? k
- 1 : array
[k
- 1]]
4411 == debug_information
[i
].loc_offsets
[j
])
4413 has_frame_base
= debug_information
[i
].have_frame_base
[j
];
4414 /* DWARF sections under Mach-O have non-zero addresses. */
4415 offset
= debug_information
[i
].loc_offsets
[j
] - section
->address
;
4416 next
= section_begin
+ offset
;
4417 base_address
= debug_information
[i
].base_address
;
4419 if (!seen_first_offset
)
4420 seen_first_offset
= 1;
4424 warn (_("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n"),
4425 (unsigned long) (start
- section_begin
),
4426 (unsigned long) (next
- section_begin
));
4427 else if (start
> next
)
4428 warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n"),
4429 (unsigned long) (start
- section_begin
),
4430 (unsigned long) (next
- section_begin
));
4434 if (offset
>= bytes
)
4436 warn (_("Offset 0x%lx is bigger than .debug_loc section size.\n"),
4442 display_loc_list_dwo (section
, &start
, i
, offset
, has_frame_base
);
4444 display_loc_list (section
, &start
, i
, offset
, base_address
,
4449 if (start
< section
->start
+ section
->size
)
4450 warn (_("There are %ld unused bytes at the end of section %s\n"),
4451 (long) (section
->start
+ section
->size
- start
), section
->name
);
4458 display_debug_str (struct dwarf_section
*section
,
4459 void *file ATTRIBUTE_UNUSED
)
4461 unsigned char *start
= section
->start
;
4462 unsigned long bytes
= section
->size
;
4463 dwarf_vma addr
= section
->address
;
4467 printf (_("\nThe %s section is empty.\n"), section
->name
);
4471 printf (_("Contents of the %s section:\n\n"), section
->name
);
4479 lbytes
= (bytes
> 16 ? 16 : bytes
);
4481 printf (" 0x%8.8lx ", (unsigned long) addr
);
4483 for (j
= 0; j
< 16; j
++)
4486 printf ("%2.2x", start
[j
]);
4494 for (j
= 0; j
< lbytes
; j
++)
4497 if (k
>= ' ' && k
< 0x80)
4516 display_debug_info (struct dwarf_section
*section
, void *file
)
4518 return process_debug_info (section
, file
, section
->abbrev_sec
, 0, 0);
4522 display_debug_types (struct dwarf_section
*section
, void *file
)
4524 return process_debug_info (section
, file
, section
->abbrev_sec
, 0, 1);
4528 display_trace_info (struct dwarf_section
*section
, void *file
)
4530 return process_debug_info (section
, file
, section
->abbrev_sec
, 0, 0);
4534 display_debug_aranges (struct dwarf_section
*section
,
4535 void *file ATTRIBUTE_UNUSED
)
4537 unsigned char *start
= section
->start
;
4538 unsigned char *end
= start
+ section
->size
;
4540 printf (_("Contents of the %s section:\n\n"), section
->name
);
4542 /* It does not matter if this load fails,
4543 we test for that later on. */
4544 load_debug_info (file
);
4548 unsigned char *hdrptr
;
4549 DWARF2_Internal_ARange arange
;
4550 unsigned char *addr_ranges
;
4553 unsigned char address_size
;
4555 unsigned int offset_size
;
4556 unsigned int initial_length_size
;
4560 SAFE_BYTE_GET_AND_INC (arange
.ar_length
, hdrptr
, 4, end
);
4561 if (arange
.ar_length
== 0xffffffff)
4563 SAFE_BYTE_GET_AND_INC (arange
.ar_length
, hdrptr
, 8, end
);
4565 initial_length_size
= 12;
4570 initial_length_size
= 4;
4573 SAFE_BYTE_GET_AND_INC (arange
.ar_version
, hdrptr
, 2, end
);
4574 SAFE_BYTE_GET_AND_INC (arange
.ar_info_offset
, hdrptr
, offset_size
, end
);
4576 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
4577 && num_debug_info_entries
> 0
4578 && find_debug_info_for_offset (arange
.ar_info_offset
) == NULL
)
4579 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
4580 (unsigned long) arange
.ar_info_offset
, section
->name
);
4582 SAFE_BYTE_GET_AND_INC (arange
.ar_pointer_size
, hdrptr
, 1, end
);
4583 SAFE_BYTE_GET_AND_INC (arange
.ar_segment_size
, hdrptr
, 1, end
);
4585 if (arange
.ar_version
!= 2 && arange
.ar_version
!= 3)
4587 warn (_("Only DWARF 2 and 3 aranges are currently supported.\n"));
4591 printf (_(" Length: %ld\n"),
4592 (long) arange
.ar_length
);
4593 printf (_(" Version: %d\n"), arange
.ar_version
);
4594 printf (_(" Offset into .debug_info: 0x%lx\n"),
4595 (unsigned long) arange
.ar_info_offset
);
4596 printf (_(" Pointer Size: %d\n"), arange
.ar_pointer_size
);
4597 printf (_(" Segment Size: %d\n"), arange
.ar_segment_size
);
4599 address_size
= arange
.ar_pointer_size
+ arange
.ar_segment_size
;
4601 if (address_size
== 0)
4603 error (_("Invalid address size in %s section!\n"),
4608 /* The DWARF spec does not require that the address size be a power
4609 of two, but we do. This will have to change if we ever encounter
4610 an uneven architecture. */
4611 if ((address_size
& (address_size
- 1)) != 0)
4613 warn (_("Pointer size + Segment size is not a power of two.\n"));
4617 if (address_size
> 4)
4618 printf (_("\n Address Length\n"));
4620 printf (_("\n Address Length\n"));
4622 addr_ranges
= hdrptr
;
4624 /* Must pad to an alignment boundary that is twice the address size. */
4625 excess
= (hdrptr
- start
) % (2 * address_size
);
4627 addr_ranges
+= (2 * address_size
) - excess
;
4629 start
+= arange
.ar_length
+ initial_length_size
;
4631 while (addr_ranges
+ 2 * address_size
<= start
)
4633 SAFE_BYTE_GET_AND_INC (address
, addr_ranges
, address_size
, end
);
4634 SAFE_BYTE_GET_AND_INC (length
, addr_ranges
, address_size
, end
);
4637 print_dwarf_vma (address
, address_size
);
4638 print_dwarf_vma (length
, address_size
);
4648 /* Comparison function for qsort. */
4650 comp_addr_base (const void * v0
, const void * v1
)
4652 debug_info
* info0
= (debug_info
*) v0
;
4653 debug_info
* info1
= (debug_info
*) v1
;
4654 return info0
->addr_base
- info1
->addr_base
;
4657 /* Display the debug_addr section. */
4659 display_debug_addr (struct dwarf_section
*section
,
4662 debug_info
**debug_addr_info
;
4663 unsigned char *entry
;
4668 if (section
->size
== 0)
4670 printf (_("\nThe %s section is empty.\n"), section
->name
);
4674 if (load_debug_info (file
) == 0)
4676 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
4681 printf (_("Contents of the %s section:\n\n"), section
->name
);
4683 debug_addr_info
= (debug_info
**) xmalloc ((num_debug_info_entries
+ 1)
4684 * sizeof (debug_info
*));
4687 for (i
= 0; i
< num_debug_info_entries
; i
++)
4689 if (debug_information
[i
].addr_base
!= DEBUG_INFO_UNAVAILABLE
)
4690 debug_addr_info
[count
++] = &debug_information
[i
];
4693 /* Add a sentinel to make iteration convenient. */
4694 debug_addr_info
[count
] = (debug_info
*) xmalloc (sizeof (debug_info
));
4695 debug_addr_info
[count
]->addr_base
= section
->size
;
4697 qsort (debug_addr_info
, count
, sizeof (debug_info
*), comp_addr_base
);
4698 for (i
= 0; i
< count
; i
++)
4701 unsigned int address_size
= debug_addr_info
[i
]->pointer_size
;
4703 printf (_(" For compilation unit at offset 0x%s:\n"),
4704 dwarf_vmatoa ("x", debug_addr_info
[i
]->cu_offset
));
4706 printf (_("\tIndex\tAddress\n"));
4707 entry
= section
->start
+ debug_addr_info
[i
]->addr_base
;
4708 end
= section
->start
+ debug_addr_info
[i
+ 1]->addr_base
;
4712 dwarf_vma base
= byte_get (entry
, address_size
);
4713 printf (_("\t%d:\t"), idx
);
4714 print_dwarf_vma (base
, address_size
);
4716 entry
+= address_size
;
4722 free (debug_addr_info
);
4726 /* Display the .debug_str_offsets and .debug_str_offsets.dwo sections. */
4728 display_debug_str_offsets (struct dwarf_section
*section
,
4729 void *file ATTRIBUTE_UNUSED
)
4731 if (section
->size
== 0)
4733 printf (_("\nThe %s section is empty.\n"), section
->name
);
4736 /* TODO: Dump the contents. This is made somewhat difficult by not knowing
4737 what the offset size is for this section. */
4741 /* Each debug_information[x].range_lists[y] gets this representation for
4742 sorting purposes. */
4746 /* The debug_information[x].range_lists[y] value. */
4747 unsigned long ranges_offset
;
4749 /* Original debug_information to find parameters of the data. */
4750 debug_info
*debug_info_p
;
4753 /* Sort struct range_entry in ascending order of its RANGES_OFFSET. */
4756 range_entry_compar (const void *ap
, const void *bp
)
4758 const struct range_entry
*a_re
= (const struct range_entry
*) ap
;
4759 const struct range_entry
*b_re
= (const struct range_entry
*) bp
;
4760 const unsigned long a
= a_re
->ranges_offset
;
4761 const unsigned long b
= b_re
->ranges_offset
;
4763 return (a
> b
) - (b
> a
);
4767 display_debug_ranges (struct dwarf_section
*section
,
4768 void *file ATTRIBUTE_UNUSED
)
4770 unsigned char *start
= section
->start
;
4771 unsigned char *last_start
= start
;
4772 unsigned long bytes
= section
->size
;
4773 unsigned char *section_begin
= start
;
4774 unsigned char *finish
= start
+ bytes
;
4775 unsigned int num_range_list
, i
;
4776 struct range_entry
*range_entries
, *range_entry_fill
;
4780 printf (_("\nThe %s section is empty.\n"), section
->name
);
4784 if (load_debug_info (file
) == 0)
4786 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
4792 for (i
= 0; i
< num_debug_info_entries
; i
++)
4793 num_range_list
+= debug_information
[i
].num_range_lists
;
4795 if (num_range_list
== 0)
4797 /* This can happen when the file was compiled with -gsplit-debug
4798 which removes references to range lists from the primary .o file. */
4799 printf (_("No range lists in .debug_info section.\n"));
4803 range_entries
= (struct range_entry
*)
4804 xmalloc (sizeof (*range_entries
) * num_range_list
);
4805 range_entry_fill
= range_entries
;
4807 for (i
= 0; i
< num_debug_info_entries
; i
++)
4809 debug_info
*debug_info_p
= &debug_information
[i
];
4812 for (j
= 0; j
< debug_info_p
->num_range_lists
; j
++)
4814 range_entry_fill
->ranges_offset
= debug_info_p
->range_lists
[j
];
4815 range_entry_fill
->debug_info_p
= debug_info_p
;
4820 qsort (range_entries
, num_range_list
, sizeof (*range_entries
),
4821 range_entry_compar
);
4823 /* DWARF sections under Mach-O have non-zero addresses. */
4824 if (dwarf_check
!= 0 && range_entries
[0].ranges_offset
!= section
->address
)
4825 warn (_("Range lists in %s section start at 0x%lx\n"),
4826 section
->name
, range_entries
[0].ranges_offset
);
4828 printf (_("Contents of the %s section:\n\n"), section
->name
);
4829 printf (_(" Offset Begin End\n"));
4831 for (i
= 0; i
< num_range_list
; i
++)
4833 struct range_entry
*range_entry
= &range_entries
[i
];
4834 debug_info
*debug_info_p
= range_entry
->debug_info_p
;
4835 unsigned int pointer_size
;
4836 unsigned long offset
;
4837 unsigned char *next
;
4838 unsigned long base_address
;
4840 pointer_size
= debug_info_p
->pointer_size
;
4842 /* DWARF sections under Mach-O have non-zero addresses. */
4843 offset
= range_entry
->ranges_offset
- section
->address
;
4844 next
= section_begin
+ offset
;
4845 base_address
= debug_info_p
->base_address
;
4847 if (dwarf_check
!= 0 && i
> 0)
4850 warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"),
4851 (unsigned long) (start
- section_begin
),
4852 (unsigned long) (next
- section_begin
), section
->name
);
4853 else if (start
> next
)
4855 if (next
== last_start
)
4857 warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"),
4858 (unsigned long) (start
- section_begin
),
4859 (unsigned long) (next
- section_begin
), section
->name
);
4865 while (start
< finish
)
4870 /* Note: we use sign extension here in order to be sure that
4871 we can detect the -1 escape value. Sign extension into the
4872 top 32 bits of a 32-bit address will not affect the values
4873 that we display since we always show hex values, and always
4874 the bottom 32-bits. */
4875 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
4876 if (start
>= finish
)
4878 SAFE_SIGNED_BYTE_GET_AND_INC (end
, start
, pointer_size
, finish
);
4880 printf (" %8.8lx ", offset
);
4882 if (begin
== 0 && end
== 0)
4884 printf (_("<End of list>\n"));
4888 /* Check base address specifiers. */
4889 if (begin
== (dwarf_vma
) -1 && end
!= (dwarf_vma
) -1)
4892 print_dwarf_vma (begin
, pointer_size
);
4893 print_dwarf_vma (end
, pointer_size
);
4894 printf ("(base address)\n");
4898 print_dwarf_vma (begin
+ base_address
, pointer_size
);
4899 print_dwarf_vma (end
+ base_address
, pointer_size
);
4902 fputs (_("(start == end)"), stdout
);
4903 else if (begin
> end
)
4904 fputs (_("(start > end)"), stdout
);
4911 free (range_entries
);
4916 typedef struct Frame_Chunk
4918 struct Frame_Chunk
*next
;
4919 unsigned char *chunk_start
;
4921 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
4922 short int *col_type
;
4925 unsigned int code_factor
;
4932 unsigned char fde_encoding
;
4933 unsigned char cfa_exp
;
4934 unsigned char ptr_size
;
4935 unsigned char segment_size
;
4939 static const char *const *dwarf_regnames
;
4940 static unsigned int dwarf_regnames_count
;
4942 /* A marker for a col_type that means this column was never referenced
4943 in the frame info. */
4944 #define DW_CFA_unreferenced (-1)
4946 /* Return 0 if not more space is needed, 1 if more space is needed,
4947 -1 for invalid reg. */
4950 frame_need_space (Frame_Chunk
*fc
, unsigned int reg
)
4952 int prev
= fc
->ncols
;
4954 if (reg
< (unsigned int) fc
->ncols
)
4957 if (dwarf_regnames_count
4958 && reg
> dwarf_regnames_count
)
4961 fc
->ncols
= reg
+ 1;
4962 fc
->col_type
= (short int *) xcrealloc (fc
->col_type
, fc
->ncols
,
4963 sizeof (short int));
4964 fc
->col_offset
= (int *) xcrealloc (fc
->col_offset
, fc
->ncols
, sizeof (int));
4966 while (prev
< fc
->ncols
)
4968 fc
->col_type
[prev
] = DW_CFA_unreferenced
;
4969 fc
->col_offset
[prev
] = 0;
4975 static const char *const dwarf_regnames_i386
[] =
4977 "eax", "ecx", "edx", "ebx", /* 0 - 3 */
4978 "esp", "ebp", "esi", "edi", /* 4 - 7 */
4979 "eip", "eflags", NULL
, /* 8 - 10 */
4980 "st0", "st1", "st2", "st3", /* 11 - 14 */
4981 "st4", "st5", "st6", "st7", /* 15 - 18 */
4982 NULL
, NULL
, /* 19 - 20 */
4983 "xmm0", "xmm1", "xmm2", "xmm3", /* 21 - 24 */
4984 "xmm4", "xmm5", "xmm6", "xmm7", /* 25 - 28 */
4985 "mm0", "mm1", "mm2", "mm3", /* 29 - 32 */
4986 "mm4", "mm5", "mm6", "mm7", /* 33 - 36 */
4987 "fcw", "fsw", "mxcsr", /* 37 - 39 */
4988 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
, /* 40 - 47 */
4989 "tr", "ldtr", /* 48 - 49 */
4990 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 50 - 57 */
4991 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 58 - 65 */
4992 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 66 - 73 */
4993 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 74 - 81 */
4994 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 82 - 89 */
4995 NULL
, NULL
, NULL
, /* 90 - 92 */
4996 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7" /* 93 - 100 */
5000 init_dwarf_regnames_i386 (void)
5002 dwarf_regnames
= dwarf_regnames_i386
;
5003 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_i386
);
5006 static const char *const dwarf_regnames_x86_64
[] =
5008 "rax", "rdx", "rcx", "rbx",
5009 "rsi", "rdi", "rbp", "rsp",
5010 "r8", "r9", "r10", "r11",
5011 "r12", "r13", "r14", "r15",
5013 "xmm0", "xmm1", "xmm2", "xmm3",
5014 "xmm4", "xmm5", "xmm6", "xmm7",
5015 "xmm8", "xmm9", "xmm10", "xmm11",
5016 "xmm12", "xmm13", "xmm14", "xmm15",
5017 "st0", "st1", "st2", "st3",
5018 "st4", "st5", "st6", "st7",
5019 "mm0", "mm1", "mm2", "mm3",
5020 "mm4", "mm5", "mm6", "mm7",
5022 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
,
5023 "fs.base", "gs.base", NULL
, NULL
,
5025 "mxcsr", "fcw", "fsw",
5026 "xmm16", "xmm17", "xmm18", "xmm19",
5027 "xmm20", "xmm21", "xmm22", "xmm23",
5028 "xmm24", "xmm25", "xmm26", "xmm27",
5029 "xmm28", "xmm29", "xmm30", "xmm31",
5030 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 83 - 90 */
5031 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 91 - 98 */
5032 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 99 - 106 */
5033 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 107 - 114 */
5034 NULL
, NULL
, NULL
, /* 115 - 117 */
5035 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7"
5039 init_dwarf_regnames_x86_64 (void)
5041 dwarf_regnames
= dwarf_regnames_x86_64
;
5042 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_x86_64
);
5046 init_dwarf_regnames (unsigned int e_machine
)
5052 init_dwarf_regnames_i386 ();
5058 init_dwarf_regnames_x86_64 ();
5067 regname (unsigned int regno
, int row
)
5069 static char reg
[64];
5071 && regno
< dwarf_regnames_count
5072 && dwarf_regnames
[regno
] != NULL
)
5075 return dwarf_regnames
[regno
];
5076 snprintf (reg
, sizeof (reg
), "r%d (%s)", regno
,
5077 dwarf_regnames
[regno
]);
5080 snprintf (reg
, sizeof (reg
), "r%d", regno
);
5085 frame_display_row (Frame_Chunk
*fc
, int *need_col_headers
, int *max_regs
)
5090 if (*max_regs
< fc
->ncols
)
5091 *max_regs
= fc
->ncols
;
5093 if (*need_col_headers
)
5095 static const char *sloc
= " LOC";
5097 *need_col_headers
= 0;
5099 printf ("%-*s CFA ", eh_addr_size
* 2, sloc
);
5101 for (r
= 0; r
< *max_regs
; r
++)
5102 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
5107 printf ("%-5s ", regname (r
, 1));
5113 print_dwarf_vma (fc
->pc_begin
, eh_addr_size
);
5115 strcpy (tmp
, "exp");
5117 sprintf (tmp
, "%s%+d", regname (fc
->cfa_reg
, 1), fc
->cfa_offset
);
5118 printf ("%-8s ", tmp
);
5120 for (r
= 0; r
< fc
->ncols
; r
++)
5122 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
5124 switch (fc
->col_type
[r
])
5126 case DW_CFA_undefined
:
5129 case DW_CFA_same_value
:
5133 sprintf (tmp
, "c%+d", fc
->col_offset
[r
]);
5135 case DW_CFA_val_offset
:
5136 sprintf (tmp
, "v%+d", fc
->col_offset
[r
]);
5138 case DW_CFA_register
:
5139 sprintf (tmp
, "%s", regname (fc
->col_offset
[r
], 0));
5141 case DW_CFA_expression
:
5142 strcpy (tmp
, "exp");
5144 case DW_CFA_val_expression
:
5145 strcpy (tmp
, "vexp");
5148 strcpy (tmp
, "n/a");
5151 printf ("%-5s ", tmp
);
5157 #define GET(VAR, N) SAFE_BYTE_GET_AND_INC (VAR, start, N, end);
5158 #define LEB() read_uleb128 (start, & length_return, end); start += length_return
5159 #define SLEB() read_sleb128 (start, & length_return, end); start += length_return
5162 display_debug_frames (struct dwarf_section
*section
,
5163 void *file ATTRIBUTE_UNUSED
)
5165 unsigned char *start
= section
->start
;
5166 unsigned char *end
= start
+ section
->size
;
5167 unsigned char *section_start
= start
;
5168 Frame_Chunk
*chunks
= 0;
5169 Frame_Chunk
*remembered_state
= 0;
5171 int is_eh
= strcmp (section
->name
, ".eh_frame") == 0;
5172 unsigned int length_return
;
5174 const char *bad_reg
= _("bad register: ");
5175 int saved_eh_addr_size
= eh_addr_size
;
5177 printf (_("Contents of the %s section:\n"), section
->name
);
5181 unsigned char *saved_start
;
5182 unsigned char *block_end
;
5187 int need_col_headers
= 1;
5188 unsigned char *augmentation_data
= NULL
;
5189 unsigned long augmentation_data_len
= 0;
5190 unsigned int encoded_ptr_size
= saved_eh_addr_size
;
5191 unsigned int offset_size
;
5192 unsigned int initial_length_size
;
5194 saved_start
= start
;
5196 SAFE_BYTE_GET_AND_INC (length
, start
, 4, end
);
5199 printf ("\n%08lx ZERO terminator\n\n",
5200 (unsigned long)(saved_start
- section_start
));
5204 if (length
== 0xffffffff)
5206 SAFE_BYTE_GET_AND_INC (length
, start
, 8, end
);
5208 initial_length_size
= 12;
5213 initial_length_size
= 4;
5216 block_end
= saved_start
+ length
+ initial_length_size
;
5217 if (block_end
> end
)
5219 warn ("Invalid length 0x%s in FDE at %#08lx\n",
5220 dwarf_vmatoa_1 (NULL
, length
, offset_size
),
5221 (unsigned long) (saved_start
- section_start
));
5225 SAFE_BYTE_GET_AND_INC (cie_id
, start
, offset_size
, end
);
5227 if (is_eh
? (cie_id
== 0) : ((offset_size
== 4 && cie_id
== DW_CIE_ID
)
5228 || (offset_size
== 8 && cie_id
== DW64_CIE_ID
)))
5232 fc
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
5233 memset (fc
, 0, sizeof (Frame_Chunk
));
5237 fc
->chunk_start
= saved_start
;
5239 fc
->col_type
= (short int *) xmalloc (sizeof (short int));
5240 fc
->col_offset
= (int *) xmalloc (sizeof (int));
5241 frame_need_space (fc
, max_regs
- 1);
5245 fc
->augmentation
= (char *) start
;
5246 start
= (unsigned char *) strchr ((char *) start
, '\0') + 1;
5248 if (strcmp (fc
->augmentation
, "eh") == 0)
5249 start
+= eh_addr_size
;
5253 GET (fc
->ptr_size
, 1);
5254 GET (fc
->segment_size
, 1);
5255 eh_addr_size
= fc
->ptr_size
;
5259 fc
->ptr_size
= eh_addr_size
;
5260 fc
->segment_size
= 0;
5262 fc
->code_factor
= LEB ();
5263 fc
->data_factor
= SLEB ();
5273 if (fc
->augmentation
[0] == 'z')
5275 augmentation_data_len
= LEB ();
5276 augmentation_data
= start
;
5277 start
+= augmentation_data_len
;
5281 printf ("\n%08lx ", (unsigned long) (saved_start
- section_start
));
5282 print_dwarf_vma (length
, fc
->ptr_size
);
5283 print_dwarf_vma (cie_id
, offset_size
);
5285 if (do_debug_frames_interp
)
5287 printf ("CIE \"%s\" cf=%d df=%d ra=%d\n", fc
->augmentation
,
5288 fc
->code_factor
, fc
->data_factor
, fc
->ra
);
5293 printf (" Version: %d\n", version
);
5294 printf (" Augmentation: \"%s\"\n", fc
->augmentation
);
5297 printf (" Pointer Size: %u\n", fc
->ptr_size
);
5298 printf (" Segment Size: %u\n", fc
->segment_size
);
5300 printf (" Code alignment factor: %u\n", fc
->code_factor
);
5301 printf (" Data alignment factor: %d\n", fc
->data_factor
);
5302 printf (" Return address column: %d\n", fc
->ra
);
5304 if (augmentation_data_len
)
5307 printf (" Augmentation data: ");
5308 for (i
= 0; i
< augmentation_data_len
; ++i
)
5309 printf (" %02x", augmentation_data
[i
]);
5315 if (augmentation_data_len
)
5317 unsigned char *p
, *q
;
5318 p
= (unsigned char *) fc
->augmentation
+ 1;
5319 q
= augmentation_data
;
5326 q
+= 1 + size_of_encoded_value (*q
);
5328 fc
->fde_encoding
= *q
++;
5336 if (fc
->fde_encoding
)
5337 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
5340 frame_need_space (fc
, fc
->ra
);
5344 unsigned char *look_for
;
5345 static Frame_Chunk fde_fc
;
5346 unsigned long segment_selector
;
5349 memset (fc
, 0, sizeof (Frame_Chunk
));
5351 look_for
= is_eh
? start
- 4 - cie_id
: section_start
+ cie_id
;
5353 for (cie
= chunks
; cie
; cie
= cie
->next
)
5354 if (cie
->chunk_start
== look_for
)
5359 warn ("Invalid CIE pointer 0x%s in FDE at %#08lx\n",
5360 dwarf_vmatoa_1 (NULL
, cie_id
, offset_size
),
5361 (unsigned long) (saved_start
- section_start
));
5363 fc
->col_type
= (short int *) xmalloc (sizeof (short int));
5364 fc
->col_offset
= (int *) xmalloc (sizeof (int));
5365 frame_need_space (fc
, max_regs
- 1);
5367 fc
->augmentation
= "";
5368 fc
->fde_encoding
= 0;
5369 fc
->ptr_size
= eh_addr_size
;
5370 fc
->segment_size
= 0;
5374 fc
->ncols
= cie
->ncols
;
5375 fc
->col_type
= (short int *) xcmalloc (fc
->ncols
, sizeof (short int));
5376 fc
->col_offset
= (int *) xcmalloc (fc
->ncols
, sizeof (int));
5377 memcpy (fc
->col_type
, cie
->col_type
, fc
->ncols
* sizeof (short int));
5378 memcpy (fc
->col_offset
, cie
->col_offset
, fc
->ncols
* sizeof (int));
5379 fc
->augmentation
= cie
->augmentation
;
5380 fc
->ptr_size
= cie
->ptr_size
;
5381 eh_addr_size
= cie
->ptr_size
;
5382 fc
->segment_size
= cie
->segment_size
;
5383 fc
->code_factor
= cie
->code_factor
;
5384 fc
->data_factor
= cie
->data_factor
;
5385 fc
->cfa_reg
= cie
->cfa_reg
;
5386 fc
->cfa_offset
= cie
->cfa_offset
;
5388 frame_need_space (fc
, max_regs
- 1);
5389 fc
->fde_encoding
= cie
->fde_encoding
;
5392 if (fc
->fde_encoding
)
5393 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
5395 segment_selector
= 0;
5396 if (fc
->segment_size
)
5398 SAFE_BYTE_GET_AND_INC (segment_selector
, start
, fc
->segment_size
, end
);
5400 fc
->pc_begin
= get_encoded_value (start
, fc
->fde_encoding
, section
);
5401 start
+= encoded_ptr_size
;
5403 /* FIXME: It appears that sometimes the final pc_range value is
5404 encoded in less than encoded_ptr_size bytes. See the x86_64
5405 run of the "objcopy on compressed debug sections" test for an
5407 SAFE_BYTE_GET_AND_INC (fc
->pc_range
, start
, encoded_ptr_size
, end
);
5409 if (cie
->augmentation
[0] == 'z')
5411 augmentation_data_len
= LEB ();
5412 augmentation_data
= start
;
5413 start
+= augmentation_data_len
;
5416 printf ("\n%08lx %s %s FDE cie=%08lx pc=",
5417 (unsigned long)(saved_start
- section_start
),
5418 dwarf_vmatoa_1 (NULL
, length
, fc
->ptr_size
),
5419 dwarf_vmatoa_1 (NULL
, cie_id
, offset_size
),
5420 (unsigned long)(cie
->chunk_start
- section_start
));
5422 if (fc
->segment_size
)
5423 printf ("%04lx:", segment_selector
);
5426 dwarf_vmatoa_1 (NULL
, fc
->pc_begin
, fc
->ptr_size
),
5427 dwarf_vmatoa_1 (NULL
, fc
->pc_begin
+ fc
->pc_range
, fc
->ptr_size
));
5429 if (! do_debug_frames_interp
&& augmentation_data_len
)
5433 printf (" Augmentation data: ");
5434 for (i
= 0; i
< augmentation_data_len
; ++i
)
5435 printf (" %02x", augmentation_data
[i
]);
5441 /* At this point, fc is the current chunk, cie (if any) is set, and
5442 we're about to interpret instructions for the chunk. */
5443 /* ??? At present we need to do this always, since this sizes the
5444 fc->col_type and fc->col_offset arrays, which we write into always.
5445 We should probably split the interpreted and non-interpreted bits
5446 into two different routines, since there's so much that doesn't
5447 really overlap between them. */
5448 if (1 || do_debug_frames_interp
)
5450 /* Start by making a pass over the chunk, allocating storage
5451 and taking note of what registers are used. */
5452 unsigned char *tmp
= start
;
5454 while (start
< block_end
)
5457 unsigned long reg
, temp
;
5464 /* Warning: if you add any more cases to this switch, be
5465 sure to add them to the corresponding switch below. */
5468 case DW_CFA_advance_loc
:
5472 if (frame_need_space (fc
, opa
) >= 0)
5473 fc
->col_type
[opa
] = DW_CFA_undefined
;
5475 case DW_CFA_restore
:
5476 if (frame_need_space (fc
, opa
) >= 0)
5477 fc
->col_type
[opa
] = DW_CFA_undefined
;
5479 case DW_CFA_set_loc
:
5480 start
+= encoded_ptr_size
;
5482 case DW_CFA_advance_loc1
:
5485 case DW_CFA_advance_loc2
:
5488 case DW_CFA_advance_loc4
:
5491 case DW_CFA_offset_extended
:
5492 case DW_CFA_val_offset
:
5493 reg
= LEB (); LEB ();
5494 if (frame_need_space (fc
, reg
) >= 0)
5495 fc
->col_type
[reg
] = DW_CFA_undefined
;
5497 case DW_CFA_restore_extended
:
5499 frame_need_space (fc
, reg
);
5500 if (frame_need_space (fc
, reg
) >= 0)
5501 fc
->col_type
[reg
] = DW_CFA_undefined
;
5503 case DW_CFA_undefined
:
5505 if (frame_need_space (fc
, reg
) >= 0)
5506 fc
->col_type
[reg
] = DW_CFA_undefined
;
5508 case DW_CFA_same_value
:
5510 if (frame_need_space (fc
, reg
) >= 0)
5511 fc
->col_type
[reg
] = DW_CFA_undefined
;
5513 case DW_CFA_register
:
5514 reg
= LEB (); LEB ();
5515 if (frame_need_space (fc
, reg
) >= 0)
5516 fc
->col_type
[reg
] = DW_CFA_undefined
;
5518 case DW_CFA_def_cfa
:
5521 case DW_CFA_def_cfa_register
:
5524 case DW_CFA_def_cfa_offset
:
5527 case DW_CFA_def_cfa_expression
:
5531 case DW_CFA_expression
:
5532 case DW_CFA_val_expression
:
5536 if (frame_need_space (fc
, reg
) >= 0)
5537 fc
->col_type
[reg
] = DW_CFA_undefined
;
5539 case DW_CFA_offset_extended_sf
:
5540 case DW_CFA_val_offset_sf
:
5541 reg
= LEB (); SLEB ();
5542 if (frame_need_space (fc
, reg
) >= 0)
5543 fc
->col_type
[reg
] = DW_CFA_undefined
;
5545 case DW_CFA_def_cfa_sf
:
5548 case DW_CFA_def_cfa_offset_sf
:
5551 case DW_CFA_MIPS_advance_loc8
:
5554 case DW_CFA_GNU_args_size
:
5557 case DW_CFA_GNU_negative_offset_extended
:
5558 reg
= LEB (); LEB ();
5559 if (frame_need_space (fc
, reg
) >= 0)
5560 fc
->col_type
[reg
] = DW_CFA_undefined
;
5569 /* Now we know what registers are used, make a second pass over
5570 the chunk, this time actually printing out the info. */
5572 while (start
< block_end
)
5575 unsigned long ul
, reg
, roffs
;
5579 const char *reg_prefix
= "";
5586 /* Warning: if you add any more cases to this switch, be
5587 sure to add them to the corresponding switch above. */
5590 case DW_CFA_advance_loc
:
5591 if (do_debug_frames_interp
)
5592 frame_display_row (fc
, &need_col_headers
, &max_regs
);
5594 printf (" DW_CFA_advance_loc: %d to %s\n",
5595 opa
* fc
->code_factor
,
5596 dwarf_vmatoa_1 (NULL
,
5597 fc
->pc_begin
+ opa
* fc
->code_factor
,
5599 fc
->pc_begin
+= opa
* fc
->code_factor
;
5604 if (opa
>= (unsigned int) fc
->ncols
)
5605 reg_prefix
= bad_reg
;
5606 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
5607 printf (" DW_CFA_offset: %s%s at cfa%+ld\n",
5608 reg_prefix
, regname (opa
, 0),
5609 roffs
* fc
->data_factor
);
5610 if (*reg_prefix
== '\0')
5612 fc
->col_type
[opa
] = DW_CFA_offset
;
5613 fc
->col_offset
[opa
] = roffs
* fc
->data_factor
;
5617 case DW_CFA_restore
:
5618 if (opa
>= (unsigned int) cie
->ncols
5619 || opa
>= (unsigned int) fc
->ncols
)
5620 reg_prefix
= bad_reg
;
5621 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
5622 printf (" DW_CFA_restore: %s%s\n",
5623 reg_prefix
, regname (opa
, 0));
5624 if (*reg_prefix
== '\0')
5626 fc
->col_type
[opa
] = cie
->col_type
[opa
];
5627 fc
->col_offset
[opa
] = cie
->col_offset
[opa
];
5628 if (do_debug_frames_interp
5629 && fc
->col_type
[opa
] == DW_CFA_unreferenced
)
5630 fc
->col_type
[opa
] = DW_CFA_undefined
;
5634 case DW_CFA_set_loc
:
5635 vma
= get_encoded_value (start
, fc
->fde_encoding
, section
);
5636 start
+= encoded_ptr_size
;
5637 if (do_debug_frames_interp
)
5638 frame_display_row (fc
, &need_col_headers
, &max_regs
);
5640 printf (" DW_CFA_set_loc: %s\n",
5641 dwarf_vmatoa_1 (NULL
, vma
, fc
->ptr_size
));
5645 case DW_CFA_advance_loc1
:
5646 SAFE_BYTE_GET_AND_INC (ofs
, start
, 1, end
);
5647 if (do_debug_frames_interp
)
5648 frame_display_row (fc
, &need_col_headers
, &max_regs
);
5650 printf (" DW_CFA_advance_loc1: %ld to %s\n",
5651 (unsigned long) (ofs
* fc
->code_factor
),
5652 dwarf_vmatoa_1 (NULL
,
5653 fc
->pc_begin
+ ofs
* fc
->code_factor
,
5655 fc
->pc_begin
+= ofs
* fc
->code_factor
;
5658 case DW_CFA_advance_loc2
:
5659 SAFE_BYTE_GET_AND_INC (ofs
, start
, 2, end
);
5660 if (do_debug_frames_interp
)
5661 frame_display_row (fc
, &need_col_headers
, &max_regs
);
5663 printf (" DW_CFA_advance_loc2: %ld to %s\n",
5664 (unsigned long) (ofs
* fc
->code_factor
),
5665 dwarf_vmatoa_1 (NULL
,
5666 fc
->pc_begin
+ ofs
* fc
->code_factor
,
5668 fc
->pc_begin
+= ofs
* fc
->code_factor
;
5671 case DW_CFA_advance_loc4
:
5672 SAFE_BYTE_GET_AND_INC (ofs
, start
, 4, end
);
5673 if (do_debug_frames_interp
)
5674 frame_display_row (fc
, &need_col_headers
, &max_regs
);
5676 printf (" DW_CFA_advance_loc4: %ld to %s\n",
5677 (unsigned long) (ofs
* fc
->code_factor
),
5678 dwarf_vmatoa_1 (NULL
,
5679 fc
->pc_begin
+ ofs
* fc
->code_factor
,
5681 fc
->pc_begin
+= ofs
* fc
->code_factor
;
5684 case DW_CFA_offset_extended
:
5687 if (reg
>= (unsigned int) fc
->ncols
)
5688 reg_prefix
= bad_reg
;
5689 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
5690 printf (" DW_CFA_offset_extended: %s%s at cfa%+ld\n",
5691 reg_prefix
, regname (reg
, 0),
5692 roffs
* fc
->data_factor
);
5693 if (*reg_prefix
== '\0')
5695 fc
->col_type
[reg
] = DW_CFA_offset
;
5696 fc
->col_offset
[reg
] = roffs
* fc
->data_factor
;
5700 case DW_CFA_val_offset
:
5703 if (reg
>= (unsigned int) fc
->ncols
)
5704 reg_prefix
= bad_reg
;
5705 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
5706 printf (" DW_CFA_val_offset: %s%s at cfa%+ld\n",
5707 reg_prefix
, regname (reg
, 0),
5708 roffs
* fc
->data_factor
);
5709 if (*reg_prefix
== '\0')
5711 fc
->col_type
[reg
] = DW_CFA_val_offset
;
5712 fc
->col_offset
[reg
] = roffs
* fc
->data_factor
;
5716 case DW_CFA_restore_extended
:
5718 if (reg
>= (unsigned int) cie
->ncols
5719 || reg
>= (unsigned int) fc
->ncols
)
5720 reg_prefix
= bad_reg
;
5721 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
5722 printf (" DW_CFA_restore_extended: %s%s\n",
5723 reg_prefix
, regname (reg
, 0));
5724 if (*reg_prefix
== '\0')
5726 fc
->col_type
[reg
] = cie
->col_type
[reg
];
5727 fc
->col_offset
[reg
] = cie
->col_offset
[reg
];
5731 case DW_CFA_undefined
:
5733 if (reg
>= (unsigned int) fc
->ncols
)
5734 reg_prefix
= bad_reg
;
5735 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
5736 printf (" DW_CFA_undefined: %s%s\n",
5737 reg_prefix
, regname (reg
, 0));
5738 if (*reg_prefix
== '\0')
5740 fc
->col_type
[reg
] = DW_CFA_undefined
;
5741 fc
->col_offset
[reg
] = 0;
5745 case DW_CFA_same_value
:
5747 if (reg
>= (unsigned int) fc
->ncols
)
5748 reg_prefix
= bad_reg
;
5749 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
5750 printf (" DW_CFA_same_value: %s%s\n",
5751 reg_prefix
, regname (reg
, 0));
5752 if (*reg_prefix
== '\0')
5754 fc
->col_type
[reg
] = DW_CFA_same_value
;
5755 fc
->col_offset
[reg
] = 0;
5759 case DW_CFA_register
:
5762 if (reg
>= (unsigned int) fc
->ncols
)
5763 reg_prefix
= bad_reg
;
5764 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
5766 printf (" DW_CFA_register: %s%s in ",
5767 reg_prefix
, regname (reg
, 0));
5768 puts (regname (roffs
, 0));
5770 if (*reg_prefix
== '\0')
5772 fc
->col_type
[reg
] = DW_CFA_register
;
5773 fc
->col_offset
[reg
] = roffs
;
5777 case DW_CFA_remember_state
:
5778 if (! do_debug_frames_interp
)
5779 printf (" DW_CFA_remember_state\n");
5780 rs
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
5781 rs
->ncols
= fc
->ncols
;
5782 rs
->col_type
= (short int *) xcmalloc (rs
->ncols
,
5783 sizeof (short int));
5784 rs
->col_offset
= (int *) xcmalloc (rs
->ncols
, sizeof (int));
5785 memcpy (rs
->col_type
, fc
->col_type
, rs
->ncols
);
5786 memcpy (rs
->col_offset
, fc
->col_offset
, rs
->ncols
* sizeof (int));
5787 rs
->next
= remembered_state
;
5788 remembered_state
= rs
;
5791 case DW_CFA_restore_state
:
5792 if (! do_debug_frames_interp
)
5793 printf (" DW_CFA_restore_state\n");
5794 rs
= remembered_state
;
5797 remembered_state
= rs
->next
;
5798 frame_need_space (fc
, rs
->ncols
- 1);
5799 memcpy (fc
->col_type
, rs
->col_type
, rs
->ncols
);
5800 memcpy (fc
->col_offset
, rs
->col_offset
,
5801 rs
->ncols
* sizeof (int));
5802 free (rs
->col_type
);
5803 free (rs
->col_offset
);
5806 else if (do_debug_frames_interp
)
5807 printf ("Mismatched DW_CFA_restore_state\n");
5810 case DW_CFA_def_cfa
:
5811 fc
->cfa_reg
= LEB ();
5812 fc
->cfa_offset
= LEB ();
5814 if (! do_debug_frames_interp
)
5815 printf (" DW_CFA_def_cfa: %s ofs %d\n",
5816 regname (fc
->cfa_reg
, 0), fc
->cfa_offset
);
5819 case DW_CFA_def_cfa_register
:
5820 fc
->cfa_reg
= LEB ();
5822 if (! do_debug_frames_interp
)
5823 printf (" DW_CFA_def_cfa_register: %s\n",
5824 regname (fc
->cfa_reg
, 0));
5827 case DW_CFA_def_cfa_offset
:
5828 fc
->cfa_offset
= LEB ();
5829 if (! do_debug_frames_interp
)
5830 printf (" DW_CFA_def_cfa_offset: %d\n", fc
->cfa_offset
);
5834 if (! do_debug_frames_interp
)
5835 printf (" DW_CFA_nop\n");
5838 case DW_CFA_def_cfa_expression
:
5840 if (! do_debug_frames_interp
)
5842 printf (" DW_CFA_def_cfa_expression (");
5843 decode_location_expression (start
, eh_addr_size
, 0, -1,
5851 case DW_CFA_expression
:
5854 if (reg
>= (unsigned int) fc
->ncols
)
5855 reg_prefix
= bad_reg
;
5856 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
5858 printf (" DW_CFA_expression: %s%s (",
5859 reg_prefix
, regname (reg
, 0));
5860 decode_location_expression (start
, eh_addr_size
, 0, -1,
5864 if (*reg_prefix
== '\0')
5865 fc
->col_type
[reg
] = DW_CFA_expression
;
5869 case DW_CFA_val_expression
:
5872 if (reg
>= (unsigned int) fc
->ncols
)
5873 reg_prefix
= bad_reg
;
5874 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
5876 printf (" DW_CFA_val_expression: %s%s (",
5877 reg_prefix
, regname (reg
, 0));
5878 decode_location_expression (start
, eh_addr_size
, 0, -1,
5882 if (*reg_prefix
== '\0')
5883 fc
->col_type
[reg
] = DW_CFA_val_expression
;
5887 case DW_CFA_offset_extended_sf
:
5890 if (frame_need_space (fc
, reg
) < 0)
5891 reg_prefix
= bad_reg
;
5892 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
5893 printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+ld\n",
5894 reg_prefix
, regname (reg
, 0),
5895 l
* fc
->data_factor
);
5896 if (*reg_prefix
== '\0')
5898 fc
->col_type
[reg
] = DW_CFA_offset
;
5899 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
5903 case DW_CFA_val_offset_sf
:
5906 if (frame_need_space (fc
, reg
) < 0)
5907 reg_prefix
= bad_reg
;
5908 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
5909 printf (" DW_CFA_val_offset_sf: %s%s at cfa%+ld\n",
5910 reg_prefix
, regname (reg
, 0),
5911 l
* fc
->data_factor
);
5912 if (*reg_prefix
== '\0')
5914 fc
->col_type
[reg
] = DW_CFA_val_offset
;
5915 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
5919 case DW_CFA_def_cfa_sf
:
5920 fc
->cfa_reg
= LEB ();
5921 fc
->cfa_offset
= SLEB ();
5922 fc
->cfa_offset
= fc
->cfa_offset
* fc
->data_factor
;
5924 if (! do_debug_frames_interp
)
5925 printf (" DW_CFA_def_cfa_sf: %s ofs %d\n",
5926 regname (fc
->cfa_reg
, 0), fc
->cfa_offset
);
5929 case DW_CFA_def_cfa_offset_sf
:
5930 fc
->cfa_offset
= SLEB ();
5931 fc
->cfa_offset
= fc
->cfa_offset
* fc
->data_factor
;
5932 if (! do_debug_frames_interp
)
5933 printf (" DW_CFA_def_cfa_offset_sf: %d\n", fc
->cfa_offset
);
5936 case DW_CFA_MIPS_advance_loc8
:
5937 SAFE_BYTE_GET_AND_INC (ofs
, start
, 8, end
);
5938 if (do_debug_frames_interp
)
5939 frame_display_row (fc
, &need_col_headers
, &max_regs
);
5941 printf (" DW_CFA_MIPS_advance_loc8: %ld to %s\n",
5942 (unsigned long) (ofs
* fc
->code_factor
),
5943 dwarf_vmatoa_1 (NULL
,
5944 fc
->pc_begin
+ ofs
* fc
->code_factor
,
5946 fc
->pc_begin
+= ofs
* fc
->code_factor
;
5949 case DW_CFA_GNU_window_save
:
5950 if (! do_debug_frames_interp
)
5951 printf (" DW_CFA_GNU_window_save\n");
5954 case DW_CFA_GNU_args_size
:
5956 if (! do_debug_frames_interp
)
5957 printf (" DW_CFA_GNU_args_size: %ld\n", ul
);
5960 case DW_CFA_GNU_negative_offset_extended
:
5963 if (frame_need_space (fc
, reg
) < 0)
5964 reg_prefix
= bad_reg
;
5965 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
5966 printf (" DW_CFA_GNU_negative_offset_extended: %s%s at cfa%+ld\n",
5967 reg_prefix
, regname (reg
, 0),
5968 l
* fc
->data_factor
);
5969 if (*reg_prefix
== '\0')
5971 fc
->col_type
[reg
] = DW_CFA_offset
;
5972 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
5977 if (op
>= DW_CFA_lo_user
&& op
<= DW_CFA_hi_user
)
5978 printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op
);
5980 warn (_("unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op
);
5985 if (do_debug_frames_interp
)
5986 frame_display_row (fc
, &need_col_headers
, &max_regs
);
5989 eh_addr_size
= saved_eh_addr_size
;
6002 display_gdb_index (struct dwarf_section
*section
,
6003 void *file ATTRIBUTE_UNUSED
)
6005 unsigned char *start
= section
->start
;
6007 uint32_t cu_list_offset
, tu_list_offset
;
6008 uint32_t address_table_offset
, symbol_table_offset
, constant_pool_offset
;
6009 unsigned int cu_list_elements
, tu_list_elements
;
6010 unsigned int address_table_size
, symbol_table_slots
;
6011 unsigned char *cu_list
, *tu_list
;
6012 unsigned char *address_table
, *symbol_table
, *constant_pool
;
6015 /* The documentation for the format of this file is in gdb/dwarf2read.c. */
6017 printf (_("Contents of the %s section:\n"), section
->name
);
6019 if (section
->size
< 6 * sizeof (uint32_t))
6021 warn (_("Truncated header in the %s section.\n"), section
->name
);
6025 version
= byte_get_little_endian (start
, 4);
6026 printf (_("Version %ld\n"), (long) version
);
6028 /* Prior versions are obsolete, and future versions may not be
6029 backwards compatible. */
6030 if (version
< 3 || version
> 8)
6032 warn (_("Unsupported version %lu.\n"), (unsigned long) version
);
6036 warn (_("The address table data in version 3 may be wrong.\n"));
6038 warn (_("Version 4 does not support case insensitive lookups.\n"));
6040 warn (_("Version 5 does not include inlined functions.\n"));
6042 warn (_("Version 6 does not include symbol attributes.\n"));
6043 /* Version 7 indices generated by Gold have bad type unit references,
6044 PR binutils/15021. But we don't know if the index was generated by
6045 Gold or not, so to avoid worrying users with gdb-generated indices
6046 we say nothing for version 7 here. */
6048 cu_list_offset
= byte_get_little_endian (start
+ 4, 4);
6049 tu_list_offset
= byte_get_little_endian (start
+ 8, 4);
6050 address_table_offset
= byte_get_little_endian (start
+ 12, 4);
6051 symbol_table_offset
= byte_get_little_endian (start
+ 16, 4);
6052 constant_pool_offset
= byte_get_little_endian (start
+ 20, 4);
6054 if (cu_list_offset
> section
->size
6055 || tu_list_offset
> section
->size
6056 || address_table_offset
> section
->size
6057 || symbol_table_offset
> section
->size
6058 || constant_pool_offset
> section
->size
)
6060 warn (_("Corrupt header in the %s section.\n"), section
->name
);
6064 cu_list_elements
= (tu_list_offset
- cu_list_offset
) / 8;
6065 tu_list_elements
= (address_table_offset
- tu_list_offset
) / 8;
6066 address_table_size
= symbol_table_offset
- address_table_offset
;
6067 symbol_table_slots
= (constant_pool_offset
- symbol_table_offset
) / 8;
6069 cu_list
= start
+ cu_list_offset
;
6070 tu_list
= start
+ tu_list_offset
;
6071 address_table
= start
+ address_table_offset
;
6072 symbol_table
= start
+ symbol_table_offset
;
6073 constant_pool
= start
+ constant_pool_offset
;
6075 printf (_("\nCU table:\n"));
6076 for (i
= 0; i
< cu_list_elements
; i
+= 2)
6078 uint64_t cu_offset
= byte_get_little_endian (cu_list
+ i
* 8, 8);
6079 uint64_t cu_length
= byte_get_little_endian (cu_list
+ i
* 8 + 8, 8);
6081 printf (_("[%3u] 0x%lx - 0x%lx\n"), i
/ 2,
6082 (unsigned long) cu_offset
,
6083 (unsigned long) (cu_offset
+ cu_length
- 1));
6086 printf (_("\nTU table:\n"));
6087 for (i
= 0; i
< tu_list_elements
; i
+= 3)
6089 uint64_t tu_offset
= byte_get_little_endian (tu_list
+ i
* 8, 8);
6090 uint64_t type_offset
= byte_get_little_endian (tu_list
+ i
* 8 + 8, 8);
6091 uint64_t signature
= byte_get_little_endian (tu_list
+ i
* 8 + 16, 8);
6093 printf (_("[%3u] 0x%lx 0x%lx "), i
/ 3,
6094 (unsigned long) tu_offset
,
6095 (unsigned long) type_offset
);
6096 print_dwarf_vma (signature
, 8);
6100 printf (_("\nAddress table:\n"));
6101 for (i
= 0; i
< address_table_size
; i
+= 2 * 8 + 4)
6103 uint64_t low
= byte_get_little_endian (address_table
+ i
, 8);
6104 uint64_t high
= byte_get_little_endian (address_table
+ i
+ 8, 8);
6105 uint32_t cu_index
= byte_get_little_endian (address_table
+ i
+ 16, 4);
6107 print_dwarf_vma (low
, 8);
6108 print_dwarf_vma (high
, 8);
6109 printf (_("%lu\n"), (unsigned long) cu_index
);
6112 printf (_("\nSymbol table:\n"));
6113 for (i
= 0; i
< symbol_table_slots
; ++i
)
6115 uint32_t name_offset
= byte_get_little_endian (symbol_table
+ i
* 8, 4);
6116 uint32_t cu_vector_offset
= byte_get_little_endian (symbol_table
+ i
* 8 + 4, 4);
6117 uint32_t num_cus
, cu
;
6119 if (name_offset
!= 0
6120 || cu_vector_offset
!= 0)
6124 printf ("[%3u] %s:", i
, constant_pool
+ name_offset
);
6125 num_cus
= byte_get_little_endian (constant_pool
+ cu_vector_offset
, 4);
6128 for (j
= 0; j
< num_cus
; ++j
)
6131 gdb_index_symbol_kind kind
;
6133 cu
= byte_get_little_endian (constant_pool
+ cu_vector_offset
+ 4 + j
* 4, 4);
6134 is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu
);
6135 kind
= GDB_INDEX_SYMBOL_KIND_VALUE (cu
);
6136 cu
= GDB_INDEX_CU_VALUE (cu
);
6137 /* Convert to TU number if it's for a type unit. */
6138 if (cu
>= cu_list_elements
/ 2)
6139 printf ("%cT%lu", num_cus
> 1 ? '\t' : ' ',
6140 (unsigned long) (cu
- cu_list_elements
/ 2));
6142 printf ("%c%lu", num_cus
> 1 ? '\t' : ' ', (unsigned long) cu
);
6146 case GDB_INDEX_SYMBOL_KIND_NONE
:
6147 printf (_(" [no symbol information]"));
6149 case GDB_INDEX_SYMBOL_KIND_TYPE
:
6151 ? _(" [static type]")
6152 : _(" [global type]"));
6154 case GDB_INDEX_SYMBOL_KIND_VARIABLE
:
6156 ? _(" [static variable]")
6157 : _(" [global variable]"));
6159 case GDB_INDEX_SYMBOL_KIND_FUNCTION
:
6161 ? _(" [static function]")
6162 : _(" [global function]"));
6164 case GDB_INDEX_SYMBOL_KIND_OTHER
:
6166 ? _(" [static other]")
6167 : _(" [global other]"));
6171 ? _(" [static unknown: %d]")
6172 : _(" [global unknown: %d]"),
6187 /* Pre-allocate enough space for the CU/TU sets needed. */
6190 prealloc_cu_tu_list (unsigned int nshndx
)
6192 if (shndx_pool
== NULL
)
6194 shndx_pool_size
= nshndx
;
6195 shndx_pool_used
= 0;
6196 shndx_pool
= (unsigned int *) xcmalloc (shndx_pool_size
,
6197 sizeof (unsigned int));
6201 shndx_pool_size
= shndx_pool_used
+ nshndx
;
6202 shndx_pool
= (unsigned int *) xcrealloc (shndx_pool
, shndx_pool_size
,
6203 sizeof (unsigned int));
6208 add_shndx_to_cu_tu_entry (unsigned int shndx
)
6210 if (shndx_pool_used
>= shndx_pool_size
)
6212 error (_("Internal error: out of space in the shndx pool.\n"));
6215 shndx_pool
[shndx_pool_used
++] = shndx
;
6219 end_cu_tu_entry (void)
6221 if (shndx_pool_used
>= shndx_pool_size
)
6223 error (_("Internal error: out of space in the shndx pool.\n"));
6226 shndx_pool
[shndx_pool_used
++] = 0;
6229 /* Return the short name of a DWARF section given by a DW_SECT enumerator. */
6232 get_DW_SECT_short_name (unsigned int dw_sect
)
6234 static char buf
[16];
6242 case DW_SECT_ABBREV
:
6248 case DW_SECT_STR_OFFSETS
:
6250 case DW_SECT_MACINFO
:
6258 snprintf (buf
, sizeof (buf
), "%d", dw_sect
);
6262 /* Process a CU or TU index. If DO_DISPLAY is true, print the contents.
6263 These sections are extensions for Fission.
6264 See http://gcc.gnu.org/wiki/DebugFissionDWP. */
6267 process_cu_tu_index (struct dwarf_section
*section
, int do_display
)
6269 unsigned char *phdr
= section
->start
;
6270 unsigned char *limit
= phdr
+ section
->size
;
6271 unsigned char *phash
;
6272 unsigned char *pindex
;
6273 unsigned char *ppool
;
6274 unsigned int version
;
6275 unsigned int ncols
= 0;
6277 unsigned int nslots
;
6280 dwarf_vma signature_high
;
6281 dwarf_vma signature_low
;
6284 version
= byte_get (phdr
, 4);
6286 ncols
= byte_get (phdr
+ 4, 4);
6287 nused
= byte_get (phdr
+ 8, 4);
6288 nslots
= byte_get (phdr
+ 12, 4);
6290 pindex
= phash
+ nslots
* 8;
6291 ppool
= pindex
+ nslots
* 4;
6295 printf (_("Contents of the %s section:\n\n"), section
->name
);
6296 printf (_(" Version: %d\n"), version
);
6298 printf (_(" Number of columns: %d\n"), ncols
);
6299 printf (_(" Number of used entries: %d\n"), nused
);
6300 printf (_(" Number of slots: %d\n\n"), nslots
);
6305 warn (_("Section %s too small for %d hash table entries\n"),
6306 section
->name
, nslots
);
6313 prealloc_cu_tu_list ((limit
- ppool
) / 4);
6314 for (i
= 0; i
< nslots
; i
++)
6316 unsigned char *shndx_list
;
6319 byte_get_64 (phash
, &signature_high
, &signature_low
);
6320 if (signature_high
!= 0 || signature_low
!= 0)
6322 j
= byte_get (pindex
, 4);
6323 shndx_list
= ppool
+ j
* 4;
6325 printf (_(" [%3d] Signature: 0x%s Sections: "),
6326 i
, dwarf_vmatoa64 (signature_high
, signature_low
,
6327 buf
, sizeof (buf
)));
6330 if (shndx_list
>= limit
)
6332 warn (_("Section %s too small for shndx pool\n"),
6336 shndx
= byte_get (shndx_list
, 4);
6340 printf (" %d", shndx
);
6342 add_shndx_to_cu_tu_entry (shndx
);
6354 else if (version
== 2)
6357 unsigned int dw_sect
;
6358 unsigned char *ph
= phash
;
6359 unsigned char *pi
= pindex
;
6360 unsigned char *poffsets
= ppool
+ ncols
* 4;
6361 unsigned char *psizes
= poffsets
+ nused
* ncols
* 4;
6362 unsigned char *pend
= psizes
+ nused
* ncols
* 4;
6363 bfd_boolean is_tu_index
;
6364 struct cu_tu_set
*this_set
= NULL
;
6366 unsigned char *prow
;
6368 is_tu_index
= strcmp (section
->name
, ".debug_tu_index") == 0;
6372 warn (_("Section %s too small for offset and size tables\n"),
6379 printf (_(" Offset table\n"));
6380 printf (" slot %-16s ",
6381 is_tu_index
? _("signature") : _("dwo_id"));
6388 tu_sets
= xcmalloc (nused
, sizeof (struct cu_tu_set
));
6394 cu_sets
= xcmalloc (nused
, sizeof (struct cu_tu_set
));
6400 for (j
= 0; j
< ncols
; j
++)
6402 dw_sect
= byte_get (ppool
+ j
* 4, 4);
6403 printf (" %8s", get_DW_SECT_short_name (dw_sect
));
6407 for (i
= 0; i
< nslots
; i
++)
6409 byte_get_64 (ph
, &signature_high
, &signature_low
);
6410 row
= byte_get (pi
, 4);
6414 memcpy (&this_set
[row
- 1].signature
, ph
, sizeof (uint64_t));
6415 prow
= poffsets
+ (row
- 1) * ncols
* 4;
6417 printf (_(" [%3d] 0x%s"),
6418 i
, dwarf_vmatoa64 (signature_high
, signature_low
,
6419 buf
, sizeof (buf
)));
6420 for (j
= 0; j
< ncols
; j
++)
6422 val
= byte_get (prow
+ j
* 4, 4);
6424 printf (" %8d", val
);
6427 dw_sect
= byte_get (ppool
+ j
* 4, 4);
6428 this_set
[row
- 1].section_offsets
[dw_sect
] = val
;
6443 printf (_(" Size table\n"));
6444 printf (" slot %-16s ",
6445 is_tu_index
? _("signature") : _("dwo_id"));
6447 for (j
= 0; j
< ncols
; j
++)
6449 val
= byte_get (ppool
+ j
* 4, 4);
6451 printf (" %8s", get_DW_SECT_short_name (val
));
6455 for (i
= 0; i
< nslots
; i
++)
6457 byte_get_64 (ph
, &signature_high
, &signature_low
);
6458 row
= byte_get (pi
, 4);
6461 prow
= psizes
+ (row
- 1) * ncols
* 4;
6463 printf (_(" [%3d] 0x%s"),
6464 i
, dwarf_vmatoa64 (signature_high
, signature_low
,
6465 buf
, sizeof (buf
)));
6466 for (j
= 0; j
< ncols
; j
++)
6468 val
= byte_get (prow
+ j
* 4, 4);
6470 printf (" %8d", val
);
6473 dw_sect
= byte_get (ppool
+ j
* 4, 4);
6474 this_set
[row
- 1].section_sizes
[dw_sect
] = val
;
6484 else if (do_display
)
6485 printf (_(" Unsupported version\n"));
6493 /* Load the CU and TU indexes if present. This will build a list of
6494 section sets that we can use to associate a .debug_info.dwo section
6495 with its associated .debug_abbrev.dwo section in a .dwp file. */
6498 load_cu_tu_indexes (void *file
)
6500 /* If we have already loaded (or tried to load) the CU and TU indexes
6501 then do not bother to repeat the task. */
6502 if (cu_tu_indexes_read
)
6505 if (load_debug_section (dwp_cu_index
, file
))
6506 process_cu_tu_index (&debug_displays
[dwp_cu_index
].section
, 0);
6508 if (load_debug_section (dwp_tu_index
, file
))
6509 process_cu_tu_index (&debug_displays
[dwp_tu_index
].section
, 0);
6511 cu_tu_indexes_read
= 1;
6514 /* Find the set of sections that includes section SHNDX. */
6517 find_cu_tu_set (void *file
, unsigned int shndx
)
6521 load_cu_tu_indexes (file
);
6523 /* Find SHNDX in the shndx pool. */
6524 for (i
= 0; i
< shndx_pool_used
; i
++)
6525 if (shndx_pool
[i
] == shndx
)
6528 if (i
>= shndx_pool_used
)
6531 /* Now backup to find the first entry in the set. */
6532 while (i
> 0 && shndx_pool
[i
- 1] != 0)
6535 return shndx_pool
+ i
;
6538 /* Display a .debug_cu_index or .debug_tu_index section. */
6541 display_cu_index (struct dwarf_section
*section
, void *file ATTRIBUTE_UNUSED
)
6543 return process_cu_tu_index (section
, 1);
6547 display_debug_not_supported (struct dwarf_section
*section
,
6548 void *file ATTRIBUTE_UNUSED
)
6550 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
6557 cmalloc (size_t nmemb
, size_t size
)
6559 /* Check for overflow. */
6560 if (nmemb
>= ~(size_t) 0 / size
)
6563 return malloc (nmemb
* size
);
6567 xcmalloc (size_t nmemb
, size_t size
)
6569 /* Check for overflow. */
6570 if (nmemb
>= ~(size_t) 0 / size
)
6573 return xmalloc (nmemb
* size
);
6577 xcrealloc (void *ptr
, size_t nmemb
, size_t size
)
6579 /* Check for overflow. */
6580 if (nmemb
>= ~(size_t) 0 / size
)
6583 return xrealloc (ptr
, nmemb
* size
);
6587 free_debug_memory (void)
6593 for (i
= 0; i
< max
; i
++)
6594 free_debug_section ((enum dwarf_section_display_enum
) i
);
6596 if (debug_information
!= NULL
)
6598 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
)
6600 for (i
= 0; i
< num_debug_info_entries
; i
++)
6602 if (!debug_information
[i
].max_loc_offsets
)
6604 free (debug_information
[i
].loc_offsets
);
6605 free (debug_information
[i
].have_frame_base
);
6607 if (!debug_information
[i
].max_range_lists
)
6608 free (debug_information
[i
].range_lists
);
6612 free (debug_information
);
6613 debug_information
= NULL
;
6614 num_debug_info_entries
= 0;
6619 dwarf_select_sections_by_names (const char *names
)
6623 const char * option
;
6627 debug_dump_long_opts
;
6629 static const debug_dump_long_opts opts_table
[] =
6631 /* Please keep this table alpha- sorted. */
6632 { "Ranges", & do_debug_ranges
, 1 },
6633 { "abbrev", & do_debug_abbrevs
, 1 },
6634 { "addr", & do_debug_addr
, 1 },
6635 { "aranges", & do_debug_aranges
, 1 },
6636 { "cu_index", & do_debug_cu_index
, 1 },
6637 { "decodedline", & do_debug_lines
, FLAG_DEBUG_LINES_DECODED
},
6638 { "frames", & do_debug_frames
, 1 },
6639 { "frames-interp", & do_debug_frames_interp
, 1 },
6640 /* The special .gdb_index section. */
6641 { "gdb_index", & do_gdb_index
, 1 },
6642 { "info", & do_debug_info
, 1 },
6643 { "line", & do_debug_lines
, FLAG_DEBUG_LINES_RAW
}, /* For backwards compatibility. */
6644 { "loc", & do_debug_loc
, 1 },
6645 { "macro", & do_debug_macinfo
, 1 },
6646 { "pubnames", & do_debug_pubnames
, 1 },
6647 { "pubtypes", & do_debug_pubtypes
, 1 },
6648 /* This entry is for compatability
6649 with earlier versions of readelf. */
6650 { "ranges", & do_debug_aranges
, 1 },
6651 { "rawline", & do_debug_lines
, FLAG_DEBUG_LINES_RAW
},
6652 { "str", & do_debug_str
, 1 },
6653 /* These trace_* sections are used by Itanium VMS. */
6654 { "trace_abbrev", & do_trace_abbrevs
, 1 },
6655 { "trace_aranges", & do_trace_aranges
, 1 },
6656 { "trace_info", & do_trace_info
, 1 },
6665 const debug_dump_long_opts
* entry
;
6667 for (entry
= opts_table
; entry
->option
; entry
++)
6669 size_t len
= strlen (entry
->option
);
6671 if (strncmp (p
, entry
->option
, len
) == 0
6672 && (p
[len
] == ',' || p
[len
] == '\0'))
6674 * entry
->variable
|= entry
->val
;
6676 /* The --debug-dump=frames-interp option also
6677 enables the --debug-dump=frames option. */
6678 if (do_debug_frames_interp
)
6679 do_debug_frames
= 1;
6686 if (entry
->option
== NULL
)
6688 warn (_("Unrecognized debug option '%s'\n"), p
);
6689 p
= strchr (p
, ',');
6700 dwarf_select_sections_by_letters (const char *letters
)
6702 unsigned int lindex
= 0;
6704 while (letters
[lindex
])
6705 switch (letters
[lindex
++])
6712 do_debug_abbrevs
= 1;
6716 do_debug_lines
|= FLAG_DEBUG_LINES_RAW
;
6720 do_debug_lines
|= FLAG_DEBUG_LINES_DECODED
;
6724 do_debug_pubnames
= 1;
6728 do_debug_pubtypes
= 1;
6732 do_debug_aranges
= 1;
6736 do_debug_ranges
= 1;
6740 do_debug_frames_interp
= 1;
6742 do_debug_frames
= 1;
6746 do_debug_macinfo
= 1;
6758 warn (_("Unrecognized debug option '%s'\n"), optarg
);
6764 dwarf_select_sections_all (void)
6767 do_debug_abbrevs
= 1;
6768 do_debug_lines
= FLAG_DEBUG_LINES_RAW
;
6769 do_debug_pubnames
= 1;
6770 do_debug_pubtypes
= 1;
6771 do_debug_aranges
= 1;
6772 do_debug_ranges
= 1;
6773 do_debug_frames
= 1;
6774 do_debug_macinfo
= 1;
6779 do_trace_abbrevs
= 1;
6780 do_trace_aranges
= 1;
6782 do_debug_cu_index
= 1;
6785 struct dwarf_section_display debug_displays
[] =
6787 { { ".debug_abbrev", ".zdebug_abbrev", NULL
, NULL
, 0, 0, 0 },
6788 display_debug_abbrev
, &do_debug_abbrevs
, 0 },
6789 { { ".debug_aranges", ".zdebug_aranges", NULL
, NULL
, 0, 0, 0 },
6790 display_debug_aranges
, &do_debug_aranges
, 1 },
6791 { { ".debug_frame", ".zdebug_frame", NULL
, NULL
, 0, 0, 0 },
6792 display_debug_frames
, &do_debug_frames
, 1 },
6793 { { ".debug_info", ".zdebug_info", NULL
, NULL
, 0, 0, abbrev
},
6794 display_debug_info
, &do_debug_info
, 1 },
6795 { { ".debug_line", ".zdebug_line", NULL
, NULL
, 0, 0, 0 },
6796 display_debug_lines
, &do_debug_lines
, 1 },
6797 { { ".debug_pubnames", ".zdebug_pubnames", NULL
, NULL
, 0, 0, 0 },
6798 display_debug_pubnames
, &do_debug_pubnames
, 0 },
6799 { { ".eh_frame", "", NULL
, NULL
, 0, 0, 0 },
6800 display_debug_frames
, &do_debug_frames
, 1 },
6801 { { ".debug_macinfo", ".zdebug_macinfo", NULL
, NULL
, 0, 0, 0 },
6802 display_debug_macinfo
, &do_debug_macinfo
, 0 },
6803 { { ".debug_macro", ".zdebug_macro", NULL
, NULL
, 0, 0, 0 },
6804 display_debug_macro
, &do_debug_macinfo
, 1 },
6805 { { ".debug_str", ".zdebug_str", NULL
, NULL
, 0, 0, 0 },
6806 display_debug_str
, &do_debug_str
, 0 },
6807 { { ".debug_loc", ".zdebug_loc", NULL
, NULL
, 0, 0, 0 },
6808 display_debug_loc
, &do_debug_loc
, 1 },
6809 { { ".debug_pubtypes", ".zdebug_pubtypes", NULL
, NULL
, 0, 0, 0 },
6810 display_debug_pubnames
, &do_debug_pubtypes
, 0 },
6811 { { ".debug_ranges", ".zdebug_ranges", NULL
, NULL
, 0, 0, 0 },
6812 display_debug_ranges
, &do_debug_ranges
, 1 },
6813 { { ".debug_static_func", ".zdebug_static_func", NULL
, NULL
, 0, 0, 0 },
6814 display_debug_not_supported
, NULL
, 0 },
6815 { { ".debug_static_vars", ".zdebug_static_vars", NULL
, NULL
, 0, 0, 0 },
6816 display_debug_not_supported
, NULL
, 0 },
6817 { { ".debug_types", ".zdebug_types", NULL
, NULL
, 0, 0, abbrev
},
6818 display_debug_types
, &do_debug_info
, 1 },
6819 { { ".debug_weaknames", ".zdebug_weaknames", NULL
, NULL
, 0, 0, 0 },
6820 display_debug_not_supported
, NULL
, 0 },
6821 { { ".gdb_index", "", NULL
, NULL
, 0, 0, 0 },
6822 display_gdb_index
, &do_gdb_index
, 0 },
6823 { { ".trace_info", "", NULL
, NULL
, 0, 0, trace_abbrev
},
6824 display_trace_info
, &do_trace_info
, 1 },
6825 { { ".trace_abbrev", "", NULL
, NULL
, 0, 0, 0 },
6826 display_debug_abbrev
, &do_trace_abbrevs
, 0 },
6827 { { ".trace_aranges", "", NULL
, NULL
, 0, 0, 0 },
6828 display_debug_aranges
, &do_trace_aranges
, 0 },
6829 { { ".debug_info.dwo", ".zdebug_info.dwo", NULL
, NULL
, 0, 0, abbrev_dwo
},
6830 display_debug_info
, &do_debug_info
, 1 },
6831 { { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo", NULL
, NULL
, 0, 0, 0 },
6832 display_debug_abbrev
, &do_debug_abbrevs
, 0 },
6833 { { ".debug_types.dwo", ".zdebug_types.dwo", NULL
, NULL
, 0, 0, abbrev_dwo
},
6834 display_debug_types
, &do_debug_info
, 1 },
6835 { { ".debug_line.dwo", ".zdebug_line.dwo", NULL
, NULL
, 0, 0, 0 },
6836 display_debug_lines
, &do_debug_lines
, 1 },
6837 { { ".debug_loc.dwo", ".zdebug_loc.dwo", NULL
, NULL
, 0, 0, 0 },
6838 display_debug_loc
, &do_debug_loc
, 1 },
6839 { { ".debug_macro.dwo", ".zdebug_macro.dwo", NULL
, NULL
, 0, 0, 0 },
6840 display_debug_macro
, &do_debug_macinfo
, 1 },
6841 { { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo", NULL
, NULL
, 0, 0, 0 },
6842 display_debug_macinfo
, &do_debug_macinfo
, 0 },
6843 { { ".debug_str.dwo", ".zdebug_str.dwo", NULL
, NULL
, 0, 0, 0 },
6844 display_debug_str
, &do_debug_str
, 1 },
6845 { { ".debug_str_offsets", ".zdebug_str_offsets", NULL
, NULL
, 0, 0, 0 },
6846 display_debug_str_offsets
, NULL
, 0 },
6847 { { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo", NULL
, NULL
, 0, 0, 0 },
6848 display_debug_str_offsets
, NULL
, 0 },
6849 { { ".debug_addr", ".zdebug_addr", NULL
, NULL
, 0, 0, 0 },
6850 display_debug_addr
, &do_debug_addr
, 1 },
6851 { { ".debug_cu_index", "", NULL
, NULL
, 0, 0, 0 },
6852 display_cu_index
, &do_debug_cu_index
, 0 },
6853 { { ".debug_tu_index", "", NULL
, NULL
, 0, 0, 0 },
6854 display_cu_index
, &do_debug_cu_index
, 0 },