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
);
1087 case DW_OP_GNU_entry_value
:
1088 uvalue
= read_leb128 (data
, &bytes_read
, 0);
1090 printf ("DW_OP_GNU_entry_value: (");
1091 if (decode_location_expression (data
, pointer_size
, offset_size
,
1092 dwarf_version
, uvalue
,
1093 cu_offset
, section
))
1094 need_frame_base
= 1;
1099 /* GNU extensions. */
1100 case DW_OP_GNU_push_tls_address
:
1101 printf ("DW_OP_GNU_push_tls_address or DW_OP_HP_unknown");
1103 case DW_OP_GNU_uninit
:
1104 printf ("DW_OP_GNU_uninit");
1105 /* FIXME: Is there data associated with this OP ? */
1107 case DW_OP_GNU_encoded_addr
:
1113 addr
= get_encoded_value (data
, encoding
, section
);
1114 data
+= size_of_encoded_value (encoding
);
1116 printf ("DW_OP_GNU_encoded_addr: fmt:%02x addr:", encoding
);
1117 print_dwarf_vma (addr
, pointer_size
);
1120 case DW_OP_GNU_implicit_pointer
:
1121 /* XXX: Strictly speaking for 64-bit DWARF3 files
1122 this ought to be an 8-byte wide computation. */
1123 if (dwarf_version
== -1)
1125 printf (_("(DW_OP_GNU_implicit_pointer in frame info)"));
1126 /* No way to tell where the next op is, so just bail. */
1127 return need_frame_base
;
1129 if (dwarf_version
== 2)
1131 printf ("DW_OP_GNU_implicit_pointer: <0x%s> %s",
1132 dwarf_vmatoa ("x", byte_get (data
, pointer_size
)),
1133 dwarf_vmatoa ("d", read_sleb128 (data
+ pointer_size
,
1135 data
+= pointer_size
+ bytes_read
;
1139 printf ("DW_OP_GNU_implicit_pointer: <0x%s> %s",
1140 dwarf_vmatoa ("x", byte_get (data
, offset_size
)),
1141 dwarf_vmatoa ("d", read_sleb128 (data
+ offset_size
,
1143 data
+= offset_size
+ bytes_read
;
1147 /* HP extensions. */
1148 case DW_OP_HP_is_value
:
1149 printf ("DW_OP_HP_is_value");
1150 /* FIXME: Is there data associated with this OP ? */
1152 case DW_OP_HP_fltconst4
:
1153 printf ("DW_OP_HP_fltconst4");
1154 /* FIXME: Is there data associated with this OP ? */
1156 case DW_OP_HP_fltconst8
:
1157 printf ("DW_OP_HP_fltconst8");
1158 /* FIXME: Is there data associated with this OP ? */
1160 case DW_OP_HP_mod_range
:
1161 printf ("DW_OP_HP_mod_range");
1162 /* FIXME: Is there data associated with this OP ? */
1164 case DW_OP_HP_unmod_range
:
1165 printf ("DW_OP_HP_unmod_range");
1166 /* FIXME: Is there data associated with this OP ? */
1169 printf ("DW_OP_HP_tls");
1170 /* FIXME: Is there data associated with this OP ? */
1173 /* PGI (STMicroelectronics) extensions. */
1174 case DW_OP_PGI_omp_thread_num
:
1175 /* Pushes the thread number for the current thread as it would be
1176 returned by the standard OpenMP library function:
1177 omp_get_thread_num(). The "current thread" is the thread for
1178 which the expression is being evaluated. */
1179 printf ("DW_OP_PGI_omp_thread_num");
1183 if (op
>= DW_OP_lo_user
1184 && op
<= DW_OP_hi_user
)
1185 printf (_("(User defined location op)"));
1187 printf (_("(Unknown location op)"));
1188 /* No way to tell where the next op is, so just bail. */
1189 return need_frame_base
;
1192 /* Separate the ops. */
1197 return need_frame_base
;
1200 static unsigned char *
1201 read_and_display_attr_value (unsigned long attribute
,
1203 unsigned char * data
,
1204 dwarf_vma cu_offset
,
1205 dwarf_vma pointer_size
,
1206 dwarf_vma offset_size
,
1208 debug_info
* debug_info_p
,
1210 struct dwarf_section
* section
)
1212 dwarf_vma uvalue
= 0;
1213 unsigned char *block_start
= NULL
;
1214 unsigned char * orig_data
= data
;
1215 unsigned int bytes_read
;
1222 case DW_FORM_ref_addr
:
1223 if (dwarf_version
== 2)
1225 uvalue
= byte_get (data
, pointer_size
);
1226 data
+= pointer_size
;
1228 else if (dwarf_version
== 3 || dwarf_version
== 4)
1230 uvalue
= byte_get (data
, offset_size
);
1231 data
+= offset_size
;
1234 error (_("Internal error: DWARF version is not 2, 3 or 4.\n"));
1239 uvalue
= byte_get (data
, pointer_size
);
1240 data
+= pointer_size
;
1244 case DW_FORM_sec_offset
:
1245 uvalue
= byte_get (data
, offset_size
);
1246 data
+= offset_size
;
1249 case DW_FORM_flag_present
:
1256 uvalue
= byte_get (data
++, 1);
1261 uvalue
= byte_get (data
, 2);
1267 uvalue
= byte_get (data
, 4);
1272 uvalue
= read_leb128 (data
, & bytes_read
, 1);
1276 case DW_FORM_ref_udata
:
1278 uvalue
= read_leb128 (data
, & bytes_read
, 0);
1282 case DW_FORM_indirect
:
1283 form
= read_leb128 (data
, & bytes_read
, 0);
1286 printf (" %s", get_FORM_name (form
));
1287 return read_and_display_attr_value (attribute
, form
, data
,
1288 cu_offset
, pointer_size
,
1289 offset_size
, dwarf_version
,
1290 debug_info_p
, do_loc
,
1296 case DW_FORM_ref_addr
:
1298 printf (" <0x%s>", dwarf_vmatoa ("x",uvalue
));
1304 case DW_FORM_ref_udata
:
1306 printf (" <0x%s>", dwarf_vmatoa ("x", uvalue
+ cu_offset
));
1311 case DW_FORM_sec_offset
:
1313 printf (" 0x%s", dwarf_vmatoa ("x", uvalue
));
1316 case DW_FORM_flag_present
:
1323 printf (" %s", dwarf_vmatoa ("d", uvalue
));
1330 uvalue
= byte_get (data
, 4);
1331 printf (" 0x%s", dwarf_vmatoa ("x", uvalue
));
1332 printf (" 0x%lx", (unsigned long) byte_get (data
+ 4, 4));
1334 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
1335 && num_debug_info_entries
== 0)
1337 if (sizeof (uvalue
) == 8)
1338 uvalue
= byte_get (data
, 8);
1340 error (_("DW_FORM_data8 is unsupported when sizeof (dwarf_vma) != 8\n"));
1345 case DW_FORM_string
:
1347 printf (" %s", data
);
1348 data
+= strlen ((char *) data
) + 1;
1352 case DW_FORM_exprloc
:
1353 uvalue
= read_leb128 (data
, & bytes_read
, 0);
1354 block_start
= data
+ bytes_read
;
1356 data
= block_start
+ uvalue
;
1358 data
= display_block (block_start
, uvalue
);
1361 case DW_FORM_block1
:
1362 uvalue
= byte_get (data
, 1);
1363 block_start
= data
+ 1;
1365 data
= block_start
+ uvalue
;
1367 data
= display_block (block_start
, uvalue
);
1370 case DW_FORM_block2
:
1371 uvalue
= byte_get (data
, 2);
1372 block_start
= data
+ 2;
1374 data
= block_start
+ uvalue
;
1376 data
= display_block (block_start
, uvalue
);
1379 case DW_FORM_block4
:
1380 uvalue
= byte_get (data
, 4);
1381 block_start
= data
+ 4;
1383 data
= block_start
+ uvalue
;
1385 data
= display_block (block_start
, uvalue
);
1390 printf (_(" (indirect string, offset: 0x%s): %s"),
1391 dwarf_vmatoa ("x", uvalue
),
1392 fetch_indirect_string (uvalue
));
1395 case DW_FORM_indirect
:
1396 /* Handled above. */
1399 case DW_FORM_ref_sig8
:
1403 printf (" signature: ");
1404 for (i
= 0; i
< 8; i
++)
1406 printf ("%02x", (unsigned) byte_get (data
, 1));
1415 warn (_("Unrecognized form: %lu\n"), form
);
1419 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
1420 && num_debug_info_entries
== 0
1421 && debug_info_p
!= NULL
)
1425 case DW_AT_frame_base
:
1426 have_frame_base
= 1;
1427 case DW_AT_location
:
1428 case DW_AT_string_length
:
1429 case DW_AT_return_addr
:
1430 case DW_AT_data_member_location
:
1431 case DW_AT_vtable_elem_location
:
1433 case DW_AT_static_link
:
1434 case DW_AT_use_location
:
1435 case DW_AT_GNU_call_site_value
:
1436 case DW_AT_GNU_call_site_data_value
:
1437 case DW_AT_GNU_call_site_target
:
1438 case DW_AT_GNU_call_site_target_clobbered
:
1439 if (form
== DW_FORM_data4
1440 || form
== DW_FORM_data8
1441 || form
== DW_FORM_sec_offset
)
1443 /* Process location list. */
1444 unsigned int lmax
= debug_info_p
->max_loc_offsets
;
1445 unsigned int num
= debug_info_p
->num_loc_offsets
;
1447 if (lmax
== 0 || num
>= lmax
)
1450 debug_info_p
->loc_offsets
= (dwarf_vma
*)
1451 xcrealloc (debug_info_p
->loc_offsets
,
1452 lmax
, sizeof (*debug_info_p
->loc_offsets
));
1453 debug_info_p
->have_frame_base
= (int *)
1454 xcrealloc (debug_info_p
->have_frame_base
,
1455 lmax
, sizeof (*debug_info_p
->have_frame_base
));
1456 debug_info_p
->max_loc_offsets
= lmax
;
1458 debug_info_p
->loc_offsets
[num
] = uvalue
;
1459 debug_info_p
->have_frame_base
[num
] = have_frame_base
;
1460 debug_info_p
->num_loc_offsets
++;
1465 if (need_base_address
)
1466 debug_info_p
->base_address
= uvalue
;
1470 if (form
== DW_FORM_data4
1471 || form
== DW_FORM_data8
1472 || form
== DW_FORM_sec_offset
)
1474 /* Process range list. */
1475 unsigned int lmax
= debug_info_p
->max_range_lists
;
1476 unsigned int num
= debug_info_p
->num_range_lists
;
1478 if (lmax
== 0 || num
>= lmax
)
1481 debug_info_p
->range_lists
= (dwarf_vma
*)
1482 xcrealloc (debug_info_p
->range_lists
,
1483 lmax
, sizeof (*debug_info_p
->range_lists
));
1484 debug_info_p
->max_range_lists
= lmax
;
1486 debug_info_p
->range_lists
[num
] = uvalue
;
1487 debug_info_p
->num_range_lists
++;
1499 /* For some attributes we can display further information. */
1507 case DW_INL_not_inlined
:
1508 printf (_("(not inlined)"));
1510 case DW_INL_inlined
:
1511 printf (_("(inlined)"));
1513 case DW_INL_declared_not_inlined
:
1514 printf (_("(declared as inline but ignored)"));
1516 case DW_INL_declared_inlined
:
1517 printf (_("(declared as inline and inlined)"));
1520 printf (_(" (Unknown inline attribute value: %s)"),
1521 dwarf_vmatoa ("x", uvalue
));
1526 case DW_AT_language
:
1529 /* Ordered by the numeric value of these constants. */
1530 case DW_LANG_C89
: printf ("(ANSI C)"); break;
1531 case DW_LANG_C
: printf ("(non-ANSI C)"); break;
1532 case DW_LANG_Ada83
: printf ("(Ada)"); break;
1533 case DW_LANG_C_plus_plus
: printf ("(C++)"); break;
1534 case DW_LANG_Cobol74
: printf ("(Cobol 74)"); break;
1535 case DW_LANG_Cobol85
: printf ("(Cobol 85)"); break;
1536 case DW_LANG_Fortran77
: printf ("(FORTRAN 77)"); break;
1537 case DW_LANG_Fortran90
: printf ("(Fortran 90)"); break;
1538 case DW_LANG_Pascal83
: printf ("(ANSI Pascal)"); break;
1539 case DW_LANG_Modula2
: printf ("(Modula 2)"); break;
1540 /* DWARF 2.1 values. */
1541 case DW_LANG_Java
: printf ("(Java)"); break;
1542 case DW_LANG_C99
: printf ("(ANSI C99)"); break;
1543 case DW_LANG_Ada95
: printf ("(ADA 95)"); break;
1544 case DW_LANG_Fortran95
: printf ("(Fortran 95)"); break;
1545 /* DWARF 3 values. */
1546 case DW_LANG_PLI
: printf ("(PLI)"); break;
1547 case DW_LANG_ObjC
: printf ("(Objective C)"); break;
1548 case DW_LANG_ObjC_plus_plus
: printf ("(Objective C++)"); break;
1549 case DW_LANG_UPC
: printf ("(Unified Parallel C)"); break;
1550 case DW_LANG_D
: printf ("(D)"); break;
1551 /* DWARF 4 values. */
1552 case DW_LANG_Python
: printf ("(Python)"); break;
1553 /* MIPS extension. */
1554 case DW_LANG_Mips_Assembler
: printf ("(MIPS assembler)"); break;
1555 /* UPC extension. */
1556 case DW_LANG_Upc
: printf ("(Unified Parallel C)"); break;
1558 if (uvalue
>= DW_LANG_lo_user
&& uvalue
<= DW_LANG_hi_user
)
1559 printf ("(implementation defined: %s)",
1560 dwarf_vmatoa ("x", uvalue
));
1562 printf ("(Unknown: %s)", dwarf_vmatoa ("x", uvalue
));
1567 case DW_AT_encoding
:
1570 case DW_ATE_void
: printf ("(void)"); break;
1571 case DW_ATE_address
: printf ("(machine address)"); break;
1572 case DW_ATE_boolean
: printf ("(boolean)"); break;
1573 case DW_ATE_complex_float
: printf ("(complex float)"); break;
1574 case DW_ATE_float
: printf ("(float)"); break;
1575 case DW_ATE_signed
: printf ("(signed)"); break;
1576 case DW_ATE_signed_char
: printf ("(signed char)"); break;
1577 case DW_ATE_unsigned
: printf ("(unsigned)"); break;
1578 case DW_ATE_unsigned_char
: printf ("(unsigned char)"); break;
1579 /* DWARF 2.1 values: */
1580 case DW_ATE_imaginary_float
: printf ("(imaginary float)"); break;
1581 case DW_ATE_decimal_float
: printf ("(decimal float)"); break;
1582 /* DWARF 3 values: */
1583 case DW_ATE_packed_decimal
: printf ("(packed_decimal)"); break;
1584 case DW_ATE_numeric_string
: printf ("(numeric_string)"); break;
1585 case DW_ATE_edited
: printf ("(edited)"); break;
1586 case DW_ATE_signed_fixed
: printf ("(signed_fixed)"); break;
1587 case DW_ATE_unsigned_fixed
: printf ("(unsigned_fixed)"); break;
1588 /* HP extensions: */
1589 case DW_ATE_HP_float80
: printf ("(HP_float80)"); break;
1590 case DW_ATE_HP_complex_float80
: printf ("(HP_complex_float80)"); break;
1591 case DW_ATE_HP_float128
: printf ("(HP_float128)"); break;
1592 case DW_ATE_HP_complex_float128
:printf ("(HP_complex_float128)"); break;
1593 case DW_ATE_HP_floathpintel
: printf ("(HP_floathpintel)"); break;
1594 case DW_ATE_HP_imaginary_float80
: printf ("(HP_imaginary_float80)"); break;
1595 case DW_ATE_HP_imaginary_float128
: printf ("(HP_imaginary_float128)"); break;
1598 if (uvalue
>= DW_ATE_lo_user
1599 && uvalue
<= DW_ATE_hi_user
)
1600 printf ("(user defined type)");
1602 printf ("(unknown type)");
1607 case DW_AT_accessibility
:
1610 case DW_ACCESS_public
: printf ("(public)"); break;
1611 case DW_ACCESS_protected
: printf ("(protected)"); break;
1612 case DW_ACCESS_private
: printf ("(private)"); break;
1614 printf ("(unknown accessibility)");
1619 case DW_AT_visibility
:
1622 case DW_VIS_local
: printf ("(local)"); break;
1623 case DW_VIS_exported
: printf ("(exported)"); break;
1624 case DW_VIS_qualified
: printf ("(qualified)"); break;
1625 default: printf ("(unknown visibility)"); break;
1629 case DW_AT_virtuality
:
1632 case DW_VIRTUALITY_none
: printf ("(none)"); break;
1633 case DW_VIRTUALITY_virtual
: printf ("(virtual)"); break;
1634 case DW_VIRTUALITY_pure_virtual
:printf ("(pure_virtual)"); break;
1635 default: printf ("(unknown virtuality)"); break;
1639 case DW_AT_identifier_case
:
1642 case DW_ID_case_sensitive
: printf ("(case_sensitive)"); break;
1643 case DW_ID_up_case
: printf ("(up_case)"); break;
1644 case DW_ID_down_case
: printf ("(down_case)"); break;
1645 case DW_ID_case_insensitive
: printf ("(case_insensitive)"); break;
1646 default: printf ("(unknown case)"); break;
1650 case DW_AT_calling_convention
:
1653 case DW_CC_normal
: printf ("(normal)"); break;
1654 case DW_CC_program
: printf ("(program)"); break;
1655 case DW_CC_nocall
: printf ("(nocall)"); break;
1657 if (uvalue
>= DW_CC_lo_user
1658 && uvalue
<= DW_CC_hi_user
)
1659 printf ("(user defined)");
1661 printf ("(unknown convention)");
1665 case DW_AT_ordering
:
1668 case -1: printf ("(undefined)"); break;
1669 case 0: printf ("(row major)"); break;
1670 case 1: printf ("(column major)"); break;
1674 case DW_AT_frame_base
:
1675 have_frame_base
= 1;
1676 case DW_AT_location
:
1677 case DW_AT_string_length
:
1678 case DW_AT_return_addr
:
1679 case DW_AT_data_member_location
:
1680 case DW_AT_vtable_elem_location
:
1682 case DW_AT_static_link
:
1683 case DW_AT_use_location
:
1684 case DW_AT_GNU_call_site_value
:
1685 case DW_AT_GNU_call_site_data_value
:
1686 case DW_AT_GNU_call_site_target
:
1687 case DW_AT_GNU_call_site_target_clobbered
:
1688 if (form
== DW_FORM_data4
1689 || form
== DW_FORM_data8
1690 || form
== DW_FORM_sec_offset
)
1691 printf (_("(location list)"));
1693 case DW_AT_allocated
:
1694 case DW_AT_associated
:
1695 case DW_AT_data_location
:
1697 case DW_AT_upper_bound
:
1698 case DW_AT_lower_bound
:
1701 int need_frame_base
;
1704 need_frame_base
= decode_location_expression (block_start
,
1709 cu_offset
, section
);
1711 if (need_frame_base
&& !have_frame_base
)
1712 printf (_(" [without DW_AT_frame_base]"));
1718 if (form
== DW_FORM_ref_sig8
)
1721 if (form
== DW_FORM_ref1
1722 || form
== DW_FORM_ref2
1723 || form
== DW_FORM_ref4
)
1724 uvalue
+= cu_offset
;
1726 if (uvalue
>= section
->size
)
1727 warn (_("Offset %s used as value for DW_AT_import attribute of DIE at offset %lx is too big.\n"),
1728 dwarf_vmatoa ("x", uvalue
),
1729 (unsigned long) (orig_data
- section
->start
));
1732 unsigned long abbrev_number
;
1733 abbrev_entry
* entry
;
1735 abbrev_number
= read_leb128 (section
->start
+ uvalue
, NULL
, 0);
1737 printf ("[Abbrev Number: %ld", abbrev_number
);
1738 for (entry
= first_abbrev
; entry
!= NULL
; entry
= entry
->next
)
1739 if (entry
->entry
== abbrev_number
)
1742 printf (" (%s)", get_TAG_name (entry
->tag
));
1756 get_AT_name (unsigned long attribute
)
1760 case DW_AT_sibling
: return "DW_AT_sibling";
1761 case DW_AT_location
: return "DW_AT_location";
1762 case DW_AT_name
: return "DW_AT_name";
1763 case DW_AT_ordering
: return "DW_AT_ordering";
1764 case DW_AT_subscr_data
: return "DW_AT_subscr_data";
1765 case DW_AT_byte_size
: return "DW_AT_byte_size";
1766 case DW_AT_bit_offset
: return "DW_AT_bit_offset";
1767 case DW_AT_bit_size
: return "DW_AT_bit_size";
1768 case DW_AT_element_list
: return "DW_AT_element_list";
1769 case DW_AT_stmt_list
: return "DW_AT_stmt_list";
1770 case DW_AT_low_pc
: return "DW_AT_low_pc";
1771 case DW_AT_high_pc
: return "DW_AT_high_pc";
1772 case DW_AT_language
: return "DW_AT_language";
1773 case DW_AT_member
: return "DW_AT_member";
1774 case DW_AT_discr
: return "DW_AT_discr";
1775 case DW_AT_discr_value
: return "DW_AT_discr_value";
1776 case DW_AT_visibility
: return "DW_AT_visibility";
1777 case DW_AT_import
: return "DW_AT_import";
1778 case DW_AT_string_length
: return "DW_AT_string_length";
1779 case DW_AT_common_reference
: return "DW_AT_common_reference";
1780 case DW_AT_comp_dir
: return "DW_AT_comp_dir";
1781 case DW_AT_const_value
: return "DW_AT_const_value";
1782 case DW_AT_containing_type
: return "DW_AT_containing_type";
1783 case DW_AT_default_value
: return "DW_AT_default_value";
1784 case DW_AT_inline
: return "DW_AT_inline";
1785 case DW_AT_is_optional
: return "DW_AT_is_optional";
1786 case DW_AT_lower_bound
: return "DW_AT_lower_bound";
1787 case DW_AT_producer
: return "DW_AT_producer";
1788 case DW_AT_prototyped
: return "DW_AT_prototyped";
1789 case DW_AT_return_addr
: return "DW_AT_return_addr";
1790 case DW_AT_start_scope
: return "DW_AT_start_scope";
1791 case DW_AT_stride_size
: return "DW_AT_stride_size";
1792 case DW_AT_upper_bound
: return "DW_AT_upper_bound";
1793 case DW_AT_abstract_origin
: return "DW_AT_abstract_origin";
1794 case DW_AT_accessibility
: return "DW_AT_accessibility";
1795 case DW_AT_address_class
: return "DW_AT_address_class";
1796 case DW_AT_artificial
: return "DW_AT_artificial";
1797 case DW_AT_base_types
: return "DW_AT_base_types";
1798 case DW_AT_calling_convention
: return "DW_AT_calling_convention";
1799 case DW_AT_count
: return "DW_AT_count";
1800 case DW_AT_data_member_location
: return "DW_AT_data_member_location";
1801 case DW_AT_decl_column
: return "DW_AT_decl_column";
1802 case DW_AT_decl_file
: return "DW_AT_decl_file";
1803 case DW_AT_decl_line
: return "DW_AT_decl_line";
1804 case DW_AT_declaration
: return "DW_AT_declaration";
1805 case DW_AT_discr_list
: return "DW_AT_discr_list";
1806 case DW_AT_encoding
: return "DW_AT_encoding";
1807 case DW_AT_external
: return "DW_AT_external";
1808 case DW_AT_frame_base
: return "DW_AT_frame_base";
1809 case DW_AT_friend
: return "DW_AT_friend";
1810 case DW_AT_identifier_case
: return "DW_AT_identifier_case";
1811 case DW_AT_macro_info
: return "DW_AT_macro_info";
1812 case DW_AT_namelist_items
: return "DW_AT_namelist_items";
1813 case DW_AT_priority
: return "DW_AT_priority";
1814 case DW_AT_segment
: return "DW_AT_segment";
1815 case DW_AT_specification
: return "DW_AT_specification";
1816 case DW_AT_static_link
: return "DW_AT_static_link";
1817 case DW_AT_type
: return "DW_AT_type";
1818 case DW_AT_use_location
: return "DW_AT_use_location";
1819 case DW_AT_variable_parameter
: return "DW_AT_variable_parameter";
1820 case DW_AT_virtuality
: return "DW_AT_virtuality";
1821 case DW_AT_vtable_elem_location
: return "DW_AT_vtable_elem_location";
1822 /* DWARF 2.1 values. */
1823 case DW_AT_allocated
: return "DW_AT_allocated";
1824 case DW_AT_associated
: return "DW_AT_associated";
1825 case DW_AT_data_location
: return "DW_AT_data_location";
1826 case DW_AT_stride
: return "DW_AT_stride";
1827 case DW_AT_entry_pc
: return "DW_AT_entry_pc";
1828 case DW_AT_use_UTF8
: return "DW_AT_use_UTF8";
1829 case DW_AT_extension
: return "DW_AT_extension";
1830 case DW_AT_ranges
: return "DW_AT_ranges";
1831 case DW_AT_trampoline
: return "DW_AT_trampoline";
1832 case DW_AT_call_column
: return "DW_AT_call_column";
1833 case DW_AT_call_file
: return "DW_AT_call_file";
1834 case DW_AT_call_line
: return "DW_AT_call_line";
1835 case DW_AT_description
: return "DW_AT_description";
1836 case DW_AT_binary_scale
: return "DW_AT_binary_scale";
1837 case DW_AT_decimal_scale
: return "DW_AT_decimal_scale";
1838 case DW_AT_small
: return "DW_AT_small";
1839 case DW_AT_decimal_sign
: return "DW_AT_decimal_sign";
1840 case DW_AT_digit_count
: return "DW_AT_digit_count";
1841 case DW_AT_picture_string
: return "DW_AT_picture_string";
1842 case DW_AT_mutable
: return "DW_AT_mutable";
1843 case DW_AT_threads_scaled
: return "DW_AT_threads_scaled";
1844 case DW_AT_explicit
: return "DW_AT_explicit";
1845 case DW_AT_object_pointer
: return "DW_AT_object_pointer";
1846 case DW_AT_endianity
: return "DW_AT_endianity";
1847 case DW_AT_elemental
: return "DW_AT_elemental";
1848 case DW_AT_pure
: return "DW_AT_pure";
1849 case DW_AT_recursive
: return "DW_AT_recursive";
1850 /* DWARF 4 values. */
1851 case DW_AT_signature
: return "DW_AT_signature";
1852 case DW_AT_main_subprogram
: return "DW_AT_main_subprogram";
1853 case DW_AT_data_bit_offset
: return "DW_AT_data_bit_offset";
1854 case DW_AT_const_expr
: return "DW_AT_const_expr";
1855 case DW_AT_enum_class
: return "DW_AT_enum_class";
1856 case DW_AT_linkage_name
: return "DW_AT_linkage_name";
1858 /* HP and SGI/MIPS extensions. */
1859 case DW_AT_MIPS_loop_begin
: return "DW_AT_MIPS_loop_begin";
1860 case DW_AT_MIPS_tail_loop_begin
: return "DW_AT_MIPS_tail_loop_begin";
1861 case DW_AT_MIPS_epilog_begin
: return "DW_AT_MIPS_epilog_begin";
1862 case DW_AT_MIPS_loop_unroll_factor
: return "DW_AT_MIPS_loop_unroll_factor";
1863 case DW_AT_MIPS_software_pipeline_depth
: return "DW_AT_MIPS_software_pipeline_depth";
1864 case DW_AT_MIPS_linkage_name
: return "DW_AT_MIPS_linkage_name";
1865 case DW_AT_MIPS_stride
: return "DW_AT_MIPS_stride";
1866 case DW_AT_MIPS_abstract_name
: return "DW_AT_MIPS_abstract_name";
1867 case DW_AT_MIPS_clone_origin
: return "DW_AT_MIPS_clone_origin";
1868 case DW_AT_MIPS_has_inlines
: return "DW_AT_MIPS_has_inlines";
1870 /* HP Extensions. */
1871 case DW_AT_HP_block_index
: return "DW_AT_HP_block_index";
1872 case DW_AT_HP_actuals_stmt_list
: return "DW_AT_HP_actuals_stmt_list";
1873 case DW_AT_HP_proc_per_section
: return "DW_AT_HP_proc_per_section";
1874 case DW_AT_HP_raw_data_ptr
: return "DW_AT_HP_raw_data_ptr";
1875 case DW_AT_HP_pass_by_reference
: return "DW_AT_HP_pass_by_reference";
1876 case DW_AT_HP_opt_level
: return "DW_AT_HP_opt_level";
1877 case DW_AT_HP_prof_version_id
: return "DW_AT_HP_prof_version_id";
1878 case DW_AT_HP_opt_flags
: return "DW_AT_HP_opt_flags";
1879 case DW_AT_HP_cold_region_low_pc
: return "DW_AT_HP_cold_region_low_pc";
1880 case DW_AT_HP_cold_region_high_pc
: return "DW_AT_HP_cold_region_high_pc";
1881 case DW_AT_HP_all_variables_modifiable
: return "DW_AT_HP_all_variables_modifiable";
1882 case DW_AT_HP_linkage_name
: return "DW_AT_HP_linkage_name";
1883 case DW_AT_HP_prof_flags
: return "DW_AT_HP_prof_flags";
1885 /* One value is shared by the MIPS and HP extensions: */
1886 case DW_AT_MIPS_fde
: return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable";
1888 /* GNU extensions. */
1889 case DW_AT_sf_names
: return "DW_AT_sf_names";
1890 case DW_AT_src_info
: return "DW_AT_src_info";
1891 case DW_AT_mac_info
: return "DW_AT_mac_info";
1892 case DW_AT_src_coords
: return "DW_AT_src_coords";
1893 case DW_AT_body_begin
: return "DW_AT_body_begin";
1894 case DW_AT_body_end
: return "DW_AT_body_end";
1895 case DW_AT_GNU_vector
: return "DW_AT_GNU_vector";
1896 case DW_AT_GNU_guarded_by
: return "DW_AT_GNU_guarded_by";
1897 case DW_AT_GNU_pt_guarded_by
: return "DW_AT_GNU_pt_guarded_by";
1898 case DW_AT_GNU_guarded
: return "DW_AT_GNU_guarded";
1899 case DW_AT_GNU_pt_guarded
: return "DW_AT_GNU_pt_guarded";
1900 case DW_AT_GNU_locks_excluded
: return "DW_AT_GNU_locks_excluded";
1901 case DW_AT_GNU_exclusive_locks_required
: return "DW_AT_GNU_exclusive_locks_required";
1902 case DW_AT_GNU_shared_locks_required
: return "DW_AT_GNU_shared_locks_required";
1903 case DW_AT_GNU_odr_signature
: return "DW_AT_GNU_odr_signature";
1904 case DW_AT_use_GNAT_descriptive_type
: return "DW_AT_use_GNAT_descriptive_type";
1905 case DW_AT_GNAT_descriptive_type
: return "DW_AT_GNAT_descriptive_type";
1906 case DW_AT_GNU_call_site_value
: return "DW_AT_GNU_call_site_value";
1907 case DW_AT_GNU_call_site_data_value
: return "DW_AT_GNU_call_site_data_value";
1908 case DW_AT_GNU_call_site_target
: return "DW_AT_GNU_call_site_target";
1909 case DW_AT_GNU_call_site_target_clobbered
: return "DW_AT_GNU_call_site_target_clobbered";
1910 case DW_AT_GNU_tail_call
: return "DW_AT_GNU_tail_call";
1911 case DW_AT_GNU_all_tail_call_sites
: return "DW_AT_GNU_all_tail_call_sites";
1912 case DW_AT_GNU_all_call_sites
: return "DW_AT_GNU_all_call_sites";
1913 case DW_AT_GNU_all_source_call_sites
: return "DW_AT_GNU_all_source_call_sites";
1915 /* UPC extension. */
1916 case DW_AT_upc_threads_scaled
: return "DW_AT_upc_threads_scaled";
1918 /* PGI (STMicroelectronics) extensions. */
1919 case DW_AT_PGI_lbase
: return "DW_AT_PGI_lbase";
1920 case DW_AT_PGI_soffset
: return "DW_AT_PGI_soffset";
1921 case DW_AT_PGI_lstride
: return "DW_AT_PGI_lstride";
1925 static char buffer
[100];
1927 snprintf (buffer
, sizeof (buffer
), _("Unknown AT value: %lx"),
1934 static unsigned char *
1935 read_and_display_attr (unsigned long attribute
,
1937 unsigned char * data
,
1938 dwarf_vma cu_offset
,
1939 dwarf_vma pointer_size
,
1940 dwarf_vma offset_size
,
1942 debug_info
* debug_info_p
,
1944 struct dwarf_section
* section
)
1947 printf (" %-18s:", get_AT_name (attribute
));
1948 data
= read_and_display_attr_value (attribute
, form
, data
, cu_offset
,
1949 pointer_size
, offset_size
,
1950 dwarf_version
, debug_info_p
,
1958 /* Process the contents of a .debug_info section. If do_loc is non-zero
1959 then we are scanning for location lists and we do not want to display
1960 anything to the user. If do_types is non-zero, we are processing
1961 a .debug_types section instead of a .debug_info section. */
1964 process_debug_info (struct dwarf_section
*section
,
1966 enum dwarf_section_display_enum abbrev_sec
,
1970 unsigned char *start
= section
->start
;
1971 unsigned char *end
= start
+ section
->size
;
1972 unsigned char *section_begin
;
1974 unsigned int num_units
= 0;
1976 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
1977 && num_debug_info_entries
== 0
1982 /* First scan the section to get the number of comp units. */
1983 for (section_begin
= start
, num_units
= 0; section_begin
< end
;
1986 /* Read the first 4 bytes. For a 32-bit DWARF section, this
1987 will be the length. For a 64-bit DWARF section, it'll be
1988 the escape code 0xffffffff followed by an 8 byte length. */
1989 length
= byte_get (section_begin
, 4);
1991 if (length
== 0xffffffff)
1993 length
= byte_get (section_begin
+ 4, 8);
1994 section_begin
+= length
+ 12;
1996 else if (length
>= 0xfffffff0 && length
< 0xffffffff)
1998 warn (_("Reserved length value (0x%s) found in section %s\n"),
1999 dwarf_vmatoa ("x", length
), section
->name
);
2003 section_begin
+= length
+ 4;
2005 /* Negative values are illegal, they may even cause infinite
2006 looping. This can happen if we can't accurately apply
2007 relocations to an object file. */
2008 if ((signed long) length
<= 0)
2010 warn (_("Corrupt unit length (0x%s) found in section %s\n"),
2011 dwarf_vmatoa ("x", length
), section
->name
);
2018 error (_("No comp units in %s section ?"), section
->name
);
2022 /* Then allocate an array to hold the information. */
2023 debug_information
= (debug_info
*) cmalloc (num_units
,
2024 sizeof (* debug_information
));
2025 if (debug_information
== NULL
)
2027 error (_("Not enough memory for a debug info array of %u entries"),
2035 if (dwarf_start_die
== 0)
2036 printf (_("Contents of the %s section:\n\n"), section
->name
);
2038 load_debug_section (str
, file
);
2041 load_debug_section (abbrev_sec
, file
);
2042 if (debug_displays
[abbrev_sec
].section
.start
== NULL
)
2044 warn (_("Unable to locate %s section!\n"),
2045 debug_displays
[abbrev_sec
].section
.name
);
2049 for (section_begin
= start
, unit
= 0; start
< end
; unit
++)
2051 DWARF2_Internal_CompUnit compunit
;
2052 unsigned char *hdrptr
;
2053 unsigned char *tags
;
2054 int level
, last_level
, saved_level
;
2055 dwarf_vma cu_offset
;
2057 int initial_length_size
;
2058 unsigned char signature
[8] = { 0 };
2059 dwarf_vma type_offset
= 0;
2063 compunit
.cu_length
= byte_get (hdrptr
, 4);
2066 if (compunit
.cu_length
== 0xffffffff)
2068 compunit
.cu_length
= byte_get (hdrptr
, 8);
2071 initial_length_size
= 12;
2076 initial_length_size
= 4;
2079 compunit
.cu_version
= byte_get (hdrptr
, 2);
2082 cu_offset
= start
- section_begin
;
2084 compunit
.cu_abbrev_offset
= byte_get (hdrptr
, offset_size
);
2085 hdrptr
+= offset_size
;
2087 compunit
.cu_pointer_size
= byte_get (hdrptr
, 1);
2094 for (i
= 0; i
< 8; i
++)
2096 signature
[i
] = byte_get (hdrptr
, 1);
2100 type_offset
= byte_get (hdrptr
, offset_size
);
2101 hdrptr
+= offset_size
;
2104 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
2105 && num_debug_info_entries
== 0
2108 debug_information
[unit
].cu_offset
= cu_offset
;
2109 debug_information
[unit
].pointer_size
2110 = compunit
.cu_pointer_size
;
2111 debug_information
[unit
].offset_size
= offset_size
;
2112 debug_information
[unit
].dwarf_version
= compunit
.cu_version
;
2113 debug_information
[unit
].base_address
= 0;
2114 debug_information
[unit
].loc_offsets
= NULL
;
2115 debug_information
[unit
].have_frame_base
= NULL
;
2116 debug_information
[unit
].max_loc_offsets
= 0;
2117 debug_information
[unit
].num_loc_offsets
= 0;
2118 debug_information
[unit
].range_lists
= NULL
;
2119 debug_information
[unit
].max_range_lists
= 0;
2120 debug_information
[unit
].num_range_lists
= 0;
2123 if (!do_loc
&& dwarf_start_die
== 0)
2125 printf (_(" Compilation Unit @ offset 0x%s:\n"),
2126 dwarf_vmatoa ("x", cu_offset
));
2127 printf (_(" Length: 0x%s (%s)\n"),
2128 dwarf_vmatoa ("x", compunit
.cu_length
),
2129 offset_size
== 8 ? "64-bit" : "32-bit");
2130 printf (_(" Version: %d\n"), compunit
.cu_version
);
2131 printf (_(" Abbrev Offset: %s\n"),
2132 dwarf_vmatoa ("d", compunit
.cu_abbrev_offset
));
2133 printf (_(" Pointer Size: %d\n"), compunit
.cu_pointer_size
);
2137 printf (_(" Signature: "));
2138 for (i
= 0; i
< 8; i
++)
2139 printf ("%02x", signature
[i
]);
2141 printf (_(" Type Offset: 0x%s\n"),
2142 dwarf_vmatoa ("x", type_offset
));
2146 if (cu_offset
+ compunit
.cu_length
+ initial_length_size
2149 warn (_("Debug info is corrupted, length of CU at %s"
2150 " extends beyond end of section (length = %s)\n"),
2151 dwarf_vmatoa ("x", cu_offset
),
2152 dwarf_vmatoa ("x", compunit
.cu_length
));
2156 start
+= compunit
.cu_length
+ initial_length_size
;
2158 if (compunit
.cu_version
!= 2
2159 && compunit
.cu_version
!= 3
2160 && compunit
.cu_version
!= 4)
2162 warn (_("CU at offset %s contains corrupt or "
2163 "unsupported version number: %d.\n"),
2164 dwarf_vmatoa ("x", cu_offset
), compunit
.cu_version
);
2170 /* Process the abbrevs used by this compilation unit. DWARF
2171 sections under Mach-O have non-zero addresses. */
2172 if (compunit
.cu_abbrev_offset
>= debug_displays
[abbrev_sec
].section
.size
)
2173 warn (_("Debug info is corrupted, abbrev offset (%lx) is larger than abbrev section size (%lx)\n"),
2174 (unsigned long) compunit
.cu_abbrev_offset
,
2175 (unsigned long) debug_displays
[abbrev_sec
].section
.size
);
2177 process_abbrev_section
2178 ((unsigned char *) debug_displays
[abbrev_sec
].section
.start
2179 + compunit
.cu_abbrev_offset
,
2180 (unsigned char *) debug_displays
[abbrev_sec
].section
.start
2181 + debug_displays
[abbrev_sec
].section
.size
);
2186 while (tags
< start
)
2188 unsigned int bytes_read
;
2189 unsigned long abbrev_number
;
2190 unsigned long die_offset
;
2191 abbrev_entry
*entry
;
2193 int do_printing
= 1;
2195 die_offset
= tags
- section_begin
;
2197 abbrev_number
= read_leb128 (tags
, & bytes_read
, 0);
2200 /* A null DIE marks the end of a list of siblings or it may also be
2201 a section padding. */
2202 if (abbrev_number
== 0)
2204 /* Check if it can be a section padding for the last CU. */
2205 if (level
== 0 && start
== end
)
2209 for (chk
= tags
; chk
< start
; chk
++)
2219 static unsigned num_bogus_warns
= 0;
2221 if (num_bogus_warns
< 3)
2223 warn (_("Bogus end-of-siblings marker detected at offset %lx in .debug_info section\n"),
2226 if (num_bogus_warns
== 3)
2227 warn (_("Further warnings about bogus end-of-sibling markers suppressed\n"));
2230 if (dwarf_start_die
!= 0 && level
< saved_level
)
2237 if (dwarf_start_die
!= 0 && die_offset
< dwarf_start_die
)
2241 if (dwarf_start_die
!= 0 && die_offset
== dwarf_start_die
)
2242 saved_level
= level
;
2243 do_printing
= (dwarf_cutoff_level
== -1
2244 || level
< dwarf_cutoff_level
);
2246 printf (_(" <%d><%lx>: Abbrev Number: %lu"),
2247 level
, die_offset
, abbrev_number
);
2248 else if (dwarf_cutoff_level
== -1
2249 || last_level
< dwarf_cutoff_level
)
2250 printf (_(" <%d><%lx>: ...\n"), level
, die_offset
);
2255 /* Scan through the abbreviation list until we reach the
2257 for (entry
= first_abbrev
;
2258 entry
&& entry
->entry
!= abbrev_number
;
2259 entry
= entry
->next
)
2264 if (!do_loc
&& do_printing
)
2269 warn (_("DIE at offset %lx refers to abbreviation number %lu which does not exist\n"),
2270 die_offset
, abbrev_number
);
2274 if (!do_loc
&& do_printing
)
2275 printf (" (%s)\n", get_TAG_name (entry
->tag
));
2280 need_base_address
= 0;
2282 case DW_TAG_compile_unit
:
2283 need_base_address
= 1;
2285 case DW_TAG_entry_point
:
2286 case DW_TAG_subprogram
:
2287 need_base_address
= 0;
2288 /* Assuming that there is no DW_AT_frame_base. */
2289 have_frame_base
= 0;
2293 for (attr
= entry
->first_attr
; attr
; attr
= attr
->next
)
2297 if (! do_loc
&& do_printing
)
2298 /* Show the offset from where the tag was extracted. */
2299 printf (" <%lx>", (unsigned long)(tags
- section_begin
));
2301 arg
= debug_information
;
2302 if (debug_information
)
2305 tags
= read_and_display_attr (attr
->attribute
,
2308 compunit
.cu_pointer_size
,
2310 compunit
.cu_version
,
2312 do_loc
|| ! do_printing
, section
);
2315 if (entry
->children
)
2320 /* Set num_debug_info_entries here so that it can be used to check if
2321 we need to process .debug_loc and .debug_ranges sections. */
2322 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
2323 && num_debug_info_entries
== 0
2325 num_debug_info_entries
= num_units
;
2333 /* Locate and scan the .debug_info section in the file and record the pointer
2334 sizes and offsets for the compilation units in it. Usually an executable
2335 will have just one pointer size, but this is not guaranteed, and so we try
2336 not to make any assumptions. Returns zero upon failure, or the number of
2337 compilation units upon success. */
2340 load_debug_info (void * file
)
2342 /* Reset the last pointer size so that we can issue correct error
2343 messages if we are displaying the contents of more than one section. */
2344 last_pointer_size
= 0;
2345 warned_about_missing_comp_units
= FALSE
;
2347 /* If we have already tried and failed to load the .debug_info
2348 section then do not bother to repear the task. */
2349 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
2352 /* If we already have the information there is nothing else to do. */
2353 if (num_debug_info_entries
> 0)
2354 return num_debug_info_entries
;
2356 if (load_debug_section (info
, file
)
2357 && process_debug_info (&debug_displays
[info
].section
, file
, abbrev
, 1, 0))
2358 return num_debug_info_entries
;
2360 num_debug_info_entries
= DEBUG_INFO_UNAVAILABLE
;
2365 display_debug_lines_raw (struct dwarf_section
*section
,
2366 unsigned char *data
,
2369 unsigned char *start
= section
->start
;
2371 printf (_("Raw dump of debug contents of section %s:\n\n"),
2376 DWARF2_Internal_LineInfo linfo
;
2377 unsigned char *standard_opcodes
;
2378 unsigned char *end_of_sequence
;
2379 unsigned char *hdrptr
;
2380 unsigned long hdroff
;
2381 int initial_length_size
;
2386 hdroff
= hdrptr
- start
;
2388 /* Check the length of the block. */
2389 linfo
.li_length
= byte_get (hdrptr
, 4);
2392 if (linfo
.li_length
== 0xffffffff)
2394 /* This section is 64-bit DWARF 3. */
2395 linfo
.li_length
= byte_get (hdrptr
, 8);
2398 initial_length_size
= 12;
2403 initial_length_size
= 4;
2406 if (linfo
.li_length
+ initial_length_size
> section
->size
)
2409 (_("The information in section %s appears to be corrupt - the section is too small\n"),
2414 /* Check its version number. */
2415 linfo
.li_version
= byte_get (hdrptr
, 2);
2417 if (linfo
.li_version
!= 2
2418 && linfo
.li_version
!= 3
2419 && linfo
.li_version
!= 4)
2421 warn (_("Only DWARF version 2, 3 and 4 line info is currently supported.\n"));
2425 linfo
.li_prologue_length
= byte_get (hdrptr
, offset_size
);
2426 hdrptr
+= offset_size
;
2427 linfo
.li_min_insn_length
= byte_get (hdrptr
, 1);
2429 if (linfo
.li_version
>= 4)
2431 linfo
.li_max_ops_per_insn
= byte_get (hdrptr
, 1);
2433 if (linfo
.li_max_ops_per_insn
== 0)
2435 warn (_("Invalid maximum operations per insn.\n"));
2440 linfo
.li_max_ops_per_insn
= 1;
2441 linfo
.li_default_is_stmt
= byte_get (hdrptr
, 1);
2443 linfo
.li_line_base
= byte_get (hdrptr
, 1);
2445 linfo
.li_line_range
= byte_get (hdrptr
, 1);
2447 linfo
.li_opcode_base
= byte_get (hdrptr
, 1);
2450 /* Sign extend the line base field. */
2451 linfo
.li_line_base
<<= 24;
2452 linfo
.li_line_base
>>= 24;
2454 printf (_(" Offset: 0x%lx\n"), hdroff
);
2455 printf (_(" Length: %ld\n"), (long) linfo
.li_length
);
2456 printf (_(" DWARF Version: %d\n"), linfo
.li_version
);
2457 printf (_(" Prologue Length: %d\n"), linfo
.li_prologue_length
);
2458 printf (_(" Minimum Instruction Length: %d\n"), linfo
.li_min_insn_length
);
2459 if (linfo
.li_version
>= 4)
2460 printf (_(" Maximum Ops per Instruction: %d\n"), linfo
.li_max_ops_per_insn
);
2461 printf (_(" Initial value of 'is_stmt': %d\n"), linfo
.li_default_is_stmt
);
2462 printf (_(" Line Base: %d\n"), linfo
.li_line_base
);
2463 printf (_(" Line Range: %d\n"), linfo
.li_line_range
);
2464 printf (_(" Opcode Base: %d\n"), linfo
.li_opcode_base
);
2466 end_of_sequence
= data
+ linfo
.li_length
+ initial_length_size
;
2468 reset_state_machine (linfo
.li_default_is_stmt
);
2470 /* Display the contents of the Opcodes table. */
2471 standard_opcodes
= hdrptr
;
2473 printf (_("\n Opcodes:\n"));
2475 for (i
= 1; i
< linfo
.li_opcode_base
; i
++)
2476 printf (_(" Opcode %d has %d args\n"), i
, standard_opcodes
[i
- 1]);
2478 /* Display the contents of the Directory table. */
2479 data
= standard_opcodes
+ linfo
.li_opcode_base
- 1;
2482 printf (_("\n The Directory Table is empty.\n"));
2485 printf (_("\n The Directory Table:\n"));
2489 printf (" %s\n", data
);
2491 data
+= strlen ((char *) data
) + 1;
2495 /* Skip the NUL at the end of the table. */
2498 /* Display the contents of the File Name table. */
2500 printf (_("\n The File Name Table is empty.\n"));
2503 printf (_("\n The File Name Table:\n"));
2504 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
2508 unsigned char *name
;
2509 unsigned int bytes_read
;
2511 printf (" %d\t", ++state_machine_regs
.last_file_entry
);
2514 data
+= strlen ((char *) data
) + 1;
2517 dwarf_vmatoa ("u", read_leb128 (data
, & bytes_read
, 0)));
2520 dwarf_vmatoa ("u", read_leb128 (data
, & bytes_read
, 0)));
2523 dwarf_vmatoa ("u", read_leb128 (data
, & bytes_read
, 0)));
2525 printf ("%s\n", name
);
2529 /* Skip the NUL at the end of the table. */
2532 /* Now display the statements. */
2533 printf (_("\n Line Number Statements:\n"));
2535 while (data
< end_of_sequence
)
2537 unsigned char op_code
;
2538 dwarf_signed_vma adv
;
2540 unsigned int bytes_read
;
2544 if (op_code
>= linfo
.li_opcode_base
)
2546 op_code
-= linfo
.li_opcode_base
;
2547 uladv
= (op_code
/ linfo
.li_line_range
);
2548 if (linfo
.li_max_ops_per_insn
== 1)
2550 uladv
*= linfo
.li_min_insn_length
;
2551 state_machine_regs
.address
+= uladv
;
2552 printf (_(" Special opcode %d: "
2553 "advance Address by %s to 0x%s"),
2554 op_code
, dwarf_vmatoa ("u", uladv
),
2555 dwarf_vmatoa ("x", state_machine_regs
.address
));
2559 state_machine_regs
.address
2560 += ((state_machine_regs
.op_index
+ uladv
)
2561 / linfo
.li_max_ops_per_insn
)
2562 * linfo
.li_min_insn_length
;
2563 state_machine_regs
.op_index
2564 = (state_machine_regs
.op_index
+ uladv
)
2565 % linfo
.li_max_ops_per_insn
;
2566 printf (_(" Special opcode %d: "
2567 "advance Address by %s to 0x%s[%d]"),
2568 op_code
, dwarf_vmatoa ("u", uladv
),
2569 dwarf_vmatoa ("x", state_machine_regs
.address
),
2570 state_machine_regs
.op_index
);
2572 adv
= (op_code
% linfo
.li_line_range
) + linfo
.li_line_base
;
2573 state_machine_regs
.line
+= adv
;
2574 printf (_(" and Line by %s to %d\n"),
2575 dwarf_vmatoa ("d", adv
), state_machine_regs
.line
);
2577 else switch (op_code
)
2579 case DW_LNS_extended_op
:
2580 data
+= process_extended_line_op (data
, linfo
.li_default_is_stmt
);
2584 printf (_(" Copy\n"));
2587 case DW_LNS_advance_pc
:
2588 uladv
= read_leb128 (data
, & bytes_read
, 0);
2590 if (linfo
.li_max_ops_per_insn
== 1)
2592 uladv
*= linfo
.li_min_insn_length
;
2593 state_machine_regs
.address
+= uladv
;
2594 printf (_(" Advance PC by %s to 0x%s\n"),
2595 dwarf_vmatoa ("u", uladv
),
2596 dwarf_vmatoa ("x", state_machine_regs
.address
));
2600 state_machine_regs
.address
2601 += ((state_machine_regs
.op_index
+ uladv
)
2602 / linfo
.li_max_ops_per_insn
)
2603 * linfo
.li_min_insn_length
;
2604 state_machine_regs
.op_index
2605 = (state_machine_regs
.op_index
+ uladv
)
2606 % linfo
.li_max_ops_per_insn
;
2607 printf (_(" Advance PC by %s to 0x%s[%d]\n"),
2608 dwarf_vmatoa ("u", uladv
),
2609 dwarf_vmatoa ("x", state_machine_regs
.address
),
2610 state_machine_regs
.op_index
);
2614 case DW_LNS_advance_line
:
2615 adv
= read_sleb128 (data
, & bytes_read
);
2617 state_machine_regs
.line
+= adv
;
2618 printf (_(" Advance Line by %s to %d\n"),
2619 dwarf_vmatoa ("d", adv
),
2620 state_machine_regs
.line
);
2623 case DW_LNS_set_file
:
2624 adv
= read_leb128 (data
, & bytes_read
, 0);
2626 printf (_(" Set File Name to entry %s in the File Name Table\n"),
2627 dwarf_vmatoa ("d", adv
));
2628 state_machine_regs
.file
= adv
;
2631 case DW_LNS_set_column
:
2632 uladv
= read_leb128 (data
, & bytes_read
, 0);
2634 printf (_(" Set column to %s\n"),
2635 dwarf_vmatoa ("u", uladv
));
2636 state_machine_regs
.column
= uladv
;
2639 case DW_LNS_negate_stmt
:
2640 adv
= state_machine_regs
.is_stmt
;
2642 printf (_(" Set is_stmt to %s\n"), dwarf_vmatoa ("d", adv
));
2643 state_machine_regs
.is_stmt
= adv
;
2646 case DW_LNS_set_basic_block
:
2647 printf (_(" Set basic block\n"));
2648 state_machine_regs
.basic_block
= 1;
2651 case DW_LNS_const_add_pc
:
2652 uladv
= ((255 - linfo
.li_opcode_base
) / linfo
.li_line_range
);
2653 if (linfo
.li_max_ops_per_insn
)
2655 uladv
*= linfo
.li_min_insn_length
;
2656 state_machine_regs
.address
+= uladv
;
2657 printf (_(" Advance PC by constant %s to 0x%s\n"),
2658 dwarf_vmatoa ("u", uladv
),
2659 dwarf_vmatoa ("x", state_machine_regs
.address
));
2663 state_machine_regs
.address
2664 += ((state_machine_regs
.op_index
+ uladv
)
2665 / linfo
.li_max_ops_per_insn
)
2666 * linfo
.li_min_insn_length
;
2667 state_machine_regs
.op_index
2668 = (state_machine_regs
.op_index
+ uladv
)
2669 % linfo
.li_max_ops_per_insn
;
2670 printf (_(" Advance PC by constant %s to 0x%s[%d]\n"),
2671 dwarf_vmatoa ("u", uladv
),
2672 dwarf_vmatoa ("x", state_machine_regs
.address
),
2673 state_machine_regs
.op_index
);
2677 case DW_LNS_fixed_advance_pc
:
2678 uladv
= byte_get (data
, 2);
2680 state_machine_regs
.address
+= uladv
;
2681 state_machine_regs
.op_index
= 0;
2682 printf (_(" Advance PC by fixed size amount %s to 0x%s\n"),
2683 dwarf_vmatoa ("u", uladv
),
2684 dwarf_vmatoa ("x", state_machine_regs
.address
));
2687 case DW_LNS_set_prologue_end
:
2688 printf (_(" Set prologue_end to true\n"));
2691 case DW_LNS_set_epilogue_begin
:
2692 printf (_(" Set epilogue_begin to true\n"));
2695 case DW_LNS_set_isa
:
2696 uladv
= read_leb128 (data
, & bytes_read
, 0);
2698 printf (_(" Set ISA to %s\n"), dwarf_vmatoa ("u", uladv
));
2702 printf (_(" Unknown opcode %d with operands: "), op_code
);
2704 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
2706 printf ("0x%s%s", dwarf_vmatoa ("x", read_leb128 (data
,
2708 i
== 1 ? "" : ", ");
2723 unsigned char *name
;
2724 unsigned int directory_index
;
2725 unsigned int modification_date
;
2726 unsigned int length
;
2729 /* Output a decoded representation of the .debug_line section. */
2732 display_debug_lines_decoded (struct dwarf_section
*section
,
2733 unsigned char *data
,
2736 printf (_("Decoded dump of debug contents of section %s:\n\n"),
2741 /* This loop amounts to one iteration per compilation unit. */
2742 DWARF2_Internal_LineInfo linfo
;
2743 unsigned char *standard_opcodes
;
2744 unsigned char *end_of_sequence
;
2745 unsigned char *hdrptr
;
2746 int initial_length_size
;
2749 File_Entry
*file_table
= NULL
;
2750 unsigned char **directory_table
= NULL
;
2754 /* Extract information from the Line Number Program Header.
2755 (section 6.2.4 in the Dwarf3 doc). */
2757 /* Get the length of this CU's line number information block. */
2758 linfo
.li_length
= byte_get (hdrptr
, 4);
2761 if (linfo
.li_length
== 0xffffffff)
2763 /* This section is 64-bit DWARF 3. */
2764 linfo
.li_length
= byte_get (hdrptr
, 8);
2767 initial_length_size
= 12;
2772 initial_length_size
= 4;
2775 if (linfo
.li_length
+ initial_length_size
> section
->size
)
2777 warn (_("The line info appears to be corrupt - "
2778 "the section is too small\n"));
2782 /* Get this CU's Line Number Block version number. */
2783 linfo
.li_version
= byte_get (hdrptr
, 2);
2785 if (linfo
.li_version
!= 2
2786 && linfo
.li_version
!= 3
2787 && linfo
.li_version
!= 4)
2789 warn (_("Only DWARF version 2, 3 and 4 line info is currently "
2794 linfo
.li_prologue_length
= byte_get (hdrptr
, offset_size
);
2795 hdrptr
+= offset_size
;
2796 linfo
.li_min_insn_length
= byte_get (hdrptr
, 1);
2798 if (linfo
.li_version
>= 4)
2800 linfo
.li_max_ops_per_insn
= byte_get (hdrptr
, 1);
2802 if (linfo
.li_max_ops_per_insn
== 0)
2804 warn (_("Invalid maximum operations per insn.\n"));
2809 linfo
.li_max_ops_per_insn
= 1;
2810 linfo
.li_default_is_stmt
= byte_get (hdrptr
, 1);
2812 linfo
.li_line_base
= byte_get (hdrptr
, 1);
2814 linfo
.li_line_range
= byte_get (hdrptr
, 1);
2816 linfo
.li_opcode_base
= byte_get (hdrptr
, 1);
2819 /* Sign extend the line base field. */
2820 linfo
.li_line_base
<<= 24;
2821 linfo
.li_line_base
>>= 24;
2823 /* Find the end of this CU's Line Number Information Block. */
2824 end_of_sequence
= data
+ linfo
.li_length
+ initial_length_size
;
2826 reset_state_machine (linfo
.li_default_is_stmt
);
2828 /* Save a pointer to the contents of the Opcodes table. */
2829 standard_opcodes
= hdrptr
;
2831 /* Traverse the Directory table just to count entries. */
2832 data
= standard_opcodes
+ linfo
.li_opcode_base
- 1;
2835 unsigned int n_directories
= 0;
2836 unsigned char *ptr_directory_table
= data
;
2840 data
+= strlen ((char *) data
) + 1;
2844 /* Go through the directory table again to save the directories. */
2845 directory_table
= (unsigned char **)
2846 xmalloc (n_directories
* sizeof (unsigned char *));
2849 while (*ptr_directory_table
!= 0)
2851 directory_table
[i
] = ptr_directory_table
;
2852 ptr_directory_table
+= strlen ((char *) ptr_directory_table
) + 1;
2856 /* Skip the NUL at the end of the table. */
2859 /* Traverse the File Name table just to count the entries. */
2862 unsigned int n_files
= 0;
2863 unsigned char *ptr_file_name_table
= data
;
2867 unsigned int bytes_read
;
2869 /* Skip Name, directory index, last modification time and length
2871 data
+= strlen ((char *) data
) + 1;
2872 read_leb128 (data
, & bytes_read
, 0);
2874 read_leb128 (data
, & bytes_read
, 0);
2876 read_leb128 (data
, & bytes_read
, 0);
2882 /* Go through the file table again to save the strings. */
2883 file_table
= (File_Entry
*) xmalloc (n_files
* sizeof (File_Entry
));
2886 while (*ptr_file_name_table
!= 0)
2888 unsigned int bytes_read
;
2890 file_table
[i
].name
= ptr_file_name_table
;
2891 ptr_file_name_table
+= strlen ((char *) ptr_file_name_table
) + 1;
2893 /* We are not interested in directory, time or size. */
2894 file_table
[i
].directory_index
= read_leb128 (ptr_file_name_table
,
2896 ptr_file_name_table
+= bytes_read
;
2897 file_table
[i
].modification_date
= read_leb128 (ptr_file_name_table
,
2899 ptr_file_name_table
+= bytes_read
;
2900 file_table
[i
].length
= read_leb128 (ptr_file_name_table
, & bytes_read
, 0);
2901 ptr_file_name_table
+= bytes_read
;
2906 /* Print the Compilation Unit's name and a header. */
2907 if (directory_table
== NULL
)
2909 printf (_("CU: %s:\n"), file_table
[0].name
);
2910 printf (_("File name Line number Starting address\n"));
2914 if (do_wide
|| strlen ((char *) directory_table
[0]) < 76)
2915 printf (_("CU: %s/%s:\n"), directory_table
[0],
2916 file_table
[0].name
);
2918 printf ("%s:\n", file_table
[0].name
);
2920 printf (_("File name Line number Starting address\n"));
2924 /* Skip the NUL at the end of the table. */
2927 /* This loop iterates through the Dwarf Line Number Program. */
2928 while (data
< end_of_sequence
)
2930 unsigned char op_code
;
2932 unsigned long int uladv
;
2933 unsigned int bytes_read
;
2934 int is_special_opcode
= 0;
2938 if (op_code
>= linfo
.li_opcode_base
)
2940 op_code
-= linfo
.li_opcode_base
;
2941 uladv
= (op_code
/ linfo
.li_line_range
);
2942 if (linfo
.li_max_ops_per_insn
== 1)
2944 uladv
*= linfo
.li_min_insn_length
;
2945 state_machine_regs
.address
+= uladv
;
2949 state_machine_regs
.address
2950 += ((state_machine_regs
.op_index
+ uladv
)
2951 / linfo
.li_max_ops_per_insn
)
2952 * linfo
.li_min_insn_length
;
2953 state_machine_regs
.op_index
2954 = (state_machine_regs
.op_index
+ uladv
)
2955 % linfo
.li_max_ops_per_insn
;
2958 adv
= (op_code
% linfo
.li_line_range
) + linfo
.li_line_base
;
2959 state_machine_regs
.line
+= adv
;
2960 is_special_opcode
= 1;
2962 else switch (op_code
)
2964 case DW_LNS_extended_op
:
2966 unsigned int ext_op_code_len
;
2967 unsigned char ext_op_code
;
2968 unsigned char *op_code_data
= data
;
2970 ext_op_code_len
= read_leb128 (op_code_data
, &bytes_read
, 0);
2971 op_code_data
+= bytes_read
;
2973 if (ext_op_code_len
== 0)
2975 warn (_("badly formed extended line op encountered!\n"));
2978 ext_op_code_len
+= bytes_read
;
2979 ext_op_code
= *op_code_data
++;
2981 switch (ext_op_code
)
2983 case DW_LNE_end_sequence
:
2984 reset_state_machine (linfo
.li_default_is_stmt
);
2986 case DW_LNE_set_address
:
2987 state_machine_regs
.address
=
2988 byte_get (op_code_data
, ext_op_code_len
- bytes_read
- 1);
2989 state_machine_regs
.op_index
= 0;
2991 case DW_LNE_define_file
:
2993 unsigned int dir_index
= 0;
2995 ++state_machine_regs
.last_file_entry
;
2996 op_code_data
+= strlen ((char *) op_code_data
) + 1;
2997 dir_index
= read_leb128 (op_code_data
, & bytes_read
, 0);
2998 op_code_data
+= bytes_read
;
2999 read_leb128 (op_code_data
, & bytes_read
, 0);
3000 op_code_data
+= bytes_read
;
3001 read_leb128 (op_code_data
, & bytes_read
, 0);
3003 printf ("%s:\n", directory_table
[dir_index
]);
3007 printf (_("UNKNOWN: length %d\n"), ext_op_code_len
- bytes_read
);
3010 data
+= ext_op_code_len
;
3016 case DW_LNS_advance_pc
:
3017 uladv
= read_leb128 (data
, & bytes_read
, 0);
3019 if (linfo
.li_max_ops_per_insn
== 1)
3021 uladv
*= linfo
.li_min_insn_length
;
3022 state_machine_regs
.address
+= uladv
;
3026 state_machine_regs
.address
3027 += ((state_machine_regs
.op_index
+ uladv
)
3028 / linfo
.li_max_ops_per_insn
)
3029 * linfo
.li_min_insn_length
;
3030 state_machine_regs
.op_index
3031 = (state_machine_regs
.op_index
+ uladv
)
3032 % linfo
.li_max_ops_per_insn
;
3036 case DW_LNS_advance_line
:
3037 adv
= read_sleb128 (data
, & bytes_read
);
3039 state_machine_regs
.line
+= adv
;
3042 case DW_LNS_set_file
:
3043 adv
= read_leb128 (data
, & bytes_read
, 0);
3045 state_machine_regs
.file
= adv
;
3046 if (file_table
[state_machine_regs
.file
- 1].directory_index
== 0)
3048 /* If directory index is 0, that means current directory. */
3049 printf ("\n./%s:[++]\n",
3050 file_table
[state_machine_regs
.file
- 1].name
);
3054 /* The directory index starts counting at 1. */
3055 printf ("\n%s/%s:\n",
3056 directory_table
[file_table
[state_machine_regs
.file
- 1].directory_index
- 1],
3057 file_table
[state_machine_regs
.file
- 1].name
);
3061 case DW_LNS_set_column
:
3062 uladv
= read_leb128 (data
, & bytes_read
, 0);
3064 state_machine_regs
.column
= uladv
;
3067 case DW_LNS_negate_stmt
:
3068 adv
= state_machine_regs
.is_stmt
;
3070 state_machine_regs
.is_stmt
= adv
;
3073 case DW_LNS_set_basic_block
:
3074 state_machine_regs
.basic_block
= 1;
3077 case DW_LNS_const_add_pc
:
3078 uladv
= ((255 - linfo
.li_opcode_base
) / linfo
.li_line_range
);
3079 if (linfo
.li_max_ops_per_insn
== 1)
3081 uladv
*= linfo
.li_min_insn_length
;
3082 state_machine_regs
.address
+= uladv
;
3086 state_machine_regs
.address
3087 += ((state_machine_regs
.op_index
+ uladv
)
3088 / linfo
.li_max_ops_per_insn
)
3089 * linfo
.li_min_insn_length
;
3090 state_machine_regs
.op_index
3091 = (state_machine_regs
.op_index
+ uladv
)
3092 % linfo
.li_max_ops_per_insn
;
3096 case DW_LNS_fixed_advance_pc
:
3097 uladv
= byte_get (data
, 2);
3099 state_machine_regs
.address
+= uladv
;
3100 state_machine_regs
.op_index
= 0;
3103 case DW_LNS_set_prologue_end
:
3106 case DW_LNS_set_epilogue_begin
:
3109 case DW_LNS_set_isa
:
3110 uladv
= read_leb128 (data
, & bytes_read
, 0);
3112 printf (_(" Set ISA to %lu\n"), uladv
);
3116 printf (_(" Unknown opcode %d with operands: "), op_code
);
3118 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
3120 printf ("0x%s%s", dwarf_vmatoa ("x", read_leb128 (data
,
3122 i
== 1 ? "" : ", ");
3129 /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row
3130 to the DWARF address/line matrix. */
3131 if ((is_special_opcode
) || (op_code
== DW_LNE_end_sequence
)
3132 || (op_code
== DW_LNS_copy
))
3134 const unsigned int MAX_FILENAME_LENGTH
= 35;
3135 char *fileName
= (char *)file_table
[state_machine_regs
.file
- 1].name
;
3136 char *newFileName
= NULL
;
3137 size_t fileNameLength
= strlen (fileName
);
3139 if ((fileNameLength
> MAX_FILENAME_LENGTH
) && (!do_wide
))
3141 newFileName
= (char *) xmalloc (MAX_FILENAME_LENGTH
+ 1);
3142 /* Truncate file name */
3143 strncpy (newFileName
,
3144 fileName
+ fileNameLength
- MAX_FILENAME_LENGTH
,
3145 MAX_FILENAME_LENGTH
+ 1);
3149 newFileName
= (char *) xmalloc (fileNameLength
+ 1);
3150 strncpy (newFileName
, fileName
, fileNameLength
+ 1);
3153 if (!do_wide
|| (fileNameLength
<= MAX_FILENAME_LENGTH
))
3155 if (linfo
.li_max_ops_per_insn
== 1)
3156 printf ("%-35s %11d %#18" DWARF_VMA_FMT
"x\n",
3157 newFileName
, state_machine_regs
.line
,
3158 state_machine_regs
.address
);
3160 printf ("%-35s %11d %#18" DWARF_VMA_FMT
"x[%d]\n",
3161 newFileName
, state_machine_regs
.line
,
3162 state_machine_regs
.address
,
3163 state_machine_regs
.op_index
);
3167 if (linfo
.li_max_ops_per_insn
== 1)
3168 printf ("%s %11d %#18" DWARF_VMA_FMT
"x\n",
3169 newFileName
, state_machine_regs
.line
,
3170 state_machine_regs
.address
);
3172 printf ("%s %11d %#18" DWARF_VMA_FMT
"x[%d]\n",
3173 newFileName
, state_machine_regs
.line
,
3174 state_machine_regs
.address
,
3175 state_machine_regs
.op_index
);
3178 if (op_code
== DW_LNE_end_sequence
)
3186 free (directory_table
);
3187 directory_table
= NULL
;
3195 display_debug_lines (struct dwarf_section
*section
, void *file ATTRIBUTE_UNUSED
)
3197 unsigned char *data
= section
->start
;
3198 unsigned char *end
= data
+ section
->size
;
3200 int retValDecoded
= 1;
3202 if (do_debug_lines
== 0)
3203 do_debug_lines
|= FLAG_DEBUG_LINES_RAW
;
3205 if (do_debug_lines
& FLAG_DEBUG_LINES_RAW
)
3206 retValRaw
= display_debug_lines_raw (section
, data
, end
);
3208 if (do_debug_lines
& FLAG_DEBUG_LINES_DECODED
)
3209 retValDecoded
= display_debug_lines_decoded (section
, data
, end
);
3211 if (!retValRaw
|| !retValDecoded
)
3218 find_debug_info_for_offset (unsigned long offset
)
3222 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
3225 for (i
= 0; i
< num_debug_info_entries
; i
++)
3226 if (debug_information
[i
].cu_offset
== offset
)
3227 return debug_information
+ i
;
3233 display_debug_pubnames (struct dwarf_section
*section
,
3234 void *file ATTRIBUTE_UNUSED
)
3236 DWARF2_Internal_PubNames names
;
3237 unsigned char *start
= section
->start
;
3238 unsigned char *end
= start
+ section
->size
;
3240 /* It does not matter if this load fails,
3241 we test for that later on. */
3242 load_debug_info (file
);
3244 printf (_("Contents of the %s section:\n\n"), section
->name
);
3248 unsigned char *data
;
3249 unsigned long offset
;
3250 int offset_size
, initial_length_size
;
3254 names
.pn_length
= byte_get (data
, 4);
3256 if (names
.pn_length
== 0xffffffff)
3258 names
.pn_length
= byte_get (data
, 8);
3261 initial_length_size
= 12;
3266 initial_length_size
= 4;
3269 names
.pn_version
= byte_get (data
, 2);
3272 names
.pn_offset
= byte_get (data
, offset_size
);
3273 data
+= offset_size
;
3275 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
3276 && num_debug_info_entries
> 0
3277 && find_debug_info_for_offset (names
.pn_offset
) == NULL
)
3278 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
3279 (unsigned long) names
.pn_offset
, section
->name
);
3281 names
.pn_size
= byte_get (data
, offset_size
);
3282 data
+= offset_size
;
3284 start
+= names
.pn_length
+ initial_length_size
;
3286 if (names
.pn_version
!= 2 && names
.pn_version
!= 3)
3288 static int warned
= 0;
3292 warn (_("Only DWARF 2 and 3 pubnames are currently supported\n"));
3299 printf (_(" Length: %ld\n"),
3300 (long) names
.pn_length
);
3301 printf (_(" Version: %d\n"),
3303 printf (_(" Offset into .debug_info section: 0x%lx\n"),
3304 (unsigned long) names
.pn_offset
);
3305 printf (_(" Size of area in .debug_info section: %ld\n"),
3306 (long) names
.pn_size
);
3308 printf (_("\n Offset\tName\n"));
3312 offset
= byte_get (data
, offset_size
);
3316 data
+= offset_size
;
3317 printf (" %-6lx\t%s\n", offset
, data
);
3318 data
+= strlen ((char *) data
) + 1;
3321 while (offset
!= 0);
3329 display_debug_macinfo (struct dwarf_section
*section
,
3330 void *file ATTRIBUTE_UNUSED
)
3332 unsigned char *start
= section
->start
;
3333 unsigned char *end
= start
+ section
->size
;
3334 unsigned char *curr
= start
;
3335 unsigned int bytes_read
;
3336 enum dwarf_macinfo_record_type op
;
3338 printf (_("Contents of the %s section:\n\n"), section
->name
);
3342 unsigned int lineno
;
3345 op
= (enum dwarf_macinfo_record_type
) *curr
;
3350 case DW_MACINFO_start_file
:
3352 unsigned int filenum
;
3354 lineno
= read_leb128 (curr
, & bytes_read
, 0);
3356 filenum
= read_leb128 (curr
, & bytes_read
, 0);
3359 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"),
3364 case DW_MACINFO_end_file
:
3365 printf (_(" DW_MACINFO_end_file\n"));
3368 case DW_MACINFO_define
:
3369 lineno
= read_leb128 (curr
, & bytes_read
, 0);
3371 string
= (char *) curr
;
3372 curr
+= strlen (string
) + 1;
3373 printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"),
3377 case DW_MACINFO_undef
:
3378 lineno
= read_leb128 (curr
, & bytes_read
, 0);
3380 string
= (char *) curr
;
3381 curr
+= strlen (string
) + 1;
3382 printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"),
3386 case DW_MACINFO_vendor_ext
:
3388 unsigned int constant
;
3390 constant
= read_leb128 (curr
, & bytes_read
, 0);
3392 string
= (char *) curr
;
3393 curr
+= strlen (string
) + 1;
3394 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"),
3405 display_debug_abbrev (struct dwarf_section
*section
,
3406 void *file ATTRIBUTE_UNUSED
)
3408 abbrev_entry
*entry
;
3409 unsigned char *start
= section
->start
;
3410 unsigned char *end
= start
+ section
->size
;
3412 printf (_("Contents of the %s section:\n\n"), section
->name
);
3418 start
= process_abbrev_section (start
, end
);
3420 if (first_abbrev
== NULL
)
3423 printf (_(" Number TAG\n"));
3425 for (entry
= first_abbrev
; entry
; entry
= entry
->next
)
3429 printf (" %ld %s [%s]\n",
3431 get_TAG_name (entry
->tag
),
3432 entry
->children
? _("has children") : _("no children"));
3434 for (attr
= entry
->first_attr
; attr
; attr
= attr
->next
)
3435 printf (" %-18s %s\n",
3436 get_AT_name (attr
->attribute
),
3437 get_FORM_name (attr
->form
));
3448 display_debug_loc (struct dwarf_section
*section
, void *file
)
3450 unsigned char *start
= section
->start
;
3451 unsigned char *section_end
;
3452 unsigned long bytes
;
3453 unsigned char *section_begin
= start
;
3454 unsigned int num_loc_list
= 0;
3455 unsigned long last_offset
= 0;
3456 unsigned int first
= 0;
3459 int seen_first_offset
= 0;
3460 int use_debug_info
= 1;
3461 unsigned char *next
;
3463 bytes
= section
->size
;
3464 section_end
= start
+ bytes
;
3468 printf (_("\nThe %s section is empty.\n"), section
->name
);
3472 if (load_debug_info (file
) == 0)
3474 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
3479 /* Check the order of location list in .debug_info section. If
3480 offsets of location lists are in the ascending order, we can
3481 use `debug_information' directly. */
3482 for (i
= 0; i
< num_debug_info_entries
; i
++)
3486 num
= debug_information
[i
].num_loc_offsets
;
3487 num_loc_list
+= num
;
3489 /* Check if we can use `debug_information' directly. */
3490 if (use_debug_info
&& num
!= 0)
3492 if (!seen_first_offset
)
3494 /* This is the first location list. */
3495 last_offset
= debug_information
[i
].loc_offsets
[0];
3497 seen_first_offset
= 1;
3503 for (; j
< num
; j
++)
3506 debug_information
[i
].loc_offsets
[j
])
3511 last_offset
= debug_information
[i
].loc_offsets
[j
];
3516 if (!use_debug_info
)
3517 /* FIXME: Should we handle this case? */
3518 error (_("Location lists in .debug_info section aren't in ascending order!\n"));
3520 if (!seen_first_offset
)
3521 error (_("No location lists in .debug_info section!\n"));
3523 /* DWARF sections under Mach-O have non-zero addresses. */
3524 if (debug_information
[first
].num_loc_offsets
> 0
3525 && debug_information
[first
].loc_offsets
[0] != section
->address
)
3526 warn (_("Location lists in %s section start at 0x%s\n"),
3528 dwarf_vmatoa ("x", debug_information
[first
].loc_offsets
[0]));
3530 printf (_("Contents of the %s section:\n\n"), section
->name
);
3531 printf (_(" Offset Begin End Expression\n"));
3533 seen_first_offset
= 0;
3534 for (i
= first
; i
< num_debug_info_entries
; i
++)
3538 unsigned short length
;
3539 unsigned long offset
;
3540 unsigned int pointer_size
;
3541 unsigned int offset_size
;
3543 unsigned long cu_offset
;
3544 unsigned long base_address
;
3545 int need_frame_base
;
3548 pointer_size
= debug_information
[i
].pointer_size
;
3549 cu_offset
= debug_information
[i
].cu_offset
;
3550 offset_size
= debug_information
[i
].offset_size
;
3551 dwarf_version
= debug_information
[i
].dwarf_version
;
3553 for (j
= 0; j
< debug_information
[i
].num_loc_offsets
; j
++)
3555 has_frame_base
= debug_information
[i
].have_frame_base
[j
];
3556 /* DWARF sections under Mach-O have non-zero addresses. */
3557 offset
= debug_information
[i
].loc_offsets
[j
] - section
->address
;
3558 next
= section_begin
+ offset
;
3559 base_address
= debug_information
[i
].base_address
;
3561 if (!seen_first_offset
)
3562 seen_first_offset
= 1;
3566 warn (_("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n"),
3567 (unsigned long) (start
- section_begin
),
3568 (unsigned long) (next
- section_begin
));
3569 else if (start
> next
)
3570 warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n"),
3571 (unsigned long) (start
- section_begin
),
3572 (unsigned long) (next
- section_begin
));
3576 if (offset
>= bytes
)
3578 warn (_("Offset 0x%lx is bigger than .debug_loc section size.\n"),
3585 if (start
+ 2 * pointer_size
> section_end
)
3587 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
3592 /* Note: we use sign extension here in order to be sure that
3593 we can detect the -1 escape value. Sign extension into the
3594 top 32 bits of a 32-bit address will not affect the values
3595 that we display since we always show hex values, and always
3596 the bottom 32-bits. */
3597 begin
= byte_get_signed (start
, pointer_size
);
3598 start
+= pointer_size
;
3599 end
= byte_get_signed (start
, pointer_size
);
3600 start
+= pointer_size
;
3602 printf (" %8.8lx ", offset
);
3604 if (begin
== 0 && end
== 0)
3606 printf (_("<End of list>\n"));
3610 /* Check base address specifiers. */
3611 if (begin
== (dwarf_vma
) -1 && end
!= (dwarf_vma
) -1)
3614 print_dwarf_vma (begin
, pointer_size
);
3615 print_dwarf_vma (end
, pointer_size
);
3616 printf (_("(base address)\n"));
3620 if (start
+ 2 > section_end
)
3622 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
3627 length
= byte_get (start
, 2);
3630 if (start
+ length
> section_end
)
3632 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
3637 print_dwarf_vma (begin
+ base_address
, pointer_size
);
3638 print_dwarf_vma (end
+ base_address
, pointer_size
);
3641 need_frame_base
= decode_location_expression (start
,
3646 cu_offset
, section
);
3649 if (need_frame_base
&& !has_frame_base
)
3650 printf (_(" [without DW_AT_frame_base]"));
3653 fputs (_(" (start == end)"), stdout
);
3654 else if (begin
> end
)
3655 fputs (_(" (start > end)"), stdout
);
3664 if (start
< section_end
)
3665 warn (_("There are %ld unused bytes at the end of section %s\n"),
3666 (long) (section_end
- start
), section
->name
);
3672 display_debug_str (struct dwarf_section
*section
,
3673 void *file ATTRIBUTE_UNUSED
)
3675 unsigned char *start
= section
->start
;
3676 unsigned long bytes
= section
->size
;
3677 dwarf_vma addr
= section
->address
;
3681 printf (_("\nThe %s section is empty.\n"), section
->name
);
3685 printf (_("Contents of the %s section:\n\n"), section
->name
);
3693 lbytes
= (bytes
> 16 ? 16 : bytes
);
3695 printf (" 0x%8.8lx ", (unsigned long) addr
);
3697 for (j
= 0; j
< 16; j
++)
3700 printf ("%2.2x", start
[j
]);
3708 for (j
= 0; j
< lbytes
; j
++)
3711 if (k
>= ' ' && k
< 0x80)
3730 display_debug_info (struct dwarf_section
*section
, void *file
)
3732 return process_debug_info (section
, file
, abbrev
, 0, 0);
3736 display_debug_types (struct dwarf_section
*section
, void *file
)
3738 return process_debug_info (section
, file
, abbrev
, 0, 1);
3742 display_trace_info (struct dwarf_section
*section
, void *file
)
3744 return process_debug_info (section
, file
, trace_abbrev
, 0, 0);
3748 display_debug_aranges (struct dwarf_section
*section
,
3749 void *file ATTRIBUTE_UNUSED
)
3751 unsigned char *start
= section
->start
;
3752 unsigned char *end
= start
+ section
->size
;
3754 printf (_("Contents of the %s section:\n\n"), section
->name
);
3756 /* It does not matter if this load fails,
3757 we test for that later on. */
3758 load_debug_info (file
);
3762 unsigned char *hdrptr
;
3763 DWARF2_Internal_ARange arange
;
3764 unsigned char *addr_ranges
;
3767 unsigned char address_size
;
3770 int initial_length_size
;
3774 arange
.ar_length
= byte_get (hdrptr
, 4);
3777 if (arange
.ar_length
== 0xffffffff)
3779 arange
.ar_length
= byte_get (hdrptr
, 8);
3782 initial_length_size
= 12;
3787 initial_length_size
= 4;
3790 arange
.ar_version
= byte_get (hdrptr
, 2);
3793 arange
.ar_info_offset
= byte_get (hdrptr
, offset_size
);
3794 hdrptr
+= offset_size
;
3796 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
3797 && num_debug_info_entries
> 0
3798 && find_debug_info_for_offset (arange
.ar_info_offset
) == NULL
)
3799 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
3800 (unsigned long) arange
.ar_info_offset
, section
->name
);
3802 arange
.ar_pointer_size
= byte_get (hdrptr
, 1);
3805 arange
.ar_segment_size
= byte_get (hdrptr
, 1);
3808 if (arange
.ar_version
!= 2 && arange
.ar_version
!= 3)
3810 warn (_("Only DWARF 2 and 3 aranges are currently supported.\n"));
3814 printf (_(" Length: %ld\n"),
3815 (long) arange
.ar_length
);
3816 printf (_(" Version: %d\n"), arange
.ar_version
);
3817 printf (_(" Offset into .debug_info: 0x%lx\n"),
3818 (unsigned long) arange
.ar_info_offset
);
3819 printf (_(" Pointer Size: %d\n"), arange
.ar_pointer_size
);
3820 printf (_(" Segment Size: %d\n"), arange
.ar_segment_size
);
3822 address_size
= arange
.ar_pointer_size
+ arange
.ar_segment_size
;
3824 /* The DWARF spec does not require that the address size be a power
3825 of two, but we do. This will have to change if we ever encounter
3826 an uneven architecture. */
3827 if ((address_size
& (address_size
- 1)) != 0)
3829 warn (_("Pointer size + Segment size is not a power of two.\n"));
3833 if (address_size
> 4)
3834 printf (_("\n Address Length\n"));
3836 printf (_("\n Address Length\n"));
3838 addr_ranges
= hdrptr
;
3840 /* Must pad to an alignment boundary that is twice the address size. */
3841 excess
= (hdrptr
- start
) % (2 * address_size
);
3843 addr_ranges
+= (2 * address_size
) - excess
;
3845 start
+= arange
.ar_length
+ initial_length_size
;
3847 while (addr_ranges
+ 2 * address_size
<= start
)
3849 address
= byte_get (addr_ranges
, address_size
);
3851 addr_ranges
+= address_size
;
3853 length
= byte_get (addr_ranges
, address_size
);
3855 addr_ranges
+= address_size
;
3858 print_dwarf_vma (address
, address_size
);
3859 print_dwarf_vma (length
, address_size
);
3869 /* Each debug_information[x].range_lists[y] gets this representation for
3870 sorting purposes. */
3874 /* The debug_information[x].range_lists[y] value. */
3875 unsigned long ranges_offset
;
3877 /* Original debug_information to find parameters of the data. */
3878 debug_info
*debug_info_p
;
3881 /* Sort struct range_entry in ascending order of its RANGES_OFFSET. */
3884 range_entry_compar (const void *ap
, const void *bp
)
3886 const struct range_entry
*a_re
= (const struct range_entry
*) ap
;
3887 const struct range_entry
*b_re
= (const struct range_entry
*) bp
;
3888 const unsigned long a
= a_re
->ranges_offset
;
3889 const unsigned long b
= b_re
->ranges_offset
;
3891 return (a
> b
) - (b
> a
);
3895 display_debug_ranges (struct dwarf_section
*section
,
3896 void *file ATTRIBUTE_UNUSED
)
3898 unsigned char *start
= section
->start
;
3899 unsigned long bytes
;
3900 unsigned char *section_begin
= start
;
3901 unsigned int num_range_list
, i
;
3902 struct range_entry
*range_entries
, *range_entry_fill
;
3904 bytes
= section
->size
;
3908 printf (_("\nThe %s section is empty.\n"), section
->name
);
3912 if (load_debug_info (file
) == 0)
3914 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
3920 for (i
= 0; i
< num_debug_info_entries
; i
++)
3921 num_range_list
+= debug_information
[i
].num_range_lists
;
3923 if (num_range_list
== 0)
3924 error (_("No range lists in .debug_info section!\n"));
3926 range_entries
= (struct range_entry
*)
3927 xmalloc (sizeof (*range_entries
) * num_range_list
);
3928 range_entry_fill
= range_entries
;
3930 for (i
= 0; i
< num_debug_info_entries
; i
++)
3932 debug_info
*debug_info_p
= &debug_information
[i
];
3935 for (j
= 0; j
< debug_info_p
->num_range_lists
; j
++)
3937 range_entry_fill
->ranges_offset
= debug_info_p
->range_lists
[j
];
3938 range_entry_fill
->debug_info_p
= debug_info_p
;
3943 qsort (range_entries
, num_range_list
, sizeof (*range_entries
),
3944 range_entry_compar
);
3946 /* DWARF sections under Mach-O have non-zero addresses. */
3947 if (range_entries
[0].ranges_offset
!= section
->address
)
3948 warn (_("Range lists in %s section start at 0x%lx\n"),
3949 section
->name
, range_entries
[0].ranges_offset
);
3951 printf (_("Contents of the %s section:\n\n"), section
->name
);
3952 printf (_(" Offset Begin End\n"));
3954 for (i
= 0; i
< num_range_list
; i
++)
3956 struct range_entry
*range_entry
= &range_entries
[i
];
3957 debug_info
*debug_info_p
= range_entry
->debug_info_p
;
3958 unsigned int pointer_size
;
3959 unsigned long offset
;
3960 unsigned char *next
;
3961 unsigned long base_address
;
3963 pointer_size
= debug_info_p
->pointer_size
;
3965 /* DWARF sections under Mach-O have non-zero addresses. */
3966 offset
= range_entry
->ranges_offset
- section
->address
;
3967 next
= section_begin
+ offset
;
3968 base_address
= debug_info_p
->base_address
;
3973 warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"),
3974 (unsigned long) (start
- section_begin
),
3975 (unsigned long) (next
- section_begin
), section
->name
);
3976 else if (start
> next
)
3977 warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"),
3978 (unsigned long) (start
- section_begin
),
3979 (unsigned long) (next
- section_begin
), section
->name
);
3988 /* Note: we use sign extension here in order to be sure that
3989 we can detect the -1 escape value. Sign extension into the
3990 top 32 bits of a 32-bit address will not affect the values
3991 that we display since we always show hex values, and always
3992 the bottom 32-bits. */
3993 begin
= byte_get_signed (start
, pointer_size
);
3994 start
+= pointer_size
;
3995 end
= byte_get_signed (start
, pointer_size
);
3996 start
+= pointer_size
;
3998 printf (" %8.8lx ", offset
);
4000 if (begin
== 0 && end
== 0)
4002 printf (_("<End of list>\n"));
4006 /* Check base address specifiers. */
4007 if (begin
== (dwarf_vma
) -1 && end
!= (dwarf_vma
) -1)
4010 print_dwarf_vma (begin
, pointer_size
);
4011 print_dwarf_vma (end
, pointer_size
);
4012 printf ("(base address)\n");
4016 print_dwarf_vma (begin
+ base_address
, pointer_size
);
4017 print_dwarf_vma (end
+ base_address
, pointer_size
);
4020 fputs (_("(start == end)"), stdout
);
4021 else if (begin
> end
)
4022 fputs (_("(start > end)"), stdout
);
4029 free (range_entries
);
4034 typedef struct Frame_Chunk
4036 struct Frame_Chunk
*next
;
4037 unsigned char *chunk_start
;
4039 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
4040 short int *col_type
;
4043 unsigned int code_factor
;
4045 unsigned long pc_begin
;
4046 unsigned long pc_range
;
4050 unsigned char fde_encoding
;
4051 unsigned char cfa_exp
;
4052 unsigned char ptr_size
;
4053 unsigned char segment_size
;
4057 static const char *const *dwarf_regnames
;
4058 static unsigned int dwarf_regnames_count
;
4060 /* A marker for a col_type that means this column was never referenced
4061 in the frame info. */
4062 #define DW_CFA_unreferenced (-1)
4064 /* Return 0 if not more space is needed, 1 if more space is needed,
4065 -1 for invalid reg. */
4068 frame_need_space (Frame_Chunk
*fc
, unsigned int reg
)
4070 int prev
= fc
->ncols
;
4072 if (reg
< (unsigned int) fc
->ncols
)
4075 if (dwarf_regnames_count
4076 && reg
> dwarf_regnames_count
)
4079 fc
->ncols
= reg
+ 1;
4080 fc
->col_type
= (short int *) xcrealloc (fc
->col_type
, fc
->ncols
,
4081 sizeof (short int));
4082 fc
->col_offset
= (int *) xcrealloc (fc
->col_offset
, fc
->ncols
, sizeof (int));
4084 while (prev
< fc
->ncols
)
4086 fc
->col_type
[prev
] = DW_CFA_unreferenced
;
4087 fc
->col_offset
[prev
] = 0;
4093 static const char *const dwarf_regnames_i386
[] =
4095 "eax", "ecx", "edx", "ebx",
4096 "esp", "ebp", "esi", "edi",
4097 "eip", "eflags", NULL
,
4098 "st0", "st1", "st2", "st3",
4099 "st4", "st5", "st6", "st7",
4101 "xmm0", "xmm1", "xmm2", "xmm3",
4102 "xmm4", "xmm5", "xmm6", "xmm7",
4103 "mm0", "mm1", "mm2", "mm3",
4104 "mm4", "mm5", "mm6", "mm7",
4105 "fcw", "fsw", "mxcsr",
4106 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
,
4111 init_dwarf_regnames_i386 (void)
4113 dwarf_regnames
= dwarf_regnames_i386
;
4114 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_i386
);
4117 static const char *const dwarf_regnames_x86_64
[] =
4119 "rax", "rdx", "rcx", "rbx",
4120 "rsi", "rdi", "rbp", "rsp",
4121 "r8", "r9", "r10", "r11",
4122 "r12", "r13", "r14", "r15",
4124 "xmm0", "xmm1", "xmm2", "xmm3",
4125 "xmm4", "xmm5", "xmm6", "xmm7",
4126 "xmm8", "xmm9", "xmm10", "xmm11",
4127 "xmm12", "xmm13", "xmm14", "xmm15",
4128 "st0", "st1", "st2", "st3",
4129 "st4", "st5", "st6", "st7",
4130 "mm0", "mm1", "mm2", "mm3",
4131 "mm4", "mm5", "mm6", "mm7",
4133 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
,
4134 "fs.base", "gs.base", NULL
, NULL
,
4136 "mxcsr", "fcw", "fsw"
4140 init_dwarf_regnames_x86_64 (void)
4142 dwarf_regnames
= dwarf_regnames_x86_64
;
4143 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_x86_64
);
4147 init_dwarf_regnames (unsigned int e_machine
)
4153 init_dwarf_regnames_i386 ();
4158 init_dwarf_regnames_x86_64 ();
4167 regname (unsigned int regno
, int row
)
4169 static char reg
[64];
4171 && regno
< dwarf_regnames_count
4172 && dwarf_regnames
[regno
] != NULL
)
4175 return dwarf_regnames
[regno
];
4176 snprintf (reg
, sizeof (reg
), "r%d (%s)", regno
,
4177 dwarf_regnames
[regno
]);
4180 snprintf (reg
, sizeof (reg
), "r%d", regno
);
4185 frame_display_row (Frame_Chunk
*fc
, int *need_col_headers
, int *max_regs
)
4190 if (*max_regs
< fc
->ncols
)
4191 *max_regs
= fc
->ncols
;
4193 if (*need_col_headers
)
4195 static const char *sloc
= " LOC";
4197 *need_col_headers
= 0;
4199 printf ("%-*s CFA ", eh_addr_size
* 2, sloc
);
4201 for (r
= 0; r
< *max_regs
; r
++)
4202 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
4207 printf ("%-5s ", regname (r
, 1));
4213 printf ("%0*lx ", eh_addr_size
* 2, fc
->pc_begin
);
4215 strcpy (tmp
, "exp");
4217 sprintf (tmp
, "%s%+d", regname (fc
->cfa_reg
, 1), fc
->cfa_offset
);
4218 printf ("%-8s ", tmp
);
4220 for (r
= 0; r
< fc
->ncols
; r
++)
4222 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
4224 switch (fc
->col_type
[r
])
4226 case DW_CFA_undefined
:
4229 case DW_CFA_same_value
:
4233 sprintf (tmp
, "c%+d", fc
->col_offset
[r
]);
4235 case DW_CFA_val_offset
:
4236 sprintf (tmp
, "v%+d", fc
->col_offset
[r
]);
4238 case DW_CFA_register
:
4239 sprintf (tmp
, "%s", regname (fc
->col_offset
[r
], 0));
4241 case DW_CFA_expression
:
4242 strcpy (tmp
, "exp");
4244 case DW_CFA_val_expression
:
4245 strcpy (tmp
, "vexp");
4248 strcpy (tmp
, "n/a");
4251 printf ("%-5s ", tmp
);
4257 #define GET(N) byte_get (start, N); start += N
4258 #define LEB() read_leb128 (start, & length_return, 0); start += length_return
4259 #define SLEB() read_sleb128 (start, & length_return); start += length_return
4262 display_debug_frames (struct dwarf_section
*section
,
4263 void *file ATTRIBUTE_UNUSED
)
4265 unsigned char *start
= section
->start
;
4266 unsigned char *end
= start
+ section
->size
;
4267 unsigned char *section_start
= start
;
4268 Frame_Chunk
*chunks
= 0;
4269 Frame_Chunk
*remembered_state
= 0;
4271 int is_eh
= strcmp (section
->name
, ".eh_frame") == 0;
4272 unsigned int length_return
;
4274 const char *bad_reg
= _("bad register: ");
4275 int saved_eh_addr_size
= eh_addr_size
;
4277 printf (_("Contents of the %s section:\n"), section
->name
);
4281 unsigned char *saved_start
;
4282 unsigned char *block_end
;
4283 unsigned long length
;
4284 unsigned long cie_id
;
4287 int need_col_headers
= 1;
4288 unsigned char *augmentation_data
= NULL
;
4289 unsigned long augmentation_data_len
= 0;
4290 int encoded_ptr_size
= saved_eh_addr_size
;
4292 int initial_length_size
;
4294 saved_start
= start
;
4295 length
= byte_get (start
, 4); start
+= 4;
4299 printf ("\n%08lx ZERO terminator\n\n",
4300 (unsigned long)(saved_start
- section_start
));
4304 if (length
== 0xffffffff)
4306 length
= byte_get (start
, 8);
4309 initial_length_size
= 12;
4314 initial_length_size
= 4;
4317 block_end
= saved_start
+ length
+ initial_length_size
;
4318 if (block_end
> end
)
4320 warn ("Invalid length %#08lx in FDE at %#08lx\n",
4321 length
, (unsigned long)(saved_start
- section_start
));
4324 cie_id
= byte_get (start
, offset_size
); start
+= offset_size
;
4326 if (is_eh
? (cie_id
== 0) : (cie_id
== DW_CIE_ID
))
4330 fc
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
4331 memset (fc
, 0, sizeof (Frame_Chunk
));
4335 fc
->chunk_start
= saved_start
;
4337 fc
->col_type
= (short int *) xmalloc (sizeof (short int));
4338 fc
->col_offset
= (int *) xmalloc (sizeof (int));
4339 frame_need_space (fc
, max_regs
- 1);
4343 fc
->augmentation
= (char *) start
;
4344 start
= (unsigned char *) strchr ((char *) start
, '\0') + 1;
4346 if (strcmp (fc
->augmentation
, "eh") == 0)
4347 start
+= eh_addr_size
;
4351 fc
->ptr_size
= GET (1);
4352 fc
->segment_size
= GET (1);
4353 eh_addr_size
= fc
->ptr_size
;
4357 fc
->ptr_size
= eh_addr_size
;
4358 fc
->segment_size
= 0;
4360 fc
->code_factor
= LEB ();
4361 fc
->data_factor
= SLEB ();
4371 if (fc
->augmentation
[0] == 'z')
4373 augmentation_data_len
= LEB ();
4374 augmentation_data
= start
;
4375 start
+= augmentation_data_len
;
4379 if (do_debug_frames_interp
)
4380 printf ("\n%08lx %08lx %08lx CIE \"%s\" cf=%d df=%d ra=%d\n",
4381 (unsigned long)(saved_start
- section_start
), length
, cie_id
,
4382 fc
->augmentation
, fc
->code_factor
, fc
->data_factor
,
4386 printf ("\n%08lx %08lx %08lx CIE\n",
4387 (unsigned long)(saved_start
- section_start
), length
, cie_id
);
4388 printf (" Version: %d\n", version
);
4389 printf (" Augmentation: \"%s\"\n", fc
->augmentation
);
4392 printf (" Pointer Size: %u\n", fc
->ptr_size
);
4393 printf (" Segment Size: %u\n", fc
->segment_size
);
4395 printf (" Code alignment factor: %u\n", fc
->code_factor
);
4396 printf (" Data alignment factor: %d\n", fc
->data_factor
);
4397 printf (" Return address column: %d\n", fc
->ra
);
4399 if (augmentation_data_len
)
4402 printf (" Augmentation data: ");
4403 for (i
= 0; i
< augmentation_data_len
; ++i
)
4404 printf (" %02x", augmentation_data
[i
]);
4410 if (augmentation_data_len
)
4412 unsigned char *p
, *q
;
4413 p
= (unsigned char *) fc
->augmentation
+ 1;
4414 q
= augmentation_data
;
4421 q
+= 1 + size_of_encoded_value (*q
);
4423 fc
->fde_encoding
= *q
++;
4431 if (fc
->fde_encoding
)
4432 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
4435 frame_need_space (fc
, fc
->ra
);
4439 unsigned char *look_for
;
4440 static Frame_Chunk fde_fc
;
4441 unsigned long segment_selector
;
4444 memset (fc
, 0, sizeof (Frame_Chunk
));
4446 look_for
= is_eh
? start
- 4 - cie_id
: section_start
+ cie_id
;
4448 for (cie
= chunks
; cie
; cie
= cie
->next
)
4449 if (cie
->chunk_start
== look_for
)
4454 warn ("Invalid CIE pointer %#08lx in FDE at %#08lx\n",
4455 cie_id
, (unsigned long)(saved_start
- section_start
));
4457 fc
->col_type
= (short int *) xmalloc (sizeof (short int));
4458 fc
->col_offset
= (int *) xmalloc (sizeof (int));
4459 frame_need_space (fc
, max_regs
- 1);
4461 fc
->augmentation
= "";
4462 fc
->fde_encoding
= 0;
4463 fc
->ptr_size
= eh_addr_size
;
4464 fc
->segment_size
= 0;
4468 fc
->ncols
= cie
->ncols
;
4469 fc
->col_type
= (short int *) xcmalloc (fc
->ncols
, sizeof (short int));
4470 fc
->col_offset
= (int *) xcmalloc (fc
->ncols
, sizeof (int));
4471 memcpy (fc
->col_type
, cie
->col_type
, fc
->ncols
* sizeof (short int));
4472 memcpy (fc
->col_offset
, cie
->col_offset
, fc
->ncols
* sizeof (int));
4473 fc
->augmentation
= cie
->augmentation
;
4474 fc
->ptr_size
= cie
->ptr_size
;
4475 eh_addr_size
= cie
->ptr_size
;
4476 fc
->segment_size
= cie
->segment_size
;
4477 fc
->code_factor
= cie
->code_factor
;
4478 fc
->data_factor
= cie
->data_factor
;
4479 fc
->cfa_reg
= cie
->cfa_reg
;
4480 fc
->cfa_offset
= cie
->cfa_offset
;
4482 frame_need_space (fc
, max_regs
- 1);
4483 fc
->fde_encoding
= cie
->fde_encoding
;
4486 if (fc
->fde_encoding
)
4487 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
4489 segment_selector
= 0;
4490 if (fc
->segment_size
)
4492 segment_selector
= byte_get (start
, fc
->segment_size
);
4493 start
+= fc
->segment_size
;
4495 fc
->pc_begin
= get_encoded_value (start
, fc
->fde_encoding
, section
);
4496 start
+= encoded_ptr_size
;
4497 fc
->pc_range
= byte_get (start
, encoded_ptr_size
);
4498 start
+= encoded_ptr_size
;
4500 if (cie
->augmentation
[0] == 'z')
4502 augmentation_data_len
= LEB ();
4503 augmentation_data
= start
;
4504 start
+= augmentation_data_len
;
4507 printf ("\n%08lx %08lx %08lx FDE cie=%08lx pc=",
4508 (unsigned long)(saved_start
- section_start
), length
, cie_id
,
4509 (unsigned long)(cie
->chunk_start
- section_start
));
4510 if (fc
->segment_size
)
4511 printf ("%04lx:", segment_selector
);
4512 printf ("%08lx..%08lx\n", fc
->pc_begin
, fc
->pc_begin
+ fc
->pc_range
);
4513 if (! do_debug_frames_interp
&& augmentation_data_len
)
4517 printf (" Augmentation data: ");
4518 for (i
= 0; i
< augmentation_data_len
; ++i
)
4519 printf (" %02x", augmentation_data
[i
]);
4525 /* At this point, fc is the current chunk, cie (if any) is set, and
4526 we're about to interpret instructions for the chunk. */
4527 /* ??? At present we need to do this always, since this sizes the
4528 fc->col_type and fc->col_offset arrays, which we write into always.
4529 We should probably split the interpreted and non-interpreted bits
4530 into two different routines, since there's so much that doesn't
4531 really overlap between them. */
4532 if (1 || do_debug_frames_interp
)
4534 /* Start by making a pass over the chunk, allocating storage
4535 and taking note of what registers are used. */
4536 unsigned char *tmp
= start
;
4538 while (start
< block_end
)
4541 unsigned long reg
, temp
;
4548 /* Warning: if you add any more cases to this switch, be
4549 sure to add them to the corresponding switch below. */
4552 case DW_CFA_advance_loc
:
4556 if (frame_need_space (fc
, opa
) >= 0)
4557 fc
->col_type
[opa
] = DW_CFA_undefined
;
4559 case DW_CFA_restore
:
4560 if (frame_need_space (fc
, opa
) >= 0)
4561 fc
->col_type
[opa
] = DW_CFA_undefined
;
4563 case DW_CFA_set_loc
:
4564 start
+= encoded_ptr_size
;
4566 case DW_CFA_advance_loc1
:
4569 case DW_CFA_advance_loc2
:
4572 case DW_CFA_advance_loc4
:
4575 case DW_CFA_offset_extended
:
4576 case DW_CFA_val_offset
:
4577 reg
= LEB (); LEB ();
4578 if (frame_need_space (fc
, reg
) >= 0)
4579 fc
->col_type
[reg
] = DW_CFA_undefined
;
4581 case DW_CFA_restore_extended
:
4583 frame_need_space (fc
, reg
);
4584 if (frame_need_space (fc
, reg
) >= 0)
4585 fc
->col_type
[reg
] = DW_CFA_undefined
;
4587 case DW_CFA_undefined
:
4589 if (frame_need_space (fc
, reg
) >= 0)
4590 fc
->col_type
[reg
] = DW_CFA_undefined
;
4592 case DW_CFA_same_value
:
4594 if (frame_need_space (fc
, reg
) >= 0)
4595 fc
->col_type
[reg
] = DW_CFA_undefined
;
4597 case DW_CFA_register
:
4598 reg
= LEB (); LEB ();
4599 if (frame_need_space (fc
, reg
) >= 0)
4600 fc
->col_type
[reg
] = DW_CFA_undefined
;
4602 case DW_CFA_def_cfa
:
4605 case DW_CFA_def_cfa_register
:
4608 case DW_CFA_def_cfa_offset
:
4611 case DW_CFA_def_cfa_expression
:
4615 case DW_CFA_expression
:
4616 case DW_CFA_val_expression
:
4620 if (frame_need_space (fc
, reg
) >= 0)
4621 fc
->col_type
[reg
] = DW_CFA_undefined
;
4623 case DW_CFA_offset_extended_sf
:
4624 case DW_CFA_val_offset_sf
:
4625 reg
= LEB (); SLEB ();
4626 if (frame_need_space (fc
, reg
) >= 0)
4627 fc
->col_type
[reg
] = DW_CFA_undefined
;
4629 case DW_CFA_def_cfa_sf
:
4632 case DW_CFA_def_cfa_offset_sf
:
4635 case DW_CFA_MIPS_advance_loc8
:
4638 case DW_CFA_GNU_args_size
:
4641 case DW_CFA_GNU_negative_offset_extended
:
4642 reg
= LEB (); LEB ();
4643 if (frame_need_space (fc
, reg
) >= 0)
4644 fc
->col_type
[reg
] = DW_CFA_undefined
;
4653 /* Now we know what registers are used, make a second pass over
4654 the chunk, this time actually printing out the info. */
4656 while (start
< block_end
)
4659 unsigned long ul
, reg
, roffs
;
4662 const char *reg_prefix
= "";
4669 /* Warning: if you add any more cases to this switch, be
4670 sure to add them to the corresponding switch above. */
4673 case DW_CFA_advance_loc
:
4674 if (do_debug_frames_interp
)
4675 frame_display_row (fc
, &need_col_headers
, &max_regs
);
4677 printf (" DW_CFA_advance_loc: %d to %08lx\n",
4678 opa
* fc
->code_factor
,
4679 fc
->pc_begin
+ opa
* fc
->code_factor
);
4680 fc
->pc_begin
+= opa
* fc
->code_factor
;
4685 if (opa
>= (unsigned int) fc
->ncols
)
4686 reg_prefix
= bad_reg
;
4687 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4688 printf (" DW_CFA_offset: %s%s at cfa%+ld\n",
4689 reg_prefix
, regname (opa
, 0),
4690 roffs
* fc
->data_factor
);
4691 if (*reg_prefix
== '\0')
4693 fc
->col_type
[opa
] = DW_CFA_offset
;
4694 fc
->col_offset
[opa
] = roffs
* fc
->data_factor
;
4698 case DW_CFA_restore
:
4699 if (opa
>= (unsigned int) cie
->ncols
4700 || opa
>= (unsigned int) fc
->ncols
)
4701 reg_prefix
= bad_reg
;
4702 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4703 printf (" DW_CFA_restore: %s%s\n",
4704 reg_prefix
, regname (opa
, 0));
4705 if (*reg_prefix
== '\0')
4707 fc
->col_type
[opa
] = cie
->col_type
[opa
];
4708 fc
->col_offset
[opa
] = cie
->col_offset
[opa
];
4712 case DW_CFA_set_loc
:
4713 vma
= get_encoded_value (start
, fc
->fde_encoding
, section
);
4714 start
+= encoded_ptr_size
;
4715 if (do_debug_frames_interp
)
4716 frame_display_row (fc
, &need_col_headers
, &max_regs
);
4718 printf (" DW_CFA_set_loc: %08lx\n", (unsigned long)vma
);
4722 case DW_CFA_advance_loc1
:
4723 ofs
= byte_get (start
, 1); start
+= 1;
4724 if (do_debug_frames_interp
)
4725 frame_display_row (fc
, &need_col_headers
, &max_regs
);
4727 printf (" DW_CFA_advance_loc1: %ld to %08lx\n",
4728 ofs
* fc
->code_factor
,
4729 fc
->pc_begin
+ ofs
* fc
->code_factor
);
4730 fc
->pc_begin
+= ofs
* fc
->code_factor
;
4733 case DW_CFA_advance_loc2
:
4734 ofs
= byte_get (start
, 2); start
+= 2;
4735 if (do_debug_frames_interp
)
4736 frame_display_row (fc
, &need_col_headers
, &max_regs
);
4738 printf (" DW_CFA_advance_loc2: %ld to %08lx\n",
4739 ofs
* fc
->code_factor
,
4740 fc
->pc_begin
+ ofs
* fc
->code_factor
);
4741 fc
->pc_begin
+= ofs
* fc
->code_factor
;
4744 case DW_CFA_advance_loc4
:
4745 ofs
= byte_get (start
, 4); start
+= 4;
4746 if (do_debug_frames_interp
)
4747 frame_display_row (fc
, &need_col_headers
, &max_regs
);
4749 printf (" DW_CFA_advance_loc4: %ld to %08lx\n",
4750 ofs
* fc
->code_factor
,
4751 fc
->pc_begin
+ ofs
* fc
->code_factor
);
4752 fc
->pc_begin
+= ofs
* fc
->code_factor
;
4755 case DW_CFA_offset_extended
:
4758 if (reg
>= (unsigned int) fc
->ncols
)
4759 reg_prefix
= bad_reg
;
4760 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4761 printf (" DW_CFA_offset_extended: %s%s at cfa%+ld\n",
4762 reg_prefix
, regname (reg
, 0),
4763 roffs
* fc
->data_factor
);
4764 if (*reg_prefix
== '\0')
4766 fc
->col_type
[reg
] = DW_CFA_offset
;
4767 fc
->col_offset
[reg
] = roffs
* fc
->data_factor
;
4771 case DW_CFA_val_offset
:
4774 if (reg
>= (unsigned int) fc
->ncols
)
4775 reg_prefix
= bad_reg
;
4776 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4777 printf (" DW_CFA_val_offset: %s%s at cfa%+ld\n",
4778 reg_prefix
, regname (reg
, 0),
4779 roffs
* fc
->data_factor
);
4780 if (*reg_prefix
== '\0')
4782 fc
->col_type
[reg
] = DW_CFA_val_offset
;
4783 fc
->col_offset
[reg
] = roffs
* fc
->data_factor
;
4787 case DW_CFA_restore_extended
:
4789 if (reg
>= (unsigned int) cie
->ncols
4790 || reg
>= (unsigned int) fc
->ncols
)
4791 reg_prefix
= bad_reg
;
4792 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4793 printf (" DW_CFA_restore_extended: %s%s\n",
4794 reg_prefix
, regname (reg
, 0));
4795 if (*reg_prefix
== '\0')
4797 fc
->col_type
[reg
] = cie
->col_type
[reg
];
4798 fc
->col_offset
[reg
] = cie
->col_offset
[reg
];
4802 case DW_CFA_undefined
:
4804 if (reg
>= (unsigned int) fc
->ncols
)
4805 reg_prefix
= bad_reg
;
4806 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4807 printf (" DW_CFA_undefined: %s%s\n",
4808 reg_prefix
, regname (reg
, 0));
4809 if (*reg_prefix
== '\0')
4811 fc
->col_type
[reg
] = DW_CFA_undefined
;
4812 fc
->col_offset
[reg
] = 0;
4816 case DW_CFA_same_value
:
4818 if (reg
>= (unsigned int) fc
->ncols
)
4819 reg_prefix
= bad_reg
;
4820 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4821 printf (" DW_CFA_same_value: %s%s\n",
4822 reg_prefix
, regname (reg
, 0));
4823 if (*reg_prefix
== '\0')
4825 fc
->col_type
[reg
] = DW_CFA_same_value
;
4826 fc
->col_offset
[reg
] = 0;
4830 case DW_CFA_register
:
4833 if (reg
>= (unsigned int) fc
->ncols
)
4834 reg_prefix
= bad_reg
;
4835 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4837 printf (" DW_CFA_register: %s%s in ",
4838 reg_prefix
, regname (reg
, 0));
4839 puts (regname (roffs
, 0));
4841 if (*reg_prefix
== '\0')
4843 fc
->col_type
[reg
] = DW_CFA_register
;
4844 fc
->col_offset
[reg
] = roffs
;
4848 case DW_CFA_remember_state
:
4849 if (! do_debug_frames_interp
)
4850 printf (" DW_CFA_remember_state\n");
4851 rs
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
4852 rs
->ncols
= fc
->ncols
;
4853 rs
->col_type
= (short int *) xcmalloc (rs
->ncols
,
4854 sizeof (short int));
4855 rs
->col_offset
= (int *) xcmalloc (rs
->ncols
, sizeof (int));
4856 memcpy (rs
->col_type
, fc
->col_type
, rs
->ncols
);
4857 memcpy (rs
->col_offset
, fc
->col_offset
, rs
->ncols
* sizeof (int));
4858 rs
->next
= remembered_state
;
4859 remembered_state
= rs
;
4862 case DW_CFA_restore_state
:
4863 if (! do_debug_frames_interp
)
4864 printf (" DW_CFA_restore_state\n");
4865 rs
= remembered_state
;
4868 remembered_state
= rs
->next
;
4869 frame_need_space (fc
, rs
->ncols
- 1);
4870 memcpy (fc
->col_type
, rs
->col_type
, rs
->ncols
);
4871 memcpy (fc
->col_offset
, rs
->col_offset
,
4872 rs
->ncols
* sizeof (int));
4873 free (rs
->col_type
);
4874 free (rs
->col_offset
);
4877 else if (do_debug_frames_interp
)
4878 printf ("Mismatched DW_CFA_restore_state\n");
4881 case DW_CFA_def_cfa
:
4882 fc
->cfa_reg
= LEB ();
4883 fc
->cfa_offset
= LEB ();
4885 if (! do_debug_frames_interp
)
4886 printf (" DW_CFA_def_cfa: %s ofs %d\n",
4887 regname (fc
->cfa_reg
, 0), fc
->cfa_offset
);
4890 case DW_CFA_def_cfa_register
:
4891 fc
->cfa_reg
= LEB ();
4893 if (! do_debug_frames_interp
)
4894 printf (" DW_CFA_def_cfa_register: %s\n",
4895 regname (fc
->cfa_reg
, 0));
4898 case DW_CFA_def_cfa_offset
:
4899 fc
->cfa_offset
= LEB ();
4900 if (! do_debug_frames_interp
)
4901 printf (" DW_CFA_def_cfa_offset: %d\n", fc
->cfa_offset
);
4905 if (! do_debug_frames_interp
)
4906 printf (" DW_CFA_nop\n");
4909 case DW_CFA_def_cfa_expression
:
4911 if (! do_debug_frames_interp
)
4913 printf (" DW_CFA_def_cfa_expression (");
4914 decode_location_expression (start
, eh_addr_size
, 0, -1,
4922 case DW_CFA_expression
:
4925 if (reg
>= (unsigned int) fc
->ncols
)
4926 reg_prefix
= bad_reg
;
4927 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4929 printf (" DW_CFA_expression: %s%s (",
4930 reg_prefix
, regname (reg
, 0));
4931 decode_location_expression (start
, eh_addr_size
, 0, -1,
4935 if (*reg_prefix
== '\0')
4936 fc
->col_type
[reg
] = DW_CFA_expression
;
4940 case DW_CFA_val_expression
:
4943 if (reg
>= (unsigned int) fc
->ncols
)
4944 reg_prefix
= bad_reg
;
4945 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4947 printf (" DW_CFA_val_expression: %s%s (",
4948 reg_prefix
, regname (reg
, 0));
4949 decode_location_expression (start
, eh_addr_size
, 0, -1,
4953 if (*reg_prefix
== '\0')
4954 fc
->col_type
[reg
] = DW_CFA_val_expression
;
4958 case DW_CFA_offset_extended_sf
:
4961 if (frame_need_space (fc
, reg
) < 0)
4962 reg_prefix
= bad_reg
;
4963 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4964 printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+ld\n",
4965 reg_prefix
, regname (reg
, 0),
4966 l
* fc
->data_factor
);
4967 if (*reg_prefix
== '\0')
4969 fc
->col_type
[reg
] = DW_CFA_offset
;
4970 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
4974 case DW_CFA_val_offset_sf
:
4977 if (frame_need_space (fc
, reg
) < 0)
4978 reg_prefix
= bad_reg
;
4979 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4980 printf (" DW_CFA_val_offset_sf: %s%s at cfa%+ld\n",
4981 reg_prefix
, regname (reg
, 0),
4982 l
* fc
->data_factor
);
4983 if (*reg_prefix
== '\0')
4985 fc
->col_type
[reg
] = DW_CFA_val_offset
;
4986 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
4990 case DW_CFA_def_cfa_sf
:
4991 fc
->cfa_reg
= LEB ();
4992 fc
->cfa_offset
= SLEB ();
4993 fc
->cfa_offset
= fc
->cfa_offset
* fc
->data_factor
;
4995 if (! do_debug_frames_interp
)
4996 printf (" DW_CFA_def_cfa_sf: %s ofs %d\n",
4997 regname (fc
->cfa_reg
, 0), fc
->cfa_offset
);
5000 case DW_CFA_def_cfa_offset_sf
:
5001 fc
->cfa_offset
= SLEB ();
5002 fc
->cfa_offset
= fc
->cfa_offset
* fc
->data_factor
;
5003 if (! do_debug_frames_interp
)
5004 printf (" DW_CFA_def_cfa_offset_sf: %d\n", fc
->cfa_offset
);
5007 case DW_CFA_MIPS_advance_loc8
:
5008 ofs
= byte_get (start
, 8); start
+= 8;
5009 if (do_debug_frames_interp
)
5010 frame_display_row (fc
, &need_col_headers
, &max_regs
);
5012 printf (" DW_CFA_MIPS_advance_loc8: %ld to %08lx\n",
5013 ofs
* fc
->code_factor
,
5014 fc
->pc_begin
+ ofs
* fc
->code_factor
);
5015 fc
->pc_begin
+= ofs
* fc
->code_factor
;
5018 case DW_CFA_GNU_window_save
:
5019 if (! do_debug_frames_interp
)
5020 printf (" DW_CFA_GNU_window_save\n");
5023 case DW_CFA_GNU_args_size
:
5025 if (! do_debug_frames_interp
)
5026 printf (" DW_CFA_GNU_args_size: %ld\n", ul
);
5029 case DW_CFA_GNU_negative_offset_extended
:
5032 if (frame_need_space (fc
, reg
) < 0)
5033 reg_prefix
= bad_reg
;
5034 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
5035 printf (" DW_CFA_GNU_negative_offset_extended: %s%s at cfa%+ld\n",
5036 reg_prefix
, regname (reg
, 0),
5037 l
* fc
->data_factor
);
5038 if (*reg_prefix
== '\0')
5040 fc
->col_type
[reg
] = DW_CFA_offset
;
5041 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
5046 if (op
>= DW_CFA_lo_user
&& op
<= DW_CFA_hi_user
)
5047 printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op
);
5049 warn (_("unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op
);
5054 if (do_debug_frames_interp
)
5055 frame_display_row (fc
, &need_col_headers
, &max_regs
);
5058 eh_addr_size
= saved_eh_addr_size
;
5071 display_gdb_index (struct dwarf_section
*section
,
5072 void *file ATTRIBUTE_UNUSED
)
5074 unsigned char *start
= section
->start
;
5076 uint32_t cu_list_offset
, tu_list_offset
;
5077 uint32_t address_table_offset
, symbol_table_offset
, constant_pool_offset
;
5078 unsigned int cu_list_elements
, tu_list_elements
;
5079 unsigned int address_table_size
, symbol_table_slots
;
5080 unsigned char *cu_list
, *tu_list
;
5081 unsigned char *address_table
, *symbol_table
, *constant_pool
;
5084 /* The documentation for the format of this file is in gdb/dwarf2read.c. */
5086 printf (_("Contents of the %s section:\n"), section
->name
);
5088 if (section
->size
< 6 * sizeof (uint32_t))
5090 warn (_("Truncated header in the %s section.\n"), section
->name
);
5094 version
= byte_get_little_endian (start
, 4);
5095 printf (_("Version %ld\n"), (long) version
);
5097 /* Prior versions are obsolete, and future versions may not be
5098 backwards compatible. */
5102 warn (_("The address table data in version 3 may be wrong.\n"));
5105 warn (_("Version 4 does not support case insensitive lookups.\n"));
5110 warn (_("Unsupported version %lu.\n"), (unsigned long) version
);
5114 cu_list_offset
= byte_get_little_endian (start
+ 4, 4);
5115 tu_list_offset
= byte_get_little_endian (start
+ 8, 4);
5116 address_table_offset
= byte_get_little_endian (start
+ 12, 4);
5117 symbol_table_offset
= byte_get_little_endian (start
+ 16, 4);
5118 constant_pool_offset
= byte_get_little_endian (start
+ 20, 4);
5120 if (cu_list_offset
> section
->size
5121 || tu_list_offset
> section
->size
5122 || address_table_offset
> section
->size
5123 || symbol_table_offset
> section
->size
5124 || constant_pool_offset
> section
->size
)
5126 warn (_("Corrupt header in the %s section.\n"), section
->name
);
5130 cu_list_elements
= (tu_list_offset
- cu_list_offset
) / 8;
5131 tu_list_elements
= (address_table_offset
- tu_list_offset
) / 8;
5132 address_table_size
= symbol_table_offset
- address_table_offset
;
5133 symbol_table_slots
= (constant_pool_offset
- symbol_table_offset
) / 8;
5135 cu_list
= start
+ cu_list_offset
;
5136 tu_list
= start
+ tu_list_offset
;
5137 address_table
= start
+ address_table_offset
;
5138 symbol_table
= start
+ symbol_table_offset
;
5139 constant_pool
= start
+ constant_pool_offset
;
5141 printf (_("\nCU table:\n"));
5142 for (i
= 0; i
< cu_list_elements
; i
+= 2)
5144 uint64_t cu_offset
= byte_get_little_endian (cu_list
+ i
* 8, 8);
5145 uint64_t cu_length
= byte_get_little_endian (cu_list
+ i
* 8 + 8, 8);
5147 printf (_("[%3u] 0x%lx - 0x%lx\n"), i
/ 2,
5148 (unsigned long) cu_offset
,
5149 (unsigned long) (cu_offset
+ cu_length
- 1));
5152 printf (_("\nTU table:\n"));
5153 for (i
= 0; i
< tu_list_elements
; i
+= 3)
5155 uint64_t tu_offset
= byte_get_little_endian (tu_list
+ i
* 8, 8);
5156 uint64_t type_offset
= byte_get_little_endian (tu_list
+ i
* 8 + 8, 8);
5157 uint64_t signature
= byte_get_little_endian (tu_list
+ i
* 8 + 16, 8);
5159 printf (_("[%3u] 0x%lx 0x%lx "), i
/ 3,
5160 (unsigned long) tu_offset
,
5161 (unsigned long) type_offset
);
5162 print_dwarf_vma (signature
, 8);
5166 printf (_("\nAddress table:\n"));
5167 for (i
= 0; i
< address_table_size
; i
+= 2 * 8 + 4)
5169 uint64_t low
= byte_get_little_endian (address_table
+ i
, 8);
5170 uint64_t high
= byte_get_little_endian (address_table
+ i
+ 8, 8);
5171 uint32_t cu_index
= byte_get_little_endian (address_table
+ i
+ 16, 4);
5173 print_dwarf_vma (low
, 8);
5174 print_dwarf_vma (high
, 8);
5175 printf (_("%lu\n"), (unsigned long) cu_index
);
5178 printf (_("\nSymbol table:\n"));
5179 for (i
= 0; i
< symbol_table_slots
; ++i
)
5181 uint32_t name_offset
= byte_get_little_endian (symbol_table
+ i
* 8, 4);
5182 uint32_t cu_vector_offset
= byte_get_little_endian (symbol_table
+ i
* 8 + 4, 4);
5183 uint32_t num_cus
, cu
;
5185 if (name_offset
!= 0
5186 || cu_vector_offset
!= 0)
5190 printf ("[%3u] %s:", i
, constant_pool
+ name_offset
);
5191 num_cus
= byte_get_little_endian (constant_pool
+ cu_vector_offset
, 4);
5192 for (j
= 0; j
< num_cus
; ++j
)
5194 cu
= byte_get_little_endian (constant_pool
+ cu_vector_offset
+ 4 + j
* 4, 4);
5195 /* Convert to TU number if it's for a type unit. */
5196 if (cu
>= cu_list_elements
)
5197 printf (" T%lu", (unsigned long) (cu
- cu_list_elements
));
5199 printf (" %lu", (unsigned long) cu
);
5209 display_debug_not_supported (struct dwarf_section
*section
,
5210 void *file ATTRIBUTE_UNUSED
)
5212 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
5219 cmalloc (size_t nmemb
, size_t size
)
5221 /* Check for overflow. */
5222 if (nmemb
>= ~(size_t) 0 / size
)
5225 return malloc (nmemb
* size
);
5229 xcmalloc (size_t nmemb
, size_t size
)
5231 /* Check for overflow. */
5232 if (nmemb
>= ~(size_t) 0 / size
)
5235 return xmalloc (nmemb
* size
);
5239 xcrealloc (void *ptr
, size_t nmemb
, size_t size
)
5241 /* Check for overflow. */
5242 if (nmemb
>= ~(size_t) 0 / size
)
5245 return xrealloc (ptr
, nmemb
* size
);
5249 free_debug_memory (void)
5255 for (i
= 0; i
< max
; i
++)
5256 free_debug_section ((enum dwarf_section_display_enum
) i
);
5258 if (debug_information
!= NULL
)
5260 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
)
5262 for (i
= 0; i
< num_debug_info_entries
; i
++)
5264 if (!debug_information
[i
].max_loc_offsets
)
5266 free (debug_information
[i
].loc_offsets
);
5267 free (debug_information
[i
].have_frame_base
);
5269 if (!debug_information
[i
].max_range_lists
)
5270 free (debug_information
[i
].range_lists
);
5274 free (debug_information
);
5275 debug_information
= NULL
;
5276 num_debug_info_entries
= 0;
5281 dwarf_select_sections_by_names (const char *names
)
5285 const char * option
;
5289 debug_dump_long_opts
;
5291 static const debug_dump_long_opts opts_table
[] =
5293 /* Please keep this table alpha- sorted. */
5294 { "Ranges", & do_debug_ranges
, 1 },
5295 { "abbrev", & do_debug_abbrevs
, 1 },
5296 { "aranges", & do_debug_aranges
, 1 },
5297 { "frames", & do_debug_frames
, 1 },
5298 { "frames-interp", & do_debug_frames_interp
, 1 },
5299 { "info", & do_debug_info
, 1 },
5300 { "line", & do_debug_lines
, FLAG_DEBUG_LINES_RAW
}, /* For backwards compatibility. */
5301 { "rawline", & do_debug_lines
, FLAG_DEBUG_LINES_RAW
},
5302 { "decodedline", & do_debug_lines
, FLAG_DEBUG_LINES_DECODED
},
5303 { "loc", & do_debug_loc
, 1 },
5304 { "macro", & do_debug_macinfo
, 1 },
5305 { "pubnames", & do_debug_pubnames
, 1 },
5306 { "pubtypes", & do_debug_pubtypes
, 1 },
5307 /* This entry is for compatability
5308 with earlier versions of readelf. */
5309 { "ranges", & do_debug_aranges
, 1 },
5310 { "str", & do_debug_str
, 1 },
5311 /* The special .gdb_index section. */
5312 { "gdb_index", & do_gdb_index
, 1 },
5313 /* These trace_* sections are used by Itanium VMS. */
5314 { "trace_abbrev", & do_trace_abbrevs
, 1 },
5315 { "trace_aranges", & do_trace_aranges
, 1 },
5316 { "trace_info", & do_trace_info
, 1 },
5325 const debug_dump_long_opts
* entry
;
5327 for (entry
= opts_table
; entry
->option
; entry
++)
5329 size_t len
= strlen (entry
->option
);
5331 if (strncmp (p
, entry
->option
, len
) == 0
5332 && (p
[len
] == ',' || p
[len
] == '\0'))
5334 * entry
->variable
|= entry
->val
;
5336 /* The --debug-dump=frames-interp option also
5337 enables the --debug-dump=frames option. */
5338 if (do_debug_frames_interp
)
5339 do_debug_frames
= 1;
5346 if (entry
->option
== NULL
)
5348 warn (_("Unrecognized debug option '%s'\n"), p
);
5349 p
= strchr (p
, ',');
5360 dwarf_select_sections_by_letters (const char *letters
)
5362 unsigned int lindex
= 0;
5364 while (letters
[lindex
])
5365 switch (letters
[lindex
++])
5372 do_debug_abbrevs
= 1;
5376 do_debug_lines
|= FLAG_DEBUG_LINES_RAW
;
5380 do_debug_lines
|= FLAG_DEBUG_LINES_DECODED
;
5384 do_debug_pubnames
= 1;
5388 do_debug_pubtypes
= 1;
5392 do_debug_aranges
= 1;
5396 do_debug_ranges
= 1;
5400 do_debug_frames_interp
= 1;
5402 do_debug_frames
= 1;
5406 do_debug_macinfo
= 1;
5418 warn (_("Unrecognized debug option '%s'\n"), optarg
);
5424 dwarf_select_sections_all (void)
5427 do_debug_abbrevs
= 1;
5428 do_debug_lines
= FLAG_DEBUG_LINES_RAW
;
5429 do_debug_pubnames
= 1;
5430 do_debug_pubtypes
= 1;
5431 do_debug_aranges
= 1;
5432 do_debug_ranges
= 1;
5433 do_debug_frames
= 1;
5434 do_debug_macinfo
= 1;
5439 do_trace_abbrevs
= 1;
5440 do_trace_aranges
= 1;
5443 struct dwarf_section_display debug_displays
[] =
5445 { { ".debug_abbrev", ".zdebug_abbrev", NULL
, NULL
, 0, 0 },
5446 display_debug_abbrev
, &do_debug_abbrevs
, 0 },
5447 { { ".debug_aranges", ".zdebug_aranges", NULL
, NULL
, 0, 0 },
5448 display_debug_aranges
, &do_debug_aranges
, 1 },
5449 { { ".debug_frame", ".zdebug_frame", NULL
, NULL
, 0, 0 },
5450 display_debug_frames
, &do_debug_frames
, 1 },
5451 { { ".debug_info", ".zdebug_info", NULL
, NULL
, 0, 0 },
5452 display_debug_info
, &do_debug_info
, 1 },
5453 { { ".debug_line", ".zdebug_line", NULL
, NULL
, 0, 0 },
5454 display_debug_lines
, &do_debug_lines
, 1 },
5455 { { ".debug_pubnames", ".zdebug_pubnames", NULL
, NULL
, 0, 0 },
5456 display_debug_pubnames
, &do_debug_pubnames
, 0 },
5457 { { ".eh_frame", "", NULL
, NULL
, 0, 0 },
5458 display_debug_frames
, &do_debug_frames
, 1 },
5459 { { ".debug_macinfo", ".zdebug_macinfo", NULL
, NULL
, 0, 0 },
5460 display_debug_macinfo
, &do_debug_macinfo
, 0 },
5461 { { ".debug_str", ".zdebug_str", NULL
, NULL
, 0, 0 },
5462 display_debug_str
, &do_debug_str
, 0 },
5463 { { ".debug_loc", ".zdebug_loc", NULL
, NULL
, 0, 0 },
5464 display_debug_loc
, &do_debug_loc
, 1 },
5465 { { ".debug_pubtypes", ".zdebug_pubtypes", NULL
, NULL
, 0, 0 },
5466 display_debug_pubnames
, &do_debug_pubtypes
, 0 },
5467 { { ".debug_ranges", ".zdebug_ranges", NULL
, NULL
, 0, 0 },
5468 display_debug_ranges
, &do_debug_ranges
, 1 },
5469 { { ".debug_static_func", ".zdebug_static_func", NULL
, NULL
, 0, 0 },
5470 display_debug_not_supported
, NULL
, 0 },
5471 { { ".debug_static_vars", ".zdebug_static_vars", NULL
, NULL
, 0, 0 },
5472 display_debug_not_supported
, NULL
, 0 },
5473 { { ".debug_types", ".zdebug_types", NULL
, NULL
, 0, 0 },
5474 display_debug_types
, &do_debug_info
, 1 },
5475 { { ".debug_weaknames", ".zdebug_weaknames", NULL
, NULL
, 0, 0 },
5476 display_debug_not_supported
, NULL
, 0 },
5477 { { ".gdb_index", "", NULL
, NULL
, 0, 0 },
5478 display_gdb_index
, &do_gdb_index
, 0 },
5479 { { ".trace_info", "", NULL
, NULL
, 0, 0 },
5480 display_trace_info
, &do_trace_info
, 1 },
5481 { { ".trace_abbrev", "", NULL
, NULL
, 0, 0 },
5482 display_debug_abbrev
, &do_trace_abbrevs
, 0 },
5483 { { ".trace_aranges", "", NULL
, NULL
, 0, 0 },
5484 display_debug_aranges
, &do_trace_aranges
, 0 }