1 /* dwarf.c -- display DWARF contents of a BFD binary file
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 2 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
27 #include "libiberty.h"
29 static int have_frame_base
;
30 static int need_base_address
;
32 static unsigned int last_pointer_size
= 0;
33 static int warned_about_missing_comp_units
= FALSE
;
35 static unsigned int num_debug_info_entries
= 0;
36 static debug_info
*debug_information
= NULL
;
38 dwarf_vma eh_addr_size
;
44 int do_debug_pubnames
;
48 int do_debug_frames_interp
;
53 dwarf_vma (*byte_get
) (unsigned char *, int);
56 byte_get_little_endian (unsigned char *field
, int size
)
64 return ((unsigned int) (field
[0]))
65 | (((unsigned int) (field
[1])) << 8);
68 return ((unsigned long) (field
[0]))
69 | (((unsigned long) (field
[1])) << 8)
70 | (((unsigned long) (field
[2])) << 16)
71 | (((unsigned long) (field
[3])) << 24);
74 if (sizeof (dwarf_vma
) == 8)
75 return ((dwarf_vma
) (field
[0]))
76 | (((dwarf_vma
) (field
[1])) << 8)
77 | (((dwarf_vma
) (field
[2])) << 16)
78 | (((dwarf_vma
) (field
[3])) << 24)
79 | (((dwarf_vma
) (field
[4])) << 32)
80 | (((dwarf_vma
) (field
[5])) << 40)
81 | (((dwarf_vma
) (field
[6])) << 48)
82 | (((dwarf_vma
) (field
[7])) << 56);
83 else if (sizeof (dwarf_vma
) == 4)
84 /* We want to extract data from an 8 byte wide field and
85 place it into a 4 byte wide field. Since this is a little
86 endian source we can just use the 4 byte extraction code. */
87 return ((unsigned long) (field
[0]))
88 | (((unsigned long) (field
[1])) << 8)
89 | (((unsigned long) (field
[2])) << 16)
90 | (((unsigned long) (field
[3])) << 24);
93 error (_("Unhandled data length: %d\n"), size
);
99 byte_get_big_endian (unsigned char *field
, int size
)
107 return ((unsigned int) (field
[1])) | (((int) (field
[0])) << 8);
110 return ((unsigned long) (field
[3]))
111 | (((unsigned long) (field
[2])) << 8)
112 | (((unsigned long) (field
[1])) << 16)
113 | (((unsigned long) (field
[0])) << 24);
116 if (sizeof (dwarf_vma
) == 8)
117 return ((dwarf_vma
) (field
[7]))
118 | (((dwarf_vma
) (field
[6])) << 8)
119 | (((dwarf_vma
) (field
[5])) << 16)
120 | (((dwarf_vma
) (field
[4])) << 24)
121 | (((dwarf_vma
) (field
[3])) << 32)
122 | (((dwarf_vma
) (field
[2])) << 40)
123 | (((dwarf_vma
) (field
[1])) << 48)
124 | (((dwarf_vma
) (field
[0])) << 56);
125 else if (sizeof (dwarf_vma
) == 4)
127 /* Although we are extracing data from an 8 byte wide field,
128 we are returning only 4 bytes of data. */
130 return ((unsigned long) (field
[3]))
131 | (((unsigned long) (field
[2])) << 8)
132 | (((unsigned long) (field
[1])) << 16)
133 | (((unsigned long) (field
[0])) << 24);
137 error (_("Unhandled data length: %d\n"), size
);
143 byte_get_signed (unsigned char *field
, int size
)
145 dwarf_vma x
= byte_get (field
, size
);
150 return (x
^ 0x80) - 0x80;
152 return (x
^ 0x8000) - 0x8000;
154 return (x
^ 0x80000000) - 0x80000000;
162 static unsigned long int
163 read_leb128 (unsigned char *data
, unsigned int *length_return
, int sign
)
165 unsigned long int result
= 0;
166 unsigned int num_read
= 0;
167 unsigned int shift
= 0;
175 result
|= ((unsigned long int) (byte
& 0x7f)) << shift
;
182 if (length_return
!= NULL
)
183 *length_return
= num_read
;
185 if (sign
&& (shift
< 8 * sizeof (result
)) && (byte
& 0x40))
186 result
|= -1L << shift
;
191 typedef struct State_Machine_Registers
193 unsigned long address
;
200 /* This variable hold the number of the last entry seen
201 in the File Table. */
202 unsigned int last_file_entry
;
205 static SMR state_machine_regs
;
208 reset_state_machine (int is_stmt
)
210 state_machine_regs
.address
= 0;
211 state_machine_regs
.file
= 1;
212 state_machine_regs
.line
= 1;
213 state_machine_regs
.column
= 0;
214 state_machine_regs
.is_stmt
= is_stmt
;
215 state_machine_regs
.basic_block
= 0;
216 state_machine_regs
.end_sequence
= 0;
217 state_machine_regs
.last_file_entry
= 0;
220 /* Handled an extend line op.
221 Returns the number of bytes read. */
224 process_extended_line_op (unsigned char *data
, int is_stmt
)
226 unsigned char op_code
;
227 unsigned int bytes_read
;
232 len
= read_leb128 (data
, & bytes_read
, 0);
237 warn (_("badly formed extended line op encountered!\n"));
244 printf (_(" Extended opcode %d: "), op_code
);
248 case DW_LNE_end_sequence
:
249 printf (_("End of Sequence\n\n"));
250 reset_state_machine (is_stmt
);
253 case DW_LNE_set_address
:
254 adr
= byte_get (data
, len
- bytes_read
- 1);
255 printf (_("set Address to 0x%lx\n"), adr
);
256 state_machine_regs
.address
= adr
;
259 case DW_LNE_define_file
:
260 printf (_(" define new File Table entry\n"));
261 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
263 printf (_(" %d\t"), ++state_machine_regs
.last_file_entry
);
265 data
+= strlen ((char *) data
) + 1;
266 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
268 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
270 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
271 printf (_("%s\n\n"), name
);
275 printf (_("UNKNOWN: length %d\n"), len
- bytes_read
);
283 fetch_indirect_string (unsigned long offset
)
285 struct dwarf_section
*section
= &debug_displays
[str
].section
;
287 if (section
->start
== NULL
)
288 return _("<no .debug_str section>");
290 /* DWARF sections under Mach-O have non-zero addresses. */
291 offset
-= section
->address
;
292 if (offset
> section
->size
)
294 warn (_("DW_FORM_strp offset too big: %lx\n"), offset
);
295 return _("<offset is too big>");
298 return (const char *) section
->start
+ offset
;
301 /* FIXME: There are better and more efficient ways to handle
302 these structures. For now though, I just want something that
303 is simple to implement. */
304 typedef struct abbrev_attr
306 unsigned long attribute
;
308 struct abbrev_attr
*next
;
312 typedef struct abbrev_entry
317 struct abbrev_attr
*first_attr
;
318 struct abbrev_attr
*last_attr
;
319 struct abbrev_entry
*next
;
323 static abbrev_entry
*first_abbrev
= NULL
;
324 static abbrev_entry
*last_abbrev
= NULL
;
329 abbrev_entry
*abbrev
;
331 for (abbrev
= first_abbrev
; abbrev
;)
333 abbrev_entry
*next
= abbrev
->next
;
336 for (attr
= abbrev
->first_attr
; attr
;)
338 abbrev_attr
*next
= attr
->next
;
348 last_abbrev
= first_abbrev
= NULL
;
352 add_abbrev (unsigned long number
, unsigned long tag
, int children
)
356 entry
= malloc (sizeof (*entry
));
362 entry
->entry
= number
;
364 entry
->children
= children
;
365 entry
->first_attr
= NULL
;
366 entry
->last_attr
= NULL
;
369 if (first_abbrev
== NULL
)
370 first_abbrev
= entry
;
372 last_abbrev
->next
= entry
;
378 add_abbrev_attr (unsigned long attribute
, unsigned long form
)
382 attr
= malloc (sizeof (*attr
));
388 attr
->attribute
= attribute
;
392 if (last_abbrev
->first_attr
== NULL
)
393 last_abbrev
->first_attr
= attr
;
395 last_abbrev
->last_attr
->next
= attr
;
397 last_abbrev
->last_attr
= attr
;
400 /* Processes the (partial) contents of a .debug_abbrev section.
401 Returns NULL if the end of the section was encountered.
402 Returns the address after the last byte read if the end of
403 an abbreviation set was found. */
405 static unsigned char *
406 process_abbrev_section (unsigned char *start
, unsigned char *end
)
408 if (first_abbrev
!= NULL
)
413 unsigned int bytes_read
;
416 unsigned long attribute
;
419 entry
= read_leb128 (start
, & bytes_read
, 0);
422 /* A single zero is supposed to end the section according
423 to the standard. If there's more, then signal that to
426 return start
== end
? NULL
: start
;
428 tag
= read_leb128 (start
, & bytes_read
, 0);
433 add_abbrev (entry
, tag
, children
);
439 attribute
= read_leb128 (start
, & bytes_read
, 0);
442 form
= read_leb128 (start
, & bytes_read
, 0);
446 add_abbrev_attr (attribute
, form
);
448 while (attribute
!= 0);
455 get_TAG_name (unsigned long tag
)
459 case DW_TAG_padding
: return "DW_TAG_padding";
460 case DW_TAG_array_type
: return "DW_TAG_array_type";
461 case DW_TAG_class_type
: return "DW_TAG_class_type";
462 case DW_TAG_entry_point
: return "DW_TAG_entry_point";
463 case DW_TAG_enumeration_type
: return "DW_TAG_enumeration_type";
464 case DW_TAG_formal_parameter
: return "DW_TAG_formal_parameter";
465 case DW_TAG_imported_declaration
: return "DW_TAG_imported_declaration";
466 case DW_TAG_label
: return "DW_TAG_label";
467 case DW_TAG_lexical_block
: return "DW_TAG_lexical_block";
468 case DW_TAG_member
: return "DW_TAG_member";
469 case DW_TAG_pointer_type
: return "DW_TAG_pointer_type";
470 case DW_TAG_reference_type
: return "DW_TAG_reference_type";
471 case DW_TAG_compile_unit
: return "DW_TAG_compile_unit";
472 case DW_TAG_string_type
: return "DW_TAG_string_type";
473 case DW_TAG_structure_type
: return "DW_TAG_structure_type";
474 case DW_TAG_subroutine_type
: return "DW_TAG_subroutine_type";
475 case DW_TAG_typedef
: return "DW_TAG_typedef";
476 case DW_TAG_union_type
: return "DW_TAG_union_type";
477 case DW_TAG_unspecified_parameters
: return "DW_TAG_unspecified_parameters";
478 case DW_TAG_variant
: return "DW_TAG_variant";
479 case DW_TAG_common_block
: return "DW_TAG_common_block";
480 case DW_TAG_common_inclusion
: return "DW_TAG_common_inclusion";
481 case DW_TAG_inheritance
: return "DW_TAG_inheritance";
482 case DW_TAG_inlined_subroutine
: return "DW_TAG_inlined_subroutine";
483 case DW_TAG_module
: return "DW_TAG_module";
484 case DW_TAG_ptr_to_member_type
: return "DW_TAG_ptr_to_member_type";
485 case DW_TAG_set_type
: return "DW_TAG_set_type";
486 case DW_TAG_subrange_type
: return "DW_TAG_subrange_type";
487 case DW_TAG_with_stmt
: return "DW_TAG_with_stmt";
488 case DW_TAG_access_declaration
: return "DW_TAG_access_declaration";
489 case DW_TAG_base_type
: return "DW_TAG_base_type";
490 case DW_TAG_catch_block
: return "DW_TAG_catch_block";
491 case DW_TAG_const_type
: return "DW_TAG_const_type";
492 case DW_TAG_constant
: return "DW_TAG_constant";
493 case DW_TAG_enumerator
: return "DW_TAG_enumerator";
494 case DW_TAG_file_type
: return "DW_TAG_file_type";
495 case DW_TAG_friend
: return "DW_TAG_friend";
496 case DW_TAG_namelist
: return "DW_TAG_namelist";
497 case DW_TAG_namelist_item
: return "DW_TAG_namelist_item";
498 case DW_TAG_packed_type
: return "DW_TAG_packed_type";
499 case DW_TAG_subprogram
: return "DW_TAG_subprogram";
500 case DW_TAG_template_type_param
: return "DW_TAG_template_type_param";
501 case DW_TAG_template_value_param
: return "DW_TAG_template_value_param";
502 case DW_TAG_thrown_type
: return "DW_TAG_thrown_type";
503 case DW_TAG_try_block
: return "DW_TAG_try_block";
504 case DW_TAG_variant_part
: return "DW_TAG_variant_part";
505 case DW_TAG_variable
: return "DW_TAG_variable";
506 case DW_TAG_volatile_type
: return "DW_TAG_volatile_type";
507 case DW_TAG_MIPS_loop
: return "DW_TAG_MIPS_loop";
508 case DW_TAG_format_label
: return "DW_TAG_format_label";
509 case DW_TAG_function_template
: return "DW_TAG_function_template";
510 case DW_TAG_class_template
: return "DW_TAG_class_template";
511 /* DWARF 2.1 values. */
512 case DW_TAG_dwarf_procedure
: return "DW_TAG_dwarf_procedure";
513 case DW_TAG_restrict_type
: return "DW_TAG_restrict_type";
514 case DW_TAG_interface_type
: return "DW_TAG_interface_type";
515 case DW_TAG_namespace
: return "DW_TAG_namespace";
516 case DW_TAG_imported_module
: return "DW_TAG_imported_module";
517 case DW_TAG_unspecified_type
: return "DW_TAG_unspecified_type";
518 case DW_TAG_partial_unit
: return "DW_TAG_partial_unit";
519 case DW_TAG_imported_unit
: return "DW_TAG_imported_unit";
521 case DW_TAG_upc_shared_type
: return "DW_TAG_upc_shared_type";
522 case DW_TAG_upc_strict_type
: return "DW_TAG_upc_strict_type";
523 case DW_TAG_upc_relaxed_type
: return "DW_TAG_upc_relaxed_type";
526 static char buffer
[100];
528 snprintf (buffer
, sizeof (buffer
), _("Unknown TAG value: %lx"), tag
);
535 get_FORM_name (unsigned long form
)
539 case DW_FORM_addr
: return "DW_FORM_addr";
540 case DW_FORM_block2
: return "DW_FORM_block2";
541 case DW_FORM_block4
: return "DW_FORM_block4";
542 case DW_FORM_data2
: return "DW_FORM_data2";
543 case DW_FORM_data4
: return "DW_FORM_data4";
544 case DW_FORM_data8
: return "DW_FORM_data8";
545 case DW_FORM_string
: return "DW_FORM_string";
546 case DW_FORM_block
: return "DW_FORM_block";
547 case DW_FORM_block1
: return "DW_FORM_block1";
548 case DW_FORM_data1
: return "DW_FORM_data1";
549 case DW_FORM_flag
: return "DW_FORM_flag";
550 case DW_FORM_sdata
: return "DW_FORM_sdata";
551 case DW_FORM_strp
: return "DW_FORM_strp";
552 case DW_FORM_udata
: return "DW_FORM_udata";
553 case DW_FORM_ref_addr
: return "DW_FORM_ref_addr";
554 case DW_FORM_ref1
: return "DW_FORM_ref1";
555 case DW_FORM_ref2
: return "DW_FORM_ref2";
556 case DW_FORM_ref4
: return "DW_FORM_ref4";
557 case DW_FORM_ref8
: return "DW_FORM_ref8";
558 case DW_FORM_ref_udata
: return "DW_FORM_ref_udata";
559 case DW_FORM_indirect
: return "DW_FORM_indirect";
562 static char buffer
[100];
564 snprintf (buffer
, sizeof (buffer
), _("Unknown FORM value: %lx"), form
);
570 static unsigned char *
571 display_block (unsigned char *data
, unsigned long length
)
573 printf (_(" %lu byte block: "), length
);
576 printf ("%lx ", (unsigned long) byte_get (data
++, 1));
582 decode_location_expression (unsigned char * data
,
583 unsigned int pointer_size
,
584 unsigned long length
,
585 unsigned long cu_offset
)
588 unsigned int bytes_read
;
589 unsigned long uvalue
;
590 unsigned char *end
= data
+ length
;
591 int need_frame_base
= 0;
600 printf ("DW_OP_addr: %lx",
601 (unsigned long) byte_get (data
, pointer_size
));
602 data
+= pointer_size
;
605 printf ("DW_OP_deref");
608 printf ("DW_OP_const1u: %lu", (unsigned long) byte_get (data
++, 1));
611 printf ("DW_OP_const1s: %ld", (long) byte_get_signed (data
++, 1));
614 printf ("DW_OP_const2u: %lu", (unsigned long) byte_get (data
, 2));
618 printf ("DW_OP_const2s: %ld", (long) byte_get_signed (data
, 2));
622 printf ("DW_OP_const4u: %lu", (unsigned long) byte_get (data
, 4));
626 printf ("DW_OP_const4s: %ld", (long) byte_get_signed (data
, 4));
630 printf ("DW_OP_const8u: %lu %lu", (unsigned long) byte_get (data
, 4),
631 (unsigned long) byte_get (data
+ 4, 4));
635 printf ("DW_OP_const8s: %ld %ld", (long) byte_get (data
, 4),
636 (long) byte_get (data
+ 4, 4));
640 printf ("DW_OP_constu: %lu", read_leb128 (data
, &bytes_read
, 0));
644 printf ("DW_OP_consts: %ld", read_leb128 (data
, &bytes_read
, 1));
648 printf ("DW_OP_dup");
651 printf ("DW_OP_drop");
654 printf ("DW_OP_over");
657 printf ("DW_OP_pick: %ld", (unsigned long) byte_get (data
++, 1));
660 printf ("DW_OP_swap");
663 printf ("DW_OP_rot");
666 printf ("DW_OP_xderef");
669 printf ("DW_OP_abs");
672 printf ("DW_OP_and");
675 printf ("DW_OP_div");
678 printf ("DW_OP_minus");
681 printf ("DW_OP_mod");
684 printf ("DW_OP_mul");
687 printf ("DW_OP_neg");
690 printf ("DW_OP_not");
696 printf ("DW_OP_plus");
698 case DW_OP_plus_uconst
:
699 printf ("DW_OP_plus_uconst: %lu",
700 read_leb128 (data
, &bytes_read
, 0));
704 printf ("DW_OP_shl");
707 printf ("DW_OP_shr");
710 printf ("DW_OP_shra");
713 printf ("DW_OP_xor");
716 printf ("DW_OP_bra: %ld", (long) byte_get_signed (data
, 2));
738 printf ("DW_OP_skip: %ld", (long) byte_get_signed (data
, 2));
774 printf ("DW_OP_lit%d", op
- DW_OP_lit0
);
809 printf ("DW_OP_reg%d", op
- DW_OP_reg0
);
844 printf ("DW_OP_breg%d: %ld", op
- DW_OP_breg0
,
845 read_leb128 (data
, &bytes_read
, 1));
850 printf ("DW_OP_regx: %lu", read_leb128 (data
, &bytes_read
, 0));
855 printf ("DW_OP_fbreg: %ld", read_leb128 (data
, &bytes_read
, 1));
859 uvalue
= read_leb128 (data
, &bytes_read
, 0);
861 printf ("DW_OP_bregx: %lu %ld", uvalue
,
862 read_leb128 (data
, &bytes_read
, 1));
866 printf ("DW_OP_piece: %lu", read_leb128 (data
, &bytes_read
, 0));
869 case DW_OP_deref_size
:
870 printf ("DW_OP_deref_size: %ld", (long) byte_get (data
++, 1));
872 case DW_OP_xderef_size
:
873 printf ("DW_OP_xderef_size: %ld", (long) byte_get (data
++, 1));
876 printf ("DW_OP_nop");
879 /* DWARF 3 extensions. */
880 case DW_OP_push_object_address
:
881 printf ("DW_OP_push_object_address");
884 /* XXX: Strictly speaking for 64-bit DWARF3 files
885 this ought to be an 8-byte wide computation. */
886 printf ("DW_OP_call2: <%lx>", (long) byte_get (data
, 2) + cu_offset
);
890 /* XXX: Strictly speaking for 64-bit DWARF3 files
891 this ought to be an 8-byte wide computation. */
892 printf ("DW_OP_call4: <%lx>", (long) byte_get (data
, 4) + cu_offset
);
896 printf ("DW_OP_call_ref");
899 /* GNU extensions. */
900 case DW_OP_GNU_push_tls_address
:
901 printf ("DW_OP_GNU_push_tls_address");
905 if (op
>= DW_OP_lo_user
906 && op
<= DW_OP_hi_user
)
907 printf (_("(User defined location op)"));
909 printf (_("(Unknown location op)"));
910 /* No way to tell where the next op is, so just bail. */
911 return need_frame_base
;
914 /* Separate the ops. */
919 return need_frame_base
;
922 static unsigned char *
923 read_and_display_attr_value (unsigned long attribute
,
926 unsigned long cu_offset
,
927 unsigned long pointer_size
,
928 unsigned long offset_size
,
930 debug_info
*debug_info_p
,
933 unsigned long uvalue
= 0;
934 unsigned char *block_start
= NULL
;
935 unsigned int bytes_read
;
942 case DW_FORM_ref_addr
:
943 if (dwarf_version
== 2)
945 uvalue
= byte_get (data
, pointer_size
);
946 data
+= pointer_size
;
948 else if (dwarf_version
== 3)
950 uvalue
= byte_get (data
, offset_size
);
955 error (_("Internal error: DWARF version is not 2 or 3.\n"));
960 uvalue
= byte_get (data
, pointer_size
);
961 data
+= pointer_size
;
965 uvalue
= byte_get (data
, offset_size
);
972 uvalue
= byte_get (data
++, 1);
977 uvalue
= byte_get (data
, 2);
983 uvalue
= byte_get (data
, 4);
988 uvalue
= read_leb128 (data
, & bytes_read
, 1);
992 case DW_FORM_ref_udata
:
994 uvalue
= read_leb128 (data
, & bytes_read
, 0);
998 case DW_FORM_indirect
:
999 form
= read_leb128 (data
, & bytes_read
, 0);
1002 printf (" %s", get_FORM_name (form
));
1003 return read_and_display_attr_value (attribute
, form
, data
,
1004 cu_offset
, pointer_size
,
1005 offset_size
, dwarf_version
,
1006 debug_info_p
, do_loc
);
1011 case DW_FORM_ref_addr
:
1013 printf (" <#%lx>", uvalue
);
1019 case DW_FORM_ref_udata
:
1021 printf (" <%lx>", uvalue
+ cu_offset
);
1027 printf (" %#lx", uvalue
);
1036 printf (" %ld", uvalue
);
1043 uvalue
= byte_get (data
, 4);
1044 printf (" %lx", uvalue
);
1045 printf (" %lx", (unsigned long) byte_get (data
+ 4, 4));
1047 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
1048 && num_debug_info_entries
== 0)
1050 if (sizeof (uvalue
) == 8)
1051 uvalue
= byte_get (data
, 8);
1053 error (_("DW_FORM_data8 is unsupported when sizeof (unsigned long) != 8\n"));
1058 case DW_FORM_string
:
1060 printf (" %s", data
);
1061 data
+= strlen ((char *) data
) + 1;
1065 uvalue
= read_leb128 (data
, & bytes_read
, 0);
1066 block_start
= data
+ bytes_read
;
1068 data
= block_start
+ uvalue
;
1070 data
= display_block (block_start
, uvalue
);
1073 case DW_FORM_block1
:
1074 uvalue
= byte_get (data
, 1);
1075 block_start
= data
+ 1;
1077 data
= block_start
+ uvalue
;
1079 data
= display_block (block_start
, uvalue
);
1082 case DW_FORM_block2
:
1083 uvalue
= byte_get (data
, 2);
1084 block_start
= data
+ 2;
1086 data
= block_start
+ uvalue
;
1088 data
= display_block (block_start
, uvalue
);
1091 case DW_FORM_block4
:
1092 uvalue
= byte_get (data
, 4);
1093 block_start
= data
+ 4;
1095 data
= block_start
+ uvalue
;
1097 data
= display_block (block_start
, uvalue
);
1102 printf (_(" (indirect string, offset: 0x%lx): %s"),
1103 uvalue
, fetch_indirect_string (uvalue
));
1106 case DW_FORM_indirect
:
1107 /* Handled above. */
1111 warn (_("Unrecognized form: %lu\n"), form
);
1115 /* For some attributes we can display further information. */
1116 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
1117 && num_debug_info_entries
== 0)
1121 case DW_AT_frame_base
:
1122 have_frame_base
= 1;
1123 case DW_AT_location
:
1124 case DW_AT_data_member_location
:
1125 case DW_AT_vtable_elem_location
:
1126 case DW_AT_allocated
:
1127 case DW_AT_associated
:
1128 case DW_AT_data_location
:
1130 case DW_AT_upper_bound
:
1131 case DW_AT_lower_bound
:
1132 if (form
== DW_FORM_data4
|| form
== DW_FORM_data8
)
1134 /* Process location list. */
1135 unsigned int max
= debug_info_p
->max_loc_offsets
;
1136 unsigned int num
= debug_info_p
->num_loc_offsets
;
1138 if (max
== 0 || num
>= max
)
1141 debug_info_p
->loc_offsets
1142 = xcrealloc (debug_info_p
->loc_offsets
,
1143 max
, sizeof (*debug_info_p
->loc_offsets
));
1144 debug_info_p
->have_frame_base
1145 = xcrealloc (debug_info_p
->have_frame_base
,
1146 max
, sizeof (*debug_info_p
->have_frame_base
));
1147 debug_info_p
->max_loc_offsets
= max
;
1149 debug_info_p
->loc_offsets
[num
] = uvalue
;
1150 debug_info_p
->have_frame_base
[num
] = have_frame_base
;
1151 debug_info_p
->num_loc_offsets
++;
1156 if (need_base_address
)
1157 debug_info_p
->base_address
= uvalue
;
1161 if (form
== DW_FORM_data4
|| form
== DW_FORM_data8
)
1163 /* Process range list. */
1164 unsigned int max
= debug_info_p
->max_range_lists
;
1165 unsigned int num
= debug_info_p
->num_range_lists
;
1167 if (max
== 0 || num
>= max
)
1170 debug_info_p
->range_lists
1171 = xcrealloc (debug_info_p
->range_lists
,
1172 max
, sizeof (*debug_info_p
->range_lists
));
1173 debug_info_p
->max_range_lists
= max
;
1175 debug_info_p
->range_lists
[num
] = uvalue
;
1176 debug_info_p
->num_range_lists
++;
1195 case DW_INL_not_inlined
:
1196 printf (_("(not inlined)"));
1198 case DW_INL_inlined
:
1199 printf (_("(inlined)"));
1201 case DW_INL_declared_not_inlined
:
1202 printf (_("(declared as inline but ignored)"));
1204 case DW_INL_declared_inlined
:
1205 printf (_("(declared as inline and inlined)"));
1208 printf (_(" (Unknown inline attribute value: %lx)"), uvalue
);
1213 case DW_AT_language
:
1216 case DW_LANG_C
: printf ("(non-ANSI C)"); break;
1217 case DW_LANG_C89
: printf ("(ANSI C)"); break;
1218 case DW_LANG_C_plus_plus
: printf ("(C++)"); break;
1219 case DW_LANG_Fortran77
: printf ("(FORTRAN 77)"); break;
1220 case DW_LANG_Fortran90
: printf ("(Fortran 90)"); break;
1221 case DW_LANG_Modula2
: printf ("(Modula 2)"); break;
1222 case DW_LANG_Pascal83
: printf ("(ANSI Pascal)"); break;
1223 case DW_LANG_Ada83
: printf ("(Ada)"); break;
1224 case DW_LANG_Cobol74
: printf ("(Cobol 74)"); break;
1225 case DW_LANG_Cobol85
: printf ("(Cobol 85)"); break;
1226 /* DWARF 2.1 values. */
1227 case DW_LANG_C99
: printf ("(ANSI C99)"); break;
1228 case DW_LANG_Ada95
: printf ("(ADA 95)"); break;
1229 case DW_LANG_Fortran95
: printf ("(Fortran 95)"); break;
1230 /* MIPS extension. */
1231 case DW_LANG_Mips_Assembler
: printf ("(MIPS assembler)"); break;
1232 /* UPC extension. */
1233 case DW_LANG_Upc
: printf ("(Unified Parallel C)"); break;
1235 printf ("(Unknown: %lx)", uvalue
);
1240 case DW_AT_encoding
:
1243 case DW_ATE_void
: printf ("(void)"); break;
1244 case DW_ATE_address
: printf ("(machine address)"); break;
1245 case DW_ATE_boolean
: printf ("(boolean)"); break;
1246 case DW_ATE_complex_float
: printf ("(complex float)"); break;
1247 case DW_ATE_float
: printf ("(float)"); break;
1248 case DW_ATE_signed
: printf ("(signed)"); break;
1249 case DW_ATE_signed_char
: printf ("(signed char)"); break;
1250 case DW_ATE_unsigned
: printf ("(unsigned)"); break;
1251 case DW_ATE_unsigned_char
: printf ("(unsigned char)"); break;
1252 /* DWARF 2.1 value. */
1253 case DW_ATE_imaginary_float
: printf ("(imaginary float)"); break;
1254 case DW_ATE_decimal_float
: printf ("(decimal float)"); break;
1256 if (uvalue
>= DW_ATE_lo_user
1257 && uvalue
<= DW_ATE_hi_user
)
1258 printf ("(user defined type)");
1260 printf ("(unknown type)");
1265 case DW_AT_accessibility
:
1268 case DW_ACCESS_public
: printf ("(public)"); break;
1269 case DW_ACCESS_protected
: printf ("(protected)"); break;
1270 case DW_ACCESS_private
: printf ("(private)"); break;
1272 printf ("(unknown accessibility)");
1277 case DW_AT_visibility
:
1280 case DW_VIS_local
: printf ("(local)"); break;
1281 case DW_VIS_exported
: printf ("(exported)"); break;
1282 case DW_VIS_qualified
: printf ("(qualified)"); break;
1283 default: printf ("(unknown visibility)"); break;
1287 case DW_AT_virtuality
:
1290 case DW_VIRTUALITY_none
: printf ("(none)"); break;
1291 case DW_VIRTUALITY_virtual
: printf ("(virtual)"); break;
1292 case DW_VIRTUALITY_pure_virtual
:printf ("(pure_virtual)"); break;
1293 default: printf ("(unknown virtuality)"); break;
1297 case DW_AT_identifier_case
:
1300 case DW_ID_case_sensitive
: printf ("(case_sensitive)"); break;
1301 case DW_ID_up_case
: printf ("(up_case)"); break;
1302 case DW_ID_down_case
: printf ("(down_case)"); break;
1303 case DW_ID_case_insensitive
: printf ("(case_insensitive)"); break;
1304 default: printf ("(unknown case)"); break;
1308 case DW_AT_calling_convention
:
1311 case DW_CC_normal
: printf ("(normal)"); break;
1312 case DW_CC_program
: printf ("(program)"); break;
1313 case DW_CC_nocall
: printf ("(nocall)"); break;
1315 if (uvalue
>= DW_CC_lo_user
1316 && uvalue
<= DW_CC_hi_user
)
1317 printf ("(user defined)");
1319 printf ("(unknown convention)");
1323 case DW_AT_ordering
:
1326 case -1: printf ("(undefined)"); break;
1327 case 0: printf ("(row major)"); break;
1328 case 1: printf ("(column major)"); break;
1332 case DW_AT_frame_base
:
1333 have_frame_base
= 1;
1334 case DW_AT_location
:
1335 case DW_AT_data_member_location
:
1336 case DW_AT_vtable_elem_location
:
1337 case DW_AT_allocated
:
1338 case DW_AT_associated
:
1339 case DW_AT_data_location
:
1341 case DW_AT_upper_bound
:
1342 case DW_AT_lower_bound
:
1345 int need_frame_base
;
1348 need_frame_base
= decode_location_expression (block_start
,
1353 if (need_frame_base
&& !have_frame_base
)
1354 printf (_(" [without DW_AT_frame_base]"));
1356 else if (form
== DW_FORM_data4
|| form
== DW_FORM_data8
)
1357 printf (_("(location list)"));
1369 get_AT_name (unsigned long attribute
)
1373 case DW_AT_sibling
: return "DW_AT_sibling";
1374 case DW_AT_location
: return "DW_AT_location";
1375 case DW_AT_name
: return "DW_AT_name";
1376 case DW_AT_ordering
: return "DW_AT_ordering";
1377 case DW_AT_subscr_data
: return "DW_AT_subscr_data";
1378 case DW_AT_byte_size
: return "DW_AT_byte_size";
1379 case DW_AT_bit_offset
: return "DW_AT_bit_offset";
1380 case DW_AT_bit_size
: return "DW_AT_bit_size";
1381 case DW_AT_element_list
: return "DW_AT_element_list";
1382 case DW_AT_stmt_list
: return "DW_AT_stmt_list";
1383 case DW_AT_low_pc
: return "DW_AT_low_pc";
1384 case DW_AT_high_pc
: return "DW_AT_high_pc";
1385 case DW_AT_language
: return "DW_AT_language";
1386 case DW_AT_member
: return "DW_AT_member";
1387 case DW_AT_discr
: return "DW_AT_discr";
1388 case DW_AT_discr_value
: return "DW_AT_discr_value";
1389 case DW_AT_visibility
: return "DW_AT_visibility";
1390 case DW_AT_import
: return "DW_AT_import";
1391 case DW_AT_string_length
: return "DW_AT_string_length";
1392 case DW_AT_common_reference
: return "DW_AT_common_reference";
1393 case DW_AT_comp_dir
: return "DW_AT_comp_dir";
1394 case DW_AT_const_value
: return "DW_AT_const_value";
1395 case DW_AT_containing_type
: return "DW_AT_containing_type";
1396 case DW_AT_default_value
: return "DW_AT_default_value";
1397 case DW_AT_inline
: return "DW_AT_inline";
1398 case DW_AT_is_optional
: return "DW_AT_is_optional";
1399 case DW_AT_lower_bound
: return "DW_AT_lower_bound";
1400 case DW_AT_producer
: return "DW_AT_producer";
1401 case DW_AT_prototyped
: return "DW_AT_prototyped";
1402 case DW_AT_return_addr
: return "DW_AT_return_addr";
1403 case DW_AT_start_scope
: return "DW_AT_start_scope";
1404 case DW_AT_stride_size
: return "DW_AT_stride_size";
1405 case DW_AT_upper_bound
: return "DW_AT_upper_bound";
1406 case DW_AT_abstract_origin
: return "DW_AT_abstract_origin";
1407 case DW_AT_accessibility
: return "DW_AT_accessibility";
1408 case DW_AT_address_class
: return "DW_AT_address_class";
1409 case DW_AT_artificial
: return "DW_AT_artificial";
1410 case DW_AT_base_types
: return "DW_AT_base_types";
1411 case DW_AT_calling_convention
: return "DW_AT_calling_convention";
1412 case DW_AT_count
: return "DW_AT_count";
1413 case DW_AT_data_member_location
: return "DW_AT_data_member_location";
1414 case DW_AT_decl_column
: return "DW_AT_decl_column";
1415 case DW_AT_decl_file
: return "DW_AT_decl_file";
1416 case DW_AT_decl_line
: return "DW_AT_decl_line";
1417 case DW_AT_declaration
: return "DW_AT_declaration";
1418 case DW_AT_discr_list
: return "DW_AT_discr_list";
1419 case DW_AT_encoding
: return "DW_AT_encoding";
1420 case DW_AT_external
: return "DW_AT_external";
1421 case DW_AT_frame_base
: return "DW_AT_frame_base";
1422 case DW_AT_friend
: return "DW_AT_friend";
1423 case DW_AT_identifier_case
: return "DW_AT_identifier_case";
1424 case DW_AT_macro_info
: return "DW_AT_macro_info";
1425 case DW_AT_namelist_items
: return "DW_AT_namelist_items";
1426 case DW_AT_priority
: return "DW_AT_priority";
1427 case DW_AT_segment
: return "DW_AT_segment";
1428 case DW_AT_specification
: return "DW_AT_specification";
1429 case DW_AT_static_link
: return "DW_AT_static_link";
1430 case DW_AT_type
: return "DW_AT_type";
1431 case DW_AT_use_location
: return "DW_AT_use_location";
1432 case DW_AT_variable_parameter
: return "DW_AT_variable_parameter";
1433 case DW_AT_virtuality
: return "DW_AT_virtuality";
1434 case DW_AT_vtable_elem_location
: return "DW_AT_vtable_elem_location";
1435 /* DWARF 2.1 values. */
1436 case DW_AT_allocated
: return "DW_AT_allocated";
1437 case DW_AT_associated
: return "DW_AT_associated";
1438 case DW_AT_data_location
: return "DW_AT_data_location";
1439 case DW_AT_stride
: return "DW_AT_stride";
1440 case DW_AT_entry_pc
: return "DW_AT_entry_pc";
1441 case DW_AT_use_UTF8
: return "DW_AT_use_UTF8";
1442 case DW_AT_extension
: return "DW_AT_extension";
1443 case DW_AT_ranges
: return "DW_AT_ranges";
1444 case DW_AT_trampoline
: return "DW_AT_trampoline";
1445 case DW_AT_call_column
: return "DW_AT_call_column";
1446 case DW_AT_call_file
: return "DW_AT_call_file";
1447 case DW_AT_call_line
: return "DW_AT_call_line";
1448 /* SGI/MIPS extensions. */
1449 case DW_AT_MIPS_fde
: return "DW_AT_MIPS_fde";
1450 case DW_AT_MIPS_loop_begin
: return "DW_AT_MIPS_loop_begin";
1451 case DW_AT_MIPS_tail_loop_begin
: return "DW_AT_MIPS_tail_loop_begin";
1452 case DW_AT_MIPS_epilog_begin
: return "DW_AT_MIPS_epilog_begin";
1453 case DW_AT_MIPS_loop_unroll_factor
: return "DW_AT_MIPS_loop_unroll_factor";
1454 case DW_AT_MIPS_software_pipeline_depth
:
1455 return "DW_AT_MIPS_software_pipeline_depth";
1456 case DW_AT_MIPS_linkage_name
: return "DW_AT_MIPS_linkage_name";
1457 case DW_AT_MIPS_stride
: return "DW_AT_MIPS_stride";
1458 case DW_AT_MIPS_abstract_name
: return "DW_AT_MIPS_abstract_name";
1459 case DW_AT_MIPS_clone_origin
: return "DW_AT_MIPS_clone_origin";
1460 case DW_AT_MIPS_has_inlines
: return "DW_AT_MIPS_has_inlines";
1461 /* GNU extensions. */
1462 case DW_AT_sf_names
: return "DW_AT_sf_names";
1463 case DW_AT_src_info
: return "DW_AT_src_info";
1464 case DW_AT_mac_info
: return "DW_AT_mac_info";
1465 case DW_AT_src_coords
: return "DW_AT_src_coords";
1466 case DW_AT_body_begin
: return "DW_AT_body_begin";
1467 case DW_AT_body_end
: return "DW_AT_body_end";
1468 case DW_AT_GNU_vector
: return "DW_AT_GNU_vector";
1469 /* UPC extension. */
1470 case DW_AT_upc_threads_scaled
: return "DW_AT_upc_threads_scaled";
1473 static char buffer
[100];
1475 snprintf (buffer
, sizeof (buffer
), _("Unknown AT value: %lx"),
1482 static unsigned char *
1483 read_and_display_attr (unsigned long attribute
,
1485 unsigned char *data
,
1486 unsigned long cu_offset
,
1487 unsigned long pointer_size
,
1488 unsigned long offset_size
,
1490 debug_info
*debug_info_p
,
1494 printf (" %-18s:", get_AT_name (attribute
));
1495 data
= read_and_display_attr_value (attribute
, form
, data
, cu_offset
,
1496 pointer_size
, offset_size
,
1497 dwarf_version
, debug_info_p
,
1505 /* Process the contents of a .debug_info section. If do_loc is non-zero
1506 then we are scanning for location lists and we do not want to display
1507 anything to the user. */
1510 process_debug_info (struct dwarf_section
*section
, void *file
,
1513 unsigned char *start
= section
->start
;
1514 unsigned char *end
= start
+ section
->size
;
1515 unsigned char *section_begin
;
1517 unsigned int num_units
= 0;
1519 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
1520 && num_debug_info_entries
== 0)
1522 unsigned long length
;
1524 /* First scan the section to get the number of comp units. */
1525 for (section_begin
= start
, num_units
= 0; section_begin
< end
;
1528 /* Read the first 4 bytes. For a 32-bit DWARF section, this
1529 will be the length. For a 64-bit DWARF section, it'll be
1530 the escape code 0xffffffff followed by an 8 byte length. */
1531 length
= byte_get (section_begin
, 4);
1533 if (length
== 0xffffffff)
1535 length
= byte_get (section_begin
+ 4, 8);
1536 section_begin
+= length
+ 12;
1539 section_begin
+= length
+ 4;
1544 error (_("No comp units in %s section ?"), section
->name
);
1548 /* Then allocate an array to hold the information. */
1549 debug_information
= cmalloc (num_units
,
1550 sizeof (* debug_information
));
1551 if (debug_information
== NULL
)
1553 error (_("Not enough memory for a debug info array of %u entries"),
1561 printf (_("The section %s contains:\n\n"), section
->name
);
1563 load_debug_section (str
, file
);
1566 load_debug_section (abbrev
, file
);
1567 if (debug_displays
[abbrev
].section
.start
== NULL
)
1569 warn (_("Unable to locate %s section!\n"),
1570 debug_displays
[abbrev
].section
.name
);
1574 for (section_begin
= start
, unit
= 0; start
< end
; unit
++)
1576 DWARF2_Internal_CompUnit compunit
;
1577 unsigned char *hdrptr
;
1578 unsigned char *cu_abbrev_offset_ptr
;
1579 unsigned char *tags
;
1581 unsigned long cu_offset
;
1583 int initial_length_size
;
1587 compunit
.cu_length
= byte_get (hdrptr
, 4);
1590 if (compunit
.cu_length
== 0xffffffff)
1592 compunit
.cu_length
= byte_get (hdrptr
, 8);
1595 initial_length_size
= 12;
1600 initial_length_size
= 4;
1603 compunit
.cu_version
= byte_get (hdrptr
, 2);
1606 cu_offset
= start
- section_begin
;
1608 cu_abbrev_offset_ptr
= hdrptr
;
1609 compunit
.cu_abbrev_offset
= byte_get (hdrptr
, offset_size
);
1610 hdrptr
+= offset_size
;
1612 compunit
.cu_pointer_size
= byte_get (hdrptr
, 1);
1614 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
1615 && num_debug_info_entries
== 0)
1617 debug_information
[unit
].cu_offset
= cu_offset
;
1618 debug_information
[unit
].pointer_size
1619 = compunit
.cu_pointer_size
;
1620 debug_information
[unit
].base_address
= 0;
1621 debug_information
[unit
].loc_offsets
= NULL
;
1622 debug_information
[unit
].have_frame_base
= NULL
;
1623 debug_information
[unit
].max_loc_offsets
= 0;
1624 debug_information
[unit
].num_loc_offsets
= 0;
1625 debug_information
[unit
].range_lists
= NULL
;
1626 debug_information
[unit
].max_range_lists
= 0;
1627 debug_information
[unit
].num_range_lists
= 0;
1632 printf (_(" Compilation Unit @ offset 0x%lx:\n"), cu_offset
);
1633 printf (_(" Length: %ld\n"), compunit
.cu_length
);
1634 printf (_(" Version: %d\n"), compunit
.cu_version
);
1635 printf (_(" Abbrev Offset: %ld\n"), compunit
.cu_abbrev_offset
);
1636 printf (_(" Pointer Size: %d\n"), compunit
.cu_pointer_size
);
1639 if (cu_offset
+ compunit
.cu_length
+ initial_length_size
1642 warn (_("Debug info is corrupted, length is invalid (section is %lu bytes)\n"),
1643 (unsigned long)section
->size
);
1647 start
+= compunit
.cu_length
+ initial_length_size
;
1649 if (compunit
.cu_version
!= 2 && compunit
.cu_version
!= 3)
1651 warn (_("Only version 2 and 3 DWARF debug information is currently supported.\n"));
1657 /* Process the abbrevs used by this compilation unit. DWARF
1658 sections under Mach-O have non-zero addresses. */
1659 if (compunit
.cu_abbrev_offset
>= debug_displays
[abbrev
].section
.size
)
1660 warn (_("Debug info is corrupted, abbrev offset is invalid (section is %lu bytes)\n"),
1661 (unsigned long)debug_displays
[abbrev
].section
.size
);
1663 process_abbrev_section
1664 ((unsigned char *) debug_displays
[abbrev
].section
.start
1665 + compunit
.cu_abbrev_offset
- debug_displays
[abbrev
].section
.address
,
1666 (unsigned char *) debug_displays
[abbrev
].section
.start
1667 + debug_displays
[abbrev
].section
.size
);
1670 while (tags
< start
)
1672 unsigned int bytes_read
;
1673 unsigned long abbrev_number
;
1674 abbrev_entry
*entry
;
1677 abbrev_number
= read_leb128 (tags
, & bytes_read
, 0);
1680 /* A null DIE marks the end of a list of children. */
1681 if (abbrev_number
== 0)
1687 /* Scan through the abbreviation list until we reach the
1689 for (entry
= first_abbrev
;
1690 entry
&& entry
->entry
!= abbrev_number
;
1691 entry
= entry
->next
)
1696 warn (_("Unable to locate entry %lu in the abbreviation table\n"),
1702 printf (_(" <%d><%lx>: Abbrev Number: %lu (%s)\n"),
1704 (unsigned long) (tags
- section_begin
1707 get_TAG_name (entry
->tag
));
1712 need_base_address
= 0;
1714 case DW_TAG_compile_unit
:
1715 need_base_address
= 1;
1717 case DW_TAG_entry_point
:
1718 case DW_TAG_inlined_subroutine
:
1719 case DW_TAG_subprogram
:
1720 need_base_address
= 0;
1721 /* Assuming that there is no DW_AT_frame_base. */
1722 have_frame_base
= 0;
1726 for (attr
= entry
->first_attr
; attr
; attr
= attr
->next
)
1727 tags
= read_and_display_attr (attr
->attribute
,
1730 compunit
.cu_pointer_size
,
1732 compunit
.cu_version
,
1733 &debug_information
[unit
],
1736 if (entry
->children
)
1741 /* Set num_debug_info_entries here so that it can be used to check if
1742 we need to process .debug_loc and .debug_ranges sections. */
1743 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
1744 && num_debug_info_entries
== 0)
1745 num_debug_info_entries
= num_units
;
1755 /* Locate and scan the .debug_info section in the file and record the pointer
1756 sizes and offsets for the compilation units in it. Usually an executable
1757 will have just one pointer size, but this is not guaranteed, and so we try
1758 not to make any assumptions. Returns zero upon failure, or the number of
1759 compilation units upon success. */
1762 load_debug_info (void * file
)
1764 /* Reset the last pointer size so that we can issue correct error
1765 messages if we are displaying the contents of more than one section. */
1766 last_pointer_size
= 0;
1767 warned_about_missing_comp_units
= FALSE
;
1769 /* If we already have the information there is nothing else to do. */
1770 if (num_debug_info_entries
> 0)
1771 return num_debug_info_entries
;
1773 if (load_debug_section (info
, file
)
1774 && process_debug_info (&debug_displays
[info
].section
, file
, 1))
1775 return num_debug_info_entries
;
1781 display_debug_lines (struct dwarf_section
*section
, void *file
)
1783 unsigned char *start
= section
->start
;
1784 unsigned char *data
= start
;
1785 unsigned char *end
= start
+ section
->size
;
1787 printf (_("\nDump of debug contents of section %s:\n\n"),
1790 load_debug_info (file
);
1794 DWARF2_Internal_LineInfo info
;
1795 unsigned char *standard_opcodes
;
1796 unsigned char *end_of_sequence
;
1797 unsigned char *hdrptr
;
1798 int initial_length_size
;
1804 /* Check the length of the block. */
1805 info
.li_length
= byte_get (hdrptr
, 4);
1808 if (info
.li_length
== 0xffffffff)
1810 /* This section is 64-bit DWARF 3. */
1811 info
.li_length
= byte_get (hdrptr
, 8);
1814 initial_length_size
= 12;
1819 initial_length_size
= 4;
1822 if (info
.li_length
+ initial_length_size
> section
->size
)
1825 (_("The line info appears to be corrupt - the section is too small\n"));
1829 /* Check its version number. */
1830 info
.li_version
= byte_get (hdrptr
, 2);
1832 if (info
.li_version
!= 2 && info
.li_version
!= 3)
1834 warn (_("Only DWARF version 2 and 3 line info is currently supported.\n"));
1838 info
.li_prologue_length
= byte_get (hdrptr
, offset_size
);
1839 hdrptr
+= offset_size
;
1840 info
.li_min_insn_length
= byte_get (hdrptr
, 1);
1842 info
.li_default_is_stmt
= byte_get (hdrptr
, 1);
1844 info
.li_line_base
= byte_get (hdrptr
, 1);
1846 info
.li_line_range
= byte_get (hdrptr
, 1);
1848 info
.li_opcode_base
= byte_get (hdrptr
, 1);
1851 /* Sign extend the line base field. */
1852 info
.li_line_base
<<= 24;
1853 info
.li_line_base
>>= 24;
1855 printf (_(" Length: %ld\n"), info
.li_length
);
1856 printf (_(" DWARF Version: %d\n"), info
.li_version
);
1857 printf (_(" Prologue Length: %d\n"), info
.li_prologue_length
);
1858 printf (_(" Minimum Instruction Length: %d\n"), info
.li_min_insn_length
);
1859 printf (_(" Initial value of 'is_stmt': %d\n"), info
.li_default_is_stmt
);
1860 printf (_(" Line Base: %d\n"), info
.li_line_base
);
1861 printf (_(" Line Range: %d\n"), info
.li_line_range
);
1862 printf (_(" Opcode Base: %d\n"), info
.li_opcode_base
);
1864 end_of_sequence
= data
+ info
.li_length
+ initial_length_size
;
1866 reset_state_machine (info
.li_default_is_stmt
);
1868 /* Display the contents of the Opcodes table. */
1869 standard_opcodes
= hdrptr
;
1871 printf (_("\n Opcodes:\n"));
1873 for (i
= 1; i
< info
.li_opcode_base
; i
++)
1874 printf (_(" Opcode %d has %d args\n"), i
, standard_opcodes
[i
- 1]);
1876 /* Display the contents of the Directory table. */
1877 data
= standard_opcodes
+ info
.li_opcode_base
- 1;
1880 printf (_("\n The Directory Table is empty.\n"));
1883 printf (_("\n The Directory Table:\n"));
1887 printf (_(" %s\n"), data
);
1889 data
+= strlen ((char *) data
) + 1;
1893 /* Skip the NUL at the end of the table. */
1896 /* Display the contents of the File Name table. */
1898 printf (_("\n The File Name Table is empty.\n"));
1901 printf (_("\n The File Name Table:\n"));
1902 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
1906 unsigned char *name
;
1907 unsigned int bytes_read
;
1909 printf (_(" %d\t"), ++state_machine_regs
.last_file_entry
);
1912 data
+= strlen ((char *) data
) + 1;
1914 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
1916 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
1918 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
1920 printf (_("%s\n"), name
);
1924 /* Skip the NUL at the end of the table. */
1927 /* Now display the statements. */
1928 printf (_("\n Line Number Statements:\n"));
1930 while (data
< end_of_sequence
)
1932 unsigned char op_code
;
1934 unsigned long int uladv
;
1935 unsigned int bytes_read
;
1939 if (op_code
>= info
.li_opcode_base
)
1941 op_code
-= info
.li_opcode_base
;
1942 uladv
= (op_code
/ info
.li_line_range
) * info
.li_min_insn_length
;
1943 state_machine_regs
.address
+= uladv
;
1944 printf (_(" Special opcode %d: advance Address by %lu to 0x%lx"),
1945 op_code
, uladv
, state_machine_regs
.address
);
1946 adv
= (op_code
% info
.li_line_range
) + info
.li_line_base
;
1947 state_machine_regs
.line
+= adv
;
1948 printf (_(" and Line by %d to %d\n"),
1949 adv
, state_machine_regs
.line
);
1951 else switch (op_code
)
1953 case DW_LNS_extended_op
:
1954 data
+= process_extended_line_op (data
, info
.li_default_is_stmt
);
1958 printf (_(" Copy\n"));
1961 case DW_LNS_advance_pc
:
1962 uladv
= read_leb128 (data
, & bytes_read
, 0);
1963 uladv
*= info
.li_min_insn_length
;
1965 state_machine_regs
.address
+= uladv
;
1966 printf (_(" Advance PC by %lu to 0x%lx\n"), uladv
,
1967 state_machine_regs
.address
);
1970 case DW_LNS_advance_line
:
1971 adv
= read_leb128 (data
, & bytes_read
, 1);
1973 state_machine_regs
.line
+= adv
;
1974 printf (_(" Advance Line by %d to %d\n"), adv
,
1975 state_machine_regs
.line
);
1978 case DW_LNS_set_file
:
1979 adv
= read_leb128 (data
, & bytes_read
, 0);
1981 printf (_(" Set File Name to entry %d in the File Name Table\n"),
1983 state_machine_regs
.file
= adv
;
1986 case DW_LNS_set_column
:
1987 uladv
= read_leb128 (data
, & bytes_read
, 0);
1989 printf (_(" Set column to %lu\n"), uladv
);
1990 state_machine_regs
.column
= uladv
;
1993 case DW_LNS_negate_stmt
:
1994 adv
= state_machine_regs
.is_stmt
;
1996 printf (_(" Set is_stmt to %d\n"), adv
);
1997 state_machine_regs
.is_stmt
= adv
;
2000 case DW_LNS_set_basic_block
:
2001 printf (_(" Set basic block\n"));
2002 state_machine_regs
.basic_block
= 1;
2005 case DW_LNS_const_add_pc
:
2006 uladv
= (((255 - info
.li_opcode_base
) / info
.li_line_range
)
2007 * info
.li_min_insn_length
);
2008 state_machine_regs
.address
+= uladv
;
2009 printf (_(" Advance PC by constant %lu to 0x%lx\n"), uladv
,
2010 state_machine_regs
.address
);
2013 case DW_LNS_fixed_advance_pc
:
2014 uladv
= byte_get (data
, 2);
2016 state_machine_regs
.address
+= uladv
;
2017 printf (_(" Advance PC by fixed size amount %lu to 0x%lx\n"),
2018 uladv
, state_machine_regs
.address
);
2021 case DW_LNS_set_prologue_end
:
2022 printf (_(" Set prologue_end to true\n"));
2025 case DW_LNS_set_epilogue_begin
:
2026 printf (_(" Set epilogue_begin to true\n"));
2029 case DW_LNS_set_isa
:
2030 uladv
= read_leb128 (data
, & bytes_read
, 0);
2032 printf (_(" Set ISA to %lu\n"), uladv
);
2036 printf (_(" Unknown opcode %d with operands: "), op_code
);
2038 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
2040 printf ("0x%lx%s", read_leb128 (data
, &bytes_read
, 0),
2041 i
== 1 ? "" : ", ");
2055 display_debug_pubnames (struct dwarf_section
*section
,
2056 void *file ATTRIBUTE_UNUSED
)
2058 DWARF2_Internal_PubNames pubnames
;
2059 unsigned char *start
= section
->start
;
2060 unsigned char *end
= start
+ section
->size
;
2062 printf (_("Contents of the %s section:\n\n"), section
->name
);
2066 unsigned char *data
;
2067 unsigned long offset
;
2068 int offset_size
, initial_length_size
;
2072 pubnames
.pn_length
= byte_get (data
, 4);
2074 if (pubnames
.pn_length
== 0xffffffff)
2076 pubnames
.pn_length
= byte_get (data
, 8);
2079 initial_length_size
= 12;
2084 initial_length_size
= 4;
2087 pubnames
.pn_version
= byte_get (data
, 2);
2089 pubnames
.pn_offset
= byte_get (data
, offset_size
);
2090 data
+= offset_size
;
2091 pubnames
.pn_size
= byte_get (data
, offset_size
);
2092 data
+= offset_size
;
2094 start
+= pubnames
.pn_length
+ initial_length_size
;
2096 if (pubnames
.pn_version
!= 2 && pubnames
.pn_version
!= 3)
2098 static int warned
= 0;
2102 warn (_("Only DWARF 2 and 3 pubnames are currently supported\n"));
2109 printf (_(" Length: %ld\n"),
2110 pubnames
.pn_length
);
2111 printf (_(" Version: %d\n"),
2112 pubnames
.pn_version
);
2113 printf (_(" Offset into .debug_info section: %ld\n"),
2114 pubnames
.pn_offset
);
2115 printf (_(" Size of area in .debug_info section: %ld\n"),
2118 printf (_("\n Offset\tName\n"));
2122 offset
= byte_get (data
, offset_size
);
2126 data
+= offset_size
;
2127 printf (" %-6ld\t\t%s\n", offset
, data
);
2128 data
+= strlen ((char *) data
) + 1;
2131 while (offset
!= 0);
2139 display_debug_macinfo (struct dwarf_section
*section
,
2140 void *file ATTRIBUTE_UNUSED
)
2142 unsigned char *start
= section
->start
;
2143 unsigned char *end
= start
+ section
->size
;
2144 unsigned char *curr
= start
;
2145 unsigned int bytes_read
;
2146 enum dwarf_macinfo_record_type op
;
2148 printf (_("Contents of the %s section:\n\n"), section
->name
);
2152 unsigned int lineno
;
2160 case DW_MACINFO_start_file
:
2162 unsigned int filenum
;
2164 lineno
= read_leb128 (curr
, & bytes_read
, 0);
2166 filenum
= read_leb128 (curr
, & bytes_read
, 0);
2169 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"),
2174 case DW_MACINFO_end_file
:
2175 printf (_(" DW_MACINFO_end_file\n"));
2178 case DW_MACINFO_define
:
2179 lineno
= read_leb128 (curr
, & bytes_read
, 0);
2181 string
= (char *) curr
;
2182 curr
+= strlen (string
) + 1;
2183 printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"),
2187 case DW_MACINFO_undef
:
2188 lineno
= read_leb128 (curr
, & bytes_read
, 0);
2190 string
= (char *) curr
;
2191 curr
+= strlen (string
) + 1;
2192 printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"),
2196 case DW_MACINFO_vendor_ext
:
2198 unsigned int constant
;
2200 constant
= read_leb128 (curr
, & bytes_read
, 0);
2202 string
= (char *) curr
;
2203 curr
+= strlen (string
) + 1;
2204 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"),
2215 display_debug_abbrev (struct dwarf_section
*section
,
2216 void *file ATTRIBUTE_UNUSED
)
2218 abbrev_entry
*entry
;
2219 unsigned char *start
= section
->start
;
2220 unsigned char *end
= start
+ section
->size
;
2222 printf (_("Contents of the %s section:\n\n"), section
->name
);
2228 start
= process_abbrev_section (start
, end
);
2230 if (first_abbrev
== NULL
)
2233 printf (_(" Number TAG\n"));
2235 for (entry
= first_abbrev
; entry
; entry
= entry
->next
)
2239 printf (_(" %ld %s [%s]\n"),
2241 get_TAG_name (entry
->tag
),
2242 entry
->children
? _("has children") : _("no children"));
2244 for (attr
= entry
->first_attr
; attr
; attr
= attr
->next
)
2245 printf (_(" %-18s %s\n"),
2246 get_AT_name (attr
->attribute
),
2247 get_FORM_name (attr
->form
));
2258 display_debug_loc (struct dwarf_section
*section
, void *file
)
2260 unsigned char *start
= section
->start
;
2261 unsigned char *section_end
;
2262 unsigned long bytes
;
2263 unsigned char *section_begin
= start
;
2264 unsigned int num_loc_list
= 0;
2265 unsigned long last_offset
= 0;
2266 unsigned int first
= 0;
2269 int seen_first_offset
= 0;
2270 int use_debug_info
= 1;
2271 unsigned char *next
;
2273 bytes
= section
->size
;
2274 section_end
= start
+ bytes
;
2278 printf (_("\nThe %s section is empty.\n"), section
->name
);
2282 load_debug_info (file
);
2284 /* Check the order of location list in .debug_info section. If
2285 offsets of location lists are in the ascending order, we can
2286 use `debug_information' directly. */
2287 for (i
= 0; i
< num_debug_info_entries
; i
++)
2291 num
= debug_information
[i
].num_loc_offsets
;
2292 num_loc_list
+= num
;
2294 /* Check if we can use `debug_information' directly. */
2295 if (use_debug_info
&& num
!= 0)
2297 if (!seen_first_offset
)
2299 /* This is the first location list. */
2300 last_offset
= debug_information
[i
].loc_offsets
[0];
2302 seen_first_offset
= 1;
2308 for (; j
< num
; j
++)
2311 debug_information
[i
].loc_offsets
[j
])
2316 last_offset
= debug_information
[i
].loc_offsets
[j
];
2321 if (!use_debug_info
)
2322 /* FIXME: Should we handle this case? */
2323 error (_("Location lists in .debug_info section aren't in ascending order!\n"));
2325 if (!seen_first_offset
)
2326 error (_("No location lists in .debug_info section!\n"));
2328 /* DWARF sections under Mach-O have non-zero addresses. */
2329 if (debug_information
[first
].num_loc_offsets
> 0
2330 && debug_information
[first
].loc_offsets
[0] != section
->address
)
2331 warn (_("Location lists in %s section start at 0x%lx\n"),
2332 section
->name
, debug_information
[first
].loc_offsets
[0]);
2334 printf (_("Contents of the %s section:\n\n"), section
->name
);
2335 printf (_(" Offset Begin End Expression\n"));
2337 seen_first_offset
= 0;
2338 for (i
= first
; i
< num_debug_info_entries
; i
++)
2340 unsigned long begin
;
2342 unsigned short length
;
2343 unsigned long offset
;
2344 unsigned int pointer_size
;
2345 unsigned long cu_offset
;
2346 unsigned long base_address
;
2347 int need_frame_base
;
2350 pointer_size
= debug_information
[i
].pointer_size
;
2351 cu_offset
= debug_information
[i
].cu_offset
;
2353 for (j
= 0; j
< debug_information
[i
].num_loc_offsets
; j
++)
2355 has_frame_base
= debug_information
[i
].have_frame_base
[j
];
2356 /* DWARF sections under Mach-O have non-zero addresses. */
2357 offset
= debug_information
[i
].loc_offsets
[j
] - section
->address
;
2358 next
= section_begin
+ offset
;
2359 base_address
= debug_information
[i
].base_address
;
2361 if (!seen_first_offset
)
2362 seen_first_offset
= 1;
2366 warn (_("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n"),
2367 (long)(start
- section_begin
), (long)(next
- section_begin
));
2368 else if (start
> next
)
2369 warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n"),
2370 (long)(start
- section_begin
), (long)(next
- section_begin
));
2374 if (offset
>= bytes
)
2376 warn (_("Offset 0x%lx is bigger than .debug_loc section size.\n"),
2383 if (start
+ 2 * pointer_size
> section_end
)
2385 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
2390 begin
= byte_get (start
, pointer_size
);
2391 start
+= pointer_size
;
2392 end
= byte_get (start
, pointer_size
);
2393 start
+= pointer_size
;
2395 if (begin
== 0 && end
== 0)
2397 printf (_(" %8.8lx <End of list>\n"), offset
);
2401 /* Check base address specifiers. */
2402 if (begin
== -1UL && end
!= -1UL)
2405 printf (_(" %8.8lx %8.8lx %8.8lx (base address)\n"),
2406 offset
, begin
, end
);
2410 if (start
+ 2 > section_end
)
2412 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
2417 length
= byte_get (start
, 2);
2420 if (start
+ length
> section_end
)
2422 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
2427 printf (" %8.8lx %8.8lx %8.8lx (",
2428 offset
, begin
+ base_address
, end
+ base_address
);
2429 need_frame_base
= decode_location_expression (start
,
2435 if (need_frame_base
&& !has_frame_base
)
2436 printf (_(" [without DW_AT_frame_base]"));
2439 fputs (_(" (start == end)"), stdout
);
2440 else if (begin
> end
)
2441 fputs (_(" (start > end)"), stdout
);
2453 display_debug_str (struct dwarf_section
*section
,
2454 void *file ATTRIBUTE_UNUSED
)
2456 unsigned char *start
= section
->start
;
2457 unsigned long bytes
= section
->size
;
2458 dwarf_vma addr
= section
->address
;
2462 printf (_("\nThe %s section is empty.\n"), section
->name
);
2466 printf (_("Contents of the %s section:\n\n"), section
->name
);
2474 lbytes
= (bytes
> 16 ? 16 : bytes
);
2476 printf (" 0x%8.8lx ", (unsigned long) addr
);
2478 for (j
= 0; j
< 16; j
++)
2481 printf ("%2.2x", start
[j
]);
2489 for (j
= 0; j
< lbytes
; j
++)
2492 if (k
>= ' ' && k
< 0x80)
2512 display_debug_info (struct dwarf_section
*section
, void *file
)
2514 return process_debug_info (section
, file
, 0);
2519 display_debug_aranges (struct dwarf_section
*section
,
2520 void *file ATTRIBUTE_UNUSED
)
2522 unsigned char *start
= section
->start
;
2523 unsigned char *end
= start
+ section
->size
;
2525 printf (_("The section %s contains:\n\n"), section
->name
);
2529 unsigned char *hdrptr
;
2530 DWARF2_Internal_ARange arange
;
2531 unsigned char *ranges
;
2532 unsigned long length
;
2533 unsigned long address
;
2534 unsigned char address_size
;
2537 int initial_length_size
;
2541 arange
.ar_length
= byte_get (hdrptr
, 4);
2544 if (arange
.ar_length
== 0xffffffff)
2546 arange
.ar_length
= byte_get (hdrptr
, 8);
2549 initial_length_size
= 12;
2554 initial_length_size
= 4;
2557 arange
.ar_version
= byte_get (hdrptr
, 2);
2560 arange
.ar_info_offset
= byte_get (hdrptr
, offset_size
);
2561 hdrptr
+= offset_size
;
2563 arange
.ar_pointer_size
= byte_get (hdrptr
, 1);
2566 arange
.ar_segment_size
= byte_get (hdrptr
, 1);
2569 if (arange
.ar_version
!= 2 && arange
.ar_version
!= 3)
2571 warn (_("Only DWARF 2 and 3 aranges are currently supported.\n"));
2575 printf (_(" Length: %ld\n"), arange
.ar_length
);
2576 printf (_(" Version: %d\n"), arange
.ar_version
);
2577 printf (_(" Offset into .debug_info: %lx\n"), arange
.ar_info_offset
);
2578 printf (_(" Pointer Size: %d\n"), arange
.ar_pointer_size
);
2579 printf (_(" Segment Size: %d\n"), arange
.ar_segment_size
);
2581 address_size
= arange
.ar_pointer_size
+ arange
.ar_segment_size
;
2583 /* The DWARF spec does not require that the address size be a power
2584 of two, but we do. This will have to change if we ever encounter
2585 an uneven architecture. */
2586 if ((address_size
& (address_size
- 1)) != 0)
2588 warn (_("Pointer size + Segment size is not a power of two.\n"));
2592 if (address_size
> 4)
2593 printf (_("\n Address Length\n"));
2595 printf (_("\n Address Length\n"));
2599 /* Must pad to an alignment boundary that is twice the address size. */
2600 excess
= (hdrptr
- start
) % (2 * address_size
);
2602 ranges
+= (2 * address_size
) - excess
;
2604 start
+= arange
.ar_length
+ initial_length_size
;
2606 while (ranges
+ 2 * address_size
<= start
)
2608 address
= byte_get (ranges
, address_size
);
2610 ranges
+= address_size
;
2612 length
= byte_get (ranges
, address_size
);
2614 ranges
+= address_size
;
2616 if (address_size
> 4)
2617 printf (" 0x%16.16lx 0x%lx\n", address
, length
);
2619 printf (" 0x%8.8lx 0x%lx\n", address
, length
);
2629 display_debug_ranges (struct dwarf_section
*section
,
2630 void *file ATTRIBUTE_UNUSED
)
2632 unsigned char *start
= section
->start
;
2633 unsigned char *section_end
;
2634 unsigned long bytes
;
2635 unsigned char *section_begin
= start
;
2636 unsigned int num_range_list
= 0;
2637 unsigned long last_offset
= 0;
2638 unsigned int first
= 0;
2641 int seen_first_offset
= 0;
2642 int use_debug_info
= 1;
2643 unsigned char *next
;
2645 bytes
= section
->size
;
2646 section_end
= start
+ bytes
;
2650 printf (_("\nThe %s section is empty.\n"), section
->name
);
2654 load_debug_info (file
);
2656 /* Check the order of range list in .debug_info section. If
2657 offsets of range lists are in the ascending order, we can
2658 use `debug_information' directly. */
2659 for (i
= 0; i
< num_debug_info_entries
; i
++)
2663 num
= debug_information
[i
].num_range_lists
;
2664 num_range_list
+= num
;
2666 /* Check if we can use `debug_information' directly. */
2667 if (use_debug_info
&& num
!= 0)
2669 if (!seen_first_offset
)
2671 /* This is the first range list. */
2672 last_offset
= debug_information
[i
].range_lists
[0];
2674 seen_first_offset
= 1;
2680 for (; j
< num
; j
++)
2683 debug_information
[i
].range_lists
[j
])
2688 last_offset
= debug_information
[i
].range_lists
[j
];
2693 if (!use_debug_info
)
2694 /* FIXME: Should we handle this case? */
2695 error (_("Range lists in .debug_info section aren't in ascending order!\n"));
2697 if (!seen_first_offset
)
2698 error (_("No range lists in .debug_info section!\n"));
2700 /* DWARF sections under Mach-O have non-zero addresses. */
2701 if (debug_information
[first
].num_range_lists
> 0
2702 && debug_information
[first
].range_lists
[0] != section
->address
)
2703 warn (_("Range lists in %s section start at 0x%lx\n"),
2704 section
->name
, debug_information
[first
].range_lists
[0]);
2706 printf (_("Contents of the %s section:\n\n"), section
->name
);
2707 printf (_(" Offset Begin End\n"));
2709 seen_first_offset
= 0;
2710 for (i
= first
; i
< num_debug_info_entries
; i
++)
2712 unsigned long begin
;
2714 unsigned long offset
;
2715 unsigned int pointer_size
;
2716 unsigned long base_address
;
2718 pointer_size
= debug_information
[i
].pointer_size
;
2720 for (j
= 0; j
< debug_information
[i
].num_range_lists
; j
++)
2722 /* DWARF sections under Mach-O have non-zero addresses. */
2723 offset
= debug_information
[i
].range_lists
[j
] - section
->address
;
2724 next
= section_begin
+ offset
;
2725 base_address
= debug_information
[i
].base_address
;
2727 if (!seen_first_offset
)
2728 seen_first_offset
= 1;
2732 warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"),
2733 (long)(start
- section_begin
),
2734 (long)(next
- section_begin
), section
->name
);
2735 else if (start
> next
)
2736 warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"),
2737 (long)(start
- section_begin
),
2738 (long)(next
- section_begin
), section
->name
);
2744 begin
= byte_get (start
, pointer_size
);
2745 start
+= pointer_size
;
2746 end
= byte_get (start
, pointer_size
);
2747 start
+= pointer_size
;
2749 if (begin
== 0 && end
== 0)
2751 printf (_(" %8.8lx <End of list>\n"), offset
);
2755 /* Check base address specifiers. */
2756 if (begin
== -1UL && end
!= -1UL)
2759 printf (" %8.8lx %8.8lx %8.8lx (base address)\n",
2760 offset
, begin
, end
);
2764 printf (" %8.8lx %8.8lx %8.8lx",
2765 offset
, begin
+ base_address
, end
+ base_address
);
2768 fputs (_(" (start == end)"), stdout
);
2769 else if (begin
> end
)
2770 fputs (_(" (start > end)"), stdout
);
2780 typedef struct Frame_Chunk
2782 struct Frame_Chunk
*next
;
2783 unsigned char *chunk_start
;
2785 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
2786 short int *col_type
;
2789 unsigned int code_factor
;
2791 unsigned long pc_begin
;
2792 unsigned long pc_range
;
2796 unsigned char fde_encoding
;
2797 unsigned char cfa_exp
;
2801 /* A marker for a col_type that means this column was never referenced
2802 in the frame info. */
2803 #define DW_CFA_unreferenced (-1)
2806 frame_need_space (Frame_Chunk
*fc
, int reg
)
2808 int prev
= fc
->ncols
;
2810 if (reg
< fc
->ncols
)
2813 fc
->ncols
= reg
+ 1;
2814 fc
->col_type
= xcrealloc (fc
->col_type
, fc
->ncols
, sizeof (short int));
2815 fc
->col_offset
= xcrealloc (fc
->col_offset
, fc
->ncols
, sizeof (int));
2817 while (prev
< fc
->ncols
)
2819 fc
->col_type
[prev
] = DW_CFA_unreferenced
;
2820 fc
->col_offset
[prev
] = 0;
2826 frame_display_row (Frame_Chunk
*fc
, int *need_col_headers
, int *max_regs
)
2831 if (*max_regs
< fc
->ncols
)
2832 *max_regs
= fc
->ncols
;
2834 if (*need_col_headers
)
2836 *need_col_headers
= 0;
2838 printf (" LOC CFA ");
2840 for (r
= 0; r
< *max_regs
; r
++)
2841 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
2846 printf ("r%-4d", r
);
2852 printf ("%08lx ", fc
->pc_begin
);
2854 strcpy (tmp
, "exp");
2856 sprintf (tmp
, "r%d%+d", fc
->cfa_reg
, fc
->cfa_offset
);
2857 printf ("%-8s ", tmp
);
2859 for (r
= 0; r
< fc
->ncols
; r
++)
2861 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
2863 switch (fc
->col_type
[r
])
2865 case DW_CFA_undefined
:
2868 case DW_CFA_same_value
:
2872 sprintf (tmp
, "c%+d", fc
->col_offset
[r
]);
2874 case DW_CFA_val_offset
:
2875 sprintf (tmp
, "v%+d", fc
->col_offset
[r
]);
2877 case DW_CFA_register
:
2878 sprintf (tmp
, "r%d", fc
->col_offset
[r
]);
2880 case DW_CFA_expression
:
2881 strcpy (tmp
, "exp");
2883 case DW_CFA_val_expression
:
2884 strcpy (tmp
, "vexp");
2887 strcpy (tmp
, "n/a");
2890 printf ("%-5s", tmp
);
2897 size_of_encoded_value (int encoding
)
2899 switch (encoding
& 0x7)
2902 case 0: return eh_addr_size
;
2910 get_encoded_value (unsigned char *data
, int encoding
)
2912 int size
= size_of_encoded_value (encoding
);
2914 if (encoding
& DW_EH_PE_signed
)
2915 return byte_get_signed (data
, size
);
2917 return byte_get (data
, size
);
2920 #define GET(N) byte_get (start, N); start += N
2921 #define LEB() read_leb128 (start, & length_return, 0); start += length_return
2922 #define SLEB() read_leb128 (start, & length_return, 1); start += length_return
2925 display_debug_frames (struct dwarf_section
*section
,
2926 void *file ATTRIBUTE_UNUSED
)
2928 unsigned char *start
= section
->start
;
2929 unsigned char *end
= start
+ section
->size
;
2930 unsigned char *section_start
= start
;
2931 Frame_Chunk
*chunks
= 0;
2932 Frame_Chunk
*remembered_state
= 0;
2934 int is_eh
= strcmp (section
->name
, ".eh_frame") == 0;
2935 unsigned int length_return
;
2938 printf (_("The section %s contains:\n"), section
->name
);
2942 unsigned char *saved_start
;
2943 unsigned char *block_end
;
2944 unsigned long length
;
2945 unsigned long cie_id
;
2948 int need_col_headers
= 1;
2949 unsigned char *augmentation_data
= NULL
;
2950 unsigned long augmentation_data_len
= 0;
2951 int encoded_ptr_size
= eh_addr_size
;
2953 int initial_length_size
;
2955 saved_start
= start
;
2956 length
= byte_get (start
, 4); start
+= 4;
2960 printf ("\n%08lx ZERO terminator\n\n",
2961 (unsigned long)(saved_start
- section_start
));
2965 if (length
== 0xffffffff)
2967 length
= byte_get (start
, 8);
2970 initial_length_size
= 12;
2975 initial_length_size
= 4;
2978 block_end
= saved_start
+ length
+ initial_length_size
;
2979 if (block_end
> end
)
2981 warn ("Invalid length %#08lx in FDE at %#08lx\n",
2982 length
, (unsigned long)(saved_start
- section_start
));
2985 cie_id
= byte_get (start
, offset_size
); start
+= offset_size
;
2987 if (is_eh
? (cie_id
== 0) : (cie_id
== DW_CIE_ID
))
2991 fc
= xmalloc (sizeof (Frame_Chunk
));
2992 memset (fc
, 0, sizeof (Frame_Chunk
));
2996 fc
->chunk_start
= saved_start
;
2998 fc
->col_type
= xmalloc (sizeof (short int));
2999 fc
->col_offset
= xmalloc (sizeof (int));
3000 frame_need_space (fc
, max_regs
-1);
3004 fc
->augmentation
= (char *) start
;
3005 start
= (unsigned char *) strchr ((char *) start
, '\0') + 1;
3007 if (fc
->augmentation
[0] == 'z')
3009 fc
->code_factor
= LEB ();
3010 fc
->data_factor
= SLEB ();
3019 augmentation_data_len
= LEB ();
3020 augmentation_data
= start
;
3021 start
+= augmentation_data_len
;
3023 else if (strcmp (fc
->augmentation
, "eh") == 0)
3025 start
+= eh_addr_size
;
3026 fc
->code_factor
= LEB ();
3027 fc
->data_factor
= SLEB ();
3039 fc
->code_factor
= LEB ();
3040 fc
->data_factor
= SLEB ();
3052 if (do_debug_frames_interp
)
3053 printf ("\n%08lx %08lx %08lx CIE \"%s\" cf=%d df=%d ra=%d\n",
3054 (unsigned long)(saved_start
- section_start
), length
, cie_id
,
3055 fc
->augmentation
, fc
->code_factor
, fc
->data_factor
,
3059 printf ("\n%08lx %08lx %08lx CIE\n",
3060 (unsigned long)(saved_start
- section_start
), length
, cie_id
);
3061 printf (" Version: %d\n", version
);
3062 printf (" Augmentation: \"%s\"\n", fc
->augmentation
);
3063 printf (" Code alignment factor: %u\n", fc
->code_factor
);
3064 printf (" Data alignment factor: %d\n", fc
->data_factor
);
3065 printf (" Return address column: %d\n", fc
->ra
);
3067 if (augmentation_data_len
)
3070 printf (" Augmentation data: ");
3071 for (i
= 0; i
< augmentation_data_len
; ++i
)
3072 printf (" %02x", augmentation_data
[i
]);
3078 if (augmentation_data_len
)
3080 unsigned char *p
, *q
;
3081 p
= (unsigned char *) fc
->augmentation
+ 1;
3082 q
= augmentation_data
;
3089 q
+= 1 + size_of_encoded_value (*q
);
3091 fc
->fde_encoding
= *q
++;
3097 if (fc
->fde_encoding
)
3098 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
3101 frame_need_space (fc
, fc
->ra
);
3105 unsigned char *look_for
;
3106 static Frame_Chunk fde_fc
;
3109 memset (fc
, 0, sizeof (Frame_Chunk
));
3111 look_for
= is_eh
? start
- 4 - cie_id
: section_start
+ cie_id
;
3113 for (cie
= chunks
; cie
; cie
= cie
->next
)
3114 if (cie
->chunk_start
== look_for
)
3119 warn ("Invalid CIE pointer %#08lx in FDE at %#08lx\n",
3120 cie_id
, (unsigned long)(saved_start
- section_start
));
3122 fc
->col_type
= xmalloc (sizeof (short int));
3123 fc
->col_offset
= xmalloc (sizeof (int));
3124 frame_need_space (fc
, max_regs
- 1);
3126 fc
->augmentation
= "";
3127 fc
->fde_encoding
= 0;
3131 fc
->ncols
= cie
->ncols
;
3132 fc
->col_type
= xcmalloc (fc
->ncols
, sizeof (short int));
3133 fc
->col_offset
= xcmalloc (fc
->ncols
, sizeof (int));
3134 memcpy (fc
->col_type
, cie
->col_type
, fc
->ncols
* sizeof (short int));
3135 memcpy (fc
->col_offset
, cie
->col_offset
, fc
->ncols
* sizeof (int));
3136 fc
->augmentation
= cie
->augmentation
;
3137 fc
->code_factor
= cie
->code_factor
;
3138 fc
->data_factor
= cie
->data_factor
;
3139 fc
->cfa_reg
= cie
->cfa_reg
;
3140 fc
->cfa_offset
= cie
->cfa_offset
;
3142 frame_need_space (fc
, max_regs
-1);
3143 fc
->fde_encoding
= cie
->fde_encoding
;
3146 if (fc
->fde_encoding
)
3147 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
3149 fc
->pc_begin
= get_encoded_value (start
, fc
->fde_encoding
);
3150 if ((fc
->fde_encoding
& 0x70) == DW_EH_PE_pcrel
3151 /* Don't adjust for relocatable file since there's
3152 invariably a pcrel reloc here, which we haven't
3155 fc
->pc_begin
+= section
->address
+ (start
- section_start
);
3156 start
+= encoded_ptr_size
;
3157 fc
->pc_range
= byte_get (start
, encoded_ptr_size
);
3158 start
+= encoded_ptr_size
;
3160 if (cie
->augmentation
[0] == 'z')
3162 augmentation_data_len
= LEB ();
3163 augmentation_data
= start
;
3164 start
+= augmentation_data_len
;
3167 printf ("\n%08lx %08lx %08lx FDE cie=%08lx pc=%08lx..%08lx\n",
3168 (unsigned long)(saved_start
- section_start
), length
, cie_id
,
3169 (unsigned long)(cie
->chunk_start
- section_start
),
3170 fc
->pc_begin
, fc
->pc_begin
+ fc
->pc_range
);
3171 if (! do_debug_frames_interp
&& augmentation_data_len
)
3175 printf (" Augmentation data: ");
3176 for (i
= 0; i
< augmentation_data_len
; ++i
)
3177 printf (" %02x", augmentation_data
[i
]);
3183 /* At this point, fc is the current chunk, cie (if any) is set, and
3184 we're about to interpret instructions for the chunk. */
3185 /* ??? At present we need to do this always, since this sizes the
3186 fc->col_type and fc->col_offset arrays, which we write into always.
3187 We should probably split the interpreted and non-interpreted bits
3188 into two different routines, since there's so much that doesn't
3189 really overlap between them. */
3190 if (1 || do_debug_frames_interp
)
3192 /* Start by making a pass over the chunk, allocating storage
3193 and taking note of what registers are used. */
3194 unsigned char *tmp
= start
;
3196 while (start
< block_end
)
3199 unsigned long reg
, tmp
;
3206 /* Warning: if you add any more cases to this switch, be
3207 sure to add them to the corresponding switch below. */
3210 case DW_CFA_advance_loc
:
3214 frame_need_space (fc
, opa
);
3215 fc
->col_type
[opa
] = DW_CFA_undefined
;
3217 case DW_CFA_restore
:
3218 frame_need_space (fc
, opa
);
3219 fc
->col_type
[opa
] = DW_CFA_undefined
;
3221 case DW_CFA_set_loc
:
3222 start
+= encoded_ptr_size
;
3224 case DW_CFA_advance_loc1
:
3227 case DW_CFA_advance_loc2
:
3230 case DW_CFA_advance_loc4
:
3233 case DW_CFA_offset_extended
:
3234 case DW_CFA_val_offset
:
3235 reg
= LEB (); LEB ();
3236 frame_need_space (fc
, reg
);
3237 fc
->col_type
[reg
] = DW_CFA_undefined
;
3239 case DW_CFA_restore_extended
:
3241 frame_need_space (fc
, reg
);
3242 fc
->col_type
[reg
] = DW_CFA_undefined
;
3244 case DW_CFA_undefined
:
3246 frame_need_space (fc
, reg
);
3247 fc
->col_type
[reg
] = DW_CFA_undefined
;
3249 case DW_CFA_same_value
:
3251 frame_need_space (fc
, reg
);
3252 fc
->col_type
[reg
] = DW_CFA_undefined
;
3254 case DW_CFA_register
:
3255 reg
= LEB (); LEB ();
3256 frame_need_space (fc
, reg
);
3257 fc
->col_type
[reg
] = DW_CFA_undefined
;
3259 case DW_CFA_def_cfa
:
3262 case DW_CFA_def_cfa_register
:
3265 case DW_CFA_def_cfa_offset
:
3268 case DW_CFA_def_cfa_expression
:
3272 case DW_CFA_expression
:
3273 case DW_CFA_val_expression
:
3277 frame_need_space (fc
, reg
);
3278 fc
->col_type
[reg
] = DW_CFA_undefined
;
3280 case DW_CFA_offset_extended_sf
:
3281 case DW_CFA_val_offset_sf
:
3282 reg
= LEB (); SLEB ();
3283 frame_need_space (fc
, reg
);
3284 fc
->col_type
[reg
] = DW_CFA_undefined
;
3286 case DW_CFA_def_cfa_sf
:
3289 case DW_CFA_def_cfa_offset_sf
:
3292 case DW_CFA_MIPS_advance_loc8
:
3295 case DW_CFA_GNU_args_size
:
3298 case DW_CFA_GNU_negative_offset_extended
:
3299 reg
= LEB (); LEB ();
3300 frame_need_space (fc
, reg
);
3301 fc
->col_type
[reg
] = DW_CFA_undefined
;
3310 /* Now we know what registers are used, make a second pass over
3311 the chunk, this time actually printing out the info. */
3313 while (start
< block_end
)
3316 unsigned long ul
, reg
, roffs
;
3325 /* Warning: if you add any more cases to this switch, be
3326 sure to add them to the corresponding switch above. */
3329 case DW_CFA_advance_loc
:
3330 if (do_debug_frames_interp
)
3331 frame_display_row (fc
, &need_col_headers
, &max_regs
);
3333 printf (" DW_CFA_advance_loc: %d to %08lx\n",
3334 opa
* fc
->code_factor
,
3335 fc
->pc_begin
+ opa
* fc
->code_factor
);
3336 fc
->pc_begin
+= opa
* fc
->code_factor
;
3341 if (! do_debug_frames_interp
)
3342 printf (" DW_CFA_offset: r%d at cfa%+ld\n",
3343 opa
, roffs
* fc
->data_factor
);
3344 fc
->col_type
[opa
] = DW_CFA_offset
;
3345 fc
->col_offset
[opa
] = roffs
* fc
->data_factor
;
3348 case DW_CFA_restore
:
3349 if (! do_debug_frames_interp
)
3350 printf (" DW_CFA_restore: r%d\n", opa
);
3351 fc
->col_type
[opa
] = cie
->col_type
[opa
];
3352 fc
->col_offset
[opa
] = cie
->col_offset
[opa
];
3355 case DW_CFA_set_loc
:
3356 vma
= get_encoded_value (start
, fc
->fde_encoding
);
3357 if ((fc
->fde_encoding
& 0x70) == DW_EH_PE_pcrel
3359 vma
+= section
->address
+ (start
- section_start
);
3360 start
+= encoded_ptr_size
;
3361 if (do_debug_frames_interp
)
3362 frame_display_row (fc
, &need_col_headers
, &max_regs
);
3364 printf (" DW_CFA_set_loc: %08lx\n", (unsigned long)vma
);
3368 case DW_CFA_advance_loc1
:
3369 ofs
= byte_get (start
, 1); start
+= 1;
3370 if (do_debug_frames_interp
)
3371 frame_display_row (fc
, &need_col_headers
, &max_regs
);
3373 printf (" DW_CFA_advance_loc1: %ld to %08lx\n",
3374 ofs
* fc
->code_factor
,
3375 fc
->pc_begin
+ ofs
* fc
->code_factor
);
3376 fc
->pc_begin
+= ofs
* fc
->code_factor
;
3379 case DW_CFA_advance_loc2
:
3380 ofs
= byte_get (start
, 2); start
+= 2;
3381 if (do_debug_frames_interp
)
3382 frame_display_row (fc
, &need_col_headers
, &max_regs
);
3384 printf (" DW_CFA_advance_loc2: %ld to %08lx\n",
3385 ofs
* fc
->code_factor
,
3386 fc
->pc_begin
+ ofs
* fc
->code_factor
);
3387 fc
->pc_begin
+= ofs
* fc
->code_factor
;
3390 case DW_CFA_advance_loc4
:
3391 ofs
= byte_get (start
, 4); start
+= 4;
3392 if (do_debug_frames_interp
)
3393 frame_display_row (fc
, &need_col_headers
, &max_regs
);
3395 printf (" DW_CFA_advance_loc4: %ld to %08lx\n",
3396 ofs
* fc
->code_factor
,
3397 fc
->pc_begin
+ ofs
* fc
->code_factor
);
3398 fc
->pc_begin
+= ofs
* fc
->code_factor
;
3401 case DW_CFA_offset_extended
:
3404 if (! do_debug_frames_interp
)
3405 printf (" DW_CFA_offset_extended: r%ld at cfa%+ld\n",
3406 reg
, roffs
* fc
->data_factor
);
3407 fc
->col_type
[reg
] = DW_CFA_offset
;
3408 fc
->col_offset
[reg
] = roffs
* fc
->data_factor
;
3411 case DW_CFA_val_offset
:
3414 if (! do_debug_frames_interp
)
3415 printf (" DW_CFA_val_offset: r%ld at cfa%+ld\n",
3416 reg
, roffs
* fc
->data_factor
);
3417 fc
->col_type
[reg
] = DW_CFA_val_offset
;
3418 fc
->col_offset
[reg
] = roffs
* fc
->data_factor
;
3421 case DW_CFA_restore_extended
:
3423 if (! do_debug_frames_interp
)
3424 printf (" DW_CFA_restore_extended: r%ld\n", reg
);
3425 fc
->col_type
[reg
] = cie
->col_type
[reg
];
3426 fc
->col_offset
[reg
] = cie
->col_offset
[reg
];
3429 case DW_CFA_undefined
:
3431 if (! do_debug_frames_interp
)
3432 printf (" DW_CFA_undefined: r%ld\n", reg
);
3433 fc
->col_type
[reg
] = DW_CFA_undefined
;
3434 fc
->col_offset
[reg
] = 0;
3437 case DW_CFA_same_value
:
3439 if (! do_debug_frames_interp
)
3440 printf (" DW_CFA_same_value: r%ld\n", reg
);
3441 fc
->col_type
[reg
] = DW_CFA_same_value
;
3442 fc
->col_offset
[reg
] = 0;
3445 case DW_CFA_register
:
3448 if (! do_debug_frames_interp
)
3449 printf (" DW_CFA_register: r%ld in r%ld\n", reg
, roffs
);
3450 fc
->col_type
[reg
] = DW_CFA_register
;
3451 fc
->col_offset
[reg
] = roffs
;
3454 case DW_CFA_remember_state
:
3455 if (! do_debug_frames_interp
)
3456 printf (" DW_CFA_remember_state\n");
3457 rs
= xmalloc (sizeof (Frame_Chunk
));
3458 rs
->ncols
= fc
->ncols
;
3459 rs
->col_type
= xcmalloc (rs
->ncols
, sizeof (short int));
3460 rs
->col_offset
= xcmalloc (rs
->ncols
, sizeof (int));
3461 memcpy (rs
->col_type
, fc
->col_type
, rs
->ncols
);
3462 memcpy (rs
->col_offset
, fc
->col_offset
, rs
->ncols
* sizeof (int));
3463 rs
->next
= remembered_state
;
3464 remembered_state
= rs
;
3467 case DW_CFA_restore_state
:
3468 if (! do_debug_frames_interp
)
3469 printf (" DW_CFA_restore_state\n");
3470 rs
= remembered_state
;
3473 remembered_state
= rs
->next
;
3474 frame_need_space (fc
, rs
->ncols
-1);
3475 memcpy (fc
->col_type
, rs
->col_type
, rs
->ncols
);
3476 memcpy (fc
->col_offset
, rs
->col_offset
,
3477 rs
->ncols
* sizeof (int));
3478 free (rs
->col_type
);
3479 free (rs
->col_offset
);
3482 else if (do_debug_frames_interp
)
3483 printf ("Mismatched DW_CFA_restore_state\n");
3486 case DW_CFA_def_cfa
:
3487 fc
->cfa_reg
= LEB ();
3488 fc
->cfa_offset
= LEB ();
3490 if (! do_debug_frames_interp
)
3491 printf (" DW_CFA_def_cfa: r%d ofs %d\n",
3492 fc
->cfa_reg
, fc
->cfa_offset
);
3495 case DW_CFA_def_cfa_register
:
3496 fc
->cfa_reg
= LEB ();
3498 if (! do_debug_frames_interp
)
3499 printf (" DW_CFA_def_cfa_reg: r%d\n", fc
->cfa_reg
);
3502 case DW_CFA_def_cfa_offset
:
3503 fc
->cfa_offset
= LEB ();
3504 if (! do_debug_frames_interp
)
3505 printf (" DW_CFA_def_cfa_offset: %d\n", fc
->cfa_offset
);
3509 if (! do_debug_frames_interp
)
3510 printf (" DW_CFA_nop\n");
3513 case DW_CFA_def_cfa_expression
:
3515 if (! do_debug_frames_interp
)
3517 printf (" DW_CFA_def_cfa_expression (");
3518 decode_location_expression (start
, eh_addr_size
, ul
, 0);
3525 case DW_CFA_expression
:
3528 if (! do_debug_frames_interp
)
3530 printf (" DW_CFA_expression: r%ld (", reg
);
3531 decode_location_expression (start
, eh_addr_size
, ul
, 0);
3534 fc
->col_type
[reg
] = DW_CFA_expression
;
3538 case DW_CFA_val_expression
:
3541 if (! do_debug_frames_interp
)
3543 printf (" DW_CFA_val_expression: r%ld (", reg
);
3544 decode_location_expression (start
, eh_addr_size
, ul
, 0);
3547 fc
->col_type
[reg
] = DW_CFA_val_expression
;
3551 case DW_CFA_offset_extended_sf
:
3554 frame_need_space (fc
, reg
);
3555 if (! do_debug_frames_interp
)
3556 printf (" DW_CFA_offset_extended_sf: r%ld at cfa%+ld\n",
3557 reg
, l
* fc
->data_factor
);
3558 fc
->col_type
[reg
] = DW_CFA_offset
;
3559 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
3562 case DW_CFA_val_offset_sf
:
3565 frame_need_space (fc
, reg
);
3566 if (! do_debug_frames_interp
)
3567 printf (" DW_CFA_val_offset_sf: r%ld at cfa%+ld\n",
3568 reg
, l
* fc
->data_factor
);
3569 fc
->col_type
[reg
] = DW_CFA_val_offset
;
3570 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
3573 case DW_CFA_def_cfa_sf
:
3574 fc
->cfa_reg
= LEB ();
3575 fc
->cfa_offset
= SLEB ();
3576 fc
->cfa_offset
= fc
->cfa_offset
* fc
->data_factor
;
3578 if (! do_debug_frames_interp
)
3579 printf (" DW_CFA_def_cfa_sf: r%d ofs %d\n",
3580 fc
->cfa_reg
, fc
->cfa_offset
);
3583 case DW_CFA_def_cfa_offset_sf
:
3584 fc
->cfa_offset
= SLEB ();
3585 fc
->cfa_offset
= fc
->cfa_offset
* fc
->data_factor
;
3586 if (! do_debug_frames_interp
)
3587 printf (" DW_CFA_def_cfa_offset_sf: %d\n", fc
->cfa_offset
);
3590 case DW_CFA_MIPS_advance_loc8
:
3591 ofs
= byte_get (start
, 8); start
+= 8;
3592 if (do_debug_frames_interp
)
3593 frame_display_row (fc
, &need_col_headers
, &max_regs
);
3595 printf (" DW_CFA_MIPS_advance_loc8: %ld to %08lx\n",
3596 ofs
* fc
->code_factor
,
3597 fc
->pc_begin
+ ofs
* fc
->code_factor
);
3598 fc
->pc_begin
+= ofs
* fc
->code_factor
;
3601 case DW_CFA_GNU_window_save
:
3602 if (! do_debug_frames_interp
)
3603 printf (" DW_CFA_GNU_window_save\n");
3606 case DW_CFA_GNU_args_size
:
3608 if (! do_debug_frames_interp
)
3609 printf (" DW_CFA_GNU_args_size: %ld\n", ul
);
3612 case DW_CFA_GNU_negative_offset_extended
:
3615 frame_need_space (fc
, reg
);
3616 if (! do_debug_frames_interp
)
3617 printf (" DW_CFA_GNU_negative_offset_extended: r%ld at cfa%+ld\n",
3618 reg
, l
* fc
->data_factor
);
3619 fc
->col_type
[reg
] = DW_CFA_offset
;
3620 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
3624 if (op
>= DW_CFA_lo_user
&& op
<= DW_CFA_hi_user
)
3625 printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op
);
3627 warn (_("unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op
);
3632 if (do_debug_frames_interp
)
3633 frame_display_row (fc
, &need_col_headers
, &max_regs
);
3648 display_debug_not_supported (struct dwarf_section
*section
,
3649 void *file ATTRIBUTE_UNUSED
)
3651 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
3658 cmalloc (size_t nmemb
, size_t size
)
3660 /* Check for overflow. */
3661 if (nmemb
>= ~(size_t) 0 / size
)
3664 return malloc (nmemb
* size
);
3668 xcmalloc (size_t nmemb
, size_t size
)
3670 /* Check for overflow. */
3671 if (nmemb
>= ~(size_t) 0 / size
)
3674 return xmalloc (nmemb
* size
);
3678 xcrealloc (void *ptr
, size_t nmemb
, size_t size
)
3680 /* Check for overflow. */
3681 if (nmemb
>= ~(size_t) 0 / size
)
3684 return xrealloc (ptr
, nmemb
* size
);
3688 error (const char *message
, ...)
3692 va_start (args
, message
);
3693 fprintf (stderr
, _("%s: Error: "), program_name
);
3694 vfprintf (stderr
, message
, args
);
3699 warn (const char *message
, ...)
3703 va_start (args
, message
);
3704 fprintf (stderr
, _("%s: Warning: "), program_name
);
3705 vfprintf (stderr
, message
, args
);
3710 free_debug_memory (void)
3712 enum dwarf_section_display_enum i
;
3716 for (i
= 0; i
< max
; i
++)
3717 free_debug_section (i
);
3719 if (debug_information
)
3721 for (i
= 0; i
< num_debug_info_entries
; i
++)
3723 if (!debug_information
[i
].max_loc_offsets
)
3725 free (debug_information
[i
].loc_offsets
);
3726 free (debug_information
[i
].have_frame_base
);
3728 if (!debug_information
[i
].max_range_lists
)
3729 free (debug_information
[i
].range_lists
);
3731 free (debug_information
);
3732 debug_information
= NULL
;
3733 num_debug_info_entries
= 0;
3738 struct dwarf_section_display debug_displays
[] =
3740 { { ".debug_abbrev", NULL
, 0, 0 },
3741 display_debug_abbrev
, 0, 0 },
3742 { { ".debug_aranges", NULL
, 0, 0 },
3743 display_debug_aranges
, 0, 0 },
3744 { { ".debug_frame", NULL
, 0, 0 },
3745 display_debug_frames
, 1, 0 },
3746 { { ".debug_info", NULL
, 0, 0 },
3747 display_debug_info
, 1, 0 },
3748 { { ".debug_line", NULL
, 0, 0 },
3749 display_debug_lines
, 0, 0 },
3750 { { ".debug_pubnames", NULL
, 0, 0 },
3751 display_debug_pubnames
, 0, 0 },
3752 { { ".eh_frame", NULL
, 0, 0 },
3753 display_debug_frames
, 1, 1 },
3754 { { ".debug_macinfo", NULL
, 0, 0 },
3755 display_debug_macinfo
, 0, 0 },
3756 { { ".debug_str", NULL
, 0, 0 },
3757 display_debug_str
, 0, 0 },
3758 { { ".debug_loc", NULL
, 0, 0 },
3759 display_debug_loc
, 0, 0 },
3760 { { ".debug_pubtypes", NULL
, 0, 0 },
3761 display_debug_pubnames
, 0, 0 },
3762 { { ".debug_ranges", NULL
, 0, 0 },
3763 display_debug_ranges
, 0, 0 },
3764 { { ".debug_static_func", NULL
, 0, 0 },
3765 display_debug_not_supported
, 0, 0 },
3766 { { ".debug_static_vars", NULL
, 0, 0 },
3767 display_debug_not_supported
, 0, 0 },
3768 { { ".debug_types", NULL
, 0, 0 },
3769 display_debug_not_supported
, 0, 0 },
3770 { { ".debug_weaknames", NULL
, 0, 0 },
3771 display_debug_not_supported
, 0, 0 }