1 /* dwarf.c -- display DWARF contents of a BFD binary file
2 Copyright 2005, 2006, 2007, 2008, 2009, 2010, 2011
3 Free Software Foundation, Inc.
5 This file is part of GNU Binutils.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
23 #include "libiberty.h"
25 #include "bfd_stdint.h"
28 #include "elf/common.h"
32 static const char *regname (unsigned int regno
, int row
);
34 static int have_frame_base
;
35 static int need_base_address
;
37 static unsigned int last_pointer_size
= 0;
38 static int warned_about_missing_comp_units
= FALSE
;
40 static unsigned int num_debug_info_entries
= 0;
41 static debug_info
*debug_information
= NULL
;
42 /* Special value for num_debug_info_entries to indicate
43 that the .debug_info section could not be loaded/parsed. */
44 #define DEBUG_INFO_UNAVAILABLE (unsigned int) -1
51 int do_debug_pubnames
;
52 int do_debug_pubtypes
;
56 int do_debug_frames_interp
;
66 /* Values for do_debug_lines. */
67 #define FLAG_DEBUG_LINES_RAW 1
68 #define FLAG_DEBUG_LINES_DECODED 2
71 size_of_encoded_value (int encoding
)
73 switch (encoding
& 0x7)
76 case 0: return eh_addr_size
;
84 get_encoded_value (unsigned char *data
,
86 struct dwarf_section
*section
)
88 int size
= size_of_encoded_value (encoding
);
91 if (encoding
& DW_EH_PE_signed
)
92 val
= byte_get_signed (data
, size
);
94 val
= byte_get (data
, size
);
96 if ((encoding
& 0x70) == DW_EH_PE_pcrel
)
97 val
+= section
->address
+ (data
- section
->start
);
101 /* Print a dwarf_vma value (typically an address, offset or length) in
102 hexadecimal format, followed by a space. The length of the value (and
103 hence the precision displayed) is determined by the byte_size parameter. */
106 print_dwarf_vma (dwarf_vma val
, unsigned byte_size
)
108 static char buff
[18];
111 /* Printf does not have a way of specifiying a maximum field width for an
112 integer value, so we print the full value into a buffer and then select
113 the precision we need. */
114 #if __STDC_VERSION__ >= 199901L || (defined(__GNUC__) && __GNUC__ >= 2)
116 snprintf (buff
, sizeof (buff
), "%16.16llx ", val
);
118 snprintf (buff
, sizeof (buff
), "%016I64x ", val
);
121 snprintf (buff
, sizeof (buff
), "%16.16lx ", val
);
126 if (byte_size
> 0 && byte_size
<= 8)
127 offset
= 16 - 2 * byte_size
;
129 error ("Wrong size in print_dwarf_vma");
132 fputs (buff
+ offset
, stdout
);
135 #if __STDC_VERSION__ >= 199901L || (defined(__GNUC__) && __GNUC__ >= 2)
137 #define DWARF_VMA_FMT "ll"
139 #define DWARF_VMA_FMT "I64"
142 #define DWARF_VMA_FMT "l"
146 dwarf_vmatoa (const char *fmtch
, dwarf_vma value
)
148 /* As dwarf_vmatoa is used more then once in a printf call
149 for output, we are cycling through an fixed array of pointers
150 for return address. */
151 static int buf_pos
= 0;
152 static struct dwarf_vmatoa_buf
159 sprintf (fmt
, "%%%s%s", DWARF_VMA_FMT
, fmtch
);
161 ret
= buf
[buf_pos
++].place
;
162 buf_pos
%= ARRAY_SIZE (buf
);
164 snprintf (ret
, sizeof (buf
[0].place
), fmt
, value
);
170 read_leb128 (unsigned char *data
, unsigned int *length_return
, int sign
)
172 dwarf_vma result
= 0;
173 unsigned int num_read
= 0;
174 unsigned int shift
= 0;
182 result
|= ((dwarf_vma
) (byte
& 0x7f)) << shift
;
189 if (length_return
!= NULL
)
190 *length_return
= num_read
;
192 if (sign
&& (shift
< 8 * sizeof (result
)) && (byte
& 0x40))
193 result
|= -1L << shift
;
198 /* Create a signed version to avoid painful typecasts. */
199 static dwarf_signed_vma
200 read_sleb128 (unsigned char *data
, unsigned int *length_return
)
202 return (dwarf_signed_vma
) read_leb128 (data
, length_return
, 1);
205 typedef struct State_Machine_Registers
213 unsigned char op_index
;
214 unsigned char end_sequence
;
215 /* This variable hold the number of the last entry seen
216 in the File Table. */
217 unsigned int last_file_entry
;
220 static SMR state_machine_regs
;
223 reset_state_machine (int is_stmt
)
225 state_machine_regs
.address
= 0;
226 state_machine_regs
.op_index
= 0;
227 state_machine_regs
.file
= 1;
228 state_machine_regs
.line
= 1;
229 state_machine_regs
.column
= 0;
230 state_machine_regs
.is_stmt
= is_stmt
;
231 state_machine_regs
.basic_block
= 0;
232 state_machine_regs
.end_sequence
= 0;
233 state_machine_regs
.last_file_entry
= 0;
236 /* Handled an extend line op.
237 Returns the number of bytes read. */
240 process_extended_line_op (unsigned char *data
, int is_stmt
)
242 unsigned char op_code
;
243 unsigned int bytes_read
;
248 len
= read_leb128 (data
, & bytes_read
, 0);
253 warn (_("badly formed extended line op encountered!\n"));
260 printf (_(" Extended opcode %d: "), op_code
);
264 case DW_LNE_end_sequence
:
265 printf (_("End of Sequence\n\n"));
266 reset_state_machine (is_stmt
);
269 case DW_LNE_set_address
:
270 adr
= byte_get (data
, len
- bytes_read
- 1);
271 printf (_("set Address to 0x%s\n"), dwarf_vmatoa ("x", adr
));
272 state_machine_regs
.address
= adr
;
273 state_machine_regs
.op_index
= 0;
276 case DW_LNE_define_file
:
277 printf (_(" define new File Table entry\n"));
278 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
280 printf (" %d\t", ++state_machine_regs
.last_file_entry
);
282 data
+= strlen ((char *) data
) + 1;
283 printf ("%s\t", dwarf_vmatoa ("u", read_leb128 (data
, & bytes_read
, 0)));
285 printf ("%s\t", dwarf_vmatoa ("u", read_leb128 (data
, & bytes_read
, 0)));
287 printf ("%s\t", dwarf_vmatoa ("u", read_leb128 (data
, & bytes_read
, 0)));
288 printf ("%s\n\n", name
);
291 case DW_LNE_set_discriminator
:
292 printf (_("set Discriminator to %s\n"),
293 dwarf_vmatoa ("u", read_leb128 (data
, & bytes_read
, 0)));
297 case DW_LNE_HP_negate_is_UV_update
:
298 printf ("DW_LNE_HP_negate_is_UV_update\n");
300 case DW_LNE_HP_push_context
:
301 printf ("DW_LNE_HP_push_context\n");
303 case DW_LNE_HP_pop_context
:
304 printf ("DW_LNE_HP_pop_context\n");
306 case DW_LNE_HP_set_file_line_column
:
307 printf ("DW_LNE_HP_set_file_line_column\n");
309 case DW_LNE_HP_set_routine_name
:
310 printf ("DW_LNE_HP_set_routine_name\n");
312 case DW_LNE_HP_set_sequence
:
313 printf ("DW_LNE_HP_set_sequence\n");
315 case DW_LNE_HP_negate_post_semantics
:
316 printf ("DW_LNE_HP_negate_post_semantics\n");
318 case DW_LNE_HP_negate_function_exit
:
319 printf ("DW_LNE_HP_negate_function_exit\n");
321 case DW_LNE_HP_negate_front_end_logical
:
322 printf ("DW_LNE_HP_negate_front_end_logical\n");
324 case DW_LNE_HP_define_proc
:
325 printf ("DW_LNE_HP_define_proc\n");
329 if (op_code
>= DW_LNE_lo_user
330 /* The test against DW_LNW_hi_user is redundant due to
331 the limited range of the unsigned char data type used
333 /*&& op_code <= DW_LNE_hi_user*/)
334 printf (_("user defined: length %d\n"), len
- bytes_read
);
336 printf (_("UNKNOWN: length %d\n"), len
- bytes_read
);
344 fetch_indirect_string (dwarf_vma offset
)
346 struct dwarf_section
*section
= &debug_displays
[str
].section
;
348 if (section
->start
== NULL
)
349 return _("<no .debug_str section>");
351 /* DWARF sections under Mach-O have non-zero addresses. */
352 offset
-= section
->address
;
353 if (offset
> section
->size
)
355 warn (_("DW_FORM_strp offset too big: %s\n"),
356 dwarf_vmatoa ("x", offset
));
357 return _("<offset is too big>");
360 return (const char *) section
->start
+ offset
;
363 /* FIXME: There are better and more efficient ways to handle
364 these structures. For now though, I just want something that
365 is simple to implement. */
366 typedef struct abbrev_attr
368 unsigned long attribute
;
370 struct abbrev_attr
*next
;
374 typedef struct abbrev_entry
379 struct abbrev_attr
*first_attr
;
380 struct abbrev_attr
*last_attr
;
381 struct abbrev_entry
*next
;
385 static abbrev_entry
*first_abbrev
= NULL
;
386 static abbrev_entry
*last_abbrev
= NULL
;
393 for (abbrv
= first_abbrev
; abbrv
;)
395 abbrev_entry
*next_abbrev
= abbrv
->next
;
398 for (attr
= abbrv
->first_attr
; attr
;)
400 abbrev_attr
*next_attr
= attr
->next
;
410 last_abbrev
= first_abbrev
= NULL
;
414 add_abbrev (unsigned long number
, unsigned long tag
, int children
)
418 entry
= (abbrev_entry
*) malloc (sizeof (*entry
));
423 entry
->entry
= number
;
425 entry
->children
= children
;
426 entry
->first_attr
= NULL
;
427 entry
->last_attr
= NULL
;
430 if (first_abbrev
== NULL
)
431 first_abbrev
= entry
;
433 last_abbrev
->next
= entry
;
439 add_abbrev_attr (unsigned long attribute
, unsigned long form
)
443 attr
= (abbrev_attr
*) malloc (sizeof (*attr
));
448 attr
->attribute
= attribute
;
452 if (last_abbrev
->first_attr
== NULL
)
453 last_abbrev
->first_attr
= attr
;
455 last_abbrev
->last_attr
->next
= attr
;
457 last_abbrev
->last_attr
= attr
;
460 /* Processes the (partial) contents of a .debug_abbrev section.
461 Returns NULL if the end of the section was encountered.
462 Returns the address after the last byte read if the end of
463 an abbreviation set was found. */
465 static unsigned char *
466 process_abbrev_section (unsigned char *start
, unsigned char *end
)
468 if (first_abbrev
!= NULL
)
473 unsigned int bytes_read
;
476 unsigned long attribute
;
479 entry
= read_leb128 (start
, & bytes_read
, 0);
482 /* A single zero is supposed to end the section according
483 to the standard. If there's more, then signal that to
486 return start
== end
? NULL
: start
;
488 tag
= read_leb128 (start
, & bytes_read
, 0);
493 add_abbrev (entry
, tag
, children
);
499 attribute
= read_leb128 (start
, & bytes_read
, 0);
502 form
= read_leb128 (start
, & bytes_read
, 0);
506 add_abbrev_attr (attribute
, form
);
508 while (attribute
!= 0);
515 get_TAG_name (unsigned long tag
)
519 case DW_TAG_padding
: return "DW_TAG_padding";
520 case DW_TAG_array_type
: return "DW_TAG_array_type";
521 case DW_TAG_class_type
: return "DW_TAG_class_type";
522 case DW_TAG_entry_point
: return "DW_TAG_entry_point";
523 case DW_TAG_enumeration_type
: return "DW_TAG_enumeration_type";
524 case DW_TAG_formal_parameter
: return "DW_TAG_formal_parameter";
525 case DW_TAG_imported_declaration
: return "DW_TAG_imported_declaration";
526 case DW_TAG_label
: return "DW_TAG_label";
527 case DW_TAG_lexical_block
: return "DW_TAG_lexical_block";
528 case DW_TAG_member
: return "DW_TAG_member";
529 case DW_TAG_pointer_type
: return "DW_TAG_pointer_type";
530 case DW_TAG_reference_type
: return "DW_TAG_reference_type";
531 case DW_TAG_compile_unit
: return "DW_TAG_compile_unit";
532 case DW_TAG_string_type
: return "DW_TAG_string_type";
533 case DW_TAG_structure_type
: return "DW_TAG_structure_type";
534 case DW_TAG_subroutine_type
: return "DW_TAG_subroutine_type";
535 case DW_TAG_typedef
: return "DW_TAG_typedef";
536 case DW_TAG_union_type
: return "DW_TAG_union_type";
537 case DW_TAG_unspecified_parameters
: return "DW_TAG_unspecified_parameters";
538 case DW_TAG_variant
: return "DW_TAG_variant";
539 case DW_TAG_common_block
: return "DW_TAG_common_block";
540 case DW_TAG_common_inclusion
: return "DW_TAG_common_inclusion";
541 case DW_TAG_inheritance
: return "DW_TAG_inheritance";
542 case DW_TAG_inlined_subroutine
: return "DW_TAG_inlined_subroutine";
543 case DW_TAG_module
: return "DW_TAG_module";
544 case DW_TAG_ptr_to_member_type
: return "DW_TAG_ptr_to_member_type";
545 case DW_TAG_set_type
: return "DW_TAG_set_type";
546 case DW_TAG_subrange_type
: return "DW_TAG_subrange_type";
547 case DW_TAG_with_stmt
: return "DW_TAG_with_stmt";
548 case DW_TAG_access_declaration
: return "DW_TAG_access_declaration";
549 case DW_TAG_base_type
: return "DW_TAG_base_type";
550 case DW_TAG_catch_block
: return "DW_TAG_catch_block";
551 case DW_TAG_const_type
: return "DW_TAG_const_type";
552 case DW_TAG_constant
: return "DW_TAG_constant";
553 case DW_TAG_enumerator
: return "DW_TAG_enumerator";
554 case DW_TAG_file_type
: return "DW_TAG_file_type";
555 case DW_TAG_friend
: return "DW_TAG_friend";
556 case DW_TAG_namelist
: return "DW_TAG_namelist";
557 case DW_TAG_namelist_item
: return "DW_TAG_namelist_item";
558 case DW_TAG_packed_type
: return "DW_TAG_packed_type";
559 case DW_TAG_subprogram
: return "DW_TAG_subprogram";
560 case DW_TAG_template_type_param
: return "DW_TAG_template_type_param";
561 case DW_TAG_template_value_param
: return "DW_TAG_template_value_param";
562 case DW_TAG_thrown_type
: return "DW_TAG_thrown_type";
563 case DW_TAG_try_block
: return "DW_TAG_try_block";
564 case DW_TAG_variant_part
: return "DW_TAG_variant_part";
565 case DW_TAG_variable
: return "DW_TAG_variable";
566 case DW_TAG_volatile_type
: return "DW_TAG_volatile_type";
567 case DW_TAG_MIPS_loop
: return "DW_TAG_MIPS_loop";
568 case DW_TAG_format_label
: return "DW_TAG_format_label";
569 case DW_TAG_function_template
: return "DW_TAG_function_template";
570 case DW_TAG_class_template
: return "DW_TAG_class_template";
571 /* DWARF 2.1 values. */
572 case DW_TAG_dwarf_procedure
: return "DW_TAG_dwarf_procedure";
573 case DW_TAG_restrict_type
: return "DW_TAG_restrict_type";
574 case DW_TAG_interface_type
: return "DW_TAG_interface_type";
575 case DW_TAG_namespace
: return "DW_TAG_namespace";
576 case DW_TAG_imported_module
: return "DW_TAG_imported_module";
577 case DW_TAG_unspecified_type
: return "DW_TAG_unspecified_type";
578 case DW_TAG_partial_unit
: return "DW_TAG_partial_unit";
579 case DW_TAG_imported_unit
: return "DW_TAG_imported_unit";
580 case DW_TAG_condition
: return "DW_TAG_condition";
581 case DW_TAG_shared_type
: return "DW_TAG_shared_type";
582 /* DWARF 4 values. */
583 case DW_TAG_type_unit
: return "DW_TAG_type_unit";
584 case DW_TAG_rvalue_reference_type
: return "DW_TAG_rvalue_reference_type";
585 case DW_TAG_template_alias
: return "DW_TAG_template_alias";
587 case DW_TAG_upc_shared_type
: return "DW_TAG_upc_shared_type";
588 case DW_TAG_upc_strict_type
: return "DW_TAG_upc_strict_type";
589 case DW_TAG_upc_relaxed_type
: return "DW_TAG_upc_relaxed_type";
591 case DW_TAG_GNU_call_site
: return "DW_TAG_GNU_call_site";
592 case DW_TAG_GNU_call_site_parameter
:return "DW_TAG_GNU_call_site_parameter";
595 static char buffer
[100];
597 snprintf (buffer
, sizeof (buffer
), _("Unknown TAG value: %lx"), tag
);
604 get_FORM_name (unsigned long form
)
608 case DW_FORM_addr
: return "DW_FORM_addr";
609 case DW_FORM_block2
: return "DW_FORM_block2";
610 case DW_FORM_block4
: return "DW_FORM_block4";
611 case DW_FORM_data2
: return "DW_FORM_data2";
612 case DW_FORM_data4
: return "DW_FORM_data4";
613 case DW_FORM_data8
: return "DW_FORM_data8";
614 case DW_FORM_string
: return "DW_FORM_string";
615 case DW_FORM_block
: return "DW_FORM_block";
616 case DW_FORM_block1
: return "DW_FORM_block1";
617 case DW_FORM_data1
: return "DW_FORM_data1";
618 case DW_FORM_flag
: return "DW_FORM_flag";
619 case DW_FORM_sdata
: return "DW_FORM_sdata";
620 case DW_FORM_strp
: return "DW_FORM_strp";
621 case DW_FORM_udata
: return "DW_FORM_udata";
622 case DW_FORM_ref_addr
: return "DW_FORM_ref_addr";
623 case DW_FORM_ref1
: return "DW_FORM_ref1";
624 case DW_FORM_ref2
: return "DW_FORM_ref2";
625 case DW_FORM_ref4
: return "DW_FORM_ref4";
626 case DW_FORM_ref8
: return "DW_FORM_ref8";
627 case DW_FORM_ref_udata
: return "DW_FORM_ref_udata";
628 case DW_FORM_indirect
: return "DW_FORM_indirect";
629 /* DWARF 4 values. */
630 case DW_FORM_sec_offset
: return "DW_FORM_sec_offset";
631 case DW_FORM_exprloc
: return "DW_FORM_exprloc";
632 case DW_FORM_flag_present
: return "DW_FORM_flag_present";
633 case DW_FORM_ref_sig8
: return "DW_FORM_ref_sig8";
636 static char buffer
[100];
638 snprintf (buffer
, sizeof (buffer
), _("Unknown FORM value: %lx"), form
);
644 static unsigned char *
645 display_block (unsigned char *data
, dwarf_vma length
)
647 printf (_(" %s byte block: "), dwarf_vmatoa ("u", length
));
650 printf ("%lx ", (unsigned long) byte_get (data
++, 1));
656 decode_location_expression (unsigned char * data
,
657 unsigned int pointer_size
,
658 unsigned int offset_size
,
662 struct dwarf_section
* section
)
665 unsigned int bytes_read
;
667 unsigned char *end
= data
+ length
;
668 int need_frame_base
= 0;
677 printf ("DW_OP_addr: %s",
678 dwarf_vmatoa ("x", byte_get (data
, pointer_size
)));
679 data
+= pointer_size
;
682 printf ("DW_OP_deref");
685 printf ("DW_OP_const1u: %lu", (unsigned long) byte_get (data
++, 1));
688 printf ("DW_OP_const1s: %ld", (long) byte_get_signed (data
++, 1));
691 printf ("DW_OP_const2u: %lu", (unsigned long) byte_get (data
, 2));
695 printf ("DW_OP_const2s: %ld", (long) byte_get_signed (data
, 2));
699 printf ("DW_OP_const4u: %lu", (unsigned long) byte_get (data
, 4));
703 printf ("DW_OP_const4s: %ld", (long) byte_get_signed (data
, 4));
707 printf ("DW_OP_const8u: %lu %lu", (unsigned long) byte_get (data
, 4),
708 (unsigned long) byte_get (data
+ 4, 4));
712 printf ("DW_OP_const8s: %ld %ld", (long) byte_get (data
, 4),
713 (long) byte_get (data
+ 4, 4));
717 printf ("DW_OP_constu: %s",
718 dwarf_vmatoa ("u", read_leb128 (data
, &bytes_read
, 0)));
722 printf ("DW_OP_consts: %s",
723 dwarf_vmatoa ("d", read_sleb128 (data
, &bytes_read
)));
727 printf ("DW_OP_dup");
730 printf ("DW_OP_drop");
733 printf ("DW_OP_over");
736 printf ("DW_OP_pick: %ld", (unsigned long) byte_get (data
++, 1));
739 printf ("DW_OP_swap");
742 printf ("DW_OP_rot");
745 printf ("DW_OP_xderef");
748 printf ("DW_OP_abs");
751 printf ("DW_OP_and");
754 printf ("DW_OP_div");
757 printf ("DW_OP_minus");
760 printf ("DW_OP_mod");
763 printf ("DW_OP_mul");
766 printf ("DW_OP_neg");
769 printf ("DW_OP_not");
775 printf ("DW_OP_plus");
777 case DW_OP_plus_uconst
:
778 printf ("DW_OP_plus_uconst: %s",
779 dwarf_vmatoa ("u", read_leb128 (data
, &bytes_read
, 0)));
783 printf ("DW_OP_shl");
786 printf ("DW_OP_shr");
789 printf ("DW_OP_shra");
792 printf ("DW_OP_xor");
795 printf ("DW_OP_bra: %ld", (long) byte_get_signed (data
, 2));
817 printf ("DW_OP_skip: %ld", (long) byte_get_signed (data
, 2));
853 printf ("DW_OP_lit%d", op
- DW_OP_lit0
);
888 printf ("DW_OP_reg%d (%s)", op
- DW_OP_reg0
,
889 regname (op
- DW_OP_reg0
, 1));
924 printf ("DW_OP_breg%d (%s): %s",
926 regname (op
- DW_OP_breg0
, 1),
927 dwarf_vmatoa ("d", (dwarf_signed_vma
)
928 read_leb128 (data
, &bytes_read
, 1)));
933 uvalue
= read_leb128 (data
, &bytes_read
, 0);
935 printf ("DW_OP_regx: %s (%s)",
936 dwarf_vmatoa ("u", uvalue
), regname (uvalue
, 1));
940 printf ("DW_OP_fbreg: %s",
941 dwarf_vmatoa ("d", read_sleb128 (data
, &bytes_read
)));
945 uvalue
= read_leb128 (data
, &bytes_read
, 0);
947 printf ("DW_OP_bregx: %s (%s) %s",
948 dwarf_vmatoa ("u", uvalue
), regname (uvalue
, 1),
949 dwarf_vmatoa ("d", read_sleb128 (data
, &bytes_read
)));
953 printf ("DW_OP_piece: %s",
954 dwarf_vmatoa ("u", read_leb128 (data
, &bytes_read
, 0)));
957 case DW_OP_deref_size
:
958 printf ("DW_OP_deref_size: %ld", (long) byte_get (data
++, 1));
960 case DW_OP_xderef_size
:
961 printf ("DW_OP_xderef_size: %ld", (long) byte_get (data
++, 1));
964 printf ("DW_OP_nop");
967 /* DWARF 3 extensions. */
968 case DW_OP_push_object_address
:
969 printf ("DW_OP_push_object_address");
972 /* XXX: Strictly speaking for 64-bit DWARF3 files
973 this ought to be an 8-byte wide computation. */
974 printf ("DW_OP_call2: <0x%s>",
975 dwarf_vmatoa ("x", (dwarf_signed_vma
) byte_get (data
, 2)
980 /* XXX: Strictly speaking for 64-bit DWARF3 files
981 this ought to be an 8-byte wide computation. */
982 printf ("DW_OP_call4: <0x%s>",
983 dwarf_vmatoa ("x", (dwarf_signed_vma
) byte_get (data
, 4)
988 /* XXX: Strictly speaking for 64-bit DWARF3 files
989 this ought to be an 8-byte wide computation. */
990 if (dwarf_version
== -1)
992 printf (_("(DW_OP_call_ref in frame info)"));
993 /* No way to tell where the next op is, so just bail. */
994 return need_frame_base
;
996 if (dwarf_version
== 2)
998 printf ("DW_OP_call_ref: <0x%s>",
999 dwarf_vmatoa ("x", byte_get (data
, pointer_size
)));
1000 data
+= pointer_size
;
1004 printf ("DW_OP_call_ref: <0x%s>",
1005 dwarf_vmatoa ("x", byte_get (data
, offset_size
)));
1006 data
+= offset_size
;
1009 case DW_OP_form_tls_address
:
1010 printf ("DW_OP_form_tls_address");
1012 case DW_OP_call_frame_cfa
:
1013 printf ("DW_OP_call_frame_cfa");
1015 case DW_OP_bit_piece
:
1016 printf ("DW_OP_bit_piece: ");
1017 printf ("size: %s ",
1018 dwarf_vmatoa ("u", read_leb128 (data
, &bytes_read
, 0)));
1020 printf ("offset: %s ",
1021 dwarf_vmatoa ("u", read_leb128 (data
, &bytes_read
, 0)));
1025 /* DWARF 4 extensions. */
1026 case DW_OP_stack_value
:
1027 printf ("DW_OP_stack_value");
1030 case DW_OP_implicit_value
:
1031 printf ("DW_OP_implicit_value");
1032 uvalue
= read_leb128 (data
, &bytes_read
, 0);
1034 display_block (data
, uvalue
);
1037 case DW_OP_GNU_entry_value
:
1038 uvalue
= read_leb128 (data
, &bytes_read
, 0);
1040 printf ("DW_OP_GNU_entry_value: (");
1041 if (decode_location_expression (data
, pointer_size
, offset_size
,
1042 dwarf_version
, uvalue
,
1043 cu_offset
, section
))
1044 need_frame_base
= 1;
1049 /* GNU extensions. */
1050 case DW_OP_GNU_push_tls_address
:
1051 printf ("DW_OP_GNU_push_tls_address or DW_OP_HP_unknown");
1053 case DW_OP_GNU_uninit
:
1054 printf ("DW_OP_GNU_uninit");
1055 /* FIXME: Is there data associated with this OP ? */
1057 case DW_OP_GNU_encoded_addr
:
1063 addr
= get_encoded_value (data
, encoding
, section
);
1064 data
+= size_of_encoded_value (encoding
);
1066 printf ("DW_OP_GNU_encoded_addr: fmt:%02x addr:", encoding
);
1067 print_dwarf_vma (addr
, pointer_size
);
1070 case DW_OP_GNU_implicit_pointer
:
1071 /* XXX: Strictly speaking for 64-bit DWARF3 files
1072 this ought to be an 8-byte wide computation. */
1073 if (dwarf_version
== -1)
1075 printf (_("(DW_OP_GNU_implicit_pointer in frame info)"));
1076 /* No way to tell where the next op is, so just bail. */
1077 return need_frame_base
;
1079 if (dwarf_version
== 2)
1081 printf ("DW_OP_GNU_implicit_pointer: <0x%s> %s",
1082 dwarf_vmatoa ("x", byte_get (data
, pointer_size
)),
1083 dwarf_vmatoa ("d", read_sleb128 (data
+ pointer_size
,
1085 data
+= pointer_size
+ bytes_read
;
1089 printf ("DW_OP_GNU_implicit_pointer: <0x%s> %s",
1090 dwarf_vmatoa ("x", byte_get (data
, offset_size
)),
1091 dwarf_vmatoa ("d", read_sleb128 (data
+ offset_size
,
1093 data
+= offset_size
+ bytes_read
;
1097 /* HP extensions. */
1098 case DW_OP_HP_is_value
:
1099 printf ("DW_OP_HP_is_value");
1100 /* FIXME: Is there data associated with this OP ? */
1102 case DW_OP_HP_fltconst4
:
1103 printf ("DW_OP_HP_fltconst4");
1104 /* FIXME: Is there data associated with this OP ? */
1106 case DW_OP_HP_fltconst8
:
1107 printf ("DW_OP_HP_fltconst8");
1108 /* FIXME: Is there data associated with this OP ? */
1110 case DW_OP_HP_mod_range
:
1111 printf ("DW_OP_HP_mod_range");
1112 /* FIXME: Is there data associated with this OP ? */
1114 case DW_OP_HP_unmod_range
:
1115 printf ("DW_OP_HP_unmod_range");
1116 /* FIXME: Is there data associated with this OP ? */
1119 printf ("DW_OP_HP_tls");
1120 /* FIXME: Is there data associated with this OP ? */
1123 /* PGI (STMicroelectronics) extensions. */
1124 case DW_OP_PGI_omp_thread_num
:
1125 /* Pushes the thread number for the current thread as it would be
1126 returned by the standard OpenMP library function:
1127 omp_get_thread_num(). The "current thread" is the thread for
1128 which the expression is being evaluated. */
1129 printf ("DW_OP_PGI_omp_thread_num");
1133 if (op
>= DW_OP_lo_user
1134 && op
<= DW_OP_hi_user
)
1135 printf (_("(User defined location op)"));
1137 printf (_("(Unknown location op)"));
1138 /* No way to tell where the next op is, so just bail. */
1139 return need_frame_base
;
1142 /* Separate the ops. */
1147 return need_frame_base
;
1150 static unsigned char *
1151 read_and_display_attr_value (unsigned long attribute
,
1153 unsigned char * data
,
1154 dwarf_vma cu_offset
,
1155 dwarf_vma pointer_size
,
1156 dwarf_vma offset_size
,
1158 debug_info
* debug_info_p
,
1160 struct dwarf_section
* section
)
1162 dwarf_vma uvalue
= 0;
1163 unsigned char *block_start
= NULL
;
1164 unsigned char * orig_data
= data
;
1165 unsigned int bytes_read
;
1172 case DW_FORM_ref_addr
:
1173 if (dwarf_version
== 2)
1175 uvalue
= byte_get (data
, pointer_size
);
1176 data
+= pointer_size
;
1178 else if (dwarf_version
== 3 || dwarf_version
== 4)
1180 uvalue
= byte_get (data
, offset_size
);
1181 data
+= offset_size
;
1184 error (_("Internal error: DWARF version is not 2, 3 or 4.\n"));
1189 uvalue
= byte_get (data
, pointer_size
);
1190 data
+= pointer_size
;
1194 case DW_FORM_sec_offset
:
1195 uvalue
= byte_get (data
, offset_size
);
1196 data
+= offset_size
;
1199 case DW_FORM_flag_present
:
1206 uvalue
= byte_get (data
++, 1);
1211 uvalue
= byte_get (data
, 2);
1217 uvalue
= byte_get (data
, 4);
1222 uvalue
= read_leb128 (data
, & bytes_read
, 1);
1226 case DW_FORM_ref_udata
:
1228 uvalue
= read_leb128 (data
, & bytes_read
, 0);
1232 case DW_FORM_indirect
:
1233 form
= read_leb128 (data
, & bytes_read
, 0);
1236 printf (" %s", get_FORM_name (form
));
1237 return read_and_display_attr_value (attribute
, form
, data
,
1238 cu_offset
, pointer_size
,
1239 offset_size
, dwarf_version
,
1240 debug_info_p
, do_loc
,
1246 case DW_FORM_ref_addr
:
1248 printf (" <0x%s>", dwarf_vmatoa ("x",uvalue
));
1254 case DW_FORM_ref_udata
:
1256 printf (" <0x%s>", dwarf_vmatoa ("x", uvalue
+ cu_offset
));
1261 case DW_FORM_sec_offset
:
1263 printf (" 0x%s", dwarf_vmatoa ("x", uvalue
));
1266 case DW_FORM_flag_present
:
1273 printf (" %s", dwarf_vmatoa ("d", uvalue
));
1280 uvalue
= byte_get (data
, 4);
1281 printf (" 0x%s", dwarf_vmatoa ("x", uvalue
));
1282 printf (" 0x%lx", (unsigned long) byte_get (data
+ 4, 4));
1284 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
1285 && num_debug_info_entries
== 0)
1287 if (sizeof (uvalue
) == 8)
1288 uvalue
= byte_get (data
, 8);
1290 error (_("DW_FORM_data8 is unsupported when sizeof (dwarf_vma) != 8\n"));
1295 case DW_FORM_string
:
1297 printf (" %s", data
);
1298 data
+= strlen ((char *) data
) + 1;
1302 case DW_FORM_exprloc
:
1303 uvalue
= read_leb128 (data
, & bytes_read
, 0);
1304 block_start
= data
+ bytes_read
;
1306 data
= block_start
+ uvalue
;
1308 data
= display_block (block_start
, uvalue
);
1311 case DW_FORM_block1
:
1312 uvalue
= byte_get (data
, 1);
1313 block_start
= data
+ 1;
1315 data
= block_start
+ uvalue
;
1317 data
= display_block (block_start
, uvalue
);
1320 case DW_FORM_block2
:
1321 uvalue
= byte_get (data
, 2);
1322 block_start
= data
+ 2;
1324 data
= block_start
+ uvalue
;
1326 data
= display_block (block_start
, uvalue
);
1329 case DW_FORM_block4
:
1330 uvalue
= byte_get (data
, 4);
1331 block_start
= data
+ 4;
1333 data
= block_start
+ uvalue
;
1335 data
= display_block (block_start
, uvalue
);
1340 printf (_(" (indirect string, offset: 0x%s): %s"),
1341 dwarf_vmatoa ("x", uvalue
),
1342 fetch_indirect_string (uvalue
));
1345 case DW_FORM_indirect
:
1346 /* Handled above. */
1349 case DW_FORM_ref_sig8
:
1353 printf (" signature: ");
1354 for (i
= 0; i
< 8; i
++)
1356 printf ("%02x", (unsigned) byte_get (data
, 1));
1365 warn (_("Unrecognized form: %lu\n"), form
);
1369 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
1370 && num_debug_info_entries
== 0)
1374 case DW_AT_frame_base
:
1375 have_frame_base
= 1;
1376 case DW_AT_location
:
1377 case DW_AT_string_length
:
1378 case DW_AT_return_addr
:
1379 case DW_AT_data_member_location
:
1380 case DW_AT_vtable_elem_location
:
1382 case DW_AT_static_link
:
1383 case DW_AT_use_location
:
1384 case DW_AT_GNU_call_site_value
:
1385 case DW_AT_GNU_call_site_data_value
:
1386 case DW_AT_GNU_call_site_target
:
1387 case DW_AT_GNU_call_site_target_clobbered
:
1388 if (form
== DW_FORM_data4
1389 || form
== DW_FORM_data8
1390 || form
== DW_FORM_sec_offset
)
1392 /* Process location list. */
1393 unsigned int lmax
= debug_info_p
->max_loc_offsets
;
1394 unsigned int num
= debug_info_p
->num_loc_offsets
;
1396 if (lmax
== 0 || num
>= lmax
)
1399 debug_info_p
->loc_offsets
= (dwarf_vma
*)
1400 xcrealloc (debug_info_p
->loc_offsets
,
1401 lmax
, sizeof (*debug_info_p
->loc_offsets
));
1402 debug_info_p
->have_frame_base
= (int *)
1403 xcrealloc (debug_info_p
->have_frame_base
,
1404 lmax
, sizeof (*debug_info_p
->have_frame_base
));
1405 debug_info_p
->max_loc_offsets
= lmax
;
1407 debug_info_p
->loc_offsets
[num
] = uvalue
;
1408 debug_info_p
->have_frame_base
[num
] = have_frame_base
;
1409 debug_info_p
->num_loc_offsets
++;
1414 if (need_base_address
)
1415 debug_info_p
->base_address
= uvalue
;
1419 if (form
== DW_FORM_data4
1420 || form
== DW_FORM_data8
1421 || form
== DW_FORM_sec_offset
)
1423 /* Process range list. */
1424 unsigned int lmax
= debug_info_p
->max_range_lists
;
1425 unsigned int num
= debug_info_p
->num_range_lists
;
1427 if (lmax
== 0 || num
>= lmax
)
1430 debug_info_p
->range_lists
= (dwarf_vma
*)
1431 xcrealloc (debug_info_p
->range_lists
,
1432 lmax
, sizeof (*debug_info_p
->range_lists
));
1433 debug_info_p
->max_range_lists
= lmax
;
1435 debug_info_p
->range_lists
[num
] = uvalue
;
1436 debug_info_p
->num_range_lists
++;
1448 /* For some attributes we can display further information. */
1456 case DW_INL_not_inlined
:
1457 printf (_("(not inlined)"));
1459 case DW_INL_inlined
:
1460 printf (_("(inlined)"));
1462 case DW_INL_declared_not_inlined
:
1463 printf (_("(declared as inline but ignored)"));
1465 case DW_INL_declared_inlined
:
1466 printf (_("(declared as inline and inlined)"));
1469 printf (_(" (Unknown inline attribute value: %s)"),
1470 dwarf_vmatoa ("x", uvalue
));
1475 case DW_AT_language
:
1478 /* Ordered by the numeric value of these constants. */
1479 case DW_LANG_C89
: printf ("(ANSI C)"); break;
1480 case DW_LANG_C
: printf ("(non-ANSI C)"); break;
1481 case DW_LANG_Ada83
: printf ("(Ada)"); break;
1482 case DW_LANG_C_plus_plus
: printf ("(C++)"); break;
1483 case DW_LANG_Cobol74
: printf ("(Cobol 74)"); break;
1484 case DW_LANG_Cobol85
: printf ("(Cobol 85)"); break;
1485 case DW_LANG_Fortran77
: printf ("(FORTRAN 77)"); break;
1486 case DW_LANG_Fortran90
: printf ("(Fortran 90)"); break;
1487 case DW_LANG_Pascal83
: printf ("(ANSI Pascal)"); break;
1488 case DW_LANG_Modula2
: printf ("(Modula 2)"); break;
1489 /* DWARF 2.1 values. */
1490 case DW_LANG_Java
: printf ("(Java)"); break;
1491 case DW_LANG_C99
: printf ("(ANSI C99)"); break;
1492 case DW_LANG_Ada95
: printf ("(ADA 95)"); break;
1493 case DW_LANG_Fortran95
: printf ("(Fortran 95)"); break;
1494 /* DWARF 3 values. */
1495 case DW_LANG_PLI
: printf ("(PLI)"); break;
1496 case DW_LANG_ObjC
: printf ("(Objective C)"); break;
1497 case DW_LANG_ObjC_plus_plus
: printf ("(Objective C++)"); break;
1498 case DW_LANG_UPC
: printf ("(Unified Parallel C)"); break;
1499 case DW_LANG_D
: printf ("(D)"); break;
1500 /* DWARF 4 values. */
1501 case DW_LANG_Python
: printf ("(Python)"); break;
1502 /* MIPS extension. */
1503 case DW_LANG_Mips_Assembler
: printf ("(MIPS assembler)"); break;
1504 /* UPC extension. */
1505 case DW_LANG_Upc
: printf ("(Unified Parallel C)"); break;
1507 if (uvalue
>= DW_LANG_lo_user
&& uvalue
<= DW_LANG_hi_user
)
1508 printf ("(implementation defined: %s)",
1509 dwarf_vmatoa ("x", uvalue
));
1511 printf ("(Unknown: %s)", dwarf_vmatoa ("x", uvalue
));
1516 case DW_AT_encoding
:
1519 case DW_ATE_void
: printf ("(void)"); break;
1520 case DW_ATE_address
: printf ("(machine address)"); break;
1521 case DW_ATE_boolean
: printf ("(boolean)"); break;
1522 case DW_ATE_complex_float
: printf ("(complex float)"); break;
1523 case DW_ATE_float
: printf ("(float)"); break;
1524 case DW_ATE_signed
: printf ("(signed)"); break;
1525 case DW_ATE_signed_char
: printf ("(signed char)"); break;
1526 case DW_ATE_unsigned
: printf ("(unsigned)"); break;
1527 case DW_ATE_unsigned_char
: printf ("(unsigned char)"); break;
1528 /* DWARF 2.1 values: */
1529 case DW_ATE_imaginary_float
: printf ("(imaginary float)"); break;
1530 case DW_ATE_decimal_float
: printf ("(decimal float)"); break;
1531 /* DWARF 3 values: */
1532 case DW_ATE_packed_decimal
: printf ("(packed_decimal)"); break;
1533 case DW_ATE_numeric_string
: printf ("(numeric_string)"); break;
1534 case DW_ATE_edited
: printf ("(edited)"); break;
1535 case DW_ATE_signed_fixed
: printf ("(signed_fixed)"); break;
1536 case DW_ATE_unsigned_fixed
: printf ("(unsigned_fixed)"); break;
1537 /* HP extensions: */
1538 case DW_ATE_HP_float80
: printf ("(HP_float80)"); break;
1539 case DW_ATE_HP_complex_float80
: printf ("(HP_complex_float80)"); break;
1540 case DW_ATE_HP_float128
: printf ("(HP_float128)"); break;
1541 case DW_ATE_HP_complex_float128
:printf ("(HP_complex_float128)"); break;
1542 case DW_ATE_HP_floathpintel
: printf ("(HP_floathpintel)"); break;
1543 case DW_ATE_HP_imaginary_float80
: printf ("(HP_imaginary_float80)"); break;
1544 case DW_ATE_HP_imaginary_float128
: printf ("(HP_imaginary_float128)"); break;
1547 if (uvalue
>= DW_ATE_lo_user
1548 && uvalue
<= DW_ATE_hi_user
)
1549 printf ("(user defined type)");
1551 printf ("(unknown type)");
1556 case DW_AT_accessibility
:
1559 case DW_ACCESS_public
: printf ("(public)"); break;
1560 case DW_ACCESS_protected
: printf ("(protected)"); break;
1561 case DW_ACCESS_private
: printf ("(private)"); break;
1563 printf ("(unknown accessibility)");
1568 case DW_AT_visibility
:
1571 case DW_VIS_local
: printf ("(local)"); break;
1572 case DW_VIS_exported
: printf ("(exported)"); break;
1573 case DW_VIS_qualified
: printf ("(qualified)"); break;
1574 default: printf ("(unknown visibility)"); break;
1578 case DW_AT_virtuality
:
1581 case DW_VIRTUALITY_none
: printf ("(none)"); break;
1582 case DW_VIRTUALITY_virtual
: printf ("(virtual)"); break;
1583 case DW_VIRTUALITY_pure_virtual
:printf ("(pure_virtual)"); break;
1584 default: printf ("(unknown virtuality)"); break;
1588 case DW_AT_identifier_case
:
1591 case DW_ID_case_sensitive
: printf ("(case_sensitive)"); break;
1592 case DW_ID_up_case
: printf ("(up_case)"); break;
1593 case DW_ID_down_case
: printf ("(down_case)"); break;
1594 case DW_ID_case_insensitive
: printf ("(case_insensitive)"); break;
1595 default: printf ("(unknown case)"); break;
1599 case DW_AT_calling_convention
:
1602 case DW_CC_normal
: printf ("(normal)"); break;
1603 case DW_CC_program
: printf ("(program)"); break;
1604 case DW_CC_nocall
: printf ("(nocall)"); break;
1606 if (uvalue
>= DW_CC_lo_user
1607 && uvalue
<= DW_CC_hi_user
)
1608 printf ("(user defined)");
1610 printf ("(unknown convention)");
1614 case DW_AT_ordering
:
1617 case -1: printf ("(undefined)"); break;
1618 case 0: printf ("(row major)"); break;
1619 case 1: printf ("(column major)"); break;
1623 case DW_AT_frame_base
:
1624 have_frame_base
= 1;
1625 case DW_AT_location
:
1626 case DW_AT_string_length
:
1627 case DW_AT_return_addr
:
1628 case DW_AT_data_member_location
:
1629 case DW_AT_vtable_elem_location
:
1631 case DW_AT_static_link
:
1632 case DW_AT_use_location
:
1633 case DW_AT_GNU_call_site_value
:
1634 case DW_AT_GNU_call_site_data_value
:
1635 case DW_AT_GNU_call_site_target
:
1636 case DW_AT_GNU_call_site_target_clobbered
:
1637 if (form
== DW_FORM_data4
1638 || form
== DW_FORM_data8
1639 || form
== DW_FORM_sec_offset
)
1640 printf (_("(location list)"));
1642 case DW_AT_allocated
:
1643 case DW_AT_associated
:
1644 case DW_AT_data_location
:
1646 case DW_AT_upper_bound
:
1647 case DW_AT_lower_bound
:
1650 int need_frame_base
;
1653 need_frame_base
= decode_location_expression (block_start
,
1658 cu_offset
, section
);
1660 if (need_frame_base
&& !have_frame_base
)
1661 printf (_(" [without DW_AT_frame_base]"));
1667 if (form
== DW_FORM_ref_sig8
)
1670 if (form
== DW_FORM_ref1
1671 || form
== DW_FORM_ref2
1672 || form
== DW_FORM_ref4
)
1673 uvalue
+= cu_offset
;
1675 if (uvalue
>= section
->size
)
1676 warn (_("Offset %s used as value for DW_AT_import attribute of DIE at offset %lx is too big.\n"),
1677 dwarf_vmatoa ("x", uvalue
),
1678 (unsigned long) (orig_data
- section
->start
));
1681 unsigned long abbrev_number
;
1682 abbrev_entry
* entry
;
1684 abbrev_number
= read_leb128 (section
->start
+ uvalue
, NULL
, 0);
1686 printf ("[Abbrev Number: %ld", abbrev_number
);
1687 for (entry
= first_abbrev
; entry
!= NULL
; entry
= entry
->next
)
1688 if (entry
->entry
== abbrev_number
)
1691 printf (" (%s)", get_TAG_name (entry
->tag
));
1705 get_AT_name (unsigned long attribute
)
1709 case DW_AT_sibling
: return "DW_AT_sibling";
1710 case DW_AT_location
: return "DW_AT_location";
1711 case DW_AT_name
: return "DW_AT_name";
1712 case DW_AT_ordering
: return "DW_AT_ordering";
1713 case DW_AT_subscr_data
: return "DW_AT_subscr_data";
1714 case DW_AT_byte_size
: return "DW_AT_byte_size";
1715 case DW_AT_bit_offset
: return "DW_AT_bit_offset";
1716 case DW_AT_bit_size
: return "DW_AT_bit_size";
1717 case DW_AT_element_list
: return "DW_AT_element_list";
1718 case DW_AT_stmt_list
: return "DW_AT_stmt_list";
1719 case DW_AT_low_pc
: return "DW_AT_low_pc";
1720 case DW_AT_high_pc
: return "DW_AT_high_pc";
1721 case DW_AT_language
: return "DW_AT_language";
1722 case DW_AT_member
: return "DW_AT_member";
1723 case DW_AT_discr
: return "DW_AT_discr";
1724 case DW_AT_discr_value
: return "DW_AT_discr_value";
1725 case DW_AT_visibility
: return "DW_AT_visibility";
1726 case DW_AT_import
: return "DW_AT_import";
1727 case DW_AT_string_length
: return "DW_AT_string_length";
1728 case DW_AT_common_reference
: return "DW_AT_common_reference";
1729 case DW_AT_comp_dir
: return "DW_AT_comp_dir";
1730 case DW_AT_const_value
: return "DW_AT_const_value";
1731 case DW_AT_containing_type
: return "DW_AT_containing_type";
1732 case DW_AT_default_value
: return "DW_AT_default_value";
1733 case DW_AT_inline
: return "DW_AT_inline";
1734 case DW_AT_is_optional
: return "DW_AT_is_optional";
1735 case DW_AT_lower_bound
: return "DW_AT_lower_bound";
1736 case DW_AT_producer
: return "DW_AT_producer";
1737 case DW_AT_prototyped
: return "DW_AT_prototyped";
1738 case DW_AT_return_addr
: return "DW_AT_return_addr";
1739 case DW_AT_start_scope
: return "DW_AT_start_scope";
1740 case DW_AT_stride_size
: return "DW_AT_stride_size";
1741 case DW_AT_upper_bound
: return "DW_AT_upper_bound";
1742 case DW_AT_abstract_origin
: return "DW_AT_abstract_origin";
1743 case DW_AT_accessibility
: return "DW_AT_accessibility";
1744 case DW_AT_address_class
: return "DW_AT_address_class";
1745 case DW_AT_artificial
: return "DW_AT_artificial";
1746 case DW_AT_base_types
: return "DW_AT_base_types";
1747 case DW_AT_calling_convention
: return "DW_AT_calling_convention";
1748 case DW_AT_count
: return "DW_AT_count";
1749 case DW_AT_data_member_location
: return "DW_AT_data_member_location";
1750 case DW_AT_decl_column
: return "DW_AT_decl_column";
1751 case DW_AT_decl_file
: return "DW_AT_decl_file";
1752 case DW_AT_decl_line
: return "DW_AT_decl_line";
1753 case DW_AT_declaration
: return "DW_AT_declaration";
1754 case DW_AT_discr_list
: return "DW_AT_discr_list";
1755 case DW_AT_encoding
: return "DW_AT_encoding";
1756 case DW_AT_external
: return "DW_AT_external";
1757 case DW_AT_frame_base
: return "DW_AT_frame_base";
1758 case DW_AT_friend
: return "DW_AT_friend";
1759 case DW_AT_identifier_case
: return "DW_AT_identifier_case";
1760 case DW_AT_macro_info
: return "DW_AT_macro_info";
1761 case DW_AT_namelist_items
: return "DW_AT_namelist_items";
1762 case DW_AT_priority
: return "DW_AT_priority";
1763 case DW_AT_segment
: return "DW_AT_segment";
1764 case DW_AT_specification
: return "DW_AT_specification";
1765 case DW_AT_static_link
: return "DW_AT_static_link";
1766 case DW_AT_type
: return "DW_AT_type";
1767 case DW_AT_use_location
: return "DW_AT_use_location";
1768 case DW_AT_variable_parameter
: return "DW_AT_variable_parameter";
1769 case DW_AT_virtuality
: return "DW_AT_virtuality";
1770 case DW_AT_vtable_elem_location
: return "DW_AT_vtable_elem_location";
1771 /* DWARF 2.1 values. */
1772 case DW_AT_allocated
: return "DW_AT_allocated";
1773 case DW_AT_associated
: return "DW_AT_associated";
1774 case DW_AT_data_location
: return "DW_AT_data_location";
1775 case DW_AT_stride
: return "DW_AT_stride";
1776 case DW_AT_entry_pc
: return "DW_AT_entry_pc";
1777 case DW_AT_use_UTF8
: return "DW_AT_use_UTF8";
1778 case DW_AT_extension
: return "DW_AT_extension";
1779 case DW_AT_ranges
: return "DW_AT_ranges";
1780 case DW_AT_trampoline
: return "DW_AT_trampoline";
1781 case DW_AT_call_column
: return "DW_AT_call_column";
1782 case DW_AT_call_file
: return "DW_AT_call_file";
1783 case DW_AT_call_line
: return "DW_AT_call_line";
1784 case DW_AT_description
: return "DW_AT_description";
1785 case DW_AT_binary_scale
: return "DW_AT_binary_scale";
1786 case DW_AT_decimal_scale
: return "DW_AT_decimal_scale";
1787 case DW_AT_small
: return "DW_AT_small";
1788 case DW_AT_decimal_sign
: return "DW_AT_decimal_sign";
1789 case DW_AT_digit_count
: return "DW_AT_digit_count";
1790 case DW_AT_picture_string
: return "DW_AT_picture_string";
1791 case DW_AT_mutable
: return "DW_AT_mutable";
1792 case DW_AT_threads_scaled
: return "DW_AT_threads_scaled";
1793 case DW_AT_explicit
: return "DW_AT_explicit";
1794 case DW_AT_object_pointer
: return "DW_AT_object_pointer";
1795 case DW_AT_endianity
: return "DW_AT_endianity";
1796 case DW_AT_elemental
: return "DW_AT_elemental";
1797 case DW_AT_pure
: return "DW_AT_pure";
1798 case DW_AT_recursive
: return "DW_AT_recursive";
1799 /* DWARF 4 values. */
1800 case DW_AT_signature
: return "DW_AT_signature";
1801 case DW_AT_main_subprogram
: return "DW_AT_main_subprogram";
1802 case DW_AT_data_bit_offset
: return "DW_AT_data_bit_offset";
1803 case DW_AT_const_expr
: return "DW_AT_const_expr";
1804 case DW_AT_enum_class
: return "DW_AT_enum_class";
1805 case DW_AT_linkage_name
: return "DW_AT_linkage_name";
1807 /* HP and SGI/MIPS extensions. */
1808 case DW_AT_MIPS_loop_begin
: return "DW_AT_MIPS_loop_begin";
1809 case DW_AT_MIPS_tail_loop_begin
: return "DW_AT_MIPS_tail_loop_begin";
1810 case DW_AT_MIPS_epilog_begin
: return "DW_AT_MIPS_epilog_begin";
1811 case DW_AT_MIPS_loop_unroll_factor
: return "DW_AT_MIPS_loop_unroll_factor";
1812 case DW_AT_MIPS_software_pipeline_depth
: return "DW_AT_MIPS_software_pipeline_depth";
1813 case DW_AT_MIPS_linkage_name
: return "DW_AT_MIPS_linkage_name";
1814 case DW_AT_MIPS_stride
: return "DW_AT_MIPS_stride";
1815 case DW_AT_MIPS_abstract_name
: return "DW_AT_MIPS_abstract_name";
1816 case DW_AT_MIPS_clone_origin
: return "DW_AT_MIPS_clone_origin";
1817 case DW_AT_MIPS_has_inlines
: return "DW_AT_MIPS_has_inlines";
1819 /* HP Extensions. */
1820 case DW_AT_HP_block_index
: return "DW_AT_HP_block_index";
1821 case DW_AT_HP_actuals_stmt_list
: return "DW_AT_HP_actuals_stmt_list";
1822 case DW_AT_HP_proc_per_section
: return "DW_AT_HP_proc_per_section";
1823 case DW_AT_HP_raw_data_ptr
: return "DW_AT_HP_raw_data_ptr";
1824 case DW_AT_HP_pass_by_reference
: return "DW_AT_HP_pass_by_reference";
1825 case DW_AT_HP_opt_level
: return "DW_AT_HP_opt_level";
1826 case DW_AT_HP_prof_version_id
: return "DW_AT_HP_prof_version_id";
1827 case DW_AT_HP_opt_flags
: return "DW_AT_HP_opt_flags";
1828 case DW_AT_HP_cold_region_low_pc
: return "DW_AT_HP_cold_region_low_pc";
1829 case DW_AT_HP_cold_region_high_pc
: return "DW_AT_HP_cold_region_high_pc";
1830 case DW_AT_HP_all_variables_modifiable
: return "DW_AT_HP_all_variables_modifiable";
1831 case DW_AT_HP_linkage_name
: return "DW_AT_HP_linkage_name";
1832 case DW_AT_HP_prof_flags
: return "DW_AT_HP_prof_flags";
1834 /* One value is shared by the MIPS and HP extensions: */
1835 case DW_AT_MIPS_fde
: return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable";
1837 /* GNU extensions. */
1838 case DW_AT_sf_names
: return "DW_AT_sf_names";
1839 case DW_AT_src_info
: return "DW_AT_src_info";
1840 case DW_AT_mac_info
: return "DW_AT_mac_info";
1841 case DW_AT_src_coords
: return "DW_AT_src_coords";
1842 case DW_AT_body_begin
: return "DW_AT_body_begin";
1843 case DW_AT_body_end
: return "DW_AT_body_end";
1844 case DW_AT_GNU_vector
: return "DW_AT_GNU_vector";
1845 case DW_AT_GNU_guarded_by
: return "DW_AT_GNU_guarded_by";
1846 case DW_AT_GNU_pt_guarded_by
: return "DW_AT_GNU_pt_guarded_by";
1847 case DW_AT_GNU_guarded
: return "DW_AT_GNU_guarded";
1848 case DW_AT_GNU_pt_guarded
: return "DW_AT_GNU_pt_guarded";
1849 case DW_AT_GNU_locks_excluded
: return "DW_AT_GNU_locks_excluded";
1850 case DW_AT_GNU_exclusive_locks_required
: return "DW_AT_GNU_exclusive_locks_required";
1851 case DW_AT_GNU_shared_locks_required
: return "DW_AT_GNU_shared_locks_required";
1852 case DW_AT_GNU_odr_signature
: return "DW_AT_GNU_odr_signature";
1853 case DW_AT_use_GNAT_descriptive_type
: return "DW_AT_use_GNAT_descriptive_type";
1854 case DW_AT_GNAT_descriptive_type
: return "DW_AT_GNAT_descriptive_type";
1855 case DW_AT_GNU_call_site_value
: return "DW_AT_GNU_call_site_value";
1856 case DW_AT_GNU_call_site_data_value
: return "DW_AT_GNU_call_site_data_value";
1857 case DW_AT_GNU_call_site_target
: return "DW_AT_GNU_call_site_target";
1858 case DW_AT_GNU_call_site_target_clobbered
: return "DW_AT_GNU_call_site_target_clobbered";
1859 case DW_AT_GNU_tail_call
: return "DW_AT_GNU_tail_call";
1860 case DW_AT_GNU_all_tail_call_sites
: return "DW_AT_GNU_all_tail_call_sites";
1861 case DW_AT_GNU_all_call_sites
: return "DW_AT_GNU_all_call_sites";
1862 case DW_AT_GNU_all_source_call_sites
: return "DW_AT_GNU_all_source_call_sites";
1864 /* UPC extension. */
1865 case DW_AT_upc_threads_scaled
: return "DW_AT_upc_threads_scaled";
1867 /* PGI (STMicroelectronics) extensions. */
1868 case DW_AT_PGI_lbase
: return "DW_AT_PGI_lbase";
1869 case DW_AT_PGI_soffset
: return "DW_AT_PGI_soffset";
1870 case DW_AT_PGI_lstride
: return "DW_AT_PGI_lstride";
1874 static char buffer
[100];
1876 snprintf (buffer
, sizeof (buffer
), _("Unknown AT value: %lx"),
1883 static unsigned char *
1884 read_and_display_attr (unsigned long attribute
,
1886 unsigned char * data
,
1887 dwarf_vma cu_offset
,
1888 dwarf_vma pointer_size
,
1889 dwarf_vma offset_size
,
1891 debug_info
* debug_info_p
,
1893 struct dwarf_section
* section
)
1896 printf (" %-18s:", get_AT_name (attribute
));
1897 data
= read_and_display_attr_value (attribute
, form
, data
, cu_offset
,
1898 pointer_size
, offset_size
,
1899 dwarf_version
, debug_info_p
,
1907 /* Process the contents of a .debug_info section. If do_loc is non-zero
1908 then we are scanning for location lists and we do not want to display
1909 anything to the user. If do_types is non-zero, we are processing
1910 a .debug_types section instead of a .debug_info section. */
1913 process_debug_info (struct dwarf_section
*section
,
1915 enum dwarf_section_display_enum abbrev_sec
,
1919 unsigned char *start
= section
->start
;
1920 unsigned char *end
= start
+ section
->size
;
1921 unsigned char *section_begin
;
1923 unsigned int num_units
= 0;
1925 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
1926 && num_debug_info_entries
== 0
1931 /* First scan the section to get the number of comp units. */
1932 for (section_begin
= start
, num_units
= 0; section_begin
< end
;
1935 /* Read the first 4 bytes. For a 32-bit DWARF section, this
1936 will be the length. For a 64-bit DWARF section, it'll be
1937 the escape code 0xffffffff followed by an 8 byte length. */
1938 length
= byte_get (section_begin
, 4);
1940 if (length
== 0xffffffff)
1942 length
= byte_get (section_begin
+ 4, 8);
1943 section_begin
+= length
+ 12;
1945 else if (length
>= 0xfffffff0 && length
< 0xffffffff)
1947 warn (_("Reserved length value (0x%s) found in section %s\n"),
1948 dwarf_vmatoa ("x", length
), section
->name
);
1952 section_begin
+= length
+ 4;
1954 /* Negative values are illegal, they may even cause infinite
1955 looping. This can happen if we can't accurately apply
1956 relocations to an object file. */
1957 if ((signed long) length
<= 0)
1959 warn (_("Corrupt unit length (0x%s) found in section %s\n"),
1960 dwarf_vmatoa ("x", length
), section
->name
);
1967 error (_("No comp units in %s section ?"), section
->name
);
1971 /* Then allocate an array to hold the information. */
1972 debug_information
= (debug_info
*) cmalloc (num_units
,
1973 sizeof (* debug_information
));
1974 if (debug_information
== NULL
)
1976 error (_("Not enough memory for a debug info array of %u entries"),
1984 printf (_("Contents of the %s section:\n\n"), section
->name
);
1986 load_debug_section (str
, file
);
1989 load_debug_section (abbrev_sec
, file
);
1990 if (debug_displays
[abbrev_sec
].section
.start
== NULL
)
1992 warn (_("Unable to locate %s section!\n"),
1993 debug_displays
[abbrev_sec
].section
.name
);
1997 for (section_begin
= start
, unit
= 0; start
< end
; unit
++)
1999 DWARF2_Internal_CompUnit compunit
;
2000 unsigned char *hdrptr
;
2001 unsigned char *tags
;
2003 dwarf_vma cu_offset
;
2005 int initial_length_size
;
2006 unsigned char signature
[8] = { 0 };
2007 dwarf_vma type_offset
= 0;
2011 compunit
.cu_length
= byte_get (hdrptr
, 4);
2014 if (compunit
.cu_length
== 0xffffffff)
2016 compunit
.cu_length
= byte_get (hdrptr
, 8);
2019 initial_length_size
= 12;
2024 initial_length_size
= 4;
2027 compunit
.cu_version
= byte_get (hdrptr
, 2);
2030 cu_offset
= start
- section_begin
;
2032 compunit
.cu_abbrev_offset
= byte_get (hdrptr
, offset_size
);
2033 hdrptr
+= offset_size
;
2035 compunit
.cu_pointer_size
= byte_get (hdrptr
, 1);
2042 for (i
= 0; i
< 8; i
++)
2044 signature
[i
] = byte_get (hdrptr
, 1);
2048 type_offset
= byte_get (hdrptr
, offset_size
);
2049 hdrptr
+= offset_size
;
2052 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
2053 && num_debug_info_entries
== 0
2056 debug_information
[unit
].cu_offset
= cu_offset
;
2057 debug_information
[unit
].pointer_size
2058 = compunit
.cu_pointer_size
;
2059 debug_information
[unit
].offset_size
= offset_size
;
2060 debug_information
[unit
].dwarf_version
= compunit
.cu_version
;
2061 debug_information
[unit
].base_address
= 0;
2062 debug_information
[unit
].loc_offsets
= NULL
;
2063 debug_information
[unit
].have_frame_base
= NULL
;
2064 debug_information
[unit
].max_loc_offsets
= 0;
2065 debug_information
[unit
].num_loc_offsets
= 0;
2066 debug_information
[unit
].range_lists
= NULL
;
2067 debug_information
[unit
].max_range_lists
= 0;
2068 debug_information
[unit
].num_range_lists
= 0;
2073 printf (_(" Compilation Unit @ offset 0x%s:\n"),
2074 dwarf_vmatoa ("x", cu_offset
));
2075 printf (_(" Length: 0x%s (%s)\n"),
2076 dwarf_vmatoa ("x", compunit
.cu_length
),
2077 offset_size
== 8 ? "64-bit" : "32-bit");
2078 printf (_(" Version: %d\n"), compunit
.cu_version
);
2079 printf (_(" Abbrev Offset: %s\n"),
2080 dwarf_vmatoa ("d", compunit
.cu_abbrev_offset
));
2081 printf (_(" Pointer Size: %d\n"), compunit
.cu_pointer_size
);
2085 printf (_(" Signature: "));
2086 for (i
= 0; i
< 8; i
++)
2087 printf ("%02x", signature
[i
]);
2089 printf (_(" Type Offset: 0x%s\n"),
2090 dwarf_vmatoa ("x", type_offset
));
2094 if (cu_offset
+ compunit
.cu_length
+ initial_length_size
2097 warn (_("Debug info is corrupted, length of CU at %s"
2098 " extends beyond end of section (length = %s)\n"),
2099 dwarf_vmatoa ("x", cu_offset
),
2100 dwarf_vmatoa ("x", compunit
.cu_length
));
2104 start
+= compunit
.cu_length
+ initial_length_size
;
2106 if (compunit
.cu_version
!= 2
2107 && compunit
.cu_version
!= 3
2108 && compunit
.cu_version
!= 4)
2110 warn (_("CU at offset %s contains corrupt or "
2111 "unsupported version number: %d.\n"),
2112 dwarf_vmatoa ("x", cu_offset
), compunit
.cu_version
);
2118 /* Process the abbrevs used by this compilation unit. DWARF
2119 sections under Mach-O have non-zero addresses. */
2120 if (compunit
.cu_abbrev_offset
>= debug_displays
[abbrev_sec
].section
.size
)
2121 warn (_("Debug info is corrupted, abbrev offset (%lx) is larger than abbrev section size (%lx)\n"),
2122 (unsigned long) compunit
.cu_abbrev_offset
,
2123 (unsigned long) debug_displays
[abbrev_sec
].section
.size
);
2125 process_abbrev_section
2126 ((unsigned char *) debug_displays
[abbrev_sec
].section
.start
2127 + compunit
.cu_abbrev_offset
,
2128 (unsigned char *) debug_displays
[abbrev_sec
].section
.start
2129 + debug_displays
[abbrev_sec
].section
.size
);
2132 while (tags
< start
)
2134 unsigned int bytes_read
;
2135 unsigned long abbrev_number
;
2136 unsigned long die_offset
;
2137 abbrev_entry
*entry
;
2140 die_offset
= tags
- section_begin
;
2142 abbrev_number
= read_leb128 (tags
, & bytes_read
, 0);
2145 /* A null DIE marks the end of a list of siblings or it may also be
2146 a section padding. */
2147 if (abbrev_number
== 0)
2149 /* Check if it can be a section padding for the last CU. */
2150 if (level
== 0 && start
== end
)
2154 for (chk
= tags
; chk
< start
; chk
++)
2164 static unsigned num_bogus_warns
= 0;
2166 if (num_bogus_warns
< 3)
2168 warn (_("Bogus end-of-siblings marker detected at offset %lx in .debug_info section\n"),
2171 if (num_bogus_warns
== 3)
2172 warn (_("Further warnings about bogus end-of-sibling markers suppressed\n"));
2179 printf (_(" <%d><%lx>: Abbrev Number: %lu"),
2180 level
, die_offset
, abbrev_number
);
2182 /* Scan through the abbreviation list until we reach the
2184 for (entry
= first_abbrev
;
2185 entry
&& entry
->entry
!= abbrev_number
;
2186 entry
= entry
->next
)
2196 warn (_("DIE at offset %lx refers to abbreviation number %lu which does not exist\n"),
2197 die_offset
, abbrev_number
);
2202 printf (" (%s)\n", get_TAG_name (entry
->tag
));
2207 need_base_address
= 0;
2209 case DW_TAG_compile_unit
:
2210 need_base_address
= 1;
2212 case DW_TAG_entry_point
:
2213 case DW_TAG_subprogram
:
2214 need_base_address
= 0;
2215 /* Assuming that there is no DW_AT_frame_base. */
2216 have_frame_base
= 0;
2220 for (attr
= entry
->first_attr
; attr
; attr
= attr
->next
)
2223 /* Show the offset from where the tag was extracted. */
2224 printf (" <%2lx>", (unsigned long)(tags
- section_begin
));
2226 tags
= read_and_display_attr (attr
->attribute
,
2229 compunit
.cu_pointer_size
,
2231 compunit
.cu_version
,
2232 debug_information
+ unit
,
2236 if (entry
->children
)
2241 /* Set num_debug_info_entries here so that it can be used to check if
2242 we need to process .debug_loc and .debug_ranges sections. */
2243 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
2244 && num_debug_info_entries
== 0
2246 num_debug_info_entries
= num_units
;
2254 /* Locate and scan the .debug_info section in the file and record the pointer
2255 sizes and offsets for the compilation units in it. Usually an executable
2256 will have just one pointer size, but this is not guaranteed, and so we try
2257 not to make any assumptions. Returns zero upon failure, or the number of
2258 compilation units upon success. */
2261 load_debug_info (void * file
)
2263 /* Reset the last pointer size so that we can issue correct error
2264 messages if we are displaying the contents of more than one section. */
2265 last_pointer_size
= 0;
2266 warned_about_missing_comp_units
= FALSE
;
2268 /* If we have already tried and failed to load the .debug_info
2269 section then do not bother to repear the task. */
2270 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
2273 /* If we already have the information there is nothing else to do. */
2274 if (num_debug_info_entries
> 0)
2275 return num_debug_info_entries
;
2277 if (load_debug_section (info
, file
)
2278 && process_debug_info (&debug_displays
[info
].section
, file
, abbrev
, 1, 0))
2279 return num_debug_info_entries
;
2281 num_debug_info_entries
= DEBUG_INFO_UNAVAILABLE
;
2286 display_debug_lines_raw (struct dwarf_section
*section
,
2287 unsigned char *data
,
2290 unsigned char *start
= section
->start
;
2292 printf (_("Raw dump of debug contents of section %s:\n\n"),
2297 DWARF2_Internal_LineInfo linfo
;
2298 unsigned char *standard_opcodes
;
2299 unsigned char *end_of_sequence
;
2300 unsigned char *hdrptr
;
2301 unsigned long hdroff
;
2302 int initial_length_size
;
2307 hdroff
= hdrptr
- start
;
2309 /* Check the length of the block. */
2310 linfo
.li_length
= byte_get (hdrptr
, 4);
2313 if (linfo
.li_length
== 0xffffffff)
2315 /* This section is 64-bit DWARF 3. */
2316 linfo
.li_length
= byte_get (hdrptr
, 8);
2319 initial_length_size
= 12;
2324 initial_length_size
= 4;
2327 if (linfo
.li_length
+ initial_length_size
> section
->size
)
2330 (_("The information in section %s appears to be corrupt - the section is too small\n"),
2335 /* Check its version number. */
2336 linfo
.li_version
= byte_get (hdrptr
, 2);
2338 if (linfo
.li_version
!= 2
2339 && linfo
.li_version
!= 3
2340 && linfo
.li_version
!= 4)
2342 warn (_("Only DWARF version 2, 3 and 4 line info is currently supported.\n"));
2346 linfo
.li_prologue_length
= byte_get (hdrptr
, offset_size
);
2347 hdrptr
+= offset_size
;
2348 linfo
.li_min_insn_length
= byte_get (hdrptr
, 1);
2350 if (linfo
.li_version
>= 4)
2352 linfo
.li_max_ops_per_insn
= byte_get (hdrptr
, 1);
2354 if (linfo
.li_max_ops_per_insn
== 0)
2356 warn (_("Invalid maximum operations per insn.\n"));
2361 linfo
.li_max_ops_per_insn
= 1;
2362 linfo
.li_default_is_stmt
= byte_get (hdrptr
, 1);
2364 linfo
.li_line_base
= byte_get (hdrptr
, 1);
2366 linfo
.li_line_range
= byte_get (hdrptr
, 1);
2368 linfo
.li_opcode_base
= byte_get (hdrptr
, 1);
2371 /* Sign extend the line base field. */
2372 linfo
.li_line_base
<<= 24;
2373 linfo
.li_line_base
>>= 24;
2375 printf (_(" Offset: 0x%lx\n"), hdroff
);
2376 printf (_(" Length: %ld\n"), (long) linfo
.li_length
);
2377 printf (_(" DWARF Version: %d\n"), linfo
.li_version
);
2378 printf (_(" Prologue Length: %d\n"), linfo
.li_prologue_length
);
2379 printf (_(" Minimum Instruction Length: %d\n"), linfo
.li_min_insn_length
);
2380 if (linfo
.li_version
>= 4)
2381 printf (_(" Maximum Ops per Instruction: %d\n"), linfo
.li_max_ops_per_insn
);
2382 printf (_(" Initial value of 'is_stmt': %d\n"), linfo
.li_default_is_stmt
);
2383 printf (_(" Line Base: %d\n"), linfo
.li_line_base
);
2384 printf (_(" Line Range: %d\n"), linfo
.li_line_range
);
2385 printf (_(" Opcode Base: %d\n"), linfo
.li_opcode_base
);
2387 end_of_sequence
= data
+ linfo
.li_length
+ initial_length_size
;
2389 reset_state_machine (linfo
.li_default_is_stmt
);
2391 /* Display the contents of the Opcodes table. */
2392 standard_opcodes
= hdrptr
;
2394 printf (_("\n Opcodes:\n"));
2396 for (i
= 1; i
< linfo
.li_opcode_base
; i
++)
2397 printf (_(" Opcode %d has %d args\n"), i
, standard_opcodes
[i
- 1]);
2399 /* Display the contents of the Directory table. */
2400 data
= standard_opcodes
+ linfo
.li_opcode_base
- 1;
2403 printf (_("\n The Directory Table is empty.\n"));
2406 printf (_("\n The Directory Table:\n"));
2410 printf (" %s\n", data
);
2412 data
+= strlen ((char *) data
) + 1;
2416 /* Skip the NUL at the end of the table. */
2419 /* Display the contents of the File Name table. */
2421 printf (_("\n The File Name Table is empty.\n"));
2424 printf (_("\n The File Name Table:\n"));
2425 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
2429 unsigned char *name
;
2430 unsigned int bytes_read
;
2432 printf (" %d\t", ++state_machine_regs
.last_file_entry
);
2435 data
+= strlen ((char *) data
) + 1;
2438 dwarf_vmatoa ("u", read_leb128 (data
, & bytes_read
, 0)));
2441 dwarf_vmatoa ("u", read_leb128 (data
, & bytes_read
, 0)));
2444 dwarf_vmatoa ("u", read_leb128 (data
, & bytes_read
, 0)));
2446 printf ("%s\n", name
);
2450 /* Skip the NUL at the end of the table. */
2453 /* Now display the statements. */
2454 printf (_("\n Line Number Statements:\n"));
2456 while (data
< end_of_sequence
)
2458 unsigned char op_code
;
2459 dwarf_signed_vma adv
;
2461 unsigned int bytes_read
;
2465 if (op_code
>= linfo
.li_opcode_base
)
2467 op_code
-= linfo
.li_opcode_base
;
2468 uladv
= (op_code
/ linfo
.li_line_range
);
2469 if (linfo
.li_max_ops_per_insn
== 1)
2471 uladv
*= linfo
.li_min_insn_length
;
2472 state_machine_regs
.address
+= uladv
;
2473 printf (_(" Special opcode %d: "
2474 "advance Address by %s to 0x%s"),
2475 op_code
, dwarf_vmatoa ("u", uladv
),
2476 dwarf_vmatoa ("x", state_machine_regs
.address
));
2480 state_machine_regs
.address
2481 += ((state_machine_regs
.op_index
+ uladv
)
2482 / linfo
.li_max_ops_per_insn
)
2483 * linfo
.li_min_insn_length
;
2484 state_machine_regs
.op_index
2485 = (state_machine_regs
.op_index
+ uladv
)
2486 % linfo
.li_max_ops_per_insn
;
2487 printf (_(" Special opcode %d: "
2488 "advance Address by %s to 0x%s[%d]"),
2489 op_code
, dwarf_vmatoa ("u", uladv
),
2490 dwarf_vmatoa ("x", state_machine_regs
.address
),
2491 state_machine_regs
.op_index
);
2493 adv
= (op_code
% linfo
.li_line_range
) + linfo
.li_line_base
;
2494 state_machine_regs
.line
+= adv
;
2495 printf (_(" and Line by %s to %d\n"),
2496 dwarf_vmatoa ("d", adv
), state_machine_regs
.line
);
2498 else switch (op_code
)
2500 case DW_LNS_extended_op
:
2501 data
+= process_extended_line_op (data
, linfo
.li_default_is_stmt
);
2505 printf (_(" Copy\n"));
2508 case DW_LNS_advance_pc
:
2509 uladv
= read_leb128 (data
, & bytes_read
, 0);
2511 if (linfo
.li_max_ops_per_insn
== 1)
2513 uladv
*= linfo
.li_min_insn_length
;
2514 state_machine_regs
.address
+= uladv
;
2515 printf (_(" Advance PC by %s to 0x%s\n"),
2516 dwarf_vmatoa ("u", uladv
),
2517 dwarf_vmatoa ("x", state_machine_regs
.address
));
2521 state_machine_regs
.address
2522 += ((state_machine_regs
.op_index
+ uladv
)
2523 / linfo
.li_max_ops_per_insn
)
2524 * linfo
.li_min_insn_length
;
2525 state_machine_regs
.op_index
2526 = (state_machine_regs
.op_index
+ uladv
)
2527 % linfo
.li_max_ops_per_insn
;
2528 printf (_(" Advance PC by %s to 0x%s[%d]\n"),
2529 dwarf_vmatoa ("u", uladv
),
2530 dwarf_vmatoa ("x", state_machine_regs
.address
),
2531 state_machine_regs
.op_index
);
2535 case DW_LNS_advance_line
:
2536 adv
= read_sleb128 (data
, & bytes_read
);
2538 state_machine_regs
.line
+= adv
;
2539 printf (_(" Advance Line by %s to %d\n"),
2540 dwarf_vmatoa ("d", adv
),
2541 state_machine_regs
.line
);
2544 case DW_LNS_set_file
:
2545 adv
= read_leb128 (data
, & bytes_read
, 0);
2547 printf (_(" Set File Name to entry %s in the File Name Table\n"),
2548 dwarf_vmatoa ("d", adv
));
2549 state_machine_regs
.file
= adv
;
2552 case DW_LNS_set_column
:
2553 uladv
= read_leb128 (data
, & bytes_read
, 0);
2555 printf (_(" Set column to %s\n"),
2556 dwarf_vmatoa ("u", uladv
));
2557 state_machine_regs
.column
= uladv
;
2560 case DW_LNS_negate_stmt
:
2561 adv
= state_machine_regs
.is_stmt
;
2563 printf (_(" Set is_stmt to %s\n"), dwarf_vmatoa ("d", adv
));
2564 state_machine_regs
.is_stmt
= adv
;
2567 case DW_LNS_set_basic_block
:
2568 printf (_(" Set basic block\n"));
2569 state_machine_regs
.basic_block
= 1;
2572 case DW_LNS_const_add_pc
:
2573 uladv
= ((255 - linfo
.li_opcode_base
) / linfo
.li_line_range
);
2574 if (linfo
.li_max_ops_per_insn
)
2576 uladv
*= linfo
.li_min_insn_length
;
2577 state_machine_regs
.address
+= uladv
;
2578 printf (_(" Advance PC by constant %s to 0x%s\n"),
2579 dwarf_vmatoa ("u", uladv
),
2580 dwarf_vmatoa ("x", state_machine_regs
.address
));
2584 state_machine_regs
.address
2585 += ((state_machine_regs
.op_index
+ uladv
)
2586 / linfo
.li_max_ops_per_insn
)
2587 * linfo
.li_min_insn_length
;
2588 state_machine_regs
.op_index
2589 = (state_machine_regs
.op_index
+ uladv
)
2590 % linfo
.li_max_ops_per_insn
;
2591 printf (_(" Advance PC by constant %s to 0x%s[%d]\n"),
2592 dwarf_vmatoa ("u", uladv
),
2593 dwarf_vmatoa ("x", state_machine_regs
.address
),
2594 state_machine_regs
.op_index
);
2598 case DW_LNS_fixed_advance_pc
:
2599 uladv
= byte_get (data
, 2);
2601 state_machine_regs
.address
+= uladv
;
2602 state_machine_regs
.op_index
= 0;
2603 printf (_(" Advance PC by fixed size amount %s to 0x%s\n"),
2604 dwarf_vmatoa ("u", uladv
),
2605 dwarf_vmatoa ("x", state_machine_regs
.address
));
2608 case DW_LNS_set_prologue_end
:
2609 printf (_(" Set prologue_end to true\n"));
2612 case DW_LNS_set_epilogue_begin
:
2613 printf (_(" Set epilogue_begin to true\n"));
2616 case DW_LNS_set_isa
:
2617 uladv
= read_leb128 (data
, & bytes_read
, 0);
2619 printf (_(" Set ISA to %s\n"), dwarf_vmatoa ("u", uladv
));
2623 printf (_(" Unknown opcode %d with operands: "), op_code
);
2625 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
2627 printf ("0x%s%s", dwarf_vmatoa ("x", read_leb128 (data
,
2629 i
== 1 ? "" : ", ");
2644 unsigned char *name
;
2645 unsigned int directory_index
;
2646 unsigned int modification_date
;
2647 unsigned int length
;
2650 /* Output a decoded representation of the .debug_line section. */
2653 display_debug_lines_decoded (struct dwarf_section
*section
,
2654 unsigned char *data
,
2657 printf (_("Decoded dump of debug contents of section %s:\n\n"),
2662 /* This loop amounts to one iteration per compilation unit. */
2663 DWARF2_Internal_LineInfo linfo
;
2664 unsigned char *standard_opcodes
;
2665 unsigned char *end_of_sequence
;
2666 unsigned char *hdrptr
;
2667 int initial_length_size
;
2670 File_Entry
*file_table
= NULL
;
2671 unsigned char **directory_table
= NULL
;
2675 /* Extract information from the Line Number Program Header.
2676 (section 6.2.4 in the Dwarf3 doc). */
2678 /* Get the length of this CU's line number information block. */
2679 linfo
.li_length
= byte_get (hdrptr
, 4);
2682 if (linfo
.li_length
== 0xffffffff)
2684 /* This section is 64-bit DWARF 3. */
2685 linfo
.li_length
= byte_get (hdrptr
, 8);
2688 initial_length_size
= 12;
2693 initial_length_size
= 4;
2696 if (linfo
.li_length
+ initial_length_size
> section
->size
)
2698 warn (_("The line info appears to be corrupt - "
2699 "the section is too small\n"));
2703 /* Get this CU's Line Number Block version number. */
2704 linfo
.li_version
= byte_get (hdrptr
, 2);
2706 if (linfo
.li_version
!= 2
2707 && linfo
.li_version
!= 3
2708 && linfo
.li_version
!= 4)
2710 warn (_("Only DWARF version 2, 3 and 4 line info is currently "
2715 linfo
.li_prologue_length
= byte_get (hdrptr
, offset_size
);
2716 hdrptr
+= offset_size
;
2717 linfo
.li_min_insn_length
= byte_get (hdrptr
, 1);
2719 if (linfo
.li_version
>= 4)
2721 linfo
.li_max_ops_per_insn
= byte_get (hdrptr
, 1);
2723 if (linfo
.li_max_ops_per_insn
== 0)
2725 warn (_("Invalid maximum operations per insn.\n"));
2730 linfo
.li_max_ops_per_insn
= 1;
2731 linfo
.li_default_is_stmt
= byte_get (hdrptr
, 1);
2733 linfo
.li_line_base
= byte_get (hdrptr
, 1);
2735 linfo
.li_line_range
= byte_get (hdrptr
, 1);
2737 linfo
.li_opcode_base
= byte_get (hdrptr
, 1);
2740 /* Sign extend the line base field. */
2741 linfo
.li_line_base
<<= 24;
2742 linfo
.li_line_base
>>= 24;
2744 /* Find the end of this CU's Line Number Information Block. */
2745 end_of_sequence
= data
+ linfo
.li_length
+ initial_length_size
;
2747 reset_state_machine (linfo
.li_default_is_stmt
);
2749 /* Save a pointer to the contents of the Opcodes table. */
2750 standard_opcodes
= hdrptr
;
2752 /* Traverse the Directory table just to count entries. */
2753 data
= standard_opcodes
+ linfo
.li_opcode_base
- 1;
2756 unsigned int n_directories
= 0;
2757 unsigned char *ptr_directory_table
= data
;
2761 data
+= strlen ((char *) data
) + 1;
2765 /* Go through the directory table again to save the directories. */
2766 directory_table
= (unsigned char **)
2767 xmalloc (n_directories
* sizeof (unsigned char *));
2770 while (*ptr_directory_table
!= 0)
2772 directory_table
[i
] = ptr_directory_table
;
2773 ptr_directory_table
+= strlen ((char *) ptr_directory_table
) + 1;
2777 /* Skip the NUL at the end of the table. */
2780 /* Traverse the File Name table just to count the entries. */
2783 unsigned int n_files
= 0;
2784 unsigned char *ptr_file_name_table
= data
;
2788 unsigned int bytes_read
;
2790 /* Skip Name, directory index, last modification time and length
2792 data
+= strlen ((char *) data
) + 1;
2793 read_leb128 (data
, & bytes_read
, 0);
2795 read_leb128 (data
, & bytes_read
, 0);
2797 read_leb128 (data
, & bytes_read
, 0);
2803 /* Go through the file table again to save the strings. */
2804 file_table
= (File_Entry
*) xmalloc (n_files
* sizeof (File_Entry
));
2807 while (*ptr_file_name_table
!= 0)
2809 unsigned int bytes_read
;
2811 file_table
[i
].name
= ptr_file_name_table
;
2812 ptr_file_name_table
+= strlen ((char *) ptr_file_name_table
) + 1;
2814 /* We are not interested in directory, time or size. */
2815 file_table
[i
].directory_index
= read_leb128 (ptr_file_name_table
,
2817 ptr_file_name_table
+= bytes_read
;
2818 file_table
[i
].modification_date
= read_leb128 (ptr_file_name_table
,
2820 ptr_file_name_table
+= bytes_read
;
2821 file_table
[i
].length
= read_leb128 (ptr_file_name_table
, & bytes_read
, 0);
2822 ptr_file_name_table
+= bytes_read
;
2827 /* Print the Compilation Unit's name and a header. */
2828 if (directory_table
== NULL
)
2830 printf (_("CU: %s:\n"), file_table
[0].name
);
2831 printf (_("File name Line number Starting address\n"));
2835 if (do_wide
|| strlen ((char *) directory_table
[0]) < 76)
2836 printf (_("CU: %s/%s:\n"), directory_table
[0],
2837 file_table
[0].name
);
2839 printf ("%s:\n", file_table
[0].name
);
2841 printf (_("File name Line number Starting address\n"));
2845 /* Skip the NUL at the end of the table. */
2848 /* This loop iterates through the Dwarf Line Number Program. */
2849 while (data
< end_of_sequence
)
2851 unsigned char op_code
;
2853 unsigned long int uladv
;
2854 unsigned int bytes_read
;
2855 int is_special_opcode
= 0;
2859 if (op_code
>= linfo
.li_opcode_base
)
2861 op_code
-= linfo
.li_opcode_base
;
2862 uladv
= (op_code
/ linfo
.li_line_range
);
2863 if (linfo
.li_max_ops_per_insn
== 1)
2865 uladv
*= linfo
.li_min_insn_length
;
2866 state_machine_regs
.address
+= uladv
;
2870 state_machine_regs
.address
2871 += ((state_machine_regs
.op_index
+ uladv
)
2872 / linfo
.li_max_ops_per_insn
)
2873 * linfo
.li_min_insn_length
;
2874 state_machine_regs
.op_index
2875 = (state_machine_regs
.op_index
+ uladv
)
2876 % linfo
.li_max_ops_per_insn
;
2879 adv
= (op_code
% linfo
.li_line_range
) + linfo
.li_line_base
;
2880 state_machine_regs
.line
+= adv
;
2881 is_special_opcode
= 1;
2883 else switch (op_code
)
2885 case DW_LNS_extended_op
:
2887 unsigned int ext_op_code_len
;
2888 unsigned char ext_op_code
;
2889 unsigned char *op_code_data
= data
;
2891 ext_op_code_len
= read_leb128 (op_code_data
, &bytes_read
, 0);
2892 op_code_data
+= bytes_read
;
2894 if (ext_op_code_len
== 0)
2896 warn (_("badly formed extended line op encountered!\n"));
2899 ext_op_code_len
+= bytes_read
;
2900 ext_op_code
= *op_code_data
++;
2902 switch (ext_op_code
)
2904 case DW_LNE_end_sequence
:
2905 reset_state_machine (linfo
.li_default_is_stmt
);
2907 case DW_LNE_set_address
:
2908 state_machine_regs
.address
=
2909 byte_get (op_code_data
, ext_op_code_len
- bytes_read
- 1);
2910 state_machine_regs
.op_index
= 0;
2912 case DW_LNE_define_file
:
2914 unsigned int dir_index
= 0;
2916 ++state_machine_regs
.last_file_entry
;
2917 op_code_data
+= strlen ((char *) op_code_data
) + 1;
2918 dir_index
= read_leb128 (op_code_data
, & bytes_read
, 0);
2919 op_code_data
+= bytes_read
;
2920 read_leb128 (op_code_data
, & bytes_read
, 0);
2921 op_code_data
+= bytes_read
;
2922 read_leb128 (op_code_data
, & bytes_read
, 0);
2924 printf ("%s:\n", directory_table
[dir_index
]);
2928 printf (_("UNKNOWN: length %d\n"), ext_op_code_len
- bytes_read
);
2931 data
+= ext_op_code_len
;
2937 case DW_LNS_advance_pc
:
2938 uladv
= read_leb128 (data
, & bytes_read
, 0);
2940 if (linfo
.li_max_ops_per_insn
== 1)
2942 uladv
*= linfo
.li_min_insn_length
;
2943 state_machine_regs
.address
+= uladv
;
2947 state_machine_regs
.address
2948 += ((state_machine_regs
.op_index
+ uladv
)
2949 / linfo
.li_max_ops_per_insn
)
2950 * linfo
.li_min_insn_length
;
2951 state_machine_regs
.op_index
2952 = (state_machine_regs
.op_index
+ uladv
)
2953 % linfo
.li_max_ops_per_insn
;
2957 case DW_LNS_advance_line
:
2958 adv
= read_sleb128 (data
, & bytes_read
);
2960 state_machine_regs
.line
+= adv
;
2963 case DW_LNS_set_file
:
2964 adv
= read_leb128 (data
, & bytes_read
, 0);
2966 state_machine_regs
.file
= adv
;
2967 if (file_table
[state_machine_regs
.file
- 1].directory_index
== 0)
2969 /* If directory index is 0, that means current directory. */
2970 printf ("\n./%s:[++]\n",
2971 file_table
[state_machine_regs
.file
- 1].name
);
2975 /* The directory index starts counting at 1. */
2976 printf ("\n%s/%s:\n",
2977 directory_table
[file_table
[state_machine_regs
.file
- 1].directory_index
- 1],
2978 file_table
[state_machine_regs
.file
- 1].name
);
2982 case DW_LNS_set_column
:
2983 uladv
= read_leb128 (data
, & bytes_read
, 0);
2985 state_machine_regs
.column
= uladv
;
2988 case DW_LNS_negate_stmt
:
2989 adv
= state_machine_regs
.is_stmt
;
2991 state_machine_regs
.is_stmt
= adv
;
2994 case DW_LNS_set_basic_block
:
2995 state_machine_regs
.basic_block
= 1;
2998 case DW_LNS_const_add_pc
:
2999 uladv
= ((255 - linfo
.li_opcode_base
) / linfo
.li_line_range
);
3000 if (linfo
.li_max_ops_per_insn
== 1)
3002 uladv
*= linfo
.li_min_insn_length
;
3003 state_machine_regs
.address
+= uladv
;
3007 state_machine_regs
.address
3008 += ((state_machine_regs
.op_index
+ uladv
)
3009 / linfo
.li_max_ops_per_insn
)
3010 * linfo
.li_min_insn_length
;
3011 state_machine_regs
.op_index
3012 = (state_machine_regs
.op_index
+ uladv
)
3013 % linfo
.li_max_ops_per_insn
;
3017 case DW_LNS_fixed_advance_pc
:
3018 uladv
= byte_get (data
, 2);
3020 state_machine_regs
.address
+= uladv
;
3021 state_machine_regs
.op_index
= 0;
3024 case DW_LNS_set_prologue_end
:
3027 case DW_LNS_set_epilogue_begin
:
3030 case DW_LNS_set_isa
:
3031 uladv
= read_leb128 (data
, & bytes_read
, 0);
3033 printf (_(" Set ISA to %lu\n"), uladv
);
3037 printf (_(" Unknown opcode %d with operands: "), op_code
);
3039 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
3041 printf ("0x%s%s", dwarf_vmatoa ("x", read_leb128 (data
,
3043 i
== 1 ? "" : ", ");
3050 /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row
3051 to the DWARF address/line matrix. */
3052 if ((is_special_opcode
) || (op_code
== DW_LNE_end_sequence
)
3053 || (op_code
== DW_LNS_copy
))
3055 const unsigned int MAX_FILENAME_LENGTH
= 35;
3056 char *fileName
= (char *)file_table
[state_machine_regs
.file
- 1].name
;
3057 char *newFileName
= NULL
;
3058 size_t fileNameLength
= strlen (fileName
);
3060 if ((fileNameLength
> MAX_FILENAME_LENGTH
) && (!do_wide
))
3062 newFileName
= (char *) xmalloc (MAX_FILENAME_LENGTH
+ 1);
3063 /* Truncate file name */
3064 strncpy (newFileName
,
3065 fileName
+ fileNameLength
- MAX_FILENAME_LENGTH
,
3066 MAX_FILENAME_LENGTH
+ 1);
3070 newFileName
= (char *) xmalloc (fileNameLength
+ 1);
3071 strncpy (newFileName
, fileName
, fileNameLength
+ 1);
3074 if (!do_wide
|| (fileNameLength
<= MAX_FILENAME_LENGTH
))
3076 if (linfo
.li_max_ops_per_insn
== 1)
3077 printf ("%-35s %11d %#18" DWARF_VMA_FMT
"x\n",
3078 newFileName
, state_machine_regs
.line
,
3079 state_machine_regs
.address
);
3081 printf ("%-35s %11d %#18" DWARF_VMA_FMT
"x[%d]\n",
3082 newFileName
, state_machine_regs
.line
,
3083 state_machine_regs
.address
,
3084 state_machine_regs
.op_index
);
3088 if (linfo
.li_max_ops_per_insn
== 1)
3089 printf ("%s %11d %#18" DWARF_VMA_FMT
"x\n",
3090 newFileName
, state_machine_regs
.line
,
3091 state_machine_regs
.address
);
3093 printf ("%s %11d %#18" DWARF_VMA_FMT
"x[%d]\n",
3094 newFileName
, state_machine_regs
.line
,
3095 state_machine_regs
.address
,
3096 state_machine_regs
.op_index
);
3099 if (op_code
== DW_LNE_end_sequence
)
3107 free (directory_table
);
3108 directory_table
= NULL
;
3116 display_debug_lines (struct dwarf_section
*section
, void *file ATTRIBUTE_UNUSED
)
3118 unsigned char *data
= section
->start
;
3119 unsigned char *end
= data
+ section
->size
;
3121 int retValDecoded
= 1;
3123 if (do_debug_lines
== 0)
3124 do_debug_lines
|= FLAG_DEBUG_LINES_RAW
;
3126 if (do_debug_lines
& FLAG_DEBUG_LINES_RAW
)
3127 retValRaw
= display_debug_lines_raw (section
, data
, end
);
3129 if (do_debug_lines
& FLAG_DEBUG_LINES_DECODED
)
3130 retValDecoded
= display_debug_lines_decoded (section
, data
, end
);
3132 if (!retValRaw
|| !retValDecoded
)
3139 find_debug_info_for_offset (unsigned long offset
)
3143 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
3146 for (i
= 0; i
< num_debug_info_entries
; i
++)
3147 if (debug_information
[i
].cu_offset
== offset
)
3148 return debug_information
+ i
;
3154 display_debug_pubnames (struct dwarf_section
*section
,
3155 void *file ATTRIBUTE_UNUSED
)
3157 DWARF2_Internal_PubNames names
;
3158 unsigned char *start
= section
->start
;
3159 unsigned char *end
= start
+ section
->size
;
3161 /* It does not matter if this load fails,
3162 we test for that later on. */
3163 load_debug_info (file
);
3165 printf (_("Contents of the %s section:\n\n"), section
->name
);
3169 unsigned char *data
;
3170 unsigned long offset
;
3171 int offset_size
, initial_length_size
;
3175 names
.pn_length
= byte_get (data
, 4);
3177 if (names
.pn_length
== 0xffffffff)
3179 names
.pn_length
= byte_get (data
, 8);
3182 initial_length_size
= 12;
3187 initial_length_size
= 4;
3190 names
.pn_version
= byte_get (data
, 2);
3193 names
.pn_offset
= byte_get (data
, offset_size
);
3194 data
+= offset_size
;
3196 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
3197 && num_debug_info_entries
> 0
3198 && find_debug_info_for_offset (names
.pn_offset
) == NULL
)
3199 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
3200 (unsigned long) names
.pn_offset
, section
->name
);
3202 names
.pn_size
= byte_get (data
, offset_size
);
3203 data
+= offset_size
;
3205 start
+= names
.pn_length
+ initial_length_size
;
3207 if (names
.pn_version
!= 2 && names
.pn_version
!= 3)
3209 static int warned
= 0;
3213 warn (_("Only DWARF 2 and 3 pubnames are currently supported\n"));
3220 printf (_(" Length: %ld\n"),
3221 (long) names
.pn_length
);
3222 printf (_(" Version: %d\n"),
3224 printf (_(" Offset into .debug_info section: 0x%lx\n"),
3225 (unsigned long) names
.pn_offset
);
3226 printf (_(" Size of area in .debug_info section: %ld\n"),
3227 (long) names
.pn_size
);
3229 printf (_("\n Offset\tName\n"));
3233 offset
= byte_get (data
, offset_size
);
3237 data
+= offset_size
;
3238 printf (" %-6lx\t%s\n", offset
, data
);
3239 data
+= strlen ((char *) data
) + 1;
3242 while (offset
!= 0);
3250 display_debug_macinfo (struct dwarf_section
*section
,
3251 void *file ATTRIBUTE_UNUSED
)
3253 unsigned char *start
= section
->start
;
3254 unsigned char *end
= start
+ section
->size
;
3255 unsigned char *curr
= start
;
3256 unsigned int bytes_read
;
3257 enum dwarf_macinfo_record_type op
;
3259 printf (_("Contents of the %s section:\n\n"), section
->name
);
3263 unsigned int lineno
;
3266 op
= (enum dwarf_macinfo_record_type
) *curr
;
3271 case DW_MACINFO_start_file
:
3273 unsigned int filenum
;
3275 lineno
= read_leb128 (curr
, & bytes_read
, 0);
3277 filenum
= read_leb128 (curr
, & bytes_read
, 0);
3280 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"),
3285 case DW_MACINFO_end_file
:
3286 printf (_(" DW_MACINFO_end_file\n"));
3289 case DW_MACINFO_define
:
3290 lineno
= read_leb128 (curr
, & bytes_read
, 0);
3292 string
= (char *) curr
;
3293 curr
+= strlen (string
) + 1;
3294 printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"),
3298 case DW_MACINFO_undef
:
3299 lineno
= read_leb128 (curr
, & bytes_read
, 0);
3301 string
= (char *) curr
;
3302 curr
+= strlen (string
) + 1;
3303 printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"),
3307 case DW_MACINFO_vendor_ext
:
3309 unsigned int constant
;
3311 constant
= read_leb128 (curr
, & bytes_read
, 0);
3313 string
= (char *) curr
;
3314 curr
+= strlen (string
) + 1;
3315 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"),
3326 display_debug_abbrev (struct dwarf_section
*section
,
3327 void *file ATTRIBUTE_UNUSED
)
3329 abbrev_entry
*entry
;
3330 unsigned char *start
= section
->start
;
3331 unsigned char *end
= start
+ section
->size
;
3333 printf (_("Contents of the %s section:\n\n"), section
->name
);
3339 start
= process_abbrev_section (start
, end
);
3341 if (first_abbrev
== NULL
)
3344 printf (_(" Number TAG\n"));
3346 for (entry
= first_abbrev
; entry
; entry
= entry
->next
)
3350 printf (" %ld %s [%s]\n",
3352 get_TAG_name (entry
->tag
),
3353 entry
->children
? _("has children") : _("no children"));
3355 for (attr
= entry
->first_attr
; attr
; attr
= attr
->next
)
3356 printf (" %-18s %s\n",
3357 get_AT_name (attr
->attribute
),
3358 get_FORM_name (attr
->form
));
3369 display_debug_loc (struct dwarf_section
*section
, void *file
)
3371 unsigned char *start
= section
->start
;
3372 unsigned char *section_end
;
3373 unsigned long bytes
;
3374 unsigned char *section_begin
= start
;
3375 unsigned int num_loc_list
= 0;
3376 unsigned long last_offset
= 0;
3377 unsigned int first
= 0;
3380 int seen_first_offset
= 0;
3381 int use_debug_info
= 1;
3382 unsigned char *next
;
3384 bytes
= section
->size
;
3385 section_end
= start
+ bytes
;
3389 printf (_("\nThe %s section is empty.\n"), section
->name
);
3393 if (load_debug_info (file
) == 0)
3395 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
3400 /* Check the order of location list in .debug_info section. If
3401 offsets of location lists are in the ascending order, we can
3402 use `debug_information' directly. */
3403 for (i
= 0; i
< num_debug_info_entries
; i
++)
3407 num
= debug_information
[i
].num_loc_offsets
;
3408 num_loc_list
+= num
;
3410 /* Check if we can use `debug_information' directly. */
3411 if (use_debug_info
&& num
!= 0)
3413 if (!seen_first_offset
)
3415 /* This is the first location list. */
3416 last_offset
= debug_information
[i
].loc_offsets
[0];
3418 seen_first_offset
= 1;
3424 for (; j
< num
; j
++)
3427 debug_information
[i
].loc_offsets
[j
])
3432 last_offset
= debug_information
[i
].loc_offsets
[j
];
3437 if (!use_debug_info
)
3438 /* FIXME: Should we handle this case? */
3439 error (_("Location lists in .debug_info section aren't in ascending order!\n"));
3441 if (!seen_first_offset
)
3442 error (_("No location lists in .debug_info section!\n"));
3444 /* DWARF sections under Mach-O have non-zero addresses. */
3445 if (debug_information
[first
].num_loc_offsets
> 0
3446 && debug_information
[first
].loc_offsets
[0] != section
->address
)
3447 warn (_("Location lists in %s section start at 0x%s\n"),
3449 dwarf_vmatoa ("x", debug_information
[first
].loc_offsets
[0]));
3451 printf (_("Contents of the %s section:\n\n"), section
->name
);
3452 printf (_(" Offset Begin End Expression\n"));
3454 seen_first_offset
= 0;
3455 for (i
= first
; i
< num_debug_info_entries
; i
++)
3459 unsigned short length
;
3460 unsigned long offset
;
3461 unsigned int pointer_size
;
3462 unsigned int offset_size
;
3464 unsigned long cu_offset
;
3465 unsigned long base_address
;
3466 int need_frame_base
;
3469 pointer_size
= debug_information
[i
].pointer_size
;
3470 cu_offset
= debug_information
[i
].cu_offset
;
3471 offset_size
= debug_information
[i
].offset_size
;
3472 dwarf_version
= debug_information
[i
].dwarf_version
;
3474 for (j
= 0; j
< debug_information
[i
].num_loc_offsets
; j
++)
3476 has_frame_base
= debug_information
[i
].have_frame_base
[j
];
3477 /* DWARF sections under Mach-O have non-zero addresses. */
3478 offset
= debug_information
[i
].loc_offsets
[j
] - section
->address
;
3479 next
= section_begin
+ offset
;
3480 base_address
= debug_information
[i
].base_address
;
3482 if (!seen_first_offset
)
3483 seen_first_offset
= 1;
3487 warn (_("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n"),
3488 (unsigned long) (start
- section_begin
),
3489 (unsigned long) (next
- section_begin
));
3490 else if (start
> next
)
3491 warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n"),
3492 (unsigned long) (start
- section_begin
),
3493 (unsigned long) (next
- section_begin
));
3497 if (offset
>= bytes
)
3499 warn (_("Offset 0x%lx is bigger than .debug_loc section size.\n"),
3506 if (start
+ 2 * pointer_size
> section_end
)
3508 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
3513 /* Note: we use sign extension here in order to be sure that
3514 we can detect the -1 escape value. Sign extension into the
3515 top 32 bits of a 32-bit address will not affect the values
3516 that we display since we always show hex values, and always
3517 the bottom 32-bits. */
3518 begin
= byte_get_signed (start
, pointer_size
);
3519 start
+= pointer_size
;
3520 end
= byte_get_signed (start
, pointer_size
);
3521 start
+= pointer_size
;
3523 printf (" %8.8lx ", offset
);
3525 if (begin
== 0 && end
== 0)
3527 printf (_("<End of list>\n"));
3531 /* Check base address specifiers. */
3532 if (begin
== (dwarf_vma
) -1 && end
!= (dwarf_vma
) -1)
3535 print_dwarf_vma (begin
, pointer_size
);
3536 print_dwarf_vma (end
, pointer_size
);
3537 printf (_("(base address)\n"));
3541 if (start
+ 2 > section_end
)
3543 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
3548 length
= byte_get (start
, 2);
3551 if (start
+ length
> section_end
)
3553 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
3558 print_dwarf_vma (begin
+ base_address
, pointer_size
);
3559 print_dwarf_vma (end
+ base_address
, pointer_size
);
3562 need_frame_base
= decode_location_expression (start
,
3567 cu_offset
, section
);
3570 if (need_frame_base
&& !has_frame_base
)
3571 printf (_(" [without DW_AT_frame_base]"));
3574 fputs (_(" (start == end)"), stdout
);
3575 else if (begin
> end
)
3576 fputs (_(" (start > end)"), stdout
);
3585 if (start
< section_end
)
3586 warn (_("There are %ld unused bytes at the end of section %s\n"),
3587 (long) (section_end
- start
), section
->name
);
3593 display_debug_str (struct dwarf_section
*section
,
3594 void *file ATTRIBUTE_UNUSED
)
3596 unsigned char *start
= section
->start
;
3597 unsigned long bytes
= section
->size
;
3598 dwarf_vma addr
= section
->address
;
3602 printf (_("\nThe %s section is empty.\n"), section
->name
);
3606 printf (_("Contents of the %s section:\n\n"), section
->name
);
3614 lbytes
= (bytes
> 16 ? 16 : bytes
);
3616 printf (" 0x%8.8lx ", (unsigned long) addr
);
3618 for (j
= 0; j
< 16; j
++)
3621 printf ("%2.2x", start
[j
]);
3629 for (j
= 0; j
< lbytes
; j
++)
3632 if (k
>= ' ' && k
< 0x80)
3651 display_debug_info (struct dwarf_section
*section
, void *file
)
3653 return process_debug_info (section
, file
, abbrev
, 0, 0);
3657 display_debug_types (struct dwarf_section
*section
, void *file
)
3659 return process_debug_info (section
, file
, abbrev
, 0, 1);
3663 display_trace_info (struct dwarf_section
*section
, void *file
)
3665 return process_debug_info (section
, file
, trace_abbrev
, 0, 0);
3669 display_debug_aranges (struct dwarf_section
*section
,
3670 void *file ATTRIBUTE_UNUSED
)
3672 unsigned char *start
= section
->start
;
3673 unsigned char *end
= start
+ section
->size
;
3675 printf (_("Contents of the %s section:\n\n"), section
->name
);
3677 /* It does not matter if this load fails,
3678 we test for that later on. */
3679 load_debug_info (file
);
3683 unsigned char *hdrptr
;
3684 DWARF2_Internal_ARange arange
;
3685 unsigned char *addr_ranges
;
3688 unsigned char address_size
;
3691 int initial_length_size
;
3695 arange
.ar_length
= byte_get (hdrptr
, 4);
3698 if (arange
.ar_length
== 0xffffffff)
3700 arange
.ar_length
= byte_get (hdrptr
, 8);
3703 initial_length_size
= 12;
3708 initial_length_size
= 4;
3711 arange
.ar_version
= byte_get (hdrptr
, 2);
3714 arange
.ar_info_offset
= byte_get (hdrptr
, offset_size
);
3715 hdrptr
+= offset_size
;
3717 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
3718 && num_debug_info_entries
> 0
3719 && find_debug_info_for_offset (arange
.ar_info_offset
) == NULL
)
3720 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
3721 (unsigned long) arange
.ar_info_offset
, section
->name
);
3723 arange
.ar_pointer_size
= byte_get (hdrptr
, 1);
3726 arange
.ar_segment_size
= byte_get (hdrptr
, 1);
3729 if (arange
.ar_version
!= 2 && arange
.ar_version
!= 3)
3731 warn (_("Only DWARF 2 and 3 aranges are currently supported.\n"));
3735 printf (_(" Length: %ld\n"),
3736 (long) arange
.ar_length
);
3737 printf (_(" Version: %d\n"), arange
.ar_version
);
3738 printf (_(" Offset into .debug_info: 0x%lx\n"),
3739 (unsigned long) arange
.ar_info_offset
);
3740 printf (_(" Pointer Size: %d\n"), arange
.ar_pointer_size
);
3741 printf (_(" Segment Size: %d\n"), arange
.ar_segment_size
);
3743 address_size
= arange
.ar_pointer_size
+ arange
.ar_segment_size
;
3745 /* The DWARF spec does not require that the address size be a power
3746 of two, but we do. This will have to change if we ever encounter
3747 an uneven architecture. */
3748 if ((address_size
& (address_size
- 1)) != 0)
3750 warn (_("Pointer size + Segment size is not a power of two.\n"));
3754 if (address_size
> 4)
3755 printf (_("\n Address Length\n"));
3757 printf (_("\n Address Length\n"));
3759 addr_ranges
= hdrptr
;
3761 /* Must pad to an alignment boundary that is twice the address size. */
3762 excess
= (hdrptr
- start
) % (2 * address_size
);
3764 addr_ranges
+= (2 * address_size
) - excess
;
3766 start
+= arange
.ar_length
+ initial_length_size
;
3768 while (addr_ranges
+ 2 * address_size
<= start
)
3770 address
= byte_get (addr_ranges
, address_size
);
3772 addr_ranges
+= address_size
;
3774 length
= byte_get (addr_ranges
, address_size
);
3776 addr_ranges
+= address_size
;
3779 print_dwarf_vma (address
, address_size
);
3780 print_dwarf_vma (length
, address_size
);
3790 /* Each debug_information[x].range_lists[y] gets this representation for
3791 sorting purposes. */
3795 /* The debug_information[x].range_lists[y] value. */
3796 unsigned long ranges_offset
;
3798 /* Original debug_information to find parameters of the data. */
3799 debug_info
*debug_info_p
;
3802 /* Sort struct range_entry in ascending order of its RANGES_OFFSET. */
3805 range_entry_compar (const void *ap
, const void *bp
)
3807 const struct range_entry
*a_re
= (const struct range_entry
*) ap
;
3808 const struct range_entry
*b_re
= (const struct range_entry
*) bp
;
3809 const unsigned long a
= a_re
->ranges_offset
;
3810 const unsigned long b
= b_re
->ranges_offset
;
3812 return (a
> b
) - (b
> a
);
3816 display_debug_ranges (struct dwarf_section
*section
,
3817 void *file ATTRIBUTE_UNUSED
)
3819 unsigned char *start
= section
->start
;
3820 unsigned long bytes
;
3821 unsigned char *section_begin
= start
;
3822 unsigned int num_range_list
, i
;
3823 struct range_entry
*range_entries
, *range_entry_fill
;
3825 bytes
= section
->size
;
3829 printf (_("\nThe %s section is empty.\n"), section
->name
);
3833 if (load_debug_info (file
) == 0)
3835 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
3841 for (i
= 0; i
< num_debug_info_entries
; i
++)
3842 num_range_list
+= debug_information
[i
].num_range_lists
;
3844 if (num_range_list
== 0)
3845 error (_("No range lists in .debug_info section!\n"));
3847 range_entries
= (struct range_entry
*)
3848 xmalloc (sizeof (*range_entries
) * num_range_list
);
3849 range_entry_fill
= range_entries
;
3851 for (i
= 0; i
< num_debug_info_entries
; i
++)
3853 debug_info
*debug_info_p
= &debug_information
[i
];
3856 for (j
= 0; j
< debug_info_p
->num_range_lists
; j
++)
3858 range_entry_fill
->ranges_offset
= debug_info_p
->range_lists
[j
];
3859 range_entry_fill
->debug_info_p
= debug_info_p
;
3864 qsort (range_entries
, num_range_list
, sizeof (*range_entries
),
3865 range_entry_compar
);
3867 /* DWARF sections under Mach-O have non-zero addresses. */
3868 if (range_entries
[0].ranges_offset
!= section
->address
)
3869 warn (_("Range lists in %s section start at 0x%lx\n"),
3870 section
->name
, range_entries
[0].ranges_offset
);
3872 printf (_("Contents of the %s section:\n\n"), section
->name
);
3873 printf (_(" Offset Begin End\n"));
3875 for (i
= 0; i
< num_range_list
; i
++)
3877 struct range_entry
*range_entry
= &range_entries
[i
];
3878 debug_info
*debug_info_p
= range_entry
->debug_info_p
;
3879 unsigned int pointer_size
;
3880 unsigned long offset
;
3881 unsigned char *next
;
3882 unsigned long base_address
;
3884 pointer_size
= debug_info_p
->pointer_size
;
3886 /* DWARF sections under Mach-O have non-zero addresses. */
3887 offset
= range_entry
->ranges_offset
- section
->address
;
3888 next
= section_begin
+ offset
;
3889 base_address
= debug_info_p
->base_address
;
3894 warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"),
3895 (unsigned long) (start
- section_begin
),
3896 (unsigned long) (next
- section_begin
), section
->name
);
3897 else if (start
> next
)
3898 warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"),
3899 (unsigned long) (start
- section_begin
),
3900 (unsigned long) (next
- section_begin
), section
->name
);
3909 /* Note: we use sign extension here in order to be sure that
3910 we can detect the -1 escape value. Sign extension into the
3911 top 32 bits of a 32-bit address will not affect the values
3912 that we display since we always show hex values, and always
3913 the bottom 32-bits. */
3914 begin
= byte_get_signed (start
, pointer_size
);
3915 start
+= pointer_size
;
3916 end
= byte_get_signed (start
, pointer_size
);
3917 start
+= pointer_size
;
3919 printf (" %8.8lx ", offset
);
3921 if (begin
== 0 && end
== 0)
3923 printf (_("<End of list>\n"));
3927 /* Check base address specifiers. */
3928 if (begin
== (dwarf_vma
) -1 && end
!= (dwarf_vma
) -1)
3931 print_dwarf_vma (begin
, pointer_size
);
3932 print_dwarf_vma (end
, pointer_size
);
3933 printf ("(base address)\n");
3937 print_dwarf_vma (begin
+ base_address
, pointer_size
);
3938 print_dwarf_vma (end
+ base_address
, pointer_size
);
3941 fputs (_("(start == end)"), stdout
);
3942 else if (begin
> end
)
3943 fputs (_("(start > end)"), stdout
);
3950 free (range_entries
);
3955 typedef struct Frame_Chunk
3957 struct Frame_Chunk
*next
;
3958 unsigned char *chunk_start
;
3960 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
3961 short int *col_type
;
3964 unsigned int code_factor
;
3966 unsigned long pc_begin
;
3967 unsigned long pc_range
;
3971 unsigned char fde_encoding
;
3972 unsigned char cfa_exp
;
3973 unsigned char ptr_size
;
3974 unsigned char segment_size
;
3978 static const char *const *dwarf_regnames
;
3979 static unsigned int dwarf_regnames_count
;
3981 /* A marker for a col_type that means this column was never referenced
3982 in the frame info. */
3983 #define DW_CFA_unreferenced (-1)
3985 /* Return 0 if not more space is needed, 1 if more space is needed,
3986 -1 for invalid reg. */
3989 frame_need_space (Frame_Chunk
*fc
, unsigned int reg
)
3991 int prev
= fc
->ncols
;
3993 if (reg
< (unsigned int) fc
->ncols
)
3996 if (dwarf_regnames_count
3997 && reg
> dwarf_regnames_count
)
4000 fc
->ncols
= reg
+ 1;
4001 fc
->col_type
= (short int *) xcrealloc (fc
->col_type
, fc
->ncols
,
4002 sizeof (short int));
4003 fc
->col_offset
= (int *) xcrealloc (fc
->col_offset
, fc
->ncols
, sizeof (int));
4005 while (prev
< fc
->ncols
)
4007 fc
->col_type
[prev
] = DW_CFA_unreferenced
;
4008 fc
->col_offset
[prev
] = 0;
4014 static const char *const dwarf_regnames_i386
[] =
4016 "eax", "ecx", "edx", "ebx",
4017 "esp", "ebp", "esi", "edi",
4018 "eip", "eflags", NULL
,
4019 "st0", "st1", "st2", "st3",
4020 "st4", "st5", "st6", "st7",
4022 "xmm0", "xmm1", "xmm2", "xmm3",
4023 "xmm4", "xmm5", "xmm6", "xmm7",
4024 "mm0", "mm1", "mm2", "mm3",
4025 "mm4", "mm5", "mm6", "mm7",
4026 "fcw", "fsw", "mxcsr",
4027 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
,
4032 init_dwarf_regnames_i386 (void)
4034 dwarf_regnames
= dwarf_regnames_i386
;
4035 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_i386
);
4038 static const char *const dwarf_regnames_x86_64
[] =
4040 "rax", "rdx", "rcx", "rbx",
4041 "rsi", "rdi", "rbp", "rsp",
4042 "r8", "r9", "r10", "r11",
4043 "r12", "r13", "r14", "r15",
4045 "xmm0", "xmm1", "xmm2", "xmm3",
4046 "xmm4", "xmm5", "xmm6", "xmm7",
4047 "xmm8", "xmm9", "xmm10", "xmm11",
4048 "xmm12", "xmm13", "xmm14", "xmm15",
4049 "st0", "st1", "st2", "st3",
4050 "st4", "st5", "st6", "st7",
4051 "mm0", "mm1", "mm2", "mm3",
4052 "mm4", "mm5", "mm6", "mm7",
4054 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
,
4055 "fs.base", "gs.base", NULL
, NULL
,
4057 "mxcsr", "fcw", "fsw"
4061 init_dwarf_regnames_x86_64 (void)
4063 dwarf_regnames
= dwarf_regnames_x86_64
;
4064 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_x86_64
);
4068 init_dwarf_regnames (unsigned int e_machine
)
4074 init_dwarf_regnames_i386 ();
4079 init_dwarf_regnames_x86_64 ();
4088 regname (unsigned int regno
, int row
)
4090 static char reg
[64];
4092 && regno
< dwarf_regnames_count
4093 && dwarf_regnames
[regno
] != NULL
)
4096 return dwarf_regnames
[regno
];
4097 snprintf (reg
, sizeof (reg
), "r%d (%s)", regno
,
4098 dwarf_regnames
[regno
]);
4101 snprintf (reg
, sizeof (reg
), "r%d", regno
);
4106 frame_display_row (Frame_Chunk
*fc
, int *need_col_headers
, int *max_regs
)
4111 if (*max_regs
< fc
->ncols
)
4112 *max_regs
= fc
->ncols
;
4114 if (*need_col_headers
)
4116 static const char *sloc
= " LOC";
4118 *need_col_headers
= 0;
4120 printf ("%-*s CFA ", eh_addr_size
* 2, sloc
);
4122 for (r
= 0; r
< *max_regs
; r
++)
4123 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
4128 printf ("%-5s ", regname (r
, 1));
4134 printf ("%0*lx ", eh_addr_size
* 2, fc
->pc_begin
);
4136 strcpy (tmp
, "exp");
4138 sprintf (tmp
, "%s%+d", regname (fc
->cfa_reg
, 1), fc
->cfa_offset
);
4139 printf ("%-8s ", tmp
);
4141 for (r
= 0; r
< fc
->ncols
; r
++)
4143 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
4145 switch (fc
->col_type
[r
])
4147 case DW_CFA_undefined
:
4150 case DW_CFA_same_value
:
4154 sprintf (tmp
, "c%+d", fc
->col_offset
[r
]);
4156 case DW_CFA_val_offset
:
4157 sprintf (tmp
, "v%+d", fc
->col_offset
[r
]);
4159 case DW_CFA_register
:
4160 sprintf (tmp
, "%s", regname (fc
->col_offset
[r
], 0));
4162 case DW_CFA_expression
:
4163 strcpy (tmp
, "exp");
4165 case DW_CFA_val_expression
:
4166 strcpy (tmp
, "vexp");
4169 strcpy (tmp
, "n/a");
4172 printf ("%-5s ", tmp
);
4178 #define GET(N) byte_get (start, N); start += N
4179 #define LEB() read_leb128 (start, & length_return, 0); start += length_return
4180 #define SLEB() read_sleb128 (start, & length_return); start += length_return
4183 display_debug_frames (struct dwarf_section
*section
,
4184 void *file ATTRIBUTE_UNUSED
)
4186 unsigned char *start
= section
->start
;
4187 unsigned char *end
= start
+ section
->size
;
4188 unsigned char *section_start
= start
;
4189 Frame_Chunk
*chunks
= 0;
4190 Frame_Chunk
*remembered_state
= 0;
4192 int is_eh
= strcmp (section
->name
, ".eh_frame") == 0;
4193 unsigned int length_return
;
4195 const char *bad_reg
= _("bad register: ");
4196 int saved_eh_addr_size
= eh_addr_size
;
4198 printf (_("Contents of the %s section:\n"), section
->name
);
4202 unsigned char *saved_start
;
4203 unsigned char *block_end
;
4204 unsigned long length
;
4205 unsigned long cie_id
;
4208 int need_col_headers
= 1;
4209 unsigned char *augmentation_data
= NULL
;
4210 unsigned long augmentation_data_len
= 0;
4211 int encoded_ptr_size
= saved_eh_addr_size
;
4213 int initial_length_size
;
4215 saved_start
= start
;
4216 length
= byte_get (start
, 4); start
+= 4;
4220 printf ("\n%08lx ZERO terminator\n\n",
4221 (unsigned long)(saved_start
- section_start
));
4225 if (length
== 0xffffffff)
4227 length
= byte_get (start
, 8);
4230 initial_length_size
= 12;
4235 initial_length_size
= 4;
4238 block_end
= saved_start
+ length
+ initial_length_size
;
4239 if (block_end
> end
)
4241 warn ("Invalid length %#08lx in FDE at %#08lx\n",
4242 length
, (unsigned long)(saved_start
- section_start
));
4245 cie_id
= byte_get (start
, offset_size
); start
+= offset_size
;
4247 if (is_eh
? (cie_id
== 0) : (cie_id
== DW_CIE_ID
))
4251 fc
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
4252 memset (fc
, 0, sizeof (Frame_Chunk
));
4256 fc
->chunk_start
= saved_start
;
4258 fc
->col_type
= (short int *) xmalloc (sizeof (short int));
4259 fc
->col_offset
= (int *) xmalloc (sizeof (int));
4260 frame_need_space (fc
, max_regs
- 1);
4264 fc
->augmentation
= (char *) start
;
4265 start
= (unsigned char *) strchr ((char *) start
, '\0') + 1;
4267 if (strcmp (fc
->augmentation
, "eh") == 0)
4268 start
+= eh_addr_size
;
4272 fc
->ptr_size
= GET (1);
4273 fc
->segment_size
= GET (1);
4274 eh_addr_size
= fc
->ptr_size
;
4278 fc
->ptr_size
= eh_addr_size
;
4279 fc
->segment_size
= 0;
4281 fc
->code_factor
= LEB ();
4282 fc
->data_factor
= SLEB ();
4292 if (fc
->augmentation
[0] == 'z')
4294 augmentation_data_len
= LEB ();
4295 augmentation_data
= start
;
4296 start
+= augmentation_data_len
;
4300 if (do_debug_frames_interp
)
4301 printf ("\n%08lx %08lx %08lx CIE \"%s\" cf=%d df=%d ra=%d\n",
4302 (unsigned long)(saved_start
- section_start
), length
, cie_id
,
4303 fc
->augmentation
, fc
->code_factor
, fc
->data_factor
,
4307 printf ("\n%08lx %08lx %08lx CIE\n",
4308 (unsigned long)(saved_start
- section_start
), length
, cie_id
);
4309 printf (" Version: %d\n", version
);
4310 printf (" Augmentation: \"%s\"\n", fc
->augmentation
);
4313 printf (" Pointer Size: %u\n", fc
->ptr_size
);
4314 printf (" Segment Size: %u\n", fc
->segment_size
);
4316 printf (" Code alignment factor: %u\n", fc
->code_factor
);
4317 printf (" Data alignment factor: %d\n", fc
->data_factor
);
4318 printf (" Return address column: %d\n", fc
->ra
);
4320 if (augmentation_data_len
)
4323 printf (" Augmentation data: ");
4324 for (i
= 0; i
< augmentation_data_len
; ++i
)
4325 printf (" %02x", augmentation_data
[i
]);
4331 if (augmentation_data_len
)
4333 unsigned char *p
, *q
;
4334 p
= (unsigned char *) fc
->augmentation
+ 1;
4335 q
= augmentation_data
;
4342 q
+= 1 + size_of_encoded_value (*q
);
4344 fc
->fde_encoding
= *q
++;
4352 if (fc
->fde_encoding
)
4353 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
4356 frame_need_space (fc
, fc
->ra
);
4360 unsigned char *look_for
;
4361 static Frame_Chunk fde_fc
;
4362 unsigned long segment_selector
;
4365 memset (fc
, 0, sizeof (Frame_Chunk
));
4367 look_for
= is_eh
? start
- 4 - cie_id
: section_start
+ cie_id
;
4369 for (cie
= chunks
; cie
; cie
= cie
->next
)
4370 if (cie
->chunk_start
== look_for
)
4375 warn ("Invalid CIE pointer %#08lx in FDE at %#08lx\n",
4376 cie_id
, (unsigned long)(saved_start
- section_start
));
4378 fc
->col_type
= (short int *) xmalloc (sizeof (short int));
4379 fc
->col_offset
= (int *) xmalloc (sizeof (int));
4380 frame_need_space (fc
, max_regs
- 1);
4382 fc
->augmentation
= "";
4383 fc
->fde_encoding
= 0;
4384 fc
->ptr_size
= eh_addr_size
;
4385 fc
->segment_size
= 0;
4389 fc
->ncols
= cie
->ncols
;
4390 fc
->col_type
= (short int *) xcmalloc (fc
->ncols
, sizeof (short int));
4391 fc
->col_offset
= (int *) xcmalloc (fc
->ncols
, sizeof (int));
4392 memcpy (fc
->col_type
, cie
->col_type
, fc
->ncols
* sizeof (short int));
4393 memcpy (fc
->col_offset
, cie
->col_offset
, fc
->ncols
* sizeof (int));
4394 fc
->augmentation
= cie
->augmentation
;
4395 fc
->ptr_size
= cie
->ptr_size
;
4396 eh_addr_size
= cie
->ptr_size
;
4397 fc
->segment_size
= cie
->segment_size
;
4398 fc
->code_factor
= cie
->code_factor
;
4399 fc
->data_factor
= cie
->data_factor
;
4400 fc
->cfa_reg
= cie
->cfa_reg
;
4401 fc
->cfa_offset
= cie
->cfa_offset
;
4403 frame_need_space (fc
, max_regs
- 1);
4404 fc
->fde_encoding
= cie
->fde_encoding
;
4407 if (fc
->fde_encoding
)
4408 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
4410 segment_selector
= 0;
4411 if (fc
->segment_size
)
4413 segment_selector
= byte_get (start
, fc
->segment_size
);
4414 start
+= fc
->segment_size
;
4416 fc
->pc_begin
= get_encoded_value (start
, fc
->fde_encoding
, section
);
4417 start
+= encoded_ptr_size
;
4418 fc
->pc_range
= byte_get (start
, encoded_ptr_size
);
4419 start
+= encoded_ptr_size
;
4421 if (cie
->augmentation
[0] == 'z')
4423 augmentation_data_len
= LEB ();
4424 augmentation_data
= start
;
4425 start
+= augmentation_data_len
;
4428 printf ("\n%08lx %08lx %08lx FDE cie=%08lx pc=",
4429 (unsigned long)(saved_start
- section_start
), length
, cie_id
,
4430 (unsigned long)(cie
->chunk_start
- section_start
));
4431 if (fc
->segment_size
)
4432 printf ("%04lx:", segment_selector
);
4433 printf ("%08lx..%08lx\n", fc
->pc_begin
, fc
->pc_begin
+ fc
->pc_range
);
4434 if (! do_debug_frames_interp
&& augmentation_data_len
)
4438 printf (" Augmentation data: ");
4439 for (i
= 0; i
< augmentation_data_len
; ++i
)
4440 printf (" %02x", augmentation_data
[i
]);
4446 /* At this point, fc is the current chunk, cie (if any) is set, and
4447 we're about to interpret instructions for the chunk. */
4448 /* ??? At present we need to do this always, since this sizes the
4449 fc->col_type and fc->col_offset arrays, which we write into always.
4450 We should probably split the interpreted and non-interpreted bits
4451 into two different routines, since there's so much that doesn't
4452 really overlap between them. */
4453 if (1 || do_debug_frames_interp
)
4455 /* Start by making a pass over the chunk, allocating storage
4456 and taking note of what registers are used. */
4457 unsigned char *tmp
= start
;
4459 while (start
< block_end
)
4462 unsigned long reg
, temp
;
4469 /* Warning: if you add any more cases to this switch, be
4470 sure to add them to the corresponding switch below. */
4473 case DW_CFA_advance_loc
:
4477 if (frame_need_space (fc
, opa
) >= 0)
4478 fc
->col_type
[opa
] = DW_CFA_undefined
;
4480 case DW_CFA_restore
:
4481 if (frame_need_space (fc
, opa
) >= 0)
4482 fc
->col_type
[opa
] = DW_CFA_undefined
;
4484 case DW_CFA_set_loc
:
4485 start
+= encoded_ptr_size
;
4487 case DW_CFA_advance_loc1
:
4490 case DW_CFA_advance_loc2
:
4493 case DW_CFA_advance_loc4
:
4496 case DW_CFA_offset_extended
:
4497 case DW_CFA_val_offset
:
4498 reg
= LEB (); LEB ();
4499 if (frame_need_space (fc
, reg
) >= 0)
4500 fc
->col_type
[reg
] = DW_CFA_undefined
;
4502 case DW_CFA_restore_extended
:
4504 frame_need_space (fc
, reg
);
4505 if (frame_need_space (fc
, reg
) >= 0)
4506 fc
->col_type
[reg
] = DW_CFA_undefined
;
4508 case DW_CFA_undefined
:
4510 if (frame_need_space (fc
, reg
) >= 0)
4511 fc
->col_type
[reg
] = DW_CFA_undefined
;
4513 case DW_CFA_same_value
:
4515 if (frame_need_space (fc
, reg
) >= 0)
4516 fc
->col_type
[reg
] = DW_CFA_undefined
;
4518 case DW_CFA_register
:
4519 reg
= LEB (); LEB ();
4520 if (frame_need_space (fc
, reg
) >= 0)
4521 fc
->col_type
[reg
] = DW_CFA_undefined
;
4523 case DW_CFA_def_cfa
:
4526 case DW_CFA_def_cfa_register
:
4529 case DW_CFA_def_cfa_offset
:
4532 case DW_CFA_def_cfa_expression
:
4536 case DW_CFA_expression
:
4537 case DW_CFA_val_expression
:
4541 if (frame_need_space (fc
, reg
) >= 0)
4542 fc
->col_type
[reg
] = DW_CFA_undefined
;
4544 case DW_CFA_offset_extended_sf
:
4545 case DW_CFA_val_offset_sf
:
4546 reg
= LEB (); SLEB ();
4547 if (frame_need_space (fc
, reg
) >= 0)
4548 fc
->col_type
[reg
] = DW_CFA_undefined
;
4550 case DW_CFA_def_cfa_sf
:
4553 case DW_CFA_def_cfa_offset_sf
:
4556 case DW_CFA_MIPS_advance_loc8
:
4559 case DW_CFA_GNU_args_size
:
4562 case DW_CFA_GNU_negative_offset_extended
:
4563 reg
= LEB (); LEB ();
4564 if (frame_need_space (fc
, reg
) >= 0)
4565 fc
->col_type
[reg
] = DW_CFA_undefined
;
4574 /* Now we know what registers are used, make a second pass over
4575 the chunk, this time actually printing out the info. */
4577 while (start
< block_end
)
4580 unsigned long ul
, reg
, roffs
;
4583 const char *reg_prefix
= "";
4590 /* Warning: if you add any more cases to this switch, be
4591 sure to add them to the corresponding switch above. */
4594 case DW_CFA_advance_loc
:
4595 if (do_debug_frames_interp
)
4596 frame_display_row (fc
, &need_col_headers
, &max_regs
);
4598 printf (" DW_CFA_advance_loc: %d to %08lx\n",
4599 opa
* fc
->code_factor
,
4600 fc
->pc_begin
+ opa
* fc
->code_factor
);
4601 fc
->pc_begin
+= opa
* fc
->code_factor
;
4606 if (opa
>= (unsigned int) fc
->ncols
)
4607 reg_prefix
= bad_reg
;
4608 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4609 printf (" DW_CFA_offset: %s%s at cfa%+ld\n",
4610 reg_prefix
, regname (opa
, 0),
4611 roffs
* fc
->data_factor
);
4612 if (*reg_prefix
== '\0')
4614 fc
->col_type
[opa
] = DW_CFA_offset
;
4615 fc
->col_offset
[opa
] = roffs
* fc
->data_factor
;
4619 case DW_CFA_restore
:
4620 if (opa
>= (unsigned int) cie
->ncols
4621 || opa
>= (unsigned int) fc
->ncols
)
4622 reg_prefix
= bad_reg
;
4623 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4624 printf (" DW_CFA_restore: %s%s\n",
4625 reg_prefix
, regname (opa
, 0));
4626 if (*reg_prefix
== '\0')
4628 fc
->col_type
[opa
] = cie
->col_type
[opa
];
4629 fc
->col_offset
[opa
] = cie
->col_offset
[opa
];
4633 case DW_CFA_set_loc
:
4634 vma
= get_encoded_value (start
, fc
->fde_encoding
, section
);
4635 start
+= encoded_ptr_size
;
4636 if (do_debug_frames_interp
)
4637 frame_display_row (fc
, &need_col_headers
, &max_regs
);
4639 printf (" DW_CFA_set_loc: %08lx\n", (unsigned long)vma
);
4643 case DW_CFA_advance_loc1
:
4644 ofs
= byte_get (start
, 1); start
+= 1;
4645 if (do_debug_frames_interp
)
4646 frame_display_row (fc
, &need_col_headers
, &max_regs
);
4648 printf (" DW_CFA_advance_loc1: %ld to %08lx\n",
4649 ofs
* fc
->code_factor
,
4650 fc
->pc_begin
+ ofs
* fc
->code_factor
);
4651 fc
->pc_begin
+= ofs
* fc
->code_factor
;
4654 case DW_CFA_advance_loc2
:
4655 ofs
= byte_get (start
, 2); start
+= 2;
4656 if (do_debug_frames_interp
)
4657 frame_display_row (fc
, &need_col_headers
, &max_regs
);
4659 printf (" DW_CFA_advance_loc2: %ld to %08lx\n",
4660 ofs
* fc
->code_factor
,
4661 fc
->pc_begin
+ ofs
* fc
->code_factor
);
4662 fc
->pc_begin
+= ofs
* fc
->code_factor
;
4665 case DW_CFA_advance_loc4
:
4666 ofs
= byte_get (start
, 4); start
+= 4;
4667 if (do_debug_frames_interp
)
4668 frame_display_row (fc
, &need_col_headers
, &max_regs
);
4670 printf (" DW_CFA_advance_loc4: %ld to %08lx\n",
4671 ofs
* fc
->code_factor
,
4672 fc
->pc_begin
+ ofs
* fc
->code_factor
);
4673 fc
->pc_begin
+= ofs
* fc
->code_factor
;
4676 case DW_CFA_offset_extended
:
4679 if (reg
>= (unsigned int) fc
->ncols
)
4680 reg_prefix
= bad_reg
;
4681 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4682 printf (" DW_CFA_offset_extended: %s%s at cfa%+ld\n",
4683 reg_prefix
, regname (reg
, 0),
4684 roffs
* fc
->data_factor
);
4685 if (*reg_prefix
== '\0')
4687 fc
->col_type
[reg
] = DW_CFA_offset
;
4688 fc
->col_offset
[reg
] = roffs
* fc
->data_factor
;
4692 case DW_CFA_val_offset
:
4695 if (reg
>= (unsigned int) fc
->ncols
)
4696 reg_prefix
= bad_reg
;
4697 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4698 printf (" DW_CFA_val_offset: %s%s at cfa%+ld\n",
4699 reg_prefix
, regname (reg
, 0),
4700 roffs
* fc
->data_factor
);
4701 if (*reg_prefix
== '\0')
4703 fc
->col_type
[reg
] = DW_CFA_val_offset
;
4704 fc
->col_offset
[reg
] = roffs
* fc
->data_factor
;
4708 case DW_CFA_restore_extended
:
4710 if (reg
>= (unsigned int) cie
->ncols
4711 || reg
>= (unsigned int) fc
->ncols
)
4712 reg_prefix
= bad_reg
;
4713 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4714 printf (" DW_CFA_restore_extended: %s%s\n",
4715 reg_prefix
, regname (reg
, 0));
4716 if (*reg_prefix
== '\0')
4718 fc
->col_type
[reg
] = cie
->col_type
[reg
];
4719 fc
->col_offset
[reg
] = cie
->col_offset
[reg
];
4723 case DW_CFA_undefined
:
4725 if (reg
>= (unsigned int) fc
->ncols
)
4726 reg_prefix
= bad_reg
;
4727 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4728 printf (" DW_CFA_undefined: %s%s\n",
4729 reg_prefix
, regname (reg
, 0));
4730 if (*reg_prefix
== '\0')
4732 fc
->col_type
[reg
] = DW_CFA_undefined
;
4733 fc
->col_offset
[reg
] = 0;
4737 case DW_CFA_same_value
:
4739 if (reg
>= (unsigned int) fc
->ncols
)
4740 reg_prefix
= bad_reg
;
4741 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4742 printf (" DW_CFA_same_value: %s%s\n",
4743 reg_prefix
, regname (reg
, 0));
4744 if (*reg_prefix
== '\0')
4746 fc
->col_type
[reg
] = DW_CFA_same_value
;
4747 fc
->col_offset
[reg
] = 0;
4751 case DW_CFA_register
:
4754 if (reg
>= (unsigned int) fc
->ncols
)
4755 reg_prefix
= bad_reg
;
4756 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4758 printf (" DW_CFA_register: %s%s in ",
4759 reg_prefix
, regname (reg
, 0));
4760 puts (regname (roffs
, 0));
4762 if (*reg_prefix
== '\0')
4764 fc
->col_type
[reg
] = DW_CFA_register
;
4765 fc
->col_offset
[reg
] = roffs
;
4769 case DW_CFA_remember_state
:
4770 if (! do_debug_frames_interp
)
4771 printf (" DW_CFA_remember_state\n");
4772 rs
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
4773 rs
->ncols
= fc
->ncols
;
4774 rs
->col_type
= (short int *) xcmalloc (rs
->ncols
,
4775 sizeof (short int));
4776 rs
->col_offset
= (int *) xcmalloc (rs
->ncols
, sizeof (int));
4777 memcpy (rs
->col_type
, fc
->col_type
, rs
->ncols
);
4778 memcpy (rs
->col_offset
, fc
->col_offset
, rs
->ncols
* sizeof (int));
4779 rs
->next
= remembered_state
;
4780 remembered_state
= rs
;
4783 case DW_CFA_restore_state
:
4784 if (! do_debug_frames_interp
)
4785 printf (" DW_CFA_restore_state\n");
4786 rs
= remembered_state
;
4789 remembered_state
= rs
->next
;
4790 frame_need_space (fc
, rs
->ncols
- 1);
4791 memcpy (fc
->col_type
, rs
->col_type
, rs
->ncols
);
4792 memcpy (fc
->col_offset
, rs
->col_offset
,
4793 rs
->ncols
* sizeof (int));
4794 free (rs
->col_type
);
4795 free (rs
->col_offset
);
4798 else if (do_debug_frames_interp
)
4799 printf ("Mismatched DW_CFA_restore_state\n");
4802 case DW_CFA_def_cfa
:
4803 fc
->cfa_reg
= LEB ();
4804 fc
->cfa_offset
= LEB ();
4806 if (! do_debug_frames_interp
)
4807 printf (" DW_CFA_def_cfa: %s ofs %d\n",
4808 regname (fc
->cfa_reg
, 0), fc
->cfa_offset
);
4811 case DW_CFA_def_cfa_register
:
4812 fc
->cfa_reg
= LEB ();
4814 if (! do_debug_frames_interp
)
4815 printf (" DW_CFA_def_cfa_register: %s\n",
4816 regname (fc
->cfa_reg
, 0));
4819 case DW_CFA_def_cfa_offset
:
4820 fc
->cfa_offset
= LEB ();
4821 if (! do_debug_frames_interp
)
4822 printf (" DW_CFA_def_cfa_offset: %d\n", fc
->cfa_offset
);
4826 if (! do_debug_frames_interp
)
4827 printf (" DW_CFA_nop\n");
4830 case DW_CFA_def_cfa_expression
:
4832 if (! do_debug_frames_interp
)
4834 printf (" DW_CFA_def_cfa_expression (");
4835 decode_location_expression (start
, eh_addr_size
, 0, -1,
4843 case DW_CFA_expression
:
4846 if (reg
>= (unsigned int) fc
->ncols
)
4847 reg_prefix
= bad_reg
;
4848 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4850 printf (" DW_CFA_expression: %s%s (",
4851 reg_prefix
, regname (reg
, 0));
4852 decode_location_expression (start
, eh_addr_size
, 0, -1,
4856 if (*reg_prefix
== '\0')
4857 fc
->col_type
[reg
] = DW_CFA_expression
;
4861 case DW_CFA_val_expression
:
4864 if (reg
>= (unsigned int) fc
->ncols
)
4865 reg_prefix
= bad_reg
;
4866 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4868 printf (" DW_CFA_val_expression: %s%s (",
4869 reg_prefix
, regname (reg
, 0));
4870 decode_location_expression (start
, eh_addr_size
, 0, -1,
4874 if (*reg_prefix
== '\0')
4875 fc
->col_type
[reg
] = DW_CFA_val_expression
;
4879 case DW_CFA_offset_extended_sf
:
4882 if (frame_need_space (fc
, reg
) < 0)
4883 reg_prefix
= bad_reg
;
4884 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4885 printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+ld\n",
4886 reg_prefix
, regname (reg
, 0),
4887 l
* fc
->data_factor
);
4888 if (*reg_prefix
== '\0')
4890 fc
->col_type
[reg
] = DW_CFA_offset
;
4891 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
4895 case DW_CFA_val_offset_sf
:
4898 if (frame_need_space (fc
, reg
) < 0)
4899 reg_prefix
= bad_reg
;
4900 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4901 printf (" DW_CFA_val_offset_sf: %s%s at cfa%+ld\n",
4902 reg_prefix
, regname (reg
, 0),
4903 l
* fc
->data_factor
);
4904 if (*reg_prefix
== '\0')
4906 fc
->col_type
[reg
] = DW_CFA_val_offset
;
4907 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
4911 case DW_CFA_def_cfa_sf
:
4912 fc
->cfa_reg
= LEB ();
4913 fc
->cfa_offset
= SLEB ();
4914 fc
->cfa_offset
= fc
->cfa_offset
* fc
->data_factor
;
4916 if (! do_debug_frames_interp
)
4917 printf (" DW_CFA_def_cfa_sf: %s ofs %d\n",
4918 regname (fc
->cfa_reg
, 0), fc
->cfa_offset
);
4921 case DW_CFA_def_cfa_offset_sf
:
4922 fc
->cfa_offset
= SLEB ();
4923 fc
->cfa_offset
= fc
->cfa_offset
* fc
->data_factor
;
4924 if (! do_debug_frames_interp
)
4925 printf (" DW_CFA_def_cfa_offset_sf: %d\n", fc
->cfa_offset
);
4928 case DW_CFA_MIPS_advance_loc8
:
4929 ofs
= byte_get (start
, 8); start
+= 8;
4930 if (do_debug_frames_interp
)
4931 frame_display_row (fc
, &need_col_headers
, &max_regs
);
4933 printf (" DW_CFA_MIPS_advance_loc8: %ld to %08lx\n",
4934 ofs
* fc
->code_factor
,
4935 fc
->pc_begin
+ ofs
* fc
->code_factor
);
4936 fc
->pc_begin
+= ofs
* fc
->code_factor
;
4939 case DW_CFA_GNU_window_save
:
4940 if (! do_debug_frames_interp
)
4941 printf (" DW_CFA_GNU_window_save\n");
4944 case DW_CFA_GNU_args_size
:
4946 if (! do_debug_frames_interp
)
4947 printf (" DW_CFA_GNU_args_size: %ld\n", ul
);
4950 case DW_CFA_GNU_negative_offset_extended
:
4953 if (frame_need_space (fc
, reg
) < 0)
4954 reg_prefix
= bad_reg
;
4955 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4956 printf (" DW_CFA_GNU_negative_offset_extended: %s%s at cfa%+ld\n",
4957 reg_prefix
, regname (reg
, 0),
4958 l
* fc
->data_factor
);
4959 if (*reg_prefix
== '\0')
4961 fc
->col_type
[reg
] = DW_CFA_offset
;
4962 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
4967 if (op
>= DW_CFA_lo_user
&& op
<= DW_CFA_hi_user
)
4968 printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op
);
4970 warn (_("unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op
);
4975 if (do_debug_frames_interp
)
4976 frame_display_row (fc
, &need_col_headers
, &max_regs
);
4979 eh_addr_size
= saved_eh_addr_size
;
4992 display_gdb_index (struct dwarf_section
*section
,
4993 void *file ATTRIBUTE_UNUSED
)
4995 unsigned char *start
= section
->start
;
4997 uint32_t cu_list_offset
, tu_list_offset
;
4998 uint32_t address_table_offset
, symbol_table_offset
, constant_pool_offset
;
4999 unsigned int cu_list_elements
, tu_list_elements
;
5000 unsigned int address_table_size
, symbol_table_slots
;
5001 unsigned char *cu_list
, *tu_list
;
5002 unsigned char *address_table
, *symbol_table
, *constant_pool
;
5005 /* The documentation for the format of this file is in gdb/dwarf2read.c. */
5007 printf (_("Contents of the %s section:\n"), section
->name
);
5009 if (section
->size
< 6 * sizeof (uint32_t))
5011 warn (_("Truncated header in the %s section.\n"), section
->name
);
5015 version
= byte_get_little_endian (start
, 4);
5016 printf (_("Version %ld\n"), (long) version
);
5018 /* Prior versions are obsolete, and future versions may not be
5019 backwards compatible. */
5023 warn (_("The address table data in version 3 may be wrong.\n"));
5028 warn (_("Unsupported version %lu.\n"), (unsigned long) version
);
5032 cu_list_offset
= byte_get_little_endian (start
+ 4, 4);
5033 tu_list_offset
= byte_get_little_endian (start
+ 8, 4);
5034 address_table_offset
= byte_get_little_endian (start
+ 12, 4);
5035 symbol_table_offset
= byte_get_little_endian (start
+ 16, 4);
5036 constant_pool_offset
= byte_get_little_endian (start
+ 20, 4);
5038 if (cu_list_offset
> section
->size
5039 || tu_list_offset
> section
->size
5040 || address_table_offset
> section
->size
5041 || symbol_table_offset
> section
->size
5042 || constant_pool_offset
> section
->size
)
5044 warn (_("Corrupt header in the %s section.\n"), section
->name
);
5048 cu_list_elements
= (tu_list_offset
- cu_list_offset
) / 8;
5049 tu_list_elements
= (address_table_offset
- tu_list_offset
) / 8;
5050 address_table_size
= symbol_table_offset
- address_table_offset
;
5051 symbol_table_slots
= (constant_pool_offset
- symbol_table_offset
) / 8;
5053 cu_list
= start
+ cu_list_offset
;
5054 tu_list
= start
+ tu_list_offset
;
5055 address_table
= start
+ address_table_offset
;
5056 symbol_table
= start
+ symbol_table_offset
;
5057 constant_pool
= start
+ constant_pool_offset
;
5059 printf (_("\nCU table:\n"));
5060 for (i
= 0; i
< cu_list_elements
; i
+= 2)
5062 uint64_t cu_offset
= byte_get_little_endian (cu_list
+ i
* 8, 8);
5063 uint64_t cu_length
= byte_get_little_endian (cu_list
+ i
* 8 + 8, 8);
5065 printf (_("[%3u] 0x%lx - 0x%lx\n"), i
/ 2,
5066 (unsigned long) cu_offset
,
5067 (unsigned long) (cu_offset
+ cu_length
- 1));
5070 printf (_("\nTU table:\n"));
5071 for (i
= 0; i
< tu_list_elements
; i
+= 3)
5073 uint64_t tu_offset
= byte_get_little_endian (tu_list
+ i
* 8, 8);
5074 uint64_t type_offset
= byte_get_little_endian (tu_list
+ i
* 8 + 8, 8);
5075 uint64_t signature
= byte_get_little_endian (tu_list
+ i
* 8 + 16, 8);
5077 printf (_("[%3u] 0x%lx 0x%lx "), i
/ 3,
5078 (unsigned long) tu_offset
,
5079 (unsigned long) type_offset
);
5080 print_dwarf_vma (signature
, 8);
5084 printf (_("\nAddress table:\n"));
5085 for (i
= 0; i
< address_table_size
; i
+= 2 * 8 + 4)
5087 uint64_t low
= byte_get_little_endian (address_table
+ i
, 8);
5088 uint64_t high
= byte_get_little_endian (address_table
+ i
+ 8, 8);
5089 uint32_t cu_index
= byte_get_little_endian (address_table
+ i
+ 16, 4);
5091 print_dwarf_vma (low
, 8);
5092 print_dwarf_vma (high
, 8);
5093 printf (_("%lu\n"), (unsigned long) cu_index
);
5096 printf (_("\nSymbol table:\n"));
5097 for (i
= 0; i
< symbol_table_slots
; ++i
)
5099 uint32_t name_offset
= byte_get_little_endian (symbol_table
+ i
* 8, 4);
5100 uint32_t cu_vector_offset
= byte_get_little_endian (symbol_table
+ i
* 8 + 4, 4);
5101 uint32_t num_cus
, cu
;
5103 if (name_offset
!= 0
5104 || cu_vector_offset
!= 0)
5108 printf ("[%3u] %s:", i
, constant_pool
+ name_offset
);
5109 num_cus
= byte_get_little_endian (constant_pool
+ cu_vector_offset
, 4);
5110 for (j
= 0; j
< num_cus
; ++j
)
5112 cu
= byte_get_little_endian (constant_pool
+ cu_vector_offset
+ 4 + j
* 4, 4);
5113 /* Convert to TU number if it's for a type unit. */
5114 if (cu
>= cu_list_elements
)
5115 printf (" T%lu", (unsigned long) (cu
- cu_list_elements
));
5117 printf (" %lu", (unsigned long) cu
);
5127 display_debug_not_supported (struct dwarf_section
*section
,
5128 void *file ATTRIBUTE_UNUSED
)
5130 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
5137 cmalloc (size_t nmemb
, size_t size
)
5139 /* Check for overflow. */
5140 if (nmemb
>= ~(size_t) 0 / size
)
5143 return malloc (nmemb
* size
);
5147 xcmalloc (size_t nmemb
, size_t size
)
5149 /* Check for overflow. */
5150 if (nmemb
>= ~(size_t) 0 / size
)
5153 return xmalloc (nmemb
* size
);
5157 xcrealloc (void *ptr
, size_t nmemb
, size_t size
)
5159 /* Check for overflow. */
5160 if (nmemb
>= ~(size_t) 0 / size
)
5163 return xrealloc (ptr
, nmemb
* size
);
5167 free_debug_memory (void)
5173 for (i
= 0; i
< max
; i
++)
5174 free_debug_section ((enum dwarf_section_display_enum
) i
);
5176 if (debug_information
!= NULL
)
5178 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
)
5180 for (i
= 0; i
< num_debug_info_entries
; i
++)
5182 if (!debug_information
[i
].max_loc_offsets
)
5184 free (debug_information
[i
].loc_offsets
);
5185 free (debug_information
[i
].have_frame_base
);
5187 if (!debug_information
[i
].max_range_lists
)
5188 free (debug_information
[i
].range_lists
);
5192 free (debug_information
);
5193 debug_information
= NULL
;
5194 num_debug_info_entries
= 0;
5199 dwarf_select_sections_by_names (const char *names
)
5203 const char * option
;
5207 debug_dump_long_opts
;
5209 static const debug_dump_long_opts opts_table
[] =
5211 /* Please keep this table alpha- sorted. */
5212 { "Ranges", & do_debug_ranges
, 1 },
5213 { "abbrev", & do_debug_abbrevs
, 1 },
5214 { "aranges", & do_debug_aranges
, 1 },
5215 { "frames", & do_debug_frames
, 1 },
5216 { "frames-interp", & do_debug_frames_interp
, 1 },
5217 { "info", & do_debug_info
, 1 },
5218 { "line", & do_debug_lines
, FLAG_DEBUG_LINES_RAW
}, /* For backwards compatibility. */
5219 { "rawline", & do_debug_lines
, FLAG_DEBUG_LINES_RAW
},
5220 { "decodedline", & do_debug_lines
, FLAG_DEBUG_LINES_DECODED
},
5221 { "loc", & do_debug_loc
, 1 },
5222 { "macro", & do_debug_macinfo
, 1 },
5223 { "pubnames", & do_debug_pubnames
, 1 },
5224 { "pubtypes", & do_debug_pubtypes
, 1 },
5225 /* This entry is for compatability
5226 with earlier versions of readelf. */
5227 { "ranges", & do_debug_aranges
, 1 },
5228 { "str", & do_debug_str
, 1 },
5229 /* The special .gdb_index section. */
5230 { "gdb_index", & do_gdb_index
, 1 },
5231 /* These trace_* sections are used by Itanium VMS. */
5232 { "trace_abbrev", & do_trace_abbrevs
, 1 },
5233 { "trace_aranges", & do_trace_aranges
, 1 },
5234 { "trace_info", & do_trace_info
, 1 },
5243 const debug_dump_long_opts
* entry
;
5245 for (entry
= opts_table
; entry
->option
; entry
++)
5247 size_t len
= strlen (entry
->option
);
5249 if (strncmp (p
, entry
->option
, len
) == 0
5250 && (p
[len
] == ',' || p
[len
] == '\0'))
5252 * entry
->variable
|= entry
->val
;
5254 /* The --debug-dump=frames-interp option also
5255 enables the --debug-dump=frames option. */
5256 if (do_debug_frames_interp
)
5257 do_debug_frames
= 1;
5264 if (entry
->option
== NULL
)
5266 warn (_("Unrecognized debug option '%s'\n"), p
);
5267 p
= strchr (p
, ',');
5278 dwarf_select_sections_by_letters (const char *letters
)
5280 unsigned int lindex
= 0;
5282 while (letters
[lindex
])
5283 switch (letters
[lindex
++])
5290 do_debug_abbrevs
= 1;
5294 do_debug_lines
|= FLAG_DEBUG_LINES_RAW
;
5298 do_debug_lines
|= FLAG_DEBUG_LINES_DECODED
;
5302 do_debug_pubnames
= 1;
5306 do_debug_pubtypes
= 1;
5310 do_debug_aranges
= 1;
5314 do_debug_ranges
= 1;
5318 do_debug_frames_interp
= 1;
5320 do_debug_frames
= 1;
5324 do_debug_macinfo
= 1;
5336 warn (_("Unrecognized debug option '%s'\n"), optarg
);
5342 dwarf_select_sections_all (void)
5345 do_debug_abbrevs
= 1;
5346 do_debug_lines
= FLAG_DEBUG_LINES_RAW
;
5347 do_debug_pubnames
= 1;
5348 do_debug_pubtypes
= 1;
5349 do_debug_aranges
= 1;
5350 do_debug_ranges
= 1;
5351 do_debug_frames
= 1;
5352 do_debug_macinfo
= 1;
5357 do_trace_abbrevs
= 1;
5358 do_trace_aranges
= 1;
5361 struct dwarf_section_display debug_displays
[] =
5363 { { ".debug_abbrev", ".zdebug_abbrev", NULL
, NULL
, 0, 0 },
5364 display_debug_abbrev
, &do_debug_abbrevs
, 0 },
5365 { { ".debug_aranges", ".zdebug_aranges", NULL
, NULL
, 0, 0 },
5366 display_debug_aranges
, &do_debug_aranges
, 1 },
5367 { { ".debug_frame", ".zdebug_frame", NULL
, NULL
, 0, 0 },
5368 display_debug_frames
, &do_debug_frames
, 1 },
5369 { { ".debug_info", ".zdebug_info", NULL
, NULL
, 0, 0 },
5370 display_debug_info
, &do_debug_info
, 1 },
5371 { { ".debug_line", ".zdebug_line", NULL
, NULL
, 0, 0 },
5372 display_debug_lines
, &do_debug_lines
, 1 },
5373 { { ".debug_pubnames", ".zdebug_pubnames", NULL
, NULL
, 0, 0 },
5374 display_debug_pubnames
, &do_debug_pubnames
, 0 },
5375 { { ".eh_frame", "", NULL
, NULL
, 0, 0 },
5376 display_debug_frames
, &do_debug_frames
, 1 },
5377 { { ".debug_macinfo", ".zdebug_macinfo", NULL
, NULL
, 0, 0 },
5378 display_debug_macinfo
, &do_debug_macinfo
, 0 },
5379 { { ".debug_str", ".zdebug_str", NULL
, NULL
, 0, 0 },
5380 display_debug_str
, &do_debug_str
, 0 },
5381 { { ".debug_loc", ".zdebug_loc", NULL
, NULL
, 0, 0 },
5382 display_debug_loc
, &do_debug_loc
, 1 },
5383 { { ".debug_pubtypes", ".zdebug_pubtypes", NULL
, NULL
, 0, 0 },
5384 display_debug_pubnames
, &do_debug_pubtypes
, 0 },
5385 { { ".debug_ranges", ".zdebug_ranges", NULL
, NULL
, 0, 0 },
5386 display_debug_ranges
, &do_debug_ranges
, 1 },
5387 { { ".debug_static_func", ".zdebug_static_func", NULL
, NULL
, 0, 0 },
5388 display_debug_not_supported
, NULL
, 0 },
5389 { { ".debug_static_vars", ".zdebug_static_vars", NULL
, NULL
, 0, 0 },
5390 display_debug_not_supported
, NULL
, 0 },
5391 { { ".debug_types", ".zdebug_types", NULL
, NULL
, 0, 0 },
5392 display_debug_types
, &do_debug_info
, 1 },
5393 { { ".debug_weaknames", ".zdebug_weaknames", NULL
, NULL
, 0, 0 },
5394 display_debug_not_supported
, NULL
, 0 },
5395 { { ".gdb_index", "", NULL
, NULL
, 0, 0 },
5396 display_gdb_index
, &do_gdb_index
, 0 },
5397 { { ".trace_info", "", NULL
, NULL
, 0, 0 },
5398 display_trace_info
, &do_trace_info
, 1 },
5399 { { ".trace_abbrev", "", NULL
, NULL
, 0, 0 },
5400 display_debug_abbrev
, &do_trace_abbrevs
, 0 },
5401 { { ".trace_aranges", "", NULL
, NULL
, 0, 0 },
5402 display_debug_aranges
, &do_trace_aranges
, 0 }