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_pubnames
;
51 int do_debug_frames_interp
;
56 dwarf_vma (*byte_get
) (unsigned char *, int);
59 byte_get_little_endian (unsigned char *field
, int size
)
67 return ((unsigned int) (field
[0]))
68 | (((unsigned int) (field
[1])) << 8);
71 return ((unsigned long) (field
[0]))
72 | (((unsigned long) (field
[1])) << 8)
73 | (((unsigned long) (field
[2])) << 16)
74 | (((unsigned long) (field
[3])) << 24);
77 if (sizeof (dwarf_vma
) == 8)
78 return ((dwarf_vma
) (field
[0]))
79 | (((dwarf_vma
) (field
[1])) << 8)
80 | (((dwarf_vma
) (field
[2])) << 16)
81 | (((dwarf_vma
) (field
[3])) << 24)
82 | (((dwarf_vma
) (field
[4])) << 32)
83 | (((dwarf_vma
) (field
[5])) << 40)
84 | (((dwarf_vma
) (field
[6])) << 48)
85 | (((dwarf_vma
) (field
[7])) << 56);
86 else if (sizeof (dwarf_vma
) == 4)
87 /* We want to extract data from an 8 byte wide field and
88 place it into a 4 byte wide field. Since this is a little
89 endian source we can just use the 4 byte extraction code. */
90 return ((unsigned long) (field
[0]))
91 | (((unsigned long) (field
[1])) << 8)
92 | (((unsigned long) (field
[2])) << 16)
93 | (((unsigned long) (field
[3])) << 24);
96 error (_("Unhandled data length: %d\n"), size
);
102 byte_get_big_endian (unsigned char *field
, int size
)
110 return ((unsigned int) (field
[1])) | (((int) (field
[0])) << 8);
113 return ((unsigned long) (field
[3]))
114 | (((unsigned long) (field
[2])) << 8)
115 | (((unsigned long) (field
[1])) << 16)
116 | (((unsigned long) (field
[0])) << 24);
119 if (sizeof (dwarf_vma
) == 8)
120 return ((dwarf_vma
) (field
[7]))
121 | (((dwarf_vma
) (field
[6])) << 8)
122 | (((dwarf_vma
) (field
[5])) << 16)
123 | (((dwarf_vma
) (field
[4])) << 24)
124 | (((dwarf_vma
) (field
[3])) << 32)
125 | (((dwarf_vma
) (field
[2])) << 40)
126 | (((dwarf_vma
) (field
[1])) << 48)
127 | (((dwarf_vma
) (field
[0])) << 56);
128 else if (sizeof (dwarf_vma
) == 4)
130 /* Although we are extracing data from an 8 byte wide field,
131 we are returning only 4 bytes of data. */
133 return ((unsigned long) (field
[3]))
134 | (((unsigned long) (field
[2])) << 8)
135 | (((unsigned long) (field
[1])) << 16)
136 | (((unsigned long) (field
[0])) << 24);
140 error (_("Unhandled data length: %d\n"), size
);
146 byte_get_signed (unsigned char *field
, int size
)
148 dwarf_vma x
= byte_get (field
, size
);
153 return (x
^ 0x80) - 0x80;
155 return (x
^ 0x8000) - 0x8000;
157 return (x
^ 0x80000000) - 0x80000000;
165 /* Print a dwarf_vma value (typically an address, offset or length) in
166 hexadecimal format, followed by a space. The length of the value (and
167 hence the precision displayed) is determined by the byte_size parameter. */
170 print_dwarf_vma (dwarf_vma val
, unsigned byte_size
)
172 static char buff
[18];
174 /* Printf does not have a way of specifiying a maximum field width for an
175 integer value, so we print the full value into a buffer and then select
176 the precision we need. */
177 #if __STDC_VERSION__ >= 199901L || (defined(__GNUC__) && __GNUC__ >= 2)
179 snprintf (buff
, sizeof (buff
), "%16.16llx ", val
);
181 snprintf (buff
, sizeof (buff
), "%016I64x ", val
);
184 snprintf (buff
, sizeof (buff
), "%16.16lx ", val
);
187 printf (buff
+ (byte_size
== 4 ? 8 : 0));
190 static unsigned long int
191 read_leb128 (unsigned char *data
, unsigned int *length_return
, int sign
)
193 unsigned long int result
= 0;
194 unsigned int num_read
= 0;
195 unsigned int shift
= 0;
203 result
|= ((unsigned long int) (byte
& 0x7f)) << shift
;
210 if (length_return
!= NULL
)
211 *length_return
= num_read
;
213 if (sign
&& (shift
< 8 * sizeof (result
)) && (byte
& 0x40))
214 result
|= -1L << shift
;
219 typedef struct State_Machine_Registers
221 unsigned long address
;
228 /* This variable hold the number of the last entry seen
229 in the File Table. */
230 unsigned int last_file_entry
;
233 static SMR state_machine_regs
;
236 reset_state_machine (int is_stmt
)
238 state_machine_regs
.address
= 0;
239 state_machine_regs
.file
= 1;
240 state_machine_regs
.line
= 1;
241 state_machine_regs
.column
= 0;
242 state_machine_regs
.is_stmt
= is_stmt
;
243 state_machine_regs
.basic_block
= 0;
244 state_machine_regs
.end_sequence
= 0;
245 state_machine_regs
.last_file_entry
= 0;
248 /* Handled an extend line op.
249 Returns the number of bytes read. */
252 process_extended_line_op (unsigned char *data
, int is_stmt
)
254 unsigned char op_code
;
255 unsigned int bytes_read
;
260 len
= read_leb128 (data
, & bytes_read
, 0);
265 warn (_("badly formed extended line op encountered!\n"));
272 printf (_(" Extended opcode %d: "), op_code
);
276 case DW_LNE_end_sequence
:
277 printf (_("End of Sequence\n\n"));
278 reset_state_machine (is_stmt
);
281 case DW_LNE_set_address
:
282 adr
= byte_get (data
, len
- bytes_read
- 1);
283 printf (_("set Address to 0x%lx\n"), adr
);
284 state_machine_regs
.address
= adr
;
287 case DW_LNE_define_file
:
288 printf (_(" define new File Table entry\n"));
289 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
291 printf (_(" %d\t"), ++state_machine_regs
.last_file_entry
);
293 data
+= strlen ((char *) data
) + 1;
294 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
296 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
298 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
299 printf (_("%s\n\n"), name
);
303 case DW_LNE_HP_negate_is_UV_update
:
304 printf ("DW_LNE_HP_negate_is_UV_update");
306 case DW_LNE_HP_push_context
:
307 printf ("DW_LNE_HP_push_context");
309 case DW_LNE_HP_pop_context
:
310 printf ("DW_LNE_HP_pop_context");
312 case DW_LNE_HP_set_file_line_column
:
313 printf ("DW_LNE_HP_set_file_line_column");
315 case DW_LNE_HP_set_routine_name
:
316 printf ("DW_LNE_HP_set_routine_name");
318 case DW_LNE_HP_set_sequence
:
319 printf ("DW_LNE_HP_set_sequence");
321 case DW_LNE_HP_negate_post_semantics
:
322 printf ("DW_LNE_HP_negate_post_semantics");
324 case DW_LNE_HP_negate_function_exit
:
325 printf ("DW_LNE_HP_negate_function_exit");
327 case DW_LNE_HP_negate_front_end_logical
:
328 printf ("DW_LNE_HP_negate_front_end_logical");
330 case DW_LNE_HP_define_proc
:
331 printf ("DW_LNE_HP_define_proc");
335 if (op_code
>= DW_LNE_lo_user
336 /* The test against DW_LNW_hi_user is redundant due to
337 the limited range of the unsigned char data type used
339 /*&& op_code <= DW_LNE_hi_user*/)
340 printf (_("user defined: length %d\n"), len
- bytes_read
);
342 printf (_("UNKNOWN: length %d\n"), len
- bytes_read
);
350 fetch_indirect_string (unsigned long offset
)
352 struct dwarf_section
*section
= &debug_displays
[str
].section
;
354 if (section
->start
== NULL
)
355 return _("<no .debug_str section>");
357 /* DWARF sections under Mach-O have non-zero addresses. */
358 offset
-= section
->address
;
359 if (offset
> section
->size
)
361 warn (_("DW_FORM_strp offset too big: %lx\n"), offset
);
362 return _("<offset is too big>");
365 return (const char *) section
->start
+ offset
;
368 /* FIXME: There are better and more efficient ways to handle
369 these structures. For now though, I just want something that
370 is simple to implement. */
371 typedef struct abbrev_attr
373 unsigned long attribute
;
375 struct abbrev_attr
*next
;
379 typedef struct abbrev_entry
384 struct abbrev_attr
*first_attr
;
385 struct abbrev_attr
*last_attr
;
386 struct abbrev_entry
*next
;
390 static abbrev_entry
*first_abbrev
= NULL
;
391 static abbrev_entry
*last_abbrev
= NULL
;
396 abbrev_entry
*abbrev
;
398 for (abbrev
= first_abbrev
; abbrev
;)
400 abbrev_entry
*next
= abbrev
->next
;
403 for (attr
= abbrev
->first_attr
; attr
;)
405 abbrev_attr
*next
= attr
->next
;
415 last_abbrev
= first_abbrev
= NULL
;
419 add_abbrev (unsigned long number
, unsigned long tag
, int children
)
423 entry
= malloc (sizeof (*entry
));
429 entry
->entry
= number
;
431 entry
->children
= children
;
432 entry
->first_attr
= NULL
;
433 entry
->last_attr
= NULL
;
436 if (first_abbrev
== NULL
)
437 first_abbrev
= entry
;
439 last_abbrev
->next
= entry
;
445 add_abbrev_attr (unsigned long attribute
, unsigned long form
)
449 attr
= malloc (sizeof (*attr
));
455 attr
->attribute
= attribute
;
459 if (last_abbrev
->first_attr
== NULL
)
460 last_abbrev
->first_attr
= attr
;
462 last_abbrev
->last_attr
->next
= attr
;
464 last_abbrev
->last_attr
= attr
;
467 /* Processes the (partial) contents of a .debug_abbrev section.
468 Returns NULL if the end of the section was encountered.
469 Returns the address after the last byte read if the end of
470 an abbreviation set was found. */
472 static unsigned char *
473 process_abbrev_section (unsigned char *start
, unsigned char *end
)
475 if (first_abbrev
!= NULL
)
480 unsigned int bytes_read
;
483 unsigned long attribute
;
486 entry
= read_leb128 (start
, & bytes_read
, 0);
489 /* A single zero is supposed to end the section according
490 to the standard. If there's more, then signal that to
493 return start
== end
? NULL
: start
;
495 tag
= read_leb128 (start
, & bytes_read
, 0);
500 add_abbrev (entry
, tag
, children
);
506 attribute
= read_leb128 (start
, & bytes_read
, 0);
509 form
= read_leb128 (start
, & bytes_read
, 0);
513 add_abbrev_attr (attribute
, form
);
515 while (attribute
!= 0);
522 get_TAG_name (unsigned long tag
)
526 case DW_TAG_padding
: return "DW_TAG_padding";
527 case DW_TAG_array_type
: return "DW_TAG_array_type";
528 case DW_TAG_class_type
: return "DW_TAG_class_type";
529 case DW_TAG_entry_point
: return "DW_TAG_entry_point";
530 case DW_TAG_enumeration_type
: return "DW_TAG_enumeration_type";
531 case DW_TAG_formal_parameter
: return "DW_TAG_formal_parameter";
532 case DW_TAG_imported_declaration
: return "DW_TAG_imported_declaration";
533 case DW_TAG_label
: return "DW_TAG_label";
534 case DW_TAG_lexical_block
: return "DW_TAG_lexical_block";
535 case DW_TAG_member
: return "DW_TAG_member";
536 case DW_TAG_pointer_type
: return "DW_TAG_pointer_type";
537 case DW_TAG_reference_type
: return "DW_TAG_reference_type";
538 case DW_TAG_compile_unit
: return "DW_TAG_compile_unit";
539 case DW_TAG_string_type
: return "DW_TAG_string_type";
540 case DW_TAG_structure_type
: return "DW_TAG_structure_type";
541 case DW_TAG_subroutine_type
: return "DW_TAG_subroutine_type";
542 case DW_TAG_typedef
: return "DW_TAG_typedef";
543 case DW_TAG_union_type
: return "DW_TAG_union_type";
544 case DW_TAG_unspecified_parameters
: return "DW_TAG_unspecified_parameters";
545 case DW_TAG_variant
: return "DW_TAG_variant";
546 case DW_TAG_common_block
: return "DW_TAG_common_block";
547 case DW_TAG_common_inclusion
: return "DW_TAG_common_inclusion";
548 case DW_TAG_inheritance
: return "DW_TAG_inheritance";
549 case DW_TAG_inlined_subroutine
: return "DW_TAG_inlined_subroutine";
550 case DW_TAG_module
: return "DW_TAG_module";
551 case DW_TAG_ptr_to_member_type
: return "DW_TAG_ptr_to_member_type";
552 case DW_TAG_set_type
: return "DW_TAG_set_type";
553 case DW_TAG_subrange_type
: return "DW_TAG_subrange_type";
554 case DW_TAG_with_stmt
: return "DW_TAG_with_stmt";
555 case DW_TAG_access_declaration
: return "DW_TAG_access_declaration";
556 case DW_TAG_base_type
: return "DW_TAG_base_type";
557 case DW_TAG_catch_block
: return "DW_TAG_catch_block";
558 case DW_TAG_const_type
: return "DW_TAG_const_type";
559 case DW_TAG_constant
: return "DW_TAG_constant";
560 case DW_TAG_enumerator
: return "DW_TAG_enumerator";
561 case DW_TAG_file_type
: return "DW_TAG_file_type";
562 case DW_TAG_friend
: return "DW_TAG_friend";
563 case DW_TAG_namelist
: return "DW_TAG_namelist";
564 case DW_TAG_namelist_item
: return "DW_TAG_namelist_item";
565 case DW_TAG_packed_type
: return "DW_TAG_packed_type";
566 case DW_TAG_subprogram
: return "DW_TAG_subprogram";
567 case DW_TAG_template_type_param
: return "DW_TAG_template_type_param";
568 case DW_TAG_template_value_param
: return "DW_TAG_template_value_param";
569 case DW_TAG_thrown_type
: return "DW_TAG_thrown_type";
570 case DW_TAG_try_block
: return "DW_TAG_try_block";
571 case DW_TAG_variant_part
: return "DW_TAG_variant_part";
572 case DW_TAG_variable
: return "DW_TAG_variable";
573 case DW_TAG_volatile_type
: return "DW_TAG_volatile_type";
574 case DW_TAG_MIPS_loop
: return "DW_TAG_MIPS_loop";
575 case DW_TAG_format_label
: return "DW_TAG_format_label";
576 case DW_TAG_function_template
: return "DW_TAG_function_template";
577 case DW_TAG_class_template
: return "DW_TAG_class_template";
578 /* DWARF 2.1 values. */
579 case DW_TAG_dwarf_procedure
: return "DW_TAG_dwarf_procedure";
580 case DW_TAG_restrict_type
: return "DW_TAG_restrict_type";
581 case DW_TAG_interface_type
: return "DW_TAG_interface_type";
582 case DW_TAG_namespace
: return "DW_TAG_namespace";
583 case DW_TAG_imported_module
: return "DW_TAG_imported_module";
584 case DW_TAG_unspecified_type
: return "DW_TAG_unspecified_type";
585 case DW_TAG_partial_unit
: return "DW_TAG_partial_unit";
586 case DW_TAG_imported_unit
: return "DW_TAG_imported_unit";
588 case DW_TAG_upc_shared_type
: return "DW_TAG_upc_shared_type";
589 case DW_TAG_upc_strict_type
: return "DW_TAG_upc_strict_type";
590 case DW_TAG_upc_relaxed_type
: return "DW_TAG_upc_relaxed_type";
593 static char buffer
[100];
595 snprintf (buffer
, sizeof (buffer
), _("Unknown TAG value: %lx"), tag
);
602 get_FORM_name (unsigned long form
)
606 case DW_FORM_addr
: return "DW_FORM_addr";
607 case DW_FORM_block2
: return "DW_FORM_block2";
608 case DW_FORM_block4
: return "DW_FORM_block4";
609 case DW_FORM_data2
: return "DW_FORM_data2";
610 case DW_FORM_data4
: return "DW_FORM_data4";
611 case DW_FORM_data8
: return "DW_FORM_data8";
612 case DW_FORM_string
: return "DW_FORM_string";
613 case DW_FORM_block
: return "DW_FORM_block";
614 case DW_FORM_block1
: return "DW_FORM_block1";
615 case DW_FORM_data1
: return "DW_FORM_data1";
616 case DW_FORM_flag
: return "DW_FORM_flag";
617 case DW_FORM_sdata
: return "DW_FORM_sdata";
618 case DW_FORM_strp
: return "DW_FORM_strp";
619 case DW_FORM_udata
: return "DW_FORM_udata";
620 case DW_FORM_ref_addr
: return "DW_FORM_ref_addr";
621 case DW_FORM_ref1
: return "DW_FORM_ref1";
622 case DW_FORM_ref2
: return "DW_FORM_ref2";
623 case DW_FORM_ref4
: return "DW_FORM_ref4";
624 case DW_FORM_ref8
: return "DW_FORM_ref8";
625 case DW_FORM_ref_udata
: return "DW_FORM_ref_udata";
626 case DW_FORM_indirect
: return "DW_FORM_indirect";
629 static char buffer
[100];
631 snprintf (buffer
, sizeof (buffer
), _("Unknown FORM value: %lx"), form
);
637 static unsigned char *
638 display_block (unsigned char *data
, unsigned long length
)
640 printf (_(" %lu byte block: "), length
);
643 printf ("%lx ", (unsigned long) byte_get (data
++, 1));
649 decode_location_expression (unsigned char * data
,
650 unsigned int pointer_size
,
651 unsigned long length
,
652 unsigned long cu_offset
)
655 unsigned int bytes_read
;
656 unsigned long uvalue
;
657 unsigned char *end
= data
+ length
;
658 int need_frame_base
= 0;
667 printf ("DW_OP_addr: %lx",
668 (unsigned long) byte_get (data
, pointer_size
));
669 data
+= pointer_size
;
672 printf ("DW_OP_deref");
675 printf ("DW_OP_const1u: %lu", (unsigned long) byte_get (data
++, 1));
678 printf ("DW_OP_const1s: %ld", (long) byte_get_signed (data
++, 1));
681 printf ("DW_OP_const2u: %lu", (unsigned long) byte_get (data
, 2));
685 printf ("DW_OP_const2s: %ld", (long) byte_get_signed (data
, 2));
689 printf ("DW_OP_const4u: %lu", (unsigned long) byte_get (data
, 4));
693 printf ("DW_OP_const4s: %ld", (long) byte_get_signed (data
, 4));
697 printf ("DW_OP_const8u: %lu %lu", (unsigned long) byte_get (data
, 4),
698 (unsigned long) byte_get (data
+ 4, 4));
702 printf ("DW_OP_const8s: %ld %ld", (long) byte_get (data
, 4),
703 (long) byte_get (data
+ 4, 4));
707 printf ("DW_OP_constu: %lu", read_leb128 (data
, &bytes_read
, 0));
711 printf ("DW_OP_consts: %ld", read_leb128 (data
, &bytes_read
, 1));
715 printf ("DW_OP_dup");
718 printf ("DW_OP_drop");
721 printf ("DW_OP_over");
724 printf ("DW_OP_pick: %ld", (unsigned long) byte_get (data
++, 1));
727 printf ("DW_OP_swap");
730 printf ("DW_OP_rot");
733 printf ("DW_OP_xderef");
736 printf ("DW_OP_abs");
739 printf ("DW_OP_and");
742 printf ("DW_OP_div");
745 printf ("DW_OP_minus");
748 printf ("DW_OP_mod");
751 printf ("DW_OP_mul");
754 printf ("DW_OP_neg");
757 printf ("DW_OP_not");
763 printf ("DW_OP_plus");
765 case DW_OP_plus_uconst
:
766 printf ("DW_OP_plus_uconst: %lu",
767 read_leb128 (data
, &bytes_read
, 0));
771 printf ("DW_OP_shl");
774 printf ("DW_OP_shr");
777 printf ("DW_OP_shra");
780 printf ("DW_OP_xor");
783 printf ("DW_OP_bra: %ld", (long) byte_get_signed (data
, 2));
805 printf ("DW_OP_skip: %ld", (long) byte_get_signed (data
, 2));
841 printf ("DW_OP_lit%d", op
- DW_OP_lit0
);
876 printf ("DW_OP_reg%d", op
- DW_OP_reg0
);
911 printf ("DW_OP_breg%d: %ld", op
- DW_OP_breg0
,
912 read_leb128 (data
, &bytes_read
, 1));
917 printf ("DW_OP_regx: %lu", read_leb128 (data
, &bytes_read
, 0));
922 printf ("DW_OP_fbreg: %ld", read_leb128 (data
, &bytes_read
, 1));
926 uvalue
= read_leb128 (data
, &bytes_read
, 0);
928 printf ("DW_OP_bregx: %lu %ld", uvalue
,
929 read_leb128 (data
, &bytes_read
, 1));
933 printf ("DW_OP_piece: %lu", read_leb128 (data
, &bytes_read
, 0));
936 case DW_OP_deref_size
:
937 printf ("DW_OP_deref_size: %ld", (long) byte_get (data
++, 1));
939 case DW_OP_xderef_size
:
940 printf ("DW_OP_xderef_size: %ld", (long) byte_get (data
++, 1));
943 printf ("DW_OP_nop");
946 /* DWARF 3 extensions. */
947 case DW_OP_push_object_address
:
948 printf ("DW_OP_push_object_address");
951 /* XXX: Strictly speaking for 64-bit DWARF3 files
952 this ought to be an 8-byte wide computation. */
953 printf ("DW_OP_call2: <%lx>", (long) byte_get (data
, 2) + cu_offset
);
957 /* XXX: Strictly speaking for 64-bit DWARF3 files
958 this ought to be an 8-byte wide computation. */
959 printf ("DW_OP_call4: <%lx>", (long) byte_get (data
, 4) + cu_offset
);
963 /* XXX: Strictly speaking for 64-bit DWARF3 files
964 this ought to be an 8-byte wide computation. */
965 printf ("DW_OP_call_ref: <%lx>", (long) byte_get (data
, 4) + cu_offset
);
968 case DW_OP_form_tls_address
:
969 printf ("DW_OP_form_tls_address");
971 case DW_OP_call_frame_cfa
:
972 printf ("DW_OP_call_frame_cfa");
974 case DW_OP_bit_piece
:
975 printf ("DW_OP_bit_piece: ");
976 printf ("size: %lu ", read_leb128 (data
, &bytes_read
, 0));
978 printf ("offset: %lu ", read_leb128 (data
, &bytes_read
, 0));
982 /* GNU extensions. */
983 case DW_OP_GNU_push_tls_address
:
984 printf ("DW_OP_GNU_push_tls_address or DW_OP_HP_unknown");
986 case DW_OP_GNU_uninit
:
987 printf ("DW_OP_GNU_uninit");
988 /* FIXME: Is there data associated with this OP ? */
992 case DW_OP_HP_is_value
:
993 printf ("DW_OP_HP_is_value");
994 /* FIXME: Is there data associated with this OP ? */
996 case DW_OP_HP_fltconst4
:
997 printf ("DW_OP_HP_fltconst4");
998 /* FIXME: Is there data associated with this OP ? */
1000 case DW_OP_HP_fltconst8
:
1001 printf ("DW_OP_HP_fltconst8");
1002 /* FIXME: Is there data associated with this OP ? */
1004 case DW_OP_HP_mod_range
:
1005 printf ("DW_OP_HP_mod_range");
1006 /* FIXME: Is there data associated with this OP ? */
1008 case DW_OP_HP_unmod_range
:
1009 printf ("DW_OP_HP_unmod_range");
1010 /* FIXME: Is there data associated with this OP ? */
1013 printf ("DW_OP_HP_tls");
1014 /* FIXME: Is there data associated with this OP ? */
1018 if (op
>= DW_OP_lo_user
1019 && op
<= DW_OP_hi_user
)
1020 printf (_("(User defined location op)"));
1022 printf (_("(Unknown location op)"));
1023 /* No way to tell where the next op is, so just bail. */
1024 return need_frame_base
;
1027 /* Separate the ops. */
1032 return need_frame_base
;
1035 static unsigned char *
1036 read_and_display_attr_value (unsigned long attribute
,
1038 unsigned char * data
,
1039 unsigned long cu_offset
,
1040 unsigned long pointer_size
,
1041 unsigned long offset_size
,
1043 debug_info
* debug_info_p
,
1045 struct dwarf_section
* section
)
1047 unsigned long uvalue
= 0;
1048 unsigned char *block_start
= NULL
;
1049 unsigned char * orig_data
= data
;
1050 unsigned int bytes_read
;
1057 case DW_FORM_ref_addr
:
1058 if (dwarf_version
== 2)
1060 uvalue
= byte_get (data
, pointer_size
);
1061 data
+= pointer_size
;
1063 else if (dwarf_version
== 3)
1065 uvalue
= byte_get (data
, offset_size
);
1066 data
+= offset_size
;
1070 error (_("Internal error: DWARF version is not 2 or 3.\n"));
1075 uvalue
= byte_get (data
, pointer_size
);
1076 data
+= pointer_size
;
1080 uvalue
= byte_get (data
, offset_size
);
1081 data
+= offset_size
;
1087 uvalue
= byte_get (data
++, 1);
1092 uvalue
= byte_get (data
, 2);
1098 uvalue
= byte_get (data
, 4);
1103 uvalue
= read_leb128 (data
, & bytes_read
, 1);
1107 case DW_FORM_ref_udata
:
1109 uvalue
= read_leb128 (data
, & bytes_read
, 0);
1113 case DW_FORM_indirect
:
1114 form
= read_leb128 (data
, & bytes_read
, 0);
1117 printf (" %s", get_FORM_name (form
));
1118 return read_and_display_attr_value (attribute
, form
, data
,
1119 cu_offset
, pointer_size
,
1120 offset_size
, dwarf_version
,
1121 debug_info_p
, do_loc
,
1127 case DW_FORM_ref_addr
:
1129 printf (" <0x%lx>", uvalue
);
1135 case DW_FORM_ref_udata
:
1137 printf (" <0x%lx>", uvalue
+ cu_offset
);
1143 printf (" 0x%lx", uvalue
);
1152 printf (" %ld", uvalue
);
1159 uvalue
= byte_get (data
, 4);
1160 printf (" 0x%lx", uvalue
);
1161 printf (" 0x%lx", (unsigned long) byte_get (data
+ 4, 4));
1163 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
1164 && num_debug_info_entries
== 0)
1166 if (sizeof (uvalue
) == 8)
1167 uvalue
= byte_get (data
, 8);
1169 error (_("DW_FORM_data8 is unsupported when sizeof (unsigned long) != 8\n"));
1174 case DW_FORM_string
:
1176 printf (" %s", data
);
1177 data
+= strlen ((char *) data
) + 1;
1181 uvalue
= read_leb128 (data
, & bytes_read
, 0);
1182 block_start
= data
+ bytes_read
;
1184 data
= block_start
+ uvalue
;
1186 data
= display_block (block_start
, uvalue
);
1189 case DW_FORM_block1
:
1190 uvalue
= byte_get (data
, 1);
1191 block_start
= data
+ 1;
1193 data
= block_start
+ uvalue
;
1195 data
= display_block (block_start
, uvalue
);
1198 case DW_FORM_block2
:
1199 uvalue
= byte_get (data
, 2);
1200 block_start
= data
+ 2;
1202 data
= block_start
+ uvalue
;
1204 data
= display_block (block_start
, uvalue
);
1207 case DW_FORM_block4
:
1208 uvalue
= byte_get (data
, 4);
1209 block_start
= data
+ 4;
1211 data
= block_start
+ uvalue
;
1213 data
= display_block (block_start
, uvalue
);
1218 printf (_(" (indirect string, offset: 0x%lx): %s"),
1219 uvalue
, fetch_indirect_string (uvalue
));
1222 case DW_FORM_indirect
:
1223 /* Handled above. */
1227 warn (_("Unrecognized form: %lu\n"), form
);
1231 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
1232 && num_debug_info_entries
== 0)
1236 case DW_AT_frame_base
:
1237 have_frame_base
= 1;
1238 case DW_AT_location
:
1239 case DW_AT_string_length
:
1240 case DW_AT_return_addr
:
1241 case DW_AT_data_member_location
:
1242 case DW_AT_vtable_elem_location
:
1244 case DW_AT_static_link
:
1245 case DW_AT_use_location
:
1246 if (form
== DW_FORM_data4
|| form
== DW_FORM_data8
)
1248 /* Process location list. */
1249 unsigned int max
= debug_info_p
->max_loc_offsets
;
1250 unsigned int num
= debug_info_p
->num_loc_offsets
;
1252 if (max
== 0 || num
>= max
)
1255 debug_info_p
->loc_offsets
1256 = xcrealloc (debug_info_p
->loc_offsets
,
1257 max
, sizeof (*debug_info_p
->loc_offsets
));
1258 debug_info_p
->have_frame_base
1259 = xcrealloc (debug_info_p
->have_frame_base
,
1260 max
, sizeof (*debug_info_p
->have_frame_base
));
1261 debug_info_p
->max_loc_offsets
= max
;
1263 debug_info_p
->loc_offsets
[num
] = uvalue
;
1264 debug_info_p
->have_frame_base
[num
] = have_frame_base
;
1265 debug_info_p
->num_loc_offsets
++;
1270 if (need_base_address
)
1271 debug_info_p
->base_address
= uvalue
;
1275 if (form
== DW_FORM_data4
|| form
== DW_FORM_data8
)
1277 /* Process range list. */
1278 unsigned int max
= debug_info_p
->max_range_lists
;
1279 unsigned int num
= debug_info_p
->num_range_lists
;
1281 if (max
== 0 || num
>= max
)
1284 debug_info_p
->range_lists
1285 = xcrealloc (debug_info_p
->range_lists
,
1286 max
, sizeof (*debug_info_p
->range_lists
));
1287 debug_info_p
->max_range_lists
= max
;
1289 debug_info_p
->range_lists
[num
] = uvalue
;
1290 debug_info_p
->num_range_lists
++;
1302 /* For some attributes we can display further information. */
1310 case DW_INL_not_inlined
:
1311 printf (_("(not inlined)"));
1313 case DW_INL_inlined
:
1314 printf (_("(inlined)"));
1316 case DW_INL_declared_not_inlined
:
1317 printf (_("(declared as inline but ignored)"));
1319 case DW_INL_declared_inlined
:
1320 printf (_("(declared as inline and inlined)"));
1323 printf (_(" (Unknown inline attribute value: %lx)"), uvalue
);
1328 case DW_AT_language
:
1331 /* Ordered by the numeric value of these constants. */
1332 case DW_LANG_C89
: printf ("(ANSI C)"); break;
1333 case DW_LANG_C
: printf ("(non-ANSI C)"); break;
1334 case DW_LANG_Ada83
: printf ("(Ada)"); break;
1335 case DW_LANG_C_plus_plus
: printf ("(C++)"); break;
1336 case DW_LANG_Cobol74
: printf ("(Cobol 74)"); break;
1337 case DW_LANG_Cobol85
: printf ("(Cobol 85)"); break;
1338 case DW_LANG_Fortran77
: printf ("(FORTRAN 77)"); break;
1339 case DW_LANG_Fortran90
: printf ("(Fortran 90)"); break;
1340 case DW_LANG_Pascal83
: printf ("(ANSI Pascal)"); break;
1341 case DW_LANG_Modula2
: printf ("(Modula 2)"); break;
1342 /* DWARF 2.1 values. */
1343 case DW_LANG_Java
: printf ("(Java)"); break;
1344 case DW_LANG_C99
: printf ("(ANSI C99)"); break;
1345 case DW_LANG_Ada95
: printf ("(ADA 95)"); break;
1346 case DW_LANG_Fortran95
: printf ("(Fortran 95)"); break;
1347 /* DWARF 3 values. */
1348 case DW_LANG_PLI
: printf ("(PLI)"); break;
1349 case DW_LANG_ObjC
: printf ("(Objective C)"); break;
1350 case DW_LANG_ObjC_plus_plus
: printf ("(Objective C++)"); break;
1351 case DW_LANG_UPC
: printf ("(Unified Parallel C)"); break;
1352 case DW_LANG_D
: printf ("(D)"); break;
1353 /* MIPS extension. */
1354 case DW_LANG_Mips_Assembler
: printf ("(MIPS assembler)"); break;
1355 /* UPC extension. */
1356 case DW_LANG_Upc
: printf ("(Unified Parallel C)"); break;
1358 if (uvalue
>= DW_LANG_lo_user
&& uvalue
<= DW_LANG_hi_user
)
1359 printf ("(implementation defined: %lx)", uvalue
);
1361 printf ("(Unknown: %lx)", uvalue
);
1366 case DW_AT_encoding
:
1369 case DW_ATE_void
: printf ("(void)"); break;
1370 case DW_ATE_address
: printf ("(machine address)"); break;
1371 case DW_ATE_boolean
: printf ("(boolean)"); break;
1372 case DW_ATE_complex_float
: printf ("(complex float)"); break;
1373 case DW_ATE_float
: printf ("(float)"); break;
1374 case DW_ATE_signed
: printf ("(signed)"); break;
1375 case DW_ATE_signed_char
: printf ("(signed char)"); break;
1376 case DW_ATE_unsigned
: printf ("(unsigned)"); break;
1377 case DW_ATE_unsigned_char
: printf ("(unsigned char)"); break;
1378 /* DWARF 2.1 values: */
1379 case DW_ATE_imaginary_float
: printf ("(imaginary float)"); break;
1380 case DW_ATE_decimal_float
: printf ("(decimal float)"); break;
1381 /* DWARF 3 values: */
1382 case DW_ATE_packed_decimal
: printf ("(packed_decimal)"); break;
1383 case DW_ATE_numeric_string
: printf ("(numeric_string)"); break;
1384 case DW_ATE_edited
: printf ("(edited)"); break;
1385 case DW_ATE_signed_fixed
: printf ("(signed_fixed)"); break;
1386 case DW_ATE_unsigned_fixed
: printf ("(unsigned_fixed)"); break;
1387 /* HP extensions: */
1388 case DW_ATE_HP_float80
: printf ("(HP_float80)"); break;
1389 case DW_ATE_HP_complex_float80
: printf ("(HP_complex_float80)"); break;
1390 case DW_ATE_HP_float128
: printf ("(HP_float128)"); break;
1391 case DW_ATE_HP_complex_float128
:printf ("(HP_complex_float128)"); break;
1392 case DW_ATE_HP_floathpintel
: printf ("(HP_floathpintel)"); break;
1393 case DW_ATE_HP_imaginary_float80
: printf ("(HP_imaginary_float80)"); break;
1394 case DW_ATE_HP_imaginary_float128
: printf ("(HP_imaginary_float128)"); break;
1397 if (uvalue
>= DW_ATE_lo_user
1398 && uvalue
<= DW_ATE_hi_user
)
1399 printf ("(user defined type)");
1401 printf ("(unknown type)");
1406 case DW_AT_accessibility
:
1409 case DW_ACCESS_public
: printf ("(public)"); break;
1410 case DW_ACCESS_protected
: printf ("(protected)"); break;
1411 case DW_ACCESS_private
: printf ("(private)"); break;
1413 printf ("(unknown accessibility)");
1418 case DW_AT_visibility
:
1421 case DW_VIS_local
: printf ("(local)"); break;
1422 case DW_VIS_exported
: printf ("(exported)"); break;
1423 case DW_VIS_qualified
: printf ("(qualified)"); break;
1424 default: printf ("(unknown visibility)"); break;
1428 case DW_AT_virtuality
:
1431 case DW_VIRTUALITY_none
: printf ("(none)"); break;
1432 case DW_VIRTUALITY_virtual
: printf ("(virtual)"); break;
1433 case DW_VIRTUALITY_pure_virtual
:printf ("(pure_virtual)"); break;
1434 default: printf ("(unknown virtuality)"); break;
1438 case DW_AT_identifier_case
:
1441 case DW_ID_case_sensitive
: printf ("(case_sensitive)"); break;
1442 case DW_ID_up_case
: printf ("(up_case)"); break;
1443 case DW_ID_down_case
: printf ("(down_case)"); break;
1444 case DW_ID_case_insensitive
: printf ("(case_insensitive)"); break;
1445 default: printf ("(unknown case)"); break;
1449 case DW_AT_calling_convention
:
1452 case DW_CC_normal
: printf ("(normal)"); break;
1453 case DW_CC_program
: printf ("(program)"); break;
1454 case DW_CC_nocall
: printf ("(nocall)"); break;
1456 if (uvalue
>= DW_CC_lo_user
1457 && uvalue
<= DW_CC_hi_user
)
1458 printf ("(user defined)");
1460 printf ("(unknown convention)");
1464 case DW_AT_ordering
:
1467 case -1: printf ("(undefined)"); break;
1468 case 0: printf ("(row major)"); break;
1469 case 1: printf ("(column major)"); break;
1473 case DW_AT_frame_base
:
1474 have_frame_base
= 1;
1475 case DW_AT_location
:
1476 case DW_AT_string_length
:
1477 case DW_AT_return_addr
:
1478 case DW_AT_data_member_location
:
1479 case DW_AT_vtable_elem_location
:
1481 case DW_AT_static_link
:
1482 case DW_AT_use_location
:
1483 if (form
== DW_FORM_data4
|| form
== DW_FORM_data8
)
1484 printf (_("(location list)"));
1486 case DW_AT_allocated
:
1487 case DW_AT_associated
:
1488 case DW_AT_data_location
:
1490 case DW_AT_upper_bound
:
1491 case DW_AT_lower_bound
:
1494 int need_frame_base
;
1497 need_frame_base
= decode_location_expression (block_start
,
1502 if (need_frame_base
&& !have_frame_base
)
1503 printf (_(" [without DW_AT_frame_base]"));
1509 if (form
== DW_FORM_ref1
1510 || form
== DW_FORM_ref2
1511 || form
== DW_FORM_ref4
)
1512 uvalue
+= cu_offset
;
1514 if (uvalue
>= section
->size
)
1515 warn (_("Offset %lx used as value for DW_AT_import attribute of DIE at offset %lx is too big.\n"),
1516 uvalue
, (long int)(orig_data
- section
->start
));
1519 unsigned long abbrev_number
;
1520 abbrev_entry
* entry
;
1522 abbrev_number
= read_leb128 (section
->start
+ uvalue
, NULL
, 0);
1524 printf ("[Abbrev Number: %ld", abbrev_number
);
1525 for (entry
= first_abbrev
; entry
!= NULL
; entry
= entry
->next
)
1526 if (entry
->entry
== abbrev_number
)
1529 printf (" (%s)", get_TAG_name (entry
->tag
));
1543 get_AT_name (unsigned long attribute
)
1547 case DW_AT_sibling
: return "DW_AT_sibling";
1548 case DW_AT_location
: return "DW_AT_location";
1549 case DW_AT_name
: return "DW_AT_name";
1550 case DW_AT_ordering
: return "DW_AT_ordering";
1551 case DW_AT_subscr_data
: return "DW_AT_subscr_data";
1552 case DW_AT_byte_size
: return "DW_AT_byte_size";
1553 case DW_AT_bit_offset
: return "DW_AT_bit_offset";
1554 case DW_AT_bit_size
: return "DW_AT_bit_size";
1555 case DW_AT_element_list
: return "DW_AT_element_list";
1556 case DW_AT_stmt_list
: return "DW_AT_stmt_list";
1557 case DW_AT_low_pc
: return "DW_AT_low_pc";
1558 case DW_AT_high_pc
: return "DW_AT_high_pc";
1559 case DW_AT_language
: return "DW_AT_language";
1560 case DW_AT_member
: return "DW_AT_member";
1561 case DW_AT_discr
: return "DW_AT_discr";
1562 case DW_AT_discr_value
: return "DW_AT_discr_value";
1563 case DW_AT_visibility
: return "DW_AT_visibility";
1564 case DW_AT_import
: return "DW_AT_import";
1565 case DW_AT_string_length
: return "DW_AT_string_length";
1566 case DW_AT_common_reference
: return "DW_AT_common_reference";
1567 case DW_AT_comp_dir
: return "DW_AT_comp_dir";
1568 case DW_AT_const_value
: return "DW_AT_const_value";
1569 case DW_AT_containing_type
: return "DW_AT_containing_type";
1570 case DW_AT_default_value
: return "DW_AT_default_value";
1571 case DW_AT_inline
: return "DW_AT_inline";
1572 case DW_AT_is_optional
: return "DW_AT_is_optional";
1573 case DW_AT_lower_bound
: return "DW_AT_lower_bound";
1574 case DW_AT_producer
: return "DW_AT_producer";
1575 case DW_AT_prototyped
: return "DW_AT_prototyped";
1576 case DW_AT_return_addr
: return "DW_AT_return_addr";
1577 case DW_AT_start_scope
: return "DW_AT_start_scope";
1578 case DW_AT_stride_size
: return "DW_AT_stride_size";
1579 case DW_AT_upper_bound
: return "DW_AT_upper_bound";
1580 case DW_AT_abstract_origin
: return "DW_AT_abstract_origin";
1581 case DW_AT_accessibility
: return "DW_AT_accessibility";
1582 case DW_AT_address_class
: return "DW_AT_address_class";
1583 case DW_AT_artificial
: return "DW_AT_artificial";
1584 case DW_AT_base_types
: return "DW_AT_base_types";
1585 case DW_AT_calling_convention
: return "DW_AT_calling_convention";
1586 case DW_AT_count
: return "DW_AT_count";
1587 case DW_AT_data_member_location
: return "DW_AT_data_member_location";
1588 case DW_AT_decl_column
: return "DW_AT_decl_column";
1589 case DW_AT_decl_file
: return "DW_AT_decl_file";
1590 case DW_AT_decl_line
: return "DW_AT_decl_line";
1591 case DW_AT_declaration
: return "DW_AT_declaration";
1592 case DW_AT_discr_list
: return "DW_AT_discr_list";
1593 case DW_AT_encoding
: return "DW_AT_encoding";
1594 case DW_AT_external
: return "DW_AT_external";
1595 case DW_AT_frame_base
: return "DW_AT_frame_base";
1596 case DW_AT_friend
: return "DW_AT_friend";
1597 case DW_AT_identifier_case
: return "DW_AT_identifier_case";
1598 case DW_AT_macro_info
: return "DW_AT_macro_info";
1599 case DW_AT_namelist_items
: return "DW_AT_namelist_items";
1600 case DW_AT_priority
: return "DW_AT_priority";
1601 case DW_AT_segment
: return "DW_AT_segment";
1602 case DW_AT_specification
: return "DW_AT_specification";
1603 case DW_AT_static_link
: return "DW_AT_static_link";
1604 case DW_AT_type
: return "DW_AT_type";
1605 case DW_AT_use_location
: return "DW_AT_use_location";
1606 case DW_AT_variable_parameter
: return "DW_AT_variable_parameter";
1607 case DW_AT_virtuality
: return "DW_AT_virtuality";
1608 case DW_AT_vtable_elem_location
: return "DW_AT_vtable_elem_location";
1609 /* DWARF 2.1 values. */
1610 case DW_AT_allocated
: return "DW_AT_allocated";
1611 case DW_AT_associated
: return "DW_AT_associated";
1612 case DW_AT_data_location
: return "DW_AT_data_location";
1613 case DW_AT_stride
: return "DW_AT_stride";
1614 case DW_AT_entry_pc
: return "DW_AT_entry_pc";
1615 case DW_AT_use_UTF8
: return "DW_AT_use_UTF8";
1616 case DW_AT_extension
: return "DW_AT_extension";
1617 case DW_AT_ranges
: return "DW_AT_ranges";
1618 case DW_AT_trampoline
: return "DW_AT_trampoline";
1619 case DW_AT_call_column
: return "DW_AT_call_column";
1620 case DW_AT_call_file
: return "DW_AT_call_file";
1621 case DW_AT_call_line
: return "DW_AT_call_line";
1622 case DW_AT_description
: return "DW_AT_description";
1623 case DW_AT_binary_scale
: return "DW_AT_binary_scale";
1624 case DW_AT_decimal_scale
: return "DW_AT_decimal_scale";
1625 case DW_AT_small
: return "DW_AT_small";
1626 case DW_AT_decimal_sign
: return "DW_AT_decimal_sign";
1627 case DW_AT_digit_count
: return "DW_AT_digit_count";
1628 case DW_AT_picture_string
: return "DW_AT_picture_string";
1629 case DW_AT_mutable
: return "DW_AT_mutable";
1630 case DW_AT_threads_scaled
: return "DW_AT_threads_scaled";
1631 case DW_AT_explicit
: return "DW_AT_explicit";
1632 case DW_AT_object_pointer
: return "DW_AT_object_pointer";
1633 case DW_AT_endianity
: return "DW_AT_endianity";
1634 case DW_AT_elemental
: return "DW_AT_elemental";
1635 case DW_AT_pure
: return "DW_AT_pure";
1636 case DW_AT_recursive
: return "DW_AT_recursive";
1638 /* HP and SGI/MIPS extensions. */
1639 case DW_AT_MIPS_loop_begin
: return "DW_AT_MIPS_loop_begin";
1640 case DW_AT_MIPS_tail_loop_begin
: return "DW_AT_MIPS_tail_loop_begin";
1641 case DW_AT_MIPS_epilog_begin
: return "DW_AT_MIPS_epilog_begin";
1642 case DW_AT_MIPS_loop_unroll_factor
: return "DW_AT_MIPS_loop_unroll_factor";
1643 case DW_AT_MIPS_software_pipeline_depth
: return "DW_AT_MIPS_software_pipeline_depth";
1644 case DW_AT_MIPS_linkage_name
: return "DW_AT_MIPS_linkage_name";
1645 case DW_AT_MIPS_stride
: return "DW_AT_MIPS_stride";
1646 case DW_AT_MIPS_abstract_name
: return "DW_AT_MIPS_abstract_name";
1647 case DW_AT_MIPS_clone_origin
: return "DW_AT_MIPS_clone_origin";
1648 case DW_AT_MIPS_has_inlines
: return "DW_AT_MIPS_has_inlines";
1650 /* HP Extensions. */
1651 case DW_AT_HP_block_index
: return "DW_AT_HP_block_index";
1652 case DW_AT_HP_actuals_stmt_list
: return "DW_AT_HP_actuals_stmt_list";
1653 case DW_AT_HP_proc_per_section
: return "DW_AT_HP_proc_per_section";
1654 case DW_AT_HP_raw_data_ptr
: return "DW_AT_HP_raw_data_ptr";
1655 case DW_AT_HP_pass_by_reference
: return "DW_AT_HP_pass_by_reference";
1656 case DW_AT_HP_opt_level
: return "DW_AT_HP_opt_level";
1657 case DW_AT_HP_prof_version_id
: return "DW_AT_HP_prof_version_id";
1658 case DW_AT_HP_opt_flags
: return "DW_AT_HP_opt_flags";
1659 case DW_AT_HP_cold_region_low_pc
: return "DW_AT_HP_cold_region_low_pc";
1660 case DW_AT_HP_cold_region_high_pc
: return "DW_AT_HP_cold_region_high_pc";
1661 case DW_AT_HP_all_variables_modifiable
: return "DW_AT_HP_all_variables_modifiable";
1662 case DW_AT_HP_linkage_name
: return "DW_AT_HP_linkage_name";
1663 case DW_AT_HP_prof_flags
: return "DW_AT_HP_prof_flags";
1665 /* One value is shared by the MIPS and HP extensions: */
1666 case DW_AT_MIPS_fde
: return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable";
1668 /* GNU extensions. */
1669 case DW_AT_sf_names
: return "DW_AT_sf_names";
1670 case DW_AT_src_info
: return "DW_AT_src_info";
1671 case DW_AT_mac_info
: return "DW_AT_mac_info";
1672 case DW_AT_src_coords
: return "DW_AT_src_coords";
1673 case DW_AT_body_begin
: return "DW_AT_body_begin";
1674 case DW_AT_body_end
: return "DW_AT_body_end";
1675 case DW_AT_GNU_vector
: return "DW_AT_GNU_vector";
1677 /* UPC extension. */
1678 case DW_AT_upc_threads_scaled
: return "DW_AT_upc_threads_scaled";
1680 /* PGI (STMicroelectronics) extensions. */
1681 case DW_AT_PGI_lbase
: return "DW_AT_PGI_lbase";
1682 case DW_AT_PGI_soffset
: return "DW_AT_PGI_soffset";
1683 case DW_AT_PGI_lstride
: return "DW_AT_PGI_lstride";
1687 static char buffer
[100];
1689 snprintf (buffer
, sizeof (buffer
), _("Unknown AT value: %lx"),
1696 static unsigned char *
1697 read_and_display_attr (unsigned long attribute
,
1699 unsigned char * data
,
1700 unsigned long cu_offset
,
1701 unsigned long pointer_size
,
1702 unsigned long offset_size
,
1704 debug_info
* debug_info_p
,
1706 struct dwarf_section
* section
)
1709 printf (" %-18s:", get_AT_name (attribute
));
1710 data
= read_and_display_attr_value (attribute
, form
, data
, cu_offset
,
1711 pointer_size
, offset_size
,
1712 dwarf_version
, debug_info_p
,
1720 /* Process the contents of a .debug_info section. If do_loc is non-zero
1721 then we are scanning for location lists and we do not want to display
1722 anything to the user. */
1725 process_debug_info (struct dwarf_section
*section
,
1729 unsigned char *start
= section
->start
;
1730 unsigned char *end
= start
+ section
->size
;
1731 unsigned char *section_begin
;
1733 unsigned int num_units
= 0;
1735 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
1736 && num_debug_info_entries
== 0)
1738 unsigned long length
;
1740 /* First scan the section to get the number of comp units. */
1741 for (section_begin
= start
, num_units
= 0; section_begin
< end
;
1744 /* Read the first 4 bytes. For a 32-bit DWARF section, this
1745 will be the length. For a 64-bit DWARF section, it'll be
1746 the escape code 0xffffffff followed by an 8 byte length. */
1747 length
= byte_get (section_begin
, 4);
1749 if (length
== 0xffffffff)
1751 length
= byte_get (section_begin
+ 4, 8);
1752 section_begin
+= length
+ 12;
1754 else if (length
>= 0xfffffff0 && length
< 0xffffffff)
1756 warn (_("Reserved length value (%lx) found in section %s\n"), length
, section
->name
);
1760 section_begin
+= length
+ 4;
1762 /* Negative values are illegal, they may even cause infinite
1763 looping. This can happen if we can't accurately apply
1764 relocations to an object file. */
1765 if ((signed long) length
<= 0)
1767 warn (_("Corrupt unit length (%lx) found in section %s\n"), length
, section
->name
);
1774 error (_("No comp units in %s section ?"), section
->name
);
1778 /* Then allocate an array to hold the information. */
1779 debug_information
= cmalloc (num_units
,
1780 sizeof (* debug_information
));
1781 if (debug_information
== NULL
)
1783 error (_("Not enough memory for a debug info array of %u entries"),
1791 printf (_("The section %s contains:\n\n"), section
->name
);
1793 load_debug_section (str
, file
);
1796 load_debug_section (abbrev
, file
);
1797 if (debug_displays
[abbrev
].section
.start
== NULL
)
1799 warn (_("Unable to locate %s section!\n"),
1800 debug_displays
[abbrev
].section
.name
);
1804 for (section_begin
= start
, unit
= 0; start
< end
; unit
++)
1806 DWARF2_Internal_CompUnit compunit
;
1807 unsigned char *hdrptr
;
1808 unsigned char *cu_abbrev_offset_ptr
;
1809 unsigned char *tags
;
1811 unsigned long cu_offset
;
1813 int initial_length_size
;
1817 compunit
.cu_length
= byte_get (hdrptr
, 4);
1820 if (compunit
.cu_length
== 0xffffffff)
1822 compunit
.cu_length
= byte_get (hdrptr
, 8);
1825 initial_length_size
= 12;
1830 initial_length_size
= 4;
1833 compunit
.cu_version
= byte_get (hdrptr
, 2);
1836 cu_offset
= start
- section_begin
;
1838 cu_abbrev_offset_ptr
= hdrptr
;
1839 compunit
.cu_abbrev_offset
= byte_get (hdrptr
, offset_size
);
1840 hdrptr
+= offset_size
;
1842 compunit
.cu_pointer_size
= byte_get (hdrptr
, 1);
1844 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
1845 && num_debug_info_entries
== 0)
1847 debug_information
[unit
].cu_offset
= cu_offset
;
1848 debug_information
[unit
].pointer_size
1849 = compunit
.cu_pointer_size
;
1850 debug_information
[unit
].base_address
= 0;
1851 debug_information
[unit
].loc_offsets
= NULL
;
1852 debug_information
[unit
].have_frame_base
= NULL
;
1853 debug_information
[unit
].max_loc_offsets
= 0;
1854 debug_information
[unit
].num_loc_offsets
= 0;
1855 debug_information
[unit
].range_lists
= NULL
;
1856 debug_information
[unit
].max_range_lists
= 0;
1857 debug_information
[unit
].num_range_lists
= 0;
1862 printf (_(" Compilation Unit @ offset 0x%lx:\n"), cu_offset
);
1863 printf (_(" Length: 0x%lx (%s)\n"), compunit
.cu_length
,
1864 initial_length_size
== 8 ? "64-bit" : "32-bit");
1865 printf (_(" Version: %d\n"), compunit
.cu_version
);
1866 printf (_(" Abbrev Offset: %ld\n"), compunit
.cu_abbrev_offset
);
1867 printf (_(" Pointer Size: %d\n"), compunit
.cu_pointer_size
);
1870 if (cu_offset
+ compunit
.cu_length
+ initial_length_size
1873 warn (_("Debug info is corrupted, length of CU at %lx extends beyond end of section (length = %lx)\n"),
1874 cu_offset
, compunit
.cu_length
);
1878 start
+= compunit
.cu_length
+ initial_length_size
;
1880 if (compunit
.cu_version
!= 2 && compunit
.cu_version
!= 3)
1882 warn (_("CU at offset %lx contains corrupt or unsupported version number: %d.\n"),
1883 cu_offset
, compunit
.cu_version
);
1889 /* Process the abbrevs used by this compilation unit. DWARF
1890 sections under Mach-O have non-zero addresses. */
1891 if (compunit
.cu_abbrev_offset
>= debug_displays
[abbrev
].section
.size
)
1892 warn (_("Debug info is corrupted, abbrev offset (%lx) is larger than abbrev section size (%lx)\n"),
1893 (unsigned long) compunit
.cu_abbrev_offset
,
1894 (unsigned long) debug_displays
[abbrev
].section
.size
);
1896 process_abbrev_section
1897 ((unsigned char *) debug_displays
[abbrev
].section
.start
1898 + compunit
.cu_abbrev_offset
- debug_displays
[abbrev
].section
.address
,
1899 (unsigned char *) debug_displays
[abbrev
].section
.start
1900 + debug_displays
[abbrev
].section
.size
);
1903 while (tags
< start
)
1905 unsigned int bytes_read
;
1906 unsigned long abbrev_number
;
1907 unsigned long die_offset
;
1908 abbrev_entry
*entry
;
1911 die_offset
= tags
- section_begin
;
1913 abbrev_number
= read_leb128 (tags
, & bytes_read
, 0);
1916 /* A null DIE marks the end of a list of siblings. */
1917 if (abbrev_number
== 0)
1922 static unsigned num_bogus_warns
= 0;
1924 if (num_bogus_warns
< 3)
1926 warn (_("Bogus end-of-siblings marker detected at offset %lx in .debug_info section\n"),
1929 if (num_bogus_warns
== 3)
1930 warn (_("Further warnings about bogus end-of-sibling markers suppressed\n"));
1937 printf (_(" <%d><%lx>: Abbrev Number: %lu"),
1938 level
, die_offset
, abbrev_number
);
1940 /* Scan through the abbreviation list until we reach the
1942 for (entry
= first_abbrev
;
1943 entry
&& entry
->entry
!= abbrev_number
;
1944 entry
= entry
->next
)
1954 warn (_("DIE at offset %lx refers to abbreviation number %lu which does not exist\n"),
1955 die_offset
, abbrev_number
);
1960 printf (_(" (%s)\n"), get_TAG_name (entry
->tag
));
1965 need_base_address
= 0;
1967 case DW_TAG_compile_unit
:
1968 need_base_address
= 1;
1970 case DW_TAG_entry_point
:
1971 case DW_TAG_subprogram
:
1972 need_base_address
= 0;
1973 /* Assuming that there is no DW_AT_frame_base. */
1974 have_frame_base
= 0;
1978 for (attr
= entry
->first_attr
; attr
; attr
= attr
->next
)
1981 /* Show the offset from where the tag was extracted. */
1982 printf (" <%2lx>", (unsigned long)(tags
- section_begin
));
1984 tags
= read_and_display_attr (attr
->attribute
,
1987 compunit
.cu_pointer_size
,
1989 compunit
.cu_version
,
1990 debug_information
+ unit
,
1994 if (entry
->children
)
1999 /* Set num_debug_info_entries here so that it can be used to check if
2000 we need to process .debug_loc and .debug_ranges sections. */
2001 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
2002 && num_debug_info_entries
== 0)
2003 num_debug_info_entries
= num_units
;
2013 /* Locate and scan the .debug_info section in the file and record the pointer
2014 sizes and offsets for the compilation units in it. Usually an executable
2015 will have just one pointer size, but this is not guaranteed, and so we try
2016 not to make any assumptions. Returns zero upon failure, or the number of
2017 compilation units upon success. */
2020 load_debug_info (void * file
)
2022 /* Reset the last pointer size so that we can issue correct error
2023 messages if we are displaying the contents of more than one section. */
2024 last_pointer_size
= 0;
2025 warned_about_missing_comp_units
= FALSE
;
2027 /* If we have already tried and failed to load the .debug_info
2028 section then do not bother to repear the task. */
2029 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
2032 /* If we already have the information there is nothing else to do. */
2033 if (num_debug_info_entries
> 0)
2034 return num_debug_info_entries
;
2036 if (load_debug_section (info
, file
)
2037 && process_debug_info (&debug_displays
[info
].section
, file
, 1))
2038 return num_debug_info_entries
;
2040 num_debug_info_entries
= DEBUG_INFO_UNAVAILABLE
;
2045 display_debug_lines (struct dwarf_section
*section
, void *file
)
2047 unsigned char *start
= section
->start
;
2048 unsigned char *data
= start
;
2049 unsigned char *end
= start
+ section
->size
;
2051 printf (_("\nDump of debug contents of section %s:\n\n"),
2054 if (load_debug_info (file
) == 0)
2056 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
2063 DWARF2_Internal_LineInfo info
;
2064 unsigned char *standard_opcodes
;
2065 unsigned char *end_of_sequence
;
2066 unsigned char *hdrptr
;
2067 unsigned long hdroff
;
2068 int initial_length_size
;
2073 hdroff
= hdrptr
- start
;
2075 /* Check the length of the block. */
2076 info
.li_length
= byte_get (hdrptr
, 4);
2079 if (info
.li_length
== 0xffffffff)
2081 /* This section is 64-bit DWARF 3. */
2082 info
.li_length
= byte_get (hdrptr
, 8);
2085 initial_length_size
= 12;
2090 initial_length_size
= 4;
2093 if (info
.li_length
+ initial_length_size
> section
->size
)
2096 (_("The line info appears to be corrupt - the section is too small\n"));
2100 /* Check its version number. */
2101 info
.li_version
= byte_get (hdrptr
, 2);
2103 if (info
.li_version
!= 2 && info
.li_version
!= 3)
2105 warn (_("Only DWARF version 2 and 3 line info is currently supported.\n"));
2109 info
.li_prologue_length
= byte_get (hdrptr
, offset_size
);
2110 hdrptr
+= offset_size
;
2111 info
.li_min_insn_length
= byte_get (hdrptr
, 1);
2113 info
.li_default_is_stmt
= byte_get (hdrptr
, 1);
2115 info
.li_line_base
= byte_get (hdrptr
, 1);
2117 info
.li_line_range
= byte_get (hdrptr
, 1);
2119 info
.li_opcode_base
= byte_get (hdrptr
, 1);
2122 /* Sign extend the line base field. */
2123 info
.li_line_base
<<= 24;
2124 info
.li_line_base
>>= 24;
2126 printf (_(" Offset: 0x%lx\n"), hdroff
);
2127 printf (_(" Length: %ld\n"), info
.li_length
);
2128 printf (_(" DWARF Version: %d\n"), info
.li_version
);
2129 printf (_(" Prologue Length: %d\n"), info
.li_prologue_length
);
2130 printf (_(" Minimum Instruction Length: %d\n"), info
.li_min_insn_length
);
2131 printf (_(" Initial value of 'is_stmt': %d\n"), info
.li_default_is_stmt
);
2132 printf (_(" Line Base: %d\n"), info
.li_line_base
);
2133 printf (_(" Line Range: %d\n"), info
.li_line_range
);
2134 printf (_(" Opcode Base: %d\n"), info
.li_opcode_base
);
2136 end_of_sequence
= data
+ info
.li_length
+ initial_length_size
;
2138 reset_state_machine (info
.li_default_is_stmt
);
2140 /* Display the contents of the Opcodes table. */
2141 standard_opcodes
= hdrptr
;
2143 printf (_("\n Opcodes:\n"));
2145 for (i
= 1; i
< info
.li_opcode_base
; i
++)
2146 printf (_(" Opcode %d has %d args\n"), i
, standard_opcodes
[i
- 1]);
2148 /* Display the contents of the Directory table. */
2149 data
= standard_opcodes
+ info
.li_opcode_base
- 1;
2152 printf (_("\n The Directory Table is empty.\n"));
2155 printf (_("\n The Directory Table:\n"));
2159 printf (_(" %s\n"), data
);
2161 data
+= strlen ((char *) data
) + 1;
2165 /* Skip the NUL at the end of the table. */
2168 /* Display the contents of the File Name table. */
2170 printf (_("\n The File Name Table is empty.\n"));
2173 printf (_("\n The File Name Table:\n"));
2174 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
2178 unsigned char *name
;
2179 unsigned int bytes_read
;
2181 printf (_(" %d\t"), ++state_machine_regs
.last_file_entry
);
2184 data
+= strlen ((char *) data
) + 1;
2186 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
2188 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
2190 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
2192 printf (_("%s\n"), name
);
2196 /* Skip the NUL at the end of the table. */
2199 /* Now display the statements. */
2200 printf (_("\n Line Number Statements:\n"));
2202 while (data
< end_of_sequence
)
2204 unsigned char op_code
;
2206 unsigned long int uladv
;
2207 unsigned int bytes_read
;
2211 if (op_code
>= info
.li_opcode_base
)
2213 op_code
-= info
.li_opcode_base
;
2214 uladv
= (op_code
/ info
.li_line_range
) * info
.li_min_insn_length
;
2215 state_machine_regs
.address
+= uladv
;
2216 printf (_(" Special opcode %d: advance Address by %lu to 0x%lx"),
2217 op_code
, uladv
, state_machine_regs
.address
);
2218 adv
= (op_code
% info
.li_line_range
) + info
.li_line_base
;
2219 state_machine_regs
.line
+= adv
;
2220 printf (_(" and Line by %d to %d\n"),
2221 adv
, state_machine_regs
.line
);
2223 else switch (op_code
)
2225 case DW_LNS_extended_op
:
2226 data
+= process_extended_line_op (data
, info
.li_default_is_stmt
);
2230 printf (_(" Copy\n"));
2233 case DW_LNS_advance_pc
:
2234 uladv
= read_leb128 (data
, & bytes_read
, 0);
2235 uladv
*= info
.li_min_insn_length
;
2237 state_machine_regs
.address
+= uladv
;
2238 printf (_(" Advance PC by %lu to 0x%lx\n"), uladv
,
2239 state_machine_regs
.address
);
2242 case DW_LNS_advance_line
:
2243 adv
= read_leb128 (data
, & bytes_read
, 1);
2245 state_machine_regs
.line
+= adv
;
2246 printf (_(" Advance Line by %d to %d\n"), adv
,
2247 state_machine_regs
.line
);
2250 case DW_LNS_set_file
:
2251 adv
= read_leb128 (data
, & bytes_read
, 0);
2253 printf (_(" Set File Name to entry %d in the File Name Table\n"),
2255 state_machine_regs
.file
= adv
;
2258 case DW_LNS_set_column
:
2259 uladv
= read_leb128 (data
, & bytes_read
, 0);
2261 printf (_(" Set column to %lu\n"), uladv
);
2262 state_machine_regs
.column
= uladv
;
2265 case DW_LNS_negate_stmt
:
2266 adv
= state_machine_regs
.is_stmt
;
2268 printf (_(" Set is_stmt to %d\n"), adv
);
2269 state_machine_regs
.is_stmt
= adv
;
2272 case DW_LNS_set_basic_block
:
2273 printf (_(" Set basic block\n"));
2274 state_machine_regs
.basic_block
= 1;
2277 case DW_LNS_const_add_pc
:
2278 uladv
= (((255 - info
.li_opcode_base
) / info
.li_line_range
)
2279 * info
.li_min_insn_length
);
2280 state_machine_regs
.address
+= uladv
;
2281 printf (_(" Advance PC by constant %lu to 0x%lx\n"), uladv
,
2282 state_machine_regs
.address
);
2285 case DW_LNS_fixed_advance_pc
:
2286 uladv
= byte_get (data
, 2);
2288 state_machine_regs
.address
+= uladv
;
2289 printf (_(" Advance PC by fixed size amount %lu to 0x%lx\n"),
2290 uladv
, state_machine_regs
.address
);
2293 case DW_LNS_set_prologue_end
:
2294 printf (_(" Set prologue_end to true\n"));
2297 case DW_LNS_set_epilogue_begin
:
2298 printf (_(" Set epilogue_begin to true\n"));
2301 case DW_LNS_set_isa
:
2302 uladv
= read_leb128 (data
, & bytes_read
, 0);
2304 printf (_(" Set ISA to %lu\n"), uladv
);
2308 printf (_(" Unknown opcode %d with operands: "), op_code
);
2310 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
2312 printf ("0x%lx%s", read_leb128 (data
, &bytes_read
, 0),
2313 i
== 1 ? "" : ", ");
2327 find_debug_info_for_offset (unsigned long offset
)
2331 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
2334 for (i
= 0; i
< num_debug_info_entries
; i
++)
2335 if (debug_information
[i
].cu_offset
== offset
)
2336 return debug_information
+ i
;
2342 display_debug_pubnames (struct dwarf_section
*section
,
2343 void *file ATTRIBUTE_UNUSED
)
2345 DWARF2_Internal_PubNames pubnames
;
2346 unsigned char *start
= section
->start
;
2347 unsigned char *end
= start
+ section
->size
;
2349 /* It does not matter if this load fails,
2350 we test for that later on. */
2351 load_debug_info (file
);
2353 printf (_("Contents of the %s section:\n\n"), section
->name
);
2357 unsigned char *data
;
2358 unsigned long offset
;
2359 int offset_size
, initial_length_size
;
2363 pubnames
.pn_length
= byte_get (data
, 4);
2365 if (pubnames
.pn_length
== 0xffffffff)
2367 pubnames
.pn_length
= byte_get (data
, 8);
2370 initial_length_size
= 12;
2375 initial_length_size
= 4;
2378 pubnames
.pn_version
= byte_get (data
, 2);
2381 pubnames
.pn_offset
= byte_get (data
, offset_size
);
2382 data
+= offset_size
;
2384 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
2385 && num_debug_info_entries
> 0
2386 && find_debug_info_for_offset (pubnames
.pn_offset
) == NULL
)
2387 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
2388 pubnames
.pn_offset
, section
->name
);
2390 pubnames
.pn_size
= byte_get (data
, offset_size
);
2391 data
+= offset_size
;
2393 start
+= pubnames
.pn_length
+ initial_length_size
;
2395 if (pubnames
.pn_version
!= 2 && pubnames
.pn_version
!= 3)
2397 static int warned
= 0;
2401 warn (_("Only DWARF 2 and 3 pubnames are currently supported\n"));
2408 printf (_(" Length: %ld\n"),
2409 pubnames
.pn_length
);
2410 printf (_(" Version: %d\n"),
2411 pubnames
.pn_version
);
2412 printf (_(" Offset into .debug_info section: 0x%lx\n"),
2413 pubnames
.pn_offset
);
2414 printf (_(" Size of area in .debug_info section: %ld\n"),
2417 printf (_("\n Offset\tName\n"));
2421 offset
= byte_get (data
, offset_size
);
2425 data
+= offset_size
;
2426 printf (" %-6ld\t\t%s\n", offset
, data
);
2427 data
+= strlen ((char *) data
) + 1;
2430 while (offset
!= 0);
2438 display_debug_macinfo (struct dwarf_section
*section
,
2439 void *file ATTRIBUTE_UNUSED
)
2441 unsigned char *start
= section
->start
;
2442 unsigned char *end
= start
+ section
->size
;
2443 unsigned char *curr
= start
;
2444 unsigned int bytes_read
;
2445 enum dwarf_macinfo_record_type op
;
2447 printf (_("Contents of the %s section:\n\n"), section
->name
);
2451 unsigned int lineno
;
2459 case DW_MACINFO_start_file
:
2461 unsigned int filenum
;
2463 lineno
= read_leb128 (curr
, & bytes_read
, 0);
2465 filenum
= read_leb128 (curr
, & bytes_read
, 0);
2468 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"),
2473 case DW_MACINFO_end_file
:
2474 printf (_(" DW_MACINFO_end_file\n"));
2477 case DW_MACINFO_define
:
2478 lineno
= read_leb128 (curr
, & bytes_read
, 0);
2480 string
= (char *) curr
;
2481 curr
+= strlen (string
) + 1;
2482 printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"),
2486 case DW_MACINFO_undef
:
2487 lineno
= read_leb128 (curr
, & bytes_read
, 0);
2489 string
= (char *) curr
;
2490 curr
+= strlen (string
) + 1;
2491 printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"),
2495 case DW_MACINFO_vendor_ext
:
2497 unsigned int constant
;
2499 constant
= read_leb128 (curr
, & bytes_read
, 0);
2501 string
= (char *) curr
;
2502 curr
+= strlen (string
) + 1;
2503 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"),
2514 display_debug_abbrev (struct dwarf_section
*section
,
2515 void *file ATTRIBUTE_UNUSED
)
2517 abbrev_entry
*entry
;
2518 unsigned char *start
= section
->start
;
2519 unsigned char *end
= start
+ section
->size
;
2521 printf (_("Contents of the %s section:\n\n"), section
->name
);
2527 start
= process_abbrev_section (start
, end
);
2529 if (first_abbrev
== NULL
)
2532 printf (_(" Number TAG\n"));
2534 for (entry
= first_abbrev
; entry
; entry
= entry
->next
)
2538 printf (_(" %ld %s [%s]\n"),
2540 get_TAG_name (entry
->tag
),
2541 entry
->children
? _("has children") : _("no children"));
2543 for (attr
= entry
->first_attr
; attr
; attr
= attr
->next
)
2544 printf (_(" %-18s %s\n"),
2545 get_AT_name (attr
->attribute
),
2546 get_FORM_name (attr
->form
));
2557 display_debug_loc (struct dwarf_section
*section
, void *file
)
2559 unsigned char *start
= section
->start
;
2560 unsigned char *section_end
;
2561 unsigned long bytes
;
2562 unsigned char *section_begin
= start
;
2563 unsigned int num_loc_list
= 0;
2564 unsigned long last_offset
= 0;
2565 unsigned int first
= 0;
2568 int seen_first_offset
= 0;
2569 int use_debug_info
= 1;
2570 unsigned char *next
;
2572 bytes
= section
->size
;
2573 section_end
= start
+ bytes
;
2577 printf (_("\nThe %s section is empty.\n"), section
->name
);
2581 if (load_debug_info (file
) == 0)
2583 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
2588 /* Check the order of location list in .debug_info section. If
2589 offsets of location lists are in the ascending order, we can
2590 use `debug_information' directly. */
2591 for (i
= 0; i
< num_debug_info_entries
; i
++)
2595 num
= debug_information
[i
].num_loc_offsets
;
2596 num_loc_list
+= num
;
2598 /* Check if we can use `debug_information' directly. */
2599 if (use_debug_info
&& num
!= 0)
2601 if (!seen_first_offset
)
2603 /* This is the first location list. */
2604 last_offset
= debug_information
[i
].loc_offsets
[0];
2606 seen_first_offset
= 1;
2612 for (; j
< num
; j
++)
2615 debug_information
[i
].loc_offsets
[j
])
2620 last_offset
= debug_information
[i
].loc_offsets
[j
];
2625 if (!use_debug_info
)
2626 /* FIXME: Should we handle this case? */
2627 error (_("Location lists in .debug_info section aren't in ascending order!\n"));
2629 if (!seen_first_offset
)
2630 error (_("No location lists in .debug_info section!\n"));
2632 /* DWARF sections under Mach-O have non-zero addresses. */
2633 if (debug_information
[first
].num_loc_offsets
> 0
2634 && debug_information
[first
].loc_offsets
[0] != section
->address
)
2635 warn (_("Location lists in %s section start at 0x%lx\n"),
2636 section
->name
, debug_information
[first
].loc_offsets
[0]);
2638 printf (_("Contents of the %s section:\n\n"), section
->name
);
2639 printf (_(" Offset Begin End Expression\n"));
2641 seen_first_offset
= 0;
2642 for (i
= first
; i
< num_debug_info_entries
; i
++)
2646 unsigned short length
;
2647 unsigned long offset
;
2648 unsigned int pointer_size
;
2649 unsigned long cu_offset
;
2650 unsigned long base_address
;
2651 int need_frame_base
;
2654 pointer_size
= debug_information
[i
].pointer_size
;
2655 cu_offset
= debug_information
[i
].cu_offset
;
2657 for (j
= 0; j
< debug_information
[i
].num_loc_offsets
; j
++)
2659 has_frame_base
= debug_information
[i
].have_frame_base
[j
];
2660 /* DWARF sections under Mach-O have non-zero addresses. */
2661 offset
= debug_information
[i
].loc_offsets
[j
] - section
->address
;
2662 next
= section_begin
+ offset
;
2663 base_address
= debug_information
[i
].base_address
;
2665 if (!seen_first_offset
)
2666 seen_first_offset
= 1;
2670 warn (_("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n"),
2671 (long)(start
- section_begin
), (long)(next
- section_begin
));
2672 else if (start
> next
)
2673 warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n"),
2674 (long)(start
- section_begin
), (long)(next
- section_begin
));
2678 if (offset
>= bytes
)
2680 warn (_("Offset 0x%lx is bigger than .debug_loc section size.\n"),
2687 if (start
+ 2 * pointer_size
> section_end
)
2689 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
2694 /* Note: we use sign extension here in order to be sure that
2695 we can detect the -1 escape value. Sign extension into the
2696 top 32 bits of a 32-bit address will not affect the values
2697 that we display since we always show hex values, and always
2698 the bottom 32-bits. */
2699 begin
= byte_get_signed (start
, pointer_size
);
2700 start
+= pointer_size
;
2701 end
= byte_get_signed (start
, pointer_size
);
2702 start
+= pointer_size
;
2704 printf (" %8.8lx ", offset
);
2706 if (begin
== 0 && end
== 0)
2708 printf (_("<End of list>\n"));
2712 /* Check base address specifiers. */
2713 if (begin
== (dwarf_vma
) -1 && end
!= (dwarf_vma
) -1)
2716 print_dwarf_vma (begin
, pointer_size
);
2717 print_dwarf_vma (end
, pointer_size
);
2718 printf (_("(base address)\n"));
2722 if (start
+ 2 > section_end
)
2724 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
2729 length
= byte_get (start
, 2);
2732 if (start
+ length
> section_end
)
2734 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
2739 print_dwarf_vma (begin
+ base_address
, pointer_size
);
2740 print_dwarf_vma (end
+ base_address
, pointer_size
);
2743 need_frame_base
= decode_location_expression (start
,
2749 if (need_frame_base
&& !has_frame_base
)
2750 printf (_(" [without DW_AT_frame_base]"));
2753 fputs (_(" (start == end)"), stdout
);
2754 else if (begin
> end
)
2755 fputs (_(" (start > end)"), stdout
);
2764 if (start
< section_end
)
2765 warn (_("There are %ld unused bytes at the end of section %s\n"),
2766 (long) (section_end
- start
), section
->name
);
2771 display_debug_str (struct dwarf_section
*section
,
2772 void *file ATTRIBUTE_UNUSED
)
2774 unsigned char *start
= section
->start
;
2775 unsigned long bytes
= section
->size
;
2776 dwarf_vma addr
= section
->address
;
2780 printf (_("\nThe %s section is empty.\n"), section
->name
);
2784 printf (_("Contents of the %s section:\n\n"), section
->name
);
2792 lbytes
= (bytes
> 16 ? 16 : bytes
);
2794 printf (" 0x%8.8lx ", (unsigned long) addr
);
2796 for (j
= 0; j
< 16; j
++)
2799 printf ("%2.2x", start
[j
]);
2807 for (j
= 0; j
< lbytes
; j
++)
2810 if (k
>= ' ' && k
< 0x80)
2829 display_debug_info (struct dwarf_section
*section
, void *file
)
2831 return process_debug_info (section
, file
, 0);
2836 display_debug_aranges (struct dwarf_section
*section
,
2837 void *file ATTRIBUTE_UNUSED
)
2839 unsigned char *start
= section
->start
;
2840 unsigned char *end
= start
+ section
->size
;
2842 printf (_("The section %s contains:\n\n"), section
->name
);
2844 /* It does not matter if this load fails,
2845 we test for that later on. */
2846 load_debug_info (file
);
2850 unsigned char *hdrptr
;
2851 DWARF2_Internal_ARange arange
;
2852 unsigned char *ranges
;
2855 unsigned char address_size
;
2858 int initial_length_size
;
2862 arange
.ar_length
= byte_get (hdrptr
, 4);
2865 if (arange
.ar_length
== 0xffffffff)
2867 arange
.ar_length
= byte_get (hdrptr
, 8);
2870 initial_length_size
= 12;
2875 initial_length_size
= 4;
2878 arange
.ar_version
= byte_get (hdrptr
, 2);
2881 arange
.ar_info_offset
= byte_get (hdrptr
, offset_size
);
2882 hdrptr
+= offset_size
;
2884 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
2885 && num_debug_info_entries
> 0
2886 && find_debug_info_for_offset (arange
.ar_info_offset
) == NULL
)
2887 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
2888 arange
.ar_info_offset
, section
->name
);
2890 arange
.ar_pointer_size
= byte_get (hdrptr
, 1);
2893 arange
.ar_segment_size
= byte_get (hdrptr
, 1);
2896 if (arange
.ar_version
!= 2 && arange
.ar_version
!= 3)
2898 warn (_("Only DWARF 2 and 3 aranges are currently supported.\n"));
2902 printf (_(" Length: %ld\n"), arange
.ar_length
);
2903 printf (_(" Version: %d\n"), arange
.ar_version
);
2904 printf (_(" Offset into .debug_info: 0x%lx\n"), arange
.ar_info_offset
);
2905 printf (_(" Pointer Size: %d\n"), arange
.ar_pointer_size
);
2906 printf (_(" Segment Size: %d\n"), arange
.ar_segment_size
);
2908 address_size
= arange
.ar_pointer_size
+ arange
.ar_segment_size
;
2910 /* The DWARF spec does not require that the address size be a power
2911 of two, but we do. This will have to change if we ever encounter
2912 an uneven architecture. */
2913 if ((address_size
& (address_size
- 1)) != 0)
2915 warn (_("Pointer size + Segment size is not a power of two.\n"));
2919 if (address_size
> 4)
2920 printf (_("\n Address Length\n"));
2922 printf (_("\n Address Length\n"));
2926 /* Must pad to an alignment boundary that is twice the address size. */
2927 excess
= (hdrptr
- start
) % (2 * address_size
);
2929 ranges
+= (2 * address_size
) - excess
;
2931 start
+= arange
.ar_length
+ initial_length_size
;
2933 while (ranges
+ 2 * address_size
<= start
)
2935 address
= byte_get (ranges
, address_size
);
2937 ranges
+= address_size
;
2939 length
= byte_get (ranges
, address_size
);
2941 ranges
+= address_size
;
2943 print_dwarf_vma (address
, address_size
);
2944 print_dwarf_vma (length
, address_size
);
2955 display_debug_ranges (struct dwarf_section
*section
,
2956 void *file ATTRIBUTE_UNUSED
)
2958 unsigned char *start
= section
->start
;
2959 unsigned char *section_end
;
2960 unsigned long bytes
;
2961 unsigned char *section_begin
= start
;
2962 unsigned int num_range_list
= 0;
2963 unsigned long last_offset
= 0;
2964 unsigned int first
= 0;
2967 int seen_first_offset
= 0;
2968 int use_debug_info
= 1;
2969 unsigned char *next
;
2971 bytes
= section
->size
;
2972 section_end
= start
+ bytes
;
2976 printf (_("\nThe %s section is empty.\n"), section
->name
);
2980 if (load_debug_info (file
) == 0)
2982 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
2987 /* Check the order of range list in .debug_info section. If
2988 offsets of range lists are in the ascending order, we can
2989 use `debug_information' directly. */
2990 for (i
= 0; i
< num_debug_info_entries
; i
++)
2994 num
= debug_information
[i
].num_range_lists
;
2995 num_range_list
+= num
;
2997 /* Check if we can use `debug_information' directly. */
2998 if (use_debug_info
&& num
!= 0)
3000 if (!seen_first_offset
)
3002 /* This is the first range list. */
3003 last_offset
= debug_information
[i
].range_lists
[0];
3005 seen_first_offset
= 1;
3011 for (; j
< num
; j
++)
3014 debug_information
[i
].range_lists
[j
])
3019 last_offset
= debug_information
[i
].range_lists
[j
];
3024 if (!use_debug_info
)
3025 /* FIXME: Should we handle this case? */
3026 error (_("Range lists in .debug_info section aren't in ascending order!\n"));
3028 if (!seen_first_offset
)
3029 error (_("No range lists in .debug_info section!\n"));
3031 /* DWARF sections under Mach-O have non-zero addresses. */
3032 if (debug_information
[first
].num_range_lists
> 0
3033 && debug_information
[first
].range_lists
[0] != section
->address
)
3034 warn (_("Range lists in %s section start at 0x%lx\n"),
3035 section
->name
, debug_information
[first
].range_lists
[0]);
3037 printf (_("Contents of the %s section:\n\n"), section
->name
);
3038 printf (_(" Offset Begin End\n"));
3040 seen_first_offset
= 0;
3041 for (i
= first
; i
< num_debug_info_entries
; i
++)
3045 unsigned long offset
;
3046 unsigned int pointer_size
;
3047 unsigned long base_address
;
3049 pointer_size
= debug_information
[i
].pointer_size
;
3051 for (j
= 0; j
< debug_information
[i
].num_range_lists
; j
++)
3053 /* DWARF sections under Mach-O have non-zero addresses. */
3054 offset
= debug_information
[i
].range_lists
[j
] - section
->address
;
3055 next
= section_begin
+ offset
;
3056 base_address
= debug_information
[i
].base_address
;
3058 if (!seen_first_offset
)
3059 seen_first_offset
= 1;
3063 warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"),
3064 (long)(start
- section_begin
),
3065 (long)(next
- section_begin
), section
->name
);
3066 else if (start
> next
)
3067 warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"),
3068 (long)(start
- section_begin
),
3069 (long)(next
- section_begin
), section
->name
);
3075 /* Note: we use sign extension here in order to be sure that
3076 we can detect the -1 escape value. Sign extension into the
3077 top 32 bits of a 32-bit address will not affect the values
3078 that we display since we always show hex values, and always
3079 the bottom 32-bits. */
3080 begin
= byte_get_signed (start
, pointer_size
);
3081 start
+= pointer_size
;
3082 end
= byte_get_signed (start
, pointer_size
);
3083 start
+= pointer_size
;
3085 printf (" %8.8lx ", offset
);
3087 if (begin
== 0 && end
== 0)
3089 printf (_("<End of list>\n"));
3093 print_dwarf_vma (begin
, pointer_size
);
3094 print_dwarf_vma (end
, pointer_size
);
3096 /* Check base address specifiers. */
3097 if (begin
== (dwarf_vma
) -1 && end
!= (dwarf_vma
) -1)
3100 printf ("(base address)\n");
3105 fputs (_("(start == end)"), stdout
);
3106 else if (begin
> end
)
3107 fputs (_("(start > end)"), stdout
);
3117 typedef struct Frame_Chunk
3119 struct Frame_Chunk
*next
;
3120 unsigned char *chunk_start
;
3122 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
3123 short int *col_type
;
3126 unsigned int code_factor
;
3128 unsigned long pc_begin
;
3129 unsigned long pc_range
;
3133 unsigned char fde_encoding
;
3134 unsigned char cfa_exp
;
3138 /* A marker for a col_type that means this column was never referenced
3139 in the frame info. */
3140 #define DW_CFA_unreferenced (-1)
3143 frame_need_space (Frame_Chunk
*fc
, int reg
)
3145 int prev
= fc
->ncols
;
3147 if (reg
< fc
->ncols
)
3150 fc
->ncols
= reg
+ 1;
3151 fc
->col_type
= xcrealloc (fc
->col_type
, fc
->ncols
, sizeof (short int));
3152 fc
->col_offset
= xcrealloc (fc
->col_offset
, fc
->ncols
, sizeof (int));
3154 while (prev
< fc
->ncols
)
3156 fc
->col_type
[prev
] = DW_CFA_unreferenced
;
3157 fc
->col_offset
[prev
] = 0;
3162 static const char *const dwarf_regnames_i386
[] =
3164 "eax", "ecx", "edx", "ebx",
3165 "esp", "ebp", "esi", "edi",
3166 "eip", "eflags", NULL
,
3167 "st0", "st1", "st2", "st3",
3168 "st4", "st5", "st6", "st7",
3170 "xmm0", "xmm1", "xmm2", "xmm3",
3171 "xmm4", "xmm5", "xmm6", "xmm7",
3172 "mm0", "mm1", "mm2", "mm3",
3173 "mm4", "mm5", "mm6", "mm7",
3174 "fcw", "fsw", "mxcsr",
3175 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
,
3179 static const char *const dwarf_regnames_x86_64
[] =
3181 "rax", "rdx", "rcx", "rbx",
3182 "rsi", "rdi", "rbp", "rsp",
3183 "r8", "r9", "r10", "r11",
3184 "r12", "r13", "r14", "r15",
3186 "xmm0", "xmm1", "xmm2", "xmm3",
3187 "xmm4", "xmm5", "xmm6", "xmm7",
3188 "xmm8", "xmm9", "xmm10", "xmm11",
3189 "xmm12", "xmm13", "xmm14", "xmm15",
3190 "st0", "st1", "st2", "st3",
3191 "st4", "st5", "st6", "st7",
3192 "mm0", "mm1", "mm2", "mm3",
3193 "mm4", "mm5", "mm6", "mm7",
3195 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
,
3196 "fs.base", "gs.base", NULL
, NULL
,
3198 "mxcsr", "fcw", "fsw"
3201 static const char *const *dwarf_regnames
;
3202 static unsigned int dwarf_regnames_count
;
3205 init_dwarf_regnames (unsigned int e_machine
)
3211 dwarf_regnames
= dwarf_regnames_i386
;
3212 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_i386
);
3216 dwarf_regnames
= dwarf_regnames_x86_64
;
3217 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_x86_64
);
3226 regname (unsigned int regno
, int row
)
3228 static char reg
[64];
3230 && regno
< dwarf_regnames_count
3231 && dwarf_regnames
[regno
] != NULL
)
3234 return dwarf_regnames
[regno
];
3235 snprintf (reg
, sizeof (reg
), "r%d (%s)", regno
,
3236 dwarf_regnames
[regno
]);
3239 snprintf (reg
, sizeof (reg
), "r%d", regno
);
3244 frame_display_row (Frame_Chunk
*fc
, int *need_col_headers
, int *max_regs
)
3249 if (*max_regs
< fc
->ncols
)
3250 *max_regs
= fc
->ncols
;
3252 if (*need_col_headers
)
3254 static const char *loc
= " LOC";
3256 *need_col_headers
= 0;
3258 printf ("%-*s CFA ", eh_addr_size
* 2, loc
);
3260 for (r
= 0; r
< *max_regs
; r
++)
3261 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
3266 printf ("%-5s ", regname (r
, 1));
3272 printf ("%0*lx ", eh_addr_size
* 2, fc
->pc_begin
);
3274 strcpy (tmp
, "exp");
3276 sprintf (tmp
, "%s%+d", regname (fc
->cfa_reg
, 1), fc
->cfa_offset
);
3277 printf ("%-8s ", tmp
);
3279 for (r
= 0; r
< fc
->ncols
; r
++)
3281 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
3283 switch (fc
->col_type
[r
])
3285 case DW_CFA_undefined
:
3288 case DW_CFA_same_value
:
3292 sprintf (tmp
, "c%+d", fc
->col_offset
[r
]);
3294 case DW_CFA_val_offset
:
3295 sprintf (tmp
, "v%+d", fc
->col_offset
[r
]);
3297 case DW_CFA_register
:
3298 sprintf (tmp
, "%s", regname (fc
->col_offset
[r
], 0));
3300 case DW_CFA_expression
:
3301 strcpy (tmp
, "exp");
3303 case DW_CFA_val_expression
:
3304 strcpy (tmp
, "vexp");
3307 strcpy (tmp
, "n/a");
3310 printf ("%-5s ", tmp
);
3317 size_of_encoded_value (int encoding
)
3319 switch (encoding
& 0x7)
3322 case 0: return eh_addr_size
;
3330 get_encoded_value (unsigned char *data
, int encoding
)
3332 int size
= size_of_encoded_value (encoding
);
3334 if (encoding
& DW_EH_PE_signed
)
3335 return byte_get_signed (data
, size
);
3337 return byte_get (data
, size
);
3340 #define GET(N) byte_get (start, N); start += N
3341 #define LEB() read_leb128 (start, & length_return, 0); start += length_return
3342 #define SLEB() read_leb128 (start, & length_return, 1); start += length_return
3345 display_debug_frames (struct dwarf_section
*section
,
3346 void *file ATTRIBUTE_UNUSED
)
3348 unsigned char *start
= section
->start
;
3349 unsigned char *end
= start
+ section
->size
;
3350 unsigned char *section_start
= start
;
3351 Frame_Chunk
*chunks
= 0;
3352 Frame_Chunk
*remembered_state
= 0;
3354 int is_eh
= strcmp (section
->name
, ".eh_frame") == 0;
3355 unsigned int length_return
;
3358 printf (_("The section %s contains:\n"), section
->name
);
3362 unsigned char *saved_start
;
3363 unsigned char *block_end
;
3364 unsigned long length
;
3365 unsigned long cie_id
;
3368 int need_col_headers
= 1;
3369 unsigned char *augmentation_data
= NULL
;
3370 unsigned long augmentation_data_len
= 0;
3371 int encoded_ptr_size
= eh_addr_size
;
3373 int initial_length_size
;
3375 saved_start
= start
;
3376 length
= byte_get (start
, 4); start
+= 4;
3380 printf ("\n%08lx ZERO terminator\n\n",
3381 (unsigned long)(saved_start
- section_start
));
3385 if (length
== 0xffffffff)
3387 length
= byte_get (start
, 8);
3390 initial_length_size
= 12;
3395 initial_length_size
= 4;
3398 block_end
= saved_start
+ length
+ initial_length_size
;
3399 if (block_end
> end
)
3401 warn ("Invalid length %#08lx in FDE at %#08lx\n",
3402 length
, (unsigned long)(saved_start
- section_start
));
3405 cie_id
= byte_get (start
, offset_size
); start
+= offset_size
;
3407 if (is_eh
? (cie_id
== 0) : (cie_id
== DW_CIE_ID
))
3411 fc
= xmalloc (sizeof (Frame_Chunk
));
3412 memset (fc
, 0, sizeof (Frame_Chunk
));
3416 fc
->chunk_start
= saved_start
;
3418 fc
->col_type
= xmalloc (sizeof (short int));
3419 fc
->col_offset
= xmalloc (sizeof (int));
3420 frame_need_space (fc
, max_regs
- 1);
3424 fc
->augmentation
= (char *) start
;
3425 start
= (unsigned char *) strchr ((char *) start
, '\0') + 1;
3427 if (fc
->augmentation
[0] == 'z')
3429 fc
->code_factor
= LEB ();
3430 fc
->data_factor
= SLEB ();
3439 augmentation_data_len
= LEB ();
3440 augmentation_data
= start
;
3441 start
+= augmentation_data_len
;
3443 else if (strcmp (fc
->augmentation
, "eh") == 0)
3445 start
+= eh_addr_size
;
3446 fc
->code_factor
= LEB ();
3447 fc
->data_factor
= SLEB ();
3459 fc
->code_factor
= LEB ();
3460 fc
->data_factor
= SLEB ();
3472 if (do_debug_frames_interp
)
3473 printf ("\n%08lx %08lx %08lx CIE \"%s\" cf=%d df=%d ra=%d\n",
3474 (unsigned long)(saved_start
- section_start
), length
, cie_id
,
3475 fc
->augmentation
, fc
->code_factor
, fc
->data_factor
,
3479 printf ("\n%08lx %08lx %08lx CIE\n",
3480 (unsigned long)(saved_start
- section_start
), length
, cie_id
);
3481 printf (" Version: %d\n", version
);
3482 printf (" Augmentation: \"%s\"\n", fc
->augmentation
);
3483 printf (" Code alignment factor: %u\n", fc
->code_factor
);
3484 printf (" Data alignment factor: %d\n", fc
->data_factor
);
3485 printf (" Return address column: %d\n", fc
->ra
);
3487 if (augmentation_data_len
)
3490 printf (" Augmentation data: ");
3491 for (i
= 0; i
< augmentation_data_len
; ++i
)
3492 printf (" %02x", augmentation_data
[i
]);
3498 if (augmentation_data_len
)
3500 unsigned char *p
, *q
;
3501 p
= (unsigned char *) fc
->augmentation
+ 1;
3502 q
= augmentation_data
;
3509 q
+= 1 + size_of_encoded_value (*q
);
3511 fc
->fde_encoding
= *q
++;
3517 if (fc
->fde_encoding
)
3518 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
3521 frame_need_space (fc
, fc
->ra
);
3525 unsigned char *look_for
;
3526 static Frame_Chunk fde_fc
;
3529 memset (fc
, 0, sizeof (Frame_Chunk
));
3531 look_for
= is_eh
? start
- 4 - cie_id
: section_start
+ cie_id
;
3533 for (cie
= chunks
; cie
; cie
= cie
->next
)
3534 if (cie
->chunk_start
== look_for
)
3539 warn ("Invalid CIE pointer %#08lx in FDE at %#08lx\n",
3540 cie_id
, (unsigned long)(saved_start
- section_start
));
3542 fc
->col_type
= xmalloc (sizeof (short int));
3543 fc
->col_offset
= xmalloc (sizeof (int));
3544 frame_need_space (fc
, max_regs
- 1);
3546 fc
->augmentation
= "";
3547 fc
->fde_encoding
= 0;
3551 fc
->ncols
= cie
->ncols
;
3552 fc
->col_type
= xcmalloc (fc
->ncols
, sizeof (short int));
3553 fc
->col_offset
= xcmalloc (fc
->ncols
, sizeof (int));
3554 memcpy (fc
->col_type
, cie
->col_type
, fc
->ncols
* sizeof (short int));
3555 memcpy (fc
->col_offset
, cie
->col_offset
, fc
->ncols
* sizeof (int));
3556 fc
->augmentation
= cie
->augmentation
;
3557 fc
->code_factor
= cie
->code_factor
;
3558 fc
->data_factor
= cie
->data_factor
;
3559 fc
->cfa_reg
= cie
->cfa_reg
;
3560 fc
->cfa_offset
= cie
->cfa_offset
;
3562 frame_need_space (fc
, max_regs
- 1);
3563 fc
->fde_encoding
= cie
->fde_encoding
;
3566 if (fc
->fde_encoding
)
3567 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
3569 fc
->pc_begin
= get_encoded_value (start
, fc
->fde_encoding
);
3570 if ((fc
->fde_encoding
& 0x70) == DW_EH_PE_pcrel
)
3571 fc
->pc_begin
+= section
->address
+ (start
- section_start
);
3572 start
+= encoded_ptr_size
;
3573 fc
->pc_range
= byte_get (start
, encoded_ptr_size
);
3574 start
+= encoded_ptr_size
;
3576 if (cie
->augmentation
[0] == 'z')
3578 augmentation_data_len
= LEB ();
3579 augmentation_data
= start
;
3580 start
+= augmentation_data_len
;
3583 printf ("\n%08lx %08lx %08lx FDE cie=%08lx pc=%08lx..%08lx\n",
3584 (unsigned long)(saved_start
- section_start
), length
, cie_id
,
3585 (unsigned long)(cie
->chunk_start
- section_start
),
3586 fc
->pc_begin
, fc
->pc_begin
+ fc
->pc_range
);
3587 if (! do_debug_frames_interp
&& augmentation_data_len
)
3591 printf (" Augmentation data: ");
3592 for (i
= 0; i
< augmentation_data_len
; ++i
)
3593 printf (" %02x", augmentation_data
[i
]);
3599 /* At this point, fc is the current chunk, cie (if any) is set, and
3600 we're about to interpret instructions for the chunk. */
3601 /* ??? At present we need to do this always, since this sizes the
3602 fc->col_type and fc->col_offset arrays, which we write into always.
3603 We should probably split the interpreted and non-interpreted bits
3604 into two different routines, since there's so much that doesn't
3605 really overlap between them. */
3606 if (1 || do_debug_frames_interp
)
3608 /* Start by making a pass over the chunk, allocating storage
3609 and taking note of what registers are used. */
3610 unsigned char *tmp
= start
;
3612 while (start
< block_end
)
3615 unsigned long reg
, tmp
;
3622 /* Warning: if you add any more cases to this switch, be
3623 sure to add them to the corresponding switch below. */
3626 case DW_CFA_advance_loc
:
3630 frame_need_space (fc
, opa
);
3631 fc
->col_type
[opa
] = DW_CFA_undefined
;
3633 case DW_CFA_restore
:
3634 frame_need_space (fc
, opa
);
3635 fc
->col_type
[opa
] = DW_CFA_undefined
;
3637 case DW_CFA_set_loc
:
3638 start
+= encoded_ptr_size
;
3640 case DW_CFA_advance_loc1
:
3643 case DW_CFA_advance_loc2
:
3646 case DW_CFA_advance_loc4
:
3649 case DW_CFA_offset_extended
:
3650 case DW_CFA_val_offset
:
3651 reg
= LEB (); LEB ();
3652 frame_need_space (fc
, reg
);
3653 fc
->col_type
[reg
] = DW_CFA_undefined
;
3655 case DW_CFA_restore_extended
:
3657 frame_need_space (fc
, reg
);
3658 fc
->col_type
[reg
] = DW_CFA_undefined
;
3660 case DW_CFA_undefined
:
3662 frame_need_space (fc
, reg
);
3663 fc
->col_type
[reg
] = DW_CFA_undefined
;
3665 case DW_CFA_same_value
:
3667 frame_need_space (fc
, reg
);
3668 fc
->col_type
[reg
] = DW_CFA_undefined
;
3670 case DW_CFA_register
:
3671 reg
= LEB (); LEB ();
3672 frame_need_space (fc
, reg
);
3673 fc
->col_type
[reg
] = DW_CFA_undefined
;
3675 case DW_CFA_def_cfa
:
3678 case DW_CFA_def_cfa_register
:
3681 case DW_CFA_def_cfa_offset
:
3684 case DW_CFA_def_cfa_expression
:
3688 case DW_CFA_expression
:
3689 case DW_CFA_val_expression
:
3693 frame_need_space (fc
, reg
);
3694 fc
->col_type
[reg
] = DW_CFA_undefined
;
3696 case DW_CFA_offset_extended_sf
:
3697 case DW_CFA_val_offset_sf
:
3698 reg
= LEB (); SLEB ();
3699 frame_need_space (fc
, reg
);
3700 fc
->col_type
[reg
] = DW_CFA_undefined
;
3702 case DW_CFA_def_cfa_sf
:
3705 case DW_CFA_def_cfa_offset_sf
:
3708 case DW_CFA_MIPS_advance_loc8
:
3711 case DW_CFA_GNU_args_size
:
3714 case DW_CFA_GNU_negative_offset_extended
:
3715 reg
= LEB (); LEB ();
3716 frame_need_space (fc
, reg
);
3717 fc
->col_type
[reg
] = DW_CFA_undefined
;
3726 /* Now we know what registers are used, make a second pass over
3727 the chunk, this time actually printing out the info. */
3729 while (start
< block_end
)
3732 unsigned long ul
, reg
, roffs
;
3741 /* Warning: if you add any more cases to this switch, be
3742 sure to add them to the corresponding switch above. */
3745 case DW_CFA_advance_loc
:
3746 if (do_debug_frames_interp
)
3747 frame_display_row (fc
, &need_col_headers
, &max_regs
);
3749 printf (" DW_CFA_advance_loc: %d to %08lx\n",
3750 opa
* fc
->code_factor
,
3751 fc
->pc_begin
+ opa
* fc
->code_factor
);
3752 fc
->pc_begin
+= opa
* fc
->code_factor
;
3757 if (! do_debug_frames_interp
)
3758 printf (" DW_CFA_offset: %s at cfa%+ld\n",
3759 regname (opa
, 0), roffs
* fc
->data_factor
);
3760 fc
->col_type
[opa
] = DW_CFA_offset
;
3761 fc
->col_offset
[opa
] = roffs
* fc
->data_factor
;
3764 case DW_CFA_restore
:
3765 if (! do_debug_frames_interp
)
3766 printf (" DW_CFA_restore: %s\n", regname (opa
, 0));
3767 fc
->col_type
[opa
] = cie
->col_type
[opa
];
3768 fc
->col_offset
[opa
] = cie
->col_offset
[opa
];
3771 case DW_CFA_set_loc
:
3772 vma
= get_encoded_value (start
, fc
->fde_encoding
);
3773 if ((fc
->fde_encoding
& 0x70) == DW_EH_PE_pcrel
)
3774 vma
+= section
->address
+ (start
- section_start
);
3775 start
+= encoded_ptr_size
;
3776 if (do_debug_frames_interp
)
3777 frame_display_row (fc
, &need_col_headers
, &max_regs
);
3779 printf (" DW_CFA_set_loc: %08lx\n", (unsigned long)vma
);
3783 case DW_CFA_advance_loc1
:
3784 ofs
= byte_get (start
, 1); start
+= 1;
3785 if (do_debug_frames_interp
)
3786 frame_display_row (fc
, &need_col_headers
, &max_regs
);
3788 printf (" DW_CFA_advance_loc1: %ld to %08lx\n",
3789 ofs
* fc
->code_factor
,
3790 fc
->pc_begin
+ ofs
* fc
->code_factor
);
3791 fc
->pc_begin
+= ofs
* fc
->code_factor
;
3794 case DW_CFA_advance_loc2
:
3795 ofs
= byte_get (start
, 2); start
+= 2;
3796 if (do_debug_frames_interp
)
3797 frame_display_row (fc
, &need_col_headers
, &max_regs
);
3799 printf (" DW_CFA_advance_loc2: %ld to %08lx\n",
3800 ofs
* fc
->code_factor
,
3801 fc
->pc_begin
+ ofs
* fc
->code_factor
);
3802 fc
->pc_begin
+= ofs
* fc
->code_factor
;
3805 case DW_CFA_advance_loc4
:
3806 ofs
= byte_get (start
, 4); start
+= 4;
3807 if (do_debug_frames_interp
)
3808 frame_display_row (fc
, &need_col_headers
, &max_regs
);
3810 printf (" DW_CFA_advance_loc4: %ld to %08lx\n",
3811 ofs
* fc
->code_factor
,
3812 fc
->pc_begin
+ ofs
* fc
->code_factor
);
3813 fc
->pc_begin
+= ofs
* fc
->code_factor
;
3816 case DW_CFA_offset_extended
:
3819 if (! do_debug_frames_interp
)
3820 printf (" DW_CFA_offset_extended: %s at cfa%+ld\n",
3821 regname (reg
, 0), roffs
* fc
->data_factor
);
3822 fc
->col_type
[reg
] = DW_CFA_offset
;
3823 fc
->col_offset
[reg
] = roffs
* fc
->data_factor
;
3826 case DW_CFA_val_offset
:
3829 if (! do_debug_frames_interp
)
3830 printf (" DW_CFA_val_offset: %s at cfa%+ld\n",
3831 regname (reg
, 0), roffs
* fc
->data_factor
);
3832 fc
->col_type
[reg
] = DW_CFA_val_offset
;
3833 fc
->col_offset
[reg
] = roffs
* fc
->data_factor
;
3836 case DW_CFA_restore_extended
:
3838 if (! do_debug_frames_interp
)
3839 printf (" DW_CFA_restore_extended: %s\n",
3841 fc
->col_type
[reg
] = cie
->col_type
[reg
];
3842 fc
->col_offset
[reg
] = cie
->col_offset
[reg
];
3845 case DW_CFA_undefined
:
3847 if (! do_debug_frames_interp
)
3848 printf (" DW_CFA_undefined: %s\n", regname (reg
, 0));
3849 fc
->col_type
[reg
] = DW_CFA_undefined
;
3850 fc
->col_offset
[reg
] = 0;
3853 case DW_CFA_same_value
:
3855 if (! do_debug_frames_interp
)
3856 printf (" DW_CFA_same_value: %s\n", regname (reg
, 0));
3857 fc
->col_type
[reg
] = DW_CFA_same_value
;
3858 fc
->col_offset
[reg
] = 0;
3861 case DW_CFA_register
:
3864 if (! do_debug_frames_interp
)
3866 printf (" DW_CFA_register: %s in ",
3868 puts (regname (roffs
, 0));
3870 fc
->col_type
[reg
] = DW_CFA_register
;
3871 fc
->col_offset
[reg
] = roffs
;
3874 case DW_CFA_remember_state
:
3875 if (! do_debug_frames_interp
)
3876 printf (" DW_CFA_remember_state\n");
3877 rs
= xmalloc (sizeof (Frame_Chunk
));
3878 rs
->ncols
= fc
->ncols
;
3879 rs
->col_type
= xcmalloc (rs
->ncols
, sizeof (short int));
3880 rs
->col_offset
= xcmalloc (rs
->ncols
, sizeof (int));
3881 memcpy (rs
->col_type
, fc
->col_type
, rs
->ncols
);
3882 memcpy (rs
->col_offset
, fc
->col_offset
, rs
->ncols
* sizeof (int));
3883 rs
->next
= remembered_state
;
3884 remembered_state
= rs
;
3887 case DW_CFA_restore_state
:
3888 if (! do_debug_frames_interp
)
3889 printf (" DW_CFA_restore_state\n");
3890 rs
= remembered_state
;
3893 remembered_state
= rs
->next
;
3894 frame_need_space (fc
, rs
->ncols
- 1);
3895 memcpy (fc
->col_type
, rs
->col_type
, rs
->ncols
);
3896 memcpy (fc
->col_offset
, rs
->col_offset
,
3897 rs
->ncols
* sizeof (int));
3898 free (rs
->col_type
);
3899 free (rs
->col_offset
);
3902 else if (do_debug_frames_interp
)
3903 printf ("Mismatched DW_CFA_restore_state\n");
3906 case DW_CFA_def_cfa
:
3907 fc
->cfa_reg
= LEB ();
3908 fc
->cfa_offset
= LEB ();
3910 if (! do_debug_frames_interp
)
3911 printf (" DW_CFA_def_cfa: %s ofs %d\n",
3912 regname (fc
->cfa_reg
, 0), fc
->cfa_offset
);
3915 case DW_CFA_def_cfa_register
:
3916 fc
->cfa_reg
= LEB ();
3918 if (! do_debug_frames_interp
)
3919 printf (" DW_CFA_def_cfa_register: %s\n",
3920 regname (fc
->cfa_reg
, 0));
3923 case DW_CFA_def_cfa_offset
:
3924 fc
->cfa_offset
= LEB ();
3925 if (! do_debug_frames_interp
)
3926 printf (" DW_CFA_def_cfa_offset: %d\n", fc
->cfa_offset
);
3930 if (! do_debug_frames_interp
)
3931 printf (" DW_CFA_nop\n");
3934 case DW_CFA_def_cfa_expression
:
3936 if (! do_debug_frames_interp
)
3938 printf (" DW_CFA_def_cfa_expression (");
3939 decode_location_expression (start
, eh_addr_size
, ul
, 0);
3946 case DW_CFA_expression
:
3949 if (! do_debug_frames_interp
)
3951 printf (" DW_CFA_expression: %s (",
3953 decode_location_expression (start
, eh_addr_size
,
3957 fc
->col_type
[reg
] = DW_CFA_expression
;
3961 case DW_CFA_val_expression
:
3964 if (! do_debug_frames_interp
)
3966 printf (" DW_CFA_val_expression: %s (",
3968 decode_location_expression (start
, eh_addr_size
, ul
, 0);
3971 fc
->col_type
[reg
] = DW_CFA_val_expression
;
3975 case DW_CFA_offset_extended_sf
:
3978 frame_need_space (fc
, reg
);
3979 if (! do_debug_frames_interp
)
3980 printf (" DW_CFA_offset_extended_sf: %s at cfa%+ld\n",
3981 regname (reg
, 0), l
* fc
->data_factor
);
3982 fc
->col_type
[reg
] = DW_CFA_offset
;
3983 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
3986 case DW_CFA_val_offset_sf
:
3989 frame_need_space (fc
, reg
);
3990 if (! do_debug_frames_interp
)
3991 printf (" DW_CFA_val_offset_sf: %s at cfa%+ld\n",
3992 regname (reg
, 0), l
* fc
->data_factor
);
3993 fc
->col_type
[reg
] = DW_CFA_val_offset
;
3994 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
3997 case DW_CFA_def_cfa_sf
:
3998 fc
->cfa_reg
= LEB ();
3999 fc
->cfa_offset
= SLEB ();
4000 fc
->cfa_offset
= fc
->cfa_offset
* fc
->data_factor
;
4002 if (! do_debug_frames_interp
)
4003 printf (" DW_CFA_def_cfa_sf: %s ofs %d\n",
4004 regname (fc
->cfa_reg
, 0), fc
->cfa_offset
);
4007 case DW_CFA_def_cfa_offset_sf
:
4008 fc
->cfa_offset
= SLEB ();
4009 fc
->cfa_offset
= fc
->cfa_offset
* fc
->data_factor
;
4010 if (! do_debug_frames_interp
)
4011 printf (" DW_CFA_def_cfa_offset_sf: %d\n", fc
->cfa_offset
);
4014 case DW_CFA_MIPS_advance_loc8
:
4015 ofs
= byte_get (start
, 8); start
+= 8;
4016 if (do_debug_frames_interp
)
4017 frame_display_row (fc
, &need_col_headers
, &max_regs
);
4019 printf (" DW_CFA_MIPS_advance_loc8: %ld to %08lx\n",
4020 ofs
* fc
->code_factor
,
4021 fc
->pc_begin
+ ofs
* fc
->code_factor
);
4022 fc
->pc_begin
+= ofs
* fc
->code_factor
;
4025 case DW_CFA_GNU_window_save
:
4026 if (! do_debug_frames_interp
)
4027 printf (" DW_CFA_GNU_window_save\n");
4030 case DW_CFA_GNU_args_size
:
4032 if (! do_debug_frames_interp
)
4033 printf (" DW_CFA_GNU_args_size: %ld\n", ul
);
4036 case DW_CFA_GNU_negative_offset_extended
:
4039 frame_need_space (fc
, reg
);
4040 if (! do_debug_frames_interp
)
4041 printf (" DW_CFA_GNU_negative_offset_extended: %s at cfa%+ld\n",
4042 regname (reg
, 0), l
* fc
->data_factor
);
4043 fc
->col_type
[reg
] = DW_CFA_offset
;
4044 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
4048 if (op
>= DW_CFA_lo_user
&& op
<= DW_CFA_hi_user
)
4049 printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op
);
4051 warn (_("unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op
);
4056 if (do_debug_frames_interp
)
4057 frame_display_row (fc
, &need_col_headers
, &max_regs
);
4072 display_debug_not_supported (struct dwarf_section
*section
,
4073 void *file ATTRIBUTE_UNUSED
)
4075 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
4082 cmalloc (size_t nmemb
, size_t size
)
4084 /* Check for overflow. */
4085 if (nmemb
>= ~(size_t) 0 / size
)
4088 return malloc (nmemb
* size
);
4092 xcmalloc (size_t nmemb
, size_t size
)
4094 /* Check for overflow. */
4095 if (nmemb
>= ~(size_t) 0 / size
)
4098 return xmalloc (nmemb
* size
);
4102 xcrealloc (void *ptr
, size_t nmemb
, size_t size
)
4104 /* Check for overflow. */
4105 if (nmemb
>= ~(size_t) 0 / size
)
4108 return xrealloc (ptr
, nmemb
* size
);
4112 error (const char *message
, ...)
4116 va_start (args
, message
);
4117 fprintf (stderr
, _("%s: Error: "), program_name
);
4118 vfprintf (stderr
, message
, args
);
4123 warn (const char *message
, ...)
4127 va_start (args
, message
);
4128 fprintf (stderr
, _("%s: Warning: "), program_name
);
4129 vfprintf (stderr
, message
, args
);
4134 free_debug_memory (void)
4136 enum dwarf_section_display_enum i
;
4140 for (i
= 0; i
< max
; i
++)
4141 free_debug_section (i
);
4143 if (debug_information
!= NULL
)
4145 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
)
4147 for (i
= 0; i
< num_debug_info_entries
; i
++)
4149 if (!debug_information
[i
].max_loc_offsets
)
4151 free (debug_information
[i
].loc_offsets
);
4152 free (debug_information
[i
].have_frame_base
);
4154 if (!debug_information
[i
].max_range_lists
)
4155 free (debug_information
[i
].range_lists
);
4159 free (debug_information
);
4160 debug_information
= NULL
;
4161 num_debug_info_entries
= 0;
4165 struct dwarf_section_display debug_displays
[] =
4167 { { ".debug_abbrev", NULL
, 0, 0 },
4168 display_debug_abbrev
, 0, 0 },
4169 { { ".debug_aranges", NULL
, 0, 0 },
4170 display_debug_aranges
, 0, 0 },
4171 { { ".debug_frame", NULL
, 0, 0 },
4172 display_debug_frames
, 1, 0 },
4173 { { ".debug_info", NULL
, 0, 0 },
4174 display_debug_info
, 1, 0 },
4175 { { ".debug_line", NULL
, 0, 0 },
4176 display_debug_lines
, 0, 0 },
4177 { { ".debug_pubnames", NULL
, 0, 0 },
4178 display_debug_pubnames
, 0, 0 },
4179 { { ".eh_frame", NULL
, 0, 0 },
4180 display_debug_frames
, 1, 1 },
4181 { { ".debug_macinfo", NULL
, 0, 0 },
4182 display_debug_macinfo
, 0, 0 },
4183 { { ".debug_str", NULL
, 0, 0 },
4184 display_debug_str
, 0, 0 },
4185 { { ".debug_loc", NULL
, 0, 0 },
4186 display_debug_loc
, 0, 0 },
4187 { { ".debug_pubtypes", NULL
, 0, 0 },
4188 display_debug_pubnames
, 0, 0 },
4189 { { ".debug_ranges", NULL
, 0, 0 },
4190 display_debug_ranges
, 0, 0 },
4191 { { ".debug_static_func", NULL
, 0, 0 },
4192 display_debug_not_supported
, 0, 0 },
4193 { { ".debug_static_vars", NULL
, 0, 0 },
4194 display_debug_not_supported
, 0, 0 },
4195 { { ".debug_types", NULL
, 0, 0 },
4196 display_debug_not_supported
, 0, 0 },
4197 { { ".debug_weaknames", NULL
, 0, 0 },
4198 display_debug_not_supported
, 0, 0 }