1 /* dwarf.c -- display DWARF contents of a BFD binary file
2 Copyright 2005, 2006, 2007, 2008
3 Free Software Foundation, Inc.
5 This file is part of GNU Binutils.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
23 #include "libiberty.h"
26 #include "elf/common.h"
27 #include "elf/dwarf2.h"
30 static int have_frame_base
;
31 static int need_base_address
;
33 static unsigned int last_pointer_size
= 0;
34 static int warned_about_missing_comp_units
= FALSE
;
36 static unsigned int num_debug_info_entries
= 0;
37 static debug_info
*debug_information
= NULL
;
38 /* Special value for num_debug_info_entries to indicate
39 that the .debug_info section could not be loaded/parsed. */
40 #define DEBUG_INFO_UNAVAILABLE (unsigned int) -1
47 int do_debug_pubnames
;
51 int do_debug_frames_interp
;
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 /* GNU extensions. */
1018 case DW_OP_GNU_push_tls_address
:
1019 printf ("DW_OP_GNU_push_tls_address or DW_OP_HP_unknown");
1021 case DW_OP_GNU_uninit
:
1022 printf ("DW_OP_GNU_uninit");
1023 /* FIXME: Is there data associated with this OP ? */
1025 case DW_OP_GNU_encoded_addr
:
1031 addr
= get_encoded_value (data
, encoding
);
1032 if ((encoding
& 0x70) == DW_EH_PE_pcrel
)
1033 addr
+= section
->address
+ (data
- section
->start
);
1034 data
+= size_of_encoded_value (encoding
);
1036 printf ("DW_OP_GNU_encoded_addr: fmt:%02x addr:", encoding
);
1037 print_dwarf_vma (addr
, pointer_size
);
1041 /* HP extensions. */
1042 case DW_OP_HP_is_value
:
1043 printf ("DW_OP_HP_is_value");
1044 /* FIXME: Is there data associated with this OP ? */
1046 case DW_OP_HP_fltconst4
:
1047 printf ("DW_OP_HP_fltconst4");
1048 /* FIXME: Is there data associated with this OP ? */
1050 case DW_OP_HP_fltconst8
:
1051 printf ("DW_OP_HP_fltconst8");
1052 /* FIXME: Is there data associated with this OP ? */
1054 case DW_OP_HP_mod_range
:
1055 printf ("DW_OP_HP_mod_range");
1056 /* FIXME: Is there data associated with this OP ? */
1058 case DW_OP_HP_unmod_range
:
1059 printf ("DW_OP_HP_unmod_range");
1060 /* FIXME: Is there data associated with this OP ? */
1063 printf ("DW_OP_HP_tls");
1064 /* FIXME: Is there data associated with this OP ? */
1067 /* PGI (STMicroelectronics) extensions. */
1068 case DW_OP_PGI_omp_thread_num
:
1069 /* Pushes the thread number for the current thread as it would be
1070 returned by the standard OpenMP library function:
1071 omp_get_thread_num(). The "current thread" is the thread for
1072 which the expression is being evaluated. */
1073 printf ("DW_OP_PGI_omp_thread_num");
1077 if (op
>= DW_OP_lo_user
1078 && op
<= DW_OP_hi_user
)
1079 printf (_("(User defined location op)"));
1081 printf (_("(Unknown location op)"));
1082 /* No way to tell where the next op is, so just bail. */
1083 return need_frame_base
;
1086 /* Separate the ops. */
1091 return need_frame_base
;
1094 static unsigned char *
1095 read_and_display_attr_value (unsigned long attribute
,
1097 unsigned char * data
,
1098 unsigned long cu_offset
,
1099 unsigned long pointer_size
,
1100 unsigned long offset_size
,
1102 debug_info
* debug_info_p
,
1104 struct dwarf_section
* section
)
1106 unsigned long uvalue
= 0;
1107 unsigned char *block_start
= NULL
;
1108 unsigned char * orig_data
= data
;
1109 unsigned int bytes_read
;
1116 case DW_FORM_ref_addr
:
1117 if (dwarf_version
== 2)
1119 uvalue
= byte_get (data
, pointer_size
);
1120 data
+= pointer_size
;
1122 else if (dwarf_version
== 3)
1124 uvalue
= byte_get (data
, offset_size
);
1125 data
+= offset_size
;
1129 error (_("Internal error: DWARF version is not 2 or 3.\n"));
1134 uvalue
= byte_get (data
, pointer_size
);
1135 data
+= pointer_size
;
1139 uvalue
= byte_get (data
, offset_size
);
1140 data
+= offset_size
;
1146 uvalue
= byte_get (data
++, 1);
1151 uvalue
= byte_get (data
, 2);
1157 uvalue
= byte_get (data
, 4);
1162 uvalue
= read_leb128 (data
, & bytes_read
, 1);
1166 case DW_FORM_ref_udata
:
1168 uvalue
= read_leb128 (data
, & bytes_read
, 0);
1172 case DW_FORM_indirect
:
1173 form
= read_leb128 (data
, & bytes_read
, 0);
1176 printf (" %s", get_FORM_name (form
));
1177 return read_and_display_attr_value (attribute
, form
, data
,
1178 cu_offset
, pointer_size
,
1179 offset_size
, dwarf_version
,
1180 debug_info_p
, do_loc
,
1186 case DW_FORM_ref_addr
:
1188 printf (" <0x%lx>", uvalue
);
1194 case DW_FORM_ref_udata
:
1196 printf (" <0x%lx>", uvalue
+ cu_offset
);
1202 printf (" 0x%lx", uvalue
);
1211 printf (" %ld", uvalue
);
1218 uvalue
= byte_get (data
, 4);
1219 printf (" 0x%lx", uvalue
);
1220 printf (" 0x%lx", (unsigned long) byte_get (data
+ 4, 4));
1222 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
1223 && num_debug_info_entries
== 0)
1225 if (sizeof (uvalue
) == 8)
1226 uvalue
= byte_get (data
, 8);
1228 error (_("DW_FORM_data8 is unsupported when sizeof (unsigned long) != 8\n"));
1233 case DW_FORM_string
:
1235 printf (" %s", data
);
1236 data
+= strlen ((char *) data
) + 1;
1240 uvalue
= read_leb128 (data
, & bytes_read
, 0);
1241 block_start
= data
+ bytes_read
;
1243 data
= block_start
+ uvalue
;
1245 data
= display_block (block_start
, uvalue
);
1248 case DW_FORM_block1
:
1249 uvalue
= byte_get (data
, 1);
1250 block_start
= data
+ 1;
1252 data
= block_start
+ uvalue
;
1254 data
= display_block (block_start
, uvalue
);
1257 case DW_FORM_block2
:
1258 uvalue
= byte_get (data
, 2);
1259 block_start
= data
+ 2;
1261 data
= block_start
+ uvalue
;
1263 data
= display_block (block_start
, uvalue
);
1266 case DW_FORM_block4
:
1267 uvalue
= byte_get (data
, 4);
1268 block_start
= data
+ 4;
1270 data
= block_start
+ uvalue
;
1272 data
= display_block (block_start
, uvalue
);
1277 printf (_(" (indirect string, offset: 0x%lx): %s"),
1278 uvalue
, fetch_indirect_string (uvalue
));
1281 case DW_FORM_indirect
:
1282 /* Handled above. */
1286 warn (_("Unrecognized form: %lu\n"), form
);
1290 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
1291 && num_debug_info_entries
== 0)
1295 case DW_AT_frame_base
:
1296 have_frame_base
= 1;
1297 case DW_AT_location
:
1298 case DW_AT_string_length
:
1299 case DW_AT_return_addr
:
1300 case DW_AT_data_member_location
:
1301 case DW_AT_vtable_elem_location
:
1303 case DW_AT_static_link
:
1304 case DW_AT_use_location
:
1305 if (form
== DW_FORM_data4
|| form
== DW_FORM_data8
)
1307 /* Process location list. */
1308 unsigned int max
= debug_info_p
->max_loc_offsets
;
1309 unsigned int num
= debug_info_p
->num_loc_offsets
;
1311 if (max
== 0 || num
>= max
)
1314 debug_info_p
->loc_offsets
1315 = xcrealloc (debug_info_p
->loc_offsets
,
1316 max
, sizeof (*debug_info_p
->loc_offsets
));
1317 debug_info_p
->have_frame_base
1318 = xcrealloc (debug_info_p
->have_frame_base
,
1319 max
, sizeof (*debug_info_p
->have_frame_base
));
1320 debug_info_p
->max_loc_offsets
= max
;
1322 debug_info_p
->loc_offsets
[num
] = uvalue
;
1323 debug_info_p
->have_frame_base
[num
] = have_frame_base
;
1324 debug_info_p
->num_loc_offsets
++;
1329 if (need_base_address
)
1330 debug_info_p
->base_address
= uvalue
;
1334 if (form
== DW_FORM_data4
|| form
== DW_FORM_data8
)
1336 /* Process range list. */
1337 unsigned int max
= debug_info_p
->max_range_lists
;
1338 unsigned int num
= debug_info_p
->num_range_lists
;
1340 if (max
== 0 || num
>= max
)
1343 debug_info_p
->range_lists
1344 = xcrealloc (debug_info_p
->range_lists
,
1345 max
, sizeof (*debug_info_p
->range_lists
));
1346 debug_info_p
->max_range_lists
= max
;
1348 debug_info_p
->range_lists
[num
] = uvalue
;
1349 debug_info_p
->num_range_lists
++;
1361 /* For some attributes we can display further information. */
1369 case DW_INL_not_inlined
:
1370 printf (_("(not inlined)"));
1372 case DW_INL_inlined
:
1373 printf (_("(inlined)"));
1375 case DW_INL_declared_not_inlined
:
1376 printf (_("(declared as inline but ignored)"));
1378 case DW_INL_declared_inlined
:
1379 printf (_("(declared as inline and inlined)"));
1382 printf (_(" (Unknown inline attribute value: %lx)"), uvalue
);
1387 case DW_AT_language
:
1390 /* Ordered by the numeric value of these constants. */
1391 case DW_LANG_C89
: printf ("(ANSI C)"); break;
1392 case DW_LANG_C
: printf ("(non-ANSI C)"); break;
1393 case DW_LANG_Ada83
: printf ("(Ada)"); break;
1394 case DW_LANG_C_plus_plus
: printf ("(C++)"); break;
1395 case DW_LANG_Cobol74
: printf ("(Cobol 74)"); break;
1396 case DW_LANG_Cobol85
: printf ("(Cobol 85)"); break;
1397 case DW_LANG_Fortran77
: printf ("(FORTRAN 77)"); break;
1398 case DW_LANG_Fortran90
: printf ("(Fortran 90)"); break;
1399 case DW_LANG_Pascal83
: printf ("(ANSI Pascal)"); break;
1400 case DW_LANG_Modula2
: printf ("(Modula 2)"); break;
1401 /* DWARF 2.1 values. */
1402 case DW_LANG_Java
: printf ("(Java)"); break;
1403 case DW_LANG_C99
: printf ("(ANSI C99)"); break;
1404 case DW_LANG_Ada95
: printf ("(ADA 95)"); break;
1405 case DW_LANG_Fortran95
: printf ("(Fortran 95)"); break;
1406 /* DWARF 3 values. */
1407 case DW_LANG_PLI
: printf ("(PLI)"); break;
1408 case DW_LANG_ObjC
: printf ("(Objective C)"); break;
1409 case DW_LANG_ObjC_plus_plus
: printf ("(Objective C++)"); break;
1410 case DW_LANG_UPC
: printf ("(Unified Parallel C)"); break;
1411 case DW_LANG_D
: printf ("(D)"); break;
1412 /* MIPS extension. */
1413 case DW_LANG_Mips_Assembler
: printf ("(MIPS assembler)"); break;
1414 /* UPC extension. */
1415 case DW_LANG_Upc
: printf ("(Unified Parallel C)"); break;
1417 if (uvalue
>= DW_LANG_lo_user
&& uvalue
<= DW_LANG_hi_user
)
1418 printf ("(implementation defined: %lx)", uvalue
);
1420 printf ("(Unknown: %lx)", uvalue
);
1425 case DW_AT_encoding
:
1428 case DW_ATE_void
: printf ("(void)"); break;
1429 case DW_ATE_address
: printf ("(machine address)"); break;
1430 case DW_ATE_boolean
: printf ("(boolean)"); break;
1431 case DW_ATE_complex_float
: printf ("(complex float)"); break;
1432 case DW_ATE_float
: printf ("(float)"); break;
1433 case DW_ATE_signed
: printf ("(signed)"); break;
1434 case DW_ATE_signed_char
: printf ("(signed char)"); break;
1435 case DW_ATE_unsigned
: printf ("(unsigned)"); break;
1436 case DW_ATE_unsigned_char
: printf ("(unsigned char)"); break;
1437 /* DWARF 2.1 values: */
1438 case DW_ATE_imaginary_float
: printf ("(imaginary float)"); break;
1439 case DW_ATE_decimal_float
: printf ("(decimal float)"); break;
1440 /* DWARF 3 values: */
1441 case DW_ATE_packed_decimal
: printf ("(packed_decimal)"); break;
1442 case DW_ATE_numeric_string
: printf ("(numeric_string)"); break;
1443 case DW_ATE_edited
: printf ("(edited)"); break;
1444 case DW_ATE_signed_fixed
: printf ("(signed_fixed)"); break;
1445 case DW_ATE_unsigned_fixed
: printf ("(unsigned_fixed)"); break;
1446 /* HP extensions: */
1447 case DW_ATE_HP_float80
: printf ("(HP_float80)"); break;
1448 case DW_ATE_HP_complex_float80
: printf ("(HP_complex_float80)"); break;
1449 case DW_ATE_HP_float128
: printf ("(HP_float128)"); break;
1450 case DW_ATE_HP_complex_float128
:printf ("(HP_complex_float128)"); break;
1451 case DW_ATE_HP_floathpintel
: printf ("(HP_floathpintel)"); break;
1452 case DW_ATE_HP_imaginary_float80
: printf ("(HP_imaginary_float80)"); break;
1453 case DW_ATE_HP_imaginary_float128
: printf ("(HP_imaginary_float128)"); break;
1456 if (uvalue
>= DW_ATE_lo_user
1457 && uvalue
<= DW_ATE_hi_user
)
1458 printf ("(user defined type)");
1460 printf ("(unknown type)");
1465 case DW_AT_accessibility
:
1468 case DW_ACCESS_public
: printf ("(public)"); break;
1469 case DW_ACCESS_protected
: printf ("(protected)"); break;
1470 case DW_ACCESS_private
: printf ("(private)"); break;
1472 printf ("(unknown accessibility)");
1477 case DW_AT_visibility
:
1480 case DW_VIS_local
: printf ("(local)"); break;
1481 case DW_VIS_exported
: printf ("(exported)"); break;
1482 case DW_VIS_qualified
: printf ("(qualified)"); break;
1483 default: printf ("(unknown visibility)"); break;
1487 case DW_AT_virtuality
:
1490 case DW_VIRTUALITY_none
: printf ("(none)"); break;
1491 case DW_VIRTUALITY_virtual
: printf ("(virtual)"); break;
1492 case DW_VIRTUALITY_pure_virtual
:printf ("(pure_virtual)"); break;
1493 default: printf ("(unknown virtuality)"); break;
1497 case DW_AT_identifier_case
:
1500 case DW_ID_case_sensitive
: printf ("(case_sensitive)"); break;
1501 case DW_ID_up_case
: printf ("(up_case)"); break;
1502 case DW_ID_down_case
: printf ("(down_case)"); break;
1503 case DW_ID_case_insensitive
: printf ("(case_insensitive)"); break;
1504 default: printf ("(unknown case)"); break;
1508 case DW_AT_calling_convention
:
1511 case DW_CC_normal
: printf ("(normal)"); break;
1512 case DW_CC_program
: printf ("(program)"); break;
1513 case DW_CC_nocall
: printf ("(nocall)"); break;
1515 if (uvalue
>= DW_CC_lo_user
1516 && uvalue
<= DW_CC_hi_user
)
1517 printf ("(user defined)");
1519 printf ("(unknown convention)");
1523 case DW_AT_ordering
:
1526 case -1: printf ("(undefined)"); break;
1527 case 0: printf ("(row major)"); break;
1528 case 1: printf ("(column major)"); break;
1532 case DW_AT_frame_base
:
1533 have_frame_base
= 1;
1534 case DW_AT_location
:
1535 case DW_AT_string_length
:
1536 case DW_AT_return_addr
:
1537 case DW_AT_data_member_location
:
1538 case DW_AT_vtable_elem_location
:
1540 case DW_AT_static_link
:
1541 case DW_AT_use_location
:
1542 if (form
== DW_FORM_data4
|| form
== DW_FORM_data8
)
1543 printf (_("(location list)"));
1545 case DW_AT_allocated
:
1546 case DW_AT_associated
:
1547 case DW_AT_data_location
:
1549 case DW_AT_upper_bound
:
1550 case DW_AT_lower_bound
:
1553 int need_frame_base
;
1556 need_frame_base
= decode_location_expression (block_start
,
1559 cu_offset
, section
);
1561 if (need_frame_base
&& !have_frame_base
)
1562 printf (_(" [without DW_AT_frame_base]"));
1568 if (form
== DW_FORM_ref1
1569 || form
== DW_FORM_ref2
1570 || form
== DW_FORM_ref4
)
1571 uvalue
+= cu_offset
;
1573 if (uvalue
>= section
->size
)
1574 warn (_("Offset %lx used as value for DW_AT_import attribute of DIE at offset %lx is too big.\n"),
1575 uvalue
, (unsigned long) (orig_data
- section
->start
));
1578 unsigned long abbrev_number
;
1579 abbrev_entry
* entry
;
1581 abbrev_number
= read_leb128 (section
->start
+ uvalue
, NULL
, 0);
1583 printf ("[Abbrev Number: %ld", abbrev_number
);
1584 for (entry
= first_abbrev
; entry
!= NULL
; entry
= entry
->next
)
1585 if (entry
->entry
== abbrev_number
)
1588 printf (" (%s)", get_TAG_name (entry
->tag
));
1602 get_AT_name (unsigned long attribute
)
1606 case DW_AT_sibling
: return "DW_AT_sibling";
1607 case DW_AT_location
: return "DW_AT_location";
1608 case DW_AT_name
: return "DW_AT_name";
1609 case DW_AT_ordering
: return "DW_AT_ordering";
1610 case DW_AT_subscr_data
: return "DW_AT_subscr_data";
1611 case DW_AT_byte_size
: return "DW_AT_byte_size";
1612 case DW_AT_bit_offset
: return "DW_AT_bit_offset";
1613 case DW_AT_bit_size
: return "DW_AT_bit_size";
1614 case DW_AT_element_list
: return "DW_AT_element_list";
1615 case DW_AT_stmt_list
: return "DW_AT_stmt_list";
1616 case DW_AT_low_pc
: return "DW_AT_low_pc";
1617 case DW_AT_high_pc
: return "DW_AT_high_pc";
1618 case DW_AT_language
: return "DW_AT_language";
1619 case DW_AT_member
: return "DW_AT_member";
1620 case DW_AT_discr
: return "DW_AT_discr";
1621 case DW_AT_discr_value
: return "DW_AT_discr_value";
1622 case DW_AT_visibility
: return "DW_AT_visibility";
1623 case DW_AT_import
: return "DW_AT_import";
1624 case DW_AT_string_length
: return "DW_AT_string_length";
1625 case DW_AT_common_reference
: return "DW_AT_common_reference";
1626 case DW_AT_comp_dir
: return "DW_AT_comp_dir";
1627 case DW_AT_const_value
: return "DW_AT_const_value";
1628 case DW_AT_containing_type
: return "DW_AT_containing_type";
1629 case DW_AT_default_value
: return "DW_AT_default_value";
1630 case DW_AT_inline
: return "DW_AT_inline";
1631 case DW_AT_is_optional
: return "DW_AT_is_optional";
1632 case DW_AT_lower_bound
: return "DW_AT_lower_bound";
1633 case DW_AT_producer
: return "DW_AT_producer";
1634 case DW_AT_prototyped
: return "DW_AT_prototyped";
1635 case DW_AT_return_addr
: return "DW_AT_return_addr";
1636 case DW_AT_start_scope
: return "DW_AT_start_scope";
1637 case DW_AT_stride_size
: return "DW_AT_stride_size";
1638 case DW_AT_upper_bound
: return "DW_AT_upper_bound";
1639 case DW_AT_abstract_origin
: return "DW_AT_abstract_origin";
1640 case DW_AT_accessibility
: return "DW_AT_accessibility";
1641 case DW_AT_address_class
: return "DW_AT_address_class";
1642 case DW_AT_artificial
: return "DW_AT_artificial";
1643 case DW_AT_base_types
: return "DW_AT_base_types";
1644 case DW_AT_calling_convention
: return "DW_AT_calling_convention";
1645 case DW_AT_count
: return "DW_AT_count";
1646 case DW_AT_data_member_location
: return "DW_AT_data_member_location";
1647 case DW_AT_decl_column
: return "DW_AT_decl_column";
1648 case DW_AT_decl_file
: return "DW_AT_decl_file";
1649 case DW_AT_decl_line
: return "DW_AT_decl_line";
1650 case DW_AT_declaration
: return "DW_AT_declaration";
1651 case DW_AT_discr_list
: return "DW_AT_discr_list";
1652 case DW_AT_encoding
: return "DW_AT_encoding";
1653 case DW_AT_external
: return "DW_AT_external";
1654 case DW_AT_frame_base
: return "DW_AT_frame_base";
1655 case DW_AT_friend
: return "DW_AT_friend";
1656 case DW_AT_identifier_case
: return "DW_AT_identifier_case";
1657 case DW_AT_macro_info
: return "DW_AT_macro_info";
1658 case DW_AT_namelist_items
: return "DW_AT_namelist_items";
1659 case DW_AT_priority
: return "DW_AT_priority";
1660 case DW_AT_segment
: return "DW_AT_segment";
1661 case DW_AT_specification
: return "DW_AT_specification";
1662 case DW_AT_static_link
: return "DW_AT_static_link";
1663 case DW_AT_type
: return "DW_AT_type";
1664 case DW_AT_use_location
: return "DW_AT_use_location";
1665 case DW_AT_variable_parameter
: return "DW_AT_variable_parameter";
1666 case DW_AT_virtuality
: return "DW_AT_virtuality";
1667 case DW_AT_vtable_elem_location
: return "DW_AT_vtable_elem_location";
1668 /* DWARF 2.1 values. */
1669 case DW_AT_allocated
: return "DW_AT_allocated";
1670 case DW_AT_associated
: return "DW_AT_associated";
1671 case DW_AT_data_location
: return "DW_AT_data_location";
1672 case DW_AT_stride
: return "DW_AT_stride";
1673 case DW_AT_entry_pc
: return "DW_AT_entry_pc";
1674 case DW_AT_use_UTF8
: return "DW_AT_use_UTF8";
1675 case DW_AT_extension
: return "DW_AT_extension";
1676 case DW_AT_ranges
: return "DW_AT_ranges";
1677 case DW_AT_trampoline
: return "DW_AT_trampoline";
1678 case DW_AT_call_column
: return "DW_AT_call_column";
1679 case DW_AT_call_file
: return "DW_AT_call_file";
1680 case DW_AT_call_line
: return "DW_AT_call_line";
1681 case DW_AT_description
: return "DW_AT_description";
1682 case DW_AT_binary_scale
: return "DW_AT_binary_scale";
1683 case DW_AT_decimal_scale
: return "DW_AT_decimal_scale";
1684 case DW_AT_small
: return "DW_AT_small";
1685 case DW_AT_decimal_sign
: return "DW_AT_decimal_sign";
1686 case DW_AT_digit_count
: return "DW_AT_digit_count";
1687 case DW_AT_picture_string
: return "DW_AT_picture_string";
1688 case DW_AT_mutable
: return "DW_AT_mutable";
1689 case DW_AT_threads_scaled
: return "DW_AT_threads_scaled";
1690 case DW_AT_explicit
: return "DW_AT_explicit";
1691 case DW_AT_object_pointer
: return "DW_AT_object_pointer";
1692 case DW_AT_endianity
: return "DW_AT_endianity";
1693 case DW_AT_elemental
: return "DW_AT_elemental";
1694 case DW_AT_pure
: return "DW_AT_pure";
1695 case DW_AT_recursive
: return "DW_AT_recursive";
1697 /* HP and SGI/MIPS extensions. */
1698 case DW_AT_MIPS_loop_begin
: return "DW_AT_MIPS_loop_begin";
1699 case DW_AT_MIPS_tail_loop_begin
: return "DW_AT_MIPS_tail_loop_begin";
1700 case DW_AT_MIPS_epilog_begin
: return "DW_AT_MIPS_epilog_begin";
1701 case DW_AT_MIPS_loop_unroll_factor
: return "DW_AT_MIPS_loop_unroll_factor";
1702 case DW_AT_MIPS_software_pipeline_depth
: return "DW_AT_MIPS_software_pipeline_depth";
1703 case DW_AT_MIPS_linkage_name
: return "DW_AT_MIPS_linkage_name";
1704 case DW_AT_MIPS_stride
: return "DW_AT_MIPS_stride";
1705 case DW_AT_MIPS_abstract_name
: return "DW_AT_MIPS_abstract_name";
1706 case DW_AT_MIPS_clone_origin
: return "DW_AT_MIPS_clone_origin";
1707 case DW_AT_MIPS_has_inlines
: return "DW_AT_MIPS_has_inlines";
1709 /* HP Extensions. */
1710 case DW_AT_HP_block_index
: return "DW_AT_HP_block_index";
1711 case DW_AT_HP_actuals_stmt_list
: return "DW_AT_HP_actuals_stmt_list";
1712 case DW_AT_HP_proc_per_section
: return "DW_AT_HP_proc_per_section";
1713 case DW_AT_HP_raw_data_ptr
: return "DW_AT_HP_raw_data_ptr";
1714 case DW_AT_HP_pass_by_reference
: return "DW_AT_HP_pass_by_reference";
1715 case DW_AT_HP_opt_level
: return "DW_AT_HP_opt_level";
1716 case DW_AT_HP_prof_version_id
: return "DW_AT_HP_prof_version_id";
1717 case DW_AT_HP_opt_flags
: return "DW_AT_HP_opt_flags";
1718 case DW_AT_HP_cold_region_low_pc
: return "DW_AT_HP_cold_region_low_pc";
1719 case DW_AT_HP_cold_region_high_pc
: return "DW_AT_HP_cold_region_high_pc";
1720 case DW_AT_HP_all_variables_modifiable
: return "DW_AT_HP_all_variables_modifiable";
1721 case DW_AT_HP_linkage_name
: return "DW_AT_HP_linkage_name";
1722 case DW_AT_HP_prof_flags
: return "DW_AT_HP_prof_flags";
1724 /* One value is shared by the MIPS and HP extensions: */
1725 case DW_AT_MIPS_fde
: return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable";
1727 /* GNU extensions. */
1728 case DW_AT_sf_names
: return "DW_AT_sf_names";
1729 case DW_AT_src_info
: return "DW_AT_src_info";
1730 case DW_AT_mac_info
: return "DW_AT_mac_info";
1731 case DW_AT_src_coords
: return "DW_AT_src_coords";
1732 case DW_AT_body_begin
: return "DW_AT_body_begin";
1733 case DW_AT_body_end
: return "DW_AT_body_end";
1734 case DW_AT_GNU_vector
: return "DW_AT_GNU_vector";
1736 /* UPC extension. */
1737 case DW_AT_upc_threads_scaled
: return "DW_AT_upc_threads_scaled";
1739 /* PGI (STMicroelectronics) extensions. */
1740 case DW_AT_PGI_lbase
: return "DW_AT_PGI_lbase";
1741 case DW_AT_PGI_soffset
: return "DW_AT_PGI_soffset";
1742 case DW_AT_PGI_lstride
: return "DW_AT_PGI_lstride";
1746 static char buffer
[100];
1748 snprintf (buffer
, sizeof (buffer
), _("Unknown AT value: %lx"),
1755 static unsigned char *
1756 read_and_display_attr (unsigned long attribute
,
1758 unsigned char * data
,
1759 unsigned long cu_offset
,
1760 unsigned long pointer_size
,
1761 unsigned long offset_size
,
1763 debug_info
* debug_info_p
,
1765 struct dwarf_section
* section
)
1768 printf (" %-18s:", get_AT_name (attribute
));
1769 data
= read_and_display_attr_value (attribute
, form
, data
, cu_offset
,
1770 pointer_size
, offset_size
,
1771 dwarf_version
, debug_info_p
,
1779 /* Process the contents of a .debug_info section. If do_loc is non-zero
1780 then we are scanning for location lists and we do not want to display
1781 anything to the user. */
1784 process_debug_info (struct dwarf_section
*section
,
1788 unsigned char *start
= section
->start
;
1789 unsigned char *end
= start
+ section
->size
;
1790 unsigned char *section_begin
;
1792 unsigned int num_units
= 0;
1794 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
1795 && num_debug_info_entries
== 0)
1797 unsigned long length
;
1799 /* First scan the section to get the number of comp units. */
1800 for (section_begin
= start
, num_units
= 0; section_begin
< end
;
1803 /* Read the first 4 bytes. For a 32-bit DWARF section, this
1804 will be the length. For a 64-bit DWARF section, it'll be
1805 the escape code 0xffffffff followed by an 8 byte length. */
1806 length
= byte_get (section_begin
, 4);
1808 if (length
== 0xffffffff)
1810 length
= byte_get (section_begin
+ 4, 8);
1811 section_begin
+= length
+ 12;
1813 else if (length
>= 0xfffffff0 && length
< 0xffffffff)
1815 warn (_("Reserved length value (%lx) found in section %s\n"), length
, section
->name
);
1819 section_begin
+= length
+ 4;
1821 /* Negative values are illegal, they may even cause infinite
1822 looping. This can happen if we can't accurately apply
1823 relocations to an object file. */
1824 if ((signed long) length
<= 0)
1826 warn (_("Corrupt unit length (%lx) found in section %s\n"), length
, section
->name
);
1833 error (_("No comp units in %s section ?"), section
->name
);
1837 /* Then allocate an array to hold the information. */
1838 debug_information
= cmalloc (num_units
,
1839 sizeof (* debug_information
));
1840 if (debug_information
== NULL
)
1842 error (_("Not enough memory for a debug info array of %u entries"),
1850 printf (_("Contents of the %s section:\n\n"), section
->name
);
1852 load_debug_section (str
, file
);
1855 load_debug_section (abbrev
, file
);
1856 if (debug_displays
[abbrev
].section
.start
== NULL
)
1858 warn (_("Unable to locate %s section!\n"),
1859 debug_displays
[abbrev
].section
.name
);
1863 for (section_begin
= start
, unit
= 0; start
< end
; unit
++)
1865 DWARF2_Internal_CompUnit compunit
;
1866 unsigned char *hdrptr
;
1867 unsigned char *cu_abbrev_offset_ptr
;
1868 unsigned char *tags
;
1870 unsigned long cu_offset
;
1872 int initial_length_size
;
1876 compunit
.cu_length
= byte_get (hdrptr
, 4);
1879 if (compunit
.cu_length
== 0xffffffff)
1881 compunit
.cu_length
= byte_get (hdrptr
, 8);
1884 initial_length_size
= 12;
1889 initial_length_size
= 4;
1892 compunit
.cu_version
= byte_get (hdrptr
, 2);
1895 cu_offset
= start
- section_begin
;
1897 cu_abbrev_offset_ptr
= hdrptr
;
1898 compunit
.cu_abbrev_offset
= byte_get (hdrptr
, offset_size
);
1899 hdrptr
+= offset_size
;
1901 compunit
.cu_pointer_size
= byte_get (hdrptr
, 1);
1903 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
1904 && num_debug_info_entries
== 0)
1906 debug_information
[unit
].cu_offset
= cu_offset
;
1907 debug_information
[unit
].pointer_size
1908 = compunit
.cu_pointer_size
;
1909 debug_information
[unit
].base_address
= 0;
1910 debug_information
[unit
].loc_offsets
= NULL
;
1911 debug_information
[unit
].have_frame_base
= NULL
;
1912 debug_information
[unit
].max_loc_offsets
= 0;
1913 debug_information
[unit
].num_loc_offsets
= 0;
1914 debug_information
[unit
].range_lists
= NULL
;
1915 debug_information
[unit
].max_range_lists
= 0;
1916 debug_information
[unit
].num_range_lists
= 0;
1921 printf (_(" Compilation Unit @ offset 0x%lx:\n"), cu_offset
);
1922 printf (_(" Length: 0x%lx (%s)\n"), compunit
.cu_length
,
1923 initial_length_size
== 8 ? "64-bit" : "32-bit");
1924 printf (_(" Version: %d\n"), compunit
.cu_version
);
1925 printf (_(" Abbrev Offset: %ld\n"), compunit
.cu_abbrev_offset
);
1926 printf (_(" Pointer Size: %d\n"), compunit
.cu_pointer_size
);
1929 if (cu_offset
+ compunit
.cu_length
+ initial_length_size
1932 warn (_("Debug info is corrupted, length of CU at %lx extends beyond end of section (length = %lx)\n"),
1933 cu_offset
, compunit
.cu_length
);
1937 start
+= compunit
.cu_length
+ initial_length_size
;
1939 if (compunit
.cu_version
!= 2 && compunit
.cu_version
!= 3)
1941 warn (_("CU at offset %lx contains corrupt or unsupported version number: %d.\n"),
1942 cu_offset
, compunit
.cu_version
);
1948 /* Process the abbrevs used by this compilation unit. DWARF
1949 sections under Mach-O have non-zero addresses. */
1950 if (compunit
.cu_abbrev_offset
>= debug_displays
[abbrev
].section
.size
)
1951 warn (_("Debug info is corrupted, abbrev offset (%lx) is larger than abbrev section size (%lx)\n"),
1952 (unsigned long) compunit
.cu_abbrev_offset
,
1953 (unsigned long) debug_displays
[abbrev
].section
.size
);
1955 process_abbrev_section
1956 ((unsigned char *) debug_displays
[abbrev
].section
.start
1957 + compunit
.cu_abbrev_offset
- debug_displays
[abbrev
].section
.address
,
1958 (unsigned char *) debug_displays
[abbrev
].section
.start
1959 + debug_displays
[abbrev
].section
.size
);
1962 while (tags
< start
)
1964 unsigned int bytes_read
;
1965 unsigned long abbrev_number
;
1966 unsigned long die_offset
;
1967 abbrev_entry
*entry
;
1970 die_offset
= tags
- section_begin
;
1972 abbrev_number
= read_leb128 (tags
, & bytes_read
, 0);
1975 /* A null DIE marks the end of a list of siblings. */
1976 if (abbrev_number
== 0)
1981 static unsigned num_bogus_warns
= 0;
1983 if (num_bogus_warns
< 3)
1985 warn (_("Bogus end-of-siblings marker detected at offset %lx in .debug_info section\n"),
1988 if (num_bogus_warns
== 3)
1989 warn (_("Further warnings about bogus end-of-sibling markers suppressed\n"));
1996 printf (_(" <%d><%lx>: Abbrev Number: %lu"),
1997 level
, die_offset
, abbrev_number
);
1999 /* Scan through the abbreviation list until we reach the
2001 for (entry
= first_abbrev
;
2002 entry
&& entry
->entry
!= abbrev_number
;
2003 entry
= entry
->next
)
2013 warn (_("DIE at offset %lx refers to abbreviation number %lu which does not exist\n"),
2014 die_offset
, abbrev_number
);
2019 printf (_(" (%s)\n"), get_TAG_name (entry
->tag
));
2024 need_base_address
= 0;
2026 case DW_TAG_compile_unit
:
2027 need_base_address
= 1;
2029 case DW_TAG_entry_point
:
2030 case DW_TAG_subprogram
:
2031 need_base_address
= 0;
2032 /* Assuming that there is no DW_AT_frame_base. */
2033 have_frame_base
= 0;
2037 for (attr
= entry
->first_attr
; attr
; attr
= attr
->next
)
2040 /* Show the offset from where the tag was extracted. */
2041 printf (" <%2lx>", (unsigned long)(tags
- section_begin
));
2043 tags
= read_and_display_attr (attr
->attribute
,
2046 compunit
.cu_pointer_size
,
2048 compunit
.cu_version
,
2049 debug_information
+ unit
,
2053 if (entry
->children
)
2058 /* Set num_debug_info_entries here so that it can be used to check if
2059 we need to process .debug_loc and .debug_ranges sections. */
2060 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
2061 && num_debug_info_entries
== 0)
2062 num_debug_info_entries
= num_units
;
2072 /* Locate and scan the .debug_info section in the file and record the pointer
2073 sizes and offsets for the compilation units in it. Usually an executable
2074 will have just one pointer size, but this is not guaranteed, and so we try
2075 not to make any assumptions. Returns zero upon failure, or the number of
2076 compilation units upon success. */
2079 load_debug_info (void * file
)
2081 /* Reset the last pointer size so that we can issue correct error
2082 messages if we are displaying the contents of more than one section. */
2083 last_pointer_size
= 0;
2084 warned_about_missing_comp_units
= FALSE
;
2086 /* If we have already tried and failed to load the .debug_info
2087 section then do not bother to repear the task. */
2088 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
2091 /* If we already have the information there is nothing else to do. */
2092 if (num_debug_info_entries
> 0)
2093 return num_debug_info_entries
;
2095 if (load_debug_section (info
, file
)
2096 && process_debug_info (&debug_displays
[info
].section
, file
, 1))
2097 return num_debug_info_entries
;
2099 num_debug_info_entries
= DEBUG_INFO_UNAVAILABLE
;
2104 display_debug_lines_raw (struct dwarf_section
*section
,
2105 unsigned char *data
,
2108 unsigned char *start
= section
->start
;
2110 printf (_("Raw dump of debug contents of section %s:\n\n"),
2115 DWARF2_Internal_LineInfo info
;
2116 unsigned char *standard_opcodes
;
2117 unsigned char *end_of_sequence
;
2118 unsigned char *hdrptr
;
2119 unsigned long hdroff
;
2120 int initial_length_size
;
2125 hdroff
= hdrptr
- start
;
2127 /* Check the length of the block. */
2128 info
.li_length
= byte_get (hdrptr
, 4);
2131 if (info
.li_length
== 0xffffffff)
2133 /* This section is 64-bit DWARF 3. */
2134 info
.li_length
= byte_get (hdrptr
, 8);
2137 initial_length_size
= 12;
2142 initial_length_size
= 4;
2145 if (info
.li_length
+ initial_length_size
> section
->size
)
2148 (_("The line info appears to be corrupt - the section is too small\n"));
2152 /* Check its version number. */
2153 info
.li_version
= byte_get (hdrptr
, 2);
2155 if (info
.li_version
!= 2 && info
.li_version
!= 3)
2157 warn (_("Only DWARF version 2 and 3 line info is currently supported.\n"));
2161 info
.li_prologue_length
= byte_get (hdrptr
, offset_size
);
2162 hdrptr
+= offset_size
;
2163 info
.li_min_insn_length
= byte_get (hdrptr
, 1);
2165 info
.li_default_is_stmt
= byte_get (hdrptr
, 1);
2167 info
.li_line_base
= byte_get (hdrptr
, 1);
2169 info
.li_line_range
= byte_get (hdrptr
, 1);
2171 info
.li_opcode_base
= byte_get (hdrptr
, 1);
2174 /* Sign extend the line base field. */
2175 info
.li_line_base
<<= 24;
2176 info
.li_line_base
>>= 24;
2178 printf (_(" Offset: 0x%lx\n"), hdroff
);
2179 printf (_(" Length: %ld\n"), info
.li_length
);
2180 printf (_(" DWARF Version: %d\n"), info
.li_version
);
2181 printf (_(" Prologue Length: %d\n"), info
.li_prologue_length
);
2182 printf (_(" Minimum Instruction Length: %d\n"), info
.li_min_insn_length
);
2183 printf (_(" Initial value of 'is_stmt': %d\n"), info
.li_default_is_stmt
);
2184 printf (_(" Line Base: %d\n"), info
.li_line_base
);
2185 printf (_(" Line Range: %d\n"), info
.li_line_range
);
2186 printf (_(" Opcode Base: %d\n"), info
.li_opcode_base
);
2188 end_of_sequence
= data
+ info
.li_length
+ initial_length_size
;
2190 reset_state_machine (info
.li_default_is_stmt
);
2192 /* Display the contents of the Opcodes table. */
2193 standard_opcodes
= hdrptr
;
2195 printf (_("\n Opcodes:\n"));
2197 for (i
= 1; i
< info
.li_opcode_base
; i
++)
2198 printf (_(" Opcode %d has %d args\n"), i
, standard_opcodes
[i
- 1]);
2200 /* Display the contents of the Directory table. */
2201 data
= standard_opcodes
+ info
.li_opcode_base
- 1;
2204 printf (_("\n The Directory Table is empty.\n"));
2207 printf (_("\n The Directory Table:\n"));
2211 printf (_(" %s\n"), data
);
2213 data
+= strlen ((char *) data
) + 1;
2217 /* Skip the NUL at the end of the table. */
2220 /* Display the contents of the File Name table. */
2222 printf (_("\n The File Name Table is empty.\n"));
2225 printf (_("\n The File Name Table:\n"));
2226 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
2230 unsigned char *name
;
2231 unsigned int bytes_read
;
2233 printf (_(" %d\t"), ++state_machine_regs
.last_file_entry
);
2236 data
+= strlen ((char *) data
) + 1;
2238 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
2240 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
2242 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
2244 printf (_("%s\n"), name
);
2248 /* Skip the NUL at the end of the table. */
2251 /* Now display the statements. */
2252 printf (_("\n Line Number Statements:\n"));
2254 while (data
< end_of_sequence
)
2256 unsigned char op_code
;
2258 unsigned long int uladv
;
2259 unsigned int bytes_read
;
2263 if (op_code
>= info
.li_opcode_base
)
2265 op_code
-= info
.li_opcode_base
;
2266 uladv
= (op_code
/ info
.li_line_range
) * info
.li_min_insn_length
;
2267 state_machine_regs
.address
+= uladv
;
2268 printf (_(" Special opcode %d: advance Address by %lu to 0x%lx"),
2269 op_code
, uladv
, state_machine_regs
.address
);
2270 adv
= (op_code
% info
.li_line_range
) + info
.li_line_base
;
2271 state_machine_regs
.line
+= adv
;
2272 printf (_(" and Line by %d to %d\n"),
2273 adv
, state_machine_regs
.line
);
2275 else switch (op_code
)
2277 case DW_LNS_extended_op
:
2278 data
+= process_extended_line_op (data
, info
.li_default_is_stmt
);
2282 printf (_(" Copy\n"));
2285 case DW_LNS_advance_pc
:
2286 uladv
= read_leb128 (data
, & bytes_read
, 0);
2287 uladv
*= info
.li_min_insn_length
;
2289 state_machine_regs
.address
+= uladv
;
2290 printf (_(" Advance PC by %lu to 0x%lx\n"), uladv
,
2291 state_machine_regs
.address
);
2294 case DW_LNS_advance_line
:
2295 adv
= read_leb128 (data
, & bytes_read
, 1);
2297 state_machine_regs
.line
+= adv
;
2298 printf (_(" Advance Line by %d to %d\n"), adv
,
2299 state_machine_regs
.line
);
2302 case DW_LNS_set_file
:
2303 adv
= read_leb128 (data
, & bytes_read
, 0);
2305 printf (_(" Set File Name to entry %d in the File Name Table\n"),
2307 state_machine_regs
.file
= adv
;
2310 case DW_LNS_set_column
:
2311 uladv
= read_leb128 (data
, & bytes_read
, 0);
2313 printf (_(" Set column to %lu\n"), uladv
);
2314 state_machine_regs
.column
= uladv
;
2317 case DW_LNS_negate_stmt
:
2318 adv
= state_machine_regs
.is_stmt
;
2320 printf (_(" Set is_stmt to %d\n"), adv
);
2321 state_machine_regs
.is_stmt
= adv
;
2324 case DW_LNS_set_basic_block
:
2325 printf (_(" Set basic block\n"));
2326 state_machine_regs
.basic_block
= 1;
2329 case DW_LNS_const_add_pc
:
2330 uladv
= (((255 - info
.li_opcode_base
) / info
.li_line_range
)
2331 * info
.li_min_insn_length
);
2332 state_machine_regs
.address
+= uladv
;
2333 printf (_(" Advance PC by constant %lu to 0x%lx\n"), uladv
,
2334 state_machine_regs
.address
);
2337 case DW_LNS_fixed_advance_pc
:
2338 uladv
= byte_get (data
, 2);
2340 state_machine_regs
.address
+= uladv
;
2341 printf (_(" Advance PC by fixed size amount %lu to 0x%lx\n"),
2342 uladv
, state_machine_regs
.address
);
2345 case DW_LNS_set_prologue_end
:
2346 printf (_(" Set prologue_end to true\n"));
2349 case DW_LNS_set_epilogue_begin
:
2350 printf (_(" Set epilogue_begin to true\n"));
2353 case DW_LNS_set_isa
:
2354 uladv
= read_leb128 (data
, & bytes_read
, 0);
2356 printf (_(" Set ISA to %lu\n"), uladv
);
2360 printf (_(" Unknown opcode %d with operands: "), op_code
);
2362 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
2364 printf ("0x%lx%s", read_leb128 (data
, &bytes_read
, 0),
2365 i
== 1 ? "" : ", ");
2380 unsigned char *name
;
2381 unsigned int directory_index
;
2382 unsigned int modification_date
;
2383 unsigned int length
;
2386 /* Output a decoded representation of the .debug_line section. */
2389 display_debug_lines_decoded (struct dwarf_section
*section
,
2390 unsigned char *data
,
2393 printf (_("Decoded dump of debug contents of section %s:\n\n"),
2398 /* This loop amounts to one iteration per compilation unit. */
2399 DWARF2_Internal_LineInfo info
;
2400 unsigned char *standard_opcodes
;
2401 unsigned char *end_of_sequence
;
2402 unsigned char *hdrptr
;
2403 int initial_length_size
;
2406 File_Entry
*file_table
= NULL
;
2407 unsigned char **directory_table
= NULL
;
2408 unsigned int prev_line
= 0;
2412 /* Extract information from the Line Number Program Header.
2413 (section 6.2.4 in the Dwarf3 doc). */
2415 /* Get the length of this CU's line number information block. */
2416 info
.li_length
= byte_get (hdrptr
, 4);
2419 if (info
.li_length
== 0xffffffff)
2421 /* This section is 64-bit DWARF 3. */
2422 info
.li_length
= byte_get (hdrptr
, 8);
2425 initial_length_size
= 12;
2430 initial_length_size
= 4;
2433 if (info
.li_length
+ initial_length_size
> section
->size
)
2435 warn (_("The line info appears to be corrupt - "
2436 "the section is too small\n"));
2440 /* Get this CU's Line Number Block version number. */
2441 info
.li_version
= byte_get (hdrptr
, 2);
2443 if (info
.li_version
!= 2 && info
.li_version
!= 3)
2445 warn (_("Only DWARF version 2 and 3 line info is currently "
2450 info
.li_prologue_length
= byte_get (hdrptr
, offset_size
);
2451 hdrptr
+= offset_size
;
2452 info
.li_min_insn_length
= byte_get (hdrptr
, 1);
2454 info
.li_default_is_stmt
= byte_get (hdrptr
, 1);
2456 info
.li_line_base
= byte_get (hdrptr
, 1);
2458 info
.li_line_range
= byte_get (hdrptr
, 1);
2460 info
.li_opcode_base
= byte_get (hdrptr
, 1);
2463 /* Sign extend the line base field. */
2464 info
.li_line_base
<<= 24;
2465 info
.li_line_base
>>= 24;
2467 /* Find the end of this CU's Line Number Information Block. */
2468 end_of_sequence
= data
+ info
.li_length
+ initial_length_size
;
2470 reset_state_machine (info
.li_default_is_stmt
);
2472 /* Save a pointer to the contents of the Opcodes table. */
2473 standard_opcodes
= hdrptr
;
2475 /* Traverse the Directory table just to count entries. */
2476 data
= standard_opcodes
+ info
.li_opcode_base
- 1;
2479 unsigned int n_directories
= 0;
2480 unsigned char *ptr_directory_table
= data
;
2485 data
+= strlen ((char *) data
) + 1;
2489 /* Go through the directory table again to save the directories. */
2490 directory_table
= xmalloc (n_directories
* sizeof (unsigned char *));
2493 while (*ptr_directory_table
!= 0)
2495 directory_table
[i
] = ptr_directory_table
;
2496 ptr_directory_table
+= strlen ((char *) ptr_directory_table
) + 1;
2500 /* Skip the NUL at the end of the table. */
2503 /* Traverse the File Name table just to count the entries. */
2506 unsigned int n_files
= 0;
2507 unsigned char *ptr_file_name_table
= data
;
2512 unsigned int bytes_read
;
2514 /* Skip Name, directory index, last modification time and length
2516 data
+= strlen ((char *) data
) + 1;
2517 read_leb128 (data
, & bytes_read
, 0);
2519 read_leb128 (data
, & bytes_read
, 0);
2521 read_leb128 (data
, & bytes_read
, 0);
2527 /* Go through the file table again to save the strings. */
2528 file_table
= xmalloc (n_files
* sizeof (File_Entry
));
2531 while (*ptr_file_name_table
!= 0)
2533 unsigned int bytes_read
;
2535 file_table
[i
].name
= ptr_file_name_table
;
2536 ptr_file_name_table
+= strlen ((char *) ptr_file_name_table
) + 1;
2538 /* We are not interested in directory, time or size. */
2539 file_table
[i
].directory_index
= read_leb128 (ptr_file_name_table
,
2541 ptr_file_name_table
+= bytes_read
;
2542 file_table
[i
].modification_date
= read_leb128 (ptr_file_name_table
,
2544 ptr_file_name_table
+= bytes_read
;
2545 file_table
[i
].length
= read_leb128 (ptr_file_name_table
, & bytes_read
, 0);
2546 ptr_file_name_table
+= bytes_read
;
2551 /* Print the Compilation Unit's name and a header. */
2552 if (directory_table
== NULL
)
2554 printf (_("CU: %s:\n"), file_table
[0].name
);
2555 printf (_("File name Line number Starting address\n"));
2559 if (do_wide
|| strlen ((char *) directory_table
[0]) < 76)
2561 printf (_("CU: %s/%s:\n"), directory_table
[0],
2562 file_table
[0].name
);
2566 printf (_("%s:\n"), file_table
[0].name
);
2568 printf (_("File name Line number Starting address\n"));
2572 /* Skip the NUL at the end of the table. */
2575 /* This loop iterates through the Dwarf Line Number Program. */
2576 while (data
< end_of_sequence
)
2578 unsigned char op_code
;
2580 unsigned long int uladv
;
2581 unsigned int bytes_read
;
2582 int is_special_opcode
= 0;
2585 prev_line
= state_machine_regs
.line
;
2587 if (op_code
>= info
.li_opcode_base
)
2589 op_code
-= info
.li_opcode_base
;
2590 uladv
= (op_code
/ info
.li_line_range
) * info
.li_min_insn_length
;
2591 state_machine_regs
.address
+= uladv
;
2593 adv
= (op_code
% info
.li_line_range
) + info
.li_line_base
;
2594 state_machine_regs
.line
+= adv
;
2595 is_special_opcode
= 1;
2597 else switch (op_code
)
2599 case DW_LNS_extended_op
:
2601 unsigned int ext_op_code_len
;
2602 unsigned int bytes_read
;
2603 unsigned char ext_op_code
;
2604 unsigned char *op_code_data
= data
;
2606 ext_op_code_len
= read_leb128 (op_code_data
, &bytes_read
, 0);
2607 op_code_data
+= bytes_read
;
2609 if (ext_op_code_len
== 0)
2611 warn (_("badly formed extended line op encountered!\n"));
2614 ext_op_code_len
+= bytes_read
;
2615 ext_op_code
= *op_code_data
++;
2617 switch (ext_op_code
)
2619 case DW_LNE_end_sequence
:
2620 reset_state_machine (info
.li_default_is_stmt
);
2622 case DW_LNE_set_address
:
2623 state_machine_regs
.address
=
2624 byte_get (op_code_data
, ext_op_code_len
- bytes_read
- 1);
2626 case DW_LNE_define_file
:
2628 unsigned int dir_index
= 0;
2630 ++state_machine_regs
.last_file_entry
;
2631 op_code_data
+= strlen ((char *) op_code_data
) + 1;
2632 dir_index
= read_leb128 (op_code_data
, & bytes_read
, 0);
2633 op_code_data
+= bytes_read
;
2634 read_leb128 (op_code_data
, & bytes_read
, 0);
2635 op_code_data
+= bytes_read
;
2636 read_leb128 (op_code_data
, & bytes_read
, 0);
2638 printf (_("%s:\n"), directory_table
[dir_index
]);
2642 printf (_("UNKNOWN: length %d\n"), ext_op_code_len
- bytes_read
);
2645 data
+= ext_op_code_len
;
2651 case DW_LNS_advance_pc
:
2652 uladv
= read_leb128 (data
, & bytes_read
, 0);
2653 uladv
*= info
.li_min_insn_length
;
2655 state_machine_regs
.address
+= uladv
;
2658 case DW_LNS_advance_line
:
2659 adv
= read_leb128 (data
, & bytes_read
, 1);
2661 state_machine_regs
.line
+= adv
;
2664 case DW_LNS_set_file
:
2665 adv
= read_leb128 (data
, & bytes_read
, 0);
2667 state_machine_regs
.file
= adv
;
2668 if (file_table
[state_machine_regs
.file
- 1].directory_index
== 0)
2670 /* If directory index is 0, that means current directory. */
2671 printf (_("\n./%s:[++]\n"),
2672 file_table
[state_machine_regs
.file
- 1].name
);
2676 /* The directory index starts counting at 1. */
2677 printf (_("\n%s/%s:\n"),
2678 directory_table
[file_table
[state_machine_regs
.file
- 1].directory_index
- 1],
2679 file_table
[state_machine_regs
.file
- 1].name
);
2683 case DW_LNS_set_column
:
2684 uladv
= read_leb128 (data
, & bytes_read
, 0);
2686 state_machine_regs
.column
= uladv
;
2689 case DW_LNS_negate_stmt
:
2690 adv
= state_machine_regs
.is_stmt
;
2692 state_machine_regs
.is_stmt
= adv
;
2695 case DW_LNS_set_basic_block
:
2696 state_machine_regs
.basic_block
= 1;
2699 case DW_LNS_const_add_pc
:
2700 uladv
= (((255 - info
.li_opcode_base
) / info
.li_line_range
)
2701 * info
.li_min_insn_length
);
2702 state_machine_regs
.address
+= uladv
;
2705 case DW_LNS_fixed_advance_pc
:
2706 uladv
= byte_get (data
, 2);
2708 state_machine_regs
.address
+= uladv
;
2711 case DW_LNS_set_prologue_end
:
2714 case DW_LNS_set_epilogue_begin
:
2717 case DW_LNS_set_isa
:
2718 uladv
= read_leb128 (data
, & bytes_read
, 0);
2720 printf (_(" Set ISA to %lu\n"), uladv
);
2724 printf (_(" Unknown opcode %d with operands: "), op_code
);
2726 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
2728 printf ("0x%lx%s", read_leb128 (data
, &bytes_read
, 0),
2729 i
== 1 ? "" : ", ");
2736 /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row
2737 to the DWARF address/line matrix. */
2738 if ((is_special_opcode
) || (op_code
== DW_LNE_end_sequence
)
2739 || (op_code
== DW_LNS_copy
))
2741 const unsigned int MAX_FILENAME_LENGTH
= 35;
2742 char *fileName
= (char *)file_table
[state_machine_regs
.file
- 1].name
;
2743 char *newFileName
= NULL
;
2744 size_t fileNameLength
= strlen (fileName
);
2746 if ((fileNameLength
> MAX_FILENAME_LENGTH
) && (!do_wide
))
2748 newFileName
= xmalloc (MAX_FILENAME_LENGTH
+ 1);
2749 /* Truncate file name */
2750 strncpy (newFileName
,
2751 fileName
+ fileNameLength
- MAX_FILENAME_LENGTH
,
2752 MAX_FILENAME_LENGTH
+ 1);
2756 newFileName
= xmalloc (fileNameLength
+ 1);
2757 strncpy (newFileName
, fileName
, fileNameLength
+ 1);
2760 if (!do_wide
|| (fileNameLength
<= MAX_FILENAME_LENGTH
))
2762 printf (_("%-35s %11d %#18lx\n"), newFileName
,
2763 state_machine_regs
.line
, state_machine_regs
.address
);
2767 printf (_("%s %11d %#18lx\n"), newFileName
,
2768 state_machine_regs
.line
, state_machine_regs
.address
);
2771 if (op_code
== DW_LNE_end_sequence
)
2779 free (directory_table
);
2780 directory_table
= NULL
;
2788 display_debug_lines (struct dwarf_section
*section
, void *file
)
2790 unsigned char *data
= section
->start
;
2791 unsigned char *end
= data
+ section
->size
;
2793 int retValDecoded
= 1;
2795 if (load_debug_info (file
) == 0)
2797 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
2802 if (do_debug_lines
& FLAG_DEBUG_LINES_RAW
)
2803 retValRaw
= display_debug_lines_raw (section
, data
, end
);
2805 if (do_debug_lines
& FLAG_DEBUG_LINES_DECODED
)
2806 retValDecoded
= display_debug_lines_decoded (section
, data
, end
);
2808 if (!retValRaw
|| !retValDecoded
)
2815 find_debug_info_for_offset (unsigned long offset
)
2819 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
2822 for (i
= 0; i
< num_debug_info_entries
; i
++)
2823 if (debug_information
[i
].cu_offset
== offset
)
2824 return debug_information
+ i
;
2830 display_debug_pubnames (struct dwarf_section
*section
,
2831 void *file ATTRIBUTE_UNUSED
)
2833 DWARF2_Internal_PubNames pubnames
;
2834 unsigned char *start
= section
->start
;
2835 unsigned char *end
= start
+ section
->size
;
2837 /* It does not matter if this load fails,
2838 we test for that later on. */
2839 load_debug_info (file
);
2841 printf (_("Contents of the %s section:\n\n"), section
->name
);
2845 unsigned char *data
;
2846 unsigned long offset
;
2847 int offset_size
, initial_length_size
;
2851 pubnames
.pn_length
= byte_get (data
, 4);
2853 if (pubnames
.pn_length
== 0xffffffff)
2855 pubnames
.pn_length
= byte_get (data
, 8);
2858 initial_length_size
= 12;
2863 initial_length_size
= 4;
2866 pubnames
.pn_version
= byte_get (data
, 2);
2869 pubnames
.pn_offset
= byte_get (data
, offset_size
);
2870 data
+= offset_size
;
2872 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
2873 && num_debug_info_entries
> 0
2874 && find_debug_info_for_offset (pubnames
.pn_offset
) == NULL
)
2875 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
2876 pubnames
.pn_offset
, section
->name
);
2878 pubnames
.pn_size
= byte_get (data
, offset_size
);
2879 data
+= offset_size
;
2881 start
+= pubnames
.pn_length
+ initial_length_size
;
2883 if (pubnames
.pn_version
!= 2 && pubnames
.pn_version
!= 3)
2885 static int warned
= 0;
2889 warn (_("Only DWARF 2 and 3 pubnames are currently supported\n"));
2896 printf (_(" Length: %ld\n"),
2897 pubnames
.pn_length
);
2898 printf (_(" Version: %d\n"),
2899 pubnames
.pn_version
);
2900 printf (_(" Offset into .debug_info section: 0x%lx\n"),
2901 pubnames
.pn_offset
);
2902 printf (_(" Size of area in .debug_info section: %ld\n"),
2905 printf (_("\n Offset\tName\n"));
2909 offset
= byte_get (data
, offset_size
);
2913 data
+= offset_size
;
2914 printf (" %-6lx\t%s\n", offset
, data
);
2915 data
+= strlen ((char *) data
) + 1;
2918 while (offset
!= 0);
2926 display_debug_macinfo (struct dwarf_section
*section
,
2927 void *file ATTRIBUTE_UNUSED
)
2929 unsigned char *start
= section
->start
;
2930 unsigned char *end
= start
+ section
->size
;
2931 unsigned char *curr
= start
;
2932 unsigned int bytes_read
;
2933 enum dwarf_macinfo_record_type op
;
2935 printf (_("Contents of the %s section:\n\n"), section
->name
);
2939 unsigned int lineno
;
2947 case DW_MACINFO_start_file
:
2949 unsigned int filenum
;
2951 lineno
= read_leb128 (curr
, & bytes_read
, 0);
2953 filenum
= read_leb128 (curr
, & bytes_read
, 0);
2956 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"),
2961 case DW_MACINFO_end_file
:
2962 printf (_(" DW_MACINFO_end_file\n"));
2965 case DW_MACINFO_define
:
2966 lineno
= read_leb128 (curr
, & bytes_read
, 0);
2968 string
= (char *) curr
;
2969 curr
+= strlen (string
) + 1;
2970 printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"),
2974 case DW_MACINFO_undef
:
2975 lineno
= read_leb128 (curr
, & bytes_read
, 0);
2977 string
= (char *) curr
;
2978 curr
+= strlen (string
) + 1;
2979 printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"),
2983 case DW_MACINFO_vendor_ext
:
2985 unsigned int constant
;
2987 constant
= read_leb128 (curr
, & bytes_read
, 0);
2989 string
= (char *) curr
;
2990 curr
+= strlen (string
) + 1;
2991 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"),
3002 display_debug_abbrev (struct dwarf_section
*section
,
3003 void *file ATTRIBUTE_UNUSED
)
3005 abbrev_entry
*entry
;
3006 unsigned char *start
= section
->start
;
3007 unsigned char *end
= start
+ section
->size
;
3009 printf (_("Contents of the %s section:\n\n"), section
->name
);
3015 start
= process_abbrev_section (start
, end
);
3017 if (first_abbrev
== NULL
)
3020 printf (_(" Number TAG\n"));
3022 for (entry
= first_abbrev
; entry
; entry
= entry
->next
)
3026 printf (_(" %ld %s [%s]\n"),
3028 get_TAG_name (entry
->tag
),
3029 entry
->children
? _("has children") : _("no children"));
3031 for (attr
= entry
->first_attr
; attr
; attr
= attr
->next
)
3032 printf (_(" %-18s %s\n"),
3033 get_AT_name (attr
->attribute
),
3034 get_FORM_name (attr
->form
));
3045 display_debug_loc (struct dwarf_section
*section
, void *file
)
3047 unsigned char *start
= section
->start
;
3048 unsigned char *section_end
;
3049 unsigned long bytes
;
3050 unsigned char *section_begin
= start
;
3051 unsigned int num_loc_list
= 0;
3052 unsigned long last_offset
= 0;
3053 unsigned int first
= 0;
3056 int seen_first_offset
= 0;
3057 int use_debug_info
= 1;
3058 unsigned char *next
;
3060 bytes
= section
->size
;
3061 section_end
= start
+ bytes
;
3065 printf (_("\nThe %s section is empty.\n"), section
->name
);
3069 if (load_debug_info (file
) == 0)
3071 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
3076 /* Check the order of location list in .debug_info section. If
3077 offsets of location lists are in the ascending order, we can
3078 use `debug_information' directly. */
3079 for (i
= 0; i
< num_debug_info_entries
; i
++)
3083 num
= debug_information
[i
].num_loc_offsets
;
3084 num_loc_list
+= num
;
3086 /* Check if we can use `debug_information' directly. */
3087 if (use_debug_info
&& num
!= 0)
3089 if (!seen_first_offset
)
3091 /* This is the first location list. */
3092 last_offset
= debug_information
[i
].loc_offsets
[0];
3094 seen_first_offset
= 1;
3100 for (; j
< num
; j
++)
3103 debug_information
[i
].loc_offsets
[j
])
3108 last_offset
= debug_information
[i
].loc_offsets
[j
];
3113 if (!use_debug_info
)
3114 /* FIXME: Should we handle this case? */
3115 error (_("Location lists in .debug_info section aren't in ascending order!\n"));
3117 if (!seen_first_offset
)
3118 error (_("No location lists in .debug_info section!\n"));
3120 /* DWARF sections under Mach-O have non-zero addresses. */
3121 if (debug_information
[first
].num_loc_offsets
> 0
3122 && debug_information
[first
].loc_offsets
[0] != section
->address
)
3123 warn (_("Location lists in %s section start at 0x%lx\n"),
3124 section
->name
, debug_information
[first
].loc_offsets
[0]);
3126 printf (_("Contents of the %s section:\n\n"), section
->name
);
3127 printf (_(" Offset Begin End Expression\n"));
3129 seen_first_offset
= 0;
3130 for (i
= first
; i
< num_debug_info_entries
; i
++)
3134 unsigned short length
;
3135 unsigned long offset
;
3136 unsigned int pointer_size
;
3137 unsigned long cu_offset
;
3138 unsigned long base_address
;
3139 int need_frame_base
;
3142 pointer_size
= debug_information
[i
].pointer_size
;
3143 cu_offset
= debug_information
[i
].cu_offset
;
3145 for (j
= 0; j
< debug_information
[i
].num_loc_offsets
; j
++)
3147 has_frame_base
= debug_information
[i
].have_frame_base
[j
];
3148 /* DWARF sections under Mach-O have non-zero addresses. */
3149 offset
= debug_information
[i
].loc_offsets
[j
] - section
->address
;
3150 next
= section_begin
+ offset
;
3151 base_address
= debug_information
[i
].base_address
;
3153 if (!seen_first_offset
)
3154 seen_first_offset
= 1;
3158 warn (_("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n"),
3159 (unsigned long) (start
- section_begin
),
3160 (unsigned long) (next
- section_begin
));
3161 else if (start
> next
)
3162 warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n"),
3163 (unsigned long) (start
- section_begin
),
3164 (unsigned long) (next
- section_begin
));
3168 if (offset
>= bytes
)
3170 warn (_("Offset 0x%lx is bigger than .debug_loc section size.\n"),
3177 if (start
+ 2 * pointer_size
> section_end
)
3179 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
3184 /* Note: we use sign extension here in order to be sure that
3185 we can detect the -1 escape value. Sign extension into the
3186 top 32 bits of a 32-bit address will not affect the values
3187 that we display since we always show hex values, and always
3188 the bottom 32-bits. */
3189 begin
= byte_get_signed (start
, pointer_size
);
3190 start
+= pointer_size
;
3191 end
= byte_get_signed (start
, pointer_size
);
3192 start
+= pointer_size
;
3194 printf (" %8.8lx ", offset
);
3196 if (begin
== 0 && end
== 0)
3198 printf (_("<End of list>\n"));
3202 /* Check base address specifiers. */
3203 if (begin
== (dwarf_vma
) -1 && end
!= (dwarf_vma
) -1)
3206 print_dwarf_vma (begin
, pointer_size
);
3207 print_dwarf_vma (end
, pointer_size
);
3208 printf (_("(base address)\n"));
3212 if (start
+ 2 > section_end
)
3214 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
3219 length
= byte_get (start
, 2);
3222 if (start
+ length
> section_end
)
3224 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
3229 print_dwarf_vma (begin
+ base_address
, pointer_size
);
3230 print_dwarf_vma (end
+ base_address
, pointer_size
);
3233 need_frame_base
= decode_location_expression (start
,
3236 cu_offset
, section
);
3239 if (need_frame_base
&& !has_frame_base
)
3240 printf (_(" [without DW_AT_frame_base]"));
3243 fputs (_(" (start == end)"), stdout
);
3244 else if (begin
> end
)
3245 fputs (_(" (start > end)"), stdout
);
3254 if (start
< section_end
)
3255 warn (_("There are %ld unused bytes at the end of section %s\n"),
3256 (long) (section_end
- start
), section
->name
);
3262 display_debug_str (struct dwarf_section
*section
,
3263 void *file ATTRIBUTE_UNUSED
)
3265 unsigned char *start
= section
->start
;
3266 unsigned long bytes
= section
->size
;
3267 dwarf_vma addr
= section
->address
;
3271 printf (_("\nThe %s section is empty.\n"), section
->name
);
3275 printf (_("Contents of the %s section:\n\n"), section
->name
);
3283 lbytes
= (bytes
> 16 ? 16 : bytes
);
3285 printf (" 0x%8.8lx ", (unsigned long) addr
);
3287 for (j
= 0; j
< 16; j
++)
3290 printf ("%2.2x", start
[j
]);
3298 for (j
= 0; j
< lbytes
; j
++)
3301 if (k
>= ' ' && k
< 0x80)
3320 display_debug_info (struct dwarf_section
*section
, void *file
)
3322 return process_debug_info (section
, file
, 0);
3327 display_debug_aranges (struct dwarf_section
*section
,
3328 void *file ATTRIBUTE_UNUSED
)
3330 unsigned char *start
= section
->start
;
3331 unsigned char *end
= start
+ section
->size
;
3333 printf (_("Contents of the %s section:\n\n"), section
->name
);
3335 /* It does not matter if this load fails,
3336 we test for that later on. */
3337 load_debug_info (file
);
3341 unsigned char *hdrptr
;
3342 DWARF2_Internal_ARange arange
;
3343 unsigned char *ranges
;
3346 unsigned char address_size
;
3349 int initial_length_size
;
3353 arange
.ar_length
= byte_get (hdrptr
, 4);
3356 if (arange
.ar_length
== 0xffffffff)
3358 arange
.ar_length
= byte_get (hdrptr
, 8);
3361 initial_length_size
= 12;
3366 initial_length_size
= 4;
3369 arange
.ar_version
= byte_get (hdrptr
, 2);
3372 arange
.ar_info_offset
= byte_get (hdrptr
, offset_size
);
3373 hdrptr
+= offset_size
;
3375 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
3376 && num_debug_info_entries
> 0
3377 && find_debug_info_for_offset (arange
.ar_info_offset
) == NULL
)
3378 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
3379 arange
.ar_info_offset
, section
->name
);
3381 arange
.ar_pointer_size
= byte_get (hdrptr
, 1);
3384 arange
.ar_segment_size
= byte_get (hdrptr
, 1);
3387 if (arange
.ar_version
!= 2 && arange
.ar_version
!= 3)
3389 warn (_("Only DWARF 2 and 3 aranges are currently supported.\n"));
3393 printf (_(" Length: %ld\n"), arange
.ar_length
);
3394 printf (_(" Version: %d\n"), arange
.ar_version
);
3395 printf (_(" Offset into .debug_info: 0x%lx\n"), arange
.ar_info_offset
);
3396 printf (_(" Pointer Size: %d\n"), arange
.ar_pointer_size
);
3397 printf (_(" Segment Size: %d\n"), arange
.ar_segment_size
);
3399 address_size
= arange
.ar_pointer_size
+ arange
.ar_segment_size
;
3401 /* The DWARF spec does not require that the address size be a power
3402 of two, but we do. This will have to change if we ever encounter
3403 an uneven architecture. */
3404 if ((address_size
& (address_size
- 1)) != 0)
3406 warn (_("Pointer size + Segment size is not a power of two.\n"));
3410 if (address_size
> 4)
3411 printf (_("\n Address Length\n"));
3413 printf (_("\n Address Length\n"));
3417 /* Must pad to an alignment boundary that is twice the address size. */
3418 excess
= (hdrptr
- start
) % (2 * address_size
);
3420 ranges
+= (2 * address_size
) - excess
;
3422 start
+= arange
.ar_length
+ initial_length_size
;
3424 while (ranges
+ 2 * address_size
<= start
)
3426 address
= byte_get (ranges
, address_size
);
3428 ranges
+= address_size
;
3430 length
= byte_get (ranges
, address_size
);
3432 ranges
+= address_size
;
3435 print_dwarf_vma (address
, address_size
);
3436 print_dwarf_vma (length
, address_size
);
3447 display_debug_ranges (struct dwarf_section
*section
,
3448 void *file ATTRIBUTE_UNUSED
)
3450 unsigned char *start
= section
->start
;
3451 unsigned char *section_end
;
3452 unsigned long bytes
;
3453 unsigned char *section_begin
= start
;
3454 unsigned int num_range_list
= 0;
3455 unsigned long last_offset
= 0;
3456 unsigned int first
= 0;
3459 int seen_first_offset
= 0;
3460 int use_debug_info
= 1;
3461 unsigned char *next
;
3463 bytes
= section
->size
;
3464 section_end
= start
+ bytes
;
3468 printf (_("\nThe %s section is empty.\n"), section
->name
);
3472 if (load_debug_info (file
) == 0)
3474 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
3479 /* Check the order of range list in .debug_info section. If
3480 offsets of range lists are in the ascending order, we can
3481 use `debug_information' directly. */
3482 for (i
= 0; i
< num_debug_info_entries
; i
++)
3486 num
= debug_information
[i
].num_range_lists
;
3487 num_range_list
+= num
;
3489 /* Check if we can use `debug_information' directly. */
3490 if (use_debug_info
&& num
!= 0)
3492 if (!seen_first_offset
)
3494 /* This is the first range list. */
3495 last_offset
= debug_information
[i
].range_lists
[0];
3497 seen_first_offset
= 1;
3503 for (; j
< num
; j
++)
3506 debug_information
[i
].range_lists
[j
])
3511 last_offset
= debug_information
[i
].range_lists
[j
];
3516 if (!use_debug_info
)
3517 /* FIXME: Should we handle this case? */
3518 error (_("Range lists in .debug_info section aren't in ascending order!\n"));
3520 if (!seen_first_offset
)
3521 error (_("No range lists in .debug_info section!\n"));
3523 /* DWARF sections under Mach-O have non-zero addresses. */
3524 if (debug_information
[first
].num_range_lists
> 0
3525 && debug_information
[first
].range_lists
[0] != section
->address
)
3526 warn (_("Range lists in %s section start at 0x%lx\n"),
3527 section
->name
, debug_information
[first
].range_lists
[0]);
3529 printf (_("Contents of the %s section:\n\n"), section
->name
);
3530 printf (_(" Offset Begin End\n"));
3532 seen_first_offset
= 0;
3533 for (i
= first
; i
< num_debug_info_entries
; i
++)
3537 unsigned long offset
;
3538 unsigned int pointer_size
;
3539 unsigned long base_address
;
3541 pointer_size
= debug_information
[i
].pointer_size
;
3543 for (j
= 0; j
< debug_information
[i
].num_range_lists
; j
++)
3545 /* DWARF sections under Mach-O have non-zero addresses. */
3546 offset
= debug_information
[i
].range_lists
[j
] - section
->address
;
3547 next
= section_begin
+ offset
;
3548 base_address
= debug_information
[i
].base_address
;
3550 if (!seen_first_offset
)
3551 seen_first_offset
= 1;
3555 warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"),
3556 (unsigned long) (start
- section_begin
),
3557 (unsigned long) (next
- section_begin
), section
->name
);
3558 else if (start
> next
)
3559 warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"),
3560 (unsigned long) (start
- section_begin
),
3561 (unsigned long) (next
- section_begin
), section
->name
);
3567 /* Note: we use sign extension here in order to be sure that
3568 we can detect the -1 escape value. Sign extension into the
3569 top 32 bits of a 32-bit address will not affect the values
3570 that we display since we always show hex values, and always
3571 the bottom 32-bits. */
3572 begin
= byte_get_signed (start
, pointer_size
);
3573 start
+= pointer_size
;
3574 end
= byte_get_signed (start
, pointer_size
);
3575 start
+= pointer_size
;
3577 printf (" %8.8lx ", offset
);
3579 if (begin
== 0 && end
== 0)
3581 printf (_("<End of list>\n"));
3585 /* Check base address specifiers. */
3586 if (begin
== (dwarf_vma
) -1 && end
!= (dwarf_vma
) -1)
3589 print_dwarf_vma (begin
, pointer_size
);
3590 print_dwarf_vma (end
, pointer_size
);
3591 printf ("(base address)\n");
3595 print_dwarf_vma (begin
+ base_address
, pointer_size
);
3596 print_dwarf_vma (end
+ base_address
, pointer_size
);
3599 fputs (_("(start == end)"), stdout
);
3600 else if (begin
> end
)
3601 fputs (_("(start > end)"), stdout
);
3611 typedef struct Frame_Chunk
3613 struct Frame_Chunk
*next
;
3614 unsigned char *chunk_start
;
3616 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
3617 short int *col_type
;
3620 unsigned int code_factor
;
3622 unsigned long pc_begin
;
3623 unsigned long pc_range
;
3627 unsigned char fde_encoding
;
3628 unsigned char cfa_exp
;
3632 static const char *const *dwarf_regnames
;
3633 static unsigned int dwarf_regnames_count
;
3635 /* A marker for a col_type that means this column was never referenced
3636 in the frame info. */
3637 #define DW_CFA_unreferenced (-1)
3639 /* Return 0 if not more space is needed, 1 if more space is needed,
3640 -1 for invalid reg. */
3643 frame_need_space (Frame_Chunk
*fc
, unsigned int reg
)
3645 int prev
= fc
->ncols
;
3647 if (reg
< (unsigned int) fc
->ncols
)
3650 if (dwarf_regnames_count
3651 && reg
> dwarf_regnames_count
)
3654 fc
->ncols
= reg
+ 1;
3655 fc
->col_type
= xcrealloc (fc
->col_type
, fc
->ncols
, sizeof (short int));
3656 fc
->col_offset
= xcrealloc (fc
->col_offset
, fc
->ncols
, sizeof (int));
3658 while (prev
< fc
->ncols
)
3660 fc
->col_type
[prev
] = DW_CFA_unreferenced
;
3661 fc
->col_offset
[prev
] = 0;
3667 static const char *const dwarf_regnames_i386
[] =
3669 "eax", "ecx", "edx", "ebx",
3670 "esp", "ebp", "esi", "edi",
3671 "eip", "eflags", NULL
,
3672 "st0", "st1", "st2", "st3",
3673 "st4", "st5", "st6", "st7",
3675 "xmm0", "xmm1", "xmm2", "xmm3",
3676 "xmm4", "xmm5", "xmm6", "xmm7",
3677 "mm0", "mm1", "mm2", "mm3",
3678 "mm4", "mm5", "mm6", "mm7",
3679 "fcw", "fsw", "mxcsr",
3680 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
,
3684 static const char *const dwarf_regnames_x86_64
[] =
3686 "rax", "rdx", "rcx", "rbx",
3687 "rsi", "rdi", "rbp", "rsp",
3688 "r8", "r9", "r10", "r11",
3689 "r12", "r13", "r14", "r15",
3691 "xmm0", "xmm1", "xmm2", "xmm3",
3692 "xmm4", "xmm5", "xmm6", "xmm7",
3693 "xmm8", "xmm9", "xmm10", "xmm11",
3694 "xmm12", "xmm13", "xmm14", "xmm15",
3695 "st0", "st1", "st2", "st3",
3696 "st4", "st5", "st6", "st7",
3697 "mm0", "mm1", "mm2", "mm3",
3698 "mm4", "mm5", "mm6", "mm7",
3700 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
,
3701 "fs.base", "gs.base", NULL
, NULL
,
3703 "mxcsr", "fcw", "fsw"
3707 init_dwarf_regnames (unsigned int e_machine
)
3713 dwarf_regnames
= dwarf_regnames_i386
;
3714 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_i386
);
3718 dwarf_regnames
= dwarf_regnames_x86_64
;
3719 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_x86_64
);
3728 regname (unsigned int regno
, int row
)
3730 static char reg
[64];
3732 && regno
< dwarf_regnames_count
3733 && dwarf_regnames
[regno
] != NULL
)
3736 return dwarf_regnames
[regno
];
3737 snprintf (reg
, sizeof (reg
), "r%d (%s)", regno
,
3738 dwarf_regnames
[regno
]);
3741 snprintf (reg
, sizeof (reg
), "r%d", regno
);
3746 frame_display_row (Frame_Chunk
*fc
, int *need_col_headers
, int *max_regs
)
3751 if (*max_regs
< fc
->ncols
)
3752 *max_regs
= fc
->ncols
;
3754 if (*need_col_headers
)
3756 static const char *loc
= " LOC";
3758 *need_col_headers
= 0;
3760 printf ("%-*s CFA ", eh_addr_size
* 2, loc
);
3762 for (r
= 0; r
< *max_regs
; r
++)
3763 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
3768 printf ("%-5s ", regname (r
, 1));
3774 printf ("%0*lx ", eh_addr_size
* 2, fc
->pc_begin
);
3776 strcpy (tmp
, "exp");
3778 sprintf (tmp
, "%s%+d", regname (fc
->cfa_reg
, 1), fc
->cfa_offset
);
3779 printf ("%-8s ", tmp
);
3781 for (r
= 0; r
< fc
->ncols
; r
++)
3783 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
3785 switch (fc
->col_type
[r
])
3787 case DW_CFA_undefined
:
3790 case DW_CFA_same_value
:
3794 sprintf (tmp
, "c%+d", fc
->col_offset
[r
]);
3796 case DW_CFA_val_offset
:
3797 sprintf (tmp
, "v%+d", fc
->col_offset
[r
]);
3799 case DW_CFA_register
:
3800 sprintf (tmp
, "%s", regname (fc
->col_offset
[r
], 0));
3802 case DW_CFA_expression
:
3803 strcpy (tmp
, "exp");
3805 case DW_CFA_val_expression
:
3806 strcpy (tmp
, "vexp");
3809 strcpy (tmp
, "n/a");
3812 printf ("%-5s ", tmp
);
3818 #define GET(N) byte_get (start, N); start += N
3819 #define LEB() read_leb128 (start, & length_return, 0); start += length_return
3820 #define SLEB() read_leb128 (start, & length_return, 1); start += length_return
3823 display_debug_frames (struct dwarf_section
*section
,
3824 void *file ATTRIBUTE_UNUSED
)
3826 unsigned char *start
= section
->start
;
3827 unsigned char *end
= start
+ section
->size
;
3828 unsigned char *section_start
= start
;
3829 Frame_Chunk
*chunks
= 0;
3830 Frame_Chunk
*remembered_state
= 0;
3832 int is_eh
= strcmp (section
->name
, ".eh_frame") == 0;
3833 unsigned int length_return
;
3835 const char *bad_reg
= _("bad register: ");
3837 printf (_("Contents of the %s section:\n"), section
->name
);
3841 unsigned char *saved_start
;
3842 unsigned char *block_end
;
3843 unsigned long length
;
3844 unsigned long cie_id
;
3847 int need_col_headers
= 1;
3848 unsigned char *augmentation_data
= NULL
;
3849 unsigned long augmentation_data_len
= 0;
3850 int encoded_ptr_size
= eh_addr_size
;
3852 int initial_length_size
;
3854 saved_start
= start
;
3855 length
= byte_get (start
, 4); start
+= 4;
3859 printf ("\n%08lx ZERO terminator\n\n",
3860 (unsigned long)(saved_start
- section_start
));
3864 if (length
== 0xffffffff)
3866 length
= byte_get (start
, 8);
3869 initial_length_size
= 12;
3874 initial_length_size
= 4;
3877 block_end
= saved_start
+ length
+ initial_length_size
;
3878 if (block_end
> end
)
3880 warn ("Invalid length %#08lx in FDE at %#08lx\n",
3881 length
, (unsigned long)(saved_start
- section_start
));
3884 cie_id
= byte_get (start
, offset_size
); start
+= offset_size
;
3886 if (is_eh
? (cie_id
== 0) : (cie_id
== DW_CIE_ID
))
3890 fc
= xmalloc (sizeof (Frame_Chunk
));
3891 memset (fc
, 0, sizeof (Frame_Chunk
));
3895 fc
->chunk_start
= saved_start
;
3897 fc
->col_type
= xmalloc (sizeof (short int));
3898 fc
->col_offset
= xmalloc (sizeof (int));
3899 frame_need_space (fc
, max_regs
- 1);
3903 fc
->augmentation
= (char *) start
;
3904 start
= (unsigned char *) strchr ((char *) start
, '\0') + 1;
3906 if (fc
->augmentation
[0] == 'z')
3908 fc
->code_factor
= LEB ();
3909 fc
->data_factor
= SLEB ();
3918 augmentation_data_len
= LEB ();
3919 augmentation_data
= start
;
3920 start
+= augmentation_data_len
;
3922 else if (strcmp (fc
->augmentation
, "eh") == 0)
3924 start
+= eh_addr_size
;
3925 fc
->code_factor
= LEB ();
3926 fc
->data_factor
= SLEB ();
3938 fc
->code_factor
= LEB ();
3939 fc
->data_factor
= SLEB ();
3951 if (do_debug_frames_interp
)
3952 printf ("\n%08lx %08lx %08lx CIE \"%s\" cf=%d df=%d ra=%d\n",
3953 (unsigned long)(saved_start
- section_start
), length
, cie_id
,
3954 fc
->augmentation
, fc
->code_factor
, fc
->data_factor
,
3958 printf ("\n%08lx %08lx %08lx CIE\n",
3959 (unsigned long)(saved_start
- section_start
), length
, cie_id
);
3960 printf (" Version: %d\n", version
);
3961 printf (" Augmentation: \"%s\"\n", fc
->augmentation
);
3962 printf (" Code alignment factor: %u\n", fc
->code_factor
);
3963 printf (" Data alignment factor: %d\n", fc
->data_factor
);
3964 printf (" Return address column: %d\n", fc
->ra
);
3966 if (augmentation_data_len
)
3969 printf (" Augmentation data: ");
3970 for (i
= 0; i
< augmentation_data_len
; ++i
)
3971 printf (" %02x", augmentation_data
[i
]);
3977 if (augmentation_data_len
)
3979 unsigned char *p
, *q
;
3980 p
= (unsigned char *) fc
->augmentation
+ 1;
3981 q
= augmentation_data
;
3988 q
+= 1 + size_of_encoded_value (*q
);
3990 fc
->fde_encoding
= *q
++;
3996 if (fc
->fde_encoding
)
3997 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
4000 frame_need_space (fc
, fc
->ra
);
4004 unsigned char *look_for
;
4005 static Frame_Chunk fde_fc
;
4008 memset (fc
, 0, sizeof (Frame_Chunk
));
4010 look_for
= is_eh
? start
- 4 - cie_id
: section_start
+ cie_id
;
4012 for (cie
= chunks
; cie
; cie
= cie
->next
)
4013 if (cie
->chunk_start
== look_for
)
4018 warn ("Invalid CIE pointer %#08lx in FDE at %#08lx\n",
4019 cie_id
, (unsigned long)(saved_start
- section_start
));
4021 fc
->col_type
= xmalloc (sizeof (short int));
4022 fc
->col_offset
= xmalloc (sizeof (int));
4023 frame_need_space (fc
, max_regs
- 1);
4025 fc
->augmentation
= "";
4026 fc
->fde_encoding
= 0;
4030 fc
->ncols
= cie
->ncols
;
4031 fc
->col_type
= xcmalloc (fc
->ncols
, sizeof (short int));
4032 fc
->col_offset
= xcmalloc (fc
->ncols
, sizeof (int));
4033 memcpy (fc
->col_type
, cie
->col_type
, fc
->ncols
* sizeof (short int));
4034 memcpy (fc
->col_offset
, cie
->col_offset
, fc
->ncols
* sizeof (int));
4035 fc
->augmentation
= cie
->augmentation
;
4036 fc
->code_factor
= cie
->code_factor
;
4037 fc
->data_factor
= cie
->data_factor
;
4038 fc
->cfa_reg
= cie
->cfa_reg
;
4039 fc
->cfa_offset
= cie
->cfa_offset
;
4041 frame_need_space (fc
, max_regs
- 1);
4042 fc
->fde_encoding
= cie
->fde_encoding
;
4045 if (fc
->fde_encoding
)
4046 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
4048 fc
->pc_begin
= get_encoded_value (start
, fc
->fde_encoding
);
4049 if ((fc
->fde_encoding
& 0x70) == DW_EH_PE_pcrel
)
4050 fc
->pc_begin
+= section
->address
+ (start
- section_start
);
4051 start
+= encoded_ptr_size
;
4052 fc
->pc_range
= byte_get (start
, encoded_ptr_size
);
4053 start
+= encoded_ptr_size
;
4055 if (cie
->augmentation
[0] == 'z')
4057 augmentation_data_len
= LEB ();
4058 augmentation_data
= start
;
4059 start
+= augmentation_data_len
;
4062 printf ("\n%08lx %08lx %08lx FDE cie=%08lx pc=%08lx..%08lx\n",
4063 (unsigned long)(saved_start
- section_start
), length
, cie_id
,
4064 (unsigned long)(cie
->chunk_start
- section_start
),
4065 fc
->pc_begin
, fc
->pc_begin
+ fc
->pc_range
);
4066 if (! do_debug_frames_interp
&& augmentation_data_len
)
4070 printf (" Augmentation data: ");
4071 for (i
= 0; i
< augmentation_data_len
; ++i
)
4072 printf (" %02x", augmentation_data
[i
]);
4078 /* At this point, fc is the current chunk, cie (if any) is set, and
4079 we're about to interpret instructions for the chunk. */
4080 /* ??? At present we need to do this always, since this sizes the
4081 fc->col_type and fc->col_offset arrays, which we write into always.
4082 We should probably split the interpreted and non-interpreted bits
4083 into two different routines, since there's so much that doesn't
4084 really overlap between them. */
4085 if (1 || do_debug_frames_interp
)
4087 /* Start by making a pass over the chunk, allocating storage
4088 and taking note of what registers are used. */
4089 unsigned char *tmp
= start
;
4091 while (start
< block_end
)
4094 unsigned long reg
, tmp
;
4101 /* Warning: if you add any more cases to this switch, be
4102 sure to add them to the corresponding switch below. */
4105 case DW_CFA_advance_loc
:
4109 if (frame_need_space (fc
, opa
) >= 0)
4110 fc
->col_type
[opa
] = DW_CFA_undefined
;
4112 case DW_CFA_restore
:
4113 if (frame_need_space (fc
, opa
) >= 0)
4114 fc
->col_type
[opa
] = DW_CFA_undefined
;
4116 case DW_CFA_set_loc
:
4117 start
+= encoded_ptr_size
;
4119 case DW_CFA_advance_loc1
:
4122 case DW_CFA_advance_loc2
:
4125 case DW_CFA_advance_loc4
:
4128 case DW_CFA_offset_extended
:
4129 case DW_CFA_val_offset
:
4130 reg
= LEB (); LEB ();
4131 if (frame_need_space (fc
, reg
) >= 0)
4132 fc
->col_type
[reg
] = DW_CFA_undefined
;
4134 case DW_CFA_restore_extended
:
4136 frame_need_space (fc
, reg
);
4137 if (frame_need_space (fc
, reg
) >= 0)
4138 fc
->col_type
[reg
] = DW_CFA_undefined
;
4140 case DW_CFA_undefined
:
4142 if (frame_need_space (fc
, reg
) >= 0)
4143 fc
->col_type
[reg
] = DW_CFA_undefined
;
4145 case DW_CFA_same_value
:
4147 if (frame_need_space (fc
, reg
) >= 0)
4148 fc
->col_type
[reg
] = DW_CFA_undefined
;
4150 case DW_CFA_register
:
4151 reg
= LEB (); LEB ();
4152 if (frame_need_space (fc
, reg
) >= 0)
4153 fc
->col_type
[reg
] = DW_CFA_undefined
;
4155 case DW_CFA_def_cfa
:
4158 case DW_CFA_def_cfa_register
:
4161 case DW_CFA_def_cfa_offset
:
4164 case DW_CFA_def_cfa_expression
:
4168 case DW_CFA_expression
:
4169 case DW_CFA_val_expression
:
4173 if (frame_need_space (fc
, reg
) >= 0)
4174 fc
->col_type
[reg
] = DW_CFA_undefined
;
4176 case DW_CFA_offset_extended_sf
:
4177 case DW_CFA_val_offset_sf
:
4178 reg
= LEB (); SLEB ();
4179 if (frame_need_space (fc
, reg
) >= 0)
4180 fc
->col_type
[reg
] = DW_CFA_undefined
;
4182 case DW_CFA_def_cfa_sf
:
4185 case DW_CFA_def_cfa_offset_sf
:
4188 case DW_CFA_MIPS_advance_loc8
:
4191 case DW_CFA_GNU_args_size
:
4194 case DW_CFA_GNU_negative_offset_extended
:
4195 reg
= LEB (); LEB ();
4196 if (frame_need_space (fc
, reg
) >= 0)
4197 fc
->col_type
[reg
] = DW_CFA_undefined
;
4206 /* Now we know what registers are used, make a second pass over
4207 the chunk, this time actually printing out the info. */
4209 while (start
< block_end
)
4212 unsigned long ul
, reg
, roffs
;
4215 const char *reg_prefix
= "";
4222 /* Warning: if you add any more cases to this switch, be
4223 sure to add them to the corresponding switch above. */
4226 case DW_CFA_advance_loc
:
4227 if (do_debug_frames_interp
)
4228 frame_display_row (fc
, &need_col_headers
, &max_regs
);
4230 printf (" DW_CFA_advance_loc: %d to %08lx\n",
4231 opa
* fc
->code_factor
,
4232 fc
->pc_begin
+ opa
* fc
->code_factor
);
4233 fc
->pc_begin
+= opa
* fc
->code_factor
;
4238 if (opa
>= (unsigned int) fc
->ncols
)
4239 reg_prefix
= bad_reg
;
4240 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4241 printf (" DW_CFA_offset: %s%s at cfa%+ld\n",
4242 reg_prefix
, regname (opa
, 0),
4243 roffs
* fc
->data_factor
);
4244 if (*reg_prefix
== '\0')
4246 fc
->col_type
[opa
] = DW_CFA_offset
;
4247 fc
->col_offset
[opa
] = roffs
* fc
->data_factor
;
4251 case DW_CFA_restore
:
4252 if (opa
>= (unsigned int) cie
->ncols
4253 || opa
>= (unsigned int) fc
->ncols
)
4254 reg_prefix
= bad_reg
;
4255 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4256 printf (" DW_CFA_restore: %s%s\n",
4257 reg_prefix
, regname (opa
, 0));
4258 if (*reg_prefix
== '\0')
4260 fc
->col_type
[opa
] = cie
->col_type
[opa
];
4261 fc
->col_offset
[opa
] = cie
->col_offset
[opa
];
4265 case DW_CFA_set_loc
:
4266 vma
= get_encoded_value (start
, fc
->fde_encoding
);
4267 if ((fc
->fde_encoding
& 0x70) == DW_EH_PE_pcrel
)
4268 vma
+= section
->address
+ (start
- section_start
);
4269 start
+= encoded_ptr_size
;
4270 if (do_debug_frames_interp
)
4271 frame_display_row (fc
, &need_col_headers
, &max_regs
);
4273 printf (" DW_CFA_set_loc: %08lx\n", (unsigned long)vma
);
4277 case DW_CFA_advance_loc1
:
4278 ofs
= byte_get (start
, 1); start
+= 1;
4279 if (do_debug_frames_interp
)
4280 frame_display_row (fc
, &need_col_headers
, &max_regs
);
4282 printf (" DW_CFA_advance_loc1: %ld to %08lx\n",
4283 ofs
* fc
->code_factor
,
4284 fc
->pc_begin
+ ofs
* fc
->code_factor
);
4285 fc
->pc_begin
+= ofs
* fc
->code_factor
;
4288 case DW_CFA_advance_loc2
:
4289 ofs
= byte_get (start
, 2); start
+= 2;
4290 if (do_debug_frames_interp
)
4291 frame_display_row (fc
, &need_col_headers
, &max_regs
);
4293 printf (" DW_CFA_advance_loc2: %ld to %08lx\n",
4294 ofs
* fc
->code_factor
,
4295 fc
->pc_begin
+ ofs
* fc
->code_factor
);
4296 fc
->pc_begin
+= ofs
* fc
->code_factor
;
4299 case DW_CFA_advance_loc4
:
4300 ofs
= byte_get (start
, 4); start
+= 4;
4301 if (do_debug_frames_interp
)
4302 frame_display_row (fc
, &need_col_headers
, &max_regs
);
4304 printf (" DW_CFA_advance_loc4: %ld to %08lx\n",
4305 ofs
* fc
->code_factor
,
4306 fc
->pc_begin
+ ofs
* fc
->code_factor
);
4307 fc
->pc_begin
+= ofs
* fc
->code_factor
;
4310 case DW_CFA_offset_extended
:
4313 if (reg
>= (unsigned int) fc
->ncols
)
4314 reg_prefix
= bad_reg
;
4315 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4316 printf (" DW_CFA_offset_extended: %s%s at cfa%+ld\n",
4317 reg_prefix
, regname (reg
, 0),
4318 roffs
* fc
->data_factor
);
4319 if (*reg_prefix
== '\0')
4321 fc
->col_type
[reg
] = DW_CFA_offset
;
4322 fc
->col_offset
[reg
] = roffs
* fc
->data_factor
;
4326 case DW_CFA_val_offset
:
4329 if (reg
>= (unsigned int) fc
->ncols
)
4330 reg_prefix
= bad_reg
;
4331 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4332 printf (" DW_CFA_val_offset: %s%s at cfa%+ld\n",
4333 reg_prefix
, regname (reg
, 0),
4334 roffs
* fc
->data_factor
);
4335 if (*reg_prefix
== '\0')
4337 fc
->col_type
[reg
] = DW_CFA_val_offset
;
4338 fc
->col_offset
[reg
] = roffs
* fc
->data_factor
;
4342 case DW_CFA_restore_extended
:
4344 if (reg
>= (unsigned int) cie
->ncols
4345 || reg
>= (unsigned int) fc
->ncols
)
4346 reg_prefix
= bad_reg
;
4347 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4348 printf (" DW_CFA_restore_extended: %s%s\n",
4349 reg_prefix
, regname (reg
, 0));
4350 if (*reg_prefix
== '\0')
4352 fc
->col_type
[reg
] = cie
->col_type
[reg
];
4353 fc
->col_offset
[reg
] = cie
->col_offset
[reg
];
4357 case DW_CFA_undefined
:
4359 if (reg
>= (unsigned int) fc
->ncols
)
4360 reg_prefix
= bad_reg
;
4361 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4362 printf (" DW_CFA_undefined: %s%s\n",
4363 reg_prefix
, regname (reg
, 0));
4364 if (*reg_prefix
== '\0')
4366 fc
->col_type
[reg
] = DW_CFA_undefined
;
4367 fc
->col_offset
[reg
] = 0;
4371 case DW_CFA_same_value
:
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_same_value: %s%s\n",
4377 reg_prefix
, regname (reg
, 0));
4378 if (*reg_prefix
== '\0')
4380 fc
->col_type
[reg
] = DW_CFA_same_value
;
4381 fc
->col_offset
[reg
] = 0;
4385 case DW_CFA_register
:
4388 if (reg
>= (unsigned int) fc
->ncols
)
4389 reg_prefix
= bad_reg
;
4390 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4392 printf (" DW_CFA_register: %s%s in ",
4393 reg_prefix
, regname (reg
, 0));
4394 puts (regname (roffs
, 0));
4396 if (*reg_prefix
== '\0')
4398 fc
->col_type
[reg
] = DW_CFA_register
;
4399 fc
->col_offset
[reg
] = roffs
;
4403 case DW_CFA_remember_state
:
4404 if (! do_debug_frames_interp
)
4405 printf (" DW_CFA_remember_state\n");
4406 rs
= xmalloc (sizeof (Frame_Chunk
));
4407 rs
->ncols
= fc
->ncols
;
4408 rs
->col_type
= xcmalloc (rs
->ncols
, sizeof (short int));
4409 rs
->col_offset
= xcmalloc (rs
->ncols
, sizeof (int));
4410 memcpy (rs
->col_type
, fc
->col_type
, rs
->ncols
);
4411 memcpy (rs
->col_offset
, fc
->col_offset
, rs
->ncols
* sizeof (int));
4412 rs
->next
= remembered_state
;
4413 remembered_state
= rs
;
4416 case DW_CFA_restore_state
:
4417 if (! do_debug_frames_interp
)
4418 printf (" DW_CFA_restore_state\n");
4419 rs
= remembered_state
;
4422 remembered_state
= rs
->next
;
4423 frame_need_space (fc
, rs
->ncols
- 1);
4424 memcpy (fc
->col_type
, rs
->col_type
, rs
->ncols
);
4425 memcpy (fc
->col_offset
, rs
->col_offset
,
4426 rs
->ncols
* sizeof (int));
4427 free (rs
->col_type
);
4428 free (rs
->col_offset
);
4431 else if (do_debug_frames_interp
)
4432 printf ("Mismatched DW_CFA_restore_state\n");
4435 case DW_CFA_def_cfa
:
4436 fc
->cfa_reg
= LEB ();
4437 fc
->cfa_offset
= LEB ();
4439 if (! do_debug_frames_interp
)
4440 printf (" DW_CFA_def_cfa: %s ofs %d\n",
4441 regname (fc
->cfa_reg
, 0), fc
->cfa_offset
);
4444 case DW_CFA_def_cfa_register
:
4445 fc
->cfa_reg
= LEB ();
4447 if (! do_debug_frames_interp
)
4448 printf (" DW_CFA_def_cfa_register: %s\n",
4449 regname (fc
->cfa_reg
, 0));
4452 case DW_CFA_def_cfa_offset
:
4453 fc
->cfa_offset
= LEB ();
4454 if (! do_debug_frames_interp
)
4455 printf (" DW_CFA_def_cfa_offset: %d\n", fc
->cfa_offset
);
4459 if (! do_debug_frames_interp
)
4460 printf (" DW_CFA_nop\n");
4463 case DW_CFA_def_cfa_expression
:
4465 if (! do_debug_frames_interp
)
4467 printf (" DW_CFA_def_cfa_expression (");
4468 decode_location_expression (start
, eh_addr_size
, ul
, 0,
4476 case DW_CFA_expression
:
4479 if (reg
>= (unsigned int) fc
->ncols
)
4480 reg_prefix
= bad_reg
;
4481 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4483 printf (" DW_CFA_expression: %s%s (",
4484 reg_prefix
, regname (reg
, 0));
4485 decode_location_expression (start
, eh_addr_size
,
4489 if (*reg_prefix
== '\0')
4490 fc
->col_type
[reg
] = DW_CFA_expression
;
4494 case DW_CFA_val_expression
:
4497 if (reg
>= (unsigned int) fc
->ncols
)
4498 reg_prefix
= bad_reg
;
4499 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4501 printf (" DW_CFA_val_expression: %s%s (",
4502 reg_prefix
, regname (reg
, 0));
4503 decode_location_expression (start
, eh_addr_size
, ul
, 0,
4507 if (*reg_prefix
== '\0')
4508 fc
->col_type
[reg
] = DW_CFA_val_expression
;
4512 case DW_CFA_offset_extended_sf
:
4515 if (frame_need_space (fc
, reg
) < 0)
4516 reg_prefix
= bad_reg
;
4517 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4518 printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+ld\n",
4519 reg_prefix
, regname (reg
, 0),
4520 l
* fc
->data_factor
);
4521 if (*reg_prefix
== '\0')
4523 fc
->col_type
[reg
] = DW_CFA_offset
;
4524 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
4528 case DW_CFA_val_offset_sf
:
4531 if (frame_need_space (fc
, reg
) < 0)
4532 reg_prefix
= bad_reg
;
4533 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4534 printf (" DW_CFA_val_offset_sf: %s%s at cfa%+ld\n",
4535 reg_prefix
, regname (reg
, 0),
4536 l
* fc
->data_factor
);
4537 if (*reg_prefix
== '\0')
4539 fc
->col_type
[reg
] = DW_CFA_val_offset
;
4540 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
4544 case DW_CFA_def_cfa_sf
:
4545 fc
->cfa_reg
= LEB ();
4546 fc
->cfa_offset
= SLEB ();
4547 fc
->cfa_offset
= fc
->cfa_offset
* fc
->data_factor
;
4549 if (! do_debug_frames_interp
)
4550 printf (" DW_CFA_def_cfa_sf: %s ofs %d\n",
4551 regname (fc
->cfa_reg
, 0), fc
->cfa_offset
);
4554 case DW_CFA_def_cfa_offset_sf
:
4555 fc
->cfa_offset
= SLEB ();
4556 fc
->cfa_offset
= fc
->cfa_offset
* fc
->data_factor
;
4557 if (! do_debug_frames_interp
)
4558 printf (" DW_CFA_def_cfa_offset_sf: %d\n", fc
->cfa_offset
);
4561 case DW_CFA_MIPS_advance_loc8
:
4562 ofs
= byte_get (start
, 8); start
+= 8;
4563 if (do_debug_frames_interp
)
4564 frame_display_row (fc
, &need_col_headers
, &max_regs
);
4566 printf (" DW_CFA_MIPS_advance_loc8: %ld to %08lx\n",
4567 ofs
* fc
->code_factor
,
4568 fc
->pc_begin
+ ofs
* fc
->code_factor
);
4569 fc
->pc_begin
+= ofs
* fc
->code_factor
;
4572 case DW_CFA_GNU_window_save
:
4573 if (! do_debug_frames_interp
)
4574 printf (" DW_CFA_GNU_window_save\n");
4577 case DW_CFA_GNU_args_size
:
4579 if (! do_debug_frames_interp
)
4580 printf (" DW_CFA_GNU_args_size: %ld\n", ul
);
4583 case DW_CFA_GNU_negative_offset_extended
:
4586 if (frame_need_space (fc
, reg
) < 0)
4587 reg_prefix
= bad_reg
;
4588 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4589 printf (" DW_CFA_GNU_negative_offset_extended: %s%s at cfa%+ld\n",
4590 reg_prefix
, regname (reg
, 0),
4591 l
* fc
->data_factor
);
4592 if (*reg_prefix
== '\0')
4594 fc
->col_type
[reg
] = DW_CFA_offset
;
4595 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
4600 if (op
>= DW_CFA_lo_user
&& op
<= DW_CFA_hi_user
)
4601 printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op
);
4603 warn (_("unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op
);
4608 if (do_debug_frames_interp
)
4609 frame_display_row (fc
, &need_col_headers
, &max_regs
);
4624 display_debug_not_supported (struct dwarf_section
*section
,
4625 void *file ATTRIBUTE_UNUSED
)
4627 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
4634 cmalloc (size_t nmemb
, size_t size
)
4636 /* Check for overflow. */
4637 if (nmemb
>= ~(size_t) 0 / size
)
4640 return malloc (nmemb
* size
);
4644 xcmalloc (size_t nmemb
, size_t size
)
4646 /* Check for overflow. */
4647 if (nmemb
>= ~(size_t) 0 / size
)
4650 return xmalloc (nmemb
* size
);
4654 xcrealloc (void *ptr
, size_t nmemb
, size_t size
)
4656 /* Check for overflow. */
4657 if (nmemb
>= ~(size_t) 0 / size
)
4660 return xrealloc (ptr
, nmemb
* size
);
4664 error (const char *message
, ...)
4668 va_start (args
, message
);
4669 fprintf (stderr
, _("%s: Error: "), program_name
);
4670 vfprintf (stderr
, message
, args
);
4675 warn (const char *message
, ...)
4679 va_start (args
, message
);
4680 fprintf (stderr
, _("%s: Warning: "), program_name
);
4681 vfprintf (stderr
, message
, args
);
4686 free_debug_memory (void)
4688 enum dwarf_section_display_enum i
;
4692 for (i
= 0; i
< max
; i
++)
4693 free_debug_section (i
);
4695 if (debug_information
!= NULL
)
4697 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
)
4699 for (i
= 0; i
< num_debug_info_entries
; i
++)
4701 if (!debug_information
[i
].max_loc_offsets
)
4703 free (debug_information
[i
].loc_offsets
);
4704 free (debug_information
[i
].have_frame_base
);
4706 if (!debug_information
[i
].max_range_lists
)
4707 free (debug_information
[i
].range_lists
);
4711 free (debug_information
);
4712 debug_information
= NULL
;
4713 num_debug_info_entries
= 0;
4718 dwarf_select_sections_by_names (const char *names
)
4722 const char * option
;
4726 debug_dump_long_opts
;
4728 static const debug_dump_long_opts opts_table
[] =
4730 /* Please keep this table alpha- sorted. */
4731 { "Ranges", & do_debug_ranges
, 1 },
4732 { "abbrev", & do_debug_abbrevs
, 1 },
4733 { "aranges", & do_debug_aranges
, 1 },
4734 { "frames", & do_debug_frames
, 1 },
4735 { "frames-interp", & do_debug_frames_interp
, 1 },
4736 { "info", & do_debug_info
, 1 },
4737 { "line", & do_debug_lines
, FLAG_DEBUG_LINES_RAW
}, /* For backwards compatibility. */
4738 { "rawline", & do_debug_lines
, FLAG_DEBUG_LINES_RAW
},
4739 { "decodedline", & do_debug_lines
, FLAG_DEBUG_LINES_DECODED
},
4740 { "loc", & do_debug_loc
, 1 },
4741 { "macro", & do_debug_macinfo
, 1 },
4742 { "pubnames", & do_debug_pubnames
, 1 },
4743 /* This entry is for compatability
4744 with earlier versions of readelf. */
4745 { "ranges", & do_debug_aranges
, 1 },
4746 { "str", & do_debug_str
, 1 },
4755 const debug_dump_long_opts
* entry
;
4757 for (entry
= opts_table
; entry
->option
; entry
++)
4759 size_t len
= strlen (entry
->option
);
4761 if (strncmp (p
, entry
->option
, len
) == 0
4762 && (p
[len
] == ',' || p
[len
] == '\0'))
4764 * entry
->variable
|= entry
->val
;
4766 /* The --debug-dump=frames-interp option also
4767 enables the --debug-dump=frames option. */
4768 if (do_debug_frames_interp
)
4769 do_debug_frames
= 1;
4776 if (entry
->option
== NULL
)
4778 warn (_("Unrecognized debug option '%s'\n"), p
);
4779 p
= strchr (p
, ',');
4790 dwarf_select_sections_by_letters (const char *letters
)
4792 unsigned int index
= 0;
4794 while (letters
[index
])
4795 switch (letters
[index
++])
4802 do_debug_abbrevs
= 1;
4806 do_debug_lines
|= FLAG_DEBUG_LINES_RAW
;
4810 do_debug_lines
|= FLAG_DEBUG_LINES_DECODED
;
4814 do_debug_pubnames
= 1;
4818 do_debug_aranges
= 1;
4822 do_debug_ranges
= 1;
4826 do_debug_frames_interp
= 1;
4828 do_debug_frames
= 1;
4832 do_debug_macinfo
= 1;
4844 warn (_("Unrecognized debug option '%s'\n"), optarg
);
4850 dwarf_select_sections_all (void)
4853 do_debug_abbrevs
= 1;
4854 do_debug_lines
= FLAG_DEBUG_LINES_RAW
;
4855 do_debug_pubnames
= 1;
4856 do_debug_aranges
= 1;
4857 do_debug_ranges
= 1;
4858 do_debug_frames
= 1;
4859 do_debug_macinfo
= 1;
4864 struct dwarf_section_display debug_displays
[] =
4866 { { ".debug_abbrev", ".zdebug_abbrev", NULL
, NULL
, 0, 0 },
4867 display_debug_abbrev
, &do_debug_abbrevs
, 0, 0 },
4868 { { ".debug_aranges", ".zdebug_aranges", NULL
, NULL
, 0, 0 },
4869 display_debug_aranges
, &do_debug_aranges
, 1, 0 },
4870 { { ".debug_frame", ".zdebug_frame", NULL
, NULL
, 0, 0 },
4871 display_debug_frames
, &do_debug_frames
, 1, 0 },
4872 { { ".debug_info", ".zdebug_info", NULL
, NULL
, 0, 0 },
4873 display_debug_info
, &do_debug_info
, 1, 0 },
4874 { { ".debug_line", ".zdebug_line", NULL
, NULL
, 0, 0 },
4875 display_debug_lines
, &do_debug_lines
, 0, 0 },
4876 { { ".debug_pubnames", ".zdebug_pubnames", NULL
, NULL
, 0, 0 },
4877 display_debug_pubnames
, &do_debug_pubnames
, 0, 0 },
4878 { { ".eh_frame", "", NULL
, NULL
, 0, 0 },
4879 display_debug_frames
, &do_debug_frames
, 1, 1 },
4880 { { ".debug_macinfo", ".zdebug_macinfo", NULL
, NULL
, 0, 0 },
4881 display_debug_macinfo
, &do_debug_macinfo
, 0, 0 },
4882 { { ".debug_str", ".zdebug_str", NULL
, NULL
, 0, 0 },
4883 display_debug_str
, &do_debug_str
, 0, 0 },
4884 { { ".debug_loc", ".zdebug_loc", NULL
, NULL
, 0, 0 },
4885 display_debug_loc
, &do_debug_loc
, 1, 0 },
4886 { { ".debug_pubtypes", ".zdebug_pubtypes", NULL
, NULL
, 0, 0 },
4887 display_debug_pubnames
, &do_debug_pubnames
, 0, 0 },
4888 { { ".debug_ranges", ".zdebug_ranges", NULL
, NULL
, 0, 0 },
4889 display_debug_ranges
, &do_debug_ranges
, 0, 0 },
4890 { { ".debug_static_func", ".zdebug_static_func", NULL
, NULL
, 0, 0 },
4891 display_debug_not_supported
, NULL
, 0, 0 },
4892 { { ".debug_static_vars", ".zdebug_static_vars", NULL
, NULL
, 0, 0 },
4893 display_debug_not_supported
, NULL
, 0, 0 },
4894 { { ".debug_types", ".zdebug_types", NULL
, NULL
, 0, 0 },
4895 display_debug_not_supported
, NULL
, 0, 0 },
4896 { { ".debug_weaknames", ".zdebug_weaknames", NULL
, NULL
, 0, 0 },
4897 display_debug_not_supported
, NULL
, 0, 0 }