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 int dwarf_cutoff_level
= -1;
67 unsigned long dwarf_start_die
;
69 /* Values for do_debug_lines. */
70 #define FLAG_DEBUG_LINES_RAW 1
71 #define FLAG_DEBUG_LINES_DECODED 2
74 size_of_encoded_value (int encoding
)
76 switch (encoding
& 0x7)
79 case 0: return eh_addr_size
;
87 get_encoded_value (unsigned char *data
,
89 struct dwarf_section
*section
)
91 int size
= size_of_encoded_value (encoding
);
94 if (encoding
& DW_EH_PE_signed
)
95 val
= byte_get_signed (data
, size
);
97 val
= byte_get (data
, size
);
99 if ((encoding
& 0x70) == DW_EH_PE_pcrel
)
100 val
+= section
->address
+ (data
- section
->start
);
104 /* Print a dwarf_vma value (typically an address, offset or length) in
105 hexadecimal format, followed by a space. The length of the value (and
106 hence the precision displayed) is determined by the byte_size parameter. */
109 print_dwarf_vma (dwarf_vma val
, unsigned byte_size
)
111 static char buff
[18];
114 /* Printf does not have a way of specifiying a maximum field width for an
115 integer value, so we print the full value into a buffer and then select
116 the precision we need. */
117 #if __STDC_VERSION__ >= 199901L || (defined(__GNUC__) && __GNUC__ >= 2)
119 snprintf (buff
, sizeof (buff
), "%16.16llx ", val
);
121 snprintf (buff
, sizeof (buff
), "%016I64x ", val
);
124 snprintf (buff
, sizeof (buff
), "%16.16lx ", val
);
129 if (byte_size
> 0 && byte_size
<= 8)
130 offset
= 16 - 2 * byte_size
;
132 error ("Wrong size in print_dwarf_vma");
135 fputs (buff
+ offset
, stdout
);
138 #if __STDC_VERSION__ >= 199901L || (defined(__GNUC__) && __GNUC__ >= 2)
140 #define DWARF_VMA_FMT "ll"
142 #define DWARF_VMA_FMT "I64"
145 #define DWARF_VMA_FMT "l"
149 dwarf_vmatoa (const char *fmtch
, dwarf_vma value
)
151 /* As dwarf_vmatoa is used more then once in a printf call
152 for output, we are cycling through an fixed array of pointers
153 for return address. */
154 static int buf_pos
= 0;
155 static struct dwarf_vmatoa_buf
162 sprintf (fmt
, "%%%s%s", DWARF_VMA_FMT
, fmtch
);
164 ret
= buf
[buf_pos
++].place
;
165 buf_pos
%= ARRAY_SIZE (buf
);
167 snprintf (ret
, sizeof (buf
[0].place
), fmt
, value
);
173 read_leb128 (unsigned char *data
, unsigned int *length_return
, int sign
)
175 dwarf_vma result
= 0;
176 unsigned int num_read
= 0;
177 unsigned int shift
= 0;
185 result
|= ((dwarf_vma
) (byte
& 0x7f)) << shift
;
192 if (length_return
!= NULL
)
193 *length_return
= num_read
;
195 if (sign
&& (shift
< 8 * sizeof (result
)) && (byte
& 0x40))
196 result
|= -1L << shift
;
201 /* Create a signed version to avoid painful typecasts. */
202 static dwarf_signed_vma
203 read_sleb128 (unsigned char *data
, unsigned int *length_return
)
205 return (dwarf_signed_vma
) read_leb128 (data
, length_return
, 1);
208 typedef struct State_Machine_Registers
216 unsigned char op_index
;
217 unsigned char end_sequence
;
218 /* This variable hold the number of the last entry seen
219 in the File Table. */
220 unsigned int last_file_entry
;
223 static SMR state_machine_regs
;
226 reset_state_machine (int is_stmt
)
228 state_machine_regs
.address
= 0;
229 state_machine_regs
.op_index
= 0;
230 state_machine_regs
.file
= 1;
231 state_machine_regs
.line
= 1;
232 state_machine_regs
.column
= 0;
233 state_machine_regs
.is_stmt
= is_stmt
;
234 state_machine_regs
.basic_block
= 0;
235 state_machine_regs
.end_sequence
= 0;
236 state_machine_regs
.last_file_entry
= 0;
239 /* Handled an extend line op.
240 Returns the number of bytes read. */
243 process_extended_line_op (unsigned char *data
, int is_stmt
)
245 unsigned char op_code
;
246 unsigned int bytes_read
;
251 len
= read_leb128 (data
, & bytes_read
, 0);
256 warn (_("badly formed extended line op encountered!\n"));
263 printf (_(" Extended opcode %d: "), op_code
);
267 case DW_LNE_end_sequence
:
268 printf (_("End of Sequence\n\n"));
269 reset_state_machine (is_stmt
);
272 case DW_LNE_set_address
:
273 adr
= byte_get (data
, len
- bytes_read
- 1);
274 printf (_("set Address to 0x%s\n"), dwarf_vmatoa ("x", adr
));
275 state_machine_regs
.address
= adr
;
276 state_machine_regs
.op_index
= 0;
279 case DW_LNE_define_file
:
280 printf (_(" define new File Table entry\n"));
281 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
283 printf (" %d\t", ++state_machine_regs
.last_file_entry
);
285 data
+= strlen ((char *) data
) + 1;
286 printf ("%s\t", dwarf_vmatoa ("u", read_leb128 (data
, & bytes_read
, 0)));
288 printf ("%s\t", dwarf_vmatoa ("u", read_leb128 (data
, & bytes_read
, 0)));
290 printf ("%s\t", dwarf_vmatoa ("u", read_leb128 (data
, & bytes_read
, 0)));
291 printf ("%s\n\n", name
);
294 case DW_LNE_set_discriminator
:
295 printf (_("set Discriminator to %s\n"),
296 dwarf_vmatoa ("u", read_leb128 (data
, & bytes_read
, 0)));
300 case DW_LNE_HP_negate_is_UV_update
:
301 printf ("DW_LNE_HP_negate_is_UV_update\n");
303 case DW_LNE_HP_push_context
:
304 printf ("DW_LNE_HP_push_context\n");
306 case DW_LNE_HP_pop_context
:
307 printf ("DW_LNE_HP_pop_context\n");
309 case DW_LNE_HP_set_file_line_column
:
310 printf ("DW_LNE_HP_set_file_line_column\n");
312 case DW_LNE_HP_set_routine_name
:
313 printf ("DW_LNE_HP_set_routine_name\n");
315 case DW_LNE_HP_set_sequence
:
316 printf ("DW_LNE_HP_set_sequence\n");
318 case DW_LNE_HP_negate_post_semantics
:
319 printf ("DW_LNE_HP_negate_post_semantics\n");
321 case DW_LNE_HP_negate_function_exit
:
322 printf ("DW_LNE_HP_negate_function_exit\n");
324 case DW_LNE_HP_negate_front_end_logical
:
325 printf ("DW_LNE_HP_negate_front_end_logical\n");
327 case DW_LNE_HP_define_proc
:
328 printf ("DW_LNE_HP_define_proc\n");
330 case DW_LNE_HP_source_file_correlation
:
332 unsigned char *edata
= data
+ len
- bytes_read
- 1;
334 printf ("DW_LNE_HP_source_file_correlation\n");
340 opc
= read_leb128 (data
, & bytes_read
, 0);
345 case DW_LNE_HP_SFC_formfeed
:
346 printf (" DW_LNE_HP_SFC_formfeed\n");
348 case DW_LNE_HP_SFC_set_listing_line
:
349 printf (" DW_LNE_HP_SFC_set_listing_line (%s)\n",
351 read_leb128 (data
, & bytes_read
, 0)));
354 case DW_LNE_HP_SFC_associate
:
355 printf (" DW_LNE_HP_SFC_associate ");
358 read_leb128 (data
, & bytes_read
, 0)));
362 read_leb128 (data
, & bytes_read
, 0)));
366 read_leb128 (data
, & bytes_read
, 0)));
370 printf (" UNKNOW DW_LNE_HP_SFC opcode (%u)\n", opc
);
379 if (op_code
>= DW_LNE_lo_user
380 /* The test against DW_LNW_hi_user is redundant due to
381 the limited range of the unsigned char data type used
383 /*&& op_code <= DW_LNE_hi_user*/)
384 printf (_("user defined: length %d\n"), len
- bytes_read
);
386 printf (_("UNKNOWN: length %d\n"), len
- bytes_read
);
394 fetch_indirect_string (dwarf_vma offset
)
396 struct dwarf_section
*section
= &debug_displays
[str
].section
;
398 if (section
->start
== NULL
)
399 return _("<no .debug_str section>");
401 /* DWARF sections under Mach-O have non-zero addresses. */
402 offset
-= section
->address
;
403 if (offset
> section
->size
)
405 warn (_("DW_FORM_strp offset too big: %s\n"),
406 dwarf_vmatoa ("x", offset
));
407 return _("<offset is too big>");
410 return (const char *) section
->start
+ offset
;
413 /* FIXME: There are better and more efficient ways to handle
414 these structures. For now though, I just want something that
415 is simple to implement. */
416 typedef struct abbrev_attr
418 unsigned long attribute
;
420 struct abbrev_attr
*next
;
424 typedef struct abbrev_entry
429 struct abbrev_attr
*first_attr
;
430 struct abbrev_attr
*last_attr
;
431 struct abbrev_entry
*next
;
435 static abbrev_entry
*first_abbrev
= NULL
;
436 static abbrev_entry
*last_abbrev
= NULL
;
443 for (abbrv
= first_abbrev
; abbrv
;)
445 abbrev_entry
*next_abbrev
= abbrv
->next
;
448 for (attr
= abbrv
->first_attr
; attr
;)
450 abbrev_attr
*next_attr
= attr
->next
;
460 last_abbrev
= first_abbrev
= NULL
;
464 add_abbrev (unsigned long number
, unsigned long tag
, int children
)
468 entry
= (abbrev_entry
*) malloc (sizeof (*entry
));
473 entry
->entry
= number
;
475 entry
->children
= children
;
476 entry
->first_attr
= NULL
;
477 entry
->last_attr
= NULL
;
480 if (first_abbrev
== NULL
)
481 first_abbrev
= entry
;
483 last_abbrev
->next
= entry
;
489 add_abbrev_attr (unsigned long attribute
, unsigned long form
)
493 attr
= (abbrev_attr
*) malloc (sizeof (*attr
));
498 attr
->attribute
= attribute
;
502 if (last_abbrev
->first_attr
== NULL
)
503 last_abbrev
->first_attr
= attr
;
505 last_abbrev
->last_attr
->next
= attr
;
507 last_abbrev
->last_attr
= attr
;
510 /* Processes the (partial) contents of a .debug_abbrev section.
511 Returns NULL if the end of the section was encountered.
512 Returns the address after the last byte read if the end of
513 an abbreviation set was found. */
515 static unsigned char *
516 process_abbrev_section (unsigned char *start
, unsigned char *end
)
518 if (first_abbrev
!= NULL
)
523 unsigned int bytes_read
;
526 unsigned long attribute
;
529 entry
= read_leb128 (start
, & bytes_read
, 0);
532 /* A single zero is supposed to end the section according
533 to the standard. If there's more, then signal that to
536 return start
== end
? NULL
: start
;
538 tag
= read_leb128 (start
, & bytes_read
, 0);
543 add_abbrev (entry
, tag
, children
);
549 attribute
= read_leb128 (start
, & bytes_read
, 0);
552 form
= read_leb128 (start
, & bytes_read
, 0);
556 add_abbrev_attr (attribute
, form
);
558 while (attribute
!= 0);
565 get_TAG_name (unsigned long tag
)
569 case DW_TAG_padding
: return "DW_TAG_padding";
570 case DW_TAG_array_type
: return "DW_TAG_array_type";
571 case DW_TAG_class_type
: return "DW_TAG_class_type";
572 case DW_TAG_entry_point
: return "DW_TAG_entry_point";
573 case DW_TAG_enumeration_type
: return "DW_TAG_enumeration_type";
574 case DW_TAG_formal_parameter
: return "DW_TAG_formal_parameter";
575 case DW_TAG_imported_declaration
: return "DW_TAG_imported_declaration";
576 case DW_TAG_label
: return "DW_TAG_label";
577 case DW_TAG_lexical_block
: return "DW_TAG_lexical_block";
578 case DW_TAG_member
: return "DW_TAG_member";
579 case DW_TAG_pointer_type
: return "DW_TAG_pointer_type";
580 case DW_TAG_reference_type
: return "DW_TAG_reference_type";
581 case DW_TAG_compile_unit
: return "DW_TAG_compile_unit";
582 case DW_TAG_string_type
: return "DW_TAG_string_type";
583 case DW_TAG_structure_type
: return "DW_TAG_structure_type";
584 case DW_TAG_subroutine_type
: return "DW_TAG_subroutine_type";
585 case DW_TAG_typedef
: return "DW_TAG_typedef";
586 case DW_TAG_union_type
: return "DW_TAG_union_type";
587 case DW_TAG_unspecified_parameters
: return "DW_TAG_unspecified_parameters";
588 case DW_TAG_variant
: return "DW_TAG_variant";
589 case DW_TAG_common_block
: return "DW_TAG_common_block";
590 case DW_TAG_common_inclusion
: return "DW_TAG_common_inclusion";
591 case DW_TAG_inheritance
: return "DW_TAG_inheritance";
592 case DW_TAG_inlined_subroutine
: return "DW_TAG_inlined_subroutine";
593 case DW_TAG_module
: return "DW_TAG_module";
594 case DW_TAG_ptr_to_member_type
: return "DW_TAG_ptr_to_member_type";
595 case DW_TAG_set_type
: return "DW_TAG_set_type";
596 case DW_TAG_subrange_type
: return "DW_TAG_subrange_type";
597 case DW_TAG_with_stmt
: return "DW_TAG_with_stmt";
598 case DW_TAG_access_declaration
: return "DW_TAG_access_declaration";
599 case DW_TAG_base_type
: return "DW_TAG_base_type";
600 case DW_TAG_catch_block
: return "DW_TAG_catch_block";
601 case DW_TAG_const_type
: return "DW_TAG_const_type";
602 case DW_TAG_constant
: return "DW_TAG_constant";
603 case DW_TAG_enumerator
: return "DW_TAG_enumerator";
604 case DW_TAG_file_type
: return "DW_TAG_file_type";
605 case DW_TAG_friend
: return "DW_TAG_friend";
606 case DW_TAG_namelist
: return "DW_TAG_namelist";
607 case DW_TAG_namelist_item
: return "DW_TAG_namelist_item";
608 case DW_TAG_packed_type
: return "DW_TAG_packed_type";
609 case DW_TAG_subprogram
: return "DW_TAG_subprogram";
610 case DW_TAG_template_type_param
: return "DW_TAG_template_type_param";
611 case DW_TAG_template_value_param
: return "DW_TAG_template_value_param";
612 case DW_TAG_thrown_type
: return "DW_TAG_thrown_type";
613 case DW_TAG_try_block
: return "DW_TAG_try_block";
614 case DW_TAG_variant_part
: return "DW_TAG_variant_part";
615 case DW_TAG_variable
: return "DW_TAG_variable";
616 case DW_TAG_volatile_type
: return "DW_TAG_volatile_type";
617 case DW_TAG_MIPS_loop
: return "DW_TAG_MIPS_loop";
618 case DW_TAG_format_label
: return "DW_TAG_format_label";
619 case DW_TAG_function_template
: return "DW_TAG_function_template";
620 case DW_TAG_class_template
: return "DW_TAG_class_template";
621 /* DWARF 2.1 values. */
622 case DW_TAG_dwarf_procedure
: return "DW_TAG_dwarf_procedure";
623 case DW_TAG_restrict_type
: return "DW_TAG_restrict_type";
624 case DW_TAG_interface_type
: return "DW_TAG_interface_type";
625 case DW_TAG_namespace
: return "DW_TAG_namespace";
626 case DW_TAG_imported_module
: return "DW_TAG_imported_module";
627 case DW_TAG_unspecified_type
: return "DW_TAG_unspecified_type";
628 case DW_TAG_partial_unit
: return "DW_TAG_partial_unit";
629 case DW_TAG_imported_unit
: return "DW_TAG_imported_unit";
630 case DW_TAG_condition
: return "DW_TAG_condition";
631 case DW_TAG_shared_type
: return "DW_TAG_shared_type";
632 /* DWARF 4 values. */
633 case DW_TAG_type_unit
: return "DW_TAG_type_unit";
634 case DW_TAG_rvalue_reference_type
: return "DW_TAG_rvalue_reference_type";
635 case DW_TAG_template_alias
: return "DW_TAG_template_alias";
637 case DW_TAG_upc_shared_type
: return "DW_TAG_upc_shared_type";
638 case DW_TAG_upc_strict_type
: return "DW_TAG_upc_strict_type";
639 case DW_TAG_upc_relaxed_type
: return "DW_TAG_upc_relaxed_type";
641 case DW_TAG_GNU_call_site
: return "DW_TAG_GNU_call_site";
642 case DW_TAG_GNU_call_site_parameter
:return "DW_TAG_GNU_call_site_parameter";
645 static char buffer
[100];
647 snprintf (buffer
, sizeof (buffer
), _("Unknown TAG value: %lx"), tag
);
654 get_FORM_name (unsigned long form
)
658 case DW_FORM_addr
: return "DW_FORM_addr";
659 case DW_FORM_block2
: return "DW_FORM_block2";
660 case DW_FORM_block4
: return "DW_FORM_block4";
661 case DW_FORM_data2
: return "DW_FORM_data2";
662 case DW_FORM_data4
: return "DW_FORM_data4";
663 case DW_FORM_data8
: return "DW_FORM_data8";
664 case DW_FORM_string
: return "DW_FORM_string";
665 case DW_FORM_block
: return "DW_FORM_block";
666 case DW_FORM_block1
: return "DW_FORM_block1";
667 case DW_FORM_data1
: return "DW_FORM_data1";
668 case DW_FORM_flag
: return "DW_FORM_flag";
669 case DW_FORM_sdata
: return "DW_FORM_sdata";
670 case DW_FORM_strp
: return "DW_FORM_strp";
671 case DW_FORM_udata
: return "DW_FORM_udata";
672 case DW_FORM_ref_addr
: return "DW_FORM_ref_addr";
673 case DW_FORM_ref1
: return "DW_FORM_ref1";
674 case DW_FORM_ref2
: return "DW_FORM_ref2";
675 case DW_FORM_ref4
: return "DW_FORM_ref4";
676 case DW_FORM_ref8
: return "DW_FORM_ref8";
677 case DW_FORM_ref_udata
: return "DW_FORM_ref_udata";
678 case DW_FORM_indirect
: return "DW_FORM_indirect";
679 /* DWARF 4 values. */
680 case DW_FORM_sec_offset
: return "DW_FORM_sec_offset";
681 case DW_FORM_exprloc
: return "DW_FORM_exprloc";
682 case DW_FORM_flag_present
: return "DW_FORM_flag_present";
683 case DW_FORM_ref_sig8
: return "DW_FORM_ref_sig8";
686 static char buffer
[100];
688 snprintf (buffer
, sizeof (buffer
), _("Unknown FORM value: %lx"), form
);
694 static unsigned char *
695 display_block (unsigned char *data
, dwarf_vma length
)
697 printf (_(" %s byte block: "), dwarf_vmatoa ("u", length
));
700 printf ("%lx ", (unsigned long) byte_get (data
++, 1));
706 decode_location_expression (unsigned char * data
,
707 unsigned int pointer_size
,
708 unsigned int offset_size
,
712 struct dwarf_section
* section
)
715 unsigned int bytes_read
;
717 unsigned char *end
= data
+ length
;
718 int need_frame_base
= 0;
727 printf ("DW_OP_addr: %s",
728 dwarf_vmatoa ("x", byte_get (data
, pointer_size
)));
729 data
+= pointer_size
;
732 printf ("DW_OP_deref");
735 printf ("DW_OP_const1u: %lu", (unsigned long) byte_get (data
++, 1));
738 printf ("DW_OP_const1s: %ld", (long) byte_get_signed (data
++, 1));
741 printf ("DW_OP_const2u: %lu", (unsigned long) byte_get (data
, 2));
745 printf ("DW_OP_const2s: %ld", (long) byte_get_signed (data
, 2));
749 printf ("DW_OP_const4u: %lu", (unsigned long) byte_get (data
, 4));
753 printf ("DW_OP_const4s: %ld", (long) byte_get_signed (data
, 4));
757 printf ("DW_OP_const8u: %lu %lu", (unsigned long) byte_get (data
, 4),
758 (unsigned long) byte_get (data
+ 4, 4));
762 printf ("DW_OP_const8s: %ld %ld", (long) byte_get (data
, 4),
763 (long) byte_get (data
+ 4, 4));
767 printf ("DW_OP_constu: %s",
768 dwarf_vmatoa ("u", read_leb128 (data
, &bytes_read
, 0)));
772 printf ("DW_OP_consts: %s",
773 dwarf_vmatoa ("d", read_sleb128 (data
, &bytes_read
)));
777 printf ("DW_OP_dup");
780 printf ("DW_OP_drop");
783 printf ("DW_OP_over");
786 printf ("DW_OP_pick: %ld", (unsigned long) byte_get (data
++, 1));
789 printf ("DW_OP_swap");
792 printf ("DW_OP_rot");
795 printf ("DW_OP_xderef");
798 printf ("DW_OP_abs");
801 printf ("DW_OP_and");
804 printf ("DW_OP_div");
807 printf ("DW_OP_minus");
810 printf ("DW_OP_mod");
813 printf ("DW_OP_mul");
816 printf ("DW_OP_neg");
819 printf ("DW_OP_not");
825 printf ("DW_OP_plus");
827 case DW_OP_plus_uconst
:
828 printf ("DW_OP_plus_uconst: %s",
829 dwarf_vmatoa ("u", read_leb128 (data
, &bytes_read
, 0)));
833 printf ("DW_OP_shl");
836 printf ("DW_OP_shr");
839 printf ("DW_OP_shra");
842 printf ("DW_OP_xor");
845 printf ("DW_OP_bra: %ld", (long) byte_get_signed (data
, 2));
867 printf ("DW_OP_skip: %ld", (long) byte_get_signed (data
, 2));
903 printf ("DW_OP_lit%d", op
- DW_OP_lit0
);
938 printf ("DW_OP_reg%d (%s)", op
- DW_OP_reg0
,
939 regname (op
- DW_OP_reg0
, 1));
974 printf ("DW_OP_breg%d (%s): %s",
976 regname (op
- DW_OP_breg0
, 1),
977 dwarf_vmatoa ("d", (dwarf_signed_vma
)
978 read_leb128 (data
, &bytes_read
, 1)));
983 uvalue
= read_leb128 (data
, &bytes_read
, 0);
985 printf ("DW_OP_regx: %s (%s)",
986 dwarf_vmatoa ("u", uvalue
), regname (uvalue
, 1));
990 printf ("DW_OP_fbreg: %s",
991 dwarf_vmatoa ("d", read_sleb128 (data
, &bytes_read
)));
995 uvalue
= read_leb128 (data
, &bytes_read
, 0);
997 printf ("DW_OP_bregx: %s (%s) %s",
998 dwarf_vmatoa ("u", uvalue
), regname (uvalue
, 1),
999 dwarf_vmatoa ("d", read_sleb128 (data
, &bytes_read
)));
1003 printf ("DW_OP_piece: %s",
1004 dwarf_vmatoa ("u", read_leb128 (data
, &bytes_read
, 0)));
1007 case DW_OP_deref_size
:
1008 printf ("DW_OP_deref_size: %ld", (long) byte_get (data
++, 1));
1010 case DW_OP_xderef_size
:
1011 printf ("DW_OP_xderef_size: %ld", (long) byte_get (data
++, 1));
1014 printf ("DW_OP_nop");
1017 /* DWARF 3 extensions. */
1018 case DW_OP_push_object_address
:
1019 printf ("DW_OP_push_object_address");
1022 /* XXX: Strictly speaking for 64-bit DWARF3 files
1023 this ought to be an 8-byte wide computation. */
1024 printf ("DW_OP_call2: <0x%s>",
1025 dwarf_vmatoa ("x", (dwarf_signed_vma
) byte_get (data
, 2)
1030 /* XXX: Strictly speaking for 64-bit DWARF3 files
1031 this ought to be an 8-byte wide computation. */
1032 printf ("DW_OP_call4: <0x%s>",
1033 dwarf_vmatoa ("x", (dwarf_signed_vma
) byte_get (data
, 4)
1037 case DW_OP_call_ref
:
1038 /* XXX: Strictly speaking for 64-bit DWARF3 files
1039 this ought to be an 8-byte wide computation. */
1040 if (dwarf_version
== -1)
1042 printf (_("(DW_OP_call_ref in frame info)"));
1043 /* No way to tell where the next op is, so just bail. */
1044 return need_frame_base
;
1046 if (dwarf_version
== 2)
1048 printf ("DW_OP_call_ref: <0x%s>",
1049 dwarf_vmatoa ("x", byte_get (data
, pointer_size
)));
1050 data
+= pointer_size
;
1054 printf ("DW_OP_call_ref: <0x%s>",
1055 dwarf_vmatoa ("x", byte_get (data
, offset_size
)));
1056 data
+= offset_size
;
1059 case DW_OP_form_tls_address
:
1060 printf ("DW_OP_form_tls_address");
1062 case DW_OP_call_frame_cfa
:
1063 printf ("DW_OP_call_frame_cfa");
1065 case DW_OP_bit_piece
:
1066 printf ("DW_OP_bit_piece: ");
1067 printf ("size: %s ",
1068 dwarf_vmatoa ("u", read_leb128 (data
, &bytes_read
, 0)));
1070 printf ("offset: %s ",
1071 dwarf_vmatoa ("u", read_leb128 (data
, &bytes_read
, 0)));
1075 /* DWARF 4 extensions. */
1076 case DW_OP_stack_value
:
1077 printf ("DW_OP_stack_value");
1080 case DW_OP_implicit_value
:
1081 printf ("DW_OP_implicit_value");
1082 uvalue
= read_leb128 (data
, &bytes_read
, 0);
1084 display_block (data
, uvalue
);
1088 /* GNU extensions. */
1089 case DW_OP_GNU_push_tls_address
:
1090 printf ("DW_OP_GNU_push_tls_address or DW_OP_HP_unknown");
1092 case DW_OP_GNU_uninit
:
1093 printf ("DW_OP_GNU_uninit");
1094 /* FIXME: Is there data associated with this OP ? */
1096 case DW_OP_GNU_encoded_addr
:
1102 addr
= get_encoded_value (data
, encoding
, section
);
1103 data
+= size_of_encoded_value (encoding
);
1105 printf ("DW_OP_GNU_encoded_addr: fmt:%02x addr:", encoding
);
1106 print_dwarf_vma (addr
, pointer_size
);
1109 case DW_OP_GNU_implicit_pointer
:
1110 /* XXX: Strictly speaking for 64-bit DWARF3 files
1111 this ought to be an 8-byte wide computation. */
1112 if (dwarf_version
== -1)
1114 printf (_("(DW_OP_GNU_implicit_pointer in frame info)"));
1115 /* No way to tell where the next op is, so just bail. */
1116 return need_frame_base
;
1118 if (dwarf_version
== 2)
1120 printf ("DW_OP_GNU_implicit_pointer: <0x%s> %s",
1121 dwarf_vmatoa ("x", byte_get (data
, pointer_size
)),
1122 dwarf_vmatoa ("d", read_sleb128 (data
+ pointer_size
,
1124 data
+= pointer_size
+ bytes_read
;
1128 printf ("DW_OP_GNU_implicit_pointer: <0x%s> %s",
1129 dwarf_vmatoa ("x", byte_get (data
, offset_size
)),
1130 dwarf_vmatoa ("d", read_sleb128 (data
+ offset_size
,
1132 data
+= offset_size
+ bytes_read
;
1135 case DW_OP_GNU_entry_value
:
1136 uvalue
= read_leb128 (data
, &bytes_read
, 0);
1138 printf ("DW_OP_GNU_entry_value: (");
1139 if (decode_location_expression (data
, pointer_size
, offset_size
,
1140 dwarf_version
, uvalue
,
1141 cu_offset
, section
))
1142 need_frame_base
= 1;
1146 case DW_OP_GNU_const_type
:
1147 uvalue
= read_leb128 (data
, &bytes_read
, 0);
1149 printf ("DW_OP_GNU_const_type: <0x%s> ",
1150 dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1151 uvalue
= byte_get (data
++, 1);
1152 display_block (data
, uvalue
);
1155 case DW_OP_GNU_regval_type
:
1156 uvalue
= read_leb128 (data
, &bytes_read
, 0);
1158 printf ("DW_OP_GNU_regval_type: %s (%s)",
1159 dwarf_vmatoa ("u", uvalue
), regname (uvalue
, 1));
1160 uvalue
= read_leb128 (data
, &bytes_read
, 0);
1162 printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1164 case DW_OP_GNU_deref_type
:
1165 printf ("DW_OP_GNU_deref_type: %ld", (long) byte_get (data
++, 1));
1166 uvalue
= read_leb128 (data
, &bytes_read
, 0);
1168 printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1170 case DW_OP_GNU_convert
:
1171 uvalue
= read_leb128 (data
, &bytes_read
, 0);
1173 printf ("DW_OP_GNU_convert <0x%s>",
1174 dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1176 case DW_OP_GNU_reinterpret
:
1177 uvalue
= read_leb128 (data
, &bytes_read
, 0);
1179 printf ("DW_OP_GNU_reinterpret <0x%s>",
1180 dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1183 /* HP extensions. */
1184 case DW_OP_HP_is_value
:
1185 printf ("DW_OP_HP_is_value");
1186 /* FIXME: Is there data associated with this OP ? */
1188 case DW_OP_HP_fltconst4
:
1189 printf ("DW_OP_HP_fltconst4");
1190 /* FIXME: Is there data associated with this OP ? */
1192 case DW_OP_HP_fltconst8
:
1193 printf ("DW_OP_HP_fltconst8");
1194 /* FIXME: Is there data associated with this OP ? */
1196 case DW_OP_HP_mod_range
:
1197 printf ("DW_OP_HP_mod_range");
1198 /* FIXME: Is there data associated with this OP ? */
1200 case DW_OP_HP_unmod_range
:
1201 printf ("DW_OP_HP_unmod_range");
1202 /* FIXME: Is there data associated with this OP ? */
1205 printf ("DW_OP_HP_tls");
1206 /* FIXME: Is there data associated with this OP ? */
1209 /* PGI (STMicroelectronics) extensions. */
1210 case DW_OP_PGI_omp_thread_num
:
1211 /* Pushes the thread number for the current thread as it would be
1212 returned by the standard OpenMP library function:
1213 omp_get_thread_num(). The "current thread" is the thread for
1214 which the expression is being evaluated. */
1215 printf ("DW_OP_PGI_omp_thread_num");
1219 if (op
>= DW_OP_lo_user
1220 && op
<= DW_OP_hi_user
)
1221 printf (_("(User defined location op)"));
1223 printf (_("(Unknown location op)"));
1224 /* No way to tell where the next op is, so just bail. */
1225 return need_frame_base
;
1228 /* Separate the ops. */
1233 return need_frame_base
;
1236 static unsigned char *
1237 read_and_display_attr_value (unsigned long attribute
,
1239 unsigned char * data
,
1240 dwarf_vma cu_offset
,
1241 dwarf_vma pointer_size
,
1242 dwarf_vma offset_size
,
1244 debug_info
* debug_info_p
,
1246 struct dwarf_section
* section
)
1248 dwarf_vma uvalue
= 0;
1249 unsigned char *block_start
= NULL
;
1250 unsigned char * orig_data
= data
;
1251 unsigned int bytes_read
;
1258 case DW_FORM_ref_addr
:
1259 if (dwarf_version
== 2)
1261 uvalue
= byte_get (data
, pointer_size
);
1262 data
+= pointer_size
;
1264 else if (dwarf_version
== 3 || dwarf_version
== 4)
1266 uvalue
= byte_get (data
, offset_size
);
1267 data
+= offset_size
;
1270 error (_("Internal error: DWARF version is not 2, 3 or 4.\n"));
1275 uvalue
= byte_get (data
, pointer_size
);
1276 data
+= pointer_size
;
1280 case DW_FORM_sec_offset
:
1281 uvalue
= byte_get (data
, offset_size
);
1282 data
+= offset_size
;
1285 case DW_FORM_flag_present
:
1292 uvalue
= byte_get (data
++, 1);
1297 uvalue
= byte_get (data
, 2);
1303 uvalue
= byte_get (data
, 4);
1308 uvalue
= read_leb128 (data
, & bytes_read
, 1);
1312 case DW_FORM_ref_udata
:
1314 uvalue
= read_leb128 (data
, & bytes_read
, 0);
1318 case DW_FORM_indirect
:
1319 form
= read_leb128 (data
, & bytes_read
, 0);
1322 printf (" %s", get_FORM_name (form
));
1323 return read_and_display_attr_value (attribute
, form
, data
,
1324 cu_offset
, pointer_size
,
1325 offset_size
, dwarf_version
,
1326 debug_info_p
, do_loc
,
1332 case DW_FORM_ref_addr
:
1334 printf (" <0x%s>", dwarf_vmatoa ("x",uvalue
));
1340 case DW_FORM_ref_udata
:
1342 printf (" <0x%s>", dwarf_vmatoa ("x", uvalue
+ cu_offset
));
1347 case DW_FORM_sec_offset
:
1349 printf (" 0x%s", dwarf_vmatoa ("x", uvalue
));
1352 case DW_FORM_flag_present
:
1359 printf (" %s", dwarf_vmatoa ("d", uvalue
));
1366 uvalue
= byte_get (data
, 4);
1367 printf (" 0x%s", dwarf_vmatoa ("x", uvalue
));
1368 printf (" 0x%lx", (unsigned long) byte_get (data
+ 4, 4));
1370 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
1371 && num_debug_info_entries
== 0)
1373 if (sizeof (uvalue
) == 8)
1374 uvalue
= byte_get (data
, 8);
1376 error (_("DW_FORM_data8 is unsupported when sizeof (dwarf_vma) != 8\n"));
1381 case DW_FORM_string
:
1383 printf (" %s", data
);
1384 data
+= strlen ((char *) data
) + 1;
1388 case DW_FORM_exprloc
:
1389 uvalue
= read_leb128 (data
, & bytes_read
, 0);
1390 block_start
= data
+ bytes_read
;
1392 data
= block_start
+ uvalue
;
1394 data
= display_block (block_start
, uvalue
);
1397 case DW_FORM_block1
:
1398 uvalue
= byte_get (data
, 1);
1399 block_start
= data
+ 1;
1401 data
= block_start
+ uvalue
;
1403 data
= display_block (block_start
, uvalue
);
1406 case DW_FORM_block2
:
1407 uvalue
= byte_get (data
, 2);
1408 block_start
= data
+ 2;
1410 data
= block_start
+ uvalue
;
1412 data
= display_block (block_start
, uvalue
);
1415 case DW_FORM_block4
:
1416 uvalue
= byte_get (data
, 4);
1417 block_start
= data
+ 4;
1419 data
= block_start
+ uvalue
;
1421 data
= display_block (block_start
, uvalue
);
1426 printf (_(" (indirect string, offset: 0x%s): %s"),
1427 dwarf_vmatoa ("x", uvalue
),
1428 fetch_indirect_string (uvalue
));
1431 case DW_FORM_indirect
:
1432 /* Handled above. */
1435 case DW_FORM_ref_sig8
:
1439 printf (" signature: ");
1440 for (i
= 0; i
< 8; i
++)
1442 printf ("%02x", (unsigned) byte_get (data
, 1));
1451 warn (_("Unrecognized form: %lu\n"), form
);
1455 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
1456 && num_debug_info_entries
== 0
1457 && debug_info_p
!= NULL
)
1461 case DW_AT_frame_base
:
1462 have_frame_base
= 1;
1463 case DW_AT_location
:
1464 case DW_AT_string_length
:
1465 case DW_AT_return_addr
:
1466 case DW_AT_data_member_location
:
1467 case DW_AT_vtable_elem_location
:
1469 case DW_AT_static_link
:
1470 case DW_AT_use_location
:
1471 case DW_AT_GNU_call_site_value
:
1472 case DW_AT_GNU_call_site_data_value
:
1473 case DW_AT_GNU_call_site_target
:
1474 case DW_AT_GNU_call_site_target_clobbered
:
1475 if (form
== DW_FORM_data4
1476 || form
== DW_FORM_data8
1477 || form
== DW_FORM_sec_offset
)
1479 /* Process location list. */
1480 unsigned int lmax
= debug_info_p
->max_loc_offsets
;
1481 unsigned int num
= debug_info_p
->num_loc_offsets
;
1483 if (lmax
== 0 || num
>= lmax
)
1486 debug_info_p
->loc_offsets
= (dwarf_vma
*)
1487 xcrealloc (debug_info_p
->loc_offsets
,
1488 lmax
, sizeof (*debug_info_p
->loc_offsets
));
1489 debug_info_p
->have_frame_base
= (int *)
1490 xcrealloc (debug_info_p
->have_frame_base
,
1491 lmax
, sizeof (*debug_info_p
->have_frame_base
));
1492 debug_info_p
->max_loc_offsets
= lmax
;
1494 debug_info_p
->loc_offsets
[num
] = uvalue
;
1495 debug_info_p
->have_frame_base
[num
] = have_frame_base
;
1496 debug_info_p
->num_loc_offsets
++;
1501 if (need_base_address
)
1502 debug_info_p
->base_address
= uvalue
;
1506 if (form
== DW_FORM_data4
1507 || form
== DW_FORM_data8
1508 || form
== DW_FORM_sec_offset
)
1510 /* Process range list. */
1511 unsigned int lmax
= debug_info_p
->max_range_lists
;
1512 unsigned int num
= debug_info_p
->num_range_lists
;
1514 if (lmax
== 0 || num
>= lmax
)
1517 debug_info_p
->range_lists
= (dwarf_vma
*)
1518 xcrealloc (debug_info_p
->range_lists
,
1519 lmax
, sizeof (*debug_info_p
->range_lists
));
1520 debug_info_p
->max_range_lists
= lmax
;
1522 debug_info_p
->range_lists
[num
] = uvalue
;
1523 debug_info_p
->num_range_lists
++;
1535 /* For some attributes we can display further information. */
1543 case DW_INL_not_inlined
:
1544 printf (_("(not inlined)"));
1546 case DW_INL_inlined
:
1547 printf (_("(inlined)"));
1549 case DW_INL_declared_not_inlined
:
1550 printf (_("(declared as inline but ignored)"));
1552 case DW_INL_declared_inlined
:
1553 printf (_("(declared as inline and inlined)"));
1556 printf (_(" (Unknown inline attribute value: %s)"),
1557 dwarf_vmatoa ("x", uvalue
));
1562 case DW_AT_language
:
1565 /* Ordered by the numeric value of these constants. */
1566 case DW_LANG_C89
: printf ("(ANSI C)"); break;
1567 case DW_LANG_C
: printf ("(non-ANSI C)"); break;
1568 case DW_LANG_Ada83
: printf ("(Ada)"); break;
1569 case DW_LANG_C_plus_plus
: printf ("(C++)"); break;
1570 case DW_LANG_Cobol74
: printf ("(Cobol 74)"); break;
1571 case DW_LANG_Cobol85
: printf ("(Cobol 85)"); break;
1572 case DW_LANG_Fortran77
: printf ("(FORTRAN 77)"); break;
1573 case DW_LANG_Fortran90
: printf ("(Fortran 90)"); break;
1574 case DW_LANG_Pascal83
: printf ("(ANSI Pascal)"); break;
1575 case DW_LANG_Modula2
: printf ("(Modula 2)"); break;
1576 /* DWARF 2.1 values. */
1577 case DW_LANG_Java
: printf ("(Java)"); break;
1578 case DW_LANG_C99
: printf ("(ANSI C99)"); break;
1579 case DW_LANG_Ada95
: printf ("(ADA 95)"); break;
1580 case DW_LANG_Fortran95
: printf ("(Fortran 95)"); break;
1581 /* DWARF 3 values. */
1582 case DW_LANG_PLI
: printf ("(PLI)"); break;
1583 case DW_LANG_ObjC
: printf ("(Objective C)"); break;
1584 case DW_LANG_ObjC_plus_plus
: printf ("(Objective C++)"); break;
1585 case DW_LANG_UPC
: printf ("(Unified Parallel C)"); break;
1586 case DW_LANG_D
: printf ("(D)"); break;
1587 /* DWARF 4 values. */
1588 case DW_LANG_Python
: printf ("(Python)"); break;
1589 /* MIPS extension. */
1590 case DW_LANG_Mips_Assembler
: printf ("(MIPS assembler)"); break;
1591 /* UPC extension. */
1592 case DW_LANG_Upc
: printf ("(Unified Parallel C)"); break;
1594 if (uvalue
>= DW_LANG_lo_user
&& uvalue
<= DW_LANG_hi_user
)
1595 printf ("(implementation defined: %s)",
1596 dwarf_vmatoa ("x", uvalue
));
1598 printf ("(Unknown: %s)", dwarf_vmatoa ("x", uvalue
));
1603 case DW_AT_encoding
:
1606 case DW_ATE_void
: printf ("(void)"); break;
1607 case DW_ATE_address
: printf ("(machine address)"); break;
1608 case DW_ATE_boolean
: printf ("(boolean)"); break;
1609 case DW_ATE_complex_float
: printf ("(complex float)"); break;
1610 case DW_ATE_float
: printf ("(float)"); break;
1611 case DW_ATE_signed
: printf ("(signed)"); break;
1612 case DW_ATE_signed_char
: printf ("(signed char)"); break;
1613 case DW_ATE_unsigned
: printf ("(unsigned)"); break;
1614 case DW_ATE_unsigned_char
: printf ("(unsigned char)"); break;
1615 /* DWARF 2.1 values: */
1616 case DW_ATE_imaginary_float
: printf ("(imaginary float)"); break;
1617 case DW_ATE_decimal_float
: printf ("(decimal float)"); break;
1618 /* DWARF 3 values: */
1619 case DW_ATE_packed_decimal
: printf ("(packed_decimal)"); break;
1620 case DW_ATE_numeric_string
: printf ("(numeric_string)"); break;
1621 case DW_ATE_edited
: printf ("(edited)"); break;
1622 case DW_ATE_signed_fixed
: printf ("(signed_fixed)"); break;
1623 case DW_ATE_unsigned_fixed
: printf ("(unsigned_fixed)"); break;
1624 /* HP extensions: */
1625 case DW_ATE_HP_float80
: printf ("(HP_float80)"); break;
1626 case DW_ATE_HP_complex_float80
: printf ("(HP_complex_float80)"); break;
1627 case DW_ATE_HP_float128
: printf ("(HP_float128)"); break;
1628 case DW_ATE_HP_complex_float128
:printf ("(HP_complex_float128)"); break;
1629 case DW_ATE_HP_floathpintel
: printf ("(HP_floathpintel)"); break;
1630 case DW_ATE_HP_imaginary_float80
: printf ("(HP_imaginary_float80)"); break;
1631 case DW_ATE_HP_imaginary_float128
: printf ("(HP_imaginary_float128)"); break;
1634 if (uvalue
>= DW_ATE_lo_user
1635 && uvalue
<= DW_ATE_hi_user
)
1636 printf ("(user defined type)");
1638 printf ("(unknown type)");
1643 case DW_AT_accessibility
:
1646 case DW_ACCESS_public
: printf ("(public)"); break;
1647 case DW_ACCESS_protected
: printf ("(protected)"); break;
1648 case DW_ACCESS_private
: printf ("(private)"); break;
1650 printf ("(unknown accessibility)");
1655 case DW_AT_visibility
:
1658 case DW_VIS_local
: printf ("(local)"); break;
1659 case DW_VIS_exported
: printf ("(exported)"); break;
1660 case DW_VIS_qualified
: printf ("(qualified)"); break;
1661 default: printf ("(unknown visibility)"); break;
1665 case DW_AT_virtuality
:
1668 case DW_VIRTUALITY_none
: printf ("(none)"); break;
1669 case DW_VIRTUALITY_virtual
: printf ("(virtual)"); break;
1670 case DW_VIRTUALITY_pure_virtual
:printf ("(pure_virtual)"); break;
1671 default: printf ("(unknown virtuality)"); break;
1675 case DW_AT_identifier_case
:
1678 case DW_ID_case_sensitive
: printf ("(case_sensitive)"); break;
1679 case DW_ID_up_case
: printf ("(up_case)"); break;
1680 case DW_ID_down_case
: printf ("(down_case)"); break;
1681 case DW_ID_case_insensitive
: printf ("(case_insensitive)"); break;
1682 default: printf ("(unknown case)"); break;
1686 case DW_AT_calling_convention
:
1689 case DW_CC_normal
: printf ("(normal)"); break;
1690 case DW_CC_program
: printf ("(program)"); break;
1691 case DW_CC_nocall
: printf ("(nocall)"); break;
1693 if (uvalue
>= DW_CC_lo_user
1694 && uvalue
<= DW_CC_hi_user
)
1695 printf ("(user defined)");
1697 printf ("(unknown convention)");
1701 case DW_AT_ordering
:
1704 case -1: printf ("(undefined)"); break;
1705 case 0: printf ("(row major)"); break;
1706 case 1: printf ("(column major)"); break;
1710 case DW_AT_frame_base
:
1711 have_frame_base
= 1;
1712 case DW_AT_location
:
1713 case DW_AT_string_length
:
1714 case DW_AT_return_addr
:
1715 case DW_AT_data_member_location
:
1716 case DW_AT_vtable_elem_location
:
1718 case DW_AT_static_link
:
1719 case DW_AT_use_location
:
1720 case DW_AT_GNU_call_site_value
:
1721 case DW_AT_GNU_call_site_data_value
:
1722 case DW_AT_GNU_call_site_target
:
1723 case DW_AT_GNU_call_site_target_clobbered
:
1724 if (form
== DW_FORM_data4
1725 || form
== DW_FORM_data8
1726 || form
== DW_FORM_sec_offset
)
1727 printf (_("(location list)"));
1729 case DW_AT_allocated
:
1730 case DW_AT_associated
:
1731 case DW_AT_data_location
:
1733 case DW_AT_upper_bound
:
1734 case DW_AT_lower_bound
:
1737 int need_frame_base
;
1740 need_frame_base
= decode_location_expression (block_start
,
1745 cu_offset
, section
);
1747 if (need_frame_base
&& !have_frame_base
)
1748 printf (_(" [without DW_AT_frame_base]"));
1754 if (form
== DW_FORM_ref_sig8
)
1757 if (form
== DW_FORM_ref1
1758 || form
== DW_FORM_ref2
1759 || form
== DW_FORM_ref4
)
1760 uvalue
+= cu_offset
;
1762 if (uvalue
>= section
->size
)
1763 warn (_("Offset %s used as value for DW_AT_import attribute of DIE at offset %lx is too big.\n"),
1764 dwarf_vmatoa ("x", uvalue
),
1765 (unsigned long) (orig_data
- section
->start
));
1768 unsigned long abbrev_number
;
1769 abbrev_entry
* entry
;
1771 abbrev_number
= read_leb128 (section
->start
+ uvalue
, NULL
, 0);
1773 printf ("[Abbrev Number: %ld", abbrev_number
);
1774 for (entry
= first_abbrev
; entry
!= NULL
; entry
= entry
->next
)
1775 if (entry
->entry
== abbrev_number
)
1778 printf (" (%s)", get_TAG_name (entry
->tag
));
1792 get_AT_name (unsigned long attribute
)
1796 case DW_AT_sibling
: return "DW_AT_sibling";
1797 case DW_AT_location
: return "DW_AT_location";
1798 case DW_AT_name
: return "DW_AT_name";
1799 case DW_AT_ordering
: return "DW_AT_ordering";
1800 case DW_AT_subscr_data
: return "DW_AT_subscr_data";
1801 case DW_AT_byte_size
: return "DW_AT_byte_size";
1802 case DW_AT_bit_offset
: return "DW_AT_bit_offset";
1803 case DW_AT_bit_size
: return "DW_AT_bit_size";
1804 case DW_AT_element_list
: return "DW_AT_element_list";
1805 case DW_AT_stmt_list
: return "DW_AT_stmt_list";
1806 case DW_AT_low_pc
: return "DW_AT_low_pc";
1807 case DW_AT_high_pc
: return "DW_AT_high_pc";
1808 case DW_AT_language
: return "DW_AT_language";
1809 case DW_AT_member
: return "DW_AT_member";
1810 case DW_AT_discr
: return "DW_AT_discr";
1811 case DW_AT_discr_value
: return "DW_AT_discr_value";
1812 case DW_AT_visibility
: return "DW_AT_visibility";
1813 case DW_AT_import
: return "DW_AT_import";
1814 case DW_AT_string_length
: return "DW_AT_string_length";
1815 case DW_AT_common_reference
: return "DW_AT_common_reference";
1816 case DW_AT_comp_dir
: return "DW_AT_comp_dir";
1817 case DW_AT_const_value
: return "DW_AT_const_value";
1818 case DW_AT_containing_type
: return "DW_AT_containing_type";
1819 case DW_AT_default_value
: return "DW_AT_default_value";
1820 case DW_AT_inline
: return "DW_AT_inline";
1821 case DW_AT_is_optional
: return "DW_AT_is_optional";
1822 case DW_AT_lower_bound
: return "DW_AT_lower_bound";
1823 case DW_AT_producer
: return "DW_AT_producer";
1824 case DW_AT_prototyped
: return "DW_AT_prototyped";
1825 case DW_AT_return_addr
: return "DW_AT_return_addr";
1826 case DW_AT_start_scope
: return "DW_AT_start_scope";
1827 case DW_AT_stride_size
: return "DW_AT_stride_size";
1828 case DW_AT_upper_bound
: return "DW_AT_upper_bound";
1829 case DW_AT_abstract_origin
: return "DW_AT_abstract_origin";
1830 case DW_AT_accessibility
: return "DW_AT_accessibility";
1831 case DW_AT_address_class
: return "DW_AT_address_class";
1832 case DW_AT_artificial
: return "DW_AT_artificial";
1833 case DW_AT_base_types
: return "DW_AT_base_types";
1834 case DW_AT_calling_convention
: return "DW_AT_calling_convention";
1835 case DW_AT_count
: return "DW_AT_count";
1836 case DW_AT_data_member_location
: return "DW_AT_data_member_location";
1837 case DW_AT_decl_column
: return "DW_AT_decl_column";
1838 case DW_AT_decl_file
: return "DW_AT_decl_file";
1839 case DW_AT_decl_line
: return "DW_AT_decl_line";
1840 case DW_AT_declaration
: return "DW_AT_declaration";
1841 case DW_AT_discr_list
: return "DW_AT_discr_list";
1842 case DW_AT_encoding
: return "DW_AT_encoding";
1843 case DW_AT_external
: return "DW_AT_external";
1844 case DW_AT_frame_base
: return "DW_AT_frame_base";
1845 case DW_AT_friend
: return "DW_AT_friend";
1846 case DW_AT_identifier_case
: return "DW_AT_identifier_case";
1847 case DW_AT_macro_info
: return "DW_AT_macro_info";
1848 case DW_AT_namelist_items
: return "DW_AT_namelist_items";
1849 case DW_AT_priority
: return "DW_AT_priority";
1850 case DW_AT_segment
: return "DW_AT_segment";
1851 case DW_AT_specification
: return "DW_AT_specification";
1852 case DW_AT_static_link
: return "DW_AT_static_link";
1853 case DW_AT_type
: return "DW_AT_type";
1854 case DW_AT_use_location
: return "DW_AT_use_location";
1855 case DW_AT_variable_parameter
: return "DW_AT_variable_parameter";
1856 case DW_AT_virtuality
: return "DW_AT_virtuality";
1857 case DW_AT_vtable_elem_location
: return "DW_AT_vtable_elem_location";
1858 /* DWARF 2.1 values. */
1859 case DW_AT_allocated
: return "DW_AT_allocated";
1860 case DW_AT_associated
: return "DW_AT_associated";
1861 case DW_AT_data_location
: return "DW_AT_data_location";
1862 case DW_AT_stride
: return "DW_AT_stride";
1863 case DW_AT_entry_pc
: return "DW_AT_entry_pc";
1864 case DW_AT_use_UTF8
: return "DW_AT_use_UTF8";
1865 case DW_AT_extension
: return "DW_AT_extension";
1866 case DW_AT_ranges
: return "DW_AT_ranges";
1867 case DW_AT_trampoline
: return "DW_AT_trampoline";
1868 case DW_AT_call_column
: return "DW_AT_call_column";
1869 case DW_AT_call_file
: return "DW_AT_call_file";
1870 case DW_AT_call_line
: return "DW_AT_call_line";
1871 case DW_AT_description
: return "DW_AT_description";
1872 case DW_AT_binary_scale
: return "DW_AT_binary_scale";
1873 case DW_AT_decimal_scale
: return "DW_AT_decimal_scale";
1874 case DW_AT_small
: return "DW_AT_small";
1875 case DW_AT_decimal_sign
: return "DW_AT_decimal_sign";
1876 case DW_AT_digit_count
: return "DW_AT_digit_count";
1877 case DW_AT_picture_string
: return "DW_AT_picture_string";
1878 case DW_AT_mutable
: return "DW_AT_mutable";
1879 case DW_AT_threads_scaled
: return "DW_AT_threads_scaled";
1880 case DW_AT_explicit
: return "DW_AT_explicit";
1881 case DW_AT_object_pointer
: return "DW_AT_object_pointer";
1882 case DW_AT_endianity
: return "DW_AT_endianity";
1883 case DW_AT_elemental
: return "DW_AT_elemental";
1884 case DW_AT_pure
: return "DW_AT_pure";
1885 case DW_AT_recursive
: return "DW_AT_recursive";
1886 /* DWARF 4 values. */
1887 case DW_AT_signature
: return "DW_AT_signature";
1888 case DW_AT_main_subprogram
: return "DW_AT_main_subprogram";
1889 case DW_AT_data_bit_offset
: return "DW_AT_data_bit_offset";
1890 case DW_AT_const_expr
: return "DW_AT_const_expr";
1891 case DW_AT_enum_class
: return "DW_AT_enum_class";
1892 case DW_AT_linkage_name
: return "DW_AT_linkage_name";
1894 /* HP and SGI/MIPS extensions. */
1895 case DW_AT_MIPS_loop_begin
: return "DW_AT_MIPS_loop_begin";
1896 case DW_AT_MIPS_tail_loop_begin
: return "DW_AT_MIPS_tail_loop_begin";
1897 case DW_AT_MIPS_epilog_begin
: return "DW_AT_MIPS_epilog_begin";
1898 case DW_AT_MIPS_loop_unroll_factor
: return "DW_AT_MIPS_loop_unroll_factor";
1899 case DW_AT_MIPS_software_pipeline_depth
: return "DW_AT_MIPS_software_pipeline_depth";
1900 case DW_AT_MIPS_linkage_name
: return "DW_AT_MIPS_linkage_name";
1901 case DW_AT_MIPS_stride
: return "DW_AT_MIPS_stride";
1902 case DW_AT_MIPS_abstract_name
: return "DW_AT_MIPS_abstract_name";
1903 case DW_AT_MIPS_clone_origin
: return "DW_AT_MIPS_clone_origin";
1904 case DW_AT_MIPS_has_inlines
: return "DW_AT_MIPS_has_inlines";
1906 /* HP Extensions. */
1907 case DW_AT_HP_block_index
: return "DW_AT_HP_block_index";
1908 case DW_AT_HP_actuals_stmt_list
: return "DW_AT_HP_actuals_stmt_list";
1909 case DW_AT_HP_proc_per_section
: return "DW_AT_HP_proc_per_section";
1910 case DW_AT_HP_raw_data_ptr
: return "DW_AT_HP_raw_data_ptr";
1911 case DW_AT_HP_pass_by_reference
: return "DW_AT_HP_pass_by_reference";
1912 case DW_AT_HP_opt_level
: return "DW_AT_HP_opt_level";
1913 case DW_AT_HP_prof_version_id
: return "DW_AT_HP_prof_version_id";
1914 case DW_AT_HP_opt_flags
: return "DW_AT_HP_opt_flags";
1915 case DW_AT_HP_cold_region_low_pc
: return "DW_AT_HP_cold_region_low_pc";
1916 case DW_AT_HP_cold_region_high_pc
: return "DW_AT_HP_cold_region_high_pc";
1917 case DW_AT_HP_all_variables_modifiable
: return "DW_AT_HP_all_variables_modifiable";
1918 case DW_AT_HP_linkage_name
: return "DW_AT_HP_linkage_name";
1919 case DW_AT_HP_prof_flags
: return "DW_AT_HP_prof_flags";
1921 /* One value is shared by the MIPS and HP extensions: */
1922 case DW_AT_MIPS_fde
: return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable";
1924 /* GNU extensions. */
1925 case DW_AT_sf_names
: return "DW_AT_sf_names";
1926 case DW_AT_src_info
: return "DW_AT_src_info";
1927 case DW_AT_mac_info
: return "DW_AT_mac_info";
1928 case DW_AT_src_coords
: return "DW_AT_src_coords";
1929 case DW_AT_body_begin
: return "DW_AT_body_begin";
1930 case DW_AT_body_end
: return "DW_AT_body_end";
1931 case DW_AT_GNU_vector
: return "DW_AT_GNU_vector";
1932 case DW_AT_GNU_guarded_by
: return "DW_AT_GNU_guarded_by";
1933 case DW_AT_GNU_pt_guarded_by
: return "DW_AT_GNU_pt_guarded_by";
1934 case DW_AT_GNU_guarded
: return "DW_AT_GNU_guarded";
1935 case DW_AT_GNU_pt_guarded
: return "DW_AT_GNU_pt_guarded";
1936 case DW_AT_GNU_locks_excluded
: return "DW_AT_GNU_locks_excluded";
1937 case DW_AT_GNU_exclusive_locks_required
: return "DW_AT_GNU_exclusive_locks_required";
1938 case DW_AT_GNU_shared_locks_required
: return "DW_AT_GNU_shared_locks_required";
1939 case DW_AT_GNU_odr_signature
: return "DW_AT_GNU_odr_signature";
1940 case DW_AT_use_GNAT_descriptive_type
: return "DW_AT_use_GNAT_descriptive_type";
1941 case DW_AT_GNAT_descriptive_type
: return "DW_AT_GNAT_descriptive_type";
1942 case DW_AT_GNU_call_site_value
: return "DW_AT_GNU_call_site_value";
1943 case DW_AT_GNU_call_site_data_value
: return "DW_AT_GNU_call_site_data_value";
1944 case DW_AT_GNU_call_site_target
: return "DW_AT_GNU_call_site_target";
1945 case DW_AT_GNU_call_site_target_clobbered
: return "DW_AT_GNU_call_site_target_clobbered";
1946 case DW_AT_GNU_tail_call
: return "DW_AT_GNU_tail_call";
1947 case DW_AT_GNU_all_tail_call_sites
: return "DW_AT_GNU_all_tail_call_sites";
1948 case DW_AT_GNU_all_call_sites
: return "DW_AT_GNU_all_call_sites";
1949 case DW_AT_GNU_all_source_call_sites
: return "DW_AT_GNU_all_source_call_sites";
1951 /* UPC extension. */
1952 case DW_AT_upc_threads_scaled
: return "DW_AT_upc_threads_scaled";
1954 /* PGI (STMicroelectronics) extensions. */
1955 case DW_AT_PGI_lbase
: return "DW_AT_PGI_lbase";
1956 case DW_AT_PGI_soffset
: return "DW_AT_PGI_soffset";
1957 case DW_AT_PGI_lstride
: return "DW_AT_PGI_lstride";
1961 static char buffer
[100];
1963 snprintf (buffer
, sizeof (buffer
), _("Unknown AT value: %lx"),
1970 static unsigned char *
1971 read_and_display_attr (unsigned long attribute
,
1973 unsigned char * data
,
1974 dwarf_vma cu_offset
,
1975 dwarf_vma pointer_size
,
1976 dwarf_vma offset_size
,
1978 debug_info
* debug_info_p
,
1980 struct dwarf_section
* section
)
1983 printf (" %-18s:", get_AT_name (attribute
));
1984 data
= read_and_display_attr_value (attribute
, form
, data
, cu_offset
,
1985 pointer_size
, offset_size
,
1986 dwarf_version
, debug_info_p
,
1994 /* Process the contents of a .debug_info section. If do_loc is non-zero
1995 then we are scanning for location lists and we do not want to display
1996 anything to the user. If do_types is non-zero, we are processing
1997 a .debug_types section instead of a .debug_info section. */
2000 process_debug_info (struct dwarf_section
*section
,
2002 enum dwarf_section_display_enum abbrev_sec
,
2006 unsigned char *start
= section
->start
;
2007 unsigned char *end
= start
+ section
->size
;
2008 unsigned char *section_begin
;
2010 unsigned int num_units
= 0;
2012 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
2013 && num_debug_info_entries
== 0
2018 /* First scan the section to get the number of comp units. */
2019 for (section_begin
= start
, num_units
= 0; section_begin
< end
;
2022 /* Read the first 4 bytes. For a 32-bit DWARF section, this
2023 will be the length. For a 64-bit DWARF section, it'll be
2024 the escape code 0xffffffff followed by an 8 byte length. */
2025 length
= byte_get (section_begin
, 4);
2027 if (length
== 0xffffffff)
2029 length
= byte_get (section_begin
+ 4, 8);
2030 section_begin
+= length
+ 12;
2032 else if (length
>= 0xfffffff0 && length
< 0xffffffff)
2034 warn (_("Reserved length value (0x%s) found in section %s\n"),
2035 dwarf_vmatoa ("x", length
), section
->name
);
2039 section_begin
+= length
+ 4;
2041 /* Negative values are illegal, they may even cause infinite
2042 looping. This can happen if we can't accurately apply
2043 relocations to an object file. */
2044 if ((signed long) length
<= 0)
2046 warn (_("Corrupt unit length (0x%s) found in section %s\n"),
2047 dwarf_vmatoa ("x", length
), section
->name
);
2054 error (_("No comp units in %s section ?"), section
->name
);
2058 /* Then allocate an array to hold the information. */
2059 debug_information
= (debug_info
*) cmalloc (num_units
,
2060 sizeof (* debug_information
));
2061 if (debug_information
== NULL
)
2063 error (_("Not enough memory for a debug info array of %u entries"),
2071 if (dwarf_start_die
== 0)
2072 printf (_("Contents of the %s section:\n\n"), section
->name
);
2074 load_debug_section (str
, file
);
2077 load_debug_section (abbrev_sec
, file
);
2078 if (debug_displays
[abbrev_sec
].section
.start
== NULL
)
2080 warn (_("Unable to locate %s section!\n"),
2081 debug_displays
[abbrev_sec
].section
.name
);
2085 for (section_begin
= start
, unit
= 0; start
< end
; unit
++)
2087 DWARF2_Internal_CompUnit compunit
;
2088 unsigned char *hdrptr
;
2089 unsigned char *tags
;
2090 int level
, last_level
, saved_level
;
2091 dwarf_vma cu_offset
;
2093 int initial_length_size
;
2094 unsigned char signature
[8] = { 0 };
2095 dwarf_vma type_offset
= 0;
2099 compunit
.cu_length
= byte_get (hdrptr
, 4);
2102 if (compunit
.cu_length
== 0xffffffff)
2104 compunit
.cu_length
= byte_get (hdrptr
, 8);
2107 initial_length_size
= 12;
2112 initial_length_size
= 4;
2115 compunit
.cu_version
= byte_get (hdrptr
, 2);
2118 cu_offset
= start
- section_begin
;
2120 compunit
.cu_abbrev_offset
= byte_get (hdrptr
, offset_size
);
2121 hdrptr
+= offset_size
;
2123 compunit
.cu_pointer_size
= byte_get (hdrptr
, 1);
2130 for (i
= 0; i
< 8; i
++)
2132 signature
[i
] = byte_get (hdrptr
, 1);
2136 type_offset
= byte_get (hdrptr
, offset_size
);
2137 hdrptr
+= offset_size
;
2140 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
2141 && num_debug_info_entries
== 0
2144 debug_information
[unit
].cu_offset
= cu_offset
;
2145 debug_information
[unit
].pointer_size
2146 = compunit
.cu_pointer_size
;
2147 debug_information
[unit
].offset_size
= offset_size
;
2148 debug_information
[unit
].dwarf_version
= compunit
.cu_version
;
2149 debug_information
[unit
].base_address
= 0;
2150 debug_information
[unit
].loc_offsets
= NULL
;
2151 debug_information
[unit
].have_frame_base
= NULL
;
2152 debug_information
[unit
].max_loc_offsets
= 0;
2153 debug_information
[unit
].num_loc_offsets
= 0;
2154 debug_information
[unit
].range_lists
= NULL
;
2155 debug_information
[unit
].max_range_lists
= 0;
2156 debug_information
[unit
].num_range_lists
= 0;
2159 if (!do_loc
&& dwarf_start_die
== 0)
2161 printf (_(" Compilation Unit @ offset 0x%s:\n"),
2162 dwarf_vmatoa ("x", cu_offset
));
2163 printf (_(" Length: 0x%s (%s)\n"),
2164 dwarf_vmatoa ("x", compunit
.cu_length
),
2165 offset_size
== 8 ? "64-bit" : "32-bit");
2166 printf (_(" Version: %d\n"), compunit
.cu_version
);
2167 printf (_(" Abbrev Offset: %s\n"),
2168 dwarf_vmatoa ("d", compunit
.cu_abbrev_offset
));
2169 printf (_(" Pointer Size: %d\n"), compunit
.cu_pointer_size
);
2173 printf (_(" Signature: "));
2174 for (i
= 0; i
< 8; i
++)
2175 printf ("%02x", signature
[i
]);
2177 printf (_(" Type Offset: 0x%s\n"),
2178 dwarf_vmatoa ("x", type_offset
));
2182 if (cu_offset
+ compunit
.cu_length
+ initial_length_size
2185 warn (_("Debug info is corrupted, length of CU at %s"
2186 " extends beyond end of section (length = %s)\n"),
2187 dwarf_vmatoa ("x", cu_offset
),
2188 dwarf_vmatoa ("x", compunit
.cu_length
));
2192 start
+= compunit
.cu_length
+ initial_length_size
;
2194 if (compunit
.cu_version
!= 2
2195 && compunit
.cu_version
!= 3
2196 && compunit
.cu_version
!= 4)
2198 warn (_("CU at offset %s contains corrupt or "
2199 "unsupported version number: %d.\n"),
2200 dwarf_vmatoa ("x", cu_offset
), compunit
.cu_version
);
2206 /* Process the abbrevs used by this compilation unit. DWARF
2207 sections under Mach-O have non-zero addresses. */
2208 if (compunit
.cu_abbrev_offset
>= debug_displays
[abbrev_sec
].section
.size
)
2209 warn (_("Debug info is corrupted, abbrev offset (%lx) is larger than abbrev section size (%lx)\n"),
2210 (unsigned long) compunit
.cu_abbrev_offset
,
2211 (unsigned long) debug_displays
[abbrev_sec
].section
.size
);
2213 process_abbrev_section
2214 ((unsigned char *) debug_displays
[abbrev_sec
].section
.start
2215 + compunit
.cu_abbrev_offset
,
2216 (unsigned char *) debug_displays
[abbrev_sec
].section
.start
2217 + debug_displays
[abbrev_sec
].section
.size
);
2222 while (tags
< start
)
2224 unsigned int bytes_read
;
2225 unsigned long abbrev_number
;
2226 unsigned long die_offset
;
2227 abbrev_entry
*entry
;
2229 int do_printing
= 1;
2231 die_offset
= tags
- section_begin
;
2233 abbrev_number
= read_leb128 (tags
, & bytes_read
, 0);
2236 /* A null DIE marks the end of a list of siblings or it may also be
2237 a section padding. */
2238 if (abbrev_number
== 0)
2240 /* Check if it can be a section padding for the last CU. */
2241 if (level
== 0 && start
== end
)
2245 for (chk
= tags
; chk
< start
; chk
++)
2255 static unsigned num_bogus_warns
= 0;
2257 if (num_bogus_warns
< 3)
2259 warn (_("Bogus end-of-siblings marker detected at offset %lx in .debug_info section\n"),
2262 if (num_bogus_warns
== 3)
2263 warn (_("Further warnings about bogus end-of-sibling markers suppressed\n"));
2266 if (dwarf_start_die
!= 0 && level
< saved_level
)
2273 if (dwarf_start_die
!= 0 && die_offset
< dwarf_start_die
)
2277 if (dwarf_start_die
!= 0 && die_offset
== dwarf_start_die
)
2278 saved_level
= level
;
2279 do_printing
= (dwarf_cutoff_level
== -1
2280 || level
< dwarf_cutoff_level
);
2282 printf (_(" <%d><%lx>: Abbrev Number: %lu"),
2283 level
, die_offset
, abbrev_number
);
2284 else if (dwarf_cutoff_level
== -1
2285 || last_level
< dwarf_cutoff_level
)
2286 printf (_(" <%d><%lx>: ...\n"), level
, die_offset
);
2291 /* Scan through the abbreviation list until we reach the
2293 for (entry
= first_abbrev
;
2294 entry
&& entry
->entry
!= abbrev_number
;
2295 entry
= entry
->next
)
2300 if (!do_loc
&& do_printing
)
2305 warn (_("DIE at offset %lx refers to abbreviation number %lu which does not exist\n"),
2306 die_offset
, abbrev_number
);
2310 if (!do_loc
&& do_printing
)
2311 printf (" (%s)\n", get_TAG_name (entry
->tag
));
2316 need_base_address
= 0;
2318 case DW_TAG_compile_unit
:
2319 need_base_address
= 1;
2321 case DW_TAG_entry_point
:
2322 case DW_TAG_subprogram
:
2323 need_base_address
= 0;
2324 /* Assuming that there is no DW_AT_frame_base. */
2325 have_frame_base
= 0;
2329 for (attr
= entry
->first_attr
; attr
; attr
= attr
->next
)
2333 if (! do_loc
&& do_printing
)
2334 /* Show the offset from where the tag was extracted. */
2335 printf (" <%lx>", (unsigned long)(tags
- section_begin
));
2337 arg
= debug_information
;
2338 if (debug_information
)
2341 tags
= read_and_display_attr (attr
->attribute
,
2344 compunit
.cu_pointer_size
,
2346 compunit
.cu_version
,
2348 do_loc
|| ! do_printing
, section
);
2351 if (entry
->children
)
2356 /* Set num_debug_info_entries here so that it can be used to check if
2357 we need to process .debug_loc and .debug_ranges sections. */
2358 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
2359 && num_debug_info_entries
== 0
2361 num_debug_info_entries
= num_units
;
2369 /* Locate and scan the .debug_info section in the file and record the pointer
2370 sizes and offsets for the compilation units in it. Usually an executable
2371 will have just one pointer size, but this is not guaranteed, and so we try
2372 not to make any assumptions. Returns zero upon failure, or the number of
2373 compilation units upon success. */
2376 load_debug_info (void * file
)
2378 /* Reset the last pointer size so that we can issue correct error
2379 messages if we are displaying the contents of more than one section. */
2380 last_pointer_size
= 0;
2381 warned_about_missing_comp_units
= FALSE
;
2383 /* If we have already tried and failed to load the .debug_info
2384 section then do not bother to repear the task. */
2385 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
2388 /* If we already have the information there is nothing else to do. */
2389 if (num_debug_info_entries
> 0)
2390 return num_debug_info_entries
;
2392 if (load_debug_section (info
, file
)
2393 && process_debug_info (&debug_displays
[info
].section
, file
, abbrev
, 1, 0))
2394 return num_debug_info_entries
;
2396 num_debug_info_entries
= DEBUG_INFO_UNAVAILABLE
;
2401 display_debug_lines_raw (struct dwarf_section
*section
,
2402 unsigned char *data
,
2405 unsigned char *start
= section
->start
;
2407 printf (_("Raw dump of debug contents of section %s:\n\n"),
2412 DWARF2_Internal_LineInfo linfo
;
2413 unsigned char *standard_opcodes
;
2414 unsigned char *end_of_sequence
;
2415 unsigned char *hdrptr
;
2416 unsigned long hdroff
;
2417 int initial_length_size
;
2422 hdroff
= hdrptr
- start
;
2424 /* Check the length of the block. */
2425 linfo
.li_length
= byte_get (hdrptr
, 4);
2428 if (linfo
.li_length
== 0xffffffff)
2430 /* This section is 64-bit DWARF 3. */
2431 linfo
.li_length
= byte_get (hdrptr
, 8);
2434 initial_length_size
= 12;
2439 initial_length_size
= 4;
2442 if (linfo
.li_length
+ initial_length_size
> section
->size
)
2445 (_("The information in section %s appears to be corrupt - the section is too small\n"),
2450 /* Check its version number. */
2451 linfo
.li_version
= byte_get (hdrptr
, 2);
2453 if (linfo
.li_version
!= 2
2454 && linfo
.li_version
!= 3
2455 && linfo
.li_version
!= 4)
2457 warn (_("Only DWARF version 2, 3 and 4 line info is currently supported.\n"));
2461 linfo
.li_prologue_length
= byte_get (hdrptr
, offset_size
);
2462 hdrptr
+= offset_size
;
2463 linfo
.li_min_insn_length
= byte_get (hdrptr
, 1);
2465 if (linfo
.li_version
>= 4)
2467 linfo
.li_max_ops_per_insn
= byte_get (hdrptr
, 1);
2469 if (linfo
.li_max_ops_per_insn
== 0)
2471 warn (_("Invalid maximum operations per insn.\n"));
2476 linfo
.li_max_ops_per_insn
= 1;
2477 linfo
.li_default_is_stmt
= byte_get (hdrptr
, 1);
2479 linfo
.li_line_base
= byte_get (hdrptr
, 1);
2481 linfo
.li_line_range
= byte_get (hdrptr
, 1);
2483 linfo
.li_opcode_base
= byte_get (hdrptr
, 1);
2486 /* Sign extend the line base field. */
2487 linfo
.li_line_base
<<= 24;
2488 linfo
.li_line_base
>>= 24;
2490 printf (_(" Offset: 0x%lx\n"), hdroff
);
2491 printf (_(" Length: %ld\n"), (long) linfo
.li_length
);
2492 printf (_(" DWARF Version: %d\n"), linfo
.li_version
);
2493 printf (_(" Prologue Length: %d\n"), linfo
.li_prologue_length
);
2494 printf (_(" Minimum Instruction Length: %d\n"), linfo
.li_min_insn_length
);
2495 if (linfo
.li_version
>= 4)
2496 printf (_(" Maximum Ops per Instruction: %d\n"), linfo
.li_max_ops_per_insn
);
2497 printf (_(" Initial value of 'is_stmt': %d\n"), linfo
.li_default_is_stmt
);
2498 printf (_(" Line Base: %d\n"), linfo
.li_line_base
);
2499 printf (_(" Line Range: %d\n"), linfo
.li_line_range
);
2500 printf (_(" Opcode Base: %d\n"), linfo
.li_opcode_base
);
2502 end_of_sequence
= data
+ linfo
.li_length
+ initial_length_size
;
2504 reset_state_machine (linfo
.li_default_is_stmt
);
2506 /* Display the contents of the Opcodes table. */
2507 standard_opcodes
= hdrptr
;
2509 printf (_("\n Opcodes:\n"));
2511 for (i
= 1; i
< linfo
.li_opcode_base
; i
++)
2512 printf (_(" Opcode %d has %d args\n"), i
, standard_opcodes
[i
- 1]);
2514 /* Display the contents of the Directory table. */
2515 data
= standard_opcodes
+ linfo
.li_opcode_base
- 1;
2518 printf (_("\n The Directory Table is empty.\n"));
2521 printf (_("\n The Directory Table:\n"));
2525 printf (" %s\n", data
);
2527 data
+= strlen ((char *) data
) + 1;
2531 /* Skip the NUL at the end of the table. */
2534 /* Display the contents of the File Name table. */
2536 printf (_("\n The File Name Table is empty.\n"));
2539 printf (_("\n The File Name Table:\n"));
2540 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
2544 unsigned char *name
;
2545 unsigned int bytes_read
;
2547 printf (" %d\t", ++state_machine_regs
.last_file_entry
);
2550 data
+= strlen ((char *) data
) + 1;
2553 dwarf_vmatoa ("u", read_leb128 (data
, & bytes_read
, 0)));
2556 dwarf_vmatoa ("u", read_leb128 (data
, & bytes_read
, 0)));
2559 dwarf_vmatoa ("u", read_leb128 (data
, & bytes_read
, 0)));
2561 printf ("%s\n", name
);
2565 /* Skip the NUL at the end of the table. */
2568 /* Now display the statements. */
2569 printf (_("\n Line Number Statements:\n"));
2571 while (data
< end_of_sequence
)
2573 unsigned char op_code
;
2574 dwarf_signed_vma adv
;
2576 unsigned int bytes_read
;
2580 if (op_code
>= linfo
.li_opcode_base
)
2582 op_code
-= linfo
.li_opcode_base
;
2583 uladv
= (op_code
/ linfo
.li_line_range
);
2584 if (linfo
.li_max_ops_per_insn
== 1)
2586 uladv
*= linfo
.li_min_insn_length
;
2587 state_machine_regs
.address
+= uladv
;
2588 printf (_(" Special opcode %d: "
2589 "advance Address by %s to 0x%s"),
2590 op_code
, dwarf_vmatoa ("u", uladv
),
2591 dwarf_vmatoa ("x", state_machine_regs
.address
));
2595 state_machine_regs
.address
2596 += ((state_machine_regs
.op_index
+ uladv
)
2597 / linfo
.li_max_ops_per_insn
)
2598 * linfo
.li_min_insn_length
;
2599 state_machine_regs
.op_index
2600 = (state_machine_regs
.op_index
+ uladv
)
2601 % linfo
.li_max_ops_per_insn
;
2602 printf (_(" Special opcode %d: "
2603 "advance Address by %s to 0x%s[%d]"),
2604 op_code
, dwarf_vmatoa ("u", uladv
),
2605 dwarf_vmatoa ("x", state_machine_regs
.address
),
2606 state_machine_regs
.op_index
);
2608 adv
= (op_code
% linfo
.li_line_range
) + linfo
.li_line_base
;
2609 state_machine_regs
.line
+= adv
;
2610 printf (_(" and Line by %s to %d\n"),
2611 dwarf_vmatoa ("d", adv
), state_machine_regs
.line
);
2613 else switch (op_code
)
2615 case DW_LNS_extended_op
:
2616 data
+= process_extended_line_op (data
, linfo
.li_default_is_stmt
);
2620 printf (_(" Copy\n"));
2623 case DW_LNS_advance_pc
:
2624 uladv
= read_leb128 (data
, & bytes_read
, 0);
2626 if (linfo
.li_max_ops_per_insn
== 1)
2628 uladv
*= linfo
.li_min_insn_length
;
2629 state_machine_regs
.address
+= uladv
;
2630 printf (_(" Advance PC by %s to 0x%s\n"),
2631 dwarf_vmatoa ("u", uladv
),
2632 dwarf_vmatoa ("x", state_machine_regs
.address
));
2636 state_machine_regs
.address
2637 += ((state_machine_regs
.op_index
+ uladv
)
2638 / linfo
.li_max_ops_per_insn
)
2639 * linfo
.li_min_insn_length
;
2640 state_machine_regs
.op_index
2641 = (state_machine_regs
.op_index
+ uladv
)
2642 % linfo
.li_max_ops_per_insn
;
2643 printf (_(" Advance PC by %s to 0x%s[%d]\n"),
2644 dwarf_vmatoa ("u", uladv
),
2645 dwarf_vmatoa ("x", state_machine_regs
.address
),
2646 state_machine_regs
.op_index
);
2650 case DW_LNS_advance_line
:
2651 adv
= read_sleb128 (data
, & bytes_read
);
2653 state_machine_regs
.line
+= adv
;
2654 printf (_(" Advance Line by %s to %d\n"),
2655 dwarf_vmatoa ("d", adv
),
2656 state_machine_regs
.line
);
2659 case DW_LNS_set_file
:
2660 adv
= read_leb128 (data
, & bytes_read
, 0);
2662 printf (_(" Set File Name to entry %s in the File Name Table\n"),
2663 dwarf_vmatoa ("d", adv
));
2664 state_machine_regs
.file
= adv
;
2667 case DW_LNS_set_column
:
2668 uladv
= read_leb128 (data
, & bytes_read
, 0);
2670 printf (_(" Set column to %s\n"),
2671 dwarf_vmatoa ("u", uladv
));
2672 state_machine_regs
.column
= uladv
;
2675 case DW_LNS_negate_stmt
:
2676 adv
= state_machine_regs
.is_stmt
;
2678 printf (_(" Set is_stmt to %s\n"), dwarf_vmatoa ("d", adv
));
2679 state_machine_regs
.is_stmt
= adv
;
2682 case DW_LNS_set_basic_block
:
2683 printf (_(" Set basic block\n"));
2684 state_machine_regs
.basic_block
= 1;
2687 case DW_LNS_const_add_pc
:
2688 uladv
= ((255 - linfo
.li_opcode_base
) / linfo
.li_line_range
);
2689 if (linfo
.li_max_ops_per_insn
)
2691 uladv
*= linfo
.li_min_insn_length
;
2692 state_machine_regs
.address
+= uladv
;
2693 printf (_(" Advance PC by constant %s to 0x%s\n"),
2694 dwarf_vmatoa ("u", uladv
),
2695 dwarf_vmatoa ("x", state_machine_regs
.address
));
2699 state_machine_regs
.address
2700 += ((state_machine_regs
.op_index
+ uladv
)
2701 / linfo
.li_max_ops_per_insn
)
2702 * linfo
.li_min_insn_length
;
2703 state_machine_regs
.op_index
2704 = (state_machine_regs
.op_index
+ uladv
)
2705 % linfo
.li_max_ops_per_insn
;
2706 printf (_(" Advance PC by constant %s to 0x%s[%d]\n"),
2707 dwarf_vmatoa ("u", uladv
),
2708 dwarf_vmatoa ("x", state_machine_regs
.address
),
2709 state_machine_regs
.op_index
);
2713 case DW_LNS_fixed_advance_pc
:
2714 uladv
= byte_get (data
, 2);
2716 state_machine_regs
.address
+= uladv
;
2717 state_machine_regs
.op_index
= 0;
2718 printf (_(" Advance PC by fixed size amount %s to 0x%s\n"),
2719 dwarf_vmatoa ("u", uladv
),
2720 dwarf_vmatoa ("x", state_machine_regs
.address
));
2723 case DW_LNS_set_prologue_end
:
2724 printf (_(" Set prologue_end to true\n"));
2727 case DW_LNS_set_epilogue_begin
:
2728 printf (_(" Set epilogue_begin to true\n"));
2731 case DW_LNS_set_isa
:
2732 uladv
= read_leb128 (data
, & bytes_read
, 0);
2734 printf (_(" Set ISA to %s\n"), dwarf_vmatoa ("u", uladv
));
2738 printf (_(" Unknown opcode %d with operands: "), op_code
);
2740 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
2742 printf ("0x%s%s", dwarf_vmatoa ("x", read_leb128 (data
,
2744 i
== 1 ? "" : ", ");
2759 unsigned char *name
;
2760 unsigned int directory_index
;
2761 unsigned int modification_date
;
2762 unsigned int length
;
2765 /* Output a decoded representation of the .debug_line section. */
2768 display_debug_lines_decoded (struct dwarf_section
*section
,
2769 unsigned char *data
,
2772 printf (_("Decoded dump of debug contents of section %s:\n\n"),
2777 /* This loop amounts to one iteration per compilation unit. */
2778 DWARF2_Internal_LineInfo linfo
;
2779 unsigned char *standard_opcodes
;
2780 unsigned char *end_of_sequence
;
2781 unsigned char *hdrptr
;
2782 int initial_length_size
;
2785 File_Entry
*file_table
= NULL
;
2786 unsigned char **directory_table
= NULL
;
2790 /* Extract information from the Line Number Program Header.
2791 (section 6.2.4 in the Dwarf3 doc). */
2793 /* Get the length of this CU's line number information block. */
2794 linfo
.li_length
= byte_get (hdrptr
, 4);
2797 if (linfo
.li_length
== 0xffffffff)
2799 /* This section is 64-bit DWARF 3. */
2800 linfo
.li_length
= byte_get (hdrptr
, 8);
2803 initial_length_size
= 12;
2808 initial_length_size
= 4;
2811 if (linfo
.li_length
+ initial_length_size
> section
->size
)
2813 warn (_("The line info appears to be corrupt - "
2814 "the section is too small\n"));
2818 /* Get this CU's Line Number Block version number. */
2819 linfo
.li_version
= byte_get (hdrptr
, 2);
2821 if (linfo
.li_version
!= 2
2822 && linfo
.li_version
!= 3
2823 && linfo
.li_version
!= 4)
2825 warn (_("Only DWARF version 2, 3 and 4 line info is currently "
2830 linfo
.li_prologue_length
= byte_get (hdrptr
, offset_size
);
2831 hdrptr
+= offset_size
;
2832 linfo
.li_min_insn_length
= byte_get (hdrptr
, 1);
2834 if (linfo
.li_version
>= 4)
2836 linfo
.li_max_ops_per_insn
= byte_get (hdrptr
, 1);
2838 if (linfo
.li_max_ops_per_insn
== 0)
2840 warn (_("Invalid maximum operations per insn.\n"));
2845 linfo
.li_max_ops_per_insn
= 1;
2846 linfo
.li_default_is_stmt
= byte_get (hdrptr
, 1);
2848 linfo
.li_line_base
= byte_get (hdrptr
, 1);
2850 linfo
.li_line_range
= byte_get (hdrptr
, 1);
2852 linfo
.li_opcode_base
= byte_get (hdrptr
, 1);
2855 /* Sign extend the line base field. */
2856 linfo
.li_line_base
<<= 24;
2857 linfo
.li_line_base
>>= 24;
2859 /* Find the end of this CU's Line Number Information Block. */
2860 end_of_sequence
= data
+ linfo
.li_length
+ initial_length_size
;
2862 reset_state_machine (linfo
.li_default_is_stmt
);
2864 /* Save a pointer to the contents of the Opcodes table. */
2865 standard_opcodes
= hdrptr
;
2867 /* Traverse the Directory table just to count entries. */
2868 data
= standard_opcodes
+ linfo
.li_opcode_base
- 1;
2871 unsigned int n_directories
= 0;
2872 unsigned char *ptr_directory_table
= data
;
2876 data
+= strlen ((char *) data
) + 1;
2880 /* Go through the directory table again to save the directories. */
2881 directory_table
= (unsigned char **)
2882 xmalloc (n_directories
* sizeof (unsigned char *));
2885 while (*ptr_directory_table
!= 0)
2887 directory_table
[i
] = ptr_directory_table
;
2888 ptr_directory_table
+= strlen ((char *) ptr_directory_table
) + 1;
2892 /* Skip the NUL at the end of the table. */
2895 /* Traverse the File Name table just to count the entries. */
2898 unsigned int n_files
= 0;
2899 unsigned char *ptr_file_name_table
= data
;
2903 unsigned int bytes_read
;
2905 /* Skip Name, directory index, last modification time and length
2907 data
+= strlen ((char *) data
) + 1;
2908 read_leb128 (data
, & bytes_read
, 0);
2910 read_leb128 (data
, & bytes_read
, 0);
2912 read_leb128 (data
, & bytes_read
, 0);
2918 /* Go through the file table again to save the strings. */
2919 file_table
= (File_Entry
*) xmalloc (n_files
* sizeof (File_Entry
));
2922 while (*ptr_file_name_table
!= 0)
2924 unsigned int bytes_read
;
2926 file_table
[i
].name
= ptr_file_name_table
;
2927 ptr_file_name_table
+= strlen ((char *) ptr_file_name_table
) + 1;
2929 /* We are not interested in directory, time or size. */
2930 file_table
[i
].directory_index
= read_leb128 (ptr_file_name_table
,
2932 ptr_file_name_table
+= bytes_read
;
2933 file_table
[i
].modification_date
= read_leb128 (ptr_file_name_table
,
2935 ptr_file_name_table
+= bytes_read
;
2936 file_table
[i
].length
= read_leb128 (ptr_file_name_table
, & bytes_read
, 0);
2937 ptr_file_name_table
+= bytes_read
;
2942 /* Print the Compilation Unit's name and a header. */
2943 if (directory_table
== NULL
)
2945 printf (_("CU: %s:\n"), file_table
[0].name
);
2946 printf (_("File name Line number Starting address\n"));
2950 if (do_wide
|| strlen ((char *) directory_table
[0]) < 76)
2951 printf (_("CU: %s/%s:\n"), directory_table
[0],
2952 file_table
[0].name
);
2954 printf ("%s:\n", file_table
[0].name
);
2956 printf (_("File name Line number Starting address\n"));
2960 /* Skip the NUL at the end of the table. */
2963 /* This loop iterates through the Dwarf Line Number Program. */
2964 while (data
< end_of_sequence
)
2966 unsigned char op_code
;
2968 unsigned long int uladv
;
2969 unsigned int bytes_read
;
2970 int is_special_opcode
= 0;
2974 if (op_code
>= linfo
.li_opcode_base
)
2976 op_code
-= linfo
.li_opcode_base
;
2977 uladv
= (op_code
/ linfo
.li_line_range
);
2978 if (linfo
.li_max_ops_per_insn
== 1)
2980 uladv
*= linfo
.li_min_insn_length
;
2981 state_machine_regs
.address
+= uladv
;
2985 state_machine_regs
.address
2986 += ((state_machine_regs
.op_index
+ uladv
)
2987 / linfo
.li_max_ops_per_insn
)
2988 * linfo
.li_min_insn_length
;
2989 state_machine_regs
.op_index
2990 = (state_machine_regs
.op_index
+ uladv
)
2991 % linfo
.li_max_ops_per_insn
;
2994 adv
= (op_code
% linfo
.li_line_range
) + linfo
.li_line_base
;
2995 state_machine_regs
.line
+= adv
;
2996 is_special_opcode
= 1;
2998 else switch (op_code
)
3000 case DW_LNS_extended_op
:
3002 unsigned int ext_op_code_len
;
3003 unsigned char ext_op_code
;
3004 unsigned char *op_code_data
= data
;
3006 ext_op_code_len
= read_leb128 (op_code_data
, &bytes_read
, 0);
3007 op_code_data
+= bytes_read
;
3009 if (ext_op_code_len
== 0)
3011 warn (_("badly formed extended line op encountered!\n"));
3014 ext_op_code_len
+= bytes_read
;
3015 ext_op_code
= *op_code_data
++;
3017 switch (ext_op_code
)
3019 case DW_LNE_end_sequence
:
3020 reset_state_machine (linfo
.li_default_is_stmt
);
3022 case DW_LNE_set_address
:
3023 state_machine_regs
.address
=
3024 byte_get (op_code_data
, ext_op_code_len
- bytes_read
- 1);
3025 state_machine_regs
.op_index
= 0;
3027 case DW_LNE_define_file
:
3029 unsigned int dir_index
= 0;
3031 ++state_machine_regs
.last_file_entry
;
3032 op_code_data
+= strlen ((char *) op_code_data
) + 1;
3033 dir_index
= read_leb128 (op_code_data
, & bytes_read
, 0);
3034 op_code_data
+= bytes_read
;
3035 read_leb128 (op_code_data
, & bytes_read
, 0);
3036 op_code_data
+= bytes_read
;
3037 read_leb128 (op_code_data
, & bytes_read
, 0);
3039 printf ("%s:\n", directory_table
[dir_index
]);
3043 printf (_("UNKNOWN: length %d\n"), ext_op_code_len
- bytes_read
);
3046 data
+= ext_op_code_len
;
3052 case DW_LNS_advance_pc
:
3053 uladv
= read_leb128 (data
, & bytes_read
, 0);
3055 if (linfo
.li_max_ops_per_insn
== 1)
3057 uladv
*= linfo
.li_min_insn_length
;
3058 state_machine_regs
.address
+= uladv
;
3062 state_machine_regs
.address
3063 += ((state_machine_regs
.op_index
+ uladv
)
3064 / linfo
.li_max_ops_per_insn
)
3065 * linfo
.li_min_insn_length
;
3066 state_machine_regs
.op_index
3067 = (state_machine_regs
.op_index
+ uladv
)
3068 % linfo
.li_max_ops_per_insn
;
3072 case DW_LNS_advance_line
:
3073 adv
= read_sleb128 (data
, & bytes_read
);
3075 state_machine_regs
.line
+= adv
;
3078 case DW_LNS_set_file
:
3079 adv
= read_leb128 (data
, & bytes_read
, 0);
3081 state_machine_regs
.file
= adv
;
3082 if (file_table
[state_machine_regs
.file
- 1].directory_index
== 0)
3084 /* If directory index is 0, that means current directory. */
3085 printf ("\n./%s:[++]\n",
3086 file_table
[state_machine_regs
.file
- 1].name
);
3090 /* The directory index starts counting at 1. */
3091 printf ("\n%s/%s:\n",
3092 directory_table
[file_table
[state_machine_regs
.file
- 1].directory_index
- 1],
3093 file_table
[state_machine_regs
.file
- 1].name
);
3097 case DW_LNS_set_column
:
3098 uladv
= read_leb128 (data
, & bytes_read
, 0);
3100 state_machine_regs
.column
= uladv
;
3103 case DW_LNS_negate_stmt
:
3104 adv
= state_machine_regs
.is_stmt
;
3106 state_machine_regs
.is_stmt
= adv
;
3109 case DW_LNS_set_basic_block
:
3110 state_machine_regs
.basic_block
= 1;
3113 case DW_LNS_const_add_pc
:
3114 uladv
= ((255 - linfo
.li_opcode_base
) / linfo
.li_line_range
);
3115 if (linfo
.li_max_ops_per_insn
== 1)
3117 uladv
*= linfo
.li_min_insn_length
;
3118 state_machine_regs
.address
+= uladv
;
3122 state_machine_regs
.address
3123 += ((state_machine_regs
.op_index
+ uladv
)
3124 / linfo
.li_max_ops_per_insn
)
3125 * linfo
.li_min_insn_length
;
3126 state_machine_regs
.op_index
3127 = (state_machine_regs
.op_index
+ uladv
)
3128 % linfo
.li_max_ops_per_insn
;
3132 case DW_LNS_fixed_advance_pc
:
3133 uladv
= byte_get (data
, 2);
3135 state_machine_regs
.address
+= uladv
;
3136 state_machine_regs
.op_index
= 0;
3139 case DW_LNS_set_prologue_end
:
3142 case DW_LNS_set_epilogue_begin
:
3145 case DW_LNS_set_isa
:
3146 uladv
= read_leb128 (data
, & bytes_read
, 0);
3148 printf (_(" Set ISA to %lu\n"), uladv
);
3152 printf (_(" Unknown opcode %d with operands: "), op_code
);
3154 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
3156 printf ("0x%s%s", dwarf_vmatoa ("x", read_leb128 (data
,
3158 i
== 1 ? "" : ", ");
3165 /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row
3166 to the DWARF address/line matrix. */
3167 if ((is_special_opcode
) || (op_code
== DW_LNE_end_sequence
)
3168 || (op_code
== DW_LNS_copy
))
3170 const unsigned int MAX_FILENAME_LENGTH
= 35;
3171 char *fileName
= (char *)file_table
[state_machine_regs
.file
- 1].name
;
3172 char *newFileName
= NULL
;
3173 size_t fileNameLength
= strlen (fileName
);
3175 if ((fileNameLength
> MAX_FILENAME_LENGTH
) && (!do_wide
))
3177 newFileName
= (char *) xmalloc (MAX_FILENAME_LENGTH
+ 1);
3178 /* Truncate file name */
3179 strncpy (newFileName
,
3180 fileName
+ fileNameLength
- MAX_FILENAME_LENGTH
,
3181 MAX_FILENAME_LENGTH
+ 1);
3185 newFileName
= (char *) xmalloc (fileNameLength
+ 1);
3186 strncpy (newFileName
, fileName
, fileNameLength
+ 1);
3189 if (!do_wide
|| (fileNameLength
<= MAX_FILENAME_LENGTH
))
3191 if (linfo
.li_max_ops_per_insn
== 1)
3192 printf ("%-35s %11d %#18" DWARF_VMA_FMT
"x\n",
3193 newFileName
, state_machine_regs
.line
,
3194 state_machine_regs
.address
);
3196 printf ("%-35s %11d %#18" DWARF_VMA_FMT
"x[%d]\n",
3197 newFileName
, state_machine_regs
.line
,
3198 state_machine_regs
.address
,
3199 state_machine_regs
.op_index
);
3203 if (linfo
.li_max_ops_per_insn
== 1)
3204 printf ("%s %11d %#18" DWARF_VMA_FMT
"x\n",
3205 newFileName
, state_machine_regs
.line
,
3206 state_machine_regs
.address
);
3208 printf ("%s %11d %#18" DWARF_VMA_FMT
"x[%d]\n",
3209 newFileName
, state_machine_regs
.line
,
3210 state_machine_regs
.address
,
3211 state_machine_regs
.op_index
);
3214 if (op_code
== DW_LNE_end_sequence
)
3222 free (directory_table
);
3223 directory_table
= NULL
;
3231 display_debug_lines (struct dwarf_section
*section
, void *file ATTRIBUTE_UNUSED
)
3233 unsigned char *data
= section
->start
;
3234 unsigned char *end
= data
+ section
->size
;
3236 int retValDecoded
= 1;
3238 if (do_debug_lines
== 0)
3239 do_debug_lines
|= FLAG_DEBUG_LINES_RAW
;
3241 if (do_debug_lines
& FLAG_DEBUG_LINES_RAW
)
3242 retValRaw
= display_debug_lines_raw (section
, data
, end
);
3244 if (do_debug_lines
& FLAG_DEBUG_LINES_DECODED
)
3245 retValDecoded
= display_debug_lines_decoded (section
, data
, end
);
3247 if (!retValRaw
|| !retValDecoded
)
3254 find_debug_info_for_offset (unsigned long offset
)
3258 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
3261 for (i
= 0; i
< num_debug_info_entries
; i
++)
3262 if (debug_information
[i
].cu_offset
== offset
)
3263 return debug_information
+ i
;
3269 display_debug_pubnames (struct dwarf_section
*section
,
3270 void *file ATTRIBUTE_UNUSED
)
3272 DWARF2_Internal_PubNames names
;
3273 unsigned char *start
= section
->start
;
3274 unsigned char *end
= start
+ section
->size
;
3276 /* It does not matter if this load fails,
3277 we test for that later on. */
3278 load_debug_info (file
);
3280 printf (_("Contents of the %s section:\n\n"), section
->name
);
3284 unsigned char *data
;
3285 unsigned long offset
;
3286 int offset_size
, initial_length_size
;
3290 names
.pn_length
= byte_get (data
, 4);
3292 if (names
.pn_length
== 0xffffffff)
3294 names
.pn_length
= byte_get (data
, 8);
3297 initial_length_size
= 12;
3302 initial_length_size
= 4;
3305 names
.pn_version
= byte_get (data
, 2);
3308 names
.pn_offset
= byte_get (data
, offset_size
);
3309 data
+= offset_size
;
3311 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
3312 && num_debug_info_entries
> 0
3313 && find_debug_info_for_offset (names
.pn_offset
) == NULL
)
3314 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
3315 (unsigned long) names
.pn_offset
, section
->name
);
3317 names
.pn_size
= byte_get (data
, offset_size
);
3318 data
+= offset_size
;
3320 start
+= names
.pn_length
+ initial_length_size
;
3322 if (names
.pn_version
!= 2 && names
.pn_version
!= 3)
3324 static int warned
= 0;
3328 warn (_("Only DWARF 2 and 3 pubnames are currently supported\n"));
3335 printf (_(" Length: %ld\n"),
3336 (long) names
.pn_length
);
3337 printf (_(" Version: %d\n"),
3339 printf (_(" Offset into .debug_info section: 0x%lx\n"),
3340 (unsigned long) names
.pn_offset
);
3341 printf (_(" Size of area in .debug_info section: %ld\n"),
3342 (long) names
.pn_size
);
3344 printf (_("\n Offset\tName\n"));
3348 offset
= byte_get (data
, offset_size
);
3352 data
+= offset_size
;
3353 printf (" %-6lx\t%s\n", offset
, data
);
3354 data
+= strlen ((char *) data
) + 1;
3357 while (offset
!= 0);
3365 display_debug_macinfo (struct dwarf_section
*section
,
3366 void *file ATTRIBUTE_UNUSED
)
3368 unsigned char *start
= section
->start
;
3369 unsigned char *end
= start
+ section
->size
;
3370 unsigned char *curr
= start
;
3371 unsigned int bytes_read
;
3372 enum dwarf_macinfo_record_type op
;
3374 printf (_("Contents of the %s section:\n\n"), section
->name
);
3378 unsigned int lineno
;
3381 op
= (enum dwarf_macinfo_record_type
) *curr
;
3386 case DW_MACINFO_start_file
:
3388 unsigned int filenum
;
3390 lineno
= read_leb128 (curr
, & bytes_read
, 0);
3392 filenum
= read_leb128 (curr
, & bytes_read
, 0);
3395 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"),
3400 case DW_MACINFO_end_file
:
3401 printf (_(" DW_MACINFO_end_file\n"));
3404 case DW_MACINFO_define
:
3405 lineno
= read_leb128 (curr
, & bytes_read
, 0);
3407 string
= (char *) curr
;
3408 curr
+= strlen (string
) + 1;
3409 printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"),
3413 case DW_MACINFO_undef
:
3414 lineno
= read_leb128 (curr
, & bytes_read
, 0);
3416 string
= (char *) curr
;
3417 curr
+= strlen (string
) + 1;
3418 printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"),
3422 case DW_MACINFO_vendor_ext
:
3424 unsigned int constant
;
3426 constant
= read_leb128 (curr
, & bytes_read
, 0);
3428 string
= (char *) curr
;
3429 curr
+= strlen (string
) + 1;
3430 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"),
3441 display_debug_abbrev (struct dwarf_section
*section
,
3442 void *file ATTRIBUTE_UNUSED
)
3444 abbrev_entry
*entry
;
3445 unsigned char *start
= section
->start
;
3446 unsigned char *end
= start
+ section
->size
;
3448 printf (_("Contents of the %s section:\n\n"), section
->name
);
3454 start
= process_abbrev_section (start
, end
);
3456 if (first_abbrev
== NULL
)
3459 printf (_(" Number TAG\n"));
3461 for (entry
= first_abbrev
; entry
; entry
= entry
->next
)
3465 printf (" %ld %s [%s]\n",
3467 get_TAG_name (entry
->tag
),
3468 entry
->children
? _("has children") : _("no children"));
3470 for (attr
= entry
->first_attr
; attr
; attr
= attr
->next
)
3471 printf (" %-18s %s\n",
3472 get_AT_name (attr
->attribute
),
3473 get_FORM_name (attr
->form
));
3484 display_debug_loc (struct dwarf_section
*section
, void *file
)
3486 unsigned char *start
= section
->start
;
3487 unsigned char *section_end
;
3488 unsigned long bytes
;
3489 unsigned char *section_begin
= start
;
3490 unsigned int num_loc_list
= 0;
3491 unsigned long last_offset
= 0;
3492 unsigned int first
= 0;
3495 int seen_first_offset
= 0;
3496 int use_debug_info
= 1;
3497 unsigned char *next
;
3499 bytes
= section
->size
;
3500 section_end
= start
+ bytes
;
3504 printf (_("\nThe %s section is empty.\n"), section
->name
);
3508 if (load_debug_info (file
) == 0)
3510 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
3515 /* Check the order of location list in .debug_info section. If
3516 offsets of location lists are in the ascending order, we can
3517 use `debug_information' directly. */
3518 for (i
= 0; i
< num_debug_info_entries
; i
++)
3522 num
= debug_information
[i
].num_loc_offsets
;
3523 num_loc_list
+= num
;
3525 /* Check if we can use `debug_information' directly. */
3526 if (use_debug_info
&& num
!= 0)
3528 if (!seen_first_offset
)
3530 /* This is the first location list. */
3531 last_offset
= debug_information
[i
].loc_offsets
[0];
3533 seen_first_offset
= 1;
3539 for (; j
< num
; j
++)
3542 debug_information
[i
].loc_offsets
[j
])
3547 last_offset
= debug_information
[i
].loc_offsets
[j
];
3552 if (!use_debug_info
)
3553 /* FIXME: Should we handle this case? */
3554 error (_("Location lists in .debug_info section aren't in ascending order!\n"));
3556 if (!seen_first_offset
)
3557 error (_("No location lists in .debug_info section!\n"));
3559 /* DWARF sections under Mach-O have non-zero addresses. */
3560 if (debug_information
[first
].num_loc_offsets
> 0
3561 && debug_information
[first
].loc_offsets
[0] != section
->address
)
3562 warn (_("Location lists in %s section start at 0x%s\n"),
3564 dwarf_vmatoa ("x", debug_information
[first
].loc_offsets
[0]));
3566 printf (_("Contents of the %s section:\n\n"), section
->name
);
3567 printf (_(" Offset Begin End Expression\n"));
3569 seen_first_offset
= 0;
3570 for (i
= first
; i
< num_debug_info_entries
; i
++)
3574 unsigned short length
;
3575 unsigned long offset
;
3576 unsigned int pointer_size
;
3577 unsigned int offset_size
;
3579 unsigned long cu_offset
;
3580 unsigned long base_address
;
3581 int need_frame_base
;
3584 pointer_size
= debug_information
[i
].pointer_size
;
3585 cu_offset
= debug_information
[i
].cu_offset
;
3586 offset_size
= debug_information
[i
].offset_size
;
3587 dwarf_version
= debug_information
[i
].dwarf_version
;
3589 for (j
= 0; j
< debug_information
[i
].num_loc_offsets
; j
++)
3591 has_frame_base
= debug_information
[i
].have_frame_base
[j
];
3592 /* DWARF sections under Mach-O have non-zero addresses. */
3593 offset
= debug_information
[i
].loc_offsets
[j
] - section
->address
;
3594 next
= section_begin
+ offset
;
3595 base_address
= debug_information
[i
].base_address
;
3597 if (!seen_first_offset
)
3598 seen_first_offset
= 1;
3602 warn (_("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n"),
3603 (unsigned long) (start
- section_begin
),
3604 (unsigned long) (next
- section_begin
));
3605 else if (start
> next
)
3606 warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n"),
3607 (unsigned long) (start
- section_begin
),
3608 (unsigned long) (next
- section_begin
));
3612 if (offset
>= bytes
)
3614 warn (_("Offset 0x%lx is bigger than .debug_loc section size.\n"),
3621 if (start
+ 2 * pointer_size
> section_end
)
3623 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
3628 /* Note: we use sign extension here in order to be sure that
3629 we can detect the -1 escape value. Sign extension into the
3630 top 32 bits of a 32-bit address will not affect the values
3631 that we display since we always show hex values, and always
3632 the bottom 32-bits. */
3633 begin
= byte_get_signed (start
, pointer_size
);
3634 start
+= pointer_size
;
3635 end
= byte_get_signed (start
, pointer_size
);
3636 start
+= pointer_size
;
3638 printf (" %8.8lx ", offset
);
3640 if (begin
== 0 && end
== 0)
3642 printf (_("<End of list>\n"));
3646 /* Check base address specifiers. */
3647 if (begin
== (dwarf_vma
) -1 && end
!= (dwarf_vma
) -1)
3650 print_dwarf_vma (begin
, pointer_size
);
3651 print_dwarf_vma (end
, pointer_size
);
3652 printf (_("(base address)\n"));
3656 if (start
+ 2 > section_end
)
3658 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
3663 length
= byte_get (start
, 2);
3666 if (start
+ length
> section_end
)
3668 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
3673 print_dwarf_vma (begin
+ base_address
, pointer_size
);
3674 print_dwarf_vma (end
+ base_address
, pointer_size
);
3677 need_frame_base
= decode_location_expression (start
,
3682 cu_offset
, section
);
3685 if (need_frame_base
&& !has_frame_base
)
3686 printf (_(" [without DW_AT_frame_base]"));
3689 fputs (_(" (start == end)"), stdout
);
3690 else if (begin
> end
)
3691 fputs (_(" (start > end)"), stdout
);
3700 if (start
< section_end
)
3701 warn (_("There are %ld unused bytes at the end of section %s\n"),
3702 (long) (section_end
- start
), section
->name
);
3708 display_debug_str (struct dwarf_section
*section
,
3709 void *file ATTRIBUTE_UNUSED
)
3711 unsigned char *start
= section
->start
;
3712 unsigned long bytes
= section
->size
;
3713 dwarf_vma addr
= section
->address
;
3717 printf (_("\nThe %s section is empty.\n"), section
->name
);
3721 printf (_("Contents of the %s section:\n\n"), section
->name
);
3729 lbytes
= (bytes
> 16 ? 16 : bytes
);
3731 printf (" 0x%8.8lx ", (unsigned long) addr
);
3733 for (j
= 0; j
< 16; j
++)
3736 printf ("%2.2x", start
[j
]);
3744 for (j
= 0; j
< lbytes
; j
++)
3747 if (k
>= ' ' && k
< 0x80)
3766 display_debug_info (struct dwarf_section
*section
, void *file
)
3768 return process_debug_info (section
, file
, abbrev
, 0, 0);
3772 display_debug_types (struct dwarf_section
*section
, void *file
)
3774 return process_debug_info (section
, file
, abbrev
, 0, 1);
3778 display_trace_info (struct dwarf_section
*section
, void *file
)
3780 return process_debug_info (section
, file
, trace_abbrev
, 0, 0);
3784 display_debug_aranges (struct dwarf_section
*section
,
3785 void *file ATTRIBUTE_UNUSED
)
3787 unsigned char *start
= section
->start
;
3788 unsigned char *end
= start
+ section
->size
;
3790 printf (_("Contents of the %s section:\n\n"), section
->name
);
3792 /* It does not matter if this load fails,
3793 we test for that later on. */
3794 load_debug_info (file
);
3798 unsigned char *hdrptr
;
3799 DWARF2_Internal_ARange arange
;
3800 unsigned char *addr_ranges
;
3803 unsigned char address_size
;
3806 int initial_length_size
;
3810 arange
.ar_length
= byte_get (hdrptr
, 4);
3813 if (arange
.ar_length
== 0xffffffff)
3815 arange
.ar_length
= byte_get (hdrptr
, 8);
3818 initial_length_size
= 12;
3823 initial_length_size
= 4;
3826 arange
.ar_version
= byte_get (hdrptr
, 2);
3829 arange
.ar_info_offset
= byte_get (hdrptr
, offset_size
);
3830 hdrptr
+= offset_size
;
3832 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
3833 && num_debug_info_entries
> 0
3834 && find_debug_info_for_offset (arange
.ar_info_offset
) == NULL
)
3835 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
3836 (unsigned long) arange
.ar_info_offset
, section
->name
);
3838 arange
.ar_pointer_size
= byte_get (hdrptr
, 1);
3841 arange
.ar_segment_size
= byte_get (hdrptr
, 1);
3844 if (arange
.ar_version
!= 2 && arange
.ar_version
!= 3)
3846 warn (_("Only DWARF 2 and 3 aranges are currently supported.\n"));
3850 printf (_(" Length: %ld\n"),
3851 (long) arange
.ar_length
);
3852 printf (_(" Version: %d\n"), arange
.ar_version
);
3853 printf (_(" Offset into .debug_info: 0x%lx\n"),
3854 (unsigned long) arange
.ar_info_offset
);
3855 printf (_(" Pointer Size: %d\n"), arange
.ar_pointer_size
);
3856 printf (_(" Segment Size: %d\n"), arange
.ar_segment_size
);
3858 address_size
= arange
.ar_pointer_size
+ arange
.ar_segment_size
;
3860 /* The DWARF spec does not require that the address size be a power
3861 of two, but we do. This will have to change if we ever encounter
3862 an uneven architecture. */
3863 if ((address_size
& (address_size
- 1)) != 0)
3865 warn (_("Pointer size + Segment size is not a power of two.\n"));
3869 if (address_size
> 4)
3870 printf (_("\n Address Length\n"));
3872 printf (_("\n Address Length\n"));
3874 addr_ranges
= hdrptr
;
3876 /* Must pad to an alignment boundary that is twice the address size. */
3877 excess
= (hdrptr
- start
) % (2 * address_size
);
3879 addr_ranges
+= (2 * address_size
) - excess
;
3881 start
+= arange
.ar_length
+ initial_length_size
;
3883 while (addr_ranges
+ 2 * address_size
<= start
)
3885 address
= byte_get (addr_ranges
, address_size
);
3887 addr_ranges
+= address_size
;
3889 length
= byte_get (addr_ranges
, address_size
);
3891 addr_ranges
+= address_size
;
3894 print_dwarf_vma (address
, address_size
);
3895 print_dwarf_vma (length
, address_size
);
3905 /* Each debug_information[x].range_lists[y] gets this representation for
3906 sorting purposes. */
3910 /* The debug_information[x].range_lists[y] value. */
3911 unsigned long ranges_offset
;
3913 /* Original debug_information to find parameters of the data. */
3914 debug_info
*debug_info_p
;
3917 /* Sort struct range_entry in ascending order of its RANGES_OFFSET. */
3920 range_entry_compar (const void *ap
, const void *bp
)
3922 const struct range_entry
*a_re
= (const struct range_entry
*) ap
;
3923 const struct range_entry
*b_re
= (const struct range_entry
*) bp
;
3924 const unsigned long a
= a_re
->ranges_offset
;
3925 const unsigned long b
= b_re
->ranges_offset
;
3927 return (a
> b
) - (b
> a
);
3931 display_debug_ranges (struct dwarf_section
*section
,
3932 void *file ATTRIBUTE_UNUSED
)
3934 unsigned char *start
= section
->start
;
3935 unsigned long bytes
;
3936 unsigned char *section_begin
= start
;
3937 unsigned int num_range_list
, i
;
3938 struct range_entry
*range_entries
, *range_entry_fill
;
3940 bytes
= section
->size
;
3944 printf (_("\nThe %s section is empty.\n"), section
->name
);
3948 if (load_debug_info (file
) == 0)
3950 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
3956 for (i
= 0; i
< num_debug_info_entries
; i
++)
3957 num_range_list
+= debug_information
[i
].num_range_lists
;
3959 if (num_range_list
== 0)
3960 error (_("No range lists in .debug_info section!\n"));
3962 range_entries
= (struct range_entry
*)
3963 xmalloc (sizeof (*range_entries
) * num_range_list
);
3964 range_entry_fill
= range_entries
;
3966 for (i
= 0; i
< num_debug_info_entries
; i
++)
3968 debug_info
*debug_info_p
= &debug_information
[i
];
3971 for (j
= 0; j
< debug_info_p
->num_range_lists
; j
++)
3973 range_entry_fill
->ranges_offset
= debug_info_p
->range_lists
[j
];
3974 range_entry_fill
->debug_info_p
= debug_info_p
;
3979 qsort (range_entries
, num_range_list
, sizeof (*range_entries
),
3980 range_entry_compar
);
3982 /* DWARF sections under Mach-O have non-zero addresses. */
3983 if (range_entries
[0].ranges_offset
!= section
->address
)
3984 warn (_("Range lists in %s section start at 0x%lx\n"),
3985 section
->name
, range_entries
[0].ranges_offset
);
3987 printf (_("Contents of the %s section:\n\n"), section
->name
);
3988 printf (_(" Offset Begin End\n"));
3990 for (i
= 0; i
< num_range_list
; i
++)
3992 struct range_entry
*range_entry
= &range_entries
[i
];
3993 debug_info
*debug_info_p
= range_entry
->debug_info_p
;
3994 unsigned int pointer_size
;
3995 unsigned long offset
;
3996 unsigned char *next
;
3997 unsigned long base_address
;
3999 pointer_size
= debug_info_p
->pointer_size
;
4001 /* DWARF sections under Mach-O have non-zero addresses. */
4002 offset
= range_entry
->ranges_offset
- section
->address
;
4003 next
= section_begin
+ offset
;
4004 base_address
= debug_info_p
->base_address
;
4009 warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"),
4010 (unsigned long) (start
- section_begin
),
4011 (unsigned long) (next
- section_begin
), section
->name
);
4012 else if (start
> next
)
4013 warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"),
4014 (unsigned long) (start
- section_begin
),
4015 (unsigned long) (next
- section_begin
), section
->name
);
4024 /* Note: we use sign extension here in order to be sure that
4025 we can detect the -1 escape value. Sign extension into the
4026 top 32 bits of a 32-bit address will not affect the values
4027 that we display since we always show hex values, and always
4028 the bottom 32-bits. */
4029 begin
= byte_get_signed (start
, pointer_size
);
4030 start
+= pointer_size
;
4031 end
= byte_get_signed (start
, pointer_size
);
4032 start
+= pointer_size
;
4034 printf (" %8.8lx ", offset
);
4036 if (begin
== 0 && end
== 0)
4038 printf (_("<End of list>\n"));
4042 /* Check base address specifiers. */
4043 if (begin
== (dwarf_vma
) -1 && end
!= (dwarf_vma
) -1)
4046 print_dwarf_vma (begin
, pointer_size
);
4047 print_dwarf_vma (end
, pointer_size
);
4048 printf ("(base address)\n");
4052 print_dwarf_vma (begin
+ base_address
, pointer_size
);
4053 print_dwarf_vma (end
+ base_address
, pointer_size
);
4056 fputs (_("(start == end)"), stdout
);
4057 else if (begin
> end
)
4058 fputs (_("(start > end)"), stdout
);
4065 free (range_entries
);
4070 typedef struct Frame_Chunk
4072 struct Frame_Chunk
*next
;
4073 unsigned char *chunk_start
;
4075 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
4076 short int *col_type
;
4079 unsigned int code_factor
;
4081 unsigned long pc_begin
;
4082 unsigned long pc_range
;
4086 unsigned char fde_encoding
;
4087 unsigned char cfa_exp
;
4088 unsigned char ptr_size
;
4089 unsigned char segment_size
;
4093 static const char *const *dwarf_regnames
;
4094 static unsigned int dwarf_regnames_count
;
4096 /* A marker for a col_type that means this column was never referenced
4097 in the frame info. */
4098 #define DW_CFA_unreferenced (-1)
4100 /* Return 0 if not more space is needed, 1 if more space is needed,
4101 -1 for invalid reg. */
4104 frame_need_space (Frame_Chunk
*fc
, unsigned int reg
)
4106 int prev
= fc
->ncols
;
4108 if (reg
< (unsigned int) fc
->ncols
)
4111 if (dwarf_regnames_count
4112 && reg
> dwarf_regnames_count
)
4115 fc
->ncols
= reg
+ 1;
4116 fc
->col_type
= (short int *) xcrealloc (fc
->col_type
, fc
->ncols
,
4117 sizeof (short int));
4118 fc
->col_offset
= (int *) xcrealloc (fc
->col_offset
, fc
->ncols
, sizeof (int));
4120 while (prev
< fc
->ncols
)
4122 fc
->col_type
[prev
] = DW_CFA_unreferenced
;
4123 fc
->col_offset
[prev
] = 0;
4129 static const char *const dwarf_regnames_i386
[] =
4131 "eax", "ecx", "edx", "ebx",
4132 "esp", "ebp", "esi", "edi",
4133 "eip", "eflags", NULL
,
4134 "st0", "st1", "st2", "st3",
4135 "st4", "st5", "st6", "st7",
4137 "xmm0", "xmm1", "xmm2", "xmm3",
4138 "xmm4", "xmm5", "xmm6", "xmm7",
4139 "mm0", "mm1", "mm2", "mm3",
4140 "mm4", "mm5", "mm6", "mm7",
4141 "fcw", "fsw", "mxcsr",
4142 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
,
4147 init_dwarf_regnames_i386 (void)
4149 dwarf_regnames
= dwarf_regnames_i386
;
4150 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_i386
);
4153 static const char *const dwarf_regnames_x86_64
[] =
4155 "rax", "rdx", "rcx", "rbx",
4156 "rsi", "rdi", "rbp", "rsp",
4157 "r8", "r9", "r10", "r11",
4158 "r12", "r13", "r14", "r15",
4160 "xmm0", "xmm1", "xmm2", "xmm3",
4161 "xmm4", "xmm5", "xmm6", "xmm7",
4162 "xmm8", "xmm9", "xmm10", "xmm11",
4163 "xmm12", "xmm13", "xmm14", "xmm15",
4164 "st0", "st1", "st2", "st3",
4165 "st4", "st5", "st6", "st7",
4166 "mm0", "mm1", "mm2", "mm3",
4167 "mm4", "mm5", "mm6", "mm7",
4169 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
,
4170 "fs.base", "gs.base", NULL
, NULL
,
4172 "mxcsr", "fcw", "fsw"
4176 init_dwarf_regnames_x86_64 (void)
4178 dwarf_regnames
= dwarf_regnames_x86_64
;
4179 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_x86_64
);
4183 init_dwarf_regnames (unsigned int e_machine
)
4189 init_dwarf_regnames_i386 ();
4194 init_dwarf_regnames_x86_64 ();
4203 regname (unsigned int regno
, int row
)
4205 static char reg
[64];
4207 && regno
< dwarf_regnames_count
4208 && dwarf_regnames
[regno
] != NULL
)
4211 return dwarf_regnames
[regno
];
4212 snprintf (reg
, sizeof (reg
), "r%d (%s)", regno
,
4213 dwarf_regnames
[regno
]);
4216 snprintf (reg
, sizeof (reg
), "r%d", regno
);
4221 frame_display_row (Frame_Chunk
*fc
, int *need_col_headers
, int *max_regs
)
4226 if (*max_regs
< fc
->ncols
)
4227 *max_regs
= fc
->ncols
;
4229 if (*need_col_headers
)
4231 static const char *sloc
= " LOC";
4233 *need_col_headers
= 0;
4235 printf ("%-*s CFA ", eh_addr_size
* 2, sloc
);
4237 for (r
= 0; r
< *max_regs
; r
++)
4238 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
4243 printf ("%-5s ", regname (r
, 1));
4249 printf ("%0*lx ", eh_addr_size
* 2, fc
->pc_begin
);
4251 strcpy (tmp
, "exp");
4253 sprintf (tmp
, "%s%+d", regname (fc
->cfa_reg
, 1), fc
->cfa_offset
);
4254 printf ("%-8s ", tmp
);
4256 for (r
= 0; r
< fc
->ncols
; r
++)
4258 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
4260 switch (fc
->col_type
[r
])
4262 case DW_CFA_undefined
:
4265 case DW_CFA_same_value
:
4269 sprintf (tmp
, "c%+d", fc
->col_offset
[r
]);
4271 case DW_CFA_val_offset
:
4272 sprintf (tmp
, "v%+d", fc
->col_offset
[r
]);
4274 case DW_CFA_register
:
4275 sprintf (tmp
, "%s", regname (fc
->col_offset
[r
], 0));
4277 case DW_CFA_expression
:
4278 strcpy (tmp
, "exp");
4280 case DW_CFA_val_expression
:
4281 strcpy (tmp
, "vexp");
4284 strcpy (tmp
, "n/a");
4287 printf ("%-5s ", tmp
);
4293 #define GET(N) byte_get (start, N); start += N
4294 #define LEB() read_leb128 (start, & length_return, 0); start += length_return
4295 #define SLEB() read_sleb128 (start, & length_return); start += length_return
4298 display_debug_frames (struct dwarf_section
*section
,
4299 void *file ATTRIBUTE_UNUSED
)
4301 unsigned char *start
= section
->start
;
4302 unsigned char *end
= start
+ section
->size
;
4303 unsigned char *section_start
= start
;
4304 Frame_Chunk
*chunks
= 0;
4305 Frame_Chunk
*remembered_state
= 0;
4307 int is_eh
= strcmp (section
->name
, ".eh_frame") == 0;
4308 unsigned int length_return
;
4310 const char *bad_reg
= _("bad register: ");
4311 int saved_eh_addr_size
= eh_addr_size
;
4313 printf (_("Contents of the %s section:\n"), section
->name
);
4317 unsigned char *saved_start
;
4318 unsigned char *block_end
;
4319 unsigned long length
;
4320 unsigned long cie_id
;
4323 int need_col_headers
= 1;
4324 unsigned char *augmentation_data
= NULL
;
4325 unsigned long augmentation_data_len
= 0;
4326 int encoded_ptr_size
= saved_eh_addr_size
;
4328 int initial_length_size
;
4330 saved_start
= start
;
4331 length
= byte_get (start
, 4); start
+= 4;
4335 printf ("\n%08lx ZERO terminator\n\n",
4336 (unsigned long)(saved_start
- section_start
));
4340 if (length
== 0xffffffff)
4342 length
= byte_get (start
, 8);
4345 initial_length_size
= 12;
4350 initial_length_size
= 4;
4353 block_end
= saved_start
+ length
+ initial_length_size
;
4354 if (block_end
> end
)
4356 warn ("Invalid length %#08lx in FDE at %#08lx\n",
4357 length
, (unsigned long)(saved_start
- section_start
));
4360 cie_id
= byte_get (start
, offset_size
); start
+= offset_size
;
4362 if (is_eh
? (cie_id
== 0) : (cie_id
== DW_CIE_ID
))
4366 fc
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
4367 memset (fc
, 0, sizeof (Frame_Chunk
));
4371 fc
->chunk_start
= saved_start
;
4373 fc
->col_type
= (short int *) xmalloc (sizeof (short int));
4374 fc
->col_offset
= (int *) xmalloc (sizeof (int));
4375 frame_need_space (fc
, max_regs
- 1);
4379 fc
->augmentation
= (char *) start
;
4380 start
= (unsigned char *) strchr ((char *) start
, '\0') + 1;
4382 if (strcmp (fc
->augmentation
, "eh") == 0)
4383 start
+= eh_addr_size
;
4387 fc
->ptr_size
= GET (1);
4388 fc
->segment_size
= GET (1);
4389 eh_addr_size
= fc
->ptr_size
;
4393 fc
->ptr_size
= eh_addr_size
;
4394 fc
->segment_size
= 0;
4396 fc
->code_factor
= LEB ();
4397 fc
->data_factor
= SLEB ();
4407 if (fc
->augmentation
[0] == 'z')
4409 augmentation_data_len
= LEB ();
4410 augmentation_data
= start
;
4411 start
+= augmentation_data_len
;
4415 if (do_debug_frames_interp
)
4416 printf ("\n%08lx %08lx %08lx CIE \"%s\" cf=%d df=%d ra=%d\n",
4417 (unsigned long)(saved_start
- section_start
), length
, cie_id
,
4418 fc
->augmentation
, fc
->code_factor
, fc
->data_factor
,
4422 printf ("\n%08lx %08lx %08lx CIE\n",
4423 (unsigned long)(saved_start
- section_start
), length
, cie_id
);
4424 printf (" Version: %d\n", version
);
4425 printf (" Augmentation: \"%s\"\n", fc
->augmentation
);
4428 printf (" Pointer Size: %u\n", fc
->ptr_size
);
4429 printf (" Segment Size: %u\n", fc
->segment_size
);
4431 printf (" Code alignment factor: %u\n", fc
->code_factor
);
4432 printf (" Data alignment factor: %d\n", fc
->data_factor
);
4433 printf (" Return address column: %d\n", fc
->ra
);
4435 if (augmentation_data_len
)
4438 printf (" Augmentation data: ");
4439 for (i
= 0; i
< augmentation_data_len
; ++i
)
4440 printf (" %02x", augmentation_data
[i
]);
4446 if (augmentation_data_len
)
4448 unsigned char *p
, *q
;
4449 p
= (unsigned char *) fc
->augmentation
+ 1;
4450 q
= augmentation_data
;
4457 q
+= 1 + size_of_encoded_value (*q
);
4459 fc
->fde_encoding
= *q
++;
4467 if (fc
->fde_encoding
)
4468 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
4471 frame_need_space (fc
, fc
->ra
);
4475 unsigned char *look_for
;
4476 static Frame_Chunk fde_fc
;
4477 unsigned long segment_selector
;
4480 memset (fc
, 0, sizeof (Frame_Chunk
));
4482 look_for
= is_eh
? start
- 4 - cie_id
: section_start
+ cie_id
;
4484 for (cie
= chunks
; cie
; cie
= cie
->next
)
4485 if (cie
->chunk_start
== look_for
)
4490 warn ("Invalid CIE pointer %#08lx in FDE at %#08lx\n",
4491 cie_id
, (unsigned long)(saved_start
- section_start
));
4493 fc
->col_type
= (short int *) xmalloc (sizeof (short int));
4494 fc
->col_offset
= (int *) xmalloc (sizeof (int));
4495 frame_need_space (fc
, max_regs
- 1);
4497 fc
->augmentation
= "";
4498 fc
->fde_encoding
= 0;
4499 fc
->ptr_size
= eh_addr_size
;
4500 fc
->segment_size
= 0;
4504 fc
->ncols
= cie
->ncols
;
4505 fc
->col_type
= (short int *) xcmalloc (fc
->ncols
, sizeof (short int));
4506 fc
->col_offset
= (int *) xcmalloc (fc
->ncols
, sizeof (int));
4507 memcpy (fc
->col_type
, cie
->col_type
, fc
->ncols
* sizeof (short int));
4508 memcpy (fc
->col_offset
, cie
->col_offset
, fc
->ncols
* sizeof (int));
4509 fc
->augmentation
= cie
->augmentation
;
4510 fc
->ptr_size
= cie
->ptr_size
;
4511 eh_addr_size
= cie
->ptr_size
;
4512 fc
->segment_size
= cie
->segment_size
;
4513 fc
->code_factor
= cie
->code_factor
;
4514 fc
->data_factor
= cie
->data_factor
;
4515 fc
->cfa_reg
= cie
->cfa_reg
;
4516 fc
->cfa_offset
= cie
->cfa_offset
;
4518 frame_need_space (fc
, max_regs
- 1);
4519 fc
->fde_encoding
= cie
->fde_encoding
;
4522 if (fc
->fde_encoding
)
4523 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
4525 segment_selector
= 0;
4526 if (fc
->segment_size
)
4528 segment_selector
= byte_get (start
, fc
->segment_size
);
4529 start
+= fc
->segment_size
;
4531 fc
->pc_begin
= get_encoded_value (start
, fc
->fde_encoding
, section
);
4532 start
+= encoded_ptr_size
;
4533 fc
->pc_range
= byte_get (start
, encoded_ptr_size
);
4534 start
+= encoded_ptr_size
;
4536 if (cie
->augmentation
[0] == 'z')
4538 augmentation_data_len
= LEB ();
4539 augmentation_data
= start
;
4540 start
+= augmentation_data_len
;
4543 printf ("\n%08lx %08lx %08lx FDE cie=%08lx pc=",
4544 (unsigned long)(saved_start
- section_start
), length
, cie_id
,
4545 (unsigned long)(cie
->chunk_start
- section_start
));
4546 if (fc
->segment_size
)
4547 printf ("%04lx:", segment_selector
);
4548 printf ("%08lx..%08lx\n", fc
->pc_begin
, fc
->pc_begin
+ fc
->pc_range
);
4549 if (! do_debug_frames_interp
&& augmentation_data_len
)
4553 printf (" Augmentation data: ");
4554 for (i
= 0; i
< augmentation_data_len
; ++i
)
4555 printf (" %02x", augmentation_data
[i
]);
4561 /* At this point, fc is the current chunk, cie (if any) is set, and
4562 we're about to interpret instructions for the chunk. */
4563 /* ??? At present we need to do this always, since this sizes the
4564 fc->col_type and fc->col_offset arrays, which we write into always.
4565 We should probably split the interpreted and non-interpreted bits
4566 into two different routines, since there's so much that doesn't
4567 really overlap between them. */
4568 if (1 || do_debug_frames_interp
)
4570 /* Start by making a pass over the chunk, allocating storage
4571 and taking note of what registers are used. */
4572 unsigned char *tmp
= start
;
4574 while (start
< block_end
)
4577 unsigned long reg
, temp
;
4584 /* Warning: if you add any more cases to this switch, be
4585 sure to add them to the corresponding switch below. */
4588 case DW_CFA_advance_loc
:
4592 if (frame_need_space (fc
, opa
) >= 0)
4593 fc
->col_type
[opa
] = DW_CFA_undefined
;
4595 case DW_CFA_restore
:
4596 if (frame_need_space (fc
, opa
) >= 0)
4597 fc
->col_type
[opa
] = DW_CFA_undefined
;
4599 case DW_CFA_set_loc
:
4600 start
+= encoded_ptr_size
;
4602 case DW_CFA_advance_loc1
:
4605 case DW_CFA_advance_loc2
:
4608 case DW_CFA_advance_loc4
:
4611 case DW_CFA_offset_extended
:
4612 case DW_CFA_val_offset
:
4613 reg
= LEB (); LEB ();
4614 if (frame_need_space (fc
, reg
) >= 0)
4615 fc
->col_type
[reg
] = DW_CFA_undefined
;
4617 case DW_CFA_restore_extended
:
4619 frame_need_space (fc
, reg
);
4620 if (frame_need_space (fc
, reg
) >= 0)
4621 fc
->col_type
[reg
] = DW_CFA_undefined
;
4623 case DW_CFA_undefined
:
4625 if (frame_need_space (fc
, reg
) >= 0)
4626 fc
->col_type
[reg
] = DW_CFA_undefined
;
4628 case DW_CFA_same_value
:
4630 if (frame_need_space (fc
, reg
) >= 0)
4631 fc
->col_type
[reg
] = DW_CFA_undefined
;
4633 case DW_CFA_register
:
4634 reg
= LEB (); LEB ();
4635 if (frame_need_space (fc
, reg
) >= 0)
4636 fc
->col_type
[reg
] = DW_CFA_undefined
;
4638 case DW_CFA_def_cfa
:
4641 case DW_CFA_def_cfa_register
:
4644 case DW_CFA_def_cfa_offset
:
4647 case DW_CFA_def_cfa_expression
:
4651 case DW_CFA_expression
:
4652 case DW_CFA_val_expression
:
4656 if (frame_need_space (fc
, reg
) >= 0)
4657 fc
->col_type
[reg
] = DW_CFA_undefined
;
4659 case DW_CFA_offset_extended_sf
:
4660 case DW_CFA_val_offset_sf
:
4661 reg
= LEB (); SLEB ();
4662 if (frame_need_space (fc
, reg
) >= 0)
4663 fc
->col_type
[reg
] = DW_CFA_undefined
;
4665 case DW_CFA_def_cfa_sf
:
4668 case DW_CFA_def_cfa_offset_sf
:
4671 case DW_CFA_MIPS_advance_loc8
:
4674 case DW_CFA_GNU_args_size
:
4677 case DW_CFA_GNU_negative_offset_extended
:
4678 reg
= LEB (); LEB ();
4679 if (frame_need_space (fc
, reg
) >= 0)
4680 fc
->col_type
[reg
] = DW_CFA_undefined
;
4689 /* Now we know what registers are used, make a second pass over
4690 the chunk, this time actually printing out the info. */
4692 while (start
< block_end
)
4695 unsigned long ul
, reg
, roffs
;
4698 const char *reg_prefix
= "";
4705 /* Warning: if you add any more cases to this switch, be
4706 sure to add them to the corresponding switch above. */
4709 case DW_CFA_advance_loc
:
4710 if (do_debug_frames_interp
)
4711 frame_display_row (fc
, &need_col_headers
, &max_regs
);
4713 printf (" DW_CFA_advance_loc: %d to %08lx\n",
4714 opa
* fc
->code_factor
,
4715 fc
->pc_begin
+ opa
* fc
->code_factor
);
4716 fc
->pc_begin
+= opa
* fc
->code_factor
;
4721 if (opa
>= (unsigned int) fc
->ncols
)
4722 reg_prefix
= bad_reg
;
4723 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4724 printf (" DW_CFA_offset: %s%s at cfa%+ld\n",
4725 reg_prefix
, regname (opa
, 0),
4726 roffs
* fc
->data_factor
);
4727 if (*reg_prefix
== '\0')
4729 fc
->col_type
[opa
] = DW_CFA_offset
;
4730 fc
->col_offset
[opa
] = roffs
* fc
->data_factor
;
4734 case DW_CFA_restore
:
4735 if (opa
>= (unsigned int) cie
->ncols
4736 || opa
>= (unsigned int) fc
->ncols
)
4737 reg_prefix
= bad_reg
;
4738 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4739 printf (" DW_CFA_restore: %s%s\n",
4740 reg_prefix
, regname (opa
, 0));
4741 if (*reg_prefix
== '\0')
4743 fc
->col_type
[opa
] = cie
->col_type
[opa
];
4744 fc
->col_offset
[opa
] = cie
->col_offset
[opa
];
4748 case DW_CFA_set_loc
:
4749 vma
= get_encoded_value (start
, fc
->fde_encoding
, section
);
4750 start
+= encoded_ptr_size
;
4751 if (do_debug_frames_interp
)
4752 frame_display_row (fc
, &need_col_headers
, &max_regs
);
4754 printf (" DW_CFA_set_loc: %08lx\n", (unsigned long)vma
);
4758 case DW_CFA_advance_loc1
:
4759 ofs
= byte_get (start
, 1); start
+= 1;
4760 if (do_debug_frames_interp
)
4761 frame_display_row (fc
, &need_col_headers
, &max_regs
);
4763 printf (" DW_CFA_advance_loc1: %ld to %08lx\n",
4764 ofs
* fc
->code_factor
,
4765 fc
->pc_begin
+ ofs
* fc
->code_factor
);
4766 fc
->pc_begin
+= ofs
* fc
->code_factor
;
4769 case DW_CFA_advance_loc2
:
4770 ofs
= byte_get (start
, 2); start
+= 2;
4771 if (do_debug_frames_interp
)
4772 frame_display_row (fc
, &need_col_headers
, &max_regs
);
4774 printf (" DW_CFA_advance_loc2: %ld to %08lx\n",
4775 ofs
* fc
->code_factor
,
4776 fc
->pc_begin
+ ofs
* fc
->code_factor
);
4777 fc
->pc_begin
+= ofs
* fc
->code_factor
;
4780 case DW_CFA_advance_loc4
:
4781 ofs
= byte_get (start
, 4); start
+= 4;
4782 if (do_debug_frames_interp
)
4783 frame_display_row (fc
, &need_col_headers
, &max_regs
);
4785 printf (" DW_CFA_advance_loc4: %ld to %08lx\n",
4786 ofs
* fc
->code_factor
,
4787 fc
->pc_begin
+ ofs
* fc
->code_factor
);
4788 fc
->pc_begin
+= ofs
* fc
->code_factor
;
4791 case DW_CFA_offset_extended
:
4794 if (reg
>= (unsigned int) fc
->ncols
)
4795 reg_prefix
= bad_reg
;
4796 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4797 printf (" DW_CFA_offset_extended: %s%s at cfa%+ld\n",
4798 reg_prefix
, regname (reg
, 0),
4799 roffs
* fc
->data_factor
);
4800 if (*reg_prefix
== '\0')
4802 fc
->col_type
[reg
] = DW_CFA_offset
;
4803 fc
->col_offset
[reg
] = roffs
* fc
->data_factor
;
4807 case DW_CFA_val_offset
:
4810 if (reg
>= (unsigned int) fc
->ncols
)
4811 reg_prefix
= bad_reg
;
4812 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4813 printf (" DW_CFA_val_offset: %s%s at cfa%+ld\n",
4814 reg_prefix
, regname (reg
, 0),
4815 roffs
* fc
->data_factor
);
4816 if (*reg_prefix
== '\0')
4818 fc
->col_type
[reg
] = DW_CFA_val_offset
;
4819 fc
->col_offset
[reg
] = roffs
* fc
->data_factor
;
4823 case DW_CFA_restore_extended
:
4825 if (reg
>= (unsigned int) cie
->ncols
4826 || reg
>= (unsigned int) fc
->ncols
)
4827 reg_prefix
= bad_reg
;
4828 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4829 printf (" DW_CFA_restore_extended: %s%s\n",
4830 reg_prefix
, regname (reg
, 0));
4831 if (*reg_prefix
== '\0')
4833 fc
->col_type
[reg
] = cie
->col_type
[reg
];
4834 fc
->col_offset
[reg
] = cie
->col_offset
[reg
];
4838 case DW_CFA_undefined
:
4840 if (reg
>= (unsigned int) fc
->ncols
)
4841 reg_prefix
= bad_reg
;
4842 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4843 printf (" DW_CFA_undefined: %s%s\n",
4844 reg_prefix
, regname (reg
, 0));
4845 if (*reg_prefix
== '\0')
4847 fc
->col_type
[reg
] = DW_CFA_undefined
;
4848 fc
->col_offset
[reg
] = 0;
4852 case DW_CFA_same_value
:
4854 if (reg
>= (unsigned int) fc
->ncols
)
4855 reg_prefix
= bad_reg
;
4856 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4857 printf (" DW_CFA_same_value: %s%s\n",
4858 reg_prefix
, regname (reg
, 0));
4859 if (*reg_prefix
== '\0')
4861 fc
->col_type
[reg
] = DW_CFA_same_value
;
4862 fc
->col_offset
[reg
] = 0;
4866 case DW_CFA_register
:
4869 if (reg
>= (unsigned int) fc
->ncols
)
4870 reg_prefix
= bad_reg
;
4871 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4873 printf (" DW_CFA_register: %s%s in ",
4874 reg_prefix
, regname (reg
, 0));
4875 puts (regname (roffs
, 0));
4877 if (*reg_prefix
== '\0')
4879 fc
->col_type
[reg
] = DW_CFA_register
;
4880 fc
->col_offset
[reg
] = roffs
;
4884 case DW_CFA_remember_state
:
4885 if (! do_debug_frames_interp
)
4886 printf (" DW_CFA_remember_state\n");
4887 rs
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
4888 rs
->ncols
= fc
->ncols
;
4889 rs
->col_type
= (short int *) xcmalloc (rs
->ncols
,
4890 sizeof (short int));
4891 rs
->col_offset
= (int *) xcmalloc (rs
->ncols
, sizeof (int));
4892 memcpy (rs
->col_type
, fc
->col_type
, rs
->ncols
);
4893 memcpy (rs
->col_offset
, fc
->col_offset
, rs
->ncols
* sizeof (int));
4894 rs
->next
= remembered_state
;
4895 remembered_state
= rs
;
4898 case DW_CFA_restore_state
:
4899 if (! do_debug_frames_interp
)
4900 printf (" DW_CFA_restore_state\n");
4901 rs
= remembered_state
;
4904 remembered_state
= rs
->next
;
4905 frame_need_space (fc
, rs
->ncols
- 1);
4906 memcpy (fc
->col_type
, rs
->col_type
, rs
->ncols
);
4907 memcpy (fc
->col_offset
, rs
->col_offset
,
4908 rs
->ncols
* sizeof (int));
4909 free (rs
->col_type
);
4910 free (rs
->col_offset
);
4913 else if (do_debug_frames_interp
)
4914 printf ("Mismatched DW_CFA_restore_state\n");
4917 case DW_CFA_def_cfa
:
4918 fc
->cfa_reg
= LEB ();
4919 fc
->cfa_offset
= LEB ();
4921 if (! do_debug_frames_interp
)
4922 printf (" DW_CFA_def_cfa: %s ofs %d\n",
4923 regname (fc
->cfa_reg
, 0), fc
->cfa_offset
);
4926 case DW_CFA_def_cfa_register
:
4927 fc
->cfa_reg
= LEB ();
4929 if (! do_debug_frames_interp
)
4930 printf (" DW_CFA_def_cfa_register: %s\n",
4931 regname (fc
->cfa_reg
, 0));
4934 case DW_CFA_def_cfa_offset
:
4935 fc
->cfa_offset
= LEB ();
4936 if (! do_debug_frames_interp
)
4937 printf (" DW_CFA_def_cfa_offset: %d\n", fc
->cfa_offset
);
4941 if (! do_debug_frames_interp
)
4942 printf (" DW_CFA_nop\n");
4945 case DW_CFA_def_cfa_expression
:
4947 if (! do_debug_frames_interp
)
4949 printf (" DW_CFA_def_cfa_expression (");
4950 decode_location_expression (start
, eh_addr_size
, 0, -1,
4958 case DW_CFA_expression
:
4961 if (reg
>= (unsigned int) fc
->ncols
)
4962 reg_prefix
= bad_reg
;
4963 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4965 printf (" DW_CFA_expression: %s%s (",
4966 reg_prefix
, regname (reg
, 0));
4967 decode_location_expression (start
, eh_addr_size
, 0, -1,
4971 if (*reg_prefix
== '\0')
4972 fc
->col_type
[reg
] = DW_CFA_expression
;
4976 case DW_CFA_val_expression
:
4979 if (reg
>= (unsigned int) fc
->ncols
)
4980 reg_prefix
= bad_reg
;
4981 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4983 printf (" DW_CFA_val_expression: %s%s (",
4984 reg_prefix
, regname (reg
, 0));
4985 decode_location_expression (start
, eh_addr_size
, 0, -1,
4989 if (*reg_prefix
== '\0')
4990 fc
->col_type
[reg
] = DW_CFA_val_expression
;
4994 case DW_CFA_offset_extended_sf
:
4997 if (frame_need_space (fc
, reg
) < 0)
4998 reg_prefix
= bad_reg
;
4999 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
5000 printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+ld\n",
5001 reg_prefix
, regname (reg
, 0),
5002 l
* fc
->data_factor
);
5003 if (*reg_prefix
== '\0')
5005 fc
->col_type
[reg
] = DW_CFA_offset
;
5006 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
5010 case DW_CFA_val_offset_sf
:
5013 if (frame_need_space (fc
, reg
) < 0)
5014 reg_prefix
= bad_reg
;
5015 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
5016 printf (" DW_CFA_val_offset_sf: %s%s at cfa%+ld\n",
5017 reg_prefix
, regname (reg
, 0),
5018 l
* fc
->data_factor
);
5019 if (*reg_prefix
== '\0')
5021 fc
->col_type
[reg
] = DW_CFA_val_offset
;
5022 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
5026 case DW_CFA_def_cfa_sf
:
5027 fc
->cfa_reg
= LEB ();
5028 fc
->cfa_offset
= SLEB ();
5029 fc
->cfa_offset
= fc
->cfa_offset
* fc
->data_factor
;
5031 if (! do_debug_frames_interp
)
5032 printf (" DW_CFA_def_cfa_sf: %s ofs %d\n",
5033 regname (fc
->cfa_reg
, 0), fc
->cfa_offset
);
5036 case DW_CFA_def_cfa_offset_sf
:
5037 fc
->cfa_offset
= SLEB ();
5038 fc
->cfa_offset
= fc
->cfa_offset
* fc
->data_factor
;
5039 if (! do_debug_frames_interp
)
5040 printf (" DW_CFA_def_cfa_offset_sf: %d\n", fc
->cfa_offset
);
5043 case DW_CFA_MIPS_advance_loc8
:
5044 ofs
= byte_get (start
, 8); start
+= 8;
5045 if (do_debug_frames_interp
)
5046 frame_display_row (fc
, &need_col_headers
, &max_regs
);
5048 printf (" DW_CFA_MIPS_advance_loc8: %ld to %08lx\n",
5049 ofs
* fc
->code_factor
,
5050 fc
->pc_begin
+ ofs
* fc
->code_factor
);
5051 fc
->pc_begin
+= ofs
* fc
->code_factor
;
5054 case DW_CFA_GNU_window_save
:
5055 if (! do_debug_frames_interp
)
5056 printf (" DW_CFA_GNU_window_save\n");
5059 case DW_CFA_GNU_args_size
:
5061 if (! do_debug_frames_interp
)
5062 printf (" DW_CFA_GNU_args_size: %ld\n", ul
);
5065 case DW_CFA_GNU_negative_offset_extended
:
5068 if (frame_need_space (fc
, reg
) < 0)
5069 reg_prefix
= bad_reg
;
5070 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
5071 printf (" DW_CFA_GNU_negative_offset_extended: %s%s at cfa%+ld\n",
5072 reg_prefix
, regname (reg
, 0),
5073 l
* fc
->data_factor
);
5074 if (*reg_prefix
== '\0')
5076 fc
->col_type
[reg
] = DW_CFA_offset
;
5077 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
5082 if (op
>= DW_CFA_lo_user
&& op
<= DW_CFA_hi_user
)
5083 printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op
);
5085 warn (_("unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op
);
5090 if (do_debug_frames_interp
)
5091 frame_display_row (fc
, &need_col_headers
, &max_regs
);
5094 eh_addr_size
= saved_eh_addr_size
;
5107 display_gdb_index (struct dwarf_section
*section
,
5108 void *file ATTRIBUTE_UNUSED
)
5110 unsigned char *start
= section
->start
;
5112 uint32_t cu_list_offset
, tu_list_offset
;
5113 uint32_t address_table_offset
, symbol_table_offset
, constant_pool_offset
;
5114 unsigned int cu_list_elements
, tu_list_elements
;
5115 unsigned int address_table_size
, symbol_table_slots
;
5116 unsigned char *cu_list
, *tu_list
;
5117 unsigned char *address_table
, *symbol_table
, *constant_pool
;
5120 /* The documentation for the format of this file is in gdb/dwarf2read.c. */
5122 printf (_("Contents of the %s section:\n"), section
->name
);
5124 if (section
->size
< 6 * sizeof (uint32_t))
5126 warn (_("Truncated header in the %s section.\n"), section
->name
);
5130 version
= byte_get_little_endian (start
, 4);
5131 printf (_("Version %ld\n"), (long) version
);
5133 /* Prior versions are obsolete, and future versions may not be
5134 backwards compatible. */
5138 warn (_("The address table data in version 3 may be wrong.\n"));
5141 warn (_("Version 4 does not support case insensitive lookups.\n"));
5146 warn (_("Unsupported version %lu.\n"), (unsigned long) version
);
5150 cu_list_offset
= byte_get_little_endian (start
+ 4, 4);
5151 tu_list_offset
= byte_get_little_endian (start
+ 8, 4);
5152 address_table_offset
= byte_get_little_endian (start
+ 12, 4);
5153 symbol_table_offset
= byte_get_little_endian (start
+ 16, 4);
5154 constant_pool_offset
= byte_get_little_endian (start
+ 20, 4);
5156 if (cu_list_offset
> section
->size
5157 || tu_list_offset
> section
->size
5158 || address_table_offset
> section
->size
5159 || symbol_table_offset
> section
->size
5160 || constant_pool_offset
> section
->size
)
5162 warn (_("Corrupt header in the %s section.\n"), section
->name
);
5166 cu_list_elements
= (tu_list_offset
- cu_list_offset
) / 8;
5167 tu_list_elements
= (address_table_offset
- tu_list_offset
) / 8;
5168 address_table_size
= symbol_table_offset
- address_table_offset
;
5169 symbol_table_slots
= (constant_pool_offset
- symbol_table_offset
) / 8;
5171 cu_list
= start
+ cu_list_offset
;
5172 tu_list
= start
+ tu_list_offset
;
5173 address_table
= start
+ address_table_offset
;
5174 symbol_table
= start
+ symbol_table_offset
;
5175 constant_pool
= start
+ constant_pool_offset
;
5177 printf (_("\nCU table:\n"));
5178 for (i
= 0; i
< cu_list_elements
; i
+= 2)
5180 uint64_t cu_offset
= byte_get_little_endian (cu_list
+ i
* 8, 8);
5181 uint64_t cu_length
= byte_get_little_endian (cu_list
+ i
* 8 + 8, 8);
5183 printf (_("[%3u] 0x%lx - 0x%lx\n"), i
/ 2,
5184 (unsigned long) cu_offset
,
5185 (unsigned long) (cu_offset
+ cu_length
- 1));
5188 printf (_("\nTU table:\n"));
5189 for (i
= 0; i
< tu_list_elements
; i
+= 3)
5191 uint64_t tu_offset
= byte_get_little_endian (tu_list
+ i
* 8, 8);
5192 uint64_t type_offset
= byte_get_little_endian (tu_list
+ i
* 8 + 8, 8);
5193 uint64_t signature
= byte_get_little_endian (tu_list
+ i
* 8 + 16, 8);
5195 printf (_("[%3u] 0x%lx 0x%lx "), i
/ 3,
5196 (unsigned long) tu_offset
,
5197 (unsigned long) type_offset
);
5198 print_dwarf_vma (signature
, 8);
5202 printf (_("\nAddress table:\n"));
5203 for (i
= 0; i
< address_table_size
; i
+= 2 * 8 + 4)
5205 uint64_t low
= byte_get_little_endian (address_table
+ i
, 8);
5206 uint64_t high
= byte_get_little_endian (address_table
+ i
+ 8, 8);
5207 uint32_t cu_index
= byte_get_little_endian (address_table
+ i
+ 16, 4);
5209 print_dwarf_vma (low
, 8);
5210 print_dwarf_vma (high
, 8);
5211 printf (_("%lu\n"), (unsigned long) cu_index
);
5214 printf (_("\nSymbol table:\n"));
5215 for (i
= 0; i
< symbol_table_slots
; ++i
)
5217 uint32_t name_offset
= byte_get_little_endian (symbol_table
+ i
* 8, 4);
5218 uint32_t cu_vector_offset
= byte_get_little_endian (symbol_table
+ i
* 8 + 4, 4);
5219 uint32_t num_cus
, cu
;
5221 if (name_offset
!= 0
5222 || cu_vector_offset
!= 0)
5226 printf ("[%3u] %s:", i
, constant_pool
+ name_offset
);
5227 num_cus
= byte_get_little_endian (constant_pool
+ cu_vector_offset
, 4);
5228 for (j
= 0; j
< num_cus
; ++j
)
5230 cu
= byte_get_little_endian (constant_pool
+ cu_vector_offset
+ 4 + j
* 4, 4);
5231 /* Convert to TU number if it's for a type unit. */
5232 if (cu
>= cu_list_elements
)
5233 printf (" T%lu", (unsigned long) (cu
- cu_list_elements
));
5235 printf (" %lu", (unsigned long) cu
);
5245 display_debug_not_supported (struct dwarf_section
*section
,
5246 void *file ATTRIBUTE_UNUSED
)
5248 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
5255 cmalloc (size_t nmemb
, size_t size
)
5257 /* Check for overflow. */
5258 if (nmemb
>= ~(size_t) 0 / size
)
5261 return malloc (nmemb
* size
);
5265 xcmalloc (size_t nmemb
, size_t size
)
5267 /* Check for overflow. */
5268 if (nmemb
>= ~(size_t) 0 / size
)
5271 return xmalloc (nmemb
* size
);
5275 xcrealloc (void *ptr
, size_t nmemb
, size_t size
)
5277 /* Check for overflow. */
5278 if (nmemb
>= ~(size_t) 0 / size
)
5281 return xrealloc (ptr
, nmemb
* size
);
5285 free_debug_memory (void)
5291 for (i
= 0; i
< max
; i
++)
5292 free_debug_section ((enum dwarf_section_display_enum
) i
);
5294 if (debug_information
!= NULL
)
5296 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
)
5298 for (i
= 0; i
< num_debug_info_entries
; i
++)
5300 if (!debug_information
[i
].max_loc_offsets
)
5302 free (debug_information
[i
].loc_offsets
);
5303 free (debug_information
[i
].have_frame_base
);
5305 if (!debug_information
[i
].max_range_lists
)
5306 free (debug_information
[i
].range_lists
);
5310 free (debug_information
);
5311 debug_information
= NULL
;
5312 num_debug_info_entries
= 0;
5317 dwarf_select_sections_by_names (const char *names
)
5321 const char * option
;
5325 debug_dump_long_opts
;
5327 static const debug_dump_long_opts opts_table
[] =
5329 /* Please keep this table alpha- sorted. */
5330 { "Ranges", & do_debug_ranges
, 1 },
5331 { "abbrev", & do_debug_abbrevs
, 1 },
5332 { "aranges", & do_debug_aranges
, 1 },
5333 { "frames", & do_debug_frames
, 1 },
5334 { "frames-interp", & do_debug_frames_interp
, 1 },
5335 { "info", & do_debug_info
, 1 },
5336 { "line", & do_debug_lines
, FLAG_DEBUG_LINES_RAW
}, /* For backwards compatibility. */
5337 { "rawline", & do_debug_lines
, FLAG_DEBUG_LINES_RAW
},
5338 { "decodedline", & do_debug_lines
, FLAG_DEBUG_LINES_DECODED
},
5339 { "loc", & do_debug_loc
, 1 },
5340 { "macro", & do_debug_macinfo
, 1 },
5341 { "pubnames", & do_debug_pubnames
, 1 },
5342 { "pubtypes", & do_debug_pubtypes
, 1 },
5343 /* This entry is for compatability
5344 with earlier versions of readelf. */
5345 { "ranges", & do_debug_aranges
, 1 },
5346 { "str", & do_debug_str
, 1 },
5347 /* The special .gdb_index section. */
5348 { "gdb_index", & do_gdb_index
, 1 },
5349 /* These trace_* sections are used by Itanium VMS. */
5350 { "trace_abbrev", & do_trace_abbrevs
, 1 },
5351 { "trace_aranges", & do_trace_aranges
, 1 },
5352 { "trace_info", & do_trace_info
, 1 },
5361 const debug_dump_long_opts
* entry
;
5363 for (entry
= opts_table
; entry
->option
; entry
++)
5365 size_t len
= strlen (entry
->option
);
5367 if (strncmp (p
, entry
->option
, len
) == 0
5368 && (p
[len
] == ',' || p
[len
] == '\0'))
5370 * entry
->variable
|= entry
->val
;
5372 /* The --debug-dump=frames-interp option also
5373 enables the --debug-dump=frames option. */
5374 if (do_debug_frames_interp
)
5375 do_debug_frames
= 1;
5382 if (entry
->option
== NULL
)
5384 warn (_("Unrecognized debug option '%s'\n"), p
);
5385 p
= strchr (p
, ',');
5396 dwarf_select_sections_by_letters (const char *letters
)
5398 unsigned int lindex
= 0;
5400 while (letters
[lindex
])
5401 switch (letters
[lindex
++])
5408 do_debug_abbrevs
= 1;
5412 do_debug_lines
|= FLAG_DEBUG_LINES_RAW
;
5416 do_debug_lines
|= FLAG_DEBUG_LINES_DECODED
;
5420 do_debug_pubnames
= 1;
5424 do_debug_pubtypes
= 1;
5428 do_debug_aranges
= 1;
5432 do_debug_ranges
= 1;
5436 do_debug_frames_interp
= 1;
5438 do_debug_frames
= 1;
5442 do_debug_macinfo
= 1;
5454 warn (_("Unrecognized debug option '%s'\n"), optarg
);
5460 dwarf_select_sections_all (void)
5463 do_debug_abbrevs
= 1;
5464 do_debug_lines
= FLAG_DEBUG_LINES_RAW
;
5465 do_debug_pubnames
= 1;
5466 do_debug_pubtypes
= 1;
5467 do_debug_aranges
= 1;
5468 do_debug_ranges
= 1;
5469 do_debug_frames
= 1;
5470 do_debug_macinfo
= 1;
5475 do_trace_abbrevs
= 1;
5476 do_trace_aranges
= 1;
5479 struct dwarf_section_display debug_displays
[] =
5481 { { ".debug_abbrev", ".zdebug_abbrev", NULL
, NULL
, 0, 0 },
5482 display_debug_abbrev
, &do_debug_abbrevs
, 0 },
5483 { { ".debug_aranges", ".zdebug_aranges", NULL
, NULL
, 0, 0 },
5484 display_debug_aranges
, &do_debug_aranges
, 1 },
5485 { { ".debug_frame", ".zdebug_frame", NULL
, NULL
, 0, 0 },
5486 display_debug_frames
, &do_debug_frames
, 1 },
5487 { { ".debug_info", ".zdebug_info", NULL
, NULL
, 0, 0 },
5488 display_debug_info
, &do_debug_info
, 1 },
5489 { { ".debug_line", ".zdebug_line", NULL
, NULL
, 0, 0 },
5490 display_debug_lines
, &do_debug_lines
, 1 },
5491 { { ".debug_pubnames", ".zdebug_pubnames", NULL
, NULL
, 0, 0 },
5492 display_debug_pubnames
, &do_debug_pubnames
, 0 },
5493 { { ".eh_frame", "", NULL
, NULL
, 0, 0 },
5494 display_debug_frames
, &do_debug_frames
, 1 },
5495 { { ".debug_macinfo", ".zdebug_macinfo", NULL
, NULL
, 0, 0 },
5496 display_debug_macinfo
, &do_debug_macinfo
, 0 },
5497 { { ".debug_str", ".zdebug_str", NULL
, NULL
, 0, 0 },
5498 display_debug_str
, &do_debug_str
, 0 },
5499 { { ".debug_loc", ".zdebug_loc", NULL
, NULL
, 0, 0 },
5500 display_debug_loc
, &do_debug_loc
, 1 },
5501 { { ".debug_pubtypes", ".zdebug_pubtypes", NULL
, NULL
, 0, 0 },
5502 display_debug_pubnames
, &do_debug_pubtypes
, 0 },
5503 { { ".debug_ranges", ".zdebug_ranges", NULL
, NULL
, 0, 0 },
5504 display_debug_ranges
, &do_debug_ranges
, 1 },
5505 { { ".debug_static_func", ".zdebug_static_func", NULL
, NULL
, 0, 0 },
5506 display_debug_not_supported
, NULL
, 0 },
5507 { { ".debug_static_vars", ".zdebug_static_vars", NULL
, NULL
, 0, 0 },
5508 display_debug_not_supported
, NULL
, 0 },
5509 { { ".debug_types", ".zdebug_types", NULL
, NULL
, 0, 0 },
5510 display_debug_types
, &do_debug_info
, 1 },
5511 { { ".debug_weaknames", ".zdebug_weaknames", NULL
, NULL
, 0, 0 },
5512 display_debug_not_supported
, NULL
, 0 },
5513 { { ".gdb_index", "", NULL
, NULL
, 0, 0 },
5514 display_gdb_index
, &do_gdb_index
, 0 },
5515 { { ".trace_info", "", NULL
, NULL
, 0, 0 },
5516 display_trace_info
, &do_trace_info
, 1 },
5517 { { ".trace_abbrev", "", NULL
, NULL
, 0, 0 },
5518 display_debug_abbrev
, &do_trace_abbrevs
, 0 },
5519 { { ".trace_aranges", "", NULL
, NULL
, 0, 0 },
5520 display_debug_aranges
, &do_trace_aranges
, 0 }