1 /* dwarf.c -- display DWARF contents of a BFD binary file
2 Copyright 2005, 2006, 2007, 2008
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"
26 #include "elf/common.h"
27 #include "elf/dwarf2.h"
30 static int have_frame_base
;
31 static int need_base_address
;
33 static unsigned int last_pointer_size
= 0;
34 static int warned_about_missing_comp_units
= FALSE
;
36 static unsigned int num_debug_info_entries
= 0;
37 static debug_info
*debug_information
= NULL
;
38 /* Special value for num_debug_info_entries to indicate
39 that the .debug_info section could not be loaded/parsed. */
40 #define DEBUG_INFO_UNAVAILABLE (unsigned int) -1
47 int do_debug_lines_decoded
;
48 int do_debug_pubnames
;
52 int do_debug_frames_interp
;
58 dwarf_vma (*byte_get
) (unsigned char *, int);
61 byte_get_little_endian (unsigned char *field
, int size
)
69 return ((unsigned int) (field
[0]))
70 | (((unsigned int) (field
[1])) << 8);
73 return ((unsigned long) (field
[0]))
74 | (((unsigned long) (field
[1])) << 8)
75 | (((unsigned long) (field
[2])) << 16)
76 | (((unsigned long) (field
[3])) << 24);
79 if (sizeof (dwarf_vma
) == 8)
80 return ((dwarf_vma
) (field
[0]))
81 | (((dwarf_vma
) (field
[1])) << 8)
82 | (((dwarf_vma
) (field
[2])) << 16)
83 | (((dwarf_vma
) (field
[3])) << 24)
84 | (((dwarf_vma
) (field
[4])) << 32)
85 | (((dwarf_vma
) (field
[5])) << 40)
86 | (((dwarf_vma
) (field
[6])) << 48)
87 | (((dwarf_vma
) (field
[7])) << 56);
88 else if (sizeof (dwarf_vma
) == 4)
89 /* We want to extract data from an 8 byte wide field and
90 place it into a 4 byte wide field. Since this is a little
91 endian source we can just use the 4 byte extraction code. */
92 return ((unsigned long) (field
[0]))
93 | (((unsigned long) (field
[1])) << 8)
94 | (((unsigned long) (field
[2])) << 16)
95 | (((unsigned long) (field
[3])) << 24);
98 error (_("Unhandled data length: %d\n"), size
);
104 byte_get_big_endian (unsigned char *field
, int size
)
112 return ((unsigned int) (field
[1])) | (((int) (field
[0])) << 8);
115 return ((unsigned long) (field
[3]))
116 | (((unsigned long) (field
[2])) << 8)
117 | (((unsigned long) (field
[1])) << 16)
118 | (((unsigned long) (field
[0])) << 24);
121 if (sizeof (dwarf_vma
) == 8)
122 return ((dwarf_vma
) (field
[7]))
123 | (((dwarf_vma
) (field
[6])) << 8)
124 | (((dwarf_vma
) (field
[5])) << 16)
125 | (((dwarf_vma
) (field
[4])) << 24)
126 | (((dwarf_vma
) (field
[3])) << 32)
127 | (((dwarf_vma
) (field
[2])) << 40)
128 | (((dwarf_vma
) (field
[1])) << 48)
129 | (((dwarf_vma
) (field
[0])) << 56);
130 else if (sizeof (dwarf_vma
) == 4)
132 /* Although we are extracing data from an 8 byte wide field,
133 we are returning only 4 bytes of data. */
135 return ((unsigned long) (field
[3]))
136 | (((unsigned long) (field
[2])) << 8)
137 | (((unsigned long) (field
[1])) << 16)
138 | (((unsigned long) (field
[0])) << 24);
142 error (_("Unhandled data length: %d\n"), size
);
148 byte_get_signed (unsigned char *field
, int size
)
150 dwarf_vma x
= byte_get (field
, size
);
155 return (x
^ 0x80) - 0x80;
157 return (x
^ 0x8000) - 0x8000;
159 return (x
^ 0x80000000) - 0x80000000;
168 size_of_encoded_value (int encoding
)
170 switch (encoding
& 0x7)
173 case 0: return eh_addr_size
;
181 get_encoded_value (unsigned char *data
, int encoding
)
183 int size
= size_of_encoded_value (encoding
);
185 if (encoding
& DW_EH_PE_signed
)
186 return byte_get_signed (data
, size
);
188 return byte_get (data
, size
);
191 /* Print a dwarf_vma value (typically an address, offset or length) in
192 hexadecimal format, followed by a space. The length of the value (and
193 hence the precision displayed) is determined by the byte_size parameter. */
196 print_dwarf_vma (dwarf_vma val
, unsigned byte_size
)
198 static char buff
[18];
200 /* Printf does not have a way of specifiying a maximum field width for an
201 integer value, so we print the full value into a buffer and then select
202 the precision we need. */
203 #if __STDC_VERSION__ >= 199901L || (defined(__GNUC__) && __GNUC__ >= 2)
205 snprintf (buff
, sizeof (buff
), "%16.16llx ", val
);
207 snprintf (buff
, sizeof (buff
), "%016I64x ", val
);
210 snprintf (buff
, sizeof (buff
), "%16.16lx ", val
);
213 fputs (buff
+ (byte_size
== 4 ? 8 : 0), stdout
);
216 static unsigned long int
217 read_leb128 (unsigned char *data
, unsigned int *length_return
, int sign
)
219 unsigned long int result
= 0;
220 unsigned int num_read
= 0;
221 unsigned int shift
= 0;
229 result
|= ((unsigned long int) (byte
& 0x7f)) << shift
;
236 if (length_return
!= NULL
)
237 *length_return
= num_read
;
239 if (sign
&& (shift
< 8 * sizeof (result
)) && (byte
& 0x40))
240 result
|= -1L << shift
;
245 typedef struct State_Machine_Registers
247 unsigned long address
;
254 /* This variable hold the number of the last entry seen
255 in the File Table. */
256 unsigned int last_file_entry
;
259 static SMR state_machine_regs
;
262 reset_state_machine (int is_stmt
)
264 state_machine_regs
.address
= 0;
265 state_machine_regs
.file
= 1;
266 state_machine_regs
.line
= 1;
267 state_machine_regs
.column
= 0;
268 state_machine_regs
.is_stmt
= is_stmt
;
269 state_machine_regs
.basic_block
= 0;
270 state_machine_regs
.end_sequence
= 0;
271 state_machine_regs
.last_file_entry
= 0;
274 /* Handled an extend line op.
275 Returns the number of bytes read. */
278 process_extended_line_op (unsigned char *data
, int is_stmt
)
280 unsigned char op_code
;
281 unsigned int bytes_read
;
286 len
= read_leb128 (data
, & bytes_read
, 0);
291 warn (_("badly formed extended line op encountered!\n"));
298 printf (_(" Extended opcode %d: "), op_code
);
302 case DW_LNE_end_sequence
:
303 printf (_("End of Sequence\n\n"));
304 reset_state_machine (is_stmt
);
307 case DW_LNE_set_address
:
308 adr
= byte_get (data
, len
- bytes_read
- 1);
309 printf (_("set Address to 0x%lx\n"), adr
);
310 state_machine_regs
.address
= adr
;
313 case DW_LNE_define_file
:
314 printf (_(" define new File Table entry\n"));
315 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
317 printf (_(" %d\t"), ++state_machine_regs
.last_file_entry
);
319 data
+= strlen ((char *) data
) + 1;
320 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
322 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
324 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
325 printf (_("%s\n\n"), name
);
329 case DW_LNE_HP_negate_is_UV_update
:
330 printf ("DW_LNE_HP_negate_is_UV_update");
332 case DW_LNE_HP_push_context
:
333 printf ("DW_LNE_HP_push_context");
335 case DW_LNE_HP_pop_context
:
336 printf ("DW_LNE_HP_pop_context");
338 case DW_LNE_HP_set_file_line_column
:
339 printf ("DW_LNE_HP_set_file_line_column");
341 case DW_LNE_HP_set_routine_name
:
342 printf ("DW_LNE_HP_set_routine_name");
344 case DW_LNE_HP_set_sequence
:
345 printf ("DW_LNE_HP_set_sequence");
347 case DW_LNE_HP_negate_post_semantics
:
348 printf ("DW_LNE_HP_negate_post_semantics");
350 case DW_LNE_HP_negate_function_exit
:
351 printf ("DW_LNE_HP_negate_function_exit");
353 case DW_LNE_HP_negate_front_end_logical
:
354 printf ("DW_LNE_HP_negate_front_end_logical");
356 case DW_LNE_HP_define_proc
:
357 printf ("DW_LNE_HP_define_proc");
361 if (op_code
>= DW_LNE_lo_user
362 /* The test against DW_LNW_hi_user is redundant due to
363 the limited range of the unsigned char data type used
365 /*&& op_code <= DW_LNE_hi_user*/)
366 printf (_("user defined: length %d\n"), len
- bytes_read
);
368 printf (_("UNKNOWN: length %d\n"), len
- bytes_read
);
376 fetch_indirect_string (unsigned long offset
)
378 struct dwarf_section
*section
= &debug_displays
[str
].section
;
380 if (section
->start
== NULL
)
381 return _("<no .debug_str section>");
383 /* DWARF sections under Mach-O have non-zero addresses. */
384 offset
-= section
->address
;
385 if (offset
> section
->size
)
387 warn (_("DW_FORM_strp offset too big: %lx\n"), offset
);
388 return _("<offset is too big>");
391 return (const char *) section
->start
+ offset
;
394 /* FIXME: There are better and more efficient ways to handle
395 these structures. For now though, I just want something that
396 is simple to implement. */
397 typedef struct abbrev_attr
399 unsigned long attribute
;
401 struct abbrev_attr
*next
;
405 typedef struct abbrev_entry
410 struct abbrev_attr
*first_attr
;
411 struct abbrev_attr
*last_attr
;
412 struct abbrev_entry
*next
;
416 static abbrev_entry
*first_abbrev
= NULL
;
417 static abbrev_entry
*last_abbrev
= NULL
;
422 abbrev_entry
*abbrev
;
424 for (abbrev
= first_abbrev
; abbrev
;)
426 abbrev_entry
*next
= abbrev
->next
;
429 for (attr
= abbrev
->first_attr
; attr
;)
431 abbrev_attr
*next
= attr
->next
;
441 last_abbrev
= first_abbrev
= NULL
;
445 add_abbrev (unsigned long number
, unsigned long tag
, int children
)
449 entry
= malloc (sizeof (*entry
));
455 entry
->entry
= number
;
457 entry
->children
= children
;
458 entry
->first_attr
= NULL
;
459 entry
->last_attr
= NULL
;
462 if (first_abbrev
== NULL
)
463 first_abbrev
= entry
;
465 last_abbrev
->next
= entry
;
471 add_abbrev_attr (unsigned long attribute
, unsigned long form
)
475 attr
= malloc (sizeof (*attr
));
481 attr
->attribute
= attribute
;
485 if (last_abbrev
->first_attr
== NULL
)
486 last_abbrev
->first_attr
= attr
;
488 last_abbrev
->last_attr
->next
= attr
;
490 last_abbrev
->last_attr
= attr
;
493 /* Processes the (partial) contents of a .debug_abbrev section.
494 Returns NULL if the end of the section was encountered.
495 Returns the address after the last byte read if the end of
496 an abbreviation set was found. */
498 static unsigned char *
499 process_abbrev_section (unsigned char *start
, unsigned char *end
)
501 if (first_abbrev
!= NULL
)
506 unsigned int bytes_read
;
509 unsigned long attribute
;
512 entry
= read_leb128 (start
, & bytes_read
, 0);
515 /* A single zero is supposed to end the section according
516 to the standard. If there's more, then signal that to
519 return start
== end
? NULL
: start
;
521 tag
= read_leb128 (start
, & bytes_read
, 0);
526 add_abbrev (entry
, tag
, children
);
532 attribute
= read_leb128 (start
, & bytes_read
, 0);
535 form
= read_leb128 (start
, & bytes_read
, 0);
539 add_abbrev_attr (attribute
, form
);
541 while (attribute
!= 0);
548 get_TAG_name (unsigned long tag
)
552 case DW_TAG_padding
: return "DW_TAG_padding";
553 case DW_TAG_array_type
: return "DW_TAG_array_type";
554 case DW_TAG_class_type
: return "DW_TAG_class_type";
555 case DW_TAG_entry_point
: return "DW_TAG_entry_point";
556 case DW_TAG_enumeration_type
: return "DW_TAG_enumeration_type";
557 case DW_TAG_formal_parameter
: return "DW_TAG_formal_parameter";
558 case DW_TAG_imported_declaration
: return "DW_TAG_imported_declaration";
559 case DW_TAG_label
: return "DW_TAG_label";
560 case DW_TAG_lexical_block
: return "DW_TAG_lexical_block";
561 case DW_TAG_member
: return "DW_TAG_member";
562 case DW_TAG_pointer_type
: return "DW_TAG_pointer_type";
563 case DW_TAG_reference_type
: return "DW_TAG_reference_type";
564 case DW_TAG_compile_unit
: return "DW_TAG_compile_unit";
565 case DW_TAG_string_type
: return "DW_TAG_string_type";
566 case DW_TAG_structure_type
: return "DW_TAG_structure_type";
567 case DW_TAG_subroutine_type
: return "DW_TAG_subroutine_type";
568 case DW_TAG_typedef
: return "DW_TAG_typedef";
569 case DW_TAG_union_type
: return "DW_TAG_union_type";
570 case DW_TAG_unspecified_parameters
: return "DW_TAG_unspecified_parameters";
571 case DW_TAG_variant
: return "DW_TAG_variant";
572 case DW_TAG_common_block
: return "DW_TAG_common_block";
573 case DW_TAG_common_inclusion
: return "DW_TAG_common_inclusion";
574 case DW_TAG_inheritance
: return "DW_TAG_inheritance";
575 case DW_TAG_inlined_subroutine
: return "DW_TAG_inlined_subroutine";
576 case DW_TAG_module
: return "DW_TAG_module";
577 case DW_TAG_ptr_to_member_type
: return "DW_TAG_ptr_to_member_type";
578 case DW_TAG_set_type
: return "DW_TAG_set_type";
579 case DW_TAG_subrange_type
: return "DW_TAG_subrange_type";
580 case DW_TAG_with_stmt
: return "DW_TAG_with_stmt";
581 case DW_TAG_access_declaration
: return "DW_TAG_access_declaration";
582 case DW_TAG_base_type
: return "DW_TAG_base_type";
583 case DW_TAG_catch_block
: return "DW_TAG_catch_block";
584 case DW_TAG_const_type
: return "DW_TAG_const_type";
585 case DW_TAG_constant
: return "DW_TAG_constant";
586 case DW_TAG_enumerator
: return "DW_TAG_enumerator";
587 case DW_TAG_file_type
: return "DW_TAG_file_type";
588 case DW_TAG_friend
: return "DW_TAG_friend";
589 case DW_TAG_namelist
: return "DW_TAG_namelist";
590 case DW_TAG_namelist_item
: return "DW_TAG_namelist_item";
591 case DW_TAG_packed_type
: return "DW_TAG_packed_type";
592 case DW_TAG_subprogram
: return "DW_TAG_subprogram";
593 case DW_TAG_template_type_param
: return "DW_TAG_template_type_param";
594 case DW_TAG_template_value_param
: return "DW_TAG_template_value_param";
595 case DW_TAG_thrown_type
: return "DW_TAG_thrown_type";
596 case DW_TAG_try_block
: return "DW_TAG_try_block";
597 case DW_TAG_variant_part
: return "DW_TAG_variant_part";
598 case DW_TAG_variable
: return "DW_TAG_variable";
599 case DW_TAG_volatile_type
: return "DW_TAG_volatile_type";
600 case DW_TAG_MIPS_loop
: return "DW_TAG_MIPS_loop";
601 case DW_TAG_format_label
: return "DW_TAG_format_label";
602 case DW_TAG_function_template
: return "DW_TAG_function_template";
603 case DW_TAG_class_template
: return "DW_TAG_class_template";
604 /* DWARF 2.1 values. */
605 case DW_TAG_dwarf_procedure
: return "DW_TAG_dwarf_procedure";
606 case DW_TAG_restrict_type
: return "DW_TAG_restrict_type";
607 case DW_TAG_interface_type
: return "DW_TAG_interface_type";
608 case DW_TAG_namespace
: return "DW_TAG_namespace";
609 case DW_TAG_imported_module
: return "DW_TAG_imported_module";
610 case DW_TAG_unspecified_type
: return "DW_TAG_unspecified_type";
611 case DW_TAG_partial_unit
: return "DW_TAG_partial_unit";
612 case DW_TAG_imported_unit
: return "DW_TAG_imported_unit";
614 case DW_TAG_upc_shared_type
: return "DW_TAG_upc_shared_type";
615 case DW_TAG_upc_strict_type
: return "DW_TAG_upc_strict_type";
616 case DW_TAG_upc_relaxed_type
: return "DW_TAG_upc_relaxed_type";
619 static char buffer
[100];
621 snprintf (buffer
, sizeof (buffer
), _("Unknown TAG value: %lx"), tag
);
628 get_FORM_name (unsigned long form
)
632 case DW_FORM_addr
: return "DW_FORM_addr";
633 case DW_FORM_block2
: return "DW_FORM_block2";
634 case DW_FORM_block4
: return "DW_FORM_block4";
635 case DW_FORM_data2
: return "DW_FORM_data2";
636 case DW_FORM_data4
: return "DW_FORM_data4";
637 case DW_FORM_data8
: return "DW_FORM_data8";
638 case DW_FORM_string
: return "DW_FORM_string";
639 case DW_FORM_block
: return "DW_FORM_block";
640 case DW_FORM_block1
: return "DW_FORM_block1";
641 case DW_FORM_data1
: return "DW_FORM_data1";
642 case DW_FORM_flag
: return "DW_FORM_flag";
643 case DW_FORM_sdata
: return "DW_FORM_sdata";
644 case DW_FORM_strp
: return "DW_FORM_strp";
645 case DW_FORM_udata
: return "DW_FORM_udata";
646 case DW_FORM_ref_addr
: return "DW_FORM_ref_addr";
647 case DW_FORM_ref1
: return "DW_FORM_ref1";
648 case DW_FORM_ref2
: return "DW_FORM_ref2";
649 case DW_FORM_ref4
: return "DW_FORM_ref4";
650 case DW_FORM_ref8
: return "DW_FORM_ref8";
651 case DW_FORM_ref_udata
: return "DW_FORM_ref_udata";
652 case DW_FORM_indirect
: return "DW_FORM_indirect";
655 static char buffer
[100];
657 snprintf (buffer
, sizeof (buffer
), _("Unknown FORM value: %lx"), form
);
663 static unsigned char *
664 display_block (unsigned char *data
, unsigned long length
)
666 printf (_(" %lu byte block: "), length
);
669 printf ("%lx ", (unsigned long) byte_get (data
++, 1));
675 decode_location_expression (unsigned char * data
,
676 unsigned int pointer_size
,
677 unsigned long length
,
678 unsigned long cu_offset
,
679 struct dwarf_section
* section
)
682 unsigned int bytes_read
;
683 unsigned long uvalue
;
684 unsigned char *end
= data
+ length
;
685 int need_frame_base
= 0;
694 printf ("DW_OP_addr: %lx",
695 (unsigned long) byte_get (data
, pointer_size
));
696 data
+= pointer_size
;
699 printf ("DW_OP_deref");
702 printf ("DW_OP_const1u: %lu", (unsigned long) byte_get (data
++, 1));
705 printf ("DW_OP_const1s: %ld", (long) byte_get_signed (data
++, 1));
708 printf ("DW_OP_const2u: %lu", (unsigned long) byte_get (data
, 2));
712 printf ("DW_OP_const2s: %ld", (long) byte_get_signed (data
, 2));
716 printf ("DW_OP_const4u: %lu", (unsigned long) byte_get (data
, 4));
720 printf ("DW_OP_const4s: %ld", (long) byte_get_signed (data
, 4));
724 printf ("DW_OP_const8u: %lu %lu", (unsigned long) byte_get (data
, 4),
725 (unsigned long) byte_get (data
+ 4, 4));
729 printf ("DW_OP_const8s: %ld %ld", (long) byte_get (data
, 4),
730 (long) byte_get (data
+ 4, 4));
734 printf ("DW_OP_constu: %lu", read_leb128 (data
, &bytes_read
, 0));
738 printf ("DW_OP_consts: %ld", read_leb128 (data
, &bytes_read
, 1));
742 printf ("DW_OP_dup");
745 printf ("DW_OP_drop");
748 printf ("DW_OP_over");
751 printf ("DW_OP_pick: %ld", (unsigned long) byte_get (data
++, 1));
754 printf ("DW_OP_swap");
757 printf ("DW_OP_rot");
760 printf ("DW_OP_xderef");
763 printf ("DW_OP_abs");
766 printf ("DW_OP_and");
769 printf ("DW_OP_div");
772 printf ("DW_OP_minus");
775 printf ("DW_OP_mod");
778 printf ("DW_OP_mul");
781 printf ("DW_OP_neg");
784 printf ("DW_OP_not");
790 printf ("DW_OP_plus");
792 case DW_OP_plus_uconst
:
793 printf ("DW_OP_plus_uconst: %lu",
794 read_leb128 (data
, &bytes_read
, 0));
798 printf ("DW_OP_shl");
801 printf ("DW_OP_shr");
804 printf ("DW_OP_shra");
807 printf ("DW_OP_xor");
810 printf ("DW_OP_bra: %ld", (long) byte_get_signed (data
, 2));
832 printf ("DW_OP_skip: %ld", (long) byte_get_signed (data
, 2));
868 printf ("DW_OP_lit%d", op
- DW_OP_lit0
);
903 printf ("DW_OP_reg%d", op
- DW_OP_reg0
);
938 printf ("DW_OP_breg%d: %ld", op
- DW_OP_breg0
,
939 read_leb128 (data
, &bytes_read
, 1));
944 printf ("DW_OP_regx: %lu", read_leb128 (data
, &bytes_read
, 0));
949 printf ("DW_OP_fbreg: %ld", read_leb128 (data
, &bytes_read
, 1));
953 uvalue
= read_leb128 (data
, &bytes_read
, 0);
955 printf ("DW_OP_bregx: %lu %ld", uvalue
,
956 read_leb128 (data
, &bytes_read
, 1));
960 printf ("DW_OP_piece: %lu", read_leb128 (data
, &bytes_read
, 0));
963 case DW_OP_deref_size
:
964 printf ("DW_OP_deref_size: %ld", (long) byte_get (data
++, 1));
966 case DW_OP_xderef_size
:
967 printf ("DW_OP_xderef_size: %ld", (long) byte_get (data
++, 1));
970 printf ("DW_OP_nop");
973 /* DWARF 3 extensions. */
974 case DW_OP_push_object_address
:
975 printf ("DW_OP_push_object_address");
978 /* XXX: Strictly speaking for 64-bit DWARF3 files
979 this ought to be an 8-byte wide computation. */
980 printf ("DW_OP_call2: <%lx>", (long) byte_get (data
, 2) + cu_offset
);
984 /* XXX: Strictly speaking for 64-bit DWARF3 files
985 this ought to be an 8-byte wide computation. */
986 printf ("DW_OP_call4: <%lx>", (long) byte_get (data
, 4) + cu_offset
);
990 /* XXX: Strictly speaking for 64-bit DWARF3 files
991 this ought to be an 8-byte wide computation. */
992 printf ("DW_OP_call_ref: <%lx>", (long) byte_get (data
, 4) + cu_offset
);
995 case DW_OP_form_tls_address
:
996 printf ("DW_OP_form_tls_address");
998 case DW_OP_call_frame_cfa
:
999 printf ("DW_OP_call_frame_cfa");
1001 case DW_OP_bit_piece
:
1002 printf ("DW_OP_bit_piece: ");
1003 printf ("size: %lu ", read_leb128 (data
, &bytes_read
, 0));
1005 printf ("offset: %lu ", read_leb128 (data
, &bytes_read
, 0));
1009 /* GNU extensions. */
1010 case DW_OP_GNU_push_tls_address
:
1011 printf ("DW_OP_GNU_push_tls_address or DW_OP_HP_unknown");
1013 case DW_OP_GNU_uninit
:
1014 printf ("DW_OP_GNU_uninit");
1015 /* FIXME: Is there data associated with this OP ? */
1017 case DW_OP_GNU_encoded_addr
:
1023 addr
= get_encoded_value (data
, encoding
);
1024 if ((encoding
& 0x70) == DW_EH_PE_pcrel
)
1025 addr
+= section
->address
+ (data
- section
->start
);
1026 data
+= size_of_encoded_value (encoding
);
1028 printf ("DW_OP_GNU_encoded_addr: fmt:%02x addr:", encoding
);
1029 print_dwarf_vma (addr
, pointer_size
);
1033 /* HP extensions. */
1034 case DW_OP_HP_is_value
:
1035 printf ("DW_OP_HP_is_value");
1036 /* FIXME: Is there data associated with this OP ? */
1038 case DW_OP_HP_fltconst4
:
1039 printf ("DW_OP_HP_fltconst4");
1040 /* FIXME: Is there data associated with this OP ? */
1042 case DW_OP_HP_fltconst8
:
1043 printf ("DW_OP_HP_fltconst8");
1044 /* FIXME: Is there data associated with this OP ? */
1046 case DW_OP_HP_mod_range
:
1047 printf ("DW_OP_HP_mod_range");
1048 /* FIXME: Is there data associated with this OP ? */
1050 case DW_OP_HP_unmod_range
:
1051 printf ("DW_OP_HP_unmod_range");
1052 /* FIXME: Is there data associated with this OP ? */
1055 printf ("DW_OP_HP_tls");
1056 /* FIXME: Is there data associated with this OP ? */
1059 /* PGI (STMicroelectronics) extensions. */
1060 case DW_OP_PGI_omp_thread_num
:
1061 /* Pushes the thread number for the current thread as it would be
1062 returned by the standard OpenMP library function:
1063 omp_get_thread_num(). The "current thread" is the thread for
1064 which the expression is being evaluated. */
1065 printf ("DW_OP_PGI_omp_thread_num");
1069 if (op
>= DW_OP_lo_user
1070 && op
<= DW_OP_hi_user
)
1071 printf (_("(User defined location op)"));
1073 printf (_("(Unknown location op)"));
1074 /* No way to tell where the next op is, so just bail. */
1075 return need_frame_base
;
1078 /* Separate the ops. */
1083 return need_frame_base
;
1086 static unsigned char *
1087 read_and_display_attr_value (unsigned long attribute
,
1089 unsigned char * data
,
1090 unsigned long cu_offset
,
1091 unsigned long pointer_size
,
1092 unsigned long offset_size
,
1094 debug_info
* debug_info_p
,
1096 struct dwarf_section
* section
)
1098 unsigned long uvalue
= 0;
1099 unsigned char *block_start
= NULL
;
1100 unsigned char * orig_data
= data
;
1101 unsigned int bytes_read
;
1108 case DW_FORM_ref_addr
:
1109 if (dwarf_version
== 2)
1111 uvalue
= byte_get (data
, pointer_size
);
1112 data
+= pointer_size
;
1114 else if (dwarf_version
== 3)
1116 uvalue
= byte_get (data
, offset_size
);
1117 data
+= offset_size
;
1121 error (_("Internal error: DWARF version is not 2 or 3.\n"));
1126 uvalue
= byte_get (data
, pointer_size
);
1127 data
+= pointer_size
;
1131 uvalue
= byte_get (data
, offset_size
);
1132 data
+= offset_size
;
1138 uvalue
= byte_get (data
++, 1);
1143 uvalue
= byte_get (data
, 2);
1149 uvalue
= byte_get (data
, 4);
1154 uvalue
= read_leb128 (data
, & bytes_read
, 1);
1158 case DW_FORM_ref_udata
:
1160 uvalue
= read_leb128 (data
, & bytes_read
, 0);
1164 case DW_FORM_indirect
:
1165 form
= read_leb128 (data
, & bytes_read
, 0);
1168 printf (" %s", get_FORM_name (form
));
1169 return read_and_display_attr_value (attribute
, form
, data
,
1170 cu_offset
, pointer_size
,
1171 offset_size
, dwarf_version
,
1172 debug_info_p
, do_loc
,
1178 case DW_FORM_ref_addr
:
1180 printf (" <0x%lx>", uvalue
);
1186 case DW_FORM_ref_udata
:
1188 printf (" <0x%lx>", uvalue
+ cu_offset
);
1194 printf (" 0x%lx", uvalue
);
1203 printf (" %ld", uvalue
);
1210 uvalue
= byte_get (data
, 4);
1211 printf (" 0x%lx", uvalue
);
1212 printf (" 0x%lx", (unsigned long) byte_get (data
+ 4, 4));
1214 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
1215 && num_debug_info_entries
== 0)
1217 if (sizeof (uvalue
) == 8)
1218 uvalue
= byte_get (data
, 8);
1220 error (_("DW_FORM_data8 is unsupported when sizeof (unsigned long) != 8\n"));
1225 case DW_FORM_string
:
1227 printf (" %s", data
);
1228 data
+= strlen ((char *) data
) + 1;
1232 uvalue
= read_leb128 (data
, & bytes_read
, 0);
1233 block_start
= data
+ bytes_read
;
1235 data
= block_start
+ uvalue
;
1237 data
= display_block (block_start
, uvalue
);
1240 case DW_FORM_block1
:
1241 uvalue
= byte_get (data
, 1);
1242 block_start
= data
+ 1;
1244 data
= block_start
+ uvalue
;
1246 data
= display_block (block_start
, uvalue
);
1249 case DW_FORM_block2
:
1250 uvalue
= byte_get (data
, 2);
1251 block_start
= data
+ 2;
1253 data
= block_start
+ uvalue
;
1255 data
= display_block (block_start
, uvalue
);
1258 case DW_FORM_block4
:
1259 uvalue
= byte_get (data
, 4);
1260 block_start
= data
+ 4;
1262 data
= block_start
+ uvalue
;
1264 data
= display_block (block_start
, uvalue
);
1269 printf (_(" (indirect string, offset: 0x%lx): %s"),
1270 uvalue
, fetch_indirect_string (uvalue
));
1273 case DW_FORM_indirect
:
1274 /* Handled above. */
1278 warn (_("Unrecognized form: %lu\n"), form
);
1282 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
1283 && num_debug_info_entries
== 0)
1287 case DW_AT_frame_base
:
1288 have_frame_base
= 1;
1289 case DW_AT_location
:
1290 case DW_AT_string_length
:
1291 case DW_AT_return_addr
:
1292 case DW_AT_data_member_location
:
1293 case DW_AT_vtable_elem_location
:
1295 case DW_AT_static_link
:
1296 case DW_AT_use_location
:
1297 if (form
== DW_FORM_data4
|| form
== DW_FORM_data8
)
1299 /* Process location list. */
1300 unsigned int max
= debug_info_p
->max_loc_offsets
;
1301 unsigned int num
= debug_info_p
->num_loc_offsets
;
1303 if (max
== 0 || num
>= max
)
1306 debug_info_p
->loc_offsets
1307 = xcrealloc (debug_info_p
->loc_offsets
,
1308 max
, sizeof (*debug_info_p
->loc_offsets
));
1309 debug_info_p
->have_frame_base
1310 = xcrealloc (debug_info_p
->have_frame_base
,
1311 max
, sizeof (*debug_info_p
->have_frame_base
));
1312 debug_info_p
->max_loc_offsets
= max
;
1314 debug_info_p
->loc_offsets
[num
] = uvalue
;
1315 debug_info_p
->have_frame_base
[num
] = have_frame_base
;
1316 debug_info_p
->num_loc_offsets
++;
1321 if (need_base_address
)
1322 debug_info_p
->base_address
= uvalue
;
1326 if (form
== DW_FORM_data4
|| form
== DW_FORM_data8
)
1328 /* Process range list. */
1329 unsigned int max
= debug_info_p
->max_range_lists
;
1330 unsigned int num
= debug_info_p
->num_range_lists
;
1332 if (max
== 0 || num
>= max
)
1335 debug_info_p
->range_lists
1336 = xcrealloc (debug_info_p
->range_lists
,
1337 max
, sizeof (*debug_info_p
->range_lists
));
1338 debug_info_p
->max_range_lists
= max
;
1340 debug_info_p
->range_lists
[num
] = uvalue
;
1341 debug_info_p
->num_range_lists
++;
1353 /* For some attributes we can display further information. */
1361 case DW_INL_not_inlined
:
1362 printf (_("(not inlined)"));
1364 case DW_INL_inlined
:
1365 printf (_("(inlined)"));
1367 case DW_INL_declared_not_inlined
:
1368 printf (_("(declared as inline but ignored)"));
1370 case DW_INL_declared_inlined
:
1371 printf (_("(declared as inline and inlined)"));
1374 printf (_(" (Unknown inline attribute value: %lx)"), uvalue
);
1379 case DW_AT_language
:
1382 /* Ordered by the numeric value of these constants. */
1383 case DW_LANG_C89
: printf ("(ANSI C)"); break;
1384 case DW_LANG_C
: printf ("(non-ANSI C)"); break;
1385 case DW_LANG_Ada83
: printf ("(Ada)"); break;
1386 case DW_LANG_C_plus_plus
: printf ("(C++)"); break;
1387 case DW_LANG_Cobol74
: printf ("(Cobol 74)"); break;
1388 case DW_LANG_Cobol85
: printf ("(Cobol 85)"); break;
1389 case DW_LANG_Fortran77
: printf ("(FORTRAN 77)"); break;
1390 case DW_LANG_Fortran90
: printf ("(Fortran 90)"); break;
1391 case DW_LANG_Pascal83
: printf ("(ANSI Pascal)"); break;
1392 case DW_LANG_Modula2
: printf ("(Modula 2)"); break;
1393 /* DWARF 2.1 values. */
1394 case DW_LANG_Java
: printf ("(Java)"); break;
1395 case DW_LANG_C99
: printf ("(ANSI C99)"); break;
1396 case DW_LANG_Ada95
: printf ("(ADA 95)"); break;
1397 case DW_LANG_Fortran95
: printf ("(Fortran 95)"); break;
1398 /* DWARF 3 values. */
1399 case DW_LANG_PLI
: printf ("(PLI)"); break;
1400 case DW_LANG_ObjC
: printf ("(Objective C)"); break;
1401 case DW_LANG_ObjC_plus_plus
: printf ("(Objective C++)"); break;
1402 case DW_LANG_UPC
: printf ("(Unified Parallel C)"); break;
1403 case DW_LANG_D
: printf ("(D)"); break;
1404 /* MIPS extension. */
1405 case DW_LANG_Mips_Assembler
: printf ("(MIPS assembler)"); break;
1406 /* UPC extension. */
1407 case DW_LANG_Upc
: printf ("(Unified Parallel C)"); break;
1409 if (uvalue
>= DW_LANG_lo_user
&& uvalue
<= DW_LANG_hi_user
)
1410 printf ("(implementation defined: %lx)", uvalue
);
1412 printf ("(Unknown: %lx)", uvalue
);
1417 case DW_AT_encoding
:
1420 case DW_ATE_void
: printf ("(void)"); break;
1421 case DW_ATE_address
: printf ("(machine address)"); break;
1422 case DW_ATE_boolean
: printf ("(boolean)"); break;
1423 case DW_ATE_complex_float
: printf ("(complex float)"); break;
1424 case DW_ATE_float
: printf ("(float)"); break;
1425 case DW_ATE_signed
: printf ("(signed)"); break;
1426 case DW_ATE_signed_char
: printf ("(signed char)"); break;
1427 case DW_ATE_unsigned
: printf ("(unsigned)"); break;
1428 case DW_ATE_unsigned_char
: printf ("(unsigned char)"); break;
1429 /* DWARF 2.1 values: */
1430 case DW_ATE_imaginary_float
: printf ("(imaginary float)"); break;
1431 case DW_ATE_decimal_float
: printf ("(decimal float)"); break;
1432 /* DWARF 3 values: */
1433 case DW_ATE_packed_decimal
: printf ("(packed_decimal)"); break;
1434 case DW_ATE_numeric_string
: printf ("(numeric_string)"); break;
1435 case DW_ATE_edited
: printf ("(edited)"); break;
1436 case DW_ATE_signed_fixed
: printf ("(signed_fixed)"); break;
1437 case DW_ATE_unsigned_fixed
: printf ("(unsigned_fixed)"); break;
1438 /* HP extensions: */
1439 case DW_ATE_HP_float80
: printf ("(HP_float80)"); break;
1440 case DW_ATE_HP_complex_float80
: printf ("(HP_complex_float80)"); break;
1441 case DW_ATE_HP_float128
: printf ("(HP_float128)"); break;
1442 case DW_ATE_HP_complex_float128
:printf ("(HP_complex_float128)"); break;
1443 case DW_ATE_HP_floathpintel
: printf ("(HP_floathpintel)"); break;
1444 case DW_ATE_HP_imaginary_float80
: printf ("(HP_imaginary_float80)"); break;
1445 case DW_ATE_HP_imaginary_float128
: printf ("(HP_imaginary_float128)"); break;
1448 if (uvalue
>= DW_ATE_lo_user
1449 && uvalue
<= DW_ATE_hi_user
)
1450 printf ("(user defined type)");
1452 printf ("(unknown type)");
1457 case DW_AT_accessibility
:
1460 case DW_ACCESS_public
: printf ("(public)"); break;
1461 case DW_ACCESS_protected
: printf ("(protected)"); break;
1462 case DW_ACCESS_private
: printf ("(private)"); break;
1464 printf ("(unknown accessibility)");
1469 case DW_AT_visibility
:
1472 case DW_VIS_local
: printf ("(local)"); break;
1473 case DW_VIS_exported
: printf ("(exported)"); break;
1474 case DW_VIS_qualified
: printf ("(qualified)"); break;
1475 default: printf ("(unknown visibility)"); break;
1479 case DW_AT_virtuality
:
1482 case DW_VIRTUALITY_none
: printf ("(none)"); break;
1483 case DW_VIRTUALITY_virtual
: printf ("(virtual)"); break;
1484 case DW_VIRTUALITY_pure_virtual
:printf ("(pure_virtual)"); break;
1485 default: printf ("(unknown virtuality)"); break;
1489 case DW_AT_identifier_case
:
1492 case DW_ID_case_sensitive
: printf ("(case_sensitive)"); break;
1493 case DW_ID_up_case
: printf ("(up_case)"); break;
1494 case DW_ID_down_case
: printf ("(down_case)"); break;
1495 case DW_ID_case_insensitive
: printf ("(case_insensitive)"); break;
1496 default: printf ("(unknown case)"); break;
1500 case DW_AT_calling_convention
:
1503 case DW_CC_normal
: printf ("(normal)"); break;
1504 case DW_CC_program
: printf ("(program)"); break;
1505 case DW_CC_nocall
: printf ("(nocall)"); break;
1507 if (uvalue
>= DW_CC_lo_user
1508 && uvalue
<= DW_CC_hi_user
)
1509 printf ("(user defined)");
1511 printf ("(unknown convention)");
1515 case DW_AT_ordering
:
1518 case -1: printf ("(undefined)"); break;
1519 case 0: printf ("(row major)"); break;
1520 case 1: printf ("(column major)"); break;
1524 case DW_AT_frame_base
:
1525 have_frame_base
= 1;
1526 case DW_AT_location
:
1527 case DW_AT_string_length
:
1528 case DW_AT_return_addr
:
1529 case DW_AT_data_member_location
:
1530 case DW_AT_vtable_elem_location
:
1532 case DW_AT_static_link
:
1533 case DW_AT_use_location
:
1534 if (form
== DW_FORM_data4
|| form
== DW_FORM_data8
)
1535 printf (_("(location list)"));
1537 case DW_AT_allocated
:
1538 case DW_AT_associated
:
1539 case DW_AT_data_location
:
1541 case DW_AT_upper_bound
:
1542 case DW_AT_lower_bound
:
1545 int need_frame_base
;
1548 need_frame_base
= decode_location_expression (block_start
,
1551 cu_offset
, section
);
1553 if (need_frame_base
&& !have_frame_base
)
1554 printf (_(" [without DW_AT_frame_base]"));
1560 if (form
== DW_FORM_ref1
1561 || form
== DW_FORM_ref2
1562 || form
== DW_FORM_ref4
)
1563 uvalue
+= cu_offset
;
1565 if (uvalue
>= section
->size
)
1566 warn (_("Offset %lx used as value for DW_AT_import attribute of DIE at offset %lx is too big.\n"),
1567 uvalue
, (unsigned long) (orig_data
- section
->start
));
1570 unsigned long abbrev_number
;
1571 abbrev_entry
* entry
;
1573 abbrev_number
= read_leb128 (section
->start
+ uvalue
, NULL
, 0);
1575 printf ("[Abbrev Number: %ld", abbrev_number
);
1576 for (entry
= first_abbrev
; entry
!= NULL
; entry
= entry
->next
)
1577 if (entry
->entry
== abbrev_number
)
1580 printf (" (%s)", get_TAG_name (entry
->tag
));
1594 get_AT_name (unsigned long attribute
)
1598 case DW_AT_sibling
: return "DW_AT_sibling";
1599 case DW_AT_location
: return "DW_AT_location";
1600 case DW_AT_name
: return "DW_AT_name";
1601 case DW_AT_ordering
: return "DW_AT_ordering";
1602 case DW_AT_subscr_data
: return "DW_AT_subscr_data";
1603 case DW_AT_byte_size
: return "DW_AT_byte_size";
1604 case DW_AT_bit_offset
: return "DW_AT_bit_offset";
1605 case DW_AT_bit_size
: return "DW_AT_bit_size";
1606 case DW_AT_element_list
: return "DW_AT_element_list";
1607 case DW_AT_stmt_list
: return "DW_AT_stmt_list";
1608 case DW_AT_low_pc
: return "DW_AT_low_pc";
1609 case DW_AT_high_pc
: return "DW_AT_high_pc";
1610 case DW_AT_language
: return "DW_AT_language";
1611 case DW_AT_member
: return "DW_AT_member";
1612 case DW_AT_discr
: return "DW_AT_discr";
1613 case DW_AT_discr_value
: return "DW_AT_discr_value";
1614 case DW_AT_visibility
: return "DW_AT_visibility";
1615 case DW_AT_import
: return "DW_AT_import";
1616 case DW_AT_string_length
: return "DW_AT_string_length";
1617 case DW_AT_common_reference
: return "DW_AT_common_reference";
1618 case DW_AT_comp_dir
: return "DW_AT_comp_dir";
1619 case DW_AT_const_value
: return "DW_AT_const_value";
1620 case DW_AT_containing_type
: return "DW_AT_containing_type";
1621 case DW_AT_default_value
: return "DW_AT_default_value";
1622 case DW_AT_inline
: return "DW_AT_inline";
1623 case DW_AT_is_optional
: return "DW_AT_is_optional";
1624 case DW_AT_lower_bound
: return "DW_AT_lower_bound";
1625 case DW_AT_producer
: return "DW_AT_producer";
1626 case DW_AT_prototyped
: return "DW_AT_prototyped";
1627 case DW_AT_return_addr
: return "DW_AT_return_addr";
1628 case DW_AT_start_scope
: return "DW_AT_start_scope";
1629 case DW_AT_stride_size
: return "DW_AT_stride_size";
1630 case DW_AT_upper_bound
: return "DW_AT_upper_bound";
1631 case DW_AT_abstract_origin
: return "DW_AT_abstract_origin";
1632 case DW_AT_accessibility
: return "DW_AT_accessibility";
1633 case DW_AT_address_class
: return "DW_AT_address_class";
1634 case DW_AT_artificial
: return "DW_AT_artificial";
1635 case DW_AT_base_types
: return "DW_AT_base_types";
1636 case DW_AT_calling_convention
: return "DW_AT_calling_convention";
1637 case DW_AT_count
: return "DW_AT_count";
1638 case DW_AT_data_member_location
: return "DW_AT_data_member_location";
1639 case DW_AT_decl_column
: return "DW_AT_decl_column";
1640 case DW_AT_decl_file
: return "DW_AT_decl_file";
1641 case DW_AT_decl_line
: return "DW_AT_decl_line";
1642 case DW_AT_declaration
: return "DW_AT_declaration";
1643 case DW_AT_discr_list
: return "DW_AT_discr_list";
1644 case DW_AT_encoding
: return "DW_AT_encoding";
1645 case DW_AT_external
: return "DW_AT_external";
1646 case DW_AT_frame_base
: return "DW_AT_frame_base";
1647 case DW_AT_friend
: return "DW_AT_friend";
1648 case DW_AT_identifier_case
: return "DW_AT_identifier_case";
1649 case DW_AT_macro_info
: return "DW_AT_macro_info";
1650 case DW_AT_namelist_items
: return "DW_AT_namelist_items";
1651 case DW_AT_priority
: return "DW_AT_priority";
1652 case DW_AT_segment
: return "DW_AT_segment";
1653 case DW_AT_specification
: return "DW_AT_specification";
1654 case DW_AT_static_link
: return "DW_AT_static_link";
1655 case DW_AT_type
: return "DW_AT_type";
1656 case DW_AT_use_location
: return "DW_AT_use_location";
1657 case DW_AT_variable_parameter
: return "DW_AT_variable_parameter";
1658 case DW_AT_virtuality
: return "DW_AT_virtuality";
1659 case DW_AT_vtable_elem_location
: return "DW_AT_vtable_elem_location";
1660 /* DWARF 2.1 values. */
1661 case DW_AT_allocated
: return "DW_AT_allocated";
1662 case DW_AT_associated
: return "DW_AT_associated";
1663 case DW_AT_data_location
: return "DW_AT_data_location";
1664 case DW_AT_stride
: return "DW_AT_stride";
1665 case DW_AT_entry_pc
: return "DW_AT_entry_pc";
1666 case DW_AT_use_UTF8
: return "DW_AT_use_UTF8";
1667 case DW_AT_extension
: return "DW_AT_extension";
1668 case DW_AT_ranges
: return "DW_AT_ranges";
1669 case DW_AT_trampoline
: return "DW_AT_trampoline";
1670 case DW_AT_call_column
: return "DW_AT_call_column";
1671 case DW_AT_call_file
: return "DW_AT_call_file";
1672 case DW_AT_call_line
: return "DW_AT_call_line";
1673 case DW_AT_description
: return "DW_AT_description";
1674 case DW_AT_binary_scale
: return "DW_AT_binary_scale";
1675 case DW_AT_decimal_scale
: return "DW_AT_decimal_scale";
1676 case DW_AT_small
: return "DW_AT_small";
1677 case DW_AT_decimal_sign
: return "DW_AT_decimal_sign";
1678 case DW_AT_digit_count
: return "DW_AT_digit_count";
1679 case DW_AT_picture_string
: return "DW_AT_picture_string";
1680 case DW_AT_mutable
: return "DW_AT_mutable";
1681 case DW_AT_threads_scaled
: return "DW_AT_threads_scaled";
1682 case DW_AT_explicit
: return "DW_AT_explicit";
1683 case DW_AT_object_pointer
: return "DW_AT_object_pointer";
1684 case DW_AT_endianity
: return "DW_AT_endianity";
1685 case DW_AT_elemental
: return "DW_AT_elemental";
1686 case DW_AT_pure
: return "DW_AT_pure";
1687 case DW_AT_recursive
: return "DW_AT_recursive";
1689 /* HP and SGI/MIPS extensions. */
1690 case DW_AT_MIPS_loop_begin
: return "DW_AT_MIPS_loop_begin";
1691 case DW_AT_MIPS_tail_loop_begin
: return "DW_AT_MIPS_tail_loop_begin";
1692 case DW_AT_MIPS_epilog_begin
: return "DW_AT_MIPS_epilog_begin";
1693 case DW_AT_MIPS_loop_unroll_factor
: return "DW_AT_MIPS_loop_unroll_factor";
1694 case DW_AT_MIPS_software_pipeline_depth
: return "DW_AT_MIPS_software_pipeline_depth";
1695 case DW_AT_MIPS_linkage_name
: return "DW_AT_MIPS_linkage_name";
1696 case DW_AT_MIPS_stride
: return "DW_AT_MIPS_stride";
1697 case DW_AT_MIPS_abstract_name
: return "DW_AT_MIPS_abstract_name";
1698 case DW_AT_MIPS_clone_origin
: return "DW_AT_MIPS_clone_origin";
1699 case DW_AT_MIPS_has_inlines
: return "DW_AT_MIPS_has_inlines";
1701 /* HP Extensions. */
1702 case DW_AT_HP_block_index
: return "DW_AT_HP_block_index";
1703 case DW_AT_HP_actuals_stmt_list
: return "DW_AT_HP_actuals_stmt_list";
1704 case DW_AT_HP_proc_per_section
: return "DW_AT_HP_proc_per_section";
1705 case DW_AT_HP_raw_data_ptr
: return "DW_AT_HP_raw_data_ptr";
1706 case DW_AT_HP_pass_by_reference
: return "DW_AT_HP_pass_by_reference";
1707 case DW_AT_HP_opt_level
: return "DW_AT_HP_opt_level";
1708 case DW_AT_HP_prof_version_id
: return "DW_AT_HP_prof_version_id";
1709 case DW_AT_HP_opt_flags
: return "DW_AT_HP_opt_flags";
1710 case DW_AT_HP_cold_region_low_pc
: return "DW_AT_HP_cold_region_low_pc";
1711 case DW_AT_HP_cold_region_high_pc
: return "DW_AT_HP_cold_region_high_pc";
1712 case DW_AT_HP_all_variables_modifiable
: return "DW_AT_HP_all_variables_modifiable";
1713 case DW_AT_HP_linkage_name
: return "DW_AT_HP_linkage_name";
1714 case DW_AT_HP_prof_flags
: return "DW_AT_HP_prof_flags";
1716 /* One value is shared by the MIPS and HP extensions: */
1717 case DW_AT_MIPS_fde
: return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable";
1719 /* GNU extensions. */
1720 case DW_AT_sf_names
: return "DW_AT_sf_names";
1721 case DW_AT_src_info
: return "DW_AT_src_info";
1722 case DW_AT_mac_info
: return "DW_AT_mac_info";
1723 case DW_AT_src_coords
: return "DW_AT_src_coords";
1724 case DW_AT_body_begin
: return "DW_AT_body_begin";
1725 case DW_AT_body_end
: return "DW_AT_body_end";
1726 case DW_AT_GNU_vector
: return "DW_AT_GNU_vector";
1728 /* UPC extension. */
1729 case DW_AT_upc_threads_scaled
: return "DW_AT_upc_threads_scaled";
1731 /* PGI (STMicroelectronics) extensions. */
1732 case DW_AT_PGI_lbase
: return "DW_AT_PGI_lbase";
1733 case DW_AT_PGI_soffset
: return "DW_AT_PGI_soffset";
1734 case DW_AT_PGI_lstride
: return "DW_AT_PGI_lstride";
1738 static char buffer
[100];
1740 snprintf (buffer
, sizeof (buffer
), _("Unknown AT value: %lx"),
1747 static unsigned char *
1748 read_and_display_attr (unsigned long attribute
,
1750 unsigned char * data
,
1751 unsigned long cu_offset
,
1752 unsigned long pointer_size
,
1753 unsigned long offset_size
,
1755 debug_info
* debug_info_p
,
1757 struct dwarf_section
* section
)
1760 printf (" %-18s:", get_AT_name (attribute
));
1761 data
= read_and_display_attr_value (attribute
, form
, data
, cu_offset
,
1762 pointer_size
, offset_size
,
1763 dwarf_version
, debug_info_p
,
1771 /* Process the contents of a .debug_info section. If do_loc is non-zero
1772 then we are scanning for location lists and we do not want to display
1773 anything to the user. */
1776 process_debug_info (struct dwarf_section
*section
,
1780 unsigned char *start
= section
->start
;
1781 unsigned char *end
= start
+ section
->size
;
1782 unsigned char *section_begin
;
1784 unsigned int num_units
= 0;
1786 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
1787 && num_debug_info_entries
== 0)
1789 unsigned long length
;
1791 /* First scan the section to get the number of comp units. */
1792 for (section_begin
= start
, num_units
= 0; section_begin
< end
;
1795 /* Read the first 4 bytes. For a 32-bit DWARF section, this
1796 will be the length. For a 64-bit DWARF section, it'll be
1797 the escape code 0xffffffff followed by an 8 byte length. */
1798 length
= byte_get (section_begin
, 4);
1800 if (length
== 0xffffffff)
1802 length
= byte_get (section_begin
+ 4, 8);
1803 section_begin
+= length
+ 12;
1805 else if (length
>= 0xfffffff0 && length
< 0xffffffff)
1807 warn (_("Reserved length value (%lx) found in section %s\n"), length
, section
->name
);
1811 section_begin
+= length
+ 4;
1813 /* Negative values are illegal, they may even cause infinite
1814 looping. This can happen if we can't accurately apply
1815 relocations to an object file. */
1816 if ((signed long) length
<= 0)
1818 warn (_("Corrupt unit length (%lx) found in section %s\n"), length
, section
->name
);
1825 error (_("No comp units in %s section ?"), section
->name
);
1829 /* Then allocate an array to hold the information. */
1830 debug_information
= cmalloc (num_units
,
1831 sizeof (* debug_information
));
1832 if (debug_information
== NULL
)
1834 error (_("Not enough memory for a debug info array of %u entries"),
1842 printf (_("The section %s contains:\n\n"), section
->name
);
1844 load_debug_section (str
, file
);
1847 load_debug_section (abbrev
, file
);
1848 if (debug_displays
[abbrev
].section
.start
== NULL
)
1850 warn (_("Unable to locate %s section!\n"),
1851 debug_displays
[abbrev
].section
.name
);
1855 for (section_begin
= start
, unit
= 0; start
< end
; unit
++)
1857 DWARF2_Internal_CompUnit compunit
;
1858 unsigned char *hdrptr
;
1859 unsigned char *cu_abbrev_offset_ptr
;
1860 unsigned char *tags
;
1862 unsigned long cu_offset
;
1864 int initial_length_size
;
1868 compunit
.cu_length
= byte_get (hdrptr
, 4);
1871 if (compunit
.cu_length
== 0xffffffff)
1873 compunit
.cu_length
= byte_get (hdrptr
, 8);
1876 initial_length_size
= 12;
1881 initial_length_size
= 4;
1884 compunit
.cu_version
= byte_get (hdrptr
, 2);
1887 cu_offset
= start
- section_begin
;
1889 cu_abbrev_offset_ptr
= hdrptr
;
1890 compunit
.cu_abbrev_offset
= byte_get (hdrptr
, offset_size
);
1891 hdrptr
+= offset_size
;
1893 compunit
.cu_pointer_size
= byte_get (hdrptr
, 1);
1895 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
1896 && num_debug_info_entries
== 0)
1898 debug_information
[unit
].cu_offset
= cu_offset
;
1899 debug_information
[unit
].pointer_size
1900 = compunit
.cu_pointer_size
;
1901 debug_information
[unit
].base_address
= 0;
1902 debug_information
[unit
].loc_offsets
= NULL
;
1903 debug_information
[unit
].have_frame_base
= NULL
;
1904 debug_information
[unit
].max_loc_offsets
= 0;
1905 debug_information
[unit
].num_loc_offsets
= 0;
1906 debug_information
[unit
].range_lists
= NULL
;
1907 debug_information
[unit
].max_range_lists
= 0;
1908 debug_information
[unit
].num_range_lists
= 0;
1913 printf (_(" Compilation Unit @ offset 0x%lx:\n"), cu_offset
);
1914 printf (_(" Length: 0x%lx (%s)\n"), compunit
.cu_length
,
1915 initial_length_size
== 8 ? "64-bit" : "32-bit");
1916 printf (_(" Version: %d\n"), compunit
.cu_version
);
1917 printf (_(" Abbrev Offset: %ld\n"), compunit
.cu_abbrev_offset
);
1918 printf (_(" Pointer Size: %d\n"), compunit
.cu_pointer_size
);
1921 if (cu_offset
+ compunit
.cu_length
+ initial_length_size
1924 warn (_("Debug info is corrupted, length of CU at %lx extends beyond end of section (length = %lx)\n"),
1925 cu_offset
, compunit
.cu_length
);
1929 start
+= compunit
.cu_length
+ initial_length_size
;
1931 if (compunit
.cu_version
!= 2 && compunit
.cu_version
!= 3)
1933 warn (_("CU at offset %lx contains corrupt or unsupported version number: %d.\n"),
1934 cu_offset
, compunit
.cu_version
);
1940 /* Process the abbrevs used by this compilation unit. DWARF
1941 sections under Mach-O have non-zero addresses. */
1942 if (compunit
.cu_abbrev_offset
>= debug_displays
[abbrev
].section
.size
)
1943 warn (_("Debug info is corrupted, abbrev offset (%lx) is larger than abbrev section size (%lx)\n"),
1944 (unsigned long) compunit
.cu_abbrev_offset
,
1945 (unsigned long) debug_displays
[abbrev
].section
.size
);
1947 process_abbrev_section
1948 ((unsigned char *) debug_displays
[abbrev
].section
.start
1949 + compunit
.cu_abbrev_offset
- debug_displays
[abbrev
].section
.address
,
1950 (unsigned char *) debug_displays
[abbrev
].section
.start
1951 + debug_displays
[abbrev
].section
.size
);
1954 while (tags
< start
)
1956 unsigned int bytes_read
;
1957 unsigned long abbrev_number
;
1958 unsigned long die_offset
;
1959 abbrev_entry
*entry
;
1962 die_offset
= tags
- section_begin
;
1964 abbrev_number
= read_leb128 (tags
, & bytes_read
, 0);
1967 /* A null DIE marks the end of a list of siblings. */
1968 if (abbrev_number
== 0)
1973 static unsigned num_bogus_warns
= 0;
1975 if (num_bogus_warns
< 3)
1977 warn (_("Bogus end-of-siblings marker detected at offset %lx in .debug_info section\n"),
1980 if (num_bogus_warns
== 3)
1981 warn (_("Further warnings about bogus end-of-sibling markers suppressed\n"));
1988 printf (_(" <%d><%lx>: Abbrev Number: %lu"),
1989 level
, die_offset
, abbrev_number
);
1991 /* Scan through the abbreviation list until we reach the
1993 for (entry
= first_abbrev
;
1994 entry
&& entry
->entry
!= abbrev_number
;
1995 entry
= entry
->next
)
2005 warn (_("DIE at offset %lx refers to abbreviation number %lu which does not exist\n"),
2006 die_offset
, abbrev_number
);
2011 printf (_(" (%s)\n"), get_TAG_name (entry
->tag
));
2016 need_base_address
= 0;
2018 case DW_TAG_compile_unit
:
2019 need_base_address
= 1;
2021 case DW_TAG_entry_point
:
2022 case DW_TAG_subprogram
:
2023 need_base_address
= 0;
2024 /* Assuming that there is no DW_AT_frame_base. */
2025 have_frame_base
= 0;
2029 for (attr
= entry
->first_attr
; attr
; attr
= attr
->next
)
2032 /* Show the offset from where the tag was extracted. */
2033 printf (" <%2lx>", (unsigned long)(tags
- section_begin
));
2035 tags
= read_and_display_attr (attr
->attribute
,
2038 compunit
.cu_pointer_size
,
2040 compunit
.cu_version
,
2041 debug_information
+ unit
,
2045 if (entry
->children
)
2050 /* Set num_debug_info_entries here so that it can be used to check if
2051 we need to process .debug_loc and .debug_ranges sections. */
2052 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
2053 && num_debug_info_entries
== 0)
2054 num_debug_info_entries
= num_units
;
2064 /* Locate and scan the .debug_info section in the file and record the pointer
2065 sizes and offsets for the compilation units in it. Usually an executable
2066 will have just one pointer size, but this is not guaranteed, and so we try
2067 not to make any assumptions. Returns zero upon failure, or the number of
2068 compilation units upon success. */
2071 load_debug_info (void * file
)
2073 /* Reset the last pointer size so that we can issue correct error
2074 messages if we are displaying the contents of more than one section. */
2075 last_pointer_size
= 0;
2076 warned_about_missing_comp_units
= FALSE
;
2078 /* If we have already tried and failed to load the .debug_info
2079 section then do not bother to repear the task. */
2080 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
2083 /* If we already have the information there is nothing else to do. */
2084 if (num_debug_info_entries
> 0)
2085 return num_debug_info_entries
;
2087 if (load_debug_section (info
, file
)
2088 && process_debug_info (&debug_displays
[info
].section
, file
, 1))
2089 return num_debug_info_entries
;
2091 num_debug_info_entries
= DEBUG_INFO_UNAVAILABLE
;
2096 display_debug_lines_raw (struct dwarf_section
*section
,
2097 unsigned char *data
,
2100 unsigned char *start
= section
->start
;
2102 printf (_("Raw dump of debug contents of section %s:\n\n"),
2107 DWARF2_Internal_LineInfo info
;
2108 unsigned char *standard_opcodes
;
2109 unsigned char *end_of_sequence
;
2110 unsigned char *hdrptr
;
2111 unsigned long hdroff
;
2112 int initial_length_size
;
2117 hdroff
= hdrptr
- start
;
2119 /* Check the length of the block. */
2120 info
.li_length
= byte_get (hdrptr
, 4);
2123 if (info
.li_length
== 0xffffffff)
2125 /* This section is 64-bit DWARF 3. */
2126 info
.li_length
= byte_get (hdrptr
, 8);
2129 initial_length_size
= 12;
2134 initial_length_size
= 4;
2137 if (info
.li_length
+ initial_length_size
> section
->size
)
2140 (_("The line info appears to be corrupt - the section is too small\n"));
2144 /* Check its version number. */
2145 info
.li_version
= byte_get (hdrptr
, 2);
2147 if (info
.li_version
!= 2 && info
.li_version
!= 3)
2149 warn (_("Only DWARF version 2 and 3 line info is currently supported.\n"));
2153 info
.li_prologue_length
= byte_get (hdrptr
, offset_size
);
2154 hdrptr
+= offset_size
;
2155 info
.li_min_insn_length
= byte_get (hdrptr
, 1);
2157 info
.li_default_is_stmt
= byte_get (hdrptr
, 1);
2159 info
.li_line_base
= byte_get (hdrptr
, 1);
2161 info
.li_line_range
= byte_get (hdrptr
, 1);
2163 info
.li_opcode_base
= byte_get (hdrptr
, 1);
2166 /* Sign extend the line base field. */
2167 info
.li_line_base
<<= 24;
2168 info
.li_line_base
>>= 24;
2170 printf (_(" Offset: 0x%lx\n"), hdroff
);
2171 printf (_(" Length: %ld\n"), info
.li_length
);
2172 printf (_(" DWARF Version: %d\n"), info
.li_version
);
2173 printf (_(" Prologue Length: %d\n"), info
.li_prologue_length
);
2174 printf (_(" Minimum Instruction Length: %d\n"), info
.li_min_insn_length
);
2175 printf (_(" Initial value of 'is_stmt': %d\n"), info
.li_default_is_stmt
);
2176 printf (_(" Line Base: %d\n"), info
.li_line_base
);
2177 printf (_(" Line Range: %d\n"), info
.li_line_range
);
2178 printf (_(" Opcode Base: %d\n"), info
.li_opcode_base
);
2180 end_of_sequence
= data
+ info
.li_length
+ initial_length_size
;
2182 reset_state_machine (info
.li_default_is_stmt
);
2184 /* Display the contents of the Opcodes table. */
2185 standard_opcodes
= hdrptr
;
2187 printf (_("\n Opcodes:\n"));
2189 for (i
= 1; i
< info
.li_opcode_base
; i
++)
2190 printf (_(" Opcode %d has %d args\n"), i
, standard_opcodes
[i
- 1]);
2192 /* Display the contents of the Directory table. */
2193 data
= standard_opcodes
+ info
.li_opcode_base
- 1;
2196 printf (_("\n The Directory Table is empty.\n"));
2199 printf (_("\n The Directory Table:\n"));
2203 printf (_(" %s\n"), data
);
2205 data
+= strlen ((char *) data
) + 1;
2209 /* Skip the NUL at the end of the table. */
2212 /* Display the contents of the File Name table. */
2214 printf (_("\n The File Name Table is empty.\n"));
2217 printf (_("\n The File Name Table:\n"));
2218 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
2222 unsigned char *name
;
2223 unsigned int bytes_read
;
2225 printf (_(" %d\t"), ++state_machine_regs
.last_file_entry
);
2228 data
+= strlen ((char *) data
) + 1;
2230 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
2232 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
2234 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
2236 printf (_("%s\n"), name
);
2240 /* Skip the NUL at the end of the table. */
2243 /* Now display the statements. */
2244 printf (_("\n Line Number Statements:\n"));
2246 while (data
< end_of_sequence
)
2248 unsigned char op_code
;
2250 unsigned long int uladv
;
2251 unsigned int bytes_read
;
2255 if (op_code
>= info
.li_opcode_base
)
2257 op_code
-= info
.li_opcode_base
;
2258 uladv
= (op_code
/ info
.li_line_range
) * info
.li_min_insn_length
;
2259 state_machine_regs
.address
+= uladv
;
2260 printf (_(" Special opcode %d: advance Address by %lu to 0x%lx"),
2261 op_code
, uladv
, state_machine_regs
.address
);
2262 adv
= (op_code
% info
.li_line_range
) + info
.li_line_base
;
2263 state_machine_regs
.line
+= adv
;
2264 printf (_(" and Line by %d to %d\n"),
2265 adv
, state_machine_regs
.line
);
2267 else switch (op_code
)
2269 case DW_LNS_extended_op
:
2270 data
+= process_extended_line_op (data
, info
.li_default_is_stmt
);
2274 printf (_(" Copy\n"));
2277 case DW_LNS_advance_pc
:
2278 uladv
= read_leb128 (data
, & bytes_read
, 0);
2279 uladv
*= info
.li_min_insn_length
;
2281 state_machine_regs
.address
+= uladv
;
2282 printf (_(" Advance PC by %lu to 0x%lx\n"), uladv
,
2283 state_machine_regs
.address
);
2286 case DW_LNS_advance_line
:
2287 adv
= read_leb128 (data
, & bytes_read
, 1);
2289 state_machine_regs
.line
+= adv
;
2290 printf (_(" Advance Line by %d to %d\n"), adv
,
2291 state_machine_regs
.line
);
2294 case DW_LNS_set_file
:
2295 adv
= read_leb128 (data
, & bytes_read
, 0);
2297 printf (_(" Set File Name to entry %d in the File Name Table\n"),
2299 state_machine_regs
.file
= adv
;
2302 case DW_LNS_set_column
:
2303 uladv
= read_leb128 (data
, & bytes_read
, 0);
2305 printf (_(" Set column to %lu\n"), uladv
);
2306 state_machine_regs
.column
= uladv
;
2309 case DW_LNS_negate_stmt
:
2310 adv
= state_machine_regs
.is_stmt
;
2312 printf (_(" Set is_stmt to %d\n"), adv
);
2313 state_machine_regs
.is_stmt
= adv
;
2316 case DW_LNS_set_basic_block
:
2317 printf (_(" Set basic block\n"));
2318 state_machine_regs
.basic_block
= 1;
2321 case DW_LNS_const_add_pc
:
2322 uladv
= (((255 - info
.li_opcode_base
) / info
.li_line_range
)
2323 * info
.li_min_insn_length
);
2324 state_machine_regs
.address
+= uladv
;
2325 printf (_(" Advance PC by constant %lu to 0x%lx\n"), uladv
,
2326 state_machine_regs
.address
);
2329 case DW_LNS_fixed_advance_pc
:
2330 uladv
= byte_get (data
, 2);
2332 state_machine_regs
.address
+= uladv
;
2333 printf (_(" Advance PC by fixed size amount %lu to 0x%lx\n"),
2334 uladv
, state_machine_regs
.address
);
2337 case DW_LNS_set_prologue_end
:
2338 printf (_(" Set prologue_end to true\n"));
2341 case DW_LNS_set_epilogue_begin
:
2342 printf (_(" Set epilogue_begin to true\n"));
2345 case DW_LNS_set_isa
:
2346 uladv
= read_leb128 (data
, & bytes_read
, 0);
2348 printf (_(" Set ISA to %lu\n"), uladv
);
2352 printf (_(" Unknown opcode %d with operands: "), op_code
);
2354 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
2356 printf ("0x%lx%s", read_leb128 (data
, &bytes_read
, 0),
2357 i
== 1 ? "" : ", ");
2372 unsigned char *name
;
2373 unsigned int directory_index
;
2374 unsigned int modification_date
;
2375 unsigned int length
;
2378 /* Output a decoded representation of the .debug_line section. */
2381 display_debug_lines_decoded (struct dwarf_section
*section
,
2382 unsigned char *data
,
2385 printf (_("Decoded dump of debug contents of section %s:\n\n"),
2390 /* This loop amounts to one iteration per compilation unit. */
2391 DWARF2_Internal_LineInfo info
;
2392 unsigned char *standard_opcodes
;
2393 unsigned char *end_of_sequence
;
2394 unsigned char *hdrptr
;
2395 int initial_length_size
;
2398 File_Entry
*file_table
= NULL
;
2399 unsigned char **directory_table
= NULL
;
2400 unsigned int prev_line
= 0;
2404 /* Extract information from the Line Number Program Header.
2405 (section 6.2.4 in the Dwarf3 doc). */
2407 /* Get the length of this CU's line number information block. */
2408 info
.li_length
= byte_get (hdrptr
, 4);
2411 if (info
.li_length
== 0xffffffff)
2413 /* This section is 64-bit DWARF 3. */
2414 info
.li_length
= byte_get (hdrptr
, 8);
2417 initial_length_size
= 12;
2422 initial_length_size
= 4;
2425 if (info
.li_length
+ initial_length_size
> section
->size
)
2427 warn (_("The line info appears to be corrupt - "
2428 "the section is too small\n"));
2432 /* Get this CU's Line Number Block version number. */
2433 info
.li_version
= byte_get (hdrptr
, 2);
2435 if (info
.li_version
!= 2 && info
.li_version
!= 3)
2437 warn (_("Only DWARF version 2 and 3 line info is currently "
2442 info
.li_prologue_length
= byte_get (hdrptr
, offset_size
);
2443 hdrptr
+= offset_size
;
2444 info
.li_min_insn_length
= byte_get (hdrptr
, 1);
2446 info
.li_default_is_stmt
= byte_get (hdrptr
, 1);
2448 info
.li_line_base
= byte_get (hdrptr
, 1);
2450 info
.li_line_range
= byte_get (hdrptr
, 1);
2452 info
.li_opcode_base
= byte_get (hdrptr
, 1);
2455 /* Sign extend the line base field. */
2456 info
.li_line_base
<<= 24;
2457 info
.li_line_base
>>= 24;
2459 /* Find the end of this CU's Line Number Information Block. */
2460 end_of_sequence
= data
+ info
.li_length
+ initial_length_size
;
2462 reset_state_machine (info
.li_default_is_stmt
);
2464 /* Save a pointer to the contents of the Opcodes table. */
2465 standard_opcodes
= hdrptr
;
2467 /* Traverse the Directory table just to count entries. */
2468 data
= standard_opcodes
+ info
.li_opcode_base
- 1;
2471 unsigned int n_directories
= 0;
2472 unsigned char *ptr_directory_table
= data
;
2477 data
+= strlen ((char *) data
) + 1;
2481 /* Go through the directory table again to save the directories. */
2482 directory_table
= xmalloc (n_directories
* sizeof (unsigned char *));
2485 while (*ptr_directory_table
!= 0)
2487 directory_table
[i
] = ptr_directory_table
;
2488 ptr_directory_table
+= strlen ((char *) ptr_directory_table
) + 1;
2492 /* Skip the NUL at the end of the table. */
2495 /* Traverse the File Name table just to count the entries. */
2498 unsigned int n_files
= 0;
2499 unsigned char *ptr_file_name_table
= data
;
2504 unsigned int bytes_read
;
2506 /* Skip Name, directory index, last modification time and length
2508 data
+= strlen ((char *) data
) + 1;
2509 read_leb128 (data
, & bytes_read
, 0);
2511 read_leb128 (data
, & bytes_read
, 0);
2513 read_leb128 (data
, & bytes_read
, 0);
2519 /* Go through the file table again to save the strings. */
2520 file_table
= xmalloc (n_files
* sizeof (File_Entry
));
2523 while (*ptr_file_name_table
!= 0)
2525 unsigned int bytes_read
;
2527 file_table
[i
].name
= ptr_file_name_table
;
2528 ptr_file_name_table
+= strlen ((char *) ptr_file_name_table
) + 1;
2530 /* We are not interested in directory, time or size. */
2531 file_table
[i
].directory_index
= read_leb128 (ptr_file_name_table
,
2533 ptr_file_name_table
+= bytes_read
;
2534 file_table
[i
].modification_date
= read_leb128 (ptr_file_name_table
,
2536 ptr_file_name_table
+= bytes_read
;
2537 file_table
[i
].length
= read_leb128 (ptr_file_name_table
, & bytes_read
, 0);
2538 ptr_file_name_table
+= bytes_read
;
2543 /* Print the Compilation Unit's name and a header. */
2544 if (directory_table
== NULL
)
2546 printf (_("CU: %s:\n"), file_table
[0].name
);
2547 printf (_("File name Line number Starting address\n"));
2551 if (do_wide
|| strlen ((char *) directory_table
[0]) < 76)
2553 printf (_("CU: %s/%s:\n"), directory_table
[0],
2554 file_table
[0].name
);
2558 printf (_("%s:\n"), file_table
[0].name
);
2560 printf (_("File name Line number Starting address\n"));
2564 /* Skip the NUL at the end of the table. */
2567 /* This loop iterates through the Dwarf Line Number Program. */
2568 while (data
< end_of_sequence
)
2570 unsigned char op_code
;
2572 unsigned long int uladv
;
2573 unsigned int bytes_read
;
2574 int is_special_opcode
= 0;
2577 prev_line
= state_machine_regs
.line
;
2579 if (op_code
>= info
.li_opcode_base
)
2581 op_code
-= info
.li_opcode_base
;
2582 uladv
= (op_code
/ info
.li_line_range
) * info
.li_min_insn_length
;
2583 state_machine_regs
.address
+= uladv
;
2585 adv
= (op_code
% info
.li_line_range
) + info
.li_line_base
;
2586 state_machine_regs
.line
+= adv
;
2587 is_special_opcode
= 1;
2589 else switch (op_code
)
2591 case DW_LNS_extended_op
:
2593 unsigned int ext_op_code_len
;
2594 unsigned int bytes_read
;
2595 unsigned char ext_op_code
;
2596 unsigned char *op_code_data
= data
;
2598 ext_op_code_len
= read_leb128 (op_code_data
, &bytes_read
, 0);
2599 op_code_data
+= bytes_read
;
2601 if (ext_op_code_len
== 0)
2603 warn (_("badly formed extended line op encountered!\n"));
2606 ext_op_code_len
+= bytes_read
;
2607 ext_op_code
= *op_code_data
++;
2609 switch (ext_op_code
)
2611 case DW_LNE_end_sequence
:
2612 reset_state_machine (info
.li_default_is_stmt
);
2614 case DW_LNE_set_address
:
2615 state_machine_regs
.address
=
2616 byte_get (op_code_data
, ext_op_code_len
- bytes_read
- 1);
2618 case DW_LNE_define_file
:
2620 unsigned int dir_index
= 0;
2622 ++state_machine_regs
.last_file_entry
;
2623 op_code_data
+= strlen ((char *) op_code_data
) + 1;
2624 dir_index
= read_leb128 (op_code_data
, & bytes_read
, 0);
2625 op_code_data
+= bytes_read
;
2626 read_leb128 (op_code_data
, & bytes_read
, 0);
2627 op_code_data
+= bytes_read
;
2628 read_leb128 (op_code_data
, & bytes_read
, 0);
2630 printf (_("%s:\n"), directory_table
[dir_index
]);
2634 printf (_("UNKNOWN: length %d\n"), ext_op_code_len
- bytes_read
);
2637 data
+= ext_op_code_len
;
2643 case DW_LNS_advance_pc
:
2644 uladv
= read_leb128 (data
, & bytes_read
, 0);
2645 uladv
*= info
.li_min_insn_length
;
2647 state_machine_regs
.address
+= uladv
;
2650 case DW_LNS_advance_line
:
2651 adv
= read_leb128 (data
, & bytes_read
, 1);
2653 state_machine_regs
.line
+= adv
;
2656 case DW_LNS_set_file
:
2657 adv
= read_leb128 (data
, & bytes_read
, 0);
2659 state_machine_regs
.file
= adv
;
2660 if (file_table
[state_machine_regs
.file
- 1].directory_index
== 0)
2662 /* If directory index is 0, that means current directory. */
2663 printf (_("\n./%s:[++]\n"),
2664 file_table
[state_machine_regs
.file
- 1].name
);
2668 /* The directory index starts counting at 1. */
2669 printf (_("\n%s/%s:\n"),
2670 directory_table
[file_table
[state_machine_regs
.file
- 1].directory_index
- 1],
2671 file_table
[state_machine_regs
.file
- 1].name
);
2675 case DW_LNS_set_column
:
2676 uladv
= read_leb128 (data
, & bytes_read
, 0);
2678 state_machine_regs
.column
= uladv
;
2681 case DW_LNS_negate_stmt
:
2682 adv
= state_machine_regs
.is_stmt
;
2684 state_machine_regs
.is_stmt
= adv
;
2687 case DW_LNS_set_basic_block
:
2688 state_machine_regs
.basic_block
= 1;
2691 case DW_LNS_const_add_pc
:
2692 uladv
= (((255 - info
.li_opcode_base
) / info
.li_line_range
)
2693 * info
.li_min_insn_length
);
2694 state_machine_regs
.address
+= uladv
;
2697 case DW_LNS_fixed_advance_pc
:
2698 uladv
= byte_get (data
, 2);
2700 state_machine_regs
.address
+= uladv
;
2703 case DW_LNS_set_prologue_end
:
2706 case DW_LNS_set_epilogue_begin
:
2709 case DW_LNS_set_isa
:
2710 uladv
= read_leb128 (data
, & bytes_read
, 0);
2712 printf (_(" Set ISA to %lu\n"), uladv
);
2716 printf (_(" Unknown opcode %d with operands: "), op_code
);
2718 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
2720 printf ("0x%lx%s", read_leb128 (data
, &bytes_read
, 0),
2721 i
== 1 ? "" : ", ");
2728 /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row
2729 to the DWARF address/line matrix. */
2730 if ((is_special_opcode
) || (op_code
== DW_LNE_end_sequence
)
2731 || (op_code
== DW_LNS_copy
))
2733 const unsigned int MAX_FILENAME_LENGTH
= 35;
2734 char *fileName
= (char *)file_table
[state_machine_regs
.file
- 1].name
;
2735 char *newFileName
= NULL
;
2736 size_t fileNameLength
= strlen (fileName
);
2738 if ((fileNameLength
> MAX_FILENAME_LENGTH
) && (!do_wide
))
2740 newFileName
= xmalloc (MAX_FILENAME_LENGTH
+ 1);
2741 /* Truncate file name */
2742 strncpy (newFileName
,
2743 fileName
+ fileNameLength
- MAX_FILENAME_LENGTH
,
2744 MAX_FILENAME_LENGTH
+ 1);
2748 newFileName
= xmalloc (fileNameLength
+ 1);
2749 strncpy (newFileName
, fileName
, fileNameLength
+ 1);
2752 if (!do_wide
|| (fileNameLength
<= MAX_FILENAME_LENGTH
))
2754 printf (_("%-35s %11d %#18lx\n"), newFileName
,
2755 state_machine_regs
.line
, state_machine_regs
.address
);
2759 printf (_("%s %11d %#18lx\n"), newFileName
,
2760 state_machine_regs
.line
, state_machine_regs
.address
);
2763 if (op_code
== DW_LNE_end_sequence
)
2771 free (directory_table
);
2772 directory_table
= NULL
;
2780 display_debug_lines (struct dwarf_section
*section
, void *file
)
2782 unsigned char *data
= section
->start
;
2783 unsigned char *end
= data
+ section
->size
;
2785 int retValDecoded
= 0;
2787 if (load_debug_info (file
) == 0)
2789 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
2795 retValRaw
= display_debug_lines_raw (section
, data
, end
);
2797 if (do_debug_lines_decoded
)
2798 retValDecoded
= display_debug_lines_decoded (section
, data
, end
);
2800 if ((do_debug_lines
&& !retValRaw
)
2801 || (do_debug_lines_decoded
&& !retValDecoded
))
2808 find_debug_info_for_offset (unsigned long offset
)
2812 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
2815 for (i
= 0; i
< num_debug_info_entries
; i
++)
2816 if (debug_information
[i
].cu_offset
== offset
)
2817 return debug_information
+ i
;
2823 display_debug_pubnames (struct dwarf_section
*section
,
2824 void *file ATTRIBUTE_UNUSED
)
2826 DWARF2_Internal_PubNames pubnames
;
2827 unsigned char *start
= section
->start
;
2828 unsigned char *end
= start
+ section
->size
;
2830 /* It does not matter if this load fails,
2831 we test for that later on. */
2832 load_debug_info (file
);
2834 printf (_("Contents of the %s section:\n\n"), section
->name
);
2838 unsigned char *data
;
2839 unsigned long offset
;
2840 int offset_size
, initial_length_size
;
2844 pubnames
.pn_length
= byte_get (data
, 4);
2846 if (pubnames
.pn_length
== 0xffffffff)
2848 pubnames
.pn_length
= byte_get (data
, 8);
2851 initial_length_size
= 12;
2856 initial_length_size
= 4;
2859 pubnames
.pn_version
= byte_get (data
, 2);
2862 pubnames
.pn_offset
= byte_get (data
, offset_size
);
2863 data
+= offset_size
;
2865 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
2866 && num_debug_info_entries
> 0
2867 && find_debug_info_for_offset (pubnames
.pn_offset
) == NULL
)
2868 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
2869 pubnames
.pn_offset
, section
->name
);
2871 pubnames
.pn_size
= byte_get (data
, offset_size
);
2872 data
+= offset_size
;
2874 start
+= pubnames
.pn_length
+ initial_length_size
;
2876 if (pubnames
.pn_version
!= 2 && pubnames
.pn_version
!= 3)
2878 static int warned
= 0;
2882 warn (_("Only DWARF 2 and 3 pubnames are currently supported\n"));
2889 printf (_(" Length: %ld\n"),
2890 pubnames
.pn_length
);
2891 printf (_(" Version: %d\n"),
2892 pubnames
.pn_version
);
2893 printf (_(" Offset into .debug_info section: 0x%lx\n"),
2894 pubnames
.pn_offset
);
2895 printf (_(" Size of area in .debug_info section: %ld\n"),
2898 printf (_("\n Offset\tName\n"));
2902 offset
= byte_get (data
, offset_size
);
2906 data
+= offset_size
;
2907 printf (" %-6ld\t\t%s\n", offset
, data
);
2908 data
+= strlen ((char *) data
) + 1;
2911 while (offset
!= 0);
2919 display_debug_macinfo (struct dwarf_section
*section
,
2920 void *file ATTRIBUTE_UNUSED
)
2922 unsigned char *start
= section
->start
;
2923 unsigned char *end
= start
+ section
->size
;
2924 unsigned char *curr
= start
;
2925 unsigned int bytes_read
;
2926 enum dwarf_macinfo_record_type op
;
2928 printf (_("Contents of the %s section:\n\n"), section
->name
);
2932 unsigned int lineno
;
2940 case DW_MACINFO_start_file
:
2942 unsigned int filenum
;
2944 lineno
= read_leb128 (curr
, & bytes_read
, 0);
2946 filenum
= read_leb128 (curr
, & bytes_read
, 0);
2949 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"),
2954 case DW_MACINFO_end_file
:
2955 printf (_(" DW_MACINFO_end_file\n"));
2958 case DW_MACINFO_define
:
2959 lineno
= read_leb128 (curr
, & bytes_read
, 0);
2961 string
= (char *) curr
;
2962 curr
+= strlen (string
) + 1;
2963 printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"),
2967 case DW_MACINFO_undef
:
2968 lineno
= read_leb128 (curr
, & bytes_read
, 0);
2970 string
= (char *) curr
;
2971 curr
+= strlen (string
) + 1;
2972 printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"),
2976 case DW_MACINFO_vendor_ext
:
2978 unsigned int constant
;
2980 constant
= read_leb128 (curr
, & bytes_read
, 0);
2982 string
= (char *) curr
;
2983 curr
+= strlen (string
) + 1;
2984 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"),
2995 display_debug_abbrev (struct dwarf_section
*section
,
2996 void *file ATTRIBUTE_UNUSED
)
2998 abbrev_entry
*entry
;
2999 unsigned char *start
= section
->start
;
3000 unsigned char *end
= start
+ section
->size
;
3002 printf (_("Contents of the %s section:\n\n"), section
->name
);
3008 start
= process_abbrev_section (start
, end
);
3010 if (first_abbrev
== NULL
)
3013 printf (_(" Number TAG\n"));
3015 for (entry
= first_abbrev
; entry
; entry
= entry
->next
)
3019 printf (_(" %ld %s [%s]\n"),
3021 get_TAG_name (entry
->tag
),
3022 entry
->children
? _("has children") : _("no children"));
3024 for (attr
= entry
->first_attr
; attr
; attr
= attr
->next
)
3025 printf (_(" %-18s %s\n"),
3026 get_AT_name (attr
->attribute
),
3027 get_FORM_name (attr
->form
));
3038 display_debug_loc (struct dwarf_section
*section
, void *file
)
3040 unsigned char *start
= section
->start
;
3041 unsigned char *section_end
;
3042 unsigned long bytes
;
3043 unsigned char *section_begin
= start
;
3044 unsigned int num_loc_list
= 0;
3045 unsigned long last_offset
= 0;
3046 unsigned int first
= 0;
3049 int seen_first_offset
= 0;
3050 int use_debug_info
= 1;
3051 unsigned char *next
;
3053 bytes
= section
->size
;
3054 section_end
= start
+ bytes
;
3058 printf (_("\nThe %s section is empty.\n"), section
->name
);
3062 if (load_debug_info (file
) == 0)
3064 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
3069 /* Check the order of location list in .debug_info section. If
3070 offsets of location lists are in the ascending order, we can
3071 use `debug_information' directly. */
3072 for (i
= 0; i
< num_debug_info_entries
; i
++)
3076 num
= debug_information
[i
].num_loc_offsets
;
3077 num_loc_list
+= num
;
3079 /* Check if we can use `debug_information' directly. */
3080 if (use_debug_info
&& num
!= 0)
3082 if (!seen_first_offset
)
3084 /* This is the first location list. */
3085 last_offset
= debug_information
[i
].loc_offsets
[0];
3087 seen_first_offset
= 1;
3093 for (; j
< num
; j
++)
3096 debug_information
[i
].loc_offsets
[j
])
3101 last_offset
= debug_information
[i
].loc_offsets
[j
];
3106 if (!use_debug_info
)
3107 /* FIXME: Should we handle this case? */
3108 error (_("Location lists in .debug_info section aren't in ascending order!\n"));
3110 if (!seen_first_offset
)
3111 error (_("No location lists in .debug_info section!\n"));
3113 /* DWARF sections under Mach-O have non-zero addresses. */
3114 if (debug_information
[first
].num_loc_offsets
> 0
3115 && debug_information
[first
].loc_offsets
[0] != section
->address
)
3116 warn (_("Location lists in %s section start at 0x%lx\n"),
3117 section
->name
, debug_information
[first
].loc_offsets
[0]);
3119 printf (_("Contents of the %s section:\n\n"), section
->name
);
3120 printf (_(" Offset Begin End Expression\n"));
3122 seen_first_offset
= 0;
3123 for (i
= first
; i
< num_debug_info_entries
; i
++)
3127 unsigned short length
;
3128 unsigned long offset
;
3129 unsigned int pointer_size
;
3130 unsigned long cu_offset
;
3131 unsigned long base_address
;
3132 int need_frame_base
;
3135 pointer_size
= debug_information
[i
].pointer_size
;
3136 cu_offset
= debug_information
[i
].cu_offset
;
3138 for (j
= 0; j
< debug_information
[i
].num_loc_offsets
; j
++)
3140 has_frame_base
= debug_information
[i
].have_frame_base
[j
];
3141 /* DWARF sections under Mach-O have non-zero addresses. */
3142 offset
= debug_information
[i
].loc_offsets
[j
] - section
->address
;
3143 next
= section_begin
+ offset
;
3144 base_address
= debug_information
[i
].base_address
;
3146 if (!seen_first_offset
)
3147 seen_first_offset
= 1;
3151 warn (_("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n"),
3152 (unsigned long) (start
- section_begin
),
3153 (unsigned long) (next
- section_begin
));
3154 else if (start
> next
)
3155 warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n"),
3156 (unsigned long) (start
- section_begin
),
3157 (unsigned long) (next
- section_begin
));
3161 if (offset
>= bytes
)
3163 warn (_("Offset 0x%lx is bigger than .debug_loc section size.\n"),
3170 if (start
+ 2 * pointer_size
> section_end
)
3172 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
3177 /* Note: we use sign extension here in order to be sure that
3178 we can detect the -1 escape value. Sign extension into the
3179 top 32 bits of a 32-bit address will not affect the values
3180 that we display since we always show hex values, and always
3181 the bottom 32-bits. */
3182 begin
= byte_get_signed (start
, pointer_size
);
3183 start
+= pointer_size
;
3184 end
= byte_get_signed (start
, pointer_size
);
3185 start
+= pointer_size
;
3187 printf (" %8.8lx ", offset
);
3189 if (begin
== 0 && end
== 0)
3191 printf (_("<End of list>\n"));
3195 /* Check base address specifiers. */
3196 if (begin
== (dwarf_vma
) -1 && end
!= (dwarf_vma
) -1)
3199 print_dwarf_vma (begin
, pointer_size
);
3200 print_dwarf_vma (end
, pointer_size
);
3201 printf (_("(base address)\n"));
3205 if (start
+ 2 > section_end
)
3207 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
3212 length
= byte_get (start
, 2);
3215 if (start
+ length
> section_end
)
3217 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
3222 print_dwarf_vma (begin
+ base_address
, pointer_size
);
3223 print_dwarf_vma (end
+ base_address
, pointer_size
);
3226 need_frame_base
= decode_location_expression (start
,
3229 cu_offset
, section
);
3232 if (need_frame_base
&& !has_frame_base
)
3233 printf (_(" [without DW_AT_frame_base]"));
3236 fputs (_(" (start == end)"), stdout
);
3237 else if (begin
> end
)
3238 fputs (_(" (start > end)"), stdout
);
3247 if (start
< section_end
)
3248 warn (_("There are %ld unused bytes at the end of section %s\n"),
3249 (long) (section_end
- start
), section
->name
);
3254 display_debug_str (struct dwarf_section
*section
,
3255 void *file ATTRIBUTE_UNUSED
)
3257 unsigned char *start
= section
->start
;
3258 unsigned long bytes
= section
->size
;
3259 dwarf_vma addr
= section
->address
;
3263 printf (_("\nThe %s section is empty.\n"), section
->name
);
3267 printf (_("Contents of the %s section:\n\n"), section
->name
);
3275 lbytes
= (bytes
> 16 ? 16 : bytes
);
3277 printf (" 0x%8.8lx ", (unsigned long) addr
);
3279 for (j
= 0; j
< 16; j
++)
3282 printf ("%2.2x", start
[j
]);
3290 for (j
= 0; j
< lbytes
; j
++)
3293 if (k
>= ' ' && k
< 0x80)
3312 display_debug_info (struct dwarf_section
*section
, void *file
)
3314 return process_debug_info (section
, file
, 0);
3319 display_debug_aranges (struct dwarf_section
*section
,
3320 void *file ATTRIBUTE_UNUSED
)
3322 unsigned char *start
= section
->start
;
3323 unsigned char *end
= start
+ section
->size
;
3325 printf (_("The section %s contains:\n\n"), section
->name
);
3327 /* It does not matter if this load fails,
3328 we test for that later on. */
3329 load_debug_info (file
);
3333 unsigned char *hdrptr
;
3334 DWARF2_Internal_ARange arange
;
3335 unsigned char *ranges
;
3338 unsigned char address_size
;
3341 int initial_length_size
;
3345 arange
.ar_length
= byte_get (hdrptr
, 4);
3348 if (arange
.ar_length
== 0xffffffff)
3350 arange
.ar_length
= byte_get (hdrptr
, 8);
3353 initial_length_size
= 12;
3358 initial_length_size
= 4;
3361 arange
.ar_version
= byte_get (hdrptr
, 2);
3364 arange
.ar_info_offset
= byte_get (hdrptr
, offset_size
);
3365 hdrptr
+= offset_size
;
3367 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
3368 && num_debug_info_entries
> 0
3369 && find_debug_info_for_offset (arange
.ar_info_offset
) == NULL
)
3370 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
3371 arange
.ar_info_offset
, section
->name
);
3373 arange
.ar_pointer_size
= byte_get (hdrptr
, 1);
3376 arange
.ar_segment_size
= byte_get (hdrptr
, 1);
3379 if (arange
.ar_version
!= 2 && arange
.ar_version
!= 3)
3381 warn (_("Only DWARF 2 and 3 aranges are currently supported.\n"));
3385 printf (_(" Length: %ld\n"), arange
.ar_length
);
3386 printf (_(" Version: %d\n"), arange
.ar_version
);
3387 printf (_(" Offset into .debug_info: 0x%lx\n"), arange
.ar_info_offset
);
3388 printf (_(" Pointer Size: %d\n"), arange
.ar_pointer_size
);
3389 printf (_(" Segment Size: %d\n"), arange
.ar_segment_size
);
3391 address_size
= arange
.ar_pointer_size
+ arange
.ar_segment_size
;
3393 /* The DWARF spec does not require that the address size be a power
3394 of two, but we do. This will have to change if we ever encounter
3395 an uneven architecture. */
3396 if ((address_size
& (address_size
- 1)) != 0)
3398 warn (_("Pointer size + Segment size is not a power of two.\n"));
3402 if (address_size
> 4)
3403 printf (_("\n Address Length\n"));
3405 printf (_("\n Address Length\n"));
3409 /* Must pad to an alignment boundary that is twice the address size. */
3410 excess
= (hdrptr
- start
) % (2 * address_size
);
3412 ranges
+= (2 * address_size
) - excess
;
3414 start
+= arange
.ar_length
+ initial_length_size
;
3416 while (ranges
+ 2 * address_size
<= start
)
3418 address
= byte_get (ranges
, address_size
);
3420 ranges
+= address_size
;
3422 length
= byte_get (ranges
, address_size
);
3424 ranges
+= address_size
;
3426 print_dwarf_vma (address
, address_size
);
3427 print_dwarf_vma (length
, address_size
);
3438 display_debug_ranges (struct dwarf_section
*section
,
3439 void *file ATTRIBUTE_UNUSED
)
3441 unsigned char *start
= section
->start
;
3442 unsigned char *section_end
;
3443 unsigned long bytes
;
3444 unsigned char *section_begin
= start
;
3445 unsigned int num_range_list
= 0;
3446 unsigned long last_offset
= 0;
3447 unsigned int first
= 0;
3450 int seen_first_offset
= 0;
3451 int use_debug_info
= 1;
3452 unsigned char *next
;
3454 bytes
= section
->size
;
3455 section_end
= start
+ bytes
;
3459 printf (_("\nThe %s section is empty.\n"), section
->name
);
3463 if (load_debug_info (file
) == 0)
3465 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
3470 /* Check the order of range list in .debug_info section. If
3471 offsets of range lists are in the ascending order, we can
3472 use `debug_information' directly. */
3473 for (i
= 0; i
< num_debug_info_entries
; i
++)
3477 num
= debug_information
[i
].num_range_lists
;
3478 num_range_list
+= num
;
3480 /* Check if we can use `debug_information' directly. */
3481 if (use_debug_info
&& num
!= 0)
3483 if (!seen_first_offset
)
3485 /* This is the first range list. */
3486 last_offset
= debug_information
[i
].range_lists
[0];
3488 seen_first_offset
= 1;
3494 for (; j
< num
; j
++)
3497 debug_information
[i
].range_lists
[j
])
3502 last_offset
= debug_information
[i
].range_lists
[j
];
3507 if (!use_debug_info
)
3508 /* FIXME: Should we handle this case? */
3509 error (_("Range lists in .debug_info section aren't in ascending order!\n"));
3511 if (!seen_first_offset
)
3512 error (_("No range lists in .debug_info section!\n"));
3514 /* DWARF sections under Mach-O have non-zero addresses. */
3515 if (debug_information
[first
].num_range_lists
> 0
3516 && debug_information
[first
].range_lists
[0] != section
->address
)
3517 warn (_("Range lists in %s section start at 0x%lx\n"),
3518 section
->name
, debug_information
[first
].range_lists
[0]);
3520 printf (_("Contents of the %s section:\n\n"), section
->name
);
3521 printf (_(" Offset Begin End\n"));
3523 seen_first_offset
= 0;
3524 for (i
= first
; i
< num_debug_info_entries
; i
++)
3528 unsigned long offset
;
3529 unsigned int pointer_size
;
3530 unsigned long base_address
;
3532 pointer_size
= debug_information
[i
].pointer_size
;
3534 for (j
= 0; j
< debug_information
[i
].num_range_lists
; j
++)
3536 /* DWARF sections under Mach-O have non-zero addresses. */
3537 offset
= debug_information
[i
].range_lists
[j
] - section
->address
;
3538 next
= section_begin
+ offset
;
3539 base_address
= debug_information
[i
].base_address
;
3541 if (!seen_first_offset
)
3542 seen_first_offset
= 1;
3546 warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"),
3547 (unsigned long) (start
- section_begin
),
3548 (unsigned long) (next
- section_begin
), section
->name
);
3549 else if (start
> next
)
3550 warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"),
3551 (unsigned long) (start
- section_begin
),
3552 (unsigned long) (next
- section_begin
), section
->name
);
3558 /* Note: we use sign extension here in order to be sure that
3559 we can detect the -1 escape value. Sign extension into the
3560 top 32 bits of a 32-bit address will not affect the values
3561 that we display since we always show hex values, and always
3562 the bottom 32-bits. */
3563 begin
= byte_get_signed (start
, pointer_size
);
3564 start
+= pointer_size
;
3565 end
= byte_get_signed (start
, pointer_size
);
3566 start
+= pointer_size
;
3568 printf (" %8.8lx ", offset
);
3570 if (begin
== 0 && end
== 0)
3572 printf (_("<End of list>\n"));
3576 print_dwarf_vma (begin
, pointer_size
);
3577 print_dwarf_vma (end
, pointer_size
);
3579 /* Check base address specifiers. */
3580 if (begin
== (dwarf_vma
) -1 && end
!= (dwarf_vma
) -1)
3583 printf ("(base address)\n");
3588 fputs (_("(start == end)"), stdout
);
3589 else if (begin
> end
)
3590 fputs (_("(start > end)"), stdout
);
3600 typedef struct Frame_Chunk
3602 struct Frame_Chunk
*next
;
3603 unsigned char *chunk_start
;
3605 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
3606 short int *col_type
;
3609 unsigned int code_factor
;
3611 unsigned long pc_begin
;
3612 unsigned long pc_range
;
3616 unsigned char fde_encoding
;
3617 unsigned char cfa_exp
;
3621 /* A marker for a col_type that means this column was never referenced
3622 in the frame info. */
3623 #define DW_CFA_unreferenced (-1)
3626 frame_need_space (Frame_Chunk
*fc
, int reg
)
3628 int prev
= fc
->ncols
;
3630 if (reg
< fc
->ncols
)
3633 fc
->ncols
= reg
+ 1;
3634 fc
->col_type
= xcrealloc (fc
->col_type
, fc
->ncols
, sizeof (short int));
3635 fc
->col_offset
= xcrealloc (fc
->col_offset
, fc
->ncols
, sizeof (int));
3637 while (prev
< fc
->ncols
)
3639 fc
->col_type
[prev
] = DW_CFA_unreferenced
;
3640 fc
->col_offset
[prev
] = 0;
3645 static const char *const dwarf_regnames_i386
[] =
3647 "eax", "ecx", "edx", "ebx",
3648 "esp", "ebp", "esi", "edi",
3649 "eip", "eflags", NULL
,
3650 "st0", "st1", "st2", "st3",
3651 "st4", "st5", "st6", "st7",
3653 "xmm0", "xmm1", "xmm2", "xmm3",
3654 "xmm4", "xmm5", "xmm6", "xmm7",
3655 "mm0", "mm1", "mm2", "mm3",
3656 "mm4", "mm5", "mm6", "mm7",
3657 "fcw", "fsw", "mxcsr",
3658 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
,
3662 static const char *const dwarf_regnames_x86_64
[] =
3664 "rax", "rdx", "rcx", "rbx",
3665 "rsi", "rdi", "rbp", "rsp",
3666 "r8", "r9", "r10", "r11",
3667 "r12", "r13", "r14", "r15",
3669 "xmm0", "xmm1", "xmm2", "xmm3",
3670 "xmm4", "xmm5", "xmm6", "xmm7",
3671 "xmm8", "xmm9", "xmm10", "xmm11",
3672 "xmm12", "xmm13", "xmm14", "xmm15",
3673 "st0", "st1", "st2", "st3",
3674 "st4", "st5", "st6", "st7",
3675 "mm0", "mm1", "mm2", "mm3",
3676 "mm4", "mm5", "mm6", "mm7",
3678 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
,
3679 "fs.base", "gs.base", NULL
, NULL
,
3681 "mxcsr", "fcw", "fsw"
3684 static const char *const *dwarf_regnames
;
3685 static unsigned int dwarf_regnames_count
;
3688 init_dwarf_regnames (unsigned int e_machine
)
3694 dwarf_regnames
= dwarf_regnames_i386
;
3695 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_i386
);
3699 dwarf_regnames
= dwarf_regnames_x86_64
;
3700 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_x86_64
);
3709 regname (unsigned int regno
, int row
)
3711 static char reg
[64];
3713 && regno
< dwarf_regnames_count
3714 && dwarf_regnames
[regno
] != NULL
)
3717 return dwarf_regnames
[regno
];
3718 snprintf (reg
, sizeof (reg
), "r%d (%s)", regno
,
3719 dwarf_regnames
[regno
]);
3722 snprintf (reg
, sizeof (reg
), "r%d", regno
);
3727 frame_display_row (Frame_Chunk
*fc
, int *need_col_headers
, int *max_regs
)
3732 if (*max_regs
< fc
->ncols
)
3733 *max_regs
= fc
->ncols
;
3735 if (*need_col_headers
)
3737 static const char *loc
= " LOC";
3739 *need_col_headers
= 0;
3741 printf ("%-*s CFA ", eh_addr_size
* 2, loc
);
3743 for (r
= 0; r
< *max_regs
; r
++)
3744 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
3749 printf ("%-5s ", regname (r
, 1));
3755 printf ("%0*lx ", eh_addr_size
* 2, fc
->pc_begin
);
3757 strcpy (tmp
, "exp");
3759 sprintf (tmp
, "%s%+d", regname (fc
->cfa_reg
, 1), fc
->cfa_offset
);
3760 printf ("%-8s ", tmp
);
3762 for (r
= 0; r
< fc
->ncols
; r
++)
3764 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
3766 switch (fc
->col_type
[r
])
3768 case DW_CFA_undefined
:
3771 case DW_CFA_same_value
:
3775 sprintf (tmp
, "c%+d", fc
->col_offset
[r
]);
3777 case DW_CFA_val_offset
:
3778 sprintf (tmp
, "v%+d", fc
->col_offset
[r
]);
3780 case DW_CFA_register
:
3781 sprintf (tmp
, "%s", regname (fc
->col_offset
[r
], 0));
3783 case DW_CFA_expression
:
3784 strcpy (tmp
, "exp");
3786 case DW_CFA_val_expression
:
3787 strcpy (tmp
, "vexp");
3790 strcpy (tmp
, "n/a");
3793 printf ("%-5s ", tmp
);
3799 #define GET(N) byte_get (start, N); start += N
3800 #define LEB() read_leb128 (start, & length_return, 0); start += length_return
3801 #define SLEB() read_leb128 (start, & length_return, 1); start += length_return
3804 display_debug_frames (struct dwarf_section
*section
,
3805 void *file ATTRIBUTE_UNUSED
)
3807 unsigned char *start
= section
->start
;
3808 unsigned char *end
= start
+ section
->size
;
3809 unsigned char *section_start
= start
;
3810 Frame_Chunk
*chunks
= 0;
3811 Frame_Chunk
*remembered_state
= 0;
3813 int is_eh
= strcmp (section
->name
, ".eh_frame") == 0;
3814 unsigned int length_return
;
3817 printf (_("The section %s contains:\n"), section
->name
);
3821 unsigned char *saved_start
;
3822 unsigned char *block_end
;
3823 unsigned long length
;
3824 unsigned long cie_id
;
3827 int need_col_headers
= 1;
3828 unsigned char *augmentation_data
= NULL
;
3829 unsigned long augmentation_data_len
= 0;
3830 int encoded_ptr_size
= eh_addr_size
;
3832 int initial_length_size
;
3834 saved_start
= start
;
3835 length
= byte_get (start
, 4); start
+= 4;
3839 printf ("\n%08lx ZERO terminator\n\n",
3840 (unsigned long)(saved_start
- section_start
));
3844 if (length
== 0xffffffff)
3846 length
= byte_get (start
, 8);
3849 initial_length_size
= 12;
3854 initial_length_size
= 4;
3857 block_end
= saved_start
+ length
+ initial_length_size
;
3858 if (block_end
> end
)
3860 warn ("Invalid length %#08lx in FDE at %#08lx\n",
3861 length
, (unsigned long)(saved_start
- section_start
));
3864 cie_id
= byte_get (start
, offset_size
); start
+= offset_size
;
3866 if (is_eh
? (cie_id
== 0) : (cie_id
== DW_CIE_ID
))
3870 fc
= xmalloc (sizeof (Frame_Chunk
));
3871 memset (fc
, 0, sizeof (Frame_Chunk
));
3875 fc
->chunk_start
= saved_start
;
3877 fc
->col_type
= xmalloc (sizeof (short int));
3878 fc
->col_offset
= xmalloc (sizeof (int));
3879 frame_need_space (fc
, max_regs
- 1);
3883 fc
->augmentation
= (char *) start
;
3884 start
= (unsigned char *) strchr ((char *) start
, '\0') + 1;
3886 if (fc
->augmentation
[0] == 'z')
3888 fc
->code_factor
= LEB ();
3889 fc
->data_factor
= SLEB ();
3898 augmentation_data_len
= LEB ();
3899 augmentation_data
= start
;
3900 start
+= augmentation_data_len
;
3902 else if (strcmp (fc
->augmentation
, "eh") == 0)
3904 start
+= eh_addr_size
;
3905 fc
->code_factor
= LEB ();
3906 fc
->data_factor
= SLEB ();
3918 fc
->code_factor
= LEB ();
3919 fc
->data_factor
= SLEB ();
3931 if (do_debug_frames_interp
)
3932 printf ("\n%08lx %08lx %08lx CIE \"%s\" cf=%d df=%d ra=%d\n",
3933 (unsigned long)(saved_start
- section_start
), length
, cie_id
,
3934 fc
->augmentation
, fc
->code_factor
, fc
->data_factor
,
3938 printf ("\n%08lx %08lx %08lx CIE\n",
3939 (unsigned long)(saved_start
- section_start
), length
, cie_id
);
3940 printf (" Version: %d\n", version
);
3941 printf (" Augmentation: \"%s\"\n", fc
->augmentation
);
3942 printf (" Code alignment factor: %u\n", fc
->code_factor
);
3943 printf (" Data alignment factor: %d\n", fc
->data_factor
);
3944 printf (" Return address column: %d\n", fc
->ra
);
3946 if (augmentation_data_len
)
3949 printf (" Augmentation data: ");
3950 for (i
= 0; i
< augmentation_data_len
; ++i
)
3951 printf (" %02x", augmentation_data
[i
]);
3957 if (augmentation_data_len
)
3959 unsigned char *p
, *q
;
3960 p
= (unsigned char *) fc
->augmentation
+ 1;
3961 q
= augmentation_data
;
3968 q
+= 1 + size_of_encoded_value (*q
);
3970 fc
->fde_encoding
= *q
++;
3976 if (fc
->fde_encoding
)
3977 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
3980 frame_need_space (fc
, fc
->ra
);
3984 unsigned char *look_for
;
3985 static Frame_Chunk fde_fc
;
3988 memset (fc
, 0, sizeof (Frame_Chunk
));
3990 look_for
= is_eh
? start
- 4 - cie_id
: section_start
+ cie_id
;
3992 for (cie
= chunks
; cie
; cie
= cie
->next
)
3993 if (cie
->chunk_start
== look_for
)
3998 warn ("Invalid CIE pointer %#08lx in FDE at %#08lx\n",
3999 cie_id
, (unsigned long)(saved_start
- section_start
));
4001 fc
->col_type
= xmalloc (sizeof (short int));
4002 fc
->col_offset
= xmalloc (sizeof (int));
4003 frame_need_space (fc
, max_regs
- 1);
4005 fc
->augmentation
= "";
4006 fc
->fde_encoding
= 0;
4010 fc
->ncols
= cie
->ncols
;
4011 fc
->col_type
= xcmalloc (fc
->ncols
, sizeof (short int));
4012 fc
->col_offset
= xcmalloc (fc
->ncols
, sizeof (int));
4013 memcpy (fc
->col_type
, cie
->col_type
, fc
->ncols
* sizeof (short int));
4014 memcpy (fc
->col_offset
, cie
->col_offset
, fc
->ncols
* sizeof (int));
4015 fc
->augmentation
= cie
->augmentation
;
4016 fc
->code_factor
= cie
->code_factor
;
4017 fc
->data_factor
= cie
->data_factor
;
4018 fc
->cfa_reg
= cie
->cfa_reg
;
4019 fc
->cfa_offset
= cie
->cfa_offset
;
4021 frame_need_space (fc
, max_regs
- 1);
4022 fc
->fde_encoding
= cie
->fde_encoding
;
4025 if (fc
->fde_encoding
)
4026 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
4028 fc
->pc_begin
= get_encoded_value (start
, fc
->fde_encoding
);
4029 if ((fc
->fde_encoding
& 0x70) == DW_EH_PE_pcrel
)
4030 fc
->pc_begin
+= section
->address
+ (start
- section_start
);
4031 start
+= encoded_ptr_size
;
4032 fc
->pc_range
= byte_get (start
, encoded_ptr_size
);
4033 start
+= encoded_ptr_size
;
4035 if (cie
->augmentation
[0] == 'z')
4037 augmentation_data_len
= LEB ();
4038 augmentation_data
= start
;
4039 start
+= augmentation_data_len
;
4042 printf ("\n%08lx %08lx %08lx FDE cie=%08lx pc=%08lx..%08lx\n",
4043 (unsigned long)(saved_start
- section_start
), length
, cie_id
,
4044 (unsigned long)(cie
->chunk_start
- section_start
),
4045 fc
->pc_begin
, fc
->pc_begin
+ fc
->pc_range
);
4046 if (! do_debug_frames_interp
&& augmentation_data_len
)
4050 printf (" Augmentation data: ");
4051 for (i
= 0; i
< augmentation_data_len
; ++i
)
4052 printf (" %02x", augmentation_data
[i
]);
4058 /* At this point, fc is the current chunk, cie (if any) is set, and
4059 we're about to interpret instructions for the chunk. */
4060 /* ??? At present we need to do this always, since this sizes the
4061 fc->col_type and fc->col_offset arrays, which we write into always.
4062 We should probably split the interpreted and non-interpreted bits
4063 into two different routines, since there's so much that doesn't
4064 really overlap between them. */
4065 if (1 || do_debug_frames_interp
)
4067 /* Start by making a pass over the chunk, allocating storage
4068 and taking note of what registers are used. */
4069 unsigned char *tmp
= start
;
4071 while (start
< block_end
)
4074 unsigned long reg
, tmp
;
4081 /* Warning: if you add any more cases to this switch, be
4082 sure to add them to the corresponding switch below. */
4085 case DW_CFA_advance_loc
:
4089 frame_need_space (fc
, opa
);
4090 fc
->col_type
[opa
] = DW_CFA_undefined
;
4092 case DW_CFA_restore
:
4093 frame_need_space (fc
, opa
);
4094 fc
->col_type
[opa
] = DW_CFA_undefined
;
4096 case DW_CFA_set_loc
:
4097 start
+= encoded_ptr_size
;
4099 case DW_CFA_advance_loc1
:
4102 case DW_CFA_advance_loc2
:
4105 case DW_CFA_advance_loc4
:
4108 case DW_CFA_offset_extended
:
4109 case DW_CFA_val_offset
:
4110 reg
= LEB (); LEB ();
4111 frame_need_space (fc
, reg
);
4112 fc
->col_type
[reg
] = DW_CFA_undefined
;
4114 case DW_CFA_restore_extended
:
4116 frame_need_space (fc
, reg
);
4117 fc
->col_type
[reg
] = DW_CFA_undefined
;
4119 case DW_CFA_undefined
:
4121 frame_need_space (fc
, reg
);
4122 fc
->col_type
[reg
] = DW_CFA_undefined
;
4124 case DW_CFA_same_value
:
4126 frame_need_space (fc
, reg
);
4127 fc
->col_type
[reg
] = DW_CFA_undefined
;
4129 case DW_CFA_register
:
4130 reg
= LEB (); LEB ();
4131 frame_need_space (fc
, reg
);
4132 fc
->col_type
[reg
] = DW_CFA_undefined
;
4134 case DW_CFA_def_cfa
:
4137 case DW_CFA_def_cfa_register
:
4140 case DW_CFA_def_cfa_offset
:
4143 case DW_CFA_def_cfa_expression
:
4147 case DW_CFA_expression
:
4148 case DW_CFA_val_expression
:
4152 frame_need_space (fc
, reg
);
4153 fc
->col_type
[reg
] = DW_CFA_undefined
;
4155 case DW_CFA_offset_extended_sf
:
4156 case DW_CFA_val_offset_sf
:
4157 reg
= LEB (); SLEB ();
4158 frame_need_space (fc
, reg
);
4159 fc
->col_type
[reg
] = DW_CFA_undefined
;
4161 case DW_CFA_def_cfa_sf
:
4164 case DW_CFA_def_cfa_offset_sf
:
4167 case DW_CFA_MIPS_advance_loc8
:
4170 case DW_CFA_GNU_args_size
:
4173 case DW_CFA_GNU_negative_offset_extended
:
4174 reg
= LEB (); LEB ();
4175 frame_need_space (fc
, reg
);
4176 fc
->col_type
[reg
] = DW_CFA_undefined
;
4185 /* Now we know what registers are used, make a second pass over
4186 the chunk, this time actually printing out the info. */
4188 while (start
< block_end
)
4191 unsigned long ul
, reg
, roffs
;
4200 /* Warning: if you add any more cases to this switch, be
4201 sure to add them to the corresponding switch above. */
4204 case DW_CFA_advance_loc
:
4205 if (do_debug_frames_interp
)
4206 frame_display_row (fc
, &need_col_headers
, &max_regs
);
4208 printf (" DW_CFA_advance_loc: %d to %08lx\n",
4209 opa
* fc
->code_factor
,
4210 fc
->pc_begin
+ opa
* fc
->code_factor
);
4211 fc
->pc_begin
+= opa
* fc
->code_factor
;
4216 if (! do_debug_frames_interp
)
4217 printf (" DW_CFA_offset: %s at cfa%+ld\n",
4218 regname (opa
, 0), roffs
* fc
->data_factor
);
4219 fc
->col_type
[opa
] = DW_CFA_offset
;
4220 fc
->col_offset
[opa
] = roffs
* fc
->data_factor
;
4223 case DW_CFA_restore
:
4224 if (! do_debug_frames_interp
)
4225 printf (" DW_CFA_restore: %s\n", regname (opa
, 0));
4226 fc
->col_type
[opa
] = cie
->col_type
[opa
];
4227 fc
->col_offset
[opa
] = cie
->col_offset
[opa
];
4230 case DW_CFA_set_loc
:
4231 vma
= get_encoded_value (start
, fc
->fde_encoding
);
4232 if ((fc
->fde_encoding
& 0x70) == DW_EH_PE_pcrel
)
4233 vma
+= section
->address
+ (start
- section_start
);
4234 start
+= encoded_ptr_size
;
4235 if (do_debug_frames_interp
)
4236 frame_display_row (fc
, &need_col_headers
, &max_regs
);
4238 printf (" DW_CFA_set_loc: %08lx\n", (unsigned long)vma
);
4242 case DW_CFA_advance_loc1
:
4243 ofs
= byte_get (start
, 1); start
+= 1;
4244 if (do_debug_frames_interp
)
4245 frame_display_row (fc
, &need_col_headers
, &max_regs
);
4247 printf (" DW_CFA_advance_loc1: %ld to %08lx\n",
4248 ofs
* fc
->code_factor
,
4249 fc
->pc_begin
+ ofs
* fc
->code_factor
);
4250 fc
->pc_begin
+= ofs
* fc
->code_factor
;
4253 case DW_CFA_advance_loc2
:
4254 ofs
= byte_get (start
, 2); start
+= 2;
4255 if (do_debug_frames_interp
)
4256 frame_display_row (fc
, &need_col_headers
, &max_regs
);
4258 printf (" DW_CFA_advance_loc2: %ld to %08lx\n",
4259 ofs
* fc
->code_factor
,
4260 fc
->pc_begin
+ ofs
* fc
->code_factor
);
4261 fc
->pc_begin
+= ofs
* fc
->code_factor
;
4264 case DW_CFA_advance_loc4
:
4265 ofs
= byte_get (start
, 4); start
+= 4;
4266 if (do_debug_frames_interp
)
4267 frame_display_row (fc
, &need_col_headers
, &max_regs
);
4269 printf (" DW_CFA_advance_loc4: %ld to %08lx\n",
4270 ofs
* fc
->code_factor
,
4271 fc
->pc_begin
+ ofs
* fc
->code_factor
);
4272 fc
->pc_begin
+= ofs
* fc
->code_factor
;
4275 case DW_CFA_offset_extended
:
4278 if (! do_debug_frames_interp
)
4279 printf (" DW_CFA_offset_extended: %s at cfa%+ld\n",
4280 regname (reg
, 0), roffs
* fc
->data_factor
);
4281 fc
->col_type
[reg
] = DW_CFA_offset
;
4282 fc
->col_offset
[reg
] = roffs
* fc
->data_factor
;
4285 case DW_CFA_val_offset
:
4288 if (! do_debug_frames_interp
)
4289 printf (" DW_CFA_val_offset: %s at cfa%+ld\n",
4290 regname (reg
, 0), roffs
* fc
->data_factor
);
4291 fc
->col_type
[reg
] = DW_CFA_val_offset
;
4292 fc
->col_offset
[reg
] = roffs
* fc
->data_factor
;
4295 case DW_CFA_restore_extended
:
4297 if (! do_debug_frames_interp
)
4298 printf (" DW_CFA_restore_extended: %s\n",
4300 fc
->col_type
[reg
] = cie
->col_type
[reg
];
4301 fc
->col_offset
[reg
] = cie
->col_offset
[reg
];
4304 case DW_CFA_undefined
:
4306 if (! do_debug_frames_interp
)
4307 printf (" DW_CFA_undefined: %s\n", regname (reg
, 0));
4308 fc
->col_type
[reg
] = DW_CFA_undefined
;
4309 fc
->col_offset
[reg
] = 0;
4312 case DW_CFA_same_value
:
4314 if (! do_debug_frames_interp
)
4315 printf (" DW_CFA_same_value: %s\n", regname (reg
, 0));
4316 fc
->col_type
[reg
] = DW_CFA_same_value
;
4317 fc
->col_offset
[reg
] = 0;
4320 case DW_CFA_register
:
4323 if (! do_debug_frames_interp
)
4325 printf (" DW_CFA_register: %s in ",
4327 puts (regname (roffs
, 0));
4329 fc
->col_type
[reg
] = DW_CFA_register
;
4330 fc
->col_offset
[reg
] = roffs
;
4333 case DW_CFA_remember_state
:
4334 if (! do_debug_frames_interp
)
4335 printf (" DW_CFA_remember_state\n");
4336 rs
= xmalloc (sizeof (Frame_Chunk
));
4337 rs
->ncols
= fc
->ncols
;
4338 rs
->col_type
= xcmalloc (rs
->ncols
, sizeof (short int));
4339 rs
->col_offset
= xcmalloc (rs
->ncols
, sizeof (int));
4340 memcpy (rs
->col_type
, fc
->col_type
, rs
->ncols
);
4341 memcpy (rs
->col_offset
, fc
->col_offset
, rs
->ncols
* sizeof (int));
4342 rs
->next
= remembered_state
;
4343 remembered_state
= rs
;
4346 case DW_CFA_restore_state
:
4347 if (! do_debug_frames_interp
)
4348 printf (" DW_CFA_restore_state\n");
4349 rs
= remembered_state
;
4352 remembered_state
= rs
->next
;
4353 frame_need_space (fc
, rs
->ncols
- 1);
4354 memcpy (fc
->col_type
, rs
->col_type
, rs
->ncols
);
4355 memcpy (fc
->col_offset
, rs
->col_offset
,
4356 rs
->ncols
* sizeof (int));
4357 free (rs
->col_type
);
4358 free (rs
->col_offset
);
4361 else if (do_debug_frames_interp
)
4362 printf ("Mismatched DW_CFA_restore_state\n");
4365 case DW_CFA_def_cfa
:
4366 fc
->cfa_reg
= LEB ();
4367 fc
->cfa_offset
= LEB ();
4369 if (! do_debug_frames_interp
)
4370 printf (" DW_CFA_def_cfa: %s ofs %d\n",
4371 regname (fc
->cfa_reg
, 0), fc
->cfa_offset
);
4374 case DW_CFA_def_cfa_register
:
4375 fc
->cfa_reg
= LEB ();
4377 if (! do_debug_frames_interp
)
4378 printf (" DW_CFA_def_cfa_register: %s\n",
4379 regname (fc
->cfa_reg
, 0));
4382 case DW_CFA_def_cfa_offset
:
4383 fc
->cfa_offset
= LEB ();
4384 if (! do_debug_frames_interp
)
4385 printf (" DW_CFA_def_cfa_offset: %d\n", fc
->cfa_offset
);
4389 if (! do_debug_frames_interp
)
4390 printf (" DW_CFA_nop\n");
4393 case DW_CFA_def_cfa_expression
:
4395 if (! do_debug_frames_interp
)
4397 printf (" DW_CFA_def_cfa_expression (");
4398 decode_location_expression (start
, eh_addr_size
, ul
, 0,
4406 case DW_CFA_expression
:
4409 if (! do_debug_frames_interp
)
4411 printf (" DW_CFA_expression: %s (",
4413 decode_location_expression (start
, eh_addr_size
,
4417 fc
->col_type
[reg
] = DW_CFA_expression
;
4421 case DW_CFA_val_expression
:
4424 if (! do_debug_frames_interp
)
4426 printf (" DW_CFA_val_expression: %s (",
4428 decode_location_expression (start
, eh_addr_size
, ul
, 0,
4432 fc
->col_type
[reg
] = DW_CFA_val_expression
;
4436 case DW_CFA_offset_extended_sf
:
4439 frame_need_space (fc
, reg
);
4440 if (! do_debug_frames_interp
)
4441 printf (" DW_CFA_offset_extended_sf: %s at cfa%+ld\n",
4442 regname (reg
, 0), l
* fc
->data_factor
);
4443 fc
->col_type
[reg
] = DW_CFA_offset
;
4444 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
4447 case DW_CFA_val_offset_sf
:
4450 frame_need_space (fc
, reg
);
4451 if (! do_debug_frames_interp
)
4452 printf (" DW_CFA_val_offset_sf: %s at cfa%+ld\n",
4453 regname (reg
, 0), l
* fc
->data_factor
);
4454 fc
->col_type
[reg
] = DW_CFA_val_offset
;
4455 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
4458 case DW_CFA_def_cfa_sf
:
4459 fc
->cfa_reg
= LEB ();
4460 fc
->cfa_offset
= SLEB ();
4461 fc
->cfa_offset
= fc
->cfa_offset
* fc
->data_factor
;
4463 if (! do_debug_frames_interp
)
4464 printf (" DW_CFA_def_cfa_sf: %s ofs %d\n",
4465 regname (fc
->cfa_reg
, 0), fc
->cfa_offset
);
4468 case DW_CFA_def_cfa_offset_sf
:
4469 fc
->cfa_offset
= SLEB ();
4470 fc
->cfa_offset
= fc
->cfa_offset
* fc
->data_factor
;
4471 if (! do_debug_frames_interp
)
4472 printf (" DW_CFA_def_cfa_offset_sf: %d\n", fc
->cfa_offset
);
4475 case DW_CFA_MIPS_advance_loc8
:
4476 ofs
= byte_get (start
, 8); start
+= 8;
4477 if (do_debug_frames_interp
)
4478 frame_display_row (fc
, &need_col_headers
, &max_regs
);
4480 printf (" DW_CFA_MIPS_advance_loc8: %ld to %08lx\n",
4481 ofs
* fc
->code_factor
,
4482 fc
->pc_begin
+ ofs
* fc
->code_factor
);
4483 fc
->pc_begin
+= ofs
* fc
->code_factor
;
4486 case DW_CFA_GNU_window_save
:
4487 if (! do_debug_frames_interp
)
4488 printf (" DW_CFA_GNU_window_save\n");
4491 case DW_CFA_GNU_args_size
:
4493 if (! do_debug_frames_interp
)
4494 printf (" DW_CFA_GNU_args_size: %ld\n", ul
);
4497 case DW_CFA_GNU_negative_offset_extended
:
4500 frame_need_space (fc
, reg
);
4501 if (! do_debug_frames_interp
)
4502 printf (" DW_CFA_GNU_negative_offset_extended: %s at cfa%+ld\n",
4503 regname (reg
, 0), l
* fc
->data_factor
);
4504 fc
->col_type
[reg
] = DW_CFA_offset
;
4505 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
4509 if (op
>= DW_CFA_lo_user
&& op
<= DW_CFA_hi_user
)
4510 printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op
);
4512 warn (_("unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op
);
4517 if (do_debug_frames_interp
)
4518 frame_display_row (fc
, &need_col_headers
, &max_regs
);
4533 display_debug_not_supported (struct dwarf_section
*section
,
4534 void *file ATTRIBUTE_UNUSED
)
4536 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
4543 cmalloc (size_t nmemb
, size_t size
)
4545 /* Check for overflow. */
4546 if (nmemb
>= ~(size_t) 0 / size
)
4549 return malloc (nmemb
* size
);
4553 xcmalloc (size_t nmemb
, size_t size
)
4555 /* Check for overflow. */
4556 if (nmemb
>= ~(size_t) 0 / size
)
4559 return xmalloc (nmemb
* size
);
4563 xcrealloc (void *ptr
, size_t nmemb
, size_t size
)
4565 /* Check for overflow. */
4566 if (nmemb
>= ~(size_t) 0 / size
)
4569 return xrealloc (ptr
, nmemb
* size
);
4573 error (const char *message
, ...)
4577 va_start (args
, message
);
4578 fprintf (stderr
, _("%s: Error: "), program_name
);
4579 vfprintf (stderr
, message
, args
);
4584 warn (const char *message
, ...)
4588 va_start (args
, message
);
4589 fprintf (stderr
, _("%s: Warning: "), program_name
);
4590 vfprintf (stderr
, message
, args
);
4595 free_debug_memory (void)
4597 enum dwarf_section_display_enum i
;
4601 for (i
= 0; i
< max
; i
++)
4602 free_debug_section (i
);
4604 if (debug_information
!= NULL
)
4606 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
)
4608 for (i
= 0; i
< num_debug_info_entries
; i
++)
4610 if (!debug_information
[i
].max_loc_offsets
)
4612 free (debug_information
[i
].loc_offsets
);
4613 free (debug_information
[i
].have_frame_base
);
4615 if (!debug_information
[i
].max_range_lists
)
4616 free (debug_information
[i
].range_lists
);
4620 free (debug_information
);
4621 debug_information
= NULL
;
4622 num_debug_info_entries
= 0;
4626 struct dwarf_section_display debug_displays
[] =
4628 { { ".debug_abbrev", ".zdebug_abbrev", NULL
, NULL
, 0, 0 },
4629 display_debug_abbrev
, 0, 0 },
4630 { { ".debug_aranges", ".zdebug_aranges", NULL
, NULL
, 0, 0 },
4631 display_debug_aranges
, 0, 0 },
4632 { { ".debug_frame", ".zdebug_frame", NULL
, NULL
, 0, 0 },
4633 display_debug_frames
, 1, 0 },
4634 { { ".debug_info", ".zdebug_info", NULL
, NULL
, 0, 0 },
4635 display_debug_info
, 1, 0 },
4636 { { ".debug_line", ".zdebug_line", NULL
, NULL
, 0, 0 },
4637 display_debug_lines
, 0, 0 },
4638 { { ".debug_pubnames", ".zdebug_pubnames", NULL
, NULL
, 0, 0 },
4639 display_debug_pubnames
, 0, 0 },
4640 { { ".eh_frame", "", NULL
, NULL
, 0, 0 },
4641 display_debug_frames
, 1, 1 },
4642 { { ".debug_macinfo", ".zdebug_macinfo", NULL
, NULL
, 0, 0 },
4643 display_debug_macinfo
, 0, 0 },
4644 { { ".debug_str", ".zdebug_str", NULL
, NULL
, 0, 0 },
4645 display_debug_str
, 0, 0 },
4646 { { ".debug_loc", ".zdebug_loc", NULL
, NULL
, 0, 0 },
4647 display_debug_loc
, 0, 0 },
4648 { { ".debug_pubtypes", ".zdebug_pubtypes", NULL
, NULL
, 0, 0 },
4649 display_debug_pubnames
, 0, 0 },
4650 { { ".debug_ranges", ".zdebug_ranges", NULL
, NULL
, 0, 0 },
4651 display_debug_ranges
, 0, 0 },
4652 { { ".debug_static_func", ".zdebug_static_func", NULL
, NULL
, 0, 0 },
4653 display_debug_not_supported
, 0, 0 },
4654 { { ".debug_static_vars", ".zdebug_static_vars", NULL
, NULL
, 0, 0 },
4655 display_debug_not_supported
, 0, 0 },
4656 { { ".debug_types", ".zdebug_types", NULL
, NULL
, 0, 0 },
4657 display_debug_not_supported
, 0, 0 },
4658 { { ".debug_weaknames", ".zdebug_weaknames", NULL
, NULL
, 0, 0 },
4659 display_debug_not_supported
, 0, 0 }