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
);
173 read_leb128 (unsigned char *data
, unsigned int *length_return
, int sign
)
175 dwarf_vma result
= 0;
176 unsigned int num_read
= 0;
177 unsigned int shift
= 0;
185 result
|= ((dwarf_vma
) (byte
& 0x7f)) << shift
;
192 if (length_return
!= NULL
)
193 *length_return
= num_read
;
195 if (sign
&& (shift
< 8 * sizeof (result
)) && (byte
& 0x40))
196 result
|= -1L << shift
;
201 /* Create a signed version to avoid painful typecasts. */
202 static dwarf_signed_vma
203 read_sleb128 (unsigned char *data
, unsigned int *length_return
)
205 return (dwarf_signed_vma
) read_leb128 (data
, length_return
, 1);
208 typedef struct State_Machine_Registers
216 unsigned char op_index
;
217 unsigned char end_sequence
;
218 /* This variable hold the number of the last entry seen
219 in the File Table. */
220 unsigned int last_file_entry
;
223 static SMR state_machine_regs
;
226 reset_state_machine (int is_stmt
)
228 state_machine_regs
.address
= 0;
229 state_machine_regs
.op_index
= 0;
230 state_machine_regs
.file
= 1;
231 state_machine_regs
.line
= 1;
232 state_machine_regs
.column
= 0;
233 state_machine_regs
.is_stmt
= is_stmt
;
234 state_machine_regs
.basic_block
= 0;
235 state_machine_regs
.end_sequence
= 0;
236 state_machine_regs
.last_file_entry
= 0;
239 /* Handled an extend line op.
240 Returns the number of bytes read. */
243 process_extended_line_op (unsigned char *data
, int is_stmt
)
245 unsigned char op_code
;
246 unsigned int bytes_read
;
250 unsigned char *orig_data
= data
;
252 len
= read_leb128 (data
, & bytes_read
, 0);
257 warn (_("badly formed extended line op encountered!\n"));
264 printf (_(" Extended opcode %d: "), op_code
);
268 case DW_LNE_end_sequence
:
269 printf (_("End of Sequence\n\n"));
270 reset_state_machine (is_stmt
);
273 case DW_LNE_set_address
:
274 adr
= byte_get (data
, len
- bytes_read
- 1);
275 printf (_("set Address to 0x%s\n"), dwarf_vmatoa ("x", adr
));
276 state_machine_regs
.address
= adr
;
277 state_machine_regs
.op_index
= 0;
280 case DW_LNE_define_file
:
281 printf (_("define new File Table entry\n"));
282 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
284 printf (" %d\t", ++state_machine_regs
.last_file_entry
);
286 data
+= strlen ((char *) data
) + 1;
287 printf ("%s\t", dwarf_vmatoa ("u", read_leb128 (data
, & bytes_read
, 0)));
289 printf ("%s\t", dwarf_vmatoa ("u", read_leb128 (data
, & bytes_read
, 0)));
291 printf ("%s\t", dwarf_vmatoa ("u", read_leb128 (data
, & bytes_read
, 0)));
294 if ((unsigned int) (data
- orig_data
) != len
)
295 printf (_(" [Bad opcode length]"));
299 case DW_LNE_set_discriminator
:
300 printf (_("set Discriminator to %s\n"),
301 dwarf_vmatoa ("u", read_leb128 (data
, & bytes_read
, 0)));
305 case DW_LNE_HP_negate_is_UV_update
:
306 printf ("DW_LNE_HP_negate_is_UV_update\n");
308 case DW_LNE_HP_push_context
:
309 printf ("DW_LNE_HP_push_context\n");
311 case DW_LNE_HP_pop_context
:
312 printf ("DW_LNE_HP_pop_context\n");
314 case DW_LNE_HP_set_file_line_column
:
315 printf ("DW_LNE_HP_set_file_line_column\n");
317 case DW_LNE_HP_set_routine_name
:
318 printf ("DW_LNE_HP_set_routine_name\n");
320 case DW_LNE_HP_set_sequence
:
321 printf ("DW_LNE_HP_set_sequence\n");
323 case DW_LNE_HP_negate_post_semantics
:
324 printf ("DW_LNE_HP_negate_post_semantics\n");
326 case DW_LNE_HP_negate_function_exit
:
327 printf ("DW_LNE_HP_negate_function_exit\n");
329 case DW_LNE_HP_negate_front_end_logical
:
330 printf ("DW_LNE_HP_negate_front_end_logical\n");
332 case DW_LNE_HP_define_proc
:
333 printf ("DW_LNE_HP_define_proc\n");
335 case DW_LNE_HP_source_file_correlation
:
337 unsigned char *edata
= data
+ len
- bytes_read
- 1;
339 printf ("DW_LNE_HP_source_file_correlation\n");
345 opc
= read_leb128 (data
, & bytes_read
, 0);
350 case DW_LNE_HP_SFC_formfeed
:
351 printf (" DW_LNE_HP_SFC_formfeed\n");
353 case DW_LNE_HP_SFC_set_listing_line
:
354 printf (" DW_LNE_HP_SFC_set_listing_line (%s)\n",
356 read_leb128 (data
, & bytes_read
, 0)));
359 case DW_LNE_HP_SFC_associate
:
360 printf (" DW_LNE_HP_SFC_associate ");
363 read_leb128 (data
, & bytes_read
, 0)));
367 read_leb128 (data
, & bytes_read
, 0)));
371 read_leb128 (data
, & bytes_read
, 0)));
375 printf (_(" UNKNOWN DW_LNE_HP_SFC opcode (%u)\n"), opc
);
385 unsigned int rlen
= len
- bytes_read
- 1;
387 if (op_code
>= DW_LNE_lo_user
388 /* The test against DW_LNW_hi_user is redundant due to
389 the limited range of the unsigned char data type used
391 /*&& op_code <= DW_LNE_hi_user*/)
392 printf (_("user defined: "));
394 printf (_("UNKNOWN: "));
395 printf (_("length %d ["), rlen
);
397 printf (" %02x", *data
++);
407 fetch_indirect_string (dwarf_vma offset
)
409 struct dwarf_section
*section
= &debug_displays
[str
].section
;
411 if (section
->start
== NULL
)
412 return _("<no .debug_str section>");
414 /* DWARF sections under Mach-O have non-zero addresses. */
415 offset
-= section
->address
;
416 if (offset
> section
->size
)
418 warn (_("DW_FORM_strp offset too big: %s\n"),
419 dwarf_vmatoa ("x", offset
));
420 return _("<offset is too big>");
423 return (const char *) section
->start
+ offset
;
426 /* FIXME: There are better and more efficient ways to handle
427 these structures. For now though, I just want something that
428 is simple to implement. */
429 typedef struct abbrev_attr
431 unsigned long attribute
;
433 struct abbrev_attr
*next
;
437 typedef struct abbrev_entry
442 struct abbrev_attr
*first_attr
;
443 struct abbrev_attr
*last_attr
;
444 struct abbrev_entry
*next
;
448 static abbrev_entry
*first_abbrev
= NULL
;
449 static abbrev_entry
*last_abbrev
= NULL
;
456 for (abbrv
= first_abbrev
; abbrv
;)
458 abbrev_entry
*next_abbrev
= abbrv
->next
;
461 for (attr
= abbrv
->first_attr
; attr
;)
463 abbrev_attr
*next_attr
= attr
->next
;
473 last_abbrev
= first_abbrev
= NULL
;
477 add_abbrev (unsigned long number
, unsigned long tag
, int children
)
481 entry
= (abbrev_entry
*) malloc (sizeof (*entry
));
486 entry
->entry
= number
;
488 entry
->children
= children
;
489 entry
->first_attr
= NULL
;
490 entry
->last_attr
= NULL
;
493 if (first_abbrev
== NULL
)
494 first_abbrev
= entry
;
496 last_abbrev
->next
= entry
;
502 add_abbrev_attr (unsigned long attribute
, unsigned long form
)
506 attr
= (abbrev_attr
*) malloc (sizeof (*attr
));
511 attr
->attribute
= attribute
;
515 if (last_abbrev
->first_attr
== NULL
)
516 last_abbrev
->first_attr
= attr
;
518 last_abbrev
->last_attr
->next
= attr
;
520 last_abbrev
->last_attr
= attr
;
523 /* Processes the (partial) contents of a .debug_abbrev section.
524 Returns NULL if the end of the section was encountered.
525 Returns the address after the last byte read if the end of
526 an abbreviation set was found. */
528 static unsigned char *
529 process_abbrev_section (unsigned char *start
, unsigned char *end
)
531 if (first_abbrev
!= NULL
)
536 unsigned int bytes_read
;
539 unsigned long attribute
;
542 entry
= read_leb128 (start
, & bytes_read
, 0);
545 /* A single zero is supposed to end the section according
546 to the standard. If there's more, then signal that to
549 return start
== end
? NULL
: start
;
551 tag
= read_leb128 (start
, & bytes_read
, 0);
556 add_abbrev (entry
, tag
, children
);
562 attribute
= read_leb128 (start
, & bytes_read
, 0);
565 form
= read_leb128 (start
, & bytes_read
, 0);
569 add_abbrev_attr (attribute
, form
);
571 while (attribute
!= 0);
578 get_TAG_name (unsigned long tag
)
582 case DW_TAG_padding
: return "DW_TAG_padding";
583 case DW_TAG_array_type
: return "DW_TAG_array_type";
584 case DW_TAG_class_type
: return "DW_TAG_class_type";
585 case DW_TAG_entry_point
: return "DW_TAG_entry_point";
586 case DW_TAG_enumeration_type
: return "DW_TAG_enumeration_type";
587 case DW_TAG_formal_parameter
: return "DW_TAG_formal_parameter";
588 case DW_TAG_imported_declaration
: return "DW_TAG_imported_declaration";
589 case DW_TAG_label
: return "DW_TAG_label";
590 case DW_TAG_lexical_block
: return "DW_TAG_lexical_block";
591 case DW_TAG_member
: return "DW_TAG_member";
592 case DW_TAG_pointer_type
: return "DW_TAG_pointer_type";
593 case DW_TAG_reference_type
: return "DW_TAG_reference_type";
594 case DW_TAG_compile_unit
: return "DW_TAG_compile_unit";
595 case DW_TAG_string_type
: return "DW_TAG_string_type";
596 case DW_TAG_structure_type
: return "DW_TAG_structure_type";
597 case DW_TAG_subroutine_type
: return "DW_TAG_subroutine_type";
598 case DW_TAG_typedef
: return "DW_TAG_typedef";
599 case DW_TAG_union_type
: return "DW_TAG_union_type";
600 case DW_TAG_unspecified_parameters
: return "DW_TAG_unspecified_parameters";
601 case DW_TAG_variant
: return "DW_TAG_variant";
602 case DW_TAG_common_block
: return "DW_TAG_common_block";
603 case DW_TAG_common_inclusion
: return "DW_TAG_common_inclusion";
604 case DW_TAG_inheritance
: return "DW_TAG_inheritance";
605 case DW_TAG_inlined_subroutine
: return "DW_TAG_inlined_subroutine";
606 case DW_TAG_module
: return "DW_TAG_module";
607 case DW_TAG_ptr_to_member_type
: return "DW_TAG_ptr_to_member_type";
608 case DW_TAG_set_type
: return "DW_TAG_set_type";
609 case DW_TAG_subrange_type
: return "DW_TAG_subrange_type";
610 case DW_TAG_with_stmt
: return "DW_TAG_with_stmt";
611 case DW_TAG_access_declaration
: return "DW_TAG_access_declaration";
612 case DW_TAG_base_type
: return "DW_TAG_base_type";
613 case DW_TAG_catch_block
: return "DW_TAG_catch_block";
614 case DW_TAG_const_type
: return "DW_TAG_const_type";
615 case DW_TAG_constant
: return "DW_TAG_constant";
616 case DW_TAG_enumerator
: return "DW_TAG_enumerator";
617 case DW_TAG_file_type
: return "DW_TAG_file_type";
618 case DW_TAG_friend
: return "DW_TAG_friend";
619 case DW_TAG_namelist
: return "DW_TAG_namelist";
620 case DW_TAG_namelist_item
: return "DW_TAG_namelist_item";
621 case DW_TAG_packed_type
: return "DW_TAG_packed_type";
622 case DW_TAG_subprogram
: return "DW_TAG_subprogram";
623 case DW_TAG_template_type_param
: return "DW_TAG_template_type_param";
624 case DW_TAG_template_value_param
: return "DW_TAG_template_value_param";
625 case DW_TAG_thrown_type
: return "DW_TAG_thrown_type";
626 case DW_TAG_try_block
: return "DW_TAG_try_block";
627 case DW_TAG_variant_part
: return "DW_TAG_variant_part";
628 case DW_TAG_variable
: return "DW_TAG_variable";
629 case DW_TAG_volatile_type
: return "DW_TAG_volatile_type";
630 case DW_TAG_MIPS_loop
: return "DW_TAG_MIPS_loop";
631 case DW_TAG_format_label
: return "DW_TAG_format_label";
632 case DW_TAG_function_template
: return "DW_TAG_function_template";
633 case DW_TAG_class_template
: return "DW_TAG_class_template";
634 /* DWARF 2.1 values. */
635 case DW_TAG_dwarf_procedure
: return "DW_TAG_dwarf_procedure";
636 case DW_TAG_restrict_type
: return "DW_TAG_restrict_type";
637 case DW_TAG_interface_type
: return "DW_TAG_interface_type";
638 case DW_TAG_namespace
: return "DW_TAG_namespace";
639 case DW_TAG_imported_module
: return "DW_TAG_imported_module";
640 case DW_TAG_unspecified_type
: return "DW_TAG_unspecified_type";
641 case DW_TAG_partial_unit
: return "DW_TAG_partial_unit";
642 case DW_TAG_imported_unit
: return "DW_TAG_imported_unit";
643 case DW_TAG_condition
: return "DW_TAG_condition";
644 case DW_TAG_shared_type
: return "DW_TAG_shared_type";
645 /* DWARF 4 values. */
646 case DW_TAG_type_unit
: return "DW_TAG_type_unit";
647 case DW_TAG_rvalue_reference_type
: return "DW_TAG_rvalue_reference_type";
648 case DW_TAG_template_alias
: return "DW_TAG_template_alias";
650 case DW_TAG_upc_shared_type
: return "DW_TAG_upc_shared_type";
651 case DW_TAG_upc_strict_type
: return "DW_TAG_upc_strict_type";
652 case DW_TAG_upc_relaxed_type
: return "DW_TAG_upc_relaxed_type";
654 case DW_TAG_GNU_call_site
: return "DW_TAG_GNU_call_site";
655 case DW_TAG_GNU_call_site_parameter
:return "DW_TAG_GNU_call_site_parameter";
658 static char buffer
[100];
660 snprintf (buffer
, sizeof (buffer
), _("Unknown TAG value: %lx"), tag
);
667 get_FORM_name (unsigned long form
)
671 case DW_FORM_addr
: return "DW_FORM_addr";
672 case DW_FORM_block2
: return "DW_FORM_block2";
673 case DW_FORM_block4
: return "DW_FORM_block4";
674 case DW_FORM_data2
: return "DW_FORM_data2";
675 case DW_FORM_data4
: return "DW_FORM_data4";
676 case DW_FORM_data8
: return "DW_FORM_data8";
677 case DW_FORM_string
: return "DW_FORM_string";
678 case DW_FORM_block
: return "DW_FORM_block";
679 case DW_FORM_block1
: return "DW_FORM_block1";
680 case DW_FORM_data1
: return "DW_FORM_data1";
681 case DW_FORM_flag
: return "DW_FORM_flag";
682 case DW_FORM_sdata
: return "DW_FORM_sdata";
683 case DW_FORM_strp
: return "DW_FORM_strp";
684 case DW_FORM_udata
: return "DW_FORM_udata";
685 case DW_FORM_ref_addr
: return "DW_FORM_ref_addr";
686 case DW_FORM_ref1
: return "DW_FORM_ref1";
687 case DW_FORM_ref2
: return "DW_FORM_ref2";
688 case DW_FORM_ref4
: return "DW_FORM_ref4";
689 case DW_FORM_ref8
: return "DW_FORM_ref8";
690 case DW_FORM_ref_udata
: return "DW_FORM_ref_udata";
691 case DW_FORM_indirect
: return "DW_FORM_indirect";
692 /* DWARF 4 values. */
693 case DW_FORM_sec_offset
: return "DW_FORM_sec_offset";
694 case DW_FORM_exprloc
: return "DW_FORM_exprloc";
695 case DW_FORM_flag_present
: return "DW_FORM_flag_present";
696 case DW_FORM_ref_sig8
: return "DW_FORM_ref_sig8";
699 static char buffer
[100];
701 snprintf (buffer
, sizeof (buffer
), _("Unknown FORM value: %lx"), form
);
707 static unsigned char *
708 display_block (unsigned char *data
, dwarf_vma length
)
710 printf (_(" %s byte block: "), dwarf_vmatoa ("u", length
));
713 printf ("%lx ", (unsigned long) byte_get (data
++, 1));
719 decode_location_expression (unsigned char * data
,
720 unsigned int pointer_size
,
721 unsigned int offset_size
,
725 struct dwarf_section
* section
)
728 unsigned int bytes_read
;
730 unsigned char *end
= data
+ length
;
731 int need_frame_base
= 0;
740 printf ("DW_OP_addr: %s",
741 dwarf_vmatoa ("x", byte_get (data
, pointer_size
)));
742 data
+= pointer_size
;
745 printf ("DW_OP_deref");
748 printf ("DW_OP_const1u: %lu", (unsigned long) byte_get (data
++, 1));
751 printf ("DW_OP_const1s: %ld", (long) byte_get_signed (data
++, 1));
754 printf ("DW_OP_const2u: %lu", (unsigned long) byte_get (data
, 2));
758 printf ("DW_OP_const2s: %ld", (long) byte_get_signed (data
, 2));
762 printf ("DW_OP_const4u: %lu", (unsigned long) byte_get (data
, 4));
766 printf ("DW_OP_const4s: %ld", (long) byte_get_signed (data
, 4));
770 printf ("DW_OP_const8u: %lu %lu", (unsigned long) byte_get (data
, 4),
771 (unsigned long) byte_get (data
+ 4, 4));
775 printf ("DW_OP_const8s: %ld %ld", (long) byte_get (data
, 4),
776 (long) byte_get (data
+ 4, 4));
780 printf ("DW_OP_constu: %s",
781 dwarf_vmatoa ("u", read_leb128 (data
, &bytes_read
, 0)));
785 printf ("DW_OP_consts: %s",
786 dwarf_vmatoa ("d", read_sleb128 (data
, &bytes_read
)));
790 printf ("DW_OP_dup");
793 printf ("DW_OP_drop");
796 printf ("DW_OP_over");
799 printf ("DW_OP_pick: %ld", (unsigned long) byte_get (data
++, 1));
802 printf ("DW_OP_swap");
805 printf ("DW_OP_rot");
808 printf ("DW_OP_xderef");
811 printf ("DW_OP_abs");
814 printf ("DW_OP_and");
817 printf ("DW_OP_div");
820 printf ("DW_OP_minus");
823 printf ("DW_OP_mod");
826 printf ("DW_OP_mul");
829 printf ("DW_OP_neg");
832 printf ("DW_OP_not");
838 printf ("DW_OP_plus");
840 case DW_OP_plus_uconst
:
841 printf ("DW_OP_plus_uconst: %s",
842 dwarf_vmatoa ("u", read_leb128 (data
, &bytes_read
, 0)));
846 printf ("DW_OP_shl");
849 printf ("DW_OP_shr");
852 printf ("DW_OP_shra");
855 printf ("DW_OP_xor");
858 printf ("DW_OP_bra: %ld", (long) byte_get_signed (data
, 2));
880 printf ("DW_OP_skip: %ld", (long) byte_get_signed (data
, 2));
916 printf ("DW_OP_lit%d", op
- DW_OP_lit0
);
951 printf ("DW_OP_reg%d (%s)", op
- DW_OP_reg0
,
952 regname (op
- DW_OP_reg0
, 1));
987 printf ("DW_OP_breg%d (%s): %s",
989 regname (op
- DW_OP_breg0
, 1),
990 dwarf_vmatoa ("d", (dwarf_signed_vma
)
991 read_leb128 (data
, &bytes_read
, 1)));
996 uvalue
= read_leb128 (data
, &bytes_read
, 0);
998 printf ("DW_OP_regx: %s (%s)",
999 dwarf_vmatoa ("u", uvalue
), regname (uvalue
, 1));
1002 need_frame_base
= 1;
1003 printf ("DW_OP_fbreg: %s",
1004 dwarf_vmatoa ("d", read_sleb128 (data
, &bytes_read
)));
1008 uvalue
= read_leb128 (data
, &bytes_read
, 0);
1010 printf ("DW_OP_bregx: %s (%s) %s",
1011 dwarf_vmatoa ("u", uvalue
), regname (uvalue
, 1),
1012 dwarf_vmatoa ("d", read_sleb128 (data
, &bytes_read
)));
1016 printf ("DW_OP_piece: %s",
1017 dwarf_vmatoa ("u", read_leb128 (data
, &bytes_read
, 0)));
1020 case DW_OP_deref_size
:
1021 printf ("DW_OP_deref_size: %ld", (long) byte_get (data
++, 1));
1023 case DW_OP_xderef_size
:
1024 printf ("DW_OP_xderef_size: %ld", (long) byte_get (data
++, 1));
1027 printf ("DW_OP_nop");
1030 /* DWARF 3 extensions. */
1031 case DW_OP_push_object_address
:
1032 printf ("DW_OP_push_object_address");
1035 /* XXX: Strictly speaking for 64-bit DWARF3 files
1036 this ought to be an 8-byte wide computation. */
1037 printf ("DW_OP_call2: <0x%s>",
1038 dwarf_vmatoa ("x", (dwarf_signed_vma
) byte_get (data
, 2)
1043 /* XXX: Strictly speaking for 64-bit DWARF3 files
1044 this ought to be an 8-byte wide computation. */
1045 printf ("DW_OP_call4: <0x%s>",
1046 dwarf_vmatoa ("x", (dwarf_signed_vma
) byte_get (data
, 4)
1050 case DW_OP_call_ref
:
1051 /* XXX: Strictly speaking for 64-bit DWARF3 files
1052 this ought to be an 8-byte wide computation. */
1053 if (dwarf_version
== -1)
1055 printf (_("(DW_OP_call_ref in frame info)"));
1056 /* No way to tell where the next op is, so just bail. */
1057 return need_frame_base
;
1059 if (dwarf_version
== 2)
1061 printf ("DW_OP_call_ref: <0x%s>",
1062 dwarf_vmatoa ("x", byte_get (data
, pointer_size
)));
1063 data
+= pointer_size
;
1067 printf ("DW_OP_call_ref: <0x%s>",
1068 dwarf_vmatoa ("x", byte_get (data
, offset_size
)));
1069 data
+= offset_size
;
1072 case DW_OP_form_tls_address
:
1073 printf ("DW_OP_form_tls_address");
1075 case DW_OP_call_frame_cfa
:
1076 printf ("DW_OP_call_frame_cfa");
1078 case DW_OP_bit_piece
:
1079 printf ("DW_OP_bit_piece: ");
1080 printf (_("size: %s "),
1081 dwarf_vmatoa ("u", read_leb128 (data
, &bytes_read
, 0)));
1083 printf (_("offset: %s "),
1084 dwarf_vmatoa ("u", read_leb128 (data
, &bytes_read
, 0)));
1088 /* DWARF 4 extensions. */
1089 case DW_OP_stack_value
:
1090 printf ("DW_OP_stack_value");
1093 case DW_OP_implicit_value
:
1094 printf ("DW_OP_implicit_value");
1095 uvalue
= read_leb128 (data
, &bytes_read
, 0);
1097 display_block (data
, uvalue
);
1101 /* GNU extensions. */
1102 case DW_OP_GNU_push_tls_address
:
1103 printf (_("DW_OP_GNU_push_tls_address or DW_OP_HP_unknown"));
1105 case DW_OP_GNU_uninit
:
1106 printf ("DW_OP_GNU_uninit");
1107 /* FIXME: Is there data associated with this OP ? */
1109 case DW_OP_GNU_encoded_addr
:
1115 addr
= get_encoded_value (data
, encoding
, section
);
1116 data
+= size_of_encoded_value (encoding
);
1118 printf ("DW_OP_GNU_encoded_addr: fmt:%02x addr:", encoding
);
1119 print_dwarf_vma (addr
, pointer_size
);
1122 case DW_OP_GNU_implicit_pointer
:
1123 /* XXX: Strictly speaking for 64-bit DWARF3 files
1124 this ought to be an 8-byte wide computation. */
1125 if (dwarf_version
== -1)
1127 printf (_("(DW_OP_GNU_implicit_pointer in frame info)"));
1128 /* No way to tell where the next op is, so just bail. */
1129 return need_frame_base
;
1131 if (dwarf_version
== 2)
1133 printf ("DW_OP_GNU_implicit_pointer: <0x%s> %s",
1134 dwarf_vmatoa ("x", byte_get (data
, pointer_size
)),
1135 dwarf_vmatoa ("d", read_sleb128 (data
+ pointer_size
,
1137 data
+= pointer_size
+ bytes_read
;
1141 printf ("DW_OP_GNU_implicit_pointer: <0x%s> %s",
1142 dwarf_vmatoa ("x", byte_get (data
, offset_size
)),
1143 dwarf_vmatoa ("d", read_sleb128 (data
+ offset_size
,
1145 data
+= offset_size
+ bytes_read
;
1148 case DW_OP_GNU_entry_value
:
1149 uvalue
= read_leb128 (data
, &bytes_read
, 0);
1151 printf ("DW_OP_GNU_entry_value: (");
1152 if (decode_location_expression (data
, pointer_size
, offset_size
,
1153 dwarf_version
, uvalue
,
1154 cu_offset
, section
))
1155 need_frame_base
= 1;
1159 case DW_OP_GNU_const_type
:
1160 uvalue
= read_leb128 (data
, &bytes_read
, 0);
1162 printf ("DW_OP_GNU_const_type: <0x%s> ",
1163 dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1164 uvalue
= byte_get (data
++, 1);
1165 display_block (data
, uvalue
);
1168 case DW_OP_GNU_regval_type
:
1169 uvalue
= read_leb128 (data
, &bytes_read
, 0);
1171 printf ("DW_OP_GNU_regval_type: %s (%s)",
1172 dwarf_vmatoa ("u", uvalue
), regname (uvalue
, 1));
1173 uvalue
= read_leb128 (data
, &bytes_read
, 0);
1175 printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1177 case DW_OP_GNU_deref_type
:
1178 printf ("DW_OP_GNU_deref_type: %ld", (long) byte_get (data
++, 1));
1179 uvalue
= read_leb128 (data
, &bytes_read
, 0);
1181 printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1183 case DW_OP_GNU_convert
:
1184 uvalue
= read_leb128 (data
, &bytes_read
, 0);
1186 printf ("DW_OP_GNU_convert <0x%s>",
1187 dwarf_vmatoa ("x", uvalue
? cu_offset
+ uvalue
: 0));
1189 case DW_OP_GNU_reinterpret
:
1190 uvalue
= read_leb128 (data
, &bytes_read
, 0);
1192 printf ("DW_OP_GNU_reinterpret <0x%s>",
1193 dwarf_vmatoa ("x", uvalue
? cu_offset
+ uvalue
: 0));
1195 case DW_OP_GNU_parameter_ref
:
1196 printf ("DW_OP_GNU_parameter_ref: <0x%s>",
1197 dwarf_vmatoa ("x", cu_offset
+ byte_get (data
, 4)));
1201 /* HP extensions. */
1202 case DW_OP_HP_is_value
:
1203 printf ("DW_OP_HP_is_value");
1204 /* FIXME: Is there data associated with this OP ? */
1206 case DW_OP_HP_fltconst4
:
1207 printf ("DW_OP_HP_fltconst4");
1208 /* FIXME: Is there data associated with this OP ? */
1210 case DW_OP_HP_fltconst8
:
1211 printf ("DW_OP_HP_fltconst8");
1212 /* FIXME: Is there data associated with this OP ? */
1214 case DW_OP_HP_mod_range
:
1215 printf ("DW_OP_HP_mod_range");
1216 /* FIXME: Is there data associated with this OP ? */
1218 case DW_OP_HP_unmod_range
:
1219 printf ("DW_OP_HP_unmod_range");
1220 /* FIXME: Is there data associated with this OP ? */
1223 printf ("DW_OP_HP_tls");
1224 /* FIXME: Is there data associated with this OP ? */
1227 /* PGI (STMicroelectronics) extensions. */
1228 case DW_OP_PGI_omp_thread_num
:
1229 /* Pushes the thread number for the current thread as it would be
1230 returned by the standard OpenMP library function:
1231 omp_get_thread_num(). The "current thread" is the thread for
1232 which the expression is being evaluated. */
1233 printf ("DW_OP_PGI_omp_thread_num");
1237 if (op
>= DW_OP_lo_user
1238 && op
<= DW_OP_hi_user
)
1239 printf (_("(User defined location op)"));
1241 printf (_("(Unknown location op)"));
1242 /* No way to tell where the next op is, so just bail. */
1243 return need_frame_base
;
1246 /* Separate the ops. */
1251 return need_frame_base
;
1254 static unsigned char *
1255 read_and_display_attr_value (unsigned long attribute
,
1257 unsigned char * data
,
1258 dwarf_vma cu_offset
,
1259 dwarf_vma pointer_size
,
1260 dwarf_vma offset_size
,
1262 debug_info
* debug_info_p
,
1264 struct dwarf_section
* section
)
1266 dwarf_vma uvalue
= 0;
1267 unsigned char *block_start
= NULL
;
1268 unsigned char * orig_data
= data
;
1269 unsigned int bytes_read
;
1276 case DW_FORM_ref_addr
:
1277 if (dwarf_version
== 2)
1279 uvalue
= byte_get (data
, pointer_size
);
1280 data
+= pointer_size
;
1282 else if (dwarf_version
== 3 || dwarf_version
== 4)
1284 uvalue
= byte_get (data
, offset_size
);
1285 data
+= offset_size
;
1288 error (_("Internal error: DWARF version is not 2, 3 or 4.\n"));
1293 uvalue
= byte_get (data
, pointer_size
);
1294 data
+= pointer_size
;
1298 case DW_FORM_sec_offset
:
1299 uvalue
= byte_get (data
, offset_size
);
1300 data
+= offset_size
;
1303 case DW_FORM_flag_present
:
1310 uvalue
= byte_get (data
++, 1);
1315 uvalue
= byte_get (data
, 2);
1321 uvalue
= byte_get (data
, 4);
1326 uvalue
= read_leb128 (data
, & bytes_read
, 1);
1330 case DW_FORM_ref_udata
:
1332 uvalue
= read_leb128 (data
, & bytes_read
, 0);
1336 case DW_FORM_indirect
:
1337 form
= read_leb128 (data
, & bytes_read
, 0);
1340 printf (" %s", get_FORM_name (form
));
1341 return read_and_display_attr_value (attribute
, form
, data
,
1342 cu_offset
, pointer_size
,
1343 offset_size
, dwarf_version
,
1344 debug_info_p
, do_loc
,
1350 case DW_FORM_ref_addr
:
1352 printf (" <0x%s>", dwarf_vmatoa ("x",uvalue
));
1358 case DW_FORM_ref_udata
:
1360 printf (" <0x%s>", dwarf_vmatoa ("x", uvalue
+ cu_offset
));
1365 case DW_FORM_sec_offset
:
1367 printf (" 0x%s", dwarf_vmatoa ("x", uvalue
));
1370 case DW_FORM_flag_present
:
1377 printf (" %s", dwarf_vmatoa ("d", uvalue
));
1384 uvalue
= byte_get (data
, 4);
1385 printf (" 0x%s", dwarf_vmatoa ("x", uvalue
));
1386 printf (" 0x%lx", (unsigned long) byte_get (data
+ 4, 4));
1388 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
1389 && num_debug_info_entries
== 0)
1391 if (sizeof (uvalue
) == 8)
1392 uvalue
= byte_get (data
, 8);
1394 error (_("DW_FORM_data8 is unsupported when sizeof (dwarf_vma) != 8\n"));
1399 case DW_FORM_string
:
1401 printf (" %s", data
);
1402 data
+= strlen ((char *) data
) + 1;
1406 case DW_FORM_exprloc
:
1407 uvalue
= read_leb128 (data
, & bytes_read
, 0);
1408 block_start
= data
+ bytes_read
;
1410 data
= block_start
+ uvalue
;
1412 data
= display_block (block_start
, uvalue
);
1415 case DW_FORM_block1
:
1416 uvalue
= byte_get (data
, 1);
1417 block_start
= data
+ 1;
1419 data
= block_start
+ uvalue
;
1421 data
= display_block (block_start
, uvalue
);
1424 case DW_FORM_block2
:
1425 uvalue
= byte_get (data
, 2);
1426 block_start
= data
+ 2;
1428 data
= block_start
+ uvalue
;
1430 data
= display_block (block_start
, uvalue
);
1433 case DW_FORM_block4
:
1434 uvalue
= byte_get (data
, 4);
1435 block_start
= data
+ 4;
1437 data
= block_start
+ uvalue
;
1439 data
= display_block (block_start
, uvalue
);
1444 printf (_(" (indirect string, offset: 0x%s): %s"),
1445 dwarf_vmatoa ("x", uvalue
),
1446 fetch_indirect_string (uvalue
));
1449 case DW_FORM_indirect
:
1450 /* Handled above. */
1453 case DW_FORM_ref_sig8
:
1457 printf (" signature: ");
1458 for (i
= 0; i
< 8; i
++)
1460 printf ("%02x", (unsigned) byte_get (data
, 1));
1469 warn (_("Unrecognized form: %lu\n"), form
);
1473 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
1474 && num_debug_info_entries
== 0
1475 && debug_info_p
!= NULL
)
1479 case DW_AT_frame_base
:
1480 have_frame_base
= 1;
1481 case DW_AT_location
:
1482 case DW_AT_string_length
:
1483 case DW_AT_return_addr
:
1484 case DW_AT_data_member_location
:
1485 case DW_AT_vtable_elem_location
:
1487 case DW_AT_static_link
:
1488 case DW_AT_use_location
:
1489 case DW_AT_GNU_call_site_value
:
1490 case DW_AT_GNU_call_site_data_value
:
1491 case DW_AT_GNU_call_site_target
:
1492 case DW_AT_GNU_call_site_target_clobbered
:
1493 if ((dwarf_version
< 4
1494 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
1495 || form
== DW_FORM_sec_offset
)
1497 /* Process location list. */
1498 unsigned int lmax
= debug_info_p
->max_loc_offsets
;
1499 unsigned int num
= debug_info_p
->num_loc_offsets
;
1501 if (lmax
== 0 || num
>= lmax
)
1504 debug_info_p
->loc_offsets
= (dwarf_vma
*)
1505 xcrealloc (debug_info_p
->loc_offsets
,
1506 lmax
, sizeof (*debug_info_p
->loc_offsets
));
1507 debug_info_p
->have_frame_base
= (int *)
1508 xcrealloc (debug_info_p
->have_frame_base
,
1509 lmax
, sizeof (*debug_info_p
->have_frame_base
));
1510 debug_info_p
->max_loc_offsets
= lmax
;
1512 debug_info_p
->loc_offsets
[num
] = uvalue
;
1513 debug_info_p
->have_frame_base
[num
] = have_frame_base
;
1514 debug_info_p
->num_loc_offsets
++;
1519 if (need_base_address
)
1520 debug_info_p
->base_address
= uvalue
;
1524 if ((dwarf_version
< 4
1525 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
1526 || form
== DW_FORM_sec_offset
)
1528 /* Process range list. */
1529 unsigned int lmax
= debug_info_p
->max_range_lists
;
1530 unsigned int num
= debug_info_p
->num_range_lists
;
1532 if (lmax
== 0 || num
>= lmax
)
1535 debug_info_p
->range_lists
= (dwarf_vma
*)
1536 xcrealloc (debug_info_p
->range_lists
,
1537 lmax
, sizeof (*debug_info_p
->range_lists
));
1538 debug_info_p
->max_range_lists
= lmax
;
1540 debug_info_p
->range_lists
[num
] = uvalue
;
1541 debug_info_p
->num_range_lists
++;
1550 if (do_loc
|| attribute
== 0)
1553 /* For some attributes we can display further information. */
1561 case DW_INL_not_inlined
:
1562 printf (_("(not inlined)"));
1564 case DW_INL_inlined
:
1565 printf (_("(inlined)"));
1567 case DW_INL_declared_not_inlined
:
1568 printf (_("(declared as inline but ignored)"));
1570 case DW_INL_declared_inlined
:
1571 printf (_("(declared as inline and inlined)"));
1574 printf (_(" (Unknown inline attribute value: %s)"),
1575 dwarf_vmatoa ("x", uvalue
));
1580 case DW_AT_language
:
1583 /* Ordered by the numeric value of these constants. */
1584 case DW_LANG_C89
: printf ("(ANSI C)"); break;
1585 case DW_LANG_C
: printf ("(non-ANSI C)"); break;
1586 case DW_LANG_Ada83
: printf ("(Ada)"); break;
1587 case DW_LANG_C_plus_plus
: printf ("(C++)"); break;
1588 case DW_LANG_Cobol74
: printf ("(Cobol 74)"); break;
1589 case DW_LANG_Cobol85
: printf ("(Cobol 85)"); break;
1590 case DW_LANG_Fortran77
: printf ("(FORTRAN 77)"); break;
1591 case DW_LANG_Fortran90
: printf ("(Fortran 90)"); break;
1592 case DW_LANG_Pascal83
: printf ("(ANSI Pascal)"); break;
1593 case DW_LANG_Modula2
: printf ("(Modula 2)"); break;
1594 /* DWARF 2.1 values. */
1595 case DW_LANG_Java
: printf ("(Java)"); break;
1596 case DW_LANG_C99
: printf ("(ANSI C99)"); break;
1597 case DW_LANG_Ada95
: printf ("(ADA 95)"); break;
1598 case DW_LANG_Fortran95
: printf ("(Fortran 95)"); break;
1599 /* DWARF 3 values. */
1600 case DW_LANG_PLI
: printf ("(PLI)"); break;
1601 case DW_LANG_ObjC
: printf ("(Objective C)"); break;
1602 case DW_LANG_ObjC_plus_plus
: printf ("(Objective C++)"); break;
1603 case DW_LANG_UPC
: printf ("(Unified Parallel C)"); break;
1604 case DW_LANG_D
: printf ("(D)"); break;
1605 /* DWARF 4 values. */
1606 case DW_LANG_Python
: printf ("(Python)"); break;
1607 /* DWARF 5 values. */
1608 case DW_LANG_Go
: printf ("(Go)"); break;
1609 /* MIPS extension. */
1610 case DW_LANG_Mips_Assembler
: printf ("(MIPS assembler)"); break;
1611 /* UPC extension. */
1612 case DW_LANG_Upc
: printf ("(Unified Parallel C)"); break;
1614 if (uvalue
>= DW_LANG_lo_user
&& uvalue
<= DW_LANG_hi_user
)
1615 printf (_("(implementation defined: %s)"),
1616 dwarf_vmatoa ("x", uvalue
));
1618 printf (_("(Unknown: %s)"), dwarf_vmatoa ("x", uvalue
));
1623 case DW_AT_encoding
:
1626 case DW_ATE_void
: printf ("(void)"); break;
1627 case DW_ATE_address
: printf ("(machine address)"); break;
1628 case DW_ATE_boolean
: printf ("(boolean)"); break;
1629 case DW_ATE_complex_float
: printf ("(complex float)"); break;
1630 case DW_ATE_float
: printf ("(float)"); break;
1631 case DW_ATE_signed
: printf ("(signed)"); break;
1632 case DW_ATE_signed_char
: printf ("(signed char)"); break;
1633 case DW_ATE_unsigned
: printf ("(unsigned)"); break;
1634 case DW_ATE_unsigned_char
: printf ("(unsigned char)"); break;
1635 /* DWARF 2.1 values: */
1636 case DW_ATE_imaginary_float
: printf ("(imaginary float)"); break;
1637 case DW_ATE_decimal_float
: printf ("(decimal float)"); break;
1638 /* DWARF 3 values: */
1639 case DW_ATE_packed_decimal
: printf ("(packed_decimal)"); break;
1640 case DW_ATE_numeric_string
: printf ("(numeric_string)"); break;
1641 case DW_ATE_edited
: printf ("(edited)"); break;
1642 case DW_ATE_signed_fixed
: printf ("(signed_fixed)"); break;
1643 case DW_ATE_unsigned_fixed
: printf ("(unsigned_fixed)"); break;
1644 /* HP extensions: */
1645 case DW_ATE_HP_float80
: printf ("(HP_float80)"); break;
1646 case DW_ATE_HP_complex_float80
: printf ("(HP_complex_float80)"); break;
1647 case DW_ATE_HP_float128
: printf ("(HP_float128)"); break;
1648 case DW_ATE_HP_complex_float128
:printf ("(HP_complex_float128)"); break;
1649 case DW_ATE_HP_floathpintel
: printf ("(HP_floathpintel)"); break;
1650 case DW_ATE_HP_imaginary_float80
: printf ("(HP_imaginary_float80)"); break;
1651 case DW_ATE_HP_imaginary_float128
: printf ("(HP_imaginary_float128)"); break;
1654 if (uvalue
>= DW_ATE_lo_user
1655 && uvalue
<= DW_ATE_hi_user
)
1656 printf (_("(user defined type)"));
1658 printf (_("(unknown type)"));
1663 case DW_AT_accessibility
:
1666 case DW_ACCESS_public
: printf ("(public)"); break;
1667 case DW_ACCESS_protected
: printf ("(protected)"); break;
1668 case DW_ACCESS_private
: printf ("(private)"); break;
1670 printf (_("(unknown accessibility)"));
1675 case DW_AT_visibility
:
1678 case DW_VIS_local
: printf ("(local)"); break;
1679 case DW_VIS_exported
: printf ("(exported)"); break;
1680 case DW_VIS_qualified
: printf ("(qualified)"); break;
1681 default: printf (_("(unknown visibility)")); break;
1685 case DW_AT_virtuality
:
1688 case DW_VIRTUALITY_none
: printf ("(none)"); break;
1689 case DW_VIRTUALITY_virtual
: printf ("(virtual)"); break;
1690 case DW_VIRTUALITY_pure_virtual
:printf ("(pure_virtual)"); break;
1691 default: printf (_("(unknown virtuality)")); break;
1695 case DW_AT_identifier_case
:
1698 case DW_ID_case_sensitive
: printf ("(case_sensitive)"); break;
1699 case DW_ID_up_case
: printf ("(up_case)"); break;
1700 case DW_ID_down_case
: printf ("(down_case)"); break;
1701 case DW_ID_case_insensitive
: printf ("(case_insensitive)"); break;
1702 default: printf (_("(unknown case)")); break;
1706 case DW_AT_calling_convention
:
1709 case DW_CC_normal
: printf ("(normal)"); break;
1710 case DW_CC_program
: printf ("(program)"); break;
1711 case DW_CC_nocall
: printf ("(nocall)"); break;
1713 if (uvalue
>= DW_CC_lo_user
1714 && uvalue
<= DW_CC_hi_user
)
1715 printf (_("(user defined)"));
1717 printf (_("(unknown convention)"));
1721 case DW_AT_ordering
:
1724 case -1: printf (_("(undefined)")); break;
1725 case 0: printf ("(row major)"); break;
1726 case 1: printf ("(column major)"); break;
1730 case DW_AT_frame_base
:
1731 have_frame_base
= 1;
1732 case DW_AT_location
:
1733 case DW_AT_string_length
:
1734 case DW_AT_return_addr
:
1735 case DW_AT_data_member_location
:
1736 case DW_AT_vtable_elem_location
:
1738 case DW_AT_static_link
:
1739 case DW_AT_use_location
:
1740 case DW_AT_GNU_call_site_value
:
1741 case DW_AT_GNU_call_site_data_value
:
1742 case DW_AT_GNU_call_site_target
:
1743 case DW_AT_GNU_call_site_target_clobbered
:
1744 if ((dwarf_version
< 4
1745 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
1746 || form
== DW_FORM_sec_offset
)
1747 printf (_("(location list)"));
1749 case DW_AT_allocated
:
1750 case DW_AT_associated
:
1751 case DW_AT_data_location
:
1753 case DW_AT_upper_bound
:
1754 case DW_AT_lower_bound
:
1757 int need_frame_base
;
1760 need_frame_base
= decode_location_expression (block_start
,
1765 cu_offset
, section
);
1767 if (need_frame_base
&& !have_frame_base
)
1768 printf (_(" [without DW_AT_frame_base]"));
1774 if (form
== DW_FORM_ref_sig8
)
1777 if (form
== DW_FORM_ref1
1778 || form
== DW_FORM_ref2
1779 || form
== DW_FORM_ref4
1780 || form
== DW_FORM_ref_udata
)
1781 uvalue
+= cu_offset
;
1783 if (uvalue
>= section
->size
)
1784 warn (_("Offset %s used as value for DW_AT_import attribute of DIE at offset %lx is too big.\n"),
1785 dwarf_vmatoa ("x", uvalue
),
1786 (unsigned long) (orig_data
- section
->start
));
1789 unsigned long abbrev_number
;
1790 abbrev_entry
* entry
;
1792 abbrev_number
= read_leb128 (section
->start
+ uvalue
, NULL
, 0);
1794 printf (_("[Abbrev Number: %ld"), abbrev_number
);
1795 for (entry
= first_abbrev
; entry
!= NULL
; entry
= entry
->next
)
1796 if (entry
->entry
== abbrev_number
)
1799 printf (" (%s)", get_TAG_name (entry
->tag
));
1813 get_AT_name (unsigned long attribute
)
1817 case DW_AT_sibling
: return "DW_AT_sibling";
1818 case DW_AT_location
: return "DW_AT_location";
1819 case DW_AT_name
: return "DW_AT_name";
1820 case DW_AT_ordering
: return "DW_AT_ordering";
1821 case DW_AT_subscr_data
: return "DW_AT_subscr_data";
1822 case DW_AT_byte_size
: return "DW_AT_byte_size";
1823 case DW_AT_bit_offset
: return "DW_AT_bit_offset";
1824 case DW_AT_bit_size
: return "DW_AT_bit_size";
1825 case DW_AT_element_list
: return "DW_AT_element_list";
1826 case DW_AT_stmt_list
: return "DW_AT_stmt_list";
1827 case DW_AT_low_pc
: return "DW_AT_low_pc";
1828 case DW_AT_high_pc
: return "DW_AT_high_pc";
1829 case DW_AT_language
: return "DW_AT_language";
1830 case DW_AT_member
: return "DW_AT_member";
1831 case DW_AT_discr
: return "DW_AT_discr";
1832 case DW_AT_discr_value
: return "DW_AT_discr_value";
1833 case DW_AT_visibility
: return "DW_AT_visibility";
1834 case DW_AT_import
: return "DW_AT_import";
1835 case DW_AT_string_length
: return "DW_AT_string_length";
1836 case DW_AT_common_reference
: return "DW_AT_common_reference";
1837 case DW_AT_comp_dir
: return "DW_AT_comp_dir";
1838 case DW_AT_const_value
: return "DW_AT_const_value";
1839 case DW_AT_containing_type
: return "DW_AT_containing_type";
1840 case DW_AT_default_value
: return "DW_AT_default_value";
1841 case DW_AT_inline
: return "DW_AT_inline";
1842 case DW_AT_is_optional
: return "DW_AT_is_optional";
1843 case DW_AT_lower_bound
: return "DW_AT_lower_bound";
1844 case DW_AT_producer
: return "DW_AT_producer";
1845 case DW_AT_prototyped
: return "DW_AT_prototyped";
1846 case DW_AT_return_addr
: return "DW_AT_return_addr";
1847 case DW_AT_start_scope
: return "DW_AT_start_scope";
1848 case DW_AT_stride_size
: return "DW_AT_stride_size";
1849 case DW_AT_upper_bound
: return "DW_AT_upper_bound";
1850 case DW_AT_abstract_origin
: return "DW_AT_abstract_origin";
1851 case DW_AT_accessibility
: return "DW_AT_accessibility";
1852 case DW_AT_address_class
: return "DW_AT_address_class";
1853 case DW_AT_artificial
: return "DW_AT_artificial";
1854 case DW_AT_base_types
: return "DW_AT_base_types";
1855 case DW_AT_calling_convention
: return "DW_AT_calling_convention";
1856 case DW_AT_count
: return "DW_AT_count";
1857 case DW_AT_data_member_location
: return "DW_AT_data_member_location";
1858 case DW_AT_decl_column
: return "DW_AT_decl_column";
1859 case DW_AT_decl_file
: return "DW_AT_decl_file";
1860 case DW_AT_decl_line
: return "DW_AT_decl_line";
1861 case DW_AT_declaration
: return "DW_AT_declaration";
1862 case DW_AT_discr_list
: return "DW_AT_discr_list";
1863 case DW_AT_encoding
: return "DW_AT_encoding";
1864 case DW_AT_external
: return "DW_AT_external";
1865 case DW_AT_frame_base
: return "DW_AT_frame_base";
1866 case DW_AT_friend
: return "DW_AT_friend";
1867 case DW_AT_identifier_case
: return "DW_AT_identifier_case";
1868 case DW_AT_macro_info
: return "DW_AT_macro_info";
1869 case DW_AT_namelist_items
: return "DW_AT_namelist_items";
1870 case DW_AT_priority
: return "DW_AT_priority";
1871 case DW_AT_segment
: return "DW_AT_segment";
1872 case DW_AT_specification
: return "DW_AT_specification";
1873 case DW_AT_static_link
: return "DW_AT_static_link";
1874 case DW_AT_type
: return "DW_AT_type";
1875 case DW_AT_use_location
: return "DW_AT_use_location";
1876 case DW_AT_variable_parameter
: return "DW_AT_variable_parameter";
1877 case DW_AT_virtuality
: return "DW_AT_virtuality";
1878 case DW_AT_vtable_elem_location
: return "DW_AT_vtable_elem_location";
1879 /* DWARF 2.1 values. */
1880 case DW_AT_allocated
: return "DW_AT_allocated";
1881 case DW_AT_associated
: return "DW_AT_associated";
1882 case DW_AT_data_location
: return "DW_AT_data_location";
1883 case DW_AT_stride
: return "DW_AT_stride";
1884 case DW_AT_entry_pc
: return "DW_AT_entry_pc";
1885 case DW_AT_use_UTF8
: return "DW_AT_use_UTF8";
1886 case DW_AT_extension
: return "DW_AT_extension";
1887 case DW_AT_ranges
: return "DW_AT_ranges";
1888 case DW_AT_trampoline
: return "DW_AT_trampoline";
1889 case DW_AT_call_column
: return "DW_AT_call_column";
1890 case DW_AT_call_file
: return "DW_AT_call_file";
1891 case DW_AT_call_line
: return "DW_AT_call_line";
1892 case DW_AT_description
: return "DW_AT_description";
1893 case DW_AT_binary_scale
: return "DW_AT_binary_scale";
1894 case DW_AT_decimal_scale
: return "DW_AT_decimal_scale";
1895 case DW_AT_small
: return "DW_AT_small";
1896 case DW_AT_decimal_sign
: return "DW_AT_decimal_sign";
1897 case DW_AT_digit_count
: return "DW_AT_digit_count";
1898 case DW_AT_picture_string
: return "DW_AT_picture_string";
1899 case DW_AT_mutable
: return "DW_AT_mutable";
1900 case DW_AT_threads_scaled
: return "DW_AT_threads_scaled";
1901 case DW_AT_explicit
: return "DW_AT_explicit";
1902 case DW_AT_object_pointer
: return "DW_AT_object_pointer";
1903 case DW_AT_endianity
: return "DW_AT_endianity";
1904 case DW_AT_elemental
: return "DW_AT_elemental";
1905 case DW_AT_pure
: return "DW_AT_pure";
1906 case DW_AT_recursive
: return "DW_AT_recursive";
1907 /* DWARF 4 values. */
1908 case DW_AT_signature
: return "DW_AT_signature";
1909 case DW_AT_main_subprogram
: return "DW_AT_main_subprogram";
1910 case DW_AT_data_bit_offset
: return "DW_AT_data_bit_offset";
1911 case DW_AT_const_expr
: return "DW_AT_const_expr";
1912 case DW_AT_enum_class
: return "DW_AT_enum_class";
1913 case DW_AT_linkage_name
: return "DW_AT_linkage_name";
1915 /* HP and SGI/MIPS extensions. */
1916 case DW_AT_MIPS_loop_begin
: return "DW_AT_MIPS_loop_begin";
1917 case DW_AT_MIPS_tail_loop_begin
: return "DW_AT_MIPS_tail_loop_begin";
1918 case DW_AT_MIPS_epilog_begin
: return "DW_AT_MIPS_epilog_begin";
1919 case DW_AT_MIPS_loop_unroll_factor
: return "DW_AT_MIPS_loop_unroll_factor";
1920 case DW_AT_MIPS_software_pipeline_depth
: return "DW_AT_MIPS_software_pipeline_depth";
1921 case DW_AT_MIPS_linkage_name
: return "DW_AT_MIPS_linkage_name";
1922 case DW_AT_MIPS_stride
: return "DW_AT_MIPS_stride";
1923 case DW_AT_MIPS_abstract_name
: return "DW_AT_MIPS_abstract_name";
1924 case DW_AT_MIPS_clone_origin
: return "DW_AT_MIPS_clone_origin";
1925 case DW_AT_MIPS_has_inlines
: return "DW_AT_MIPS_has_inlines";
1927 /* HP Extensions. */
1928 case DW_AT_HP_block_index
: return "DW_AT_HP_block_index";
1929 case DW_AT_HP_actuals_stmt_list
: return "DW_AT_HP_actuals_stmt_list";
1930 case DW_AT_HP_proc_per_section
: return "DW_AT_HP_proc_per_section";
1931 case DW_AT_HP_raw_data_ptr
: return "DW_AT_HP_raw_data_ptr";
1932 case DW_AT_HP_pass_by_reference
: return "DW_AT_HP_pass_by_reference";
1933 case DW_AT_HP_opt_level
: return "DW_AT_HP_opt_level";
1934 case DW_AT_HP_prof_version_id
: return "DW_AT_HP_prof_version_id";
1935 case DW_AT_HP_opt_flags
: return "DW_AT_HP_opt_flags";
1936 case DW_AT_HP_cold_region_low_pc
: return "DW_AT_HP_cold_region_low_pc";
1937 case DW_AT_HP_cold_region_high_pc
: return "DW_AT_HP_cold_region_high_pc";
1938 case DW_AT_HP_all_variables_modifiable
: return "DW_AT_HP_all_variables_modifiable";
1939 case DW_AT_HP_linkage_name
: return "DW_AT_HP_linkage_name";
1940 case DW_AT_HP_prof_flags
: return "DW_AT_HP_prof_flags";
1942 /* One value is shared by the MIPS and HP extensions: */
1943 case DW_AT_MIPS_fde
: return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable";
1945 /* GNU extensions. */
1946 case DW_AT_sf_names
: return "DW_AT_sf_names";
1947 case DW_AT_src_info
: return "DW_AT_src_info";
1948 case DW_AT_mac_info
: return "DW_AT_mac_info";
1949 case DW_AT_src_coords
: return "DW_AT_src_coords";
1950 case DW_AT_body_begin
: return "DW_AT_body_begin";
1951 case DW_AT_body_end
: return "DW_AT_body_end";
1952 case DW_AT_GNU_vector
: return "DW_AT_GNU_vector";
1953 case DW_AT_GNU_guarded_by
: return "DW_AT_GNU_guarded_by";
1954 case DW_AT_GNU_pt_guarded_by
: return "DW_AT_GNU_pt_guarded_by";
1955 case DW_AT_GNU_guarded
: return "DW_AT_GNU_guarded";
1956 case DW_AT_GNU_pt_guarded
: return "DW_AT_GNU_pt_guarded";
1957 case DW_AT_GNU_locks_excluded
: return "DW_AT_GNU_locks_excluded";
1958 case DW_AT_GNU_exclusive_locks_required
: return "DW_AT_GNU_exclusive_locks_required";
1959 case DW_AT_GNU_shared_locks_required
: return "DW_AT_GNU_shared_locks_required";
1960 case DW_AT_GNU_odr_signature
: return "DW_AT_GNU_odr_signature";
1961 case DW_AT_use_GNAT_descriptive_type
: return "DW_AT_use_GNAT_descriptive_type";
1962 case DW_AT_GNAT_descriptive_type
: return "DW_AT_GNAT_descriptive_type";
1963 case DW_AT_GNU_call_site_value
: return "DW_AT_GNU_call_site_value";
1964 case DW_AT_GNU_call_site_data_value
: return "DW_AT_GNU_call_site_data_value";
1965 case DW_AT_GNU_call_site_target
: return "DW_AT_GNU_call_site_target";
1966 case DW_AT_GNU_call_site_target_clobbered
: return "DW_AT_GNU_call_site_target_clobbered";
1967 case DW_AT_GNU_tail_call
: return "DW_AT_GNU_tail_call";
1968 case DW_AT_GNU_all_tail_call_sites
: return "DW_AT_GNU_all_tail_call_sites";
1969 case DW_AT_GNU_all_call_sites
: return "DW_AT_GNU_all_call_sites";
1970 case DW_AT_GNU_all_source_call_sites
: return "DW_AT_GNU_all_source_call_sites";
1971 case DW_AT_GNU_macros
: return "DW_AT_GNU_macros";
1973 /* UPC extension. */
1974 case DW_AT_upc_threads_scaled
: return "DW_AT_upc_threads_scaled";
1976 /* PGI (STMicroelectronics) extensions. */
1977 case DW_AT_PGI_lbase
: return "DW_AT_PGI_lbase";
1978 case DW_AT_PGI_soffset
: return "DW_AT_PGI_soffset";
1979 case DW_AT_PGI_lstride
: return "DW_AT_PGI_lstride";
1983 static char buffer
[100];
1985 snprintf (buffer
, sizeof (buffer
), _("Unknown AT value: %lx"),
1992 static unsigned char *
1993 read_and_display_attr (unsigned long attribute
,
1995 unsigned char * data
,
1996 dwarf_vma cu_offset
,
1997 dwarf_vma pointer_size
,
1998 dwarf_vma offset_size
,
2000 debug_info
* debug_info_p
,
2002 struct dwarf_section
* section
)
2005 printf (" %-18s:", get_AT_name (attribute
));
2006 data
= read_and_display_attr_value (attribute
, form
, data
, cu_offset
,
2007 pointer_size
, offset_size
,
2008 dwarf_version
, debug_info_p
,
2016 /* Process the contents of a .debug_info section. If do_loc is non-zero
2017 then we are scanning for location lists and we do not want to display
2018 anything to the user. If do_types is non-zero, we are processing
2019 a .debug_types section instead of a .debug_info section. */
2022 process_debug_info (struct dwarf_section
*section
,
2024 enum dwarf_section_display_enum abbrev_sec
,
2028 unsigned char *start
= section
->start
;
2029 unsigned char *end
= start
+ section
->size
;
2030 unsigned char *section_begin
;
2032 unsigned int num_units
= 0;
2034 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
2035 && num_debug_info_entries
== 0
2040 /* First scan the section to get the number of comp units. */
2041 for (section_begin
= start
, num_units
= 0; section_begin
< end
;
2044 /* Read the first 4 bytes. For a 32-bit DWARF section, this
2045 will be the length. For a 64-bit DWARF section, it'll be
2046 the escape code 0xffffffff followed by an 8 byte length. */
2047 length
= byte_get (section_begin
, 4);
2049 if (length
== 0xffffffff)
2051 length
= byte_get (section_begin
+ 4, 8);
2052 section_begin
+= length
+ 12;
2054 else if (length
>= 0xfffffff0 && length
< 0xffffffff)
2056 warn (_("Reserved length value (0x%s) found in section %s\n"),
2057 dwarf_vmatoa ("x", length
), section
->name
);
2061 section_begin
+= length
+ 4;
2063 /* Negative values are illegal, they may even cause infinite
2064 looping. This can happen if we can't accurately apply
2065 relocations to an object file. */
2066 if ((signed long) length
<= 0)
2068 warn (_("Corrupt unit length (0x%s) found in section %s\n"),
2069 dwarf_vmatoa ("x", length
), section
->name
);
2076 error (_("No comp units in %s section ?"), section
->name
);
2080 /* Then allocate an array to hold the information. */
2081 debug_information
= (debug_info
*) cmalloc (num_units
,
2082 sizeof (* debug_information
));
2083 if (debug_information
== NULL
)
2085 error (_("Not enough memory for a debug info array of %u entries"),
2093 if (dwarf_start_die
== 0)
2094 printf (_("Contents of the %s section:\n\n"), section
->name
);
2096 load_debug_section (str
, file
);
2099 load_debug_section (abbrev_sec
, file
);
2100 if (debug_displays
[abbrev_sec
].section
.start
== NULL
)
2102 warn (_("Unable to locate %s section!\n"),
2103 debug_displays
[abbrev_sec
].section
.name
);
2107 for (section_begin
= start
, unit
= 0; start
< end
; unit
++)
2109 DWARF2_Internal_CompUnit compunit
;
2110 unsigned char *hdrptr
;
2111 unsigned char *tags
;
2112 int level
, last_level
, saved_level
;
2113 dwarf_vma cu_offset
;
2115 int initial_length_size
;
2116 unsigned char signature
[8] = { 0 };
2117 dwarf_vma type_offset
= 0;
2121 compunit
.cu_length
= byte_get (hdrptr
, 4);
2124 if (compunit
.cu_length
== 0xffffffff)
2126 compunit
.cu_length
= byte_get (hdrptr
, 8);
2129 initial_length_size
= 12;
2134 initial_length_size
= 4;
2137 compunit
.cu_version
= byte_get (hdrptr
, 2);
2140 cu_offset
= start
- section_begin
;
2142 compunit
.cu_abbrev_offset
= byte_get (hdrptr
, offset_size
);
2143 hdrptr
+= offset_size
;
2145 compunit
.cu_pointer_size
= byte_get (hdrptr
, 1);
2152 for (i
= 0; i
< 8; i
++)
2154 signature
[i
] = byte_get (hdrptr
, 1);
2158 type_offset
= byte_get (hdrptr
, offset_size
);
2159 hdrptr
+= offset_size
;
2162 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
2163 && num_debug_info_entries
== 0
2166 debug_information
[unit
].cu_offset
= cu_offset
;
2167 debug_information
[unit
].pointer_size
2168 = compunit
.cu_pointer_size
;
2169 debug_information
[unit
].offset_size
= offset_size
;
2170 debug_information
[unit
].dwarf_version
= compunit
.cu_version
;
2171 debug_information
[unit
].base_address
= 0;
2172 debug_information
[unit
].loc_offsets
= NULL
;
2173 debug_information
[unit
].have_frame_base
= NULL
;
2174 debug_information
[unit
].max_loc_offsets
= 0;
2175 debug_information
[unit
].num_loc_offsets
= 0;
2176 debug_information
[unit
].range_lists
= NULL
;
2177 debug_information
[unit
].max_range_lists
= 0;
2178 debug_information
[unit
].num_range_lists
= 0;
2181 if (!do_loc
&& dwarf_start_die
== 0)
2183 printf (_(" Compilation Unit @ offset 0x%s:\n"),
2184 dwarf_vmatoa ("x", cu_offset
));
2185 printf (_(" Length: 0x%s (%s)\n"),
2186 dwarf_vmatoa ("x", compunit
.cu_length
),
2187 offset_size
== 8 ? "64-bit" : "32-bit");
2188 printf (_(" Version: %d\n"), compunit
.cu_version
);
2189 printf (_(" Abbrev Offset: %s\n"),
2190 dwarf_vmatoa ("d", compunit
.cu_abbrev_offset
));
2191 printf (_(" Pointer Size: %d\n"), compunit
.cu_pointer_size
);
2195 printf (_(" Signature: "));
2196 for (i
= 0; i
< 8; i
++)
2197 printf ("%02x", signature
[i
]);
2199 printf (_(" Type Offset: 0x%s\n"),
2200 dwarf_vmatoa ("x", type_offset
));
2204 if (cu_offset
+ compunit
.cu_length
+ initial_length_size
2207 warn (_("Debug info is corrupted, length of CU at %s"
2208 " extends beyond end of section (length = %s)\n"),
2209 dwarf_vmatoa ("x", cu_offset
),
2210 dwarf_vmatoa ("x", compunit
.cu_length
));
2214 start
+= compunit
.cu_length
+ initial_length_size
;
2216 if (compunit
.cu_version
!= 2
2217 && compunit
.cu_version
!= 3
2218 && compunit
.cu_version
!= 4)
2220 warn (_("CU at offset %s contains corrupt or "
2221 "unsupported version number: %d.\n"),
2222 dwarf_vmatoa ("x", cu_offset
), compunit
.cu_version
);
2228 /* Process the abbrevs used by this compilation unit. DWARF
2229 sections under Mach-O have non-zero addresses. */
2230 if (compunit
.cu_abbrev_offset
>= debug_displays
[abbrev_sec
].section
.size
)
2231 warn (_("Debug info is corrupted, abbrev offset (%lx) is larger than abbrev section size (%lx)\n"),
2232 (unsigned long) compunit
.cu_abbrev_offset
,
2233 (unsigned long) debug_displays
[abbrev_sec
].section
.size
);
2235 process_abbrev_section
2236 ((unsigned char *) debug_displays
[abbrev_sec
].section
.start
2237 + compunit
.cu_abbrev_offset
,
2238 (unsigned char *) debug_displays
[abbrev_sec
].section
.start
2239 + debug_displays
[abbrev_sec
].section
.size
);
2244 while (tags
< start
)
2246 unsigned int bytes_read
;
2247 unsigned long abbrev_number
;
2248 unsigned long die_offset
;
2249 abbrev_entry
*entry
;
2251 int do_printing
= 1;
2253 die_offset
= tags
- section_begin
;
2255 abbrev_number
= read_leb128 (tags
, & bytes_read
, 0);
2258 /* A null DIE marks the end of a list of siblings or it may also be
2259 a section padding. */
2260 if (abbrev_number
== 0)
2262 /* Check if it can be a section padding for the last CU. */
2263 if (level
== 0 && start
== end
)
2267 for (chk
= tags
; chk
< start
; chk
++)
2277 static unsigned num_bogus_warns
= 0;
2279 if (num_bogus_warns
< 3)
2281 warn (_("Bogus end-of-siblings marker detected at offset %lx in .debug_info section\n"),
2284 if (num_bogus_warns
== 3)
2285 warn (_("Further warnings about bogus end-of-sibling markers suppressed\n"));
2288 if (dwarf_start_die
!= 0 && level
< saved_level
)
2295 if (dwarf_start_die
!= 0 && die_offset
< dwarf_start_die
)
2299 if (dwarf_start_die
!= 0 && die_offset
== dwarf_start_die
)
2300 saved_level
= level
;
2301 do_printing
= (dwarf_cutoff_level
== -1
2302 || level
< dwarf_cutoff_level
);
2304 printf (_(" <%d><%lx>: Abbrev Number: %lu"),
2305 level
, die_offset
, abbrev_number
);
2306 else if (dwarf_cutoff_level
== -1
2307 || last_level
< dwarf_cutoff_level
)
2308 printf (_(" <%d><%lx>: ...\n"), level
, die_offset
);
2313 /* Scan through the abbreviation list until we reach the
2315 for (entry
= first_abbrev
;
2316 entry
&& entry
->entry
!= abbrev_number
;
2317 entry
= entry
->next
)
2322 if (!do_loc
&& do_printing
)
2327 warn (_("DIE at offset %lx refers to abbreviation number %lu which does not exist\n"),
2328 die_offset
, abbrev_number
);
2332 if (!do_loc
&& do_printing
)
2333 printf (" (%s)\n", get_TAG_name (entry
->tag
));
2338 need_base_address
= 0;
2340 case DW_TAG_compile_unit
:
2341 need_base_address
= 1;
2343 case DW_TAG_entry_point
:
2344 case DW_TAG_subprogram
:
2345 need_base_address
= 0;
2346 /* Assuming that there is no DW_AT_frame_base. */
2347 have_frame_base
= 0;
2351 for (attr
= entry
->first_attr
; attr
; attr
= attr
->next
)
2355 if (! do_loc
&& do_printing
)
2356 /* Show the offset from where the tag was extracted. */
2357 printf (" <%lx>", (unsigned long)(tags
- section_begin
));
2359 arg
= debug_information
;
2360 if (debug_information
)
2363 tags
= read_and_display_attr (attr
->attribute
,
2366 compunit
.cu_pointer_size
,
2368 compunit
.cu_version
,
2370 do_loc
|| ! do_printing
, section
);
2373 if (entry
->children
)
2378 /* Set num_debug_info_entries here so that it can be used to check if
2379 we need to process .debug_loc and .debug_ranges sections. */
2380 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
2381 && num_debug_info_entries
== 0
2383 num_debug_info_entries
= num_units
;
2391 /* Locate and scan the .debug_info section in the file and record the pointer
2392 sizes and offsets for the compilation units in it. Usually an executable
2393 will have just one pointer size, but this is not guaranteed, and so we try
2394 not to make any assumptions. Returns zero upon failure, or the number of
2395 compilation units upon success. */
2398 load_debug_info (void * file
)
2400 /* Reset the last pointer size so that we can issue correct error
2401 messages if we are displaying the contents of more than one section. */
2402 last_pointer_size
= 0;
2403 warned_about_missing_comp_units
= FALSE
;
2405 /* If we have already tried and failed to load the .debug_info
2406 section then do not bother to repear the task. */
2407 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
2410 /* If we already have the information there is nothing else to do. */
2411 if (num_debug_info_entries
> 0)
2412 return num_debug_info_entries
;
2414 if (load_debug_section (info
, file
)
2415 && process_debug_info (&debug_displays
[info
].section
, file
, abbrev
, 1, 0))
2416 return num_debug_info_entries
;
2418 num_debug_info_entries
= DEBUG_INFO_UNAVAILABLE
;
2423 display_debug_lines_raw (struct dwarf_section
*section
,
2424 unsigned char *data
,
2427 unsigned char *start
= section
->start
;
2429 printf (_("Raw dump of debug contents of section %s:\n\n"),
2434 DWARF2_Internal_LineInfo linfo
;
2435 unsigned char *standard_opcodes
;
2436 unsigned char *end_of_sequence
;
2437 unsigned char *hdrptr
;
2438 unsigned long hdroff
;
2439 int initial_length_size
;
2444 hdroff
= hdrptr
- start
;
2446 /* Check the length of the block. */
2447 linfo
.li_length
= byte_get (hdrptr
, 4);
2450 if (linfo
.li_length
== 0xffffffff)
2452 /* This section is 64-bit DWARF 3. */
2453 linfo
.li_length
= byte_get (hdrptr
, 8);
2456 initial_length_size
= 12;
2461 initial_length_size
= 4;
2464 if (linfo
.li_length
+ initial_length_size
> section
->size
)
2467 (_("The information in section %s appears to be corrupt - the section is too small\n"),
2472 /* Check its version number. */
2473 linfo
.li_version
= byte_get (hdrptr
, 2);
2475 if (linfo
.li_version
!= 2
2476 && linfo
.li_version
!= 3
2477 && linfo
.li_version
!= 4)
2479 warn (_("Only DWARF version 2, 3 and 4 line info is currently supported.\n"));
2483 linfo
.li_prologue_length
= byte_get (hdrptr
, offset_size
);
2484 hdrptr
+= offset_size
;
2485 linfo
.li_min_insn_length
= byte_get (hdrptr
, 1);
2487 if (linfo
.li_version
>= 4)
2489 linfo
.li_max_ops_per_insn
= byte_get (hdrptr
, 1);
2491 if (linfo
.li_max_ops_per_insn
== 0)
2493 warn (_("Invalid maximum operations per insn.\n"));
2498 linfo
.li_max_ops_per_insn
= 1;
2499 linfo
.li_default_is_stmt
= byte_get (hdrptr
, 1);
2501 linfo
.li_line_base
= byte_get (hdrptr
, 1);
2503 linfo
.li_line_range
= byte_get (hdrptr
, 1);
2505 linfo
.li_opcode_base
= byte_get (hdrptr
, 1);
2508 /* Sign extend the line base field. */
2509 linfo
.li_line_base
<<= 24;
2510 linfo
.li_line_base
>>= 24;
2512 printf (_(" Offset: 0x%lx\n"), hdroff
);
2513 printf (_(" Length: %ld\n"), (long) linfo
.li_length
);
2514 printf (_(" DWARF Version: %d\n"), linfo
.li_version
);
2515 printf (_(" Prologue Length: %d\n"), linfo
.li_prologue_length
);
2516 printf (_(" Minimum Instruction Length: %d\n"), linfo
.li_min_insn_length
);
2517 if (linfo
.li_version
>= 4)
2518 printf (_(" Maximum Ops per Instruction: %d\n"), linfo
.li_max_ops_per_insn
);
2519 printf (_(" Initial value of 'is_stmt': %d\n"), linfo
.li_default_is_stmt
);
2520 printf (_(" Line Base: %d\n"), linfo
.li_line_base
);
2521 printf (_(" Line Range: %d\n"), linfo
.li_line_range
);
2522 printf (_(" Opcode Base: %d\n"), linfo
.li_opcode_base
);
2524 end_of_sequence
= data
+ linfo
.li_length
+ initial_length_size
;
2526 reset_state_machine (linfo
.li_default_is_stmt
);
2528 /* Display the contents of the Opcodes table. */
2529 standard_opcodes
= hdrptr
;
2531 printf (_("\n Opcodes:\n"));
2533 for (i
= 1; i
< linfo
.li_opcode_base
; i
++)
2534 printf (_(" Opcode %d has %d args\n"), i
, standard_opcodes
[i
- 1]);
2536 /* Display the contents of the Directory table. */
2537 data
= standard_opcodes
+ linfo
.li_opcode_base
- 1;
2540 printf (_("\n The Directory Table is empty.\n"));
2543 printf (_("\n The Directory Table:\n"));
2547 printf (" %s\n", data
);
2549 data
+= strlen ((char *) data
) + 1;
2553 /* Skip the NUL at the end of the table. */
2556 /* Display the contents of the File Name table. */
2558 printf (_("\n The File Name Table is empty.\n"));
2561 printf (_("\n The File Name Table:\n"));
2562 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
2566 unsigned char *name
;
2567 unsigned int bytes_read
;
2569 printf (" %d\t", ++state_machine_regs
.last_file_entry
);
2572 data
+= strlen ((char *) data
) + 1;
2575 dwarf_vmatoa ("u", read_leb128 (data
, & bytes_read
, 0)));
2578 dwarf_vmatoa ("u", read_leb128 (data
, & bytes_read
, 0)));
2581 dwarf_vmatoa ("u", read_leb128 (data
, & bytes_read
, 0)));
2583 printf ("%s\n", name
);
2587 /* Skip the NUL at the end of the table. */
2590 /* Now display the statements. */
2591 printf (_("\n Line Number Statements:\n"));
2593 while (data
< end_of_sequence
)
2595 unsigned char op_code
;
2596 dwarf_signed_vma adv
;
2598 unsigned int bytes_read
;
2602 if (op_code
>= linfo
.li_opcode_base
)
2604 op_code
-= linfo
.li_opcode_base
;
2605 uladv
= (op_code
/ linfo
.li_line_range
);
2606 if (linfo
.li_max_ops_per_insn
== 1)
2608 uladv
*= linfo
.li_min_insn_length
;
2609 state_machine_regs
.address
+= uladv
;
2610 printf (_(" Special opcode %d: "
2611 "advance Address by %s to 0x%s"),
2612 op_code
, dwarf_vmatoa ("u", uladv
),
2613 dwarf_vmatoa ("x", state_machine_regs
.address
));
2617 state_machine_regs
.address
2618 += ((state_machine_regs
.op_index
+ uladv
)
2619 / linfo
.li_max_ops_per_insn
)
2620 * linfo
.li_min_insn_length
;
2621 state_machine_regs
.op_index
2622 = (state_machine_regs
.op_index
+ uladv
)
2623 % linfo
.li_max_ops_per_insn
;
2624 printf (_(" Special opcode %d: "
2625 "advance Address by %s to 0x%s[%d]"),
2626 op_code
, dwarf_vmatoa ("u", uladv
),
2627 dwarf_vmatoa ("x", state_machine_regs
.address
),
2628 state_machine_regs
.op_index
);
2630 adv
= (op_code
% linfo
.li_line_range
) + linfo
.li_line_base
;
2631 state_machine_regs
.line
+= adv
;
2632 printf (_(" and Line by %s to %d\n"),
2633 dwarf_vmatoa ("d", adv
), state_machine_regs
.line
);
2635 else switch (op_code
)
2637 case DW_LNS_extended_op
:
2638 data
+= process_extended_line_op (data
, linfo
.li_default_is_stmt
);
2642 printf (_(" Copy\n"));
2645 case DW_LNS_advance_pc
:
2646 uladv
= read_leb128 (data
, & bytes_read
, 0);
2648 if (linfo
.li_max_ops_per_insn
== 1)
2650 uladv
*= linfo
.li_min_insn_length
;
2651 state_machine_regs
.address
+= uladv
;
2652 printf (_(" Advance PC by %s to 0x%s\n"),
2653 dwarf_vmatoa ("u", uladv
),
2654 dwarf_vmatoa ("x", state_machine_regs
.address
));
2658 state_machine_regs
.address
2659 += ((state_machine_regs
.op_index
+ uladv
)
2660 / linfo
.li_max_ops_per_insn
)
2661 * linfo
.li_min_insn_length
;
2662 state_machine_regs
.op_index
2663 = (state_machine_regs
.op_index
+ uladv
)
2664 % linfo
.li_max_ops_per_insn
;
2665 printf (_(" Advance PC by %s to 0x%s[%d]\n"),
2666 dwarf_vmatoa ("u", uladv
),
2667 dwarf_vmatoa ("x", state_machine_regs
.address
),
2668 state_machine_regs
.op_index
);
2672 case DW_LNS_advance_line
:
2673 adv
= read_sleb128 (data
, & bytes_read
);
2675 state_machine_regs
.line
+= adv
;
2676 printf (_(" Advance Line by %s to %d\n"),
2677 dwarf_vmatoa ("d", adv
),
2678 state_machine_regs
.line
);
2681 case DW_LNS_set_file
:
2682 adv
= read_leb128 (data
, & bytes_read
, 0);
2684 printf (_(" Set File Name to entry %s in the File Name Table\n"),
2685 dwarf_vmatoa ("d", adv
));
2686 state_machine_regs
.file
= adv
;
2689 case DW_LNS_set_column
:
2690 uladv
= read_leb128 (data
, & bytes_read
, 0);
2692 printf (_(" Set column to %s\n"),
2693 dwarf_vmatoa ("u", uladv
));
2694 state_machine_regs
.column
= uladv
;
2697 case DW_LNS_negate_stmt
:
2698 adv
= state_machine_regs
.is_stmt
;
2700 printf (_(" Set is_stmt to %s\n"), dwarf_vmatoa ("d", adv
));
2701 state_machine_regs
.is_stmt
= adv
;
2704 case DW_LNS_set_basic_block
:
2705 printf (_(" Set basic block\n"));
2706 state_machine_regs
.basic_block
= 1;
2709 case DW_LNS_const_add_pc
:
2710 uladv
= ((255 - linfo
.li_opcode_base
) / linfo
.li_line_range
);
2711 if (linfo
.li_max_ops_per_insn
)
2713 uladv
*= linfo
.li_min_insn_length
;
2714 state_machine_regs
.address
+= uladv
;
2715 printf (_(" Advance PC by constant %s to 0x%s\n"),
2716 dwarf_vmatoa ("u", uladv
),
2717 dwarf_vmatoa ("x", state_machine_regs
.address
));
2721 state_machine_regs
.address
2722 += ((state_machine_regs
.op_index
+ uladv
)
2723 / linfo
.li_max_ops_per_insn
)
2724 * linfo
.li_min_insn_length
;
2725 state_machine_regs
.op_index
2726 = (state_machine_regs
.op_index
+ uladv
)
2727 % linfo
.li_max_ops_per_insn
;
2728 printf (_(" Advance PC by constant %s to 0x%s[%d]\n"),
2729 dwarf_vmatoa ("u", uladv
),
2730 dwarf_vmatoa ("x", state_machine_regs
.address
),
2731 state_machine_regs
.op_index
);
2735 case DW_LNS_fixed_advance_pc
:
2736 uladv
= byte_get (data
, 2);
2738 state_machine_regs
.address
+= uladv
;
2739 state_machine_regs
.op_index
= 0;
2740 printf (_(" Advance PC by fixed size amount %s to 0x%s\n"),
2741 dwarf_vmatoa ("u", uladv
),
2742 dwarf_vmatoa ("x", state_machine_regs
.address
));
2745 case DW_LNS_set_prologue_end
:
2746 printf (_(" Set prologue_end to true\n"));
2749 case DW_LNS_set_epilogue_begin
:
2750 printf (_(" Set epilogue_begin to true\n"));
2753 case DW_LNS_set_isa
:
2754 uladv
= read_leb128 (data
, & bytes_read
, 0);
2756 printf (_(" Set ISA to %s\n"), dwarf_vmatoa ("u", uladv
));
2760 printf (_(" Unknown opcode %d with operands: "), op_code
);
2762 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
2764 printf ("0x%s%s", dwarf_vmatoa ("x", read_leb128 (data
,
2766 i
== 1 ? "" : ", ");
2781 unsigned char *name
;
2782 unsigned int directory_index
;
2783 unsigned int modification_date
;
2784 unsigned int length
;
2787 /* Output a decoded representation of the .debug_line section. */
2790 display_debug_lines_decoded (struct dwarf_section
*section
,
2791 unsigned char *data
,
2794 printf (_("Decoded dump of debug contents of section %s:\n\n"),
2799 /* This loop amounts to one iteration per compilation unit. */
2800 DWARF2_Internal_LineInfo linfo
;
2801 unsigned char *standard_opcodes
;
2802 unsigned char *end_of_sequence
;
2803 unsigned char *hdrptr
;
2804 int initial_length_size
;
2807 File_Entry
*file_table
= NULL
;
2808 unsigned int n_files
= 0;
2809 unsigned char **directory_table
= NULL
;
2810 unsigned int n_directories
= 0;
2814 /* Extract information from the Line Number Program Header.
2815 (section 6.2.4 in the Dwarf3 doc). */
2817 /* Get the length of this CU's line number information block. */
2818 linfo
.li_length
= byte_get (hdrptr
, 4);
2821 if (linfo
.li_length
== 0xffffffff)
2823 /* This section is 64-bit DWARF 3. */
2824 linfo
.li_length
= byte_get (hdrptr
, 8);
2827 initial_length_size
= 12;
2832 initial_length_size
= 4;
2835 if (linfo
.li_length
+ initial_length_size
> section
->size
)
2837 warn (_("The line info appears to be corrupt - "
2838 "the section is too small\n"));
2842 /* Get this CU's Line Number Block version number. */
2843 linfo
.li_version
= byte_get (hdrptr
, 2);
2845 if (linfo
.li_version
!= 2
2846 && linfo
.li_version
!= 3
2847 && linfo
.li_version
!= 4)
2849 warn (_("Only DWARF version 2, 3 and 4 line info is currently "
2854 linfo
.li_prologue_length
= byte_get (hdrptr
, offset_size
);
2855 hdrptr
+= offset_size
;
2856 linfo
.li_min_insn_length
= byte_get (hdrptr
, 1);
2858 if (linfo
.li_version
>= 4)
2860 linfo
.li_max_ops_per_insn
= byte_get (hdrptr
, 1);
2862 if (linfo
.li_max_ops_per_insn
== 0)
2864 warn (_("Invalid maximum operations per insn.\n"));
2869 linfo
.li_max_ops_per_insn
= 1;
2870 linfo
.li_default_is_stmt
= byte_get (hdrptr
, 1);
2872 linfo
.li_line_base
= byte_get (hdrptr
, 1);
2874 linfo
.li_line_range
= byte_get (hdrptr
, 1);
2876 linfo
.li_opcode_base
= byte_get (hdrptr
, 1);
2879 /* Sign extend the line base field. */
2880 linfo
.li_line_base
<<= 24;
2881 linfo
.li_line_base
>>= 24;
2883 /* Find the end of this CU's Line Number Information Block. */
2884 end_of_sequence
= data
+ linfo
.li_length
+ initial_length_size
;
2886 reset_state_machine (linfo
.li_default_is_stmt
);
2888 /* Save a pointer to the contents of the Opcodes table. */
2889 standard_opcodes
= hdrptr
;
2891 /* Traverse the Directory table just to count entries. */
2892 data
= standard_opcodes
+ linfo
.li_opcode_base
- 1;
2895 unsigned char *ptr_directory_table
= data
;
2899 data
+= strlen ((char *) data
) + 1;
2903 /* Go through the directory table again to save the directories. */
2904 directory_table
= (unsigned char **)
2905 xmalloc (n_directories
* sizeof (unsigned char *));
2908 while (*ptr_directory_table
!= 0)
2910 directory_table
[i
] = ptr_directory_table
;
2911 ptr_directory_table
+= strlen ((char *) ptr_directory_table
) + 1;
2915 /* Skip the NUL at the end of the table. */
2918 /* Traverse the File Name table just to count the entries. */
2921 unsigned char *ptr_file_name_table
= data
;
2925 unsigned int bytes_read
;
2927 /* Skip Name, directory index, last modification time and length
2929 data
+= strlen ((char *) data
) + 1;
2930 read_leb128 (data
, & bytes_read
, 0);
2932 read_leb128 (data
, & bytes_read
, 0);
2934 read_leb128 (data
, & bytes_read
, 0);
2940 /* Go through the file table again to save the strings. */
2941 file_table
= (File_Entry
*) xmalloc (n_files
* sizeof (File_Entry
));
2944 while (*ptr_file_name_table
!= 0)
2946 unsigned int bytes_read
;
2948 file_table
[i
].name
= ptr_file_name_table
;
2949 ptr_file_name_table
+= strlen ((char *) ptr_file_name_table
) + 1;
2951 /* We are not interested in directory, time or size. */
2952 file_table
[i
].directory_index
= read_leb128 (ptr_file_name_table
,
2954 ptr_file_name_table
+= bytes_read
;
2955 file_table
[i
].modification_date
= read_leb128 (ptr_file_name_table
,
2957 ptr_file_name_table
+= bytes_read
;
2958 file_table
[i
].length
= read_leb128 (ptr_file_name_table
, & bytes_read
, 0);
2959 ptr_file_name_table
+= bytes_read
;
2964 /* Print the Compilation Unit's name and a header. */
2965 if (directory_table
== NULL
)
2967 printf (_("CU: %s:\n"), file_table
[0].name
);
2968 printf (_("File name Line number Starting address\n"));
2972 unsigned int ix
= file_table
[0].directory_index
;
2973 const char *directory
= ix
? (char *)directory_table
[ix
- 1] : ".";
2974 if (do_wide
|| strlen (directory
) < 76)
2975 printf (_("CU: %s/%s:\n"), directory
, file_table
[0].name
);
2977 printf ("%s:\n", file_table
[0].name
);
2979 printf (_("File name Line number Starting address\n"));
2983 /* Skip the NUL at the end of the table. */
2986 /* This loop iterates through the Dwarf Line Number Program. */
2987 while (data
< end_of_sequence
)
2989 unsigned char op_code
;
2991 unsigned long int uladv
;
2992 unsigned int bytes_read
;
2993 int is_special_opcode
= 0;
2997 if (op_code
>= linfo
.li_opcode_base
)
2999 op_code
-= linfo
.li_opcode_base
;
3000 uladv
= (op_code
/ linfo
.li_line_range
);
3001 if (linfo
.li_max_ops_per_insn
== 1)
3003 uladv
*= linfo
.li_min_insn_length
;
3004 state_machine_regs
.address
+= uladv
;
3008 state_machine_regs
.address
3009 += ((state_machine_regs
.op_index
+ uladv
)
3010 / linfo
.li_max_ops_per_insn
)
3011 * linfo
.li_min_insn_length
;
3012 state_machine_regs
.op_index
3013 = (state_machine_regs
.op_index
+ uladv
)
3014 % linfo
.li_max_ops_per_insn
;
3017 adv
= (op_code
% linfo
.li_line_range
) + linfo
.li_line_base
;
3018 state_machine_regs
.line
+= adv
;
3019 is_special_opcode
= 1;
3021 else switch (op_code
)
3023 case DW_LNS_extended_op
:
3025 unsigned int ext_op_code_len
;
3026 unsigned char ext_op_code
;
3027 unsigned char *op_code_data
= data
;
3029 ext_op_code_len
= read_leb128 (op_code_data
, &bytes_read
, 0);
3030 op_code_data
+= bytes_read
;
3032 if (ext_op_code_len
== 0)
3034 warn (_("badly formed extended line op encountered!\n"));
3037 ext_op_code_len
+= bytes_read
;
3038 ext_op_code
= *op_code_data
++;
3040 switch (ext_op_code
)
3042 case DW_LNE_end_sequence
:
3043 reset_state_machine (linfo
.li_default_is_stmt
);
3045 case DW_LNE_set_address
:
3046 state_machine_regs
.address
=
3047 byte_get (op_code_data
, ext_op_code_len
- bytes_read
- 1);
3048 state_machine_regs
.op_index
= 0;
3050 case DW_LNE_define_file
:
3052 file_table
= (File_Entry
*) xrealloc
3053 (file_table
, (n_files
+ 1) * sizeof (File_Entry
));
3055 ++state_machine_regs
.last_file_entry
;
3056 /* Source file name. */
3057 file_table
[n_files
].name
= op_code_data
;
3058 op_code_data
+= strlen ((char *) op_code_data
) + 1;
3059 /* Directory index. */
3060 file_table
[n_files
].directory_index
=
3061 read_leb128 (op_code_data
, & bytes_read
, 0);
3062 op_code_data
+= bytes_read
;
3063 /* Last modification time. */
3064 file_table
[n_files
].modification_date
=
3065 read_leb128 (op_code_data
, & bytes_read
, 0);
3066 op_code_data
+= bytes_read
;
3068 file_table
[n_files
].length
=
3069 read_leb128 (op_code_data
, & bytes_read
, 0);
3074 case DW_LNE_set_discriminator
:
3075 case DW_LNE_HP_set_sequence
:
3076 /* Simply ignored. */
3080 printf (_("UNKNOWN (%u): length %d\n"),
3081 ext_op_code
, ext_op_code_len
- bytes_read
);
3084 data
+= ext_op_code_len
;
3090 case DW_LNS_advance_pc
:
3091 uladv
= read_leb128 (data
, & bytes_read
, 0);
3093 if (linfo
.li_max_ops_per_insn
== 1)
3095 uladv
*= linfo
.li_min_insn_length
;
3096 state_machine_regs
.address
+= uladv
;
3100 state_machine_regs
.address
3101 += ((state_machine_regs
.op_index
+ uladv
)
3102 / linfo
.li_max_ops_per_insn
)
3103 * linfo
.li_min_insn_length
;
3104 state_machine_regs
.op_index
3105 = (state_machine_regs
.op_index
+ uladv
)
3106 % linfo
.li_max_ops_per_insn
;
3110 case DW_LNS_advance_line
:
3111 adv
= read_sleb128 (data
, & bytes_read
);
3113 state_machine_regs
.line
+= adv
;
3116 case DW_LNS_set_file
:
3117 adv
= read_leb128 (data
, & bytes_read
, 0);
3119 state_machine_regs
.file
= adv
;
3120 if (file_table
[state_machine_regs
.file
- 1].directory_index
== 0)
3122 /* If directory index is 0, that means current directory. */
3123 printf ("\n./%s:[++]\n",
3124 file_table
[state_machine_regs
.file
- 1].name
);
3128 /* The directory index starts counting at 1. */
3129 printf ("\n%s/%s:\n",
3130 directory_table
[file_table
[state_machine_regs
.file
- 1].directory_index
- 1],
3131 file_table
[state_machine_regs
.file
- 1].name
);
3135 case DW_LNS_set_column
:
3136 uladv
= read_leb128 (data
, & bytes_read
, 0);
3138 state_machine_regs
.column
= uladv
;
3141 case DW_LNS_negate_stmt
:
3142 adv
= state_machine_regs
.is_stmt
;
3144 state_machine_regs
.is_stmt
= adv
;
3147 case DW_LNS_set_basic_block
:
3148 state_machine_regs
.basic_block
= 1;
3151 case DW_LNS_const_add_pc
:
3152 uladv
= ((255 - linfo
.li_opcode_base
) / linfo
.li_line_range
);
3153 if (linfo
.li_max_ops_per_insn
== 1)
3155 uladv
*= linfo
.li_min_insn_length
;
3156 state_machine_regs
.address
+= uladv
;
3160 state_machine_regs
.address
3161 += ((state_machine_regs
.op_index
+ uladv
)
3162 / linfo
.li_max_ops_per_insn
)
3163 * linfo
.li_min_insn_length
;
3164 state_machine_regs
.op_index
3165 = (state_machine_regs
.op_index
+ uladv
)
3166 % linfo
.li_max_ops_per_insn
;
3170 case DW_LNS_fixed_advance_pc
:
3171 uladv
= byte_get (data
, 2);
3173 state_machine_regs
.address
+= uladv
;
3174 state_machine_regs
.op_index
= 0;
3177 case DW_LNS_set_prologue_end
:
3180 case DW_LNS_set_epilogue_begin
:
3183 case DW_LNS_set_isa
:
3184 uladv
= read_leb128 (data
, & bytes_read
, 0);
3186 printf (_(" Set ISA to %lu\n"), uladv
);
3190 printf (_(" Unknown opcode %d with operands: "), op_code
);
3192 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
3194 printf ("0x%s%s", dwarf_vmatoa ("x", read_leb128 (data
,
3196 i
== 1 ? "" : ", ");
3203 /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row
3204 to the DWARF address/line matrix. */
3205 if ((is_special_opcode
) || (op_code
== DW_LNE_end_sequence
)
3206 || (op_code
== DW_LNS_copy
))
3208 const unsigned int MAX_FILENAME_LENGTH
= 35;
3209 char *fileName
= (char *)file_table
[state_machine_regs
.file
- 1].name
;
3210 char *newFileName
= NULL
;
3211 size_t fileNameLength
= strlen (fileName
);
3213 if ((fileNameLength
> MAX_FILENAME_LENGTH
) && (!do_wide
))
3215 newFileName
= (char *) xmalloc (MAX_FILENAME_LENGTH
+ 1);
3216 /* Truncate file name */
3217 strncpy (newFileName
,
3218 fileName
+ fileNameLength
- MAX_FILENAME_LENGTH
,
3219 MAX_FILENAME_LENGTH
+ 1);
3223 newFileName
= (char *) xmalloc (fileNameLength
+ 1);
3224 strncpy (newFileName
, fileName
, fileNameLength
+ 1);
3227 if (!do_wide
|| (fileNameLength
<= MAX_FILENAME_LENGTH
))
3229 if (linfo
.li_max_ops_per_insn
== 1)
3230 printf ("%-35s %11d %#18" DWARF_VMA_FMT
"x\n",
3231 newFileName
, state_machine_regs
.line
,
3232 state_machine_regs
.address
);
3234 printf ("%-35s %11d %#18" DWARF_VMA_FMT
"x[%d]\n",
3235 newFileName
, state_machine_regs
.line
,
3236 state_machine_regs
.address
,
3237 state_machine_regs
.op_index
);
3241 if (linfo
.li_max_ops_per_insn
== 1)
3242 printf ("%s %11d %#18" DWARF_VMA_FMT
"x\n",
3243 newFileName
, state_machine_regs
.line
,
3244 state_machine_regs
.address
);
3246 printf ("%s %11d %#18" DWARF_VMA_FMT
"x[%d]\n",
3247 newFileName
, state_machine_regs
.line
,
3248 state_machine_regs
.address
,
3249 state_machine_regs
.op_index
);
3252 if (op_code
== DW_LNE_end_sequence
)
3260 free (directory_table
);
3261 directory_table
= NULL
;
3269 display_debug_lines (struct dwarf_section
*section
, void *file ATTRIBUTE_UNUSED
)
3271 unsigned char *data
= section
->start
;
3272 unsigned char *end
= data
+ section
->size
;
3274 int retValDecoded
= 1;
3276 if (do_debug_lines
== 0)
3277 do_debug_lines
|= FLAG_DEBUG_LINES_RAW
;
3279 if (do_debug_lines
& FLAG_DEBUG_LINES_RAW
)
3280 retValRaw
= display_debug_lines_raw (section
, data
, end
);
3282 if (do_debug_lines
& FLAG_DEBUG_LINES_DECODED
)
3283 retValDecoded
= display_debug_lines_decoded (section
, data
, end
);
3285 if (!retValRaw
|| !retValDecoded
)
3292 find_debug_info_for_offset (unsigned long offset
)
3296 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
3299 for (i
= 0; i
< num_debug_info_entries
; i
++)
3300 if (debug_information
[i
].cu_offset
== offset
)
3301 return debug_information
+ i
;
3307 display_debug_pubnames (struct dwarf_section
*section
,
3308 void *file ATTRIBUTE_UNUSED
)
3310 DWARF2_Internal_PubNames names
;
3311 unsigned char *start
= section
->start
;
3312 unsigned char *end
= start
+ section
->size
;
3314 /* It does not matter if this load fails,
3315 we test for that later on. */
3316 load_debug_info (file
);
3318 printf (_("Contents of the %s section:\n\n"), section
->name
);
3322 unsigned char *data
;
3323 unsigned long offset
;
3324 int offset_size
, initial_length_size
;
3328 names
.pn_length
= byte_get (data
, 4);
3330 if (names
.pn_length
== 0xffffffff)
3332 names
.pn_length
= byte_get (data
, 8);
3335 initial_length_size
= 12;
3340 initial_length_size
= 4;
3343 names
.pn_version
= byte_get (data
, 2);
3346 names
.pn_offset
= byte_get (data
, offset_size
);
3347 data
+= offset_size
;
3349 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
3350 && num_debug_info_entries
> 0
3351 && find_debug_info_for_offset (names
.pn_offset
) == NULL
)
3352 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
3353 (unsigned long) names
.pn_offset
, section
->name
);
3355 names
.pn_size
= byte_get (data
, offset_size
);
3356 data
+= offset_size
;
3358 start
+= names
.pn_length
+ initial_length_size
;
3360 if (names
.pn_version
!= 2 && names
.pn_version
!= 3)
3362 static int warned
= 0;
3366 warn (_("Only DWARF 2 and 3 pubnames are currently supported\n"));
3373 printf (_(" Length: %ld\n"),
3374 (long) names
.pn_length
);
3375 printf (_(" Version: %d\n"),
3377 printf (_(" Offset into .debug_info section: 0x%lx\n"),
3378 (unsigned long) names
.pn_offset
);
3379 printf (_(" Size of area in .debug_info section: %ld\n"),
3380 (long) names
.pn_size
);
3382 printf (_("\n Offset\tName\n"));
3386 offset
= byte_get (data
, offset_size
);
3390 data
+= offset_size
;
3391 printf (" %-6lx\t%s\n", offset
, data
);
3392 data
+= strlen ((char *) data
) + 1;
3395 while (offset
!= 0);
3403 display_debug_macinfo (struct dwarf_section
*section
,
3404 void *file ATTRIBUTE_UNUSED
)
3406 unsigned char *start
= section
->start
;
3407 unsigned char *end
= start
+ section
->size
;
3408 unsigned char *curr
= start
;
3409 unsigned int bytes_read
;
3410 enum dwarf_macinfo_record_type op
;
3412 printf (_("Contents of the %s section:\n\n"), section
->name
);
3416 unsigned int lineno
;
3419 op
= (enum dwarf_macinfo_record_type
) *curr
;
3424 case DW_MACINFO_start_file
:
3426 unsigned int filenum
;
3428 lineno
= read_leb128 (curr
, & bytes_read
, 0);
3430 filenum
= read_leb128 (curr
, & bytes_read
, 0);
3433 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"),
3438 case DW_MACINFO_end_file
:
3439 printf (_(" DW_MACINFO_end_file\n"));
3442 case DW_MACINFO_define
:
3443 lineno
= read_leb128 (curr
, & bytes_read
, 0);
3445 string
= (char *) curr
;
3446 curr
+= strlen (string
) + 1;
3447 printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"),
3451 case DW_MACINFO_undef
:
3452 lineno
= read_leb128 (curr
, & bytes_read
, 0);
3454 string
= (char *) curr
;
3455 curr
+= strlen (string
) + 1;
3456 printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"),
3460 case DW_MACINFO_vendor_ext
:
3462 unsigned int constant
;
3464 constant
= read_leb128 (curr
, & bytes_read
, 0);
3466 string
= (char *) curr
;
3467 curr
+= strlen (string
) + 1;
3468 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"),
3478 /* Given LINE_OFFSET into the .debug_line section, attempt to return
3479 filename and dirname corresponding to file name table entry with index
3480 FILEIDX. Return NULL on failure. */
3482 static unsigned char *
3483 get_line_filename_and_dirname (dwarf_vma line_offset
, dwarf_vma fileidx
,
3484 unsigned char **dir_name
)
3486 struct dwarf_section
*section
= &debug_displays
[line
].section
;
3487 unsigned char *hdrptr
, *dirtable
, *file_name
;
3488 unsigned int offset_size
, initial_length_size
;
3489 unsigned int version
, opcode_base
, bytes_read
;
3490 dwarf_vma length
, diridx
;
3493 if (section
->start
== NULL
3494 || line_offset
>= section
->size
3498 hdrptr
= section
->start
+ line_offset
;
3499 length
= byte_get (hdrptr
, 4);
3501 if (length
== 0xffffffff)
3503 /* This section is 64-bit DWARF 3. */
3504 length
= byte_get (hdrptr
, 8);
3507 initial_length_size
= 12;
3512 initial_length_size
= 4;
3514 if (length
+ initial_length_size
> section
->size
)
3516 version
= byte_get (hdrptr
, 2);
3518 if (version
!= 2 && version
!= 3 && version
!= 4)
3520 hdrptr
+= offset_size
+ 1;/* Skip prologue_length and min_insn_length. */
3522 hdrptr
++; /* Skip max_ops_per_insn. */
3523 hdrptr
+= 3; /* Skip default_is_stmt, line_base, line_range. */
3524 opcode_base
= byte_get (hdrptr
, 1);
3525 if (opcode_base
== 0)
3528 hdrptr
+= opcode_base
- 1;
3530 /* Skip over dirname table. */
3531 while (*hdrptr
!= '\0')
3532 hdrptr
+= strlen ((char *) hdrptr
) + 1;
3533 hdrptr
++; /* Skip the NUL at the end of the table. */
3534 /* Now skip over preceding filename table entries. */
3535 for (; *hdrptr
!= '\0' && fileidx
> 1; fileidx
--)
3537 hdrptr
+= strlen ((char *) hdrptr
) + 1;
3538 read_leb128 (hdrptr
, &bytes_read
, 0);
3539 hdrptr
+= bytes_read
;
3540 read_leb128 (hdrptr
, &bytes_read
, 0);
3541 hdrptr
+= bytes_read
;
3542 read_leb128 (hdrptr
, &bytes_read
, 0);
3543 hdrptr
+= bytes_read
;
3545 if (*hdrptr
== '\0')
3548 hdrptr
+= strlen ((char *) hdrptr
) + 1;
3549 diridx
= read_leb128 (hdrptr
, &bytes_read
, 0);
3552 for (; *dirtable
!= '\0' && diridx
> 1; diridx
--)
3553 dirtable
+= strlen ((char *) dirtable
) + 1;
3554 if (*dirtable
== '\0')
3556 *dir_name
= dirtable
;
3561 display_debug_macro (struct dwarf_section
*section
,
3564 unsigned char *start
= section
->start
;
3565 unsigned char *end
= start
+ section
->size
;
3566 unsigned char *curr
= start
;
3567 unsigned char *extended_op_buf
[256];
3568 unsigned int bytes_read
;
3570 load_debug_section (str
, file
);
3571 load_debug_section (line
, file
);
3573 printf (_("Contents of the %s section:\n\n"), section
->name
);
3577 unsigned int lineno
, version
, flags
;
3578 unsigned int offset_size
= 4;
3580 dwarf_vma line_offset
= 0, sec_offset
= curr
- start
, offset
;
3581 unsigned char **extended_ops
= NULL
;
3583 version
= byte_get (curr
, 2);
3588 error (_("Only GNU extension to DWARF 4 of %s is currently supported.\n"),
3593 flags
= byte_get (curr
++, 1);
3596 printf (_(" Offset: 0x%lx\n"),
3597 (unsigned long) sec_offset
);
3598 printf (_(" Version: %d\n"), version
);
3599 printf (_(" Offset size: %d\n"), offset_size
);
3602 line_offset
= byte_get (curr
, offset_size
);
3603 curr
+= offset_size
;
3604 printf (_(" Offset into .debug_line: 0x%lx\n"),
3605 (unsigned long) line_offset
);
3609 unsigned int i
, count
= byte_get (curr
++, 1), op
;
3611 memset (extended_op_buf
, 0, sizeof (extended_op_buf
));
3612 extended_ops
= extended_op_buf
;
3615 printf (_(" Extension opcode arguments:\n"));
3616 for (i
= 0; i
< count
; i
++)
3618 op
= byte_get (curr
++, 1);
3619 extended_ops
[op
] = curr
;
3620 nargs
= read_leb128 (curr
, &bytes_read
, 0);
3623 printf (_(" DW_MACRO_GNU_%02x has no arguments\n"), op
);
3626 printf (_(" DW_MACRO_GNU_%02x arguments: "), op
);
3627 for (n
= 0; n
< nargs
; n
++)
3629 unsigned int form
= byte_get (curr
++, 1);
3630 printf ("%s%s", get_FORM_name (form
),
3631 n
== nargs
- 1 ? "\n" : ", ");
3641 case DW_FORM_block1
:
3642 case DW_FORM_block2
:
3643 case DW_FORM_block4
:
3645 case DW_FORM_string
:
3647 case DW_FORM_sec_offset
:
3650 error (_("Invalid extension opcode form %s\n"),
3651 get_FORM_name (form
));
3667 error (_(".debug_macro section not zero terminated\n"));
3671 op
= byte_get (curr
++, 1);
3677 case DW_MACRO_GNU_start_file
:
3679 unsigned int filenum
;
3680 unsigned char *file_name
= NULL
, *dir_name
= NULL
;
3682 lineno
= read_leb128 (curr
, &bytes_read
, 0);
3684 filenum
= read_leb128 (curr
, &bytes_read
, 0);
3687 if ((flags
& 2) == 0)
3688 error (_("DW_MACRO_GNU_start_file used, but no .debug_line offset provided.\n"));
3691 = get_line_filename_and_dirname (line_offset
, filenum
,
3693 if (file_name
== NULL
)
3694 printf (_(" DW_MACRO_GNU_start_file - lineno: %d filenum: %d\n"),
3697 printf (_(" DW_MACRO_GNU_start_file - lineno: %d filenum: %d filename: %s%s%s\n"),
3699 dir_name
!= NULL
? (const char *) dir_name
: "",
3700 dir_name
!= NULL
? "/" : "", file_name
);
3704 case DW_MACRO_GNU_end_file
:
3705 printf (_(" DW_MACRO_GNU_end_file\n"));
3708 case DW_MACRO_GNU_define
:
3709 lineno
= read_leb128 (curr
, &bytes_read
, 0);
3711 string
= (char *) curr
;
3712 curr
+= strlen (string
) + 1;
3713 printf (_(" DW_MACRO_GNU_define - lineno : %d macro : %s\n"),
3717 case DW_MACRO_GNU_undef
:
3718 lineno
= read_leb128 (curr
, &bytes_read
, 0);
3720 string
= (char *) curr
;
3721 curr
+= strlen (string
) + 1;
3722 printf (_(" DW_MACRO_GNU_undef - lineno : %d macro : %s\n"),
3726 case DW_MACRO_GNU_define_indirect
:
3727 lineno
= read_leb128 (curr
, &bytes_read
, 0);
3729 offset
= byte_get (curr
, offset_size
);
3730 curr
+= offset_size
;
3731 string
= fetch_indirect_string (offset
);
3732 printf (_(" DW_MACRO_GNU_define_indirect - lineno : %d macro : %s\n"),
3736 case DW_MACRO_GNU_undef_indirect
:
3737 lineno
= read_leb128 (curr
, &bytes_read
, 0);
3739 offset
= byte_get (curr
, offset_size
);
3740 curr
+= offset_size
;
3741 string
= fetch_indirect_string (offset
);
3742 printf (_(" DW_MACRO_GNU_undef_indirect - lineno : %d macro : %s\n"),
3746 case DW_MACRO_GNU_transparent_include
:
3747 offset
= byte_get (curr
, offset_size
);
3748 curr
+= offset_size
;
3749 printf (_(" DW_MACRO_GNU_transparent_include - offset : 0x%lx\n"),
3750 (unsigned long) offset
);
3754 if (extended_ops
== NULL
|| extended_ops
[op
] == NULL
)
3756 error (_(" Unknown macro opcode %02x seen\n"), op
);
3761 /* Skip over unhandled opcodes. */
3763 unsigned char *desc
= extended_ops
[op
];
3764 nargs
= read_leb128 (desc
, &bytes_read
, 0);
3768 printf (_(" DW_MACRO_GNU_%02x\n"), op
);
3771 printf (_(" DW_MACRO_GNU_%02x -"), op
);
3772 for (n
= 0; n
< nargs
; n
++)
3775 = read_and_display_attr_value (0, byte_get (desc
++, 1),
3776 curr
, 0, 0, offset_size
,
3777 version
, NULL
, 0, NULL
);
3794 display_debug_abbrev (struct dwarf_section
*section
,
3795 void *file ATTRIBUTE_UNUSED
)
3797 abbrev_entry
*entry
;
3798 unsigned char *start
= section
->start
;
3799 unsigned char *end
= start
+ section
->size
;
3801 printf (_("Contents of the %s section:\n\n"), section
->name
);
3807 start
= process_abbrev_section (start
, end
);
3809 if (first_abbrev
== NULL
)
3812 printf (_(" Number TAG\n"));
3814 for (entry
= first_abbrev
; entry
; entry
= entry
->next
)
3818 printf (" %ld %s [%s]\n",
3820 get_TAG_name (entry
->tag
),
3821 entry
->children
? _("has children") : _("no children"));
3823 for (attr
= entry
->first_attr
; attr
; attr
= attr
->next
)
3824 printf (" %-18s %s\n",
3825 get_AT_name (attr
->attribute
),
3826 get_FORM_name (attr
->form
));
3836 /* Sort array of indexes in ascending order of loc_offsets[idx]. */
3838 static dwarf_vma
*loc_offsets
;
3841 loc_offsets_compar (const void *ap
, const void *bp
)
3843 dwarf_vma a
= loc_offsets
[*(const unsigned int *) ap
];
3844 dwarf_vma b
= loc_offsets
[*(const unsigned int *) bp
];
3846 return (a
> b
) - (b
> a
);
3850 display_debug_loc (struct dwarf_section
*section
, void *file
)
3852 unsigned char *start
= section
->start
;
3853 unsigned char *section_end
;
3854 unsigned long bytes
;
3855 unsigned char *section_begin
= start
;
3856 unsigned int num_loc_list
= 0;
3857 unsigned long last_offset
= 0;
3858 unsigned int first
= 0;
3862 int seen_first_offset
= 0;
3863 int locs_sorted
= 1;
3864 unsigned char *next
;
3865 unsigned int *array
= NULL
;
3867 bytes
= section
->size
;
3868 section_end
= start
+ bytes
;
3872 printf (_("\nThe %s section is empty.\n"), section
->name
);
3876 if (load_debug_info (file
) == 0)
3878 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
3883 /* Check the order of location list in .debug_info section. If
3884 offsets of location lists are in the ascending order, we can
3885 use `debug_information' directly. */
3886 for (i
= 0; i
< num_debug_info_entries
; i
++)
3890 num
= debug_information
[i
].num_loc_offsets
;
3891 if (num
> num_loc_list
)
3894 /* Check if we can use `debug_information' directly. */
3895 if (locs_sorted
&& num
!= 0)
3897 if (!seen_first_offset
)
3899 /* This is the first location list. */
3900 last_offset
= debug_information
[i
].loc_offsets
[0];
3902 seen_first_offset
= 1;
3908 for (; j
< num
; j
++)
3911 debug_information
[i
].loc_offsets
[j
])
3916 last_offset
= debug_information
[i
].loc_offsets
[j
];
3921 if (!seen_first_offset
)
3922 error (_("No location lists in .debug_info section!\n"));
3924 /* DWARF sections under Mach-O have non-zero addresses. */
3925 if (debug_information
[first
].num_loc_offsets
> 0
3926 && debug_information
[first
].loc_offsets
[0] != section
->address
)
3927 warn (_("Location lists in %s section start at 0x%s\n"),
3929 dwarf_vmatoa ("x", debug_information
[first
].loc_offsets
[0]));
3932 array
= (unsigned int *) xcmalloc (num_loc_list
, sizeof (unsigned int));
3933 printf (_("Contents of the %s section:\n\n"), section
->name
);
3934 printf (_(" Offset Begin End Expression\n"));
3936 seen_first_offset
= 0;
3937 for (i
= first
; i
< num_debug_info_entries
; i
++)
3941 unsigned short length
;
3942 unsigned long offset
;
3943 unsigned int pointer_size
;
3944 unsigned int offset_size
;
3946 unsigned long cu_offset
;
3947 unsigned long base_address
;
3948 int need_frame_base
;
3951 pointer_size
= debug_information
[i
].pointer_size
;
3952 cu_offset
= debug_information
[i
].cu_offset
;
3953 offset_size
= debug_information
[i
].offset_size
;
3954 dwarf_version
= debug_information
[i
].dwarf_version
;
3957 for (k
= 0; k
< debug_information
[i
].num_loc_offsets
; k
++)
3959 loc_offsets
= debug_information
[i
].loc_offsets
;
3960 qsort (array
, debug_information
[i
].num_loc_offsets
,
3961 sizeof (*array
), loc_offsets_compar
);
3964 for (k
= 0; k
< debug_information
[i
].num_loc_offsets
; k
++)
3966 j
= locs_sorted
? k
: array
[k
];
3968 && debug_information
[i
].loc_offsets
[locs_sorted
3969 ? k
- 1 : array
[k
- 1]]
3970 == debug_information
[i
].loc_offsets
[j
])
3972 has_frame_base
= debug_information
[i
].have_frame_base
[j
];
3973 /* DWARF sections under Mach-O have non-zero addresses. */
3974 offset
= debug_information
[i
].loc_offsets
[j
] - section
->address
;
3975 next
= section_begin
+ offset
;
3976 base_address
= debug_information
[i
].base_address
;
3978 if (!seen_first_offset
)
3979 seen_first_offset
= 1;
3983 warn (_("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n"),
3984 (unsigned long) (start
- section_begin
),
3985 (unsigned long) (next
- section_begin
));
3986 else if (start
> next
)
3987 warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n"),
3988 (unsigned long) (start
- section_begin
),
3989 (unsigned long) (next
- section_begin
));
3993 if (offset
>= bytes
)
3995 warn (_("Offset 0x%lx is bigger than .debug_loc section size.\n"),
4002 if (start
+ 2 * pointer_size
> section_end
)
4004 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
4009 /* Note: we use sign extension here in order to be sure that
4010 we can detect the -1 escape value. Sign extension into the
4011 top 32 bits of a 32-bit address will not affect the values
4012 that we display since we always show hex values, and always
4013 the bottom 32-bits. */
4014 begin
= byte_get_signed (start
, pointer_size
);
4015 start
+= pointer_size
;
4016 end
= byte_get_signed (start
, pointer_size
);
4017 start
+= pointer_size
;
4019 printf (" %8.8lx ", offset
);
4021 if (begin
== 0 && end
== 0)
4023 printf (_("<End of list>\n"));
4027 /* Check base address specifiers. */
4028 if (begin
== (dwarf_vma
) -1 && end
!= (dwarf_vma
) -1)
4031 print_dwarf_vma (begin
, pointer_size
);
4032 print_dwarf_vma (end
, pointer_size
);
4033 printf (_("(base address)\n"));
4037 if (start
+ 2 > section_end
)
4039 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
4044 length
= byte_get (start
, 2);
4047 if (start
+ length
> section_end
)
4049 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
4054 print_dwarf_vma (begin
+ base_address
, pointer_size
);
4055 print_dwarf_vma (end
+ base_address
, pointer_size
);
4058 need_frame_base
= decode_location_expression (start
,
4063 cu_offset
, section
);
4066 if (need_frame_base
&& !has_frame_base
)
4067 printf (_(" [without DW_AT_frame_base]"));
4070 fputs (_(" (start == end)"), stdout
);
4071 else if (begin
> end
)
4072 fputs (_(" (start > end)"), stdout
);
4081 if (start
< section_end
)
4082 warn (_("There are %ld unused bytes at the end of section %s\n"),
4083 (long) (section_end
- start
), section
->name
);
4090 display_debug_str (struct dwarf_section
*section
,
4091 void *file ATTRIBUTE_UNUSED
)
4093 unsigned char *start
= section
->start
;
4094 unsigned long bytes
= section
->size
;
4095 dwarf_vma addr
= section
->address
;
4099 printf (_("\nThe %s section is empty.\n"), section
->name
);
4103 printf (_("Contents of the %s section:\n\n"), section
->name
);
4111 lbytes
= (bytes
> 16 ? 16 : bytes
);
4113 printf (" 0x%8.8lx ", (unsigned long) addr
);
4115 for (j
= 0; j
< 16; j
++)
4118 printf ("%2.2x", start
[j
]);
4126 for (j
= 0; j
< lbytes
; j
++)
4129 if (k
>= ' ' && k
< 0x80)
4148 display_debug_info (struct dwarf_section
*section
, void *file
)
4150 return process_debug_info (section
, file
, abbrev
, 0, 0);
4154 display_debug_types (struct dwarf_section
*section
, void *file
)
4156 return process_debug_info (section
, file
, abbrev
, 0, 1);
4160 display_trace_info (struct dwarf_section
*section
, void *file
)
4162 return process_debug_info (section
, file
, trace_abbrev
, 0, 0);
4166 display_debug_aranges (struct dwarf_section
*section
,
4167 void *file ATTRIBUTE_UNUSED
)
4169 unsigned char *start
= section
->start
;
4170 unsigned char *end
= start
+ section
->size
;
4172 printf (_("Contents of the %s section:\n\n"), section
->name
);
4174 /* It does not matter if this load fails,
4175 we test for that later on. */
4176 load_debug_info (file
);
4180 unsigned char *hdrptr
;
4181 DWARF2_Internal_ARange arange
;
4182 unsigned char *addr_ranges
;
4185 unsigned char address_size
;
4188 int initial_length_size
;
4192 arange
.ar_length
= byte_get (hdrptr
, 4);
4195 if (arange
.ar_length
== 0xffffffff)
4197 arange
.ar_length
= byte_get (hdrptr
, 8);
4200 initial_length_size
= 12;
4205 initial_length_size
= 4;
4208 arange
.ar_version
= byte_get (hdrptr
, 2);
4211 arange
.ar_info_offset
= byte_get (hdrptr
, offset_size
);
4212 hdrptr
+= offset_size
;
4214 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
4215 && num_debug_info_entries
> 0
4216 && find_debug_info_for_offset (arange
.ar_info_offset
) == NULL
)
4217 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
4218 (unsigned long) arange
.ar_info_offset
, section
->name
);
4220 arange
.ar_pointer_size
= byte_get (hdrptr
, 1);
4223 arange
.ar_segment_size
= byte_get (hdrptr
, 1);
4226 if (arange
.ar_version
!= 2 && arange
.ar_version
!= 3)
4228 warn (_("Only DWARF 2 and 3 aranges are currently supported.\n"));
4232 printf (_(" Length: %ld\n"),
4233 (long) arange
.ar_length
);
4234 printf (_(" Version: %d\n"), arange
.ar_version
);
4235 printf (_(" Offset into .debug_info: 0x%lx\n"),
4236 (unsigned long) arange
.ar_info_offset
);
4237 printf (_(" Pointer Size: %d\n"), arange
.ar_pointer_size
);
4238 printf (_(" Segment Size: %d\n"), arange
.ar_segment_size
);
4240 address_size
= arange
.ar_pointer_size
+ arange
.ar_segment_size
;
4242 if (address_size
== 0)
4244 error (_("Invalid address size in %s section!\n"),
4249 /* The DWARF spec does not require that the address size be a power
4250 of two, but we do. This will have to change if we ever encounter
4251 an uneven architecture. */
4252 if ((address_size
& (address_size
- 1)) != 0)
4254 warn (_("Pointer size + Segment size is not a power of two.\n"));
4258 if (address_size
> 4)
4259 printf (_("\n Address Length\n"));
4261 printf (_("\n Address Length\n"));
4263 addr_ranges
= hdrptr
;
4265 /* Must pad to an alignment boundary that is twice the address size. */
4266 excess
= (hdrptr
- start
) % (2 * address_size
);
4268 addr_ranges
+= (2 * address_size
) - excess
;
4270 start
+= arange
.ar_length
+ initial_length_size
;
4272 while (addr_ranges
+ 2 * address_size
<= start
)
4274 address
= byte_get (addr_ranges
, address_size
);
4276 addr_ranges
+= address_size
;
4278 length
= byte_get (addr_ranges
, address_size
);
4280 addr_ranges
+= address_size
;
4283 print_dwarf_vma (address
, address_size
);
4284 print_dwarf_vma (length
, address_size
);
4294 /* Each debug_information[x].range_lists[y] gets this representation for
4295 sorting purposes. */
4299 /* The debug_information[x].range_lists[y] value. */
4300 unsigned long ranges_offset
;
4302 /* Original debug_information to find parameters of the data. */
4303 debug_info
*debug_info_p
;
4306 /* Sort struct range_entry in ascending order of its RANGES_OFFSET. */
4309 range_entry_compar (const void *ap
, const void *bp
)
4311 const struct range_entry
*a_re
= (const struct range_entry
*) ap
;
4312 const struct range_entry
*b_re
= (const struct range_entry
*) bp
;
4313 const unsigned long a
= a_re
->ranges_offset
;
4314 const unsigned long b
= b_re
->ranges_offset
;
4316 return (a
> b
) - (b
> a
);
4320 display_debug_ranges (struct dwarf_section
*section
,
4321 void *file ATTRIBUTE_UNUSED
)
4323 unsigned char *start
= section
->start
;
4324 unsigned long bytes
;
4325 unsigned char *section_begin
= start
;
4326 unsigned int num_range_list
, i
;
4327 struct range_entry
*range_entries
, *range_entry_fill
;
4329 bytes
= section
->size
;
4333 printf (_("\nThe %s section is empty.\n"), section
->name
);
4337 if (load_debug_info (file
) == 0)
4339 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
4345 for (i
= 0; i
< num_debug_info_entries
; i
++)
4346 num_range_list
+= debug_information
[i
].num_range_lists
;
4348 if (num_range_list
== 0)
4349 error (_("No range lists in .debug_info section!\n"));
4351 range_entries
= (struct range_entry
*)
4352 xmalloc (sizeof (*range_entries
) * num_range_list
);
4353 range_entry_fill
= range_entries
;
4355 for (i
= 0; i
< num_debug_info_entries
; i
++)
4357 debug_info
*debug_info_p
= &debug_information
[i
];
4360 for (j
= 0; j
< debug_info_p
->num_range_lists
; j
++)
4362 range_entry_fill
->ranges_offset
= debug_info_p
->range_lists
[j
];
4363 range_entry_fill
->debug_info_p
= debug_info_p
;
4368 qsort (range_entries
, num_range_list
, sizeof (*range_entries
),
4369 range_entry_compar
);
4371 /* DWARF sections under Mach-O have non-zero addresses. */
4372 if (range_entries
[0].ranges_offset
!= section
->address
)
4373 warn (_("Range lists in %s section start at 0x%lx\n"),
4374 section
->name
, range_entries
[0].ranges_offset
);
4376 printf (_("Contents of the %s section:\n\n"), section
->name
);
4377 printf (_(" Offset Begin End\n"));
4379 for (i
= 0; i
< num_range_list
; i
++)
4381 struct range_entry
*range_entry
= &range_entries
[i
];
4382 debug_info
*debug_info_p
= range_entry
->debug_info_p
;
4383 unsigned int pointer_size
;
4384 unsigned long offset
;
4385 unsigned char *next
;
4386 unsigned long base_address
;
4388 pointer_size
= debug_info_p
->pointer_size
;
4390 /* DWARF sections under Mach-O have non-zero addresses. */
4391 offset
= range_entry
->ranges_offset
- section
->address
;
4392 next
= section_begin
+ offset
;
4393 base_address
= debug_info_p
->base_address
;
4398 warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"),
4399 (unsigned long) (start
- section_begin
),
4400 (unsigned long) (next
- section_begin
), section
->name
);
4401 else if (start
> next
)
4402 warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"),
4403 (unsigned long) (start
- section_begin
),
4404 (unsigned long) (next
- section_begin
), section
->name
);
4413 /* Note: we use sign extension here in order to be sure that
4414 we can detect the -1 escape value. Sign extension into the
4415 top 32 bits of a 32-bit address will not affect the values
4416 that we display since we always show hex values, and always
4417 the bottom 32-bits. */
4418 begin
= byte_get_signed (start
, pointer_size
);
4419 start
+= pointer_size
;
4420 end
= byte_get_signed (start
, pointer_size
);
4421 start
+= pointer_size
;
4423 printf (" %8.8lx ", offset
);
4425 if (begin
== 0 && end
== 0)
4427 printf (_("<End of list>\n"));
4431 /* Check base address specifiers. */
4432 if (begin
== (dwarf_vma
) -1 && end
!= (dwarf_vma
) -1)
4435 print_dwarf_vma (begin
, pointer_size
);
4436 print_dwarf_vma (end
, pointer_size
);
4437 printf ("(base address)\n");
4441 print_dwarf_vma (begin
+ base_address
, pointer_size
);
4442 print_dwarf_vma (end
+ base_address
, pointer_size
);
4445 fputs (_("(start == end)"), stdout
);
4446 else if (begin
> end
)
4447 fputs (_("(start > end)"), stdout
);
4454 free (range_entries
);
4459 typedef struct Frame_Chunk
4461 struct Frame_Chunk
*next
;
4462 unsigned char *chunk_start
;
4464 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
4465 short int *col_type
;
4468 unsigned int code_factor
;
4470 unsigned long pc_begin
;
4471 unsigned long pc_range
;
4475 unsigned char fde_encoding
;
4476 unsigned char cfa_exp
;
4477 unsigned char ptr_size
;
4478 unsigned char segment_size
;
4482 static const char *const *dwarf_regnames
;
4483 static unsigned int dwarf_regnames_count
;
4485 /* A marker for a col_type that means this column was never referenced
4486 in the frame info. */
4487 #define DW_CFA_unreferenced (-1)
4489 /* Return 0 if not more space is needed, 1 if more space is needed,
4490 -1 for invalid reg. */
4493 frame_need_space (Frame_Chunk
*fc
, unsigned int reg
)
4495 int prev
= fc
->ncols
;
4497 if (reg
< (unsigned int) fc
->ncols
)
4500 if (dwarf_regnames_count
4501 && reg
> dwarf_regnames_count
)
4504 fc
->ncols
= reg
+ 1;
4505 fc
->col_type
= (short int *) xcrealloc (fc
->col_type
, fc
->ncols
,
4506 sizeof (short int));
4507 fc
->col_offset
= (int *) xcrealloc (fc
->col_offset
, fc
->ncols
, sizeof (int));
4509 while (prev
< fc
->ncols
)
4511 fc
->col_type
[prev
] = DW_CFA_unreferenced
;
4512 fc
->col_offset
[prev
] = 0;
4518 static const char *const dwarf_regnames_i386
[] =
4520 "eax", "ecx", "edx", "ebx",
4521 "esp", "ebp", "esi", "edi",
4522 "eip", "eflags", NULL
,
4523 "st0", "st1", "st2", "st3",
4524 "st4", "st5", "st6", "st7",
4526 "xmm0", "xmm1", "xmm2", "xmm3",
4527 "xmm4", "xmm5", "xmm6", "xmm7",
4528 "mm0", "mm1", "mm2", "mm3",
4529 "mm4", "mm5", "mm6", "mm7",
4530 "fcw", "fsw", "mxcsr",
4531 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
,
4536 init_dwarf_regnames_i386 (void)
4538 dwarf_regnames
= dwarf_regnames_i386
;
4539 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_i386
);
4542 static const char *const dwarf_regnames_x86_64
[] =
4544 "rax", "rdx", "rcx", "rbx",
4545 "rsi", "rdi", "rbp", "rsp",
4546 "r8", "r9", "r10", "r11",
4547 "r12", "r13", "r14", "r15",
4549 "xmm0", "xmm1", "xmm2", "xmm3",
4550 "xmm4", "xmm5", "xmm6", "xmm7",
4551 "xmm8", "xmm9", "xmm10", "xmm11",
4552 "xmm12", "xmm13", "xmm14", "xmm15",
4553 "st0", "st1", "st2", "st3",
4554 "st4", "st5", "st6", "st7",
4555 "mm0", "mm1", "mm2", "mm3",
4556 "mm4", "mm5", "mm6", "mm7",
4558 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
,
4559 "fs.base", "gs.base", NULL
, NULL
,
4561 "mxcsr", "fcw", "fsw"
4565 init_dwarf_regnames_x86_64 (void)
4567 dwarf_regnames
= dwarf_regnames_x86_64
;
4568 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_x86_64
);
4572 init_dwarf_regnames (unsigned int e_machine
)
4578 init_dwarf_regnames_i386 ();
4584 init_dwarf_regnames_x86_64 ();
4593 regname (unsigned int regno
, int row
)
4595 static char reg
[64];
4597 && regno
< dwarf_regnames_count
4598 && dwarf_regnames
[regno
] != NULL
)
4601 return dwarf_regnames
[regno
];
4602 snprintf (reg
, sizeof (reg
), "r%d (%s)", regno
,
4603 dwarf_regnames
[regno
]);
4606 snprintf (reg
, sizeof (reg
), "r%d", regno
);
4611 frame_display_row (Frame_Chunk
*fc
, int *need_col_headers
, int *max_regs
)
4616 if (*max_regs
< fc
->ncols
)
4617 *max_regs
= fc
->ncols
;
4619 if (*need_col_headers
)
4621 static const char *sloc
= " LOC";
4623 *need_col_headers
= 0;
4625 printf ("%-*s CFA ", eh_addr_size
* 2, sloc
);
4627 for (r
= 0; r
< *max_regs
; r
++)
4628 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
4633 printf ("%-5s ", regname (r
, 1));
4639 printf ("%0*lx ", eh_addr_size
* 2, fc
->pc_begin
);
4641 strcpy (tmp
, "exp");
4643 sprintf (tmp
, "%s%+d", regname (fc
->cfa_reg
, 1), fc
->cfa_offset
);
4644 printf ("%-8s ", tmp
);
4646 for (r
= 0; r
< fc
->ncols
; r
++)
4648 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
4650 switch (fc
->col_type
[r
])
4652 case DW_CFA_undefined
:
4655 case DW_CFA_same_value
:
4659 sprintf (tmp
, "c%+d", fc
->col_offset
[r
]);
4661 case DW_CFA_val_offset
:
4662 sprintf (tmp
, "v%+d", fc
->col_offset
[r
]);
4664 case DW_CFA_register
:
4665 sprintf (tmp
, "%s", regname (fc
->col_offset
[r
], 0));
4667 case DW_CFA_expression
:
4668 strcpy (tmp
, "exp");
4670 case DW_CFA_val_expression
:
4671 strcpy (tmp
, "vexp");
4674 strcpy (tmp
, "n/a");
4677 printf ("%-5s ", tmp
);
4683 #define GET(N) byte_get (start, N); start += N
4684 #define LEB() read_leb128 (start, & length_return, 0); start += length_return
4685 #define SLEB() read_sleb128 (start, & length_return); start += length_return
4688 display_debug_frames (struct dwarf_section
*section
,
4689 void *file ATTRIBUTE_UNUSED
)
4691 unsigned char *start
= section
->start
;
4692 unsigned char *end
= start
+ section
->size
;
4693 unsigned char *section_start
= start
;
4694 Frame_Chunk
*chunks
= 0;
4695 Frame_Chunk
*remembered_state
= 0;
4697 int is_eh
= strcmp (section
->name
, ".eh_frame") == 0;
4698 unsigned int length_return
;
4700 const char *bad_reg
= _("bad register: ");
4701 int saved_eh_addr_size
= eh_addr_size
;
4703 printf (_("Contents of the %s section:\n"), section
->name
);
4707 unsigned char *saved_start
;
4708 unsigned char *block_end
;
4709 unsigned long length
;
4710 unsigned long cie_id
;
4713 int need_col_headers
= 1;
4714 unsigned char *augmentation_data
= NULL
;
4715 unsigned long augmentation_data_len
= 0;
4716 int encoded_ptr_size
= saved_eh_addr_size
;
4718 int initial_length_size
;
4720 saved_start
= start
;
4721 length
= byte_get (start
, 4); start
+= 4;
4725 printf ("\n%08lx ZERO terminator\n\n",
4726 (unsigned long)(saved_start
- section_start
));
4730 if (length
== 0xffffffff)
4732 length
= byte_get (start
, 8);
4735 initial_length_size
= 12;
4740 initial_length_size
= 4;
4743 block_end
= saved_start
+ length
+ initial_length_size
;
4744 if (block_end
> end
)
4746 warn ("Invalid length %#08lx in FDE at %#08lx\n",
4747 length
, (unsigned long)(saved_start
- section_start
));
4750 cie_id
= byte_get (start
, offset_size
); start
+= offset_size
;
4752 if (is_eh
? (cie_id
== 0) : (cie_id
== DW_CIE_ID
))
4756 fc
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
4757 memset (fc
, 0, sizeof (Frame_Chunk
));
4761 fc
->chunk_start
= saved_start
;
4763 fc
->col_type
= (short int *) xmalloc (sizeof (short int));
4764 fc
->col_offset
= (int *) xmalloc (sizeof (int));
4765 frame_need_space (fc
, max_regs
- 1);
4769 fc
->augmentation
= (char *) start
;
4770 start
= (unsigned char *) strchr ((char *) start
, '\0') + 1;
4772 if (strcmp (fc
->augmentation
, "eh") == 0)
4773 start
+= eh_addr_size
;
4777 fc
->ptr_size
= GET (1);
4778 fc
->segment_size
= GET (1);
4779 eh_addr_size
= fc
->ptr_size
;
4783 fc
->ptr_size
= eh_addr_size
;
4784 fc
->segment_size
= 0;
4786 fc
->code_factor
= LEB ();
4787 fc
->data_factor
= SLEB ();
4797 if (fc
->augmentation
[0] == 'z')
4799 augmentation_data_len
= LEB ();
4800 augmentation_data
= start
;
4801 start
+= augmentation_data_len
;
4805 if (do_debug_frames_interp
)
4806 printf ("\n%08lx %08lx %08lx CIE \"%s\" cf=%d df=%d ra=%d\n",
4807 (unsigned long)(saved_start
- section_start
), length
, cie_id
,
4808 fc
->augmentation
, fc
->code_factor
, fc
->data_factor
,
4812 printf ("\n%08lx %08lx %08lx CIE\n",
4813 (unsigned long)(saved_start
- section_start
), length
, cie_id
);
4814 printf (" Version: %d\n", version
);
4815 printf (" Augmentation: \"%s\"\n", fc
->augmentation
);
4818 printf (" Pointer Size: %u\n", fc
->ptr_size
);
4819 printf (" Segment Size: %u\n", fc
->segment_size
);
4821 printf (" Code alignment factor: %u\n", fc
->code_factor
);
4822 printf (" Data alignment factor: %d\n", fc
->data_factor
);
4823 printf (" Return address column: %d\n", fc
->ra
);
4825 if (augmentation_data_len
)
4828 printf (" Augmentation data: ");
4829 for (i
= 0; i
< augmentation_data_len
; ++i
)
4830 printf (" %02x", augmentation_data
[i
]);
4836 if (augmentation_data_len
)
4838 unsigned char *p
, *q
;
4839 p
= (unsigned char *) fc
->augmentation
+ 1;
4840 q
= augmentation_data
;
4847 q
+= 1 + size_of_encoded_value (*q
);
4849 fc
->fde_encoding
= *q
++;
4857 if (fc
->fde_encoding
)
4858 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
4861 frame_need_space (fc
, fc
->ra
);
4865 unsigned char *look_for
;
4866 static Frame_Chunk fde_fc
;
4867 unsigned long segment_selector
;
4870 memset (fc
, 0, sizeof (Frame_Chunk
));
4872 look_for
= is_eh
? start
- 4 - cie_id
: section_start
+ cie_id
;
4874 for (cie
= chunks
; cie
; cie
= cie
->next
)
4875 if (cie
->chunk_start
== look_for
)
4880 warn ("Invalid CIE pointer %#08lx in FDE at %#08lx\n",
4881 cie_id
, (unsigned long)(saved_start
- section_start
));
4883 fc
->col_type
= (short int *) xmalloc (sizeof (short int));
4884 fc
->col_offset
= (int *) xmalloc (sizeof (int));
4885 frame_need_space (fc
, max_regs
- 1);
4887 fc
->augmentation
= "";
4888 fc
->fde_encoding
= 0;
4889 fc
->ptr_size
= eh_addr_size
;
4890 fc
->segment_size
= 0;
4894 fc
->ncols
= cie
->ncols
;
4895 fc
->col_type
= (short int *) xcmalloc (fc
->ncols
, sizeof (short int));
4896 fc
->col_offset
= (int *) xcmalloc (fc
->ncols
, sizeof (int));
4897 memcpy (fc
->col_type
, cie
->col_type
, fc
->ncols
* sizeof (short int));
4898 memcpy (fc
->col_offset
, cie
->col_offset
, fc
->ncols
* sizeof (int));
4899 fc
->augmentation
= cie
->augmentation
;
4900 fc
->ptr_size
= cie
->ptr_size
;
4901 eh_addr_size
= cie
->ptr_size
;
4902 fc
->segment_size
= cie
->segment_size
;
4903 fc
->code_factor
= cie
->code_factor
;
4904 fc
->data_factor
= cie
->data_factor
;
4905 fc
->cfa_reg
= cie
->cfa_reg
;
4906 fc
->cfa_offset
= cie
->cfa_offset
;
4908 frame_need_space (fc
, max_regs
- 1);
4909 fc
->fde_encoding
= cie
->fde_encoding
;
4912 if (fc
->fde_encoding
)
4913 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
4915 segment_selector
= 0;
4916 if (fc
->segment_size
)
4918 segment_selector
= byte_get (start
, fc
->segment_size
);
4919 start
+= fc
->segment_size
;
4921 fc
->pc_begin
= get_encoded_value (start
, fc
->fde_encoding
, section
);
4922 start
+= encoded_ptr_size
;
4923 fc
->pc_range
= byte_get (start
, encoded_ptr_size
);
4924 start
+= encoded_ptr_size
;
4926 if (cie
->augmentation
[0] == 'z')
4928 augmentation_data_len
= LEB ();
4929 augmentation_data
= start
;
4930 start
+= augmentation_data_len
;
4933 printf ("\n%08lx %08lx %08lx FDE cie=%08lx pc=",
4934 (unsigned long)(saved_start
- section_start
), length
, cie_id
,
4935 (unsigned long)(cie
->chunk_start
- section_start
));
4936 if (fc
->segment_size
)
4937 printf ("%04lx:", segment_selector
);
4938 printf ("%08lx..%08lx\n", fc
->pc_begin
, fc
->pc_begin
+ fc
->pc_range
);
4939 if (! do_debug_frames_interp
&& augmentation_data_len
)
4943 printf (" Augmentation data: ");
4944 for (i
= 0; i
< augmentation_data_len
; ++i
)
4945 printf (" %02x", augmentation_data
[i
]);
4951 /* At this point, fc is the current chunk, cie (if any) is set, and
4952 we're about to interpret instructions for the chunk. */
4953 /* ??? At present we need to do this always, since this sizes the
4954 fc->col_type and fc->col_offset arrays, which we write into always.
4955 We should probably split the interpreted and non-interpreted bits
4956 into two different routines, since there's so much that doesn't
4957 really overlap between them. */
4958 if (1 || do_debug_frames_interp
)
4960 /* Start by making a pass over the chunk, allocating storage
4961 and taking note of what registers are used. */
4962 unsigned char *tmp
= start
;
4964 while (start
< block_end
)
4967 unsigned long reg
, temp
;
4974 /* Warning: if you add any more cases to this switch, be
4975 sure to add them to the corresponding switch below. */
4978 case DW_CFA_advance_loc
:
4982 if (frame_need_space (fc
, opa
) >= 0)
4983 fc
->col_type
[opa
] = DW_CFA_undefined
;
4985 case DW_CFA_restore
:
4986 if (frame_need_space (fc
, opa
) >= 0)
4987 fc
->col_type
[opa
] = DW_CFA_undefined
;
4989 case DW_CFA_set_loc
:
4990 start
+= encoded_ptr_size
;
4992 case DW_CFA_advance_loc1
:
4995 case DW_CFA_advance_loc2
:
4998 case DW_CFA_advance_loc4
:
5001 case DW_CFA_offset_extended
:
5002 case DW_CFA_val_offset
:
5003 reg
= LEB (); LEB ();
5004 if (frame_need_space (fc
, reg
) >= 0)
5005 fc
->col_type
[reg
] = DW_CFA_undefined
;
5007 case DW_CFA_restore_extended
:
5009 frame_need_space (fc
, reg
);
5010 if (frame_need_space (fc
, reg
) >= 0)
5011 fc
->col_type
[reg
] = DW_CFA_undefined
;
5013 case DW_CFA_undefined
:
5015 if (frame_need_space (fc
, reg
) >= 0)
5016 fc
->col_type
[reg
] = DW_CFA_undefined
;
5018 case DW_CFA_same_value
:
5020 if (frame_need_space (fc
, reg
) >= 0)
5021 fc
->col_type
[reg
] = DW_CFA_undefined
;
5023 case DW_CFA_register
:
5024 reg
= LEB (); LEB ();
5025 if (frame_need_space (fc
, reg
) >= 0)
5026 fc
->col_type
[reg
] = DW_CFA_undefined
;
5028 case DW_CFA_def_cfa
:
5031 case DW_CFA_def_cfa_register
:
5034 case DW_CFA_def_cfa_offset
:
5037 case DW_CFA_def_cfa_expression
:
5041 case DW_CFA_expression
:
5042 case DW_CFA_val_expression
:
5046 if (frame_need_space (fc
, reg
) >= 0)
5047 fc
->col_type
[reg
] = DW_CFA_undefined
;
5049 case DW_CFA_offset_extended_sf
:
5050 case DW_CFA_val_offset_sf
:
5051 reg
= LEB (); SLEB ();
5052 if (frame_need_space (fc
, reg
) >= 0)
5053 fc
->col_type
[reg
] = DW_CFA_undefined
;
5055 case DW_CFA_def_cfa_sf
:
5058 case DW_CFA_def_cfa_offset_sf
:
5061 case DW_CFA_MIPS_advance_loc8
:
5064 case DW_CFA_GNU_args_size
:
5067 case DW_CFA_GNU_negative_offset_extended
:
5068 reg
= LEB (); LEB ();
5069 if (frame_need_space (fc
, reg
) >= 0)
5070 fc
->col_type
[reg
] = DW_CFA_undefined
;
5079 /* Now we know what registers are used, make a second pass over
5080 the chunk, this time actually printing out the info. */
5082 while (start
< block_end
)
5085 unsigned long ul
, reg
, roffs
;
5088 const char *reg_prefix
= "";
5095 /* Warning: if you add any more cases to this switch, be
5096 sure to add them to the corresponding switch above. */
5099 case DW_CFA_advance_loc
:
5100 if (do_debug_frames_interp
)
5101 frame_display_row (fc
, &need_col_headers
, &max_regs
);
5103 printf (" DW_CFA_advance_loc: %d to %08lx\n",
5104 opa
* fc
->code_factor
,
5105 fc
->pc_begin
+ opa
* fc
->code_factor
);
5106 fc
->pc_begin
+= opa
* fc
->code_factor
;
5111 if (opa
>= (unsigned int) fc
->ncols
)
5112 reg_prefix
= bad_reg
;
5113 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
5114 printf (" DW_CFA_offset: %s%s at cfa%+ld\n",
5115 reg_prefix
, regname (opa
, 0),
5116 roffs
* fc
->data_factor
);
5117 if (*reg_prefix
== '\0')
5119 fc
->col_type
[opa
] = DW_CFA_offset
;
5120 fc
->col_offset
[opa
] = roffs
* fc
->data_factor
;
5124 case DW_CFA_restore
:
5125 if (opa
>= (unsigned int) cie
->ncols
5126 || opa
>= (unsigned int) fc
->ncols
)
5127 reg_prefix
= bad_reg
;
5128 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
5129 printf (" DW_CFA_restore: %s%s\n",
5130 reg_prefix
, regname (opa
, 0));
5131 if (*reg_prefix
== '\0')
5133 fc
->col_type
[opa
] = cie
->col_type
[opa
];
5134 fc
->col_offset
[opa
] = cie
->col_offset
[opa
];
5135 if (do_debug_frames_interp
5136 && fc
->col_type
[opa
] == DW_CFA_unreferenced
)
5137 fc
->col_type
[opa
] = DW_CFA_undefined
;
5141 case DW_CFA_set_loc
:
5142 vma
= get_encoded_value (start
, fc
->fde_encoding
, section
);
5143 start
+= encoded_ptr_size
;
5144 if (do_debug_frames_interp
)
5145 frame_display_row (fc
, &need_col_headers
, &max_regs
);
5147 printf (" DW_CFA_set_loc: %08lx\n", (unsigned long)vma
);
5151 case DW_CFA_advance_loc1
:
5152 ofs
= byte_get (start
, 1); start
+= 1;
5153 if (do_debug_frames_interp
)
5154 frame_display_row (fc
, &need_col_headers
, &max_regs
);
5156 printf (" DW_CFA_advance_loc1: %ld to %08lx\n",
5157 ofs
* fc
->code_factor
,
5158 fc
->pc_begin
+ ofs
* fc
->code_factor
);
5159 fc
->pc_begin
+= ofs
* fc
->code_factor
;
5162 case DW_CFA_advance_loc2
:
5163 ofs
= byte_get (start
, 2); start
+= 2;
5164 if (do_debug_frames_interp
)
5165 frame_display_row (fc
, &need_col_headers
, &max_regs
);
5167 printf (" DW_CFA_advance_loc2: %ld to %08lx\n",
5168 ofs
* fc
->code_factor
,
5169 fc
->pc_begin
+ ofs
* fc
->code_factor
);
5170 fc
->pc_begin
+= ofs
* fc
->code_factor
;
5173 case DW_CFA_advance_loc4
:
5174 ofs
= byte_get (start
, 4); start
+= 4;
5175 if (do_debug_frames_interp
)
5176 frame_display_row (fc
, &need_col_headers
, &max_regs
);
5178 printf (" DW_CFA_advance_loc4: %ld to %08lx\n",
5179 ofs
* fc
->code_factor
,
5180 fc
->pc_begin
+ ofs
* fc
->code_factor
);
5181 fc
->pc_begin
+= ofs
* fc
->code_factor
;
5184 case DW_CFA_offset_extended
:
5187 if (reg
>= (unsigned int) fc
->ncols
)
5188 reg_prefix
= bad_reg
;
5189 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
5190 printf (" DW_CFA_offset_extended: %s%s at cfa%+ld\n",
5191 reg_prefix
, regname (reg
, 0),
5192 roffs
* fc
->data_factor
);
5193 if (*reg_prefix
== '\0')
5195 fc
->col_type
[reg
] = DW_CFA_offset
;
5196 fc
->col_offset
[reg
] = roffs
* fc
->data_factor
;
5200 case DW_CFA_val_offset
:
5203 if (reg
>= (unsigned int) fc
->ncols
)
5204 reg_prefix
= bad_reg
;
5205 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
5206 printf (" DW_CFA_val_offset: %s%s at cfa%+ld\n",
5207 reg_prefix
, regname (reg
, 0),
5208 roffs
* fc
->data_factor
);
5209 if (*reg_prefix
== '\0')
5211 fc
->col_type
[reg
] = DW_CFA_val_offset
;
5212 fc
->col_offset
[reg
] = roffs
* fc
->data_factor
;
5216 case DW_CFA_restore_extended
:
5218 if (reg
>= (unsigned int) cie
->ncols
5219 || reg
>= (unsigned int) fc
->ncols
)
5220 reg_prefix
= bad_reg
;
5221 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
5222 printf (" DW_CFA_restore_extended: %s%s\n",
5223 reg_prefix
, regname (reg
, 0));
5224 if (*reg_prefix
== '\0')
5226 fc
->col_type
[reg
] = cie
->col_type
[reg
];
5227 fc
->col_offset
[reg
] = cie
->col_offset
[reg
];
5231 case DW_CFA_undefined
:
5233 if (reg
>= (unsigned int) fc
->ncols
)
5234 reg_prefix
= bad_reg
;
5235 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
5236 printf (" DW_CFA_undefined: %s%s\n",
5237 reg_prefix
, regname (reg
, 0));
5238 if (*reg_prefix
== '\0')
5240 fc
->col_type
[reg
] = DW_CFA_undefined
;
5241 fc
->col_offset
[reg
] = 0;
5245 case DW_CFA_same_value
:
5247 if (reg
>= (unsigned int) fc
->ncols
)
5248 reg_prefix
= bad_reg
;
5249 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
5250 printf (" DW_CFA_same_value: %s%s\n",
5251 reg_prefix
, regname (reg
, 0));
5252 if (*reg_prefix
== '\0')
5254 fc
->col_type
[reg
] = DW_CFA_same_value
;
5255 fc
->col_offset
[reg
] = 0;
5259 case DW_CFA_register
:
5262 if (reg
>= (unsigned int) fc
->ncols
)
5263 reg_prefix
= bad_reg
;
5264 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
5266 printf (" DW_CFA_register: %s%s in ",
5267 reg_prefix
, regname (reg
, 0));
5268 puts (regname (roffs
, 0));
5270 if (*reg_prefix
== '\0')
5272 fc
->col_type
[reg
] = DW_CFA_register
;
5273 fc
->col_offset
[reg
] = roffs
;
5277 case DW_CFA_remember_state
:
5278 if (! do_debug_frames_interp
)
5279 printf (" DW_CFA_remember_state\n");
5280 rs
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
5281 rs
->ncols
= fc
->ncols
;
5282 rs
->col_type
= (short int *) xcmalloc (rs
->ncols
,
5283 sizeof (short int));
5284 rs
->col_offset
= (int *) xcmalloc (rs
->ncols
, sizeof (int));
5285 memcpy (rs
->col_type
, fc
->col_type
, rs
->ncols
);
5286 memcpy (rs
->col_offset
, fc
->col_offset
, rs
->ncols
* sizeof (int));
5287 rs
->next
= remembered_state
;
5288 remembered_state
= rs
;
5291 case DW_CFA_restore_state
:
5292 if (! do_debug_frames_interp
)
5293 printf (" DW_CFA_restore_state\n");
5294 rs
= remembered_state
;
5297 remembered_state
= rs
->next
;
5298 frame_need_space (fc
, rs
->ncols
- 1);
5299 memcpy (fc
->col_type
, rs
->col_type
, rs
->ncols
);
5300 memcpy (fc
->col_offset
, rs
->col_offset
,
5301 rs
->ncols
* sizeof (int));
5302 free (rs
->col_type
);
5303 free (rs
->col_offset
);
5306 else if (do_debug_frames_interp
)
5307 printf ("Mismatched DW_CFA_restore_state\n");
5310 case DW_CFA_def_cfa
:
5311 fc
->cfa_reg
= LEB ();
5312 fc
->cfa_offset
= LEB ();
5314 if (! do_debug_frames_interp
)
5315 printf (" DW_CFA_def_cfa: %s ofs %d\n",
5316 regname (fc
->cfa_reg
, 0), fc
->cfa_offset
);
5319 case DW_CFA_def_cfa_register
:
5320 fc
->cfa_reg
= LEB ();
5322 if (! do_debug_frames_interp
)
5323 printf (" DW_CFA_def_cfa_register: %s\n",
5324 regname (fc
->cfa_reg
, 0));
5327 case DW_CFA_def_cfa_offset
:
5328 fc
->cfa_offset
= LEB ();
5329 if (! do_debug_frames_interp
)
5330 printf (" DW_CFA_def_cfa_offset: %d\n", fc
->cfa_offset
);
5334 if (! do_debug_frames_interp
)
5335 printf (" DW_CFA_nop\n");
5338 case DW_CFA_def_cfa_expression
:
5340 if (! do_debug_frames_interp
)
5342 printf (" DW_CFA_def_cfa_expression (");
5343 decode_location_expression (start
, eh_addr_size
, 0, -1,
5351 case DW_CFA_expression
:
5354 if (reg
>= (unsigned int) fc
->ncols
)
5355 reg_prefix
= bad_reg
;
5356 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
5358 printf (" DW_CFA_expression: %s%s (",
5359 reg_prefix
, regname (reg
, 0));
5360 decode_location_expression (start
, eh_addr_size
, 0, -1,
5364 if (*reg_prefix
== '\0')
5365 fc
->col_type
[reg
] = DW_CFA_expression
;
5369 case DW_CFA_val_expression
:
5372 if (reg
>= (unsigned int) fc
->ncols
)
5373 reg_prefix
= bad_reg
;
5374 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
5376 printf (" DW_CFA_val_expression: %s%s (",
5377 reg_prefix
, regname (reg
, 0));
5378 decode_location_expression (start
, eh_addr_size
, 0, -1,
5382 if (*reg_prefix
== '\0')
5383 fc
->col_type
[reg
] = DW_CFA_val_expression
;
5387 case DW_CFA_offset_extended_sf
:
5390 if (frame_need_space (fc
, reg
) < 0)
5391 reg_prefix
= bad_reg
;
5392 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
5393 printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+ld\n",
5394 reg_prefix
, regname (reg
, 0),
5395 l
* fc
->data_factor
);
5396 if (*reg_prefix
== '\0')
5398 fc
->col_type
[reg
] = DW_CFA_offset
;
5399 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
5403 case DW_CFA_val_offset_sf
:
5406 if (frame_need_space (fc
, reg
) < 0)
5407 reg_prefix
= bad_reg
;
5408 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
5409 printf (" DW_CFA_val_offset_sf: %s%s at cfa%+ld\n",
5410 reg_prefix
, regname (reg
, 0),
5411 l
* fc
->data_factor
);
5412 if (*reg_prefix
== '\0')
5414 fc
->col_type
[reg
] = DW_CFA_val_offset
;
5415 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
5419 case DW_CFA_def_cfa_sf
:
5420 fc
->cfa_reg
= LEB ();
5421 fc
->cfa_offset
= SLEB ();
5422 fc
->cfa_offset
= fc
->cfa_offset
* fc
->data_factor
;
5424 if (! do_debug_frames_interp
)
5425 printf (" DW_CFA_def_cfa_sf: %s ofs %d\n",
5426 regname (fc
->cfa_reg
, 0), fc
->cfa_offset
);
5429 case DW_CFA_def_cfa_offset_sf
:
5430 fc
->cfa_offset
= SLEB ();
5431 fc
->cfa_offset
= fc
->cfa_offset
* fc
->data_factor
;
5432 if (! do_debug_frames_interp
)
5433 printf (" DW_CFA_def_cfa_offset_sf: %d\n", fc
->cfa_offset
);
5436 case DW_CFA_MIPS_advance_loc8
:
5437 ofs
= byte_get (start
, 8); start
+= 8;
5438 if (do_debug_frames_interp
)
5439 frame_display_row (fc
, &need_col_headers
, &max_regs
);
5441 printf (" DW_CFA_MIPS_advance_loc8: %ld to %08lx\n",
5442 ofs
* fc
->code_factor
,
5443 fc
->pc_begin
+ ofs
* fc
->code_factor
);
5444 fc
->pc_begin
+= ofs
* fc
->code_factor
;
5447 case DW_CFA_GNU_window_save
:
5448 if (! do_debug_frames_interp
)
5449 printf (" DW_CFA_GNU_window_save\n");
5452 case DW_CFA_GNU_args_size
:
5454 if (! do_debug_frames_interp
)
5455 printf (" DW_CFA_GNU_args_size: %ld\n", ul
);
5458 case DW_CFA_GNU_negative_offset_extended
:
5461 if (frame_need_space (fc
, reg
) < 0)
5462 reg_prefix
= bad_reg
;
5463 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
5464 printf (" DW_CFA_GNU_negative_offset_extended: %s%s at cfa%+ld\n",
5465 reg_prefix
, regname (reg
, 0),
5466 l
* fc
->data_factor
);
5467 if (*reg_prefix
== '\0')
5469 fc
->col_type
[reg
] = DW_CFA_offset
;
5470 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
5475 if (op
>= DW_CFA_lo_user
&& op
<= DW_CFA_hi_user
)
5476 printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op
);
5478 warn (_("unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op
);
5483 if (do_debug_frames_interp
)
5484 frame_display_row (fc
, &need_col_headers
, &max_regs
);
5487 eh_addr_size
= saved_eh_addr_size
;
5500 display_gdb_index (struct dwarf_section
*section
,
5501 void *file ATTRIBUTE_UNUSED
)
5503 unsigned char *start
= section
->start
;
5505 uint32_t cu_list_offset
, tu_list_offset
;
5506 uint32_t address_table_offset
, symbol_table_offset
, constant_pool_offset
;
5507 unsigned int cu_list_elements
, tu_list_elements
;
5508 unsigned int address_table_size
, symbol_table_slots
;
5509 unsigned char *cu_list
, *tu_list
;
5510 unsigned char *address_table
, *symbol_table
, *constant_pool
;
5513 /* The documentation for the format of this file is in gdb/dwarf2read.c. */
5515 printf (_("Contents of the %s section:\n"), section
->name
);
5517 if (section
->size
< 6 * sizeof (uint32_t))
5519 warn (_("Truncated header in the %s section.\n"), section
->name
);
5523 version
= byte_get_little_endian (start
, 4);
5524 printf (_("Version %ld\n"), (long) version
);
5526 /* Prior versions are obsolete, and future versions may not be
5527 backwards compatible. */
5531 warn (_("The address table data in version 3 may be wrong.\n"));
5534 warn (_("Version 4 does not support case insensitive lookups.\n"));
5539 warn (_("Unsupported version %lu.\n"), (unsigned long) version
);
5543 cu_list_offset
= byte_get_little_endian (start
+ 4, 4);
5544 tu_list_offset
= byte_get_little_endian (start
+ 8, 4);
5545 address_table_offset
= byte_get_little_endian (start
+ 12, 4);
5546 symbol_table_offset
= byte_get_little_endian (start
+ 16, 4);
5547 constant_pool_offset
= byte_get_little_endian (start
+ 20, 4);
5549 if (cu_list_offset
> section
->size
5550 || tu_list_offset
> section
->size
5551 || address_table_offset
> section
->size
5552 || symbol_table_offset
> section
->size
5553 || constant_pool_offset
> section
->size
)
5555 warn (_("Corrupt header in the %s section.\n"), section
->name
);
5559 cu_list_elements
= (tu_list_offset
- cu_list_offset
) / 8;
5560 tu_list_elements
= (address_table_offset
- tu_list_offset
) / 8;
5561 address_table_size
= symbol_table_offset
- address_table_offset
;
5562 symbol_table_slots
= (constant_pool_offset
- symbol_table_offset
) / 8;
5564 cu_list
= start
+ cu_list_offset
;
5565 tu_list
= start
+ tu_list_offset
;
5566 address_table
= start
+ address_table_offset
;
5567 symbol_table
= start
+ symbol_table_offset
;
5568 constant_pool
= start
+ constant_pool_offset
;
5570 printf (_("\nCU table:\n"));
5571 for (i
= 0; i
< cu_list_elements
; i
+= 2)
5573 uint64_t cu_offset
= byte_get_little_endian (cu_list
+ i
* 8, 8);
5574 uint64_t cu_length
= byte_get_little_endian (cu_list
+ i
* 8 + 8, 8);
5576 printf (_("[%3u] 0x%lx - 0x%lx\n"), i
/ 2,
5577 (unsigned long) cu_offset
,
5578 (unsigned long) (cu_offset
+ cu_length
- 1));
5581 printf (_("\nTU table:\n"));
5582 for (i
= 0; i
< tu_list_elements
; i
+= 3)
5584 uint64_t tu_offset
= byte_get_little_endian (tu_list
+ i
* 8, 8);
5585 uint64_t type_offset
= byte_get_little_endian (tu_list
+ i
* 8 + 8, 8);
5586 uint64_t signature
= byte_get_little_endian (tu_list
+ i
* 8 + 16, 8);
5588 printf (_("[%3u] 0x%lx 0x%lx "), i
/ 3,
5589 (unsigned long) tu_offset
,
5590 (unsigned long) type_offset
);
5591 print_dwarf_vma (signature
, 8);
5595 printf (_("\nAddress table:\n"));
5596 for (i
= 0; i
< address_table_size
; i
+= 2 * 8 + 4)
5598 uint64_t low
= byte_get_little_endian (address_table
+ i
, 8);
5599 uint64_t high
= byte_get_little_endian (address_table
+ i
+ 8, 8);
5600 uint32_t cu_index
= byte_get_little_endian (address_table
+ i
+ 16, 4);
5602 print_dwarf_vma (low
, 8);
5603 print_dwarf_vma (high
, 8);
5604 printf (_("%lu\n"), (unsigned long) cu_index
);
5607 printf (_("\nSymbol table:\n"));
5608 for (i
= 0; i
< symbol_table_slots
; ++i
)
5610 uint32_t name_offset
= byte_get_little_endian (symbol_table
+ i
* 8, 4);
5611 uint32_t cu_vector_offset
= byte_get_little_endian (symbol_table
+ i
* 8 + 4, 4);
5612 uint32_t num_cus
, cu
;
5614 if (name_offset
!= 0
5615 || cu_vector_offset
!= 0)
5619 printf ("[%3u] %s:", i
, constant_pool
+ name_offset
);
5620 num_cus
= byte_get_little_endian (constant_pool
+ cu_vector_offset
, 4);
5621 for (j
= 0; j
< num_cus
; ++j
)
5623 cu
= byte_get_little_endian (constant_pool
+ cu_vector_offset
+ 4 + j
* 4, 4);
5624 /* Convert to TU number if it's for a type unit. */
5625 if (cu
>= cu_list_elements
/ 2)
5626 printf (" T%lu", (unsigned long) (cu
- cu_list_elements
/ 2));
5628 printf (" %lu", (unsigned long) cu
);
5638 display_debug_not_supported (struct dwarf_section
*section
,
5639 void *file ATTRIBUTE_UNUSED
)
5641 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
5648 cmalloc (size_t nmemb
, size_t size
)
5650 /* Check for overflow. */
5651 if (nmemb
>= ~(size_t) 0 / size
)
5654 return malloc (nmemb
* size
);
5658 xcmalloc (size_t nmemb
, size_t size
)
5660 /* Check for overflow. */
5661 if (nmemb
>= ~(size_t) 0 / size
)
5664 return xmalloc (nmemb
* size
);
5668 xcrealloc (void *ptr
, size_t nmemb
, size_t size
)
5670 /* Check for overflow. */
5671 if (nmemb
>= ~(size_t) 0 / size
)
5674 return xrealloc (ptr
, nmemb
* size
);
5678 free_debug_memory (void)
5684 for (i
= 0; i
< max
; i
++)
5685 free_debug_section ((enum dwarf_section_display_enum
) i
);
5687 if (debug_information
!= NULL
)
5689 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
)
5691 for (i
= 0; i
< num_debug_info_entries
; i
++)
5693 if (!debug_information
[i
].max_loc_offsets
)
5695 free (debug_information
[i
].loc_offsets
);
5696 free (debug_information
[i
].have_frame_base
);
5698 if (!debug_information
[i
].max_range_lists
)
5699 free (debug_information
[i
].range_lists
);
5703 free (debug_information
);
5704 debug_information
= NULL
;
5705 num_debug_info_entries
= 0;
5710 dwarf_select_sections_by_names (const char *names
)
5714 const char * option
;
5718 debug_dump_long_opts
;
5720 static const debug_dump_long_opts opts_table
[] =
5722 /* Please keep this table alpha- sorted. */
5723 { "Ranges", & do_debug_ranges
, 1 },
5724 { "abbrev", & do_debug_abbrevs
, 1 },
5725 { "aranges", & do_debug_aranges
, 1 },
5726 { "frames", & do_debug_frames
, 1 },
5727 { "frames-interp", & do_debug_frames_interp
, 1 },
5728 { "info", & do_debug_info
, 1 },
5729 { "line", & do_debug_lines
, FLAG_DEBUG_LINES_RAW
}, /* For backwards compatibility. */
5730 { "rawline", & do_debug_lines
, FLAG_DEBUG_LINES_RAW
},
5731 { "decodedline", & do_debug_lines
, FLAG_DEBUG_LINES_DECODED
},
5732 { "loc", & do_debug_loc
, 1 },
5733 { "macro", & do_debug_macinfo
, 1 },
5734 { "pubnames", & do_debug_pubnames
, 1 },
5735 { "pubtypes", & do_debug_pubtypes
, 1 },
5736 /* This entry is for compatability
5737 with earlier versions of readelf. */
5738 { "ranges", & do_debug_aranges
, 1 },
5739 { "str", & do_debug_str
, 1 },
5740 /* The special .gdb_index section. */
5741 { "gdb_index", & do_gdb_index
, 1 },
5742 /* These trace_* sections are used by Itanium VMS. */
5743 { "trace_abbrev", & do_trace_abbrevs
, 1 },
5744 { "trace_aranges", & do_trace_aranges
, 1 },
5745 { "trace_info", & do_trace_info
, 1 },
5754 const debug_dump_long_opts
* entry
;
5756 for (entry
= opts_table
; entry
->option
; entry
++)
5758 size_t len
= strlen (entry
->option
);
5760 if (strncmp (p
, entry
->option
, len
) == 0
5761 && (p
[len
] == ',' || p
[len
] == '\0'))
5763 * entry
->variable
|= entry
->val
;
5765 /* The --debug-dump=frames-interp option also
5766 enables the --debug-dump=frames option. */
5767 if (do_debug_frames_interp
)
5768 do_debug_frames
= 1;
5775 if (entry
->option
== NULL
)
5777 warn (_("Unrecognized debug option '%s'\n"), p
);
5778 p
= strchr (p
, ',');
5789 dwarf_select_sections_by_letters (const char *letters
)
5791 unsigned int lindex
= 0;
5793 while (letters
[lindex
])
5794 switch (letters
[lindex
++])
5801 do_debug_abbrevs
= 1;
5805 do_debug_lines
|= FLAG_DEBUG_LINES_RAW
;
5809 do_debug_lines
|= FLAG_DEBUG_LINES_DECODED
;
5813 do_debug_pubnames
= 1;
5817 do_debug_pubtypes
= 1;
5821 do_debug_aranges
= 1;
5825 do_debug_ranges
= 1;
5829 do_debug_frames_interp
= 1;
5831 do_debug_frames
= 1;
5835 do_debug_macinfo
= 1;
5847 warn (_("Unrecognized debug option '%s'\n"), optarg
);
5853 dwarf_select_sections_all (void)
5856 do_debug_abbrevs
= 1;
5857 do_debug_lines
= FLAG_DEBUG_LINES_RAW
;
5858 do_debug_pubnames
= 1;
5859 do_debug_pubtypes
= 1;
5860 do_debug_aranges
= 1;
5861 do_debug_ranges
= 1;
5862 do_debug_frames
= 1;
5863 do_debug_macinfo
= 1;
5868 do_trace_abbrevs
= 1;
5869 do_trace_aranges
= 1;
5872 struct dwarf_section_display debug_displays
[] =
5874 { { ".debug_abbrev", ".zdebug_abbrev", NULL
, NULL
, 0, 0 },
5875 display_debug_abbrev
, &do_debug_abbrevs
, 0 },
5876 { { ".debug_aranges", ".zdebug_aranges", NULL
, NULL
, 0, 0 },
5877 display_debug_aranges
, &do_debug_aranges
, 1 },
5878 { { ".debug_frame", ".zdebug_frame", NULL
, NULL
, 0, 0 },
5879 display_debug_frames
, &do_debug_frames
, 1 },
5880 { { ".debug_info", ".zdebug_info", NULL
, NULL
, 0, 0 },
5881 display_debug_info
, &do_debug_info
, 1 },
5882 { { ".debug_line", ".zdebug_line", NULL
, NULL
, 0, 0 },
5883 display_debug_lines
, &do_debug_lines
, 1 },
5884 { { ".debug_pubnames", ".zdebug_pubnames", NULL
, NULL
, 0, 0 },
5885 display_debug_pubnames
, &do_debug_pubnames
, 0 },
5886 { { ".eh_frame", "", NULL
, NULL
, 0, 0 },
5887 display_debug_frames
, &do_debug_frames
, 1 },
5888 { { ".debug_macinfo", ".zdebug_macinfo", NULL
, NULL
, 0, 0 },
5889 display_debug_macinfo
, &do_debug_macinfo
, 0 },
5890 { { ".debug_macro", ".zdebug_macro", NULL
, NULL
, 0, 0 },
5891 display_debug_macro
, &do_debug_macinfo
, 1 },
5892 { { ".debug_str", ".zdebug_str", NULL
, NULL
, 0, 0 },
5893 display_debug_str
, &do_debug_str
, 0 },
5894 { { ".debug_loc", ".zdebug_loc", NULL
, NULL
, 0, 0 },
5895 display_debug_loc
, &do_debug_loc
, 1 },
5896 { { ".debug_pubtypes", ".zdebug_pubtypes", NULL
, NULL
, 0, 0 },
5897 display_debug_pubnames
, &do_debug_pubtypes
, 0 },
5898 { { ".debug_ranges", ".zdebug_ranges", NULL
, NULL
, 0, 0 },
5899 display_debug_ranges
, &do_debug_ranges
, 1 },
5900 { { ".debug_static_func", ".zdebug_static_func", NULL
, NULL
, 0, 0 },
5901 display_debug_not_supported
, NULL
, 0 },
5902 { { ".debug_static_vars", ".zdebug_static_vars", NULL
, NULL
, 0, 0 },
5903 display_debug_not_supported
, NULL
, 0 },
5904 { { ".debug_types", ".zdebug_types", NULL
, NULL
, 0, 0 },
5905 display_debug_types
, &do_debug_info
, 1 },
5906 { { ".debug_weaknames", ".zdebug_weaknames", NULL
, NULL
, 0, 0 },
5907 display_debug_not_supported
, NULL
, 0 },
5908 { { ".gdb_index", "", NULL
, NULL
, 0, 0 },
5909 display_gdb_index
, &do_gdb_index
, 0 },
5910 { { ".trace_info", "", NULL
, NULL
, 0, 0 },
5911 display_trace_info
, &do_trace_info
, 1 },
5912 { { ".trace_abbrev", "", NULL
, NULL
, 0, 0 },
5913 display_debug_abbrev
, &do_trace_abbrevs
, 0 },
5914 { { ".trace_aranges", "", NULL
, NULL
, 0, 0 },
5915 display_debug_aranges
, &do_trace_aranges
, 0 }