1 /* dwarf.c -- display DWARF contents of a BFD binary file
2 Copyright 2005, 2006, 2007, 2008, 2009
3 Free Software Foundation, Inc.
5 This file is part of GNU Binutils.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
23 #include "libiberty.h"
26 #include "elf/common.h"
30 static int have_frame_base
;
31 static int need_base_address
;
33 static unsigned int last_pointer_size
= 0;
34 static int warned_about_missing_comp_units
= FALSE
;
36 static unsigned int num_debug_info_entries
= 0;
37 static debug_info
*debug_information
= NULL
;
38 /* Special value for num_debug_info_entries to indicate
39 that the .debug_info section could not be loaded/parsed. */
40 #define DEBUG_INFO_UNAVAILABLE (unsigned int) -1
47 int do_debug_pubnames
;
51 int do_debug_frames_interp
;
57 /* Values for do_debug_lines. */
58 #define FLAG_DEBUG_LINES_RAW 1
59 #define FLAG_DEBUG_LINES_DECODED 2
61 dwarf_vma (*byte_get
) (unsigned char *, int);
64 byte_get_little_endian (unsigned char *field
, int size
)
72 return ((unsigned int) (field
[0]))
73 | (((unsigned int) (field
[1])) << 8);
76 return ((unsigned long) (field
[0]))
77 | (((unsigned long) (field
[1])) << 8)
78 | (((unsigned long) (field
[2])) << 16);
81 return ((unsigned long) (field
[0]))
82 | (((unsigned long) (field
[1])) << 8)
83 | (((unsigned long) (field
[2])) << 16)
84 | (((unsigned long) (field
[3])) << 24);
87 if (sizeof (dwarf_vma
) == 8)
88 return ((dwarf_vma
) (field
[0]))
89 | (((dwarf_vma
) (field
[1])) << 8)
90 | (((dwarf_vma
) (field
[2])) << 16)
91 | (((dwarf_vma
) (field
[3])) << 24)
92 | (((dwarf_vma
) (field
[4])) << 32)
93 | (((dwarf_vma
) (field
[5])) << 40)
94 | (((dwarf_vma
) (field
[6])) << 48)
95 | (((dwarf_vma
) (field
[7])) << 56);
96 else if (sizeof (dwarf_vma
) == 4)
97 /* We want to extract data from an 8 byte wide field and
98 place it into a 4 byte wide field. Since this is a little
99 endian source we can just use the 4 byte extraction code. */
100 return ((unsigned long) (field
[0]))
101 | (((unsigned long) (field
[1])) << 8)
102 | (((unsigned long) (field
[2])) << 16)
103 | (((unsigned long) (field
[3])) << 24);
106 error (_("Unhandled data length: %d\n"), size
);
112 byte_get_big_endian (unsigned char *field
, int size
)
120 return ((unsigned int) (field
[1])) | (((int) (field
[0])) << 8);
123 return ((unsigned long) (field
[2]))
124 | (((unsigned long) (field
[1])) << 8)
125 | (((unsigned long) (field
[0])) << 16);
128 return ((unsigned long) (field
[3]))
129 | (((unsigned long) (field
[2])) << 8)
130 | (((unsigned long) (field
[1])) << 16)
131 | (((unsigned long) (field
[0])) << 24);
134 if (sizeof (dwarf_vma
) == 8)
135 return ((dwarf_vma
) (field
[7]))
136 | (((dwarf_vma
) (field
[6])) << 8)
137 | (((dwarf_vma
) (field
[5])) << 16)
138 | (((dwarf_vma
) (field
[4])) << 24)
139 | (((dwarf_vma
) (field
[3])) << 32)
140 | (((dwarf_vma
) (field
[2])) << 40)
141 | (((dwarf_vma
) (field
[1])) << 48)
142 | (((dwarf_vma
) (field
[0])) << 56);
143 else if (sizeof (dwarf_vma
) == 4)
145 /* Although we are extracing data from an 8 byte wide field,
146 we are returning only 4 bytes of data. */
148 return ((unsigned long) (field
[3]))
149 | (((unsigned long) (field
[2])) << 8)
150 | (((unsigned long) (field
[1])) << 16)
151 | (((unsigned long) (field
[0])) << 24);
155 error (_("Unhandled data length: %d\n"), size
);
161 byte_get_signed (unsigned char *field
, int size
)
163 dwarf_vma x
= byte_get (field
, size
);
168 return (x
^ 0x80) - 0x80;
170 return (x
^ 0x8000) - 0x8000;
172 return (x
^ 0x80000000) - 0x80000000;
181 size_of_encoded_value (int encoding
)
183 switch (encoding
& 0x7)
186 case 0: return eh_addr_size
;
194 get_encoded_value (unsigned char *data
, int encoding
)
196 int size
= size_of_encoded_value (encoding
);
198 if (encoding
& DW_EH_PE_signed
)
199 return byte_get_signed (data
, size
);
201 return byte_get (data
, size
);
204 /* Print a dwarf_vma value (typically an address, offset or length) in
205 hexadecimal format, followed by a space. The length of the value (and
206 hence the precision displayed) is determined by the byte_size parameter. */
209 print_dwarf_vma (dwarf_vma val
, unsigned byte_size
)
211 static char buff
[18];
213 /* Printf does not have a way of specifiying a maximum field width for an
214 integer value, so we print the full value into a buffer and then select
215 the precision we need. */
216 #if __STDC_VERSION__ >= 199901L || (defined(__GNUC__) && __GNUC__ >= 2)
218 snprintf (buff
, sizeof (buff
), "%16.16llx ", val
);
220 snprintf (buff
, sizeof (buff
), "%016I64x ", val
);
223 snprintf (buff
, sizeof (buff
), "%16.16lx ", val
);
226 fputs (buff
+ (byte_size
== 4 ? 8 : 0), stdout
);
229 static unsigned long int
230 read_leb128 (unsigned char *data
, unsigned int *length_return
, int sign
)
232 unsigned long int result
= 0;
233 unsigned int num_read
= 0;
234 unsigned int shift
= 0;
242 result
|= ((unsigned long int) (byte
& 0x7f)) << shift
;
249 if (length_return
!= NULL
)
250 *length_return
= num_read
;
252 if (sign
&& (shift
< 8 * sizeof (result
)) && (byte
& 0x40))
253 result
|= -1L << shift
;
258 typedef struct State_Machine_Registers
260 unsigned long address
;
267 /* This variable hold the number of the last entry seen
268 in the File Table. */
269 unsigned int last_file_entry
;
272 static SMR state_machine_regs
;
275 reset_state_machine (int is_stmt
)
277 state_machine_regs
.address
= 0;
278 state_machine_regs
.file
= 1;
279 state_machine_regs
.line
= 1;
280 state_machine_regs
.column
= 0;
281 state_machine_regs
.is_stmt
= is_stmt
;
282 state_machine_regs
.basic_block
= 0;
283 state_machine_regs
.end_sequence
= 0;
284 state_machine_regs
.last_file_entry
= 0;
287 /* Handled an extend line op.
288 Returns the number of bytes read. */
291 process_extended_line_op (unsigned char *data
, int is_stmt
)
293 unsigned char op_code
;
294 unsigned int bytes_read
;
299 len
= read_leb128 (data
, & bytes_read
, 0);
304 warn (_("badly formed extended line op encountered!\n"));
311 printf (_(" Extended opcode %d: "), op_code
);
315 case DW_LNE_end_sequence
:
316 printf (_("End of Sequence\n\n"));
317 reset_state_machine (is_stmt
);
320 case DW_LNE_set_address
:
321 adr
= byte_get (data
, len
- bytes_read
- 1);
322 printf (_("set Address to 0x%lx\n"), adr
);
323 state_machine_regs
.address
= adr
;
326 case DW_LNE_define_file
:
327 printf (_(" define new File Table entry\n"));
328 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
330 printf (_(" %d\t"), ++state_machine_regs
.last_file_entry
);
332 data
+= strlen ((char *) data
) + 1;
333 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
335 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
337 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
338 printf (_("%s\n\n"), name
);
341 case DW_LNE_set_discriminator
:
342 printf (_("set Discriminator to %lu\n"),
343 read_leb128 (data
, & bytes_read
, 0));
347 case DW_LNE_HP_negate_is_UV_update
:
348 printf ("DW_LNE_HP_negate_is_UV_update\n");
350 case DW_LNE_HP_push_context
:
351 printf ("DW_LNE_HP_push_context\n");
353 case DW_LNE_HP_pop_context
:
354 printf ("DW_LNE_HP_pop_context\n");
356 case DW_LNE_HP_set_file_line_column
:
357 printf ("DW_LNE_HP_set_file_line_column\n");
359 case DW_LNE_HP_set_routine_name
:
360 printf ("DW_LNE_HP_set_routine_name\n");
362 case DW_LNE_HP_set_sequence
:
363 printf ("DW_LNE_HP_set_sequence\n");
365 case DW_LNE_HP_negate_post_semantics
:
366 printf ("DW_LNE_HP_negate_post_semantics\n");
368 case DW_LNE_HP_negate_function_exit
:
369 printf ("DW_LNE_HP_negate_function_exit\n");
371 case DW_LNE_HP_negate_front_end_logical
:
372 printf ("DW_LNE_HP_negate_front_end_logical\n");
374 case DW_LNE_HP_define_proc
:
375 printf ("DW_LNE_HP_define_proc\n");
379 if (op_code
>= DW_LNE_lo_user
380 /* The test against DW_LNW_hi_user is redundant due to
381 the limited range of the unsigned char data type used
383 /*&& op_code <= DW_LNE_hi_user*/)
384 printf (_("user defined: length %d\n"), len
- bytes_read
);
386 printf (_("UNKNOWN: length %d\n"), len
- bytes_read
);
394 fetch_indirect_string (unsigned long offset
)
396 struct dwarf_section
*section
= &debug_displays
[str
].section
;
398 if (section
->start
== NULL
)
399 return _("<no .debug_str section>");
401 /* DWARF sections under Mach-O have non-zero addresses. */
402 offset
-= section
->address
;
403 if (offset
> section
->size
)
405 warn (_("DW_FORM_strp offset too big: %lx\n"), offset
);
406 return _("<offset is too big>");
409 return (const char *) section
->start
+ offset
;
412 /* FIXME: There are better and more efficient ways to handle
413 these structures. For now though, I just want something that
414 is simple to implement. */
415 typedef struct abbrev_attr
417 unsigned long attribute
;
419 struct abbrev_attr
*next
;
423 typedef struct abbrev_entry
428 struct abbrev_attr
*first_attr
;
429 struct abbrev_attr
*last_attr
;
430 struct abbrev_entry
*next
;
434 static abbrev_entry
*first_abbrev
= NULL
;
435 static abbrev_entry
*last_abbrev
= NULL
;
440 abbrev_entry
*abbrev
;
442 for (abbrev
= first_abbrev
; abbrev
;)
444 abbrev_entry
*next
= abbrev
->next
;
447 for (attr
= abbrev
->first_attr
; attr
;)
449 abbrev_attr
*next
= attr
->next
;
459 last_abbrev
= first_abbrev
= NULL
;
463 add_abbrev (unsigned long number
, unsigned long tag
, int children
)
467 entry
= malloc (sizeof (*entry
));
473 entry
->entry
= number
;
475 entry
->children
= children
;
476 entry
->first_attr
= NULL
;
477 entry
->last_attr
= NULL
;
480 if (first_abbrev
== NULL
)
481 first_abbrev
= entry
;
483 last_abbrev
->next
= entry
;
489 add_abbrev_attr (unsigned long attribute
, unsigned long form
)
493 attr
= malloc (sizeof (*attr
));
499 attr
->attribute
= attribute
;
503 if (last_abbrev
->first_attr
== NULL
)
504 last_abbrev
->first_attr
= attr
;
506 last_abbrev
->last_attr
->next
= attr
;
508 last_abbrev
->last_attr
= attr
;
511 /* Processes the (partial) contents of a .debug_abbrev section.
512 Returns NULL if the end of the section was encountered.
513 Returns the address after the last byte read if the end of
514 an abbreviation set was found. */
516 static unsigned char *
517 process_abbrev_section (unsigned char *start
, unsigned char *end
)
519 if (first_abbrev
!= NULL
)
524 unsigned int bytes_read
;
527 unsigned long attribute
;
530 entry
= read_leb128 (start
, & bytes_read
, 0);
533 /* A single zero is supposed to end the section according
534 to the standard. If there's more, then signal that to
537 return start
== end
? NULL
: start
;
539 tag
= read_leb128 (start
, & bytes_read
, 0);
544 add_abbrev (entry
, tag
, children
);
550 attribute
= read_leb128 (start
, & bytes_read
, 0);
553 form
= read_leb128 (start
, & bytes_read
, 0);
557 add_abbrev_attr (attribute
, form
);
559 while (attribute
!= 0);
566 get_TAG_name (unsigned long tag
)
570 case DW_TAG_padding
: return "DW_TAG_padding";
571 case DW_TAG_array_type
: return "DW_TAG_array_type";
572 case DW_TAG_class_type
: return "DW_TAG_class_type";
573 case DW_TAG_entry_point
: return "DW_TAG_entry_point";
574 case DW_TAG_enumeration_type
: return "DW_TAG_enumeration_type";
575 case DW_TAG_formal_parameter
: return "DW_TAG_formal_parameter";
576 case DW_TAG_imported_declaration
: return "DW_TAG_imported_declaration";
577 case DW_TAG_label
: return "DW_TAG_label";
578 case DW_TAG_lexical_block
: return "DW_TAG_lexical_block";
579 case DW_TAG_member
: return "DW_TAG_member";
580 case DW_TAG_pointer_type
: return "DW_TAG_pointer_type";
581 case DW_TAG_reference_type
: return "DW_TAG_reference_type";
582 case DW_TAG_compile_unit
: return "DW_TAG_compile_unit";
583 case DW_TAG_string_type
: return "DW_TAG_string_type";
584 case DW_TAG_structure_type
: return "DW_TAG_structure_type";
585 case DW_TAG_subroutine_type
: return "DW_TAG_subroutine_type";
586 case DW_TAG_typedef
: return "DW_TAG_typedef";
587 case DW_TAG_union_type
: return "DW_TAG_union_type";
588 case DW_TAG_unspecified_parameters
: return "DW_TAG_unspecified_parameters";
589 case DW_TAG_variant
: return "DW_TAG_variant";
590 case DW_TAG_common_block
: return "DW_TAG_common_block";
591 case DW_TAG_common_inclusion
: return "DW_TAG_common_inclusion";
592 case DW_TAG_inheritance
: return "DW_TAG_inheritance";
593 case DW_TAG_inlined_subroutine
: return "DW_TAG_inlined_subroutine";
594 case DW_TAG_module
: return "DW_TAG_module";
595 case DW_TAG_ptr_to_member_type
: return "DW_TAG_ptr_to_member_type";
596 case DW_TAG_set_type
: return "DW_TAG_set_type";
597 case DW_TAG_subrange_type
: return "DW_TAG_subrange_type";
598 case DW_TAG_with_stmt
: return "DW_TAG_with_stmt";
599 case DW_TAG_access_declaration
: return "DW_TAG_access_declaration";
600 case DW_TAG_base_type
: return "DW_TAG_base_type";
601 case DW_TAG_catch_block
: return "DW_TAG_catch_block";
602 case DW_TAG_const_type
: return "DW_TAG_const_type";
603 case DW_TAG_constant
: return "DW_TAG_constant";
604 case DW_TAG_enumerator
: return "DW_TAG_enumerator";
605 case DW_TAG_file_type
: return "DW_TAG_file_type";
606 case DW_TAG_friend
: return "DW_TAG_friend";
607 case DW_TAG_namelist
: return "DW_TAG_namelist";
608 case DW_TAG_namelist_item
: return "DW_TAG_namelist_item";
609 case DW_TAG_packed_type
: return "DW_TAG_packed_type";
610 case DW_TAG_subprogram
: return "DW_TAG_subprogram";
611 case DW_TAG_template_type_param
: return "DW_TAG_template_type_param";
612 case DW_TAG_template_value_param
: return "DW_TAG_template_value_param";
613 case DW_TAG_thrown_type
: return "DW_TAG_thrown_type";
614 case DW_TAG_try_block
: return "DW_TAG_try_block";
615 case DW_TAG_variant_part
: return "DW_TAG_variant_part";
616 case DW_TAG_variable
: return "DW_TAG_variable";
617 case DW_TAG_volatile_type
: return "DW_TAG_volatile_type";
618 case DW_TAG_MIPS_loop
: return "DW_TAG_MIPS_loop";
619 case DW_TAG_format_label
: return "DW_TAG_format_label";
620 case DW_TAG_function_template
: return "DW_TAG_function_template";
621 case DW_TAG_class_template
: return "DW_TAG_class_template";
622 /* DWARF 2.1 values. */
623 case DW_TAG_dwarf_procedure
: return "DW_TAG_dwarf_procedure";
624 case DW_TAG_restrict_type
: return "DW_TAG_restrict_type";
625 case DW_TAG_interface_type
: return "DW_TAG_interface_type";
626 case DW_TAG_namespace
: return "DW_TAG_namespace";
627 case DW_TAG_imported_module
: return "DW_TAG_imported_module";
628 case DW_TAG_unspecified_type
: return "DW_TAG_unspecified_type";
629 case DW_TAG_partial_unit
: return "DW_TAG_partial_unit";
630 case DW_TAG_imported_unit
: return "DW_TAG_imported_unit";
632 case DW_TAG_upc_shared_type
: return "DW_TAG_upc_shared_type";
633 case DW_TAG_upc_strict_type
: return "DW_TAG_upc_strict_type";
634 case DW_TAG_upc_relaxed_type
: return "DW_TAG_upc_relaxed_type";
637 static char buffer
[100];
639 snprintf (buffer
, sizeof (buffer
), _("Unknown TAG value: %lx"), tag
);
646 get_FORM_name (unsigned long form
)
650 case DW_FORM_addr
: return "DW_FORM_addr";
651 case DW_FORM_block2
: return "DW_FORM_block2";
652 case DW_FORM_block4
: return "DW_FORM_block4";
653 case DW_FORM_data2
: return "DW_FORM_data2";
654 case DW_FORM_data4
: return "DW_FORM_data4";
655 case DW_FORM_data8
: return "DW_FORM_data8";
656 case DW_FORM_string
: return "DW_FORM_string";
657 case DW_FORM_block
: return "DW_FORM_block";
658 case DW_FORM_block1
: return "DW_FORM_block1";
659 case DW_FORM_data1
: return "DW_FORM_data1";
660 case DW_FORM_flag
: return "DW_FORM_flag";
661 case DW_FORM_sdata
: return "DW_FORM_sdata";
662 case DW_FORM_strp
: return "DW_FORM_strp";
663 case DW_FORM_udata
: return "DW_FORM_udata";
664 case DW_FORM_ref_addr
: return "DW_FORM_ref_addr";
665 case DW_FORM_ref1
: return "DW_FORM_ref1";
666 case DW_FORM_ref2
: return "DW_FORM_ref2";
667 case DW_FORM_ref4
: return "DW_FORM_ref4";
668 case DW_FORM_ref8
: return "DW_FORM_ref8";
669 case DW_FORM_ref_udata
: return "DW_FORM_ref_udata";
670 case DW_FORM_indirect
: return "DW_FORM_indirect";
673 static char buffer
[100];
675 snprintf (buffer
, sizeof (buffer
), _("Unknown FORM value: %lx"), form
);
681 static unsigned char *
682 display_block (unsigned char *data
, unsigned long length
)
684 printf (_(" %lu byte block: "), length
);
687 printf ("%lx ", (unsigned long) byte_get (data
++, 1));
693 decode_location_expression (unsigned char * data
,
694 unsigned int pointer_size
,
695 unsigned long length
,
696 unsigned long cu_offset
,
697 struct dwarf_section
* section
)
700 unsigned int bytes_read
;
701 unsigned long uvalue
;
702 unsigned char *end
= data
+ length
;
703 int need_frame_base
= 0;
712 printf ("DW_OP_addr: %lx",
713 (unsigned long) byte_get (data
, pointer_size
));
714 data
+= pointer_size
;
717 printf ("DW_OP_deref");
720 printf ("DW_OP_const1u: %lu", (unsigned long) byte_get (data
++, 1));
723 printf ("DW_OP_const1s: %ld", (long) byte_get_signed (data
++, 1));
726 printf ("DW_OP_const2u: %lu", (unsigned long) byte_get (data
, 2));
730 printf ("DW_OP_const2s: %ld", (long) byte_get_signed (data
, 2));
734 printf ("DW_OP_const4u: %lu", (unsigned long) byte_get (data
, 4));
738 printf ("DW_OP_const4s: %ld", (long) byte_get_signed (data
, 4));
742 printf ("DW_OP_const8u: %lu %lu", (unsigned long) byte_get (data
, 4),
743 (unsigned long) byte_get (data
+ 4, 4));
747 printf ("DW_OP_const8s: %ld %ld", (long) byte_get (data
, 4),
748 (long) byte_get (data
+ 4, 4));
752 printf ("DW_OP_constu: %lu", read_leb128 (data
, &bytes_read
, 0));
756 printf ("DW_OP_consts: %ld", read_leb128 (data
, &bytes_read
, 1));
760 printf ("DW_OP_dup");
763 printf ("DW_OP_drop");
766 printf ("DW_OP_over");
769 printf ("DW_OP_pick: %ld", (unsigned long) byte_get (data
++, 1));
772 printf ("DW_OP_swap");
775 printf ("DW_OP_rot");
778 printf ("DW_OP_xderef");
781 printf ("DW_OP_abs");
784 printf ("DW_OP_and");
787 printf ("DW_OP_div");
790 printf ("DW_OP_minus");
793 printf ("DW_OP_mod");
796 printf ("DW_OP_mul");
799 printf ("DW_OP_neg");
802 printf ("DW_OP_not");
808 printf ("DW_OP_plus");
810 case DW_OP_plus_uconst
:
811 printf ("DW_OP_plus_uconst: %lu",
812 read_leb128 (data
, &bytes_read
, 0));
816 printf ("DW_OP_shl");
819 printf ("DW_OP_shr");
822 printf ("DW_OP_shra");
825 printf ("DW_OP_xor");
828 printf ("DW_OP_bra: %ld", (long) byte_get_signed (data
, 2));
850 printf ("DW_OP_skip: %ld", (long) byte_get_signed (data
, 2));
886 printf ("DW_OP_lit%d", op
- DW_OP_lit0
);
921 printf ("DW_OP_reg%d", op
- DW_OP_reg0
);
956 printf ("DW_OP_breg%d: %ld", op
- DW_OP_breg0
,
957 read_leb128 (data
, &bytes_read
, 1));
962 printf ("DW_OP_regx: %lu", read_leb128 (data
, &bytes_read
, 0));
967 printf ("DW_OP_fbreg: %ld", read_leb128 (data
, &bytes_read
, 1));
971 uvalue
= read_leb128 (data
, &bytes_read
, 0);
973 printf ("DW_OP_bregx: %lu %ld", uvalue
,
974 read_leb128 (data
, &bytes_read
, 1));
978 printf ("DW_OP_piece: %lu", read_leb128 (data
, &bytes_read
, 0));
981 case DW_OP_deref_size
:
982 printf ("DW_OP_deref_size: %ld", (long) byte_get (data
++, 1));
984 case DW_OP_xderef_size
:
985 printf ("DW_OP_xderef_size: %ld", (long) byte_get (data
++, 1));
988 printf ("DW_OP_nop");
991 /* DWARF 3 extensions. */
992 case DW_OP_push_object_address
:
993 printf ("DW_OP_push_object_address");
996 /* XXX: Strictly speaking for 64-bit DWARF3 files
997 this ought to be an 8-byte wide computation. */
998 printf ("DW_OP_call2: <%lx>", (long) byte_get (data
, 2) + cu_offset
);
1002 /* XXX: Strictly speaking for 64-bit DWARF3 files
1003 this ought to be an 8-byte wide computation. */
1004 printf ("DW_OP_call4: <%lx>", (long) byte_get (data
, 4) + cu_offset
);
1007 case DW_OP_call_ref
:
1008 /* XXX: Strictly speaking for 64-bit DWARF3 files
1009 this ought to be an 8-byte wide computation. */
1010 printf ("DW_OP_call_ref: <%lx>", (long) byte_get (data
, 4) + cu_offset
);
1013 case DW_OP_form_tls_address
:
1014 printf ("DW_OP_form_tls_address");
1016 case DW_OP_call_frame_cfa
:
1017 printf ("DW_OP_call_frame_cfa");
1019 case DW_OP_bit_piece
:
1020 printf ("DW_OP_bit_piece: ");
1021 printf ("size: %lu ", read_leb128 (data
, &bytes_read
, 0));
1023 printf ("offset: %lu ", read_leb128 (data
, &bytes_read
, 0));
1027 /* DWARF 4 extensions. */
1028 case DW_OP_stack_value
:
1029 printf ("DW_OP_stack_value");
1032 case DW_OP_implicit_value
:
1033 printf ("DW_OP_implicit_value");
1034 uvalue
= read_leb128 (data
, &bytes_read
, 0);
1036 display_block (data
, uvalue
);
1040 /* GNU extensions. */
1041 case DW_OP_GNU_push_tls_address
:
1042 printf ("DW_OP_GNU_push_tls_address or DW_OP_HP_unknown");
1044 case DW_OP_GNU_uninit
:
1045 printf ("DW_OP_GNU_uninit");
1046 /* FIXME: Is there data associated with this OP ? */
1048 case DW_OP_GNU_encoded_addr
:
1054 addr
= get_encoded_value (data
, encoding
);
1055 if ((encoding
& 0x70) == DW_EH_PE_pcrel
)
1056 addr
+= section
->address
+ (data
- section
->start
);
1057 data
+= size_of_encoded_value (encoding
);
1059 printf ("DW_OP_GNU_encoded_addr: fmt:%02x addr:", encoding
);
1060 print_dwarf_vma (addr
, pointer_size
);
1064 /* HP extensions. */
1065 case DW_OP_HP_is_value
:
1066 printf ("DW_OP_HP_is_value");
1067 /* FIXME: Is there data associated with this OP ? */
1069 case DW_OP_HP_fltconst4
:
1070 printf ("DW_OP_HP_fltconst4");
1071 /* FIXME: Is there data associated with this OP ? */
1073 case DW_OP_HP_fltconst8
:
1074 printf ("DW_OP_HP_fltconst8");
1075 /* FIXME: Is there data associated with this OP ? */
1077 case DW_OP_HP_mod_range
:
1078 printf ("DW_OP_HP_mod_range");
1079 /* FIXME: Is there data associated with this OP ? */
1081 case DW_OP_HP_unmod_range
:
1082 printf ("DW_OP_HP_unmod_range");
1083 /* FIXME: Is there data associated with this OP ? */
1086 printf ("DW_OP_HP_tls");
1087 /* FIXME: Is there data associated with this OP ? */
1090 /* PGI (STMicroelectronics) extensions. */
1091 case DW_OP_PGI_omp_thread_num
:
1092 /* Pushes the thread number for the current thread as it would be
1093 returned by the standard OpenMP library function:
1094 omp_get_thread_num(). The "current thread" is the thread for
1095 which the expression is being evaluated. */
1096 printf ("DW_OP_PGI_omp_thread_num");
1100 if (op
>= DW_OP_lo_user
1101 && op
<= DW_OP_hi_user
)
1102 printf (_("(User defined location op)"));
1104 printf (_("(Unknown location op)"));
1105 /* No way to tell where the next op is, so just bail. */
1106 return need_frame_base
;
1109 /* Separate the ops. */
1114 return need_frame_base
;
1117 static unsigned char *
1118 read_and_display_attr_value (unsigned long attribute
,
1120 unsigned char * data
,
1121 unsigned long cu_offset
,
1122 unsigned long pointer_size
,
1123 unsigned long offset_size
,
1125 debug_info
* debug_info_p
,
1127 struct dwarf_section
* section
)
1129 unsigned long uvalue
= 0;
1130 unsigned char *block_start
= NULL
;
1131 unsigned char * orig_data
= data
;
1132 unsigned int bytes_read
;
1139 case DW_FORM_ref_addr
:
1140 if (dwarf_version
== 2)
1142 uvalue
= byte_get (data
, pointer_size
);
1143 data
+= pointer_size
;
1145 else if (dwarf_version
== 3)
1147 uvalue
= byte_get (data
, offset_size
);
1148 data
+= offset_size
;
1152 error (_("Internal error: DWARF version is not 2 or 3.\n"));
1157 uvalue
= byte_get (data
, pointer_size
);
1158 data
+= pointer_size
;
1162 uvalue
= byte_get (data
, offset_size
);
1163 data
+= offset_size
;
1169 uvalue
= byte_get (data
++, 1);
1174 uvalue
= byte_get (data
, 2);
1180 uvalue
= byte_get (data
, 4);
1185 uvalue
= read_leb128 (data
, & bytes_read
, 1);
1189 case DW_FORM_ref_udata
:
1191 uvalue
= read_leb128 (data
, & bytes_read
, 0);
1195 case DW_FORM_indirect
:
1196 form
= read_leb128 (data
, & bytes_read
, 0);
1199 printf (" %s", get_FORM_name (form
));
1200 return read_and_display_attr_value (attribute
, form
, data
,
1201 cu_offset
, pointer_size
,
1202 offset_size
, dwarf_version
,
1203 debug_info_p
, do_loc
,
1209 case DW_FORM_ref_addr
:
1211 printf (" <0x%lx>", uvalue
);
1217 case DW_FORM_ref_udata
:
1219 printf (" <0x%lx>", uvalue
+ cu_offset
);
1225 printf (" 0x%lx", uvalue
);
1234 printf (" %ld", uvalue
);
1241 uvalue
= byte_get (data
, 4);
1242 printf (" 0x%lx", uvalue
);
1243 printf (" 0x%lx", (unsigned long) byte_get (data
+ 4, 4));
1245 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
1246 && num_debug_info_entries
== 0)
1248 if (sizeof (uvalue
) == 8)
1249 uvalue
= byte_get (data
, 8);
1251 error (_("DW_FORM_data8 is unsupported when sizeof (unsigned long) != 8\n"));
1256 case DW_FORM_string
:
1258 printf (" %s", data
);
1259 data
+= strlen ((char *) data
) + 1;
1263 uvalue
= read_leb128 (data
, & bytes_read
, 0);
1264 block_start
= data
+ bytes_read
;
1266 data
= block_start
+ uvalue
;
1268 data
= display_block (block_start
, uvalue
);
1271 case DW_FORM_block1
:
1272 uvalue
= byte_get (data
, 1);
1273 block_start
= data
+ 1;
1275 data
= block_start
+ uvalue
;
1277 data
= display_block (block_start
, uvalue
);
1280 case DW_FORM_block2
:
1281 uvalue
= byte_get (data
, 2);
1282 block_start
= data
+ 2;
1284 data
= block_start
+ uvalue
;
1286 data
= display_block (block_start
, uvalue
);
1289 case DW_FORM_block4
:
1290 uvalue
= byte_get (data
, 4);
1291 block_start
= data
+ 4;
1293 data
= block_start
+ uvalue
;
1295 data
= display_block (block_start
, uvalue
);
1300 printf (_(" (indirect string, offset: 0x%lx): %s"),
1301 uvalue
, fetch_indirect_string (uvalue
));
1304 case DW_FORM_indirect
:
1305 /* Handled above. */
1309 warn (_("Unrecognized form: %lu\n"), form
);
1313 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
1314 && num_debug_info_entries
== 0)
1318 case DW_AT_frame_base
:
1319 have_frame_base
= 1;
1320 case DW_AT_location
:
1321 case DW_AT_string_length
:
1322 case DW_AT_return_addr
:
1323 case DW_AT_data_member_location
:
1324 case DW_AT_vtable_elem_location
:
1326 case DW_AT_static_link
:
1327 case DW_AT_use_location
:
1328 if (form
== DW_FORM_data4
|| form
== DW_FORM_data8
)
1330 /* Process location list. */
1331 unsigned int max
= debug_info_p
->max_loc_offsets
;
1332 unsigned int num
= debug_info_p
->num_loc_offsets
;
1334 if (max
== 0 || num
>= max
)
1337 debug_info_p
->loc_offsets
1338 = xcrealloc (debug_info_p
->loc_offsets
,
1339 max
, sizeof (*debug_info_p
->loc_offsets
));
1340 debug_info_p
->have_frame_base
1341 = xcrealloc (debug_info_p
->have_frame_base
,
1342 max
, sizeof (*debug_info_p
->have_frame_base
));
1343 debug_info_p
->max_loc_offsets
= max
;
1345 debug_info_p
->loc_offsets
[num
] = uvalue
;
1346 debug_info_p
->have_frame_base
[num
] = have_frame_base
;
1347 debug_info_p
->num_loc_offsets
++;
1352 if (need_base_address
)
1353 debug_info_p
->base_address
= uvalue
;
1357 if (form
== DW_FORM_data4
|| form
== DW_FORM_data8
)
1359 /* Process range list. */
1360 unsigned int max
= debug_info_p
->max_range_lists
;
1361 unsigned int num
= debug_info_p
->num_range_lists
;
1363 if (max
== 0 || num
>= max
)
1366 debug_info_p
->range_lists
1367 = xcrealloc (debug_info_p
->range_lists
,
1368 max
, sizeof (*debug_info_p
->range_lists
));
1369 debug_info_p
->max_range_lists
= max
;
1371 debug_info_p
->range_lists
[num
] = uvalue
;
1372 debug_info_p
->num_range_lists
++;
1384 /* For some attributes we can display further information. */
1392 case DW_INL_not_inlined
:
1393 printf (_("(not inlined)"));
1395 case DW_INL_inlined
:
1396 printf (_("(inlined)"));
1398 case DW_INL_declared_not_inlined
:
1399 printf (_("(declared as inline but ignored)"));
1401 case DW_INL_declared_inlined
:
1402 printf (_("(declared as inline and inlined)"));
1405 printf (_(" (Unknown inline attribute value: %lx)"), uvalue
);
1410 case DW_AT_language
:
1413 /* Ordered by the numeric value of these constants. */
1414 case DW_LANG_C89
: printf ("(ANSI C)"); break;
1415 case DW_LANG_C
: printf ("(non-ANSI C)"); break;
1416 case DW_LANG_Ada83
: printf ("(Ada)"); break;
1417 case DW_LANG_C_plus_plus
: printf ("(C++)"); break;
1418 case DW_LANG_Cobol74
: printf ("(Cobol 74)"); break;
1419 case DW_LANG_Cobol85
: printf ("(Cobol 85)"); break;
1420 case DW_LANG_Fortran77
: printf ("(FORTRAN 77)"); break;
1421 case DW_LANG_Fortran90
: printf ("(Fortran 90)"); break;
1422 case DW_LANG_Pascal83
: printf ("(ANSI Pascal)"); break;
1423 case DW_LANG_Modula2
: printf ("(Modula 2)"); break;
1424 /* DWARF 2.1 values. */
1425 case DW_LANG_Java
: printf ("(Java)"); break;
1426 case DW_LANG_C99
: printf ("(ANSI C99)"); break;
1427 case DW_LANG_Ada95
: printf ("(ADA 95)"); break;
1428 case DW_LANG_Fortran95
: printf ("(Fortran 95)"); break;
1429 /* DWARF 3 values. */
1430 case DW_LANG_PLI
: printf ("(PLI)"); break;
1431 case DW_LANG_ObjC
: printf ("(Objective C)"); break;
1432 case DW_LANG_ObjC_plus_plus
: printf ("(Objective C++)"); break;
1433 case DW_LANG_UPC
: printf ("(Unified Parallel C)"); break;
1434 case DW_LANG_D
: printf ("(D)"); break;
1435 /* MIPS extension. */
1436 case DW_LANG_Mips_Assembler
: printf ("(MIPS assembler)"); break;
1437 /* UPC extension. */
1438 case DW_LANG_Upc
: printf ("(Unified Parallel C)"); break;
1440 if (uvalue
>= DW_LANG_lo_user
&& uvalue
<= DW_LANG_hi_user
)
1441 printf ("(implementation defined: %lx)", uvalue
);
1443 printf ("(Unknown: %lx)", uvalue
);
1448 case DW_AT_encoding
:
1451 case DW_ATE_void
: printf ("(void)"); break;
1452 case DW_ATE_address
: printf ("(machine address)"); break;
1453 case DW_ATE_boolean
: printf ("(boolean)"); break;
1454 case DW_ATE_complex_float
: printf ("(complex float)"); break;
1455 case DW_ATE_float
: printf ("(float)"); break;
1456 case DW_ATE_signed
: printf ("(signed)"); break;
1457 case DW_ATE_signed_char
: printf ("(signed char)"); break;
1458 case DW_ATE_unsigned
: printf ("(unsigned)"); break;
1459 case DW_ATE_unsigned_char
: printf ("(unsigned char)"); break;
1460 /* DWARF 2.1 values: */
1461 case DW_ATE_imaginary_float
: printf ("(imaginary float)"); break;
1462 case DW_ATE_decimal_float
: printf ("(decimal float)"); break;
1463 /* DWARF 3 values: */
1464 case DW_ATE_packed_decimal
: printf ("(packed_decimal)"); break;
1465 case DW_ATE_numeric_string
: printf ("(numeric_string)"); break;
1466 case DW_ATE_edited
: printf ("(edited)"); break;
1467 case DW_ATE_signed_fixed
: printf ("(signed_fixed)"); break;
1468 case DW_ATE_unsigned_fixed
: printf ("(unsigned_fixed)"); break;
1469 /* HP extensions: */
1470 case DW_ATE_HP_float80
: printf ("(HP_float80)"); break;
1471 case DW_ATE_HP_complex_float80
: printf ("(HP_complex_float80)"); break;
1472 case DW_ATE_HP_float128
: printf ("(HP_float128)"); break;
1473 case DW_ATE_HP_complex_float128
:printf ("(HP_complex_float128)"); break;
1474 case DW_ATE_HP_floathpintel
: printf ("(HP_floathpintel)"); break;
1475 case DW_ATE_HP_imaginary_float80
: printf ("(HP_imaginary_float80)"); break;
1476 case DW_ATE_HP_imaginary_float128
: printf ("(HP_imaginary_float128)"); break;
1479 if (uvalue
>= DW_ATE_lo_user
1480 && uvalue
<= DW_ATE_hi_user
)
1481 printf ("(user defined type)");
1483 printf ("(unknown type)");
1488 case DW_AT_accessibility
:
1491 case DW_ACCESS_public
: printf ("(public)"); break;
1492 case DW_ACCESS_protected
: printf ("(protected)"); break;
1493 case DW_ACCESS_private
: printf ("(private)"); break;
1495 printf ("(unknown accessibility)");
1500 case DW_AT_visibility
:
1503 case DW_VIS_local
: printf ("(local)"); break;
1504 case DW_VIS_exported
: printf ("(exported)"); break;
1505 case DW_VIS_qualified
: printf ("(qualified)"); break;
1506 default: printf ("(unknown visibility)"); break;
1510 case DW_AT_virtuality
:
1513 case DW_VIRTUALITY_none
: printf ("(none)"); break;
1514 case DW_VIRTUALITY_virtual
: printf ("(virtual)"); break;
1515 case DW_VIRTUALITY_pure_virtual
:printf ("(pure_virtual)"); break;
1516 default: printf ("(unknown virtuality)"); break;
1520 case DW_AT_identifier_case
:
1523 case DW_ID_case_sensitive
: printf ("(case_sensitive)"); break;
1524 case DW_ID_up_case
: printf ("(up_case)"); break;
1525 case DW_ID_down_case
: printf ("(down_case)"); break;
1526 case DW_ID_case_insensitive
: printf ("(case_insensitive)"); break;
1527 default: printf ("(unknown case)"); break;
1531 case DW_AT_calling_convention
:
1534 case DW_CC_normal
: printf ("(normal)"); break;
1535 case DW_CC_program
: printf ("(program)"); break;
1536 case DW_CC_nocall
: printf ("(nocall)"); break;
1538 if (uvalue
>= DW_CC_lo_user
1539 && uvalue
<= DW_CC_hi_user
)
1540 printf ("(user defined)");
1542 printf ("(unknown convention)");
1546 case DW_AT_ordering
:
1549 case -1: printf ("(undefined)"); break;
1550 case 0: printf ("(row major)"); break;
1551 case 1: printf ("(column major)"); break;
1555 case DW_AT_frame_base
:
1556 have_frame_base
= 1;
1557 case DW_AT_location
:
1558 case DW_AT_string_length
:
1559 case DW_AT_return_addr
:
1560 case DW_AT_data_member_location
:
1561 case DW_AT_vtable_elem_location
:
1563 case DW_AT_static_link
:
1564 case DW_AT_use_location
:
1565 if (form
== DW_FORM_data4
|| form
== DW_FORM_data8
)
1566 printf (_("(location list)"));
1568 case DW_AT_allocated
:
1569 case DW_AT_associated
:
1570 case DW_AT_data_location
:
1572 case DW_AT_upper_bound
:
1573 case DW_AT_lower_bound
:
1576 int need_frame_base
;
1579 need_frame_base
= decode_location_expression (block_start
,
1582 cu_offset
, section
);
1584 if (need_frame_base
&& !have_frame_base
)
1585 printf (_(" [without DW_AT_frame_base]"));
1591 if (form
== DW_FORM_ref1
1592 || form
== DW_FORM_ref2
1593 || form
== DW_FORM_ref4
)
1594 uvalue
+= cu_offset
;
1596 if (uvalue
>= section
->size
)
1597 warn (_("Offset %lx used as value for DW_AT_import attribute of DIE at offset %lx is too big.\n"),
1598 uvalue
, (unsigned long) (orig_data
- section
->start
));
1601 unsigned long abbrev_number
;
1602 abbrev_entry
* entry
;
1604 abbrev_number
= read_leb128 (section
->start
+ uvalue
, NULL
, 0);
1606 printf ("[Abbrev Number: %ld", abbrev_number
);
1607 for (entry
= first_abbrev
; entry
!= NULL
; entry
= entry
->next
)
1608 if (entry
->entry
== abbrev_number
)
1611 printf (" (%s)", get_TAG_name (entry
->tag
));
1625 get_AT_name (unsigned long attribute
)
1629 case DW_AT_sibling
: return "DW_AT_sibling";
1630 case DW_AT_location
: return "DW_AT_location";
1631 case DW_AT_name
: return "DW_AT_name";
1632 case DW_AT_ordering
: return "DW_AT_ordering";
1633 case DW_AT_subscr_data
: return "DW_AT_subscr_data";
1634 case DW_AT_byte_size
: return "DW_AT_byte_size";
1635 case DW_AT_bit_offset
: return "DW_AT_bit_offset";
1636 case DW_AT_bit_size
: return "DW_AT_bit_size";
1637 case DW_AT_element_list
: return "DW_AT_element_list";
1638 case DW_AT_stmt_list
: return "DW_AT_stmt_list";
1639 case DW_AT_low_pc
: return "DW_AT_low_pc";
1640 case DW_AT_high_pc
: return "DW_AT_high_pc";
1641 case DW_AT_language
: return "DW_AT_language";
1642 case DW_AT_member
: return "DW_AT_member";
1643 case DW_AT_discr
: return "DW_AT_discr";
1644 case DW_AT_discr_value
: return "DW_AT_discr_value";
1645 case DW_AT_visibility
: return "DW_AT_visibility";
1646 case DW_AT_import
: return "DW_AT_import";
1647 case DW_AT_string_length
: return "DW_AT_string_length";
1648 case DW_AT_common_reference
: return "DW_AT_common_reference";
1649 case DW_AT_comp_dir
: return "DW_AT_comp_dir";
1650 case DW_AT_const_value
: return "DW_AT_const_value";
1651 case DW_AT_containing_type
: return "DW_AT_containing_type";
1652 case DW_AT_default_value
: return "DW_AT_default_value";
1653 case DW_AT_inline
: return "DW_AT_inline";
1654 case DW_AT_is_optional
: return "DW_AT_is_optional";
1655 case DW_AT_lower_bound
: return "DW_AT_lower_bound";
1656 case DW_AT_producer
: return "DW_AT_producer";
1657 case DW_AT_prototyped
: return "DW_AT_prototyped";
1658 case DW_AT_return_addr
: return "DW_AT_return_addr";
1659 case DW_AT_start_scope
: return "DW_AT_start_scope";
1660 case DW_AT_stride_size
: return "DW_AT_stride_size";
1661 case DW_AT_upper_bound
: return "DW_AT_upper_bound";
1662 case DW_AT_abstract_origin
: return "DW_AT_abstract_origin";
1663 case DW_AT_accessibility
: return "DW_AT_accessibility";
1664 case DW_AT_address_class
: return "DW_AT_address_class";
1665 case DW_AT_artificial
: return "DW_AT_artificial";
1666 case DW_AT_base_types
: return "DW_AT_base_types";
1667 case DW_AT_calling_convention
: return "DW_AT_calling_convention";
1668 case DW_AT_count
: return "DW_AT_count";
1669 case DW_AT_data_member_location
: return "DW_AT_data_member_location";
1670 case DW_AT_decl_column
: return "DW_AT_decl_column";
1671 case DW_AT_decl_file
: return "DW_AT_decl_file";
1672 case DW_AT_decl_line
: return "DW_AT_decl_line";
1673 case DW_AT_declaration
: return "DW_AT_declaration";
1674 case DW_AT_discr_list
: return "DW_AT_discr_list";
1675 case DW_AT_encoding
: return "DW_AT_encoding";
1676 case DW_AT_external
: return "DW_AT_external";
1677 case DW_AT_frame_base
: return "DW_AT_frame_base";
1678 case DW_AT_friend
: return "DW_AT_friend";
1679 case DW_AT_identifier_case
: return "DW_AT_identifier_case";
1680 case DW_AT_macro_info
: return "DW_AT_macro_info";
1681 case DW_AT_namelist_items
: return "DW_AT_namelist_items";
1682 case DW_AT_priority
: return "DW_AT_priority";
1683 case DW_AT_segment
: return "DW_AT_segment";
1684 case DW_AT_specification
: return "DW_AT_specification";
1685 case DW_AT_static_link
: return "DW_AT_static_link";
1686 case DW_AT_type
: return "DW_AT_type";
1687 case DW_AT_use_location
: return "DW_AT_use_location";
1688 case DW_AT_variable_parameter
: return "DW_AT_variable_parameter";
1689 case DW_AT_virtuality
: return "DW_AT_virtuality";
1690 case DW_AT_vtable_elem_location
: return "DW_AT_vtable_elem_location";
1691 /* DWARF 2.1 values. */
1692 case DW_AT_allocated
: return "DW_AT_allocated";
1693 case DW_AT_associated
: return "DW_AT_associated";
1694 case DW_AT_data_location
: return "DW_AT_data_location";
1695 case DW_AT_stride
: return "DW_AT_stride";
1696 case DW_AT_entry_pc
: return "DW_AT_entry_pc";
1697 case DW_AT_use_UTF8
: return "DW_AT_use_UTF8";
1698 case DW_AT_extension
: return "DW_AT_extension";
1699 case DW_AT_ranges
: return "DW_AT_ranges";
1700 case DW_AT_trampoline
: return "DW_AT_trampoline";
1701 case DW_AT_call_column
: return "DW_AT_call_column";
1702 case DW_AT_call_file
: return "DW_AT_call_file";
1703 case DW_AT_call_line
: return "DW_AT_call_line";
1704 case DW_AT_description
: return "DW_AT_description";
1705 case DW_AT_binary_scale
: return "DW_AT_binary_scale";
1706 case DW_AT_decimal_scale
: return "DW_AT_decimal_scale";
1707 case DW_AT_small
: return "DW_AT_small";
1708 case DW_AT_decimal_sign
: return "DW_AT_decimal_sign";
1709 case DW_AT_digit_count
: return "DW_AT_digit_count";
1710 case DW_AT_picture_string
: return "DW_AT_picture_string";
1711 case DW_AT_mutable
: return "DW_AT_mutable";
1712 case DW_AT_threads_scaled
: return "DW_AT_threads_scaled";
1713 case DW_AT_explicit
: return "DW_AT_explicit";
1714 case DW_AT_object_pointer
: return "DW_AT_object_pointer";
1715 case DW_AT_endianity
: return "DW_AT_endianity";
1716 case DW_AT_elemental
: return "DW_AT_elemental";
1717 case DW_AT_pure
: return "DW_AT_pure";
1718 case DW_AT_recursive
: return "DW_AT_recursive";
1720 /* HP and SGI/MIPS extensions. */
1721 case DW_AT_MIPS_loop_begin
: return "DW_AT_MIPS_loop_begin";
1722 case DW_AT_MIPS_tail_loop_begin
: return "DW_AT_MIPS_tail_loop_begin";
1723 case DW_AT_MIPS_epilog_begin
: return "DW_AT_MIPS_epilog_begin";
1724 case DW_AT_MIPS_loop_unroll_factor
: return "DW_AT_MIPS_loop_unroll_factor";
1725 case DW_AT_MIPS_software_pipeline_depth
: return "DW_AT_MIPS_software_pipeline_depth";
1726 case DW_AT_MIPS_linkage_name
: return "DW_AT_MIPS_linkage_name";
1727 case DW_AT_MIPS_stride
: return "DW_AT_MIPS_stride";
1728 case DW_AT_MIPS_abstract_name
: return "DW_AT_MIPS_abstract_name";
1729 case DW_AT_MIPS_clone_origin
: return "DW_AT_MIPS_clone_origin";
1730 case DW_AT_MIPS_has_inlines
: return "DW_AT_MIPS_has_inlines";
1732 /* HP Extensions. */
1733 case DW_AT_HP_block_index
: return "DW_AT_HP_block_index";
1734 case DW_AT_HP_actuals_stmt_list
: return "DW_AT_HP_actuals_stmt_list";
1735 case DW_AT_HP_proc_per_section
: return "DW_AT_HP_proc_per_section";
1736 case DW_AT_HP_raw_data_ptr
: return "DW_AT_HP_raw_data_ptr";
1737 case DW_AT_HP_pass_by_reference
: return "DW_AT_HP_pass_by_reference";
1738 case DW_AT_HP_opt_level
: return "DW_AT_HP_opt_level";
1739 case DW_AT_HP_prof_version_id
: return "DW_AT_HP_prof_version_id";
1740 case DW_AT_HP_opt_flags
: return "DW_AT_HP_opt_flags";
1741 case DW_AT_HP_cold_region_low_pc
: return "DW_AT_HP_cold_region_low_pc";
1742 case DW_AT_HP_cold_region_high_pc
: return "DW_AT_HP_cold_region_high_pc";
1743 case DW_AT_HP_all_variables_modifiable
: return "DW_AT_HP_all_variables_modifiable";
1744 case DW_AT_HP_linkage_name
: return "DW_AT_HP_linkage_name";
1745 case DW_AT_HP_prof_flags
: return "DW_AT_HP_prof_flags";
1747 /* One value is shared by the MIPS and HP extensions: */
1748 case DW_AT_MIPS_fde
: return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable";
1750 /* GNU extensions. */
1751 case DW_AT_sf_names
: return "DW_AT_sf_names";
1752 case DW_AT_src_info
: return "DW_AT_src_info";
1753 case DW_AT_mac_info
: return "DW_AT_mac_info";
1754 case DW_AT_src_coords
: return "DW_AT_src_coords";
1755 case DW_AT_body_begin
: return "DW_AT_body_begin";
1756 case DW_AT_body_end
: return "DW_AT_body_end";
1757 case DW_AT_GNU_vector
: return "DW_AT_GNU_vector";
1759 /* UPC extension. */
1760 case DW_AT_upc_threads_scaled
: return "DW_AT_upc_threads_scaled";
1762 /* PGI (STMicroelectronics) extensions. */
1763 case DW_AT_PGI_lbase
: return "DW_AT_PGI_lbase";
1764 case DW_AT_PGI_soffset
: return "DW_AT_PGI_soffset";
1765 case DW_AT_PGI_lstride
: return "DW_AT_PGI_lstride";
1769 static char buffer
[100];
1771 snprintf (buffer
, sizeof (buffer
), _("Unknown AT value: %lx"),
1778 static unsigned char *
1779 read_and_display_attr (unsigned long attribute
,
1781 unsigned char * data
,
1782 unsigned long cu_offset
,
1783 unsigned long pointer_size
,
1784 unsigned long offset_size
,
1786 debug_info
* debug_info_p
,
1788 struct dwarf_section
* section
)
1791 printf (" %-18s:", get_AT_name (attribute
));
1792 data
= read_and_display_attr_value (attribute
, form
, data
, cu_offset
,
1793 pointer_size
, offset_size
,
1794 dwarf_version
, debug_info_p
,
1802 /* Process the contents of a .debug_info section. If do_loc is non-zero
1803 then we are scanning for location lists and we do not want to display
1804 anything to the user. */
1807 process_debug_info (struct dwarf_section
*section
,
1811 unsigned char *start
= section
->start
;
1812 unsigned char *end
= start
+ section
->size
;
1813 unsigned char *section_begin
;
1815 unsigned int num_units
= 0;
1817 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
1818 && num_debug_info_entries
== 0)
1820 unsigned long length
;
1822 /* First scan the section to get the number of comp units. */
1823 for (section_begin
= start
, num_units
= 0; section_begin
< end
;
1826 /* Read the first 4 bytes. For a 32-bit DWARF section, this
1827 will be the length. For a 64-bit DWARF section, it'll be
1828 the escape code 0xffffffff followed by an 8 byte length. */
1829 length
= byte_get (section_begin
, 4);
1831 if (length
== 0xffffffff)
1833 length
= byte_get (section_begin
+ 4, 8);
1834 section_begin
+= length
+ 12;
1836 else if (length
>= 0xfffffff0 && length
< 0xffffffff)
1838 warn (_("Reserved length value (%lx) found in section %s\n"), length
, section
->name
);
1842 section_begin
+= length
+ 4;
1844 /* Negative values are illegal, they may even cause infinite
1845 looping. This can happen if we can't accurately apply
1846 relocations to an object file. */
1847 if ((signed long) length
<= 0)
1849 warn (_("Corrupt unit length (%lx) found in section %s\n"), length
, section
->name
);
1856 error (_("No comp units in %s section ?"), section
->name
);
1860 /* Then allocate an array to hold the information. */
1861 debug_information
= cmalloc (num_units
,
1862 sizeof (* debug_information
));
1863 if (debug_information
== NULL
)
1865 error (_("Not enough memory for a debug info array of %u entries"),
1873 printf (_("Contents of the %s section:\n\n"), section
->name
);
1875 load_debug_section (str
, file
);
1878 load_debug_section (abbrev
, file
);
1879 if (debug_displays
[abbrev
].section
.start
== NULL
)
1881 warn (_("Unable to locate %s section!\n"),
1882 debug_displays
[abbrev
].section
.name
);
1886 for (section_begin
= start
, unit
= 0; start
< end
; unit
++)
1888 DWARF2_Internal_CompUnit compunit
;
1889 unsigned char *hdrptr
;
1890 unsigned char *cu_abbrev_offset_ptr
;
1891 unsigned char *tags
;
1893 unsigned long cu_offset
;
1895 int initial_length_size
;
1899 compunit
.cu_length
= byte_get (hdrptr
, 4);
1902 if (compunit
.cu_length
== 0xffffffff)
1904 compunit
.cu_length
= byte_get (hdrptr
, 8);
1907 initial_length_size
= 12;
1912 initial_length_size
= 4;
1915 compunit
.cu_version
= byte_get (hdrptr
, 2);
1918 cu_offset
= start
- section_begin
;
1920 cu_abbrev_offset_ptr
= hdrptr
;
1921 compunit
.cu_abbrev_offset
= byte_get (hdrptr
, offset_size
);
1922 hdrptr
+= offset_size
;
1924 compunit
.cu_pointer_size
= byte_get (hdrptr
, 1);
1926 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
1927 && num_debug_info_entries
== 0)
1929 debug_information
[unit
].cu_offset
= cu_offset
;
1930 debug_information
[unit
].pointer_size
1931 = compunit
.cu_pointer_size
;
1932 debug_information
[unit
].base_address
= 0;
1933 debug_information
[unit
].loc_offsets
= NULL
;
1934 debug_information
[unit
].have_frame_base
= NULL
;
1935 debug_information
[unit
].max_loc_offsets
= 0;
1936 debug_information
[unit
].num_loc_offsets
= 0;
1937 debug_information
[unit
].range_lists
= NULL
;
1938 debug_information
[unit
].max_range_lists
= 0;
1939 debug_information
[unit
].num_range_lists
= 0;
1944 printf (_(" Compilation Unit @ offset 0x%lx:\n"), cu_offset
);
1945 printf (_(" Length: 0x%lx (%s)\n"), compunit
.cu_length
,
1946 initial_length_size
== 8 ? "64-bit" : "32-bit");
1947 printf (_(" Version: %d\n"), compunit
.cu_version
);
1948 printf (_(" Abbrev Offset: %ld\n"), compunit
.cu_abbrev_offset
);
1949 printf (_(" Pointer Size: %d\n"), compunit
.cu_pointer_size
);
1952 if (cu_offset
+ compunit
.cu_length
+ initial_length_size
1955 warn (_("Debug info is corrupted, length of CU at %lx extends beyond end of section (length = %lx)\n"),
1956 cu_offset
, compunit
.cu_length
);
1960 start
+= compunit
.cu_length
+ initial_length_size
;
1962 if (compunit
.cu_version
!= 2 && compunit
.cu_version
!= 3)
1964 warn (_("CU at offset %lx contains corrupt or unsupported version number: %d.\n"),
1965 cu_offset
, compunit
.cu_version
);
1971 /* Process the abbrevs used by this compilation unit. DWARF
1972 sections under Mach-O have non-zero addresses. */
1973 if (compunit
.cu_abbrev_offset
>= debug_displays
[abbrev
].section
.size
)
1974 warn (_("Debug info is corrupted, abbrev offset (%lx) is larger than abbrev section size (%lx)\n"),
1975 (unsigned long) compunit
.cu_abbrev_offset
,
1976 (unsigned long) debug_displays
[abbrev
].section
.size
);
1978 process_abbrev_section
1979 ((unsigned char *) debug_displays
[abbrev
].section
.start
1980 + compunit
.cu_abbrev_offset
- debug_displays
[abbrev
].section
.address
,
1981 (unsigned char *) debug_displays
[abbrev
].section
.start
1982 + debug_displays
[abbrev
].section
.size
);
1985 while (tags
< start
)
1987 unsigned int bytes_read
;
1988 unsigned long abbrev_number
;
1989 unsigned long die_offset
;
1990 abbrev_entry
*entry
;
1993 die_offset
= tags
- section_begin
;
1995 abbrev_number
= read_leb128 (tags
, & bytes_read
, 0);
1998 /* A null DIE marks the end of a list of siblings or it may also be
1999 a section padding. */
2000 if (abbrev_number
== 0)
2002 /* Check if it can be a section padding for the last CU. */
2003 if (level
== 0 && start
== end
)
2007 for (chk
= tags
; chk
< start
; chk
++)
2017 static unsigned num_bogus_warns
= 0;
2019 if (num_bogus_warns
< 3)
2021 warn (_("Bogus end-of-siblings marker detected at offset %lx in .debug_info section\n"),
2024 if (num_bogus_warns
== 3)
2025 warn (_("Further warnings about bogus end-of-sibling markers suppressed\n"));
2032 printf (_(" <%d><%lx>: Abbrev Number: %lu"),
2033 level
, die_offset
, abbrev_number
);
2035 /* Scan through the abbreviation list until we reach the
2037 for (entry
= first_abbrev
;
2038 entry
&& entry
->entry
!= abbrev_number
;
2039 entry
= entry
->next
)
2049 warn (_("DIE at offset %lx refers to abbreviation number %lu which does not exist\n"),
2050 die_offset
, abbrev_number
);
2055 printf (_(" (%s)\n"), get_TAG_name (entry
->tag
));
2060 need_base_address
= 0;
2062 case DW_TAG_compile_unit
:
2063 need_base_address
= 1;
2065 case DW_TAG_entry_point
:
2066 case DW_TAG_subprogram
:
2067 need_base_address
= 0;
2068 /* Assuming that there is no DW_AT_frame_base. */
2069 have_frame_base
= 0;
2073 for (attr
= entry
->first_attr
; attr
; attr
= attr
->next
)
2076 /* Show the offset from where the tag was extracted. */
2077 printf (" <%2lx>", (unsigned long)(tags
- section_begin
));
2079 tags
= read_and_display_attr (attr
->attribute
,
2082 compunit
.cu_pointer_size
,
2084 compunit
.cu_version
,
2085 debug_information
+ unit
,
2089 if (entry
->children
)
2094 /* Set num_debug_info_entries here so that it can be used to check if
2095 we need to process .debug_loc and .debug_ranges sections. */
2096 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
2097 && num_debug_info_entries
== 0)
2098 num_debug_info_entries
= num_units
;
2108 /* Locate and scan the .debug_info section in the file and record the pointer
2109 sizes and offsets for the compilation units in it. Usually an executable
2110 will have just one pointer size, but this is not guaranteed, and so we try
2111 not to make any assumptions. Returns zero upon failure, or the number of
2112 compilation units upon success. */
2115 load_debug_info (void * file
)
2117 /* Reset the last pointer size so that we can issue correct error
2118 messages if we are displaying the contents of more than one section. */
2119 last_pointer_size
= 0;
2120 warned_about_missing_comp_units
= FALSE
;
2122 /* If we have already tried and failed to load the .debug_info
2123 section then do not bother to repear the task. */
2124 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
2127 /* If we already have the information there is nothing else to do. */
2128 if (num_debug_info_entries
> 0)
2129 return num_debug_info_entries
;
2131 if (load_debug_section (info
, file
)
2132 && process_debug_info (&debug_displays
[info
].section
, file
, 1))
2133 return num_debug_info_entries
;
2135 num_debug_info_entries
= DEBUG_INFO_UNAVAILABLE
;
2140 display_debug_lines_raw (struct dwarf_section
*section
,
2141 unsigned char *data
,
2144 unsigned char *start
= section
->start
;
2146 printf (_("Raw dump of debug contents of section %s:\n\n"),
2151 DWARF2_Internal_LineInfo info
;
2152 unsigned char *standard_opcodes
;
2153 unsigned char *end_of_sequence
;
2154 unsigned char *hdrptr
;
2155 unsigned long hdroff
;
2156 int initial_length_size
;
2161 hdroff
= hdrptr
- start
;
2163 /* Check the length of the block. */
2164 info
.li_length
= byte_get (hdrptr
, 4);
2167 if (info
.li_length
== 0xffffffff)
2169 /* This section is 64-bit DWARF 3. */
2170 info
.li_length
= byte_get (hdrptr
, 8);
2173 initial_length_size
= 12;
2178 initial_length_size
= 4;
2181 if (info
.li_length
+ initial_length_size
> section
->size
)
2184 (_("The information in section %s appears to be corrupt - the section is too small\n"),
2189 /* Check its version number. */
2190 info
.li_version
= byte_get (hdrptr
, 2);
2192 if (info
.li_version
!= 2 && info
.li_version
!= 3)
2194 warn (_("Only DWARF version 2 and 3 line info is currently supported.\n"));
2198 info
.li_prologue_length
= byte_get (hdrptr
, offset_size
);
2199 hdrptr
+= offset_size
;
2200 info
.li_min_insn_length
= byte_get (hdrptr
, 1);
2202 info
.li_default_is_stmt
= byte_get (hdrptr
, 1);
2204 info
.li_line_base
= byte_get (hdrptr
, 1);
2206 info
.li_line_range
= byte_get (hdrptr
, 1);
2208 info
.li_opcode_base
= byte_get (hdrptr
, 1);
2211 /* Sign extend the line base field. */
2212 info
.li_line_base
<<= 24;
2213 info
.li_line_base
>>= 24;
2215 printf (_(" Offset: 0x%lx\n"), hdroff
);
2216 printf (_(" Length: %ld\n"), info
.li_length
);
2217 printf (_(" DWARF Version: %d\n"), info
.li_version
);
2218 printf (_(" Prologue Length: %d\n"), info
.li_prologue_length
);
2219 printf (_(" Minimum Instruction Length: %d\n"), info
.li_min_insn_length
);
2220 printf (_(" Initial value of 'is_stmt': %d\n"), info
.li_default_is_stmt
);
2221 printf (_(" Line Base: %d\n"), info
.li_line_base
);
2222 printf (_(" Line Range: %d\n"), info
.li_line_range
);
2223 printf (_(" Opcode Base: %d\n"), info
.li_opcode_base
);
2225 end_of_sequence
= data
+ info
.li_length
+ initial_length_size
;
2227 reset_state_machine (info
.li_default_is_stmt
);
2229 /* Display the contents of the Opcodes table. */
2230 standard_opcodes
= hdrptr
;
2232 printf (_("\n Opcodes:\n"));
2234 for (i
= 1; i
< info
.li_opcode_base
; i
++)
2235 printf (_(" Opcode %d has %d args\n"), i
, standard_opcodes
[i
- 1]);
2237 /* Display the contents of the Directory table. */
2238 data
= standard_opcodes
+ info
.li_opcode_base
- 1;
2241 printf (_("\n The Directory Table is empty.\n"));
2244 printf (_("\n The Directory Table:\n"));
2248 printf (_(" %s\n"), data
);
2250 data
+= strlen ((char *) data
) + 1;
2254 /* Skip the NUL at the end of the table. */
2257 /* Display the contents of the File Name table. */
2259 printf (_("\n The File Name Table is empty.\n"));
2262 printf (_("\n The File Name Table:\n"));
2263 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
2267 unsigned char *name
;
2268 unsigned int bytes_read
;
2270 printf (_(" %d\t"), ++state_machine_regs
.last_file_entry
);
2273 data
+= strlen ((char *) data
) + 1;
2275 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
2277 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
2279 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
2281 printf (_("%s\n"), name
);
2285 /* Skip the NUL at the end of the table. */
2288 /* Now display the statements. */
2289 printf (_("\n Line Number Statements:\n"));
2291 while (data
< end_of_sequence
)
2293 unsigned char op_code
;
2295 unsigned long int uladv
;
2296 unsigned int bytes_read
;
2300 if (op_code
>= info
.li_opcode_base
)
2302 op_code
-= info
.li_opcode_base
;
2303 uladv
= (op_code
/ info
.li_line_range
) * info
.li_min_insn_length
;
2304 state_machine_regs
.address
+= uladv
;
2305 printf (_(" Special opcode %d: advance Address by %lu to 0x%lx"),
2306 op_code
, uladv
, state_machine_regs
.address
);
2307 adv
= (op_code
% info
.li_line_range
) + info
.li_line_base
;
2308 state_machine_regs
.line
+= adv
;
2309 printf (_(" and Line by %d to %d\n"),
2310 adv
, state_machine_regs
.line
);
2312 else switch (op_code
)
2314 case DW_LNS_extended_op
:
2315 data
+= process_extended_line_op (data
, info
.li_default_is_stmt
);
2319 printf (_(" Copy\n"));
2322 case DW_LNS_advance_pc
:
2323 uladv
= read_leb128 (data
, & bytes_read
, 0);
2324 uladv
*= info
.li_min_insn_length
;
2326 state_machine_regs
.address
+= uladv
;
2327 printf (_(" Advance PC by %lu to 0x%lx\n"), uladv
,
2328 state_machine_regs
.address
);
2331 case DW_LNS_advance_line
:
2332 adv
= read_leb128 (data
, & bytes_read
, 1);
2334 state_machine_regs
.line
+= adv
;
2335 printf (_(" Advance Line by %d to %d\n"), adv
,
2336 state_machine_regs
.line
);
2339 case DW_LNS_set_file
:
2340 adv
= read_leb128 (data
, & bytes_read
, 0);
2342 printf (_(" Set File Name to entry %d in the File Name Table\n"),
2344 state_machine_regs
.file
= adv
;
2347 case DW_LNS_set_column
:
2348 uladv
= read_leb128 (data
, & bytes_read
, 0);
2350 printf (_(" Set column to %lu\n"), uladv
);
2351 state_machine_regs
.column
= uladv
;
2354 case DW_LNS_negate_stmt
:
2355 adv
= state_machine_regs
.is_stmt
;
2357 printf (_(" Set is_stmt to %d\n"), adv
);
2358 state_machine_regs
.is_stmt
= adv
;
2361 case DW_LNS_set_basic_block
:
2362 printf (_(" Set basic block\n"));
2363 state_machine_regs
.basic_block
= 1;
2366 case DW_LNS_const_add_pc
:
2367 uladv
= (((255 - info
.li_opcode_base
) / info
.li_line_range
)
2368 * info
.li_min_insn_length
);
2369 state_machine_regs
.address
+= uladv
;
2370 printf (_(" Advance PC by constant %lu to 0x%lx\n"), uladv
,
2371 state_machine_regs
.address
);
2374 case DW_LNS_fixed_advance_pc
:
2375 uladv
= byte_get (data
, 2);
2377 state_machine_regs
.address
+= uladv
;
2378 printf (_(" Advance PC by fixed size amount %lu to 0x%lx\n"),
2379 uladv
, state_machine_regs
.address
);
2382 case DW_LNS_set_prologue_end
:
2383 printf (_(" Set prologue_end to true\n"));
2386 case DW_LNS_set_epilogue_begin
:
2387 printf (_(" Set epilogue_begin to true\n"));
2390 case DW_LNS_set_isa
:
2391 uladv
= read_leb128 (data
, & bytes_read
, 0);
2393 printf (_(" Set ISA to %lu\n"), uladv
);
2397 printf (_(" Unknown opcode %d with operands: "), op_code
);
2399 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
2401 printf ("0x%lx%s", read_leb128 (data
, &bytes_read
, 0),
2402 i
== 1 ? "" : ", ");
2417 unsigned char *name
;
2418 unsigned int directory_index
;
2419 unsigned int modification_date
;
2420 unsigned int length
;
2423 /* Output a decoded representation of the .debug_line section. */
2426 display_debug_lines_decoded (struct dwarf_section
*section
,
2427 unsigned char *data
,
2430 printf (_("Decoded dump of debug contents of section %s:\n\n"),
2435 /* This loop amounts to one iteration per compilation unit. */
2436 DWARF2_Internal_LineInfo info
;
2437 unsigned char *standard_opcodes
;
2438 unsigned char *end_of_sequence
;
2439 unsigned char *hdrptr
;
2440 int initial_length_size
;
2443 File_Entry
*file_table
= NULL
;
2444 unsigned char **directory_table
= NULL
;
2445 unsigned int prev_line
= 0;
2449 /* Extract information from the Line Number Program Header.
2450 (section 6.2.4 in the Dwarf3 doc). */
2452 /* Get the length of this CU's line number information block. */
2453 info
.li_length
= byte_get (hdrptr
, 4);
2456 if (info
.li_length
== 0xffffffff)
2458 /* This section is 64-bit DWARF 3. */
2459 info
.li_length
= byte_get (hdrptr
, 8);
2462 initial_length_size
= 12;
2467 initial_length_size
= 4;
2470 if (info
.li_length
+ initial_length_size
> section
->size
)
2472 warn (_("The line info appears to be corrupt - "
2473 "the section is too small\n"));
2477 /* Get this CU's Line Number Block version number. */
2478 info
.li_version
= byte_get (hdrptr
, 2);
2480 if (info
.li_version
!= 2 && info
.li_version
!= 3)
2482 warn (_("Only DWARF version 2 and 3 line info is currently "
2487 info
.li_prologue_length
= byte_get (hdrptr
, offset_size
);
2488 hdrptr
+= offset_size
;
2489 info
.li_min_insn_length
= byte_get (hdrptr
, 1);
2491 info
.li_default_is_stmt
= byte_get (hdrptr
, 1);
2493 info
.li_line_base
= byte_get (hdrptr
, 1);
2495 info
.li_line_range
= byte_get (hdrptr
, 1);
2497 info
.li_opcode_base
= byte_get (hdrptr
, 1);
2500 /* Sign extend the line base field. */
2501 info
.li_line_base
<<= 24;
2502 info
.li_line_base
>>= 24;
2504 /* Find the end of this CU's Line Number Information Block. */
2505 end_of_sequence
= data
+ info
.li_length
+ initial_length_size
;
2507 reset_state_machine (info
.li_default_is_stmt
);
2509 /* Save a pointer to the contents of the Opcodes table. */
2510 standard_opcodes
= hdrptr
;
2512 /* Traverse the Directory table just to count entries. */
2513 data
= standard_opcodes
+ info
.li_opcode_base
- 1;
2516 unsigned int n_directories
= 0;
2517 unsigned char *ptr_directory_table
= data
;
2522 data
+= strlen ((char *) data
) + 1;
2526 /* Go through the directory table again to save the directories. */
2527 directory_table
= xmalloc (n_directories
* sizeof (unsigned char *));
2530 while (*ptr_directory_table
!= 0)
2532 directory_table
[i
] = ptr_directory_table
;
2533 ptr_directory_table
+= strlen ((char *) ptr_directory_table
) + 1;
2537 /* Skip the NUL at the end of the table. */
2540 /* Traverse the File Name table just to count the entries. */
2543 unsigned int n_files
= 0;
2544 unsigned char *ptr_file_name_table
= data
;
2549 unsigned int bytes_read
;
2551 /* Skip Name, directory index, last modification time and length
2553 data
+= strlen ((char *) data
) + 1;
2554 read_leb128 (data
, & bytes_read
, 0);
2556 read_leb128 (data
, & bytes_read
, 0);
2558 read_leb128 (data
, & bytes_read
, 0);
2564 /* Go through the file table again to save the strings. */
2565 file_table
= xmalloc (n_files
* sizeof (File_Entry
));
2568 while (*ptr_file_name_table
!= 0)
2570 unsigned int bytes_read
;
2572 file_table
[i
].name
= ptr_file_name_table
;
2573 ptr_file_name_table
+= strlen ((char *) ptr_file_name_table
) + 1;
2575 /* We are not interested in directory, time or size. */
2576 file_table
[i
].directory_index
= read_leb128 (ptr_file_name_table
,
2578 ptr_file_name_table
+= bytes_read
;
2579 file_table
[i
].modification_date
= read_leb128 (ptr_file_name_table
,
2581 ptr_file_name_table
+= bytes_read
;
2582 file_table
[i
].length
= read_leb128 (ptr_file_name_table
, & bytes_read
, 0);
2583 ptr_file_name_table
+= bytes_read
;
2588 /* Print the Compilation Unit's name and a header. */
2589 if (directory_table
== NULL
)
2591 printf (_("CU: %s:\n"), file_table
[0].name
);
2592 printf (_("File name Line number Starting address\n"));
2596 if (do_wide
|| strlen ((char *) directory_table
[0]) < 76)
2598 printf (_("CU: %s/%s:\n"), directory_table
[0],
2599 file_table
[0].name
);
2603 printf (_("%s:\n"), file_table
[0].name
);
2605 printf (_("File name Line number Starting address\n"));
2609 /* Skip the NUL at the end of the table. */
2612 /* This loop iterates through the Dwarf Line Number Program. */
2613 while (data
< end_of_sequence
)
2615 unsigned char op_code
;
2617 unsigned long int uladv
;
2618 unsigned int bytes_read
;
2619 int is_special_opcode
= 0;
2622 prev_line
= state_machine_regs
.line
;
2624 if (op_code
>= info
.li_opcode_base
)
2626 op_code
-= info
.li_opcode_base
;
2627 uladv
= (op_code
/ info
.li_line_range
) * info
.li_min_insn_length
;
2628 state_machine_regs
.address
+= uladv
;
2630 adv
= (op_code
% info
.li_line_range
) + info
.li_line_base
;
2631 state_machine_regs
.line
+= adv
;
2632 is_special_opcode
= 1;
2634 else switch (op_code
)
2636 case DW_LNS_extended_op
:
2638 unsigned int ext_op_code_len
;
2639 unsigned int bytes_read
;
2640 unsigned char ext_op_code
;
2641 unsigned char *op_code_data
= data
;
2643 ext_op_code_len
= read_leb128 (op_code_data
, &bytes_read
, 0);
2644 op_code_data
+= bytes_read
;
2646 if (ext_op_code_len
== 0)
2648 warn (_("badly formed extended line op encountered!\n"));
2651 ext_op_code_len
+= bytes_read
;
2652 ext_op_code
= *op_code_data
++;
2654 switch (ext_op_code
)
2656 case DW_LNE_end_sequence
:
2657 reset_state_machine (info
.li_default_is_stmt
);
2659 case DW_LNE_set_address
:
2660 state_machine_regs
.address
=
2661 byte_get (op_code_data
, ext_op_code_len
- bytes_read
- 1);
2663 case DW_LNE_define_file
:
2665 unsigned int dir_index
= 0;
2667 ++state_machine_regs
.last_file_entry
;
2668 op_code_data
+= strlen ((char *) op_code_data
) + 1;
2669 dir_index
= read_leb128 (op_code_data
, & bytes_read
, 0);
2670 op_code_data
+= bytes_read
;
2671 read_leb128 (op_code_data
, & bytes_read
, 0);
2672 op_code_data
+= bytes_read
;
2673 read_leb128 (op_code_data
, & bytes_read
, 0);
2675 printf (_("%s:\n"), directory_table
[dir_index
]);
2679 printf (_("UNKNOWN: length %d\n"), ext_op_code_len
- bytes_read
);
2682 data
+= ext_op_code_len
;
2688 case DW_LNS_advance_pc
:
2689 uladv
= read_leb128 (data
, & bytes_read
, 0);
2690 uladv
*= info
.li_min_insn_length
;
2692 state_machine_regs
.address
+= uladv
;
2695 case DW_LNS_advance_line
:
2696 adv
= read_leb128 (data
, & bytes_read
, 1);
2698 state_machine_regs
.line
+= adv
;
2701 case DW_LNS_set_file
:
2702 adv
= read_leb128 (data
, & bytes_read
, 0);
2704 state_machine_regs
.file
= adv
;
2705 if (file_table
[state_machine_regs
.file
- 1].directory_index
== 0)
2707 /* If directory index is 0, that means current directory. */
2708 printf (_("\n./%s:[++]\n"),
2709 file_table
[state_machine_regs
.file
- 1].name
);
2713 /* The directory index starts counting at 1. */
2714 printf (_("\n%s/%s:\n"),
2715 directory_table
[file_table
[state_machine_regs
.file
- 1].directory_index
- 1],
2716 file_table
[state_machine_regs
.file
- 1].name
);
2720 case DW_LNS_set_column
:
2721 uladv
= read_leb128 (data
, & bytes_read
, 0);
2723 state_machine_regs
.column
= uladv
;
2726 case DW_LNS_negate_stmt
:
2727 adv
= state_machine_regs
.is_stmt
;
2729 state_machine_regs
.is_stmt
= adv
;
2732 case DW_LNS_set_basic_block
:
2733 state_machine_regs
.basic_block
= 1;
2736 case DW_LNS_const_add_pc
:
2737 uladv
= (((255 - info
.li_opcode_base
) / info
.li_line_range
)
2738 * info
.li_min_insn_length
);
2739 state_machine_regs
.address
+= uladv
;
2742 case DW_LNS_fixed_advance_pc
:
2743 uladv
= byte_get (data
, 2);
2745 state_machine_regs
.address
+= uladv
;
2748 case DW_LNS_set_prologue_end
:
2751 case DW_LNS_set_epilogue_begin
:
2754 case DW_LNS_set_isa
:
2755 uladv
= read_leb128 (data
, & bytes_read
, 0);
2757 printf (_(" Set ISA to %lu\n"), uladv
);
2761 printf (_(" Unknown opcode %d with operands: "), op_code
);
2763 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
2765 printf ("0x%lx%s", read_leb128 (data
, &bytes_read
, 0),
2766 i
== 1 ? "" : ", ");
2773 /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row
2774 to the DWARF address/line matrix. */
2775 if ((is_special_opcode
) || (op_code
== DW_LNE_end_sequence
)
2776 || (op_code
== DW_LNS_copy
))
2778 const unsigned int MAX_FILENAME_LENGTH
= 35;
2779 char *fileName
= (char *)file_table
[state_machine_regs
.file
- 1].name
;
2780 char *newFileName
= NULL
;
2781 size_t fileNameLength
= strlen (fileName
);
2783 if ((fileNameLength
> MAX_FILENAME_LENGTH
) && (!do_wide
))
2785 newFileName
= xmalloc (MAX_FILENAME_LENGTH
+ 1);
2786 /* Truncate file name */
2787 strncpy (newFileName
,
2788 fileName
+ fileNameLength
- MAX_FILENAME_LENGTH
,
2789 MAX_FILENAME_LENGTH
+ 1);
2793 newFileName
= xmalloc (fileNameLength
+ 1);
2794 strncpy (newFileName
, fileName
, fileNameLength
+ 1);
2797 if (!do_wide
|| (fileNameLength
<= MAX_FILENAME_LENGTH
))
2799 printf (_("%-35s %11d %#18lx\n"), newFileName
,
2800 state_machine_regs
.line
, state_machine_regs
.address
);
2804 printf (_("%s %11d %#18lx\n"), newFileName
,
2805 state_machine_regs
.line
, state_machine_regs
.address
);
2808 if (op_code
== DW_LNE_end_sequence
)
2816 free (directory_table
);
2817 directory_table
= NULL
;
2825 display_debug_lines (struct dwarf_section
*section
, void *file
)
2827 unsigned char *data
= section
->start
;
2828 unsigned char *end
= data
+ section
->size
;
2830 int retValDecoded
= 1;
2832 if (load_debug_info (file
) == 0)
2834 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
2839 if (do_debug_lines
== 0)
2840 do_debug_lines
|= FLAG_DEBUG_LINES_RAW
;
2842 if (do_debug_lines
& FLAG_DEBUG_LINES_RAW
)
2843 retValRaw
= display_debug_lines_raw (section
, data
, end
);
2845 if (do_debug_lines
& FLAG_DEBUG_LINES_DECODED
)
2846 retValDecoded
= display_debug_lines_decoded (section
, data
, end
);
2848 if (!retValRaw
|| !retValDecoded
)
2855 find_debug_info_for_offset (unsigned long offset
)
2859 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
2862 for (i
= 0; i
< num_debug_info_entries
; i
++)
2863 if (debug_information
[i
].cu_offset
== offset
)
2864 return debug_information
+ i
;
2870 display_debug_pubnames (struct dwarf_section
*section
,
2871 void *file ATTRIBUTE_UNUSED
)
2873 DWARF2_Internal_PubNames pubnames
;
2874 unsigned char *start
= section
->start
;
2875 unsigned char *end
= start
+ section
->size
;
2877 /* It does not matter if this load fails,
2878 we test for that later on. */
2879 load_debug_info (file
);
2881 printf (_("Contents of the %s section:\n\n"), section
->name
);
2885 unsigned char *data
;
2886 unsigned long offset
;
2887 int offset_size
, initial_length_size
;
2891 pubnames
.pn_length
= byte_get (data
, 4);
2893 if (pubnames
.pn_length
== 0xffffffff)
2895 pubnames
.pn_length
= byte_get (data
, 8);
2898 initial_length_size
= 12;
2903 initial_length_size
= 4;
2906 pubnames
.pn_version
= byte_get (data
, 2);
2909 pubnames
.pn_offset
= byte_get (data
, offset_size
);
2910 data
+= offset_size
;
2912 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
2913 && num_debug_info_entries
> 0
2914 && find_debug_info_for_offset (pubnames
.pn_offset
) == NULL
)
2915 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
2916 pubnames
.pn_offset
, section
->name
);
2918 pubnames
.pn_size
= byte_get (data
, offset_size
);
2919 data
+= offset_size
;
2921 start
+= pubnames
.pn_length
+ initial_length_size
;
2923 if (pubnames
.pn_version
!= 2 && pubnames
.pn_version
!= 3)
2925 static int warned
= 0;
2929 warn (_("Only DWARF 2 and 3 pubnames are currently supported\n"));
2936 printf (_(" Length: %ld\n"),
2937 pubnames
.pn_length
);
2938 printf (_(" Version: %d\n"),
2939 pubnames
.pn_version
);
2940 printf (_(" Offset into .debug_info section: 0x%lx\n"),
2941 pubnames
.pn_offset
);
2942 printf (_(" Size of area in .debug_info section: %ld\n"),
2945 printf (_("\n Offset\tName\n"));
2949 offset
= byte_get (data
, offset_size
);
2953 data
+= offset_size
;
2954 printf (" %-6lx\t%s\n", offset
, data
);
2955 data
+= strlen ((char *) data
) + 1;
2958 while (offset
!= 0);
2966 display_debug_macinfo (struct dwarf_section
*section
,
2967 void *file ATTRIBUTE_UNUSED
)
2969 unsigned char *start
= section
->start
;
2970 unsigned char *end
= start
+ section
->size
;
2971 unsigned char *curr
= start
;
2972 unsigned int bytes_read
;
2973 enum dwarf_macinfo_record_type op
;
2975 printf (_("Contents of the %s section:\n\n"), section
->name
);
2979 unsigned int lineno
;
2987 case DW_MACINFO_start_file
:
2989 unsigned int filenum
;
2991 lineno
= read_leb128 (curr
, & bytes_read
, 0);
2993 filenum
= read_leb128 (curr
, & bytes_read
, 0);
2996 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"),
3001 case DW_MACINFO_end_file
:
3002 printf (_(" DW_MACINFO_end_file\n"));
3005 case DW_MACINFO_define
:
3006 lineno
= read_leb128 (curr
, & bytes_read
, 0);
3008 string
= (char *) curr
;
3009 curr
+= strlen (string
) + 1;
3010 printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"),
3014 case DW_MACINFO_undef
:
3015 lineno
= read_leb128 (curr
, & bytes_read
, 0);
3017 string
= (char *) curr
;
3018 curr
+= strlen (string
) + 1;
3019 printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"),
3023 case DW_MACINFO_vendor_ext
:
3025 unsigned int constant
;
3027 constant
= read_leb128 (curr
, & bytes_read
, 0);
3029 string
= (char *) curr
;
3030 curr
+= strlen (string
) + 1;
3031 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"),
3042 display_debug_abbrev (struct dwarf_section
*section
,
3043 void *file ATTRIBUTE_UNUSED
)
3045 abbrev_entry
*entry
;
3046 unsigned char *start
= section
->start
;
3047 unsigned char *end
= start
+ section
->size
;
3049 printf (_("Contents of the %s section:\n\n"), section
->name
);
3055 start
= process_abbrev_section (start
, end
);
3057 if (first_abbrev
== NULL
)
3060 printf (_(" Number TAG\n"));
3062 for (entry
= first_abbrev
; entry
; entry
= entry
->next
)
3066 printf (_(" %ld %s [%s]\n"),
3068 get_TAG_name (entry
->tag
),
3069 entry
->children
? _("has children") : _("no children"));
3071 for (attr
= entry
->first_attr
; attr
; attr
= attr
->next
)
3072 printf (_(" %-18s %s\n"),
3073 get_AT_name (attr
->attribute
),
3074 get_FORM_name (attr
->form
));
3085 display_debug_loc (struct dwarf_section
*section
, void *file
)
3087 unsigned char *start
= section
->start
;
3088 unsigned char *section_end
;
3089 unsigned long bytes
;
3090 unsigned char *section_begin
= start
;
3091 unsigned int num_loc_list
= 0;
3092 unsigned long last_offset
= 0;
3093 unsigned int first
= 0;
3096 int seen_first_offset
= 0;
3097 int use_debug_info
= 1;
3098 unsigned char *next
;
3100 bytes
= section
->size
;
3101 section_end
= start
+ bytes
;
3105 printf (_("\nThe %s section is empty.\n"), section
->name
);
3109 if (load_debug_info (file
) == 0)
3111 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
3116 /* Check the order of location list in .debug_info section. If
3117 offsets of location lists are in the ascending order, we can
3118 use `debug_information' directly. */
3119 for (i
= 0; i
< num_debug_info_entries
; i
++)
3123 num
= debug_information
[i
].num_loc_offsets
;
3124 num_loc_list
+= num
;
3126 /* Check if we can use `debug_information' directly. */
3127 if (use_debug_info
&& num
!= 0)
3129 if (!seen_first_offset
)
3131 /* This is the first location list. */
3132 last_offset
= debug_information
[i
].loc_offsets
[0];
3134 seen_first_offset
= 1;
3140 for (; j
< num
; j
++)
3143 debug_information
[i
].loc_offsets
[j
])
3148 last_offset
= debug_information
[i
].loc_offsets
[j
];
3153 if (!use_debug_info
)
3154 /* FIXME: Should we handle this case? */
3155 error (_("Location lists in .debug_info section aren't in ascending order!\n"));
3157 if (!seen_first_offset
)
3158 error (_("No location lists in .debug_info section!\n"));
3160 /* DWARF sections under Mach-O have non-zero addresses. */
3161 if (debug_information
[first
].num_loc_offsets
> 0
3162 && debug_information
[first
].loc_offsets
[0] != section
->address
)
3163 warn (_("Location lists in %s section start at 0x%lx\n"),
3164 section
->name
, debug_information
[first
].loc_offsets
[0]);
3166 printf (_("Contents of the %s section:\n\n"), section
->name
);
3167 printf (_(" Offset Begin End Expression\n"));
3169 seen_first_offset
= 0;
3170 for (i
= first
; i
< num_debug_info_entries
; i
++)
3174 unsigned short length
;
3175 unsigned long offset
;
3176 unsigned int pointer_size
;
3177 unsigned long cu_offset
;
3178 unsigned long base_address
;
3179 int need_frame_base
;
3182 pointer_size
= debug_information
[i
].pointer_size
;
3183 cu_offset
= debug_information
[i
].cu_offset
;
3185 for (j
= 0; j
< debug_information
[i
].num_loc_offsets
; j
++)
3187 has_frame_base
= debug_information
[i
].have_frame_base
[j
];
3188 /* DWARF sections under Mach-O have non-zero addresses. */
3189 offset
= debug_information
[i
].loc_offsets
[j
] - section
->address
;
3190 next
= section_begin
+ offset
;
3191 base_address
= debug_information
[i
].base_address
;
3193 if (!seen_first_offset
)
3194 seen_first_offset
= 1;
3198 warn (_("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n"),
3199 (unsigned long) (start
- section_begin
),
3200 (unsigned long) (next
- section_begin
));
3201 else if (start
> next
)
3202 warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n"),
3203 (unsigned long) (start
- section_begin
),
3204 (unsigned long) (next
- section_begin
));
3208 if (offset
>= bytes
)
3210 warn (_("Offset 0x%lx is bigger than .debug_loc section size.\n"),
3217 if (start
+ 2 * pointer_size
> section_end
)
3219 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
3224 /* Note: we use sign extension here in order to be sure that
3225 we can detect the -1 escape value. Sign extension into the
3226 top 32 bits of a 32-bit address will not affect the values
3227 that we display since we always show hex values, and always
3228 the bottom 32-bits. */
3229 begin
= byte_get_signed (start
, pointer_size
);
3230 start
+= pointer_size
;
3231 end
= byte_get_signed (start
, pointer_size
);
3232 start
+= pointer_size
;
3234 printf (" %8.8lx ", offset
);
3236 if (begin
== 0 && end
== 0)
3238 printf (_("<End of list>\n"));
3242 /* Check base address specifiers. */
3243 if (begin
== (dwarf_vma
) -1 && end
!= (dwarf_vma
) -1)
3246 print_dwarf_vma (begin
, pointer_size
);
3247 print_dwarf_vma (end
, pointer_size
);
3248 printf (_("(base address)\n"));
3252 if (start
+ 2 > section_end
)
3254 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
3259 length
= byte_get (start
, 2);
3262 if (start
+ length
> section_end
)
3264 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
3269 print_dwarf_vma (begin
+ base_address
, pointer_size
);
3270 print_dwarf_vma (end
+ base_address
, pointer_size
);
3273 need_frame_base
= decode_location_expression (start
,
3276 cu_offset
, section
);
3279 if (need_frame_base
&& !has_frame_base
)
3280 printf (_(" [without DW_AT_frame_base]"));
3283 fputs (_(" (start == end)"), stdout
);
3284 else if (begin
> end
)
3285 fputs (_(" (start > end)"), stdout
);
3294 if (start
< section_end
)
3295 warn (_("There are %ld unused bytes at the end of section %s\n"),
3296 (long) (section_end
- start
), section
->name
);
3302 display_debug_str (struct dwarf_section
*section
,
3303 void *file ATTRIBUTE_UNUSED
)
3305 unsigned char *start
= section
->start
;
3306 unsigned long bytes
= section
->size
;
3307 dwarf_vma addr
= section
->address
;
3311 printf (_("\nThe %s section is empty.\n"), section
->name
);
3315 printf (_("Contents of the %s section:\n\n"), section
->name
);
3323 lbytes
= (bytes
> 16 ? 16 : bytes
);
3325 printf (" 0x%8.8lx ", (unsigned long) addr
);
3327 for (j
= 0; j
< 16; j
++)
3330 printf ("%2.2x", start
[j
]);
3338 for (j
= 0; j
< lbytes
; j
++)
3341 if (k
>= ' ' && k
< 0x80)
3360 display_debug_info (struct dwarf_section
*section
, void *file
)
3362 return process_debug_info (section
, file
, 0);
3367 display_debug_aranges (struct dwarf_section
*section
,
3368 void *file ATTRIBUTE_UNUSED
)
3370 unsigned char *start
= section
->start
;
3371 unsigned char *end
= start
+ section
->size
;
3373 printf (_("Contents of the %s section:\n\n"), section
->name
);
3375 /* It does not matter if this load fails,
3376 we test for that later on. */
3377 load_debug_info (file
);
3381 unsigned char *hdrptr
;
3382 DWARF2_Internal_ARange arange
;
3383 unsigned char *ranges
;
3386 unsigned char address_size
;
3389 int initial_length_size
;
3393 arange
.ar_length
= byte_get (hdrptr
, 4);
3396 if (arange
.ar_length
== 0xffffffff)
3398 arange
.ar_length
= byte_get (hdrptr
, 8);
3401 initial_length_size
= 12;
3406 initial_length_size
= 4;
3409 arange
.ar_version
= byte_get (hdrptr
, 2);
3412 arange
.ar_info_offset
= byte_get (hdrptr
, offset_size
);
3413 hdrptr
+= offset_size
;
3415 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
3416 && num_debug_info_entries
> 0
3417 && find_debug_info_for_offset (arange
.ar_info_offset
) == NULL
)
3418 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
3419 arange
.ar_info_offset
, section
->name
);
3421 arange
.ar_pointer_size
= byte_get (hdrptr
, 1);
3424 arange
.ar_segment_size
= byte_get (hdrptr
, 1);
3427 if (arange
.ar_version
!= 2 && arange
.ar_version
!= 3)
3429 warn (_("Only DWARF 2 and 3 aranges are currently supported.\n"));
3433 printf (_(" Length: %ld\n"), arange
.ar_length
);
3434 printf (_(" Version: %d\n"), arange
.ar_version
);
3435 printf (_(" Offset into .debug_info: 0x%lx\n"), arange
.ar_info_offset
);
3436 printf (_(" Pointer Size: %d\n"), arange
.ar_pointer_size
);
3437 printf (_(" Segment Size: %d\n"), arange
.ar_segment_size
);
3439 address_size
= arange
.ar_pointer_size
+ arange
.ar_segment_size
;
3441 /* The DWARF spec does not require that the address size be a power
3442 of two, but we do. This will have to change if we ever encounter
3443 an uneven architecture. */
3444 if ((address_size
& (address_size
- 1)) != 0)
3446 warn (_("Pointer size + Segment size is not a power of two.\n"));
3450 if (address_size
> 4)
3451 printf (_("\n Address Length\n"));
3453 printf (_("\n Address Length\n"));
3457 /* Must pad to an alignment boundary that is twice the address size. */
3458 excess
= (hdrptr
- start
) % (2 * address_size
);
3460 ranges
+= (2 * address_size
) - excess
;
3462 start
+= arange
.ar_length
+ initial_length_size
;
3464 while (ranges
+ 2 * address_size
<= start
)
3466 address
= byte_get (ranges
, address_size
);
3468 ranges
+= address_size
;
3470 length
= byte_get (ranges
, address_size
);
3472 ranges
+= address_size
;
3475 print_dwarf_vma (address
, address_size
);
3476 print_dwarf_vma (length
, address_size
);
3486 /* Each debug_information[x].range_lists[y] gets this representation for
3487 sorting purposes. */
3491 /* The debug_information[x].range_lists[y] value. */
3492 unsigned long ranges_offset
;
3494 /* Original debug_information to find parameters of the data. */
3495 debug_info
*debug_info_p
;
3498 /* Sort struct range_entry in ascending order of its RANGES_OFFSET. */
3501 range_entry_compar (const void *ap
, const void *bp
)
3503 const struct range_entry
*a_re
= ap
;
3504 const struct range_entry
*b_re
= bp
;
3505 const unsigned long a
= a_re
->ranges_offset
;
3506 const unsigned long b
= b_re
->ranges_offset
;
3508 return (a
> b
) - (b
> a
);
3512 display_debug_ranges (struct dwarf_section
*section
,
3513 void *file ATTRIBUTE_UNUSED
)
3515 unsigned char *start
= section
->start
;
3516 unsigned char *section_end
;
3517 unsigned long bytes
;
3518 unsigned char *section_begin
= start
;
3519 unsigned int num_range_list
, i
;
3520 struct range_entry
*range_entries
, *range_entry_fill
;
3522 bytes
= section
->size
;
3523 section_end
= start
+ bytes
;
3527 printf (_("\nThe %s section is empty.\n"), section
->name
);
3531 if (load_debug_info (file
) == 0)
3533 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
3539 for (i
= 0; i
< num_debug_info_entries
; i
++)
3540 num_range_list
+= debug_information
[i
].num_range_lists
;
3542 if (num_range_list
== 0)
3543 error (_("No range lists in .debug_info section!\n"));
3545 range_entries
= xmalloc (sizeof (*range_entries
) * num_range_list
);
3546 range_entry_fill
= range_entries
;
3548 for (i
= 0; i
< num_debug_info_entries
; i
++)
3550 debug_info
*debug_info_p
= &debug_information
[i
];
3553 for (j
= 0; j
< debug_info_p
->num_range_lists
; j
++)
3555 range_entry_fill
->ranges_offset
= debug_info_p
->range_lists
[j
];
3556 range_entry_fill
->debug_info_p
= debug_info_p
;
3561 qsort (range_entries
, num_range_list
, sizeof (*range_entries
),
3562 range_entry_compar
);
3564 /* DWARF sections under Mach-O have non-zero addresses. */
3565 if (range_entries
[0].ranges_offset
!= section
->address
)
3566 warn (_("Range lists in %s section start at 0x%lx\n"),
3567 section
->name
, range_entries
[0].ranges_offset
);
3569 printf (_("Contents of the %s section:\n\n"), section
->name
);
3570 printf (_(" Offset Begin End\n"));
3572 for (i
= 0; i
< num_range_list
; i
++)
3574 struct range_entry
*range_entry
= &range_entries
[i
];
3575 debug_info
*debug_info_p
= range_entry
->debug_info_p
;
3576 unsigned int pointer_size
;
3577 unsigned long offset
;
3578 unsigned char *next
;
3579 unsigned long base_address
;
3581 pointer_size
= debug_info_p
->pointer_size
;
3583 /* DWARF sections under Mach-O have non-zero addresses. */
3584 offset
= range_entry
->ranges_offset
- section
->address
;
3585 next
= section_begin
+ offset
;
3586 base_address
= debug_info_p
->base_address
;
3591 warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"),
3592 (unsigned long) (start
- section_begin
),
3593 (unsigned long) (next
- section_begin
), section
->name
);
3594 else if (start
> next
)
3595 warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"),
3596 (unsigned long) (start
- section_begin
),
3597 (unsigned long) (next
- section_begin
), section
->name
);
3606 /* Note: we use sign extension here in order to be sure that
3607 we can detect the -1 escape value. Sign extension into the
3608 top 32 bits of a 32-bit address will not affect the values
3609 that we display since we always show hex values, and always
3610 the bottom 32-bits. */
3611 begin
= byte_get_signed (start
, pointer_size
);
3612 start
+= pointer_size
;
3613 end
= byte_get_signed (start
, pointer_size
);
3614 start
+= pointer_size
;
3616 printf (" %8.8lx ", offset
);
3618 if (begin
== 0 && end
== 0)
3620 printf (_("<End of list>\n"));
3624 /* Check base address specifiers. */
3625 if (begin
== (dwarf_vma
) -1 && end
!= (dwarf_vma
) -1)
3628 print_dwarf_vma (begin
, pointer_size
);
3629 print_dwarf_vma (end
, pointer_size
);
3630 printf ("(base address)\n");
3634 print_dwarf_vma (begin
+ base_address
, pointer_size
);
3635 print_dwarf_vma (end
+ base_address
, pointer_size
);
3638 fputs (_("(start == end)"), stdout
);
3639 else if (begin
> end
)
3640 fputs (_("(start > end)"), stdout
);
3647 free (range_entries
);
3652 typedef struct Frame_Chunk
3654 struct Frame_Chunk
*next
;
3655 unsigned char *chunk_start
;
3657 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
3658 short int *col_type
;
3661 unsigned int code_factor
;
3663 unsigned long pc_begin
;
3664 unsigned long pc_range
;
3668 unsigned char fde_encoding
;
3669 unsigned char cfa_exp
;
3673 static const char *const *dwarf_regnames
;
3674 static unsigned int dwarf_regnames_count
;
3676 /* A marker for a col_type that means this column was never referenced
3677 in the frame info. */
3678 #define DW_CFA_unreferenced (-1)
3680 /* Return 0 if not more space is needed, 1 if more space is needed,
3681 -1 for invalid reg. */
3684 frame_need_space (Frame_Chunk
*fc
, unsigned int reg
)
3686 int prev
= fc
->ncols
;
3688 if (reg
< (unsigned int) fc
->ncols
)
3691 if (dwarf_regnames_count
3692 && reg
> dwarf_regnames_count
)
3695 fc
->ncols
= reg
+ 1;
3696 fc
->col_type
= xcrealloc (fc
->col_type
, fc
->ncols
, sizeof (short int));
3697 fc
->col_offset
= xcrealloc (fc
->col_offset
, fc
->ncols
, sizeof (int));
3699 while (prev
< fc
->ncols
)
3701 fc
->col_type
[prev
] = DW_CFA_unreferenced
;
3702 fc
->col_offset
[prev
] = 0;
3708 static const char *const dwarf_regnames_i386
[] =
3710 "eax", "ecx", "edx", "ebx",
3711 "esp", "ebp", "esi", "edi",
3712 "eip", "eflags", NULL
,
3713 "st0", "st1", "st2", "st3",
3714 "st4", "st5", "st6", "st7",
3716 "xmm0", "xmm1", "xmm2", "xmm3",
3717 "xmm4", "xmm5", "xmm6", "xmm7",
3718 "mm0", "mm1", "mm2", "mm3",
3719 "mm4", "mm5", "mm6", "mm7",
3720 "fcw", "fsw", "mxcsr",
3721 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
,
3725 static const char *const dwarf_regnames_x86_64
[] =
3727 "rax", "rdx", "rcx", "rbx",
3728 "rsi", "rdi", "rbp", "rsp",
3729 "r8", "r9", "r10", "r11",
3730 "r12", "r13", "r14", "r15",
3732 "xmm0", "xmm1", "xmm2", "xmm3",
3733 "xmm4", "xmm5", "xmm6", "xmm7",
3734 "xmm8", "xmm9", "xmm10", "xmm11",
3735 "xmm12", "xmm13", "xmm14", "xmm15",
3736 "st0", "st1", "st2", "st3",
3737 "st4", "st5", "st6", "st7",
3738 "mm0", "mm1", "mm2", "mm3",
3739 "mm4", "mm5", "mm6", "mm7",
3741 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
,
3742 "fs.base", "gs.base", NULL
, NULL
,
3744 "mxcsr", "fcw", "fsw"
3748 init_dwarf_regnames (unsigned int e_machine
)
3754 dwarf_regnames
= dwarf_regnames_i386
;
3755 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_i386
);
3759 dwarf_regnames
= dwarf_regnames_x86_64
;
3760 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_x86_64
);
3769 regname (unsigned int regno
, int row
)
3771 static char reg
[64];
3773 && regno
< dwarf_regnames_count
3774 && dwarf_regnames
[regno
] != NULL
)
3777 return dwarf_regnames
[regno
];
3778 snprintf (reg
, sizeof (reg
), "r%d (%s)", regno
,
3779 dwarf_regnames
[regno
]);
3782 snprintf (reg
, sizeof (reg
), "r%d", regno
);
3787 frame_display_row (Frame_Chunk
*fc
, int *need_col_headers
, int *max_regs
)
3792 if (*max_regs
< fc
->ncols
)
3793 *max_regs
= fc
->ncols
;
3795 if (*need_col_headers
)
3797 static const char *loc
= " LOC";
3799 *need_col_headers
= 0;
3801 printf ("%-*s CFA ", eh_addr_size
* 2, loc
);
3803 for (r
= 0; r
< *max_regs
; r
++)
3804 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
3809 printf ("%-5s ", regname (r
, 1));
3815 printf ("%0*lx ", eh_addr_size
* 2, fc
->pc_begin
);
3817 strcpy (tmp
, "exp");
3819 sprintf (tmp
, "%s%+d", regname (fc
->cfa_reg
, 1), fc
->cfa_offset
);
3820 printf ("%-8s ", tmp
);
3822 for (r
= 0; r
< fc
->ncols
; r
++)
3824 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
3826 switch (fc
->col_type
[r
])
3828 case DW_CFA_undefined
:
3831 case DW_CFA_same_value
:
3835 sprintf (tmp
, "c%+d", fc
->col_offset
[r
]);
3837 case DW_CFA_val_offset
:
3838 sprintf (tmp
, "v%+d", fc
->col_offset
[r
]);
3840 case DW_CFA_register
:
3841 sprintf (tmp
, "%s", regname (fc
->col_offset
[r
], 0));
3843 case DW_CFA_expression
:
3844 strcpy (tmp
, "exp");
3846 case DW_CFA_val_expression
:
3847 strcpy (tmp
, "vexp");
3850 strcpy (tmp
, "n/a");
3853 printf ("%-5s ", tmp
);
3859 #define GET(N) byte_get (start, N); start += N
3860 #define LEB() read_leb128 (start, & length_return, 0); start += length_return
3861 #define SLEB() read_leb128 (start, & length_return, 1); start += length_return
3864 display_debug_frames (struct dwarf_section
*section
,
3865 void *file ATTRIBUTE_UNUSED
)
3867 unsigned char *start
= section
->start
;
3868 unsigned char *end
= start
+ section
->size
;
3869 unsigned char *section_start
= start
;
3870 Frame_Chunk
*chunks
= 0;
3871 Frame_Chunk
*remembered_state
= 0;
3873 int is_eh
= strcmp (section
->name
, ".eh_frame") == 0;
3874 unsigned int length_return
;
3876 const char *bad_reg
= _("bad register: ");
3878 printf (_("Contents of the %s section:\n"), section
->name
);
3882 unsigned char *saved_start
;
3883 unsigned char *block_end
;
3884 unsigned long length
;
3885 unsigned long cie_id
;
3888 int need_col_headers
= 1;
3889 unsigned char *augmentation_data
= NULL
;
3890 unsigned long augmentation_data_len
= 0;
3891 int encoded_ptr_size
= eh_addr_size
;
3893 int initial_length_size
;
3895 saved_start
= start
;
3896 length
= byte_get (start
, 4); start
+= 4;
3900 printf ("\n%08lx ZERO terminator\n\n",
3901 (unsigned long)(saved_start
- section_start
));
3905 if (length
== 0xffffffff)
3907 length
= byte_get (start
, 8);
3910 initial_length_size
= 12;
3915 initial_length_size
= 4;
3918 block_end
= saved_start
+ length
+ initial_length_size
;
3919 if (block_end
> end
)
3921 warn ("Invalid length %#08lx in FDE at %#08lx\n",
3922 length
, (unsigned long)(saved_start
- section_start
));
3925 cie_id
= byte_get (start
, offset_size
); start
+= offset_size
;
3927 if (is_eh
? (cie_id
== 0) : (cie_id
== DW_CIE_ID
))
3931 fc
= xmalloc (sizeof (Frame_Chunk
));
3932 memset (fc
, 0, sizeof (Frame_Chunk
));
3936 fc
->chunk_start
= saved_start
;
3938 fc
->col_type
= xmalloc (sizeof (short int));
3939 fc
->col_offset
= xmalloc (sizeof (int));
3940 frame_need_space (fc
, max_regs
- 1);
3944 fc
->augmentation
= (char *) start
;
3945 start
= (unsigned char *) strchr ((char *) start
, '\0') + 1;
3947 if (fc
->augmentation
[0] == 'z')
3949 fc
->code_factor
= LEB ();
3950 fc
->data_factor
= SLEB ();
3959 augmentation_data_len
= LEB ();
3960 augmentation_data
= start
;
3961 start
+= augmentation_data_len
;
3963 else if (strcmp (fc
->augmentation
, "eh") == 0)
3965 start
+= eh_addr_size
;
3966 fc
->code_factor
= LEB ();
3967 fc
->data_factor
= SLEB ();
3979 fc
->code_factor
= LEB ();
3980 fc
->data_factor
= SLEB ();
3992 if (do_debug_frames_interp
)
3993 printf ("\n%08lx %08lx %08lx CIE \"%s\" cf=%d df=%d ra=%d\n",
3994 (unsigned long)(saved_start
- section_start
), length
, cie_id
,
3995 fc
->augmentation
, fc
->code_factor
, fc
->data_factor
,
3999 printf ("\n%08lx %08lx %08lx CIE\n",
4000 (unsigned long)(saved_start
- section_start
), length
, cie_id
);
4001 printf (" Version: %d\n", version
);
4002 printf (" Augmentation: \"%s\"\n", fc
->augmentation
);
4003 printf (" Code alignment factor: %u\n", fc
->code_factor
);
4004 printf (" Data alignment factor: %d\n", fc
->data_factor
);
4005 printf (" Return address column: %d\n", fc
->ra
);
4007 if (augmentation_data_len
)
4010 printf (" Augmentation data: ");
4011 for (i
= 0; i
< augmentation_data_len
; ++i
)
4012 printf (" %02x", augmentation_data
[i
]);
4018 if (augmentation_data_len
)
4020 unsigned char *p
, *q
;
4021 p
= (unsigned char *) fc
->augmentation
+ 1;
4022 q
= augmentation_data
;
4029 q
+= 1 + size_of_encoded_value (*q
);
4031 fc
->fde_encoding
= *q
++;
4037 if (fc
->fde_encoding
)
4038 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
4041 frame_need_space (fc
, fc
->ra
);
4045 unsigned char *look_for
;
4046 static Frame_Chunk fde_fc
;
4049 memset (fc
, 0, sizeof (Frame_Chunk
));
4051 look_for
= is_eh
? start
- 4 - cie_id
: section_start
+ cie_id
;
4053 for (cie
= chunks
; cie
; cie
= cie
->next
)
4054 if (cie
->chunk_start
== look_for
)
4059 warn ("Invalid CIE pointer %#08lx in FDE at %#08lx\n",
4060 cie_id
, (unsigned long)(saved_start
- section_start
));
4062 fc
->col_type
= xmalloc (sizeof (short int));
4063 fc
->col_offset
= xmalloc (sizeof (int));
4064 frame_need_space (fc
, max_regs
- 1);
4066 fc
->augmentation
= "";
4067 fc
->fde_encoding
= 0;
4071 fc
->ncols
= cie
->ncols
;
4072 fc
->col_type
= xcmalloc (fc
->ncols
, sizeof (short int));
4073 fc
->col_offset
= xcmalloc (fc
->ncols
, sizeof (int));
4074 memcpy (fc
->col_type
, cie
->col_type
, fc
->ncols
* sizeof (short int));
4075 memcpy (fc
->col_offset
, cie
->col_offset
, fc
->ncols
* sizeof (int));
4076 fc
->augmentation
= cie
->augmentation
;
4077 fc
->code_factor
= cie
->code_factor
;
4078 fc
->data_factor
= cie
->data_factor
;
4079 fc
->cfa_reg
= cie
->cfa_reg
;
4080 fc
->cfa_offset
= cie
->cfa_offset
;
4082 frame_need_space (fc
, max_regs
- 1);
4083 fc
->fde_encoding
= cie
->fde_encoding
;
4086 if (fc
->fde_encoding
)
4087 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
4089 fc
->pc_begin
= get_encoded_value (start
, fc
->fde_encoding
);
4090 if ((fc
->fde_encoding
& 0x70) == DW_EH_PE_pcrel
)
4091 fc
->pc_begin
+= section
->address
+ (start
- section_start
);
4092 start
+= encoded_ptr_size
;
4093 fc
->pc_range
= byte_get (start
, encoded_ptr_size
);
4094 start
+= encoded_ptr_size
;
4096 if (cie
->augmentation
[0] == 'z')
4098 augmentation_data_len
= LEB ();
4099 augmentation_data
= start
;
4100 start
+= augmentation_data_len
;
4103 printf ("\n%08lx %08lx %08lx FDE cie=%08lx pc=%08lx..%08lx\n",
4104 (unsigned long)(saved_start
- section_start
), length
, cie_id
,
4105 (unsigned long)(cie
->chunk_start
- section_start
),
4106 fc
->pc_begin
, fc
->pc_begin
+ fc
->pc_range
);
4107 if (! do_debug_frames_interp
&& augmentation_data_len
)
4111 printf (" Augmentation data: ");
4112 for (i
= 0; i
< augmentation_data_len
; ++i
)
4113 printf (" %02x", augmentation_data
[i
]);
4119 /* At this point, fc is the current chunk, cie (if any) is set, and
4120 we're about to interpret instructions for the chunk. */
4121 /* ??? At present we need to do this always, since this sizes the
4122 fc->col_type and fc->col_offset arrays, which we write into always.
4123 We should probably split the interpreted and non-interpreted bits
4124 into two different routines, since there's so much that doesn't
4125 really overlap between them. */
4126 if (1 || do_debug_frames_interp
)
4128 /* Start by making a pass over the chunk, allocating storage
4129 and taking note of what registers are used. */
4130 unsigned char *tmp
= start
;
4132 while (start
< block_end
)
4135 unsigned long reg
, tmp
;
4142 /* Warning: if you add any more cases to this switch, be
4143 sure to add them to the corresponding switch below. */
4146 case DW_CFA_advance_loc
:
4150 if (frame_need_space (fc
, opa
) >= 0)
4151 fc
->col_type
[opa
] = DW_CFA_undefined
;
4153 case DW_CFA_restore
:
4154 if (frame_need_space (fc
, opa
) >= 0)
4155 fc
->col_type
[opa
] = DW_CFA_undefined
;
4157 case DW_CFA_set_loc
:
4158 start
+= encoded_ptr_size
;
4160 case DW_CFA_advance_loc1
:
4163 case DW_CFA_advance_loc2
:
4166 case DW_CFA_advance_loc4
:
4169 case DW_CFA_offset_extended
:
4170 case DW_CFA_val_offset
:
4171 reg
= LEB (); LEB ();
4172 if (frame_need_space (fc
, reg
) >= 0)
4173 fc
->col_type
[reg
] = DW_CFA_undefined
;
4175 case DW_CFA_restore_extended
:
4177 frame_need_space (fc
, reg
);
4178 if (frame_need_space (fc
, reg
) >= 0)
4179 fc
->col_type
[reg
] = DW_CFA_undefined
;
4181 case DW_CFA_undefined
:
4183 if (frame_need_space (fc
, reg
) >= 0)
4184 fc
->col_type
[reg
] = DW_CFA_undefined
;
4186 case DW_CFA_same_value
:
4188 if (frame_need_space (fc
, reg
) >= 0)
4189 fc
->col_type
[reg
] = DW_CFA_undefined
;
4191 case DW_CFA_register
:
4192 reg
= LEB (); LEB ();
4193 if (frame_need_space (fc
, reg
) >= 0)
4194 fc
->col_type
[reg
] = DW_CFA_undefined
;
4196 case DW_CFA_def_cfa
:
4199 case DW_CFA_def_cfa_register
:
4202 case DW_CFA_def_cfa_offset
:
4205 case DW_CFA_def_cfa_expression
:
4209 case DW_CFA_expression
:
4210 case DW_CFA_val_expression
:
4214 if (frame_need_space (fc
, reg
) >= 0)
4215 fc
->col_type
[reg
] = DW_CFA_undefined
;
4217 case DW_CFA_offset_extended_sf
:
4218 case DW_CFA_val_offset_sf
:
4219 reg
= LEB (); SLEB ();
4220 if (frame_need_space (fc
, reg
) >= 0)
4221 fc
->col_type
[reg
] = DW_CFA_undefined
;
4223 case DW_CFA_def_cfa_sf
:
4226 case DW_CFA_def_cfa_offset_sf
:
4229 case DW_CFA_MIPS_advance_loc8
:
4232 case DW_CFA_GNU_args_size
:
4235 case DW_CFA_GNU_negative_offset_extended
:
4236 reg
= LEB (); LEB ();
4237 if (frame_need_space (fc
, reg
) >= 0)
4238 fc
->col_type
[reg
] = DW_CFA_undefined
;
4247 /* Now we know what registers are used, make a second pass over
4248 the chunk, this time actually printing out the info. */
4250 while (start
< block_end
)
4253 unsigned long ul
, reg
, roffs
;
4256 const char *reg_prefix
= "";
4263 /* Warning: if you add any more cases to this switch, be
4264 sure to add them to the corresponding switch above. */
4267 case DW_CFA_advance_loc
:
4268 if (do_debug_frames_interp
)
4269 frame_display_row (fc
, &need_col_headers
, &max_regs
);
4271 printf (" DW_CFA_advance_loc: %d to %08lx\n",
4272 opa
* fc
->code_factor
,
4273 fc
->pc_begin
+ opa
* fc
->code_factor
);
4274 fc
->pc_begin
+= opa
* fc
->code_factor
;
4279 if (opa
>= (unsigned int) fc
->ncols
)
4280 reg_prefix
= bad_reg
;
4281 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4282 printf (" DW_CFA_offset: %s%s at cfa%+ld\n",
4283 reg_prefix
, regname (opa
, 0),
4284 roffs
* fc
->data_factor
);
4285 if (*reg_prefix
== '\0')
4287 fc
->col_type
[opa
] = DW_CFA_offset
;
4288 fc
->col_offset
[opa
] = roffs
* fc
->data_factor
;
4292 case DW_CFA_restore
:
4293 if (opa
>= (unsigned int) cie
->ncols
4294 || opa
>= (unsigned int) fc
->ncols
)
4295 reg_prefix
= bad_reg
;
4296 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4297 printf (" DW_CFA_restore: %s%s\n",
4298 reg_prefix
, regname (opa
, 0));
4299 if (*reg_prefix
== '\0')
4301 fc
->col_type
[opa
] = cie
->col_type
[opa
];
4302 fc
->col_offset
[opa
] = cie
->col_offset
[opa
];
4306 case DW_CFA_set_loc
:
4307 vma
= get_encoded_value (start
, fc
->fde_encoding
);
4308 if ((fc
->fde_encoding
& 0x70) == DW_EH_PE_pcrel
)
4309 vma
+= section
->address
+ (start
- section_start
);
4310 start
+= encoded_ptr_size
;
4311 if (do_debug_frames_interp
)
4312 frame_display_row (fc
, &need_col_headers
, &max_regs
);
4314 printf (" DW_CFA_set_loc: %08lx\n", (unsigned long)vma
);
4318 case DW_CFA_advance_loc1
:
4319 ofs
= byte_get (start
, 1); start
+= 1;
4320 if (do_debug_frames_interp
)
4321 frame_display_row (fc
, &need_col_headers
, &max_regs
);
4323 printf (" DW_CFA_advance_loc1: %ld to %08lx\n",
4324 ofs
* fc
->code_factor
,
4325 fc
->pc_begin
+ ofs
* fc
->code_factor
);
4326 fc
->pc_begin
+= ofs
* fc
->code_factor
;
4329 case DW_CFA_advance_loc2
:
4330 ofs
= byte_get (start
, 2); start
+= 2;
4331 if (do_debug_frames_interp
)
4332 frame_display_row (fc
, &need_col_headers
, &max_regs
);
4334 printf (" DW_CFA_advance_loc2: %ld to %08lx\n",
4335 ofs
* fc
->code_factor
,
4336 fc
->pc_begin
+ ofs
* fc
->code_factor
);
4337 fc
->pc_begin
+= ofs
* fc
->code_factor
;
4340 case DW_CFA_advance_loc4
:
4341 ofs
= byte_get (start
, 4); start
+= 4;
4342 if (do_debug_frames_interp
)
4343 frame_display_row (fc
, &need_col_headers
, &max_regs
);
4345 printf (" DW_CFA_advance_loc4: %ld to %08lx\n",
4346 ofs
* fc
->code_factor
,
4347 fc
->pc_begin
+ ofs
* fc
->code_factor
);
4348 fc
->pc_begin
+= ofs
* fc
->code_factor
;
4351 case DW_CFA_offset_extended
:
4354 if (reg
>= (unsigned int) fc
->ncols
)
4355 reg_prefix
= bad_reg
;
4356 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4357 printf (" DW_CFA_offset_extended: %s%s at cfa%+ld\n",
4358 reg_prefix
, regname (reg
, 0),
4359 roffs
* fc
->data_factor
);
4360 if (*reg_prefix
== '\0')
4362 fc
->col_type
[reg
] = DW_CFA_offset
;
4363 fc
->col_offset
[reg
] = roffs
* fc
->data_factor
;
4367 case DW_CFA_val_offset
:
4370 if (reg
>= (unsigned int) fc
->ncols
)
4371 reg_prefix
= bad_reg
;
4372 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4373 printf (" DW_CFA_val_offset: %s%s at cfa%+ld\n",
4374 reg_prefix
, regname (reg
, 0),
4375 roffs
* fc
->data_factor
);
4376 if (*reg_prefix
== '\0')
4378 fc
->col_type
[reg
] = DW_CFA_val_offset
;
4379 fc
->col_offset
[reg
] = roffs
* fc
->data_factor
;
4383 case DW_CFA_restore_extended
:
4385 if (reg
>= (unsigned int) cie
->ncols
4386 || reg
>= (unsigned int) fc
->ncols
)
4387 reg_prefix
= bad_reg
;
4388 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4389 printf (" DW_CFA_restore_extended: %s%s\n",
4390 reg_prefix
, regname (reg
, 0));
4391 if (*reg_prefix
== '\0')
4393 fc
->col_type
[reg
] = cie
->col_type
[reg
];
4394 fc
->col_offset
[reg
] = cie
->col_offset
[reg
];
4398 case DW_CFA_undefined
:
4400 if (reg
>= (unsigned int) fc
->ncols
)
4401 reg_prefix
= bad_reg
;
4402 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4403 printf (" DW_CFA_undefined: %s%s\n",
4404 reg_prefix
, regname (reg
, 0));
4405 if (*reg_prefix
== '\0')
4407 fc
->col_type
[reg
] = DW_CFA_undefined
;
4408 fc
->col_offset
[reg
] = 0;
4412 case DW_CFA_same_value
:
4414 if (reg
>= (unsigned int) fc
->ncols
)
4415 reg_prefix
= bad_reg
;
4416 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4417 printf (" DW_CFA_same_value: %s%s\n",
4418 reg_prefix
, regname (reg
, 0));
4419 if (*reg_prefix
== '\0')
4421 fc
->col_type
[reg
] = DW_CFA_same_value
;
4422 fc
->col_offset
[reg
] = 0;
4426 case DW_CFA_register
:
4429 if (reg
>= (unsigned int) fc
->ncols
)
4430 reg_prefix
= bad_reg
;
4431 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4433 printf (" DW_CFA_register: %s%s in ",
4434 reg_prefix
, regname (reg
, 0));
4435 puts (regname (roffs
, 0));
4437 if (*reg_prefix
== '\0')
4439 fc
->col_type
[reg
] = DW_CFA_register
;
4440 fc
->col_offset
[reg
] = roffs
;
4444 case DW_CFA_remember_state
:
4445 if (! do_debug_frames_interp
)
4446 printf (" DW_CFA_remember_state\n");
4447 rs
= xmalloc (sizeof (Frame_Chunk
));
4448 rs
->ncols
= fc
->ncols
;
4449 rs
->col_type
= xcmalloc (rs
->ncols
, sizeof (short int));
4450 rs
->col_offset
= xcmalloc (rs
->ncols
, sizeof (int));
4451 memcpy (rs
->col_type
, fc
->col_type
, rs
->ncols
);
4452 memcpy (rs
->col_offset
, fc
->col_offset
, rs
->ncols
* sizeof (int));
4453 rs
->next
= remembered_state
;
4454 remembered_state
= rs
;
4457 case DW_CFA_restore_state
:
4458 if (! do_debug_frames_interp
)
4459 printf (" DW_CFA_restore_state\n");
4460 rs
= remembered_state
;
4463 remembered_state
= rs
->next
;
4464 frame_need_space (fc
, rs
->ncols
- 1);
4465 memcpy (fc
->col_type
, rs
->col_type
, rs
->ncols
);
4466 memcpy (fc
->col_offset
, rs
->col_offset
,
4467 rs
->ncols
* sizeof (int));
4468 free (rs
->col_type
);
4469 free (rs
->col_offset
);
4472 else if (do_debug_frames_interp
)
4473 printf ("Mismatched DW_CFA_restore_state\n");
4476 case DW_CFA_def_cfa
:
4477 fc
->cfa_reg
= LEB ();
4478 fc
->cfa_offset
= LEB ();
4480 if (! do_debug_frames_interp
)
4481 printf (" DW_CFA_def_cfa: %s ofs %d\n",
4482 regname (fc
->cfa_reg
, 0), fc
->cfa_offset
);
4485 case DW_CFA_def_cfa_register
:
4486 fc
->cfa_reg
= LEB ();
4488 if (! do_debug_frames_interp
)
4489 printf (" DW_CFA_def_cfa_register: %s\n",
4490 regname (fc
->cfa_reg
, 0));
4493 case DW_CFA_def_cfa_offset
:
4494 fc
->cfa_offset
= LEB ();
4495 if (! do_debug_frames_interp
)
4496 printf (" DW_CFA_def_cfa_offset: %d\n", fc
->cfa_offset
);
4500 if (! do_debug_frames_interp
)
4501 printf (" DW_CFA_nop\n");
4504 case DW_CFA_def_cfa_expression
:
4506 if (! do_debug_frames_interp
)
4508 printf (" DW_CFA_def_cfa_expression (");
4509 decode_location_expression (start
, eh_addr_size
, ul
, 0,
4517 case DW_CFA_expression
:
4520 if (reg
>= (unsigned int) fc
->ncols
)
4521 reg_prefix
= bad_reg
;
4522 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4524 printf (" DW_CFA_expression: %s%s (",
4525 reg_prefix
, regname (reg
, 0));
4526 decode_location_expression (start
, eh_addr_size
,
4530 if (*reg_prefix
== '\0')
4531 fc
->col_type
[reg
] = DW_CFA_expression
;
4535 case DW_CFA_val_expression
:
4538 if (reg
>= (unsigned int) fc
->ncols
)
4539 reg_prefix
= bad_reg
;
4540 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4542 printf (" DW_CFA_val_expression: %s%s (",
4543 reg_prefix
, regname (reg
, 0));
4544 decode_location_expression (start
, eh_addr_size
, ul
, 0,
4548 if (*reg_prefix
== '\0')
4549 fc
->col_type
[reg
] = DW_CFA_val_expression
;
4553 case DW_CFA_offset_extended_sf
:
4556 if (frame_need_space (fc
, reg
) < 0)
4557 reg_prefix
= bad_reg
;
4558 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4559 printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+ld\n",
4560 reg_prefix
, regname (reg
, 0),
4561 l
* fc
->data_factor
);
4562 if (*reg_prefix
== '\0')
4564 fc
->col_type
[reg
] = DW_CFA_offset
;
4565 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
4569 case DW_CFA_val_offset_sf
:
4572 if (frame_need_space (fc
, reg
) < 0)
4573 reg_prefix
= bad_reg
;
4574 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4575 printf (" DW_CFA_val_offset_sf: %s%s at cfa%+ld\n",
4576 reg_prefix
, regname (reg
, 0),
4577 l
* fc
->data_factor
);
4578 if (*reg_prefix
== '\0')
4580 fc
->col_type
[reg
] = DW_CFA_val_offset
;
4581 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
4585 case DW_CFA_def_cfa_sf
:
4586 fc
->cfa_reg
= LEB ();
4587 fc
->cfa_offset
= SLEB ();
4588 fc
->cfa_offset
= fc
->cfa_offset
* fc
->data_factor
;
4590 if (! do_debug_frames_interp
)
4591 printf (" DW_CFA_def_cfa_sf: %s ofs %d\n",
4592 regname (fc
->cfa_reg
, 0), fc
->cfa_offset
);
4595 case DW_CFA_def_cfa_offset_sf
:
4596 fc
->cfa_offset
= SLEB ();
4597 fc
->cfa_offset
= fc
->cfa_offset
* fc
->data_factor
;
4598 if (! do_debug_frames_interp
)
4599 printf (" DW_CFA_def_cfa_offset_sf: %d\n", fc
->cfa_offset
);
4602 case DW_CFA_MIPS_advance_loc8
:
4603 ofs
= byte_get (start
, 8); start
+= 8;
4604 if (do_debug_frames_interp
)
4605 frame_display_row (fc
, &need_col_headers
, &max_regs
);
4607 printf (" DW_CFA_MIPS_advance_loc8: %ld to %08lx\n",
4608 ofs
* fc
->code_factor
,
4609 fc
->pc_begin
+ ofs
* fc
->code_factor
);
4610 fc
->pc_begin
+= ofs
* fc
->code_factor
;
4613 case DW_CFA_GNU_window_save
:
4614 if (! do_debug_frames_interp
)
4615 printf (" DW_CFA_GNU_window_save\n");
4618 case DW_CFA_GNU_args_size
:
4620 if (! do_debug_frames_interp
)
4621 printf (" DW_CFA_GNU_args_size: %ld\n", ul
);
4624 case DW_CFA_GNU_negative_offset_extended
:
4627 if (frame_need_space (fc
, reg
) < 0)
4628 reg_prefix
= bad_reg
;
4629 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4630 printf (" DW_CFA_GNU_negative_offset_extended: %s%s at cfa%+ld\n",
4631 reg_prefix
, regname (reg
, 0),
4632 l
* fc
->data_factor
);
4633 if (*reg_prefix
== '\0')
4635 fc
->col_type
[reg
] = DW_CFA_offset
;
4636 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
4641 if (op
>= DW_CFA_lo_user
&& op
<= DW_CFA_hi_user
)
4642 printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op
);
4644 warn (_("unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op
);
4649 if (do_debug_frames_interp
)
4650 frame_display_row (fc
, &need_col_headers
, &max_regs
);
4665 display_debug_not_supported (struct dwarf_section
*section
,
4666 void *file ATTRIBUTE_UNUSED
)
4668 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
4675 cmalloc (size_t nmemb
, size_t size
)
4677 /* Check for overflow. */
4678 if (nmemb
>= ~(size_t) 0 / size
)
4681 return malloc (nmemb
* size
);
4685 xcmalloc (size_t nmemb
, size_t size
)
4687 /* Check for overflow. */
4688 if (nmemb
>= ~(size_t) 0 / size
)
4691 return xmalloc (nmemb
* size
);
4695 xcrealloc (void *ptr
, size_t nmemb
, size_t size
)
4697 /* Check for overflow. */
4698 if (nmemb
>= ~(size_t) 0 / size
)
4701 return xrealloc (ptr
, nmemb
* size
);
4705 error (const char *message
, ...)
4709 va_start (args
, message
);
4710 fprintf (stderr
, _("%s: Error: "), program_name
);
4711 vfprintf (stderr
, message
, args
);
4716 warn (const char *message
, ...)
4720 va_start (args
, message
);
4721 fprintf (stderr
, _("%s: Warning: "), program_name
);
4722 vfprintf (stderr
, message
, args
);
4727 free_debug_memory (void)
4729 enum dwarf_section_display_enum i
;
4733 for (i
= 0; i
< max
; i
++)
4734 free_debug_section (i
);
4736 if (debug_information
!= NULL
)
4738 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
)
4740 for (i
= 0; i
< num_debug_info_entries
; i
++)
4742 if (!debug_information
[i
].max_loc_offsets
)
4744 free (debug_information
[i
].loc_offsets
);
4745 free (debug_information
[i
].have_frame_base
);
4747 if (!debug_information
[i
].max_range_lists
)
4748 free (debug_information
[i
].range_lists
);
4752 free (debug_information
);
4753 debug_information
= NULL
;
4754 num_debug_info_entries
= 0;
4759 dwarf_select_sections_by_names (const char *names
)
4763 const char * option
;
4767 debug_dump_long_opts
;
4769 static const debug_dump_long_opts opts_table
[] =
4771 /* Please keep this table alpha- sorted. */
4772 { "Ranges", & do_debug_ranges
, 1 },
4773 { "abbrev", & do_debug_abbrevs
, 1 },
4774 { "aranges", & do_debug_aranges
, 1 },
4775 { "frames", & do_debug_frames
, 1 },
4776 { "frames-interp", & do_debug_frames_interp
, 1 },
4777 { "info", & do_debug_info
, 1 },
4778 { "line", & do_debug_lines
, FLAG_DEBUG_LINES_RAW
}, /* For backwards compatibility. */
4779 { "rawline", & do_debug_lines
, FLAG_DEBUG_LINES_RAW
},
4780 { "decodedline", & do_debug_lines
, FLAG_DEBUG_LINES_DECODED
},
4781 { "loc", & do_debug_loc
, 1 },
4782 { "macro", & do_debug_macinfo
, 1 },
4783 { "pubnames", & do_debug_pubnames
, 1 },
4784 /* This entry is for compatability
4785 with earlier versions of readelf. */
4786 { "ranges", & do_debug_aranges
, 1 },
4787 { "str", & do_debug_str
, 1 },
4796 const debug_dump_long_opts
* entry
;
4798 for (entry
= opts_table
; entry
->option
; entry
++)
4800 size_t len
= strlen (entry
->option
);
4802 if (strncmp (p
, entry
->option
, len
) == 0
4803 && (p
[len
] == ',' || p
[len
] == '\0'))
4805 * entry
->variable
|= entry
->val
;
4807 /* The --debug-dump=frames-interp option also
4808 enables the --debug-dump=frames option. */
4809 if (do_debug_frames_interp
)
4810 do_debug_frames
= 1;
4817 if (entry
->option
== NULL
)
4819 warn (_("Unrecognized debug option '%s'\n"), p
);
4820 p
= strchr (p
, ',');
4831 dwarf_select_sections_by_letters (const char *letters
)
4833 unsigned int index
= 0;
4835 while (letters
[index
])
4836 switch (letters
[index
++])
4843 do_debug_abbrevs
= 1;
4847 do_debug_lines
|= FLAG_DEBUG_LINES_RAW
;
4851 do_debug_lines
|= FLAG_DEBUG_LINES_DECODED
;
4855 do_debug_pubnames
= 1;
4859 do_debug_aranges
= 1;
4863 do_debug_ranges
= 1;
4867 do_debug_frames_interp
= 1;
4869 do_debug_frames
= 1;
4873 do_debug_macinfo
= 1;
4885 warn (_("Unrecognized debug option '%s'\n"), optarg
);
4891 dwarf_select_sections_all (void)
4894 do_debug_abbrevs
= 1;
4895 do_debug_lines
= FLAG_DEBUG_LINES_RAW
;
4896 do_debug_pubnames
= 1;
4897 do_debug_aranges
= 1;
4898 do_debug_ranges
= 1;
4899 do_debug_frames
= 1;
4900 do_debug_macinfo
= 1;
4905 struct dwarf_section_display debug_displays
[] =
4907 { { ".debug_abbrev", ".zdebug_abbrev", NULL
, NULL
, 0, 0 },
4908 display_debug_abbrev
, &do_debug_abbrevs
, 0 },
4909 { { ".debug_aranges", ".zdebug_aranges", NULL
, NULL
, 0, 0 },
4910 display_debug_aranges
, &do_debug_aranges
, 1 },
4911 { { ".debug_frame", ".zdebug_frame", NULL
, NULL
, 0, 0 },
4912 display_debug_frames
, &do_debug_frames
, 1 },
4913 { { ".debug_info", ".zdebug_info", NULL
, NULL
, 0, 0 },
4914 display_debug_info
, &do_debug_info
, 1 },
4915 { { ".debug_line", ".zdebug_line", NULL
, NULL
, 0, 0 },
4916 display_debug_lines
, &do_debug_lines
, 1 },
4917 { { ".debug_pubnames", ".zdebug_pubnames", NULL
, NULL
, 0, 0 },
4918 display_debug_pubnames
, &do_debug_pubnames
, 0 },
4919 { { ".eh_frame", "", NULL
, NULL
, 0, 0 },
4920 display_debug_frames
, &do_debug_frames
, 1 },
4921 { { ".debug_macinfo", ".zdebug_macinfo", NULL
, NULL
, 0, 0 },
4922 display_debug_macinfo
, &do_debug_macinfo
, 0 },
4923 { { ".debug_str", ".zdebug_str", NULL
, NULL
, 0, 0 },
4924 display_debug_str
, &do_debug_str
, 0 },
4925 { { ".debug_loc", ".zdebug_loc", NULL
, NULL
, 0, 0 },
4926 display_debug_loc
, &do_debug_loc
, 1 },
4927 { { ".debug_pubtypes", ".zdebug_pubtypes", NULL
, NULL
, 0, 0 },
4928 display_debug_pubnames
, &do_debug_pubnames
, 0 },
4929 { { ".debug_ranges", ".zdebug_ranges", NULL
, NULL
, 0, 0 },
4930 display_debug_ranges
, &do_debug_ranges
, 1 },
4931 { { ".debug_static_func", ".zdebug_static_func", NULL
, NULL
, 0, 0 },
4932 display_debug_not_supported
, NULL
, 0 },
4933 { { ".debug_static_vars", ".zdebug_static_vars", NULL
, NULL
, 0, 0 },
4934 display_debug_not_supported
, NULL
, 0 },
4935 { { ".debug_types", ".zdebug_types", NULL
, NULL
, 0, 0 },
4936 display_debug_not_supported
, NULL
, 0 },
4937 { { ".debug_weaknames", ".zdebug_weaknames", NULL
, NULL
, 0, 0 },
4938 display_debug_not_supported
, NULL
, 0 }