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"
30 static int have_frame_base
;
31 static int need_base_address
;
33 static unsigned int last_pointer_size
= 0;
34 static int warned_about_missing_comp_units
= FALSE
;
36 static unsigned int num_debug_info_entries
= 0;
37 static debug_info
*debug_information
= NULL
;
38 /* Special value for num_debug_info_entries to indicate
39 that the .debug_info section could not be loaded/parsed. */
40 #define DEBUG_INFO_UNAVAILABLE (unsigned int) -1
47 int do_debug_pubnames
;
51 int do_debug_frames_interp
;
57 /* Values for do_debug_lines. */
58 #define FLAG_DEBUG_LINES_RAW 1
59 #define FLAG_DEBUG_LINES_DECODED 2
61 dwarf_vma (*byte_get
) (unsigned char *, int);
64 byte_get_little_endian (unsigned char *field
, int size
)
72 return ((unsigned int) (field
[0]))
73 | (((unsigned int) (field
[1])) << 8);
76 return ((unsigned long) (field
[0]))
77 | (((unsigned long) (field
[1])) << 8)
78 | (((unsigned long) (field
[2])) << 16)
79 | (((unsigned long) (field
[3])) << 24);
82 if (sizeof (dwarf_vma
) == 8)
83 return ((dwarf_vma
) (field
[0]))
84 | (((dwarf_vma
) (field
[1])) << 8)
85 | (((dwarf_vma
) (field
[2])) << 16)
86 | (((dwarf_vma
) (field
[3])) << 24)
87 | (((dwarf_vma
) (field
[4])) << 32)
88 | (((dwarf_vma
) (field
[5])) << 40)
89 | (((dwarf_vma
) (field
[6])) << 48)
90 | (((dwarf_vma
) (field
[7])) << 56);
91 else if (sizeof (dwarf_vma
) == 4)
92 /* We want to extract data from an 8 byte wide field and
93 place it into a 4 byte wide field. Since this is a little
94 endian source we can just use the 4 byte extraction code. */
95 return ((unsigned long) (field
[0]))
96 | (((unsigned long) (field
[1])) << 8)
97 | (((unsigned long) (field
[2])) << 16)
98 | (((unsigned long) (field
[3])) << 24);
101 error (_("Unhandled data length: %d\n"), size
);
107 byte_get_big_endian (unsigned char *field
, int size
)
115 return ((unsigned int) (field
[1])) | (((int) (field
[0])) << 8);
118 return ((unsigned long) (field
[3]))
119 | (((unsigned long) (field
[2])) << 8)
120 | (((unsigned long) (field
[1])) << 16)
121 | (((unsigned long) (field
[0])) << 24);
124 if (sizeof (dwarf_vma
) == 8)
125 return ((dwarf_vma
) (field
[7]))
126 | (((dwarf_vma
) (field
[6])) << 8)
127 | (((dwarf_vma
) (field
[5])) << 16)
128 | (((dwarf_vma
) (field
[4])) << 24)
129 | (((dwarf_vma
) (field
[3])) << 32)
130 | (((dwarf_vma
) (field
[2])) << 40)
131 | (((dwarf_vma
) (field
[1])) << 48)
132 | (((dwarf_vma
) (field
[0])) << 56);
133 else if (sizeof (dwarf_vma
) == 4)
135 /* Although we are extracing data from an 8 byte wide field,
136 we are returning only 4 bytes of data. */
138 return ((unsigned long) (field
[3]))
139 | (((unsigned long) (field
[2])) << 8)
140 | (((unsigned long) (field
[1])) << 16)
141 | (((unsigned long) (field
[0])) << 24);
145 error (_("Unhandled data length: %d\n"), size
);
151 byte_get_signed (unsigned char *field
, int size
)
153 dwarf_vma x
= byte_get (field
, size
);
158 return (x
^ 0x80) - 0x80;
160 return (x
^ 0x8000) - 0x8000;
162 return (x
^ 0x80000000) - 0x80000000;
171 size_of_encoded_value (int encoding
)
173 switch (encoding
& 0x7)
176 case 0: return eh_addr_size
;
184 get_encoded_value (unsigned char *data
, int encoding
)
186 int size
= size_of_encoded_value (encoding
);
188 if (encoding
& DW_EH_PE_signed
)
189 return byte_get_signed (data
, size
);
191 return byte_get (data
, size
);
194 /* Print a dwarf_vma value (typically an address, offset or length) in
195 hexadecimal format, followed by a space. The length of the value (and
196 hence the precision displayed) is determined by the byte_size parameter. */
199 print_dwarf_vma (dwarf_vma val
, unsigned byte_size
)
201 static char buff
[18];
203 /* Printf does not have a way of specifiying a maximum field width for an
204 integer value, so we print the full value into a buffer and then select
205 the precision we need. */
206 #if __STDC_VERSION__ >= 199901L || (defined(__GNUC__) && __GNUC__ >= 2)
208 snprintf (buff
, sizeof (buff
), "%16.16llx ", val
);
210 snprintf (buff
, sizeof (buff
), "%016I64x ", val
);
213 snprintf (buff
, sizeof (buff
), "%16.16lx ", val
);
216 fputs (buff
+ (byte_size
== 4 ? 8 : 0), stdout
);
219 static unsigned long int
220 read_leb128 (unsigned char *data
, unsigned int *length_return
, int sign
)
222 unsigned long int result
= 0;
223 unsigned int num_read
= 0;
224 unsigned int shift
= 0;
232 result
|= ((unsigned long int) (byte
& 0x7f)) << shift
;
239 if (length_return
!= NULL
)
240 *length_return
= num_read
;
242 if (sign
&& (shift
< 8 * sizeof (result
)) && (byte
& 0x40))
243 result
|= -1L << shift
;
248 typedef struct State_Machine_Registers
250 unsigned long address
;
257 /* This variable hold the number of the last entry seen
258 in the File Table. */
259 unsigned int last_file_entry
;
262 static SMR state_machine_regs
;
265 reset_state_machine (int is_stmt
)
267 state_machine_regs
.address
= 0;
268 state_machine_regs
.file
= 1;
269 state_machine_regs
.line
= 1;
270 state_machine_regs
.column
= 0;
271 state_machine_regs
.is_stmt
= is_stmt
;
272 state_machine_regs
.basic_block
= 0;
273 state_machine_regs
.end_sequence
= 0;
274 state_machine_regs
.last_file_entry
= 0;
277 /* Handled an extend line op.
278 Returns the number of bytes read. */
281 process_extended_line_op (unsigned char *data
, int is_stmt
)
283 unsigned char op_code
;
284 unsigned int bytes_read
;
289 len
= read_leb128 (data
, & bytes_read
, 0);
294 warn (_("badly formed extended line op encountered!\n"));
301 printf (_(" Extended opcode %d: "), op_code
);
305 case DW_LNE_end_sequence
:
306 printf (_("End of Sequence\n\n"));
307 reset_state_machine (is_stmt
);
310 case DW_LNE_set_address
:
311 adr
= byte_get (data
, len
- bytes_read
- 1);
312 printf (_("set Address to 0x%lx\n"), adr
);
313 state_machine_regs
.address
= adr
;
316 case DW_LNE_define_file
:
317 printf (_(" define new File Table entry\n"));
318 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
320 printf (_(" %d\t"), ++state_machine_regs
.last_file_entry
);
322 data
+= strlen ((char *) data
) + 1;
323 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
325 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
327 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
328 printf (_("%s\n\n"), name
);
331 case DW_LNE_set_discriminator
:
332 printf (_("set Discriminator to %lu\n"),
333 read_leb128 (data
, & bytes_read
, 0));
337 case DW_LNE_HP_negate_is_UV_update
:
338 printf ("DW_LNE_HP_negate_is_UV_update\n");
340 case DW_LNE_HP_push_context
:
341 printf ("DW_LNE_HP_push_context\n");
343 case DW_LNE_HP_pop_context
:
344 printf ("DW_LNE_HP_pop_context\n");
346 case DW_LNE_HP_set_file_line_column
:
347 printf ("DW_LNE_HP_set_file_line_column\n");
349 case DW_LNE_HP_set_routine_name
:
350 printf ("DW_LNE_HP_set_routine_name\n");
352 case DW_LNE_HP_set_sequence
:
353 printf ("DW_LNE_HP_set_sequence\n");
355 case DW_LNE_HP_negate_post_semantics
:
356 printf ("DW_LNE_HP_negate_post_semantics\n");
358 case DW_LNE_HP_negate_function_exit
:
359 printf ("DW_LNE_HP_negate_function_exit\n");
361 case DW_LNE_HP_negate_front_end_logical
:
362 printf ("DW_LNE_HP_negate_front_end_logical\n");
364 case DW_LNE_HP_define_proc
:
365 printf ("DW_LNE_HP_define_proc\n");
369 if (op_code
>= DW_LNE_lo_user
370 /* The test against DW_LNW_hi_user is redundant due to
371 the limited range of the unsigned char data type used
373 /*&& op_code <= DW_LNE_hi_user*/)
374 printf (_("user defined: length %d\n"), len
- bytes_read
);
376 printf (_("UNKNOWN: length %d\n"), len
- bytes_read
);
384 fetch_indirect_string (unsigned long offset
)
386 struct dwarf_section
*section
= &debug_displays
[str
].section
;
388 if (section
->start
== NULL
)
389 return _("<no .debug_str section>");
391 /* DWARF sections under Mach-O have non-zero addresses. */
392 offset
-= section
->address
;
393 if (offset
> section
->size
)
395 warn (_("DW_FORM_strp offset too big: %lx\n"), offset
);
396 return _("<offset is too big>");
399 return (const char *) section
->start
+ offset
;
402 /* FIXME: There are better and more efficient ways to handle
403 these structures. For now though, I just want something that
404 is simple to implement. */
405 typedef struct abbrev_attr
407 unsigned long attribute
;
409 struct abbrev_attr
*next
;
413 typedef struct abbrev_entry
418 struct abbrev_attr
*first_attr
;
419 struct abbrev_attr
*last_attr
;
420 struct abbrev_entry
*next
;
424 static abbrev_entry
*first_abbrev
= NULL
;
425 static abbrev_entry
*last_abbrev
= NULL
;
430 abbrev_entry
*abbrev
;
432 for (abbrev
= first_abbrev
; abbrev
;)
434 abbrev_entry
*next
= abbrev
->next
;
437 for (attr
= abbrev
->first_attr
; attr
;)
439 abbrev_attr
*next
= attr
->next
;
449 last_abbrev
= first_abbrev
= NULL
;
453 add_abbrev (unsigned long number
, unsigned long tag
, int children
)
457 entry
= malloc (sizeof (*entry
));
463 entry
->entry
= number
;
465 entry
->children
= children
;
466 entry
->first_attr
= NULL
;
467 entry
->last_attr
= NULL
;
470 if (first_abbrev
== NULL
)
471 first_abbrev
= entry
;
473 last_abbrev
->next
= entry
;
479 add_abbrev_attr (unsigned long attribute
, unsigned long form
)
483 attr
= malloc (sizeof (*attr
));
489 attr
->attribute
= attribute
;
493 if (last_abbrev
->first_attr
== NULL
)
494 last_abbrev
->first_attr
= attr
;
496 last_abbrev
->last_attr
->next
= attr
;
498 last_abbrev
->last_attr
= attr
;
501 /* Processes the (partial) contents of a .debug_abbrev section.
502 Returns NULL if the end of the section was encountered.
503 Returns the address after the last byte read if the end of
504 an abbreviation set was found. */
506 static unsigned char *
507 process_abbrev_section (unsigned char *start
, unsigned char *end
)
509 if (first_abbrev
!= NULL
)
514 unsigned int bytes_read
;
517 unsigned long attribute
;
520 entry
= read_leb128 (start
, & bytes_read
, 0);
523 /* A single zero is supposed to end the section according
524 to the standard. If there's more, then signal that to
527 return start
== end
? NULL
: start
;
529 tag
= read_leb128 (start
, & bytes_read
, 0);
534 add_abbrev (entry
, tag
, children
);
540 attribute
= read_leb128 (start
, & bytes_read
, 0);
543 form
= read_leb128 (start
, & bytes_read
, 0);
547 add_abbrev_attr (attribute
, form
);
549 while (attribute
!= 0);
556 get_TAG_name (unsigned long tag
)
560 case DW_TAG_padding
: return "DW_TAG_padding";
561 case DW_TAG_array_type
: return "DW_TAG_array_type";
562 case DW_TAG_class_type
: return "DW_TAG_class_type";
563 case DW_TAG_entry_point
: return "DW_TAG_entry_point";
564 case DW_TAG_enumeration_type
: return "DW_TAG_enumeration_type";
565 case DW_TAG_formal_parameter
: return "DW_TAG_formal_parameter";
566 case DW_TAG_imported_declaration
: return "DW_TAG_imported_declaration";
567 case DW_TAG_label
: return "DW_TAG_label";
568 case DW_TAG_lexical_block
: return "DW_TAG_lexical_block";
569 case DW_TAG_member
: return "DW_TAG_member";
570 case DW_TAG_pointer_type
: return "DW_TAG_pointer_type";
571 case DW_TAG_reference_type
: return "DW_TAG_reference_type";
572 case DW_TAG_compile_unit
: return "DW_TAG_compile_unit";
573 case DW_TAG_string_type
: return "DW_TAG_string_type";
574 case DW_TAG_structure_type
: return "DW_TAG_structure_type";
575 case DW_TAG_subroutine_type
: return "DW_TAG_subroutine_type";
576 case DW_TAG_typedef
: return "DW_TAG_typedef";
577 case DW_TAG_union_type
: return "DW_TAG_union_type";
578 case DW_TAG_unspecified_parameters
: return "DW_TAG_unspecified_parameters";
579 case DW_TAG_variant
: return "DW_TAG_variant";
580 case DW_TAG_common_block
: return "DW_TAG_common_block";
581 case DW_TAG_common_inclusion
: return "DW_TAG_common_inclusion";
582 case DW_TAG_inheritance
: return "DW_TAG_inheritance";
583 case DW_TAG_inlined_subroutine
: return "DW_TAG_inlined_subroutine";
584 case DW_TAG_module
: return "DW_TAG_module";
585 case DW_TAG_ptr_to_member_type
: return "DW_TAG_ptr_to_member_type";
586 case DW_TAG_set_type
: return "DW_TAG_set_type";
587 case DW_TAG_subrange_type
: return "DW_TAG_subrange_type";
588 case DW_TAG_with_stmt
: return "DW_TAG_with_stmt";
589 case DW_TAG_access_declaration
: return "DW_TAG_access_declaration";
590 case DW_TAG_base_type
: return "DW_TAG_base_type";
591 case DW_TAG_catch_block
: return "DW_TAG_catch_block";
592 case DW_TAG_const_type
: return "DW_TAG_const_type";
593 case DW_TAG_constant
: return "DW_TAG_constant";
594 case DW_TAG_enumerator
: return "DW_TAG_enumerator";
595 case DW_TAG_file_type
: return "DW_TAG_file_type";
596 case DW_TAG_friend
: return "DW_TAG_friend";
597 case DW_TAG_namelist
: return "DW_TAG_namelist";
598 case DW_TAG_namelist_item
: return "DW_TAG_namelist_item";
599 case DW_TAG_packed_type
: return "DW_TAG_packed_type";
600 case DW_TAG_subprogram
: return "DW_TAG_subprogram";
601 case DW_TAG_template_type_param
: return "DW_TAG_template_type_param";
602 case DW_TAG_template_value_param
: return "DW_TAG_template_value_param";
603 case DW_TAG_thrown_type
: return "DW_TAG_thrown_type";
604 case DW_TAG_try_block
: return "DW_TAG_try_block";
605 case DW_TAG_variant_part
: return "DW_TAG_variant_part";
606 case DW_TAG_variable
: return "DW_TAG_variable";
607 case DW_TAG_volatile_type
: return "DW_TAG_volatile_type";
608 case DW_TAG_MIPS_loop
: return "DW_TAG_MIPS_loop";
609 case DW_TAG_format_label
: return "DW_TAG_format_label";
610 case DW_TAG_function_template
: return "DW_TAG_function_template";
611 case DW_TAG_class_template
: return "DW_TAG_class_template";
612 /* DWARF 2.1 values. */
613 case DW_TAG_dwarf_procedure
: return "DW_TAG_dwarf_procedure";
614 case DW_TAG_restrict_type
: return "DW_TAG_restrict_type";
615 case DW_TAG_interface_type
: return "DW_TAG_interface_type";
616 case DW_TAG_namespace
: return "DW_TAG_namespace";
617 case DW_TAG_imported_module
: return "DW_TAG_imported_module";
618 case DW_TAG_unspecified_type
: return "DW_TAG_unspecified_type";
619 case DW_TAG_partial_unit
: return "DW_TAG_partial_unit";
620 case DW_TAG_imported_unit
: return "DW_TAG_imported_unit";
622 case DW_TAG_upc_shared_type
: return "DW_TAG_upc_shared_type";
623 case DW_TAG_upc_strict_type
: return "DW_TAG_upc_strict_type";
624 case DW_TAG_upc_relaxed_type
: return "DW_TAG_upc_relaxed_type";
627 static char buffer
[100];
629 snprintf (buffer
, sizeof (buffer
), _("Unknown TAG value: %lx"), tag
);
636 get_FORM_name (unsigned long form
)
640 case DW_FORM_addr
: return "DW_FORM_addr";
641 case DW_FORM_block2
: return "DW_FORM_block2";
642 case DW_FORM_block4
: return "DW_FORM_block4";
643 case DW_FORM_data2
: return "DW_FORM_data2";
644 case DW_FORM_data4
: return "DW_FORM_data4";
645 case DW_FORM_data8
: return "DW_FORM_data8";
646 case DW_FORM_string
: return "DW_FORM_string";
647 case DW_FORM_block
: return "DW_FORM_block";
648 case DW_FORM_block1
: return "DW_FORM_block1";
649 case DW_FORM_data1
: return "DW_FORM_data1";
650 case DW_FORM_flag
: return "DW_FORM_flag";
651 case DW_FORM_sdata
: return "DW_FORM_sdata";
652 case DW_FORM_strp
: return "DW_FORM_strp";
653 case DW_FORM_udata
: return "DW_FORM_udata";
654 case DW_FORM_ref_addr
: return "DW_FORM_ref_addr";
655 case DW_FORM_ref1
: return "DW_FORM_ref1";
656 case DW_FORM_ref2
: return "DW_FORM_ref2";
657 case DW_FORM_ref4
: return "DW_FORM_ref4";
658 case DW_FORM_ref8
: return "DW_FORM_ref8";
659 case DW_FORM_ref_udata
: return "DW_FORM_ref_udata";
660 case DW_FORM_indirect
: return "DW_FORM_indirect";
663 static char buffer
[100];
665 snprintf (buffer
, sizeof (buffer
), _("Unknown FORM value: %lx"), form
);
671 static unsigned char *
672 display_block (unsigned char *data
, unsigned long length
)
674 printf (_(" %lu byte block: "), length
);
677 printf ("%lx ", (unsigned long) byte_get (data
++, 1));
683 decode_location_expression (unsigned char * data
,
684 unsigned int pointer_size
,
685 unsigned long length
,
686 unsigned long cu_offset
,
687 struct dwarf_section
* section
)
690 unsigned int bytes_read
;
691 unsigned long uvalue
;
692 unsigned char *end
= data
+ length
;
693 int need_frame_base
= 0;
702 printf ("DW_OP_addr: %lx",
703 (unsigned long) byte_get (data
, pointer_size
));
704 data
+= pointer_size
;
707 printf ("DW_OP_deref");
710 printf ("DW_OP_const1u: %lu", (unsigned long) byte_get (data
++, 1));
713 printf ("DW_OP_const1s: %ld", (long) byte_get_signed (data
++, 1));
716 printf ("DW_OP_const2u: %lu", (unsigned long) byte_get (data
, 2));
720 printf ("DW_OP_const2s: %ld", (long) byte_get_signed (data
, 2));
724 printf ("DW_OP_const4u: %lu", (unsigned long) byte_get (data
, 4));
728 printf ("DW_OP_const4s: %ld", (long) byte_get_signed (data
, 4));
732 printf ("DW_OP_const8u: %lu %lu", (unsigned long) byte_get (data
, 4),
733 (unsigned long) byte_get (data
+ 4, 4));
737 printf ("DW_OP_const8s: %ld %ld", (long) byte_get (data
, 4),
738 (long) byte_get (data
+ 4, 4));
742 printf ("DW_OP_constu: %lu", read_leb128 (data
, &bytes_read
, 0));
746 printf ("DW_OP_consts: %ld", read_leb128 (data
, &bytes_read
, 1));
750 printf ("DW_OP_dup");
753 printf ("DW_OP_drop");
756 printf ("DW_OP_over");
759 printf ("DW_OP_pick: %ld", (unsigned long) byte_get (data
++, 1));
762 printf ("DW_OP_swap");
765 printf ("DW_OP_rot");
768 printf ("DW_OP_xderef");
771 printf ("DW_OP_abs");
774 printf ("DW_OP_and");
777 printf ("DW_OP_div");
780 printf ("DW_OP_minus");
783 printf ("DW_OP_mod");
786 printf ("DW_OP_mul");
789 printf ("DW_OP_neg");
792 printf ("DW_OP_not");
798 printf ("DW_OP_plus");
800 case DW_OP_plus_uconst
:
801 printf ("DW_OP_plus_uconst: %lu",
802 read_leb128 (data
, &bytes_read
, 0));
806 printf ("DW_OP_shl");
809 printf ("DW_OP_shr");
812 printf ("DW_OP_shra");
815 printf ("DW_OP_xor");
818 printf ("DW_OP_bra: %ld", (long) byte_get_signed (data
, 2));
840 printf ("DW_OP_skip: %ld", (long) byte_get_signed (data
, 2));
876 printf ("DW_OP_lit%d", op
- DW_OP_lit0
);
911 printf ("DW_OP_reg%d", op
- DW_OP_reg0
);
946 printf ("DW_OP_breg%d: %ld", op
- DW_OP_breg0
,
947 read_leb128 (data
, &bytes_read
, 1));
952 printf ("DW_OP_regx: %lu", read_leb128 (data
, &bytes_read
, 0));
957 printf ("DW_OP_fbreg: %ld", read_leb128 (data
, &bytes_read
, 1));
961 uvalue
= read_leb128 (data
, &bytes_read
, 0);
963 printf ("DW_OP_bregx: %lu %ld", uvalue
,
964 read_leb128 (data
, &bytes_read
, 1));
968 printf ("DW_OP_piece: %lu", read_leb128 (data
, &bytes_read
, 0));
971 case DW_OP_deref_size
:
972 printf ("DW_OP_deref_size: %ld", (long) byte_get (data
++, 1));
974 case DW_OP_xderef_size
:
975 printf ("DW_OP_xderef_size: %ld", (long) byte_get (data
++, 1));
978 printf ("DW_OP_nop");
981 /* DWARF 3 extensions. */
982 case DW_OP_push_object_address
:
983 printf ("DW_OP_push_object_address");
986 /* XXX: Strictly speaking for 64-bit DWARF3 files
987 this ought to be an 8-byte wide computation. */
988 printf ("DW_OP_call2: <%lx>", (long) byte_get (data
, 2) + cu_offset
);
992 /* XXX: Strictly speaking for 64-bit DWARF3 files
993 this ought to be an 8-byte wide computation. */
994 printf ("DW_OP_call4: <%lx>", (long) byte_get (data
, 4) + cu_offset
);
998 /* XXX: Strictly speaking for 64-bit DWARF3 files
999 this ought to be an 8-byte wide computation. */
1000 printf ("DW_OP_call_ref: <%lx>", (long) byte_get (data
, 4) + cu_offset
);
1003 case DW_OP_form_tls_address
:
1004 printf ("DW_OP_form_tls_address");
1006 case DW_OP_call_frame_cfa
:
1007 printf ("DW_OP_call_frame_cfa");
1009 case DW_OP_bit_piece
:
1010 printf ("DW_OP_bit_piece: ");
1011 printf ("size: %lu ", read_leb128 (data
, &bytes_read
, 0));
1013 printf ("offset: %lu ", read_leb128 (data
, &bytes_read
, 0));
1017 /* DWARF 4 extensions. */
1018 case DW_OP_stack_value
:
1019 printf ("DW_OP_stack_value");
1022 case DW_OP_implicit_value
:
1023 printf ("DW_OP_implicit_value");
1024 uvalue
= read_leb128 (data
, &bytes_read
, 0);
1026 display_block (data
, uvalue
);
1030 /* GNU extensions. */
1031 case DW_OP_GNU_push_tls_address
:
1032 printf ("DW_OP_GNU_push_tls_address or DW_OP_HP_unknown");
1034 case DW_OP_GNU_uninit
:
1035 printf ("DW_OP_GNU_uninit");
1036 /* FIXME: Is there data associated with this OP ? */
1038 case DW_OP_GNU_encoded_addr
:
1044 addr
= get_encoded_value (data
, encoding
);
1045 if ((encoding
& 0x70) == DW_EH_PE_pcrel
)
1046 addr
+= section
->address
+ (data
- section
->start
);
1047 data
+= size_of_encoded_value (encoding
);
1049 printf ("DW_OP_GNU_encoded_addr: fmt:%02x addr:", encoding
);
1050 print_dwarf_vma (addr
, pointer_size
);
1054 /* HP extensions. */
1055 case DW_OP_HP_is_value
:
1056 printf ("DW_OP_HP_is_value");
1057 /* FIXME: Is there data associated with this OP ? */
1059 case DW_OP_HP_fltconst4
:
1060 printf ("DW_OP_HP_fltconst4");
1061 /* FIXME: Is there data associated with this OP ? */
1063 case DW_OP_HP_fltconst8
:
1064 printf ("DW_OP_HP_fltconst8");
1065 /* FIXME: Is there data associated with this OP ? */
1067 case DW_OP_HP_mod_range
:
1068 printf ("DW_OP_HP_mod_range");
1069 /* FIXME: Is there data associated with this OP ? */
1071 case DW_OP_HP_unmod_range
:
1072 printf ("DW_OP_HP_unmod_range");
1073 /* FIXME: Is there data associated with this OP ? */
1076 printf ("DW_OP_HP_tls");
1077 /* FIXME: Is there data associated with this OP ? */
1080 /* PGI (STMicroelectronics) extensions. */
1081 case DW_OP_PGI_omp_thread_num
:
1082 /* Pushes the thread number for the current thread as it would be
1083 returned by the standard OpenMP library function:
1084 omp_get_thread_num(). The "current thread" is the thread for
1085 which the expression is being evaluated. */
1086 printf ("DW_OP_PGI_omp_thread_num");
1090 if (op
>= DW_OP_lo_user
1091 && op
<= DW_OP_hi_user
)
1092 printf (_("(User defined location op)"));
1094 printf (_("(Unknown location op)"));
1095 /* No way to tell where the next op is, so just bail. */
1096 return need_frame_base
;
1099 /* Separate the ops. */
1104 return need_frame_base
;
1107 static unsigned char *
1108 read_and_display_attr_value (unsigned long attribute
,
1110 unsigned char * data
,
1111 unsigned long cu_offset
,
1112 unsigned long pointer_size
,
1113 unsigned long offset_size
,
1115 debug_info
* debug_info_p
,
1117 struct dwarf_section
* section
)
1119 unsigned long uvalue
= 0;
1120 unsigned char *block_start
= NULL
;
1121 unsigned char * orig_data
= data
;
1122 unsigned int bytes_read
;
1129 case DW_FORM_ref_addr
:
1130 if (dwarf_version
== 2)
1132 uvalue
= byte_get (data
, pointer_size
);
1133 data
+= pointer_size
;
1135 else if (dwarf_version
== 3)
1137 uvalue
= byte_get (data
, offset_size
);
1138 data
+= offset_size
;
1142 error (_("Internal error: DWARF version is not 2 or 3.\n"));
1147 uvalue
= byte_get (data
, pointer_size
);
1148 data
+= pointer_size
;
1152 uvalue
= byte_get (data
, offset_size
);
1153 data
+= offset_size
;
1159 uvalue
= byte_get (data
++, 1);
1164 uvalue
= byte_get (data
, 2);
1170 uvalue
= byte_get (data
, 4);
1175 uvalue
= read_leb128 (data
, & bytes_read
, 1);
1179 case DW_FORM_ref_udata
:
1181 uvalue
= read_leb128 (data
, & bytes_read
, 0);
1185 case DW_FORM_indirect
:
1186 form
= read_leb128 (data
, & bytes_read
, 0);
1189 printf (" %s", get_FORM_name (form
));
1190 return read_and_display_attr_value (attribute
, form
, data
,
1191 cu_offset
, pointer_size
,
1192 offset_size
, dwarf_version
,
1193 debug_info_p
, do_loc
,
1199 case DW_FORM_ref_addr
:
1201 printf (" <0x%lx>", uvalue
);
1207 case DW_FORM_ref_udata
:
1209 printf (" <0x%lx>", uvalue
+ cu_offset
);
1215 printf (" 0x%lx", uvalue
);
1224 printf (" %ld", uvalue
);
1231 uvalue
= byte_get (data
, 4);
1232 printf (" 0x%lx", uvalue
);
1233 printf (" 0x%lx", (unsigned long) byte_get (data
+ 4, 4));
1235 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
1236 && num_debug_info_entries
== 0)
1238 if (sizeof (uvalue
) == 8)
1239 uvalue
= byte_get (data
, 8);
1241 error (_("DW_FORM_data8 is unsupported when sizeof (unsigned long) != 8\n"));
1246 case DW_FORM_string
:
1248 printf (" %s", data
);
1249 data
+= strlen ((char *) data
) + 1;
1253 uvalue
= read_leb128 (data
, & bytes_read
, 0);
1254 block_start
= data
+ bytes_read
;
1256 data
= block_start
+ uvalue
;
1258 data
= display_block (block_start
, uvalue
);
1261 case DW_FORM_block1
:
1262 uvalue
= byte_get (data
, 1);
1263 block_start
= data
+ 1;
1265 data
= block_start
+ uvalue
;
1267 data
= display_block (block_start
, uvalue
);
1270 case DW_FORM_block2
:
1271 uvalue
= byte_get (data
, 2);
1272 block_start
= data
+ 2;
1274 data
= block_start
+ uvalue
;
1276 data
= display_block (block_start
, uvalue
);
1279 case DW_FORM_block4
:
1280 uvalue
= byte_get (data
, 4);
1281 block_start
= data
+ 4;
1283 data
= block_start
+ uvalue
;
1285 data
= display_block (block_start
, uvalue
);
1290 printf (_(" (indirect string, offset: 0x%lx): %s"),
1291 uvalue
, fetch_indirect_string (uvalue
));
1294 case DW_FORM_indirect
:
1295 /* Handled above. */
1299 warn (_("Unrecognized form: %lu\n"), form
);
1303 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
1304 && num_debug_info_entries
== 0)
1308 case DW_AT_frame_base
:
1309 have_frame_base
= 1;
1310 case DW_AT_location
:
1311 case DW_AT_string_length
:
1312 case DW_AT_return_addr
:
1313 case DW_AT_data_member_location
:
1314 case DW_AT_vtable_elem_location
:
1316 case DW_AT_static_link
:
1317 case DW_AT_use_location
:
1318 if (form
== DW_FORM_data4
|| form
== DW_FORM_data8
)
1320 /* Process location list. */
1321 unsigned int max
= debug_info_p
->max_loc_offsets
;
1322 unsigned int num
= debug_info_p
->num_loc_offsets
;
1324 if (max
== 0 || num
>= max
)
1327 debug_info_p
->loc_offsets
1328 = xcrealloc (debug_info_p
->loc_offsets
,
1329 max
, sizeof (*debug_info_p
->loc_offsets
));
1330 debug_info_p
->have_frame_base
1331 = xcrealloc (debug_info_p
->have_frame_base
,
1332 max
, sizeof (*debug_info_p
->have_frame_base
));
1333 debug_info_p
->max_loc_offsets
= max
;
1335 debug_info_p
->loc_offsets
[num
] = uvalue
;
1336 debug_info_p
->have_frame_base
[num
] = have_frame_base
;
1337 debug_info_p
->num_loc_offsets
++;
1342 if (need_base_address
)
1343 debug_info_p
->base_address
= uvalue
;
1347 if (form
== DW_FORM_data4
|| form
== DW_FORM_data8
)
1349 /* Process range list. */
1350 unsigned int max
= debug_info_p
->max_range_lists
;
1351 unsigned int num
= debug_info_p
->num_range_lists
;
1353 if (max
== 0 || num
>= max
)
1356 debug_info_p
->range_lists
1357 = xcrealloc (debug_info_p
->range_lists
,
1358 max
, sizeof (*debug_info_p
->range_lists
));
1359 debug_info_p
->max_range_lists
= max
;
1361 debug_info_p
->range_lists
[num
] = uvalue
;
1362 debug_info_p
->num_range_lists
++;
1374 /* For some attributes we can display further information. */
1382 case DW_INL_not_inlined
:
1383 printf (_("(not inlined)"));
1385 case DW_INL_inlined
:
1386 printf (_("(inlined)"));
1388 case DW_INL_declared_not_inlined
:
1389 printf (_("(declared as inline but ignored)"));
1391 case DW_INL_declared_inlined
:
1392 printf (_("(declared as inline and inlined)"));
1395 printf (_(" (Unknown inline attribute value: %lx)"), uvalue
);
1400 case DW_AT_language
:
1403 /* Ordered by the numeric value of these constants. */
1404 case DW_LANG_C89
: printf ("(ANSI C)"); break;
1405 case DW_LANG_C
: printf ("(non-ANSI C)"); break;
1406 case DW_LANG_Ada83
: printf ("(Ada)"); break;
1407 case DW_LANG_C_plus_plus
: printf ("(C++)"); break;
1408 case DW_LANG_Cobol74
: printf ("(Cobol 74)"); break;
1409 case DW_LANG_Cobol85
: printf ("(Cobol 85)"); break;
1410 case DW_LANG_Fortran77
: printf ("(FORTRAN 77)"); break;
1411 case DW_LANG_Fortran90
: printf ("(Fortran 90)"); break;
1412 case DW_LANG_Pascal83
: printf ("(ANSI Pascal)"); break;
1413 case DW_LANG_Modula2
: printf ("(Modula 2)"); break;
1414 /* DWARF 2.1 values. */
1415 case DW_LANG_Java
: printf ("(Java)"); break;
1416 case DW_LANG_C99
: printf ("(ANSI C99)"); break;
1417 case DW_LANG_Ada95
: printf ("(ADA 95)"); break;
1418 case DW_LANG_Fortran95
: printf ("(Fortran 95)"); break;
1419 /* DWARF 3 values. */
1420 case DW_LANG_PLI
: printf ("(PLI)"); break;
1421 case DW_LANG_ObjC
: printf ("(Objective C)"); break;
1422 case DW_LANG_ObjC_plus_plus
: printf ("(Objective C++)"); break;
1423 case DW_LANG_UPC
: printf ("(Unified Parallel C)"); break;
1424 case DW_LANG_D
: printf ("(D)"); break;
1425 /* MIPS extension. */
1426 case DW_LANG_Mips_Assembler
: printf ("(MIPS assembler)"); break;
1427 /* UPC extension. */
1428 case DW_LANG_Upc
: printf ("(Unified Parallel C)"); break;
1430 if (uvalue
>= DW_LANG_lo_user
&& uvalue
<= DW_LANG_hi_user
)
1431 printf ("(implementation defined: %lx)", uvalue
);
1433 printf ("(Unknown: %lx)", uvalue
);
1438 case DW_AT_encoding
:
1441 case DW_ATE_void
: printf ("(void)"); break;
1442 case DW_ATE_address
: printf ("(machine address)"); break;
1443 case DW_ATE_boolean
: printf ("(boolean)"); break;
1444 case DW_ATE_complex_float
: printf ("(complex float)"); break;
1445 case DW_ATE_float
: printf ("(float)"); break;
1446 case DW_ATE_signed
: printf ("(signed)"); break;
1447 case DW_ATE_signed_char
: printf ("(signed char)"); break;
1448 case DW_ATE_unsigned
: printf ("(unsigned)"); break;
1449 case DW_ATE_unsigned_char
: printf ("(unsigned char)"); break;
1450 /* DWARF 2.1 values: */
1451 case DW_ATE_imaginary_float
: printf ("(imaginary float)"); break;
1452 case DW_ATE_decimal_float
: printf ("(decimal float)"); break;
1453 /* DWARF 3 values: */
1454 case DW_ATE_packed_decimal
: printf ("(packed_decimal)"); break;
1455 case DW_ATE_numeric_string
: printf ("(numeric_string)"); break;
1456 case DW_ATE_edited
: printf ("(edited)"); break;
1457 case DW_ATE_signed_fixed
: printf ("(signed_fixed)"); break;
1458 case DW_ATE_unsigned_fixed
: printf ("(unsigned_fixed)"); break;
1459 /* HP extensions: */
1460 case DW_ATE_HP_float80
: printf ("(HP_float80)"); break;
1461 case DW_ATE_HP_complex_float80
: printf ("(HP_complex_float80)"); break;
1462 case DW_ATE_HP_float128
: printf ("(HP_float128)"); break;
1463 case DW_ATE_HP_complex_float128
:printf ("(HP_complex_float128)"); break;
1464 case DW_ATE_HP_floathpintel
: printf ("(HP_floathpintel)"); break;
1465 case DW_ATE_HP_imaginary_float80
: printf ("(HP_imaginary_float80)"); break;
1466 case DW_ATE_HP_imaginary_float128
: printf ("(HP_imaginary_float128)"); break;
1469 if (uvalue
>= DW_ATE_lo_user
1470 && uvalue
<= DW_ATE_hi_user
)
1471 printf ("(user defined type)");
1473 printf ("(unknown type)");
1478 case DW_AT_accessibility
:
1481 case DW_ACCESS_public
: printf ("(public)"); break;
1482 case DW_ACCESS_protected
: printf ("(protected)"); break;
1483 case DW_ACCESS_private
: printf ("(private)"); break;
1485 printf ("(unknown accessibility)");
1490 case DW_AT_visibility
:
1493 case DW_VIS_local
: printf ("(local)"); break;
1494 case DW_VIS_exported
: printf ("(exported)"); break;
1495 case DW_VIS_qualified
: printf ("(qualified)"); break;
1496 default: printf ("(unknown visibility)"); break;
1500 case DW_AT_virtuality
:
1503 case DW_VIRTUALITY_none
: printf ("(none)"); break;
1504 case DW_VIRTUALITY_virtual
: printf ("(virtual)"); break;
1505 case DW_VIRTUALITY_pure_virtual
:printf ("(pure_virtual)"); break;
1506 default: printf ("(unknown virtuality)"); break;
1510 case DW_AT_identifier_case
:
1513 case DW_ID_case_sensitive
: printf ("(case_sensitive)"); break;
1514 case DW_ID_up_case
: printf ("(up_case)"); break;
1515 case DW_ID_down_case
: printf ("(down_case)"); break;
1516 case DW_ID_case_insensitive
: printf ("(case_insensitive)"); break;
1517 default: printf ("(unknown case)"); break;
1521 case DW_AT_calling_convention
:
1524 case DW_CC_normal
: printf ("(normal)"); break;
1525 case DW_CC_program
: printf ("(program)"); break;
1526 case DW_CC_nocall
: printf ("(nocall)"); break;
1528 if (uvalue
>= DW_CC_lo_user
1529 && uvalue
<= DW_CC_hi_user
)
1530 printf ("(user defined)");
1532 printf ("(unknown convention)");
1536 case DW_AT_ordering
:
1539 case -1: printf ("(undefined)"); break;
1540 case 0: printf ("(row major)"); break;
1541 case 1: printf ("(column major)"); break;
1545 case DW_AT_frame_base
:
1546 have_frame_base
= 1;
1547 case DW_AT_location
:
1548 case DW_AT_string_length
:
1549 case DW_AT_return_addr
:
1550 case DW_AT_data_member_location
:
1551 case DW_AT_vtable_elem_location
:
1553 case DW_AT_static_link
:
1554 case DW_AT_use_location
:
1555 if (form
== DW_FORM_data4
|| form
== DW_FORM_data8
)
1556 printf (_("(location list)"));
1558 case DW_AT_allocated
:
1559 case DW_AT_associated
:
1560 case DW_AT_data_location
:
1562 case DW_AT_upper_bound
:
1563 case DW_AT_lower_bound
:
1566 int need_frame_base
;
1569 need_frame_base
= decode_location_expression (block_start
,
1572 cu_offset
, section
);
1574 if (need_frame_base
&& !have_frame_base
)
1575 printf (_(" [without DW_AT_frame_base]"));
1581 if (form
== DW_FORM_ref1
1582 || form
== DW_FORM_ref2
1583 || form
== DW_FORM_ref4
)
1584 uvalue
+= cu_offset
;
1586 if (uvalue
>= section
->size
)
1587 warn (_("Offset %lx used as value for DW_AT_import attribute of DIE at offset %lx is too big.\n"),
1588 uvalue
, (unsigned long) (orig_data
- section
->start
));
1591 unsigned long abbrev_number
;
1592 abbrev_entry
* entry
;
1594 abbrev_number
= read_leb128 (section
->start
+ uvalue
, NULL
, 0);
1596 printf ("[Abbrev Number: %ld", abbrev_number
);
1597 for (entry
= first_abbrev
; entry
!= NULL
; entry
= entry
->next
)
1598 if (entry
->entry
== abbrev_number
)
1601 printf (" (%s)", get_TAG_name (entry
->tag
));
1615 get_AT_name (unsigned long attribute
)
1619 case DW_AT_sibling
: return "DW_AT_sibling";
1620 case DW_AT_location
: return "DW_AT_location";
1621 case DW_AT_name
: return "DW_AT_name";
1622 case DW_AT_ordering
: return "DW_AT_ordering";
1623 case DW_AT_subscr_data
: return "DW_AT_subscr_data";
1624 case DW_AT_byte_size
: return "DW_AT_byte_size";
1625 case DW_AT_bit_offset
: return "DW_AT_bit_offset";
1626 case DW_AT_bit_size
: return "DW_AT_bit_size";
1627 case DW_AT_element_list
: return "DW_AT_element_list";
1628 case DW_AT_stmt_list
: return "DW_AT_stmt_list";
1629 case DW_AT_low_pc
: return "DW_AT_low_pc";
1630 case DW_AT_high_pc
: return "DW_AT_high_pc";
1631 case DW_AT_language
: return "DW_AT_language";
1632 case DW_AT_member
: return "DW_AT_member";
1633 case DW_AT_discr
: return "DW_AT_discr";
1634 case DW_AT_discr_value
: return "DW_AT_discr_value";
1635 case DW_AT_visibility
: return "DW_AT_visibility";
1636 case DW_AT_import
: return "DW_AT_import";
1637 case DW_AT_string_length
: return "DW_AT_string_length";
1638 case DW_AT_common_reference
: return "DW_AT_common_reference";
1639 case DW_AT_comp_dir
: return "DW_AT_comp_dir";
1640 case DW_AT_const_value
: return "DW_AT_const_value";
1641 case DW_AT_containing_type
: return "DW_AT_containing_type";
1642 case DW_AT_default_value
: return "DW_AT_default_value";
1643 case DW_AT_inline
: return "DW_AT_inline";
1644 case DW_AT_is_optional
: return "DW_AT_is_optional";
1645 case DW_AT_lower_bound
: return "DW_AT_lower_bound";
1646 case DW_AT_producer
: return "DW_AT_producer";
1647 case DW_AT_prototyped
: return "DW_AT_prototyped";
1648 case DW_AT_return_addr
: return "DW_AT_return_addr";
1649 case DW_AT_start_scope
: return "DW_AT_start_scope";
1650 case DW_AT_stride_size
: return "DW_AT_stride_size";
1651 case DW_AT_upper_bound
: return "DW_AT_upper_bound";
1652 case DW_AT_abstract_origin
: return "DW_AT_abstract_origin";
1653 case DW_AT_accessibility
: return "DW_AT_accessibility";
1654 case DW_AT_address_class
: return "DW_AT_address_class";
1655 case DW_AT_artificial
: return "DW_AT_artificial";
1656 case DW_AT_base_types
: return "DW_AT_base_types";
1657 case DW_AT_calling_convention
: return "DW_AT_calling_convention";
1658 case DW_AT_count
: return "DW_AT_count";
1659 case DW_AT_data_member_location
: return "DW_AT_data_member_location";
1660 case DW_AT_decl_column
: return "DW_AT_decl_column";
1661 case DW_AT_decl_file
: return "DW_AT_decl_file";
1662 case DW_AT_decl_line
: return "DW_AT_decl_line";
1663 case DW_AT_declaration
: return "DW_AT_declaration";
1664 case DW_AT_discr_list
: return "DW_AT_discr_list";
1665 case DW_AT_encoding
: return "DW_AT_encoding";
1666 case DW_AT_external
: return "DW_AT_external";
1667 case DW_AT_frame_base
: return "DW_AT_frame_base";
1668 case DW_AT_friend
: return "DW_AT_friend";
1669 case DW_AT_identifier_case
: return "DW_AT_identifier_case";
1670 case DW_AT_macro_info
: return "DW_AT_macro_info";
1671 case DW_AT_namelist_items
: return "DW_AT_namelist_items";
1672 case DW_AT_priority
: return "DW_AT_priority";
1673 case DW_AT_segment
: return "DW_AT_segment";
1674 case DW_AT_specification
: return "DW_AT_specification";
1675 case DW_AT_static_link
: return "DW_AT_static_link";
1676 case DW_AT_type
: return "DW_AT_type";
1677 case DW_AT_use_location
: return "DW_AT_use_location";
1678 case DW_AT_variable_parameter
: return "DW_AT_variable_parameter";
1679 case DW_AT_virtuality
: return "DW_AT_virtuality";
1680 case DW_AT_vtable_elem_location
: return "DW_AT_vtable_elem_location";
1681 /* DWARF 2.1 values. */
1682 case DW_AT_allocated
: return "DW_AT_allocated";
1683 case DW_AT_associated
: return "DW_AT_associated";
1684 case DW_AT_data_location
: return "DW_AT_data_location";
1685 case DW_AT_stride
: return "DW_AT_stride";
1686 case DW_AT_entry_pc
: return "DW_AT_entry_pc";
1687 case DW_AT_use_UTF8
: return "DW_AT_use_UTF8";
1688 case DW_AT_extension
: return "DW_AT_extension";
1689 case DW_AT_ranges
: return "DW_AT_ranges";
1690 case DW_AT_trampoline
: return "DW_AT_trampoline";
1691 case DW_AT_call_column
: return "DW_AT_call_column";
1692 case DW_AT_call_file
: return "DW_AT_call_file";
1693 case DW_AT_call_line
: return "DW_AT_call_line";
1694 case DW_AT_description
: return "DW_AT_description";
1695 case DW_AT_binary_scale
: return "DW_AT_binary_scale";
1696 case DW_AT_decimal_scale
: return "DW_AT_decimal_scale";
1697 case DW_AT_small
: return "DW_AT_small";
1698 case DW_AT_decimal_sign
: return "DW_AT_decimal_sign";
1699 case DW_AT_digit_count
: return "DW_AT_digit_count";
1700 case DW_AT_picture_string
: return "DW_AT_picture_string";
1701 case DW_AT_mutable
: return "DW_AT_mutable";
1702 case DW_AT_threads_scaled
: return "DW_AT_threads_scaled";
1703 case DW_AT_explicit
: return "DW_AT_explicit";
1704 case DW_AT_object_pointer
: return "DW_AT_object_pointer";
1705 case DW_AT_endianity
: return "DW_AT_endianity";
1706 case DW_AT_elemental
: return "DW_AT_elemental";
1707 case DW_AT_pure
: return "DW_AT_pure";
1708 case DW_AT_recursive
: return "DW_AT_recursive";
1710 /* HP and SGI/MIPS extensions. */
1711 case DW_AT_MIPS_loop_begin
: return "DW_AT_MIPS_loop_begin";
1712 case DW_AT_MIPS_tail_loop_begin
: return "DW_AT_MIPS_tail_loop_begin";
1713 case DW_AT_MIPS_epilog_begin
: return "DW_AT_MIPS_epilog_begin";
1714 case DW_AT_MIPS_loop_unroll_factor
: return "DW_AT_MIPS_loop_unroll_factor";
1715 case DW_AT_MIPS_software_pipeline_depth
: return "DW_AT_MIPS_software_pipeline_depth";
1716 case DW_AT_MIPS_linkage_name
: return "DW_AT_MIPS_linkage_name";
1717 case DW_AT_MIPS_stride
: return "DW_AT_MIPS_stride";
1718 case DW_AT_MIPS_abstract_name
: return "DW_AT_MIPS_abstract_name";
1719 case DW_AT_MIPS_clone_origin
: return "DW_AT_MIPS_clone_origin";
1720 case DW_AT_MIPS_has_inlines
: return "DW_AT_MIPS_has_inlines";
1722 /* HP Extensions. */
1723 case DW_AT_HP_block_index
: return "DW_AT_HP_block_index";
1724 case DW_AT_HP_actuals_stmt_list
: return "DW_AT_HP_actuals_stmt_list";
1725 case DW_AT_HP_proc_per_section
: return "DW_AT_HP_proc_per_section";
1726 case DW_AT_HP_raw_data_ptr
: return "DW_AT_HP_raw_data_ptr";
1727 case DW_AT_HP_pass_by_reference
: return "DW_AT_HP_pass_by_reference";
1728 case DW_AT_HP_opt_level
: return "DW_AT_HP_opt_level";
1729 case DW_AT_HP_prof_version_id
: return "DW_AT_HP_prof_version_id";
1730 case DW_AT_HP_opt_flags
: return "DW_AT_HP_opt_flags";
1731 case DW_AT_HP_cold_region_low_pc
: return "DW_AT_HP_cold_region_low_pc";
1732 case DW_AT_HP_cold_region_high_pc
: return "DW_AT_HP_cold_region_high_pc";
1733 case DW_AT_HP_all_variables_modifiable
: return "DW_AT_HP_all_variables_modifiable";
1734 case DW_AT_HP_linkage_name
: return "DW_AT_HP_linkage_name";
1735 case DW_AT_HP_prof_flags
: return "DW_AT_HP_prof_flags";
1737 /* One value is shared by the MIPS and HP extensions: */
1738 case DW_AT_MIPS_fde
: return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable";
1740 /* GNU extensions. */
1741 case DW_AT_sf_names
: return "DW_AT_sf_names";
1742 case DW_AT_src_info
: return "DW_AT_src_info";
1743 case DW_AT_mac_info
: return "DW_AT_mac_info";
1744 case DW_AT_src_coords
: return "DW_AT_src_coords";
1745 case DW_AT_body_begin
: return "DW_AT_body_begin";
1746 case DW_AT_body_end
: return "DW_AT_body_end";
1747 case DW_AT_GNU_vector
: return "DW_AT_GNU_vector";
1749 /* UPC extension. */
1750 case DW_AT_upc_threads_scaled
: return "DW_AT_upc_threads_scaled";
1752 /* PGI (STMicroelectronics) extensions. */
1753 case DW_AT_PGI_lbase
: return "DW_AT_PGI_lbase";
1754 case DW_AT_PGI_soffset
: return "DW_AT_PGI_soffset";
1755 case DW_AT_PGI_lstride
: return "DW_AT_PGI_lstride";
1759 static char buffer
[100];
1761 snprintf (buffer
, sizeof (buffer
), _("Unknown AT value: %lx"),
1768 static unsigned char *
1769 read_and_display_attr (unsigned long attribute
,
1771 unsigned char * data
,
1772 unsigned long cu_offset
,
1773 unsigned long pointer_size
,
1774 unsigned long offset_size
,
1776 debug_info
* debug_info_p
,
1778 struct dwarf_section
* section
)
1781 printf (" %-18s:", get_AT_name (attribute
));
1782 data
= read_and_display_attr_value (attribute
, form
, data
, cu_offset
,
1783 pointer_size
, offset_size
,
1784 dwarf_version
, debug_info_p
,
1792 /* Process the contents of a .debug_info section. If do_loc is non-zero
1793 then we are scanning for location lists and we do not want to display
1794 anything to the user. */
1797 process_debug_info (struct dwarf_section
*section
,
1801 unsigned char *start
= section
->start
;
1802 unsigned char *end
= start
+ section
->size
;
1803 unsigned char *section_begin
;
1805 unsigned int num_units
= 0;
1807 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
1808 && num_debug_info_entries
== 0)
1810 unsigned long length
;
1812 /* First scan the section to get the number of comp units. */
1813 for (section_begin
= start
, num_units
= 0; section_begin
< end
;
1816 /* Read the first 4 bytes. For a 32-bit DWARF section, this
1817 will be the length. For a 64-bit DWARF section, it'll be
1818 the escape code 0xffffffff followed by an 8 byte length. */
1819 length
= byte_get (section_begin
, 4);
1821 if (length
== 0xffffffff)
1823 length
= byte_get (section_begin
+ 4, 8);
1824 section_begin
+= length
+ 12;
1826 else if (length
>= 0xfffffff0 && length
< 0xffffffff)
1828 warn (_("Reserved length value (%lx) found in section %s\n"), length
, section
->name
);
1832 section_begin
+= length
+ 4;
1834 /* Negative values are illegal, they may even cause infinite
1835 looping. This can happen if we can't accurately apply
1836 relocations to an object file. */
1837 if ((signed long) length
<= 0)
1839 warn (_("Corrupt unit length (%lx) found in section %s\n"), length
, section
->name
);
1846 error (_("No comp units in %s section ?"), section
->name
);
1850 /* Then allocate an array to hold the information. */
1851 debug_information
= cmalloc (num_units
,
1852 sizeof (* debug_information
));
1853 if (debug_information
== NULL
)
1855 error (_("Not enough memory for a debug info array of %u entries"),
1863 printf (_("Contents of the %s section:\n\n"), section
->name
);
1865 load_debug_section (str
, file
);
1868 load_debug_section (abbrev
, file
);
1869 if (debug_displays
[abbrev
].section
.start
== NULL
)
1871 warn (_("Unable to locate %s section!\n"),
1872 debug_displays
[abbrev
].section
.name
);
1876 for (section_begin
= start
, unit
= 0; start
< end
; unit
++)
1878 DWARF2_Internal_CompUnit compunit
;
1879 unsigned char *hdrptr
;
1880 unsigned char *cu_abbrev_offset_ptr
;
1881 unsigned char *tags
;
1883 unsigned long cu_offset
;
1885 int initial_length_size
;
1889 compunit
.cu_length
= byte_get (hdrptr
, 4);
1892 if (compunit
.cu_length
== 0xffffffff)
1894 compunit
.cu_length
= byte_get (hdrptr
, 8);
1897 initial_length_size
= 12;
1902 initial_length_size
= 4;
1905 compunit
.cu_version
= byte_get (hdrptr
, 2);
1908 cu_offset
= start
- section_begin
;
1910 cu_abbrev_offset_ptr
= hdrptr
;
1911 compunit
.cu_abbrev_offset
= byte_get (hdrptr
, offset_size
);
1912 hdrptr
+= offset_size
;
1914 compunit
.cu_pointer_size
= byte_get (hdrptr
, 1);
1916 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
1917 && num_debug_info_entries
== 0)
1919 debug_information
[unit
].cu_offset
= cu_offset
;
1920 debug_information
[unit
].pointer_size
1921 = compunit
.cu_pointer_size
;
1922 debug_information
[unit
].base_address
= 0;
1923 debug_information
[unit
].loc_offsets
= NULL
;
1924 debug_information
[unit
].have_frame_base
= NULL
;
1925 debug_information
[unit
].max_loc_offsets
= 0;
1926 debug_information
[unit
].num_loc_offsets
= 0;
1927 debug_information
[unit
].range_lists
= NULL
;
1928 debug_information
[unit
].max_range_lists
= 0;
1929 debug_information
[unit
].num_range_lists
= 0;
1934 printf (_(" Compilation Unit @ offset 0x%lx:\n"), cu_offset
);
1935 printf (_(" Length: 0x%lx (%s)\n"), compunit
.cu_length
,
1936 initial_length_size
== 8 ? "64-bit" : "32-bit");
1937 printf (_(" Version: %d\n"), compunit
.cu_version
);
1938 printf (_(" Abbrev Offset: %ld\n"), compunit
.cu_abbrev_offset
);
1939 printf (_(" Pointer Size: %d\n"), compunit
.cu_pointer_size
);
1942 if (cu_offset
+ compunit
.cu_length
+ initial_length_size
1945 warn (_("Debug info is corrupted, length of CU at %lx extends beyond end of section (length = %lx)\n"),
1946 cu_offset
, compunit
.cu_length
);
1950 start
+= compunit
.cu_length
+ initial_length_size
;
1952 if (compunit
.cu_version
!= 2 && compunit
.cu_version
!= 3)
1954 warn (_("CU at offset %lx contains corrupt or unsupported version number: %d.\n"),
1955 cu_offset
, compunit
.cu_version
);
1961 /* Process the abbrevs used by this compilation unit. DWARF
1962 sections under Mach-O have non-zero addresses. */
1963 if (compunit
.cu_abbrev_offset
>= debug_displays
[abbrev
].section
.size
)
1964 warn (_("Debug info is corrupted, abbrev offset (%lx) is larger than abbrev section size (%lx)\n"),
1965 (unsigned long) compunit
.cu_abbrev_offset
,
1966 (unsigned long) debug_displays
[abbrev
].section
.size
);
1968 process_abbrev_section
1969 ((unsigned char *) debug_displays
[abbrev
].section
.start
1970 + compunit
.cu_abbrev_offset
- debug_displays
[abbrev
].section
.address
,
1971 (unsigned char *) debug_displays
[abbrev
].section
.start
1972 + debug_displays
[abbrev
].section
.size
);
1975 while (tags
< start
)
1977 unsigned int bytes_read
;
1978 unsigned long abbrev_number
;
1979 unsigned long die_offset
;
1980 abbrev_entry
*entry
;
1983 die_offset
= tags
- section_begin
;
1985 abbrev_number
= read_leb128 (tags
, & bytes_read
, 0);
1988 /* A null DIE marks the end of a list of siblings. */
1989 if (abbrev_number
== 0)
1994 static unsigned num_bogus_warns
= 0;
1996 if (num_bogus_warns
< 3)
1998 warn (_("Bogus end-of-siblings marker detected at offset %lx in .debug_info section\n"),
2001 if (num_bogus_warns
== 3)
2002 warn (_("Further warnings about bogus end-of-sibling markers suppressed\n"));
2009 printf (_(" <%d><%lx>: Abbrev Number: %lu"),
2010 level
, die_offset
, abbrev_number
);
2012 /* Scan through the abbreviation list until we reach the
2014 for (entry
= first_abbrev
;
2015 entry
&& entry
->entry
!= abbrev_number
;
2016 entry
= entry
->next
)
2026 warn (_("DIE at offset %lx refers to abbreviation number %lu which does not exist\n"),
2027 die_offset
, abbrev_number
);
2032 printf (_(" (%s)\n"), get_TAG_name (entry
->tag
));
2037 need_base_address
= 0;
2039 case DW_TAG_compile_unit
:
2040 need_base_address
= 1;
2042 case DW_TAG_entry_point
:
2043 case DW_TAG_subprogram
:
2044 need_base_address
= 0;
2045 /* Assuming that there is no DW_AT_frame_base. */
2046 have_frame_base
= 0;
2050 for (attr
= entry
->first_attr
; attr
; attr
= attr
->next
)
2053 /* Show the offset from where the tag was extracted. */
2054 printf (" <%2lx>", (unsigned long)(tags
- section_begin
));
2056 tags
= read_and_display_attr (attr
->attribute
,
2059 compunit
.cu_pointer_size
,
2061 compunit
.cu_version
,
2062 debug_information
+ unit
,
2066 if (entry
->children
)
2071 /* Set num_debug_info_entries here so that it can be used to check if
2072 we need to process .debug_loc and .debug_ranges sections. */
2073 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
2074 && num_debug_info_entries
== 0)
2075 num_debug_info_entries
= num_units
;
2085 /* Locate and scan the .debug_info section in the file and record the pointer
2086 sizes and offsets for the compilation units in it. Usually an executable
2087 will have just one pointer size, but this is not guaranteed, and so we try
2088 not to make any assumptions. Returns zero upon failure, or the number of
2089 compilation units upon success. */
2092 load_debug_info (void * file
)
2094 /* Reset the last pointer size so that we can issue correct error
2095 messages if we are displaying the contents of more than one section. */
2096 last_pointer_size
= 0;
2097 warned_about_missing_comp_units
= FALSE
;
2099 /* If we have already tried and failed to load the .debug_info
2100 section then do not bother to repear the task. */
2101 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
2104 /* If we already have the information there is nothing else to do. */
2105 if (num_debug_info_entries
> 0)
2106 return num_debug_info_entries
;
2108 if (load_debug_section (info
, file
)
2109 && process_debug_info (&debug_displays
[info
].section
, file
, 1))
2110 return num_debug_info_entries
;
2112 num_debug_info_entries
= DEBUG_INFO_UNAVAILABLE
;
2117 display_debug_lines_raw (struct dwarf_section
*section
,
2118 unsigned char *data
,
2121 unsigned char *start
= section
->start
;
2123 printf (_("Raw dump of debug contents of section %s:\n\n"),
2128 DWARF2_Internal_LineInfo info
;
2129 unsigned char *standard_opcodes
;
2130 unsigned char *end_of_sequence
;
2131 unsigned char *hdrptr
;
2132 unsigned long hdroff
;
2133 int initial_length_size
;
2138 hdroff
= hdrptr
- start
;
2140 /* Check the length of the block. */
2141 info
.li_length
= byte_get (hdrptr
, 4);
2144 if (info
.li_length
== 0xffffffff)
2146 /* This section is 64-bit DWARF 3. */
2147 info
.li_length
= byte_get (hdrptr
, 8);
2150 initial_length_size
= 12;
2155 initial_length_size
= 4;
2158 if (info
.li_length
+ initial_length_size
> section
->size
)
2161 (_("The information in section %s appears to be corrupt - the section is too small\n"),
2166 /* Check its version number. */
2167 info
.li_version
= byte_get (hdrptr
, 2);
2169 if (info
.li_version
!= 2 && info
.li_version
!= 3)
2171 warn (_("Only DWARF version 2 and 3 line info is currently supported.\n"));
2175 info
.li_prologue_length
= byte_get (hdrptr
, offset_size
);
2176 hdrptr
+= offset_size
;
2177 info
.li_min_insn_length
= byte_get (hdrptr
, 1);
2179 info
.li_default_is_stmt
= byte_get (hdrptr
, 1);
2181 info
.li_line_base
= byte_get (hdrptr
, 1);
2183 info
.li_line_range
= byte_get (hdrptr
, 1);
2185 info
.li_opcode_base
= byte_get (hdrptr
, 1);
2188 /* Sign extend the line base field. */
2189 info
.li_line_base
<<= 24;
2190 info
.li_line_base
>>= 24;
2192 printf (_(" Offset: 0x%lx\n"), hdroff
);
2193 printf (_(" Length: %ld\n"), info
.li_length
);
2194 printf (_(" DWARF Version: %d\n"), info
.li_version
);
2195 printf (_(" Prologue Length: %d\n"), info
.li_prologue_length
);
2196 printf (_(" Minimum Instruction Length: %d\n"), info
.li_min_insn_length
);
2197 printf (_(" Initial value of 'is_stmt': %d\n"), info
.li_default_is_stmt
);
2198 printf (_(" Line Base: %d\n"), info
.li_line_base
);
2199 printf (_(" Line Range: %d\n"), info
.li_line_range
);
2200 printf (_(" Opcode Base: %d\n"), info
.li_opcode_base
);
2202 end_of_sequence
= data
+ info
.li_length
+ initial_length_size
;
2204 reset_state_machine (info
.li_default_is_stmt
);
2206 /* Display the contents of the Opcodes table. */
2207 standard_opcodes
= hdrptr
;
2209 printf (_("\n Opcodes:\n"));
2211 for (i
= 1; i
< info
.li_opcode_base
; i
++)
2212 printf (_(" Opcode %d has %d args\n"), i
, standard_opcodes
[i
- 1]);
2214 /* Display the contents of the Directory table. */
2215 data
= standard_opcodes
+ info
.li_opcode_base
- 1;
2218 printf (_("\n The Directory Table is empty.\n"));
2221 printf (_("\n The Directory Table:\n"));
2225 printf (_(" %s\n"), data
);
2227 data
+= strlen ((char *) data
) + 1;
2231 /* Skip the NUL at the end of the table. */
2234 /* Display the contents of the File Name table. */
2236 printf (_("\n The File Name Table is empty.\n"));
2239 printf (_("\n The File Name Table:\n"));
2240 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
2244 unsigned char *name
;
2245 unsigned int bytes_read
;
2247 printf (_(" %d\t"), ++state_machine_regs
.last_file_entry
);
2250 data
+= strlen ((char *) data
) + 1;
2252 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
2254 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
2256 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
2258 printf (_("%s\n"), name
);
2262 /* Skip the NUL at the end of the table. */
2265 /* Now display the statements. */
2266 printf (_("\n Line Number Statements:\n"));
2268 while (data
< end_of_sequence
)
2270 unsigned char op_code
;
2272 unsigned long int uladv
;
2273 unsigned int bytes_read
;
2277 if (op_code
>= info
.li_opcode_base
)
2279 op_code
-= info
.li_opcode_base
;
2280 uladv
= (op_code
/ info
.li_line_range
) * info
.li_min_insn_length
;
2281 state_machine_regs
.address
+= uladv
;
2282 printf (_(" Special opcode %d: advance Address by %lu to 0x%lx"),
2283 op_code
, uladv
, state_machine_regs
.address
);
2284 adv
= (op_code
% info
.li_line_range
) + info
.li_line_base
;
2285 state_machine_regs
.line
+= adv
;
2286 printf (_(" and Line by %d to %d\n"),
2287 adv
, state_machine_regs
.line
);
2289 else switch (op_code
)
2291 case DW_LNS_extended_op
:
2292 data
+= process_extended_line_op (data
, info
.li_default_is_stmt
);
2296 printf (_(" Copy\n"));
2299 case DW_LNS_advance_pc
:
2300 uladv
= read_leb128 (data
, & bytes_read
, 0);
2301 uladv
*= info
.li_min_insn_length
;
2303 state_machine_regs
.address
+= uladv
;
2304 printf (_(" Advance PC by %lu to 0x%lx\n"), uladv
,
2305 state_machine_regs
.address
);
2308 case DW_LNS_advance_line
:
2309 adv
= read_leb128 (data
, & bytes_read
, 1);
2311 state_machine_regs
.line
+= adv
;
2312 printf (_(" Advance Line by %d to %d\n"), adv
,
2313 state_machine_regs
.line
);
2316 case DW_LNS_set_file
:
2317 adv
= read_leb128 (data
, & bytes_read
, 0);
2319 printf (_(" Set File Name to entry %d in the File Name Table\n"),
2321 state_machine_regs
.file
= adv
;
2324 case DW_LNS_set_column
:
2325 uladv
= read_leb128 (data
, & bytes_read
, 0);
2327 printf (_(" Set column to %lu\n"), uladv
);
2328 state_machine_regs
.column
= uladv
;
2331 case DW_LNS_negate_stmt
:
2332 adv
= state_machine_regs
.is_stmt
;
2334 printf (_(" Set is_stmt to %d\n"), adv
);
2335 state_machine_regs
.is_stmt
= adv
;
2338 case DW_LNS_set_basic_block
:
2339 printf (_(" Set basic block\n"));
2340 state_machine_regs
.basic_block
= 1;
2343 case DW_LNS_const_add_pc
:
2344 uladv
= (((255 - info
.li_opcode_base
) / info
.li_line_range
)
2345 * info
.li_min_insn_length
);
2346 state_machine_regs
.address
+= uladv
;
2347 printf (_(" Advance PC by constant %lu to 0x%lx\n"), uladv
,
2348 state_machine_regs
.address
);
2351 case DW_LNS_fixed_advance_pc
:
2352 uladv
= byte_get (data
, 2);
2354 state_machine_regs
.address
+= uladv
;
2355 printf (_(" Advance PC by fixed size amount %lu to 0x%lx\n"),
2356 uladv
, state_machine_regs
.address
);
2359 case DW_LNS_set_prologue_end
:
2360 printf (_(" Set prologue_end to true\n"));
2363 case DW_LNS_set_epilogue_begin
:
2364 printf (_(" Set epilogue_begin to true\n"));
2367 case DW_LNS_set_isa
:
2368 uladv
= read_leb128 (data
, & bytes_read
, 0);
2370 printf (_(" Set ISA to %lu\n"), uladv
);
2374 printf (_(" Unknown opcode %d with operands: "), op_code
);
2376 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
2378 printf ("0x%lx%s", read_leb128 (data
, &bytes_read
, 0),
2379 i
== 1 ? "" : ", ");
2394 unsigned char *name
;
2395 unsigned int directory_index
;
2396 unsigned int modification_date
;
2397 unsigned int length
;
2400 /* Output a decoded representation of the .debug_line section. */
2403 display_debug_lines_decoded (struct dwarf_section
*section
,
2404 unsigned char *data
,
2407 printf (_("Decoded dump of debug contents of section %s:\n\n"),
2412 /* This loop amounts to one iteration per compilation unit. */
2413 DWARF2_Internal_LineInfo info
;
2414 unsigned char *standard_opcodes
;
2415 unsigned char *end_of_sequence
;
2416 unsigned char *hdrptr
;
2417 int initial_length_size
;
2420 File_Entry
*file_table
= NULL
;
2421 unsigned char **directory_table
= NULL
;
2422 unsigned int prev_line
= 0;
2426 /* Extract information from the Line Number Program Header.
2427 (section 6.2.4 in the Dwarf3 doc). */
2429 /* Get the length of this CU's line number information block. */
2430 info
.li_length
= byte_get (hdrptr
, 4);
2433 if (info
.li_length
== 0xffffffff)
2435 /* This section is 64-bit DWARF 3. */
2436 info
.li_length
= byte_get (hdrptr
, 8);
2439 initial_length_size
= 12;
2444 initial_length_size
= 4;
2447 if (info
.li_length
+ initial_length_size
> section
->size
)
2449 warn (_("The line info appears to be corrupt - "
2450 "the section is too small\n"));
2454 /* Get this CU's Line Number Block version number. */
2455 info
.li_version
= byte_get (hdrptr
, 2);
2457 if (info
.li_version
!= 2 && info
.li_version
!= 3)
2459 warn (_("Only DWARF version 2 and 3 line info is currently "
2464 info
.li_prologue_length
= byte_get (hdrptr
, offset_size
);
2465 hdrptr
+= offset_size
;
2466 info
.li_min_insn_length
= byte_get (hdrptr
, 1);
2468 info
.li_default_is_stmt
= byte_get (hdrptr
, 1);
2470 info
.li_line_base
= byte_get (hdrptr
, 1);
2472 info
.li_line_range
= byte_get (hdrptr
, 1);
2474 info
.li_opcode_base
= byte_get (hdrptr
, 1);
2477 /* Sign extend the line base field. */
2478 info
.li_line_base
<<= 24;
2479 info
.li_line_base
>>= 24;
2481 /* Find the end of this CU's Line Number Information Block. */
2482 end_of_sequence
= data
+ info
.li_length
+ initial_length_size
;
2484 reset_state_machine (info
.li_default_is_stmt
);
2486 /* Save a pointer to the contents of the Opcodes table. */
2487 standard_opcodes
= hdrptr
;
2489 /* Traverse the Directory table just to count entries. */
2490 data
= standard_opcodes
+ info
.li_opcode_base
- 1;
2493 unsigned int n_directories
= 0;
2494 unsigned char *ptr_directory_table
= data
;
2499 data
+= strlen ((char *) data
) + 1;
2503 /* Go through the directory table again to save the directories. */
2504 directory_table
= xmalloc (n_directories
* sizeof (unsigned char *));
2507 while (*ptr_directory_table
!= 0)
2509 directory_table
[i
] = ptr_directory_table
;
2510 ptr_directory_table
+= strlen ((char *) ptr_directory_table
) + 1;
2514 /* Skip the NUL at the end of the table. */
2517 /* Traverse the File Name table just to count the entries. */
2520 unsigned int n_files
= 0;
2521 unsigned char *ptr_file_name_table
= data
;
2526 unsigned int bytes_read
;
2528 /* Skip Name, directory index, last modification time and length
2530 data
+= strlen ((char *) data
) + 1;
2531 read_leb128 (data
, & bytes_read
, 0);
2533 read_leb128 (data
, & bytes_read
, 0);
2535 read_leb128 (data
, & bytes_read
, 0);
2541 /* Go through the file table again to save the strings. */
2542 file_table
= xmalloc (n_files
* sizeof (File_Entry
));
2545 while (*ptr_file_name_table
!= 0)
2547 unsigned int bytes_read
;
2549 file_table
[i
].name
= ptr_file_name_table
;
2550 ptr_file_name_table
+= strlen ((char *) ptr_file_name_table
) + 1;
2552 /* We are not interested in directory, time or size. */
2553 file_table
[i
].directory_index
= read_leb128 (ptr_file_name_table
,
2555 ptr_file_name_table
+= bytes_read
;
2556 file_table
[i
].modification_date
= read_leb128 (ptr_file_name_table
,
2558 ptr_file_name_table
+= bytes_read
;
2559 file_table
[i
].length
= read_leb128 (ptr_file_name_table
, & bytes_read
, 0);
2560 ptr_file_name_table
+= bytes_read
;
2565 /* Print the Compilation Unit's name and a header. */
2566 if (directory_table
== NULL
)
2568 printf (_("CU: %s:\n"), file_table
[0].name
);
2569 printf (_("File name Line number Starting address\n"));
2573 if (do_wide
|| strlen ((char *) directory_table
[0]) < 76)
2575 printf (_("CU: %s/%s:\n"), directory_table
[0],
2576 file_table
[0].name
);
2580 printf (_("%s:\n"), file_table
[0].name
);
2582 printf (_("File name Line number Starting address\n"));
2586 /* Skip the NUL at the end of the table. */
2589 /* This loop iterates through the Dwarf Line Number Program. */
2590 while (data
< end_of_sequence
)
2592 unsigned char op_code
;
2594 unsigned long int uladv
;
2595 unsigned int bytes_read
;
2596 int is_special_opcode
= 0;
2599 prev_line
= state_machine_regs
.line
;
2601 if (op_code
>= info
.li_opcode_base
)
2603 op_code
-= info
.li_opcode_base
;
2604 uladv
= (op_code
/ info
.li_line_range
) * info
.li_min_insn_length
;
2605 state_machine_regs
.address
+= uladv
;
2607 adv
= (op_code
% info
.li_line_range
) + info
.li_line_base
;
2608 state_machine_regs
.line
+= adv
;
2609 is_special_opcode
= 1;
2611 else switch (op_code
)
2613 case DW_LNS_extended_op
:
2615 unsigned int ext_op_code_len
;
2616 unsigned int bytes_read
;
2617 unsigned char ext_op_code
;
2618 unsigned char *op_code_data
= data
;
2620 ext_op_code_len
= read_leb128 (op_code_data
, &bytes_read
, 0);
2621 op_code_data
+= bytes_read
;
2623 if (ext_op_code_len
== 0)
2625 warn (_("badly formed extended line op encountered!\n"));
2628 ext_op_code_len
+= bytes_read
;
2629 ext_op_code
= *op_code_data
++;
2631 switch (ext_op_code
)
2633 case DW_LNE_end_sequence
:
2634 reset_state_machine (info
.li_default_is_stmt
);
2636 case DW_LNE_set_address
:
2637 state_machine_regs
.address
=
2638 byte_get (op_code_data
, ext_op_code_len
- bytes_read
- 1);
2640 case DW_LNE_define_file
:
2642 unsigned int dir_index
= 0;
2644 ++state_machine_regs
.last_file_entry
;
2645 op_code_data
+= strlen ((char *) op_code_data
) + 1;
2646 dir_index
= read_leb128 (op_code_data
, & bytes_read
, 0);
2647 op_code_data
+= bytes_read
;
2648 read_leb128 (op_code_data
, & bytes_read
, 0);
2649 op_code_data
+= bytes_read
;
2650 read_leb128 (op_code_data
, & bytes_read
, 0);
2652 printf (_("%s:\n"), directory_table
[dir_index
]);
2656 printf (_("UNKNOWN: length %d\n"), ext_op_code_len
- bytes_read
);
2659 data
+= ext_op_code_len
;
2665 case DW_LNS_advance_pc
:
2666 uladv
= read_leb128 (data
, & bytes_read
, 0);
2667 uladv
*= info
.li_min_insn_length
;
2669 state_machine_regs
.address
+= uladv
;
2672 case DW_LNS_advance_line
:
2673 adv
= read_leb128 (data
, & bytes_read
, 1);
2675 state_machine_regs
.line
+= adv
;
2678 case DW_LNS_set_file
:
2679 adv
= read_leb128 (data
, & bytes_read
, 0);
2681 state_machine_regs
.file
= adv
;
2682 if (file_table
[state_machine_regs
.file
- 1].directory_index
== 0)
2684 /* If directory index is 0, that means current directory. */
2685 printf (_("\n./%s:[++]\n"),
2686 file_table
[state_machine_regs
.file
- 1].name
);
2690 /* The directory index starts counting at 1. */
2691 printf (_("\n%s/%s:\n"),
2692 directory_table
[file_table
[state_machine_regs
.file
- 1].directory_index
- 1],
2693 file_table
[state_machine_regs
.file
- 1].name
);
2697 case DW_LNS_set_column
:
2698 uladv
= read_leb128 (data
, & bytes_read
, 0);
2700 state_machine_regs
.column
= uladv
;
2703 case DW_LNS_negate_stmt
:
2704 adv
= state_machine_regs
.is_stmt
;
2706 state_machine_regs
.is_stmt
= adv
;
2709 case DW_LNS_set_basic_block
:
2710 state_machine_regs
.basic_block
= 1;
2713 case DW_LNS_const_add_pc
:
2714 uladv
= (((255 - info
.li_opcode_base
) / info
.li_line_range
)
2715 * info
.li_min_insn_length
);
2716 state_machine_regs
.address
+= uladv
;
2719 case DW_LNS_fixed_advance_pc
:
2720 uladv
= byte_get (data
, 2);
2722 state_machine_regs
.address
+= uladv
;
2725 case DW_LNS_set_prologue_end
:
2728 case DW_LNS_set_epilogue_begin
:
2731 case DW_LNS_set_isa
:
2732 uladv
= read_leb128 (data
, & bytes_read
, 0);
2734 printf (_(" Set ISA to %lu\n"), uladv
);
2738 printf (_(" Unknown opcode %d with operands: "), op_code
);
2740 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
2742 printf ("0x%lx%s", read_leb128 (data
, &bytes_read
, 0),
2743 i
== 1 ? "" : ", ");
2750 /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row
2751 to the DWARF address/line matrix. */
2752 if ((is_special_opcode
) || (op_code
== DW_LNE_end_sequence
)
2753 || (op_code
== DW_LNS_copy
))
2755 const unsigned int MAX_FILENAME_LENGTH
= 35;
2756 char *fileName
= (char *)file_table
[state_machine_regs
.file
- 1].name
;
2757 char *newFileName
= NULL
;
2758 size_t fileNameLength
= strlen (fileName
);
2760 if ((fileNameLength
> MAX_FILENAME_LENGTH
) && (!do_wide
))
2762 newFileName
= xmalloc (MAX_FILENAME_LENGTH
+ 1);
2763 /* Truncate file name */
2764 strncpy (newFileName
,
2765 fileName
+ fileNameLength
- MAX_FILENAME_LENGTH
,
2766 MAX_FILENAME_LENGTH
+ 1);
2770 newFileName
= xmalloc (fileNameLength
+ 1);
2771 strncpy (newFileName
, fileName
, fileNameLength
+ 1);
2774 if (!do_wide
|| (fileNameLength
<= MAX_FILENAME_LENGTH
))
2776 printf (_("%-35s %11d %#18lx\n"), newFileName
,
2777 state_machine_regs
.line
, state_machine_regs
.address
);
2781 printf (_("%s %11d %#18lx\n"), newFileName
,
2782 state_machine_regs
.line
, state_machine_regs
.address
);
2785 if (op_code
== DW_LNE_end_sequence
)
2793 free (directory_table
);
2794 directory_table
= NULL
;
2802 display_debug_lines (struct dwarf_section
*section
, void *file
)
2804 unsigned char *data
= section
->start
;
2805 unsigned char *end
= data
+ section
->size
;
2807 int retValDecoded
= 1;
2809 if (load_debug_info (file
) == 0)
2811 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
2816 if (do_debug_lines
& FLAG_DEBUG_LINES_RAW
)
2817 retValRaw
= display_debug_lines_raw (section
, data
, end
);
2819 if (do_debug_lines
& FLAG_DEBUG_LINES_DECODED
)
2820 retValDecoded
= display_debug_lines_decoded (section
, data
, end
);
2822 if (!retValRaw
|| !retValDecoded
)
2829 find_debug_info_for_offset (unsigned long offset
)
2833 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
2836 for (i
= 0; i
< num_debug_info_entries
; i
++)
2837 if (debug_information
[i
].cu_offset
== offset
)
2838 return debug_information
+ i
;
2844 display_debug_pubnames (struct dwarf_section
*section
,
2845 void *file ATTRIBUTE_UNUSED
)
2847 DWARF2_Internal_PubNames pubnames
;
2848 unsigned char *start
= section
->start
;
2849 unsigned char *end
= start
+ section
->size
;
2851 /* It does not matter if this load fails,
2852 we test for that later on. */
2853 load_debug_info (file
);
2855 printf (_("Contents of the %s section:\n\n"), section
->name
);
2859 unsigned char *data
;
2860 unsigned long offset
;
2861 int offset_size
, initial_length_size
;
2865 pubnames
.pn_length
= byte_get (data
, 4);
2867 if (pubnames
.pn_length
== 0xffffffff)
2869 pubnames
.pn_length
= byte_get (data
, 8);
2872 initial_length_size
= 12;
2877 initial_length_size
= 4;
2880 pubnames
.pn_version
= byte_get (data
, 2);
2883 pubnames
.pn_offset
= byte_get (data
, offset_size
);
2884 data
+= offset_size
;
2886 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
2887 && num_debug_info_entries
> 0
2888 && find_debug_info_for_offset (pubnames
.pn_offset
) == NULL
)
2889 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
2890 pubnames
.pn_offset
, section
->name
);
2892 pubnames
.pn_size
= byte_get (data
, offset_size
);
2893 data
+= offset_size
;
2895 start
+= pubnames
.pn_length
+ initial_length_size
;
2897 if (pubnames
.pn_version
!= 2 && pubnames
.pn_version
!= 3)
2899 static int warned
= 0;
2903 warn (_("Only DWARF 2 and 3 pubnames are currently supported\n"));
2910 printf (_(" Length: %ld\n"),
2911 pubnames
.pn_length
);
2912 printf (_(" Version: %d\n"),
2913 pubnames
.pn_version
);
2914 printf (_(" Offset into .debug_info section: 0x%lx\n"),
2915 pubnames
.pn_offset
);
2916 printf (_(" Size of area in .debug_info section: %ld\n"),
2919 printf (_("\n Offset\tName\n"));
2923 offset
= byte_get (data
, offset_size
);
2927 data
+= offset_size
;
2928 printf (" %-6lx\t%s\n", offset
, data
);
2929 data
+= strlen ((char *) data
) + 1;
2932 while (offset
!= 0);
2940 display_debug_macinfo (struct dwarf_section
*section
,
2941 void *file ATTRIBUTE_UNUSED
)
2943 unsigned char *start
= section
->start
;
2944 unsigned char *end
= start
+ section
->size
;
2945 unsigned char *curr
= start
;
2946 unsigned int bytes_read
;
2947 enum dwarf_macinfo_record_type op
;
2949 printf (_("Contents of the %s section:\n\n"), section
->name
);
2953 unsigned int lineno
;
2961 case DW_MACINFO_start_file
:
2963 unsigned int filenum
;
2965 lineno
= read_leb128 (curr
, & bytes_read
, 0);
2967 filenum
= read_leb128 (curr
, & bytes_read
, 0);
2970 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"),
2975 case DW_MACINFO_end_file
:
2976 printf (_(" DW_MACINFO_end_file\n"));
2979 case DW_MACINFO_define
:
2980 lineno
= read_leb128 (curr
, & bytes_read
, 0);
2982 string
= (char *) curr
;
2983 curr
+= strlen (string
) + 1;
2984 printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"),
2988 case DW_MACINFO_undef
:
2989 lineno
= read_leb128 (curr
, & bytes_read
, 0);
2991 string
= (char *) curr
;
2992 curr
+= strlen (string
) + 1;
2993 printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"),
2997 case DW_MACINFO_vendor_ext
:
2999 unsigned int constant
;
3001 constant
= read_leb128 (curr
, & bytes_read
, 0);
3003 string
= (char *) curr
;
3004 curr
+= strlen (string
) + 1;
3005 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"),
3016 display_debug_abbrev (struct dwarf_section
*section
,
3017 void *file ATTRIBUTE_UNUSED
)
3019 abbrev_entry
*entry
;
3020 unsigned char *start
= section
->start
;
3021 unsigned char *end
= start
+ section
->size
;
3023 printf (_("Contents of the %s section:\n\n"), section
->name
);
3029 start
= process_abbrev_section (start
, end
);
3031 if (first_abbrev
== NULL
)
3034 printf (_(" Number TAG\n"));
3036 for (entry
= first_abbrev
; entry
; entry
= entry
->next
)
3040 printf (_(" %ld %s [%s]\n"),
3042 get_TAG_name (entry
->tag
),
3043 entry
->children
? _("has children") : _("no children"));
3045 for (attr
= entry
->first_attr
; attr
; attr
= attr
->next
)
3046 printf (_(" %-18s %s\n"),
3047 get_AT_name (attr
->attribute
),
3048 get_FORM_name (attr
->form
));
3059 display_debug_loc (struct dwarf_section
*section
, void *file
)
3061 unsigned char *start
= section
->start
;
3062 unsigned char *section_end
;
3063 unsigned long bytes
;
3064 unsigned char *section_begin
= start
;
3065 unsigned int num_loc_list
= 0;
3066 unsigned long last_offset
= 0;
3067 unsigned int first
= 0;
3070 int seen_first_offset
= 0;
3071 int use_debug_info
= 1;
3072 unsigned char *next
;
3074 bytes
= section
->size
;
3075 section_end
= start
+ bytes
;
3079 printf (_("\nThe %s section is empty.\n"), section
->name
);
3083 if (load_debug_info (file
) == 0)
3085 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
3090 /* Check the order of location list in .debug_info section. If
3091 offsets of location lists are in the ascending order, we can
3092 use `debug_information' directly. */
3093 for (i
= 0; i
< num_debug_info_entries
; i
++)
3097 num
= debug_information
[i
].num_loc_offsets
;
3098 num_loc_list
+= num
;
3100 /* Check if we can use `debug_information' directly. */
3101 if (use_debug_info
&& num
!= 0)
3103 if (!seen_first_offset
)
3105 /* This is the first location list. */
3106 last_offset
= debug_information
[i
].loc_offsets
[0];
3108 seen_first_offset
= 1;
3114 for (; j
< num
; j
++)
3117 debug_information
[i
].loc_offsets
[j
])
3122 last_offset
= debug_information
[i
].loc_offsets
[j
];
3127 if (!use_debug_info
)
3128 /* FIXME: Should we handle this case? */
3129 error (_("Location lists in .debug_info section aren't in ascending order!\n"));
3131 if (!seen_first_offset
)
3132 error (_("No location lists in .debug_info section!\n"));
3134 /* DWARF sections under Mach-O have non-zero addresses. */
3135 if (debug_information
[first
].num_loc_offsets
> 0
3136 && debug_information
[first
].loc_offsets
[0] != section
->address
)
3137 warn (_("Location lists in %s section start at 0x%lx\n"),
3138 section
->name
, debug_information
[first
].loc_offsets
[0]);
3140 printf (_("Contents of the %s section:\n\n"), section
->name
);
3141 printf (_(" Offset Begin End Expression\n"));
3143 seen_first_offset
= 0;
3144 for (i
= first
; i
< num_debug_info_entries
; i
++)
3148 unsigned short length
;
3149 unsigned long offset
;
3150 unsigned int pointer_size
;
3151 unsigned long cu_offset
;
3152 unsigned long base_address
;
3153 int need_frame_base
;
3156 pointer_size
= debug_information
[i
].pointer_size
;
3157 cu_offset
= debug_information
[i
].cu_offset
;
3159 for (j
= 0; j
< debug_information
[i
].num_loc_offsets
; j
++)
3161 has_frame_base
= debug_information
[i
].have_frame_base
[j
];
3162 /* DWARF sections under Mach-O have non-zero addresses. */
3163 offset
= debug_information
[i
].loc_offsets
[j
] - section
->address
;
3164 next
= section_begin
+ offset
;
3165 base_address
= debug_information
[i
].base_address
;
3167 if (!seen_first_offset
)
3168 seen_first_offset
= 1;
3172 warn (_("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n"),
3173 (unsigned long) (start
- section_begin
),
3174 (unsigned long) (next
- section_begin
));
3175 else if (start
> next
)
3176 warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n"),
3177 (unsigned long) (start
- section_begin
),
3178 (unsigned long) (next
- section_begin
));
3182 if (offset
>= bytes
)
3184 warn (_("Offset 0x%lx is bigger than .debug_loc section size.\n"),
3191 if (start
+ 2 * pointer_size
> section_end
)
3193 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
3198 /* Note: we use sign extension here in order to be sure that
3199 we can detect the -1 escape value. Sign extension into the
3200 top 32 bits of a 32-bit address will not affect the values
3201 that we display since we always show hex values, and always
3202 the bottom 32-bits. */
3203 begin
= byte_get_signed (start
, pointer_size
);
3204 start
+= pointer_size
;
3205 end
= byte_get_signed (start
, pointer_size
);
3206 start
+= pointer_size
;
3208 printf (" %8.8lx ", offset
);
3210 if (begin
== 0 && end
== 0)
3212 printf (_("<End of list>\n"));
3216 /* Check base address specifiers. */
3217 if (begin
== (dwarf_vma
) -1 && end
!= (dwarf_vma
) -1)
3220 print_dwarf_vma (begin
, pointer_size
);
3221 print_dwarf_vma (end
, pointer_size
);
3222 printf (_("(base address)\n"));
3226 if (start
+ 2 > section_end
)
3228 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
3233 length
= byte_get (start
, 2);
3236 if (start
+ length
> section_end
)
3238 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
3243 print_dwarf_vma (begin
+ base_address
, pointer_size
);
3244 print_dwarf_vma (end
+ base_address
, pointer_size
);
3247 need_frame_base
= decode_location_expression (start
,
3250 cu_offset
, section
);
3253 if (need_frame_base
&& !has_frame_base
)
3254 printf (_(" [without DW_AT_frame_base]"));
3257 fputs (_(" (start == end)"), stdout
);
3258 else if (begin
> end
)
3259 fputs (_(" (start > end)"), stdout
);
3268 if (start
< section_end
)
3269 warn (_("There are %ld unused bytes at the end of section %s\n"),
3270 (long) (section_end
- start
), section
->name
);
3276 display_debug_str (struct dwarf_section
*section
,
3277 void *file ATTRIBUTE_UNUSED
)
3279 unsigned char *start
= section
->start
;
3280 unsigned long bytes
= section
->size
;
3281 dwarf_vma addr
= section
->address
;
3285 printf (_("\nThe %s section is empty.\n"), section
->name
);
3289 printf (_("Contents of the %s section:\n\n"), section
->name
);
3297 lbytes
= (bytes
> 16 ? 16 : bytes
);
3299 printf (" 0x%8.8lx ", (unsigned long) addr
);
3301 for (j
= 0; j
< 16; j
++)
3304 printf ("%2.2x", start
[j
]);
3312 for (j
= 0; j
< lbytes
; j
++)
3315 if (k
>= ' ' && k
< 0x80)
3334 display_debug_info (struct dwarf_section
*section
, void *file
)
3336 return process_debug_info (section
, file
, 0);
3341 display_debug_aranges (struct dwarf_section
*section
,
3342 void *file ATTRIBUTE_UNUSED
)
3344 unsigned char *start
= section
->start
;
3345 unsigned char *end
= start
+ section
->size
;
3347 printf (_("Contents of the %s section:\n\n"), section
->name
);
3349 /* It does not matter if this load fails,
3350 we test for that later on. */
3351 load_debug_info (file
);
3355 unsigned char *hdrptr
;
3356 DWARF2_Internal_ARange arange
;
3357 unsigned char *ranges
;
3360 unsigned char address_size
;
3363 int initial_length_size
;
3367 arange
.ar_length
= byte_get (hdrptr
, 4);
3370 if (arange
.ar_length
== 0xffffffff)
3372 arange
.ar_length
= byte_get (hdrptr
, 8);
3375 initial_length_size
= 12;
3380 initial_length_size
= 4;
3383 arange
.ar_version
= byte_get (hdrptr
, 2);
3386 arange
.ar_info_offset
= byte_get (hdrptr
, offset_size
);
3387 hdrptr
+= offset_size
;
3389 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
3390 && num_debug_info_entries
> 0
3391 && find_debug_info_for_offset (arange
.ar_info_offset
) == NULL
)
3392 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
3393 arange
.ar_info_offset
, section
->name
);
3395 arange
.ar_pointer_size
= byte_get (hdrptr
, 1);
3398 arange
.ar_segment_size
= byte_get (hdrptr
, 1);
3401 if (arange
.ar_version
!= 2 && arange
.ar_version
!= 3)
3403 warn (_("Only DWARF 2 and 3 aranges are currently supported.\n"));
3407 printf (_(" Length: %ld\n"), arange
.ar_length
);
3408 printf (_(" Version: %d\n"), arange
.ar_version
);
3409 printf (_(" Offset into .debug_info: 0x%lx\n"), arange
.ar_info_offset
);
3410 printf (_(" Pointer Size: %d\n"), arange
.ar_pointer_size
);
3411 printf (_(" Segment Size: %d\n"), arange
.ar_segment_size
);
3413 address_size
= arange
.ar_pointer_size
+ arange
.ar_segment_size
;
3415 /* The DWARF spec does not require that the address size be a power
3416 of two, but we do. This will have to change if we ever encounter
3417 an uneven architecture. */
3418 if ((address_size
& (address_size
- 1)) != 0)
3420 warn (_("Pointer size + Segment size is not a power of two.\n"));
3424 if (address_size
> 4)
3425 printf (_("\n Address Length\n"));
3427 printf (_("\n Address Length\n"));
3431 /* Must pad to an alignment boundary that is twice the address size. */
3432 excess
= (hdrptr
- start
) % (2 * address_size
);
3434 ranges
+= (2 * address_size
) - excess
;
3436 start
+= arange
.ar_length
+ initial_length_size
;
3438 while (ranges
+ 2 * address_size
<= start
)
3440 address
= byte_get (ranges
, address_size
);
3442 ranges
+= address_size
;
3444 length
= byte_get (ranges
, address_size
);
3446 ranges
+= address_size
;
3449 print_dwarf_vma (address
, address_size
);
3450 print_dwarf_vma (length
, address_size
);
3461 display_debug_ranges (struct dwarf_section
*section
,
3462 void *file ATTRIBUTE_UNUSED
)
3464 unsigned char *start
= section
->start
;
3465 unsigned char *section_end
;
3466 unsigned long bytes
;
3467 unsigned char *section_begin
= start
;
3468 unsigned int num_range_list
= 0;
3469 unsigned long last_offset
= 0;
3470 unsigned int first
= 0;
3473 int seen_first_offset
= 0;
3474 int use_debug_info
= 1;
3475 unsigned char *next
;
3477 bytes
= section
->size
;
3478 section_end
= start
+ bytes
;
3482 printf (_("\nThe %s section is empty.\n"), section
->name
);
3486 if (load_debug_info (file
) == 0)
3488 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
3493 /* Check the order of range list in .debug_info section. If
3494 offsets of range lists are in the ascending order, we can
3495 use `debug_information' directly. */
3496 for (i
= 0; i
< num_debug_info_entries
; i
++)
3500 num
= debug_information
[i
].num_range_lists
;
3501 num_range_list
+= num
;
3503 /* Check if we can use `debug_information' directly. */
3504 if (use_debug_info
&& num
!= 0)
3506 if (!seen_first_offset
)
3508 /* This is the first range list. */
3509 last_offset
= debug_information
[i
].range_lists
[0];
3511 seen_first_offset
= 1;
3517 for (; j
< num
; j
++)
3520 debug_information
[i
].range_lists
[j
])
3525 last_offset
= debug_information
[i
].range_lists
[j
];
3530 if (!use_debug_info
)
3531 /* FIXME: Should we handle this case? */
3532 error (_("Range lists in .debug_info section aren't in ascending order!\n"));
3534 if (!seen_first_offset
)
3535 error (_("No range lists in .debug_info section!\n"));
3537 /* DWARF sections under Mach-O have non-zero addresses. */
3538 if (debug_information
[first
].num_range_lists
> 0
3539 && debug_information
[first
].range_lists
[0] != section
->address
)
3540 warn (_("Range lists in %s section start at 0x%lx\n"),
3541 section
->name
, debug_information
[first
].range_lists
[0]);
3543 printf (_("Contents of the %s section:\n\n"), section
->name
);
3544 printf (_(" Offset Begin End\n"));
3546 seen_first_offset
= 0;
3547 for (i
= first
; i
< num_debug_info_entries
; i
++)
3551 unsigned long offset
;
3552 unsigned int pointer_size
;
3553 unsigned long base_address
;
3555 pointer_size
= debug_information
[i
].pointer_size
;
3557 for (j
= 0; j
< debug_information
[i
].num_range_lists
; j
++)
3559 /* DWARF sections under Mach-O have non-zero addresses. */
3560 offset
= debug_information
[i
].range_lists
[j
] - section
->address
;
3561 next
= section_begin
+ offset
;
3562 base_address
= debug_information
[i
].base_address
;
3564 if (!seen_first_offset
)
3565 seen_first_offset
= 1;
3569 warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"),
3570 (unsigned long) (start
- section_begin
),
3571 (unsigned long) (next
- section_begin
), section
->name
);
3572 else if (start
> next
)
3573 warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"),
3574 (unsigned long) (start
- section_begin
),
3575 (unsigned long) (next
- section_begin
), section
->name
);
3581 /* Note: we use sign extension here in order to be sure that
3582 we can detect the -1 escape value. Sign extension into the
3583 top 32 bits of a 32-bit address will not affect the values
3584 that we display since we always show hex values, and always
3585 the bottom 32-bits. */
3586 begin
= byte_get_signed (start
, pointer_size
);
3587 start
+= pointer_size
;
3588 end
= byte_get_signed (start
, pointer_size
);
3589 start
+= pointer_size
;
3591 printf (" %8.8lx ", offset
);
3593 if (begin
== 0 && end
== 0)
3595 printf (_("<End of list>\n"));
3599 /* Check base address specifiers. */
3600 if (begin
== (dwarf_vma
) -1 && end
!= (dwarf_vma
) -1)
3603 print_dwarf_vma (begin
, pointer_size
);
3604 print_dwarf_vma (end
, pointer_size
);
3605 printf ("(base address)\n");
3609 print_dwarf_vma (begin
+ base_address
, pointer_size
);
3610 print_dwarf_vma (end
+ base_address
, pointer_size
);
3613 fputs (_("(start == end)"), stdout
);
3614 else if (begin
> end
)
3615 fputs (_("(start > end)"), stdout
);
3625 typedef struct Frame_Chunk
3627 struct Frame_Chunk
*next
;
3628 unsigned char *chunk_start
;
3630 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
3631 short int *col_type
;
3634 unsigned int code_factor
;
3636 unsigned long pc_begin
;
3637 unsigned long pc_range
;
3641 unsigned char fde_encoding
;
3642 unsigned char cfa_exp
;
3646 static const char *const *dwarf_regnames
;
3647 static unsigned int dwarf_regnames_count
;
3649 /* A marker for a col_type that means this column was never referenced
3650 in the frame info. */
3651 #define DW_CFA_unreferenced (-1)
3653 /* Return 0 if not more space is needed, 1 if more space is needed,
3654 -1 for invalid reg. */
3657 frame_need_space (Frame_Chunk
*fc
, unsigned int reg
)
3659 int prev
= fc
->ncols
;
3661 if (reg
< (unsigned int) fc
->ncols
)
3664 if (dwarf_regnames_count
3665 && reg
> dwarf_regnames_count
)
3668 fc
->ncols
= reg
+ 1;
3669 fc
->col_type
= xcrealloc (fc
->col_type
, fc
->ncols
, sizeof (short int));
3670 fc
->col_offset
= xcrealloc (fc
->col_offset
, fc
->ncols
, sizeof (int));
3672 while (prev
< fc
->ncols
)
3674 fc
->col_type
[prev
] = DW_CFA_unreferenced
;
3675 fc
->col_offset
[prev
] = 0;
3681 static const char *const dwarf_regnames_i386
[] =
3683 "eax", "ecx", "edx", "ebx",
3684 "esp", "ebp", "esi", "edi",
3685 "eip", "eflags", NULL
,
3686 "st0", "st1", "st2", "st3",
3687 "st4", "st5", "st6", "st7",
3689 "xmm0", "xmm1", "xmm2", "xmm3",
3690 "xmm4", "xmm5", "xmm6", "xmm7",
3691 "mm0", "mm1", "mm2", "mm3",
3692 "mm4", "mm5", "mm6", "mm7",
3693 "fcw", "fsw", "mxcsr",
3694 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
,
3698 static const char *const dwarf_regnames_x86_64
[] =
3700 "rax", "rdx", "rcx", "rbx",
3701 "rsi", "rdi", "rbp", "rsp",
3702 "r8", "r9", "r10", "r11",
3703 "r12", "r13", "r14", "r15",
3705 "xmm0", "xmm1", "xmm2", "xmm3",
3706 "xmm4", "xmm5", "xmm6", "xmm7",
3707 "xmm8", "xmm9", "xmm10", "xmm11",
3708 "xmm12", "xmm13", "xmm14", "xmm15",
3709 "st0", "st1", "st2", "st3",
3710 "st4", "st5", "st6", "st7",
3711 "mm0", "mm1", "mm2", "mm3",
3712 "mm4", "mm5", "mm6", "mm7",
3714 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
,
3715 "fs.base", "gs.base", NULL
, NULL
,
3717 "mxcsr", "fcw", "fsw"
3721 init_dwarf_regnames (unsigned int e_machine
)
3727 dwarf_regnames
= dwarf_regnames_i386
;
3728 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_i386
);
3732 dwarf_regnames
= dwarf_regnames_x86_64
;
3733 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_x86_64
);
3742 regname (unsigned int regno
, int row
)
3744 static char reg
[64];
3746 && regno
< dwarf_regnames_count
3747 && dwarf_regnames
[regno
] != NULL
)
3750 return dwarf_regnames
[regno
];
3751 snprintf (reg
, sizeof (reg
), "r%d (%s)", regno
,
3752 dwarf_regnames
[regno
]);
3755 snprintf (reg
, sizeof (reg
), "r%d", regno
);
3760 frame_display_row (Frame_Chunk
*fc
, int *need_col_headers
, int *max_regs
)
3765 if (*max_regs
< fc
->ncols
)
3766 *max_regs
= fc
->ncols
;
3768 if (*need_col_headers
)
3770 static const char *loc
= " LOC";
3772 *need_col_headers
= 0;
3774 printf ("%-*s CFA ", eh_addr_size
* 2, loc
);
3776 for (r
= 0; r
< *max_regs
; r
++)
3777 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
3782 printf ("%-5s ", regname (r
, 1));
3788 printf ("%0*lx ", eh_addr_size
* 2, fc
->pc_begin
);
3790 strcpy (tmp
, "exp");
3792 sprintf (tmp
, "%s%+d", regname (fc
->cfa_reg
, 1), fc
->cfa_offset
);
3793 printf ("%-8s ", tmp
);
3795 for (r
= 0; r
< fc
->ncols
; r
++)
3797 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
3799 switch (fc
->col_type
[r
])
3801 case DW_CFA_undefined
:
3804 case DW_CFA_same_value
:
3808 sprintf (tmp
, "c%+d", fc
->col_offset
[r
]);
3810 case DW_CFA_val_offset
:
3811 sprintf (tmp
, "v%+d", fc
->col_offset
[r
]);
3813 case DW_CFA_register
:
3814 sprintf (tmp
, "%s", regname (fc
->col_offset
[r
], 0));
3816 case DW_CFA_expression
:
3817 strcpy (tmp
, "exp");
3819 case DW_CFA_val_expression
:
3820 strcpy (tmp
, "vexp");
3823 strcpy (tmp
, "n/a");
3826 printf ("%-5s ", tmp
);
3832 #define GET(N) byte_get (start, N); start += N
3833 #define LEB() read_leb128 (start, & length_return, 0); start += length_return
3834 #define SLEB() read_leb128 (start, & length_return, 1); start += length_return
3837 display_debug_frames (struct dwarf_section
*section
,
3838 void *file ATTRIBUTE_UNUSED
)
3840 unsigned char *start
= section
->start
;
3841 unsigned char *end
= start
+ section
->size
;
3842 unsigned char *section_start
= start
;
3843 Frame_Chunk
*chunks
= 0;
3844 Frame_Chunk
*remembered_state
= 0;
3846 int is_eh
= strcmp (section
->name
, ".eh_frame") == 0;
3847 unsigned int length_return
;
3849 const char *bad_reg
= _("bad register: ");
3851 printf (_("Contents of the %s section:\n"), section
->name
);
3855 unsigned char *saved_start
;
3856 unsigned char *block_end
;
3857 unsigned long length
;
3858 unsigned long cie_id
;
3861 int need_col_headers
= 1;
3862 unsigned char *augmentation_data
= NULL
;
3863 unsigned long augmentation_data_len
= 0;
3864 int encoded_ptr_size
= eh_addr_size
;
3866 int initial_length_size
;
3868 saved_start
= start
;
3869 length
= byte_get (start
, 4); start
+= 4;
3873 printf ("\n%08lx ZERO terminator\n\n",
3874 (unsigned long)(saved_start
- section_start
));
3878 if (length
== 0xffffffff)
3880 length
= byte_get (start
, 8);
3883 initial_length_size
= 12;
3888 initial_length_size
= 4;
3891 block_end
= saved_start
+ length
+ initial_length_size
;
3892 if (block_end
> end
)
3894 warn ("Invalid length %#08lx in FDE at %#08lx\n",
3895 length
, (unsigned long)(saved_start
- section_start
));
3898 cie_id
= byte_get (start
, offset_size
); start
+= offset_size
;
3900 if (is_eh
? (cie_id
== 0) : (cie_id
== DW_CIE_ID
))
3904 fc
= xmalloc (sizeof (Frame_Chunk
));
3905 memset (fc
, 0, sizeof (Frame_Chunk
));
3909 fc
->chunk_start
= saved_start
;
3911 fc
->col_type
= xmalloc (sizeof (short int));
3912 fc
->col_offset
= xmalloc (sizeof (int));
3913 frame_need_space (fc
, max_regs
- 1);
3917 fc
->augmentation
= (char *) start
;
3918 start
= (unsigned char *) strchr ((char *) start
, '\0') + 1;
3920 if (fc
->augmentation
[0] == 'z')
3922 fc
->code_factor
= LEB ();
3923 fc
->data_factor
= SLEB ();
3932 augmentation_data_len
= LEB ();
3933 augmentation_data
= start
;
3934 start
+= augmentation_data_len
;
3936 else if (strcmp (fc
->augmentation
, "eh") == 0)
3938 start
+= eh_addr_size
;
3939 fc
->code_factor
= LEB ();
3940 fc
->data_factor
= SLEB ();
3952 fc
->code_factor
= LEB ();
3953 fc
->data_factor
= SLEB ();
3965 if (do_debug_frames_interp
)
3966 printf ("\n%08lx %08lx %08lx CIE \"%s\" cf=%d df=%d ra=%d\n",
3967 (unsigned long)(saved_start
- section_start
), length
, cie_id
,
3968 fc
->augmentation
, fc
->code_factor
, fc
->data_factor
,
3972 printf ("\n%08lx %08lx %08lx CIE\n",
3973 (unsigned long)(saved_start
- section_start
), length
, cie_id
);
3974 printf (" Version: %d\n", version
);
3975 printf (" Augmentation: \"%s\"\n", fc
->augmentation
);
3976 printf (" Code alignment factor: %u\n", fc
->code_factor
);
3977 printf (" Data alignment factor: %d\n", fc
->data_factor
);
3978 printf (" Return address column: %d\n", fc
->ra
);
3980 if (augmentation_data_len
)
3983 printf (" Augmentation data: ");
3984 for (i
= 0; i
< augmentation_data_len
; ++i
)
3985 printf (" %02x", augmentation_data
[i
]);
3991 if (augmentation_data_len
)
3993 unsigned char *p
, *q
;
3994 p
= (unsigned char *) fc
->augmentation
+ 1;
3995 q
= augmentation_data
;
4002 q
+= 1 + size_of_encoded_value (*q
);
4004 fc
->fde_encoding
= *q
++;
4010 if (fc
->fde_encoding
)
4011 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
4014 frame_need_space (fc
, fc
->ra
);
4018 unsigned char *look_for
;
4019 static Frame_Chunk fde_fc
;
4022 memset (fc
, 0, sizeof (Frame_Chunk
));
4024 look_for
= is_eh
? start
- 4 - cie_id
: section_start
+ cie_id
;
4026 for (cie
= chunks
; cie
; cie
= cie
->next
)
4027 if (cie
->chunk_start
== look_for
)
4032 warn ("Invalid CIE pointer %#08lx in FDE at %#08lx\n",
4033 cie_id
, (unsigned long)(saved_start
- section_start
));
4035 fc
->col_type
= xmalloc (sizeof (short int));
4036 fc
->col_offset
= xmalloc (sizeof (int));
4037 frame_need_space (fc
, max_regs
- 1);
4039 fc
->augmentation
= "";
4040 fc
->fde_encoding
= 0;
4044 fc
->ncols
= cie
->ncols
;
4045 fc
->col_type
= xcmalloc (fc
->ncols
, sizeof (short int));
4046 fc
->col_offset
= xcmalloc (fc
->ncols
, sizeof (int));
4047 memcpy (fc
->col_type
, cie
->col_type
, fc
->ncols
* sizeof (short int));
4048 memcpy (fc
->col_offset
, cie
->col_offset
, fc
->ncols
* sizeof (int));
4049 fc
->augmentation
= cie
->augmentation
;
4050 fc
->code_factor
= cie
->code_factor
;
4051 fc
->data_factor
= cie
->data_factor
;
4052 fc
->cfa_reg
= cie
->cfa_reg
;
4053 fc
->cfa_offset
= cie
->cfa_offset
;
4055 frame_need_space (fc
, max_regs
- 1);
4056 fc
->fde_encoding
= cie
->fde_encoding
;
4059 if (fc
->fde_encoding
)
4060 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
4062 fc
->pc_begin
= get_encoded_value (start
, fc
->fde_encoding
);
4063 if ((fc
->fde_encoding
& 0x70) == DW_EH_PE_pcrel
)
4064 fc
->pc_begin
+= section
->address
+ (start
- section_start
);
4065 start
+= encoded_ptr_size
;
4066 fc
->pc_range
= byte_get (start
, encoded_ptr_size
);
4067 start
+= encoded_ptr_size
;
4069 if (cie
->augmentation
[0] == 'z')
4071 augmentation_data_len
= LEB ();
4072 augmentation_data
= start
;
4073 start
+= augmentation_data_len
;
4076 printf ("\n%08lx %08lx %08lx FDE cie=%08lx pc=%08lx..%08lx\n",
4077 (unsigned long)(saved_start
- section_start
), length
, cie_id
,
4078 (unsigned long)(cie
->chunk_start
- section_start
),
4079 fc
->pc_begin
, fc
->pc_begin
+ fc
->pc_range
);
4080 if (! do_debug_frames_interp
&& augmentation_data_len
)
4084 printf (" Augmentation data: ");
4085 for (i
= 0; i
< augmentation_data_len
; ++i
)
4086 printf (" %02x", augmentation_data
[i
]);
4092 /* At this point, fc is the current chunk, cie (if any) is set, and
4093 we're about to interpret instructions for the chunk. */
4094 /* ??? At present we need to do this always, since this sizes the
4095 fc->col_type and fc->col_offset arrays, which we write into always.
4096 We should probably split the interpreted and non-interpreted bits
4097 into two different routines, since there's so much that doesn't
4098 really overlap between them. */
4099 if (1 || do_debug_frames_interp
)
4101 /* Start by making a pass over the chunk, allocating storage
4102 and taking note of what registers are used. */
4103 unsigned char *tmp
= start
;
4105 while (start
< block_end
)
4108 unsigned long reg
, tmp
;
4115 /* Warning: if you add any more cases to this switch, be
4116 sure to add them to the corresponding switch below. */
4119 case DW_CFA_advance_loc
:
4123 if (frame_need_space (fc
, opa
) >= 0)
4124 fc
->col_type
[opa
] = DW_CFA_undefined
;
4126 case DW_CFA_restore
:
4127 if (frame_need_space (fc
, opa
) >= 0)
4128 fc
->col_type
[opa
] = DW_CFA_undefined
;
4130 case DW_CFA_set_loc
:
4131 start
+= encoded_ptr_size
;
4133 case DW_CFA_advance_loc1
:
4136 case DW_CFA_advance_loc2
:
4139 case DW_CFA_advance_loc4
:
4142 case DW_CFA_offset_extended
:
4143 case DW_CFA_val_offset
:
4144 reg
= LEB (); LEB ();
4145 if (frame_need_space (fc
, reg
) >= 0)
4146 fc
->col_type
[reg
] = DW_CFA_undefined
;
4148 case DW_CFA_restore_extended
:
4150 frame_need_space (fc
, reg
);
4151 if (frame_need_space (fc
, reg
) >= 0)
4152 fc
->col_type
[reg
] = DW_CFA_undefined
;
4154 case DW_CFA_undefined
:
4156 if (frame_need_space (fc
, reg
) >= 0)
4157 fc
->col_type
[reg
] = DW_CFA_undefined
;
4159 case DW_CFA_same_value
:
4161 if (frame_need_space (fc
, reg
) >= 0)
4162 fc
->col_type
[reg
] = DW_CFA_undefined
;
4164 case DW_CFA_register
:
4165 reg
= LEB (); LEB ();
4166 if (frame_need_space (fc
, reg
) >= 0)
4167 fc
->col_type
[reg
] = DW_CFA_undefined
;
4169 case DW_CFA_def_cfa
:
4172 case DW_CFA_def_cfa_register
:
4175 case DW_CFA_def_cfa_offset
:
4178 case DW_CFA_def_cfa_expression
:
4182 case DW_CFA_expression
:
4183 case DW_CFA_val_expression
:
4187 if (frame_need_space (fc
, reg
) >= 0)
4188 fc
->col_type
[reg
] = DW_CFA_undefined
;
4190 case DW_CFA_offset_extended_sf
:
4191 case DW_CFA_val_offset_sf
:
4192 reg
= LEB (); SLEB ();
4193 if (frame_need_space (fc
, reg
) >= 0)
4194 fc
->col_type
[reg
] = DW_CFA_undefined
;
4196 case DW_CFA_def_cfa_sf
:
4199 case DW_CFA_def_cfa_offset_sf
:
4202 case DW_CFA_MIPS_advance_loc8
:
4205 case DW_CFA_GNU_args_size
:
4208 case DW_CFA_GNU_negative_offset_extended
:
4209 reg
= LEB (); LEB ();
4210 if (frame_need_space (fc
, reg
) >= 0)
4211 fc
->col_type
[reg
] = DW_CFA_undefined
;
4220 /* Now we know what registers are used, make a second pass over
4221 the chunk, this time actually printing out the info. */
4223 while (start
< block_end
)
4226 unsigned long ul
, reg
, roffs
;
4229 const char *reg_prefix
= "";
4236 /* Warning: if you add any more cases to this switch, be
4237 sure to add them to the corresponding switch above. */
4240 case DW_CFA_advance_loc
:
4241 if (do_debug_frames_interp
)
4242 frame_display_row (fc
, &need_col_headers
, &max_regs
);
4244 printf (" DW_CFA_advance_loc: %d to %08lx\n",
4245 opa
* fc
->code_factor
,
4246 fc
->pc_begin
+ opa
* fc
->code_factor
);
4247 fc
->pc_begin
+= opa
* fc
->code_factor
;
4252 if (opa
>= (unsigned int) fc
->ncols
)
4253 reg_prefix
= bad_reg
;
4254 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4255 printf (" DW_CFA_offset: %s%s at cfa%+ld\n",
4256 reg_prefix
, regname (opa
, 0),
4257 roffs
* fc
->data_factor
);
4258 if (*reg_prefix
== '\0')
4260 fc
->col_type
[opa
] = DW_CFA_offset
;
4261 fc
->col_offset
[opa
] = roffs
* fc
->data_factor
;
4265 case DW_CFA_restore
:
4266 if (opa
>= (unsigned int) cie
->ncols
4267 || opa
>= (unsigned int) fc
->ncols
)
4268 reg_prefix
= bad_reg
;
4269 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4270 printf (" DW_CFA_restore: %s%s\n",
4271 reg_prefix
, regname (opa
, 0));
4272 if (*reg_prefix
== '\0')
4274 fc
->col_type
[opa
] = cie
->col_type
[opa
];
4275 fc
->col_offset
[opa
] = cie
->col_offset
[opa
];
4279 case DW_CFA_set_loc
:
4280 vma
= get_encoded_value (start
, fc
->fde_encoding
);
4281 if ((fc
->fde_encoding
& 0x70) == DW_EH_PE_pcrel
)
4282 vma
+= section
->address
+ (start
- section_start
);
4283 start
+= encoded_ptr_size
;
4284 if (do_debug_frames_interp
)
4285 frame_display_row (fc
, &need_col_headers
, &max_regs
);
4287 printf (" DW_CFA_set_loc: %08lx\n", (unsigned long)vma
);
4291 case DW_CFA_advance_loc1
:
4292 ofs
= byte_get (start
, 1); start
+= 1;
4293 if (do_debug_frames_interp
)
4294 frame_display_row (fc
, &need_col_headers
, &max_regs
);
4296 printf (" DW_CFA_advance_loc1: %ld to %08lx\n",
4297 ofs
* fc
->code_factor
,
4298 fc
->pc_begin
+ ofs
* fc
->code_factor
);
4299 fc
->pc_begin
+= ofs
* fc
->code_factor
;
4302 case DW_CFA_advance_loc2
:
4303 ofs
= byte_get (start
, 2); start
+= 2;
4304 if (do_debug_frames_interp
)
4305 frame_display_row (fc
, &need_col_headers
, &max_regs
);
4307 printf (" DW_CFA_advance_loc2: %ld to %08lx\n",
4308 ofs
* fc
->code_factor
,
4309 fc
->pc_begin
+ ofs
* fc
->code_factor
);
4310 fc
->pc_begin
+= ofs
* fc
->code_factor
;
4313 case DW_CFA_advance_loc4
:
4314 ofs
= byte_get (start
, 4); start
+= 4;
4315 if (do_debug_frames_interp
)
4316 frame_display_row (fc
, &need_col_headers
, &max_regs
);
4318 printf (" DW_CFA_advance_loc4: %ld to %08lx\n",
4319 ofs
* fc
->code_factor
,
4320 fc
->pc_begin
+ ofs
* fc
->code_factor
);
4321 fc
->pc_begin
+= ofs
* fc
->code_factor
;
4324 case DW_CFA_offset_extended
:
4327 if (reg
>= (unsigned int) fc
->ncols
)
4328 reg_prefix
= bad_reg
;
4329 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4330 printf (" DW_CFA_offset_extended: %s%s at cfa%+ld\n",
4331 reg_prefix
, regname (reg
, 0),
4332 roffs
* fc
->data_factor
);
4333 if (*reg_prefix
== '\0')
4335 fc
->col_type
[reg
] = DW_CFA_offset
;
4336 fc
->col_offset
[reg
] = roffs
* fc
->data_factor
;
4340 case DW_CFA_val_offset
:
4343 if (reg
>= (unsigned int) fc
->ncols
)
4344 reg_prefix
= bad_reg
;
4345 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4346 printf (" DW_CFA_val_offset: %s%s at cfa%+ld\n",
4347 reg_prefix
, regname (reg
, 0),
4348 roffs
* fc
->data_factor
);
4349 if (*reg_prefix
== '\0')
4351 fc
->col_type
[reg
] = DW_CFA_val_offset
;
4352 fc
->col_offset
[reg
] = roffs
* fc
->data_factor
;
4356 case DW_CFA_restore_extended
:
4358 if (reg
>= (unsigned int) cie
->ncols
4359 || reg
>= (unsigned int) fc
->ncols
)
4360 reg_prefix
= bad_reg
;
4361 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4362 printf (" DW_CFA_restore_extended: %s%s\n",
4363 reg_prefix
, regname (reg
, 0));
4364 if (*reg_prefix
== '\0')
4366 fc
->col_type
[reg
] = cie
->col_type
[reg
];
4367 fc
->col_offset
[reg
] = cie
->col_offset
[reg
];
4371 case DW_CFA_undefined
:
4373 if (reg
>= (unsigned int) fc
->ncols
)
4374 reg_prefix
= bad_reg
;
4375 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4376 printf (" DW_CFA_undefined: %s%s\n",
4377 reg_prefix
, regname (reg
, 0));
4378 if (*reg_prefix
== '\0')
4380 fc
->col_type
[reg
] = DW_CFA_undefined
;
4381 fc
->col_offset
[reg
] = 0;
4385 case DW_CFA_same_value
:
4387 if (reg
>= (unsigned int) fc
->ncols
)
4388 reg_prefix
= bad_reg
;
4389 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4390 printf (" DW_CFA_same_value: %s%s\n",
4391 reg_prefix
, regname (reg
, 0));
4392 if (*reg_prefix
== '\0')
4394 fc
->col_type
[reg
] = DW_CFA_same_value
;
4395 fc
->col_offset
[reg
] = 0;
4399 case DW_CFA_register
:
4402 if (reg
>= (unsigned int) fc
->ncols
)
4403 reg_prefix
= bad_reg
;
4404 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4406 printf (" DW_CFA_register: %s%s in ",
4407 reg_prefix
, regname (reg
, 0));
4408 puts (regname (roffs
, 0));
4410 if (*reg_prefix
== '\0')
4412 fc
->col_type
[reg
] = DW_CFA_register
;
4413 fc
->col_offset
[reg
] = roffs
;
4417 case DW_CFA_remember_state
:
4418 if (! do_debug_frames_interp
)
4419 printf (" DW_CFA_remember_state\n");
4420 rs
= xmalloc (sizeof (Frame_Chunk
));
4421 rs
->ncols
= fc
->ncols
;
4422 rs
->col_type
= xcmalloc (rs
->ncols
, sizeof (short int));
4423 rs
->col_offset
= xcmalloc (rs
->ncols
, sizeof (int));
4424 memcpy (rs
->col_type
, fc
->col_type
, rs
->ncols
);
4425 memcpy (rs
->col_offset
, fc
->col_offset
, rs
->ncols
* sizeof (int));
4426 rs
->next
= remembered_state
;
4427 remembered_state
= rs
;
4430 case DW_CFA_restore_state
:
4431 if (! do_debug_frames_interp
)
4432 printf (" DW_CFA_restore_state\n");
4433 rs
= remembered_state
;
4436 remembered_state
= rs
->next
;
4437 frame_need_space (fc
, rs
->ncols
- 1);
4438 memcpy (fc
->col_type
, rs
->col_type
, rs
->ncols
);
4439 memcpy (fc
->col_offset
, rs
->col_offset
,
4440 rs
->ncols
* sizeof (int));
4441 free (rs
->col_type
);
4442 free (rs
->col_offset
);
4445 else if (do_debug_frames_interp
)
4446 printf ("Mismatched DW_CFA_restore_state\n");
4449 case DW_CFA_def_cfa
:
4450 fc
->cfa_reg
= LEB ();
4451 fc
->cfa_offset
= LEB ();
4453 if (! do_debug_frames_interp
)
4454 printf (" DW_CFA_def_cfa: %s ofs %d\n",
4455 regname (fc
->cfa_reg
, 0), fc
->cfa_offset
);
4458 case DW_CFA_def_cfa_register
:
4459 fc
->cfa_reg
= LEB ();
4461 if (! do_debug_frames_interp
)
4462 printf (" DW_CFA_def_cfa_register: %s\n",
4463 regname (fc
->cfa_reg
, 0));
4466 case DW_CFA_def_cfa_offset
:
4467 fc
->cfa_offset
= LEB ();
4468 if (! do_debug_frames_interp
)
4469 printf (" DW_CFA_def_cfa_offset: %d\n", fc
->cfa_offset
);
4473 if (! do_debug_frames_interp
)
4474 printf (" DW_CFA_nop\n");
4477 case DW_CFA_def_cfa_expression
:
4479 if (! do_debug_frames_interp
)
4481 printf (" DW_CFA_def_cfa_expression (");
4482 decode_location_expression (start
, eh_addr_size
, ul
, 0,
4490 case DW_CFA_expression
:
4493 if (reg
>= (unsigned int) fc
->ncols
)
4494 reg_prefix
= bad_reg
;
4495 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4497 printf (" DW_CFA_expression: %s%s (",
4498 reg_prefix
, regname (reg
, 0));
4499 decode_location_expression (start
, eh_addr_size
,
4503 if (*reg_prefix
== '\0')
4504 fc
->col_type
[reg
] = DW_CFA_expression
;
4508 case DW_CFA_val_expression
:
4511 if (reg
>= (unsigned int) fc
->ncols
)
4512 reg_prefix
= bad_reg
;
4513 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4515 printf (" DW_CFA_val_expression: %s%s (",
4516 reg_prefix
, regname (reg
, 0));
4517 decode_location_expression (start
, eh_addr_size
, ul
, 0,
4521 if (*reg_prefix
== '\0')
4522 fc
->col_type
[reg
] = DW_CFA_val_expression
;
4526 case DW_CFA_offset_extended_sf
:
4529 if (frame_need_space (fc
, reg
) < 0)
4530 reg_prefix
= bad_reg
;
4531 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4532 printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+ld\n",
4533 reg_prefix
, regname (reg
, 0),
4534 l
* fc
->data_factor
);
4535 if (*reg_prefix
== '\0')
4537 fc
->col_type
[reg
] = DW_CFA_offset
;
4538 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
4542 case DW_CFA_val_offset_sf
:
4545 if (frame_need_space (fc
, reg
) < 0)
4546 reg_prefix
= bad_reg
;
4547 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4548 printf (" DW_CFA_val_offset_sf: %s%s at cfa%+ld\n",
4549 reg_prefix
, regname (reg
, 0),
4550 l
* fc
->data_factor
);
4551 if (*reg_prefix
== '\0')
4553 fc
->col_type
[reg
] = DW_CFA_val_offset
;
4554 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
4558 case DW_CFA_def_cfa_sf
:
4559 fc
->cfa_reg
= LEB ();
4560 fc
->cfa_offset
= SLEB ();
4561 fc
->cfa_offset
= fc
->cfa_offset
* fc
->data_factor
;
4563 if (! do_debug_frames_interp
)
4564 printf (" DW_CFA_def_cfa_sf: %s ofs %d\n",
4565 regname (fc
->cfa_reg
, 0), fc
->cfa_offset
);
4568 case DW_CFA_def_cfa_offset_sf
:
4569 fc
->cfa_offset
= SLEB ();
4570 fc
->cfa_offset
= fc
->cfa_offset
* fc
->data_factor
;
4571 if (! do_debug_frames_interp
)
4572 printf (" DW_CFA_def_cfa_offset_sf: %d\n", fc
->cfa_offset
);
4575 case DW_CFA_MIPS_advance_loc8
:
4576 ofs
= byte_get (start
, 8); start
+= 8;
4577 if (do_debug_frames_interp
)
4578 frame_display_row (fc
, &need_col_headers
, &max_regs
);
4580 printf (" DW_CFA_MIPS_advance_loc8: %ld to %08lx\n",
4581 ofs
* fc
->code_factor
,
4582 fc
->pc_begin
+ ofs
* fc
->code_factor
);
4583 fc
->pc_begin
+= ofs
* fc
->code_factor
;
4586 case DW_CFA_GNU_window_save
:
4587 if (! do_debug_frames_interp
)
4588 printf (" DW_CFA_GNU_window_save\n");
4591 case DW_CFA_GNU_args_size
:
4593 if (! do_debug_frames_interp
)
4594 printf (" DW_CFA_GNU_args_size: %ld\n", ul
);
4597 case DW_CFA_GNU_negative_offset_extended
:
4600 if (frame_need_space (fc
, reg
) < 0)
4601 reg_prefix
= bad_reg
;
4602 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4603 printf (" DW_CFA_GNU_negative_offset_extended: %s%s at cfa%+ld\n",
4604 reg_prefix
, regname (reg
, 0),
4605 l
* fc
->data_factor
);
4606 if (*reg_prefix
== '\0')
4608 fc
->col_type
[reg
] = DW_CFA_offset
;
4609 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
4614 if (op
>= DW_CFA_lo_user
&& op
<= DW_CFA_hi_user
)
4615 printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op
);
4617 warn (_("unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op
);
4622 if (do_debug_frames_interp
)
4623 frame_display_row (fc
, &need_col_headers
, &max_regs
);
4638 display_debug_not_supported (struct dwarf_section
*section
,
4639 void *file ATTRIBUTE_UNUSED
)
4641 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
4648 cmalloc (size_t nmemb
, size_t size
)
4650 /* Check for overflow. */
4651 if (nmemb
>= ~(size_t) 0 / size
)
4654 return malloc (nmemb
* size
);
4658 xcmalloc (size_t nmemb
, size_t size
)
4660 /* Check for overflow. */
4661 if (nmemb
>= ~(size_t) 0 / size
)
4664 return xmalloc (nmemb
* size
);
4668 xcrealloc (void *ptr
, size_t nmemb
, size_t size
)
4670 /* Check for overflow. */
4671 if (nmemb
>= ~(size_t) 0 / size
)
4674 return xrealloc (ptr
, nmemb
* size
);
4678 error (const char *message
, ...)
4682 va_start (args
, message
);
4683 fprintf (stderr
, _("%s: Error: "), program_name
);
4684 vfprintf (stderr
, message
, args
);
4689 warn (const char *message
, ...)
4693 va_start (args
, message
);
4694 fprintf (stderr
, _("%s: Warning: "), program_name
);
4695 vfprintf (stderr
, message
, args
);
4700 free_debug_memory (void)
4702 enum dwarf_section_display_enum i
;
4706 for (i
= 0; i
< max
; i
++)
4707 free_debug_section (i
);
4709 if (debug_information
!= NULL
)
4711 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
)
4713 for (i
= 0; i
< num_debug_info_entries
; i
++)
4715 if (!debug_information
[i
].max_loc_offsets
)
4717 free (debug_information
[i
].loc_offsets
);
4718 free (debug_information
[i
].have_frame_base
);
4720 if (!debug_information
[i
].max_range_lists
)
4721 free (debug_information
[i
].range_lists
);
4725 free (debug_information
);
4726 debug_information
= NULL
;
4727 num_debug_info_entries
= 0;
4732 dwarf_select_sections_by_names (const char *names
)
4736 const char * option
;
4740 debug_dump_long_opts
;
4742 static const debug_dump_long_opts opts_table
[] =
4744 /* Please keep this table alpha- sorted. */
4745 { "Ranges", & do_debug_ranges
, 1 },
4746 { "abbrev", & do_debug_abbrevs
, 1 },
4747 { "aranges", & do_debug_aranges
, 1 },
4748 { "frames", & do_debug_frames
, 1 },
4749 { "frames-interp", & do_debug_frames_interp
, 1 },
4750 { "info", & do_debug_info
, 1 },
4751 { "line", & do_debug_lines
, FLAG_DEBUG_LINES_RAW
}, /* For backwards compatibility. */
4752 { "rawline", & do_debug_lines
, FLAG_DEBUG_LINES_RAW
},
4753 { "decodedline", & do_debug_lines
, FLAG_DEBUG_LINES_DECODED
},
4754 { "loc", & do_debug_loc
, 1 },
4755 { "macro", & do_debug_macinfo
, 1 },
4756 { "pubnames", & do_debug_pubnames
, 1 },
4757 /* This entry is for compatability
4758 with earlier versions of readelf. */
4759 { "ranges", & do_debug_aranges
, 1 },
4760 { "str", & do_debug_str
, 1 },
4769 const debug_dump_long_opts
* entry
;
4771 for (entry
= opts_table
; entry
->option
; entry
++)
4773 size_t len
= strlen (entry
->option
);
4775 if (strncmp (p
, entry
->option
, len
) == 0
4776 && (p
[len
] == ',' || p
[len
] == '\0'))
4778 * entry
->variable
|= entry
->val
;
4780 /* The --debug-dump=frames-interp option also
4781 enables the --debug-dump=frames option. */
4782 if (do_debug_frames_interp
)
4783 do_debug_frames
= 1;
4790 if (entry
->option
== NULL
)
4792 warn (_("Unrecognized debug option '%s'\n"), p
);
4793 p
= strchr (p
, ',');
4804 dwarf_select_sections_by_letters (const char *letters
)
4806 unsigned int index
= 0;
4808 while (letters
[index
])
4809 switch (letters
[index
++])
4816 do_debug_abbrevs
= 1;
4820 do_debug_lines
|= FLAG_DEBUG_LINES_RAW
;
4824 do_debug_lines
|= FLAG_DEBUG_LINES_DECODED
;
4828 do_debug_pubnames
= 1;
4832 do_debug_aranges
= 1;
4836 do_debug_ranges
= 1;
4840 do_debug_frames_interp
= 1;
4842 do_debug_frames
= 1;
4846 do_debug_macinfo
= 1;
4858 warn (_("Unrecognized debug option '%s'\n"), optarg
);
4864 dwarf_select_sections_all (void)
4867 do_debug_abbrevs
= 1;
4868 do_debug_lines
= FLAG_DEBUG_LINES_RAW
;
4869 do_debug_pubnames
= 1;
4870 do_debug_aranges
= 1;
4871 do_debug_ranges
= 1;
4872 do_debug_frames
= 1;
4873 do_debug_macinfo
= 1;
4878 struct dwarf_section_display debug_displays
[] =
4880 { { ".debug_abbrev", ".zdebug_abbrev", NULL
, NULL
, 0, 0 },
4881 display_debug_abbrev
, &do_debug_abbrevs
, 0 },
4882 { { ".debug_aranges", ".zdebug_aranges", NULL
, NULL
, 0, 0 },
4883 display_debug_aranges
, &do_debug_aranges
, 1 },
4884 { { ".debug_frame", ".zdebug_frame", NULL
, NULL
, 0, 0 },
4885 display_debug_frames
, &do_debug_frames
, 1 },
4886 { { ".debug_info", ".zdebug_info", NULL
, NULL
, 0, 0 },
4887 display_debug_info
, &do_debug_info
, 1 },
4888 { { ".debug_line", ".zdebug_line", NULL
, NULL
, 0, 0 },
4889 display_debug_lines
, &do_debug_lines
, 1 },
4890 { { ".debug_pubnames", ".zdebug_pubnames", NULL
, NULL
, 0, 0 },
4891 display_debug_pubnames
, &do_debug_pubnames
, 0 },
4892 { { ".eh_frame", "", NULL
, NULL
, 0, 0 },
4893 display_debug_frames
, &do_debug_frames
, 1 },
4894 { { ".debug_macinfo", ".zdebug_macinfo", NULL
, NULL
, 0, 0 },
4895 display_debug_macinfo
, &do_debug_macinfo
, 0 },
4896 { { ".debug_str", ".zdebug_str", NULL
, NULL
, 0, 0 },
4897 display_debug_str
, &do_debug_str
, 0 },
4898 { { ".debug_loc", ".zdebug_loc", NULL
, NULL
, 0, 0 },
4899 display_debug_loc
, &do_debug_loc
, 1 },
4900 { { ".debug_pubtypes", ".zdebug_pubtypes", NULL
, NULL
, 0, 0 },
4901 display_debug_pubnames
, &do_debug_pubnames
, 0 },
4902 { { ".debug_ranges", ".zdebug_ranges", NULL
, NULL
, 0, 0 },
4903 display_debug_ranges
, &do_debug_ranges
, 1 },
4904 { { ".debug_static_func", ".zdebug_static_func", NULL
, NULL
, 0, 0 },
4905 display_debug_not_supported
, NULL
, 0 },
4906 { { ".debug_static_vars", ".zdebug_static_vars", NULL
, NULL
, 0, 0 },
4907 display_debug_not_supported
, NULL
, 0 },
4908 { { ".debug_types", ".zdebug_types", NULL
, NULL
, 0, 0 },
4909 display_debug_not_supported
, NULL
, 0 },
4910 { { ".debug_weaknames", ".zdebug_weaknames", NULL
, NULL
, 0, 0 },
4911 display_debug_not_supported
, NULL
, 0 }