1 /* dwarf.c -- display DWARF contents of a BFD binary file
2 Copyright 2005, 2006, 2007, 2008, 2009, 2010, 2011
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"
25 #include "bfd_stdint.h"
28 #include "elf/common.h"
32 static const char *regname (unsigned int regno
, int row
);
34 static int have_frame_base
;
35 static int need_base_address
;
37 static unsigned int last_pointer_size
= 0;
38 static int warned_about_missing_comp_units
= FALSE
;
40 static unsigned int num_debug_info_entries
= 0;
41 static debug_info
*debug_information
= NULL
;
42 /* Special value for num_debug_info_entries to indicate
43 that the .debug_info section could not be loaded/parsed. */
44 #define DEBUG_INFO_UNAVAILABLE (unsigned int) -1
51 int do_debug_pubnames
;
52 int do_debug_pubtypes
;
56 int do_debug_frames_interp
;
66 int dwarf_cutoff_level
= -1;
67 unsigned long dwarf_start_die
;
69 /* Values for do_debug_lines. */
70 #define FLAG_DEBUG_LINES_RAW 1
71 #define FLAG_DEBUG_LINES_DECODED 2
74 size_of_encoded_value (int encoding
)
76 switch (encoding
& 0x7)
79 case 0: return eh_addr_size
;
87 get_encoded_value (unsigned char *data
,
89 struct dwarf_section
*section
)
91 int size
= size_of_encoded_value (encoding
);
94 if (encoding
& DW_EH_PE_signed
)
95 val
= byte_get_signed (data
, size
);
97 val
= byte_get (data
, size
);
99 if ((encoding
& 0x70) == DW_EH_PE_pcrel
)
100 val
+= section
->address
+ (data
- section
->start
);
104 /* Print a dwarf_vma value (typically an address, offset or length) in
105 hexadecimal format, followed by a space. The length of the value (and
106 hence the precision displayed) is determined by the byte_size parameter. */
109 print_dwarf_vma (dwarf_vma val
, unsigned byte_size
)
111 static char buff
[18];
114 /* Printf does not have a way of specifiying a maximum field width for an
115 integer value, so we print the full value into a buffer and then select
116 the precision we need. */
117 #if __STDC_VERSION__ >= 199901L || (defined(__GNUC__) && __GNUC__ >= 2)
119 snprintf (buff
, sizeof (buff
), "%16.16llx ", val
);
121 snprintf (buff
, sizeof (buff
), "%016I64x ", val
);
124 snprintf (buff
, sizeof (buff
), "%16.16lx ", val
);
129 if (byte_size
> 0 && byte_size
<= 8)
130 offset
= 16 - 2 * byte_size
;
132 error (_("Wrong size in print_dwarf_vma"));
135 fputs (buff
+ offset
, stdout
);
138 #if __STDC_VERSION__ >= 199901L || (defined(__GNUC__) && __GNUC__ >= 2)
140 #define DWARF_VMA_FMT "ll"
142 #define DWARF_VMA_FMT "I64"
145 #define DWARF_VMA_FMT "l"
149 dwarf_vmatoa (const char *fmtch
, dwarf_vma value
)
151 /* As dwarf_vmatoa is used more then once in a printf call
152 for output, we are cycling through an fixed array of pointers
153 for return address. */
154 static int buf_pos
= 0;
155 static struct dwarf_vmatoa_buf
162 sprintf (fmt
, "%%%s%s", DWARF_VMA_FMT
, fmtch
);
164 ret
= buf
[buf_pos
++].place
;
165 buf_pos
%= ARRAY_SIZE (buf
);
167 snprintf (ret
, sizeof (buf
[0].place
), fmt
, value
);
172 /* Format a 64-bit value, given as two 32-bit values, in hex.
173 For reentrancy, this uses a buffer provided by the caller. */
176 dwarf_vmatoa64 (dwarf_vma hvalue
, dwarf_vma lvalue
, char *buf
,
177 unsigned int buf_len
)
182 snprintf (buf
, buf_len
, "%" DWARF_VMA_FMT
"x", lvalue
);
185 len
= snprintf (buf
, buf_len
, "%" DWARF_VMA_FMT
"x", hvalue
);
186 snprintf (buf
+ len
, buf_len
- len
,
187 "%08" DWARF_VMA_FMT
"x", lvalue
);
194 read_leb128 (unsigned char *data
, unsigned int *length_return
, int sign
)
196 dwarf_vma result
= 0;
197 unsigned int num_read
= 0;
198 unsigned int shift
= 0;
206 result
|= ((dwarf_vma
) (byte
& 0x7f)) << shift
;
213 if (length_return
!= NULL
)
214 *length_return
= num_read
;
216 if (sign
&& (shift
< 8 * sizeof (result
)) && (byte
& 0x40))
217 result
|= -1L << shift
;
222 /* Create a signed version to avoid painful typecasts. */
223 static dwarf_signed_vma
224 read_sleb128 (unsigned char *data
, unsigned int *length_return
)
226 return (dwarf_signed_vma
) read_leb128 (data
, length_return
, 1);
229 typedef struct State_Machine_Registers
237 unsigned char op_index
;
238 unsigned char end_sequence
;
239 /* This variable hold the number of the last entry seen
240 in the File Table. */
241 unsigned int last_file_entry
;
244 static SMR state_machine_regs
;
247 reset_state_machine (int is_stmt
)
249 state_machine_regs
.address
= 0;
250 state_machine_regs
.op_index
= 0;
251 state_machine_regs
.file
= 1;
252 state_machine_regs
.line
= 1;
253 state_machine_regs
.column
= 0;
254 state_machine_regs
.is_stmt
= is_stmt
;
255 state_machine_regs
.basic_block
= 0;
256 state_machine_regs
.end_sequence
= 0;
257 state_machine_regs
.last_file_entry
= 0;
260 /* Handled an extend line op.
261 Returns the number of bytes read. */
264 process_extended_line_op (unsigned char *data
, int is_stmt
)
266 unsigned char op_code
;
267 unsigned int bytes_read
;
271 unsigned char *orig_data
= data
;
273 len
= read_leb128 (data
, & bytes_read
, 0);
278 warn (_("badly formed extended line op encountered!\n"));
285 printf (_(" Extended opcode %d: "), op_code
);
289 case DW_LNE_end_sequence
:
290 printf (_("End of Sequence\n\n"));
291 reset_state_machine (is_stmt
);
294 case DW_LNE_set_address
:
295 adr
= byte_get (data
, len
- bytes_read
- 1);
296 printf (_("set Address to 0x%s\n"), dwarf_vmatoa ("x", adr
));
297 state_machine_regs
.address
= adr
;
298 state_machine_regs
.op_index
= 0;
301 case DW_LNE_define_file
:
302 printf (_("define new File Table entry\n"));
303 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
305 printf (" %d\t", ++state_machine_regs
.last_file_entry
);
307 data
+= strlen ((char *) data
) + 1;
308 printf ("%s\t", dwarf_vmatoa ("u", read_leb128 (data
, & bytes_read
, 0)));
310 printf ("%s\t", dwarf_vmatoa ("u", read_leb128 (data
, & bytes_read
, 0)));
312 printf ("%s\t", dwarf_vmatoa ("u", read_leb128 (data
, & bytes_read
, 0)));
315 if ((unsigned int) (data
- orig_data
) != len
)
316 printf (_(" [Bad opcode length]"));
320 case DW_LNE_set_discriminator
:
321 printf (_("set Discriminator to %s\n"),
322 dwarf_vmatoa ("u", read_leb128 (data
, & bytes_read
, 0)));
326 case DW_LNE_HP_negate_is_UV_update
:
327 printf ("DW_LNE_HP_negate_is_UV_update\n");
329 case DW_LNE_HP_push_context
:
330 printf ("DW_LNE_HP_push_context\n");
332 case DW_LNE_HP_pop_context
:
333 printf ("DW_LNE_HP_pop_context\n");
335 case DW_LNE_HP_set_file_line_column
:
336 printf ("DW_LNE_HP_set_file_line_column\n");
338 case DW_LNE_HP_set_routine_name
:
339 printf ("DW_LNE_HP_set_routine_name\n");
341 case DW_LNE_HP_set_sequence
:
342 printf ("DW_LNE_HP_set_sequence\n");
344 case DW_LNE_HP_negate_post_semantics
:
345 printf ("DW_LNE_HP_negate_post_semantics\n");
347 case DW_LNE_HP_negate_function_exit
:
348 printf ("DW_LNE_HP_negate_function_exit\n");
350 case DW_LNE_HP_negate_front_end_logical
:
351 printf ("DW_LNE_HP_negate_front_end_logical\n");
353 case DW_LNE_HP_define_proc
:
354 printf ("DW_LNE_HP_define_proc\n");
356 case DW_LNE_HP_source_file_correlation
:
358 unsigned char *edata
= data
+ len
- bytes_read
- 1;
360 printf ("DW_LNE_HP_source_file_correlation\n");
366 opc
= read_leb128 (data
, & bytes_read
, 0);
371 case DW_LNE_HP_SFC_formfeed
:
372 printf (" DW_LNE_HP_SFC_formfeed\n");
374 case DW_LNE_HP_SFC_set_listing_line
:
375 printf (" DW_LNE_HP_SFC_set_listing_line (%s)\n",
377 read_leb128 (data
, & bytes_read
, 0)));
380 case DW_LNE_HP_SFC_associate
:
381 printf (" DW_LNE_HP_SFC_associate ");
384 read_leb128 (data
, & bytes_read
, 0)));
388 read_leb128 (data
, & bytes_read
, 0)));
392 read_leb128 (data
, & bytes_read
, 0)));
396 printf (_(" UNKNOWN DW_LNE_HP_SFC opcode (%u)\n"), opc
);
406 unsigned int rlen
= len
- bytes_read
- 1;
408 if (op_code
>= DW_LNE_lo_user
409 /* The test against DW_LNW_hi_user is redundant due to
410 the limited range of the unsigned char data type used
412 /*&& op_code <= DW_LNE_hi_user*/)
413 printf (_("user defined: "));
415 printf (_("UNKNOWN: "));
416 printf (_("length %d ["), rlen
);
418 printf (" %02x", *data
++);
428 fetch_indirect_string (dwarf_vma offset
)
430 struct dwarf_section
*section
= &debug_displays
[str
].section
;
432 if (section
->start
== NULL
)
433 return _("<no .debug_str section>");
435 /* DWARF sections under Mach-O have non-zero addresses. */
436 offset
-= section
->address
;
437 if (offset
> section
->size
)
439 warn (_("DW_FORM_strp offset too big: %s\n"),
440 dwarf_vmatoa ("x", offset
));
441 return _("<offset is too big>");
444 return (const char *) section
->start
+ offset
;
447 /* FIXME: There are better and more efficient ways to handle
448 these structures. For now though, I just want something that
449 is simple to implement. */
450 typedef struct abbrev_attr
452 unsigned long attribute
;
454 struct abbrev_attr
*next
;
458 typedef struct abbrev_entry
463 struct abbrev_attr
*first_attr
;
464 struct abbrev_attr
*last_attr
;
465 struct abbrev_entry
*next
;
469 static abbrev_entry
*first_abbrev
= NULL
;
470 static abbrev_entry
*last_abbrev
= NULL
;
477 for (abbrv
= first_abbrev
; abbrv
;)
479 abbrev_entry
*next_abbrev
= abbrv
->next
;
482 for (attr
= abbrv
->first_attr
; attr
;)
484 abbrev_attr
*next_attr
= attr
->next
;
494 last_abbrev
= first_abbrev
= NULL
;
498 add_abbrev (unsigned long number
, unsigned long tag
, int children
)
502 entry
= (abbrev_entry
*) malloc (sizeof (*entry
));
507 entry
->entry
= number
;
509 entry
->children
= children
;
510 entry
->first_attr
= NULL
;
511 entry
->last_attr
= NULL
;
514 if (first_abbrev
== NULL
)
515 first_abbrev
= entry
;
517 last_abbrev
->next
= entry
;
523 add_abbrev_attr (unsigned long attribute
, unsigned long form
)
527 attr
= (abbrev_attr
*) malloc (sizeof (*attr
));
532 attr
->attribute
= attribute
;
536 if (last_abbrev
->first_attr
== NULL
)
537 last_abbrev
->first_attr
= attr
;
539 last_abbrev
->last_attr
->next
= attr
;
541 last_abbrev
->last_attr
= attr
;
544 /* Processes the (partial) contents of a .debug_abbrev section.
545 Returns NULL if the end of the section was encountered.
546 Returns the address after the last byte read if the end of
547 an abbreviation set was found. */
549 static unsigned char *
550 process_abbrev_section (unsigned char *start
, unsigned char *end
)
552 if (first_abbrev
!= NULL
)
557 unsigned int bytes_read
;
560 unsigned long attribute
;
563 entry
= read_leb128 (start
, & bytes_read
, 0);
566 /* A single zero is supposed to end the section according
567 to the standard. If there's more, then signal that to
570 return start
== end
? NULL
: start
;
572 tag
= read_leb128 (start
, & bytes_read
, 0);
577 add_abbrev (entry
, tag
, children
);
583 attribute
= read_leb128 (start
, & bytes_read
, 0);
586 form
= read_leb128 (start
, & bytes_read
, 0);
590 add_abbrev_attr (attribute
, form
);
592 while (attribute
!= 0);
599 get_TAG_name (unsigned long tag
)
603 case DW_TAG_padding
: return "DW_TAG_padding";
604 case DW_TAG_array_type
: return "DW_TAG_array_type";
605 case DW_TAG_class_type
: return "DW_TAG_class_type";
606 case DW_TAG_entry_point
: return "DW_TAG_entry_point";
607 case DW_TAG_enumeration_type
: return "DW_TAG_enumeration_type";
608 case DW_TAG_formal_parameter
: return "DW_TAG_formal_parameter";
609 case DW_TAG_imported_declaration
: return "DW_TAG_imported_declaration";
610 case DW_TAG_label
: return "DW_TAG_label";
611 case DW_TAG_lexical_block
: return "DW_TAG_lexical_block";
612 case DW_TAG_member
: return "DW_TAG_member";
613 case DW_TAG_pointer_type
: return "DW_TAG_pointer_type";
614 case DW_TAG_reference_type
: return "DW_TAG_reference_type";
615 case DW_TAG_compile_unit
: return "DW_TAG_compile_unit";
616 case DW_TAG_string_type
: return "DW_TAG_string_type";
617 case DW_TAG_structure_type
: return "DW_TAG_structure_type";
618 case DW_TAG_subroutine_type
: return "DW_TAG_subroutine_type";
619 case DW_TAG_typedef
: return "DW_TAG_typedef";
620 case DW_TAG_union_type
: return "DW_TAG_union_type";
621 case DW_TAG_unspecified_parameters
: return "DW_TAG_unspecified_parameters";
622 case DW_TAG_variant
: return "DW_TAG_variant";
623 case DW_TAG_common_block
: return "DW_TAG_common_block";
624 case DW_TAG_common_inclusion
: return "DW_TAG_common_inclusion";
625 case DW_TAG_inheritance
: return "DW_TAG_inheritance";
626 case DW_TAG_inlined_subroutine
: return "DW_TAG_inlined_subroutine";
627 case DW_TAG_module
: return "DW_TAG_module";
628 case DW_TAG_ptr_to_member_type
: return "DW_TAG_ptr_to_member_type";
629 case DW_TAG_set_type
: return "DW_TAG_set_type";
630 case DW_TAG_subrange_type
: return "DW_TAG_subrange_type";
631 case DW_TAG_with_stmt
: return "DW_TAG_with_stmt";
632 case DW_TAG_access_declaration
: return "DW_TAG_access_declaration";
633 case DW_TAG_base_type
: return "DW_TAG_base_type";
634 case DW_TAG_catch_block
: return "DW_TAG_catch_block";
635 case DW_TAG_const_type
: return "DW_TAG_const_type";
636 case DW_TAG_constant
: return "DW_TAG_constant";
637 case DW_TAG_enumerator
: return "DW_TAG_enumerator";
638 case DW_TAG_file_type
: return "DW_TAG_file_type";
639 case DW_TAG_friend
: return "DW_TAG_friend";
640 case DW_TAG_namelist
: return "DW_TAG_namelist";
641 case DW_TAG_namelist_item
: return "DW_TAG_namelist_item";
642 case DW_TAG_packed_type
: return "DW_TAG_packed_type";
643 case DW_TAG_subprogram
: return "DW_TAG_subprogram";
644 case DW_TAG_template_type_param
: return "DW_TAG_template_type_param";
645 case DW_TAG_template_value_param
: return "DW_TAG_template_value_param";
646 case DW_TAG_thrown_type
: return "DW_TAG_thrown_type";
647 case DW_TAG_try_block
: return "DW_TAG_try_block";
648 case DW_TAG_variant_part
: return "DW_TAG_variant_part";
649 case DW_TAG_variable
: return "DW_TAG_variable";
650 case DW_TAG_volatile_type
: return "DW_TAG_volatile_type";
651 case DW_TAG_MIPS_loop
: return "DW_TAG_MIPS_loop";
652 case DW_TAG_format_label
: return "DW_TAG_format_label";
653 case DW_TAG_function_template
: return "DW_TAG_function_template";
654 case DW_TAG_class_template
: return "DW_TAG_class_template";
655 /* DWARF 2.1 values. */
656 case DW_TAG_dwarf_procedure
: return "DW_TAG_dwarf_procedure";
657 case DW_TAG_restrict_type
: return "DW_TAG_restrict_type";
658 case DW_TAG_interface_type
: return "DW_TAG_interface_type";
659 case DW_TAG_namespace
: return "DW_TAG_namespace";
660 case DW_TAG_imported_module
: return "DW_TAG_imported_module";
661 case DW_TAG_unspecified_type
: return "DW_TAG_unspecified_type";
662 case DW_TAG_partial_unit
: return "DW_TAG_partial_unit";
663 case DW_TAG_imported_unit
: return "DW_TAG_imported_unit";
664 case DW_TAG_condition
: return "DW_TAG_condition";
665 case DW_TAG_shared_type
: return "DW_TAG_shared_type";
666 /* DWARF 4 values. */
667 case DW_TAG_type_unit
: return "DW_TAG_type_unit";
668 case DW_TAG_rvalue_reference_type
: return "DW_TAG_rvalue_reference_type";
669 case DW_TAG_template_alias
: return "DW_TAG_template_alias";
671 case DW_TAG_upc_shared_type
: return "DW_TAG_upc_shared_type";
672 case DW_TAG_upc_strict_type
: return "DW_TAG_upc_strict_type";
673 case DW_TAG_upc_relaxed_type
: return "DW_TAG_upc_relaxed_type";
675 case DW_TAG_GNU_call_site
: return "DW_TAG_GNU_call_site";
676 case DW_TAG_GNU_call_site_parameter
:return "DW_TAG_GNU_call_site_parameter";
679 static char buffer
[100];
681 snprintf (buffer
, sizeof (buffer
), _("Unknown TAG value: %lx"), tag
);
688 get_FORM_name (unsigned long form
)
692 case DW_FORM_addr
: return "DW_FORM_addr";
693 case DW_FORM_block2
: return "DW_FORM_block2";
694 case DW_FORM_block4
: return "DW_FORM_block4";
695 case DW_FORM_data2
: return "DW_FORM_data2";
696 case DW_FORM_data4
: return "DW_FORM_data4";
697 case DW_FORM_data8
: return "DW_FORM_data8";
698 case DW_FORM_string
: return "DW_FORM_string";
699 case DW_FORM_block
: return "DW_FORM_block";
700 case DW_FORM_block1
: return "DW_FORM_block1";
701 case DW_FORM_data1
: return "DW_FORM_data1";
702 case DW_FORM_flag
: return "DW_FORM_flag";
703 case DW_FORM_sdata
: return "DW_FORM_sdata";
704 case DW_FORM_strp
: return "DW_FORM_strp";
705 case DW_FORM_udata
: return "DW_FORM_udata";
706 case DW_FORM_ref_addr
: return "DW_FORM_ref_addr";
707 case DW_FORM_ref1
: return "DW_FORM_ref1";
708 case DW_FORM_ref2
: return "DW_FORM_ref2";
709 case DW_FORM_ref4
: return "DW_FORM_ref4";
710 case DW_FORM_ref8
: return "DW_FORM_ref8";
711 case DW_FORM_ref_udata
: return "DW_FORM_ref_udata";
712 case DW_FORM_indirect
: return "DW_FORM_indirect";
713 /* DWARF 4 values. */
714 case DW_FORM_sec_offset
: return "DW_FORM_sec_offset";
715 case DW_FORM_exprloc
: return "DW_FORM_exprloc";
716 case DW_FORM_flag_present
: return "DW_FORM_flag_present";
717 case DW_FORM_ref_sig8
: return "DW_FORM_ref_sig8";
720 static char buffer
[100];
722 snprintf (buffer
, sizeof (buffer
), _("Unknown FORM value: %lx"), form
);
728 static unsigned char *
729 display_block (unsigned char *data
, dwarf_vma length
)
731 printf (_(" %s byte block: "), dwarf_vmatoa ("u", length
));
734 printf ("%lx ", (unsigned long) byte_get (data
++, 1));
740 decode_location_expression (unsigned char * data
,
741 unsigned int pointer_size
,
742 unsigned int offset_size
,
746 struct dwarf_section
* section
)
749 unsigned int bytes_read
;
751 unsigned char *end
= data
+ length
;
752 int need_frame_base
= 0;
761 printf ("DW_OP_addr: %s",
762 dwarf_vmatoa ("x", byte_get (data
, pointer_size
)));
763 data
+= pointer_size
;
766 printf ("DW_OP_deref");
769 printf ("DW_OP_const1u: %lu", (unsigned long) byte_get (data
++, 1));
772 printf ("DW_OP_const1s: %ld", (long) byte_get_signed (data
++, 1));
775 printf ("DW_OP_const2u: %lu", (unsigned long) byte_get (data
, 2));
779 printf ("DW_OP_const2s: %ld", (long) byte_get_signed (data
, 2));
783 printf ("DW_OP_const4u: %lu", (unsigned long) byte_get (data
, 4));
787 printf ("DW_OP_const4s: %ld", (long) byte_get_signed (data
, 4));
791 printf ("DW_OP_const8u: %lu %lu", (unsigned long) byte_get (data
, 4),
792 (unsigned long) byte_get (data
+ 4, 4));
796 printf ("DW_OP_const8s: %ld %ld", (long) byte_get (data
, 4),
797 (long) byte_get (data
+ 4, 4));
801 printf ("DW_OP_constu: %s",
802 dwarf_vmatoa ("u", read_leb128 (data
, &bytes_read
, 0)));
806 printf ("DW_OP_consts: %s",
807 dwarf_vmatoa ("d", read_sleb128 (data
, &bytes_read
)));
811 printf ("DW_OP_dup");
814 printf ("DW_OP_drop");
817 printf ("DW_OP_over");
820 printf ("DW_OP_pick: %ld", (unsigned long) byte_get (data
++, 1));
823 printf ("DW_OP_swap");
826 printf ("DW_OP_rot");
829 printf ("DW_OP_xderef");
832 printf ("DW_OP_abs");
835 printf ("DW_OP_and");
838 printf ("DW_OP_div");
841 printf ("DW_OP_minus");
844 printf ("DW_OP_mod");
847 printf ("DW_OP_mul");
850 printf ("DW_OP_neg");
853 printf ("DW_OP_not");
859 printf ("DW_OP_plus");
861 case DW_OP_plus_uconst
:
862 printf ("DW_OP_plus_uconst: %s",
863 dwarf_vmatoa ("u", read_leb128 (data
, &bytes_read
, 0)));
867 printf ("DW_OP_shl");
870 printf ("DW_OP_shr");
873 printf ("DW_OP_shra");
876 printf ("DW_OP_xor");
879 printf ("DW_OP_bra: %ld", (long) byte_get_signed (data
, 2));
901 printf ("DW_OP_skip: %ld", (long) byte_get_signed (data
, 2));
937 printf ("DW_OP_lit%d", op
- DW_OP_lit0
);
972 printf ("DW_OP_reg%d (%s)", op
- DW_OP_reg0
,
973 regname (op
- DW_OP_reg0
, 1));
1008 printf ("DW_OP_breg%d (%s): %s",
1010 regname (op
- DW_OP_breg0
, 1),
1011 dwarf_vmatoa ("d", (dwarf_signed_vma
)
1012 read_leb128 (data
, &bytes_read
, 1)));
1017 uvalue
= read_leb128 (data
, &bytes_read
, 0);
1019 printf ("DW_OP_regx: %s (%s)",
1020 dwarf_vmatoa ("u", uvalue
), regname (uvalue
, 1));
1023 need_frame_base
= 1;
1024 printf ("DW_OP_fbreg: %s",
1025 dwarf_vmatoa ("d", read_sleb128 (data
, &bytes_read
)));
1029 uvalue
= read_leb128 (data
, &bytes_read
, 0);
1031 printf ("DW_OP_bregx: %s (%s) %s",
1032 dwarf_vmatoa ("u", uvalue
), regname (uvalue
, 1),
1033 dwarf_vmatoa ("d", read_sleb128 (data
, &bytes_read
)));
1037 printf ("DW_OP_piece: %s",
1038 dwarf_vmatoa ("u", read_leb128 (data
, &bytes_read
, 0)));
1041 case DW_OP_deref_size
:
1042 printf ("DW_OP_deref_size: %ld", (long) byte_get (data
++, 1));
1044 case DW_OP_xderef_size
:
1045 printf ("DW_OP_xderef_size: %ld", (long) byte_get (data
++, 1));
1048 printf ("DW_OP_nop");
1051 /* DWARF 3 extensions. */
1052 case DW_OP_push_object_address
:
1053 printf ("DW_OP_push_object_address");
1056 /* XXX: Strictly speaking for 64-bit DWARF3 files
1057 this ought to be an 8-byte wide computation. */
1058 printf ("DW_OP_call2: <0x%s>",
1059 dwarf_vmatoa ("x", (dwarf_signed_vma
) byte_get (data
, 2)
1064 /* XXX: Strictly speaking for 64-bit DWARF3 files
1065 this ought to be an 8-byte wide computation. */
1066 printf ("DW_OP_call4: <0x%s>",
1067 dwarf_vmatoa ("x", (dwarf_signed_vma
) byte_get (data
, 4)
1071 case DW_OP_call_ref
:
1072 /* XXX: Strictly speaking for 64-bit DWARF3 files
1073 this ought to be an 8-byte wide computation. */
1074 if (dwarf_version
== -1)
1076 printf (_("(DW_OP_call_ref in frame info)"));
1077 /* No way to tell where the next op is, so just bail. */
1078 return need_frame_base
;
1080 if (dwarf_version
== 2)
1082 printf ("DW_OP_call_ref: <0x%s>",
1083 dwarf_vmatoa ("x", byte_get (data
, pointer_size
)));
1084 data
+= pointer_size
;
1088 printf ("DW_OP_call_ref: <0x%s>",
1089 dwarf_vmatoa ("x", byte_get (data
, offset_size
)));
1090 data
+= offset_size
;
1093 case DW_OP_form_tls_address
:
1094 printf ("DW_OP_form_tls_address");
1096 case DW_OP_call_frame_cfa
:
1097 printf ("DW_OP_call_frame_cfa");
1099 case DW_OP_bit_piece
:
1100 printf ("DW_OP_bit_piece: ");
1101 printf (_("size: %s "),
1102 dwarf_vmatoa ("u", read_leb128 (data
, &bytes_read
, 0)));
1104 printf (_("offset: %s "),
1105 dwarf_vmatoa ("u", read_leb128 (data
, &bytes_read
, 0)));
1109 /* DWARF 4 extensions. */
1110 case DW_OP_stack_value
:
1111 printf ("DW_OP_stack_value");
1114 case DW_OP_implicit_value
:
1115 printf ("DW_OP_implicit_value");
1116 uvalue
= read_leb128 (data
, &bytes_read
, 0);
1118 display_block (data
, uvalue
);
1122 /* GNU extensions. */
1123 case DW_OP_GNU_push_tls_address
:
1124 printf (_("DW_OP_GNU_push_tls_address or DW_OP_HP_unknown"));
1126 case DW_OP_GNU_uninit
:
1127 printf ("DW_OP_GNU_uninit");
1128 /* FIXME: Is there data associated with this OP ? */
1130 case DW_OP_GNU_encoded_addr
:
1136 addr
= get_encoded_value (data
, encoding
, section
);
1137 data
+= size_of_encoded_value (encoding
);
1139 printf ("DW_OP_GNU_encoded_addr: fmt:%02x addr:", encoding
);
1140 print_dwarf_vma (addr
, pointer_size
);
1143 case DW_OP_GNU_implicit_pointer
:
1144 /* XXX: Strictly speaking for 64-bit DWARF3 files
1145 this ought to be an 8-byte wide computation. */
1146 if (dwarf_version
== -1)
1148 printf (_("(DW_OP_GNU_implicit_pointer in frame info)"));
1149 /* No way to tell where the next op is, so just bail. */
1150 return need_frame_base
;
1152 if (dwarf_version
== 2)
1154 printf ("DW_OP_GNU_implicit_pointer: <0x%s> %s",
1155 dwarf_vmatoa ("x", byte_get (data
, pointer_size
)),
1156 dwarf_vmatoa ("d", read_sleb128 (data
+ pointer_size
,
1158 data
+= pointer_size
+ bytes_read
;
1162 printf ("DW_OP_GNU_implicit_pointer: <0x%s> %s",
1163 dwarf_vmatoa ("x", byte_get (data
, offset_size
)),
1164 dwarf_vmatoa ("d", read_sleb128 (data
+ offset_size
,
1166 data
+= offset_size
+ bytes_read
;
1169 case DW_OP_GNU_entry_value
:
1170 uvalue
= read_leb128 (data
, &bytes_read
, 0);
1172 printf ("DW_OP_GNU_entry_value: (");
1173 if (decode_location_expression (data
, pointer_size
, offset_size
,
1174 dwarf_version
, uvalue
,
1175 cu_offset
, section
))
1176 need_frame_base
= 1;
1180 case DW_OP_GNU_const_type
:
1181 uvalue
= read_leb128 (data
, &bytes_read
, 0);
1183 printf ("DW_OP_GNU_const_type: <0x%s> ",
1184 dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1185 uvalue
= byte_get (data
++, 1);
1186 display_block (data
, uvalue
);
1189 case DW_OP_GNU_regval_type
:
1190 uvalue
= read_leb128 (data
, &bytes_read
, 0);
1192 printf ("DW_OP_GNU_regval_type: %s (%s)",
1193 dwarf_vmatoa ("u", uvalue
), regname (uvalue
, 1));
1194 uvalue
= read_leb128 (data
, &bytes_read
, 0);
1196 printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1198 case DW_OP_GNU_deref_type
:
1199 printf ("DW_OP_GNU_deref_type: %ld", (long) byte_get (data
++, 1));
1200 uvalue
= read_leb128 (data
, &bytes_read
, 0);
1202 printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1204 case DW_OP_GNU_convert
:
1205 uvalue
= read_leb128 (data
, &bytes_read
, 0);
1207 printf ("DW_OP_GNU_convert <0x%s>",
1208 dwarf_vmatoa ("x", uvalue
? cu_offset
+ uvalue
: 0));
1210 case DW_OP_GNU_reinterpret
:
1211 uvalue
= read_leb128 (data
, &bytes_read
, 0);
1213 printf ("DW_OP_GNU_reinterpret <0x%s>",
1214 dwarf_vmatoa ("x", uvalue
? cu_offset
+ uvalue
: 0));
1216 case DW_OP_GNU_parameter_ref
:
1217 printf ("DW_OP_GNU_parameter_ref: <0x%s>",
1218 dwarf_vmatoa ("x", cu_offset
+ byte_get (data
, 4)));
1222 /* HP extensions. */
1223 case DW_OP_HP_is_value
:
1224 printf ("DW_OP_HP_is_value");
1225 /* FIXME: Is there data associated with this OP ? */
1227 case DW_OP_HP_fltconst4
:
1228 printf ("DW_OP_HP_fltconst4");
1229 /* FIXME: Is there data associated with this OP ? */
1231 case DW_OP_HP_fltconst8
:
1232 printf ("DW_OP_HP_fltconst8");
1233 /* FIXME: Is there data associated with this OP ? */
1235 case DW_OP_HP_mod_range
:
1236 printf ("DW_OP_HP_mod_range");
1237 /* FIXME: Is there data associated with this OP ? */
1239 case DW_OP_HP_unmod_range
:
1240 printf ("DW_OP_HP_unmod_range");
1241 /* FIXME: Is there data associated with this OP ? */
1244 printf ("DW_OP_HP_tls");
1245 /* FIXME: Is there data associated with this OP ? */
1248 /* PGI (STMicroelectronics) extensions. */
1249 case DW_OP_PGI_omp_thread_num
:
1250 /* Pushes the thread number for the current thread as it would be
1251 returned by the standard OpenMP library function:
1252 omp_get_thread_num(). The "current thread" is the thread for
1253 which the expression is being evaluated. */
1254 printf ("DW_OP_PGI_omp_thread_num");
1258 if (op
>= DW_OP_lo_user
1259 && op
<= DW_OP_hi_user
)
1260 printf (_("(User defined location op)"));
1262 printf (_("(Unknown location op)"));
1263 /* No way to tell where the next op is, so just bail. */
1264 return need_frame_base
;
1267 /* Separate the ops. */
1272 return need_frame_base
;
1275 static unsigned char *
1276 read_and_display_attr_value (unsigned long attribute
,
1278 unsigned char * data
,
1279 dwarf_vma cu_offset
,
1280 dwarf_vma pointer_size
,
1281 dwarf_vma offset_size
,
1283 debug_info
* debug_info_p
,
1285 struct dwarf_section
* section
)
1287 dwarf_vma uvalue
= 0;
1288 unsigned char *block_start
= NULL
;
1289 unsigned char * orig_data
= data
;
1290 unsigned int bytes_read
;
1297 case DW_FORM_ref_addr
:
1298 if (dwarf_version
== 2)
1300 uvalue
= byte_get (data
, pointer_size
);
1301 data
+= pointer_size
;
1303 else if (dwarf_version
== 3 || dwarf_version
== 4)
1305 uvalue
= byte_get (data
, offset_size
);
1306 data
+= offset_size
;
1309 error (_("Internal error: DWARF version is not 2, 3 or 4.\n"));
1314 uvalue
= byte_get (data
, pointer_size
);
1315 data
+= pointer_size
;
1319 case DW_FORM_sec_offset
:
1320 uvalue
= byte_get (data
, offset_size
);
1321 data
+= offset_size
;
1324 case DW_FORM_flag_present
:
1331 uvalue
= byte_get (data
++, 1);
1336 uvalue
= byte_get (data
, 2);
1342 uvalue
= byte_get (data
, 4);
1347 uvalue
= read_leb128 (data
, & bytes_read
, 1);
1351 case DW_FORM_ref_udata
:
1353 uvalue
= read_leb128 (data
, & bytes_read
, 0);
1357 case DW_FORM_indirect
:
1358 form
= read_leb128 (data
, & bytes_read
, 0);
1361 printf (" %s", get_FORM_name (form
));
1362 return read_and_display_attr_value (attribute
, form
, data
,
1363 cu_offset
, pointer_size
,
1364 offset_size
, dwarf_version
,
1365 debug_info_p
, do_loc
,
1371 case DW_FORM_ref_addr
:
1373 printf (" <0x%s>", dwarf_vmatoa ("x",uvalue
));
1379 case DW_FORM_ref_udata
:
1381 printf (" <0x%s>", dwarf_vmatoa ("x", uvalue
+ cu_offset
));
1386 case DW_FORM_sec_offset
:
1388 printf (" 0x%s", dwarf_vmatoa ("x", uvalue
));
1391 case DW_FORM_flag_present
:
1398 printf (" %s", dwarf_vmatoa ("d", uvalue
));
1405 dwarf_vma high_bits
;
1408 byte_get_64 (data
, &high_bits
, &uvalue
);
1410 dwarf_vmatoa64 (high_bits
, uvalue
, buf
, sizeof (buf
)));
1412 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
1413 && num_debug_info_entries
== 0)
1415 if (sizeof (uvalue
) == 8)
1416 uvalue
= byte_get (data
, 8);
1418 error (_("DW_FORM_data8 is unsupported when sizeof (dwarf_vma) != 8\n"));
1423 case DW_FORM_string
:
1425 printf (" %s", data
);
1426 data
+= strlen ((char *) data
) + 1;
1430 case DW_FORM_exprloc
:
1431 uvalue
= read_leb128 (data
, & bytes_read
, 0);
1432 block_start
= data
+ bytes_read
;
1434 data
= block_start
+ uvalue
;
1436 data
= display_block (block_start
, uvalue
);
1439 case DW_FORM_block1
:
1440 uvalue
= byte_get (data
, 1);
1441 block_start
= data
+ 1;
1443 data
= block_start
+ uvalue
;
1445 data
= display_block (block_start
, uvalue
);
1448 case DW_FORM_block2
:
1449 uvalue
= byte_get (data
, 2);
1450 block_start
= data
+ 2;
1452 data
= block_start
+ uvalue
;
1454 data
= display_block (block_start
, uvalue
);
1457 case DW_FORM_block4
:
1458 uvalue
= byte_get (data
, 4);
1459 block_start
= data
+ 4;
1461 data
= block_start
+ uvalue
;
1463 data
= display_block (block_start
, uvalue
);
1468 printf (_(" (indirect string, offset: 0x%s): %s"),
1469 dwarf_vmatoa ("x", uvalue
),
1470 fetch_indirect_string (uvalue
));
1473 case DW_FORM_indirect
:
1474 /* Handled above. */
1477 case DW_FORM_ref_sig8
:
1480 dwarf_vma high_bits
;
1483 byte_get_64 (data
, &high_bits
, &uvalue
);
1484 printf (" signature: 0x%s",
1485 dwarf_vmatoa64 (high_bits
, uvalue
, buf
, sizeof (buf
)));
1491 warn (_("Unrecognized form: %lu\n"), form
);
1495 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
1496 && num_debug_info_entries
== 0
1497 && debug_info_p
!= NULL
)
1501 case DW_AT_frame_base
:
1502 have_frame_base
= 1;
1503 case DW_AT_location
:
1504 case DW_AT_string_length
:
1505 case DW_AT_return_addr
:
1506 case DW_AT_data_member_location
:
1507 case DW_AT_vtable_elem_location
:
1509 case DW_AT_static_link
:
1510 case DW_AT_use_location
:
1511 case DW_AT_GNU_call_site_value
:
1512 case DW_AT_GNU_call_site_data_value
:
1513 case DW_AT_GNU_call_site_target
:
1514 case DW_AT_GNU_call_site_target_clobbered
:
1515 if ((dwarf_version
< 4
1516 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
1517 || form
== DW_FORM_sec_offset
)
1519 /* Process location list. */
1520 unsigned int lmax
= debug_info_p
->max_loc_offsets
;
1521 unsigned int num
= debug_info_p
->num_loc_offsets
;
1523 if (lmax
== 0 || num
>= lmax
)
1526 debug_info_p
->loc_offsets
= (dwarf_vma
*)
1527 xcrealloc (debug_info_p
->loc_offsets
,
1528 lmax
, sizeof (*debug_info_p
->loc_offsets
));
1529 debug_info_p
->have_frame_base
= (int *)
1530 xcrealloc (debug_info_p
->have_frame_base
,
1531 lmax
, sizeof (*debug_info_p
->have_frame_base
));
1532 debug_info_p
->max_loc_offsets
= lmax
;
1534 debug_info_p
->loc_offsets
[num
] = uvalue
;
1535 debug_info_p
->have_frame_base
[num
] = have_frame_base
;
1536 debug_info_p
->num_loc_offsets
++;
1541 if (need_base_address
)
1542 debug_info_p
->base_address
= uvalue
;
1546 if ((dwarf_version
< 4
1547 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
1548 || form
== DW_FORM_sec_offset
)
1550 /* Process range list. */
1551 unsigned int lmax
= debug_info_p
->max_range_lists
;
1552 unsigned int num
= debug_info_p
->num_range_lists
;
1554 if (lmax
== 0 || num
>= lmax
)
1557 debug_info_p
->range_lists
= (dwarf_vma
*)
1558 xcrealloc (debug_info_p
->range_lists
,
1559 lmax
, sizeof (*debug_info_p
->range_lists
));
1560 debug_info_p
->max_range_lists
= lmax
;
1562 debug_info_p
->range_lists
[num
] = uvalue
;
1563 debug_info_p
->num_range_lists
++;
1572 if (do_loc
|| attribute
== 0)
1575 /* For some attributes we can display further information. */
1583 case DW_INL_not_inlined
:
1584 printf (_("(not inlined)"));
1586 case DW_INL_inlined
:
1587 printf (_("(inlined)"));
1589 case DW_INL_declared_not_inlined
:
1590 printf (_("(declared as inline but ignored)"));
1592 case DW_INL_declared_inlined
:
1593 printf (_("(declared as inline and inlined)"));
1596 printf (_(" (Unknown inline attribute value: %s)"),
1597 dwarf_vmatoa ("x", uvalue
));
1602 case DW_AT_language
:
1605 /* Ordered by the numeric value of these constants. */
1606 case DW_LANG_C89
: printf ("(ANSI C)"); break;
1607 case DW_LANG_C
: printf ("(non-ANSI C)"); break;
1608 case DW_LANG_Ada83
: printf ("(Ada)"); break;
1609 case DW_LANG_C_plus_plus
: printf ("(C++)"); break;
1610 case DW_LANG_Cobol74
: printf ("(Cobol 74)"); break;
1611 case DW_LANG_Cobol85
: printf ("(Cobol 85)"); break;
1612 case DW_LANG_Fortran77
: printf ("(FORTRAN 77)"); break;
1613 case DW_LANG_Fortran90
: printf ("(Fortran 90)"); break;
1614 case DW_LANG_Pascal83
: printf ("(ANSI Pascal)"); break;
1615 case DW_LANG_Modula2
: printf ("(Modula 2)"); break;
1616 /* DWARF 2.1 values. */
1617 case DW_LANG_Java
: printf ("(Java)"); break;
1618 case DW_LANG_C99
: printf ("(ANSI C99)"); break;
1619 case DW_LANG_Ada95
: printf ("(ADA 95)"); break;
1620 case DW_LANG_Fortran95
: printf ("(Fortran 95)"); break;
1621 /* DWARF 3 values. */
1622 case DW_LANG_PLI
: printf ("(PLI)"); break;
1623 case DW_LANG_ObjC
: printf ("(Objective C)"); break;
1624 case DW_LANG_ObjC_plus_plus
: printf ("(Objective C++)"); break;
1625 case DW_LANG_UPC
: printf ("(Unified Parallel C)"); break;
1626 case DW_LANG_D
: printf ("(D)"); break;
1627 /* DWARF 4 values. */
1628 case DW_LANG_Python
: printf ("(Python)"); break;
1629 /* DWARF 5 values. */
1630 case DW_LANG_Go
: printf ("(Go)"); break;
1631 /* MIPS extension. */
1632 case DW_LANG_Mips_Assembler
: printf ("(MIPS assembler)"); break;
1633 /* UPC extension. */
1634 case DW_LANG_Upc
: printf ("(Unified Parallel C)"); break;
1636 if (uvalue
>= DW_LANG_lo_user
&& uvalue
<= DW_LANG_hi_user
)
1637 printf (_("(implementation defined: %s)"),
1638 dwarf_vmatoa ("x", uvalue
));
1640 printf (_("(Unknown: %s)"), dwarf_vmatoa ("x", uvalue
));
1645 case DW_AT_encoding
:
1648 case DW_ATE_void
: printf ("(void)"); break;
1649 case DW_ATE_address
: printf ("(machine address)"); break;
1650 case DW_ATE_boolean
: printf ("(boolean)"); break;
1651 case DW_ATE_complex_float
: printf ("(complex float)"); break;
1652 case DW_ATE_float
: printf ("(float)"); break;
1653 case DW_ATE_signed
: printf ("(signed)"); break;
1654 case DW_ATE_signed_char
: printf ("(signed char)"); break;
1655 case DW_ATE_unsigned
: printf ("(unsigned)"); break;
1656 case DW_ATE_unsigned_char
: printf ("(unsigned char)"); break;
1657 /* DWARF 2.1 values: */
1658 case DW_ATE_imaginary_float
: printf ("(imaginary float)"); break;
1659 case DW_ATE_decimal_float
: printf ("(decimal float)"); break;
1660 /* DWARF 3 values: */
1661 case DW_ATE_packed_decimal
: printf ("(packed_decimal)"); break;
1662 case DW_ATE_numeric_string
: printf ("(numeric_string)"); break;
1663 case DW_ATE_edited
: printf ("(edited)"); break;
1664 case DW_ATE_signed_fixed
: printf ("(signed_fixed)"); break;
1665 case DW_ATE_unsigned_fixed
: printf ("(unsigned_fixed)"); break;
1666 /* HP extensions: */
1667 case DW_ATE_HP_float80
: printf ("(HP_float80)"); break;
1668 case DW_ATE_HP_complex_float80
: printf ("(HP_complex_float80)"); break;
1669 case DW_ATE_HP_float128
: printf ("(HP_float128)"); break;
1670 case DW_ATE_HP_complex_float128
:printf ("(HP_complex_float128)"); break;
1671 case DW_ATE_HP_floathpintel
: printf ("(HP_floathpintel)"); break;
1672 case DW_ATE_HP_imaginary_float80
: printf ("(HP_imaginary_float80)"); break;
1673 case DW_ATE_HP_imaginary_float128
: printf ("(HP_imaginary_float128)"); break;
1676 if (uvalue
>= DW_ATE_lo_user
1677 && uvalue
<= DW_ATE_hi_user
)
1678 printf (_("(user defined type)"));
1680 printf (_("(unknown type)"));
1685 case DW_AT_accessibility
:
1688 case DW_ACCESS_public
: printf ("(public)"); break;
1689 case DW_ACCESS_protected
: printf ("(protected)"); break;
1690 case DW_ACCESS_private
: printf ("(private)"); break;
1692 printf (_("(unknown accessibility)"));
1697 case DW_AT_visibility
:
1700 case DW_VIS_local
: printf ("(local)"); break;
1701 case DW_VIS_exported
: printf ("(exported)"); break;
1702 case DW_VIS_qualified
: printf ("(qualified)"); break;
1703 default: printf (_("(unknown visibility)")); break;
1707 case DW_AT_virtuality
:
1710 case DW_VIRTUALITY_none
: printf ("(none)"); break;
1711 case DW_VIRTUALITY_virtual
: printf ("(virtual)"); break;
1712 case DW_VIRTUALITY_pure_virtual
:printf ("(pure_virtual)"); break;
1713 default: printf (_("(unknown virtuality)")); break;
1717 case DW_AT_identifier_case
:
1720 case DW_ID_case_sensitive
: printf ("(case_sensitive)"); break;
1721 case DW_ID_up_case
: printf ("(up_case)"); break;
1722 case DW_ID_down_case
: printf ("(down_case)"); break;
1723 case DW_ID_case_insensitive
: printf ("(case_insensitive)"); break;
1724 default: printf (_("(unknown case)")); break;
1728 case DW_AT_calling_convention
:
1731 case DW_CC_normal
: printf ("(normal)"); break;
1732 case DW_CC_program
: printf ("(program)"); break;
1733 case DW_CC_nocall
: printf ("(nocall)"); break;
1735 if (uvalue
>= DW_CC_lo_user
1736 && uvalue
<= DW_CC_hi_user
)
1737 printf (_("(user defined)"));
1739 printf (_("(unknown convention)"));
1743 case DW_AT_ordering
:
1746 case -1: printf (_("(undefined)")); break;
1747 case 0: printf ("(row major)"); break;
1748 case 1: printf ("(column major)"); break;
1752 case DW_AT_frame_base
:
1753 have_frame_base
= 1;
1754 case DW_AT_location
:
1755 case DW_AT_string_length
:
1756 case DW_AT_return_addr
:
1757 case DW_AT_data_member_location
:
1758 case DW_AT_vtable_elem_location
:
1760 case DW_AT_static_link
:
1761 case DW_AT_use_location
:
1762 case DW_AT_GNU_call_site_value
:
1763 case DW_AT_GNU_call_site_data_value
:
1764 case DW_AT_GNU_call_site_target
:
1765 case DW_AT_GNU_call_site_target_clobbered
:
1766 if ((dwarf_version
< 4
1767 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
1768 || form
== DW_FORM_sec_offset
)
1769 printf (_("(location list)"));
1771 case DW_AT_allocated
:
1772 case DW_AT_associated
:
1773 case DW_AT_data_location
:
1775 case DW_AT_upper_bound
:
1776 case DW_AT_lower_bound
:
1779 int need_frame_base
;
1782 need_frame_base
= decode_location_expression (block_start
,
1787 cu_offset
, section
);
1789 if (need_frame_base
&& !have_frame_base
)
1790 printf (_(" [without DW_AT_frame_base]"));
1796 if (form
== DW_FORM_ref_sig8
)
1799 if (form
== DW_FORM_ref1
1800 || form
== DW_FORM_ref2
1801 || form
== DW_FORM_ref4
1802 || form
== DW_FORM_ref_udata
)
1803 uvalue
+= cu_offset
;
1805 if (uvalue
>= section
->size
)
1806 warn (_("Offset %s used as value for DW_AT_import attribute of DIE at offset %lx is too big.\n"),
1807 dwarf_vmatoa ("x", uvalue
),
1808 (unsigned long) (orig_data
- section
->start
));
1811 unsigned long abbrev_number
;
1812 abbrev_entry
* entry
;
1814 abbrev_number
= read_leb128 (section
->start
+ uvalue
, NULL
, 0);
1816 printf (_("[Abbrev Number: %ld"), abbrev_number
);
1817 for (entry
= first_abbrev
; entry
!= NULL
; entry
= entry
->next
)
1818 if (entry
->entry
== abbrev_number
)
1821 printf (" (%s)", get_TAG_name (entry
->tag
));
1835 get_AT_name (unsigned long attribute
)
1839 case DW_AT_sibling
: return "DW_AT_sibling";
1840 case DW_AT_location
: return "DW_AT_location";
1841 case DW_AT_name
: return "DW_AT_name";
1842 case DW_AT_ordering
: return "DW_AT_ordering";
1843 case DW_AT_subscr_data
: return "DW_AT_subscr_data";
1844 case DW_AT_byte_size
: return "DW_AT_byte_size";
1845 case DW_AT_bit_offset
: return "DW_AT_bit_offset";
1846 case DW_AT_bit_size
: return "DW_AT_bit_size";
1847 case DW_AT_element_list
: return "DW_AT_element_list";
1848 case DW_AT_stmt_list
: return "DW_AT_stmt_list";
1849 case DW_AT_low_pc
: return "DW_AT_low_pc";
1850 case DW_AT_high_pc
: return "DW_AT_high_pc";
1851 case DW_AT_language
: return "DW_AT_language";
1852 case DW_AT_member
: return "DW_AT_member";
1853 case DW_AT_discr
: return "DW_AT_discr";
1854 case DW_AT_discr_value
: return "DW_AT_discr_value";
1855 case DW_AT_visibility
: return "DW_AT_visibility";
1856 case DW_AT_import
: return "DW_AT_import";
1857 case DW_AT_string_length
: return "DW_AT_string_length";
1858 case DW_AT_common_reference
: return "DW_AT_common_reference";
1859 case DW_AT_comp_dir
: return "DW_AT_comp_dir";
1860 case DW_AT_const_value
: return "DW_AT_const_value";
1861 case DW_AT_containing_type
: return "DW_AT_containing_type";
1862 case DW_AT_default_value
: return "DW_AT_default_value";
1863 case DW_AT_inline
: return "DW_AT_inline";
1864 case DW_AT_is_optional
: return "DW_AT_is_optional";
1865 case DW_AT_lower_bound
: return "DW_AT_lower_bound";
1866 case DW_AT_producer
: return "DW_AT_producer";
1867 case DW_AT_prototyped
: return "DW_AT_prototyped";
1868 case DW_AT_return_addr
: return "DW_AT_return_addr";
1869 case DW_AT_start_scope
: return "DW_AT_start_scope";
1870 case DW_AT_stride_size
: return "DW_AT_stride_size";
1871 case DW_AT_upper_bound
: return "DW_AT_upper_bound";
1872 case DW_AT_abstract_origin
: return "DW_AT_abstract_origin";
1873 case DW_AT_accessibility
: return "DW_AT_accessibility";
1874 case DW_AT_address_class
: return "DW_AT_address_class";
1875 case DW_AT_artificial
: return "DW_AT_artificial";
1876 case DW_AT_base_types
: return "DW_AT_base_types";
1877 case DW_AT_calling_convention
: return "DW_AT_calling_convention";
1878 case DW_AT_count
: return "DW_AT_count";
1879 case DW_AT_data_member_location
: return "DW_AT_data_member_location";
1880 case DW_AT_decl_column
: return "DW_AT_decl_column";
1881 case DW_AT_decl_file
: return "DW_AT_decl_file";
1882 case DW_AT_decl_line
: return "DW_AT_decl_line";
1883 case DW_AT_declaration
: return "DW_AT_declaration";
1884 case DW_AT_discr_list
: return "DW_AT_discr_list";
1885 case DW_AT_encoding
: return "DW_AT_encoding";
1886 case DW_AT_external
: return "DW_AT_external";
1887 case DW_AT_frame_base
: return "DW_AT_frame_base";
1888 case DW_AT_friend
: return "DW_AT_friend";
1889 case DW_AT_identifier_case
: return "DW_AT_identifier_case";
1890 case DW_AT_macro_info
: return "DW_AT_macro_info";
1891 case DW_AT_namelist_items
: return "DW_AT_namelist_items";
1892 case DW_AT_priority
: return "DW_AT_priority";
1893 case DW_AT_segment
: return "DW_AT_segment";
1894 case DW_AT_specification
: return "DW_AT_specification";
1895 case DW_AT_static_link
: return "DW_AT_static_link";
1896 case DW_AT_type
: return "DW_AT_type";
1897 case DW_AT_use_location
: return "DW_AT_use_location";
1898 case DW_AT_variable_parameter
: return "DW_AT_variable_parameter";
1899 case DW_AT_virtuality
: return "DW_AT_virtuality";
1900 case DW_AT_vtable_elem_location
: return "DW_AT_vtable_elem_location";
1901 /* DWARF 2.1 values. */
1902 case DW_AT_allocated
: return "DW_AT_allocated";
1903 case DW_AT_associated
: return "DW_AT_associated";
1904 case DW_AT_data_location
: return "DW_AT_data_location";
1905 case DW_AT_stride
: return "DW_AT_stride";
1906 case DW_AT_entry_pc
: return "DW_AT_entry_pc";
1907 case DW_AT_use_UTF8
: return "DW_AT_use_UTF8";
1908 case DW_AT_extension
: return "DW_AT_extension";
1909 case DW_AT_ranges
: return "DW_AT_ranges";
1910 case DW_AT_trampoline
: return "DW_AT_trampoline";
1911 case DW_AT_call_column
: return "DW_AT_call_column";
1912 case DW_AT_call_file
: return "DW_AT_call_file";
1913 case DW_AT_call_line
: return "DW_AT_call_line";
1914 case DW_AT_description
: return "DW_AT_description";
1915 case DW_AT_binary_scale
: return "DW_AT_binary_scale";
1916 case DW_AT_decimal_scale
: return "DW_AT_decimal_scale";
1917 case DW_AT_small
: return "DW_AT_small";
1918 case DW_AT_decimal_sign
: return "DW_AT_decimal_sign";
1919 case DW_AT_digit_count
: return "DW_AT_digit_count";
1920 case DW_AT_picture_string
: return "DW_AT_picture_string";
1921 case DW_AT_mutable
: return "DW_AT_mutable";
1922 case DW_AT_threads_scaled
: return "DW_AT_threads_scaled";
1923 case DW_AT_explicit
: return "DW_AT_explicit";
1924 case DW_AT_object_pointer
: return "DW_AT_object_pointer";
1925 case DW_AT_endianity
: return "DW_AT_endianity";
1926 case DW_AT_elemental
: return "DW_AT_elemental";
1927 case DW_AT_pure
: return "DW_AT_pure";
1928 case DW_AT_recursive
: return "DW_AT_recursive";
1929 /* DWARF 4 values. */
1930 case DW_AT_signature
: return "DW_AT_signature";
1931 case DW_AT_main_subprogram
: return "DW_AT_main_subprogram";
1932 case DW_AT_data_bit_offset
: return "DW_AT_data_bit_offset";
1933 case DW_AT_const_expr
: return "DW_AT_const_expr";
1934 case DW_AT_enum_class
: return "DW_AT_enum_class";
1935 case DW_AT_linkage_name
: return "DW_AT_linkage_name";
1937 /* HP and SGI/MIPS extensions. */
1938 case DW_AT_MIPS_loop_begin
: return "DW_AT_MIPS_loop_begin";
1939 case DW_AT_MIPS_tail_loop_begin
: return "DW_AT_MIPS_tail_loop_begin";
1940 case DW_AT_MIPS_epilog_begin
: return "DW_AT_MIPS_epilog_begin";
1941 case DW_AT_MIPS_loop_unroll_factor
: return "DW_AT_MIPS_loop_unroll_factor";
1942 case DW_AT_MIPS_software_pipeline_depth
: return "DW_AT_MIPS_software_pipeline_depth";
1943 case DW_AT_MIPS_linkage_name
: return "DW_AT_MIPS_linkage_name";
1944 case DW_AT_MIPS_stride
: return "DW_AT_MIPS_stride";
1945 case DW_AT_MIPS_abstract_name
: return "DW_AT_MIPS_abstract_name";
1946 case DW_AT_MIPS_clone_origin
: return "DW_AT_MIPS_clone_origin";
1947 case DW_AT_MIPS_has_inlines
: return "DW_AT_MIPS_has_inlines";
1949 /* HP Extensions. */
1950 case DW_AT_HP_block_index
: return "DW_AT_HP_block_index";
1951 case DW_AT_HP_actuals_stmt_list
: return "DW_AT_HP_actuals_stmt_list";
1952 case DW_AT_HP_proc_per_section
: return "DW_AT_HP_proc_per_section";
1953 case DW_AT_HP_raw_data_ptr
: return "DW_AT_HP_raw_data_ptr";
1954 case DW_AT_HP_pass_by_reference
: return "DW_AT_HP_pass_by_reference";
1955 case DW_AT_HP_opt_level
: return "DW_AT_HP_opt_level";
1956 case DW_AT_HP_prof_version_id
: return "DW_AT_HP_prof_version_id";
1957 case DW_AT_HP_opt_flags
: return "DW_AT_HP_opt_flags";
1958 case DW_AT_HP_cold_region_low_pc
: return "DW_AT_HP_cold_region_low_pc";
1959 case DW_AT_HP_cold_region_high_pc
: return "DW_AT_HP_cold_region_high_pc";
1960 case DW_AT_HP_all_variables_modifiable
: return "DW_AT_HP_all_variables_modifiable";
1961 case DW_AT_HP_linkage_name
: return "DW_AT_HP_linkage_name";
1962 case DW_AT_HP_prof_flags
: return "DW_AT_HP_prof_flags";
1964 /* One value is shared by the MIPS and HP extensions: */
1965 case DW_AT_MIPS_fde
: return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable";
1967 /* GNU extensions. */
1968 case DW_AT_sf_names
: return "DW_AT_sf_names";
1969 case DW_AT_src_info
: return "DW_AT_src_info";
1970 case DW_AT_mac_info
: return "DW_AT_mac_info";
1971 case DW_AT_src_coords
: return "DW_AT_src_coords";
1972 case DW_AT_body_begin
: return "DW_AT_body_begin";
1973 case DW_AT_body_end
: return "DW_AT_body_end";
1974 case DW_AT_GNU_vector
: return "DW_AT_GNU_vector";
1975 case DW_AT_GNU_guarded_by
: return "DW_AT_GNU_guarded_by";
1976 case DW_AT_GNU_pt_guarded_by
: return "DW_AT_GNU_pt_guarded_by";
1977 case DW_AT_GNU_guarded
: return "DW_AT_GNU_guarded";
1978 case DW_AT_GNU_pt_guarded
: return "DW_AT_GNU_pt_guarded";
1979 case DW_AT_GNU_locks_excluded
: return "DW_AT_GNU_locks_excluded";
1980 case DW_AT_GNU_exclusive_locks_required
: return "DW_AT_GNU_exclusive_locks_required";
1981 case DW_AT_GNU_shared_locks_required
: return "DW_AT_GNU_shared_locks_required";
1982 case DW_AT_GNU_odr_signature
: return "DW_AT_GNU_odr_signature";
1983 case DW_AT_use_GNAT_descriptive_type
: return "DW_AT_use_GNAT_descriptive_type";
1984 case DW_AT_GNAT_descriptive_type
: return "DW_AT_GNAT_descriptive_type";
1985 case DW_AT_GNU_call_site_value
: return "DW_AT_GNU_call_site_value";
1986 case DW_AT_GNU_call_site_data_value
: return "DW_AT_GNU_call_site_data_value";
1987 case DW_AT_GNU_call_site_target
: return "DW_AT_GNU_call_site_target";
1988 case DW_AT_GNU_call_site_target_clobbered
: return "DW_AT_GNU_call_site_target_clobbered";
1989 case DW_AT_GNU_tail_call
: return "DW_AT_GNU_tail_call";
1990 case DW_AT_GNU_all_tail_call_sites
: return "DW_AT_GNU_all_tail_call_sites";
1991 case DW_AT_GNU_all_call_sites
: return "DW_AT_GNU_all_call_sites";
1992 case DW_AT_GNU_all_source_call_sites
: return "DW_AT_GNU_all_source_call_sites";
1993 case DW_AT_GNU_macros
: return "DW_AT_GNU_macros";
1995 /* UPC extension. */
1996 case DW_AT_upc_threads_scaled
: return "DW_AT_upc_threads_scaled";
1998 /* PGI (STMicroelectronics) extensions. */
1999 case DW_AT_PGI_lbase
: return "DW_AT_PGI_lbase";
2000 case DW_AT_PGI_soffset
: return "DW_AT_PGI_soffset";
2001 case DW_AT_PGI_lstride
: return "DW_AT_PGI_lstride";
2005 static char buffer
[100];
2007 snprintf (buffer
, sizeof (buffer
), _("Unknown AT value: %lx"),
2014 static unsigned char *
2015 read_and_display_attr (unsigned long attribute
,
2017 unsigned char * data
,
2018 dwarf_vma cu_offset
,
2019 dwarf_vma pointer_size
,
2020 dwarf_vma offset_size
,
2022 debug_info
* debug_info_p
,
2024 struct dwarf_section
* section
)
2027 printf (" %-18s:", get_AT_name (attribute
));
2028 data
= read_and_display_attr_value (attribute
, form
, data
, cu_offset
,
2029 pointer_size
, offset_size
,
2030 dwarf_version
, debug_info_p
,
2038 /* Process the contents of a .debug_info section. If do_loc is non-zero
2039 then we are scanning for location lists and we do not want to display
2040 anything to the user. If do_types is non-zero, we are processing
2041 a .debug_types section instead of a .debug_info section. */
2044 process_debug_info (struct dwarf_section
*section
,
2046 enum dwarf_section_display_enum abbrev_sec
,
2050 unsigned char *start
= section
->start
;
2051 unsigned char *end
= start
+ section
->size
;
2052 unsigned char *section_begin
;
2054 unsigned int num_units
= 0;
2056 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
2057 && num_debug_info_entries
== 0
2062 /* First scan the section to get the number of comp units. */
2063 for (section_begin
= start
, num_units
= 0; section_begin
< end
;
2066 /* Read the first 4 bytes. For a 32-bit DWARF section, this
2067 will be the length. For a 64-bit DWARF section, it'll be
2068 the escape code 0xffffffff followed by an 8 byte length. */
2069 length
= byte_get (section_begin
, 4);
2071 if (length
== 0xffffffff)
2073 length
= byte_get (section_begin
+ 4, 8);
2074 section_begin
+= length
+ 12;
2076 else if (length
>= 0xfffffff0 && length
< 0xffffffff)
2078 warn (_("Reserved length value (0x%s) found in section %s\n"),
2079 dwarf_vmatoa ("x", length
), section
->name
);
2083 section_begin
+= length
+ 4;
2085 /* Negative values are illegal, they may even cause infinite
2086 looping. This can happen if we can't accurately apply
2087 relocations to an object file. */
2088 if ((signed long) length
<= 0)
2090 warn (_("Corrupt unit length (0x%s) found in section %s\n"),
2091 dwarf_vmatoa ("x", length
), section
->name
);
2098 error (_("No comp units in %s section ?"), section
->name
);
2102 /* Then allocate an array to hold the information. */
2103 debug_information
= (debug_info
*) cmalloc (num_units
,
2104 sizeof (* debug_information
));
2105 if (debug_information
== NULL
)
2107 error (_("Not enough memory for a debug info array of %u entries"),
2115 if (dwarf_start_die
== 0)
2116 printf (_("Contents of the %s section:\n\n"), section
->name
);
2118 load_debug_section (str
, file
);
2121 load_debug_section (abbrev_sec
, file
);
2122 if (debug_displays
[abbrev_sec
].section
.start
== NULL
)
2124 warn (_("Unable to locate %s section!\n"),
2125 debug_displays
[abbrev_sec
].section
.name
);
2129 for (section_begin
= start
, unit
= 0; start
< end
; unit
++)
2131 DWARF2_Internal_CompUnit compunit
;
2132 unsigned char *hdrptr
;
2133 unsigned char *tags
;
2134 int level
, last_level
, saved_level
;
2135 dwarf_vma cu_offset
;
2137 int initial_length_size
;
2138 dwarf_vma signature_high
= 0;
2139 dwarf_vma signature_low
= 0;
2140 dwarf_vma type_offset
= 0;
2144 compunit
.cu_length
= byte_get (hdrptr
, 4);
2147 if (compunit
.cu_length
== 0xffffffff)
2149 compunit
.cu_length
= byte_get (hdrptr
, 8);
2152 initial_length_size
= 12;
2157 initial_length_size
= 4;
2160 compunit
.cu_version
= byte_get (hdrptr
, 2);
2163 cu_offset
= start
- section_begin
;
2165 compunit
.cu_abbrev_offset
= byte_get (hdrptr
, offset_size
);
2166 hdrptr
+= offset_size
;
2168 compunit
.cu_pointer_size
= byte_get (hdrptr
, 1);
2173 byte_get_64 (hdrptr
, &signature_high
, &signature_low
);
2175 type_offset
= byte_get (hdrptr
, offset_size
);
2176 hdrptr
+= offset_size
;
2179 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
2180 && num_debug_info_entries
== 0
2183 debug_information
[unit
].cu_offset
= cu_offset
;
2184 debug_information
[unit
].pointer_size
2185 = compunit
.cu_pointer_size
;
2186 debug_information
[unit
].offset_size
= offset_size
;
2187 debug_information
[unit
].dwarf_version
= compunit
.cu_version
;
2188 debug_information
[unit
].base_address
= 0;
2189 debug_information
[unit
].loc_offsets
= NULL
;
2190 debug_information
[unit
].have_frame_base
= NULL
;
2191 debug_information
[unit
].max_loc_offsets
= 0;
2192 debug_information
[unit
].num_loc_offsets
= 0;
2193 debug_information
[unit
].range_lists
= NULL
;
2194 debug_information
[unit
].max_range_lists
= 0;
2195 debug_information
[unit
].num_range_lists
= 0;
2198 if (!do_loc
&& dwarf_start_die
== 0)
2200 printf (_(" Compilation Unit @ offset 0x%s:\n"),
2201 dwarf_vmatoa ("x", cu_offset
));
2202 printf (_(" Length: 0x%s (%s)\n"),
2203 dwarf_vmatoa ("x", compunit
.cu_length
),
2204 offset_size
== 8 ? "64-bit" : "32-bit");
2205 printf (_(" Version: %d\n"), compunit
.cu_version
);
2206 printf (_(" Abbrev Offset: %s\n"),
2207 dwarf_vmatoa ("d", compunit
.cu_abbrev_offset
));
2208 printf (_(" Pointer Size: %d\n"), compunit
.cu_pointer_size
);
2213 printf (_(" Signature: 0x%s\n"),
2214 dwarf_vmatoa64 (signature_high
, signature_low
,
2215 buf
, sizeof (buf
)));
2216 printf (_(" Type Offset: 0x%s\n"),
2217 dwarf_vmatoa ("x", type_offset
));
2221 if (cu_offset
+ compunit
.cu_length
+ initial_length_size
2224 warn (_("Debug info is corrupted, length of CU at %s"
2225 " extends beyond end of section (length = %s)\n"),
2226 dwarf_vmatoa ("x", cu_offset
),
2227 dwarf_vmatoa ("x", compunit
.cu_length
));
2231 start
+= compunit
.cu_length
+ initial_length_size
;
2233 if (compunit
.cu_version
!= 2
2234 && compunit
.cu_version
!= 3
2235 && compunit
.cu_version
!= 4)
2237 warn (_("CU at offset %s contains corrupt or "
2238 "unsupported version number: %d.\n"),
2239 dwarf_vmatoa ("x", cu_offset
), compunit
.cu_version
);
2245 /* Process the abbrevs used by this compilation unit. DWARF
2246 sections under Mach-O have non-zero addresses. */
2247 if (compunit
.cu_abbrev_offset
>= debug_displays
[abbrev_sec
].section
.size
)
2248 warn (_("Debug info is corrupted, abbrev offset (%lx) is larger than abbrev section size (%lx)\n"),
2249 (unsigned long) compunit
.cu_abbrev_offset
,
2250 (unsigned long) debug_displays
[abbrev_sec
].section
.size
);
2252 process_abbrev_section
2253 ((unsigned char *) debug_displays
[abbrev_sec
].section
.start
2254 + compunit
.cu_abbrev_offset
,
2255 (unsigned char *) debug_displays
[abbrev_sec
].section
.start
2256 + debug_displays
[abbrev_sec
].section
.size
);
2261 while (tags
< start
)
2263 unsigned int bytes_read
;
2264 unsigned long abbrev_number
;
2265 unsigned long die_offset
;
2266 abbrev_entry
*entry
;
2268 int do_printing
= 1;
2270 die_offset
= tags
- section_begin
;
2272 abbrev_number
= read_leb128 (tags
, & bytes_read
, 0);
2275 /* A null DIE marks the end of a list of siblings or it may also be
2276 a section padding. */
2277 if (abbrev_number
== 0)
2279 /* Check if it can be a section padding for the last CU. */
2280 if (level
== 0 && start
== end
)
2284 for (chk
= tags
; chk
< start
; chk
++)
2294 static unsigned num_bogus_warns
= 0;
2296 if (num_bogus_warns
< 3)
2298 warn (_("Bogus end-of-siblings marker detected at offset %lx in .debug_info section\n"),
2301 if (num_bogus_warns
== 3)
2302 warn (_("Further warnings about bogus end-of-sibling markers suppressed\n"));
2305 if (dwarf_start_die
!= 0 && level
< saved_level
)
2312 if (dwarf_start_die
!= 0 && die_offset
< dwarf_start_die
)
2316 if (dwarf_start_die
!= 0 && die_offset
== dwarf_start_die
)
2317 saved_level
= level
;
2318 do_printing
= (dwarf_cutoff_level
== -1
2319 || level
< dwarf_cutoff_level
);
2321 printf (_(" <%d><%lx>: Abbrev Number: %lu"),
2322 level
, die_offset
, abbrev_number
);
2323 else if (dwarf_cutoff_level
== -1
2324 || last_level
< dwarf_cutoff_level
)
2325 printf (_(" <%d><%lx>: ...\n"), level
, die_offset
);
2330 /* Scan through the abbreviation list until we reach the
2332 for (entry
= first_abbrev
;
2333 entry
&& entry
->entry
!= abbrev_number
;
2334 entry
= entry
->next
)
2339 if (!do_loc
&& do_printing
)
2344 warn (_("DIE at offset %lx refers to abbreviation number %lu which does not exist\n"),
2345 die_offset
, abbrev_number
);
2349 if (!do_loc
&& do_printing
)
2350 printf (" (%s)\n", get_TAG_name (entry
->tag
));
2355 need_base_address
= 0;
2357 case DW_TAG_compile_unit
:
2358 need_base_address
= 1;
2360 case DW_TAG_entry_point
:
2361 case DW_TAG_subprogram
:
2362 need_base_address
= 0;
2363 /* Assuming that there is no DW_AT_frame_base. */
2364 have_frame_base
= 0;
2368 for (attr
= entry
->first_attr
; attr
; attr
= attr
->next
)
2372 if (! do_loc
&& do_printing
)
2373 /* Show the offset from where the tag was extracted. */
2374 printf (" <%lx>", (unsigned long)(tags
- section_begin
));
2376 arg
= debug_information
;
2377 if (debug_information
)
2380 tags
= read_and_display_attr (attr
->attribute
,
2383 compunit
.cu_pointer_size
,
2385 compunit
.cu_version
,
2387 do_loc
|| ! do_printing
, section
);
2390 if (entry
->children
)
2395 /* Set num_debug_info_entries here so that it can be used to check if
2396 we need to process .debug_loc and .debug_ranges sections. */
2397 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
2398 && num_debug_info_entries
== 0
2400 num_debug_info_entries
= num_units
;
2408 /* Locate and scan the .debug_info section in the file and record the pointer
2409 sizes and offsets for the compilation units in it. Usually an executable
2410 will have just one pointer size, but this is not guaranteed, and so we try
2411 not to make any assumptions. Returns zero upon failure, or the number of
2412 compilation units upon success. */
2415 load_debug_info (void * file
)
2417 /* Reset the last pointer size so that we can issue correct error
2418 messages if we are displaying the contents of more than one section. */
2419 last_pointer_size
= 0;
2420 warned_about_missing_comp_units
= FALSE
;
2422 /* If we have already tried and failed to load the .debug_info
2423 section then do not bother to repear the task. */
2424 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
2427 /* If we already have the information there is nothing else to do. */
2428 if (num_debug_info_entries
> 0)
2429 return num_debug_info_entries
;
2431 if (load_debug_section (info
, file
)
2432 && process_debug_info (&debug_displays
[info
].section
, file
, abbrev
, 1, 0))
2433 return num_debug_info_entries
;
2435 num_debug_info_entries
= DEBUG_INFO_UNAVAILABLE
;
2440 display_debug_lines_raw (struct dwarf_section
*section
,
2441 unsigned char *data
,
2444 unsigned char *start
= section
->start
;
2446 printf (_("Raw dump of debug contents of section %s:\n\n"),
2451 DWARF2_Internal_LineInfo linfo
;
2452 unsigned char *standard_opcodes
;
2453 unsigned char *end_of_sequence
;
2454 unsigned char *hdrptr
;
2455 unsigned long hdroff
;
2456 int initial_length_size
;
2461 hdroff
= hdrptr
- start
;
2463 /* Check the length of the block. */
2464 linfo
.li_length
= byte_get (hdrptr
, 4);
2467 if (linfo
.li_length
== 0xffffffff)
2469 /* This section is 64-bit DWARF 3. */
2470 linfo
.li_length
= byte_get (hdrptr
, 8);
2473 initial_length_size
= 12;
2478 initial_length_size
= 4;
2481 if (linfo
.li_length
+ initial_length_size
> section
->size
)
2484 (_("The information in section %s appears to be corrupt - the section is too small\n"),
2489 /* Check its version number. */
2490 linfo
.li_version
= byte_get (hdrptr
, 2);
2492 if (linfo
.li_version
!= 2
2493 && linfo
.li_version
!= 3
2494 && linfo
.li_version
!= 4)
2496 warn (_("Only DWARF version 2, 3 and 4 line info is currently supported.\n"));
2500 linfo
.li_prologue_length
= byte_get (hdrptr
, offset_size
);
2501 hdrptr
+= offset_size
;
2502 linfo
.li_min_insn_length
= byte_get (hdrptr
, 1);
2504 if (linfo
.li_version
>= 4)
2506 linfo
.li_max_ops_per_insn
= byte_get (hdrptr
, 1);
2508 if (linfo
.li_max_ops_per_insn
== 0)
2510 warn (_("Invalid maximum operations per insn.\n"));
2515 linfo
.li_max_ops_per_insn
= 1;
2516 linfo
.li_default_is_stmt
= byte_get (hdrptr
, 1);
2518 linfo
.li_line_base
= byte_get (hdrptr
, 1);
2520 linfo
.li_line_range
= byte_get (hdrptr
, 1);
2522 linfo
.li_opcode_base
= byte_get (hdrptr
, 1);
2525 /* Sign extend the line base field. */
2526 linfo
.li_line_base
<<= 24;
2527 linfo
.li_line_base
>>= 24;
2529 printf (_(" Offset: 0x%lx\n"), hdroff
);
2530 printf (_(" Length: %ld\n"), (long) linfo
.li_length
);
2531 printf (_(" DWARF Version: %d\n"), linfo
.li_version
);
2532 printf (_(" Prologue Length: %d\n"), linfo
.li_prologue_length
);
2533 printf (_(" Minimum Instruction Length: %d\n"), linfo
.li_min_insn_length
);
2534 if (linfo
.li_version
>= 4)
2535 printf (_(" Maximum Ops per Instruction: %d\n"), linfo
.li_max_ops_per_insn
);
2536 printf (_(" Initial value of 'is_stmt': %d\n"), linfo
.li_default_is_stmt
);
2537 printf (_(" Line Base: %d\n"), linfo
.li_line_base
);
2538 printf (_(" Line Range: %d\n"), linfo
.li_line_range
);
2539 printf (_(" Opcode Base: %d\n"), linfo
.li_opcode_base
);
2541 end_of_sequence
= data
+ linfo
.li_length
+ initial_length_size
;
2543 reset_state_machine (linfo
.li_default_is_stmt
);
2545 /* Display the contents of the Opcodes table. */
2546 standard_opcodes
= hdrptr
;
2548 printf (_("\n Opcodes:\n"));
2550 for (i
= 1; i
< linfo
.li_opcode_base
; i
++)
2551 printf (_(" Opcode %d has %d args\n"), i
, standard_opcodes
[i
- 1]);
2553 /* Display the contents of the Directory table. */
2554 data
= standard_opcodes
+ linfo
.li_opcode_base
- 1;
2557 printf (_("\n The Directory Table is empty.\n"));
2560 printf (_("\n The Directory Table:\n"));
2564 printf (" %s\n", data
);
2566 data
+= strlen ((char *) data
) + 1;
2570 /* Skip the NUL at the end of the table. */
2573 /* Display the contents of the File Name table. */
2575 printf (_("\n The File Name Table is empty.\n"));
2578 printf (_("\n The File Name Table:\n"));
2579 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
2583 unsigned char *name
;
2584 unsigned int bytes_read
;
2586 printf (" %d\t", ++state_machine_regs
.last_file_entry
);
2589 data
+= strlen ((char *) data
) + 1;
2592 dwarf_vmatoa ("u", read_leb128 (data
, & bytes_read
, 0)));
2595 dwarf_vmatoa ("u", read_leb128 (data
, & bytes_read
, 0)));
2598 dwarf_vmatoa ("u", read_leb128 (data
, & bytes_read
, 0)));
2600 printf ("%s\n", name
);
2604 /* Skip the NUL at the end of the table. */
2607 /* Now display the statements. */
2608 printf (_("\n Line Number Statements:\n"));
2610 while (data
< end_of_sequence
)
2612 unsigned char op_code
;
2613 dwarf_signed_vma adv
;
2615 unsigned int bytes_read
;
2619 if (op_code
>= linfo
.li_opcode_base
)
2621 op_code
-= linfo
.li_opcode_base
;
2622 uladv
= (op_code
/ linfo
.li_line_range
);
2623 if (linfo
.li_max_ops_per_insn
== 1)
2625 uladv
*= linfo
.li_min_insn_length
;
2626 state_machine_regs
.address
+= uladv
;
2627 printf (_(" Special opcode %d: "
2628 "advance Address by %s to 0x%s"),
2629 op_code
, dwarf_vmatoa ("u", uladv
),
2630 dwarf_vmatoa ("x", state_machine_regs
.address
));
2634 state_machine_regs
.address
2635 += ((state_machine_regs
.op_index
+ uladv
)
2636 / linfo
.li_max_ops_per_insn
)
2637 * linfo
.li_min_insn_length
;
2638 state_machine_regs
.op_index
2639 = (state_machine_regs
.op_index
+ uladv
)
2640 % linfo
.li_max_ops_per_insn
;
2641 printf (_(" Special opcode %d: "
2642 "advance Address by %s to 0x%s[%d]"),
2643 op_code
, dwarf_vmatoa ("u", uladv
),
2644 dwarf_vmatoa ("x", state_machine_regs
.address
),
2645 state_machine_regs
.op_index
);
2647 adv
= (op_code
% linfo
.li_line_range
) + linfo
.li_line_base
;
2648 state_machine_regs
.line
+= adv
;
2649 printf (_(" and Line by %s to %d\n"),
2650 dwarf_vmatoa ("d", adv
), state_machine_regs
.line
);
2652 else switch (op_code
)
2654 case DW_LNS_extended_op
:
2655 data
+= process_extended_line_op (data
, linfo
.li_default_is_stmt
);
2659 printf (_(" Copy\n"));
2662 case DW_LNS_advance_pc
:
2663 uladv
= read_leb128 (data
, & bytes_read
, 0);
2665 if (linfo
.li_max_ops_per_insn
== 1)
2667 uladv
*= linfo
.li_min_insn_length
;
2668 state_machine_regs
.address
+= uladv
;
2669 printf (_(" Advance PC by %s to 0x%s\n"),
2670 dwarf_vmatoa ("u", uladv
),
2671 dwarf_vmatoa ("x", state_machine_regs
.address
));
2675 state_machine_regs
.address
2676 += ((state_machine_regs
.op_index
+ uladv
)
2677 / linfo
.li_max_ops_per_insn
)
2678 * linfo
.li_min_insn_length
;
2679 state_machine_regs
.op_index
2680 = (state_machine_regs
.op_index
+ uladv
)
2681 % linfo
.li_max_ops_per_insn
;
2682 printf (_(" Advance PC by %s to 0x%s[%d]\n"),
2683 dwarf_vmatoa ("u", uladv
),
2684 dwarf_vmatoa ("x", state_machine_regs
.address
),
2685 state_machine_regs
.op_index
);
2689 case DW_LNS_advance_line
:
2690 adv
= read_sleb128 (data
, & bytes_read
);
2692 state_machine_regs
.line
+= adv
;
2693 printf (_(" Advance Line by %s to %d\n"),
2694 dwarf_vmatoa ("d", adv
),
2695 state_machine_regs
.line
);
2698 case DW_LNS_set_file
:
2699 adv
= read_leb128 (data
, & bytes_read
, 0);
2701 printf (_(" Set File Name to entry %s in the File Name Table\n"),
2702 dwarf_vmatoa ("d", adv
));
2703 state_machine_regs
.file
= adv
;
2706 case DW_LNS_set_column
:
2707 uladv
= read_leb128 (data
, & bytes_read
, 0);
2709 printf (_(" Set column to %s\n"),
2710 dwarf_vmatoa ("u", uladv
));
2711 state_machine_regs
.column
= uladv
;
2714 case DW_LNS_negate_stmt
:
2715 adv
= state_machine_regs
.is_stmt
;
2717 printf (_(" Set is_stmt to %s\n"), dwarf_vmatoa ("d", adv
));
2718 state_machine_regs
.is_stmt
= adv
;
2721 case DW_LNS_set_basic_block
:
2722 printf (_(" Set basic block\n"));
2723 state_machine_regs
.basic_block
= 1;
2726 case DW_LNS_const_add_pc
:
2727 uladv
= ((255 - linfo
.li_opcode_base
) / linfo
.li_line_range
);
2728 if (linfo
.li_max_ops_per_insn
)
2730 uladv
*= linfo
.li_min_insn_length
;
2731 state_machine_regs
.address
+= uladv
;
2732 printf (_(" Advance PC by constant %s to 0x%s\n"),
2733 dwarf_vmatoa ("u", uladv
),
2734 dwarf_vmatoa ("x", state_machine_regs
.address
));
2738 state_machine_regs
.address
2739 += ((state_machine_regs
.op_index
+ uladv
)
2740 / linfo
.li_max_ops_per_insn
)
2741 * linfo
.li_min_insn_length
;
2742 state_machine_regs
.op_index
2743 = (state_machine_regs
.op_index
+ uladv
)
2744 % linfo
.li_max_ops_per_insn
;
2745 printf (_(" Advance PC by constant %s to 0x%s[%d]\n"),
2746 dwarf_vmatoa ("u", uladv
),
2747 dwarf_vmatoa ("x", state_machine_regs
.address
),
2748 state_machine_regs
.op_index
);
2752 case DW_LNS_fixed_advance_pc
:
2753 uladv
= byte_get (data
, 2);
2755 state_machine_regs
.address
+= uladv
;
2756 state_machine_regs
.op_index
= 0;
2757 printf (_(" Advance PC by fixed size amount %s to 0x%s\n"),
2758 dwarf_vmatoa ("u", uladv
),
2759 dwarf_vmatoa ("x", state_machine_regs
.address
));
2762 case DW_LNS_set_prologue_end
:
2763 printf (_(" Set prologue_end to true\n"));
2766 case DW_LNS_set_epilogue_begin
:
2767 printf (_(" Set epilogue_begin to true\n"));
2770 case DW_LNS_set_isa
:
2771 uladv
= read_leb128 (data
, & bytes_read
, 0);
2773 printf (_(" Set ISA to %s\n"), dwarf_vmatoa ("u", uladv
));
2777 printf (_(" Unknown opcode %d with operands: "), op_code
);
2779 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
2781 printf ("0x%s%s", dwarf_vmatoa ("x", read_leb128 (data
,
2783 i
== 1 ? "" : ", ");
2798 unsigned char *name
;
2799 unsigned int directory_index
;
2800 unsigned int modification_date
;
2801 unsigned int length
;
2804 /* Output a decoded representation of the .debug_line section. */
2807 display_debug_lines_decoded (struct dwarf_section
*section
,
2808 unsigned char *data
,
2811 printf (_("Decoded dump of debug contents of section %s:\n\n"),
2816 /* This loop amounts to one iteration per compilation unit. */
2817 DWARF2_Internal_LineInfo linfo
;
2818 unsigned char *standard_opcodes
;
2819 unsigned char *end_of_sequence
;
2820 unsigned char *hdrptr
;
2821 int initial_length_size
;
2824 File_Entry
*file_table
= NULL
;
2825 unsigned int n_files
= 0;
2826 unsigned char **directory_table
= NULL
;
2827 unsigned int n_directories
= 0;
2831 /* Extract information from the Line Number Program Header.
2832 (section 6.2.4 in the Dwarf3 doc). */
2834 /* Get the length of this CU's line number information block. */
2835 linfo
.li_length
= byte_get (hdrptr
, 4);
2838 if (linfo
.li_length
== 0xffffffff)
2840 /* This section is 64-bit DWARF 3. */
2841 linfo
.li_length
= byte_get (hdrptr
, 8);
2844 initial_length_size
= 12;
2849 initial_length_size
= 4;
2852 if (linfo
.li_length
+ initial_length_size
> section
->size
)
2854 warn (_("The line info appears to be corrupt - "
2855 "the section is too small\n"));
2859 /* Get this CU's Line Number Block version number. */
2860 linfo
.li_version
= byte_get (hdrptr
, 2);
2862 if (linfo
.li_version
!= 2
2863 && linfo
.li_version
!= 3
2864 && linfo
.li_version
!= 4)
2866 warn (_("Only DWARF version 2, 3 and 4 line info is currently "
2871 linfo
.li_prologue_length
= byte_get (hdrptr
, offset_size
);
2872 hdrptr
+= offset_size
;
2873 linfo
.li_min_insn_length
= byte_get (hdrptr
, 1);
2875 if (linfo
.li_version
>= 4)
2877 linfo
.li_max_ops_per_insn
= byte_get (hdrptr
, 1);
2879 if (linfo
.li_max_ops_per_insn
== 0)
2881 warn (_("Invalid maximum operations per insn.\n"));
2886 linfo
.li_max_ops_per_insn
= 1;
2887 linfo
.li_default_is_stmt
= byte_get (hdrptr
, 1);
2889 linfo
.li_line_base
= byte_get (hdrptr
, 1);
2891 linfo
.li_line_range
= byte_get (hdrptr
, 1);
2893 linfo
.li_opcode_base
= byte_get (hdrptr
, 1);
2896 /* Sign extend the line base field. */
2897 linfo
.li_line_base
<<= 24;
2898 linfo
.li_line_base
>>= 24;
2900 /* Find the end of this CU's Line Number Information Block. */
2901 end_of_sequence
= data
+ linfo
.li_length
+ initial_length_size
;
2903 reset_state_machine (linfo
.li_default_is_stmt
);
2905 /* Save a pointer to the contents of the Opcodes table. */
2906 standard_opcodes
= hdrptr
;
2908 /* Traverse the Directory table just to count entries. */
2909 data
= standard_opcodes
+ linfo
.li_opcode_base
- 1;
2912 unsigned char *ptr_directory_table
= data
;
2916 data
+= strlen ((char *) data
) + 1;
2920 /* Go through the directory table again to save the directories. */
2921 directory_table
= (unsigned char **)
2922 xmalloc (n_directories
* sizeof (unsigned char *));
2925 while (*ptr_directory_table
!= 0)
2927 directory_table
[i
] = ptr_directory_table
;
2928 ptr_directory_table
+= strlen ((char *) ptr_directory_table
) + 1;
2932 /* Skip the NUL at the end of the table. */
2935 /* Traverse the File Name table just to count the entries. */
2938 unsigned char *ptr_file_name_table
= data
;
2942 unsigned int bytes_read
;
2944 /* Skip Name, directory index, last modification time and length
2946 data
+= strlen ((char *) data
) + 1;
2947 read_leb128 (data
, & bytes_read
, 0);
2949 read_leb128 (data
, & bytes_read
, 0);
2951 read_leb128 (data
, & bytes_read
, 0);
2957 /* Go through the file table again to save the strings. */
2958 file_table
= (File_Entry
*) xmalloc (n_files
* sizeof (File_Entry
));
2961 while (*ptr_file_name_table
!= 0)
2963 unsigned int bytes_read
;
2965 file_table
[i
].name
= ptr_file_name_table
;
2966 ptr_file_name_table
+= strlen ((char *) ptr_file_name_table
) + 1;
2968 /* We are not interested in directory, time or size. */
2969 file_table
[i
].directory_index
= read_leb128 (ptr_file_name_table
,
2971 ptr_file_name_table
+= bytes_read
;
2972 file_table
[i
].modification_date
= read_leb128 (ptr_file_name_table
,
2974 ptr_file_name_table
+= bytes_read
;
2975 file_table
[i
].length
= read_leb128 (ptr_file_name_table
, & bytes_read
, 0);
2976 ptr_file_name_table
+= bytes_read
;
2981 /* Print the Compilation Unit's name and a header. */
2982 if (directory_table
== NULL
)
2984 printf (_("CU: %s:\n"), file_table
[0].name
);
2985 printf (_("File name Line number Starting address\n"));
2989 unsigned int ix
= file_table
[0].directory_index
;
2990 const char *directory
= ix
? (char *)directory_table
[ix
- 1] : ".";
2991 if (do_wide
|| strlen (directory
) < 76)
2992 printf (_("CU: %s/%s:\n"), directory
, file_table
[0].name
);
2994 printf ("%s:\n", file_table
[0].name
);
2996 printf (_("File name Line number Starting address\n"));
3000 /* Skip the NUL at the end of the table. */
3003 /* This loop iterates through the Dwarf Line Number Program. */
3004 while (data
< end_of_sequence
)
3006 unsigned char op_code
;
3008 unsigned long int uladv
;
3009 unsigned int bytes_read
;
3010 int is_special_opcode
= 0;
3014 if (op_code
>= linfo
.li_opcode_base
)
3016 op_code
-= linfo
.li_opcode_base
;
3017 uladv
= (op_code
/ linfo
.li_line_range
);
3018 if (linfo
.li_max_ops_per_insn
== 1)
3020 uladv
*= linfo
.li_min_insn_length
;
3021 state_machine_regs
.address
+= uladv
;
3025 state_machine_regs
.address
3026 += ((state_machine_regs
.op_index
+ uladv
)
3027 / linfo
.li_max_ops_per_insn
)
3028 * linfo
.li_min_insn_length
;
3029 state_machine_regs
.op_index
3030 = (state_machine_regs
.op_index
+ uladv
)
3031 % linfo
.li_max_ops_per_insn
;
3034 adv
= (op_code
% linfo
.li_line_range
) + linfo
.li_line_base
;
3035 state_machine_regs
.line
+= adv
;
3036 is_special_opcode
= 1;
3038 else switch (op_code
)
3040 case DW_LNS_extended_op
:
3042 unsigned int ext_op_code_len
;
3043 unsigned char ext_op_code
;
3044 unsigned char *op_code_data
= data
;
3046 ext_op_code_len
= read_leb128 (op_code_data
, &bytes_read
, 0);
3047 op_code_data
+= bytes_read
;
3049 if (ext_op_code_len
== 0)
3051 warn (_("badly formed extended line op encountered!\n"));
3054 ext_op_code_len
+= bytes_read
;
3055 ext_op_code
= *op_code_data
++;
3057 switch (ext_op_code
)
3059 case DW_LNE_end_sequence
:
3060 reset_state_machine (linfo
.li_default_is_stmt
);
3062 case DW_LNE_set_address
:
3063 state_machine_regs
.address
=
3064 byte_get (op_code_data
, ext_op_code_len
- bytes_read
- 1);
3065 state_machine_regs
.op_index
= 0;
3067 case DW_LNE_define_file
:
3069 file_table
= (File_Entry
*) xrealloc
3070 (file_table
, (n_files
+ 1) * sizeof (File_Entry
));
3072 ++state_machine_regs
.last_file_entry
;
3073 /* Source file name. */
3074 file_table
[n_files
].name
= op_code_data
;
3075 op_code_data
+= strlen ((char *) op_code_data
) + 1;
3076 /* Directory index. */
3077 file_table
[n_files
].directory_index
=
3078 read_leb128 (op_code_data
, & bytes_read
, 0);
3079 op_code_data
+= bytes_read
;
3080 /* Last modification time. */
3081 file_table
[n_files
].modification_date
=
3082 read_leb128 (op_code_data
, & bytes_read
, 0);
3083 op_code_data
+= bytes_read
;
3085 file_table
[n_files
].length
=
3086 read_leb128 (op_code_data
, & bytes_read
, 0);
3091 case DW_LNE_set_discriminator
:
3092 case DW_LNE_HP_set_sequence
:
3093 /* Simply ignored. */
3097 printf (_("UNKNOWN (%u): length %d\n"),
3098 ext_op_code
, ext_op_code_len
- bytes_read
);
3101 data
+= ext_op_code_len
;
3107 case DW_LNS_advance_pc
:
3108 uladv
= read_leb128 (data
, & bytes_read
, 0);
3110 if (linfo
.li_max_ops_per_insn
== 1)
3112 uladv
*= linfo
.li_min_insn_length
;
3113 state_machine_regs
.address
+= uladv
;
3117 state_machine_regs
.address
3118 += ((state_machine_regs
.op_index
+ uladv
)
3119 / linfo
.li_max_ops_per_insn
)
3120 * linfo
.li_min_insn_length
;
3121 state_machine_regs
.op_index
3122 = (state_machine_regs
.op_index
+ uladv
)
3123 % linfo
.li_max_ops_per_insn
;
3127 case DW_LNS_advance_line
:
3128 adv
= read_sleb128 (data
, & bytes_read
);
3130 state_machine_regs
.line
+= adv
;
3133 case DW_LNS_set_file
:
3134 adv
= read_leb128 (data
, & bytes_read
, 0);
3136 state_machine_regs
.file
= adv
;
3137 if (file_table
[state_machine_regs
.file
- 1].directory_index
== 0)
3139 /* If directory index is 0, that means current directory. */
3140 printf ("\n./%s:[++]\n",
3141 file_table
[state_machine_regs
.file
- 1].name
);
3145 /* The directory index starts counting at 1. */
3146 printf ("\n%s/%s:\n",
3147 directory_table
[file_table
[state_machine_regs
.file
- 1].directory_index
- 1],
3148 file_table
[state_machine_regs
.file
- 1].name
);
3152 case DW_LNS_set_column
:
3153 uladv
= read_leb128 (data
, & bytes_read
, 0);
3155 state_machine_regs
.column
= uladv
;
3158 case DW_LNS_negate_stmt
:
3159 adv
= state_machine_regs
.is_stmt
;
3161 state_machine_regs
.is_stmt
= adv
;
3164 case DW_LNS_set_basic_block
:
3165 state_machine_regs
.basic_block
= 1;
3168 case DW_LNS_const_add_pc
:
3169 uladv
= ((255 - linfo
.li_opcode_base
) / linfo
.li_line_range
);
3170 if (linfo
.li_max_ops_per_insn
== 1)
3172 uladv
*= linfo
.li_min_insn_length
;
3173 state_machine_regs
.address
+= uladv
;
3177 state_machine_regs
.address
3178 += ((state_machine_regs
.op_index
+ uladv
)
3179 / linfo
.li_max_ops_per_insn
)
3180 * linfo
.li_min_insn_length
;
3181 state_machine_regs
.op_index
3182 = (state_machine_regs
.op_index
+ uladv
)
3183 % linfo
.li_max_ops_per_insn
;
3187 case DW_LNS_fixed_advance_pc
:
3188 uladv
= byte_get (data
, 2);
3190 state_machine_regs
.address
+= uladv
;
3191 state_machine_regs
.op_index
= 0;
3194 case DW_LNS_set_prologue_end
:
3197 case DW_LNS_set_epilogue_begin
:
3200 case DW_LNS_set_isa
:
3201 uladv
= read_leb128 (data
, & bytes_read
, 0);
3203 printf (_(" Set ISA to %lu\n"), uladv
);
3207 printf (_(" Unknown opcode %d with operands: "), op_code
);
3209 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
3211 printf ("0x%s%s", dwarf_vmatoa ("x", read_leb128 (data
,
3213 i
== 1 ? "" : ", ");
3220 /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row
3221 to the DWARF address/line matrix. */
3222 if ((is_special_opcode
) || (op_code
== DW_LNE_end_sequence
)
3223 || (op_code
== DW_LNS_copy
))
3225 const unsigned int MAX_FILENAME_LENGTH
= 35;
3226 char *fileName
= (char *)file_table
[state_machine_regs
.file
- 1].name
;
3227 char *newFileName
= NULL
;
3228 size_t fileNameLength
= strlen (fileName
);
3230 if ((fileNameLength
> MAX_FILENAME_LENGTH
) && (!do_wide
))
3232 newFileName
= (char *) xmalloc (MAX_FILENAME_LENGTH
+ 1);
3233 /* Truncate file name */
3234 strncpy (newFileName
,
3235 fileName
+ fileNameLength
- MAX_FILENAME_LENGTH
,
3236 MAX_FILENAME_LENGTH
+ 1);
3240 newFileName
= (char *) xmalloc (fileNameLength
+ 1);
3241 strncpy (newFileName
, fileName
, fileNameLength
+ 1);
3244 if (!do_wide
|| (fileNameLength
<= MAX_FILENAME_LENGTH
))
3246 if (linfo
.li_max_ops_per_insn
== 1)
3247 printf ("%-35s %11d %#18" DWARF_VMA_FMT
"x\n",
3248 newFileName
, state_machine_regs
.line
,
3249 state_machine_regs
.address
);
3251 printf ("%-35s %11d %#18" DWARF_VMA_FMT
"x[%d]\n",
3252 newFileName
, state_machine_regs
.line
,
3253 state_machine_regs
.address
,
3254 state_machine_regs
.op_index
);
3258 if (linfo
.li_max_ops_per_insn
== 1)
3259 printf ("%s %11d %#18" DWARF_VMA_FMT
"x\n",
3260 newFileName
, state_machine_regs
.line
,
3261 state_machine_regs
.address
);
3263 printf ("%s %11d %#18" DWARF_VMA_FMT
"x[%d]\n",
3264 newFileName
, state_machine_regs
.line
,
3265 state_machine_regs
.address
,
3266 state_machine_regs
.op_index
);
3269 if (op_code
== DW_LNE_end_sequence
)
3277 free (directory_table
);
3278 directory_table
= NULL
;
3286 display_debug_lines (struct dwarf_section
*section
, void *file ATTRIBUTE_UNUSED
)
3288 unsigned char *data
= section
->start
;
3289 unsigned char *end
= data
+ section
->size
;
3291 int retValDecoded
= 1;
3293 if (do_debug_lines
== 0)
3294 do_debug_lines
|= FLAG_DEBUG_LINES_RAW
;
3296 if (do_debug_lines
& FLAG_DEBUG_LINES_RAW
)
3297 retValRaw
= display_debug_lines_raw (section
, data
, end
);
3299 if (do_debug_lines
& FLAG_DEBUG_LINES_DECODED
)
3300 retValDecoded
= display_debug_lines_decoded (section
, data
, end
);
3302 if (!retValRaw
|| !retValDecoded
)
3309 find_debug_info_for_offset (unsigned long offset
)
3313 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
3316 for (i
= 0; i
< num_debug_info_entries
; i
++)
3317 if (debug_information
[i
].cu_offset
== offset
)
3318 return debug_information
+ i
;
3324 display_debug_pubnames (struct dwarf_section
*section
,
3325 void *file ATTRIBUTE_UNUSED
)
3327 DWARF2_Internal_PubNames names
;
3328 unsigned char *start
= section
->start
;
3329 unsigned char *end
= start
+ section
->size
;
3331 /* It does not matter if this load fails,
3332 we test for that later on. */
3333 load_debug_info (file
);
3335 printf (_("Contents of the %s section:\n\n"), section
->name
);
3339 unsigned char *data
;
3340 unsigned long offset
;
3341 int offset_size
, initial_length_size
;
3345 names
.pn_length
= byte_get (data
, 4);
3347 if (names
.pn_length
== 0xffffffff)
3349 names
.pn_length
= byte_get (data
, 8);
3352 initial_length_size
= 12;
3357 initial_length_size
= 4;
3360 names
.pn_version
= byte_get (data
, 2);
3363 names
.pn_offset
= byte_get (data
, offset_size
);
3364 data
+= offset_size
;
3366 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
3367 && num_debug_info_entries
> 0
3368 && find_debug_info_for_offset (names
.pn_offset
) == NULL
)
3369 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
3370 (unsigned long) names
.pn_offset
, section
->name
);
3372 names
.pn_size
= byte_get (data
, offset_size
);
3373 data
+= offset_size
;
3375 start
+= names
.pn_length
+ initial_length_size
;
3377 if (names
.pn_version
!= 2 && names
.pn_version
!= 3)
3379 static int warned
= 0;
3383 warn (_("Only DWARF 2 and 3 pubnames are currently supported\n"));
3390 printf (_(" Length: %ld\n"),
3391 (long) names
.pn_length
);
3392 printf (_(" Version: %d\n"),
3394 printf (_(" Offset into .debug_info section: 0x%lx\n"),
3395 (unsigned long) names
.pn_offset
);
3396 printf (_(" Size of area in .debug_info section: %ld\n"),
3397 (long) names
.pn_size
);
3399 printf (_("\n Offset\tName\n"));
3403 offset
= byte_get (data
, offset_size
);
3407 data
+= offset_size
;
3408 printf (" %-6lx\t%s\n", offset
, data
);
3409 data
+= strlen ((char *) data
) + 1;
3412 while (offset
!= 0);
3420 display_debug_macinfo (struct dwarf_section
*section
,
3421 void *file ATTRIBUTE_UNUSED
)
3423 unsigned char *start
= section
->start
;
3424 unsigned char *end
= start
+ section
->size
;
3425 unsigned char *curr
= start
;
3426 unsigned int bytes_read
;
3427 enum dwarf_macinfo_record_type op
;
3429 printf (_("Contents of the %s section:\n\n"), section
->name
);
3433 unsigned int lineno
;
3436 op
= (enum dwarf_macinfo_record_type
) *curr
;
3441 case DW_MACINFO_start_file
:
3443 unsigned int filenum
;
3445 lineno
= read_leb128 (curr
, & bytes_read
, 0);
3447 filenum
= read_leb128 (curr
, & bytes_read
, 0);
3450 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"),
3455 case DW_MACINFO_end_file
:
3456 printf (_(" DW_MACINFO_end_file\n"));
3459 case DW_MACINFO_define
:
3460 lineno
= read_leb128 (curr
, & bytes_read
, 0);
3462 string
= (char *) curr
;
3463 curr
+= strlen (string
) + 1;
3464 printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"),
3468 case DW_MACINFO_undef
:
3469 lineno
= read_leb128 (curr
, & bytes_read
, 0);
3471 string
= (char *) curr
;
3472 curr
+= strlen (string
) + 1;
3473 printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"),
3477 case DW_MACINFO_vendor_ext
:
3479 unsigned int constant
;
3481 constant
= read_leb128 (curr
, & bytes_read
, 0);
3483 string
= (char *) curr
;
3484 curr
+= strlen (string
) + 1;
3485 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"),
3495 /* Given LINE_OFFSET into the .debug_line section, attempt to return
3496 filename and dirname corresponding to file name table entry with index
3497 FILEIDX. Return NULL on failure. */
3499 static unsigned char *
3500 get_line_filename_and_dirname (dwarf_vma line_offset
, dwarf_vma fileidx
,
3501 unsigned char **dir_name
)
3503 struct dwarf_section
*section
= &debug_displays
[line
].section
;
3504 unsigned char *hdrptr
, *dirtable
, *file_name
;
3505 unsigned int offset_size
, initial_length_size
;
3506 unsigned int version
, opcode_base
, bytes_read
;
3507 dwarf_vma length
, diridx
;
3510 if (section
->start
== NULL
3511 || line_offset
>= section
->size
3515 hdrptr
= section
->start
+ line_offset
;
3516 length
= byte_get (hdrptr
, 4);
3518 if (length
== 0xffffffff)
3520 /* This section is 64-bit DWARF 3. */
3521 length
= byte_get (hdrptr
, 8);
3524 initial_length_size
= 12;
3529 initial_length_size
= 4;
3531 if (length
+ initial_length_size
> section
->size
)
3533 version
= byte_get (hdrptr
, 2);
3535 if (version
!= 2 && version
!= 3 && version
!= 4)
3537 hdrptr
+= offset_size
+ 1;/* Skip prologue_length and min_insn_length. */
3539 hdrptr
++; /* Skip max_ops_per_insn. */
3540 hdrptr
+= 3; /* Skip default_is_stmt, line_base, line_range. */
3541 opcode_base
= byte_get (hdrptr
, 1);
3542 if (opcode_base
== 0)
3545 hdrptr
+= opcode_base
- 1;
3547 /* Skip over dirname table. */
3548 while (*hdrptr
!= '\0')
3549 hdrptr
+= strlen ((char *) hdrptr
) + 1;
3550 hdrptr
++; /* Skip the NUL at the end of the table. */
3551 /* Now skip over preceding filename table entries. */
3552 for (; *hdrptr
!= '\0' && fileidx
> 1; fileidx
--)
3554 hdrptr
+= strlen ((char *) hdrptr
) + 1;
3555 read_leb128 (hdrptr
, &bytes_read
, 0);
3556 hdrptr
+= bytes_read
;
3557 read_leb128 (hdrptr
, &bytes_read
, 0);
3558 hdrptr
+= bytes_read
;
3559 read_leb128 (hdrptr
, &bytes_read
, 0);
3560 hdrptr
+= bytes_read
;
3562 if (*hdrptr
== '\0')
3565 hdrptr
+= strlen ((char *) hdrptr
) + 1;
3566 diridx
= read_leb128 (hdrptr
, &bytes_read
, 0);
3569 for (; *dirtable
!= '\0' && diridx
> 1; diridx
--)
3570 dirtable
+= strlen ((char *) dirtable
) + 1;
3571 if (*dirtable
== '\0')
3573 *dir_name
= dirtable
;
3578 display_debug_macro (struct dwarf_section
*section
,
3581 unsigned char *start
= section
->start
;
3582 unsigned char *end
= start
+ section
->size
;
3583 unsigned char *curr
= start
;
3584 unsigned char *extended_op_buf
[256];
3585 unsigned int bytes_read
;
3587 load_debug_section (str
, file
);
3588 load_debug_section (line
, file
);
3590 printf (_("Contents of the %s section:\n\n"), section
->name
);
3594 unsigned int lineno
, version
, flags
;
3595 unsigned int offset_size
= 4;
3597 dwarf_vma line_offset
= 0, sec_offset
= curr
- start
, offset
;
3598 unsigned char **extended_ops
= NULL
;
3600 version
= byte_get (curr
, 2);
3605 error (_("Only GNU extension to DWARF 4 of %s is currently supported.\n"),
3610 flags
= byte_get (curr
++, 1);
3613 printf (_(" Offset: 0x%lx\n"),
3614 (unsigned long) sec_offset
);
3615 printf (_(" Version: %d\n"), version
);
3616 printf (_(" Offset size: %d\n"), offset_size
);
3619 line_offset
= byte_get (curr
, offset_size
);
3620 curr
+= offset_size
;
3621 printf (_(" Offset into .debug_line: 0x%lx\n"),
3622 (unsigned long) line_offset
);
3626 unsigned int i
, count
= byte_get (curr
++, 1), op
;
3628 memset (extended_op_buf
, 0, sizeof (extended_op_buf
));
3629 extended_ops
= extended_op_buf
;
3632 printf (_(" Extension opcode arguments:\n"));
3633 for (i
= 0; i
< count
; i
++)
3635 op
= byte_get (curr
++, 1);
3636 extended_ops
[op
] = curr
;
3637 nargs
= read_leb128 (curr
, &bytes_read
, 0);
3640 printf (_(" DW_MACRO_GNU_%02x has no arguments\n"), op
);
3643 printf (_(" DW_MACRO_GNU_%02x arguments: "), op
);
3644 for (n
= 0; n
< nargs
; n
++)
3646 unsigned int form
= byte_get (curr
++, 1);
3647 printf ("%s%s", get_FORM_name (form
),
3648 n
== nargs
- 1 ? "\n" : ", ");
3658 case DW_FORM_block1
:
3659 case DW_FORM_block2
:
3660 case DW_FORM_block4
:
3662 case DW_FORM_string
:
3664 case DW_FORM_sec_offset
:
3667 error (_("Invalid extension opcode form %s\n"),
3668 get_FORM_name (form
));
3684 error (_(".debug_macro section not zero terminated\n"));
3688 op
= byte_get (curr
++, 1);
3694 case DW_MACRO_GNU_start_file
:
3696 unsigned int filenum
;
3697 unsigned char *file_name
= NULL
, *dir_name
= NULL
;
3699 lineno
= read_leb128 (curr
, &bytes_read
, 0);
3701 filenum
= read_leb128 (curr
, &bytes_read
, 0);
3704 if ((flags
& 2) == 0)
3705 error (_("DW_MACRO_GNU_start_file used, but no .debug_line offset provided.\n"));
3708 = get_line_filename_and_dirname (line_offset
, filenum
,
3710 if (file_name
== NULL
)
3711 printf (_(" DW_MACRO_GNU_start_file - lineno: %d filenum: %d\n"),
3714 printf (_(" DW_MACRO_GNU_start_file - lineno: %d filenum: %d filename: %s%s%s\n"),
3716 dir_name
!= NULL
? (const char *) dir_name
: "",
3717 dir_name
!= NULL
? "/" : "", file_name
);
3721 case DW_MACRO_GNU_end_file
:
3722 printf (_(" DW_MACRO_GNU_end_file\n"));
3725 case DW_MACRO_GNU_define
:
3726 lineno
= read_leb128 (curr
, &bytes_read
, 0);
3728 string
= (char *) curr
;
3729 curr
+= strlen (string
) + 1;
3730 printf (_(" DW_MACRO_GNU_define - lineno : %d macro : %s\n"),
3734 case DW_MACRO_GNU_undef
:
3735 lineno
= read_leb128 (curr
, &bytes_read
, 0);
3737 string
= (char *) curr
;
3738 curr
+= strlen (string
) + 1;
3739 printf (_(" DW_MACRO_GNU_undef - lineno : %d macro : %s\n"),
3743 case DW_MACRO_GNU_define_indirect
:
3744 lineno
= read_leb128 (curr
, &bytes_read
, 0);
3746 offset
= byte_get (curr
, offset_size
);
3747 curr
+= offset_size
;
3748 string
= fetch_indirect_string (offset
);
3749 printf (_(" DW_MACRO_GNU_define_indirect - lineno : %d macro : %s\n"),
3753 case DW_MACRO_GNU_undef_indirect
:
3754 lineno
= read_leb128 (curr
, &bytes_read
, 0);
3756 offset
= byte_get (curr
, offset_size
);
3757 curr
+= offset_size
;
3758 string
= fetch_indirect_string (offset
);
3759 printf (_(" DW_MACRO_GNU_undef_indirect - lineno : %d macro : %s\n"),
3763 case DW_MACRO_GNU_transparent_include
:
3764 offset
= byte_get (curr
, offset_size
);
3765 curr
+= offset_size
;
3766 printf (_(" DW_MACRO_GNU_transparent_include - offset : 0x%lx\n"),
3767 (unsigned long) offset
);
3771 if (extended_ops
== NULL
|| extended_ops
[op
] == NULL
)
3773 error (_(" Unknown macro opcode %02x seen\n"), op
);
3778 /* Skip over unhandled opcodes. */
3780 unsigned char *desc
= extended_ops
[op
];
3781 nargs
= read_leb128 (desc
, &bytes_read
, 0);
3785 printf (_(" DW_MACRO_GNU_%02x\n"), op
);
3788 printf (_(" DW_MACRO_GNU_%02x -"), op
);
3789 for (n
= 0; n
< nargs
; n
++)
3792 = read_and_display_attr_value (0, byte_get (desc
++, 1),
3793 curr
, 0, 0, offset_size
,
3794 version
, NULL
, 0, NULL
);
3811 display_debug_abbrev (struct dwarf_section
*section
,
3812 void *file ATTRIBUTE_UNUSED
)
3814 abbrev_entry
*entry
;
3815 unsigned char *start
= section
->start
;
3816 unsigned char *end
= start
+ section
->size
;
3818 printf (_("Contents of the %s section:\n\n"), section
->name
);
3824 start
= process_abbrev_section (start
, end
);
3826 if (first_abbrev
== NULL
)
3829 printf (_(" Number TAG\n"));
3831 for (entry
= first_abbrev
; entry
; entry
= entry
->next
)
3835 printf (" %ld %s [%s]\n",
3837 get_TAG_name (entry
->tag
),
3838 entry
->children
? _("has children") : _("no children"));
3840 for (attr
= entry
->first_attr
; attr
; attr
= attr
->next
)
3841 printf (" %-18s %s\n",
3842 get_AT_name (attr
->attribute
),
3843 get_FORM_name (attr
->form
));
3853 /* Sort array of indexes in ascending order of loc_offsets[idx]. */
3855 static dwarf_vma
*loc_offsets
;
3858 loc_offsets_compar (const void *ap
, const void *bp
)
3860 dwarf_vma a
= loc_offsets
[*(const unsigned int *) ap
];
3861 dwarf_vma b
= loc_offsets
[*(const unsigned int *) bp
];
3863 return (a
> b
) - (b
> a
);
3867 display_debug_loc (struct dwarf_section
*section
, void *file
)
3869 unsigned char *start
= section
->start
;
3870 unsigned char *section_end
;
3871 unsigned long bytes
;
3872 unsigned char *section_begin
= start
;
3873 unsigned int num_loc_list
= 0;
3874 unsigned long last_offset
= 0;
3875 unsigned int first
= 0;
3879 int seen_first_offset
= 0;
3880 int locs_sorted
= 1;
3881 unsigned char *next
;
3882 unsigned int *array
= NULL
;
3884 bytes
= section
->size
;
3885 section_end
= start
+ bytes
;
3889 printf (_("\nThe %s section is empty.\n"), section
->name
);
3893 if (load_debug_info (file
) == 0)
3895 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
3900 /* Check the order of location list in .debug_info section. If
3901 offsets of location lists are in the ascending order, we can
3902 use `debug_information' directly. */
3903 for (i
= 0; i
< num_debug_info_entries
; i
++)
3907 num
= debug_information
[i
].num_loc_offsets
;
3908 if (num
> num_loc_list
)
3911 /* Check if we can use `debug_information' directly. */
3912 if (locs_sorted
&& num
!= 0)
3914 if (!seen_first_offset
)
3916 /* This is the first location list. */
3917 last_offset
= debug_information
[i
].loc_offsets
[0];
3919 seen_first_offset
= 1;
3925 for (; j
< num
; j
++)
3928 debug_information
[i
].loc_offsets
[j
])
3933 last_offset
= debug_information
[i
].loc_offsets
[j
];
3938 if (!seen_first_offset
)
3939 error (_("No location lists in .debug_info section!\n"));
3941 /* DWARF sections under Mach-O have non-zero addresses. */
3942 if (debug_information
[first
].num_loc_offsets
> 0
3943 && debug_information
[first
].loc_offsets
[0] != section
->address
)
3944 warn (_("Location lists in %s section start at 0x%s\n"),
3946 dwarf_vmatoa ("x", debug_information
[first
].loc_offsets
[0]));
3949 array
= (unsigned int *) xcmalloc (num_loc_list
, sizeof (unsigned int));
3950 printf (_("Contents of the %s section:\n\n"), section
->name
);
3951 printf (_(" Offset Begin End Expression\n"));
3953 seen_first_offset
= 0;
3954 for (i
= first
; i
< num_debug_info_entries
; i
++)
3958 unsigned short length
;
3959 unsigned long offset
;
3960 unsigned int pointer_size
;
3961 unsigned int offset_size
;
3963 unsigned long cu_offset
;
3964 unsigned long base_address
;
3965 int need_frame_base
;
3968 pointer_size
= debug_information
[i
].pointer_size
;
3969 cu_offset
= debug_information
[i
].cu_offset
;
3970 offset_size
= debug_information
[i
].offset_size
;
3971 dwarf_version
= debug_information
[i
].dwarf_version
;
3974 for (k
= 0; k
< debug_information
[i
].num_loc_offsets
; k
++)
3976 loc_offsets
= debug_information
[i
].loc_offsets
;
3977 qsort (array
, debug_information
[i
].num_loc_offsets
,
3978 sizeof (*array
), loc_offsets_compar
);
3981 for (k
= 0; k
< debug_information
[i
].num_loc_offsets
; k
++)
3983 j
= locs_sorted
? k
: array
[k
];
3985 && debug_information
[i
].loc_offsets
[locs_sorted
3986 ? k
- 1 : array
[k
- 1]]
3987 == debug_information
[i
].loc_offsets
[j
])
3989 has_frame_base
= debug_information
[i
].have_frame_base
[j
];
3990 /* DWARF sections under Mach-O have non-zero addresses. */
3991 offset
= debug_information
[i
].loc_offsets
[j
] - section
->address
;
3992 next
= section_begin
+ offset
;
3993 base_address
= debug_information
[i
].base_address
;
3995 if (!seen_first_offset
)
3996 seen_first_offset
= 1;
4000 warn (_("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n"),
4001 (unsigned long) (start
- section_begin
),
4002 (unsigned long) (next
- section_begin
));
4003 else if (start
> next
)
4004 warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n"),
4005 (unsigned long) (start
- section_begin
),
4006 (unsigned long) (next
- section_begin
));
4010 if (offset
>= bytes
)
4012 warn (_("Offset 0x%lx is bigger than .debug_loc section size.\n"),
4019 if (start
+ 2 * pointer_size
> section_end
)
4021 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
4026 /* Note: we use sign extension here in order to be sure that
4027 we can detect the -1 escape value. Sign extension into the
4028 top 32 bits of a 32-bit address will not affect the values
4029 that we display since we always show hex values, and always
4030 the bottom 32-bits. */
4031 begin
= byte_get_signed (start
, pointer_size
);
4032 start
+= pointer_size
;
4033 end
= byte_get_signed (start
, pointer_size
);
4034 start
+= pointer_size
;
4036 printf (" %8.8lx ", offset
);
4038 if (begin
== 0 && end
== 0)
4040 printf (_("<End of list>\n"));
4044 /* Check base address specifiers. */
4045 if (begin
== (dwarf_vma
) -1 && end
!= (dwarf_vma
) -1)
4048 print_dwarf_vma (begin
, pointer_size
);
4049 print_dwarf_vma (end
, pointer_size
);
4050 printf (_("(base address)\n"));
4054 if (start
+ 2 > section_end
)
4056 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
4061 length
= byte_get (start
, 2);
4064 if (start
+ length
> section_end
)
4066 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
4071 print_dwarf_vma (begin
+ base_address
, pointer_size
);
4072 print_dwarf_vma (end
+ base_address
, pointer_size
);
4075 need_frame_base
= decode_location_expression (start
,
4080 cu_offset
, section
);
4083 if (need_frame_base
&& !has_frame_base
)
4084 printf (_(" [without DW_AT_frame_base]"));
4087 fputs (_(" (start == end)"), stdout
);
4088 else if (begin
> end
)
4089 fputs (_(" (start > end)"), stdout
);
4098 if (start
< section_end
)
4099 warn (_("There are %ld unused bytes at the end of section %s\n"),
4100 (long) (section_end
- start
), section
->name
);
4107 display_debug_str (struct dwarf_section
*section
,
4108 void *file ATTRIBUTE_UNUSED
)
4110 unsigned char *start
= section
->start
;
4111 unsigned long bytes
= section
->size
;
4112 dwarf_vma addr
= section
->address
;
4116 printf (_("\nThe %s section is empty.\n"), section
->name
);
4120 printf (_("Contents of the %s section:\n\n"), section
->name
);
4128 lbytes
= (bytes
> 16 ? 16 : bytes
);
4130 printf (" 0x%8.8lx ", (unsigned long) addr
);
4132 for (j
= 0; j
< 16; j
++)
4135 printf ("%2.2x", start
[j
]);
4143 for (j
= 0; j
< lbytes
; j
++)
4146 if (k
>= ' ' && k
< 0x80)
4165 display_debug_info (struct dwarf_section
*section
, void *file
)
4167 return process_debug_info (section
, file
, abbrev
, 0, 0);
4171 display_debug_types (struct dwarf_section
*section
, void *file
)
4173 return process_debug_info (section
, file
, abbrev
, 0, 1);
4177 display_trace_info (struct dwarf_section
*section
, void *file
)
4179 return process_debug_info (section
, file
, trace_abbrev
, 0, 0);
4183 display_debug_aranges (struct dwarf_section
*section
,
4184 void *file ATTRIBUTE_UNUSED
)
4186 unsigned char *start
= section
->start
;
4187 unsigned char *end
= start
+ section
->size
;
4189 printf (_("Contents of the %s section:\n\n"), section
->name
);
4191 /* It does not matter if this load fails,
4192 we test for that later on. */
4193 load_debug_info (file
);
4197 unsigned char *hdrptr
;
4198 DWARF2_Internal_ARange arange
;
4199 unsigned char *addr_ranges
;
4202 unsigned char address_size
;
4205 int initial_length_size
;
4209 arange
.ar_length
= byte_get (hdrptr
, 4);
4212 if (arange
.ar_length
== 0xffffffff)
4214 arange
.ar_length
= byte_get (hdrptr
, 8);
4217 initial_length_size
= 12;
4222 initial_length_size
= 4;
4225 arange
.ar_version
= byte_get (hdrptr
, 2);
4228 arange
.ar_info_offset
= byte_get (hdrptr
, offset_size
);
4229 hdrptr
+= offset_size
;
4231 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
4232 && num_debug_info_entries
> 0
4233 && find_debug_info_for_offset (arange
.ar_info_offset
) == NULL
)
4234 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
4235 (unsigned long) arange
.ar_info_offset
, section
->name
);
4237 arange
.ar_pointer_size
= byte_get (hdrptr
, 1);
4240 arange
.ar_segment_size
= byte_get (hdrptr
, 1);
4243 if (arange
.ar_version
!= 2 && arange
.ar_version
!= 3)
4245 warn (_("Only DWARF 2 and 3 aranges are currently supported.\n"));
4249 printf (_(" Length: %ld\n"),
4250 (long) arange
.ar_length
);
4251 printf (_(" Version: %d\n"), arange
.ar_version
);
4252 printf (_(" Offset into .debug_info: 0x%lx\n"),
4253 (unsigned long) arange
.ar_info_offset
);
4254 printf (_(" Pointer Size: %d\n"), arange
.ar_pointer_size
);
4255 printf (_(" Segment Size: %d\n"), arange
.ar_segment_size
);
4257 address_size
= arange
.ar_pointer_size
+ arange
.ar_segment_size
;
4259 if (address_size
== 0)
4261 error (_("Invalid address size in %s section!\n"),
4266 /* The DWARF spec does not require that the address size be a power
4267 of two, but we do. This will have to change if we ever encounter
4268 an uneven architecture. */
4269 if ((address_size
& (address_size
- 1)) != 0)
4271 warn (_("Pointer size + Segment size is not a power of two.\n"));
4275 if (address_size
> 4)
4276 printf (_("\n Address Length\n"));
4278 printf (_("\n Address Length\n"));
4280 addr_ranges
= hdrptr
;
4282 /* Must pad to an alignment boundary that is twice the address size. */
4283 excess
= (hdrptr
- start
) % (2 * address_size
);
4285 addr_ranges
+= (2 * address_size
) - excess
;
4287 start
+= arange
.ar_length
+ initial_length_size
;
4289 while (addr_ranges
+ 2 * address_size
<= start
)
4291 address
= byte_get (addr_ranges
, address_size
);
4293 addr_ranges
+= address_size
;
4295 length
= byte_get (addr_ranges
, address_size
);
4297 addr_ranges
+= address_size
;
4300 print_dwarf_vma (address
, address_size
);
4301 print_dwarf_vma (length
, address_size
);
4311 /* Each debug_information[x].range_lists[y] gets this representation for
4312 sorting purposes. */
4316 /* The debug_information[x].range_lists[y] value. */
4317 unsigned long ranges_offset
;
4319 /* Original debug_information to find parameters of the data. */
4320 debug_info
*debug_info_p
;
4323 /* Sort struct range_entry in ascending order of its RANGES_OFFSET. */
4326 range_entry_compar (const void *ap
, const void *bp
)
4328 const struct range_entry
*a_re
= (const struct range_entry
*) ap
;
4329 const struct range_entry
*b_re
= (const struct range_entry
*) bp
;
4330 const unsigned long a
= a_re
->ranges_offset
;
4331 const unsigned long b
= b_re
->ranges_offset
;
4333 return (a
> b
) - (b
> a
);
4337 display_debug_ranges (struct dwarf_section
*section
,
4338 void *file ATTRIBUTE_UNUSED
)
4340 unsigned char *start
= section
->start
;
4341 unsigned long bytes
;
4342 unsigned char *section_begin
= start
;
4343 unsigned int num_range_list
, i
;
4344 struct range_entry
*range_entries
, *range_entry_fill
;
4346 bytes
= section
->size
;
4350 printf (_("\nThe %s section is empty.\n"), section
->name
);
4354 if (load_debug_info (file
) == 0)
4356 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
4362 for (i
= 0; i
< num_debug_info_entries
; i
++)
4363 num_range_list
+= debug_information
[i
].num_range_lists
;
4365 if (num_range_list
== 0)
4366 error (_("No range lists in .debug_info section!\n"));
4368 range_entries
= (struct range_entry
*)
4369 xmalloc (sizeof (*range_entries
) * num_range_list
);
4370 range_entry_fill
= range_entries
;
4372 for (i
= 0; i
< num_debug_info_entries
; i
++)
4374 debug_info
*debug_info_p
= &debug_information
[i
];
4377 for (j
= 0; j
< debug_info_p
->num_range_lists
; j
++)
4379 range_entry_fill
->ranges_offset
= debug_info_p
->range_lists
[j
];
4380 range_entry_fill
->debug_info_p
= debug_info_p
;
4385 qsort (range_entries
, num_range_list
, sizeof (*range_entries
),
4386 range_entry_compar
);
4388 /* DWARF sections under Mach-O have non-zero addresses. */
4389 if (range_entries
[0].ranges_offset
!= section
->address
)
4390 warn (_("Range lists in %s section start at 0x%lx\n"),
4391 section
->name
, range_entries
[0].ranges_offset
);
4393 printf (_("Contents of the %s section:\n\n"), section
->name
);
4394 printf (_(" Offset Begin End\n"));
4396 for (i
= 0; i
< num_range_list
; i
++)
4398 struct range_entry
*range_entry
= &range_entries
[i
];
4399 debug_info
*debug_info_p
= range_entry
->debug_info_p
;
4400 unsigned int pointer_size
;
4401 unsigned long offset
;
4402 unsigned char *next
;
4403 unsigned long base_address
;
4405 pointer_size
= debug_info_p
->pointer_size
;
4407 /* DWARF sections under Mach-O have non-zero addresses. */
4408 offset
= range_entry
->ranges_offset
- section
->address
;
4409 next
= section_begin
+ offset
;
4410 base_address
= debug_info_p
->base_address
;
4415 warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"),
4416 (unsigned long) (start
- section_begin
),
4417 (unsigned long) (next
- section_begin
), section
->name
);
4418 else if (start
> next
)
4419 warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"),
4420 (unsigned long) (start
- section_begin
),
4421 (unsigned long) (next
- section_begin
), section
->name
);
4430 /* Note: we use sign extension here in order to be sure that
4431 we can detect the -1 escape value. Sign extension into the
4432 top 32 bits of a 32-bit address will not affect the values
4433 that we display since we always show hex values, and always
4434 the bottom 32-bits. */
4435 begin
= byte_get_signed (start
, pointer_size
);
4436 start
+= pointer_size
;
4437 end
= byte_get_signed (start
, pointer_size
);
4438 start
+= pointer_size
;
4440 printf (" %8.8lx ", offset
);
4442 if (begin
== 0 && end
== 0)
4444 printf (_("<End of list>\n"));
4448 /* Check base address specifiers. */
4449 if (begin
== (dwarf_vma
) -1 && end
!= (dwarf_vma
) -1)
4452 print_dwarf_vma (begin
, pointer_size
);
4453 print_dwarf_vma (end
, pointer_size
);
4454 printf ("(base address)\n");
4458 print_dwarf_vma (begin
+ base_address
, pointer_size
);
4459 print_dwarf_vma (end
+ base_address
, pointer_size
);
4462 fputs (_("(start == end)"), stdout
);
4463 else if (begin
> end
)
4464 fputs (_("(start > end)"), stdout
);
4471 free (range_entries
);
4476 typedef struct Frame_Chunk
4478 struct Frame_Chunk
*next
;
4479 unsigned char *chunk_start
;
4481 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
4482 short int *col_type
;
4485 unsigned int code_factor
;
4487 unsigned long pc_begin
;
4488 unsigned long pc_range
;
4492 unsigned char fde_encoding
;
4493 unsigned char cfa_exp
;
4494 unsigned char ptr_size
;
4495 unsigned char segment_size
;
4499 static const char *const *dwarf_regnames
;
4500 static unsigned int dwarf_regnames_count
;
4502 /* A marker for a col_type that means this column was never referenced
4503 in the frame info. */
4504 #define DW_CFA_unreferenced (-1)
4506 /* Return 0 if not more space is needed, 1 if more space is needed,
4507 -1 for invalid reg. */
4510 frame_need_space (Frame_Chunk
*fc
, unsigned int reg
)
4512 int prev
= fc
->ncols
;
4514 if (reg
< (unsigned int) fc
->ncols
)
4517 if (dwarf_regnames_count
4518 && reg
> dwarf_regnames_count
)
4521 fc
->ncols
= reg
+ 1;
4522 fc
->col_type
= (short int *) xcrealloc (fc
->col_type
, fc
->ncols
,
4523 sizeof (short int));
4524 fc
->col_offset
= (int *) xcrealloc (fc
->col_offset
, fc
->ncols
, sizeof (int));
4526 while (prev
< fc
->ncols
)
4528 fc
->col_type
[prev
] = DW_CFA_unreferenced
;
4529 fc
->col_offset
[prev
] = 0;
4535 static const char *const dwarf_regnames_i386
[] =
4537 "eax", "ecx", "edx", "ebx",
4538 "esp", "ebp", "esi", "edi",
4539 "eip", "eflags", NULL
,
4540 "st0", "st1", "st2", "st3",
4541 "st4", "st5", "st6", "st7",
4543 "xmm0", "xmm1", "xmm2", "xmm3",
4544 "xmm4", "xmm5", "xmm6", "xmm7",
4545 "mm0", "mm1", "mm2", "mm3",
4546 "mm4", "mm5", "mm6", "mm7",
4547 "fcw", "fsw", "mxcsr",
4548 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
,
4553 init_dwarf_regnames_i386 (void)
4555 dwarf_regnames
= dwarf_regnames_i386
;
4556 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_i386
);
4559 static const char *const dwarf_regnames_x86_64
[] =
4561 "rax", "rdx", "rcx", "rbx",
4562 "rsi", "rdi", "rbp", "rsp",
4563 "r8", "r9", "r10", "r11",
4564 "r12", "r13", "r14", "r15",
4566 "xmm0", "xmm1", "xmm2", "xmm3",
4567 "xmm4", "xmm5", "xmm6", "xmm7",
4568 "xmm8", "xmm9", "xmm10", "xmm11",
4569 "xmm12", "xmm13", "xmm14", "xmm15",
4570 "st0", "st1", "st2", "st3",
4571 "st4", "st5", "st6", "st7",
4572 "mm0", "mm1", "mm2", "mm3",
4573 "mm4", "mm5", "mm6", "mm7",
4575 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
,
4576 "fs.base", "gs.base", NULL
, NULL
,
4578 "mxcsr", "fcw", "fsw"
4582 init_dwarf_regnames_x86_64 (void)
4584 dwarf_regnames
= dwarf_regnames_x86_64
;
4585 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_x86_64
);
4589 init_dwarf_regnames (unsigned int e_machine
)
4595 init_dwarf_regnames_i386 ();
4601 init_dwarf_regnames_x86_64 ();
4610 regname (unsigned int regno
, int row
)
4612 static char reg
[64];
4614 && regno
< dwarf_regnames_count
4615 && dwarf_regnames
[regno
] != NULL
)
4618 return dwarf_regnames
[regno
];
4619 snprintf (reg
, sizeof (reg
), "r%d (%s)", regno
,
4620 dwarf_regnames
[regno
]);
4623 snprintf (reg
, sizeof (reg
), "r%d", regno
);
4628 frame_display_row (Frame_Chunk
*fc
, int *need_col_headers
, int *max_regs
)
4633 if (*max_regs
< fc
->ncols
)
4634 *max_regs
= fc
->ncols
;
4636 if (*need_col_headers
)
4638 static const char *sloc
= " LOC";
4640 *need_col_headers
= 0;
4642 printf ("%-*s CFA ", eh_addr_size
* 2, sloc
);
4644 for (r
= 0; r
< *max_regs
; r
++)
4645 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
4650 printf ("%-5s ", regname (r
, 1));
4656 printf ("%0*lx ", eh_addr_size
* 2, fc
->pc_begin
);
4658 strcpy (tmp
, "exp");
4660 sprintf (tmp
, "%s%+d", regname (fc
->cfa_reg
, 1), fc
->cfa_offset
);
4661 printf ("%-8s ", tmp
);
4663 for (r
= 0; r
< fc
->ncols
; r
++)
4665 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
4667 switch (fc
->col_type
[r
])
4669 case DW_CFA_undefined
:
4672 case DW_CFA_same_value
:
4676 sprintf (tmp
, "c%+d", fc
->col_offset
[r
]);
4678 case DW_CFA_val_offset
:
4679 sprintf (tmp
, "v%+d", fc
->col_offset
[r
]);
4681 case DW_CFA_register
:
4682 sprintf (tmp
, "%s", regname (fc
->col_offset
[r
], 0));
4684 case DW_CFA_expression
:
4685 strcpy (tmp
, "exp");
4687 case DW_CFA_val_expression
:
4688 strcpy (tmp
, "vexp");
4691 strcpy (tmp
, "n/a");
4694 printf ("%-5s ", tmp
);
4700 #define GET(N) byte_get (start, N); start += N
4701 #define LEB() read_leb128 (start, & length_return, 0); start += length_return
4702 #define SLEB() read_sleb128 (start, & length_return); start += length_return
4705 display_debug_frames (struct dwarf_section
*section
,
4706 void *file ATTRIBUTE_UNUSED
)
4708 unsigned char *start
= section
->start
;
4709 unsigned char *end
= start
+ section
->size
;
4710 unsigned char *section_start
= start
;
4711 Frame_Chunk
*chunks
= 0;
4712 Frame_Chunk
*remembered_state
= 0;
4714 int is_eh
= strcmp (section
->name
, ".eh_frame") == 0;
4715 unsigned int length_return
;
4717 const char *bad_reg
= _("bad register: ");
4718 int saved_eh_addr_size
= eh_addr_size
;
4720 printf (_("Contents of the %s section:\n"), section
->name
);
4724 unsigned char *saved_start
;
4725 unsigned char *block_end
;
4726 unsigned long length
;
4727 unsigned long cie_id
;
4730 int need_col_headers
= 1;
4731 unsigned char *augmentation_data
= NULL
;
4732 unsigned long augmentation_data_len
= 0;
4733 int encoded_ptr_size
= saved_eh_addr_size
;
4735 int initial_length_size
;
4737 saved_start
= start
;
4738 length
= byte_get (start
, 4); start
+= 4;
4742 printf ("\n%08lx ZERO terminator\n\n",
4743 (unsigned long)(saved_start
- section_start
));
4747 if (length
== 0xffffffff)
4749 length
= byte_get (start
, 8);
4752 initial_length_size
= 12;
4757 initial_length_size
= 4;
4760 block_end
= saved_start
+ length
+ initial_length_size
;
4761 if (block_end
> end
)
4763 warn ("Invalid length %#08lx in FDE at %#08lx\n",
4764 length
, (unsigned long)(saved_start
- section_start
));
4767 cie_id
= byte_get (start
, offset_size
); start
+= offset_size
;
4769 if (is_eh
? (cie_id
== 0) : (cie_id
== DW_CIE_ID
))
4773 fc
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
4774 memset (fc
, 0, sizeof (Frame_Chunk
));
4778 fc
->chunk_start
= saved_start
;
4780 fc
->col_type
= (short int *) xmalloc (sizeof (short int));
4781 fc
->col_offset
= (int *) xmalloc (sizeof (int));
4782 frame_need_space (fc
, max_regs
- 1);
4786 fc
->augmentation
= (char *) start
;
4787 start
= (unsigned char *) strchr ((char *) start
, '\0') + 1;
4789 if (strcmp (fc
->augmentation
, "eh") == 0)
4790 start
+= eh_addr_size
;
4794 fc
->ptr_size
= GET (1);
4795 fc
->segment_size
= GET (1);
4796 eh_addr_size
= fc
->ptr_size
;
4800 fc
->ptr_size
= eh_addr_size
;
4801 fc
->segment_size
= 0;
4803 fc
->code_factor
= LEB ();
4804 fc
->data_factor
= SLEB ();
4814 if (fc
->augmentation
[0] == 'z')
4816 augmentation_data_len
= LEB ();
4817 augmentation_data
= start
;
4818 start
+= augmentation_data_len
;
4822 if (do_debug_frames_interp
)
4823 printf ("\n%08lx %08lx %08lx CIE \"%s\" cf=%d df=%d ra=%d\n",
4824 (unsigned long)(saved_start
- section_start
), length
, cie_id
,
4825 fc
->augmentation
, fc
->code_factor
, fc
->data_factor
,
4829 printf ("\n%08lx %08lx %08lx CIE\n",
4830 (unsigned long)(saved_start
- section_start
), length
, cie_id
);
4831 printf (" Version: %d\n", version
);
4832 printf (" Augmentation: \"%s\"\n", fc
->augmentation
);
4835 printf (" Pointer Size: %u\n", fc
->ptr_size
);
4836 printf (" Segment Size: %u\n", fc
->segment_size
);
4838 printf (" Code alignment factor: %u\n", fc
->code_factor
);
4839 printf (" Data alignment factor: %d\n", fc
->data_factor
);
4840 printf (" Return address column: %d\n", fc
->ra
);
4842 if (augmentation_data_len
)
4845 printf (" Augmentation data: ");
4846 for (i
= 0; i
< augmentation_data_len
; ++i
)
4847 printf (" %02x", augmentation_data
[i
]);
4853 if (augmentation_data_len
)
4855 unsigned char *p
, *q
;
4856 p
= (unsigned char *) fc
->augmentation
+ 1;
4857 q
= augmentation_data
;
4864 q
+= 1 + size_of_encoded_value (*q
);
4866 fc
->fde_encoding
= *q
++;
4874 if (fc
->fde_encoding
)
4875 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
4878 frame_need_space (fc
, fc
->ra
);
4882 unsigned char *look_for
;
4883 static Frame_Chunk fde_fc
;
4884 unsigned long segment_selector
;
4887 memset (fc
, 0, sizeof (Frame_Chunk
));
4889 look_for
= is_eh
? start
- 4 - cie_id
: section_start
+ cie_id
;
4891 for (cie
= chunks
; cie
; cie
= cie
->next
)
4892 if (cie
->chunk_start
== look_for
)
4897 warn ("Invalid CIE pointer %#08lx in FDE at %#08lx\n",
4898 cie_id
, (unsigned long)(saved_start
- section_start
));
4900 fc
->col_type
= (short int *) xmalloc (sizeof (short int));
4901 fc
->col_offset
= (int *) xmalloc (sizeof (int));
4902 frame_need_space (fc
, max_regs
- 1);
4904 fc
->augmentation
= "";
4905 fc
->fde_encoding
= 0;
4906 fc
->ptr_size
= eh_addr_size
;
4907 fc
->segment_size
= 0;
4911 fc
->ncols
= cie
->ncols
;
4912 fc
->col_type
= (short int *) xcmalloc (fc
->ncols
, sizeof (short int));
4913 fc
->col_offset
= (int *) xcmalloc (fc
->ncols
, sizeof (int));
4914 memcpy (fc
->col_type
, cie
->col_type
, fc
->ncols
* sizeof (short int));
4915 memcpy (fc
->col_offset
, cie
->col_offset
, fc
->ncols
* sizeof (int));
4916 fc
->augmentation
= cie
->augmentation
;
4917 fc
->ptr_size
= cie
->ptr_size
;
4918 eh_addr_size
= cie
->ptr_size
;
4919 fc
->segment_size
= cie
->segment_size
;
4920 fc
->code_factor
= cie
->code_factor
;
4921 fc
->data_factor
= cie
->data_factor
;
4922 fc
->cfa_reg
= cie
->cfa_reg
;
4923 fc
->cfa_offset
= cie
->cfa_offset
;
4925 frame_need_space (fc
, max_regs
- 1);
4926 fc
->fde_encoding
= cie
->fde_encoding
;
4929 if (fc
->fde_encoding
)
4930 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
4932 segment_selector
= 0;
4933 if (fc
->segment_size
)
4935 segment_selector
= byte_get (start
, fc
->segment_size
);
4936 start
+= fc
->segment_size
;
4938 fc
->pc_begin
= get_encoded_value (start
, fc
->fde_encoding
, section
);
4939 start
+= encoded_ptr_size
;
4940 fc
->pc_range
= byte_get (start
, encoded_ptr_size
);
4941 start
+= encoded_ptr_size
;
4943 if (cie
->augmentation
[0] == 'z')
4945 augmentation_data_len
= LEB ();
4946 augmentation_data
= start
;
4947 start
+= augmentation_data_len
;
4950 printf ("\n%08lx %08lx %08lx FDE cie=%08lx pc=",
4951 (unsigned long)(saved_start
- section_start
), length
, cie_id
,
4952 (unsigned long)(cie
->chunk_start
- section_start
));
4953 if (fc
->segment_size
)
4954 printf ("%04lx:", segment_selector
);
4955 printf ("%08lx..%08lx\n", fc
->pc_begin
, fc
->pc_begin
+ fc
->pc_range
);
4956 if (! do_debug_frames_interp
&& augmentation_data_len
)
4960 printf (" Augmentation data: ");
4961 for (i
= 0; i
< augmentation_data_len
; ++i
)
4962 printf (" %02x", augmentation_data
[i
]);
4968 /* At this point, fc is the current chunk, cie (if any) is set, and
4969 we're about to interpret instructions for the chunk. */
4970 /* ??? At present we need to do this always, since this sizes the
4971 fc->col_type and fc->col_offset arrays, which we write into always.
4972 We should probably split the interpreted and non-interpreted bits
4973 into two different routines, since there's so much that doesn't
4974 really overlap between them. */
4975 if (1 || do_debug_frames_interp
)
4977 /* Start by making a pass over the chunk, allocating storage
4978 and taking note of what registers are used. */
4979 unsigned char *tmp
= start
;
4981 while (start
< block_end
)
4984 unsigned long reg
, temp
;
4991 /* Warning: if you add any more cases to this switch, be
4992 sure to add them to the corresponding switch below. */
4995 case DW_CFA_advance_loc
:
4999 if (frame_need_space (fc
, opa
) >= 0)
5000 fc
->col_type
[opa
] = DW_CFA_undefined
;
5002 case DW_CFA_restore
:
5003 if (frame_need_space (fc
, opa
) >= 0)
5004 fc
->col_type
[opa
] = DW_CFA_undefined
;
5006 case DW_CFA_set_loc
:
5007 start
+= encoded_ptr_size
;
5009 case DW_CFA_advance_loc1
:
5012 case DW_CFA_advance_loc2
:
5015 case DW_CFA_advance_loc4
:
5018 case DW_CFA_offset_extended
:
5019 case DW_CFA_val_offset
:
5020 reg
= LEB (); LEB ();
5021 if (frame_need_space (fc
, reg
) >= 0)
5022 fc
->col_type
[reg
] = DW_CFA_undefined
;
5024 case DW_CFA_restore_extended
:
5026 frame_need_space (fc
, reg
);
5027 if (frame_need_space (fc
, reg
) >= 0)
5028 fc
->col_type
[reg
] = DW_CFA_undefined
;
5030 case DW_CFA_undefined
:
5032 if (frame_need_space (fc
, reg
) >= 0)
5033 fc
->col_type
[reg
] = DW_CFA_undefined
;
5035 case DW_CFA_same_value
:
5037 if (frame_need_space (fc
, reg
) >= 0)
5038 fc
->col_type
[reg
] = DW_CFA_undefined
;
5040 case DW_CFA_register
:
5041 reg
= LEB (); LEB ();
5042 if (frame_need_space (fc
, reg
) >= 0)
5043 fc
->col_type
[reg
] = DW_CFA_undefined
;
5045 case DW_CFA_def_cfa
:
5048 case DW_CFA_def_cfa_register
:
5051 case DW_CFA_def_cfa_offset
:
5054 case DW_CFA_def_cfa_expression
:
5058 case DW_CFA_expression
:
5059 case DW_CFA_val_expression
:
5063 if (frame_need_space (fc
, reg
) >= 0)
5064 fc
->col_type
[reg
] = DW_CFA_undefined
;
5066 case DW_CFA_offset_extended_sf
:
5067 case DW_CFA_val_offset_sf
:
5068 reg
= LEB (); SLEB ();
5069 if (frame_need_space (fc
, reg
) >= 0)
5070 fc
->col_type
[reg
] = DW_CFA_undefined
;
5072 case DW_CFA_def_cfa_sf
:
5075 case DW_CFA_def_cfa_offset_sf
:
5078 case DW_CFA_MIPS_advance_loc8
:
5081 case DW_CFA_GNU_args_size
:
5084 case DW_CFA_GNU_negative_offset_extended
:
5085 reg
= LEB (); LEB ();
5086 if (frame_need_space (fc
, reg
) >= 0)
5087 fc
->col_type
[reg
] = DW_CFA_undefined
;
5096 /* Now we know what registers are used, make a second pass over
5097 the chunk, this time actually printing out the info. */
5099 while (start
< block_end
)
5102 unsigned long ul
, reg
, roffs
;
5105 const char *reg_prefix
= "";
5112 /* Warning: if you add any more cases to this switch, be
5113 sure to add them to the corresponding switch above. */
5116 case DW_CFA_advance_loc
:
5117 if (do_debug_frames_interp
)
5118 frame_display_row (fc
, &need_col_headers
, &max_regs
);
5120 printf (" DW_CFA_advance_loc: %d to %08lx\n",
5121 opa
* fc
->code_factor
,
5122 fc
->pc_begin
+ opa
* fc
->code_factor
);
5123 fc
->pc_begin
+= opa
* fc
->code_factor
;
5128 if (opa
>= (unsigned int) fc
->ncols
)
5129 reg_prefix
= bad_reg
;
5130 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
5131 printf (" DW_CFA_offset: %s%s at cfa%+ld\n",
5132 reg_prefix
, regname (opa
, 0),
5133 roffs
* fc
->data_factor
);
5134 if (*reg_prefix
== '\0')
5136 fc
->col_type
[opa
] = DW_CFA_offset
;
5137 fc
->col_offset
[opa
] = roffs
* fc
->data_factor
;
5141 case DW_CFA_restore
:
5142 if (opa
>= (unsigned int) cie
->ncols
5143 || opa
>= (unsigned int) fc
->ncols
)
5144 reg_prefix
= bad_reg
;
5145 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
5146 printf (" DW_CFA_restore: %s%s\n",
5147 reg_prefix
, regname (opa
, 0));
5148 if (*reg_prefix
== '\0')
5150 fc
->col_type
[opa
] = cie
->col_type
[opa
];
5151 fc
->col_offset
[opa
] = cie
->col_offset
[opa
];
5152 if (do_debug_frames_interp
5153 && fc
->col_type
[opa
] == DW_CFA_unreferenced
)
5154 fc
->col_type
[opa
] = DW_CFA_undefined
;
5158 case DW_CFA_set_loc
:
5159 vma
= get_encoded_value (start
, fc
->fde_encoding
, section
);
5160 start
+= encoded_ptr_size
;
5161 if (do_debug_frames_interp
)
5162 frame_display_row (fc
, &need_col_headers
, &max_regs
);
5164 printf (" DW_CFA_set_loc: %08lx\n", (unsigned long)vma
);
5168 case DW_CFA_advance_loc1
:
5169 ofs
= byte_get (start
, 1); start
+= 1;
5170 if (do_debug_frames_interp
)
5171 frame_display_row (fc
, &need_col_headers
, &max_regs
);
5173 printf (" DW_CFA_advance_loc1: %ld to %08lx\n",
5174 ofs
* fc
->code_factor
,
5175 fc
->pc_begin
+ ofs
* fc
->code_factor
);
5176 fc
->pc_begin
+= ofs
* fc
->code_factor
;
5179 case DW_CFA_advance_loc2
:
5180 ofs
= byte_get (start
, 2); start
+= 2;
5181 if (do_debug_frames_interp
)
5182 frame_display_row (fc
, &need_col_headers
, &max_regs
);
5184 printf (" DW_CFA_advance_loc2: %ld to %08lx\n",
5185 ofs
* fc
->code_factor
,
5186 fc
->pc_begin
+ ofs
* fc
->code_factor
);
5187 fc
->pc_begin
+= ofs
* fc
->code_factor
;
5190 case DW_CFA_advance_loc4
:
5191 ofs
= byte_get (start
, 4); start
+= 4;
5192 if (do_debug_frames_interp
)
5193 frame_display_row (fc
, &need_col_headers
, &max_regs
);
5195 printf (" DW_CFA_advance_loc4: %ld to %08lx\n",
5196 ofs
* fc
->code_factor
,
5197 fc
->pc_begin
+ ofs
* fc
->code_factor
);
5198 fc
->pc_begin
+= ofs
* fc
->code_factor
;
5201 case DW_CFA_offset_extended
:
5204 if (reg
>= (unsigned int) fc
->ncols
)
5205 reg_prefix
= bad_reg
;
5206 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
5207 printf (" DW_CFA_offset_extended: %s%s at cfa%+ld\n",
5208 reg_prefix
, regname (reg
, 0),
5209 roffs
* fc
->data_factor
);
5210 if (*reg_prefix
== '\0')
5212 fc
->col_type
[reg
] = DW_CFA_offset
;
5213 fc
->col_offset
[reg
] = roffs
* fc
->data_factor
;
5217 case DW_CFA_val_offset
:
5220 if (reg
>= (unsigned int) fc
->ncols
)
5221 reg_prefix
= bad_reg
;
5222 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
5223 printf (" DW_CFA_val_offset: %s%s at cfa%+ld\n",
5224 reg_prefix
, regname (reg
, 0),
5225 roffs
* fc
->data_factor
);
5226 if (*reg_prefix
== '\0')
5228 fc
->col_type
[reg
] = DW_CFA_val_offset
;
5229 fc
->col_offset
[reg
] = roffs
* fc
->data_factor
;
5233 case DW_CFA_restore_extended
:
5235 if (reg
>= (unsigned int) cie
->ncols
5236 || reg
>= (unsigned int) fc
->ncols
)
5237 reg_prefix
= bad_reg
;
5238 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
5239 printf (" DW_CFA_restore_extended: %s%s\n",
5240 reg_prefix
, regname (reg
, 0));
5241 if (*reg_prefix
== '\0')
5243 fc
->col_type
[reg
] = cie
->col_type
[reg
];
5244 fc
->col_offset
[reg
] = cie
->col_offset
[reg
];
5248 case DW_CFA_undefined
:
5250 if (reg
>= (unsigned int) fc
->ncols
)
5251 reg_prefix
= bad_reg
;
5252 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
5253 printf (" DW_CFA_undefined: %s%s\n",
5254 reg_prefix
, regname (reg
, 0));
5255 if (*reg_prefix
== '\0')
5257 fc
->col_type
[reg
] = DW_CFA_undefined
;
5258 fc
->col_offset
[reg
] = 0;
5262 case DW_CFA_same_value
:
5264 if (reg
>= (unsigned int) fc
->ncols
)
5265 reg_prefix
= bad_reg
;
5266 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
5267 printf (" DW_CFA_same_value: %s%s\n",
5268 reg_prefix
, regname (reg
, 0));
5269 if (*reg_prefix
== '\0')
5271 fc
->col_type
[reg
] = DW_CFA_same_value
;
5272 fc
->col_offset
[reg
] = 0;
5276 case DW_CFA_register
:
5279 if (reg
>= (unsigned int) fc
->ncols
)
5280 reg_prefix
= bad_reg
;
5281 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
5283 printf (" DW_CFA_register: %s%s in ",
5284 reg_prefix
, regname (reg
, 0));
5285 puts (regname (roffs
, 0));
5287 if (*reg_prefix
== '\0')
5289 fc
->col_type
[reg
] = DW_CFA_register
;
5290 fc
->col_offset
[reg
] = roffs
;
5294 case DW_CFA_remember_state
:
5295 if (! do_debug_frames_interp
)
5296 printf (" DW_CFA_remember_state\n");
5297 rs
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
5298 rs
->ncols
= fc
->ncols
;
5299 rs
->col_type
= (short int *) xcmalloc (rs
->ncols
,
5300 sizeof (short int));
5301 rs
->col_offset
= (int *) xcmalloc (rs
->ncols
, sizeof (int));
5302 memcpy (rs
->col_type
, fc
->col_type
, rs
->ncols
);
5303 memcpy (rs
->col_offset
, fc
->col_offset
, rs
->ncols
* sizeof (int));
5304 rs
->next
= remembered_state
;
5305 remembered_state
= rs
;
5308 case DW_CFA_restore_state
:
5309 if (! do_debug_frames_interp
)
5310 printf (" DW_CFA_restore_state\n");
5311 rs
= remembered_state
;
5314 remembered_state
= rs
->next
;
5315 frame_need_space (fc
, rs
->ncols
- 1);
5316 memcpy (fc
->col_type
, rs
->col_type
, rs
->ncols
);
5317 memcpy (fc
->col_offset
, rs
->col_offset
,
5318 rs
->ncols
* sizeof (int));
5319 free (rs
->col_type
);
5320 free (rs
->col_offset
);
5323 else if (do_debug_frames_interp
)
5324 printf ("Mismatched DW_CFA_restore_state\n");
5327 case DW_CFA_def_cfa
:
5328 fc
->cfa_reg
= LEB ();
5329 fc
->cfa_offset
= LEB ();
5331 if (! do_debug_frames_interp
)
5332 printf (" DW_CFA_def_cfa: %s ofs %d\n",
5333 regname (fc
->cfa_reg
, 0), fc
->cfa_offset
);
5336 case DW_CFA_def_cfa_register
:
5337 fc
->cfa_reg
= LEB ();
5339 if (! do_debug_frames_interp
)
5340 printf (" DW_CFA_def_cfa_register: %s\n",
5341 regname (fc
->cfa_reg
, 0));
5344 case DW_CFA_def_cfa_offset
:
5345 fc
->cfa_offset
= LEB ();
5346 if (! do_debug_frames_interp
)
5347 printf (" DW_CFA_def_cfa_offset: %d\n", fc
->cfa_offset
);
5351 if (! do_debug_frames_interp
)
5352 printf (" DW_CFA_nop\n");
5355 case DW_CFA_def_cfa_expression
:
5357 if (! do_debug_frames_interp
)
5359 printf (" DW_CFA_def_cfa_expression (");
5360 decode_location_expression (start
, eh_addr_size
, 0, -1,
5368 case DW_CFA_expression
:
5371 if (reg
>= (unsigned int) fc
->ncols
)
5372 reg_prefix
= bad_reg
;
5373 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
5375 printf (" DW_CFA_expression: %s%s (",
5376 reg_prefix
, regname (reg
, 0));
5377 decode_location_expression (start
, eh_addr_size
, 0, -1,
5381 if (*reg_prefix
== '\0')
5382 fc
->col_type
[reg
] = DW_CFA_expression
;
5386 case DW_CFA_val_expression
:
5389 if (reg
>= (unsigned int) fc
->ncols
)
5390 reg_prefix
= bad_reg
;
5391 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
5393 printf (" DW_CFA_val_expression: %s%s (",
5394 reg_prefix
, regname (reg
, 0));
5395 decode_location_expression (start
, eh_addr_size
, 0, -1,
5399 if (*reg_prefix
== '\0')
5400 fc
->col_type
[reg
] = DW_CFA_val_expression
;
5404 case DW_CFA_offset_extended_sf
:
5407 if (frame_need_space (fc
, reg
) < 0)
5408 reg_prefix
= bad_reg
;
5409 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
5410 printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+ld\n",
5411 reg_prefix
, regname (reg
, 0),
5412 l
* fc
->data_factor
);
5413 if (*reg_prefix
== '\0')
5415 fc
->col_type
[reg
] = DW_CFA_offset
;
5416 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
5420 case DW_CFA_val_offset_sf
:
5423 if (frame_need_space (fc
, reg
) < 0)
5424 reg_prefix
= bad_reg
;
5425 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
5426 printf (" DW_CFA_val_offset_sf: %s%s at cfa%+ld\n",
5427 reg_prefix
, regname (reg
, 0),
5428 l
* fc
->data_factor
);
5429 if (*reg_prefix
== '\0')
5431 fc
->col_type
[reg
] = DW_CFA_val_offset
;
5432 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
5436 case DW_CFA_def_cfa_sf
:
5437 fc
->cfa_reg
= LEB ();
5438 fc
->cfa_offset
= SLEB ();
5439 fc
->cfa_offset
= fc
->cfa_offset
* fc
->data_factor
;
5441 if (! do_debug_frames_interp
)
5442 printf (" DW_CFA_def_cfa_sf: %s ofs %d\n",
5443 regname (fc
->cfa_reg
, 0), fc
->cfa_offset
);
5446 case DW_CFA_def_cfa_offset_sf
:
5447 fc
->cfa_offset
= SLEB ();
5448 fc
->cfa_offset
= fc
->cfa_offset
* fc
->data_factor
;
5449 if (! do_debug_frames_interp
)
5450 printf (" DW_CFA_def_cfa_offset_sf: %d\n", fc
->cfa_offset
);
5453 case DW_CFA_MIPS_advance_loc8
:
5454 ofs
= byte_get (start
, 8); start
+= 8;
5455 if (do_debug_frames_interp
)
5456 frame_display_row (fc
, &need_col_headers
, &max_regs
);
5458 printf (" DW_CFA_MIPS_advance_loc8: %ld to %08lx\n",
5459 ofs
* fc
->code_factor
,
5460 fc
->pc_begin
+ ofs
* fc
->code_factor
);
5461 fc
->pc_begin
+= ofs
* fc
->code_factor
;
5464 case DW_CFA_GNU_window_save
:
5465 if (! do_debug_frames_interp
)
5466 printf (" DW_CFA_GNU_window_save\n");
5469 case DW_CFA_GNU_args_size
:
5471 if (! do_debug_frames_interp
)
5472 printf (" DW_CFA_GNU_args_size: %ld\n", ul
);
5475 case DW_CFA_GNU_negative_offset_extended
:
5478 if (frame_need_space (fc
, reg
) < 0)
5479 reg_prefix
= bad_reg
;
5480 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
5481 printf (" DW_CFA_GNU_negative_offset_extended: %s%s at cfa%+ld\n",
5482 reg_prefix
, regname (reg
, 0),
5483 l
* fc
->data_factor
);
5484 if (*reg_prefix
== '\0')
5486 fc
->col_type
[reg
] = DW_CFA_offset
;
5487 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
5492 if (op
>= DW_CFA_lo_user
&& op
<= DW_CFA_hi_user
)
5493 printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op
);
5495 warn (_("unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op
);
5500 if (do_debug_frames_interp
)
5501 frame_display_row (fc
, &need_col_headers
, &max_regs
);
5504 eh_addr_size
= saved_eh_addr_size
;
5517 display_gdb_index (struct dwarf_section
*section
,
5518 void *file ATTRIBUTE_UNUSED
)
5520 unsigned char *start
= section
->start
;
5522 uint32_t cu_list_offset
, tu_list_offset
;
5523 uint32_t address_table_offset
, symbol_table_offset
, constant_pool_offset
;
5524 unsigned int cu_list_elements
, tu_list_elements
;
5525 unsigned int address_table_size
, symbol_table_slots
;
5526 unsigned char *cu_list
, *tu_list
;
5527 unsigned char *address_table
, *symbol_table
, *constant_pool
;
5530 /* The documentation for the format of this file is in gdb/dwarf2read.c. */
5532 printf (_("Contents of the %s section:\n"), section
->name
);
5534 if (section
->size
< 6 * sizeof (uint32_t))
5536 warn (_("Truncated header in the %s section.\n"), section
->name
);
5540 version
= byte_get_little_endian (start
, 4);
5541 printf (_("Version %ld\n"), (long) version
);
5543 /* Prior versions are obsolete, and future versions may not be
5544 backwards compatible. */
5548 warn (_("The address table data in version 3 may be wrong.\n"));
5551 warn (_("Version 4 does not support case insensitive lookups.\n"));
5556 warn (_("Unsupported version %lu.\n"), (unsigned long) version
);
5560 cu_list_offset
= byte_get_little_endian (start
+ 4, 4);
5561 tu_list_offset
= byte_get_little_endian (start
+ 8, 4);
5562 address_table_offset
= byte_get_little_endian (start
+ 12, 4);
5563 symbol_table_offset
= byte_get_little_endian (start
+ 16, 4);
5564 constant_pool_offset
= byte_get_little_endian (start
+ 20, 4);
5566 if (cu_list_offset
> section
->size
5567 || tu_list_offset
> section
->size
5568 || address_table_offset
> section
->size
5569 || symbol_table_offset
> section
->size
5570 || constant_pool_offset
> section
->size
)
5572 warn (_("Corrupt header in the %s section.\n"), section
->name
);
5576 cu_list_elements
= (tu_list_offset
- cu_list_offset
) / 8;
5577 tu_list_elements
= (address_table_offset
- tu_list_offset
) / 8;
5578 address_table_size
= symbol_table_offset
- address_table_offset
;
5579 symbol_table_slots
= (constant_pool_offset
- symbol_table_offset
) / 8;
5581 cu_list
= start
+ cu_list_offset
;
5582 tu_list
= start
+ tu_list_offset
;
5583 address_table
= start
+ address_table_offset
;
5584 symbol_table
= start
+ symbol_table_offset
;
5585 constant_pool
= start
+ constant_pool_offset
;
5587 printf (_("\nCU table:\n"));
5588 for (i
= 0; i
< cu_list_elements
; i
+= 2)
5590 uint64_t cu_offset
= byte_get_little_endian (cu_list
+ i
* 8, 8);
5591 uint64_t cu_length
= byte_get_little_endian (cu_list
+ i
* 8 + 8, 8);
5593 printf (_("[%3u] 0x%lx - 0x%lx\n"), i
/ 2,
5594 (unsigned long) cu_offset
,
5595 (unsigned long) (cu_offset
+ cu_length
- 1));
5598 printf (_("\nTU table:\n"));
5599 for (i
= 0; i
< tu_list_elements
; i
+= 3)
5601 uint64_t tu_offset
= byte_get_little_endian (tu_list
+ i
* 8, 8);
5602 uint64_t type_offset
= byte_get_little_endian (tu_list
+ i
* 8 + 8, 8);
5603 uint64_t signature
= byte_get_little_endian (tu_list
+ i
* 8 + 16, 8);
5605 printf (_("[%3u] 0x%lx 0x%lx "), i
/ 3,
5606 (unsigned long) tu_offset
,
5607 (unsigned long) type_offset
);
5608 print_dwarf_vma (signature
, 8);
5612 printf (_("\nAddress table:\n"));
5613 for (i
= 0; i
< address_table_size
; i
+= 2 * 8 + 4)
5615 uint64_t low
= byte_get_little_endian (address_table
+ i
, 8);
5616 uint64_t high
= byte_get_little_endian (address_table
+ i
+ 8, 8);
5617 uint32_t cu_index
= byte_get_little_endian (address_table
+ i
+ 16, 4);
5619 print_dwarf_vma (low
, 8);
5620 print_dwarf_vma (high
, 8);
5621 printf (_("%lu\n"), (unsigned long) cu_index
);
5624 printf (_("\nSymbol table:\n"));
5625 for (i
= 0; i
< symbol_table_slots
; ++i
)
5627 uint32_t name_offset
= byte_get_little_endian (symbol_table
+ i
* 8, 4);
5628 uint32_t cu_vector_offset
= byte_get_little_endian (symbol_table
+ i
* 8 + 4, 4);
5629 uint32_t num_cus
, cu
;
5631 if (name_offset
!= 0
5632 || cu_vector_offset
!= 0)
5636 printf ("[%3u] %s:", i
, constant_pool
+ name_offset
);
5637 num_cus
= byte_get_little_endian (constant_pool
+ cu_vector_offset
, 4);
5638 for (j
= 0; j
< num_cus
; ++j
)
5640 cu
= byte_get_little_endian (constant_pool
+ cu_vector_offset
+ 4 + j
* 4, 4);
5641 /* Convert to TU number if it's for a type unit. */
5642 if (cu
>= cu_list_elements
/ 2)
5643 printf (" T%lu", (unsigned long) (cu
- cu_list_elements
/ 2));
5645 printf (" %lu", (unsigned long) cu
);
5655 display_debug_not_supported (struct dwarf_section
*section
,
5656 void *file ATTRIBUTE_UNUSED
)
5658 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
5665 cmalloc (size_t nmemb
, size_t size
)
5667 /* Check for overflow. */
5668 if (nmemb
>= ~(size_t) 0 / size
)
5671 return malloc (nmemb
* size
);
5675 xcmalloc (size_t nmemb
, size_t size
)
5677 /* Check for overflow. */
5678 if (nmemb
>= ~(size_t) 0 / size
)
5681 return xmalloc (nmemb
* size
);
5685 xcrealloc (void *ptr
, size_t nmemb
, size_t size
)
5687 /* Check for overflow. */
5688 if (nmemb
>= ~(size_t) 0 / size
)
5691 return xrealloc (ptr
, nmemb
* size
);
5695 free_debug_memory (void)
5701 for (i
= 0; i
< max
; i
++)
5702 free_debug_section ((enum dwarf_section_display_enum
) i
);
5704 if (debug_information
!= NULL
)
5706 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
)
5708 for (i
= 0; i
< num_debug_info_entries
; i
++)
5710 if (!debug_information
[i
].max_loc_offsets
)
5712 free (debug_information
[i
].loc_offsets
);
5713 free (debug_information
[i
].have_frame_base
);
5715 if (!debug_information
[i
].max_range_lists
)
5716 free (debug_information
[i
].range_lists
);
5720 free (debug_information
);
5721 debug_information
= NULL
;
5722 num_debug_info_entries
= 0;
5727 dwarf_select_sections_by_names (const char *names
)
5731 const char * option
;
5735 debug_dump_long_opts
;
5737 static const debug_dump_long_opts opts_table
[] =
5739 /* Please keep this table alpha- sorted. */
5740 { "Ranges", & do_debug_ranges
, 1 },
5741 { "abbrev", & do_debug_abbrevs
, 1 },
5742 { "aranges", & do_debug_aranges
, 1 },
5743 { "frames", & do_debug_frames
, 1 },
5744 { "frames-interp", & do_debug_frames_interp
, 1 },
5745 { "info", & do_debug_info
, 1 },
5746 { "line", & do_debug_lines
, FLAG_DEBUG_LINES_RAW
}, /* For backwards compatibility. */
5747 { "rawline", & do_debug_lines
, FLAG_DEBUG_LINES_RAW
},
5748 { "decodedline", & do_debug_lines
, FLAG_DEBUG_LINES_DECODED
},
5749 { "loc", & do_debug_loc
, 1 },
5750 { "macro", & do_debug_macinfo
, 1 },
5751 { "pubnames", & do_debug_pubnames
, 1 },
5752 { "pubtypes", & do_debug_pubtypes
, 1 },
5753 /* This entry is for compatability
5754 with earlier versions of readelf. */
5755 { "ranges", & do_debug_aranges
, 1 },
5756 { "str", & do_debug_str
, 1 },
5757 /* The special .gdb_index section. */
5758 { "gdb_index", & do_gdb_index
, 1 },
5759 /* These trace_* sections are used by Itanium VMS. */
5760 { "trace_abbrev", & do_trace_abbrevs
, 1 },
5761 { "trace_aranges", & do_trace_aranges
, 1 },
5762 { "trace_info", & do_trace_info
, 1 },
5771 const debug_dump_long_opts
* entry
;
5773 for (entry
= opts_table
; entry
->option
; entry
++)
5775 size_t len
= strlen (entry
->option
);
5777 if (strncmp (p
, entry
->option
, len
) == 0
5778 && (p
[len
] == ',' || p
[len
] == '\0'))
5780 * entry
->variable
|= entry
->val
;
5782 /* The --debug-dump=frames-interp option also
5783 enables the --debug-dump=frames option. */
5784 if (do_debug_frames_interp
)
5785 do_debug_frames
= 1;
5792 if (entry
->option
== NULL
)
5794 warn (_("Unrecognized debug option '%s'\n"), p
);
5795 p
= strchr (p
, ',');
5806 dwarf_select_sections_by_letters (const char *letters
)
5808 unsigned int lindex
= 0;
5810 while (letters
[lindex
])
5811 switch (letters
[lindex
++])
5818 do_debug_abbrevs
= 1;
5822 do_debug_lines
|= FLAG_DEBUG_LINES_RAW
;
5826 do_debug_lines
|= FLAG_DEBUG_LINES_DECODED
;
5830 do_debug_pubnames
= 1;
5834 do_debug_pubtypes
= 1;
5838 do_debug_aranges
= 1;
5842 do_debug_ranges
= 1;
5846 do_debug_frames_interp
= 1;
5848 do_debug_frames
= 1;
5852 do_debug_macinfo
= 1;
5864 warn (_("Unrecognized debug option '%s'\n"), optarg
);
5870 dwarf_select_sections_all (void)
5873 do_debug_abbrevs
= 1;
5874 do_debug_lines
= FLAG_DEBUG_LINES_RAW
;
5875 do_debug_pubnames
= 1;
5876 do_debug_pubtypes
= 1;
5877 do_debug_aranges
= 1;
5878 do_debug_ranges
= 1;
5879 do_debug_frames
= 1;
5880 do_debug_macinfo
= 1;
5885 do_trace_abbrevs
= 1;
5886 do_trace_aranges
= 1;
5889 struct dwarf_section_display debug_displays
[] =
5891 { { ".debug_abbrev", ".zdebug_abbrev", NULL
, NULL
, 0, 0 },
5892 display_debug_abbrev
, &do_debug_abbrevs
, 0 },
5893 { { ".debug_aranges", ".zdebug_aranges", NULL
, NULL
, 0, 0 },
5894 display_debug_aranges
, &do_debug_aranges
, 1 },
5895 { { ".debug_frame", ".zdebug_frame", NULL
, NULL
, 0, 0 },
5896 display_debug_frames
, &do_debug_frames
, 1 },
5897 { { ".debug_info", ".zdebug_info", NULL
, NULL
, 0, 0 },
5898 display_debug_info
, &do_debug_info
, 1 },
5899 { { ".debug_line", ".zdebug_line", NULL
, NULL
, 0, 0 },
5900 display_debug_lines
, &do_debug_lines
, 1 },
5901 { { ".debug_pubnames", ".zdebug_pubnames", NULL
, NULL
, 0, 0 },
5902 display_debug_pubnames
, &do_debug_pubnames
, 0 },
5903 { { ".eh_frame", "", NULL
, NULL
, 0, 0 },
5904 display_debug_frames
, &do_debug_frames
, 1 },
5905 { { ".debug_macinfo", ".zdebug_macinfo", NULL
, NULL
, 0, 0 },
5906 display_debug_macinfo
, &do_debug_macinfo
, 0 },
5907 { { ".debug_macro", ".zdebug_macro", NULL
, NULL
, 0, 0 },
5908 display_debug_macro
, &do_debug_macinfo
, 1 },
5909 { { ".debug_str", ".zdebug_str", NULL
, NULL
, 0, 0 },
5910 display_debug_str
, &do_debug_str
, 0 },
5911 { { ".debug_loc", ".zdebug_loc", NULL
, NULL
, 0, 0 },
5912 display_debug_loc
, &do_debug_loc
, 1 },
5913 { { ".debug_pubtypes", ".zdebug_pubtypes", NULL
, NULL
, 0, 0 },
5914 display_debug_pubnames
, &do_debug_pubtypes
, 0 },
5915 { { ".debug_ranges", ".zdebug_ranges", NULL
, NULL
, 0, 0 },
5916 display_debug_ranges
, &do_debug_ranges
, 1 },
5917 { { ".debug_static_func", ".zdebug_static_func", NULL
, NULL
, 0, 0 },
5918 display_debug_not_supported
, NULL
, 0 },
5919 { { ".debug_static_vars", ".zdebug_static_vars", NULL
, NULL
, 0, 0 },
5920 display_debug_not_supported
, NULL
, 0 },
5921 { { ".debug_types", ".zdebug_types", NULL
, NULL
, 0, 0 },
5922 display_debug_types
, &do_debug_info
, 1 },
5923 { { ".debug_weaknames", ".zdebug_weaknames", NULL
, NULL
, 0, 0 },
5924 display_debug_not_supported
, NULL
, 0 },
5925 { { ".gdb_index", "", NULL
, NULL
, 0, 0 },
5926 display_gdb_index
, &do_gdb_index
, 0 },
5927 { { ".trace_info", "", NULL
, NULL
, 0, 0 },
5928 display_trace_info
, &do_trace_info
, 1 },
5929 { { ".trace_abbrev", "", NULL
, NULL
, 0, 0 },
5930 display_debug_abbrev
, &do_trace_abbrevs
, 0 },
5931 { { ".trace_aranges", "", NULL
, NULL
, 0, 0 },
5932 display_debug_aranges
, &do_trace_aranges
, 0 }