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: %lx",
678 (unsigned long) 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
1929 unsigned long length
;
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 (%lx) found in section %s\n"), length
, section
->name
);
1951 section_begin
+= length
+ 4;
1953 /* Negative values are illegal, they may even cause infinite
1954 looping. This can happen if we can't accurately apply
1955 relocations to an object file. */
1956 if ((signed long) length
<= 0)
1958 warn (_("Corrupt unit length (%lx) found in section %s\n"), length
, section
->name
);
1965 error (_("No comp units in %s section ?"), section
->name
);
1969 /* Then allocate an array to hold the information. */
1970 debug_information
= (debug_info
*) cmalloc (num_units
,
1971 sizeof (* debug_information
));
1972 if (debug_information
== NULL
)
1974 error (_("Not enough memory for a debug info array of %u entries"),
1982 printf (_("Contents of the %s section:\n\n"), section
->name
);
1984 load_debug_section (str
, file
);
1987 load_debug_section (abbrev_sec
, file
);
1988 if (debug_displays
[abbrev_sec
].section
.start
== NULL
)
1990 warn (_("Unable to locate %s section!\n"),
1991 debug_displays
[abbrev_sec
].section
.name
);
1995 for (section_begin
= start
, unit
= 0; start
< end
; unit
++)
1997 DWARF2_Internal_CompUnit compunit
;
1998 unsigned char *hdrptr
;
1999 unsigned char *tags
;
2001 dwarf_vma cu_offset
;
2003 int initial_length_size
;
2004 unsigned char signature
[8] = { 0 };
2005 unsigned long type_offset
= 0;
2009 compunit
.cu_length
= byte_get (hdrptr
, 4);
2012 if (compunit
.cu_length
== 0xffffffff)
2014 compunit
.cu_length
= byte_get (hdrptr
, 8);
2017 initial_length_size
= 12;
2022 initial_length_size
= 4;
2025 compunit
.cu_version
= byte_get (hdrptr
, 2);
2028 cu_offset
= start
- section_begin
;
2030 compunit
.cu_abbrev_offset
= byte_get (hdrptr
, offset_size
);
2031 hdrptr
+= offset_size
;
2033 compunit
.cu_pointer_size
= byte_get (hdrptr
, 1);
2040 for (i
= 0; i
< 8; i
++)
2042 signature
[i
] = byte_get (hdrptr
, 1);
2046 type_offset
= byte_get (hdrptr
, offset_size
);
2047 hdrptr
+= offset_size
;
2050 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
2051 && num_debug_info_entries
== 0
2054 debug_information
[unit
].cu_offset
= cu_offset
;
2055 debug_information
[unit
].pointer_size
2056 = compunit
.cu_pointer_size
;
2057 debug_information
[unit
].offset_size
= offset_size
;
2058 debug_information
[unit
].dwarf_version
= compunit
.cu_version
;
2059 debug_information
[unit
].base_address
= 0;
2060 debug_information
[unit
].loc_offsets
= NULL
;
2061 debug_information
[unit
].have_frame_base
= NULL
;
2062 debug_information
[unit
].max_loc_offsets
= 0;
2063 debug_information
[unit
].num_loc_offsets
= 0;
2064 debug_information
[unit
].range_lists
= NULL
;
2065 debug_information
[unit
].max_range_lists
= 0;
2066 debug_information
[unit
].num_range_lists
= 0;
2071 printf (_(" Compilation Unit @ offset 0x%s:\n"),
2072 dwarf_vmatoa ("x", cu_offset
));
2073 printf (_(" Length: 0x%s (%s)\n"),
2074 dwarf_vmatoa ("x", compunit
.cu_length
),
2075 initial_length_size
== 8 ? "64-bit" : "32-bit");
2076 printf (_(" Version: %d\n"), compunit
.cu_version
);
2077 printf (_(" Abbrev Offset: %s\n"),
2078 dwarf_vmatoa ("d", compunit
.cu_abbrev_offset
));
2079 printf (_(" Pointer Size: %d\n"), compunit
.cu_pointer_size
);
2083 printf (_(" Signature: "));
2084 for (i
= 0; i
< 8; i
++)
2085 printf ("%02x", signature
[i
]);
2087 printf (_(" Type Offset: 0x%lx\n"), type_offset
);
2091 if (cu_offset
+ compunit
.cu_length
+ initial_length_size
2094 warn (_("Debug info is corrupted, length of CU at %s"
2095 " extends beyond end of section (length = %s)\n"),
2096 dwarf_vmatoa ("x", cu_offset
),
2097 dwarf_vmatoa ("x", compunit
.cu_length
));
2101 start
+= compunit
.cu_length
+ initial_length_size
;
2103 if (compunit
.cu_version
!= 2
2104 && compunit
.cu_version
!= 3
2105 && compunit
.cu_version
!= 4)
2107 warn (_("CU at offset %s contains corrupt or "
2108 "unsupported version number: %d.\n"),
2109 dwarf_vmatoa ("x", cu_offset
), compunit
.cu_version
);
2115 /* Process the abbrevs used by this compilation unit. DWARF
2116 sections under Mach-O have non-zero addresses. */
2117 if (compunit
.cu_abbrev_offset
>= debug_displays
[abbrev_sec
].section
.size
)
2118 warn (_("Debug info is corrupted, abbrev offset (%lx) is larger than abbrev section size (%lx)\n"),
2119 (unsigned long) compunit
.cu_abbrev_offset
,
2120 (unsigned long) debug_displays
[abbrev_sec
].section
.size
);
2122 process_abbrev_section
2123 ((unsigned char *) debug_displays
[abbrev_sec
].section
.start
2124 + compunit
.cu_abbrev_offset
,
2125 (unsigned char *) debug_displays
[abbrev_sec
].section
.start
2126 + debug_displays
[abbrev_sec
].section
.size
);
2129 while (tags
< start
)
2131 unsigned int bytes_read
;
2132 unsigned long abbrev_number
;
2133 unsigned long die_offset
;
2134 abbrev_entry
*entry
;
2137 die_offset
= tags
- section_begin
;
2139 abbrev_number
= read_leb128 (tags
, & bytes_read
, 0);
2142 /* A null DIE marks the end of a list of siblings or it may also be
2143 a section padding. */
2144 if (abbrev_number
== 0)
2146 /* Check if it can be a section padding for the last CU. */
2147 if (level
== 0 && start
== end
)
2151 for (chk
= tags
; chk
< start
; chk
++)
2161 static unsigned num_bogus_warns
= 0;
2163 if (num_bogus_warns
< 3)
2165 warn (_("Bogus end-of-siblings marker detected at offset %lx in .debug_info section\n"),
2168 if (num_bogus_warns
== 3)
2169 warn (_("Further warnings about bogus end-of-sibling markers suppressed\n"));
2176 printf (_(" <%d><%lx>: Abbrev Number: %lu"),
2177 level
, die_offset
, abbrev_number
);
2179 /* Scan through the abbreviation list until we reach the
2181 for (entry
= first_abbrev
;
2182 entry
&& entry
->entry
!= abbrev_number
;
2183 entry
= entry
->next
)
2193 warn (_("DIE at offset %lx refers to abbreviation number %lu which does not exist\n"),
2194 die_offset
, abbrev_number
);
2199 printf (" (%s)\n", get_TAG_name (entry
->tag
));
2204 need_base_address
= 0;
2206 case DW_TAG_compile_unit
:
2207 need_base_address
= 1;
2209 case DW_TAG_entry_point
:
2210 case DW_TAG_subprogram
:
2211 need_base_address
= 0;
2212 /* Assuming that there is no DW_AT_frame_base. */
2213 have_frame_base
= 0;
2217 for (attr
= entry
->first_attr
; attr
; attr
= attr
->next
)
2220 /* Show the offset from where the tag was extracted. */
2221 printf (" <%2lx>", (unsigned long)(tags
- section_begin
));
2223 tags
= read_and_display_attr (attr
->attribute
,
2226 compunit
.cu_pointer_size
,
2228 compunit
.cu_version
,
2229 debug_information
+ unit
,
2233 if (entry
->children
)
2238 /* Set num_debug_info_entries here so that it can be used to check if
2239 we need to process .debug_loc and .debug_ranges sections. */
2240 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
2241 && num_debug_info_entries
== 0
2243 num_debug_info_entries
= num_units
;
2251 /* Locate and scan the .debug_info section in the file and record the pointer
2252 sizes and offsets for the compilation units in it. Usually an executable
2253 will have just one pointer size, but this is not guaranteed, and so we try
2254 not to make any assumptions. Returns zero upon failure, or the number of
2255 compilation units upon success. */
2258 load_debug_info (void * file
)
2260 /* Reset the last pointer size so that we can issue correct error
2261 messages if we are displaying the contents of more than one section. */
2262 last_pointer_size
= 0;
2263 warned_about_missing_comp_units
= FALSE
;
2265 /* If we have already tried and failed to load the .debug_info
2266 section then do not bother to repear the task. */
2267 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
2270 /* If we already have the information there is nothing else to do. */
2271 if (num_debug_info_entries
> 0)
2272 return num_debug_info_entries
;
2274 if (load_debug_section (info
, file
)
2275 && process_debug_info (&debug_displays
[info
].section
, file
, abbrev
, 1, 0))
2276 return num_debug_info_entries
;
2278 num_debug_info_entries
= DEBUG_INFO_UNAVAILABLE
;
2283 display_debug_lines_raw (struct dwarf_section
*section
,
2284 unsigned char *data
,
2287 unsigned char *start
= section
->start
;
2289 printf (_("Raw dump of debug contents of section %s:\n\n"),
2294 DWARF2_Internal_LineInfo linfo
;
2295 unsigned char *standard_opcodes
;
2296 unsigned char *end_of_sequence
;
2297 unsigned char *hdrptr
;
2298 unsigned long hdroff
;
2299 int initial_length_size
;
2304 hdroff
= hdrptr
- start
;
2306 /* Check the length of the block. */
2307 linfo
.li_length
= byte_get (hdrptr
, 4);
2310 if (linfo
.li_length
== 0xffffffff)
2312 /* This section is 64-bit DWARF 3. */
2313 linfo
.li_length
= byte_get (hdrptr
, 8);
2316 initial_length_size
= 12;
2321 initial_length_size
= 4;
2324 if (linfo
.li_length
+ initial_length_size
> section
->size
)
2327 (_("The information in section %s appears to be corrupt - the section is too small\n"),
2332 /* Check its version number. */
2333 linfo
.li_version
= byte_get (hdrptr
, 2);
2335 if (linfo
.li_version
!= 2
2336 && linfo
.li_version
!= 3
2337 && linfo
.li_version
!= 4)
2339 warn (_("Only DWARF version 2, 3 and 4 line info is currently supported.\n"));
2343 linfo
.li_prologue_length
= byte_get (hdrptr
, offset_size
);
2344 hdrptr
+= offset_size
;
2345 linfo
.li_min_insn_length
= byte_get (hdrptr
, 1);
2347 if (linfo
.li_version
>= 4)
2349 linfo
.li_max_ops_per_insn
= byte_get (hdrptr
, 1);
2351 if (linfo
.li_max_ops_per_insn
== 0)
2353 warn (_("Invalid maximum operations per insn.\n"));
2358 linfo
.li_max_ops_per_insn
= 1;
2359 linfo
.li_default_is_stmt
= byte_get (hdrptr
, 1);
2361 linfo
.li_line_base
= byte_get (hdrptr
, 1);
2363 linfo
.li_line_range
= byte_get (hdrptr
, 1);
2365 linfo
.li_opcode_base
= byte_get (hdrptr
, 1);
2368 /* Sign extend the line base field. */
2369 linfo
.li_line_base
<<= 24;
2370 linfo
.li_line_base
>>= 24;
2372 printf (_(" Offset: 0x%lx\n"), hdroff
);
2373 printf (_(" Length: %ld\n"), (long) linfo
.li_length
);
2374 printf (_(" DWARF Version: %d\n"), linfo
.li_version
);
2375 printf (_(" Prologue Length: %d\n"), linfo
.li_prologue_length
);
2376 printf (_(" Minimum Instruction Length: %d\n"), linfo
.li_min_insn_length
);
2377 if (linfo
.li_version
>= 4)
2378 printf (_(" Maximum Ops per Instruction: %d\n"), linfo
.li_max_ops_per_insn
);
2379 printf (_(" Initial value of 'is_stmt': %d\n"), linfo
.li_default_is_stmt
);
2380 printf (_(" Line Base: %d\n"), linfo
.li_line_base
);
2381 printf (_(" Line Range: %d\n"), linfo
.li_line_range
);
2382 printf (_(" Opcode Base: %d\n"), linfo
.li_opcode_base
);
2384 end_of_sequence
= data
+ linfo
.li_length
+ initial_length_size
;
2386 reset_state_machine (linfo
.li_default_is_stmt
);
2388 /* Display the contents of the Opcodes table. */
2389 standard_opcodes
= hdrptr
;
2391 printf (_("\n Opcodes:\n"));
2393 for (i
= 1; i
< linfo
.li_opcode_base
; i
++)
2394 printf (_(" Opcode %d has %d args\n"), i
, standard_opcodes
[i
- 1]);
2396 /* Display the contents of the Directory table. */
2397 data
= standard_opcodes
+ linfo
.li_opcode_base
- 1;
2400 printf (_("\n The Directory Table is empty.\n"));
2403 printf (_("\n The Directory Table:\n"));
2407 printf (" %s\n", data
);
2409 data
+= strlen ((char *) data
) + 1;
2413 /* Skip the NUL at the end of the table. */
2416 /* Display the contents of the File Name table. */
2418 printf (_("\n The File Name Table is empty.\n"));
2421 printf (_("\n The File Name Table:\n"));
2422 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
2426 unsigned char *name
;
2427 unsigned int bytes_read
;
2429 printf (" %d\t", ++state_machine_regs
.last_file_entry
);
2432 data
+= strlen ((char *) data
) + 1;
2435 dwarf_vmatoa ("u", read_leb128 (data
, & bytes_read
, 0)));
2438 dwarf_vmatoa ("u", read_leb128 (data
, & bytes_read
, 0)));
2441 dwarf_vmatoa ("u", read_leb128 (data
, & bytes_read
, 0)));
2443 printf ("%s\n", name
);
2447 /* Skip the NUL at the end of the table. */
2450 /* Now display the statements. */
2451 printf (_("\n Line Number Statements:\n"));
2453 while (data
< end_of_sequence
)
2455 unsigned char op_code
;
2456 dwarf_signed_vma adv
;
2458 unsigned int bytes_read
;
2462 if (op_code
>= linfo
.li_opcode_base
)
2464 op_code
-= linfo
.li_opcode_base
;
2465 uladv
= (op_code
/ linfo
.li_line_range
);
2466 if (linfo
.li_max_ops_per_insn
== 1)
2468 uladv
*= linfo
.li_min_insn_length
;
2469 state_machine_regs
.address
+= uladv
;
2470 printf (_(" Special opcode %d: "
2471 "advance Address by %s to 0x%s"),
2472 op_code
, dwarf_vmatoa ("u", uladv
),
2473 dwarf_vmatoa ("x", state_machine_regs
.address
));
2477 state_machine_regs
.address
2478 += ((state_machine_regs
.op_index
+ uladv
)
2479 / linfo
.li_max_ops_per_insn
)
2480 * linfo
.li_min_insn_length
;
2481 state_machine_regs
.op_index
2482 = (state_machine_regs
.op_index
+ uladv
)
2483 % linfo
.li_max_ops_per_insn
;
2484 printf (_(" Special opcode %d: "
2485 "advance Address by %s to 0x%s[%d]"),
2486 op_code
, dwarf_vmatoa ("u", uladv
),
2487 dwarf_vmatoa ("x", state_machine_regs
.address
),
2488 state_machine_regs
.op_index
);
2490 adv
= (op_code
% linfo
.li_line_range
) + linfo
.li_line_base
;
2491 state_machine_regs
.line
+= adv
;
2492 printf (_(" and Line by %s to %d\n"),
2493 dwarf_vmatoa ("d", adv
), state_machine_regs
.line
);
2495 else switch (op_code
)
2497 case DW_LNS_extended_op
:
2498 data
+= process_extended_line_op (data
, linfo
.li_default_is_stmt
);
2502 printf (_(" Copy\n"));
2505 case DW_LNS_advance_pc
:
2506 uladv
= read_leb128 (data
, & bytes_read
, 0);
2508 if (linfo
.li_max_ops_per_insn
== 1)
2510 uladv
*= linfo
.li_min_insn_length
;
2511 state_machine_regs
.address
+= uladv
;
2512 printf (_(" Advance PC by %s to 0x%s\n"),
2513 dwarf_vmatoa ("u", uladv
),
2514 dwarf_vmatoa ("x", state_machine_regs
.address
));
2518 state_machine_regs
.address
2519 += ((state_machine_regs
.op_index
+ uladv
)
2520 / linfo
.li_max_ops_per_insn
)
2521 * linfo
.li_min_insn_length
;
2522 state_machine_regs
.op_index
2523 = (state_machine_regs
.op_index
+ uladv
)
2524 % linfo
.li_max_ops_per_insn
;
2525 printf (_(" Advance PC by %s to 0x%s[%d]\n"),
2526 dwarf_vmatoa ("u", uladv
),
2527 dwarf_vmatoa ("x", state_machine_regs
.address
),
2528 state_machine_regs
.op_index
);
2532 case DW_LNS_advance_line
:
2533 adv
= read_sleb128 (data
, & bytes_read
);
2535 state_machine_regs
.line
+= adv
;
2536 printf (_(" Advance Line by %s to %d\n"),
2537 dwarf_vmatoa ("d", adv
),
2538 state_machine_regs
.line
);
2541 case DW_LNS_set_file
:
2542 adv
= read_leb128 (data
, & bytes_read
, 0);
2544 printf (_(" Set File Name to entry %s in the File Name Table\n"),
2545 dwarf_vmatoa ("d", adv
));
2546 state_machine_regs
.file
= adv
;
2549 case DW_LNS_set_column
:
2550 uladv
= read_leb128 (data
, & bytes_read
, 0);
2552 printf (_(" Set column to %s\n"),
2553 dwarf_vmatoa ("u", uladv
));
2554 state_machine_regs
.column
= uladv
;
2557 case DW_LNS_negate_stmt
:
2558 adv
= state_machine_regs
.is_stmt
;
2560 printf (_(" Set is_stmt to %s\n"), dwarf_vmatoa ("d", adv
));
2561 state_machine_regs
.is_stmt
= adv
;
2564 case DW_LNS_set_basic_block
:
2565 printf (_(" Set basic block\n"));
2566 state_machine_regs
.basic_block
= 1;
2569 case DW_LNS_const_add_pc
:
2570 uladv
= ((255 - linfo
.li_opcode_base
) / linfo
.li_line_range
);
2571 if (linfo
.li_max_ops_per_insn
)
2573 uladv
*= linfo
.li_min_insn_length
;
2574 state_machine_regs
.address
+= uladv
;
2575 printf (_(" Advance PC by constant %s to 0x%s\n"),
2576 dwarf_vmatoa ("u", uladv
),
2577 dwarf_vmatoa ("x", state_machine_regs
.address
));
2581 state_machine_regs
.address
2582 += ((state_machine_regs
.op_index
+ uladv
)
2583 / linfo
.li_max_ops_per_insn
)
2584 * linfo
.li_min_insn_length
;
2585 state_machine_regs
.op_index
2586 = (state_machine_regs
.op_index
+ uladv
)
2587 % linfo
.li_max_ops_per_insn
;
2588 printf (_(" Advance PC by constant %s to 0x%s[%d]\n"),
2589 dwarf_vmatoa ("u", uladv
),
2590 dwarf_vmatoa ("x", state_machine_regs
.address
),
2591 state_machine_regs
.op_index
);
2595 case DW_LNS_fixed_advance_pc
:
2596 uladv
= byte_get (data
, 2);
2598 state_machine_regs
.address
+= uladv
;
2599 state_machine_regs
.op_index
= 0;
2600 printf (_(" Advance PC by fixed size amount %s to 0x%s\n"),
2601 dwarf_vmatoa ("u", uladv
),
2602 dwarf_vmatoa ("x", state_machine_regs
.address
));
2605 case DW_LNS_set_prologue_end
:
2606 printf (_(" Set prologue_end to true\n"));
2609 case DW_LNS_set_epilogue_begin
:
2610 printf (_(" Set epilogue_begin to true\n"));
2613 case DW_LNS_set_isa
:
2614 uladv
= read_leb128 (data
, & bytes_read
, 0);
2616 printf (_(" Set ISA to %s\n"), dwarf_vmatoa ("u", uladv
));
2620 printf (_(" Unknown opcode %d with operands: "), op_code
);
2622 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
2624 printf ("0x%s%s", dwarf_vmatoa ("x", read_leb128 (data
,
2626 i
== 1 ? "" : ", ");
2641 unsigned char *name
;
2642 unsigned int directory_index
;
2643 unsigned int modification_date
;
2644 unsigned int length
;
2647 /* Output a decoded representation of the .debug_line section. */
2650 display_debug_lines_decoded (struct dwarf_section
*section
,
2651 unsigned char *data
,
2654 printf (_("Decoded dump of debug contents of section %s:\n\n"),
2659 /* This loop amounts to one iteration per compilation unit. */
2660 DWARF2_Internal_LineInfo linfo
;
2661 unsigned char *standard_opcodes
;
2662 unsigned char *end_of_sequence
;
2663 unsigned char *hdrptr
;
2664 int initial_length_size
;
2667 File_Entry
*file_table
= NULL
;
2668 unsigned char **directory_table
= NULL
;
2672 /* Extract information from the Line Number Program Header.
2673 (section 6.2.4 in the Dwarf3 doc). */
2675 /* Get the length of this CU's line number information block. */
2676 linfo
.li_length
= byte_get (hdrptr
, 4);
2679 if (linfo
.li_length
== 0xffffffff)
2681 /* This section is 64-bit DWARF 3. */
2682 linfo
.li_length
= byte_get (hdrptr
, 8);
2685 initial_length_size
= 12;
2690 initial_length_size
= 4;
2693 if (linfo
.li_length
+ initial_length_size
> section
->size
)
2695 warn (_("The line info appears to be corrupt - "
2696 "the section is too small\n"));
2700 /* Get this CU's Line Number Block version number. */
2701 linfo
.li_version
= byte_get (hdrptr
, 2);
2703 if (linfo
.li_version
!= 2
2704 && linfo
.li_version
!= 3
2705 && linfo
.li_version
!= 4)
2707 warn (_("Only DWARF version 2, 3 and 4 line info is currently "
2712 linfo
.li_prologue_length
= byte_get (hdrptr
, offset_size
);
2713 hdrptr
+= offset_size
;
2714 linfo
.li_min_insn_length
= byte_get (hdrptr
, 1);
2716 if (linfo
.li_version
>= 4)
2718 linfo
.li_max_ops_per_insn
= byte_get (hdrptr
, 1);
2720 if (linfo
.li_max_ops_per_insn
== 0)
2722 warn (_("Invalid maximum operations per insn.\n"));
2727 linfo
.li_max_ops_per_insn
= 1;
2728 linfo
.li_default_is_stmt
= byte_get (hdrptr
, 1);
2730 linfo
.li_line_base
= byte_get (hdrptr
, 1);
2732 linfo
.li_line_range
= byte_get (hdrptr
, 1);
2734 linfo
.li_opcode_base
= byte_get (hdrptr
, 1);
2737 /* Sign extend the line base field. */
2738 linfo
.li_line_base
<<= 24;
2739 linfo
.li_line_base
>>= 24;
2741 /* Find the end of this CU's Line Number Information Block. */
2742 end_of_sequence
= data
+ linfo
.li_length
+ initial_length_size
;
2744 reset_state_machine (linfo
.li_default_is_stmt
);
2746 /* Save a pointer to the contents of the Opcodes table. */
2747 standard_opcodes
= hdrptr
;
2749 /* Traverse the Directory table just to count entries. */
2750 data
= standard_opcodes
+ linfo
.li_opcode_base
- 1;
2753 unsigned int n_directories
= 0;
2754 unsigned char *ptr_directory_table
= data
;
2758 data
+= strlen ((char *) data
) + 1;
2762 /* Go through the directory table again to save the directories. */
2763 directory_table
= (unsigned char **)
2764 xmalloc (n_directories
* sizeof (unsigned char *));
2767 while (*ptr_directory_table
!= 0)
2769 directory_table
[i
] = ptr_directory_table
;
2770 ptr_directory_table
+= strlen ((char *) ptr_directory_table
) + 1;
2774 /* Skip the NUL at the end of the table. */
2777 /* Traverse the File Name table just to count the entries. */
2780 unsigned int n_files
= 0;
2781 unsigned char *ptr_file_name_table
= data
;
2785 unsigned int bytes_read
;
2787 /* Skip Name, directory index, last modification time and length
2789 data
+= strlen ((char *) data
) + 1;
2790 read_leb128 (data
, & bytes_read
, 0);
2792 read_leb128 (data
, & bytes_read
, 0);
2794 read_leb128 (data
, & bytes_read
, 0);
2800 /* Go through the file table again to save the strings. */
2801 file_table
= (File_Entry
*) xmalloc (n_files
* sizeof (File_Entry
));
2804 while (*ptr_file_name_table
!= 0)
2806 unsigned int bytes_read
;
2808 file_table
[i
].name
= ptr_file_name_table
;
2809 ptr_file_name_table
+= strlen ((char *) ptr_file_name_table
) + 1;
2811 /* We are not interested in directory, time or size. */
2812 file_table
[i
].directory_index
= read_leb128 (ptr_file_name_table
,
2814 ptr_file_name_table
+= bytes_read
;
2815 file_table
[i
].modification_date
= read_leb128 (ptr_file_name_table
,
2817 ptr_file_name_table
+= bytes_read
;
2818 file_table
[i
].length
= read_leb128 (ptr_file_name_table
, & bytes_read
, 0);
2819 ptr_file_name_table
+= bytes_read
;
2824 /* Print the Compilation Unit's name and a header. */
2825 if (directory_table
== NULL
)
2827 printf (_("CU: %s:\n"), file_table
[0].name
);
2828 printf (_("File name Line number Starting address\n"));
2832 if (do_wide
|| strlen ((char *) directory_table
[0]) < 76)
2833 printf (_("CU: %s/%s:\n"), directory_table
[0],
2834 file_table
[0].name
);
2836 printf ("%s:\n", file_table
[0].name
);
2838 printf (_("File name Line number Starting address\n"));
2842 /* Skip the NUL at the end of the table. */
2845 /* This loop iterates through the Dwarf Line Number Program. */
2846 while (data
< end_of_sequence
)
2848 unsigned char op_code
;
2850 unsigned long int uladv
;
2851 unsigned int bytes_read
;
2852 int is_special_opcode
= 0;
2856 if (op_code
>= linfo
.li_opcode_base
)
2858 op_code
-= linfo
.li_opcode_base
;
2859 uladv
= (op_code
/ linfo
.li_line_range
);
2860 if (linfo
.li_max_ops_per_insn
== 1)
2862 uladv
*= linfo
.li_min_insn_length
;
2863 state_machine_regs
.address
+= uladv
;
2867 state_machine_regs
.address
2868 += ((state_machine_regs
.op_index
+ uladv
)
2869 / linfo
.li_max_ops_per_insn
)
2870 * linfo
.li_min_insn_length
;
2871 state_machine_regs
.op_index
2872 = (state_machine_regs
.op_index
+ uladv
)
2873 % linfo
.li_max_ops_per_insn
;
2876 adv
= (op_code
% linfo
.li_line_range
) + linfo
.li_line_base
;
2877 state_machine_regs
.line
+= adv
;
2878 is_special_opcode
= 1;
2880 else switch (op_code
)
2882 case DW_LNS_extended_op
:
2884 unsigned int ext_op_code_len
;
2885 unsigned char ext_op_code
;
2886 unsigned char *op_code_data
= data
;
2888 ext_op_code_len
= read_leb128 (op_code_data
, &bytes_read
, 0);
2889 op_code_data
+= bytes_read
;
2891 if (ext_op_code_len
== 0)
2893 warn (_("badly formed extended line op encountered!\n"));
2896 ext_op_code_len
+= bytes_read
;
2897 ext_op_code
= *op_code_data
++;
2899 switch (ext_op_code
)
2901 case DW_LNE_end_sequence
:
2902 reset_state_machine (linfo
.li_default_is_stmt
);
2904 case DW_LNE_set_address
:
2905 state_machine_regs
.address
=
2906 byte_get (op_code_data
, ext_op_code_len
- bytes_read
- 1);
2907 state_machine_regs
.op_index
= 0;
2909 case DW_LNE_define_file
:
2911 unsigned int dir_index
= 0;
2913 ++state_machine_regs
.last_file_entry
;
2914 op_code_data
+= strlen ((char *) op_code_data
) + 1;
2915 dir_index
= read_leb128 (op_code_data
, & bytes_read
, 0);
2916 op_code_data
+= bytes_read
;
2917 read_leb128 (op_code_data
, & bytes_read
, 0);
2918 op_code_data
+= bytes_read
;
2919 read_leb128 (op_code_data
, & bytes_read
, 0);
2921 printf ("%s:\n", directory_table
[dir_index
]);
2925 printf (_("UNKNOWN: length %d\n"), ext_op_code_len
- bytes_read
);
2928 data
+= ext_op_code_len
;
2934 case DW_LNS_advance_pc
:
2935 uladv
= read_leb128 (data
, & bytes_read
, 0);
2937 if (linfo
.li_max_ops_per_insn
== 1)
2939 uladv
*= linfo
.li_min_insn_length
;
2940 state_machine_regs
.address
+= uladv
;
2944 state_machine_regs
.address
2945 += ((state_machine_regs
.op_index
+ uladv
)
2946 / linfo
.li_max_ops_per_insn
)
2947 * linfo
.li_min_insn_length
;
2948 state_machine_regs
.op_index
2949 = (state_machine_regs
.op_index
+ uladv
)
2950 % linfo
.li_max_ops_per_insn
;
2954 case DW_LNS_advance_line
:
2955 adv
= read_sleb128 (data
, & bytes_read
);
2957 state_machine_regs
.line
+= adv
;
2960 case DW_LNS_set_file
:
2961 adv
= read_leb128 (data
, & bytes_read
, 0);
2963 state_machine_regs
.file
= adv
;
2964 if (file_table
[state_machine_regs
.file
- 1].directory_index
== 0)
2966 /* If directory index is 0, that means current directory. */
2967 printf ("\n./%s:[++]\n",
2968 file_table
[state_machine_regs
.file
- 1].name
);
2972 /* The directory index starts counting at 1. */
2973 printf ("\n%s/%s:\n",
2974 directory_table
[file_table
[state_machine_regs
.file
- 1].directory_index
- 1],
2975 file_table
[state_machine_regs
.file
- 1].name
);
2979 case DW_LNS_set_column
:
2980 uladv
= read_leb128 (data
, & bytes_read
, 0);
2982 state_machine_regs
.column
= uladv
;
2985 case DW_LNS_negate_stmt
:
2986 adv
= state_machine_regs
.is_stmt
;
2988 state_machine_regs
.is_stmt
= adv
;
2991 case DW_LNS_set_basic_block
:
2992 state_machine_regs
.basic_block
= 1;
2995 case DW_LNS_const_add_pc
:
2996 uladv
= ((255 - linfo
.li_opcode_base
) / linfo
.li_line_range
);
2997 if (linfo
.li_max_ops_per_insn
== 1)
2999 uladv
*= linfo
.li_min_insn_length
;
3000 state_machine_regs
.address
+= uladv
;
3004 state_machine_regs
.address
3005 += ((state_machine_regs
.op_index
+ uladv
)
3006 / linfo
.li_max_ops_per_insn
)
3007 * linfo
.li_min_insn_length
;
3008 state_machine_regs
.op_index
3009 = (state_machine_regs
.op_index
+ uladv
)
3010 % linfo
.li_max_ops_per_insn
;
3014 case DW_LNS_fixed_advance_pc
:
3015 uladv
= byte_get (data
, 2);
3017 state_machine_regs
.address
+= uladv
;
3018 state_machine_regs
.op_index
= 0;
3021 case DW_LNS_set_prologue_end
:
3024 case DW_LNS_set_epilogue_begin
:
3027 case DW_LNS_set_isa
:
3028 uladv
= read_leb128 (data
, & bytes_read
, 0);
3030 printf (_(" Set ISA to %lu\n"), uladv
);
3034 printf (_(" Unknown opcode %d with operands: "), op_code
);
3036 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
3038 printf ("0x%s%s", dwarf_vmatoa ("x", read_leb128 (data
,
3040 i
== 1 ? "" : ", ");
3047 /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row
3048 to the DWARF address/line matrix. */
3049 if ((is_special_opcode
) || (op_code
== DW_LNE_end_sequence
)
3050 || (op_code
== DW_LNS_copy
))
3052 const unsigned int MAX_FILENAME_LENGTH
= 35;
3053 char *fileName
= (char *)file_table
[state_machine_regs
.file
- 1].name
;
3054 char *newFileName
= NULL
;
3055 size_t fileNameLength
= strlen (fileName
);
3057 if ((fileNameLength
> MAX_FILENAME_LENGTH
) && (!do_wide
))
3059 newFileName
= (char *) xmalloc (MAX_FILENAME_LENGTH
+ 1);
3060 /* Truncate file name */
3061 strncpy (newFileName
,
3062 fileName
+ fileNameLength
- MAX_FILENAME_LENGTH
,
3063 MAX_FILENAME_LENGTH
+ 1);
3067 newFileName
= (char *) xmalloc (fileNameLength
+ 1);
3068 strncpy (newFileName
, fileName
, fileNameLength
+ 1);
3071 if (!do_wide
|| (fileNameLength
<= MAX_FILENAME_LENGTH
))
3073 if (linfo
.li_max_ops_per_insn
== 1)
3074 printf ("%-35s %11d %#18" DWARF_VMA_FMT
"x\n",
3075 newFileName
, state_machine_regs
.line
,
3076 state_machine_regs
.address
);
3078 printf ("%-35s %11d %#18" DWARF_VMA_FMT
"x[%d]\n",
3079 newFileName
, state_machine_regs
.line
,
3080 state_machine_regs
.address
,
3081 state_machine_regs
.op_index
);
3085 if (linfo
.li_max_ops_per_insn
== 1)
3086 printf ("%s %11d %#18" DWARF_VMA_FMT
"x\n",
3087 newFileName
, state_machine_regs
.line
,
3088 state_machine_regs
.address
);
3090 printf ("%s %11d %#18" DWARF_VMA_FMT
"x[%d]\n",
3091 newFileName
, state_machine_regs
.line
,
3092 state_machine_regs
.address
,
3093 state_machine_regs
.op_index
);
3096 if (op_code
== DW_LNE_end_sequence
)
3104 free (directory_table
);
3105 directory_table
= NULL
;
3113 display_debug_lines (struct dwarf_section
*section
, void *file ATTRIBUTE_UNUSED
)
3115 unsigned char *data
= section
->start
;
3116 unsigned char *end
= data
+ section
->size
;
3118 int retValDecoded
= 1;
3120 if (do_debug_lines
== 0)
3121 do_debug_lines
|= FLAG_DEBUG_LINES_RAW
;
3123 if (do_debug_lines
& FLAG_DEBUG_LINES_RAW
)
3124 retValRaw
= display_debug_lines_raw (section
, data
, end
);
3126 if (do_debug_lines
& FLAG_DEBUG_LINES_DECODED
)
3127 retValDecoded
= display_debug_lines_decoded (section
, data
, end
);
3129 if (!retValRaw
|| !retValDecoded
)
3136 find_debug_info_for_offset (unsigned long offset
)
3140 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
3143 for (i
= 0; i
< num_debug_info_entries
; i
++)
3144 if (debug_information
[i
].cu_offset
== offset
)
3145 return debug_information
+ i
;
3151 display_debug_pubnames (struct dwarf_section
*section
,
3152 void *file ATTRIBUTE_UNUSED
)
3154 DWARF2_Internal_PubNames names
;
3155 unsigned char *start
= section
->start
;
3156 unsigned char *end
= start
+ section
->size
;
3158 /* It does not matter if this load fails,
3159 we test for that later on. */
3160 load_debug_info (file
);
3162 printf (_("Contents of the %s section:\n\n"), section
->name
);
3166 unsigned char *data
;
3167 unsigned long offset
;
3168 int offset_size
, initial_length_size
;
3172 names
.pn_length
= byte_get (data
, 4);
3174 if (names
.pn_length
== 0xffffffff)
3176 names
.pn_length
= byte_get (data
, 8);
3179 initial_length_size
= 12;
3184 initial_length_size
= 4;
3187 names
.pn_version
= byte_get (data
, 2);
3190 names
.pn_offset
= byte_get (data
, offset_size
);
3191 data
+= offset_size
;
3193 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
3194 && num_debug_info_entries
> 0
3195 && find_debug_info_for_offset (names
.pn_offset
) == NULL
)
3196 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
3197 (unsigned long) names
.pn_offset
, section
->name
);
3199 names
.pn_size
= byte_get (data
, offset_size
);
3200 data
+= offset_size
;
3202 start
+= names
.pn_length
+ initial_length_size
;
3204 if (names
.pn_version
!= 2 && names
.pn_version
!= 3)
3206 static int warned
= 0;
3210 warn (_("Only DWARF 2 and 3 pubnames are currently supported\n"));
3217 printf (_(" Length: %ld\n"),
3218 (long) names
.pn_length
);
3219 printf (_(" Version: %d\n"),
3221 printf (_(" Offset into .debug_info section: 0x%lx\n"),
3222 (unsigned long) names
.pn_offset
);
3223 printf (_(" Size of area in .debug_info section: %ld\n"),
3224 (long) names
.pn_size
);
3226 printf (_("\n Offset\tName\n"));
3230 offset
= byte_get (data
, offset_size
);
3234 data
+= offset_size
;
3235 printf (" %-6lx\t%s\n", offset
, data
);
3236 data
+= strlen ((char *) data
) + 1;
3239 while (offset
!= 0);
3247 display_debug_macinfo (struct dwarf_section
*section
,
3248 void *file ATTRIBUTE_UNUSED
)
3250 unsigned char *start
= section
->start
;
3251 unsigned char *end
= start
+ section
->size
;
3252 unsigned char *curr
= start
;
3253 unsigned int bytes_read
;
3254 enum dwarf_macinfo_record_type op
;
3256 printf (_("Contents of the %s section:\n\n"), section
->name
);
3260 unsigned int lineno
;
3263 op
= (enum dwarf_macinfo_record_type
) *curr
;
3268 case DW_MACINFO_start_file
:
3270 unsigned int filenum
;
3272 lineno
= read_leb128 (curr
, & bytes_read
, 0);
3274 filenum
= read_leb128 (curr
, & bytes_read
, 0);
3277 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"),
3282 case DW_MACINFO_end_file
:
3283 printf (_(" DW_MACINFO_end_file\n"));
3286 case DW_MACINFO_define
:
3287 lineno
= read_leb128 (curr
, & bytes_read
, 0);
3289 string
= (char *) curr
;
3290 curr
+= strlen (string
) + 1;
3291 printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"),
3295 case DW_MACINFO_undef
:
3296 lineno
= read_leb128 (curr
, & bytes_read
, 0);
3298 string
= (char *) curr
;
3299 curr
+= strlen (string
) + 1;
3300 printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"),
3304 case DW_MACINFO_vendor_ext
:
3306 unsigned int constant
;
3308 constant
= read_leb128 (curr
, & bytes_read
, 0);
3310 string
= (char *) curr
;
3311 curr
+= strlen (string
) + 1;
3312 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"),
3323 display_debug_abbrev (struct dwarf_section
*section
,
3324 void *file ATTRIBUTE_UNUSED
)
3326 abbrev_entry
*entry
;
3327 unsigned char *start
= section
->start
;
3328 unsigned char *end
= start
+ section
->size
;
3330 printf (_("Contents of the %s section:\n\n"), section
->name
);
3336 start
= process_abbrev_section (start
, end
);
3338 if (first_abbrev
== NULL
)
3341 printf (_(" Number TAG\n"));
3343 for (entry
= first_abbrev
; entry
; entry
= entry
->next
)
3347 printf (" %ld %s [%s]\n",
3349 get_TAG_name (entry
->tag
),
3350 entry
->children
? _("has children") : _("no children"));
3352 for (attr
= entry
->first_attr
; attr
; attr
= attr
->next
)
3353 printf (" %-18s %s\n",
3354 get_AT_name (attr
->attribute
),
3355 get_FORM_name (attr
->form
));
3366 display_debug_loc (struct dwarf_section
*section
, void *file
)
3368 unsigned char *start
= section
->start
;
3369 unsigned char *section_end
;
3370 unsigned long bytes
;
3371 unsigned char *section_begin
= start
;
3372 unsigned int num_loc_list
= 0;
3373 unsigned long last_offset
= 0;
3374 unsigned int first
= 0;
3377 int seen_first_offset
= 0;
3378 int use_debug_info
= 1;
3379 unsigned char *next
;
3381 bytes
= section
->size
;
3382 section_end
= start
+ bytes
;
3386 printf (_("\nThe %s section is empty.\n"), section
->name
);
3390 if (load_debug_info (file
) == 0)
3392 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
3397 /* Check the order of location list in .debug_info section. If
3398 offsets of location lists are in the ascending order, we can
3399 use `debug_information' directly. */
3400 for (i
= 0; i
< num_debug_info_entries
; i
++)
3404 num
= debug_information
[i
].num_loc_offsets
;
3405 num_loc_list
+= num
;
3407 /* Check if we can use `debug_information' directly. */
3408 if (use_debug_info
&& num
!= 0)
3410 if (!seen_first_offset
)
3412 /* This is the first location list. */
3413 last_offset
= debug_information
[i
].loc_offsets
[0];
3415 seen_first_offset
= 1;
3421 for (; j
< num
; j
++)
3424 debug_information
[i
].loc_offsets
[j
])
3429 last_offset
= debug_information
[i
].loc_offsets
[j
];
3434 if (!use_debug_info
)
3435 /* FIXME: Should we handle this case? */
3436 error (_("Location lists in .debug_info section aren't in ascending order!\n"));
3438 if (!seen_first_offset
)
3439 error (_("No location lists in .debug_info section!\n"));
3441 /* DWARF sections under Mach-O have non-zero addresses. */
3442 if (debug_information
[first
].num_loc_offsets
> 0
3443 && debug_information
[first
].loc_offsets
[0] != section
->address
)
3444 warn (_("Location lists in %s section start at 0x%s\n"),
3446 dwarf_vmatoa ("x", debug_information
[first
].loc_offsets
[0]));
3448 printf (_("Contents of the %s section:\n\n"), section
->name
);
3449 printf (_(" Offset Begin End Expression\n"));
3451 seen_first_offset
= 0;
3452 for (i
= first
; i
< num_debug_info_entries
; i
++)
3456 unsigned short length
;
3457 unsigned long offset
;
3458 unsigned int pointer_size
;
3459 unsigned int offset_size
;
3461 unsigned long cu_offset
;
3462 unsigned long base_address
;
3463 int need_frame_base
;
3466 pointer_size
= debug_information
[i
].pointer_size
;
3467 cu_offset
= debug_information
[i
].cu_offset
;
3468 offset_size
= debug_information
[i
].offset_size
;
3469 dwarf_version
= debug_information
[i
].dwarf_version
;
3471 for (j
= 0; j
< debug_information
[i
].num_loc_offsets
; j
++)
3473 has_frame_base
= debug_information
[i
].have_frame_base
[j
];
3474 /* DWARF sections under Mach-O have non-zero addresses. */
3475 offset
= debug_information
[i
].loc_offsets
[j
] - section
->address
;
3476 next
= section_begin
+ offset
;
3477 base_address
= debug_information
[i
].base_address
;
3479 if (!seen_first_offset
)
3480 seen_first_offset
= 1;
3484 warn (_("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n"),
3485 (unsigned long) (start
- section_begin
),
3486 (unsigned long) (next
- section_begin
));
3487 else if (start
> next
)
3488 warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n"),
3489 (unsigned long) (start
- section_begin
),
3490 (unsigned long) (next
- section_begin
));
3494 if (offset
>= bytes
)
3496 warn (_("Offset 0x%lx is bigger than .debug_loc section size.\n"),
3503 if (start
+ 2 * pointer_size
> section_end
)
3505 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
3510 /* Note: we use sign extension here in order to be sure that
3511 we can detect the -1 escape value. Sign extension into the
3512 top 32 bits of a 32-bit address will not affect the values
3513 that we display since we always show hex values, and always
3514 the bottom 32-bits. */
3515 begin
= byte_get_signed (start
, pointer_size
);
3516 start
+= pointer_size
;
3517 end
= byte_get_signed (start
, pointer_size
);
3518 start
+= pointer_size
;
3520 printf (" %8.8lx ", offset
);
3522 if (begin
== 0 && end
== 0)
3524 printf (_("<End of list>\n"));
3528 /* Check base address specifiers. */
3529 if (begin
== (dwarf_vma
) -1 && end
!= (dwarf_vma
) -1)
3532 print_dwarf_vma (begin
, pointer_size
);
3533 print_dwarf_vma (end
, pointer_size
);
3534 printf (_("(base address)\n"));
3538 if (start
+ 2 > section_end
)
3540 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
3545 length
= byte_get (start
, 2);
3548 if (start
+ length
> section_end
)
3550 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
3555 print_dwarf_vma (begin
+ base_address
, pointer_size
);
3556 print_dwarf_vma (end
+ base_address
, pointer_size
);
3559 need_frame_base
= decode_location_expression (start
,
3564 cu_offset
, section
);
3567 if (need_frame_base
&& !has_frame_base
)
3568 printf (_(" [without DW_AT_frame_base]"));
3571 fputs (_(" (start == end)"), stdout
);
3572 else if (begin
> end
)
3573 fputs (_(" (start > end)"), stdout
);
3582 if (start
< section_end
)
3583 warn (_("There are %ld unused bytes at the end of section %s\n"),
3584 (long) (section_end
- start
), section
->name
);
3590 display_debug_str (struct dwarf_section
*section
,
3591 void *file ATTRIBUTE_UNUSED
)
3593 unsigned char *start
= section
->start
;
3594 unsigned long bytes
= section
->size
;
3595 dwarf_vma addr
= section
->address
;
3599 printf (_("\nThe %s section is empty.\n"), section
->name
);
3603 printf (_("Contents of the %s section:\n\n"), section
->name
);
3611 lbytes
= (bytes
> 16 ? 16 : bytes
);
3613 printf (" 0x%8.8lx ", (unsigned long) addr
);
3615 for (j
= 0; j
< 16; j
++)
3618 printf ("%2.2x", start
[j
]);
3626 for (j
= 0; j
< lbytes
; j
++)
3629 if (k
>= ' ' && k
< 0x80)
3648 display_debug_info (struct dwarf_section
*section
, void *file
)
3650 return process_debug_info (section
, file
, abbrev
, 0, 0);
3654 display_debug_types (struct dwarf_section
*section
, void *file
)
3656 return process_debug_info (section
, file
, abbrev
, 0, 1);
3660 display_trace_info (struct dwarf_section
*section
, void *file
)
3662 return process_debug_info (section
, file
, trace_abbrev
, 0, 0);
3666 display_debug_aranges (struct dwarf_section
*section
,
3667 void *file ATTRIBUTE_UNUSED
)
3669 unsigned char *start
= section
->start
;
3670 unsigned char *end
= start
+ section
->size
;
3672 printf (_("Contents of the %s section:\n\n"), section
->name
);
3674 /* It does not matter if this load fails,
3675 we test for that later on. */
3676 load_debug_info (file
);
3680 unsigned char *hdrptr
;
3681 DWARF2_Internal_ARange arange
;
3682 unsigned char *addr_ranges
;
3685 unsigned char address_size
;
3688 int initial_length_size
;
3692 arange
.ar_length
= byte_get (hdrptr
, 4);
3695 if (arange
.ar_length
== 0xffffffff)
3697 arange
.ar_length
= byte_get (hdrptr
, 8);
3700 initial_length_size
= 12;
3705 initial_length_size
= 4;
3708 arange
.ar_version
= byte_get (hdrptr
, 2);
3711 arange
.ar_info_offset
= byte_get (hdrptr
, offset_size
);
3712 hdrptr
+= offset_size
;
3714 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
3715 && num_debug_info_entries
> 0
3716 && find_debug_info_for_offset (arange
.ar_info_offset
) == NULL
)
3717 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
3718 (unsigned long) arange
.ar_info_offset
, section
->name
);
3720 arange
.ar_pointer_size
= byte_get (hdrptr
, 1);
3723 arange
.ar_segment_size
= byte_get (hdrptr
, 1);
3726 if (arange
.ar_version
!= 2 && arange
.ar_version
!= 3)
3728 warn (_("Only DWARF 2 and 3 aranges are currently supported.\n"));
3732 printf (_(" Length: %ld\n"),
3733 (long) arange
.ar_length
);
3734 printf (_(" Version: %d\n"), arange
.ar_version
);
3735 printf (_(" Offset into .debug_info: 0x%lx\n"),
3736 (unsigned long) arange
.ar_info_offset
);
3737 printf (_(" Pointer Size: %d\n"), arange
.ar_pointer_size
);
3738 printf (_(" Segment Size: %d\n"), arange
.ar_segment_size
);
3740 address_size
= arange
.ar_pointer_size
+ arange
.ar_segment_size
;
3742 /* The DWARF spec does not require that the address size be a power
3743 of two, but we do. This will have to change if we ever encounter
3744 an uneven architecture. */
3745 if ((address_size
& (address_size
- 1)) != 0)
3747 warn (_("Pointer size + Segment size is not a power of two.\n"));
3751 if (address_size
> 4)
3752 printf (_("\n Address Length\n"));
3754 printf (_("\n Address Length\n"));
3756 addr_ranges
= hdrptr
;
3758 /* Must pad to an alignment boundary that is twice the address size. */
3759 excess
= (hdrptr
- start
) % (2 * address_size
);
3761 addr_ranges
+= (2 * address_size
) - excess
;
3763 start
+= arange
.ar_length
+ initial_length_size
;
3765 while (addr_ranges
+ 2 * address_size
<= start
)
3767 address
= byte_get (addr_ranges
, address_size
);
3769 addr_ranges
+= address_size
;
3771 length
= byte_get (addr_ranges
, address_size
);
3773 addr_ranges
+= address_size
;
3776 print_dwarf_vma (address
, address_size
);
3777 print_dwarf_vma (length
, address_size
);
3787 /* Each debug_information[x].range_lists[y] gets this representation for
3788 sorting purposes. */
3792 /* The debug_information[x].range_lists[y] value. */
3793 unsigned long ranges_offset
;
3795 /* Original debug_information to find parameters of the data. */
3796 debug_info
*debug_info_p
;
3799 /* Sort struct range_entry in ascending order of its RANGES_OFFSET. */
3802 range_entry_compar (const void *ap
, const void *bp
)
3804 const struct range_entry
*a_re
= (const struct range_entry
*) ap
;
3805 const struct range_entry
*b_re
= (const struct range_entry
*) bp
;
3806 const unsigned long a
= a_re
->ranges_offset
;
3807 const unsigned long b
= b_re
->ranges_offset
;
3809 return (a
> b
) - (b
> a
);
3813 display_debug_ranges (struct dwarf_section
*section
,
3814 void *file ATTRIBUTE_UNUSED
)
3816 unsigned char *start
= section
->start
;
3817 unsigned long bytes
;
3818 unsigned char *section_begin
= start
;
3819 unsigned int num_range_list
, i
;
3820 struct range_entry
*range_entries
, *range_entry_fill
;
3822 bytes
= section
->size
;
3826 printf (_("\nThe %s section is empty.\n"), section
->name
);
3830 if (load_debug_info (file
) == 0)
3832 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
3838 for (i
= 0; i
< num_debug_info_entries
; i
++)
3839 num_range_list
+= debug_information
[i
].num_range_lists
;
3841 if (num_range_list
== 0)
3842 error (_("No range lists in .debug_info section!\n"));
3844 range_entries
= (struct range_entry
*)
3845 xmalloc (sizeof (*range_entries
) * num_range_list
);
3846 range_entry_fill
= range_entries
;
3848 for (i
= 0; i
< num_debug_info_entries
; i
++)
3850 debug_info
*debug_info_p
= &debug_information
[i
];
3853 for (j
= 0; j
< debug_info_p
->num_range_lists
; j
++)
3855 range_entry_fill
->ranges_offset
= debug_info_p
->range_lists
[j
];
3856 range_entry_fill
->debug_info_p
= debug_info_p
;
3861 qsort (range_entries
, num_range_list
, sizeof (*range_entries
),
3862 range_entry_compar
);
3864 /* DWARF sections under Mach-O have non-zero addresses. */
3865 if (range_entries
[0].ranges_offset
!= section
->address
)
3866 warn (_("Range lists in %s section start at 0x%lx\n"),
3867 section
->name
, range_entries
[0].ranges_offset
);
3869 printf (_("Contents of the %s section:\n\n"), section
->name
);
3870 printf (_(" Offset Begin End\n"));
3872 for (i
= 0; i
< num_range_list
; i
++)
3874 struct range_entry
*range_entry
= &range_entries
[i
];
3875 debug_info
*debug_info_p
= range_entry
->debug_info_p
;
3876 unsigned int pointer_size
;
3877 unsigned long offset
;
3878 unsigned char *next
;
3879 unsigned long base_address
;
3881 pointer_size
= debug_info_p
->pointer_size
;
3883 /* DWARF sections under Mach-O have non-zero addresses. */
3884 offset
= range_entry
->ranges_offset
- section
->address
;
3885 next
= section_begin
+ offset
;
3886 base_address
= debug_info_p
->base_address
;
3891 warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"),
3892 (unsigned long) (start
- section_begin
),
3893 (unsigned long) (next
- section_begin
), section
->name
);
3894 else if (start
> next
)
3895 warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"),
3896 (unsigned long) (start
- section_begin
),
3897 (unsigned long) (next
- section_begin
), section
->name
);
3906 /* Note: we use sign extension here in order to be sure that
3907 we can detect the -1 escape value. Sign extension into the
3908 top 32 bits of a 32-bit address will not affect the values
3909 that we display since we always show hex values, and always
3910 the bottom 32-bits. */
3911 begin
= byte_get_signed (start
, pointer_size
);
3912 start
+= pointer_size
;
3913 end
= byte_get_signed (start
, pointer_size
);
3914 start
+= pointer_size
;
3916 printf (" %8.8lx ", offset
);
3918 if (begin
== 0 && end
== 0)
3920 printf (_("<End of list>\n"));
3924 /* Check base address specifiers. */
3925 if (begin
== (dwarf_vma
) -1 && end
!= (dwarf_vma
) -1)
3928 print_dwarf_vma (begin
, pointer_size
);
3929 print_dwarf_vma (end
, pointer_size
);
3930 printf ("(base address)\n");
3934 print_dwarf_vma (begin
+ base_address
, pointer_size
);
3935 print_dwarf_vma (end
+ base_address
, pointer_size
);
3938 fputs (_("(start == end)"), stdout
);
3939 else if (begin
> end
)
3940 fputs (_("(start > end)"), stdout
);
3947 free (range_entries
);
3952 typedef struct Frame_Chunk
3954 struct Frame_Chunk
*next
;
3955 unsigned char *chunk_start
;
3957 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
3958 short int *col_type
;
3961 unsigned int code_factor
;
3963 unsigned long pc_begin
;
3964 unsigned long pc_range
;
3968 unsigned char fde_encoding
;
3969 unsigned char cfa_exp
;
3970 unsigned char ptr_size
;
3971 unsigned char segment_size
;
3975 static const char *const *dwarf_regnames
;
3976 static unsigned int dwarf_regnames_count
;
3978 /* A marker for a col_type that means this column was never referenced
3979 in the frame info. */
3980 #define DW_CFA_unreferenced (-1)
3982 /* Return 0 if not more space is needed, 1 if more space is needed,
3983 -1 for invalid reg. */
3986 frame_need_space (Frame_Chunk
*fc
, unsigned int reg
)
3988 int prev
= fc
->ncols
;
3990 if (reg
< (unsigned int) fc
->ncols
)
3993 if (dwarf_regnames_count
3994 && reg
> dwarf_regnames_count
)
3997 fc
->ncols
= reg
+ 1;
3998 fc
->col_type
= (short int *) xcrealloc (fc
->col_type
, fc
->ncols
,
3999 sizeof (short int));
4000 fc
->col_offset
= (int *) xcrealloc (fc
->col_offset
, fc
->ncols
, sizeof (int));
4002 while (prev
< fc
->ncols
)
4004 fc
->col_type
[prev
] = DW_CFA_unreferenced
;
4005 fc
->col_offset
[prev
] = 0;
4011 static const char *const dwarf_regnames_i386
[] =
4013 "eax", "ecx", "edx", "ebx",
4014 "esp", "ebp", "esi", "edi",
4015 "eip", "eflags", NULL
,
4016 "st0", "st1", "st2", "st3",
4017 "st4", "st5", "st6", "st7",
4019 "xmm0", "xmm1", "xmm2", "xmm3",
4020 "xmm4", "xmm5", "xmm6", "xmm7",
4021 "mm0", "mm1", "mm2", "mm3",
4022 "mm4", "mm5", "mm6", "mm7",
4023 "fcw", "fsw", "mxcsr",
4024 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
,
4029 init_dwarf_regnames_i386 (void)
4031 dwarf_regnames
= dwarf_regnames_i386
;
4032 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_i386
);
4035 static const char *const dwarf_regnames_x86_64
[] =
4037 "rax", "rdx", "rcx", "rbx",
4038 "rsi", "rdi", "rbp", "rsp",
4039 "r8", "r9", "r10", "r11",
4040 "r12", "r13", "r14", "r15",
4042 "xmm0", "xmm1", "xmm2", "xmm3",
4043 "xmm4", "xmm5", "xmm6", "xmm7",
4044 "xmm8", "xmm9", "xmm10", "xmm11",
4045 "xmm12", "xmm13", "xmm14", "xmm15",
4046 "st0", "st1", "st2", "st3",
4047 "st4", "st5", "st6", "st7",
4048 "mm0", "mm1", "mm2", "mm3",
4049 "mm4", "mm5", "mm6", "mm7",
4051 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
,
4052 "fs.base", "gs.base", NULL
, NULL
,
4054 "mxcsr", "fcw", "fsw"
4058 init_dwarf_regnames_x86_64 (void)
4060 dwarf_regnames
= dwarf_regnames_x86_64
;
4061 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_x86_64
);
4065 init_dwarf_regnames (unsigned int e_machine
)
4071 init_dwarf_regnames_i386 ();
4076 init_dwarf_regnames_x86_64 ();
4085 regname (unsigned int regno
, int row
)
4087 static char reg
[64];
4089 && regno
< dwarf_regnames_count
4090 && dwarf_regnames
[regno
] != NULL
)
4093 return dwarf_regnames
[regno
];
4094 snprintf (reg
, sizeof (reg
), "r%d (%s)", regno
,
4095 dwarf_regnames
[regno
]);
4098 snprintf (reg
, sizeof (reg
), "r%d", regno
);
4103 frame_display_row (Frame_Chunk
*fc
, int *need_col_headers
, int *max_regs
)
4108 if (*max_regs
< fc
->ncols
)
4109 *max_regs
= fc
->ncols
;
4111 if (*need_col_headers
)
4113 static const char *sloc
= " LOC";
4115 *need_col_headers
= 0;
4117 printf ("%-*s CFA ", eh_addr_size
* 2, sloc
);
4119 for (r
= 0; r
< *max_regs
; r
++)
4120 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
4125 printf ("%-5s ", regname (r
, 1));
4131 printf ("%0*lx ", eh_addr_size
* 2, fc
->pc_begin
);
4133 strcpy (tmp
, "exp");
4135 sprintf (tmp
, "%s%+d", regname (fc
->cfa_reg
, 1), fc
->cfa_offset
);
4136 printf ("%-8s ", tmp
);
4138 for (r
= 0; r
< fc
->ncols
; r
++)
4140 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
4142 switch (fc
->col_type
[r
])
4144 case DW_CFA_undefined
:
4147 case DW_CFA_same_value
:
4151 sprintf (tmp
, "c%+d", fc
->col_offset
[r
]);
4153 case DW_CFA_val_offset
:
4154 sprintf (tmp
, "v%+d", fc
->col_offset
[r
]);
4156 case DW_CFA_register
:
4157 sprintf (tmp
, "%s", regname (fc
->col_offset
[r
], 0));
4159 case DW_CFA_expression
:
4160 strcpy (tmp
, "exp");
4162 case DW_CFA_val_expression
:
4163 strcpy (tmp
, "vexp");
4166 strcpy (tmp
, "n/a");
4169 printf ("%-5s ", tmp
);
4175 #define GET(N) byte_get (start, N); start += N
4176 #define LEB() read_leb128 (start, & length_return, 0); start += length_return
4177 #define SLEB() read_sleb128 (start, & length_return); start += length_return
4180 display_debug_frames (struct dwarf_section
*section
,
4181 void *file ATTRIBUTE_UNUSED
)
4183 unsigned char *start
= section
->start
;
4184 unsigned char *end
= start
+ section
->size
;
4185 unsigned char *section_start
= start
;
4186 Frame_Chunk
*chunks
= 0;
4187 Frame_Chunk
*remembered_state
= 0;
4189 int is_eh
= strcmp (section
->name
, ".eh_frame") == 0;
4190 unsigned int length_return
;
4192 const char *bad_reg
= _("bad register: ");
4193 int saved_eh_addr_size
= eh_addr_size
;
4195 printf (_("Contents of the %s section:\n"), section
->name
);
4199 unsigned char *saved_start
;
4200 unsigned char *block_end
;
4201 unsigned long length
;
4202 unsigned long cie_id
;
4205 int need_col_headers
= 1;
4206 unsigned char *augmentation_data
= NULL
;
4207 unsigned long augmentation_data_len
= 0;
4208 int encoded_ptr_size
= saved_eh_addr_size
;
4210 int initial_length_size
;
4212 saved_start
= start
;
4213 length
= byte_get (start
, 4); start
+= 4;
4217 printf ("\n%08lx ZERO terminator\n\n",
4218 (unsigned long)(saved_start
- section_start
));
4222 if (length
== 0xffffffff)
4224 length
= byte_get (start
, 8);
4227 initial_length_size
= 12;
4232 initial_length_size
= 4;
4235 block_end
= saved_start
+ length
+ initial_length_size
;
4236 if (block_end
> end
)
4238 warn ("Invalid length %#08lx in FDE at %#08lx\n",
4239 length
, (unsigned long)(saved_start
- section_start
));
4242 cie_id
= byte_get (start
, offset_size
); start
+= offset_size
;
4244 if (is_eh
? (cie_id
== 0) : (cie_id
== DW_CIE_ID
))
4248 fc
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
4249 memset (fc
, 0, sizeof (Frame_Chunk
));
4253 fc
->chunk_start
= saved_start
;
4255 fc
->col_type
= (short int *) xmalloc (sizeof (short int));
4256 fc
->col_offset
= (int *) xmalloc (sizeof (int));
4257 frame_need_space (fc
, max_regs
- 1);
4261 fc
->augmentation
= (char *) start
;
4262 start
= (unsigned char *) strchr ((char *) start
, '\0') + 1;
4264 if (strcmp (fc
->augmentation
, "eh") == 0)
4265 start
+= eh_addr_size
;
4269 fc
->ptr_size
= GET (1);
4270 fc
->segment_size
= GET (1);
4271 eh_addr_size
= fc
->ptr_size
;
4275 fc
->ptr_size
= eh_addr_size
;
4276 fc
->segment_size
= 0;
4278 fc
->code_factor
= LEB ();
4279 fc
->data_factor
= SLEB ();
4289 if (fc
->augmentation
[0] == 'z')
4291 augmentation_data_len
= LEB ();
4292 augmentation_data
= start
;
4293 start
+= augmentation_data_len
;
4297 if (do_debug_frames_interp
)
4298 printf ("\n%08lx %08lx %08lx CIE \"%s\" cf=%d df=%d ra=%d\n",
4299 (unsigned long)(saved_start
- section_start
), length
, cie_id
,
4300 fc
->augmentation
, fc
->code_factor
, fc
->data_factor
,
4304 printf ("\n%08lx %08lx %08lx CIE\n",
4305 (unsigned long)(saved_start
- section_start
), length
, cie_id
);
4306 printf (" Version: %d\n", version
);
4307 printf (" Augmentation: \"%s\"\n", fc
->augmentation
);
4310 printf (" Pointer Size: %u\n", fc
->ptr_size
);
4311 printf (" Segment Size: %u\n", fc
->segment_size
);
4313 printf (" Code alignment factor: %u\n", fc
->code_factor
);
4314 printf (" Data alignment factor: %d\n", fc
->data_factor
);
4315 printf (" Return address column: %d\n", fc
->ra
);
4317 if (augmentation_data_len
)
4320 printf (" Augmentation data: ");
4321 for (i
= 0; i
< augmentation_data_len
; ++i
)
4322 printf (" %02x", augmentation_data
[i
]);
4328 if (augmentation_data_len
)
4330 unsigned char *p
, *q
;
4331 p
= (unsigned char *) fc
->augmentation
+ 1;
4332 q
= augmentation_data
;
4339 q
+= 1 + size_of_encoded_value (*q
);
4341 fc
->fde_encoding
= *q
++;
4349 if (fc
->fde_encoding
)
4350 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
4353 frame_need_space (fc
, fc
->ra
);
4357 unsigned char *look_for
;
4358 static Frame_Chunk fde_fc
;
4359 unsigned long segment_selector
;
4362 memset (fc
, 0, sizeof (Frame_Chunk
));
4364 look_for
= is_eh
? start
- 4 - cie_id
: section_start
+ cie_id
;
4366 for (cie
= chunks
; cie
; cie
= cie
->next
)
4367 if (cie
->chunk_start
== look_for
)
4372 warn ("Invalid CIE pointer %#08lx in FDE at %#08lx\n",
4373 cie_id
, (unsigned long)(saved_start
- section_start
));
4375 fc
->col_type
= (short int *) xmalloc (sizeof (short int));
4376 fc
->col_offset
= (int *) xmalloc (sizeof (int));
4377 frame_need_space (fc
, max_regs
- 1);
4379 fc
->augmentation
= "";
4380 fc
->fde_encoding
= 0;
4381 fc
->ptr_size
= eh_addr_size
;
4382 fc
->segment_size
= 0;
4386 fc
->ncols
= cie
->ncols
;
4387 fc
->col_type
= (short int *) xcmalloc (fc
->ncols
, sizeof (short int));
4388 fc
->col_offset
= (int *) xcmalloc (fc
->ncols
, sizeof (int));
4389 memcpy (fc
->col_type
, cie
->col_type
, fc
->ncols
* sizeof (short int));
4390 memcpy (fc
->col_offset
, cie
->col_offset
, fc
->ncols
* sizeof (int));
4391 fc
->augmentation
= cie
->augmentation
;
4392 fc
->ptr_size
= cie
->ptr_size
;
4393 eh_addr_size
= cie
->ptr_size
;
4394 fc
->segment_size
= cie
->segment_size
;
4395 fc
->code_factor
= cie
->code_factor
;
4396 fc
->data_factor
= cie
->data_factor
;
4397 fc
->cfa_reg
= cie
->cfa_reg
;
4398 fc
->cfa_offset
= cie
->cfa_offset
;
4400 frame_need_space (fc
, max_regs
- 1);
4401 fc
->fde_encoding
= cie
->fde_encoding
;
4404 if (fc
->fde_encoding
)
4405 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
4407 segment_selector
= 0;
4408 if (fc
->segment_size
)
4410 segment_selector
= byte_get (start
, fc
->segment_size
);
4411 start
+= fc
->segment_size
;
4413 fc
->pc_begin
= get_encoded_value (start
, fc
->fde_encoding
, section
);
4414 start
+= encoded_ptr_size
;
4415 fc
->pc_range
= byte_get (start
, encoded_ptr_size
);
4416 start
+= encoded_ptr_size
;
4418 if (cie
->augmentation
[0] == 'z')
4420 augmentation_data_len
= LEB ();
4421 augmentation_data
= start
;
4422 start
+= augmentation_data_len
;
4425 printf ("\n%08lx %08lx %08lx FDE cie=%08lx pc=",
4426 (unsigned long)(saved_start
- section_start
), length
, cie_id
,
4427 (unsigned long)(cie
->chunk_start
- section_start
));
4428 if (fc
->segment_size
)
4429 printf ("%04lx:", segment_selector
);
4430 printf ("%08lx..%08lx\n", fc
->pc_begin
, fc
->pc_begin
+ fc
->pc_range
);
4431 if (! do_debug_frames_interp
&& augmentation_data_len
)
4435 printf (" Augmentation data: ");
4436 for (i
= 0; i
< augmentation_data_len
; ++i
)
4437 printf (" %02x", augmentation_data
[i
]);
4443 /* At this point, fc is the current chunk, cie (if any) is set, and
4444 we're about to interpret instructions for the chunk. */
4445 /* ??? At present we need to do this always, since this sizes the
4446 fc->col_type and fc->col_offset arrays, which we write into always.
4447 We should probably split the interpreted and non-interpreted bits
4448 into two different routines, since there's so much that doesn't
4449 really overlap between them. */
4450 if (1 || do_debug_frames_interp
)
4452 /* Start by making a pass over the chunk, allocating storage
4453 and taking note of what registers are used. */
4454 unsigned char *tmp
= start
;
4456 while (start
< block_end
)
4459 unsigned long reg
, temp
;
4466 /* Warning: if you add any more cases to this switch, be
4467 sure to add them to the corresponding switch below. */
4470 case DW_CFA_advance_loc
:
4474 if (frame_need_space (fc
, opa
) >= 0)
4475 fc
->col_type
[opa
] = DW_CFA_undefined
;
4477 case DW_CFA_restore
:
4478 if (frame_need_space (fc
, opa
) >= 0)
4479 fc
->col_type
[opa
] = DW_CFA_undefined
;
4481 case DW_CFA_set_loc
:
4482 start
+= encoded_ptr_size
;
4484 case DW_CFA_advance_loc1
:
4487 case DW_CFA_advance_loc2
:
4490 case DW_CFA_advance_loc4
:
4493 case DW_CFA_offset_extended
:
4494 case DW_CFA_val_offset
:
4495 reg
= LEB (); LEB ();
4496 if (frame_need_space (fc
, reg
) >= 0)
4497 fc
->col_type
[reg
] = DW_CFA_undefined
;
4499 case DW_CFA_restore_extended
:
4501 frame_need_space (fc
, reg
);
4502 if (frame_need_space (fc
, reg
) >= 0)
4503 fc
->col_type
[reg
] = DW_CFA_undefined
;
4505 case DW_CFA_undefined
:
4507 if (frame_need_space (fc
, reg
) >= 0)
4508 fc
->col_type
[reg
] = DW_CFA_undefined
;
4510 case DW_CFA_same_value
:
4512 if (frame_need_space (fc
, reg
) >= 0)
4513 fc
->col_type
[reg
] = DW_CFA_undefined
;
4515 case DW_CFA_register
:
4516 reg
= LEB (); LEB ();
4517 if (frame_need_space (fc
, reg
) >= 0)
4518 fc
->col_type
[reg
] = DW_CFA_undefined
;
4520 case DW_CFA_def_cfa
:
4523 case DW_CFA_def_cfa_register
:
4526 case DW_CFA_def_cfa_offset
:
4529 case DW_CFA_def_cfa_expression
:
4533 case DW_CFA_expression
:
4534 case DW_CFA_val_expression
:
4538 if (frame_need_space (fc
, reg
) >= 0)
4539 fc
->col_type
[reg
] = DW_CFA_undefined
;
4541 case DW_CFA_offset_extended_sf
:
4542 case DW_CFA_val_offset_sf
:
4543 reg
= LEB (); SLEB ();
4544 if (frame_need_space (fc
, reg
) >= 0)
4545 fc
->col_type
[reg
] = DW_CFA_undefined
;
4547 case DW_CFA_def_cfa_sf
:
4550 case DW_CFA_def_cfa_offset_sf
:
4553 case DW_CFA_MIPS_advance_loc8
:
4556 case DW_CFA_GNU_args_size
:
4559 case DW_CFA_GNU_negative_offset_extended
:
4560 reg
= LEB (); LEB ();
4561 if (frame_need_space (fc
, reg
) >= 0)
4562 fc
->col_type
[reg
] = DW_CFA_undefined
;
4571 /* Now we know what registers are used, make a second pass over
4572 the chunk, this time actually printing out the info. */
4574 while (start
< block_end
)
4577 unsigned long ul
, reg
, roffs
;
4580 const char *reg_prefix
= "";
4587 /* Warning: if you add any more cases to this switch, be
4588 sure to add them to the corresponding switch above. */
4591 case DW_CFA_advance_loc
:
4592 if (do_debug_frames_interp
)
4593 frame_display_row (fc
, &need_col_headers
, &max_regs
);
4595 printf (" DW_CFA_advance_loc: %d to %08lx\n",
4596 opa
* fc
->code_factor
,
4597 fc
->pc_begin
+ opa
* fc
->code_factor
);
4598 fc
->pc_begin
+= opa
* fc
->code_factor
;
4603 if (opa
>= (unsigned int) fc
->ncols
)
4604 reg_prefix
= bad_reg
;
4605 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4606 printf (" DW_CFA_offset: %s%s at cfa%+ld\n",
4607 reg_prefix
, regname (opa
, 0),
4608 roffs
* fc
->data_factor
);
4609 if (*reg_prefix
== '\0')
4611 fc
->col_type
[opa
] = DW_CFA_offset
;
4612 fc
->col_offset
[opa
] = roffs
* fc
->data_factor
;
4616 case DW_CFA_restore
:
4617 if (opa
>= (unsigned int) cie
->ncols
4618 || opa
>= (unsigned int) fc
->ncols
)
4619 reg_prefix
= bad_reg
;
4620 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4621 printf (" DW_CFA_restore: %s%s\n",
4622 reg_prefix
, regname (opa
, 0));
4623 if (*reg_prefix
== '\0')
4625 fc
->col_type
[opa
] = cie
->col_type
[opa
];
4626 fc
->col_offset
[opa
] = cie
->col_offset
[opa
];
4630 case DW_CFA_set_loc
:
4631 vma
= get_encoded_value (start
, fc
->fde_encoding
, section
);
4632 start
+= encoded_ptr_size
;
4633 if (do_debug_frames_interp
)
4634 frame_display_row (fc
, &need_col_headers
, &max_regs
);
4636 printf (" DW_CFA_set_loc: %08lx\n", (unsigned long)vma
);
4640 case DW_CFA_advance_loc1
:
4641 ofs
= byte_get (start
, 1); start
+= 1;
4642 if (do_debug_frames_interp
)
4643 frame_display_row (fc
, &need_col_headers
, &max_regs
);
4645 printf (" DW_CFA_advance_loc1: %ld to %08lx\n",
4646 ofs
* fc
->code_factor
,
4647 fc
->pc_begin
+ ofs
* fc
->code_factor
);
4648 fc
->pc_begin
+= ofs
* fc
->code_factor
;
4651 case DW_CFA_advance_loc2
:
4652 ofs
= byte_get (start
, 2); start
+= 2;
4653 if (do_debug_frames_interp
)
4654 frame_display_row (fc
, &need_col_headers
, &max_regs
);
4656 printf (" DW_CFA_advance_loc2: %ld to %08lx\n",
4657 ofs
* fc
->code_factor
,
4658 fc
->pc_begin
+ ofs
* fc
->code_factor
);
4659 fc
->pc_begin
+= ofs
* fc
->code_factor
;
4662 case DW_CFA_advance_loc4
:
4663 ofs
= byte_get (start
, 4); start
+= 4;
4664 if (do_debug_frames_interp
)
4665 frame_display_row (fc
, &need_col_headers
, &max_regs
);
4667 printf (" DW_CFA_advance_loc4: %ld to %08lx\n",
4668 ofs
* fc
->code_factor
,
4669 fc
->pc_begin
+ ofs
* fc
->code_factor
);
4670 fc
->pc_begin
+= ofs
* fc
->code_factor
;
4673 case DW_CFA_offset_extended
:
4676 if (reg
>= (unsigned int) fc
->ncols
)
4677 reg_prefix
= bad_reg
;
4678 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4679 printf (" DW_CFA_offset_extended: %s%s at cfa%+ld\n",
4680 reg_prefix
, regname (reg
, 0),
4681 roffs
* fc
->data_factor
);
4682 if (*reg_prefix
== '\0')
4684 fc
->col_type
[reg
] = DW_CFA_offset
;
4685 fc
->col_offset
[reg
] = roffs
* fc
->data_factor
;
4689 case DW_CFA_val_offset
:
4692 if (reg
>= (unsigned int) fc
->ncols
)
4693 reg_prefix
= bad_reg
;
4694 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4695 printf (" DW_CFA_val_offset: %s%s at cfa%+ld\n",
4696 reg_prefix
, regname (reg
, 0),
4697 roffs
* fc
->data_factor
);
4698 if (*reg_prefix
== '\0')
4700 fc
->col_type
[reg
] = DW_CFA_val_offset
;
4701 fc
->col_offset
[reg
] = roffs
* fc
->data_factor
;
4705 case DW_CFA_restore_extended
:
4707 if (reg
>= (unsigned int) cie
->ncols
4708 || reg
>= (unsigned int) fc
->ncols
)
4709 reg_prefix
= bad_reg
;
4710 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4711 printf (" DW_CFA_restore_extended: %s%s\n",
4712 reg_prefix
, regname (reg
, 0));
4713 if (*reg_prefix
== '\0')
4715 fc
->col_type
[reg
] = cie
->col_type
[reg
];
4716 fc
->col_offset
[reg
] = cie
->col_offset
[reg
];
4720 case DW_CFA_undefined
:
4722 if (reg
>= (unsigned int) fc
->ncols
)
4723 reg_prefix
= bad_reg
;
4724 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4725 printf (" DW_CFA_undefined: %s%s\n",
4726 reg_prefix
, regname (reg
, 0));
4727 if (*reg_prefix
== '\0')
4729 fc
->col_type
[reg
] = DW_CFA_undefined
;
4730 fc
->col_offset
[reg
] = 0;
4734 case DW_CFA_same_value
:
4736 if (reg
>= (unsigned int) fc
->ncols
)
4737 reg_prefix
= bad_reg
;
4738 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4739 printf (" DW_CFA_same_value: %s%s\n",
4740 reg_prefix
, regname (reg
, 0));
4741 if (*reg_prefix
== '\0')
4743 fc
->col_type
[reg
] = DW_CFA_same_value
;
4744 fc
->col_offset
[reg
] = 0;
4748 case DW_CFA_register
:
4751 if (reg
>= (unsigned int) fc
->ncols
)
4752 reg_prefix
= bad_reg
;
4753 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4755 printf (" DW_CFA_register: %s%s in ",
4756 reg_prefix
, regname (reg
, 0));
4757 puts (regname (roffs
, 0));
4759 if (*reg_prefix
== '\0')
4761 fc
->col_type
[reg
] = DW_CFA_register
;
4762 fc
->col_offset
[reg
] = roffs
;
4766 case DW_CFA_remember_state
:
4767 if (! do_debug_frames_interp
)
4768 printf (" DW_CFA_remember_state\n");
4769 rs
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
4770 rs
->ncols
= fc
->ncols
;
4771 rs
->col_type
= (short int *) xcmalloc (rs
->ncols
,
4772 sizeof (short int));
4773 rs
->col_offset
= (int *) xcmalloc (rs
->ncols
, sizeof (int));
4774 memcpy (rs
->col_type
, fc
->col_type
, rs
->ncols
);
4775 memcpy (rs
->col_offset
, fc
->col_offset
, rs
->ncols
* sizeof (int));
4776 rs
->next
= remembered_state
;
4777 remembered_state
= rs
;
4780 case DW_CFA_restore_state
:
4781 if (! do_debug_frames_interp
)
4782 printf (" DW_CFA_restore_state\n");
4783 rs
= remembered_state
;
4786 remembered_state
= rs
->next
;
4787 frame_need_space (fc
, rs
->ncols
- 1);
4788 memcpy (fc
->col_type
, rs
->col_type
, rs
->ncols
);
4789 memcpy (fc
->col_offset
, rs
->col_offset
,
4790 rs
->ncols
* sizeof (int));
4791 free (rs
->col_type
);
4792 free (rs
->col_offset
);
4795 else if (do_debug_frames_interp
)
4796 printf ("Mismatched DW_CFA_restore_state\n");
4799 case DW_CFA_def_cfa
:
4800 fc
->cfa_reg
= LEB ();
4801 fc
->cfa_offset
= LEB ();
4803 if (! do_debug_frames_interp
)
4804 printf (" DW_CFA_def_cfa: %s ofs %d\n",
4805 regname (fc
->cfa_reg
, 0), fc
->cfa_offset
);
4808 case DW_CFA_def_cfa_register
:
4809 fc
->cfa_reg
= LEB ();
4811 if (! do_debug_frames_interp
)
4812 printf (" DW_CFA_def_cfa_register: %s\n",
4813 regname (fc
->cfa_reg
, 0));
4816 case DW_CFA_def_cfa_offset
:
4817 fc
->cfa_offset
= LEB ();
4818 if (! do_debug_frames_interp
)
4819 printf (" DW_CFA_def_cfa_offset: %d\n", fc
->cfa_offset
);
4823 if (! do_debug_frames_interp
)
4824 printf (" DW_CFA_nop\n");
4827 case DW_CFA_def_cfa_expression
:
4829 if (! do_debug_frames_interp
)
4831 printf (" DW_CFA_def_cfa_expression (");
4832 decode_location_expression (start
, eh_addr_size
, 0, -1,
4840 case DW_CFA_expression
:
4843 if (reg
>= (unsigned int) fc
->ncols
)
4844 reg_prefix
= bad_reg
;
4845 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4847 printf (" DW_CFA_expression: %s%s (",
4848 reg_prefix
, regname (reg
, 0));
4849 decode_location_expression (start
, eh_addr_size
, 0, -1,
4853 if (*reg_prefix
== '\0')
4854 fc
->col_type
[reg
] = DW_CFA_expression
;
4858 case DW_CFA_val_expression
:
4861 if (reg
>= (unsigned int) fc
->ncols
)
4862 reg_prefix
= bad_reg
;
4863 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4865 printf (" DW_CFA_val_expression: %s%s (",
4866 reg_prefix
, regname (reg
, 0));
4867 decode_location_expression (start
, eh_addr_size
, 0, -1,
4871 if (*reg_prefix
== '\0')
4872 fc
->col_type
[reg
] = DW_CFA_val_expression
;
4876 case DW_CFA_offset_extended_sf
:
4879 if (frame_need_space (fc
, reg
) < 0)
4880 reg_prefix
= bad_reg
;
4881 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4882 printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+ld\n",
4883 reg_prefix
, regname (reg
, 0),
4884 l
* fc
->data_factor
);
4885 if (*reg_prefix
== '\0')
4887 fc
->col_type
[reg
] = DW_CFA_offset
;
4888 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
4892 case DW_CFA_val_offset_sf
:
4895 if (frame_need_space (fc
, reg
) < 0)
4896 reg_prefix
= bad_reg
;
4897 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4898 printf (" DW_CFA_val_offset_sf: %s%s at cfa%+ld\n",
4899 reg_prefix
, regname (reg
, 0),
4900 l
* fc
->data_factor
);
4901 if (*reg_prefix
== '\0')
4903 fc
->col_type
[reg
] = DW_CFA_val_offset
;
4904 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
4908 case DW_CFA_def_cfa_sf
:
4909 fc
->cfa_reg
= LEB ();
4910 fc
->cfa_offset
= SLEB ();
4911 fc
->cfa_offset
= fc
->cfa_offset
* fc
->data_factor
;
4913 if (! do_debug_frames_interp
)
4914 printf (" DW_CFA_def_cfa_sf: %s ofs %d\n",
4915 regname (fc
->cfa_reg
, 0), fc
->cfa_offset
);
4918 case DW_CFA_def_cfa_offset_sf
:
4919 fc
->cfa_offset
= SLEB ();
4920 fc
->cfa_offset
= fc
->cfa_offset
* fc
->data_factor
;
4921 if (! do_debug_frames_interp
)
4922 printf (" DW_CFA_def_cfa_offset_sf: %d\n", fc
->cfa_offset
);
4925 case DW_CFA_MIPS_advance_loc8
:
4926 ofs
= byte_get (start
, 8); start
+= 8;
4927 if (do_debug_frames_interp
)
4928 frame_display_row (fc
, &need_col_headers
, &max_regs
);
4930 printf (" DW_CFA_MIPS_advance_loc8: %ld to %08lx\n",
4931 ofs
* fc
->code_factor
,
4932 fc
->pc_begin
+ ofs
* fc
->code_factor
);
4933 fc
->pc_begin
+= ofs
* fc
->code_factor
;
4936 case DW_CFA_GNU_window_save
:
4937 if (! do_debug_frames_interp
)
4938 printf (" DW_CFA_GNU_window_save\n");
4941 case DW_CFA_GNU_args_size
:
4943 if (! do_debug_frames_interp
)
4944 printf (" DW_CFA_GNU_args_size: %ld\n", ul
);
4947 case DW_CFA_GNU_negative_offset_extended
:
4950 if (frame_need_space (fc
, reg
) < 0)
4951 reg_prefix
= bad_reg
;
4952 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4953 printf (" DW_CFA_GNU_negative_offset_extended: %s%s at cfa%+ld\n",
4954 reg_prefix
, regname (reg
, 0),
4955 l
* fc
->data_factor
);
4956 if (*reg_prefix
== '\0')
4958 fc
->col_type
[reg
] = DW_CFA_offset
;
4959 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
4964 if (op
>= DW_CFA_lo_user
&& op
<= DW_CFA_hi_user
)
4965 printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op
);
4967 warn (_("unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op
);
4972 if (do_debug_frames_interp
)
4973 frame_display_row (fc
, &need_col_headers
, &max_regs
);
4976 eh_addr_size
= saved_eh_addr_size
;
4989 display_gdb_index (struct dwarf_section
*section
,
4990 void *file ATTRIBUTE_UNUSED
)
4992 unsigned char *start
= section
->start
;
4994 uint32_t cu_list_offset
, tu_list_offset
;
4995 uint32_t address_table_offset
, symbol_table_offset
, constant_pool_offset
;
4996 unsigned int cu_list_elements
, tu_list_elements
;
4997 unsigned int address_table_size
, symbol_table_slots
;
4998 unsigned char *cu_list
, *tu_list
;
4999 unsigned char *address_table
, *symbol_table
, *constant_pool
;
5002 /* The documentation for the format of this file is in gdb/dwarf2read.c. */
5004 printf (_("Contents of the %s section:\n"), section
->name
);
5006 if (section
->size
< 6 * sizeof (uint32_t))
5008 warn (_("Truncated header in the %s section.\n"), section
->name
);
5012 version
= byte_get_little_endian (start
, 4);
5013 printf (_("Version %ld\n"), (long) version
);
5015 /* Prior versions are obsolete, and future versions may not be
5016 backwards compatible. */
5020 warn (_("The address table data in version 3 may be wrong.\n"));
5025 warn (_("Unsupported version %lu.\n"), (unsigned long) version
);
5029 cu_list_offset
= byte_get_little_endian (start
+ 4, 4);
5030 tu_list_offset
= byte_get_little_endian (start
+ 8, 4);
5031 address_table_offset
= byte_get_little_endian (start
+ 12, 4);
5032 symbol_table_offset
= byte_get_little_endian (start
+ 16, 4);
5033 constant_pool_offset
= byte_get_little_endian (start
+ 20, 4);
5035 if (cu_list_offset
> section
->size
5036 || tu_list_offset
> section
->size
5037 || address_table_offset
> section
->size
5038 || symbol_table_offset
> section
->size
5039 || constant_pool_offset
> section
->size
)
5041 warn (_("Corrupt header in the %s section.\n"), section
->name
);
5045 cu_list_elements
= (tu_list_offset
- cu_list_offset
) / 8;
5046 tu_list_elements
= (address_table_offset
- tu_list_offset
) / 8;
5047 address_table_size
= symbol_table_offset
- address_table_offset
;
5048 symbol_table_slots
= (constant_pool_offset
- symbol_table_offset
) / 8;
5050 cu_list
= start
+ cu_list_offset
;
5051 tu_list
= start
+ tu_list_offset
;
5052 address_table
= start
+ address_table_offset
;
5053 symbol_table
= start
+ symbol_table_offset
;
5054 constant_pool
= start
+ constant_pool_offset
;
5056 printf (_("\nCU table:\n"));
5057 for (i
= 0; i
< cu_list_elements
; i
+= 2)
5059 uint64_t cu_offset
= byte_get_little_endian (cu_list
+ i
* 8, 8);
5060 uint64_t cu_length
= byte_get_little_endian (cu_list
+ i
* 8 + 8, 8);
5062 printf (_("[%3u] 0x%lx - 0x%lx\n"), i
/ 2,
5063 (unsigned long) cu_offset
,
5064 (unsigned long) (cu_offset
+ cu_length
- 1));
5067 printf (_("\nTU table:\n"));
5068 for (i
= 0; i
< tu_list_elements
; i
+= 3)
5070 uint64_t tu_offset
= byte_get_little_endian (tu_list
+ i
* 8, 8);
5071 uint64_t type_offset
= byte_get_little_endian (tu_list
+ i
* 8 + 8, 8);
5072 uint64_t signature
= byte_get_little_endian (tu_list
+ i
* 8 + 16, 8);
5074 printf (_("[%3u] 0x%lx 0x%lx "), i
/ 3,
5075 (unsigned long) tu_offset
,
5076 (unsigned long) type_offset
);
5077 print_dwarf_vma (signature
, 8);
5081 printf (_("\nAddress table:\n"));
5082 for (i
= 0; i
< address_table_size
; i
+= 2 * 8 + 4)
5084 uint64_t low
= byte_get_little_endian (address_table
+ i
, 8);
5085 uint64_t high
= byte_get_little_endian (address_table
+ i
+ 8, 8);
5086 uint32_t cu_index
= byte_get_little_endian (address_table
+ i
+ 16, 4);
5088 print_dwarf_vma (low
, 8);
5089 print_dwarf_vma (high
, 8);
5090 printf (_("%lu\n"), (unsigned long) cu_index
);
5093 printf (_("\nSymbol table:\n"));
5094 for (i
= 0; i
< symbol_table_slots
; ++i
)
5096 uint32_t name_offset
= byte_get_little_endian (symbol_table
+ i
* 8, 4);
5097 uint32_t cu_vector_offset
= byte_get_little_endian (symbol_table
+ i
* 8 + 4, 4);
5098 uint32_t num_cus
, cu
;
5100 if (name_offset
!= 0
5101 || cu_vector_offset
!= 0)
5105 printf ("[%3u] %s:", i
, constant_pool
+ name_offset
);
5106 num_cus
= byte_get_little_endian (constant_pool
+ cu_vector_offset
, 4);
5107 for (j
= 0; j
< num_cus
; ++j
)
5109 cu
= byte_get_little_endian (constant_pool
+ cu_vector_offset
+ 4 + j
* 4, 4);
5110 /* Convert to TU number if it's for a type unit. */
5111 if (cu
>= cu_list_elements
)
5112 printf (" T%lu", (unsigned long) (cu
- cu_list_elements
));
5114 printf (" %lu", (unsigned long) cu
);
5124 display_debug_not_supported (struct dwarf_section
*section
,
5125 void *file ATTRIBUTE_UNUSED
)
5127 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
5134 cmalloc (size_t nmemb
, size_t size
)
5136 /* Check for overflow. */
5137 if (nmemb
>= ~(size_t) 0 / size
)
5140 return malloc (nmemb
* size
);
5144 xcmalloc (size_t nmemb
, size_t size
)
5146 /* Check for overflow. */
5147 if (nmemb
>= ~(size_t) 0 / size
)
5150 return xmalloc (nmemb
* size
);
5154 xcrealloc (void *ptr
, size_t nmemb
, size_t size
)
5156 /* Check for overflow. */
5157 if (nmemb
>= ~(size_t) 0 / size
)
5160 return xrealloc (ptr
, nmemb
* size
);
5164 free_debug_memory (void)
5170 for (i
= 0; i
< max
; i
++)
5171 free_debug_section ((enum dwarf_section_display_enum
) i
);
5173 if (debug_information
!= NULL
)
5175 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
)
5177 for (i
= 0; i
< num_debug_info_entries
; i
++)
5179 if (!debug_information
[i
].max_loc_offsets
)
5181 free (debug_information
[i
].loc_offsets
);
5182 free (debug_information
[i
].have_frame_base
);
5184 if (!debug_information
[i
].max_range_lists
)
5185 free (debug_information
[i
].range_lists
);
5189 free (debug_information
);
5190 debug_information
= NULL
;
5191 num_debug_info_entries
= 0;
5196 dwarf_select_sections_by_names (const char *names
)
5200 const char * option
;
5204 debug_dump_long_opts
;
5206 static const debug_dump_long_opts opts_table
[] =
5208 /* Please keep this table alpha- sorted. */
5209 { "Ranges", & do_debug_ranges
, 1 },
5210 { "abbrev", & do_debug_abbrevs
, 1 },
5211 { "aranges", & do_debug_aranges
, 1 },
5212 { "frames", & do_debug_frames
, 1 },
5213 { "frames-interp", & do_debug_frames_interp
, 1 },
5214 { "info", & do_debug_info
, 1 },
5215 { "line", & do_debug_lines
, FLAG_DEBUG_LINES_RAW
}, /* For backwards compatibility. */
5216 { "rawline", & do_debug_lines
, FLAG_DEBUG_LINES_RAW
},
5217 { "decodedline", & do_debug_lines
, FLAG_DEBUG_LINES_DECODED
},
5218 { "loc", & do_debug_loc
, 1 },
5219 { "macro", & do_debug_macinfo
, 1 },
5220 { "pubnames", & do_debug_pubnames
, 1 },
5221 { "pubtypes", & do_debug_pubtypes
, 1 },
5222 /* This entry is for compatability
5223 with earlier versions of readelf. */
5224 { "ranges", & do_debug_aranges
, 1 },
5225 { "str", & do_debug_str
, 1 },
5226 /* The special .gdb_index section. */
5227 { "gdb_index", & do_gdb_index
, 1 },
5228 /* These trace_* sections are used by Itanium VMS. */
5229 { "trace_abbrev", & do_trace_abbrevs
, 1 },
5230 { "trace_aranges", & do_trace_aranges
, 1 },
5231 { "trace_info", & do_trace_info
, 1 },
5240 const debug_dump_long_opts
* entry
;
5242 for (entry
= opts_table
; entry
->option
; entry
++)
5244 size_t len
= strlen (entry
->option
);
5246 if (strncmp (p
, entry
->option
, len
) == 0
5247 && (p
[len
] == ',' || p
[len
] == '\0'))
5249 * entry
->variable
|= entry
->val
;
5251 /* The --debug-dump=frames-interp option also
5252 enables the --debug-dump=frames option. */
5253 if (do_debug_frames_interp
)
5254 do_debug_frames
= 1;
5261 if (entry
->option
== NULL
)
5263 warn (_("Unrecognized debug option '%s'\n"), p
);
5264 p
= strchr (p
, ',');
5275 dwarf_select_sections_by_letters (const char *letters
)
5277 unsigned int lindex
= 0;
5279 while (letters
[lindex
])
5280 switch (letters
[lindex
++])
5287 do_debug_abbrevs
= 1;
5291 do_debug_lines
|= FLAG_DEBUG_LINES_RAW
;
5295 do_debug_lines
|= FLAG_DEBUG_LINES_DECODED
;
5299 do_debug_pubnames
= 1;
5303 do_debug_pubtypes
= 1;
5307 do_debug_aranges
= 1;
5311 do_debug_ranges
= 1;
5315 do_debug_frames_interp
= 1;
5317 do_debug_frames
= 1;
5321 do_debug_macinfo
= 1;
5333 warn (_("Unrecognized debug option '%s'\n"), optarg
);
5339 dwarf_select_sections_all (void)
5342 do_debug_abbrevs
= 1;
5343 do_debug_lines
= FLAG_DEBUG_LINES_RAW
;
5344 do_debug_pubnames
= 1;
5345 do_debug_pubtypes
= 1;
5346 do_debug_aranges
= 1;
5347 do_debug_ranges
= 1;
5348 do_debug_frames
= 1;
5349 do_debug_macinfo
= 1;
5354 do_trace_abbrevs
= 1;
5355 do_trace_aranges
= 1;
5358 struct dwarf_section_display debug_displays
[] =
5360 { { ".debug_abbrev", ".zdebug_abbrev", NULL
, NULL
, 0, 0 },
5361 display_debug_abbrev
, &do_debug_abbrevs
, 0 },
5362 { { ".debug_aranges", ".zdebug_aranges", NULL
, NULL
, 0, 0 },
5363 display_debug_aranges
, &do_debug_aranges
, 1 },
5364 { { ".debug_frame", ".zdebug_frame", NULL
, NULL
, 0, 0 },
5365 display_debug_frames
, &do_debug_frames
, 1 },
5366 { { ".debug_info", ".zdebug_info", NULL
, NULL
, 0, 0 },
5367 display_debug_info
, &do_debug_info
, 1 },
5368 { { ".debug_line", ".zdebug_line", NULL
, NULL
, 0, 0 },
5369 display_debug_lines
, &do_debug_lines
, 1 },
5370 { { ".debug_pubnames", ".zdebug_pubnames", NULL
, NULL
, 0, 0 },
5371 display_debug_pubnames
, &do_debug_pubnames
, 0 },
5372 { { ".eh_frame", "", NULL
, NULL
, 0, 0 },
5373 display_debug_frames
, &do_debug_frames
, 1 },
5374 { { ".debug_macinfo", ".zdebug_macinfo", NULL
, NULL
, 0, 0 },
5375 display_debug_macinfo
, &do_debug_macinfo
, 0 },
5376 { { ".debug_str", ".zdebug_str", NULL
, NULL
, 0, 0 },
5377 display_debug_str
, &do_debug_str
, 0 },
5378 { { ".debug_loc", ".zdebug_loc", NULL
, NULL
, 0, 0 },
5379 display_debug_loc
, &do_debug_loc
, 1 },
5380 { { ".debug_pubtypes", ".zdebug_pubtypes", NULL
, NULL
, 0, 0 },
5381 display_debug_pubnames
, &do_debug_pubtypes
, 0 },
5382 { { ".debug_ranges", ".zdebug_ranges", NULL
, NULL
, 0, 0 },
5383 display_debug_ranges
, &do_debug_ranges
, 1 },
5384 { { ".debug_static_func", ".zdebug_static_func", NULL
, NULL
, 0, 0 },
5385 display_debug_not_supported
, NULL
, 0 },
5386 { { ".debug_static_vars", ".zdebug_static_vars", NULL
, NULL
, 0, 0 },
5387 display_debug_not_supported
, NULL
, 0 },
5388 { { ".debug_types", ".zdebug_types", NULL
, NULL
, 0, 0 },
5389 display_debug_types
, &do_debug_info
, 1 },
5390 { { ".debug_weaknames", ".zdebug_weaknames", NULL
, NULL
, 0, 0 },
5391 display_debug_not_supported
, NULL
, 0 },
5392 { { ".gdb_index", "", NULL
, NULL
, 0, 0 },
5393 display_gdb_index
, &do_gdb_index
, 0 },
5394 { { ".trace_info", "", NULL
, NULL
, 0, 0 },
5395 display_trace_info
, &do_trace_info
, 1 },
5396 { { ".trace_abbrev", "", NULL
, NULL
, 0, 0 },
5397 display_debug_abbrev
, &do_trace_abbrevs
, 0 },
5398 { { ".trace_aranges", "", NULL
, NULL
, 0, 0 },
5399 display_debug_aranges
, &do_trace_aranges
, 0 }