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 ? */
1017 /* PGI (STMicroelectronics) extensions. */
1018 case DW_OP_PGI_omp_thread_num
:
1019 /* Pushes the thread number for the current thread as it would be
1020 returned by the standard OpenMP library function:
1021 omp_get_thread_num(). The "current thread" is the thread for
1022 which the expression is being evaluated. */
1023 printf ("DW_OP_PGI_omp_thread_num");
1027 if (op
>= DW_OP_lo_user
1028 && op
<= DW_OP_hi_user
)
1029 printf (_("(User defined location op)"));
1031 printf (_("(Unknown location op)"));
1032 /* No way to tell where the next op is, so just bail. */
1033 return need_frame_base
;
1036 /* Separate the ops. */
1041 return need_frame_base
;
1044 static unsigned char *
1045 read_and_display_attr_value (unsigned long attribute
,
1047 unsigned char * data
,
1048 unsigned long cu_offset
,
1049 unsigned long pointer_size
,
1050 unsigned long offset_size
,
1052 debug_info
* debug_info_p
,
1054 struct dwarf_section
* section
)
1056 unsigned long uvalue
= 0;
1057 unsigned char *block_start
= NULL
;
1058 unsigned char * orig_data
= data
;
1059 unsigned int bytes_read
;
1066 case DW_FORM_ref_addr
:
1067 if (dwarf_version
== 2)
1069 uvalue
= byte_get (data
, pointer_size
);
1070 data
+= pointer_size
;
1072 else if (dwarf_version
== 3)
1074 uvalue
= byte_get (data
, offset_size
);
1075 data
+= offset_size
;
1079 error (_("Internal error: DWARF version is not 2 or 3.\n"));
1084 uvalue
= byte_get (data
, pointer_size
);
1085 data
+= pointer_size
;
1089 uvalue
= byte_get (data
, offset_size
);
1090 data
+= offset_size
;
1096 uvalue
= byte_get (data
++, 1);
1101 uvalue
= byte_get (data
, 2);
1107 uvalue
= byte_get (data
, 4);
1112 uvalue
= read_leb128 (data
, & bytes_read
, 1);
1116 case DW_FORM_ref_udata
:
1118 uvalue
= read_leb128 (data
, & bytes_read
, 0);
1122 case DW_FORM_indirect
:
1123 form
= read_leb128 (data
, & bytes_read
, 0);
1126 printf (" %s", get_FORM_name (form
));
1127 return read_and_display_attr_value (attribute
, form
, data
,
1128 cu_offset
, pointer_size
,
1129 offset_size
, dwarf_version
,
1130 debug_info_p
, do_loc
,
1136 case DW_FORM_ref_addr
:
1138 printf (" <0x%lx>", uvalue
);
1144 case DW_FORM_ref_udata
:
1146 printf (" <0x%lx>", uvalue
+ cu_offset
);
1152 printf (" 0x%lx", uvalue
);
1161 printf (" %ld", uvalue
);
1168 uvalue
= byte_get (data
, 4);
1169 printf (" 0x%lx", uvalue
);
1170 printf (" 0x%lx", (unsigned long) byte_get (data
+ 4, 4));
1172 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
1173 && num_debug_info_entries
== 0)
1175 if (sizeof (uvalue
) == 8)
1176 uvalue
= byte_get (data
, 8);
1178 error (_("DW_FORM_data8 is unsupported when sizeof (unsigned long) != 8\n"));
1183 case DW_FORM_string
:
1185 printf (" %s", data
);
1186 data
+= strlen ((char *) data
) + 1;
1190 uvalue
= read_leb128 (data
, & bytes_read
, 0);
1191 block_start
= data
+ bytes_read
;
1193 data
= block_start
+ uvalue
;
1195 data
= display_block (block_start
, uvalue
);
1198 case DW_FORM_block1
:
1199 uvalue
= byte_get (data
, 1);
1200 block_start
= data
+ 1;
1202 data
= block_start
+ uvalue
;
1204 data
= display_block (block_start
, uvalue
);
1207 case DW_FORM_block2
:
1208 uvalue
= byte_get (data
, 2);
1209 block_start
= data
+ 2;
1211 data
= block_start
+ uvalue
;
1213 data
= display_block (block_start
, uvalue
);
1216 case DW_FORM_block4
:
1217 uvalue
= byte_get (data
, 4);
1218 block_start
= data
+ 4;
1220 data
= block_start
+ uvalue
;
1222 data
= display_block (block_start
, uvalue
);
1227 printf (_(" (indirect string, offset: 0x%lx): %s"),
1228 uvalue
, fetch_indirect_string (uvalue
));
1231 case DW_FORM_indirect
:
1232 /* Handled above. */
1236 warn (_("Unrecognized form: %lu\n"), form
);
1240 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
1241 && num_debug_info_entries
== 0)
1245 case DW_AT_frame_base
:
1246 have_frame_base
= 1;
1247 case DW_AT_location
:
1248 case DW_AT_string_length
:
1249 case DW_AT_return_addr
:
1250 case DW_AT_data_member_location
:
1251 case DW_AT_vtable_elem_location
:
1253 case DW_AT_static_link
:
1254 case DW_AT_use_location
:
1255 if (form
== DW_FORM_data4
|| form
== DW_FORM_data8
)
1257 /* Process location list. */
1258 unsigned int max
= debug_info_p
->max_loc_offsets
;
1259 unsigned int num
= debug_info_p
->num_loc_offsets
;
1261 if (max
== 0 || num
>= max
)
1264 debug_info_p
->loc_offsets
1265 = xcrealloc (debug_info_p
->loc_offsets
,
1266 max
, sizeof (*debug_info_p
->loc_offsets
));
1267 debug_info_p
->have_frame_base
1268 = xcrealloc (debug_info_p
->have_frame_base
,
1269 max
, sizeof (*debug_info_p
->have_frame_base
));
1270 debug_info_p
->max_loc_offsets
= max
;
1272 debug_info_p
->loc_offsets
[num
] = uvalue
;
1273 debug_info_p
->have_frame_base
[num
] = have_frame_base
;
1274 debug_info_p
->num_loc_offsets
++;
1279 if (need_base_address
)
1280 debug_info_p
->base_address
= uvalue
;
1284 if (form
== DW_FORM_data4
|| form
== DW_FORM_data8
)
1286 /* Process range list. */
1287 unsigned int max
= debug_info_p
->max_range_lists
;
1288 unsigned int num
= debug_info_p
->num_range_lists
;
1290 if (max
== 0 || num
>= max
)
1293 debug_info_p
->range_lists
1294 = xcrealloc (debug_info_p
->range_lists
,
1295 max
, sizeof (*debug_info_p
->range_lists
));
1296 debug_info_p
->max_range_lists
= max
;
1298 debug_info_p
->range_lists
[num
] = uvalue
;
1299 debug_info_p
->num_range_lists
++;
1311 /* For some attributes we can display further information. */
1319 case DW_INL_not_inlined
:
1320 printf (_("(not inlined)"));
1322 case DW_INL_inlined
:
1323 printf (_("(inlined)"));
1325 case DW_INL_declared_not_inlined
:
1326 printf (_("(declared as inline but ignored)"));
1328 case DW_INL_declared_inlined
:
1329 printf (_("(declared as inline and inlined)"));
1332 printf (_(" (Unknown inline attribute value: %lx)"), uvalue
);
1337 case DW_AT_language
:
1340 /* Ordered by the numeric value of these constants. */
1341 case DW_LANG_C89
: printf ("(ANSI C)"); break;
1342 case DW_LANG_C
: printf ("(non-ANSI C)"); break;
1343 case DW_LANG_Ada83
: printf ("(Ada)"); break;
1344 case DW_LANG_C_plus_plus
: printf ("(C++)"); break;
1345 case DW_LANG_Cobol74
: printf ("(Cobol 74)"); break;
1346 case DW_LANG_Cobol85
: printf ("(Cobol 85)"); break;
1347 case DW_LANG_Fortran77
: printf ("(FORTRAN 77)"); break;
1348 case DW_LANG_Fortran90
: printf ("(Fortran 90)"); break;
1349 case DW_LANG_Pascal83
: printf ("(ANSI Pascal)"); break;
1350 case DW_LANG_Modula2
: printf ("(Modula 2)"); break;
1351 /* DWARF 2.1 values. */
1352 case DW_LANG_Java
: printf ("(Java)"); break;
1353 case DW_LANG_C99
: printf ("(ANSI C99)"); break;
1354 case DW_LANG_Ada95
: printf ("(ADA 95)"); break;
1355 case DW_LANG_Fortran95
: printf ("(Fortran 95)"); break;
1356 /* DWARF 3 values. */
1357 case DW_LANG_PLI
: printf ("(PLI)"); break;
1358 case DW_LANG_ObjC
: printf ("(Objective C)"); break;
1359 case DW_LANG_ObjC_plus_plus
: printf ("(Objective C++)"); break;
1360 case DW_LANG_UPC
: printf ("(Unified Parallel C)"); break;
1361 case DW_LANG_D
: printf ("(D)"); break;
1362 /* MIPS extension. */
1363 case DW_LANG_Mips_Assembler
: printf ("(MIPS assembler)"); break;
1364 /* UPC extension. */
1365 case DW_LANG_Upc
: printf ("(Unified Parallel C)"); break;
1367 if (uvalue
>= DW_LANG_lo_user
&& uvalue
<= DW_LANG_hi_user
)
1368 printf ("(implementation defined: %lx)", uvalue
);
1370 printf ("(Unknown: %lx)", uvalue
);
1375 case DW_AT_encoding
:
1378 case DW_ATE_void
: printf ("(void)"); break;
1379 case DW_ATE_address
: printf ("(machine address)"); break;
1380 case DW_ATE_boolean
: printf ("(boolean)"); break;
1381 case DW_ATE_complex_float
: printf ("(complex float)"); break;
1382 case DW_ATE_float
: printf ("(float)"); break;
1383 case DW_ATE_signed
: printf ("(signed)"); break;
1384 case DW_ATE_signed_char
: printf ("(signed char)"); break;
1385 case DW_ATE_unsigned
: printf ("(unsigned)"); break;
1386 case DW_ATE_unsigned_char
: printf ("(unsigned char)"); break;
1387 /* DWARF 2.1 values: */
1388 case DW_ATE_imaginary_float
: printf ("(imaginary float)"); break;
1389 case DW_ATE_decimal_float
: printf ("(decimal float)"); break;
1390 /* DWARF 3 values: */
1391 case DW_ATE_packed_decimal
: printf ("(packed_decimal)"); break;
1392 case DW_ATE_numeric_string
: printf ("(numeric_string)"); break;
1393 case DW_ATE_edited
: printf ("(edited)"); break;
1394 case DW_ATE_signed_fixed
: printf ("(signed_fixed)"); break;
1395 case DW_ATE_unsigned_fixed
: printf ("(unsigned_fixed)"); break;
1396 /* HP extensions: */
1397 case DW_ATE_HP_float80
: printf ("(HP_float80)"); break;
1398 case DW_ATE_HP_complex_float80
: printf ("(HP_complex_float80)"); break;
1399 case DW_ATE_HP_float128
: printf ("(HP_float128)"); break;
1400 case DW_ATE_HP_complex_float128
:printf ("(HP_complex_float128)"); break;
1401 case DW_ATE_HP_floathpintel
: printf ("(HP_floathpintel)"); break;
1402 case DW_ATE_HP_imaginary_float80
: printf ("(HP_imaginary_float80)"); break;
1403 case DW_ATE_HP_imaginary_float128
: printf ("(HP_imaginary_float128)"); break;
1406 if (uvalue
>= DW_ATE_lo_user
1407 && uvalue
<= DW_ATE_hi_user
)
1408 printf ("(user defined type)");
1410 printf ("(unknown type)");
1415 case DW_AT_accessibility
:
1418 case DW_ACCESS_public
: printf ("(public)"); break;
1419 case DW_ACCESS_protected
: printf ("(protected)"); break;
1420 case DW_ACCESS_private
: printf ("(private)"); break;
1422 printf ("(unknown accessibility)");
1427 case DW_AT_visibility
:
1430 case DW_VIS_local
: printf ("(local)"); break;
1431 case DW_VIS_exported
: printf ("(exported)"); break;
1432 case DW_VIS_qualified
: printf ("(qualified)"); break;
1433 default: printf ("(unknown visibility)"); break;
1437 case DW_AT_virtuality
:
1440 case DW_VIRTUALITY_none
: printf ("(none)"); break;
1441 case DW_VIRTUALITY_virtual
: printf ("(virtual)"); break;
1442 case DW_VIRTUALITY_pure_virtual
:printf ("(pure_virtual)"); break;
1443 default: printf ("(unknown virtuality)"); break;
1447 case DW_AT_identifier_case
:
1450 case DW_ID_case_sensitive
: printf ("(case_sensitive)"); break;
1451 case DW_ID_up_case
: printf ("(up_case)"); break;
1452 case DW_ID_down_case
: printf ("(down_case)"); break;
1453 case DW_ID_case_insensitive
: printf ("(case_insensitive)"); break;
1454 default: printf ("(unknown case)"); break;
1458 case DW_AT_calling_convention
:
1461 case DW_CC_normal
: printf ("(normal)"); break;
1462 case DW_CC_program
: printf ("(program)"); break;
1463 case DW_CC_nocall
: printf ("(nocall)"); break;
1465 if (uvalue
>= DW_CC_lo_user
1466 && uvalue
<= DW_CC_hi_user
)
1467 printf ("(user defined)");
1469 printf ("(unknown convention)");
1473 case DW_AT_ordering
:
1476 case -1: printf ("(undefined)"); break;
1477 case 0: printf ("(row major)"); break;
1478 case 1: printf ("(column major)"); break;
1482 case DW_AT_frame_base
:
1483 have_frame_base
= 1;
1484 case DW_AT_location
:
1485 case DW_AT_string_length
:
1486 case DW_AT_return_addr
:
1487 case DW_AT_data_member_location
:
1488 case DW_AT_vtable_elem_location
:
1490 case DW_AT_static_link
:
1491 case DW_AT_use_location
:
1492 if (form
== DW_FORM_data4
|| form
== DW_FORM_data8
)
1493 printf (_("(location list)"));
1495 case DW_AT_allocated
:
1496 case DW_AT_associated
:
1497 case DW_AT_data_location
:
1499 case DW_AT_upper_bound
:
1500 case DW_AT_lower_bound
:
1503 int need_frame_base
;
1506 need_frame_base
= decode_location_expression (block_start
,
1511 if (need_frame_base
&& !have_frame_base
)
1512 printf (_(" [without DW_AT_frame_base]"));
1518 if (form
== DW_FORM_ref1
1519 || form
== DW_FORM_ref2
1520 || form
== DW_FORM_ref4
)
1521 uvalue
+= cu_offset
;
1523 if (uvalue
>= section
->size
)
1524 warn (_("Offset %lx used as value for DW_AT_import attribute of DIE at offset %lx is too big.\n"),
1525 uvalue
, (long int)(orig_data
- section
->start
));
1528 unsigned long abbrev_number
;
1529 abbrev_entry
* entry
;
1531 abbrev_number
= read_leb128 (section
->start
+ uvalue
, NULL
, 0);
1533 printf ("[Abbrev Number: %ld", abbrev_number
);
1534 for (entry
= first_abbrev
; entry
!= NULL
; entry
= entry
->next
)
1535 if (entry
->entry
== abbrev_number
)
1538 printf (" (%s)", get_TAG_name (entry
->tag
));
1552 get_AT_name (unsigned long attribute
)
1556 case DW_AT_sibling
: return "DW_AT_sibling";
1557 case DW_AT_location
: return "DW_AT_location";
1558 case DW_AT_name
: return "DW_AT_name";
1559 case DW_AT_ordering
: return "DW_AT_ordering";
1560 case DW_AT_subscr_data
: return "DW_AT_subscr_data";
1561 case DW_AT_byte_size
: return "DW_AT_byte_size";
1562 case DW_AT_bit_offset
: return "DW_AT_bit_offset";
1563 case DW_AT_bit_size
: return "DW_AT_bit_size";
1564 case DW_AT_element_list
: return "DW_AT_element_list";
1565 case DW_AT_stmt_list
: return "DW_AT_stmt_list";
1566 case DW_AT_low_pc
: return "DW_AT_low_pc";
1567 case DW_AT_high_pc
: return "DW_AT_high_pc";
1568 case DW_AT_language
: return "DW_AT_language";
1569 case DW_AT_member
: return "DW_AT_member";
1570 case DW_AT_discr
: return "DW_AT_discr";
1571 case DW_AT_discr_value
: return "DW_AT_discr_value";
1572 case DW_AT_visibility
: return "DW_AT_visibility";
1573 case DW_AT_import
: return "DW_AT_import";
1574 case DW_AT_string_length
: return "DW_AT_string_length";
1575 case DW_AT_common_reference
: return "DW_AT_common_reference";
1576 case DW_AT_comp_dir
: return "DW_AT_comp_dir";
1577 case DW_AT_const_value
: return "DW_AT_const_value";
1578 case DW_AT_containing_type
: return "DW_AT_containing_type";
1579 case DW_AT_default_value
: return "DW_AT_default_value";
1580 case DW_AT_inline
: return "DW_AT_inline";
1581 case DW_AT_is_optional
: return "DW_AT_is_optional";
1582 case DW_AT_lower_bound
: return "DW_AT_lower_bound";
1583 case DW_AT_producer
: return "DW_AT_producer";
1584 case DW_AT_prototyped
: return "DW_AT_prototyped";
1585 case DW_AT_return_addr
: return "DW_AT_return_addr";
1586 case DW_AT_start_scope
: return "DW_AT_start_scope";
1587 case DW_AT_stride_size
: return "DW_AT_stride_size";
1588 case DW_AT_upper_bound
: return "DW_AT_upper_bound";
1589 case DW_AT_abstract_origin
: return "DW_AT_abstract_origin";
1590 case DW_AT_accessibility
: return "DW_AT_accessibility";
1591 case DW_AT_address_class
: return "DW_AT_address_class";
1592 case DW_AT_artificial
: return "DW_AT_artificial";
1593 case DW_AT_base_types
: return "DW_AT_base_types";
1594 case DW_AT_calling_convention
: return "DW_AT_calling_convention";
1595 case DW_AT_count
: return "DW_AT_count";
1596 case DW_AT_data_member_location
: return "DW_AT_data_member_location";
1597 case DW_AT_decl_column
: return "DW_AT_decl_column";
1598 case DW_AT_decl_file
: return "DW_AT_decl_file";
1599 case DW_AT_decl_line
: return "DW_AT_decl_line";
1600 case DW_AT_declaration
: return "DW_AT_declaration";
1601 case DW_AT_discr_list
: return "DW_AT_discr_list";
1602 case DW_AT_encoding
: return "DW_AT_encoding";
1603 case DW_AT_external
: return "DW_AT_external";
1604 case DW_AT_frame_base
: return "DW_AT_frame_base";
1605 case DW_AT_friend
: return "DW_AT_friend";
1606 case DW_AT_identifier_case
: return "DW_AT_identifier_case";
1607 case DW_AT_macro_info
: return "DW_AT_macro_info";
1608 case DW_AT_namelist_items
: return "DW_AT_namelist_items";
1609 case DW_AT_priority
: return "DW_AT_priority";
1610 case DW_AT_segment
: return "DW_AT_segment";
1611 case DW_AT_specification
: return "DW_AT_specification";
1612 case DW_AT_static_link
: return "DW_AT_static_link";
1613 case DW_AT_type
: return "DW_AT_type";
1614 case DW_AT_use_location
: return "DW_AT_use_location";
1615 case DW_AT_variable_parameter
: return "DW_AT_variable_parameter";
1616 case DW_AT_virtuality
: return "DW_AT_virtuality";
1617 case DW_AT_vtable_elem_location
: return "DW_AT_vtable_elem_location";
1618 /* DWARF 2.1 values. */
1619 case DW_AT_allocated
: return "DW_AT_allocated";
1620 case DW_AT_associated
: return "DW_AT_associated";
1621 case DW_AT_data_location
: return "DW_AT_data_location";
1622 case DW_AT_stride
: return "DW_AT_stride";
1623 case DW_AT_entry_pc
: return "DW_AT_entry_pc";
1624 case DW_AT_use_UTF8
: return "DW_AT_use_UTF8";
1625 case DW_AT_extension
: return "DW_AT_extension";
1626 case DW_AT_ranges
: return "DW_AT_ranges";
1627 case DW_AT_trampoline
: return "DW_AT_trampoline";
1628 case DW_AT_call_column
: return "DW_AT_call_column";
1629 case DW_AT_call_file
: return "DW_AT_call_file";
1630 case DW_AT_call_line
: return "DW_AT_call_line";
1631 case DW_AT_description
: return "DW_AT_description";
1632 case DW_AT_binary_scale
: return "DW_AT_binary_scale";
1633 case DW_AT_decimal_scale
: return "DW_AT_decimal_scale";
1634 case DW_AT_small
: return "DW_AT_small";
1635 case DW_AT_decimal_sign
: return "DW_AT_decimal_sign";
1636 case DW_AT_digit_count
: return "DW_AT_digit_count";
1637 case DW_AT_picture_string
: return "DW_AT_picture_string";
1638 case DW_AT_mutable
: return "DW_AT_mutable";
1639 case DW_AT_threads_scaled
: return "DW_AT_threads_scaled";
1640 case DW_AT_explicit
: return "DW_AT_explicit";
1641 case DW_AT_object_pointer
: return "DW_AT_object_pointer";
1642 case DW_AT_endianity
: return "DW_AT_endianity";
1643 case DW_AT_elemental
: return "DW_AT_elemental";
1644 case DW_AT_pure
: return "DW_AT_pure";
1645 case DW_AT_recursive
: return "DW_AT_recursive";
1647 /* HP and SGI/MIPS extensions. */
1648 case DW_AT_MIPS_loop_begin
: return "DW_AT_MIPS_loop_begin";
1649 case DW_AT_MIPS_tail_loop_begin
: return "DW_AT_MIPS_tail_loop_begin";
1650 case DW_AT_MIPS_epilog_begin
: return "DW_AT_MIPS_epilog_begin";
1651 case DW_AT_MIPS_loop_unroll_factor
: return "DW_AT_MIPS_loop_unroll_factor";
1652 case DW_AT_MIPS_software_pipeline_depth
: return "DW_AT_MIPS_software_pipeline_depth";
1653 case DW_AT_MIPS_linkage_name
: return "DW_AT_MIPS_linkage_name";
1654 case DW_AT_MIPS_stride
: return "DW_AT_MIPS_stride";
1655 case DW_AT_MIPS_abstract_name
: return "DW_AT_MIPS_abstract_name";
1656 case DW_AT_MIPS_clone_origin
: return "DW_AT_MIPS_clone_origin";
1657 case DW_AT_MIPS_has_inlines
: return "DW_AT_MIPS_has_inlines";
1659 /* HP Extensions. */
1660 case DW_AT_HP_block_index
: return "DW_AT_HP_block_index";
1661 case DW_AT_HP_actuals_stmt_list
: return "DW_AT_HP_actuals_stmt_list";
1662 case DW_AT_HP_proc_per_section
: return "DW_AT_HP_proc_per_section";
1663 case DW_AT_HP_raw_data_ptr
: return "DW_AT_HP_raw_data_ptr";
1664 case DW_AT_HP_pass_by_reference
: return "DW_AT_HP_pass_by_reference";
1665 case DW_AT_HP_opt_level
: return "DW_AT_HP_opt_level";
1666 case DW_AT_HP_prof_version_id
: return "DW_AT_HP_prof_version_id";
1667 case DW_AT_HP_opt_flags
: return "DW_AT_HP_opt_flags";
1668 case DW_AT_HP_cold_region_low_pc
: return "DW_AT_HP_cold_region_low_pc";
1669 case DW_AT_HP_cold_region_high_pc
: return "DW_AT_HP_cold_region_high_pc";
1670 case DW_AT_HP_all_variables_modifiable
: return "DW_AT_HP_all_variables_modifiable";
1671 case DW_AT_HP_linkage_name
: return "DW_AT_HP_linkage_name";
1672 case DW_AT_HP_prof_flags
: return "DW_AT_HP_prof_flags";
1674 /* One value is shared by the MIPS and HP extensions: */
1675 case DW_AT_MIPS_fde
: return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable";
1677 /* GNU extensions. */
1678 case DW_AT_sf_names
: return "DW_AT_sf_names";
1679 case DW_AT_src_info
: return "DW_AT_src_info";
1680 case DW_AT_mac_info
: return "DW_AT_mac_info";
1681 case DW_AT_src_coords
: return "DW_AT_src_coords";
1682 case DW_AT_body_begin
: return "DW_AT_body_begin";
1683 case DW_AT_body_end
: return "DW_AT_body_end";
1684 case DW_AT_GNU_vector
: return "DW_AT_GNU_vector";
1686 /* UPC extension. */
1687 case DW_AT_upc_threads_scaled
: return "DW_AT_upc_threads_scaled";
1689 /* PGI (STMicroelectronics) extensions. */
1690 case DW_AT_PGI_lbase
: return "DW_AT_PGI_lbase";
1691 case DW_AT_PGI_soffset
: return "DW_AT_PGI_soffset";
1692 case DW_AT_PGI_lstride
: return "DW_AT_PGI_lstride";
1696 static char buffer
[100];
1698 snprintf (buffer
, sizeof (buffer
), _("Unknown AT value: %lx"),
1705 static unsigned char *
1706 read_and_display_attr (unsigned long attribute
,
1708 unsigned char * data
,
1709 unsigned long cu_offset
,
1710 unsigned long pointer_size
,
1711 unsigned long offset_size
,
1713 debug_info
* debug_info_p
,
1715 struct dwarf_section
* section
)
1718 printf (" %-18s:", get_AT_name (attribute
));
1719 data
= read_and_display_attr_value (attribute
, form
, data
, cu_offset
,
1720 pointer_size
, offset_size
,
1721 dwarf_version
, debug_info_p
,
1729 /* Process the contents of a .debug_info section. If do_loc is non-zero
1730 then we are scanning for location lists and we do not want to display
1731 anything to the user. */
1734 process_debug_info (struct dwarf_section
*section
,
1738 unsigned char *start
= section
->start
;
1739 unsigned char *end
= start
+ section
->size
;
1740 unsigned char *section_begin
;
1742 unsigned int num_units
= 0;
1744 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
1745 && num_debug_info_entries
== 0)
1747 unsigned long length
;
1749 /* First scan the section to get the number of comp units. */
1750 for (section_begin
= start
, num_units
= 0; section_begin
< end
;
1753 /* Read the first 4 bytes. For a 32-bit DWARF section, this
1754 will be the length. For a 64-bit DWARF section, it'll be
1755 the escape code 0xffffffff followed by an 8 byte length. */
1756 length
= byte_get (section_begin
, 4);
1758 if (length
== 0xffffffff)
1760 length
= byte_get (section_begin
+ 4, 8);
1761 section_begin
+= length
+ 12;
1763 else if (length
>= 0xfffffff0 && length
< 0xffffffff)
1765 warn (_("Reserved length value (%lx) found in section %s\n"), length
, section
->name
);
1769 section_begin
+= length
+ 4;
1771 /* Negative values are illegal, they may even cause infinite
1772 looping. This can happen if we can't accurately apply
1773 relocations to an object file. */
1774 if ((signed long) length
<= 0)
1776 warn (_("Corrupt unit length (%lx) found in section %s\n"), length
, section
->name
);
1783 error (_("No comp units in %s section ?"), section
->name
);
1787 /* Then allocate an array to hold the information. */
1788 debug_information
= cmalloc (num_units
,
1789 sizeof (* debug_information
));
1790 if (debug_information
== NULL
)
1792 error (_("Not enough memory for a debug info array of %u entries"),
1800 printf (_("The section %s contains:\n\n"), section
->name
);
1802 load_debug_section (str
, file
);
1805 load_debug_section (abbrev
, file
);
1806 if (debug_displays
[abbrev
].section
.start
== NULL
)
1808 warn (_("Unable to locate %s section!\n"),
1809 debug_displays
[abbrev
].section
.name
);
1813 for (section_begin
= start
, unit
= 0; start
< end
; unit
++)
1815 DWARF2_Internal_CompUnit compunit
;
1816 unsigned char *hdrptr
;
1817 unsigned char *cu_abbrev_offset_ptr
;
1818 unsigned char *tags
;
1820 unsigned long cu_offset
;
1822 int initial_length_size
;
1826 compunit
.cu_length
= byte_get (hdrptr
, 4);
1829 if (compunit
.cu_length
== 0xffffffff)
1831 compunit
.cu_length
= byte_get (hdrptr
, 8);
1834 initial_length_size
= 12;
1839 initial_length_size
= 4;
1842 compunit
.cu_version
= byte_get (hdrptr
, 2);
1845 cu_offset
= start
- section_begin
;
1847 cu_abbrev_offset_ptr
= hdrptr
;
1848 compunit
.cu_abbrev_offset
= byte_get (hdrptr
, offset_size
);
1849 hdrptr
+= offset_size
;
1851 compunit
.cu_pointer_size
= byte_get (hdrptr
, 1);
1853 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
1854 && num_debug_info_entries
== 0)
1856 debug_information
[unit
].cu_offset
= cu_offset
;
1857 debug_information
[unit
].pointer_size
1858 = compunit
.cu_pointer_size
;
1859 debug_information
[unit
].base_address
= 0;
1860 debug_information
[unit
].loc_offsets
= NULL
;
1861 debug_information
[unit
].have_frame_base
= NULL
;
1862 debug_information
[unit
].max_loc_offsets
= 0;
1863 debug_information
[unit
].num_loc_offsets
= 0;
1864 debug_information
[unit
].range_lists
= NULL
;
1865 debug_information
[unit
].max_range_lists
= 0;
1866 debug_information
[unit
].num_range_lists
= 0;
1871 printf (_(" Compilation Unit @ offset 0x%lx:\n"), cu_offset
);
1872 printf (_(" Length: 0x%lx (%s)\n"), compunit
.cu_length
,
1873 initial_length_size
== 8 ? "64-bit" : "32-bit");
1874 printf (_(" Version: %d\n"), compunit
.cu_version
);
1875 printf (_(" Abbrev Offset: %ld\n"), compunit
.cu_abbrev_offset
);
1876 printf (_(" Pointer Size: %d\n"), compunit
.cu_pointer_size
);
1879 if (cu_offset
+ compunit
.cu_length
+ initial_length_size
1882 warn (_("Debug info is corrupted, length of CU at %lx extends beyond end of section (length = %lx)\n"),
1883 cu_offset
, compunit
.cu_length
);
1887 start
+= compunit
.cu_length
+ initial_length_size
;
1889 if (compunit
.cu_version
!= 2 && compunit
.cu_version
!= 3)
1891 warn (_("CU at offset %lx contains corrupt or unsupported version number: %d.\n"),
1892 cu_offset
, compunit
.cu_version
);
1898 /* Process the abbrevs used by this compilation unit. DWARF
1899 sections under Mach-O have non-zero addresses. */
1900 if (compunit
.cu_abbrev_offset
>= debug_displays
[abbrev
].section
.size
)
1901 warn (_("Debug info is corrupted, abbrev offset (%lx) is larger than abbrev section size (%lx)\n"),
1902 (unsigned long) compunit
.cu_abbrev_offset
,
1903 (unsigned long) debug_displays
[abbrev
].section
.size
);
1905 process_abbrev_section
1906 ((unsigned char *) debug_displays
[abbrev
].section
.start
1907 + compunit
.cu_abbrev_offset
- debug_displays
[abbrev
].section
.address
,
1908 (unsigned char *) debug_displays
[abbrev
].section
.start
1909 + debug_displays
[abbrev
].section
.size
);
1912 while (tags
< start
)
1914 unsigned int bytes_read
;
1915 unsigned long abbrev_number
;
1916 unsigned long die_offset
;
1917 abbrev_entry
*entry
;
1920 die_offset
= tags
- section_begin
;
1922 abbrev_number
= read_leb128 (tags
, & bytes_read
, 0);
1925 /* A null DIE marks the end of a list of siblings. */
1926 if (abbrev_number
== 0)
1931 static unsigned num_bogus_warns
= 0;
1933 if (num_bogus_warns
< 3)
1935 warn (_("Bogus end-of-siblings marker detected at offset %lx in .debug_info section\n"),
1938 if (num_bogus_warns
== 3)
1939 warn (_("Further warnings about bogus end-of-sibling markers suppressed\n"));
1946 printf (_(" <%d><%lx>: Abbrev Number: %lu"),
1947 level
, die_offset
, abbrev_number
);
1949 /* Scan through the abbreviation list until we reach the
1951 for (entry
= first_abbrev
;
1952 entry
&& entry
->entry
!= abbrev_number
;
1953 entry
= entry
->next
)
1963 warn (_("DIE at offset %lx refers to abbreviation number %lu which does not exist\n"),
1964 die_offset
, abbrev_number
);
1969 printf (_(" (%s)\n"), get_TAG_name (entry
->tag
));
1974 need_base_address
= 0;
1976 case DW_TAG_compile_unit
:
1977 need_base_address
= 1;
1979 case DW_TAG_entry_point
:
1980 case DW_TAG_subprogram
:
1981 need_base_address
= 0;
1982 /* Assuming that there is no DW_AT_frame_base. */
1983 have_frame_base
= 0;
1987 for (attr
= entry
->first_attr
; attr
; attr
= attr
->next
)
1990 /* Show the offset from where the tag was extracted. */
1991 printf (" <%2lx>", (unsigned long)(tags
- section_begin
));
1993 tags
= read_and_display_attr (attr
->attribute
,
1996 compunit
.cu_pointer_size
,
1998 compunit
.cu_version
,
1999 debug_information
+ unit
,
2003 if (entry
->children
)
2008 /* Set num_debug_info_entries here so that it can be used to check if
2009 we need to process .debug_loc and .debug_ranges sections. */
2010 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
2011 && num_debug_info_entries
== 0)
2012 num_debug_info_entries
= num_units
;
2022 /* Locate and scan the .debug_info section in the file and record the pointer
2023 sizes and offsets for the compilation units in it. Usually an executable
2024 will have just one pointer size, but this is not guaranteed, and so we try
2025 not to make any assumptions. Returns zero upon failure, or the number of
2026 compilation units upon success. */
2029 load_debug_info (void * file
)
2031 /* Reset the last pointer size so that we can issue correct error
2032 messages if we are displaying the contents of more than one section. */
2033 last_pointer_size
= 0;
2034 warned_about_missing_comp_units
= FALSE
;
2036 /* If we have already tried and failed to load the .debug_info
2037 section then do not bother to repear the task. */
2038 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
2041 /* If we already have the information there is nothing else to do. */
2042 if (num_debug_info_entries
> 0)
2043 return num_debug_info_entries
;
2045 if (load_debug_section (info
, file
)
2046 && process_debug_info (&debug_displays
[info
].section
, file
, 1))
2047 return num_debug_info_entries
;
2049 num_debug_info_entries
= DEBUG_INFO_UNAVAILABLE
;
2054 display_debug_lines (struct dwarf_section
*section
, void *file
)
2056 unsigned char *start
= section
->start
;
2057 unsigned char *data
= start
;
2058 unsigned char *end
= start
+ section
->size
;
2060 printf (_("\nDump of debug contents of section %s:\n\n"),
2063 if (load_debug_info (file
) == 0)
2065 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
2072 DWARF2_Internal_LineInfo info
;
2073 unsigned char *standard_opcodes
;
2074 unsigned char *end_of_sequence
;
2075 unsigned char *hdrptr
;
2076 unsigned long hdroff
;
2077 int initial_length_size
;
2082 hdroff
= hdrptr
- start
;
2084 /* Check the length of the block. */
2085 info
.li_length
= byte_get (hdrptr
, 4);
2088 if (info
.li_length
== 0xffffffff)
2090 /* This section is 64-bit DWARF 3. */
2091 info
.li_length
= byte_get (hdrptr
, 8);
2094 initial_length_size
= 12;
2099 initial_length_size
= 4;
2102 if (info
.li_length
+ initial_length_size
> section
->size
)
2105 (_("The line info appears to be corrupt - the section is too small\n"));
2109 /* Check its version number. */
2110 info
.li_version
= byte_get (hdrptr
, 2);
2112 if (info
.li_version
!= 2 && info
.li_version
!= 3)
2114 warn (_("Only DWARF version 2 and 3 line info is currently supported.\n"));
2118 info
.li_prologue_length
= byte_get (hdrptr
, offset_size
);
2119 hdrptr
+= offset_size
;
2120 info
.li_min_insn_length
= byte_get (hdrptr
, 1);
2122 info
.li_default_is_stmt
= byte_get (hdrptr
, 1);
2124 info
.li_line_base
= byte_get (hdrptr
, 1);
2126 info
.li_line_range
= byte_get (hdrptr
, 1);
2128 info
.li_opcode_base
= byte_get (hdrptr
, 1);
2131 /* Sign extend the line base field. */
2132 info
.li_line_base
<<= 24;
2133 info
.li_line_base
>>= 24;
2135 printf (_(" Offset: 0x%lx\n"), hdroff
);
2136 printf (_(" Length: %ld\n"), info
.li_length
);
2137 printf (_(" DWARF Version: %d\n"), info
.li_version
);
2138 printf (_(" Prologue Length: %d\n"), info
.li_prologue_length
);
2139 printf (_(" Minimum Instruction Length: %d\n"), info
.li_min_insn_length
);
2140 printf (_(" Initial value of 'is_stmt': %d\n"), info
.li_default_is_stmt
);
2141 printf (_(" Line Base: %d\n"), info
.li_line_base
);
2142 printf (_(" Line Range: %d\n"), info
.li_line_range
);
2143 printf (_(" Opcode Base: %d\n"), info
.li_opcode_base
);
2145 end_of_sequence
= data
+ info
.li_length
+ initial_length_size
;
2147 reset_state_machine (info
.li_default_is_stmt
);
2149 /* Display the contents of the Opcodes table. */
2150 standard_opcodes
= hdrptr
;
2152 printf (_("\n Opcodes:\n"));
2154 for (i
= 1; i
< info
.li_opcode_base
; i
++)
2155 printf (_(" Opcode %d has %d args\n"), i
, standard_opcodes
[i
- 1]);
2157 /* Display the contents of the Directory table. */
2158 data
= standard_opcodes
+ info
.li_opcode_base
- 1;
2161 printf (_("\n The Directory Table is empty.\n"));
2164 printf (_("\n The Directory Table:\n"));
2168 printf (_(" %s\n"), data
);
2170 data
+= strlen ((char *) data
) + 1;
2174 /* Skip the NUL at the end of the table. */
2177 /* Display the contents of the File Name table. */
2179 printf (_("\n The File Name Table is empty.\n"));
2182 printf (_("\n The File Name Table:\n"));
2183 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
2187 unsigned char *name
;
2188 unsigned int bytes_read
;
2190 printf (_(" %d\t"), ++state_machine_regs
.last_file_entry
);
2193 data
+= strlen ((char *) data
) + 1;
2195 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
2197 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
2199 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
2201 printf (_("%s\n"), name
);
2205 /* Skip the NUL at the end of the table. */
2208 /* Now display the statements. */
2209 printf (_("\n Line Number Statements:\n"));
2211 while (data
< end_of_sequence
)
2213 unsigned char op_code
;
2215 unsigned long int uladv
;
2216 unsigned int bytes_read
;
2220 if (op_code
>= info
.li_opcode_base
)
2222 op_code
-= info
.li_opcode_base
;
2223 uladv
= (op_code
/ info
.li_line_range
) * info
.li_min_insn_length
;
2224 state_machine_regs
.address
+= uladv
;
2225 printf (_(" Special opcode %d: advance Address by %lu to 0x%lx"),
2226 op_code
, uladv
, state_machine_regs
.address
);
2227 adv
= (op_code
% info
.li_line_range
) + info
.li_line_base
;
2228 state_machine_regs
.line
+= adv
;
2229 printf (_(" and Line by %d to %d\n"),
2230 adv
, state_machine_regs
.line
);
2232 else switch (op_code
)
2234 case DW_LNS_extended_op
:
2235 data
+= process_extended_line_op (data
, info
.li_default_is_stmt
);
2239 printf (_(" Copy\n"));
2242 case DW_LNS_advance_pc
:
2243 uladv
= read_leb128 (data
, & bytes_read
, 0);
2244 uladv
*= info
.li_min_insn_length
;
2246 state_machine_regs
.address
+= uladv
;
2247 printf (_(" Advance PC by %lu to 0x%lx\n"), uladv
,
2248 state_machine_regs
.address
);
2251 case DW_LNS_advance_line
:
2252 adv
= read_leb128 (data
, & bytes_read
, 1);
2254 state_machine_regs
.line
+= adv
;
2255 printf (_(" Advance Line by %d to %d\n"), adv
,
2256 state_machine_regs
.line
);
2259 case DW_LNS_set_file
:
2260 adv
= read_leb128 (data
, & bytes_read
, 0);
2262 printf (_(" Set File Name to entry %d in the File Name Table\n"),
2264 state_machine_regs
.file
= adv
;
2267 case DW_LNS_set_column
:
2268 uladv
= read_leb128 (data
, & bytes_read
, 0);
2270 printf (_(" Set column to %lu\n"), uladv
);
2271 state_machine_regs
.column
= uladv
;
2274 case DW_LNS_negate_stmt
:
2275 adv
= state_machine_regs
.is_stmt
;
2277 printf (_(" Set is_stmt to %d\n"), adv
);
2278 state_machine_regs
.is_stmt
= adv
;
2281 case DW_LNS_set_basic_block
:
2282 printf (_(" Set basic block\n"));
2283 state_machine_regs
.basic_block
= 1;
2286 case DW_LNS_const_add_pc
:
2287 uladv
= (((255 - info
.li_opcode_base
) / info
.li_line_range
)
2288 * info
.li_min_insn_length
);
2289 state_machine_regs
.address
+= uladv
;
2290 printf (_(" Advance PC by constant %lu to 0x%lx\n"), uladv
,
2291 state_machine_regs
.address
);
2294 case DW_LNS_fixed_advance_pc
:
2295 uladv
= byte_get (data
, 2);
2297 state_machine_regs
.address
+= uladv
;
2298 printf (_(" Advance PC by fixed size amount %lu to 0x%lx\n"),
2299 uladv
, state_machine_regs
.address
);
2302 case DW_LNS_set_prologue_end
:
2303 printf (_(" Set prologue_end to true\n"));
2306 case DW_LNS_set_epilogue_begin
:
2307 printf (_(" Set epilogue_begin to true\n"));
2310 case DW_LNS_set_isa
:
2311 uladv
= read_leb128 (data
, & bytes_read
, 0);
2313 printf (_(" Set ISA to %lu\n"), uladv
);
2317 printf (_(" Unknown opcode %d with operands: "), op_code
);
2319 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
2321 printf ("0x%lx%s", read_leb128 (data
, &bytes_read
, 0),
2322 i
== 1 ? "" : ", ");
2336 find_debug_info_for_offset (unsigned long offset
)
2340 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
2343 for (i
= 0; i
< num_debug_info_entries
; i
++)
2344 if (debug_information
[i
].cu_offset
== offset
)
2345 return debug_information
+ i
;
2351 display_debug_pubnames (struct dwarf_section
*section
,
2352 void *file ATTRIBUTE_UNUSED
)
2354 DWARF2_Internal_PubNames pubnames
;
2355 unsigned char *start
= section
->start
;
2356 unsigned char *end
= start
+ section
->size
;
2358 /* It does not matter if this load fails,
2359 we test for that later on. */
2360 load_debug_info (file
);
2362 printf (_("Contents of the %s section:\n\n"), section
->name
);
2366 unsigned char *data
;
2367 unsigned long offset
;
2368 int offset_size
, initial_length_size
;
2372 pubnames
.pn_length
= byte_get (data
, 4);
2374 if (pubnames
.pn_length
== 0xffffffff)
2376 pubnames
.pn_length
= byte_get (data
, 8);
2379 initial_length_size
= 12;
2384 initial_length_size
= 4;
2387 pubnames
.pn_version
= byte_get (data
, 2);
2390 pubnames
.pn_offset
= byte_get (data
, offset_size
);
2391 data
+= offset_size
;
2393 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
2394 && num_debug_info_entries
> 0
2395 && find_debug_info_for_offset (pubnames
.pn_offset
) == NULL
)
2396 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
2397 pubnames
.pn_offset
, section
->name
);
2399 pubnames
.pn_size
= byte_get (data
, offset_size
);
2400 data
+= offset_size
;
2402 start
+= pubnames
.pn_length
+ initial_length_size
;
2404 if (pubnames
.pn_version
!= 2 && pubnames
.pn_version
!= 3)
2406 static int warned
= 0;
2410 warn (_("Only DWARF 2 and 3 pubnames are currently supported\n"));
2417 printf (_(" Length: %ld\n"),
2418 pubnames
.pn_length
);
2419 printf (_(" Version: %d\n"),
2420 pubnames
.pn_version
);
2421 printf (_(" Offset into .debug_info section: 0x%lx\n"),
2422 pubnames
.pn_offset
);
2423 printf (_(" Size of area in .debug_info section: %ld\n"),
2426 printf (_("\n Offset\tName\n"));
2430 offset
= byte_get (data
, offset_size
);
2434 data
+= offset_size
;
2435 printf (" %-6ld\t\t%s\n", offset
, data
);
2436 data
+= strlen ((char *) data
) + 1;
2439 while (offset
!= 0);
2447 display_debug_macinfo (struct dwarf_section
*section
,
2448 void *file ATTRIBUTE_UNUSED
)
2450 unsigned char *start
= section
->start
;
2451 unsigned char *end
= start
+ section
->size
;
2452 unsigned char *curr
= start
;
2453 unsigned int bytes_read
;
2454 enum dwarf_macinfo_record_type op
;
2456 printf (_("Contents of the %s section:\n\n"), section
->name
);
2460 unsigned int lineno
;
2468 case DW_MACINFO_start_file
:
2470 unsigned int filenum
;
2472 lineno
= read_leb128 (curr
, & bytes_read
, 0);
2474 filenum
= read_leb128 (curr
, & bytes_read
, 0);
2477 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"),
2482 case DW_MACINFO_end_file
:
2483 printf (_(" DW_MACINFO_end_file\n"));
2486 case DW_MACINFO_define
:
2487 lineno
= read_leb128 (curr
, & bytes_read
, 0);
2489 string
= (char *) curr
;
2490 curr
+= strlen (string
) + 1;
2491 printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"),
2495 case DW_MACINFO_undef
:
2496 lineno
= read_leb128 (curr
, & bytes_read
, 0);
2498 string
= (char *) curr
;
2499 curr
+= strlen (string
) + 1;
2500 printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"),
2504 case DW_MACINFO_vendor_ext
:
2506 unsigned int constant
;
2508 constant
= read_leb128 (curr
, & bytes_read
, 0);
2510 string
= (char *) curr
;
2511 curr
+= strlen (string
) + 1;
2512 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"),
2523 display_debug_abbrev (struct dwarf_section
*section
,
2524 void *file ATTRIBUTE_UNUSED
)
2526 abbrev_entry
*entry
;
2527 unsigned char *start
= section
->start
;
2528 unsigned char *end
= start
+ section
->size
;
2530 printf (_("Contents of the %s section:\n\n"), section
->name
);
2536 start
= process_abbrev_section (start
, end
);
2538 if (first_abbrev
== NULL
)
2541 printf (_(" Number TAG\n"));
2543 for (entry
= first_abbrev
; entry
; entry
= entry
->next
)
2547 printf (_(" %ld %s [%s]\n"),
2549 get_TAG_name (entry
->tag
),
2550 entry
->children
? _("has children") : _("no children"));
2552 for (attr
= entry
->first_attr
; attr
; attr
= attr
->next
)
2553 printf (_(" %-18s %s\n"),
2554 get_AT_name (attr
->attribute
),
2555 get_FORM_name (attr
->form
));
2566 display_debug_loc (struct dwarf_section
*section
, void *file
)
2568 unsigned char *start
= section
->start
;
2569 unsigned char *section_end
;
2570 unsigned long bytes
;
2571 unsigned char *section_begin
= start
;
2572 unsigned int num_loc_list
= 0;
2573 unsigned long last_offset
= 0;
2574 unsigned int first
= 0;
2577 int seen_first_offset
= 0;
2578 int use_debug_info
= 1;
2579 unsigned char *next
;
2581 bytes
= section
->size
;
2582 section_end
= start
+ bytes
;
2586 printf (_("\nThe %s section is empty.\n"), section
->name
);
2590 if (load_debug_info (file
) == 0)
2592 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
2597 /* Check the order of location list in .debug_info section. If
2598 offsets of location lists are in the ascending order, we can
2599 use `debug_information' directly. */
2600 for (i
= 0; i
< num_debug_info_entries
; i
++)
2604 num
= debug_information
[i
].num_loc_offsets
;
2605 num_loc_list
+= num
;
2607 /* Check if we can use `debug_information' directly. */
2608 if (use_debug_info
&& num
!= 0)
2610 if (!seen_first_offset
)
2612 /* This is the first location list. */
2613 last_offset
= debug_information
[i
].loc_offsets
[0];
2615 seen_first_offset
= 1;
2621 for (; j
< num
; j
++)
2624 debug_information
[i
].loc_offsets
[j
])
2629 last_offset
= debug_information
[i
].loc_offsets
[j
];
2634 if (!use_debug_info
)
2635 /* FIXME: Should we handle this case? */
2636 error (_("Location lists in .debug_info section aren't in ascending order!\n"));
2638 if (!seen_first_offset
)
2639 error (_("No location lists in .debug_info section!\n"));
2641 /* DWARF sections under Mach-O have non-zero addresses. */
2642 if (debug_information
[first
].num_loc_offsets
> 0
2643 && debug_information
[first
].loc_offsets
[0] != section
->address
)
2644 warn (_("Location lists in %s section start at 0x%lx\n"),
2645 section
->name
, debug_information
[first
].loc_offsets
[0]);
2647 printf (_("Contents of the %s section:\n\n"), section
->name
);
2648 printf (_(" Offset Begin End Expression\n"));
2650 seen_first_offset
= 0;
2651 for (i
= first
; i
< num_debug_info_entries
; i
++)
2655 unsigned short length
;
2656 unsigned long offset
;
2657 unsigned int pointer_size
;
2658 unsigned long cu_offset
;
2659 unsigned long base_address
;
2660 int need_frame_base
;
2663 pointer_size
= debug_information
[i
].pointer_size
;
2664 cu_offset
= debug_information
[i
].cu_offset
;
2666 for (j
= 0; j
< debug_information
[i
].num_loc_offsets
; j
++)
2668 has_frame_base
= debug_information
[i
].have_frame_base
[j
];
2669 /* DWARF sections under Mach-O have non-zero addresses. */
2670 offset
= debug_information
[i
].loc_offsets
[j
] - section
->address
;
2671 next
= section_begin
+ offset
;
2672 base_address
= debug_information
[i
].base_address
;
2674 if (!seen_first_offset
)
2675 seen_first_offset
= 1;
2679 warn (_("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n"),
2680 (long)(start
- section_begin
), (long)(next
- section_begin
));
2681 else if (start
> next
)
2682 warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n"),
2683 (long)(start
- section_begin
), (long)(next
- section_begin
));
2687 if (offset
>= bytes
)
2689 warn (_("Offset 0x%lx is bigger than .debug_loc section size.\n"),
2696 if (start
+ 2 * pointer_size
> section_end
)
2698 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
2703 /* Note: we use sign extension here in order to be sure that
2704 we can detect the -1 escape value. Sign extension into the
2705 top 32 bits of a 32-bit address will not affect the values
2706 that we display since we always show hex values, and always
2707 the bottom 32-bits. */
2708 begin
= byte_get_signed (start
, pointer_size
);
2709 start
+= pointer_size
;
2710 end
= byte_get_signed (start
, pointer_size
);
2711 start
+= pointer_size
;
2713 printf (" %8.8lx ", offset
);
2715 if (begin
== 0 && end
== 0)
2717 printf (_("<End of list>\n"));
2721 /* Check base address specifiers. */
2722 if (begin
== (dwarf_vma
) -1 && end
!= (dwarf_vma
) -1)
2725 print_dwarf_vma (begin
, pointer_size
);
2726 print_dwarf_vma (end
, pointer_size
);
2727 printf (_("(base address)\n"));
2731 if (start
+ 2 > section_end
)
2733 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
2738 length
= byte_get (start
, 2);
2741 if (start
+ length
> section_end
)
2743 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
2748 print_dwarf_vma (begin
+ base_address
, pointer_size
);
2749 print_dwarf_vma (end
+ base_address
, pointer_size
);
2752 need_frame_base
= decode_location_expression (start
,
2758 if (need_frame_base
&& !has_frame_base
)
2759 printf (_(" [without DW_AT_frame_base]"));
2762 fputs (_(" (start == end)"), stdout
);
2763 else if (begin
> end
)
2764 fputs (_(" (start > end)"), stdout
);
2773 if (start
< section_end
)
2774 warn (_("There are %ld unused bytes at the end of section %s\n"),
2775 (long) (section_end
- start
), section
->name
);
2780 display_debug_str (struct dwarf_section
*section
,
2781 void *file ATTRIBUTE_UNUSED
)
2783 unsigned char *start
= section
->start
;
2784 unsigned long bytes
= section
->size
;
2785 dwarf_vma addr
= section
->address
;
2789 printf (_("\nThe %s section is empty.\n"), section
->name
);
2793 printf (_("Contents of the %s section:\n\n"), section
->name
);
2801 lbytes
= (bytes
> 16 ? 16 : bytes
);
2803 printf (" 0x%8.8lx ", (unsigned long) addr
);
2805 for (j
= 0; j
< 16; j
++)
2808 printf ("%2.2x", start
[j
]);
2816 for (j
= 0; j
< lbytes
; j
++)
2819 if (k
>= ' ' && k
< 0x80)
2838 display_debug_info (struct dwarf_section
*section
, void *file
)
2840 return process_debug_info (section
, file
, 0);
2845 display_debug_aranges (struct dwarf_section
*section
,
2846 void *file ATTRIBUTE_UNUSED
)
2848 unsigned char *start
= section
->start
;
2849 unsigned char *end
= start
+ section
->size
;
2851 printf (_("The section %s contains:\n\n"), section
->name
);
2853 /* It does not matter if this load fails,
2854 we test for that later on. */
2855 load_debug_info (file
);
2859 unsigned char *hdrptr
;
2860 DWARF2_Internal_ARange arange
;
2861 unsigned char *ranges
;
2864 unsigned char address_size
;
2867 int initial_length_size
;
2871 arange
.ar_length
= byte_get (hdrptr
, 4);
2874 if (arange
.ar_length
== 0xffffffff)
2876 arange
.ar_length
= byte_get (hdrptr
, 8);
2879 initial_length_size
= 12;
2884 initial_length_size
= 4;
2887 arange
.ar_version
= byte_get (hdrptr
, 2);
2890 arange
.ar_info_offset
= byte_get (hdrptr
, offset_size
);
2891 hdrptr
+= offset_size
;
2893 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
2894 && num_debug_info_entries
> 0
2895 && find_debug_info_for_offset (arange
.ar_info_offset
) == NULL
)
2896 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
2897 arange
.ar_info_offset
, section
->name
);
2899 arange
.ar_pointer_size
= byte_get (hdrptr
, 1);
2902 arange
.ar_segment_size
= byte_get (hdrptr
, 1);
2905 if (arange
.ar_version
!= 2 && arange
.ar_version
!= 3)
2907 warn (_("Only DWARF 2 and 3 aranges are currently supported.\n"));
2911 printf (_(" Length: %ld\n"), arange
.ar_length
);
2912 printf (_(" Version: %d\n"), arange
.ar_version
);
2913 printf (_(" Offset into .debug_info: 0x%lx\n"), arange
.ar_info_offset
);
2914 printf (_(" Pointer Size: %d\n"), arange
.ar_pointer_size
);
2915 printf (_(" Segment Size: %d\n"), arange
.ar_segment_size
);
2917 address_size
= arange
.ar_pointer_size
+ arange
.ar_segment_size
;
2919 /* The DWARF spec does not require that the address size be a power
2920 of two, but we do. This will have to change if we ever encounter
2921 an uneven architecture. */
2922 if ((address_size
& (address_size
- 1)) != 0)
2924 warn (_("Pointer size + Segment size is not a power of two.\n"));
2928 if (address_size
> 4)
2929 printf (_("\n Address Length\n"));
2931 printf (_("\n Address Length\n"));
2935 /* Must pad to an alignment boundary that is twice the address size. */
2936 excess
= (hdrptr
- start
) % (2 * address_size
);
2938 ranges
+= (2 * address_size
) - excess
;
2940 start
+= arange
.ar_length
+ initial_length_size
;
2942 while (ranges
+ 2 * address_size
<= start
)
2944 address
= byte_get (ranges
, address_size
);
2946 ranges
+= address_size
;
2948 length
= byte_get (ranges
, address_size
);
2950 ranges
+= address_size
;
2952 print_dwarf_vma (address
, address_size
);
2953 print_dwarf_vma (length
, address_size
);
2964 display_debug_ranges (struct dwarf_section
*section
,
2965 void *file ATTRIBUTE_UNUSED
)
2967 unsigned char *start
= section
->start
;
2968 unsigned char *section_end
;
2969 unsigned long bytes
;
2970 unsigned char *section_begin
= start
;
2971 unsigned int num_range_list
= 0;
2972 unsigned long last_offset
= 0;
2973 unsigned int first
= 0;
2976 int seen_first_offset
= 0;
2977 int use_debug_info
= 1;
2978 unsigned char *next
;
2980 bytes
= section
->size
;
2981 section_end
= start
+ bytes
;
2985 printf (_("\nThe %s section is empty.\n"), section
->name
);
2989 if (load_debug_info (file
) == 0)
2991 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
2996 /* Check the order of range list in .debug_info section. If
2997 offsets of range lists are in the ascending order, we can
2998 use `debug_information' directly. */
2999 for (i
= 0; i
< num_debug_info_entries
; i
++)
3003 num
= debug_information
[i
].num_range_lists
;
3004 num_range_list
+= num
;
3006 /* Check if we can use `debug_information' directly. */
3007 if (use_debug_info
&& num
!= 0)
3009 if (!seen_first_offset
)
3011 /* This is the first range list. */
3012 last_offset
= debug_information
[i
].range_lists
[0];
3014 seen_first_offset
= 1;
3020 for (; j
< num
; j
++)
3023 debug_information
[i
].range_lists
[j
])
3028 last_offset
= debug_information
[i
].range_lists
[j
];
3033 if (!use_debug_info
)
3034 /* FIXME: Should we handle this case? */
3035 error (_("Range lists in .debug_info section aren't in ascending order!\n"));
3037 if (!seen_first_offset
)
3038 error (_("No range lists in .debug_info section!\n"));
3040 /* DWARF sections under Mach-O have non-zero addresses. */
3041 if (debug_information
[first
].num_range_lists
> 0
3042 && debug_information
[first
].range_lists
[0] != section
->address
)
3043 warn (_("Range lists in %s section start at 0x%lx\n"),
3044 section
->name
, debug_information
[first
].range_lists
[0]);
3046 printf (_("Contents of the %s section:\n\n"), section
->name
);
3047 printf (_(" Offset Begin End\n"));
3049 seen_first_offset
= 0;
3050 for (i
= first
; i
< num_debug_info_entries
; i
++)
3054 unsigned long offset
;
3055 unsigned int pointer_size
;
3056 unsigned long base_address
;
3058 pointer_size
= debug_information
[i
].pointer_size
;
3060 for (j
= 0; j
< debug_information
[i
].num_range_lists
; j
++)
3062 /* DWARF sections under Mach-O have non-zero addresses. */
3063 offset
= debug_information
[i
].range_lists
[j
] - section
->address
;
3064 next
= section_begin
+ offset
;
3065 base_address
= debug_information
[i
].base_address
;
3067 if (!seen_first_offset
)
3068 seen_first_offset
= 1;
3072 warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"),
3073 (long)(start
- section_begin
),
3074 (long)(next
- section_begin
), section
->name
);
3075 else if (start
> next
)
3076 warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"),
3077 (long)(start
- section_begin
),
3078 (long)(next
- section_begin
), section
->name
);
3084 /* Note: we use sign extension here in order to be sure that
3085 we can detect the -1 escape value. Sign extension into the
3086 top 32 bits of a 32-bit address will not affect the values
3087 that we display since we always show hex values, and always
3088 the bottom 32-bits. */
3089 begin
= byte_get_signed (start
, pointer_size
);
3090 start
+= pointer_size
;
3091 end
= byte_get_signed (start
, pointer_size
);
3092 start
+= pointer_size
;
3094 printf (" %8.8lx ", offset
);
3096 if (begin
== 0 && end
== 0)
3098 printf (_("<End of list>\n"));
3102 print_dwarf_vma (begin
, pointer_size
);
3103 print_dwarf_vma (end
, pointer_size
);
3105 /* Check base address specifiers. */
3106 if (begin
== (dwarf_vma
) -1 && end
!= (dwarf_vma
) -1)
3109 printf ("(base address)\n");
3114 fputs (_("(start == end)"), stdout
);
3115 else if (begin
> end
)
3116 fputs (_("(start > end)"), stdout
);
3126 typedef struct Frame_Chunk
3128 struct Frame_Chunk
*next
;
3129 unsigned char *chunk_start
;
3131 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
3132 short int *col_type
;
3135 unsigned int code_factor
;
3137 unsigned long pc_begin
;
3138 unsigned long pc_range
;
3142 unsigned char fde_encoding
;
3143 unsigned char cfa_exp
;
3147 /* A marker for a col_type that means this column was never referenced
3148 in the frame info. */
3149 #define DW_CFA_unreferenced (-1)
3152 frame_need_space (Frame_Chunk
*fc
, int reg
)
3154 int prev
= fc
->ncols
;
3156 if (reg
< fc
->ncols
)
3159 fc
->ncols
= reg
+ 1;
3160 fc
->col_type
= xcrealloc (fc
->col_type
, fc
->ncols
, sizeof (short int));
3161 fc
->col_offset
= xcrealloc (fc
->col_offset
, fc
->ncols
, sizeof (int));
3163 while (prev
< fc
->ncols
)
3165 fc
->col_type
[prev
] = DW_CFA_unreferenced
;
3166 fc
->col_offset
[prev
] = 0;
3171 static const char *const dwarf_regnames_i386
[] =
3173 "eax", "ecx", "edx", "ebx",
3174 "esp", "ebp", "esi", "edi",
3175 "eip", "eflags", NULL
,
3176 "st0", "st1", "st2", "st3",
3177 "st4", "st5", "st6", "st7",
3179 "xmm0", "xmm1", "xmm2", "xmm3",
3180 "xmm4", "xmm5", "xmm6", "xmm7",
3181 "mm0", "mm1", "mm2", "mm3",
3182 "mm4", "mm5", "mm6", "mm7",
3183 "fcw", "fsw", "mxcsr",
3184 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
,
3188 static const char *const dwarf_regnames_x86_64
[] =
3190 "rax", "rdx", "rcx", "rbx",
3191 "rsi", "rdi", "rbp", "rsp",
3192 "r8", "r9", "r10", "r11",
3193 "r12", "r13", "r14", "r15",
3195 "xmm0", "xmm1", "xmm2", "xmm3",
3196 "xmm4", "xmm5", "xmm6", "xmm7",
3197 "xmm8", "xmm9", "xmm10", "xmm11",
3198 "xmm12", "xmm13", "xmm14", "xmm15",
3199 "st0", "st1", "st2", "st3",
3200 "st4", "st5", "st6", "st7",
3201 "mm0", "mm1", "mm2", "mm3",
3202 "mm4", "mm5", "mm6", "mm7",
3204 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
,
3205 "fs.base", "gs.base", NULL
, NULL
,
3207 "mxcsr", "fcw", "fsw"
3210 static const char *const *dwarf_regnames
;
3211 static unsigned int dwarf_regnames_count
;
3214 init_dwarf_regnames (unsigned int e_machine
)
3220 dwarf_regnames
= dwarf_regnames_i386
;
3221 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_i386
);
3225 dwarf_regnames
= dwarf_regnames_x86_64
;
3226 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_x86_64
);
3235 regname (unsigned int regno
, int row
)
3237 static char reg
[64];
3239 && regno
< dwarf_regnames_count
3240 && dwarf_regnames
[regno
] != NULL
)
3243 return dwarf_regnames
[regno
];
3244 snprintf (reg
, sizeof (reg
), "r%d (%s)", regno
,
3245 dwarf_regnames
[regno
]);
3248 snprintf (reg
, sizeof (reg
), "r%d", regno
);
3253 frame_display_row (Frame_Chunk
*fc
, int *need_col_headers
, int *max_regs
)
3258 if (*max_regs
< fc
->ncols
)
3259 *max_regs
= fc
->ncols
;
3261 if (*need_col_headers
)
3263 static const char *loc
= " LOC";
3265 *need_col_headers
= 0;
3267 printf ("%-*s CFA ", eh_addr_size
* 2, loc
);
3269 for (r
= 0; r
< *max_regs
; r
++)
3270 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
3275 printf ("%-5s ", regname (r
, 1));
3281 printf ("%0*lx ", eh_addr_size
* 2, fc
->pc_begin
);
3283 strcpy (tmp
, "exp");
3285 sprintf (tmp
, "%s%+d", regname (fc
->cfa_reg
, 1), fc
->cfa_offset
);
3286 printf ("%-8s ", tmp
);
3288 for (r
= 0; r
< fc
->ncols
; r
++)
3290 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
3292 switch (fc
->col_type
[r
])
3294 case DW_CFA_undefined
:
3297 case DW_CFA_same_value
:
3301 sprintf (tmp
, "c%+d", fc
->col_offset
[r
]);
3303 case DW_CFA_val_offset
:
3304 sprintf (tmp
, "v%+d", fc
->col_offset
[r
]);
3306 case DW_CFA_register
:
3307 sprintf (tmp
, "%s", regname (fc
->col_offset
[r
], 0));
3309 case DW_CFA_expression
:
3310 strcpy (tmp
, "exp");
3312 case DW_CFA_val_expression
:
3313 strcpy (tmp
, "vexp");
3316 strcpy (tmp
, "n/a");
3319 printf ("%-5s ", tmp
);
3326 size_of_encoded_value (int encoding
)
3328 switch (encoding
& 0x7)
3331 case 0: return eh_addr_size
;
3339 get_encoded_value (unsigned char *data
, int encoding
)
3341 int size
= size_of_encoded_value (encoding
);
3343 if (encoding
& DW_EH_PE_signed
)
3344 return byte_get_signed (data
, size
);
3346 return byte_get (data
, size
);
3349 #define GET(N) byte_get (start, N); start += N
3350 #define LEB() read_leb128 (start, & length_return, 0); start += length_return
3351 #define SLEB() read_leb128 (start, & length_return, 1); start += length_return
3354 display_debug_frames (struct dwarf_section
*section
,
3355 void *file ATTRIBUTE_UNUSED
)
3357 unsigned char *start
= section
->start
;
3358 unsigned char *end
= start
+ section
->size
;
3359 unsigned char *section_start
= start
;
3360 Frame_Chunk
*chunks
= 0;
3361 Frame_Chunk
*remembered_state
= 0;
3363 int is_eh
= strcmp (section
->name
, ".eh_frame") == 0;
3364 unsigned int length_return
;
3367 printf (_("The section %s contains:\n"), section
->name
);
3371 unsigned char *saved_start
;
3372 unsigned char *block_end
;
3373 unsigned long length
;
3374 unsigned long cie_id
;
3377 int need_col_headers
= 1;
3378 unsigned char *augmentation_data
= NULL
;
3379 unsigned long augmentation_data_len
= 0;
3380 int encoded_ptr_size
= eh_addr_size
;
3382 int initial_length_size
;
3384 saved_start
= start
;
3385 length
= byte_get (start
, 4); start
+= 4;
3389 printf ("\n%08lx ZERO terminator\n\n",
3390 (unsigned long)(saved_start
- section_start
));
3394 if (length
== 0xffffffff)
3396 length
= byte_get (start
, 8);
3399 initial_length_size
= 12;
3404 initial_length_size
= 4;
3407 block_end
= saved_start
+ length
+ initial_length_size
;
3408 if (block_end
> end
)
3410 warn ("Invalid length %#08lx in FDE at %#08lx\n",
3411 length
, (unsigned long)(saved_start
- section_start
));
3414 cie_id
= byte_get (start
, offset_size
); start
+= offset_size
;
3416 if (is_eh
? (cie_id
== 0) : (cie_id
== DW_CIE_ID
))
3420 fc
= xmalloc (sizeof (Frame_Chunk
));
3421 memset (fc
, 0, sizeof (Frame_Chunk
));
3425 fc
->chunk_start
= saved_start
;
3427 fc
->col_type
= xmalloc (sizeof (short int));
3428 fc
->col_offset
= xmalloc (sizeof (int));
3429 frame_need_space (fc
, max_regs
- 1);
3433 fc
->augmentation
= (char *) start
;
3434 start
= (unsigned char *) strchr ((char *) start
, '\0') + 1;
3436 if (fc
->augmentation
[0] == 'z')
3438 fc
->code_factor
= LEB ();
3439 fc
->data_factor
= SLEB ();
3448 augmentation_data_len
= LEB ();
3449 augmentation_data
= start
;
3450 start
+= augmentation_data_len
;
3452 else if (strcmp (fc
->augmentation
, "eh") == 0)
3454 start
+= eh_addr_size
;
3455 fc
->code_factor
= LEB ();
3456 fc
->data_factor
= SLEB ();
3468 fc
->code_factor
= LEB ();
3469 fc
->data_factor
= SLEB ();
3481 if (do_debug_frames_interp
)
3482 printf ("\n%08lx %08lx %08lx CIE \"%s\" cf=%d df=%d ra=%d\n",
3483 (unsigned long)(saved_start
- section_start
), length
, cie_id
,
3484 fc
->augmentation
, fc
->code_factor
, fc
->data_factor
,
3488 printf ("\n%08lx %08lx %08lx CIE\n",
3489 (unsigned long)(saved_start
- section_start
), length
, cie_id
);
3490 printf (" Version: %d\n", version
);
3491 printf (" Augmentation: \"%s\"\n", fc
->augmentation
);
3492 printf (" Code alignment factor: %u\n", fc
->code_factor
);
3493 printf (" Data alignment factor: %d\n", fc
->data_factor
);
3494 printf (" Return address column: %d\n", fc
->ra
);
3496 if (augmentation_data_len
)
3499 printf (" Augmentation data: ");
3500 for (i
= 0; i
< augmentation_data_len
; ++i
)
3501 printf (" %02x", augmentation_data
[i
]);
3507 if (augmentation_data_len
)
3509 unsigned char *p
, *q
;
3510 p
= (unsigned char *) fc
->augmentation
+ 1;
3511 q
= augmentation_data
;
3518 q
+= 1 + size_of_encoded_value (*q
);
3520 fc
->fde_encoding
= *q
++;
3526 if (fc
->fde_encoding
)
3527 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
3530 frame_need_space (fc
, fc
->ra
);
3534 unsigned char *look_for
;
3535 static Frame_Chunk fde_fc
;
3538 memset (fc
, 0, sizeof (Frame_Chunk
));
3540 look_for
= is_eh
? start
- 4 - cie_id
: section_start
+ cie_id
;
3542 for (cie
= chunks
; cie
; cie
= cie
->next
)
3543 if (cie
->chunk_start
== look_for
)
3548 warn ("Invalid CIE pointer %#08lx in FDE at %#08lx\n",
3549 cie_id
, (unsigned long)(saved_start
- section_start
));
3551 fc
->col_type
= xmalloc (sizeof (short int));
3552 fc
->col_offset
= xmalloc (sizeof (int));
3553 frame_need_space (fc
, max_regs
- 1);
3555 fc
->augmentation
= "";
3556 fc
->fde_encoding
= 0;
3560 fc
->ncols
= cie
->ncols
;
3561 fc
->col_type
= xcmalloc (fc
->ncols
, sizeof (short int));
3562 fc
->col_offset
= xcmalloc (fc
->ncols
, sizeof (int));
3563 memcpy (fc
->col_type
, cie
->col_type
, fc
->ncols
* sizeof (short int));
3564 memcpy (fc
->col_offset
, cie
->col_offset
, fc
->ncols
* sizeof (int));
3565 fc
->augmentation
= cie
->augmentation
;
3566 fc
->code_factor
= cie
->code_factor
;
3567 fc
->data_factor
= cie
->data_factor
;
3568 fc
->cfa_reg
= cie
->cfa_reg
;
3569 fc
->cfa_offset
= cie
->cfa_offset
;
3571 frame_need_space (fc
, max_regs
- 1);
3572 fc
->fde_encoding
= cie
->fde_encoding
;
3575 if (fc
->fde_encoding
)
3576 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
3578 fc
->pc_begin
= get_encoded_value (start
, fc
->fde_encoding
);
3579 if ((fc
->fde_encoding
& 0x70) == DW_EH_PE_pcrel
)
3580 fc
->pc_begin
+= section
->address
+ (start
- section_start
);
3581 start
+= encoded_ptr_size
;
3582 fc
->pc_range
= byte_get (start
, encoded_ptr_size
);
3583 start
+= encoded_ptr_size
;
3585 if (cie
->augmentation
[0] == 'z')
3587 augmentation_data_len
= LEB ();
3588 augmentation_data
= start
;
3589 start
+= augmentation_data_len
;
3592 printf ("\n%08lx %08lx %08lx FDE cie=%08lx pc=%08lx..%08lx\n",
3593 (unsigned long)(saved_start
- section_start
), length
, cie_id
,
3594 (unsigned long)(cie
->chunk_start
- section_start
),
3595 fc
->pc_begin
, fc
->pc_begin
+ fc
->pc_range
);
3596 if (! do_debug_frames_interp
&& augmentation_data_len
)
3600 printf (" Augmentation data: ");
3601 for (i
= 0; i
< augmentation_data_len
; ++i
)
3602 printf (" %02x", augmentation_data
[i
]);
3608 /* At this point, fc is the current chunk, cie (if any) is set, and
3609 we're about to interpret instructions for the chunk. */
3610 /* ??? At present we need to do this always, since this sizes the
3611 fc->col_type and fc->col_offset arrays, which we write into always.
3612 We should probably split the interpreted and non-interpreted bits
3613 into two different routines, since there's so much that doesn't
3614 really overlap between them. */
3615 if (1 || do_debug_frames_interp
)
3617 /* Start by making a pass over the chunk, allocating storage
3618 and taking note of what registers are used. */
3619 unsigned char *tmp
= start
;
3621 while (start
< block_end
)
3624 unsigned long reg
, tmp
;
3631 /* Warning: if you add any more cases to this switch, be
3632 sure to add them to the corresponding switch below. */
3635 case DW_CFA_advance_loc
:
3639 frame_need_space (fc
, opa
);
3640 fc
->col_type
[opa
] = DW_CFA_undefined
;
3642 case DW_CFA_restore
:
3643 frame_need_space (fc
, opa
);
3644 fc
->col_type
[opa
] = DW_CFA_undefined
;
3646 case DW_CFA_set_loc
:
3647 start
+= encoded_ptr_size
;
3649 case DW_CFA_advance_loc1
:
3652 case DW_CFA_advance_loc2
:
3655 case DW_CFA_advance_loc4
:
3658 case DW_CFA_offset_extended
:
3659 case DW_CFA_val_offset
:
3660 reg
= LEB (); LEB ();
3661 frame_need_space (fc
, reg
);
3662 fc
->col_type
[reg
] = DW_CFA_undefined
;
3664 case DW_CFA_restore_extended
:
3666 frame_need_space (fc
, reg
);
3667 fc
->col_type
[reg
] = DW_CFA_undefined
;
3669 case DW_CFA_undefined
:
3671 frame_need_space (fc
, reg
);
3672 fc
->col_type
[reg
] = DW_CFA_undefined
;
3674 case DW_CFA_same_value
:
3676 frame_need_space (fc
, reg
);
3677 fc
->col_type
[reg
] = DW_CFA_undefined
;
3679 case DW_CFA_register
:
3680 reg
= LEB (); LEB ();
3681 frame_need_space (fc
, reg
);
3682 fc
->col_type
[reg
] = DW_CFA_undefined
;
3684 case DW_CFA_def_cfa
:
3687 case DW_CFA_def_cfa_register
:
3690 case DW_CFA_def_cfa_offset
:
3693 case DW_CFA_def_cfa_expression
:
3697 case DW_CFA_expression
:
3698 case DW_CFA_val_expression
:
3702 frame_need_space (fc
, reg
);
3703 fc
->col_type
[reg
] = DW_CFA_undefined
;
3705 case DW_CFA_offset_extended_sf
:
3706 case DW_CFA_val_offset_sf
:
3707 reg
= LEB (); SLEB ();
3708 frame_need_space (fc
, reg
);
3709 fc
->col_type
[reg
] = DW_CFA_undefined
;
3711 case DW_CFA_def_cfa_sf
:
3714 case DW_CFA_def_cfa_offset_sf
:
3717 case DW_CFA_MIPS_advance_loc8
:
3720 case DW_CFA_GNU_args_size
:
3723 case DW_CFA_GNU_negative_offset_extended
:
3724 reg
= LEB (); LEB ();
3725 frame_need_space (fc
, reg
);
3726 fc
->col_type
[reg
] = DW_CFA_undefined
;
3735 /* Now we know what registers are used, make a second pass over
3736 the chunk, this time actually printing out the info. */
3738 while (start
< block_end
)
3741 unsigned long ul
, reg
, roffs
;
3750 /* Warning: if you add any more cases to this switch, be
3751 sure to add them to the corresponding switch above. */
3754 case DW_CFA_advance_loc
:
3755 if (do_debug_frames_interp
)
3756 frame_display_row (fc
, &need_col_headers
, &max_regs
);
3758 printf (" DW_CFA_advance_loc: %d to %08lx\n",
3759 opa
* fc
->code_factor
,
3760 fc
->pc_begin
+ opa
* fc
->code_factor
);
3761 fc
->pc_begin
+= opa
* fc
->code_factor
;
3766 if (! do_debug_frames_interp
)
3767 printf (" DW_CFA_offset: %s at cfa%+ld\n",
3768 regname (opa
, 0), roffs
* fc
->data_factor
);
3769 fc
->col_type
[opa
] = DW_CFA_offset
;
3770 fc
->col_offset
[opa
] = roffs
* fc
->data_factor
;
3773 case DW_CFA_restore
:
3774 if (! do_debug_frames_interp
)
3775 printf (" DW_CFA_restore: %s\n", regname (opa
, 0));
3776 fc
->col_type
[opa
] = cie
->col_type
[opa
];
3777 fc
->col_offset
[opa
] = cie
->col_offset
[opa
];
3780 case DW_CFA_set_loc
:
3781 vma
= get_encoded_value (start
, fc
->fde_encoding
);
3782 if ((fc
->fde_encoding
& 0x70) == DW_EH_PE_pcrel
)
3783 vma
+= section
->address
+ (start
- section_start
);
3784 start
+= encoded_ptr_size
;
3785 if (do_debug_frames_interp
)
3786 frame_display_row (fc
, &need_col_headers
, &max_regs
);
3788 printf (" DW_CFA_set_loc: %08lx\n", (unsigned long)vma
);
3792 case DW_CFA_advance_loc1
:
3793 ofs
= byte_get (start
, 1); start
+= 1;
3794 if (do_debug_frames_interp
)
3795 frame_display_row (fc
, &need_col_headers
, &max_regs
);
3797 printf (" DW_CFA_advance_loc1: %ld to %08lx\n",
3798 ofs
* fc
->code_factor
,
3799 fc
->pc_begin
+ ofs
* fc
->code_factor
);
3800 fc
->pc_begin
+= ofs
* fc
->code_factor
;
3803 case DW_CFA_advance_loc2
:
3804 ofs
= byte_get (start
, 2); start
+= 2;
3805 if (do_debug_frames_interp
)
3806 frame_display_row (fc
, &need_col_headers
, &max_regs
);
3808 printf (" DW_CFA_advance_loc2: %ld to %08lx\n",
3809 ofs
* fc
->code_factor
,
3810 fc
->pc_begin
+ ofs
* fc
->code_factor
);
3811 fc
->pc_begin
+= ofs
* fc
->code_factor
;
3814 case DW_CFA_advance_loc4
:
3815 ofs
= byte_get (start
, 4); start
+= 4;
3816 if (do_debug_frames_interp
)
3817 frame_display_row (fc
, &need_col_headers
, &max_regs
);
3819 printf (" DW_CFA_advance_loc4: %ld to %08lx\n",
3820 ofs
* fc
->code_factor
,
3821 fc
->pc_begin
+ ofs
* fc
->code_factor
);
3822 fc
->pc_begin
+= ofs
* fc
->code_factor
;
3825 case DW_CFA_offset_extended
:
3828 if (! do_debug_frames_interp
)
3829 printf (" DW_CFA_offset_extended: %s at cfa%+ld\n",
3830 regname (reg
, 0), roffs
* fc
->data_factor
);
3831 fc
->col_type
[reg
] = DW_CFA_offset
;
3832 fc
->col_offset
[reg
] = roffs
* fc
->data_factor
;
3835 case DW_CFA_val_offset
:
3838 if (! do_debug_frames_interp
)
3839 printf (" DW_CFA_val_offset: %s at cfa%+ld\n",
3840 regname (reg
, 0), roffs
* fc
->data_factor
);
3841 fc
->col_type
[reg
] = DW_CFA_val_offset
;
3842 fc
->col_offset
[reg
] = roffs
* fc
->data_factor
;
3845 case DW_CFA_restore_extended
:
3847 if (! do_debug_frames_interp
)
3848 printf (" DW_CFA_restore_extended: %s\n",
3850 fc
->col_type
[reg
] = cie
->col_type
[reg
];
3851 fc
->col_offset
[reg
] = cie
->col_offset
[reg
];
3854 case DW_CFA_undefined
:
3856 if (! do_debug_frames_interp
)
3857 printf (" DW_CFA_undefined: %s\n", regname (reg
, 0));
3858 fc
->col_type
[reg
] = DW_CFA_undefined
;
3859 fc
->col_offset
[reg
] = 0;
3862 case DW_CFA_same_value
:
3864 if (! do_debug_frames_interp
)
3865 printf (" DW_CFA_same_value: %s\n", regname (reg
, 0));
3866 fc
->col_type
[reg
] = DW_CFA_same_value
;
3867 fc
->col_offset
[reg
] = 0;
3870 case DW_CFA_register
:
3873 if (! do_debug_frames_interp
)
3875 printf (" DW_CFA_register: %s in ",
3877 puts (regname (roffs
, 0));
3879 fc
->col_type
[reg
] = DW_CFA_register
;
3880 fc
->col_offset
[reg
] = roffs
;
3883 case DW_CFA_remember_state
:
3884 if (! do_debug_frames_interp
)
3885 printf (" DW_CFA_remember_state\n");
3886 rs
= xmalloc (sizeof (Frame_Chunk
));
3887 rs
->ncols
= fc
->ncols
;
3888 rs
->col_type
= xcmalloc (rs
->ncols
, sizeof (short int));
3889 rs
->col_offset
= xcmalloc (rs
->ncols
, sizeof (int));
3890 memcpy (rs
->col_type
, fc
->col_type
, rs
->ncols
);
3891 memcpy (rs
->col_offset
, fc
->col_offset
, rs
->ncols
* sizeof (int));
3892 rs
->next
= remembered_state
;
3893 remembered_state
= rs
;
3896 case DW_CFA_restore_state
:
3897 if (! do_debug_frames_interp
)
3898 printf (" DW_CFA_restore_state\n");
3899 rs
= remembered_state
;
3902 remembered_state
= rs
->next
;
3903 frame_need_space (fc
, rs
->ncols
- 1);
3904 memcpy (fc
->col_type
, rs
->col_type
, rs
->ncols
);
3905 memcpy (fc
->col_offset
, rs
->col_offset
,
3906 rs
->ncols
* sizeof (int));
3907 free (rs
->col_type
);
3908 free (rs
->col_offset
);
3911 else if (do_debug_frames_interp
)
3912 printf ("Mismatched DW_CFA_restore_state\n");
3915 case DW_CFA_def_cfa
:
3916 fc
->cfa_reg
= LEB ();
3917 fc
->cfa_offset
= LEB ();
3919 if (! do_debug_frames_interp
)
3920 printf (" DW_CFA_def_cfa: %s ofs %d\n",
3921 regname (fc
->cfa_reg
, 0), fc
->cfa_offset
);
3924 case DW_CFA_def_cfa_register
:
3925 fc
->cfa_reg
= LEB ();
3927 if (! do_debug_frames_interp
)
3928 printf (" DW_CFA_def_cfa_register: %s\n",
3929 regname (fc
->cfa_reg
, 0));
3932 case DW_CFA_def_cfa_offset
:
3933 fc
->cfa_offset
= LEB ();
3934 if (! do_debug_frames_interp
)
3935 printf (" DW_CFA_def_cfa_offset: %d\n", fc
->cfa_offset
);
3939 if (! do_debug_frames_interp
)
3940 printf (" DW_CFA_nop\n");
3943 case DW_CFA_def_cfa_expression
:
3945 if (! do_debug_frames_interp
)
3947 printf (" DW_CFA_def_cfa_expression (");
3948 decode_location_expression (start
, eh_addr_size
, ul
, 0);
3955 case DW_CFA_expression
:
3958 if (! do_debug_frames_interp
)
3960 printf (" DW_CFA_expression: %s (",
3962 decode_location_expression (start
, eh_addr_size
,
3966 fc
->col_type
[reg
] = DW_CFA_expression
;
3970 case DW_CFA_val_expression
:
3973 if (! do_debug_frames_interp
)
3975 printf (" DW_CFA_val_expression: %s (",
3977 decode_location_expression (start
, eh_addr_size
, ul
, 0);
3980 fc
->col_type
[reg
] = DW_CFA_val_expression
;
3984 case DW_CFA_offset_extended_sf
:
3987 frame_need_space (fc
, reg
);
3988 if (! do_debug_frames_interp
)
3989 printf (" DW_CFA_offset_extended_sf: %s at cfa%+ld\n",
3990 regname (reg
, 0), l
* fc
->data_factor
);
3991 fc
->col_type
[reg
] = DW_CFA_offset
;
3992 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
3995 case DW_CFA_val_offset_sf
:
3998 frame_need_space (fc
, reg
);
3999 if (! do_debug_frames_interp
)
4000 printf (" DW_CFA_val_offset_sf: %s at cfa%+ld\n",
4001 regname (reg
, 0), l
* fc
->data_factor
);
4002 fc
->col_type
[reg
] = DW_CFA_val_offset
;
4003 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
4006 case DW_CFA_def_cfa_sf
:
4007 fc
->cfa_reg
= LEB ();
4008 fc
->cfa_offset
= SLEB ();
4009 fc
->cfa_offset
= fc
->cfa_offset
* fc
->data_factor
;
4011 if (! do_debug_frames_interp
)
4012 printf (" DW_CFA_def_cfa_sf: %s ofs %d\n",
4013 regname (fc
->cfa_reg
, 0), fc
->cfa_offset
);
4016 case DW_CFA_def_cfa_offset_sf
:
4017 fc
->cfa_offset
= SLEB ();
4018 fc
->cfa_offset
= fc
->cfa_offset
* fc
->data_factor
;
4019 if (! do_debug_frames_interp
)
4020 printf (" DW_CFA_def_cfa_offset_sf: %d\n", fc
->cfa_offset
);
4023 case DW_CFA_MIPS_advance_loc8
:
4024 ofs
= byte_get (start
, 8); start
+= 8;
4025 if (do_debug_frames_interp
)
4026 frame_display_row (fc
, &need_col_headers
, &max_regs
);
4028 printf (" DW_CFA_MIPS_advance_loc8: %ld to %08lx\n",
4029 ofs
* fc
->code_factor
,
4030 fc
->pc_begin
+ ofs
* fc
->code_factor
);
4031 fc
->pc_begin
+= ofs
* fc
->code_factor
;
4034 case DW_CFA_GNU_window_save
:
4035 if (! do_debug_frames_interp
)
4036 printf (" DW_CFA_GNU_window_save\n");
4039 case DW_CFA_GNU_args_size
:
4041 if (! do_debug_frames_interp
)
4042 printf (" DW_CFA_GNU_args_size: %ld\n", ul
);
4045 case DW_CFA_GNU_negative_offset_extended
:
4048 frame_need_space (fc
, reg
);
4049 if (! do_debug_frames_interp
)
4050 printf (" DW_CFA_GNU_negative_offset_extended: %s at cfa%+ld\n",
4051 regname (reg
, 0), l
* fc
->data_factor
);
4052 fc
->col_type
[reg
] = DW_CFA_offset
;
4053 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
4057 if (op
>= DW_CFA_lo_user
&& op
<= DW_CFA_hi_user
)
4058 printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op
);
4060 warn (_("unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op
);
4065 if (do_debug_frames_interp
)
4066 frame_display_row (fc
, &need_col_headers
, &max_regs
);
4081 display_debug_not_supported (struct dwarf_section
*section
,
4082 void *file ATTRIBUTE_UNUSED
)
4084 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
4091 cmalloc (size_t nmemb
, size_t size
)
4093 /* Check for overflow. */
4094 if (nmemb
>= ~(size_t) 0 / size
)
4097 return malloc (nmemb
* size
);
4101 xcmalloc (size_t nmemb
, size_t size
)
4103 /* Check for overflow. */
4104 if (nmemb
>= ~(size_t) 0 / size
)
4107 return xmalloc (nmemb
* size
);
4111 xcrealloc (void *ptr
, size_t nmemb
, size_t size
)
4113 /* Check for overflow. */
4114 if (nmemb
>= ~(size_t) 0 / size
)
4117 return xrealloc (ptr
, nmemb
* size
);
4121 error (const char *message
, ...)
4125 va_start (args
, message
);
4126 fprintf (stderr
, _("%s: Error: "), program_name
);
4127 vfprintf (stderr
, message
, args
);
4132 warn (const char *message
, ...)
4136 va_start (args
, message
);
4137 fprintf (stderr
, _("%s: Warning: "), program_name
);
4138 vfprintf (stderr
, message
, args
);
4143 free_debug_memory (void)
4145 enum dwarf_section_display_enum i
;
4149 for (i
= 0; i
< max
; i
++)
4150 free_debug_section (i
);
4152 if (debug_information
!= NULL
)
4154 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
)
4156 for (i
= 0; i
< num_debug_info_entries
; i
++)
4158 if (!debug_information
[i
].max_loc_offsets
)
4160 free (debug_information
[i
].loc_offsets
);
4161 free (debug_information
[i
].have_frame_base
);
4163 if (!debug_information
[i
].max_range_lists
)
4164 free (debug_information
[i
].range_lists
);
4168 free (debug_information
);
4169 debug_information
= NULL
;
4170 num_debug_info_entries
= 0;
4174 struct dwarf_section_display debug_displays
[] =
4176 { { ".debug_abbrev", NULL
, 0, 0 },
4177 display_debug_abbrev
, 0, 0 },
4178 { { ".debug_aranges", NULL
, 0, 0 },
4179 display_debug_aranges
, 0, 0 },
4180 { { ".debug_frame", NULL
, 0, 0 },
4181 display_debug_frames
, 1, 0 },
4182 { { ".debug_info", NULL
, 0, 0 },
4183 display_debug_info
, 1, 0 },
4184 { { ".debug_line", NULL
, 0, 0 },
4185 display_debug_lines
, 0, 0 },
4186 { { ".debug_pubnames", NULL
, 0, 0 },
4187 display_debug_pubnames
, 0, 0 },
4188 { { ".eh_frame", NULL
, 0, 0 },
4189 display_debug_frames
, 1, 1 },
4190 { { ".debug_macinfo", NULL
, 0, 0 },
4191 display_debug_macinfo
, 0, 0 },
4192 { { ".debug_str", NULL
, 0, 0 },
4193 display_debug_str
, 0, 0 },
4194 { { ".debug_loc", NULL
, 0, 0 },
4195 display_debug_loc
, 0, 0 },
4196 { { ".debug_pubtypes", NULL
, 0, 0 },
4197 display_debug_pubnames
, 0, 0 },
4198 { { ".debug_ranges", NULL
, 0, 0 },
4199 display_debug_ranges
, 0, 0 },
4200 { { ".debug_static_func", NULL
, 0, 0 },
4201 display_debug_not_supported
, 0, 0 },
4202 { { ".debug_static_vars", NULL
, 0, 0 },
4203 display_debug_not_supported
, 0, 0 },
4204 { { ".debug_types", NULL
, 0, 0 },
4205 display_debug_not_supported
, 0, 0 },
4206 { { ".debug_weaknames", NULL
, 0, 0 },
4207 display_debug_not_supported
, 0, 0 }