1 /* dwarf.c -- display DWARF contents of a BFD binary file
2 Copyright 2005, 2006, 2007, 2008
3 Free Software Foundation, Inc.
5 This file is part of GNU Binutils.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
23 #include "libiberty.h"
26 #include "elf/common.h"
27 #include "elf/dwarf2.h"
30 static int have_frame_base
;
31 static int need_base_address
;
33 static unsigned int last_pointer_size
= 0;
34 static int warned_about_missing_comp_units
= FALSE
;
36 static unsigned int num_debug_info_entries
= 0;
37 static debug_info
*debug_information
= NULL
;
38 /* Special value for num_debug_info_entries to indicate
39 that the .debug_info section could not be loaded/parsed. */
40 #define DEBUG_INFO_UNAVAILABLE (unsigned int) -1
47 int do_debug_lines_decoded
;
48 int do_debug_pubnames
;
52 int do_debug_frames_interp
;
58 dwarf_vma (*byte_get
) (unsigned char *, int);
61 byte_get_little_endian (unsigned char *field
, int size
)
69 return ((unsigned int) (field
[0]))
70 | (((unsigned int) (field
[1])) << 8);
73 return ((unsigned long) (field
[0]))
74 | (((unsigned long) (field
[1])) << 8)
75 | (((unsigned long) (field
[2])) << 16)
76 | (((unsigned long) (field
[3])) << 24);
79 if (sizeof (dwarf_vma
) == 8)
80 return ((dwarf_vma
) (field
[0]))
81 | (((dwarf_vma
) (field
[1])) << 8)
82 | (((dwarf_vma
) (field
[2])) << 16)
83 | (((dwarf_vma
) (field
[3])) << 24)
84 | (((dwarf_vma
) (field
[4])) << 32)
85 | (((dwarf_vma
) (field
[5])) << 40)
86 | (((dwarf_vma
) (field
[6])) << 48)
87 | (((dwarf_vma
) (field
[7])) << 56);
88 else if (sizeof (dwarf_vma
) == 4)
89 /* We want to extract data from an 8 byte wide field and
90 place it into a 4 byte wide field. Since this is a little
91 endian source we can just use the 4 byte extraction code. */
92 return ((unsigned long) (field
[0]))
93 | (((unsigned long) (field
[1])) << 8)
94 | (((unsigned long) (field
[2])) << 16)
95 | (((unsigned long) (field
[3])) << 24);
98 error (_("Unhandled data length: %d\n"), size
);
104 byte_get_big_endian (unsigned char *field
, int size
)
112 return ((unsigned int) (field
[1])) | (((int) (field
[0])) << 8);
115 return ((unsigned long) (field
[3]))
116 | (((unsigned long) (field
[2])) << 8)
117 | (((unsigned long) (field
[1])) << 16)
118 | (((unsigned long) (field
[0])) << 24);
121 if (sizeof (dwarf_vma
) == 8)
122 return ((dwarf_vma
) (field
[7]))
123 | (((dwarf_vma
) (field
[6])) << 8)
124 | (((dwarf_vma
) (field
[5])) << 16)
125 | (((dwarf_vma
) (field
[4])) << 24)
126 | (((dwarf_vma
) (field
[3])) << 32)
127 | (((dwarf_vma
) (field
[2])) << 40)
128 | (((dwarf_vma
) (field
[1])) << 48)
129 | (((dwarf_vma
) (field
[0])) << 56);
130 else if (sizeof (dwarf_vma
) == 4)
132 /* Although we are extracing data from an 8 byte wide field,
133 we are returning only 4 bytes of data. */
135 return ((unsigned long) (field
[3]))
136 | (((unsigned long) (field
[2])) << 8)
137 | (((unsigned long) (field
[1])) << 16)
138 | (((unsigned long) (field
[0])) << 24);
142 error (_("Unhandled data length: %d\n"), size
);
148 byte_get_signed (unsigned char *field
, int size
)
150 dwarf_vma x
= byte_get (field
, size
);
155 return (x
^ 0x80) - 0x80;
157 return (x
^ 0x8000) - 0x8000;
159 return (x
^ 0x80000000) - 0x80000000;
167 /* Print a dwarf_vma value (typically an address, offset or length) in
168 hexadecimal format, followed by a space. The length of the value (and
169 hence the precision displayed) is determined by the byte_size parameter. */
172 print_dwarf_vma (dwarf_vma val
, unsigned byte_size
)
174 static char buff
[18];
176 /* Printf does not have a way of specifiying a maximum field width for an
177 integer value, so we print the full value into a buffer and then select
178 the precision we need. */
179 #if __STDC_VERSION__ >= 199901L || (defined(__GNUC__) && __GNUC__ >= 2)
181 snprintf (buff
, sizeof (buff
), "%16.16llx ", val
);
183 snprintf (buff
, sizeof (buff
), "%016I64x ", val
);
186 snprintf (buff
, sizeof (buff
), "%16.16lx ", val
);
189 printf (buff
+ (byte_size
== 4 ? 8 : 0));
192 static unsigned long int
193 read_leb128 (unsigned char *data
, unsigned int *length_return
, int sign
)
195 unsigned long int result
= 0;
196 unsigned int num_read
= 0;
197 unsigned int shift
= 0;
205 result
|= ((unsigned long int) (byte
& 0x7f)) << shift
;
212 if (length_return
!= NULL
)
213 *length_return
= num_read
;
215 if (sign
&& (shift
< 8 * sizeof (result
)) && (byte
& 0x40))
216 result
|= -1L << shift
;
221 typedef struct State_Machine_Registers
223 unsigned long address
;
230 /* This variable hold the number of the last entry seen
231 in the File Table. */
232 unsigned int last_file_entry
;
235 static SMR state_machine_regs
;
238 reset_state_machine (int is_stmt
)
240 state_machine_regs
.address
= 0;
241 state_machine_regs
.file
= 1;
242 state_machine_regs
.line
= 1;
243 state_machine_regs
.column
= 0;
244 state_machine_regs
.is_stmt
= is_stmt
;
245 state_machine_regs
.basic_block
= 0;
246 state_machine_regs
.end_sequence
= 0;
247 state_machine_regs
.last_file_entry
= 0;
250 /* Handled an extend line op.
251 Returns the number of bytes read. */
254 process_extended_line_op (unsigned char *data
, int is_stmt
)
256 unsigned char op_code
;
257 unsigned int bytes_read
;
262 len
= read_leb128 (data
, & bytes_read
, 0);
267 warn (_("badly formed extended line op encountered!\n"));
274 printf (_(" Extended opcode %d: "), op_code
);
278 case DW_LNE_end_sequence
:
279 printf (_("End of Sequence\n\n"));
280 reset_state_machine (is_stmt
);
283 case DW_LNE_set_address
:
284 adr
= byte_get (data
, len
- bytes_read
- 1);
285 printf (_("set Address to 0x%lx\n"), adr
);
286 state_machine_regs
.address
= adr
;
289 case DW_LNE_define_file
:
290 printf (_(" define new File Table entry\n"));
291 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
293 printf (_(" %d\t"), ++state_machine_regs
.last_file_entry
);
295 data
+= strlen ((char *) data
) + 1;
296 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
298 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
300 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
301 printf (_("%s\n\n"), name
);
305 case DW_LNE_HP_negate_is_UV_update
:
306 printf ("DW_LNE_HP_negate_is_UV_update");
308 case DW_LNE_HP_push_context
:
309 printf ("DW_LNE_HP_push_context");
311 case DW_LNE_HP_pop_context
:
312 printf ("DW_LNE_HP_pop_context");
314 case DW_LNE_HP_set_file_line_column
:
315 printf ("DW_LNE_HP_set_file_line_column");
317 case DW_LNE_HP_set_routine_name
:
318 printf ("DW_LNE_HP_set_routine_name");
320 case DW_LNE_HP_set_sequence
:
321 printf ("DW_LNE_HP_set_sequence");
323 case DW_LNE_HP_negate_post_semantics
:
324 printf ("DW_LNE_HP_negate_post_semantics");
326 case DW_LNE_HP_negate_function_exit
:
327 printf ("DW_LNE_HP_negate_function_exit");
329 case DW_LNE_HP_negate_front_end_logical
:
330 printf ("DW_LNE_HP_negate_front_end_logical");
332 case DW_LNE_HP_define_proc
:
333 printf ("DW_LNE_HP_define_proc");
337 if (op_code
>= DW_LNE_lo_user
338 /* The test against DW_LNW_hi_user is redundant due to
339 the limited range of the unsigned char data type used
341 /*&& op_code <= DW_LNE_hi_user*/)
342 printf (_("user defined: length %d\n"), len
- bytes_read
);
344 printf (_("UNKNOWN: length %d\n"), len
- bytes_read
);
352 fetch_indirect_string (unsigned long offset
)
354 struct dwarf_section
*section
= &debug_displays
[str
].section
;
356 if (section
->start
== NULL
)
357 return _("<no .debug_str section>");
359 /* DWARF sections under Mach-O have non-zero addresses. */
360 offset
-= section
->address
;
361 if (offset
> section
->size
)
363 warn (_("DW_FORM_strp offset too big: %lx\n"), offset
);
364 return _("<offset is too big>");
367 return (const char *) section
->start
+ offset
;
370 /* FIXME: There are better and more efficient ways to handle
371 these structures. For now though, I just want something that
372 is simple to implement. */
373 typedef struct abbrev_attr
375 unsigned long attribute
;
377 struct abbrev_attr
*next
;
381 typedef struct abbrev_entry
386 struct abbrev_attr
*first_attr
;
387 struct abbrev_attr
*last_attr
;
388 struct abbrev_entry
*next
;
392 static abbrev_entry
*first_abbrev
= NULL
;
393 static abbrev_entry
*last_abbrev
= NULL
;
398 abbrev_entry
*abbrev
;
400 for (abbrev
= first_abbrev
; abbrev
;)
402 abbrev_entry
*next
= abbrev
->next
;
405 for (attr
= abbrev
->first_attr
; attr
;)
407 abbrev_attr
*next
= attr
->next
;
417 last_abbrev
= first_abbrev
= NULL
;
421 add_abbrev (unsigned long number
, unsigned long tag
, int children
)
425 entry
= malloc (sizeof (*entry
));
431 entry
->entry
= number
;
433 entry
->children
= children
;
434 entry
->first_attr
= NULL
;
435 entry
->last_attr
= NULL
;
438 if (first_abbrev
== NULL
)
439 first_abbrev
= entry
;
441 last_abbrev
->next
= entry
;
447 add_abbrev_attr (unsigned long attribute
, unsigned long form
)
451 attr
= malloc (sizeof (*attr
));
457 attr
->attribute
= attribute
;
461 if (last_abbrev
->first_attr
== NULL
)
462 last_abbrev
->first_attr
= attr
;
464 last_abbrev
->last_attr
->next
= attr
;
466 last_abbrev
->last_attr
= attr
;
469 /* Processes the (partial) contents of a .debug_abbrev section.
470 Returns NULL if the end of the section was encountered.
471 Returns the address after the last byte read if the end of
472 an abbreviation set was found. */
474 static unsigned char *
475 process_abbrev_section (unsigned char *start
, unsigned char *end
)
477 if (first_abbrev
!= NULL
)
482 unsigned int bytes_read
;
485 unsigned long attribute
;
488 entry
= read_leb128 (start
, & bytes_read
, 0);
491 /* A single zero is supposed to end the section according
492 to the standard. If there's more, then signal that to
495 return start
== end
? NULL
: start
;
497 tag
= read_leb128 (start
, & bytes_read
, 0);
502 add_abbrev (entry
, tag
, children
);
508 attribute
= read_leb128 (start
, & bytes_read
, 0);
511 form
= read_leb128 (start
, & bytes_read
, 0);
515 add_abbrev_attr (attribute
, form
);
517 while (attribute
!= 0);
524 get_TAG_name (unsigned long tag
)
528 case DW_TAG_padding
: return "DW_TAG_padding";
529 case DW_TAG_array_type
: return "DW_TAG_array_type";
530 case DW_TAG_class_type
: return "DW_TAG_class_type";
531 case DW_TAG_entry_point
: return "DW_TAG_entry_point";
532 case DW_TAG_enumeration_type
: return "DW_TAG_enumeration_type";
533 case DW_TAG_formal_parameter
: return "DW_TAG_formal_parameter";
534 case DW_TAG_imported_declaration
: return "DW_TAG_imported_declaration";
535 case DW_TAG_label
: return "DW_TAG_label";
536 case DW_TAG_lexical_block
: return "DW_TAG_lexical_block";
537 case DW_TAG_member
: return "DW_TAG_member";
538 case DW_TAG_pointer_type
: return "DW_TAG_pointer_type";
539 case DW_TAG_reference_type
: return "DW_TAG_reference_type";
540 case DW_TAG_compile_unit
: return "DW_TAG_compile_unit";
541 case DW_TAG_string_type
: return "DW_TAG_string_type";
542 case DW_TAG_structure_type
: return "DW_TAG_structure_type";
543 case DW_TAG_subroutine_type
: return "DW_TAG_subroutine_type";
544 case DW_TAG_typedef
: return "DW_TAG_typedef";
545 case DW_TAG_union_type
: return "DW_TAG_union_type";
546 case DW_TAG_unspecified_parameters
: return "DW_TAG_unspecified_parameters";
547 case DW_TAG_variant
: return "DW_TAG_variant";
548 case DW_TAG_common_block
: return "DW_TAG_common_block";
549 case DW_TAG_common_inclusion
: return "DW_TAG_common_inclusion";
550 case DW_TAG_inheritance
: return "DW_TAG_inheritance";
551 case DW_TAG_inlined_subroutine
: return "DW_TAG_inlined_subroutine";
552 case DW_TAG_module
: return "DW_TAG_module";
553 case DW_TAG_ptr_to_member_type
: return "DW_TAG_ptr_to_member_type";
554 case DW_TAG_set_type
: return "DW_TAG_set_type";
555 case DW_TAG_subrange_type
: return "DW_TAG_subrange_type";
556 case DW_TAG_with_stmt
: return "DW_TAG_with_stmt";
557 case DW_TAG_access_declaration
: return "DW_TAG_access_declaration";
558 case DW_TAG_base_type
: return "DW_TAG_base_type";
559 case DW_TAG_catch_block
: return "DW_TAG_catch_block";
560 case DW_TAG_const_type
: return "DW_TAG_const_type";
561 case DW_TAG_constant
: return "DW_TAG_constant";
562 case DW_TAG_enumerator
: return "DW_TAG_enumerator";
563 case DW_TAG_file_type
: return "DW_TAG_file_type";
564 case DW_TAG_friend
: return "DW_TAG_friend";
565 case DW_TAG_namelist
: return "DW_TAG_namelist";
566 case DW_TAG_namelist_item
: return "DW_TAG_namelist_item";
567 case DW_TAG_packed_type
: return "DW_TAG_packed_type";
568 case DW_TAG_subprogram
: return "DW_TAG_subprogram";
569 case DW_TAG_template_type_param
: return "DW_TAG_template_type_param";
570 case DW_TAG_template_value_param
: return "DW_TAG_template_value_param";
571 case DW_TAG_thrown_type
: return "DW_TAG_thrown_type";
572 case DW_TAG_try_block
: return "DW_TAG_try_block";
573 case DW_TAG_variant_part
: return "DW_TAG_variant_part";
574 case DW_TAG_variable
: return "DW_TAG_variable";
575 case DW_TAG_volatile_type
: return "DW_TAG_volatile_type";
576 case DW_TAG_MIPS_loop
: return "DW_TAG_MIPS_loop";
577 case DW_TAG_format_label
: return "DW_TAG_format_label";
578 case DW_TAG_function_template
: return "DW_TAG_function_template";
579 case DW_TAG_class_template
: return "DW_TAG_class_template";
580 /* DWARF 2.1 values. */
581 case DW_TAG_dwarf_procedure
: return "DW_TAG_dwarf_procedure";
582 case DW_TAG_restrict_type
: return "DW_TAG_restrict_type";
583 case DW_TAG_interface_type
: return "DW_TAG_interface_type";
584 case DW_TAG_namespace
: return "DW_TAG_namespace";
585 case DW_TAG_imported_module
: return "DW_TAG_imported_module";
586 case DW_TAG_unspecified_type
: return "DW_TAG_unspecified_type";
587 case DW_TAG_partial_unit
: return "DW_TAG_partial_unit";
588 case DW_TAG_imported_unit
: return "DW_TAG_imported_unit";
590 case DW_TAG_upc_shared_type
: return "DW_TAG_upc_shared_type";
591 case DW_TAG_upc_strict_type
: return "DW_TAG_upc_strict_type";
592 case DW_TAG_upc_relaxed_type
: return "DW_TAG_upc_relaxed_type";
595 static char buffer
[100];
597 snprintf (buffer
, sizeof (buffer
), _("Unknown TAG value: %lx"), tag
);
604 get_FORM_name (unsigned long form
)
608 case DW_FORM_addr
: return "DW_FORM_addr";
609 case DW_FORM_block2
: return "DW_FORM_block2";
610 case DW_FORM_block4
: return "DW_FORM_block4";
611 case DW_FORM_data2
: return "DW_FORM_data2";
612 case DW_FORM_data4
: return "DW_FORM_data4";
613 case DW_FORM_data8
: return "DW_FORM_data8";
614 case DW_FORM_string
: return "DW_FORM_string";
615 case DW_FORM_block
: return "DW_FORM_block";
616 case DW_FORM_block1
: return "DW_FORM_block1";
617 case DW_FORM_data1
: return "DW_FORM_data1";
618 case DW_FORM_flag
: return "DW_FORM_flag";
619 case DW_FORM_sdata
: return "DW_FORM_sdata";
620 case DW_FORM_strp
: return "DW_FORM_strp";
621 case DW_FORM_udata
: return "DW_FORM_udata";
622 case DW_FORM_ref_addr
: return "DW_FORM_ref_addr";
623 case DW_FORM_ref1
: return "DW_FORM_ref1";
624 case DW_FORM_ref2
: return "DW_FORM_ref2";
625 case DW_FORM_ref4
: return "DW_FORM_ref4";
626 case DW_FORM_ref8
: return "DW_FORM_ref8";
627 case DW_FORM_ref_udata
: return "DW_FORM_ref_udata";
628 case DW_FORM_indirect
: return "DW_FORM_indirect";
631 static char buffer
[100];
633 snprintf (buffer
, sizeof (buffer
), _("Unknown FORM value: %lx"), form
);
639 static unsigned char *
640 display_block (unsigned char *data
, unsigned long length
)
642 printf (_(" %lu byte block: "), length
);
645 printf ("%lx ", (unsigned long) byte_get (data
++, 1));
651 decode_location_expression (unsigned char * data
,
652 unsigned int pointer_size
,
653 unsigned long length
,
654 unsigned long cu_offset
)
657 unsigned int bytes_read
;
658 unsigned long uvalue
;
659 unsigned char *end
= data
+ length
;
660 int need_frame_base
= 0;
669 printf ("DW_OP_addr: %lx",
670 (unsigned long) byte_get (data
, pointer_size
));
671 data
+= pointer_size
;
674 printf ("DW_OP_deref");
677 printf ("DW_OP_const1u: %lu", (unsigned long) byte_get (data
++, 1));
680 printf ("DW_OP_const1s: %ld", (long) byte_get_signed (data
++, 1));
683 printf ("DW_OP_const2u: %lu", (unsigned long) byte_get (data
, 2));
687 printf ("DW_OP_const2s: %ld", (long) byte_get_signed (data
, 2));
691 printf ("DW_OP_const4u: %lu", (unsigned long) byte_get (data
, 4));
695 printf ("DW_OP_const4s: %ld", (long) byte_get_signed (data
, 4));
699 printf ("DW_OP_const8u: %lu %lu", (unsigned long) byte_get (data
, 4),
700 (unsigned long) byte_get (data
+ 4, 4));
704 printf ("DW_OP_const8s: %ld %ld", (long) byte_get (data
, 4),
705 (long) byte_get (data
+ 4, 4));
709 printf ("DW_OP_constu: %lu", read_leb128 (data
, &bytes_read
, 0));
713 printf ("DW_OP_consts: %ld", read_leb128 (data
, &bytes_read
, 1));
717 printf ("DW_OP_dup");
720 printf ("DW_OP_drop");
723 printf ("DW_OP_over");
726 printf ("DW_OP_pick: %ld", (unsigned long) byte_get (data
++, 1));
729 printf ("DW_OP_swap");
732 printf ("DW_OP_rot");
735 printf ("DW_OP_xderef");
738 printf ("DW_OP_abs");
741 printf ("DW_OP_and");
744 printf ("DW_OP_div");
747 printf ("DW_OP_minus");
750 printf ("DW_OP_mod");
753 printf ("DW_OP_mul");
756 printf ("DW_OP_neg");
759 printf ("DW_OP_not");
765 printf ("DW_OP_plus");
767 case DW_OP_plus_uconst
:
768 printf ("DW_OP_plus_uconst: %lu",
769 read_leb128 (data
, &bytes_read
, 0));
773 printf ("DW_OP_shl");
776 printf ("DW_OP_shr");
779 printf ("DW_OP_shra");
782 printf ("DW_OP_xor");
785 printf ("DW_OP_bra: %ld", (long) byte_get_signed (data
, 2));
807 printf ("DW_OP_skip: %ld", (long) byte_get_signed (data
, 2));
843 printf ("DW_OP_lit%d", op
- DW_OP_lit0
);
878 printf ("DW_OP_reg%d", op
- DW_OP_reg0
);
913 printf ("DW_OP_breg%d: %ld", op
- DW_OP_breg0
,
914 read_leb128 (data
, &bytes_read
, 1));
919 printf ("DW_OP_regx: %lu", read_leb128 (data
, &bytes_read
, 0));
924 printf ("DW_OP_fbreg: %ld", read_leb128 (data
, &bytes_read
, 1));
928 uvalue
= read_leb128 (data
, &bytes_read
, 0);
930 printf ("DW_OP_bregx: %lu %ld", uvalue
,
931 read_leb128 (data
, &bytes_read
, 1));
935 printf ("DW_OP_piece: %lu", read_leb128 (data
, &bytes_read
, 0));
938 case DW_OP_deref_size
:
939 printf ("DW_OP_deref_size: %ld", (long) byte_get (data
++, 1));
941 case DW_OP_xderef_size
:
942 printf ("DW_OP_xderef_size: %ld", (long) byte_get (data
++, 1));
945 printf ("DW_OP_nop");
948 /* DWARF 3 extensions. */
949 case DW_OP_push_object_address
:
950 printf ("DW_OP_push_object_address");
953 /* XXX: Strictly speaking for 64-bit DWARF3 files
954 this ought to be an 8-byte wide computation. */
955 printf ("DW_OP_call2: <%lx>", (long) byte_get (data
, 2) + cu_offset
);
959 /* XXX: Strictly speaking for 64-bit DWARF3 files
960 this ought to be an 8-byte wide computation. */
961 printf ("DW_OP_call4: <%lx>", (long) byte_get (data
, 4) + cu_offset
);
965 /* XXX: Strictly speaking for 64-bit DWARF3 files
966 this ought to be an 8-byte wide computation. */
967 printf ("DW_OP_call_ref: <%lx>", (long) byte_get (data
, 4) + cu_offset
);
970 case DW_OP_form_tls_address
:
971 printf ("DW_OP_form_tls_address");
973 case DW_OP_call_frame_cfa
:
974 printf ("DW_OP_call_frame_cfa");
976 case DW_OP_bit_piece
:
977 printf ("DW_OP_bit_piece: ");
978 printf ("size: %lu ", read_leb128 (data
, &bytes_read
, 0));
980 printf ("offset: %lu ", read_leb128 (data
, &bytes_read
, 0));
984 /* GNU extensions. */
985 case DW_OP_GNU_push_tls_address
:
986 printf ("DW_OP_GNU_push_tls_address or DW_OP_HP_unknown");
988 case DW_OP_GNU_uninit
:
989 printf ("DW_OP_GNU_uninit");
990 /* FIXME: Is there data associated with this OP ? */
994 case DW_OP_HP_is_value
:
995 printf ("DW_OP_HP_is_value");
996 /* FIXME: Is there data associated with this OP ? */
998 case DW_OP_HP_fltconst4
:
999 printf ("DW_OP_HP_fltconst4");
1000 /* FIXME: Is there data associated with this OP ? */
1002 case DW_OP_HP_fltconst8
:
1003 printf ("DW_OP_HP_fltconst8");
1004 /* FIXME: Is there data associated with this OP ? */
1006 case DW_OP_HP_mod_range
:
1007 printf ("DW_OP_HP_mod_range");
1008 /* FIXME: Is there data associated with this OP ? */
1010 case DW_OP_HP_unmod_range
:
1011 printf ("DW_OP_HP_unmod_range");
1012 /* FIXME: Is there data associated with this OP ? */
1015 printf ("DW_OP_HP_tls");
1016 /* FIXME: Is there data associated with this OP ? */
1019 /* PGI (STMicroelectronics) extensions. */
1020 case DW_OP_PGI_omp_thread_num
:
1021 /* Pushes the thread number for the current thread as it would be
1022 returned by the standard OpenMP library function:
1023 omp_get_thread_num(). The "current thread" is the thread for
1024 which the expression is being evaluated. */
1025 printf ("DW_OP_PGI_omp_thread_num");
1029 if (op
>= DW_OP_lo_user
1030 && op
<= DW_OP_hi_user
)
1031 printf (_("(User defined location op)"));
1033 printf (_("(Unknown location op)"));
1034 /* No way to tell where the next op is, so just bail. */
1035 return need_frame_base
;
1038 /* Separate the ops. */
1043 return need_frame_base
;
1046 static unsigned char *
1047 read_and_display_attr_value (unsigned long attribute
,
1049 unsigned char * data
,
1050 unsigned long cu_offset
,
1051 unsigned long pointer_size
,
1052 unsigned long offset_size
,
1054 debug_info
* debug_info_p
,
1056 struct dwarf_section
* section
)
1058 unsigned long uvalue
= 0;
1059 unsigned char *block_start
= NULL
;
1060 unsigned char * orig_data
= data
;
1061 unsigned int bytes_read
;
1068 case DW_FORM_ref_addr
:
1069 if (dwarf_version
== 2)
1071 uvalue
= byte_get (data
, pointer_size
);
1072 data
+= pointer_size
;
1074 else if (dwarf_version
== 3)
1076 uvalue
= byte_get (data
, offset_size
);
1077 data
+= offset_size
;
1081 error (_("Internal error: DWARF version is not 2 or 3.\n"));
1086 uvalue
= byte_get (data
, pointer_size
);
1087 data
+= pointer_size
;
1091 uvalue
= byte_get (data
, offset_size
);
1092 data
+= offset_size
;
1098 uvalue
= byte_get (data
++, 1);
1103 uvalue
= byte_get (data
, 2);
1109 uvalue
= byte_get (data
, 4);
1114 uvalue
= read_leb128 (data
, & bytes_read
, 1);
1118 case DW_FORM_ref_udata
:
1120 uvalue
= read_leb128 (data
, & bytes_read
, 0);
1124 case DW_FORM_indirect
:
1125 form
= read_leb128 (data
, & bytes_read
, 0);
1128 printf (" %s", get_FORM_name (form
));
1129 return read_and_display_attr_value (attribute
, form
, data
,
1130 cu_offset
, pointer_size
,
1131 offset_size
, dwarf_version
,
1132 debug_info_p
, do_loc
,
1138 case DW_FORM_ref_addr
:
1140 printf (" <0x%lx>", uvalue
);
1146 case DW_FORM_ref_udata
:
1148 printf (" <0x%lx>", uvalue
+ cu_offset
);
1154 printf (" 0x%lx", uvalue
);
1163 printf (" %ld", uvalue
);
1170 uvalue
= byte_get (data
, 4);
1171 printf (" 0x%lx", uvalue
);
1172 printf (" 0x%lx", (unsigned long) byte_get (data
+ 4, 4));
1174 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
1175 && num_debug_info_entries
== 0)
1177 if (sizeof (uvalue
) == 8)
1178 uvalue
= byte_get (data
, 8);
1180 error (_("DW_FORM_data8 is unsupported when sizeof (unsigned long) != 8\n"));
1185 case DW_FORM_string
:
1187 printf (" %s", data
);
1188 data
+= strlen ((char *) data
) + 1;
1192 uvalue
= read_leb128 (data
, & bytes_read
, 0);
1193 block_start
= data
+ bytes_read
;
1195 data
= block_start
+ uvalue
;
1197 data
= display_block (block_start
, uvalue
);
1200 case DW_FORM_block1
:
1201 uvalue
= byte_get (data
, 1);
1202 block_start
= data
+ 1;
1204 data
= block_start
+ uvalue
;
1206 data
= display_block (block_start
, uvalue
);
1209 case DW_FORM_block2
:
1210 uvalue
= byte_get (data
, 2);
1211 block_start
= data
+ 2;
1213 data
= block_start
+ uvalue
;
1215 data
= display_block (block_start
, uvalue
);
1218 case DW_FORM_block4
:
1219 uvalue
= byte_get (data
, 4);
1220 block_start
= data
+ 4;
1222 data
= block_start
+ uvalue
;
1224 data
= display_block (block_start
, uvalue
);
1229 printf (_(" (indirect string, offset: 0x%lx): %s"),
1230 uvalue
, fetch_indirect_string (uvalue
));
1233 case DW_FORM_indirect
:
1234 /* Handled above. */
1238 warn (_("Unrecognized form: %lu\n"), form
);
1242 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
1243 && num_debug_info_entries
== 0)
1247 case DW_AT_frame_base
:
1248 have_frame_base
= 1;
1249 case DW_AT_location
:
1250 case DW_AT_string_length
:
1251 case DW_AT_return_addr
:
1252 case DW_AT_data_member_location
:
1253 case DW_AT_vtable_elem_location
:
1255 case DW_AT_static_link
:
1256 case DW_AT_use_location
:
1257 if (form
== DW_FORM_data4
|| form
== DW_FORM_data8
)
1259 /* Process location list. */
1260 unsigned int max
= debug_info_p
->max_loc_offsets
;
1261 unsigned int num
= debug_info_p
->num_loc_offsets
;
1263 if (max
== 0 || num
>= max
)
1266 debug_info_p
->loc_offsets
1267 = xcrealloc (debug_info_p
->loc_offsets
,
1268 max
, sizeof (*debug_info_p
->loc_offsets
));
1269 debug_info_p
->have_frame_base
1270 = xcrealloc (debug_info_p
->have_frame_base
,
1271 max
, sizeof (*debug_info_p
->have_frame_base
));
1272 debug_info_p
->max_loc_offsets
= max
;
1274 debug_info_p
->loc_offsets
[num
] = uvalue
;
1275 debug_info_p
->have_frame_base
[num
] = have_frame_base
;
1276 debug_info_p
->num_loc_offsets
++;
1281 if (need_base_address
)
1282 debug_info_p
->base_address
= uvalue
;
1286 if (form
== DW_FORM_data4
|| form
== DW_FORM_data8
)
1288 /* Process range list. */
1289 unsigned int max
= debug_info_p
->max_range_lists
;
1290 unsigned int num
= debug_info_p
->num_range_lists
;
1292 if (max
== 0 || num
>= max
)
1295 debug_info_p
->range_lists
1296 = xcrealloc (debug_info_p
->range_lists
,
1297 max
, sizeof (*debug_info_p
->range_lists
));
1298 debug_info_p
->max_range_lists
= max
;
1300 debug_info_p
->range_lists
[num
] = uvalue
;
1301 debug_info_p
->num_range_lists
++;
1313 /* For some attributes we can display further information. */
1321 case DW_INL_not_inlined
:
1322 printf (_("(not inlined)"));
1324 case DW_INL_inlined
:
1325 printf (_("(inlined)"));
1327 case DW_INL_declared_not_inlined
:
1328 printf (_("(declared as inline but ignored)"));
1330 case DW_INL_declared_inlined
:
1331 printf (_("(declared as inline and inlined)"));
1334 printf (_(" (Unknown inline attribute value: %lx)"), uvalue
);
1339 case DW_AT_language
:
1342 /* Ordered by the numeric value of these constants. */
1343 case DW_LANG_C89
: printf ("(ANSI C)"); break;
1344 case DW_LANG_C
: printf ("(non-ANSI C)"); break;
1345 case DW_LANG_Ada83
: printf ("(Ada)"); break;
1346 case DW_LANG_C_plus_plus
: printf ("(C++)"); break;
1347 case DW_LANG_Cobol74
: printf ("(Cobol 74)"); break;
1348 case DW_LANG_Cobol85
: printf ("(Cobol 85)"); break;
1349 case DW_LANG_Fortran77
: printf ("(FORTRAN 77)"); break;
1350 case DW_LANG_Fortran90
: printf ("(Fortran 90)"); break;
1351 case DW_LANG_Pascal83
: printf ("(ANSI Pascal)"); break;
1352 case DW_LANG_Modula2
: printf ("(Modula 2)"); break;
1353 /* DWARF 2.1 values. */
1354 case DW_LANG_Java
: printf ("(Java)"); break;
1355 case DW_LANG_C99
: printf ("(ANSI C99)"); break;
1356 case DW_LANG_Ada95
: printf ("(ADA 95)"); break;
1357 case DW_LANG_Fortran95
: printf ("(Fortran 95)"); break;
1358 /* DWARF 3 values. */
1359 case DW_LANG_PLI
: printf ("(PLI)"); break;
1360 case DW_LANG_ObjC
: printf ("(Objective C)"); break;
1361 case DW_LANG_ObjC_plus_plus
: printf ("(Objective C++)"); break;
1362 case DW_LANG_UPC
: printf ("(Unified Parallel C)"); break;
1363 case DW_LANG_D
: printf ("(D)"); break;
1364 /* MIPS extension. */
1365 case DW_LANG_Mips_Assembler
: printf ("(MIPS assembler)"); break;
1366 /* UPC extension. */
1367 case DW_LANG_Upc
: printf ("(Unified Parallel C)"); break;
1369 if (uvalue
>= DW_LANG_lo_user
&& uvalue
<= DW_LANG_hi_user
)
1370 printf ("(implementation defined: %lx)", uvalue
);
1372 printf ("(Unknown: %lx)", uvalue
);
1377 case DW_AT_encoding
:
1380 case DW_ATE_void
: printf ("(void)"); break;
1381 case DW_ATE_address
: printf ("(machine address)"); break;
1382 case DW_ATE_boolean
: printf ("(boolean)"); break;
1383 case DW_ATE_complex_float
: printf ("(complex float)"); break;
1384 case DW_ATE_float
: printf ("(float)"); break;
1385 case DW_ATE_signed
: printf ("(signed)"); break;
1386 case DW_ATE_signed_char
: printf ("(signed char)"); break;
1387 case DW_ATE_unsigned
: printf ("(unsigned)"); break;
1388 case DW_ATE_unsigned_char
: printf ("(unsigned char)"); break;
1389 /* DWARF 2.1 values: */
1390 case DW_ATE_imaginary_float
: printf ("(imaginary float)"); break;
1391 case DW_ATE_decimal_float
: printf ("(decimal float)"); break;
1392 /* DWARF 3 values: */
1393 case DW_ATE_packed_decimal
: printf ("(packed_decimal)"); break;
1394 case DW_ATE_numeric_string
: printf ("(numeric_string)"); break;
1395 case DW_ATE_edited
: printf ("(edited)"); break;
1396 case DW_ATE_signed_fixed
: printf ("(signed_fixed)"); break;
1397 case DW_ATE_unsigned_fixed
: printf ("(unsigned_fixed)"); break;
1398 /* HP extensions: */
1399 case DW_ATE_HP_float80
: printf ("(HP_float80)"); break;
1400 case DW_ATE_HP_complex_float80
: printf ("(HP_complex_float80)"); break;
1401 case DW_ATE_HP_float128
: printf ("(HP_float128)"); break;
1402 case DW_ATE_HP_complex_float128
:printf ("(HP_complex_float128)"); break;
1403 case DW_ATE_HP_floathpintel
: printf ("(HP_floathpintel)"); break;
1404 case DW_ATE_HP_imaginary_float80
: printf ("(HP_imaginary_float80)"); break;
1405 case DW_ATE_HP_imaginary_float128
: printf ("(HP_imaginary_float128)"); break;
1408 if (uvalue
>= DW_ATE_lo_user
1409 && uvalue
<= DW_ATE_hi_user
)
1410 printf ("(user defined type)");
1412 printf ("(unknown type)");
1417 case DW_AT_accessibility
:
1420 case DW_ACCESS_public
: printf ("(public)"); break;
1421 case DW_ACCESS_protected
: printf ("(protected)"); break;
1422 case DW_ACCESS_private
: printf ("(private)"); break;
1424 printf ("(unknown accessibility)");
1429 case DW_AT_visibility
:
1432 case DW_VIS_local
: printf ("(local)"); break;
1433 case DW_VIS_exported
: printf ("(exported)"); break;
1434 case DW_VIS_qualified
: printf ("(qualified)"); break;
1435 default: printf ("(unknown visibility)"); break;
1439 case DW_AT_virtuality
:
1442 case DW_VIRTUALITY_none
: printf ("(none)"); break;
1443 case DW_VIRTUALITY_virtual
: printf ("(virtual)"); break;
1444 case DW_VIRTUALITY_pure_virtual
:printf ("(pure_virtual)"); break;
1445 default: printf ("(unknown virtuality)"); break;
1449 case DW_AT_identifier_case
:
1452 case DW_ID_case_sensitive
: printf ("(case_sensitive)"); break;
1453 case DW_ID_up_case
: printf ("(up_case)"); break;
1454 case DW_ID_down_case
: printf ("(down_case)"); break;
1455 case DW_ID_case_insensitive
: printf ("(case_insensitive)"); break;
1456 default: printf ("(unknown case)"); break;
1460 case DW_AT_calling_convention
:
1463 case DW_CC_normal
: printf ("(normal)"); break;
1464 case DW_CC_program
: printf ("(program)"); break;
1465 case DW_CC_nocall
: printf ("(nocall)"); break;
1467 if (uvalue
>= DW_CC_lo_user
1468 && uvalue
<= DW_CC_hi_user
)
1469 printf ("(user defined)");
1471 printf ("(unknown convention)");
1475 case DW_AT_ordering
:
1478 case -1: printf ("(undefined)"); break;
1479 case 0: printf ("(row major)"); break;
1480 case 1: printf ("(column major)"); break;
1484 case DW_AT_frame_base
:
1485 have_frame_base
= 1;
1486 case DW_AT_location
:
1487 case DW_AT_string_length
:
1488 case DW_AT_return_addr
:
1489 case DW_AT_data_member_location
:
1490 case DW_AT_vtable_elem_location
:
1492 case DW_AT_static_link
:
1493 case DW_AT_use_location
:
1494 if (form
== DW_FORM_data4
|| form
== DW_FORM_data8
)
1495 printf (_("(location list)"));
1497 case DW_AT_allocated
:
1498 case DW_AT_associated
:
1499 case DW_AT_data_location
:
1501 case DW_AT_upper_bound
:
1502 case DW_AT_lower_bound
:
1505 int need_frame_base
;
1508 need_frame_base
= decode_location_expression (block_start
,
1513 if (need_frame_base
&& !have_frame_base
)
1514 printf (_(" [without DW_AT_frame_base]"));
1520 if (form
== DW_FORM_ref1
1521 || form
== DW_FORM_ref2
1522 || form
== DW_FORM_ref4
)
1523 uvalue
+= cu_offset
;
1525 if (uvalue
>= section
->size
)
1526 warn (_("Offset %lx used as value for DW_AT_import attribute of DIE at offset %lx is too big.\n"),
1527 uvalue
, (unsigned long) (orig_data
- section
->start
));
1530 unsigned long abbrev_number
;
1531 abbrev_entry
* entry
;
1533 abbrev_number
= read_leb128 (section
->start
+ uvalue
, NULL
, 0);
1535 printf ("[Abbrev Number: %ld", abbrev_number
);
1536 for (entry
= first_abbrev
; entry
!= NULL
; entry
= entry
->next
)
1537 if (entry
->entry
== abbrev_number
)
1540 printf (" (%s)", get_TAG_name (entry
->tag
));
1554 get_AT_name (unsigned long attribute
)
1558 case DW_AT_sibling
: return "DW_AT_sibling";
1559 case DW_AT_location
: return "DW_AT_location";
1560 case DW_AT_name
: return "DW_AT_name";
1561 case DW_AT_ordering
: return "DW_AT_ordering";
1562 case DW_AT_subscr_data
: return "DW_AT_subscr_data";
1563 case DW_AT_byte_size
: return "DW_AT_byte_size";
1564 case DW_AT_bit_offset
: return "DW_AT_bit_offset";
1565 case DW_AT_bit_size
: return "DW_AT_bit_size";
1566 case DW_AT_element_list
: return "DW_AT_element_list";
1567 case DW_AT_stmt_list
: return "DW_AT_stmt_list";
1568 case DW_AT_low_pc
: return "DW_AT_low_pc";
1569 case DW_AT_high_pc
: return "DW_AT_high_pc";
1570 case DW_AT_language
: return "DW_AT_language";
1571 case DW_AT_member
: return "DW_AT_member";
1572 case DW_AT_discr
: return "DW_AT_discr";
1573 case DW_AT_discr_value
: return "DW_AT_discr_value";
1574 case DW_AT_visibility
: return "DW_AT_visibility";
1575 case DW_AT_import
: return "DW_AT_import";
1576 case DW_AT_string_length
: return "DW_AT_string_length";
1577 case DW_AT_common_reference
: return "DW_AT_common_reference";
1578 case DW_AT_comp_dir
: return "DW_AT_comp_dir";
1579 case DW_AT_const_value
: return "DW_AT_const_value";
1580 case DW_AT_containing_type
: return "DW_AT_containing_type";
1581 case DW_AT_default_value
: return "DW_AT_default_value";
1582 case DW_AT_inline
: return "DW_AT_inline";
1583 case DW_AT_is_optional
: return "DW_AT_is_optional";
1584 case DW_AT_lower_bound
: return "DW_AT_lower_bound";
1585 case DW_AT_producer
: return "DW_AT_producer";
1586 case DW_AT_prototyped
: return "DW_AT_prototyped";
1587 case DW_AT_return_addr
: return "DW_AT_return_addr";
1588 case DW_AT_start_scope
: return "DW_AT_start_scope";
1589 case DW_AT_stride_size
: return "DW_AT_stride_size";
1590 case DW_AT_upper_bound
: return "DW_AT_upper_bound";
1591 case DW_AT_abstract_origin
: return "DW_AT_abstract_origin";
1592 case DW_AT_accessibility
: return "DW_AT_accessibility";
1593 case DW_AT_address_class
: return "DW_AT_address_class";
1594 case DW_AT_artificial
: return "DW_AT_artificial";
1595 case DW_AT_base_types
: return "DW_AT_base_types";
1596 case DW_AT_calling_convention
: return "DW_AT_calling_convention";
1597 case DW_AT_count
: return "DW_AT_count";
1598 case DW_AT_data_member_location
: return "DW_AT_data_member_location";
1599 case DW_AT_decl_column
: return "DW_AT_decl_column";
1600 case DW_AT_decl_file
: return "DW_AT_decl_file";
1601 case DW_AT_decl_line
: return "DW_AT_decl_line";
1602 case DW_AT_declaration
: return "DW_AT_declaration";
1603 case DW_AT_discr_list
: return "DW_AT_discr_list";
1604 case DW_AT_encoding
: return "DW_AT_encoding";
1605 case DW_AT_external
: return "DW_AT_external";
1606 case DW_AT_frame_base
: return "DW_AT_frame_base";
1607 case DW_AT_friend
: return "DW_AT_friend";
1608 case DW_AT_identifier_case
: return "DW_AT_identifier_case";
1609 case DW_AT_macro_info
: return "DW_AT_macro_info";
1610 case DW_AT_namelist_items
: return "DW_AT_namelist_items";
1611 case DW_AT_priority
: return "DW_AT_priority";
1612 case DW_AT_segment
: return "DW_AT_segment";
1613 case DW_AT_specification
: return "DW_AT_specification";
1614 case DW_AT_static_link
: return "DW_AT_static_link";
1615 case DW_AT_type
: return "DW_AT_type";
1616 case DW_AT_use_location
: return "DW_AT_use_location";
1617 case DW_AT_variable_parameter
: return "DW_AT_variable_parameter";
1618 case DW_AT_virtuality
: return "DW_AT_virtuality";
1619 case DW_AT_vtable_elem_location
: return "DW_AT_vtable_elem_location";
1620 /* DWARF 2.1 values. */
1621 case DW_AT_allocated
: return "DW_AT_allocated";
1622 case DW_AT_associated
: return "DW_AT_associated";
1623 case DW_AT_data_location
: return "DW_AT_data_location";
1624 case DW_AT_stride
: return "DW_AT_stride";
1625 case DW_AT_entry_pc
: return "DW_AT_entry_pc";
1626 case DW_AT_use_UTF8
: return "DW_AT_use_UTF8";
1627 case DW_AT_extension
: return "DW_AT_extension";
1628 case DW_AT_ranges
: return "DW_AT_ranges";
1629 case DW_AT_trampoline
: return "DW_AT_trampoline";
1630 case DW_AT_call_column
: return "DW_AT_call_column";
1631 case DW_AT_call_file
: return "DW_AT_call_file";
1632 case DW_AT_call_line
: return "DW_AT_call_line";
1633 case DW_AT_description
: return "DW_AT_description";
1634 case DW_AT_binary_scale
: return "DW_AT_binary_scale";
1635 case DW_AT_decimal_scale
: return "DW_AT_decimal_scale";
1636 case DW_AT_small
: return "DW_AT_small";
1637 case DW_AT_decimal_sign
: return "DW_AT_decimal_sign";
1638 case DW_AT_digit_count
: return "DW_AT_digit_count";
1639 case DW_AT_picture_string
: return "DW_AT_picture_string";
1640 case DW_AT_mutable
: return "DW_AT_mutable";
1641 case DW_AT_threads_scaled
: return "DW_AT_threads_scaled";
1642 case DW_AT_explicit
: return "DW_AT_explicit";
1643 case DW_AT_object_pointer
: return "DW_AT_object_pointer";
1644 case DW_AT_endianity
: return "DW_AT_endianity";
1645 case DW_AT_elemental
: return "DW_AT_elemental";
1646 case DW_AT_pure
: return "DW_AT_pure";
1647 case DW_AT_recursive
: return "DW_AT_recursive";
1649 /* HP and SGI/MIPS extensions. */
1650 case DW_AT_MIPS_loop_begin
: return "DW_AT_MIPS_loop_begin";
1651 case DW_AT_MIPS_tail_loop_begin
: return "DW_AT_MIPS_tail_loop_begin";
1652 case DW_AT_MIPS_epilog_begin
: return "DW_AT_MIPS_epilog_begin";
1653 case DW_AT_MIPS_loop_unroll_factor
: return "DW_AT_MIPS_loop_unroll_factor";
1654 case DW_AT_MIPS_software_pipeline_depth
: return "DW_AT_MIPS_software_pipeline_depth";
1655 case DW_AT_MIPS_linkage_name
: return "DW_AT_MIPS_linkage_name";
1656 case DW_AT_MIPS_stride
: return "DW_AT_MIPS_stride";
1657 case DW_AT_MIPS_abstract_name
: return "DW_AT_MIPS_abstract_name";
1658 case DW_AT_MIPS_clone_origin
: return "DW_AT_MIPS_clone_origin";
1659 case DW_AT_MIPS_has_inlines
: return "DW_AT_MIPS_has_inlines";
1661 /* HP Extensions. */
1662 case DW_AT_HP_block_index
: return "DW_AT_HP_block_index";
1663 case DW_AT_HP_actuals_stmt_list
: return "DW_AT_HP_actuals_stmt_list";
1664 case DW_AT_HP_proc_per_section
: return "DW_AT_HP_proc_per_section";
1665 case DW_AT_HP_raw_data_ptr
: return "DW_AT_HP_raw_data_ptr";
1666 case DW_AT_HP_pass_by_reference
: return "DW_AT_HP_pass_by_reference";
1667 case DW_AT_HP_opt_level
: return "DW_AT_HP_opt_level";
1668 case DW_AT_HP_prof_version_id
: return "DW_AT_HP_prof_version_id";
1669 case DW_AT_HP_opt_flags
: return "DW_AT_HP_opt_flags";
1670 case DW_AT_HP_cold_region_low_pc
: return "DW_AT_HP_cold_region_low_pc";
1671 case DW_AT_HP_cold_region_high_pc
: return "DW_AT_HP_cold_region_high_pc";
1672 case DW_AT_HP_all_variables_modifiable
: return "DW_AT_HP_all_variables_modifiable";
1673 case DW_AT_HP_linkage_name
: return "DW_AT_HP_linkage_name";
1674 case DW_AT_HP_prof_flags
: return "DW_AT_HP_prof_flags";
1676 /* One value is shared by the MIPS and HP extensions: */
1677 case DW_AT_MIPS_fde
: return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable";
1679 /* GNU extensions. */
1680 case DW_AT_sf_names
: return "DW_AT_sf_names";
1681 case DW_AT_src_info
: return "DW_AT_src_info";
1682 case DW_AT_mac_info
: return "DW_AT_mac_info";
1683 case DW_AT_src_coords
: return "DW_AT_src_coords";
1684 case DW_AT_body_begin
: return "DW_AT_body_begin";
1685 case DW_AT_body_end
: return "DW_AT_body_end";
1686 case DW_AT_GNU_vector
: return "DW_AT_GNU_vector";
1688 /* UPC extension. */
1689 case DW_AT_upc_threads_scaled
: return "DW_AT_upc_threads_scaled";
1691 /* PGI (STMicroelectronics) extensions. */
1692 case DW_AT_PGI_lbase
: return "DW_AT_PGI_lbase";
1693 case DW_AT_PGI_soffset
: return "DW_AT_PGI_soffset";
1694 case DW_AT_PGI_lstride
: return "DW_AT_PGI_lstride";
1698 static char buffer
[100];
1700 snprintf (buffer
, sizeof (buffer
), _("Unknown AT value: %lx"),
1707 static unsigned char *
1708 read_and_display_attr (unsigned long attribute
,
1710 unsigned char * data
,
1711 unsigned long cu_offset
,
1712 unsigned long pointer_size
,
1713 unsigned long offset_size
,
1715 debug_info
* debug_info_p
,
1717 struct dwarf_section
* section
)
1720 printf (" %-18s:", get_AT_name (attribute
));
1721 data
= read_and_display_attr_value (attribute
, form
, data
, cu_offset
,
1722 pointer_size
, offset_size
,
1723 dwarf_version
, debug_info_p
,
1731 /* Process the contents of a .debug_info section. If do_loc is non-zero
1732 then we are scanning for location lists and we do not want to display
1733 anything to the user. */
1736 process_debug_info (struct dwarf_section
*section
,
1740 unsigned char *start
= section
->start
;
1741 unsigned char *end
= start
+ section
->size
;
1742 unsigned char *section_begin
;
1744 unsigned int num_units
= 0;
1746 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
1747 && num_debug_info_entries
== 0)
1749 unsigned long length
;
1751 /* First scan the section to get the number of comp units. */
1752 for (section_begin
= start
, num_units
= 0; section_begin
< end
;
1755 /* Read the first 4 bytes. For a 32-bit DWARF section, this
1756 will be the length. For a 64-bit DWARF section, it'll be
1757 the escape code 0xffffffff followed by an 8 byte length. */
1758 length
= byte_get (section_begin
, 4);
1760 if (length
== 0xffffffff)
1762 length
= byte_get (section_begin
+ 4, 8);
1763 section_begin
+= length
+ 12;
1765 else if (length
>= 0xfffffff0 && length
< 0xffffffff)
1767 warn (_("Reserved length value (%lx) found in section %s\n"), length
, section
->name
);
1771 section_begin
+= length
+ 4;
1773 /* Negative values are illegal, they may even cause infinite
1774 looping. This can happen if we can't accurately apply
1775 relocations to an object file. */
1776 if ((signed long) length
<= 0)
1778 warn (_("Corrupt unit length (%lx) found in section %s\n"), length
, section
->name
);
1785 error (_("No comp units in %s section ?"), section
->name
);
1789 /* Then allocate an array to hold the information. */
1790 debug_information
= cmalloc (num_units
,
1791 sizeof (* debug_information
));
1792 if (debug_information
== NULL
)
1794 error (_("Not enough memory for a debug info array of %u entries"),
1802 printf (_("The section %s contains:\n\n"), section
->name
);
1804 load_debug_section (str
, file
);
1807 load_debug_section (abbrev
, file
);
1808 if (debug_displays
[abbrev
].section
.start
== NULL
)
1810 warn (_("Unable to locate %s section!\n"),
1811 debug_displays
[abbrev
].section
.name
);
1815 for (section_begin
= start
, unit
= 0; start
< end
; unit
++)
1817 DWARF2_Internal_CompUnit compunit
;
1818 unsigned char *hdrptr
;
1819 unsigned char *cu_abbrev_offset_ptr
;
1820 unsigned char *tags
;
1822 unsigned long cu_offset
;
1824 int initial_length_size
;
1828 compunit
.cu_length
= byte_get (hdrptr
, 4);
1831 if (compunit
.cu_length
== 0xffffffff)
1833 compunit
.cu_length
= byte_get (hdrptr
, 8);
1836 initial_length_size
= 12;
1841 initial_length_size
= 4;
1844 compunit
.cu_version
= byte_get (hdrptr
, 2);
1847 cu_offset
= start
- section_begin
;
1849 cu_abbrev_offset_ptr
= hdrptr
;
1850 compunit
.cu_abbrev_offset
= byte_get (hdrptr
, offset_size
);
1851 hdrptr
+= offset_size
;
1853 compunit
.cu_pointer_size
= byte_get (hdrptr
, 1);
1855 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
1856 && num_debug_info_entries
== 0)
1858 debug_information
[unit
].cu_offset
= cu_offset
;
1859 debug_information
[unit
].pointer_size
1860 = compunit
.cu_pointer_size
;
1861 debug_information
[unit
].base_address
= 0;
1862 debug_information
[unit
].loc_offsets
= NULL
;
1863 debug_information
[unit
].have_frame_base
= NULL
;
1864 debug_information
[unit
].max_loc_offsets
= 0;
1865 debug_information
[unit
].num_loc_offsets
= 0;
1866 debug_information
[unit
].range_lists
= NULL
;
1867 debug_information
[unit
].max_range_lists
= 0;
1868 debug_information
[unit
].num_range_lists
= 0;
1873 printf (_(" Compilation Unit @ offset 0x%lx:\n"), cu_offset
);
1874 printf (_(" Length: 0x%lx (%s)\n"), compunit
.cu_length
,
1875 initial_length_size
== 8 ? "64-bit" : "32-bit");
1876 printf (_(" Version: %d\n"), compunit
.cu_version
);
1877 printf (_(" Abbrev Offset: %ld\n"), compunit
.cu_abbrev_offset
);
1878 printf (_(" Pointer Size: %d\n"), compunit
.cu_pointer_size
);
1881 if (cu_offset
+ compunit
.cu_length
+ initial_length_size
1884 warn (_("Debug info is corrupted, length of CU at %lx extends beyond end of section (length = %lx)\n"),
1885 cu_offset
, compunit
.cu_length
);
1889 start
+= compunit
.cu_length
+ initial_length_size
;
1891 if (compunit
.cu_version
!= 2 && compunit
.cu_version
!= 3)
1893 warn (_("CU at offset %lx contains corrupt or unsupported version number: %d.\n"),
1894 cu_offset
, compunit
.cu_version
);
1900 /* Process the abbrevs used by this compilation unit. DWARF
1901 sections under Mach-O have non-zero addresses. */
1902 if (compunit
.cu_abbrev_offset
>= debug_displays
[abbrev
].section
.size
)
1903 warn (_("Debug info is corrupted, abbrev offset (%lx) is larger than abbrev section size (%lx)\n"),
1904 (unsigned long) compunit
.cu_abbrev_offset
,
1905 (unsigned long) debug_displays
[abbrev
].section
.size
);
1907 process_abbrev_section
1908 ((unsigned char *) debug_displays
[abbrev
].section
.start
1909 + compunit
.cu_abbrev_offset
- debug_displays
[abbrev
].section
.address
,
1910 (unsigned char *) debug_displays
[abbrev
].section
.start
1911 + debug_displays
[abbrev
].section
.size
);
1914 while (tags
< start
)
1916 unsigned int bytes_read
;
1917 unsigned long abbrev_number
;
1918 unsigned long die_offset
;
1919 abbrev_entry
*entry
;
1922 die_offset
= tags
- section_begin
;
1924 abbrev_number
= read_leb128 (tags
, & bytes_read
, 0);
1927 /* A null DIE marks the end of a list of siblings. */
1928 if (abbrev_number
== 0)
1933 static unsigned num_bogus_warns
= 0;
1935 if (num_bogus_warns
< 3)
1937 warn (_("Bogus end-of-siblings marker detected at offset %lx in .debug_info section\n"),
1940 if (num_bogus_warns
== 3)
1941 warn (_("Further warnings about bogus end-of-sibling markers suppressed\n"));
1948 printf (_(" <%d><%lx>: Abbrev Number: %lu"),
1949 level
, die_offset
, abbrev_number
);
1951 /* Scan through the abbreviation list until we reach the
1953 for (entry
= first_abbrev
;
1954 entry
&& entry
->entry
!= abbrev_number
;
1955 entry
= entry
->next
)
1965 warn (_("DIE at offset %lx refers to abbreviation number %lu which does not exist\n"),
1966 die_offset
, abbrev_number
);
1971 printf (_(" (%s)\n"), get_TAG_name (entry
->tag
));
1976 need_base_address
= 0;
1978 case DW_TAG_compile_unit
:
1979 need_base_address
= 1;
1981 case DW_TAG_entry_point
:
1982 case DW_TAG_subprogram
:
1983 need_base_address
= 0;
1984 /* Assuming that there is no DW_AT_frame_base. */
1985 have_frame_base
= 0;
1989 for (attr
= entry
->first_attr
; attr
; attr
= attr
->next
)
1992 /* Show the offset from where the tag was extracted. */
1993 printf (" <%2lx>", (unsigned long)(tags
- section_begin
));
1995 tags
= read_and_display_attr (attr
->attribute
,
1998 compunit
.cu_pointer_size
,
2000 compunit
.cu_version
,
2001 debug_information
+ unit
,
2005 if (entry
->children
)
2010 /* Set num_debug_info_entries here so that it can be used to check if
2011 we need to process .debug_loc and .debug_ranges sections. */
2012 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
2013 && num_debug_info_entries
== 0)
2014 num_debug_info_entries
= num_units
;
2024 /* Locate and scan the .debug_info section in the file and record the pointer
2025 sizes and offsets for the compilation units in it. Usually an executable
2026 will have just one pointer size, but this is not guaranteed, and so we try
2027 not to make any assumptions. Returns zero upon failure, or the number of
2028 compilation units upon success. */
2031 load_debug_info (void * file
)
2033 /* Reset the last pointer size so that we can issue correct error
2034 messages if we are displaying the contents of more than one section. */
2035 last_pointer_size
= 0;
2036 warned_about_missing_comp_units
= FALSE
;
2038 /* If we have already tried and failed to load the .debug_info
2039 section then do not bother to repear the task. */
2040 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
2043 /* If we already have the information there is nothing else to do. */
2044 if (num_debug_info_entries
> 0)
2045 return num_debug_info_entries
;
2047 if (load_debug_section (info
, file
)
2048 && process_debug_info (&debug_displays
[info
].section
, file
, 1))
2049 return num_debug_info_entries
;
2051 num_debug_info_entries
= DEBUG_INFO_UNAVAILABLE
;
2056 display_debug_lines_raw (struct dwarf_section
*section
,
2057 unsigned char *data
,
2060 unsigned char *start
= section
->start
;
2062 printf (_("Raw dump of debug contents of section %s:\n\n"),
2067 DWARF2_Internal_LineInfo info
;
2068 unsigned char *standard_opcodes
;
2069 unsigned char *end_of_sequence
;
2070 unsigned char *hdrptr
;
2071 unsigned long hdroff
;
2072 int initial_length_size
;
2077 hdroff
= hdrptr
- start
;
2079 /* Check the length of the block. */
2080 info
.li_length
= byte_get (hdrptr
, 4);
2083 if (info
.li_length
== 0xffffffff)
2085 /* This section is 64-bit DWARF 3. */
2086 info
.li_length
= byte_get (hdrptr
, 8);
2089 initial_length_size
= 12;
2094 initial_length_size
= 4;
2097 if (info
.li_length
+ initial_length_size
> section
->size
)
2100 (_("The line info appears to be corrupt - the section is too small\n"));
2104 /* Check its version number. */
2105 info
.li_version
= byte_get (hdrptr
, 2);
2107 if (info
.li_version
!= 2 && info
.li_version
!= 3)
2109 warn (_("Only DWARF version 2 and 3 line info is currently supported.\n"));
2113 info
.li_prologue_length
= byte_get (hdrptr
, offset_size
);
2114 hdrptr
+= offset_size
;
2115 info
.li_min_insn_length
= byte_get (hdrptr
, 1);
2117 info
.li_default_is_stmt
= byte_get (hdrptr
, 1);
2119 info
.li_line_base
= byte_get (hdrptr
, 1);
2121 info
.li_line_range
= byte_get (hdrptr
, 1);
2123 info
.li_opcode_base
= byte_get (hdrptr
, 1);
2126 /* Sign extend the line base field. */
2127 info
.li_line_base
<<= 24;
2128 info
.li_line_base
>>= 24;
2130 printf (_(" Offset: 0x%lx\n"), hdroff
);
2131 printf (_(" Length: %ld\n"), info
.li_length
);
2132 printf (_(" DWARF Version: %d\n"), info
.li_version
);
2133 printf (_(" Prologue Length: %d\n"), info
.li_prologue_length
);
2134 printf (_(" Minimum Instruction Length: %d\n"), info
.li_min_insn_length
);
2135 printf (_(" Initial value of 'is_stmt': %d\n"), info
.li_default_is_stmt
);
2136 printf (_(" Line Base: %d\n"), info
.li_line_base
);
2137 printf (_(" Line Range: %d\n"), info
.li_line_range
);
2138 printf (_(" Opcode Base: %d\n"), info
.li_opcode_base
);
2140 end_of_sequence
= data
+ info
.li_length
+ initial_length_size
;
2142 reset_state_machine (info
.li_default_is_stmt
);
2144 /* Display the contents of the Opcodes table. */
2145 standard_opcodes
= hdrptr
;
2147 printf (_("\n Opcodes:\n"));
2149 for (i
= 1; i
< info
.li_opcode_base
; i
++)
2150 printf (_(" Opcode %d has %d args\n"), i
, standard_opcodes
[i
- 1]);
2152 /* Display the contents of the Directory table. */
2153 data
= standard_opcodes
+ info
.li_opcode_base
- 1;
2156 printf (_("\n The Directory Table is empty.\n"));
2159 printf (_("\n The Directory Table:\n"));
2163 printf (_(" %s\n"), data
);
2165 data
+= strlen ((char *) data
) + 1;
2169 /* Skip the NUL at the end of the table. */
2172 /* Display the contents of the File Name table. */
2174 printf (_("\n The File Name Table is empty.\n"));
2177 printf (_("\n The File Name Table:\n"));
2178 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
2182 unsigned char *name
;
2183 unsigned int bytes_read
;
2185 printf (_(" %d\t"), ++state_machine_regs
.last_file_entry
);
2188 data
+= strlen ((char *) data
) + 1;
2190 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
2192 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
2194 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
2196 printf (_("%s\n"), name
);
2200 /* Skip the NUL at the end of the table. */
2203 /* Now display the statements. */
2204 printf (_("\n Line Number Statements:\n"));
2206 while (data
< end_of_sequence
)
2208 unsigned char op_code
;
2210 unsigned long int uladv
;
2211 unsigned int bytes_read
;
2215 if (op_code
>= info
.li_opcode_base
)
2217 op_code
-= info
.li_opcode_base
;
2218 uladv
= (op_code
/ info
.li_line_range
) * info
.li_min_insn_length
;
2219 state_machine_regs
.address
+= uladv
;
2220 printf (_(" Special opcode %d: advance Address by %lu to 0x%lx"),
2221 op_code
, uladv
, state_machine_regs
.address
);
2222 adv
= (op_code
% info
.li_line_range
) + info
.li_line_base
;
2223 state_machine_regs
.line
+= adv
;
2224 printf (_(" and Line by %d to %d\n"),
2225 adv
, state_machine_regs
.line
);
2227 else switch (op_code
)
2229 case DW_LNS_extended_op
:
2230 data
+= process_extended_line_op (data
, info
.li_default_is_stmt
);
2234 printf (_(" Copy\n"));
2237 case DW_LNS_advance_pc
:
2238 uladv
= read_leb128 (data
, & bytes_read
, 0);
2239 uladv
*= info
.li_min_insn_length
;
2241 state_machine_regs
.address
+= uladv
;
2242 printf (_(" Advance PC by %lu to 0x%lx\n"), uladv
,
2243 state_machine_regs
.address
);
2246 case DW_LNS_advance_line
:
2247 adv
= read_leb128 (data
, & bytes_read
, 1);
2249 state_machine_regs
.line
+= adv
;
2250 printf (_(" Advance Line by %d to %d\n"), adv
,
2251 state_machine_regs
.line
);
2254 case DW_LNS_set_file
:
2255 adv
= read_leb128 (data
, & bytes_read
, 0);
2257 printf (_(" Set File Name to entry %d in the File Name Table\n"),
2259 state_machine_regs
.file
= adv
;
2262 case DW_LNS_set_column
:
2263 uladv
= read_leb128 (data
, & bytes_read
, 0);
2265 printf (_(" Set column to %lu\n"), uladv
);
2266 state_machine_regs
.column
= uladv
;
2269 case DW_LNS_negate_stmt
:
2270 adv
= state_machine_regs
.is_stmt
;
2272 printf (_(" Set is_stmt to %d\n"), adv
);
2273 state_machine_regs
.is_stmt
= adv
;
2276 case DW_LNS_set_basic_block
:
2277 printf (_(" Set basic block\n"));
2278 state_machine_regs
.basic_block
= 1;
2281 case DW_LNS_const_add_pc
:
2282 uladv
= (((255 - info
.li_opcode_base
) / info
.li_line_range
)
2283 * info
.li_min_insn_length
);
2284 state_machine_regs
.address
+= uladv
;
2285 printf (_(" Advance PC by constant %lu to 0x%lx\n"), uladv
,
2286 state_machine_regs
.address
);
2289 case DW_LNS_fixed_advance_pc
:
2290 uladv
= byte_get (data
, 2);
2292 state_machine_regs
.address
+= uladv
;
2293 printf (_(" Advance PC by fixed size amount %lu to 0x%lx\n"),
2294 uladv
, state_machine_regs
.address
);
2297 case DW_LNS_set_prologue_end
:
2298 printf (_(" Set prologue_end to true\n"));
2301 case DW_LNS_set_epilogue_begin
:
2302 printf (_(" Set epilogue_begin to true\n"));
2305 case DW_LNS_set_isa
:
2306 uladv
= read_leb128 (data
, & bytes_read
, 0);
2308 printf (_(" Set ISA to %lu\n"), uladv
);
2312 printf (_(" Unknown opcode %d with operands: "), op_code
);
2314 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
2316 printf ("0x%lx%s", read_leb128 (data
, &bytes_read
, 0),
2317 i
== 1 ? "" : ", ");
2332 unsigned char *name
;
2333 unsigned int directory_index
;
2334 unsigned int modification_date
;
2335 unsigned int length
;
2338 /* Output a decoded representation of the .debug_line section. */
2341 display_debug_lines_decoded (struct dwarf_section
*section
,
2342 unsigned char *data
,
2345 printf (_("Decoded dump of debug contents of section %s:\n\n"),
2350 /* This loop amounts to one iteration per compilation unit. */
2351 DWARF2_Internal_LineInfo info
;
2352 unsigned char *standard_opcodes
;
2353 unsigned char *end_of_sequence
;
2354 unsigned char *hdrptr
;
2355 int initial_length_size
;
2358 File_Entry
*file_table
= NULL
;
2359 unsigned char **directory_table
= NULL
;
2360 unsigned int prev_line
= 0;
2364 /* Extract information from the Line Number Program Header.
2365 (section 6.2.4 in the Dwarf3 doc). */
2367 /* Get the length of this CU's line number information block. */
2368 info
.li_length
= byte_get (hdrptr
, 4);
2371 if (info
.li_length
== 0xffffffff)
2373 /* This section is 64-bit DWARF 3. */
2374 info
.li_length
= byte_get (hdrptr
, 8);
2377 initial_length_size
= 12;
2382 initial_length_size
= 4;
2385 if (info
.li_length
+ initial_length_size
> section
->size
)
2387 warn (_("The line info appears to be corrupt - "
2388 "the section is too small\n"));
2392 /* Get this CU's Line Number Block version number. */
2393 info
.li_version
= byte_get (hdrptr
, 2);
2395 if (info
.li_version
!= 2 && info
.li_version
!= 3)
2397 warn (_("Only DWARF version 2 and 3 line info is currently "
2402 info
.li_prologue_length
= byte_get (hdrptr
, offset_size
);
2403 hdrptr
+= offset_size
;
2404 info
.li_min_insn_length
= byte_get (hdrptr
, 1);
2406 info
.li_default_is_stmt
= byte_get (hdrptr
, 1);
2408 info
.li_line_base
= byte_get (hdrptr
, 1);
2410 info
.li_line_range
= byte_get (hdrptr
, 1);
2412 info
.li_opcode_base
= byte_get (hdrptr
, 1);
2415 /* Sign extend the line base field. */
2416 info
.li_line_base
<<= 24;
2417 info
.li_line_base
>>= 24;
2419 /* Find the end of this CU's Line Number Information Block. */
2420 end_of_sequence
= data
+ info
.li_length
+ initial_length_size
;
2422 reset_state_machine (info
.li_default_is_stmt
);
2424 /* Save a pointer to the contents of the Opcodes table. */
2425 standard_opcodes
= hdrptr
;
2427 /* Traverse the Directory table just to count entries. */
2428 data
= standard_opcodes
+ info
.li_opcode_base
- 1;
2431 unsigned int n_directories
= 0;
2432 unsigned char *ptr_directory_table
= data
;
2437 data
+= strlen ((char *) data
) + 1;
2441 /* Go through the directory table again to save the directories. */
2442 directory_table
= xmalloc (n_directories
* sizeof (unsigned char *));
2445 while (*ptr_directory_table
!= 0)
2447 directory_table
[i
] = ptr_directory_table
;
2448 ptr_directory_table
+= strlen ((char *) ptr_directory_table
) + 1;
2452 /* Skip the NUL at the end of the table. */
2455 /* Traverse the File Name table just to count the entries. */
2458 unsigned int n_files
= 0;
2459 unsigned char *ptr_file_name_table
= data
;
2464 unsigned int bytes_read
;
2466 /* Skip Name, directory index, last modification time and length
2468 data
+= strlen ((char *) data
) + 1;
2469 read_leb128 (data
, & bytes_read
, 0);
2471 read_leb128 (data
, & bytes_read
, 0);
2473 read_leb128 (data
, & bytes_read
, 0);
2479 /* Go through the file table again to save the strings. */
2480 file_table
= xmalloc (n_files
* sizeof (File_Entry
));
2483 while (*ptr_file_name_table
!= 0)
2485 unsigned int bytes_read
;
2487 file_table
[i
].name
= ptr_file_name_table
;
2488 ptr_file_name_table
+= strlen ((char *) ptr_file_name_table
) + 1;
2490 /* We are not interested in directory, time or size. */
2491 file_table
[i
].directory_index
= read_leb128 (ptr_file_name_table
,
2493 ptr_file_name_table
+= bytes_read
;
2494 file_table
[i
].modification_date
= read_leb128 (ptr_file_name_table
,
2496 ptr_file_name_table
+= bytes_read
;
2497 file_table
[i
].length
= read_leb128 (ptr_file_name_table
, & bytes_read
, 0);
2498 ptr_file_name_table
+= bytes_read
;
2503 /* Print the Compilation Unit's name and a header. */
2504 if (directory_table
== NULL
)
2506 printf (_("CU: %s:\n"), file_table
[0].name
);
2507 printf (_("File name Line number Starting address\n"));
2511 if (do_wide
|| strlen ((char *) directory_table
[0]) < 76)
2513 printf (_("CU: %s/%s:\n"), directory_table
[0],
2514 file_table
[0].name
);
2518 printf (_("%s:\n"), file_table
[0].name
);
2520 printf (_("File name Line number Starting address\n"));
2524 /* Skip the NUL at the end of the table. */
2527 /* This loop iterates through the Dwarf Line Number Program. */
2528 while (data
< end_of_sequence
)
2530 unsigned char op_code
;
2532 unsigned long int uladv
;
2533 unsigned int bytes_read
;
2534 int is_special_opcode
= 0;
2537 prev_line
= state_machine_regs
.line
;
2539 if (op_code
>= info
.li_opcode_base
)
2541 op_code
-= info
.li_opcode_base
;
2542 uladv
= (op_code
/ info
.li_line_range
) * info
.li_min_insn_length
;
2543 state_machine_regs
.address
+= uladv
;
2545 adv
= (op_code
% info
.li_line_range
) + info
.li_line_base
;
2546 state_machine_regs
.line
+= adv
;
2547 is_special_opcode
= 1;
2549 else switch (op_code
)
2551 case DW_LNS_extended_op
:
2553 unsigned int ext_op_code_len
;
2554 unsigned int bytes_read
;
2555 unsigned char ext_op_code
;
2556 unsigned char *op_code_data
= data
;
2558 ext_op_code_len
= read_leb128 (op_code_data
, &bytes_read
, 0);
2559 op_code_data
+= bytes_read
;
2561 if (ext_op_code_len
== 0)
2563 warn (_("badly formed extended line op encountered!\n"));
2566 ext_op_code_len
+= bytes_read
;
2567 ext_op_code
= *op_code_data
++;
2569 switch (ext_op_code
)
2571 case DW_LNE_end_sequence
:
2572 reset_state_machine (info
.li_default_is_stmt
);
2574 case DW_LNE_set_address
:
2575 state_machine_regs
.address
=
2576 byte_get (op_code_data
, ext_op_code_len
- bytes_read
- 1);
2578 case DW_LNE_define_file
:
2580 unsigned int dir_index
= 0;
2582 ++state_machine_regs
.last_file_entry
;
2583 op_code_data
+= strlen ((char *) op_code_data
) + 1;
2584 dir_index
= read_leb128 (op_code_data
, & bytes_read
, 0);
2585 op_code_data
+= bytes_read
;
2586 read_leb128 (op_code_data
, & bytes_read
, 0);
2587 op_code_data
+= bytes_read
;
2588 read_leb128 (op_code_data
, & bytes_read
, 0);
2590 printf (_("%s:\n"), directory_table
[dir_index
]);
2594 printf (_("UNKNOWN: length %d\n"), ext_op_code_len
- bytes_read
);
2597 data
+= ext_op_code_len
;
2603 case DW_LNS_advance_pc
:
2604 uladv
= read_leb128 (data
, & bytes_read
, 0);
2605 uladv
*= info
.li_min_insn_length
;
2607 state_machine_regs
.address
+= uladv
;
2610 case DW_LNS_advance_line
:
2611 adv
= read_leb128 (data
, & bytes_read
, 1);
2613 state_machine_regs
.line
+= adv
;
2616 case DW_LNS_set_file
:
2617 adv
= read_leb128 (data
, & bytes_read
, 0);
2619 state_machine_regs
.file
= adv
;
2620 if (file_table
[state_machine_regs
.file
- 1].directory_index
== 0)
2622 /* If directory index is 0, that means current directory. */
2623 printf (_("\n./%s:[++]\n"),
2624 file_table
[state_machine_regs
.file
- 1].name
);
2628 /* The directory index starts counting at 1. */
2629 printf (_("\n%s/%s:\n"),
2630 directory_table
[file_table
[state_machine_regs
.file
- 1].directory_index
- 1],
2631 file_table
[state_machine_regs
.file
- 1].name
);
2635 case DW_LNS_set_column
:
2636 uladv
= read_leb128 (data
, & bytes_read
, 0);
2638 state_machine_regs
.column
= uladv
;
2641 case DW_LNS_negate_stmt
:
2642 adv
= state_machine_regs
.is_stmt
;
2644 state_machine_regs
.is_stmt
= adv
;
2647 case DW_LNS_set_basic_block
:
2648 state_machine_regs
.basic_block
= 1;
2651 case DW_LNS_const_add_pc
:
2652 uladv
= (((255 - info
.li_opcode_base
) / info
.li_line_range
)
2653 * info
.li_min_insn_length
);
2654 state_machine_regs
.address
+= uladv
;
2657 case DW_LNS_fixed_advance_pc
:
2658 uladv
= byte_get (data
, 2);
2660 state_machine_regs
.address
+= uladv
;
2663 case DW_LNS_set_prologue_end
:
2666 case DW_LNS_set_epilogue_begin
:
2669 case DW_LNS_set_isa
:
2670 uladv
= read_leb128 (data
, & bytes_read
, 0);
2672 printf (_(" Set ISA to %lu\n"), uladv
);
2676 printf (_(" Unknown opcode %d with operands: "), op_code
);
2678 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
2680 printf ("0x%lx%s", read_leb128 (data
, &bytes_read
, 0),
2681 i
== 1 ? "" : ", ");
2688 /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row
2689 to the DWARF address/line matrix. */
2690 if ((is_special_opcode
) || (op_code
== DW_LNE_end_sequence
)
2691 || (op_code
== DW_LNS_copy
))
2693 const unsigned int MAX_FILENAME_LENGTH
= 35;
2694 char *fileName
= (char *)file_table
[state_machine_regs
.file
- 1].name
;
2695 char *newFileName
= NULL
;
2696 size_t fileNameLength
= strlen (fileName
);
2698 if ((fileNameLength
> MAX_FILENAME_LENGTH
) && (!do_wide
))
2700 newFileName
= xmalloc (MAX_FILENAME_LENGTH
+ 1);
2701 /* Truncate file name */
2702 strncpy (newFileName
,
2703 fileName
+ fileNameLength
- MAX_FILENAME_LENGTH
,
2704 MAX_FILENAME_LENGTH
+ 1);
2708 newFileName
= xmalloc (fileNameLength
+ 1);
2709 strncpy (newFileName
, fileName
, fileNameLength
+ 1);
2712 if (!do_wide
|| (fileNameLength
<= MAX_FILENAME_LENGTH
))
2714 printf (_("%-35s %11d %#18lx\n"), newFileName
,
2715 state_machine_regs
.line
, state_machine_regs
.address
);
2719 printf (_("%s %11d %#18lx\n"), newFileName
,
2720 state_machine_regs
.line
, state_machine_regs
.address
);
2723 if (op_code
== DW_LNE_end_sequence
)
2731 free (directory_table
);
2732 directory_table
= NULL
;
2740 display_debug_lines (struct dwarf_section
*section
, void *file
)
2742 unsigned char *data
= section
->start
;
2743 unsigned char *end
= data
+ section
->size
;
2745 int retValDecoded
= 0;
2747 if (load_debug_info (file
) == 0)
2749 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
2755 retValRaw
= display_debug_lines_raw (section
, data
, end
);
2757 if (do_debug_lines_decoded
)
2758 retValDecoded
= display_debug_lines_decoded (section
, data
, end
);
2760 if ((do_debug_lines
&& !retValRaw
)
2761 || (do_debug_lines_decoded
&& !retValDecoded
))
2768 find_debug_info_for_offset (unsigned long offset
)
2772 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
2775 for (i
= 0; i
< num_debug_info_entries
; i
++)
2776 if (debug_information
[i
].cu_offset
== offset
)
2777 return debug_information
+ i
;
2783 display_debug_pubnames (struct dwarf_section
*section
,
2784 void *file ATTRIBUTE_UNUSED
)
2786 DWARF2_Internal_PubNames pubnames
;
2787 unsigned char *start
= section
->start
;
2788 unsigned char *end
= start
+ section
->size
;
2790 /* It does not matter if this load fails,
2791 we test for that later on. */
2792 load_debug_info (file
);
2794 printf (_("Contents of the %s section:\n\n"), section
->name
);
2798 unsigned char *data
;
2799 unsigned long offset
;
2800 int offset_size
, initial_length_size
;
2804 pubnames
.pn_length
= byte_get (data
, 4);
2806 if (pubnames
.pn_length
== 0xffffffff)
2808 pubnames
.pn_length
= byte_get (data
, 8);
2811 initial_length_size
= 12;
2816 initial_length_size
= 4;
2819 pubnames
.pn_version
= byte_get (data
, 2);
2822 pubnames
.pn_offset
= byte_get (data
, offset_size
);
2823 data
+= offset_size
;
2825 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
2826 && num_debug_info_entries
> 0
2827 && find_debug_info_for_offset (pubnames
.pn_offset
) == NULL
)
2828 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
2829 pubnames
.pn_offset
, section
->name
);
2831 pubnames
.pn_size
= byte_get (data
, offset_size
);
2832 data
+= offset_size
;
2834 start
+= pubnames
.pn_length
+ initial_length_size
;
2836 if (pubnames
.pn_version
!= 2 && pubnames
.pn_version
!= 3)
2838 static int warned
= 0;
2842 warn (_("Only DWARF 2 and 3 pubnames are currently supported\n"));
2849 printf (_(" Length: %ld\n"),
2850 pubnames
.pn_length
);
2851 printf (_(" Version: %d\n"),
2852 pubnames
.pn_version
);
2853 printf (_(" Offset into .debug_info section: 0x%lx\n"),
2854 pubnames
.pn_offset
);
2855 printf (_(" Size of area in .debug_info section: %ld\n"),
2858 printf (_("\n Offset\tName\n"));
2862 offset
= byte_get (data
, offset_size
);
2866 data
+= offset_size
;
2867 printf (" %-6ld\t\t%s\n", offset
, data
);
2868 data
+= strlen ((char *) data
) + 1;
2871 while (offset
!= 0);
2879 display_debug_macinfo (struct dwarf_section
*section
,
2880 void *file ATTRIBUTE_UNUSED
)
2882 unsigned char *start
= section
->start
;
2883 unsigned char *end
= start
+ section
->size
;
2884 unsigned char *curr
= start
;
2885 unsigned int bytes_read
;
2886 enum dwarf_macinfo_record_type op
;
2888 printf (_("Contents of the %s section:\n\n"), section
->name
);
2892 unsigned int lineno
;
2900 case DW_MACINFO_start_file
:
2902 unsigned int filenum
;
2904 lineno
= read_leb128 (curr
, & bytes_read
, 0);
2906 filenum
= read_leb128 (curr
, & bytes_read
, 0);
2909 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"),
2914 case DW_MACINFO_end_file
:
2915 printf (_(" DW_MACINFO_end_file\n"));
2918 case DW_MACINFO_define
:
2919 lineno
= read_leb128 (curr
, & bytes_read
, 0);
2921 string
= (char *) curr
;
2922 curr
+= strlen (string
) + 1;
2923 printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"),
2927 case DW_MACINFO_undef
:
2928 lineno
= read_leb128 (curr
, & bytes_read
, 0);
2930 string
= (char *) curr
;
2931 curr
+= strlen (string
) + 1;
2932 printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"),
2936 case DW_MACINFO_vendor_ext
:
2938 unsigned int constant
;
2940 constant
= read_leb128 (curr
, & bytes_read
, 0);
2942 string
= (char *) curr
;
2943 curr
+= strlen (string
) + 1;
2944 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"),
2955 display_debug_abbrev (struct dwarf_section
*section
,
2956 void *file ATTRIBUTE_UNUSED
)
2958 abbrev_entry
*entry
;
2959 unsigned char *start
= section
->start
;
2960 unsigned char *end
= start
+ section
->size
;
2962 printf (_("Contents of the %s section:\n\n"), section
->name
);
2968 start
= process_abbrev_section (start
, end
);
2970 if (first_abbrev
== NULL
)
2973 printf (_(" Number TAG\n"));
2975 for (entry
= first_abbrev
; entry
; entry
= entry
->next
)
2979 printf (_(" %ld %s [%s]\n"),
2981 get_TAG_name (entry
->tag
),
2982 entry
->children
? _("has children") : _("no children"));
2984 for (attr
= entry
->first_attr
; attr
; attr
= attr
->next
)
2985 printf (_(" %-18s %s\n"),
2986 get_AT_name (attr
->attribute
),
2987 get_FORM_name (attr
->form
));
2998 display_debug_loc (struct dwarf_section
*section
, void *file
)
3000 unsigned char *start
= section
->start
;
3001 unsigned char *section_end
;
3002 unsigned long bytes
;
3003 unsigned char *section_begin
= start
;
3004 unsigned int num_loc_list
= 0;
3005 unsigned long last_offset
= 0;
3006 unsigned int first
= 0;
3009 int seen_first_offset
= 0;
3010 int use_debug_info
= 1;
3011 unsigned char *next
;
3013 bytes
= section
->size
;
3014 section_end
= start
+ bytes
;
3018 printf (_("\nThe %s section is empty.\n"), section
->name
);
3022 if (load_debug_info (file
) == 0)
3024 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
3029 /* Check the order of location list in .debug_info section. If
3030 offsets of location lists are in the ascending order, we can
3031 use `debug_information' directly. */
3032 for (i
= 0; i
< num_debug_info_entries
; i
++)
3036 num
= debug_information
[i
].num_loc_offsets
;
3037 num_loc_list
+= num
;
3039 /* Check if we can use `debug_information' directly. */
3040 if (use_debug_info
&& num
!= 0)
3042 if (!seen_first_offset
)
3044 /* This is the first location list. */
3045 last_offset
= debug_information
[i
].loc_offsets
[0];
3047 seen_first_offset
= 1;
3053 for (; j
< num
; j
++)
3056 debug_information
[i
].loc_offsets
[j
])
3061 last_offset
= debug_information
[i
].loc_offsets
[j
];
3066 if (!use_debug_info
)
3067 /* FIXME: Should we handle this case? */
3068 error (_("Location lists in .debug_info section aren't in ascending order!\n"));
3070 if (!seen_first_offset
)
3071 error (_("No location lists in .debug_info section!\n"));
3073 /* DWARF sections under Mach-O have non-zero addresses. */
3074 if (debug_information
[first
].num_loc_offsets
> 0
3075 && debug_information
[first
].loc_offsets
[0] != section
->address
)
3076 warn (_("Location lists in %s section start at 0x%lx\n"),
3077 section
->name
, debug_information
[first
].loc_offsets
[0]);
3079 printf (_("Contents of the %s section:\n\n"), section
->name
);
3080 printf (_(" Offset Begin End Expression\n"));
3082 seen_first_offset
= 0;
3083 for (i
= first
; i
< num_debug_info_entries
; i
++)
3087 unsigned short length
;
3088 unsigned long offset
;
3089 unsigned int pointer_size
;
3090 unsigned long cu_offset
;
3091 unsigned long base_address
;
3092 int need_frame_base
;
3095 pointer_size
= debug_information
[i
].pointer_size
;
3096 cu_offset
= debug_information
[i
].cu_offset
;
3098 for (j
= 0; j
< debug_information
[i
].num_loc_offsets
; j
++)
3100 has_frame_base
= debug_information
[i
].have_frame_base
[j
];
3101 /* DWARF sections under Mach-O have non-zero addresses. */
3102 offset
= debug_information
[i
].loc_offsets
[j
] - section
->address
;
3103 next
= section_begin
+ offset
;
3104 base_address
= debug_information
[i
].base_address
;
3106 if (!seen_first_offset
)
3107 seen_first_offset
= 1;
3111 warn (_("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n"),
3112 (unsigned long) (start
- section_begin
),
3113 (unsigned long) (next
- section_begin
));
3114 else if (start
> next
)
3115 warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n"),
3116 (unsigned long) (start
- section_begin
),
3117 (unsigned long) (next
- section_begin
));
3121 if (offset
>= bytes
)
3123 warn (_("Offset 0x%lx is bigger than .debug_loc section size.\n"),
3130 if (start
+ 2 * pointer_size
> section_end
)
3132 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
3137 /* Note: we use sign extension here in order to be sure that
3138 we can detect the -1 escape value. Sign extension into the
3139 top 32 bits of a 32-bit address will not affect the values
3140 that we display since we always show hex values, and always
3141 the bottom 32-bits. */
3142 begin
= byte_get_signed (start
, pointer_size
);
3143 start
+= pointer_size
;
3144 end
= byte_get_signed (start
, pointer_size
);
3145 start
+= pointer_size
;
3147 printf (" %8.8lx ", offset
);
3149 if (begin
== 0 && end
== 0)
3151 printf (_("<End of list>\n"));
3155 /* Check base address specifiers. */
3156 if (begin
== (dwarf_vma
) -1 && end
!= (dwarf_vma
) -1)
3159 print_dwarf_vma (begin
, pointer_size
);
3160 print_dwarf_vma (end
, pointer_size
);
3161 printf (_("(base address)\n"));
3165 if (start
+ 2 > section_end
)
3167 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
3172 length
= byte_get (start
, 2);
3175 if (start
+ length
> section_end
)
3177 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
3182 print_dwarf_vma (begin
+ base_address
, pointer_size
);
3183 print_dwarf_vma (end
+ base_address
, pointer_size
);
3186 need_frame_base
= decode_location_expression (start
,
3192 if (need_frame_base
&& !has_frame_base
)
3193 printf (_(" [without DW_AT_frame_base]"));
3196 fputs (_(" (start == end)"), stdout
);
3197 else if (begin
> end
)
3198 fputs (_(" (start > end)"), stdout
);
3207 if (start
< section_end
)
3208 warn (_("There are %ld unused bytes at the end of section %s\n"),
3209 (long) (section_end
- start
), section
->name
);
3214 display_debug_str (struct dwarf_section
*section
,
3215 void *file ATTRIBUTE_UNUSED
)
3217 unsigned char *start
= section
->start
;
3218 unsigned long bytes
= section
->size
;
3219 dwarf_vma addr
= section
->address
;
3223 printf (_("\nThe %s section is empty.\n"), section
->name
);
3227 printf (_("Contents of the %s section:\n\n"), section
->name
);
3235 lbytes
= (bytes
> 16 ? 16 : bytes
);
3237 printf (" 0x%8.8lx ", (unsigned long) addr
);
3239 for (j
= 0; j
< 16; j
++)
3242 printf ("%2.2x", start
[j
]);
3250 for (j
= 0; j
< lbytes
; j
++)
3253 if (k
>= ' ' && k
< 0x80)
3272 display_debug_info (struct dwarf_section
*section
, void *file
)
3274 return process_debug_info (section
, file
, 0);
3279 display_debug_aranges (struct dwarf_section
*section
,
3280 void *file ATTRIBUTE_UNUSED
)
3282 unsigned char *start
= section
->start
;
3283 unsigned char *end
= start
+ section
->size
;
3285 printf (_("The section %s contains:\n\n"), section
->name
);
3287 /* It does not matter if this load fails,
3288 we test for that later on. */
3289 load_debug_info (file
);
3293 unsigned char *hdrptr
;
3294 DWARF2_Internal_ARange arange
;
3295 unsigned char *ranges
;
3298 unsigned char address_size
;
3301 int initial_length_size
;
3305 arange
.ar_length
= byte_get (hdrptr
, 4);
3308 if (arange
.ar_length
== 0xffffffff)
3310 arange
.ar_length
= byte_get (hdrptr
, 8);
3313 initial_length_size
= 12;
3318 initial_length_size
= 4;
3321 arange
.ar_version
= byte_get (hdrptr
, 2);
3324 arange
.ar_info_offset
= byte_get (hdrptr
, offset_size
);
3325 hdrptr
+= offset_size
;
3327 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
3328 && num_debug_info_entries
> 0
3329 && find_debug_info_for_offset (arange
.ar_info_offset
) == NULL
)
3330 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
3331 arange
.ar_info_offset
, section
->name
);
3333 arange
.ar_pointer_size
= byte_get (hdrptr
, 1);
3336 arange
.ar_segment_size
= byte_get (hdrptr
, 1);
3339 if (arange
.ar_version
!= 2 && arange
.ar_version
!= 3)
3341 warn (_("Only DWARF 2 and 3 aranges are currently supported.\n"));
3345 printf (_(" Length: %ld\n"), arange
.ar_length
);
3346 printf (_(" Version: %d\n"), arange
.ar_version
);
3347 printf (_(" Offset into .debug_info: 0x%lx\n"), arange
.ar_info_offset
);
3348 printf (_(" Pointer Size: %d\n"), arange
.ar_pointer_size
);
3349 printf (_(" Segment Size: %d\n"), arange
.ar_segment_size
);
3351 address_size
= arange
.ar_pointer_size
+ arange
.ar_segment_size
;
3353 /* The DWARF spec does not require that the address size be a power
3354 of two, but we do. This will have to change if we ever encounter
3355 an uneven architecture. */
3356 if ((address_size
& (address_size
- 1)) != 0)
3358 warn (_("Pointer size + Segment size is not a power of two.\n"));
3362 if (address_size
> 4)
3363 printf (_("\n Address Length\n"));
3365 printf (_("\n Address Length\n"));
3369 /* Must pad to an alignment boundary that is twice the address size. */
3370 excess
= (hdrptr
- start
) % (2 * address_size
);
3372 ranges
+= (2 * address_size
) - excess
;
3374 start
+= arange
.ar_length
+ initial_length_size
;
3376 while (ranges
+ 2 * address_size
<= start
)
3378 address
= byte_get (ranges
, address_size
);
3380 ranges
+= address_size
;
3382 length
= byte_get (ranges
, address_size
);
3384 ranges
+= address_size
;
3386 print_dwarf_vma (address
, address_size
);
3387 print_dwarf_vma (length
, address_size
);
3398 display_debug_ranges (struct dwarf_section
*section
,
3399 void *file ATTRIBUTE_UNUSED
)
3401 unsigned char *start
= section
->start
;
3402 unsigned char *section_end
;
3403 unsigned long bytes
;
3404 unsigned char *section_begin
= start
;
3405 unsigned int num_range_list
= 0;
3406 unsigned long last_offset
= 0;
3407 unsigned int first
= 0;
3410 int seen_first_offset
= 0;
3411 int use_debug_info
= 1;
3412 unsigned char *next
;
3414 bytes
= section
->size
;
3415 section_end
= start
+ bytes
;
3419 printf (_("\nThe %s section is empty.\n"), section
->name
);
3423 if (load_debug_info (file
) == 0)
3425 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
3430 /* Check the order of range list in .debug_info section. If
3431 offsets of range lists are in the ascending order, we can
3432 use `debug_information' directly. */
3433 for (i
= 0; i
< num_debug_info_entries
; i
++)
3437 num
= debug_information
[i
].num_range_lists
;
3438 num_range_list
+= num
;
3440 /* Check if we can use `debug_information' directly. */
3441 if (use_debug_info
&& num
!= 0)
3443 if (!seen_first_offset
)
3445 /* This is the first range list. */
3446 last_offset
= debug_information
[i
].range_lists
[0];
3448 seen_first_offset
= 1;
3454 for (; j
< num
; j
++)
3457 debug_information
[i
].range_lists
[j
])
3462 last_offset
= debug_information
[i
].range_lists
[j
];
3467 if (!use_debug_info
)
3468 /* FIXME: Should we handle this case? */
3469 error (_("Range lists in .debug_info section aren't in ascending order!\n"));
3471 if (!seen_first_offset
)
3472 error (_("No range lists in .debug_info section!\n"));
3474 /* DWARF sections under Mach-O have non-zero addresses. */
3475 if (debug_information
[first
].num_range_lists
> 0
3476 && debug_information
[first
].range_lists
[0] != section
->address
)
3477 warn (_("Range lists in %s section start at 0x%lx\n"),
3478 section
->name
, debug_information
[first
].range_lists
[0]);
3480 printf (_("Contents of the %s section:\n\n"), section
->name
);
3481 printf (_(" Offset Begin End\n"));
3483 seen_first_offset
= 0;
3484 for (i
= first
; i
< num_debug_info_entries
; i
++)
3488 unsigned long offset
;
3489 unsigned int pointer_size
;
3490 unsigned long base_address
;
3492 pointer_size
= debug_information
[i
].pointer_size
;
3494 for (j
= 0; j
< debug_information
[i
].num_range_lists
; j
++)
3496 /* DWARF sections under Mach-O have non-zero addresses. */
3497 offset
= debug_information
[i
].range_lists
[j
] - section
->address
;
3498 next
= section_begin
+ offset
;
3499 base_address
= debug_information
[i
].base_address
;
3501 if (!seen_first_offset
)
3502 seen_first_offset
= 1;
3506 warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"),
3507 (unsigned long) (start
- section_begin
),
3508 (unsigned long) (next
- section_begin
), section
->name
);
3509 else if (start
> next
)
3510 warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"),
3511 (unsigned long) (start
- section_begin
),
3512 (unsigned long) (next
- section_begin
), section
->name
);
3518 /* Note: we use sign extension here in order to be sure that
3519 we can detect the -1 escape value. Sign extension into the
3520 top 32 bits of a 32-bit address will not affect the values
3521 that we display since we always show hex values, and always
3522 the bottom 32-bits. */
3523 begin
= byte_get_signed (start
, pointer_size
);
3524 start
+= pointer_size
;
3525 end
= byte_get_signed (start
, pointer_size
);
3526 start
+= pointer_size
;
3528 printf (" %8.8lx ", offset
);
3530 if (begin
== 0 && end
== 0)
3532 printf (_("<End of list>\n"));
3536 print_dwarf_vma (begin
, pointer_size
);
3537 print_dwarf_vma (end
, pointer_size
);
3539 /* Check base address specifiers. */
3540 if (begin
== (dwarf_vma
) -1 && end
!= (dwarf_vma
) -1)
3543 printf ("(base address)\n");
3548 fputs (_("(start == end)"), stdout
);
3549 else if (begin
> end
)
3550 fputs (_("(start > end)"), stdout
);
3560 typedef struct Frame_Chunk
3562 struct Frame_Chunk
*next
;
3563 unsigned char *chunk_start
;
3565 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
3566 short int *col_type
;
3569 unsigned int code_factor
;
3571 unsigned long pc_begin
;
3572 unsigned long pc_range
;
3576 unsigned char fde_encoding
;
3577 unsigned char cfa_exp
;
3581 /* A marker for a col_type that means this column was never referenced
3582 in the frame info. */
3583 #define DW_CFA_unreferenced (-1)
3586 frame_need_space (Frame_Chunk
*fc
, int reg
)
3588 int prev
= fc
->ncols
;
3590 if (reg
< fc
->ncols
)
3593 fc
->ncols
= reg
+ 1;
3594 fc
->col_type
= xcrealloc (fc
->col_type
, fc
->ncols
, sizeof (short int));
3595 fc
->col_offset
= xcrealloc (fc
->col_offset
, fc
->ncols
, sizeof (int));
3597 while (prev
< fc
->ncols
)
3599 fc
->col_type
[prev
] = DW_CFA_unreferenced
;
3600 fc
->col_offset
[prev
] = 0;
3605 static const char *const dwarf_regnames_i386
[] =
3607 "eax", "ecx", "edx", "ebx",
3608 "esp", "ebp", "esi", "edi",
3609 "eip", "eflags", NULL
,
3610 "st0", "st1", "st2", "st3",
3611 "st4", "st5", "st6", "st7",
3613 "xmm0", "xmm1", "xmm2", "xmm3",
3614 "xmm4", "xmm5", "xmm6", "xmm7",
3615 "mm0", "mm1", "mm2", "mm3",
3616 "mm4", "mm5", "mm6", "mm7",
3617 "fcw", "fsw", "mxcsr",
3618 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
,
3622 static const char *const dwarf_regnames_x86_64
[] =
3624 "rax", "rdx", "rcx", "rbx",
3625 "rsi", "rdi", "rbp", "rsp",
3626 "r8", "r9", "r10", "r11",
3627 "r12", "r13", "r14", "r15",
3629 "xmm0", "xmm1", "xmm2", "xmm3",
3630 "xmm4", "xmm5", "xmm6", "xmm7",
3631 "xmm8", "xmm9", "xmm10", "xmm11",
3632 "xmm12", "xmm13", "xmm14", "xmm15",
3633 "st0", "st1", "st2", "st3",
3634 "st4", "st5", "st6", "st7",
3635 "mm0", "mm1", "mm2", "mm3",
3636 "mm4", "mm5", "mm6", "mm7",
3638 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
,
3639 "fs.base", "gs.base", NULL
, NULL
,
3641 "mxcsr", "fcw", "fsw"
3644 static const char *const *dwarf_regnames
;
3645 static unsigned int dwarf_regnames_count
;
3648 init_dwarf_regnames (unsigned int e_machine
)
3654 dwarf_regnames
= dwarf_regnames_i386
;
3655 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_i386
);
3659 dwarf_regnames
= dwarf_regnames_x86_64
;
3660 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_x86_64
);
3669 regname (unsigned int regno
, int row
)
3671 static char reg
[64];
3673 && regno
< dwarf_regnames_count
3674 && dwarf_regnames
[regno
] != NULL
)
3677 return dwarf_regnames
[regno
];
3678 snprintf (reg
, sizeof (reg
), "r%d (%s)", regno
,
3679 dwarf_regnames
[regno
]);
3682 snprintf (reg
, sizeof (reg
), "r%d", regno
);
3687 frame_display_row (Frame_Chunk
*fc
, int *need_col_headers
, int *max_regs
)
3692 if (*max_regs
< fc
->ncols
)
3693 *max_regs
= fc
->ncols
;
3695 if (*need_col_headers
)
3697 static const char *loc
= " LOC";
3699 *need_col_headers
= 0;
3701 printf ("%-*s CFA ", eh_addr_size
* 2, loc
);
3703 for (r
= 0; r
< *max_regs
; r
++)
3704 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
3709 printf ("%-5s ", regname (r
, 1));
3715 printf ("%0*lx ", eh_addr_size
* 2, fc
->pc_begin
);
3717 strcpy (tmp
, "exp");
3719 sprintf (tmp
, "%s%+d", regname (fc
->cfa_reg
, 1), fc
->cfa_offset
);
3720 printf ("%-8s ", tmp
);
3722 for (r
= 0; r
< fc
->ncols
; r
++)
3724 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
3726 switch (fc
->col_type
[r
])
3728 case DW_CFA_undefined
:
3731 case DW_CFA_same_value
:
3735 sprintf (tmp
, "c%+d", fc
->col_offset
[r
]);
3737 case DW_CFA_val_offset
:
3738 sprintf (tmp
, "v%+d", fc
->col_offset
[r
]);
3740 case DW_CFA_register
:
3741 sprintf (tmp
, "%s", regname (fc
->col_offset
[r
], 0));
3743 case DW_CFA_expression
:
3744 strcpy (tmp
, "exp");
3746 case DW_CFA_val_expression
:
3747 strcpy (tmp
, "vexp");
3750 strcpy (tmp
, "n/a");
3753 printf ("%-5s ", tmp
);
3760 size_of_encoded_value (int encoding
)
3762 switch (encoding
& 0x7)
3765 case 0: return eh_addr_size
;
3773 get_encoded_value (unsigned char *data
, int encoding
)
3775 int size
= size_of_encoded_value (encoding
);
3777 if (encoding
& DW_EH_PE_signed
)
3778 return byte_get_signed (data
, size
);
3780 return byte_get (data
, size
);
3783 #define GET(N) byte_get (start, N); start += N
3784 #define LEB() read_leb128 (start, & length_return, 0); start += length_return
3785 #define SLEB() read_leb128 (start, & length_return, 1); start += length_return
3788 display_debug_frames (struct dwarf_section
*section
,
3789 void *file ATTRIBUTE_UNUSED
)
3791 unsigned char *start
= section
->start
;
3792 unsigned char *end
= start
+ section
->size
;
3793 unsigned char *section_start
= start
;
3794 Frame_Chunk
*chunks
= 0;
3795 Frame_Chunk
*remembered_state
= 0;
3797 int is_eh
= strcmp (section
->name
, ".eh_frame") == 0;
3798 unsigned int length_return
;
3801 printf (_("The section %s contains:\n"), section
->name
);
3805 unsigned char *saved_start
;
3806 unsigned char *block_end
;
3807 unsigned long length
;
3808 unsigned long cie_id
;
3811 int need_col_headers
= 1;
3812 unsigned char *augmentation_data
= NULL
;
3813 unsigned long augmentation_data_len
= 0;
3814 int encoded_ptr_size
= eh_addr_size
;
3816 int initial_length_size
;
3818 saved_start
= start
;
3819 length
= byte_get (start
, 4); start
+= 4;
3823 printf ("\n%08lx ZERO terminator\n\n",
3824 (unsigned long)(saved_start
- section_start
));
3828 if (length
== 0xffffffff)
3830 length
= byte_get (start
, 8);
3833 initial_length_size
= 12;
3838 initial_length_size
= 4;
3841 block_end
= saved_start
+ length
+ initial_length_size
;
3842 if (block_end
> end
)
3844 warn ("Invalid length %#08lx in FDE at %#08lx\n",
3845 length
, (unsigned long)(saved_start
- section_start
));
3848 cie_id
= byte_get (start
, offset_size
); start
+= offset_size
;
3850 if (is_eh
? (cie_id
== 0) : (cie_id
== DW_CIE_ID
))
3854 fc
= xmalloc (sizeof (Frame_Chunk
));
3855 memset (fc
, 0, sizeof (Frame_Chunk
));
3859 fc
->chunk_start
= saved_start
;
3861 fc
->col_type
= xmalloc (sizeof (short int));
3862 fc
->col_offset
= xmalloc (sizeof (int));
3863 frame_need_space (fc
, max_regs
- 1);
3867 fc
->augmentation
= (char *) start
;
3868 start
= (unsigned char *) strchr ((char *) start
, '\0') + 1;
3870 if (fc
->augmentation
[0] == 'z')
3872 fc
->code_factor
= LEB ();
3873 fc
->data_factor
= SLEB ();
3882 augmentation_data_len
= LEB ();
3883 augmentation_data
= start
;
3884 start
+= augmentation_data_len
;
3886 else if (strcmp (fc
->augmentation
, "eh") == 0)
3888 start
+= eh_addr_size
;
3889 fc
->code_factor
= LEB ();
3890 fc
->data_factor
= SLEB ();
3902 fc
->code_factor
= LEB ();
3903 fc
->data_factor
= SLEB ();
3915 if (do_debug_frames_interp
)
3916 printf ("\n%08lx %08lx %08lx CIE \"%s\" cf=%d df=%d ra=%d\n",
3917 (unsigned long)(saved_start
- section_start
), length
, cie_id
,
3918 fc
->augmentation
, fc
->code_factor
, fc
->data_factor
,
3922 printf ("\n%08lx %08lx %08lx CIE\n",
3923 (unsigned long)(saved_start
- section_start
), length
, cie_id
);
3924 printf (" Version: %d\n", version
);
3925 printf (" Augmentation: \"%s\"\n", fc
->augmentation
);
3926 printf (" Code alignment factor: %u\n", fc
->code_factor
);
3927 printf (" Data alignment factor: %d\n", fc
->data_factor
);
3928 printf (" Return address column: %d\n", fc
->ra
);
3930 if (augmentation_data_len
)
3933 printf (" Augmentation data: ");
3934 for (i
= 0; i
< augmentation_data_len
; ++i
)
3935 printf (" %02x", augmentation_data
[i
]);
3941 if (augmentation_data_len
)
3943 unsigned char *p
, *q
;
3944 p
= (unsigned char *) fc
->augmentation
+ 1;
3945 q
= augmentation_data
;
3952 q
+= 1 + size_of_encoded_value (*q
);
3954 fc
->fde_encoding
= *q
++;
3960 if (fc
->fde_encoding
)
3961 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
3964 frame_need_space (fc
, fc
->ra
);
3968 unsigned char *look_for
;
3969 static Frame_Chunk fde_fc
;
3972 memset (fc
, 0, sizeof (Frame_Chunk
));
3974 look_for
= is_eh
? start
- 4 - cie_id
: section_start
+ cie_id
;
3976 for (cie
= chunks
; cie
; cie
= cie
->next
)
3977 if (cie
->chunk_start
== look_for
)
3982 warn ("Invalid CIE pointer %#08lx in FDE at %#08lx\n",
3983 cie_id
, (unsigned long)(saved_start
- section_start
));
3985 fc
->col_type
= xmalloc (sizeof (short int));
3986 fc
->col_offset
= xmalloc (sizeof (int));
3987 frame_need_space (fc
, max_regs
- 1);
3989 fc
->augmentation
= "";
3990 fc
->fde_encoding
= 0;
3994 fc
->ncols
= cie
->ncols
;
3995 fc
->col_type
= xcmalloc (fc
->ncols
, sizeof (short int));
3996 fc
->col_offset
= xcmalloc (fc
->ncols
, sizeof (int));
3997 memcpy (fc
->col_type
, cie
->col_type
, fc
->ncols
* sizeof (short int));
3998 memcpy (fc
->col_offset
, cie
->col_offset
, fc
->ncols
* sizeof (int));
3999 fc
->augmentation
= cie
->augmentation
;
4000 fc
->code_factor
= cie
->code_factor
;
4001 fc
->data_factor
= cie
->data_factor
;
4002 fc
->cfa_reg
= cie
->cfa_reg
;
4003 fc
->cfa_offset
= cie
->cfa_offset
;
4005 frame_need_space (fc
, max_regs
- 1);
4006 fc
->fde_encoding
= cie
->fde_encoding
;
4009 if (fc
->fde_encoding
)
4010 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
4012 fc
->pc_begin
= get_encoded_value (start
, fc
->fde_encoding
);
4013 if ((fc
->fde_encoding
& 0x70) == DW_EH_PE_pcrel
)
4014 fc
->pc_begin
+= section
->address
+ (start
- section_start
);
4015 start
+= encoded_ptr_size
;
4016 fc
->pc_range
= byte_get (start
, encoded_ptr_size
);
4017 start
+= encoded_ptr_size
;
4019 if (cie
->augmentation
[0] == 'z')
4021 augmentation_data_len
= LEB ();
4022 augmentation_data
= start
;
4023 start
+= augmentation_data_len
;
4026 printf ("\n%08lx %08lx %08lx FDE cie=%08lx pc=%08lx..%08lx\n",
4027 (unsigned long)(saved_start
- section_start
), length
, cie_id
,
4028 (unsigned long)(cie
->chunk_start
- section_start
),
4029 fc
->pc_begin
, fc
->pc_begin
+ fc
->pc_range
);
4030 if (! do_debug_frames_interp
&& augmentation_data_len
)
4034 printf (" Augmentation data: ");
4035 for (i
= 0; i
< augmentation_data_len
; ++i
)
4036 printf (" %02x", augmentation_data
[i
]);
4042 /* At this point, fc is the current chunk, cie (if any) is set, and
4043 we're about to interpret instructions for the chunk. */
4044 /* ??? At present we need to do this always, since this sizes the
4045 fc->col_type and fc->col_offset arrays, which we write into always.
4046 We should probably split the interpreted and non-interpreted bits
4047 into two different routines, since there's so much that doesn't
4048 really overlap between them. */
4049 if (1 || do_debug_frames_interp
)
4051 /* Start by making a pass over the chunk, allocating storage
4052 and taking note of what registers are used. */
4053 unsigned char *tmp
= start
;
4055 while (start
< block_end
)
4058 unsigned long reg
, tmp
;
4065 /* Warning: if you add any more cases to this switch, be
4066 sure to add them to the corresponding switch below. */
4069 case DW_CFA_advance_loc
:
4073 frame_need_space (fc
, opa
);
4074 fc
->col_type
[opa
] = DW_CFA_undefined
;
4076 case DW_CFA_restore
:
4077 frame_need_space (fc
, opa
);
4078 fc
->col_type
[opa
] = DW_CFA_undefined
;
4080 case DW_CFA_set_loc
:
4081 start
+= encoded_ptr_size
;
4083 case DW_CFA_advance_loc1
:
4086 case DW_CFA_advance_loc2
:
4089 case DW_CFA_advance_loc4
:
4092 case DW_CFA_offset_extended
:
4093 case DW_CFA_val_offset
:
4094 reg
= LEB (); LEB ();
4095 frame_need_space (fc
, reg
);
4096 fc
->col_type
[reg
] = DW_CFA_undefined
;
4098 case DW_CFA_restore_extended
:
4100 frame_need_space (fc
, reg
);
4101 fc
->col_type
[reg
] = DW_CFA_undefined
;
4103 case DW_CFA_undefined
:
4105 frame_need_space (fc
, reg
);
4106 fc
->col_type
[reg
] = DW_CFA_undefined
;
4108 case DW_CFA_same_value
:
4110 frame_need_space (fc
, reg
);
4111 fc
->col_type
[reg
] = DW_CFA_undefined
;
4113 case DW_CFA_register
:
4114 reg
= LEB (); LEB ();
4115 frame_need_space (fc
, reg
);
4116 fc
->col_type
[reg
] = DW_CFA_undefined
;
4118 case DW_CFA_def_cfa
:
4121 case DW_CFA_def_cfa_register
:
4124 case DW_CFA_def_cfa_offset
:
4127 case DW_CFA_def_cfa_expression
:
4131 case DW_CFA_expression
:
4132 case DW_CFA_val_expression
:
4136 frame_need_space (fc
, reg
);
4137 fc
->col_type
[reg
] = DW_CFA_undefined
;
4139 case DW_CFA_offset_extended_sf
:
4140 case DW_CFA_val_offset_sf
:
4141 reg
= LEB (); SLEB ();
4142 frame_need_space (fc
, reg
);
4143 fc
->col_type
[reg
] = DW_CFA_undefined
;
4145 case DW_CFA_def_cfa_sf
:
4148 case DW_CFA_def_cfa_offset_sf
:
4151 case DW_CFA_MIPS_advance_loc8
:
4154 case DW_CFA_GNU_args_size
:
4157 case DW_CFA_GNU_negative_offset_extended
:
4158 reg
= LEB (); LEB ();
4159 frame_need_space (fc
, reg
);
4160 fc
->col_type
[reg
] = DW_CFA_undefined
;
4169 /* Now we know what registers are used, make a second pass over
4170 the chunk, this time actually printing out the info. */
4172 while (start
< block_end
)
4175 unsigned long ul
, reg
, roffs
;
4184 /* Warning: if you add any more cases to this switch, be
4185 sure to add them to the corresponding switch above. */
4188 case DW_CFA_advance_loc
:
4189 if (do_debug_frames_interp
)
4190 frame_display_row (fc
, &need_col_headers
, &max_regs
);
4192 printf (" DW_CFA_advance_loc: %d to %08lx\n",
4193 opa
* fc
->code_factor
,
4194 fc
->pc_begin
+ opa
* fc
->code_factor
);
4195 fc
->pc_begin
+= opa
* fc
->code_factor
;
4200 if (! do_debug_frames_interp
)
4201 printf (" DW_CFA_offset: %s at cfa%+ld\n",
4202 regname (opa
, 0), roffs
* fc
->data_factor
);
4203 fc
->col_type
[opa
] = DW_CFA_offset
;
4204 fc
->col_offset
[opa
] = roffs
* fc
->data_factor
;
4207 case DW_CFA_restore
:
4208 if (! do_debug_frames_interp
)
4209 printf (" DW_CFA_restore: %s\n", regname (opa
, 0));
4210 fc
->col_type
[opa
] = cie
->col_type
[opa
];
4211 fc
->col_offset
[opa
] = cie
->col_offset
[opa
];
4214 case DW_CFA_set_loc
:
4215 vma
= get_encoded_value (start
, fc
->fde_encoding
);
4216 if ((fc
->fde_encoding
& 0x70) == DW_EH_PE_pcrel
)
4217 vma
+= section
->address
+ (start
- section_start
);
4218 start
+= encoded_ptr_size
;
4219 if (do_debug_frames_interp
)
4220 frame_display_row (fc
, &need_col_headers
, &max_regs
);
4222 printf (" DW_CFA_set_loc: %08lx\n", (unsigned long)vma
);
4226 case DW_CFA_advance_loc1
:
4227 ofs
= byte_get (start
, 1); start
+= 1;
4228 if (do_debug_frames_interp
)
4229 frame_display_row (fc
, &need_col_headers
, &max_regs
);
4231 printf (" DW_CFA_advance_loc1: %ld to %08lx\n",
4232 ofs
* fc
->code_factor
,
4233 fc
->pc_begin
+ ofs
* fc
->code_factor
);
4234 fc
->pc_begin
+= ofs
* fc
->code_factor
;
4237 case DW_CFA_advance_loc2
:
4238 ofs
= byte_get (start
, 2); start
+= 2;
4239 if (do_debug_frames_interp
)
4240 frame_display_row (fc
, &need_col_headers
, &max_regs
);
4242 printf (" DW_CFA_advance_loc2: %ld to %08lx\n",
4243 ofs
* fc
->code_factor
,
4244 fc
->pc_begin
+ ofs
* fc
->code_factor
);
4245 fc
->pc_begin
+= ofs
* fc
->code_factor
;
4248 case DW_CFA_advance_loc4
:
4249 ofs
= byte_get (start
, 4); start
+= 4;
4250 if (do_debug_frames_interp
)
4251 frame_display_row (fc
, &need_col_headers
, &max_regs
);
4253 printf (" DW_CFA_advance_loc4: %ld to %08lx\n",
4254 ofs
* fc
->code_factor
,
4255 fc
->pc_begin
+ ofs
* fc
->code_factor
);
4256 fc
->pc_begin
+= ofs
* fc
->code_factor
;
4259 case DW_CFA_offset_extended
:
4262 if (! do_debug_frames_interp
)
4263 printf (" DW_CFA_offset_extended: %s at cfa%+ld\n",
4264 regname (reg
, 0), roffs
* fc
->data_factor
);
4265 fc
->col_type
[reg
] = DW_CFA_offset
;
4266 fc
->col_offset
[reg
] = roffs
* fc
->data_factor
;
4269 case DW_CFA_val_offset
:
4272 if (! do_debug_frames_interp
)
4273 printf (" DW_CFA_val_offset: %s at cfa%+ld\n",
4274 regname (reg
, 0), roffs
* fc
->data_factor
);
4275 fc
->col_type
[reg
] = DW_CFA_val_offset
;
4276 fc
->col_offset
[reg
] = roffs
* fc
->data_factor
;
4279 case DW_CFA_restore_extended
:
4281 if (! do_debug_frames_interp
)
4282 printf (" DW_CFA_restore_extended: %s\n",
4284 fc
->col_type
[reg
] = cie
->col_type
[reg
];
4285 fc
->col_offset
[reg
] = cie
->col_offset
[reg
];
4288 case DW_CFA_undefined
:
4290 if (! do_debug_frames_interp
)
4291 printf (" DW_CFA_undefined: %s\n", regname (reg
, 0));
4292 fc
->col_type
[reg
] = DW_CFA_undefined
;
4293 fc
->col_offset
[reg
] = 0;
4296 case DW_CFA_same_value
:
4298 if (! do_debug_frames_interp
)
4299 printf (" DW_CFA_same_value: %s\n", regname (reg
, 0));
4300 fc
->col_type
[reg
] = DW_CFA_same_value
;
4301 fc
->col_offset
[reg
] = 0;
4304 case DW_CFA_register
:
4307 if (! do_debug_frames_interp
)
4309 printf (" DW_CFA_register: %s in ",
4311 puts (regname (roffs
, 0));
4313 fc
->col_type
[reg
] = DW_CFA_register
;
4314 fc
->col_offset
[reg
] = roffs
;
4317 case DW_CFA_remember_state
:
4318 if (! do_debug_frames_interp
)
4319 printf (" DW_CFA_remember_state\n");
4320 rs
= xmalloc (sizeof (Frame_Chunk
));
4321 rs
->ncols
= fc
->ncols
;
4322 rs
->col_type
= xcmalloc (rs
->ncols
, sizeof (short int));
4323 rs
->col_offset
= xcmalloc (rs
->ncols
, sizeof (int));
4324 memcpy (rs
->col_type
, fc
->col_type
, rs
->ncols
);
4325 memcpy (rs
->col_offset
, fc
->col_offset
, rs
->ncols
* sizeof (int));
4326 rs
->next
= remembered_state
;
4327 remembered_state
= rs
;
4330 case DW_CFA_restore_state
:
4331 if (! do_debug_frames_interp
)
4332 printf (" DW_CFA_restore_state\n");
4333 rs
= remembered_state
;
4336 remembered_state
= rs
->next
;
4337 frame_need_space (fc
, rs
->ncols
- 1);
4338 memcpy (fc
->col_type
, rs
->col_type
, rs
->ncols
);
4339 memcpy (fc
->col_offset
, rs
->col_offset
,
4340 rs
->ncols
* sizeof (int));
4341 free (rs
->col_type
);
4342 free (rs
->col_offset
);
4345 else if (do_debug_frames_interp
)
4346 printf ("Mismatched DW_CFA_restore_state\n");
4349 case DW_CFA_def_cfa
:
4350 fc
->cfa_reg
= LEB ();
4351 fc
->cfa_offset
= LEB ();
4353 if (! do_debug_frames_interp
)
4354 printf (" DW_CFA_def_cfa: %s ofs %d\n",
4355 regname (fc
->cfa_reg
, 0), fc
->cfa_offset
);
4358 case DW_CFA_def_cfa_register
:
4359 fc
->cfa_reg
= LEB ();
4361 if (! do_debug_frames_interp
)
4362 printf (" DW_CFA_def_cfa_register: %s\n",
4363 regname (fc
->cfa_reg
, 0));
4366 case DW_CFA_def_cfa_offset
:
4367 fc
->cfa_offset
= LEB ();
4368 if (! do_debug_frames_interp
)
4369 printf (" DW_CFA_def_cfa_offset: %d\n", fc
->cfa_offset
);
4373 if (! do_debug_frames_interp
)
4374 printf (" DW_CFA_nop\n");
4377 case DW_CFA_def_cfa_expression
:
4379 if (! do_debug_frames_interp
)
4381 printf (" DW_CFA_def_cfa_expression (");
4382 decode_location_expression (start
, eh_addr_size
, ul
, 0);
4389 case DW_CFA_expression
:
4392 if (! do_debug_frames_interp
)
4394 printf (" DW_CFA_expression: %s (",
4396 decode_location_expression (start
, eh_addr_size
,
4400 fc
->col_type
[reg
] = DW_CFA_expression
;
4404 case DW_CFA_val_expression
:
4407 if (! do_debug_frames_interp
)
4409 printf (" DW_CFA_val_expression: %s (",
4411 decode_location_expression (start
, eh_addr_size
, ul
, 0);
4414 fc
->col_type
[reg
] = DW_CFA_val_expression
;
4418 case DW_CFA_offset_extended_sf
:
4421 frame_need_space (fc
, reg
);
4422 if (! do_debug_frames_interp
)
4423 printf (" DW_CFA_offset_extended_sf: %s at cfa%+ld\n",
4424 regname (reg
, 0), l
* fc
->data_factor
);
4425 fc
->col_type
[reg
] = DW_CFA_offset
;
4426 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
4429 case DW_CFA_val_offset_sf
:
4432 frame_need_space (fc
, reg
);
4433 if (! do_debug_frames_interp
)
4434 printf (" DW_CFA_val_offset_sf: %s at cfa%+ld\n",
4435 regname (reg
, 0), l
* fc
->data_factor
);
4436 fc
->col_type
[reg
] = DW_CFA_val_offset
;
4437 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
4440 case DW_CFA_def_cfa_sf
:
4441 fc
->cfa_reg
= LEB ();
4442 fc
->cfa_offset
= SLEB ();
4443 fc
->cfa_offset
= fc
->cfa_offset
* fc
->data_factor
;
4445 if (! do_debug_frames_interp
)
4446 printf (" DW_CFA_def_cfa_sf: %s ofs %d\n",
4447 regname (fc
->cfa_reg
, 0), fc
->cfa_offset
);
4450 case DW_CFA_def_cfa_offset_sf
:
4451 fc
->cfa_offset
= SLEB ();
4452 fc
->cfa_offset
= fc
->cfa_offset
* fc
->data_factor
;
4453 if (! do_debug_frames_interp
)
4454 printf (" DW_CFA_def_cfa_offset_sf: %d\n", fc
->cfa_offset
);
4457 case DW_CFA_MIPS_advance_loc8
:
4458 ofs
= byte_get (start
, 8); start
+= 8;
4459 if (do_debug_frames_interp
)
4460 frame_display_row (fc
, &need_col_headers
, &max_regs
);
4462 printf (" DW_CFA_MIPS_advance_loc8: %ld to %08lx\n",
4463 ofs
* fc
->code_factor
,
4464 fc
->pc_begin
+ ofs
* fc
->code_factor
);
4465 fc
->pc_begin
+= ofs
* fc
->code_factor
;
4468 case DW_CFA_GNU_window_save
:
4469 if (! do_debug_frames_interp
)
4470 printf (" DW_CFA_GNU_window_save\n");
4473 case DW_CFA_GNU_args_size
:
4475 if (! do_debug_frames_interp
)
4476 printf (" DW_CFA_GNU_args_size: %ld\n", ul
);
4479 case DW_CFA_GNU_negative_offset_extended
:
4482 frame_need_space (fc
, reg
);
4483 if (! do_debug_frames_interp
)
4484 printf (" DW_CFA_GNU_negative_offset_extended: %s at cfa%+ld\n",
4485 regname (reg
, 0), l
* fc
->data_factor
);
4486 fc
->col_type
[reg
] = DW_CFA_offset
;
4487 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
4491 if (op
>= DW_CFA_lo_user
&& op
<= DW_CFA_hi_user
)
4492 printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op
);
4494 warn (_("unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op
);
4499 if (do_debug_frames_interp
)
4500 frame_display_row (fc
, &need_col_headers
, &max_regs
);
4515 display_debug_not_supported (struct dwarf_section
*section
,
4516 void *file ATTRIBUTE_UNUSED
)
4518 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
4525 cmalloc (size_t nmemb
, size_t size
)
4527 /* Check for overflow. */
4528 if (nmemb
>= ~(size_t) 0 / size
)
4531 return malloc (nmemb
* size
);
4535 xcmalloc (size_t nmemb
, size_t size
)
4537 /* Check for overflow. */
4538 if (nmemb
>= ~(size_t) 0 / size
)
4541 return xmalloc (nmemb
* size
);
4545 xcrealloc (void *ptr
, size_t nmemb
, size_t size
)
4547 /* Check for overflow. */
4548 if (nmemb
>= ~(size_t) 0 / size
)
4551 return xrealloc (ptr
, nmemb
* size
);
4555 error (const char *message
, ...)
4559 va_start (args
, message
);
4560 fprintf (stderr
, _("%s: Error: "), program_name
);
4561 vfprintf (stderr
, message
, args
);
4566 warn (const char *message
, ...)
4570 va_start (args
, message
);
4571 fprintf (stderr
, _("%s: Warning: "), program_name
);
4572 vfprintf (stderr
, message
, args
);
4577 free_debug_memory (void)
4579 enum dwarf_section_display_enum i
;
4583 for (i
= 0; i
< max
; i
++)
4584 free_debug_section (i
);
4586 if (debug_information
!= NULL
)
4588 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
)
4590 for (i
= 0; i
< num_debug_info_entries
; i
++)
4592 if (!debug_information
[i
].max_loc_offsets
)
4594 free (debug_information
[i
].loc_offsets
);
4595 free (debug_information
[i
].have_frame_base
);
4597 if (!debug_information
[i
].max_range_lists
)
4598 free (debug_information
[i
].range_lists
);
4602 free (debug_information
);
4603 debug_information
= NULL
;
4604 num_debug_info_entries
= 0;
4608 struct dwarf_section_display debug_displays
[] =
4610 { { ".debug_abbrev", ".zdebug_abbrev", NULL
, NULL
, 0, 0 },
4611 display_debug_abbrev
, 0, 0 },
4612 { { ".debug_aranges", ".zdebug_aranges", NULL
, NULL
, 0, 0 },
4613 display_debug_aranges
, 0, 0 },
4614 { { ".debug_frame", ".zdebug_frame", NULL
, NULL
, 0, 0 },
4615 display_debug_frames
, 1, 0 },
4616 { { ".debug_info", ".zdebug_info", NULL
, NULL
, 0, 0 },
4617 display_debug_info
, 1, 0 },
4618 { { ".debug_line", ".zdebug_line", NULL
, NULL
, 0, 0 },
4619 display_debug_lines
, 0, 0 },
4620 { { ".debug_pubnames", ".zdebug_pubnames", NULL
, NULL
, 0, 0 },
4621 display_debug_pubnames
, 0, 0 },
4622 { { ".eh_frame", "", NULL
, NULL
, 0, 0 },
4623 display_debug_frames
, 1, 1 },
4624 { { ".debug_macinfo", ".zdebug_macinfo", NULL
, NULL
, 0, 0 },
4625 display_debug_macinfo
, 0, 0 },
4626 { { ".debug_str", ".zdebug_str", NULL
, NULL
, 0, 0 },
4627 display_debug_str
, 0, 0 },
4628 { { ".debug_loc", ".zdebug_loc", NULL
, NULL
, 0, 0 },
4629 display_debug_loc
, 0, 0 },
4630 { { ".debug_pubtypes", ".zdebug_pubtypes", NULL
, NULL
, 0, 0 },
4631 display_debug_pubnames
, 0, 0 },
4632 { { ".debug_ranges", ".zdebug_ranges", NULL
, NULL
, 0, 0 },
4633 display_debug_ranges
, 0, 0 },
4634 { { ".debug_static_func", ".zdebug_static_func", NULL
, NULL
, 0, 0 },
4635 display_debug_not_supported
, 0, 0 },
4636 { { ".debug_static_vars", ".zdebug_static_vars", NULL
, NULL
, 0, 0 },
4637 display_debug_not_supported
, 0, 0 },
4638 { { ".debug_types", ".zdebug_types", NULL
, NULL
, 0, 0 },
4639 display_debug_not_supported
, 0, 0 },
4640 { { ".debug_weaknames", ".zdebug_weaknames", NULL
, NULL
, 0, 0 },
4641 display_debug_not_supported
, 0, 0 }