1 /* dwarf.c -- display DWARF contents of a BFD binary file
2 Copyright 2005, 2006, 2007, 2008, 2009, 2010, 2011
3 Free Software Foundation, Inc.
5 This file is part of GNU Binutils.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
23 #include "libiberty.h"
25 #include "bfd_stdint.h"
28 #include "elf/common.h"
32 static const char *regname (unsigned int regno
, int row
);
34 static int have_frame_base
;
35 static int need_base_address
;
37 static unsigned int last_pointer_size
= 0;
38 static int warned_about_missing_comp_units
= FALSE
;
40 static unsigned int num_debug_info_entries
= 0;
41 static debug_info
*debug_information
= NULL
;
42 /* Special value for num_debug_info_entries to indicate
43 that the .debug_info section could not be loaded/parsed. */
44 #define DEBUG_INFO_UNAVAILABLE (unsigned int) -1
51 int do_debug_pubnames
;
52 int do_debug_pubtypes
;
56 int do_debug_frames_interp
;
66 /* Values for do_debug_lines. */
67 #define FLAG_DEBUG_LINES_RAW 1
68 #define FLAG_DEBUG_LINES_DECODED 2
71 size_of_encoded_value (int encoding
)
73 switch (encoding
& 0x7)
76 case 0: return eh_addr_size
;
84 get_encoded_value (unsigned char *data
,
86 struct dwarf_section
*section
)
88 int size
= size_of_encoded_value (encoding
);
91 if (encoding
& DW_EH_PE_signed
)
92 val
= byte_get_signed (data
, size
);
94 val
= byte_get (data
, size
);
96 if ((encoding
& 0x70) == DW_EH_PE_pcrel
)
97 val
+= section
->address
+ (data
- section
->start
);
101 /* Print a dwarf_vma value (typically an address, offset or length) in
102 hexadecimal format, followed by a space. The length of the value (and
103 hence the precision displayed) is determined by the byte_size parameter. */
106 print_dwarf_vma (dwarf_vma val
, unsigned byte_size
)
108 static char buff
[18];
111 /* Printf does not have a way of specifiying a maximum field width for an
112 integer value, so we print the full value into a buffer and then select
113 the precision we need. */
114 #if __STDC_VERSION__ >= 199901L || (defined(__GNUC__) && __GNUC__ >= 2)
116 snprintf (buff
, sizeof (buff
), "%16.16llx ", val
);
118 snprintf (buff
, sizeof (buff
), "%016I64x ", val
);
121 snprintf (buff
, sizeof (buff
), "%16.16lx ", val
);
126 if (byte_size
> 0 && byte_size
<= 8)
127 offset
= 16 - 2 * byte_size
;
129 error ("Wrong size in print_dwarf_vma");
132 fputs (buff
+ offset
, stdout
);
135 #if __STDC_VERSION__ >= 199901L || (defined(__GNUC__) && __GNUC__ >= 2)
137 #define DWARF_VMA_FMT "ll"
139 #define DWARF_VMA_FMT "I64"
142 #define DWARF_VMA_FMT "l"
146 dwarf_vmatoa (const char *fmtch
, dwarf_vma value
)
148 /* As dwarf_vmatoa is used more then once in a printf call
149 for output, we are cycling through an fixed array of pointers
150 for return address. */
151 static int buf_pos
= 0;
152 static struct dwarf_vmatoa_buf
159 sprintf (fmt
, "%%%s%s", DWARF_VMA_FMT
, fmtch
);
161 ret
= buf
[buf_pos
++].place
;
162 buf_pos
%= ARRAY_SIZE (buf
);
164 snprintf (ret
, sizeof (buf
[0].place
), fmt
, value
);
170 read_leb128 (unsigned char *data
, unsigned int *length_return
, int sign
)
172 dwarf_vma result
= 0;
173 unsigned int num_read
= 0;
174 unsigned int shift
= 0;
182 result
|= ((dwarf_vma
) (byte
& 0x7f)) << shift
;
189 if (length_return
!= NULL
)
190 *length_return
= num_read
;
192 if (sign
&& (shift
< 8 * sizeof (result
)) && (byte
& 0x40))
193 result
|= -1L << shift
;
198 /* Create a signed version to avoid painful typecasts. */
199 static dwarf_signed_vma
200 read_sleb128 (unsigned char *data
, unsigned int *length_return
)
202 return (dwarf_signed_vma
) read_leb128 (data
, length_return
, 1);
205 typedef struct State_Machine_Registers
213 unsigned char op_index
;
214 unsigned char end_sequence
;
215 /* This variable hold the number of the last entry seen
216 in the File Table. */
217 unsigned int last_file_entry
;
220 static SMR state_machine_regs
;
223 reset_state_machine (int is_stmt
)
225 state_machine_regs
.address
= 0;
226 state_machine_regs
.op_index
= 0;
227 state_machine_regs
.file
= 1;
228 state_machine_regs
.line
= 1;
229 state_machine_regs
.column
= 0;
230 state_machine_regs
.is_stmt
= is_stmt
;
231 state_machine_regs
.basic_block
= 0;
232 state_machine_regs
.end_sequence
= 0;
233 state_machine_regs
.last_file_entry
= 0;
236 /* Handled an extend line op.
237 Returns the number of bytes read. */
240 process_extended_line_op (unsigned char *data
, int is_stmt
)
242 unsigned char op_code
;
243 unsigned int bytes_read
;
248 len
= read_leb128 (data
, & bytes_read
, 0);
253 warn (_("badly formed extended line op encountered!\n"));
260 printf (_(" Extended opcode %d: "), op_code
);
264 case DW_LNE_end_sequence
:
265 printf (_("End of Sequence\n\n"));
266 reset_state_machine (is_stmt
);
269 case DW_LNE_set_address
:
270 adr
= byte_get (data
, len
- bytes_read
- 1);
271 printf (_("set Address to 0x%s\n"), dwarf_vmatoa ("x", adr
));
272 state_machine_regs
.address
= adr
;
273 state_machine_regs
.op_index
= 0;
276 case DW_LNE_define_file
:
277 printf (_(" define new File Table entry\n"));
278 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
280 printf (" %d\t", ++state_machine_regs
.last_file_entry
);
282 data
+= strlen ((char *) data
) + 1;
283 printf ("%s\t", dwarf_vmatoa ("u", read_leb128 (data
, & bytes_read
, 0)));
285 printf ("%s\t", dwarf_vmatoa ("u", read_leb128 (data
, & bytes_read
, 0)));
287 printf ("%s\t", dwarf_vmatoa ("u", read_leb128 (data
, & bytes_read
, 0)));
288 printf ("%s\n\n", name
);
291 case DW_LNE_set_discriminator
:
292 printf (_("set Discriminator to %s\n"),
293 dwarf_vmatoa ("u", read_leb128 (data
, & bytes_read
, 0)));
297 case DW_LNE_HP_negate_is_UV_update
:
298 printf ("DW_LNE_HP_negate_is_UV_update\n");
300 case DW_LNE_HP_push_context
:
301 printf ("DW_LNE_HP_push_context\n");
303 case DW_LNE_HP_pop_context
:
304 printf ("DW_LNE_HP_pop_context\n");
306 case DW_LNE_HP_set_file_line_column
:
307 printf ("DW_LNE_HP_set_file_line_column\n");
309 case DW_LNE_HP_set_routine_name
:
310 printf ("DW_LNE_HP_set_routine_name\n");
312 case DW_LNE_HP_set_sequence
:
313 printf ("DW_LNE_HP_set_sequence\n");
315 case DW_LNE_HP_negate_post_semantics
:
316 printf ("DW_LNE_HP_negate_post_semantics\n");
318 case DW_LNE_HP_negate_function_exit
:
319 printf ("DW_LNE_HP_negate_function_exit\n");
321 case DW_LNE_HP_negate_front_end_logical
:
322 printf ("DW_LNE_HP_negate_front_end_logical\n");
324 case DW_LNE_HP_define_proc
:
325 printf ("DW_LNE_HP_define_proc\n");
327 case DW_LNE_HP_source_file_correlation
:
329 unsigned char *edata
= data
+ len
- bytes_read
- 1;
331 printf ("DW_LNE_HP_source_file_correlation\n");
337 opc
= read_leb128 (data
, & bytes_read
, 0);
342 case DW_LNE_HP_SFC_formfeed
:
343 printf (" DW_LNE_HP_SFC_formfeed\n");
345 case DW_LNE_HP_SFC_set_listing_line
:
346 printf (" DW_LNE_HP_SFC_set_listing_line (%s)\n",
348 read_leb128 (data
, & bytes_read
, 0)));
351 case DW_LNE_HP_SFC_associate
:
352 printf (" DW_LNE_HP_SFC_associate ");
355 read_leb128 (data
, & bytes_read
, 0)));
359 read_leb128 (data
, & bytes_read
, 0)));
363 read_leb128 (data
, & bytes_read
, 0)));
367 printf (" UNKNOW DW_LNE_HP_SFC opcode (%u)\n", opc
);
376 if (op_code
>= DW_LNE_lo_user
377 /* The test against DW_LNW_hi_user is redundant due to
378 the limited range of the unsigned char data type used
380 /*&& op_code <= DW_LNE_hi_user*/)
381 printf (_("user defined: length %d\n"), len
- bytes_read
);
383 printf (_("UNKNOWN: length %d\n"), len
- bytes_read
);
391 fetch_indirect_string (dwarf_vma offset
)
393 struct dwarf_section
*section
= &debug_displays
[str
].section
;
395 if (section
->start
== NULL
)
396 return _("<no .debug_str section>");
398 /* DWARF sections under Mach-O have non-zero addresses. */
399 offset
-= section
->address
;
400 if (offset
> section
->size
)
402 warn (_("DW_FORM_strp offset too big: %s\n"),
403 dwarf_vmatoa ("x", offset
));
404 return _("<offset is too big>");
407 return (const char *) section
->start
+ offset
;
410 /* FIXME: There are better and more efficient ways to handle
411 these structures. For now though, I just want something that
412 is simple to implement. */
413 typedef struct abbrev_attr
415 unsigned long attribute
;
417 struct abbrev_attr
*next
;
421 typedef struct abbrev_entry
426 struct abbrev_attr
*first_attr
;
427 struct abbrev_attr
*last_attr
;
428 struct abbrev_entry
*next
;
432 static abbrev_entry
*first_abbrev
= NULL
;
433 static abbrev_entry
*last_abbrev
= NULL
;
440 for (abbrv
= first_abbrev
; abbrv
;)
442 abbrev_entry
*next_abbrev
= abbrv
->next
;
445 for (attr
= abbrv
->first_attr
; attr
;)
447 abbrev_attr
*next_attr
= attr
->next
;
457 last_abbrev
= first_abbrev
= NULL
;
461 add_abbrev (unsigned long number
, unsigned long tag
, int children
)
465 entry
= (abbrev_entry
*) malloc (sizeof (*entry
));
470 entry
->entry
= number
;
472 entry
->children
= children
;
473 entry
->first_attr
= NULL
;
474 entry
->last_attr
= NULL
;
477 if (first_abbrev
== NULL
)
478 first_abbrev
= entry
;
480 last_abbrev
->next
= entry
;
486 add_abbrev_attr (unsigned long attribute
, unsigned long form
)
490 attr
= (abbrev_attr
*) malloc (sizeof (*attr
));
495 attr
->attribute
= attribute
;
499 if (last_abbrev
->first_attr
== NULL
)
500 last_abbrev
->first_attr
= attr
;
502 last_abbrev
->last_attr
->next
= attr
;
504 last_abbrev
->last_attr
= attr
;
507 /* Processes the (partial) contents of a .debug_abbrev section.
508 Returns NULL if the end of the section was encountered.
509 Returns the address after the last byte read if the end of
510 an abbreviation set was found. */
512 static unsigned char *
513 process_abbrev_section (unsigned char *start
, unsigned char *end
)
515 if (first_abbrev
!= NULL
)
520 unsigned int bytes_read
;
523 unsigned long attribute
;
526 entry
= read_leb128 (start
, & bytes_read
, 0);
529 /* A single zero is supposed to end the section according
530 to the standard. If there's more, then signal that to
533 return start
== end
? NULL
: start
;
535 tag
= read_leb128 (start
, & bytes_read
, 0);
540 add_abbrev (entry
, tag
, children
);
546 attribute
= read_leb128 (start
, & bytes_read
, 0);
549 form
= read_leb128 (start
, & bytes_read
, 0);
553 add_abbrev_attr (attribute
, form
);
555 while (attribute
!= 0);
562 get_TAG_name (unsigned long tag
)
566 case DW_TAG_padding
: return "DW_TAG_padding";
567 case DW_TAG_array_type
: return "DW_TAG_array_type";
568 case DW_TAG_class_type
: return "DW_TAG_class_type";
569 case DW_TAG_entry_point
: return "DW_TAG_entry_point";
570 case DW_TAG_enumeration_type
: return "DW_TAG_enumeration_type";
571 case DW_TAG_formal_parameter
: return "DW_TAG_formal_parameter";
572 case DW_TAG_imported_declaration
: return "DW_TAG_imported_declaration";
573 case DW_TAG_label
: return "DW_TAG_label";
574 case DW_TAG_lexical_block
: return "DW_TAG_lexical_block";
575 case DW_TAG_member
: return "DW_TAG_member";
576 case DW_TAG_pointer_type
: return "DW_TAG_pointer_type";
577 case DW_TAG_reference_type
: return "DW_TAG_reference_type";
578 case DW_TAG_compile_unit
: return "DW_TAG_compile_unit";
579 case DW_TAG_string_type
: return "DW_TAG_string_type";
580 case DW_TAG_structure_type
: return "DW_TAG_structure_type";
581 case DW_TAG_subroutine_type
: return "DW_TAG_subroutine_type";
582 case DW_TAG_typedef
: return "DW_TAG_typedef";
583 case DW_TAG_union_type
: return "DW_TAG_union_type";
584 case DW_TAG_unspecified_parameters
: return "DW_TAG_unspecified_parameters";
585 case DW_TAG_variant
: return "DW_TAG_variant";
586 case DW_TAG_common_block
: return "DW_TAG_common_block";
587 case DW_TAG_common_inclusion
: return "DW_TAG_common_inclusion";
588 case DW_TAG_inheritance
: return "DW_TAG_inheritance";
589 case DW_TAG_inlined_subroutine
: return "DW_TAG_inlined_subroutine";
590 case DW_TAG_module
: return "DW_TAG_module";
591 case DW_TAG_ptr_to_member_type
: return "DW_TAG_ptr_to_member_type";
592 case DW_TAG_set_type
: return "DW_TAG_set_type";
593 case DW_TAG_subrange_type
: return "DW_TAG_subrange_type";
594 case DW_TAG_with_stmt
: return "DW_TAG_with_stmt";
595 case DW_TAG_access_declaration
: return "DW_TAG_access_declaration";
596 case DW_TAG_base_type
: return "DW_TAG_base_type";
597 case DW_TAG_catch_block
: return "DW_TAG_catch_block";
598 case DW_TAG_const_type
: return "DW_TAG_const_type";
599 case DW_TAG_constant
: return "DW_TAG_constant";
600 case DW_TAG_enumerator
: return "DW_TAG_enumerator";
601 case DW_TAG_file_type
: return "DW_TAG_file_type";
602 case DW_TAG_friend
: return "DW_TAG_friend";
603 case DW_TAG_namelist
: return "DW_TAG_namelist";
604 case DW_TAG_namelist_item
: return "DW_TAG_namelist_item";
605 case DW_TAG_packed_type
: return "DW_TAG_packed_type";
606 case DW_TAG_subprogram
: return "DW_TAG_subprogram";
607 case DW_TAG_template_type_param
: return "DW_TAG_template_type_param";
608 case DW_TAG_template_value_param
: return "DW_TAG_template_value_param";
609 case DW_TAG_thrown_type
: return "DW_TAG_thrown_type";
610 case DW_TAG_try_block
: return "DW_TAG_try_block";
611 case DW_TAG_variant_part
: return "DW_TAG_variant_part";
612 case DW_TAG_variable
: return "DW_TAG_variable";
613 case DW_TAG_volatile_type
: return "DW_TAG_volatile_type";
614 case DW_TAG_MIPS_loop
: return "DW_TAG_MIPS_loop";
615 case DW_TAG_format_label
: return "DW_TAG_format_label";
616 case DW_TAG_function_template
: return "DW_TAG_function_template";
617 case DW_TAG_class_template
: return "DW_TAG_class_template";
618 /* DWARF 2.1 values. */
619 case DW_TAG_dwarf_procedure
: return "DW_TAG_dwarf_procedure";
620 case DW_TAG_restrict_type
: return "DW_TAG_restrict_type";
621 case DW_TAG_interface_type
: return "DW_TAG_interface_type";
622 case DW_TAG_namespace
: return "DW_TAG_namespace";
623 case DW_TAG_imported_module
: return "DW_TAG_imported_module";
624 case DW_TAG_unspecified_type
: return "DW_TAG_unspecified_type";
625 case DW_TAG_partial_unit
: return "DW_TAG_partial_unit";
626 case DW_TAG_imported_unit
: return "DW_TAG_imported_unit";
627 case DW_TAG_condition
: return "DW_TAG_condition";
628 case DW_TAG_shared_type
: return "DW_TAG_shared_type";
629 /* DWARF 4 values. */
630 case DW_TAG_type_unit
: return "DW_TAG_type_unit";
631 case DW_TAG_rvalue_reference_type
: return "DW_TAG_rvalue_reference_type";
632 case DW_TAG_template_alias
: return "DW_TAG_template_alias";
634 case DW_TAG_upc_shared_type
: return "DW_TAG_upc_shared_type";
635 case DW_TAG_upc_strict_type
: return "DW_TAG_upc_strict_type";
636 case DW_TAG_upc_relaxed_type
: return "DW_TAG_upc_relaxed_type";
638 case DW_TAG_GNU_call_site
: return "DW_TAG_GNU_call_site";
639 case DW_TAG_GNU_call_site_parameter
:return "DW_TAG_GNU_call_site_parameter";
642 static char buffer
[100];
644 snprintf (buffer
, sizeof (buffer
), _("Unknown TAG value: %lx"), tag
);
651 get_FORM_name (unsigned long form
)
655 case DW_FORM_addr
: return "DW_FORM_addr";
656 case DW_FORM_block2
: return "DW_FORM_block2";
657 case DW_FORM_block4
: return "DW_FORM_block4";
658 case DW_FORM_data2
: return "DW_FORM_data2";
659 case DW_FORM_data4
: return "DW_FORM_data4";
660 case DW_FORM_data8
: return "DW_FORM_data8";
661 case DW_FORM_string
: return "DW_FORM_string";
662 case DW_FORM_block
: return "DW_FORM_block";
663 case DW_FORM_block1
: return "DW_FORM_block1";
664 case DW_FORM_data1
: return "DW_FORM_data1";
665 case DW_FORM_flag
: return "DW_FORM_flag";
666 case DW_FORM_sdata
: return "DW_FORM_sdata";
667 case DW_FORM_strp
: return "DW_FORM_strp";
668 case DW_FORM_udata
: return "DW_FORM_udata";
669 case DW_FORM_ref_addr
: return "DW_FORM_ref_addr";
670 case DW_FORM_ref1
: return "DW_FORM_ref1";
671 case DW_FORM_ref2
: return "DW_FORM_ref2";
672 case DW_FORM_ref4
: return "DW_FORM_ref4";
673 case DW_FORM_ref8
: return "DW_FORM_ref8";
674 case DW_FORM_ref_udata
: return "DW_FORM_ref_udata";
675 case DW_FORM_indirect
: return "DW_FORM_indirect";
676 /* DWARF 4 values. */
677 case DW_FORM_sec_offset
: return "DW_FORM_sec_offset";
678 case DW_FORM_exprloc
: return "DW_FORM_exprloc";
679 case DW_FORM_flag_present
: return "DW_FORM_flag_present";
680 case DW_FORM_ref_sig8
: return "DW_FORM_ref_sig8";
683 static char buffer
[100];
685 snprintf (buffer
, sizeof (buffer
), _("Unknown FORM value: %lx"), form
);
691 static unsigned char *
692 display_block (unsigned char *data
, dwarf_vma length
)
694 printf (_(" %s byte block: "), dwarf_vmatoa ("u", length
));
697 printf ("%lx ", (unsigned long) byte_get (data
++, 1));
703 decode_location_expression (unsigned char * data
,
704 unsigned int pointer_size
,
705 unsigned int offset_size
,
709 struct dwarf_section
* section
)
712 unsigned int bytes_read
;
714 unsigned char *end
= data
+ length
;
715 int need_frame_base
= 0;
724 printf ("DW_OP_addr: %s",
725 dwarf_vmatoa ("x", byte_get (data
, pointer_size
)));
726 data
+= pointer_size
;
729 printf ("DW_OP_deref");
732 printf ("DW_OP_const1u: %lu", (unsigned long) byte_get (data
++, 1));
735 printf ("DW_OP_const1s: %ld", (long) byte_get_signed (data
++, 1));
738 printf ("DW_OP_const2u: %lu", (unsigned long) byte_get (data
, 2));
742 printf ("DW_OP_const2s: %ld", (long) byte_get_signed (data
, 2));
746 printf ("DW_OP_const4u: %lu", (unsigned long) byte_get (data
, 4));
750 printf ("DW_OP_const4s: %ld", (long) byte_get_signed (data
, 4));
754 printf ("DW_OP_const8u: %lu %lu", (unsigned long) byte_get (data
, 4),
755 (unsigned long) byte_get (data
+ 4, 4));
759 printf ("DW_OP_const8s: %ld %ld", (long) byte_get (data
, 4),
760 (long) byte_get (data
+ 4, 4));
764 printf ("DW_OP_constu: %s",
765 dwarf_vmatoa ("u", read_leb128 (data
, &bytes_read
, 0)));
769 printf ("DW_OP_consts: %s",
770 dwarf_vmatoa ("d", read_sleb128 (data
, &bytes_read
)));
774 printf ("DW_OP_dup");
777 printf ("DW_OP_drop");
780 printf ("DW_OP_over");
783 printf ("DW_OP_pick: %ld", (unsigned long) byte_get (data
++, 1));
786 printf ("DW_OP_swap");
789 printf ("DW_OP_rot");
792 printf ("DW_OP_xderef");
795 printf ("DW_OP_abs");
798 printf ("DW_OP_and");
801 printf ("DW_OP_div");
804 printf ("DW_OP_minus");
807 printf ("DW_OP_mod");
810 printf ("DW_OP_mul");
813 printf ("DW_OP_neg");
816 printf ("DW_OP_not");
822 printf ("DW_OP_plus");
824 case DW_OP_plus_uconst
:
825 printf ("DW_OP_plus_uconst: %s",
826 dwarf_vmatoa ("u", read_leb128 (data
, &bytes_read
, 0)));
830 printf ("DW_OP_shl");
833 printf ("DW_OP_shr");
836 printf ("DW_OP_shra");
839 printf ("DW_OP_xor");
842 printf ("DW_OP_bra: %ld", (long) byte_get_signed (data
, 2));
864 printf ("DW_OP_skip: %ld", (long) byte_get_signed (data
, 2));
900 printf ("DW_OP_lit%d", op
- DW_OP_lit0
);
935 printf ("DW_OP_reg%d (%s)", op
- DW_OP_reg0
,
936 regname (op
- DW_OP_reg0
, 1));
971 printf ("DW_OP_breg%d (%s): %s",
973 regname (op
- DW_OP_breg0
, 1),
974 dwarf_vmatoa ("d", (dwarf_signed_vma
)
975 read_leb128 (data
, &bytes_read
, 1)));
980 uvalue
= read_leb128 (data
, &bytes_read
, 0);
982 printf ("DW_OP_regx: %s (%s)",
983 dwarf_vmatoa ("u", uvalue
), regname (uvalue
, 1));
987 printf ("DW_OP_fbreg: %s",
988 dwarf_vmatoa ("d", read_sleb128 (data
, &bytes_read
)));
992 uvalue
= read_leb128 (data
, &bytes_read
, 0);
994 printf ("DW_OP_bregx: %s (%s) %s",
995 dwarf_vmatoa ("u", uvalue
), regname (uvalue
, 1),
996 dwarf_vmatoa ("d", read_sleb128 (data
, &bytes_read
)));
1000 printf ("DW_OP_piece: %s",
1001 dwarf_vmatoa ("u", read_leb128 (data
, &bytes_read
, 0)));
1004 case DW_OP_deref_size
:
1005 printf ("DW_OP_deref_size: %ld", (long) byte_get (data
++, 1));
1007 case DW_OP_xderef_size
:
1008 printf ("DW_OP_xderef_size: %ld", (long) byte_get (data
++, 1));
1011 printf ("DW_OP_nop");
1014 /* DWARF 3 extensions. */
1015 case DW_OP_push_object_address
:
1016 printf ("DW_OP_push_object_address");
1019 /* XXX: Strictly speaking for 64-bit DWARF3 files
1020 this ought to be an 8-byte wide computation. */
1021 printf ("DW_OP_call2: <0x%s>",
1022 dwarf_vmatoa ("x", (dwarf_signed_vma
) byte_get (data
, 2)
1027 /* XXX: Strictly speaking for 64-bit DWARF3 files
1028 this ought to be an 8-byte wide computation. */
1029 printf ("DW_OP_call4: <0x%s>",
1030 dwarf_vmatoa ("x", (dwarf_signed_vma
) byte_get (data
, 4)
1034 case DW_OP_call_ref
:
1035 /* XXX: Strictly speaking for 64-bit DWARF3 files
1036 this ought to be an 8-byte wide computation. */
1037 if (dwarf_version
== -1)
1039 printf (_("(DW_OP_call_ref in frame info)"));
1040 /* No way to tell where the next op is, so just bail. */
1041 return need_frame_base
;
1043 if (dwarf_version
== 2)
1045 printf ("DW_OP_call_ref: <0x%s>",
1046 dwarf_vmatoa ("x", byte_get (data
, pointer_size
)));
1047 data
+= pointer_size
;
1051 printf ("DW_OP_call_ref: <0x%s>",
1052 dwarf_vmatoa ("x", byte_get (data
, offset_size
)));
1053 data
+= offset_size
;
1056 case DW_OP_form_tls_address
:
1057 printf ("DW_OP_form_tls_address");
1059 case DW_OP_call_frame_cfa
:
1060 printf ("DW_OP_call_frame_cfa");
1062 case DW_OP_bit_piece
:
1063 printf ("DW_OP_bit_piece: ");
1064 printf ("size: %s ",
1065 dwarf_vmatoa ("u", read_leb128 (data
, &bytes_read
, 0)));
1067 printf ("offset: %s ",
1068 dwarf_vmatoa ("u", read_leb128 (data
, &bytes_read
, 0)));
1072 /* DWARF 4 extensions. */
1073 case DW_OP_stack_value
:
1074 printf ("DW_OP_stack_value");
1077 case DW_OP_implicit_value
:
1078 printf ("DW_OP_implicit_value");
1079 uvalue
= read_leb128 (data
, &bytes_read
, 0);
1081 display_block (data
, uvalue
);
1084 case DW_OP_GNU_entry_value
:
1085 uvalue
= read_leb128 (data
, &bytes_read
, 0);
1087 printf ("DW_OP_GNU_entry_value: (");
1088 if (decode_location_expression (data
, pointer_size
, offset_size
,
1089 dwarf_version
, uvalue
,
1090 cu_offset
, section
))
1091 need_frame_base
= 1;
1096 /* GNU extensions. */
1097 case DW_OP_GNU_push_tls_address
:
1098 printf ("DW_OP_GNU_push_tls_address or DW_OP_HP_unknown");
1100 case DW_OP_GNU_uninit
:
1101 printf ("DW_OP_GNU_uninit");
1102 /* FIXME: Is there data associated with this OP ? */
1104 case DW_OP_GNU_encoded_addr
:
1110 addr
= get_encoded_value (data
, encoding
, section
);
1111 data
+= size_of_encoded_value (encoding
);
1113 printf ("DW_OP_GNU_encoded_addr: fmt:%02x addr:", encoding
);
1114 print_dwarf_vma (addr
, pointer_size
);
1117 case DW_OP_GNU_implicit_pointer
:
1118 /* XXX: Strictly speaking for 64-bit DWARF3 files
1119 this ought to be an 8-byte wide computation. */
1120 if (dwarf_version
== -1)
1122 printf (_("(DW_OP_GNU_implicit_pointer in frame info)"));
1123 /* No way to tell where the next op is, so just bail. */
1124 return need_frame_base
;
1126 if (dwarf_version
== 2)
1128 printf ("DW_OP_GNU_implicit_pointer: <0x%s> %s",
1129 dwarf_vmatoa ("x", byte_get (data
, pointer_size
)),
1130 dwarf_vmatoa ("d", read_sleb128 (data
+ pointer_size
,
1132 data
+= pointer_size
+ bytes_read
;
1136 printf ("DW_OP_GNU_implicit_pointer: <0x%s> %s",
1137 dwarf_vmatoa ("x", byte_get (data
, offset_size
)),
1138 dwarf_vmatoa ("d", read_sleb128 (data
+ offset_size
,
1140 data
+= offset_size
+ bytes_read
;
1144 /* HP extensions. */
1145 case DW_OP_HP_is_value
:
1146 printf ("DW_OP_HP_is_value");
1147 /* FIXME: Is there data associated with this OP ? */
1149 case DW_OP_HP_fltconst4
:
1150 printf ("DW_OP_HP_fltconst4");
1151 /* FIXME: Is there data associated with this OP ? */
1153 case DW_OP_HP_fltconst8
:
1154 printf ("DW_OP_HP_fltconst8");
1155 /* FIXME: Is there data associated with this OP ? */
1157 case DW_OP_HP_mod_range
:
1158 printf ("DW_OP_HP_mod_range");
1159 /* FIXME: Is there data associated with this OP ? */
1161 case DW_OP_HP_unmod_range
:
1162 printf ("DW_OP_HP_unmod_range");
1163 /* FIXME: Is there data associated with this OP ? */
1166 printf ("DW_OP_HP_tls");
1167 /* FIXME: Is there data associated with this OP ? */
1170 /* PGI (STMicroelectronics) extensions. */
1171 case DW_OP_PGI_omp_thread_num
:
1172 /* Pushes the thread number for the current thread as it would be
1173 returned by the standard OpenMP library function:
1174 omp_get_thread_num(). The "current thread" is the thread for
1175 which the expression is being evaluated. */
1176 printf ("DW_OP_PGI_omp_thread_num");
1180 if (op
>= DW_OP_lo_user
1181 && op
<= DW_OP_hi_user
)
1182 printf (_("(User defined location op)"));
1184 printf (_("(Unknown location op)"));
1185 /* No way to tell where the next op is, so just bail. */
1186 return need_frame_base
;
1189 /* Separate the ops. */
1194 return need_frame_base
;
1197 static unsigned char *
1198 read_and_display_attr_value (unsigned long attribute
,
1200 unsigned char * data
,
1201 dwarf_vma cu_offset
,
1202 dwarf_vma pointer_size
,
1203 dwarf_vma offset_size
,
1205 debug_info
* debug_info_p
,
1207 struct dwarf_section
* section
)
1209 dwarf_vma uvalue
= 0;
1210 unsigned char *block_start
= NULL
;
1211 unsigned char * orig_data
= data
;
1212 unsigned int bytes_read
;
1219 case DW_FORM_ref_addr
:
1220 if (dwarf_version
== 2)
1222 uvalue
= byte_get (data
, pointer_size
);
1223 data
+= pointer_size
;
1225 else if (dwarf_version
== 3 || dwarf_version
== 4)
1227 uvalue
= byte_get (data
, offset_size
);
1228 data
+= offset_size
;
1231 error (_("Internal error: DWARF version is not 2, 3 or 4.\n"));
1236 uvalue
= byte_get (data
, pointer_size
);
1237 data
+= pointer_size
;
1241 case DW_FORM_sec_offset
:
1242 uvalue
= byte_get (data
, offset_size
);
1243 data
+= offset_size
;
1246 case DW_FORM_flag_present
:
1253 uvalue
= byte_get (data
++, 1);
1258 uvalue
= byte_get (data
, 2);
1264 uvalue
= byte_get (data
, 4);
1269 uvalue
= read_leb128 (data
, & bytes_read
, 1);
1273 case DW_FORM_ref_udata
:
1275 uvalue
= read_leb128 (data
, & bytes_read
, 0);
1279 case DW_FORM_indirect
:
1280 form
= read_leb128 (data
, & bytes_read
, 0);
1283 printf (" %s", get_FORM_name (form
));
1284 return read_and_display_attr_value (attribute
, form
, data
,
1285 cu_offset
, pointer_size
,
1286 offset_size
, dwarf_version
,
1287 debug_info_p
, do_loc
,
1293 case DW_FORM_ref_addr
:
1295 printf (" <0x%s>", dwarf_vmatoa ("x",uvalue
));
1301 case DW_FORM_ref_udata
:
1303 printf (" <0x%s>", dwarf_vmatoa ("x", uvalue
+ cu_offset
));
1308 case DW_FORM_sec_offset
:
1310 printf (" 0x%s", dwarf_vmatoa ("x", uvalue
));
1313 case DW_FORM_flag_present
:
1320 printf (" %s", dwarf_vmatoa ("d", uvalue
));
1327 uvalue
= byte_get (data
, 4);
1328 printf (" 0x%s", dwarf_vmatoa ("x", uvalue
));
1329 printf (" 0x%lx", (unsigned long) byte_get (data
+ 4, 4));
1331 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
1332 && num_debug_info_entries
== 0)
1334 if (sizeof (uvalue
) == 8)
1335 uvalue
= byte_get (data
, 8);
1337 error (_("DW_FORM_data8 is unsupported when sizeof (dwarf_vma) != 8\n"));
1342 case DW_FORM_string
:
1344 printf (" %s", data
);
1345 data
+= strlen ((char *) data
) + 1;
1349 case DW_FORM_exprloc
:
1350 uvalue
= read_leb128 (data
, & bytes_read
, 0);
1351 block_start
= data
+ bytes_read
;
1353 data
= block_start
+ uvalue
;
1355 data
= display_block (block_start
, uvalue
);
1358 case DW_FORM_block1
:
1359 uvalue
= byte_get (data
, 1);
1360 block_start
= data
+ 1;
1362 data
= block_start
+ uvalue
;
1364 data
= display_block (block_start
, uvalue
);
1367 case DW_FORM_block2
:
1368 uvalue
= byte_get (data
, 2);
1369 block_start
= data
+ 2;
1371 data
= block_start
+ uvalue
;
1373 data
= display_block (block_start
, uvalue
);
1376 case DW_FORM_block4
:
1377 uvalue
= byte_get (data
, 4);
1378 block_start
= data
+ 4;
1380 data
= block_start
+ uvalue
;
1382 data
= display_block (block_start
, uvalue
);
1387 printf (_(" (indirect string, offset: 0x%s): %s"),
1388 dwarf_vmatoa ("x", uvalue
),
1389 fetch_indirect_string (uvalue
));
1392 case DW_FORM_indirect
:
1393 /* Handled above. */
1396 case DW_FORM_ref_sig8
:
1400 printf (" signature: ");
1401 for (i
= 0; i
< 8; i
++)
1403 printf ("%02x", (unsigned) byte_get (data
, 1));
1412 warn (_("Unrecognized form: %lu\n"), form
);
1416 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
1417 && num_debug_info_entries
== 0)
1421 case DW_AT_frame_base
:
1422 have_frame_base
= 1;
1423 case DW_AT_location
:
1424 case DW_AT_string_length
:
1425 case DW_AT_return_addr
:
1426 case DW_AT_data_member_location
:
1427 case DW_AT_vtable_elem_location
:
1429 case DW_AT_static_link
:
1430 case DW_AT_use_location
:
1431 case DW_AT_GNU_call_site_value
:
1432 case DW_AT_GNU_call_site_data_value
:
1433 case DW_AT_GNU_call_site_target
:
1434 case DW_AT_GNU_call_site_target_clobbered
:
1435 if (form
== DW_FORM_data4
1436 || form
== DW_FORM_data8
1437 || form
== DW_FORM_sec_offset
)
1439 /* Process location list. */
1440 unsigned int lmax
= debug_info_p
->max_loc_offsets
;
1441 unsigned int num
= debug_info_p
->num_loc_offsets
;
1443 if (lmax
== 0 || num
>= lmax
)
1446 debug_info_p
->loc_offsets
= (dwarf_vma
*)
1447 xcrealloc (debug_info_p
->loc_offsets
,
1448 lmax
, sizeof (*debug_info_p
->loc_offsets
));
1449 debug_info_p
->have_frame_base
= (int *)
1450 xcrealloc (debug_info_p
->have_frame_base
,
1451 lmax
, sizeof (*debug_info_p
->have_frame_base
));
1452 debug_info_p
->max_loc_offsets
= lmax
;
1454 debug_info_p
->loc_offsets
[num
] = uvalue
;
1455 debug_info_p
->have_frame_base
[num
] = have_frame_base
;
1456 debug_info_p
->num_loc_offsets
++;
1461 if (need_base_address
)
1462 debug_info_p
->base_address
= uvalue
;
1466 if (form
== DW_FORM_data4
1467 || form
== DW_FORM_data8
1468 || form
== DW_FORM_sec_offset
)
1470 /* Process range list. */
1471 unsigned int lmax
= debug_info_p
->max_range_lists
;
1472 unsigned int num
= debug_info_p
->num_range_lists
;
1474 if (lmax
== 0 || num
>= lmax
)
1477 debug_info_p
->range_lists
= (dwarf_vma
*)
1478 xcrealloc (debug_info_p
->range_lists
,
1479 lmax
, sizeof (*debug_info_p
->range_lists
));
1480 debug_info_p
->max_range_lists
= lmax
;
1482 debug_info_p
->range_lists
[num
] = uvalue
;
1483 debug_info_p
->num_range_lists
++;
1495 /* For some attributes we can display further information. */
1503 case DW_INL_not_inlined
:
1504 printf (_("(not inlined)"));
1506 case DW_INL_inlined
:
1507 printf (_("(inlined)"));
1509 case DW_INL_declared_not_inlined
:
1510 printf (_("(declared as inline but ignored)"));
1512 case DW_INL_declared_inlined
:
1513 printf (_("(declared as inline and inlined)"));
1516 printf (_(" (Unknown inline attribute value: %s)"),
1517 dwarf_vmatoa ("x", uvalue
));
1522 case DW_AT_language
:
1525 /* Ordered by the numeric value of these constants. */
1526 case DW_LANG_C89
: printf ("(ANSI C)"); break;
1527 case DW_LANG_C
: printf ("(non-ANSI C)"); break;
1528 case DW_LANG_Ada83
: printf ("(Ada)"); break;
1529 case DW_LANG_C_plus_plus
: printf ("(C++)"); break;
1530 case DW_LANG_Cobol74
: printf ("(Cobol 74)"); break;
1531 case DW_LANG_Cobol85
: printf ("(Cobol 85)"); break;
1532 case DW_LANG_Fortran77
: printf ("(FORTRAN 77)"); break;
1533 case DW_LANG_Fortran90
: printf ("(Fortran 90)"); break;
1534 case DW_LANG_Pascal83
: printf ("(ANSI Pascal)"); break;
1535 case DW_LANG_Modula2
: printf ("(Modula 2)"); break;
1536 /* DWARF 2.1 values. */
1537 case DW_LANG_Java
: printf ("(Java)"); break;
1538 case DW_LANG_C99
: printf ("(ANSI C99)"); break;
1539 case DW_LANG_Ada95
: printf ("(ADA 95)"); break;
1540 case DW_LANG_Fortran95
: printf ("(Fortran 95)"); break;
1541 /* DWARF 3 values. */
1542 case DW_LANG_PLI
: printf ("(PLI)"); break;
1543 case DW_LANG_ObjC
: printf ("(Objective C)"); break;
1544 case DW_LANG_ObjC_plus_plus
: printf ("(Objective C++)"); break;
1545 case DW_LANG_UPC
: printf ("(Unified Parallel C)"); break;
1546 case DW_LANG_D
: printf ("(D)"); break;
1547 /* DWARF 4 values. */
1548 case DW_LANG_Python
: printf ("(Python)"); break;
1549 /* MIPS extension. */
1550 case DW_LANG_Mips_Assembler
: printf ("(MIPS assembler)"); break;
1551 /* UPC extension. */
1552 case DW_LANG_Upc
: printf ("(Unified Parallel C)"); break;
1554 if (uvalue
>= DW_LANG_lo_user
&& uvalue
<= DW_LANG_hi_user
)
1555 printf ("(implementation defined: %s)",
1556 dwarf_vmatoa ("x", uvalue
));
1558 printf ("(Unknown: %s)", dwarf_vmatoa ("x", uvalue
));
1563 case DW_AT_encoding
:
1566 case DW_ATE_void
: printf ("(void)"); break;
1567 case DW_ATE_address
: printf ("(machine address)"); break;
1568 case DW_ATE_boolean
: printf ("(boolean)"); break;
1569 case DW_ATE_complex_float
: printf ("(complex float)"); break;
1570 case DW_ATE_float
: printf ("(float)"); break;
1571 case DW_ATE_signed
: printf ("(signed)"); break;
1572 case DW_ATE_signed_char
: printf ("(signed char)"); break;
1573 case DW_ATE_unsigned
: printf ("(unsigned)"); break;
1574 case DW_ATE_unsigned_char
: printf ("(unsigned char)"); break;
1575 /* DWARF 2.1 values: */
1576 case DW_ATE_imaginary_float
: printf ("(imaginary float)"); break;
1577 case DW_ATE_decimal_float
: printf ("(decimal float)"); break;
1578 /* DWARF 3 values: */
1579 case DW_ATE_packed_decimal
: printf ("(packed_decimal)"); break;
1580 case DW_ATE_numeric_string
: printf ("(numeric_string)"); break;
1581 case DW_ATE_edited
: printf ("(edited)"); break;
1582 case DW_ATE_signed_fixed
: printf ("(signed_fixed)"); break;
1583 case DW_ATE_unsigned_fixed
: printf ("(unsigned_fixed)"); break;
1584 /* HP extensions: */
1585 case DW_ATE_HP_float80
: printf ("(HP_float80)"); break;
1586 case DW_ATE_HP_complex_float80
: printf ("(HP_complex_float80)"); break;
1587 case DW_ATE_HP_float128
: printf ("(HP_float128)"); break;
1588 case DW_ATE_HP_complex_float128
:printf ("(HP_complex_float128)"); break;
1589 case DW_ATE_HP_floathpintel
: printf ("(HP_floathpintel)"); break;
1590 case DW_ATE_HP_imaginary_float80
: printf ("(HP_imaginary_float80)"); break;
1591 case DW_ATE_HP_imaginary_float128
: printf ("(HP_imaginary_float128)"); break;
1594 if (uvalue
>= DW_ATE_lo_user
1595 && uvalue
<= DW_ATE_hi_user
)
1596 printf ("(user defined type)");
1598 printf ("(unknown type)");
1603 case DW_AT_accessibility
:
1606 case DW_ACCESS_public
: printf ("(public)"); break;
1607 case DW_ACCESS_protected
: printf ("(protected)"); break;
1608 case DW_ACCESS_private
: printf ("(private)"); break;
1610 printf ("(unknown accessibility)");
1615 case DW_AT_visibility
:
1618 case DW_VIS_local
: printf ("(local)"); break;
1619 case DW_VIS_exported
: printf ("(exported)"); break;
1620 case DW_VIS_qualified
: printf ("(qualified)"); break;
1621 default: printf ("(unknown visibility)"); break;
1625 case DW_AT_virtuality
:
1628 case DW_VIRTUALITY_none
: printf ("(none)"); break;
1629 case DW_VIRTUALITY_virtual
: printf ("(virtual)"); break;
1630 case DW_VIRTUALITY_pure_virtual
:printf ("(pure_virtual)"); break;
1631 default: printf ("(unknown virtuality)"); break;
1635 case DW_AT_identifier_case
:
1638 case DW_ID_case_sensitive
: printf ("(case_sensitive)"); break;
1639 case DW_ID_up_case
: printf ("(up_case)"); break;
1640 case DW_ID_down_case
: printf ("(down_case)"); break;
1641 case DW_ID_case_insensitive
: printf ("(case_insensitive)"); break;
1642 default: printf ("(unknown case)"); break;
1646 case DW_AT_calling_convention
:
1649 case DW_CC_normal
: printf ("(normal)"); break;
1650 case DW_CC_program
: printf ("(program)"); break;
1651 case DW_CC_nocall
: printf ("(nocall)"); break;
1653 if (uvalue
>= DW_CC_lo_user
1654 && uvalue
<= DW_CC_hi_user
)
1655 printf ("(user defined)");
1657 printf ("(unknown convention)");
1661 case DW_AT_ordering
:
1664 case -1: printf ("(undefined)"); break;
1665 case 0: printf ("(row major)"); break;
1666 case 1: printf ("(column major)"); break;
1670 case DW_AT_frame_base
:
1671 have_frame_base
= 1;
1672 case DW_AT_location
:
1673 case DW_AT_string_length
:
1674 case DW_AT_return_addr
:
1675 case DW_AT_data_member_location
:
1676 case DW_AT_vtable_elem_location
:
1678 case DW_AT_static_link
:
1679 case DW_AT_use_location
:
1680 case DW_AT_GNU_call_site_value
:
1681 case DW_AT_GNU_call_site_data_value
:
1682 case DW_AT_GNU_call_site_target
:
1683 case DW_AT_GNU_call_site_target_clobbered
:
1684 if (form
== DW_FORM_data4
1685 || form
== DW_FORM_data8
1686 || form
== DW_FORM_sec_offset
)
1687 printf (_("(location list)"));
1689 case DW_AT_allocated
:
1690 case DW_AT_associated
:
1691 case DW_AT_data_location
:
1693 case DW_AT_upper_bound
:
1694 case DW_AT_lower_bound
:
1697 int need_frame_base
;
1700 need_frame_base
= decode_location_expression (block_start
,
1705 cu_offset
, section
);
1707 if (need_frame_base
&& !have_frame_base
)
1708 printf (_(" [without DW_AT_frame_base]"));
1714 if (form
== DW_FORM_ref_sig8
)
1717 if (form
== DW_FORM_ref1
1718 || form
== DW_FORM_ref2
1719 || form
== DW_FORM_ref4
)
1720 uvalue
+= cu_offset
;
1722 if (uvalue
>= section
->size
)
1723 warn (_("Offset %s used as value for DW_AT_import attribute of DIE at offset %lx is too big.\n"),
1724 dwarf_vmatoa ("x", uvalue
),
1725 (unsigned long) (orig_data
- section
->start
));
1728 unsigned long abbrev_number
;
1729 abbrev_entry
* entry
;
1731 abbrev_number
= read_leb128 (section
->start
+ uvalue
, NULL
, 0);
1733 printf ("[Abbrev Number: %ld", abbrev_number
);
1734 for (entry
= first_abbrev
; entry
!= NULL
; entry
= entry
->next
)
1735 if (entry
->entry
== abbrev_number
)
1738 printf (" (%s)", get_TAG_name (entry
->tag
));
1752 get_AT_name (unsigned long attribute
)
1756 case DW_AT_sibling
: return "DW_AT_sibling";
1757 case DW_AT_location
: return "DW_AT_location";
1758 case DW_AT_name
: return "DW_AT_name";
1759 case DW_AT_ordering
: return "DW_AT_ordering";
1760 case DW_AT_subscr_data
: return "DW_AT_subscr_data";
1761 case DW_AT_byte_size
: return "DW_AT_byte_size";
1762 case DW_AT_bit_offset
: return "DW_AT_bit_offset";
1763 case DW_AT_bit_size
: return "DW_AT_bit_size";
1764 case DW_AT_element_list
: return "DW_AT_element_list";
1765 case DW_AT_stmt_list
: return "DW_AT_stmt_list";
1766 case DW_AT_low_pc
: return "DW_AT_low_pc";
1767 case DW_AT_high_pc
: return "DW_AT_high_pc";
1768 case DW_AT_language
: return "DW_AT_language";
1769 case DW_AT_member
: return "DW_AT_member";
1770 case DW_AT_discr
: return "DW_AT_discr";
1771 case DW_AT_discr_value
: return "DW_AT_discr_value";
1772 case DW_AT_visibility
: return "DW_AT_visibility";
1773 case DW_AT_import
: return "DW_AT_import";
1774 case DW_AT_string_length
: return "DW_AT_string_length";
1775 case DW_AT_common_reference
: return "DW_AT_common_reference";
1776 case DW_AT_comp_dir
: return "DW_AT_comp_dir";
1777 case DW_AT_const_value
: return "DW_AT_const_value";
1778 case DW_AT_containing_type
: return "DW_AT_containing_type";
1779 case DW_AT_default_value
: return "DW_AT_default_value";
1780 case DW_AT_inline
: return "DW_AT_inline";
1781 case DW_AT_is_optional
: return "DW_AT_is_optional";
1782 case DW_AT_lower_bound
: return "DW_AT_lower_bound";
1783 case DW_AT_producer
: return "DW_AT_producer";
1784 case DW_AT_prototyped
: return "DW_AT_prototyped";
1785 case DW_AT_return_addr
: return "DW_AT_return_addr";
1786 case DW_AT_start_scope
: return "DW_AT_start_scope";
1787 case DW_AT_stride_size
: return "DW_AT_stride_size";
1788 case DW_AT_upper_bound
: return "DW_AT_upper_bound";
1789 case DW_AT_abstract_origin
: return "DW_AT_abstract_origin";
1790 case DW_AT_accessibility
: return "DW_AT_accessibility";
1791 case DW_AT_address_class
: return "DW_AT_address_class";
1792 case DW_AT_artificial
: return "DW_AT_artificial";
1793 case DW_AT_base_types
: return "DW_AT_base_types";
1794 case DW_AT_calling_convention
: return "DW_AT_calling_convention";
1795 case DW_AT_count
: return "DW_AT_count";
1796 case DW_AT_data_member_location
: return "DW_AT_data_member_location";
1797 case DW_AT_decl_column
: return "DW_AT_decl_column";
1798 case DW_AT_decl_file
: return "DW_AT_decl_file";
1799 case DW_AT_decl_line
: return "DW_AT_decl_line";
1800 case DW_AT_declaration
: return "DW_AT_declaration";
1801 case DW_AT_discr_list
: return "DW_AT_discr_list";
1802 case DW_AT_encoding
: return "DW_AT_encoding";
1803 case DW_AT_external
: return "DW_AT_external";
1804 case DW_AT_frame_base
: return "DW_AT_frame_base";
1805 case DW_AT_friend
: return "DW_AT_friend";
1806 case DW_AT_identifier_case
: return "DW_AT_identifier_case";
1807 case DW_AT_macro_info
: return "DW_AT_macro_info";
1808 case DW_AT_namelist_items
: return "DW_AT_namelist_items";
1809 case DW_AT_priority
: return "DW_AT_priority";
1810 case DW_AT_segment
: return "DW_AT_segment";
1811 case DW_AT_specification
: return "DW_AT_specification";
1812 case DW_AT_static_link
: return "DW_AT_static_link";
1813 case DW_AT_type
: return "DW_AT_type";
1814 case DW_AT_use_location
: return "DW_AT_use_location";
1815 case DW_AT_variable_parameter
: return "DW_AT_variable_parameter";
1816 case DW_AT_virtuality
: return "DW_AT_virtuality";
1817 case DW_AT_vtable_elem_location
: return "DW_AT_vtable_elem_location";
1818 /* DWARF 2.1 values. */
1819 case DW_AT_allocated
: return "DW_AT_allocated";
1820 case DW_AT_associated
: return "DW_AT_associated";
1821 case DW_AT_data_location
: return "DW_AT_data_location";
1822 case DW_AT_stride
: return "DW_AT_stride";
1823 case DW_AT_entry_pc
: return "DW_AT_entry_pc";
1824 case DW_AT_use_UTF8
: return "DW_AT_use_UTF8";
1825 case DW_AT_extension
: return "DW_AT_extension";
1826 case DW_AT_ranges
: return "DW_AT_ranges";
1827 case DW_AT_trampoline
: return "DW_AT_trampoline";
1828 case DW_AT_call_column
: return "DW_AT_call_column";
1829 case DW_AT_call_file
: return "DW_AT_call_file";
1830 case DW_AT_call_line
: return "DW_AT_call_line";
1831 case DW_AT_description
: return "DW_AT_description";
1832 case DW_AT_binary_scale
: return "DW_AT_binary_scale";
1833 case DW_AT_decimal_scale
: return "DW_AT_decimal_scale";
1834 case DW_AT_small
: return "DW_AT_small";
1835 case DW_AT_decimal_sign
: return "DW_AT_decimal_sign";
1836 case DW_AT_digit_count
: return "DW_AT_digit_count";
1837 case DW_AT_picture_string
: return "DW_AT_picture_string";
1838 case DW_AT_mutable
: return "DW_AT_mutable";
1839 case DW_AT_threads_scaled
: return "DW_AT_threads_scaled";
1840 case DW_AT_explicit
: return "DW_AT_explicit";
1841 case DW_AT_object_pointer
: return "DW_AT_object_pointer";
1842 case DW_AT_endianity
: return "DW_AT_endianity";
1843 case DW_AT_elemental
: return "DW_AT_elemental";
1844 case DW_AT_pure
: return "DW_AT_pure";
1845 case DW_AT_recursive
: return "DW_AT_recursive";
1846 /* DWARF 4 values. */
1847 case DW_AT_signature
: return "DW_AT_signature";
1848 case DW_AT_main_subprogram
: return "DW_AT_main_subprogram";
1849 case DW_AT_data_bit_offset
: return "DW_AT_data_bit_offset";
1850 case DW_AT_const_expr
: return "DW_AT_const_expr";
1851 case DW_AT_enum_class
: return "DW_AT_enum_class";
1852 case DW_AT_linkage_name
: return "DW_AT_linkage_name";
1854 /* HP and SGI/MIPS extensions. */
1855 case DW_AT_MIPS_loop_begin
: return "DW_AT_MIPS_loop_begin";
1856 case DW_AT_MIPS_tail_loop_begin
: return "DW_AT_MIPS_tail_loop_begin";
1857 case DW_AT_MIPS_epilog_begin
: return "DW_AT_MIPS_epilog_begin";
1858 case DW_AT_MIPS_loop_unroll_factor
: return "DW_AT_MIPS_loop_unroll_factor";
1859 case DW_AT_MIPS_software_pipeline_depth
: return "DW_AT_MIPS_software_pipeline_depth";
1860 case DW_AT_MIPS_linkage_name
: return "DW_AT_MIPS_linkage_name";
1861 case DW_AT_MIPS_stride
: return "DW_AT_MIPS_stride";
1862 case DW_AT_MIPS_abstract_name
: return "DW_AT_MIPS_abstract_name";
1863 case DW_AT_MIPS_clone_origin
: return "DW_AT_MIPS_clone_origin";
1864 case DW_AT_MIPS_has_inlines
: return "DW_AT_MIPS_has_inlines";
1866 /* HP Extensions. */
1867 case DW_AT_HP_block_index
: return "DW_AT_HP_block_index";
1868 case DW_AT_HP_actuals_stmt_list
: return "DW_AT_HP_actuals_stmt_list";
1869 case DW_AT_HP_proc_per_section
: return "DW_AT_HP_proc_per_section";
1870 case DW_AT_HP_raw_data_ptr
: return "DW_AT_HP_raw_data_ptr";
1871 case DW_AT_HP_pass_by_reference
: return "DW_AT_HP_pass_by_reference";
1872 case DW_AT_HP_opt_level
: return "DW_AT_HP_opt_level";
1873 case DW_AT_HP_prof_version_id
: return "DW_AT_HP_prof_version_id";
1874 case DW_AT_HP_opt_flags
: return "DW_AT_HP_opt_flags";
1875 case DW_AT_HP_cold_region_low_pc
: return "DW_AT_HP_cold_region_low_pc";
1876 case DW_AT_HP_cold_region_high_pc
: return "DW_AT_HP_cold_region_high_pc";
1877 case DW_AT_HP_all_variables_modifiable
: return "DW_AT_HP_all_variables_modifiable";
1878 case DW_AT_HP_linkage_name
: return "DW_AT_HP_linkage_name";
1879 case DW_AT_HP_prof_flags
: return "DW_AT_HP_prof_flags";
1881 /* One value is shared by the MIPS and HP extensions: */
1882 case DW_AT_MIPS_fde
: return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable";
1884 /* GNU extensions. */
1885 case DW_AT_sf_names
: return "DW_AT_sf_names";
1886 case DW_AT_src_info
: return "DW_AT_src_info";
1887 case DW_AT_mac_info
: return "DW_AT_mac_info";
1888 case DW_AT_src_coords
: return "DW_AT_src_coords";
1889 case DW_AT_body_begin
: return "DW_AT_body_begin";
1890 case DW_AT_body_end
: return "DW_AT_body_end";
1891 case DW_AT_GNU_vector
: return "DW_AT_GNU_vector";
1892 case DW_AT_GNU_guarded_by
: return "DW_AT_GNU_guarded_by";
1893 case DW_AT_GNU_pt_guarded_by
: return "DW_AT_GNU_pt_guarded_by";
1894 case DW_AT_GNU_guarded
: return "DW_AT_GNU_guarded";
1895 case DW_AT_GNU_pt_guarded
: return "DW_AT_GNU_pt_guarded";
1896 case DW_AT_GNU_locks_excluded
: return "DW_AT_GNU_locks_excluded";
1897 case DW_AT_GNU_exclusive_locks_required
: return "DW_AT_GNU_exclusive_locks_required";
1898 case DW_AT_GNU_shared_locks_required
: return "DW_AT_GNU_shared_locks_required";
1899 case DW_AT_GNU_odr_signature
: return "DW_AT_GNU_odr_signature";
1900 case DW_AT_use_GNAT_descriptive_type
: return "DW_AT_use_GNAT_descriptive_type";
1901 case DW_AT_GNAT_descriptive_type
: return "DW_AT_GNAT_descriptive_type";
1902 case DW_AT_GNU_call_site_value
: return "DW_AT_GNU_call_site_value";
1903 case DW_AT_GNU_call_site_data_value
: return "DW_AT_GNU_call_site_data_value";
1904 case DW_AT_GNU_call_site_target
: return "DW_AT_GNU_call_site_target";
1905 case DW_AT_GNU_call_site_target_clobbered
: return "DW_AT_GNU_call_site_target_clobbered";
1906 case DW_AT_GNU_tail_call
: return "DW_AT_GNU_tail_call";
1907 case DW_AT_GNU_all_tail_call_sites
: return "DW_AT_GNU_all_tail_call_sites";
1908 case DW_AT_GNU_all_call_sites
: return "DW_AT_GNU_all_call_sites";
1909 case DW_AT_GNU_all_source_call_sites
: return "DW_AT_GNU_all_source_call_sites";
1911 /* UPC extension. */
1912 case DW_AT_upc_threads_scaled
: return "DW_AT_upc_threads_scaled";
1914 /* PGI (STMicroelectronics) extensions. */
1915 case DW_AT_PGI_lbase
: return "DW_AT_PGI_lbase";
1916 case DW_AT_PGI_soffset
: return "DW_AT_PGI_soffset";
1917 case DW_AT_PGI_lstride
: return "DW_AT_PGI_lstride";
1921 static char buffer
[100];
1923 snprintf (buffer
, sizeof (buffer
), _("Unknown AT value: %lx"),
1930 static unsigned char *
1931 read_and_display_attr (unsigned long attribute
,
1933 unsigned char * data
,
1934 dwarf_vma cu_offset
,
1935 dwarf_vma pointer_size
,
1936 dwarf_vma offset_size
,
1938 debug_info
* debug_info_p
,
1940 struct dwarf_section
* section
)
1943 printf (" %-18s:", get_AT_name (attribute
));
1944 data
= read_and_display_attr_value (attribute
, form
, data
, cu_offset
,
1945 pointer_size
, offset_size
,
1946 dwarf_version
, debug_info_p
,
1954 /* Process the contents of a .debug_info section. If do_loc is non-zero
1955 then we are scanning for location lists and we do not want to display
1956 anything to the user. If do_types is non-zero, we are processing
1957 a .debug_types section instead of a .debug_info section. */
1960 process_debug_info (struct dwarf_section
*section
,
1962 enum dwarf_section_display_enum abbrev_sec
,
1966 unsigned char *start
= section
->start
;
1967 unsigned char *end
= start
+ section
->size
;
1968 unsigned char *section_begin
;
1970 unsigned int num_units
= 0;
1972 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
1973 && num_debug_info_entries
== 0
1978 /* First scan the section to get the number of comp units. */
1979 for (section_begin
= start
, num_units
= 0; section_begin
< end
;
1982 /* Read the first 4 bytes. For a 32-bit DWARF section, this
1983 will be the length. For a 64-bit DWARF section, it'll be
1984 the escape code 0xffffffff followed by an 8 byte length. */
1985 length
= byte_get (section_begin
, 4);
1987 if (length
== 0xffffffff)
1989 length
= byte_get (section_begin
+ 4, 8);
1990 section_begin
+= length
+ 12;
1992 else if (length
>= 0xfffffff0 && length
< 0xffffffff)
1994 warn (_("Reserved length value (0x%s) found in section %s\n"),
1995 dwarf_vmatoa ("x", length
), section
->name
);
1999 section_begin
+= length
+ 4;
2001 /* Negative values are illegal, they may even cause infinite
2002 looping. This can happen if we can't accurately apply
2003 relocations to an object file. */
2004 if ((signed long) length
<= 0)
2006 warn (_("Corrupt unit length (0x%s) found in section %s\n"),
2007 dwarf_vmatoa ("x", length
), section
->name
);
2014 error (_("No comp units in %s section ?"), section
->name
);
2018 /* Then allocate an array to hold the information. */
2019 debug_information
= (debug_info
*) cmalloc (num_units
,
2020 sizeof (* debug_information
));
2021 if (debug_information
== NULL
)
2023 error (_("Not enough memory for a debug info array of %u entries"),
2031 printf (_("Contents of the %s section:\n\n"), section
->name
);
2033 load_debug_section (str
, file
);
2036 load_debug_section (abbrev_sec
, file
);
2037 if (debug_displays
[abbrev_sec
].section
.start
== NULL
)
2039 warn (_("Unable to locate %s section!\n"),
2040 debug_displays
[abbrev_sec
].section
.name
);
2044 for (section_begin
= start
, unit
= 0; start
< end
; unit
++)
2046 DWARF2_Internal_CompUnit compunit
;
2047 unsigned char *hdrptr
;
2048 unsigned char *tags
;
2050 dwarf_vma cu_offset
;
2052 int initial_length_size
;
2053 unsigned char signature
[8] = { 0 };
2054 dwarf_vma type_offset
= 0;
2058 compunit
.cu_length
= byte_get (hdrptr
, 4);
2061 if (compunit
.cu_length
== 0xffffffff)
2063 compunit
.cu_length
= byte_get (hdrptr
, 8);
2066 initial_length_size
= 12;
2071 initial_length_size
= 4;
2074 compunit
.cu_version
= byte_get (hdrptr
, 2);
2077 cu_offset
= start
- section_begin
;
2079 compunit
.cu_abbrev_offset
= byte_get (hdrptr
, offset_size
);
2080 hdrptr
+= offset_size
;
2082 compunit
.cu_pointer_size
= byte_get (hdrptr
, 1);
2089 for (i
= 0; i
< 8; i
++)
2091 signature
[i
] = byte_get (hdrptr
, 1);
2095 type_offset
= byte_get (hdrptr
, offset_size
);
2096 hdrptr
+= offset_size
;
2099 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
2100 && num_debug_info_entries
== 0
2103 debug_information
[unit
].cu_offset
= cu_offset
;
2104 debug_information
[unit
].pointer_size
2105 = compunit
.cu_pointer_size
;
2106 debug_information
[unit
].offset_size
= offset_size
;
2107 debug_information
[unit
].dwarf_version
= compunit
.cu_version
;
2108 debug_information
[unit
].base_address
= 0;
2109 debug_information
[unit
].loc_offsets
= NULL
;
2110 debug_information
[unit
].have_frame_base
= NULL
;
2111 debug_information
[unit
].max_loc_offsets
= 0;
2112 debug_information
[unit
].num_loc_offsets
= 0;
2113 debug_information
[unit
].range_lists
= NULL
;
2114 debug_information
[unit
].max_range_lists
= 0;
2115 debug_information
[unit
].num_range_lists
= 0;
2120 printf (_(" Compilation Unit @ offset 0x%s:\n"),
2121 dwarf_vmatoa ("x", cu_offset
));
2122 printf (_(" Length: 0x%s (%s)\n"),
2123 dwarf_vmatoa ("x", compunit
.cu_length
),
2124 offset_size
== 8 ? "64-bit" : "32-bit");
2125 printf (_(" Version: %d\n"), compunit
.cu_version
);
2126 printf (_(" Abbrev Offset: %s\n"),
2127 dwarf_vmatoa ("d", compunit
.cu_abbrev_offset
));
2128 printf (_(" Pointer Size: %d\n"), compunit
.cu_pointer_size
);
2132 printf (_(" Signature: "));
2133 for (i
= 0; i
< 8; i
++)
2134 printf ("%02x", signature
[i
]);
2136 printf (_(" Type Offset: 0x%s\n"),
2137 dwarf_vmatoa ("x", type_offset
));
2141 if (cu_offset
+ compunit
.cu_length
+ initial_length_size
2144 warn (_("Debug info is corrupted, length of CU at %s"
2145 " extends beyond end of section (length = %s)\n"),
2146 dwarf_vmatoa ("x", cu_offset
),
2147 dwarf_vmatoa ("x", compunit
.cu_length
));
2151 start
+= compunit
.cu_length
+ initial_length_size
;
2153 if (compunit
.cu_version
!= 2
2154 && compunit
.cu_version
!= 3
2155 && compunit
.cu_version
!= 4)
2157 warn (_("CU at offset %s contains corrupt or "
2158 "unsupported version number: %d.\n"),
2159 dwarf_vmatoa ("x", cu_offset
), compunit
.cu_version
);
2165 /* Process the abbrevs used by this compilation unit. DWARF
2166 sections under Mach-O have non-zero addresses. */
2167 if (compunit
.cu_abbrev_offset
>= debug_displays
[abbrev_sec
].section
.size
)
2168 warn (_("Debug info is corrupted, abbrev offset (%lx) is larger than abbrev section size (%lx)\n"),
2169 (unsigned long) compunit
.cu_abbrev_offset
,
2170 (unsigned long) debug_displays
[abbrev_sec
].section
.size
);
2172 process_abbrev_section
2173 ((unsigned char *) debug_displays
[abbrev_sec
].section
.start
2174 + compunit
.cu_abbrev_offset
,
2175 (unsigned char *) debug_displays
[abbrev_sec
].section
.start
2176 + debug_displays
[abbrev_sec
].section
.size
);
2179 while (tags
< start
)
2181 unsigned int bytes_read
;
2182 unsigned long abbrev_number
;
2183 unsigned long die_offset
;
2184 abbrev_entry
*entry
;
2187 die_offset
= tags
- section_begin
;
2189 abbrev_number
= read_leb128 (tags
, & bytes_read
, 0);
2192 /* A null DIE marks the end of a list of siblings or it may also be
2193 a section padding. */
2194 if (abbrev_number
== 0)
2196 /* Check if it can be a section padding for the last CU. */
2197 if (level
== 0 && start
== end
)
2201 for (chk
= tags
; chk
< start
; chk
++)
2211 static unsigned num_bogus_warns
= 0;
2213 if (num_bogus_warns
< 3)
2215 warn (_("Bogus end-of-siblings marker detected at offset %lx in .debug_info section\n"),
2218 if (num_bogus_warns
== 3)
2219 warn (_("Further warnings about bogus end-of-sibling markers suppressed\n"));
2226 printf (_(" <%d><%lx>: Abbrev Number: %lu"),
2227 level
, die_offset
, abbrev_number
);
2229 /* Scan through the abbreviation list until we reach the
2231 for (entry
= first_abbrev
;
2232 entry
&& entry
->entry
!= abbrev_number
;
2233 entry
= entry
->next
)
2243 warn (_("DIE at offset %lx refers to abbreviation number %lu which does not exist\n"),
2244 die_offset
, abbrev_number
);
2249 printf (" (%s)\n", get_TAG_name (entry
->tag
));
2254 need_base_address
= 0;
2256 case DW_TAG_compile_unit
:
2257 need_base_address
= 1;
2259 case DW_TAG_entry_point
:
2260 case DW_TAG_subprogram
:
2261 need_base_address
= 0;
2262 /* Assuming that there is no DW_AT_frame_base. */
2263 have_frame_base
= 0;
2267 for (attr
= entry
->first_attr
; attr
; attr
= attr
->next
)
2270 /* Show the offset from where the tag was extracted. */
2271 printf (" <%2lx>", (unsigned long)(tags
- section_begin
));
2273 tags
= read_and_display_attr (attr
->attribute
,
2276 compunit
.cu_pointer_size
,
2278 compunit
.cu_version
,
2279 debug_information
+ unit
,
2283 if (entry
->children
)
2288 /* Set num_debug_info_entries here so that it can be used to check if
2289 we need to process .debug_loc and .debug_ranges sections. */
2290 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
2291 && num_debug_info_entries
== 0
2293 num_debug_info_entries
= num_units
;
2301 /* Locate and scan the .debug_info section in the file and record the pointer
2302 sizes and offsets for the compilation units in it. Usually an executable
2303 will have just one pointer size, but this is not guaranteed, and so we try
2304 not to make any assumptions. Returns zero upon failure, or the number of
2305 compilation units upon success. */
2308 load_debug_info (void * file
)
2310 /* Reset the last pointer size so that we can issue correct error
2311 messages if we are displaying the contents of more than one section. */
2312 last_pointer_size
= 0;
2313 warned_about_missing_comp_units
= FALSE
;
2315 /* If we have already tried and failed to load the .debug_info
2316 section then do not bother to repear the task. */
2317 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
2320 /* If we already have the information there is nothing else to do. */
2321 if (num_debug_info_entries
> 0)
2322 return num_debug_info_entries
;
2324 if (load_debug_section (info
, file
)
2325 && process_debug_info (&debug_displays
[info
].section
, file
, abbrev
, 1, 0))
2326 return num_debug_info_entries
;
2328 num_debug_info_entries
= DEBUG_INFO_UNAVAILABLE
;
2333 display_debug_lines_raw (struct dwarf_section
*section
,
2334 unsigned char *data
,
2337 unsigned char *start
= section
->start
;
2339 printf (_("Raw dump of debug contents of section %s:\n\n"),
2344 DWARF2_Internal_LineInfo linfo
;
2345 unsigned char *standard_opcodes
;
2346 unsigned char *end_of_sequence
;
2347 unsigned char *hdrptr
;
2348 unsigned long hdroff
;
2349 int initial_length_size
;
2354 hdroff
= hdrptr
- start
;
2356 /* Check the length of the block. */
2357 linfo
.li_length
= byte_get (hdrptr
, 4);
2360 if (linfo
.li_length
== 0xffffffff)
2362 /* This section is 64-bit DWARF 3. */
2363 linfo
.li_length
= byte_get (hdrptr
, 8);
2366 initial_length_size
= 12;
2371 initial_length_size
= 4;
2374 if (linfo
.li_length
+ initial_length_size
> section
->size
)
2377 (_("The information in section %s appears to be corrupt - the section is too small\n"),
2382 /* Check its version number. */
2383 linfo
.li_version
= byte_get (hdrptr
, 2);
2385 if (linfo
.li_version
!= 2
2386 && linfo
.li_version
!= 3
2387 && linfo
.li_version
!= 4)
2389 warn (_("Only DWARF version 2, 3 and 4 line info is currently supported.\n"));
2393 linfo
.li_prologue_length
= byte_get (hdrptr
, offset_size
);
2394 hdrptr
+= offset_size
;
2395 linfo
.li_min_insn_length
= byte_get (hdrptr
, 1);
2397 if (linfo
.li_version
>= 4)
2399 linfo
.li_max_ops_per_insn
= byte_get (hdrptr
, 1);
2401 if (linfo
.li_max_ops_per_insn
== 0)
2403 warn (_("Invalid maximum operations per insn.\n"));
2408 linfo
.li_max_ops_per_insn
= 1;
2409 linfo
.li_default_is_stmt
= byte_get (hdrptr
, 1);
2411 linfo
.li_line_base
= byte_get (hdrptr
, 1);
2413 linfo
.li_line_range
= byte_get (hdrptr
, 1);
2415 linfo
.li_opcode_base
= byte_get (hdrptr
, 1);
2418 /* Sign extend the line base field. */
2419 linfo
.li_line_base
<<= 24;
2420 linfo
.li_line_base
>>= 24;
2422 printf (_(" Offset: 0x%lx\n"), hdroff
);
2423 printf (_(" Length: %ld\n"), (long) linfo
.li_length
);
2424 printf (_(" DWARF Version: %d\n"), linfo
.li_version
);
2425 printf (_(" Prologue Length: %d\n"), linfo
.li_prologue_length
);
2426 printf (_(" Minimum Instruction Length: %d\n"), linfo
.li_min_insn_length
);
2427 if (linfo
.li_version
>= 4)
2428 printf (_(" Maximum Ops per Instruction: %d\n"), linfo
.li_max_ops_per_insn
);
2429 printf (_(" Initial value of 'is_stmt': %d\n"), linfo
.li_default_is_stmt
);
2430 printf (_(" Line Base: %d\n"), linfo
.li_line_base
);
2431 printf (_(" Line Range: %d\n"), linfo
.li_line_range
);
2432 printf (_(" Opcode Base: %d\n"), linfo
.li_opcode_base
);
2434 end_of_sequence
= data
+ linfo
.li_length
+ initial_length_size
;
2436 reset_state_machine (linfo
.li_default_is_stmt
);
2438 /* Display the contents of the Opcodes table. */
2439 standard_opcodes
= hdrptr
;
2441 printf (_("\n Opcodes:\n"));
2443 for (i
= 1; i
< linfo
.li_opcode_base
; i
++)
2444 printf (_(" Opcode %d has %d args\n"), i
, standard_opcodes
[i
- 1]);
2446 /* Display the contents of the Directory table. */
2447 data
= standard_opcodes
+ linfo
.li_opcode_base
- 1;
2450 printf (_("\n The Directory Table is empty.\n"));
2453 printf (_("\n The Directory Table:\n"));
2457 printf (" %s\n", data
);
2459 data
+= strlen ((char *) data
) + 1;
2463 /* Skip the NUL at the end of the table. */
2466 /* Display the contents of the File Name table. */
2468 printf (_("\n The File Name Table is empty.\n"));
2471 printf (_("\n The File Name Table:\n"));
2472 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
2476 unsigned char *name
;
2477 unsigned int bytes_read
;
2479 printf (" %d\t", ++state_machine_regs
.last_file_entry
);
2482 data
+= strlen ((char *) data
) + 1;
2485 dwarf_vmatoa ("u", read_leb128 (data
, & bytes_read
, 0)));
2488 dwarf_vmatoa ("u", read_leb128 (data
, & bytes_read
, 0)));
2491 dwarf_vmatoa ("u", read_leb128 (data
, & bytes_read
, 0)));
2493 printf ("%s\n", name
);
2497 /* Skip the NUL at the end of the table. */
2500 /* Now display the statements. */
2501 printf (_("\n Line Number Statements:\n"));
2503 while (data
< end_of_sequence
)
2505 unsigned char op_code
;
2506 dwarf_signed_vma adv
;
2508 unsigned int bytes_read
;
2512 if (op_code
>= linfo
.li_opcode_base
)
2514 op_code
-= linfo
.li_opcode_base
;
2515 uladv
= (op_code
/ linfo
.li_line_range
);
2516 if (linfo
.li_max_ops_per_insn
== 1)
2518 uladv
*= linfo
.li_min_insn_length
;
2519 state_machine_regs
.address
+= uladv
;
2520 printf (_(" Special opcode %d: "
2521 "advance Address by %s to 0x%s"),
2522 op_code
, dwarf_vmatoa ("u", uladv
),
2523 dwarf_vmatoa ("x", state_machine_regs
.address
));
2527 state_machine_regs
.address
2528 += ((state_machine_regs
.op_index
+ uladv
)
2529 / linfo
.li_max_ops_per_insn
)
2530 * linfo
.li_min_insn_length
;
2531 state_machine_regs
.op_index
2532 = (state_machine_regs
.op_index
+ uladv
)
2533 % linfo
.li_max_ops_per_insn
;
2534 printf (_(" Special opcode %d: "
2535 "advance Address by %s to 0x%s[%d]"),
2536 op_code
, dwarf_vmatoa ("u", uladv
),
2537 dwarf_vmatoa ("x", state_machine_regs
.address
),
2538 state_machine_regs
.op_index
);
2540 adv
= (op_code
% linfo
.li_line_range
) + linfo
.li_line_base
;
2541 state_machine_regs
.line
+= adv
;
2542 printf (_(" and Line by %s to %d\n"),
2543 dwarf_vmatoa ("d", adv
), state_machine_regs
.line
);
2545 else switch (op_code
)
2547 case DW_LNS_extended_op
:
2548 data
+= process_extended_line_op (data
, linfo
.li_default_is_stmt
);
2552 printf (_(" Copy\n"));
2555 case DW_LNS_advance_pc
:
2556 uladv
= read_leb128 (data
, & bytes_read
, 0);
2558 if (linfo
.li_max_ops_per_insn
== 1)
2560 uladv
*= linfo
.li_min_insn_length
;
2561 state_machine_regs
.address
+= uladv
;
2562 printf (_(" Advance PC by %s to 0x%s\n"),
2563 dwarf_vmatoa ("u", uladv
),
2564 dwarf_vmatoa ("x", state_machine_regs
.address
));
2568 state_machine_regs
.address
2569 += ((state_machine_regs
.op_index
+ uladv
)
2570 / linfo
.li_max_ops_per_insn
)
2571 * linfo
.li_min_insn_length
;
2572 state_machine_regs
.op_index
2573 = (state_machine_regs
.op_index
+ uladv
)
2574 % linfo
.li_max_ops_per_insn
;
2575 printf (_(" Advance PC by %s to 0x%s[%d]\n"),
2576 dwarf_vmatoa ("u", uladv
),
2577 dwarf_vmatoa ("x", state_machine_regs
.address
),
2578 state_machine_regs
.op_index
);
2582 case DW_LNS_advance_line
:
2583 adv
= read_sleb128 (data
, & bytes_read
);
2585 state_machine_regs
.line
+= adv
;
2586 printf (_(" Advance Line by %s to %d\n"),
2587 dwarf_vmatoa ("d", adv
),
2588 state_machine_regs
.line
);
2591 case DW_LNS_set_file
:
2592 adv
= read_leb128 (data
, & bytes_read
, 0);
2594 printf (_(" Set File Name to entry %s in the File Name Table\n"),
2595 dwarf_vmatoa ("d", adv
));
2596 state_machine_regs
.file
= adv
;
2599 case DW_LNS_set_column
:
2600 uladv
= read_leb128 (data
, & bytes_read
, 0);
2602 printf (_(" Set column to %s\n"),
2603 dwarf_vmatoa ("u", uladv
));
2604 state_machine_regs
.column
= uladv
;
2607 case DW_LNS_negate_stmt
:
2608 adv
= state_machine_regs
.is_stmt
;
2610 printf (_(" Set is_stmt to %s\n"), dwarf_vmatoa ("d", adv
));
2611 state_machine_regs
.is_stmt
= adv
;
2614 case DW_LNS_set_basic_block
:
2615 printf (_(" Set basic block\n"));
2616 state_machine_regs
.basic_block
= 1;
2619 case DW_LNS_const_add_pc
:
2620 uladv
= ((255 - linfo
.li_opcode_base
) / linfo
.li_line_range
);
2621 if (linfo
.li_max_ops_per_insn
)
2623 uladv
*= linfo
.li_min_insn_length
;
2624 state_machine_regs
.address
+= uladv
;
2625 printf (_(" Advance PC by constant %s to 0x%s\n"),
2626 dwarf_vmatoa ("u", uladv
),
2627 dwarf_vmatoa ("x", state_machine_regs
.address
));
2631 state_machine_regs
.address
2632 += ((state_machine_regs
.op_index
+ uladv
)
2633 / linfo
.li_max_ops_per_insn
)
2634 * linfo
.li_min_insn_length
;
2635 state_machine_regs
.op_index
2636 = (state_machine_regs
.op_index
+ uladv
)
2637 % linfo
.li_max_ops_per_insn
;
2638 printf (_(" Advance PC by constant %s to 0x%s[%d]\n"),
2639 dwarf_vmatoa ("u", uladv
),
2640 dwarf_vmatoa ("x", state_machine_regs
.address
),
2641 state_machine_regs
.op_index
);
2645 case DW_LNS_fixed_advance_pc
:
2646 uladv
= byte_get (data
, 2);
2648 state_machine_regs
.address
+= uladv
;
2649 state_machine_regs
.op_index
= 0;
2650 printf (_(" Advance PC by fixed size amount %s to 0x%s\n"),
2651 dwarf_vmatoa ("u", uladv
),
2652 dwarf_vmatoa ("x", state_machine_regs
.address
));
2655 case DW_LNS_set_prologue_end
:
2656 printf (_(" Set prologue_end to true\n"));
2659 case DW_LNS_set_epilogue_begin
:
2660 printf (_(" Set epilogue_begin to true\n"));
2663 case DW_LNS_set_isa
:
2664 uladv
= read_leb128 (data
, & bytes_read
, 0);
2666 printf (_(" Set ISA to %s\n"), dwarf_vmatoa ("u", uladv
));
2670 printf (_(" Unknown opcode %d with operands: "), op_code
);
2672 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
2674 printf ("0x%s%s", dwarf_vmatoa ("x", read_leb128 (data
,
2676 i
== 1 ? "" : ", ");
2691 unsigned char *name
;
2692 unsigned int directory_index
;
2693 unsigned int modification_date
;
2694 unsigned int length
;
2697 /* Output a decoded representation of the .debug_line section. */
2700 display_debug_lines_decoded (struct dwarf_section
*section
,
2701 unsigned char *data
,
2704 printf (_("Decoded dump of debug contents of section %s:\n\n"),
2709 /* This loop amounts to one iteration per compilation unit. */
2710 DWARF2_Internal_LineInfo linfo
;
2711 unsigned char *standard_opcodes
;
2712 unsigned char *end_of_sequence
;
2713 unsigned char *hdrptr
;
2714 int initial_length_size
;
2717 File_Entry
*file_table
= NULL
;
2718 unsigned char **directory_table
= NULL
;
2722 /* Extract information from the Line Number Program Header.
2723 (section 6.2.4 in the Dwarf3 doc). */
2725 /* Get the length of this CU's line number information block. */
2726 linfo
.li_length
= byte_get (hdrptr
, 4);
2729 if (linfo
.li_length
== 0xffffffff)
2731 /* This section is 64-bit DWARF 3. */
2732 linfo
.li_length
= byte_get (hdrptr
, 8);
2735 initial_length_size
= 12;
2740 initial_length_size
= 4;
2743 if (linfo
.li_length
+ initial_length_size
> section
->size
)
2745 warn (_("The line info appears to be corrupt - "
2746 "the section is too small\n"));
2750 /* Get this CU's Line Number Block version number. */
2751 linfo
.li_version
= byte_get (hdrptr
, 2);
2753 if (linfo
.li_version
!= 2
2754 && linfo
.li_version
!= 3
2755 && linfo
.li_version
!= 4)
2757 warn (_("Only DWARF version 2, 3 and 4 line info is currently "
2762 linfo
.li_prologue_length
= byte_get (hdrptr
, offset_size
);
2763 hdrptr
+= offset_size
;
2764 linfo
.li_min_insn_length
= byte_get (hdrptr
, 1);
2766 if (linfo
.li_version
>= 4)
2768 linfo
.li_max_ops_per_insn
= byte_get (hdrptr
, 1);
2770 if (linfo
.li_max_ops_per_insn
== 0)
2772 warn (_("Invalid maximum operations per insn.\n"));
2777 linfo
.li_max_ops_per_insn
= 1;
2778 linfo
.li_default_is_stmt
= byte_get (hdrptr
, 1);
2780 linfo
.li_line_base
= byte_get (hdrptr
, 1);
2782 linfo
.li_line_range
= byte_get (hdrptr
, 1);
2784 linfo
.li_opcode_base
= byte_get (hdrptr
, 1);
2787 /* Sign extend the line base field. */
2788 linfo
.li_line_base
<<= 24;
2789 linfo
.li_line_base
>>= 24;
2791 /* Find the end of this CU's Line Number Information Block. */
2792 end_of_sequence
= data
+ linfo
.li_length
+ initial_length_size
;
2794 reset_state_machine (linfo
.li_default_is_stmt
);
2796 /* Save a pointer to the contents of the Opcodes table. */
2797 standard_opcodes
= hdrptr
;
2799 /* Traverse the Directory table just to count entries. */
2800 data
= standard_opcodes
+ linfo
.li_opcode_base
- 1;
2803 unsigned int n_directories
= 0;
2804 unsigned char *ptr_directory_table
= data
;
2808 data
+= strlen ((char *) data
) + 1;
2812 /* Go through the directory table again to save the directories. */
2813 directory_table
= (unsigned char **)
2814 xmalloc (n_directories
* sizeof (unsigned char *));
2817 while (*ptr_directory_table
!= 0)
2819 directory_table
[i
] = ptr_directory_table
;
2820 ptr_directory_table
+= strlen ((char *) ptr_directory_table
) + 1;
2824 /* Skip the NUL at the end of the table. */
2827 /* Traverse the File Name table just to count the entries. */
2830 unsigned int n_files
= 0;
2831 unsigned char *ptr_file_name_table
= data
;
2835 unsigned int bytes_read
;
2837 /* Skip Name, directory index, last modification time and length
2839 data
+= strlen ((char *) data
) + 1;
2840 read_leb128 (data
, & bytes_read
, 0);
2842 read_leb128 (data
, & bytes_read
, 0);
2844 read_leb128 (data
, & bytes_read
, 0);
2850 /* Go through the file table again to save the strings. */
2851 file_table
= (File_Entry
*) xmalloc (n_files
* sizeof (File_Entry
));
2854 while (*ptr_file_name_table
!= 0)
2856 unsigned int bytes_read
;
2858 file_table
[i
].name
= ptr_file_name_table
;
2859 ptr_file_name_table
+= strlen ((char *) ptr_file_name_table
) + 1;
2861 /* We are not interested in directory, time or size. */
2862 file_table
[i
].directory_index
= read_leb128 (ptr_file_name_table
,
2864 ptr_file_name_table
+= bytes_read
;
2865 file_table
[i
].modification_date
= read_leb128 (ptr_file_name_table
,
2867 ptr_file_name_table
+= bytes_read
;
2868 file_table
[i
].length
= read_leb128 (ptr_file_name_table
, & bytes_read
, 0);
2869 ptr_file_name_table
+= bytes_read
;
2874 /* Print the Compilation Unit's name and a header. */
2875 if (directory_table
== NULL
)
2877 printf (_("CU: %s:\n"), file_table
[0].name
);
2878 printf (_("File name Line number Starting address\n"));
2882 if (do_wide
|| strlen ((char *) directory_table
[0]) < 76)
2883 printf (_("CU: %s/%s:\n"), directory_table
[0],
2884 file_table
[0].name
);
2886 printf ("%s:\n", file_table
[0].name
);
2888 printf (_("File name Line number Starting address\n"));
2892 /* Skip the NUL at the end of the table. */
2895 /* This loop iterates through the Dwarf Line Number Program. */
2896 while (data
< end_of_sequence
)
2898 unsigned char op_code
;
2900 unsigned long int uladv
;
2901 unsigned int bytes_read
;
2902 int is_special_opcode
= 0;
2906 if (op_code
>= linfo
.li_opcode_base
)
2908 op_code
-= linfo
.li_opcode_base
;
2909 uladv
= (op_code
/ linfo
.li_line_range
);
2910 if (linfo
.li_max_ops_per_insn
== 1)
2912 uladv
*= linfo
.li_min_insn_length
;
2913 state_machine_regs
.address
+= uladv
;
2917 state_machine_regs
.address
2918 += ((state_machine_regs
.op_index
+ uladv
)
2919 / linfo
.li_max_ops_per_insn
)
2920 * linfo
.li_min_insn_length
;
2921 state_machine_regs
.op_index
2922 = (state_machine_regs
.op_index
+ uladv
)
2923 % linfo
.li_max_ops_per_insn
;
2926 adv
= (op_code
% linfo
.li_line_range
) + linfo
.li_line_base
;
2927 state_machine_regs
.line
+= adv
;
2928 is_special_opcode
= 1;
2930 else switch (op_code
)
2932 case DW_LNS_extended_op
:
2934 unsigned int ext_op_code_len
;
2935 unsigned char ext_op_code
;
2936 unsigned char *op_code_data
= data
;
2938 ext_op_code_len
= read_leb128 (op_code_data
, &bytes_read
, 0);
2939 op_code_data
+= bytes_read
;
2941 if (ext_op_code_len
== 0)
2943 warn (_("badly formed extended line op encountered!\n"));
2946 ext_op_code_len
+= bytes_read
;
2947 ext_op_code
= *op_code_data
++;
2949 switch (ext_op_code
)
2951 case DW_LNE_end_sequence
:
2952 reset_state_machine (linfo
.li_default_is_stmt
);
2954 case DW_LNE_set_address
:
2955 state_machine_regs
.address
=
2956 byte_get (op_code_data
, ext_op_code_len
- bytes_read
- 1);
2957 state_machine_regs
.op_index
= 0;
2959 case DW_LNE_define_file
:
2961 unsigned int dir_index
= 0;
2963 ++state_machine_regs
.last_file_entry
;
2964 op_code_data
+= strlen ((char *) op_code_data
) + 1;
2965 dir_index
= read_leb128 (op_code_data
, & bytes_read
, 0);
2966 op_code_data
+= bytes_read
;
2967 read_leb128 (op_code_data
, & bytes_read
, 0);
2968 op_code_data
+= bytes_read
;
2969 read_leb128 (op_code_data
, & bytes_read
, 0);
2971 printf ("%s:\n", directory_table
[dir_index
]);
2975 printf (_("UNKNOWN: length %d\n"), ext_op_code_len
- bytes_read
);
2978 data
+= ext_op_code_len
;
2984 case DW_LNS_advance_pc
:
2985 uladv
= read_leb128 (data
, & bytes_read
, 0);
2987 if (linfo
.li_max_ops_per_insn
== 1)
2989 uladv
*= linfo
.li_min_insn_length
;
2990 state_machine_regs
.address
+= uladv
;
2994 state_machine_regs
.address
2995 += ((state_machine_regs
.op_index
+ uladv
)
2996 / linfo
.li_max_ops_per_insn
)
2997 * linfo
.li_min_insn_length
;
2998 state_machine_regs
.op_index
2999 = (state_machine_regs
.op_index
+ uladv
)
3000 % linfo
.li_max_ops_per_insn
;
3004 case DW_LNS_advance_line
:
3005 adv
= read_sleb128 (data
, & bytes_read
);
3007 state_machine_regs
.line
+= adv
;
3010 case DW_LNS_set_file
:
3011 adv
= read_leb128 (data
, & bytes_read
, 0);
3013 state_machine_regs
.file
= adv
;
3014 if (file_table
[state_machine_regs
.file
- 1].directory_index
== 0)
3016 /* If directory index is 0, that means current directory. */
3017 printf ("\n./%s:[++]\n",
3018 file_table
[state_machine_regs
.file
- 1].name
);
3022 /* The directory index starts counting at 1. */
3023 printf ("\n%s/%s:\n",
3024 directory_table
[file_table
[state_machine_regs
.file
- 1].directory_index
- 1],
3025 file_table
[state_machine_regs
.file
- 1].name
);
3029 case DW_LNS_set_column
:
3030 uladv
= read_leb128 (data
, & bytes_read
, 0);
3032 state_machine_regs
.column
= uladv
;
3035 case DW_LNS_negate_stmt
:
3036 adv
= state_machine_regs
.is_stmt
;
3038 state_machine_regs
.is_stmt
= adv
;
3041 case DW_LNS_set_basic_block
:
3042 state_machine_regs
.basic_block
= 1;
3045 case DW_LNS_const_add_pc
:
3046 uladv
= ((255 - linfo
.li_opcode_base
) / linfo
.li_line_range
);
3047 if (linfo
.li_max_ops_per_insn
== 1)
3049 uladv
*= linfo
.li_min_insn_length
;
3050 state_machine_regs
.address
+= uladv
;
3054 state_machine_regs
.address
3055 += ((state_machine_regs
.op_index
+ uladv
)
3056 / linfo
.li_max_ops_per_insn
)
3057 * linfo
.li_min_insn_length
;
3058 state_machine_regs
.op_index
3059 = (state_machine_regs
.op_index
+ uladv
)
3060 % linfo
.li_max_ops_per_insn
;
3064 case DW_LNS_fixed_advance_pc
:
3065 uladv
= byte_get (data
, 2);
3067 state_machine_regs
.address
+= uladv
;
3068 state_machine_regs
.op_index
= 0;
3071 case DW_LNS_set_prologue_end
:
3074 case DW_LNS_set_epilogue_begin
:
3077 case DW_LNS_set_isa
:
3078 uladv
= read_leb128 (data
, & bytes_read
, 0);
3080 printf (_(" Set ISA to %lu\n"), uladv
);
3084 printf (_(" Unknown opcode %d with operands: "), op_code
);
3086 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
3088 printf ("0x%s%s", dwarf_vmatoa ("x", read_leb128 (data
,
3090 i
== 1 ? "" : ", ");
3097 /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row
3098 to the DWARF address/line matrix. */
3099 if ((is_special_opcode
) || (op_code
== DW_LNE_end_sequence
)
3100 || (op_code
== DW_LNS_copy
))
3102 const unsigned int MAX_FILENAME_LENGTH
= 35;
3103 char *fileName
= (char *)file_table
[state_machine_regs
.file
- 1].name
;
3104 char *newFileName
= NULL
;
3105 size_t fileNameLength
= strlen (fileName
);
3107 if ((fileNameLength
> MAX_FILENAME_LENGTH
) && (!do_wide
))
3109 newFileName
= (char *) xmalloc (MAX_FILENAME_LENGTH
+ 1);
3110 /* Truncate file name */
3111 strncpy (newFileName
,
3112 fileName
+ fileNameLength
- MAX_FILENAME_LENGTH
,
3113 MAX_FILENAME_LENGTH
+ 1);
3117 newFileName
= (char *) xmalloc (fileNameLength
+ 1);
3118 strncpy (newFileName
, fileName
, fileNameLength
+ 1);
3121 if (!do_wide
|| (fileNameLength
<= MAX_FILENAME_LENGTH
))
3123 if (linfo
.li_max_ops_per_insn
== 1)
3124 printf ("%-35s %11d %#18" DWARF_VMA_FMT
"x\n",
3125 newFileName
, state_machine_regs
.line
,
3126 state_machine_regs
.address
);
3128 printf ("%-35s %11d %#18" DWARF_VMA_FMT
"x[%d]\n",
3129 newFileName
, state_machine_regs
.line
,
3130 state_machine_regs
.address
,
3131 state_machine_regs
.op_index
);
3135 if (linfo
.li_max_ops_per_insn
== 1)
3136 printf ("%s %11d %#18" DWARF_VMA_FMT
"x\n",
3137 newFileName
, state_machine_regs
.line
,
3138 state_machine_regs
.address
);
3140 printf ("%s %11d %#18" DWARF_VMA_FMT
"x[%d]\n",
3141 newFileName
, state_machine_regs
.line
,
3142 state_machine_regs
.address
,
3143 state_machine_regs
.op_index
);
3146 if (op_code
== DW_LNE_end_sequence
)
3154 free (directory_table
);
3155 directory_table
= NULL
;
3163 display_debug_lines (struct dwarf_section
*section
, void *file ATTRIBUTE_UNUSED
)
3165 unsigned char *data
= section
->start
;
3166 unsigned char *end
= data
+ section
->size
;
3168 int retValDecoded
= 1;
3170 if (do_debug_lines
== 0)
3171 do_debug_lines
|= FLAG_DEBUG_LINES_RAW
;
3173 if (do_debug_lines
& FLAG_DEBUG_LINES_RAW
)
3174 retValRaw
= display_debug_lines_raw (section
, data
, end
);
3176 if (do_debug_lines
& FLAG_DEBUG_LINES_DECODED
)
3177 retValDecoded
= display_debug_lines_decoded (section
, data
, end
);
3179 if (!retValRaw
|| !retValDecoded
)
3186 find_debug_info_for_offset (unsigned long offset
)
3190 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
3193 for (i
= 0; i
< num_debug_info_entries
; i
++)
3194 if (debug_information
[i
].cu_offset
== offset
)
3195 return debug_information
+ i
;
3201 display_debug_pubnames (struct dwarf_section
*section
,
3202 void *file ATTRIBUTE_UNUSED
)
3204 DWARF2_Internal_PubNames names
;
3205 unsigned char *start
= section
->start
;
3206 unsigned char *end
= start
+ section
->size
;
3208 /* It does not matter if this load fails,
3209 we test for that later on. */
3210 load_debug_info (file
);
3212 printf (_("Contents of the %s section:\n\n"), section
->name
);
3216 unsigned char *data
;
3217 unsigned long offset
;
3218 int offset_size
, initial_length_size
;
3222 names
.pn_length
= byte_get (data
, 4);
3224 if (names
.pn_length
== 0xffffffff)
3226 names
.pn_length
= byte_get (data
, 8);
3229 initial_length_size
= 12;
3234 initial_length_size
= 4;
3237 names
.pn_version
= byte_get (data
, 2);
3240 names
.pn_offset
= byte_get (data
, offset_size
);
3241 data
+= offset_size
;
3243 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
3244 && num_debug_info_entries
> 0
3245 && find_debug_info_for_offset (names
.pn_offset
) == NULL
)
3246 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
3247 (unsigned long) names
.pn_offset
, section
->name
);
3249 names
.pn_size
= byte_get (data
, offset_size
);
3250 data
+= offset_size
;
3252 start
+= names
.pn_length
+ initial_length_size
;
3254 if (names
.pn_version
!= 2 && names
.pn_version
!= 3)
3256 static int warned
= 0;
3260 warn (_("Only DWARF 2 and 3 pubnames are currently supported\n"));
3267 printf (_(" Length: %ld\n"),
3268 (long) names
.pn_length
);
3269 printf (_(" Version: %d\n"),
3271 printf (_(" Offset into .debug_info section: 0x%lx\n"),
3272 (unsigned long) names
.pn_offset
);
3273 printf (_(" Size of area in .debug_info section: %ld\n"),
3274 (long) names
.pn_size
);
3276 printf (_("\n Offset\tName\n"));
3280 offset
= byte_get (data
, offset_size
);
3284 data
+= offset_size
;
3285 printf (" %-6lx\t%s\n", offset
, data
);
3286 data
+= strlen ((char *) data
) + 1;
3289 while (offset
!= 0);
3297 display_debug_macinfo (struct dwarf_section
*section
,
3298 void *file ATTRIBUTE_UNUSED
)
3300 unsigned char *start
= section
->start
;
3301 unsigned char *end
= start
+ section
->size
;
3302 unsigned char *curr
= start
;
3303 unsigned int bytes_read
;
3304 enum dwarf_macinfo_record_type op
;
3306 printf (_("Contents of the %s section:\n\n"), section
->name
);
3310 unsigned int lineno
;
3313 op
= (enum dwarf_macinfo_record_type
) *curr
;
3318 case DW_MACINFO_start_file
:
3320 unsigned int filenum
;
3322 lineno
= read_leb128 (curr
, & bytes_read
, 0);
3324 filenum
= read_leb128 (curr
, & bytes_read
, 0);
3327 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"),
3332 case DW_MACINFO_end_file
:
3333 printf (_(" DW_MACINFO_end_file\n"));
3336 case DW_MACINFO_define
:
3337 lineno
= read_leb128 (curr
, & bytes_read
, 0);
3339 string
= (char *) curr
;
3340 curr
+= strlen (string
) + 1;
3341 printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"),
3345 case DW_MACINFO_undef
:
3346 lineno
= read_leb128 (curr
, & bytes_read
, 0);
3348 string
= (char *) curr
;
3349 curr
+= strlen (string
) + 1;
3350 printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"),
3354 case DW_MACINFO_vendor_ext
:
3356 unsigned int constant
;
3358 constant
= read_leb128 (curr
, & bytes_read
, 0);
3360 string
= (char *) curr
;
3361 curr
+= strlen (string
) + 1;
3362 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"),
3373 display_debug_abbrev (struct dwarf_section
*section
,
3374 void *file ATTRIBUTE_UNUSED
)
3376 abbrev_entry
*entry
;
3377 unsigned char *start
= section
->start
;
3378 unsigned char *end
= start
+ section
->size
;
3380 printf (_("Contents of the %s section:\n\n"), section
->name
);
3386 start
= process_abbrev_section (start
, end
);
3388 if (first_abbrev
== NULL
)
3391 printf (_(" Number TAG\n"));
3393 for (entry
= first_abbrev
; entry
; entry
= entry
->next
)
3397 printf (" %ld %s [%s]\n",
3399 get_TAG_name (entry
->tag
),
3400 entry
->children
? _("has children") : _("no children"));
3402 for (attr
= entry
->first_attr
; attr
; attr
= attr
->next
)
3403 printf (" %-18s %s\n",
3404 get_AT_name (attr
->attribute
),
3405 get_FORM_name (attr
->form
));
3416 display_debug_loc (struct dwarf_section
*section
, void *file
)
3418 unsigned char *start
= section
->start
;
3419 unsigned char *section_end
;
3420 unsigned long bytes
;
3421 unsigned char *section_begin
= start
;
3422 unsigned int num_loc_list
= 0;
3423 unsigned long last_offset
= 0;
3424 unsigned int first
= 0;
3427 int seen_first_offset
= 0;
3428 int use_debug_info
= 1;
3429 unsigned char *next
;
3431 bytes
= section
->size
;
3432 section_end
= start
+ bytes
;
3436 printf (_("\nThe %s section is empty.\n"), section
->name
);
3440 if (load_debug_info (file
) == 0)
3442 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
3447 /* Check the order of location list in .debug_info section. If
3448 offsets of location lists are in the ascending order, we can
3449 use `debug_information' directly. */
3450 for (i
= 0; i
< num_debug_info_entries
; i
++)
3454 num
= debug_information
[i
].num_loc_offsets
;
3455 num_loc_list
+= num
;
3457 /* Check if we can use `debug_information' directly. */
3458 if (use_debug_info
&& num
!= 0)
3460 if (!seen_first_offset
)
3462 /* This is the first location list. */
3463 last_offset
= debug_information
[i
].loc_offsets
[0];
3465 seen_first_offset
= 1;
3471 for (; j
< num
; j
++)
3474 debug_information
[i
].loc_offsets
[j
])
3479 last_offset
= debug_information
[i
].loc_offsets
[j
];
3484 if (!use_debug_info
)
3485 /* FIXME: Should we handle this case? */
3486 error (_("Location lists in .debug_info section aren't in ascending order!\n"));
3488 if (!seen_first_offset
)
3489 error (_("No location lists in .debug_info section!\n"));
3491 /* DWARF sections under Mach-O have non-zero addresses. */
3492 if (debug_information
[first
].num_loc_offsets
> 0
3493 && debug_information
[first
].loc_offsets
[0] != section
->address
)
3494 warn (_("Location lists in %s section start at 0x%s\n"),
3496 dwarf_vmatoa ("x", debug_information
[first
].loc_offsets
[0]));
3498 printf (_("Contents of the %s section:\n\n"), section
->name
);
3499 printf (_(" Offset Begin End Expression\n"));
3501 seen_first_offset
= 0;
3502 for (i
= first
; i
< num_debug_info_entries
; i
++)
3506 unsigned short length
;
3507 unsigned long offset
;
3508 unsigned int pointer_size
;
3509 unsigned int offset_size
;
3511 unsigned long cu_offset
;
3512 unsigned long base_address
;
3513 int need_frame_base
;
3516 pointer_size
= debug_information
[i
].pointer_size
;
3517 cu_offset
= debug_information
[i
].cu_offset
;
3518 offset_size
= debug_information
[i
].offset_size
;
3519 dwarf_version
= debug_information
[i
].dwarf_version
;
3521 for (j
= 0; j
< debug_information
[i
].num_loc_offsets
; j
++)
3523 has_frame_base
= debug_information
[i
].have_frame_base
[j
];
3524 /* DWARF sections under Mach-O have non-zero addresses. */
3525 offset
= debug_information
[i
].loc_offsets
[j
] - section
->address
;
3526 next
= section_begin
+ offset
;
3527 base_address
= debug_information
[i
].base_address
;
3529 if (!seen_first_offset
)
3530 seen_first_offset
= 1;
3534 warn (_("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n"),
3535 (unsigned long) (start
- section_begin
),
3536 (unsigned long) (next
- section_begin
));
3537 else if (start
> next
)
3538 warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n"),
3539 (unsigned long) (start
- section_begin
),
3540 (unsigned long) (next
- section_begin
));
3544 if (offset
>= bytes
)
3546 warn (_("Offset 0x%lx is bigger than .debug_loc section size.\n"),
3553 if (start
+ 2 * pointer_size
> section_end
)
3555 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
3560 /* Note: we use sign extension here in order to be sure that
3561 we can detect the -1 escape value. Sign extension into the
3562 top 32 bits of a 32-bit address will not affect the values
3563 that we display since we always show hex values, and always
3564 the bottom 32-bits. */
3565 begin
= byte_get_signed (start
, pointer_size
);
3566 start
+= pointer_size
;
3567 end
= byte_get_signed (start
, pointer_size
);
3568 start
+= pointer_size
;
3570 printf (" %8.8lx ", offset
);
3572 if (begin
== 0 && end
== 0)
3574 printf (_("<End of list>\n"));
3578 /* Check base address specifiers. */
3579 if (begin
== (dwarf_vma
) -1 && end
!= (dwarf_vma
) -1)
3582 print_dwarf_vma (begin
, pointer_size
);
3583 print_dwarf_vma (end
, pointer_size
);
3584 printf (_("(base address)\n"));
3588 if (start
+ 2 > section_end
)
3590 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
3595 length
= byte_get (start
, 2);
3598 if (start
+ length
> section_end
)
3600 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
3605 print_dwarf_vma (begin
+ base_address
, pointer_size
);
3606 print_dwarf_vma (end
+ base_address
, pointer_size
);
3609 need_frame_base
= decode_location_expression (start
,
3614 cu_offset
, section
);
3617 if (need_frame_base
&& !has_frame_base
)
3618 printf (_(" [without DW_AT_frame_base]"));
3621 fputs (_(" (start == end)"), stdout
);
3622 else if (begin
> end
)
3623 fputs (_(" (start > end)"), stdout
);
3632 if (start
< section_end
)
3633 warn (_("There are %ld unused bytes at the end of section %s\n"),
3634 (long) (section_end
- start
), section
->name
);
3640 display_debug_str (struct dwarf_section
*section
,
3641 void *file ATTRIBUTE_UNUSED
)
3643 unsigned char *start
= section
->start
;
3644 unsigned long bytes
= section
->size
;
3645 dwarf_vma addr
= section
->address
;
3649 printf (_("\nThe %s section is empty.\n"), section
->name
);
3653 printf (_("Contents of the %s section:\n\n"), section
->name
);
3661 lbytes
= (bytes
> 16 ? 16 : bytes
);
3663 printf (" 0x%8.8lx ", (unsigned long) addr
);
3665 for (j
= 0; j
< 16; j
++)
3668 printf ("%2.2x", start
[j
]);
3676 for (j
= 0; j
< lbytes
; j
++)
3679 if (k
>= ' ' && k
< 0x80)
3698 display_debug_info (struct dwarf_section
*section
, void *file
)
3700 return process_debug_info (section
, file
, abbrev
, 0, 0);
3704 display_debug_types (struct dwarf_section
*section
, void *file
)
3706 return process_debug_info (section
, file
, abbrev
, 0, 1);
3710 display_trace_info (struct dwarf_section
*section
, void *file
)
3712 return process_debug_info (section
, file
, trace_abbrev
, 0, 0);
3716 display_debug_aranges (struct dwarf_section
*section
,
3717 void *file ATTRIBUTE_UNUSED
)
3719 unsigned char *start
= section
->start
;
3720 unsigned char *end
= start
+ section
->size
;
3722 printf (_("Contents of the %s section:\n\n"), section
->name
);
3724 /* It does not matter if this load fails,
3725 we test for that later on. */
3726 load_debug_info (file
);
3730 unsigned char *hdrptr
;
3731 DWARF2_Internal_ARange arange
;
3732 unsigned char *addr_ranges
;
3735 unsigned char address_size
;
3738 int initial_length_size
;
3742 arange
.ar_length
= byte_get (hdrptr
, 4);
3745 if (arange
.ar_length
== 0xffffffff)
3747 arange
.ar_length
= byte_get (hdrptr
, 8);
3750 initial_length_size
= 12;
3755 initial_length_size
= 4;
3758 arange
.ar_version
= byte_get (hdrptr
, 2);
3761 arange
.ar_info_offset
= byte_get (hdrptr
, offset_size
);
3762 hdrptr
+= offset_size
;
3764 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
3765 && num_debug_info_entries
> 0
3766 && find_debug_info_for_offset (arange
.ar_info_offset
) == NULL
)
3767 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
3768 (unsigned long) arange
.ar_info_offset
, section
->name
);
3770 arange
.ar_pointer_size
= byte_get (hdrptr
, 1);
3773 arange
.ar_segment_size
= byte_get (hdrptr
, 1);
3776 if (arange
.ar_version
!= 2 && arange
.ar_version
!= 3)
3778 warn (_("Only DWARF 2 and 3 aranges are currently supported.\n"));
3782 printf (_(" Length: %ld\n"),
3783 (long) arange
.ar_length
);
3784 printf (_(" Version: %d\n"), arange
.ar_version
);
3785 printf (_(" Offset into .debug_info: 0x%lx\n"),
3786 (unsigned long) arange
.ar_info_offset
);
3787 printf (_(" Pointer Size: %d\n"), arange
.ar_pointer_size
);
3788 printf (_(" Segment Size: %d\n"), arange
.ar_segment_size
);
3790 address_size
= arange
.ar_pointer_size
+ arange
.ar_segment_size
;
3792 /* The DWARF spec does not require that the address size be a power
3793 of two, but we do. This will have to change if we ever encounter
3794 an uneven architecture. */
3795 if ((address_size
& (address_size
- 1)) != 0)
3797 warn (_("Pointer size + Segment size is not a power of two.\n"));
3801 if (address_size
> 4)
3802 printf (_("\n Address Length\n"));
3804 printf (_("\n Address Length\n"));
3806 addr_ranges
= hdrptr
;
3808 /* Must pad to an alignment boundary that is twice the address size. */
3809 excess
= (hdrptr
- start
) % (2 * address_size
);
3811 addr_ranges
+= (2 * address_size
) - excess
;
3813 start
+= arange
.ar_length
+ initial_length_size
;
3815 while (addr_ranges
+ 2 * address_size
<= start
)
3817 address
= byte_get (addr_ranges
, address_size
);
3819 addr_ranges
+= address_size
;
3821 length
= byte_get (addr_ranges
, address_size
);
3823 addr_ranges
+= address_size
;
3826 print_dwarf_vma (address
, address_size
);
3827 print_dwarf_vma (length
, address_size
);
3837 /* Each debug_information[x].range_lists[y] gets this representation for
3838 sorting purposes. */
3842 /* The debug_information[x].range_lists[y] value. */
3843 unsigned long ranges_offset
;
3845 /* Original debug_information to find parameters of the data. */
3846 debug_info
*debug_info_p
;
3849 /* Sort struct range_entry in ascending order of its RANGES_OFFSET. */
3852 range_entry_compar (const void *ap
, const void *bp
)
3854 const struct range_entry
*a_re
= (const struct range_entry
*) ap
;
3855 const struct range_entry
*b_re
= (const struct range_entry
*) bp
;
3856 const unsigned long a
= a_re
->ranges_offset
;
3857 const unsigned long b
= b_re
->ranges_offset
;
3859 return (a
> b
) - (b
> a
);
3863 display_debug_ranges (struct dwarf_section
*section
,
3864 void *file ATTRIBUTE_UNUSED
)
3866 unsigned char *start
= section
->start
;
3867 unsigned long bytes
;
3868 unsigned char *section_begin
= start
;
3869 unsigned int num_range_list
, i
;
3870 struct range_entry
*range_entries
, *range_entry_fill
;
3872 bytes
= section
->size
;
3876 printf (_("\nThe %s section is empty.\n"), section
->name
);
3880 if (load_debug_info (file
) == 0)
3882 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
3888 for (i
= 0; i
< num_debug_info_entries
; i
++)
3889 num_range_list
+= debug_information
[i
].num_range_lists
;
3891 if (num_range_list
== 0)
3892 error (_("No range lists in .debug_info section!\n"));
3894 range_entries
= (struct range_entry
*)
3895 xmalloc (sizeof (*range_entries
) * num_range_list
);
3896 range_entry_fill
= range_entries
;
3898 for (i
= 0; i
< num_debug_info_entries
; i
++)
3900 debug_info
*debug_info_p
= &debug_information
[i
];
3903 for (j
= 0; j
< debug_info_p
->num_range_lists
; j
++)
3905 range_entry_fill
->ranges_offset
= debug_info_p
->range_lists
[j
];
3906 range_entry_fill
->debug_info_p
= debug_info_p
;
3911 qsort (range_entries
, num_range_list
, sizeof (*range_entries
),
3912 range_entry_compar
);
3914 /* DWARF sections under Mach-O have non-zero addresses. */
3915 if (range_entries
[0].ranges_offset
!= section
->address
)
3916 warn (_("Range lists in %s section start at 0x%lx\n"),
3917 section
->name
, range_entries
[0].ranges_offset
);
3919 printf (_("Contents of the %s section:\n\n"), section
->name
);
3920 printf (_(" Offset Begin End\n"));
3922 for (i
= 0; i
< num_range_list
; i
++)
3924 struct range_entry
*range_entry
= &range_entries
[i
];
3925 debug_info
*debug_info_p
= range_entry
->debug_info_p
;
3926 unsigned int pointer_size
;
3927 unsigned long offset
;
3928 unsigned char *next
;
3929 unsigned long base_address
;
3931 pointer_size
= debug_info_p
->pointer_size
;
3933 /* DWARF sections under Mach-O have non-zero addresses. */
3934 offset
= range_entry
->ranges_offset
- section
->address
;
3935 next
= section_begin
+ offset
;
3936 base_address
= debug_info_p
->base_address
;
3941 warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"),
3942 (unsigned long) (start
- section_begin
),
3943 (unsigned long) (next
- section_begin
), section
->name
);
3944 else if (start
> next
)
3945 warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"),
3946 (unsigned long) (start
- section_begin
),
3947 (unsigned long) (next
- section_begin
), section
->name
);
3956 /* Note: we use sign extension here in order to be sure that
3957 we can detect the -1 escape value. Sign extension into the
3958 top 32 bits of a 32-bit address will not affect the values
3959 that we display since we always show hex values, and always
3960 the bottom 32-bits. */
3961 begin
= byte_get_signed (start
, pointer_size
);
3962 start
+= pointer_size
;
3963 end
= byte_get_signed (start
, pointer_size
);
3964 start
+= pointer_size
;
3966 printf (" %8.8lx ", offset
);
3968 if (begin
== 0 && end
== 0)
3970 printf (_("<End of list>\n"));
3974 /* Check base address specifiers. */
3975 if (begin
== (dwarf_vma
) -1 && end
!= (dwarf_vma
) -1)
3978 print_dwarf_vma (begin
, pointer_size
);
3979 print_dwarf_vma (end
, pointer_size
);
3980 printf ("(base address)\n");
3984 print_dwarf_vma (begin
+ base_address
, pointer_size
);
3985 print_dwarf_vma (end
+ base_address
, pointer_size
);
3988 fputs (_("(start == end)"), stdout
);
3989 else if (begin
> end
)
3990 fputs (_("(start > end)"), stdout
);
3997 free (range_entries
);
4002 typedef struct Frame_Chunk
4004 struct Frame_Chunk
*next
;
4005 unsigned char *chunk_start
;
4007 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
4008 short int *col_type
;
4011 unsigned int code_factor
;
4013 unsigned long pc_begin
;
4014 unsigned long pc_range
;
4018 unsigned char fde_encoding
;
4019 unsigned char cfa_exp
;
4020 unsigned char ptr_size
;
4021 unsigned char segment_size
;
4025 static const char *const *dwarf_regnames
;
4026 static unsigned int dwarf_regnames_count
;
4028 /* A marker for a col_type that means this column was never referenced
4029 in the frame info. */
4030 #define DW_CFA_unreferenced (-1)
4032 /* Return 0 if not more space is needed, 1 if more space is needed,
4033 -1 for invalid reg. */
4036 frame_need_space (Frame_Chunk
*fc
, unsigned int reg
)
4038 int prev
= fc
->ncols
;
4040 if (reg
< (unsigned int) fc
->ncols
)
4043 if (dwarf_regnames_count
4044 && reg
> dwarf_regnames_count
)
4047 fc
->ncols
= reg
+ 1;
4048 fc
->col_type
= (short int *) xcrealloc (fc
->col_type
, fc
->ncols
,
4049 sizeof (short int));
4050 fc
->col_offset
= (int *) xcrealloc (fc
->col_offset
, fc
->ncols
, sizeof (int));
4052 while (prev
< fc
->ncols
)
4054 fc
->col_type
[prev
] = DW_CFA_unreferenced
;
4055 fc
->col_offset
[prev
] = 0;
4061 static const char *const dwarf_regnames_i386
[] =
4063 "eax", "ecx", "edx", "ebx",
4064 "esp", "ebp", "esi", "edi",
4065 "eip", "eflags", NULL
,
4066 "st0", "st1", "st2", "st3",
4067 "st4", "st5", "st6", "st7",
4069 "xmm0", "xmm1", "xmm2", "xmm3",
4070 "xmm4", "xmm5", "xmm6", "xmm7",
4071 "mm0", "mm1", "mm2", "mm3",
4072 "mm4", "mm5", "mm6", "mm7",
4073 "fcw", "fsw", "mxcsr",
4074 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
,
4079 init_dwarf_regnames_i386 (void)
4081 dwarf_regnames
= dwarf_regnames_i386
;
4082 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_i386
);
4085 static const char *const dwarf_regnames_x86_64
[] =
4087 "rax", "rdx", "rcx", "rbx",
4088 "rsi", "rdi", "rbp", "rsp",
4089 "r8", "r9", "r10", "r11",
4090 "r12", "r13", "r14", "r15",
4092 "xmm0", "xmm1", "xmm2", "xmm3",
4093 "xmm4", "xmm5", "xmm6", "xmm7",
4094 "xmm8", "xmm9", "xmm10", "xmm11",
4095 "xmm12", "xmm13", "xmm14", "xmm15",
4096 "st0", "st1", "st2", "st3",
4097 "st4", "st5", "st6", "st7",
4098 "mm0", "mm1", "mm2", "mm3",
4099 "mm4", "mm5", "mm6", "mm7",
4101 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
,
4102 "fs.base", "gs.base", NULL
, NULL
,
4104 "mxcsr", "fcw", "fsw"
4108 init_dwarf_regnames_x86_64 (void)
4110 dwarf_regnames
= dwarf_regnames_x86_64
;
4111 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_x86_64
);
4115 init_dwarf_regnames (unsigned int e_machine
)
4121 init_dwarf_regnames_i386 ();
4126 init_dwarf_regnames_x86_64 ();
4135 regname (unsigned int regno
, int row
)
4137 static char reg
[64];
4139 && regno
< dwarf_regnames_count
4140 && dwarf_regnames
[regno
] != NULL
)
4143 return dwarf_regnames
[regno
];
4144 snprintf (reg
, sizeof (reg
), "r%d (%s)", regno
,
4145 dwarf_regnames
[regno
]);
4148 snprintf (reg
, sizeof (reg
), "r%d", regno
);
4153 frame_display_row (Frame_Chunk
*fc
, int *need_col_headers
, int *max_regs
)
4158 if (*max_regs
< fc
->ncols
)
4159 *max_regs
= fc
->ncols
;
4161 if (*need_col_headers
)
4163 static const char *sloc
= " LOC";
4165 *need_col_headers
= 0;
4167 printf ("%-*s CFA ", eh_addr_size
* 2, sloc
);
4169 for (r
= 0; r
< *max_regs
; r
++)
4170 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
4175 printf ("%-5s ", regname (r
, 1));
4181 printf ("%0*lx ", eh_addr_size
* 2, fc
->pc_begin
);
4183 strcpy (tmp
, "exp");
4185 sprintf (tmp
, "%s%+d", regname (fc
->cfa_reg
, 1), fc
->cfa_offset
);
4186 printf ("%-8s ", tmp
);
4188 for (r
= 0; r
< fc
->ncols
; r
++)
4190 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
4192 switch (fc
->col_type
[r
])
4194 case DW_CFA_undefined
:
4197 case DW_CFA_same_value
:
4201 sprintf (tmp
, "c%+d", fc
->col_offset
[r
]);
4203 case DW_CFA_val_offset
:
4204 sprintf (tmp
, "v%+d", fc
->col_offset
[r
]);
4206 case DW_CFA_register
:
4207 sprintf (tmp
, "%s", regname (fc
->col_offset
[r
], 0));
4209 case DW_CFA_expression
:
4210 strcpy (tmp
, "exp");
4212 case DW_CFA_val_expression
:
4213 strcpy (tmp
, "vexp");
4216 strcpy (tmp
, "n/a");
4219 printf ("%-5s ", tmp
);
4225 #define GET(N) byte_get (start, N); start += N
4226 #define LEB() read_leb128 (start, & length_return, 0); start += length_return
4227 #define SLEB() read_sleb128 (start, & length_return); start += length_return
4230 display_debug_frames (struct dwarf_section
*section
,
4231 void *file ATTRIBUTE_UNUSED
)
4233 unsigned char *start
= section
->start
;
4234 unsigned char *end
= start
+ section
->size
;
4235 unsigned char *section_start
= start
;
4236 Frame_Chunk
*chunks
= 0;
4237 Frame_Chunk
*remembered_state
= 0;
4239 int is_eh
= strcmp (section
->name
, ".eh_frame") == 0;
4240 unsigned int length_return
;
4242 const char *bad_reg
= _("bad register: ");
4243 int saved_eh_addr_size
= eh_addr_size
;
4245 printf (_("Contents of the %s section:\n"), section
->name
);
4249 unsigned char *saved_start
;
4250 unsigned char *block_end
;
4251 unsigned long length
;
4252 unsigned long cie_id
;
4255 int need_col_headers
= 1;
4256 unsigned char *augmentation_data
= NULL
;
4257 unsigned long augmentation_data_len
= 0;
4258 int encoded_ptr_size
= saved_eh_addr_size
;
4260 int initial_length_size
;
4262 saved_start
= start
;
4263 length
= byte_get (start
, 4); start
+= 4;
4267 printf ("\n%08lx ZERO terminator\n\n",
4268 (unsigned long)(saved_start
- section_start
));
4272 if (length
== 0xffffffff)
4274 length
= byte_get (start
, 8);
4277 initial_length_size
= 12;
4282 initial_length_size
= 4;
4285 block_end
= saved_start
+ length
+ initial_length_size
;
4286 if (block_end
> end
)
4288 warn ("Invalid length %#08lx in FDE at %#08lx\n",
4289 length
, (unsigned long)(saved_start
- section_start
));
4292 cie_id
= byte_get (start
, offset_size
); start
+= offset_size
;
4294 if (is_eh
? (cie_id
== 0) : (cie_id
== DW_CIE_ID
))
4298 fc
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
4299 memset (fc
, 0, sizeof (Frame_Chunk
));
4303 fc
->chunk_start
= saved_start
;
4305 fc
->col_type
= (short int *) xmalloc (sizeof (short int));
4306 fc
->col_offset
= (int *) xmalloc (sizeof (int));
4307 frame_need_space (fc
, max_regs
- 1);
4311 fc
->augmentation
= (char *) start
;
4312 start
= (unsigned char *) strchr ((char *) start
, '\0') + 1;
4314 if (strcmp (fc
->augmentation
, "eh") == 0)
4315 start
+= eh_addr_size
;
4319 fc
->ptr_size
= GET (1);
4320 fc
->segment_size
= GET (1);
4321 eh_addr_size
= fc
->ptr_size
;
4325 fc
->ptr_size
= eh_addr_size
;
4326 fc
->segment_size
= 0;
4328 fc
->code_factor
= LEB ();
4329 fc
->data_factor
= SLEB ();
4339 if (fc
->augmentation
[0] == 'z')
4341 augmentation_data_len
= LEB ();
4342 augmentation_data
= start
;
4343 start
+= augmentation_data_len
;
4347 if (do_debug_frames_interp
)
4348 printf ("\n%08lx %08lx %08lx CIE \"%s\" cf=%d df=%d ra=%d\n",
4349 (unsigned long)(saved_start
- section_start
), length
, cie_id
,
4350 fc
->augmentation
, fc
->code_factor
, fc
->data_factor
,
4354 printf ("\n%08lx %08lx %08lx CIE\n",
4355 (unsigned long)(saved_start
- section_start
), length
, cie_id
);
4356 printf (" Version: %d\n", version
);
4357 printf (" Augmentation: \"%s\"\n", fc
->augmentation
);
4360 printf (" Pointer Size: %u\n", fc
->ptr_size
);
4361 printf (" Segment Size: %u\n", fc
->segment_size
);
4363 printf (" Code alignment factor: %u\n", fc
->code_factor
);
4364 printf (" Data alignment factor: %d\n", fc
->data_factor
);
4365 printf (" Return address column: %d\n", fc
->ra
);
4367 if (augmentation_data_len
)
4370 printf (" Augmentation data: ");
4371 for (i
= 0; i
< augmentation_data_len
; ++i
)
4372 printf (" %02x", augmentation_data
[i
]);
4378 if (augmentation_data_len
)
4380 unsigned char *p
, *q
;
4381 p
= (unsigned char *) fc
->augmentation
+ 1;
4382 q
= augmentation_data
;
4389 q
+= 1 + size_of_encoded_value (*q
);
4391 fc
->fde_encoding
= *q
++;
4399 if (fc
->fde_encoding
)
4400 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
4403 frame_need_space (fc
, fc
->ra
);
4407 unsigned char *look_for
;
4408 static Frame_Chunk fde_fc
;
4409 unsigned long segment_selector
;
4412 memset (fc
, 0, sizeof (Frame_Chunk
));
4414 look_for
= is_eh
? start
- 4 - cie_id
: section_start
+ cie_id
;
4416 for (cie
= chunks
; cie
; cie
= cie
->next
)
4417 if (cie
->chunk_start
== look_for
)
4422 warn ("Invalid CIE pointer %#08lx in FDE at %#08lx\n",
4423 cie_id
, (unsigned long)(saved_start
- section_start
));
4425 fc
->col_type
= (short int *) xmalloc (sizeof (short int));
4426 fc
->col_offset
= (int *) xmalloc (sizeof (int));
4427 frame_need_space (fc
, max_regs
- 1);
4429 fc
->augmentation
= "";
4430 fc
->fde_encoding
= 0;
4431 fc
->ptr_size
= eh_addr_size
;
4432 fc
->segment_size
= 0;
4436 fc
->ncols
= cie
->ncols
;
4437 fc
->col_type
= (short int *) xcmalloc (fc
->ncols
, sizeof (short int));
4438 fc
->col_offset
= (int *) xcmalloc (fc
->ncols
, sizeof (int));
4439 memcpy (fc
->col_type
, cie
->col_type
, fc
->ncols
* sizeof (short int));
4440 memcpy (fc
->col_offset
, cie
->col_offset
, fc
->ncols
* sizeof (int));
4441 fc
->augmentation
= cie
->augmentation
;
4442 fc
->ptr_size
= cie
->ptr_size
;
4443 eh_addr_size
= cie
->ptr_size
;
4444 fc
->segment_size
= cie
->segment_size
;
4445 fc
->code_factor
= cie
->code_factor
;
4446 fc
->data_factor
= cie
->data_factor
;
4447 fc
->cfa_reg
= cie
->cfa_reg
;
4448 fc
->cfa_offset
= cie
->cfa_offset
;
4450 frame_need_space (fc
, max_regs
- 1);
4451 fc
->fde_encoding
= cie
->fde_encoding
;
4454 if (fc
->fde_encoding
)
4455 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
4457 segment_selector
= 0;
4458 if (fc
->segment_size
)
4460 segment_selector
= byte_get (start
, fc
->segment_size
);
4461 start
+= fc
->segment_size
;
4463 fc
->pc_begin
= get_encoded_value (start
, fc
->fde_encoding
, section
);
4464 start
+= encoded_ptr_size
;
4465 fc
->pc_range
= byte_get (start
, encoded_ptr_size
);
4466 start
+= encoded_ptr_size
;
4468 if (cie
->augmentation
[0] == 'z')
4470 augmentation_data_len
= LEB ();
4471 augmentation_data
= start
;
4472 start
+= augmentation_data_len
;
4475 printf ("\n%08lx %08lx %08lx FDE cie=%08lx pc=",
4476 (unsigned long)(saved_start
- section_start
), length
, cie_id
,
4477 (unsigned long)(cie
->chunk_start
- section_start
));
4478 if (fc
->segment_size
)
4479 printf ("%04lx:", segment_selector
);
4480 printf ("%08lx..%08lx\n", fc
->pc_begin
, fc
->pc_begin
+ fc
->pc_range
);
4481 if (! do_debug_frames_interp
&& augmentation_data_len
)
4485 printf (" Augmentation data: ");
4486 for (i
= 0; i
< augmentation_data_len
; ++i
)
4487 printf (" %02x", augmentation_data
[i
]);
4493 /* At this point, fc is the current chunk, cie (if any) is set, and
4494 we're about to interpret instructions for the chunk. */
4495 /* ??? At present we need to do this always, since this sizes the
4496 fc->col_type and fc->col_offset arrays, which we write into always.
4497 We should probably split the interpreted and non-interpreted bits
4498 into two different routines, since there's so much that doesn't
4499 really overlap between them. */
4500 if (1 || do_debug_frames_interp
)
4502 /* Start by making a pass over the chunk, allocating storage
4503 and taking note of what registers are used. */
4504 unsigned char *tmp
= start
;
4506 while (start
< block_end
)
4509 unsigned long reg
, temp
;
4516 /* Warning: if you add any more cases to this switch, be
4517 sure to add them to the corresponding switch below. */
4520 case DW_CFA_advance_loc
:
4524 if (frame_need_space (fc
, opa
) >= 0)
4525 fc
->col_type
[opa
] = DW_CFA_undefined
;
4527 case DW_CFA_restore
:
4528 if (frame_need_space (fc
, opa
) >= 0)
4529 fc
->col_type
[opa
] = DW_CFA_undefined
;
4531 case DW_CFA_set_loc
:
4532 start
+= encoded_ptr_size
;
4534 case DW_CFA_advance_loc1
:
4537 case DW_CFA_advance_loc2
:
4540 case DW_CFA_advance_loc4
:
4543 case DW_CFA_offset_extended
:
4544 case DW_CFA_val_offset
:
4545 reg
= LEB (); LEB ();
4546 if (frame_need_space (fc
, reg
) >= 0)
4547 fc
->col_type
[reg
] = DW_CFA_undefined
;
4549 case DW_CFA_restore_extended
:
4551 frame_need_space (fc
, reg
);
4552 if (frame_need_space (fc
, reg
) >= 0)
4553 fc
->col_type
[reg
] = DW_CFA_undefined
;
4555 case DW_CFA_undefined
:
4557 if (frame_need_space (fc
, reg
) >= 0)
4558 fc
->col_type
[reg
] = DW_CFA_undefined
;
4560 case DW_CFA_same_value
:
4562 if (frame_need_space (fc
, reg
) >= 0)
4563 fc
->col_type
[reg
] = DW_CFA_undefined
;
4565 case DW_CFA_register
:
4566 reg
= LEB (); LEB ();
4567 if (frame_need_space (fc
, reg
) >= 0)
4568 fc
->col_type
[reg
] = DW_CFA_undefined
;
4570 case DW_CFA_def_cfa
:
4573 case DW_CFA_def_cfa_register
:
4576 case DW_CFA_def_cfa_offset
:
4579 case DW_CFA_def_cfa_expression
:
4583 case DW_CFA_expression
:
4584 case DW_CFA_val_expression
:
4588 if (frame_need_space (fc
, reg
) >= 0)
4589 fc
->col_type
[reg
] = DW_CFA_undefined
;
4591 case DW_CFA_offset_extended_sf
:
4592 case DW_CFA_val_offset_sf
:
4593 reg
= LEB (); SLEB ();
4594 if (frame_need_space (fc
, reg
) >= 0)
4595 fc
->col_type
[reg
] = DW_CFA_undefined
;
4597 case DW_CFA_def_cfa_sf
:
4600 case DW_CFA_def_cfa_offset_sf
:
4603 case DW_CFA_MIPS_advance_loc8
:
4606 case DW_CFA_GNU_args_size
:
4609 case DW_CFA_GNU_negative_offset_extended
:
4610 reg
= LEB (); LEB ();
4611 if (frame_need_space (fc
, reg
) >= 0)
4612 fc
->col_type
[reg
] = DW_CFA_undefined
;
4621 /* Now we know what registers are used, make a second pass over
4622 the chunk, this time actually printing out the info. */
4624 while (start
< block_end
)
4627 unsigned long ul
, reg
, roffs
;
4630 const char *reg_prefix
= "";
4637 /* Warning: if you add any more cases to this switch, be
4638 sure to add them to the corresponding switch above. */
4641 case DW_CFA_advance_loc
:
4642 if (do_debug_frames_interp
)
4643 frame_display_row (fc
, &need_col_headers
, &max_regs
);
4645 printf (" DW_CFA_advance_loc: %d to %08lx\n",
4646 opa
* fc
->code_factor
,
4647 fc
->pc_begin
+ opa
* fc
->code_factor
);
4648 fc
->pc_begin
+= opa
* fc
->code_factor
;
4653 if (opa
>= (unsigned int) fc
->ncols
)
4654 reg_prefix
= bad_reg
;
4655 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4656 printf (" DW_CFA_offset: %s%s at cfa%+ld\n",
4657 reg_prefix
, regname (opa
, 0),
4658 roffs
* fc
->data_factor
);
4659 if (*reg_prefix
== '\0')
4661 fc
->col_type
[opa
] = DW_CFA_offset
;
4662 fc
->col_offset
[opa
] = roffs
* fc
->data_factor
;
4666 case DW_CFA_restore
:
4667 if (opa
>= (unsigned int) cie
->ncols
4668 || opa
>= (unsigned int) fc
->ncols
)
4669 reg_prefix
= bad_reg
;
4670 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4671 printf (" DW_CFA_restore: %s%s\n",
4672 reg_prefix
, regname (opa
, 0));
4673 if (*reg_prefix
== '\0')
4675 fc
->col_type
[opa
] = cie
->col_type
[opa
];
4676 fc
->col_offset
[opa
] = cie
->col_offset
[opa
];
4680 case DW_CFA_set_loc
:
4681 vma
= get_encoded_value (start
, fc
->fde_encoding
, section
);
4682 start
+= encoded_ptr_size
;
4683 if (do_debug_frames_interp
)
4684 frame_display_row (fc
, &need_col_headers
, &max_regs
);
4686 printf (" DW_CFA_set_loc: %08lx\n", (unsigned long)vma
);
4690 case DW_CFA_advance_loc1
:
4691 ofs
= byte_get (start
, 1); start
+= 1;
4692 if (do_debug_frames_interp
)
4693 frame_display_row (fc
, &need_col_headers
, &max_regs
);
4695 printf (" DW_CFA_advance_loc1: %ld to %08lx\n",
4696 ofs
* fc
->code_factor
,
4697 fc
->pc_begin
+ ofs
* fc
->code_factor
);
4698 fc
->pc_begin
+= ofs
* fc
->code_factor
;
4701 case DW_CFA_advance_loc2
:
4702 ofs
= byte_get (start
, 2); start
+= 2;
4703 if (do_debug_frames_interp
)
4704 frame_display_row (fc
, &need_col_headers
, &max_regs
);
4706 printf (" DW_CFA_advance_loc2: %ld to %08lx\n",
4707 ofs
* fc
->code_factor
,
4708 fc
->pc_begin
+ ofs
* fc
->code_factor
);
4709 fc
->pc_begin
+= ofs
* fc
->code_factor
;
4712 case DW_CFA_advance_loc4
:
4713 ofs
= byte_get (start
, 4); start
+= 4;
4714 if (do_debug_frames_interp
)
4715 frame_display_row (fc
, &need_col_headers
, &max_regs
);
4717 printf (" DW_CFA_advance_loc4: %ld to %08lx\n",
4718 ofs
* fc
->code_factor
,
4719 fc
->pc_begin
+ ofs
* fc
->code_factor
);
4720 fc
->pc_begin
+= ofs
* fc
->code_factor
;
4723 case DW_CFA_offset_extended
:
4726 if (reg
>= (unsigned int) fc
->ncols
)
4727 reg_prefix
= bad_reg
;
4728 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4729 printf (" DW_CFA_offset_extended: %s%s at cfa%+ld\n",
4730 reg_prefix
, regname (reg
, 0),
4731 roffs
* fc
->data_factor
);
4732 if (*reg_prefix
== '\0')
4734 fc
->col_type
[reg
] = DW_CFA_offset
;
4735 fc
->col_offset
[reg
] = roffs
* fc
->data_factor
;
4739 case DW_CFA_val_offset
:
4742 if (reg
>= (unsigned int) fc
->ncols
)
4743 reg_prefix
= bad_reg
;
4744 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4745 printf (" DW_CFA_val_offset: %s%s at cfa%+ld\n",
4746 reg_prefix
, regname (reg
, 0),
4747 roffs
* fc
->data_factor
);
4748 if (*reg_prefix
== '\0')
4750 fc
->col_type
[reg
] = DW_CFA_val_offset
;
4751 fc
->col_offset
[reg
] = roffs
* fc
->data_factor
;
4755 case DW_CFA_restore_extended
:
4757 if (reg
>= (unsigned int) cie
->ncols
4758 || reg
>= (unsigned int) fc
->ncols
)
4759 reg_prefix
= bad_reg
;
4760 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4761 printf (" DW_CFA_restore_extended: %s%s\n",
4762 reg_prefix
, regname (reg
, 0));
4763 if (*reg_prefix
== '\0')
4765 fc
->col_type
[reg
] = cie
->col_type
[reg
];
4766 fc
->col_offset
[reg
] = cie
->col_offset
[reg
];
4770 case DW_CFA_undefined
:
4772 if (reg
>= (unsigned int) fc
->ncols
)
4773 reg_prefix
= bad_reg
;
4774 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4775 printf (" DW_CFA_undefined: %s%s\n",
4776 reg_prefix
, regname (reg
, 0));
4777 if (*reg_prefix
== '\0')
4779 fc
->col_type
[reg
] = DW_CFA_undefined
;
4780 fc
->col_offset
[reg
] = 0;
4784 case DW_CFA_same_value
:
4786 if (reg
>= (unsigned int) fc
->ncols
)
4787 reg_prefix
= bad_reg
;
4788 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4789 printf (" DW_CFA_same_value: %s%s\n",
4790 reg_prefix
, regname (reg
, 0));
4791 if (*reg_prefix
== '\0')
4793 fc
->col_type
[reg
] = DW_CFA_same_value
;
4794 fc
->col_offset
[reg
] = 0;
4798 case DW_CFA_register
:
4801 if (reg
>= (unsigned int) fc
->ncols
)
4802 reg_prefix
= bad_reg
;
4803 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4805 printf (" DW_CFA_register: %s%s in ",
4806 reg_prefix
, regname (reg
, 0));
4807 puts (regname (roffs
, 0));
4809 if (*reg_prefix
== '\0')
4811 fc
->col_type
[reg
] = DW_CFA_register
;
4812 fc
->col_offset
[reg
] = roffs
;
4816 case DW_CFA_remember_state
:
4817 if (! do_debug_frames_interp
)
4818 printf (" DW_CFA_remember_state\n");
4819 rs
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
4820 rs
->ncols
= fc
->ncols
;
4821 rs
->col_type
= (short int *) xcmalloc (rs
->ncols
,
4822 sizeof (short int));
4823 rs
->col_offset
= (int *) xcmalloc (rs
->ncols
, sizeof (int));
4824 memcpy (rs
->col_type
, fc
->col_type
, rs
->ncols
);
4825 memcpy (rs
->col_offset
, fc
->col_offset
, rs
->ncols
* sizeof (int));
4826 rs
->next
= remembered_state
;
4827 remembered_state
= rs
;
4830 case DW_CFA_restore_state
:
4831 if (! do_debug_frames_interp
)
4832 printf (" DW_CFA_restore_state\n");
4833 rs
= remembered_state
;
4836 remembered_state
= rs
->next
;
4837 frame_need_space (fc
, rs
->ncols
- 1);
4838 memcpy (fc
->col_type
, rs
->col_type
, rs
->ncols
);
4839 memcpy (fc
->col_offset
, rs
->col_offset
,
4840 rs
->ncols
* sizeof (int));
4841 free (rs
->col_type
);
4842 free (rs
->col_offset
);
4845 else if (do_debug_frames_interp
)
4846 printf ("Mismatched DW_CFA_restore_state\n");
4849 case DW_CFA_def_cfa
:
4850 fc
->cfa_reg
= LEB ();
4851 fc
->cfa_offset
= LEB ();
4853 if (! do_debug_frames_interp
)
4854 printf (" DW_CFA_def_cfa: %s ofs %d\n",
4855 regname (fc
->cfa_reg
, 0), fc
->cfa_offset
);
4858 case DW_CFA_def_cfa_register
:
4859 fc
->cfa_reg
= LEB ();
4861 if (! do_debug_frames_interp
)
4862 printf (" DW_CFA_def_cfa_register: %s\n",
4863 regname (fc
->cfa_reg
, 0));
4866 case DW_CFA_def_cfa_offset
:
4867 fc
->cfa_offset
= LEB ();
4868 if (! do_debug_frames_interp
)
4869 printf (" DW_CFA_def_cfa_offset: %d\n", fc
->cfa_offset
);
4873 if (! do_debug_frames_interp
)
4874 printf (" DW_CFA_nop\n");
4877 case DW_CFA_def_cfa_expression
:
4879 if (! do_debug_frames_interp
)
4881 printf (" DW_CFA_def_cfa_expression (");
4882 decode_location_expression (start
, eh_addr_size
, 0, -1,
4890 case DW_CFA_expression
:
4893 if (reg
>= (unsigned int) fc
->ncols
)
4894 reg_prefix
= bad_reg
;
4895 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4897 printf (" DW_CFA_expression: %s%s (",
4898 reg_prefix
, regname (reg
, 0));
4899 decode_location_expression (start
, eh_addr_size
, 0, -1,
4903 if (*reg_prefix
== '\0')
4904 fc
->col_type
[reg
] = DW_CFA_expression
;
4908 case DW_CFA_val_expression
:
4911 if (reg
>= (unsigned int) fc
->ncols
)
4912 reg_prefix
= bad_reg
;
4913 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4915 printf (" DW_CFA_val_expression: %s%s (",
4916 reg_prefix
, regname (reg
, 0));
4917 decode_location_expression (start
, eh_addr_size
, 0, -1,
4921 if (*reg_prefix
== '\0')
4922 fc
->col_type
[reg
] = DW_CFA_val_expression
;
4926 case DW_CFA_offset_extended_sf
:
4929 if (frame_need_space (fc
, reg
) < 0)
4930 reg_prefix
= bad_reg
;
4931 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4932 printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+ld\n",
4933 reg_prefix
, regname (reg
, 0),
4934 l
* fc
->data_factor
);
4935 if (*reg_prefix
== '\0')
4937 fc
->col_type
[reg
] = DW_CFA_offset
;
4938 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
4942 case DW_CFA_val_offset_sf
:
4945 if (frame_need_space (fc
, reg
) < 0)
4946 reg_prefix
= bad_reg
;
4947 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4948 printf (" DW_CFA_val_offset_sf: %s%s at cfa%+ld\n",
4949 reg_prefix
, regname (reg
, 0),
4950 l
* fc
->data_factor
);
4951 if (*reg_prefix
== '\0')
4953 fc
->col_type
[reg
] = DW_CFA_val_offset
;
4954 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
4958 case DW_CFA_def_cfa_sf
:
4959 fc
->cfa_reg
= LEB ();
4960 fc
->cfa_offset
= SLEB ();
4961 fc
->cfa_offset
= fc
->cfa_offset
* fc
->data_factor
;
4963 if (! do_debug_frames_interp
)
4964 printf (" DW_CFA_def_cfa_sf: %s ofs %d\n",
4965 regname (fc
->cfa_reg
, 0), fc
->cfa_offset
);
4968 case DW_CFA_def_cfa_offset_sf
:
4969 fc
->cfa_offset
= SLEB ();
4970 fc
->cfa_offset
= fc
->cfa_offset
* fc
->data_factor
;
4971 if (! do_debug_frames_interp
)
4972 printf (" DW_CFA_def_cfa_offset_sf: %d\n", fc
->cfa_offset
);
4975 case DW_CFA_MIPS_advance_loc8
:
4976 ofs
= byte_get (start
, 8); start
+= 8;
4977 if (do_debug_frames_interp
)
4978 frame_display_row (fc
, &need_col_headers
, &max_regs
);
4980 printf (" DW_CFA_MIPS_advance_loc8: %ld to %08lx\n",
4981 ofs
* fc
->code_factor
,
4982 fc
->pc_begin
+ ofs
* fc
->code_factor
);
4983 fc
->pc_begin
+= ofs
* fc
->code_factor
;
4986 case DW_CFA_GNU_window_save
:
4987 if (! do_debug_frames_interp
)
4988 printf (" DW_CFA_GNU_window_save\n");
4991 case DW_CFA_GNU_args_size
:
4993 if (! do_debug_frames_interp
)
4994 printf (" DW_CFA_GNU_args_size: %ld\n", ul
);
4997 case DW_CFA_GNU_negative_offset_extended
:
5000 if (frame_need_space (fc
, reg
) < 0)
5001 reg_prefix
= bad_reg
;
5002 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
5003 printf (" DW_CFA_GNU_negative_offset_extended: %s%s at cfa%+ld\n",
5004 reg_prefix
, regname (reg
, 0),
5005 l
* fc
->data_factor
);
5006 if (*reg_prefix
== '\0')
5008 fc
->col_type
[reg
] = DW_CFA_offset
;
5009 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
5014 if (op
>= DW_CFA_lo_user
&& op
<= DW_CFA_hi_user
)
5015 printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op
);
5017 warn (_("unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op
);
5022 if (do_debug_frames_interp
)
5023 frame_display_row (fc
, &need_col_headers
, &max_regs
);
5026 eh_addr_size
= saved_eh_addr_size
;
5039 display_gdb_index (struct dwarf_section
*section
,
5040 void *file ATTRIBUTE_UNUSED
)
5042 unsigned char *start
= section
->start
;
5044 uint32_t cu_list_offset
, tu_list_offset
;
5045 uint32_t address_table_offset
, symbol_table_offset
, constant_pool_offset
;
5046 unsigned int cu_list_elements
, tu_list_elements
;
5047 unsigned int address_table_size
, symbol_table_slots
;
5048 unsigned char *cu_list
, *tu_list
;
5049 unsigned char *address_table
, *symbol_table
, *constant_pool
;
5052 /* The documentation for the format of this file is in gdb/dwarf2read.c. */
5054 printf (_("Contents of the %s section:\n"), section
->name
);
5056 if (section
->size
< 6 * sizeof (uint32_t))
5058 warn (_("Truncated header in the %s section.\n"), section
->name
);
5062 version
= byte_get_little_endian (start
, 4);
5063 printf (_("Version %ld\n"), (long) version
);
5065 /* Prior versions are obsolete, and future versions may not be
5066 backwards compatible. */
5070 warn (_("The address table data in version 3 may be wrong.\n"));
5075 warn (_("Unsupported version %lu.\n"), (unsigned long) version
);
5079 cu_list_offset
= byte_get_little_endian (start
+ 4, 4);
5080 tu_list_offset
= byte_get_little_endian (start
+ 8, 4);
5081 address_table_offset
= byte_get_little_endian (start
+ 12, 4);
5082 symbol_table_offset
= byte_get_little_endian (start
+ 16, 4);
5083 constant_pool_offset
= byte_get_little_endian (start
+ 20, 4);
5085 if (cu_list_offset
> section
->size
5086 || tu_list_offset
> section
->size
5087 || address_table_offset
> section
->size
5088 || symbol_table_offset
> section
->size
5089 || constant_pool_offset
> section
->size
)
5091 warn (_("Corrupt header in the %s section.\n"), section
->name
);
5095 cu_list_elements
= (tu_list_offset
- cu_list_offset
) / 8;
5096 tu_list_elements
= (address_table_offset
- tu_list_offset
) / 8;
5097 address_table_size
= symbol_table_offset
- address_table_offset
;
5098 symbol_table_slots
= (constant_pool_offset
- symbol_table_offset
) / 8;
5100 cu_list
= start
+ cu_list_offset
;
5101 tu_list
= start
+ tu_list_offset
;
5102 address_table
= start
+ address_table_offset
;
5103 symbol_table
= start
+ symbol_table_offset
;
5104 constant_pool
= start
+ constant_pool_offset
;
5106 printf (_("\nCU table:\n"));
5107 for (i
= 0; i
< cu_list_elements
; i
+= 2)
5109 uint64_t cu_offset
= byte_get_little_endian (cu_list
+ i
* 8, 8);
5110 uint64_t cu_length
= byte_get_little_endian (cu_list
+ i
* 8 + 8, 8);
5112 printf (_("[%3u] 0x%lx - 0x%lx\n"), i
/ 2,
5113 (unsigned long) cu_offset
,
5114 (unsigned long) (cu_offset
+ cu_length
- 1));
5117 printf (_("\nTU table:\n"));
5118 for (i
= 0; i
< tu_list_elements
; i
+= 3)
5120 uint64_t tu_offset
= byte_get_little_endian (tu_list
+ i
* 8, 8);
5121 uint64_t type_offset
= byte_get_little_endian (tu_list
+ i
* 8 + 8, 8);
5122 uint64_t signature
= byte_get_little_endian (tu_list
+ i
* 8 + 16, 8);
5124 printf (_("[%3u] 0x%lx 0x%lx "), i
/ 3,
5125 (unsigned long) tu_offset
,
5126 (unsigned long) type_offset
);
5127 print_dwarf_vma (signature
, 8);
5131 printf (_("\nAddress table:\n"));
5132 for (i
= 0; i
< address_table_size
; i
+= 2 * 8 + 4)
5134 uint64_t low
= byte_get_little_endian (address_table
+ i
, 8);
5135 uint64_t high
= byte_get_little_endian (address_table
+ i
+ 8, 8);
5136 uint32_t cu_index
= byte_get_little_endian (address_table
+ i
+ 16, 4);
5138 print_dwarf_vma (low
, 8);
5139 print_dwarf_vma (high
, 8);
5140 printf (_("%lu\n"), (unsigned long) cu_index
);
5143 printf (_("\nSymbol table:\n"));
5144 for (i
= 0; i
< symbol_table_slots
; ++i
)
5146 uint32_t name_offset
= byte_get_little_endian (symbol_table
+ i
* 8, 4);
5147 uint32_t cu_vector_offset
= byte_get_little_endian (symbol_table
+ i
* 8 + 4, 4);
5148 uint32_t num_cus
, cu
;
5150 if (name_offset
!= 0
5151 || cu_vector_offset
!= 0)
5155 printf ("[%3u] %s:", i
, constant_pool
+ name_offset
);
5156 num_cus
= byte_get_little_endian (constant_pool
+ cu_vector_offset
, 4);
5157 for (j
= 0; j
< num_cus
; ++j
)
5159 cu
= byte_get_little_endian (constant_pool
+ cu_vector_offset
+ 4 + j
* 4, 4);
5160 /* Convert to TU number if it's for a type unit. */
5161 if (cu
>= cu_list_elements
)
5162 printf (" T%lu", (unsigned long) (cu
- cu_list_elements
));
5164 printf (" %lu", (unsigned long) cu
);
5174 display_debug_not_supported (struct dwarf_section
*section
,
5175 void *file ATTRIBUTE_UNUSED
)
5177 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
5184 cmalloc (size_t nmemb
, size_t size
)
5186 /* Check for overflow. */
5187 if (nmemb
>= ~(size_t) 0 / size
)
5190 return malloc (nmemb
* size
);
5194 xcmalloc (size_t nmemb
, size_t size
)
5196 /* Check for overflow. */
5197 if (nmemb
>= ~(size_t) 0 / size
)
5200 return xmalloc (nmemb
* size
);
5204 xcrealloc (void *ptr
, size_t nmemb
, size_t size
)
5206 /* Check for overflow. */
5207 if (nmemb
>= ~(size_t) 0 / size
)
5210 return xrealloc (ptr
, nmemb
* size
);
5214 free_debug_memory (void)
5220 for (i
= 0; i
< max
; i
++)
5221 free_debug_section ((enum dwarf_section_display_enum
) i
);
5223 if (debug_information
!= NULL
)
5225 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
)
5227 for (i
= 0; i
< num_debug_info_entries
; i
++)
5229 if (!debug_information
[i
].max_loc_offsets
)
5231 free (debug_information
[i
].loc_offsets
);
5232 free (debug_information
[i
].have_frame_base
);
5234 if (!debug_information
[i
].max_range_lists
)
5235 free (debug_information
[i
].range_lists
);
5239 free (debug_information
);
5240 debug_information
= NULL
;
5241 num_debug_info_entries
= 0;
5246 dwarf_select_sections_by_names (const char *names
)
5250 const char * option
;
5254 debug_dump_long_opts
;
5256 static const debug_dump_long_opts opts_table
[] =
5258 /* Please keep this table alpha- sorted. */
5259 { "Ranges", & do_debug_ranges
, 1 },
5260 { "abbrev", & do_debug_abbrevs
, 1 },
5261 { "aranges", & do_debug_aranges
, 1 },
5262 { "frames", & do_debug_frames
, 1 },
5263 { "frames-interp", & do_debug_frames_interp
, 1 },
5264 { "info", & do_debug_info
, 1 },
5265 { "line", & do_debug_lines
, FLAG_DEBUG_LINES_RAW
}, /* For backwards compatibility. */
5266 { "rawline", & do_debug_lines
, FLAG_DEBUG_LINES_RAW
},
5267 { "decodedline", & do_debug_lines
, FLAG_DEBUG_LINES_DECODED
},
5268 { "loc", & do_debug_loc
, 1 },
5269 { "macro", & do_debug_macinfo
, 1 },
5270 { "pubnames", & do_debug_pubnames
, 1 },
5271 { "pubtypes", & do_debug_pubtypes
, 1 },
5272 /* This entry is for compatability
5273 with earlier versions of readelf. */
5274 { "ranges", & do_debug_aranges
, 1 },
5275 { "str", & do_debug_str
, 1 },
5276 /* The special .gdb_index section. */
5277 { "gdb_index", & do_gdb_index
, 1 },
5278 /* These trace_* sections are used by Itanium VMS. */
5279 { "trace_abbrev", & do_trace_abbrevs
, 1 },
5280 { "trace_aranges", & do_trace_aranges
, 1 },
5281 { "trace_info", & do_trace_info
, 1 },
5290 const debug_dump_long_opts
* entry
;
5292 for (entry
= opts_table
; entry
->option
; entry
++)
5294 size_t len
= strlen (entry
->option
);
5296 if (strncmp (p
, entry
->option
, len
) == 0
5297 && (p
[len
] == ',' || p
[len
] == '\0'))
5299 * entry
->variable
|= entry
->val
;
5301 /* The --debug-dump=frames-interp option also
5302 enables the --debug-dump=frames option. */
5303 if (do_debug_frames_interp
)
5304 do_debug_frames
= 1;
5311 if (entry
->option
== NULL
)
5313 warn (_("Unrecognized debug option '%s'\n"), p
);
5314 p
= strchr (p
, ',');
5325 dwarf_select_sections_by_letters (const char *letters
)
5327 unsigned int lindex
= 0;
5329 while (letters
[lindex
])
5330 switch (letters
[lindex
++])
5337 do_debug_abbrevs
= 1;
5341 do_debug_lines
|= FLAG_DEBUG_LINES_RAW
;
5345 do_debug_lines
|= FLAG_DEBUG_LINES_DECODED
;
5349 do_debug_pubnames
= 1;
5353 do_debug_pubtypes
= 1;
5357 do_debug_aranges
= 1;
5361 do_debug_ranges
= 1;
5365 do_debug_frames_interp
= 1;
5367 do_debug_frames
= 1;
5371 do_debug_macinfo
= 1;
5383 warn (_("Unrecognized debug option '%s'\n"), optarg
);
5389 dwarf_select_sections_all (void)
5392 do_debug_abbrevs
= 1;
5393 do_debug_lines
= FLAG_DEBUG_LINES_RAW
;
5394 do_debug_pubnames
= 1;
5395 do_debug_pubtypes
= 1;
5396 do_debug_aranges
= 1;
5397 do_debug_ranges
= 1;
5398 do_debug_frames
= 1;
5399 do_debug_macinfo
= 1;
5404 do_trace_abbrevs
= 1;
5405 do_trace_aranges
= 1;
5408 struct dwarf_section_display debug_displays
[] =
5410 { { ".debug_abbrev", ".zdebug_abbrev", NULL
, NULL
, 0, 0 },
5411 display_debug_abbrev
, &do_debug_abbrevs
, 0 },
5412 { { ".debug_aranges", ".zdebug_aranges", NULL
, NULL
, 0, 0 },
5413 display_debug_aranges
, &do_debug_aranges
, 1 },
5414 { { ".debug_frame", ".zdebug_frame", NULL
, NULL
, 0, 0 },
5415 display_debug_frames
, &do_debug_frames
, 1 },
5416 { { ".debug_info", ".zdebug_info", NULL
, NULL
, 0, 0 },
5417 display_debug_info
, &do_debug_info
, 1 },
5418 { { ".debug_line", ".zdebug_line", NULL
, NULL
, 0, 0 },
5419 display_debug_lines
, &do_debug_lines
, 1 },
5420 { { ".debug_pubnames", ".zdebug_pubnames", NULL
, NULL
, 0, 0 },
5421 display_debug_pubnames
, &do_debug_pubnames
, 0 },
5422 { { ".eh_frame", "", NULL
, NULL
, 0, 0 },
5423 display_debug_frames
, &do_debug_frames
, 1 },
5424 { { ".debug_macinfo", ".zdebug_macinfo", NULL
, NULL
, 0, 0 },
5425 display_debug_macinfo
, &do_debug_macinfo
, 0 },
5426 { { ".debug_str", ".zdebug_str", NULL
, NULL
, 0, 0 },
5427 display_debug_str
, &do_debug_str
, 0 },
5428 { { ".debug_loc", ".zdebug_loc", NULL
, NULL
, 0, 0 },
5429 display_debug_loc
, &do_debug_loc
, 1 },
5430 { { ".debug_pubtypes", ".zdebug_pubtypes", NULL
, NULL
, 0, 0 },
5431 display_debug_pubnames
, &do_debug_pubtypes
, 0 },
5432 { { ".debug_ranges", ".zdebug_ranges", NULL
, NULL
, 0, 0 },
5433 display_debug_ranges
, &do_debug_ranges
, 1 },
5434 { { ".debug_static_func", ".zdebug_static_func", NULL
, NULL
, 0, 0 },
5435 display_debug_not_supported
, NULL
, 0 },
5436 { { ".debug_static_vars", ".zdebug_static_vars", NULL
, NULL
, 0, 0 },
5437 display_debug_not_supported
, NULL
, 0 },
5438 { { ".debug_types", ".zdebug_types", NULL
, NULL
, 0, 0 },
5439 display_debug_types
, &do_debug_info
, 1 },
5440 { { ".debug_weaknames", ".zdebug_weaknames", NULL
, NULL
, 0, 0 },
5441 display_debug_not_supported
, NULL
, 0 },
5442 { { ".gdb_index", "", NULL
, NULL
, 0, 0 },
5443 display_gdb_index
, &do_gdb_index
, 0 },
5444 { { ".trace_info", "", NULL
, NULL
, 0, 0 },
5445 display_trace_info
, &do_trace_info
, 1 },
5446 { { ".trace_abbrev", "", NULL
, NULL
, 0, 0 },
5447 display_debug_abbrev
, &do_trace_abbrevs
, 0 },
5448 { { ".trace_aranges", "", NULL
, NULL
, 0, 0 },
5449 display_debug_aranges
, &do_trace_aranges
, 0 }